Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4237603ybg; Tue, 29 Oct 2019 04:18:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4gLPyLQZRZxSjCKg3Ofhww8DrQw2RtF3npLESVNo0gpOaiGK1jpyfYxnEw8tcAgAoxi+H X-Received: by 2002:aa7:c645:: with SMTP id z5mr12469752edr.204.1572347882070; Tue, 29 Oct 2019 04:18:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1572347882; cv=pass; d=google.com; s=arc-20160816; b=P0AUI2eCr3dXZu//dcJwT71WA1Qi7X35ouCNz9xiIbTzea7vEbVtJYGDLLOA2bFRWW ixf0zEoPInOyyfDwbY2CMcYa4tiPY1g2L31j1NLIDsgoYsH50lS/7kyH0K6Bj/m5x+Bn Ai4b3uCoxL9GQQDDN0+LdO1f8qCuU6aI5zeZ77t2iFnCEgTKvV0sJAVOF0NQeRhRQWYd QTr3dCt/2HwA4k2VqpTfeNe88Idvu6/QaWs3XTIMS/Us7Rmn+AHbHV0p3kzq1lLDbVIU 54THOo5LZAI3seeez2mS2IZyWgwgxvGrUOVi3OBoaO68de7frfgo26dqGXAwtEYrMtww quvg== 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=k7qbsUFt6gIDpj2dYmDYOFz7It+gjHYfXKxGp9daL6Q=; b=QO//yHq3Ukc6UIPzgY0pJeBgIYheebcr6Ak99RwUwlnbxvkFXTJ9n5bEzCf220Xbgr zG3TObAvB0i6LegLu6QwnepzGchsq1suL/ntqkeDTSyheGSDUhpUH57v3q1yhLVNNqcs nJf62gSPe85VjdZmzApguGWclbKCiXBarC7ubcXBrXhG4VSh+wDfXK+vzYRvwm1F9JCv /ncn86VrmOzqfXFqGLszEIH25orVXeU6IZOJbXy3u60M/B7//uJDxkAndRwg2P612Lo7 lBHUzb8dRArOSvcjtFy8yMaoK5wN45l49Vk/6Ii20qptNZ6M4fMbV35MlGASBUQ6ihNp afwg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector2-xilinx-onmicrosoft-com header.b=Y2mg5Sas; 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 p10si7896258ejf.388.2019.10.29.04.17.38; Tue, 29 Oct 2019 04:18:02 -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=Y2mg5Sas; 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 S1730496AbfJ2KbE (ORCPT + 99 others); Tue, 29 Oct 2019 06:31:04 -0400 Received: from mail-eopbgr790073.outbound.protection.outlook.com ([40.107.79.73]:53472 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727875AbfJ2KbD (ORCPT ); Tue, 29 Oct 2019 06:31:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bRCJA60GQkFgkmDETlihb7+gYHI87fv18OK0ltTip0frjgVebmt0QXwKhvCjLNahNphbHTuLMH53NR5jgcRxJ6AR17KWooi8LGHs8W5mJtKeLLXqR8ZwzkaUFEExgstZkXk2hQQazDBQQNwG4Cr6MFzhX2lHwKRIqTUt1m7XHn7pXull5Lf5VhqY/oZjIDu9thAmk5S8op+LsqNZBEcp9AwqrOTQutc+5k8I+Y0qSMSLZSkz0XY16Ghb293yhRVN3SL7inmmWGTlFsMlkMv0ndGT7OHcHXa/L4/OxWeDCJNBisZkoviSFr6z884HMBev+DeGdoz5OHBWCLVC68htfg== 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=k7qbsUFt6gIDpj2dYmDYOFz7It+gjHYfXKxGp9daL6Q=; b=RPwYn9NowNx6evtc2u9saGUOa4J6rQvzGTl/yf0AKCrwtbGE/I7J129MYiU0jOP9ss3XB5rfLIxULOxdTHHKC+MkJCWAlp7UhWsmLaSLXedPhOY4pu0ofSL6hL530Hwh4A2PTzqcl3YtDTYD4e1+1A6I0UGE49spBRPebqykr9adJ4rXV9w3VbK7WRl4spb7RQLYg8ceB8Z6tScF3GwA+e4gioqHZ7+DRoCnRdtrdhMTCz/+pLRVrLL4FkDPJbZwwrxZ5L6qWorPJJKWyFEk2ajbgx4C32xbV9VLjHvnGYVOqyF0znirbImytZhnKTwmpmnHRXPh0TkH9LgzB4cfVA== 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=k7qbsUFt6gIDpj2dYmDYOFz7It+gjHYfXKxGp9daL6Q=; b=Y2mg5Sas96pznHk2bL3g//Gb6C+X7Q6nD48XQrP7WyKZr+x3+pQAKS5CoD+HguQgkQIzGPHWRdoFpW8Y9jXagt0Meb+oymhOHOcPX5AKZ7c8/cWbYiIQfbgjaJojzhPuMvouavLv9jwI0SKdZ8hOIDZwqhkRdI3MrwnZP5mbwO0= Received: from BL0PR02CA0117.namprd02.prod.outlook.com (2603:10b6:208:35::22) by BL0PR02MB4401.namprd02.prod.outlook.com (2603:10b6:208:40::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.22; Tue, 29 Oct 2019 10:30:52 +0000 Received: from BL2NAM02FT048.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::202) by BL0PR02CA0117.outlook.office365.com (2603:10b6:208:35::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2408.17 via Frontend Transport; Tue, 29 Oct 2019 10:30:52 +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 BL2NAM02FT048.mail.protection.outlook.com (10.152.76.109) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.2387.20 via Frontend Transport; Tue, 29 Oct 2019 10:30:51 +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 1iPOm3-0002t7-6M; Tue, 29 Oct 2019 03:30:51 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1iPOly-0005lF-16; Tue, 29 Oct 2019 03:30:46 -0700 Received: from [172.23.64.106] (helo=xhdvnc125.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1iPOlx-0005kY-3r; Tue, 29 Oct 2019 03:30:45 -0700 Received: by xhdvnc125.xilinx.com (Postfix, from userid 16987) id 650FE121750; Tue, 29 Oct 2019 16:00:44 +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 v4 3/8] mmc: sdhci-of-arasan: Add sampling clock for a phy to use Date: Tue, 29 Oct 2019 16:00:37 +0530 Message-Id: <1572345042-101207-3-git-send-email-manish.narani@xilinx.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1572345042-101207-1-git-send-email-manish.narani@xilinx.com> References: <1572345042-101207-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)(39860400002)(376002)(396003)(346002)(136003)(199004)(189003)(6666004)(42186006)(356004)(16586007)(26005)(316002)(51416003)(76176011)(186003)(48376002)(305945005)(478600001)(36386004)(5660300002)(47776003)(106002)(6266002)(50466002)(50226002)(4326008)(107886003)(8936002)(103686004)(8676002)(81156014)(81166006)(426003)(126002)(2616005)(476003)(446003)(11346002)(14444005)(336012)(486006)(70206006)(44832011)(70586007)(2906002)(36756003);DIR:OUT;SFP:1101;SCL:1;SRVR:BL0PR02MB4401;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;LANG:en;PTR:unknown-60-83.xilinx.com;A:1;MX:1; MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c2984c26-cf70-4cbf-1e7d-08d75c5b12a6 X-MS-TrafficTypeDiagnostic: BL0PR02MB4401: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 0205EDCD76 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PFaNsYhyRIWlJZ3ZQJ0SfHzh8XG4E3xMx/VvR1OR2tFmdRCMV3eEisdd2DQyGz7m6XfOROMoQd+fZhpwb2fUlzypp3nqBw1oOmBEB+3e56Ga1doB3KwWZqmRzwM97XHbS/Xwe/WIS5d/EleIc3lyN+WvukUspz+vnOa/OHvC2Bjjyow2PY05iEtn/88uvIP3WF9zwggDzZp/FrhhMPMSl+cUj8kz89V3/wgXV78uktZX2PZcO1Hscp1oGV7Cf3cb4jhFc25X3vdQCQVq2PW98clUQyh6/APUsb8g36No4ub0HBtsw0ju0BSSrBsJX+mpn9/JakiXc6STxAL2wJOxAwqvV7uGxzMtdcTUv3zfx/hSowV/46J4l9xFDDQc8rLw2YB8KisjpuaV0QONuINZAlkdTdEy/XTRIUQq1GE0CP8hVgIUC4yMucXsx+4L7HWL X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2019 10:30:51.8078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c2984c26-cf70-4cbf-1e7d-08d75c5b12a6 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: BL0PR02MB4401 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..b75ba780f902 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