* [PATCH v2 0/4] Add AXP209 GPIO driver
@ 2016-07-20 14:11 Maxime Ripard
2016-07-20 14:11 ` [PATCH v2 1/4] gpio: " Maxime Ripard
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Maxime Ripard @ 2016-07-20 14:11 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
The axp209 PMIC used in combination to some Allwinner SoCs has a bunch
of GPIOs accessible. Some boards use these to control their backlight
or a few LEDs.
There's supposed to be 4 of them, but the fourth one has a different
configuration register scheme, and I couldn't find any board that was
using this GPIO. It will be probably be supported eventually, but
until then, we support only the first 3 GPIOs.
Let me know what you think,
Maxime
Changes from v1:
- Use gpiochip_add_data and gpiochip_get_data
- Drop unneeded headers
- Make sure gpio_get returns 0 or 1
- Made sure it compiles
- Rebased on linux-next
Maxime Ripard (4):
gpio: Add AXP209 GPIO driver
mfd: axp20x: Add AXP209 GPIO driver to the mfd
ARM: dt: axp209: Add AXP209 GPIO driver
ARM: sun5i: chip: Add status LED
.../devicetree/bindings/gpio/gpio-axp209.txt | 30 ++++
arch/arm/boot/dts/axp209.dtsi | 6 +
arch/arm/boot/dts/sun5i-r8-chip.dts | 10 ++
drivers/gpio/Kconfig | 6 +
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-axp209.c | 162 +++++++++++++++++++++
drivers/mfd/axp20x.c | 3 +
7 files changed, 218 insertions(+)
create mode 100644 Documentation/devicetree/bindings/gpio/gpio-axp209.txt
create mode 100644 drivers/gpio/gpio-axp209.c
--
2.9.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 1/4] gpio: Add AXP209 GPIO driver 2016-07-20 14:11 [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard @ 2016-07-20 14:11 ` Maxime Ripard 2016-08-11 8:28 ` Linus Walleij 2016-07-20 14:11 ` [PATCH v2 2/4] mfd: axp20x: Add AXP209 GPIO driver to the mfd Maxime Ripard ` (3 subsequent siblings) 4 siblings, 1 reply; 8+ messages in thread From: Maxime Ripard @ 2016-07-20 14:11 UTC (permalink / raw) To: linux-arm-kernel The AXP209 PMIC has a bunch of GPIOs accessible, that are usually used to control LEDs or backlight. Add a driver for them Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Acked-by: Rob Herring <robh@kernel.org> --- .../devicetree/bindings/gpio/gpio-axp209.txt | 30 ++++ drivers/gpio/Kconfig | 6 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-axp209.c | 162 +++++++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-axp209.txt create mode 100644 drivers/gpio/gpio-axp209.c diff --git a/Documentation/devicetree/bindings/gpio/gpio-axp209.txt b/Documentation/devicetree/bindings/gpio/gpio-axp209.txt new file mode 100644 index 000000000000..a6611304dd3c --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-axp209.txt @@ -0,0 +1,30 @@ +AXP209 GPIO controller + +This driver follows the usual GPIO bindings found in +Documentation/devicetree/bindings/gpio/gpio.txt + +Required properties: +- compatible: Should be "x-powers,axp209-gpio" +- #gpio-cells: Should be two. The first cell is the pin number and the + second is the GPIO flags. +- gpio-controller: Marks the device node as a GPIO controller. + +This node must be a subnode of the axp20x PMIC, documented in +Documentation/devicetree/bindings/mfd/axp20x.txt + +Example: + +axp209: pmic at 34 { + compatible = "x-powers,axp209"; + reg = <0x34>; + interrupt-parent = <&nmi_intc>; + interrupts = <0 IRQ_TYPE_LEVEL_LOW>; + interrupt-controller; + #interrupt-cells = <1>; + + axp_gpio: gpio { + compatible = "x-powers,axp209-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; +}; diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 98dd47a30fc7..7d8995b88330 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -137,6 +137,12 @@ config GPIO_ATH79 Select this option to enable GPIO driver for Atheros AR71XX/AR724X/AR913X SoC devices. +config GPIO_AXP209 + tristate "X-Powers AXP209 PMIC GPIO Support" + depends on MFD_AXP20X + help + Say yes to enable GPIO support for the AXP209 PMIC + config GPIO_BCM_KONA bool "Broadcom Kona GPIO" depends on OF_GPIO && (ARCH_BCM_MOBILE || COMPILE_TEST) diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 2a035ed8f168..b7d509e27ed1 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o +obj-$(CONFIG_GPIO_AXP209) += gpio-axp209.o obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o diff --git a/drivers/gpio/gpio-axp209.c b/drivers/gpio/gpio-axp209.c new file mode 100644 index 000000000000..3174799c27c6 --- /dev/null +++ b/drivers/gpio/gpio-axp209.c @@ -0,0 +1,162 @@ +/* + * AXP20x GPIO driver + * + * Copyright (C) 2016 Maxime Ripard <maxime.ripard@free-electrons.com> + * + * 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. + */ + +#include <linux/bitops.h> +#include <linux/device.h> +#include <linux/gpio/driver.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/mfd/axp20x.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/slab.h> + +#define AXP20X_GPIO_FUNCTIONS 0x7 +#define AXP20X_GPIO_FUNCTION_OUT_LOW 0 +#define AXP20X_GPIO_FUNCTION_OUT_HIGH 1 +#define AXP20X_GPIO_FUNCTION_INPUT 2 + +struct axp20x_gpio { + struct gpio_chip chip; + struct regmap *regmap; +}; + +static int axp20x_gpio_get_reg(unsigned offset) +{ + switch (offset) { + case 0: + return AXP20X_GPIO0_CTRL; + case 1: + return AXP20X_GPIO1_CTRL; + case 2: + return AXP20X_GPIO2_CTRL; + } + + return -EINVAL; +} + +static int axp20x_gpio_input(struct gpio_chip *chip, unsigned offset) +{ + struct axp20x_gpio *gpio = gpiochip_get_data(chip); + int reg; + + reg = axp20x_gpio_get_reg(offset); + if (reg < 0) + return reg; + + return regmap_update_bits(gpio->regmap, reg, + AXP20X_GPIO_FUNCTIONS, + AXP20X_GPIO_FUNCTION_INPUT); +} + +static int axp20x_gpio_get(struct gpio_chip *chip, unsigned offset) +{ + struct axp20x_gpio *gpio = gpiochip_get_data(chip); + unsigned int val; + int reg, ret; + + reg = axp20x_gpio_get_reg(offset); + if (reg < 0) + return reg; + + ret = regmap_read(gpio->regmap, reg, &val); + if (ret) + return ret; + + return !!(val & BIT(offset + 4)); +} + +static int axp20x_gpio_output(struct gpio_chip *chip, unsigned offset, + int value) +{ + struct axp20x_gpio *gpio = gpiochip_get_data(chip); + int reg; + + reg = axp20x_gpio_get_reg(offset); + if (reg < 0) + return reg; + + return regmap_update_bits(gpio->regmap, reg, + AXP20X_GPIO_FUNCTIONS, + value ? AXP20X_GPIO_FUNCTION_OUT_HIGH + : AXP20X_GPIO_FUNCTION_OUT_LOW); +} + +static void axp20x_gpio_set(struct gpio_chip *chip, unsigned offset, + int value) +{ + axp20x_gpio_output(chip, offset, value); +} + +static int axp20x_gpio_probe(struct platform_device *pdev) +{ + struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); + struct axp20x_gpio *gpio; + int ret; + + if (!of_device_is_available(pdev->dev.of_node)) + return -ENODEV; + + if (!axp20x) { + dev_err(&pdev->dev, "Parent drvdata not set\n"); + return -EINVAL; + } + + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); + if (!gpio) + return -ENOMEM; + + gpio->chip.base = -1; + gpio->chip.can_sleep = true; + gpio->chip.parent = &pdev->dev; + gpio->chip.label = dev_name(&pdev->dev); + gpio->chip.owner = THIS_MODULE; + gpio->chip.get = axp20x_gpio_get; + gpio->chip.set = axp20x_gpio_set; + gpio->chip.direction_input = axp20x_gpio_input; + gpio->chip.direction_output = axp20x_gpio_output; + gpio->chip.ngpio = 3; + + gpio->regmap = axp20x->regmap; + + ret = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); + if (ret) { + dev_err(&pdev->dev, "Failed to register GPIO chip\n"); + return ret; + } + + dev_info(&pdev->dev, "AXP209 GPIO driver loaded\n"); + + return 0; +} + +static const struct of_device_id axp20x_gpio_match[] = { + { .compatible = "x-powers,axp209-gpio" }, + { } +}; +MODULE_DEVICE_TABLE(of, axp20x_gpio_match); + +static struct platform_driver axp20x_gpio_driver = { + .probe = axp20x_gpio_probe, + .driver = { + .name = "axp20x-gpio", + .of_match_table = axp20x_gpio_match, + }, +}; + +module_platform_driver(axp20x_gpio_driver); + +MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); +MODULE_DESCRIPTION("AXP20x PMIC GPIO driver"); +MODULE_LICENSE("GPL"); -- 2.9.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 1/4] gpio: Add AXP209 GPIO driver 2016-07-20 14:11 ` [PATCH v2 1/4] gpio: " Maxime Ripard @ 2016-08-11 8:28 ` Linus Walleij 0 siblings, 0 replies; 8+ messages in thread From: Linus Walleij @ 2016-08-11 8:28 UTC (permalink / raw) To: linux-arm-kernel On Wed, Jul 20, 2016 at 4:11 PM, Maxime Ripard <maxime.ripard@free-electrons.com> wrote: > The AXP209 PMIC has a bunch of GPIOs accessible, that are usually used to > control LEDs or backlight. > > Add a driver for them > > Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> > Acked-by: Rob Herring <robh@kernel.org> Patch applied, it's clean and simple. I would suggest the following immediate improvement (send separate patch): Add a .get_direction() callback, I have started to push this for new driver as it gives better userspace experience and overall better control of stuff. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] mfd: axp20x: Add AXP209 GPIO driver to the mfd 2016-07-20 14:11 [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard 2016-07-20 14:11 ` [PATCH v2 1/4] gpio: " Maxime Ripard @ 2016-07-20 14:11 ` Maxime Ripard 2016-08-09 9:58 ` Lee Jones 2016-07-20 14:11 ` [PATCH v2 3/4] ARM: dt: axp209: Add AXP209 GPIO driver Maxime Ripard ` (2 subsequent siblings) 4 siblings, 1 reply; 8+ messages in thread From: Maxime Ripard @ 2016-07-20 14:11 UTC (permalink / raw) To: linux-arm-kernel Now that we have a GPIO driver for the AXP209, we can add it to our MFD. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/mfd/axp20x.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c index fd80b0981f0f..4b3e073c47b7 100644 --- a/drivers/mfd/axp20x.c +++ b/drivers/mfd/axp20x.c @@ -508,6 +508,9 @@ static const struct regmap_irq_chip axp809_regmap_irq_chip = { static struct mfd_cell axp20x_cells[] = { { + .name = "axp20x-gpio", + .of_compatible = "x-powers,axp209-gpio", + }, { .name = "axp20x-pek", .num_resources = ARRAY_SIZE(axp20x_pek_resources), .resources = axp20x_pek_resources, -- 2.9.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] mfd: axp20x: Add AXP209 GPIO driver to the mfd 2016-07-20 14:11 ` [PATCH v2 2/4] mfd: axp20x: Add AXP209 GPIO driver to the mfd Maxime Ripard @ 2016-08-09 9:58 ` Lee Jones 0 siblings, 0 replies; 8+ messages in thread From: Lee Jones @ 2016-08-09 9:58 UTC (permalink / raw) To: linux-arm-kernel On Wed, 20 Jul 2016, Maxime Ripard wrote: > Now that we have a GPIO driver for the AXP209, we can add it to our MFD. > > Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> > Acked-by: Linus Walleij <linus.walleij@linaro.org> > --- > drivers/mfd/axp20x.c | 3 +++ > 1 file changed, 3 insertions(+) Applied, thanks. > diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c > index fd80b0981f0f..4b3e073c47b7 100644 > --- a/drivers/mfd/axp20x.c > +++ b/drivers/mfd/axp20x.c > @@ -508,6 +508,9 @@ static const struct regmap_irq_chip axp809_regmap_irq_chip = { > > static struct mfd_cell axp20x_cells[] = { > { > + .name = "axp20x-gpio", > + .of_compatible = "x-powers,axp209-gpio", > + }, { > .name = "axp20x-pek", > .num_resources = ARRAY_SIZE(axp20x_pek_resources), > .resources = axp20x_pek_resources, -- Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 3/4] ARM: dt: axp209: Add AXP209 GPIO driver 2016-07-20 14:11 [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard 2016-07-20 14:11 ` [PATCH v2 1/4] gpio: " Maxime Ripard 2016-07-20 14:11 ` [PATCH v2 2/4] mfd: axp20x: Add AXP209 GPIO driver to the mfd Maxime Ripard @ 2016-07-20 14:11 ` Maxime Ripard 2016-07-20 14:11 ` [PATCH v2 4/4] ARM: sun5i: chip: Add status LED Maxime Ripard 2016-08-22 13:36 ` [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard 4 siblings, 0 replies; 8+ messages in thread From: Maxime Ripard @ 2016-07-20 14:11 UTC (permalink / raw) To: linux-arm-kernel Add the AXP209 GPIO node to our AXP209 DTSI so that boards can use it. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> --- arch/arm/boot/dts/axp209.dtsi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/boot/dts/axp209.dtsi b/arch/arm/boot/dts/axp209.dtsi index afbe89c01df5..675bb0f30825 100644 --- a/arch/arm/boot/dts/axp209.dtsi +++ b/arch/arm/boot/dts/axp209.dtsi @@ -53,6 +53,12 @@ interrupt-controller; #interrupt-cells = <1>; + axp_gpio: gpio { + compatible = "x-powers,axp209-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; + regulators { /* Default work frequency for buck regulators */ x-powers,dcdc-freq = <1500>; -- 2.9.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/4] ARM: sun5i: chip: Add status LED 2016-07-20 14:11 [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard ` (2 preceding siblings ...) 2016-07-20 14:11 ` [PATCH v2 3/4] ARM: dt: axp209: Add AXP209 GPIO driver Maxime Ripard @ 2016-07-20 14:11 ` Maxime Ripard 2016-08-22 13:36 ` [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard 4 siblings, 0 replies; 8+ messages in thread From: Maxime Ripard @ 2016-07-20 14:11 UTC (permalink / raw) To: linux-arm-kernel The CHIP has a status LED connected to one of the AXP GPIOs. Add the gpio-leds node to be able to use the proper LED framework to control it. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> --- arch/arm/boot/dts/sun5i-r8-chip.dts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/boot/dts/sun5i-r8-chip.dts b/arch/arm/boot/dts/sun5i-r8-chip.dts index f694482bdeb6..b68a12374b35 100644 --- a/arch/arm/boot/dts/sun5i-r8-chip.dts +++ b/arch/arm/boot/dts/sun5i-r8-chip.dts @@ -64,6 +64,16 @@ chosen { stdout-path = "serial0:115200n8"; }; + + leds { + compatible = "gpio-leds"; + + status { + label = "chip:white:status"; + gpios = <&axp_gpio 2 GPIO_ACTIVE_HIGH>; + default-state = "on"; + }; + }; }; &be0 { -- 2.9.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 0/4] Add AXP209 GPIO driver 2016-07-20 14:11 [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard ` (3 preceding siblings ...) 2016-07-20 14:11 ` [PATCH v2 4/4] ARM: sun5i: chip: Add status LED Maxime Ripard @ 2016-08-22 13:36 ` Maxime Ripard 4 siblings, 0 replies; 8+ messages in thread From: Maxime Ripard @ 2016-08-22 13:36 UTC (permalink / raw) To: linux-arm-kernel On Wed, Jul 20, 2016 at 04:11:35PM +0200, Maxime Ripard wrote: > Hi, > > The axp209 PMIC used in combination to some Allwinner SoCs has a bunch > of GPIOs accessible. Some boards use these to control their backlight > or a few LEDs. > > There's supposed to be 4 of them, but the fourth one has a different > configuration register scheme, and I couldn't find any board that was > using this GPIO. It will be probably be supported eventually, but > until then, we support only the first 3 GPIOs. I merged the patches 3 and 4. Maxime -- Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160822/303fe1f7/attachment-0001.sig> ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-08-22 13:36 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-07-20 14:11 [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard 2016-07-20 14:11 ` [PATCH v2 1/4] gpio: " Maxime Ripard 2016-08-11 8:28 ` Linus Walleij 2016-07-20 14:11 ` [PATCH v2 2/4] mfd: axp20x: Add AXP209 GPIO driver to the mfd Maxime Ripard 2016-08-09 9:58 ` Lee Jones 2016-07-20 14:11 ` [PATCH v2 3/4] ARM: dt: axp209: Add AXP209 GPIO driver Maxime Ripard 2016-07-20 14:11 ` [PATCH v2 4/4] ARM: sun5i: chip: Add status LED Maxime Ripard 2016-08-22 13:36 ` [PATCH v2 0/4] Add AXP209 GPIO driver Maxime Ripard
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).