On 8/2/23 23:43, Titus Rwantare wrote:
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.
Reviewed-by: Hao Wu <wuhao...@google.com>
Signed-off-by: Titus Rwantare <tit...@google.com>
---
hw/gpio/pca_i2c_gpio.c | 94 ++++++++++++++++++++++++++++++++++
include/hw/gpio/pca_i2c_gpio.h | 7 +++
2 files changed, 101 insertions(+)
diff --git a/include/hw/gpio/pca_i2c_gpio.h b/include/hw/gpio/pca_i2c_gpio.h
index 99322959e1..3ab7d19a97 100644
--- a/include/hw/gpio/pca_i2c_gpio.h
+++ b/include/hw/gpio/pca_i2c_gpio.h
@@ -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 */
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 :)