Skip to contentSkip to conversation

tmp105: Improvements and fixes

PATCH In review Philippe Mathieu-Daudé 3 participants 13 messages Sep 6, 2024 – Sep 12, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover tmp105: Improvements and fixes

Respin of Guenter fixes with:
- Use registerfields API
- Clear OS bit in WRITE path

Supersedes: <[email protected]>

Guenter Roeck (2):
hw/sensor/tmp105: Coding style fixes hw/sensor/tmp105: Lower 4 bit of limit registers are always 0

Philippe Mathieu-Daudé (3):
hw/sensor/tmp105: Use registerfields API
hw/sensor/tmp105: Pass 'oneshot' argument to tmp105_alarm_update() hw/sensor/tmp105: OS (one-shot) bit in config register always returns

    0
 hw/sensor/tmp105.c | 66 ++++++++++++++++++++++++++--------------------
 1 file changed, 37 insertions(+), 29 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/5 hw/sensor/tmp105: Coding style fixes

From: Guenter Roeck <[email protected]>

Coding style asks for no space between variable and "++". The next patch in this series will change one of those assignments. Instead of changing just one with that patch, change all of them for consistency.

While at it, also fix other coding style problems reported by checkpatch.

---
 hw/sensor/tmp105.c | 44 ++++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 20 deletions(-)
hw/sensor/tmp105.c +24 -20
index a8730d0b7f..ad97c9684c 100644
@@ -29,16 +29,17 @@
 
 static void tmp105_interrupt_update(TMP105State *s)
 {
-    qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1));	/* POL */
+    qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1));   /* POL */
 }
 
 static void tmp105_alarm_update(TMP105State *s)
 {
-    if ((s->config >> 0) & 1) {					/* SD */
-        if ((s->config >> 7) & 1)				/* OS */
-            s->config &= ~(1 << 7);				/* OS */
-        else
+    if ((s->config >> 0) & 1) {                                 /* SD */
+        if ((s->config >> 7) & 1) {                             /* OS */
+            s->config &= ~(1 << 7);                             /* OS */
+        } else {
             return;
+        }
     }
 
     if (s->config >> 1 & 1) {
@@ -89,7 +90,8 @@ static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name,
     visit_type_int(v, name, &value, errp);
 }
 
-/* Units are 0.001 centigrades relative to 0 C.  s->temperature is 8.8
+/*
+ * Units are 0.001 centigrades relative to 0 C.  s->temperature is 8.8
  * fixed point, so units are 1/256 centigrades.  A simple ratio will do.
  */
 static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,
@@ -118,30 +120,30 @@ static void tmp105_read(TMP105State *s)
 {
     s->len = 0;
 
-    if ((s->config >> 1) & 1) {					/* TM */
+    if ((s->config >> 1) & 1) {                                 /* TM */
         s->alarm = 0;
         tmp105_interrupt_update(s);
     }
 
     switch (s->pointer & 3) {
     case TMP105_REG_TEMPERATURE:
-        s->buf[s->len ++] = (((uint16_t) s->temperature) >> 8);
-        s->buf[s->len ++] = (((uint16_t) s->temperature) >> 0) &
-                (0xf0 << ((~s->config >> 5) & 3));		/* R */
+        s->buf[s->len++] = (((uint16_t) s->temperature) >> 8);
+        s->buf[s->len++] = (((uint16_t) s->temperature) >> 0) &
+                (0xf0 << ((~s->config >> 5) & 3));              /* R */
         break;
 
     case TMP105_REG_CONFIG:
-        s->buf[s->len ++] = s->config;
+        s->buf[s->len++] = s->config;
         break;
 
     case TMP105_REG_T_LOW:
-        s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 8;
-        s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 0;
+        s->buf[s->len++] = ((uint16_t) s->limit[0]) >> 8;
+        s->buf[s->len++] = ((uint16_t) s->limit[0]) >> 0;
         break;
 
     case TMP105_REG_T_HIGH:
-        s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 8;
-        s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 0;
+        s->buf[s->len++] = ((uint16_t) s->limit[1]) >> 8;
+        s->buf[s->len++] = ((uint16_t) s->limit[1]) >> 0;
         break;
     }
 }
@@ -153,18 +155,20 @@ static void tmp105_write(TMP105State *s)
         break;
 
     case TMP105_REG_CONFIG:
-        if (s->buf[0] & ~s->config & (1 << 0))			/* SD */
+        if (s->buf[0] & ~s->config & (1 << 0)) {                /* SD */
             printf("%s: TMP105 shutdown\n", __func__);
+        }
         s->config = s->buf[0];
-        s->faults = tmp105_faultq[(s->config >> 3) & 3];	/* F */
+        s->faults = tmp105_faultq[(s->config >> 3) & 3];        /* F */
         tmp105_alarm_update(s);
         break;
 
     case TMP105_REG_T_LOW:
     case TMP105_REG_T_HIGH:
-        if (s->len >= 3)
+        if (s->len >= 3) {
             s->limit[s->pointer & 1] = (int16_t)
                     ((((uint16_t) s->buf[0]) << 8) | s->buf[1]);
+        }
         tmp105_alarm_update(s);
         break;
     }
@@ -175,7 +179,7 @@ static uint8_t tmp105_rx(I2CSlave *i2c)
     TMP105State *s = TMP105(i2c);
 
     if (s->len < 2) {
-        return s->buf[s->len ++];
+        return s->buf[s->len++];
     } else {
         return 0xff;
     }
@@ -215,7 +219,7 @@ static int tmp105_post_load(void *opaque, int version_id)
 {
     TMP105State *s = opaque;
 
-    s->faults = tmp105_faultq[(s->config >> 3) & 3];		/* F */
+    s->faults = tmp105_faultq[(s->config >> 3) & 3];            /* F */
 
     tmp105_interrupt_update(s);
     return 0;
Signature · 1 line
2.45.2
author Reviewed-by Cédric Le Goater on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] hw/sensor/tmp105: Coding style fixes

Quoted 9 lines · Philippe Mathieu-Daudé

From: Guenter Roeck <[email protected]>

Coding style asks for no space between variable and "++". The next patch in this series will change one of those assignments. Instead of changing just one with that patch, change all of them for consistency.

While at it, also fix other coding style problems reported by checkpatch.

Quoted 124 lines
---
  hw/sensor/tmp105.c | 44 ++++++++++++++++++++++++--------------------
  1 file changed, 24 insertions(+), 20 deletions(-)
hw/sensor/tmp105.c +24 -20
index a8730d0b7f..ad97c9684c 100644
@@ -29,16 +29,17 @@
 
  static void tmp105_interrupt_update(TMP105State *s)
  {
-    qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1));	/* POL */
+    qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1));   /* POL */
  }
 
  static void tmp105_alarm_update(TMP105State *s)
  {
-    if ((s->config >> 0) & 1) {					/* SD */
-        if ((s->config >> 7) & 1)				/* OS */
-            s->config &= ~(1 << 7);				/* OS */
-        else
+    if ((s->config >> 0) & 1) {                                 /* SD */
+        if ((s->config >> 7) & 1) {                             /* OS */
+            s->config &= ~(1 << 7);                             /* OS */
+        } else {
              return;
+        }
      }
 
      if (s->config >> 1 & 1) {
@@ -89,7 +90,8 @@ static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name,
      visit_type_int(v, name, &value, errp);
  }
 
-/* Units are 0.001 centigrades relative to 0 C.  s->temperature is 8.8
+/*
+ * Units are 0.001 centigrades relative to 0 C.  s->temperature is 8.8
   * fixed point, so units are 1/256 centigrades.  A simple ratio will do.
   */
  static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,
@@ -118,30 +120,30 @@ static void tmp105_read(TMP105State *s)
  {
      s->len = 0;
 
-    if ((s->config >> 1) & 1) {					/* TM */
+    if ((s->config >> 1) & 1) {                                 /* TM */
          s->alarm = 0;
          tmp105_interrupt_update(s);
      }
 
      switch (s->pointer & 3) {
      case TMP105_REG_TEMPERATURE:
-        s->buf[s->len ++] = (((uint16_t) s->temperature) >> 8);
-        s->buf[s->len ++] = (((uint16_t) s->temperature) >> 0) &
-                (0xf0 << ((~s->config >> 5) & 3));		/* R */
+        s->buf[s->len++] = (((uint16_t) s->temperature) >> 8);
+        s->buf[s->len++] = (((uint16_t) s->temperature) >> 0) &
+                (0xf0 << ((~s->config >> 5) & 3));              /* R */
          break;
 
      case TMP105_REG_CONFIG:
-        s->buf[s->len ++] = s->config;
+        s->buf[s->len++] = s->config;
          break;
 
      case TMP105_REG_T_LOW:
-        s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 8;
-        s->buf[s->len ++] = ((uint16_t) s->limit[0]) >> 0;
+        s->buf[s->len++] = ((uint16_t) s->limit[0]) >> 8;
+        s->buf[s->len++] = ((uint16_t) s->limit[0]) >> 0;
          break;
 
      case TMP105_REG_T_HIGH:
-        s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 8;
-        s->buf[s->len ++] = ((uint16_t) s->limit[1]) >> 0;
+        s->buf[s->len++] = ((uint16_t) s->limit[1]) >> 8;
+        s->buf[s->len++] = ((uint16_t) s->limit[1]) >> 0;
          break;
      }
  }
@@ -153,18 +155,20 @@ static void tmp105_write(TMP105State *s)
          break;
 
      case TMP105_REG_CONFIG:
-        if (s->buf[0] & ~s->config & (1 << 0))			/* SD */
+        if (s->buf[0] & ~s->config & (1 << 0)) {                /* SD */
              printf("%s: TMP105 shutdown\n", __func__);
+        }
          s->config = s->buf[0];
-        s->faults = tmp105_faultq[(s->config >> 3) & 3];	/* F */
+        s->faults = tmp105_faultq[(s->config >> 3) & 3];        /* F */
          tmp105_alarm_update(s);
          break;
 
      case TMP105_REG_T_LOW:
      case TMP105_REG_T_HIGH:
-        if (s->len >= 3)
+        if (s->len >= 3) {
              s->limit[s->pointer & 1] = (int16_t)
                      ((((uint16_t) s->buf[0]) << 8) | s->buf[1]);
+        }
          tmp105_alarm_update(s);
          break;
      }
@@ -175,7 +179,7 @@ static uint8_t tmp105_rx(I2CSlave *i2c)
      TMP105State *s = TMP105(i2c);
 
      if (s->len < 2) {
-        return s->buf[s->len ++];
+        return s->buf[s->len++];
      } else {
          return 0xff;
      }
@@ -215,7 +219,7 @@ static int tmp105_post_load(void *opaque, int version_id)
  {
      TMP105State *s = opaque;
 
-    s->faults = tmp105_faultq[(s->config >> 3) & 3];		/* F */
+    s->faults = tmp105_faultq[(s->config >> 3) & 3];            /* F */
 
      tmp105_interrupt_update(s);
      return 0;
#3 lore raw

PATCH v2 2/5 hw/sensor/tmp105: Use registerfields API

In reply to Philippe Mathieu-Daudé

To improve readability, use the registerfields API. Define the register bits with FIELD(), and use the FIELD_EX8() and FIELD_DP8() macros. Remove the abbreviations in comments.

---
 hw/sensor/tmp105.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)
hw/sensor/tmp105.c +19 -11
index ad97c9684c..150d09b278 100644
@@ -26,23 +26,31 @@
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "qemu/module.h"
+#include "hw/registerfields.h"
+
+FIELD(CONFIG, SHUTDOWN_MODE,        0, 1)
+FIELD(CONFIG, THERMOSTAT_MODE,      1, 1)
+FIELD(CONFIG, POLARITY,             2, 1)
+FIELD(CONFIG, FAULT_QUEUE,          3, 2)
+FIELD(CONFIG, CONVERTER_RESOLUTION, 5, 2)
+FIELD(CONFIG, ONE_SHOT,             7, 1)
 
 static void tmp105_interrupt_update(TMP105State *s)
 {
-    qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1));   /* POL */
+    qemu_set_irq(s->pin, s->alarm ^ FIELD_EX8(~s->config, CONFIG, POLARITY));
 }
 
 static void tmp105_alarm_update(TMP105State *s)
 {
-    if ((s->config >> 0) & 1) {                                 /* SD */
-        if ((s->config >> 7) & 1) {                             /* OS */
-            s->config &= ~(1 << 7);                             /* OS */
+    if (FIELD_EX8(s->config, CONFIG, SHUTDOWN_MODE)) {
+        if (FIELD_EX8(s->config, CONFIG, ONE_SHOT)) {
+            s->config = FIELD_DP8(s->config, CONFIG, ONE_SHOT, 0);
         } else {
             return;
         }
     }
 
-    if (s->config >> 1 & 1) {
+    if (FIELD_EX8(s->config, CONFIG, THERMOSTAT_MODE)) {
         /*
          * TM == 1 : Interrupt mode. We signal Alert when the
          * temperature rises above T_high, and expect the guest to clear
@@ -120,7 +128,7 @@ static void tmp105_read(TMP105State *s)
 {
     s->len = 0;
 
-    if ((s->config >> 1) & 1) {                                 /* TM */
+    if (FIELD_EX8(s->config, CONFIG, THERMOSTAT_MODE)) {
         s->alarm = 0;
         tmp105_interrupt_update(s);
     }
@@ -129,7 +137,7 @@ static void tmp105_read(TMP105State *s)
     case TMP105_REG_TEMPERATURE:
         s->buf[s->len++] = (((uint16_t) s->temperature) >> 8);
         s->buf[s->len++] = (((uint16_t) s->temperature) >> 0) &
-                (0xf0 << ((~s->config >> 5) & 3));              /* R */
+                (0xf0 << (FIELD_EX8(~s->config, CONFIG, CONVERTER_RESOLUTION)));
         break;
 
     case TMP105_REG_CONFIG:
@@ -155,11 +163,11 @@ static void tmp105_write(TMP105State *s)
         break;
 
     case TMP105_REG_CONFIG:
-        if (s->buf[0] & ~s->config & (1 << 0)) {                /* SD */
+        if (FIELD_EX8(s->buf[0] & ~s->config, CONFIG, SHUTDOWN_MODE)) {
             printf("%s: TMP105 shutdown\n", __func__);
         }
         s->config = s->buf[0];
-        s->faults = tmp105_faultq[(s->config >> 3) & 3];        /* F */
+        s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)];
         tmp105_alarm_update(s);
         break;
 
@@ -219,7 +227,7 @@ static int tmp105_post_load(void *opaque, int version_id)
 {
     TMP105State *s = opaque;
 
-    s->faults = tmp105_faultq[(s->config >> 3) & 3];            /* F */
+    s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)];
 
     tmp105_interrupt_update(s);
     return 0;
@@ -277,7 +285,7 @@ static void tmp105_reset(I2CSlave *i2c)
     s->temperature = 0;
     s->pointer = 0;
     s->config = 0;
-    s->faults = tmp105_faultq[(s->config >> 3) & 3];
+    s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)];
     s->alarm = 0;
     s->detect_falling = false;
 
Signature · 1 line
2.45.2
#5 lore raw

PATCH v2 3/5 hw/sensor/tmp105: Pass 'oneshot' argument to tmp105_alarm_update()

In reply to Philippe Mathieu-Daudé

The next commit will clear the ONE_SHOT bit in the WRITE path (to keep the READ path trivial). As a preliminary step, pass the 'oneshot' value as argument to tmp105_alarm_update(). No logical change intended.

---
 hw/sensor/tmp105.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/sensor/tmp105.c +5 -5
index 150d09b278..6740200aea 100644
@@ -40,10 +40,10 @@ static void tmp105_interrupt_update(TMP105State *s)
     qemu_set_irq(s->pin, s->alarm ^ FIELD_EX8(~s->config, CONFIG, POLARITY));
 }
 
-static void tmp105_alarm_update(TMP105State *s)
+static void tmp105_alarm_update(TMP105State *s, bool one_shot)
 {
     if (FIELD_EX8(s->config, CONFIG, SHUTDOWN_MODE)) {
-        if (FIELD_EX8(s->config, CONFIG, ONE_SHOT)) {
+        if (one_shot) {
             s->config = FIELD_DP8(s->config, CONFIG, ONE_SHOT, 0);
         } else {
             return;
@@ -119,7 +119,7 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,
 
     s->temperature = (int16_t) (temp * 256 / 1000);
 
-    tmp105_alarm_update(s);
+    tmp105_alarm_update(s, false);
 }
 
 static const int tmp105_faultq[4] = { 1, 2, 4, 6 };
@@ -168,7 +168,7 @@ static void tmp105_write(TMP105State *s)
         }
         s->config = s->buf[0];
         s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)];
-        tmp105_alarm_update(s);
+        tmp105_alarm_update(s, FIELD_EX8(s->buf[0], CONFIG, ONE_SHOT));
         break;
 
     case TMP105_REG_T_LOW:
@@ -177,7 +177,7 @@ static void tmp105_write(TMP105State *s)
             s->limit[s->pointer & 1] = (int16_t)
                     ((((uint16_t) s->buf[0]) << 8) | s->buf[1]);
         }
-        tmp105_alarm_update(s);
+        tmp105_alarm_update(s, false);
         break;
     }
 }
Signature · 1 line
2.45.2
Reviewed-by on v2 3/5
#6 lore raw

Re: [PATCH v2 3/5] hw/sensor/tmp105: Pass 'oneshot' argument to tmp105_alarm_update()

Quoted 6 lines · Philippe Mathieu-Daudé

The next commit will clear the ONE_SHOT bit in the WRITE path (to keep the READ path trivial). As a preliminary step, pass the 'oneshot' value as argument to tmp105_alarm_update(). No logical change intended.

#7 lore raw

PATCH v2 4/5 hw/sensor/tmp105: OS (one-shot) bit in config register always returns 0

In reply to Philippe Mathieu-Daudé

Per datasheet, "ONE-SHOT (OS)", the OS bit always returns 0 when reading the configuration register.

Clear the ONE_SHOT bit in the WRITE path. Now than the READ path is simpler, we can also simplify tmp105_alarm_update().

---
 hw/sensor/tmp105.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
hw/sensor/tmp105.c +3 -7
index 6740200aea..f5101af919 100644
@@ -42,12 +42,8 @@ static void tmp105_interrupt_update(TMP105State *s)
 
 static void tmp105_alarm_update(TMP105State *s, bool one_shot)
 {
-    if (FIELD_EX8(s->config, CONFIG, SHUTDOWN_MODE)) {
-        if (one_shot) {
-            s->config = FIELD_DP8(s->config, CONFIG, ONE_SHOT, 0);
-        } else {
-            return;
-        }
+    if (FIELD_EX8(s->config, CONFIG, SHUTDOWN_MODE) && !one_shot) {
+        return;
     }
 
     if (FIELD_EX8(s->config, CONFIG, THERMOSTAT_MODE)) {
@@ -166,7 +162,7 @@ static void tmp105_write(TMP105State *s)
         if (FIELD_EX8(s->buf[0] & ~s->config, CONFIG, SHUTDOWN_MODE)) {
             printf("%s: TMP105 shutdown\n", __func__);
         }
-        s->config = s->buf[0];
+        s->config = FIELD_DP8(s->buf[0], CONFIG, ONE_SHOT, 0);
         s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)];
         tmp105_alarm_update(s, FIELD_EX8(s->buf[0], CONFIG, ONE_SHOT));
         break;
Signature · 1 line
2.45.2
Reviewed-by on v2 4/5
#8 lore raw

Re: [PATCH v2 4/5] hw/sensor/tmp105: OS (one-shot) bit in config register always returns 0

Quoted 8 lines · Philippe Mathieu-Daudé

Per datasheet, "ONE-SHOT (OS)", the OS bit always returns 0 when reading the configuration register.

Clear the ONE_SHOT bit in the WRITE path. Now than the READ path is simpler, we can also simplify tmp105_alarm_update().

Thanks,

C.

Quoted 32 lines
---
  hw/sensor/tmp105.c | 10 +++-------
  1 file changed, 3 insertions(+), 7 deletions(-)
hw/sensor/tmp105.c +3 -7
index 6740200aea..f5101af919 100644
@@ -42,12 +42,8 @@ static void tmp105_interrupt_update(TMP105State *s)
 
  static void tmp105_alarm_update(TMP105State *s, bool one_shot)
  {
-    if (FIELD_EX8(s->config, CONFIG, SHUTDOWN_MODE)) {
-        if (one_shot) {
-            s->config = FIELD_DP8(s->config, CONFIG, ONE_SHOT, 0);
-        } else {
-            return;
-        }
+    if (FIELD_EX8(s->config, CONFIG, SHUTDOWN_MODE) && !one_shot) {
+        return;
      }
 
      if (FIELD_EX8(s->config, CONFIG, THERMOSTAT_MODE)) {
@@ -166,7 +162,7 @@ static void tmp105_write(TMP105State *s)
          if (FIELD_EX8(s->buf[0] & ~s->config, CONFIG, SHUTDOWN_MODE)) {
              printf("%s: TMP105 shutdown\n", __func__);
          }
-        s->config = s->buf[0];
+        s->config = FIELD_DP8(s->buf[0], CONFIG, ONE_SHOT, 0);
          s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)];
          tmp105_alarm_update(s, FIELD_EX8(s->buf[0], CONFIG, ONE_SHOT));
          break;
#9 lore raw

PATCH v2 5/5 hw/sensor/tmp105: Lower 4 bit of limit registers are always 0

In reply to Philippe Mathieu-Daudé

From: Guenter Roeck <[email protected]>

Per datasheet, "HIGH AND LOW LIMIT REGISTERS", the lower 4 bit of the limit registers are unused and always report 0. The lower 4 bit should not be used for temperature comparisons, so mask the unused bits before storing the limits.

---
 hw/sensor/tmp105.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sensor/tmp105.c +1 -1
index f5101af919..9d7b911f59 100644
@@ -171,7 +171,7 @@ static void tmp105_write(TMP105State *s)
     case TMP105_REG_T_HIGH:
         if (s->len >= 3) {
             s->limit[s->pointer & 1] = (int16_t)
-                    ((((uint16_t) s->buf[0]) << 8) | s->buf[1]);
+                    ((((uint16_t) s->buf[0]) << 8) | (s->buf[1] & 0xf0));
         }
         tmp105_alarm_update(s, false);
         break;
Signature · 1 line
2.45.2
author Reviewed-by Reviewed-by Cédric Le Goater on v2 5/5
#10 lore raw

Re: [PATCH v2 5/5] hw/sensor/tmp105: Lower 4 bit of limit registers are always 0

Quoted 8 lines · Philippe Mathieu-Daudé

From: Guenter Roeck <[email protected]>

Per datasheet, "HIGH AND LOW LIMIT REGISTERS", the lower 4 bit of the limit registers are unused and always report 0. The lower 4 bit should not be used for temperature comparisons, so mask the unused bits before storing the limits.

Quoted 18 lines
---
  hw/sensor/tmp105.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/sensor/tmp105.c +1 -1
index f5101af919..9d7b911f59 100644
@@ -171,7 +171,7 @@ static void tmp105_write(TMP105State *s)
      case TMP105_REG_T_HIGH:
          if (s->len >= 3) {
              s->limit[s->pointer & 1] = (int16_t)
-                    ((((uint16_t) s->buf[0]) << 8) | s->buf[1]);
+                    ((((uint16_t) s->buf[0]) << 8) | (s->buf[1] & 0xf0));
          }
          tmp105_alarm_update(s, false);
          break;
#11 lore raw
In reply to Philippe Mathieu-Daudé

Hi Cédric,

Quoted 3 lines · Philippe Mathieu-Daudé

Respin of Guenter fixes with:
- Use registerfields API
- Clear OS bit in WRITE path

Since our mails crossed (you reviewed v1 while I was posting v2), do you mind having another look at this v2? At least patch #4 isn't yet reviewed.

Thanks,

Phil.

Quoted 15 lines

Supersedes: <[email protected]>

Guenter Roeck (2):
hw/sensor/tmp105: Coding style fixes hw/sensor/tmp105: Lower 4 bit of limit registers are always 0

Philippe Mathieu-Daudé (3):
hw/sensor/tmp105: Use registerfields API hw/sensor/tmp105: Pass 'oneshot' argument to tmp105_alarm_update() hw/sensor/tmp105: OS (one-shot) bit in config register always returns

     0
  hw/sensor/tmp105.c | 66 ++++++++++++++++++++++++++--------------------
  1 file changed, 37 insertions(+), 29 deletions(-)
#12 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Respin of Guenter fixes with:
- Use registerfields API
- Clear OS bit in WRITE path

Supersedes: <[email protected]>

Guenter Roeck (2):
hw/sensor/tmp105: Coding style fixes hw/sensor/tmp105: Lower 4 bit of limit registers are always 0

Quoted 5 lines

Philippe Mathieu-Daudé (3):
hw/sensor/tmp105: Use registerfields API hw/sensor/tmp105: Pass 'oneshot' argument to tmp105_alarm_update() hw/sensor/tmp105: OS (one-shot) bit in config register always returns

     0

Series queued, thanks!