Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5631637pxb; Mon, 28 Mar 2022 15:13:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTPPM3Q343QZPcbrRiVqcTIUS7zbvVAD7kitdyi1KhhJpnpn7WFqruNQVqZfVqkjcMCMTs X-Received: by 2002:a05:6808:20a7:b0:2da:5fcb:29b2 with SMTP id s39-20020a05680820a700b002da5fcb29b2mr720619oiw.82.1648505635090; Mon, 28 Mar 2022 15:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648505635; cv=none; d=google.com; s=arc-20160816; b=LjgFLSPzoz4oS/Q9BvbXba6gjPoOFU/fHGSl5/BTn9EHLUll12Oq7ptNfUYDmipXPE CJY8gF/nq8xgcasSJZ/YuePxqmrrw6ieC/LUFJ+Ljjbtm7C63+OlUsv7CaArv3KJqUbu 6ewiTcYR8UtfiaoB7KOVJ+Yz39ce5h/xfz81g493SQ9gn93qv5C0UevEg92TYmdCeanl 8PWmd6P1NS8TzfP/2EWeEa7Dec5wkQS5sJ0MwM3wt5VMsHJ1TyFWrSudyEfz6ZBZbmjr A2VKyyf2Cn4pfQjKCBjVXbm7IHwJQ7ay4dHZyeQ0TF7Te/A0h/ihgpoaRGDpzHfMwYyv 1hJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=s8/hjJ3Mxs6TNNKBuPTlAebuny86Ylaq+Kt1EqWatAk=; b=QDtxBjQKSNNioRRPVZlULOFqm441uDSnILF0r+a+yISkYciZiWSk+gfVzmeWOE4exB p9I5M8xGUWUr0NcfmEpcT2p5c5vNvwiYS53kP0+VVUKzd8/V9WHUkAGGTpBodmzkNnz5 dTJLr9CacjkUlwsQmrczkqi/dCUg90j1u2MQDU0ZnagOK8wWQjfv25DEfrEmeinyzHsX SJMvnytoNUuz3LiBXWGRlmZ3Nn4Hf63gY0LESbeh1ttiWiTfsmVgZ2Qjvx8I3HFVCPA9 uXAWP6YK8be1kuOZYBgZ7S8irMI+b+gcyKS4q3msMPoeBgC+Mz7V/BMsWHLLqvWAMueX SFFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=K1uYWeC2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o10-20020a056870968a00b000ddf6e6ee4csi10972932oaq.189.2022.03.28.15.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 15:13:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b=K1uYWeC2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5A4031704FC; Mon, 28 Mar 2022 14:33:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239416AbiC1PtE (ORCPT + 99 others); Mon, 28 Mar 2022 11:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239096AbiC1PqK (ORCPT ); Mon, 28 Mar 2022 11:46:10 -0400 Received: from mail.baikalelectronics.ru (mail.baikalelectronics.com [87.245.175.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DDCF64B1E9; Mon, 28 Mar 2022 08:44:19 -0700 (PDT) Received: from mail.baikalelectronics.ru (unknown [192.168.51.25]) by mail.baikalelectronics.ru (Postfix) with ESMTP id D96631E28DF; Thu, 24 Mar 2022 03:16:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.baikalelectronics.ru D96631E28DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baikalelectronics.ru; s=mail; t=1648081005; bh=s8/hjJ3Mxs6TNNKBuPTlAebuny86Ylaq+Kt1EqWatAk=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=K1uYWeC2FnUOs850BMTzhqOyMJPSXexWjTMqTdoqm2Dq1csKayY5b7MAz8CDRfNVo 0atB27pqp4fzZ0F5cBAjmzk+ZCefLtwB7I1rmAh1EUMaXB4K0WazGir93MQwMs6LQs WXLeXy8fX3hoZemkoaHDN7/++2wVZk6di1sngrxM= Received: from localhost (192.168.168.10) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 24 Mar 2022 03:16:45 +0300 From: Serge Semin To: Damien Le Moal , Hans de Goede , Jens Axboe , Serge Semin CC: Serge Semin , Alexey Malahov , Pavel Parkhomenko , Rob Herring , , , Subject: [PATCH 19/21] ata: ahci-dwc: Add platform-specific quirks support Date: Thu, 24 Mar 2022 03:16:26 +0300 Message-ID: <20220324001628.13028-20-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20220324001628.13028-1-Sergey.Semin@baikalelectronics.ru> References: <20220324001628.13028-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some DWC AHCI SATA IP-core derivatives require to perform small platform or IP-core specific setups. They are too small to be placed in a dedicated driver. It's just much easier to have a set of quirks for them right in the DWC AHCI driver code. Since we are about to add such platform support, as a pre-requisite we introduce a platform-data based DWC AHCI quirks API. The platform data can be used to define the flags passed to the ahci_platform_get_resources() method, additional AHCI host-flags and a set of callbacks to initialize, re-initialize and clear the platform settings. Signed-off-by: Serge Semin --- drivers/ata/ahci_dwc.c | 52 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/drivers/ata/ahci_dwc.c b/drivers/ata/ahci_dwc.c index c51e2251994e..9e294f994ed3 100644 --- a/drivers/ata/ahci_dwc.c +++ b/drivers/ata/ahci_dwc.c @@ -90,7 +90,16 @@ #define DWC_AHCI_PORT_PHYCR 0x74 #define DWC_AHCI_PORT_PHYSR 0x78 +struct dwc_ahci_plat_data { + unsigned int pflags; + unsigned int hflags; + int (*init)(struct ahci_host_priv *hpriv); + int (*reinit)(struct ahci_host_priv *hpriv); + void (*clear)(struct ahci_host_priv *hpriv); +}; + struct dwc_ahci_host_priv { + const struct dwc_ahci_plat_data *pdata; struct platform_device *pdev; u32 timv; @@ -107,11 +116,15 @@ static struct ahci_host_priv *dwc_ahci_get_resources(struct platform_device *pde return ERR_PTR(-ENOMEM); dpriv->pdev = pdev; + dpriv->pdata = device_get_match_data(&pdev->dev); + if (!dpriv->pdata) + return ERR_PTR(-EINVAL); - hpriv = ahci_platform_get_resources(pdev, AHCI_PLATFORM_GET_RESETS); + hpriv = ahci_platform_get_resources(pdev, dpriv->pdata->pflags); if (IS_ERR(hpriv)) return hpriv; + hpriv->flags |= dpriv->pdata->hflags; hpriv->plat_data = (void *)dpriv; return hpriv; @@ -242,22 +255,33 @@ static int dwc_ahci_init_dmacr(struct ahci_host_priv *hpriv) static int dwc_ahci_init_host(struct ahci_host_priv *hpriv) { + struct dwc_ahci_host_priv *dpriv = hpriv->plat_data; int rc; rc = ahci_platform_enable_resources(hpriv); if (rc) return rc; + if (dpriv->pdata->init) { + rc = dpriv->pdata->init(hpriv); + if (rc) + goto err_disable_resources; + } + dwc_ahci_check_cap(hpriv); dwc_ahci_init_timer(hpriv); rc = dwc_ahci_init_dmacr(hpriv); if (rc) - goto err_disable_resources; + goto err_clear_platform; return 0; +err_clear_platform: + if (dpriv->pdata->clear) + dpriv->pdata->clear(hpriv); + err_disable_resources: ahci_platform_disable_resources(hpriv); @@ -275,6 +299,12 @@ static int dwc_ahci_reinit_host(struct ahci_host_priv *hpriv) if (rc) return rc; + if (dpriv->pdata->reinit) { + rc = dpriv->pdata->reinit(hpriv); + if (rc) + goto err_disable_resources; + } + writel(dpriv->timv, hpriv->mmio + DWC_AHCI_HOST_TIMER1MS); for_each_set_bit(i, &port_map, AHCI_MAX_PORTS) { @@ -283,10 +313,20 @@ static int dwc_ahci_reinit_host(struct ahci_host_priv *hpriv) } return 0; + +err_disable_resources: + ahci_platform_disable_resources(hpriv); + + return rc; } static void dwc_ahci_clear_host(struct ahci_host_priv *hpriv) { + struct dwc_ahci_host_priv *dpriv = hpriv->plat_data; + + if (dpriv->pdata->clear) + dpriv->pdata->clear(hpriv); + ahci_platform_disable_resources(hpriv); } @@ -371,9 +411,13 @@ static int dwc_ahci_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(dwc_ahci_pm_ops, dwc_ahci_suspend, dwc_ahci_resume); +struct dwc_ahci_plat_data dwc_ahci_plat = { + .pflags = AHCI_PLATFORM_GET_RESETS, +}; + static const struct of_device_id dwc_ahci_of_match[] = { - { .compatible = "snps,dwc-ahci", }, - { .compatible = "snps,spear-ahci", }, + { .compatible = "snps,dwc-ahci", &dwc_ahci_plat }, + { .compatible = "snps,spear-ahci", &dwc_ahci_plat }, {}, }; MODULE_DEVICE_TABLE(of, dwc_ahci_of_match); -- 2.35.1