TI TPS6594 PMIC support (RTC, pinctrl, regulators)
Subsystems (5)
v5 cover TI TPS6594 PMIC support (RTC, pinctrl, regulators)
TPS6594 is a Power Management IC which provides regulators and others features like GPIOs, RTC, watchdog, ESMs (Error Signal Monitor), and PFSM (Pre-configurable Finite State Machine). The SoC and the PMIC can communicate through the I2C or SPI interfaces.
TPS6594 is the super-set device while TPS6593 and LP8764 are derivatives.
This series adds support to TI TPS6594 PMIC and its derivatives.
This should be applied on top of other patch series:
- https://lore.kernel.org/all/[email protected]/
For core MFD driver
The features implemented in this series are:
- RTC (child device)
- Pinmux/GPIO (child device)
- Regulator (child device)
RTC description:
The TPS6594 family has an RTC built-in, except for LP8764. It provides time and an alarm.
Pinmux/GPIO:
TPS6594 family has 11 GPIOs. Those GPIO can also serve different functions such as I2C or SPI interface, watchdog disable functions. The driver provides both pinmuxing for the functions and GPIO capability.
Regulator:
TPS6594/TPS6593: 5 BUCKs and 4LDOs
LP8764: 4 BUCKs and no LDO
Bucks can be used in multipahse mode.
Changes since v1:
https://lore.kernel.org/all/[email protected]/
Rtc:
- Removed struct tps6594_rtc.
- Removed some dev_err messages.
- Removed some comments.
- Remove some whitespaces in comments and error messages.
- Check if RTC is running before reading a timestamp in read_rtc.
- Stop RTC at the end of probe to wait for a timestamp to be set.
- Add default MFD_TPS6594 to Kconfig.
Pinctrl:
- Removed #define DEBUG.
- Add default MFD_TPS6594 to Kconfig.
- Fix typo and reword help message of Kconfig.
Regulators:
Further to Mark Brown review:
- File header whole block C++ style.
- Configuring modes not supported: omit all mode operations
- Log the error before notifying.
- Request the interrupts while registering the regulators (then remove the lookup function).
Further to Matti review:
- Postponed: devm_regulator_irq_helper() and regulator_irq_map_event_simple() can probably be used but code. refactoring is not so trivial. This can be done later as an enhancement after this patch list is merged.
Buck Multi phase management:
- Multiphase property can take an array when 2 multi phase buck, buck12 and buck34.
- Configuration multi phase buck34 without multiphase buck12 is not supported (when only one multiphase, must be buck12). Not clear from the spec but confirmed by TI.
- Supported multiphase conficurations: buck12, buck123, buck1234, buck12 + buck34.
- All interrupts are attached to the multiphase buck (ie: for regulator buck12, buck1 & buck2 interrupts are registered).
Changes since v2:
https://lore.kernel.org/all/[email protected]/
Rtc:
- Add logic to avoid reinitializing a working clock.
- Fix some multiline comments format.
Regulators:
Further to Mark Brown review:
- Log the error before notifying.
- Request the interrupts while registering the regulators. Further to Krzysztof Kozlowski:
https://lore.kernel.org/all/[email protected]/
- Remove ti, multi-phase-id property which is redundant with buck dts naming rules.
Changes since v3:
https://lore.kernel.org/lkml/[email protected]/
RTC:
- Add wakeup source
Pinctrl:
- Switch to GPIO_REGMAP framework
Change since v4:
https://lore.kernel.org/lkml/[email protected]/
Update Copyright notice date
Reorder includes
RTC:
- Rework some comments, fixing punctuation and style
- Use NANO macro from units.h for PPB_MULT
- Rework to use bitwise types
- Remove unnecessary casts
- Add SAFETY comments
- Use dev_err_probe(...) instead of print then return
Pinctrl:
- Reword help message and add module name in Kconfig
- Rework code to use struct pinfunction and PINCTRL_PINFUNCTION() macro
- Remove unnecessary casts
- Use dev_err_probe(...) instead of print then return
- Replace TPS6594_REG_GPIO1_CONF with a comment for TPS6594_REG_GPIOX_CONF
Regulators:
- nits: Add missing tabs, standard spaces, group "buck_multi".
- Use OF dedicated of_node_cmp API instead of standard strcmp.
- Use devm_kmalloc_array(...) API instead of devm_kmalloc(...) wherever possible.
- return dev_err_probe(...) wherever possible.
Esteban Blanc (2):
rtc: tps6594: Add driver for TPS6594 RTC
pinctrl: tps6594: Add driver for TPS6594 pinctrl and GPIOs
Jerome Neanne (1):
regulator: tps6594-regulator: Add driver for TI TPS6594 regulators
drivers/pinctrl/Kconfig | 13 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-tps6594.c | 367 +++++++++++++++ drivers/regulator/Kconfig | 13 + drivers/regulator/Makefile | 1 + drivers/regulator/tps6594-regulator.c | 615 ++++++++++++++++++++++++++ drivers/rtc/Kconfig | 12 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-tps6594.c | 463 +++++++++++++++++++ include/linux/mfd/tps6594.h | 3 +- 10 files changed, 1488 insertions(+), 1 deletion(-) create mode 100644 drivers/pinctrl/pinctrl-tps6594.c create mode 100644 drivers/regulator/tps6594-regulator.c create mode 100644 drivers/rtc/rtc-tps6594.c
Signature · 1 line
2.39.2
PATCH v5 1/3 rtc: tps6594: Add driver for TPS6594 RTC
TPS6594 PMIC is a MFD. This patch adds support for the RTC found inside TPS6594 family of PMIC.
Alarm is also supported.
--- drivers/rtc/Kconfig | 12 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-tps6594.c | 463 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 476 insertions(+) create mode 100644 drivers/rtc/rtc-tps6594.c
drivers/rtc/Kconfig +12 -0
@@ -578,6 +578,18 @@ config RTC_DRV_TPS6586X along with alarm. This driver supports the RTC driver for the TPS6586X RTC module. +config RTC_DRV_TPS6594 + tristate "TI TPS6594 RTC driver" + depends on MFD_TPS6594 + default MFD_TPS6594 + help + TI Power Management IC TPS6594 supports RTC functionality + along with alarm. This driver supports the RTC driver for + the TPS6594 RTC module. + + This driver can also be built as a module. If so, the module + will be called tps6594-rtc + config RTC_DRV_TPS65910 tristate "TI TPS65910 RTC driver" depends on MFD_TPS65910
drivers/rtc/Makefile +1 -0
@@ -175,6 +175,7 @@ obj-$(CONFIG_RTC_DRV_TEGRA) += rtc-tegra.o obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o obj-$(CONFIG_RTC_DRV_TI_K3) += rtc-ti-k3.o obj-$(CONFIG_RTC_DRV_TPS6586X) += rtc-tps6586x.o +obj-$(CONFIG_RTC_DRV_TPS6594) += rtc-tps6594.o obj-$(CONFIG_RTC_DRV_TPS65910) += rtc-tps65910.o obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o obj-$(CONFIG_RTC_DRV_VT8500) += rtc-vt8500.o
drivers/rtc/rtc-tps6594.c new file +463 -0
463 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v5 1/3] rtc: tps6594: Add driver for TPS6594 RTC
Mon, May 22, 2023 at 06:31:13PM +0200, Esteban Blanc kirjoitti:
Quoted 4 lines
TPS6594 PMIC is a MFD. This patch adds support for the RTC found inside TPS6594 family of PMIC.
Alarm is also supported.
...
drivers/rtc/Kconfig config RTC_DRV_TPS6586X · line 591
Quoted 7 lines
drivers/rtc/Kconfig +7
-0+ help + TI Power Management IC TPS6594 supports RTC functionality + along with alarm. This driver supports the RTC driver for + the TPS6594 RTC module. + + This driver can also be built as a module. If so, the module + will be called tps6594-rtc
Grammar period at the end?
...
drivers/rtc/rtc-tps6594.c line 24
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+#define TPS6594_GET_TIME_ON TPS6594_BIT_GET_TIME +#define TPS6594_GET_TIME_OFF 0
Not used.
drivers/rtc/rtc-tps6594.c line 26
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+#define TPS6594_IT_ALARM_ON TPS6594_BIT_IT_ALARM +#define TPS6594_IT_ALARM_OFF 0
Used only once.
Quoted 1 line
+#define
TPS6594_AUTO_COMP_ONTPS6594_BIT_IT_ALARM
No _OFF counterpart.
That said the _OFF can be dropped completely. And the rest I see no value to have, just use those bit definitions directly?
...
drivers/rtc/rtc-tps6594.c line 56
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+static int tps6594_rtc_alarm_irq_enable (struct device *dev, +unsigned int enabled) +{ +struct tps6594 *tps =dev_get_drvdata (dev->parent); +u8 val =0 ;
Redundant assignment.
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ val = enabled ?TPS6594_IT_ALARM_ON :TPS6594_IT_ALARM_OFF ; + +return regmap_update_bits (tps->regmap,TPS6594_REG_RTC_INTERRUPTS , +TPS6594_BIT_IT_ALARM , val); +}
...
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+// Read shadowed RTC registers. + ret =regmap_bulk_read (tps->regmap,TPS6594_REG_RTC_SECONDS , rtc_data, +NUM_TIME_REGS ); +if (ret <0 ) +return ret;
drivers/rtc/rtc-tps6594.c line 118
Quoted 10 lines
drivers/rtc/rtc-tps6594.c new file +10
-0+ + tm->tm_sec =bcd2bin (rtc_data[0 ]); + tm->tm_min =bcd2bin (rtc_data[1 ]); + tm->tm_hour =bcd2bin (rtc_data[2 ]); + tm->tm_mday =bcd2bin (rtc_data[3 ]); + tm->tm_mon =bcd2bin (rtc_data[4 ]) -1 ; + tm->tm_year =bcd2bin (rtc_data[5 ]) +100 ; + tm->tm_wday =bcd2bin (rtc_data[6 ]); + +return ret;
return 0;
No?
...
Quoted 4 lines
drivers/rtc/rtc-tps6594.c new file +4
-0+static int tps6594_rtc_set_calibration (struct device *dev,int calibration) +{ +unsigned char comp_data[NUM_COMP_REGS ]; +struct tps6594 *tps =dev_get_drvdata (dev->parent);
drivers/rtc/rtc-tps6594.c line 223
Quoted 10 lines
drivers/rtc/rtc-tps6594.c new file +10
-0+__le16 value; +int ret; + +/* +* TPS6594 uses two's complement 16 bit value for compensation of RTC +* crystal inaccuracies. One time every hour when seconds counter +* increments from 0 to 1 compensation value will be added to internal +* RTC counter value. +* +* Valid range for compensation value: [-32767 .. 32767].
This is defined naturally by the bits available, correct?
drivers/rtc/rtc-tps6594.c line 225
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+*/ +if (calibration <-32767 || calibration >32767 ) {
So, this can be S16_MIN / S16_MAX range. The question here is what the -32768 meaning is and why it can't be used.
drivers/rtc/rtc-tps6594.c line 228
Quoted 3 lines
drivers/rtc/rtc-tps6594.c new file +3
-0+dev_err (dev,"RTC calibration value out of range: %d\n" , + calibration); +return -EINVAL ;
-ERANGE
drivers/rtc/rtc-tps6594.c line 234
Quoted 6 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ } + value = (__le16 )calibration; + + comp_data[0 ] = value &0xFF ; + comp_data[1 ] = (value >>8 ) &0xFF ;
Of course these three lines is not what expected.
value = cpu_to_le16();
drivers/rtc/rtc-tps6594.c line 238
Quoted 3 lines
drivers/rtc/rtc-tps6594.c new file +3
-0+// Update all the compensation registers in one shot. + ret =regmap_bulk_write (tps->regmap,TPS6594_REG_RTC_COMP_LSB , + comp_data,NUM_COMP_REGS );
&value, sizeof(value) ?
Quoted 7 lines
drivers/rtc/rtc-tps6594.c new file +7
-0+if (ret <0 ) +return ret; + +// Enable automatic compensation. +return regmap_set_bits (tps->regmap,TPS6594_REG_RTC_CTRL_1 , +TPS6594_BIT_AUTO_COMP ); +}
...
drivers/rtc/rtc-tps6594.c line 272
Quoted 8 lines
drivers/rtc/rtc-tps6594.c new file +8
-0+ ret =regmap_bulk_read (tps->regmap,TPS6594_REG_RTC_COMP_LSB , comp_data, +NUM_COMP_REGS ); +if (ret <0 ) +return ret; + + value = (__le16 )comp_data[0 ] | ((__le16 )comp_data[1 ] <<8 ); + + *calibration = value;
In the similar (complementary API) way as above.
...
drivers/rtc/rtc-tps6594.c line 433
Quoted 1 line
drivers/rtc/rtc-tps6594.c new file +1
-0+ ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
Having
struct device *dev = &pdev->dev;
might make this and other lines shorter / neater.
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ tps6594_rtc_interrupt,IRQF_ONESHOT , + TPS6594_IRQ_NAME_ALARM, &pdev->dev); +if (ret <0 ) +return dev_err_probe (&pdev->dev, ret, +"Failed to request_threaded_irq\n" );
Signature · 2 lines
With Best Regards, Andy Shevchenko
Alexandre Belloni
maintainerRe: [PATCH v5 1/3] rtc: tps6594: Add driver for TPS6594 RTC
Quoted 100 lines · On 23/05/2023 16:36:59+0300, [email protected] wrote:
Mon, May 22, 2023 at 06:31:13PM +0200, Esteban Blanc kirjoitti:
Quoted 4 lines
TPS6594 PMIC is a MFD. This patch adds support for the RTC found inside TPS6594 family of PMIC.
Alarm is also supported.
...
drivers/rtc/Kconfig config RTC_DRV_TPS6586X · line 591
Quoted 7 lines
drivers/rtc/Kconfig +7
-0+ help + TI Power Management IC TPS6594 supports RTC functionality + along with alarm. This driver supports the RTC driver for + the TPS6594 RTC module. + + This driver can also be built as a module. If so, the module + will be called tps6594-rtcGrammar period at the end?
...
drivers/rtc/rtc-tps6594.c line 24
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+#define TPS6594_GET_TIME_ON TPS6594_BIT_GET_TIME +#define TPS6594_GET_TIME_OFF 0Not used.
drivers/rtc/rtc-tps6594.c line 26
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+#define TPS6594_IT_ALARM_ON TPS6594_BIT_IT_ALARM +#define TPS6594_IT_ALARM_OFF 0Used only once.
Quoted 1 line
+#define
TPS6594_AUTO_COMP_ONTPS6594_BIT_IT_ALARMNo
_OFFcounterpart.That said the
_OFFcan be dropped completely. And the rest I see no value to have, just use those bit definitions directly?...
drivers/rtc/rtc-tps6594.c line 56
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+static int tps6594_rtc_alarm_irq_enable (struct device *dev, +unsigned int enabled) +{ +struct tps6594 *tps =dev_get_drvdata (dev->parent); +u8 val =0 ;Redundant assignment.
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ val = enabled ?TPS6594_IT_ALARM_ON :TPS6594_IT_ALARM_OFF ; + +return regmap_update_bits (tps->regmap,TPS6594_REG_RTC_INTERRUPTS , +TPS6594_BIT_IT_ALARM , val); +}...
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+// Read shadowed RTC registers. + ret =regmap_bulk_read (tps->regmap,TPS6594_REG_RTC_SECONDS , rtc_data, +NUM_TIME_REGS ); +if (ret <0 ) +return ret;drivers/rtc/rtc-tps6594.c line 118
Quoted 10 lines
drivers/rtc/rtc-tps6594.c new file +10
-0+ + tm->tm_sec =bcd2bin (rtc_data[0 ]); + tm->tm_min =bcd2bin (rtc_data[1 ]); + tm->tm_hour =bcd2bin (rtc_data[2 ]); + tm->tm_mday =bcd2bin (rtc_data[3 ]); + tm->tm_mon =bcd2bin (rtc_data[4 ]) -1 ; + tm->tm_year =bcd2bin (rtc_data[5 ]) +100 ; + tm->tm_wday =bcd2bin (rtc_data[6 ]); + +return ret;return 0;No?
...
Quoted 4 lines
drivers/rtc/rtc-tps6594.c new file +4
-0+static int tps6594_rtc_set_calibration (struct device *dev,int calibration) +{ +unsigned char comp_data[NUM_COMP_REGS ]; +struct tps6594 *tps =dev_get_drvdata (dev->parent);drivers/rtc/rtc-tps6594.c line 223
Quoted 10 lines
drivers/rtc/rtc-tps6594.c new file +10
-0+__le16 value; +int ret; + +/* +* TPS6594 uses two's complement 16 bit value for compensation of RTC +* crystal inaccuracies. One time every hour when seconds counter +* increments from 0 to 1 compensation value will be added to internal +* RTC counter value. +* +* Valid range for compensation value: [-32767 .. 32767]. This is defined naturally by the bits available, correct?
drivers/rtc/rtc-tps6594.c line 225
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+*/ +if (calibration <-32767 || calibration >32767 ) {So, this can be
S16_MIN/S16_MAXrange. The question here is what the -32768 meaning is and why it can't be used.
Quoted 6 lines
drivers/rtc/rtc-tps6594.c line 228
Quoted 3 lines
drivers/rtc/rtc-tps6594.c new file +3
-0+dev_err (dev,"RTC calibration value out of range: %d\n" , + calibration); +return -EINVAL ;
-ERANGE
And after using -ERANGE, you can drop the dev_err string.
Quoted 59 lines
drivers/rtc/rtc-tps6594.c line 234
Quoted 6 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ } + value = (__le16 )calibration; + + comp_data[0 ] = value &0xFF ; + comp_data[1 ] = (value >>8 ) &0xFF ;Of course these three lines is not what expected.
value = cpu_to_le16();drivers/rtc/rtc-tps6594.c line 238
Quoted 3 lines
drivers/rtc/rtc-tps6594.c new file +3
-0+// Update all the compensation registers in one shot. + ret =regmap_bulk_write (tps->regmap,TPS6594_REG_RTC_COMP_LSB , + comp_data,NUM_COMP_REGS );&value, sizeof(value) ?
Quoted 7 lines
drivers/rtc/rtc-tps6594.c new file +7
-0+if (ret <0 ) +return ret; + +// Enable automatic compensation. +return regmap_set_bits (tps->regmap,TPS6594_REG_RTC_CTRL_1 , +TPS6594_BIT_AUTO_COMP ); +}...
drivers/rtc/rtc-tps6594.c line 272
Quoted 8 lines
drivers/rtc/rtc-tps6594.c new file +8
-0+ ret =regmap_bulk_read (tps->regmap,TPS6594_REG_RTC_COMP_LSB , comp_data, +NUM_COMP_REGS ); +if (ret <0 ) +return ret; + + value = (__le16 )comp_data[0 ] | ((__le16 )comp_data[1 ] <<8 ); + + *calibration = value;In the similar (complementary API) way as above.
...
drivers/rtc/rtc-tps6594.c line 433
Quoted 1 line
drivers/rtc/rtc-tps6594.c new file +1
-0+ ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,Having
struct device *dev = &pdev->dev;might make this and other lines shorter / neater.
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ tps6594_rtc_interrupt,IRQF_ONESHOT , + TPS6594_IRQ_NAME_ALARM, &pdev->dev); +if (ret <0 ) +return dev_err_probe (&pdev->dev, ret, +"Failed to request_threaded_irq\n" );Signature · 2 lines
With Best Regards, Andy Shevchenko
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v5 1/3] rtc: tps6594: Add driver for TPS6594 RTC
In reply to [email protected]Quoted 8 lines · CEST,
Mon, May 22, 2023 at 06:31:13PM +0200, Esteban Blanc kirjoitti:
Quoted 4 lines
TPS6594 PMIC is a MFD. This patch adds support for the RTC found inside TPS6594 family of PMIC.
Alarm is also supported.
...
Quoted 9 lines
drivers/rtc/Kconfig config RTC_DRV_TPS6586X · line 591
Quoted 7 lines
drivers/rtc/Kconfig +7
-0+ help + TI Power Management IC TPS6594 supports RTC functionality + along with alarm. This driver supports the RTC driver for + the TPS6594 RTC module. + + This driver can also be built as a module. If so, the module + will be called tps6594-rtcGrammar period at the end?
Thanks!
Quoted 4 lines
drivers/rtc/rtc-tps6594.c line 24
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+#define TPS6594_GET_TIME_ON TPS6594_BIT_GET_TIME +#define TPS6594_GET_TIME_OFF 0Not used.
Thanks.
Quoted 5 lines
drivers/rtc/rtc-tps6594.c line 26
Quoted 3 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+#define TPS6594_IT_ALARM_ON TPS6594_BIT_IT_ALARM +#define TPS6594_IT_ALARM_OFF 0Used only once.
True. Is that a bad thing?
Quoted 6 lines
Quoted 1 line
+#define
TPS6594_AUTO_COMP_ONTPS6594_BIT_IT_ALARMNo
_OFFcounterpart.That said the
_OFFcan be dropped completely. And the rest I see no value to have, just use those bit definitions directly?
I was thinking it would make this more readable. I will remove them, no problem.
Quoted 8 lines
drivers/rtc/rtc-tps6594.c line 56
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+static int tps6594_rtc_alarm_irq_enable (struct device *dev, +unsigned int enabled) +{ +struct tps6594 *tps =dev_get_drvdata (dev->parent); +u8 val =0 ;Redundant assignment.
Thanks!
Quoted 18 lines
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+// Read shadowed RTC registers. + ret =regmap_bulk_read (tps->regmap,TPS6594_REG_RTC_SECONDS , rtc_data, +NUM_TIME_REGS ); +if (ret <0 ) +return ret;drivers/rtc/rtc-tps6594.c line 118
Quoted 10 lines
drivers/rtc/rtc-tps6594.c new file +10
-0+ + tm->tm_sec =bcd2bin (rtc_data[0 ]); + tm->tm_min =bcd2bin (rtc_data[1 ]); + tm->tm_hour =bcd2bin (rtc_data[2 ]); + tm->tm_mday =bcd2bin (rtc_data[3 ]); + tm->tm_mon =bcd2bin (rtc_data[4 ]) -1 ; + tm->tm_year =bcd2bin (rtc_data[5 ]) +100 ; + tm->tm_wday =bcd2bin (rtc_data[6 ]); + +return ret;return 0;
Quoted 1 line
No?
regmap_bulk_read returns 0 on success so ret should be 0 here. I will apply your suggestion anyway it is more readable. Thanks!
Quoted 8 lines
Quoted 8 lines
drivers/rtc/rtc-tps6594.c new file +8
-0+static int tps6594_rtc_set_calibration (struct device *dev,int calibration) +{ +unsigned char comp_data[NUM_COMP_REGS ]; +struct tps6594 *tps =dev_get_drvdata (dev->parent); +__le16 value; +int ret; + +/*
Quoted 8 lines
drivers/rtc/rtc-tps6594.c line 223
Quoted 6 lines
drivers/rtc/rtc-tps6594.c new file +6
-0+* TPS6594 uses two's complement 16 bit value for compensation of RTC +* crystal inaccuracies. One time every hour when seconds counter +* increments from 0 to 1 compensation value will be added to internal +* RTC counter value. +* +* Valid range for compensation value: [-32767 .. 32767]. This is defined naturally by the bits available, correct?
Your right. Maybe calibration argument should be an s16 instead of an int?
Quoted 5 lines
drivers/rtc/rtc-tps6594.c line 225
Quoted 2 lines
drivers/rtc/rtc-tps6594.c new file +2
-0+*/ +if (calibration <-32767 || calibration >32767 ) {So, this can be
S16_MIN/S16_MAXrange. The question here is what the -32768 meaning is and why it can't be used.
I will rewrite it using this 2 macros.
This range [-32767,32767] is specified in the datasheet. As for why -32768 can't be used I have no idea.
Quoted 5 lines
drivers/rtc/rtc-tps6594.c line 228
Quoted 3 lines
drivers/rtc/rtc-tps6594.c new file +3
-0+dev_err (dev,"RTC calibration value out of range: %d\n" , + calibration); +return -EINVAL ;
-ERANGE
Ok, thanks.
Quoted 10 lines
drivers/rtc/rtc-tps6594.c line 234
Quoted 6 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ } + value = (__le16 )calibration; + + comp_data[0 ] = value &0xFF ; + comp_data[1 ] = (value >>8 ) &0xFF ;Of course these three lines is not what expected.
value = cpu_to_le16();
Sorry for the mistake. I've tried to find more information on those type but I did not realize there was specific functions/macros for them.
I have learn something today :)
Quoted 5 lines
drivers/rtc/rtc-tps6594.c line 238
Quoted 3 lines
drivers/rtc/rtc-tps6594.c new file +3
-0+// Update all the compensation registers in one shot. + ret =regmap_bulk_write (tps->regmap,TPS6594_REG_RTC_COMP_LSB , + comp_data,NUM_COMP_REGS );&value, sizeof(value) ?
This is way cleaner indeed.
Quoted 8 lines
Quoted 7 lines
drivers/rtc/rtc-tps6594.c new file +7
-0+if (ret <0 ) +return ret; + +// Enable automatic compensation. +return regmap_set_bits (tps->regmap,TPS6594_REG_RTC_CTRL_1 , +TPS6594_BIT_AUTO_COMP ); +}
Quoted 10 lines
drivers/rtc/rtc-tps6594.c line 272
Quoted 8 lines
drivers/rtc/rtc-tps6594.c new file +8
-0+ ret =regmap_bulk_read (tps->regmap,TPS6594_REG_RTC_COMP_LSB , comp_data, +NUM_COMP_REGS ); +if (ret <0 ) +return ret; + + value = (__le16 )comp_data[0 ] | ((__le16 )comp_data[1 ] <<8 ); + + *calibration = value;In the similar (complementary API) way as above.
Sure.
Quoted 7 lines
drivers/rtc/rtc-tps6594.c line 433
Quoted 1 line
drivers/rtc/rtc-tps6594.c new file +1
-0+ ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,Having
struct device *dev = &pdev->dev;might make this and other lines shorter / neater.
Will do, thanks.
Quoted 5 lines
drivers/rtc/rtc-tps6594.c line 438
Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5
-0+ tps6594_rtc_interrupt,IRQF_ONESHOT , + TPS6594_IRQ_NAME_ALARM, &pdev->dev); +if (ret <0 ) +return dev_err_probe (&pdev->dev, ret, +"Failed to request_threaded_irq\n" );
Thanks for your review.
Best regards,
--
Esteban Blanc
BayLibre
PATCH v5 2/3 pinctrl: tps6594: Add driver for TPS6594 pinctrl and GPIOs
In reply to Esteban BlancTI TPS6594 PMIC has 11 GPIOs which can be used
for different functions.
This patch adds a pinctrl and GPIO drivers in
order to use those functions.
--- drivers/pinctrl/Kconfig | 13 ++ drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-tps6594.c | 367 ++++++++++++++++++++++++++++++ include/linux/mfd/tps6594.h | 3 +- 4 files changed, 383 insertions(+), 1 deletion(-) create mode 100644 drivers/pinctrl/pinctrl-tps6594.c
drivers/pinctrl/Kconfig +13 -0
@@ -480,6 +480,19 @@ config PINCTRL_TB10X depends on OF && ARC_PLAT_TB10X select GPIOLIB +config PINCTRL_TPS6594 + tristate "Pinctrl and GPIO driver for TI TPS6594 PMIC" + depends on MFD_TPS6594 + default MFD_TPS6594 + select PINMUX + select GPIOLIB + select REGMAP + select GPIO_REGMAP + help + Say Y to select the pinmuxing and GPIOs driver for the TPS6594 + PMICs chip family. This driver can also be built as a module + called tps6594-pinctrl. + config PINCTRL_ZYNQ bool "Pinctrl driver for Xilinx Zynq" depends on ARCH_ZYNQ
drivers/pinctrl/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o obj-$(CONFIG_PINCTRL_STMFX) += pinctrl-stmfx.o obj-$(CONFIG_PINCTRL_SX150X) += pinctrl-sx150x.o obj-$(CONFIG_PINCTRL_TB10X) += pinctrl-tb10x.o +obj-$(CONFIG_PINCTRL_TPS6594) += pinctrl-tps6594.o obj-$(CONFIG_PINCTRL_ZYNQMP) += pinctrl-zynqmp.o obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o
drivers/pinctrl/pinctrl-tps6594.c new file +367 -0
367 lines not on this page · raw message
include/linux/mfd/tps6594.h +2 -1
@@ -47,7 +47,8 @@ enum pmic_id {#define TPS6594_REG_VMON2_PG_WINDOW 0x2f#define TPS6594_REG_VMON2_PG_LEVEL 0x30 -#define TPS6594_REG_GPIOX_CONF (gpio_inst) (0x31 + (gpio_inst)) +// Used to compute register address of GPIO1_CONF to GPIO11_CONF +#define TPS6594_REG_GPIOX_CONF (gpio_inst) (0x31 + (gpio_inst))#define TPS6594_REG_NPWRON_CONF 0x3c#define TPS6594_REG_GPIO_OUT_1 0x3d#define TPS6594_REG_GPIO_OUT_2 0x3e
Signature · 1 line
2.39.2
Re: [PATCH v5 2/3] pinctrl: tps6594: Add driver for TPS6594 pinctrl and GPIOs
Mon, May 22, 2023 at 06:31:14PM +0200, Esteban Blanc kirjoitti:
Quoted 5 lines
TI TPS6594 PMIC has 11 GPIOs which can be used
for different functions.This patch adds a pinctrl and GPIO drivers in
order to use those functions.
...
drivers/pinctrl/pinctrl-tps6594.c line 48
Quoted 5 lines
drivers/pinctrl/pinctrl-tps6594.c new file +5
-0+#define FUNCTION (n, g, v) \ + { \ + .pinfunction = PINCTRL_PINFUNCTION((n), (g), ARRAY_SIZE(g)), \ + .muxval = v, \ + }
It seems you have used SPACEs before \, can you move to TABs?
...
Quoted 12 lines
drivers/pinctrl/pinctrl-tps6594.c new file +12
-0+static int tps6594_gpio_regmap_xlate (struct gpio_regmap *gpio, +unsigned int base,unsigned int offset, +unsigned int *reg,unsigned int *mask) +{ +unsigned int line = offset %8 ; +unsigned int stride = offset /8 ; + +switch (base) { +case TPS6594_REG_GPIO1_CONF : + *reg =TPS6594_REG_GPIOX_CONF (offset); + *mask =TPS6594_BIT_GPIO_DIR ; +break ;
drivers/pinctrl/pinctrl-tps6594.c line 199
Quoted 10 lines
drivers/pinctrl/pinctrl-tps6594.c new file +9
-0+case TPS6594_REG_GPIO_IN_1 : +case TPS6594_REG_GPIO_OUT_1 : + *reg = base + stride; + *mask =BIT (line); +break ; +default : +return -EINVAL ; + } +return 0 ;
You can return directly instead of breaking.
drivers/pinctrl/pinctrl-tps6594.c line 334
Quoted 5 lines
drivers/pinctrl/pinctrl-tps6594.c new file +4
-0+} + pinctrl->pins = tps6594_pins; + pinctrl->pctl_dev = +devm_pinctrl_register (&pdev->dev, pctrl_desc, pinctrl);
With
struct device *dev = &pdev->dev;
the above becomes a single line. This may help other similar uses.
drivers/pinctrl/pinctrl-tps6594.c line 338
Quoted 4 lines
drivers/pinctrl/pinctrl-tps6594.c new file +4
-0+if (IS_ERR (pinctrl->pctl_dev)) { +return dev_err_probe (&pdev->dev,PTR_ERR (pinctrl->pctl_dev), +"Couldn't register pinctrl driver\n" ); + }
Also the {} can be dropped.
...
drivers/pinctrl/pinctrl-tps6594.c line 353
Quoted 5 lines
drivers/pinctrl/pinctrl-tps6594.c new file +5
-0+ pinctrl->gpio_regmap =devm_gpio_regmap_register (&pdev->dev, &config); +if (IS_ERR (pinctrl->gpio_regmap)) { +return dev_err_probe (&pdev->dev,PTR_ERR (pinctrl->gpio_regmap), +"Couldn't register gpio_regmap driver\n" ); + }
Ditto.
...
drivers/pinctrl/pinctrl-tps6594.c line 359
Quoted 2 lines
drivers/pinctrl/pinctrl-tps6594.c new file +2
-0+static struct platform_driver tps6594_pinctrl_driver = { + .driver = { .name ="tps6594-pinctrl" },
Can you use more standard way of style here, i.e.
.driver = {
.name = "tps6594-pinctrl",
},In case someone is going to add something there in the future it will become just as cleaner as possible.
drivers/pinctrl/pinctrl-tps6594.c line 363
Quoted 4 lines
drivers/pinctrl/pinctrl-tps6594.c new file +4
-0+ .probe = tps6594_pinctrl_probe, +}; + +module_platform_driver (tps6594_pinctrl_driver);
Move the above blank line here.
Quoted 2 lines
drivers/pinctrl/pinctrl-tps6594.c new file +2
-0+MODULE_ALIAS ("platform:tps6594-pinctrl" ); +MODULE_AUTHOR ("Esteban Blanc <[email protected]>" );
...
Quoted 1 line
+// Used to compute register address of
GPIO1_CONFtoGPIO11_CONF
This is good.
include/linux/mfd/tps6594.h enum pmic_id { · line 51
Quoted 2 lines
include/linux/mfd/tps6594.h +1
-1-#define TPS6594_REG_GPIOX_CONF (gpio_inst) (0x31 + (gpio_inst)) +#define TPS6594_REG_GPIOX_CONF (gpio_inst) (0x31 + (gpio_inst))
But why this?!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 2/3] pinctrl: tps6594: Add driver for TPS6594 pinctrl and GPIOs
Quoted 9 lines · CEST,
Mon, May 22, 2023 at 06:31:14PM +0200, Esteban Blanc kirjoitti:
Quoted 5 lines
TI TPS6594 PMIC has 11 GPIOs which can be used
for different functions.This patch adds a pinctrl and GPIO drivers in
order to use those functions....
Quoted 7 lines
drivers/pinctrl/pinctrl-tps6594.c line 48
Quoted 5 lines
drivers/pinctrl/pinctrl-tps6594.c new file +5
-0+#define FUNCTION (n, g, v) \ + { \ + .pinfunction = PINCTRL_PINFUNCTION((n), (g), ARRAY_SIZE(g)), \ + .muxval = v, \ + }It seems you have used SPACEs before \, can you move to TABs?
Once again clang-format is not doing the right thing. Sur I will fix this.
Quoted 8 lines
Quoted 1 line
+// Used to compute register address of
GPIO1_CONFtoGPIO11_CONFThis is good.
include/linux/mfd/tps6594.h enum pmic_id { · line 51
Quoted 2 lines
include/linux/mfd/tps6594.h +1
-1-#define TPS6594_REG_GPIOX_CONF (gpio_inst) (0x31 + (gpio_inst)) +#define TPS6594_REG_GPIOX_CONF (gpio_inst) (0x31 + (gpio_inst))But why this?!
Once again, clang-format... I will fix this.
Thanks for your help.
Best regards,
Signature · 2 lines
Esteban Blanc BayLibre
Re: [PATCH v5 2/3] pinctrl: tps6594: Add driver for TPS6594 pinctrl and GPIOs
Quoted 2 lines · Esteban Blanc
Quoted 1 line · CEST,
Mon, May 22, 2023 at 06:31:14PM +0200, Esteban Blanc kirjoitti:
...
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+// Used to compute register address of
GPIO1_CONFtoGPIO11_CONFThis is good.
Btw
the register
and shouldn't it start from GPIO0_CONF (please, double check, my memory can do tricks on me)?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 2/3] pinctrl: tps6594: Add driver for TPS6594 pinctrl and GPIOs
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Esteban Blanc
Quoted 1 line · CEST,
Mon, May 22, 2023 at 06:31:14PM +0200, Esteban Blanc kirjoitti:
...
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+// Used to compute register address of
GPIO1_CONFtoGPIO11_CONFThis is good.
Btw
the register
Ah yes, thanks.
Quoted 2 lines
and shouldn't it start from
GPIO0_CONF(please, double check, my memory can do tricks on me)?
On Linux side it is GPIO0 but on datasheet side it is GPIO1_CONF to GPIO11_CONF. I was referring to the "real" register names (datasheet ones)
Quoted 4 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
PATCH v5 3/3 regulator: tps6594-regulator: Add driver for TI TPS6594 regulators
In reply to Esteban BlancFrom: Jerome Neanne <[email protected]>
This patch adds support for TPS6594 regulators (bucks and LDOs). The output voltages are configurable and are meant to supply power to the main processor and other components.
Bucks can be used in single or multiphase mode, depending on PMIC part number.
--- drivers/regulator/Kconfig | 13 + drivers/regulator/Makefile | 1 + drivers/regulator/tps6594-regulator.c | 615 ++++++++++++++++++++++++++ 3 files changed, 629 insertions(+) create mode 100644 drivers/regulator/tps6594-regulator.c
drivers/regulator/Kconfig +13 -0
@@ -1463,6 +1463,19 @@ config REGULATOR_TPS65219 voltage regulators. It supports software based voltage control for different voltage domains. +config REGULATOR_TPS6594 + tristate "TI TPS6594 Power regulators" + depends on MFD_TPS6594 && OF + default MFD_TPS6594 + help + This driver supports TPS6594 voltage regulator chips. + TPS6594 series of PMICs have 5 BUCKs and 4 LDOs + voltage regulators. + BUCKs 1,2,3,4 can be used in single phase or multiphase mode. + Part number defines which single or multiphase mode is i used. + It supports software based voltage control + for different voltage domains. + config REGULATOR_TPS6524X tristate "TI TPS6524X Power regulators" depends on SPI
drivers/regulator/Makefile +1 -0
@@ -174,6 +174,7 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o +obj-$(CONFIG_REGULATOR_TPS6594) += tps6594-regulator.o obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
drivers/regulator/tps6594-regulator.c new file +615 -0
615 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v5 3/3] regulator: tps6594-regulator: Add driver for TI TPS6594 regulators
Mon, May 22, 2023 at 06:31:15PM +0200, Esteban Blanc kirjoitti:
Quoted 3 lines
From: Jerome Neanne <[email protected]>
This patch adds support for TPS6594 regulators (bucks and LDOs).
BUCKs (otherwise $$$?)
Quoted 3 lines
The output voltages are configurable and are meant to supply power to the main processor and other components.
Bucks can be used in single or multiphase mode, depending on PMIC
BUCKs (otherwise $$$?)
Quoted 1 line
part number.
...
drivers/regulator/Kconfig config REGULATOR_TPS65219 · line 1475
Quoted 6 lines
drivers/regulator/Kconfig +6
-0+ help + This driver supports TPS6594 voltage regulator chips. + TPS6594 series of PMICs have 5 BUCKs and 4 LDOs + voltage regulators. + BUCKs 1,2,3,4 can be used in single phase or multiphase mode. + Part number defines which single or multiphase mode is i used.
i?!
Quoted 2 lines
drivers/regulator/Kconfig +2
-0+ It supports software based voltage control + for different voltage domains.
...
drivers/regulator/tps6594-regulator.c line 12
Quoted 7 lines
drivers/regulator/tps6594-regulator.c new file +6
-0+#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of_device.h>
Are you sure this one is correct and / or of.h is not missing? of_match_ptr() IIRC is defined in of.h.
Quoted 5 lines
drivers/regulator/tps6594-regulator.c new file +5
-0+#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/machine.h> +#include <linux/regulator/of_regulator.h>
...
drivers/regulator/tps6594-regulator.c line 135
Quoted 12 lines
drivers/regulator/tps6594-regulator.c new file +11
-0+/* Operations permitted on BUCK1/2/3/4/5 */ +static const struct regulator_ops tps6594_bucks_ops = { + .is_enabled = regulator_is_enabled_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, + .set_voltage_time_sel = regulator_set_voltage_time_sel, +
Redundant blank line.
Quoted 1 line
+};
...
Quoted 9 lines
drivers/regulator/tps6594-regulator.c new file +9
-0+int error; + +for (j =0 ; j <REGS_INT_NB ; j++) { + irq_type = &tps6594_regs_irq_types[j]; + irq =platform_get_irq_byname (pdev, irq_type->irq_name); +if (irq <0 ) +return -EINVAL ; + + irq_data[*irq_idx + j].dev = tps->dev;
drivers/regulator/tps6594-regulator.c line 396
Quoted 10 lines
drivers/regulator/tps6594-regulator.c new file +9
-0+ irq_data[*irq_idx + j].type = irq_type; + irq_data[*irq_idx + j].rdev = rdev; + + error =devm_request_threaded_irq (tps->dev, irq,NULL , + tps6594_regulator_irq_handler, +IRQF_ONESHOT , + irq_type->irq_name, + &irq_data[*irq_idx]); + (*irq_idx)++;
This is interesing. So, even in error case we touch given parameter. Usually the pattern is not to touch the output if we know there is an error.
Quoted 6 lines
drivers/regulator/tps6594-regulator.c new file +6
-0+if (error) { +dev_err (tps->dev,"tps6594 failed to request %s IRQ %d: %d\n" , + irq_type->irq_name, irq, error); +return error; + } + }
...
drivers/regulator/tps6594-regulator.c line 417
Quoted 2 lines
drivers/regulator/tps6594-regulator.c new file +2
-0+u8 buck_configured[BUCK_NB ] = {0 }; +u8 buck_multi[MULTI_PHASE_NB ] = {0 };
0:s are not needed but I dunno if it's a style in the regulator subsystem.
drivers/regulator/tps6594-regulator.c line 424
Quoted 8 lines
drivers/regulator/tps6594-regulator.c new file +7
-0+static const char *const multiphases[] = {"buck12" ,"buck123" ,"buck1234" ,"buck34" }; +static const char *npname; +int error, i, irq, multi, delta; +int irq_idx =0 ; +int buck_idx =0 ; +int ext_reg_irq_nb =2 ; +
Redundant blank line.
drivers/regulator/tps6594-regulator.c line 432
Quoted 9 lines
drivers/regulator/tps6594-regulator.c new file +8
-0+enum { +MULTI_BUCK12 , +MULTI_BUCK123 , +MULTI_BUCK1234 , +MULTI_BUCK12_34 , +MULTI_FIRST =MULTI_BUCK12 , +MULTI_LAST =MULTI_BUCK12_34 , +MULTI_NUM =MULTI_LAST -MULTI_FIRST +1
MULT_NUM
will suffice instead all this.
Review
Quoted 1 line
(quoted diff) +1
-0+ };
But why enum at all? See below.
...
drivers/regulator/tps6594-regulator.c line 451
Quoted 13 lines
drivers/regulator/tps6594-regulator.c new file +13
-0+/* +* Switch case defines different possible multi phase config +* This is based on dts buck node name. +* Buck node name must be chosen accordingly. +* Default case is no Multiphase buck. +* In case of Multiphase configuration, value should be defined for +* buck_configured to avoid creating bucks for every buck in multiphase +*/ +for (multi =MULTI_FIRST ; multi <MULTI_NUM ; multi++) { + np =of_find_node_by_name (tps->dev->of_node, multiphases[multi]); + npname =of_node_full_name (np); + np_pmic_parent =of_get_parent (of_get_parent (np)); +if (of_node_cmp (of_node_full_name (np_pmic_parent), tps->dev->of_node->full_name))
Why not of_node_full_name() in the second case?
drivers/regulator/tps6594-regulator.c line 456
Quoted 5 lines
drivers/regulator/tps6594-regulator.c new file +5
-0+continue ; + delta =strcmp (npname, multiphases[multi]); +if (!delta) { +switch (multi) { +case MULTI_BUCK12 :
This all looks like match_string() reinvention.
Quoted 29 lines
drivers/regulator/tps6594-regulator.c new file +29
-0+ buck_multi[0 ] =1 ; + buck_configured[0 ] =1 ; + buck_configured[1 ] =1 ; +break ; +/* multiphase buck34 is supported only with buck12 */ +case MULTI_BUCK12_34 : + buck_multi[0 ] =1 ; + buck_multi[1 ] =1 ; + buck_configured[0 ] =1 ; + buck_configured[1 ] =1 ; + buck_configured[2 ] =1 ; + buck_configured[3 ] =1 ; +break ; +case MULTI_BUCK123 : + buck_multi[2 ] =1 ; + buck_configured[0 ] =1 ; + buck_configured[1 ] =1 ; + buck_configured[2 ] =1 ; +break ; +case MULTI_BUCK1234 : + buck_multi[3 ] =1 ; + buck_configured[0 ] =1 ; + buck_configured[1 ] =1 ; + buck_configured[2 ] =1 ; + buck_configured[3 ] =1 ; +break ; + } + } + }
...
drivers/regulator/tps6594-regulator.c line 495
Quoted 5 lines
drivers/regulator/tps6594-regulator.c new file +5
-0+ irq_data =devm_kmalloc_array (tps->dev, +REGS_INT_NB *sizeof (struct tps6594_regulator_irq_data ), +ARRAY_SIZE (tps6594_bucks_irq_types) + +ARRAY_SIZE (tps6594_ldos_irq_types), +GFP_KERNEL );
Have you checked overflow.h? There are macros to help with the above calculus.
Quoted 2 lines
drivers/regulator/tps6594-regulator.c new file +2
-0+if (!irq_data) +return -ENOMEM ;
...
drivers/regulator/tps6594-regulator.c line 505
Quoted 3 lines
drivers/regulator/tps6594-regulator.c new file +3
-0+ rdev =devm_regulator_register (&pdev->dev, &multi_regs[i], &config); +if (IS_ERR (rdev)) + return dev_err_probe(tps->dev, PTR_ERR(rdev),
Why not &pdev->dev here?
Quoted 2 lines
(quoted diff) +2
-0+ "failed to register %s regulator\n", + pdev->name);
...
drivers/regulator/tps6594-regulator.c line 545
Quoted 5 lines
drivers/regulator/tps6594-regulator.c new file +5
-0+ rdev =devm_regulator_register (&pdev->dev, &buck_regs[i], &config); +if (IS_ERR (rdev)) +return dev_err_probe (tps->dev,PTR_ERR (rdev), +"failed to register %s regulator\n" , + pdev->name);
Hmm... Again, why the error is printed against different device than regulator registration?
...
Quoted 8 lines
drivers/regulator/tps6594-regulator.c new file +8
-0+/* LP8764 dosen't have LDO */ +if (tps->chip_id !=LP8764 ) { +for (i =0 ; i <ARRAY_SIZE (ldo_regs); i++) { + rdev =devm_regulator_register (&pdev->dev, &ldo_regs[i], &config); +if (IS_ERR (rdev)) +return dev_err_probe (tps->dev,PTR_ERR (rdev), +"failed to register %s regulator\n" , + pdev->name);
drivers/regulator/tps6594-regulator.c line 570
Quoted 10 lines
drivers/regulator/tps6594-regulator.c new file +10
-0+ + error =tps6594_request_reg_irqs (pdev, rdev, irq_data, + tps6594_ldos_irq_types[i], + &irq_idx); +if (error) +return error; + } + } + +if (tps->chip_id ==LP8764 )
'else'?
Or actually
if (tps->chip_id == LP8764) {
...
} else {
the above part
}?
Quoted 1 line
drivers/regulator/tps6594-regulator.c new file +1
-0+ ext_reg_irq_nb =ARRAY_SIZE (tps6594_ext_regulator_irq_types);
...
drivers/regulator/tps6594-regulator.c line 609
Quoted 8 lines
drivers/regulator/tps6594-regulator.c new file +7
-0+static struct platform_driver tps6594_regulator_driver = { + .driver = { + .name ="tps6594-regulator" , + }, + .probe = tps6594_regulator_probe, +}; +
This blank line is not needed.
Quoted 1 line
+module_platform_driver(tps6594_regulator_driver);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v5 3/3] regulator: tps6594-regulator: Add driver for TI TPS6594 regulators
Quoted 14 lines
drivers/regulator/tps6594-regulator.c line 432
Quoted 11 lines
drivers/regulator/tps6594-regulator.c new file +8
-0+enum { +MULTI_BUCK12 , +MULTI_BUCK123 , +MULTI_BUCK1234 , +MULTI_BUCK12_34 , +MULTI_FIRST =MULTI_BUCK12 , +MULTI_LAST =MULTI_BUCK12_34 , +MULTI_NUM =MULTI_LAST -MULTI_FIRST +1
MULT_NUM
Quoted 5 lines
will suffice instead all this.
Review
Quoted 1 line
(quoted diff) +1
-0+ };But why enum at all? See below.
Just for the switch case readability.
I have to iterate across the multiphases array for look up name into device tree and evaluate in that order.
This can be reduced to:
enum {
MULTI_BUCK12,
MULTI_BUCK123,
MULTI_BUCK1234,
MULTI_BUCK12_34,
MULTI_NUM = MULTI_BUCK12_34 - MULTI_BUCK12 + 1
};Quoted 18 lines
...
drivers/regulator/tps6594-regulator.c line 451
Quoted 13 lines
drivers/regulator/tps6594-regulator.c new file +13
-0+/* +* Switch case defines different possible multi phase config +* This is based on dts buck node name. +* Buck node name must be chosen accordingly. +* Default case is no Multiphase buck. +* In case of Multiphase configuration, value should be defined for +* buck_configured to avoid creating bucks for every buck in multiphase +*/ +for (multi =MULTI_FIRST ; multi <MULTI_NUM ; multi++) { + np =of_find_node_by_name (tps->dev->of_node, multiphases[multi]); + npname =of_node_full_name (np); + np_pmic_parent =of_get_parent (of_get_parent (np)); +if (of_node_cmp (of_node_full_name (np_pmic_parent), tps->dev->of_node->full_name))Why not
of_node_full_name()in the second case?
Sure.
Quoted 9 lines
drivers/regulator/tps6594-regulator.c line 456
Quoted 7 lines
drivers/regulator/tps6594-regulator.c new file +5
-0+continue ; + delta =strcmp (npname, multiphases[multi]); +if (!delta) { +switch (multi) { +case MULTI_BUCK12 :This all looks like
match_string()reinvention.
I can go with match_string but this is not significantly changing the game:
index = match_string(multiphases, ARRAY_SIZE(multiphases), npname);
if (index >= 0) {
switch (index) {No question on all your other feedback. Just wondering if I missed something with match_string use. Looks like a good idea indeed but this is not drastically changing the code as you seem to expect... Let me know if you think I'm doing it in a wrong way.
Regards,
Jerome.
Re: [PATCH v5 3/3] regulator: tps6594-regulator: Add driver for TI TPS6594 regulators
On Wed, Jun 7, 2023 at 2:44 PM jerome Neanne <[email protected]> wrote:
...
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/regulator/tps6594-regulator.c new file +5
-0+enum { +MULTI_BUCK12 , +MULTI_BUCK123 , +MULTI_BUCK1234 , +MULTI_BUCK12_34 ,
Quoted 7 lines
Quoted 7 lines
drivers/regulator/tps6594-regulator.c line 432
Quoted 3 lines
drivers/regulator/tps6594-regulator.c new file +3
-0+MULTI_FIRST =MULTI_BUCK12 , +MULTI_LAST =MULTI_BUCK12_34 , +MULTI_NUM =MULTI_LAST -MULTI_FIRST +1
MULT_NUMwill suffice instead of all this.
(1)
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ };
But why enum at all? See below.
Just for the switch case readability.
I have to iterate across the multiphases array for look up name into device tree and evaluate in that order.
Quoted 8 lines
This can be reduced to:
enum { MULTI_BUCK12, MULTI_BUCK123, MULTI_BUCK1234, MULTI_BUCK12_34, MULTI_NUM = MULTI_BUCK12_34 - MULTI_BUCK12 + 1
See (1) above.
Quoted 1 line
};
...
Quoted 9 lines
Quoted 7 lines
drivers/regulator/tps6594-regulator.c line 456
Quoted 5 lines
drivers/regulator/tps6594-regulator.c new file +5
-0+continue ; + delta =strcmp (npname, multiphases[multi]); +if (!delta) { +switch (multi) { +case MULTI_BUCK12 :This all looks like
match_string()reinvention.I can go with
match_stringbut this is not significantly changing the game:
Quoted 8 lines
index =
match_string(multiphases, ARRAY_SIZE(multiphases), npname);if (index >= 0) { switch (index) {No question on all your other feedback. Just wondering if I missed something with
match_stringuse. Looks like a good idea indeed but this is not drastically changing the code as you seem to expect... Let me know if you think I'm doing it in a wrong way.
I guess the entire big for-loop can be optimized, but I haven't looked at that. At least match_string() would help understanding what you are trying to do,
In any case it seems Mark applied your version, so the follow ups can be made.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Mark Brown
maintainerQuoted 3 lines · Esteban Blanc
This should be applied on top of other patch series:
- https://lore.kernel.org/all/[email protected]/
For core MFD driver
Please if you're doing this in future just post a single series, it makes things much easier to follow.
Mark Brown
maintainerRe: (subset) [PATCH v5 0/3] TI TPS6594 PMIC support (RTC, pinctrl, regulators)
In reply to Esteban BlancQuoted 9 lines · Esteban Blanc
TPS6594 is a Power Management IC which provides regulators and others features like GPIOs, RTC, watchdog, ESMs (Error Signal Monitor), and PFSM (Pre-configurable Finite State Machine). The SoC and the PMIC can communicate through the I2C or SPI interfaces.
TPS6594 is the super-set device while TPS6593 and LP8764 are derivatives.This series adds support to TI TPS6594 PMIC and its derivatives.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
Thanks!
[3/3] regulator: tps6594-regulator: Add driver for TI TPS6594 regulators
commit: f17ccc5deb4d024bb52fd3433471e77ab7ae9ad8
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark