From patchwork Wed Jan 16 00:57:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 212359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 195912C0095 for ; Wed, 16 Jan 2013 11:58:34 +1100 (EST) Received: from localhost ([::1]:53863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvHKq-00043C-9B for incoming@patchwork.ozlabs.org; Tue, 15 Jan 2013 19:58:32 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvHKX-0003yH-HG for qemu-devel@nongnu.org; Tue, 15 Jan 2013 19:58:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvHKU-0002TC-Vr for qemu-devel@nongnu.org; Tue, 15 Jan 2013 19:58:13 -0500 Received: from mout.web.de ([212.227.15.4]:58027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvHKU-0002St-MM for qemu-devel@nongnu.org; Tue, 15 Jan 2013 19:58:10 -0500 Received: from localhost.localdomain ([84.148.40.139]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0MQNjQ-1TVsBJ0sIu-00U1eb; Wed, 16 Jan 2013 01:58:09 +0100 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2013 01:57:58 +0100 Message-Id: <1358297879-26576-6-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358297879-26576-1-git-send-email-andreas.faerber@web.de> References: <1358297879-26576-1-git-send-email-andreas.faerber@web.de> MIME-Version: 1.0 X-Provags-ID: V02:K0:HqTE/kQkN18LHO+WskpM2ziHuCae6GdRKRTjiy86jSQ 3NO6+A0xAskkihZnphd+NuiV+nUCRSecMP975RQGdXM8boHisc hDzMl3o6q5vKowRp4Qg2kYvoTphAZv33zZt88cJ/+jUk1XODow nYksDKgUFcGYNUPaQPEpGbVPPrIwSBSSZ3K1gugp9vTtKsBluC OJm+OTXWM/m6o9v2LtqNQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.15.4 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , anthony@codemonkey.ws Subject: [Qemu-devel] [PATCH for-1.4 v4 5/6] tmp105: QOM'ify X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Introduce TYPE_ constant and cast macro. Move the state struct to the new header to allow for future embedding. Signed-off-by: Andreas Färber Reviewed-by: Anthony Liguori --- hw/tmp105.c | 36 ++++++++++++------------------------ hw/tmp105.h | 27 +++++++++++++++++++++++++++ 2 Dateien geändert, 39 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-) diff --git a/hw/tmp105.c b/hw/tmp105.c index 10d94c9..a16f538 100644 --- a/hw/tmp105.c +++ b/hw/tmp105.c @@ -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, diff --git a/hw/tmp105.h b/hw/tmp105.h index 982d1c9..c21396f 100644 --- a/hw/tmp105.h +++ b/hw/tmp105.h @@ -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