[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/26] hw/i2c: flatten pca954x mux device
From: |
Peter Maydell |
Subject: |
[PULL 04/26] hw/i2c: flatten pca954x mux device |
Date: |
Wed, 2 Mar 2022 20:52:08 +0000 |
From: Patrick Venture <venture@google.com>
Previously this device created N subdevices which each owned an i2c bus.
Now this device simply owns the N i2c busses directly.
Tested: Verified devices behind mux are still accessible via qmp and i2c
from within an arm32 SoC.
Reviewed-by: Hao Wu <wuhaotsh@google.com>
Signed-off-by: Patrick Venture <venture@google.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20220202164533.1283668-1-venture@google.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/i2c/i2c_mux_pca954x.c | 77 +++++++---------------------------------
1 file changed, 13 insertions(+), 64 deletions(-)
diff --git a/hw/i2c/i2c_mux_pca954x.c b/hw/i2c/i2c_mux_pca954x.c
index 847c59921cf..a9517b612ae 100644
--- a/hw/i2c/i2c_mux_pca954x.c
+++ b/hw/i2c/i2c_mux_pca954x.c
@@ -30,24 +30,6 @@
#define PCA9548_CHANNEL_COUNT 8
#define PCA9546_CHANNEL_COUNT 4
-/*
- * struct Pca954xChannel - The i2c mux device will have N of these states
- * that own the i2c channel bus.
- * @bus: The owned channel bus.
- * @enabled: Is this channel active?
- */
-typedef struct Pca954xChannel {
- SysBusDevice parent;
-
- I2CBus *bus;
-
- bool enabled;
-} Pca954xChannel;
-
-#define TYPE_PCA954X_CHANNEL "pca954x-channel"
-#define PCA954X_CHANNEL(obj) \
- OBJECT_CHECK(Pca954xChannel, (obj), TYPE_PCA954X_CHANNEL)
-
/*
* struct Pca954xState - The pca954x state object.
* @control: The value written to the mux control.
@@ -59,8 +41,8 @@ typedef struct Pca954xState {
uint8_t control;
- /* The channel i2c buses. */
- Pca954xChannel channel[PCA9548_CHANNEL_COUNT];
+ bool enabled[PCA9548_CHANNEL_COUNT];
+ I2CBus *bus[PCA9548_CHANNEL_COUNT];
} Pca954xState;
/*
@@ -98,11 +80,11 @@ static bool pca954x_match(I2CSlave *candidate, uint8_t
address,
}
for (i = 0; i < mc->nchans; i++) {
- if (!mux->channel[i].enabled) {
+ if (!mux->enabled[i]) {
continue;
}
- if (i2c_scan_bus(mux->channel[i].bus, address, broadcast,
+ if (i2c_scan_bus(mux->bus[i], address, broadcast,
current_devs)) {
if (!broadcast) {
return true;
@@ -125,9 +107,9 @@ static void pca954x_enable_channel(Pca954xState *s, uint8_t
enable_mask)
*/
for (i = 0; i < mc->nchans; i++) {
if (enable_mask & (1 << i)) {
- s->channel[i].enabled = true;
+ s->enabled[i] = true;
} else {
- s->channel[i].enabled = false;
+ s->enabled[i] = false;
}
}
}
@@ -184,23 +166,7 @@ I2CBus *pca954x_i2c_get_bus(I2CSlave *mux, uint8_t channel)
Pca954xState *pca954x = PCA954X(mux);
g_assert(channel < pc->nchans);
- return I2C_BUS(qdev_get_child_bus(DEVICE(&pca954x->channel[channel]),
- "i2c-bus"));
-}
-
-static void pca954x_channel_init(Object *obj)
-{
- Pca954xChannel *s = PCA954X_CHANNEL(obj);
- s->bus = i2c_init_bus(DEVICE(s), "i2c-bus");
-
- /* Start all channels as disabled. */
- s->enabled = false;
-}
-
-static void pca954x_channel_class_init(ObjectClass *klass, void *data)
-{
- DeviceClass *dc = DEVICE_CLASS(klass);
- dc->desc = "Pca954x Channel";
+ return pca954x->bus[channel];
}
static void pca9546_class_init(ObjectClass *klass, void *data)
@@ -215,28 +181,19 @@ static void pca9548_class_init(ObjectClass *klass, void
*data)
s->nchans = PCA9548_CHANNEL_COUNT;
}
-static void pca954x_realize(DeviceState *dev, Error **errp)
-{
- Pca954xState *s = PCA954X(dev);
- Pca954xClass *c = PCA954X_GET_CLASS(s);
- int i;
-
- /* SMBus modules. Cannot fail. */
- for (i = 0; i < c->nchans; i++) {
- sysbus_realize(SYS_BUS_DEVICE(&s->channel[i]), &error_abort);
- }
-}
-
static void pca954x_init(Object *obj)
{
Pca954xState *s = PCA954X(obj);
Pca954xClass *c = PCA954X_GET_CLASS(obj);
int i;
- /* Only initialize the children we expect. */
+ /* SMBus modules. Cannot fail. */
for (i = 0; i < c->nchans; i++) {
- object_initialize_child(obj, "channel[*]", &s->channel[i],
- TYPE_PCA954X_CHANNEL);
+ g_autofree gchar *bus_name = g_strdup_printf("i2c.%d", i);
+
+ /* start all channels as disabled. */
+ s->enabled[i] = false;
+ s->bus[i] = i2c_init_bus(DEVICE(s), bus_name);
}
}
@@ -252,7 +209,6 @@ static void pca954x_class_init(ObjectClass *klass, void
*data)
rc->phases.enter = pca954x_enter_reset;
dc->desc = "Pca954x i2c-mux";
- dc->realize = pca954x_realize;
k->write_data = pca954x_write_data;
k->receive_byte = pca954x_read_byte;
@@ -278,13 +234,6 @@ static const TypeInfo pca954x_info[] = {
.parent = TYPE_PCA954X,
.class_init = pca9548_class_init,
},
- {
- .name = TYPE_PCA954X_CHANNEL,
- .parent = TYPE_SYS_BUS_DEVICE,
- .class_init = pca954x_channel_class_init,
- .instance_size = sizeof(Pca954xChannel),
- .instance_init = pca954x_channel_init,
- }
};
DEFINE_TYPES(pca954x_info)
--
2.25.1
- [PULL 02/26] hw/arm/mps2-tz.c: Update AN547 documentation URL, (continued)
- [PULL 02/26] hw/arm/mps2-tz.c: Update AN547 documentation URL, Peter Maydell, 2022/03/02
- [PULL 03/26] hw/input/tsc210x: Don't abort on bad SPI word widths, Peter Maydell, 2022/03/02
- [PULL 07/26] tests/qtest: add qtests for npcm7xx sdhci, Peter Maydell, 2022/03/02
- [PULL 08/26] hw/registerfields: Add FIELD_SEX<N> and FIELD_SDP<N>, Peter Maydell, 2022/03/02
- [PULL 09/26] target/arm: Set TCR_EL1.TSZ for user-only, Peter Maydell, 2022/03/02
- [PULL 10/26] target/arm: Fault on invalid TCR_ELx.TxSZ, Peter Maydell, 2022/03/02
- [PULL 12/26] target/arm: Pass outputsize down to check_s2_mmu_setup, Peter Maydell, 2022/03/02
- [PULL 14/26] target/arm: Honor TCR_ELx.{I}PS, Peter Maydell, 2022/03/02
- [PULL 11/26] target/arm: Move arm_pamax out of line, Peter Maydell, 2022/03/02
- [PULL 17/26] target/arm: Implement FEAT_LPA, Peter Maydell, 2022/03/02
- [PULL 04/26] hw/i2c: flatten pca954x mux device,
Peter Maydell <=
- [PULL 06/26] target/arm: Fix early free of TCG temp in handle_simd_shift_fpint_conv(), Peter Maydell, 2022/03/02
- [PULL 01/26] mps3-an547: Add missing user ahb interfaces, Peter Maydell, 2022/03/02
- [PULL 05/26] target/arm: Support PSCI 1.1 and SMCCC 1.0, Peter Maydell, 2022/03/02
- [PULL 15/26] target/arm: Prepare DBGBVR and DBGWVR for FEAT_LVA, Peter Maydell, 2022/03/02
- [PULL 18/26] target/arm: Extend arm_fi_to_lfsc to level -1, Peter Maydell, 2022/03/02
- [PULL 22/26] target/arm: Advertise all page sizes for -cpu max, Peter Maydell, 2022/03/02
- [PULL 23/26] target/arm: Implement FEAT_LPA2, Peter Maydell, 2022/03/02
- [PULL 25/26] ui/cocoa.m: Fix updateUIInfo threading issues, Peter Maydell, 2022/03/02
- [PULL 16/26] target/arm: Implement FEAT_LVA, Peter Maydell, 2022/03/02
- [PULL 19/26] target/arm: Introduce tlbi_aa64_get_range, Peter Maydell, 2022/03/02