summary refs log tree commit diff stats
path: root/hw/i2c
diff options
context:
space:
mode:
authorShengtan Mao <stmao@google.com>2022-03-07 12:06:02 -0800
committerPhilippe Mathieu-Daudé <f4bug@amsat.org>2022-03-08 18:46:48 +0100
commit648a488216837bda04114b700246011316b44478 (patch)
treeaf18f2cad7fa2eca7725d277221cbdc0e1e67594 /hw/i2c
parentbf0e0c70924c725b7b778f6b870a72f789a359af (diff)
downloadfocaccia-qemu-648a488216837bda04114b700246011316b44478.tar.gz
focaccia-qemu-648a488216837bda04114b700246011316b44478.zip
hw/i2c: Added linear mode translation for pmbus devices
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>
Diffstat (limited to 'hw/i2c')
-rw-r--r--hw/i2c/pmbus_device.c18
1 files changed, 18 insertions, 0 deletions
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) {