From: Patrick Venture <venture@google.com>
To: cminyard@mvista.com, wuhaotsh@google.com, hskinnemoen@google.com
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
Patrick Venture <venture@google.com>
Subject: [PATCH 1/2] hw/i2c/core: add reachable state boolean
Date: Sat, 3 Apr 2021 15:28:09 -0700 [thread overview]
Message-ID: <20210403222810.3481372-2-venture@google.com> (raw)
In-Reply-To: <20210403222810.3481372-1-venture@google.com>
An i2c device can be reachable or not, controlled by some external
factor. This field is leveraged by an i2c mux which presents the
devices on the parent bus when the associated channel is enabled and
otherwise not.
Signed-off-by: Patrick Venture <venture@google.com>
Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com>
Reviewed-by: Hao Wu <wuhaotsh@google.com>
---
hw/i2c/core.c | 6 ++++++
include/hw/i2c/i2c.h | 3 +++
2 files changed, 9 insertions(+)
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 21ec52ac5a..fa7db4549d 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -18,6 +18,7 @@
#define I2C_BROADCAST 0x00
static Property i2c_props[] = {
+ DEFINE_PROP_BOOL("reachable", struct I2CSlave, reachable, true),
DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
DEFINE_PROP_END_OF_LIST(),
};
@@ -118,6 +119,9 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
DeviceState *qdev = kid->child;
I2CSlave *candidate = I2C_SLAVE(qdev);
+ if (!candidate->reachable) {
+ continue;
+ }
if ((candidate->address == address) || (bus->broadcast)) {
node = g_malloc(sizeof(struct I2CNode));
node->elt = candidate;
@@ -262,6 +266,7 @@ const VMStateDescription vmstate_i2c_slave = {
.minimum_version_id = 1,
.post_load = i2c_slave_post_load,
.fields = (VMStateField[]) {
+ VMSTATE_BOOL(reachable, I2CSlave),
VMSTATE_UINT8(address, I2CSlave),
VMSTATE_END_OF_LIST()
}
@@ -272,6 +277,7 @@ I2CSlave *i2c_slave_new(const char *name, uint8_t addr)
DeviceState *dev;
dev = qdev_new(name);
+ qdev_prop_set_bit(dev, "reachable", true);
qdev_prop_set_uint8(dev, "address", addr);
return I2C_SLAVE(dev);
}
diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
index 277dd9f2d6..e5ca15e486 100644
--- a/include/hw/i2c/i2c.h
+++ b/include/hw/i2c/i2c.h
@@ -44,6 +44,9 @@ struct I2CSlaveClass {
struct I2CSlave {
DeviceState qdev;
+ /* Whether the i2c child device is reachable from this bus. */
+ bool reachable;
+
/* Remaining fields for internal use by the I2C code. */
uint8_t address;
};
--
2.31.0.208.g409f899ff0-goog
next prev parent reply other threads:[~2021-04-03 22:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-03 22:28 [PATCH 0/2] hw/i2c: Adds pca954x i2c mux switch device Patrick Venture
2021-04-03 22:28 ` Patrick Venture [this message]
2021-04-03 22:28 ` [PATCH 2/2] hw/i2c: add pca954x i2c-mux switch Patrick Venture
2021-04-05 19:58 ` [PATCH 0/2] hw/i2c: Adds pca954x i2c mux switch device Corey Minyard
2021-04-06 15:41 ` Patrick Venture
2021-04-06 15:55 ` Patrick Venture
2021-04-06 18:36 ` Corey Minyard
2021-04-06 22:21 ` Patrick Venture
2021-04-06 23:39 ` Corey Minyard
2021-04-07 23:25 ` Patrick Venture
2021-04-06 16:47 ` Corey Minyard
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=20210403222810.3481372-2-venture@google.com \
--to=venture@google.com \
--cc=cminyard@mvista.com \
--cc=hskinnemoen@google.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=wuhaotsh@google.com \
/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 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.