From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4712C433F5 for ; Tue, 10 May 2022 11:31:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B0E86842BE; Tue, 10 May 2022 13:31:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="xeMBvj3y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 627E084268; Tue, 10 May 2022 11:51:38 +0200 (CEST) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C89018416F for ; Tue, 10 May 2022 11:51:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=1129038f24=amelie.delaunay@foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24A6P0p7004391; Tue, 10 May 2022 11:51:33 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=Aa6M1vUXEe4RAdcbiRSFTXPMsw6C6aqXpG4NO6KYQ+Q=; b=xeMBvj3yeey2HS77Qcmit0Z4xN3FXwVHoVXnPUk/NB74BcPuUlMUlCjey+tG/9s17/Zz PH/eB/699PjMnB6B7why+RQS6YSgPDrASGxR9mxJEJT1aenyeElPu2H8SZce9Y1GFyZ0 OO65FjmZb6usf8WsgYNUBUyzavwS+s4nGzIJ1GqkEMycpKT9NlBfnySp03tv6CbhiDps uqEqNOYj3DGFQbcw6pFXcNwjz5cAPQTEoUbpBpl6iyy+SHpW59ZqccmhG8qvYopB/TzZ mUHrdGZiwJTl5v+NeXAELkhRuv8OxZy0Q3KRDTEC3p0JHocLflYPHElCawqtb6f+hsF8 LA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3fwfngh33d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 May 2022 11:51:33 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7BF2010002A; Tue, 10 May 2022 11:51:32 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 713B2214D1F; Tue, 10 May 2022 11:51:32 +0200 (CEST) Received: from [10.211.10.48] (10.75.127.49) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Tue, 10 May 2022 11:51:29 +0200 Message-ID: <8776d357-028b-0d21-cb90-4cbdd73f4ffb@foss.st.com> Date: Tue, 10 May 2022 11:51:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH 1/3] phy: stm32-usbphyc: add counter of PLL consumer Content-Language: en-US To: Patrick DELAUNAY , Sean Anderson , CC: Joe Hershberger , Patrice Chotard , References: <20220426123750.579726-1-patrick.delaunay@foss.st.com> <20220426143736.1.I15bd7c3c8c983d6a6cec3d2ee371d75fe72fcd41@changeid> <27373592-d6c9-ff00-799b-a2f04f4500b1@gmail.com> <0aeffe8a-b73a-5e3d-de89-9938d8d53150@foss.st.com> From: Amelie Delaunay In-Reply-To: <0aeffe8a-b73a-5e3d-de89-9938d8d53150@foss.st.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-10_01,2022-05-09_02,2022-02-23_01 X-Mailman-Approved-At: Tue, 10 May 2022 13:31:06 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Hi Patrick, Hi Sean, On 5/9/22 16:37, Patrick DELAUNAY wrote: > Hi Sean, > > On 5/8/22 20:21, Sean Anderson wrote: >> On 4/26/22 8:37 AM, Patrick Delaunay wrote: >>> Add the counter of the PLL user n_pll_cons managed by the 2 functions >>> stm32_usbphyc_pll_enable / stm32_usbphyc_pll_disable. >>> >>> This counter allow to remove the function stm32_usbphyc_is_init >>> and it is a preliminary step for ck_usbo_48m introduction. >> >> Is it necessary to disable this clock before booting to Linux? If it >> isn't, >> then perhaps it is simpler to just not disable the clock. >> >> --Sean > > > No, it is not necessary, we only need to enable the clock for the first > user. > > I copy the clock behavior from kernel, > > but I agree that can be simpler. > > > Amelie any notice about this point ? > > Do you prefer that I kept the behavior - same as kernel driver - or I > simplify the U-Boot driver ? In case the PLL has not been disabled before Kernel boot, usbphyc Kernel driver will wait for the PLL pwerdown. USB could also not being used in Kernel, so PLL would remain enabled, and would waste power. I am rather in favor of disabling the PLL. Regards, Amelie > > > Patrick > > >> >>> Signed-off-by: Patrick Delaunay >>> --- >>> >>>   drivers/phy/phy-stm32-usbphyc.c | 76 +++++++++++++++++++++------------ >>>   1 file changed, 48 insertions(+), 28 deletions(-) >>> >>> diff --git a/drivers/phy/phy-stm32-usbphyc.c >>> b/drivers/phy/phy-stm32-usbphyc.c >>> index 9c1dcfae52..16c8799eca 100644 >>> --- a/drivers/phy/phy-stm32-usbphyc.c >>> +++ b/drivers/phy/phy-stm32-usbphyc.c >>> @@ -65,6 +65,7 @@ struct stm32_usbphyc { >>>           bool init; >>>           bool powered; >>>       } phys[MAX_PHYS]; >>> +    int n_pll_cons; >>>   }; >>>     static void stm32_usbphyc_get_pll_params(u32 clk_rate, >>> @@ -124,18 +125,6 @@ static int stm32_usbphyc_pll_init(struct >>> stm32_usbphyc *usbphyc) >>>       return 0; >>>   } >>>   -static bool stm32_usbphyc_is_init(struct stm32_usbphyc *usbphyc) >>> -{ >>> -    int i; >>> - >>> -    for (i = 0; i < MAX_PHYS; i++) { >>> -        if (usbphyc->phys[i].init) >>> -            return true; >>> -    } >>> - >>> -    return false; >>> -} >>> - >>>   static bool stm32_usbphyc_is_powered(struct stm32_usbphyc *usbphyc) >>>   { >>>       int i; >>> @@ -148,18 +137,17 @@ static bool stm32_usbphyc_is_powered(struct >>> stm32_usbphyc *usbphyc) >>>       return false; >>>   } >>>   -static int stm32_usbphyc_phy_init(struct phy *phy) >>> +static int stm32_usbphyc_pll_enable(struct stm32_usbphyc *usbphyc) >>>   { >>> -    struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev); >>> -    struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + phy->id; >>>       bool pllen = readl(usbphyc->base + STM32_USBPHYC_PLL) & PLLEN ? >>>                true : false; >>>       int ret; >>>   -    dev_dbg(phy->dev, "phy ID = %lu\n", phy->id); >>> -    /* Check if one phy port has already configured the pll */ >>> -    if (pllen && stm32_usbphyc_is_init(usbphyc)) >>> -        goto initialized; >>> +    /* Check if one consumer has already configured the pll */ >>> +    if (pllen && usbphyc->n_pll_cons) { >>> +        usbphyc->n_pll_cons++; >>> +        return 0; >>> +    } >>>         if (usbphyc->vdda1v1) { >>>           ret = regulator_set_enable(usbphyc->vdda1v1, true); >>> @@ -190,23 +178,19 @@ static int stm32_usbphyc_phy_init(struct phy *phy) >>>       if (!(readl(usbphyc->base + STM32_USBPHYC_PLL) & PLLEN)) >>>           return -EIO; >>>   -initialized: >>> -    usbphyc_phy->init = true; >>> +    usbphyc->n_pll_cons++; >>>         return 0; >>>   } >>>   -static int stm32_usbphyc_phy_exit(struct phy *phy) >>> +static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc) >>>   { >>> -    struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev); >>> -    struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + phy->id; >>>       int ret; >>>   -    dev_dbg(phy->dev, "phy ID = %lu\n", phy->id); >>> -    usbphyc_phy->init = false; >>> +    usbphyc->n_pll_cons--; >>>   -    /* Check if other phy port requires pllen */ >>> -    if (stm32_usbphyc_is_init(usbphyc)) >>> +    /* Check if other consumer requires pllen */ >>> +    if (usbphyc->n_pll_cons) >>>           return 0; >>>         clrbits_le32(usbphyc->base + STM32_USBPHYC_PLL, PLLEN); >>> @@ -235,6 +219,42 @@ static int stm32_usbphyc_phy_exit(struct phy *phy) >>>       return 0; >>>   } >>>   +static int stm32_usbphyc_phy_init(struct phy *phy) >>> +{ >>> +    struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev); >>> +    struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + phy->id; >>> +    int ret; >>> + >>> +    dev_dbg(phy->dev, "phy ID = %lu\n", phy->id); >>> +    if (usbphyc_phy->init) >>> +        return 0; >>> + >>> +    ret = stm32_usbphyc_pll_enable(usbphyc); >>> +    if (ret) >>> +        return log_ret(ret); >>> + >>> +    usbphyc_phy->init = true; >>> + >>> +    return 0; >>> +} >>> + >>> +static int stm32_usbphyc_phy_exit(struct phy *phy) >>> +{ >>> +    struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev); >>> +    struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + phy->id; >>> +    int ret; >>> + >>> +    dev_dbg(phy->dev, "phy ID = %lu\n", phy->id); >>> +    if (!usbphyc_phy->init) >>> +        return 0; >>> + >>> +    ret = stm32_usbphyc_pll_disable(usbphyc); >>> + >>> +    usbphyc_phy->init = false; >>> + >>> +    return log_ret(ret); >>> +} >>> + >>>   static int stm32_usbphyc_phy_power_on(struct phy *phy) >>>   { >>>       struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev); >>> >>