Skip to contentSkip to conversation

TI TPS6594 PMIC support (RTC, pinctrl, regulators, device trees)

PATCH Superseded Esteban Blanc 3 participants 9 messages Mar 28, 2023

Subsystems (4)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover TI TPS6594 PMIC support (RTC, pinctrl, regulators, device trees)

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:
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)

Esteban Blanc (2):
rtc: tps6594: add driver for TPS6594 PMIC RTC
pinctrl: tps6594: add for TPS6594 PMIC

Jerome Neanne (1):
regulator: tps6594-regulator: Add driver for TI TPS6594 regulators

 drivers/pinctrl/Kconfig               |  10 +
 drivers/pinctrl/Makefile              |   1 +
 drivers/pinctrl/pinctrl-tps6594.c     | 365 +++++++++++++++
 drivers/regulator/Kconfig             |  13 +
 drivers/regulator/Makefile            |   1 +
 drivers/regulator/tps6594-regulator.c | 628 ++++++++++++++++++++++++++
 drivers/rtc/Kconfig                   |   9 +
 drivers/rtc/Makefile                  |   1 +
 drivers/rtc/rtc-tps6594.c             | 462 +++++++++++++++++++
 9 files changed, 1490 insertions(+)
 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
#1 lore raw

PATCH v2 1/3 rtc: tps6594: add driver for TPS6594 PMIC RTC

TPS6594 PMIC is a MFD driver. This add support for the RTC found inside TPS6594 family of PMIC.

Alarm is also supported.

---
 drivers/rtc/Kconfig       |   9 +
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-tps6594.c | 462 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 472 insertions(+)
 create mode 100644 drivers/rtc/rtc-tps6594.c
drivers/rtc/Kconfig +9 -0
index 5a71579af0a1..e5614a570d7e 100644
@@ -578,6 +578,15 @@ 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.
+
 config RTC_DRV_TPS65910
 	tristate "TI TPS65910 RTC driver"
 	depends on MFD_TPS65910
drivers/rtc/Makefile +1 -0
index ea445d1ebb17..3d3f8c9d0697 100644
@@ -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 +462 -0

462 lines not on this page · raw message

Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v2 1/3] rtc: tps6594: add driver for TPS6594 PMIC RTC

Hello,

Quoted 15 lines · Esteban Blanc
drivers/rtc/rtc-tps6594.c new file +15 -0
+	/* Start rtc */
+	ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+			      TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+
+	mdelay(100);
+
+	/*
+	 * RTC should be running now. Check if this is the case.
+	 * If not it might be a missing oscillator.
+	 */
+	ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS,
+			       TPS6594_BIT_RUN);
+	if (ret < 0)

drivers/rtc/rtc-tps6594.c line 426

Quoted 10 lines
drivers/rtc/rtc-tps6594.c new file +10 -0
+		return ret;
+	if (ret == 0)
+		return -ENODEV;
+
+	/* Stop RTC until first call to `tps6594_rtc_set_time */
+	ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+				TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+

This whole block must not be executed when the RTC is already running, else, you are stopping a perfectly running RTC.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

Re: [PATCH v2 1/3] rtc: tps6594: add driver for TPS6594 PMIC RTC

Quoted 23 lines · Alexandre Belloni

Hello,

Quoted 20 lines · Esteban Blanc
drivers/rtc/rtc-tps6594.c new file +20 -0
+	/* Start rtc */
+	ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+			      TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+
+	mdelay(100);
+
+	/*
+	 * RTC should be running now. Check if this is the case.
+	 * If not it might be a missing oscillator.
+	 */
+	ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS,
+			       TPS6594_BIT_RUN);
+	if (ret < 0)
+		return ret;
+	if (ret == 0)
+		return -ENODEV;
+
+	/* Stop RTC until first call to `tps6594_rtc_set_time */
Quoted 8 lines

drivers/rtc/rtc-tps6594.c line 157

Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5 -0
+	ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+				TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+

This whole block must not be executed when the RTC is already running, else, you are stopping a perfectly running RTC.

I'm not sure to get your point. You mean that during probe, the driver might encounter an RTC device that is already running with a correct timestamp? How would this be possible? A previous bootstage or the driver was removed then re-inserted again?

Thanks for your time,

Signature · 2 lines
Esteban Blanc
BayLibre
#4 lore raw

Re: [PATCH v2 1/3] rtc: tps6594: add driver for TPS6594 PMIC RTC

Quoted 33 lines · Esteban Blanc
Quoted 23 lines · Alexandre Belloni

Hello,

Quoted 20 lines · Esteban Blanc
drivers/rtc/rtc-tps6594.c new file +20 -0
+	/* Start rtc */
+	ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+			      TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+
+	mdelay(100);
+
+	/*
+	 * RTC should be running now. Check if this is the case.
+	 * If not it might be a missing oscillator.
+	 */
+	ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS,
+			       TPS6594_BIT_RUN);
+	if (ret < 0)
+		return ret;
+	if (ret == 0)
+		return -ENODEV;
+
+	/* Stop RTC until first call to `tps6594_rtc_set_time */
Quoted 8 lines

drivers/rtc/rtc-tps6594.c line 157

Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5 -0
+	ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+				TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+

This whole block must not be executed when the RTC is already running, else, you are stopping a perfectly running RTC.

Quoted 5 lines

I'm not sure to get your point. You mean that during probe, the driver might encounter an RTC device that is already running with a correct timestamp? How would this be possible? A previous bootstage or the driver was removed then re-inserted again?

The whole point of having an RTC is that the time tracking survives a reboot so yes, I would expect the RTC to have a valid timestamp at probe time.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

Re: [PATCH v2 1/3] rtc: tps6594: add driver for TPS6594 PMIC RTC

Quoted 40 lines · Alexandre Belloni
Quoted 33 lines · Esteban Blanc
Quoted 23 lines · Alexandre Belloni

Hello,

Quoted 20 lines · Esteban Blanc
drivers/rtc/rtc-tps6594.c new file +20 -0
+	/* Start rtc */
+	ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+			      TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+
+	mdelay(100);
+
+	/*
+	 * RTC should be running now. Check if this is the case.
+	 * If not it might be a missing oscillator.
+	 */
+	ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS,
+			       TPS6594_BIT_RUN);
+	if (ret < 0)
+		return ret;
+	if (ret == 0)
+		return -ENODEV;
+
+	/* Stop RTC until first call to `tps6594_rtc_set_time */
Quoted 8 lines

drivers/rtc/rtc-tps6594.c line 157

Quoted 5 lines
drivers/rtc/rtc-tps6594.c new file +5 -0
+	ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
+				TPS6594_BIT_STOP_RTC);
+	if (ret < 0)
+		return ret;
+

This whole block must not be executed when the RTC is already running, else, you are stopping a perfectly running RTC.

Quoted 5 lines

I'm not sure to get your point. You mean that during probe, the driver might encounter an RTC device that is already running with a correct timestamp? How would this be possible? A previous bootstage or the driver was removed then re-inserted again?

Quoted 3 lines

The whole point of having an RTC is that the time tracking survives a reboot so yes, I would expect the RTC to have a valid timestamp at probe time.

Oh. Oh I see. I did not think of that. I will add a check for that.

Thanks again,

Signature · 2 lines
Esteban Blanc
BayLibre
#6 lore raw

PATCH v2 2/3 pinctrl: tps6594: add for TPS6594 PMIC

In reply to Esteban Blanc

TI TPS6594 PMIC has 11 GPIOs which can be used for different functions

This add a pinctrl and pinmux drivers in order to use those functions

---
 drivers/pinctrl/Kconfig           |  10 +
 drivers/pinctrl/Makefile          |   1 +
 drivers/pinctrl/pinctrl-tps6594.c | 365 ++++++++++++++++++++++++++++++
 3 files changed, 376 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-tps6594.c
drivers/pinctrl/Kconfig +10 -0
index dcb53c4a9584..2c1826e86a54 100644
@@ -499,6 +499,16 @@ config PINCTRL_THUNDERBAY
 	  rate control and direction control. This module will be
 	  called as pinctrl-thunderbay.
 
+config PINCTRL_TPS6594
+	tristate "Pinctrl and GPIO driver for TI TPS6594 PMIC"
+	depends on MFD_TPS6594
+	default MFD_TPS6594
+	select PINMUX
+	select GPIOLIB
+	help
+	  This driver supports GPIOs and pinmuxing for the TPS6594
+	  PMICs chip family.
+
 config PINCTRL_ZYNQ
 	bool "Pinctrl driver for Xilinx Zynq"
 	depends on ARCH_ZYNQ
drivers/pinctrl/Makefile +1 -0
index d5939840bb2a..ddaee9459da7 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_PINCTRL_STMFX) 	+= pinctrl-stmfx.o
 obj-$(CONFIG_PINCTRL_SX150X)	+= pinctrl-sx150x.o
 obj-$(CONFIG_PINCTRL_TB10X)	+= pinctrl-tb10x.o
 obj-$(CONFIG_PINCTRL_THUNDERBAY) += pinctrl-thunderbay.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 +365 -0

365 lines not on this page · raw message

Signature · 1 line
2.39.2
#7 lore raw

PATCH v2 3/3 regulator: tps6594-regulator: Add driver for TI TPS6594 regulators

In reply to Esteban Blanc

From: 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 | 628 ++++++++++++++++++++++++++
 3 files changed, 642 insertions(+)
 create mode 100644 drivers/regulator/tps6594-regulator.c
drivers/regulator/Kconfig +13 -0
index aae28d0a489c..5f01132b04e1 100644
@@ -1440,6 +1440,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
index ee383d8fc835..cb420adf7670 100644
@@ -172,6 +172,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 +628 -0

628 lines not on this page · raw message

Signature · 1 line
2.39.2
#8 lore raw

Re: [PATCH v2 3/3] regulator: tps6594-regulator: Add driver for TI TPS6594 regulators

Thank you for the patch! Perhaps something to improve:

Hi Esteban,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linusw-pinctrl/devel]
[also build test WARNING on linusw-pinctrl/for-next broonie-regulator/for-next abelloni/rtc-next linus/master v6.3-rc4 next-20230328] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Esteban-Blanc/rtc-tps6594-add-driver-for-TPS6594-PMIC-RTC/20230328-171612
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
patch link:    https://lore.kernel.org/r/20230328091448.648452-4-eblanc%40baylibre.com
patch subject: [PATCH v2 3/3] regulator: tps6594-regulator: Add driver for TI TPS6594 regulators
config: loongarch-allyesconfig (https://download.01.org/0day-ci/archive/20230329/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/842fe9039c5ca8c856ee7433c0dff43ee7f52cfe
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Esteban-Blanc/rtc-tps6594-add-driver-for-TPS6594-PMIC-RTC/20230328-171612 git checkout 842fe9039c5ca8c856ee7433c0dff43ee7f52cfe
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/regulator/tps6594-regulator.c: In function 'tps6594_regulator_probe':

>> drivers/regulator/tps6594-regulator.c:423:31: warning: variable 'rdevldotbl' set but not used [-Wunused-but-set-variable]
     423 |         struct regulator_dev *rdevldotbl[LDO_NB];
         |                               ^~~~~~~~~~
>> drivers/regulator/tps6594-regulator.c:422:31: warning: variable 'rdevmultitbl' set but not used [-Wunused-but-set-variable]
     422 |         struct regulator_dev *rdevmultitbl[MULTI_PHASE_NB];
         |                               ^~~~~~~~~~~~
>> drivers/regulator/tps6594-regulator.c:421:31: warning: variable 'rdevbucktbl' set but not used [-Wunused-but-set-variable]
     421 |         struct regulator_dev *rdevbucktbl[BUCK_NB];
         |                               ^~~~~~~~~~~

vim +/rdevldotbl +423 drivers/regulator/tps6594-regulator.c

405
406 static int tps6594_regulator_probe(struct platform_device *pdev)
407 {
408 struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent);
409 struct regulator_dev *rdev;
410 struct regulator_config config = {};
411 u8 buck_configured[BUCK_NB] = { 0 };
412 u8 buck_multi[MULTI_PHASE_NB] = { 0 };
413 int i, nranges;
414 int irq_idx = 0;
415 int buck_idx = 0;
416 int error, irq;
417 int ext_reg_irq_nb = 2;
418 struct tps6594_regulator_irq_data *irq_data;
419 struct tps6594_ext_regulator_irq_data *irq_ext_reg_data;
420 struct tps6594_regulator_irq_type *irq_type;

 > 421		struct regulator_dev *rdevbucktbl[BUCK_NB];
 > 422		struct regulator_dev *rdevmultitbl[MULTI_PHASE_NB];
 > 423		struct regulator_dev *rdevldotbl[LDO_NB];
   424		u32 multi_phase_id;
   425		u32 multi_phase_id_tbl[2];
   426	
   427		config.dev = tps->dev;
   428		config.driver_data = tps;
   429		config.regmap = tps->regmap;
   430	
   431		/*
   432		 * Switch case defines different possible multi phase config
   433		 * This is based on dts custom property: multi-phase-id
   434		 * Using compatible or device rev is a too complex alternative
   435		 * Default case is no Multiphase buck.
   436		 * In case of Multiphase configuration, value should be defined for
   437		 * buck_configured to avoid creating bucks for every buck in multiphase
   438		 */
   439	
   440		if (device_property_present(tps->dev, "ti,multi-phase-id")) {
   441			nranges = device_property_count_u32(tps->dev, "ti,multi-phase-id");
   442			if (nranges < 1 || nranges > 2) {
   443				dev_err(tps->dev, "%s port range: '%s' property\n",
   444					nranges == -EINVAL ? "Missing" : "Invalid",
   445					"ti,multi-phase-id");
   446				return -EINVAL;
   447			}
   448			error = device_property_read_u32_array(tps->dev, "ti,multi-phase-id",
   449							       multi_phase_id_tbl, nranges);
   450			if (error) {
   451				dev_err(tps->dev, "failed to parse '%s' property: %d\n",
   452					"ti,multi-phase-id", error);
   453				return error;
   454			}
   455			multi_phase_id = multi_phase_id_tbl[0];
   456			/* Only configuration multiphase buck12 & buck34 requires 2 arguments */
   457			if (nranges > 1 && multi_phase_id != 34)
   458				multi_phase_id = multi_phase_id_tbl[1];
   459	
   460			switch (multi_phase_id) {
   461			case 12:
   462				buck_multi[0] = 1;
   463				buck_configured[0] = 1;
   464				buck_configured[1] = 1;
   465				break;
   466			/* multiphase buck34 is supported only with buck12 */
   467			case 34:
   468				buck_multi[0] = 1;
   469				buck_configured[0] = 1;
   470				buck_configured[1] = 1;
   471				buck_multi[1] = 1;
   472				buck_configured[2] = 1;
   473				buck_configured[3] = 1;
   474				break;
   475			case 123:
   476				buck_multi[2] = 1;
   477				buck_configured[0] = 1;
   478				buck_configured[1] = 1;
   479				buck_configured[2] = 1;
   480				break;
   481			case 1234:
   482				buck_multi[3] = 1;
   483				buck_configured[0] = 1;
   484				buck_configured[1] = 1;
   485				buck_configured[2] = 1;
   486				buck_configured[3] = 1;
   487				break;
   488			}
   489		}
   490	
   491		if (tps->chip_id == LP8764X)
   492			/* There is only 4 buck on LP8764X */
   493			buck_configured[4] = 1;
   494	
   495		irq_data = devm_kmalloc(tps->dev,
   496					ARRAY_SIZE(tps6594_bucks_irq_types) *
   497					REGS_INT_NB *
   498					sizeof(struct tps6594_regulator_irq_data) +
   499					ARRAY_SIZE(tps6594_ldos_irq_types) *
   500					REGS_INT_NB *
   501					sizeof(struct tps6594_regulator_irq_data),
   502					GFP_KERNEL);
   503		if (!irq_data)
   504			return -ENOMEM;
   505	
   506		for (i = 0; i < MULTI_PHASE_NB; i++) {
   507			if (buck_multi[i] == 0)
   508				continue;
   509	
   510			rdev = devm_regulator_register(&pdev->dev, &multi_regs[i], &config);
   511			if (IS_ERR(rdev)) {
   512				dev_err(tps->dev, "failed to register %s regulator\n",
   513					pdev->name);
   514				return PTR_ERR(rdev);
   515			}
   516			rdevmultitbl[i] = rdev;
   517			/* config multiphase buck12+buck34 */
   518			if (i == 1)
   519				buck_idx = 2;
   520			error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
   521							 tps6594_bucks_irq_types[buck_idx], &irq_idx);
   522			if (error)
   523				return error;
   524			error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
   525							 tps6594_bucks_irq_types[buck_idx + 1], &irq_idx);
   526			if (error)
   527				return error;
   528	
   529			if (i == 2 || i == 3) {
   530				error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
   531								 tps6594_bucks_irq_types[buck_idx + 2],
   532								 &irq_idx);
   533				if (error)
   534					return error;
   535			}
   536			if (i == 3) {
   537				error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
   538								 tps6594_bucks_irq_types[buck_idx + 3],
   539								 &irq_idx);
   540				if (error)
   541					return error;
   542			}
   543		}
   544	
   545		for (i = 0; i < BUCK_NB; i++) {
   546			if (buck_configured[i] == 1)
   547				continue;
   548	
   549			rdev = devm_regulator_register(&pdev->dev, &buck_regs[i], &config);
   550			if (IS_ERR(rdev)) {
   551				dev_err(tps->dev, "failed to register %s regulator\n",
   552					pdev->name);
   553				return PTR_ERR(rdev);
   554			}
   555			rdevbucktbl[i] = rdev;
   556	
   557			error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
   558							 tps6594_bucks_irq_types[i], &irq_idx);
   559			if (error)
   560				return error;
   561		}
   562	
   563		/* LP8764X dosen't have LDO */
   564		if (tps->chip_id != LP8764X) {
   565			for (i = 0; i < ARRAY_SIZE(ldo_regs); i++) {
   566				rdev = devm_regulator_register(&pdev->dev, &ldo_regs[i], &config);
   567				if (IS_ERR(rdev)) {
   568					dev_err(tps->dev,
   569						"failed to register %s regulator\n",
   570						pdev->name);
   571					return PTR_ERR(rdev);
   572				}
   573				rdevldotbl[i] = rdev;
   574				error = tps6594_request_reg_irqs(pdev, rdev, irq_data,
   575								 tps6594_ldos_irq_types[i],
   576								 &irq_idx);
   577				if (error)
   578					return error;
   579			}
   580		}
   581	
   582		if (tps->chip_id == LP8764X)
   583			ext_reg_irq_nb = ARRAY_SIZE(tps6594_ext_regulator_irq_types);
   584	
   585		irq_ext_reg_data = devm_kmalloc(tps->dev,
   586						ext_reg_irq_nb *
   587						sizeof(struct tps6594_ext_regulator_irq_data),
   588						GFP_KERNEL);
   589		if (!irq_ext_reg_data)
   590			return -ENOMEM;
   591	
   592		for (i = 0; i < ext_reg_irq_nb; ++i) {
   593			irq_type = &tps6594_ext_regulator_irq_types[i];
   594	
   595			irq = platform_get_irq_byname(pdev, irq_type->irq_name);
   596			if (irq < 0)
   597				return -EINVAL;
   598	
   599			irq_ext_reg_data[i].dev = tps->dev;
   600			irq_ext_reg_data[i].type = irq_type;
   601	
   602			error = devm_request_threaded_irq(tps->dev, irq, NULL,
   603							  tps6594_regulator_irq_handler,
   604							  IRQF_ONESHOT,
   605							  irq_type->irq_name,
   606							  &irq_ext_reg_data[i]);

607 if (error) {
608 dev_err(tps->dev, "failed to request %s IRQ %d: %d\n",
609 irq_type->irq_name, irq, error);
610 return error;
611 }
612 }
613 return 0;
614 }
615

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests