Skip to contentSkip to conversation

Add driver for LT8722 regulator

PATCH In review Ramon Cristopher M. Calam 6 participants 12 messages Nov 8, 2024 – Nov 15, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Add driver for LT8722 regulator

The Analog Devices LT8722 is a high performance, high efficiency, 15V input, 4A monolithic full bridge DC/DC converter. This converter has 92.5% efficiency with high power output of 54W for fine control TEC driving applications.

Ramon Cristopher M. Calam (2):
regulator: lt8722: Add driver for LT8722
dt-bindings: regulator: Add adi,lt8722-regulator.yaml

 .../regulator/adi,lt8722-regulator.yaml       | 178 +++++
 drivers/regulator/Kconfig                     |  10 +
 drivers/regulator/Makefile                    |   1 +
 drivers/regulator/lt8722-regulator.c          | 701 ++++++++++++++++++
 4 files changed, 890 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml
 create mode 100644 drivers/regulator/lt8722-regulator.c

base-commit: e18da71634d12a94a15138947538ef2f0ac22746

Signature · 1 line
2.47.0
#1 lore raw

PATCH 1/2 regulator: lt8722: Add driver for LT8722

Add ADI LT8722 full bridge DC/DC converter driver.

---
 drivers/regulator/Kconfig            |  10 +
 drivers/regulator/Makefile           |   1 +
 drivers/regulator/lt8722-regulator.c | 701 +++++++++++++++++++++++++++
 3 files changed, 712 insertions(+)
 create mode 100644 drivers/regulator/lt8722-regulator.c
drivers/regulator/Kconfig +10 -0
index 39297f7d8177..d88b050ce166 100644
@@ -550,6 +550,16 @@ config REGULATOR_LP8788
 	help
 	  This driver supports LP8788 voltage regulator chip.
 
+config REGULATOR_LT8722
+	tristate "LT8722 ultracompact full bridge driver with SPI"
+	depends on SPI && OF
+	help
+	  This driver controls an Analog Devices LT8722 ultracompact 4A, 15V,
+	  full bridge driver with SPI interface.
+
+	  Say M here if you want to include support for the regulator as a
+	  module.
+
 config REGULATOR_LTC3589
 	tristate "LTC3589 8-output voltage regulator"
 	depends on I2C
drivers/regulator/Makefile +1 -0
index 3d5a803dce8a..8f9e5aec74d2 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_REGULATOR_LP87565) += lp87565-regulator.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o
 obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o
+obj-$(CONFIG_REGULATOR_LT8722) += lt8722-regulator.o
 obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o
 obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o
 obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
drivers/regulator/lt8722-regulator.c new file +701 -0

701 lines not on this page · raw message

Signature · 1 line
2.47.0
maintainer
#2 lore raw

Re: [PATCH 1/2] regulator: lt8722: Add driver for LT8722

drivers/regulator/lt8722-regulator.c line 4

Quoted 8 lines · Ramon Cristopher M. Calam

Add ADI LT8722 full bridge DC/DC converter driver.

+++ b/drivers/regulator/lt8722-regulator.c

drivers/regulator/lt8722-regulator.c new file +4 -0
@@ -0,0 +1,701 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices LT8722 Ultracompact Full Bridge Driver with SPI driver
+ *

Please make the entire comment a C++ one so things look more intentional.

drivers/regulator/lt8722-regulator.c line 239

Quoted 5 lines
drivers/regulator/lt8722-regulator.c new file +4 -0
+static int lt8722_reg_read(struct spi_device *spi, u8 reg, u32 *val)
+{
 
+static int lt8722_reg_write(struct spi_device *spi, u8 reg, u32 val)
+{

You can use these as reg_read() and reg_write() operations in regmap which will allow the driver to use all the standard helpers and vastly reduce the size of the driver.

drivers/regulator/lt8722-regulator.c line 329

Quoted 7 lines
drivers/regulator/lt8722-regulator.c new file +7 -0
+static int lt8722_parse_fw(struct lt8722_chip_info *chip,
+			   struct regulator_init_data *init_data)
+{
+	int ret;
+
+	/* Override the min_uV constraint with the minimum output voltage */
+	init_data->constraints.min_uV = LT8722_MIN_VOUT;

Any modification of the constraints by the driver is a bug. Adjust the information the driver provides about the voltages it supports if you need to do this.

Quoted 6 lines
drivers/regulator/lt8722-regulator.c new file +6 -0
+static int lt8722_is_enabled(struct regulator_dev *rdev)
+{
+	struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+	int ret;
+	u32 reg_val;
+	bool en_req, en_pin;

drivers/regulator/lt8722-regulator.c line 533

Quoted 10 lines
drivers/regulator/lt8722-regulator.c new file +10 -0
+
+	ret = lt8722_reg_read(chip->spi, LT8722_SPIS_COMMAND, &reg_val);
+	if (ret < 0)
+		return ret;
+
+	en_req = FIELD_GET(LT8722_EN_REQ_MASK, reg_val);
+	en_pin = gpiod_get_value(chip->en_gpio);
+
+	return en_req && en_pin;
+}

Always adjusting both the GPIO and register all the time like this is pointless, it turns the GPIO into just pure overhead. Just use the standard support for setting enables via registrers and GPIOs. When there's a GPIO leave the register permanently enabld.

drivers/regulator/lt8722-regulator.c line 648

Quoted 3 lines
drivers/regulator/lt8722-regulator.c new file +3 -0
+	chip->en_gpio = devm_gpiod_get(&spi->dev, "enable", GPIOD_OUT_LOW);
+	if (IS_ERR(chip->en_gpio))
+		return PTR_ERR(chip->en_gpio);

Presumably this is optional, it could just be tied off.

#3 lore raw

RE: [PATCH 1/2] regulator: lt8722: Add driver for LT8722

Quoted 15 lines

-----Original Message-----
From: Mark Brown <[email protected]>
Sent: Friday, November 8, 2024 8:51 PM
To: Calam, Ramon Cristopher <[email protected]>
Cc: [email protected]; [email protected]; Liam Girdwood <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>
Subject: Re: [PATCH 1/2] regulator: lt8722: Add driver for LT8722

[External]

Quoted 1 line · Ramon Cristopher M. Calam

Add ADI LT8722 full bridge DC/DC converter driver.

Quoted 9 lines

drivers/regulator/lt8722-regulator.c line 5

Quoted 7 lines

+++ b/drivers/regulator/lt8722-regulator.c

drivers/regulator/lt8722-regulator.c new file +5 -0
@@ -0,0 +1,701 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices LT8722 Ultracompact Full Bridge Driver with SPI
+driver
+ *

Please make the entire comment a C++ one so things look more intentional.

I will implement this.

Quoted 10 lines

drivers/regulator/lt8722-regulator.c line 239

Quoted 6 lines
drivers/regulator/lt8722-regulator.c new file +4 -0
+static int lt8722_reg_read(struct spi_device *spi, u8 reg, u32 *val)
+{
 
+static int lt8722_reg_write(struct spi_device *spi, u8 reg, u32 val)
+{

You can use these as reg_read() and reg_write() operations in regmap which will allow the driver to use all the standard helpers and vastly reduce the size of the driver.

I will implement reg_read() and reg_write() operations in regmap to utilize the standard helper.

Quoted 7 lines

drivers/regulator/lt8722-regulator.c

Quoted 6 lines
drivers/regulator/lt8722-regulator.c new file +5 -0
+static int lt8722_parse_fw(struct lt8722_chip_info *chip,
+			   struct regulator_init_data *init_data) {
+	int ret;
+
+	/* Override the min_uV constraint with the minimum output voltage

*/

Quoted 5 lines

drivers/regulator/lt8722-regulator.c line 329

Quoted 1 line
drivers/regulator/lt8722-regulator.c new file +1 -0
+	init_data->constraints.min_uV = LT8722_MIN_VOUT;

Any modification of the constraints by the driver is a bug. Adjust the information the driver provides about the voltages it supports if you need to do this.

The device features UV/OC clamp registers for setting the maximum negative/positive output voltage. I've defined these values in the adi,uv/ov-clamp-microvolt property within the device tree, which necessitates adjusting the constraints in the driver. My idea is to utilize the regulator-min/max-microvolt property instead, thus eliminating the need for manual constraint modifications. Would this approach be appropriate? I'm also considering applying this method to the minimum and maximum output currents.

Quoted 13 lines
Quoted 13 lines
drivers/regulator/lt8722-regulator.c new file +12 -0
+static int lt8722_is_enabled(struct regulator_dev *rdev) {
+	struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+	int ret;
+	u32 reg_val;
+	bool en_req, en_pin;
+
+	ret = lt8722_reg_read(chip->spi, LT8722_SPIS_COMMAND, &reg_val);
+	if (ret < 0)
+		return ret;
+
+	en_req = FIELD_GET(LT8722_EN_REQ_MASK, reg_val);
+	en_pin = gpiod_get_value(chip->en_gpio);
Quoted 8 lines

drivers/regulator/lt8722-regulator.c line 533

Quoted 3 lines
drivers/regulator/lt8722-regulator.c new file +3 -0
+
+	return en_req && en_pin;
+}

Always adjusting both the GPIO and register all the time like this is pointless, it turns the GPIO into just pure overhead. Just use the standard support for setting enables via registrers and GPIOs. When there's a GPIO leave the register permanently enabld.

I will implement this.

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +1 -0
+	chip->en_gpio = devm_gpiod_get(&spi->dev, "enable",

GPIOD_OUT_LOW);

drivers/regulator/lt8722-regulator.c line 648

Quoted 2 lines
drivers/regulator/lt8722-regulator.c new file +2 -0
+	if (IS_ERR(chip->en_gpio))
+		return PTR_ERR(chip->en_gpio);

Presumably this is optional, it could just be tied off.

This is currently not optional but from the comment above, yes it could just be tied off.

Thank you for reviewing the patch,

Best regards,
RC

#4 lore raw

Re: [PATCH 1/2] regulator: lt8722: Add driver for LT8722

In reply to Ramon Cristopher M. Calam
kernel test robot noticed the following build errors:

Hi Ramon,

kernel test robot noticed the following build errors:

[auto build test ERROR on e18da71634d12a94a15138947538ef2f0ac22746]

url:    https://github.com/intel-lab-lkp/linux/commits/Ramon-Cristopher-M-Calam/regulator-lt8722-Add-driver-for-LT8722/20241108-174141
base:   e18da71634d12a94a15138947538ef2f0ac22746
patch link:    https://lore.kernel.org/r/20241108093544.9492-2-ramoncristopher.calam%40analog.com
patch subject: [PATCH 1/2] regulator: lt8722: Add driver for LT8722
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20241108/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241108/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/regulator/lt8722-regulator.c:8:10: fatal error: asm/unaligned.h: No such file or directory

8 | #include <asm/unaligned.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [m]:
- RESOURCE_KUNIT_TEST [=m] && RUNTIME_TESTING_MENU [=y] && KUNIT [=m]

vim +8 drivers/regulator/lt8722-regulator.c

   > 8	#include <asm/unaligned.h>
     9	#include <linux/bitfield.h>
    10	#include <linux/bits.h>
    11	#include <linux/crc8.h>
    12	#include <linux/delay.h>
    13	#include <linux/gpio.h>
    14	#include <linux/math.h>
    15	#include <linux/module.h>
    16	#include <linux/regulator/driver.h>
    17	#include <linux/regulator/machine.h>
    18	#include <linux/regulator/of_regulator.h>
    19	#include <linux/spi/spi.h>
    20	#include <linux/util_macros.h>
    21	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

Re: [PATCH 1/2] regulator: lt8722: Add driver for LT8722

In reply to Ramon Cristopher M. Calam
kernel test robot noticed the following build errors:

Hi Ramon,

kernel test robot noticed the following build errors:

[auto build test ERROR on e18da71634d12a94a15138947538ef2f0ac22746]

url:    https://github.com/intel-lab-lkp/linux/commits/Ramon-Cristopher-M-Calam/regulator-lt8722-Add-driver-for-LT8722/20241108-174141
base:   e18da71634d12a94a15138947538ef2f0ac22746
patch link:    https://lore.kernel.org/r/20241108093544.9492-2-ramoncristopher.calam%40analog.com
patch subject: [PATCH 1/2] regulator: lt8722: Add driver for LT8722
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20241109/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 592c0fe55f6d9a811028b5f3507be91458ab2713)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241109/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/regulator/lt8722-regulator.c:8:10: fatal error: 'asm/unaligned.h' file not found

8 | #include <asm/unaligned.h>
| ^~~~~~~~~~~~~~~~~
1 error generated.

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [m]:
- RESOURCE_KUNIT_TEST [=m] && RUNTIME_TESTING_MENU [=y] && KUNIT [=m]

vim +8 drivers/regulator/lt8722-regulator.c

   > 8	#include <asm/unaligned.h>
     9	#include <linux/bitfield.h>
    10	#include <linux/bits.h>
    11	#include <linux/crc8.h>
    12	#include <linux/delay.h>
    13	#include <linux/gpio.h>
    14	#include <linux/math.h>
    15	#include <linux/module.h>
    16	#include <linux/regulator/driver.h>
    17	#include <linux/regulator/machine.h>
    18	#include <linux/regulator/of_regulator.h>
    19	#include <linux/spi/spi.h>
    20	#include <linux/util_macros.h>
    21	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw

Re: [PATCH 1/2] regulator: lt8722: Add driver for LT8722

In reply to Ramon Cristopher M. Calam
Quoted 355 lines · Ramon Cristopher M. Calam

Add ADI LT8722 full bridge DC/DC converter driver.

---
 drivers/regulator/Kconfig            |  10 +
 drivers/regulator/Makefile           |   1 +
 drivers/regulator/lt8722-regulator.c | 701 +++++++++++++++++++++++++++
 3 files changed, 712 insertions(+)
 create mode 100644 drivers/regulator/lt8722-regulator.c
drivers/regulator/Kconfig +10 -0
index 39297f7d8177..d88b050ce166 100644
@@ -550,6 +550,16 @@ config REGULATOR_LP8788
        help
          This driver supports LP8788 voltage regulator chip.
 
+config REGULATOR_LT8722
+       tristate "LT8722 ultracompact full bridge driver with SPI"
+       depends on SPI && OF
+       help
+         This driver controls an Analog Devices LT8722 ultracompact 4A, 15V,
+         full bridge driver with SPI interface.
+
+         Say M here if you want to include support for the regulator as a
+         module.
+
 config REGULATOR_LTC3589
        tristate "LTC3589 8-output voltage regulator"
        depends on I2C
drivers/regulator/Makefile +1 -0
index 3d5a803dce8a..8f9e5aec74d2 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_REGULATOR_LP87565) += lp87565-regulator.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o
 obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o
+obj-$(CONFIG_REGULATOR_LT8722) += lt8722-regulator.o
 obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o
 obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o
 obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
drivers/regulator/lt8722-regulator.c new file +305 -0
new file mode 100644
index 000000000000..f5d378c0b1f2
@@ -0,0 +1,701 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices LT8722 Ultracompact Full Bridge Driver with SPI driver
+ *
+ * Copyright 2024 Analog Devices Inc.
+ */
+
+#include <asm/unaligned.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/crc8.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/math.h>
+#include <linux/module.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/spi/spi.h>
+#include <linux/util_macros.h>
+
+/* Register map */
+#define LT8722_SPIS_COMMAND            0x00
+#define LT8722_SPIS_STATUS             0x01
+#define        LT8722_SPIS_DAC_ILIMN           0x02
+#define        LT8722_SPIS_DAC_ILIMP           0x03
+#define        LT8722_SPIS_DAC                 0x04
+#define        LT8722_SPIS_OV_CLAMP            0x05
+#define        LT8722_SPIS_UV_CLAMP            0x06
+#define        LT8722_SPIS_AMUX                0x07
+
+/* Register masks */
+#define LT8722_SPIS_COMMAND_MASK       GENMASK(21, 0)
+#define LT8722_SPIS_STATUS_MASK                GENMASK(10, 0)
+#define LT8722_SPIS_DAC_ILIMN_MASK     GENMASK(8, 0)
+#define LT8722_SPIS_DAC_ILIMP_MASK     GENMASK(8, 0)
+#define LT8722_SPIS_DAC_MASK           GENMASK(31, 0)
+#define LT8722_SPIS_OV_CLAMP_MASK      GENMASK(3, 0)
+#define LT8722_SPIS_UV_CLAMP_MASK      GENMASK(3, 0)
+#define LT8722_SPIS_AMUX_MASK          GENMASK(6, 0)
+
+/* SPIS_COMMAND register bit masks */
+#define LT8722_EN_REQ_MASK             BIT(0)
+#define LT8722_SWEN_REQ_MASK           BIT(1)
+#define LT8722_SW_FRQ_SET_MASK         GENMASK(4, 2)
+#define LT8722_SW_FRQ_ADJ_MASK         GENMASK(6, 5)
+#define LT8722_SYS_DC_MASK             GENMASK(8, 7)
+#define LT8722_VCC_VREG_MASK           BIT(9)
+#define LT8722_SW_VC_IN_MASK           GENMASK(13, 11)
+#define LT8722_SPI_RST_MASK            BIT(14)
+#define LT8722_PWR_LIM_MASK            GENMASK(18, 15)
+
+#define LT8722_FAULTS_MASK             GENMASK(10, 5)
+#define LT8722_UV_OV_MASK              GENMASK(23, 20)
+#define LT8722_OC_MASK                 BIT(5)
+#define LT8722_TSD_MASK                        BIT(6)
+
+#define LT8722_CRC8_POLY               0x07
+#define LT8722_CRC_INIT                        0x00
+
+#define LT8722_READ_CMD                        0xF4
+#define LT8722_WRITE_CMD               0xF2
+#define LT8722_RW_CMD_SIZE             8
+#define LT8722_DATA_SIZE               4
+#define LT8722_DATA_POS                        2
+#define LT8722_CRC_POS                 6
+#define LT8722_ACK                     0xA5
+#define LT8722_ACK_POS                 7
+
+#define LT8722_DAC_VREF                        2500000
+#define LT8722_DAC_BITS                        25
+#define LT8722_ILIM_STEP               13280
+#define LT8722_RAMP_STEPS              5
+
+#define LT8722_MIN_DAC_CODE            0xFF000000
+#define LT8722_MAX_DAC_CODE            0x00FFFFFF
+#define LT8722_ILIMN_MIN_IOUT          -6786000
+#define LT8722_ILIMN_MAX_IOUT          -664640
+#define LT8722_ILIMP_MIN_IOUT          637440
+#define LT8722_ILIMP_MAX_IOUT          6800000
+#define LT8722_MIN_VOUT                        -20000000
+#define LT8722_MAX_VOUT                        20000000
+#define LT8722_MIN_IOUT                        -6786000
+#define LT8722_MAX_IOUT                        6800000
+
+DECLARE_CRC8_TABLE(lt8722_crc8_table);
+
+struct lt8722_chip_info {
+       struct spi_device *spi;
+       struct regulator_dev *rdev;
+       struct gpio_desc *en_gpio;
+       struct gpio_desc *swen_gpio;
+       int uv_clamp_uV;
+       int ov_clamp_uV;
+       int ilimn_uA;
+       int ilimp_uA;
+       int switch_freq_hz;
+       const char *switch_freq_adjust;
+       const char *duty_cycle_range;
+       int vcc_vreg_mV;
+       int peak_inductor_current_mA;
+       int power_limit_mW;
+};
+
+static const unsigned int lt8722_uv_clamp[] = {
+       -20000000,
+       -18750000,
+       -17500000,
+       -16250000,
+       -15000000,
+       -13750000,
+       -12500000,
+       -11250000,
+       -10000000,
+       -8750000,
+       -7500000,
+       -6250000,
+       -5000000,
+       -3750000,
+       -2500000,
+       -1250000,
+};
+
+static const unsigned int lt8722_ov_clamp[] = {
+       1250000,
+       2500000,
+       3750000,
+       5000000,
+       6250000,
+       7500000,
+       8750000,
+       10000000,
+       11250000,
+       12500000,
+       13750000,
+       15000000,
+       16250000,
+       17500000,
+       18750000,
+       20000000,
+};
+
+static const unsigned int lt8722_switch_freq[] = {
+       500000,
+       1000000,
+       1500000,
+       2000000,
+       2500000,
+       3000000,
+};
+
+static const char * const lt8722_switch_freq_adjust[] = {
+       "0%",
+       "15%",
+       "-15%",
+};
+
+static const char * const lt8722_duty_cycle_range[] = {
+       "20%-80%",
+       "15%-85%",
+       "10%-90%",
+};
+
+static const unsigned int lt8722_vcc_vreg[] = {
+       3100,
+       3400,
+};
+
+static const unsigned int lt8722_peak_inductor_current[] = {
+       252,
+       594,
+       936,
+       1278,
+       1620,
+       1962,
+       2304,
+       2646,
+};
+
+static const unsigned int lt8722_power_limit[] = {
+       2000,
+       0,
+       3000,
+       3500,
+};
+
+static s32 _lt8722_dac_to_uV(u32 dac_val)
+{
+       s64 tmp;
+
+       tmp = (s64)dac_val * LT8722_DAC_VREF;
+       tmp = 16 * div_s64(tmp, BIT(LT8722_DAC_BITS));
+
+       return tmp;
+}
+
+static s32 _lt8722_uV_to_dac(s32 uV)
+{
+       s64 tmp;
+
+       tmp = (s64)uV * BIT(LT8722_DAC_BITS);
+       tmp = div_s64(tmp, LT8722_DAC_VREF * 16);
+
+       return tmp;
+}
+
+static int lt8722_reg_read(struct spi_device *spi, u8 reg, u32 *val)
+{
+       int ret;
+       struct spi_transfer t;
+       u8 rx_buf[LT8722_RW_CMD_SIZE] = {0};
+       u8 tx_buf[LT8722_RW_CMD_SIZE] = {0};
+
+       tx_buf[0] = LT8722_READ_CMD;
+       tx_buf[1] = reg << 1;
+       tx_buf[2] = crc8(lt8722_crc8_table, tx_buf, 2, LT8722_CRC_INIT);
+
+       t.tx_buf = tx_buf;
+       t.rx_buf = rx_buf;
+       t.len = LT8722_RW_CMD_SIZE;
+
+       ret = spi_sync_transfer(spi, &t, 1);
+       if (ret < 0)
+               return ret;
+
+       if (rx_buf[LT8722_CRC_POS] != crc8(lt8722_crc8_table, rx_buf,
+                               LT8722_CRC_POS, LT8722_CRC_INIT))
+               return -EIO;
+
+       if (rx_buf[LT8722_ACK_POS] != LT8722_ACK)
+               return -EIO;
+
+       *val = get_unaligned_be32(&rx_buf[LT8722_DATA_POS]);
+
+       return 0;
+}
+
+static int lt8722_reg_write(struct spi_device *spi, u8 reg, u32 val)
+{
+       int ret;
+       struct spi_transfer t;
+       u8 rx_buf[LT8722_RW_CMD_SIZE] = {0};
+       u8 tx_buf[LT8722_RW_CMD_SIZE] = {0};
+
+       tx_buf[0] = LT8722_WRITE_CMD;
+       tx_buf[1] = reg << 1;
+
+       put_unaligned_be32(val, &tx_buf[LT8722_DATA_POS]);
+
+       tx_buf[LT8722_CRC_POS] = crc8(lt8722_crc8_table, tx_buf, LT8722_CRC_POS,
+                                     LT8722_CRC_INIT);
+
+       t.tx_buf = tx_buf;
+       t.rx_buf = rx_buf;
+       t.len = LT8722_RW_CMD_SIZE;
+
+       ret = spi_sync_transfer(spi, &t, 1);
+       if (ret < 0)
+               return ret;
+
+       if (rx_buf[LT8722_ACK_POS] != LT8722_ACK)
+               return -EIO;
+
+       return 0;
+}
+
+static int lt8722_reg_write_mask(struct spi_device *spi, u8 reg, u32 mask,
+                                u32 val)
+{
+       int ret;
+       u32 reg_val;
+
+       ret = lt8722_reg_read(spi, reg, &reg_val);
+       if (ret < 0)
+               return ret;
+
+       reg_val = (reg_val & ~mask) | (val & mask);
+
+       return lt8722_reg_write(spi, reg, reg_val);
+}
+
+static int lt8722_set_voltage(struct regulator_dev *rdev, int min_uV,
+                             int max_uV, unsigned int *selector)
+{
+       struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+
+       if (min_uV < LT8722_MIN_VOUT || max_uV > LT8722_MAX_VOUT)
+               return -EINVAL;
+
+       *selector = _lt8722_uV_to_dac(min_uV);
+
+       return lt8722_reg_write(chip->spi, LT8722_SPIS_DAC, *selector);
+}
+
+static int lt8722_get_voltage(struct regulator_dev *rdev)
+{
+       struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+       int ret, dac_val;
+
+       ret = lt8722_reg_read(chip->spi, LT8722_SPIS_DAC, &dac_val);
+       if (ret < 0)
+               return ret;
+
+       dac_val = FIELD_GET(LT8722_SPIS_DAC_MASK, dac_val);
+

drivers/regulator/lt8722-regulator.c line 315

Quoted 10 lines
drivers/regulator/lt8722-regulator.c new file +10 -0
+       return _lt8722_dac_to_uV(dac_val);
+}
+
+static int lt8722_get_prop_index(const u32 *table, size_t table_size, u32 value)
+{
+       int i;
+
+       for (i = 0; i < table_size; i++)
+               if (table[i] == value)
+                       break;

Nit pick: instead of break you can return the index instead of checking again below if it is equal to table_size, saving one check. Once you do that then you can get rid of below if and simply return EINVAL.

Quoted 390 lines
drivers/regulator/lt8722-regulator.c new file +386 -1
+
+       if (i == table_size)
+               return -EINVAL;
+
+       return i;
+}
+
+static int lt8722_parse_fw(struct lt8722_chip_info *chip,
+                          struct regulator_init_data *init_data)
+{
+       int ret;
+
+       /* Override the min_uV constraint with the minimum output voltage */
+       init_data->constraints.min_uV = LT8722_MIN_VOUT;
+
+       ret = device_property_read_u32(&chip->spi->dev, "adi,uv-clamp-microvolt",
+                                      &chip->uv_clamp_uV);
+       if (!ret) {
+               ret = lt8722_get_prop_index(lt8722_uv_clamp,
+                               ARRAY_SIZE(lt8722_uv_clamp), chip->uv_clamp_uV);
+               if (ret < 0)
+                       return ret;
+
+               ret = lt8722_reg_write(chip->spi, LT8722_SPIS_UV_CLAMP, ret);
+               if (ret < 0)
+                       return ret;
+
+               /* Override the min_uV constraint with the UV clamp value */
+               init_data->constraints.min_uV = chip->uv_clamp_uV;
+       }
+
+       /* Override the max_uV constraint with the maximum output voltage */
+       init_data->constraints.max_uV = LT8722_MAX_VOUT;
+
+       ret = device_property_read_u32(&chip->spi->dev, "adi,ov-clamp-microvolt",
+                                      &chip->ov_clamp_uV);
+       if (!ret) {
+               ret = lt8722_get_prop_index(lt8722_ov_clamp,
+                               ARRAY_SIZE(lt8722_ov_clamp), chip->ov_clamp_uV);
+               if (ret < 0)
+                       return ret;
+
+               ret = lt8722_reg_write(chip->spi, LT8722_SPIS_OV_CLAMP, ret);
+               if (ret < 0)
+                       return ret;
+
+               /* Override the max_uV constraint with the OV clamp value */
+               init_data->constraints.max_uV = chip->ov_clamp_uV;
+       }
+
+       /* Override the min_uA constraint with the minimum output current */
+       init_data->constraints.min_uA = LT8722_MIN_IOUT;
+
+       ret = device_property_read_u32(&chip->spi->dev, "adi,ilimn-microamp",
+                                      &chip->ilimn_uA);
+       if (!ret) {
+               if (chip->ilimn_uA < LT8722_ILIMN_MIN_IOUT ||
+                   chip->ilimn_uA > LT8722_ILIMN_MAX_IOUT)
+                       return -EINVAL;
+
+               ret = div_s64(chip->ilimn_uA, -LT8722_ILIM_STEP);
+
+               ret = lt8722_reg_write(chip->spi, LT8722_SPIS_DAC_ILIMN, ret);
+               if (ret < 0)
+                       return ret;
+
+               /* Override the min_uA constraint with the ILIMN value */
+               init_data->constraints.min_uA = chip->ilimn_uA;
+       }
+
+       /* Override the max_uA constraint with the maximum output current */
+       init_data->constraints.max_uA = LT8722_MAX_IOUT;
+
+       ret = device_property_read_u32(&chip->spi->dev, "adi,ilimp-microamp",
+                                      &chip->ilimp_uA);
+       if (!ret) {
+               if (chip->ilimp_uA < LT8722_ILIMP_MIN_IOUT ||
+                   chip->ilimp_uA > LT8722_ILIMP_MAX_IOUT)
+                       return -EINVAL;
+
+               ret = div_s64(LT8722_MAX_IOUT - chip->ilimp_uA, LT8722_ILIM_STEP);
+
+               ret = lt8722_reg_write(chip->spi, LT8722_SPIS_DAC_ILIMP, ret);
+               if (ret < 0)
+                       return ret;
+
+               /* Override the max_uA constraint with the ILIMP value */
+               init_data->constraints.max_uA = chip->ilimp_uA;
+       }
+
+       ret = device_property_read_u32(&chip->spi->dev, "adi,switch-frequency-hz",
+                                      &chip->switch_freq_hz);
+       if (!ret) {
+               ret = lt8722_get_prop_index(lt8722_switch_freq,
+                                           ARRAY_SIZE(lt8722_switch_freq),
+                                           chip->switch_freq_hz);
+               if (ret < 0)
+                       return ret;
+
+               ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                               LT8722_SW_FRQ_SET_MASK,
+                               FIELD_PREP(LT8722_SW_FRQ_SET_MASK, ret));
+               if (ret < 0)
+                       return ret;
+       }
+
+       ret = device_property_match_property_string(&chip->spi->dev,
+                       "adi,switch-frequency-adjust",
+                       lt8722_switch_freq_adjust,
+                       ARRAY_SIZE(lt8722_switch_freq_adjust));
+       if (ret >= 0) {
+               ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                               LT8722_SW_FRQ_ADJ_MASK,
+                               FIELD_PREP(LT8722_SW_FRQ_ADJ_MASK, ret));
+               if (ret < 0)
+                       return ret;
+       }
+
+       ret = device_property_match_property_string(&chip->spi->dev,
+                       "adi,duty-cycle-range", lt8722_duty_cycle_range,
+                       ARRAY_SIZE(lt8722_duty_cycle_range));
+       if (ret >= 0) {
+               ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                               LT8722_SYS_DC_MASK,
+                               FIELD_PREP(LT8722_SYS_DC_MASK, ret));
+               if (ret < 0)
+                       return ret;
+       }
+
+       ret = device_property_read_u32(&chip->spi->dev, "adi,vcc-vreg-millivolt",
+                                      &chip->vcc_vreg_mV);
+       if (!ret) {
+               ret = lt8722_get_prop_index(lt8722_vcc_vreg,
+                               ARRAY_SIZE(lt8722_vcc_vreg), chip->vcc_vreg_mV);
+               if (ret < 0)
+                       return ret;
+
+               ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                               LT8722_VCC_VREG_MASK,
+                               FIELD_PREP(LT8722_VCC_VREG_MASK, ret));
+               if (ret < 0)
+                       return ret;
+       }
+
+       ret = device_property_read_u32(&chip->spi->dev,
+                                      "adi,peak-inductor-current-milliamp",
+                                      &chip->peak_inductor_current_mA);
+       if (!ret) {
+               ret = lt8722_get_prop_index(lt8722_peak_inductor_current,
+                               ARRAY_SIZE(lt8722_peak_inductor_current),
+                               chip->peak_inductor_current_mA);
+               if (ret < 0)
+                       return ret;
+
+               ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                               LT8722_SW_VC_IN_MASK,
+                               FIELD_PREP(LT8722_SW_VC_IN_MASK, ret));
+               if (ret < 0)
+                       return ret;
+       }
+
+       ret = device_property_read_u32(&chip->spi->dev, "adi,power-limit-milliwatt",
+                                      &chip->power_limit_mW);
+       if (!ret) {
+               ret = lt8722_get_prop_index(lt8722_power_limit,
+                                           ARRAY_SIZE(lt8722_power_limit),
+                                           chip->power_limit_mW);
+               if (ret < 0)
+                       return ret;
+
+               ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                               LT8722_PWR_LIM_MASK,
+                               FIELD_PREP(LT8722_PWR_LIM_MASK, ret));
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int lt8722_enable(struct regulator_dev *rdev)
+{
+       struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+
+       gpiod_set_value_cansleep(chip->en_gpio, 1);
+
+       return lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                       LT8722_EN_REQ_MASK,
+                       FIELD_PREP(LT8722_EN_REQ_MASK, 0x1));
+}
+
+static int lt8722_disable(struct regulator_dev *rdev)
+{
+       struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+
+       gpiod_set_value_cansleep(chip->en_gpio, 0);
+
+       return lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                       LT8722_EN_REQ_MASK,
+                       FIELD_PREP(LT8722_EN_REQ_MASK, 0x0));
+}
+
+static int lt8722_is_enabled(struct regulator_dev *rdev)
+{
+       struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+       int ret;
+       u32 reg_val;
+       bool en_req, en_pin;
+
+       ret = lt8722_reg_read(chip->spi, LT8722_SPIS_COMMAND, &reg_val);
+       if (ret < 0)
+               return ret;
+
+       en_req = FIELD_GET(LT8722_EN_REQ_MASK, reg_val);
+       en_pin = gpiod_get_value(chip->en_gpio);
+
+       return en_req && en_pin;
+}
+
+static int lt8722_get_error_flags(struct regulator_dev *rdev,
+                                 unsigned int *flags)
+{
+       struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+       int ret;
+       u32 reg_val;
+
+       ret = lt8722_reg_read(chip->spi, LT8722_SPIS_STATUS, &reg_val);
+       if (ret < 0)
+               return ret;
+
+       *flags = 0;
+
+       if (FIELD_GET(LT8722_OC_MASK, reg_val))
+               *flags |= REGULATOR_ERROR_OVER_CURRENT;
+
+       if (FIELD_GET(LT8722_TSD_MASK, reg_val))
+               *flags |= REGULATOR_ERROR_OVER_TEMP;
+
+       return 0;
+}
+
+static int lt8722_set_soft_start(struct regulator_dev *rdev)
+{
+       struct lt8722_chip_info *chip = rdev_get_drvdata(rdev);
+       s32 dac_val;
+       int ret, i;
+
+       /* Clear faults before enabled VCC LDO and other device circuitry */
+       ret = lt8722_reg_write(chip->spi, LT8722_SPIS_STATUS, 0x0);
+       if (ret < 0)
+               return ret;
+
+       ret = lt8722_enable(rdev);
+       if (ret < 0)
+               return ret;
+
+       /* Configure output voltage control DAC to 0xFF000000 */
+       ret = lt8722_reg_write(chip->spi, LT8722_SPIS_DAC, LT8722_MIN_DAC_CODE);
+       if (ret < 0)
+               return ret;
+
+       /* Write all SPIS_STATUS register bits to 0 */
+       ret = lt8722_reg_write(chip->spi, LT8722_SPIS_STATUS, 0x0);
+       if (ret < 0)
+               return ret;
+
+       fsleep(1000);
+
+       /* Ramp the output voltage control DAC from 0xFF000000 to 0x00000000 */
+       for (i = 0; i < LT8722_RAMP_STEPS; i++) {
+               dac_val = LT8722_MIN_DAC_CODE + 0x400000 * i;
+
+               ret = lt8722_reg_write(chip->spi, LT8722_SPIS_DAC, dac_val);
+               if (ret < 0)
+                       return ret;
+
+               fsleep(1000);
+       }
+
+       /* Enable the PWM switching behavior */
+       gpiod_set_value_cansleep(chip->swen_gpio, 1);
+
+       ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                       LT8722_SWEN_REQ_MASK,
+                       FIELD_PREP(LT8722_SWEN_REQ_MASK, 0x1));
+       if (ret < 0)
+               return ret;
+
+       fsleep(160);
+
+       return 0;
+}
+
+static const struct regulator_ops lt8722_regulator_ops = {
+       .set_voltage = lt8722_set_voltage,
+       .get_voltage = lt8722_get_voltage,
+       .enable = lt8722_enable,
+       .disable = lt8722_disable,
+       .is_enabled = lt8722_is_enabled,
+       .set_soft_start = lt8722_set_soft_start,
+       .get_error_flags = lt8722_get_error_flags,
+};
+
+static struct regulator_desc lt8722_regulator_desc = {
+       .name = "lt8722",
+       .ops = &lt8722_regulator_ops,
+       .type = REGULATOR_VOLTAGE,
+       .owner = THIS_MODULE,
+};
+
+static int lt8722_probe(struct spi_device *spi)
+{
+       struct regulator_init_data *init_data;
+       struct regulator_config config = { };
+       struct lt8722_chip_info *chip;
+       int ret;
+
+       init_data = of_get_regulator_init_data(&spi->dev, spi->dev.of_node,
+                                              &lt8722_regulator_desc);
+       if (!init_data)
+               return -EINVAL;
+
+       chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL);
+       if (!chip)
+               return -ENOMEM;
+
+       crc8_populate_msb(lt8722_crc8_table, LT8722_CRC8_POLY);
+
+       chip->spi = spi;
+
+       chip->en_gpio = devm_gpiod_get(&spi->dev, "enable", GPIOD_OUT_LOW);
+       if (IS_ERR(chip->en_gpio))
+               return PTR_ERR(chip->en_gpio);
+
+       chip->swen_gpio = devm_gpiod_get(&spi->dev, "switch-enable",
+                       GPIOD_OUT_LOW);
+       if (IS_ERR(chip->swen_gpio))
+               return PTR_ERR(chip->swen_gpio);
+
+       ret = lt8722_reg_write_mask(chip->spi, LT8722_SPIS_COMMAND,
+                       LT8722_SPI_RST_MASK,
+                       FIELD_PREP(LT8722_SPI_RST_MASK, 0x1));
+       if (ret < 0)
+               return ret;
+
+       ret = lt8722_parse_fw(chip, init_data);
+       if (ret < 0)
+               return ret;
+
+       config.dev = &spi->dev;
+       config.init_data = init_data;
+       config.driver_data = chip;
+
+       chip->rdev = devm_regulator_register(&spi->dev, &lt8722_regulator_desc,
+                                            &config);
+       if (IS_ERR(chip->rdev))
+               return PTR_ERR(chip->rdev);
+
+       return 0;
+}
+
+static const struct of_device_id lt8722_of_match[] = {
+       { .compatible = "adi,lt8722", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, lt8722_of_match);
+
+static const struct spi_device_id lt8722_id[] = {
+       { "lt8722" },
+       { }
+};
+MODULE_DEVICE_TABLE(spi, lt8722_id);
+
+struct spi_driver lt8722_driver = {
+       .driver = {
+               .name = "lt8722",
+               .of_match_table = lt8722_of_match,
+       },
+       .probe = lt8722_probe,
+       .id_table = lt8722_id,
+};
+module_spi_driver(lt8722_driver);
+
+MODULE_AUTHOR("Ramon Cristopher Calam <[email protected]>");
+MODULE_DESCRIPTION("LT8722 ultracompact full bridge driver with SPI driver");
+MODULE_LICENSE("GPL");
--

2.47.0

#7 lore raw

PATCH 2/2 dt-bindings: regulator: Add adi,lt8722-regulator.yaml

In reply to Ramon Cristopher M. Calam

Add documentation for device tree bindings of LT8722.

---
 .../regulator/adi,lt8722-regulator.yaml       | 178 ++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml new file +178 -0
new file mode 100644
index 000000000000..3fbf788d4154
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (c) 2023 Analog Devices, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/adi,lt8722-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices LT8722 Ultracompact Full Bridge Driver
+
+maintainers:
+  - Ramon Cristopher Calam <[email protected]>
+
+description: |
+  The Analog Devices LT8722 is a high performance, high efficiency, 15V input,
+  4A monolithic full bridge DC/DC converter. This converter has 92.5% efficiency
+  with high power output of 54W for fine control TEC driving applications.
+
+properties:
+  compatible:
+    enum:
+      - adi,lt8722
+
+  reg:
+    maxItems: 1
+
+  enable-gpios:
+    description:
+      This pin in used together with the ENABLE_REQ bit in the SPIS_COMMAND
+      register to set the state of LT8722. When both the ENABLE_REQ bit and
+      the enable GPIO are low, LT8722 is in shutdown mode. When either the
+      ENABLE_REQ bit or the enable GPIO is high, LT8722 is active and the
+      internal VCC LDO regulator is enabled. The enable GPIO is active high.
+    maxItems: 1
+
+  switch-enable-gpios:
+    description:
+      This pin is used together with the SWEN_REG bit in the SPIS_COMMAND
+      register to set the PWM switching behavior of LT8722. When both the
+      SWEN_REG bit and the switch enable GPIO are low, LT8722 PWM switching
+      is disabled. When both the SWEN_REG bit and the switch enable GPIO are
+      high, LT8722 PWM switching is enabled. The switch enable GPIO is active
+      high.
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 10000000
+
+  adi,uv-clamp-microvolt:
+    description: Maximum negative output voltage clamp in microvolts.
+    enum: [
+      -20000000,
+      -18750000,
+      -17500000,
+      -16250000,
+      -15000000,
+      -13750000,
+      -12500000,
+      -11250000,
+      -10000000,
+      -8750000,
+      -7500000,
+      -6250000,
+      -5000000,
+      -3750000,
+      -2500000,
+      -1250000
+    ]
+    default: -20000000
+
+  adi,ov-clamp-microvolt:
+    description: Maximum positive output voltage clamp in microvolts.
+    enum: [
+      1250000,
+      2500000,
+      3750000,
+      5000000,
+      6250000,
+      7500000,
+      8750000,
+      10000000,
+      11250000,
+      12500000,
+      13750000,
+      15000000,
+      16250000,
+      17500000,
+      18750000,
+      20000000
+    ]
+    default: 20000000
+
+  adi,ilimn-microamp:
+    description: Maximum negative output current limit in microamps.
+    minimum: -6786000
+    maximum: -637440
+    default: -6786000
+
+  adi,ilimp-microamp:
+    description: Maximum positive output current limit in microamps.
+    minimum: 637440
+    maximum: 6800000
+    default: 6800000
+
+  adi,switch-frequency-hz:
+    description: PWM switch frequency.
+    enum: [500000, 1000000, 1500000, 2000000, 2500000, 3000000]
+    default: 500000
+
+  adi,switch-frequency-adjust:
+    description: PWM switch frequency adjustment.
+    enum: [0%, 15%, -15%]
+    default: 0%
+
+  adi,duty-cycle-range:
+    description: PWM duty cycle.
+    enum: [20%-80%, 15%-85%, 10%-90%]
+    default: 20%-80%
+
+  adi,vcc-vreg-millivolt:
+    description: VCC LCO regulation voltage in millivolts.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [3100, 3400]
+    default: 3400
+
+  adi,peak-inductor-current-milliamp:
+    description: Typical peak inductor current in milliamps.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [252, 594, 936, 1278, 1620, 1962, 2304, 2646]
+    default: 1620
+
+  adi,power-limit-milliwatt:
+    description: Linear power stage MOSFET power limit in milliwatts.
+    enum: [0, 2000, 3000, 3500]
+    default: 0
+
+required:
+  - compatible
+  - reg
+  - enable-gpios
+  - switch-enable-gpios
+
+allOf:
+  - $ref: regulator.yaml#
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        regulator@0 {
+            compatible = "adi,lt8722";
+            reg = <0>;
+            enable-gpios = <&gpio 23 GPIO_ACTIVE_HIGH>;
+            switch-enable-gpios = <&gpio 24 GPIO_ACTIVE_HIGH>;
+            spi-max-frequency = <10000000>;
+            spi-bits-per-word = <8>;
+
+            adi,uv-clamp-microvolt = <(-20000000)>;
+            adi,ov-clamp-microvolt = <20000000>;
+            adi,ilimn-microamp = <(-6786000)>;
+            adi,ilimp-microamp = <6800000>;
+            adi,switch-frequency-hz = <500000>;
+            adi,switch-frequency-adjust = "0%";
+            adi,duty-cycle-range = "20%-80%";
+            adi,vcc-vreg-millivolt = <3400>;
+            adi,peak-inductor-current-milliamp = <1620>;
+            adi,power-limit-milliwatt = <0>;
+
+            regulator-min-microvolt = <-20000000>;
+            regulator-max-microvolt = <20000000>;
+            regulator-soft-start;
+        };
+    };
Signature · 1 line
2.47.0
#8 lore raw

Re: [PATCH 2/2] dt-bindings: regulator: Add adi,lt8722-regulator.yaml

Quoted 8 lines · Ramon Cristopher M. Calam

Add documentation for device tree bindings of LT8722.

---
 .../regulator/adi,lt8722-regulator.yaml       | 178 ++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.example.dts:42.44-45 syntax error FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.dtbs:129: Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.example.dtb] Error 1 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1442: dt_binding_check] Error 2
make: *** [Makefile:224: __sub-make] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#9 lore raw

RE: [PATCH 2/2] dt-bindings: regulator: Add adi,lt8722-regulator.yaml

Quoted 57 lines

-----Original Message-----
From: Rob Herring (Arm) <[email protected]>
Sent: Friday, November 8, 2024 6:18 PM
To: Calam, Ramon Cristopher <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Liam Girdwood <[email protected]>; linux- [email protected]; Mark Brown <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] dt-bindings: regulator: Add adi,lt8722-regulator.yaml

[External]

Quoted 3 lines · Ramon Cristopher M. Calam

Add documentation for device tree bindings of LT8722.

Signed-off-by Ramon Cristopher M. Calam

<[email protected]>

Quoted 4 lines
---
 .../regulator/adi,lt8722-regulator.yaml       | 178 ++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml

Quoted 1 line

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/regulator/adi,lt8722- regulator.example.dts:42.44-45 syntax error
FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.dtbs:129:
Documentation/devicetree/bindings/regulator/adi,lt8722- regulator.example.dtb] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [/builds/robherring/dt-review-ci/linux/Makefile:1442:
dt_binding_check] Error 2
make: *** [Makefile:224: __sub-make] Error 2

doc reference errors (make refcheckdocs):

See
https://urldefense.com/v3/__https://patchwork.ozlabs.org/project/devicetr
ee-bindings/patch/20241108093544.9492-3- [email protected]__;!!A3Ni8CS0y2Y!_KU8t2BD5P_t7WfxY jWxOUHnAG7bO5XoQOA1gbUBMObfWMLO9SM6NZUCyTgbSxcxmC93rYrTs 5Ombu0lvybSbA$

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

Quoted 6 lines

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

I've checked and corrected the errors reported by 'make dt_binding_check'. The error was caused by the missing parenthesis on the negative value of the 'regulator-min-microvolt' property. I've rerun the command with the fix and no longer see the error. Will resubmit the patch soon.

Thanks,
Ramon

#10 lore raw

Re: [PATCH 2/2] dt-bindings: regulator: Add adi,lt8722-regulator.yaml

In reply to Ramon Cristopher M. Calam
Quoted 8 lines · Ramon Cristopher M. Calam

Add documentation for device tree bindings of LT8722.

---
 .../regulator/adi,lt8722-regulator.yaml       | 178 ++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml

This wasn't tested, so limited review follows.

Please use subject prefixes matching the subsystem. You can get them for example with 'git log --oneline -- DIRECTORY_OR_FILE' on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters

Quoted 6 lines
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml new file +0 -0
new file mode 100644
index 000000000000..3fbf788d4154

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml line 8

Quoted 8 lines
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml new file +8 -0
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (c) 2023 Analog Devices, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/adi,lt8722-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices LT8722 Ultracompact Full Bridge Driver

Driver like motor driver or regulator? Or Linux driver? If the latter then, drop. Describe the hardware please.

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml line 13

Quoted 5 lines
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml new file +5 -0
+
+maintainers:
+  - Ramon Cristopher Calam <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

That's all folks! More review when this is tested, please.

Best regards,
Krzysztof

#11 lore raw

RE: [PATCH 2/2] dt-bindings: regulator: Add adi,lt8722-regulator.yaml

Quoted 59 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Friday, November 8, 2024 7:43 PM
To: Calam, Ramon Cristopher <[email protected]>
Cc: [email protected]; [email protected]; Liam Girdwood <[email protected]>; Mark Brown <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>
Subject: Re: [PATCH 2/2] dt-bindings: regulator: Add adi,lt8722-regulator.yaml

[External]

Quoted 10 lines · Ramon Cristopher M. Calam

Add documentation for device tree bindings of LT8722.

Signed-off-by: Ramon Cristopher M. Calam
<[email protected]>

---
 .../regulator/adi,lt8722-regulator.yaml       | 178 ++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yaml

This wasn't tested, so limited review follows.

Please use subject prefixes matching the subsystem. You can get them for example with 'git log --oneline -- DIRECTORY_OR_FILE' on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://urldefense.com/v3/__https://www.kernel.org/doc/html/latest/devic
etree/bindings/submitting-patches.html*i-for-patch- submitters__;Iw!!A3Ni8CS0y2Y!4oCmeTiTgVsrbS0h3A8z0TbxaKPm_GIn6rOz 8q48wWGHHDiFUnSbWQNtfx1s1okiqOIwJh-jS1S68-GRpPAtAQ$

Quoted 11 lines

diff --git a/Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yam l b/Documentation/devicetree/bindings/regulator/adi,lt8722-regulator.yam l
new file mode 100644
index 000000000000..3fbf788d4154

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator new file +1 -0
+++ .yaml

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator line 7

Quoted 7 lines
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator new file +7 -0
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) # Copyright (c)
+2023 Analog Devices, Inc.
+%YAML 1.2
+---
+$id:
+https://urldefense.com/v3/__http://devicetree.org/schemas/regulator/a
+di,lt8722-

regulator.yaml*__;Iw!!A3Ni8CS0y2Y!4oCmeTiTgVsrbS0h3A8z0Tbxa

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator line 8

Quoted 1 line
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator new file +1 -0
+KPm_GIn6rOz8q48wWGHHDiFUnSbWQNtfx1s1okiqOIwJh-jS1S68-

GzivZhfQ$

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator line 10

Quoted 3 lines
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator new file +2 -0
+$schema:
+https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.y
Quoted 9 lines

+aml*__;Iw!!A3Ni8CS0y2Y!4oCmeTiTgVsrbS0h3A8z0TbxaKPm_GIn6rOz8q48 wWGHHD

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator line 13

Quoted 3 lines
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator new file +3 -0
+iFUnSbWQNtfx1s1okiqOIwJh-jS1S68-E5-fGDNQ$
+
+title: Analog Devices LT8722 Ultracompact Full Bridge Driver

Driver like motor driver or regulator? Or Linux driver? If the latter then, drop. Describe the hardware please.

The term 'driver' refers to the LT8722's function in controlling the full bridge output stage of the regulator.

One side of the full bridge is driven by a pulse width modulation (PWM) buck power stage, while the other side is driven by a linear power stage. An integrated 25-bit DAC is used to control the output voltage.

I will revise the title to ' Analog Devices LT8722 Ultracompact Full Bridge DC/DC Converter' for clarity and enhance the description with detailed hardware information.

Quoted 9 lines

Documentation/devicetree/bindings/regulator/adi,lt8722-regulator line 18

Quoted 6 lines
Documentation/devicetree/bindings/regulator/adi,lt8722-regulator new file +5 -0
+
+maintainers:
+  - Ramon Cristopher Calam <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

Quoted 4 lines

That's all folks! More review when this is tested, please.

Best regards,
Krzysztof

Thanks, I will remove this in the next patch.

Best regards,
Ramon