mfd: max8907: Schema, pdata and poweroff
Subsystems (3)
v2 cover mfd: max8907: Schema, pdata and poweroff
Convert existing txt documentation file to DF schema. Remove platform data use. Switch to device managed poweroff handler.
Schema includes reference to pending tegra-regulators-coupling
conversion. https://lore.kernel.org/lkml/[email protected]/
---
Changes in v2:
- fixed max8907_power_off return
---
Svyatoslav Ryhel (3):
regulator: dt-bindings: maxim,max8907: Convert to DT schema
mfd: max8907: Remove platform_data based probing
mfd: max8907: Convert to use device managed poweroff handler
.../devicetree/bindings/regulator/max8907.txt | 69 ----- .../bindings/regulator/maxim,max8907.yaml | 285 ++++++++++++++++++ drivers/mfd/max8907.c | 38 +-- drivers/regulator/max8907-regulator.c | 8 +- include/linux/mfd/max8907.h | 5 - 5 files changed, 309 insertions(+), 96 deletions(-) delete mode 100644 Documentation/devicetree/bindings/regulator/max8907.txt create mode 100644 Documentation/devicetree/bindings/regulator/maxim,max8907.yaml
Signature · 1 line
2.53.0
PATCH RESEND v2 1/3 regulator: dt-bindings: maxim,max8907: Convert to DT schema
Convert Maxim MAX8907 regulator binding from text to DT schema. Reference to nvidia,tegra-regulators-coupling in child regulator nodes.
--- .../devicetree/bindings/regulator/max8907.txt | 69 ----- .../bindings/regulator/maxim,max8907.yaml | 285 ++++++++++++++++++ 2 files changed, 285 insertions(+), 69 deletions(-) delete mode 100644 Documentation/devicetree/bindings/regulator/max8907.txt create mode 100644 Documentation/devicetree/bindings/regulator/maxim,max8907.yaml
Documentation/devicetree/bindings/regulator/max8907.txt deleted +0 -69
@@ -1,69 +0,0 @@ -MAX8907 regulator - -Required properties: -- compatible: "maxim,max8907" -- reg: I2C slave address -- interrupts: The interrupt output of the controller -- mbatt-supply: The input supply for MBATT, BBAT, SDBY, VRTC. -- in-v1-supply: The input supply for SD1. -- in-v2-supply: The input supply for SD2. -- in-v3-supply: The input supply for SD3. -- in1-supply: The input supply for LDO1. -... -- in20-supply: The input supply for LDO20. -- regulators: A node that houses a sub-node for each regulator within the - device. Each sub-node is identified using the node's name (or the deprecated - regulator-compatible property if present), with valid values listed below. - The content of each sub-node is defined by the standard binding for - regulators; see regulator.txt. - -Optional properties: -- maxim,system-power-controller: Boolean property indicating that the PMIC - controls the overall system power. - -The valid names for regulators are: - - sd1, sd2, sd3, ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8, ldo9, ldo10, - ldo11, ldo12, ldo13, ldo14, ldo15, ldo16, ldo17, ldo18, ldo19, ldo20, out5v, - out33v, bbat, sdby, vrtc. - -Example: - - max8907@3c { - compatible = "maxim,max8907"; - reg = <0x3c>; - interrupts = <0 86 0x4>; - - maxim,system-power-controller; - - mbatt-supply = <&some_reg>; - in-v1-supply = <&mbatt_reg>; - ... - in1-supply = <&mbatt_reg>; - ... - - regulators { - mbatt_reg: mbatt { - regulator-name = "vbat_pmu"; - regulator-min-microvolt = <5000000>; - regulator-max-microvolt = <5000000>; - regulator-always-on; - }; - - sd1 { - regulator-name = "nvvdd_sv1,vdd_cpu_pmu"; - regulator-min-microvolt = <1000000>; - regulator-max-microvolt = <1000000>; - regulator-always-on; - }; - - sd2 { - regulator-name = "nvvdd_sv2,vdd_core"; - regulator-min-microvolt = <1200000>; - regulator-max-microvolt = <1200000>; - regulator-always-on; - }; -... - }; - }; - };
Documentation/devicetree/bindings/regulator/maxim,max8907.yaml new file +285 -0
285 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 1/3 RESEND] regulator: dt-bindings: maxim,max8907: Convert to DT schema
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
Convert Maxim MAX8907 regulator binding from text to DT schema. Reference to nvidia,tegra-regulators-coupling in child regulator nodes.
Signed-off-by Svyatoslav Ryhel <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH RESEND v2 2/3 mfd: max8907: Remove platform_data based probing
In reply to Svyatoslav RyhelThere are no in-tree users of this driver, but it supports devicetree based probing, which means external dtb files may exist that work with this.
Remove the unused legacy code and make this a DT-only driver.
--- drivers/mfd/max8907.c | 8 +------- drivers/regulator/max8907-regulator.c | 8 +++----- include/linux/mfd/max8907.h | 5 ----- 3 files changed, 4 insertions(+), 17 deletions(-)
drivers/mfd/max8907.c +1 -7
@@ -184,13 +184,7 @@ static int max8907_i2c_probe(struct i2c_client *i2c) {struct max8907 *max8907;int ret; -struct max8907_platform_data *pdata =dev_get_platdata (&i2c->dev); -bool pm_off = false; - -if (pdata) - pm_off = pdata->pm_off; -else if (i2c->dev.of_node) - pm_off =of_property_read_bool (i2c->dev.of_node, +bool pm_off =of_property_read_bool (i2c->dev.of_node,"maxim,system-power-controller" ); max8907 =devm_kzalloc (&i2c->dev,sizeof (struct max8907 ),GFP_KERNEL );
drivers/regulator/max8907-regulator.c +3 -5
@@ -274,7 +274,6 @@ static inline struct device_node *match_of_node(int index)static int max8907_regulator_probe (struct platform_device *pdev) {struct max8907 *max8907 =dev_get_drvdata (pdev->dev.parent); -struct max8907_platform_data *pdata =dev_get_platdata (max8907->dev);int ret;struct max8907_regulator *pmic;unsigned int val;
@@ -312,10 +311,9 @@ static int max8907_regulator_probe(struct platform_device *pdev)struct regulator_dev *rdev; config.dev = pdev->dev.parent; -if (pdata) - idata = pdata->init_data[i]; -else - idata =match_init_data (i); + + idata =match_init_data (i); + config.init_data = idata; config.driver_data = pmic; config.regmap = max8907->regmap_gen;
include/linux/mfd/max8907.h +0 -5
@@ -227,11 +227,6 @@ enum { MAX8907_IRQ_RTC_ALARM0, }; -struct max8907_platform_data { -struct regulator_init_data *init_data[MAX8907_NUM_REGULATORS ]; -bool pm_off; -}; -struct regmap_irq_chips_data ;struct max8907 {
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 2/3 RESEND] mfd: max8907: Remove platform_data based probing
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] regulator: max8907: NULL pointer dereference if optional DT nodes are omitted --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] regulator: max8907: NULL pointer dereference if optional DT nodes are omitted --
commit 71b1062244be38a96a85d244d04303ea12b325fe
Author: Svyatoslav Ryhel <[email protected]>
mfd: max8907: Remove platform_data based probing
This patch removes legacy platform_data based probing for the max8907 driver, converting it to be strictly device tree based.
Quoted 4 lines
drivers/regulator/max8907-regulator.c +0
-0
[ ... ]
drivers/regulator/max8907-regulator.c static int max8907_regulator_probe(struct platform_device *pdev) · line 316
Quoted 11 lines
drivers/regulator/max8907-regulator.c +3
-4@@ -312,10 +311,9 @@ static int max8907_regulator_probe(struct platform_device *pdev)struct regulator_dev *rdev; config.dev = pdev->dev.parent; -if (pdata) - idata = pdata->init_data[i]; -else - idata =match_init_data (i); + + idata =match_init_data (i); +
[Severity: High]
Will this cause a NULL pointer dereference if optional regulator nodes are omitted from the device tree?
Since the patch removes the platform_data fallback, the driver now relies entirely on match_init_data(i). If a system omits the nodes for MAX8907_BBAT, MAX8907_SDBY, or MAX8907_VRTC, match_init_data() will return NULL.
Looking at max8907_regulator_probe() just below this change, idata is unconditionally dereferenced for these specific regulators:
drivers/regulator/max8907-regulator.c:max8907_regulator_probe() {
...
switch (pmic->desc[i].id) {
...
case MAX8907_BBAT:
case MAX8907_SDBY:
case MAX8907_VRTC:
idata->supply_regulator = mbatt_rail_name;
break;
}
...
}Could we add a NULL check for idata before dereferencing it here?
Quoted 3 lines
drivers/regulator/max8907-regulator.c +0
-0config.init_data = idata; config.driver_data = pmic; config.regmap = max8907->regmap_gen;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH RESEND v2 3/3 mfd: max8907: Convert to use device managed poweroff handler
In reply to Svyatoslav RyhelReplace the legacy global 'pm_power_off' function pointer assignment with the devm_register_sys_off_handler() helper.
--- drivers/mfd/max8907.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/mfd/max8907.c +21 -11
@@ -15,6 +15,7 @@#include <linux/mfd/max8907.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/reboot.h> #include <linux/regmap.h> #include <linux/slab.h>
@@ -173,19 +174,23 @@ static const struct regmap_irq_chip max8907_rtc_irq_chip = { .num_irqs = ARRAY_SIZE(max8907_rtc_irqs), }; -static struct max8907 *max8907_pm_off; -static void max8907_power_off (void ) +static int max8907_power_off (struct sys_off_data *data) { -regmap_update_bits (max8907_pm_off->regmap_gen,MAX8907_REG_RESET_CNFG , -MAX8907_MASK_POWER_OFF ,MAX8907_MASK_POWER_OFF ); +struct max8907 *max8907 = data->cb_data; +int ret; + + ret =regmap_update_bits (max8907->regmap_gen,MAX8907_REG_RESET_CNFG , +MAX8907_MASK_POWER_OFF ,MAX8907_MASK_POWER_OFF ); +if (ret) +dev_err (max8907->dev,"failed to restart device!\n" ); + +return NOTIFY_DONE ; }static int max8907_i2c_probe (struct i2c_client *i2c) {struct max8907 *max8907;int ret; -bool pm_off =of_property_read_bool (i2c->dev.of_node, -"maxim,system-power-controller" ); max8907 =devm_kzalloc (&i2c->dev,sizeof (struct max8907 ),GFP_KERNEL );if (!max8907) {
@@ -204,6 +209,16 @@ static int max8907_i2c_probe(struct i2c_client *i2c) goto err_regmap_gen; } +if (device_property_read_bool (&i2c->dev,"system-power-controller" ) || +device_property_read_bool (&i2c->dev,"maxim,system-power-controller" )) { + ret =devm_register_sys_off_handler (&i2c->dev,SYS_OFF_MODE_POWER_OFF , +SYS_OFF_PRIO_DEFAULT , + &max8907_power_off, max8907); +if (ret) +return dev_err_probe (&i2c->dev, ret, +"failed to register poweroff handler\n" ); + } + max8907->i2c_rtc =i2c_new_dummy_device (i2c->adapter,MAX8907_RTC_I2C_ADDR );if (IS_ERR (max8907->i2c_rtc)) { ret =PTR_ERR (max8907->i2c_rtc);
@@ -250,11 +265,6 @@ static int max8907_i2c_probe(struct i2c_client *i2c) goto err_add_devices; } -if (pm_off && !pm_power_off) { - max8907_pm_off = max8907; - pm_power_off = max8907_power_off; - } -return 0 ; err_add_devices:
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 3/3 RESEND] mfd: max8907: Convert to use device managed poweroff handler
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] mfd: max8907: regmap mutex deadlock and sleep in atomic power-off - [Low] mfd: max8907: missing…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mfd: max8907: regmap mutex deadlock and sleep in atomic power-off
- [Low] mfd: max8907: missing <linux/property.h> for device_property_read_bool()
- [Low] mfd: max8907: misleading error message in power-off handler
--
commit 5506b550cb60d6cb6be8b862f1268bdb1e810f08
Author: Svyatoslav Ryhel <[email protected]>
mfd: max8907: Convert to use device managed poweroff handler
Replace the legacy global 'pm_power_off' function pointer assignment with the devm_register_sys_off_handler() helper.
Quoted 4 lines
drivers/mfd/max8907.c +0
-0
[ ... ]
drivers/mfd/max8907.c static const struct regmap_irq_chip max8907_rtc_irq_chip = { · line 183
Quoted 11 lines
drivers/mfd/max8907.c +6
-4-static struct max8907 *max8907_pm_off; -static void max8907_power_off (void ) +static int max8907_power_off (struct sys_off_data *data) { -regmap_update_bits (max8907_pm_off->regmap_gen,MAX8907_REG_RESET_CNFG , -MAX8907_MASK_POWER_OFF ,MAX8907_MASK_POWER_OFF ); +struct max8907 *max8907 = data->cb_data; +int ret; + + ret =regmap_update_bits (max8907->regmap_gen,MAX8907_REG_RESET_CNFG , +MAX8907_MASK_POWER_OFF ,MAX8907_MASK_POWER_OFF );
[Severity: High]
Does this code risk a deadlock or sleep in an atomic context?
The handler max8907_power_off() is registered with SYS_OFF_MODE_POWER_OFF. This means it will be called via an atomic notifier chain during system shutdown, after machine_power_off() stops CPUs and disables interrupts. However, regmap_update_bits() acquires a mutex and invokes I2C transfers that can sleep.
Should this use SYS_OFF_MODE_POWER_OFF_PREPARE instead? That mode uses a blocking notifier chain and runs in process context before CPUs are stopped.
drivers/mfd/max8907.c static const struct regmap_irq_chip max8907_rtc_irq_chip = { · line 185
Quoted 2 lines
drivers/mfd/max8907.c +2
-0+if (ret) +dev_err (max8907->dev,"failed to restart device!\n" );
[Severity: Low]
Is this error message accurate?
This error path logs a failure to "restart device", but max8907_power_off() is explicitly used for powering off the device, not restarting it.
Quoted 8 lines
drivers/mfd/max8907.c +2
-0+ +return NOTIFY_DONE ; }static int max8907_i2c_probe (struct i2c_client *i2c) {struct max8907 *max8907;int ret;
[ ... ]
drivers/mfd/max8907.c static int max8907_i2c_probe(struct i2c_client *i2c) · line 213
Quoted 6 lines
drivers/mfd/max8907.c +2
-0@@ -204,6 +209,16 @@ static int max8907_i2c_probe(struct i2c_client *i2c) goto err_regmap_gen; } +if (device_property_read_bool (&i2c->dev,"system-power-controller" ) || +device_property_read_bool (&i2c->dev,"maxim,system-power-controller" )) {
[Severity: Low]
Could this lead to a build failure due to a missing header?
The patch replaces of_property_read_bool() with device_property_read_bool() in max8907_i2c_probe(). The new function is defined in <linux/property.h>, but that header is not explicitly included in this file. Relying on implicit transitive headers might break builds on some architectures or configurations.
Quoted 7 lines
drivers/mfd/max8907.c +7
-0+ ret =devm_register_sys_off_handler (&i2c->dev,SYS_OFF_MODE_POWER_OFF , +SYS_OFF_PRIO_DEFAULT , + &max8907_power_off, max8907); +if (ret) +return dev_err_probe (&i2c->dev, ret, +"failed to register poweroff handler\n" ); + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3