Add PMIC and SPMI driver for mt8196
Subsystems (11)
cover Add PMIC and SPMI driver for mt8196
This series is based on linux-next.
Changes in v0:
- Modify SPMI driver for mt8196
- Add SPMI PMIC mfd driver
- Add PMIC regulator driver for mt8196
*** BLURB HERE ***
Lu.Tang (5):
pmic: mediatek: Add pmic auxadc driver
pmic: mediatek: Add pmic regulator driver
pmic: mediatek: Add spmi pmic mfd driver
spmi: mediatek: modify spmi dirver for mt8196
dt-bindings: pmic: mediatek: Add pmic documents
.../iio/adc/mediatek,spmi-pmic-auxadc.yaml | 31 + .../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6685.yaml | 50 + .../bindings/mfd/mediatek,spmi-pmic.yaml | 173 +++ .../pinctrl/mediatek,mt65xx-pinctrl.yaml | 1 + drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mtk-spmi-pmic-adc.c | 576 +++++++++ drivers/mfd/Kconfig | 26 + drivers/mfd/Makefile | 2 + drivers/mfd/mt6685-core.c | 83 ++ drivers/mfd/mtk-spmi-pmic.c | 518 ++++++++ drivers/regulator/Kconfig | 34 + drivers/regulator/Makefile | 3 + drivers/regulator/mt6316-regulator.c | 381 ++++++ drivers/regulator/mt6363-regulator.c | 1106 +++++++++++++++++ drivers/regulator/mt6373-regulator.c | 826 ++++++++++++ drivers/spmi/spmi-mtk-pmif.c | 1040 +++++++++++++++- include/linux/mfd/mt6363/core.h | 134 ++ include/linux/mfd/mt6363/registers.h | 168 +++ include/linux/mfd/mt6373/core.h | 94 ++ include/linux/mfd/mt6373/registers.h | 53 + include/linux/regulator/mt6316-regulator.h | 48 + include/linux/regulator/mt6363-regulator.h | 424 +++++++ include/linux/regulator/mt6373-regulator.h | 318 +++++ 25 files changed, 6037 insertions(+), 64 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml create mode 100644 drivers/iio/adc/mtk-spmi-pmic-adc.c create mode 100644 drivers/mfd/mt6685-core.c create mode 100644 drivers/mfd/mtk-spmi-pmic.c create mode 100644 drivers/regulator/mt6316-regulator.c create mode 100644 drivers/regulator/mt6363-regulator.c create mode 100644 drivers/regulator/mt6373-regulator.c create mode 100644 include/linux/mfd/mt6363/core.h create mode 100644 include/linux/mfd/mt6363/registers.h create mode 100644 include/linux/mfd/mt6373/core.h create mode 100644 include/linux/mfd/mt6373/registers.h create mode 100644 include/linux/regulator/mt6316-regulator.h create mode 100644 include/linux/regulator/mt6363-regulator.h create mode 100644 include/linux/regulator/mt6373-regulator.h
Signature · 1 line
2.46.0
PATCH 1/5 pmic: mediatek: Add pmic auxadc driver
From: "Lu.Tang" <[email protected]>
Add pmic mt6363 and mt6373 auxadc driver
--- drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mtk-spmi-pmic-adc.c | 576 ++++++++++++++++++++++++++++ 3 files changed, 587 insertions(+) create mode 100644 drivers/iio/adc/mtk-spmi-pmic-adc.c
drivers/iio/adc/Kconfig +10 -0
@@ -1039,6 +1039,16 @@ config MEDIATEK_MT6577_AUXADC This driver can also be built as a module. If so, the module will be called mt6577_auxadc. +config MEDIATEK_SPMI_PMIC_ADC + tristate "MediaTek SPMI PMIC ADC Support" + depends on MFD_MTK_SPMI_PMIC + help + Say yes here to enable support for MediaTek SPMI PMIC ADC. + The driver supports multiple channels read. + + This driver can also be built as a module. If so, the module will be + called mtk-spmi-pmic-adc. + config MEN_Z188_ADC tristate "MEN 16z188 ADC IP Core support" depends on MCB
drivers/iio/adc/Makefile +1 -0
@@ -91,6 +91,7 @@ obj-$(CONFIG_MEDIATEK_MT6359_AUXADC) += mt6359-auxadc.o obj-$(CONFIG_MEDIATEK_MT6360_ADC) += mt6360-adc.o obj-$(CONFIG_MEDIATEK_MT6370_ADC) += mt6370-adc.o obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o +obj-$(CONFIG_MEDIATEK_SPMI_PMIC_ADC) += mtk-spmi-pmic-adc.o obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o obj-$(CONFIG_MESON_SARADC) += meson_saradc.o obj-$(CONFIG_MP2629_ADC) += mp2629_adc.o
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +576 -0
576 lines not on this page · raw message
Signature · 1 line
2.46.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH 1/5] pmic: mediatek: Add pmic auxadc driver
Il 14/03/25 08:32, Lu.Tang ha scritto:
Quoted 4 lines
From: "Lu.Tang" <[email protected]>
Add pmic mt6363 and mt6373 auxadc driver
Can't you just add MT6363 and MT6373 support to the already present mt6359-auxadc driver?!
Regards,
Angelo
回复: [PATCH 1/5] pmic: mediatek: Add pmic auxadc driver
Update email
-----邮件原件-----
发件人: AngeloGioacchino Del Regno <[email protected]>
发送时间: 2025年3月14日 16:53
收件人: Lu Tang (汤璐) <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Project_Global_Chrome_Upstream_Group <[email protected]>
主题: Re: [PATCH 1/5] pmic: mediatek: Add pmic auxadc driver
External email : Please do not click links or open attachments until you have verified the sender or the content.
Il 14/03/25 08:32, Lu.Tang ha scritto:
Quoted 4 lines
From: "Lu.Tang" <[email protected]>
Add pmic mt6363 and mt6373 auxadc driver
Can't you just add MT6363 and MT6373 support to the already present mt6359-auxadc driver?!
Regards,
Angelo
Re: 回复: [PATCH 1/5] pmic: mediatek: Add pmic auxadc driver
Quoted 2 lines · Lu Tang (汤璐)
Update email
You just sent 10 emails like this to everyone. This is pointless, don't.
Best regards,
Krzysztof
回复: [PATCH 1/5] pmic: mediatek: Add pmic auxadc driver
In reply to Lu.TangUpdate email address
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:32
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Project_Global_Chrome_Upstream_Group <[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 1/5] pmic: mediatek: Add pmic auxadc driver
From: "Lu.Tang" <[email protected]>
Add pmic mt6363 and mt6373 auxadc driver
--- drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mtk-spmi-pmic-adc.c | 576 ++++++++++++++++++++++++++++ 3 files changed, 587 insertions(+) create mode 100644 drivers/iio/adc/mtk-spmi-pmic-adc.c
drivers/iio/adc/Kconfig +10 -0
@@ -1039,6 +1039,16 @@ config MEDIATEK_MT6577_AUXADC This driver can also be built as a module. If so, the module will be called mt6577_auxadc. +config MEDIATEK_SPMI_PMIC_ADC + tristate "MediaTek SPMI PMIC ADC Support" + depends on MFD_MTK_SPMI_PMIC + help + Say yes here to enable support for MediaTek SPMI PMIC ADC. + The driver supports multiple channels read. + + This driver can also be built as a module. If so, the module will be + called mtk-spmi-pmic-adc. + config MEN_Z188_ADC tristate "MEN 16z188 ADC IP Core support" depends on MCB
drivers/iio/adc/Makefile +1 -0
@@ -91,6 +91,7 @@ obj-$(CONFIG_MEDIATEK_MT6359_AUXADC) += mt6359-auxadc.o obj-$(CONFIG_MEDIATEK_MT6360_ADC) += mt6360-adc.o obj-$(CONFIG_MEDIATEK_MT6370_ADC) += mt6370-adc.o obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o +obj-$(CONFIG_MEDIATEK_SPMI_PMIC_ADC) += mtk-spmi-pmic-adc.o obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o obj-$(CONFIG_MESON_SARADC) += meson_saradc.o obj-$(CONFIG_MP2629_ADC) += mp2629_adc.o diff --git a/drivers/iio/adc/mtk-spmi-pmic-adc.c b/drivers/iio/adc/mtk-spmi-pmic-adc.c
new file mode 100644
index 000000000000..61e062bc8cf5
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +565 -0
565 lines not on this page · raw message
--
2.46.0
Jonathan Cameron
maintainerRe: [PATCH 1/5] pmic: mediatek: Add pmic auxadc driver
In reply to Lu.TangQuoted 3 lines · On Fri, 14 Mar 2025 15:32:27 +0800 Lu.Tang <[email protected]> wrote:
From: "Lu.Tang" <[email protected]>
Add pmic mt6363 and mt6373 auxadc driver
On assumption that there is good reason to not combine this with existing driver I'll give it a quick review. Definitely confirm why this can't be combined with existing driver though before looking at this.
Jonathan
Quoted 14 lines
Signed-off-by Lu Tang <[email protected]>--- drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mtk-spmi-pmic-adc.c | 576 ++++++++++++++++++++++++++++ 3 files changed, 587 insertions(+) create mode 100644 drivers/iio/adc/mtk-spmi-pmic-adc.cdrivers/iio/adc/Kconfig +0
-0
drivers/iio/adc/Kconfig config MEDIATEK_MT6577_AUXADC · line 1042
Quoted 4 lines
drivers/iio/adc/Kconfig +1
-0@@ -1039,6 +1039,16 @@ config MEDIATEK_MT6577_AUXADC This driver can also be built as a module. If so, the module will be called mt6577_auxadc. +config MEDIATEK_SPMI_PMIC_ADC
Clearly a history of non compatible mediatek parts so it is probably better to just name this after one of the supported parts than it is to use a generic name.
Quoted 16 lines
drivers/iio/adc/Kconfig +9
-0+ tristate "MediaTek SPMI PMIC ADC Support" + depends on MFD_MTK_SPMI_PMIC + help + Say yes here to enable support for MediaTek SPMI PMIC ADC. + The driver supports multiple channels read. + + This driver can also be built as a module. If so, the module will be + called mtk-spmi-pmic-adc. +drivers/iio/adc/mtk-spmi-pmic-adc.c new file +0
-0
drivers/iio/adc/mtk-spmi-pmic-adc.c line 3
Quoted 3 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +3
-0@@ -0,0 +1,576 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2024 MediaTek Inc.
Update?
drivers/iio/adc/mtk-spmi-pmic-adc.c line 15
Quoted 12 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +12
-0+*/ + +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/iio/iio.h> +#include <linux/kernel.h> +#include <linux/mfd/mt6363/registers.h> +#include <linux/mfd/mt6373/registers.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h>
These shouldn't be used.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 16
Quoted 1 line
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +1
-0+#include <linux/property.h>
only this should be so the of includes should be dropped.
Quoted 8 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +7
-0+#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/syscore_ops.h> + +#include <dt-bindings/iio/mt635x-auxadc.h>
drivers/iio/adc/mtk-spmi-pmic-adc.c line 32
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +9
-0+ +#define AUXADC_RDY_BIT BIT(15) + +#define AUXADC_DEF_R_RATIO 1 +#define AUXADC_DEF_AVG_NUM 32 + +#define AUXADC_AVG_TIME_US 10 +#define AUXADC_POLL_DELAY_US 100 +#define AUXADC_TIMEOUT_US 32000
These aren't really magic values so the only benefit in a define would be to put a comment giving a spec reference next to them. If not consider just putting the values inline.
Quoted 1 line
+#define
VOLT_FULL1840
Prefix all defines with something related to the driver. MT8195_AUXADC_xx
That avoid potential aliasing that can occur with generic names.
Quoted 5 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +5
-0+ +#define IMP_VOLT_FULL 18400 +#define IMIX_R_MIN_MOHM 100 +#define IMIX_R_CALI_CNT 2 +
drivers/iio/adc/mtk-spmi-pmic-adc.c line 48
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+#define EXT_THR_PURES_SHIFT 3 +#define EXT_THR_SEL_MASK 0x1F + +#define DT_CHANNEL_CONVERT (val) ((val) & 0xFF) +#define DT_PURES_CONVERT (val) (((val) & 0xFF00) >> 8) + +struct pmic_adc_device { +struct device *dev; +struct regmap *regmap; +struct mutex lock;
All locks must have comment describing the scope of data they protect.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 49
Quoted 1 line
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +1
-0+struct iio_chan_spec *iio_chans;
Looks like some of these only exist to avoid passing more variables into the dt parsing function. Make them local to the caller of that and pass them in. We should not have them in here.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 60
Quoted 11 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +11
-0+unsigned int nchannels; +const struct auxadc_info *info; +struct regulator *isink_load; +int imix_r; +int imp_curr; +int pre_uisoc; +}; + +static struct pmic_adc_device *imix_r_dev; + +/*
Make this correct kernel-doc. It nearly is already!
drivers/iio/adc/mtk-spmi-pmic-adc.c line 68
Quoted 8 lines
+ * @ch_name: HW channel name
+ * @res: ADC resolution
+ * @r_ratio: resistance ratio, represented by r_ratio[0] / r_ratio[1]
+ * @avg_num: sampling times of AUXADC measurements then average it
+ * @regs: request and data output registers for this channel
+ */drivers/iio/adc/mtk-spmi-pmic-adc.c new file +2
-0+struct auxadc_channels { +enum iio_chan_type type;
Random things aren't documented. Document all structure elements.
Quoted 4 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +4
-0+long info_mask; +/* AUXADC channel attribute */ +const char *ch_name; +unsigned char res;
drivers/iio/adc/mtk-spmi-pmic-adc.c line 82
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+unsigned char r_ratio[2 ]; +unsigned short avg_num; +const struct auxadc_regs *regs; +}; + +#define AUXADC_CHANNEL (_ch_name, _res) \ + [AUXADC_##_ch_name] = { \ + .type = IIO_VOLTAGE, \ + .info_mask = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \
We almost never allow both raw and processed. There are a few exceptions to that rule though. Why does it make sense here?
Quoted 44 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +44
-0+ .ch_name = __stringify(_ch_name), \ + .res = _res, \ + } + +/* +* The array represents all possible AUXADC channels found +* in the supported PMICs. +*/ +static struct auxadc_channels auxadc_chans[] = { +AUXADC_CHANNEL (BATADC ,15 ), +AUXADC_CHANNEL (VCDT ,12 ), +AUXADC_CHANNEL (BAT_TEMP ,12 ), +AUXADC_CHANNEL (CHIP_TEMP ,12 ), +AUXADC_CHANNEL (VCORE_TEMP ,12 ), +AUXADC_CHANNEL (VPROC_TEMP ,12 ), +AUXADC_CHANNEL (VGPU_TEMP ,12 ), +AUXADC_CHANNEL (ACCDET ,12 ), +AUXADC_CHANNEL (HPOFS_CAL ,15 ), +AUXADC_CHANNEL (VTREF ,12 ), +AUXADC_CHANNEL (VBIF ,12 ), +AUXADC_CHANNEL (IMP ,15 ), + [AUXADC_IMIX_R ] = { + .type =IIO_RESISTANCE , + .info_mask =BIT (IIO_CHAN_INFO_RAW ), + .ch_name ="IMIX_R" , + }, +AUXADC_CHANNEL (VSYSSNS ,15 ), +AUXADC_CHANNEL (VIN1 ,15 ), +AUXADC_CHANNEL (VIN2 ,15 ), +AUXADC_CHANNEL (VIN3 ,15 ), +AUXADC_CHANNEL (VIN4 ,15 ), +AUXADC_CHANNEL (VIN5 ,15 ), +AUXADC_CHANNEL (VIN6 ,15 ), +AUXADC_CHANNEL (VIN7 ,15 ), +}; + +struct auxadc_regs { +unsigned int enable_reg; +unsigned int enable_mask; +unsigned int ready_reg; +unsigned int ready_mask; +unsigned int value_reg; +unsigned int ext_thr_sel; +u8 src_sel;
drivers/iio/adc/mtk-spmi-pmic-adc.c line 136
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+}; + +#define AUXADC_REG (_ch_name, _chip, _enable_reg, _enable_mask, _value_reg) \ + [AUXADC_##_ch_name] = { \ + .enable_reg = _chip##_##_enable_reg, \ + .enable_mask = _enable_mask, \ + .ready_reg = _chip##_##_value_reg, \ + .ready_mask = AUXADC_RDY_BIT, \ + .value_reg = _chip##_##_value_reg, \ + } \
Should be no \ on last line.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 147
Quoted 11 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +11
-0+ +#define TIA_ADC_REG (_src_sel, _chip) \ + [AUXADC_VIN##_src_sel] = { \ + .enable_reg = _chip##_AUXADC_RQST1, \ + .enable_mask = BIT(4), \ + .ready_reg = _chip##_AUXADC_ADC_CH12_L, \ + .ready_mask = AUXADC_RDY_BIT, \ + .value_reg = _chip##_AUXADC_ADC_CH12_L, \ + .ext_thr_sel = _chip##_SDMADC_CON0, \ + .src_sel = _src_sel, \ + } \
same here.
Quoted 41 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +41
-0+ +static const struct auxadc_regs mt6363_auxadc_regs_tbl[] = { +AUXADC_REG (BATADC ,MT6363 ,AUXADC_RQST0 ,BIT (0 ),AUXADC_ADC0_L ), +AUXADC_REG (BAT_TEMP ,MT6363 ,AUXADC_RQST0 ,BIT (3 ),AUXADC_ADC3_L ), +AUXADC_REG (CHIP_TEMP ,MT6363 ,AUXADC_RQST0 ,BIT (4 ),AUXADC_ADC4_L ), +AUXADC_REG (VCORE_TEMP ,MT6363 ,AUXADC_RQST3 ,BIT (0 ),AUXADC_ADC38_L ), +AUXADC_REG (VPROC_TEMP ,MT6363 ,AUXADC_RQST3 ,BIT (1 ),AUXADC_ADC39_L ), +AUXADC_REG (VGPU_TEMP ,MT6363 ,AUXADC_RQST3 ,BIT (2 ),AUXADC_ADC40_L ), +AUXADC_REG (VTREF ,MT6363 ,AUXADC_RQST1 ,BIT (3 ),AUXADC_ADC11_L ), + [AUXADC_IMP ] = { + .enable_reg =MT6363_AUXADC_IMP0 , + .enable_mask =BIT (0 ), + .ready_reg =MT6363_AUXADC_IMP1 , + .ready_mask =BIT (7 ), + .value_reg =MT6363_AUXADC_ADC42_L , + }, +AUXADC_REG (VSYSSNS ,MT6363 ,AUXADC_RQST1 ,BIT (6 ),AUXADC_ADC_CH14_L ), +TIA_ADC_REG (1 ,MT6363 ), +TIA_ADC_REG (2 ,MT6363 ), +TIA_ADC_REG (3 ,MT6363 ), +TIA_ADC_REG (4 ,MT6363 ), +TIA_ADC_REG (5 ,MT6363 ), +TIA_ADC_REG (6 ,MT6363 ), +TIA_ADC_REG (7 ,MT6363 ), +}; + +static const struct auxadc_regs mt6373_auxadc_regs_tbl[] = { +AUXADC_REG (CHIP_TEMP ,MT6373 ,AUXADC_RQST0 ,BIT (4 ),AUXADC_ADC4_L ), +AUXADC_REG (VCORE_TEMP ,MT6373 ,AUXADC_RQST3 ,BIT (0 ),AUXADC_ADC38_L ), +AUXADC_REG (VPROC_TEMP ,MT6373 ,AUXADC_RQST3 ,BIT (1 ),AUXADC_ADC39_L ), +AUXADC_REG (VGPU_TEMP ,MT6373 ,AUXADC_RQST3 ,BIT (2 ),AUXADC_ADC40_L ), +TIA_ADC_REG (1 ,MT6373 ), +TIA_ADC_REG (2 ,MT6373 ), +TIA_ADC_REG (3 ,MT6373 ), +TIA_ADC_REG (4 ,MT6373 ), +TIA_ADC_REG (5 ,MT6373 ), +}; + +struct auxadc_info { +const struct auxadc_regs *regs_tbl; +};
drivers/iio/adc/mtk-spmi-pmic-adc.c line 198
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+ +static const struct auxadc_info mt6363_info = { + .regs_tbl = mt6363_auxadc_regs_tbl, +}; + +static const struct auxadc_info mt6373_info = { + .regs_tbl = mt6373_auxadc_regs_tbl, +}; + +#define regmap_bulk_read_poll_timeout (map, addr, val, val_count, cond, sleep_us, timeout_us) \
This looks generic so shouldn't be in a driver. Either propose it for the regmap core, or give it a non generic driver specific name.
Quoted 14 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +14
-0+({ \ + u64 __timeout_us = (timeout_us); \ + unsigned long __sleep_us = (sleep_us); \ + ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \ + int __ret; \ + might_sleep_if(__sleep_us); \ + for (;;) { \ + __ret = regmap_bulk_read((map), (addr), (u8 *) &(val), val_count); \ + if (__ret) \ + break; \ + if (cond) \ + break; \ + if ((__timeout_us) && \ + ktime_compare(ktime_get(), __timeout) > 0) { \
drivers/iio/adc/mtk-spmi-pmic-adc.c line 222
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+ __ret =regmap_bulk_read ((map), (addr), (u8 *) &(val), val_count); \ +break ; \ + } \ +if (__sleep_us) \ +usleep_range ((__sleep_us >>2 ) +1 , __sleep_us); \ + } \ + __ret ?: ((cond) ?0 : -ETIMEDOUT ); \ +}) + +/*
For this sort of text make it all kernel-doc style and run the script on the file to make sure no warnings / errors.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 229
Quoted 7 lines
+ * @adc_dev: pointer to the struct
pmic_adc_device
+ * @auxadc_chan: pointer to the structauxadc_channels, it represents specificdrivers/iio/adc/mtk-spmi-pmic-adc.c new file +5
-0+auxadc channel +* @val: pointer to output value +*/ +static int get_auxadc_out (struct pmic_adc_device *adc_dev, +int channel,int channel2,int *val)
For example these parameters are different from the docs and the kernel-doc script would point that out for you.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 236
Quoted 7 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +7
-0+{ +int ret; +u16 buf =0 ; +const struct auxadc_channels *auxadc_chan = &auxadc_chans[channel]; + +if (!auxadc_chan->regs) +return -EINVAL ;
Why would that happen? Don't defend against things that can't occur.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 240
Quoted 4 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +4
-0+ +if (auxadc_chan->regs->ext_thr_sel) { + buf = (channel2 <<EXT_THR_PURES_SHIFT ) + | auxadc_chan->regs->src_sel;
FIELD_PREP plus use appropriate mask not shift. Also apply FIELD_PREP() for the src_sel.
Avoids anyone needing to check values are in range or where the various register fields are.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 247
Quoted 7 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +7
-0+ ret =regmap_update_bits (adc_dev->regmap, + auxadc_chan->regs->ext_thr_sel, +EXT_THR_SEL_MASK , buf); +if (ret <0 ) +return ret; + } + regmap_write(adc_dev->regmap,
Check for errors.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 255
Quoted 8 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +8
-0+ auxadc_chan->regs->enable_reg, + auxadc_chan->regs->enable_mask); +usleep_range (auxadc_chan->avg_num *AUXADC_AVG_TIME_US , + (auxadc_chan->avg_num +1 ) *AUXADC_AVG_TIME_US ); + + ret = regmap_bulk_read_poll_timeout(adc_dev->regmap, + auxadc_chan->regs->value_reg, + buf, 2,
buf should be u16 and use sizeof(buf) for that 2.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 256
Quoted 1 line
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +1
-0+ (buf & AUXADC_RDY_BIT),
brackets add nothing.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 266
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+AUXADC_POLL_DELAY_US , + AUXADC_TIMEOUT_US); + *val = buf & (BIT (auxadc_chan->res) -1 ); +if (ret) +dev_err (adc_dev->dev,"%s ret error code:%d!\n" , auxadc_chan->ch_name, ret); + +/* set PURES to OPEN after measuring done */ +if (auxadc_chan->regs->ext_thr_sel) { + buf = (ADC_PURES_OPEN <<EXT_THR_PURES_SHIFT ) + | auxadc_chan->regs->src_sel;
FIELD_PREP() for both of those.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 243
Quoted 3 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +3
-0+ ret =regmap_update_bits (adc_dev->regmap, + auxadc_chan->regs->ext_thr_sel, +EXT_THR_SEL_MASK , buf);
Overwrite the earlier error potentially which is not something we normally want to do as can make debugging harder.
Quoted 23 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +23
-0+ } + +return ret; +} + +static int gauge_get_imp_ibat (void ) +{ +struct power_supply *psy; +union power_supply_propval prop; +int ret; + + psy =power_supply_get_by_name ("mtk-gauge" ); +if (!psy) +return 0 ; + + ret =power_supply_get_property (psy,POWER_SUPPLY_PROP_CURRENT_NOW , &prop); +if (ret) +return ret; + +power_supply_put (psy); +return prop.intval; +} +
drivers/iio/adc/mtk-spmi-pmic-adc.c line 302
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+static int get_imp_out (struct pmic_adc_device *adc_dev,int *val) +{ +int ret; +unsigned int buf =0 ; +const struct auxadc_channels *auxadc_chan = &auxadc_chans[AUXADC_IMP ]; + +if (!auxadc_chan->regs) +return -EINVAL ; + + regmap_write(adc_dev->regmap,
Probably worth a local variable for the regmap to shorten some lines.
drivers/iio/adc/mtk-spmi-pmic-adc.c
Quoted 2 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +2
-0+ auxadc_chan->regs->enable_reg, + auxadc_chan->regs->enable_mask);
Check for errors.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 311
Quoted 7 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +7
-0+ ret =regmap_read_poll_timeout (adc_dev->regmap, auxadc_chan->regs->ready_reg, + buf, buf & auxadc_chan->regs->ready_mask, +AUXADC_POLL_DELAY_US , +AUXADC_TIMEOUT_US ); +if (ret) { +dev_err (adc_dev->dev,"%s %s ret error code:%d!\n" , + __func__, auxadc_chan->ch_name, ret);
No need for the __func__ in here. Say what failed in the error message.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 315
Quoted 4 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +4
-0+return ret; + } + + ret =regmap_bulk_read (adc_dev->regmap, auxadc_chan->regs->value_reg, (u8 *) &buf,2 );
Why cast to u8 *? It takes a void * and you never need to cast to that. However, you also shouldn't be doing a 2 byte read into a integer. Use a u16 and get the size with appropriate sizeof()
drivers/iio/adc/mtk-spmi-pmic-adc.c line 322
Quoted 7 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +7
-0+if (ret) +return ret; + *val = buf & (BIT (auxadc_chan->res) -1 ); + adc_dev->imp_curr =gauge_get_imp_ibat (); + +regmap_write (adc_dev->regmap, + auxadc_chan->regs->enable_reg,0 );
Check for errors.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 327
Quoted 5 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +5
-0+ +return 0 ; +} + +static int pmic_adc_read_raw(struct iio_dev *indio_dev,
All functions should be prefixed with driver name. Avoids potential clashes if generic stuff ends up in headers later.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 336
Quoted 9 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +9
-0+struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct pmic_adc_device *adc_dev = iio_priv(indio_dev); +const struct auxadc_channels *auxadc_chan; +int auxadc_out =0 ; +int ret =0 ; + +mutex_lock (&adc_dev->lock);
consider pushing the lock down into the various implementations.
Quoted 7 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +7
-0+switch (chan->channel) { +case AUXADC_IMP : + ret =get_imp_out (adc_dev, &auxadc_out); +break ; +case AUXADC_IMIX_R : + auxadc_out = adc_dev->imix_r; +break ;
drivers/iio/adc/mtk-spmi-pmic-adc.c line 353
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+default : + ret =get_auxadc_out (adc_dev, + chan->channel, chan->channel2, + &auxadc_out); +break ; + } +mutex_unlock (&adc_dev->lock); + +if (ret && ret != -ETIMEDOUT ) +return ret;
Why would you carry on if it timed out?
drivers/iio/adc/mtk-spmi-pmic-adc.c line 359
Quoted 6 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +6
-0+ +switch (mask) { +case IIO_CHAN_INFO_PROCESSED : + auxadc_chan = &auxadc_chans[chan->channel]; + *val = auxadc_out * auxadc_chan->r_ratio[0 ] *VOLT_FULL ; + *val = (*val / auxadc_chan->r_ratio[1 ]) >> auxadc_chan->res;
This looks linear - in which case why not leave the maths to userspace and provide IIO_CHAN_INFO_SCALE + _RAW
drivers/iio/adc/mtk-spmi-pmic-adc.c line 362
Quoted 3 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +3
-0+ ret =IIO_VAL_INT ; +break ; +case IIO_CHAN_INFO_RAW :
Why provide this at all if you are providing processed output.
Quoted 24 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +23
-0+ *val = auxadc_out; + ret =IIO_VAL_INT ; +break ; +default : +return -EINVAL ; + } +if (chan->channel ==AUXADC_IMP ) { + *val2 = adc_dev->imp_curr; + ret =IIO_VAL_INT_MULTIPLE ; + } + +return ret; +} + +static const struct iio_info pmic_adc_info = { + .read_raw = &pmic_adc_read_raw, + .fwnode_xlate = &pmic_adc_fwnode_xlate, +}; + +static int auxadc_init_imix_r (struct pmic_adc_device *adc_dev, +struct device_node *imix_r_node) +{ +unsigned int val =0 ;
drivers/iio/adc/mtk-spmi-pmic-adc.c line 411
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+int ret; + +if (!adc_dev) +return -EINVAL ; + + adc_dev->isink_load =devm_regulator_get_exclusive (adc_dev->dev,"isink_load" ); +if (IS_ERR (adc_dev->isink_load)) { +dev_err (adc_dev->dev,"Failed to get isink_load regulator, ret=%d\n" , + (int )PTR_ERR (adc_dev->isink_load)); +return PTR_ERR (adc_dev->isink_load);
Use dev_err_probe() which will also pretty print the return value so remember to drop that bit.
Quoted 5 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +5
-0+ } + + imix_r_dev = adc_dev; +if (imix_r_dev->imix_r) +return 0 ;
drivers/iio/adc/mtk-spmi-pmic-adc.c line 426
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+ + ret =of_property_read_u32 (imix_r_node,"val" , &val); +if (ret) +dev_notice (imix_r_dev->dev,"no imix_r, ret=%d\n" , ret); + imix_r_dev->imix_r = (int )val; + imix_r_dev->pre_uisoc =101 ; +return 0 ; +} + +static int auxadc_get_data_from_dt(struct pmic_adc_device *adc_dev,
from_fw() and use the generic property.h accessors, not the dt specific ones.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 436
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+struct iio_chan_spec *iio_chan, + struct device_node *node) +{ + struct auxadc_channels *auxadc_chan; +unsigned int channel =0 ; +unsigned int value =0 ; +unsigned int val_arr[2 ] = {0 }; +int ret; + + ret =of_property_read_u32 (node,"channel" , &channel);
That doesn't looks like a standard dt binding. why do you need it vs what is in adc.yaml? Probably just reg is enough.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 439
Quoted 3 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +3
-0+if (ret) { +dev_err (adc_dev->dev,"invalid channel in node:%s\n" , + node->name);
use return dev_err_probe() for all error prints that are part of probe. Gives prettier printing and other benefits in some cases.
Quoted 7 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +7
-0+return ret; + } +if (channel >AUXADC_CHAN_MAX ) { +dev_err (adc_dev->dev,"invalid channel number %d in node:%s\n" , + channel, node->name); +return -EINVAL ; + }
drivers/iio/adc/mtk-spmi-pmic-adc.c line 456
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+if (channel >=ARRAY_SIZE (auxadc_chans)) { +dev_err (adc_dev->dev,"channel number %d in node:%s not exists\n" , + channel, node->name); +return -EINVAL ; + } + iio_chan->channel = channel; + iio_chan->datasheet_name = auxadc_chans[channel].ch_name; + iio_chan->info_mask_separate = auxadc_chans[channel].info_mask; + iio_chan->type = auxadc_chans[channel].type; + iio_chan->extend_name = node->name;
No. This is almost never used in a modern driver as it makes for really nasty userspace ABI. Use label if you need to mark a channel as something specific.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 457
Quoted 1 line
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +1
-0+ ret =of_property_read_u32 (node,"pures" , &value);
I have no idea what this one is or why you'd put anything in channel2 for a single ended ADC channel with no modifier.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 467
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+if (!ret) + iio_chan->channel2 = value; + +if (channel ==AUXADC_IMIX_R ) +return auxadc_init_imix_r (adc_dev, node); + + auxadc_chan = &auxadc_chans[channel]; + auxadc_chan->regs = &adc_dev->info->regs_tbl[channel]; + + ret =of_property_read_u32_array (node,"resistance-ratio" , val_arr,2 );
Interesting but not standard DT binding. In general this seems to have no connect to the dt bindings in this seris.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 476
Quoted 9 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +9
-0+if (!ret) { + auxadc_chan->r_ratio[0 ] = val_arr[0 ]; + auxadc_chan->r_ratio[1 ] = val_arr[1 ]; + }else { + auxadc_chan->r_ratio[0 ] =AUXADC_DEF_R_RATIO ; + auxadc_chan->r_ratio[1 ] =1 ; + } + + ret =of_property_read_u32 (node,"avg-num" , &value);
Also not a standing binding and rarely found in DT because it is usually a policy decision on noise vs sampling rate and exposed as oversampling control to userspace.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 485
Quoted 9 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +9
-0+if (!ret) + auxadc_chan->avg_num = value; +else + auxadc_chan->avg_num =AUXADC_DEF_AVG_NUM ; + +return 0 ; +} + +static int auxadc_parse_dt(struct pmic_adc_device *adc_dev,
parse_fw() as you'll be using generic accessors thoughout.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 493
Quoted 8 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +8
-0+ struct device_node *node) +{ +struct iio_chan_spec *iio_chan; +struct device_node *child; +unsigned int index =0 ; +int ret; + + adc_dev->nchannels =of_get_available_child_count (node);
Use generic property accessors, not of specific ones (property.h)
Quoted 28 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +28
-0+if (!adc_dev->nchannels) +return -EINVAL ; + + adc_dev->iio_chans =devm_kcalloc (adc_dev->dev, adc_dev->nchannels, +sizeof (*adc_dev->iio_chans),GFP_KERNEL ); +if (!adc_dev->iio_chans) +return -ENOMEM ; + iio_chan = adc_dev->iio_chans; + +for_each_available_child_of_node (node, child) { + ret =auxadc_get_data_from_dt (adc_dev, iio_chan, child); +if (ret <0 ) { +of_node_put (child); +return ret; + } + iio_chan->indexed =1 ; + iio_chan->address = index++; + iio_chan++; + } + +return 0 ; +} + +static int pmic_adc_probe (struct platform_device *pdev) +{ +struct device_node *node = pdev->dev.of_node; +struct pmic_adc_device *adc_dev; +struct iio_dev *indio_dev;
drivers/iio/adc/mtk-spmi-pmic-adc.c line 531
Quoted 10 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +10
-0+int ret; + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*adc_dev)); +if (!indio_dev) +return -ENOMEM ; + + adc_dev =iio_priv (indio_dev); + adc_dev->dev = &pdev->dev; + adc_dev->regmap =dev_get_regmap (pdev->dev.parent,NULL ); +mutex_init (&adc_dev->lock);
In new drivers I prefer to see
ret = devm_mutex_init() if (ret) return ret;
Brings only a minor debug benefit, but the cost of getting that is low so it is a nice thing to have!
drivers/iio/adc/mtk-spmi-pmic-adc.c line 540
Quoted 9 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +9
-0+ adc_dev->info =of_device_get_match_data (&pdev->dev); + + ret =auxadc_parse_dt (adc_dev, node); +if (ret) { +dev_notice (&pdev->dev,"auxadc_parse_dt fail, ret=%d\n" , ret); +return ret; + } + + indio_dev->dev.parent = &pdev->dev;
No need for that - it's done the IIO core.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 541
Quoted 1 line
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +1
-0+ indio_dev->name =dev_name (&pdev->dev);
This needs to be the part number, not come from the device name which can be very different depending on how the device is created etc. So just hard code the part number in the info structure and set it here.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 549
Quoted 8 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +8
-0+ indio_dev->info = &pmic_adc_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->channels = adc_dev->iio_chans; + indio_dev->num_channels = adc_dev->nchannels; + + ret =devm_iio_device_register (&pdev->dev, indio_dev); +if (ret <0 ) { +dev_notice (&pdev->dev,"failed to register iio device!\n" );
dev_err() given if you manage to hit here you definitely have an error. Same for other error paths.
drivers/iio/adc/mtk-spmi-pmic-adc.c line 553
Quoted 4 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +4
-0+return ret; + } + +dev_dbg (&pdev->dev,"probe done\n" );
No purpose in this one. It is very easy to see if probe succeeded without it.
Quoted 3 lines
drivers/iio/adc/mtk-spmi-pmic-adc.c new file +3
-0+ +return 0 ; +}
PATCH 2/5 pmic: mediatek: Add pmic regulator driver
In reply to Lu.TangFrom: "Lu.Tang" <[email protected]>
Add pmic mt6316/mt6373/mt6363 regulator driver
--- drivers/regulator/Kconfig | 34 + drivers/regulator/Makefile | 3 + drivers/regulator/mt6316-regulator.c | 381 +++++++ drivers/regulator/mt6363-regulator.c | 1106 ++++++++++++++++++++ drivers/regulator/mt6373-regulator.c | 826 +++++++++++++++ include/linux/regulator/mt6316-regulator.h | 48 + include/linux/regulator/mt6363-regulator.h | 424 ++++++++ include/linux/regulator/mt6373-regulator.h | 318 ++++++ 8 files changed, 3140 insertions(+) create mode 100644 drivers/regulator/mt6316-regulator.c create mode 100644 drivers/regulator/mt6363-regulator.c create mode 100644 drivers/regulator/mt6373-regulator.c create mode 100644 include/linux/regulator/mt6316-regulator.h create mode 100644 include/linux/regulator/mt6363-regulator.h create mode 100644 include/linux/regulator/mt6373-regulator.h
drivers/regulator/Kconfig +34 -0
@@ -853,6 +853,16 @@ config REGULATOR_MT6315 This driver supports the control of different power rails of device through regulator interface. +config REGULATOR_MT6316 + tristate "MediaTek MT6316 PMIC" + depends on SPMI + select REGMAP_SPMI + help + Say y here to select this option to enable the power regulator of + MediaTek MT6316 PMIC. + 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
@@ -916,6 +926,18 @@ config REGULATOR_MT6360 2-channel buck with Thermal Shutdown and Overload Protection 6-channel High PSRR and Low Dropout LDO. +config REGULATOR_MT6363 + tristate "MT6363 SPMI Regulator driver" + depends on MFD_MTK_SPMI_PMIC + help + Say y here to select this option to enable the power regulator of + MediaTek MT6363 PMIC. + This driver supports the control of different power rails of device + through regulator interface. + + The driver can also be build as a module. + If so, the module will be called mt6363_regulator + config REGULATOR_MT6370 tristate "MT6370 SubPMIC Regulator" depends on MFD_MT6370
@@ -924,6 +946,18 @@ config REGULATOR_MT6370 This driver supports the control for DisplayBias voltages and one general purpose LDO which is commonly used to drive the vibrator. +config REGULATOR_MT6373 + tristate "MT6373 SPMI Regulator driver" + depends on MFD_MTK_SPMI_PMIC + help + Say y here to select this option to enable the power regulator of + MediaTek MT6373 PMIC. + This driver supports the control of different power rails of device + through regulator interface. + + The driver can also be build as a module. + If so, the module will be called mt6373_regulator + config REGULATOR_MT6380 tristate "MediaTek MT6380 PMIC" depends on MTK_PMIC_WRAP
drivers/regulator/Makefile +3 -0
@@ -102,6 +102,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_MT6316) += mt6316-regulator.o obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o obj-$(CONFIG_REGULATOR_MT6331) += mt6331-regulator.o obj-$(CONFIG_REGULATOR_MT6332) += mt6332-regulator.o
@@ -109,7 +110,9 @@ 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 +obj-$(CONFIG_REGULATOR_MT6363) += mt6363-regulator.o obj-$(CONFIG_REGULATOR_MT6370) += mt6370-regulator.o +obj-$(CONFIG_REGULATOR_MT6373) += mt6373-regulator.o obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o obj-$(CONFIG_REGULATOR_MTK_DVFSRC) += mtk-dvfsrc-regulator.o
drivers/regulator/mt6316-regulator.c new file +381 -0
381 lines not on this page · raw message
drivers/regulator/mt6363-regulator.c new file +1106 -0
1,106 lines not on this page · raw message
drivers/regulator/mt6373-regulator.c new file +826 -0
826 lines not on this page · raw message
include/linux/regulator/mt6316-regulator.h new file +48 -0
48 lines not on this page · raw message
include/linux/regulator/mt6363-regulator.h new file +424 -0
424 lines not on this page · raw message
include/linux/regulator/mt6373-regulator.h new file +318 -0
147 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.46.0
Part of the diff is not shown here. View the raw message.
Re: [PATCH 2/5] pmic: mediatek: Add pmic regulator driver
Quoted 4 lines · Lu.Tang
From: "Lu.Tang" <[email protected]>
Add pmic mt6316/mt6373/mt6363 regulator driver
Please split this into one patch per PMIC. That will make the patch size much more manageable. And the patch subject should just say what PMIC is added.
Quoted 5 lines
Signed-off-by Lu Tang <[email protected]>--- drivers/regulator/Kconfig | 34 + drivers/regulator/Makefile | 3 + drivers/regulator/mt6316-regulator.c | 381 +++++++
How much of the MT6316 driver is the same or similar to MT6315? AFAICT they are both 4 buck regulators where some of the outputs can be combined into a polyphase output.
Quoted 418 lines
drivers/regulator/mt6363-regulator.c | 1106 ++++++++++++++++++++ drivers/regulator/mt6373-regulator.c | 826 +++++++++++++++ include/linux/regulator/mt6316-regulator.h | 48 + include/linux/regulator/mt6363-regulator.h | 424 ++++++++ include/linux/regulator/mt6373-regulator.h | 318 ++++++ 8 files changed, 3140 insertions(+) create mode 100644 drivers/regulator/mt6316-regulator.c create mode 100644 drivers/regulator/mt6363-regulator.c create mode 100644 drivers/regulator/mt6373-regulator.c create mode 100644 include/linux/regulator/mt6316-regulator.h create mode 100644 include/linux/regulator/mt6363-regulator.h create mode 100644 include/linux/regulator/mt6373-regulator.hdrivers/regulator/Kconfig +34
-0@@ -853,6 +853,16 @@ config REGULATOR_MT6315 This driver supports the control of different power rails of device through regulator interface. +config REGULATOR_MT6316 + tristate "MediaTek MT6316 PMIC" + depends on SPMI + select REGMAP_SPMI + help + Say y here to select this option to enable the power regulator of + MediaTek MT6316 PMIC. + 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@@ -916,6 +926,18 @@ config REGULATOR_MT6360 2-channel buck with Thermal Shutdown and Overload Protection 6-channel High PSRR and Low Dropout LDO. +config REGULATOR_MT6363 + tristate "MT6363 SPMI Regulator driver" + depends on MFD_MTK_SPMI_PMIC + help + Say y here to select this option to enable the power regulator of + MediaTek MT6363 PMIC. + This driver supports the control of different power rails of device + through regulator interface. + + The driver can also be build as a module. + If so, the module will be called mt6363_regulator + config REGULATOR_MT6370 tristate "MT6370 SubPMIC Regulator" depends on MFD_MT6370@@ -924,6 +946,18 @@ config REGULATOR_MT6370 This driver supports the control for DisplayBias voltages and one general purpose LDO which is commonly used to drive the vibrator. +config REGULATOR_MT6373 + tristate "MT6373 SPMI Regulator driver" + depends on MFD_MTK_SPMI_PMIC + help + Say y here to select this option to enable the power regulator of + MediaTek MT6373 PMIC. + This driver supports the control of different power rails of device + through regulator interface. + + The driver can also be build as a module. + If so, the module will be called mt6373_regulator + config REGULATOR_MT6380 tristate "MediaTek MT6380 PMIC" depends on MTK_PMIC_WRAPdrivers/regulator/Makefile +3
-0@@ -102,6 +102,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_MT6316) += mt6316-regulator.o obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o obj-$(CONFIG_REGULATOR_MT6331) += mt6331-regulator.o obj-$(CONFIG_REGULATOR_MT6332) += mt6332-regulator.o@@ -109,7 +110,9 @@ 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 +obj-$(CONFIG_REGULATOR_MT6363) += mt6363-regulator.o obj-$(CONFIG_REGULATOR_MT6370) += mt6370-regulator.o +obj-$(CONFIG_REGULATOR_MT6373) += mt6373-regulator.o obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o obj-$(CONFIG_REGULATOR_MTK_DVFSRC) += mtk-dvfsrc-regulator.odrivers/regulator/mt6316-regulator.c new file +318
-0@@ -0,0 +1,381 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2024 MediaTek Inc. + +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/machine.h> +#include <linux/regulator/mt6316-regulator.h> +#include <linux/regulator/of_regulator.h> + +#define SET_OFFSET 0x1 +#define CLR_OFFSET 0x2 + +#define MT6316_REG_WIDTH 8 + +#define MT6316_BUCK_MODE_AUTO 0 +#define MT6316_BUCK_MODE_FORCE_PWM 1 +#define MT6316_BUCK_MODE_NORMAL 0 +#define MT6316_BUCK_MODE_LP 2 + +#define BUCK_PHASE_3 3 +#define BUCK_PHASE_4 4 + +struct mt6316_regulator_info { +struct regulator_desc desc; +u32 da_reg; +u32 qi; +u32 modeset_reg; +u32 modeset_mask; +u32 lp_mode_reg; +u32 lp_mode_mask; +u32 lp_mode_shift; +}; + +struct mt6316_init_data { +u32 id; +u32 size; +}; + +struct mt6316_chip { +struct device *dev; +struct regmap *regmap; +u32 slave_id; +}; + +#define MT_BUCK (match, _name, volt_ranges, _bid, _vsel) \ +[MT6316_ID_##_name] = { \ + .desc = { \ + .name = #_name, \ + .of_match = of_match_ptr(match), \ + .ops = &mt6316_volt_range_ops, \ + .type = REGULATOR_VOLTAGE, \ + .id = MT6316_ID_##_name, \ + .owner = THIS_MODULE, \ + .n_voltages = 0x1ff, \ + .linear_ranges = volt_ranges, \ + .n_linear_ranges = ARRAY_SIZE(volt_ranges),\ + .vsel_reg = _vsel, \ + .vsel_mask = 0xff, \ + .enable_reg = MT6316_BUCK_TOP_CON0, \ + .enable_mask = BIT(_bid - 1), \ + .of_map_mode = mt6316_map_mode, \ + }, \ + .da_reg = MT6316_VBUCK##_bid##_DBG8, \ + .qi = BIT(0), \ + .lp_mode_reg = MT6316_BUCK_TOP_CON1, \ + .lp_mode_mask = BIT(_bid - 1), \ + .lp_mode_shift = _bid - 1, \ + .modeset_reg = MT6316_BUCK_TOP_4PHASE_TOP_ANA_CON0,\ + .modeset_mask = BIT(_bid - 1), \ +} + +static const struct linear_range mt_volt_range1[] = { +REGULATOR_LINEAR_RANGE (0 ,0 ,0x1fe ,2500 ), +}; + +static int mt6316_regulator_enable (struct regulator_dev *rdev) +{ +return regmap_write (rdev->regmap, rdev->desc->enable_reg +SET_OFFSET , + rdev->desc->enable_mask); +} + +static int mt6316_regulator_disable (struct regulator_dev *rdev) +{ +return regmap_write (rdev->regmap, rdev->desc->enable_reg +CLR_OFFSET , + rdev->desc->enable_mask); +} + +static unsigned int mt6316_map_mode (u32 mode) +{ +switch (mode) { +case MT6316_BUCK_MODE_AUTO : +return REGULATOR_MODE_NORMAL ; +case MT6316_BUCK_MODE_FORCE_PWM : +return REGULATOR_MODE_FAST ; +case MT6316_BUCK_MODE_LP : +return REGULATOR_MODE_IDLE ; +default : +return REGULATOR_MODE_INVALID ; + } +} + +static int mt6316_regulator_set_voltage_sel (struct regulator_dev *rdev,unsigned int selector) +{ +unsigned short reg_val =0 ; +int ret =0 ; + + reg_val = ((selector &0x1 ) <<8 ) | (selector >>1 ); + ret =regmap_bulk_write (rdev->regmap, rdev->desc->vsel_reg, (u8 *) ®_val,2 ); + +return ret; +} + +static int mt6316_regulator_get_voltage_sel (struct regulator_dev *rdev) +{ +int ret =0 ; +unsigned int reg_val =0 ; + + ret =regmap_bulk_read (rdev->regmap, rdev->desc->vsel_reg, (u8 *) ®_val,2 ); +if (ret !=0 ) { +dev_err (&rdev->dev,"Failed to get mt6316 regulator voltage: %d\n" , ret); +return ret; + } + ret = ((reg_val >>8 ) &0x1 ) + ((reg_val & rdev->desc->vsel_mask) <<1 ); + +return ret; +} + +static unsigned int mt6316_regulator_get_mode (struct regulator_dev *rdev) +{ +struct mt6316_regulator_info *info; +int ret =0 , regval =0 ; +u32 modeset_mask; + + info = container_of(rdev->desc, struct mt6316_regulator_info, desc); + ret =regmap_read (rdev->regmap, info->modeset_reg, ®val); +if (ret !=0 ) { +dev_err (&rdev->dev,"Failed to get mt6316 buck mode: %d\n" , ret); +return ret; + } + + modeset_mask = info->modeset_mask; + +if ((regval & modeset_mask) == modeset_mask) +return REGULATOR_MODE_FAST ; + + ret =regmap_read (rdev->regmap, info->lp_mode_reg, ®val); +if (ret !=0 ) { +dev_err (&rdev->dev,"Failed to get mt6316 buck lp mode: %d\n" , ret); +return ret; + } + +if (regval & info->lp_mode_mask) +return REGULATOR_MODE_IDLE ; +else +return REGULATOR_MODE_NORMAL ; +} + +static int mt6316_regulator_set_mode (struct regulator_dev *rdev,u32 mode) +{ +struct mt6316_regulator_info *info; +int ret =0 , val, curr_mode; +u32 modeset_mask; + + info = container_of(rdev->desc, struct mt6316_regulator_info, desc); + modeset_mask = info->modeset_mask; + + curr_mode =mt6316_regulator_get_mode (rdev); +switch (mode) { +case REGULATOR_MODE_FAST : + ret =regmap_update_bits (rdev->regmap, info->modeset_reg, + modeset_mask, modeset_mask); +break ; +case REGULATOR_MODE_NORMAL : +if (curr_mode ==REGULATOR_MODE_FAST ) { + ret =regmap_update_bits (rdev->regmap, info->modeset_reg, + modeset_mask,0 ); + }else if (curr_mode ==REGULATOR_MODE_IDLE ) { + ret =regmap_update_bits (rdev->regmap, info->lp_mode_reg, + info->lp_mode_mask,0 ); +usleep_range (100 ,110 ); + } +break ; +case REGULATOR_MODE_IDLE : + val =MT6316_BUCK_MODE_LP >>1 ; + val <<= info->lp_mode_shift; + ret =regmap_update_bits (rdev->regmap, info->lp_mode_reg, info->lp_mode_mask, val); +break ; +default : + ret = -EINVAL ; + goto err_mode; + } + +err_mode: +if (ret !=0 ) { +dev_err (&rdev->dev,"Failed to set mt6316 buck mode: %d\n" , ret); +return ret; + } + +return 0 ; +} + +static int mt6316_get_status (struct regulator_dev *rdev) +{ +int ret =0 ; +u32 regval =0 ; +struct mt6316_regulator_info *info; + + info = container_of(rdev->desc, struct mt6316_regulator_info, desc); + ret =regmap_read (rdev->regmap, info->da_reg, ®val); +if (ret !=0 ) { +dev_notice (&rdev->dev,"Failed to get enable reg: %d\n" , ret); +return ret; + } + +return (regval & info->qi) ?REGULATOR_STATUS_ON :REGULATOR_STATUS_OFF ; +} + +static void mt6316_buck_phase_init (struct mt6316_chip *chip,unsigned int *s6_buck_phase) +{ +int ret =0 ; +u32 val =0 ; + + ret =regmap_read (chip->regmap,MT6316_BUCK_TOP_4PHASE_TOP_ELR_0 , &val); +if (ret) { +dev_err (chip->dev,"Failed to get mt6316 buck phase: %d\n" , ret); +return ; + } + +dev_info (chip->dev,"S%d RG_4PH_CONFIG:%d\n" , chip->slave_id, val); +if (chip->slave_id ==MT6316_SLAVE_ID_6 ) + *s6_buck_phase = val; +} + +static const struct regulator_ops mt6316_volt_range_ops = { + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, + .set_voltage_sel = mt6316_regulator_set_voltage_sel, + .get_voltage_sel = mt6316_regulator_get_voltage_sel, + .set_voltage_time_sel = regulator_set_voltage_time_sel, + .enable = mt6316_regulator_enable, + .disable = mt6316_regulator_disable, + .is_enabled = regulator_is_enabled_regmap, + .get_status = mt6316_get_status, + .set_mode = mt6316_regulator_set_mode, + .get_mode = mt6316_regulator_get_mode, +}; + +static struct mt6316_regulator_info mt6316_regulators[] = { +MT_BUCK ("vbuck1" ,VBUCK1 , mt_volt_range1,1 ,MT6316_BUCK_TOP_ELR0 ), +MT_BUCK ("vbuck2" ,VBUCK2 , mt_volt_range1,2 ,MT6316_BUCK_TOP_ELR2 ), +MT_BUCK ("vbuck3" ,VBUCK3 , mt_volt_range1,3 ,MT6316_BUCK_TOP_ELR4 ), +MT_BUCK ("vbuck4" ,VBUCK4 , mt_volt_range1,4 ,MT6316_BUCK_TOP_ELR6 ), +}; + +static struct mt6316_init_data mt6316_3_init_data = { + .id =MT6316_SLAVE_ID_3 , + .size =MT6316_ID_3_MAX , +}; + +static struct mt6316_init_data mt6316_6_init_data = { + .id =MT6316_SLAVE_ID_6 , + .size =MT6316_ID_6_MAX , +}; + +static struct mt6316_init_data mt6316_7_init_data = { + .id =MT6316_SLAVE_ID_7 , + .size =MT6316_ID_7_MAX , +}; + +static struct mt6316_init_data mt6316_8_init_data = { + .id =MT6316_SLAVE_ID_8 , + .size =MT6316_ID_8_MAX , +}; + +static struct mt6316_init_data mt6316_15_init_data = { + .id =MT6316_SLAVE_ID_15 , + .size =MT6316_ID_15_MAX , +}; + +static const struct of_device_id mt6316_of_match[] = { + { + .compatible ="mediatek,mt6316-3-regulator" , + .data = &mt6316_3_init_data, + }, { + .compatible ="mediatek,mt6316-6-regulator" , + .data = &mt6316_6_init_data, + }, { + .compatible ="mediatek,mt6316-7-regulator" , + .data = &mt6316_7_init_data, + }, { + .compatible ="mediatek,mt6316-8-regulator" , + .data = &mt6316_8_init_data, + }, { + .compatible ="mediatek,mt6316-15-regulator" , + .data = &mt6316_15_init_data, + }, { +/* sentinel */ + }, +}; +MODULE_DEVICE_TABLE (of, mt6316_of_match); + +static int mt6316_regulator_probe (struct platform_device *pdev) +{ +const struct of_device_id *of_id; +struct device *dev = &pdev->dev; +struct regmap *regmap; +struct mt6316_init_data *pdata; +struct mt6316_chip *chip; +struct regulator_config config = {}; +struct regulator_dev *rdev; +struct device_node *node = pdev->dev.of_node; +u32 val =0 ;
drivers/regulator/mt6316-regulator.c line 328
Quoted 10 lines
drivers/regulator/mt6316-regulator.c new file +10
-0+int i; +unsigned int s6_buck_phase; + + regmap =dev_get_regmap (dev->parent,NULL ); +if (!regmap) +return -ENODEV ; + + chip =devm_kzalloc (dev,sizeof (struct mt6316_chip ),GFP_KERNEL ); +if (!chip) +return -ENOMEM ;
Replace the following block:
drivers/regulator/mt6316-regulator.c line 334
Quoted 5 lines
drivers/regulator/mt6316-regulator.c new file +5
-0+ of_id =of_match_device (mt6316_of_match, dev); +if (!of_id || !of_id->data) +return -ENODEV ; + + pdata = (struct mt6316_init_data *)of_id->data;
with
pdata = of_device_get_match_data(dev);
pdata should never be NULL since the driver is probed only when an OF match happens, and all the entries in mt6316_of_match[] have .data set.
drivers/regulator/mt6316-regulator.c line 335
Quoted 1 line
drivers/regulator/mt6316-regulator.c new file +1
-0+ chip->slave_id = pdata->id;
If the ID is supposed to be the SPMI ID, then there should be no reason to tie it to the compatible string. Simply get the ID from the device tree.
drivers/regulator/mt6316-regulator.c line 337
Quoted 2 lines
drivers/regulator/mt6316-regulator.c new file +2
-0+if (!of_property_read_u32 (node,"buck-size" , &val)) + pdata->size = val;
As mentioned in downstream review, the chip has 4 buck regulators, regardless of whether they are being used or not. This is not the right way to describe unused regulators.
Quoted 22 lines
drivers/regulator/mt6316-regulator.c new file +22
-0+ chip->dev = dev; + chip->regmap = regmap; +dev_set_drvdata (dev, chip); + + dev->fwnode = &(dev->of_node->fwnode); +if (dev->fwnode && !dev->fwnode->dev) + dev->fwnode->dev = dev; + + config.dev = dev; + config.driver_data = pdata; + config.regmap = regmap; + +mt6316_buck_phase_init (chip, &s6_buck_phase); +for (i =0 ; i < pdata->size; i++) { +if (pdata->id ==MT6316_SLAVE_ID_6 && + s6_buck_phase ==BUCK_PHASE_4 && + (mt6316_regulators + i)->desc.id ==MT6316_ID_VBUCK3 ) { +dev_info (dev,"skip registering %s.\n" , (mt6316_regulators + i)->desc.name); +continue ; + } + + rdev =devm_regulator_register (dev, &(mt6316_regulators + i)->desc, &config);
drivers/regulator/mt6316-regulator.c line 369
Quoted 10 lines
drivers/regulator/mt6316-regulator.c new file +10
-0+if (IS_ERR (rdev)) { +dev_err (dev,"failed to register %s\n" , (mt6316_regulators + i)->desc.name); +continue ; + } + } + +return 0 ; +} + +static struct platform_driver mt6316_regulator_driver = {
The MT6316 only has regulators. Why does it need to go through another layer, instead of this driver being the SPMI driver?
drivers/regulator/mt6316-regulator.c line 381
Quoted 12 lines
drivers/regulator/mt6316-regulator.c new file +12
-0+ .driver = { + .name = "mt6316-regulator", + .of_match_table = mt6316_of_match, + }, + .probe = mt6316_regulator_probe, +}; + +module_platform_driver (mt6316_regulator_driver); + +MODULE_AUTHOR ("Lu Tang <[email protected]>" ); +MODULE_DESCRIPTION ("Regulator Driver for MediaTek MT6316 PMIC" ); +MODULE_LICENSE ("GPL" );
[...]
Skipping the other two PMICs for now.
Quoted 44 lines
include/linux/regulator/mt6316-regulator.h new file +38
-0@@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2024 MediaTek Inc. +*/ + +#ifndef __LINUX_REGULATOR_MT6316_H +#define __LINUX_REGULATOR_MT6316_H + +#define MT6316_SLAVE_ID_3 3 +#define MT6316_SLAVE_ID_6 6 +#define MT6316_SLAVE_ID_7 7 +#define MT6316_SLAVE_ID_8 8 +#define MT6316_SLAVE_ID_15 15 + +#define MT6316_ID_3_MAX 3 +#define MT6316_ID_6_MAX 3 +#define MT6316_ID_7_MAX 3 +#define MT6316_ID_8_MAX 3 +#define MT6316_ID_15_MAX 2 + +enum { +MT6316_ID_VBUCK1 =0 , +MT6316_ID_VBUCK2 , +MT6316_ID_VBUCK3 , +MT6316_ID_VBUCK4 , +MT6316_ID_MAX , +}; + +/* Register */ +#define MT6316_TOP_CFG_ELR4 0x143 +#define MT6316_BUCK_TOP_CON0 0x1440 +#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_VBUCK1_DBG4 0x14A4 +#define MT6316_VBUCK1_DBG8 0x14A8
include/linux/regulator/mt6316-regulator.h line 48
Quoted 10 lines
include/linux/regulator/mt6316-regulator.h new file +10
-0+#define MT6316_VBUCK2_DBG4 0x1524 +#define MT6316_VBUCK2_DBG8 0x1528 +#define MT6316_VBUCK3_DBG4 0x15A4 +#define MT6316_VBUCK3_DBG8 0x15A8 +#define MT6316_VBUCK4_DBG4 0x1624 +#define MT6316_VBUCK4_DBG8 0x1628 +#define MT6316_BUCK_TOP_4PHASE_TOP_ANA_CON0 0x1688 +#define MT6316_BUCK_TOP_4PHASE_TOP_ELR_0 0x1690 + +#endif /* __LINUX_REGULATOR_MT6316_H */
AFAICT, no part of this file is used by other parts of the kernel. It can be moved under drivers/regulator/, or even recombined with the .c file.
Thanks
ChenYu
回复: [PATCH 2/5] pmic: mediatek: Add pmic regulator driver
In reply to Lu.TangUpdate email address
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:32
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Project_Global_Chrome_Upstream_Group <[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 2/5] pmic: mediatek: Add pmic regulator driver
From: "Lu.Tang" <[email protected]>
Add pmic mt6316/mt6373/mt6363 regulator driver
--- drivers/regulator/Kconfig | 34 + drivers/regulator/Makefile | 3 + drivers/regulator/mt6316-regulator.c | 381 +++++++ drivers/regulator/mt6363-regulator.c | 1106 ++++++++++++++++++++ drivers/regulator/mt6373-regulator.c | 826 +++++++++++++++ include/linux/regulator/mt6316-regulator.h | 48 + include/linux/regulator/mt6363-regulator.h | 424 ++++++++ include/linux/regulator/mt6373-regulator.h | 318 ++++++ 8 files changed, 3140 insertions(+) create mode 100644 drivers/regulator/mt6316-regulator.c create mode 100644 drivers/regulator/mt6363-regulator.c create mode 100644 drivers/regulator/mt6373-regulator.c create mode 100644 include/linux/regulator/mt6316-regulator.h create mode 100644 include/linux/regulator/mt6363-regulator.h create mode 100644 include/linux/regulator/mt6373-regulator.h
drivers/regulator/Kconfig +34 -0
@@ -853,6 +853,16 @@ config REGULATOR_MT6315 This driver supports the control of different power rails of device through regulator interface. +config REGULATOR_MT6316 + tristate "MediaTek MT6316 PMIC" + depends on SPMI + select REGMAP_SPMI + help + Say y here to select this option to enable the power regulator of + MediaTek MT6316 PMIC. + 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
@@ -916,6 +926,18 @@ config REGULATOR_MT6360 2-channel buck with Thermal Shutdown and Overload Protection 6-channel High PSRR and Low Dropout LDO. +config REGULATOR_MT6363 + tristate "MT6363 SPMI Regulator driver" + depends on MFD_MTK_SPMI_PMIC + help + Say y here to select this option to enable the power regulator of + MediaTek MT6363 PMIC. + This driver supports the control of different power rails of device + through regulator interface. + + The driver can also be build as a module. + If so, the module will be called mt6363_regulator + config REGULATOR_MT6370 tristate "MT6370 SubPMIC Regulator" depends on MFD_MT6370
@@ -924,6 +946,18 @@ config REGULATOR_MT6370 This driver supports the control for DisplayBias voltages and one general purpose LDO which is commonly used to drive the vibrator. +config REGULATOR_MT6373 + tristate "MT6373 SPMI Regulator driver" + depends on MFD_MTK_SPMI_PMIC + help + Say y here to select this option to enable the power regulator of + MediaTek MT6373 PMIC. + This driver supports the control of different power rails of device + through regulator interface. + + The driver can also be build as a module. + If so, the module will be called mt6373_regulator + config REGULATOR_MT6380 tristate "MediaTek MT6380 PMIC" depends on MTK_PMIC_WRAP
drivers/regulator/Makefile +3 -0
@@ -102,6 +102,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_MT6316) += mt6316-regulator.o obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o obj-$(CONFIG_REGULATOR_MT6331) += mt6331-regulator.o obj-$(CONFIG_REGULATOR_MT6332) += mt6332-regulator.o
@@ -109,7 +110,9 @@ 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 +obj-$(CONFIG_REGULATOR_MT6363) += mt6363-regulator.o obj-$(CONFIG_REGULATOR_MT6370) += mt6370-regulator.o +obj-$(CONFIG_REGULATOR_MT6373) += mt6373-regulator.o obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o obj-$(CONFIG_REGULATOR_MTK_DVFSRC) += mtk-dvfsrc-regulator.o
drivers/regulator/mt6316-regulator.c new file +381 -0
381 lines not on this page · raw message
drivers/regulator/mt6363-regulator.c new file +1106 -0
1,106 lines not on this page · raw message
drivers/regulator/mt6373-regulator.c new file +826 -0
826 lines not on this page · raw message
include/linux/regulator/mt6316-regulator.h new file +48 -0
48 lines not on this page · raw message
include/linux/regulator/mt6363-regulator.h new file +424 -0
424 lines not on this page · raw message
include/linux/regulator/mt6373-regulator.h new file +318 -0
147 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.46.0
Part of the diff is not shown here. View the raw message.
PATCH 3/5 pmic: mediatek: Add spmi pmic mfd driver
In reply to Lu.TangFrom: "Lu.Tang" <[email protected]>
Add spmi pmic mfd driver for mt8196
--- drivers/mfd/Kconfig | 26 ++ drivers/mfd/Makefile | 2 + drivers/mfd/mt6685-core.c | 83 +++++ drivers/mfd/mtk-spmi-pmic.c | 518 +++++++++++++++++++++++++++ include/linux/mfd/mt6363/core.h | 134 +++++++ include/linux/mfd/mt6363/registers.h | 168 +++++++++ include/linux/mfd/mt6373/core.h | 94 +++++ include/linux/mfd/mt6373/registers.h | 53 +++ 8 files changed, 1078 insertions(+) create mode 100644 drivers/mfd/mt6685-core.c create mode 100644 drivers/mfd/mtk-spmi-pmic.c create mode 100644 include/linux/mfd/mt6363/core.h create mode 100644 include/linux/mfd/mt6363/registers.h create mode 100644 include/linux/mfd/mt6373/core.h create mode 100644 include/linux/mfd/mt6373/registers.h
drivers/mfd/Kconfig +26 -0
@@ -1030,6 +1030,32 @@ config MFD_MT6397 accessing the device; additional drivers must be enabled in order to use the functionality of the device. +config MFD_MT6685 + tristate "MT6685 SPMI PMIC" + depends on OF + depends on SPMI + select REGMAP_SPMI + select REGMAP_IRQ + help + This enables support for the Mediatek SPMI PMICs. + These PMICs are currently used with the Mediatek series of + SoCs. Note, that this will only be useful paired with descriptions + of the independent functions as children nodes in the device tree. + +config MFD_MTK_SPMI_PMIC + tristate "Mediatek SPMI PMICs" + depends on OF + depends on SPMI + select REGMAP_SPMI + help + This enables support for the Mediatek SPMI PMICs. + These PMICs are currently used with the MT63xx series of + SoCs. Note, that this will only be useful paired with descriptions + of the independent functions as children nodes in the device tree. + + Say M here if you want to include support for the SPMI PMIC + series as a module. The module will be called "mtk-spmi-pmic". + config MFD_MENF21BMC tristate "MEN 14F021P00 Board Management Controller Support" depends on I2C
drivers/mfd/Makefile +2 -0
@@ -182,6 +182,8 @@ obj-$(CONFIG_MFD_MT6360) += mt6360-core.o obj-$(CONFIG_MFD_MT6370) += mt6370.o mt6397-objs := mt6397-core.o mt6397-irq.o mt6358-irq.o obj-$(CONFIG_MFD_MT6397) += mt6397.o +obj-$(CONFIG_MFD_MT6685) += mt6685-core.o +obj-$(CONFIG_MFD_MTK_SPMI_PMIC) += mtk-spmi-pmic.o pcf50633-objs := pcf50633-core.o pcf50633-irq.o obj-$(CONFIG_MFD_PCF50633) += pcf50633.o
drivers/mfd/mt6685-core.c new file +83 -0
83 lines not on this page · raw message
drivers/mfd/mtk-spmi-pmic.c new file +518 -0
518 lines not on this page · raw message
include/linux/mfd/mt6363/core.h new file +134 -0
134 lines not on this page · raw message
include/linux/mfd/mt6363/registers.h new file +168 -0
168 lines not on this page · raw message
include/linux/mfd/mt6373/core.h new file +94 -0
94 lines not on this page · raw message
include/linux/mfd/mt6373/registers.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.46.0
回复: [PATCH 3/5] pmic: mediatek: Add spmi pmic mfd driver
Update email address
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:32
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Project_Global_Chrome_Upstream_Group <[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 3/5] pmic: mediatek: Add spmi pmic mfd driver
From: "Lu.Tang" <[email protected]>
Add spmi pmic mfd driver for mt8196
--- drivers/mfd/Kconfig | 26 ++ drivers/mfd/Makefile | 2 + drivers/mfd/mt6685-core.c | 83 +++++ drivers/mfd/mtk-spmi-pmic.c | 518 +++++++++++++++++++++++++++ include/linux/mfd/mt6363/core.h | 134 +++++++ include/linux/mfd/mt6363/registers.h | 168 +++++++++ include/linux/mfd/mt6373/core.h | 94 +++++ include/linux/mfd/mt6373/registers.h | 53 +++ 8 files changed, 1078 insertions(+) create mode 100644 drivers/mfd/mt6685-core.c create mode 100644 drivers/mfd/mtk-spmi-pmic.c create mode 100644 include/linux/mfd/mt6363/core.h create mode 100644 include/linux/mfd/mt6363/registers.h create mode 100644 include/linux/mfd/mt6373/core.h create mode 100644 include/linux/mfd/mt6373/registers.h
drivers/mfd/Kconfig +26 -0
@@ -1030,6 +1030,32 @@ config MFD_MT6397 accessing the device; additional drivers must be enabled in order to use the functionality of the device. +config MFD_MT6685 + tristate "MT6685 SPMI PMIC" + depends on OF + depends on SPMI + select REGMAP_SPMI + select REGMAP_IRQ + help + This enables support for the Mediatek SPMI PMICs. + These PMICs are currently used with the Mediatek series of + SoCs. Note, that this will only be useful paired with descriptions + of the independent functions as children nodes in the device tree. + +config MFD_MTK_SPMI_PMIC + tristate "Mediatek SPMI PMICs" + depends on OF + depends on SPMI + select REGMAP_SPMI + help + This enables support for the Mediatek SPMI PMICs. + These PMICs are currently used with the MT63xx series of + SoCs. Note, that this will only be useful paired with descriptions + of the independent functions as children nodes in the device tree. + + Say M here if you want to include support for the SPMI PMIC + series as a module. The module will be called "mtk-spmi-pmic". + config MFD_MENF21BMC tristate "MEN 14F021P00 Board Management Controller Support" depends on I2C
drivers/mfd/Makefile +2 -0
@@ -182,6 +182,8 @@ obj-$(CONFIG_MFD_MT6360) += mt6360-core.o obj-$(CONFIG_MFD_MT6370) += mt6370.o mt6397-objs := mt6397-core.o mt6397-irq.o mt6358-irq.o obj-$(CONFIG_MFD_MT6397) += mt6397.o +obj-$(CONFIG_MFD_MT6685) += mt6685-core.o +obj-$(CONFIG_MFD_MTK_SPMI_PMIC) += mtk-spmi-pmic.o pcf50633-objs := pcf50633-core.o pcf50633-irq.o obj-$(CONFIG_MFD_PCF50633) += pcf50633.o
drivers/mfd/mt6685-core.c new file +81 -0
81 lines not on this page · raw message
drivers/mfd/mtk-spmi-pmic.c new file +500 -0
500 lines not on this page · raw message
include/linux/mfd/mt6363/core.h new file +133 -0
133 lines not on this page · raw message
include/linux/mfd/mt6363/registers.h new file +168 -0
168 lines not on this page · raw message
include/linux/mfd/mt6373/core.h new file +94 -0
94 lines not on this page · raw message
include/linux/mfd/mt6373/registers.h new file +53 -0
53 lines not on this page · raw message
--
2.46.0
Lee Jones
maintainerRe: 回复: [PATCH 3/5] pmic: mediatek: Add spmi pmic mfd driver
Quoted 1 line · Lu Tang (汤璐)
Update email address
What is this?
Please refrain from top-posting.
Quoted 6 lines
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:32
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];Project_Global_Chrome_Upstream_Group<[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 3/5] pmic: mediatek: Add spmi pmic mfd driver
Fix your mailer. Headers have no place in the body of an email.
Quoted 3 lines
From: "Lu.Tang" <[email protected]>
Add spmi pmic mfd driver for mt8196
7 words for a 900 line change is not going to fly.
What is this device? What does it provide? What are its dependencies?
Etc.
Quoted 13 lines
Signed-off-by Lu Tang <[email protected]>--- drivers/mfd/Kconfig | 26 ++ drivers/mfd/Makefile | 2 + drivers/mfd/mt6685-core.c | 83 +++++ drivers/mfd/mtk-spmi-pmic.c | 518 +++++++++++++++++++++++++++ include/linux/mfd/mt6363/core.h | 134 +++++++ include/linux/mfd/mt6363/registers.h | 168 +++++++++ include/linux/mfd/mt6373/core.h | 94 +++++ include/linux/mfd/mt6373/registers.h | 53 +++ 8 files changed, 1078 insertions(+) create mode 100644 drivers/mfd/mt6685-core.c create mode 100644 drivers/mfd/mtk-spmi-pmic.c create mode 100644 include/linux/mfd/mt6363/core.h create mode 100644 include/linux/mfd/mt6363/registers.h create mode 100644 include/linux/mfd/mt6373/core.h create mode 100644 include/linux/mfd/mt6373/registers.h
Please try again.
Signature · 1 line
Lee Jones [李琼斯]
PATCH 4/5 spmi: mediatek: modify spmi dirver for mt8196
In reply to Lu.TangFrom: "Lu.Tang" <[email protected]>
Modify spmi driver for mt8196 pmic.
Add pmif_s/pmif_m controller and rcs irq handler.
--- drivers/spmi/spmi-mtk-pmif.c | 1040 +++++++++++++++++++++++++++++++--- 1 file changed, 976 insertions(+), 64 deletions(-)
drivers/spmi/spmi-mtk-pmif.c +976 -64
@@ -1,14 +1,20 @@// SPDX-License-Identifier: GPL-2.0 // -// Copyright (c) 2021 MediaTek Inc. +// Copyright (c) 2024 MediaTek Inc. #include <linux/clk.h> #include <linux/iopoll.h> +#include <linux/interrupt.h> +#include <linux/irqdomain.h> +#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/sched/clock.h> +#include <linux/sched/mm.h> #include <linux/platform_device.h> #include <linux/property.h> #include <linux/spmi.h> +#include <linux/irq.h> #define SWINF_IDLE 0x00#define SWINF_WFVLDCLR 0x06
@@ -21,14 +27,21 @@#define PMIF_CMD_EXT_REG_LONG 3#define PMIF_DELAY_US 10 -#define PMIF_TIMEOUT_US (10 * 1000) +#define PMIF_TIMEOUT_US (100 * 1000)#define PMIF_CHAN_OFFSET 0x5 +#define PMIF_CAPS_VER_1 1 +#define PMIF_CAPS_VER_2 2 +#define PMIF_MAX_CLKS 3#define SPMI_OP_ST_BUSY 1 +#define SPMI_SOC_CHANNEL 2 + +#define PMIF_IRQDESC (name) { #name, pmif_##name##_irq_handler, -1} +struct ch_reg {u32 ch_sta;u32 wdata;
@@ -41,25 +54,53 @@ struct pmif_data {const u32 *regs;const u32 *spmimst_regs;u32 soc_chan; +u32 caps; };struct pmif { -void __iomem *base; -void __iomem *spmimst_base; +void __iomem *pmif_base[2 ]; +void __iomem *spmimst_base[2 ];struct ch_reg chan;struct clk_bulk_data clks[PMIF_MAX_CLKS ];size_t nclks;const struct pmif_data *data; -raw_spinlock_t lock; +raw_spinlock_t lock_m; +raw_spinlock_t lock_p; +struct spmi_controller *spmic; +struct wakeup_source *pmif_m_Thread_lock; +struct wakeup_source *pmif_p_Thread_lock; +struct mutex pmif_m_mutex; +struct mutex pmif_p_mutex; +int irq; +int irq_p; +struct irq_domain *domain; +struct irq_chip irq_chip; +struct irq_chip irq_chip_p; +int rcs_irq; +int rcs_irq_p; +struct mutex rcs_m_irqlock; +struct mutex rcs_p_irqlock; +bool *rcs_enable_hwirq; +int spmi_nack_irq; +int spmi_p_nack_irq; };static const char *const pmif_clock_names[] = {"pmif_sys_ck" ,"pmif_tmr_ck" ,"spmimst_clk_mux" , }; +struct pmif_irq_desc { +const char *name; +irq_handler_t irq_handler; +int irq; +}; +enum pmif_regs {PMIF_INIT_DONE ,PMIF_INF_EN , +MD_AUXADC_RDATA_0_ADDR , +MD_AUXADC_RDATA_1_ADDR , +MD_AUXADC_RDATA_2_ADDR ,PMIF_ARB_EN ,PMIF_CMDISSUE_EN ,PMIF_TIMER_CTRL ,
@@ -103,6 +144,11 @@ enum pmif_regs {PMIF_SWINF_3_RDATA_31_0 ,PMIF_SWINF_3_ACC ,PMIF_SWINF_3_VLD_CLR , +PMIF_PMIC_SWINF_0_PER , +PMIF_PMIC_SWINF_1_PER , +PMIF_ACC_VIO_INFO_0 , +PMIF_ACC_VIO_INFO_1 , + PMIF_ACC_VIO_INFO_2, }; static const u32 mt6873_regs[] = {
@@ -201,6 +247,63 @@ static const u32 mt8195_regs[] = { [PMIF_SWINF_3_STA] = 0x08E8, }; +static const u32 mt6xxx_regs[] = { + [PMIF_INIT_DONE ] =0x0000 , + [PMIF_INF_EN ] =0x0024 , + [MD_AUXADC_RDATA_0_ADDR ] =0x0080 , + [MD_AUXADC_RDATA_1_ADDR ] =0x0084 , + [MD_AUXADC_RDATA_2_ADDR ] =0x0088 , + [PMIF_ARB_EN ] =0x0150 , + [PMIF_CMDISSUE_EN ] =0x03B8 , + [PMIF_TIMER_CTRL ] =0x03E4 , + [PMIF_SPI_MODE_CTRL ] =0x0408 , + [PMIF_IRQ_EVENT_EN_0 ] =0x0420 , + [PMIF_IRQ_FLAG_0 ] =0x0428 , + [PMIF_IRQ_CLR_0 ] =0x042C , + [PMIF_IRQ_EVENT_EN_1 ] =0x0430 , + [PMIF_IRQ_FLAG_1 ] =0x0438 , + [PMIF_IRQ_CLR_1 ] =0x043C , + [PMIF_IRQ_EVENT_EN_2 ] =0x0440 , + [PMIF_IRQ_FLAG_2 ] =0x0448 , + [PMIF_IRQ_CLR_2 ] =0x044C , + [PMIF_IRQ_EVENT_EN_3 ] =0x0450 , + [PMIF_IRQ_FLAG_3 ] =0x0458 , + [PMIF_IRQ_CLR_3 ] =0x045C , + [PMIF_IRQ_EVENT_EN_4 ] =0x0460 , + [PMIF_IRQ_FLAG_4 ] =0x0468 , + [PMIF_IRQ_CLR_4 ] =0x046C , + [PMIF_WDT_EVENT_EN_0 ] =0x0474 , + [PMIF_WDT_FLAG_0 ] =0x0478 , + [PMIF_WDT_EVENT_EN_1 ] =0x047C , + [PMIF_WDT_FLAG_1 ] =0x0480 , + [PMIF_SWINF_0_ACC ] =0x0800 , + [PMIF_SWINF_0_WDATA_31_0 ] =0x0804 , + [PMIF_SWINF_0_RDATA_31_0 ] =0x0814 , + [PMIF_SWINF_0_VLD_CLR ] =0x0824 , + [PMIF_SWINF_0_STA ] =0x0828 , + [PMIF_SWINF_1_ACC ] =0x0840 , + [PMIF_SWINF_1_WDATA_31_0 ] =0x0844 , + [PMIF_SWINF_1_RDATA_31_0 ] =0x0854 , + [PMIF_SWINF_1_VLD_CLR ] =0x0864 , + [PMIF_SWINF_1_STA ] =0x0868 , + [PMIF_SWINF_2_ACC ] =0x0880 , + [PMIF_SWINF_2_WDATA_31_0 ] =0x0884 , + [PMIF_SWINF_2_RDATA_31_0 ] =0x0894 , + [PMIF_SWINF_2_VLD_CLR ] =0x08A4 , + [PMIF_SWINF_2_STA ] =0x08A8 , + [PMIF_SWINF_3_ACC ] =0x08C0 , + [PMIF_SWINF_3_WDATA_31_0 ] =0x08C4 , + [PMIF_SWINF_3_RDATA_31_0 ] =0x08D4 , + [PMIF_SWINF_3_VLD_CLR ] =0x08E4 , + [PMIF_SWINF_3_STA ] =0x08E8 , + [PMIF_PMIC_SWINF_0_PER ] =0x093C , + [PMIF_PMIC_SWINF_1_PER ] =0x0940 , + [PMIF_ACC_VIO_INFO_0 ] =0x0980 , + [PMIF_ACC_VIO_INFO_1 ] =0x0984 , + [PMIF_ACC_VIO_INFO_2 ] =0x0988 , + +}; +enum spmi_regs {SPMI_OP_ST_CTRL ,SPMI_GRP_ID_EN ,
@@ -262,26 +365,132 @@ static const u32 mt8195_spmi_regs[] = { [SPMI_MST_DBG] = 0x00FC, }; -static u32 pmif_readl (struct pmif *arb,enum pmif_regs reg) +static const u32 mt6853_spmi_regs[] = { + [SPMI_OP_ST_CTRL ] =0x0000 , + [SPMI_GRP_ID_EN ] =0x0004 , + [SPMI_OP_ST_STA ] =0x0008 , + [SPMI_MST_SAMPL ] =0x000C , + [SPMI_MST_REQ_EN ] =0x0010 , + [SPMI_MST_RCS_CTRL ] =0x0014 , + [SPMI_SLV_3_0_EINT ] =0x0020 , + [SPMI_SLV_7_4_EINT ] =0x0024 , + [SPMI_SLV_B_8_EINT ] =0x0028 , + [SPMI_SLV_F_C_EINT ] =0x002C , + [SPMI_REC_CTRL ] =0x0040 , + [SPMI_REC0 ] =0x0044 , + [SPMI_REC1 ] =0x0048 , + [SPMI_REC2 ] =0x004C , + [SPMI_REC3 ] =0x0050 , + [SPMI_REC4 ] =0x0054 , + [SPMI_REC_CMD_DEC ] =0x005C , + [SPMI_DEC_DBG ] =0x00F8 , + [SPMI_MST_DBG ] =0x00FC , +}; + +enum { +IRQ_LAT_LIMIT_REACHED =6 , +IRQ_HW_MONITOR =7 , +IRQ_WDT =8 , +/* MT6833/MT6877 series */ +IRQ_HW_MONITOR_V3 =12 , +IRQ_WDT_V3 =13 , +IRQ_ALL_PMIC_MPU_VIO_V3 =14 , +/* MT6885/MT6873 series */ +IRQ_PMIC_CMD_ERR_PARITY_ERR =17 , +IRQ_PMIF_ACC_VIO =20 , +IRQ_PMIC_ACC_VIO =21 , +/* MT6985/MT6897 */ +IRQ_PMIF_ACC_VIO_V3 =27 , +/* MT6853 series */ +IRQ_PMIF_ACC_VIO_V2 =31 , +}; + +enum { +IRQ_PMIC_ACC_VIO_V2 =0 , +IRQ_PMIF_SWINF_ACC_ERR_0 =3 , +IRQ_PMIF_SWINF_ACC_ERR_1 =4 , +IRQ_PMIF_SWINF_ACC_ERR_2 =5 , +IRQ_PMIF_SWINF_ACC_ERR_3 =6 , +IRQ_PMIF_SWINF_ACC_ERR_4 =7 , +IRQ_PMIF_SWINF_ACC_ERR_5 =8 , +IRQ_HW_MONITOR_V2 =18 , +IRQ_WDT_V2 =19 , +IRQ_ALL_PMIC_MPU_VIO_V2 =20 , +IRQ_PMIF_SWINF_ACC_ERR_0_V2 =23 , +IRQ_PMIF_SWINF_ACC_ERR_1_V2 =24 , +IRQ_PMIF_SWINF_ACC_ERR_2_V2 =25 , +IRQ_PMIF_SWINF_ACC_ERR_3_V2 =26 , +IRQ_PMIF_SWINF_ACC_ERR_4_V2 =27 , +IRQ_PMIF_SWINF_ACC_ERR_5_V2 =28 , +/* MT6983/MT6879 */ +IRQ_HW_MONITOR_V4 =29 , +IRQ_WDT_V4 =30 , +IRQ_ALL_PMIC_MPU_VIO_V4 =31 , +}; + +struct spmi_dev { +int exist; +int slvid; +unsigned int path; +unsigned short hwcid_addr; +unsigned char hwcid_val; +}; + +static struct spmi_dev spmidev[16 ]; + +static void spmi_dev_parse (struct platform_device *pdev) { -return readl (arb->base + arb->data->regs[reg]); +int i =0 , j =0 , ret =0 ; +u32 spmi_dev_mask =0 ; + + ret =of_property_read_u32 (pdev->dev.of_node,"spmi-dev-mask" , + &spmi_dev_mask); +if (ret) +dev_info (&pdev->dev,"No spmi-dev-mask found in dts, default all PMIC on SPMI-M\n" ); + + j = spmi_dev_mask; +for (i =0 ; i <16 ; i++) { +if (j &BIT (i)) + spmidev[i].path =1 ;/* slvid i is in path p */ +else + spmidev[i].path =0 ; + } +} + +unsigned long long get_current_time_ms (void ) +{ +unsigned long long cur_ts; + + cur_ts =sched_clock (); +do_div (cur_ts,1000000 ); +return cur_ts; } -static void pmif_writel (struct pmif *arb,u32 val,enum pmif_regs reg) +static u32 pmif_readl (void __iomem *addr,struct pmif *arb,enum pmif_regs reg) { -writel (val, arb->base + arb->data->regs[reg]); +return readl (addr + arb->data->regs[reg]); } -static void mtk_spmi_writel (struct pmif *arb,u32 val,enum spmi_regs reg) +static void pmif_writel (void __iomem *addr,struct pmif *arb,u32 val,enum pmif_regs reg) { -writel (val, arb->spmimst_base + arb->data->spmimst_regs[reg]); +writel (val, addr + arb->data->regs[reg]); } -static bool pmif_is_fsm_vldclr (struct pmif *arb) +static void mtk_spmi_writel (void __iomem *addr,struct pmif *arb,u32 val,enum spmi_regs reg) +{ +writel (val, addr + arb->data->spmimst_regs[reg]); +} + +static u32 mtk_spmi_readl (void __iomem *addr,struct pmif *arb,enum spmi_regs reg) +{ +return readl (addr + arb->data->spmimst_regs[reg]); +} + +static bool pmif_is_fsm_vldclr (void __iomem *addr,struct pmif *arb) {u32 reg_rdata; - reg_rdata =pmif_readl (arb, arb->chan.ch_sta); + reg_rdata =pmif_readl (addr, arb, arb->chan.ch_sta);return GET_SWINF (reg_rdata) ==SWINF_WFVLDCLR ; }
@@ -298,8 +507,8 @@ static int pmif_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid) cmd = opc -SPMI_CMD_RESET ; -mtk_spmi_writel (arb, (cmd <<0x4 ) | sid,SPMI_OP_ST_CTRL ); - ret =readl_poll_timeout_atomic (arb->spmimst_base + arb->data->spmimst_regs[SPMI_OP_ST_STA ], +mtk_spmi_writel (arb->spmimst_base[spmidev[sid].path], arb, (cmd <<0x4 ) | sid,SPMI_OP_ST_CTRL ); + ret =readl_poll_timeout_atomic (arb->spmimst_base[spmidev[sid].path] + arb->data->spmimst_regs[SPMI_OP_ST_STA ], rdata, (rdata &SPMI_OP_ST_BUSY ) ==SPMI_OP_ST_BUSY ,PMIF_DELAY_US ,PMIF_TIMEOUT_US );if (ret <0 )
@@ -315,7 +524,7 @@ static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,struct ch_reg *inf_reg;int ret;u32 data, cmd; -unsigned long flags; +unsigned long flags_m;/* Check for argument validation. */ if (sid & ~0xf ) {
@@ -336,31 +545,31 @@ static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,else return -EINVAL ; -raw_spin_lock_irqsave (&arb->lock, flags); +raw_spin_lock_irqsave (&arb->lock_m, flags_m);/* Wait for Software Interface FSM state to be IDLE. */ inf_reg = &arb->chan; - ret =readl_poll_timeout_atomic (arb->base + arb->data->regs[inf_reg->ch_sta], + ret =readl_poll_timeout_atomic (arb->pmif_base[spmidev[sid].path] + arb->data->regs[inf_reg->ch_sta], data,GET_SWINF (data) ==SWINF_IDLE ,PMIF_DELAY_US ,PMIF_TIMEOUT_US );if (ret <0 ) {/* set channel ready if the data has transferred */ -if (pmif_is_fsm_vldclr (arb)) -pmif_writel (arb,1 , inf_reg->ch_rdy); -raw_spin_unlock_irqrestore (&arb->lock, flags); +if (pmif_is_fsm_vldclr (arb->pmif_base[spmidev[sid].path], arb)) +pmif_writel (arb->pmif_base[spmidev[sid].path], arb,1 , inf_reg->ch_rdy); +raw_spin_unlock_irqrestore (&arb->lock_m, flags_m);dev_err (&ctrl->dev,"failed to wait for SWINF_IDLE\n" );return ret; }/* Send the command. */ cmd = (opc <<30 ) | (sid <<24 ) | ((len -1 ) <<16 ) | addr; -pmif_writel (arb, cmd, inf_reg->ch_send); -raw_spin_unlock_irqrestore (&arb->lock, flags); +pmif_writel (arb->pmif_base[spmidev[sid].path], arb, cmd, inf_reg->ch_send); +raw_spin_unlock_irqrestore (&arb->lock_m, flags_m);/* * Wait for Software Interface FSM state to be WFVLDCLR, * read the data and clear the valid flag. */ - ret =readl_poll_timeout_atomic (arb->base + arb->data->regs[inf_reg->ch_sta], + ret =readl_poll_timeout_atomic (arb->pmif_base[spmidev[sid].path] + arb->data->regs[inf_reg->ch_sta], data,GET_SWINF (data) ==SWINF_WFVLDCLR ,PMIF_DELAY_US ,PMIF_TIMEOUT_US );if (ret <0 ) {
@@ -368,9 +577,9 @@ static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,return ret; } - data =pmif_readl (arb, inf_reg->rdata); + data =pmif_readl (arb->pmif_base[spmidev[sid].path], arb, inf_reg->rdata);memcpy (buf, &data, len); -pmif_writel (arb,1 , inf_reg->ch_rdy); +pmif_writel (arb->pmif_base[spmidev[sid].path], arb,1 , inf_reg->ch_rdy);return 0 ; }
@@ -382,7 +591,7 @@ static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,struct ch_reg *inf_reg;int ret;u32 data, wdata, cmd; -unsigned long flags; +unsigned long flags_m;/* Check for argument validation. */ if (unlikely (sid & ~0xf )) {
@@ -409,27 +618,27 @@ static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,/* Set the write data. */ memcpy (&wdata, buf, len); -raw_spin_lock_irqsave (&arb->lock, flags); +raw_spin_lock_irqsave (&arb->lock_m, flags_m);/* Wait for Software Interface FSM state to be IDLE. */ inf_reg = &arb->chan; - ret =readl_poll_timeout_atomic (arb->base + arb->data->regs[inf_reg->ch_sta], + ret =readl_poll_timeout_atomic (arb->pmif_base[spmidev[sid].path] + arb->data->regs[inf_reg->ch_sta], data,GET_SWINF (data) ==SWINF_IDLE ,PMIF_DELAY_US ,PMIF_TIMEOUT_US );if (ret <0 ) {/* set channel ready if the data has transferred */ -if (pmif_is_fsm_vldclr (arb)) -pmif_writel (arb,1 , inf_reg->ch_rdy); -raw_spin_unlock_irqrestore (&arb->lock, flags); +if (pmif_is_fsm_vldclr (arb->pmif_base[spmidev[sid].path], arb)) +pmif_writel (arb->pmif_base[spmidev[sid].path], arb,1 , inf_reg->ch_rdy); +raw_spin_unlock_irqrestore (&arb->lock_m, flags_m);dev_err (&ctrl->dev,"failed to wait for SWINF_IDLE\n" );return ret; } -pmif_writel (arb, wdata, inf_reg->wdata); +pmif_writel (arb->pmif_base[spmidev[sid].path], arb, wdata, inf_reg->wdata);/* Send the command. */ cmd = (opc <<30 ) |BIT (29 ) | (sid <<24 ) | ((len -1 ) <<16 ) | addr; -pmif_writel (arb, cmd, inf_reg->ch_send); -raw_spin_unlock_irqrestore (&arb->lock, flags); +pmif_writel (arb->pmif_base[spmidev[sid].path], arb, cmd, inf_reg->ch_send); +raw_spin_unlock_irqrestore (&arb->lock_m, flags_m);return 0 ; }
@@ -437,15 +646,642 @@ static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,static const struct pmif_data mt6873_pmif_arb = { .regs = mt6873_regs, .spmimst_regs = mt6873_spmi_regs, - .soc_chan =2 , + .soc_chan =SPMI_SOC_CHANNEL , + .caps =PMIF_CAPS_VER_1 , };static const struct pmif_data mt8195_pmif_arb = { .regs = mt8195_regs, .spmimst_regs = mt8195_spmi_regs, - .soc_chan =2 , + .soc_chan =SPMI_SOC_CHANNEL , + .caps =PMIF_CAPS_VER_1 , }; +static const struct pmif_data mt6xxx_pmif_arb = { + .regs = mt6xxx_regs, + .spmimst_regs = mt6853_spmi_regs, + .soc_chan =SPMI_SOC_CHANNEL , + .caps =PMIF_CAPS_VER_2 , +}; +static void mtk_spmi_readl_datas (struct pmif *arb,int id,unsigned int *spmi_nack, +unsigned int *spmi_nack_data,unsigned int *spmi_rcs_nack, +unsigned int *spmi_debug_nack,unsigned int *spmi_mst_nack) +{ +if (id <0 || id >=PMIF_CAPS_VER_2 ) { +dev_err (&arb->spmic->dev,"%s Invalid id: %d\n" , __func__, id); +return ; + } + *spmi_nack =mtk_spmi_readl (arb->spmimst_base[id], arb,SPMI_REC0 ); + *spmi_nack_data =mtk_spmi_readl (arb->spmimst_base[id], arb,SPMI_REC1 ); + *spmi_rcs_nack =mtk_spmi_readl (arb->spmimst_base[id], arb,SPMI_REC_CMD_DEC ); + *spmi_debug_nack =mtk_spmi_readl (arb->spmimst_base[id], arb,SPMI_DEC_DBG ); + *spmi_mst_nack =mtk_spmi_readl (arb->spmimst_base[id], arb,SPMI_MST_DBG ); +} +static irqreturn_t spmi_nack_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +int sid =0 ; +unsigned int spmi_nack =0 , spmi_p_nack =0 , spmi_nack_data =0 , spmi_p_nack_data =0 ; +unsigned int spmi_rcs_nack =0 , spmi_debug_nack =0 , spmi_mst_nack =0 , + spmi_p_rcs_nack =0 , spmi_p_debug_nack =0 , spmi_p_mst_nack =0 ; +u8 rdata =0 , rdata1 =0 ; +unsigned short mt6316INTSTA =0x240 , hwcidaddr_mt6316 =0x209 ,VIO18_SWITCH_6363 =0x53 , + hwcidaddr_mt6363 =0x9 ; + +mutex_lock (&arb->pmif_m_mutex); + +mtk_spmi_readl_datas (arb,0 , &spmi_nack, &spmi_nack_data, &spmi_rcs_nack, + &spmi_debug_nack, &spmi_mst_nack); +if (!IS_ERR (arb->spmimst_base[1 ])) { +mtk_spmi_readl_datas (arb,1 , &spmi_p_nack, &spmi_p_nack_data, &spmi_p_rcs_nack, + &spmi_p_debug_nack, &spmi_p_mst_nack); + } +if ((spmi_nack &0xD8 ) || (spmi_p_nack &0xD8 )) { +if (spmi_p_nack &0xD8 ) { +for (sid =0x8 ; sid >=0x6 ; sid--) { + arb->spmic->read_cmd (arb->spmic,SPMI_CMD_EXT_READL , sid, + mt6316INTSTA, &rdata,1 ); + arb->spmic->read_cmd (arb->spmic,SPMI_CMD_EXT_READL , sid, + hwcidaddr_mt6316, &rdata1,1 ); +dev_notice (&arb->spmic->dev,"%s slvid 0x%x INT_RAW_STA 0x%x cid 0x%x\n" , + __func__, sid, rdata, rdata1); + } + } +dev_notice (&arb->spmic->dev,"%s spmi transaction fail irq triggered" , __func__); +dev_notice (&arb->spmic->dev,"SPMI_REC0 m/p:0x%x/0x%x SPMI_REC1 m/p 0x%x/0x%x\n" , + spmi_nack, spmi_p_nack, spmi_nack_data, spmi_p_nack_data); + } +if ((spmi_rcs_nack &0xC0000 ) || (spmi_p_rcs_nack &0xC0000 )) { +dev_notice (&arb->spmic->dev,"%s spmi_rcs transaction fail irq triggered SPMI_REC_CMD_DEC m/p:0x%x/0x%x\n" , + __func__, spmi_rcs_nack, spmi_p_rcs_nack); + } +if ((spmi_debug_nack &0xF0000 ) || (spmi_p_debug_nack &0xF0000 )) { +dev_notice (&arb->spmic->dev,"%s spmi_debug_nack transaction fail irq triggered SPMI_DEC_DBG m/p: 0x%x/0x%x\n" , + __func__, spmi_debug_nack, spmi_p_debug_nack); + } +if ((spmi_mst_nack &0xC0000 ) || (spmi_p_mst_nack &0xC0000 )) { +dev_notice (&arb->spmic->dev,"%s spmi_mst_nack transaction fail irq triggered SPMI_MST_DBG m/p: 0x%x/0x%x\n" , + __func__, spmi_mst_nack, spmi_p_mst_nack); + } +if ((spmi_nack &0x20 ) || (spmi_p_nack &0x20 )) { +dev_notice (&arb->spmic->dev,"%s spmi transaction fail (Read) irq triggered" , __func__); +dev_notice (&arb->spmic->dev,"SPMI_REC0 m/p:0x%x/0x%x SPMI_REC1 m/p 0x%x/0x%x\n" , + spmi_nack, spmi_p_nack, spmi_nack_data, spmi_p_nack_data); + } + +if ((spmi_nack &0xF8 ) || (spmi_rcs_nack &0xC0000 ) || + (spmi_debug_nack &0xF0000 ) || (spmi_mst_nack &0xC0000 )) { +mtk_spmi_writel (arb->spmimst_base[0 ], arb,0x3 ,SPMI_REC_CTRL ); + }else if ((spmi_p_nack &0xF8 ) || (spmi_p_rcs_nack &0xC0000 ) || + (spmi_p_debug_nack &0xF0000 ) || (spmi_p_mst_nack &0xC0000 )) { +if (spmi_p_nack &0xD8 ) { +dev_notice (&arb->spmic->dev,"%s SPMI_REC0 m/p:0x%x/0x%x, SPMI_REC1 m/p:0x%x/0x%x\n" , + __func__, spmi_nack, spmi_p_nack, spmi_nack_data, spmi_p_nack_data); +dev_notice (&arb->spmic->dev,"%s SPMI_REC_CMD_DEC m/p:0x%x/0x%x\n" , __func__, + spmi_rcs_nack, spmi_p_rcs_nack); +dev_notice (&arb->spmic->dev,"%s SPMI_DEC_DBG m/p:0x%x/0x%x\n" , __func__, + spmi_debug_nack, spmi_p_debug_nack); +dev_notice (&arb->spmic->dev,"%s SPMI_MST_DBG m/p:0x%x/0x%x\n" , __func__, + spmi_mst_nack, spmi_p_mst_nack); + arb->spmic->read_cmd (arb->spmic,SPMI_CMD_EXT_READL ,0x4 , + hwcidaddr_mt6363, &rdata,1 ); + arb->spmic->read_cmd (arb->spmic,SPMI_CMD_EXT_READL ,0x4 , +VIO18_SWITCH_6363 , &rdata1,1 ); +dev_notice (&arb->spmic->dev,"%s 6363 CID/VIO18_SWITCH 0x%x/0x%x\n" , __func__, rdata, rdata1); + } +mtk_spmi_writel (arb->spmimst_base[1 ], arb,0x3 ,SPMI_REC_CTRL ); + }else +dev_notice (&arb->spmic->dev,"%s IRQ not cleared\n" , __func__); + +mutex_unlock (&arb->pmif_m_mutex); + +return IRQ_HANDLED ; +} +static int spmi_nack_irq_register (struct platform_device *pdev, +struct pmif *arb,int irq) +{ +int ret =0 ; + ret =devm_request_threaded_irq (&pdev->dev, irq,NULL , + spmi_nack_irq_handler, +IRQF_TRIGGER_HIGH |IRQF_ONESHOT |IRQF_SHARED , +"spmi_nack_irq" , arb); +if (ret <0 ) { +dev_notice (&pdev->dev,"request %s irq fail\n" , +"spmi_nack_irq" ); + } +return ret; +} +static void rcs_irq_lock (struct irq_data *data) +{ +struct pmif *arb =irq_data_get_irq_chip_data (data); +mutex_lock (&arb->rcs_m_irqlock); +} +static void rcs_irq_sync_unlock (struct irq_data *data) +{ +struct pmif *arb =irq_data_get_irq_chip_data (data); +mutex_unlock (&arb->rcs_m_irqlock); +} +static void rcs_irq_enable (struct irq_data *data) +{ +unsigned int hwirq =irqd_to_hwirq (data); +struct pmif *arb =irq_data_get_irq_chip_data (data); + arb->rcs_enable_hwirq[hwirq] = true; +} +static void rcs_irq_disable (struct irq_data *data) +{ +unsigned int hwirq =irqd_to_hwirq (data); +struct pmif *arb =irq_data_get_irq_chip_data (data); + arb->rcs_enable_hwirq[hwirq] = false; +} +static int rcs_irq_set_wake (struct irq_data *data,unsigned int on) +{ +struct pmif *arb =irq_data_get_irq_chip_data (data); +return irq_set_irq_wake (arb->rcs_irq, on); +} +static int rcs_irq_p_set_wake (struct irq_data *data,unsigned int on) +{ +struct pmif *arb =irq_data_get_irq_chip_data (data); +return irq_set_irq_wake (arb->rcs_irq_p, on); +} +static const struct irq_chip rcs_irq_chip = { + .name ="rcs_irq" , + .irq_bus_lock = rcs_irq_lock, + .irq_bus_sync_unlock = rcs_irq_sync_unlock, + .irq_enable = rcs_irq_enable, + .irq_disable = rcs_irq_disable, + .irq_set_wake = rcs_irq_set_wake, +}; + +static const struct irq_chip rcs_irq_chip_p = { + .name ="rcs_irq_p" , + .irq_bus_lock = rcs_irq_lock, + .irq_bus_sync_unlock = rcs_irq_sync_unlock, + .irq_enable = rcs_irq_enable, + .irq_disable = rcs_irq_disable, + .irq_set_wake = rcs_irq_p_set_wake, +}; +static int rcs_irq_map (struct irq_domain *d,unsigned int virq, +irq_hw_number_t hw) +{ +struct pmif *arb = d->host_data; +irq_set_chip_data (virq, arb); +irq_set_chip (virq, &arb->irq_chip); +irq_set_nested_thread (virq,1 ); +irq_set_parent (virq, arb->rcs_irq); +irq_set_noprobe (virq); +return 0 ; +} +static const struct irq_domain_ops rcs_irq_domain_ops = { + .map = rcs_irq_map, + .xlate = irq_domain_xlate_onetwocell, +}; +static void pmif_lat_limit_reached_irq_handler (int irq,void *data) +{ +} +static void pmif_acc_vio_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF ACC violation debug info\n" ); +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF-M\n" ); +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF_ACC_VIO_INFO_0 = 0x%x\n" ,pmif_readl (arb->pmif_base[0 ], + arb,PMIF_ACC_VIO_INFO_0 )); +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF_ACC_VIO_INFO_1 = 0x%x\n" ,pmif_readl (arb->pmif_base[0 ], + arb,PMIF_ACC_VIO_INFO_1 )); +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF_ACC_VIO_INFO_2 = 0x%x\n" ,pmif_readl (arb->pmif_base[0 ], + arb,PMIF_ACC_VIO_INFO_2 )); +if (!IS_ERR (arb->pmif_base[1 ])) { +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF-P\n" ); +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF_ACC_VIO_INFO_0 = 0x%x\n" ,pmif_readl (arb->pmif_base[1 ], + arb,PMIF_ACC_VIO_INFO_0 )); +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF_ACC_VIO_INFO_1 = 0x%x\n" ,pmif_readl (arb->pmif_base[1 ], + arb,PMIF_ACC_VIO_INFO_1 )); +dev_notice (&arb->spmic->dev,"[PMIF]:PMIF_ACC_VIO_INFO_2 = 0x%x\n" ,pmif_readl (arb->pmif_base[1 ], + arb,PMIF_ACC_VIO_INFO_2 )); + } +} +static void pmif_wdt_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +pmif_writel (arb->pmif_base[0 ], arb,0x40000000 ,PMIF_IRQ_CLR_0 ); +if (!IS_ERR (arb->pmif_base[1 ])) +pmif_writel (arb->pmif_base[1 ], arb,0x40000000 ,PMIF_IRQ_CLR_0 ); +dev_notice (&arb->spmic->dev,"[PMIF]:WDT IRQ HANDLER DONE\n" ); +} +static void pmif_pmif_acc_vio_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +#if (IS_ENABLED (CONFIG_MTK_AEE_FEATURE )) +aee_kernel_warning ("PMIF" ,"PMIF:pmif_acc_vio" ); +#endif +dev_notice (&arb->spmic->dev,"[PMIF]:pmif_acc_vio\n" ); +} +static void pmif_pmic_acc_vio_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +#if (IS_ENABLED (CONFIG_MTK_AEE_FEATURE )) +aee_kernel_warning ("PMIF" ,"PMIF:pmic_acc_vio" ); +#endif +dev_notice (&arb->spmic->dev,"[PMIF]:pmic_acc_vio\n" ); +} +static void pmif_cmd_err_parity_err_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +#if (IS_ENABLED (CONFIG_MTK_AEE_FEATURE )) +aee_kernel_warning ("PMIF" ,"PMIF:parity error" ); +#endif +dev_notice (&arb->spmic->dev,"[PMIF]:parity error\n" ); +} +static void pmif_hw_monitor_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +#if (IS_ENABLED (CONFIG_MTK_AEE_FEATURE )) +aee_kernel_warning ("PMIF" ,"PMIF:pmif_hw_monitor_match" ); +#endif +dev_notice (&arb->spmic->dev,"[PMIF]:pmif_hw_monitor_match\n" ); +} +static void pmif_swinf_acc_err_irq_handler (int irq,void *data,u32 val) +{ +struct pmif *arb = data; +pmif_writel (arb->pmif_base[0 ], arb, val,MD_AUXADC_RDATA_0_ADDR ); +pmif_writel (arb->pmif_base[0 ], arb, (u32 )get_current_time_ms (),MD_AUXADC_RDATA_1_ADDR ); +if (!IS_ERR (arb->pmif_base[1 ])) { +pmif_writel (arb->pmif_base[1 ], arb, val,MD_AUXADC_RDATA_0_ADDR ); +pmif_writel (arb->pmif_base[1 ], arb, (u32 )get_current_time_ms (),MD_AUXADC_RDATA_1_ADDR ); + } +dev_notice (&arb->spmic->dev,"[PMIF]:SWINF_ACC_ERR:%d\n" , val); +} +static irqreturn_t pmif_event_0_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +int irq_f =0 , irq_f_p =0 , idx =0 ; +__pm_stay_awake (arb->pmif_m_Thread_lock); +mutex_lock (&arb->pmif_m_mutex); + irq_f =pmif_readl (arb->pmif_base[0 ], arb,PMIF_IRQ_FLAG_0 ); +if (!IS_ERR (arb->pmif_base[1 ])) + irq_f_p =pmif_readl (arb->pmif_base[1 ], arb,PMIF_IRQ_FLAG_0 ); +if ((irq_f ==0 ) && (irq_f_p ==0 )) { +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_NONE ; + } +for (idx =0 ; idx <32 ; idx++) { +if (((irq_f & (0x1 << idx)) !=0 ) || ((irq_f_p & (0x1 << idx)) !=0 )) { +switch (idx) { +case IRQ_PMIF_ACC_VIO_V3 : +pmif_acc_vio_irq_handler (irq, data); +break ; +case IRQ_WDT_V4 : +pmif_wdt_irq_handler (irq, data); +break ; +case IRQ_ALL_PMIC_MPU_VIO_V4 : +pmif_pmif_acc_vio_irq_handler (irq, data); +break ; +default : +dev_notice (&arb->spmic->dev,"%s IRQ[%d] triggered\n" , + __func__, idx); +break ; + } +if (irq_f) +pmif_writel (arb->pmif_base[0 ], arb, irq_f,PMIF_IRQ_CLR_0 ); +else if (irq_f_p) +pmif_writel (arb->pmif_base[1 ], arb, irq_f_p,PMIF_IRQ_CLR_0 ); +else +dev_notice (&arb->spmic->dev,"%s IRQ[%d] is not cleared due to empty flags\n" , + __func__, idx); +break ; + } + } +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_HANDLED ; +} +static irqreturn_t pmif_event_1_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +int irq_f =0 , irq_f_p =0 , idx =0 ; +__pm_stay_awake (arb->pmif_m_Thread_lock); +mutex_lock (&arb->pmif_m_mutex); + irq_f =pmif_readl (arb->pmif_base[0 ], arb,PMIF_IRQ_FLAG_1 ); +if (!IS_ERR (arb->pmif_base[1 ])) + irq_f_p =pmif_readl (arb->pmif_base[1 ], arb,PMIF_IRQ_FLAG_1 ); +if ((irq_f ==0 ) && (irq_f_p ==0 )) { +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_NONE ; + } +for (idx =0 ; idx <32 ; idx++) { +if (((irq_f & (0x1 << idx)) !=0 ) || ((irq_f_p & (0x1 << idx)) !=0 )) { +switch (idx) { +default : +dev_notice (&arb->spmic->dev,"%s IRQ[%d] triggered\n" , + __func__, idx); +break ; + } +if (irq_f) +pmif_writel (arb->pmif_base[0 ], arb, irq_f,PMIF_IRQ_CLR_1 ); +else if (irq_f_p) +pmif_writel (arb->pmif_base[1 ], arb, irq_f_p,PMIF_IRQ_CLR_1 ); +else +dev_notice (&arb->spmic->dev,"%s IRQ[%d] is not cleared due to empty flags\n" , + __func__, idx); +break ; + } + } +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_HANDLED ; +} +static irqreturn_t pmif_event_2_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +int irq_f =0 , irq_f_p =0 , idx =0 ; +__pm_stay_awake (arb->pmif_m_Thread_lock); +mutex_lock (&arb->pmif_m_mutex); + irq_f =pmif_readl (arb->pmif_base[0 ], arb,PMIF_IRQ_FLAG_2 ); +if (!IS_ERR (arb->pmif_base[1 ])) + irq_f_p =pmif_readl (arb->pmif_base[1 ], arb,PMIF_IRQ_FLAG_2 ); +if ((irq_f ==0 ) && (irq_f_p ==0 )) { +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_NONE ; + } +for (idx =0 ; idx <32 ; idx++) { +if (((irq_f & (0x1 << idx)) !=0 ) || ((irq_f_p & (0x1 << idx)) !=0 )) { +switch (idx) { +case IRQ_PMIC_CMD_ERR_PARITY_ERR : +pmif_cmd_err_parity_err_irq_handler (irq, data); +break ; +case IRQ_PMIF_ACC_VIO_V2 : +pmif_pmif_acc_vio_irq_handler (irq, data); +break ; +case IRQ_PMIC_ACC_VIO : +pmif_pmic_acc_vio_irq_handler (irq, data); +break ; +default : +dev_notice (&arb->spmic->dev,"%s IRQ[%d] triggered\n" , + __func__, idx); +break ; + } +if (irq_f) +pmif_writel (arb->pmif_base[0 ], arb, irq_f,PMIF_IRQ_CLR_2 ); +else if (irq_f_p) +pmif_writel (arb->pmif_base[1 ], arb, irq_f_p,PMIF_IRQ_CLR_2 ); +else +dev_notice (&arb->spmic->dev,"%s IRQ[%d] is not cleared due to empty flags\n" , + __func__, idx); +break ; + } + } +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_HANDLED ; +} +static irqreturn_t pmif_event_3_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +int irq_f =0 , irq_f_p =0 , idx =0 ; +__pm_stay_awake (arb->pmif_m_Thread_lock); +mutex_lock (&arb->pmif_m_mutex); + irq_f =pmif_readl (arb->pmif_base[0 ], arb,PMIF_IRQ_FLAG_3 ); +if (!IS_ERR (arb->pmif_base[1 ])) + irq_f_p =pmif_readl (arb->pmif_base[1 ], arb,PMIF_IRQ_FLAG_3 ); +if ((irq_f ==0 ) && (irq_f_p ==0 )) { +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_NONE ; + } +for (idx =0 ; idx <32 ; idx++) { +if (((irq_f & (0x1 << idx)) !=0 ) || ((irq_f_p & (0x1 << idx)) !=0 )) { +switch (idx) { +case IRQ_PMIF_SWINF_ACC_ERR_0 : +case IRQ_PMIF_SWINF_ACC_ERR_0_V2 : +pmif_swinf_acc_err_irq_handler (irq, data,0x0 ); +break ; +case IRQ_PMIF_SWINF_ACC_ERR_1 : +case IRQ_PMIF_SWINF_ACC_ERR_1_V2 : +pmif_swinf_acc_err_irq_handler (irq, data,0x1 ); +break ; +case IRQ_PMIF_SWINF_ACC_ERR_2 : +case IRQ_PMIF_SWINF_ACC_ERR_2_V2 : +pmif_swinf_acc_err_irq_handler (irq, data,0x2 ); +break ; +case IRQ_LAT_LIMIT_REACHED : +case IRQ_PMIF_SWINF_ACC_ERR_3_V2 : +if (arb->data->caps ==1 ) +pmif_lat_limit_reached_irq_handler (irq, data); +else +pmif_swinf_acc_err_irq_handler (irq, data,0x3 ); +break ; +case IRQ_PMIF_SWINF_ACC_ERR_4 : +case IRQ_PMIF_SWINF_ACC_ERR_4_V2 : +pmif_swinf_acc_err_irq_handler (irq, data,0x4 ); +break ; +case IRQ_PMIF_SWINF_ACC_ERR_5 : +case IRQ_PMIF_SWINF_ACC_ERR_5_V2 : +pmif_swinf_acc_err_irq_handler (irq, data,0x5 ); +break ; +case IRQ_HW_MONITOR_V2 : +case IRQ_HW_MONITOR_V3 : +pmif_hw_monitor_irq_handler (irq, data); +break ; +case IRQ_WDT_V2 : +case IRQ_WDT_V3 : +pmif_wdt_irq_handler (irq, data); +break ; +case IRQ_PMIC_ACC_VIO_V2 : +pmif_pmic_acc_vio_irq_handler (irq, data); +break ; +case IRQ_ALL_PMIC_MPU_VIO_V2 : +case IRQ_ALL_PMIC_MPU_VIO_V3 : +pmif_pmif_acc_vio_irq_handler (irq, data); +break ; +default : +dev_notice (&arb->spmic->dev,"%s IRQ[%d] triggered\n" , __func__, idx); +break ; + } +if (irq_f) { +if ((!(irq_f & (0x1 <<IRQ_PMIF_SWINF_ACC_ERR_0 ))) && + (!(irq_f & (0x1 <<IRQ_PMIF_SWINF_ACC_ERR_0_V2 )))) +pmif_writel (arb->pmif_base[0 ], arb, irq_f,PMIF_IRQ_CLR_3 ); + }else if (irq_f_p) { +if ((!(irq_f_p & (0x1 <<IRQ_PMIF_SWINF_ACC_ERR_0 ))) && + (!(irq_f & (0x1 <<IRQ_PMIF_SWINF_ACC_ERR_0_V2 )))) +pmif_writel (arb->pmif_base[1 ], arb, irq_f_p,PMIF_IRQ_CLR_3 ); + }else +dev_notice (&arb->spmic->dev,"%s IRQ[%d] is not cleared due to empty flags\n" , + __func__, idx); +break ; + } + } +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_HANDLED ; +} +static irqreturn_t pmif_event_4_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +int irq_f =0 , irq_f_p =0 , idx =0 ; +__pm_stay_awake (arb->pmif_m_Thread_lock); +mutex_lock (&arb->pmif_m_mutex); + irq_f =pmif_readl (arb->pmif_base[0 ], arb,PMIF_IRQ_FLAG_4 ); +if (!IS_ERR (arb->pmif_base[1 ])) + irq_f_p =pmif_readl (arb->pmif_base[1 ], arb,PMIF_IRQ_FLAG_4 ); +if ((irq_f ==0 ) && (irq_f_p ==0 )) { +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_NONE ; + } +for (idx =0 ; idx <32 ; idx++) { +if (((irq_f & (0x1 << idx)) !=0 ) || ((irq_f_p & (0x1 << idx)) !=0 )) { +switch (idx) { +default : +dev_notice (&arb->spmic->dev,"%s IRQ[%d] triggered\n" , + __func__, idx); +break ; + } +if (irq_f) +pmif_writel (arb->pmif_base[0 ], arb, irq_f,PMIF_IRQ_CLR_4 ); +else if (irq_f_p) +pmif_writel (arb->pmif_base[1 ], arb, irq_f_p,PMIF_IRQ_CLR_4 ); +else +dev_notice (&arb->spmic->dev,"%s IRQ[%d] is not cleared due to empty flags\n" , + __func__, idx); +break ; + } + } +mutex_unlock (&arb->pmif_m_mutex); +__pm_relax (arb->pmif_m_Thread_lock); +return IRQ_HANDLED ; +} +static struct pmif_irq_desc pmif_event_irq[] = { +PMIF_IRQDESC (event_0), +PMIF_IRQDESC (event_1), +PMIF_IRQDESC (event_2), +PMIF_IRQDESC (event_3), +PMIF_IRQDESC (event_4), +}; +static void pmif_irq_register (struct platform_device *pdev, +struct pmif *arb,int irq) +{ +int i =0 , ret =0 ; +u32 irq_event_en[5 ] = {0 }; +for (i =0 ; i <ARRAY_SIZE (pmif_event_irq); i++) { +if (!pmif_event_irq[i].name) +continue ; + ret =devm_request_threaded_irq (&pdev->dev, irq,NULL , + pmif_event_irq[i].irq_handler, +IRQF_TRIGGER_HIGH |IRQF_ONESHOT |IRQF_SHARED , + pmif_event_irq[i].name, arb); +if (ret <0 ) { +dev_notice (&pdev->dev,"request %s irq fail\n" , + pmif_event_irq[i].name); +continue ; + } + pmif_event_irq[i].irq = irq; + } + ret =of_property_read_u32_array (pdev->dev.of_node,"irq-event-en" , + irq_event_en,ARRAY_SIZE (irq_event_en)); +pmif_writel (arb->pmif_base[0 ], arb, irq_event_en[0 ] |pmif_readl (arb->pmif_base[0 ], + arb,PMIF_IRQ_EVENT_EN_0 ),PMIF_IRQ_EVENT_EN_0 ); +pmif_writel (arb->pmif_base[0 ], arb, irq_event_en[1 ] |pmif_readl (arb->pmif_base[0 ], + arb,PMIF_IRQ_EVENT_EN_1 ),PMIF_IRQ_EVENT_EN_1 ); +pmif_writel (arb->pmif_base[0 ], arb, irq_event_en[2 ] |pmif_readl (arb->pmif_base[0 ], + arb,PMIF_IRQ_EVENT_EN_2 ),PMIF_IRQ_EVENT_EN_2 ); +pmif_writel (arb->pmif_base[0 ], arb, irq_event_en[3 ] |pmif_readl (arb->pmif_base[0 ], + arb,PMIF_IRQ_EVENT_EN_3 ),PMIF_IRQ_EVENT_EN_3 ); +pmif_writel (arb->pmif_base[0 ], arb, irq_event_en[4 ] |pmif_readl (arb->pmif_base[0 ], + arb,PMIF_IRQ_EVENT_EN_4 ),PMIF_IRQ_EVENT_EN_4 ); +if (!IS_ERR (arb->pmif_base[1 ])) { +pmif_writel (arb->pmif_base[1 ], arb, irq_event_en[0 ] |pmif_readl (arb->pmif_base[1 ], + arb,PMIF_IRQ_EVENT_EN_0 ),PMIF_IRQ_EVENT_EN_0 ); +pmif_writel (arb->pmif_base[1 ], arb, irq_event_en[1 ] |pmif_readl (arb->pmif_base[1 ], + arb,PMIF_IRQ_EVENT_EN_1 ),PMIF_IRQ_EVENT_EN_1 ); +pmif_writel (arb->pmif_base[1 ], arb, irq_event_en[2 ] |pmif_readl (arb->pmif_base[1 ], + arb,PMIF_IRQ_EVENT_EN_2 ),PMIF_IRQ_EVENT_EN_2 ); +pmif_writel (arb->pmif_base[1 ], arb, irq_event_en[3 ] |pmif_readl (arb->pmif_base[1 ], + arb,PMIF_IRQ_EVENT_EN_3 ),PMIF_IRQ_EVENT_EN_3 ); +pmif_writel (arb->pmif_base[1 ], arb, irq_event_en[4 ] |pmif_readl (arb->pmif_base[1 ], + arb,PMIF_IRQ_EVENT_EN_4 ),PMIF_IRQ_EVENT_EN_4 ); + } +} +static irqreturn_t rcs_irq_handler (int irq,void *data) +{ +struct pmif *arb = data; +unsigned int slv_irq_sta, slv_irq_sta_p; +int i; + +for (i =0 ; i <SPMI_MAX_SLAVE_ID ; i++) { + slv_irq_sta =mtk_spmi_readl (arb->spmimst_base[0 ], arb,SPMI_SLV_3_0_EINT + (i /4 )); + slv_irq_sta = (slv_irq_sta >> ((i %4 ) *8 )) &0xFF ; +if (!IS_ERR (arb->spmimst_base[1 ])) { + slv_irq_sta_p =mtk_spmi_readl (arb->spmimst_base[1 ], arb,SPMI_SLV_3_0_EINT + (i /4 )); + slv_irq_sta_p = (slv_irq_sta_p >> ((i %4 ) *8 )) &0xFF ; + } +if (slv_irq_sta) { +mtk_spmi_writel (arb->spmimst_base[0 ], arb, (0xFF << ((i %4 ) *8 )), +SPMI_SLV_3_0_EINT + (i /4 )); +if (arb->rcs_enable_hwirq[i] && slv_irq_sta) { +dev_info (&arb->spmic->dev, +"hwirq=%d, sta=0x%x\n" , i, slv_irq_sta); +handle_nested_irq (irq_find_mapping (arb->domain, i)); + } + }else { +if (!IS_ERR (arb->spmimst_base[1 ])) { +mtk_spmi_writel (arb->spmimst_base[1 ], arb, (0xFF << ((i %4 ) *8 )), +SPMI_SLV_3_0_EINT + (i /4 )); +if (arb->rcs_enable_hwirq[i] && slv_irq_sta_p) { +dev_info (&arb->spmic->dev, +"hwirq=%d, sta=0x%x\n" , i, slv_irq_sta_p); +handle_nested_irq (irq_find_mapping (arb->domain, i)); + } + } + } + } +return IRQ_HANDLED ; +} +static int rcs_irq_register (struct platform_device *pdev, +struct pmif *arb,int irq) +{ +int i, ret =0 ; +mutex_init (&arb->rcs_m_irqlock); +mutex_init (&arb->rcs_p_irqlock); + arb->rcs_enable_hwirq =devm_kcalloc (&pdev->dev,SPMI_MAX_SLAVE_ID , +sizeof (*arb->rcs_enable_hwirq), +GFP_KERNEL ); +if (!arb->rcs_enable_hwirq) +return -ENOMEM ; +if (arb->rcs_irq == irq) + arb->irq_chip = rcs_irq_chip; +else if (arb->rcs_irq_p == irq) + arb->irq_chip_p = rcs_irq_chip_p; +else +dev_notice (&pdev->dev,"no rcs irq %d registered\n" , irq); + arb->domain =irq_domain_add_linear (pdev->dev.of_node, +SPMI_MAX_SLAVE_ID , + &rcs_irq_domain_ops, arb); +if (!arb->domain) { +dev_notice (&pdev->dev,"Failed to create IRQ domain\n" ); +return -ENODEV ; + } +for (i =0 ; i <SPMI_MAX_SLAVE_ID ; i++) { +mtk_spmi_writel (arb->spmimst_base[0 ], arb, (0xFF << ((i %4 ) *8 )), +SPMI_SLV_3_0_EINT + (i /4 )); +if (!IS_ERR (arb->spmimst_base[1 ])) { +mtk_spmi_writel (arb->spmimst_base[1 ], arb, (0xFF << ((i %4 ) *8 )), +SPMI_SLV_3_0_EINT + (i /4 )); + } + } + ret =devm_request_threaded_irq (&pdev->dev, irq,NULL , + rcs_irq_handler,IRQF_ONESHOT , + rcs_irq_chip.name, arb); +if (ret <0 ) { +dev_notice (&pdev->dev,"Failed to request IRQ=%d, ret = %d\n" , + irq, ret); +return ret; + } +enable_irq_wake (irq); +return ret; +}static int mtk_spmi_probe (struct platform_device *pdev) {struct pmif *arb;
@@ -457,41 +1293,50 @@ static int mtk_spmi_probe(struct platform_device *pdev)if (IS_ERR (ctrl))return PTR_ERR (ctrl); + ctrl->cmd = pmif_arb_cmd; + ctrl->read_cmd = pmif_spmi_read_cmd; + ctrl->write_cmd = pmif_spmi_write_cmd; arb =spmi_controller_get_drvdata (ctrl); + arb->spmic = ctrl; arb->data =device_get_match_data (&pdev->dev);if (!arb->data) {dev_err (&pdev->dev,"Cannot get drv_data\n" );return -EINVAL ; } - arb->base =devm_platform_ioremap_resource_byname (pdev,"pmif" ); -if (IS_ERR (arb->base)) -return PTR_ERR (arb->base); - - arb->spmimst_base =devm_platform_ioremap_resource_byname (pdev,"spmimst" ); -if (IS_ERR (arb->spmimst_base)) -return PTR_ERR (arb->spmimst_base); - - arb->nclks =ARRAY_SIZE (pmif_clock_names); -for (i =0 ; i < arb->nclks; i++) - arb->clks[i].id = pmif_clock_names[i]; - - err =clk_bulk_get (&pdev->dev, arb->nclks, arb->clks); -if (err) { -dev_err (&pdev->dev,"Failed to get clocks: %d\n" , err); -return err; - } - - err =clk_bulk_prepare_enable (arb->nclks, arb->clks); -if (err) { -dev_err (&pdev->dev,"Failed to enable clocks: %d\n" , err); - goto err_put_clks; + arb->pmif_base[0 ] =devm_platform_ioremap_resource_byname (pdev,"pmif" ); +if (IS_ERR (arb->pmif_base[0 ])) +return PTR_ERR (arb->pmif_base[0 ]); + + arb->spmimst_base[0 ] =devm_platform_ioremap_resource_byname (pdev,"spmimst" ); +if (IS_ERR (arb->spmimst_base[0 ])) +return PTR_ERR (arb->spmimst_base[0 ]); + + arb->pmif_base[1 ] =devm_platform_ioremap_resource_byname (pdev,"pmif-p" ); +if (IS_ERR (arb->pmif_base[1 ])) +dev_notice (&pdev->dev,"[PMIF]:no pmif-p found\n" ); + arb->spmimst_base[1 ] =devm_platform_ioremap_resource_byname (pdev,"spmimst-p" ); +if (IS_ERR (arb->spmimst_base[1 ])) +dev_notice (&pdev->dev,"[PMIF]:no spmimst-p found\n" ); +if (arb->data->caps ==1 ) { + + arb->nclks =ARRAY_SIZE (pmif_clock_names); +for (i =0 ; i < arb->nclks; i++) + arb->clks[i].id = pmif_clock_names[i]; + + err =clk_bulk_get (&pdev->dev, arb->nclks, arb->clks); +if (err) { +dev_err (&pdev->dev,"Failed to get clocks: %d\n" , err); +return err; + } + + err =clk_bulk_prepare_enable (arb->nclks, arb->clks); +if (err) { +dev_err (&pdev->dev,"Failed to enable clocks: %d\n" , err); + goto err_put_clks; + } } - ctrl->cmd = pmif_arb_cmd; - ctrl->read_cmd = pmif_spmi_read_cmd; - ctrl->write_cmd = pmif_spmi_write_cmd; - chan_offset =PMIF_CHAN_OFFSET * arb->data->soc_chan; arb->chan.ch_sta =PMIF_SWINF_0_STA + chan_offset; arb->chan.wdata =PMIF_SWINF_0_WDATA_31_0 + chan_offset;
@@ -499,7 +1344,71 @@ static int mtk_spmi_probe(struct platform_device *pdev) arb->chan.ch_send =PMIF_SWINF_0_ACC + chan_offset; arb->chan.ch_rdy =PMIF_SWINF_0_VLD_CLR + chan_offset; -raw_spin_lock_init (&arb->lock); +raw_spin_lock_init (&arb->lock_m); +raw_spin_lock_init (&arb->lock_p); + arb->pmif_m_Thread_lock = +wakeup_source_register (NULL ,"pmif_m wakelock" ); + arb->pmif_p_Thread_lock = +wakeup_source_register (NULL ,"pmif_p wakelock" ); +mutex_init (&arb->pmif_m_mutex); +mutex_init (&arb->pmif_p_mutex); +if (arb->data->caps ==2 ) { + arb->irq =platform_get_irq_byname (pdev,"pmif_irq" ); +if (arb->irq <0 ) { +dev_notice (&pdev->dev, +"Failed to get pmif_irq, ret = %d\n" , arb->irq); + } +pmif_irq_register (pdev, arb, arb->irq); + arb->irq_p =platform_get_irq_byname (pdev,"pmif_p_irq" ); +if (arb->irq_p <0 ) { +dev_notice (&pdev->dev, +"Failed to get pmif_p_irq, ret = %d\n" , arb->irq_p); + } +pmif_irq_register (pdev, arb, arb->irq_p); + arb->rcs_irq =platform_get_irq_byname (pdev,"rcs_irq" ); +if (arb->rcs_irq <0 ) { +dev_notice (&pdev->dev, +"Failed to get rcs_irq, ret = %d\n" , arb->rcs_irq); + }else { + err =rcs_irq_register (pdev, arb, arb->rcs_irq); +if (err) +dev_notice (&pdev->dev, +"Failed to register rcs_irq, ret = %d\n" , arb->rcs_irq); + } + arb->rcs_irq_p =platform_get_irq_byname (pdev,"rcs_irq_p" ); +if (arb->rcs_irq_p <0 ) { +dev_notice (&pdev->dev, +"Failed to get rcs_irq_p, ret = %d\n" , arb->rcs_irq_p); + }else { + err =rcs_irq_register (pdev, arb, arb->rcs_irq_p); +if (err) +dev_notice (&pdev->dev, +"Failed to register rcs_irq_p, ret = %d\n" , arb->rcs_irq_p); + } + arb->spmi_nack_irq =platform_get_irq_byname (pdev,"spmi_nack_irq" ); +if (arb->spmi_nack_irq <0 ) { +dev_notice (&pdev->dev, +"Failed to get spmi_nack_irq, ret = %d\n" , arb->spmi_nack_irq); + }else { + err =spmi_nack_irq_register (pdev, arb, arb->spmi_nack_irq); +if (err) +dev_notice (&pdev->dev, +"Failed to register spmi_nack_irq, ret = %d\n" , + arb->spmi_nack_irq); + } + arb->spmi_p_nack_irq =platform_get_irq_byname (pdev,"spmi_p_nack_irq" ); +if (arb->spmi_p_nack_irq <0 ) { +dev_notice (&pdev->dev, +"Failed to get spmi_p_nack_irq, ret = %d\n" , arb->spmi_p_nack_irq); + }else { + err =spmi_nack_irq_register (pdev, arb, arb->spmi_p_nack_irq); +if (err) +dev_notice (&pdev->dev, +"Failed to register spmi_p_nack_irq, ret = %d\n" , + arb->spmi_p_nack_irq); + } + } +spmi_dev_parse (pdev);platform_set_drvdata (pdev, ctrl);
@@ -533,6 +1442,9 @@ static const struct of_device_id mtk_spmi_match_table[] = { }, { .compatible = "mediatek,mt8195-spmi", .data = &mt8195_pmif_arb, + }, { + .compatible = "mediatek,mt8196-spmi", + .data = &mt6xxx_pmif_arb, }, { /* sentinel */ },
Signature · 1 line
2.46.0
回复: [PATCH 4/5] spmi: mediatek: modify spmi dirver for mt8196
Update email address
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:33
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Project_Global_Chrome_Upstream_Group <[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 4/5] spmi: mediatek: modify spmi dirver for mt8196
From: "Lu.Tang" <[email protected]>
Modify spmi driver for mt8196 pmic.
Add pmif_s/pmif_m controller and rcs irq handler.
--- drivers/spmi/spmi-mtk-pmif.c | 1040 +++++++++++++++++++++++++++++++--- 1 file changed, 976 insertions(+), 64 deletions(-)
drivers/spmi/spmi-mtk-pmif.c +222 -13
@@ -1,14 +1,20 @@// SPDX-License-Identifier: GPL-2.0 // -// Copyright (c) 2021 MediaTek Inc. +// Copyright (c) 2024 MediaTek Inc. #include <linux/clk.h> #include <linux/iopoll.h> +#include <linux/interrupt.h> +#include <linux/irqdomain.h> +#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/sched/clock.h> +#include <linux/sched/mm.h> #include <linux/platform_device.h> #include <linux/property.h> #include <linux/spmi.h> +#include <linux/irq.h> #define SWINF_IDLE 0x00#define SWINF_WFVLDCLR 0x06
@@ -21,14 +27,21 @@#define PMIF_CMD_EXT_REG_LONG 3#define PMIF_DELAY_US 10 -#define PMIF_TIMEOUT_US (10 * 1000) +#define PMIF_TIMEOUT_US (100 * 1000)#define PMIF_CHAN_OFFSET 0x5 +#define PMIF_CAPS_VER_1 1 +#define PMIF_CAPS_VER_2 2 +#define PMIF_MAX_CLKS 3#define SPMI_OP_ST_BUSY 1 +#define SPMI_SOC_CHANNEL 2 + +#define PMIF_IRQDESC (name) { #name, pmif_##name##_irq_handler, -1} +struct ch_reg {u32 ch_sta;u32 wdata;
@@ -41,25 +54,53 @@ struct pmif_data {const u32 *regs;const u32 *spmimst_regs;u32 soc_chan; +u32 caps; };struct pmif { -void __iomem *base; -void __iomem *spmimst_base; +void __iomem *pmif_base[2 ]; +void __iomem *spmimst_base[2 ];struct ch_reg chan;struct clk_bulk_data clks[PMIF_MAX_CLKS ];size_t nclks;const struct pmif_data *data; -raw_spinlock_t lock; +raw_spinlock_t lock_m; +raw_spinlock_t lock_p; +struct spmi_controller *spmic; +struct wakeup_source *pmif_m_Thread_lock; +struct wakeup_source *pmif_p_Thread_lock; +struct mutex pmif_m_mutex; +struct mutex pmif_p_mutex; +int irq; +int irq_p; +struct irq_domain *domain; +struct irq_chip irq_chip; +struct irq_chip irq_chip_p; +int rcs_irq; +int rcs_irq_p; +struct mutex rcs_m_irqlock; +struct mutex rcs_p_irqlock; +bool *rcs_enable_hwirq; +int spmi_nack_irq; +int spmi_p_nack_irq; };static const char *const pmif_clock_names[] = {"pmif_sys_ck" ,"pmif_tmr_ck" ,"spmimst_clk_mux" , }; +struct pmif_irq_desc { +const char *name; +irq_handler_t irq_handler; +int irq; +}; +enum pmif_regs {PMIF_INIT_DONE ,PMIF_INF_EN , +MD_AUXADC_RDATA_0_ADDR , +MD_AUXADC_RDATA_1_ADDR , +MD_AUXADC_RDATA_2_ADDR ,PMIF_ARB_EN ,PMIF_CMDISSUE_EN ,PMIF_TIMER_CTRL ,
@@ -103,6 +144,11 @@ enum pmif_regs {PMIF_SWINF_3_RDATA_31_0 ,PMIF_SWINF_3_ACC ,PMIF_SWINF_3_VLD_CLR , +PMIF_PMIC_SWINF_0_PER , +PMIF_PMIC_SWINF_1_PER , +PMIF_ACC_VIO_INFO_0 , +PMIF_ACC_VIO_INFO_1 , + PMIF_ACC_VIO_INFO_2, }; static const u32 mt6873_regs[] = {
@@ -201,6 +247,63 @@ static const u32 mt8195_regs[] = { [PMIF_SWINF_3_STA] = 0x08E8, }; +static const u32 mt6xxx_regs[] = { + [PMIF_INIT_DONE ] =0x0000 , + [PMIF_INF_EN ] =0x0024 , + [MD_AUXADC_RDATA_0_ADDR ] =0x0080 , + [MD_AUXADC_RDATA_1_ADDR ] =0x0084 , + [MD_AUXADC_RDATA_2_ADDR ] =0x0088 , + [PMIF_ARB_EN ] =0x0150 , + [PMIF_CMDISSUE_EN ] =0x03B8 , + [PMIF_TIMER_CTRL ] =0x03E4 , + [PMIF_SPI_MODE_CTRL ] =0x0408 , + [PMIF_IRQ_EVENT_EN_0 ] =0x0420 , + [PMIF_IRQ_FLAG_0 ] =0x0428 , + [PMIF_IRQ_CLR_0 ] =0x042C , + [PMIF_IRQ_EVENT_EN_1 ] =0x0430 , + [PMIF_IRQ_FLAG_1 ] =0x0438 , + [PMIF_IRQ_CLR_1 ] =0x043C , + [PMIF_IRQ_EVENT_EN_2 ] =0x0440 , + [PMIF_IRQ_FLAG_2 ] =0x0448 , + [PMIF_IRQ_CLR_2 ] =0x044C , + [PMIF_IRQ_EVENT_EN_3 ] =0x0450 , + [PMIF_IRQ_FLAG_3 ] =0x0458 , + [PMIF_IRQ_CLR_3 ] =0x045C , + [PMIF_IRQ_EVENT_EN_4 ] =0x0460 , + [PMIF_IRQ_FLAG_4 ] =0x0468 , + [PMIF_IRQ_CLR_4 ] =0x046C , + [PMIF_WDT_EVENT_EN_0 ] =0x0474 , + [PMIF_WDT_FLAG_0 ] =0x0478 , + [PMIF_WDT_EVENT_EN_1 ] =0x047C , + [PMIF_WDT_FLAG_1 ] =0x0480 , + [PMIF_SWINF_0_ACC ] =0x0800 , + [PMIF_SWINF_0_WDATA_31_0 ] =0x0804 , + [PMIF_SWINF_0_RDATA_31_0 ] =0x0814 , + [PMIF_SWINF_0_VLD_CLR ] =0x0824 , + [PMIF_SWINF_0_STA ] =0x0828 , + [PMIF_SWINF_1_ACC ] =0x0840 , + [PMIF_SWINF_1_WDATA_31_0 ] =0x0844 , + [PMIF_SWINF_1_RDATA_31_0 ] =0x0854 , + [PMIF_SWINF_1_VLD_CLR ] =0x0864 , + [PMIF_SWINF_1_STA ] =0x0868 , + [PMIF_SWINF_2_ACC ] =0x0880 , + [PMIF_SWINF_2_WDATA_31_0 ] =0x0884 , + [PMIF_SWINF_2_RDATA_31_0 ] =0x0894 , + [PMIF_SWINF_2_VLD_CLR ] =0x08A4 , + [PMIF_SWINF_2_STA ] =0x08A8 , + [PMIF_SWINF_3_ACC ] =0x08C0 , + [PMIF_SWINF_3_WDATA_31_0 ] =0x08C4 , + [PMIF_SWINF_3_RDATA_31_0 ] =0x08D4 , + [PMIF_SWINF_3_VLD_CLR ] =0x08E4 , + [PMIF_SWINF_3_STA ] =0x08E8 , + [PMIF_PMIC_SWINF_0_PER ] =0x093C , + [PMIF_PMIC_SWINF_1_PER ] =0x0940 , + [PMIF_ACC_VIO_INFO_0 ] =0x0980 , + [PMIF_ACC_VIO_INFO_1 ] =0x0984 , + [PMIF_ACC_VIO_INFO_2 ] =0x0988 , + +}; +enum spmi_regs {SPMI_OP_ST_CTRL ,SPMI_GRP_ID_EN ,
@@ -262,26 +365,132 @@ static const u32 mt8195_spmi_regs[] = { [SPMI_MST_DBG] = 0x00FC, }; -static u32 pmif_readl (struct pmif *arb,enum pmif_regs reg) +static const u32 mt6853_spmi_regs[] = { + [SPMI_OP_ST_CTRL ] =0x0000 , + [SPMI_GRP_ID_EN ] =0x0004 , + [SPMI_OP_ST_STA ] =0x0008 , + [SPMI_MST_SAMPL ] =0x000C , + [SPMI_MST_REQ_EN ] =0x0010 , + [SPMI_MST_RCS_CTRL ] =0x0014 , + [SPMI_SLV_3_0_EINT ] =0x0020 , + [SPMI_SLV_7_4_EINT ] =0x0024 , + [SPMI_SLV_B_8_EINT ] =0x0028 , + [SPMI_SLV_F_C_EINT ] =0x002C , + [SPMI_REC_CTRL ] =0x0040 , + [SPMI_REC0 ] =0x0044 , + [SPMI_REC1 ] =0x0048 , + [SPMI_REC2 ] =0x004C , + [SPMI_REC3 ] =0x0050 , + [SPMI_REC4 ] =0x0054 , + [SPMI_REC_CMD_DEC ] =0x005C , + [SPMI_DEC_DBG ] =0x00F8 , + [SPMI_MST_DBG ] =0x00FC , +}; + +enum { +IRQ_LAT_LIMIT_REACHED =6 , +IRQ_HW_MONITOR =7 , +IRQ_WDT =8 , +/* MT6833/MT6877 series */ +IRQ_HW_MONITOR_V3 =12 , +IRQ_WDT_V3 =13 , +IRQ_ALL_PMIC_MPU_VIO_V3 =14 , +/* MT6885/MT6873 series */ +IRQ_PMIC_CMD_ERR_PARITY_ERR =17 , +IRQ_PMIF_ACC_VIO =20 , +IRQ_PMIC_ACC_VIO =21 , +/* MT6985/MT6897 */ +IRQ_PMIF_ACC_VIO_V3 =27 , +/* MT6853 series */ +IRQ_PMIF_ACC_VIO_V2 =31 , +}; + +enum { +IRQ_PMIC_ACC_VIO_V2 =0 , +IRQ_PMIF_SWINF_ACC_ERR_0 =3 , +IRQ_PMIF_SWINF_ACC_ERR_1 =4 , +IRQ_PMIF_SWINF_ACC_ERR_2 =5 , +IRQ_PMIF_SWINF_ACC_ERR_3 =6 , +IRQ_PMIF_SWINF_ACC_ERR_4 =7 , +IRQ_PMIF_SWINF_ACC_ERR_5 =8 , +IRQ_HW_MONITOR_V2 =18 , +IRQ_WDT_V2 =19 , +IRQ_ALL_PMIC_MPU_VIO_V2 =20 , +IRQ_PMIF_SWINF_ACC_ERR_0_V2 =23 , +IRQ_PMIF_SWINF_ACC_ERR_1_V2 =24 , +IRQ_PMIF_SWINF_ACC_ERR_2_V2 =25 , +IRQ_PMIF_SWINF_ACC_ERR_3_V2 =26 , +IRQ_PMIF_SWINF_ACC_ERR_4_V2 =27 , +IRQ_PMIF_SWINF_ACC_ERR_5_V2 =28 , +/* MT6983/MT6879 */ +IRQ_HW_MONITOR_V4 =29 , +IRQ_WDT_V4 =30 , +IRQ_ALL_PMIC_MPU_VIO_V4 =31 , +}; + +struct spmi_dev { +int exist; +int slvid; +unsigned int path; +unsigned short hwcid_addr; +unsigned char hwcid_val; +}; + +static struct spmi_dev spmidev[16 ]; + +static void spmi_dev_parse (struct platform_device *pdev) { -return readl (arb->base + arb->data->regs[reg]); +int i =0 , j =0 , ret =0 ; +u32 spmi_dev_mask =0 ; + + ret =of_property_read_u32 (pdev->dev.of_node,"spmi-dev-mask" , + &spmi_dev_mask); +if (ret) + dev_info(&pdev->dev, "No spmi-dev-mask found in dts, default all PMIC +on SPMI-M\n"); + + j = spmi_dev_mask; +for (i =0 ; i <16 ; i++) { +if (j &BIT (i)) + spmidev[i].path =1 ;/* slvid i is in path p */ +else + spmidev[i].path =0 ; + } +} + +unsigned long long get_current_time_ms (void ) { +unsigned long long cur_ts; + + cur_ts =sched_clock (); +do_div (cur_ts,1000000 ); +return cur_ts; } -static void pmif_writel (struct pmif *arb,u32 val,enum pmif_regs reg) +static u32 pmif_readl (void __iomem *addr,struct pmif *arb,enum +pmif_regs reg) { -writel (val, arb->base + arb->data->regs[reg]); +return readl (addr + arb->data->regs[reg]); } -static void mtk_spmi_writel (struct pmif *arb,u32 val,enum spmi_regs reg) +static void pmif_writel (void __iomem *addr,struct pmif *arb,u32 val, +enum pmif_regs reg) { -writel (val, arb->spmimst_base + arb->data->spmimst_regs[reg]); +writel (val, addr + arb->data->regs[reg]); } -static bool pmif_is_fsm_vldclr (struct pmif *arb) +static void mtk_spmi_writel (void __iomem *addr,struct pmif *arb,u32 +val,enum spmi_regs reg) { +writel (val, addr + arb->data->spmimst_regs[reg]); } + +static u32 mtk_spmi_readl (void __iomem *addr,struct pmif *arb,enum +spmi_regs reg) { +return readl (addr + arb->data->spmimst_regs[reg]); } + +static bool pmif_is_fsm_vldclr (void __iomem *addr,struct pmif *arb) {u32 reg_rdata; - reg_rdata =pmif_readl (arb, arb->chan.ch_sta); + reg_rdata =pmif_readl (addr, arb, arb->chan.ch_sta); return GET_SWINF(reg_rdata) == SWINF_WFVLDCLR; } @@ -298,8 +507,8 @@ static int pmif_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid)
cmd = opc - SPMI_CMD_RESET;
- mtk_spmi_writel(arb, (cmd << 0x4) | sid, SPMI_OP_ST_CTRL);
- ret = readl_poll_timeout_atomic(arb->spmimst_base + arb->data->spmimst_regs[SPMI_OP_ST_STA],
+ mtk_spmi_writel(arb->spmimst_base[spmidev[sid].path], arb, (cmd << 0x4) | sid, SPMI_OP_ST_CTRL);
+ ret = readl_poll_timeout_atomic(arb->spmimst_base[spmidev[sid].path] +
+arb->data->spmimst_regs[SPMI_OP_ST_STA],
rdata, (rdata & SPMI_OP_ST_BUSY) == SPMI_OP_ST_BUSY, PMIF_DELAY_US, PMIF_TIMEOUT_US);
if (ret < 0)
@@ -315,7 +524,7 @@ static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
struct ch_reg *inf_reg;
int ret;
u32 data, cmd;
- unsigned long flags;
+ unsigned long flags_m;
/* Check for argument validation. */
if (sid & ~0xf) {
@@ -336,31 +545,31 @@ static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
else
return -EINVAL;
- raw_spin_lock_irqsave(&arb->lock, flags);
+ raw_spin_lock_irqsave(&arb->lock_m, flags_m);
/* Wait for Software Interface FSM state to be IDLE. */ inf_reg = &arb->chan;
- ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta],
+ ret = readl_poll_timeout_atomic(arb->pmif_base[spmidev[sid].path] +
+arb->data->regs[inf_reg->ch_sta],
data, GET_SWINF(data) == SWINF_IDLE, PMIF_DELAY_US, PMIF_TIMEOUT_US);
if (ret < 0) {
/* set channel ready if the data has transferred */
- if (pmif_is_fsm_vldclr(arb))
- pmif_writel(arb, 1, inf_reg->ch_rdy);
- raw_spin_unlock_irqrestore(&arb->lock, flags);
+ if (pmif_is_fsm_vldclr(arb->pmif_base[spmidev[sid].path], arb))
+ pmif_writel(arb->pmif_base[spmidev[sid].path], arb, 1, inf_reg->ch_rdy);
+ raw_spin_unlock_irqrestore(&arb->lock_m, flags_m);
dev_err(&ctrl->dev, "failed to wait for SWINF_IDLE\n"); return ret;
}
/* Send the command. */
cmd = (opc << 30) | (sid << 24) | ((len - 1) << 16) | addr;
- pmif_writel(arb, cmd, inf_reg->ch_send);
- raw_spin_unlock_irqrestore(&arb->lock, flags);
+ pmif_writel(arb->pmif_base[spmidev[sid].path], arb, cmd, inf_reg->ch_send);
+ raw_spin_unlock_irqrestore(&arb->lock_m, flags_m);
/*
* Wait for Software Interface FSM state to be WFVLDCLR,
* read the data and clear the valid flag.
*/
- ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta],
+ ret = readl_poll_timeout_atomic(arb->pmif_base[spmidev[sid].path] +
+arb->data->regs[inf_reg->ch_sta],
data, GET_SWINF(data) == SWINF_WFVLDCLR, PMIF_DELAY_US, PMIF_TIMEOUT_US);
if (ret < 0) {
@@ -368,9 +577,9 @@ static int pmif_spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
return ret;
}
- data = pmif_readl(arb, inf_reg->rdata);
+ data = pmif_readl(arb->pmif_base[spmidev[sid].path], arb,
+inf_reg->rdata);
memcpy(buf, &data, len);
- pmif_writel(arb, 1, inf_reg->ch_rdy);
+ pmif_writel(arb->pmif_base[spmidev[sid].path], arb, 1,
+inf_reg->ch_rdy);
return 0;
}
@@ -382,7 +591,7 @@ static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
struct ch_reg *inf_reg;
int ret;
u32 data, wdata, cmd;
- unsigned long flags;
+ unsigned long flags_m;
/* Check for argument validation. */
if (unlikely(sid & ~0xf)) {
@@ -409,27 +618,27 @@ static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
/* Set the write data. */
memcpy(&wdata, buf, len);
- raw_spin_lock_irqsave(&arb->lock, flags);
+ raw_spin_lock_irqsave(&arb->lock_m, flags_m);
/* Wait for Software Interface FSM state to be IDLE. */ inf_reg = &arb->chan;
- ret = readl_poll_timeout_atomic(arb->base + arb->data->regs[inf_reg->ch_sta],
+ ret = readl_poll_timeout_atomic(arb->pmif_base[spmidev[sid].path] +
+arb->data->regs[inf_reg->ch_sta],
data, GET_SWINF(data) == SWINF_IDLE, PMIF_DELAY_US, PMIF_TIMEOUT_US);
if (ret < 0) {
/* set channel ready if the data has transferred */
- if (pmif_is_fsm_vldclr(arb))
- pmif_writel(arb, 1, inf_reg->ch_rdy);
- raw_spin_unlock_irqrestore(&arb->lock, flags);
+ if (pmif_is_fsm_vldclr(arb->pmif_base[spmidev[sid].path], arb))
+ pmif_writel(arb->pmif_base[spmidev[sid].path], arb, 1, inf_reg->ch_rdy);
+ raw_spin_unlock_irqrestore(&arb->lock_m, flags_m);
dev_err(&ctrl->dev, "failed to wait for SWINF_IDLE\n"); return ret;
}
- pmif_writel(arb, wdata, inf_reg->wdata);
+ pmif_writel(arb->pmif_base[spmidev[sid].path], arb, wdata,
+inf_reg->wdata);
/* Send the command. */
cmd = (opc << 30) | BIT(29) | (sid << 24) | ((len - 1) << 16) | addr;
- pmif_writel(arb, cmd, inf_reg->ch_send);
- raw_spin_unlock_irqrestore(&arb->lock, flags);
+ pmif_writel(arb->pmif_base[spmidev[sid].path], arb, cmd, inf_reg->ch_send);
+ raw_spin_unlock_irqrestore(&arb->lock_m, flags_m);
return 0;
}
@@ -437,15 +646,642 @@ static int pmif_spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, static const struct pmif_data mt6873_pmif_arb = {
.regs = mt6873_regs,
.spmimst_regs = mt6873_spmi_regs,
- .soc_chan = 2,
+ .soc_chan = SPMI_SOC_CHANNEL,
+ .caps = PMIF_CAPS_VER_1,
};
static const struct pmif_data mt8195_pmif_arb = {
.regs = mt8195_regs,
.spmimst_regs = mt8195_spmi_regs,
- .soc_chan = 2,
+ .soc_chan = SPMI_SOC_CHANNEL,
+ .caps = PMIF_CAPS_VER_1,
};
+static const struct pmif_data mt6xxx_pmif_arb = {
+ .regs = mt6xxx_regs,
+ .spmimst_regs = mt6853_spmi_regs,
+ .soc_chan = SPMI_SOC_CHANNEL,
+ .caps = PMIF_CAPS_VER_2,
+};
+static void mtk_spmi_readl_datas(struct pmif *arb, int id, unsigned int *spmi_nack,
+ unsigned int *spmi_nack_data, unsigned int *spmi_rcs_nack,
+ unsigned int *spmi_debug_nack, unsigned int *spmi_mst_nack) {
+ if (id < 0 || id >= PMIF_CAPS_VER_2) {
+ dev_err(&arb->spmic->dev, "%s Invalid id: %d\n", __func__, id);
+ return;
+ }
+ *spmi_nack = mtk_spmi_readl(arb->spmimst_base[id], arb, SPMI_REC0);
+ *spmi_nack_data = mtk_spmi_readl(arb->spmimst_base[id], arb, SPMI_REC1);
+ *spmi_rcs_nack = mtk_spmi_readl(arb->spmimst_base[id], arb, SPMI_REC_CMD_DEC);
+ *spmi_debug_nack = mtk_spmi_readl(arb->spmimst_base[id], arb, SPMI_DEC_DBG);
+ *spmi_mst_nack = mtk_spmi_readl(arb->spmimst_base[id], arb,
+SPMI_MST_DBG); } static irqreturn_t spmi_nack_irq_handler(int irq, void +*data) {
+ struct pmif *arb = data;
+ int sid = 0;
+ unsigned int spmi_nack = 0, spmi_p_nack = 0, spmi_nack_data = 0, spmi_p_nack_data = 0;
+ unsigned int spmi_rcs_nack = 0, spmi_debug_nack = 0, spmi_mst_nack = 0,
+ spmi_p_rcs_nack = 0, spmi_p_debug_nack = 0, spmi_p_mst_nack = 0;
+ u8 rdata = 0, rdata1 = 0;
+ unsigned short mt6316INTSTA = 0x240, hwcidaddr_mt6316 = 0x209, VIO18_SWITCH_6363 = 0x53,
+ hwcidaddr_mt6363 = 0x9;
+
+ mutex_lock(&arb->pmif_m_mutex);
+
+ mtk_spmi_readl_datas(arb, 0, &spmi_nack, &spmi_nack_data, &spmi_rcs_nack,
+ &spmi_debug_nack, &spmi_mst_nack);
+ if (!IS_ERR(arb->spmimst_base[1])) {
+ mtk_spmi_readl_datas(arb, 1, &spmi_p_nack, &spmi_p_nack_data, &spmi_p_rcs_nack,
+ &spmi_p_debug_nack, &spmi_p_mst_nack);
+ }
+ if ((spmi_nack & 0xD8) || (spmi_p_nack & 0xD8)) {
+ if (spmi_p_nack & 0xD8) {
+ for (sid = 0x8; sid >= 0x6; sid--) {
+ arb->spmic->read_cmd(arb->spmic, SPMI_CMD_EXT_READL, sid,
+ mt6316INTSTA, &rdata, 1);
+ arb->spmic->read_cmd(arb->spmic, SPMI_CMD_EXT_READL, sid,
+ hwcidaddr_mt6316, &rdata1, 1);
+ dev_notice(&arb->spmic->dev, "%s slvid 0x%x INT_RAW_STA 0x%x cid 0x%x\n",
+ __func__, sid, rdata, rdata1);
+ }
+ }
+ dev_notice(&arb->spmic->dev, "%s spmi transaction fail irq triggered", __func__);
+ dev_notice(&arb->spmic->dev, "SPMI_REC0 m/p:0x%x/0x%x SPMI_REC1 m/p 0x%x/0x%x\n",
+ spmi_nack, spmi_p_nack, spmi_nack_data, spmi_p_nack_data);
+ }
+ if ((spmi_rcs_nack & 0xC0000) || (spmi_p_rcs_nack & 0xC0000)) {
+ dev_notice(&arb->spmic->dev, "%s spmi_rcs transaction fail irq triggered SPMI_REC_CMD_DEC m/p:0x%x/0x%x\n",
+ __func__, spmi_rcs_nack, spmi_p_rcs_nack);
+ }
+ if ((spmi_debug_nack & 0xF0000) || (spmi_p_debug_nack & 0xF0000)) {
+ dev_notice(&arb->spmic->dev, "%s spmi_debug_nack transaction fail irq triggered SPMI_DEC_DBG m/p: 0x%x/0x%x\n",
+ __func__, spmi_debug_nack, spmi_p_debug_nack);
+ }
+ if ((spmi_mst_nack & 0xC0000) || (spmi_p_mst_nack & 0xC0000)) {
+ dev_notice(&arb->spmic->dev, "%s spmi_mst_nack transaction fail irq triggered SPMI_MST_DBG m/p: 0x%x/0x%x\n",
+ __func__, spmi_mst_nack, spmi_p_mst_nack);
+ }
+ if ((spmi_nack & 0x20) || (spmi_p_nack & 0x20)) {
+ dev_notice(&arb->spmic->dev, "%s spmi transaction fail (Read) irq triggered", __func__);
+ dev_notice(&arb->spmic->dev, "SPMI_REC0 m/p:0x%x/0x%x SPMI_REC1 m/p 0x%x/0x%x\n",
+ spmi_nack, spmi_p_nack, spmi_nack_data, spmi_p_nack_data);
+ }
+
+ if ((spmi_nack & 0xF8) || (spmi_rcs_nack & 0xC0000) ||
+ (spmi_debug_nack & 0xF0000) || (spmi_mst_nack & 0xC0000)) {
+ mtk_spmi_writel(arb->spmimst_base[0], arb, 0x3, SPMI_REC_CTRL);
+ } else if ((spmi_p_nack & 0xF8) || (spmi_p_rcs_nack & 0xC0000) ||
+ (spmi_p_debug_nack & 0xF0000) || (spmi_p_mst_nack & 0xC0000)) {
+ if (spmi_p_nack & 0xD8) {
+ dev_notice(&arb->spmic->dev, "%s SPMI_REC0 m/p:0x%x/0x%x, SPMI_REC1 m/p:0x%x/0x%x\n",
+ __func__, spmi_nack, spmi_p_nack, spmi_nack_data, spmi_p_nack_data);
+ dev_notice(&arb->spmic->dev, "%s SPMI_REC_CMD_DEC m/p:0x%x/0x%x\n", __func__,
+ spmi_rcs_nack, spmi_p_rcs_nack);
+ dev_notice(&arb->spmic->dev, "%s SPMI_DEC_DBG m/p:0x%x/0x%x\n", __func__,
+ spmi_debug_nack, spmi_p_debug_nack);
+ dev_notice(&arb->spmic->dev, "%s SPMI_MST_DBG m/p:0x%x/0x%x\n", __func__,
+ spmi_mst_nack, spmi_p_mst_nack);
+ arb->spmic->read_cmd(arb->spmic, SPMI_CMD_EXT_READL, 0x4,
+ hwcidaddr_mt6363, &rdata, 1);
+ arb->spmic->read_cmd(arb->spmic, SPMI_CMD_EXT_READL, 0x4,
+ VIO18_SWITCH_6363, &rdata1, 1);
+ dev_notice(&arb->spmic->dev, "%s 6363 CID/VIO18_SWITCH 0x%x/0x%x\n", __func__, rdata, rdata1);
+ }
+ mtk_spmi_writel(arb->spmimst_base[1], arb, 0x3, SPMI_REC_CTRL);
+ } else
+ dev_notice(&arb->spmic->dev, "%s IRQ not cleared\n", __func__);
+
+ mutex_unlock(&arb->pmif_m_mutex);
+
+ return IRQ_HANDLED;
+}
+static int spmi_nack_irq_register(struct platform_device *pdev,
+ struct pmif *arb, int irq)
+{
+ int ret = 0;
+ ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+ spmi_nack_irq_handler,
+ IRQF_TRIGGER_HIGH | IRQF_ONESHOT | IRQF_SHARED,
+ "spmi_nack_irq", arb);
+ if (ret < 0) {
+ dev_notice(&pdev->dev, "request %s irq fail\n",
+ "spmi_nack_irq");
+ }
+ return ret;
+}
+static void rcs_irq_lock(struct irq_data *data) {
+ struct pmif *arb = irq_data_get_irq_chip_data(data);
+ mutex_lock(&arb->rcs_m_irqlock);
+}
+static void rcs_irq_sync_unlock(struct irq_data *data) {
+ struct pmif *arb = irq_data_get_irq_chip_data(data);
+ mutex_unlock(&arb->rcs_m_irqlock);
+}
+static void rcs_irq_enable(struct irq_data *data) {
+ unsigned int hwirq = irqd_to_hwirq(data);
+ struct pmif *arb = irq_data_get_irq_chip_data(data);
+ arb->rcs_enable_hwirq[hwirq] = true;
+}
+static void rcs_irq_disable(struct irq_data *data) {
+ unsigned int hwirq = irqd_to_hwirq(data);
+ struct pmif *arb = irq_data_get_irq_chip_data(data);
+ arb->rcs_enable_hwirq[hwirq] = false;
+}
+static int rcs_irq_set_wake(struct irq_data *data, unsigned int on) {
+ struct pmif *arb = irq_data_get_irq_chip_data(data);
+ return irq_set_irq_wake(arb->rcs_irq, on); } static int
+rcs_irq_p_set_wake(struct irq_data *data, unsigned int on) {
+ struct pmif *arb = irq_data_get_irq_chip_data(data);
+ return irq_set_irq_wake(arb->rcs_irq_p, on); } static const struct
+irq_chip rcs_irq_chip = {
+ .name = "rcs_irq",
+ .irq_bus_lock = rcs_irq_lock,
+ .irq_bus_sync_unlock = rcs_irq_sync_unlock,
+ .irq_enable = rcs_irq_enable,
+ .irq_disable = rcs_irq_disable,
+ .irq_set_wake = rcs_irq_set_wake,
+};
+
+static const struct irq_chip rcs_irq_chip_p = {
+ .name = "rcs_irq_p",
+ .irq_bus_lock = rcs_irq_lock,
+ .irq_bus_sync_unlock = rcs_irq_sync_unlock,
+ .irq_enable = rcs_irq_enable,
+ .irq_disable = rcs_irq_disable,
+ .irq_set_wake = rcs_irq_p_set_wake,
+};
+static int rcs_irq_map(struct irq_domain *d, unsigned int virq,
+ irq_hw_number_t hw)
+{
+ struct pmif *arb = d->host_data;
+ irq_set_chip_data(virq, arb);
+ irq_set_chip(virq, &arb->irq_chip);
+ irq_set_nested_thread(virq, 1);
+ irq_set_parent(virq, arb->rcs_irq);
+ irq_set_noprobe(virq);
+ return 0;
+}
+static const struct irq_domain_ops rcs_irq_domain_ops = {
+ .map = rcs_irq_map,
+ .xlate = irq_domain_xlate_onetwocell,
+};
+static void pmif_lat_limit_reached_irq_handler(int irq, void *data) { } +static void pmif_acc_vio_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF ACC violation debug info\n");
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF-M\n");
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF_ACC_VIO_INFO_0 = 0x%x\n", pmif_readl(arb->pmif_base[0],
+ arb, PMIF_ACC_VIO_INFO_0));
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF_ACC_VIO_INFO_1 = 0x%x\n", pmif_readl(arb->pmif_base[0],
+ arb, PMIF_ACC_VIO_INFO_1));
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF_ACC_VIO_INFO_2 = 0x%x\n", pmif_readl(arb->pmif_base[0],
+ arb, PMIF_ACC_VIO_INFO_2));
+ if (!IS_ERR(arb->pmif_base[1])) {
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF-P\n");
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF_ACC_VIO_INFO_0 = 0x%x\n", pmif_readl(arb->pmif_base[1],
+ arb, PMIF_ACC_VIO_INFO_0));
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF_ACC_VIO_INFO_1 = 0x%x\n", pmif_readl(arb->pmif_base[1],
+ arb, PMIF_ACC_VIO_INFO_1));
+ dev_notice(&arb->spmic->dev, "[PMIF]:PMIF_ACC_VIO_INFO_2 = 0x%x\n", pmif_readl(arb->pmif_base[1],
+ arb, PMIF_ACC_VIO_INFO_2));
+ }
+}
+static void pmif_wdt_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ pmif_writel(arb->pmif_base[0], arb, 0x40000000, PMIF_IRQ_CLR_0);
+ if (!IS_ERR(arb->pmif_base[1]))
+ pmif_writel(arb->pmif_base[1], arb, 0x40000000, PMIF_IRQ_CLR_0);
+ dev_notice(&arb->spmic->dev, "[PMIF]:WDT IRQ HANDLER DONE\n"); }
+static void pmif_pmif_acc_vio_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+#if (IS_ENABLED(CONFIG_MTK_AEE_FEATURE))
+ aee_kernel_warning("PMIF", "PMIF:pmif_acc_vio"); #endif
+ dev_notice(&arb->spmic->dev, "[PMIF]:pmif_acc_vio\n"); } static void
+pmif_pmic_acc_vio_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+#if (IS_ENABLED(CONFIG_MTK_AEE_FEATURE))
+ aee_kernel_warning("PMIF", "PMIF:pmic_acc_vio"); #endif
+ dev_notice(&arb->spmic->dev, "[PMIF]:pmic_acc_vio\n"); } static void
+pmif_cmd_err_parity_err_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+#if (IS_ENABLED(CONFIG_MTK_AEE_FEATURE))
+ aee_kernel_warning("PMIF", "PMIF:parity error"); #endif
+ dev_notice(&arb->spmic->dev, "[PMIF]:parity error\n"); } static void
+pmif_hw_monitor_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+#if (IS_ENABLED(CONFIG_MTK_AEE_FEATURE))
+ aee_kernel_warning("PMIF", "PMIF:pmif_hw_monitor_match"); #endif
+ dev_notice(&arb->spmic->dev, "[PMIF]:pmif_hw_monitor_match\n");
+}
+static void pmif_swinf_acc_err_irq_handler(int irq, void *data, u32 +val) {
+ struct pmif *arb = data;
+ pmif_writel(arb->pmif_base[0], arb, val, MD_AUXADC_RDATA_0_ADDR);
+ pmif_writel(arb->pmif_base[0], arb, (u32)get_current_time_ms(), MD_AUXADC_RDATA_1_ADDR);
+ if (!IS_ERR(arb->pmif_base[1])) {
+ pmif_writel(arb->pmif_base[1], arb, val, MD_AUXADC_RDATA_0_ADDR);
+ pmif_writel(arb->pmif_base[1], arb, (u32)get_current_time_ms(), MD_AUXADC_RDATA_1_ADDR);
+ }
+ dev_notice(&arb->spmic->dev, "[PMIF]:SWINF_ACC_ERR:%d\n", val); }
+static irqreturn_t pmif_event_0_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ int irq_f = 0, irq_f_p = 0, idx = 0;
+ __pm_stay_awake(arb->pmif_m_Thread_lock);
+ mutex_lock(&arb->pmif_m_mutex);
+ irq_f = pmif_readl(arb->pmif_base[0], arb, PMIF_IRQ_FLAG_0);
+ if (!IS_ERR(arb->pmif_base[1]))
+ irq_f_p = pmif_readl(arb->pmif_base[1], arb, PMIF_IRQ_FLAG_0);
+ if ((irq_f == 0) && (irq_f_p == 0)) {
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_NONE;
+ }
+ for (idx = 0; idx < 32; idx++) {
+ if (((irq_f & (0x1 << idx)) != 0) || ((irq_f_p & (0x1 << idx)) != 0)) {
+ switch (idx) {
+ case IRQ_PMIF_ACC_VIO_V3:
+ pmif_acc_vio_irq_handler(irq, data);
+ break;
+ case IRQ_WDT_V4:
+ pmif_wdt_irq_handler(irq, data);
+ break;
+ case IRQ_ALL_PMIC_MPU_VIO_V4:
+ pmif_pmif_acc_vio_irq_handler(irq, data);
+ break;
+ default:
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] triggered\n",
+ __func__, idx);
+ break;
+ }
+ if (irq_f)
+ pmif_writel(arb->pmif_base[0], arb, irq_f, PMIF_IRQ_CLR_0);
+ else if (irq_f_p)
+ pmif_writel(arb->pmif_base[1], arb, irq_f_p, PMIF_IRQ_CLR_0);
+ else
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] is not cleared due to empty flags\n",
+ __func__, idx);
+ break;
+ }
+ }
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_HANDLED;
+}
+static irqreturn_t pmif_event_1_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ int irq_f = 0, irq_f_p = 0, idx = 0;
+ __pm_stay_awake(arb->pmif_m_Thread_lock);
+ mutex_lock(&arb->pmif_m_mutex);
+ irq_f = pmif_readl(arb->pmif_base[0], arb, PMIF_IRQ_FLAG_1);
+ if (!IS_ERR(arb->pmif_base[1]))
+ irq_f_p = pmif_readl(arb->pmif_base[1], arb, PMIF_IRQ_FLAG_1);
+ if ((irq_f == 0) && (irq_f_p == 0)) {
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_NONE;
+ }
+ for (idx = 0; idx < 32; idx++) {
+ if (((irq_f & (0x1 << idx)) != 0) || ((irq_f_p & (0x1 << idx)) != 0)) {
+ switch (idx) {
+ default:
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] triggered\n",
+ __func__, idx);
+ break;
+ }
+ if (irq_f)
+ pmif_writel(arb->pmif_base[0], arb, irq_f, PMIF_IRQ_CLR_1);
+ else if (irq_f_p)
+ pmif_writel(arb->pmif_base[1], arb, irq_f_p, PMIF_IRQ_CLR_1);
+ else
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] is not cleared due to empty flags\n",
+ __func__, idx);
+ break;
+ }
+ }
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_HANDLED;
+}
+static irqreturn_t pmif_event_2_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ int irq_f = 0, irq_f_p = 0, idx = 0;
+ __pm_stay_awake(arb->pmif_m_Thread_lock);
+ mutex_lock(&arb->pmif_m_mutex);
+ irq_f = pmif_readl(arb->pmif_base[0], arb, PMIF_IRQ_FLAG_2);
+ if (!IS_ERR(arb->pmif_base[1]))
+ irq_f_p = pmif_readl(arb->pmif_base[1], arb, PMIF_IRQ_FLAG_2);
+ if ((irq_f == 0) && (irq_f_p == 0)) {
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_NONE;
+ }
+ for (idx = 0; idx < 32; idx++) {
+ if (((irq_f & (0x1 << idx)) != 0) || ((irq_f_p & (0x1 << idx)) != 0)) {
+ switch (idx) {
+ case IRQ_PMIC_CMD_ERR_PARITY_ERR:
+ pmif_cmd_err_parity_err_irq_handler(irq, data);
+ break;
+ case IRQ_PMIF_ACC_VIO_V2:
+ pmif_pmif_acc_vio_irq_handler(irq, data);
+ break;
+ case IRQ_PMIC_ACC_VIO:
+ pmif_pmic_acc_vio_irq_handler(irq, data);
+ break;
+ default:
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] triggered\n",
+ __func__, idx);
+ break;
+ }
+ if (irq_f)
+ pmif_writel(arb->pmif_base[0], arb, irq_f, PMIF_IRQ_CLR_2);
+ else if (irq_f_p)
+ pmif_writel(arb->pmif_base[1], arb, irq_f_p, PMIF_IRQ_CLR_2);
+ else
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] is not cleared due to empty flags\n",
+ __func__, idx);
+ break;
+ }
+ }
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_HANDLED;
+}
+static irqreturn_t pmif_event_3_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ int irq_f = 0, irq_f_p = 0, idx = 0;
+ __pm_stay_awake(arb->pmif_m_Thread_lock);
+ mutex_lock(&arb->pmif_m_mutex);
+ irq_f = pmif_readl(arb->pmif_base[0], arb, PMIF_IRQ_FLAG_3);
+ if (!IS_ERR(arb->pmif_base[1]))
+ irq_f_p = pmif_readl(arb->pmif_base[1], arb, PMIF_IRQ_FLAG_3);
+ if ((irq_f == 0) && (irq_f_p == 0)) {
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_NONE;
+ }
+ for (idx = 0; idx < 32; idx++) {
+ if (((irq_f & (0x1 << idx)) != 0) || ((irq_f_p & (0x1 << idx)) != 0)) {
+ switch (idx) {
+ case IRQ_PMIF_SWINF_ACC_ERR_0:
+ case IRQ_PMIF_SWINF_ACC_ERR_0_V2:
+ pmif_swinf_acc_err_irq_handler(irq, data, 0x0);
+ break;
+ case IRQ_PMIF_SWINF_ACC_ERR_1:
+ case IRQ_PMIF_SWINF_ACC_ERR_1_V2:
+ pmif_swinf_acc_err_irq_handler(irq, data, 0x1);
+ break;
+ case IRQ_PMIF_SWINF_ACC_ERR_2:
+ case IRQ_PMIF_SWINF_ACC_ERR_2_V2:
+ pmif_swinf_acc_err_irq_handler(irq, data, 0x2);
+ break;
+ case IRQ_LAT_LIMIT_REACHED:
+ case IRQ_PMIF_SWINF_ACC_ERR_3_V2:
+ if (arb->data->caps == 1)
+ pmif_lat_limit_reached_irq_handler(irq, data);
+ else
+ pmif_swinf_acc_err_irq_handler(irq, data, 0x3);
+ break;
+ case IRQ_PMIF_SWINF_ACC_ERR_4:
+ case IRQ_PMIF_SWINF_ACC_ERR_4_V2:
+ pmif_swinf_acc_err_irq_handler(irq, data, 0x4);
+ break;
+ case IRQ_PMIF_SWINF_ACC_ERR_5:
+ case IRQ_PMIF_SWINF_ACC_ERR_5_V2:
+ pmif_swinf_acc_err_irq_handler(irq, data, 0x5);
+ break;
+ case IRQ_HW_MONITOR_V2:
+ case IRQ_HW_MONITOR_V3:
+ pmif_hw_monitor_irq_handler(irq, data);
+ break;
+ case IRQ_WDT_V2:
+ case IRQ_WDT_V3:
+ pmif_wdt_irq_handler(irq, data);
+ break;
+ case IRQ_PMIC_ACC_VIO_V2:
+ pmif_pmic_acc_vio_irq_handler(irq, data);
+ break;
+ case IRQ_ALL_PMIC_MPU_VIO_V2:
+ case IRQ_ALL_PMIC_MPU_VIO_V3:
+ pmif_pmif_acc_vio_irq_handler(irq, data);
+ break;
+ default:
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] triggered\n", __func__, idx);
+ break;
+ }
+ if (irq_f) {
+ if ((!(irq_f & (0x1 << IRQ_PMIF_SWINF_ACC_ERR_0))) &&
+ (!(irq_f & (0x1 << IRQ_PMIF_SWINF_ACC_ERR_0_V2))))
+ pmif_writel(arb->pmif_base[0], arb, irq_f, PMIF_IRQ_CLR_3);
+ } else if (irq_f_p) {
+ if ((!(irq_f_p & (0x1 << IRQ_PMIF_SWINF_ACC_ERR_0))) &&
+ (!(irq_f & (0x1 << IRQ_PMIF_SWINF_ACC_ERR_0_V2))))
+ pmif_writel(arb->pmif_base[1], arb, irq_f_p, PMIF_IRQ_CLR_3);
+ } else
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] is not cleared due to empty flags\n",
+ __func__, idx);
+ break;
+ }
+ }
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_HANDLED;
+}
+static irqreturn_t pmif_event_4_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ int irq_f = 0, irq_f_p = 0, idx = 0;
+ __pm_stay_awake(arb->pmif_m_Thread_lock);
+ mutex_lock(&arb->pmif_m_mutex);
+ irq_f = pmif_readl(arb->pmif_base[0], arb, PMIF_IRQ_FLAG_4);
+ if (!IS_ERR(arb->pmif_base[1]))
+ irq_f_p = pmif_readl(arb->pmif_base[1], arb, PMIF_IRQ_FLAG_4);
+ if ((irq_f == 0) && (irq_f_p == 0)) {
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_NONE;
+ }
+ for (idx = 0; idx < 32; idx++) {
+ if (((irq_f & (0x1 << idx)) != 0) || ((irq_f_p & (0x1 << idx)) != 0)) {
+ switch (idx) {
+ default:
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] triggered\n",
+ __func__, idx);
+ break;
+ }
+ if (irq_f)
+ pmif_writel(arb->pmif_base[0], arb, irq_f, PMIF_IRQ_CLR_4);
+ else if (irq_f_p)
+ pmif_writel(arb->pmif_base[1], arb, irq_f_p, PMIF_IRQ_CLR_4);
+ else
+ dev_notice(&arb->spmic->dev, "%s IRQ[%d] is not cleared due to empty flags\n",
+ __func__, idx);
+ break;
+ }
+ }
+ mutex_unlock(&arb->pmif_m_mutex);
+ __pm_relax(arb->pmif_m_Thread_lock);
+ return IRQ_HANDLED;
+}
+static struct pmif_irq_desc pmif_event_irq[] = {
+ PMIF_IRQDESC(event_0),
+ PMIF_IRQDESC(event_1),
+ PMIF_IRQDESC(event_2),
+ PMIF_IRQDESC(event_3),
+ PMIF_IRQDESC(event_4),
+};
+static void pmif_irq_register(struct platform_device *pdev,
+ struct pmif *arb, int irq)
+{
+ int i = 0, ret = 0;
+ u32 irq_event_en[5] = {0};
+ for (i = 0; i < ARRAY_SIZE(pmif_event_irq); i++) {
+ if (!pmif_event_irq[i].name)
+ continue;
+ ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+ pmif_event_irq[i].irq_handler,
+ IRQF_TRIGGER_HIGH | IRQF_ONESHOT | IRQF_SHARED,
+ pmif_event_irq[i].name, arb);
+ if (ret < 0) {
+ dev_notice(&pdev->dev, "request %s irq fail\n",
+ pmif_event_irq[i].name);
+ continue;
+ }
+ pmif_event_irq[i].irq = irq;
+ }
+ ret = of_property_read_u32_array(pdev->dev.of_node, "irq-event-en",
+ irq_event_en, ARRAY_SIZE(irq_event_en));
+ pmif_writel(arb->pmif_base[0], arb, irq_event_en[0] | pmif_readl(arb->pmif_base[0],
+ arb, PMIF_IRQ_EVENT_EN_0), PMIF_IRQ_EVENT_EN_0);
+ pmif_writel(arb->pmif_base[0], arb, irq_event_en[1] | pmif_readl(arb->pmif_base[0],
+ arb, PMIF_IRQ_EVENT_EN_1), PMIF_IRQ_EVENT_EN_1);
+ pmif_writel(arb->pmif_base[0], arb, irq_event_en[2] | pmif_readl(arb->pmif_base[0],
+ arb, PMIF_IRQ_EVENT_EN_2), PMIF_IRQ_EVENT_EN_2);
+ pmif_writel(arb->pmif_base[0], arb, irq_event_en[3] | pmif_readl(arb->pmif_base[0],
+ arb, PMIF_IRQ_EVENT_EN_3), PMIF_IRQ_EVENT_EN_3);
+ pmif_writel(arb->pmif_base[0], arb, irq_event_en[4] | pmif_readl(arb->pmif_base[0],
+ arb, PMIF_IRQ_EVENT_EN_4), PMIF_IRQ_EVENT_EN_4);
+ if (!IS_ERR(arb->pmif_base[1])) {
+ pmif_writel(arb->pmif_base[1], arb, irq_event_en[0] | pmif_readl(arb->pmif_base[1],
+ arb, PMIF_IRQ_EVENT_EN_0), PMIF_IRQ_EVENT_EN_0);
+ pmif_writel(arb->pmif_base[1], arb, irq_event_en[1] | pmif_readl(arb->pmif_base[1],
+ arb, PMIF_IRQ_EVENT_EN_1), PMIF_IRQ_EVENT_EN_1);
+ pmif_writel(arb->pmif_base[1], arb, irq_event_en[2] | pmif_readl(arb->pmif_base[1],
+ arb, PMIF_IRQ_EVENT_EN_2), PMIF_IRQ_EVENT_EN_2);
+ pmif_writel(arb->pmif_base[1], arb, irq_event_en[3] | pmif_readl(arb->pmif_base[1],
+ arb, PMIF_IRQ_EVENT_EN_3), PMIF_IRQ_EVENT_EN_3);
+ pmif_writel(arb->pmif_base[1], arb, irq_event_en[4] | pmif_readl(arb->pmif_base[1],
+ arb, PMIF_IRQ_EVENT_EN_4), PMIF_IRQ_EVENT_EN_4);
+ }
+}
+static irqreturn_t rcs_irq_handler(int irq, void *data) {
+ struct pmif *arb = data;
+ unsigned int slv_irq_sta, slv_irq_sta_p;
+ int i;
+
+ for (i = 0; i < SPMI_MAX_SLAVE_ID; i++) {
+ slv_irq_sta = mtk_spmi_readl(arb->spmimst_base[0], arb, SPMI_SLV_3_0_EINT + (i / 4));
+ slv_irq_sta = (slv_irq_sta >> ((i % 4) * 8)) & 0xFF;
+ if (!IS_ERR(arb->spmimst_base[1])) {
+ slv_irq_sta_p = mtk_spmi_readl(arb->spmimst_base[1], arb, SPMI_SLV_3_0_EINT + (i / 4));
+ slv_irq_sta_p = (slv_irq_sta_p >> ((i % 4) * 8)) & 0xFF;
+ }
+ if (slv_irq_sta) {
+ mtk_spmi_writel(arb->spmimst_base[0], arb, (0xFF << ((i % 4) * 8)),
+ SPMI_SLV_3_0_EINT + (i / 4));
+ if (arb->rcs_enable_hwirq[i] && slv_irq_sta) {
+ dev_info(&arb->spmic->dev,
+ "hwirq=%d, sta=0x%x\n", i, slv_irq_sta);
+ handle_nested_irq(irq_find_mapping(arb->domain, i));
+ }
+ } else {
+ if (!IS_ERR(arb->spmimst_base[1])) {
+ mtk_spmi_writel(arb->spmimst_base[1], arb, (0xFF << ((i % 4) * 8)),
+ SPMI_SLV_3_0_EINT + (i / 4));
+ if (arb->rcs_enable_hwirq[i] && slv_irq_sta_p) {
+ dev_info(&arb->spmic->dev,
+ "hwirq=%d, sta=0x%x\n", i, slv_irq_sta_p);
+ handle_nested_irq(irq_find_mapping(arb->domain, i));
+ }
+ }
+ }
+ }
+ return IRQ_HANDLED;
+}
+static int rcs_irq_register(struct platform_device *pdev,
+ struct pmif *arb, int irq)
+{
+ int i, ret = 0;
+ mutex_init(&arb->rcs_m_irqlock);
+ mutex_init(&arb->rcs_p_irqlock);
+ arb->rcs_enable_hwirq = devm_kcalloc(&pdev->dev, SPMI_MAX_SLAVE_ID,
+ sizeof(*arb->rcs_enable_hwirq),
+ GFP_KERNEL);
+ if (!arb->rcs_enable_hwirq)
+ return -ENOMEM;
+ if (arb->rcs_irq == irq)
+ arb->irq_chip = rcs_irq_chip;
+ else if (arb->rcs_irq_p == irq)
+ arb->irq_chip_p = rcs_irq_chip_p;
+ else
+ dev_notice(&pdev->dev, "no rcs irq %d registered\n", irq);
+ arb->domain = irq_domain_add_linear(pdev->dev.of_node,
+ SPMI_MAX_SLAVE_ID,
+ &rcs_irq_domain_ops, arb);
+ if (!arb->domain) {
+ dev_notice(&pdev->dev, "Failed to create IRQ domain\n");
+ return -ENODEV;
+ }
+ for (i = 0; i < SPMI_MAX_SLAVE_ID; i++) {
+ mtk_spmi_writel(arb->spmimst_base[0], arb, (0xFF << ((i % 4) * 8)),
+ SPMI_SLV_3_0_EINT + (i / 4));
+ if (!IS_ERR(arb->spmimst_base[1])) {
+ mtk_spmi_writel(arb->spmimst_base[1], arb, (0xFF << ((i % 4) * 8)),
+ SPMI_SLV_3_0_EINT + (i / 4));
+ }
+ }
+ ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+ rcs_irq_handler, IRQF_ONESHOT,
+ rcs_irq_chip.name, arb);
+ if (ret < 0) {
+ dev_notice(&pdev->dev, "Failed to request IRQ=%d, ret = %d\n",
+ irq, ret);
+ return ret;
+ }
+ enable_irq_wake(irq);
+ return ret;
+}
static int mtk_spmi_probe(struct platform_device *pdev) {
struct pmif *arb;
@@ -457,41 +1293,50 @@ static int mtk_spmi_probe(struct platform_device *pdev)
if (IS_ERR(ctrl))
return PTR_ERR(ctrl);
+ ctrl->cmd = pmif_arb_cmd;
+ ctrl->read_cmd = pmif_spmi_read_cmd;
+ ctrl->write_cmd = pmif_spmi_write_cmd;
arb = spmi_controller_get_drvdata(ctrl);
+ arb->spmic = ctrl;
arb->data = device_get_match_data(&pdev->dev); if (!arb->data) {
dev_err(&pdev->dev, "Cannot get drv_data\n"); return -EINVAL;
}
- arb->base = devm_platform_ioremap_resource_byname(pdev, "pmif");
- if (IS_ERR(arb->base))
- return PTR_ERR(arb->base);
-
- arb->spmimst_base = devm_platform_ioremap_resource_byname(pdev, "spmimst");
- if (IS_ERR(arb->spmimst_base))
- return PTR_ERR(arb->spmimst_base);
-
- arb->nclks = ARRAY_SIZE(pmif_clock_names);
- for (i = 0; i < arb->nclks; i++)
- arb->clks[i].id = pmif_clock_names[i];
-
- err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks);
- if (err) {
- dev_err(&pdev->dev, "Failed to get clocks: %d\n", err);
- return err;
- }
-
- err = clk_bulk_prepare_enable(arb->nclks, arb->clks);
- if (err) {
- dev_err(&pdev->dev, "Failed to enable clocks: %d\n", err);
- goto err_put_clks;
+ arb->pmif_base[0] = devm_platform_ioremap_resource_byname(pdev, "pmif");
+ if (IS_ERR(arb->pmif_base[0]))
+ return PTR_ERR(arb->pmif_base[0]);
+
+ arb->spmimst_base[0] = devm_platform_ioremap_resource_byname(pdev, "spmimst");
+ if (IS_ERR(arb->spmimst_base[0]))
+ return PTR_ERR(arb->spmimst_base[0]);
+
+ arb->pmif_base[1] = devm_platform_ioremap_resource_byname(pdev, "pmif-p");
+ if (IS_ERR(arb->pmif_base[1]))
+ dev_notice(&pdev->dev, "[PMIF]:no pmif-p found\n");
+ arb->spmimst_base[1] = devm_platform_ioremap_resource_byname(pdev, "spmimst-p");
+ if (IS_ERR(arb->spmimst_base[1]))
+ dev_notice(&pdev->dev, "[PMIF]:no spmimst-p found\n");
+ if (arb->data->caps == 1) {
+
+ arb->nclks = ARRAY_SIZE(pmif_clock_names);
+ for (i = 0; i < arb->nclks; i++)
+ arb->clks[i].id = pmif_clock_names[i];
+
+ err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks);
+ if (err) {
+ dev_err(&pdev->dev, "Failed to get clocks: %d\n", err);
+ return err;
+ }
+
+ err = clk_bulk_prepare_enable(arb->nclks, arb->clks);
+ if (err) {
+ dev_err(&pdev->dev, "Failed to enable clocks: %d\n", err);
+ goto err_put_clks;
+ }
}
- ctrl->cmd = pmif_arb_cmd;
- ctrl->read_cmd = pmif_spmi_read_cmd;
- ctrl->write_cmd = pmif_spmi_write_cmd;
-
chan_offset = PMIF_CHAN_OFFSET * arb->data->soc_chan;
arb->chan.ch_sta = PMIF_SWINF_0_STA + chan_offset;
arb->chan.wdata = PMIF_SWINF_0_WDATA_31_0 + chan_offset; @@ -499,7 +1344,71 @@ static int mtk_spmi_probe(struct platform_device *pdev) arb->chan.ch_send = PMIF_SWINF_0_ACC + chan_offset;
arb->chan.ch_rdy = PMIF_SWINF_0_VLD_CLR + chan_offset;
- raw_spin_lock_init(&arb->lock);
+ raw_spin_lock_init(&arb->lock_m);
+ raw_spin_lock_init(&arb->lock_p);
+ arb->pmif_m_Thread_lock =
+ wakeup_source_register(NULL, "pmif_m wakelock");
+ arb->pmif_p_Thread_lock =
+ wakeup_source_register(NULL, "pmif_p wakelock");
+ mutex_init(&arb->pmif_m_mutex);
+ mutex_init(&arb->pmif_p_mutex);
+ if (arb->data->caps == 2) {
+ arb->irq = platform_get_irq_byname(pdev, "pmif_irq");
+ if (arb->irq < 0) {
+ dev_notice(&pdev->dev,
+ "Failed to get pmif_irq, ret = %d\n", arb->irq);
+ }
+ pmif_irq_register(pdev, arb, arb->irq);
+ arb->irq_p = platform_get_irq_byname(pdev, "pmif_p_irq");
+ if (arb->irq_p < 0) {
+ dev_notice(&pdev->dev,
+ "Failed to get pmif_p_irq, ret = %d\n", arb->irq_p);
+ }
+ pmif_irq_register(pdev, arb, arb->irq_p);
+ arb->rcs_irq = platform_get_irq_byname(pdev, "rcs_irq");
+ if (arb->rcs_irq < 0) {
+ dev_notice(&pdev->dev,
+ "Failed to get rcs_irq, ret = %d\n", arb->rcs_irq);
+ } else {
+ err = rcs_irq_register(pdev, arb, arb->rcs_irq);
+ if (err)
+ dev_notice(&pdev->dev,
+ "Failed to register rcs_irq, ret = %d\n", arb->rcs_irq);
+ }
+ arb->rcs_irq_p = platform_get_irq_byname(pdev, "rcs_irq_p");
+ if (arb->rcs_irq_p < 0) {
+ dev_notice(&pdev->dev,
+ "Failed to get rcs_irq_p, ret = %d\n", arb->rcs_irq_p);
+ } else {
+ err = rcs_irq_register(pdev, arb, arb->rcs_irq_p);
+ if (err)
+ dev_notice(&pdev->dev,
+ "Failed to register rcs_irq_p, ret = %d\n", arb->rcs_irq_p);
+ }
+ arb->spmi_nack_irq = platform_get_irq_byname(pdev, "spmi_nack_irq");
+ if (arb->spmi_nack_irq < 0) {
+ dev_notice(&pdev->dev,
+ "Failed to get spmi_nack_irq, ret = %d\n", arb->spmi_nack_irq);
+ } else {
+ err = spmi_nack_irq_register(pdev, arb, arb->spmi_nack_irq);
+ if (err)
+ dev_notice(&pdev->dev,
+ "Failed to register spmi_nack_irq, ret = %d\n",
+ arb->spmi_nack_irq);
+ }
+ arb->spmi_p_nack_irq = platform_get_irq_byname(pdev, "spmi_p_nack_irq");
+ if (arb->spmi_p_nack_irq < 0) {
+ dev_notice(&pdev->dev,
+ "Failed to get spmi_p_nack_irq, ret = %d\n", arb->spmi_p_nack_irq);
+ } else {
+ err = spmi_nack_irq_register(pdev, arb, arb->spmi_p_nack_irq);
+ if (err)
+ dev_notice(&pdev->dev,
+ "Failed to register spmi_p_nack_irq, ret = %d\n",
+ arb->spmi_p_nack_irq);
+ }
+ }
+ spmi_dev_parse(pdev);
platform_set_drvdata(pdev, ctrl);
@@ -533,6 +1442,9 @@ static const struct of_device_id mtk_spmi_match_table[] = {
}, {
.compatible = "mediatek,mt8195-spmi",
.data = &mt8195_pmif_arb,
+ }, {
+ .compatible = "mediatek,mt8196-spmi",
+ .data = &mt6xxx_pmif_arb,
}, {
/* sentinel */
},
--
2.46.0
PATCH 5/5 dt-bindings: pmic: mediatek: Add pmic documents
In reply to Lu.TangAdd new pmic mfd and adc documents for mt8196
--- .../iio/adc/mediatek,spmi-pmic-auxadc.yaml | 31 ++++ .../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6685.yaml | 50 +++++ .../bindings/mfd/mediatek,spmi-pmic.yaml | 173 ++++++++++++++++++ .../pinctrl/mediatek,mt65xx-pinctrl.yaml | 1 + 5 files changed, 256 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml new file +31 -0
@@ -0,0 +1,31 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/mediatek,spmi-pmic-auxadc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek SPMI PMIC AUXADC + +maintainers: + - Lu Tang <[email protected]> + +description: + The Auxiliary Analog/Digital Converter (AUXADC) is an ADC found + in some MediaTek PMICs, performing various PMIC related measurements + such as battery and PMIC internal voltage regulators temperatures, + other than voltages for various PMIC internal components. + +properties: + compatible: + enum: + - mediatek,mt6363-auxadc + - mediatek,mt6373-auxadc + + "#io-channel-cells": + const: 1 + +required: + - compatible + - "#io-channel-cells" + +additionalProperties: false
Documentation/devicetree/bindings/input/mediatek,pmic-keys.yaml +1 -0
@@ -31,6 +31,7 @@ properties: - mediatek,mt6358-keys - mediatek,mt6359-keys - mediatek,mt6397-keys + - mediatek,mt6363-keys power-off-time-sec: true
Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml new file +50 -0
50 lines not on this page · raw message
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +173 -0
173 lines not on this page · raw message
Documentation/devicetree/bindings/pinctrl/mediatek,mt65xx-pinctrl.yaml +1 -0
@@ -17,6 +17,7 @@ properties: enum: - mediatek,mt2701-pinctrl - mediatek,mt2712-pinctrl + - mediatek,mt6363-pinctrl - mediatek,mt6397-pinctrl - mediatek,mt7623-pinctrl - mediatek,mt8127-pinctrl
Signature · 1 line
2.46.0
Rob Herring (Arm)
maintainerRe: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
Quoted 14 lines · Lu.Tang
Add new pmic mfd and adc documents for mt8196
Signed-off-by Lu.Tang <[email protected]>--- .../iio/adc/mediatek,spmi-pmic-auxadc.yaml | 31 ++++ .../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6685.yaml | 50 +++++ .../bindings/mfd/mediatek,spmi-pmic.yaml | 173 ++++++++++++++++++ .../pinctrl/mediatek,mt65xx-pinctrl.yaml | 1 + 5 files changed, 256 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dts:25.17-31: Warning (reg_format): /example-0/spmi/mfd@9:reg: property has invalid length (8 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dtb: Warning (pci_device_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dtb: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dtb: Warning (simple_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dtb: Warning (i2c_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dtb: Warning (spi_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dts:23.19-28.15: Warning (avoid_default_addr_size): /example-0/spmi/mfd@9: Relying on default #address-cells value Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dts:23.19-28.15: Warning (avoid_default_addr_size): /example-0/spmi/mfd@9: Relying on default #size-cells value Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dtb: Warning (unique_unit_address_if_enabled): Failed prerequisite 'avoid_default_addr_size' /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/mediatek,mt6685.example.dtb: mfd@9: '#address-cells', '#size-cells', 'reg' do not match any of the regexes: 'pinctrl-[0-9]+'
from schema $id: http://devicetree.org/schemas/mfd/mediatek,mt6685.yaml#
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dts:31.17-31: Warning (reg_format): /example-0/spmi/pmic@4:reg: property has invalid length (8 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dtb: Warning (pci_device_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dtb: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dtb: Warning (simple_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dtb: Warning (i2c_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dtb: Warning (spi_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dts:29.31-109.15: Warning (avoid_default_addr_size): /example-0/spmi/pmic@4: Relying on default #address-cells value Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dts:29.31-109.15: Warning (avoid_default_addr_size): /example-0/spmi/pmic@4: Relying on default #size-cells value Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dtb: Warning (unique_unit_address_if_enabled): Failed prerequisite 'avoid_default_addr_size' /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.example.dtb: pmic@4: '#address-cells', 'reg' do not match any of the regexes: 'pinctrl-[0-9]+'
from schema $id: http://devicetree.org/schemas/mfd/mediatek,spmi-pmic.yaml#
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
In reply to Lu.TangQuoted 42 lines · Lu.Tang
Add new pmic mfd and adc documents for mt8196
Signed-off-by Lu.Tang <[email protected]>--- .../iio/adc/mediatek,spmi-pmic-auxadc.yaml | 31 ++++ .../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6685.yaml | 50 +++++ .../bindings/mfd/mediatek,spmi-pmic.yaml | 173 ++++++++++++++++++ .../pinctrl/mediatek,mt65xx-pinctrl.yaml | 1 + 5 files changed, 256 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yamlDocumentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml new file +21
-0@@ -0,0 +1,31 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/mediatek,spmi-pmic-auxadc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek SPMI PMIC AUXADC + +maintainers: + - Lu Tang <[email protected]> + +description: + The Auxiliary Analog/Digital Converter (AUXADC) is an ADC found + in some MediaTek PMICs, performing various PMIC related measurements + such as battery and PMIC internal voltage regulators temperatures, + other than voltages for various PMIC internal components. + +properties: + compatible: + enum: + - mediatek,mt6363-auxadc
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml line 31
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml new file +10
-0+ - mediatek,mt6373-auxadc + + "#io-channel-cells": + const: 1 + +required: + - compatible + - "#io-channel-cells" + +additionalProperties: false
This is simply a sub-function of the PMIC, and is really not tied to whatever interface the PMIC uses. Please integrate this into the existing binding:
Documentation/devicetree/bindings/iio/adc/mediatek,mt6359-auxadc.yaml
Quoted 91 lines
Documentation/devicetree/bindings/input/mediatek,pmic-keys.yaml +1
-0@@ -31,6 +31,7 @@ properties: - mediatek,mt6358-keys - mediatek,mt6359-keys - mediatek,mt6397-keys + - mediatek,mt6363-keys power-off-time-sec: trueDocumentation/devicetree/bindings/mfd/mediatek,mt6685.yaml new file +50
-0@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/mediatek,mt6685.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek MT6685 Clock IC + +maintainers: + - Lu Tang <[email protected]> + +description: | + MT6685 is a clock IC. + Please see the sub-modules below for supported features. + + MT6685 is a multifunction device with the following sub modules: + - RTC + - Clock + +properties: + compatible: + const: mediatek,mt6685 + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 2 + +required: + - compatible + +additionalProperties: false + +examples: + - | + #include <dt-bindings/spmi/spmi.h> + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + + spmi { + mfd@9 { + compatible = "mediatek,mt6685"; + reg = <0x9 SPMI_USID>; + #address-cells = <1>; + #size-cells = <0>; + }; + };Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +17
-0@@ -0,0 +1,173 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/mediatek,spmi-pmic.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek SPMI PMICs multi-function device + +maintainers: + - Lu Tang <[email protected]> + +description: | + Some Mediatek PMICs are interfaced to the chip via the SPMI (System Power + Management Interface) bus. + + The Mediatek SPMI series includes the MT6363, MT6373, MT6316 and other + PMICs.Please see the sub-modules below for supported features.
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml line 25
Quoted 10 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +8
-0+ + MT6363/MT6373 is a multifunction device with the following sub modules: + - Regulators + - ADC + - GPIO + - Keys + MT6316 is a multifunction device with the following sub modules: + - Regulators
Then it is not multifunctional. Please move this to the MT6315 binding:
Documentation/devicetree/bindings/regulator/mt6315-regulator.yaml
Also, you have not covered regulator bindings in this series.
ChenYu
Quoted 163 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +147
-0+properties: + compatible: + oneOf: + - enum: + - mediatek,mt6363 + - mediatek,mt6373 + - mediatek,mt6316 + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 2 + + regulators: + type: object + description: + List of child nodes that specify the regulators. + additionalProperties: true + + properties: + compatible: + oneOf: + - enum: + - mediatek,mt6363-regulator + - mediatek,mt6373-regulator + - mediatek,mt6316-regulator + + required: + - compatible + + adc: + type: object + $ref: /schemas/iio/adc/mediatek,spmi-pmic-auxadc.yaml# + unevaluatedProperties: false + + keys: + type: object + $ref: /schemas/input/mediatek,pmic-keys.yaml + unevaluatedProperties: false + description: + Power and Home keys. + + pinctrl: + type: object + $ref: /schemas/pinctrl/mediatek,mt65xx-pinctrl.yaml + unevaluatedProperties: false + description: + Pin controller + +required: + - compatible + - regulators + +additionalProperties: false + +examples: + - | + #include <dt-bindings/spmi/spmi.h> + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + + spmi { + main_pmic: pmic@4 { + compatible = "mediatek,mt6363"; + reg = <0x4 SPMI_USID>; + interrupts = <0x4 IRQ_TYPE_NONE>; + #address-cells = <0>; + interrupt-controller; + #interrupt-cells = <2>; + + mt6363keys: keys { + compatible = "mediatek,mt6363-keys"; + mediatek,long-press-mode = <1>; + power-off-time-sec = <0>; + + power { + linux,keycodes = <116>; + wakeup-source; + }; + + home { + linux,keycodes = <115>; + }; + }; + + mt6363_pio: pinctrl { + compatible = "mediatek,mt6363-pinctrl"; + gpio-controller; + #gpio-cells = <2>; + }; + + mt6363regulator: regulators { + compatible = "mediatek,mt6363-regulator"; + + mt6363_vs2: vs2 { + regulator-name = "mt6363_vs2"; + regulator-allowed-modes = <0 1 2>; + regulator-always-on; + regulator-allow-set-load; + }; + + mt6363_vbuck1: vbuck1 { + regulator-name = "mt6363_vbuck1"; + regulator-allowed-modes = <0 1 2>; + }; + + mt6363_vbuck2: vbuck2 { + regulator-name = "mt6363_vbuck2"; + regulator-allowed-modes = <0 1 2>; + }; + + mt6363_vbuck3: vbuck3 { + regulator-name = "mt6363_vbuck3"; + regulator-allowed-modes = <0 1 2>; + }; + + mt6363_vbuck4: vbuck4 { + regulator-name = "mt6363_vbuck4"; + regulator-allowed-modes = <0 1 2>; + }; + + mt6363_vbuck5: vbuck5 { + regulator-name = "mt6363_vbuck5"; + regulator-allowed-modes = <0 1 2>; + }; + + mt6363_vbuck6: vbuck6 { + regulator-name = "mt6363_vbuck6"; + regulator-allowed-modes = <0 1 2>; + }; + + mt6363_vbuck7: vbuck7 { + regulator-name = "mt6363_vbuck7"; + regulator-allowed-modes = <0 1 2>; + }; + + // ... + + mt6363_isink_load: isink-load { + regulator-name = "mt6363_isink_load"; + }; + }; + }; + };Documentation/devicetree/bindings/pinctrl/mediatek,mt65xx-pinctrl.yaml +1
-1@@ -17,6 +17,7 @@ properties: enum: - mediatek,mt2701-pinctrl - mediatek,mt2712-pinctrl + - mediatek,mt6363-pinctrl - mediatek,mt6397-pinctrl - mediatek,mt7623-pinctrl - mediatek,mt8127-pinctrl --2.46.0
回复: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
In reply to Lu.TangUpdate email
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:33
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Project_Global_Chrome_Upstream_Group <[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
Add new pmic mfd and adc documents for mt8196
--- .../iio/adc/mediatek,spmi-pmic-auxadc.yaml | 31 ++++ .../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6685.yaml | 50 +++++ .../bindings/mfd/mediatek,spmi-pmic.yaml | 173 ++++++++++++++++++ .../pinctrl/mediatek,mt65xx-pinctrl.yaml | 1 + 5 files changed, 256 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxad new file +0 -0
+++ c.yaml
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) %YAML 1.2
+---
+$id:
+http://devicetree.org/schemas/iio/adc/mediatek,spmi-pmic-auxadc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek SPMI PMIC AUXADC
+
+maintainers:
+ - Lu Tang <[email protected]>
+
+description:
+ The Auxiliary Analog/Digital Converter (AUXADC) is an ADC found + in some MediaTek PMICs, performing various PMIC related measurements + such as battery and PMIC internal voltage regulators temperatures, + other than voltages for various PMIC internal components.
+
+properties:
+ compatible:
+ enum:
+ - mediatek,mt6363-auxadc
+ - mediatek,mt6373-auxadc
+
+ "#io-channel-cells":
+ const: 1
+
+required:
+ - compatible
+ - "#io-channel-cells"
+
+additionalProperties: false
Documentation/devicetree/bindings/input/mediatek,pmic-keys.yaml +1 -0
@@ -31,6 +31,7 @@ properties: - mediatek,mt6358-keys - mediatek,mt6359-keys - mediatek,mt6397-keys + - mediatek,mt6363-keys power-off-time-sec: true
Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml new file +49 -0
49 lines not on this page · raw message
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +173 -0
173 lines not on this page · raw message
Documentation/devicetree/bindings/pinctrl/mediatek,mt65xx-pinctrl. renamed from Documentation/devicetree/bindings/pinctrl/mediatek,mt65xx-pinctrl.yaml +0 -0
+++ yaml
@@ -17,6 +17,7 @@ properties:
enum:
- mediatek,mt2701-pinctrl
- mediatek,mt2712-pinctrl
+ - mediatek,mt6363-pinctrl
- mediatek,mt6397-pinctrl
- mediatek,mt7623-pinctrl
- mediatek,mt8127-pinctrl
--
2.46.0
Re: 回复: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
Quoted 8 lines · Lu Tang (汤璐)
Update email
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:33
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];Project_Global_Chrome_Upstream_Group<[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
The amount of errors shown by checkpatch on this is just shocking.
Best regards,
Krzysztof
Re: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
In reply to Lu.TangOn 14/03/2025 08:32, Lu.Tang wrote:
Please use subject prefixes matching the subsystem. You can get them for example with git log --oneline -- DIRECTORY_OR_FILE on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters
There is no subsystem "pmic".
Quoted 3 lines
Add new pmic mfd and adc documents for mt8196
Signed-off-by Lu.Tang <[email protected]>
Are you sure Latin transcription of your name includes '.' or you just copy-paste email address?
...
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml line 22
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml new file +13
-0+ - Lu Tang <[email protected]> + +description: + The Auxiliary Analog/Digital Converter (AUXADC) is an ADC found + in some MediaTek PMICs, performing various PMIC related measurements + such as battery and PMIC internal voltage regulators temperatures, + other than voltages for various PMIC internal components. + +properties: + compatible: + enum: + - mediatek,mt6363-auxadc + - mediatek,mt6373-auxadc
Just fold the device to the parent node.
..
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml
Quoted 5 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +0
-0
Filename matching one of the compatibles, e.g. the oldest one.
Quoted 16 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +15
-0@@ -0,0 +1,173 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/mediatek,spmi-pmic.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek SPMI PMICs multi-function device + +maintainers: + - Lu Tang <[email protected]> + +description: | + Some Mediatek PMICs are interfaced to the chip via the SPMI (System Power + Management Interface) bus. +
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml line 25
Quoted 10 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +10
-0+ The Mediatek SPMI series includes the MT6363, MT6373, MT6316 and other + PMICs.Please see the sub-modules below for supported features. + + MT6363/MT6373 is a multifunction device with the following sub modules: + - Regulators + - ADC + - GPIO + - Keys + MT6316 is a multifunction device with the following sub modules: + - Regulators
I don't get why they are in the same schema. It would result in unnecessary big if:then with half of children not applicable for other variants.
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml line 33
Quoted 8 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +8
-0+ +properties: + compatible: + oneOf: + - enum: + - mediatek,mt6363 + - mediatek,mt6373 + - mediatek,mt6316
Sort these with alphanumeric order.
Best regards,
Krzysztof
AngeloGioacchino Del Regno
maintainerRe: [PATCH 5/5] dt-bindings: pmic: mediatek: Add pmic documents
Il 14/03/25 11:32, Krzysztof Kozlowski ha scritto:
Quoted 42 lines · Lu.Tang
Please use subject prefixes matching the subsystem. You can get them for example with
git log --oneline -- DIRECTORY_OR_FILEon the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submittersThere is no subsystem "pmic".
Quoted 3 lines
Add new pmic mfd and adc documents for mt8196
Signed-off-by Lu.Tang <[email protected]>Are you sure Latin transcription of your name includes '.' or you just copy-paste email address?
...
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml line 22
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml new file +13
-0+ - Lu Tang <[email protected]> + +description: + The Auxiliary Analog/Digital Converter (AUXADC) is an ADC found + in some MediaTek PMICs, performing various PMIC related measurements + such as battery and PMIC internal voltage regulators temperatures, + other than voltages for various PMIC internal components. + +properties: + compatible: + enum: + - mediatek,mt6363-auxadc + - mediatek,mt6373-auxadcJust fold the device to the parent node.
..
Quoted 8 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml
Quoted 5 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +0
-0Filename matching one of the compatibles, e.g. the oldest one.
Yeah but besides that I don't see valid reasons why this should be a different binding (and also why this should use a different driver, fwiw) - when it can most probably just extend the current PMIC MFD driver... and the same goes for the PMIC AUXADC: there's a mt6359-auxadc binding and driver that can be extended to 6363 and 6373 rather easily.
There's nothing "really special" about those.....
Cheers
Quoted 43 lines
Quoted 16 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +15
-0@@ -0,0 +1,173 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/mediatek,spmi-pmic.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek SPMI PMICs multi-function device + +maintainers: + - Lu Tang <[email protected]> + +description: | + Some Mediatek PMICs are interfaced to the chip via the SPMI (System Power + Management Interface) bus. +Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml line 25
Quoted 10 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +10
-0+ The Mediatek SPMI series includes the MT6363, MT6373, MT6316 and other + PMICs.Please see the sub-modules below for supported features. + + MT6363/MT6373 is a multifunction device with the following sub modules: + - Regulators + - ADC + - GPIO + - Keys + MT6316 is a multifunction device with the following sub modules: + - RegulatorsI don't get why they are in the same schema. It would result in unnecessary big if:then with half of children not applicable for other variants.
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml line 33
Quoted 8 lines
Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml new file +8
-0+ +properties: + compatible: + oneOf: + - enum: + - mediatek,mt6363 + - mediatek,mt6373 + - mediatek,mt6316Sort these with alphanumeric order.
Best regards,
Krzysztof
Quoted 8 lines · Lu.Tang
This series is based on linux-next.
Changes in v0:
- Modify SPMI driver for mt8196
- Add SPMI PMIC mfd driver
- Add PMIC regulator driver for mt8196
Quoted 8 lines
*** BLURB HERE ***
Lu.Tang (5):
pmic: mediatek: Add pmic auxadc driver
pmic: mediatek: Add pmic regulator driver
pmic: mediatek: Add spmi pmic mfd driver
spmi: mediatek: modify spmi dirver for mt8196
dt-bindings: pmic: mediatek: Add pmic documents
You are adding three PMICs at the same time. Please separate each patch in this series so that it is one patch per type per PMIC.
ChenYu
Quoted 47 lines
.../iio/adc/mediatek,spmi-pmic-auxadc.yaml | 31 + .../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6685.yaml | 50 + .../bindings/mfd/mediatek,spmi-pmic.yaml | 173 +++ .../pinctrl/mediatek,mt65xx-pinctrl.yaml | 1 + drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mtk-spmi-pmic-adc.c | 576 +++++++++ drivers/mfd/Kconfig | 26 + drivers/mfd/Makefile | 2 + drivers/mfd/mt6685-core.c | 83 ++ drivers/mfd/mtk-spmi-pmic.c | 518 ++++++++ drivers/regulator/Kconfig | 34 + drivers/regulator/Makefile | 3 + drivers/regulator/mt6316-regulator.c | 381 ++++++ drivers/regulator/mt6363-regulator.c | 1106 +++++++++++++++++ drivers/regulator/mt6373-regulator.c | 826 ++++++++++++ drivers/spmi/spmi-mtk-pmif.c | 1040 +++++++++++++++- include/linux/mfd/mt6363/core.h | 134 ++ include/linux/mfd/mt6363/registers.h | 168 +++ include/linux/mfd/mt6373/core.h | 94 ++ include/linux/mfd/mt6373/registers.h | 53 + include/linux/regulator/mt6316-regulator.h | 48 + include/linux/regulator/mt6363-regulator.h | 424 +++++++ include/linux/regulator/mt6373-regulator.h | 318 +++++ 25 files changed, 6037 insertions(+), 64 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml create mode 100644 drivers/iio/adc/mtk-spmi-pmic-adc.c create mode 100644 drivers/mfd/mt6685-core.c create mode 100644 drivers/mfd/mtk-spmi-pmic.c create mode 100644 drivers/regulator/mt6316-regulator.c create mode 100644 drivers/regulator/mt6363-regulator.c create mode 100644 drivers/regulator/mt6373-regulator.c create mode 100644 include/linux/mfd/mt6363/core.h create mode 100644 include/linux/mfd/mt6363/registers.h create mode 100644 include/linux/mfd/mt6373/core.h create mode 100644 include/linux/mfd/mt6373/registers.h create mode 100644 include/linux/regulator/mt6316-regulator.h create mode 100644 include/linux/regulator/mt6363-regulator.h create mode 100644 include/linux/regulator/mt6373-regulator.h--
2.46.0
Update email address
-----邮件原件-----
发件人: Lu.Tang <[email protected]>
发送时间: 2025年3月14日 15:32
收件人: Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Matthias Brugger <[email protected]>; AngeloGioacchino Del Regno <[email protected]>; Sean Wang <[email protected]>; Linus Walleij <[email protected]>; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Stephen Boyd <[email protected]>; Chen Zhong (钟辰) <[email protected]>; Sen Chu <[email protected]> 抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Project_Global_Chrome_Upstream_Group <[email protected]>; Lu Tang (汤璐) <[email protected]>
主题: [PATCH 0/5] Add PMIC and SPMI driver for mt8196
This series is based on linux-next.
Changes in v0:
- Modify SPMI driver for mt8196
- Add SPMI PMIC mfd driver
- Add PMIC regulator driver for mt8196
*** BLURB HERE ***
Lu.Tang (5):
pmic: mediatek: Add pmic auxadc driver
pmic: mediatek: Add pmic regulator driver
pmic: mediatek: Add spmi pmic mfd driver
spmi: mediatek: modify spmi dirver for mt8196
dt-bindings: pmic: mediatek: Add pmic documents
.../iio/adc/mediatek,spmi-pmic-auxadc.yaml | 31 + .../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6685.yaml | 50 + .../bindings/mfd/mediatek,spmi-pmic.yaml | 173 +++ .../pinctrl/mediatek,mt65xx-pinctrl.yaml | 1 + drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mtk-spmi-pmic-adc.c | 576 +++++++++ drivers/mfd/Kconfig | 26 + drivers/mfd/Makefile | 2 + drivers/mfd/mt6685-core.c | 83 ++ drivers/mfd/mtk-spmi-pmic.c | 518 ++++++++ drivers/regulator/Kconfig | 34 + drivers/regulator/Makefile | 3 + drivers/regulator/mt6316-regulator.c | 381 ++++++ drivers/regulator/mt6363-regulator.c | 1106 +++++++++++++++++ drivers/regulator/mt6373-regulator.c | 826 ++++++++++++ drivers/spmi/spmi-mtk-pmif.c | 1040 +++++++++++++++- include/linux/mfd/mt6363/core.h | 134 ++ include/linux/mfd/mt6363/registers.h | 168 +++ include/linux/mfd/mt6373/core.h | 94 ++ include/linux/mfd/mt6373/registers.h | 53 + include/linux/regulator/mt6316-regulator.h | 48 + include/linux/regulator/mt6363-regulator.h | 424 +++++++ include/linux/regulator/mt6373-regulator.h | 318 +++++ 25 files changed, 6037 insertions(+), 64 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/adc/mediatek,spmi-pmic-auxadc.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6685.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,spmi-pmic.yaml create mode 100644 drivers/iio/adc/mtk-spmi-pmic-adc.c create mode 100644 drivers/mfd/mt6685-core.c create mode 100644 drivers/mfd/mtk-spmi-pmic.c create mode 100644 drivers/regulator/mt6316-regulator.c create mode 100644 drivers/regulator/mt6363-regulator.c create mode 100644 drivers/regulator/mt6373-regulator.c create mode 100644 include/linux/mfd/mt6363/core.h create mode 100644 include/linux/mfd/mt6363/registers.h create mode 100644 include/linux/mfd/mt6373/core.h create mode 100644 include/linux/mfd/mt6373/registers.h create mode 100644 include/linux/regulator/mt6316-regulator.h create mode 100644 include/linux/regulator/mt6363-regulator.h create mode 100644 include/linux/regulator/mt6373-regulator.h
--
2.46.0