qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: fred.konrad@greensocs.com
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
	hyunk@xilinx.com, mark.burton@greensocs.com,
	guillaume.delbergue@greensocs.com, fred.konrad@greensocs.com
Subject: [Qemu-devel] [PATCH V2 2/7] i2c: implement broadcast write.
Date: Mon, 15 Jun 2015 17:15:38 +0200	[thread overview]
Message-ID: <1434381343-7583-3-git-send-email-fred.konrad@greensocs.com> (raw)
In-Reply-To: <1434381343-7583-1-git-send-email-fred.konrad@greensocs.com>

From: KONRAD Frederic <fred.konrad@greensocs.com>

This does a write to every slaves when the I2C bus get a write to address 0.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/i2c/core.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 5a64026..db1cbdd 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -15,6 +15,7 @@ struct I2CBus
     I2CSlave *current_dev;
     I2CSlave *dev;
     uint8_t saved_address;
+    bool broadcast;
 };
 
 static Property i2c_props[] = {
@@ -67,6 +68,8 @@ I2CBus *i2c_init_bus(DeviceState *parent, const char *name)
 
     bus = I2C_BUS(qbus_create(TYPE_I2C_BUS, parent, name));
     vmstate_register(NULL, -1, &vmstate_i2c_bus, bus);
+
+    bus->broadcast = false;
     return bus;
 }
 
@@ -89,6 +92,21 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
     I2CSlave *slave = NULL;
     I2CSlaveClass *sc;
 
+    if (address == 0x00) {
+        /*
+         * This is a broadcast.
+         */
+        QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
+            I2CSlave *dev = I2C_SLAVE(kid->child);
+            sc = I2C_SLAVE_GET_CLASS(dev);
+            bus->broadcast = true;
+            if (sc->event) {
+                sc->event(dev, recv ? I2C_START_RECV : I2C_START_SEND);
+            }
+        }
+        return 0;
+    }
+
     QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
         DeviceState *qdev = kid->child;
         I2CSlave *candidate = I2C_SLAVE(qdev);
@@ -114,9 +132,21 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
 
 void i2c_end_transfer(I2CBus *bus)
 {
+    BusChild *kid;
     I2CSlave *dev = bus->current_dev;
     I2CSlaveClass *sc;
 
+    if (bus->broadcast) {
+        QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
+            I2CSlave *dev = I2C_SLAVE(kid->child);
+            sc = I2C_SLAVE_GET_CLASS(dev);
+            if (sc->event) {
+                sc->event(dev, I2C_FINISH);
+            }
+        }
+        bus->broadcast = false;
+    }
+
     if (!dev) {
         return;
     }
@@ -131,8 +161,22 @@ void i2c_end_transfer(I2CBus *bus)
 
 int i2c_send(I2CBus *bus, uint8_t data)
 {
+    BusChild *kid;
     I2CSlave *dev = bus->current_dev;
     I2CSlaveClass *sc;
+    int ret = 0;
+
+    if (bus->broadcast) {
+        QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
+            I2CSlave *dev = I2C_SLAVE(kid->child);
+            sc = I2C_SLAVE_GET_CLASS(dev);
+            bus->broadcast = true;
+            if (sc->send) {
+                ret |= sc->send(dev, data);
+            }
+        }
+        return ret;
+    }
 
     if (!dev) {
         return -1;
@@ -151,7 +195,7 @@ int i2c_recv(I2CBus *bus)
     I2CSlave *dev = bus->current_dev;
     I2CSlaveClass *sc;
 
-    if (!dev) {
+    if ((!dev) || (bus->broadcast)) {
         return -1;
     }
 
-- 
1.9.0

  parent reply	other threads:[~2015-06-15 15:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-15 15:15 [Qemu-devel] [PATCH V2 0/7] Xilinx DisplayPort fred.konrad
2015-06-15 15:15 ` [Qemu-devel] [PATCH V2 1/7] Introduce AUX bus fred.konrad
2015-06-24  6:21   ` Peter Crosthwaite
2015-07-06 16:27     ` Frederic Konrad
2015-06-15 15:15 ` fred.konrad [this message]
2015-06-24  6:35   ` [Qemu-devel] [PATCH V2 2/7] i2c: implement broadcast write Peter Crosthwaite
2015-07-06 16:28     ` Frederic Konrad
2015-07-06 16:54       ` Peter Crosthwaite
2015-06-15 15:15 ` [Qemu-devel] [PATCH V2 3/7] introduce dpcd module fred.konrad
2015-06-24  6:44   ` Peter Crosthwaite
2015-07-06 16:30     ` Frederic Konrad
2015-07-06 16:57       ` Peter Crosthwaite
2015-06-15 15:15 ` [Qemu-devel] [PATCH V2 4/7] hw/i2c-ddc.c: Implement DDC I2C slave fred.konrad
2015-06-24  7:03   ` Peter Crosthwaite
2015-06-15 15:15 ` [Qemu-devel] [PATCH V2 5/7] Introduce xilinx dpdma fred.konrad
2015-06-24  7:41   ` Peter Crosthwaite
2015-06-15 15:15 ` [Qemu-devel] [PATCH V2 6/7] Introduce xilinx dp fred.konrad
2015-06-24  8:21   ` Peter Crosthwaite
2015-06-15 15:15 ` [Qemu-devel] [PATCH V2 7/7] arm: xlnx-zynqmp: Add DisplayPort and DPDMA fred.konrad
2015-06-24  8:23   ` Peter Crosthwaite

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434381343-7583-3-git-send-email-fred.konrad@greensocs.com \
    --to=fred.konrad@greensocs.com \
    --cc=guillaume.delbergue@greensocs.com \
    --cc=hyunk@xilinx.com \
    --cc=mark.burton@greensocs.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).