Re: [PATCH 4/5] gpio: Add support for LMP92001 GPIO
On Tue, Aug 1, 2017 at 11:15 AM,wrote: > From: Abhisit Sangjan That is a bit terse commit message for an entire new driver. Elaborate some please. > +#include #include ONLY please. > +#include > +#include > +#include > +#include Why? Supporting old kernels? We don't do that upstream. Add this: #include (See below) > +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. > + > +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); > +return (val >> offset) & 1; Do this: return !!(val (offset)); > +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
Re: [PATCH 4/5] gpio: Add support for LMP92001 GPIO
On Tue, Aug 1, 2017 at 11:15 AM, wrote: > From: Abhisit Sangjan That is a bit terse commit message for an entire new driver. Elaborate some please. > +#include #include ONLY please. > +#include > +#include > +#include > +#include Why? Supporting old kernels? We don't do that upstream. Add this: #include (See below) > +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. > + > +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); > +return (val >> offset) & 1; Do this: return !!(val (offset)); > +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
[PATCH 4/5] gpio: Add support for LMP92001 GPIO
From: Abhisit Sangjan--- 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 diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index f235eae..b9b5c97 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -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" diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index a9fda6c..153daea 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -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 diff --git a/drivers/gpio/gpio-lmp92001.c b/drivers/gpio/gpio-lmp92001.c new file mode 100644 index 000..ac0eb4d5 --- /dev/null +++ b/drivers/gpio/gpio-lmp92001.c @@ -0,0 +1,235 @@ +/* + * gpio-lmp92001.c - Support for TI LMP92001 GPIOs + * + * Copyright 2016-2017 Celestica Ltd. + * + * Author: Abhisit Sangjan + * + * Inspired by wm831x driver. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +struct lmp92001_gpio { +struct lmp92001 *lmp92001; +struct gpio_chip gpio_chip; +}; + +static inline struct lmp92001_gpio *to_lmp92001_gpio(struct gpio_chip *chip) +{ +return container_of(chip, struct lmp92001_gpio, gpio_chip); +} + +static int lmp92001_gpio_get_direction(struct gpio_chip *chip, unsigned offset) +{ +struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip); +struct lmp92001 *lmp92001 = lmp92001_gpio->lmp92001; +unsigned int val; +int ret; + +ret = regmap_read(lmp92001->regmap, LMP92001_CGPO, ); +if (ret < 0) +return ret; + +return (val >> offset) & 1; +} + +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); +} + +static int lmp92001_gpio_get(struct gpio_chip *chip, unsigned offset) +{ +struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip); +struct lmp92001 *lmp92001 = lmp92001_gpio->lmp92001; +unsigned int val, sgen; + +/* + * Does the GPIO input mode? + * Does the GPIO was set? + * Reading indicated logic level. + * Clear indicated logic level. + */ +regmap_read(lmp92001->regmap, LMP92001_CGPO, ); +if ((val >> offset) & 1) +{ +regmap_read(lmp92001->regmap, LMP92001_SGEN, ); +if (sgen & 1) +{ +regmap_read(lmp92001->regmap, LMP92001_SGPI, ); +regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, +0xFF, val); +} +} + +return (val >> offset) & 1; +} + +static int lmp92001_gpio_direction_out(struct gpio_chip *chip, unsigned offset, +int value) +{ +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, +0 << offset); +} + +static void lmp92001_gpio_set(struct gpio_chip *chip, unsigned offset, +int value) +{ +struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip); +struct lmp92001 *lmp92001 = lmp92001_gpio->lmp92001; + +regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, 1 << offset, +value << offset); +}
[PATCH 4/5] gpio: Add support for LMP92001 GPIO
From: Abhisit Sangjan --- 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 diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index f235eae..b9b5c97 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -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" diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index a9fda6c..153daea 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -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 diff --git a/drivers/gpio/gpio-lmp92001.c b/drivers/gpio/gpio-lmp92001.c new file mode 100644 index 000..ac0eb4d5 --- /dev/null +++ b/drivers/gpio/gpio-lmp92001.c @@ -0,0 +1,235 @@ +/* + * gpio-lmp92001.c - Support for TI LMP92001 GPIOs + * + * Copyright 2016-2017 Celestica Ltd. + * + * Author: Abhisit Sangjan + * + * Inspired by wm831x driver. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +struct lmp92001_gpio { +struct lmp92001 *lmp92001; +struct gpio_chip gpio_chip; +}; + +static inline struct lmp92001_gpio *to_lmp92001_gpio(struct gpio_chip *chip) +{ +return container_of(chip, struct lmp92001_gpio, gpio_chip); +} + +static int lmp92001_gpio_get_direction(struct gpio_chip *chip, unsigned offset) +{ +struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip); +struct lmp92001 *lmp92001 = lmp92001_gpio->lmp92001; +unsigned int val; +int ret; + +ret = regmap_read(lmp92001->regmap, LMP92001_CGPO, ); +if (ret < 0) +return ret; + +return (val >> offset) & 1; +} + +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); +} + +static int lmp92001_gpio_get(struct gpio_chip *chip, unsigned offset) +{ +struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip); +struct lmp92001 *lmp92001 = lmp92001_gpio->lmp92001; +unsigned int val, sgen; + +/* + * Does the GPIO input mode? + * Does the GPIO was set? + * Reading indicated logic level. + * Clear indicated logic level. + */ +regmap_read(lmp92001->regmap, LMP92001_CGPO, ); +if ((val >> offset) & 1) +{ +regmap_read(lmp92001->regmap, LMP92001_SGEN, ); +if (sgen & 1) +{ +regmap_read(lmp92001->regmap, LMP92001_SGPI, ); +regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, +0xFF, val); +} +} + +return (val >> offset) & 1; +} + +static int lmp92001_gpio_direction_out(struct gpio_chip *chip, unsigned offset, +int value) +{ +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, +0 << offset); +} + +static void lmp92001_gpio_set(struct gpio_chip *chip, unsigned offset, +int value) +{ +struct lmp92001_gpio *lmp92001_gpio = to_lmp92001_gpio(chip); +struct lmp92001 *lmp92001 = lmp92001_gpio->lmp92001; + +regmap_update_bits(lmp92001->regmap, LMP92001_CGPO, 1 << offset, +value << offset); +} + +#ifdef CONFIG_DEBUG_FS +static void