Add support for MAX77675 device
Subsystems (2)
v5 cover Add support for MAX77675 device
From: Joan Na <[email protected]>
MAX77675 regulator driver and device tree bindings
---
Changes in v5:
- Fix subject prefix order to match subsystem ('regulator: dt-bindings: ...')
- Drop unnecessary '|' from description fields
- Drop repeated constraint descriptions from YAML
- Rename 'maxim,en-debounce-time-us' to 'maxim,debounce-delay-us' for clearer naming
- Used common 'reset-time-sec' property from input.yaml
- Remove duplicate description for 'maxim,fps-slot' and wrap lines to 80 chars
- Drop the node reference immediately after registering the regulator
Changes in v4:
- Remove the 'maxim,max77675-regulator.h' file as it is no longer used for bindings
- Eliminate unnecessary '|' characters where they are not needed
- Add and modify code to drop references that are no longer used
- Remove dead code
- Add detailed descriptions for each mode of 'maxim,en-mode'
- Rename 'maxim,latency-mode' to 'maxim,voltage-change-latency-us' for clearer meaning
- Update max77675_parse_latency_mode function to max77675_parse_voltage_change_latency accordingly
- Fix errors detected by running make dt_binding_check
- Fix incorrect indentation in the YAML file
Changes in v3:
- Removed unused variable 'value'
- Removed duplicate .list_voltage initializer
- Wrapped of_match_table with of_match_ptr() to fix build failure when CONFIG_OF is not set
- Updated driver code to match new DT binding schema
- Changed regmap_config from REGCACHE_NONE to REGCACHE_MAPLE for improved performance
- Added volatile_reg() to mark status registers as non-cacheable
- Missing explanation of maxim,fps-slot default value
- Updated DT binding enums to use string values (e.g., "low", "high") instead of integers
- Converted several binary properties to boolean typei
- Renamed time-based properties to use standard unit suffixes (e.g., "-sec", "-us")
- Added default values for properties
- Removed unused macros
- Renamed macros for clarity
Changes in v2:
- Fixed build error due to missing 'max77675_of_match' declaration
- Removed duplicate '.list_voltage' initialization
- Corrected value usage in regmap_update_bits call
- Added CONFIG_OF guards and used of_match_ptr()
---
Joan Na (2):
regulator: dt-bindings: Add MAX77675 regulator binding
regulator: max77675: Add MAX77675 regulator driver
.../bindings/regulator/maxim,max77675.yaml | 186 ++++ drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/max77675-regulator.c | 861 ++++++++++++++++++ drivers/regulator/max77675-regulator.h | 260 ++++++ 5 files changed, 1317 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/maxim,max77675.yaml create mode 100644 drivers/regulator/max77675-regulator.c create mode 100644 drivers/regulator/max77675-regulator.h
base-commit: 6548d364a3e850326831799d7e3ea2d7bb97ba08 --
2.34.1
PATCH v5 1/2 regulator: dt-bindings: Add MAX77675 regulator binding
From: Joan Na <[email protected]>
Add device tree binding YAML schema for the Maxim MAX77675 PMIC regulator. This defines the node properties and supported regulator names for use in device tree sources.
--- .../bindings/regulator/maxim,max77675.yaml | 186 ++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/maxim,max77675.yaml
Documentation/devicetree/bindings/regulator/maxim,max77675.yaml new file +186 -0
@@ -0,0 +1,186 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/maxim,max77675.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim MAX77675 PMIC Regulator + +maintainers: + - Joan Na <[email protected]> + +description: + The MAX77675 is a Power Management IC providing four switching buck + regulators (SBB0–SBB3) accessible via I2C. It supports configuration + of output voltages and enable controls for each regulator. + +allOf: + - $ref: /schemas/input/input.yaml + +properties: + compatible: + const: maxim,max77675 + + reg: + maxItems: 1 + + reset-time-sec: + description: Manual reset time in seconds + enum: [4, 8, 12, 16] + default: 4 + + maxim,en-mode: + description: | + Enable mode configuration. + The debounce time set by 'maxim,debounce-time-us' applies to + both push-button and slide-switch modes. + "push-button" - A long press triggers power-on or power-down + "slide-switch" - Low level powers on, high level powers down + "logic" - Low level powers on, high level powers down (no debounce time) + $ref: /schemas/types.yaml#/definitions/string + enum: [push-button, slide-switch, logic] + default: slide-switch + + maxim,voltage-change-latency-us: + description: + Specifies the delay (in microseconds) between an output voltage change request + and the start of the SBB voltage ramp. + enum: [10, 100] + default: 100 + + maxim,drv-sbb-strength: + description: | + SIMO Buck-Boost Drive Strength Trim. + Controls the drive strength of the SIMO regulator's power MOSFETs. + This setting affects the switching speed, which impacts power efficiency and EMI. + "max" – Maximum drive strength (~0.6 ns transition time) + "high" – High drive strength (~1.2 ns transition time) + "low" – Low drive strength (~1.8 ns transition time) + "min" – Minimum drive strength (~8 ns transition time) + $ref: /schemas/types.yaml#/definitions/string + enum: [max, high, low, min] + default: max + + maxim,dvs-slew-rate-mv-per-us: + description: + Dynamic rising slew rate for output voltage transitions, in mV/μs. + This setting is only used when 'maxim,fixed-slew-rate' is not present. + enum: [5, 10] + default: 5 + + maxim,debounce-time-us: + description: Debounce time for the enable pin, in microseconds + enum: [100, 30000] + default: 100 + + maxim,en-pullup-disable: + type: boolean + description: Disable internal pull-up for EN pin + default: false + + maxim,bias-low-power-request: + type: boolean + description: Request low-power bias mode + default: false + + maxim,simo-int-ldo-always-on: + type: boolean + description: Set internal LDO to always supply 1.8V + default: false + + regulators: + type: object + description: Regulator child nodes + patternProperties: + "^sbb[0-3]$": + type: object + $ref: regulator.yaml# + properties: + maxim,fps-slot: + description: | + FPS (Flexible Power Sequencer) slot selection. + The Flexible Power Sequencer allows resources to power up under + hardware or software control. Additionally, each resource can + power up independently or among a group of other regulators with + adjustable power-up and power-down slots. + "slot0" - Assign to FPS Slot 0 + "slot1" - Assign to FPS Slot 1 + "slot2" - Assign to FPS Slot 2 + "slot3" - Assign to FPS Slot 3 + "default" - Use the default FPS slot value stored in OTP and read from the register + $ref: /schemas/types.yaml#/definitions/string + enum: [slot0, slot1, slot2, slot3, default] + default: default + + maxim,fixed-slew-rate: + type: boolean + description: + When this property is present, the device uses a constant 2 mV/μs + slew rate and ignores any dynamic slew rate configuration. + When absent, the device uses the dynamic slew rate specified + by 'maxim,dvs-slew-rate-mv-per-us' + default: true + + unevaluatedProperties: false + +required: + - compatible + - reg + - regulators + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + max77675: pmic@44 { + compatible = "maxim,max77675"; + reg = <0x44>; + + reset-time-sec = <4>; + + maxim,en-mode = "slide-switch"; + maxim,voltage-change-latency-us = <100>; + maxim,drv-sbb-strength = "max"; + maxim,dvs-slew-rate-mv-per-us = <5>; + maxim,debounce-time-us = <100>; + + regulators { + sbb0: sbb0 { + regulator-name = "sbb0"; + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <5500000>; + maxim,fps-slot = "default"; + maxim,fixed-slew-rate; + }; + + sbb1: sbb1 { + regulator-name = "sbb1"; + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <5500000>; + maxim,fps-slot = "default"; + maxim,fixed-slew-rate; + }; + + sbb2: sbb2 { + regulator-name = "sbb2"; + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <5500000>; + maxim,fps-slot = "default"; + maxim,fixed-slew-rate; + }; + + sbb3: sbb3 { + regulator-name = "sbb3"; + regulator-min-microvolt = <500000>; + regulator-max-microvolt = <5500000>; + maxim,fps-slot = "default"; + maxim,fixed-slew-rate; + }; + }; + }; + }; +
--
2.34.1
Re: [PATCH v5 1/2] regulator: dt-bindings: Add MAX77675 regulator binding
Quoted 5 lines · Joan-Na-adi
From: Joan Na <[email protected]>
Add device tree binding YAML schema for the Maxim MAX77675 PMIC regulator. This defines the node properties and supported regulator names for use in device tree sources.
My comments form v3 were still not applied. I pointed out this at v4.
You still did not reply to comments. Did not implement them, either.
<form letter>
This is a friendly reminder during the review process.
It seems my or other reviewer's previous comments were not fully addressed. Maybe the feedback got lost between the quotes, maybe you just forgot to apply it. Please go back to the previous discussion and either implement all requested changes or keep discussing them.
Thank you.
</form letter>
Best regards,
Krzysztof
Re: [PATCH v5 1/2] regulator: dt-bindings: Add MAX77675 regulator binding
Quoted 19 lines · Krzysztof Kozlowski
Quoted 5 lines · Joan-Na-adi
From: Joan Na <[email protected]>
Add device tree binding YAML schema for the Maxim MAX77675 PMIC regulator. This defines the node properties and supported regulator names for use in device tree sources.
My comments form v3 were still not applied. I pointed out this at v4.
You still did not reply to comments. Did not implement them, either.
<form letter>
This is a friendly reminder during the review process.It seems my or other reviewer's previous comments were not fully addressed. Maybe the feedback got lost between the quotes, maybe you just forgot to apply it. Please go back to the previous discussion and either implement all requested changes or keep discussing them.
Quoted 6 lines
Thank you.
</form letter>Best regards,
Krzysztof
Thank you for pointing this out. I apologize for missing your comments from v3 and v4. I’ll make sure to review them carefully and address each point in the next update. I appreciate your patience.
Signature · 2 lines
Best regards, Joan Na
PATCH v5 2/2 regulator: max77675: Add MAX77675 regulator driver
In reply to Joan-Na-adiFrom: Joan Na <[email protected]>
Add support for the Maxim Integrated MAX77675 PMIC regulator.
The MAX77675 is a compact, highly efficient SIMO (Single Inductor Multiple Output) power management IC that provides four programmable buck-boost switching regulators with only one inductor. It supports up to 700mA total output current and operates from a single-cell Li-ion battery.
An integrated power-up sequencer and I2C interface allow flexible startup configuration and runtime control.
--- drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/max77675-regulator.c | 861 +++++++++++++++++++++++++ drivers/regulator/max77675-regulator.h | 260 ++++++++ 4 files changed, 1131 insertions(+) create mode 100644 drivers/regulator/max77675-regulator.c create mode 100644 drivers/regulator/max77675-regulator.h
drivers/regulator/Kconfig +9 -0
@@ -649,6 +649,15 @@ config REGULATOR_MAX77650 Semiconductor. This device has a SIMO with three independent power rails and an LDO. +config REGULATOR_MAX77675 + tristate "Maxim MAX77675 regulator driver" + depends on I2C + select REGMAP_I2C + help + This driver controls the Maxim MAX77675 power regulator via I2C. + It supports four programmable buck-boost outputs. + Say Y here to enable the regulator driver + config REGULATOR_MAX77857 tristate "ADI MAX77857/MAX77831 regulator support" depends on I2C
drivers/regulator/Makefile +1 -0
@@ -78,6 +78,7 @@ obj-$(CONFIG_REGULATOR_MAX77503) += max77503-regulator.o obj-$(CONFIG_REGULATOR_MAX77541) += max77541-regulator.o obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o +obj-$(CONFIG_REGULATOR_MAX77675) += max77675-regulator.o obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o obj-$(CONFIG_REGULATOR_MAX8893) += max8893.o
drivers/regulator/max77675-regulator.c new file +861 -0
861 lines not on this page · raw message
drivers/regulator/max77675-regulator.h new file +260 -0
260 lines not on this page · raw message
--
2.34.1
Re: [PATCH v5 2/2] regulator: max77675: Add MAX77675 regulator driver
Quoted 9 lines · Joan-Na-adi
From: Joan Na <[email protected]>
Add support for the Maxim Integrated MAX77675 PMIC regulator.
The MAX77675 is a compact, highly efficient SIMO (Single Inductor Multiple Output) power management IC that provides four programmable buck-boost switching regulators with only one inductor. It supports up to 700mA total output current and operates from a single-cell Li-ion battery.
Quoted 5 lines
An integrated power-up sequencer and I2C interface allow flexible startup configuration and runtime control.
Signed-off-by Joan Na <[email protected]>---
Hi Joan,
Some comments from me...
Quoted 16 lines
drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 +
drivers/regulator/max77675-regulator.c| 861 +++++++++++++++++++++++++drivers/regulator/max77675-regulator.h| 260 ++++++++4 files changed, 1131 insertions(+)create mode 100644
drivers/regulator/max77675-regulator.ccreate mode 100644drivers/regulator/max77675-regulator.hdrivers/regulator/Kconfig +0
-0@@ -649,6 +649,15 @@ config REGULATOR_MAX77650Semiconductor. This device has a SIMO with three independent power rails and an LDO.
drivers/regulator/Kconfig config REGULATOR_MAX77650 · line 654
Quoted 3 lines
drivers/regulator/Kconfig +3
-0+config REGULATOR_MAX77675 + tristate "Maxim MAX77675 regulator driver" + depends on I2C
Looking at your code, I would expected OF to be a dependency as well.
Quoted 33 lines
drivers/regulator/Kconfig +6
-0+ select REGMAP_I2C + help + This driver controls the Maxim MAX77675 power regulator via I2C. + It supports four programmable buck-boost outputs. + Say Y here to enable the regulator driver +config
REGULATOR_MAX77857
tristate "ADI MAX77857/MAX77831 regulator support" depends on I2Cdrivers/regulator/Makefile +0
-0@@ -78,6 +78,7 @@ obj-$(CONFIG_REGULATOR_MAX77503) += max77503-regulator.oobj-$(CONFIG_REGULATOR_MAX77541) += max77541-regulator.o obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o +obj-$(CONFIG_REGULATOR_MAX77675) += max77675-regulator.o
obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o obj-$(CONFIG_REGULATOR_MAX8893) += max8893.odrivers/regulator/max77675-regulator.c new file +6
-0@@ -0,0 +1,861 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2025 Analog Devices, Inc. +* ADI regulator driver for MAX77675. +*/ +
drivers/regulator/max77675-regulator.c line 16
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+#include <linux/module.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/i2c.h> +#include <linux/regmap.h> +#include <linux/platform_device.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/consumer.h> +#include <linux/regulator/of_regulator.h> +#include <linux/bitfield.h>
You're clearly missing (at least) mod_devicetable.h. I know that at least clang allows you to get iwyu,
drivers/regulator/max77675-regulator.c line 18
Quoted 2 lines
drivers/regulator/max77675-regulator.c new file +2
-0+ +#include "max77675-regulator.h"
Why do we need the header file? Just include everything in the source code unless you expect to share something with another module (which I dunno)?
drivers/regulator/max77675-regulator.c line 24
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +struct max77675_regulator_pdata { + u8 fps_slot; +bool fixed_slew_rate; +}; +
I would get rid of the _pdata suffix. Implies some legacy way of doing things (but kind of a nitpick)
Quoted 22 lines
drivers/regulator/max77675-regulator.c new file +22
-0+struct max77675_config { + u8 en_mode; + u8 voltage_change_latency; + u8 drv_sbb_strength; + u8 dvs_slew_rate; + u8 debounce_time; + u8 manual_reset_time; +bool en_pullup_disable; +bool bias_low_power_request; +bool simo_int_ldo_always_on; +}; + +struct max77675_regulator { +struct device *dev; +struct regmap *regmap; +struct max77675_config config; +struct max77675_regulator_pdata pdata[MAX77675_ID_NUM_MAX ]; +}; + +/** +* Set latency mode. +*
drivers/regulator/max77675-regulator.c line 56
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+* @param maxreg Pointer to max77675 device structure. +* @param enable true to enable latency mode, false to disable. +*/ +static int max77675_set_latency_mode (struct max77675_regulator *maxreg,bool enable) +{ +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_SBB_TOP_B , + MAX77675_LAT_MODE_BIT, + FIELD_PREP(MAX77675_LAT_MODE_BIT, enable)); +} +
I would drop these one liner wrappers. Personally, I don't see a big benefit on it.
drivers/regulator/max77675-regulator.c line 69
Quoted 13 lines
drivers/regulator/max77675-regulator.c new file +13
-0+/** +* Set DVS slew rate mode. +* +* @param maxreg Pointer to max77675 device structure. +* @param enable true to use DVS-controlled slew rate, false for fixed 2mV/us. +*/ +static int max77675_set_dvs_slew_rate (struct max77675_regulator *maxreg,bool enable) +{ +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_SBB_TOP_B , + MAX77675_DVS_SLEW_BIT, + FIELD_PREP(MAX77675_DVS_SLEW_BIT, enable)); +} +
Ditto for all other places.
...
Quoted 37 lines
drivers/regulator/max77675-regulator.c new file +36
-0+ +/** +* Set debounce time for EN pin. +* +* @param maxreg Pointer to max77675 device structure. +* @param debounce_30ms true for 30ms, false for 100us +*/ +static int max77675_set_debounce_time (struct max77675_regulator *maxreg,bool debounce_30ms) +{ +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_GLBL_A , + MAX77675_DBEN_EN_BIT, + FIELD_PREP(MAX77675_DBEN_EN_BIT, debounce_30ms)); +} + +static int max77675_regulator_get_fps_src (struct max77675_regulator *maxreg,int id) +{ +unsigned int reg_addr; +unsigned int val; +int ret; + +switch (id) { +case MAX77675_ID_SBB0 : + reg_addr =MAX77675_REG_CNFG_SBB0_B ; +break ; +case MAX77675_ID_SBB1 : + reg_addr =MAX77675_REG_CNFG_SBB1_B ; +break ; +case MAX77675_ID_SBB2 : + reg_addr =MAX77675_REG_CNFG_SBB2_B ; +break ; +case MAX77675_ID_SBB3 : + reg_addr =MAX77675_REG_CNFG_SBB3_B ; +break ; +default : +dev_err (maxreg->dev,"Invalid regulator id: %d\n" , id); +return -EINVAL ;
drivers/regulator/max77675-regulator.c line 194
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ } + + ret =regmap_read (maxreg->regmap, reg_addr, &val); +if (ret <0 ) { +dev_err (maxreg->dev,"Failed to read FPS source (reg 0x%02x): %d\n" , + reg_addr, ret); +return ret; + } + +return val &MAX77675_EN_SBB_MASK ;
Ok, this works since the mask is 0x7. However, FIELD_GET() would make it more readable and easy to review. I mean, I would not need to go and see the mask value.
Quoted 22 lines
drivers/regulator/max77675-regulator.c new file +22
-0+} + +static int max77675_regulator_set_fps_src (struct max77675_regulator *maxreg,int id,u8 fps_src) +{ +unsigned int reg_addr; +int ret; + +switch (id) { +case MAX77675_ID_SBB0 : + reg_addr =MAX77675_REG_CNFG_SBB0_B ; +break ; +case MAX77675_ID_SBB1 : + reg_addr =MAX77675_REG_CNFG_SBB1_B ; +break ; +case MAX77675_ID_SBB2 : + reg_addr =MAX77675_REG_CNFG_SBB2_B ; +break ; +case MAX77675_ID_SBB3 : + reg_addr =MAX77675_REG_CNFG_SBB3_B ; +break ; +default : +dev_err (maxreg->dev,"Invalid regulator id: %d\n" , id);
drivers/regulator/max77675-regulator.c line 226
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+return -EINVAL ; + } + + ret =regmap_update_bits (maxreg->regmap, reg_addr, +MAX77675_EN_SBB_MASK , fps_src); +if (ret <0 ) { +dev_err (maxreg->dev,"Failed to set FPS source (reg 0x%02x): %d\n" , + reg_addr, ret); +return ret; + }
I would drop the log and just do return regmap_update_bits(). Up to you...
Quoted 61 lines
drivers/regulator/max77675-regulator.c new file +17
-0+ +return 0 ; +} + +/** +* max77675_set_sbb_slew_rate_fixed - Set the slew rate for a specific SBB regulator channel +* +* @maxreg: Pointer to the max77675 regulator structure +* @id: Regulator channel ID (ID_SBB0 ~ ID_SBB3) +* @fixed: Slew rate value (true = 2mV/us, false = use DVS_SLEW) +* +* This function configures the slew rate control source for the specified SBB channel by +* updating the corresponding bits in the CNFG_SBB_TOP_B register. +* +* Return: 0 on success, negative error code on failure (e.g., invalid channel ID). +*/ +static int max77675_set_sbb_slew_rate_fixed(struct max77675_regulator *maxreg, int id, boolfixed)
drivers/regulator/max77675-regulator.c new file +43
-0+{ +u8 mask, value; +u8 slew_src_ctrl_bit = fixed ?0 :1 ; + +switch (id) { +case MAX77675_ID_SBB0 : + mask =MAX77675_SR_SBB0_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB0_BIT , slew_src_ctrl_bit); +break ; + +case MAX77675_ID_SBB1 : + mask =MAX77675_SR_SBB1_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB1_BIT , slew_src_ctrl_bit); +break ; + +case MAX77675_ID_SBB2 : + mask =MAX77675_SR_SBB2_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB2_BIT , slew_src_ctrl_bit); +break ; + +case MAX77675_ID_SBB3 : + mask =MAX77675_SR_SBB3_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB3_BIT , slew_src_ctrl_bit); +break ; + +default : +return -EINVAL ; + } + +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_SBB_TOP_B , mask, value); +} + +static int max77675_init_regulator (struct max77675_regulator *maxreg,int id) +{ +struct max77675_regulator_pdata *rpdata = &maxreg->pdata[id]; +int ret; + +if (rpdata->fps_slot ==MAX77675_FPS_DEF ) { + ret =max77675_regulator_get_fps_src (maxreg, id); +if (ret <0 ) { +dev_err (maxreg->dev,"Failed to read FPS source for ID %d\n" , id); +return ret; + }
drivers/regulator/max77675-regulator.c line 296
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ rpdata->fps_slot = ret; + }else { + ret =max77675_regulator_set_fps_src (maxreg, id, rpdata->fps_slot); +if (ret) +dev_warn (maxreg->dev,"Failed to set FPS source for ID %d\n" , id); + } + + ret =max77675_set_sbb_slew_rate_fixed (maxreg, id, rpdata->fixed_slew_rate); +if (ret) +dev_warn (maxreg->dev,"Failed to set slew rate for ID %d\n" , id);
Do we really want to treat this as a warning (as FPS)? If so, I would expect a proper comment explaining why we can afford it.
Quoted 7 lines
drivers/regulator/max77675-regulator.c new file +7
-0+ +return 0 ; +} + +static int max77675_of_parse_cb (struct device_node *np, +const struct regulator_desc *desc, +struct regulator_config *config)
drivers/regulator/max77675-regulator.c line 313
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+{ +struct max77675_regulator *maxreg = config->driver_data; +struct max77675_regulator_pdata *rpdata = &maxreg->pdata[desc->id]; +u32 pval; +int ret; + +/* Parse FPS slot from DT */ + ret =of_property_read_u32 (np,"maxim,fps-slot" , &pval); + rpdata->fps_slot = (!ret) ? (u8 )pval :MAX77675_FPS_DEF ; +
So, can we get any arbitrary value for pval? I see we you have an enum in the bindings so make sure we properly validate it. Same for all other properties. The bindings also have this as a string and here you have a u32? Not going to work. You need of_property_read_string() + match_string().
Also, "maxim,"? For some time now it's "adi,".
Quoted 32 lines
drivers/regulator/max77675-regulator.c new file +32
-0+/* Parse slew rate control source */ + rpdata->fixed_slew_rate =of_property_read_bool (np,"maxim,fixed-slew-rate" ); + +/* Apply parsed configuration */ +return max77675_init_regulator (maxreg, desc->id); +} + +static int max77675_get_error_flags (struct regulator_dev *rdev,unsigned int *flags) +{ +struct max77675_regulator *maxreg =rdev_get_drvdata (rdev); +unsigned int int_flags; +int id =rdev_get_id (rdev); +int ret; + + ret =regmap_read (maxreg->regmap,MAX77675_REG_INT_GLBL , &int_flags); +if (ret) { +dev_err (maxreg->dev,"Failed to read INT_GLBL: %d\n" , ret); +return ret; + } + + *flags =0 ; + +switch (id) { +case MAX77675_ID_SBB0 : +if (int_flags &MAX77675_INT_SBB0_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +case MAX77675_ID_SBB1 : +if (int_flags &MAX77675_INT_SBB1_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +case MAX77675_ID_SBB2 :
drivers/regulator/max77675-regulator.c line 355
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+if (int_flags &MAX77675_INT_SBB2_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +case MAX77675_ID_SBB3 : +if (int_flags &MAX77675_INT_SBB3_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +default : +dev_warn (maxreg->dev,"Unsupported regulator ID: %d\n" , id); +break ;
Should not be a warning. Also wonder if it can happen at all?
Quoted 17 lines
drivers/regulator/max77675-regulator.c new file +17
-0+ } + +if (int_flags &MAX77675_INT_TJAL2_R_BIT ) { +/* TJAL2 interrupt: Over-temperature condition (above 120 degree) */ + *flags |=REGULATOR_ERROR_OVER_TEMP ; + } + +return 0 ; +} + +static const struct regulator_ops max77675_regulator_ops = { + .list_voltage = regulator_list_voltage_linear, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .map_voltage = regulator_map_voltage_linear, + .set_voltage_sel = regulator_set_voltage_sel_regmap,
drivers/regulator/max77675-regulator.c line 382
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_active_discharge = regulator_set_active_discharge_regmap, + .get_error_flags = max77675_get_error_flags, +}; + +static struct regulator_desc max77675_regulators[MAX77675_ID_NUM_MAX ] = { + { + .name = "sbb0", + .of_match = of_match_ptr("sbb0"), + .regulators_node = of_match_ptr("regulators"),
I wonder if we need of_match_ptr() given that the whole thing depends on OF.
...
Quoted 49 lines
drivers/regulator/max77675-regulator.c new file +49
-0+ +static int max77675_apply_config (struct max77675_regulator *maxreg) +{ +const struct max77675_config *config = &maxreg->config; +int ret; + + ret =max77675_set_en_mode (maxreg, config->en_mode); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN mode: %d\n" , ret); +return ret; + } + + ret =max77675_set_latency_mode (maxreg, config->voltage_change_latency); +if (ret) { +dev_err (maxreg->dev,"Failed to set latency mode: %d\n" , ret); +return ret; + } + + ret =max77675_set_drv_sbb_strength (maxreg, config->drv_sbb_strength); +if (ret) { +dev_err (maxreg->dev,"Failed to set drive strength: %d\n" , ret); +return ret; + } + + ret =max77675_set_dvs_slew_rate (maxreg, config->dvs_slew_rate); +if (ret) { +dev_err (maxreg->dev,"Failed to set DVS slew rate: %d\n" , ret); +return ret; + } + + ret =max77675_set_debounce_time (maxreg, config->debounce_time); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN debounce time: %d\n" , ret); +return ret; + } + + ret =max77675_set_manual_reset_time (maxreg, config->manual_reset_time); +if (ret) { +dev_err (maxreg->dev,"Failed to set manual reset time: %d\n" , ret); +return ret; + } + + ret =max77675_set_en_pullup_disable (maxreg, config->en_pullup_disable); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN pull-up disable: %d\n" , ret); +return ret; + } + + ret =max77675_set_bias_low_power_request (maxreg, config->bias_low_power_request);
drivers/regulator/max77675-regulator.c line 552
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+if (ret) { +dev_err (maxreg->dev,"Failed to set bias low-power request: %d\n" , ret); +return ret; + } + + ret =max77675_set_simo_int_ldo_always_on (maxreg, config->simo_int_ldo_always_on); +if (ret) { +dev_err (maxreg->dev,"Failed to set SIMO internal LDO always-on: %d\n" , ret); +return ret; + }
This seems to called during probe. All the above can be return dev_err_probe()...
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +return 0 ; +} + +static u8 max77675_parse_voltage_change_latency (struct device_node *np) +{
drivers/regulator/max77675-regulator.c line 568
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+u32 val; + +if (!of_property_read_u32 (np,"maxim,voltage-change-latency-us" , &val)) { +switch (val) { +case 10 : +return MAX77675_LOW_LATENCY_MODE ; +case 100 : +return MAX77675_HIGH_LATENCY_MODE ; +default : +break ;
The above is wrong. You're ignoring invalid values being given and overwrite them with defaults. The pattern is:
val = MAX77675_HIGH_LATENCY_MODE;
if (!of_property_read_u32(np, "maxim,voltage-change-latency-us", &val)) {
...
default:
return dev_err_probe(dev, -EINVAL, ...);
}You can also do:
ret = of_property_read_u32(...);
/* Not 100% sure if -EINVAL is the error code for a missing property */ if (ret && ret != -EINVAL)
return ret;
if (!ret) {
...
}Quoted 8 lines
drivers/regulator/max77675-regulator.c new file +8
-0+ } + } + +/* default: high latency */ +return MAX77675_HIGH_LATENCY_MODE ; +} + +static u8 max77675_parse_en_mode (struct device_node *np)
drivers/regulator/max77675-regulator.c line 586
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+{ +const char *str; + +if (!of_property_read_string (np,"maxim,en-mode" , &str)) { +if (!strcasecmp (str,"push-button" )) +return MAX77675_EN_PUSH_BUTTON ; +else if (!strcasecmp (str,"slide-switch" )) +return MAX77675_EN_SLIDE_SWITCH ; +else if (!strcasecmp (str,"logic" )) +return MAX77675_EN_LOGIC ;
redundant else if(). Moreover, this looks like it could use match_string()
Quoted 12 lines
drivers/regulator/max77675-regulator.c new file +12
-0+ } + +/* default : slide-switch */ +return MAX77675_EN_SLIDE_SWITCH ; +} + +static u8 max77675_parse_manual_reset_time (struct device_node *np) +{ +u32 val; + +if (!of_property_read_u32 (np,"reset-time-sec" , &val)) { +switch (val) {
drivers/regulator/max77675-regulator.c line 608
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+case 4 : +return MAX77675_MRT_4S ; +case 8 : +return MAX77675_MRT_8S ; +case 12 : +return MAX77675_MRT_12S ; +case 16 : +return MAX77675_MRT_16S ; +default : +break ;
Ditto.
...
Quoted 14 lines
drivers/regulator/max77675-regulator.c new file +14
-0+ +static int max77675_parse_config (struct max77675_regulator *maxreg) +{ +struct device_node *np = maxreg->dev->of_node; +struct max77675_config *config = &maxreg->config; +int ret; + +/* EN pin mode: push-button, slide-switch, or logic */ + config->en_mode =max77675_parse_en_mode (np); + +/* latency mode */ + config->voltage_change_latency =max77675_parse_voltage_change_latency (np); + +/* drive strength */
drivers/regulator/max77675-regulator.c line 695
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ config->drv_sbb_strength =max77675_parse_drv_sbb_strength (np); + +/* drv slew rate */ + config->dvs_slew_rate =max77675_parse_dvs_slew_rate (np); + +/* Debounce time for EN pin */ + config->debounce_time =max77675_parse_debounce_time_us (np); + +/* Manual reset time for EN pin */ + config->manual_reset_time =max77675_parse_manual_reset_time (np);
Seems to me that all of the above will need some error handling.
Quoted 65 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +/* Disable internal pull-up resistor on EN pin */ + config->en_pullup_disable =of_property_read_bool (np,"maxim,en-pullup-disable" ); + +/* Request low-power mode for main bias */ + config->bias_low_power_request = of_property_read_bool(np, "maxim,bias-low-power-request");
drivers/regulator/max77675-regulator.c new file +3
-0+ +/* Force internal LDO to always supply 1.8V */ + config->simo_int_ldo_always_on = of_property_read_bool(np, "maxim,simo-int-ldo-always-on");
drivers/regulator/max77675-regulator.c new file +54
-0+ + ret =max77675_apply_config (maxreg); + +return ret; +} + +static int max77675_init_event (struct max77675_regulator *maxreg) +{ +unsigned int ercflag, int_glbl; +int ret; + + ret =regmap_read (maxreg->regmap,MAX77675_REG_ERCF_GLBL , &ercflag); +if (ret) { +dev_err (maxreg->dev,"Failed to read CID register: %d\n" , ret); +return ret; + } + + ret =regmap_read (maxreg->regmap,MAX77675_REG_INT_GLBL , &int_glbl); +if (ret) { +dev_err (maxreg->dev,"Failed to read INT_GLBL register: %d\n" , ret); +return ret; + } + +if (ercflag &MAX77675_SFT_CRST_F_BIT ) +dev_info (maxreg->dev,"Software Cold Reset Flag is set\n" ); + +if (ercflag &MAX77675_SFT_OFF_F_BIT ) +dev_info (maxreg->dev,"Software Off Flag is set\n" ); + +if (ercflag &MAX77675_MRST_BIT ) +dev_info (maxreg->dev,"Manual Reset Timer Flag is set\n" ); + +if (ercflag &MAX77675_UVLO_BIT ) +dev_info (maxreg->dev,"Undervoltage Lockout Flag is set\n" ); + +if (ercflag &MAX77675_OVLO_BIT ) +dev_info (maxreg->dev,"Overvoltage Lockout Flag is set\n" ); + +if (ercflag &MAX77675_TOVLD_BIT ) +dev_info (maxreg->dev,"Thermal Overload Flag is set\n" ); + +if (int_glbl &MAX77675_INT_SBB3_F_BIT ) +dev_info (maxreg->dev,"SBB3 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_SBB2_F_BIT ) +dev_info (maxreg->dev,"SBB2 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_SBB1_F_BIT ) +dev_info (maxreg->dev,"SBB1 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_SBB0_F_BIT ) +dev_info (maxreg->dev,"SBB0 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_TJAL2_R_BIT )
drivers/regulator/max77675-regulator.c line 768
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+dev_info (maxreg->dev,"Thermal Alarm 2 Rising Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_TJAL1_R_BIT ) +dev_info (maxreg->dev,"Thermal Alarm 1 Rising Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_EN_R_BIT ) +dev_info (maxreg->dev,"nEN Rising Edge Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_EN_F_BIT ) +dev_info (maxreg->dev,"nEN Falling Edge Interrupt occurred\n" );
All of the above looks like dev_dbg() to me.
Quoted 26 lines
drivers/regulator/max77675-regulator.c new file +26
-0+ +return 0 ; +} + +static int max77675_regulator_probe (struct i2c_client *client) +{ +struct max77675_regulator *maxreg; +struct regulator_config config = {}; +struct device_node *regulators_np; +int i, ret; + + maxreg =devm_kzalloc (&client->dev,sizeof (*maxreg),GFP_KERNEL ); +if (!maxreg) +return -ENOMEM ; + + maxreg->dev = &client->dev; + + maxreg->regmap =devm_regmap_init_i2c (client, &max77675_regmap_config); +if (IS_ERR (maxreg->regmap)) +return dev_err_probe (maxreg->dev, + PTR_ERR(maxreg->regmap), + "Failed to init regmap\n"); + + ret =max77675_init_event (maxreg); +if (ret) +return dev_err_probe (maxreg->dev, ret,"Failed to init event\n" );
drivers/regulator/max77675-regulator.c line 804
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ + ret =max77675_parse_config (maxreg); +if (ret) +return dev_err_probe (maxreg->dev, ret,"Failed to apply config\n" ); + + config.dev = &client->dev; + config.regmap = maxreg->regmap; + config.driver_data = maxreg; + + regulators_np =of_get_child_by_name (client->dev.of_node,"regulators" );
The above can actually be:
struct device_node *regulators_np __free(device_node) = of_get_child_by_name(...)
and then no need to care about of_node_put(). You need cleanup.h
Quoted 17 lines
drivers/regulator/max77675-regulator.c new file +17
-0+if (!regulators_np) { +dev_err (maxreg->dev,"No 'regulators' subnode found in DT\n" ); +return -EINVAL ; + } + +for (i =0 ; i <MAX77675_ID_NUM_MAX ; i++) { +const struct regulator_desc *desc = &max77675_regulators[i]; +struct regulator_dev *rdev; + + config.of_node =of_get_child_by_name (regulators_np, desc->name); +if (!config.of_node) { +dev_warn (maxreg->dev,"No DT node for regulator %s\n" , desc->name); +continue ; + } + + rdev =devm_regulator_register (&client->dev, desc, &config); +of_node_put (config.of_node);
drivers/regulator/max77675-regulator.c line 831
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+if (IS_ERR (rdev)) { +of_node_put (regulators_np); +return dev_err_probe (maxreg->dev,PTR_ERR (rdev), +"Failed to register regulator %d (%s): %d\n" , + i, desc->name, ret); + } + } + +of_node_put (regulators_np); +i2c_set_clientdata (client, maxreg);
I do not see i2c_get_clientdata() anywhere. I suspect you can drop the above.
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ +return 0 ; +} + +static const struct i2c_device_id max77675_i2c_id[] = { + {"max77675" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, max77675_i2c_id); +
drivers/regulator/max77675-regulator.c line 851
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+static const struct of_device_id __maybe_unused max77675_of_match[] = { + { .compatible ="maxim,max77675" , }, + { } +}; +MODULE_DEVICE_TABLE (of, max77675_of_match); + +static struct i2c_driver max77675_regulator_driver = { + .driver = { + .name ="max77675" , + .of_match_table =of_match_ptr (max77675_of_match),
I guess we can drop of_match_ptr() if we agree that we depend on OF
drivers/regulator/max77675-regulator.h
Quoted 15 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ }, + .probe = max77675_regulator_probe, + .id_table = max77675_i2c_id, +}; + +module_i2c_driver (max77675_regulator_driver); + +MODULE_DESCRIPTION ("MAX77675 Regulator Driver" ); +MODULE_AUTHOR ("Joan Na <[email protected]>" ); +MODULE_LICENSE ("GPL" );drivers/regulator/max77675-regulator.h new file +0
-0
As said, drop the header.
- Nuno Sá
Re: [PATCH v5 2/2] regulator: max77675: Add MAX77675 regulator driver
Quoted 13 lines · Nuno Sá
Quoted 12 lines · Joan-Na-adi
From: Joan Na <[email protected]>
Add support for the Maxim Integrated MAX77675 PMIC regulator.
The MAX77675 is a compact, highly efficient SIMO (Single Inductor Multiple Output) power management IC that provides four programmable buck-boost switching regulators with only one inductor. It supports up to 700mA total output current and operates from a single-cell Li-ion battery.
An integrated power-up sequencer and I2C interface allow flexible startup configuration and runtime control.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Joan Na <[email protected]>---
Hi Joan,
Some comments from me...
Hello Nuno,
Thank you for taking the time to review.
Please refer to my response below.
Quoted 16 lines
Quoted 16 lines
drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 +
drivers/regulator/max77675-regulator.c| 861 +++++++++++++++++++++++++drivers/regulator/max77675-regulator.h| 260 ++++++++4 files changed, 1131 insertions(+)create mode 100644
drivers/regulator/max77675-regulator.ccreate mode 100644drivers/regulator/max77675-regulator.hdrivers/regulator/Kconfig +0
-0@@ -649,6 +649,15 @@ config REGULATOR_MAX77650Semiconductor. This device has a SIMO with three independent power rails and an LDO.
Quoted 6 lines
drivers/regulator/Kconfig config REGULATOR_MAX77650 · line 654
Quoted 3 lines
drivers/regulator/Kconfig +3
-0+config REGULATOR_MAX77675 + tristate "Maxim MAX77675 regulator driver" + depends on I2CLooking at your code, I would expected OF to be a dependency as well.
I’ll add OF as a dependency
Quoted 38 lines
Quoted 38 lines
drivers/regulator/Kconfig +6
-0+ select REGMAP_I2C + help + This driver controls the Maxim MAX77675 power regulator via I2C. + It supports four programmable buck-boost outputs. + Say Y here to enable the regulator driver +config
REGULATOR_MAX77857
tristate "ADI MAX77857/MAX77831 regulator support" depends on I2Cdrivers/regulator/Makefile +0
-0@@ -78,6 +78,7 @@ obj-$(CONFIG_REGULATOR_MAX77503) += max77503-regulator.oobj-$(CONFIG_REGULATOR_MAX77541) += max77541-regulator.o obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o +obj-$(CONFIG_REGULATOR_MAX77675) += max77675-regulator.o
obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o obj-$(CONFIG_REGULATOR_MAX8893) += max8893.odrivers/regulator/max77675-regulator.c new file +11
-0@@ -0,0 +1,861 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2025 Analog Devices, Inc. +* ADI regulator driver for MAX77675. +*/ + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/i2c.h> +#include <linux/regmap.h>
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 16
Quoted 5 lines
drivers/regulator/max77675-regulator.c new file +5
-0+#include <linux/platform_device.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/consumer.h> +#include <linux/regulator/of_regulator.h> +#include <linux/bitfield.h> You're clearly missing (at least)
mod_devicetable.h. I know that at least clang allows you to get iwyu,
I will add it.
Quoted 6 lines
drivers/regulator/max77675-regulator.c line 18
Quoted 2 lines
drivers/regulator/max77675-regulator.c new file +2
-0+ +#include "max77675-regulator.h" Why do we need the header file? Just include everything in the source code unless you expect to share something with another module (which I dunno)?
I will remove the header file as suggested
Quoted 10 lines
drivers/regulator/max77675-regulator.c line 24
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +struct max77675_regulator_pdata { + u8 fps_slot; +bool fixed_slew_rate; +}; +I would get rid of the
_pdatasuffix. Implies some legacy way of doing things (but kind of a nitpick)
I will rename it to max77675_regulator_sbb_setting.
Quoted 26 lines
Quoted 26 lines
drivers/regulator/max77675-regulator.c new file +26
-0+struct max77675_config { + u8 en_mode; + u8 voltage_change_latency; + u8 drv_sbb_strength; + u8 dvs_slew_rate; + u8 debounce_time; + u8 manual_reset_time; +bool en_pullup_disable; +bool bias_low_power_request; +bool simo_int_ldo_always_on; +}; + +struct max77675_regulator { +struct device *dev; +struct regmap *regmap; +struct max77675_config config; +struct max77675_regulator_pdata pdata[MAX77675_ID_NUM_MAX ]; +}; + +/** +* Set latency mode. +* +* @param maxreg Pointer to max77675 device structure. +* @param enable true to enable latency mode, false to disable. +*/ +static int max77675_set_latency_mode (struct max77675_regulator *maxreg,bool enable)
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 56
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+{ +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_SBB_TOP_B , + MAX77675_LAT_MODE_BIT, + FIELD_PREP(MAX77675_LAT_MODE_BIT, enable)); +} +I would drop these one liner wrappers. Personally, I don't see a big benefit on it.
I agree with your point and will remove these one-liner wrappers as suggested
Quoted 60 lines
drivers/regulator/max77675-regulator.c line 69
Quoted 13 lines
drivers/regulator/max77675-regulator.c new file +13
-0+/** +* Set DVS slew rate mode. +* +* @param maxreg Pointer to max77675 device structure. +* @param enable true to use DVS-controlled slew rate, false for fixed 2mV/us. +*/ +static int max77675_set_dvs_slew_rate (struct max77675_regulator *maxreg,bool enable) +{ +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_SBB_TOP_B , + MAX77675_DVS_SLEW_BIT, + FIELD_PREP(MAX77675_DVS_SLEW_BIT, enable)); +} +Ditto for all other places.
...
Quoted 42 lines
drivers/regulator/max77675-regulator.c new file +41
-0+ +/** +* Set debounce time for EN pin. +* +* @param maxreg Pointer to max77675 device structure. +* @param debounce_30ms true for 30ms, false for 100us +*/ +static int max77675_set_debounce_time (struct max77675_regulator *maxreg,bool debounce_30ms) +{ +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_GLBL_A , + MAX77675_DBEN_EN_BIT, + FIELD_PREP(MAX77675_DBEN_EN_BIT, debounce_30ms)); +} + +static int max77675_regulator_get_fps_src (struct max77675_regulator *maxreg,int id) +{ +unsigned int reg_addr; +unsigned int val; +int ret; + +switch (id) { +case MAX77675_ID_SBB0 : + reg_addr =MAX77675_REG_CNFG_SBB0_B ; +break ; +case MAX77675_ID_SBB1 : + reg_addr =MAX77675_REG_CNFG_SBB1_B ; +break ; +case MAX77675_ID_SBB2 : + reg_addr =MAX77675_REG_CNFG_SBB2_B ; +break ; +case MAX77675_ID_SBB3 : + reg_addr =MAX77675_REG_CNFG_SBB3_B ; +break ; +default : +dev_err (maxreg->dev,"Invalid regulator id: %d\n" , id); +return -EINVAL ; + } + + ret =regmap_read (maxreg->regmap, reg_addr, &val); +if (ret <0 ) { + dev_err(maxreg->dev, "Failed to read FPS source (reg 0x%02x): %d\n",
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 194
Quoted 5 lines
drivers/regulator/max77675-regulator.c new file +5
-0+ reg_addr, ret); +return ret; + } + +return val &MAX77675_EN_SBB_MASK ;Ok, this works since the mask is
0x7. However,FIELD_GET()would make it more readable and easy to review. I mean, I would not need to go and see the mask value.
I will change it to "return FIELD_GET(MAX77675_EN_SBB_MASK, val)"
Quoted 26 lines
Quoted 26 lines
drivers/regulator/max77675-regulator.c new file +26
-0+} + +static int max77675_regulator_set_fps_src (struct max77675_regulator *maxreg,int id,u8 fps_src) +{ +unsigned int reg_addr; +int ret; + +switch (id) { +case MAX77675_ID_SBB0 : + reg_addr =MAX77675_REG_CNFG_SBB0_B ; +break ; +case MAX77675_ID_SBB1 : + reg_addr =MAX77675_REG_CNFG_SBB1_B ; +break ; +case MAX77675_ID_SBB2 : + reg_addr =MAX77675_REG_CNFG_SBB2_B ; +break ; +case MAX77675_ID_SBB3 : + reg_addr =MAX77675_REG_CNFG_SBB3_B ; +break ; +default : +dev_err (maxreg->dev,"Invalid regulator id: %d\n" , id); +return -EINVAL ; + } + + ret = regmap_update_bits(maxreg->regmap, reg_addr,
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 226
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ MAX77675_EN_SBB_MASK, fps_src); +if (ret <0 ) { +dev_err (maxreg->dev,"Failed to set FPS source (reg 0x%02x): %d\n" , + reg_addr, ret); +return ret; + }I would drop the log and just do return
regmap_update_bits(). Up to you...
I will change it
Quoted 66 lines
Quoted 66 lines
drivers/regulator/max77675-regulator.c new file +17
-0+ +return 0 ; +} + +/** +* max77675_set_sbb_slew_rate_fixed - Set the slew rate for a specific SBB regulator channel +* +* @maxreg: Pointer to the max77675 regulator structure +* @id: Regulator channel ID (ID_SBB0 ~ ID_SBB3) +* @fixed: Slew rate value (true = 2mV/us, false = use DVS_SLEW) +* +* This function configures the slew rate control source for the specified SBB channel by +* updating the corresponding bits in the CNFG_SBB_TOP_B register. +* +* Return: 0 on success, negative error code on failure (e.g., invalid channel ID). +*/ +static int max77675_set_sbb_slew_rate_fixed(struct max77675_regulator *maxreg, int id, boolfixed)
drivers/regulator/max77675-regulator.c new file +48
-0+{ +u8 mask, value; +u8 slew_src_ctrl_bit = fixed ?0 :1 ; + +switch (id) { +case MAX77675_ID_SBB0 : + mask =MAX77675_SR_SBB0_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB0_BIT , slew_src_ctrl_bit); +break ; + +case MAX77675_ID_SBB1 : + mask =MAX77675_SR_SBB1_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB1_BIT , slew_src_ctrl_bit); +break ; + +case MAX77675_ID_SBB2 : + mask =MAX77675_SR_SBB2_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB2_BIT , slew_src_ctrl_bit); +break ; + +case MAX77675_ID_SBB3 : + mask =MAX77675_SR_SBB3_BIT ; + value =FIELD_PREP (MAX77675_SR_SBB3_BIT , slew_src_ctrl_bit); +break ; + +default : +return -EINVAL ; + } + +return regmap_update_bits (maxreg->regmap,MAX77675_REG_CNFG_SBB_TOP_B , mask, value); +} + +static int max77675_init_regulator (struct max77675_regulator *maxreg,int id) +{ +struct max77675_regulator_pdata *rpdata = &maxreg->pdata[id]; +int ret; + +if (rpdata->fps_slot ==MAX77675_FPS_DEF ) { + ret =max77675_regulator_get_fps_src (maxreg, id); +if (ret <0 ) { +dev_err (maxreg->dev,"Failed to read FPS source for ID %d\n" , id); +return ret; + } + rpdata->fps_slot = ret; + }else { + ret =max77675_regulator_set_fps_src (maxreg, id, rpdata->fps_slot); +if (ret) +dev_warn (maxreg->dev,"Failed to set FPS source for ID %d\n" , id);
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 296
Quoted 5 lines
drivers/regulator/max77675-regulator.c new file +5
-0+ } + + ret =max77675_set_sbb_slew_rate_fixed (maxreg, id, rpdata->fixed_slew_rate); +if (ret) +dev_warn (maxreg->dev,"Failed to set slew rate for ID %d\n" , id);Do we really want to treat this as a warning (as FPS)? If so, I would expect a proper comment explaining why we can afford it.
As this could impact proper operation, I’ll make the function return an error.
Quoted 14 lines
Quoted 14 lines
drivers/regulator/max77675-regulator.c new file +14
-0+ +return 0 ; +} + +static int max77675_of_parse_cb (struct device_node *np, +const struct regulator_desc *desc, +struct regulator_config *config) +{ +struct max77675_regulator *maxreg = config->driver_data; +struct max77675_regulator_pdata *rpdata = &maxreg->pdata[desc->id]; +u32 pval; +int ret; + +/* Parse FPS slot from DT */
Quoted 8 lines
drivers/regulator/max77675-regulator.c line 313
Quoted 3 lines
drivers/regulator/max77675-regulator.c new file +3
-0+ ret =of_property_read_u32 (np,"maxim,fps-slot" , &pval); + rpdata->fps_slot = (!ret) ? (u8 )pval :MAX77675_FPS_DEF ; +So, can we get any arbitrary value for pval? I see we you have an enum in the bindings so make sure we properly validate it. Same for all other properties. The bindings also have this as a string and here you have a u32? Not going to work. You need
of_property_read_string()+match_string().
Thanks, I will change it
Quoted 4 lines
Also, "maxim,"? For some time now it's "adi,".
I will change it
Quoted 36 lines
Quoted 36 lines
drivers/regulator/max77675-regulator.c new file +36
-0+/* Parse slew rate control source */ + rpdata->fixed_slew_rate =of_property_read_bool (np,"maxim,fixed-slew-rate" ); + +/* Apply parsed configuration */ +return max77675_init_regulator (maxreg, desc->id); +} + +static int max77675_get_error_flags (struct regulator_dev *rdev,unsigned int *flags) +{ +struct max77675_regulator *maxreg =rdev_get_drvdata (rdev); +unsigned int int_flags; +int id =rdev_get_id (rdev); +int ret; + + ret =regmap_read (maxreg->regmap,MAX77675_REG_INT_GLBL , &int_flags); +if (ret) { +dev_err (maxreg->dev,"Failed to read INT_GLBL: %d\n" , ret); +return ret; + } + + *flags =0 ; + +switch (id) { +case MAX77675_ID_SBB0 : +if (int_flags &MAX77675_INT_SBB0_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +case MAX77675_ID_SBB1 : +if (int_flags &MAX77675_INT_SBB1_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +case MAX77675_ID_SBB2 : +if (int_flags &MAX77675_INT_SBB2_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +case MAX77675_ID_SBB3 :
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 355
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+if (int_flags &MAX77675_INT_SBB3_F_BIT ) + *flags |=REGULATOR_ERROR_FAIL ; +break ; +default : +dev_warn (maxreg->dev,"Unsupported regulator ID: %d\n" , id); +break ;Should not be a warning. Also wonder if it can happen at all?
Agreed, this case shouldn’t happen. I’ll drop the warning.
Quoted 30 lines
Quoted 17 lines
drivers/regulator/max77675-regulator.c new file +17
-0+ } + +if (int_flags &MAX77675_INT_TJAL2_R_BIT ) { +/* TJAL2 interrupt: Over-temperature condition (above 120 degree) */ + *flags |=REGULATOR_ERROR_OVER_TEMP ; + } + +return 0 ; +} + +static const struct regulator_ops max77675_regulator_ops = { + .list_voltage = regulator_list_voltage_linear, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .map_voltage = regulator_map_voltage_linear, + .set_voltage_sel = regulator_set_voltage_sel_regmap,drivers/regulator/max77675-regulator.c line 382
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_active_discharge = regulator_set_active_discharge_regmap, + .get_error_flags = max77675_get_error_flags, +}; + +static struct regulator_desc max77675_regulators[MAX77675_ID_NUM_MAX ] = { + { + .name = "sbb0", + .of_match = of_match_ptr("sbb0"), + .regulators_node = of_match_ptr("regulators"),I wonder if we need
of_match_ptr()given that the whole thing depends on OF.
Quoted 2 lines
...
I agree with you. If there are no objections, I will remove it.
Quoted 53 lines
Quoted 53 lines
drivers/regulator/max77675-regulator.c new file +53
-0+ +static int max77675_apply_config (struct max77675_regulator *maxreg) +{ +const struct max77675_config *config = &maxreg->config; +int ret; + + ret =max77675_set_en_mode (maxreg, config->en_mode); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN mode: %d\n" , ret); +return ret; + } + + ret =max77675_set_latency_mode (maxreg, config->voltage_change_latency); +if (ret) { +dev_err (maxreg->dev,"Failed to set latency mode: %d\n" , ret); +return ret; + } + + ret =max77675_set_drv_sbb_strength (maxreg, config->drv_sbb_strength); +if (ret) { +dev_err (maxreg->dev,"Failed to set drive strength: %d\n" , ret); +return ret; + } + + ret =max77675_set_dvs_slew_rate (maxreg, config->dvs_slew_rate); +if (ret) { +dev_err (maxreg->dev,"Failed to set DVS slew rate: %d\n" , ret); +return ret; + } + + ret =max77675_set_debounce_time (maxreg, config->debounce_time); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN debounce time: %d\n" , ret); +return ret; + } + + ret =max77675_set_manual_reset_time (maxreg, config->manual_reset_time); +if (ret) { +dev_err (maxreg->dev,"Failed to set manual reset time: %d\n" , ret); +return ret; + } + + ret =max77675_set_en_pullup_disable (maxreg, config->en_pullup_disable); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN pull-up disable: %d\n" , ret); +return ret; + } + + ret =max77675_set_bias_low_power_request (maxreg, config->bias_low_power_request); +if (ret) { +dev_err (maxreg->dev,"Failed to set bias low-power request: %d\n" , ret); +return ret; + }
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 552
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ + ret =max77675_set_simo_int_ldo_always_on (maxreg, config->simo_int_ldo_always_on); +if (ret) { +dev_err (maxreg->dev,"Failed to set SIMO internal LDO always-on: %d\n" , ret); +return ret; + }This seems to called during probe. All the above can be return
dev_err_probe()...
I’m thinking of handling it directly where the return value is checked. What are your thoughts?
ret = max77675_apply_config(maxreg);
if (ret)
return dev_err_probe(maxreg->dev, ret, "Failed to apply config\n");Quoted 29 lines
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +return 0 ; +} + +static u8 max77675_parse_voltage_change_latency (struct device_node *np) +{drivers/regulator/max77675-regulator.c line 568
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+u32 val; + +if (!of_property_read_u32 (np,"maxim,voltage-change-latency-us" , &val)) { +switch (val) { +case 10 : +return MAX77675_LOW_LATENCY_MODE ; +case 100 : +return MAX77675_HIGH_LATENCY_MODE ; +default : +break ;The above is wrong. You're ignoring invalid values being given and overwrite them with defaults. The pattern is:
val =
MAX77675_HIGH_LATENCY_MODE;if (!of_property_read_u32(np, "maxim,voltage-change-latency-us", &val)) { ... default: return dev_err_probe(dev, -EINVAL, ...); }You can also do:
Quoted 8 lines
ret =
of_property_read_u32(...);
/* Not 100% sure if-EINVALis the error code for a missing property */ if (ret && ret !=-EINVAL)return ret; if (!ret) { ... }
I will update the code to set a default value first and handle invalid values by returning an error.
Quoted 12 lines
Quoted 12 lines
drivers/regulator/max77675-regulator.c new file +12
-0+ } + } + +/* default: high latency */ +return MAX77675_HIGH_LATENCY_MODE ; +} + +static u8 max77675_parse_en_mode (struct device_node *np) +{ +const char *str; + +if (!of_property_read_string (np,"maxim,en-mode" , &str)) {
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 586
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+if (!strcasecmp (str,"push-button" )) +return MAX77675_EN_PUSH_BUTTON ; +else if (!strcasecmp (str,"slide-switch" )) +return MAX77675_EN_SLIDE_SWITCH ; +else if (!strcasecmp (str,"logic" )) +return MAX77675_EN_LOGIC ;redundant else
if(). Moreover, this looks like it could usematch_string()
I will update it to use match_string.
Quoted 45 lines
Quoted 12 lines
drivers/regulator/max77675-regulator.c new file +12
-0+ } + +/* default : slide-switch */ +return MAX77675_EN_SLIDE_SWITCH ; +} + +static u8 max77675_parse_manual_reset_time (struct device_node *np) +{ +u32 val; + +if (!of_property_read_u32 (np,"reset-time-sec" , &val)) { +switch (val) {drivers/regulator/max77675-regulator.c line 608
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+case 4 : +return MAX77675_MRT_4S ; +case 8 : +return MAX77675_MRT_8S ; +case 12 : +return MAX77675_MRT_12S ; +case 16 : +return MAX77675_MRT_16S ; +default : +break ;Ditto.
...
Quoted 18 lines
drivers/regulator/max77675-regulator.c new file +18
-0+ +static int max77675_parse_config (struct max77675_regulator *maxreg) +{ +struct device_node *np = maxreg->dev->of_node; +struct max77675_config *config = &maxreg->config; +int ret; + +/* EN pin mode: push-button, slide-switch, or logic */ + config->en_mode =max77675_parse_en_mode (np); + +/* latency mode */ + config->voltage_change_latency =max77675_parse_voltage_change_latency (np); + +/* drive strength */ + config->drv_sbb_strength =max77675_parse_drv_sbb_strength (np); + +/* drv slew rate */ + config->dvs_slew_rate =max77675_parse_dvs_slew_rate (np);
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 695
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +/* Debounce time for EN pin */ + config->debounce_time =max77675_parse_debounce_time_us (np); + +/* Manual reset time for EN pin */ + config->manual_reset_time =max77675_parse_manual_reset_time (np);Seems to me that all of the above will need some error handling.
I will update the code to handle errors.
Quoted 69 lines
Quoted 69 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +/* Disable internal pull-up resistor on EN pin */ + config->en_pullup_disable =of_property_read_bool (np,"maxim,en-pullup-disable" ); + +/* Request low-power mode for main bias */ + config->bias_low_power_request = of_property_read_bool(np, "maxim,bias-low-power-request");
drivers/regulator/max77675-regulator.c new file +3
-0+ +/* Force internal LDO to always supply 1.8V */ + config->simo_int_ldo_always_on = of_property_read_bool(np, "maxim,simo-int-ldo-always-on");
drivers/regulator/max77675-regulator.c new file +58
-0+ + ret =max77675_apply_config (maxreg); + +return ret; +} + +static int max77675_init_event (struct max77675_regulator *maxreg) +{ +unsigned int ercflag, int_glbl; +int ret; + + ret =regmap_read (maxreg->regmap,MAX77675_REG_ERCF_GLBL , &ercflag); +if (ret) { +dev_err (maxreg->dev,"Failed to read CID register: %d\n" , ret); +return ret; + } + + ret =regmap_read (maxreg->regmap,MAX77675_REG_INT_GLBL , &int_glbl); +if (ret) { +dev_err (maxreg->dev,"Failed to read INT_GLBL register: %d\n" , ret); +return ret; + } + +if (ercflag &MAX77675_SFT_CRST_F_BIT ) +dev_info (maxreg->dev,"Software Cold Reset Flag is set\n" ); + +if (ercflag &MAX77675_SFT_OFF_F_BIT ) +dev_info (maxreg->dev,"Software Off Flag is set\n" ); + +if (ercflag &MAX77675_MRST_BIT ) +dev_info (maxreg->dev,"Manual Reset Timer Flag is set\n" ); + +if (ercflag &MAX77675_UVLO_BIT ) +dev_info (maxreg->dev,"Undervoltage Lockout Flag is set\n" ); + +if (ercflag &MAX77675_OVLO_BIT ) +dev_info (maxreg->dev,"Overvoltage Lockout Flag is set\n" ); + +if (ercflag &MAX77675_TOVLD_BIT ) +dev_info (maxreg->dev,"Thermal Overload Flag is set\n" ); + +if (int_glbl &MAX77675_INT_SBB3_F_BIT ) +dev_info (maxreg->dev,"SBB3 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_SBB2_F_BIT ) +dev_info (maxreg->dev,"SBB2 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_SBB1_F_BIT ) +dev_info (maxreg->dev,"SBB1 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_SBB0_F_BIT ) +dev_info (maxreg->dev,"SBB0 Channel Fault Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_TJAL2_R_BIT ) +dev_info (maxreg->dev,"Thermal Alarm 2 Rising Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_TJAL1_R_BIT ) +dev_info (maxreg->dev,"Thermal Alarm 1 Rising Interrupt occurred\n" );
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 768
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ +if (int_glbl &MAX77675_INT_EN_R_BIT ) +dev_info (maxreg->dev,"nEN Rising Edge Interrupt occurred\n" ); + +if (int_glbl &MAX77675_INT_EN_F_BIT ) +dev_info (maxreg->dev,"nEN Falling Edge Interrupt occurred\n" );All of the above looks like
dev_dbg()to me.
I will change it
Quoted 39 lines
Quoted 26 lines
drivers/regulator/max77675-regulator.c new file +26
-0+ +return 0 ; +} + +static int max77675_regulator_probe (struct i2c_client *client) +{ +struct max77675_regulator *maxreg; +struct regulator_config config = {}; +struct device_node *regulators_np; +int i, ret; + + maxreg =devm_kzalloc (&client->dev,sizeof (*maxreg),GFP_KERNEL ); +if (!maxreg) +return -ENOMEM ; + + maxreg->dev = &client->dev; + + maxreg->regmap =devm_regmap_init_i2c (client, &max77675_regmap_config); +if (IS_ERR (maxreg->regmap)) +return dev_err_probe (maxreg->dev, + PTR_ERR(maxreg->regmap), + "Failed to init regmap\n"); + + ret =max77675_init_event (maxreg); +if (ret) +return dev_err_probe (maxreg->dev, ret,"Failed to init event\n" );drivers/regulator/max77675-regulator.c line 804
Quoted 10 lines
drivers/regulator/max77675-regulator.c new file +10
-0+ + ret =max77675_parse_config (maxreg); +if (ret) +return dev_err_probe (maxreg->dev, ret,"Failed to apply config\n" ); + + config.dev = &client->dev; + config.regmap = maxreg->regmap; + config.driver_data = maxreg; + + regulators_np =of_get_child_by_name (client->dev.of_node,"regulators" );The above can actually be:
Quoted 4 lines
struct
device_node*regulators_np__free(device_node)=of_get_child_by_name(...)and then no need to care about
of_node_put(). You needcleanup.h
Thanks fot letting me know, I will change it
Quoted 21 lines
Quoted 21 lines
drivers/regulator/max77675-regulator.c new file +21
-0+if (!regulators_np) { +dev_err (maxreg->dev,"No 'regulators' subnode found in DT\n" ); +return -EINVAL ; + } + +for (i =0 ; i <MAX77675_ID_NUM_MAX ; i++) { +const struct regulator_desc *desc = &max77675_regulators[i]; +struct regulator_dev *rdev; + + config.of_node =of_get_child_by_name (regulators_np, desc->name); +if (!config.of_node) { +dev_warn (maxreg->dev,"No DT node for regulator %s\n" , desc->name); +continue ; + } + + rdev =devm_regulator_register (&client->dev, desc, &config); +of_node_put (config.of_node); +if (IS_ERR (rdev)) { +of_node_put (regulators_np); + return dev_err_probe(maxreg->dev, PTR_ERR(rdev), + "Failed to register regulator %d (%s): %d\n",
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 831
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ i, desc->name, ret); + } + } + +of_node_put (regulators_np); +i2c_set_clientdata (client, maxreg);I do not see
i2c_get_clientdata()anywhere. I suspect you can drop the above.
I will remove it
Quoted 14 lines
Quoted 14 lines
drivers/regulator/max77675-regulator.c new file +14
-0+ +return 0 ; +} + +static const struct i2c_device_id max77675_i2c_id[] = { + {"max77675" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, max77675_i2c_id); + +static const struct of_device_id __maybe_unused max77675_of_match[] = { + { .compatible ="maxim,max77675" , }, + { } +};
Quoted 9 lines
drivers/regulator/max77675-regulator.c line 851
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+MODULE_DEVICE_TABLE (of, max77675_of_match); + +static struct i2c_driver max77675_regulator_driver = { + .driver = { + .name ="max77675" , + .of_match_table =of_match_ptr (max77675_of_match),I guess we can drop
of_match_ptr()if we agree that we depend on OF
I agree with you. If there are no objections, I will remove it.
Quoted 9 lines
Quoted 9 lines
drivers/regulator/max77675-regulator.c new file +9
-0+ }, + .probe = max77675_regulator_probe, + .id_table = max77675_i2c_id, +}; + +module_i2c_driver (max77675_regulator_driver); + +MODULE_DESCRIPTION ("MAX77675 Regulator Driver" ); +MODULE_AUTHOR ("Joan Na <[email protected]>" );
Quoted 9 lines
drivers/regulator/max77675-regulator.h
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +1
-0+MODULE_LICENSE ("GPL" );drivers/regulator/max77675-regulator.h new file +0
-0As said, drop the header.
I will drop the header.
Quoted 1 line
- Nuno Sá
Signature · 2 lines
Best regards, Joan Na
Re: [PATCH v5 2/2] regulator: max77675: Add MAX77675 regulator driver
Quoted 27 lines · Joan Na
Quoted 13 lines · Nuno Sá
Quoted 12 lines · Joan-Na-adi
From: Joan Na <[email protected]>
Add support for the Maxim Integrated MAX77675 PMIC regulator.
The MAX77675 is a compact, highly efficient SIMO (Single Inductor Multiple Output) power management IC that provides four programmable buck-boost switching regulators with only one inductor. It supports up to 700mA total output current and operates from a single-cell Li-ion battery.
An integrated power-up sequencer and I2C interface allow flexible startup configuration and runtime control.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Joan Na <[email protected]>---
Hi Joan,
Some comments from me...
Hello Nuno,
Thank you for taking the time to review.
Please refer to my response below.
...
Quoted 65 lines
Quoted 55 lines
Quoted 55 lines
drivers/regulator/max77675-regulator.c new file +53
-0+ +static int max77675_apply_config (struct max77675_regulator *maxreg) +{ +const struct max77675_config *config = &maxreg->config; +int ret; + + ret =max77675_set_en_mode (maxreg, config->en_mode); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN mode: %d\n" , ret); +return ret; + } + + ret =max77675_set_latency_mode (maxreg, config->voltage_change_latency); +if (ret) { +dev_err (maxreg->dev,"Failed to set latency mode: %d\n" , ret); +return ret; + } + + ret =max77675_set_drv_sbb_strength (maxreg, config->drv_sbb_strength); +if (ret) { +dev_err (maxreg->dev,"Failed to set drive strength: %d\n" , ret); +return ret; + } + + ret =max77675_set_dvs_slew_rate (maxreg, config->dvs_slew_rate); +if (ret) { +dev_err (maxreg->dev,"Failed to set DVS slew rate: %d\n" , ret); +return ret; + } + + ret =max77675_set_debounce_time (maxreg, config->debounce_time); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN debounce time: %d\n" , ret); +return ret; + } + + ret =max77675_set_manual_reset_time (maxreg, config->manual_reset_time); +if (ret) { +dev_err (maxreg->dev,"Failed to set manual reset time: %d\n" , ret); +return ret; + } + + ret =max77675_set_en_pullup_disable (maxreg, config->en_pullup_disable); +if (ret) { +dev_err (maxreg->dev,"Failed to set EN pull-up disable: %d\n" , ret); +return ret; + } + + ret =max77675_set_bias_low_power_request (maxreg, config->bias_low_power_request); +if (ret) { +dev_err (maxreg->dev,"Failed to set bias low-power request: %d\n" , ret); +return ret; + }Quoted 9 lines
drivers/regulator/max77675-regulator.c line 552
Quoted 6 lines
drivers/regulator/max77675-regulator.c new file +6
-0+ + ret =max77675_set_simo_int_ldo_always_on (maxreg, config->simo_int_ldo_always_on); +if (ret) { +dev_err (maxreg->dev,"Failed to set SIMO internal LDO always-on: %d\n" , ret); +return ret; + }This seems to called during probe. All the above can be return
dev_err_probe()...
Quoted 5 lines
I’m thinking of handling it directly where the return value is checked. What are your thoughts?
ret =
max77675_apply_config(maxreg);
if (ret)
returndev_err_probe(maxreg->dev, ret, "Failed to apply config\n");
Up to you. You'll have less details if you encounter some issue though...
- Nuno Sá