qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Titus Rwantare" <titusr@google.com>,
	"Corey Minyard" <cminyard@mvista.com>,
	"Shengtan Mao" <stmao@google.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Corey Minyard" <minyard@acm.org>
Subject: [PULL 6/9] hw/i2c: Added linear mode translation for pmbus devices
Date: Tue,  8 Mar 2022 19:13:17 +0100	[thread overview]
Message-ID: <20220308181320.79400-7-philippe.mathieu.daude@gmail.com> (raw)
In-Reply-To: <20220308181320.79400-1-philippe.mathieu.daude@gmail.com>

From: Shengtan Mao <stmao@google.com>

Signed-off-by: Shengtan Mao <stmao@google.com>
Reviewed-by: Titus Rwantare <titusr@google.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Corey Minyard <cminyard@mvista.com>
Message-Id: <20220307200605.4001451-7-titusr@google.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/i2c/pmbus_device.c         | 18 ++++++++++++++++++
 include/hw/i2c/pmbus_device.h | 20 +++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c
index 8cb9db0f80..62885fa6a1 100644
--- a/hw/i2c/pmbus_device.c
+++ b/hw/i2c/pmbus_device.c
@@ -28,6 +28,24 @@ uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value)
     return x;
 }
 
+uint16_t pmbus_data2linear_mode(uint16_t value, int exp)
+{
+    /* L = D * 2^(-e) */
+    if (exp < 0) {
+        return value << (-exp);
+    }
+    return value >> exp;
+}
+
+uint16_t pmbus_linear_mode2data(uint16_t value, int exp)
+{
+    /* D = L * 2^e */
+    if (exp < 0) {
+        return value >> (-exp);
+    }
+    return value << exp;
+}
+
 void pmbus_send(PMBusDevice *pmdev, const uint8_t *data, uint16_t len)
 {
     if (pmdev->out_buf_len + len > SMBUS_DATA_MAX_LEN) {
diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h
index bab4526734..0f4d6b3fad 100644
--- a/include/hw/i2c/pmbus_device.h
+++ b/include/hw/i2c/pmbus_device.h
@@ -448,7 +448,7 @@ typedef struct PMBusCoefficients {
  *
  * Y = (m * x - b) * 10^R
  *
- * @return uint32_t
+ * @return uint16_t
  */
 uint16_t pmbus_data2direct_mode(PMBusCoefficients c, uint32_t value);
 
@@ -461,6 +461,24 @@ uint16_t pmbus_data2direct_mode(PMBusCoefficients c, uint32_t value);
  */
 uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value);
 
+/**
+ * Convert sensor values to linear mode format
+ *
+ * L = D * 2^(-e)
+ *
+ * @return uint16
+ */
+uint16_t pmbus_data2linear_mode(uint16_t value, int exp);
+
+/**
+ * Convert linear mode formatted data into sensor reading
+ *
+ * D = L * 2^e
+ *
+ * @return uint16
+ */
+uint16_t pmbus_linear_mode2data(uint16_t value, int exp);
+
 /**
  * @brief Send a block of data over PMBus
  * Assumes that the bytes in the block are already ordered correctly,
-- 
2.34.1



  parent reply	other threads:[~2022-03-08 18:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 18:13 [PULL 0/9] I²C / SMBus / PMBus patches for 2022-03-08 Philippe Mathieu-Daudé
2022-03-08 18:13 ` [PULL 1/9] hw/i2c: pmbus: add registers Philippe Mathieu-Daudé
2022-03-08 18:13 ` [PULL 2/9] hw/i2c: pmbus: fix error returns and guard against out of range accesses Philippe Mathieu-Daudé
2022-03-08 18:13 ` [PULL 3/9] hw/i2c: pmbus: add PEC unsupported warning Philippe Mathieu-Daudé
2022-03-08 18:13 ` [PULL 4/9] hw/i2c: pmbus: refactor uint handling Philippe Mathieu-Daudé
2022-03-08 18:13 ` [PULL 5/9] hw/i2c: pmbus: update MAINTAINERS Philippe Mathieu-Daudé
2022-03-08 18:13 ` Philippe Mathieu-Daudé [this message]
2022-03-08 18:13 ` [PULL 7/9] hw/sensor: add Intersil ISL69260 device model Philippe Mathieu-Daudé
2022-03-08 18:13 ` [PULL 8/9] hw/sensor: add Renesas raa229004 PMBus device Philippe Mathieu-Daudé
2022-03-08 18:13 ` [PULL 9/9] hw/sensor: add Renesas raa228000 device Philippe Mathieu-Daudé
2022-03-10  9:18 ` [PULL 0/9] I²C / SMBus / PMBus patches for 2022-03-08 Peter Maydell
2022-03-10 11:26   ` Philippe Mathieu-Daudé

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=20220308181320.79400-7-philippe.mathieu.daude@gmail.com \
    --to=philippe.mathieu.daude@gmail.com \
    --cc=cminyard@mvista.com \
    --cc=f4bug@amsat.org \
    --cc=minyard@acm.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stmao@google.com \
    --cc=titusr@google.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;
as well as URLs for NNTP newsgroup(s).