Skip to contentSkip to conversation

gpio: Add support for LMP92001 GPIO

PATCH In review [email protected] 2 participants 2 messages Aug 1, 2017 – Aug 7, 2017 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 4/5 gpio: Add support for LMP92001 GPIO

From: Abhisit Sangjan <[email protected]>

---
 drivers/gpio/Kconfig         |   7 ++
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-lmp92001.c | 235 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 243 insertions(+)
 create mode 100644 drivers/gpio/gpio-lmp92001.c
drivers/gpio/Kconfig +7 -0
index f235eae..b9b5c97 100644
@@ -1119,6 +1119,13 @@ config GPIO_WM8994
 	  Say yes here to access the GPIO signals of WM8994 audio hub
 	  CODECs from Wolfson Microelectronics.
 
+config GPIO_LMP92001
+       tristate "LMP92001 GPIOs"
+       depends on MFD_LMP92001
+       help
+         Say yes here to access the GPIO signals of TI LMP92001 Analog System
+         Monitor and Controller.
+
 endmenu
 
 menu "PCI GPIO expanders"
drivers/gpio/Makefile +1 -0
index a9fda6c..153daea 100644
@@ -148,3 +148,4 @@ obj-$(CONFIG_GPIO_ZEVIO)	+= gpio-zevio.o
 obj-$(CONFIG_GPIO_ZYNQ)		+= gpio-zynq.o
 obj-$(CONFIG_GPIO_ZX)		+= gpio-zx.o
 obj-$(CONFIG_GPIO_LOONGSON1)	+= gpio-loongson1.o
+obj-$(CONFIG_GPIO_LMP92001)	+= gpio-lmp92001.o
drivers/gpio/gpio-lmp92001.c new file +235 -0

235 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw
Quoted 1 line · On Tue, Aug 1, 2017 at 11:15 AM, <[email protected]> wrote:

From: Abhisit Sangjan <[email protected]>

That is a bit terse commit message for an entire new driver. Elaborate some please.

Quoted 1 line

+#include <linux/gpio.h>

#include <linux/gpio/driver.h>

ONLY please.

drivers/gpio/gpio-lmp92001.c line 28

Quoted 4 lines
drivers/gpio/gpio-lmp92001.c new file +4 -0
+#include <linux/platform_device.h>
+#include <linux/seq_file.h>
+#include <linux/mfd/core.h>
+#include <linux/version.h>

Why? Supporting old kernels? We don't do that upstream.

Add this:
#include <linux/bitops.h>

(See below)

drivers/gpio/gpio-lmp92001.c line 40

Quoted 4 lines
drivers/gpio/gpio-lmp92001.c new file +4 -0
+static inline struct lmp92001_gpio *to_lmp92001_gpio(struct gpio_chip *chip)
+{
+        return container_of(chip, struct lmp92001_gpio, gpio_chip);
+}

Do not use this. Use the new devm_gpiochip_add_data() and pass a state container as you data pointer.

drivers/gpio/gpio-lmp92001.c line 44

Quoted 4 lines
drivers/gpio/gpio-lmp92001.c new file +4 -0
+
+static int lmp92001_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
+{
+        struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip);

Then use this:
struct lmp92001_gpio *lmp92001_gpio = gpiochip_get_data(chip);

Quoted 1 line

+ return (val >> offset) & 1;

Do this:

return !!(val &BIT(offset));

drivers/gpio/gpio-lmp92001.c line 62

Quoted 7 lines
drivers/gpio/gpio-lmp92001.c new file +7 -0
+static int lmp92001_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
+{
+        struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip);
+        struct lmp92001 *lmp92001 =  lmp92001_gpio->lmp92001;
+
+        return regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, 1 << offset,
+                        1 << offset);

return regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, BIT(offset), BIT(offset));

But seriously: why do you need to mask the bit even?

return regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, 0, BIT(offset));

should work shouldn't it?

Use the bitops BIT() and state container gpiochip_get_data() and resend and I will look at more details.

Yours,
Linus Walleij