Add support for MT6392 PMIC
Subsystems (11)
v8 cover Add support for MT6392 PMIC
The MediaTek MT6392 PMIC is usually found on devices powered by the MT8516/MT8167 SoC and is yet another MT6323/MT6397 variant.
This series is mostly based around patches submitted a couple years ago by Fabien Parent and not merged and from Val Packett's submission from Jan 2025 that included extra cleanups, fixes, and a new dtsi file similar to ones that exist for other PMICs. Some comments weren't addressed and the series was ultimately not merged.
These patches enable four functions: keys, regulator, pinctrl and RTC. Mono speaker amp will follow later as I need to work further on the audio codec.
I added a handful of device tree improvements to fix some dtbs_check errors, added support for the pinctrl device and addressed the comments from last year's reviews.
Please note that patch 0006 and 0008 depend on patch 0005 as they need the registers.h file, but belong to different driver areas. I'm not sure if I'm supposed to squash them even if they belong to different driver areas of if it's fine like this. Any advice is welcome.
Patch 0009 also depends on patch 0003 because of mt6392-regulator.h.
The series has been tested on Xiaomi Mi Smart Clock X04G and on the Lenovo Smart Clock 2 CD-24502F.
Changes in v8:
From reviewers:
- Added example code to the MFD device binding, removed it from the regulators docs.
- Added minItems/maxItems constraints on the regulator mode definitions, improved the mode constants.
- Fixed formatting issues in the regulator binding.
- Import the mt6392.dtsi file in pumpkin-common.dtsi, as it was originally meant in [8].
From sashiko:
- Added more explicit constraints on the regulator modes definitions.
- Use the appropriate modeget register for LDO regulators, Buck registers don't have the corresponding register according to the data sheet.
- Added the missing of_map_mode function.
- Removed some debugging code that had no use and masked error codes.
Changes in v7 [7]:
- Removed patch 0008 dependency on patch 0003.
- Reintroduced the regulator driver. In earlier revisions of this series, it was proposed to remove the dedicated compatible for the regulator device [3]. The driver does not use actually it, but it is not possible at this time to remove it from the bindings since it's a required property.
Making the regulator-required property conditional was NACKed in [5], with the suggestion to create a separate binding altogether for devices that do not require the compatible property. I tried implementing this, but since the parent device needs to be declared as compatible with mt6323, it leads to a warning in dt_binding_check since mt6323 would be declared as a compatible in both mt6392 and mt6397.
In the end the only regulator driver from the mt6397 documentation that still declares an of_match is mt6397-regulator and it does not seem to be necessary, so it should be possible to remove it and make the regulator compatible optional for all regulators, but that change would probably deserve its own separate patch series.
Changes in v6 [6]:
- Dropped the regulators driver for the moment
- Explained the FCHR key name origin in the commit message
- Introduced the MFD_CELL_* macro in the sub-devices definitions. A separate, independent commit introduced MFD_CELL_* to all the subdevices in the mt6397-core.c file for consistency
- Replaced of_device_get_match_data with device_get_match_data
- Removed the mfd_match_data enum in favor of the preexisting chip_id enum
- Adjusted the error message if the device is unsupported
Changes in v5 [5]:
- Double checked regulator driver with data sheet and Android sources. The data sheet I have misses a lot of register descriptions, but Android sources have been helpful to fill the gaps
- Reintroduced the required attribute for the regulator compatible in the bindings
- Fixed the missing reference to the MT6392 schema
- Fixed casts/unused vars reported by kernel test robot
- Removed Reviewed-by tags from the regulator patches as they have been modified in this version
Changes in v4 [4]:
- Dropped usage of the regulator compatible
- Fixed commit messages text to properly reference the target subsystem
- Added supply rails to the regulator
- Reworked the regulator schema and PMIC dtsi. Now all supplies are documented and the schema no longer includes voltage information
- Removed redundant ldo- / buck- prefixes
- Renamed the pinfunc header to mediatek,mt6392-pinfunc.h
- Modified the MFD driver to use a simple identifier in the of_match data properties
Changes in v3 [3]:
- Added pinctrl device
- Changed mt6397-rtc fallback to mt6323-rtc
- Added schema for regulators
- Fixed checkpatch issues
Changes in v2 [2]:
- Replaced explicit compatibles with fallbacks
Initial version: [1]
[1] https://lore.kernel.org/linux-mediatek/[email protected]/
[2] https://lore.kernel.org/linux-mediatek/[email protected]/
[3] https://lore.kernel.org/linux-mediatek/[email protected]/
[4] https://lore.kernel.org/linux-mediatek/[email protected]/
[5] https://lore.kernel.org/linux-mediatek/[email protected]/
[6] https://lore.kernel.org/linux-mediatek/[email protected]/
[7] https://lore.kernel.org/linux-mediatek/[email protected]/
[8] https://lore.kernel.org/linux-mediatek/[email protected]/
Fabien Parent (3):
dt-bindings: input: mtk-pmic-keys: Add MT6392 PMIC keys
mfd: mt6397: Add support for MT6392 PMIC
regulator: Add MediaTek MT6392 regulator
Luca Leonardo Scorcia (4):
dt-bindings: mfd: mt6397: Add MT6392 PMIC
regulator: dt-bindings: Add MediaTek MT6392 PMIC
mfd: mt6397: Use MFD_CELL_* to describe sub-devices
pinctrl: mediatek: mt6397: Add MediaTek MT6392
Val Packett (2):
input: keyboard: mtk-pmic-keys: Add MT6392 support
arm64: dts: mediatek: Add MediaTek MT6392 PMIC dtsi
.../bindings/input/mediatek,pmic-keys.yaml | 1 + .../bindings/mfd/mediatek,mt6397.yaml | 74 ++ .../regulator/mediatek,mt6392-regulator.yaml | 118 +++ arch/arm64/boot/dts/mediatek/mt6392.dtsi | 148 ++++ .../boot/dts/mediatek/pumpkin-common.dtsi | 2 + drivers/input/keyboard/mtk-pmic-keys.c | 17 + drivers/mfd/mt6397-core.c | 295 ++++--- drivers/mfd/mt6397-irq.c | 8 + drivers/pinctrl/mediatek/pinctrl-mt6397.c | 37 +- drivers/pinctrl/mediatek/pinctrl-mtk-mt6392.h | 64 ++ drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/mt6392-regulator.c | 764 ++++++++++++++++++ .../regulator/mediatek,mt6392-regulator.h | 23 + include/linux/mfd/mt6392/core.h | 43 + include/linux/mfd/mt6392/registers.h | 488 +++++++++++ include/linux/mfd/mt6397/core.h | 1 + include/linux/regulator/mt6392-regulator.h | 42 + 18 files changed, 1973 insertions(+), 162 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml create mode 100644 arch/arm64/boot/dts/mediatek/mt6392.dtsi create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-mt6392.h create mode 100644 drivers/regulator/mt6392-regulator.c create mode 100644 include/dt-bindings/regulator/mediatek,mt6392-regulator.h create mode 100644 include/linux/mfd/mt6392/core.h create mode 100644 include/linux/mfd/mt6392/registers.h create mode 100644 include/linux/regulator/mt6392-regulator.h
Signature · 1 line
2.43.0
PATCH v8 1/9 dt-bindings: mfd: mt6397: Add MT6392 PMIC
Describe the MT6392 PMIC and its RTC and regulator devices. This device is mostly based on MT6323 with some similarities to MT6397 and is usually found on boards using the MT8516/MT8167 SoC.
--- .../bindings/mfd/mediatek,mt6397.yaml | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+)
Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml +74 -0
@@ -40,6 +40,10 @@ properties: - mediatek,mt6358 - mediatek,mt6359 - mediatek,mt6397 + - items: + - enum: + - mediatek,mt6392 + - const: mediatek,mt6323 - items: - enum: - mediatek,mt6366
@@ -72,6 +76,10 @@ properties: - mediatek,mt6331-rtc - mediatek,mt6358-rtc - mediatek,mt6397-rtc + - items: + - enum: + - mediatek,mt6392-rtc + - const: mediatek,mt6323-rtc - items: - enum: - mediatek,mt6359-rtc
@@ -99,6 +107,7 @@ properties: - mediatek,mt6331-regulator - mediatek,mt6358-regulator - mediatek,mt6359-regulator + - mediatek,mt6392-regulator - mediatek,mt6397-regulator - items: - enum:
@@ -663,3 +672,68 @@ examples: compatible = "mediatek,mt6397-rtc"; }; }; + + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + pmic { + compatible = "mediatek,mt6392", "mediatek,mt6323"; + + interrupts-extended = <&pio 28 IRQ_TYPE_LEVEL_HIGH>; + interrupt-controller; + #interrupt-cells = <2>; + + keys { + compatible = "mediatek,mt6392-keys"; + + key-power { + linux,keycodes = <KEY_POWER>; + wakeup-source; + }; + + key-home { + linux,keycodes = <KEY_HOME>; + wakeup-source; + }; + }; + + pinctrl { + compatible = "mediatek,mt6392-pinctrl"; + + gpio-controller; + #gpio-cells = <2>; + }; + + regulators { + compatible = "mediatek,mt6392-regulator"; + + vproc { + regulator-allowed-modes = <0 1>; + regulator-initial-mode = <0>; + regulator-min-microvolt = < 700000>; + regulator-max-microvolt = <1350000>; + regulator-always-on; + regulator-boot-on; + }; + + // ... + + vadc18 { + regulator-allowed-modes = <0 2>; + regulator-initial-mode = <0>; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-boot-on; + regulator-always-on; + }; + + vefuse { + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <2000000>; + }; + }; + + rtc { + compatible = "mediatek,mt6392-rtc", "mediatek,mt6323-rtc"; + }; + };
Signature · 1 line
2.43.0
PATCH v8 2/9 dt-bindings: input: mtk-pmic-keys: Add MT6392 PMIC keys
In reply to Luca Leonardo ScorciaFrom: Fabien Parent <[email protected]>
Add the binding documentation of mtk-pmic-keys for the MT6392 PMIC.
--- Documentation/devicetree/bindings/input/mediatek,pmic-keys.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/input/mediatek,pmic-keys.yaml +1 -0
@@ -31,6 +31,7 @@ properties: - mediatek,mt6357-keys - mediatek,mt6358-keys - mediatek,mt6359-keys + - mediatek,mt6392-keys - mediatek,mt6397-keys - items: - enum:
Signature · 1 line
2.43.0
PATCH v8 3/9 regulator: dt-bindings: Add MediaTek MT6392 PMIC
In reply to Luca Leonardo ScorciaAdd bindings for the regulators found in the MediaTek MT6392 PMIC, usually found in board designs using the MediaTek MT8516/MT8167 SoCs.
--- .../regulator/mediatek,mt6392-regulator.yaml | 118 ++++++++++++++++++ .../regulator/mediatek,mt6392-regulator.h | 23 ++++ 2 files changed, 141 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml create mode 100644 include/dt-bindings/regulator/mediatek,mt6392-regulator.h
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +118 -0
@@ -0,0 +1,118 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/mediatek,mt6392-regulator.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek MT6392 regulator + +maintainers: + - Luca Leonardo Scorcia <[email protected]> + +description: + MT6392 is a power management system chip containing three buck converters and + 23 LDOs. All voltage regulators provided by the PMIC are described as + sub-nodes of this node. + +properties: + compatible: + items: + - const: mediatek,mt6392-regulator + + vproc-supply: + description: Supply for buck regulator vproc + vcore-supply: + description: Supply for buck regulator vcore + vsys-supply: + description: Supply for buck regulator vsys + avddldo-supply: + description: + Supply for AVDD LDOs (vm, vio18, vcn18, vcamd, vcamio). According to the data sheet + this is an internal supply derived from vsys. + ldo1-supply: + description: Supply for LDOs group 1 (vaud28, vxo22, vaud22, vadc18, vcama, vrtc) + ldo2-supply: + description: Supply for LDOs group 2 (vcn35, vio28, vmc, vmch, vefuse, vdig18) + ldo3-supply: + description: Supply for LDOs group 3 (vusb, vemc3v3, vcamaf, vgp1, vgp2, vm25) + +patternProperties: + "^v(core|proc|sys)$": + description: Buck regulators + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + properties: + regulator-allowed-modes: + description: + BUCK regulators can set regulator-allowed-modes to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 1] + minItems: 1 + maxItems: 2 + regulator-initial-mode: + description: + BUCK regulators can set regulator-initial-mode to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 1] + maxItems: 1 + + "^v(adc18|camio|cn18|io18|xo22|m25|aud28|io28|rtc|usb)$": + description: LDOs with fixed output and mode setting + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + properties: + regulator-allowed-modes: + description: + LDO regulators can set regulator-allowed-modes to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 2] + minItems: 1 + maxItems: 2 + regulator-initial-mode: + description: + LDO regulators can set regulator-initial-mode to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 2] + maxItems: 1 + + "^v(cama|dig18)$": + description: LDOs with fixed output without mode setting + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + properties: + regulator-allowed-modes: false + regulator-initial-mode: false + + "^v(aud22|camaf|camd|cn35|efuse|emc3v3|gp1|gp2|m|mc|mch)$": + description: LDOs with adjustable output and mode setting + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + properties: + regulator-allowed-modes: + description: + LDO regulators can set regulator-allowed-modes to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 2] + minItems: 1 + maxItems: 2 + regulator-initial-mode: + description: + LDO regulators can set regulator-initial-mode to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 2] + maxItems: 1 + +required: + - compatible + +additionalProperties: false
include/dt-bindings/regulator/mediatek,mt6392-regulator.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ + +#ifndef _DT_BINDINGS_REGULATOR_MEDIATEK_MT6392_H_ +#define _DT_BINDINGS_REGULATOR_MEDIATEK_MT6392_H_ + +/* +* Buck mode constants which may be used in devicetree properties (eg. +* regulator-initial-mode, regulator-allowed-modes). +* See the manufacturer's datasheet for more information on these modes. +*/ + +#define MT6392_REGULATOR_MODE_NORMAL 0 +#define MT6392_BUCK_MODE_FORCE_PWM 1 + +/* +* LDO mode constants which may be used in devicetree properties (eg. +* regulator-initial-mode, regulator-allowed-modes). +* See the manufacturer's datasheet for more information on these modes. +*/ + +#define MT6392_LDO_MODE_LP 2 + +#endif
Signature · 1 line
2.43.0
PATCH v8 4/9 mfd: mt6397: Use MFD_CELL_* to describe sub-devices
In reply to Luca Leonardo ScorciaUse the MFD_CELL_* macros to describe sub-devices. No functional changes.
--- drivers/mfd/mt6397-core.c | 197 ++++++++++++-------------------------- 1 file changed, 63 insertions(+), 134 deletions(-)
drivers/mfd/mt6397-core.c +63 -134
@@ -124,159 +124,88 @@ static const struct resource mt6323_pwrc_resources[] = { };static const struct mfd_cell mt6323_devs[] = { - { - .name ="mt6323-rtc" , - .num_resources =ARRAY_SIZE (mt6323_rtc_resources), - .resources = mt6323_rtc_resources, - .of_compatible ="mediatek,mt6323-rtc" , - }, { - .name ="mt6323-regulator" , - .of_compatible ="mediatek,mt6323-regulator" - }, { - .name ="mt6323-led" , - .of_compatible ="mediatek,mt6323-led" - }, { - .name ="mt6323-keys" , - .num_resources =ARRAY_SIZE (mt6323_keys_resources), - .resources = mt6323_keys_resources, - .of_compatible ="mediatek,mt6323-keys" - }, { - .name ="mt6323-pwrc" , - .num_resources =ARRAY_SIZE (mt6323_pwrc_resources), - .resources = mt6323_pwrc_resources, - .of_compatible ="mediatek,mt6323-pwrc" - }, +MFD_CELL_OF ("mt6323-rtc" , mt6323_rtc_resources,NULL ,0 ,0 , +"mediatek,mt6323-rtc" ), +MFD_CELL_OF ("mt6323-regulator" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6323-regulator" ), +MFD_CELL_OF ("mt6323-led" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6323-led" ), +MFD_CELL_OF ("mt6323-keys" , mt6323_keys_resources,NULL ,0 ,0 , +"mediatek,mt6323-keys" ), +MFD_CELL_OF ("mt6323-pwrc" , mt6323_pwrc_resources,NULL ,0 ,0 , +"mediatek,mt6323-pwrc" ), };static const struct mfd_cell mt6328_devs[] = { - { - .name ="mt6328-regulator" , - .of_compatible ="mediatek,mt6328-regulator" - }, { - .name ="mt6328-keys" , - .num_resources =ARRAY_SIZE (mt6328_keys_resources), - .resources = mt6328_keys_resources, - .of_compatible ="mediatek,mt6328-keys" - }, +MFD_CELL_OF ("mt6328-regulator" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6328-regulator" ), +MFD_CELL_OF ("mt6328-keys" , mt6328_keys_resources,NULL ,0 ,0 , +"mediatek,mt6328-keys" ), };static const struct mfd_cell mt6357_devs[] = { - { - .name ="mt6359-auxadc" , - .of_compatible ="mediatek,mt6357-auxadc" - }, { - .name ="mt6357-regulator" , - }, { - .name ="mt6357-rtc" , - .num_resources =ARRAY_SIZE (mt6357_rtc_resources), - .resources = mt6357_rtc_resources, - .of_compatible ="mediatek,mt6357-rtc" , - }, { - .name ="mt6357-sound" , - .of_compatible ="mediatek,mt6357-sound" - }, { - .name ="mt6357-keys" , - .num_resources =ARRAY_SIZE (mt6357_keys_resources), - .resources = mt6357_keys_resources, - .of_compatible ="mediatek,mt6357-keys" - }, +MFD_CELL_OF ("mt6359-auxadc" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6357-auxadc" ), +MFD_CELL_NAME ("mt6357-regulator" ), +MFD_CELL_OF ("mt6357-rtc" , mt6357_rtc_resources,NULL ,0 ,0 , +"mediatek,mt6357-rtc" ), +MFD_CELL_OF ("mt6357-sound" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6357-sound" ), +MFD_CELL_OF ("mt6357-keys" , mt6357_keys_resources,NULL ,0 ,0 , +"mediatek,mt6357-keys" ), };/* MT6331 is always used in combination with MT6332 */ static const struct mfd_cell mt6331_mt6332_devs[] = { - { - .name ="mt6331-rtc" , - .num_resources =ARRAY_SIZE (mt6331_rtc_resources), - .resources = mt6331_rtc_resources, - .of_compatible ="mediatek,mt6331-rtc" , - }, { - .name ="mt6331-regulator" , - .of_compatible ="mediatek,mt6331-regulator" - }, { - .name ="mt6332-regulator" , - .of_compatible ="mediatek,mt6332-regulator" - }, { - .name ="mt6331-keys" , - .num_resources =ARRAY_SIZE (mt6331_keys_resources), - .resources = mt6331_keys_resources, - .of_compatible ="mediatek,mt6331-keys" - }, +MFD_CELL_OF ("mt6331-rtc" , mt6331_rtc_resources,NULL ,0 ,0 , +"mediatek,mt6331-rtc" ), +MFD_CELL_OF ("mt6331-regulator" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6331-regulator" ), +MFD_CELL_OF ("mt6332-regulator" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6332-regulator" ), +MFD_CELL_OF ("mt6331-keys" , mt6331_keys_resources,NULL ,0 ,0 , +"mediatek,mt6331-keys" ), };static const struct mfd_cell mt6358_devs[] = { - { - .name ="mt6359-auxadc" , - .of_compatible ="mediatek,mt6358-auxadc" - }, { - .name ="mt6358-regulator" , - .of_compatible ="mediatek,mt6358-regulator" - }, { - .name ="mt6358-rtc" , - .num_resources =ARRAY_SIZE (mt6358_rtc_resources), - .resources = mt6358_rtc_resources, - .of_compatible ="mediatek,mt6358-rtc" , - }, { - .name ="mt6358-sound" , - .of_compatible ="mediatek,mt6358-sound" - }, { - .name ="mt6358-keys" , - .num_resources =ARRAY_SIZE (mt6358_keys_resources), - .resources = mt6358_keys_resources, - .of_compatible ="mediatek,mt6358-keys" - }, +MFD_CELL_OF ("mt6359-auxadc" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6358-auxadc" ), +MFD_CELL_OF ("mt6358-regulator" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6358-regulator" ), +MFD_CELL_OF ("mt6358-rtc" , mt6358_rtc_resources,NULL ,0 ,0 , +"mediatek,mt6358-rtc" ), +MFD_CELL_OF ("mt6358-sound" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6358-sound" ), +MFD_CELL_OF ("mt6358-keys" , mt6358_keys_resources,NULL ,0 ,0 , +"mediatek,mt6358-keys" ), };static const struct mfd_cell mt6359_devs[] = { - { - .name ="mt6359-auxadc" , - .of_compatible ="mediatek,mt6359-auxadc" - }, - { .name ="mt6359-regulator" , }, - { - .name ="mt6359-rtc" , - .num_resources =ARRAY_SIZE (mt6358_rtc_resources), - .resources = mt6358_rtc_resources, - .of_compatible ="mediatek,mt6358-rtc" , - }, - { .name ="mt6359-sound" , }, - { - .name ="mt6359-keys" , - .num_resources =ARRAY_SIZE (mt6359_keys_resources), - .resources = mt6359_keys_resources, - .of_compatible ="mediatek,mt6359-keys" - }, - { - .name ="mt6359-accdet" , - .of_compatible ="mediatek,mt6359-accdet" , - .num_resources =ARRAY_SIZE (mt6359_accdet_resources), - .resources = mt6359_accdet_resources, - }, +MFD_CELL_OF ("mt6359-auxadc" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6359-auxadc" ), +MFD_CELL_NAME ("mt6359-regulator" ), +MFD_CELL_OF ("mt6359-rtc" , mt6358_rtc_resources,NULL ,0 ,0 , +"mediatek,mt6358-rtc" ), +MFD_CELL_NAME ("mt6359-sound" ), +MFD_CELL_OF ("mt6359-keys" , mt6359_keys_resources,NULL ,0 ,0 , +"mediatek,mt6359-keys" ), +MFD_CELL_OF ("mt6359-accdet" , mt6359_accdet_resources,NULL ,0 ,0 , +"mediatek,mt6359-accdet" ), };static const struct mfd_cell mt6397_devs[] = { - { - .name ="mt6397-rtc" , - .num_resources =ARRAY_SIZE (mt6397_rtc_resources), - .resources = mt6397_rtc_resources, - .of_compatible ="mediatek,mt6397-rtc" , - }, { - .name ="mt6397-regulator" , - .of_compatible ="mediatek,mt6397-regulator" , - }, { - .name ="mt6397-codec" , - .of_compatible ="mediatek,mt6397-codec" , - }, { - .name ="mt6397-clk" , - .of_compatible ="mediatek,mt6397-clk" , - }, { - .name ="mt6397-pinctrl" , - .of_compatible ="mediatek,mt6397-pinctrl" , - }, { - .name ="mt6397-keys" , - .num_resources =ARRAY_SIZE (mt6397_keys_resources), - .resources = mt6397_keys_resources, - .of_compatible ="mediatek,mt6397-keys" - } +MFD_CELL_OF ("mt6397-rtc" , mt6397_rtc_resources,NULL ,0 ,0 , +"mediatek,mt6397-rtc" ), +MFD_CELL_OF ("mt6397-regulator" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6397-regulator" ), +MFD_CELL_OF ("mt6397-codec" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6397-codec" ), +MFD_CELL_OF ("mt6397-clk" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6397-clk" ), +MFD_CELL_OF ("mt6397-pinctrl" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6397-pinctrl" ), +MFD_CELL_OF ("mt6397-keys" , mt6397_keys_resources,NULL ,0 ,0 , +"mediatek,mt6397-keys" ), };struct chip_data {
Signature · 1 line
2.43.0
PATCH v8 5/9 mfd: mt6397: Add support for MT6392 PMIC
In reply to Luca Leonardo ScorciaFrom: Fabien Parent <[email protected]>
Align the MT6397 PMIC driver to other MFD drivers by passing only an identifier through mt6397_of_match[*].data and add support for the MT6392 PMIC and its regulator, RTC, keys and pinctrl devices.
The keys device manages two buttons named PWRKEY and FCHR_ENB, the latter is identified as "Force charging disable" in the data sheet but it also says "Merge with HOMEKEY", so call it "Home" for consistency.
--- drivers/mfd/mt6397-core.c | 98 ++++-- drivers/mfd/mt6397-irq.c | 8 + include/linux/mfd/mt6392/core.h | 43 +++ include/linux/mfd/mt6392/registers.h | 488 +++++++++++++++++++++++++++ include/linux/mfd/mt6397/core.h | 1 + 5 files changed, 612 insertions(+), 26 deletions(-) create mode 100644 include/linux/mfd/mt6392/core.h create mode 100644 include/linux/mfd/mt6392/registers.h
drivers/mfd/mt6397-core.c +72 -26
@@ -18,6 +18,7 @@#include <linux/mfd/mt6357/core.h> #include <linux/mfd/mt6358/core.h> #include <linux/mfd/mt6359/core.h> +#include <linux/mfd/mt6392/core.h> #include <linux/mfd/mt6397/core.h> #include <linux/mfd/mt6323/registers.h> #include <linux/mfd/mt6328/registers.h>
@@ -25,6 +26,7 @@#include <linux/mfd/mt6357/registers.h> #include <linux/mfd/mt6358/registers.h> #include <linux/mfd/mt6359/registers.h> +#include <linux/mfd/mt6392/registers.h> #include <linux/mfd/mt6397/registers.h> #define MT6323_RTC_BASE 0x8000
@@ -39,6 +41,9 @@#define MT6358_RTC_BASE 0x0588#define MT6358_RTC_SIZE 0x3c +#define MT6392_RTC_BASE 0x8000 +#define MT6392_RTC_SIZE 0x3e +#define MT6397_RTC_BASE 0xe000#define MT6397_RTC_SIZE 0x3e
@@ -65,6 +70,11 @@ static const struct resource mt6358_rtc_resources[] = { DEFINE_RES_IRQ(MT6358_IRQ_RTC), }; +static const struct resource mt6392_rtc_resources[] = { +DEFINE_RES_MEM (MT6392_RTC_BASE ,MT6392_RTC_SIZE ), +DEFINE_RES_IRQ (MT6392_IRQ_RTC ), +}; +static const struct resource mt6397_rtc_resources[] = {DEFINE_RES_MEM (MT6397_RTC_BASE ,MT6397_RTC_SIZE ),DEFINE_RES_IRQ (MT6397_IRQ_RTC ),
@@ -114,6 +124,11 @@ static const struct resource mt6331_keys_resources[] = { DEFINE_RES_IRQ_NAMED(MT6331_IRQ_STATUS_HOMEKEY, "homekey"), }; +static const struct resource mt6392_keys_resources[] = { +DEFINE_RES_IRQ_NAMED (MT6392_IRQ_PWRKEY ,"powerkey" ), +DEFINE_RES_IRQ_NAMED (MT6392_IRQ_FCHRKEY ,"homekey" ), +}; +static const struct resource mt6397_keys_resources[] = {DEFINE_RES_IRQ_NAMED (MT6397_IRQ_PWRKEY ,"powerkey" ),DEFINE_RES_IRQ_NAMED (MT6397_IRQ_HOMEKEY ,"homekey" ),
@@ -193,6 +208,16 @@ static const struct mfd_cell mt6359_devs[] = { "mediatek,mt6359-accdet"), }; +static const struct mfd_cell mt6392_devs[] = { +MFD_CELL_OF ("mt6392-keys" , mt6392_keys_resources,NULL ,0 ,0 , +"mediatek,mt6392-keys" ), +MFD_CELL_OF ("mt6392-pinctrl" ,NULL ,NULL ,0 ,0 , +"mediatek,mt6392-pinctrl" ), +MFD_CELL_NAME ("mt6392-regulator" ), +MFD_CELL_OF ("mt6392-rtc" , mt6392_rtc_resources,NULL ,0 ,0 , +"mediatek,mt6392-rtc" ), +}; +static const struct mfd_cell mt6397_devs[] = {MFD_CELL_OF ("mt6397-rtc" , mt6397_rtc_resources,NULL ,0 ,0 ,"mediatek,mt6397-rtc" ),
@@ -264,6 +289,14 @@ static const struct chip_data mt6359_core = { .irq_init = mt6358_irq_init, }; +static const struct chip_data mt6392_core = { + .cid_addr =MT6392_CID , + .cid_shift =0 , + .cells = mt6392_devs, + .cell_size =ARRAY_SIZE (mt6392_devs), + .irq_init = mt6397_irq_init, +}; +static const struct chip_data mt6397_core = { .cid_addr =MT6397_CID , .cid_shift =0 ,
@@ -278,6 +311,7 @@ static int mt6397_probe(struct platform_device *pdev)unsigned int id =0 ;struct mt6397_chip *pmic;const struct chip_data *pmic_core; +int chip_variant; pmic =devm_kzalloc (&pdev->dev,sizeof (*pmic),GFP_KERNEL );if (!pmic)
@@ -293,9 +327,36 @@ static int mt6397_probe(struct platform_device *pdev)if (!pmic->regmap)return -ENODEV ; - pmic_core =of_device_get_match_data (&pdev->dev); -if (!pmic_core) + chip_variant = (unsigned int )(uintptr_t )device_get_match_data (&pdev->dev); +switch (chip_variant) { +case MT6323_CHIP_ID : + pmic_core = &mt6323_core; +break ; +case MT6328_CHIP_ID : + pmic_core = &mt6328_core; +break ; +case MT6331_CHIP_ID : + pmic_core = &mt6331_mt6332_core; +break ; +case MT6357_CHIP_ID : + pmic_core = &mt6357_core; +break ; +case MT6358_CHIP_ID : + pmic_core = &mt6358_core; +break ; +case MT6359_CHIP_ID : + pmic_core = &mt6359_core; +break ; +case MT6392_CHIP_ID : + pmic_core = &mt6392_core; +break ; +case MT6397_CHIP_ID : + pmic_core = &mt6397_core; +break ; +default : +dev_err (&pdev->dev,"Device not supported\n" );return -ENODEV ; + } ret =regmap_read (pmic->regmap, pmic_core->cid_addr, &id);if (ret) {
@@ -327,30 +388,15 @@ static int mt6397_probe(struct platform_device *pdev) }static const struct of_device_id mt6397_of_match[] = { - { - .compatible ="mediatek,mt6323" , - .data = &mt6323_core, - }, { - .compatible ="mediatek,mt6328" , - .data = &mt6328_core, - }, { - .compatible ="mediatek,mt6331" , - .data = &mt6331_mt6332_core, - }, { - .compatible ="mediatek,mt6357" , - .data = &mt6357_core, - }, { - .compatible ="mediatek,mt6358" , - .data = &mt6358_core, - }, { - .compatible ="mediatek,mt6359" , - .data = &mt6359_core, - }, { - .compatible ="mediatek,mt6397" , - .data = &mt6397_core, - }, { -/* sentinel */ - } + { .compatible ="mediatek,mt6323" , .data = (void *)MT6323_CHIP_ID , }, + { .compatible ="mediatek,mt6328" , .data = (void *)MT6328_CHIP_ID , }, + { .compatible ="mediatek,mt6331" , .data = (void *)MT6331_CHIP_ID , }, + { .compatible ="mediatek,mt6357" , .data = (void *)MT6357_CHIP_ID , }, + { .compatible ="mediatek,mt6358" , .data = (void *)MT6358_CHIP_ID , }, + { .compatible ="mediatek,mt6359" , .data = (void *)MT6359_CHIP_ID , }, + { .compatible ="mediatek,mt6392" , .data = (void *)MT6392_CHIP_ID , }, + { .compatible ="mediatek,mt6397" , .data = (void *)MT6397_CHIP_ID , }, + {/* sentinel */ } };MODULE_DEVICE_TABLE (of, mt6397_of_match);
drivers/mfd/mt6397-irq.c +8 -0
@@ -15,6 +15,8 @@#include <linux/mfd/mt6328/registers.h> #include <linux/mfd/mt6331/core.h> #include <linux/mfd/mt6331/registers.h> +#include <linux/mfd/mt6392/core.h> +#include <linux/mfd/mt6392/registers.h> #include <linux/mfd/mt6397/core.h> #include <linux/mfd/mt6397/registers.h>
@@ -203,6 +205,12 @@ int mt6397_irq_init(struct mt6397_chip *chip) chip->int_status[0 ] =MT6397_INT_STATUS0 ; chip->int_status[1 ] =MT6397_INT_STATUS1 ;break ; +case MT6392_CHIP_ID : + chip->int_con[0 ] =MT6392_INT_CON0 ; + chip->int_con[1 ] =MT6392_INT_CON1 ; + chip->int_status[0 ] =MT6392_INT_STATUS0 ; + chip->int_status[1 ] =MT6392_INT_STATUS1 ; +break ;default :dev_err (chip->dev,"unsupported chip: 0x%x\n" , chip->chip_id);
include/linux/mfd/mt6392/core.h new file +43 -0
43 lines not on this page · raw message
include/linux/mfd/mt6392/registers.h new file +488 -0
488 lines not on this page · raw message
include/linux/mfd/mt6397/core.h +1 -0
@@ -20,6 +20,7 @@ enum chip_id {MT6359_CHIP_ID =0x59 ,MT6366_CHIP_ID =0x66 ,MT6391_CHIP_ID =0x91 , +MT6392_CHIP_ID =0x92 , MT6397_CHIP_ID = 0x97, };
Signature · 1 line
2.43.0
PATCH v8 6/9 input: keyboard: mtk-pmic-keys: Add MT6392 support
In reply to Luca Leonardo ScorciaFrom: Val Packett <[email protected]>
Add support for the MT6392 PMIC to the keys driver.
--- drivers/input/keyboard/mtk-pmic-keys.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/input/keyboard/mtk-pmic-keys.c +17 -0
@@ -13,6 +13,7 @@#include <linux/mfd/mt6357/registers.h> #include <linux/mfd/mt6358/registers.h> #include <linux/mfd/mt6359/registers.h> +#include <linux/mfd/mt6392/registers.h> #include <linux/mfd/mt6397/core.h> #include <linux/mfd/mt6397/registers.h> #include <linux/module.h>
@@ -69,6 +70,19 @@ static const struct mtk_pmic_regs mt6397_regs = { .rst_lprst_mask = MTK_PMIC_RST_DU_MASK, }; +static const struct mtk_pmic_regs mt6392_regs = { + .keys_regs[MTK_PMIC_PWRKEY_INDEX ] = +MTK_PMIC_KEYS_REGS (MT6392_CHRSTATUS ,0x2 , +MT6392_INT_MISC_CON ,0x10 , +MTK_PMIC_PWRKEY_RST ), + .keys_regs[MTK_PMIC_HOMEKEY_INDEX ] = +MTK_PMIC_KEYS_REGS (MT6392_CHRSTATUS ,0x4 , +MT6392_INT_MISC_CON ,0x8 , +MTK_PMIC_HOMEKEY_RST ), + .pmic_rst_reg =MT6392_TOP_RST_MISC , + .rst_lprst_mask =MTK_PMIC_RST_DU_MASK , +}; +static const struct mtk_pmic_regs mt6323_regs = { .keys_regs[MTK_PMIC_PWRKEY_INDEX ] = MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS,
@@ -301,6 +315,9 @@ static const struct of_device_id of_mtk_pmic_keys_match_tbl[] = { { .compatible = "mediatek,mt6397-keys", .data = &mt6397_regs, + }, { + .compatible = "mediatek,mt6392-keys", + .data = &mt6392_regs, }, { .compatible = "mediatek,mt6323-keys", .data = &mt6323_regs,
Signature · 1 line
2.43.0
PATCH v8 7/9 pinctrl: mediatek: mt6397: Add MediaTek MT6392
In reply to Luca Leonardo ScorciaAdd support for the MT6392 pinctrl device, which is very similar to MT6397 with a handful of different property values and its own pins definition.
Update the MT6397 driver to retrieve device data from the match table and use it for driver init.
--- drivers/pinctrl/mediatek/pinctrl-mt6397.c | 37 ++++++++++- drivers/pinctrl/mediatek/pinctrl-mtk-mt6392.h | 64 +++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 drivers/pinctrl/mediatek/pinctrl-mtk-mt6392.h
drivers/pinctrl/mediatek/pinctrl-mt6397.c +35 -2
@@ -12,10 +12,32 @@#include <linux/mfd/mt6397/core.h> #include "pinctrl-mtk-common.h" +#include "pinctrl-mtk-mt6392.h" #include "pinctrl-mtk-mt6397.h" #define MT6397_PIN_REG_BASE 0xc000 +static const struct mtk_pinctrl_devdata mt6392_pinctrl_data = { + .pins = mtk_pins_mt6392, + .npins =ARRAY_SIZE (mtk_pins_mt6392), + .dir_offset = (MT6397_PIN_REG_BASE +0x000 ), + .ies_offset =MTK_PINCTRL_NOT_SUPPORT , + .smt_offset =MTK_PINCTRL_NOT_SUPPORT , + .pullen_offset = (MT6397_PIN_REG_BASE +0x020 ), + .pullsel_offset = (MT6397_PIN_REG_BASE +0x040 ), + .dout_offset = (MT6397_PIN_REG_BASE +0x080 ), + .din_offset = (MT6397_PIN_REG_BASE +0x0a0 ), + .pinmux_offset = (MT6397_PIN_REG_BASE +0x0c0 ), + .type1_start =7 , + .type1_end =7 , + .port_shf =3 , + .port_mask =0x3 , + .port_align =2 , + .mode_mask =0xf , + .mode_per_reg =5 , + .mode_shf =4 , +}; +static const struct mtk_pinctrl_devdata mt6397_pinctrl_data = { .pins = mtk_pins_mt6397, .npins =ARRAY_SIZE (mtk_pins_mt6397),
@@ -40,13 +62,24 @@ static const struct mtk_pinctrl_devdata mt6397_pinctrl_data = {static int mt6397_pinctrl_probe (struct platform_device *pdev) {struct mt6397_chip *mt6397; +const struct mtk_pinctrl_devdata *data; + + data =device_get_match_data (&pdev->dev); +if (!data) +return -ENOENT ; mt6397 =dev_get_drvdata (pdev->dev.parent); -return mtk_pctrl_init (pdev, &mt6397_pinctrl_data, mt6397->regmap); +return mtk_pctrl_init (pdev, data, mt6397->regmap); }static const struct of_device_id mt6397_pctrl_match[] = { - { .compatible ="mediatek,mt6397-pinctrl" , }, + { + .compatible ="mediatek,mt6392-pinctrl" , + .data = &mt6392_pinctrl_data + }, { + .compatible ="mediatek,mt6397-pinctrl" , + .data = &mt6397_pinctrl_data + }, { } };
drivers/pinctrl/mediatek/pinctrl-mtk-mt6392.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v8 8/9 regulator: Add MediaTek MT6392 regulator
In reply to Luca Leonardo ScorciaFrom: Fabien Parent <[email protected]>
The MT6392 is a regulator found on boards based on the MediaTek MT8167, MT8516, and probably other SoCs. It is a so called PMIC and connects as a slave to a SoC using SPI, wrapped inside PWRAP.
--- drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/mt6392-regulator.c | 764 +++++++++++++++++++++ include/linux/regulator/mt6392-regulator.h | 42 ++ 4 files changed, 816 insertions(+) create mode 100644 drivers/regulator/mt6392-regulator.c create mode 100644 include/linux/regulator/mt6392-regulator.h
drivers/regulator/Kconfig +9 -0
@@ -1001,6 +1001,15 @@ config REGULATOR_MT6380 This driver supports the control of different power rails of device through regulator interface. +config REGULATOR_MT6392 + tristate "MediaTek MT6392 PMIC" + depends on MFD_MT6397 + help + Say y here to select this option to enable the power regulator of + MediaTek MT6392 PMIC. + This driver supports the control of different power rails of device + through regulator interface. + config REGULATOR_MT6397 tristate "MediaTek MT6397 PMIC" depends on MFD_MT6397
drivers/regulator/Makefile +1 -0
@@ -118,6 +118,7 @@ obj-$(CONFIG_REGULATOR_MT6360) += mt6360-regulator.o obj-$(CONFIG_REGULATOR_MT6363) += mt6363-regulator.o obj-$(CONFIG_REGULATOR_MT6370) += mt6370-regulator.o obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o +obj-$(CONFIG_REGULATOR_MT6392) += mt6392-regulator.o obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o obj-$(CONFIG_REGULATOR_MTK_DVFSRC) += mtk-dvfsrc-regulator.o obj-$(CONFIG_REGULATOR_QCOM_LABIBB) += qcom-labibb-regulator.o
drivers/regulator/mt6392-regulator.c new file +764 -0
764 lines not on this page · raw message
include/linux/regulator/mt6392-regulator.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v8 9/9 arm64: dts: mediatek: Add MediaTek MT6392 PMIC dtsi
In reply to Luca Leonardo ScorciaFrom: Val Packett <[email protected]>
Add the dtsi to be included by all boards using the MT6392 PMIC, providing support for regulator, keys, pinctrl and RTC.
Import the new file in the shared device tree for the Pumpkin boards.
--- arch/arm64/boot/dts/mediatek/mt6392.dtsi | 148 ++++++++++++++++++ .../boot/dts/mediatek/pumpkin-common.dtsi | 2 + 2 files changed, 150 insertions(+) create mode 100644 arch/arm64/boot/dts/mediatek/mt6392.dtsi
arch/arm64/boot/dts/mediatek/mt6392.dtsi new file +148 -0
@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 MediaTek Inc. + * Copyright (c) 2024 Val Packett <[email protected]> + * Copyright (c) 2026 Luca Leonardo Scorcia <[email protected]> + */ + +#include <dt-bindings/input/input.h> +#include <dt-bindings/regulator/mediatek,mt6392-regulator.h> + +&pwrap { + pmic: pmic { + compatible = "mediatek,mt6392", "mediatek,mt6323"; + interrupt-controller; + #interrupt-cells = <2>; + + mt6392keys: keys { + compatible = "mediatek,mt6392-keys"; + + key-power { + linux,keycodes = <KEY_POWER>; + wakeup-source; + }; + + key-home { + linux,keycodes = <KEY_HOME>; + wakeup-source; + }; + }; + + mt6392pio: pinctrl { + compatible = "mediatek,mt6392-pinctrl"; + + gpio-controller; + #gpio-cells = <2>; + }; + + mt6392regulators: regulators { + compatible = "mediatek,mt6392-regulator"; + + /* Fixed supply defined in the data sheet */ + avddldo-supply = <&mt6392_vsys_reg>; + + mt6392_vcore_reg: vcore { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_BUCK_MODE_FORCE_PWM>; + }; + mt6392_vproc_reg: vproc { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_BUCK_MODE_FORCE_PWM>; + }; + mt6392_vsys_reg: vsys { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_BUCK_MODE_FORCE_PWM>; + }; + mt6392_vaud28_reg: vaud28 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vxo22_reg: vxo22 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vaud22_reg: vaud22 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vadc18_reg: vadc18 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vcama_reg: vcama { }; + mt6392_vcn35_reg: vcn35 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vio28_reg: vio28 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vusb_reg: vusb { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vmc_reg: vmc { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vmch_reg: vmch { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vemc3v3_reg: vemc3v3 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vcamaf_reg: vcamaf { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vgp1_reg: vgp1 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vgp2_reg: vgp2 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vefuse_reg: vefuse { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vm25_reg: vm25 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vdig18_reg: vdig18 { }; + mt6392_vm_reg: vm { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vio18_reg: vio18 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vcn18_reg: vcn18 { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vcamd_reg: vcamd { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vcamio_reg: vcamio { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + mt6392_vrtc_reg: vrtc { + regulator-allowed-modes = <MT6392_REGULATOR_MODE_NORMAL + MT6392_LDO_MODE_LP>; + }; + }; + + mt6392rtc: rtc { + compatible = "mediatek,mt6392-rtc", "mediatek,mt6323-rtc"; + }; + }; +};
arch/arm64/boot/dts/mediatek/pumpkin-common.dtsi +2 -0
@@ -6,6 +6,8 @@ #include <dt-bindings/gpio/gpio.h> +#include "mt6392.dtsi" + / { aliases { serial0 = &uart0;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v8 8/9] regulator: Add MediaTek MT6392 regulator
In reply to Luca Leonardo ScorciaThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The driver modifies the globally shared static `mt6392_regulators` array during probe, leading to…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The driver modifies the globally shared static mt6392_regulators array during probe, leading to cross-device state corruption and data races.
- [Medium] mt6392_ldo_set_mode() clears the low-power mode bit instead of setting it when requesting STANDBY mode, due to confusing a devicetree constant with a register bit value. --
commit 93833e30ee73cbbe6e2371cc49b2ce2c9207ea99
Author: Fabien Parent <[email protected]>
regulator: Add MediaTek MT6392 regulator
This commit adds a new regulator driver for the MediaTek MT6392 PMIC. It supports control over different power rails on boards based on MT8167, MT8516, and other SoCs. The driver uses regmap for voltage and mode control across multiple buck and LDO regulators.
Quoted 4 lines
drivers/regulator/mt6392-regulator.c new file +0
-0
[ ... ]
Quoted 5 lines
drivers/regulator/mt6392-regulator.c new file +5
-0+static int mt6392_ldo_set_mode (struct regulator_dev *rdev,unsigned int mode) +{ +int ret, val =0 ; +struct mt6392_regulator_info *info =rdev_get_drvdata (rdev); +
drivers/regulator/mt6392-regulator.c line 380
Quoted 10 lines
drivers/regulator/mt6392-regulator.c new file +10
-0+if (!info->lp_modeset_mask) { +dev_err (&rdev->dev,"regulator %s doesn't support set_mode\n" , + info->desc.name); +return -EINVAL ; + } + +switch (mode) { +case REGULATOR_MODE_STANDBY : + val =MT6392_LDO_MODE_LP ; +break ;
[Severity: Medium]
Will this clear the low-power mode bit instead of setting it?
MT6392_LDO_MODE_LP is defined as 2. If the mask is a single bit, shifting val by ffs(mask) - 1 will result in a value that evaluates to 0 when masked in regmap_update_bits().
Does val need to be 1 here to correctly set the bit for STANDBY mode?
Quoted 11 lines
drivers/regulator/mt6392-regulator.c new file +11
-0+case REGULATOR_MODE_NORMAL : + val =MT6392_REGULATOR_MODE_NORMAL ; +break ; +default : +return -EINVAL ; + } + + val <<=ffs (info->lp_modeset_mask) -1 ; + + ret =regmap_update_bits (rdev->regmap, info->lp_modeset_reg, + info->lp_modeset_mask, val);
[ ... ]
Quoted 16 lines
drivers/regulator/mt6392-regulator.c new file +16
-0+// Buck regulators can be in Register mode or Normal mode. +// Each mode uses a different register to set the desired voltage. +static int mt6392_set_buck_vsel_reg (struct platform_device *pdev) +{ +struct mt6397_chip *mt6392 =dev_get_drvdata (pdev->dev.parent); +int i; +u32 regval; + +for (i =0 ; i <MT6392_MAX_REGULATOR ; i++) { +if (mt6392_regulators[i].vselctrl_reg) { +// Read the vselctrl_reg register +if (regmap_read (mt6392->regmap, + mt6392_regulators[i].vselctrl_reg, + ®val) <0 ) { +dev_err (&pdev->dev, +"Failed to read buck ctrl\n" );
drivers/regulator/mt6392-regulator.c line 700
Quoted 10 lines
drivers/regulator/mt6392-regulator.c new file +10
-0+return -EIO ; + } + +// vselctrl_reg[vselctrl_mask] defines the mode +if (regval & mt6392_regulators[i].vselctrl_mask) { +// Regulator in Normal mode + mt6392_regulators[i].desc.vsel_reg = + mt6392_regulators[i].vsel_normal_mode_reg; + mt6392_regulators[i].desc.vsel_mask = + mt6392_regulators[i].vsel_normal_mode_mask;
[Severity: High]
Does this code mutate the globally shared static mt6392_regulators array during probe?
Since the driver uses PROBE_PREFER_ASYNCHRONOUS, concurrent probes of multiple PMIC instances could cause a data race.
Furthermore, as devm_regulator_register() stores a pointer to the desc structure, all instantiated PMICs would end up sharing the mutated vsel_reg from the last probed PMIC.
Could this break voltage control for any instances whose hardware state differs?
Quoted 12 lines
drivers/regulator/mt6392-regulator.c new file +12
-0+ }else { +// Regulator in Register mode + mt6392_regulators[i].desc.vsel_reg = + mt6392_regulators[i].vsel_reg_mode_reg; + mt6392_regulators[i].desc.vsel_mask = + mt6392_regulators[i].vsel_reg_mode_mask; + } + } + } + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH v8 1/9] dt-bindings: mfd: mt6397: Add MT6392 PMIC
In reply to Luca Leonardo ScorciaThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing required header for input macros in device tree example --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing required header for input macros in device tree example
--
commit 17d3dfc19cdb75b35edbf6c7f6fe9a12ac08651b
Author: Luca Leonardo Scorcia <[email protected]>
dt-bindings: mfd: mt6397: Add MT6392 PMIC
Describe the MT6392 PMIC and its RTC and regulator devices. This device is mostly based on MT6323 with some similarities to MT6397 and is usually found on boards using the MT8516/MT8167 SoC.
Quoted 4 lines
Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml +0
-0
[ ... ]
Quoted 10 lines
Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml +6
-0@@ -663,3 +672,68 @@ examples: compatible = "mediatek,mt6397-rtc"; }; }; + + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + + pmic { + compatible = "mediatek,mt6392", "mediatek,mt6323";
Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml examples: · line 690
Quoted 10 lines
Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml +10
-0+ + interrupts-extended = <&pio 28 IRQ_TYPE_LEVEL_HIGH>; + interrupt-controller; + #interrupt-cells = <2>; + + keys { + compatible = "mediatek,mt6392-keys"; + + key-power { + linux,keycodes = <KEY_POWER>;
[Severity: Low]
Does this example miss the <dt-bindings/input/input.h> include for the KEY_POWER and KEY_HOME macros?
Although the dt_binding_check tooling extracts and concatenates all examples into a single file (meaning it will inadvertently compile successfully because a previous example includes the header), omitting the header in this specific standalone example block might cause compilation failures if copied by developers for standalone use.
Quoted 7 lines
Documentation/devicetree/bindings/mfd/mediatek,mt6397.yaml +7
-0+ wakeup-source; + }; + + key-home { + linux,keycodes = <KEY_HOME>; + wakeup-source; + };
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v8 3/9] regulator: dt-bindings: Add MediaTek MT6392 PMIC
In reply to Luca Leonardo ScorciaThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] Invalid use of array validation keywords (`items`, `maxItems`) on the scalar…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Invalid use of array validation keywords (items, maxItems) on the scalar regulator-initial-mode property, allowing any integer value to bypass the intended enum constraints.
- [Low] The dt-binding YAML file is completely missing an examples: section.
- [Low] Exposing an internal, hardwired connection (avddldo-supply) as an external device tree property.
--
commit 17d808769b24018a674d4068d9bab99043b30c55
Author: Luca Leonardo Scorcia <[email protected]>
regulator: dt-bindings: Add MediaTek MT6392 PMIC
Add bindings for the regulators found in the MediaTek MT6392 PMIC, usually found in board designs using the MediaTek MT8516/MT8167 SoCs.
Quoted 6 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +0
-0@@ -0,0 +1,118 @@
[ ... ]
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml line 31
Quoted 10 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +10
-0+ vproc-supply: + description: Supply for buck regulator vproc + vcore-supply: + description: Supply for buck regulator vcore + vsys-supply: + description: Supply for buck regulator vsys + avddldo-supply: + description: + Supply for AVDD LDOs (vm, vio18, vcn18, vcamd, vcamio). According to the data sheet + this is an internal supply derived from vsys.
[Severity: Low]
Should this internal supply be exposed as an external device tree property?
Since the description notes this is an internal supply derived from vsys, exposing it here requires board device trees to describe internal IC routing instead of external hardware wiring.
[ ... ]
Quoted 12 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +12
-0+patternProperties: + "^v(core|proc|sys)$": + description: Buck regulators + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + properties: + regulator-allowed-modes: + description: + BUCK regulators can set regulator-allowed-modes to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items:
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml line 60
Quoted 10 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +10
-0+ enum: [0, 1] + minItems: 1 + maxItems: 2 + regulator-initial-mode: + description: + BUCK regulators can set regulator-initial-mode to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 1] + maxItems: 1
[Severity: Medium]
Is it correct to use array validation keywords like items and maxItems for regulator-initial-mode?
Since regulator-initial-mode is defined as a scalar uint32 in regulator.yaml, applying array constraints to it causes the schema validation to ignore them. This allows any arbitrary integer value to bypass the enum constraints.
[ ... ]
Quoted 7 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +7
-0+ "^v(adc18|camio|cn18|io18|xo22|m25|aud28|io28|rtc|usb)$": + description: LDOs with fixed output and mode setting + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + properties: + regulator-allowed-modes:
[ ... ]
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml line 82
Quoted 7 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +7
-0+ regulator-initial-mode: + description: + LDO regulators can set regulator-initial-mode to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 2] + maxItems: 1
[Severity: Medium]
Does this have the same issue with array validation keywords being applied to a scalar property?
[ ... ]
Quoted 7 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +7
-0+ "^v(aud22|camaf|camd|cn35|efuse|emc3v3|gp1|gp2|m|mc|mch)$": + description: LDOs with adjustable output and mode setting + type: object + $ref: regulator.yaml# + unevaluatedProperties: false + properties: + regulator-allowed-modes:
[ ... ]
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml line 82
Quoted 7 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +7
-0+ regulator-initial-mode: + description: + LDO regulators can set regulator-initial-mode to values specified in + dt-bindings/regulator/mediatek,mt6392-regulator.h + items: + enum: [0, 2] + maxItems: 1
[Severity: Medium]
This regulator-initial-mode property also appears to be using array validation keywords for a scalar value.
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml line 118
Quoted 5 lines
Documentation/devicetree/bindings/regulator/mediatek,mt6392-regulator.yaml new file +5
-0+ +required: + - compatible + +additionalProperties: false
[Severity: Low]
Is there an examples section missing from this file?
Device tree binding guidelines require every standalone schema file to include an examples section to provide a validated example of the device node and to pass dt_binding_check validation.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v8 7/9] pinctrl: mediatek: mt6397: Add MediaTek MT6392
In reply to Luca Leonardo ScorciaThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] NULL pointer dereference triggered on gpio_to_irq() for MT6397 pins.
- [High] Use-After-Free in gpiolib due to missing devres registration and .remove callback.
- [High] Use-After-Free in IRQ handler from non-devres chained handler registration. --
commit b7ca497bf50208e7b29acdf520d006f2e9f79e4b
Author: Luca Leonardo Scorcia <[email protected]>
pinctrl: mediatek: mt6397: Add MediaTek MT6392
Add support for the MT6392 pinctrl device, which is very similar to MT6397 with a handful of different property values and its own pins definition.
Quoted 4 lines
drivers/pinctrl/mediatek/pinctrl-mt6397.c +0
-0
[ ... ]
drivers/pinctrl/mediatek/pinctrl-mt6397.c static const struct mtk_pinctrl_devdata mt6397_pinctrl_data = { · line 72
Quoted 13 lines
drivers/pinctrl/mediatek/pinctrl-mt6397.c +6
-1@@ -40,13 +62,24 @@ static const struct mtk_pinctrl_devdata mt6397_pinctrl_data = {static int mt6397_pinctrl_probe (struct platform_device *pdev) {struct mt6397_chip *mt6397; +const struct mtk_pinctrl_devdata *data; + + data =device_get_match_data (&pdev->dev); +if (!data) +return -ENOENT ; mt6397 =dev_get_drvdata (pdev->dev.parent); -return mtk_pctrl_init (pdev, &mt6397_pinctrl_data, mt6397->regmap); +return mtk_pctrl_init (pdev, data, mt6397->regmap);
[Severity: High]
This is a pre-existing issue, but does mtk_pctrl_init() leave pctl->eint uninitialized for these devices, leading to a NULL pointer dereference?
Because neither mt6392_pinctrl_data nor mt6397_pinctrl_data initialize the eint_hw field, mtk_pctrl_init() skips mtk_eint_init().
If gpio_to_irq() is later invoked on these pins, it calls down through:
mtk_gpio_to_irq()
mtk_eint_find_irq(pctl->eint, eint_n)
irq_find_mapping(eint->domain, eint_n)
Will this dereference the NULL pctl->eint pointer directly?
[Severity: High]
This isn't a bug introduced by this patch, but does the driver lack proper devres cleanup for the gpiochip?
In mtk_pctrl_init(), pctl->chip is allocated using devm_kzalloc() and then registered globally:
mtk_pctrl_init()
pctl->chip = devm_kzalloc(...)
gpiochip_add_data(pctl->chip, pctl)
Since gpiochip_add_data() does not use devres tracking, and the driver lacks a .remove callback or suppress_bind_attrs, unbinding the driver via sysfs will immediately free pctl->chip. Can this leave a dangling pointer in gpiolib, leading to a use-after-free?
[Severity: High]
This is also a pre-existing issue, but does the IRQ handler registration capture a devm-allocated pointer without devres tracked cleanup?
For MediaTek pinctrl devices that do initialize EINT, mtk_eint_do_init() registers the chained handler:
mtk_eint_do_init()
irq_set_chained_handler_and_data(eint->irq, mtk_eint_irq_handler, eint)
If the driver is unbound, the devm allocated eint structure will be freed. Does the lack of a cleanup function mean the subsystem could later trigger mtk_eint_irq_handler() with the freed eint pointer?
Quoted 8 lines
drivers/pinctrl/mediatek/pinctrl-mt6397.c +4
-1}static const struct of_device_id mt6397_pctrl_match[] = { - { .compatible ="mediatek,mt6397-pinctrl" , }, + { + .compatible ="mediatek,mt6392-pinctrl" , + .data = &mt6392_pinctrl_data + }, {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH v8 6/9] input: keyboard: mtk-pmic-keys: Add MT6392 support
In reply to Luca Leonardo ScorciaThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect reset bitmask used for MT6357 home key, causing register corruption. --
commit 1b3cefe34c0ab03bf79d61642de046924d4afa84
Author: Val Packett <[email protected]>
input: keyboard: mtk-pmic-keys: Add MT6392 support
Add support for the MT6392 PMIC to the keys driver.
Quoted 4 lines
drivers/input/keyboard/mtk-pmic-keys.c +0
-0
[ ... ]
drivers/input/keyboard/mtk-pmic-keys.c static const struct mtk_pmic_regs mt6397_regs = { · line 81
Quoted 13 lines
drivers/input/keyboard/mtk-pmic-keys.c +9
-0@@ -69,6 +70,19 @@ static const struct mtk_pmic_regs mt6397_regs = { .rst_lprst_mask = MTK_PMIC_RST_DU_MASK, }; +static const struct mtk_pmic_regs mt6392_regs = { + .keys_regs[MTK_PMIC_PWRKEY_INDEX ] = +MTK_PMIC_KEYS_REGS (MT6392_CHRSTATUS ,0x2 , +MT6392_INT_MISC_CON ,0x10 , +MTK_PMIC_PWRKEY_RST ), + .keys_regs[MTK_PMIC_HOMEKEY_INDEX ] = +MTK_PMIC_KEYS_REGS (MT6392_CHRSTATUS ,0x4 , +MT6392_INT_MISC_CON ,0x8 , +MTK_PMIC_HOMEKEY_RST ),
[Severity: High]
This is a pre-existing issue, but while reviewing these new register configurations I noticed a copy-paste typo in the mt6357_regs struct.
In mt6357_regs, the home key reset mask is initialized like this:
.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
MTK_PMIC_KEYS_REGS(MT6357_TOPSTATUS,
0x8, MT6357_PSC_TOP_INT_CON0, 0xa,
MTK_PMIC_HOMEKEY_INDEX),Does this incorrectly use the array index MTK_PMIC_HOMEKEY_INDEX instead of the reset bitmask MTK_PMIC_HOMEKEY_RST?
When mtk_pmic_keys_lp_reset_setup() is called during probe for an MT6357 device, wouldn't this inadvertently modify bit 0 of the MT6357_TOP_RST_MISC register instead of bit 5?
It looks like this might corrupt an unrelated control bit in the PMIC register state, while also failing to manage the long-press reset functionality for the home key.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH v8 9/9] arm64: dts: mediatek: Add MediaTek MT6392 PMIC dtsi
In reply to Luca Leonardo ScorciaThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The `pmic` node lacks an upstream `interrupts` or `interrupts-extended` property, causing the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The pmic node lacks an upstream interrupts or interrupts-extended property, causing the MT6397/MT6392 PMIC driver to fail probing. --
commit fc85085e7df96d6b701cb80ab653d3bbb4392af1
Author: Val Packett <[email protected]>
arm64: dts: mediatek: Add MediaTek MT6392 PMIC dtsi
Add the dtsi to be included by all boards using the MT6392 PMIC, providing support for regulator, keys, pinctrl and RTC. Import the new file in the shared device tree for the Pumpkin boards.
Quoted 6 lines
arch/arm64/boot/dts/mediatek/mt6392.dtsi new file +0
-0@@ -0,0 +1,148 @@
[ ... ]
Quoted 5 lines
+&pwrap {
arch/arm64/boot/dts/mediatek/mt6392.dtsi new file +4
-0+ pmic: pmic { + compatible = "mediatek,mt6392", "mediatek,mt6323"; + interrupt-controller; + #interrupt-cells = <2>;
[ ... ]
arch/arm64/boot/dts/mediatek/pumpkin-common.dtsi line 10
Quoted 10 lines
arch/arm64/boot/dts/mediatek/pumpkin-common.dtsi +2
-0@@ -6,6 +6,8 @@ #include <dt-bindings/gpio/gpio.h> +#include "mt6392.dtsi" +
[Severity: High]
Does this inclusion miss the board-specific interrupts definition for the PMIC?
The new mt6392.dtsi defines the pmic node but omits the interrupts property, as expected for a generic include. However, pumpkin-common.dtsi doesn't appear to override the &pmic node to provide the board-specific interrupt routing.
Since the MT6397 PMIC core driver aborts probing completely if it cannot find an interrupt via platform_get_irq(pdev, 0), will this cause the PMIC driver to fail probing, leaving all PMIC sub-devices unavailable?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
[email protected]
AI reviewRe: [PATCH v8 5/9] mfd: mt6397: Add support for MT6392 PMIC
In reply to Luca Leonardo ScorciaThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing unregister_pm_notifier() causes Use-After-Free of PM notifier block on probe error and driver unbind.
- [High] The IRQ domain is created with a hardcoded size of MT6397_IRQ_NR (32), which breaks PMICs like MT6328 that use a third interrupt register (hwirqs 32-47).
- [High] mt6397_irq_pm_notifier modifies IRQ mask registers concurrently with running tasks, causing race conditions.
--
commit 15d5fe2891c82970874377c126d0244fd87f5699
Author: Fabien Parent <[email protected]>
mfd: mt6397: Add support for MT6392 PMIC
Align the MT6397 PMIC driver to other MFD drivers by passing only an identifier through mt6397_of_match[*].data and add support for the MT6392 PMIC and its regulator, RTC, keys and pinctrl devices.
Quoted 4 lines
drivers/mfd/mt6397-core.c +0
-0
[ ... ]
Quoted 16 lines
drivers/mfd/mt6397-core.c +3
-2@@ -278,6 +311,7 @@ static int mt6397_probe(struct platform_device *pdev)unsigned int id =0 ;struct mt6397_chip *pmic;const struct chip_data *pmic_core; +int chip_variant; pmic =devm_kzalloc (&pdev->dev,sizeof (*pmic),GFP_KERNEL );if (!pmic)@@ -293,9 +327,36 @@ static int mt6397_probe(struct platform_device *pdev)if (!pmic->regmap)return -ENODEV ; - pmic_core =of_device_get_match_data (&pdev->dev); -if (!pmic_core) + chip_variant = (unsigned int )(uintptr_t )device_get_match_data (&pdev->dev); +switch (chip_variant) {
[ ... ]
drivers/mfd/mt6397-core.c static int mt6397_probe(struct platform_device *pdev) · line 352
Quoted 3 lines
drivers/mfd/mt6397-core.c +3
-0+case MT6392_CHIP_ID : + pmic_core = &mt6392_core; +break ;
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but looking at the error path of mt6397_probe() in drivers/mfd/mt6397-core.c:
ret = pmic_core->irq_init(pmic);
if (ret)
return ret;
ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
pmic_core->cells, pmic_core->cell_size,
NULL, 0, pmic->irq_domain);
if (ret) {
irq_domain_remove(pmic->irq_domain);
dev_err(&pdev->dev, "failed to add child devices: %d\n", ret);
}
return ret;Since mt6397_irq_init() registers a PM notifier with register_pm_notifier(), if devm_mfd_add_devices() fails (or when the driver is unbound), the devres cleanup will automatically free the pmic structure containing the pm_nb notifier block.
Because unregister_pm_notifier() is never called in this error path or in a remove callback, will this leave a dangling pointer in the PM subsystem that causes a Use-After-Free during the next suspend/resume cycle?
Quoted 4 lines
drivers/mfd/mt6397-irq.c +0
-0
[ ... ]
drivers/mfd/mt6397-irq.c int mt6397_irq_init(struct mt6397_chip *chip) · line 216
Quoted 13 lines
drivers/mfd/mt6397-irq.c +6
-0@@ -203,6 +205,12 @@ int mt6397_irq_init(struct mt6397_chip *chip) chip->int_status[0 ] =MT6397_INT_STATUS0 ; chip->int_status[1 ] =MT6397_INT_STATUS1 ;break ; +case MT6392_CHIP_ID : + chip->int_con[0 ] =MT6392_INT_CON0 ; + chip->int_con[1 ] =MT6392_INT_CON1 ; + chip->int_status[0 ] =MT6392_INT_STATUS0 ; + chip->int_status[1 ] =MT6392_INT_STATUS1 ; +break ;default :dev_err (chip->dev,"unsupported chip: 0x%x\n" , chip->chip_id);
[Severity: High]
This is a pre-existing issue, but further down in mt6397_irq_init() in drivers/mfd/mt6397-irq.c, the linear IRQ domain is allocated with a hardcoded size:
chip->irq_domain = irq_domain_create_linear(dev_fwnode(chip->dev), MT6397_IRQ_NR, &mt6397_irq_domain_ops, chip);
Since MT6397_IRQ_NR is 32, but PMICs like MT6328 use a third interrupt status register for hardware IRQs 32-47:
if (mt6397->int_status[2]) mt6397_irq_handle_reg(mt6397, mt6397->int_status[2], 32);
Won't irq_find_mapping() silently fail to find a mapping for any interrupts at index 32 or higher, breaking functionality for those higher-numbered interrupts?
[Severity: High]
This is also a pre-existing issue, but mt6397_irq_pm_notifier() in drivers/mfd/mt6397-irq.c writes directly to the PMIC's interrupt control registers without locking:
case PM_SUSPEND_PREPARE: regmap_write(chip->regmap, chip->int_con[0], chip->wake_mask[0]);
Because PM_SUSPEND_PREPARE runs before user tasks are frozen, running tasks can concurrently request or enable an IRQ. When this happens, mt6397_irq_sync_unlock() will acquire irqlock and write irq_masks_cur to the same registers:
regmap_write(mt6397->regmap, mt6397->int_con[0], mt6397->irq_masks_cur[0]);
Could this concurrent modification overwrite the suspend configuration established by the notifier, leading to lost wakeup sources or spurious interrupts?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Sashiko review of v8 pointed out some easy-to-fix but real issues. Please ignore this series as I have fixed them and I will send out v9.
Signature · 2 lines
Luca Leonardo Scorcia [email protected]