From: Naresh Solanki <naresh.solanki@9elements.com>
To: Guenter Roeck <linux@roeck-us.net>,
Jean Delvare <jdelvare@suse.com>,
krzysztof.kozlowski+dt@linaro.org
Cc: linux-hwmon@vger.kernel.org,
Patrick Rudolph <patrick.rudolph@9elements.com>,
Naresh Solanki <Naresh.Solanki@9elements.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] hwmon: (pmbus/tda38640) Add workaround for bug in SVID mode
Date: Tue, 25 Jul 2023 13:40:28 +0200 [thread overview]
Message-ID: <20230725114030.1860571-3-Naresh.Solanki@9elements.com> (raw)
In-Reply-To: <20230725114030.1860571-1-Naresh.Solanki@9elements.com>
From: Patrick Rudolph <patrick.rudolph@9elements.com>
The TDA38640 supports two operating modes to set the output voltage:
- PMBUS
- SVID
Due to an undocumented bug the regulator cannot be enabled using BIT7
of OPERATION(01h) register when in SVID mode.
It works when in PMBUS mode. In SVID mode the regulator only cares
about the ENABLE pin.
Add a workaround that needs the ENABLE pin to be left floating or
tied to a fixed level. The DT must contain the newly introduced
property 'infineon,en-pin-fixed-level' to enable this workaround.
The workaround will map the PB_OPERATION_CONTROL_ON bit to the
PB_ON_OFF_CONFIG_EN_PIN_REQ bit of the ON_OFF_CONFIG register.
In combination with the fixed level on the ENABLE pin the regulator
can be controlled as expected.
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
drivers/hwmon/pmbus/tda38640.c | 95 +++++++++++++++++++++++++++++++++-
1 file changed, 93 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/pmbus/tda38640.c b/drivers/hwmon/pmbus/tda38640.c
index 450b0273fb59..9d3b89d9845c 100644
--- a/drivers/hwmon/pmbus/tda38640.c
+++ b/drivers/hwmon/pmbus/tda38640.c
@@ -18,6 +18,72 @@ 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 struct pmbus_driver_info tda38640_info = {
.pages = 1,
.format[PSC_VOLTAGE_IN] = linear,
@@ -26,7 +92,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 +106,33 @@ static struct pmbus_driver_info tda38640_info = {
static int tda38640_probe(struct i2c_client *client)
{
- return pmbus_do_probe(client, &tda38640_info);
+ struct device *dev = &client->dev;
+ struct device_node *np = dev_of_node(dev);
+ struct tda38640_data *data;
+
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+ memcpy(&data->info, &tda38640_info, sizeof(tda38640_info));
+
+ if (!CONFIG_SENSORS_TDA38640_REGULATOR || !np ||
+ of_property_read_u32(np, "infineon,en-pin-fixed-level", &data->en_pin_lvl))
+ return pmbus_do_probe(client, &data->info);
+
+ /*
+ * Apply ON_OFF_CONFIG workaround as enabling the regulator using the
+ * OPERATION register doesn't work in SVID mode.
+ */
+ data->info.read_byte_data = tda38640_read_byte_data;
+ data->info.write_byte_data = tda38640_write_byte_data;
+ /*
+ * One should configure PMBUS_ON_OFF_CONFIG here, but
+ * PB_ON_OFF_CONFIG_POWERUP_CONTROL, PB_ON_OFF_CONFIG_EN_PIN_REQ and
+ * PB_ON_OFF_CONFIG_EN_PIN_REQ are ignored by the device.
+ * Only PB_ON_OFF_CONFIG_POLARITY_HIGH has an effect.
+ */
+
+ return pmbus_do_probe(client, &data->info);
}
static const struct i2c_device_id tda38640_id[] = {
--
2.41.0
next prev parent reply other threads:[~2023-07-25 11:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-25 11:40 [PATCH 1/3] dt-bindings: hwmon: Add Infineon TDA38640 Naresh Solanki
2023-07-25 11:40 ` [PATCH 2/3] hwmon: (pmbus) Add ON_OFF_CONFIG register bits Naresh Solanki
2023-07-25 11:40 ` Naresh Solanki [this message]
2023-07-25 14:21 ` [PATCH 3/3] hwmon: (pmbus/tda38640) Add workaround for bug in SVID mode Guenter Roeck
2023-07-26 12:22 ` Naresh Solanki
2023-07-26 14:19 ` Guenter Roeck
2023-07-27 8:30 ` Naresh Solanki
2023-07-25 16:19 ` kernel test robot
2023-07-25 18:54 ` kernel test robot
2023-07-25 12:28 ` [PATCH 1/3] dt-bindings: hwmon: Add Infineon TDA38640 Rob Herring
2023-07-25 13:10 ` Rob Herring
2023-07-25 14:17 ` Naresh Solanki
2023-07-25 14:28 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230725114030.1860571-3-Naresh.Solanki@9elements.com \
--to=naresh.solanki@9elements.com \
--cc=jdelvare@suse.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=patrick.rudolph@9elements.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome