diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-29 14:53:11 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-29 14:53:11 -0400 |
commit | 4b781474682434e7881f20e9dfbe6687ea619795 (patch) | |
tree | bdd976645ead7f04900e60017502e6a41b03e601 /drivers/gpio | |
parent | 53f2c4a8fd882009a2a75c5b72d6898c0808616e (diff) | |
parent | 29f772d41c01ad6b72c3de705e79779857badcde (diff) |
Merge tag 'mfd-3.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6
Pull MFD changes from Samuel Ortiz:
"Besides the usual cleanups, this one brings:
* Support for 5 new chipsets: Intel's ICH LPC and SCH Centerton,
ST-E's STAX211, Samsung's MAX77693 and TI's LM3533.
* Device tree support for the twl6040, tps65910, da9502 and ab8500
drivers.
* Fairly big tps56910, ab8500 and db8500 updates.
* i2c support for mc13xxx.
* Our regular update for the wm8xxx driver from Mark."
Fix up various conflicts with other trees, largely due to ab5500 removal
etc.
* tag 'mfd-3.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6: (106 commits)
mfd: Fix build break of max77693 by adding REGMAP_I2C option
mfd: Fix twl6040 build failure
mfd: Fix max77693 build failure
mfd: ab8500-core should depend on MFD_DB8500_PRCMU
gpio: tps65910: dt: process gpio specific device node info
mfd: Remove the parsing of dt info for tps65910 gpio
mfd: Save device node parsed platform data for tps65910 sub devices
mfd: Add r_select to lm3533 platform data
gpio: Add Intel Centerton support to gpio-sch
mfd: Emulate active low IRQs as well as active high IRQs for wm831x
mfd: Mark two lm3533 zone registers as volatile
mfd: Fix return type of lm533 attribute is_visible
mfd: Enable Device Tree support in the ab8500-pwm driver
mfd: Enable Device Tree support in the ab8500-sysctrl driver
mfd: Add support for Device Tree to twl6040
mfd: Register the twl6040 child for the ASoC codec unconditionally
mfd: Allocate twl6040 IRQ numbers dynamically
mfd: twl6040 code cleanup in interrupt initialization part
mfd: Enable ab8500-gpadc driver for Device Tree
mfd: Prevent unassigned pointer from being used in ab8500-gpadc driver
...
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/Kconfig | 30 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 2 | ||||
-rw-r--r-- | drivers/gpio/gpio-ich.c | 419 | ||||
-rw-r--r-- | drivers/gpio/gpio-sch.c | 8 | ||||
-rw-r--r-- | drivers/gpio/gpio-sta2x11.c | 435 | ||||
-rw-r--r-- | drivers/gpio/gpio-tps65910.c | 188 | ||||
-rw-r--r-- | drivers/gpio/gpio-wm831x.c | 6 |
7 files changed, 1037 insertions, 51 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index aa3642cb8209..0356099ae040 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -167,6 +167,14 @@ config GPIO_PXA | |||
167 | help | 167 | help |
168 | Say yes here to support the PXA GPIO device | 168 | Say yes here to support the PXA GPIO device |
169 | 169 | ||
170 | config GPIO_STA2X11 | ||
171 | bool "STA2x11/ConneXt GPIO support" | ||
172 | depends on MFD_STA2X11 | ||
173 | select GENERIC_IRQ_CHIP | ||
174 | help | ||
175 | Say yes here to support the STA2x11/ConneXt GPIO device. | ||
176 | The GPIO module has 128 GPIO pins with alternate functions. | ||
177 | |||
170 | config GPIO_XILINX | 178 | config GPIO_XILINX |
171 | bool "Xilinx GPIO support" | 179 | bool "Xilinx GPIO support" |
172 | depends on PPC_OF || MICROBLAZE | 180 | depends on PPC_OF || MICROBLAZE |
@@ -180,13 +188,13 @@ config GPIO_VR41XX | |||
180 | Say yes here to support the NEC VR4100 series General-purpose I/O Uint | 188 | Say yes here to support the NEC VR4100 series General-purpose I/O Uint |
181 | 189 | ||
182 | config GPIO_SCH | 190 | config GPIO_SCH |
183 | tristate "Intel SCH/TunnelCreek GPIO" | 191 | tristate "Intel SCH/TunnelCreek/Centerton GPIO" |
184 | depends on PCI && X86 | 192 | depends on PCI && X86 |
185 | select MFD_CORE | 193 | select MFD_CORE |
186 | select LPC_SCH | 194 | select LPC_SCH |
187 | help | 195 | help |
188 | Say yes here to support GPIO interface on Intel Poulsbo SCH | 196 | Say yes here to support GPIO interface on Intel Poulsbo SCH, |
189 | or Intel Tunnel Creek processor. | 197 | Intel Tunnel Creek processor or Intel Centerton processor. |
190 | The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are | 198 | The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are |
191 | powered by the core power rail and are turned off during sleep | 199 | powered by the core power rail and are turned off during sleep |
192 | modes (S3 and higher). The remaining four GPIOs are powered by | 200 | modes (S3 and higher). The remaining four GPIOs are powered by |
@@ -195,6 +203,22 @@ config GPIO_SCH | |||
195 | system from the Suspend-to-RAM state. | 203 | system from the Suspend-to-RAM state. |
196 | The Intel Tunnel Creek processor has 5 GPIOs powered by the | 204 | The Intel Tunnel Creek processor has 5 GPIOs powered by the |
197 | core power rail and 9 from suspend power supply. | 205 | core power rail and 9 from suspend power supply. |
206 | The Intel Centerton processor has a total of 30 GPIO pins. | ||
207 | Twenty-one are powered by the core power rail and 9 from the | ||
208 | suspend power supply. | ||
209 | |||
210 | config GPIO_ICH | ||
211 | tristate "Intel ICH GPIO" | ||
212 | depends on PCI && X86 | ||
213 | select MFD_CORE | ||
214 | select LPC_ICH | ||
215 | help | ||
216 | Say yes here to support the GPIO functionality of a number of Intel | ||
217 | ICH-based chipsets. Currently supported devices: ICH6, ICH7, ICH8 | ||
218 | ICH9, ICH10, Series 5/3400 (eg Ibex Peak), Series 6/C200 (eg | ||
219 | Cougar Point), NM10 (Tiger Point), and 3100 (Whitmore Lake). | ||
220 | |||
221 | If unsure, say N. | ||
198 | 222 | ||
199 | config GPIO_VX855 | 223 | config GPIO_VX855 |
200 | tristate "VIA VX855/VX875 GPIO" | 224 | tristate "VIA VX855/VX875 GPIO" |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 07a79e245407..fde36e5e3537 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -19,6 +19,7 @@ obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o | |||
19 | obj-$(CONFIG_GPIO_EM) += gpio-em.o | 19 | obj-$(CONFIG_GPIO_EM) += gpio-em.o |
20 | obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o | 20 | obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o |
21 | obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o | 21 | obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o |
22 | obj-$(CONFIG_GPIO_ICH) += gpio-ich.o | ||
22 | obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o | 23 | obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o |
23 | obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o | 24 | obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o |
24 | obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o | 25 | obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o |
@@ -51,6 +52,7 @@ obj-$(CONFIG_PLAT_SAMSUNG) += gpio-samsung.o | |||
51 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o | 52 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o |
52 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o | 53 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o |
53 | obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o | 54 | obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o |
55 | obj-$(CONFIG_GPIO_STA2X11) += gpio-sta2x11.o | ||
54 | obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o | 56 | obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o |
55 | obj-$(CONFIG_GPIO_SX150X) += gpio-sx150x.o | 57 | obj-$(CONFIG_GPIO_SX150X) += gpio-sx150x.o |
56 | obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o | 58 | obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o |
diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c new file mode 100644 index 000000000000..b7c06517403d --- /dev/null +++ b/drivers/gpio/gpio-ich.c | |||
@@ -0,0 +1,419 @@ | |||
1 | /* | ||
2 | * Intel ICH6-10, Series 5 and 6 GPIO driver | ||
3 | * | ||
4 | * Copyright (C) 2010 Extreme Engineering Solutions. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/pci.h> | ||
25 | #include <linux/gpio.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/mfd/lpc_ich.h> | ||
28 | |||
29 | #define DRV_NAME "gpio_ich" | ||
30 | |||
31 | /* | ||
32 | * GPIO register offsets in GPIO I/O space. | ||
33 | * Each chunk of 32 GPIOs is manipulated via its own USE_SELx, IO_SELx, and | ||
34 | * LVLx registers. Logic in the read/write functions takes a register and | ||
35 | * an absolute bit number and determines the proper register offset and bit | ||
36 | * number in that register. For example, to read the value of GPIO bit 50 | ||
37 | * the code would access offset ichx_regs[2(=GPIO_LVL)][1(=50/32)], | ||
38 | * bit 18 (50%32). | ||
39 | */ | ||
40 | enum GPIO_REG { | ||
41 | GPIO_USE_SEL = 0, | ||
42 | GPIO_IO_SEL, | ||
43 | GPIO_LVL, | ||
44 | }; | ||
45 | |||
46 | static const u8 ichx_regs[3][3] = { | ||
47 | {0x00, 0x30, 0x40}, /* USE_SEL[1-3] offsets */ | ||
48 | {0x04, 0x34, 0x44}, /* IO_SEL[1-3] offsets */ | ||
49 | {0x0c, 0x38, 0x48}, /* LVL[1-3] offsets */ | ||
50 | }; | ||
51 | |||
52 | #define ICHX_WRITE(val, reg, base_res) outl(val, (reg) + (base_res)->start) | ||
53 | #define ICHX_READ(reg, base_res) inl((reg) + (base_res)->start) | ||
54 | |||
55 | struct ichx_desc { | ||
56 | /* Max GPIO pins the chipset can have */ | ||
57 | uint ngpio; | ||
58 | |||
59 | /* Whether the chipset has GPIO in GPE0_STS in the PM IO region */ | ||
60 | bool uses_gpe0; | ||
61 | |||
62 | /* USE_SEL is bogus on some chipsets, eg 3100 */ | ||
63 | u32 use_sel_ignore[3]; | ||
64 | |||
65 | /* Some chipsets have quirks, let these use their own request/get */ | ||
66 | int (*request)(struct gpio_chip *chip, unsigned offset); | ||
67 | int (*get)(struct gpio_chip *chip, unsigned offset); | ||
68 | }; | ||
69 | |||
70 | static struct { | ||
71 | spinlock_t lock; | ||
72 | struct platform_device *dev; | ||
73 | struct gpio_chip chip; | ||
74 | struct resource *gpio_base; /* GPIO IO base */ | ||
75 | struct resource *pm_base; /* Power Mangagment IO base */ | ||
76 | struct ichx_desc *desc; /* Pointer to chipset-specific description */ | ||
77 | u32 orig_gpio_ctrl; /* Orig CTRL value, used to restore on exit */ | ||
78 | } ichx_priv; | ||
79 | |||
80 | static int modparam_gpiobase = -1; /* dynamic */ | ||
81 | module_param_named(gpiobase, modparam_gpiobase, int, 0444); | ||
82 | MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, " | ||
83 | "which is the default."); | ||
84 | |||
85 | static int ichx_write_bit(int reg, unsigned nr, int val, int verify) | ||
86 | { | ||
87 | unsigned long flags; | ||
88 | u32 data, tmp; | ||
89 | int reg_nr = nr / 32; | ||
90 | int bit = nr & 0x1f; | ||
91 | int ret = 0; | ||
92 | |||
93 | spin_lock_irqsave(&ichx_priv.lock, flags); | ||
94 | |||
95 | data = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
96 | if (val) | ||
97 | data |= 1 << bit; | ||
98 | else | ||
99 | data &= ~(1 << bit); | ||
100 | ICHX_WRITE(data, ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
101 | tmp = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
102 | if (verify && data != tmp) | ||
103 | ret = -EPERM; | ||
104 | |||
105 | spin_unlock_irqrestore(&ichx_priv.lock, flags); | ||
106 | |||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | static int ichx_read_bit(int reg, unsigned nr) | ||
111 | { | ||
112 | unsigned long flags; | ||
113 | u32 data; | ||
114 | int reg_nr = nr / 32; | ||
115 | int bit = nr & 0x1f; | ||
116 | |||
117 | spin_lock_irqsave(&ichx_priv.lock, flags); | ||
118 | |||
119 | data = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
120 | |||
121 | spin_unlock_irqrestore(&ichx_priv.lock, flags); | ||
122 | |||
123 | return data & (1 << bit) ? 1 : 0; | ||
124 | } | ||
125 | |||
126 | static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | ||
127 | { | ||
128 | /* | ||
129 | * Try setting pin as an input and verify it worked since many pins | ||
130 | * are output-only. | ||
131 | */ | ||
132 | if (ichx_write_bit(GPIO_IO_SEL, nr, 1, 1)) | ||
133 | return -EINVAL; | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | ||
139 | int val) | ||
140 | { | ||
141 | /* Set GPIO output value. */ | ||
142 | ichx_write_bit(GPIO_LVL, nr, val, 0); | ||
143 | |||
144 | /* | ||
145 | * Try setting pin as an output and verify it worked since many pins | ||
146 | * are input-only. | ||
147 | */ | ||
148 | if (ichx_write_bit(GPIO_IO_SEL, nr, 0, 1)) | ||
149 | return -EINVAL; | ||
150 | |||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | static int ichx_gpio_get(struct gpio_chip *chip, unsigned nr) | ||
155 | { | ||
156 | return ichx_read_bit(GPIO_LVL, nr); | ||
157 | } | ||
158 | |||
159 | static int ich6_gpio_get(struct gpio_chip *chip, unsigned nr) | ||
160 | { | ||
161 | unsigned long flags; | ||
162 | u32 data; | ||
163 | |||
164 | /* | ||
165 | * GPI 0 - 15 need to be read from the power management registers on | ||
166 | * a ICH6/3100 bridge. | ||
167 | */ | ||
168 | if (nr < 16) { | ||
169 | if (!ichx_priv.pm_base) | ||
170 | return -ENXIO; | ||
171 | |||
172 | spin_lock_irqsave(&ichx_priv.lock, flags); | ||
173 | |||
174 | /* GPI 0 - 15 are latched, write 1 to clear*/ | ||
175 | ICHX_WRITE(1 << (16 + nr), 0, ichx_priv.pm_base); | ||
176 | data = ICHX_READ(0, ichx_priv.pm_base); | ||
177 | |||
178 | spin_unlock_irqrestore(&ichx_priv.lock, flags); | ||
179 | |||
180 | return (data >> 16) & (1 << nr) ? 1 : 0; | ||
181 | } else { | ||
182 | return ichx_gpio_get(chip, nr); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | static int ichx_gpio_request(struct gpio_chip *chip, unsigned nr) | ||
187 | { | ||
188 | /* | ||
189 | * Note we assume the BIOS properly set a bridge's USE value. Some | ||
190 | * chips (eg Intel 3100) have bogus USE values though, so first see if | ||
191 | * the chipset's USE value can be trusted for this specific bit. | ||
192 | * If it can't be trusted, assume that the pin can be used as a GPIO. | ||
193 | */ | ||
194 | if (ichx_priv.desc->use_sel_ignore[nr / 32] & (1 << (nr & 0x1f))) | ||
195 | return 1; | ||
196 | |||
197 | return ichx_read_bit(GPIO_USE_SEL, nr) ? 0 : -ENODEV; | ||
198 | } | ||
199 | |||
200 | static int ich6_gpio_request(struct gpio_chip *chip, unsigned nr) | ||
201 | { | ||
202 | /* | ||
203 | * Fixups for bits 16 and 17 are necessary on the Intel ICH6/3100 | ||
204 | * bridge as they are controlled by USE register bits 0 and 1. See | ||
205 | * "Table 704 GPIO_USE_SEL1 register" in the i3100 datasheet for | ||
206 | * additional info. | ||
207 | */ | ||
208 | if (nr == 16 || nr == 17) | ||
209 | nr -= 16; | ||
210 | |||
211 | return ichx_gpio_request(chip, nr); | ||
212 | } | ||
213 | |||
214 | static void ichx_gpio_set(struct gpio_chip *chip, unsigned nr, int val) | ||
215 | { | ||
216 | ichx_write_bit(GPIO_LVL, nr, val, 0); | ||
217 | } | ||
218 | |||
219 | static void __devinit ichx_gpiolib_setup(struct gpio_chip *chip) | ||
220 | { | ||
221 | chip->owner = THIS_MODULE; | ||
222 | chip->label = DRV_NAME; | ||
223 | chip->dev = &ichx_priv.dev->dev; | ||
224 | |||
225 | /* Allow chip-specific overrides of request()/get() */ | ||
226 | chip->request = ichx_priv.desc->request ? | ||
227 | ichx_priv.desc->request : ichx_gpio_request; | ||
228 | chip->get = ichx_priv.desc->get ? | ||
229 | ichx_priv.desc->get : ichx_gpio_get; | ||
230 | |||
231 | chip->set = ichx_gpio_set; | ||
232 | chip->direction_input = ichx_gpio_direction_input; | ||
233 | chip->direction_output = ichx_gpio_direction_output; | ||
234 | chip->base = modparam_gpiobase; | ||
235 | chip->ngpio = ichx_priv.desc->ngpio; | ||
236 | chip->can_sleep = 0; | ||
237 | chip->dbg_show = NULL; | ||
238 | } | ||
239 | |||
240 | /* ICH6-based, 631xesb-based */ | ||
241 | static struct ichx_desc ich6_desc = { | ||
242 | /* Bridges using the ICH6 controller need fixups for GPIO 0 - 17 */ | ||
243 | .request = ich6_gpio_request, | ||
244 | .get = ich6_gpio_get, | ||
245 | |||
246 | /* GPIO 0-15 are read in the GPE0_STS PM register */ | ||
247 | .uses_gpe0 = true, | ||
248 | |||
249 | .ngpio = 50, | ||
250 | }; | ||
251 | |||
252 | /* Intel 3100 */ | ||
253 | static struct ichx_desc i3100_desc = { | ||
254 | /* | ||
255 | * Bits 16,17, 20 of USE_SEL and bit 16 of USE_SEL2 always read 0 on | ||
256 | * the Intel 3100. See "Table 712. GPIO Summary Table" of 3100 | ||
257 | * Datasheet for more info. | ||
258 | */ | ||
259 | .use_sel_ignore = {0x00130000, 0x00010000, 0x0}, | ||
260 | |||
261 | /* The 3100 needs fixups for GPIO 0 - 17 */ | ||
262 | .request = ich6_gpio_request, | ||
263 | .get = ich6_gpio_get, | ||
264 | |||
265 | /* GPIO 0-15 are read in the GPE0_STS PM register */ | ||
266 | .uses_gpe0 = true, | ||
267 | |||
268 | .ngpio = 50, | ||
269 | }; | ||
270 | |||
271 | /* ICH7 and ICH8-based */ | ||
272 | static struct ichx_desc ich7_desc = { | ||
273 | .ngpio = 50, | ||
274 | }; | ||
275 | |||
276 | /* ICH9-based */ | ||
277 | static struct ichx_desc ich9_desc = { | ||
278 | .ngpio = 61, | ||
279 | }; | ||
280 | |||
281 | /* ICH10-based - Consumer/corporate versions have different amount of GPIO */ | ||
282 | static struct ichx_desc ich10_cons_desc = { | ||
283 | .ngpio = 61, | ||
284 | }; | ||
285 | static struct ichx_desc ich10_corp_desc = { | ||
286 | .ngpio = 72, | ||
287 | }; | ||
288 | |||
289 | /* Intel 5 series, 6 series, 3400 series, and C200 series */ | ||
290 | static struct ichx_desc intel5_desc = { | ||
291 | .ngpio = 76, | ||
292 | }; | ||
293 | |||
294 | static int __devinit ichx_gpio_probe(struct platform_device *pdev) | ||
295 | { | ||
296 | struct resource *res_base, *res_pm; | ||
297 | int err; | ||
298 | struct lpc_ich_info *ich_info = pdev->dev.platform_data; | ||
299 | |||
300 | if (!ich_info) | ||
301 | return -ENODEV; | ||
302 | |||
303 | ichx_priv.dev = pdev; | ||
304 | |||
305 | switch (ich_info->gpio_version) { | ||
306 | case ICH_I3100_GPIO: | ||
307 | ichx_priv.desc = &i3100_desc; | ||
308 | break; | ||
309 | case ICH_V5_GPIO: | ||
310 | ichx_priv.desc = &intel5_desc; | ||
311 | break; | ||
312 | case ICH_V6_GPIO: | ||
313 | ichx_priv.desc = &ich6_desc; | ||
314 | break; | ||
315 | case ICH_V7_GPIO: | ||
316 | ichx_priv.desc = &ich7_desc; | ||
317 | break; | ||
318 | case ICH_V9_GPIO: | ||
319 | ichx_priv.desc = &ich9_desc; | ||
320 | break; | ||
321 | case ICH_V10CORP_GPIO: | ||
322 | ichx_priv.desc = &ich10_corp_desc; | ||
323 | break; | ||
324 | case ICH_V10CONS_GPIO: | ||
325 | ichx_priv.desc = &ich10_cons_desc; | ||
326 | break; | ||
327 | default: | ||
328 | return -ENODEV; | ||
329 | } | ||
330 | |||
331 | res_base = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPIO); | ||
332 | if (!res_base || !res_base->start || !res_base->end) | ||
333 | return -ENODEV; | ||
334 | |||
335 | if (!request_region(res_base->start, resource_size(res_base), | ||
336 | pdev->name)) | ||
337 | return -EBUSY; | ||
338 | |||
339 | ichx_priv.gpio_base = res_base; | ||
340 | |||
341 | /* | ||
342 | * If necessary, determine the I/O address of ACPI/power management | ||
343 | * registers which are needed to read the the GPE0 register for GPI pins | ||
344 | * 0 - 15 on some chipsets. | ||
345 | */ | ||
346 | if (!ichx_priv.desc->uses_gpe0) | ||
347 | goto init; | ||
348 | |||
349 | res_pm = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPE0); | ||
350 | if (!res_pm) { | ||
351 | pr_warn("ACPI BAR is unavailable, GPI 0 - 15 unavailable\n"); | ||
352 | goto init; | ||
353 | } | ||
354 | |||
355 | if (!request_region(res_pm->start, resource_size(res_pm), | ||
356 | pdev->name)) { | ||
357 | pr_warn("ACPI BAR is busy, GPI 0 - 15 unavailable\n"); | ||
358 | goto init; | ||
359 | } | ||
360 | |||
361 | ichx_priv.pm_base = res_pm; | ||
362 | |||
363 | init: | ||
364 | ichx_gpiolib_setup(&ichx_priv.chip); | ||
365 | err = gpiochip_add(&ichx_priv.chip); | ||
366 | if (err) { | ||
367 | pr_err("Failed to register GPIOs\n"); | ||
368 | goto add_err; | ||
369 | } | ||
370 | |||
371 | pr_info("GPIO from %d to %d on %s\n", ichx_priv.chip.base, | ||
372 | ichx_priv.chip.base + ichx_priv.chip.ngpio - 1, DRV_NAME); | ||
373 | |||
374 | return 0; | ||
375 | |||
376 | add_err: | ||
377 | release_region(ichx_priv.gpio_base->start, | ||
378 | resource_size(ichx_priv.gpio_base)); | ||
379 | if (ichx_priv.pm_base) | ||
380 | release_region(ichx_priv.pm_base->start, | ||
381 | resource_size(ichx_priv.pm_base)); | ||
382 | return err; | ||
383 | } | ||
384 | |||
385 | static int __devexit ichx_gpio_remove(struct platform_device *pdev) | ||
386 | { | ||
387 | int err; | ||
388 | |||
389 | err = gpiochip_remove(&ichx_priv.chip); | ||
390 | if (err) { | ||
391 | dev_err(&pdev->dev, "%s failed, %d\n", | ||
392 | "gpiochip_remove()", err); | ||
393 | return err; | ||
394 | } | ||
395 | |||
396 | release_region(ichx_priv.gpio_base->start, | ||
397 | resource_size(ichx_priv.gpio_base)); | ||
398 | if (ichx_priv.pm_base) | ||
399 | release_region(ichx_priv.pm_base->start, | ||
400 | resource_size(ichx_priv.pm_base)); | ||
401 | |||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | static struct platform_driver ichx_gpio_driver = { | ||
406 | .driver = { | ||
407 | .owner = THIS_MODULE, | ||
408 | .name = DRV_NAME, | ||
409 | }, | ||
410 | .probe = ichx_gpio_probe, | ||
411 | .remove = __devexit_p(ichx_gpio_remove), | ||
412 | }; | ||
413 | |||
414 | module_platform_driver(ichx_gpio_driver); | ||
415 | |||
416 | MODULE_AUTHOR("Peter Tyser <ptyser@xes-inc.com>"); | ||
417 | MODULE_DESCRIPTION("GPIO interface for Intel ICH series"); | ||
418 | MODULE_LICENSE("GPL"); | ||
419 | MODULE_ALIAS("platform:"DRV_NAME); | ||
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c index 8cadf4d683a8..424dce8e3f30 100644 --- a/drivers/gpio/gpio-sch.c +++ b/drivers/gpio/gpio-sch.c | |||
@@ -232,6 +232,14 @@ static int __devinit sch_gpio_probe(struct platform_device *pdev) | |||
232 | sch_gpio_resume.ngpio = 9; | 232 | sch_gpio_resume.ngpio = 9; |
233 | break; | 233 | break; |
234 | 234 | ||
235 | case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: | ||
236 | sch_gpio_core.base = 0; | ||
237 | sch_gpio_core.ngpio = 21; | ||
238 | |||
239 | sch_gpio_resume.base = 21; | ||
240 | sch_gpio_resume.ngpio = 9; | ||
241 | break; | ||
242 | |||
235 | default: | 243 | default: |
236 | return -ENODEV; | 244 | return -ENODEV; |
237 | } | 245 | } |
diff --git a/drivers/gpio/gpio-sta2x11.c b/drivers/gpio/gpio-sta2x11.c new file mode 100644 index 000000000000..38416be8ba11 --- /dev/null +++ b/drivers/gpio/gpio-sta2x11.c | |||
@@ -0,0 +1,435 @@ | |||
1 | /* | ||
2 | * STMicroelectronics ConneXt (STA2X11) GPIO driver | ||
3 | * | ||
4 | * Copyright 2012 ST Microelectronics (Alessandro Rubini) | ||
5 | * Based on gpio-ml-ioh.c, Copyright 2010 OKI Semiconductors Ltd. | ||
6 | * Also based on previous sta2x11 work, Copyright 2011 Wind River Systems, Inc. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
15 | * See the GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/gpio.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/irq.h> | ||
29 | #include <linux/pci.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/mfd/sta2x11-mfd.h> | ||
32 | |||
33 | struct gsta_regs { | ||
34 | u32 dat; /* 0x00 */ | ||
35 | u32 dats; | ||
36 | u32 datc; | ||
37 | u32 pdis; | ||
38 | u32 dir; /* 0x10 */ | ||
39 | u32 dirs; | ||
40 | u32 dirc; | ||
41 | u32 unused_1c; | ||
42 | u32 afsela; /* 0x20 */ | ||
43 | u32 unused_24[7]; | ||
44 | u32 rimsc; /* 0x40 */ | ||
45 | u32 fimsc; | ||
46 | u32 is; | ||
47 | u32 ic; | ||
48 | }; | ||
49 | |||
50 | struct gsta_gpio { | ||
51 | spinlock_t lock; | ||
52 | struct device *dev; | ||
53 | void __iomem *reg_base; | ||
54 | struct gsta_regs __iomem *regs[GSTA_NR_BLOCKS]; | ||
55 | struct gpio_chip gpio; | ||
56 | int irq_base; | ||
57 | /* FIXME: save the whole config here (AF, ...) */ | ||
58 | unsigned irq_type[GSTA_NR_GPIO]; | ||
59 | }; | ||
60 | |||
61 | static inline struct gsta_regs __iomem *__regs(struct gsta_gpio *chip, int nr) | ||
62 | { | ||
63 | return chip->regs[nr / GSTA_GPIO_PER_BLOCK]; | ||
64 | } | ||
65 | |||
66 | static inline u32 __bit(int nr) | ||
67 | { | ||
68 | return 1U << (nr % GSTA_GPIO_PER_BLOCK); | ||
69 | } | ||
70 | |||
71 | /* | ||
72 | * gpio methods | ||
73 | */ | ||
74 | |||
75 | static void gsta_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | ||
76 | { | ||
77 | struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); | ||
78 | struct gsta_regs __iomem *regs = __regs(chip, nr); | ||
79 | u32 bit = __bit(nr); | ||
80 | |||
81 | if (val) | ||
82 | writel(bit, ®s->dats); | ||
83 | else | ||
84 | writel(bit, ®s->datc); | ||
85 | } | ||
86 | |||
87 | static int gsta_gpio_get(struct gpio_chip *gpio, unsigned nr) | ||
88 | { | ||
89 | struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); | ||
90 | struct gsta_regs __iomem *regs = __regs(chip, nr); | ||
91 | u32 bit = __bit(nr); | ||
92 | |||
93 | return readl(®s->dat) & bit; | ||
94 | } | ||
95 | |||
96 | static int gsta_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | ||
97 | int val) | ||
98 | { | ||
99 | struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); | ||
100 | struct gsta_regs __iomem *regs = __regs(chip, nr); | ||
101 | u32 bit = __bit(nr); | ||
102 | |||
103 | writel(bit, ®s->dirs); | ||
104 | /* Data register after direction, otherwise pullup/down is selected */ | ||
105 | if (val) | ||
106 | writel(bit, ®s->dats); | ||
107 | else | ||
108 | writel(bit, ®s->datc); | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static int gsta_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | ||
113 | { | ||
114 | struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); | ||
115 | struct gsta_regs __iomem *regs = __regs(chip, nr); | ||
116 | u32 bit = __bit(nr); | ||
117 | |||
118 | writel(bit, ®s->dirc); | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | static int gsta_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) | ||
123 | { | ||
124 | struct gsta_gpio *chip = container_of(gpio, struct gsta_gpio, gpio); | ||
125 | return chip->irq_base + offset; | ||
126 | } | ||
127 | |||
128 | static void gsta_gpio_setup(struct gsta_gpio *chip) /* called from probe */ | ||
129 | { | ||
130 | struct gpio_chip *gpio = &chip->gpio; | ||
131 | |||
132 | /* | ||
133 | * ARCH_NR_GPIOS is currently 256 and dynamic allocation starts | ||
134 | * from the end. However, for compatibility, we need the first | ||
135 | * ConneXt device to start from gpio 0: it's the main chipset | ||
136 | * on most boards so documents and drivers assume gpio0..gpio127 | ||
137 | */ | ||
138 | static int gpio_base; | ||
139 | |||
140 | gpio->label = dev_name(chip->dev); | ||
141 | gpio->owner = THIS_MODULE; | ||
142 | gpio->direction_input = gsta_gpio_direction_input; | ||
143 | gpio->get = gsta_gpio_get; | ||
144 | gpio->direction_output = gsta_gpio_direction_output; | ||
145 | gpio->set = gsta_gpio_set; | ||
146 | gpio->dbg_show = NULL; | ||
147 | gpio->base = gpio_base; | ||
148 | gpio->ngpio = GSTA_NR_GPIO; | ||
149 | gpio->can_sleep = 0; | ||
150 | gpio->to_irq = gsta_gpio_to_irq; | ||
151 | |||
152 | /* | ||
153 | * After the first device, turn to dynamic gpio numbers. | ||
154 | * For example, with ARCH_NR_GPIOS = 256 we can fit two cards | ||
155 | */ | ||
156 | if (!gpio_base) | ||
157 | gpio_base = -1; | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * Special method: alternate functions and pullup/pulldown. This is only | ||
162 | * invoked on startup to configure gpio's according to platform data. | ||
163 | * FIXME : this functionality shall be managed (and exported to other drivers) | ||
164 | * via the pin control subsystem. | ||
165 | */ | ||
166 | static void gsta_set_config(struct gsta_gpio *chip, int nr, unsigned cfg) | ||
167 | { | ||
168 | struct gsta_regs __iomem *regs = __regs(chip, nr); | ||
169 | unsigned long flags; | ||
170 | u32 bit = __bit(nr); | ||
171 | u32 val; | ||
172 | int err = 0; | ||
173 | |||
174 | pr_info("%s: %p %i %i\n", __func__, chip, nr, cfg); | ||
175 | |||
176 | if (cfg == PINMUX_TYPE_NONE) | ||
177 | return; | ||
178 | |||
179 | /* Alternate function or not? */ | ||
180 | spin_lock_irqsave(&chip->lock, flags); | ||
181 | val = readl(®s->afsela); | ||
182 | if (cfg == PINMUX_TYPE_FUNCTION) | ||
183 | val |= bit; | ||
184 | else | ||
185 | val &= ~bit; | ||
186 | writel(val | bit, ®s->afsela); | ||
187 | if (cfg == PINMUX_TYPE_FUNCTION) { | ||
188 | spin_unlock_irqrestore(&chip->lock, flags); | ||
189 | return; | ||
190 | } | ||
191 | |||
192 | /* not alternate function: set details */ | ||
193 | switch (cfg) { | ||
194 | case PINMUX_TYPE_OUTPUT_LOW: | ||
195 | writel(bit, ®s->dirs); | ||
196 | writel(bit, ®s->datc); | ||
197 | break; | ||
198 | case PINMUX_TYPE_OUTPUT_HIGH: | ||
199 | writel(bit, ®s->dirs); | ||
200 | writel(bit, ®s->dats); | ||
201 | break; | ||
202 | case PINMUX_TYPE_INPUT: | ||
203 | writel(bit, ®s->dirc); | ||
204 | val = readl(®s->pdis) | bit; | ||
205 | writel(val, ®s->pdis); | ||
206 | break; | ||
207 | case PINMUX_TYPE_INPUT_PULLUP: | ||
208 | writel(bit, ®s->dirc); | ||
209 | val = readl(®s->pdis) & ~bit; | ||
210 | writel(val, ®s->pdis); | ||
211 | writel(bit, ®s->dats); | ||
212 | break; | ||
213 | case PINMUX_TYPE_INPUT_PULLDOWN: | ||
214 | writel(bit, ®s->dirc); | ||
215 | val = readl(®s->pdis) & ~bit; | ||
216 | writel(val, ®s->pdis); | ||
217 | writel(bit, ®s->datc); | ||
218 | break; | ||
219 | default: | ||
220 | err = 1; | ||
221 | } | ||
222 | spin_unlock_irqrestore(&chip->lock, flags); | ||
223 | if (err) | ||
224 | pr_err("%s: chip %p, pin %i, cfg %i is invalid\n", | ||
225 | __func__, chip, nr, cfg); | ||
226 | } | ||
227 | |||
228 | /* | ||
229 | * Irq methods | ||
230 | */ | ||
231 | |||
232 | static void gsta_irq_disable(struct irq_data *data) | ||
233 | { | ||
234 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); | ||
235 | struct gsta_gpio *chip = gc->private; | ||
236 | int nr = data->irq - chip->irq_base; | ||
237 | struct gsta_regs __iomem *regs = __regs(chip, nr); | ||
238 | u32 bit = __bit(nr); | ||
239 | u32 val; | ||
240 | unsigned long flags; | ||
241 | |||
242 | spin_lock_irqsave(&chip->lock, flags); | ||
243 | if (chip->irq_type[nr] & IRQ_TYPE_EDGE_RISING) { | ||
244 | val = readl(®s->rimsc) & ~bit; | ||
245 | writel(val, ®s->rimsc); | ||
246 | } | ||
247 | if (chip->irq_type[nr] & IRQ_TYPE_EDGE_FALLING) { | ||
248 | val = readl(®s->fimsc) & ~bit; | ||
249 | writel(val, ®s->fimsc); | ||
250 | } | ||
251 | spin_unlock_irqrestore(&chip->lock, flags); | ||
252 | return; | ||
253 | } | ||
254 | |||
255 | static void gsta_irq_enable(struct irq_data *data) | ||
256 | { | ||
257 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data); | ||
258 | struct gsta_gpio *chip = gc->private; | ||
259 | int nr = data->irq - chip->irq_base; | ||
260 | struct gsta_regs __iomem *regs = __regs(chip, nr); | ||
261 | u32 bit = __bit(nr); | ||
262 | u32 val; | ||
263 | int type; | ||
264 | unsigned long flags; | ||
265 | |||
266 | type = chip->irq_type[nr]; | ||
267 | |||
268 | spin_lock_irqsave(&chip->lock, flags); | ||
269 | val = readl(®s->rimsc); | ||
270 | if (type & IRQ_TYPE_EDGE_RISING) | ||
271 | writel(val | bit, ®s->rimsc); | ||
272 | else | ||
273 | writel(val & ~bit, ®s->rimsc); | ||
274 | val = readl(®s->rimsc); | ||
275 | if (type & IRQ_TYPE_EDGE_FALLING) | ||
276 | writel(val | bit, ®s->fimsc); | ||
277 | else | ||
278 | writel(val & ~bit, ®s->fimsc); | ||
279 | spin_unlock_irqrestore(&chip->lock, flags); | ||
280 | return; | ||
281 | } | ||
282 | |||
283 | static int gsta_irq_type(struct irq_data *d, unsigned int type) | ||
284 | { | ||
285 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
286 | struct gsta_gpio *chip = gc->private; | ||
287 | int nr = d->irq - chip->irq_base; | ||
288 | |||
289 | /* We only support edge interrupts */ | ||
290 | if (!(type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))) { | ||
291 | pr_debug("%s: unsupported type 0x%x\n", __func__, type); | ||
292 | return -EINVAL; | ||
293 | } | ||
294 | |||
295 | chip->irq_type[nr] = type; /* used for enable/disable */ | ||
296 | |||
297 | gsta_irq_enable(d); | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static irqreturn_t gsta_gpio_handler(int irq, void *dev_id) | ||
302 | { | ||
303 | struct gsta_gpio *chip = dev_id; | ||
304 | struct gsta_regs __iomem *regs; | ||
305 | u32 is; | ||
306 | int i, nr, base; | ||
307 | irqreturn_t ret = IRQ_NONE; | ||
308 | |||
309 | for (i = 0; i < GSTA_NR_BLOCKS; i++) { | ||
310 | regs = chip->regs[i]; | ||
311 | base = chip->irq_base + i * GSTA_GPIO_PER_BLOCK; | ||
312 | while ((is = readl(®s->is))) { | ||
313 | nr = __ffs(is); | ||
314 | irq = base + nr; | ||
315 | generic_handle_irq(irq); | ||
316 | writel(1 << nr, ®s->ic); | ||
317 | ret = IRQ_HANDLED; | ||
318 | } | ||
319 | } | ||
320 | return ret; | ||
321 | } | ||
322 | |||
323 | static __devinit void gsta_alloc_irq_chip(struct gsta_gpio *chip) | ||
324 | { | ||
325 | struct irq_chip_generic *gc; | ||
326 | struct irq_chip_type *ct; | ||
327 | |||
328 | gc = irq_alloc_generic_chip(KBUILD_MODNAME, 1, chip->irq_base, | ||
329 | chip->reg_base, handle_simple_irq); | ||
330 | gc->private = chip; | ||
331 | ct = gc->chip_types; | ||
332 | |||
333 | ct->chip.irq_set_type = gsta_irq_type; | ||
334 | ct->chip.irq_disable = gsta_irq_disable; | ||
335 | ct->chip.irq_enable = gsta_irq_enable; | ||
336 | |||
337 | /* FIXME: this makes at most 32 interrupts. Request 0 by now */ | ||
338 | irq_setup_generic_chip(gc, 0 /* IRQ_MSK(GSTA_GPIO_PER_BLOCK) */, 0, | ||
339 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); | ||
340 | |||
341 | /* Set up all all 128 interrupts: code from setup_generic_chip */ | ||
342 | { | ||
343 | struct irq_chip_type *ct = gc->chip_types; | ||
344 | int i, j; | ||
345 | for (j = 0; j < GSTA_NR_GPIO; j++) { | ||
346 | i = chip->irq_base + j; | ||
347 | irq_set_chip_and_handler(i, &ct->chip, ct->handler); | ||
348 | irq_set_chip_data(i, gc); | ||
349 | irq_modify_status(i, IRQ_NOREQUEST | IRQ_NOPROBE, 0); | ||
350 | } | ||
351 | gc->irq_cnt = i - gc->irq_base; | ||
352 | } | ||
353 | } | ||
354 | |||
355 | /* The platform device used here is instantiated by the MFD device */ | ||
356 | static int __devinit gsta_probe(struct platform_device *dev) | ||
357 | { | ||
358 | int i, err; | ||
359 | struct pci_dev *pdev; | ||
360 | struct sta2x11_gpio_pdata *gpio_pdata; | ||
361 | struct gsta_gpio *chip; | ||
362 | struct resource *res; | ||
363 | |||
364 | pdev = *(struct pci_dev **)(dev->dev.platform_data); | ||
365 | gpio_pdata = dev_get_platdata(&pdev->dev); | ||
366 | |||
367 | if (gpio_pdata == NULL) | ||
368 | dev_err(&dev->dev, "no gpio config\n"); | ||
369 | pr_debug("gpio config: %p\n", gpio_pdata); | ||
370 | |||
371 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
372 | |||
373 | chip = devm_kzalloc(&dev->dev, sizeof(*chip), GFP_KERNEL); | ||
374 | chip->dev = &dev->dev; | ||
375 | chip->reg_base = devm_request_and_ioremap(&dev->dev, res); | ||
376 | |||
377 | for (i = 0; i < GSTA_NR_BLOCKS; i++) { | ||
378 | chip->regs[i] = chip->reg_base + i * 4096; | ||
379 | /* disable all irqs */ | ||
380 | writel(0, &chip->regs[i]->rimsc); | ||
381 | writel(0, &chip->regs[i]->fimsc); | ||
382 | writel(~0, &chip->regs[i]->ic); | ||
383 | } | ||
384 | spin_lock_init(&chip->lock); | ||
385 | gsta_gpio_setup(chip); | ||
386 | for (i = 0; i < GSTA_NR_GPIO; i++) | ||
387 | gsta_set_config(chip, i, gpio_pdata->pinconfig[i]); | ||
388 | |||
389 | /* 384 was used in previous code: be compatible for other drivers */ | ||
390 | err = irq_alloc_descs(-1, 384, GSTA_NR_GPIO, NUMA_NO_NODE); | ||
391 | if (err < 0) { | ||
392 | dev_warn(&dev->dev, "sta2x11 gpio: Can't get irq base (%i)\n", | ||
393 | -err); | ||
394 | return err; | ||
395 | } | ||
396 | chip->irq_base = err; | ||
397 | gsta_alloc_irq_chip(chip); | ||
398 | |||
399 | err = request_irq(pdev->irq, gsta_gpio_handler, | ||
400 | IRQF_SHARED, KBUILD_MODNAME, chip); | ||
401 | if (err < 0) { | ||
402 | dev_err(&dev->dev, "sta2x11 gpio: Can't request irq (%i)\n", | ||
403 | -err); | ||
404 | goto err_free_descs; | ||
405 | } | ||
406 | |||
407 | err = gpiochip_add(&chip->gpio); | ||
408 | if (err < 0) { | ||
409 | dev_err(&dev->dev, "sta2x11 gpio: Can't register (%i)\n", | ||
410 | -err); | ||
411 | goto err_free_irq; | ||
412 | } | ||
413 | |||
414 | platform_set_drvdata(dev, chip); | ||
415 | return 0; | ||
416 | |||
417 | err_free_irq: | ||
418 | free_irq(pdev->irq, chip); | ||
419 | err_free_descs: | ||
420 | irq_free_descs(chip->irq_base, GSTA_NR_GPIO); | ||
421 | return err; | ||
422 | } | ||
423 | |||
424 | static struct platform_driver sta2x11_gpio_platform_driver = { | ||
425 | .driver = { | ||
426 | .name = "sta2x11-gpio", | ||
427 | .owner = THIS_MODULE, | ||
428 | }, | ||
429 | .probe = gsta_probe, | ||
430 | }; | ||
431 | |||
432 | module_platform_driver(sta2x11_gpio_platform_driver); | ||
433 | |||
434 | MODULE_LICENSE("GPL v2"); | ||
435 | MODULE_DESCRIPTION("sta2x11_gpio GPIO driver"); | ||
diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c index 7eef648a3351..c1ad2884f2ed 100644 --- a/drivers/gpio/gpio-tps65910.c +++ b/drivers/gpio/gpio-tps65910.c | |||
@@ -18,14 +18,27 @@ | |||
18 | #include <linux/errno.h> | 18 | #include <linux/errno.h> |
19 | #include <linux/gpio.h> | 19 | #include <linux/gpio.h> |
20 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
21 | #include <linux/platform_device.h> | ||
21 | #include <linux/mfd/tps65910.h> | 22 | #include <linux/mfd/tps65910.h> |
23 | #include <linux/of_device.h> | ||
24 | |||
25 | struct tps65910_gpio { | ||
26 | struct gpio_chip gpio_chip; | ||
27 | struct tps65910 *tps65910; | ||
28 | }; | ||
29 | |||
30 | static inline struct tps65910_gpio *to_tps65910_gpio(struct gpio_chip *chip) | ||
31 | { | ||
32 | return container_of(chip, struct tps65910_gpio, gpio_chip); | ||
33 | } | ||
22 | 34 | ||
23 | static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) | 35 | static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) |
24 | { | 36 | { |
25 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | 37 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); |
26 | uint8_t val; | 38 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; |
39 | unsigned int val; | ||
27 | 40 | ||
28 | tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val); | 41 | tps65910_reg_read(tps65910, TPS65910_GPIO0 + offset, &val); |
29 | 42 | ||
30 | if (val & GPIO_STS_MASK) | 43 | if (val & GPIO_STS_MASK) |
31 | return 1; | 44 | return 1; |
@@ -36,83 +49,170 @@ static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) | |||
36 | static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset, | 49 | static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset, |
37 | int value) | 50 | int value) |
38 | { | 51 | { |
39 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | 52 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); |
53 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; | ||
40 | 54 | ||
41 | if (value) | 55 | if (value) |
42 | tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset, | 56 | tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset, |
43 | GPIO_SET_MASK); | 57 | GPIO_SET_MASK); |
44 | else | 58 | else |
45 | tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset, | 59 | tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset, |
46 | GPIO_SET_MASK); | 60 | GPIO_SET_MASK); |
47 | } | 61 | } |
48 | 62 | ||
49 | static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset, | 63 | static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset, |
50 | int value) | 64 | int value) |
51 | { | 65 | { |
52 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | 66 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); |
67 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; | ||
53 | 68 | ||
54 | /* Set the initial value */ | 69 | /* Set the initial value */ |
55 | tps65910_gpio_set(gc, offset, value); | 70 | tps65910_gpio_set(gc, offset, value); |
56 | 71 | ||
57 | return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset, | 72 | return tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset, |
58 | GPIO_CFG_MASK); | 73 | GPIO_CFG_MASK); |
59 | } | 74 | } |
60 | 75 | ||
61 | static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset) | 76 | static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset) |
62 | { | 77 | { |
63 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); | 78 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); |
79 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; | ||
64 | 80 | ||
65 | return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset, | 81 | return tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset, |
66 | GPIO_CFG_MASK); | 82 | GPIO_CFG_MASK); |
67 | } | 83 | } |
68 | 84 | ||
69 | void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base) | 85 | #ifdef CONFIG_OF |
86 | static struct tps65910_board *tps65910_parse_dt_for_gpio(struct device *dev, | ||
87 | struct tps65910 *tps65910, int chip_ngpio) | ||
70 | { | 88 | { |
89 | struct tps65910_board *tps65910_board = tps65910->of_plat_data; | ||
90 | unsigned int prop_array[TPS6591X_MAX_NUM_GPIO]; | ||
91 | int ngpio = min(chip_ngpio, TPS6591X_MAX_NUM_GPIO); | ||
71 | int ret; | 92 | int ret; |
72 | struct tps65910_board *board_data; | 93 | int idx; |
94 | |||
95 | tps65910_board->gpio_base = -1; | ||
96 | ret = of_property_read_u32_array(tps65910->dev->of_node, | ||
97 | "ti,en-gpio-sleep", prop_array, ngpio); | ||
98 | if (ret < 0) { | ||
99 | dev_dbg(dev, "ti,en-gpio-sleep not specified\n"); | ||
100 | return tps65910_board; | ||
101 | } | ||
73 | 102 | ||
74 | if (!gpio_base) | 103 | for (idx = 0; idx < ngpio; idx++) |
75 | return; | 104 | tps65910_board->en_gpio_sleep[idx] = (prop_array[idx] != 0); |
76 | 105 | ||
77 | tps65910->gpio.owner = THIS_MODULE; | 106 | return tps65910_board; |
78 | tps65910->gpio.label = tps65910->i2c_client->name; | 107 | } |
79 | tps65910->gpio.dev = tps65910->dev; | 108 | #else |
80 | tps65910->gpio.base = gpio_base; | 109 | static struct tps65910_board *tps65910_parse_dt_for_gpio(struct device *dev, |
110 | struct tps65910 *tps65910, int chip_ngpio) | ||
111 | { | ||
112 | return NULL; | ||
113 | } | ||
114 | #endif | ||
115 | |||
116 | static int __devinit tps65910_gpio_probe(struct platform_device *pdev) | ||
117 | { | ||
118 | struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); | ||
119 | struct tps65910_board *pdata = dev_get_platdata(tps65910->dev); | ||
120 | struct tps65910_gpio *tps65910_gpio; | ||
121 | int ret; | ||
122 | int i; | ||
123 | |||
124 | tps65910_gpio = devm_kzalloc(&pdev->dev, | ||
125 | sizeof(*tps65910_gpio), GFP_KERNEL); | ||
126 | if (!tps65910_gpio) { | ||
127 | dev_err(&pdev->dev, "Could not allocate tps65910_gpio\n"); | ||
128 | return -ENOMEM; | ||
129 | } | ||
130 | |||
131 | tps65910_gpio->tps65910 = tps65910; | ||
132 | |||
133 | tps65910_gpio->gpio_chip.owner = THIS_MODULE; | ||
134 | tps65910_gpio->gpio_chip.label = tps65910->i2c_client->name; | ||
81 | 135 | ||
82 | switch(tps65910_chip_id(tps65910)) { | 136 | switch(tps65910_chip_id(tps65910)) { |
83 | case TPS65910: | 137 | case TPS65910: |
84 | tps65910->gpio.ngpio = TPS65910_NUM_GPIO; | 138 | tps65910_gpio->gpio_chip.ngpio = TPS65910_NUM_GPIO; |
85 | break; | 139 | break; |
86 | case TPS65911: | 140 | case TPS65911: |
87 | tps65910->gpio.ngpio = TPS65911_NUM_GPIO; | 141 | tps65910_gpio->gpio_chip.ngpio = TPS65911_NUM_GPIO; |
88 | break; | 142 | break; |
89 | default: | 143 | default: |
90 | return; | 144 | return -EINVAL; |
145 | } | ||
146 | tps65910_gpio->gpio_chip.can_sleep = 1; | ||
147 | tps65910_gpio->gpio_chip.direction_input = tps65910_gpio_input; | ||
148 | tps65910_gpio->gpio_chip.direction_output = tps65910_gpio_output; | ||
149 | tps65910_gpio->gpio_chip.set = tps65910_gpio_set; | ||
150 | tps65910_gpio->gpio_chip.get = tps65910_gpio_get; | ||
151 | tps65910_gpio->gpio_chip.dev = &pdev->dev; | ||
152 | if (pdata && pdata->gpio_base) | ||
153 | tps65910_gpio->gpio_chip.base = pdata->gpio_base; | ||
154 | else | ||
155 | tps65910_gpio->gpio_chip.base = -1; | ||
156 | |||
157 | if (!pdata && tps65910->dev->of_node) | ||
158 | pdata = tps65910_parse_dt_for_gpio(&pdev->dev, tps65910, | ||
159 | tps65910_gpio->gpio_chip.ngpio); | ||
160 | |||
161 | if (!pdata) | ||
162 | goto skip_init; | ||
163 | |||
164 | /* Configure sleep control for gpios if provided */ | ||
165 | for (i = 0; i < tps65910_gpio->gpio_chip.ngpio; ++i) { | ||
166 | if (!pdata->en_gpio_sleep[i]) | ||
167 | continue; | ||
168 | |||
169 | ret = tps65910_reg_set_bits(tps65910, | ||
170 | TPS65910_GPIO0 + i, GPIO_SLEEP_MASK); | ||
171 | if (ret < 0) | ||
172 | dev_warn(tps65910->dev, | ||
173 | "GPIO Sleep setting failed with err %d\n", ret); | ||
91 | } | 174 | } |
92 | tps65910->gpio.can_sleep = 1; | 175 | |
93 | 176 | skip_init: | |
94 | tps65910->gpio.direction_input = tps65910_gpio_input; | 177 | ret = gpiochip_add(&tps65910_gpio->gpio_chip); |
95 | tps65910->gpio.direction_output = tps65910_gpio_output; | 178 | if (ret < 0) { |
96 | tps65910->gpio.set = tps65910_gpio_set; | 179 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); |
97 | tps65910->gpio.get = tps65910_gpio_get; | 180 | return ret; |
98 | |||
99 | /* Configure sleep control for gpios */ | ||
100 | board_data = dev_get_platdata(tps65910->dev); | ||
101 | if (board_data) { | ||
102 | int i; | ||
103 | for (i = 0; i < tps65910->gpio.ngpio; ++i) { | ||
104 | if (board_data->en_gpio_sleep[i]) { | ||
105 | ret = tps65910_set_bits(tps65910, | ||
106 | TPS65910_GPIO0 + i, GPIO_SLEEP_MASK); | ||
107 | if (ret < 0) | ||
108 | dev_warn(tps65910->dev, | ||
109 | "GPIO Sleep setting failed\n"); | ||
110 | } | ||
111 | } | ||
112 | } | 181 | } |
113 | 182 | ||
114 | ret = gpiochip_add(&tps65910->gpio); | 183 | platform_set_drvdata(pdev, tps65910_gpio); |
184 | |||
185 | return ret; | ||
186 | } | ||
187 | |||
188 | static int __devexit tps65910_gpio_remove(struct platform_device *pdev) | ||
189 | { | ||
190 | struct tps65910_gpio *tps65910_gpio = platform_get_drvdata(pdev); | ||
115 | 191 | ||
116 | if (ret) | 192 | return gpiochip_remove(&tps65910_gpio->gpio_chip); |
117 | dev_warn(tps65910->dev, "GPIO registration failed: %d\n", ret); | ||
118 | } | 193 | } |
194 | |||
195 | static struct platform_driver tps65910_gpio_driver = { | ||
196 | .driver.name = "tps65910-gpio", | ||
197 | .driver.owner = THIS_MODULE, | ||
198 | .probe = tps65910_gpio_probe, | ||
199 | .remove = __devexit_p(tps65910_gpio_remove), | ||
200 | }; | ||
201 | |||
202 | static int __init tps65910_gpio_init(void) | ||
203 | { | ||
204 | return platform_driver_register(&tps65910_gpio_driver); | ||
205 | } | ||
206 | subsys_initcall(tps65910_gpio_init); | ||
207 | |||
208 | static void __exit tps65910_gpio_exit(void) | ||
209 | { | ||
210 | platform_driver_unregister(&tps65910_gpio_driver); | ||
211 | } | ||
212 | module_exit(tps65910_gpio_exit); | ||
213 | |||
214 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); | ||
215 | MODULE_AUTHOR("Jorge Eduardo Candelaria jedu@slimlogic.co.uk>"); | ||
216 | MODULE_DESCRIPTION("GPIO interface for TPS65910/TPS6511 PMICs"); | ||
217 | MODULE_LICENSE("GPL v2"); | ||
218 | MODULE_ALIAS("platform:tps65910-gpio"); | ||
diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c index deb949e75ec1..e56a2165641c 100644 --- a/drivers/gpio/gpio-wm831x.c +++ b/drivers/gpio/gpio-wm831x.c | |||
@@ -102,10 +102,8 @@ static int wm831x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | |||
102 | struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); | 102 | struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); |
103 | struct wm831x *wm831x = wm831x_gpio->wm831x; | 103 | struct wm831x *wm831x = wm831x_gpio->wm831x; |
104 | 104 | ||
105 | if (!wm831x->irq_base) | 105 | return irq_create_mapping(wm831x->irq_domain, |
106 | return -EINVAL; | 106 | WM831X_IRQ_GPIO_1 + offset); |
107 | |||
108 | return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset; | ||
109 | } | 107 | } |
110 | 108 | ||
111 | static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, | 109 | static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, |