[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 6/9] hw/i2c: Added linear mode translation for pmbus devices
From: |
Titus Rwantare |
Subject: |
[PATCH v3 6/9] hw/i2c: Added linear mode translation for pmbus devices |
Date: |
Tue, 1 Mar 2022 17:50:50 -0800 |
From: Shengtan Mao <stmao@google.com>
Signed-off-by: Shengtan Mao <stmao@google.com>
Reviewed-by: Titus Rwantare <titusr@google.com>
---
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 3beb02afad..1036c41c49 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 72c0483149..9a274247ab 100644
--- a/include/hw/i2c/pmbus_device.h
+++ b/include/hw/i2c/pmbus_device.h
@@ -446,7 +446,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);
@@ -459,6 +459,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.35.1.616.g0bdcbb4464-goog
- [PATCH v3 0/9] This patch series contains updates to PMBus in QEMU along with some PMBus device models for Renesas regulators. I have also added myself to MAINTAINERS as this code is in use daily, where I am responsible for it., Titus Rwantare, 2022/03/01
- [PATCH v3 1/9] hw/i2c: pmbus: add registers, Titus Rwantare, 2022/03/01
- [PATCH v3 3/9] hw/i2c: pmbus: add PEC unsupported warning, Titus Rwantare, 2022/03/01
- [PATCH v3 4/9] hw/i2c: pmbus: refactor uint handling, Titus Rwantare, 2022/03/01
- [PATCH v3 6/9] hw/i2c: Added linear mode translation for pmbus devices,
Titus Rwantare <=
- [PATCH v3 8/9] hw/sensor: add Renesas raa229004 PMBus device, Titus Rwantare, 2022/03/01
- [PATCH v3 2/9] hw/i2c: pmbus: guard against out of range accesses, Titus Rwantare, 2022/03/01
- [PATCH v3 9/9] hw/sensor: add Renesas raa228000 device, Titus Rwantare, 2022/03/01
- [PATCH v3 5/9] hw/i2c: pmbus: update MAINTAINERS, Titus Rwantare, 2022/03/01