I2C libqos and tmp105 qtest support
v4 cover I2C libqos and tmp105 qtest support
Hello Anthony,
Here's another rebased version of $subject. Please review changed bits and apply.
Regards,
Andreas
v3 -> v4:
* Rebased tmp105 onto already-const TypeInfo.
* Rebased qtest Makefile additions onto second build reorganization.
v2 -> v3:
* Alex' tmp105.h patch was applied.
* Rebased onto header reorganization.
* Rebased onto introduction of gcov support.
* Switched order of test case and bugfix to keep make check happy.
* Dropped extra white line and renamed int64_t value -> temp to make patch smaller.
v1 -> v2:
* Factor out libqos API for I2C and an OMAP driver
* Avoid casts by using uint8_t* in API, suggested by Blue
* Ignore SBD bit in omap_i2c driver
* Drop omap_i2c patch clearing SBD
* Incorporate Alex' tmp105.h patch
* Split out tmp105_regs.h for qtest, inspired by rtc-test
* Append replacement for Alex' fix
* Append QOM cleanup and turn setter function into QOM property
Andreas Färber (6):
libqtest: Prepare I2C libqos
tmp105: Split out I2C message constants from header
tmp105: Fix I2C protocol bug
tests: Add tmp105 qtest test case
tmp105: QOM'ify
tmp105: Add temperature QOM property
hw/tmp105.c | 77 ++++++++++++++---------- hw/tmp105.h | 64 +++++++------------- hw/tmp105_regs.h | 50 ++++++++++++++++ tests/Makefile | 4 ++ tests/libi2c-omap.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/libi2c.c | 22 +++++++ tests/libi2c.h | 30 ++++++++++ tests/tmp105-test.c | 76 +++++++++++++++++++++++ 8 Dateien geändert, 416 Zeilen hinzugefügt(+), 73 Zeilen entfernt(-) create mode 100644 hw/tmp105_regs.h create mode 100644 tests/libi2c-omap.c create mode 100644 tests/libi2c.c create mode 100644 tests/libi2c.h create mode 100644 tests/tmp105-test.c
Signature · 1 line
1.7.10.4
PATCH v4 1/6 libqtest: Prepare I2C libqos
This adds a simple I2C API and a driver implementation for omap_i2c.
--- tests/Makefile | 1 + tests/libi2c-omap.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/libi2c.c | 22 +++++++ tests/libi2c.h | 30 ++++++++++ 4 Dateien geändert, 219 Zeilen hinzugefügt(+) create mode 100644 tests/libi2c-omap.c create mode 100644 tests/libi2c.c create mode 100644 tests/libi2c.h
tests/Makefile +1 -0
@@ -116,6 +116,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
tests/libi2c-omap.c new file +166 -0
166 lines not on this page · raw message
tests/libi2c.c new file +22 -0
@@ -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); +}
tests/libi2c.h new file +30 -0
@@ -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
Signature · 1 line
1.7.10.4
PATCH v4 2/6 tmp105: Split out I2C message constants from header
In reply to Andreas FärberAllows value sharing with qtest.
--- hw/tmp105.h | 34 +--------------------------------- hw/tmp105_regs.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 Dateien geändert, 51 Zeilen hinzugefügt(+), 33 Zeilen entfernt(-) create mode 100644 hw/tmp105_regs.h
hw/tmp105.h +1 -33
@@ -15,39 +15,7 @@#define QEMU_TMP105_H #include "i2c.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 ; +#include "tmp105_regs.h" /** * tmp105_set:
hw/tmp105_regs.h new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v4 3/6 tmp105: Fix I2C protocol bug
In reply to Andreas FärberAn early length postincrement in the TMP105's I2C TX path led to transfers of more than one byte to place the second byte in the third byte's place within the buffer and the third byte to get discarded.
Fix this by explictly incrementing the length after the checks but before the callback is called, which again checks the length.
Adjust the Coding Style while at it.
--- hw/tmp105.c | 9 ++++++---
1 Datei geändert, 6 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)
hw/tmp105.c +6 -3
@@ -153,11 +153,14 @@ static int tmp105_tx(I2CSlave *i2c, uint8_t data) {TMP105State *s = (TMP105State *) 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); }
Signature · 1 line
1.7.10.4
PATCH v4 4/6 tests: Add tmp105 qtest test case
In reply to Andreas FärberExercise all four commands of the TMP105, testing for an issue in the I2C TX path.
The test case uses the N800's OMAP I2C and is the first for ARM.
--- tests/Makefile | 3 ++ tests/tmp105-test.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 Dateien geändert, 79 Zeilen hinzugefügt(+) create mode 100644 tests/tmp105-test.c
tests/Makefile +3 -0
@@ -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
tests/tmp105-test.c new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v4 5/6 tmp105: QOM'ify
In reply to Andreas FärberIntroduce TYPE_ constant and cast macro.
Move the state struct to the new header to allow for future embedding.
--- hw/tmp105.c | 36 ++++++++++++------------------------ hw/tmp105.h | 27 +++++++++++++++++++++++++++
2 Dateien geändert, 39 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)
hw/tmp105.c +12 -24
@@ -22,20 +22,6 @@#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 ; -static void tmp105_interrupt_update (TMP105State *s) {qemu_set_irq (s->pin, s->alarm ^ ((~s->config >>2 ) &1 ));/* POL */
@@ -68,7 +54,7 @@ static void tmp105_alarm_update(TMP105State *s)/* Units are 0.001 centigrades relative to 0 C. */ void tmp105_set (I2CSlave *i2c,int temp) { -TMP105State *s = (TMP105State *) i2c; +TMP105State *s =TMP105 (i2c);if (temp >=128000 || temp <-128000 ) { fprintf(stderr, "%s: values is out of range (%i.%03i C)\n",
@@ -141,17 +127,18 @@ 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 ==0 ) { s->pointer = data;
@@ -169,10 +156,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 ; }
@@ -208,7 +196,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 ;
@@ -221,7 +209,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 );
@@ -243,7 +231,7 @@ 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), .class_init = tmp105_class_init,
hw/tmp105.h +27 -0
@@ -17,6 +17,33 @@#include "i2c.h" #include "tmp105_regs.h" +#define TYPE_TMP105 "tmp105" +#define TMP105 (obj) OBJECT_CHECK(TMP105State, (obj), TYPE_TMP105) + +/** +* TMP105State: +* @config: Bits 5 and 6 (value 32 and 64) determine the precision of the +* temperature. See Table 8 in the data sheet. +* +* @see_also: http://www.ti.com/lit/gpn/tmp105 +*/ +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 ; +/** * tmp105_set: * @i2c: dispatcher to TMP105 hardware model
Signature · 1 line
1.7.10.4
PATCH v4 6/6 tmp105: Add temperature QOM property
In reply to Andreas FärberThis obsoletes tmp105_set() and allows for better error handling.
--- hw/tmp105.c | 34 +++++++++++++++++++++++++++++----- hw/tmp105.h | 15 ---------------
2 Dateien geändert, 29 Zeilen hinzugefügt(+), 20 Zeilen entfernt(-)
hw/tmp105.c +29 -5
@@ -21,6 +21,7 @@#include "hw.h" #include "i2c.h" #include "tmp105.h" +#include "qapi/visitor.h" static void tmp105_interrupt_update (TMP105State *s) {
@@ -51,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 =TMP105 (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 ;
@@ -218,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);
@@ -234,6 +257,7 @@ static const TypeInfo tmp105_info = { .name = TYPE_TMP105, .parent = TYPE_I2C_SLAVE, .instance_size = sizeof(TMP105State), + .instance_init = tmp105_initfn, .class_init = tmp105_class_init, };
hw/tmp105.h +0 -15
@@ -44,19 +44,4 @@ typedef struct TMP105State { uint8_t alarm; } TMP105State; -/** -* 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. -* -* 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); -#endif
Signature · 1 line
1.7.10.4