Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp154946pxb; Thu, 14 Jan 2021 02:26:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4kYzj3aPWkic35hCnS4iv7xIvCU3iwnf9OgMK61816SbFad+61tp4VdhNtbxxfGXtMelc X-Received: by 2002:a05:6402:424a:: with SMTP id g10mr5176080edb.236.1610619966103; Thu, 14 Jan 2021 02:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610619966; cv=none; d=google.com; s=arc-20160816; b=waLvEeQK2N+C2uUIf3hzjPKrmAvUIBVACSW06eZ726OSvKnHXqJ25Bsb5V9CLuarqL R6K/BeJE/fPyi4txxnDsIGZoDzVXEMsCOZc+oj8c30gitmQ83nqQjIInLZbwlp4KTkut UWYscumped74JnXKd78mVDPchIUNLar4sfPFe6pTW6YPzn11DJCJ0CHsoEvm1Fydbpjn 8jMmGzRux3cCc9RL6MtmBDPp2+Rz4X+4iCE/XWEfC8/FgWyhPg1MCaK0trqJqym1Laah FDExDtPXntdiGDr1RZymAyrOek0UcIHmCqP3ulV+7t4bNLXuNjATy1rGvh/hm9aZBzXi d2xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DDk9Rejbn/sUw5+U6OTrWK27xmNxoSdD8bZ1t4GVGKo=; b=xGuFa3OclH+rNDVRyAfDJQrPEYCoqEqcai8AIkmNkKFVhgDINdXEOlE5cUg5mmihRv 24FEc2oxxNTYcTdG1OCgTclfP99aOirc6uWpkxYCg55pJamtMgTCEvxR4an+Sc0xMtau VDMf8rtu2JvLAmeiz7M8b0iQm9/fQfJU1TCs6341Yyvnkk7dn8uBRC8IVBr3lpIWQEv4 XlHwBmbsoCAXrPata2O245PEUGGw45eF14SmLeinJD50x3dcuXzsJm4/XtVpGh/ZNMIM 9xGv9BhqlTBi3hFCDVob3GKEVUUPApbTsE6JEHTTOf255SvediOxmaXCax1TW5LZZ9Y9 sXHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=1AxBlQbq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f7si2456428edd.574.2021.01.14.02.25.40; Thu, 14 Jan 2021 02:26:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=1AxBlQbq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728639AbhANKVM (ORCPT + 99 others); Thu, 14 Jan 2021 05:21:12 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:27696 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728535AbhANKUz (ORCPT ); Thu, 14 Jan 2021 05:20:55 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 10EAGtIE027251; Thu, 14 Jan 2021 11:20:02 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=DDk9Rejbn/sUw5+U6OTrWK27xmNxoSdD8bZ1t4GVGKo=; b=1AxBlQbqbqQhSgppZxaDfF/TCBm2YvG7bjmcKJW6GfBORr90VdaXg6tm8FfMAXS3VTK6 qEzdXRYPeatGtwgQUPRhyoGLJBCk9WoolSCISRa5yHgl/SWQLpMVbAG+GabgiVHEhO5H 1/kttBPrued2kvqHfDElJEx0e7wvsUjPOnsLn0Xs/VhTVEEk2Ndn5+cXAuEX8DbbwhrZ zOLs/NnG2YTVLFS3/tbamcA0+dazmkN8TLmBYzSbRCADIy0QAwt5hndAI98mT58L49Ug NbStre5cUZJGJn7we2gBDHbFC50TFo01MWtX1XQScZq73U68oHT3qKSutOSxlJG737ub lg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35yp3y1p96-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Jan 2021 11:20:02 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id BA71A10002A; Thu, 14 Jan 2021 11:20:01 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id A976222E763; Thu, 14 Jan 2021 11:20:01 +0100 (CET) Received: from localhost (10.75.127.45) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 14 Jan 2021 11:20:01 +0100 From: Amelie Delaunay To: Kishon Vijay Abraham I , Vinod Koul , Rob Herring , Alexandre Torgue , Maxime Coquelin CC: , , , , Amelie Delaunay Subject: [PATCH 2/2] phy: stm32: register usbphyc as clock provider of ck_usbo_48m clock Date: Thu, 14 Jan 2021 11:19:49 +0100 Message-ID: <20210114101949.23859-3-amelie.delaunay@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210114101949.23859-1-amelie.delaunay@foss.st.com> References: <20210114101949.23859-1-amelie.delaunay@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG3NODE3.st.com (10.75.127.9) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-14_03:2021-01-13,2021-01-14 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ck_usbo_48m is generated by usbphyc PLL and used by OTG controller for Full-Speed use cases with dedicated Full-Speed transceiver. ck_usbo_48m is available as soon as the PLL is enabled. Signed-off-by: Amelie Delaunay --- drivers/phy/st/phy-stm32-usbphyc.c | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/phy/st/phy-stm32-usbphyc.c b/drivers/phy/st/phy-stm32-usbphyc.c index d08fbb180e43..349976259112 100644 --- a/drivers/phy/st/phy-stm32-usbphyc.c +++ b/drivers/phy/st/phy-stm32-usbphyc.c @@ -7,6 +7,7 @@ */ #include #include +#include #include #include #include @@ -70,6 +71,7 @@ struct stm32_usbphyc { struct regulator *vdda1v1; struct regulator *vdda1v8; atomic_t n_pll_cons; + struct clk_hw clk48_hw; int switch_setup; }; @@ -295,6 +297,61 @@ static const struct phy_ops stm32_usbphyc_phy_ops = { .owner = THIS_MODULE, }; +static int stm32_usbphyc_clk48_prepare(struct clk_hw *hw) +{ + struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw); + + return stm32_usbphyc_pll_enable(usbphyc); +} + +static void stm32_usbphyc_clk48_unprepare(struct clk_hw *hw) +{ + struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw); + + stm32_usbphyc_pll_disable(usbphyc); +} + +static unsigned long stm32_usbphyc_clk48_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) +{ + return 48000000; +} + +static const struct clk_ops usbphyc_clk48_ops = { + .prepare = stm32_usbphyc_clk48_prepare, + .unprepare = stm32_usbphyc_clk48_unprepare, + .recalc_rate = stm32_usbphyc_clk48_recalc_rate, +}; + +static void stm32_usbphyc_clk48_unregister(void *data) +{ + struct stm32_usbphyc *usbphyc = data; + + of_clk_del_provider(usbphyc->dev->of_node); + clk_hw_unregister(&usbphyc->clk48_hw); +} + +static int stm32_usbphyc_clk48_register(struct stm32_usbphyc *usbphyc) +{ + struct device_node *node = usbphyc->dev->of_node; + struct clk_init_data init = { }; + int ret = 0; + + init.name = "ck_usbo_48m"; + init.ops = &usbphyc_clk48_ops; + + usbphyc->clk48_hw.init = &init; + + ret = clk_hw_register(usbphyc->dev, &usbphyc->clk48_hw); + if (ret) + return ret; + + ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &usbphyc->clk48_hw); + if (ret) + clk_hw_unregister(&usbphyc->clk48_hw); + + return ret; +} + static void stm32_usbphyc_switch_setup(struct stm32_usbphyc *usbphyc, u32 utmi_switch) { @@ -473,6 +530,13 @@ static int stm32_usbphyc_probe(struct platform_device *pdev) goto clk_disable; } + ret = stm32_usbphyc_clk48_register(usbphyc); + if (ret) { + dev_err(dev, + "failed to register ck_usbo_48m clock: %d\n", ret); + goto clk_disable; + } + version = readl_relaxed(usbphyc->base + STM32_USBPHYC_VERSION); dev_info(dev, "registered rev:%lu.%lu\n", FIELD_GET(MAJREV, version), FIELD_GET(MINREV, version)); @@ -497,6 +561,8 @@ static int stm32_usbphyc_remove(struct platform_device *pdev) if (usbphyc->phys[port]->active) stm32_usbphyc_phy_exit(usbphyc->phys[port]->phy); + stm32_usbphyc_clk48_unregister(usbphyc); + clk_disable_unprepare(usbphyc->clk); return 0; -- 2.17.1