From patchwork Mon Oct 24 20:38:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Canet X-Patchwork-Id: 121423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 25961B6F84 for ; Tue, 25 Oct 2011 08:40:25 +1100 (EST) Received: from localhost ([::1]:57563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RISFq-0001WW-6T for incoming@patchwork.ozlabs.org; Mon, 24 Oct 2011 17:40:22 -0400 Received: from eggs.gnu.org ([140.186.70.92]:42965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIRHU-0004PH-Hr for qemu-devel@nongnu.org; Mon, 24 Oct 2011 16:38:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RIRHS-0005SA-QV for qemu-devel@nongnu.org; Mon, 24 Oct 2011 16:38:00 -0400 Received: from mail-ww0-f41.google.com ([74.125.82.41]:51356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIRHS-0005Rr-HO for qemu-devel@nongnu.org; Mon, 24 Oct 2011 16:37:58 -0400 Received: by wwe32 with SMTP id 32so4229407wwe.4 for ; Mon, 24 Oct 2011 13:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=S3SVi2w3jJTREyBRzDzYkElzfbu+oODnR/tiI5sIOCE=; b=Fj8jg3S+2lwXlXSId6+fBuMV0DWXnNtdaZ5Of5RTdYHhktzo2XLa3XDqJ1up7wBl6W 64jwiEletP5tuWg+RzIkPrHZHj+9xTIuT9sWOpHJt5U71BKrsCr9gLG8ZMLaM7cVNzL3 Q0lwgcBi3giVviVkZvIYjJQVi1uOJxTJgpLVI= Received: by 10.216.140.223 with SMTP id e73mr11078987wej.9.1319488620407; Mon, 24 Oct 2011 13:37:00 -0700 (PDT) Received: from localhost.localdomain ([78.250.84.36]) by mx.google.com with ESMTPS id ff6sm10499039wbb.10.2011.10.24.13.36.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Oct 2011 13:36:59 -0700 (PDT) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Mon, 24 Oct 2011 22:38:30 +0200 Message-Id: <1319488713-3482-12-git-send-email-benoit.canet@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1319488713-3482-1-git-send-email-benoit.canet@gmail.com> References: <1319488713-3482-1-git-send-email-benoit.canet@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.41 Cc: peter.maydell@linaro.org, =?UTF-8?q?Beno=C3=AEt=20Canet?= Subject: [Qemu-devel] [PATCH 11/14] bitbang_i2c: convert to VMState 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 Signed-off-by: Benoit Canet --- hw/bitbang_i2c.c | 92 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 61 insertions(+), 31 deletions(-) diff --git a/hw/bitbang_i2c.c b/hw/bitbang_i2c.c index 431359d..453f1da 100644 --- a/hw/bitbang_i2c.c +++ b/hw/bitbang_i2c.c @@ -19,37 +19,53 @@ do { printf("bitbang_i2c: " fmt , ## __VA_ARGS__); } while (0) #define DPRINTF(fmt, ...) do {} while(0) #endif -typedef enum bitbang_i2c_state { +enum { STOPPED = 0, - SENDING_BIT7, - SENDING_BIT6, - SENDING_BIT5, - SENDING_BIT4, - SENDING_BIT3, - SENDING_BIT2, - SENDING_BIT1, - SENDING_BIT0, - WAITING_FOR_ACK, - RECEIVING_BIT7, - RECEIVING_BIT6, - RECEIVING_BIT5, - RECEIVING_BIT4, - RECEIVING_BIT3, - RECEIVING_BIT2, - RECEIVING_BIT1, - RECEIVING_BIT0, - SENDING_ACK, - SENT_NACK -} bitbang_i2c_state; + SENDING_BIT7 = 1, + SENDING_BIT6 = 2, + SENDING_BIT5 = 3, + SENDING_BIT4 = 4, + SENDING_BIT3 = 5, + SENDING_BIT2 = 6, + SENDING_BIT1 = 7, + SENDING_BIT0 = 8, + WAITING_FOR_ACK = 9, + RECEIVING_BIT7 = 10, + RECEIVING_BIT6 = 11, + RECEIVING_BIT5 = 12, + RECEIVING_BIT4 = 13, + RECEIVING_BIT3 = 14, + RECEIVING_BIT2 = 15, + RECEIVING_BIT1 = 16, + RECEIVING_BIT0 = 17, + SENDING_ACK = 18, + SENT_NACK = 19 +}; struct bitbang_i2c_interface { i2c_bus *bus; - bitbang_i2c_state state; - int last_data; - int last_clock; - int device_out; + uint8_t state; + int32_t last_data; + int32_t last_clock; + int32_t device_out; uint8_t buffer; - int current_addr; + int32_t current_addr; +}; + +const VMStateDescription vmstate_bitbang_i2c = { + .name = "bitbang_i2c", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField []) { + VMSTATE_UINT8(state, bitbang_i2c_interface), + VMSTATE_INT32(last_data, bitbang_i2c_interface), + VMSTATE_INT32(last_clock, bitbang_i2c_interface), + VMSTATE_INT32(device_out, bitbang_i2c_interface), + VMSTATE_UINT8(buffer, bitbang_i2c_interface), + VMSTATE_INT32(current_addr, bitbang_i2c_interface), + VMSTATE_END_OF_LIST() + } }; static void bitbang_i2c_enter_stop(bitbang_i2c_interface *i2c) @@ -62,7 +78,7 @@ static void bitbang_i2c_enter_stop(bitbang_i2c_interface *i2c) } /* Set device data pin. */ -static int bitbang_i2c_ret(bitbang_i2c_interface *i2c, int level) +static int32_t bitbang_i2c_ret(bitbang_i2c_interface *i2c, int32_t level) { i2c->device_out = level; //DPRINTF("%d %d %d\n", i2c->last_clock, i2c->last_data, i2c->device_out); @@ -70,13 +86,13 @@ static int bitbang_i2c_ret(bitbang_i2c_interface *i2c, int level) } /* Leave device data pin unodified. */ -static int bitbang_i2c_nop(bitbang_i2c_interface *i2c) +static int32_t bitbang_i2c_nop(bitbang_i2c_interface *i2c) { return bitbang_i2c_ret(i2c, i2c->device_out); } /* Returns data line level. */ -int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level) +int32_t bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int32_t level) { int data; @@ -185,11 +201,24 @@ bitbang_i2c_interface *bitbang_i2c_init(i2c_bus *bus) typedef struct { SysBusDevice busdev; bitbang_i2c_interface *bitbang; - int last_level; + int32_t last_level; qemu_irq out; } GPIOI2CState; -static void bitbang_i2c_gpio_set(void *opaque, int irq, int level) +const VMStateDescription vmstate_gpio_i2c = { + .name = "gpio_i2c", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField []) { + VMSTATE_STRUCT_POINTER(bitbang, GPIOI2CState, vmstate_bitbang_i2c, + bitbang_i2c_interface *), + VMSTATE_INT32(last_level, GPIOI2CState), + VMSTATE_END_OF_LIST() + } +}; + +static void bitbang_i2c_gpio_set(void *opaque, int irq, int32_t level) { GPIOI2CState *s = opaque; @@ -221,6 +250,7 @@ static SysBusDeviceInfo gpio_i2c_info = { .qdev.name = "gpio_i2c", .qdev.desc = "Virtual GPIO to I2C bridge", .qdev.size = sizeof(GPIOI2CState), + .qdev.vmsd = &vmstate_gpio_i2c, }; static void bitbang_i2c_register(void)