summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--audio/audio.c5
-rw-r--r--hw/pc_q35.c1
-rw-r--r--hw/ppc405_boards.c1
-rw-r--r--hw/spapr.c7
-rw-r--r--hw/spapr_vio.c29
-rw-r--r--hw/tmp105.c77
-rw-r--r--hw/tmp105.h64
-rw-r--r--hw/tmp105_regs.h50
-rw-r--r--hw/usb/dev-storage.c2
-rw-r--r--tests/Makefile4
-rw-r--r--tests/libi2c-omap.c166
-rw-r--r--tests/libi2c.c22
-rw-r--r--tests/libi2c.h30
-rw-r--r--tests/tmp105-test.c76
-rw-r--r--ui/keymaps.c16
16 files changed, 440 insertions, 111 deletions
diff --git a/Makefile b/Makefile
index 7622a4cfa4..cfa2fa6383 100644
--- a/Makefile
+++ b/Makefile
@@ -153,6 +153,7 @@ version.o: $(SRC_PATH)/version.rc config-host.h
$(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
version-obj-$(CONFIG_WIN32) += version.o
+Makefile: $(version-obj-y)
######################################################################
# Build libraries
diff --git a/audio/audio.c b/audio/audio.c
index 1510b598a6..02bb8861f8 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -828,8 +828,9 @@ static int audio_attach_capture (HWVoiceOut *hw)
QLIST_INSERT_HEAD (&hw_cap->sw_head, sw, entries);
QLIST_INSERT_HEAD (&hw->cap_head, sc, entries);
#ifdef DEBUG_CAPTURE
- asprintf (&sw->name, "for %p %d,%d,%d",
- hw, sw->info.freq, sw->info.bits, sw->info.nchannels);
+ sw->name = g_strdup_printf ("for %p %d,%d,%d",
+ hw, sw->info.freq, sw->info.bits,
+ sw->info.nchannels);
dolog ("Added %s active = %d\n", sw->name, sw->active);
#endif
if (sw->active) {
diff --git a/hw/pc_q35.c b/hw/pc_q35.c
index 52d997613f..d82353e84f 100644
--- a/hw/pc_q35.c
+++ b/hw/pc_q35.c
@@ -214,6 +214,7 @@ static QEMUMachine pc_q35_machine = {
.desc = "Standard PC (Q35 + ICH9, 2009)",
.init = pc_q35_init,
.max_cpus = 255,
+ DEFAULT_MACHINE_OPTIONS,
};
static void pc_q35_machine_init(void)
diff --git a/hw/ppc405_boards.c b/hw/ppc405_boards.c
index 45ed3769a3..cf371db053 100644
--- a/hw/ppc405_boards.c
+++ b/hw/ppc405_boards.c
@@ -362,6 +362,7 @@ static QEMUMachine ref405ep_machine = {
.name = "ref405ep",
.desc = "ref405ep",
.init = ref405ep_init,
+ DEFAULT_MACHINE_OPTIONS,
};
/*****************************************************************************/
diff --git a/hw/spapr.c b/hw/spapr.c
index 21c261be4a..d80b792b37 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -328,14 +328,11 @@ static void *spapr_create_fdt_skel(const char *cpu_model,
continue;
}
- if (asprintf(&nodename, "%s@%x", modelname, index) < 0) {
- fprintf(stderr, "Allocation failure\n");
- exit(1);
- }
+ nodename = g_strdup_printf("%s@%x", modelname, index);
_FDT((fdt_begin_node(fdt, nodename)));
- free(nodename);
+ g_free(nodename);
_FDT((fdt_property_cell(fdt, "reg", index)));
_FDT((fdt_property_string(fdt, "device_type", "cpu")));
diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c
index 3a1a4864e6..2054219c95 100644
--- a/hw/spapr_vio.c
+++ b/hw/spapr_vio.c
@@ -80,9 +80,7 @@ static char *vio_format_dev_name(VIOsPAPRDevice *dev)
char *name;
/* Device tree style name device@reg */
- if (asprintf(&name, "%s@%x", pc->dt_name, dev->reg) < 0) {
- return NULL;
- }
+ name = g_strdup_printf("%s@%x", pc->dt_name, dev->reg);
return name;
}
@@ -101,12 +99,8 @@ static int vio_make_devnode(VIOsPAPRDevice *dev,
}
dt_name = vio_format_dev_name(dev);
- if (!dt_name) {
- return -ENOMEM;
- }
-
node_off = fdt_add_subnode(fdt, vdevice_off, dt_name);
- free(dt_name);
+ g_free(dt_name);
if (node_off < 0) {
return node_off;
}
@@ -444,9 +438,6 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
/* Don't overwrite ids assigned on the command line */
if (!dev->qdev.id) {
id = vio_format_dev_name(dev);
- if (!id) {
- return -1;
- }
dev->qdev.id = id;
}
@@ -646,20 +637,12 @@ int spapr_populate_chosen_stdout(void *fdt, VIOsPAPRBus *bus)
}
name = vio_format_dev_name(dev);
- if (!name) {
- return -ENOMEM;
- }
-
- if (asprintf(&path, "/vdevice/%s", name) < 0) {
- path = NULL;
- ret = -ENOMEM;
- goto out;
- }
+ path = g_strdup_printf("/vdevice/%s", name);
ret = fdt_setprop_string(fdt, offset, "linux,stdout-path", path);
-out:
- free(name);
- free(path);
+
+ g_free(name);
+ g_free(path);
return ret;
}
diff --git a/hw/tmp105.c b/hw/tmp105.c
index 0ade4eb6bd..3ad2d2f04c 100644
--- a/hw/tmp105.c
+++ b/hw/tmp105.c
@@ -21,20 +21,7 @@
#include "hw.h"
#include "i2c.h"
#include "tmp105.h"
-
-typedef struct {
- I2CSlave i2c;
- uint8_t len;
- uint8_t buf[2];
- qemu_irq pin;
-
- uint8_t pointer;
- uint8_t config;
- int16_t temperature;
- int16_t limit[2];
- int faults;
- uint8_t alarm;
-} TMP105State;
+#include "qapi/visitor.h"
static void tmp105_interrupt_update(TMP105State *s)
{
@@ -65,15 +52,30 @@ static void tmp105_alarm_update(TMP105State *s)
tmp105_interrupt_update(s);
}
+static void tmp105_get_temperature(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ TMP105State *s = TMP105(obj);
+ int64_t value = s->temperature;
+
+ visit_type_int(v, &value, name, errp);
+}
+
/* Units are 0.001 centigrades relative to 0 C. */
-void tmp105_set(I2CSlave *i2c, int temp)
+static void tmp105_set_temperature(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(obj);
+ int64_t temp;
+ visit_type_int(v, &temp, name, errp);
+ if (error_is_set(errp)) {
+ return;
+ }
if (temp >= 128000 || temp < -128000) {
- fprintf(stderr, "%s: values is out of range (%i.%03i C)\n",
- __FUNCTION__, temp / 1000, temp % 1000);
- exit(-1);
+ error_setg(errp, "value %" PRId64 ".%03" PRIu64 " °C is out of range",
+ temp / 1000, temp % 1000);
+ return;
}
s->temperature = ((int16_t) (temp * 0x800 / 128000)) << 4;
@@ -141,23 +143,27 @@ static void tmp105_write(TMP105State *s)
static int tmp105_rx(I2CSlave *i2c)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
- if (s->len < 2)
+ if (s->len < 2) {
return s->buf[s->len ++];
- else
+ } else {
return 0xff;
+ }
}
static int tmp105_tx(I2CSlave *i2c, uint8_t data)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
- if (!s->len ++)
+ if (s->len == 0) {
s->pointer = data;
- else {
- if (s->len <= 2)
+ s->len++;
+ } else {
+ if (s->len <= 2) {
s->buf[s->len - 1] = data;
+ }
+ s->len++;
tmp105_write(s);
}
@@ -166,10 +172,11 @@ static int tmp105_tx(I2CSlave *i2c, uint8_t data)
static void tmp105_event(I2CSlave *i2c, enum i2c_event event)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
- if (event == I2C_START_RECV)
+ if (event == I2C_START_RECV) {
tmp105_read(s);
+ }
s->len = 0;
}
@@ -205,7 +212,7 @@ static const VMStateDescription vmstate_tmp105 = {
static void tmp105_reset(I2CSlave *i2c)
{
- TMP105State *s = (TMP105State *) i2c;
+ TMP105State *s = TMP105(i2c);
s->temperature = 0;
s->pointer = 0;
@@ -218,7 +225,7 @@ static void tmp105_reset(I2CSlave *i2c)
static int tmp105_init(I2CSlave *i2c)
{
- TMP105State *s = FROM_I2C_SLAVE(TMP105State, i2c);
+ TMP105State *s = TMP105(i2c);
qdev_init_gpio_out(&i2c->qdev, &s->pin, 1);
@@ -227,6 +234,13 @@ static int tmp105_init(I2CSlave *i2c)
return 0;
}
+static void tmp105_initfn(Object *obj)
+{
+ object_property_add(obj, "temperature", "int",
+ tmp105_get_temperature,
+ tmp105_set_temperature, NULL, NULL, NULL);
+}
+
static void tmp105_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -240,9 +254,10 @@ static void tmp105_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo tmp105_info = {
- .name = "tmp105",
+ .name = TYPE_TMP105,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(TMP105State),
+ .instance_init = tmp105_initfn,
.class_init = tmp105_class_init,
};
diff --git a/hw/tmp105.h b/hw/tmp105.h
index 51eff4be1c..d2189191e2 100644
--- a/hw/tmp105.h
+++ b/hw/tmp105.h
@@ -15,53 +15,33 @@
#define QEMU_TMP105_H
#include "i2c.h"
+#include "tmp105_regs.h"
-/**
- * TMP105Reg:
- * @TMP105_REG_TEMPERATURE: Temperature register
- * @TMP105_REG_CONFIG: Configuration register
- * @TMP105_REG_T_LOW: Low temperature register (also known as T_hyst)
- * @TMP105_REG_T_HIGH: High temperature register (also known as T_OS)
- *
- * The following temperature sensors are
- * compatible with the TMP105 registers:
- * - adt75
- * - ds1775
- * - ds75
- * - lm75
- * - lm75a
- * - max6625
- * - max6626
- * - mcp980x
- * - stds75
- * - tcn75
- * - tmp100
- * - tmp101
- * - tmp105
- * - tmp175
- * - tmp275
- * - tmp75
- **/
-typedef enum TMP105Reg {
- TMP105_REG_TEMPERATURE = 0,
- TMP105_REG_CONFIG,
- TMP105_REG_T_LOW,
- TMP105_REG_T_HIGH,
-} TMP105Reg;
+#define TYPE_TMP105 "tmp105"
+#define TMP105(obj) OBJECT_CHECK(TMP105State, (obj), TYPE_TMP105)
/**
- * tmp105_set:
- * @i2c: dispatcher to TMP105 hardware model
- * @temp: temperature with 0.001 centigrades units in the range -40 C to +125 C
- *
- * Sets the temperature of the TMP105 hardware model.
+ * TMP105State:
+ * @config: Bits 5 and 6 (value 32 and 64) determine the precision of the
+ * temperature. See Table 8 in the data sheet.
*
- * Bits 5 and 6 (value 32 and 64) in the register indexed by TMP105_REG_CONFIG
- * determine the precision of the temperature. See Table 8 in the data sheet.
- *
- * @see_also: I2C_SLAVE macro
* @see_also: http://www.ti.com/lit/gpn/tmp105
*/
-void tmp105_set(I2CSlave *i2c, int temp);
+typedef struct TMP105State {
+ /*< private >*/
+ I2CSlave i2c;
+ /*< public >*/
+
+ uint8_t len;
+ uint8_t buf[2];
+ qemu_irq pin;
+
+ uint8_t pointer;
+ uint8_t config;
+ int16_t temperature;
+ int16_t limit[2];
+ int faults;
+ uint8_t alarm;
+} TMP105State;
#endif
diff --git a/hw/tmp105_regs.h b/hw/tmp105_regs.h
new file mode 100644
index 0000000000..9b55abaf90
--- /dev/null
+++ b/hw/tmp105_regs.h
@@ -0,0 +1,50 @@
+/*
+ * Texas Instruments TMP105 Temperature Sensor I2C messages
+ *
+ * Browse the data sheet:
+ *
+ * http://www.ti.com/lit/gpn/tmp105
+ *
+ * Copyright (C) 2012 Alex Horn <alex.horn@cs.ox.ac.uk>
+ * Copyright (C) 2008-2012 Andrzej Zaborowski <balrogg@gmail.com>
+ *
+ * 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 QEMU_TMP105_MSGS_H
+#define QEMU_TMP105_MSGS_H
+
+/**
+ * TMP105Reg:
+ * @TMP105_REG_TEMPERATURE: Temperature register
+ * @TMP105_REG_CONFIG: Configuration register
+ * @TMP105_REG_T_LOW: Low temperature register (also known as T_hyst)
+ * @TMP105_REG_T_HIGH: High temperature register (also known as T_OS)
+ *
+ * The following temperature sensors are
+ * compatible with the TMP105 registers:
+ * - adt75
+ * - ds1775
+ * - ds75
+ * - lm75
+ * - lm75a
+ * - max6625
+ * - max6626
+ * - mcp980x
+ * - stds75
+ * - tcn75
+ * - tmp100
+ * - tmp101
+ * - tmp105
+ * - tmp175
+ * - tmp275
+ * - tmp75
+ **/
+typedef enum TMP105Reg {
+ TMP105_REG_TEMPERATURE = 0,
+ TMP105_REG_CONFIG,
+ TMP105_REG_T_LOW,
+ TMP105_REG_T_HIGH,
+} TMP105Reg;
+
+#endif
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 1b87352db0..b839798eaf 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -427,7 +427,7 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
scsi_req_print(s->req);
#endif
scsi_req_enqueue(s->req);
- if (s->req && s->req->cmd.xfer != SCSI_XFER_NONE) {
+ if (s->req->cmd.xfer != SCSI_XFER_NONE) {
scsi_req_continue(s->req);
}
break;
diff --git a/tests/Makefile b/tests/Makefile
index d97a571c8b..d86e95a400 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -60,6 +60,8 @@ gcov-files-i386-y += i386-softmmu/hw/mc146818rtc.c
check-qtest-sparc-y = tests/m48t59-test$(EXESUF)
check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
gcov-files-sparc-y += hw/m48t59.c
+check-qtest-arm-y = tests/tmp105-test$(EXESUF)
+qcov-files-arm-y += hw/tmp105.c
GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
@@ -108,6 +110,7 @@ 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
# QTest rules
@@ -116,6 +119,7 @@ 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
new file mode 100644
index 0000000000..9be57e92c4
--- /dev/null
+++ b/tests/libi2c-omap.c
@@ -0,0 +1,166 @@
+/*
+ * 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 <glib.h>
+#include <string.h>
+
+#include "qemu/osdep.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;
+
+ memwrite(s->addr + OMAP_I2C_SA, &data, 2);
+ memread(s->addr + OMAP_I2C_SA, &data, 2);
+ 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;
+ memwrite(s->addr + OMAP_I2C_CNT, &data, 2);
+
+ 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);
+ g_assert((data & OMAP_I2C_CON_STP) != 0);
+
+ memread(s->addr + OMAP_I2C_STAT, &data, 2);
+ g_assert((data & OMAP_I2C_STAT_NACK) == 0);
+
+ while (len > 1) {
+ memread(s->addr + OMAP_I2C_STAT, &data, 2);
+ g_assert((data & OMAP_I2C_STAT_XRDY) != 0);
+
+ memwrite(s->addr + OMAP_I2C_DATA, buf, 2);
+ buf = (uint8_t *)buf + 2;
+ len -= 2;
+ }
+ if (len == 1) {
+ memread(s->addr + OMAP_I2C_STAT, &data, 2);
+ g_assert((data & OMAP_I2C_STAT_XRDY) != 0);
+
+ memwrite(s->addr + OMAP_I2C_DATA, buf, 1);
+ }
+
+ memread(s->addr + OMAP_I2C_CON, &data, 2);
+ 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;
+ memwrite(s->addr + OMAP_I2C_CNT, &data, 2);
+
+ 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);
+ g_assert((data & OMAP_I2C_CON_STP) == 0);
+
+ memread(s->addr + OMAP_I2C_STAT, &data, 2);
+ g_assert((data & OMAP_I2C_STAT_NACK) == 0);
+
+ memread(s->addr + OMAP_I2C_CNT, &data, 2);
+ g_assert_cmpuint(data, ==, len);
+
+ while (len > 0) {
+ memread(s->addr + OMAP_I2C_STAT, &data, 2);
+ 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);
+ if (unlikely(len == 1)) {
+ *buf = data & 0xf;
+ buf++;
+ len--;
+ } else {
+ memcpy(buf, &data, 2);
+ buf += 2;
+ len -= 2;
+ }
+ }
+
+ memread(s->addr + OMAP_I2C_CON, &data, 2);
+ 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 */
+ memread(addr + OMAP_I2C_REV, &data, 2);
+ g_assert_cmphex(data, ==, 0x34);
+
+ return i2c;
+}
diff --git a/tests/libi2c.c b/tests/libi2c.c
new file mode 100644
index 0000000000..13ec85c0cb
--- /dev/null
+++ b/tests/libi2c.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 "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
new file mode 100644
index 0000000000..1ce9af4053
--- /dev/null
+++ b/tests/libi2c.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 <stdint.h>
+
+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
new file mode 100644
index 0000000000..a6ad213de8
--- /dev/null
+++ b/tests/tmp105-test.c
@@ -0,0 +1,76 @@
+/*
+ * QTest testcase for the TMP105 temperature sensor
+ *
+ * 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 "libqtest.h"
+#include "libi2c.h"
+#include "hw/tmp105_regs.h"
+
+#include <glib.h>
+
+#define OMAP2_I2C_1_BASE 0x48070000
+
+#define N8X0_ADDR 0x48
+
+static I2CAdapter *i2c;
+static uint8_t addr;
+
+static void send_and_receive(void)
+{
+ uint8_t cmd[3];
+ uint8_t resp[2];
+
+ cmd[0] = TMP105_REG_TEMPERATURE;
+ i2c_send(i2c, addr, cmd, 1);
+ i2c_recv(i2c, addr, resp, 2);
+ g_assert_cmpuint(((uint16_t)resp[0] << 8) | resp[1], ==, 0);
+
+ cmd[0] = TMP105_REG_CONFIG;
+ cmd[1] = 0x0; /* matches the reset value */
+ i2c_send(i2c, addr, cmd, 2);
+ i2c_recv(i2c, addr, resp, 1);
+ g_assert_cmphex(resp[0], ==, cmd[1]);
+
+ cmd[0] = TMP105_REG_T_LOW;
+ cmd[1] = 0x12;
+ cmd[2] = 0x34;
+ i2c_send(i2c, addr, cmd, 3);
+ i2c_recv(i2c, addr, resp, 2);
+ g_assert_cmphex(resp[0], ==, cmd[1]);
+ g_assert_cmphex(resp[1], ==, cmd[2]);
+
+ cmd[0] = TMP105_REG_T_HIGH;
+ cmd[1] = 0x42;
+ cmd[2] = 0x31;
+ i2c_send(i2c, addr, cmd, 3);
+ i2c_recv(i2c, addr, resp, 2);
+ g_assert_cmphex(resp[0], ==, cmd[1]);
+ g_assert_cmphex(resp[1], ==, cmd[2]);
+}
+
+int main(int argc, char **argv)
+{
+ QTestState *s = NULL;
+ int ret;
+
+ g_test_init(&argc, &argv, NULL);
+
+ s = qtest_start("-display none -machine n800");
+ i2c = omap_i2c_create(OMAP2_I2C_1_BASE);
+ addr = N8X0_ADDR;
+
+ qtest_add_func("/tmp105/tx-rx", send_and_receive);
+
+ ret = g_test_run();
+
+ if (s) {
+ qtest_quit(s);
+ }
+ g_free(i2c);
+
+ return ret;
+}
diff --git a/ui/keymaps.c b/ui/keymaps.c
index 9625d82fa1..f373cc53d9 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -127,25 +127,27 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
// fprintf(stderr, "Warning: unknown keysym %s\n", line);
} else {
const char *rest = end_of_keysym + 1;
- char *rest2;
- int keycode = strtol(rest, &rest2, 0);
+ int keycode = strtol(rest, NULL, 0);
- if (rest && strstr(rest, "numlock")) {
+ if (strstr(rest, "numlock")) {
add_to_key_range(&k->keypad_range, keycode);
add_to_key_range(&k->numlock_range, keysym);
//fprintf(stderr, "keypad keysym %04x keycode %d\n", keysym, keycode);
}
- if (rest && strstr(rest, "shift"))
+ if (strstr(rest, "shift")) {
keycode |= SCANCODE_SHIFT;
- if (rest && strstr(rest, "altgr"))
+ }
+ if (strstr(rest, "altgr")) {
keycode |= SCANCODE_ALTGR;
- if (rest && strstr(rest, "ctrl"))
+ }
+ if (strstr(rest, "ctrl")) {
keycode |= SCANCODE_CTRL;
+ }
add_keysym(line, keysym, keycode, k);
- if (rest && strstr(rest, "addupper")) {
+ if (strstr(rest, "addupper")) {
char *c;
for (c = line; *c; c++)
*c = qemu_toupper(*c);