diff options
author | Marek Vasut <marek.vasut@gmail.com> | 2017-04-25 14:32:09 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2017-04-28 03:47:46 -0400 |
commit | 9384793036afb7529c1c564e839ef4356271d68e (patch) | |
tree | 2fedafe17393b8fade189710790b72dc4d643d72 | |
parent | 881ebd229f4a5ea88f269c1225245e50db9ba303 (diff) |
gpio: Add ROHM BD9571MWV-M PMIC GPIO driver
Add driver for the GPIO block in the ROHM BD9571MWV-W MFD PMIC.
This block is pretty trivial and supports setting GPIO direction
as Input/Output and in case of Output, supports setting value.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: linux-gpio@vger.kernel.org
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/gpio/Kconfig | 11 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/gpio-bd9571mwv.c | 144 |
3 files changed, 156 insertions, 0 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index c0629e6639fa..5662b0580777 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -844,6 +844,17 @@ config GPIO_ARIZONA | |||
844 | help | 844 | help |
845 | Support for GPIOs on Wolfson Arizona class devices. | 845 | Support for GPIOs on Wolfson Arizona class devices. |
846 | 846 | ||
847 | config GPIO_BD9571MWV | ||
848 | tristate "ROHM BD9571 GPIO support" | ||
849 | depends on MFD_BD9571MWV | ||
850 | help | ||
851 | Support for GPIOs on ROHM BD9571 PMIC. There are two GPIOs | ||
852 | available on the ROHM PMIC in total, both of which can also | ||
853 | generate interrupts. | ||
854 | |||
855 | This driver can also be built as a module. If so, the module | ||
856 | will be called gpio-bd9571mwv. | ||
857 | |||
847 | config GPIO_CRYSTAL_COVE | 858 | config GPIO_CRYSTAL_COVE |
848 | tristate "GPIO support for Crystal Cove PMIC" | 859 | tristate "GPIO support for Crystal Cove PMIC" |
849 | depends on (X86 || COMPILE_TEST) && INTEL_SOC_PMIC | 860 | depends on (X86 || COMPILE_TEST) && INTEL_SOC_PMIC |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 095598e856ca..68b96277d9fa 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -33,6 +33,7 @@ obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o | |||
33 | obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o | 33 | obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o |
34 | obj-$(CONFIG_GPIO_AXP209) += gpio-axp209.o | 34 | obj-$(CONFIG_GPIO_AXP209) += gpio-axp209.o |
35 | obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o | 35 | obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o |
36 | obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o | ||
36 | obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o | 37 | obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o |
37 | obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o | 38 | obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o |
38 | obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o | 39 | obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o |
diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c new file mode 100644 index 000000000000..5224a946e8ab --- /dev/null +++ b/drivers/gpio/gpio-bd9571mwv.c | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | * ROHM BD9571MWV-M GPIO driver | ||
3 | * | ||
4 | * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
11 | * kind, whether expressed or implied; without even the implied warranty | ||
12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License version 2 for more details. | ||
14 | * | ||
15 | * Based on the TPS65086 driver | ||
16 | * | ||
17 | * NOTE: Interrupts are not supported yet. | ||
18 | */ | ||
19 | |||
20 | #include <linux/gpio/driver.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | |||
24 | #include <linux/mfd/bd9571mwv.h> | ||
25 | |||
26 | struct bd9571mwv_gpio { | ||
27 | struct gpio_chip chip; | ||
28 | struct bd9571mwv *bd; | ||
29 | }; | ||
30 | |||
31 | static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip, | ||
32 | unsigned int offset) | ||
33 | { | ||
34 | struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); | ||
35 | int ret, val; | ||
36 | |||
37 | ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, &val); | ||
38 | if (ret < 0) | ||
39 | return ret; | ||
40 | |||
41 | return val & BIT(offset); | ||
42 | } | ||
43 | |||
44 | static int bd9571mwv_gpio_direction_input(struct gpio_chip *chip, | ||
45 | unsigned int offset) | ||
46 | { | ||
47 | struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); | ||
48 | |||
49 | regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR, | ||
50 | BIT(offset), 0); | ||
51 | |||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static int bd9571mwv_gpio_direction_output(struct gpio_chip *chip, | ||
56 | unsigned int offset, int value) | ||
57 | { | ||
58 | struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); | ||
59 | |||
60 | /* Set the initial value */ | ||
61 | regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT, | ||
62 | BIT(offset), value ? BIT(offset) : 0); | ||
63 | regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR, | ||
64 | BIT(offset), BIT(offset)); | ||
65 | |||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset) | ||
70 | { | ||
71 | struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); | ||
72 | int ret, val; | ||
73 | |||
74 | ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, &val); | ||
75 | if (ret < 0) | ||
76 | return ret; | ||
77 | |||
78 | return val & BIT(offset); | ||
79 | } | ||
80 | |||
81 | static void bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset, | ||
82 | int value) | ||
83 | { | ||
84 | struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip); | ||
85 | |||
86 | regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT, | ||
87 | BIT(offset), value ? BIT(offset) : 0); | ||
88 | } | ||
89 | |||
90 | static const struct gpio_chip template_chip = { | ||
91 | .label = "bd9571mwv-gpio", | ||
92 | .owner = THIS_MODULE, | ||
93 | .get_direction = bd9571mwv_gpio_get_direction, | ||
94 | .direction_input = bd9571mwv_gpio_direction_input, | ||
95 | .direction_output = bd9571mwv_gpio_direction_output, | ||
96 | .get = bd9571mwv_gpio_get, | ||
97 | .set = bd9571mwv_gpio_set, | ||
98 | .base = -1, | ||
99 | .ngpio = 2, | ||
100 | .can_sleep = true, | ||
101 | }; | ||
102 | |||
103 | static int bd9571mwv_gpio_probe(struct platform_device *pdev) | ||
104 | { | ||
105 | struct bd9571mwv_gpio *gpio; | ||
106 | int ret; | ||
107 | |||
108 | gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); | ||
109 | if (!gpio) | ||
110 | return -ENOMEM; | ||
111 | |||
112 | platform_set_drvdata(pdev, gpio); | ||
113 | |||
114 | gpio->bd = dev_get_drvdata(pdev->dev.parent); | ||
115 | gpio->chip = template_chip; | ||
116 | gpio->chip.parent = gpio->bd->dev; | ||
117 | |||
118 | ret = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio); | ||
119 | if (ret < 0) { | ||
120 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | ||
121 | return ret; | ||
122 | } | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static const struct platform_device_id bd9571mwv_gpio_id_table[] = { | ||
128 | { "bd9571mwv-gpio", }, | ||
129 | { /* sentinel */ } | ||
130 | }; | ||
131 | MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table); | ||
132 | |||
133 | static struct platform_driver bd9571mwv_gpio_driver = { | ||
134 | .driver = { | ||
135 | .name = "bd9571mwv-gpio", | ||
136 | }, | ||
137 | .probe = bd9571mwv_gpio_probe, | ||
138 | .id_table = bd9571mwv_gpio_id_table, | ||
139 | }; | ||
140 | module_platform_driver(bd9571mwv_gpio_driver); | ||
141 | |||
142 | MODULE_AUTHOR("Marek Vasut <marek.vasut+renesas@gmail.com>"); | ||
143 | MODULE_DESCRIPTION("BD9571MWV GPIO driver"); | ||
144 | MODULE_LICENSE("GPL v2"); | ||