Skip to contentSkip to conversation

gpio: Initial support for ROHM bd70528 GPIO block

RFC PATCH Superseded Matti Vaittinen 2 participants 3 messages Jan 25, 2019 – Jan 28, 2019

Subsystems (4)

v2 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 7/10 gpio: Initial support for ROHM bd70528 GPIO block

ROHM BD70528 PMIC has 4 GPIO pins. Allow them to be controlled by GPIO framework.

IRQs are handled by regmap-irq and GPIO driver is not aware of the irq usage.

---
 drivers/gpio/Kconfig        |  11 +++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bd70528.c | 192 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/gpio/gpio-bd70528.c
drivers/gpio/Kconfig +11 -0
index b5a2845347ec..c82187648630 100644
@@ -962,6 +962,17 @@ config GPIO_ARIZONA
 	help
 	  Support for GPIOs on Wolfson Arizona class devices.
 
+config GPIO_BD70528
+	tristate "ROHM BD70528 GPIO support"
+	depends on MFD_ROHM_BD70528
+	help
+	  Support for GPIOs on ROHM BD70528 PMIC. There are four GPIOs
+	  available on the ROHM PMIC in total. The GPIOs can also
+	  generate interrupts.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called gpio-bd70528.
+
 config GPIO_BD9571MWV
 	tristate "ROHM BD9571 GPIO support"
 	depends on MFD_BD9571MWV
drivers/gpio/Makefile +1 -0
index 37628f8dbf70..6f12c83598fc 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_GPIO_ATH79)	+= gpio-ath79.o
 obj-$(CONFIG_GPIO_ASPEED)	+= gpio-aspeed.o
 obj-$(CONFIG_GPIO_RASPBERRYPI_EXP)	+= gpio-raspberrypi-exp.o
 obj-$(CONFIG_GPIO_BCM_KONA)	+= gpio-bcm-kona.o
+obj-$(CONFIG_GPIO_BD70528) 	+= gpio-bd70528.o
 obj-$(CONFIG_GPIO_BD9571MWV)	+= gpio-bd9571mwv.o
 obj-$(CONFIG_GPIO_BRCMSTB)	+= gpio-brcmstb.o
 obj-$(CONFIG_GPIO_BT8XX)	+= gpio-bt8xx.o
drivers/gpio/gpio-bd70528.c new file +192 -0

192 lines not on this page · raw message

Signature · 8 lines
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~
Reviewed-by on v2 7/10
#1 lore raw

Hi Matti!

Thanks for your patch!

Quoted 7 lines · Matti Vaittinen

ROHM BD70528 PMIC has 4 GPIO pins. Allow them to be controlled by GPIO framework.

IRQs are handled by regmap-irq and GPIO driver is not aware of the irq usage.

This is overall a very nicely written driver.

Just small comments:

drivers/gpio/gpio-bd70528.c line 6

Quoted 2 lines
drivers/gpio/gpio-bd70528.c new file +2 -0
+#include <linux/gpio/driver.h>
+#include <linux/interrupt.h>

Why interrupt? You do not use it.

drivers/gpio/gpio-bd70528.c line 52

Quoted 6 lines
drivers/gpio/gpio-bd70528.c new file +6 -0
+static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
+       struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+       int val, ret;
+
+       /* Do we need to do something to IRQs here? */

Well you don't support IRQs yet so no problem as long as they're masked?

drivers/gpio/gpio-bd70528.c line 63

Quoted 11 lines
drivers/gpio/gpio-bd70528.c new file +11 -0
+       ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val);
+       if (ret) {
+               dev_err(bdgpio->chip.dev, "Could not read gpio direction\n");
+               return ret;
+       }
+
+       return !(val & BD70528_GPIO_OUT_EN_MASK);
+}
+
+static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
+                                  unsigned long config)

This is very nice. With Thomas Petazzoni's ongoing work you will be able to also support pull up/down if you need it.

drivers/gpio/gpio-bd70528.c line 94

Quoted 5 lines
drivers/gpio/gpio-bd70528.c new file +5 -0
+static int bd70528_direction_input(struct gpio_chip *chip, unsigned int offset)
+{
+       struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+
+       /* Do we need to do something to IRQs here? */

Hmmm?

Apart from that it looks good. Feel free to add:

on the next iteration.

Yours,
Linus Walleij

#2 lore raw
Quoted 3 lines · Linus Walleij

Hi Matti!

Thanks for your patch!

No, thank you for the review =)

Quoted 11 lines
Quoted 7 lines · Matti Vaittinen

ROHM BD70528 PMIC has 4 GPIO pins. Allow them to be controlled by GPIO framework.

IRQs are handled by regmap-irq and GPIO driver is not aware of the irq usage.

Quoted 8 lines

This is overall a very nicely written driver.

Just small comments:

drivers/gpio/gpio-bd70528.c line 6

Quoted 2 lines
drivers/gpio/gpio-bd70528.c new file +2 -0
+#include <linux/gpio/driver.h>
+#include <linux/interrupt.h>

Why interrupt? You do not use it.

Right, I'd better to drop it.

Quoted 9 lines

drivers/gpio/gpio-bd70528.c line 52

Quoted 7 lines
drivers/gpio/gpio-bd70528.c new file +6 -0
+static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
+       struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+       int val, ret;
+
+       /* Do we need to do something to IRQs here? */

Well you don't support IRQs yet so no problem as long as they're masked?

I may have not worded this correctly. These pins can be used for IRQs. HW supports it and I added the irq registers in regmap-irq controller (please see the MFD part). It's just that this GPIO driver is currently not aware of that. This comment here is a reminder for me to figure out if we should look whether the pin is used for I/O or for irqs here - and what should we return if pin is configured to be used for IRQs.

Quoted 15 lines

drivers/gpio/gpio-bd70528.c line 63

Quoted 11 lines
drivers/gpio/gpio-bd70528.c new file +11 -0
+       ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val);
+       if (ret) {
+               dev_err(bdgpio->chip.dev, "Could not read gpio direction\n");
+               return ret;
+       }
+
+       return !(val & BD70528_GPIO_OUT_EN_MASK);
+}
+
+static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
+                                  unsigned long config)

This is very nice. With Thomas Petazzoni's ongoing work you will be able to also support pull up/down if you need it.

Quoted 7 lines

drivers/gpio/gpio-bd70528.c line 94

Quoted 5 lines
drivers/gpio/gpio-bd70528.c new file +5 -0
+static int bd70528_direction_input(struct gpio_chip *chip, unsigned int offset)
+{
+       struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+
+       /* Do we need to do something to IRQs here? */

Hmmm?

Same thing as with the get_direction. Should we allow setting the direction if pin is already configured as an irq source? Should we somehow try to warn user if it seems the pin is tried to be used for both irqs and I/O?

Quoted 4 lines

Apart from that it looks good. Feel free to add:

on the next iteration.

I will need to do some further testing on this before submitting next version. I will gladly maintain your Reviewed-by if I don't do any bigger changes to the driver - but if I do I'll drop your tag and ask for re-review :)

Br,
Matti Vaittinen