Message ID | 20221005-mt6357-support-v2-0-f17ba2d2d0a9@baylibre.com |
---|---|
Headers | show |
Series | Add MediaTek MT6357 PMIC support | expand |
On Wed, Oct 05, 2022 at 04:57:24PM +0200, Alexandre Mergnat wrote: > +static int mt6357_set_voltage_sel(struct regulator_dev *rdev, > + unsigned int selector) > +{ > + int idx, ret; > + const u32 *pvol; > + struct mt6357_regulator_info *info = rdev_get_drvdata(rdev); > + > + pvol = info->index_table; > + > + idx = pvol[selector]; > + ret = regmap_update_bits(rdev->regmap, info->desc.vsel_reg, > + info->desc.vsel_mask, > + idx << 8); > + > + return ret; > +} There's a bunch of other Mediatek drivers doing this and multiple instances in this driver, the helper should really be factored out.
On Wed, Oct 05, 2022 at 16:57, Alexandre Mergnat <amergnat@baylibre.com> wrote: > From: Fabien Parent <fparent@baylibre.com> > > Add PMIC Keys support on MT6357 SoC. > > Signed-off-by: Fabien Parent <fparent@baylibre.com> > Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> > --- > drivers/input/keyboard/mtk-pmic-keys.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c > index 9b34da0ec260..2a63e0718eb6 100644 > --- a/drivers/input/keyboard/mtk-pmic-keys.c > +++ b/drivers/input/keyboard/mtk-pmic-keys.c > @@ -10,6 +10,7 @@ > #include <linux/kernel.h> > #include <linux/mfd/mt6323/registers.h> > #include <linux/mfd/mt6331/registers.h> > +#include <linux/mfd/mt6357/registers.h> > #include <linux/mfd/mt6358/registers.h> > #include <linux/mfd/mt6397/core.h> > #include <linux/mfd/mt6397/registers.h> > @@ -90,6 +91,19 @@ static const struct mtk_pmic_regs mt6331_regs = { > .rst_lprst_mask = MTK_PMIC_MT6331_RST_DU_MASK, > }; > > +static const struct mtk_pmic_regs mt6357_regs = { > + .keys_regs[MTK_PMIC_PWRKEY_INDEX] = > + MTK_PMIC_KEYS_REGS(MT6357_TOPSTATUS, > + 0x2, MT6357_PSC_TOP_INT_CON0, 0x5, > + MTK_PMIC_PWRKEY_RST), > + .keys_regs[MTK_PMIC_HOMEKEY_INDEX] = > + MTK_PMIC_KEYS_REGS(MT6357_TOPSTATUS, > + 0x8, MT6357_PSC_TOP_INT_CON0, 0xa, > + MTK_PMIC_HOMEKEY_INDEX), > + .pmic_rst_reg = MT6357_TOP_RST_MISC, > + .rst_lprst_mask = MTK_PMIC_RST_DU_MASK, > +}; > + > static const struct mtk_pmic_regs mt6358_regs = { > .keys_regs[MTK_PMIC_PWRKEY_INDEX] = > MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS, > @@ -276,6 +290,9 @@ static const struct of_device_id of_mtk_pmic_keys_match_tbl[] = { > }, { > .compatible = "mediatek,mt6331-keys", > .data = &mt6331_regs, > + }, { > + .compatible = "mediatek,mt6357-keys", > + .data = &mt6357_regs, > }, { > .compatible = "mediatek,mt6358-keys", > .data = &mt6358_regs, > > -- > b4 0.10.1
Il 05/10/22 16:57, Alexandre Mergnat ha scritto: > From: Fabien Parent <fparent@baylibre.com> > > Add regulator driver for the MT6357 PMIC. > > Signed-off-by: Fabien Parent <fparent@baylibre.com> > Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com> > --- > drivers/regulator/Kconfig | 9 + > drivers/regulator/Makefile | 1 + > drivers/regulator/mt6357-regulator.c | 485 +++++++++++++++++++++++++++++ > include/linux/regulator/mt6357-regulator.h | 51 +++ > 4 files changed, 546 insertions(+) > > diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig > index 070e4403c6c2..a659a57438f4 100644 > --- a/drivers/regulator/Kconfig > +++ b/drivers/regulator/Kconfig > @@ -805,6 +805,15 @@ config REGULATOR_MT6332 > This driver supports the control of different power rails of device > through regulator interface > > +config REGULATOR_MT6357 > + tristate "MediaTek MT6357 PMIC" > + depends on MFD_MT6397 > + help > + Say y here to select this option to enable the power regulator of > + MediaTek MT6357 PMIC. > + This driver supports the control of different power rails of device > + through regulator interface. > + > config REGULATOR_MT6358 > tristate "MediaTek MT6358 PMIC" > depends on MFD_MT6397 > diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile > index 5962307e1130..e4d67b7b1af6 100644 > --- a/drivers/regulator/Makefile > +++ b/drivers/regulator/Makefile > @@ -97,6 +97,7 @@ obj-$(CONFIG_REGULATOR_MT6315) += mt6315-regulator.o > obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o > obj-$(CONFIG_REGULATOR_MT6331) += mt6331-regulator.o > obj-$(CONFIG_REGULATOR_MT6332) += mt6332-regulator.o > +obj-$(CONFIG_REGULATOR_MT6357) += mt6357-regulator.o > obj-$(CONFIG_REGULATOR_MT6358) += mt6358-regulator.o > obj-$(CONFIG_REGULATOR_MT6359) += mt6359-regulator.o > obj-$(CONFIG_REGULATOR_MT6360) += mt6360-regulator.o > diff --git a/drivers/regulator/mt6357-regulator.c b/drivers/regulator/mt6357-regulator.c > new file mode 100644 > index 000000000000..4ecd41429448 > --- /dev/null > +++ b/drivers/regulator/mt6357-regulator.c > @@ -0,0 +1,485 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// Copyright (c) 2022 MediaTek Inc. > +// Copyright (c) 2022 BayLibre, SAS. > +// Author: Chen Zhong <chen.zhong@mediatek.com> > +// Author: Fabien Parent <fparent@baylibre.com> > +// > +// Based on mt6397-regulator.c > +// > + > +#include <linux/module.h> > +#include <linux/linear_range.h> > +#include <linux/of.h> > +#include <linux/platform_device.h> > +#include <linux/regmap.h> > +#include <linux/mfd/mt6397/core.h> > +#include <linux/mfd/mt6357/registers.h> > +#include <linux/regulator/driver.h> > +#include <linux/regulator/machine.h> > +#include <linux/regulator/mt6357-regulator.h> > +#include <linux/regulator/of_regulator.h> > + > +/* > + * MT6357 regulators' information > + * > + * @desc: standard fields of regulator description. > + * @vselon_reg: Register sections for hardware control mode of bucks > + * @vselctrl_reg: Register for controlling the buck control mode. > + * @vselctrl_mask: Mask for query buck's voltage control mode. > + */ > +struct mt6357_regulator_info { > + struct regulator_desc desc; > + const u32 *index_table; > + unsigned int n_table; > + u32 vsel_shift; > + u32 da_vsel_reg; > + u32 da_vsel_mask; > + u32 da_vsel_shift; > +}; > + > +#define MT6357_BUCK(match, vreg, min, max, step, \ > + volt_ranges, vosel_reg, vosel_mask, _da_vsel_mask) \ > +[MT6357_ID_##vreg] = { \ > + .desc = { \ > + .name = #vreg, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = "regulators", \ > + .ops = &mt6357_volt_range_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = MT6357_ID_##vreg, \ > + .owner = THIS_MODULE, \ > + .n_voltages = ((max) - (min)) / (step) + 1, \ > + .linear_ranges = volt_ranges, \ > + .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ > + .vsel_reg = vosel_reg, \ > + .vsel_mask = vosel_mask, \ > + .enable_reg = MT6357_BUCK_##vreg##_CON0, \ > + .enable_mask = BIT(0), \ > + }, \ > + .da_vsel_reg = MT6357_BUCK_##vreg##_DBG0, \ > + .da_vsel_mask = vosel_mask, \ > + .da_vsel_shift = 0, \ > +} > + > +#define MT6357_LDO(match, vreg, ldo_volt_table, \ > + ldo_index_table, enreg, vosel, \ > + vosel_mask) \ > +[MT6357_ID_##vreg] = { \ > + .desc = { \ > + .name = #vreg, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = "regulators", \ > + .ops = &mt6357_volt_table_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = MT6357_ID_##vreg, \ > + .owner = THIS_MODULE, \ > + .n_voltages = ARRAY_SIZE(ldo_volt_table), \ > + .volt_table = ldo_volt_table, \ > + .vsel_reg = vosel, \ > + .vsel_mask = vosel_mask << 8, \ > + .enable_reg = enreg, \ > + .enable_mask = BIT(0), \ > + }, \ > + .index_table = ldo_index_table, \ > + .n_table = ARRAY_SIZE(ldo_index_table), \ > +} > + > +#define MT6357_LDO1(match, vreg, min, max, step, volt_ranges, \ > + enreg, vosel, vosel_mask) \ > +[MT6357_ID_##vreg] = { \ > + .desc = { \ > + .name = #vreg, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = "regulators", \ > + .ops = &mt6357_volt_range_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = MT6357_ID_##vreg, \ > + .owner = THIS_MODULE, \ > + .n_voltages = ((max) - (min)) / (step) + 1, \ > + .linear_ranges = volt_ranges, \ > + .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ > + .vsel_reg = vosel, \ > + .vsel_mask = vosel_mask, \ > + .enable_reg = enreg, \ > + .enable_mask = BIT(0), \ > + }, \ > + .da_vsel_reg = MT6357_LDO_##vreg##_DBG0, \ > + .da_vsel_mask = 0x7f, \ > + .da_vsel_shift = 8, \ There's something wrong here: ((val & 0x7f) >> 8) is always zero, and you're using mt6357_volt_range_ops, that is using function mt6357_get_buck_voltage_sel, which is doing exactly that. Regards, Angelo
Il 05/10/22 16:57, Alexandre Mergnat ha scritto: > From: Fabien Parent <fparent@baylibre.com> > > Add PMIC Keys support on MT6357 SoC. > > Signed-off-by: Fabien Parent <fparent@baylibre.com> > Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com> > Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
On Wed, Oct 05, 2022 at 04:57:25PM +0200, Alexandre Mergnat wrote: > From: Fabien Parent <fparent@baylibre.com> > > Add PMIC Keys support on MT6357 SoC. > > Signed-off-by: Fabien Parent <fparent@baylibre.com> > Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Please merge through MFD tree with the rest of the patches. > --- > drivers/input/keyboard/mtk-pmic-keys.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c > index 9b34da0ec260..2a63e0718eb6 100644 > --- a/drivers/input/keyboard/mtk-pmic-keys.c > +++ b/drivers/input/keyboard/mtk-pmic-keys.c > @@ -10,6 +10,7 @@ > #include <linux/kernel.h> > #include <linux/mfd/mt6323/registers.h> > #include <linux/mfd/mt6331/registers.h> > +#include <linux/mfd/mt6357/registers.h> > #include <linux/mfd/mt6358/registers.h> > #include <linux/mfd/mt6397/core.h> > #include <linux/mfd/mt6397/registers.h> > @@ -90,6 +91,19 @@ static const struct mtk_pmic_regs mt6331_regs = { > .rst_lprst_mask = MTK_PMIC_MT6331_RST_DU_MASK, > }; > > +static const struct mtk_pmic_regs mt6357_regs = { > + .keys_regs[MTK_PMIC_PWRKEY_INDEX] = > + MTK_PMIC_KEYS_REGS(MT6357_TOPSTATUS, > + 0x2, MT6357_PSC_TOP_INT_CON0, 0x5, > + MTK_PMIC_PWRKEY_RST), > + .keys_regs[MTK_PMIC_HOMEKEY_INDEX] = > + MTK_PMIC_KEYS_REGS(MT6357_TOPSTATUS, > + 0x8, MT6357_PSC_TOP_INT_CON0, 0xa, > + MTK_PMIC_HOMEKEY_INDEX), > + .pmic_rst_reg = MT6357_TOP_RST_MISC, > + .rst_lprst_mask = MTK_PMIC_RST_DU_MASK, > +}; > + > static const struct mtk_pmic_regs mt6358_regs = { > .keys_regs[MTK_PMIC_PWRKEY_INDEX] = > MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS, > @@ -276,6 +290,9 @@ static const struct of_device_id of_mtk_pmic_keys_match_tbl[] = { > }, { > .compatible = "mediatek,mt6331-keys", > .data = &mt6331_regs, > + }, { > + .compatible = "mediatek,mt6357-keys", > + .data = &mt6357_regs, > }, { > .compatible = "mediatek,mt6358-keys", > .data = &mt6358_regs, > > -- > b4 0.10.1 Thanks.
On Mon, 10 Oct 2022, Dmitry Torokhov wrote: > On Wed, Oct 05, 2022 at 04:57:25PM +0200, Alexandre Mergnat wrote: > > From: Fabien Parent <fparent@baylibre.com> > > > > Add PMIC Keys support on MT6357 SoC. > > > > Signed-off-by: Fabien Parent <fparent@baylibre.com> > > Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com> > > Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> > > Please merge through MFD tree with the rest of the patches. The MFD part is only a small doc change. The Input and Regulator changes should be merged through their own subsystems IMHO.
Hi, This patch series adds MFD, PMIC keys, and regulator support for MT6357. MT6357 is a MediaTek PMIC very similar to MT6358. Regards, Alex Changes in v2: - Rebase - Fix typo - Remove dependencies with https://lore.kernel.org/all/20220415153629.1817202-1-fparent@baylibre.com/ which is no longer relevant. Previous versions: v1 - https://lore.kernel.org/all/20220531124959.202787-1-fparent@baylibre.com/ To: Lee Jones <lee@kernel.org> To: Rob Herring <robh+dt@kernel.org> To: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org> To: Matthias Brugger <matthias.bgg@gmail.com> To: Dmitry Torokhov <dmitry.torokhov@gmail.com> To: Chen Zhong <chen.zhong@mediatek.com> To: Liam Girdwood <lgirdwood@gmail.com> To: Mark Brown <broonie@kernel.org> Cc: devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mediatek@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org Cc: Fabien Parent <fparent@baylibre.com> Cc: Rob Herring <robh@kernel.org> Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com> --- Fabien Parent (5): dt-bindings: mfd: mt6397: add binding for MT6357 dt-bindings: input: mtk-pmic-keys: add binding for MT6357 PMIC dt-bindings: regulator: Add binding schema for mt6357 regulators regulator: add mt6357 regulator Input: mtk-pmic-keys: add MT6357 support .../bindings/input/mediatek,pmic-keys.yaml | 1 + Documentation/devicetree/bindings/mfd/mt6397.txt | 1 + .../regulator/mediatek,mt6357-regulator.yaml | 284 ++++++++++++ drivers/input/keyboard/mtk-pmic-keys.c | 17 + drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/mt6357-regulator.c | 485 +++++++++++++++++++++ include/linux/regulator/mt6357-regulator.h | 51 +++ 8 files changed, 849 insertions(+) --- base-commit: 7c69ce28cba3d6ad011f86a5d18dc8c04a921b29 change-id: 20221005-mt6357-support-55308b82e33f Best regards,