From: "Kallas, Pawel" <pawel.kallas@intel.com>
To: linux@roeck-us.net, jdelvare@suse.com, corbet@lwn.net,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org
Cc: iwona.winiarska@intel.com, pawel.kallas@intel.com
Subject: [PATCH 1/3] hwmon: (pmbus) add support for QUERY command
Date: Wed, 6 Jul 2022 12:40:22 +0200 [thread overview]
Message-ID: <20220706104024.3118590-2-pawel.kallas@intel.com> (raw)
In-Reply-To: <20220706104024.3118590-1-pawel.kallas@intel.com>
QUERY command is used for checking if given command is supported by
the device and what data format it uses. It is needed to check if
READ_EIN and READ_EOUT commands are supported.
Signed-off-by: Kallas, Pawel <pawel.kallas@intel.com>
---
Documentation/hwmon/pmbus-core.rst | 7 +++++++
drivers/hwmon/pmbus/pmbus.h | 14 ++++++++++++++
drivers/hwmon/pmbus/pmbus_core.c | 21 +++++++++++++++++++++
3 files changed, 42 insertions(+)
diff --git a/Documentation/hwmon/pmbus-core.rst b/Documentation/hwmon/pmbus-core.rst
index e7e0c9ef10bec..6ba0a9d86f1f6 100644
--- a/Documentation/hwmon/pmbus-core.rst
+++ b/Documentation/hwmon/pmbus-core.rst
@@ -268,6 +268,13 @@ otherwise.
This function calls the device specific write_byte function if defined to
obtain the chip status. Therefore, it must _not_ be called from that function.
+::
+
+ int pmbus_query_register(struct i2c_client *client, int reg);
+
+Send pmbus QUERY command for specific register. Returns QUERY command
+response or negative value on fail.
+
::
int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info);
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index 75aa97b1ecc05..971554f40dba6 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -364,6 +364,19 @@ enum pmbus_fan_mode { percent = 0, rpm };
#define PB_CML_FAULT_INVALID_DATA BIT(6)
#define PB_CML_FAULT_INVALID_COMMAND BIT(7)
+/*
+ * QUERY
+ */
+#define PB_QUERY_COMMAND_MODE_MASK 0x1C
+
+#define PB_QUERY_COMMAND_MODE_LINEAR 0x00
+#define PB_QUERY_COMMAND_MODE_DIRECT 0x0C
+#define PB_QUERY_COMMAND_MODE_VID 0x14
+
+#define PB_QUERY_COMMAND_SUPPORTED_FOR_READ BIT(5)
+#define PB_QUERY_COMMAND_SUPPORTED_FOR_WRITE BIT(6)
+#define PB_QUERY_COMMAND_SUPPORTED BIT(7)
+
enum pmbus_sensor_classes {
PSC_VOLTAGE_IN = 0,
PSC_VOLTAGE_OUT,
@@ -492,6 +505,7 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
void pmbus_clear_faults(struct i2c_client *client);
bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
+int pmbus_query_register(struct i2c_client *client, int reg);
int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info);
const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
*client);
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index d462f732f3b40..4bcb70ab9b598 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -648,6 +648,27 @@ static int pmbus_get_status(struct i2c_client *client, int page, int reg)
return status;
}
+int pmbus_query_register(struct i2c_client *client, int reg)
+{
+ int rv;
+ union i2c_smbus_data data;
+
+ data.block[0] = 1;
+ data.block[1] = reg;
+
+ rv = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
+ I2C_SMBUS_WRITE, PMBUS_QUERY,
+ I2C_SMBUS_BLOCK_PROC_CALL, &data);
+ if (rv < 0)
+ return rv;
+
+ if (data.block[0] != 1)
+ return -EIO;
+
+ return data.block[1];
+}
+EXPORT_SYMBOL_NS_GPL(pmbus_query_register, PMBUS);
+
static void pmbus_update_sensor_data(struct i2c_client *client, struct pmbus_sensor *sensor)
{
if (sensor->data < 0 || sensor->update)
next prev parent reply other threads:[~2022-07-06 10:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-06 10:40 [PATCH 0/3] hwmon: (pmbus) add power from energy readings Kallas, Pawel
2022-07-06 10:40 ` Kallas, Pawel [this message]
2022-07-06 10:40 ` [PATCH 2/3] hwmon: (pmbus) refactor sensor initialization Kallas, Pawel
2022-07-06 10:40 ` [PATCH 3/3] hwmon: (pmbus) add EIN and EOUT readings Kallas, Pawel
2022-07-06 13:17 ` [PATCH 0/3] hwmon: (pmbus) add power from energy readings Guenter Roeck
2022-07-07 14:01 ` Kallas, Pawel
2022-07-07 14:09 ` Guenter Roeck
2022-07-07 16:00 ` Kallas, Pawel
2022-07-14 13:38 ` 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=20220706104024.3118590-2-pawel.kallas@intel.com \
--to=pawel.kallas@intel.com \
--cc=corbet@lwn.net \
--cc=iwona.winiarska@intel.com \
--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).