From patchwork Fri Oct 11 09:38:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhou Yuan X-Patchwork-Id: 282556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 05FE62C00E7 for ; Fri, 11 Oct 2013 20:39:23 +1100 (EST) Received: from localhost ([::1]:53287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUZBo-0007r2-Sy for incoming@patchwork.ozlabs.org; Fri, 11 Oct 2013 05:39:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUZBM-0007kP-RN for qemu-devel@nongnu.org; Fri, 11 Oct 2013 05:38:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUZBI-0000Yr-HC for qemu-devel@nongnu.org; Fri, 11 Oct 2013 05:38:52 -0400 Received: from [222.73.24.84] (port=38967 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUZBI-0000YD-1i for qemu-devel@nongnu.org; Fri, 11 Oct 2013 05:38:48 -0400 X-IronPort-AV: E=Sophos;i="4.93,474,1378828800"; d="scan'208";a="8723944" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 11 Oct 2013 17:35:23 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r9B9cdOE032403 for ; Fri, 11 Oct 2013 17:38:39 +0800 Received: from G08FNSTD131504 ([10.167.223.35]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013101117362996-2186793 ; Fri, 11 Oct 2013 17:36:29 +0800 Date: Fri, 11 Oct 2013 17:38:39 +0800 From: "Zhou Yuan" To: "qemu-devel" Message-ID: <201310111738374027672@cn.fujitsu.com> X-mailer: Foxmail 6, 15, 201, 23 [cn] Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/10/11 17:36:29, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/10/11 17:36:30, Serialize complete at 2013/10/11 17:36:30 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Subject: [Qemu-devel] [PATCH] hw/gpio/max7310.c : add output register property and update the outputports level when necessary 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 From: Zhouy To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2013 15:54:47 -0400 Subject: [PATCH 1/1] add output register property and update the outputports level when necessary Signed-off-by: Zhouy --- qemu-master/hw/gpio/max7310.c | 33 ++++++++++++++++++++++----------- 1 files changed, 22 insertions(+), 11 deletions(-) diff --git a/qemu-master/hw/gpio/max7310.c b/qemu-master/hw/gpio/max7310.c index 59b2877..ffbeb6f 100644 --- a/qemu-master/hw/gpio/max7310.c +++ b/qemu-master/hw/gpio/max7310.c @@ -19,10 +19,25 @@ typedef struct { uint8_t polarity; uint8_t status; uint8_t command; + uint8_t output; qemu_irq handler[8]; qemu_irq *gpio_in; } MAX7310State; +/*this function to update outputports level*/ +static void max7310_update(MAX7310State *s) +{ + uint8_t diff = 0; + uint8_t line = 0; + for (diff = (s->output ^ s->level) & ~s->direction; diff; + diff &= ~(1 << line)) { + line = ffs(diff) - 1; + if (s->handler[line]) { + qemu_set_irq(s->handler[line], (s->output >> line) & 1); + } + } + s->level = (s->level & s->direction) | (s->level & ~s->direction); +} + static void max7310_reset(DeviceState *dev) { MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, I2C_SLAVE(dev)); @@ -31,6 +46,8 @@ static void max7310_reset(DeviceState *dev) s->polarity = 0xf0; s->status = 0x01; s->command = 0x00; + s->output = 0x00; + max7310_update(s); } static int max7310_rx(I2CSlave *i2c) @@ -43,7 +60,7 @@ static int max7310_rx(I2CSlave *i2c) break; case 0x01: /* Output port */ - return s->level & ~s->direction; + return s->output; break; case 0x02: /* Polarity inversion */ @@ -71,8 +88,6 @@ static int max7310_rx(I2CSlave *i2c) static int max7310_tx(I2CSlave *i2c, uint8_t data) { MAX7310State *s = (MAX7310State *) i2c; - uint8_t diff; - int line; if (s->len ++ > 1) { #ifdef VERBOSE @@ -89,13 +104,8 @@ static int max7310_tx(I2CSlave *i2c, uint8_t data) switch (s->command) { case 0x01: /* Output port */ - for (diff = (data ^ s->level) & ~s->direction; diff; - diff &= ~(1 << line)) { - line = ffs(diff) - 1; - if (s->handler[line]) - qemu_set_irq(s->handler[line], (data >> line) & 1); - } - s->level = (s->level & s->direction) | (data & ~s->direction); + s->output = data; + max7310_update(s); break; case 0x02: /* Polarity inversion */ @@ -103,8 +113,8 @@ static int max7310_tx(I2CSlave *i2c, uint8_t data) break; case 0x03: /* Configuration */ - s->level &= ~(s->direction ^ data); s->direction = data; + max7310_update(s); break; case 0x04: /* Timeout */ @@ -156,6 +166,7 @@ static const VMStateDescription vmstate_max7310 = { VMSTATE_UINT8(polarity, MAX7310State), VMSTATE_UINT8(status, MAX7310State), VMSTATE_UINT8(command, MAX7310State), + VMSTATE_UINT8(output, MAX7310State), VMSTATE_I2C_SLAVE(i2c, MAX7310State), VMSTATE_END_OF_LIST() }