Patchwork [v2,5/6] hw/ds1338.c: Implement support for the control register.

login
register
mail settings
Submitter Antoine Mathys
Date Dec. 11, 2012, 10:58 p.m.
Message ID <50C7BAA5.2020603@gmail.com>
Download mbox | patch
Permalink /patch/205335/
State New
Headers show

Comments

Antoine Mathys - Dec. 11, 2012, 10:58 p.m.
The previous patch has the side effect of clearing the control register. 
That's already its proper power-on-reset value.

Signed-off-by: Antoine Mathys <barsamin@gmail.com>
---
  hw/ds1338.c |   17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
Peter Maydell - Dec. 12, 2012, 12:18 p.m.
On 11 December 2012 22:58, Antoine Mathys <barsamin@gmail.com> wrote:
> The previous patch has the side effect of clearing the control register.
> That's already its proper power-on-reset value.

This is true but it reads a bit oddly as a standalone
git commit message...

> Signed-off-by: Antoine Mathys <barsamin@gmail.com>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM

Patch

diff --git a/hw/ds1338.c b/hw/ds1338.c
index 5a6234b..319c341 100644
--- a/hw/ds1338.c
+++ b/hw/ds1338.c
@@ -125,7 +125,8 @@  static int ds1338_send(I2CSlave *i2c, uint8_t data)
          s->addr_byte = false;
          return 0;
      }
-    if (s->ptr < 8) {
+    if (s->ptr < 7) {
+        /* Time register. */
          struct tm now;
          qemu_get_timedate(&now, s->offset);
          switch(s->ptr) {
@@ -162,11 +163,19 @@  static int ds1338_send(I2CSlave *i2c, uint8_t data)
          case 6:
              now.tm_year = from_bcd(data) + 100;
              break;
-        case 7:
-            /* Control register. Currently ignored.  */
-            break;
          }
          s->offset = qemu_timedate_diff(&now);
+    } else if (s->ptr == 7) {
+        /* Control register. */
+
+        /* Ensure bits 2, 3 and 6 will read back as zero. */
+        data &= 0xB3;
+
+        /* Attempting to write the OSF flag to logic 1 leaves the
+           value unchanged. */
+        data = (data & ~CTRL_OSF) | (data & s->nvram[s->ptr] & CTRL_OSF);
+
+        s->nvram[s->ptr] = data;
      } else {
          s->nvram[s->ptr] = data;
      }