Skip to contentSkip to conversation

adp5588-keys refactor and fw properties support

PATCH In review Nuno Sá 4 participants 17 messages Aug 29, 2022 – Aug 31, 2022

Subsystems (5)
lore
Share & tools
lore

Nuno Sá

author
#0 lore raw

v4 cover adp5588-keys refactor and fw properties support

The main goal of this patchset is to remove platform data and replace it by firmware properties. Original discussion in [1].

While in here, some refactor was done to the driver. The most noticeable one is to replace the GPIs events handling by irqchip support so that this gpi keys can be "consumed" by the gpio-keys driver (also as suggested in [1]). With this, the gpio-adp5588 can be removed. This change comes first so that we can already remove some platform data variables making it easier to completly replace it by firmware properties further down in the series.

As there's no users of the platform data, I just replace it in a single patch as there's no point in having support for both (even though it might be harder to review the patch as-is).

Special note to the gpio-adp5588 driver removal. I'm aware of some changes to the driver in [2]. These changes are in the gpio tree and this patchset is naturally based on the input tree which means that patch 2 will not apply. So, I'm not really sure how to handle this. I guess in this case the conflict is easy to handle :) but just let me know on how to proceed in here if there's anything for me to do.

[1]: https://lore.kernel.org/linux-input/[email protected]/
[2]: https://lore.kernel.org/linux-gpio/[email protected]/

v2 changes:

[1/10]
* Turn hwirq signed so we can compare < 0;
* Replace WARN_ON with dev_warn();
* Do not set of_node on gpiochip;
* Moved to use a const irqchip within the gpiochip;
* Set default handler to 'handle_bad_irq()' and change it
in irq_set_type;

[4/10]
* Dropped "-keys" from compatible and added vendor prefix;
* Fix -Wformat complains;
* Don't use abbrev in comments (fw -> Firmware).

[5/10]
* Be consistent on $refs;
* Drop "-keys" from compatible.

[7/10]
* Include bits.h;
* Use GENMASK();
* Use BIT() in KP_SEL();
* Reflect code changes in the commit message.

[9/10]
* One line for regulator_disable action.

v3 changes:

[1/10]
* Use 'irqd_to_hwirq()' helper;
* Use INVALID_HWIRQ to signal hwirq not found;
* Just compare irq against 0 in 'irq_find_mapping()';
* Renamed irq_data *desc to *irqd to avoid confusion.

[5/10]
* Dropped the -keys suffix on the filename;
* Compatible enum in alphabetical order;
* Improved 'adi,unlock-keys' description;
* 4 spaces indentation for dts example;
* Renamed device node to a generic name and fixed the
compatible property in the example.

v4 changes:

[1/10]
* Use local 'INVALID_HWIRQ' macro;
* Explicitly define a local variable to hold 'irqd_to_hwirq()'

Nuno Sá (10):
input: keyboard: adp5588-keys: support gpi key events as 'gpio keys'
gpio: gpio-adp5588: drop the driver
input: keyboard: adp5588-keys: bail out on returned error
input: keyboard: adp5588-keys: add support for fw properties
dt-bindings: input: adp5588: add bindings
input: keyboard: adp5588-keys: do not check for irq presence
input: keyboard: adp5588-keys: fix coding style warnings
input: keyboard: adp5588-keys: add optional reset gpio
input: keyboard: adp5588-keys: add regulator support
input: keyboard: adp5588-keys: Use new PM macros

 .../bindings/input/adi,adp5588.yaml           | 111 +++
 MAINTAINERS                                   |   2 +-
 drivers/gpio/Kconfig                          |  14 -
 drivers/gpio/Makefile                         |   1 -
 drivers/gpio/gpio-adp5588.c                   | 446 -----------
 drivers/input/keyboard/Kconfig                |   3 +
 drivers/input/keyboard/adp5588-keys.c         | 724 ++++++++++++------
 include/linux/platform_data/adp5588.h         | 171 -----
 8 files changed, 594 insertions(+), 878 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/adi,adp5588.yaml
 delete mode 100644 drivers/gpio/gpio-adp5588.c
 delete mode 100644 include/linux/platform_data/adp5588.h
Signature · 1 line
2.37.2
author
#1 lore raw

PATCH v4 1/10 input: keyboard: adp5588-keys: support gpi key events as 'gpio keys'

This change replaces the support for GPIs as key event generators. Instead of reporting the events directly, we add a gpio based irqchip so that these events can be consumed by keys defined in the gpio-keys driver (as it's goal is indeed for keys on GPIOs capable of generating interrupts). With this, the gpio-adp5588 driver can also be dropped.

The basic idea is that all the pins that are not being used as part of the keymap matrix can be possibly requested as GPIOs by gpio-keys (it's also fine to use these pins as plain interrupts though that's not really the point).

Since the gpiochip now also has irqchip capabilities, we should only remove it after we free the device interrupt (otherwise we could, in theory, be handling GPIs interrupts while the gpiochip is concurrently removed). Thus the call 'adp5588_gpio_add()' is moved and since the setup phase also needs to come before making the gpios visible, we also need to move 'adp5588_setup()'.

While at it, always select GPIOLIB so that we don't need to use #ifdef guards.

---
 drivers/input/keyboard/Kconfig        |   2 +
 drivers/input/keyboard/adp5588-keys.c | 274 +++++++++++++-------------
 include/linux/platform_data/adp5588.h |   2 -
 3 files changed, 144 insertions(+), 134 deletions(-)
drivers/input/keyboard/Kconfig +2 -0
index a20ee693b22b..ca5cd5e520a7 100644
@@ -40,6 +40,8 @@ config KEYBOARD_ADP5520
 config KEYBOARD_ADP5588
 	tristate "ADP5588/87 I2C QWERTY Keypad and IO Expander"
 	depends on I2C
+	select GPIOLIB
+	select GPIOLIB_IRQCHIP
 	help
 	  Say Y here if you want to use a ADP5588/87 attached to your
 	  system I2C bus.
drivers/input/keyboard/adp5588-keys.c +142 -132

391 lines not on this page · raw message

include/linux/platform_data/adp5588.h +0 -2
index 6d3f7d911a92..82170ec8c266 100644
@@ -147,8 +147,6 @@ struct adp5588_kpad_platform_data {
 	unsigned en_keylock:1;		/* Enable Key Lock feature */
 	unsigned short unlock_key1;	/* Unlock Key 1 */
 	unsigned short unlock_key2;	/* Unlock Key 2 */
-	const struct adp5588_gpi_map *gpimap;
-	unsigned short gpimapsize;
 	const struct adp5588_gpio_platform_data *gpio_data;
 };
 
Signature · 1 line
2.37.2
Reviewed-by on v4 1/10
#2 lore raw

Re: [PATCH v4 01/10] input: keyboard: adp5588-keys: support gpi key events as 'gpio keys'

Quoted 19 lines · Nuno Sá

This change replaces the support for GPIs as key event generators. Instead of reporting the events directly, we add a gpio based irqchip so that these events can be consumed by keys defined in the gpio-keys driver (as it's goal is indeed for keys on GPIOs capable of generating interrupts). With this, the gpio-adp5588 driver can also be dropped.

The basic idea is that all the pins that are not being used as part of the keymap matrix can be possibly requested as GPIOs by gpio-keys (it's also fine to use these pins as plain interrupts though that's not really the point).

Since the gpiochip now also has irqchip capabilities, we should only remove it after we free the device interrupt (otherwise we could, in theory, be handling GPIs interrupts while the gpiochip is concurrently removed). Thus the call 'adp5588_gpio_add()' is moved and since the setup phase also needs to come before making the gpios visible, we also need to move 'adp5588_setup()'.

Quoted 2 lines

While at it, always select GPIOLIB so that we don't need to use #ifdef guards.

Fine with me from GPIO chip (incl. IRQ one) perspective,

Quoted 446 lines
---
 drivers/input/keyboard/Kconfig        |   2 +
 drivers/input/keyboard/adp5588-keys.c | 274 +++++++++++++-------------
 include/linux/platform_data/adp5588.h |   2 -
 3 files changed, 144 insertions(+), 134 deletions(-)
drivers/input/keyboard/Kconfig +2 -0
index a20ee693b22b..ca5cd5e520a7 100644
@@ -40,6 +40,8 @@ config KEYBOARD_ADP5520
 config KEYBOARD_ADP5588
        tristate "ADP5588/87 I2C QWERTY Keypad and IO Expander"
        depends on I2C
+       select GPIOLIB
+       select GPIOLIB_IRQCHIP
        help
          Say Y here if you want to use a ADP5588/87 attached to your
          system I2C bus.
drivers/input/keyboard/adp5588-keys.c +142 -132
index e2719737360a..f5f7ddfe68be 100644
@@ -40,21 +40,21 @@
 #define WA_DELAYED_READOUT_REVID(rev)          ((rev) < 4)
 #define WA_DELAYED_READOUT_TIME                        25
 
+#define ADP5588_INVALID_HWIRQ  (~0UL)
+
 struct adp5588_kpad {
        struct i2c_client *client;
        struct input_dev *input;
        ktime_t irq_time;
        unsigned long delay;
        unsigned short keycode[ADP5588_KEYMAPSIZE];
-       const struct adp5588_gpi_map *gpimap;
-       unsigned short gpimapsize;
-#ifdef CONFIG_GPIOLIB
        unsigned char gpiomap[ADP5588_MAXGPIO];
        struct gpio_chip gc;
        struct mutex gpio_lock; /* Protect cached dir, dat_out */
        u8 dat_out[3];
        u8 dir[3];
-#endif
+       u8 int_en[3];
+       u8 irq_mask[3];
 };
 
 static int adp5588_read(struct i2c_client *client, u8 reg)
@@ -72,7 +72,6 @@ static int adp5588_write(struct i2c_client *client, u8 reg, u8 val)
        return i2c_smbus_write_byte_data(client, reg, val);
 }
 
-#ifdef CONFIG_GPIOLIB
 static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
 {
        struct adp5588_kpad *kpad = gpiochip_get_data(chip);
@@ -171,9 +170,6 @@ static int adp5588_build_gpiomap(struct adp5588_kpad *kpad,
        for (i = 0; i < pdata->cols; i++)
                pin_used[i + GPI_PIN_COL_BASE - GPI_PIN_BASE] = true;
 
-       for (i = 0; i < kpad->gpimapsize; i++)
-               pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true;
-
        for (i = 0; i < ADP5588_MAXGPIO; i++)
                if (!pin_used[i])
                        kpad->gpiomap[n_unused++] = i;
@@ -196,11 +192,79 @@ static void adp5588_gpio_do_teardown(void *_kpad)
                dev_warn(&kpad->client->dev, "teardown failed %d\n", error);
 }
 
+static void adp5588_irq_bus_lock(struct irq_data *d)
+{
+       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+       struct adp5588_kpad *kpad = gpiochip_get_data(gc);
+
+       mutex_lock(&kpad->gpio_lock);
+}
+
+static void adp5588_irq_bus_sync_unlock(struct irq_data *d)
+{
+       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+       struct adp5588_kpad *kpad = gpiochip_get_data(gc);
+       int i;
+
+       for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
+               if (kpad->int_en[i] ^ kpad->irq_mask[i]) {
+                       kpad->int_en[i] = kpad->irq_mask[i];
+                       adp5588_write(kpad->client, GPI_EM1 + i, kpad->int_en[i]);
+               }
+       }
+
+       mutex_unlock(&kpad->gpio_lock);
+}
+
+static void adp5588_irq_mask(struct irq_data *d)
+{
+       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+       struct adp5588_kpad *kpad = gpiochip_get_data(gc);
+       irq_hw_number_t hwirq = irqd_to_hwirq(d);
+       unsigned long real_irq = kpad->gpiomap[hwirq];
+
+       kpad->irq_mask[ADP5588_BANK(real_irq)] &= ~ADP5588_BIT(real_irq);
+       gpiochip_disable_irq(gc, hwirq);
+}
+
+static void adp5588_irq_unmask(struct irq_data *d)
+{
+       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+       struct adp5588_kpad *kpad = gpiochip_get_data(gc);
+       irq_hw_number_t hwirq = irqd_to_hwirq(d);
+       unsigned long real_irq = kpad->gpiomap[hwirq];
+
+       gpiochip_enable_irq(gc, hwirq);
+       kpad->irq_mask[ADP5588_BANK(real_irq)] |= ADP5588_BIT(real_irq);
+}
+
+static int adp5588_irq_set_type(struct irq_data *d, unsigned int type)
+{
+       if (!(type & IRQ_TYPE_EDGE_BOTH))
+               return -EINVAL;
+
+       irq_set_handler_locked(d, handle_edge_irq);
+
+       return 0;
+}
+
+static const struct irq_chip adp5588_irq_chip = {
+       .name = "adp5588",
+       .irq_mask = adp5588_irq_mask,
+       .irq_unmask = adp5588_irq_unmask,
+       .irq_bus_lock = adp5588_irq_bus_lock,
+       .irq_bus_sync_unlock = adp5588_irq_bus_sync_unlock,
+       .irq_set_type = adp5588_irq_set_type,
+       .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_IMMUTABLE,
+       GPIOCHIP_IRQ_RESOURCE_HELPERS,
+};
+
 static int adp5588_gpio_add(struct adp5588_kpad *kpad)
 {
        struct device *dev = &kpad->client->dev;
        const struct adp5588_kpad_platform_data *pdata = dev_get_platdata(dev);
        const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
+       struct gpio_irq_chip *girq;
        int i, error;
 
        if (!gpio_data)
@@ -212,6 +276,7 @@ static int adp5588_gpio_add(struct adp5588_kpad *kpad)
                return 0;
        }
 
+       kpad->gc.parent = &kpad->client->dev;
        kpad->gc.direction_input = adp5588_gpio_direction_input;
        kpad->gc.direction_output = adp5588_gpio_direction_output;
        kpad->gc.get = adp5588_gpio_get_value;
@@ -223,6 +288,11 @@ static int adp5588_gpio_add(struct adp5588_kpad *kpad)
        kpad->gc.owner = THIS_MODULE;
        kpad->gc.names = gpio_data->names;
 
+       girq = &kpad->gc.irq;
+       gpio_irq_chip_set_chip(girq, &adp5588_irq_chip);
+       girq->handler = handle_bad_irq;
+       girq->threaded = true;
+
        mutex_init(&kpad->gpio_lock);
 
        error = devm_gpiochip_add_data(dev, &kpad->gc, kpad);
@@ -255,35 +325,73 @@ static int adp5588_gpio_add(struct adp5588_kpad *kpad)
        return 0;
 }
 
-#else
-static inline int adp5588_gpio_add(struct adp5588_kpad *kpad)
+static unsigned long adp5588_gpiomap_get_hwirq(struct device *dev,
+                                              const u8 *map, unsigned int gpio,
+                                              unsigned int ngpios)
 {
-       return 0;
+       unsigned int hwirq;
+
+       for (hwirq = 0; hwirq < ngpios; hwirq++)
+               if (map[hwirq] == gpio)
+                       return hwirq;
+
+       /* should never happen */
+       dev_warn_ratelimited(dev, "could not find the hwirq for gpio(%u)\n", gpio);
+
+       return ADP5588_INVALID_HWIRQ;
+}
+
+static void adp5588_gpio_irq_handle(struct adp5588_kpad *kpad, int key_val,
+                                   int key_press)
+{
+       unsigned int irq, gpio = key_val - GPI_PIN_BASE, irq_type;
+       struct i2c_client *client = kpad->client;
+       struct irq_data *irqd;
+       unsigned long hwirq;
+
+       hwirq = adp5588_gpiomap_get_hwirq(&client->dev, kpad->gpiomap,
+                                         gpio, kpad->gc.ngpio);
+       if (hwirq == ADP5588_INVALID_HWIRQ) {
+               dev_err(&client->dev, "Could not get hwirq for key(%u)\n", key_val);
+               return;
+       }
+
+       irq = irq_find_mapping(kpad->gc.irq.domain, hwirq);
+       if (!irq)
+               return;
+
+       irqd = irq_get_irq_data(irq);
+       if (!irqd) {
+               dev_err(&client->dev, "Could not get irq(%u) data\n", irq);
+               return;
+       }
+
+       irq_type = irqd_get_trigger_type(irqd);
+
+       /*
+        * Default is active low which means key_press is asserted on
+        * the falling edge.
+        */
+       if ((irq_type & IRQ_TYPE_EDGE_RISING && !key_press) ||
+           (irq_type & IRQ_TYPE_EDGE_FALLING && key_press))
+               handle_nested_irq(irq);
 }
-#endif
 
 static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt)
 {
-       int i, j;
+       int i;
 
        for (i = 0; i < ev_cnt; i++) {
                int key = adp5588_read(kpad->client, Key_EVENTA + i);
                int key_val = key & KEY_EV_MASK;
+               int key_press = key & KEY_EV_PRESSED;
 
-               if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END) {
-                       for (j = 0; j < kpad->gpimapsize; j++) {
-                               if (key_val == kpad->gpimap[j].pin) {
-                                       input_report_switch(kpad->input,
-                                                       kpad->gpimap[j].sw_evt,
-                                                       key & KEY_EV_PRESSED);
-                                       break;
-                               }
-                       }
-               } else {
+               if (key_val >= GPI_PIN_BASE && key_val <= GPI_PIN_END)
+                       /* gpio line used as IRQ source */
+                       adp5588_gpio_irq_handle(kpad, key_val, key_press);
+               else
                        input_report_key(kpad->input,
-                                        kpad->keycode[key_val - 1],
-                                        key & KEY_EV_PRESSED);
-               }
+                                        kpad->keycode[key_val - 1], key_press);
        }
 }
 
@@ -341,7 +449,6 @@ static int adp5588_setup(struct i2c_client *client)
                        dev_get_platdata(&client->dev);
        const struct adp5588_gpio_platform_data *gpio_data = pdata->gpio_data;
        int i, ret;
-       unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
 
        ret = adp5588_write(client, KP_GPIO1, KP_SEL(pdata->rows));
        ret |= adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
@@ -356,23 +463,6 @@ static int adp5588_setup(struct i2c_client *client)
        for (i = 0; i < KEYP_MAX_EVENT; i++)
                ret |= adp5588_read(client, Key_EVENTA);
 
-       for (i = 0; i < pdata->gpimapsize; i++) {
-               unsigned short pin = pdata->gpimap[i].pin;
-
-               if (pin <= GPI_PIN_ROW_END) {
-                       evt_mode1 |= (1 << (pin - GPI_PIN_ROW_BASE));
-               } else {
-                       evt_mode2 |= ((1 << (pin - GPI_PIN_COL_BASE)) & 0xFF);
-                       evt_mode3 |= ((1 << (pin - GPI_PIN_COL_BASE)) >> 8);
-               }
-       }
-
-       if (pdata->gpimapsize) {
-               ret |= adp5588_write(client, GPI_EM1, evt_mode1);
-               ret |= adp5588_write(client, GPI_EM2, evt_mode2);
-               ret |= adp5588_write(client, GPI_EM3, evt_mode3);
-       }
-
        if (gpio_data) {
                for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
                        int pull_mask = gpio_data->pullup_dis_mask;
@@ -399,44 +489,6 @@ static int adp5588_setup(struct i2c_client *client)
        return 0;
 }
 
-static void adp5588_report_switch_state(struct adp5588_kpad *kpad)
-{
-       int gpi_stat1 = adp5588_read(kpad->client, GPIO_DAT_STAT1);
-       int gpi_stat2 = adp5588_read(kpad->client, GPIO_DAT_STAT2);
-       int gpi_stat3 = adp5588_read(kpad->client, GPIO_DAT_STAT3);
-       int gpi_stat_tmp, pin_loc;
-       int i;
-
-       for (i = 0; i < kpad->gpimapsize; i++) {
-               unsigned short pin = kpad->gpimap[i].pin;
-
-               if (pin <= GPI_PIN_ROW_END) {
-                       gpi_stat_tmp = gpi_stat1;
-                       pin_loc = pin - GPI_PIN_ROW_BASE;
-               } else if ((pin - GPI_PIN_COL_BASE) < 8) {
-                       gpi_stat_tmp = gpi_stat2;
-                       pin_loc = pin - GPI_PIN_COL_BASE;
-               } else {
-                       gpi_stat_tmp = gpi_stat3;
-                       pin_loc = pin - GPI_PIN_COL_BASE - 8;
-               }
-
-               if (gpi_stat_tmp < 0) {
-                       dev_err(&kpad->client->dev,
-                               "Can't read GPIO_DAT_STAT switch %d default to OFF\n",
-                               pin);
-                       gpi_stat_tmp = 0;
-               }
-
-               input_report_switch(kpad->input,
-                                   kpad->gpimap[i].sw_evt,
-                                   !(gpi_stat_tmp & (1 << pin_loc)));
-       }
-
-       input_sync(kpad->input);
-}
-
-
 static int adp5588_probe(struct i2c_client *client,
                         const struct i2c_device_id *id)
 {
@@ -469,37 +521,6 @@ static int adp5588_probe(struct i2c_client *client,
                return -EINVAL;
        }
 
-       if (!pdata->gpimap && pdata->gpimapsize) {
-               dev_err(&client->dev, "invalid gpimap from pdata\n");
-               return -EINVAL;
-       }
-
-       if (pdata->gpimapsize > ADP5588_GPIMAPSIZE_MAX) {
-               dev_err(&client->dev, "invalid gpimapsize\n");
-               return -EINVAL;
-       }
-
-       for (i = 0; i < pdata->gpimapsize; i++) {
-               unsigned short pin = pdata->gpimap[i].pin;
-
-               if (pin < GPI_PIN_BASE || pin > GPI_PIN_END) {
-                       dev_err(&client->dev, "invalid gpi pin data\n");
-                       return -EINVAL;
-               }
-
-               if (pin <= GPI_PIN_ROW_END) {
-                       if (pin - GPI_PIN_ROW_BASE + 1 <= pdata->rows) {
-                               dev_err(&client->dev, "invalid gpi row data\n");
-                               return -EINVAL;
-                       }
-               } else {
-                       if (pin - GPI_PIN_COL_BASE + 1 <= pdata->cols) {
-                               dev_err(&client->dev, "invalid gpi col data\n");
-                               return -EINVAL;
-                       }
-               }
-       }
-
        if (!client->irq) {
                dev_err(&client->dev, "no IRQ?\n");
                return -EINVAL;
@@ -541,9 +562,6 @@ static int adp5588_probe(struct i2c_client *client,
        memcpy(kpad->keycode, pdata->keymap,
                pdata->keymapsize * input->keycodesize);
 
-       kpad->gpimap = pdata->gpimap;
-       kpad->gpimapsize = pdata->gpimapsize;
-
        /* setup input device */
        __set_bit(EV_KEY, input->evbit);
 
@@ -555,11 +573,6 @@ static int adp5588_probe(struct i2c_client *client,
                        __set_bit(kpad->keycode[i], input->keybit);
        __clear_bit(KEY_RESERVED, input->keybit);
 
-       if (kpad->gpimapsize)
-               __set_bit(EV_SW, input->evbit);
-       for (i = 0; i < kpad->gpimapsize; i++)
-               __set_bit(kpad->gpimap[i].sw_evt, input->swbit);
-
        error = input_register_device(input);
        if (error) {
                dev_err(&client->dev, "unable to register input device: %d\n",
@@ -567,6 +580,14 @@ static int adp5588_probe(struct i2c_client *client,
                return error;
        }
 
+       error = adp5588_setup(client);
+       if (error)
+               return error;
+
+       error = adp5588_gpio_add(kpad);
+       if (error)
+               return error;
+
        error = devm_request_threaded_irq(&client->dev, client->irq,
                                          adp5588_hard_irq, adp5588_thread_irq,
                                          IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
@@ -577,17 +598,6 @@ static int adp5588_probe(struct i2c_client *client,
                return error;
        }
 
-       error = adp5588_setup(client);
-       if (error)
-               return error;
-
-       if (kpad->gpimapsize)
-               adp5588_report_switch_state(kpad);
-
-       error = adp5588_gpio_add(kpad);
-       if (error)
-               return error;
-
        dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq);
        return 0;
 }
include/linux/platform_data/adp5588.h +0 -3
index 6d3f7d911a92..82170ec8c266 100644
@@ -147,8 +147,6 @@ struct adp5588_kpad_platform_data {
        unsigned en_keylock:1;          /* Enable Key Lock feature */
        unsigned short unlock_key1;     /* Unlock Key 1 */
        unsigned short unlock_key2;     /* Unlock Key 2 */
-       const struct adp5588_gpi_map *gpimap;
-       unsigned short gpimapsize;
        const struct adp5588_gpio_platform_data *gpio_data;
 };
 
--

2.37.2

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v4 1/10
#3 lore raw

Re: [PATCH v4 01/10] input: keyboard: adp5588-keys: support gpi key events as 'gpio keys'

In reply to Nuno Sá
Quoted 18 lines · Nuno Sá

This change replaces the support for GPIs as key event generators. Instead of reporting the events directly, we add a gpio based irqchip so that these events can be consumed by keys defined in the gpio-keys driver (as it's goal is indeed for keys on GPIOs capable of generating interrupts). With this, the gpio-adp5588 driver can also be dropped.

The basic idea is that all the pins that are not being used as part of the keymap matrix can be possibly requested as GPIOs by gpio-keys (it's also fine to use these pins as plain interrupts though that's not really the point).

Since the gpiochip now also has irqchip capabilities, we should only remove it after we free the device interrupt (otherwise we could, in theory, be handling GPIs interrupts while the gpiochip is concurrently removed). Thus the call 'adp5588_gpio_add()' is moved and since the setup phase also needs to come before making the gpios visible, we also need to move 'adp5588_setup()'.

Quoted 4 lines

While at it, always select GPIOLIB so that we don't need to use #ifdef guards.

Makes the world simpler so:

Yours,
Linus Walleij

author
#4 lore raw

PATCH v4 2/10 gpio: gpio-adp5588: drop the driver

In reply to Nuno Sá

With commit 70466baac3de
("input: keyboard: adp5588-keys: support gpi key events as 'gpio keys'"), the irchip functionality is directly supported in the input driver as the main goal of these pins is to be used as gpio keys. Hence, this driver can be removed.

---
 MAINTAINERS                 |   1 -
 drivers/gpio/Kconfig        |  14 --
 drivers/gpio/Makefile       |   1 -
 drivers/gpio/gpio-adp5588.c | 446 ------------------------------------
 4 files changed, 462 deletions(-)
 delete mode 100644 drivers/gpio/gpio-adp5588.c
MAINTAINERS +0 -1
index 711bcd4f6269..8404c18e6bcf 100644
@@ -556,7 +556,6 @@ M:	Michael Hennerich <[email protected]>
 S:	Supported
 W:	http://wiki.analog.com/ADP5588
 W:	https://ez.analog.com/linux-software-drivers
-F:	drivers/gpio/gpio-adp5588.c
 F:	drivers/input/keyboard/adp5588-keys.c
 
 ADP8860 BACKLIGHT DRIVER (ADP8860/ADP8861/ADP8863)
drivers/gpio/Kconfig +0 -14
index 0642f579196f..3055ed2e115a 100644
@@ -985,20 +985,6 @@ endmenu
 menu "I2C GPIO expanders"
 	depends on I2C
 
-config GPIO_ADP5588
-	tristate "ADP5588 I2C GPIO expander"
-	help
-	  This option enables support for 18 GPIOs found
-	  on Analog Devices ADP5588 GPIO Expanders.
-
-config GPIO_ADP5588_IRQ
-	bool "Interrupt controller support for ADP5588"
-	depends on GPIO_ADP5588=y
-	select GPIOLIB_IRQCHIP
-	help
-	  Say yes here to enable the adp5588 to be used as an interrupt
-	  controller. It requires the driver to be built in the kernel.
-
 config GPIO_ADNP
 	tristate "Avionic Design N-bit GPIO expander"
 	depends on OF_GPIO
drivers/gpio/Makefile +0 -1
index a0985d30f51b..5b890a695f82 100644
@@ -25,7 +25,6 @@ obj-$(CONFIG_GPIO_74X164)		+= gpio-74x164.o
 obj-$(CONFIG_GPIO_74XX_MMIO)		+= gpio-74xx-mmio.o
 obj-$(CONFIG_GPIO_ADNP)			+= gpio-adnp.o
 obj-$(CONFIG_GPIO_ADP5520)		+= gpio-adp5520.o
-obj-$(CONFIG_GPIO_ADP5588)		+= gpio-adp5588.o
 obj-$(CONFIG_GPIO_AGGREGATOR)		+= gpio-aggregator.o
 obj-$(CONFIG_GPIO_ALTERA_A10SR)		+= gpio-altera-a10sr.o
 obj-$(CONFIG_GPIO_ALTERA)  		+= gpio-altera.o
drivers/gpio/gpio-adp5588.c deleted +0 -446

446 lines not on this page · raw message

Signature · 1 line
2.37.2
#5 lore raw

Re: [PATCH v4 02/10] gpio: gpio-adp5588: drop the driver

Quoted 2 lines · Nuno Sá

With commit 70466baac3de
("input: keyboard: adp5588-keys: support gpi key events as 'gpio keys'"),

This commit isn't in the upstream kernel.

Are you using some Analog devices internal tree? Upstream those changes first.

Yours,
Linus Walleij

#6 lore raw

Re: [PATCH v4 02/10] gpio: gpio-adp5588: drop the driver

Quoted 9 lines · Linus Walleij
Quoted 2 lines · Nuno Sá

With commit 70466baac3de
("input: keyboard: adp5588-keys: support gpi key events as 'gpio keys'"),

This commit isn't in the upstream kernel.

Are you using some Analog devices internal tree? Upstream those changes first.

Aha I see that is patch 1, OK the hash will change all the time so you can't include that when doing a patch series. Just use the title of the previous patch if you need to.

Yours,
Linus Walleij

author
#7 lore raw

RE: [PATCH v4 02/10] gpio: gpio-adp5588: drop the driver

Quoted 26 lines

-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Wednesday, August 31, 2022 2:23 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]; Bartosz Golaszewski <[email protected]>; Dmitry Torokhov <[email protected]>; [email protected]; [email protected]; linux- [email protected]; Andy Shevchenko <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Hennerich, Michael <[email protected]>
Subject: Re: [PATCH v4 02/10] gpio: gpio-adp5588: drop the driver

[External]

Quoted 1 line · Linus Walleij

On Mon, Aug 29, 2022 at 3:15 PM Nuno Sá <[email protected]>

Quoted 3 lines · wrote:
Quoted 3 lines

With commit 70466baac3de
("input: keyboard: adp5588-keys: support gpi key events as 'gpio

keys'"),

Quoted 1 line
Quoted 9 lines
Quoted 4 lines

This commit isn't in the upstream kernel.

Are you using some Analog devices internal tree? Upstream those changes first.

Aha I see that is patch 1, OK the hash will change all the time so you can't include that when doing a patch series. Just use the title of the previous patch if you need to.

Ahh I see... Will do that next time I have something like this :)

- Nuno Sá

author
#8 lore raw

PATCH v4 3/10 input: keyboard: adp5588-keys: bail out on returned error

In reply to Nuno Sá

Don't continue in code paths after some error is found. It makes no sense to do any other device configuration if a previous one failed.

---
 drivers/input/keyboard/adp5588-keys.c | 56 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 18 deletions(-)
drivers/input/keyboard/adp5588-keys.c +38 -18
index f5f7ddfe68be..2452ea4128b3 100644
@@ -147,9 +147,13 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
 
 	ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
 				 kpad->dat_out[bank]);
-	ret |= adp5588_write(kpad->client, GPIO_DIR1 + bank,
+	if (ret)
+		goto out_unlock;
+
+	ret = adp5588_write(kpad->client, GPIO_DIR1 + bank,
 				 kpad->dir[bank]);
 
+out_unlock:
 	mutex_unlock(&kpad->gpio_lock);
 
 	return ret;
@@ -451,42 +455,58 @@ static int adp5588_setup(struct i2c_client *client)
 	int i, ret;
 
 	ret = adp5588_write(client, KP_GPIO1, KP_SEL(pdata->rows));
-	ret |= adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
-	ret |= adp5588_write(client, KP_GPIO3, KP_SEL(pdata->cols) >> 8);
+	if (ret)
+		return ret;
+
+	ret = adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
+	if (ret)
+		return ret;
+
+	ret = adp5588_write(client, KP_GPIO3, KP_SEL(pdata->cols) >> 8);
+	if (ret)
+		return ret;
 
 	if (pdata->en_keylock) {
-		ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1);
-		ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2);
-		ret |= adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
+		ret = adp5588_write(client, UNLOCK1, pdata->unlock_key1);
+		if (ret)
+			return ret;
+
+		ret = adp5588_write(client, UNLOCK2, pdata->unlock_key2);
+		if (ret)
+			return ret;
+
+		ret = adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
+		if (ret)
+			return ret;
 	}
 
-	for (i = 0; i < KEYP_MAX_EVENT; i++)
-		ret |= adp5588_read(client, Key_EVENTA);
+	for (i = 0; i < KEYP_MAX_EVENT; i++) {
+		ret = adp5588_read(client, Key_EVENTA);
+		if (ret)
+			return ret;
+	}
 
 	if (gpio_data) {
 		for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
 			int pull_mask = gpio_data->pullup_dis_mask;
 
-			ret |= adp5588_write(client, GPIO_PULL1 + i,
+			ret = adp5588_write(client, GPIO_PULL1 + i,
 				(pull_mask >> (8 * i)) & 0xFF);
+			if (ret)
+				return ret;
 		}
 	}
 
-	ret |= adp5588_write(client, INT_STAT,
+	ret = adp5588_write(client, INT_STAT,
 				ADP5588_CMP2_INT | ADP5588_CMP1_INT |
 				ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
 				ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
+	if (ret)
+		return ret;
 
-	ret |= adp5588_write(client, CFG, ADP5588_INT_CFG |
+	return adp5588_write(client, CFG, ADP5588_INT_CFG |
 					  ADP5588_OVR_FLOW_IEN |
 					  ADP5588_KE_IEN);
-
-	if (ret < 0) {
-		dev_err(&client->dev, "Write Error\n");
-		return ret;
-	}
-
-	return 0;
 }
 
 static int adp5588_probe(struct i2c_client *client,
Signature · 1 line
2.37.2
author
#9 lore raw

PATCH v4 4/10 input: keyboard: adp5588-keys: add support for fw properties

In reply to Nuno Sá

Use firmware properties (eg: OF) to get the device specific configuration. This change just replaces the platform data since there was no platform using it and so, it makes no sense having both.

Special note to the PULL-UP disable setting that is now supported as part of the gpio subsystem (using 'set_config()' callback).

---
 drivers/input/keyboard/Kconfig        |   1 +
 drivers/input/keyboard/adp5588-keys.c | 394 +++++++++++++++++++-------
 include/linux/platform_data/adp5588.h | 169 -----------
 3 files changed, 288 insertions(+), 276 deletions(-)
 delete mode 100644 include/linux/platform_data/adp5588.h
drivers/input/keyboard/Kconfig +1 -0
index ca5cd5e520a7..be4a6f8165cd 100644
@@ -42,6 +42,7 @@ config KEYBOARD_ADP5588
 	depends on I2C
 	select GPIOLIB
 	select GPIOLIB_IRQCHIP
+	select INPUT_MATRIXKMAP
 	help
 	  Say Y here if you want to use a ADP5588/87 attached to your
 	  system I2C bus.
drivers/input/keyboard/adp5588-keys.c +287 -107

553 lines not on this page · raw message

include/linux/platform_data/adp5588.h deleted +0 -169

169 lines not on this page · raw message

Signature · 1 line
2.37.2
author
#10 lore raw

PATCH v4 5/10 dt-bindings: input: adp5588: add bindings

In reply to Nuno Sá

Add device tree bindings for the adp5588-keys driver.

---
 .../bindings/input/adi,adp5588.yaml           | 111 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 112 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/adi,adp5588.yaml
Documentation/devicetree/bindings/input/adi,adp5588.yaml new file +111 -0
new file mode 100644
index 000000000000..26ea66834ae2
@@ -0,0 +1,111 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/adi,adp5588.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADP5588 Keypad Controller
+
+maintainers:
+  - Nuno Sá <[email protected]>
+
+description: |
+  Analog Devices Mobile I/O Expander and QWERTY Keypad Controller
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ADP5588.pdf
+
+allOf:
+  - $ref: matrix-keymap.yaml#
+  - $ref: input.yaml#
+
+properties:
+  compatible:
+    enum:
+      - adi,adp5587
+      - adi,adp5588
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:
+    description: Supply Voltage Input
+
+  reset-gpios:
+    description:
+      If specified, it will be asserted during driver probe. As the line is
+      active low, it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  gpio-controller:
+    description:
+      This property applies if either keypad,num-rows lower than 8 or
+      keypad,num-columns lower than 10.
+
+  '#gpio-cells':
+    const: 2
+
+  interrupt-controller:
+    description:
+      This property applies if either keypad,num-rows lower than 8 or
+      keypad,num-columns lower than 10.
+
+  '#interrupt-cells':
+    const: 2
+
+  adi,unlock-keys:
+    description:
+      Specifies a maximum of 2 keys that can be used to unlock the keypad.
+      If this property is set, the keyboard will be locked and only unlocked
+      after these keys are pressed. If only one key is set, a double click is
+      needed to unlock the keypad. The value of this property cannot be bigger
+      or equal than keypad,num-rows * keypad,num-columns.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    maxItems: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - keypad,num-rows
+  - keypad,num-columns
+  - linux,keymap
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/input/input.h>
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        keys@34 {
+            compatible = "adi,adp5588";
+            reg = <0x34>;
+
+            vcc-supply = <&vcc>;
+            interrupts = <21 IRQ_TYPE_EDGE_FALLING>;
+            interrupt-parent = <&gpio>;
+            reset-gpios = <&gpio 20 GPIO_ACTIVE_LOW>;
+
+            keypad,num-rows = <1>;
+            keypad,num-columns = <9>;
+            linux,keymap = <
+                MATRIX_KEY(0x00, 0x00, KEY_1)
+                MATRIX_KEY(0x00, 0x01, KEY_2)
+                MATRIX_KEY(0x00, 0x02, KEY_3)
+                MATRIX_KEY(0x00, 0x03, KEY_4)
+                MATRIX_KEY(0x00, 0x04, KEY_5)
+                MATRIX_KEY(0x00, 0x05, KEY_6)
+                MATRIX_KEY(0x00, 0x06, KEY_7)
+                MATRIX_KEY(0x00, 0x07, KEY_8)
+                MATRIX_KEY(0x00, 0x08, KEY_9)
+            >;
+        };
+    };
+...
MAINTAINERS +1 -0
index 8404c18e6bcf..aa71df8b699b 100644
@@ -556,6 +556,7 @@ M:	Michael Hennerich <[email protected]>
 S:	Supported
 W:	http://wiki.analog.com/ADP5588
 W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/input/adi,adp5588.yaml
 F:	drivers/input/keyboard/adp5588-keys.c
 
 ADP8860 BACKLIGHT DRIVER (ADP8860/ADP8861/ADP8863)
Signature · 1 line
2.37.2
author
#11 lore raw

PATCH v4 6/10 input: keyboard: adp5588-keys: do not check for irq presence

In reply to Nuno Sá

There's no need for an extra check for 'client-irq'. Just let it fail when calling 'request_irq()'.

---
 drivers/input/keyboard/adp5588-keys.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/input/keyboard/adp5588-keys.c +0 -5
index 2b00bc0f174c..e716efbb2105 100644
@@ -727,11 +727,6 @@ static int adp5588_probe(struct i2c_client *client,
 		return -EIO;
 	}
 
-	if (!client->irq) {
-		dev_err(&client->dev, "no IRQ?\n");
-		return -EINVAL;
-	}
-
 	kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL);
 	if (!kpad)
 		return -ENOMEM;
Signature · 1 line
2.37.2
author
#12 lore raw

PATCH v4 7/10 input: keyboard: adp5588-keys: fix coding style warnings

In reply to Nuno Sá

Just some code cleanup regarding coding style. With the introduction of the bits.h macros changes in the code are indeed introduced.

---
 drivers/input/keyboard/adp5588-keys.c | 98 +++++++++++++--------------
 1 file changed, 48 insertions(+), 50 deletions(-)
drivers/input/keyboard/adp5588-keys.c +48 -50
index e716efbb2105..3a234ec37fd4 100644
@@ -8,6 +8,7 @@
  * Copyright (C) 2008-2010 Analog Devices Inc.
  */
 
+#include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/gpio/driver.h>
@@ -29,16 +30,16 @@
 #define CFG 0x01		/* Configuration Register1 */
 #define INT_STAT 0x02		/* Interrupt Status Register */
 #define KEY_LCK_EC_STAT 0x03	/* Key Lock and Event Counter Register */
-#define Key_EVENTA 0x04		/* Key Event Register A */
-#define Key_EVENTB 0x05		/* Key Event Register B */
-#define Key_EVENTC 0x06		/* Key Event Register C */
-#define Key_EVENTD 0x07		/* Key Event Register D */
-#define Key_EVENTE 0x08		/* Key Event Register E */
-#define Key_EVENTF 0x09		/* Key Event Register F */
-#define Key_EVENTG 0x0A		/* Key Event Register G */
-#define Key_EVENTH 0x0B		/* Key Event Register H */
-#define Key_EVENTI 0x0C		/* Key Event Register I */
-#define Key_EVENTJ 0x0D		/* Key Event Register J */
+#define KEY_EVENTA 0x04		/* Key Event Register A */
+#define KEY_EVENTB 0x05		/* Key Event Register B */
+#define KEY_EVENTC 0x06		/* Key Event Register C */
+#define KEY_EVENTD 0x07		/* Key Event Register D */
+#define KEY_EVENTE 0x08		/* Key Event Register E */
+#define KEY_EVENTF 0x09		/* Key Event Register F */
+#define KEY_EVENTG 0x0A		/* Key Event Register G */
+#define KEY_EVENTH 0x0B		/* Key Event Register H */
+#define KEY_EVENTI 0x0C		/* Key Event Register I */
+#define KEY_EVENTJ 0x0D		/* Key Event Register J */
 #define KP_LCK_TMR 0x0E		/* Keypad Lock1 to Lock2 Timer */
 #define UNLOCK1 0x0F		/* Unlock Key1 */
 #define UNLOCK2 0x10		/* Unlock Key2 */
@@ -66,9 +67,9 @@
 #define GPIO_INT_LVL1 0x26	/* GPIO Edge/Level Detect */
 #define GPIO_INT_LVL2 0x27	/* GPIO Edge/Level Detect */
 #define GPIO_INT_LVL3 0x28	/* GPIO Edge/Level Detect */
-#define Debounce_DIS1 0x29	/* Debounce Disable */
-#define Debounce_DIS2 0x2A	/* Debounce Disable */
-#define Debounce_DIS3 0x2B	/* Debounce Disable */
+#define DEBOUNCE_DIS1 0x29	/* Debounce Disable */
+#define DEBOUNCE_DIS2 0x2A	/* Debounce Disable */
+#define DEBOUNCE_DIS3 0x2B	/* Debounce Disable */
 #define GPIO_PULL1 0x2C		/* GPIO Pull Disable */
 #define GPIO_PULL2 0x2D		/* GPIO Pull Disable */
 #define GPIO_PULL3 0x2E		/* GPIO Pull Disable */
@@ -91,27 +92,27 @@
 #define ADP5588_DEVICE_ID_MASK	0xF
 
  /* Configuration Register1 */
-#define ADP5588_AUTO_INC	(1 << 7)
-#define ADP5588_GPIEM_CFG	(1 << 6)
-#define ADP5588_OVR_FLOW_M	(1 << 5)
-#define ADP5588_INT_CFG		(1 << 4)
-#define ADP5588_OVR_FLOW_IEN	(1 << 3)
-#define ADP5588_K_LCK_IM	(1 << 2)
-#define ADP5588_GPI_IEN		(1 << 1)
-#define ADP5588_KE_IEN		(1 << 0)
+#define ADP5588_AUTO_INC	BIT(7)
+#define ADP5588_GPIEM_CFG	BIT(6)
+#define ADP5588_OVR_FLOW_M	BIT(5)
+#define ADP5588_INT_CFG		BIT(4)
+#define ADP5588_OVR_FLOW_IEN	BIT(3)
+#define ADP5588_K_LCK_IM	BIT(2)
+#define ADP5588_GPI_IEN		BIT(1)
+#define ADP5588_KE_IEN		BIT(0)
 
 /* Interrupt Status Register */
-#define ADP5588_CMP2_INT	(1 << 5)
-#define ADP5588_CMP1_INT	(1 << 4)
-#define ADP5588_OVR_FLOW_INT	(1 << 3)
-#define ADP5588_K_LCK_INT	(1 << 2)
-#define ADP5588_GPI_INT		(1 << 1)
-#define ADP5588_KE_INT		(1 << 0)
+#define ADP5588_CMP2_INT	BIT(5)
+#define ADP5588_CMP1_INT	BIT(4)
+#define ADP5588_OVR_FLOW_INT	BIT(3)
+#define ADP5588_K_LCK_INT	BIT(2)
+#define ADP5588_GPI_INT		BIT(1)
+#define ADP5588_KE_INT		BIT(0)
 
 /* Key Lock and Event Counter Register */
-#define ADP5588_K_LCK_EN	(1 << 6)
+#define ADP5588_K_LCK_EN	BIT(6)
 #define ADP5588_LCK21		0x30
-#define ADP5588_KEC		0xF
+#define ADP5588_KEC		GENMASK(3, 0)
 
 #define ADP5588_MAXGPIO		18
 #define ADP5588_BANK(offs)	((offs) >> 3)
@@ -158,10 +159,10 @@
 #define ADP5588_GPIMAPSIZE_MAX (GPI_PIN_END - GPI_PIN_BASE + 1)
 
 /* Key Event Register xy */
-#define KEY_EV_PRESSED		(1 << 7)
-#define KEY_EV_MASK		(0x7F)
+#define KEY_EV_PRESSED		BIT(7)
+#define KEY_EV_MASK		GENMASK(6, 0)
 
-#define KP_SEL(x)		(0xFFFF >> (16 - x))	/* 2^x-1 */
+#define KP_SEL(x)		(BIT(x) - 1)	/* 2^x-1 */
 
 #define KEYP_MAX_EVENT		10
 
@@ -211,7 +212,7 @@ static int adp5588_write(struct i2c_client *client, u8 reg, u8 val)
 	return i2c_smbus_write_byte_data(client, reg, val);
 }
 
-static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
+static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned int off)
 {
 	struct adp5588_kpad *kpad = gpiochip_get_data(chip);
 	unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
@@ -231,7 +232,7 @@ static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
 }
 
 static void adp5588_gpio_set_value(struct gpio_chip *chip,
-				   unsigned off, int val)
+				   unsigned int off, int val)
 {
 	struct adp5588_kpad *kpad = gpiochip_get_data(chip);
 	unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
@@ -244,8 +245,7 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
 	else
 		kpad->dat_out[bank] &= ~bit;
 
-	adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
-			   kpad->dat_out[bank]);
+	adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, kpad->dat_out[bank]);
 
 	mutex_unlock(&kpad->gpio_lock);
 }
@@ -284,7 +284,7 @@ static int adp5588_gpio_set_config(struct gpio_chip *chip,  unsigned int off,
 	return ret;
 }
 
-static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
+static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned int off)
 {
 	struct adp5588_kpad *kpad = gpiochip_get_data(chip);
 	unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
@@ -302,7 +302,7 @@ static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
 }
 
 static int adp5588_gpio_direction_output(struct gpio_chip *chip,
-					 unsigned off, int val)
+					 unsigned int off, int val)
 {
 	struct adp5588_kpad *kpad = gpiochip_get_data(chip);
 	unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
@@ -319,12 +319,11 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
 		kpad->dat_out[bank] &= ~bit;
 
 	ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
-				 kpad->dat_out[bank]);
+			    kpad->dat_out[bank]);
 	if (ret)
 		goto out_unlock;
 
-	ret = adp5588_write(kpad->client, GPIO_DIR1 + bank,
-				 kpad->dir[bank]);
+	ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]);
 
 out_unlock:
 	mutex_unlock(&kpad->gpio_lock);
@@ -524,7 +523,7 @@ static void adp5588_report_events(struct adp5588_kpad *kpad, int ev_cnt)
 	int i;
 
 	for (i = 0; i < ev_cnt; i++) {
-		int key = adp5588_read(kpad->client, Key_EVENTA + i);
+		int key = adp5588_read(kpad->client, KEY_EVENTA + i);
 		int key_val = key & KEY_EV_MASK;
 		int key_press = key & KEY_EV_PRESSED;
 
@@ -624,21 +623,20 @@ static int adp5588_setup(struct adp5588_kpad *kpad)
 	}
 
 	for (i = 0; i < KEYP_MAX_EVENT; i++) {
-		ret = adp5588_read(client, Key_EVENTA);
+		ret = adp5588_read(client, KEY_EVENTA);
 		if (ret)
 			return ret;
 	}
 
 	ret = adp5588_write(client, INT_STAT,
-				ADP5588_CMP2_INT | ADP5588_CMP1_INT |
-				ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
-				ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
+			    ADP5588_CMP2_INT | ADP5588_CMP1_INT |
+			    ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
+			    ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
 	if (ret)
 		return ret;
 
 	return adp5588_write(client, CFG, ADP5588_INT_CFG |
-					  ADP5588_OVR_FLOW_IEN |
-					  ADP5588_KE_IEN);
+			     ADP5588_OVR_FLOW_IEN | ADP5588_KE_IEN);
 }
 
 static int adp5588_fw_parse(struct adp5588_kpad *kpad)
@@ -722,7 +720,7 @@ static int adp5588_probe(struct i2c_client *client,
 	int error;
 
 	if (!i2c_check_functionality(client->adapter,
-					I2C_FUNC_SMBUS_BYTE_DATA)) {
+				     I2C_FUNC_SMBUS_BYTE_DATA)) {
 		dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
 		return -EIO;
 	}
@@ -746,7 +744,7 @@ static int adp5588_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	revid = (u8) ret & ADP5588_DEVICE_ID_MASK;
+	revid = ret & ADP5588_DEVICE_ID_MASK;
 	if (WA_DELAYED_READOUT_REVID(revid))
 		kpad->delay = msecs_to_jiffies(WA_DELAYED_READOUT_TIME);
 
Signature · 1 line
2.37.2
author
#13 lore raw

PATCH v4 8/10 input: keyboard: adp5588-keys: add optional reset gpio

In reply to Nuno Sá

Optionally reset the device during probe.

---
 drivers/input/keyboard/adp5588-keys.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/input/keyboard/adp5588-keys.c +12 -0
index 3a234ec37fd4..b2bb7c6702e1 100644
@@ -11,6 +11,7 @@
 #include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
@@ -715,6 +716,7 @@ static int adp5588_probe(struct i2c_client *client,
 {
 	struct adp5588_kpad *kpad;
 	struct input_dev *input;
+	struct gpio_desc *gpio;
 	unsigned int revid;
 	int ret;
 	int error;
@@ -740,6 +742,16 @@ static int adp5588_probe(struct i2c_client *client,
 	if (error)
 		return error;
 
+	gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpio))
+		return PTR_ERR(gpio);
+
+	if (gpio) {
+		fsleep(30);
+		gpiod_set_value_cansleep(gpio, 0);
+		fsleep(60);
+	}
+
 	ret = adp5588_read(client, DEV_ID);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.37.2
author
#14 lore raw

PATCH v4 9/10 input: keyboard: adp5588-keys: add regulator support

In reply to Nuno Sá

Support feeding VCC through a regulator.

---
 drivers/input/keyboard/adp5588-keys.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/input/keyboard/adp5588-keys.c +19 -0
index b2bb7c6702e1..0e6f4a47bb9c 100644
@@ -24,6 +24,7 @@
 #include <linux/pinctrl/pinconf-generic.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
+#include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <linux/timekeeping.h>
 
@@ -711,12 +712,18 @@ static int adp5588_fw_parse(struct adp5588_kpad *kpad)
 	return 0;
 }
 
+static void adp5588_disable_regulator(void *reg)
+{
+	regulator_disable(reg);
+}
+
 static int adp5588_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
 	struct adp5588_kpad *kpad;
 	struct input_dev *input;
 	struct gpio_desc *gpio;
+	struct regulator *vcc;
 	unsigned int revid;
 	int ret;
 	int error;
@@ -742,6 +749,18 @@ static int adp5588_probe(struct i2c_client *client,
 	if (error)
 		return error;
 
+	vcc = devm_regulator_get(&client->dev, "vcc");
+	if (IS_ERR(vcc))
+		return PTR_ERR(vcc);
+
+	ret = regulator_enable(vcc);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(&client->dev, adp5588_disable_regulator, vcc);
+	if (ret)
+		return ret;
+
 	gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
 	if (IS_ERR(gpio))
 		return PTR_ERR(gpio);
Signature · 1 line
2.37.2
author
#15 lore raw

PATCH v4 10/10 input: keyboard: adp5588-keys: Use new PM macros

In reply to Nuno Sá

With the new PM macros (DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr()), the compiler has visibility to see that the functions are not used when !CONFIG_PM and hence, remove the dead code. As such, there's no need for '__maybe_unused'.

---
 drivers/input/keyboard/adp5588-keys.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/input/keyboard/adp5588-keys.c +4 -4
index 0e6f4a47bb9c..7cb120ad3a68 100644
@@ -825,7 +825,7 @@ static void adp5588_remove(struct i2c_client *client)
 	/* all resources will be freed by devm */
 }
 
-static int __maybe_unused adp5588_suspend(struct device *dev)
+static int adp5588_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 
@@ -834,7 +834,7 @@ static int __maybe_unused adp5588_suspend(struct device *dev)
 	return 0;
 }
 
-static int __maybe_unused adp5588_resume(struct device *dev)
+static int adp5588_resume(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 
@@ -843,7 +843,7 @@ static int __maybe_unused adp5588_resume(struct device *dev)
 	return 0;
 }
 
-static SIMPLE_DEV_PM_OPS(adp5588_dev_pm_ops, adp5588_suspend, adp5588_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(adp5588_dev_pm_ops, adp5588_suspend, adp5588_resume);
 
 static const struct i2c_device_id adp5588_id[] = {
 	{ "adp5588-keys", 0 },
@@ -863,7 +863,7 @@ static struct i2c_driver adp5588_driver = {
 	.driver = {
 		.name = KBUILD_MODNAME,
 		.of_match_table = adp5588_of_match,
-		.pm   = &adp5588_dev_pm_ops,
+		.pm   = pm_sleep_ptr(&adp5588_dev_pm_ops),
 	},
 	.probe    = adp5588_probe,
 	.remove   = adp5588_remove,
Signature · 1 line
2.37.2
maintainer
#16 lore raw
In reply to Nuno Sá
Quoted 21 lines · Nuno Sá

The main goal of this patchset is to remove platform data and replace it by firmware properties. Original discussion in [1].

While in here, some refactor was done to the driver. The most noticeable one is to replace the GPIs events handling by irqchip support so that this gpi keys can be "consumed" by the gpio-keys driver (also as suggested in [1]). With this, the gpio-adp5588 can be removed. This change comes first so that we can already remove some platform data variables making it easier to completly replace it by firmware properties further down in the series.

As there's no users of the platform data, I just replace it in a single patch as there's no point in having support for both (even though it might be harder to review the patch as-is).

Special note to the gpio-adp5588 driver removal. I'm aware of some changes to the driver in [2]. These changes are in the gpio tree and this patchset is naturally based on the input tree which means that patch 2 will not apply. So, I'm not really sure how to handle this. I guess in this case the conflict is easy to handle :) but just let me know on how to proceed in here if there's anything for me to do.

Quoted 2 lines

[1]: https://lore.kernel.org/linux-input/[email protected]/
[2]: https://lore.kernel.org/linux-gpio/[email protected]/

Given that one of the GPIO maintainers Acked the removal I applied the series to my tree, thank you.

Signature · 1 line
Dmitry