All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hw/gpio/max7310.c : add output register property and update the outputports level when necessary
@ 2013-10-11  9:38 Zhou Yuan
  2013-11-17  2:33 ` [Qemu-devel] [PATCH] hw/gpio/max7310.c : add the reset-pin in Max7310 and the GPIO will be reseted by the reset signal(active low) " Zhou Yuan
  0 siblings, 1 reply; 2+ messages in thread
From: Zhou Yuan @ 2013-10-11  9:38 UTC (permalink / raw)
  To: qemu-devel

From: Zhouy <zhouyuan.fnst@cn.fujitsu.com>
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 <zhouyuan.fnst@cn.fujitsu.com>
---
 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()
     }
-- 
1.7.6

--------------
A new email address of FJWAN is launched from Apr.1 2007.
The updated address is: zhouyuan.fnst@cn.fujitsu.com 
--------------------------------------------------
Zhou Yuan
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No. 6 Wenzhu Road, Nanjing, 210012, China
TEL:+86+25-86630566-9555
FUJITSU INTERNAL:7998-9555
FAX:+86+25-83317685
EMail:zhouyuan.fnst@cn.fujitsu.com
--------------------------------------------------
This communication is for use by the intended recipient(s) only and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not an intended recipient of this communication, you are hereby notified that any dissemination, distribution or copying hereof is strictly prohibited.  If you have received this communication in error, please notify me by reply e-mail, permanently delete this communication from your system, and destroy any hard copies you may have printed.
 
zhouyuan.fnst@cn.fujitsu.com
16:34:14

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Qemu-devel] [PATCH] hw/gpio/max7310.c : add the reset-pin in Max7310 and the GPIO will be reseted by the reset signal(active low) when necessary
  2013-10-11  9:38 [Qemu-devel] [PATCH] hw/gpio/max7310.c : add output register property and update the outputports level when necessary Zhou Yuan
@ 2013-11-17  2:33 ` Zhou Yuan
  0 siblings, 0 replies; 2+ messages in thread
From: Zhou Yuan @ 2013-11-17  2:33 UTC (permalink / raw)
  To: qemu-devel

From: zhouy <zhouyuan.fnst@cn.fujitsu.com>
Date: Sun, 17 Nov 2013 09:24:38 -0500
Subject: [PATCH 4/4] add the reset-pin in Max7310 and the GPIO will be
 reseted by the reset signal(active low) when necessary


Signed-off-by: zhouy <zhouyuan.fnst@cn.fujitsu.com>
---

 qemu-master/hw/gpio/max7310.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/qemu-master/hw/gpio/max7310.c b/qemu-master/hw/gpio/max7310.c
index 59b2877..54df220 100644
--- a/qemu-master/hw/gpio/max7310.c
+++ b/qemu-master/hw/gpio/max7310.c
@@ -166,7 +166,11 @@ static void max7310_gpio_set(void *opaque, int line, int level)
     MAX7310State *s = (MAX7310State *) opaque;
     if (line >= ARRAY_SIZE(s->handler) || line  < 0)
         hw_error("bad GPIO line");
-
+    /* add reset-pin (active low) as the 9th gpio-in*/
+    if (line == 8 && level == 0) {
+        max7310_reset(s);
+        return;
+    }
     if (level)
         s->level |= s->direction & (1 << line);
     else
@@ -179,7 +183,7 @@ static int max7310_init(I2CSlave *i2c)
 {
     MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, i2c);
 
-    qdev_init_gpio_in(&i2c->qdev, max7310_gpio_set, 8);
+    qdev_init_gpio_in(&i2c->qdev, max7310_gpio_set, 9);
     qdev_init_gpio_out(&i2c->qdev, s->handler, 8);
 
     return 0;
-- 
1.7.6

--------------
A new email address of FJWAN is launched from Apr.1 2007.
The updated address is: zhouyuan.fnst@cn.fujitsu.com 
--------------------------------------------------

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-17  2:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-11  9:38 [Qemu-devel] [PATCH] hw/gpio/max7310.c : add output register property and update the outputports level when necessary Zhou Yuan
2013-11-17  2:33 ` [Qemu-devel] [PATCH] hw/gpio/max7310.c : add the reset-pin in Max7310 and the GPIO will be reseted by the reset signal(active low) " Zhou Yuan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.