Re: [PATCH v4 5/9] mfd: Add support for the MediaTek MT6359 PMIC

2021-01-20 Thread Matthias Brugger
On Wed, Dec 16, 2020 at 03:47:03PM +0800, Hsin-Hsiung Wang wrote:
> This adds support for the MediaTek MT6359 PMIC. This is a
> multifunction device with the following sub modules:
> 
> - Codec
> - Interrupt
> - Regulator
> - RTC
> 
> It is interfaced to the host controller using SPI interface
> by a proprietary hardware called PMIC wrapper or pwrap.
> MT6359 MFD is a child device of the pwrap.
> 
> Signed-off-by: Hsin-Hsiung Wang 
> ---
>  drivers/mfd/mt6358-irq.c |  24 ++
>  drivers/mfd/mt6397-core.c|  28 ++
>  include/linux/mfd/mt6359/core.h  | 133 +++
>  include/linux/mfd/mt6359/registers.h | 529 +++
>  include/linux/mfd/mt6397/core.h  |   1 +
>  5 files changed, 715 insertions(+)
>  create mode 100644 include/linux/mfd/mt6359/core.h
>  create mode 100644 include/linux/mfd/mt6359/registers.h
> 
> diff --git a/drivers/mfd/mt6358-irq.c b/drivers/mfd/mt6358-irq.c
> index 4b094e5e51cc..83f3ffbdbb4c 100644
> --- a/drivers/mfd/mt6358-irq.c
> +++ b/drivers/mfd/mt6358-irq.c
> @@ -5,6 +5,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -26,6 +28,17 @@ static const struct irq_top_t mt6358_ints[] = {
>   MT6358_TOP_GEN(MISC),
>  };
>  
> +static const struct irq_top_t mt6359_ints[] = {
> + MT6359_TOP_GEN(BUCK),
> + MT6359_TOP_GEN(LDO),
> + MT6359_TOP_GEN(PSC),
> + MT6359_TOP_GEN(SCK),
> + MT6359_TOP_GEN(BM),
> + MT6359_TOP_GEN(HK),
> + MT6359_TOP_GEN(AUD),
> + MT6359_TOP_GEN(MISC),
> +};
> +
>  static struct pmic_irq_data mt6358_irqd = {
>   .num_top = ARRAY_SIZE(mt6358_ints),
>   .num_pmic_irqs = MT6358_IRQ_NR,
> @@ -33,6 +46,13 @@ static struct pmic_irq_data mt6358_irqd = {
>   .pmic_ints = mt6358_ints,
>  };
>  
> +static struct pmic_irq_data mt6359_irqd = {
> + .num_top = ARRAY_SIZE(mt6359_ints),
> + .num_pmic_irqs = MT6359_IRQ_NR,
> + .top_int_status_reg = MT6359_TOP_INT_STATUS0,
> + .pmic_ints = mt6359_ints,
> +};
> +
>  static void pmic_irq_enable(struct irq_data *data)
>  {
>   unsigned int hwirq = irqd_to_hwirq(data);
> @@ -195,6 +215,10 @@ int mt6358_irq_init(struct mt6397_chip *chip)
>   chip->irq_data = _irqd;
>   break;
>  
> + case MT6359_CHIP_ID:
> + chip->irq_data = _irqd;
> + break;
> +
>   default:
>   dev_err(chip->dev, "unsupported chip: 0x%x\n", chip->chip_id);
>   return -ENODEV;
> diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
> index f6cd8a660602..07240eaf4055 100644
> --- a/drivers/mfd/mt6397-core.c
> +++ b/drivers/mfd/mt6397-core.c
> @@ -13,9 +13,11 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  #define MT6323_RTC_BASE  0x8000
> @@ -99,6 +101,21 @@ static const struct mfd_cell mt6358_devs[] = {
>   },
>  };
>  
> +static const struct mfd_cell mt6359_devs[] = {
> + {
> + .name = "mt6359-regulator",
> + .of_compatible = "mediatek,mt6359-regulator",

This way autoload for the regulator driver will not work. Can you please
test that. From my understanding you can drop the of_compatible here.

Regards,
Matthias

> + }, {
> + .name = "mt6359-rtc",
> + .num_resources = ARRAY_SIZE(mt6358_rtc_resources),
> + .resources = mt6358_rtc_resources,
> + .of_compatible = "mediatek,mt6358-rtc",
> + }, {
> + .name = "mt6359-sound",
> + .of_compatible = "mediatek,mt6359-sound",
> + },
> +};
> +
>  static const struct mfd_cell mt6397_devs[] = {
>   {
>   .name = "mt6397-rtc",
> @@ -149,6 +166,14 @@ static const struct chip_data mt6358_core = {
>   .irq_init = mt6358_irq_init,
>  };
>  
> +static const struct chip_data mt6359_core = {
> + .cid_addr = MT6359_SWCID,
> + .cid_shift = 8,
> + .cells = mt6359_devs,
> + .cell_size = ARRAY_SIZE(mt6359_devs),
> + .irq_init = mt6358_irq_init,
> +};
> +
>  static const struct chip_data mt6397_core = {
>   .cid_addr = MT6397_CID,
>   .cid_shift = 0,
> @@ -218,6 +243,9 @@ static const struct of_device_id mt6397_of_match[] = {
>   }, {
>   .compatible = "mediatek,mt6358",
>   .data = _core,
> + }, {
> + .compatible = "mediatek,mt6359",
> + .data = _core,
>   }, {
>   .compatible = "mediatek,mt6397",
>   .data = _core,
> diff --git a/include/linux/mfd/mt6359/core.h b/include/linux/mfd/mt6359/core.h
> new file mode 100644
> index ..61872f1ecbe4
> --- /dev/null
> +++ b/include/linux/mfd/mt6359/core.h
> @@ -0,0 +1,133 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2020 MediaTek Inc.
> + */
> +
> +#ifndef __MFD_MT6359_CORE_H__
> +#define __MFD_MT6359_CORE_H__
> +
> +enum mt6359_irq_top_status_shift {
> + 

[PATCH v4 5/9] mfd: Add support for the MediaTek MT6359 PMIC

2020-12-15 Thread Hsin-Hsiung Wang
This adds support for the MediaTek MT6359 PMIC. This is a
multifunction device with the following sub modules:

- Codec
- Interrupt
- Regulator
- RTC

It is interfaced to the host controller using SPI interface
by a proprietary hardware called PMIC wrapper or pwrap.
MT6359 MFD is a child device of the pwrap.

Signed-off-by: Hsin-Hsiung Wang 
---
 drivers/mfd/mt6358-irq.c |  24 ++
 drivers/mfd/mt6397-core.c|  28 ++
 include/linux/mfd/mt6359/core.h  | 133 +++
 include/linux/mfd/mt6359/registers.h | 529 +++
 include/linux/mfd/mt6397/core.h  |   1 +
 5 files changed, 715 insertions(+)
 create mode 100644 include/linux/mfd/mt6359/core.h
 create mode 100644 include/linux/mfd/mt6359/registers.h

diff --git a/drivers/mfd/mt6358-irq.c b/drivers/mfd/mt6358-irq.c
index 4b094e5e51cc..83f3ffbdbb4c 100644
--- a/drivers/mfd/mt6358-irq.c
+++ b/drivers/mfd/mt6358-irq.c
@@ -5,6 +5,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +28,17 @@ static const struct irq_top_t mt6358_ints[] = {
MT6358_TOP_GEN(MISC),
 };
 
+static const struct irq_top_t mt6359_ints[] = {
+   MT6359_TOP_GEN(BUCK),
+   MT6359_TOP_GEN(LDO),
+   MT6359_TOP_GEN(PSC),
+   MT6359_TOP_GEN(SCK),
+   MT6359_TOP_GEN(BM),
+   MT6359_TOP_GEN(HK),
+   MT6359_TOP_GEN(AUD),
+   MT6359_TOP_GEN(MISC),
+};
+
 static struct pmic_irq_data mt6358_irqd = {
.num_top = ARRAY_SIZE(mt6358_ints),
.num_pmic_irqs = MT6358_IRQ_NR,
@@ -33,6 +46,13 @@ static struct pmic_irq_data mt6358_irqd = {
.pmic_ints = mt6358_ints,
 };
 
+static struct pmic_irq_data mt6359_irqd = {
+   .num_top = ARRAY_SIZE(mt6359_ints),
+   .num_pmic_irqs = MT6359_IRQ_NR,
+   .top_int_status_reg = MT6359_TOP_INT_STATUS0,
+   .pmic_ints = mt6359_ints,
+};
+
 static void pmic_irq_enable(struct irq_data *data)
 {
unsigned int hwirq = irqd_to_hwirq(data);
@@ -195,6 +215,10 @@ int mt6358_irq_init(struct mt6397_chip *chip)
chip->irq_data = _irqd;
break;
 
+   case MT6359_CHIP_ID:
+   chip->irq_data = _irqd;
+   break;
+
default:
dev_err(chip->dev, "unsupported chip: 0x%x\n", chip->chip_id);
return -ENODEV;
diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index f6cd8a660602..07240eaf4055 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -13,9 +13,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define MT6323_RTC_BASE0x8000
@@ -99,6 +101,21 @@ static const struct mfd_cell mt6358_devs[] = {
},
 };
 
+static const struct mfd_cell mt6359_devs[] = {
+   {
+   .name = "mt6359-regulator",
+   .of_compatible = "mediatek,mt6359-regulator",
+   }, {
+   .name = "mt6359-rtc",
+   .num_resources = ARRAY_SIZE(mt6358_rtc_resources),
+   .resources = mt6358_rtc_resources,
+   .of_compatible = "mediatek,mt6358-rtc",
+   }, {
+   .name = "mt6359-sound",
+   .of_compatible = "mediatek,mt6359-sound",
+   },
+};
+
 static const struct mfd_cell mt6397_devs[] = {
{
.name = "mt6397-rtc",
@@ -149,6 +166,14 @@ static const struct chip_data mt6358_core = {
.irq_init = mt6358_irq_init,
 };
 
+static const struct chip_data mt6359_core = {
+   .cid_addr = MT6359_SWCID,
+   .cid_shift = 8,
+   .cells = mt6359_devs,
+   .cell_size = ARRAY_SIZE(mt6359_devs),
+   .irq_init = mt6358_irq_init,
+};
+
 static const struct chip_data mt6397_core = {
.cid_addr = MT6397_CID,
.cid_shift = 0,
@@ -218,6 +243,9 @@ static const struct of_device_id mt6397_of_match[] = {
}, {
.compatible = "mediatek,mt6358",
.data = _core,
+   }, {
+   .compatible = "mediatek,mt6359",
+   .data = _core,
}, {
.compatible = "mediatek,mt6397",
.data = _core,
diff --git a/include/linux/mfd/mt6359/core.h b/include/linux/mfd/mt6359/core.h
new file mode 100644
index ..61872f1ecbe4
--- /dev/null
+++ b/include/linux/mfd/mt6359/core.h
@@ -0,0 +1,133 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2020 MediaTek Inc.
+ */
+
+#ifndef __MFD_MT6359_CORE_H__
+#define __MFD_MT6359_CORE_H__
+
+enum mt6359_irq_top_status_shift {
+   MT6359_BUCK_TOP = 0,
+   MT6359_LDO_TOP,
+   MT6359_PSC_TOP,
+   MT6359_SCK_TOP,
+   MT6359_BM_TOP,
+   MT6359_HK_TOP,
+   MT6359_AUD_TOP = 7,
+   MT6359_MISC_TOP,
+};
+
+enum mt6359_irq_numbers {
+   MT6359_IRQ_VCORE_OC = 1,
+   MT6359_IRQ_VGPU11_OC,
+   MT6359_IRQ_VGPU12_OC,
+   MT6359_IRQ_VMODEM_OC,
+   MT6359_IRQ_VPROC1_OC,
+   MT6359_IRQ_VPROC2_OC,
+   MT6359_IRQ_VS1_OC,
+