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 6E4ADC433EF for ; Fri, 20 May 2022 07:20:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C3F2E83E8B; Fri, 20 May 2022 09:20:41 +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="kgcM+QZ/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 804BE83EB3; Fri, 20 May 2022 09:20:40 +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 586E883E81 for ; Fri, 20 May 2022 09:20:36 +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=1139ae0037=patrick.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 24K5vaCR014061 for ; Fri, 20 May 2022 09:20:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=ckpWeKPdLAW+aqIePEjCKXGsxvMx/tIbwIslOPz/rFk=; b=kgcM+QZ/39BiydPuVvXWymqDIe5O/DtGEnAVSWI7oYhWbmErSlzvVl15KrYXGEiDiogV o9tZxmBxI/f1wVVAg7kLK15GwTy7bHyUeOk0lra70yUnSoII0LBp6ZWBc5T4T/B64Tgt yqL3I/cgUdFtYAmICzi6eOh6HyUStgc10N9WYNVkDlzgCT/JF50OU3EvYU9Dng6esUzQ hMTFBPe+/k/OX1SVUCFPxyyIoGnvZIuoRhMHezwXUjLK5uQ7cqg1vAQr7PNnXnjI8/bI hBY/BX+icW8G1TSFzwlgOO86+MCjLL5gjosKiOFkImurwp3GLbELDFkUg7B5xgoJlu/i MA== 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 3g23aj6e6n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 20 May 2022 09:20:35 +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 819FC100034 for ; Fri, 20 May 2022 09:20:34 +0200 (CEST) Received: from Webmail-eu.st.com (eqndag1node6.st.com [10.75.129.135]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 7B34F2128BF for ; Fri, 20 May 2022 09:20:34 +0200 (CEST) Received: from [10.48.0.213] (10.75.127.51) by EQNDAG1NODE6.st.com (10.75.129.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 09:20:30 +0200 Message-ID: Date: Fri, 20 May 2022 09:20:29 +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] ARM: dts: stm32: Configure Buck3 voltage per PMIC NVM on Avenger96 Content-Language: en-US To: References: <20220511210933.191998-1-marex@denx.de> <7ee99fd1-b7ae-582d-9f38-91c26619a216@foss.st.com> From: Patrick DELAUNAY In-Reply-To: <7ee99fd1-b7ae-582d-9f38-91c26619a216@foss.st.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To EQNDAG1NODE6.st.com (10.75.129.135) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_02,2022-05-19_03,2022-02-23_01 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, On 5/17/22 14:39, Patrick DELAUNAY wrote: > Hi, > > On 5/11/22 23:09, Marek Vasut wrote: >> The Avenger96 board comes in multiple regulator configurations. >>   - rev.100 or rev.200 have Buck3 preconfigured to 3V3 operation on >>     boot and contains extra Enpirion EP53A8LQI DCDC converter which >>     supplies the IO. Reduce Buck3 voltage to 2V9 to not waste power. >>   - rev.200L have Buck3 preconfigured to 1V8 operation and have no >>     Enpirion EP53A8LQI DCDC anymore, the IO is supplied from Buck3. >> >> Configure the Buck3 voltage on this board per PMIC NVM settings and >> update buck3 voltage limits in DT passed to OS before booting OS to >> prevent potential hardware damage. >> >> Signed-off-by: Marek Vasut >> Cc: Patrice Chotard >> Cc: Patrick Delaunay >> --- >>   arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi |   2 +- >>   board/dhelectronics/dh_stm32mp1/board.c   | 109 +++++++++++++++++++++- >>   2 files changed, 107 insertions(+), 4 deletions(-) >> >> diff --git a/arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi >> b/arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi >> index 9937b28548c..e20917824bf 100644 >> --- a/arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi >> +++ b/arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi >> @@ -19,7 +19,7 @@ >>   }; >>     &vdd >> {http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ >> -    regulator-min-microvolt = <2900000>; >> +    regulator-min-microvolt = <1800000>; >>       regulator-max-microvolt = <2900000>; >>   }; >>   diff --git a/board/dhelectronics/dh_stm32mp1/board.c >> b/board/dhelectronics/dh_stm32mp1/board.c >> index 67273f90992..d407f0bf592 100644 >> --- a/board/dhelectronics/dh_stm32mp1/board.c >> +++ b/board/dhelectronics/dh_stm32mp1/board.c >> @@ -594,14 +594,98 @@ static void board_init_fmc2(void) >>       setbits_le32(STM32_FMC2_BASE + STM32_FMC2_BCR1, >> STM32_FMC2_BCRx_FMCEN); >>   } >>   +#ifdef CONFIG_DM_REGULATOR >> +#define STPMIC_NVM_BUCKS_VOUT_SHR >> http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ >> 0xfc >> +#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V2        0 >> +#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V8        1 >> +#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V0        2 >> +#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3        3 >> +#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK        GENMASK(1, 0) >> +#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(n)    ((((n) - 1) & 3) >> * 2) >> +static int board_get_regulator_buck3_nvm_uv_av96(int *uv) >> +{ >> +    const void *fdt = gd->fdt_blob; >> +    struct udevice *dev; >> +    u8 bucks_vout = 0; >> +    const char *prop; >> +    int len, ret; >> + >> +    /* Check whether this is Avenger96 board. */ >> +    prop = fdt_getprop(fdt, 0, "compatible", &len); > > > This API is not compatible with CONFIG_OF_LIVE > > consider replacement with ofnode_read_prop or with > of_machine_is_compatible, for example > > if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96")) >     return -EINVAL; > > See also > http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ > > >> +    if (!prop || !len) >> +        return -ENODEV; >> + >> +    if (!strstr(prop, "avenger96")) >> +        return -EINVAL; >> + >> +    /* Read out STPMIC1 NVM and determine default Buck3 voltage. */ >> +    ret = uclass_get_device_by_driver(UCLASS_MISC, >> +                      DM_DRIVER_GET(stpmic1_nvm), >> +                      &dev); >> +    if (ret) >> +        return ret; >> + >> +    ret = misc_read(dev, STPMIC_NVM_BUCKS_VOUT_SHR, &bucks_vout, 1); >> +    if (ret != 1) >> +        return -EINVAL; >> + >> +    bucks_vout >>= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(3); >> +    bucks_vout &= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK; >> + >> +    /* >> +     * Avenger96 board comes in multiple regulator configurations: >> +     * - rev.100 or rev.200 have Buck3 preconfigured to 3V3 >> operation on >> +     *   boot and contains extra Enpirion EP53A8LQI DCDC converter >> which >> +     *   supplies the IO. Reduce Buck3 voltage to 2V9 to not waste >> power. >> +     * - rev.200L have Buck3 preconfigured to 1V8 operation and have no >> +     *   Enpirion EP53A8LQI DCDC anymore, >> http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/the >> IO is supplied from Buck3. >> +     */ >> +    if (bucks_vout == STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3) >> +        *uv = 2900000; >> +    else >> +        *uv = 1800000; >> + >> +    return 0; >> +} >> + >> +static void board_init_regulator_av96(void) >> +{ >> +    struct udevice *rdev; >> +    int ret, uv; >> + >> +    ret = board_get_regulator_buck3_nvm_uv_av96(&uv); >> +    if (ret)    /* Not Avenger96 board. */ >> +        return; >> + >> +    ret = regulator_get_by_devname("buck3", &rdev); >> +    if (ret) >> +        return; >> + >> +    /* Adjust Buck3 per preconfigured PMIC voltage from NVM. */ >> +    regulator_set_value(rdev, uv); >> +} >> + >> +static void board_init_regulator(void) >> +{ >> +    board_init_regulator_av96(); >> + >> + >> regulators_enable_boot_on(_DEBUG);http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ >> +} >> +#else >> +static inline int board_get_regulator_buck3_nvm_uv_av96(int *uv) >> +{ >> +    return -EINVAL; >> +} >> + >> +static inline void board_init_regulator(void) {} >> +#endif >> + >>   /* board dependent setup after realloc */ >>   int board_init(void) >>   { >>       board_key_check(); >> http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ >> -#ifdef CONFIG_DM_REGULATOR >> -    regulators_enable_boot_on(_DEBUG); >> -#endif >> +    board_init_regulator(); >>         sysconf_init(); >>   @@ -721,6 +805,25 @@ int board_interface_eth_init(struct udevice *dev, >>   #if defined(CONFIG_OF_BOARD_SETUP) >>   int ft_board_setup(void *blob, struct bd_info *bd) >>   { >> +    const char *buck3path = >> "/soc/i2c@5c002000/stpmic@33/regulators/buck3"; >> +    int buck3off, ret, uv; >> + >> +    ret = >> board_get_regulator_buck3_nvm_uvhttp://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/_av96(&uv); >> +    if (ret)    /* Not Avenger96 board, do not patch Buck3 in DT. */ >> +        return 0; >> + >> +    buck3off = fdt_path_offset(blob, buck3path); >> +    if (buck3off < 0)    /* No Buck3 regulator found. */ >> +        return 0; >> + >> +    ret = fdt_setprop_u32(blob, buck3off, "regulator-min-microvolt", >> uv); >> +    if (ret < 0) >> +        return ret; >> + >> +    ret = fdt_setprop_u32(blob, buck3off, "regulator-max-microvolt", >> uv); >> +    if (ret < 0) >> +        return ret; >> +http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ >> >>       return 0; >>   } >>   #endif > > > Reviewed-by: Patrick Delaunay > > Thanks > Patrick > Applied to u-boot-stm/master, thanks! Regards Patrick