Skip to contentSkip to conversation

dt-bindings: hwmon: Add Infineon TDA38640

PATCH Superseded Naresh Solanki 2 participants 7 messages Aug 30, 2023 – Aug 31, 2023

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 dt-bindings: hwmon: Add Infineon TDA38640

From: Patrick Rudolph <[email protected]>

Add the DT property 'infineon,en-pin-fixed-level' to indicated that the chip ENABLE pin is at fixed level or left unconnected(has internal pull-down).

----
Changes in V4:
- Update property name & description.
- Update commit message.

---
 .../hwmon/pmbus/infineon,tda38640.yaml        | 50 +++++++++++++++++++
 .../devicetree/bindings/trivial-devices.yaml  |  2 -
 2 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +50 -0
new file mode 100644
index 000000000000..1df40ee7454a
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/pmbus/infineon,tda38640.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Infineon TDA38640 Synchronous Buck Regulator with SVID and I2C
+
+maintainers:
+  - Naresh Solanki <[email protected]>
+
+description: |
+  The Infineon TDA38640 is a 40A Single-voltage Synchronous Buck
+  Regulator with SVID and I2C designed for Industrial use.
+
+  Datasheet: https://www.infineon.com/dgdl/Infineon-TDA38640-0000-DataSheet-v02_04-EN.pdf?fileId=8ac78c8c80027ecd018042f2337f00c9
+
+properties:
+  compatible:
+    enum:
+      - infineon,tda38640
+
+  reg:
+    maxItems: 1
+
+  infineon,en-pin-fixed-level:
+    description: |
+      Indicates that the chip ENABLE pin is at fixed level or left
+      unconnected(has internal pull-down).
+    type: boolean
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        tda38640@40 {
+            compatible = "infineon,tda38640";
+            reg = <0x40>;
+        };
+    };
+
Documentation/devicetree/bindings/trivial-devices.yaml +0 -2
index 40bc475ee7e1..86c7d34f63bf 100644
@@ -151,8 +151,6 @@ properties:
           - infineon,slb9645tt
             # Infineon SLB9673 I2C TPM 2.0
           - infineon,slb9673
-            # Infineon TDA38640 Voltage Regulator
-          - infineon,tda38640
             # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor
           - infineon,tlv493d-a1b6
             # Infineon Multi-phase Digital VR Controller xdpe11280

base-commit: 919a83d020a8dfa1411c1dc1cff23a833f0f5268

Signature · 1 line
2.41.0
#1 lore raw

Hey,

Quoted 42 lines · Naresh Solanki

From: Patrick Rudolph <[email protected]>

Add the DT property 'infineon,en-pin-fixed-level' to indicated that the chip ENABLE pin is at fixed level or left unconnected(has internal pull-down).

----
Changes in V4:
- Update property name & description.
- Update commit message.

---
 .../hwmon/pmbus/infineon,tda38640.yaml        | 50 +++++++++++++++++++
 .../devicetree/bindings/trivial-devices.yaml  |  2 -
 2 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +18 -0
new file mode 100644
index 000000000000..1df40ee7454a
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/pmbus/infineon,tda38640.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Infineon TDA38640 Synchronous Buck Regulator with SVID and I2C
+
+maintainers:
+  - Naresh Solanki <[email protected]>
+
+description: |
+  The Infineon TDA38640 is a 40A Single-voltage Synchronous Buck
+  Regulator with SVID and I2C designed for Industrial use.
+
+  Datasheet: https://www.infineon.com/dgdl/Infineon-TDA38640-0000-DataSheet-v02_04-EN.pdf?fileId=8ac78c8c80027ecd018042f2337f00c9
+

Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml line 28

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +10 -0
+properties:
+  compatible:
+    enum:
+      - infineon,tda38640
+
+  reg:
+    maxItems: 1
+
+  infineon,en-pin-fixed-level:
+    description: |

The | isn't needed when there is no formatting requiring preservation.

Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml line 30

Quoted 2 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +2 -0
+      Indicates that the chip ENABLE pin is at fixed level or left
+      unconnected(has internal pull-down).

Maybe you've already been over this, but if the pin is called "enable" why not use the same wording in the property?

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +5 -0
+    type: boolean
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml line 45

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +10 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        tda38640@40 {

Use a generic node name please.

Thanks,
Conor.

Quoted 23 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +5 -0
+            compatible = "infineon,tda38640";
+            reg = <0x40>;
+        };
+    };
+
Documentation/devicetree/bindings/trivial-devices.yaml +0 -2
index 40bc475ee7e1..86c7d34f63bf 100644
@@ -151,8 +151,6 @@ properties:
           - infineon,slb9645tt
             # Infineon SLB9673 I2C TPM 2.0
           - infineon,slb9673
-            # Infineon TDA38640 Voltage Regulator
-          - infineon,tda38640
             # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor
           - infineon,tlv493d-a1b6
             # Infineon Multi-phase Digital VR Controller xdpe11280

base-commit: 919a83d020a8dfa1411c1dc1cff23a833f0f5268

Signature · 1 line
2.41.0
#2 lore raw

Hi

Quoted 50 lines · Conor Dooley

Hey,

Quoted 46 lines · Naresh Solanki

From: Patrick Rudolph <[email protected]>

Add the DT property 'infineon,en-pin-fixed-level' to indicated that the chip ENABLE pin is at fixed level or left unconnected(has internal pull-down).

----
Changes in V4:
- Update property name & description.
- Update commit message.

---
 .../hwmon/pmbus/infineon,tda38640.yaml        | 50 +++++++++++++++++++
 .../devicetree/bindings/trivial-devices.yaml  |  2 -
 2 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +22 -0
new file mode 100644
index 000000000000..1df40ee7454a
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/pmbus/infineon,tda38640.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Infineon TDA38640 Synchronous Buck Regulator with SVID and I2C
+
+maintainers:
+  - Naresh Solanki <[email protected]>
+
+description: |
+  The Infineon TDA38640 is a 40A Single-voltage Synchronous Buck
+  Regulator with SVID and I2C designed for Industrial use.
+
+  Datasheet: https://www.infineon.com/dgdl/Infineon-TDA38640-0000-DataSheet-v02_04-EN.pdf?fileId=8ac78c8c80027ecd018042f2337f00c9
+
+properties:
+  compatible:
+    enum:
+      - infineon,tda38640
Quoted 8 lines

Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml line 28

Quoted 6 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +6 -0
+
+  reg:
+    maxItems: 1
+
+  infineon,en-pin-fixed-level:
+    description: |

The | isn't needed when there is no formatting requiring preservation.

Sure will remove.

Quoted 6 lines

Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml line 30

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +2 -0
+      Indicates that the chip ENABLE pin is at fixed level or left
+      unconnected(has internal pull-down).

Maybe you've already been over this, but if the pin is called "enable" why not use the same wording in the property?

EN & ENABLE is used interchangeably in the datasheet. Just to keep property name short I use EN.

Quoted 45 lines
Quoted 6 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +5 -0
+    type: boolean
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml line 45

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +10 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        tda38640@40 {

Use a generic node name please.

Thanks,
Conor.

Quoted 23 lines
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +5 -0
+            compatible = "infineon,tda38640";
+            reg = <0x40>;
+        };
+    };
+
Documentation/devicetree/bindings/trivial-devices.yaml +0 -2
index 40bc475ee7e1..86c7d34f63bf 100644
@@ -151,8 +151,6 @@ properties:
           - infineon,slb9645tt
             # Infineon SLB9673 I2C TPM 2.0
           - infineon,slb9673
-            # Infineon TDA38640 Voltage Regulator
-          - infineon,tda38640
             # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor
           - infineon,tlv493d-a1b6
             # Infineon Multi-phase Digital VR Controller xdpe11280

base-commit: 919a83d020a8dfa1411c1dc1cff23a833f0f5268 --
2.41.0

#3 lore raw
Quoted 11 lines · Naresh Solanki

Hi

Quoted 7 lines · Conor Dooley

Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml line 30

Quoted 2 lines · Naresh Solanki
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +2 -0
+      Indicates that the chip ENABLE pin is at fixed level or left
+      unconnected(has internal pull-down).

Maybe you've already been over this, but if the pin is called "enable" why not use the same wording in the property?

EN & ENABLE is used interchangeably in the datasheet.

Maybe we can go 1 for 2 in terms of consistency then, rather than 0 for 2.

Quoted 1 line

Just to keep property name short I use EN.

Consistency & readability trump brevity. Please pick one term, or point out that this is called two things in the datasheet.

#4 lore raw

Hi

Quoted 10 lines · Conor Dooley
Quoted 8 lines · Naresh Solanki

Hi

Quoted 5 lines · Conor Dooley
Quoted 2 lines · Naresh Solanki
Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file +2 -0
+      Indicates that the chip ENABLE pin is at fixed level or left
+      unconnected(has internal pull-down).
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Maybe you've already been over this, but if the pin is called "enable" why not use the same wording in the property?

EN & ENABLE is used interchangeably in the datasheet.

Maybe we can go 1 for 2 in terms of consistency then, rather than 0 for 2.

Ack.
Will go for EN as that's what is mentioned as pin name in datasheet.

Quoted 5 lines
Quoted 2 lines

Just to keep property name short I use EN.

Consistency & readability trump brevity. Please pick one term, or point out that this is called two things in the datasheet.

Sure will pick one. i.e., EN. EN is pin name & description as mentioned in datasheet is 'Enable pin to turn on and off the IC'

Regards,
Naresh

Quoted 1 line
#5 lore raw

PATCH v4 2/3 hwmon: (pmbus) Add ON_OFF_CONFIG register bits

In reply to Naresh Solanki

From: Patrick Rudolph <[email protected]>

Add bits found in the ON_OFF_CONFIG register.

---
 drivers/hwmon/pmbus/pmbus.h | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/hwmon/pmbus/pmbus.h +9 -0
index b0832a4c690d..7a28bac7f171 100644
@@ -243,6 +243,15 @@ enum pmbus_regs {
  */
 #define PB_OPERATION_CONTROL_ON		BIT(7)
 
+/*
+ * ON_OFF_CONFIG
+ */
+#define PB_ON_OFF_CONFIG_POWERUP_CONTROL	BIT(4)
+#define PB_ON_OFF_CONFIG_OPERATION_REQ		BIT(3)
+#define PB_ON_OFF_CONFIG_EN_PIN_REQ		BIT(2)
+#define PB_ON_OFF_CONFIG_POLARITY_HIGH		BIT(1)
+#define PB_ON_OFF_CONFIG_TURN_OFF_FAST		BIT(0)
+
 /*
  * WRITE_PROTECT
  */
Signature · 1 line
2.41.0
#6 lore raw

PATCH v4 3/3 hwmon: (pmbus/tda38640) Add workaround for SVID mode

In reply to Naresh Solanki

From: Patrick Rudolph <[email protected]>

TDA38640 can operate in either PMBus mode or SVID mode.

In SVID mode, by design ENABLE pin is the only option for controlling the output rail i.e., ENABLE pin is chained to power good of another reglator & FPGA.

In cases where the chip is configured for SVID mode, and the ENABLE pin is set at a fixed level or is left unconnected (with an internal pull-down), while requiring software control, the following workaround is necessary.

The workaround utilizes ENABLE pin polarity flipping to control output rail.

If property 'infineon,en-pin-fixed-level' is specified then determine if chip is in SVID mode by checking BIT15 of MTP memory offset 0x44 as described in the datasheet.

If chip is in SVID mode then apply the workaround by
1. Determine EN pin level
2. Maps BIT7 of OPERATION(01h) to EN_PIN_POLARITY(BIT1) of PB_ON_OFF_CONFIG.

----
Changes in V4:
- Update DT property name
- Commit message update
Changes in V3:
- Use dt property to determine if workaround is needed. Changes in V2:
- Remove dependency on DT propery,
- Runtime determine SVID mode & ENABLE pin level,
- Update commit message.

---
 drivers/hwmon/pmbus/tda38640.c | 154 ++++++++++++++++++++++++++++++++-
 1 file changed, 152 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/tda38640.c +152 -2
index 450b0273fb59..c238330d2e6c 100644
@@ -18,6 +18,127 @@ static const struct regulator_desc __maybe_unused tda38640_reg_desc[] = {
 	PMBUS_REGULATOR("vout", 0),
 };
 
+struct tda38640_data {
+	struct pmbus_driver_info info;
+	u32 en_pin_lvl;
+};
+
+#define to_tda38640_data(x)  container_of(x, struct tda38640_data, info)
+
+/*
+ * Map PB_ON_OFF_CONFIG_POLARITY_HIGH to PB_OPERATION_CONTROL_ON.
+ */
+static int tda38640_read_byte_data(struct i2c_client *client, int page, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	struct tda38640_data *data = to_tda38640_data(info);
+	int ret, on_off_config, enabled;
+
+	if (reg != PMBUS_OPERATION)
+		return -ENODATA;
+
+	ret = pmbus_read_byte_data(client, page, reg);
+	if (ret < 0)
+		return ret;
+
+	on_off_config = pmbus_read_byte_data(client, page,
+					     PMBUS_ON_OFF_CONFIG);
+	if (on_off_config < 0)
+		return on_off_config;
+
+	enabled = !!(on_off_config & PB_ON_OFF_CONFIG_POLARITY_HIGH);
+
+	enabled ^= data->en_pin_lvl;
+	if (enabled)
+		ret &= ~PB_OPERATION_CONTROL_ON;
+	else
+		ret |= PB_OPERATION_CONTROL_ON;
+
+	return ret;
+}
+
+/*
+ * Map PB_OPERATION_CONTROL_ON to PB_ON_OFF_CONFIG_POLARITY_HIGH.
+ */
+static int tda38640_write_byte_data(struct i2c_client *client, int page,
+				    int reg, u8 byte)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	struct tda38640_data *data = to_tda38640_data(info);
+	int enable, ret;
+
+	if (reg != PMBUS_OPERATION)
+		return -ENODATA;
+
+	enable = !!(byte & PB_OPERATION_CONTROL_ON);
+
+	byte &= ~PB_OPERATION_CONTROL_ON;
+	ret = pmbus_write_byte_data(client, page, reg, byte);
+	if (ret < 0)
+		return ret;
+
+	enable ^= data->en_pin_lvl;
+
+	return pmbus_update_byte_data(client, page, PMBUS_ON_OFF_CONFIG,
+				      PB_ON_OFF_CONFIG_POLARITY_HIGH,
+				      enable ? 0 : PB_ON_OFF_CONFIG_POLARITY_HIGH);
+}
+
+static int svid_mode(struct i2c_client *client, struct tda38640_data *data)
+{
+	/* PMBUS_MFR_READ(0xD0) + MTP Address offset */
+	u8 write_buf[] = {0xd0, 0x44, 0x00};
+	u8 read_buf[2];
+	int ret, svid;
+	bool off, reg_en_pin_pol;
+
+	struct i2c_msg msgs[2] = {
+		{
+			.addr = client->addr,
+			.flags = 0,
+			.buf = write_buf,
+			.len = sizeof(write_buf),
+		},
+		{
+			.addr = client->addr,
+			.flags = I2C_M_RD,
+			.buf = read_buf,
+			.len = sizeof(read_buf),
+		}
+	};
+
+	ret = i2c_transfer(client->adapter, msgs, 2);
+	if (ret < 0) {
+		dev_err(&client->dev, "i2c_transfer failed. %d", ret);
+		return ret;
+	}
+
+	/*
+	 * 0x44[15] determines PMBus Operating Mode
+	 * If bit is set then it is SVID mode.
+	 */
+	svid = !!(read_buf[1] & BIT(7));
+
+	/*
+	 * Determine EN pin level for use in SVID mode.
+	 * This is done with help of STATUS_BYTE bit 6(OFF) & ON_OFF_CONFIG bit 2(EN pin polarity).
+	 */
+	if (svid) {
+		ret = i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE);
+		if (ret < 0)
+			return ret;
+		off = !!(ret & PB_STATUS_OFF);
+
+		ret = i2c_smbus_read_byte_data(client, PMBUS_ON_OFF_CONFIG);
+		if (ret < 0)
+			return ret;
+		reg_en_pin_pol = !!(ret & PB_ON_OFF_CONFIG_POLARITY_HIGH);
+		data->en_pin_lvl = off ^ reg_en_pin_pol;
+	}
+
+	return svid;
+}
+
 static struct pmbus_driver_info tda38640_info = {
 	.pages = 1,
 	.format[PSC_VOLTAGE_IN] = linear,
@@ -26,7 +147,6 @@ static struct pmbus_driver_info tda38640_info = {
 	.format[PSC_CURRENT_IN] = linear,
 	.format[PSC_POWER] = linear,
 	.format[PSC_TEMPERATURE] = linear,
-
 	.func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT
 	    | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP
 	    | PMBUS_HAVE_IIN
@@ -41,7 +161,37 @@ static struct pmbus_driver_info tda38640_info = {
 
 static int tda38640_probe(struct i2c_client *client)
 {
-	return pmbus_do_probe(client, &tda38640_info);
+	struct tda38640_data *data;
+	int svid;
+
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+	memcpy(&data->info, &tda38640_info, sizeof(tda38640_info));
+
+	if (IS_ENABLED(CONFIG_SENSORS_TDA38640_REGULATOR) && \
+	    of_property_read_bool(client->dev.of_node, "infineon,en-pin-fixed-level")) {
+		svid = svid_mode(client, data);
+		if (svid < 0) {
+			dev_err_probe(&client->dev, svid, "Could not determine operating mode.");
+			return svid;
+		}
+
+		/*
+		 * Apply ON_OFF_CONFIG workaround as enabling the regulator using the
+		 * OPERATION register doesn't work in SVID mode.
+		 *
+		 * One should configure PMBUS_ON_OFF_CONFIG here, but
+		 * PB_ON_OFF_CONFIG_POWERUP_CONTROL and PB_ON_OFF_CONFIG_EN_PIN_REQ
+		 * are ignored by the device.
+		 * Only PB_ON_OFF_CONFIG_POLARITY_HIGH has an effect.
+		 */
+		if (svid) {
+			data->info.read_byte_data = tda38640_read_byte_data;
+			data->info.write_byte_data = tda38640_write_byte_data;
+		}
+	}
+	return pmbus_do_probe(client, &data->info);
 }
 
 static const struct i2c_device_id tda38640_id[] = {
Signature · 1 line
2.41.0