Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp477864ybg; Fri, 18 Oct 2019 02:46:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyI5OwiITKxO46X02T9Tph73ClGdKqXP3YFn9IB5YfBy8NN4yIROHN6NdopsZzg/Co7lrb4 X-Received: by 2002:a17:906:c49:: with SMTP id t9mr7745462ejf.267.1571392010529; Fri, 18 Oct 2019 02:46:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1571392010; cv=pass; d=google.com; s=arc-20160816; b=tW1/PGOgm6ICx7orgV+kGV6nS3Q556O7sGNzOR4k2eQ2xEiGGNVn3YrqHm7sISbALK eq2QALCtW4Z5K6fWvxYd/wx7lnD+VhyctW8+Lr6Zf02ynVXxepP3TPGXtZZLavvJ/3Bj 49TbETcLggBapGO8oODTkrf12TltUOmKh+Fd38mwb5RU6kwf11w3jWBXqXohZmvgYydx gFiNuowmLJbY8znmDgBVfEls9yx+QHaw7GgPWi5UuftE2l2FZF85L8fL6cIXUSgc/En5 gPNIE5hQeMEqYptCtR8efxaMc3zpVCCmacTOMlJn+EWz4TT+21o3FaoHEC0VkD4JEGom PDYQ== 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=40OcsSTvAI7fWjnEhcoxg8VFoF2pOMTdNxkv07pTj7E=; b=jqa0fTz8MwTcDglRtO13/orVC+2vh6OU0rRlhCVZdmKmgvF92xHIA/OmTvKwzr3lMo S1Frw5dK4nBGkX+zCRe7ijgOEFLrI+/cio/Q5Z+F31dLTS2tuPAF3rkozg9dYbn19mEH USVNV+LUyHajjHWjqBTfAmW/gGFnPiZcCdTLHwX7Y/R+RiY/NBLw9ndv6gG8hOka5+T8 cjhvAXxFgKyUTY4uWmWO+WU13g0/YbvkriWJA1nQpBvG109gmTnSicJwQkqRJJlbggwy r8iPFVmnGIQnh98Ajji+xguI8J3K6hGaPa2bsUM6PeSFTiRORFmf4oq6Bdm+96VcXEpe cUtA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector2-xilinx-onmicrosoft-com header.b="A/U14Eow"; 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 pk7si2980611ejb.216.2019.10.18.02.46.26; Fri, 18 Oct 2019 02:46:50 -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="A/U14Eow"; 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 S2407805AbfJQGWW (ORCPT + 99 others); Thu, 17 Oct 2019 02:22:22 -0400 Received: from mail-eopbgr680067.outbound.protection.outlook.com ([40.107.68.67]:38019 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2437774AbfJQGWU (ORCPT ); Thu, 17 Oct 2019 02:22:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kUGY58UTUkkbLZZ7dDvbSJiZTa6EHBy8iCm/5ac6IUiL2QD//RB28p89P4FL1Z5mc23+dqxf0jyHH4EWFqXjzdtwYIk/pGseK7ENUYiI69NLtrkAKxc/JwK0M/g1BCYpK2vTKGE08sDTw3+hrKiH3BqldFKSqyq8hCfcSuoujd56FWJ7AZZF9JBuBN4K5Ccp4iyCQhZw68tkKt8eW+w3nKFpgSmRt4Nhod+MvrpTT8p+hAsbLpxeuSk4iQZkFs2FxfkcKgIScxGdxt849gL7vBZiTTxN9E5smlk/f7wr7eUPB2qAK50oAjvO9qxNMGwHIkB4lFKpu6QRLJv3DB8awQ== 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=40OcsSTvAI7fWjnEhcoxg8VFoF2pOMTdNxkv07pTj7E=; b=JS8AhCP123m7TgsMeO1utGQ09E6B4m+3hcErLngh9nW+JyA/BxIS0Qv0szi9QP9I4dklfnlmbmvVEFWxWSj+WRPTWKT6w3XPb2Ot9K225d/RzlOSfCYAGrdEcVN7YMRCNUOpCjX3weUdGm1IJywbY6ad6Wfdjobp8TZRQ//XUmpuiQN0pW0kxGNZ4vTgx6vT0VWEqkRekto4D0GhP3Asc5n80gYtjc36QKQNqyAtwgGJzn2kuP/tF0OHJbOFiycJOSNwXztnSX0CDiUVI9P0rPgCfQ73d5lMaYPw9/wcNImpfSTxlY16GBwAdRadg6TMbhTH3dMoNlF0FNfHM0bguA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.60.83) smtp.rcpttodomain=arm.com 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=40OcsSTvAI7fWjnEhcoxg8VFoF2pOMTdNxkv07pTj7E=; b=A/U14Eowa1WBchF6NDINCi42umPRQRtgTSVww0olSIa4fiGd2BL+4khvv9Fg9rmllOHgNYfa4mXBgosi26PYVdjRK+FsKJzFY/aBAOrACaO+av4Ox9cGyC3yNAUA+GEXHrpfOWHBHQCdXrLWX96sm9j9yjcRCjxpFMEuo/V+F6k= Received: from DM6PR02CA0138.namprd02.prod.outlook.com (2603:10b6:5:1b4::40) by MWHPR02MB2829.namprd02.prod.outlook.com (2603:10b6:300:109::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16; Thu, 17 Oct 2019 06:22:15 +0000 Received: from BL2NAM02FT005.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::202) by DM6PR02CA0138.outlook.office365.com (2603:10b6:5:1b4::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16 via Frontend Transport; Thu, 17 Oct 2019 06:22:15 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; arm.com; dkim=none (message not signed) header.d=none;arm.com; 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 BL2NAM02FT005.mail.protection.outlook.com (10.152.76.252) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.2367.14 via Frontend Transport; Thu, 17 Oct 2019 06:22:14 +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 1iKzAs-0004bU-AR; Wed, 16 Oct 2019 23:22:14 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1iKzAn-0003mX-78; Wed, 16 Oct 2019 23:22:09 -0700 Received: from [172.23.64.104] (helo=xhdvnc123.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1iKzAc-0003f5-N7; Wed, 16 Oct 2019 23:21:59 -0700 Received: by xhdvnc123.xilinx.com (Postfix, from userid 16987) id DDB8C43A9A; Thu, 17 Oct 2019 11:51: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, rajan.vaja@xilinx.com, nava.manne@xilinx.com, mdf@kernel.org, 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 v3 3/8] mmc: sdhci-of-arasan: Add sampling clock for a phy to use Date: Thu, 17 Oct 2019 11:51:45 +0530 Message-Id: <1571293310-92563-4-git-send-email-manish.narani@xilinx.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1571293310-92563-1-git-send-email-manish.narani@xilinx.com> References: <1571293310-92563-1-git-send-email-manish.narani@xilinx.com> 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)(376002)(346002)(396003)(39860400002)(189003)(199004)(356004)(4326008)(8676002)(14444005)(81156014)(186003)(26005)(70206006)(106002)(2906002)(36756003)(51416003)(316002)(16586007)(70586007)(42186006)(47776003)(126002)(44832011)(476003)(305945005)(486006)(76176011)(2616005)(6666004)(426003)(107886003)(81166006)(446003)(50226002)(11346002)(103686004)(336012)(6266002)(48376002)(8936002)(36386004)(478600001)(50466002)(5660300002)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR02MB2829;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: d0411717-299a-4bb4-d848-08d752ca5a8d X-MS-TrafficTypeDiagnostic: MWHPR02MB2829: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 01930B2BA8 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DBjNxpd2Y8yqHMy83hLavX63nS3K0hqi6fw6blajHU6K7dApdrxuFReR/LpNx3lTnn+ERd/t0r4b6yzeyRxR4y9dDNpABIXQZhsQ3cFOFJCp3/qFr3JdLMIQXm+J5CpKwx+PDdPePTTDjrgn8VxW3kZewRZ7/blPA54ohSM5RBicZWn+vpo1k3jLHMdnlRGgUyERkE+neiEn7hq7BPRiIWHreJ0DxNMXXM1maNqzm/n6fa9sRZ+Wud4af/49t8IeJVXJibHuO4CUFA82hZ91dzUlIuU1kEVOVsUuiEAT1N7mxyVbjCseCodFlhKjgyTOcVRP6axlId/q8OaMZ9tRgwZY7CoXKbBtPSsx841pWtd/cdc7CVdzquLjlchI9mtl+zP358Wx16p+DSd8yqY5kNM/n0o6dzikWUsCh3VmYjI= X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2019 06:22:14.9519 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0411717-299a-4bb4-d848-08d752ca5a8d 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: MWHPR02MB2829 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are some operations like setting the clock delays may need to have two clocks, one for output path and one for input path. Adding input path clock for some phys to use. Signed-off-by: Manish Narani --- drivers/mmc/host/sdhci-of-arasan.c | 151 +++++++++++++++++++++++++---- 1 file changed, 134 insertions(+), 17 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c index 701b6cc0f9a3..f77f884f44a4 100644 --- a/drivers/mmc/host/sdhci-of-arasan.c +++ b/drivers/mmc/host/sdhci-of-arasan.c @@ -75,10 +75,14 @@ struct sdhci_arasan_soc_ctl_map { * struct sdhci_arasan_clk_data * @sdcardclk_hw: Struct for the clock we might provide to a PHY. * @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. */ struct sdhci_arasan_clk_data { struct clk_hw sdcardclk_hw; struct clk *sdcardclk; + struct clk_hw sampleclk_hw; + struct clk *sampleclk; }; /** @@ -541,6 +545,33 @@ static const struct clk_ops arasan_sdcardclk_ops = { .recalc_rate = sdhci_arasan_sdcardclk_recalc_rate, }; +/** + * sdhci_arasan_sampleclk_recalc_rate - Return the sampling clock rate + * + * Return the current actual rate of the sampling clock. This can be used + * to communicate with out PHY. + * + * @hw: Pointer to the hardware clock structure. + * @parent_rate The parent rate (should be rate of clk_xin). + * Returns the sample clock rate. + */ +static unsigned long sdhci_arasan_sampleclk_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) + +{ + struct sdhci_arasan_clk_data *clk_data = + container_of(hw, struct sdhci_arasan_clk_data, sampleclk_hw); + struct sdhci_arasan_data *sdhci_arasan = + container_of(clk_data, struct sdhci_arasan_data, clk_data); + struct sdhci_host *host = sdhci_arasan->host; + + return host->mmc->actual_clock; +} + +static const struct clk_ops arasan_sampleclk_ops = { + .recalc_rate = sdhci_arasan_sampleclk_recalc_rate, +}; + /** * sdhci_arasan_update_clockmultiplier - Set corecfg_clockmultiplier * @@ -620,28 +651,21 @@ static void sdhci_arasan_update_baseclkfreq(struct sdhci_host *host) } /** - * sdhci_arasan_register_sdclk - Register the sdclk for a PHY to use + * sdhci_arasan_register_sdcardclk - Register the sdcardclk for a PHY to use * * Some PHY devices need to know what the actual card clock is. In order for * them to find out, we'll provide a clock through the common clock framework * for them to query. * - * Note: without seriously re-architecting SDHCI's clock code and testing on - * all platforms, there's no way to create a totally beautiful clock here - * with all clock ops implemented. Instead, we'll just create a clock that can - * be queried and set the CLK_GET_RATE_NOCACHE attribute to tell common clock - * framework that we're doing things behind its back. This should be sufficient - * to create nice clean device tree bindings and later (if needed) we can try - * re-architecting SDHCI if we see some benefit to it. - * * @sdhci_arasan: Our private data structure. * @clk_xin: Pointer to the functional clock * @dev: Pointer to our struct device. * Returns 0 on success and error value on error */ -static int sdhci_arasan_register_sdclk(struct sdhci_arasan_data *sdhci_arasan, - struct clk *clk_xin, - struct device *dev) +static int +sdhci_arasan_register_sdcardclk(struct sdhci_arasan_data *sdhci_arasan, + struct clk *clk_xin, + struct device *dev) { struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data; struct device_node *np = dev->of_node; @@ -649,10 +673,6 @@ static int sdhci_arasan_register_sdclk(struct sdhci_arasan_data *sdhci_arasan, const char *parent_clk_name; int ret; - /* Providing a clock to the PHY is optional; no error if missing */ - if (!of_find_property(np, "#clock-cells", NULL)) - return 0; - ret = of_property_read_string_index(np, "clock-output-names", 0, &sdcardclk_init.name); if (ret) { @@ -674,7 +694,56 @@ static int sdhci_arasan_register_sdclk(struct sdhci_arasan_data *sdhci_arasan, ret = of_clk_add_provider(np, of_clk_src_simple_get, clk_data->sdcardclk); if (ret) - dev_err(dev, "Failed to add clock provider\n"); + dev_err(dev, "Failed to add sdcard clock provider\n"); + + return ret; +} + +/** + * sdhci_arasan_register_sampleclk - Register the sampleclk for a PHY to use + * + * Some PHY devices need to know what the actual card clock is. In order for + * them to find out, we'll provide a clock through the common clock framework + * for them to query. + * + * @sdhci_arasan: Our private data structure. + * @clk_xin: Pointer to the functional clock + * @dev: Pointer to our struct device. + * Returns 0 on success and error value on error + */ +static int +sdhci_arasan_register_sampleclk(struct sdhci_arasan_data *sdhci_arasan, + struct clk *clk_xin, + struct device *dev) +{ + struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data; + struct device_node *np = dev->of_node; + struct clk_init_data sampleclk_init; + const char *parent_clk_name; + int ret; + + ret = of_property_read_string_index(np, "clock-output-names", 1, + &sampleclk_init.name); + if (ret) { + dev_err(dev, "DT has #clock-cells but no clock-output-names\n"); + return ret; + } + + parent_clk_name = __clk_get_name(clk_xin); + sampleclk_init.parent_names = &parent_clk_name; + sampleclk_init.num_parents = 1; + sampleclk_init.flags = CLK_GET_RATE_NOCACHE; + sampleclk_init.ops = &arasan_sampleclk_ops; + + clk_data->sampleclk_hw.init = &sampleclk_init; + clk_data->sampleclk = + devm_clk_register(dev, &clk_data->sampleclk_hw); + clk_data->sampleclk_hw.init = NULL; + + ret = of_clk_add_provider(np, of_clk_src_simple_get, + clk_data->sampleclk); + if (ret) + dev_err(dev, "Failed to add sample clock provider\n"); return ret; } @@ -697,6 +766,54 @@ static void sdhci_arasan_unregister_sdclk(struct device *dev) of_clk_del_provider(dev->of_node); } +/** + * sdhci_arasan_register_sdclk - Register the sdcardclk for a PHY to use + * + * Some PHY devices need to know what the actual card clock is. In order for + * them to find out, we'll provide a clock through the common clock framework + * for them to query. + * + * Note: without seriously re-architecting SDHCI's clock code and testing on + * all platforms, there's no way to create a totally beautiful clock here + * with all clock ops implemented. Instead, we'll just create a clock that can + * be queried and set the CLK_GET_RATE_NOCACHE attribute to tell common clock + * framework that we're doing things behind its back. This should be sufficient + * to create nice clean device tree bindings and later (if needed) we can try + * re-architecting SDHCI if we see some benefit to it. + * + * @sdhci_arasan: Our private data structure. + * @clk_xin: Pointer to the functional clock + * @dev: Pointer to our struct device. + * Returns 0 on success and error value on error + */ +static int sdhci_arasan_register_sdclk(struct sdhci_arasan_data *sdhci_arasan, + struct clk *clk_xin, + struct device *dev) +{ + struct device_node *np = dev->of_node; + u32 num_clks = 0; + int ret; + + /* Providing a clock to the PHY is optional; no error if missing */ + if (of_property_read_u32(np, "#clock-cells", &num_clks) < 0) + return 0; + + ret = sdhci_arasan_register_sdcardclk(sdhci_arasan, clk_xin, dev); + if (ret) + return ret; + + if (num_clks) { + ret = sdhci_arasan_register_sampleclk(sdhci_arasan, clk_xin, + dev); + if (ret) { + sdhci_arasan_unregister_sdclk(dev); + return ret; + } + } + + return 0; +} + static int sdhci_arasan_add_host(struct sdhci_arasan_data *sdhci_arasan) { struct sdhci_host *host = sdhci_arasan->host; -- 2.17.1