From: Andreas Färber <andreas.faer...@web.de>

The libqos driver for omap_i2c currently does not work on Big Endian.
Introduce helpers for reading from and writing to 16-bit armel registers.

This fixes tmp105-test failures on ppc.

Signed-off-by: Andreas Färber <andreas.faer...@web.de>
---
 tests/libi2c-omap.c |   51 ++++++++++++++++++++++++++++++++-------------------
 1 Datei geändert, 32 Zeilen hinzugefügt(+), 19 Zeilen entfernt(-)

diff --git a/tests/libi2c-omap.c b/tests/libi2c-omap.c
index 9be57e9..7d50ef2 100644
--- a/tests/libi2c-omap.c
+++ b/tests/libi2c-omap.c
@@ -12,6 +12,7 @@
 #include <string.h>
 
 #include "qemu/osdep.h"
+#include "qemu/bswap.h"
 #include "libqtest.h"
 
 enum OMAPI2CRegisters {
@@ -48,12 +49,24 @@ typedef struct OMAPI2C {
 } OMAPI2C;
 
 
+static inline void omap_i2c_read16(uint64_t addr, uint16_t *data)
+{
+    memread(addr, data, 2);
+    *data = le16_to_cpu(*data);
+}
+
+static inline void omap_i2c_write16(uint64_t addr, uint16_t data)
+{
+    data = cpu_to_le16(data);
+    memwrite(addr, &data, 2);
+}
+
 static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr)
 {
     uint16_t data = addr;
 
-    memwrite(s->addr + OMAP_I2C_SA, &data, 2);
-    memread(s->addr + OMAP_I2C_SA, &data, 2);
+    omap_i2c_write16(s->addr + OMAP_I2C_SA, data);
+    omap_i2c_read16(s->addr + OMAP_I2C_SA, &data);
     g_assert_cmphex(data, ==, addr);
 }
 
@@ -66,22 +79,22 @@ static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr,
     omap_i2c_set_slave_addr(s, addr);
 
     data = len;
-    memwrite(s->addr + OMAP_I2C_CNT, &data, 2);
+    omap_i2c_write16(s->addr + OMAP_I2C_CNT, data);
 
     data = OMAP_I2C_CON_I2C_EN |
            OMAP_I2C_CON_TRX |
            OMAP_I2C_CON_MST |
            OMAP_I2C_CON_STT |
            OMAP_I2C_CON_STP;
-    memwrite(s->addr + OMAP_I2C_CON, &data, 2);
-    memread(s->addr + OMAP_I2C_CON, &data, 2);
+    omap_i2c_write16(s->addr + OMAP_I2C_CON, data);
+    omap_i2c_read16(s->addr + OMAP_I2C_CON, &data);
     g_assert((data & OMAP_I2C_CON_STP) != 0);
 
-    memread(s->addr + OMAP_I2C_STAT, &data, 2);
+    omap_i2c_read16(s->addr + OMAP_I2C_STAT, &data);
     g_assert((data & OMAP_I2C_STAT_NACK) == 0);
 
     while (len > 1) {
-        memread(s->addr + OMAP_I2C_STAT, &data, 2);
+        omap_i2c_read16(s->addr + OMAP_I2C_STAT, &data);
         g_assert((data & OMAP_I2C_STAT_XRDY) != 0);
 
         memwrite(s->addr + OMAP_I2C_DATA, buf, 2);
@@ -89,13 +102,13 @@ static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr,
         len -= 2;
     }
     if (len == 1) {
-        memread(s->addr + OMAP_I2C_STAT, &data, 2);
+        omap_i2c_read16(s->addr + OMAP_I2C_STAT, &data);
         g_assert((data & OMAP_I2C_STAT_XRDY) != 0);
 
         memwrite(s->addr + OMAP_I2C_DATA, buf, 1);
     }
 
-    memread(s->addr + OMAP_I2C_CON, &data, 2);
+    omap_i2c_read16(s->addr + OMAP_I2C_CON, &data);
     g_assert((data & OMAP_I2C_CON_STP) == 0);
 }
 
@@ -108,32 +121,32 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr,
     omap_i2c_set_slave_addr(s, addr);
 
     data = len;
-    memwrite(s->addr + OMAP_I2C_CNT, &data, 2);
+    omap_i2c_write16(s->addr + OMAP_I2C_CNT, data);
 
     data = OMAP_I2C_CON_I2C_EN |
            OMAP_I2C_CON_MST |
            OMAP_I2C_CON_STT |
            OMAP_I2C_CON_STP;
-    memwrite(s->addr + OMAP_I2C_CON, &data, 2);
-    memread(s->addr + OMAP_I2C_CON, &data, 2);
+    omap_i2c_write16(s->addr + OMAP_I2C_CON, data);
+    omap_i2c_read16(s->addr + OMAP_I2C_CON, &data);
     g_assert((data & OMAP_I2C_CON_STP) == 0);
 
-    memread(s->addr + OMAP_I2C_STAT, &data, 2);
+    omap_i2c_read16(s->addr + OMAP_I2C_STAT, &data);
     g_assert((data & OMAP_I2C_STAT_NACK) == 0);
 
-    memread(s->addr + OMAP_I2C_CNT, &data, 2);
+    omap_i2c_read16(s->addr + OMAP_I2C_CNT, &data);
     g_assert_cmpuint(data, ==, len);
 
     while (len > 0) {
-        memread(s->addr + OMAP_I2C_STAT, &data, 2);
+        omap_i2c_read16(s->addr + OMAP_I2C_STAT, &data);
         g_assert((data & OMAP_I2C_STAT_RRDY) != 0);
         g_assert((data & OMAP_I2C_STAT_ROVR) == 0);
 
         memread(s->addr + OMAP_I2C_DATA, &data, 2);
 
-        memread(s->addr + OMAP_I2C_STAT, &stat, 2);
+        omap_i2c_read16(s->addr + OMAP_I2C_STAT, &stat);
         if (unlikely(len == 1)) {
-            *buf = data & 0xf;
+            *buf = le16_to_cpu(data) & 0xf;
             buf++;
             len--;
         } else {
@@ -143,7 +156,7 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr,
         }
     }
 
-    memread(s->addr + OMAP_I2C_CON, &data, 2);
+    omap_i2c_read16(s->addr + OMAP_I2C_CON, &data);
     g_assert((data & OMAP_I2C_CON_STP) == 0);
 }
 
@@ -159,7 +172,7 @@ I2CAdapter *omap_i2c_create(uint64_t addr)
     i2c->recv = omap_i2c_recv;
 
     /* verify the mmio address by looking for a known signature */
-    memread(addr + OMAP_I2C_REV, &data, 2);
+    omap_i2c_read16(addr + OMAP_I2C_REV, &data);
     g_assert_cmphex(data, ==, 0x34);
 
     return i2c;
-- 
1.7.10.4


Reply via email to