From patchwork Tue Apr 21 15:11:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Delaunay X-Patchwork-Id: 238206 List-Id: U-Boot discussion From: patrick.delaunay at st.com (Patrick Delaunay) Date: Tue, 21 Apr 2020 17:11:26 +0200 Subject: [PATCH 7/9] board: st: stpmic1: add function stmpic_buck1_set In-Reply-To: <20200421151128.18072-1-patrick.delaunay@st.com> References: <20200421151128.18072-1-patrick.delaunay@st.com> Message-ID: <20200421171123.7.Ibcf2b148dc7ba271546063667955e82cf997d7ee@changeid> Add a function stmpic_buck1_set to configure buck1 voltage in SPL as regulator framework is not available. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/common/stpmic1.c | 24 ++++++++++++++++++++++++ board/st/common/stpmic1.h | 6 ++++++ 2 files changed, 30 insertions(+) create mode 100644 board/st/common/stpmic1.h diff --git a/board/st/common/stpmic1.c b/board/st/common/stpmic1.c index ca10a2246b..a912242ad9 100644 --- a/board/st/common/stpmic1.c +++ b/board/st/common/stpmic1.c @@ -9,6 +9,30 @@ #include #include +int stmpic_buck1_set(u32 voltage_mv) +{ + struct udevice *dev; + int ret; + u32 value; + + ret = uclass_get_device_by_driver(UCLASS_PMIC, + DM_GET_DRIVER(pmic_stpmic1), &dev); + if (ret) + return ret; + + /* VDDCORE= STMPCI1 BUCK1 ramp=+25mV, 5 => 725mV, 36 => 1500mV */ + value = ((voltage_mv - 725) / 25) + 5; + if (value < 5) + value = 5; + if (value > 36) + value = 36; + + return pmic_clrsetbits(dev, + STPMIC1_BUCKX_MAIN_CR(STPMIC1_BUCK1), + STPMIC1_BUCK_VOUT_MASK, + STPMIC1_BUCK_VOUT(value)); +} + int board_ddr_power_init(enum ddr_type ddr_type) { struct udevice *dev; diff --git a/board/st/common/stpmic1.h b/board/st/common/stpmic1.h new file mode 100644 index 0000000000..a020dddbe0 --- /dev/null +++ b/board/st/common/stpmic1.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ +/* + * Copyright (C) 2020, STMicroelectronics - All Rights Reserved + */ + +int stmpic_buck1_set(u32 voltage_mv);