Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp68231ybx; Thu, 31 Oct 2019 23:09:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqypohb6Tc2XkCVG7BE0O95J0sx5DRGOyxSEB7zyLhk6E8fXzLAsFd4+4WZWgfKVy+S7WFrO X-Received: by 2002:a17:906:1812:: with SMTP id v18mr8074726eje.86.1572588568174; Thu, 31 Oct 2019 23:09:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1572588568; cv=pass; d=google.com; s=arc-20160816; b=wBNSSZw95khXb0tz3mZJD1H8W/xrIlGGKr+d3r4dt7R1Mqx5h9+2OQImDsIQCq2geo fd0R/EhiZSpYzYSgIX57RuiIz9g+wXSJpT+AhnCX4Gl+fWlEnU3dTMCVrHulKcyV//7t BE7MGhJZkGvRD4FnszMmTfDRGL/NhL6sjsV+goSxNCtVa1DQxh0ibCyUBWEU6xtcW/vq 12nfO/tTq6vdZCnh0RoGmFI+48DLasX5RIzo0MP+pqt8E8xmRnQQS2SCrFUrWzSgW/JD c4lQYXhkp/8I5G8pXAmf1iX9OLWRr5U0NSmEY2P2nEptuXqmDAwrxYH7u3ZHig05dFAh SkEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=m5S1KA31oH+mkM7DanXAs+YE4sBunEXs4vCCSxmISw8=; b=ZwPSPANCl5rHBmw0rHYC7Jak5izWjRiPBHeiz/eR/DauQT1YNqutRV8+HqvdLoTLh0 1w+Yf1diIQN/NAtRJ/3ZvXZeCe53G9KAskjFWMhthFUvJIwNlgmZhehoZDQkCON4veBg dfTN4ZquicKEYNu1+e9WpUkibX1jB5HXiDzhRfkdHbx6cFR4LzVc11mIvsgvTk5N2Hl+ JIcYredDzlS5eoS7R7DPNq8sgIJT84R5JR0wSclGheHjPA6M9mCNpR+RKiBbhhMBBPhO MtnX/HFWNouUZ9LM27D16aboQOpWUunZXSmh0pq9S6R9IKCePwlbieSujuQWzw1p+Usu vIgg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector2-xilinx-onmicrosoft-com header.b=N8F4RSPH; arc=pass (i=1 spf=pass spfdomain=xilinx.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n20si5435437edr.357.2019.10.31.23.09.04; Thu, 31 Oct 2019 23:09:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector2-xilinx-onmicrosoft-com header.b=N8F4RSPH; arc=pass (i=1 spf=pass spfdomain=xilinx.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729678AbfKAGG3 (ORCPT + 99 others); Fri, 1 Nov 2019 02:06:29 -0400 Received: from mail-eopbgr680071.outbound.protection.outlook.com ([40.107.68.71]:36809 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729782AbfKAGGR (ORCPT ); Fri, 1 Nov 2019 02:06:17 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d5QXGx8pSq1eFTcV+4L5mSJTcE1MWDhoXqw8r6hRFCU+luDmX7I8W4PgBeXLhkKzttkdazdJ+qtXz2ndXM2jGeHKLuQCjRP/IQQ3TMArYkuxqkh+B1CQ4lWSdOf2zI1Z92Ur42FyIimLO67yIVbQoAK5mjtCnvCxUzLUtjxbqL6CbHEbaDhwE2DUZWl1p9lsqtospqQXH68p2uzqe5gRGqEXl2EBIVTdNpffnPiclQ8+Qx5lxPh56Fw6t3bllhaqYE+9alM0pHZqtJTnUa+xDXrSsrUHLwW71xBpovPirYjSy1hQw2ryhZ9wHYGp/i9bBL3GnEScaBqD+eGXh64EhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m5S1KA31oH+mkM7DanXAs+YE4sBunEXs4vCCSxmISw8=; b=Y+lxbsXnBH5343nZ5K/tHRjBrtWlqqFQGjbMqmgdO75N5lXvojG2K5VbS7C0YFXFyAVDPGV/2tcYxF16zEaKM6X1kPBiUeOoJ97VB48YJzSURw+Rj70wB4/a+H9zMirWI7A6n9RMXXX03OR+rSPtC7tD7ezM5+K0bZkzZN+KwSYKc8YdlRayf2ZuFm1V128jt2vqFsOpWwDDTEZJhvXxI/ExzeU6mlnYhlDNfJyTPY7nC6Ze9kXSfGXCsFTl/TnNyc7mED0RTO3N1bWF5C5D9e5mMlMFw29yi9m5x9OGts5XyR1XCe00PK2LbFmoaL78l/zc2zkqZp8xQLXyVTZFAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.60.83) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=xilinx.com; dmarc=bestguesspass action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m5S1KA31oH+mkM7DanXAs+YE4sBunEXs4vCCSxmISw8=; b=N8F4RSPH/wf2KRz0MEUzIhxbV50aLLoxeCDT/DaJXX0cbdZiPig0uNr5bJVG2ZQf36M+KhBi2FrG7Dz48liU7B6D8BKA3/vGra0P7b0SS1kUEdeYPouLn5BZcOBrnOWAj6BmhPrNPxwsj+BiThWOfEP/LfXtkGeMxnkh+eCcmxw= Received: from BYAPR02CA0030.namprd02.prod.outlook.com (2603:10b6:a02:ee::43) by SN4PR0201MB3551.namprd02.prod.outlook.com (2603:10b6:803:4c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.24; Fri, 1 Nov 2019 06:06:11 +0000 Received: from SN1NAM02FT062.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e44::207) by BYAPR02CA0030.outlook.office365.com (2603:10b6:a02:ee::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2408.19 via Frontend Transport; Fri, 1 Nov 2019 06:06:11 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; Received: from xsj-pvapsmtpgw01 (149.199.60.83) by SN1NAM02FT062.mail.protection.outlook.com (10.152.72.208) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.2367.14 via Frontend Transport; Fri, 1 Nov 2019 06:06:10 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1iQQ4Y-0005mc-7Q; Thu, 31 Oct 2019 23:06:10 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1iQQ4T-0007dN-2p; Thu, 31 Oct 2019 23:06:05 -0700 Received: from xsj-pvapsmtp01 (mail.xilinx.com [149.199.38.66] (may be forged)) by xsj-smtp-dlp2.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id xA165xhi005683; Thu, 31 Oct 2019 23:05:59 -0700 Received: from [172.23.64.106] (helo=xhdvnc125.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1iQQ4M-0007aL-Pm; Thu, 31 Oct 2019 23:05:59 -0700 Received: by xhdvnc125.xilinx.com (Postfix, from userid 16987) id 03029121386; Fri, 1 Nov 2019 11:35:57 +0530 (IST) From: Manish Narani To: ulf.hansson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, adrian.hunter@intel.com, michal.simek@xilinx.com, jolly.shah@xilinx.com, nava.manne@xilinx.com, rajan.vaja@xilinx.com, manish.narani@xilinx.com Cc: linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, git@xilinx.com Subject: [PATCH v5 5/8] mmc: sdhci-of-arasan: Add support to set clock phase delays for SD Date: Fri, 1 Nov 2019 11:35:50 +0530 Message-Id: <1572588353-110682-6-git-send-email-manish.narani@xilinx.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1572588353-110682-1-git-send-email-manish.narani@xilinx.com> References: <1572588353-110682-1-git-send-email-manish.narani@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23620.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.83;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(136003)(346002)(376002)(396003)(39860400002)(189003)(199004)(478600001)(2906002)(5660300002)(70586007)(70206006)(103686004)(107886003)(8936002)(336012)(50226002)(426003)(126002)(476003)(36756003)(50466002)(48376002)(2616005)(51416003)(14444005)(6666004)(44832011)(486006)(356004)(76176011)(8676002)(81166006)(81156014)(4326008)(42186006)(316002)(26005)(186003)(305945005)(6266002)(11346002)(446003)(36386004)(16586007)(106002)(47776003)(42866002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN4PR0201MB3551;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;LANG:en;PTR:unknown-60-83.xilinx.com;MX:1;A:1; MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cf48439f-2e49-4b22-70b1-08d75e9197fb X-MS-TrafficTypeDiagnostic: SN4PR0201MB3551: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 020877E0CB X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X/iIuO8ojDVe45XT32MBpm14XBa/VMN3w5sQCaWOgbaBD/dbl/hLR/HYkg66IVvXjwswjiAEQblvbnVqxR3SxrVzzwn/JuC/S7P7+LN+PU5oFY1H3cF6dr84fFGc+cyDZjeNP5yxT/XHEm587ErpbgvPAfruMv3mf37kobYpX8uyXk8/P4tOwm9r9C6K4Ax8IDgcJq9/g2ScQpPe89aKYHh6/N64Vgw0err0CNq8aGlTWmhfHxjecM7xaFOmuihXgj8NSUdWj1P9ozyl7xUem4PuuWBZ7kspzois2KvFHo1rUOQr13++7PCvpU+I+hr11afWHqrj1NqbRbaqeuLTLXN9Y0/WBi1KDSeYHr8wqC0sUlzQndpmeKviVMi4dSMwDq73rR77KNihkYP5tvjLW4zFPNVKOr566ycDqZ420ifOtzhVigZKKrbgnfMfxaUn X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2019 06:06:10.7419 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf48439f-2e49-4b22-70b1-08d75e9197fb X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.83];Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR0201MB3551 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to read Clock Phase Delays from the DT and set it via clk_set_phase() API from clock framework. Some of the controllers might have their own handling of setting clock delays, for this keep the set_clk_delays as function pointer which can be assigned controller specific handling of the same. Signed-off-by: Manish Narani --- drivers/mmc/host/sdhci-of-arasan.c | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c index b75ba780f902..9452ae01f6fa 100644 --- a/drivers/mmc/host/sdhci-of-arasan.c +++ b/drivers/mmc/host/sdhci-of-arasan.c @@ -77,12 +77,18 @@ struct sdhci_arasan_soc_ctl_map { * @sdcardclk: Pointer to normal 'struct clock' for sdcardclk_hw. * @sampleclk_hw: Struct for the clock we might provide to a PHY. * @sampleclk: Pointer to normal 'struct clock' for sampleclk_hw. + * @clk_phase_in: Array of Input Clock Phase Delays for all speed modes + * @clk_phase_out: Array of Output Clock Phase Delays for all speed modes + * @set_clk_delays: Function pointer for setting Clock Delays */ struct sdhci_arasan_clk_data { struct clk_hw sdcardclk_hw; struct clk *sdcardclk; struct clk_hw sampleclk_hw; struct clk *sampleclk; + int clk_phase_in[MMC_TIMING_MMC_HS400 + 1]; + int clk_phase_out[MMC_TIMING_MMC_HS400 + 1]; + void (*set_clk_delays)(struct sdhci_host *host); }; /** @@ -186,6 +192,7 @@ static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock) { struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); + struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data; bool ctrl_phy = false; if (!IS_ERR(sdhci_arasan->phy)) { @@ -227,6 +234,10 @@ static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock) sdhci_arasan->is_phy_on = false; } + /* Set the Input and Output Clock Phase Delays */ + if (clk_data->set_clk_delays) + clk_data->set_clk_delays(host); + sdhci_set_clock(host, clock); if (sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE) @@ -650,6 +661,85 @@ static void sdhci_arasan_update_baseclkfreq(struct sdhci_host *host) sdhci_arasan_syscon_write(host, &soc_ctl_map->baseclkfreq, mhz); } +static void sdhci_arasan_set_clk_delays(struct sdhci_host *host) +{ + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); + struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data; + + clk_set_phase(clk_data->sampleclk, + clk_data->clk_phase_in[host->timing]); + clk_set_phase(clk_data->sdcardclk, + clk_data->clk_phase_out[host->timing]); +} + +static void arasan_dt_read_clk_phase(struct device *dev, + struct sdhci_arasan_clk_data *clk_data, + unsigned int timing, const char *prop) +{ + struct device_node *np = dev->of_node; + + int clk_phase[2] = {0}; + + /* + * Read Tap Delay values from DT, if the DT does not contain the + * Tap Values then use the pre-defined values. + */ + if (of_property_read_variable_u32_array(np, prop, &clk_phase[0], + 2, 0)) { + dev_dbg(dev, "Using predefined clock phase for %s = %d %d\n", + prop, clk_data->clk_phase_in[timing], + clk_data->clk_phase_out[timing]); + return; + } + + /* The values read are Input and Output Clock Delays in order */ + clk_data->clk_phase_in[timing] = clk_phase[0]; + clk_data->clk_phase_out[timing] = clk_phase[1]; +} + +/** + * arasan_dt_parse_clk_phases - Read Clock Delay values from DT + * + * Called at initialization to parse the values of Clock Delays. + * + * @dev: Pointer to our struct device. + * @clk_data: Pointer to the Clock Data structure + */ +static void arasan_dt_parse_clk_phases(struct device *dev, + struct sdhci_arasan_clk_data *clk_data) +{ + /* + * This has been kept as a pointer and is assigned a function here. + * So that different controller variants can assign their own handling + * function. + */ + clk_data->set_clk_delays = sdhci_arasan_set_clk_delays; + + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_LEGACY, + "clk-phase-legacy"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_MMC_HS, + "clk-phase-mmc-hs"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_SD_HS, + "clk-phase-sd-hs"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_UHS_SDR12, + "clk-phase-uhs-sdr12"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_UHS_SDR25, + "clk-phase-uhs-sdr25"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_UHS_SDR50, + "clk-phase-uhs-sdr50"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_UHS_SDR104, + "clk-phase-uhs-sdr104"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_UHS_DDR50, + "clk-phase-uhs-ddr50"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_MMC_DDR52, + "clk-phase-mmc-ddr52"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_MMC_HS200, + "clk-phase-mmc-hs200"); + arasan_dt_read_clk_phase(dev, clk_data, MMC_TIMING_MMC_HS400, + "clk-phase-mmc-hs400"); +} + /** * sdhci_arasan_register_sdcardclk - Register the sdcardclk for a PHY to use * @@ -942,6 +1032,8 @@ static int sdhci_arasan_probe(struct platform_device *pdev) if (ret) goto clk_disable_all; + arasan_dt_parse_clk_phases(&pdev->dev, &sdhci_arasan->clk_data); + ret = mmc_of_parse(host->mmc); if (ret) { if (ret != -EPROBE_DEFER) -- 2.17.1