From: Erik Rosen <erik.rosen@metormote.com>
To: Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Jonathan Corbet <corbet@lwn.net>,
linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Erik Rosen <erik.rosen@metormote.com>
Subject: [PATCH v2 2/6] hwmon: (pmbus/pim4328) Add function for reading direct mode coefficients
Date: Sat, 22 May 2021 12:55:24 +0200 [thread overview]
Message-ID: <20210522105528.87629-3-erik.rosen@metormote.com> (raw)
In-Reply-To: <20210522105528.87629-1-erik.rosen@metormote.com>
Add the function pmbus_read_coefficients to pmbus_core to be able to
read and decode the coefficients for the direct format for a certain
command and read/write direction.
Signed-off-by: Erik Rosen <erik.rosen@metormote.com>
---
drivers/hwmon/pmbus/pmbus.h | 4 ++++
drivers/hwmon/pmbus/pmbus_core.c | 38 ++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index 3968924f8533..d9ed9736b480 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -499,6 +499,10 @@ int pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id,
enum pmbus_fan_mode mode);
int pmbus_update_fan(struct i2c_client *client, int page, int id,
u8 config, u8 mask, u16 command);
+int pmbus_read_coefficients(struct i2c_client *client,
+ struct pmbus_driver_info *info,
+ enum pmbus_sensor_classes sensor_class,
+ u8 command);
struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client);
#endif /* PMBUS_H */
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index cb885efc4fba..460cbfd716e4 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -301,6 +301,44 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id,
}
EXPORT_SYMBOL_NS_GPL(pmbus_update_fan, PMBUS);
+/*
+ * Read the coefficients for direct mode.
+ */
+int pmbus_read_coefficients(struct i2c_client *client,
+ struct pmbus_driver_info *info,
+ enum pmbus_sensor_classes sensor_class,
+ u8 command)
+{
+ int rv;
+ union i2c_smbus_data data;
+ s8 R;
+ s16 m, b;
+
+ data.block[0] = 2;
+ data.block[1] = command;
+ data.block[2] = 0x01;
+
+ rv = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
+ I2C_SMBUS_WRITE, PMBUS_COEFFICIENTS,
+ I2C_SMBUS_BLOCK_PROC_CALL, &data);
+
+ if (rv < 0)
+ return rv;
+
+ if (data.block[0] != 5)
+ return -EIO;
+
+ m = data.block[1] | (data.block[2] << 8);
+ b = data.block[3] | (data.block[4] << 8);
+ R = data.block[5];
+ info->m[sensor_class] = m;
+ info->b[sensor_class] = b;
+ info->R[sensor_class] = R;
+
+ return rv;
+}
+EXPORT_SYMBOL_NS_GPL(pmbus_read_coefficients, PMBUS);
+
int pmbus_read_word_data(struct i2c_client *client, int page, int phase, u8 reg)
{
int rv;
--
2.20.1
next prev parent reply other threads:[~2021-05-22 10:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-22 10:55 [PATCH v2 0/6] hwmon: (pmbus/pim4328) Add pim4328 PMBus driver Erik Rosen
2021-05-22 10:55 ` [PATCH v2 1/6] hwmon: (pmbus/pim4328) Add new pmbus flag NO_WRITE_PROTECT Erik Rosen
2021-05-22 10:55 ` Erik Rosen [this message]
2021-05-22 10:55 ` [PATCH v2 3/6] hwmon: (pmbus/pim4328) Add support for reading direct format coefficients Erik Rosen
2021-05-22 13:41 ` Guenter Roeck
2021-05-23 17:52 ` Erik Rosen
2021-05-23 19:47 ` Guenter Roeck
2021-05-22 10:55 ` [PATCH v2 4/6] hwmon: (pmbus/pim4328) Allow phase function even if it's not on page Erik Rosen
2021-05-22 10:55 ` [PATCH v2 5/6] hwmon: (pmbus/pim4328) Add PMBus driver for PIM4006, PIM4328 and PIM4820 Erik Rosen
2021-05-22 10:55 ` [PATCH v2 6/6] hwmon: (pmbus/pim4328) Add documentation for the pim4328 PMBus driver Erik Rosen
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=20210522105528.87629-3-erik.rosen@metormote.com \
--to=erik.rosen@metormote.com \
--cc=corbet@lwn.net \
--cc=jdelvare@suse.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/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;
as well as URLs for NNTP newsgroup(s).