PCA I2C GPIO expanders
v2 cover PCA I2C GPIO expanders
This patch series contains a set of i2c GPIO expanders, with support for 4, 8, and 16 GPIO connections.
The devices are configured as GPIO *inputs by default, but can have pins configured to be inputs with qmp commands.
For example, the following snippet in a board file for a system, configures a 16 bit pca6416 to have pins 8-11 as inputs, then asserts them.
dev = DEVICE(i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "pca6416", 0x72));
object_property_set_uint(OBJECT(dev), "gpio_config", 0x0F00, &error_abort);
object_property_set_uint(OBJECT(dev), "gpio_input", 0x0F00, &error_abort);We currently use these to test hardware presence and LEDs in simulation.
Thanks
Since v1:
- addressed comments
- fixed typos in commit messages
Titus Rwantare (4):
hw/gpio: add PCA6416 i2c GPIO expander
hw/gpio: add PCA9538 8-bit GPIO expander
hw/gpio: add PCA9536 i2c gpio expander
hw/i2c: add canonical path to i2c event traces
hw/arm/Kconfig | 1 + hw/gpio/Kconfig | 4 + hw/gpio/meson.build | 1 + hw/gpio/pca_i2c_gpio.c | 500 ++++++++++++++++++++++++++++++++ hw/gpio/trace-events | 5 + hw/i2c/core.c | 8 +- hw/i2c/trace-events | 2 +- include/hw/gpio/pca_i2c_gpio.h | 78 +++++ tests/lcitool/libvirt-ci | 2 +- tests/qtest/meson.build | 1 + tests/qtest/pca_i2c_gpio-test.c | 169 +++++++++++ 11 files changed, 766 insertions(+), 5 deletions(-) create mode 100644 hw/gpio/pca_i2c_gpio.c create mode 100644 include/hw/gpio/pca_i2c_gpio.h create mode 100644 tests/qtest/pca_i2c_gpio-test.c
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
PATCH v2 2/4 hw/gpio: add PCA9538 8-bit GPIO expander
The 8-bit expander has different register offsets than the 16-bit one, making them incompatible.
--- hw/gpio/pca_i2c_gpio.c | 94 ++++++++++++++++++++++++++++++++++ include/hw/gpio/pca_i2c_gpio.h | 7 +++ 2 files changed, 101 insertions(+)
hw/gpio/pca_i2c_gpio.c +94 -0
@@ -143,6 +143,41 @@ static uint8_t pca6416_recv(I2CSlave *i2c)return data; } +/* slave to master */ +static uint8_t pca9538_recv (I2CSlave *i2c) +{ +PCAGPIOState *ps =PCA_I2C_GPIO (i2c); +uint8_t data; + +switch (ps->command) { +case PCA9538_INPUT_PORT : + data = ps->curr_input; +break ; + +case PCA9538_OUTPUT_PORT : + data = ps->new_output; +break ; + +case PCA9538_POLARITY_INVERSION_PORT : + data = ps->polarity_inv; +break ; + +case PCA9538_CONFIGURATION_PORT : + data = ps->config; +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: reading from unsupported register 0x%02x" , + __func__, ps->command); + data =0xFF ; +break ; + } + +trace_pca_i2c_recv (DEVICE (ps)->canonical_path, ps->command, data); +return data; +} +/* master to slave */ static int pca6416_send (I2CSlave *i2c,uint8_t data) {
@@ -203,6 +238,47 @@ static int pca6416_send(I2CSlave *i2c, uint8_t data)return 0 ; } +/* master to slave */ +static int pca9538_send (I2CSlave *i2c,uint8_t data) +{ +PCAGPIOState *ps =PCA_I2C_GPIO (i2c); +if (ps->i2c_cmd) { + ps->command = data; + ps->i2c_cmd = false; +return 0 ; + } + +trace_pca_i2c_send (DEVICE (ps)->canonical_path, ps->command, data); + +switch (ps->command) { +case PCA9538_INPUT_PORT : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: writing to read only reg: 0x%02x" , + __func__, ps->command); +break ; +case PCA9538_OUTPUT_PORT : + ps->new_output = data; +break ; + +case PCA9538_POLARITY_INVERSION_PORT : + ps->polarity_inv = data; +break ; + +case PCA9538_CONFIGURATION_PORT : + ps->config = data; +break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: writing to unsupported register\n" , + __func__); +return -1 ; + } + +pca_i2c_update_irqs (ps); + +return 0 ; +} +static int pca_i2c_event (I2CSlave *i2c,enum i2c_event event) {PCAGPIOState *ps =PCA_I2C_GPIO (i2c);
@@ -337,6 +413,19 @@ static void pca6416_gpio_class_init(ObjectClass *klass, void *data) k->send = pca6416_send; } +static void pca9538_gpio_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); +PCAGPIOClass *pc =PCA_I2C_GPIO_CLASS (klass); + + dc->desc ="PCA9538 8-bit I/O expander" ; + pc->num_pins =PCA9538_NUM_PINS ; + + k->recv = pca9538_recv; + k->send = pca9538_send; +} +static void pca_i2c_gpio_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -383,6 +472,11 @@ static const TypeInfo pca_gpio_types[] = { .parent = TYPE_PCA_I2C_GPIO, .class_init = pca6416_gpio_class_init, }, + { + .name = TYPE_PCA9538_GPIO, + .parent = TYPE_PCA_I2C_GPIO, + .class_init = pca9538_gpio_class_init, + }, };DEFINE_TYPES (pca_gpio_types);
include/hw/gpio/pca_i2c_gpio.h +7 -0
@@ -19,6 +19,7 @@#define PCA_I2C_MAX_PINS 16#define PCA6416_NUM_PINS 16 +#define PCA9538_NUM_PINS 8 typedef struct PCAGPIOClass { I2CSlaveClass parent;
@@ -62,8 +63,14 @@ OBJECT_DECLARE_TYPE(PCAGPIOState, PCAGPIOClass, PCA_I2C_GPIO)#define PCA6416_CONFIGURATION_PORT_0 0x06/* read/write */ #define PCA6416_CONFIGURATION_PORT_1 0x07/* read/write */ +#define PCA9538_INPUT_PORT 0x00/* read */ +#define PCA9538_OUTPUT_PORT 0x01/* read/write */ +#define PCA9538_POLARITY_INVERSION_PORT 0x02/* read/write */ +#define PCA9538_CONFIGURATION_PORT 0x03/* read/write */ +#define PCA_I2C_CONFIG_DEFAULT 0#define TYPE_PCA6416_GPIO "pca6416" +#define TYPE_PCA9538_GPIO "pca9538"#endif
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
PATCH v2 3/4 hw/gpio: add PCA9536 i2c gpio expander
In reply to Titus RwantareThis device has the same register layout as the pca9538, but 4 fewer gpio pins. This commit lowers the number of pins initialised, and reuses the pca9538 logic.
--- hw/gpio/pca_i2c_gpio.c | 18 ++++++++++++++++++ include/hw/gpio/pca_i2c_gpio.h | 2 ++ 2 files changed, 20 insertions(+)
hw/gpio/pca_i2c_gpio.c +18 -0
@@ -426,6 +426,19 @@ static void pca9538_gpio_class_init(ObjectClass *klass, void *data) k->send = pca9538_send; } +static void pca9536_gpio_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); +PCAGPIOClass *pc =PCA_I2C_GPIO_CLASS (klass); + + dc->desc ="PCA9536 4-bit I/O expander" ; + pc->num_pins =PCA9536_NUM_PINS ; + + k->recv = pca9538_recv; + k->send = pca9538_send; +} +static void pca_i2c_gpio_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -477,6 +490,11 @@ static const TypeInfo pca_gpio_types[] = { .parent = TYPE_PCA_I2C_GPIO, .class_init = pca9538_gpio_class_init, }, + { + .name = TYPE_PCA9536_GPIO, + .parent = TYPE_PCA_I2C_GPIO, + .class_init = pca9536_gpio_class_init, + }, };DEFINE_TYPES (pca_gpio_types);
include/hw/gpio/pca_i2c_gpio.h +2 -0
@@ -20,6 +20,7 @@#define PCA_I2C_MAX_PINS 16#define PCA6416_NUM_PINS 16#define PCA9538_NUM_PINS 8 +#define PCA9536_NUM_PINS 4 typedef struct PCAGPIOClass { I2CSlaveClass parent;
@@ -72,5 +73,6 @@ OBJECT_DECLARE_TYPE(PCAGPIOState, PCAGPIOClass, PCA_I2C_GPIO)#define TYPE_PCA6416_GPIO "pca6416"#define TYPE_PCA9538_GPIO "pca9538" +#define TYPE_PCA9536_GPIO "pca9536"#endif
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
PATCH v2 4/4 hw/i2c: add canonical path to i2c event traces
In reply to Titus Rwantare--- hw/i2c/core.c | 8 +++++--- hw/i2c/trace-events | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-)
hw/i2c/core.c +5 -3
@@ -161,7 +161,8 @@ static int i2c_do_start_transfer(I2CBus *bus, uint8_t address,start condition. */ if (sc->event) { -trace_i2c_event (event ==I2C_START_SEND ?"start" :"start_async" , +trace_i2c_event (DEVICE (s)->canonical_path, + event ==I2C_START_SEND ?"start" :"start_async" , s->address); rv = sc->event (s, event);if (rv && !bus->broadcast) {
@@ -227,7 +228,7 @@ void i2c_end_transfer(I2CBus *bus)I2CSlave *s = node->elt; sc =I2C_SLAVE_GET_CLASS (s);if (sc->event) { -trace_i2c_event ("finish" , s->address); +trace_i2c_event (DEVICE (s)->canonical_path,"finish" , s->address); sc->event (s,I2C_FINISH ); }QLIST_REMOVE (node, next);
@@ -314,7 +315,8 @@ void i2c_nack(I2CBus *bus) QLIST_FOREACH(node, &bus->current_devs, next) { sc =I2C_SLAVE_GET_CLASS (node->elt);if (sc->event) { -trace_i2c_event ("nack" , node->elt->address); +trace_i2c_event (DEVICE (node->elt)->canonical_path, +"nack" , node->elt->address); sc->event (node->elt,I2C_NACK ); } }
hw/i2c/trace-events +1 -1
@@ -9,7 +9,7 @@ bitbang_i2c_data(unsigned dat, unsigned clk, unsigned old_out, unsigned new_out) # core.c -i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)" +i2c_event(const char *id, const char *event, uint8_t address) "%s: %s(addr:0x%02x)" i2c_send(uint8_t address, uint8_t data) "send(addr:0x%02x) data:0x%02x" i2c_send_async(uint8_t address, uint8_t data) "send_async(addr:0x%02x) data:0x%02x" i2c_recv(uint8_t address, uint8_t data) "recv(addr:0x%02x) data:0x%02x"
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
PATCH v2 1/4 hw/gpio: add PCA6416 i2c GPIO expander
In reply to Titus RwantareThe PCA6416 is an i2c device with 16 GPIOs.
--- hw/arm/Kconfig | 1 + hw/gpio/Kconfig | 4 + hw/gpio/meson.build | 1 + hw/gpio/pca_i2c_gpio.c | 388 ++++++++++++++++++++++++++++++++ hw/gpio/trace-events | 5 + include/hw/gpio/pca_i2c_gpio.h | 69 ++++++ tests/lcitool/libvirt-ci | 2 +- tests/qtest/meson.build | 1 + tests/qtest/pca_i2c_gpio-test.c | 169 ++++++++++++++ 9 files changed, 639 insertions(+), 1 deletion(-) create mode 100644 hw/gpio/pca_i2c_gpio.c create mode 100644 include/hw/gpio/pca_i2c_gpio.h create mode 100644 tests/qtest/pca_i2c_gpio-test.c
hw/arm/Kconfig +1 -0
@@ -418,6 +418,7 @@ config NPCM7XX select SSI select UNIMP select PCA954X + select PCA_I2C_GPIO config FSL_IMX25 bool
hw/gpio/Kconfig +4 -0
@@ -16,3 +16,7 @@ config GPIO_PWR config SIFIVE_GPIO bool + +config PCA_I2C_GPIO + bool + depends on I2C
hw/gpio/meson.build +1 -0
@@ -12,3 +12,4 @@ softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) softmmu_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) +softmmu_ss.add(when: 'CONFIG_PCA_I2C_GPIO', if_true: files('pca_i2c_gpio.c'))
hw/gpio/pca_i2c_gpio.c new file +388 -0
388 lines not on this page · raw message
hw/gpio/trace-events +5 -0
@@ -31,3 +31,8 @@ sifive_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " val # aspeed_gpio.c aspeed_gpio_read(uint64_t offset, uint64_t value) "offset: 0x%" PRIx64 " value 0x%" PRIx64 aspeed_gpio_write(uint64_t offset, uint64_t value) "offset: 0x%" PRIx64 " value 0x%" PRIx64 + +# pca_i2c_gpio.c +pca_i2c_event(const char *id, const char *event) "%s: %s" +pca_i2c_recv(const char *id, uint8_t cmd, uint8_t data) "%s cmd: 0x%" PRIx8 " data 0x%" PRIx8 +pca_i2c_send(const char *id, uint8_t cmd, uint8_t data) "%s cmd: 0x%" PRIx8 " data 0x%" PRIx8
include/hw/gpio/pca_i2c_gpio.h new file +69 -0
69 lines not on this page · raw message
tests/lcitool/libvirt-ci +1 -1
@@ -1 +1 @@ -Subproject commit 319a534c220f53fc8670254cac25d6f662c82112 +Subproject commit e3eb28cf2e17fbcf7fe7e19505ee432b8ec5bbb5
tests/qtest/meson.build +1 -0
@@ -241,6 +241,7 @@ qos_test_ss.add( 'ne2000-test.c', 'tulip-test.c', 'nvme-test.c', + 'pca_i2c_gpio-test.c', 'pca9552-test.c', 'pci-test.c', 'pcnet-test.c',
tests/qtest/pca_i2c_gpio-test.c new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
Re: [PATCH v2 1/4] hw/gpio: add PCA6416 i2c GPIO expander
Hi Titus,
Quoted 24 lines · Titus Rwantare
The PCA6416 is an i2c device with 16 GPIOs.
Reviewed-by Hao Wu <[email protected]>Signed-off-by Titus Rwantare <[email protected]>--- hw/arm/Kconfig | 1 + hw/gpio/Kconfig | 4 + hw/gpio/meson.build | 1 + hw/gpio/pca_i2c_gpio.c | 388 ++++++++++++++++++++++++++++++++ hw/gpio/trace-events | 5 + include/hw/gpio/pca_i2c_gpio.h | 69 ++++++ tests/lcitool/libvirt-ci | 2 +- tests/qtest/meson.build | 1 + tests/qtest/pca_i2c_gpio-test.c | 169 ++++++++++++++ 9 files changed, 639 insertions(+), 1 deletion(-)create mode 100644
hw/gpio/pca_i2c_gpio.ccreate mode 100644include/hw/gpio/pca_i2c_gpio.hcreate mode 100644tests/qtest/pca_i2c_gpio-test.chw/arm/Kconfig +0
-0
hw/arm/Kconfig config NPCM7XX · line 421
Quoted 4 lines
hw/arm/Kconfig +1
-0@@ -418,6 +418,7 @@ config NPCM7XX select SSI select UNIMP select PCA954X + select PCA_I2C_GPIO
Shouldn't this be s/select/imply/? See docs/devel/kconfig.rst:
Boards specify their constituent devices using ``imply`` and ``select`` directives. A device should be listed under ``select`` if the board cannot be started at all without it. It should be listed under ``imply`` if (depending on the QEMU command line) the board may or may not be started without it. Boards also default to false; they are enabled by the ``default-configs/*.mak`` for the target they apply to.
Better to split this as another "hw/arm: Allow NPCM7xx machines to use the PCA6416 i2c GPIO expander" patch.
Quoted 48 lines
hw/arm/Kconfig +47
-0+/* + * compare new_output to curr_output and update irq to match new_output + * + * The Input port registers (registers 0 and 1) reflect the incoming logic + * levels of the pins, regardless of whether the pin is defined as an input or + * an output by the Configuration register. + */ +static void pca_i2c_update_irqs(PCAGPIOState *ps) +{ + PCAGPIOClass *pc = PCA_I2C_GPIO_GET_CLASS(ps); + uint16_t out_diff = ps->new_output ^ ps->curr_output; + uint16_t in_diff = ps->new_input ^ ps->curr_input; + uint16_t mask, pin_i; + + if (in_diff || out_diff) { + for (int i = 0; i < pc->num_pins; i++) { + mask = BIT(i); + /* pin must be configured as an output to be set here */ + if (out_diff & ~ps->config & mask) { + pin_i = mask & ps->new_output; + qemu_set_irq(ps->output[i], pin_i > 0); + ps->curr_output &= ~mask; + ps->curr_output |= pin_i; + } + + if (in_diff & mask) { + ps->curr_input &= ~mask; + ps->curr_input |= mask & ps->new_input; + } + } + /* make diff = 0 */ + ps->new_input = ps->curr_input; + } +} +static void pca_i2c_enter_reset(Object *obj, ResetType type) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(obj); + PCAGPIOClass *pc = PCA_I2C_GPIO_GET_CLASS(obj); + + for (int i = 0; i < pc->num_pins; i++) { + qemu_irq_lower(ps->output[i]); + } + + ps->polarity_inv = 0; + ps->config = 0; + ps->curr_input = 0; + ps->curr_output = 0;
hw/arm/Kconfig config NPCM7XX
Quoted 10 lines
hw/arm/Kconfig +10
-0+ ps->new_input = 0; + ps->new_output = 0; + ps->command = 0; +} + +static void pca_i2c_realize(DeviceState *dev, Error **errp) +{ + PCAGPIOState *ps = PCA_I2C_GPIO(dev); + pca_i2c_update_irqs(ps); +}
pca_i2c_realize() occurs once before the reset() handler, so it seems redundant. We can probably remove it.
Quoted 11 lines
hw/arm/Kconfig +11
-0+static void pca_i2c_gpio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); + + dc->realize = pca_i2c_realize; + dc->vmsd = &vmstate_pca_i2c_gpio; + rc->phases.enter = pca_i2c_enter_reset; + k->event = pca_i2c_event; +}
hw/arm/Kconfig
Quoted 10 lines
hw/arm/Kconfig +9
-0+static const TypeInfo pca_gpio_types[] = { + { + .name = TYPE_PCA_I2C_GPIO, + .parent = TYPE_I2C_SLAVE, + .instance_size = sizeof(PCAGPIOState), + .instance_init = pca_i2c_gpio_init, + .class_size = sizeof(PCAGPIOClass), + .class_init = pca_i2c_gpio_class_init, + .abstract = true,
Per CODING_STYLE this should be indented +4 spaces.
Quoted 7 lines
hw/arm/Kconfig +7
-0+ }, + { + .name = TYPE_PCA6416_GPIO, + .parent = TYPE_PCA_I2C_GPIO, + .class_init = pca6416_gpio_class_init, + }, +};
hw/arm/Kconfig
Quoted 10 lines
hw/arm/Kconfig +8
-0+#define PCA6416_INPUT_PORT_0 0x00 /* read */ +#define PCA6416_INPUT_PORT_1 0x01 /* read */ +#define PCA6416_OUTPUT_PORT_0 0x02 /* read/write */ +#define PCA6416_OUTPUT_PORT_1 0x03 /* read/write */ +#define PCA6416_POLARITY_INVERSION_PORT_0 0x04 /* read/write */ +#define PCA6416_POLARITY_INVERSION_PORT_1 0x05 /* read/write */ +#define PCA6416_CONFIGURATION_PORT_0 0x06 /* read/write */ +#define PCA6416_CONFIGURATION_PORT_1 0x07 /* read/write */
IIUC the registers are 16-bit but the I2CSlaveClass API forces you to process 8-bit at a time. Possible simpler to use the extract / deposit API:
#define PCA6416_INPUT_PORT 0x00 /* read */
#define PCA6416_OUTPUT_PORT 0x02 /* read/write */
static uint8_t pca6416_recv(I2CSlave *i2c)
{
PCAGPIOState *ps = PCA_I2C_GPIO(i2c);
unsigned shift = (ps->command) & 1 ? 8 : 0;
uint8_t data;
switch (ps->command) {
case PCA6416_INPUT_PORT:
data = extract16(ps->curr_input, shift, 8);
break;
static int pca6416_send(I2CSlave *i2c, uint8_t data)
{
PCAGPIOState *ps = PCA_I2C_GPIO(i2c);
unsigned shift = (ps->command) & 1 ? 0 : 8;
...
switch (ps->command) {
...
case PCA6416_OUTPUT_PORT:
ps->new_output = deposit32(ps->new_output, shift 8,
extract16(data, shift, 8));
break;Regards,
Phil.
Re: [PATCH v2 2/4] hw/gpio: add PCA9538 8-bit GPIO expander
In reply to Titus RwantareQuoted 2 lines · Titus Rwantare
The 8-bit expander has different register offsets than the 16-bit one, making them incompatible.
Following extract/deposit API suggestion on previous patch, an alternatively is to use PCAGPIOClass::input_port/output_port/... offset fields.
Quoted 21 lines
Reviewed-by Hao Wu <[email protected]>Signed-off-by Titus Rwantare <[email protected]>--- hw/gpio/pca_i2c_gpio.c | 94 ++++++++++++++++++++++++++++++++++ include/hw/gpio/pca_i2c_gpio.h | 7 +++ 2 files changed, 101 insertions(+)include/hw/gpio/pca_i2c_gpio.h +1
-0@@ -19,6 +19,7 @@#define PCA_I2C_MAX_PINS 16#define PCA6416_NUM_PINS 16 +#define PCA9538_NUM_PINS 8 typedef struct PCAGPIOClass { I2CSlaveClass parent;
include/hw/gpio/pca_i2c_gpio.h OBJECT_DECLARE_TYPE(PCAGPIOState, PCAGPIOClass, PCA_I2C_GPIO) · line 69
Quoted 7 lines
include/hw/gpio/pca_i2c_gpio.h +4
-0@@ -62,8 +63,14 @@ OBJECT_DECLARE_TYPE(PCAGPIOState, PCAGPIOClass, PCA_I2C_GPIO)#define PCA6416_CONFIGURATION_PORT_0 0x06/* read/write */ #define PCA6416_CONFIGURATION_PORT_1 0x07/* read/write */ +#define PCA9538_INPUT_PORT 0x00/* read */ +#define PCA9538_OUTPUT_PORT 0x01/* read/write */ +#define PCA9538_POLARITY_INVERSION_PORT 0x02/* read/write */ +#define PCA9538_CONFIGURATION_PORT 0x03/* read/write */
Something like this maybe:
static uint8_t pca_i2c_gpio_recv(I2CSlave *i2c)
{
PCAGPIOState *ps = PCA_I2C_GPIO(i2c);
PCAGPIOClass *pc = PCA_I2C_GPIO_GET_CLASS(i2c);
unsigned shift = (ps->command) & pc->shift ? 8 : 0;
uint8_t data;
if (ps->command == pc->input_port) {
data = extract16(ps->curr_input, shift, 8);
} else if (ps->command == pc->output_port) {
data = extract16(ps->curr_input, shift, 8);
} else if (...) {Maybe I'm over-engineering :)
Re: [PATCH v2 3/4] hw/gpio: add PCA9536 i2c gpio expander
In reply to Titus RwantareQuoted 13 lines · Titus Rwantare
This device has the same register layout as the pca9538, but 4 fewer gpio pins. This commit lowers the number of pins initialised, and reuses the pca9538 logic.
Reviewed-by Hao Wu <[email protected]>Signed-off-by Titus Rwantare <[email protected]>--- hw/gpio/pca_i2c_gpio.c | 18 ++++++++++++++++++ include/hw/gpio/pca_i2c_gpio.h | 2 ++ 2 files changed, 20 insertions(+)hw/gpio/pca_i2c_gpio.c +1
-0+static void pca9536_gpio_class_init (ObjectClass *klass,void *data)
hw/gpio/pca_i2c_gpio.c static void pca9538_gpio_class_init(ObjectClass *klass, void *data) · line 439
Quoted 10 lines
hw/gpio/pca_i2c_gpio.c +10
-0+{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); +PCAGPIOClass *pc =PCA_I2C_GPIO_CLASS (klass); + + dc->desc ="PCA9536 4-bit I/O expander" ; + pc->num_pins =PCA9536_NUM_PINS ; + + k->recv = pca9538_recv; + k->send = pca9538_send;
Can we rename as pca953x_recv() / pca953x_send() in previous patch?
Otherwise,
Re: [PATCH v2 4/4] hw/i2c: add canonical path to i2c event traces
In reply to Titus RwantareQuoted 5 lines · Titus Rwantare
Signed-off-by Titus Rwantare <[email protected]>--- hw/i2c/core.c | 8 +++++--- hw/i2c/trace-events | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-)