qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 2/4] hw/gpio: add PCA9538 8-bit GPIO expander


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v2 2/4] hw/gpio: add PCA9538 8-bit GPIO expander
Date: Thu, 9 Feb 2023 08:57:32 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2

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 <wuhaotsh@google.com>
Signed-off-by: Titus Rwantare <titusr@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 :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]