[PATCH v5 2/8] regulator: Add support for MediaTek MT6316 SPMI PMIC Regulators
Chen-Yu Tsai
wenst at chromium.org
Mon Jul 21 22:18:40 PDT 2025
On Tue, Jul 15, 2025 at 10:03 PM AngeloGioacchino Del Regno
<angelogioacchino.delregno at collabora.com> wrote:
>
> Add a driver for the regulators found on all types of the MediaTek
> MT6316 SPMI PMIC, fully controlled by SPMI interface and featuring
> four step down DCDC (buck) converters.
>
> In particular, this includes support for:
> - MT6316(BP/VP): 2+2 Phase (Phase 1: buck1+2, Phase 2: buck3+4)
> - MT6316(CP/HP/KP): 3+1 Phase (Phase 1: buck1+2+4, Phase 2: buck3)
> - MT6316(DP/TP): 4+0 Phase (Single phase, buck1+2+3+4)
You should probably mention here or in the driver with comments that
some parts are not described in the datasheet, or even contradict what
the datasheet says. Examples include:
- set / clear registers for the enable bits
- voltage selector being in weird format
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
> ---
> drivers/regulator/Kconfig | 9 +
> drivers/regulator/Makefile | 1 +
> drivers/regulator/mt6316-regulator.c | 345 +++++++++++++++++++++++++++
> 3 files changed, 355 insertions(+)
> create mode 100644 drivers/regulator/mt6316-regulator.c
>
> diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
> index 7423954153b0..81f2acd0f960 100644
> --- a/drivers/regulator/Kconfig
> +++ b/drivers/regulator/Kconfig
> @@ -864,6 +864,15 @@ config REGULATOR_MT6315
> This driver supports the control of different power rails of device
> through regulator interface.
>
> +config REGULATOR_MT6316
> + tristate "MT6316 SPMI PMIC regulator driver"
> + depends on SPMI || COMPILE_TEST
> + help
> + Say Y here to enable support for 2+2, 3+1 and 4 phase regulators
> + found in the MediaTek MT6316 BP, CP, DP, HP, VP and TP SPMI PMICs.
> + This driver supports the control of different power rails of device
> + through regulator interface.
> +
> config REGULATOR_MT6323
> tristate "MediaTek MT6323 PMIC"
> depends on MFD_MT6397
> diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
> index be98b29d6675..46c0e75f6107 100644
> --- a/drivers/regulator/Makefile
> +++ b/drivers/regulator/Makefile
> @@ -103,6 +103,7 @@ obj-$(CONFIG_REGULATOR_MP886X) += mp886x.o
> obj-$(CONFIG_REGULATOR_MPQ7920) += mpq7920.o
> obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o
> obj-$(CONFIG_REGULATOR_MT6315) += mt6315-regulator.o
> +obj-$(CONFIG_REGULATOR_MT6315) += mt6316-regulator.o
> obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o
> obj-$(CONFIG_REGULATOR_MT6331) += mt6331-regulator.o
> obj-$(CONFIG_REGULATOR_MT6332) += mt6332-regulator.o
> diff --git a/drivers/regulator/mt6316-regulator.c b/drivers/regulator/mt6316-regulator.c
> new file mode 100644
> index 000000000000..952852bbe923
> --- /dev/null
> +++ b/drivers/regulator/mt6316-regulator.c
> @@ -0,0 +1,345 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Copyright (c) 2024 MediaTek Inc.
> +// Copyright (c) 2025 Collabora Ltd
> +// AngeloGioacchino Del Regno <angelogioacchino.delregno at collabora.com>
> +
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/regmap.h>
> +#include <linux/spmi.h>
> +
> +#include <linux/regulator/driver.h>
> +#include <linux/regulator/machine.h>
> +#include <linux/regulator/of_regulator.h>
> +
> +#define MT6316_BUCK_MODE_AUTO 0
> +#define MT6316_BUCK_MODE_FORCE_PWM 1
> +#define MT6316_BUCK_MODE_LP 2
> +
> +#define MT6316_CHIP_ID 0x20b
> +#define MT6316_BUCK_TOP_CON0 0x1440
> +#define EN_SET_OFFSET 0x1
> +#define EN_CLR_OFFSET 0x2
> +
> +#define MT6316_BUCK_TOP_CON1 0x1443
> +
> +#define MT6316_BUCK_TOP_ELR0 0x1448
> +#define MT6316_BUCK_TOP_ELR2 0x144a
> +#define MT6316_BUCK_TOP_ELR4 0x144c
> +#define MT6316_BUCK_TOP_ELR6 0x144e
> +#define MT6316_VSEL_MASK GENMASK(8, 0)
> +
> +#define MT6316_VBUCK1_DBG 0x14a8
> +#define MT6316_VBUCK2_DBG 0x1528
> +#define MT6316_VBUCK3_DBG 0x15a8
> +#define MT6316_VBUCK4_DBG 0x1628
> +#define MT6316_BUCK_QI BIT(0)
> +
> +#define MT6316_BUCK_TOP_4PHASE_TOP_ANA_CON0 0x1688
> +#define MT6316_BUCK_TOP_4PHASE_TOP_ELR_0 0x1690
> +
> +enum mt6316_type {
> + MT6316_TYPE_2PHASE,
> + MT6316_TYPE_3PHASE,
> + MT6316_TYPE_4PHASE
> +};
> +
> +/**
> + * struct mt6316_regulator_info - MT6316 regulators information
> + * @desc: Regulator description structure
> + * @debug_reg: Debug register for regulator status
> + * @lp_mode_reg: Low Power mode register (normal/idle)
> + * @lp_mode_mask: Low Power mode regulator mask
> + * @modeset_reg: AUTO/PWM mode register
> + * @modeset_mask: AUTO/PWM regulator mask
> + */
> +struct mt6316_regulator_info {
> + struct regulator_desc desc;
> + u16 debug_reg;
> + u16 lp_mode_reg;
> + u16 lp_mode_mask;
> + u16 modeset_reg;
> + u16 modeset_mask;
> +};
> +
> +#define MT6316_BUCK(match, vreg_id, min, max, step, vs_reg) \
> +{ \
> + .desc = { \
> + .name = match, \
.supply_name should probably be added for completeness.
> + .of_match = of_match_ptr(match), \
> + .ops = &mt6316_vreg_setclr_ops, \
> + .type = REGULATOR_VOLTAGE, \
> + .owner = THIS_MODULE, \
> + .n_voltages = (max - min) / step + 1, \
> + .min_uV = min, \
> + .uV_step = step, \
Given that the selector _always_ starts from 0 volts, I think this
should have:
.linear_min_sel = min / step,
So that different minimum values work. Or the minimum value should just
be dropped altogether to prevent miscalculation.
See below for more.
[...]
> +/* MT6316BP/VP - 2+2 phase buck */
> +static struct mt6316_regulator_info mt6316bv_regulators[] = {
> + MT6316_BUCK("vbuck12", 1, 0, 1277500, 2500, MT6316_BUCK_TOP_ELR0),
I just noticed that the overview section of the datasheet mentions that
the lowest voltage is 0.4V for all the regulators.
ChenYu
[...]
More information about the Linux-mediatek
mailing list