From: Andreas Färber Date: Thu, 2 May 2013 13:56:26 +0000 (+0200) Subject: libqos: Relocate I2C files X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=cc9936a32f91c107a2a7655af4feeee3f4de5d12;p=qemu.git libqos: Relocate I2C files Commit c4efe1cada311b9dc0df5beb71c4227ff3414aa1 (qtest: add libqos including PCI support) created a libqos/ subdirectory but left the existing I2C libqos files libi2c*.[hc] in tests/. Clean this up. Signed-off-by: Andreas Färber Signed-off-by: Andreas Färber Message-id: 1367502986-15104-1-git-send-email-afaerber@suse.de Signed-off-by: Anthony Liguori --- diff --git a/tests/Makefile b/tests/Makefile index 72bf2cd220..bf41d10050 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -119,14 +119,16 @@ tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $( tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o +libqos-obj-y += tests/libqos/i2c.o libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o tests/libqos/fw_cfg-pc.o libqos-pc-obj-y += tests/libqos/malloc-pc.o +libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/fdc-test$(EXESUF): tests/fdc-test.o tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o -tests/tmp105-test$(EXESUF): tests/tmp105-test.o +tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y) @@ -137,7 +139,6 @@ QTEST_TARGETS=$(foreach TARGET,$(TARGETS), $(if $(check-qtest-$(TARGET)-y), $(TA check-qtest-$(CONFIG_POSIX)=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y)) qtest-obj-y = tests/libqtest.o libqemuutil.a libqemustub.a -qtest-obj-y += tests/libi2c.o tests/libi2c-omap.o $(check-qtest-y): $(qtest-obj-y) .PHONY: check-help diff --git a/tests/libi2c-omap.c b/tests/libi2c-omap.c deleted file mode 100644 index c52458cbd6..0000000000 --- a/tests/libi2c-omap.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * QTest I2C driver - * - * Copyright (c) 2012 Andreas Färber - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ -#include "libi2c.h" - -#include -#include - -#include "qemu/osdep.h" -#include "qemu/bswap.h" -#include "libqtest.h" - -enum OMAPI2CRegisters { - OMAP_I2C_REV = 0x00, - OMAP_I2C_STAT = 0x08, - OMAP_I2C_CNT = 0x18, - OMAP_I2C_DATA = 0x1c, - OMAP_I2C_CON = 0x24, - OMAP_I2C_SA = 0x2c, -}; - -enum OMAPI2CSTATBits { - OMAP_I2C_STAT_NACK = 1 << 1, - OMAP_I2C_STAT_ARDY = 1 << 2, - OMAP_I2C_STAT_RRDY = 1 << 3, - OMAP_I2C_STAT_XRDY = 1 << 4, - OMAP_I2C_STAT_ROVR = 1 << 11, - OMAP_I2C_STAT_SBD = 1 << 15, -}; - -enum OMAPI2CCONBits { - OMAP_I2C_CON_STT = 1 << 0, - OMAP_I2C_CON_STP = 1 << 1, - OMAP_I2C_CON_TRX = 1 << 9, - OMAP_I2C_CON_MST = 1 << 10, - OMAP_I2C_CON_BE = 1 << 14, - OMAP_I2C_CON_I2C_EN = 1 << 15, -}; - -typedef struct OMAPI2C { - I2CAdapter parent; - - uint64_t addr; -} OMAPI2C; - - -static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr) -{ - uint16_t data = addr; - - writew(s->addr + OMAP_I2C_SA, data); - data = readw(s->addr + OMAP_I2C_SA); - g_assert_cmphex(data, ==, addr); -} - -static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr, - const uint8_t *buf, uint16_t len) -{ - OMAPI2C *s = (OMAPI2C *)i2c; - uint16_t data; - - omap_i2c_set_slave_addr(s, addr); - - data = len; - writew(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; - writew(s->addr + OMAP_I2C_CON, data); - data = readw(s->addr + OMAP_I2C_CON); - g_assert((data & OMAP_I2C_CON_STP) != 0); - - data = readw(s->addr + OMAP_I2C_STAT); - g_assert((data & OMAP_I2C_STAT_NACK) == 0); - - while (len > 1) { - data = readw(s->addr + OMAP_I2C_STAT); - g_assert((data & OMAP_I2C_STAT_XRDY) != 0); - - data = buf[0] | ((uint16_t)buf[1] << 8); - writew(s->addr + OMAP_I2C_DATA, data); - buf = (uint8_t *)buf + 2; - len -= 2; - } - if (len == 1) { - data = readw(s->addr + OMAP_I2C_STAT); - g_assert((data & OMAP_I2C_STAT_XRDY) != 0); - - data = buf[0]; - writew(s->addr + OMAP_I2C_DATA, data); - } - - data = readw(s->addr + OMAP_I2C_CON); - g_assert((data & OMAP_I2C_CON_STP) == 0); -} - -static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr, - uint8_t *buf, uint16_t len) -{ - OMAPI2C *s = (OMAPI2C *)i2c; - uint16_t data, stat; - - omap_i2c_set_slave_addr(s, addr); - - data = len; - writew(s->addr + OMAP_I2C_CNT, data); - - data = OMAP_I2C_CON_I2C_EN | - OMAP_I2C_CON_MST | - OMAP_I2C_CON_STT | - OMAP_I2C_CON_STP; - writew(s->addr + OMAP_I2C_CON, data); - data = readw(s->addr + OMAP_I2C_CON); - g_assert((data & OMAP_I2C_CON_STP) == 0); - - data = readw(s->addr + OMAP_I2C_STAT); - g_assert((data & OMAP_I2C_STAT_NACK) == 0); - - data = readw(s->addr + OMAP_I2C_CNT); - g_assert_cmpuint(data, ==, len); - - while (len > 0) { - data = readw(s->addr + OMAP_I2C_STAT); - g_assert((data & OMAP_I2C_STAT_RRDY) != 0); - g_assert((data & OMAP_I2C_STAT_ROVR) == 0); - - data = readw(s->addr + OMAP_I2C_DATA); - - stat = readw(s->addr + OMAP_I2C_STAT); - - if (unlikely(len == 1)) { - g_assert((stat & OMAP_I2C_STAT_SBD) != 0); - - buf[0] = data & 0xff; - buf++; - len--; - } else { - buf[0] = data & 0xff; - buf[1] = data >> 8; - buf += 2; - len -= 2; - } - } - - data = readw(s->addr + OMAP_I2C_CON); - g_assert((data & OMAP_I2C_CON_STP) == 0); -} - -I2CAdapter *omap_i2c_create(uint64_t addr) -{ - OMAPI2C *s = g_malloc0(sizeof(*s)); - I2CAdapter *i2c = (I2CAdapter *)s; - uint16_t data; - - s->addr = addr; - - i2c->send = omap_i2c_send; - i2c->recv = omap_i2c_recv; - - /* verify the mmio address by looking for a known signature */ - data = readw(addr + OMAP_I2C_REV); - g_assert_cmphex(data, ==, 0x34); - - return i2c; -} diff --git a/tests/libi2c.c b/tests/libi2c.c deleted file mode 100644 index 13ec85c0cb..0000000000 --- a/tests/libi2c.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * QTest I2C driver - * - * Copyright (c) 2012 Andreas Färber - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ -#include "libi2c.h" -#include "libqtest.h" - -void i2c_send(I2CAdapter *i2c, uint8_t addr, - const uint8_t *buf, uint16_t len) -{ - i2c->send(i2c, addr, buf, len); -} - -void i2c_recv(I2CAdapter *i2c, uint8_t addr, - uint8_t *buf, uint16_t len) -{ - i2c->recv(i2c, addr, buf, len); -} diff --git a/tests/libi2c.h b/tests/libi2c.h deleted file mode 100644 index 1ce9af4053..0000000000 --- a/tests/libi2c.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * I2C libqos - * - * Copyright (c) 2012 Andreas Färber - * - * This work is licensed under the terms of the GNU GPL, version 2 or later. - * See the COPYING file in the top-level directory. - */ -#ifndef LIBQOS_I2C_H -#define LIBQOS_I2C_H - -#include - -typedef struct I2CAdapter I2CAdapter; -struct I2CAdapter { - void (*send)(I2CAdapter *adapter, uint8_t addr, - const uint8_t *buf, uint16_t len); - void (*recv)(I2CAdapter *adapter, uint8_t addr, - uint8_t *buf, uint16_t len); -}; - -void i2c_send(I2CAdapter *i2c, uint8_t addr, - const uint8_t *buf, uint16_t len); -void i2c_recv(I2CAdapter *i2c, uint8_t addr, - uint8_t *buf, uint16_t len); - -/* libi2c-omap.c */ -I2CAdapter *omap_i2c_create(uint64_t addr); - -#endif diff --git a/tests/libqos/i2c-omap.c b/tests/libqos/i2c-omap.c new file mode 100644 index 0000000000..3d4d45d848 --- /dev/null +++ b/tests/libqos/i2c-omap.c @@ -0,0 +1,173 @@ +/* + * QTest I2C driver + * + * Copyright (c) 2012 Andreas Färber + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include "libqos/i2c.h" + +#include +#include + +#include "qemu/osdep.h" +#include "qemu/bswap.h" +#include "libqtest.h" + +enum OMAPI2CRegisters { + OMAP_I2C_REV = 0x00, + OMAP_I2C_STAT = 0x08, + OMAP_I2C_CNT = 0x18, + OMAP_I2C_DATA = 0x1c, + OMAP_I2C_CON = 0x24, + OMAP_I2C_SA = 0x2c, +}; + +enum OMAPI2CSTATBits { + OMAP_I2C_STAT_NACK = 1 << 1, + OMAP_I2C_STAT_ARDY = 1 << 2, + OMAP_I2C_STAT_RRDY = 1 << 3, + OMAP_I2C_STAT_XRDY = 1 << 4, + OMAP_I2C_STAT_ROVR = 1 << 11, + OMAP_I2C_STAT_SBD = 1 << 15, +}; + +enum OMAPI2CCONBits { + OMAP_I2C_CON_STT = 1 << 0, + OMAP_I2C_CON_STP = 1 << 1, + OMAP_I2C_CON_TRX = 1 << 9, + OMAP_I2C_CON_MST = 1 << 10, + OMAP_I2C_CON_BE = 1 << 14, + OMAP_I2C_CON_I2C_EN = 1 << 15, +}; + +typedef struct OMAPI2C { + I2CAdapter parent; + + uint64_t addr; +} OMAPI2C; + + +static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr) +{ + uint16_t data = addr; + + writew(s->addr + OMAP_I2C_SA, data); + data = readw(s->addr + OMAP_I2C_SA); + g_assert_cmphex(data, ==, addr); +} + +static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr, + const uint8_t *buf, uint16_t len) +{ + OMAPI2C *s = (OMAPI2C *)i2c; + uint16_t data; + + omap_i2c_set_slave_addr(s, addr); + + data = len; + writew(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; + writew(s->addr + OMAP_I2C_CON, data); + data = readw(s->addr + OMAP_I2C_CON); + g_assert((data & OMAP_I2C_CON_STP) != 0); + + data = readw(s->addr + OMAP_I2C_STAT); + g_assert((data & OMAP_I2C_STAT_NACK) == 0); + + while (len > 1) { + data = readw(s->addr + OMAP_I2C_STAT); + g_assert((data & OMAP_I2C_STAT_XRDY) != 0); + + data = buf[0] | ((uint16_t)buf[1] << 8); + writew(s->addr + OMAP_I2C_DATA, data); + buf = (uint8_t *)buf + 2; + len -= 2; + } + if (len == 1) { + data = readw(s->addr + OMAP_I2C_STAT); + g_assert((data & OMAP_I2C_STAT_XRDY) != 0); + + data = buf[0]; + writew(s->addr + OMAP_I2C_DATA, data); + } + + data = readw(s->addr + OMAP_I2C_CON); + g_assert((data & OMAP_I2C_CON_STP) == 0); +} + +static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr, + uint8_t *buf, uint16_t len) +{ + OMAPI2C *s = (OMAPI2C *)i2c; + uint16_t data, stat; + + omap_i2c_set_slave_addr(s, addr); + + data = len; + writew(s->addr + OMAP_I2C_CNT, data); + + data = OMAP_I2C_CON_I2C_EN | + OMAP_I2C_CON_MST | + OMAP_I2C_CON_STT | + OMAP_I2C_CON_STP; + writew(s->addr + OMAP_I2C_CON, data); + data = readw(s->addr + OMAP_I2C_CON); + g_assert((data & OMAP_I2C_CON_STP) == 0); + + data = readw(s->addr + OMAP_I2C_STAT); + g_assert((data & OMAP_I2C_STAT_NACK) == 0); + + data = readw(s->addr + OMAP_I2C_CNT); + g_assert_cmpuint(data, ==, len); + + while (len > 0) { + data = readw(s->addr + OMAP_I2C_STAT); + g_assert((data & OMAP_I2C_STAT_RRDY) != 0); + g_assert((data & OMAP_I2C_STAT_ROVR) == 0); + + data = readw(s->addr + OMAP_I2C_DATA); + + stat = readw(s->addr + OMAP_I2C_STAT); + + if (unlikely(len == 1)) { + g_assert((stat & OMAP_I2C_STAT_SBD) != 0); + + buf[0] = data & 0xff; + buf++; + len--; + } else { + buf[0] = data & 0xff; + buf[1] = data >> 8; + buf += 2; + len -= 2; + } + } + + data = readw(s->addr + OMAP_I2C_CON); + g_assert((data & OMAP_I2C_CON_STP) == 0); +} + +I2CAdapter *omap_i2c_create(uint64_t addr) +{ + OMAPI2C *s = g_malloc0(sizeof(*s)); + I2CAdapter *i2c = (I2CAdapter *)s; + uint16_t data; + + s->addr = addr; + + i2c->send = omap_i2c_send; + i2c->recv = omap_i2c_recv; + + /* verify the mmio address by looking for a known signature */ + data = readw(addr + OMAP_I2C_REV); + g_assert_cmphex(data, ==, 0x34); + + return i2c; +} diff --git a/tests/libqos/i2c.c b/tests/libqos/i2c.c new file mode 100644 index 0000000000..da7592f713 --- /dev/null +++ b/tests/libqos/i2c.c @@ -0,0 +1,22 @@ +/* + * QTest I2C driver + * + * Copyright (c) 2012 Andreas Färber + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include "libqos/i2c.h" +#include "libqtest.h" + +void i2c_send(I2CAdapter *i2c, uint8_t addr, + const uint8_t *buf, uint16_t len) +{ + i2c->send(i2c, addr, buf, len); +} + +void i2c_recv(I2CAdapter *i2c, uint8_t addr, + uint8_t *buf, uint16_t len) +{ + i2c->recv(i2c, addr, buf, len); +} diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h new file mode 100644 index 0000000000..1ce9af4053 --- /dev/null +++ b/tests/libqos/i2c.h @@ -0,0 +1,30 @@ +/* + * I2C libqos + * + * Copyright (c) 2012 Andreas Färber + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef LIBQOS_I2C_H +#define LIBQOS_I2C_H + +#include + +typedef struct I2CAdapter I2CAdapter; +struct I2CAdapter { + void (*send)(I2CAdapter *adapter, uint8_t addr, + const uint8_t *buf, uint16_t len); + void (*recv)(I2CAdapter *adapter, uint8_t addr, + uint8_t *buf, uint16_t len); +}; + +void i2c_send(I2CAdapter *i2c, uint8_t addr, + const uint8_t *buf, uint16_t len); +void i2c_recv(I2CAdapter *i2c, uint8_t addr, + uint8_t *buf, uint16_t len); + +/* libi2c-omap.c */ +I2CAdapter *omap_i2c_create(uint64_t addr); + +#endif diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c index 2869129df3..fecd6dcd70 100644 --- a/tests/tmp105-test.c +++ b/tests/tmp105-test.c @@ -7,7 +7,7 @@ * See the COPYING file in the top-level directory. */ #include "libqtest.h" -#include "libi2c.h" +#include "libqos/i2c.h" #include "hw/misc/tmp105_regs.h" #include