diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/gpio | |
parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) |
Patched in Tegra support.
Diffstat (limited to 'drivers/gpio')
80 files changed, 2126 insertions, 16839 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 682de754d63..d539efd96d4 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -2,14 +2,6 @@ | |||
2 | # GPIO infrastructure and drivers | 2 | # GPIO infrastructure and drivers |
3 | # | 3 | # |
4 | 4 | ||
5 | config ARCH_HAVE_CUSTOM_GPIO_H | ||
6 | bool | ||
7 | help | ||
8 | Selecting this config option from the architecture Kconfig allows | ||
9 | the architecture to provide a custom asm/gpio.h implementation | ||
10 | overriding the default implementations. New uses of this are | ||
11 | strongly discouraged. | ||
12 | |||
13 | config ARCH_WANT_OPTIONAL_GPIOLIB | 5 | config ARCH_WANT_OPTIONAL_GPIOLIB |
14 | bool | 6 | bool |
15 | help | 7 | help |
@@ -45,14 +37,6 @@ menuconfig GPIOLIB | |||
45 | 37 | ||
46 | if GPIOLIB | 38 | if GPIOLIB |
47 | 39 | ||
48 | config OF_GPIO | ||
49 | def_bool y | ||
50 | depends on OF | ||
51 | |||
52 | config GPIO_ACPI | ||
53 | def_bool y | ||
54 | depends on ACPI | ||
55 | |||
56 | config DEBUG_GPIO | 40 | config DEBUG_GPIO |
57 | bool "Debug GPIO calls" | 41 | bool "Debug GPIO calls" |
58 | depends on DEBUG_KERNEL | 42 | depends on DEBUG_KERNEL |
@@ -90,26 +74,11 @@ config GPIO_DA9052 | |||
90 | help | 74 | help |
91 | Say yes here to enable the GPIO driver for the DA9052 chip. | 75 | Say yes here to enable the GPIO driver for the DA9052 chip. |
92 | 76 | ||
93 | config GPIO_DA9055 | ||
94 | tristate "Dialog Semiconductor DA9055 GPIO" | ||
95 | depends on MFD_DA9055 | ||
96 | help | ||
97 | Say yes here to enable the GPIO driver for the DA9055 chip. | ||
98 | |||
99 | The Dialog DA9055 PMIC chip has 3 GPIO pins that can be | ||
100 | be controller by this driver. | ||
101 | |||
102 | If driver is built as a module it will be called gpio-da9055. | ||
103 | |||
104 | config GPIO_MAX730X | 77 | config GPIO_MAX730X |
105 | tristate | 78 | tristate |
106 | 79 | ||
107 | comment "Memory mapped GPIO drivers:" | 80 | comment "Memory mapped GPIO drivers:" |
108 | 81 | ||
109 | config GPIO_CLPS711X | ||
110 | def_bool y | ||
111 | depends on ARCH_CLPS711X | ||
112 | |||
113 | config GPIO_GENERIC_PLATFORM | 82 | config GPIO_GENERIC_PLATFORM |
114 | tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" | 83 | tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" |
115 | select GPIO_GENERIC | 84 | select GPIO_GENERIC |
@@ -118,44 +87,25 @@ config GPIO_GENERIC_PLATFORM | |||
118 | 87 | ||
119 | config GPIO_IT8761E | 88 | config GPIO_IT8761E |
120 | tristate "IT8761E GPIO support" | 89 | tristate "IT8761E GPIO support" |
121 | depends on X86 # unconditional access to IO space. | ||
122 | help | 90 | help |
123 | Say yes here to support GPIO functionality of IT8761E super I/O chip. | 91 | Say yes here to support GPIO functionality of IT8761E super I/O chip. |
124 | 92 | ||
125 | config GPIO_EM | ||
126 | tristate "Emma Mobile GPIO" | ||
127 | depends on ARM | ||
128 | help | ||
129 | Say yes here to support GPIO on Renesas Emma Mobile SoCs. | ||
130 | |||
131 | config GPIO_EP93XX | 93 | config GPIO_EP93XX |
132 | def_bool y | 94 | def_bool y |
133 | depends on ARCH_EP93XX | 95 | depends on ARCH_EP93XX |
134 | select GPIO_GENERIC | 96 | select GPIO_GENERIC |
135 | 97 | ||
136 | config GPIO_MM_LANTIQ | 98 | config GPIO_EXYNOS4 |
137 | bool "Lantiq Memory mapped GPIOs" | 99 | def_bool y |
138 | depends on LANTIQ && SOC_XWAY | 100 | depends on CPU_EXYNOS4210 |
139 | help | ||
140 | This enables support for memory mapped GPIOs on the External Bus Unit | ||
141 | (EBU) found on Lantiq SoCs. The gpios are output only as they are | ||
142 | created by attaching a 16bit latch to the bus. | ||
143 | 101 | ||
144 | config GPIO_MPC5200 | 102 | config GPIO_MPC5200 |
145 | def_bool y | 103 | def_bool y |
146 | depends on PPC_MPC52xx | 104 | depends on PPC_MPC52xx |
147 | 105 | ||
148 | config GPIO_MPC8XXX | ||
149 | bool "MPC512x/MPC8xxx GPIO support" | ||
150 | depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ | ||
151 | FSL_SOC_BOOKE || PPC_86xx | ||
152 | help | ||
153 | Say Y here if you're going to use hardware that connects to the | ||
154 | MPC512x/831x/834x/837x/8572/8610 GPIOs. | ||
155 | |||
156 | config GPIO_MSM_V1 | 106 | config GPIO_MSM_V1 |
157 | tristate "Qualcomm MSM GPIO v1" | 107 | tristate "Qualcomm MSM GPIO v1" |
158 | depends on GPIOLIB && ARCH_MSM && (ARCH_MSM7X00A || ARCH_MSM7X30 || ARCH_QSD8X50) | 108 | depends on GPIOLIB && ARCH_MSM |
159 | help | 109 | help |
160 | Say yes here to support the GPIO interface on ARM v6 based | 110 | Say yes here to support the GPIO interface on ARM v6 based |
161 | Qualcomm MSM chips. Most of the pins on the MSM can be | 111 | Qualcomm MSM chips. Most of the pins on the MSM can be |
@@ -169,13 +119,6 @@ config GPIO_MSM_V2 | |||
169 | Qualcomm MSM chips. Most of the pins on the MSM can be | 119 | Qualcomm MSM chips. Most of the pins on the MSM can be |
170 | selected for GPIO, and are controlled by this driver. | 120 | selected for GPIO, and are controlled by this driver. |
171 | 121 | ||
172 | config GPIO_MVEBU | ||
173 | def_bool y | ||
174 | depends on PLAT_ORION | ||
175 | depends on OF | ||
176 | select GPIO_GENERIC | ||
177 | select GENERIC_IRQ_CHIP | ||
178 | |||
179 | config GPIO_MXC | 122 | config GPIO_MXC |
180 | def_bool y | 123 | def_bool y |
181 | depends on ARCH_MXC | 124 | depends on ARCH_MXC |
@@ -188,47 +131,23 @@ config GPIO_MXS | |||
188 | select GPIO_GENERIC | 131 | select GPIO_GENERIC |
189 | select GENERIC_IRQ_CHIP | 132 | select GENERIC_IRQ_CHIP |
190 | 133 | ||
191 | config GPIO_PL061 | 134 | config GPIO_PLAT_SAMSUNG |
192 | bool "PrimeCell PL061 GPIO support" | 135 | def_bool y |
193 | depends on ARM && ARM_AMBA | 136 | depends on SAMSUNG_GPIOLIB_4BIT |
194 | select GENERIC_IRQ_CHIP | ||
195 | help | ||
196 | Say yes here to support the PrimeCell PL061 GPIO device | ||
197 | |||
198 | config GPIO_PXA | ||
199 | bool "PXA GPIO support" | ||
200 | depends on ARCH_PXA || ARCH_MMP | ||
201 | help | ||
202 | Say yes here to support the PXA GPIO device | ||
203 | |||
204 | config GPIO_SPEAR_SPICS | ||
205 | bool "ST SPEAr13xx SPI Chip Select as GPIO support" | ||
206 | depends on PLAT_SPEAR | ||
207 | select GENERIC_IRQ_CHIP | ||
208 | help | ||
209 | Say yes here to support ST SPEAr SPI Chip Select as GPIO device | ||
210 | 137 | ||
211 | config GPIO_STA2X11 | 138 | config GPIO_S5PC100 |
212 | bool "STA2x11/ConneXt GPIO support" | 139 | def_bool y |
213 | depends on MFD_STA2X11 | 140 | depends on CPU_S5PC100 |
214 | select GENERIC_IRQ_CHIP | ||
215 | help | ||
216 | Say yes here to support the STA2x11/ConneXt GPIO device. | ||
217 | The GPIO module has 128 GPIO pins with alternate functions. | ||
218 | 141 | ||
219 | config GPIO_TS5500 | 142 | config GPIO_S5PV210 |
220 | tristate "TS-5500 DIO blocks and compatibles" | 143 | def_bool y |
221 | help | 144 | depends on CPU_S5PV210 |
222 | This driver supports Digital I/O exposed by pin blocks found on some | ||
223 | Technologic Systems platforms. It includes, but is not limited to, 3 | ||
224 | blocks of the TS-5500: DIO1, DIO2 and the LCD port, and the TS-5600 | ||
225 | LCD port. | ||
226 | 145 | ||
227 | config GPIO_VT8500 | 146 | config GPIO_PL061 |
228 | bool "VIA/Wondermedia SoC GPIO Support" | 147 | bool "PrimeCell PL061 GPIO support" |
229 | depends on ARCH_VT8500 | 148 | depends on ARM_AMBA |
230 | help | 149 | help |
231 | Say yes here to support the VT8500/WM8505/WM8650 GPIO controller. | 150 | Say yes here to support the PrimeCell PL061 GPIO device |
232 | 151 | ||
233 | config GPIO_XILINX | 152 | config GPIO_XILINX |
234 | bool "Xilinx GPIO support" | 153 | bool "Xilinx GPIO support" |
@@ -243,13 +162,13 @@ config GPIO_VR41XX | |||
243 | Say yes here to support the NEC VR4100 series General-purpose I/O Uint | 162 | Say yes here to support the NEC VR4100 series General-purpose I/O Uint |
244 | 163 | ||
245 | config GPIO_SCH | 164 | config GPIO_SCH |
246 | tristate "Intel SCH/TunnelCreek/Centerton GPIO" | 165 | tristate "Intel SCH/TunnelCreek GPIO" |
247 | depends on PCI && X86 | 166 | depends on PCI && X86 |
248 | select MFD_CORE | 167 | select MFD_CORE |
249 | select LPC_SCH | 168 | select LPC_SCH |
250 | help | 169 | help |
251 | Say yes here to support GPIO interface on Intel Poulsbo SCH, | 170 | Say yes here to support GPIO interface on Intel Poulsbo SCH |
252 | Intel Tunnel Creek processor or Intel Centerton processor. | 171 | or Intel Tunnel Creek processor. |
253 | The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are | 172 | The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are |
254 | powered by the core power rail and are turned off during sleep | 173 | powered by the core power rail and are turned off during sleep |
255 | modes (S3 and higher). The remaining four GPIOs are powered by | 174 | modes (S3 and higher). The remaining four GPIOs are powered by |
@@ -258,26 +177,10 @@ config GPIO_SCH | |||
258 | system from the Suspend-to-RAM state. | 177 | system from the Suspend-to-RAM state. |
259 | The Intel Tunnel Creek processor has 5 GPIOs powered by the | 178 | The Intel Tunnel Creek processor has 5 GPIOs powered by the |
260 | core power rail and 9 from suspend power supply. | 179 | core power rail and 9 from suspend power supply. |
261 | The Intel Centerton processor has a total of 30 GPIO pins. | ||
262 | Twenty-one are powered by the core power rail and 9 from the | ||
263 | suspend power supply. | ||
264 | |||
265 | config GPIO_ICH | ||
266 | tristate "Intel ICH GPIO" | ||
267 | depends on PCI && X86 | ||
268 | select MFD_CORE | ||
269 | select LPC_ICH | ||
270 | help | ||
271 | Say yes here to support the GPIO functionality of a number of Intel | ||
272 | ICH-based chipsets. Currently supported devices: ICH6, ICH7, ICH8 | ||
273 | ICH9, ICH10, Series 5/3400 (eg Ibex Peak), Series 6/C200 (eg | ||
274 | Cougar Point), NM10 (Tiger Point), and 3100 (Whitmore Lake). | ||
275 | |||
276 | If unsure, say N. | ||
277 | 180 | ||
278 | config GPIO_VX855 | 181 | config GPIO_VX855 |
279 | tristate "VIA VX855/VX875 GPIO" | 182 | tristate "VIA VX855/VX875 GPIO" |
280 | depends on PCI | 183 | depends on MFD_SUPPORT && PCI |
281 | select MFD_CORE | 184 | select MFD_CORE |
282 | select MFD_VX855 | 185 | select MFD_VX855 |
283 | help | 186 | help |
@@ -287,25 +190,8 @@ config GPIO_VX855 | |||
287 | additional drivers must be enabled in order to use the | 190 | additional drivers must be enabled in order to use the |
288 | functionality of the device. | 191 | functionality of the device. |
289 | 192 | ||
290 | config GPIO_GE_FPGA | ||
291 | bool "GE FPGA based GPIO" | ||
292 | depends on GE_FPGA | ||
293 | help | ||
294 | Support for common GPIO functionality provided on some GE Single Board | ||
295 | Computers. | ||
296 | |||
297 | This driver provides basic support (configure as input or output, read | ||
298 | and write pin state) for GPIO implemented in a number of GE single | ||
299 | board computers. | ||
300 | |||
301 | comment "I2C GPIO expanders:" | 193 | comment "I2C GPIO expanders:" |
302 | 194 | ||
303 | config GPIO_ARIZONA | ||
304 | tristate "Wolfson Microelectronics Arizona class devices" | ||
305 | depends on MFD_ARIZONA | ||
306 | help | ||
307 | Support for GPIOs on Wolfson Arizona class devices. | ||
308 | |||
309 | config GPIO_MAX7300 | 195 | config GPIO_MAX7300 |
310 | tristate "Maxim MAX7300 GPIO expander" | 196 | tristate "Maxim MAX7300 GPIO expander" |
311 | depends on I2C | 197 | depends on I2C |
@@ -339,14 +225,8 @@ config GPIO_MAX732X_IRQ | |||
339 | Say yes here to enable the max732x to be used as an interrupt | 225 | Say yes here to enable the max732x to be used as an interrupt |
340 | controller. It requires the driver to be built in the kernel. | 226 | controller. It requires the driver to be built in the kernel. |
341 | 227 | ||
342 | config GPIO_MC9S08DZ60 | ||
343 | bool "MX35 3DS BOARD MC9S08DZ60 GPIO functions" | ||
344 | depends on I2C=y && MACH_MX35_3DS | ||
345 | help | ||
346 | Select this to enable the MC9S08DZ60 GPIO driver | ||
347 | |||
348 | config GPIO_PCA953X | 228 | config GPIO_PCA953X |
349 | tristate "PCA953x, PCA955x, PCA957x, TCA64xx, and MAX7310 I/O ports" | 229 | tristate "PCA953x, PCA955x, TCA64xx, and MAX7310 I/O ports" |
350 | depends on I2C | 230 | depends on I2C |
351 | help | 231 | help |
352 | Say yes here to provide access to several register-oriented | 232 | Say yes here to provide access to several register-oriented |
@@ -355,11 +235,10 @@ config GPIO_PCA953X | |||
355 | 235 | ||
356 | 4 bits: pca9536, pca9537 | 236 | 4 bits: pca9536, pca9537 |
357 | 237 | ||
358 | 8 bits: max7310, max7315, pca6107, pca9534, pca9538, pca9554, | 238 | 8 bits: max7310, pca9534, pca9538, pca9554, pca9557, |
359 | pca9556, pca9557, pca9574, tca6408 | 239 | tca6408 |
360 | 240 | ||
361 | 16 bits: max7312, max7313, pca9535, pca9539, pca9555, pca9575, | 241 | 16 bits: pca9535, pca9539, pca9555, tca6416 |
362 | tca6416 | ||
363 | 242 | ||
364 | config GPIO_PCA953X_IRQ | 243 | config GPIO_PCA953X_IRQ |
365 | bool "Interrupt controller support for PCA953x" | 244 | bool "Interrupt controller support for PCA953x" |
@@ -371,7 +250,6 @@ config GPIO_PCA953X_IRQ | |||
371 | config GPIO_PCF857X | 250 | config GPIO_PCF857X |
372 | tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders" | 251 | tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders" |
373 | depends on I2C | 252 | depends on I2C |
374 | select IRQ_DOMAIN | ||
375 | help | 253 | help |
376 | Say yes here to provide access to most "quasi-bidirectional" I2C | 254 | Say yes here to provide access to most "quasi-bidirectional" I2C |
377 | GPIO expanders used for additional digital outputs or inputs. | 255 | GPIO expanders used for additional digital outputs or inputs. |
@@ -393,15 +271,6 @@ config GPIO_PCF857X | |||
393 | This driver provides an in-kernel interface to those GPIOs using | 271 | This driver provides an in-kernel interface to those GPIOs using |
394 | platform-neutral GPIO calls. | 272 | platform-neutral GPIO calls. |
395 | 273 | ||
396 | config GPIO_RC5T583 | ||
397 | bool "RICOH RC5T583 GPIO" | ||
398 | depends on MFD_RC5T583 | ||
399 | help | ||
400 | Select this option to enable GPIO driver for the Ricoh RC5T583 | ||
401 | chip family. | ||
402 | This driver provides the support for driving/reading the gpio pins | ||
403 | of RC5T583 device through standard gpio library. | ||
404 | |||
405 | config GPIO_SX150X | 274 | config GPIO_SX150X |
406 | bool "Semtech SX150x I2C GPIO expander" | 275 | bool "Semtech SX150x I2C GPIO expander" |
407 | depends on I2C=y | 276 | depends on I2C=y |
@@ -420,16 +289,6 @@ config GPIO_STMPE | |||
420 | This enables support for the GPIOs found on the STMPE I/O | 289 | This enables support for the GPIOs found on the STMPE I/O |
421 | Expanders. | 290 | Expanders. |
422 | 291 | ||
423 | config GPIO_STP_XWAY | ||
424 | bool "XWAY STP GPIOs" | ||
425 | depends on SOC_XWAY | ||
426 | help | ||
427 | This enables support for the Serial To Parallel (STP) unit found on | ||
428 | XWAY SoC. The STP allows the SoC to drive a shift registers cascade, | ||
429 | that can be up to 24 bit. This peripheral is aimed at driving leds. | ||
430 | Some of the gpios/leds can be auto updated by the soc with dsl and | ||
431 | phy status. | ||
432 | |||
433 | config GPIO_TC3589X | 292 | config GPIO_TC3589X |
434 | bool "TC3589X GPIOs" | 293 | bool "TC3589X GPIOs" |
435 | depends on MFD_TC3589X | 294 | depends on MFD_TC3589X |
@@ -450,13 +309,6 @@ config GPIO_TWL4030 | |||
450 | Say yes here to access the GPIO signals of various multi-function | 309 | Say yes here to access the GPIO signals of various multi-function |
451 | power management chips from Texas Instruments. | 310 | power management chips from Texas Instruments. |
452 | 311 | ||
453 | config GPIO_TWL6040 | ||
454 | tristate "TWL6040 GPO" | ||
455 | depends on TWL6040_CORE | ||
456 | help | ||
457 | Say yes here to access the GPO signals of twl6040 | ||
458 | audio chip from Texas Instruments. | ||
459 | |||
460 | config GPIO_WM831X | 312 | config GPIO_WM831X |
461 | tristate "WM831x GPIOs" | 313 | tristate "WM831x GPIOs" |
462 | depends on MFD_WM831X | 314 | depends on MFD_WM831X |
@@ -499,22 +351,11 @@ config GPIO_ADP5588_IRQ | |||
499 | Say yes here to enable the adp5588 to be used as an interrupt | 351 | Say yes here to enable the adp5588 to be used as an interrupt |
500 | controller. It requires the driver to be built in the kernel. | 352 | controller. It requires the driver to be built in the kernel. |
501 | 353 | ||
502 | config GPIO_ADNP | ||
503 | tristate "Avionic Design N-bit GPIO expander" | ||
504 | depends on I2C && OF_GPIO | ||
505 | help | ||
506 | This option enables support for N GPIOs found on Avionic Design | ||
507 | I2C GPIO expanders. The register space will be extended by powers | ||
508 | of two, so the controller will need to accommodate for that. For | ||
509 | example: if a controller provides 48 pins, 6 registers will be | ||
510 | enough to represent all pins, but the driver will assume a | ||
511 | register layout for 64 pins (8 registers). | ||
512 | |||
513 | comment "PCI GPIO expanders:" | 354 | comment "PCI GPIO expanders:" |
514 | 355 | ||
515 | config GPIO_CS5535 | 356 | config GPIO_CS5535 |
516 | tristate "AMD CS5535/CS5536 GPIO support" | 357 | tristate "AMD CS5535/CS5536 GPIO support" |
517 | depends on PCI && X86 && MFD_CS5535 | 358 | depends on PCI && X86 && !CS5535_GPIO && MFD_CS5535 |
518 | help | 359 | help |
519 | The AMD CS5535 and CS5536 southbridges support 28 GPIO pins that | 360 | The AMD CS5535 and CS5536 southbridges support 28 GPIO pins that |
520 | can be used for quite a number of things. The CS5535/6 is found on | 361 | can be used for quite a number of things. The CS5535/6 is found on |
@@ -538,59 +379,35 @@ config GPIO_BT8XX | |||
538 | 379 | ||
539 | If unsure, say N. | 380 | If unsure, say N. |
540 | 381 | ||
541 | config GPIO_AMD8111 | ||
542 | tristate "AMD 8111 GPIO driver" | ||
543 | depends on PCI | ||
544 | help | ||
545 | The AMD 8111 south bridge contains 32 GPIO pins which can be used. | ||
546 | |||
547 | Note, that usually system firmware/ACPI handles GPIO pins on their | ||
548 | own and users might easily break their systems with uncarefull usage | ||
549 | of this driver! | ||
550 | |||
551 | If unsure, say N | ||
552 | |||
553 | config GPIO_LANGWELL | 382 | config GPIO_LANGWELL |
554 | bool "Intel Langwell/Penwell GPIO support" | 383 | bool "Intel Langwell/Penwell GPIO support" |
555 | depends on PCI && X86 | 384 | depends on PCI && X86 |
556 | select IRQ_DOMAIN | ||
557 | help | 385 | help |
558 | Say Y here to support Intel Langwell/Penwell GPIO. | 386 | Say Y here to support Intel Langwell/Penwell GPIO. |
559 | 387 | ||
560 | config GPIO_PCH | 388 | config GPIO_PCH |
561 | tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO" | 389 | tristate "Intel EG20T PCH / OKI SEMICONDUCTOR ML7223 IOH GPIO" |
562 | depends on PCI && X86 | 390 | depends on PCI && X86 |
563 | select GENERIC_IRQ_CHIP | ||
564 | help | 391 | help |
565 | This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff | 392 | This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff |
566 | which is an IOH(Input/Output Hub) for x86 embedded processor. | 393 | which is an IOH(Input/Output Hub) for x86 embedded processor. |
567 | This driver can access PCH GPIO device. | 394 | This driver can access PCH GPIO device. |
568 | 395 | ||
569 | This driver also can be used for LAPIS Semiconductor IOH(Input/ | 396 | This driver also can be used for OKI SEMICONDUCTOR IOH(Input/ |
570 | Output Hub), ML7223 and ML7831. | 397 | Output Hub), ML7223. |
571 | ML7223 IOH is for MP(Media Phone) use. | 398 | ML7223 IOH is for MP(Media Phone) use. |
572 | ML7831 IOH is for general purpose use. | 399 | ML7223 is companion chip for Intel Atom E6xx series. |
573 | ML7223/ML7831 is companion chip for Intel Atom E6xx series. | 400 | ML7223 is completely compatible for Intel EG20T PCH. |
574 | ML7223/ML7831 is completely compatible for Intel EG20T PCH. | ||
575 | 401 | ||
576 | config GPIO_ML_IOH | 402 | config GPIO_ML_IOH |
577 | tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support" | 403 | tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support" |
578 | depends on PCI | 404 | depends on PCI |
579 | select GENERIC_IRQ_CHIP | ||
580 | help | 405 | help |
581 | ML7213 is companion chip for Intel Atom E6xx series. | 406 | ML7213 is companion chip for Intel Atom E6xx series. |
582 | This driver can be used for OKI SEMICONDUCTOR ML7213 IOH(Input/Output | 407 | This driver can be used for OKI SEMICONDUCTOR ML7213 IOH(Input/Output |
583 | Hub) which is for IVI(In-Vehicle Infotainment) use. | 408 | Hub) which is for IVI(In-Vehicle Infotainment) use. |
584 | This driver can access the IOH's GPIO device. | 409 | This driver can access the IOH's GPIO device. |
585 | 410 | ||
586 | config GPIO_SODAVILLE | ||
587 | bool "Intel Sodaville GPIO support" | ||
588 | depends on X86 && PCI && OF | ||
589 | select GPIO_GENERIC | ||
590 | select GENERIC_IRQ_CHIP | ||
591 | help | ||
592 | Say Y here to support Intel Sodaville GPIO. | ||
593 | |||
594 | config GPIO_TIMBERDALE | 411 | config GPIO_TIMBERDALE |
595 | bool "Support for timberdale GPIO IP" | 412 | bool "Support for timberdale GPIO IP" |
596 | depends on MFD_TIMBERDALE && HAS_IOMEM | 413 | depends on MFD_TIMBERDALE && HAS_IOMEM |
@@ -600,6 +417,7 @@ config GPIO_TIMBERDALE | |||
600 | config GPIO_RDC321X | 417 | config GPIO_RDC321X |
601 | tristate "RDC R-321x GPIO support" | 418 | tristate "RDC R-321x GPIO support" |
602 | depends on PCI | 419 | depends on PCI |
420 | select MFD_SUPPORT | ||
603 | select MFD_CORE | 421 | select MFD_CORE |
604 | select MFD_RDC321X | 422 | select MFD_RDC321X |
605 | help | 423 | help |
@@ -663,38 +481,10 @@ config GPIO_AB8500 | |||
663 | help | 481 | help |
664 | Select this to enable the AB8500 IC GPIO driver | 482 | Select this to enable the AB8500 IC GPIO driver |
665 | 483 | ||
666 | config GPIO_TPS6586X | ||
667 | bool "TPS6586X GPIO" | ||
668 | depends on MFD_TPS6586X | ||
669 | help | ||
670 | Select this option to enable GPIO driver for the TPS6586X | ||
671 | chip family. | ||
672 | |||
673 | config GPIO_TPS65910 | 484 | config GPIO_TPS65910 |
674 | bool "TPS65910 GPIO" | 485 | bool "TPS65910 GPIO" |
675 | depends on MFD_TPS65910 | 486 | depends on MFD_TPS65910 |
676 | help | 487 | help |
677 | Select this option to enable GPIO driver for the TPS65910 | 488 | Select this option to enable GPIO driver for the TPS65910 |
678 | chip family. | 489 | chip family. |
679 | |||
680 | config GPIO_MSIC | ||
681 | bool "Intel MSIC mixed signal gpio support" | ||
682 | depends on MFD_INTEL_MSIC | ||
683 | help | ||
684 | Enable support for GPIO on intel MSIC controllers found in | ||
685 | intel MID devices | ||
686 | |||
687 | comment "USB GPIO expanders:" | ||
688 | |||
689 | config GPIO_VIPERBOARD | ||
690 | tristate "Viperboard GPIO a & b support" | ||
691 | depends on MFD_VIPERBOARD && USB | ||
692 | help | ||
693 | Say yes here to access the GPIO signals of Nano River | ||
694 | Technologies Viperboard. There are two GPIO chips on the | ||
695 | board: gpioa and gpiob. | ||
696 | See viperboard API specification and Nano | ||
697 | River Tech's viperboard.h for detailed meaning | ||
698 | of the module parameters. | ||
699 | |||
700 | endif | 490 | endif |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index c5aebd008dd..9588948c96f 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -2,83 +2,59 @@ | |||
2 | 2 | ||
3 | ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG | 3 | ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG |
4 | 4 | ||
5 | obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o | 5 | obj-$(CONFIG_GPIOLIB) += gpiolib.o |
6 | obj-$(CONFIG_OF_GPIO) += gpiolib-of.o | ||
7 | obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o | ||
8 | 6 | ||
9 | # Device drivers. Generally keep list sorted alphabetically | 7 | # Device drivers. Generally keep list sorted alphabetically |
10 | obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o | 8 | obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o |
11 | 9 | ||
12 | obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o | 10 | obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o |
13 | obj-$(CONFIG_GPIO_AB8500) += gpio-ab8500.o | 11 | obj-$(CONFIG_GPIO_AB8500) += gpio-ab8500.o |
14 | obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o | ||
15 | obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o | 12 | obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o |
16 | obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o | 13 | obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o |
17 | obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o | ||
18 | obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o | ||
19 | obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o | 14 | obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o |
20 | obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o | ||
21 | obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o | 15 | obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o |
22 | obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o | 16 | obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o |
23 | obj-$(CONFIG_GPIO_DA9055) += gpio-da9055.o | ||
24 | obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o | ||
25 | obj-$(CONFIG_GPIO_EM) += gpio-em.o | ||
26 | obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o | 17 | obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o |
27 | obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o | 18 | obj-$(CONFIG_GPIO_EXYNOS4) += gpio-exynos4.o |
28 | obj-$(CONFIG_GPIO_ICH) += gpio-ich.o | ||
29 | obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o | 19 | obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o |
30 | obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o | 20 | obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o |
31 | obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o | ||
32 | obj-$(CONFIG_GPIO_LANGWELL) += gpio-langwell.o | 21 | obj-$(CONFIG_GPIO_LANGWELL) += gpio-langwell.o |
33 | obj-$(CONFIG_ARCH_LPC32XX) += gpio-lpc32xx.o | ||
34 | obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o | 22 | obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o |
35 | obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o | 23 | obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o |
36 | obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o | 24 | obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o |
37 | obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o | 25 | obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o |
38 | obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o | 26 | obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o |
39 | obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o | ||
40 | obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o | 27 | obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o |
41 | obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o | 28 | obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o |
42 | obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o | ||
43 | obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o | 29 | obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o |
44 | obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o | ||
45 | obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o | ||
46 | obj-$(CONFIG_GPIO_MSM_V1) += gpio-msm-v1.o | 30 | obj-$(CONFIG_GPIO_MSM_V1) += gpio-msm-v1.o |
47 | obj-$(CONFIG_GPIO_MSM_V2) += gpio-msm-v2.o | 31 | obj-$(CONFIG_GPIO_MSM_V2) += gpio-msm-v2.o |
48 | obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o | ||
49 | obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o | 32 | obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o |
50 | obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o | 33 | obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o |
34 | obj-$(CONFIG_PLAT_NOMADIK) += gpio-nomadik.o | ||
51 | obj-$(CONFIG_ARCH_OMAP) += gpio-omap.o | 35 | obj-$(CONFIG_ARCH_OMAP) += gpio-omap.o |
52 | obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o | 36 | obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o |
53 | obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o | 37 | obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o |
54 | obj-$(CONFIG_GPIO_PCH) += gpio-pch.o | 38 | obj-$(CONFIG_GPIO_PCH) += gpio-pch.o |
55 | obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o | 39 | obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o |
56 | obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o | ||
57 | obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o | ||
58 | obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o | 40 | obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o |
59 | obj-$(CONFIG_PLAT_SAMSUNG) += gpio-samsung.o | 41 | |
60 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o | 42 | obj-$(CONFIG_GPIO_PLAT_SAMSUNG) += gpio-plat-samsung.o |
43 | obj-$(CONFIG_GPIO_S5PC100) += gpio-s5pc100.o | ||
44 | obj-$(CONFIG_GPIO_S5PV210) += gpio-s5pv210.o | ||
45 | |||
61 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o | 46 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o |
62 | obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o | ||
63 | obj-$(CONFIG_GPIO_SPEAR_SPICS) += gpio-spear-spics.o | ||
64 | obj-$(CONFIG_GPIO_STA2X11) += gpio-sta2x11.o | ||
65 | obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o | 47 | obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o |
66 | obj-$(CONFIG_GPIO_STP_XWAY) += gpio-stp-xway.o | ||
67 | obj-$(CONFIG_GPIO_SX150X) += gpio-sx150x.o | 48 | obj-$(CONFIG_GPIO_SX150X) += gpio-sx150x.o |
68 | obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o | 49 | obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o |
69 | obj-$(CONFIG_ARCH_TEGRA) += gpio-tegra.o | 50 | obj-$(CONFIG_ARCH_TEGRA) += gpio-tegra.o |
70 | obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o | 51 | obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o |
71 | obj-$(CONFIG_ARCH_DAVINCI_TNETV107X) += gpio-tnetv107x.o | ||
72 | obj-$(CONFIG_GPIO_TPS6586X) += gpio-tps6586x.o | ||
73 | obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o | 52 | obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o |
74 | obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o | 53 | obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o |
75 | obj-$(CONFIG_GPIO_TS5500) += gpio-ts5500.o | ||
76 | obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o | 54 | obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o |
77 | obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o | 55 | obj-$(CONFIG_MACH_U300) += gpio-u300.o |
78 | obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o | 56 | obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o |
79 | obj-$(CONFIG_GPIO_VIPERBOARD) += gpio-viperboard.o | ||
80 | obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o | 57 | obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o |
81 | obj-$(CONFIG_GPIO_VT8500) += gpio-vt8500.o | ||
82 | obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o | 58 | obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o |
83 | obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o | 59 | obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o |
84 | obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o | 60 | obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o |
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c deleted file mode 100644 index 1077754f828..00000000000 --- a/drivers/gpio/devres.c +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | /* | ||
2 | * drivers/gpio/devres.c - managed gpio resources | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 | ||
6 | * as published by the Free Software Foundation. | ||
7 | * | ||
8 | * You should have received a copy of the GNU General Public License | ||
9 | * along with this program; if not, write to the Free Software | ||
10 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
11 | * | ||
12 | * This file is based on kernel/irq/devres.c | ||
13 | * | ||
14 | * Copyright (c) 2011 John Crispin <blogic@openwrt.org> | ||
15 | */ | ||
16 | |||
17 | #include <linux/module.h> | ||
18 | #include <linux/gpio.h> | ||
19 | #include <linux/device.h> | ||
20 | #include <linux/gfp.h> | ||
21 | |||
22 | static void devm_gpio_release(struct device *dev, void *res) | ||
23 | { | ||
24 | unsigned *gpio = res; | ||
25 | |||
26 | gpio_free(*gpio); | ||
27 | } | ||
28 | |||
29 | static int devm_gpio_match(struct device *dev, void *res, void *data) | ||
30 | { | ||
31 | unsigned *this = res, *gpio = data; | ||
32 | |||
33 | return *this == *gpio; | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * devm_gpio_request - request a gpio for a managed device | ||
38 | * @dev: device to request the gpio for | ||
39 | * @gpio: gpio to allocate | ||
40 | * @label: the name of the requested gpio | ||
41 | * | ||
42 | * Except for the extra @dev argument, this function takes the | ||
43 | * same arguments and performs the same function as | ||
44 | * gpio_request(). GPIOs requested with this function will be | ||
45 | * automatically freed on driver detach. | ||
46 | * | ||
47 | * If an GPIO allocated with this function needs to be freed | ||
48 | * separately, devm_gpio_free() must be used. | ||
49 | */ | ||
50 | |||
51 | int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) | ||
52 | { | ||
53 | unsigned *dr; | ||
54 | int rc; | ||
55 | |||
56 | dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); | ||
57 | if (!dr) | ||
58 | return -ENOMEM; | ||
59 | |||
60 | rc = gpio_request(gpio, label); | ||
61 | if (rc) { | ||
62 | devres_free(dr); | ||
63 | return rc; | ||
64 | } | ||
65 | |||
66 | *dr = gpio; | ||
67 | devres_add(dev, dr); | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | EXPORT_SYMBOL(devm_gpio_request); | ||
72 | |||
73 | /** | ||
74 | * devm_gpio_request_one - request a single GPIO with initial setup | ||
75 | * @dev: device to request for | ||
76 | * @gpio: the GPIO number | ||
77 | * @flags: GPIO configuration as specified by GPIOF_* | ||
78 | * @label: a literal description string of this GPIO | ||
79 | */ | ||
80 | int devm_gpio_request_one(struct device *dev, unsigned gpio, | ||
81 | unsigned long flags, const char *label) | ||
82 | { | ||
83 | unsigned *dr; | ||
84 | int rc; | ||
85 | |||
86 | dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); | ||
87 | if (!dr) | ||
88 | return -ENOMEM; | ||
89 | |||
90 | rc = gpio_request_one(gpio, flags, label); | ||
91 | if (rc) { | ||
92 | devres_free(dr); | ||
93 | return rc; | ||
94 | } | ||
95 | |||
96 | *dr = gpio; | ||
97 | devres_add(dev, dr); | ||
98 | |||
99 | return 0; | ||
100 | } | ||
101 | EXPORT_SYMBOL(devm_gpio_request_one); | ||
102 | |||
103 | /** | ||
104 | * devm_gpio_free - free an interrupt | ||
105 | * @dev: device to free gpio for | ||
106 | * @gpio: gpio to free | ||
107 | * | ||
108 | * Except for the extra @dev argument, this function takes the | ||
109 | * same arguments and performs the same function as gpio_free(). | ||
110 | * This function instead of gpio_free() should be used to manually | ||
111 | * free GPIOs allocated with devm_gpio_request(). | ||
112 | */ | ||
113 | void devm_gpio_free(struct device *dev, unsigned int gpio) | ||
114 | { | ||
115 | |||
116 | WARN_ON(devres_release(dev, devm_gpio_release, devm_gpio_match, | ||
117 | &gpio)); | ||
118 | } | ||
119 | EXPORT_SYMBOL(devm_gpio_free); | ||
diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c index 464be961f60..ff525c0958d 100644 --- a/drivers/gpio/gpio-74x164.c +++ b/drivers/gpio/gpio-74x164.c | |||
@@ -14,18 +14,13 @@ | |||
14 | #include <linux/spi/spi.h> | 14 | #include <linux/spi/spi.h> |
15 | #include <linux/spi/74x164.h> | 15 | #include <linux/spi/74x164.h> |
16 | #include <linux/gpio.h> | 16 | #include <linux/gpio.h> |
17 | #include <linux/of_gpio.h> | ||
18 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
19 | #include <linux/module.h> | ||
20 | |||
21 | #define GEN_74X164_NUMBER_GPIOS 8 | ||
22 | 18 | ||
23 | struct gen_74x164_chip { | 19 | struct gen_74x164_chip { |
24 | struct spi_device *spi; | 20 | struct spi_device *spi; |
25 | u8 *buffer; | ||
26 | struct gpio_chip gpio_chip; | 21 | struct gpio_chip gpio_chip; |
27 | struct mutex lock; | 22 | struct mutex lock; |
28 | u32 registers; | 23 | u8 port_config; |
29 | }; | 24 | }; |
30 | 25 | ||
31 | static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) | 26 | static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) |
@@ -35,47 +30,17 @@ static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) | |||
35 | 30 | ||
36 | static int __gen_74x164_write_config(struct gen_74x164_chip *chip) | 31 | static int __gen_74x164_write_config(struct gen_74x164_chip *chip) |
37 | { | 32 | { |
38 | struct spi_message message; | 33 | return spi_write(chip->spi, |
39 | struct spi_transfer *msg_buf; | 34 | &chip->port_config, sizeof(chip->port_config)); |
40 | int i, ret = 0; | ||
41 | |||
42 | msg_buf = kzalloc(chip->registers * sizeof(struct spi_transfer), | ||
43 | GFP_KERNEL); | ||
44 | if (!msg_buf) | ||
45 | return -ENOMEM; | ||
46 | |||
47 | spi_message_init(&message); | ||
48 | |||
49 | /* | ||
50 | * Since the registers are chained, every byte sent will make | ||
51 | * the previous byte shift to the next register in the | ||
52 | * chain. Thus, the first byte send will end up in the last | ||
53 | * register at the end of the transfer. So, to have a logical | ||
54 | * numbering, send the bytes in reverse order so that the last | ||
55 | * byte of the buffer will end up in the last register. | ||
56 | */ | ||
57 | for (i = chip->registers - 1; i >= 0; i--) { | ||
58 | msg_buf[i].tx_buf = chip->buffer +i; | ||
59 | msg_buf[i].len = sizeof(u8); | ||
60 | spi_message_add_tail(msg_buf + i, &message); | ||
61 | } | ||
62 | |||
63 | ret = spi_sync(chip->spi, &message); | ||
64 | |||
65 | kfree(msg_buf); | ||
66 | |||
67 | return ret; | ||
68 | } | 35 | } |
69 | 36 | ||
70 | static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) | 37 | static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) |
71 | { | 38 | { |
72 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); | 39 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); |
73 | u8 bank = offset / 8; | ||
74 | u8 pin = offset % 8; | ||
75 | int ret; | 40 | int ret; |
76 | 41 | ||
77 | mutex_lock(&chip->lock); | 42 | mutex_lock(&chip->lock); |
78 | ret = (chip->buffer[bank] >> pin) & 0x1; | 43 | ret = (chip->port_config >> offset) & 0x1; |
79 | mutex_unlock(&chip->lock); | 44 | mutex_unlock(&chip->lock); |
80 | 45 | ||
81 | return ret; | 46 | return ret; |
@@ -85,14 +50,12 @@ static void gen_74x164_set_value(struct gpio_chip *gc, | |||
85 | unsigned offset, int val) | 50 | unsigned offset, int val) |
86 | { | 51 | { |
87 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); | 52 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); |
88 | u8 bank = offset / 8; | ||
89 | u8 pin = offset % 8; | ||
90 | 53 | ||
91 | mutex_lock(&chip->lock); | 54 | mutex_lock(&chip->lock); |
92 | if (val) | 55 | if (val) |
93 | chip->buffer[bank] |= (1 << pin); | 56 | chip->port_config |= (1 << offset); |
94 | else | 57 | else |
95 | chip->buffer[bank] &= ~(1 << pin); | 58 | chip->port_config &= ~(1 << offset); |
96 | 59 | ||
97 | __gen_74x164_write_config(chip); | 60 | __gen_74x164_write_config(chip); |
98 | mutex_unlock(&chip->lock); | 61 | mutex_unlock(&chip->lock); |
@@ -105,14 +68,15 @@ static int gen_74x164_direction_output(struct gpio_chip *gc, | |||
105 | return 0; | 68 | return 0; |
106 | } | 69 | } |
107 | 70 | ||
108 | static int gen_74x164_probe(struct spi_device *spi) | 71 | static int __devinit gen_74x164_probe(struct spi_device *spi) |
109 | { | 72 | { |
110 | struct gen_74x164_chip *chip; | 73 | struct gen_74x164_chip *chip; |
111 | struct gen_74x164_chip_platform_data *pdata; | 74 | struct gen_74x164_chip_platform_data *pdata; |
112 | int ret; | 75 | int ret; |
113 | 76 | ||
114 | if (!spi->dev.of_node) { | 77 | pdata = spi->dev.platform_data; |
115 | dev_err(&spi->dev, "No device tree data available.\n"); | 78 | if (!pdata || !pdata->base) { |
79 | dev_dbg(&spi->dev, "incorrect or missing platform data\n"); | ||
116 | return -EINVAL; | 80 | return -EINVAL; |
117 | } | 81 | } |
118 | 82 | ||
@@ -125,16 +89,10 @@ static int gen_74x164_probe(struct spi_device *spi) | |||
125 | if (ret < 0) | 89 | if (ret < 0) |
126 | return ret; | 90 | return ret; |
127 | 91 | ||
128 | chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL); | 92 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
129 | if (!chip) | 93 | if (!chip) |
130 | return -ENOMEM; | 94 | return -ENOMEM; |
131 | 95 | ||
132 | pdata = spi->dev.platform_data; | ||
133 | if (pdata && pdata->base) | ||
134 | chip->gpio_chip.base = pdata->base; | ||
135 | else | ||
136 | chip->gpio_chip.base = -1; | ||
137 | |||
138 | mutex_init(&chip->lock); | 96 | mutex_init(&chip->lock); |
139 | 97 | ||
140 | dev_set_drvdata(&spi->dev, chip); | 98 | dev_set_drvdata(&spi->dev, chip); |
@@ -145,20 +103,8 @@ static int gen_74x164_probe(struct spi_device *spi) | |||
145 | chip->gpio_chip.direction_output = gen_74x164_direction_output; | 103 | chip->gpio_chip.direction_output = gen_74x164_direction_output; |
146 | chip->gpio_chip.get = gen_74x164_get_value; | 104 | chip->gpio_chip.get = gen_74x164_get_value; |
147 | chip->gpio_chip.set = gen_74x164_set_value; | 105 | chip->gpio_chip.set = gen_74x164_set_value; |
148 | 106 | chip->gpio_chip.base = pdata->base; | |
149 | if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) { | 107 | chip->gpio_chip.ngpio = 8; |
150 | dev_err(&spi->dev, "Missing registers-number property in the DT.\n"); | ||
151 | ret = -EINVAL; | ||
152 | goto exit_destroy; | ||
153 | } | ||
154 | |||
155 | chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; | ||
156 | chip->buffer = devm_kzalloc(&spi->dev, chip->registers, GFP_KERNEL); | ||
157 | if (!chip->buffer) { | ||
158 | ret = -ENOMEM; | ||
159 | goto exit_destroy; | ||
160 | } | ||
161 | |||
162 | chip->gpio_chip.can_sleep = 1; | 108 | chip->gpio_chip.can_sleep = 1; |
163 | chip->gpio_chip.dev = &spi->dev; | 109 | chip->gpio_chip.dev = &spi->dev; |
164 | chip->gpio_chip.owner = THIS_MODULE; | 110 | chip->gpio_chip.owner = THIS_MODULE; |
@@ -178,10 +124,11 @@ static int gen_74x164_probe(struct spi_device *spi) | |||
178 | exit_destroy: | 124 | exit_destroy: |
179 | dev_set_drvdata(&spi->dev, NULL); | 125 | dev_set_drvdata(&spi->dev, NULL); |
180 | mutex_destroy(&chip->lock); | 126 | mutex_destroy(&chip->lock); |
127 | kfree(chip); | ||
181 | return ret; | 128 | return ret; |
182 | } | 129 | } |
183 | 130 | ||
184 | static int gen_74x164_remove(struct spi_device *spi) | 131 | static int __devexit gen_74x164_remove(struct spi_device *spi) |
185 | { | 132 | { |
186 | struct gen_74x164_chip *chip; | 133 | struct gen_74x164_chip *chip; |
187 | int ret; | 134 | int ret; |
@@ -193,31 +140,36 @@ static int gen_74x164_remove(struct spi_device *spi) | |||
193 | dev_set_drvdata(&spi->dev, NULL); | 140 | dev_set_drvdata(&spi->dev, NULL); |
194 | 141 | ||
195 | ret = gpiochip_remove(&chip->gpio_chip); | 142 | ret = gpiochip_remove(&chip->gpio_chip); |
196 | if (!ret) | 143 | if (!ret) { |
197 | mutex_destroy(&chip->lock); | 144 | mutex_destroy(&chip->lock); |
198 | else | 145 | kfree(chip); |
146 | } else | ||
199 | dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", | 147 | dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", |
200 | ret); | 148 | ret); |
201 | 149 | ||
202 | return ret; | 150 | return ret; |
203 | } | 151 | } |
204 | 152 | ||
205 | static const struct of_device_id gen_74x164_dt_ids[] = { | ||
206 | { .compatible = "fairchild,74hc595" }, | ||
207 | {}, | ||
208 | }; | ||
209 | MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids); | ||
210 | |||
211 | static struct spi_driver gen_74x164_driver = { | 153 | static struct spi_driver gen_74x164_driver = { |
212 | .driver = { | 154 | .driver = { |
213 | .name = "74x164", | 155 | .name = "74x164", |
214 | .owner = THIS_MODULE, | 156 | .owner = THIS_MODULE, |
215 | .of_match_table = of_match_ptr(gen_74x164_dt_ids), | ||
216 | }, | 157 | }, |
217 | .probe = gen_74x164_probe, | 158 | .probe = gen_74x164_probe, |
218 | .remove = gen_74x164_remove, | 159 | .remove = __devexit_p(gen_74x164_remove), |
219 | }; | 160 | }; |
220 | module_spi_driver(gen_74x164_driver); | 161 | |
162 | static int __init gen_74x164_init(void) | ||
163 | { | ||
164 | return spi_register_driver(&gen_74x164_driver); | ||
165 | } | ||
166 | subsys_initcall(gen_74x164_init); | ||
167 | |||
168 | static void __exit gen_74x164_exit(void) | ||
169 | { | ||
170 | spi_unregister_driver(&gen_74x164_driver); | ||
171 | } | ||
172 | module_exit(gen_74x164_exit); | ||
221 | 173 | ||
222 | MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); | 174 | MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); |
223 | MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>"); | 175 | MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>"); |
diff --git a/drivers/gpio/gpio-ab8500.c b/drivers/gpio/gpio-ab8500.c index 983ad425f0a..050c05d9189 100644 --- a/drivers/gpio/gpio-ab8500.c +++ b/drivers/gpio/gpio-ab8500.c | |||
@@ -402,7 +402,7 @@ static void ab8500_gpio_irq_remove(struct ab8500_gpio *ab8500_gpio) | |||
402 | } | 402 | } |
403 | } | 403 | } |
404 | 404 | ||
405 | static int ab8500_gpio_probe(struct platform_device *pdev) | 405 | static int __devinit ab8500_gpio_probe(struct platform_device *pdev) |
406 | { | 406 | { |
407 | struct ab8500_platform_data *ab8500_pdata = | 407 | struct ab8500_platform_data *ab8500_pdata = |
408 | dev_get_platdata(pdev->dev.parent); | 408 | dev_get_platdata(pdev->dev.parent); |
@@ -474,7 +474,7 @@ out_free: | |||
474 | * ab8500_gpio_remove() - remove Ab8500-gpio driver | 474 | * ab8500_gpio_remove() - remove Ab8500-gpio driver |
475 | * @pdev : Platform device registered | 475 | * @pdev : Platform device registered |
476 | */ | 476 | */ |
477 | static int ab8500_gpio_remove(struct platform_device *pdev) | 477 | static int __devexit ab8500_gpio_remove(struct platform_device *pdev) |
478 | { | 478 | { |
479 | struct ab8500_gpio *ab8500_gpio = platform_get_drvdata(pdev); | 479 | struct ab8500_gpio *ab8500_gpio = platform_get_drvdata(pdev); |
480 | int ret; | 480 | int ret; |
@@ -499,7 +499,7 @@ static struct platform_driver ab8500_gpio_driver = { | |||
499 | .owner = THIS_MODULE, | 499 | .owner = THIS_MODULE, |
500 | }, | 500 | }, |
501 | .probe = ab8500_gpio_probe, | 501 | .probe = ab8500_gpio_probe, |
502 | .remove = ab8500_gpio_remove, | 502 | .remove = __devexit_p(ab8500_gpio_remove), |
503 | }; | 503 | }; |
504 | 504 | ||
505 | static int __init ab8500_gpio_init(void) | 505 | static int __init ab8500_gpio_init(void) |
diff --git a/drivers/gpio/gpio-adnp.c b/drivers/gpio/gpio-adnp.c deleted file mode 100644 index e60567fc507..00000000000 --- a/drivers/gpio/gpio-adnp.c +++ /dev/null | |||
@@ -1,611 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011-2012 Avionic Design GmbH | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #include <linux/gpio.h> | ||
10 | #include <linux/i2c.h> | ||
11 | #include <linux/interrupt.h> | ||
12 | #include <linux/irqdomain.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/of_irq.h> | ||
15 | #include <linux/seq_file.h> | ||
16 | #include <linux/slab.h> | ||
17 | |||
18 | #define GPIO_DDR(gpio) (0x00 << (gpio)->reg_shift) | ||
19 | #define GPIO_PLR(gpio) (0x01 << (gpio)->reg_shift) | ||
20 | #define GPIO_IER(gpio) (0x02 << (gpio)->reg_shift) | ||
21 | #define GPIO_ISR(gpio) (0x03 << (gpio)->reg_shift) | ||
22 | #define GPIO_PTR(gpio) (0x04 << (gpio)->reg_shift) | ||
23 | |||
24 | struct adnp { | ||
25 | struct i2c_client *client; | ||
26 | struct gpio_chip gpio; | ||
27 | unsigned int reg_shift; | ||
28 | |||
29 | struct mutex i2c_lock; | ||
30 | |||
31 | struct irq_domain *domain; | ||
32 | struct mutex irq_lock; | ||
33 | |||
34 | u8 *irq_enable; | ||
35 | u8 *irq_level; | ||
36 | u8 *irq_rise; | ||
37 | u8 *irq_fall; | ||
38 | u8 *irq_high; | ||
39 | u8 *irq_low; | ||
40 | }; | ||
41 | |||
42 | static inline struct adnp *to_adnp(struct gpio_chip *chip) | ||
43 | { | ||
44 | return container_of(chip, struct adnp, gpio); | ||
45 | } | ||
46 | |||
47 | static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value) | ||
48 | { | ||
49 | int err; | ||
50 | |||
51 | err = i2c_smbus_read_byte_data(adnp->client, offset); | ||
52 | if (err < 0) { | ||
53 | dev_err(adnp->gpio.dev, "%s failed: %d\n", | ||
54 | "i2c_smbus_read_byte_data()", err); | ||
55 | return err; | ||
56 | } | ||
57 | |||
58 | *value = err; | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value) | ||
63 | { | ||
64 | int err; | ||
65 | |||
66 | err = i2c_smbus_write_byte_data(adnp->client, offset, value); | ||
67 | if (err < 0) { | ||
68 | dev_err(adnp->gpio.dev, "%s failed: %d\n", | ||
69 | "i2c_smbus_write_byte_data()", err); | ||
70 | return err; | ||
71 | } | ||
72 | |||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | static int adnp_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
77 | { | ||
78 | struct adnp *adnp = to_adnp(chip); | ||
79 | unsigned int reg = offset >> adnp->reg_shift; | ||
80 | unsigned int pos = offset & 7; | ||
81 | u8 value; | ||
82 | int err; | ||
83 | |||
84 | err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &value); | ||
85 | if (err < 0) | ||
86 | return err; | ||
87 | |||
88 | return (value & BIT(pos)) ? 1 : 0; | ||
89 | } | ||
90 | |||
91 | static void __adnp_gpio_set(struct adnp *adnp, unsigned offset, int value) | ||
92 | { | ||
93 | unsigned int reg = offset >> adnp->reg_shift; | ||
94 | unsigned int pos = offset & 7; | ||
95 | int err; | ||
96 | u8 val; | ||
97 | |||
98 | err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &val); | ||
99 | if (err < 0) | ||
100 | return; | ||
101 | |||
102 | if (value) | ||
103 | val |= BIT(pos); | ||
104 | else | ||
105 | val &= ~BIT(pos); | ||
106 | |||
107 | adnp_write(adnp, GPIO_PLR(adnp) + reg, val); | ||
108 | } | ||
109 | |||
110 | static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
111 | { | ||
112 | struct adnp *adnp = to_adnp(chip); | ||
113 | |||
114 | mutex_lock(&adnp->i2c_lock); | ||
115 | __adnp_gpio_set(adnp, offset, value); | ||
116 | mutex_unlock(&adnp->i2c_lock); | ||
117 | } | ||
118 | |||
119 | static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
120 | { | ||
121 | struct adnp *adnp = to_adnp(chip); | ||
122 | unsigned int reg = offset >> adnp->reg_shift; | ||
123 | unsigned int pos = offset & 7; | ||
124 | u8 value; | ||
125 | int err; | ||
126 | |||
127 | mutex_lock(&adnp->i2c_lock); | ||
128 | |||
129 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); | ||
130 | if (err < 0) | ||
131 | goto out; | ||
132 | |||
133 | value &= ~BIT(pos); | ||
134 | |||
135 | err = adnp_write(adnp, GPIO_DDR(adnp) + reg, value); | ||
136 | if (err < 0) | ||
137 | goto out; | ||
138 | |||
139 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); | ||
140 | if (err < 0) | ||
141 | goto out; | ||
142 | |||
143 | if (err & BIT(pos)) | ||
144 | err = -EACCES; | ||
145 | |||
146 | err = 0; | ||
147 | |||
148 | out: | ||
149 | mutex_unlock(&adnp->i2c_lock); | ||
150 | return err; | ||
151 | } | ||
152 | |||
153 | static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset, | ||
154 | int value) | ||
155 | { | ||
156 | struct adnp *adnp = to_adnp(chip); | ||
157 | unsigned int reg = offset >> adnp->reg_shift; | ||
158 | unsigned int pos = offset & 7; | ||
159 | int err; | ||
160 | u8 val; | ||
161 | |||
162 | mutex_lock(&adnp->i2c_lock); | ||
163 | |||
164 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); | ||
165 | if (err < 0) | ||
166 | goto out; | ||
167 | |||
168 | val |= BIT(pos); | ||
169 | |||
170 | err = adnp_write(adnp, GPIO_DDR(adnp) + reg, val); | ||
171 | if (err < 0) | ||
172 | goto out; | ||
173 | |||
174 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); | ||
175 | if (err < 0) | ||
176 | goto out; | ||
177 | |||
178 | if (!(val & BIT(pos))) { | ||
179 | err = -EPERM; | ||
180 | goto out; | ||
181 | } | ||
182 | |||
183 | __adnp_gpio_set(adnp, offset, value); | ||
184 | err = 0; | ||
185 | |||
186 | out: | ||
187 | mutex_unlock(&adnp->i2c_lock); | ||
188 | return err; | ||
189 | } | ||
190 | |||
191 | static void adnp_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) | ||
192 | { | ||
193 | struct adnp *adnp = to_adnp(chip); | ||
194 | unsigned int num_regs = 1 << adnp->reg_shift, i, j; | ||
195 | int err; | ||
196 | |||
197 | for (i = 0; i < num_regs; i++) { | ||
198 | u8 ddr, plr, ier, isr; | ||
199 | |||
200 | mutex_lock(&adnp->i2c_lock); | ||
201 | |||
202 | err = adnp_read(adnp, GPIO_DDR(adnp) + i, &ddr); | ||
203 | if (err < 0) { | ||
204 | mutex_unlock(&adnp->i2c_lock); | ||
205 | return; | ||
206 | } | ||
207 | |||
208 | err = adnp_read(adnp, GPIO_PLR(adnp) + i, &plr); | ||
209 | if (err < 0) { | ||
210 | mutex_unlock(&adnp->i2c_lock); | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); | ||
215 | if (err < 0) { | ||
216 | mutex_unlock(&adnp->i2c_lock); | ||
217 | return; | ||
218 | } | ||
219 | |||
220 | err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); | ||
221 | if (err < 0) { | ||
222 | mutex_unlock(&adnp->i2c_lock); | ||
223 | return; | ||
224 | } | ||
225 | |||
226 | mutex_unlock(&adnp->i2c_lock); | ||
227 | |||
228 | for (j = 0; j < 8; j++) { | ||
229 | unsigned int bit = (i << adnp->reg_shift) + j; | ||
230 | const char *direction = "input "; | ||
231 | const char *level = "low "; | ||
232 | const char *interrupt = "disabled"; | ||
233 | const char *pending = ""; | ||
234 | |||
235 | if (ddr & BIT(j)) | ||
236 | direction = "output"; | ||
237 | |||
238 | if (plr & BIT(j)) | ||
239 | level = "high"; | ||
240 | |||
241 | if (ier & BIT(j)) | ||
242 | interrupt = "enabled "; | ||
243 | |||
244 | if (isr & BIT(j)) | ||
245 | pending = "pending"; | ||
246 | |||
247 | seq_printf(s, "%2u: %s %s IRQ %s %s\n", bit, | ||
248 | direction, level, interrupt, pending); | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios) | ||
254 | { | ||
255 | struct gpio_chip *chip = &adnp->gpio; | ||
256 | |||
257 | adnp->reg_shift = get_count_order(num_gpios) - 3; | ||
258 | |||
259 | chip->direction_input = adnp_gpio_direction_input; | ||
260 | chip->direction_output = adnp_gpio_direction_output; | ||
261 | chip->get = adnp_gpio_get; | ||
262 | chip->set = adnp_gpio_set; | ||
263 | chip->can_sleep = 1; | ||
264 | |||
265 | if (IS_ENABLED(CONFIG_DEBUG_FS)) | ||
266 | chip->dbg_show = adnp_gpio_dbg_show; | ||
267 | |||
268 | chip->base = -1; | ||
269 | chip->ngpio = num_gpios; | ||
270 | chip->label = adnp->client->name; | ||
271 | chip->dev = &adnp->client->dev; | ||
272 | chip->of_node = chip->dev->of_node; | ||
273 | chip->owner = THIS_MODULE; | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static irqreturn_t adnp_irq(int irq, void *data) | ||
279 | { | ||
280 | struct adnp *adnp = data; | ||
281 | unsigned int num_regs, i; | ||
282 | |||
283 | num_regs = 1 << adnp->reg_shift; | ||
284 | |||
285 | for (i = 0; i < num_regs; i++) { | ||
286 | unsigned int base = i << adnp->reg_shift, bit; | ||
287 | u8 changed, level, isr, ier; | ||
288 | unsigned long pending; | ||
289 | int err; | ||
290 | |||
291 | mutex_lock(&adnp->i2c_lock); | ||
292 | |||
293 | err = adnp_read(adnp, GPIO_PLR(adnp) + i, &level); | ||
294 | if (err < 0) { | ||
295 | mutex_unlock(&adnp->i2c_lock); | ||
296 | continue; | ||
297 | } | ||
298 | |||
299 | err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); | ||
300 | if (err < 0) { | ||
301 | mutex_unlock(&adnp->i2c_lock); | ||
302 | continue; | ||
303 | } | ||
304 | |||
305 | err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); | ||
306 | if (err < 0) { | ||
307 | mutex_unlock(&adnp->i2c_lock); | ||
308 | continue; | ||
309 | } | ||
310 | |||
311 | mutex_unlock(&adnp->i2c_lock); | ||
312 | |||
313 | /* determine pins that changed levels */ | ||
314 | changed = level ^ adnp->irq_level[i]; | ||
315 | |||
316 | /* compute edge-triggered interrupts */ | ||
317 | pending = changed & ((adnp->irq_fall[i] & ~level) | | ||
318 | (adnp->irq_rise[i] & level)); | ||
319 | |||
320 | /* add in level-triggered interrupts */ | ||
321 | pending |= (adnp->irq_high[i] & level) | | ||
322 | (adnp->irq_low[i] & ~level); | ||
323 | |||
324 | /* mask out non-pending and disabled interrupts */ | ||
325 | pending &= isr & ier; | ||
326 | |||
327 | for_each_set_bit(bit, &pending, 8) { | ||
328 | unsigned int virq; | ||
329 | virq = irq_find_mapping(adnp->domain, base + bit); | ||
330 | handle_nested_irq(virq); | ||
331 | } | ||
332 | } | ||
333 | |||
334 | return IRQ_HANDLED; | ||
335 | } | ||
336 | |||
337 | static int adnp_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
338 | { | ||
339 | struct adnp *adnp = to_adnp(chip); | ||
340 | return irq_create_mapping(adnp->domain, offset); | ||
341 | } | ||
342 | |||
343 | static void adnp_irq_mask(struct irq_data *data) | ||
344 | { | ||
345 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
346 | unsigned int reg = data->hwirq >> adnp->reg_shift; | ||
347 | unsigned int pos = data->hwirq & 7; | ||
348 | |||
349 | adnp->irq_enable[reg] &= ~BIT(pos); | ||
350 | } | ||
351 | |||
352 | static void adnp_irq_unmask(struct irq_data *data) | ||
353 | { | ||
354 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
355 | unsigned int reg = data->hwirq >> adnp->reg_shift; | ||
356 | unsigned int pos = data->hwirq & 7; | ||
357 | |||
358 | adnp->irq_enable[reg] |= BIT(pos); | ||
359 | } | ||
360 | |||
361 | static int adnp_irq_set_type(struct irq_data *data, unsigned int type) | ||
362 | { | ||
363 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
364 | unsigned int reg = data->hwirq >> adnp->reg_shift; | ||
365 | unsigned int pos = data->hwirq & 7; | ||
366 | |||
367 | if (type & IRQ_TYPE_EDGE_RISING) | ||
368 | adnp->irq_rise[reg] |= BIT(pos); | ||
369 | else | ||
370 | adnp->irq_rise[reg] &= ~BIT(pos); | ||
371 | |||
372 | if (type & IRQ_TYPE_EDGE_FALLING) | ||
373 | adnp->irq_fall[reg] |= BIT(pos); | ||
374 | else | ||
375 | adnp->irq_fall[reg] &= ~BIT(pos); | ||
376 | |||
377 | if (type & IRQ_TYPE_LEVEL_HIGH) | ||
378 | adnp->irq_high[reg] |= BIT(pos); | ||
379 | else | ||
380 | adnp->irq_high[reg] &= ~BIT(pos); | ||
381 | |||
382 | if (type & IRQ_TYPE_LEVEL_LOW) | ||
383 | adnp->irq_low[reg] |= BIT(pos); | ||
384 | else | ||
385 | adnp->irq_low[reg] &= ~BIT(pos); | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | static void adnp_irq_bus_lock(struct irq_data *data) | ||
391 | { | ||
392 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
393 | |||
394 | mutex_lock(&adnp->irq_lock); | ||
395 | } | ||
396 | |||
397 | static void adnp_irq_bus_unlock(struct irq_data *data) | ||
398 | { | ||
399 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
400 | unsigned int num_regs = 1 << adnp->reg_shift, i; | ||
401 | |||
402 | mutex_lock(&adnp->i2c_lock); | ||
403 | |||
404 | for (i = 0; i < num_regs; i++) | ||
405 | adnp_write(adnp, GPIO_IER(adnp) + i, adnp->irq_enable[i]); | ||
406 | |||
407 | mutex_unlock(&adnp->i2c_lock); | ||
408 | mutex_unlock(&adnp->irq_lock); | ||
409 | } | ||
410 | |||
411 | static struct irq_chip adnp_irq_chip = { | ||
412 | .name = "gpio-adnp", | ||
413 | .irq_mask = adnp_irq_mask, | ||
414 | .irq_unmask = adnp_irq_unmask, | ||
415 | .irq_set_type = adnp_irq_set_type, | ||
416 | .irq_bus_lock = adnp_irq_bus_lock, | ||
417 | .irq_bus_sync_unlock = adnp_irq_bus_unlock, | ||
418 | }; | ||
419 | |||
420 | static int adnp_irq_map(struct irq_domain *domain, unsigned int irq, | ||
421 | irq_hw_number_t hwirq) | ||
422 | { | ||
423 | irq_set_chip_data(irq, domain->host_data); | ||
424 | irq_set_chip(irq, &adnp_irq_chip); | ||
425 | irq_set_nested_thread(irq, true); | ||
426 | |||
427 | #ifdef CONFIG_ARM | ||
428 | set_irq_flags(irq, IRQF_VALID); | ||
429 | #else | ||
430 | irq_set_noprobe(irq); | ||
431 | #endif | ||
432 | |||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | static const struct irq_domain_ops adnp_irq_domain_ops = { | ||
437 | .map = adnp_irq_map, | ||
438 | .xlate = irq_domain_xlate_twocell, | ||
439 | }; | ||
440 | |||
441 | static int adnp_irq_setup(struct adnp *adnp) | ||
442 | { | ||
443 | unsigned int num_regs = 1 << adnp->reg_shift, i; | ||
444 | struct gpio_chip *chip = &adnp->gpio; | ||
445 | int err; | ||
446 | |||
447 | mutex_init(&adnp->irq_lock); | ||
448 | |||
449 | /* | ||
450 | * Allocate memory to keep track of the current level and trigger | ||
451 | * modes of the interrupts. To avoid multiple allocations, a single | ||
452 | * large buffer is allocated and pointers are setup to point at the | ||
453 | * corresponding offsets. For consistency, the layout of the buffer | ||
454 | * is chosen to match the register layout of the hardware in that | ||
455 | * each segment contains the corresponding bits for all interrupts. | ||
456 | */ | ||
457 | adnp->irq_enable = devm_kzalloc(chip->dev, num_regs * 6, GFP_KERNEL); | ||
458 | if (!adnp->irq_enable) | ||
459 | return -ENOMEM; | ||
460 | |||
461 | adnp->irq_level = adnp->irq_enable + (num_regs * 1); | ||
462 | adnp->irq_rise = adnp->irq_enable + (num_regs * 2); | ||
463 | adnp->irq_fall = adnp->irq_enable + (num_regs * 3); | ||
464 | adnp->irq_high = adnp->irq_enable + (num_regs * 4); | ||
465 | adnp->irq_low = adnp->irq_enable + (num_regs * 5); | ||
466 | |||
467 | for (i = 0; i < num_regs; i++) { | ||
468 | /* | ||
469 | * Read the initial level of all pins to allow the emulation | ||
470 | * of edge triggered interrupts. | ||
471 | */ | ||
472 | err = adnp_read(adnp, GPIO_PLR(adnp) + i, &adnp->irq_level[i]); | ||
473 | if (err < 0) | ||
474 | return err; | ||
475 | |||
476 | /* disable all interrupts */ | ||
477 | err = adnp_write(adnp, GPIO_IER(adnp) + i, 0); | ||
478 | if (err < 0) | ||
479 | return err; | ||
480 | |||
481 | adnp->irq_enable[i] = 0x00; | ||
482 | } | ||
483 | |||
484 | adnp->domain = irq_domain_add_linear(chip->of_node, chip->ngpio, | ||
485 | &adnp_irq_domain_ops, adnp); | ||
486 | |||
487 | err = request_threaded_irq(adnp->client->irq, NULL, adnp_irq, | ||
488 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, | ||
489 | dev_name(chip->dev), adnp); | ||
490 | if (err != 0) { | ||
491 | dev_err(chip->dev, "can't request IRQ#%d: %d\n", | ||
492 | adnp->client->irq, err); | ||
493 | goto error; | ||
494 | } | ||
495 | |||
496 | chip->to_irq = adnp_gpio_to_irq; | ||
497 | return 0; | ||
498 | |||
499 | error: | ||
500 | irq_domain_remove(adnp->domain); | ||
501 | return err; | ||
502 | } | ||
503 | |||
504 | static void adnp_irq_teardown(struct adnp *adnp) | ||
505 | { | ||
506 | unsigned int irq, i; | ||
507 | |||
508 | free_irq(adnp->client->irq, adnp); | ||
509 | |||
510 | for (i = 0; i < adnp->gpio.ngpio; i++) { | ||
511 | irq = irq_find_mapping(adnp->domain, i); | ||
512 | if (irq > 0) | ||
513 | irq_dispose_mapping(irq); | ||
514 | } | ||
515 | |||
516 | irq_domain_remove(adnp->domain); | ||
517 | } | ||
518 | |||
519 | static int adnp_i2c_probe(struct i2c_client *client, | ||
520 | const struct i2c_device_id *id) | ||
521 | { | ||
522 | struct device_node *np = client->dev.of_node; | ||
523 | struct adnp *adnp; | ||
524 | u32 num_gpios; | ||
525 | int err; | ||
526 | |||
527 | err = of_property_read_u32(np, "nr-gpios", &num_gpios); | ||
528 | if (err < 0) | ||
529 | return err; | ||
530 | |||
531 | client->irq = irq_of_parse_and_map(np, 0); | ||
532 | if (!client->irq) | ||
533 | return -EPROBE_DEFER; | ||
534 | |||
535 | adnp = devm_kzalloc(&client->dev, sizeof(*adnp), GFP_KERNEL); | ||
536 | if (!adnp) | ||
537 | return -ENOMEM; | ||
538 | |||
539 | mutex_init(&adnp->i2c_lock); | ||
540 | adnp->client = client; | ||
541 | |||
542 | err = adnp_gpio_setup(adnp, num_gpios); | ||
543 | if (err < 0) | ||
544 | return err; | ||
545 | |||
546 | if (of_find_property(np, "interrupt-controller", NULL)) { | ||
547 | err = adnp_irq_setup(adnp); | ||
548 | if (err < 0) | ||
549 | goto teardown; | ||
550 | } | ||
551 | |||
552 | err = gpiochip_add(&adnp->gpio); | ||
553 | if (err < 0) | ||
554 | goto teardown; | ||
555 | |||
556 | i2c_set_clientdata(client, adnp); | ||
557 | return 0; | ||
558 | |||
559 | teardown: | ||
560 | if (of_find_property(np, "interrupt-controller", NULL)) | ||
561 | adnp_irq_teardown(adnp); | ||
562 | |||
563 | return err; | ||
564 | } | ||
565 | |||
566 | static int adnp_i2c_remove(struct i2c_client *client) | ||
567 | { | ||
568 | struct adnp *adnp = i2c_get_clientdata(client); | ||
569 | struct device_node *np = client->dev.of_node; | ||
570 | int err; | ||
571 | |||
572 | err = gpiochip_remove(&adnp->gpio); | ||
573 | if (err < 0) { | ||
574 | dev_err(&client->dev, "%s failed: %d\n", "gpiochip_remove()", | ||
575 | err); | ||
576 | return err; | ||
577 | } | ||
578 | |||
579 | if (of_find_property(np, "interrupt-controller", NULL)) | ||
580 | adnp_irq_teardown(adnp); | ||
581 | |||
582 | return 0; | ||
583 | } | ||
584 | |||
585 | static const struct i2c_device_id adnp_i2c_id[] = { | ||
586 | { "gpio-adnp" }, | ||
587 | { }, | ||
588 | }; | ||
589 | MODULE_DEVICE_TABLE(i2c, adnp_i2c_id); | ||
590 | |||
591 | static const struct of_device_id adnp_of_match[] = { | ||
592 | { .compatible = "ad,gpio-adnp", }, | ||
593 | { }, | ||
594 | }; | ||
595 | MODULE_DEVICE_TABLE(of, adnp_of_match); | ||
596 | |||
597 | static struct i2c_driver adnp_i2c_driver = { | ||
598 | .driver = { | ||
599 | .name = "gpio-adnp", | ||
600 | .owner = THIS_MODULE, | ||
601 | .of_match_table = of_match_ptr(adnp_of_match), | ||
602 | }, | ||
603 | .probe = adnp_i2c_probe, | ||
604 | .remove = adnp_i2c_remove, | ||
605 | .id_table = adnp_i2c_id, | ||
606 | }; | ||
607 | module_i2c_driver(adnp_i2c_driver); | ||
608 | |||
609 | MODULE_DESCRIPTION("Avionic Design N-bit GPIO expander"); | ||
610 | MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); | ||
611 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpio/gpio-adp5520.c b/drivers/gpio/gpio-adp5520.c index 8afa95f831b..9f278153700 100644 --- a/drivers/gpio/gpio-adp5520.c +++ b/drivers/gpio/gpio-adp5520.c | |||
@@ -87,7 +87,7 @@ static int adp5520_gpio_direction_output(struct gpio_chip *chip, | |||
87 | return ret; | 87 | return ret; |
88 | } | 88 | } |
89 | 89 | ||
90 | static int adp5520_gpio_probe(struct platform_device *pdev) | 90 | static int __devinit adp5520_gpio_probe(struct platform_device *pdev) |
91 | { | 91 | { |
92 | struct adp5520_gpio_platform_data *pdata = pdev->dev.platform_data; | 92 | struct adp5520_gpio_platform_data *pdata = pdev->dev.platform_data; |
93 | struct adp5520_gpio *dev; | 93 | struct adp5520_gpio *dev; |
@@ -167,7 +167,7 @@ err: | |||
167 | return ret; | 167 | return ret; |
168 | } | 168 | } |
169 | 169 | ||
170 | static int adp5520_gpio_remove(struct platform_device *pdev) | 170 | static int __devexit adp5520_gpio_remove(struct platform_device *pdev) |
171 | { | 171 | { |
172 | struct adp5520_gpio *dev; | 172 | struct adp5520_gpio *dev; |
173 | int ret; | 173 | int ret; |
@@ -190,10 +190,20 @@ static struct platform_driver adp5520_gpio_driver = { | |||
190 | .owner = THIS_MODULE, | 190 | .owner = THIS_MODULE, |
191 | }, | 191 | }, |
192 | .probe = adp5520_gpio_probe, | 192 | .probe = adp5520_gpio_probe, |
193 | .remove = adp5520_gpio_remove, | 193 | .remove = __devexit_p(adp5520_gpio_remove), |
194 | }; | 194 | }; |
195 | 195 | ||
196 | module_platform_driver(adp5520_gpio_driver); | 196 | static int __init adp5520_gpio_init(void) |
197 | { | ||
198 | return platform_driver_register(&adp5520_gpio_driver); | ||
199 | } | ||
200 | module_init(adp5520_gpio_init); | ||
201 | |||
202 | static void __exit adp5520_gpio_exit(void) | ||
203 | { | ||
204 | platform_driver_unregister(&adp5520_gpio_driver); | ||
205 | } | ||
206 | module_exit(adp5520_gpio_exit); | ||
197 | 207 | ||
198 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | 208 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
199 | MODULE_DESCRIPTION("GPIO ADP5520 Driver"); | 209 | MODULE_DESCRIPTION("GPIO ADP5520 Driver"); |
diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c index 2ba56987db0..3525ad91877 100644 --- a/drivers/gpio/gpio-adp5588.c +++ b/drivers/gpio/gpio-adp5588.c | |||
@@ -252,7 +252,7 @@ static irqreturn_t adp5588_irq_handler(int irq, void *devid) | |||
252 | if (ret < 0) | 252 | if (ret < 0) |
253 | memset(dev->irq_stat, 0, ARRAY_SIZE(dev->irq_stat)); | 253 | memset(dev->irq_stat, 0, ARRAY_SIZE(dev->irq_stat)); |
254 | 254 | ||
255 | for (bank = 0, bit = 0; bank <= ADP5588_BANK(ADP5588_MAXGPIO); | 255 | for (bank = 0; bank <= ADP5588_BANK(ADP5588_MAXGPIO); |
256 | bank++, bit = 0) { | 256 | bank++, bit = 0) { |
257 | pending = dev->irq_stat[bank] & dev->irq_mask[bank]; | 257 | pending = dev->irq_stat[bank] & dev->irq_mask[bank]; |
258 | 258 | ||
@@ -346,7 +346,7 @@ static void adp5588_irq_teardown(struct adp5588_gpio *dev) | |||
346 | } | 346 | } |
347 | #endif /* CONFIG_GPIO_ADP5588_IRQ */ | 347 | #endif /* CONFIG_GPIO_ADP5588_IRQ */ |
348 | 348 | ||
349 | static int adp5588_gpio_probe(struct i2c_client *client, | 349 | static int __devinit adp5588_gpio_probe(struct i2c_client *client, |
350 | const struct i2c_device_id *id) | 350 | const struct i2c_device_id *id) |
351 | { | 351 | { |
352 | struct adp5588_gpio_platform_data *pdata = client->dev.platform_data; | 352 | struct adp5588_gpio_platform_data *pdata = client->dev.platform_data; |
@@ -418,8 +418,9 @@ static int adp5588_gpio_probe(struct i2c_client *client, | |||
418 | if (ret) | 418 | if (ret) |
419 | goto err_irq; | 419 | goto err_irq; |
420 | 420 | ||
421 | dev_info(&client->dev, "IRQ Base: %d Rev.: %d\n", | 421 | dev_info(&client->dev, "gpios %d..%d (IRQ Base %d) on a %s Rev. %d\n", |
422 | pdata->irq_base, revid); | 422 | gc->base, gc->base + gc->ngpio - 1, |
423 | pdata->irq_base, client->name, revid); | ||
423 | 424 | ||
424 | if (pdata->setup) { | 425 | if (pdata->setup) { |
425 | ret = pdata->setup(client, gc->base, gc->ngpio, pdata->context); | 426 | ret = pdata->setup(client, gc->base, gc->ngpio, pdata->context); |
@@ -438,7 +439,7 @@ err: | |||
438 | return ret; | 439 | return ret; |
439 | } | 440 | } |
440 | 441 | ||
441 | static int adp5588_gpio_remove(struct i2c_client *client) | 442 | static int __devexit adp5588_gpio_remove(struct i2c_client *client) |
442 | { | 443 | { |
443 | struct adp5588_gpio_platform_data *pdata = client->dev.platform_data; | 444 | struct adp5588_gpio_platform_data *pdata = client->dev.platform_data; |
444 | struct adp5588_gpio *dev = i2c_get_clientdata(client); | 445 | struct adp5588_gpio *dev = i2c_get_clientdata(client); |
@@ -479,11 +480,23 @@ static struct i2c_driver adp5588_gpio_driver = { | |||
479 | .name = DRV_NAME, | 480 | .name = DRV_NAME, |
480 | }, | 481 | }, |
481 | .probe = adp5588_gpio_probe, | 482 | .probe = adp5588_gpio_probe, |
482 | .remove = adp5588_gpio_remove, | 483 | .remove = __devexit_p(adp5588_gpio_remove), |
483 | .id_table = adp5588_gpio_id, | 484 | .id_table = adp5588_gpio_id, |
484 | }; | 485 | }; |
485 | 486 | ||
486 | module_i2c_driver(adp5588_gpio_driver); | 487 | static int __init adp5588_gpio_init(void) |
488 | { | ||
489 | return i2c_add_driver(&adp5588_gpio_driver); | ||
490 | } | ||
491 | |||
492 | module_init(adp5588_gpio_init); | ||
493 | |||
494 | static void __exit adp5588_gpio_exit(void) | ||
495 | { | ||
496 | i2c_del_driver(&adp5588_gpio_driver); | ||
497 | } | ||
498 | |||
499 | module_exit(adp5588_gpio_exit); | ||
487 | 500 | ||
488 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | 501 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
489 | MODULE_DESCRIPTION("GPIO ADP5588 Driver"); | 502 | MODULE_DESCRIPTION("GPIO ADP5588 Driver"); |
diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c deleted file mode 100644 index 710fafcdd1b..00000000000 --- a/drivers/gpio/gpio-amd8111.c +++ /dev/null | |||
@@ -1,246 +0,0 @@ | |||
1 | /* | ||
2 | * GPIO driver for AMD 8111 south bridges | ||
3 | * | ||
4 | * Copyright (c) 2012 Dmitry Eremin-Solenikov | ||
5 | * | ||
6 | * Based on the AMD RNG driver: | ||
7 | * Copyright 2005 (c) MontaVista Software, Inc. | ||
8 | * with the majority of the code coming from: | ||
9 | * | ||
10 | * Hardware driver for the Intel/AMD/VIA Random Number Generators (RNG) | ||
11 | * (c) Copyright 2003 Red Hat Inc <jgarzik@redhat.com> | ||
12 | * | ||
13 | * derived from | ||
14 | * | ||
15 | * Hardware driver for the AMD 768 Random Number Generator (RNG) | ||
16 | * (c) Copyright 2001 Red Hat Inc | ||
17 | * | ||
18 | * derived from | ||
19 | * | ||
20 | * Hardware driver for Intel i810 Random Number Generator (RNG) | ||
21 | * Copyright 2000,2001 Jeff Garzik <jgarzik@pobox.com> | ||
22 | * Copyright 2000,2001 Philipp Rumpf <prumpf@mandrakesoft.com> | ||
23 | * | ||
24 | * This file is licensed under the terms of the GNU General Public | ||
25 | * License version 2. This program is licensed "as is" without any | ||
26 | * warranty of any kind, whether express or implied. | ||
27 | */ | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/gpio.h> | ||
31 | #include <linux/pci.h> | ||
32 | #include <linux/spinlock.h> | ||
33 | |||
34 | #define PMBASE_OFFSET 0xb0 | ||
35 | #define PMBASE_SIZE 0x30 | ||
36 | |||
37 | #define AMD_REG_GPIO(i) (0x10 + (i)) | ||
38 | |||
39 | #define AMD_GPIO_LTCH_STS 0x40 /* Latch status, w1 */ | ||
40 | #define AMD_GPIO_RTIN 0x20 /* Real Time in, ro */ | ||
41 | #define AMD_GPIO_DEBOUNCE 0x10 /* Debounce, rw */ | ||
42 | #define AMD_GPIO_MODE_MASK 0x0c /* Pin Mode Select, rw */ | ||
43 | #define AMD_GPIO_MODE_IN 0x00 | ||
44 | #define AMD_GPIO_MODE_OUT 0x04 | ||
45 | /* Enable alternative (e.g. clkout, IRQ, etc) function of the pin */ | ||
46 | #define AMD_GPIO_MODE_ALTFN 0x08 /* Or 0x09 */ | ||
47 | #define AMD_GPIO_X_MASK 0x03 /* In/Out specific, rw */ | ||
48 | #define AMD_GPIO_X_IN_ACTIVEHI 0x01 /* Active High */ | ||
49 | #define AMD_GPIO_X_IN_LATCH 0x02 /* Latched version is selected */ | ||
50 | #define AMD_GPIO_X_OUT_LOW 0x00 | ||
51 | #define AMD_GPIO_X_OUT_HI 0x01 | ||
52 | #define AMD_GPIO_X_OUT_CLK0 0x02 | ||
53 | #define AMD_GPIO_X_OUT_CLK1 0x03 | ||
54 | |||
55 | /* | ||
56 | * Data for PCI driver interface | ||
57 | * | ||
58 | * This data only exists for exporting the supported | ||
59 | * PCI ids via MODULE_DEVICE_TABLE. We do not actually | ||
60 | * register a pci_driver, because someone else might one day | ||
61 | * want to register another driver on the same PCI id. | ||
62 | */ | ||
63 | static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = { | ||
64 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS), 0 }, | ||
65 | { 0, }, /* terminate list */ | ||
66 | }; | ||
67 | MODULE_DEVICE_TABLE(pci, pci_tbl); | ||
68 | |||
69 | struct amd_gpio { | ||
70 | struct gpio_chip chip; | ||
71 | u32 pmbase; | ||
72 | void __iomem *pm; | ||
73 | struct pci_dev *pdev; | ||
74 | spinlock_t lock; /* guards hw registers and orig table */ | ||
75 | u8 orig[32]; | ||
76 | }; | ||
77 | |||
78 | #define to_agp(chip) container_of(chip, struct amd_gpio, chip) | ||
79 | |||
80 | static int amd_gpio_request(struct gpio_chip *chip, unsigned offset) | ||
81 | { | ||
82 | struct amd_gpio *agp = to_agp(chip); | ||
83 | |||
84 | agp->orig[offset] = ioread8(agp->pm + AMD_REG_GPIO(offset)) & | ||
85 | (AMD_GPIO_DEBOUNCE | AMD_GPIO_MODE_MASK | AMD_GPIO_X_MASK); | ||
86 | |||
87 | dev_dbg(&agp->pdev->dev, "Requested gpio %d, data %x\n", offset, agp->orig[offset]); | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static void amd_gpio_free(struct gpio_chip *chip, unsigned offset) | ||
93 | { | ||
94 | struct amd_gpio *agp = to_agp(chip); | ||
95 | |||
96 | dev_dbg(&agp->pdev->dev, "Freed gpio %d, data %x\n", offset, agp->orig[offset]); | ||
97 | |||
98 | iowrite8(agp->orig[offset], agp->pm + AMD_REG_GPIO(offset)); | ||
99 | } | ||
100 | |||
101 | static void amd_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
102 | { | ||
103 | struct amd_gpio *agp = to_agp(chip); | ||
104 | u8 temp; | ||
105 | unsigned long flags; | ||
106 | |||
107 | spin_lock_irqsave(&agp->lock, flags); | ||
108 | temp = ioread8(agp->pm + AMD_REG_GPIO(offset)); | ||
109 | temp = (temp & AMD_GPIO_DEBOUNCE) | AMD_GPIO_MODE_OUT | (value ? AMD_GPIO_X_OUT_HI : AMD_GPIO_X_OUT_LOW); | ||
110 | iowrite8(temp, agp->pm + AMD_REG_GPIO(offset)); | ||
111 | spin_unlock_irqrestore(&agp->lock, flags); | ||
112 | |||
113 | dev_dbg(&agp->pdev->dev, "Setting gpio %d, value %d, reg=%02x\n", offset, !!value, temp); | ||
114 | } | ||
115 | |||
116 | static int amd_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
117 | { | ||
118 | struct amd_gpio *agp = to_agp(chip); | ||
119 | u8 temp; | ||
120 | |||
121 | temp = ioread8(agp->pm + AMD_REG_GPIO(offset)); | ||
122 | |||
123 | dev_dbg(&agp->pdev->dev, "Getting gpio %d, reg=%02x\n", offset, temp); | ||
124 | |||
125 | return (temp & AMD_GPIO_RTIN) ? 1 : 0; | ||
126 | } | ||
127 | |||
128 | static int amd_gpio_dirout(struct gpio_chip *chip, unsigned offset, int value) | ||
129 | { | ||
130 | struct amd_gpio *agp = to_agp(chip); | ||
131 | u8 temp; | ||
132 | unsigned long flags; | ||
133 | |||
134 | spin_lock_irqsave(&agp->lock, flags); | ||
135 | temp = ioread8(agp->pm + AMD_REG_GPIO(offset)); | ||
136 | temp = (temp & AMD_GPIO_DEBOUNCE) | AMD_GPIO_MODE_OUT | (value ? AMD_GPIO_X_OUT_HI : AMD_GPIO_X_OUT_LOW); | ||
137 | iowrite8(temp, agp->pm + AMD_REG_GPIO(offset)); | ||
138 | spin_unlock_irqrestore(&agp->lock, flags); | ||
139 | |||
140 | dev_dbg(&agp->pdev->dev, "Dirout gpio %d, value %d, reg=%02x\n", offset, !!value, temp); | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | static int amd_gpio_dirin(struct gpio_chip *chip, unsigned offset) | ||
146 | { | ||
147 | struct amd_gpio *agp = to_agp(chip); | ||
148 | u8 temp; | ||
149 | unsigned long flags; | ||
150 | |||
151 | spin_lock_irqsave(&agp->lock, flags); | ||
152 | temp = ioread8(agp->pm + AMD_REG_GPIO(offset)); | ||
153 | temp = (temp & AMD_GPIO_DEBOUNCE) | AMD_GPIO_MODE_IN; | ||
154 | iowrite8(temp, agp->pm + AMD_REG_GPIO(offset)); | ||
155 | spin_unlock_irqrestore(&agp->lock, flags); | ||
156 | |||
157 | dev_dbg(&agp->pdev->dev, "Dirin gpio %d, reg=%02x\n", offset, temp); | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static struct amd_gpio gp = { | ||
163 | .chip = { | ||
164 | .label = "AMD GPIO", | ||
165 | .owner = THIS_MODULE, | ||
166 | .base = -1, | ||
167 | .ngpio = 32, | ||
168 | .request = amd_gpio_request, | ||
169 | .free = amd_gpio_free, | ||
170 | .set = amd_gpio_set, | ||
171 | .get = amd_gpio_get, | ||
172 | .direction_output = amd_gpio_dirout, | ||
173 | .direction_input = amd_gpio_dirin, | ||
174 | }, | ||
175 | }; | ||
176 | |||
177 | static int __init amd_gpio_init(void) | ||
178 | { | ||
179 | int err = -ENODEV; | ||
180 | struct pci_dev *pdev = NULL; | ||
181 | const struct pci_device_id *ent; | ||
182 | |||
183 | |||
184 | /* We look for our device - AMD South Bridge | ||
185 | * I don't know about a system with two such bridges, | ||
186 | * so we can assume that there is max. one device. | ||
187 | * | ||
188 | * We can't use plain pci_driver mechanism, | ||
189 | * as the device is really a multiple function device, | ||
190 | * main driver that binds to the pci_device is an smbus | ||
191 | * driver and have to find & bind to the device this way. | ||
192 | */ | ||
193 | for_each_pci_dev(pdev) { | ||
194 | ent = pci_match_id(pci_tbl, pdev); | ||
195 | if (ent) | ||
196 | goto found; | ||
197 | } | ||
198 | /* Device not found. */ | ||
199 | goto out; | ||
200 | |||
201 | found: | ||
202 | err = pci_read_config_dword(pdev, 0x58, &gp.pmbase); | ||
203 | if (err) | ||
204 | goto out; | ||
205 | err = -EIO; | ||
206 | gp.pmbase &= 0x0000FF00; | ||
207 | if (gp.pmbase == 0) | ||
208 | goto out; | ||
209 | if (!request_region(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE, "AMD GPIO")) { | ||
210 | dev_err(&pdev->dev, "AMD GPIO region 0x%x already in use!\n", | ||
211 | gp.pmbase + PMBASE_OFFSET); | ||
212 | err = -EBUSY; | ||
213 | goto out; | ||
214 | } | ||
215 | gp.pm = ioport_map(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE); | ||
216 | gp.pdev = pdev; | ||
217 | gp.chip.dev = &pdev->dev; | ||
218 | |||
219 | spin_lock_init(&gp.lock); | ||
220 | |||
221 | printk(KERN_INFO "AMD-8111 GPIO detected\n"); | ||
222 | err = gpiochip_add(&gp.chip); | ||
223 | if (err) { | ||
224 | printk(KERN_ERR "GPIO registering failed (%d)\n", | ||
225 | err); | ||
226 | release_region(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE); | ||
227 | goto out; | ||
228 | } | ||
229 | out: | ||
230 | return err; | ||
231 | } | ||
232 | |||
233 | static void __exit amd_gpio_exit(void) | ||
234 | { | ||
235 | int err = gpiochip_remove(&gp.chip); | ||
236 | WARN_ON(err); | ||
237 | ioport_unmap(gp.pm); | ||
238 | release_region(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE); | ||
239 | } | ||
240 | |||
241 | module_init(amd_gpio_init); | ||
242 | module_exit(amd_gpio_exit); | ||
243 | |||
244 | MODULE_AUTHOR("The Linux Kernel team"); | ||
245 | MODULE_DESCRIPTION("GPIO driver for AMD chipsets"); | ||
246 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpio/gpio-arizona.c b/drivers/gpio/gpio-arizona.c deleted file mode 100644 index 0ea853f68db..00000000000 --- a/drivers/gpio/gpio-arizona.c +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | /* | ||
2 | * gpiolib support for Wolfson Arizona class devices | ||
3 | * | ||
4 | * Copyright 2012 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/gpio.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/seq_file.h> | ||
21 | |||
22 | #include <linux/mfd/arizona/core.h> | ||
23 | #include <linux/mfd/arizona/pdata.h> | ||
24 | #include <linux/mfd/arizona/registers.h> | ||
25 | |||
26 | struct arizona_gpio { | ||
27 | struct arizona *arizona; | ||
28 | struct gpio_chip gpio_chip; | ||
29 | }; | ||
30 | |||
31 | static inline struct arizona_gpio *to_arizona_gpio(struct gpio_chip *chip) | ||
32 | { | ||
33 | return container_of(chip, struct arizona_gpio, gpio_chip); | ||
34 | } | ||
35 | |||
36 | static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset) | ||
37 | { | ||
38 | struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); | ||
39 | struct arizona *arizona = arizona_gpio->arizona; | ||
40 | |||
41 | return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, | ||
42 | ARIZONA_GPN_DIR, ARIZONA_GPN_DIR); | ||
43 | } | ||
44 | |||
45 | static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
46 | { | ||
47 | struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); | ||
48 | struct arizona *arizona = arizona_gpio->arizona; | ||
49 | unsigned int val; | ||
50 | int ret; | ||
51 | |||
52 | ret = regmap_read(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, &val); | ||
53 | if (ret < 0) | ||
54 | return ret; | ||
55 | |||
56 | if (val & ARIZONA_GPN_LVL) | ||
57 | return 1; | ||
58 | else | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int arizona_gpio_direction_out(struct gpio_chip *chip, | ||
63 | unsigned offset, int value) | ||
64 | { | ||
65 | struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); | ||
66 | struct arizona *arizona = arizona_gpio->arizona; | ||
67 | |||
68 | if (value) | ||
69 | value = ARIZONA_GPN_LVL; | ||
70 | |||
71 | return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, | ||
72 | ARIZONA_GPN_DIR | ARIZONA_GPN_LVL, value); | ||
73 | } | ||
74 | |||
75 | static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
76 | { | ||
77 | struct arizona_gpio *arizona_gpio = to_arizona_gpio(chip); | ||
78 | struct arizona *arizona = arizona_gpio->arizona; | ||
79 | |||
80 | if (value) | ||
81 | value = ARIZONA_GPN_LVL; | ||
82 | |||
83 | regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, | ||
84 | ARIZONA_GPN_LVL, value); | ||
85 | } | ||
86 | |||
87 | static struct gpio_chip template_chip = { | ||
88 | .label = "arizona", | ||
89 | .owner = THIS_MODULE, | ||
90 | .direction_input = arizona_gpio_direction_in, | ||
91 | .get = arizona_gpio_get, | ||
92 | .direction_output = arizona_gpio_direction_out, | ||
93 | .set = arizona_gpio_set, | ||
94 | .can_sleep = 1, | ||
95 | }; | ||
96 | |||
97 | static int arizona_gpio_probe(struct platform_device *pdev) | ||
98 | { | ||
99 | struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); | ||
100 | struct arizona_pdata *pdata = arizona->dev->platform_data; | ||
101 | struct arizona_gpio *arizona_gpio; | ||
102 | int ret; | ||
103 | |||
104 | arizona_gpio = devm_kzalloc(&pdev->dev, sizeof(*arizona_gpio), | ||
105 | GFP_KERNEL); | ||
106 | if (arizona_gpio == NULL) | ||
107 | return -ENOMEM; | ||
108 | |||
109 | arizona_gpio->arizona = arizona; | ||
110 | arizona_gpio->gpio_chip = template_chip; | ||
111 | arizona_gpio->gpio_chip.dev = &pdev->dev; | ||
112 | |||
113 | switch (arizona->type) { | ||
114 | case WM5102: | ||
115 | case WM5110: | ||
116 | arizona_gpio->gpio_chip.ngpio = 5; | ||
117 | break; | ||
118 | default: | ||
119 | dev_err(&pdev->dev, "Unknown chip variant %d\n", | ||
120 | arizona->type); | ||
121 | return -EINVAL; | ||
122 | } | ||
123 | |||
124 | if (pdata && pdata->gpio_base) | ||
125 | arizona_gpio->gpio_chip.base = pdata->gpio_base; | ||
126 | else | ||
127 | arizona_gpio->gpio_chip.base = -1; | ||
128 | |||
129 | ret = gpiochip_add(&arizona_gpio->gpio_chip); | ||
130 | if (ret < 0) { | ||
131 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", | ||
132 | ret); | ||
133 | goto err; | ||
134 | } | ||
135 | |||
136 | platform_set_drvdata(pdev, arizona_gpio); | ||
137 | |||
138 | return ret; | ||
139 | |||
140 | err: | ||
141 | return ret; | ||
142 | } | ||
143 | |||
144 | static int arizona_gpio_remove(struct platform_device *pdev) | ||
145 | { | ||
146 | struct arizona_gpio *arizona_gpio = platform_get_drvdata(pdev); | ||
147 | |||
148 | return gpiochip_remove(&arizona_gpio->gpio_chip); | ||
149 | } | ||
150 | |||
151 | static struct platform_driver arizona_gpio_driver = { | ||
152 | .driver.name = "arizona-gpio", | ||
153 | .driver.owner = THIS_MODULE, | ||
154 | .probe = arizona_gpio_probe, | ||
155 | .remove = arizona_gpio_remove, | ||
156 | }; | ||
157 | |||
158 | module_platform_driver(arizona_gpio_driver); | ||
159 | |||
160 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
161 | MODULE_DESCRIPTION("GPIO interface for Arizona devices"); | ||
162 | MODULE_LICENSE("GPL"); | ||
163 | MODULE_ALIAS("platform:arizona-gpio"); | ||
diff --git a/drivers/gpio/gpio-bt8xx.c b/drivers/gpio/gpio-bt8xx.c index 7d9d7cb35f2..ec57936aef6 100644 --- a/drivers/gpio/gpio-bt8xx.c +++ b/drivers/gpio/gpio-bt8xx.c | |||
@@ -50,7 +50,7 @@ | |||
50 | #include <linux/slab.h> | 50 | #include <linux/slab.h> |
51 | 51 | ||
52 | /* Steal the hardware definitions from the bttv driver. */ | 52 | /* Steal the hardware definitions from the bttv driver. */ |
53 | #include "../media/pci/bt8xx/bt848.h" | 53 | #include "../media/video/bt8xx/bt848.h" |
54 | 54 | ||
55 | 55 | ||
56 | #define BT8XXGPIO_NR_GPIOS 24 /* We have 24 GPIO pins */ | 56 | #define BT8XXGPIO_NR_GPIOS 24 /* We have 24 GPIO pins */ |
@@ -223,6 +223,9 @@ static int bt8xxgpio_probe(struct pci_dev *dev, | |||
223 | goto err_release_mem; | 223 | goto err_release_mem; |
224 | } | 224 | } |
225 | 225 | ||
226 | printk(KERN_INFO "bt8xxgpio: Abusing BT8xx card for GPIOs %d to %d\n", | ||
227 | bg->gpio.base, bg->gpio.base + BT8XXGPIO_NR_GPIOS - 1); | ||
228 | |||
226 | return 0; | 229 | return 0; |
227 | 230 | ||
228 | err_release_mem: | 231 | err_release_mem: |
@@ -310,7 +313,7 @@ static int bt8xxgpio_resume(struct pci_dev *pdev) | |||
310 | #define bt8xxgpio_resume NULL | 313 | #define bt8xxgpio_resume NULL |
311 | #endif /* CONFIG_PM */ | 314 | #endif /* CONFIG_PM */ |
312 | 315 | ||
313 | static DEFINE_PCI_DEVICE_TABLE(bt8xxgpio_pci_tbl) = { | 316 | static struct pci_device_id bt8xxgpio_pci_tbl[] = { |
314 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) }, | 317 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) }, |
315 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) }, | 318 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) }, |
316 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) }, | 319 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) }, |
@@ -328,7 +331,17 @@ static struct pci_driver bt8xxgpio_pci_driver = { | |||
328 | .resume = bt8xxgpio_resume, | 331 | .resume = bt8xxgpio_resume, |
329 | }; | 332 | }; |
330 | 333 | ||
331 | module_pci_driver(bt8xxgpio_pci_driver); | 334 | static int __init bt8xxgpio_init(void) |
335 | { | ||
336 | return pci_register_driver(&bt8xxgpio_pci_driver); | ||
337 | } | ||
338 | module_init(bt8xxgpio_init) | ||
339 | |||
340 | static void __exit bt8xxgpio_exit(void) | ||
341 | { | ||
342 | pci_unregister_driver(&bt8xxgpio_pci_driver); | ||
343 | } | ||
344 | module_exit(bt8xxgpio_exit) | ||
332 | 345 | ||
333 | MODULE_LICENSE("GPL"); | 346 | MODULE_LICENSE("GPL"); |
334 | MODULE_AUTHOR("Michael Buesch"); | 347 | MODULE_AUTHOR("Michael Buesch"); |
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c deleted file mode 100644 index ce63b75b13f..00000000000 --- a/drivers/gpio/gpio-clps711x.c +++ /dev/null | |||
@@ -1,199 +0,0 @@ | |||
1 | /* | ||
2 | * CLPS711X GPIO driver | ||
3 | * | ||
4 | * Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru> | ||
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 | |||
12 | #include <linux/io.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/gpio.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/spinlock.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | |||
19 | #include <mach/hardware.h> | ||
20 | |||
21 | #define CLPS711X_GPIO_PORTS 5 | ||
22 | #define CLPS711X_GPIO_NAME "gpio-clps711x" | ||
23 | |||
24 | struct clps711x_gpio { | ||
25 | struct gpio_chip chip[CLPS711X_GPIO_PORTS]; | ||
26 | spinlock_t lock; | ||
27 | }; | ||
28 | |||
29 | static void __iomem *clps711x_ports[] = { | ||
30 | CLPS711X_VIRT_BASE + PADR, | ||
31 | CLPS711X_VIRT_BASE + PBDR, | ||
32 | CLPS711X_VIRT_BASE + PCDR, | ||
33 | CLPS711X_VIRT_BASE + PDDR, | ||
34 | CLPS711X_VIRT_BASE + PEDR, | ||
35 | }; | ||
36 | |||
37 | static void __iomem *clps711x_pdirs[] = { | ||
38 | CLPS711X_VIRT_BASE + PADDR, | ||
39 | CLPS711X_VIRT_BASE + PBDDR, | ||
40 | CLPS711X_VIRT_BASE + PCDDR, | ||
41 | CLPS711X_VIRT_BASE + PDDDR, | ||
42 | CLPS711X_VIRT_BASE + PEDDR, | ||
43 | }; | ||
44 | |||
45 | #define clps711x_port(x) clps711x_ports[x->base / 8] | ||
46 | #define clps711x_pdir(x) clps711x_pdirs[x->base / 8] | ||
47 | |||
48 | static int gpio_clps711x_get(struct gpio_chip *chip, unsigned offset) | ||
49 | { | ||
50 | return !!(readb(clps711x_port(chip)) & (1 << offset)); | ||
51 | } | ||
52 | |||
53 | static void gpio_clps711x_set(struct gpio_chip *chip, unsigned offset, | ||
54 | int value) | ||
55 | { | ||
56 | int tmp; | ||
57 | unsigned long flags; | ||
58 | struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev); | ||
59 | |||
60 | spin_lock_irqsave(&gpio->lock, flags); | ||
61 | tmp = readb(clps711x_port(chip)) & ~(1 << offset); | ||
62 | if (value) | ||
63 | tmp |= 1 << offset; | ||
64 | writeb(tmp, clps711x_port(chip)); | ||
65 | spin_unlock_irqrestore(&gpio->lock, flags); | ||
66 | } | ||
67 | |||
68 | static int gpio_clps711x_dir_in(struct gpio_chip *chip, unsigned offset) | ||
69 | { | ||
70 | int tmp; | ||
71 | unsigned long flags; | ||
72 | struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev); | ||
73 | |||
74 | spin_lock_irqsave(&gpio->lock, flags); | ||
75 | tmp = readb(clps711x_pdir(chip)) & ~(1 << offset); | ||
76 | writeb(tmp, clps711x_pdir(chip)); | ||
77 | spin_unlock_irqrestore(&gpio->lock, flags); | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | static int gpio_clps711x_dir_out(struct gpio_chip *chip, unsigned offset, | ||
83 | int value) | ||
84 | { | ||
85 | int tmp; | ||
86 | unsigned long flags; | ||
87 | struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev); | ||
88 | |||
89 | spin_lock_irqsave(&gpio->lock, flags); | ||
90 | tmp = readb(clps711x_pdir(chip)) | (1 << offset); | ||
91 | writeb(tmp, clps711x_pdir(chip)); | ||
92 | tmp = readb(clps711x_port(chip)) & ~(1 << offset); | ||
93 | if (value) | ||
94 | tmp |= 1 << offset; | ||
95 | writeb(tmp, clps711x_port(chip)); | ||
96 | spin_unlock_irqrestore(&gpio->lock, flags); | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | static int gpio_clps711x_dir_in_inv(struct gpio_chip *chip, unsigned offset) | ||
102 | { | ||
103 | int tmp; | ||
104 | unsigned long flags; | ||
105 | struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev); | ||
106 | |||
107 | spin_lock_irqsave(&gpio->lock, flags); | ||
108 | tmp = readb(clps711x_pdir(chip)) | (1 << offset); | ||
109 | writeb(tmp, clps711x_pdir(chip)); | ||
110 | spin_unlock_irqrestore(&gpio->lock, flags); | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static int gpio_clps711x_dir_out_inv(struct gpio_chip *chip, unsigned offset, | ||
116 | int value) | ||
117 | { | ||
118 | int tmp; | ||
119 | unsigned long flags; | ||
120 | struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev); | ||
121 | |||
122 | spin_lock_irqsave(&gpio->lock, flags); | ||
123 | tmp = readb(clps711x_pdir(chip)) & ~(1 << offset); | ||
124 | writeb(tmp, clps711x_pdir(chip)); | ||
125 | tmp = readb(clps711x_port(chip)) & ~(1 << offset); | ||
126 | if (value) | ||
127 | tmp |= 1 << offset; | ||
128 | writeb(tmp, clps711x_port(chip)); | ||
129 | spin_unlock_irqrestore(&gpio->lock, flags); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | static struct { | ||
135 | char *name; | ||
136 | int nr; | ||
137 | int inv_dir; | ||
138 | } clps711x_gpio_ports[] __initconst = { | ||
139 | { "PORTA", 8, 0, }, | ||
140 | { "PORTB", 8, 0, }, | ||
141 | { "PORTC", 8, 0, }, | ||
142 | { "PORTD", 8, 1, }, | ||
143 | { "PORTE", 3, 0, }, | ||
144 | }; | ||
145 | |||
146 | static int __init gpio_clps711x_init(void) | ||
147 | { | ||
148 | int i; | ||
149 | struct platform_device *pdev; | ||
150 | struct clps711x_gpio *gpio; | ||
151 | |||
152 | pdev = platform_device_alloc(CLPS711X_GPIO_NAME, 0); | ||
153 | if (!pdev) { | ||
154 | pr_err("Cannot create platform device: %s\n", | ||
155 | CLPS711X_GPIO_NAME); | ||
156 | return -ENOMEM; | ||
157 | } | ||
158 | |||
159 | platform_device_add(pdev); | ||
160 | |||
161 | gpio = devm_kzalloc(&pdev->dev, sizeof(struct clps711x_gpio), | ||
162 | GFP_KERNEL); | ||
163 | if (!gpio) { | ||
164 | dev_err(&pdev->dev, "GPIO allocating memory error\n"); | ||
165 | platform_device_unregister(pdev); | ||
166 | return -ENOMEM; | ||
167 | } | ||
168 | |||
169 | platform_set_drvdata(pdev, gpio); | ||
170 | |||
171 | spin_lock_init(&gpio->lock); | ||
172 | |||
173 | for (i = 0; i < CLPS711X_GPIO_PORTS; i++) { | ||
174 | gpio->chip[i].owner = THIS_MODULE; | ||
175 | gpio->chip[i].dev = &pdev->dev; | ||
176 | gpio->chip[i].label = clps711x_gpio_ports[i].name; | ||
177 | gpio->chip[i].base = i * 8; | ||
178 | gpio->chip[i].ngpio = clps711x_gpio_ports[i].nr; | ||
179 | gpio->chip[i].get = gpio_clps711x_get; | ||
180 | gpio->chip[i].set = gpio_clps711x_set; | ||
181 | if (!clps711x_gpio_ports[i].inv_dir) { | ||
182 | gpio->chip[i].direction_input = gpio_clps711x_dir_in; | ||
183 | gpio->chip[i].direction_output = gpio_clps711x_dir_out; | ||
184 | } else { | ||
185 | gpio->chip[i].direction_input = gpio_clps711x_dir_in_inv; | ||
186 | gpio->chip[i].direction_output = gpio_clps711x_dir_out_inv; | ||
187 | } | ||
188 | WARN_ON(gpiochip_add(&gpio->chip[i])); | ||
189 | } | ||
190 | |||
191 | dev_info(&pdev->dev, "GPIO driver initialized\n"); | ||
192 | |||
193 | return 0; | ||
194 | } | ||
195 | arch_initcall(gpio_clps711x_init); | ||
196 | |||
197 | MODULE_LICENSE("GPL v2"); | ||
198 | MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>"); | ||
199 | MODULE_DESCRIPTION("CLPS711X GPIO driver"); | ||
diff --git a/drivers/gpio/gpio-cs5535.c b/drivers/gpio/gpio-cs5535.c index c0a3aeba6f2..6e16cba56ad 100644 --- a/drivers/gpio/gpio-cs5535.c +++ b/drivers/gpio/gpio-cs5535.c | |||
@@ -300,7 +300,7 @@ static struct cs5535_gpio_chip cs5535_gpio_chip = { | |||
300 | }, | 300 | }, |
301 | }; | 301 | }; |
302 | 302 | ||
303 | static int cs5535_gpio_probe(struct platform_device *pdev) | 303 | static int __devinit cs5535_gpio_probe(struct platform_device *pdev) |
304 | { | 304 | { |
305 | struct resource *res; | 305 | struct resource *res; |
306 | int err = -EIO; | 306 | int err = -EIO; |
@@ -347,6 +347,7 @@ static int cs5535_gpio_probe(struct platform_device *pdev) | |||
347 | if (err) | 347 | if (err) |
348 | goto release_region; | 348 | goto release_region; |
349 | 349 | ||
350 | dev_info(&pdev->dev, "GPIO support successfully loaded.\n"); | ||
350 | return 0; | 351 | return 0; |
351 | 352 | ||
352 | release_region: | 353 | release_region: |
@@ -355,7 +356,7 @@ done: | |||
355 | return err; | 356 | return err; |
356 | } | 357 | } |
357 | 358 | ||
358 | static int cs5535_gpio_remove(struct platform_device *pdev) | 359 | static int __devexit cs5535_gpio_remove(struct platform_device *pdev) |
359 | { | 360 | { |
360 | struct resource *r; | 361 | struct resource *r; |
361 | int err; | 362 | int err; |
@@ -378,10 +379,21 @@ static struct platform_driver cs5535_gpio_driver = { | |||
378 | .owner = THIS_MODULE, | 379 | .owner = THIS_MODULE, |
379 | }, | 380 | }, |
380 | .probe = cs5535_gpio_probe, | 381 | .probe = cs5535_gpio_probe, |
381 | .remove = cs5535_gpio_remove, | 382 | .remove = __devexit_p(cs5535_gpio_remove), |
382 | }; | 383 | }; |
383 | 384 | ||
384 | module_platform_driver(cs5535_gpio_driver); | 385 | static int __init cs5535_gpio_init(void) |
386 | { | ||
387 | return platform_driver_register(&cs5535_gpio_driver); | ||
388 | } | ||
389 | |||
390 | static void __exit cs5535_gpio_exit(void) | ||
391 | { | ||
392 | platform_driver_unregister(&cs5535_gpio_driver); | ||
393 | } | ||
394 | |||
395 | module_init(cs5535_gpio_init); | ||
396 | module_exit(cs5535_gpio_exit); | ||
385 | 397 | ||
386 | MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); | 398 | MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>"); |
387 | MODULE_DESCRIPTION("AMD CS5535/CS5536 GPIO driver"); | 399 | MODULE_DESCRIPTION("AMD CS5535/CS5536 GPIO driver"); |
diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c index 29b11e9b6a7..038f5eb8b13 100644 --- a/drivers/gpio/gpio-da9052.c +++ b/drivers/gpio/gpio-da9052.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/mfd/da9052/da9052.h> | 22 | #include <linux/mfd/da9052/da9052.h> |
23 | #include <linux/mfd/da9052/reg.h> | 23 | #include <linux/mfd/da9052/reg.h> |
24 | #include <linux/mfd/da9052/pdata.h> | 24 | #include <linux/mfd/da9052/pdata.h> |
25 | #include <linux/mfd/da9052/gpio.h> | ||
25 | 26 | ||
26 | #define DA9052_INPUT 1 | 27 | #define DA9052_INPUT 1 |
27 | #define DA9052_OUTPUT_OPENDRAIN 2 | 28 | #define DA9052_OUTPUT_OPENDRAIN 2 |
@@ -42,9 +43,6 @@ | |||
42 | #define DA9052_GPIO_MASK_UPPER_NIBBLE 0xF0 | 43 | #define DA9052_GPIO_MASK_UPPER_NIBBLE 0xF0 |
43 | #define DA9052_GPIO_MASK_LOWER_NIBBLE 0x0F | 44 | #define DA9052_GPIO_MASK_LOWER_NIBBLE 0x0F |
44 | #define DA9052_GPIO_NIBBLE_SHIFT 4 | 45 | #define DA9052_GPIO_NIBBLE_SHIFT 4 |
45 | #define DA9052_IRQ_GPI0 16 | ||
46 | #define DA9052_GPIO_ODD_SHIFT 7 | ||
47 | #define DA9052_GPIO_EVEN_SHIFT 3 | ||
48 | 46 | ||
49 | struct da9052_gpio { | 47 | struct da9052_gpio { |
50 | struct da9052 *da9052; | 48 | struct da9052 *da9052; |
@@ -106,26 +104,33 @@ static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset) | |||
106 | static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value) | 104 | static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value) |
107 | { | 105 | { |
108 | struct da9052_gpio *gpio = to_da9052_gpio(gc); | 106 | struct da9052_gpio *gpio = to_da9052_gpio(gc); |
107 | unsigned char register_value = 0; | ||
109 | int ret; | 108 | int ret; |
110 | 109 | ||
111 | if (da9052_gpio_port_odd(offset)) { | 110 | if (da9052_gpio_port_odd(offset)) { |
111 | if (value) { | ||
112 | register_value = DA9052_GPIO_ODD_PORT_MODE; | ||
112 | ret = da9052_reg_update(gpio->da9052, (offset >> 1) + | 113 | ret = da9052_reg_update(gpio->da9052, (offset >> 1) + |
113 | DA9052_GPIO_0_1_REG, | 114 | DA9052_GPIO_0_1_REG, |
114 | DA9052_GPIO_ODD_PORT_MODE, | 115 | DA9052_GPIO_ODD_PORT_MODE, |
115 | value << DA9052_GPIO_ODD_SHIFT); | 116 | register_value); |
116 | if (ret != 0) | 117 | if (ret != 0) |
117 | dev_err(gpio->da9052->dev, | 118 | dev_err(gpio->da9052->dev, |
118 | "Failed to updated gpio odd reg,%d", | 119 | "Failed to updated gpio odd reg,%d", |
119 | ret); | 120 | ret); |
121 | } | ||
120 | } else { | 122 | } else { |
123 | if (value) { | ||
124 | register_value = DA9052_GPIO_EVEN_PORT_MODE; | ||
121 | ret = da9052_reg_update(gpio->da9052, (offset >> 1) + | 125 | ret = da9052_reg_update(gpio->da9052, (offset >> 1) + |
122 | DA9052_GPIO_0_1_REG, | 126 | DA9052_GPIO_0_1_REG, |
123 | DA9052_GPIO_EVEN_PORT_MODE, | 127 | DA9052_GPIO_EVEN_PORT_MODE, |
124 | value << DA9052_GPIO_EVEN_SHIFT); | 128 | register_value); |
125 | if (ret != 0) | 129 | if (ret != 0) |
126 | dev_err(gpio->da9052->dev, | 130 | dev_err(gpio->da9052->dev, |
127 | "Failed to updated gpio even reg,%d", | 131 | "Failed to updated gpio even reg,%d", |
128 | ret); | 132 | ret); |
133 | } | ||
129 | } | 134 | } |
130 | } | 135 | } |
131 | 136 | ||
@@ -185,14 +190,10 @@ static int da9052_gpio_to_irq(struct gpio_chip *gc, u32 offset) | |||
185 | struct da9052_gpio *gpio = to_da9052_gpio(gc); | 190 | struct da9052_gpio *gpio = to_da9052_gpio(gc); |
186 | struct da9052 *da9052 = gpio->da9052; | 191 | struct da9052 *da9052 = gpio->da9052; |
187 | 192 | ||
188 | int irq; | 193 | return da9052->irq_base + DA9052_IRQ_GPI0 + offset; |
189 | |||
190 | irq = regmap_irq_get_virq(da9052->irq_data, DA9052_IRQ_GPI0 + offset); | ||
191 | |||
192 | return irq; | ||
193 | } | 194 | } |
194 | 195 | ||
195 | static struct gpio_chip reference_gp = { | 196 | static struct gpio_chip reference_gp __devinitdata = { |
196 | .label = "da9052-gpio", | 197 | .label = "da9052-gpio", |
197 | .owner = THIS_MODULE, | 198 | .owner = THIS_MODULE, |
198 | .get = da9052_gpio_get, | 199 | .get = da9052_gpio_get, |
@@ -200,18 +201,18 @@ static struct gpio_chip reference_gp = { | |||
200 | .direction_input = da9052_gpio_direction_input, | 201 | .direction_input = da9052_gpio_direction_input, |
201 | .direction_output = da9052_gpio_direction_output, | 202 | .direction_output = da9052_gpio_direction_output, |
202 | .to_irq = da9052_gpio_to_irq, | 203 | .to_irq = da9052_gpio_to_irq, |
203 | .can_sleep = 1, | 204 | .can_sleep = 1; |
204 | .ngpio = 16, | 205 | .ngpio = 16; |
205 | .base = -1, | 206 | .base = -1; |
206 | }; | 207 | }; |
207 | 208 | ||
208 | static int da9052_gpio_probe(struct platform_device *pdev) | 209 | static int __devinit da9052_gpio_probe(struct platform_device *pdev) |
209 | { | 210 | { |
210 | struct da9052_gpio *gpio; | 211 | struct da9052_gpio *gpio; |
211 | struct da9052_pdata *pdata; | 212 | struct da9052_pdata *pdata; |
212 | int ret; | 213 | int ret; |
213 | 214 | ||
214 | gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); | 215 | gpio = kzalloc(sizeof(*gpio), GFP_KERNEL); |
215 | if (gpio == NULL) | 216 | if (gpio == NULL) |
216 | return -ENOMEM; | 217 | return -ENOMEM; |
217 | 218 | ||
@@ -225,31 +226,50 @@ static int da9052_gpio_probe(struct platform_device *pdev) | |||
225 | ret = gpiochip_add(&gpio->gp); | 226 | ret = gpiochip_add(&gpio->gp); |
226 | if (ret < 0) { | 227 | if (ret < 0) { |
227 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | 228 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); |
228 | return ret; | 229 | goto err_mem; |
229 | } | 230 | } |
230 | 231 | ||
231 | platform_set_drvdata(pdev, gpio); | 232 | platform_set_drvdata(pdev, gpio); |
232 | 233 | ||
233 | return 0; | 234 | return 0; |
235 | |||
236 | err_mem: | ||
237 | kfree(gpio); | ||
238 | return ret; | ||
234 | } | 239 | } |
235 | 240 | ||
236 | static int da9052_gpio_remove(struct platform_device *pdev) | 241 | static int __devexit da9052_gpio_remove(struct platform_device *pdev) |
237 | { | 242 | { |
238 | struct da9052_gpio *gpio = platform_get_drvdata(pdev); | 243 | struct da9052_gpio *gpio = platform_get_drvdata(pdev); |
244 | int ret; | ||
245 | |||
246 | ret = gpiochip_remove(&gpio->gp); | ||
247 | if (ret == 0) | ||
248 | kfree(gpio); | ||
239 | 249 | ||
240 | return gpiochip_remove(&gpio->gp); | 250 | return ret; |
241 | } | 251 | } |
242 | 252 | ||
243 | static struct platform_driver da9052_gpio_driver = { | 253 | static struct platform_driver da9052_gpio_driver = { |
244 | .probe = da9052_gpio_probe, | 254 | .probe = da9052_gpio_probe, |
245 | .remove = da9052_gpio_remove, | 255 | .remove = __devexit_p(da9052_gpio_remove), |
246 | .driver = { | 256 | .driver = { |
247 | .name = "da9052-gpio", | 257 | .name = "da9052-gpio", |
248 | .owner = THIS_MODULE, | 258 | .owner = THIS_MODULE, |
249 | }, | 259 | }, |
250 | }; | 260 | }; |
251 | 261 | ||
252 | module_platform_driver(da9052_gpio_driver); | 262 | static int __init da9052_gpio_init(void) |
263 | { | ||
264 | return platform_driver_register(&da9052_gpio_driver); | ||
265 | } | ||
266 | module_init(da9052_gpio_init); | ||
267 | |||
268 | static void __exit da9052_gpio_exit(void) | ||
269 | { | ||
270 | return platform_driver_unregister(&da9052_gpio_driver); | ||
271 | } | ||
272 | module_exit(da9052_gpio_exit); | ||
253 | 273 | ||
254 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); | 274 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); |
255 | MODULE_DESCRIPTION("DA9052 GPIO Device Driver"); | 275 | MODULE_DESCRIPTION("DA9052 GPIO Device Driver"); |
diff --git a/drivers/gpio/gpio-da9055.c b/drivers/gpio/gpio-da9055.c deleted file mode 100644 index fd6dfe382f1..00000000000 --- a/drivers/gpio/gpio-da9055.c +++ /dev/null | |||
@@ -1,204 +0,0 @@ | |||
1 | /* | ||
2 | * GPIO Driver for Dialog DA9055 PMICs. | ||
3 | * | ||
4 | * Copyright(c) 2012 Dialog Semiconductor Ltd. | ||
5 | * | ||
6 | * Author: David Dajun Chen <dchen@diasemi.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/gpio.h> | ||
17 | |||
18 | #include <linux/mfd/da9055/core.h> | ||
19 | #include <linux/mfd/da9055/reg.h> | ||
20 | #include <linux/mfd/da9055/pdata.h> | ||
21 | |||
22 | #define DA9055_VDD_IO 0x0 | ||
23 | #define DA9055_PUSH_PULL 0x3 | ||
24 | #define DA9055_ACT_LOW 0x0 | ||
25 | #define DA9055_GPI 0x1 | ||
26 | #define DA9055_PORT_MASK 0x3 | ||
27 | #define DA9055_PORT_SHIFT(offset) (4 * (offset % 2)) | ||
28 | |||
29 | #define DA9055_INPUT DA9055_GPI | ||
30 | #define DA9055_OUTPUT DA9055_PUSH_PULL | ||
31 | #define DA9055_IRQ_GPI0 3 | ||
32 | |||
33 | struct da9055_gpio { | ||
34 | struct da9055 *da9055; | ||
35 | struct gpio_chip gp; | ||
36 | }; | ||
37 | |||
38 | static inline struct da9055_gpio *to_da9055_gpio(struct gpio_chip *chip) | ||
39 | { | ||
40 | return container_of(chip, struct da9055_gpio, gp); | ||
41 | } | ||
42 | |||
43 | static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset) | ||
44 | { | ||
45 | struct da9055_gpio *gpio = to_da9055_gpio(gc); | ||
46 | int gpio_direction = 0; | ||
47 | int ret; | ||
48 | |||
49 | /* Get GPIO direction */ | ||
50 | ret = da9055_reg_read(gpio->da9055, (offset >> 1) + DA9055_REG_GPIO0_1); | ||
51 | if (ret < 0) | ||
52 | return ret; | ||
53 | |||
54 | gpio_direction = ret & (DA9055_PORT_MASK) << DA9055_PORT_SHIFT(offset); | ||
55 | gpio_direction >>= DA9055_PORT_SHIFT(offset); | ||
56 | switch (gpio_direction) { | ||
57 | case DA9055_INPUT: | ||
58 | ret = da9055_reg_read(gpio->da9055, DA9055_REG_STATUS_B); | ||
59 | if (ret < 0) | ||
60 | return ret; | ||
61 | break; | ||
62 | case DA9055_OUTPUT: | ||
63 | ret = da9055_reg_read(gpio->da9055, DA9055_REG_GPIO_MODE0_2); | ||
64 | if (ret < 0) | ||
65 | return ret; | ||
66 | } | ||
67 | |||
68 | return ret & (1 << offset); | ||
69 | |||
70 | } | ||
71 | |||
72 | static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value) | ||
73 | { | ||
74 | struct da9055_gpio *gpio = to_da9055_gpio(gc); | ||
75 | |||
76 | da9055_reg_update(gpio->da9055, | ||
77 | DA9055_REG_GPIO_MODE0_2, | ||
78 | 1 << offset, | ||
79 | value << offset); | ||
80 | } | ||
81 | |||
82 | static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset) | ||
83 | { | ||
84 | struct da9055_gpio *gpio = to_da9055_gpio(gc); | ||
85 | unsigned char reg_byte; | ||
86 | |||
87 | reg_byte = (DA9055_ACT_LOW | DA9055_GPI) | ||
88 | << DA9055_PORT_SHIFT(offset); | ||
89 | |||
90 | return da9055_reg_update(gpio->da9055, (offset >> 1) + | ||
91 | DA9055_REG_GPIO0_1, | ||
92 | DA9055_PORT_MASK << | ||
93 | DA9055_PORT_SHIFT(offset), | ||
94 | reg_byte); | ||
95 | } | ||
96 | |||
97 | static int da9055_gpio_direction_output(struct gpio_chip *gc, | ||
98 | unsigned offset, int value) | ||
99 | { | ||
100 | struct da9055_gpio *gpio = to_da9055_gpio(gc); | ||
101 | unsigned char reg_byte; | ||
102 | int ret; | ||
103 | |||
104 | reg_byte = (DA9055_VDD_IO | DA9055_PUSH_PULL) | ||
105 | << DA9055_PORT_SHIFT(offset); | ||
106 | |||
107 | ret = da9055_reg_update(gpio->da9055, (offset >> 1) + | ||
108 | DA9055_REG_GPIO0_1, | ||
109 | DA9055_PORT_MASK << | ||
110 | DA9055_PORT_SHIFT(offset), | ||
111 | reg_byte); | ||
112 | if (ret < 0) | ||
113 | return ret; | ||
114 | |||
115 | da9055_gpio_set(gc, offset, value); | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static int da9055_gpio_to_irq(struct gpio_chip *gc, u32 offset) | ||
121 | { | ||
122 | struct da9055_gpio *gpio = to_da9055_gpio(gc); | ||
123 | struct da9055 *da9055 = gpio->da9055; | ||
124 | |||
125 | return regmap_irq_get_virq(da9055->irq_data, | ||
126 | DA9055_IRQ_GPI0 + offset); | ||
127 | } | ||
128 | |||
129 | static struct gpio_chip reference_gp = { | ||
130 | .label = "da9055-gpio", | ||
131 | .owner = THIS_MODULE, | ||
132 | .get = da9055_gpio_get, | ||
133 | .set = da9055_gpio_set, | ||
134 | .direction_input = da9055_gpio_direction_input, | ||
135 | .direction_output = da9055_gpio_direction_output, | ||
136 | .to_irq = da9055_gpio_to_irq, | ||
137 | .can_sleep = 1, | ||
138 | .ngpio = 3, | ||
139 | .base = -1, | ||
140 | }; | ||
141 | |||
142 | static int da9055_gpio_probe(struct platform_device *pdev) | ||
143 | { | ||
144 | struct da9055_gpio *gpio; | ||
145 | struct da9055_pdata *pdata; | ||
146 | int ret; | ||
147 | |||
148 | gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); | ||
149 | if (gpio == NULL) | ||
150 | return -ENOMEM; | ||
151 | |||
152 | gpio->da9055 = dev_get_drvdata(pdev->dev.parent); | ||
153 | pdata = gpio->da9055->dev->platform_data; | ||
154 | |||
155 | gpio->gp = reference_gp; | ||
156 | if (pdata && pdata->gpio_base) | ||
157 | gpio->gp.base = pdata->gpio_base; | ||
158 | |||
159 | ret = gpiochip_add(&gpio->gp); | ||
160 | if (ret < 0) { | ||
161 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | ||
162 | goto err_mem; | ||
163 | } | ||
164 | |||
165 | platform_set_drvdata(pdev, gpio); | ||
166 | |||
167 | return 0; | ||
168 | |||
169 | err_mem: | ||
170 | return ret; | ||
171 | } | ||
172 | |||
173 | static int da9055_gpio_remove(struct platform_device *pdev) | ||
174 | { | ||
175 | struct da9055_gpio *gpio = platform_get_drvdata(pdev); | ||
176 | |||
177 | return gpiochip_remove(&gpio->gp); | ||
178 | } | ||
179 | |||
180 | static struct platform_driver da9055_gpio_driver = { | ||
181 | .probe = da9055_gpio_probe, | ||
182 | .remove = da9055_gpio_remove, | ||
183 | .driver = { | ||
184 | .name = "da9055-gpio", | ||
185 | .owner = THIS_MODULE, | ||
186 | }, | ||
187 | }; | ||
188 | |||
189 | static int __init da9055_gpio_init(void) | ||
190 | { | ||
191 | return platform_driver_register(&da9055_gpio_driver); | ||
192 | } | ||
193 | subsys_initcall(da9055_gpio_init); | ||
194 | |||
195 | static void __exit da9055_gpio_exit(void) | ||
196 | { | ||
197 | platform_driver_unregister(&da9055_gpio_driver); | ||
198 | } | ||
199 | module_exit(da9055_gpio_exit); | ||
200 | |||
201 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); | ||
202 | MODULE_DESCRIPTION("DA9055 GPIO Device Driver"); | ||
203 | MODULE_LICENSE("GPL"); | ||
204 | MODULE_ALIAS("platform:da9055-gpio"); | ||
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c deleted file mode 100644 index 17df6db5dca..00000000000 --- a/drivers/gpio/gpio-davinci.c +++ /dev/null | |||
@@ -1,461 +0,0 @@ | |||
1 | /* | ||
2 | * TI DaVinci GPIO Support | ||
3 | * | ||
4 | * Copyright (c) 2006-2007 David Brownell | ||
5 | * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | */ | ||
12 | #include <linux/gpio.h> | ||
13 | #include <linux/errno.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/clk.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/io.h> | ||
18 | |||
19 | #include <asm/mach/irq.h> | ||
20 | |||
21 | struct davinci_gpio_regs { | ||
22 | u32 dir; | ||
23 | u32 out_data; | ||
24 | u32 set_data; | ||
25 | u32 clr_data; | ||
26 | u32 in_data; | ||
27 | u32 set_rising; | ||
28 | u32 clr_rising; | ||
29 | u32 set_falling; | ||
30 | u32 clr_falling; | ||
31 | u32 intstat; | ||
32 | }; | ||
33 | |||
34 | #define chip2controller(chip) \ | ||
35 | container_of(chip, struct davinci_gpio_controller, chip) | ||
36 | |||
37 | static struct davinci_gpio_controller chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)]; | ||
38 | static void __iomem *gpio_base; | ||
39 | |||
40 | static struct davinci_gpio_regs __iomem __init *gpio2regs(unsigned gpio) | ||
41 | { | ||
42 | void __iomem *ptr; | ||
43 | |||
44 | if (gpio < 32 * 1) | ||
45 | ptr = gpio_base + 0x10; | ||
46 | else if (gpio < 32 * 2) | ||
47 | ptr = gpio_base + 0x38; | ||
48 | else if (gpio < 32 * 3) | ||
49 | ptr = gpio_base + 0x60; | ||
50 | else if (gpio < 32 * 4) | ||
51 | ptr = gpio_base + 0x88; | ||
52 | else if (gpio < 32 * 5) | ||
53 | ptr = gpio_base + 0xb0; | ||
54 | else | ||
55 | ptr = NULL; | ||
56 | return ptr; | ||
57 | } | ||
58 | |||
59 | static inline struct davinci_gpio_regs __iomem *irq2regs(int irq) | ||
60 | { | ||
61 | struct davinci_gpio_regs __iomem *g; | ||
62 | |||
63 | g = (__force struct davinci_gpio_regs __iomem *)irq_get_chip_data(irq); | ||
64 | |||
65 | return g; | ||
66 | } | ||
67 | |||
68 | static int __init davinci_gpio_irq_setup(void); | ||
69 | |||
70 | /*--------------------------------------------------------------------------*/ | ||
71 | |||
72 | /* board setup code *MUST* setup pinmux and enable the GPIO clock. */ | ||
73 | static inline int __davinci_direction(struct gpio_chip *chip, | ||
74 | unsigned offset, bool out, int value) | ||
75 | { | ||
76 | struct davinci_gpio_controller *d = chip2controller(chip); | ||
77 | struct davinci_gpio_regs __iomem *g = d->regs; | ||
78 | unsigned long flags; | ||
79 | u32 temp; | ||
80 | u32 mask = 1 << offset; | ||
81 | |||
82 | spin_lock_irqsave(&d->lock, flags); | ||
83 | temp = __raw_readl(&g->dir); | ||
84 | if (out) { | ||
85 | temp &= ~mask; | ||
86 | __raw_writel(mask, value ? &g->set_data : &g->clr_data); | ||
87 | } else { | ||
88 | temp |= mask; | ||
89 | } | ||
90 | __raw_writel(temp, &g->dir); | ||
91 | spin_unlock_irqrestore(&d->lock, flags); | ||
92 | |||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | static int davinci_direction_in(struct gpio_chip *chip, unsigned offset) | ||
97 | { | ||
98 | return __davinci_direction(chip, offset, false, 0); | ||
99 | } | ||
100 | |||
101 | static int | ||
102 | davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value) | ||
103 | { | ||
104 | return __davinci_direction(chip, offset, true, value); | ||
105 | } | ||
106 | |||
107 | /* | ||
108 | * Read the pin's value (works even if it's set up as output); | ||
109 | * returns zero/nonzero. | ||
110 | * | ||
111 | * Note that changes are synched to the GPIO clock, so reading values back | ||
112 | * right after you've set them may give old values. | ||
113 | */ | ||
114 | static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
115 | { | ||
116 | struct davinci_gpio_controller *d = chip2controller(chip); | ||
117 | struct davinci_gpio_regs __iomem *g = d->regs; | ||
118 | |||
119 | return (1 << offset) & __raw_readl(&g->in_data); | ||
120 | } | ||
121 | |||
122 | /* | ||
123 | * Assuming the pin is muxed as a gpio output, set its output value. | ||
124 | */ | ||
125 | static void | ||
126 | davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
127 | { | ||
128 | struct davinci_gpio_controller *d = chip2controller(chip); | ||
129 | struct davinci_gpio_regs __iomem *g = d->regs; | ||
130 | |||
131 | __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data); | ||
132 | } | ||
133 | |||
134 | static int __init davinci_gpio_setup(void) | ||
135 | { | ||
136 | int i, base; | ||
137 | unsigned ngpio; | ||
138 | struct davinci_soc_info *soc_info = &davinci_soc_info; | ||
139 | struct davinci_gpio_regs *regs; | ||
140 | |||
141 | if (soc_info->gpio_type != GPIO_TYPE_DAVINCI) | ||
142 | return 0; | ||
143 | |||
144 | /* | ||
145 | * The gpio banks conceptually expose a segmented bitmap, | ||
146 | * and "ngpio" is one more than the largest zero-based | ||
147 | * bit index that's valid. | ||
148 | */ | ||
149 | ngpio = soc_info->gpio_num; | ||
150 | if (ngpio == 0) { | ||
151 | pr_err("GPIO setup: how many GPIOs?\n"); | ||
152 | return -EINVAL; | ||
153 | } | ||
154 | |||
155 | if (WARN_ON(DAVINCI_N_GPIO < ngpio)) | ||
156 | ngpio = DAVINCI_N_GPIO; | ||
157 | |||
158 | gpio_base = ioremap(soc_info->gpio_base, SZ_4K); | ||
159 | if (WARN_ON(!gpio_base)) | ||
160 | return -ENOMEM; | ||
161 | |||
162 | for (i = 0, base = 0; base < ngpio; i++, base += 32) { | ||
163 | chips[i].chip.label = "DaVinci"; | ||
164 | |||
165 | chips[i].chip.direction_input = davinci_direction_in; | ||
166 | chips[i].chip.get = davinci_gpio_get; | ||
167 | chips[i].chip.direction_output = davinci_direction_out; | ||
168 | chips[i].chip.set = davinci_gpio_set; | ||
169 | |||
170 | chips[i].chip.base = base; | ||
171 | chips[i].chip.ngpio = ngpio - base; | ||
172 | if (chips[i].chip.ngpio > 32) | ||
173 | chips[i].chip.ngpio = 32; | ||
174 | |||
175 | spin_lock_init(&chips[i].lock); | ||
176 | |||
177 | regs = gpio2regs(base); | ||
178 | chips[i].regs = regs; | ||
179 | chips[i].set_data = ®s->set_data; | ||
180 | chips[i].clr_data = ®s->clr_data; | ||
181 | chips[i].in_data = ®s->in_data; | ||
182 | |||
183 | gpiochip_add(&chips[i].chip); | ||
184 | } | ||
185 | |||
186 | soc_info->gpio_ctlrs = chips; | ||
187 | soc_info->gpio_ctlrs_num = DIV_ROUND_UP(ngpio, 32); | ||
188 | |||
189 | davinci_gpio_irq_setup(); | ||
190 | return 0; | ||
191 | } | ||
192 | pure_initcall(davinci_gpio_setup); | ||
193 | |||
194 | /*--------------------------------------------------------------------------*/ | ||
195 | /* | ||
196 | * We expect irqs will normally be set up as input pins, but they can also be | ||
197 | * used as output pins ... which is convenient for testing. | ||
198 | * | ||
199 | * NOTE: The first few GPIOs also have direct INTC hookups in addition | ||
200 | * to their GPIOBNK0 irq, with a bit less overhead. | ||
201 | * | ||
202 | * All those INTC hookups (direct, plus several IRQ banks) can also | ||
203 | * serve as EDMA event triggers. | ||
204 | */ | ||
205 | |||
206 | static void gpio_irq_disable(struct irq_data *d) | ||
207 | { | ||
208 | struct davinci_gpio_regs __iomem *g = irq2regs(d->irq); | ||
209 | u32 mask = (u32) irq_data_get_irq_handler_data(d); | ||
210 | |||
211 | __raw_writel(mask, &g->clr_falling); | ||
212 | __raw_writel(mask, &g->clr_rising); | ||
213 | } | ||
214 | |||
215 | static void gpio_irq_enable(struct irq_data *d) | ||
216 | { | ||
217 | struct davinci_gpio_regs __iomem *g = irq2regs(d->irq); | ||
218 | u32 mask = (u32) irq_data_get_irq_handler_data(d); | ||
219 | unsigned status = irqd_get_trigger_type(d); | ||
220 | |||
221 | status &= IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING; | ||
222 | if (!status) | ||
223 | status = IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING; | ||
224 | |||
225 | if (status & IRQ_TYPE_EDGE_FALLING) | ||
226 | __raw_writel(mask, &g->set_falling); | ||
227 | if (status & IRQ_TYPE_EDGE_RISING) | ||
228 | __raw_writel(mask, &g->set_rising); | ||
229 | } | ||
230 | |||
231 | static int gpio_irq_type(struct irq_data *d, unsigned trigger) | ||
232 | { | ||
233 | if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) | ||
234 | return -EINVAL; | ||
235 | |||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static struct irq_chip gpio_irqchip = { | ||
240 | .name = "GPIO", | ||
241 | .irq_enable = gpio_irq_enable, | ||
242 | .irq_disable = gpio_irq_disable, | ||
243 | .irq_set_type = gpio_irq_type, | ||
244 | .flags = IRQCHIP_SET_TYPE_MASKED, | ||
245 | }; | ||
246 | |||
247 | static void | ||
248 | gpio_irq_handler(unsigned irq, struct irq_desc *desc) | ||
249 | { | ||
250 | struct davinci_gpio_regs __iomem *g; | ||
251 | u32 mask = 0xffff; | ||
252 | struct davinci_gpio_controller *d; | ||
253 | |||
254 | d = (struct davinci_gpio_controller *)irq_desc_get_handler_data(desc); | ||
255 | g = (struct davinci_gpio_regs __iomem *)d->regs; | ||
256 | |||
257 | /* we only care about one bank */ | ||
258 | if (irq & 1) | ||
259 | mask <<= 16; | ||
260 | |||
261 | /* temporarily mask (level sensitive) parent IRQ */ | ||
262 | desc->irq_data.chip->irq_mask(&desc->irq_data); | ||
263 | desc->irq_data.chip->irq_ack(&desc->irq_data); | ||
264 | while (1) { | ||
265 | u32 status; | ||
266 | int n; | ||
267 | int res; | ||
268 | |||
269 | /* ack any irqs */ | ||
270 | status = __raw_readl(&g->intstat) & mask; | ||
271 | if (!status) | ||
272 | break; | ||
273 | __raw_writel(status, &g->intstat); | ||
274 | |||
275 | /* now demux them to the right lowlevel handler */ | ||
276 | n = d->irq_base; | ||
277 | if (irq & 1) { | ||
278 | n += 16; | ||
279 | status >>= 16; | ||
280 | } | ||
281 | |||
282 | while (status) { | ||
283 | res = ffs(status); | ||
284 | n += res; | ||
285 | generic_handle_irq(n - 1); | ||
286 | status >>= res; | ||
287 | } | ||
288 | } | ||
289 | desc->irq_data.chip->irq_unmask(&desc->irq_data); | ||
290 | /* now it may re-trigger */ | ||
291 | } | ||
292 | |||
293 | static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) | ||
294 | { | ||
295 | struct davinci_gpio_controller *d = chip2controller(chip); | ||
296 | |||
297 | if (d->irq_base >= 0) | ||
298 | return d->irq_base + offset; | ||
299 | else | ||
300 | return -ENODEV; | ||
301 | } | ||
302 | |||
303 | static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset) | ||
304 | { | ||
305 | struct davinci_soc_info *soc_info = &davinci_soc_info; | ||
306 | |||
307 | /* NOTE: we assume for now that only irqs in the first gpio_chip | ||
308 | * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). | ||
309 | */ | ||
310 | if (offset < soc_info->gpio_unbanked) | ||
311 | return soc_info->gpio_irq + offset; | ||
312 | else | ||
313 | return -ENODEV; | ||
314 | } | ||
315 | |||
316 | static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger) | ||
317 | { | ||
318 | struct davinci_gpio_controller *d; | ||
319 | struct davinci_gpio_regs __iomem *g; | ||
320 | struct davinci_soc_info *soc_info = &davinci_soc_info; | ||
321 | u32 mask; | ||
322 | |||
323 | d = (struct davinci_gpio_controller *)data->handler_data; | ||
324 | g = (struct davinci_gpio_regs __iomem *)d->regs; | ||
325 | mask = __gpio_mask(data->irq - soc_info->gpio_irq); | ||
326 | |||
327 | if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) | ||
328 | return -EINVAL; | ||
329 | |||
330 | __raw_writel(mask, (trigger & IRQ_TYPE_EDGE_FALLING) | ||
331 | ? &g->set_falling : &g->clr_falling); | ||
332 | __raw_writel(mask, (trigger & IRQ_TYPE_EDGE_RISING) | ||
333 | ? &g->set_rising : &g->clr_rising); | ||
334 | |||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | /* | ||
339 | * NOTE: for suspend/resume, probably best to make a platform_device with | ||
340 | * suspend_late/resume_resume calls hooking into results of the set_wake() | ||
341 | * calls ... so if no gpios are wakeup events the clock can be disabled, | ||
342 | * with outputs left at previously set levels, and so that VDD3P3V.IOPWDN0 | ||
343 | * (dm6446) can be set appropriately for GPIOV33 pins. | ||
344 | */ | ||
345 | |||
346 | static int __init davinci_gpio_irq_setup(void) | ||
347 | { | ||
348 | unsigned gpio, irq, bank; | ||
349 | struct clk *clk; | ||
350 | u32 binten = 0; | ||
351 | unsigned ngpio, bank_irq; | ||
352 | struct davinci_soc_info *soc_info = &davinci_soc_info; | ||
353 | struct davinci_gpio_regs __iomem *g; | ||
354 | |||
355 | ngpio = soc_info->gpio_num; | ||
356 | |||
357 | bank_irq = soc_info->gpio_irq; | ||
358 | if (bank_irq == 0) { | ||
359 | printk(KERN_ERR "Don't know first GPIO bank IRQ.\n"); | ||
360 | return -EINVAL; | ||
361 | } | ||
362 | |||
363 | clk = clk_get(NULL, "gpio"); | ||
364 | if (IS_ERR(clk)) { | ||
365 | printk(KERN_ERR "Error %ld getting gpio clock?\n", | ||
366 | PTR_ERR(clk)); | ||
367 | return PTR_ERR(clk); | ||
368 | } | ||
369 | clk_prepare_enable(clk); | ||
370 | |||
371 | /* Arrange gpio_to_irq() support, handling either direct IRQs or | ||
372 | * banked IRQs. Having GPIOs in the first GPIO bank use direct | ||
373 | * IRQs, while the others use banked IRQs, would need some setup | ||
374 | * tweaks to recognize hardware which can do that. | ||
375 | */ | ||
376 | for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) { | ||
377 | chips[bank].chip.to_irq = gpio_to_irq_banked; | ||
378 | chips[bank].irq_base = soc_info->gpio_unbanked | ||
379 | ? -EINVAL | ||
380 | : (soc_info->intc_irq_num + gpio); | ||
381 | } | ||
382 | |||
383 | /* | ||
384 | * AINTC can handle direct/unbanked IRQs for GPIOs, with the GPIO | ||
385 | * controller only handling trigger modes. We currently assume no | ||
386 | * IRQ mux conflicts; gpio_irq_type_unbanked() is only for GPIOs. | ||
387 | */ | ||
388 | if (soc_info->gpio_unbanked) { | ||
389 | static struct irq_chip_type gpio_unbanked; | ||
390 | |||
391 | /* pass "bank 0" GPIO IRQs to AINTC */ | ||
392 | chips[0].chip.to_irq = gpio_to_irq_unbanked; | ||
393 | binten = BIT(0); | ||
394 | |||
395 | /* AINTC handles mask/unmask; GPIO handles triggering */ | ||
396 | irq = bank_irq; | ||
397 | gpio_unbanked = *container_of(irq_get_chip(irq), | ||
398 | struct irq_chip_type, chip); | ||
399 | gpio_unbanked.chip.name = "GPIO-AINTC"; | ||
400 | gpio_unbanked.chip.irq_set_type = gpio_irq_type_unbanked; | ||
401 | |||
402 | /* default trigger: both edges */ | ||
403 | g = gpio2regs(0); | ||
404 | __raw_writel(~0, &g->set_falling); | ||
405 | __raw_writel(~0, &g->set_rising); | ||
406 | |||
407 | /* set the direct IRQs up to use that irqchip */ | ||
408 | for (gpio = 0; gpio < soc_info->gpio_unbanked; gpio++, irq++) { | ||
409 | irq_set_chip(irq, &gpio_unbanked.chip); | ||
410 | irq_set_handler_data(irq, &chips[gpio / 32]); | ||
411 | irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); | ||
412 | } | ||
413 | |||
414 | goto done; | ||
415 | } | ||
416 | |||
417 | /* | ||
418 | * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we | ||
419 | * then chain through our own handler. | ||
420 | */ | ||
421 | for (gpio = 0, irq = gpio_to_irq(0), bank = 0; | ||
422 | gpio < ngpio; | ||
423 | bank++, bank_irq++) { | ||
424 | unsigned i; | ||
425 | |||
426 | /* disabled by default, enabled only as needed */ | ||
427 | g = gpio2regs(gpio); | ||
428 | __raw_writel(~0, &g->clr_falling); | ||
429 | __raw_writel(~0, &g->clr_rising); | ||
430 | |||
431 | /* set up all irqs in this bank */ | ||
432 | irq_set_chained_handler(bank_irq, gpio_irq_handler); | ||
433 | |||
434 | /* | ||
435 | * Each chip handles 32 gpios, and each irq bank consists of 16 | ||
436 | * gpio irqs. Pass the irq bank's corresponding controller to | ||
437 | * the chained irq handler. | ||
438 | */ | ||
439 | irq_set_handler_data(bank_irq, &chips[gpio / 32]); | ||
440 | |||
441 | for (i = 0; i < 16 && gpio < ngpio; i++, irq++, gpio++) { | ||
442 | irq_set_chip(irq, &gpio_irqchip); | ||
443 | irq_set_chip_data(irq, (__force void *)g); | ||
444 | irq_set_handler_data(irq, (void *)__gpio_mask(gpio)); | ||
445 | irq_set_handler(irq, handle_simple_irq); | ||
446 | set_irq_flags(irq, IRQF_VALID); | ||
447 | } | ||
448 | |||
449 | binten |= BIT(bank); | ||
450 | } | ||
451 | |||
452 | done: | ||
453 | /* BINTEN -- per-bank interrupt enable. genirq would also let these | ||
454 | * bits be set/cleared dynamically. | ||
455 | */ | ||
456 | __raw_writel(binten, gpio_base + 0x08); | ||
457 | |||
458 | printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0)); | ||
459 | |||
460 | return 0; | ||
461 | } | ||
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c deleted file mode 100644 index bdc8302e711..00000000000 --- a/drivers/gpio/gpio-em.c +++ /dev/null | |||
@@ -1,380 +0,0 @@ | |||
1 | /* | ||
2 | * Emma Mobile GPIO Support - GIO | ||
3 | * | ||
4 | * Copyright (C) 2012 Magnus Damm | ||
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 | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/init.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/irq.h> | ||
27 | #include <linux/irqdomain.h> | ||
28 | #include <linux/bitops.h> | ||
29 | #include <linux/err.h> | ||
30 | #include <linux/gpio.h> | ||
31 | #include <linux/slab.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/platform_data/gpio-em.h> | ||
34 | |||
35 | struct em_gio_priv { | ||
36 | void __iomem *base0; | ||
37 | void __iomem *base1; | ||
38 | spinlock_t sense_lock; | ||
39 | struct platform_device *pdev; | ||
40 | struct gpio_chip gpio_chip; | ||
41 | struct irq_chip irq_chip; | ||
42 | struct irq_domain *irq_domain; | ||
43 | }; | ||
44 | |||
45 | #define GIO_E1 0x00 | ||
46 | #define GIO_E0 0x04 | ||
47 | #define GIO_EM 0x04 | ||
48 | #define GIO_OL 0x08 | ||
49 | #define GIO_OH 0x0c | ||
50 | #define GIO_I 0x10 | ||
51 | #define GIO_IIA 0x14 | ||
52 | #define GIO_IEN 0x18 | ||
53 | #define GIO_IDS 0x1c | ||
54 | #define GIO_IIM 0x1c | ||
55 | #define GIO_RAW 0x20 | ||
56 | #define GIO_MST 0x24 | ||
57 | #define GIO_IIR 0x28 | ||
58 | |||
59 | #define GIO_IDT0 0x40 | ||
60 | #define GIO_IDT1 0x44 | ||
61 | #define GIO_IDT2 0x48 | ||
62 | #define GIO_IDT3 0x4c | ||
63 | #define GIO_RAWBL 0x50 | ||
64 | #define GIO_RAWBH 0x54 | ||
65 | #define GIO_IRBL 0x58 | ||
66 | #define GIO_IRBH 0x5c | ||
67 | |||
68 | #define GIO_IDT(n) (GIO_IDT0 + ((n) * 4)) | ||
69 | |||
70 | static inline unsigned long em_gio_read(struct em_gio_priv *p, int offs) | ||
71 | { | ||
72 | if (offs < GIO_IDT0) | ||
73 | return ioread32(p->base0 + offs); | ||
74 | else | ||
75 | return ioread32(p->base1 + (offs - GIO_IDT0)); | ||
76 | } | ||
77 | |||
78 | static inline void em_gio_write(struct em_gio_priv *p, int offs, | ||
79 | unsigned long value) | ||
80 | { | ||
81 | if (offs < GIO_IDT0) | ||
82 | iowrite32(value, p->base0 + offs); | ||
83 | else | ||
84 | iowrite32(value, p->base1 + (offs - GIO_IDT0)); | ||
85 | } | ||
86 | |||
87 | static void em_gio_irq_disable(struct irq_data *d) | ||
88 | { | ||
89 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); | ||
90 | |||
91 | em_gio_write(p, GIO_IDS, BIT(irqd_to_hwirq(d))); | ||
92 | } | ||
93 | |||
94 | static void em_gio_irq_enable(struct irq_data *d) | ||
95 | { | ||
96 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); | ||
97 | |||
98 | em_gio_write(p, GIO_IEN, BIT(irqd_to_hwirq(d))); | ||
99 | } | ||
100 | |||
101 | #define GIO_ASYNC(x) (x + 8) | ||
102 | |||
103 | static unsigned char em_gio_sense_table[IRQ_TYPE_SENSE_MASK + 1] = { | ||
104 | [IRQ_TYPE_EDGE_RISING] = GIO_ASYNC(0x00), | ||
105 | [IRQ_TYPE_EDGE_FALLING] = GIO_ASYNC(0x01), | ||
106 | [IRQ_TYPE_LEVEL_HIGH] = GIO_ASYNC(0x02), | ||
107 | [IRQ_TYPE_LEVEL_LOW] = GIO_ASYNC(0x03), | ||
108 | [IRQ_TYPE_EDGE_BOTH] = GIO_ASYNC(0x04), | ||
109 | }; | ||
110 | |||
111 | static int em_gio_irq_set_type(struct irq_data *d, unsigned int type) | ||
112 | { | ||
113 | unsigned char value = em_gio_sense_table[type & IRQ_TYPE_SENSE_MASK]; | ||
114 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); | ||
115 | unsigned int reg, offset, shift; | ||
116 | unsigned long flags; | ||
117 | unsigned long tmp; | ||
118 | |||
119 | if (!value) | ||
120 | return -EINVAL; | ||
121 | |||
122 | offset = irqd_to_hwirq(d); | ||
123 | |||
124 | pr_debug("gio: sense irq = %d, mode = %d\n", offset, value); | ||
125 | |||
126 | /* 8 x 4 bit fields in 4 IDT registers */ | ||
127 | reg = GIO_IDT(offset >> 3); | ||
128 | shift = (offset & 0x07) << 4; | ||
129 | |||
130 | spin_lock_irqsave(&p->sense_lock, flags); | ||
131 | |||
132 | /* disable the interrupt in IIA */ | ||
133 | tmp = em_gio_read(p, GIO_IIA); | ||
134 | tmp &= ~BIT(offset); | ||
135 | em_gio_write(p, GIO_IIA, tmp); | ||
136 | |||
137 | /* change the sense setting in IDT */ | ||
138 | tmp = em_gio_read(p, reg); | ||
139 | tmp &= ~(0xf << shift); | ||
140 | tmp |= value << shift; | ||
141 | em_gio_write(p, reg, tmp); | ||
142 | |||
143 | /* clear pending interrupts */ | ||
144 | em_gio_write(p, GIO_IIR, BIT(offset)); | ||
145 | |||
146 | /* enable the interrupt in IIA */ | ||
147 | tmp = em_gio_read(p, GIO_IIA); | ||
148 | tmp |= BIT(offset); | ||
149 | em_gio_write(p, GIO_IIA, tmp); | ||
150 | |||
151 | spin_unlock_irqrestore(&p->sense_lock, flags); | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | static irqreturn_t em_gio_irq_handler(int irq, void *dev_id) | ||
157 | { | ||
158 | struct em_gio_priv *p = dev_id; | ||
159 | unsigned long pending; | ||
160 | unsigned int offset, irqs_handled = 0; | ||
161 | |||
162 | while ((pending = em_gio_read(p, GIO_MST))) { | ||
163 | offset = __ffs(pending); | ||
164 | em_gio_write(p, GIO_IIR, BIT(offset)); | ||
165 | generic_handle_irq(irq_find_mapping(p->irq_domain, offset)); | ||
166 | irqs_handled++; | ||
167 | } | ||
168 | |||
169 | return irqs_handled ? IRQ_HANDLED : IRQ_NONE; | ||
170 | } | ||
171 | |||
172 | static inline struct em_gio_priv *gpio_to_priv(struct gpio_chip *chip) | ||
173 | { | ||
174 | return container_of(chip, struct em_gio_priv, gpio_chip); | ||
175 | } | ||
176 | |||
177 | static int em_gio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
178 | { | ||
179 | em_gio_write(gpio_to_priv(chip), GIO_E0, BIT(offset)); | ||
180 | return 0; | ||
181 | } | ||
182 | |||
183 | static int em_gio_get(struct gpio_chip *chip, unsigned offset) | ||
184 | { | ||
185 | return (int)(em_gio_read(gpio_to_priv(chip), GIO_I) & BIT(offset)); | ||
186 | } | ||
187 | |||
188 | static void __em_gio_set(struct gpio_chip *chip, unsigned int reg, | ||
189 | unsigned shift, int value) | ||
190 | { | ||
191 | /* upper 16 bits contains mask and lower 16 actual value */ | ||
192 | em_gio_write(gpio_to_priv(chip), reg, | ||
193 | (1 << (shift + 16)) | (value << shift)); | ||
194 | } | ||
195 | |||
196 | static void em_gio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
197 | { | ||
198 | /* output is split into two registers */ | ||
199 | if (offset < 16) | ||
200 | __em_gio_set(chip, GIO_OL, offset, value); | ||
201 | else | ||
202 | __em_gio_set(chip, GIO_OH, offset - 16, value); | ||
203 | } | ||
204 | |||
205 | static int em_gio_direction_output(struct gpio_chip *chip, unsigned offset, | ||
206 | int value) | ||
207 | { | ||
208 | /* write GPIO value to output before selecting output mode of pin */ | ||
209 | em_gio_set(chip, offset, value); | ||
210 | em_gio_write(gpio_to_priv(chip), GIO_E1, BIT(offset)); | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | static int em_gio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
215 | { | ||
216 | return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); | ||
217 | } | ||
218 | |||
219 | static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq, | ||
220 | irq_hw_number_t hw) | ||
221 | { | ||
222 | struct em_gio_priv *p = h->host_data; | ||
223 | |||
224 | pr_debug("gio: map hw irq = %d, virq = %d\n", (int)hw, virq); | ||
225 | |||
226 | irq_set_chip_data(virq, h->host_data); | ||
227 | irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq); | ||
228 | set_irq_flags(virq, IRQF_VALID); /* kill me now */ | ||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static struct irq_domain_ops em_gio_irq_domain_ops = { | ||
233 | .map = em_gio_irq_domain_map, | ||
234 | }; | ||
235 | |||
236 | static int em_gio_probe(struct platform_device *pdev) | ||
237 | { | ||
238 | struct gpio_em_config *pdata = pdev->dev.platform_data; | ||
239 | struct em_gio_priv *p; | ||
240 | struct resource *io[2], *irq[2]; | ||
241 | struct gpio_chip *gpio_chip; | ||
242 | struct irq_chip *irq_chip; | ||
243 | const char *name = dev_name(&pdev->dev); | ||
244 | int ret; | ||
245 | |||
246 | p = kzalloc(sizeof(*p), GFP_KERNEL); | ||
247 | if (!p) { | ||
248 | dev_err(&pdev->dev, "failed to allocate driver data\n"); | ||
249 | ret = -ENOMEM; | ||
250 | goto err0; | ||
251 | } | ||
252 | |||
253 | p->pdev = pdev; | ||
254 | platform_set_drvdata(pdev, p); | ||
255 | spin_lock_init(&p->sense_lock); | ||
256 | |||
257 | io[0] = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
258 | io[1] = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
259 | irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
260 | irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1); | ||
261 | |||
262 | if (!io[0] || !io[1] || !irq[0] || !irq[1] || !pdata) { | ||
263 | dev_err(&pdev->dev, "missing IRQ, IOMEM or configuration\n"); | ||
264 | ret = -EINVAL; | ||
265 | goto err1; | ||
266 | } | ||
267 | |||
268 | p->base0 = ioremap_nocache(io[0]->start, resource_size(io[0])); | ||
269 | if (!p->base0) { | ||
270 | dev_err(&pdev->dev, "failed to remap low I/O memory\n"); | ||
271 | ret = -ENXIO; | ||
272 | goto err1; | ||
273 | } | ||
274 | |||
275 | p->base1 = ioremap_nocache(io[1]->start, resource_size(io[1])); | ||
276 | if (!p->base1) { | ||
277 | dev_err(&pdev->dev, "failed to remap high I/O memory\n"); | ||
278 | ret = -ENXIO; | ||
279 | goto err2; | ||
280 | } | ||
281 | |||
282 | gpio_chip = &p->gpio_chip; | ||
283 | gpio_chip->direction_input = em_gio_direction_input; | ||
284 | gpio_chip->get = em_gio_get; | ||
285 | gpio_chip->direction_output = em_gio_direction_output; | ||
286 | gpio_chip->set = em_gio_set; | ||
287 | gpio_chip->to_irq = em_gio_to_irq; | ||
288 | gpio_chip->label = name; | ||
289 | gpio_chip->owner = THIS_MODULE; | ||
290 | gpio_chip->base = pdata->gpio_base; | ||
291 | gpio_chip->ngpio = pdata->number_of_pins; | ||
292 | |||
293 | irq_chip = &p->irq_chip; | ||
294 | irq_chip->name = name; | ||
295 | irq_chip->irq_mask = em_gio_irq_disable; | ||
296 | irq_chip->irq_unmask = em_gio_irq_enable; | ||
297 | irq_chip->irq_enable = em_gio_irq_enable; | ||
298 | irq_chip->irq_disable = em_gio_irq_disable; | ||
299 | irq_chip->irq_set_type = em_gio_irq_set_type; | ||
300 | irq_chip->flags = IRQCHIP_SKIP_SET_WAKE; | ||
301 | |||
302 | p->irq_domain = irq_domain_add_linear(pdev->dev.of_node, | ||
303 | pdata->number_of_pins, | ||
304 | &em_gio_irq_domain_ops, p); | ||
305 | if (!p->irq_domain) { | ||
306 | ret = -ENXIO; | ||
307 | dev_err(&pdev->dev, "cannot initialize irq domain\n"); | ||
308 | goto err3; | ||
309 | } | ||
310 | |||
311 | if (request_irq(irq[0]->start, em_gio_irq_handler, 0, name, p)) { | ||
312 | dev_err(&pdev->dev, "failed to request low IRQ\n"); | ||
313 | ret = -ENOENT; | ||
314 | goto err4; | ||
315 | } | ||
316 | |||
317 | if (request_irq(irq[1]->start, em_gio_irq_handler, 0, name, p)) { | ||
318 | dev_err(&pdev->dev, "failed to request high IRQ\n"); | ||
319 | ret = -ENOENT; | ||
320 | goto err5; | ||
321 | } | ||
322 | |||
323 | ret = gpiochip_add(gpio_chip); | ||
324 | if (ret) { | ||
325 | dev_err(&pdev->dev, "failed to add GPIO controller\n"); | ||
326 | goto err6; | ||
327 | } | ||
328 | return 0; | ||
329 | |||
330 | err6: | ||
331 | free_irq(irq[1]->start, pdev); | ||
332 | err5: | ||
333 | free_irq(irq[0]->start, pdev); | ||
334 | err4: | ||
335 | irq_domain_remove(p->irq_domain); | ||
336 | err3: | ||
337 | iounmap(p->base1); | ||
338 | err2: | ||
339 | iounmap(p->base0); | ||
340 | err1: | ||
341 | kfree(p); | ||
342 | err0: | ||
343 | return ret; | ||
344 | } | ||
345 | |||
346 | static int em_gio_remove(struct platform_device *pdev) | ||
347 | { | ||
348 | struct em_gio_priv *p = platform_get_drvdata(pdev); | ||
349 | struct resource *irq[2]; | ||
350 | int ret; | ||
351 | |||
352 | ret = gpiochip_remove(&p->gpio_chip); | ||
353 | if (ret) | ||
354 | return ret; | ||
355 | |||
356 | irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
357 | irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1); | ||
358 | |||
359 | free_irq(irq[1]->start, pdev); | ||
360 | free_irq(irq[0]->start, pdev); | ||
361 | irq_domain_remove(p->irq_domain); | ||
362 | iounmap(p->base1); | ||
363 | iounmap(p->base0); | ||
364 | kfree(p); | ||
365 | return 0; | ||
366 | } | ||
367 | |||
368 | static struct platform_driver em_gio_device_driver = { | ||
369 | .probe = em_gio_probe, | ||
370 | .remove = em_gio_remove, | ||
371 | .driver = { | ||
372 | .name = "em_gio", | ||
373 | } | ||
374 | }; | ||
375 | |||
376 | module_platform_driver(em_gio_device_driver); | ||
377 | |||
378 | MODULE_AUTHOR("Magnus Damm"); | ||
379 | MODULE_DESCRIPTION("Renesas Emma Mobile GIO Driver"); | ||
380 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c index 56b98eebe1f..72fb9c66532 100644 --- a/drivers/gpio/gpio-ep93xx.c +++ b/drivers/gpio/gpio-ep93xx.c | |||
@@ -12,8 +12,9 @@ | |||
12 | * published by the Free Software Foundation. | 12 | * published by the Free Software Foundation. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
16 | |||
15 | #include <linux/init.h> | 17 | #include <linux/init.h> |
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
18 | #include <linux/io.h> | 19 | #include <linux/io.h> |
19 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
@@ -22,9 +23,6 @@ | |||
22 | #include <linux/basic_mmio_gpio.h> | 23 | #include <linux/basic_mmio_gpio.h> |
23 | 24 | ||
24 | #include <mach/hardware.h> | 25 | #include <mach/hardware.h> |
25 | #include <mach/gpio-ep93xx.h> | ||
26 | |||
27 | #define irq_to_gpio(irq) ((irq) - gpio_to_irq(0)) | ||
28 | 26 | ||
29 | struct ep93xx_gpio { | 27 | struct ep93xx_gpio { |
30 | void __iomem *mmio_base; | 28 | void __iomem *mmio_base; |
@@ -63,6 +61,11 @@ static void ep93xx_gpio_update_int_params(unsigned port) | |||
63 | EP93XX_GPIO_REG(int_en_register_offset[port])); | 61 | EP93XX_GPIO_REG(int_en_register_offset[port])); |
64 | } | 62 | } |
65 | 63 | ||
64 | static inline void ep93xx_gpio_int_mask(unsigned line) | ||
65 | { | ||
66 | gpio_int_unmasked[line >> 3] &= ~(1 << (line & 7)); | ||
67 | } | ||
68 | |||
66 | static void ep93xx_gpio_int_debounce(unsigned int irq, bool enable) | 69 | static void ep93xx_gpio_int_debounce(unsigned int irq, bool enable) |
67 | { | 70 | { |
68 | int line = irq_to_gpio(irq); | 71 | int line = irq_to_gpio(irq); |
@@ -205,6 +208,7 @@ static int ep93xx_gpio_irq_type(struct irq_data *d, unsigned int type) | |||
205 | handler = handle_edge_irq; | 208 | handler = handle_edge_irq; |
206 | break; | 209 | break; |
207 | default: | 210 | default: |
211 | pr_err("failed to set irq type %d for gpio %d\n", type, gpio); | ||
208 | return -EINVAL; | 212 | return -EINVAL; |
209 | } | 213 | } |
210 | 214 | ||
@@ -303,21 +307,6 @@ static int ep93xx_gpio_set_debounce(struct gpio_chip *chip, | |||
303 | return 0; | 307 | return 0; |
304 | } | 308 | } |
305 | 309 | ||
306 | /* | ||
307 | * Map GPIO A0..A7 (0..7) to irq 64..71, | ||
308 | * B0..B7 (7..15) to irq 72..79, and | ||
309 | * F0..F7 (16..24) to irq 80..87. | ||
310 | */ | ||
311 | static int ep93xx_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
312 | { | ||
313 | int gpio = chip->base + offset; | ||
314 | |||
315 | if (gpio > EP93XX_GPIO_LINE_MAX_IRQ) | ||
316 | return -EINVAL; | ||
317 | |||
318 | return 64 + gpio; | ||
319 | } | ||
320 | |||
321 | static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev, | 310 | static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev, |
322 | void __iomem *mmio_base, struct ep93xx_gpio_bank *bank) | 311 | void __iomem *mmio_base, struct ep93xx_gpio_bank *bank) |
323 | { | 312 | { |
@@ -325,22 +314,20 @@ static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev, | |||
325 | void __iomem *dir = mmio_base + bank->dir; | 314 | void __iomem *dir = mmio_base + bank->dir; |
326 | int err; | 315 | int err; |
327 | 316 | ||
328 | err = bgpio_init(bgc, dev, 1, data, NULL, NULL, dir, NULL, 0); | 317 | err = bgpio_init(bgc, dev, 1, data, NULL, NULL, dir, NULL, false); |
329 | if (err) | 318 | if (err) |
330 | return err; | 319 | return err; |
331 | 320 | ||
332 | bgc->gc.label = bank->label; | 321 | bgc->gc.label = bank->label; |
333 | bgc->gc.base = bank->base; | 322 | bgc->gc.base = bank->base; |
334 | 323 | ||
335 | if (bank->has_debounce) { | 324 | if (bank->has_debounce) |
336 | bgc->gc.set_debounce = ep93xx_gpio_set_debounce; | 325 | bgc->gc.set_debounce = ep93xx_gpio_set_debounce; |
337 | bgc->gc.to_irq = ep93xx_gpio_to_irq; | ||
338 | } | ||
339 | 326 | ||
340 | return gpiochip_add(&bgc->gc); | 327 | return gpiochip_add(&bgc->gc); |
341 | } | 328 | } |
342 | 329 | ||
343 | static int ep93xx_gpio_probe(struct platform_device *pdev) | 330 | static int __devinit ep93xx_gpio_probe(struct platform_device *pdev) |
344 | { | 331 | { |
345 | struct ep93xx_gpio *ep93xx_gpio; | 332 | struct ep93xx_gpio *ep93xx_gpio; |
346 | struct resource *res; | 333 | struct resource *res; |
@@ -370,6 +357,13 @@ static int ep93xx_gpio_probe(struct platform_device *pdev) | |||
370 | } | 357 | } |
371 | ep93xx_gpio->mmio_base = mmio; | 358 | ep93xx_gpio->mmio_base = mmio; |
372 | 359 | ||
360 | /* Default all ports to GPIO */ | ||
361 | ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS | | ||
362 | EP93XX_SYSCON_DEVCFG_GONK | | ||
363 | EP93XX_SYSCON_DEVCFG_EONIDE | | ||
364 | EP93XX_SYSCON_DEVCFG_GONIDE | | ||
365 | EP93XX_SYSCON_DEVCFG_HONIDE); | ||
366 | |||
373 | for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { | 367 | for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { |
374 | struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i]; | 368 | struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i]; |
375 | struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; | 369 | struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; |
diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c deleted file mode 100644 index 7b95a4a8318..00000000000 --- a/drivers/gpio/gpio-ge.c +++ /dev/null | |||
@@ -1,199 +0,0 @@ | |||
1 | /* | ||
2 | * Driver for GE FPGA based GPIO | ||
3 | * | ||
4 | * Author: Martyn Welch <martyn.welch@ge.com> | ||
5 | * | ||
6 | * 2008 (c) GE Intelligent Platforms Embedded Systems, Inc. | ||
7 | * | ||
8 | * This file is licensed under the terms of the GNU General Public License | ||
9 | * version 2. This program is licensed "as is" without any warranty of any | ||
10 | * kind, whether express or implied. | ||
11 | */ | ||
12 | |||
13 | /* TODO | ||
14 | * | ||
15 | * Configuration of output modes (totem-pole/open-drain) | ||
16 | * Interrupt configuration - interrupts are always generated the FPGA relies on | ||
17 | * the I/O interrupt controllers mask to stop them propergating | ||
18 | */ | ||
19 | |||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/compiler.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/io.h> | ||
24 | #include <linux/of.h> | ||
25 | #include <linux/of_device.h> | ||
26 | #include <linux/of_platform.h> | ||
27 | #include <linux/of_gpio.h> | ||
28 | #include <linux/gpio.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/module.h> | ||
31 | |||
32 | #define GEF_GPIO_DIRECT 0x00 | ||
33 | #define GEF_GPIO_IN 0x04 | ||
34 | #define GEF_GPIO_OUT 0x08 | ||
35 | #define GEF_GPIO_TRIG 0x0C | ||
36 | #define GEF_GPIO_POLAR_A 0x10 | ||
37 | #define GEF_GPIO_POLAR_B 0x14 | ||
38 | #define GEF_GPIO_INT_STAT 0x18 | ||
39 | #define GEF_GPIO_OVERRUN 0x1C | ||
40 | #define GEF_GPIO_MODE 0x20 | ||
41 | |||
42 | static void _gef_gpio_set(void __iomem *reg, unsigned int offset, int value) | ||
43 | { | ||
44 | unsigned int data; | ||
45 | |||
46 | data = ioread32be(reg); | ||
47 | /* value: 0=low; 1=high */ | ||
48 | if (value & 0x1) | ||
49 | data = data | (0x1 << offset); | ||
50 | else | ||
51 | data = data & ~(0x1 << offset); | ||
52 | |||
53 | iowrite32be(data, reg); | ||
54 | } | ||
55 | |||
56 | |||
57 | static int gef_gpio_dir_in(struct gpio_chip *chip, unsigned offset) | ||
58 | { | ||
59 | unsigned int data; | ||
60 | struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); | ||
61 | |||
62 | data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); | ||
63 | data = data | (0x1 << offset); | ||
64 | iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); | ||
65 | |||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static int gef_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int value) | ||
70 | { | ||
71 | unsigned int data; | ||
72 | struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); | ||
73 | |||
74 | /* Set direction before switching to input */ | ||
75 | _gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); | ||
76 | |||
77 | data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); | ||
78 | data = data & ~(0x1 << offset); | ||
79 | iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static int gef_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
85 | { | ||
86 | unsigned int data; | ||
87 | int state = 0; | ||
88 | struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); | ||
89 | |||
90 | data = ioread32be(mmchip->regs + GEF_GPIO_IN); | ||
91 | state = (int)((data >> offset) & 0x1); | ||
92 | |||
93 | return state; | ||
94 | } | ||
95 | |||
96 | static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
97 | { | ||
98 | struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); | ||
99 | |||
100 | _gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); | ||
101 | } | ||
102 | |||
103 | static int __init gef_gpio_init(void) | ||
104 | { | ||
105 | struct device_node *np; | ||
106 | int retval; | ||
107 | struct of_mm_gpio_chip *gef_gpio_chip; | ||
108 | |||
109 | for_each_compatible_node(np, NULL, "gef,sbc610-gpio") { | ||
110 | |||
111 | pr_debug("%s: Initialising GEF GPIO\n", np->full_name); | ||
112 | |||
113 | /* Allocate chip structure */ | ||
114 | gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL); | ||
115 | if (!gef_gpio_chip) { | ||
116 | pr_err("%s: Unable to allocate structure\n", | ||
117 | np->full_name); | ||
118 | continue; | ||
119 | } | ||
120 | |||
121 | /* Setup pointers to chip functions */ | ||
122 | gef_gpio_chip->gc.of_gpio_n_cells = 2; | ||
123 | gef_gpio_chip->gc.ngpio = 19; | ||
124 | gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; | ||
125 | gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; | ||
126 | gef_gpio_chip->gc.get = gef_gpio_get; | ||
127 | gef_gpio_chip->gc.set = gef_gpio_set; | ||
128 | |||
129 | /* This function adds a memory mapped GPIO chip */ | ||
130 | retval = of_mm_gpiochip_add(np, gef_gpio_chip); | ||
131 | if (retval) { | ||
132 | kfree(gef_gpio_chip); | ||
133 | pr_err("%s: Unable to add GPIO\n", np->full_name); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | for_each_compatible_node(np, NULL, "gef,sbc310-gpio") { | ||
138 | |||
139 | pr_debug("%s: Initialising GEF GPIO\n", np->full_name); | ||
140 | |||
141 | /* Allocate chip structure */ | ||
142 | gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL); | ||
143 | if (!gef_gpio_chip) { | ||
144 | pr_err("%s: Unable to allocate structure\n", | ||
145 | np->full_name); | ||
146 | continue; | ||
147 | } | ||
148 | |||
149 | /* Setup pointers to chip functions */ | ||
150 | gef_gpio_chip->gc.of_gpio_n_cells = 2; | ||
151 | gef_gpio_chip->gc.ngpio = 6; | ||
152 | gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; | ||
153 | gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; | ||
154 | gef_gpio_chip->gc.get = gef_gpio_get; | ||
155 | gef_gpio_chip->gc.set = gef_gpio_set; | ||
156 | |||
157 | /* This function adds a memory mapped GPIO chip */ | ||
158 | retval = of_mm_gpiochip_add(np, gef_gpio_chip); | ||
159 | if (retval) { | ||
160 | kfree(gef_gpio_chip); | ||
161 | pr_err("%s: Unable to add GPIO\n", np->full_name); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | for_each_compatible_node(np, NULL, "ge,imp3a-gpio") { | ||
166 | |||
167 | pr_debug("%s: Initialising GE GPIO\n", np->full_name); | ||
168 | |||
169 | /* Allocate chip structure */ | ||
170 | gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL); | ||
171 | if (!gef_gpio_chip) { | ||
172 | pr_err("%s: Unable to allocate structure\n", | ||
173 | np->full_name); | ||
174 | continue; | ||
175 | } | ||
176 | |||
177 | /* Setup pointers to chip functions */ | ||
178 | gef_gpio_chip->gc.of_gpio_n_cells = 2; | ||
179 | gef_gpio_chip->gc.ngpio = 16; | ||
180 | gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; | ||
181 | gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; | ||
182 | gef_gpio_chip->gc.get = gef_gpio_get; | ||
183 | gef_gpio_chip->gc.set = gef_gpio_set; | ||
184 | |||
185 | /* This function adds a memory mapped GPIO chip */ | ||
186 | retval = of_mm_gpiochip_add(np, gef_gpio_chip); | ||
187 | if (retval) { | ||
188 | kfree(gef_gpio_chip); | ||
189 | pr_err("%s: Unable to add GPIO\n", np->full_name); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | return 0; | ||
194 | }; | ||
195 | arch_initcall(gef_gpio_init); | ||
196 | |||
197 | MODULE_DESCRIPTION("GE I/O FPGA GPIO driver"); | ||
198 | MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com"); | ||
199 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c index 05fcc0f247c..4e24436b0f8 100644 --- a/drivers/gpio/gpio-generic.c +++ b/drivers/gpio/gpio-generic.c | |||
@@ -364,7 +364,7 @@ EXPORT_SYMBOL_GPL(bgpio_remove); | |||
364 | int bgpio_init(struct bgpio_chip *bgc, struct device *dev, | 364 | int bgpio_init(struct bgpio_chip *bgc, struct device *dev, |
365 | unsigned long sz, void __iomem *dat, void __iomem *set, | 365 | unsigned long sz, void __iomem *dat, void __iomem *set, |
366 | void __iomem *clr, void __iomem *dirout, void __iomem *dirin, | 366 | void __iomem *clr, void __iomem *dirout, void __iomem *dirin, |
367 | unsigned long flags) | 367 | bool big_endian) |
368 | { | 368 | { |
369 | int ret; | 369 | int ret; |
370 | 370 | ||
@@ -385,7 +385,7 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev, | |||
385 | if (ret) | 385 | if (ret) |
386 | return ret; | 386 | return ret; |
387 | 387 | ||
388 | ret = bgpio_setup_accessors(dev, bgc, flags & BGPIOF_BIG_ENDIAN); | 388 | ret = bgpio_setup_accessors(dev, bgc, big_endian); |
389 | if (ret) | 389 | if (ret) |
390 | return ret; | 390 | return ret; |
391 | 391 | ||
@@ -394,11 +394,6 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev, | |||
394 | return ret; | 394 | return ret; |
395 | 395 | ||
396 | bgc->data = bgc->read_reg(bgc->reg_dat); | 396 | bgc->data = bgc->read_reg(bgc->reg_dat); |
397 | if (bgc->gc.set == bgpio_set_set && | ||
398 | !(flags & BGPIOF_UNREADABLE_REG_SET)) | ||
399 | bgc->data = bgc->read_reg(bgc->reg_set); | ||
400 | if (bgc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR)) | ||
401 | bgc->dir = bgc->read_reg(bgc->reg_dir); | ||
402 | 397 | ||
403 | return ret; | 398 | return ret; |
404 | } | 399 | } |
@@ -444,7 +439,7 @@ static void __iomem *bgpio_map(struct platform_device *pdev, | |||
444 | return ret; | 439 | return ret; |
445 | } | 440 | } |
446 | 441 | ||
447 | static int bgpio_pdev_probe(struct platform_device *pdev) | 442 | static int __devinit bgpio_pdev_probe(struct platform_device *pdev) |
448 | { | 443 | { |
449 | struct device *dev = &pdev->dev; | 444 | struct device *dev = &pdev->dev; |
450 | struct resource *r; | 445 | struct resource *r; |
@@ -454,7 +449,7 @@ static int bgpio_pdev_probe(struct platform_device *pdev) | |||
454 | void __iomem *dirout; | 449 | void __iomem *dirout; |
455 | void __iomem *dirin; | 450 | void __iomem *dirin; |
456 | unsigned long sz; | 451 | unsigned long sz; |
457 | unsigned long flags = 0; | 452 | bool be; |
458 | int err; | 453 | int err; |
459 | struct bgpio_chip *bgc; | 454 | struct bgpio_chip *bgc; |
460 | struct bgpio_pdata *pdata = dev_get_platdata(dev); | 455 | struct bgpio_pdata *pdata = dev_get_platdata(dev); |
@@ -485,14 +480,13 @@ static int bgpio_pdev_probe(struct platform_device *pdev) | |||
485 | if (err) | 480 | if (err) |
486 | return err; | 481 | return err; |
487 | 482 | ||
488 | if (!strcmp(platform_get_device_id(pdev)->name, "basic-mmio-gpio-be")) | 483 | be = !strcmp(platform_get_device_id(pdev)->name, "basic-mmio-gpio-be"); |
489 | flags |= BGPIOF_BIG_ENDIAN; | ||
490 | 484 | ||
491 | bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); | 485 | bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); |
492 | if (!bgc) | 486 | if (!bgc) |
493 | return -ENOMEM; | 487 | return -ENOMEM; |
494 | 488 | ||
495 | err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, flags); | 489 | err = bgpio_init(bgc, dev, sz, dat, set, clr, dirout, dirin, be); |
496 | if (err) | 490 | if (err) |
497 | return err; | 491 | return err; |
498 | 492 | ||
@@ -507,7 +501,7 @@ static int bgpio_pdev_probe(struct platform_device *pdev) | |||
507 | return gpiochip_add(&bgc->gc); | 501 | return gpiochip_add(&bgc->gc); |
508 | } | 502 | } |
509 | 503 | ||
510 | static int bgpio_pdev_remove(struct platform_device *pdev) | 504 | static int __devexit bgpio_pdev_remove(struct platform_device *pdev) |
511 | { | 505 | { |
512 | struct bgpio_chip *bgc = platform_get_drvdata(pdev); | 506 | struct bgpio_chip *bgc = platform_get_drvdata(pdev); |
513 | 507 | ||
@@ -527,10 +521,20 @@ static struct platform_driver bgpio_driver = { | |||
527 | }, | 521 | }, |
528 | .id_table = bgpio_id_table, | 522 | .id_table = bgpio_id_table, |
529 | .probe = bgpio_pdev_probe, | 523 | .probe = bgpio_pdev_probe, |
530 | .remove = bgpio_pdev_remove, | 524 | .remove = __devexit_p(bgpio_pdev_remove), |
531 | }; | 525 | }; |
532 | 526 | ||
533 | module_platform_driver(bgpio_driver); | 527 | static int __init bgpio_platform_init(void) |
528 | { | ||
529 | return platform_driver_register(&bgpio_driver); | ||
530 | } | ||
531 | module_init(bgpio_platform_init); | ||
532 | |||
533 | static void __exit bgpio_platform_exit(void) | ||
534 | { | ||
535 | platform_driver_unregister(&bgpio_driver); | ||
536 | } | ||
537 | module_exit(bgpio_platform_exit); | ||
534 | 538 | ||
535 | #endif /* CONFIG_GPIO_GENERIC_PLATFORM */ | 539 | #endif /* CONFIG_GPIO_GENERIC_PLATFORM */ |
536 | 540 | ||
diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c deleted file mode 100644 index 6f2306db859..00000000000 --- a/drivers/gpio/gpio-ich.c +++ /dev/null | |||
@@ -1,479 +0,0 @@ | |||
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 | static const u8 ichx_reglen[3] = { | ||
53 | 0x30, 0x10, 0x10, | ||
54 | }; | ||
55 | |||
56 | #define ICHX_WRITE(val, reg, base_res) outl(val, (reg) + (base_res)->start) | ||
57 | #define ICHX_READ(reg, base_res) inl((reg) + (base_res)->start) | ||
58 | |||
59 | struct ichx_desc { | ||
60 | /* Max GPIO pins the chipset can have */ | ||
61 | uint ngpio; | ||
62 | |||
63 | /* Whether the chipset has GPIO in GPE0_STS in the PM IO region */ | ||
64 | bool uses_gpe0; | ||
65 | |||
66 | /* USE_SEL is bogus on some chipsets, eg 3100 */ | ||
67 | u32 use_sel_ignore[3]; | ||
68 | |||
69 | /* Some chipsets have quirks, let these use their own request/get */ | ||
70 | int (*request)(struct gpio_chip *chip, unsigned offset); | ||
71 | int (*get)(struct gpio_chip *chip, unsigned offset); | ||
72 | }; | ||
73 | |||
74 | static struct { | ||
75 | spinlock_t lock; | ||
76 | struct platform_device *dev; | ||
77 | struct gpio_chip chip; | ||
78 | struct resource *gpio_base; /* GPIO IO base */ | ||
79 | struct resource *pm_base; /* Power Mangagment IO base */ | ||
80 | struct ichx_desc *desc; /* Pointer to chipset-specific description */ | ||
81 | u32 orig_gpio_ctrl; /* Orig CTRL value, used to restore on exit */ | ||
82 | u8 use_gpio; /* Which GPIO groups are usable */ | ||
83 | } ichx_priv; | ||
84 | |||
85 | static int modparam_gpiobase = -1; /* dynamic */ | ||
86 | module_param_named(gpiobase, modparam_gpiobase, int, 0444); | ||
87 | MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, " | ||
88 | "which is the default."); | ||
89 | |||
90 | static int ichx_write_bit(int reg, unsigned nr, int val, int verify) | ||
91 | { | ||
92 | unsigned long flags; | ||
93 | u32 data, tmp; | ||
94 | int reg_nr = nr / 32; | ||
95 | int bit = nr & 0x1f; | ||
96 | int ret = 0; | ||
97 | |||
98 | spin_lock_irqsave(&ichx_priv.lock, flags); | ||
99 | |||
100 | data = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
101 | if (val) | ||
102 | data |= 1 << bit; | ||
103 | else | ||
104 | data &= ~(1 << bit); | ||
105 | ICHX_WRITE(data, ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
106 | tmp = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
107 | if (verify && data != tmp) | ||
108 | ret = -EPERM; | ||
109 | |||
110 | spin_unlock_irqrestore(&ichx_priv.lock, flags); | ||
111 | |||
112 | return ret; | ||
113 | } | ||
114 | |||
115 | static int ichx_read_bit(int reg, unsigned nr) | ||
116 | { | ||
117 | unsigned long flags; | ||
118 | u32 data; | ||
119 | int reg_nr = nr / 32; | ||
120 | int bit = nr & 0x1f; | ||
121 | |||
122 | spin_lock_irqsave(&ichx_priv.lock, flags); | ||
123 | |||
124 | data = ICHX_READ(ichx_regs[reg][reg_nr], ichx_priv.gpio_base); | ||
125 | |||
126 | spin_unlock_irqrestore(&ichx_priv.lock, flags); | ||
127 | |||
128 | return data & (1 << bit) ? 1 : 0; | ||
129 | } | ||
130 | |||
131 | static int ichx_gpio_check_available(struct gpio_chip *gpio, unsigned nr) | ||
132 | { | ||
133 | return (ichx_priv.use_gpio & (1 << (nr / 32))) ? 0 : -ENXIO; | ||
134 | } | ||
135 | |||
136 | static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | ||
137 | { | ||
138 | if (!ichx_gpio_check_available(gpio, nr)) | ||
139 | return -ENXIO; | ||
140 | |||
141 | /* | ||
142 | * Try setting pin as an input and verify it worked since many pins | ||
143 | * are output-only. | ||
144 | */ | ||
145 | if (ichx_write_bit(GPIO_IO_SEL, nr, 1, 1)) | ||
146 | return -EINVAL; | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | ||
152 | int val) | ||
153 | { | ||
154 | if (!ichx_gpio_check_available(gpio, nr)) | ||
155 | return -ENXIO; | ||
156 | |||
157 | /* Set GPIO output value. */ | ||
158 | ichx_write_bit(GPIO_LVL, nr, val, 0); | ||
159 | |||
160 | /* | ||
161 | * Try setting pin as an output and verify it worked since many pins | ||
162 | * are input-only. | ||
163 | */ | ||
164 | if (ichx_write_bit(GPIO_IO_SEL, nr, 0, 1)) | ||
165 | return -EINVAL; | ||
166 | |||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | static int ichx_gpio_get(struct gpio_chip *chip, unsigned nr) | ||
171 | { | ||
172 | if (!ichx_gpio_check_available(chip, nr)) | ||
173 | return -ENXIO; | ||
174 | |||
175 | return ichx_read_bit(GPIO_LVL, nr); | ||
176 | } | ||
177 | |||
178 | static int ich6_gpio_get(struct gpio_chip *chip, unsigned nr) | ||
179 | { | ||
180 | unsigned long flags; | ||
181 | u32 data; | ||
182 | |||
183 | if (!ichx_gpio_check_available(chip, nr)) | ||
184 | return -ENXIO; | ||
185 | |||
186 | /* | ||
187 | * GPI 0 - 15 need to be read from the power management registers on | ||
188 | * a ICH6/3100 bridge. | ||
189 | */ | ||
190 | if (nr < 16) { | ||
191 | if (!ichx_priv.pm_base) | ||
192 | return -ENXIO; | ||
193 | |||
194 | spin_lock_irqsave(&ichx_priv.lock, flags); | ||
195 | |||
196 | /* GPI 0 - 15 are latched, write 1 to clear*/ | ||
197 | ICHX_WRITE(1 << (16 + nr), 0, ichx_priv.pm_base); | ||
198 | data = ICHX_READ(0, ichx_priv.pm_base); | ||
199 | |||
200 | spin_unlock_irqrestore(&ichx_priv.lock, flags); | ||
201 | |||
202 | return (data >> 16) & (1 << nr) ? 1 : 0; | ||
203 | } else { | ||
204 | return ichx_gpio_get(chip, nr); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | static int ichx_gpio_request(struct gpio_chip *chip, unsigned nr) | ||
209 | { | ||
210 | /* | ||
211 | * Note we assume the BIOS properly set a bridge's USE value. Some | ||
212 | * chips (eg Intel 3100) have bogus USE values though, so first see if | ||
213 | * the chipset's USE value can be trusted for this specific bit. | ||
214 | * If it can't be trusted, assume that the pin can be used as a GPIO. | ||
215 | */ | ||
216 | if (ichx_priv.desc->use_sel_ignore[nr / 32] & (1 << (nr & 0x1f))) | ||
217 | return 1; | ||
218 | |||
219 | return ichx_read_bit(GPIO_USE_SEL, nr) ? 0 : -ENODEV; | ||
220 | } | ||
221 | |||
222 | static int ich6_gpio_request(struct gpio_chip *chip, unsigned nr) | ||
223 | { | ||
224 | /* | ||
225 | * Fixups for bits 16 and 17 are necessary on the Intel ICH6/3100 | ||
226 | * bridge as they are controlled by USE register bits 0 and 1. See | ||
227 | * "Table 704 GPIO_USE_SEL1 register" in the i3100 datasheet for | ||
228 | * additional info. | ||
229 | */ | ||
230 | if (nr == 16 || nr == 17) | ||
231 | nr -= 16; | ||
232 | |||
233 | return ichx_gpio_request(chip, nr); | ||
234 | } | ||
235 | |||
236 | static void ichx_gpio_set(struct gpio_chip *chip, unsigned nr, int val) | ||
237 | { | ||
238 | ichx_write_bit(GPIO_LVL, nr, val, 0); | ||
239 | } | ||
240 | |||
241 | static void ichx_gpiolib_setup(struct gpio_chip *chip) | ||
242 | { | ||
243 | chip->owner = THIS_MODULE; | ||
244 | chip->label = DRV_NAME; | ||
245 | chip->dev = &ichx_priv.dev->dev; | ||
246 | |||
247 | /* Allow chip-specific overrides of request()/get() */ | ||
248 | chip->request = ichx_priv.desc->request ? | ||
249 | ichx_priv.desc->request : ichx_gpio_request; | ||
250 | chip->get = ichx_priv.desc->get ? | ||
251 | ichx_priv.desc->get : ichx_gpio_get; | ||
252 | |||
253 | chip->set = ichx_gpio_set; | ||
254 | chip->direction_input = ichx_gpio_direction_input; | ||
255 | chip->direction_output = ichx_gpio_direction_output; | ||
256 | chip->base = modparam_gpiobase; | ||
257 | chip->ngpio = ichx_priv.desc->ngpio; | ||
258 | chip->can_sleep = 0; | ||
259 | chip->dbg_show = NULL; | ||
260 | } | ||
261 | |||
262 | /* ICH6-based, 631xesb-based */ | ||
263 | static struct ichx_desc ich6_desc = { | ||
264 | /* Bridges using the ICH6 controller need fixups for GPIO 0 - 17 */ | ||
265 | .request = ich6_gpio_request, | ||
266 | .get = ich6_gpio_get, | ||
267 | |||
268 | /* GPIO 0-15 are read in the GPE0_STS PM register */ | ||
269 | .uses_gpe0 = true, | ||
270 | |||
271 | .ngpio = 50, | ||
272 | }; | ||
273 | |||
274 | /* Intel 3100 */ | ||
275 | static struct ichx_desc i3100_desc = { | ||
276 | /* | ||
277 | * Bits 16,17, 20 of USE_SEL and bit 16 of USE_SEL2 always read 0 on | ||
278 | * the Intel 3100. See "Table 712. GPIO Summary Table" of 3100 | ||
279 | * Datasheet for more info. | ||
280 | */ | ||
281 | .use_sel_ignore = {0x00130000, 0x00010000, 0x0}, | ||
282 | |||
283 | /* The 3100 needs fixups for GPIO 0 - 17 */ | ||
284 | .request = ich6_gpio_request, | ||
285 | .get = ich6_gpio_get, | ||
286 | |||
287 | /* GPIO 0-15 are read in the GPE0_STS PM register */ | ||
288 | .uses_gpe0 = true, | ||
289 | |||
290 | .ngpio = 50, | ||
291 | }; | ||
292 | |||
293 | /* ICH7 and ICH8-based */ | ||
294 | static struct ichx_desc ich7_desc = { | ||
295 | .ngpio = 50, | ||
296 | }; | ||
297 | |||
298 | /* ICH9-based */ | ||
299 | static struct ichx_desc ich9_desc = { | ||
300 | .ngpio = 61, | ||
301 | }; | ||
302 | |||
303 | /* ICH10-based - Consumer/corporate versions have different amount of GPIO */ | ||
304 | static struct ichx_desc ich10_cons_desc = { | ||
305 | .ngpio = 61, | ||
306 | }; | ||
307 | static struct ichx_desc ich10_corp_desc = { | ||
308 | .ngpio = 72, | ||
309 | }; | ||
310 | |||
311 | /* Intel 5 series, 6 series, 3400 series, and C200 series */ | ||
312 | static struct ichx_desc intel5_desc = { | ||
313 | .ngpio = 76, | ||
314 | }; | ||
315 | |||
316 | static int ichx_gpio_request_regions(struct resource *res_base, | ||
317 | const char *name, u8 use_gpio) | ||
318 | { | ||
319 | int i; | ||
320 | |||
321 | if (!res_base || !res_base->start || !res_base->end) | ||
322 | return -ENODEV; | ||
323 | |||
324 | for (i = 0; i < ARRAY_SIZE(ichx_regs[0]); i++) { | ||
325 | if (!(use_gpio & (1 << i))) | ||
326 | continue; | ||
327 | if (!request_region(res_base->start + ichx_regs[0][i], | ||
328 | ichx_reglen[i], name)) | ||
329 | goto request_err; | ||
330 | } | ||
331 | return 0; | ||
332 | |||
333 | request_err: | ||
334 | /* Clean up: release already requested regions, if any */ | ||
335 | for (i--; i >= 0; i--) { | ||
336 | if (!(use_gpio & (1 << i))) | ||
337 | continue; | ||
338 | release_region(res_base->start + ichx_regs[0][i], | ||
339 | ichx_reglen[i]); | ||
340 | } | ||
341 | return -EBUSY; | ||
342 | } | ||
343 | |||
344 | static void ichx_gpio_release_regions(struct resource *res_base, u8 use_gpio) | ||
345 | { | ||
346 | int i; | ||
347 | |||
348 | for (i = 0; i < ARRAY_SIZE(ichx_regs[0]); i++) { | ||
349 | if (!(use_gpio & (1 << i))) | ||
350 | continue; | ||
351 | release_region(res_base->start + ichx_regs[0][i], | ||
352 | ichx_reglen[i]); | ||
353 | } | ||
354 | } | ||
355 | |||
356 | static int ichx_gpio_probe(struct platform_device *pdev) | ||
357 | { | ||
358 | struct resource *res_base, *res_pm; | ||
359 | int err; | ||
360 | struct lpc_ich_info *ich_info = pdev->dev.platform_data; | ||
361 | |||
362 | if (!ich_info) | ||
363 | return -ENODEV; | ||
364 | |||
365 | ichx_priv.dev = pdev; | ||
366 | |||
367 | switch (ich_info->gpio_version) { | ||
368 | case ICH_I3100_GPIO: | ||
369 | ichx_priv.desc = &i3100_desc; | ||
370 | break; | ||
371 | case ICH_V5_GPIO: | ||
372 | ichx_priv.desc = &intel5_desc; | ||
373 | break; | ||
374 | case ICH_V6_GPIO: | ||
375 | ichx_priv.desc = &ich6_desc; | ||
376 | break; | ||
377 | case ICH_V7_GPIO: | ||
378 | ichx_priv.desc = &ich7_desc; | ||
379 | break; | ||
380 | case ICH_V9_GPIO: | ||
381 | ichx_priv.desc = &ich9_desc; | ||
382 | break; | ||
383 | case ICH_V10CORP_GPIO: | ||
384 | ichx_priv.desc = &ich10_corp_desc; | ||
385 | break; | ||
386 | case ICH_V10CONS_GPIO: | ||
387 | ichx_priv.desc = &ich10_cons_desc; | ||
388 | break; | ||
389 | default: | ||
390 | return -ENODEV; | ||
391 | } | ||
392 | |||
393 | spin_lock_init(&ichx_priv.lock); | ||
394 | res_base = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPIO); | ||
395 | ichx_priv.use_gpio = ich_info->use_gpio; | ||
396 | err = ichx_gpio_request_regions(res_base, pdev->name, | ||
397 | ichx_priv.use_gpio); | ||
398 | if (err) | ||
399 | return err; | ||
400 | |||
401 | ichx_priv.gpio_base = res_base; | ||
402 | |||
403 | /* | ||
404 | * If necessary, determine the I/O address of ACPI/power management | ||
405 | * registers which are needed to read the the GPE0 register for GPI pins | ||
406 | * 0 - 15 on some chipsets. | ||
407 | */ | ||
408 | if (!ichx_priv.desc->uses_gpe0) | ||
409 | goto init; | ||
410 | |||
411 | res_pm = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPE0); | ||
412 | if (!res_pm) { | ||
413 | pr_warn("ACPI BAR is unavailable, GPI 0 - 15 unavailable\n"); | ||
414 | goto init; | ||
415 | } | ||
416 | |||
417 | if (!request_region(res_pm->start, resource_size(res_pm), | ||
418 | pdev->name)) { | ||
419 | pr_warn("ACPI BAR is busy, GPI 0 - 15 unavailable\n"); | ||
420 | goto init; | ||
421 | } | ||
422 | |||
423 | ichx_priv.pm_base = res_pm; | ||
424 | |||
425 | init: | ||
426 | ichx_gpiolib_setup(&ichx_priv.chip); | ||
427 | err = gpiochip_add(&ichx_priv.chip); | ||
428 | if (err) { | ||
429 | pr_err("Failed to register GPIOs\n"); | ||
430 | goto add_err; | ||
431 | } | ||
432 | |||
433 | pr_info("GPIO from %d to %d on %s\n", ichx_priv.chip.base, | ||
434 | ichx_priv.chip.base + ichx_priv.chip.ngpio - 1, DRV_NAME); | ||
435 | |||
436 | return 0; | ||
437 | |||
438 | add_err: | ||
439 | ichx_gpio_release_regions(ichx_priv.gpio_base, ichx_priv.use_gpio); | ||
440 | if (ichx_priv.pm_base) | ||
441 | release_region(ichx_priv.pm_base->start, | ||
442 | resource_size(ichx_priv.pm_base)); | ||
443 | return err; | ||
444 | } | ||
445 | |||
446 | static int ichx_gpio_remove(struct platform_device *pdev) | ||
447 | { | ||
448 | int err; | ||
449 | |||
450 | err = gpiochip_remove(&ichx_priv.chip); | ||
451 | if (err) { | ||
452 | dev_err(&pdev->dev, "%s failed, %d\n", | ||
453 | "gpiochip_remove()", err); | ||
454 | return err; | ||
455 | } | ||
456 | |||
457 | ichx_gpio_release_regions(ichx_priv.gpio_base, ichx_priv.use_gpio); | ||
458 | if (ichx_priv.pm_base) | ||
459 | release_region(ichx_priv.pm_base->start, | ||
460 | resource_size(ichx_priv.pm_base)); | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static struct platform_driver ichx_gpio_driver = { | ||
466 | .driver = { | ||
467 | .owner = THIS_MODULE, | ||
468 | .name = DRV_NAME, | ||
469 | }, | ||
470 | .probe = ichx_gpio_probe, | ||
471 | .remove = ichx_gpio_remove, | ||
472 | }; | ||
473 | |||
474 | module_platform_driver(ichx_gpio_driver); | ||
475 | |||
476 | MODULE_AUTHOR("Peter Tyser <ptyser@xes-inc.com>"); | ||
477 | MODULE_DESCRIPTION("GPIO interface for Intel ICH series"); | ||
478 | MODULE_LICENSE("GPL"); | ||
479 | MODULE_ALIAS("platform:"DRV_NAME); | ||
diff --git a/drivers/gpio/gpio-janz-ttl.c b/drivers/gpio/gpio-janz-ttl.c index 7d0a04169a3..813ac077e5d 100644 --- a/drivers/gpio/gpio-janz-ttl.c +++ b/drivers/gpio/gpio-janz-ttl.c | |||
@@ -108,13 +108,13 @@ static void ttl_set_value(struct gpio_chip *gpio, unsigned offset, int value) | |||
108 | spin_unlock(&mod->lock); | 108 | spin_unlock(&mod->lock); |
109 | } | 109 | } |
110 | 110 | ||
111 | static void ttl_write_reg(struct ttl_module *mod, u8 reg, u16 val) | 111 | static void __devinit ttl_write_reg(struct ttl_module *mod, u8 reg, u16 val) |
112 | { | 112 | { |
113 | iowrite16be(reg, &mod->regs->control); | 113 | iowrite16be(reg, &mod->regs->control); |
114 | iowrite16be(val, &mod->regs->control); | 114 | iowrite16be(val, &mod->regs->control); |
115 | } | 115 | } |
116 | 116 | ||
117 | static void ttl_setup_device(struct ttl_module *mod) | 117 | static void __devinit ttl_setup_device(struct ttl_module *mod) |
118 | { | 118 | { |
119 | /* reset the device to a known state */ | 119 | /* reset the device to a known state */ |
120 | iowrite16be(0x0000, &mod->regs->control); | 120 | iowrite16be(0x0000, &mod->regs->control); |
@@ -140,7 +140,7 @@ static void ttl_setup_device(struct ttl_module *mod) | |||
140 | ttl_write_reg(mod, MASTER_CONF_CTL, CONF_PAE | CONF_PBE | CONF_PCE); | 140 | ttl_write_reg(mod, MASTER_CONF_CTL, CONF_PAE | CONF_PBE | CONF_PCE); |
141 | } | 141 | } |
142 | 142 | ||
143 | static int ttl_probe(struct platform_device *pdev) | 143 | static int __devinit ttl_probe(struct platform_device *pdev) |
144 | { | 144 | { |
145 | struct janz_platform_data *pdata; | 145 | struct janz_platform_data *pdata; |
146 | struct device *dev = &pdev->dev; | 146 | struct device *dev = &pdev->dev; |
@@ -201,6 +201,8 @@ static int ttl_probe(struct platform_device *pdev) | |||
201 | goto out_iounmap_regs; | 201 | goto out_iounmap_regs; |
202 | } | 202 | } |
203 | 203 | ||
204 | dev_info(&pdev->dev, "module %d: registered GPIO device\n", | ||
205 | pdata->modno); | ||
204 | return 0; | 206 | return 0; |
205 | 207 | ||
206 | out_iounmap_regs: | 208 | out_iounmap_regs: |
@@ -211,7 +213,7 @@ out_return: | |||
211 | return ret; | 213 | return ret; |
212 | } | 214 | } |
213 | 215 | ||
214 | static int ttl_remove(struct platform_device *pdev) | 216 | static int __devexit ttl_remove(struct platform_device *pdev) |
215 | { | 217 | { |
216 | struct ttl_module *mod = platform_get_drvdata(pdev); | 218 | struct ttl_module *mod = platform_get_drvdata(pdev); |
217 | struct device *dev = &pdev->dev; | 219 | struct device *dev = &pdev->dev; |
@@ -234,12 +236,23 @@ static struct platform_driver ttl_driver = { | |||
234 | .owner = THIS_MODULE, | 236 | .owner = THIS_MODULE, |
235 | }, | 237 | }, |
236 | .probe = ttl_probe, | 238 | .probe = ttl_probe, |
237 | .remove = ttl_remove, | 239 | .remove = __devexit_p(ttl_remove), |
238 | }; | 240 | }; |
239 | 241 | ||
240 | module_platform_driver(ttl_driver); | 242 | static int __init ttl_init(void) |
243 | { | ||
244 | return platform_driver_register(&ttl_driver); | ||
245 | } | ||
246 | |||
247 | static void __exit ttl_exit(void) | ||
248 | { | ||
249 | platform_driver_unregister(&ttl_driver); | ||
250 | } | ||
241 | 251 | ||
242 | MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>"); | 252 | MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>"); |
243 | MODULE_DESCRIPTION("Janz MODULbus VMOD-TTL Driver"); | 253 | MODULE_DESCRIPTION("Janz MODULbus VMOD-TTL Driver"); |
244 | MODULE_LICENSE("GPL"); | 254 | MODULE_LICENSE("GPL"); |
245 | MODULE_ALIAS("platform:janz-ttl"); | 255 | MODULE_ALIAS("platform:janz-ttl"); |
256 | |||
257 | module_init(ttl_init); | ||
258 | module_exit(ttl_exit); | ||
diff --git a/drivers/gpio/gpio-ks8695.c b/drivers/gpio/gpio-ks8695.c deleted file mode 100644 index a3ac66ea364..00000000000 --- a/drivers/gpio/gpio-ks8695.c +++ /dev/null | |||
@@ -1,319 +0,0 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-ks8695/gpio.c | ||
3 | * | ||
4 | * Copyright (C) 2006 Andrew Victor | ||
5 | * Updated to GPIOLIB, Copyright 2008 Simtec Electronics | ||
6 | * Daniel Silverstone <dsilvers@simtec.co.uk> | ||
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. See the | ||
15 | * 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 | #include <linux/gpio.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/mm.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/debugfs.h> | ||
26 | #include <linux/seq_file.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/io.h> | ||
29 | |||
30 | #include <mach/hardware.h> | ||
31 | #include <asm/mach/irq.h> | ||
32 | |||
33 | #include <mach/regs-gpio.h> | ||
34 | #include <mach/gpio-ks8695.h> | ||
35 | |||
36 | /* | ||
37 | * Configure a GPIO line for either GPIO function, or its internal | ||
38 | * function (Interrupt, Timer, etc). | ||
39 | */ | ||
40 | static void ks8695_gpio_mode(unsigned int pin, short gpio) | ||
41 | { | ||
42 | unsigned int enable[] = { IOPC_IOEINT0EN, IOPC_IOEINT1EN, IOPC_IOEINT2EN, IOPC_IOEINT3EN, IOPC_IOTIM0EN, IOPC_IOTIM1EN }; | ||
43 | unsigned long x, flags; | ||
44 | |||
45 | if (pin > KS8695_GPIO_5) /* only GPIO 0..5 have internal functions */ | ||
46 | return; | ||
47 | |||
48 | local_irq_save(flags); | ||
49 | |||
50 | x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPC); | ||
51 | if (gpio) /* GPIO: set bit to 0 */ | ||
52 | x &= ~enable[pin]; | ||
53 | else /* Internal function: set bit to 1 */ | ||
54 | x |= enable[pin]; | ||
55 | __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPC); | ||
56 | |||
57 | local_irq_restore(flags); | ||
58 | } | ||
59 | |||
60 | |||
61 | static unsigned short gpio_irq[] = { KS8695_IRQ_EXTERN0, KS8695_IRQ_EXTERN1, KS8695_IRQ_EXTERN2, KS8695_IRQ_EXTERN3 }; | ||
62 | |||
63 | /* | ||
64 | * Configure GPIO pin as external interrupt source. | ||
65 | */ | ||
66 | int ks8695_gpio_interrupt(unsigned int pin, unsigned int type) | ||
67 | { | ||
68 | unsigned long x, flags; | ||
69 | |||
70 | if (pin > KS8695_GPIO_3) /* only GPIO 0..3 can generate IRQ */ | ||
71 | return -EINVAL; | ||
72 | |||
73 | local_irq_save(flags); | ||
74 | |||
75 | /* set pin as input */ | ||
76 | x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM); | ||
77 | x &= ~IOPM(pin); | ||
78 | __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM); | ||
79 | |||
80 | local_irq_restore(flags); | ||
81 | |||
82 | /* Set IRQ triggering type */ | ||
83 | irq_set_irq_type(gpio_irq[pin], type); | ||
84 | |||
85 | /* enable interrupt mode */ | ||
86 | ks8695_gpio_mode(pin, 0); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | EXPORT_SYMBOL(ks8695_gpio_interrupt); | ||
91 | |||
92 | |||
93 | |||
94 | /* .... Generic GPIO interface .............................................. */ | ||
95 | |||
96 | /* | ||
97 | * Configure the GPIO line as an input. | ||
98 | */ | ||
99 | static int ks8695_gpio_direction_input(struct gpio_chip *gc, unsigned int pin) | ||
100 | { | ||
101 | unsigned long x, flags; | ||
102 | |||
103 | if (pin > KS8695_GPIO_15) | ||
104 | return -EINVAL; | ||
105 | |||
106 | /* set pin to GPIO mode */ | ||
107 | ks8695_gpio_mode(pin, 1); | ||
108 | |||
109 | local_irq_save(flags); | ||
110 | |||
111 | /* set pin as input */ | ||
112 | x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM); | ||
113 | x &= ~IOPM(pin); | ||
114 | __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM); | ||
115 | |||
116 | local_irq_restore(flags); | ||
117 | |||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | |||
122 | /* | ||
123 | * Configure the GPIO line as an output, with default state. | ||
124 | */ | ||
125 | static int ks8695_gpio_direction_output(struct gpio_chip *gc, | ||
126 | unsigned int pin, int state) | ||
127 | { | ||
128 | unsigned long x, flags; | ||
129 | |||
130 | if (pin > KS8695_GPIO_15) | ||
131 | return -EINVAL; | ||
132 | |||
133 | /* set pin to GPIO mode */ | ||
134 | ks8695_gpio_mode(pin, 1); | ||
135 | |||
136 | local_irq_save(flags); | ||
137 | |||
138 | /* set line state */ | ||
139 | x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD); | ||
140 | if (state) | ||
141 | x |= IOPD(pin); | ||
142 | else | ||
143 | x &= ~IOPD(pin); | ||
144 | __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPD); | ||
145 | |||
146 | /* set pin as output */ | ||
147 | x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM); | ||
148 | x |= IOPM(pin); | ||
149 | __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM); | ||
150 | |||
151 | local_irq_restore(flags); | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | |||
157 | /* | ||
158 | * Set the state of an output GPIO line. | ||
159 | */ | ||
160 | static void ks8695_gpio_set_value(struct gpio_chip *gc, | ||
161 | unsigned int pin, int state) | ||
162 | { | ||
163 | unsigned long x, flags; | ||
164 | |||
165 | if (pin > KS8695_GPIO_15) | ||
166 | return; | ||
167 | |||
168 | local_irq_save(flags); | ||
169 | |||
170 | /* set output line state */ | ||
171 | x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD); | ||
172 | if (state) | ||
173 | x |= IOPD(pin); | ||
174 | else | ||
175 | x &= ~IOPD(pin); | ||
176 | __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPD); | ||
177 | |||
178 | local_irq_restore(flags); | ||
179 | } | ||
180 | |||
181 | |||
182 | /* | ||
183 | * Read the state of a GPIO line. | ||
184 | */ | ||
185 | static int ks8695_gpio_get_value(struct gpio_chip *gc, unsigned int pin) | ||
186 | { | ||
187 | unsigned long x; | ||
188 | |||
189 | if (pin > KS8695_GPIO_15) | ||
190 | return -EINVAL; | ||
191 | |||
192 | x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD); | ||
193 | return (x & IOPD(pin)) != 0; | ||
194 | } | ||
195 | |||
196 | |||
197 | /* | ||
198 | * Map GPIO line to IRQ number. | ||
199 | */ | ||
200 | static int ks8695_gpio_to_irq(struct gpio_chip *gc, unsigned int pin) | ||
201 | { | ||
202 | if (pin > KS8695_GPIO_3) /* only GPIO 0..3 can generate IRQ */ | ||
203 | return -EINVAL; | ||
204 | |||
205 | return gpio_irq[pin]; | ||
206 | } | ||
207 | |||
208 | /* | ||
209 | * Map IRQ number to GPIO line. | ||
210 | */ | ||
211 | int irq_to_gpio(unsigned int irq) | ||
212 | { | ||
213 | if ((irq < KS8695_IRQ_EXTERN0) || (irq > KS8695_IRQ_EXTERN3)) | ||
214 | return -EINVAL; | ||
215 | |||
216 | return (irq - KS8695_IRQ_EXTERN0); | ||
217 | } | ||
218 | EXPORT_SYMBOL(irq_to_gpio); | ||
219 | |||
220 | /* GPIOLIB interface */ | ||
221 | |||
222 | static struct gpio_chip ks8695_gpio_chip = { | ||
223 | .label = "KS8695", | ||
224 | .direction_input = ks8695_gpio_direction_input, | ||
225 | .direction_output = ks8695_gpio_direction_output, | ||
226 | .get = ks8695_gpio_get_value, | ||
227 | .set = ks8695_gpio_set_value, | ||
228 | .to_irq = ks8695_gpio_to_irq, | ||
229 | .base = 0, | ||
230 | .ngpio = 16, | ||
231 | .can_sleep = 0, | ||
232 | }; | ||
233 | |||
234 | /* Register the GPIOs */ | ||
235 | void ks8695_register_gpios(void) | ||
236 | { | ||
237 | if (gpiochip_add(&ks8695_gpio_chip)) | ||
238 | printk(KERN_ERR "Unable to register core GPIOs\n"); | ||
239 | } | ||
240 | |||
241 | /* .... Debug interface ..................................................... */ | ||
242 | |||
243 | #ifdef CONFIG_DEBUG_FS | ||
244 | |||
245 | static int ks8695_gpio_show(struct seq_file *s, void *unused) | ||
246 | { | ||
247 | unsigned int enable[] = { IOPC_IOEINT0EN, IOPC_IOEINT1EN, IOPC_IOEINT2EN, IOPC_IOEINT3EN, IOPC_IOTIM0EN, IOPC_IOTIM1EN }; | ||
248 | unsigned int intmask[] = { IOPC_IOEINT0TM, IOPC_IOEINT1TM, IOPC_IOEINT2TM, IOPC_IOEINT3TM }; | ||
249 | unsigned long mode, ctrl, data; | ||
250 | int i; | ||
251 | |||
252 | mode = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM); | ||
253 | ctrl = __raw_readl(KS8695_GPIO_VA + KS8695_IOPC); | ||
254 | data = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD); | ||
255 | |||
256 | seq_printf(s, "Pin\tI/O\tFunction\tState\n\n"); | ||
257 | |||
258 | for (i = KS8695_GPIO_0; i <= KS8695_GPIO_15 ; i++) { | ||
259 | seq_printf(s, "%i:\t", i); | ||
260 | |||
261 | seq_printf(s, "%s\t", (mode & IOPM(i)) ? "Output" : "Input"); | ||
262 | |||
263 | if (i <= KS8695_GPIO_3) { | ||
264 | if (ctrl & enable[i]) { | ||
265 | seq_printf(s, "EXT%i ", i); | ||
266 | |||
267 | switch ((ctrl & intmask[i]) >> (4 * i)) { | ||
268 | case IOPC_TM_LOW: | ||
269 | seq_printf(s, "(Low)"); break; | ||
270 | case IOPC_TM_HIGH: | ||
271 | seq_printf(s, "(High)"); break; | ||
272 | case IOPC_TM_RISING: | ||
273 | seq_printf(s, "(Rising)"); break; | ||
274 | case IOPC_TM_FALLING: | ||
275 | seq_printf(s, "(Falling)"); break; | ||
276 | case IOPC_TM_EDGE: | ||
277 | seq_printf(s, "(Edges)"); break; | ||
278 | } | ||
279 | } | ||
280 | else | ||
281 | seq_printf(s, "GPIO\t"); | ||
282 | } | ||
283 | else if (i <= KS8695_GPIO_5) { | ||
284 | if (ctrl & enable[i]) | ||
285 | seq_printf(s, "TOUT%i\t", i - KS8695_GPIO_4); | ||
286 | else | ||
287 | seq_printf(s, "GPIO\t"); | ||
288 | } | ||
289 | else | ||
290 | seq_printf(s, "GPIO\t"); | ||
291 | |||
292 | seq_printf(s, "\t"); | ||
293 | |||
294 | seq_printf(s, "%i\n", (data & IOPD(i)) ? 1 : 0); | ||
295 | } | ||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | static int ks8695_gpio_open(struct inode *inode, struct file *file) | ||
300 | { | ||
301 | return single_open(file, ks8695_gpio_show, NULL); | ||
302 | } | ||
303 | |||
304 | static const struct file_operations ks8695_gpio_operations = { | ||
305 | .open = ks8695_gpio_open, | ||
306 | .read = seq_read, | ||
307 | .llseek = seq_lseek, | ||
308 | .release = single_release, | ||
309 | }; | ||
310 | |||
311 | static int __init ks8695_gpio_debugfs_init(void) | ||
312 | { | ||
313 | /* /sys/kernel/debug/ks8695_gpio */ | ||
314 | (void) debugfs_create_file("ks8695_gpio", S_IFREG | S_IRUGO, NULL, NULL, &ks8695_gpio_operations); | ||
315 | return 0; | ||
316 | } | ||
317 | postcore_initcall(ks8695_gpio_debugfs_init); | ||
318 | |||
319 | #endif | ||
diff --git a/drivers/gpio/gpio-langwell.c b/drivers/gpio/gpio-langwell.c index e77b2b3e94a..d2eb57c60e0 100644 --- a/drivers/gpio/gpio-langwell.c +++ b/drivers/gpio/gpio-langwell.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/gpio.h> | 36 | #include <linux/gpio.h> |
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | #include <linux/pm_runtime.h> | 38 | #include <linux/pm_runtime.h> |
39 | #include <linux/irqdomain.h> | ||
40 | 39 | ||
41 | /* | 40 | /* |
42 | * Langwell chip has 64 pins and thus there are 2 32bit registers to control | 41 | * Langwell chip has 64 pins and thus there are 2 32bit registers to control |
@@ -60,15 +59,14 @@ enum GPIO_REG { | |||
60 | GRER, /* rising edge detect */ | 59 | GRER, /* rising edge detect */ |
61 | GFER, /* falling edge detect */ | 60 | GFER, /* falling edge detect */ |
62 | GEDR, /* edge detect result */ | 61 | GEDR, /* edge detect result */ |
63 | GAFR, /* alt function */ | ||
64 | }; | 62 | }; |
65 | 63 | ||
66 | struct lnw_gpio { | 64 | struct lnw_gpio { |
67 | struct gpio_chip chip; | 65 | struct gpio_chip chip; |
68 | void *reg_base; | 66 | void *reg_base; |
69 | spinlock_t lock; | 67 | spinlock_t lock; |
68 | unsigned irq_base; | ||
70 | struct pci_dev *pdev; | 69 | struct pci_dev *pdev; |
71 | struct irq_domain *domain; | ||
72 | }; | 70 | }; |
73 | 71 | ||
74 | static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, | 72 | static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, |
@@ -83,31 +81,6 @@ static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, | |||
83 | return ptr; | 81 | return ptr; |
84 | } | 82 | } |
85 | 83 | ||
86 | static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, | ||
87 | enum GPIO_REG reg_type) | ||
88 | { | ||
89 | struct lnw_gpio *lnw = container_of(chip, struct lnw_gpio, chip); | ||
90 | unsigned nreg = chip->ngpio / 32; | ||
91 | u8 reg = offset / 16; | ||
92 | void __iomem *ptr; | ||
93 | |||
94 | ptr = (void __iomem *)(lnw->reg_base + reg_type * nreg * 4 + reg * 4); | ||
95 | return ptr; | ||
96 | } | ||
97 | |||
98 | static int lnw_gpio_request(struct gpio_chip *chip, unsigned offset) | ||
99 | { | ||
100 | void __iomem *gafr = gpio_reg_2bit(chip, offset, GAFR); | ||
101 | u32 value = readl(gafr); | ||
102 | int shift = (offset % 16) << 1, af = (value >> shift) & 3; | ||
103 | |||
104 | if (af) { | ||
105 | value &= ~(3 << shift); | ||
106 | writel(value, gafr); | ||
107 | } | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | static int lnw_gpio_get(struct gpio_chip *chip, unsigned offset) | 84 | static int lnw_gpio_get(struct gpio_chip *chip, unsigned offset) |
112 | { | 85 | { |
113 | void __iomem *gplr = gpio_reg(chip, offset, GPLR); | 86 | void __iomem *gplr = gpio_reg(chip, offset, GPLR); |
@@ -177,13 +150,13 @@ static int lnw_gpio_direction_output(struct gpio_chip *chip, | |||
177 | static int lnw_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | 150 | static int lnw_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
178 | { | 151 | { |
179 | struct lnw_gpio *lnw = container_of(chip, struct lnw_gpio, chip); | 152 | struct lnw_gpio *lnw = container_of(chip, struct lnw_gpio, chip); |
180 | return irq_create_mapping(lnw->domain, offset); | 153 | return lnw->irq_base + offset; |
181 | } | 154 | } |
182 | 155 | ||
183 | static int lnw_irq_type(struct irq_data *d, unsigned type) | 156 | static int lnw_irq_type(struct irq_data *d, unsigned type) |
184 | { | 157 | { |
185 | struct lnw_gpio *lnw = irq_data_get_irq_chip_data(d); | 158 | struct lnw_gpio *lnw = irq_data_get_irq_chip_data(d); |
186 | u32 gpio = irqd_to_hwirq(d); | 159 | u32 gpio = d->irq - lnw->irq_base; |
187 | unsigned long flags; | 160 | unsigned long flags; |
188 | u32 value; | 161 | u32 value; |
189 | void __iomem *grer = gpio_reg(&lnw->chip, gpio, GRER); | 162 | void __iomem *grer = gpio_reg(&lnw->chip, gpio, GRER); |
@@ -250,55 +223,20 @@ static void lnw_irq_handler(unsigned irq, struct irq_desc *desc) | |||
250 | /* check GPIO controller to check which pin triggered the interrupt */ | 223 | /* check GPIO controller to check which pin triggered the interrupt */ |
251 | for (base = 0; base < lnw->chip.ngpio; base += 32) { | 224 | for (base = 0; base < lnw->chip.ngpio; base += 32) { |
252 | gedr = gpio_reg(&lnw->chip, base, GEDR); | 225 | gedr = gpio_reg(&lnw->chip, base, GEDR); |
253 | while ((pending = readl(gedr))) { | 226 | pending = readl(gedr); |
227 | while (pending) { | ||
254 | gpio = __ffs(pending); | 228 | gpio = __ffs(pending); |
255 | mask = BIT(gpio); | 229 | mask = BIT(gpio); |
230 | pending &= ~mask; | ||
256 | /* Clear before handling so we can't lose an edge */ | 231 | /* Clear before handling so we can't lose an edge */ |
257 | writel(mask, gedr); | 232 | writel(mask, gedr); |
258 | generic_handle_irq(irq_find_mapping(lnw->domain, | 233 | generic_handle_irq(lnw->irq_base + base + gpio); |
259 | base + gpio)); | ||
260 | } | 234 | } |
261 | } | 235 | } |
262 | 236 | ||
263 | chip->irq_eoi(data); | 237 | chip->irq_eoi(data); |
264 | } | 238 | } |
265 | 239 | ||
266 | static void lnw_irq_init_hw(struct lnw_gpio *lnw) | ||
267 | { | ||
268 | void __iomem *reg; | ||
269 | unsigned base; | ||
270 | |||
271 | for (base = 0; base < lnw->chip.ngpio; base += 32) { | ||
272 | /* Clear the rising-edge detect register */ | ||
273 | reg = gpio_reg(&lnw->chip, base, GRER); | ||
274 | writel(0, reg); | ||
275 | /* Clear the falling-edge detect register */ | ||
276 | reg = gpio_reg(&lnw->chip, base, GFER); | ||
277 | writel(0, reg); | ||
278 | /* Clear the edge detect status register */ | ||
279 | reg = gpio_reg(&lnw->chip, base, GEDR); | ||
280 | writel(~0, reg); | ||
281 | } | ||
282 | } | ||
283 | |||
284 | static int lnw_gpio_irq_map(struct irq_domain *d, unsigned int virq, | ||
285 | irq_hw_number_t hw) | ||
286 | { | ||
287 | struct lnw_gpio *lnw = d->host_data; | ||
288 | |||
289 | irq_set_chip_and_handler_name(virq, &lnw_irqchip, handle_simple_irq, | ||
290 | "demux"); | ||
291 | irq_set_chip_data(virq, lnw); | ||
292 | irq_set_irq_type(virq, IRQ_TYPE_NONE); | ||
293 | |||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | static const struct irq_domain_ops lnw_gpio_irq_ops = { | ||
298 | .map = lnw_gpio_irq_map, | ||
299 | .xlate = irq_domain_xlate_twocell, | ||
300 | }; | ||
301 | |||
302 | #ifdef CONFIG_PM | 240 | #ifdef CONFIG_PM |
303 | static int lnw_gpio_runtime_resume(struct device *dev) | 241 | static int lnw_gpio_runtime_resume(struct device *dev) |
304 | { | 242 | { |
@@ -332,96 +270,95 @@ static const struct dev_pm_ops lnw_gpio_pm_ops = { | |||
332 | .runtime_idle = lnw_gpio_runtime_idle, | 270 | .runtime_idle = lnw_gpio_runtime_idle, |
333 | }; | 271 | }; |
334 | 272 | ||
335 | static int lnw_gpio_probe(struct pci_dev *pdev, | 273 | static int __devinit lnw_gpio_probe(struct pci_dev *pdev, |
336 | const struct pci_device_id *id) | 274 | const struct pci_device_id *id) |
337 | { | 275 | { |
338 | void *base; | 276 | void *base; |
277 | int i; | ||
339 | resource_size_t start, len; | 278 | resource_size_t start, len; |
340 | struct lnw_gpio *lnw; | 279 | struct lnw_gpio *lnw; |
280 | u32 irq_base; | ||
341 | u32 gpio_base; | 281 | u32 gpio_base; |
342 | int retval; | 282 | int retval = 0; |
343 | int ngpio = id->driver_data; | ||
344 | 283 | ||
345 | retval = pci_enable_device(pdev); | 284 | retval = pci_enable_device(pdev); |
346 | if (retval) | 285 | if (retval) |
347 | return retval; | 286 | goto done; |
348 | 287 | ||
349 | retval = pci_request_regions(pdev, "langwell_gpio"); | 288 | retval = pci_request_regions(pdev, "langwell_gpio"); |
350 | if (retval) { | 289 | if (retval) { |
351 | dev_err(&pdev->dev, "error requesting resources\n"); | 290 | dev_err(&pdev->dev, "error requesting resources\n"); |
352 | goto err2; | 291 | goto err2; |
353 | } | 292 | } |
354 | /* get the gpio_base from bar1 */ | 293 | /* get the irq_base from bar1 */ |
355 | start = pci_resource_start(pdev, 1); | 294 | start = pci_resource_start(pdev, 1); |
356 | len = pci_resource_len(pdev, 1); | 295 | len = pci_resource_len(pdev, 1); |
357 | base = ioremap_nocache(start, len); | 296 | base = ioremap_nocache(start, len); |
358 | if (!base) { | 297 | if (!base) { |
359 | dev_err(&pdev->dev, "error mapping bar1\n"); | 298 | dev_err(&pdev->dev, "error mapping bar1\n"); |
360 | retval = -EFAULT; | ||
361 | goto err3; | 299 | goto err3; |
362 | } | 300 | } |
301 | irq_base = *(u32 *)base; | ||
363 | gpio_base = *((u32 *)base + 1); | 302 | gpio_base = *((u32 *)base + 1); |
364 | /* release the IO mapping, since we already get the info from bar1 */ | 303 | /* release the IO mapping, since we already get the info from bar1 */ |
365 | iounmap(base); | 304 | iounmap(base); |
366 | /* get the register base from bar0 */ | 305 | /* get the register base from bar0 */ |
367 | start = pci_resource_start(pdev, 0); | 306 | start = pci_resource_start(pdev, 0); |
368 | len = pci_resource_len(pdev, 0); | 307 | len = pci_resource_len(pdev, 0); |
369 | base = devm_ioremap_nocache(&pdev->dev, start, len); | 308 | base = ioremap_nocache(start, len); |
370 | if (!base) { | 309 | if (!base) { |
371 | dev_err(&pdev->dev, "error mapping bar0\n"); | 310 | dev_err(&pdev->dev, "error mapping bar0\n"); |
372 | retval = -EFAULT; | 311 | retval = -EFAULT; |
373 | goto err3; | 312 | goto err3; |
374 | } | 313 | } |
375 | 314 | ||
376 | lnw = devm_kzalloc(&pdev->dev, sizeof(struct lnw_gpio), GFP_KERNEL); | 315 | lnw = kzalloc(sizeof(struct lnw_gpio), GFP_KERNEL); |
377 | if (!lnw) { | 316 | if (!lnw) { |
378 | dev_err(&pdev->dev, "can't allocate langwell_gpio chip data\n"); | 317 | dev_err(&pdev->dev, "can't allocate langwell_gpio chip data\n"); |
379 | retval = -ENOMEM; | 318 | retval = -ENOMEM; |
380 | goto err3; | 319 | goto err4; |
381 | } | 320 | } |
382 | |||
383 | lnw->domain = irq_domain_add_linear(pdev->dev.of_node, ngpio, | ||
384 | &lnw_gpio_irq_ops, lnw); | ||
385 | if (!lnw->domain) { | ||
386 | retval = -ENOMEM; | ||
387 | goto err3; | ||
388 | } | ||
389 | |||
390 | lnw->reg_base = base; | 321 | lnw->reg_base = base; |
322 | lnw->irq_base = irq_base; | ||
391 | lnw->chip.label = dev_name(&pdev->dev); | 323 | lnw->chip.label = dev_name(&pdev->dev); |
392 | lnw->chip.request = lnw_gpio_request; | ||
393 | lnw->chip.direction_input = lnw_gpio_direction_input; | 324 | lnw->chip.direction_input = lnw_gpio_direction_input; |
394 | lnw->chip.direction_output = lnw_gpio_direction_output; | 325 | lnw->chip.direction_output = lnw_gpio_direction_output; |
395 | lnw->chip.get = lnw_gpio_get; | 326 | lnw->chip.get = lnw_gpio_get; |
396 | lnw->chip.set = lnw_gpio_set; | 327 | lnw->chip.set = lnw_gpio_set; |
397 | lnw->chip.to_irq = lnw_gpio_to_irq; | 328 | lnw->chip.to_irq = lnw_gpio_to_irq; |
398 | lnw->chip.base = gpio_base; | 329 | lnw->chip.base = gpio_base; |
399 | lnw->chip.ngpio = ngpio; | 330 | lnw->chip.ngpio = id->driver_data; |
400 | lnw->chip.can_sleep = 0; | 331 | lnw->chip.can_sleep = 0; |
401 | lnw->pdev = pdev; | 332 | lnw->pdev = pdev; |
402 | pci_set_drvdata(pdev, lnw); | 333 | pci_set_drvdata(pdev, lnw); |
403 | retval = gpiochip_add(&lnw->chip); | 334 | retval = gpiochip_add(&lnw->chip); |
404 | if (retval) { | 335 | if (retval) { |
405 | dev_err(&pdev->dev, "langwell gpiochip_add error %d\n", retval); | 336 | dev_err(&pdev->dev, "langwell gpiochip_add error %d\n", retval); |
406 | goto err3; | 337 | goto err5; |
407 | } | 338 | } |
408 | |||
409 | lnw_irq_init_hw(lnw); | ||
410 | |||
411 | irq_set_handler_data(pdev->irq, lnw); | 339 | irq_set_handler_data(pdev->irq, lnw); |
412 | irq_set_chained_handler(pdev->irq, lnw_irq_handler); | 340 | irq_set_chained_handler(pdev->irq, lnw_irq_handler); |
341 | for (i = 0; i < lnw->chip.ngpio; i++) { | ||
342 | irq_set_chip_and_handler_name(i + lnw->irq_base, &lnw_irqchip, | ||
343 | handle_simple_irq, "demux"); | ||
344 | irq_set_chip_data(i + lnw->irq_base, lnw); | ||
345 | } | ||
413 | 346 | ||
414 | spin_lock_init(&lnw->lock); | 347 | spin_lock_init(&lnw->lock); |
415 | 348 | ||
416 | pm_runtime_put_noidle(&pdev->dev); | 349 | pm_runtime_put_noidle(&pdev->dev); |
417 | pm_runtime_allow(&pdev->dev); | 350 | pm_runtime_allow(&pdev->dev); |
418 | 351 | ||
419 | return 0; | 352 | goto done; |
420 | 353 | err5: | |
354 | kfree(lnw); | ||
355 | err4: | ||
356 | iounmap(base); | ||
421 | err3: | 357 | err3: |
422 | pci_release_regions(pdev); | 358 | pci_release_regions(pdev); |
423 | err2: | 359 | err2: |
424 | pci_disable_device(pdev); | 360 | pci_disable_device(pdev); |
361 | done: | ||
425 | return retval; | 362 | return retval; |
426 | } | 363 | } |
427 | 364 | ||
@@ -435,7 +372,7 @@ static struct pci_driver lnw_gpio_driver = { | |||
435 | }; | 372 | }; |
436 | 373 | ||
437 | 374 | ||
438 | static int wp_gpio_probe(struct platform_device *pdev) | 375 | static int __devinit wp_gpio_probe(struct platform_device *pdev) |
439 | { | 376 | { |
440 | struct lnw_gpio *lnw; | 377 | struct lnw_gpio *lnw; |
441 | struct gpio_chip *gc; | 378 | struct gpio_chip *gc; |
@@ -484,7 +421,7 @@ err_kmalloc: | |||
484 | return retval; | 421 | return retval; |
485 | } | 422 | } |
486 | 423 | ||
487 | static int wp_gpio_remove(struct platform_device *pdev) | 424 | static int __devexit wp_gpio_remove(struct platform_device *pdev) |
488 | { | 425 | { |
489 | struct lnw_gpio *lnw = platform_get_drvdata(pdev); | 426 | struct lnw_gpio *lnw = platform_get_drvdata(pdev); |
490 | int err; | 427 | int err; |
@@ -499,7 +436,7 @@ static int wp_gpio_remove(struct platform_device *pdev) | |||
499 | 436 | ||
500 | static struct platform_driver wp_gpio_driver = { | 437 | static struct platform_driver wp_gpio_driver = { |
501 | .probe = wp_gpio_probe, | 438 | .probe = wp_gpio_probe, |
502 | .remove = wp_gpio_remove, | 439 | .remove = __devexit_p(wp_gpio_remove), |
503 | .driver = { | 440 | .driver = { |
504 | .name = "wp_gpio", | 441 | .name = "wp_gpio", |
505 | .owner = THIS_MODULE, | 442 | .owner = THIS_MODULE, |
diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c deleted file mode 100644 index 36d7dee07b2..00000000000 --- a/drivers/gpio/gpio-lpc32xx.c +++ /dev/null | |||
@@ -1,577 +0,0 @@ | |||
1 | /* | ||
2 | * GPIO driver for LPC32xx SoC | ||
3 | * | ||
4 | * Author: Kevin Wells <kevin.wells@nxp.com> | ||
5 | * | ||
6 | * Copyright (C) 2010 NXP Semiconductors | ||
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 as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/gpio.h> | ||
24 | #include <linux/of_gpio.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <linux/module.h> | ||
27 | |||
28 | #include <mach/hardware.h> | ||
29 | #include <mach/platform.h> | ||
30 | #include <mach/gpio-lpc32xx.h> | ||
31 | #include <mach/irqs.h> | ||
32 | |||
33 | #define LPC32XX_GPIO_P3_INP_STATE _GPREG(0x000) | ||
34 | #define LPC32XX_GPIO_P3_OUTP_SET _GPREG(0x004) | ||
35 | #define LPC32XX_GPIO_P3_OUTP_CLR _GPREG(0x008) | ||
36 | #define LPC32XX_GPIO_P3_OUTP_STATE _GPREG(0x00C) | ||
37 | #define LPC32XX_GPIO_P2_DIR_SET _GPREG(0x010) | ||
38 | #define LPC32XX_GPIO_P2_DIR_CLR _GPREG(0x014) | ||
39 | #define LPC32XX_GPIO_P2_DIR_STATE _GPREG(0x018) | ||
40 | #define LPC32XX_GPIO_P2_INP_STATE _GPREG(0x01C) | ||
41 | #define LPC32XX_GPIO_P2_OUTP_SET _GPREG(0x020) | ||
42 | #define LPC32XX_GPIO_P2_OUTP_CLR _GPREG(0x024) | ||
43 | #define LPC32XX_GPIO_P2_MUX_SET _GPREG(0x028) | ||
44 | #define LPC32XX_GPIO_P2_MUX_CLR _GPREG(0x02C) | ||
45 | #define LPC32XX_GPIO_P2_MUX_STATE _GPREG(0x030) | ||
46 | #define LPC32XX_GPIO_P0_INP_STATE _GPREG(0x040) | ||
47 | #define LPC32XX_GPIO_P0_OUTP_SET _GPREG(0x044) | ||
48 | #define LPC32XX_GPIO_P0_OUTP_CLR _GPREG(0x048) | ||
49 | #define LPC32XX_GPIO_P0_OUTP_STATE _GPREG(0x04C) | ||
50 | #define LPC32XX_GPIO_P0_DIR_SET _GPREG(0x050) | ||
51 | #define LPC32XX_GPIO_P0_DIR_CLR _GPREG(0x054) | ||
52 | #define LPC32XX_GPIO_P0_DIR_STATE _GPREG(0x058) | ||
53 | #define LPC32XX_GPIO_P1_INP_STATE _GPREG(0x060) | ||
54 | #define LPC32XX_GPIO_P1_OUTP_SET _GPREG(0x064) | ||
55 | #define LPC32XX_GPIO_P1_OUTP_CLR _GPREG(0x068) | ||
56 | #define LPC32XX_GPIO_P1_OUTP_STATE _GPREG(0x06C) | ||
57 | #define LPC32XX_GPIO_P1_DIR_SET _GPREG(0x070) | ||
58 | #define LPC32XX_GPIO_P1_DIR_CLR _GPREG(0x074) | ||
59 | #define LPC32XX_GPIO_P1_DIR_STATE _GPREG(0x078) | ||
60 | |||
61 | #define GPIO012_PIN_TO_BIT(x) (1 << (x)) | ||
62 | #define GPIO3_PIN_TO_BIT(x) (1 << ((x) + 25)) | ||
63 | #define GPO3_PIN_TO_BIT(x) (1 << (x)) | ||
64 | #define GPIO012_PIN_IN_SEL(x, y) (((x) >> (y)) & 1) | ||
65 | #define GPIO3_PIN_IN_SHIFT(x) ((x) == 5 ? 24 : 10 + (x)) | ||
66 | #define GPIO3_PIN_IN_SEL(x, y) (((x) >> GPIO3_PIN_IN_SHIFT(y)) & 1) | ||
67 | #define GPIO3_PIN5_IN_SEL(x) (((x) >> 24) & 1) | ||
68 | #define GPI3_PIN_IN_SEL(x, y) (((x) >> (y)) & 1) | ||
69 | #define GPO3_PIN_IN_SEL(x, y) (((x) >> (y)) & 1) | ||
70 | |||
71 | struct gpio_regs { | ||
72 | void __iomem *inp_state; | ||
73 | void __iomem *outp_state; | ||
74 | void __iomem *outp_set; | ||
75 | void __iomem *outp_clr; | ||
76 | void __iomem *dir_set; | ||
77 | void __iomem *dir_clr; | ||
78 | }; | ||
79 | |||
80 | /* | ||
81 | * GPIO names | ||
82 | */ | ||
83 | static const char *gpio_p0_names[LPC32XX_GPIO_P0_MAX] = { | ||
84 | "p0.0", "p0.1", "p0.2", "p0.3", | ||
85 | "p0.4", "p0.5", "p0.6", "p0.7" | ||
86 | }; | ||
87 | |||
88 | static const char *gpio_p1_names[LPC32XX_GPIO_P1_MAX] = { | ||
89 | "p1.0", "p1.1", "p1.2", "p1.3", | ||
90 | "p1.4", "p1.5", "p1.6", "p1.7", | ||
91 | "p1.8", "p1.9", "p1.10", "p1.11", | ||
92 | "p1.12", "p1.13", "p1.14", "p1.15", | ||
93 | "p1.16", "p1.17", "p1.18", "p1.19", | ||
94 | "p1.20", "p1.21", "p1.22", "p1.23", | ||
95 | }; | ||
96 | |||
97 | static const char *gpio_p2_names[LPC32XX_GPIO_P2_MAX] = { | ||
98 | "p2.0", "p2.1", "p2.2", "p2.3", | ||
99 | "p2.4", "p2.5", "p2.6", "p2.7", | ||
100 | "p2.8", "p2.9", "p2.10", "p2.11", | ||
101 | "p2.12" | ||
102 | }; | ||
103 | |||
104 | static const char *gpio_p3_names[LPC32XX_GPIO_P3_MAX] = { | ||
105 | "gpio00", "gpio01", "gpio02", "gpio03", | ||
106 | "gpio04", "gpio05" | ||
107 | }; | ||
108 | |||
109 | static const char *gpi_p3_names[LPC32XX_GPI_P3_MAX] = { | ||
110 | "gpi00", "gpi01", "gpi02", "gpi03", | ||
111 | "gpi04", "gpi05", "gpi06", "gpi07", | ||
112 | "gpi08", "gpi09", NULL, NULL, | ||
113 | NULL, NULL, NULL, "gpi15", | ||
114 | "gpi16", "gpi17", "gpi18", "gpi19", | ||
115 | "gpi20", "gpi21", "gpi22", "gpi23", | ||
116 | "gpi24", "gpi25", "gpi26", "gpi27", | ||
117 | "gpi28" | ||
118 | }; | ||
119 | |||
120 | static const char *gpo_p3_names[LPC32XX_GPO_P3_MAX] = { | ||
121 | "gpo00", "gpo01", "gpo02", "gpo03", | ||
122 | "gpo04", "gpo05", "gpo06", "gpo07", | ||
123 | "gpo08", "gpo09", "gpo10", "gpo11", | ||
124 | "gpo12", "gpo13", "gpo14", "gpo15", | ||
125 | "gpo16", "gpo17", "gpo18", "gpo19", | ||
126 | "gpo20", "gpo21", "gpo22", "gpo23" | ||
127 | }; | ||
128 | |||
129 | static struct gpio_regs gpio_grp_regs_p0 = { | ||
130 | .inp_state = LPC32XX_GPIO_P0_INP_STATE, | ||
131 | .outp_set = LPC32XX_GPIO_P0_OUTP_SET, | ||
132 | .outp_clr = LPC32XX_GPIO_P0_OUTP_CLR, | ||
133 | .dir_set = LPC32XX_GPIO_P0_DIR_SET, | ||
134 | .dir_clr = LPC32XX_GPIO_P0_DIR_CLR, | ||
135 | }; | ||
136 | |||
137 | static struct gpio_regs gpio_grp_regs_p1 = { | ||
138 | .inp_state = LPC32XX_GPIO_P1_INP_STATE, | ||
139 | .outp_set = LPC32XX_GPIO_P1_OUTP_SET, | ||
140 | .outp_clr = LPC32XX_GPIO_P1_OUTP_CLR, | ||
141 | .dir_set = LPC32XX_GPIO_P1_DIR_SET, | ||
142 | .dir_clr = LPC32XX_GPIO_P1_DIR_CLR, | ||
143 | }; | ||
144 | |||
145 | static struct gpio_regs gpio_grp_regs_p2 = { | ||
146 | .inp_state = LPC32XX_GPIO_P2_INP_STATE, | ||
147 | .outp_set = LPC32XX_GPIO_P2_OUTP_SET, | ||
148 | .outp_clr = LPC32XX_GPIO_P2_OUTP_CLR, | ||
149 | .dir_set = LPC32XX_GPIO_P2_DIR_SET, | ||
150 | .dir_clr = LPC32XX_GPIO_P2_DIR_CLR, | ||
151 | }; | ||
152 | |||
153 | static struct gpio_regs gpio_grp_regs_p3 = { | ||
154 | .inp_state = LPC32XX_GPIO_P3_INP_STATE, | ||
155 | .outp_state = LPC32XX_GPIO_P3_OUTP_STATE, | ||
156 | .outp_set = LPC32XX_GPIO_P3_OUTP_SET, | ||
157 | .outp_clr = LPC32XX_GPIO_P3_OUTP_CLR, | ||
158 | .dir_set = LPC32XX_GPIO_P2_DIR_SET, | ||
159 | .dir_clr = LPC32XX_GPIO_P2_DIR_CLR, | ||
160 | }; | ||
161 | |||
162 | struct lpc32xx_gpio_chip { | ||
163 | struct gpio_chip chip; | ||
164 | struct gpio_regs *gpio_grp; | ||
165 | }; | ||
166 | |||
167 | static inline struct lpc32xx_gpio_chip *to_lpc32xx_gpio( | ||
168 | struct gpio_chip *gpc) | ||
169 | { | ||
170 | return container_of(gpc, struct lpc32xx_gpio_chip, chip); | ||
171 | } | ||
172 | |||
173 | static void __set_gpio_dir_p012(struct lpc32xx_gpio_chip *group, | ||
174 | unsigned pin, int input) | ||
175 | { | ||
176 | if (input) | ||
177 | __raw_writel(GPIO012_PIN_TO_BIT(pin), | ||
178 | group->gpio_grp->dir_clr); | ||
179 | else | ||
180 | __raw_writel(GPIO012_PIN_TO_BIT(pin), | ||
181 | group->gpio_grp->dir_set); | ||
182 | } | ||
183 | |||
184 | static void __set_gpio_dir_p3(struct lpc32xx_gpio_chip *group, | ||
185 | unsigned pin, int input) | ||
186 | { | ||
187 | u32 u = GPIO3_PIN_TO_BIT(pin); | ||
188 | |||
189 | if (input) | ||
190 | __raw_writel(u, group->gpio_grp->dir_clr); | ||
191 | else | ||
192 | __raw_writel(u, group->gpio_grp->dir_set); | ||
193 | } | ||
194 | |||
195 | static void __set_gpio_level_p012(struct lpc32xx_gpio_chip *group, | ||
196 | unsigned pin, int high) | ||
197 | { | ||
198 | if (high) | ||
199 | __raw_writel(GPIO012_PIN_TO_BIT(pin), | ||
200 | group->gpio_grp->outp_set); | ||
201 | else | ||
202 | __raw_writel(GPIO012_PIN_TO_BIT(pin), | ||
203 | group->gpio_grp->outp_clr); | ||
204 | } | ||
205 | |||
206 | static void __set_gpio_level_p3(struct lpc32xx_gpio_chip *group, | ||
207 | unsigned pin, int high) | ||
208 | { | ||
209 | u32 u = GPIO3_PIN_TO_BIT(pin); | ||
210 | |||
211 | if (high) | ||
212 | __raw_writel(u, group->gpio_grp->outp_set); | ||
213 | else | ||
214 | __raw_writel(u, group->gpio_grp->outp_clr); | ||
215 | } | ||
216 | |||
217 | static void __set_gpo_level_p3(struct lpc32xx_gpio_chip *group, | ||
218 | unsigned pin, int high) | ||
219 | { | ||
220 | if (high) | ||
221 | __raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_set); | ||
222 | else | ||
223 | __raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_clr); | ||
224 | } | ||
225 | |||
226 | static int __get_gpio_state_p012(struct lpc32xx_gpio_chip *group, | ||
227 | unsigned pin) | ||
228 | { | ||
229 | return GPIO012_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state), | ||
230 | pin); | ||
231 | } | ||
232 | |||
233 | static int __get_gpio_state_p3(struct lpc32xx_gpio_chip *group, | ||
234 | unsigned pin) | ||
235 | { | ||
236 | int state = __raw_readl(group->gpio_grp->inp_state); | ||
237 | |||
238 | /* | ||
239 | * P3 GPIO pin input mapping is not contiguous, GPIOP3-0..4 is mapped | ||
240 | * to bits 10..14, while GPIOP3-5 is mapped to bit 24. | ||
241 | */ | ||
242 | return GPIO3_PIN_IN_SEL(state, pin); | ||
243 | } | ||
244 | |||
245 | static int __get_gpi_state_p3(struct lpc32xx_gpio_chip *group, | ||
246 | unsigned pin) | ||
247 | { | ||
248 | return GPI3_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state), pin); | ||
249 | } | ||
250 | |||
251 | static int __get_gpo_state_p3(struct lpc32xx_gpio_chip *group, | ||
252 | unsigned pin) | ||
253 | { | ||
254 | return GPO3_PIN_IN_SEL(__raw_readl(group->gpio_grp->outp_state), pin); | ||
255 | } | ||
256 | |||
257 | /* | ||
258 | * GENERIC_GPIO primitives. | ||
259 | */ | ||
260 | static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip, | ||
261 | unsigned pin) | ||
262 | { | ||
263 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
264 | |||
265 | __set_gpio_dir_p012(group, pin, 1); | ||
266 | |||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | static int lpc32xx_gpio_dir_input_p3(struct gpio_chip *chip, | ||
271 | unsigned pin) | ||
272 | { | ||
273 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
274 | |||
275 | __set_gpio_dir_p3(group, pin, 1); | ||
276 | |||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | static int lpc32xx_gpio_dir_in_always(struct gpio_chip *chip, | ||
281 | unsigned pin) | ||
282 | { | ||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin) | ||
287 | { | ||
288 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
289 | |||
290 | return __get_gpio_state_p012(group, pin); | ||
291 | } | ||
292 | |||
293 | static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin) | ||
294 | { | ||
295 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
296 | |||
297 | return __get_gpio_state_p3(group, pin); | ||
298 | } | ||
299 | |||
300 | static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin) | ||
301 | { | ||
302 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
303 | |||
304 | return __get_gpi_state_p3(group, pin); | ||
305 | } | ||
306 | |||
307 | static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin, | ||
308 | int value) | ||
309 | { | ||
310 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
311 | |||
312 | __set_gpio_level_p012(group, pin, value); | ||
313 | __set_gpio_dir_p012(group, pin, 0); | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin, | ||
319 | int value) | ||
320 | { | ||
321 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
322 | |||
323 | __set_gpio_level_p3(group, pin, value); | ||
324 | __set_gpio_dir_p3(group, pin, 0); | ||
325 | |||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin, | ||
330 | int value) | ||
331 | { | ||
332 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
333 | |||
334 | __set_gpo_level_p3(group, pin, value); | ||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin, | ||
339 | int value) | ||
340 | { | ||
341 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
342 | |||
343 | __set_gpio_level_p012(group, pin, value); | ||
344 | } | ||
345 | |||
346 | static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin, | ||
347 | int value) | ||
348 | { | ||
349 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
350 | |||
351 | __set_gpio_level_p3(group, pin, value); | ||
352 | } | ||
353 | |||
354 | static void lpc32xx_gpo_set_value(struct gpio_chip *chip, unsigned pin, | ||
355 | int value) | ||
356 | { | ||
357 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
358 | |||
359 | __set_gpo_level_p3(group, pin, value); | ||
360 | } | ||
361 | |||
362 | static int lpc32xx_gpo_get_value(struct gpio_chip *chip, unsigned pin) | ||
363 | { | ||
364 | struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip); | ||
365 | |||
366 | return __get_gpo_state_p3(group, pin); | ||
367 | } | ||
368 | |||
369 | static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin) | ||
370 | { | ||
371 | if (pin < chip->ngpio) | ||
372 | return 0; | ||
373 | |||
374 | return -EINVAL; | ||
375 | } | ||
376 | |||
377 | static int lpc32xx_gpio_to_irq_p01(struct gpio_chip *chip, unsigned offset) | ||
378 | { | ||
379 | return IRQ_LPC32XX_P0_P1_IRQ; | ||
380 | } | ||
381 | |||
382 | static const char lpc32xx_gpio_to_irq_gpio_p3_table[] = { | ||
383 | IRQ_LPC32XX_GPIO_00, | ||
384 | IRQ_LPC32XX_GPIO_01, | ||
385 | IRQ_LPC32XX_GPIO_02, | ||
386 | IRQ_LPC32XX_GPIO_03, | ||
387 | IRQ_LPC32XX_GPIO_04, | ||
388 | IRQ_LPC32XX_GPIO_05, | ||
389 | }; | ||
390 | |||
391 | static int lpc32xx_gpio_to_irq_gpio_p3(struct gpio_chip *chip, unsigned offset) | ||
392 | { | ||
393 | if (offset < ARRAY_SIZE(lpc32xx_gpio_to_irq_gpio_p3_table)) | ||
394 | return lpc32xx_gpio_to_irq_gpio_p3_table[offset]; | ||
395 | return -ENXIO; | ||
396 | } | ||
397 | |||
398 | static const char lpc32xx_gpio_to_irq_gpi_p3_table[] = { | ||
399 | IRQ_LPC32XX_GPI_00, | ||
400 | IRQ_LPC32XX_GPI_01, | ||
401 | IRQ_LPC32XX_GPI_02, | ||
402 | IRQ_LPC32XX_GPI_03, | ||
403 | IRQ_LPC32XX_GPI_04, | ||
404 | IRQ_LPC32XX_GPI_05, | ||
405 | IRQ_LPC32XX_GPI_06, | ||
406 | IRQ_LPC32XX_GPI_07, | ||
407 | IRQ_LPC32XX_GPI_08, | ||
408 | IRQ_LPC32XX_GPI_09, | ||
409 | -ENXIO, /* 10 */ | ||
410 | -ENXIO, /* 11 */ | ||
411 | -ENXIO, /* 12 */ | ||
412 | -ENXIO, /* 13 */ | ||
413 | -ENXIO, /* 14 */ | ||
414 | -ENXIO, /* 15 */ | ||
415 | -ENXIO, /* 16 */ | ||
416 | -ENXIO, /* 17 */ | ||
417 | -ENXIO, /* 18 */ | ||
418 | IRQ_LPC32XX_GPI_19, | ||
419 | -ENXIO, /* 20 */ | ||
420 | -ENXIO, /* 21 */ | ||
421 | -ENXIO, /* 22 */ | ||
422 | -ENXIO, /* 23 */ | ||
423 | -ENXIO, /* 24 */ | ||
424 | -ENXIO, /* 25 */ | ||
425 | -ENXIO, /* 26 */ | ||
426 | -ENXIO, /* 27 */ | ||
427 | IRQ_LPC32XX_GPI_28, | ||
428 | }; | ||
429 | |||
430 | static int lpc32xx_gpio_to_irq_gpi_p3(struct gpio_chip *chip, unsigned offset) | ||
431 | { | ||
432 | if (offset < ARRAY_SIZE(lpc32xx_gpio_to_irq_gpi_p3_table)) | ||
433 | return lpc32xx_gpio_to_irq_gpi_p3_table[offset]; | ||
434 | return -ENXIO; | ||
435 | } | ||
436 | |||
437 | static struct lpc32xx_gpio_chip lpc32xx_gpiochip[] = { | ||
438 | { | ||
439 | .chip = { | ||
440 | .label = "gpio_p0", | ||
441 | .direction_input = lpc32xx_gpio_dir_input_p012, | ||
442 | .get = lpc32xx_gpio_get_value_p012, | ||
443 | .direction_output = lpc32xx_gpio_dir_output_p012, | ||
444 | .set = lpc32xx_gpio_set_value_p012, | ||
445 | .request = lpc32xx_gpio_request, | ||
446 | .to_irq = lpc32xx_gpio_to_irq_p01, | ||
447 | .base = LPC32XX_GPIO_P0_GRP, | ||
448 | .ngpio = LPC32XX_GPIO_P0_MAX, | ||
449 | .names = gpio_p0_names, | ||
450 | .can_sleep = 0, | ||
451 | }, | ||
452 | .gpio_grp = &gpio_grp_regs_p0, | ||
453 | }, | ||
454 | { | ||
455 | .chip = { | ||
456 | .label = "gpio_p1", | ||
457 | .direction_input = lpc32xx_gpio_dir_input_p012, | ||
458 | .get = lpc32xx_gpio_get_value_p012, | ||
459 | .direction_output = lpc32xx_gpio_dir_output_p012, | ||
460 | .set = lpc32xx_gpio_set_value_p012, | ||
461 | .request = lpc32xx_gpio_request, | ||
462 | .to_irq = lpc32xx_gpio_to_irq_p01, | ||
463 | .base = LPC32XX_GPIO_P1_GRP, | ||
464 | .ngpio = LPC32XX_GPIO_P1_MAX, | ||
465 | .names = gpio_p1_names, | ||
466 | .can_sleep = 0, | ||
467 | }, | ||
468 | .gpio_grp = &gpio_grp_regs_p1, | ||
469 | }, | ||
470 | { | ||
471 | .chip = { | ||
472 | .label = "gpio_p2", | ||
473 | .direction_input = lpc32xx_gpio_dir_input_p012, | ||
474 | .get = lpc32xx_gpio_get_value_p012, | ||
475 | .direction_output = lpc32xx_gpio_dir_output_p012, | ||
476 | .set = lpc32xx_gpio_set_value_p012, | ||
477 | .request = lpc32xx_gpio_request, | ||
478 | .base = LPC32XX_GPIO_P2_GRP, | ||
479 | .ngpio = LPC32XX_GPIO_P2_MAX, | ||
480 | .names = gpio_p2_names, | ||
481 | .can_sleep = 0, | ||
482 | }, | ||
483 | .gpio_grp = &gpio_grp_regs_p2, | ||
484 | }, | ||
485 | { | ||
486 | .chip = { | ||
487 | .label = "gpio_p3", | ||
488 | .direction_input = lpc32xx_gpio_dir_input_p3, | ||
489 | .get = lpc32xx_gpio_get_value_p3, | ||
490 | .direction_output = lpc32xx_gpio_dir_output_p3, | ||
491 | .set = lpc32xx_gpio_set_value_p3, | ||
492 | .request = lpc32xx_gpio_request, | ||
493 | .to_irq = lpc32xx_gpio_to_irq_gpio_p3, | ||
494 | .base = LPC32XX_GPIO_P3_GRP, | ||
495 | .ngpio = LPC32XX_GPIO_P3_MAX, | ||
496 | .names = gpio_p3_names, | ||
497 | .can_sleep = 0, | ||
498 | }, | ||
499 | .gpio_grp = &gpio_grp_regs_p3, | ||
500 | }, | ||
501 | { | ||
502 | .chip = { | ||
503 | .label = "gpi_p3", | ||
504 | .direction_input = lpc32xx_gpio_dir_in_always, | ||
505 | .get = lpc32xx_gpi_get_value, | ||
506 | .request = lpc32xx_gpio_request, | ||
507 | .to_irq = lpc32xx_gpio_to_irq_gpi_p3, | ||
508 | .base = LPC32XX_GPI_P3_GRP, | ||
509 | .ngpio = LPC32XX_GPI_P3_MAX, | ||
510 | .names = gpi_p3_names, | ||
511 | .can_sleep = 0, | ||
512 | }, | ||
513 | .gpio_grp = &gpio_grp_regs_p3, | ||
514 | }, | ||
515 | { | ||
516 | .chip = { | ||
517 | .label = "gpo_p3", | ||
518 | .direction_output = lpc32xx_gpio_dir_out_always, | ||
519 | .set = lpc32xx_gpo_set_value, | ||
520 | .get = lpc32xx_gpo_get_value, | ||
521 | .request = lpc32xx_gpio_request, | ||
522 | .base = LPC32XX_GPO_P3_GRP, | ||
523 | .ngpio = LPC32XX_GPO_P3_MAX, | ||
524 | .names = gpo_p3_names, | ||
525 | .can_sleep = 0, | ||
526 | }, | ||
527 | .gpio_grp = &gpio_grp_regs_p3, | ||
528 | }, | ||
529 | }; | ||
530 | |||
531 | static int lpc32xx_of_xlate(struct gpio_chip *gc, | ||
532 | const struct of_phandle_args *gpiospec, u32 *flags) | ||
533 | { | ||
534 | /* Is this the correct bank? */ | ||
535 | u32 bank = gpiospec->args[0]; | ||
536 | if ((bank > ARRAY_SIZE(lpc32xx_gpiochip) || | ||
537 | (gc != &lpc32xx_gpiochip[bank].chip))) | ||
538 | return -EINVAL; | ||
539 | |||
540 | if (flags) | ||
541 | *flags = gpiospec->args[2]; | ||
542 | return gpiospec->args[1]; | ||
543 | } | ||
544 | |||
545 | static int lpc32xx_gpio_probe(struct platform_device *pdev) | ||
546 | { | ||
547 | int i; | ||
548 | |||
549 | for (i = 0; i < ARRAY_SIZE(lpc32xx_gpiochip); i++) { | ||
550 | if (pdev->dev.of_node) { | ||
551 | lpc32xx_gpiochip[i].chip.of_xlate = lpc32xx_of_xlate; | ||
552 | lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3; | ||
553 | lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node; | ||
554 | } | ||
555 | gpiochip_add(&lpc32xx_gpiochip[i].chip); | ||
556 | } | ||
557 | |||
558 | return 0; | ||
559 | } | ||
560 | |||
561 | #ifdef CONFIG_OF | ||
562 | static struct of_device_id lpc32xx_gpio_of_match[] = { | ||
563 | { .compatible = "nxp,lpc3220-gpio", }, | ||
564 | { }, | ||
565 | }; | ||
566 | #endif | ||
567 | |||
568 | static struct platform_driver lpc32xx_gpio_driver = { | ||
569 | .driver = { | ||
570 | .name = "lpc32xx-gpio", | ||
571 | .owner = THIS_MODULE, | ||
572 | .of_match_table = of_match_ptr(lpc32xx_gpio_of_match), | ||
573 | }, | ||
574 | .probe = lpc32xx_gpio_probe, | ||
575 | }; | ||
576 | |||
577 | module_platform_driver(lpc32xx_gpio_driver); | ||
diff --git a/drivers/gpio/gpio-max7300.c b/drivers/gpio/gpio-max7300.c index 4b6b9a04e32..a5ca0ab1b37 100644 --- a/drivers/gpio/gpio-max7300.c +++ b/drivers/gpio/gpio-max7300.c | |||
@@ -31,7 +31,7 @@ static int max7300_i2c_read(struct device *dev, unsigned int reg) | |||
31 | return i2c_smbus_read_byte_data(client, reg); | 31 | return i2c_smbus_read_byte_data(client, reg); |
32 | } | 32 | } |
33 | 33 | ||
34 | static int max7300_probe(struct i2c_client *client, | 34 | static int __devinit max7300_probe(struct i2c_client *client, |
35 | const struct i2c_device_id *id) | 35 | const struct i2c_device_id *id) |
36 | { | 36 | { |
37 | struct max7301 *ts; | 37 | struct max7301 *ts; |
@@ -55,7 +55,7 @@ static int max7300_probe(struct i2c_client *client, | |||
55 | return ret; | 55 | return ret; |
56 | } | 56 | } |
57 | 57 | ||
58 | static int max7300_remove(struct i2c_client *client) | 58 | static int __devexit max7300_remove(struct i2c_client *client) |
59 | { | 59 | { |
60 | return __max730x_remove(&client->dev); | 60 | return __max730x_remove(&client->dev); |
61 | } | 61 | } |
@@ -72,7 +72,7 @@ static struct i2c_driver max7300_driver = { | |||
72 | .owner = THIS_MODULE, | 72 | .owner = THIS_MODULE, |
73 | }, | 73 | }, |
74 | .probe = max7300_probe, | 74 | .probe = max7300_probe, |
75 | .remove = max7300_remove, | 75 | .remove = __devexit_p(max7300_remove), |
76 | .id_table = max7300_id, | 76 | .id_table = max7300_id, |
77 | }; | 77 | }; |
78 | 78 | ||
diff --git a/drivers/gpio/gpio-max7301.c b/drivers/gpio/gpio-max7301.c index c6c535c1310..741acfcbe76 100644 --- a/drivers/gpio/gpio-max7301.c +++ b/drivers/gpio/gpio-max7301.c | |||
@@ -50,7 +50,7 @@ static int max7301_spi_read(struct device *dev, unsigned int reg) | |||
50 | return word & 0xff; | 50 | return word & 0xff; |
51 | } | 51 | } |
52 | 52 | ||
53 | static int max7301_probe(struct spi_device *spi) | 53 | static int __devinit max7301_probe(struct spi_device *spi) |
54 | { | 54 | { |
55 | struct max7301 *ts; | 55 | struct max7301 *ts; |
56 | int ret; | 56 | int ret; |
@@ -75,7 +75,7 @@ static int max7301_probe(struct spi_device *spi) | |||
75 | return ret; | 75 | return ret; |
76 | } | 76 | } |
77 | 77 | ||
78 | static int max7301_remove(struct spi_device *spi) | 78 | static int __devexit max7301_remove(struct spi_device *spi) |
79 | { | 79 | { |
80 | return __max730x_remove(&spi->dev); | 80 | return __max730x_remove(&spi->dev); |
81 | } | 81 | } |
@@ -92,7 +92,7 @@ static struct spi_driver max7301_driver = { | |||
92 | .owner = THIS_MODULE, | 92 | .owner = THIS_MODULE, |
93 | }, | 93 | }, |
94 | .probe = max7301_probe, | 94 | .probe = max7301_probe, |
95 | .remove = max7301_remove, | 95 | .remove = __devexit_p(max7301_remove), |
96 | .id_table = max7301_id, | 96 | .id_table = max7301_id, |
97 | }; | 97 | }; |
98 | 98 | ||
diff --git a/drivers/gpio/gpio-max730x.c b/drivers/gpio/gpio-max730x.c index 00092342b84..05e2dac60b3 100644 --- a/drivers/gpio/gpio-max730x.c +++ b/drivers/gpio/gpio-max730x.c | |||
@@ -160,13 +160,17 @@ static void max7301_set(struct gpio_chip *chip, unsigned offset, int value) | |||
160 | mutex_unlock(&ts->lock); | 160 | mutex_unlock(&ts->lock); |
161 | } | 161 | } |
162 | 162 | ||
163 | int __max730x_probe(struct max7301 *ts) | 163 | int __devinit __max730x_probe(struct max7301 *ts) |
164 | { | 164 | { |
165 | struct device *dev = ts->dev; | 165 | struct device *dev = ts->dev; |
166 | struct max7301_platform_data *pdata; | 166 | struct max7301_platform_data *pdata; |
167 | int i, ret; | 167 | int i, ret; |
168 | 168 | ||
169 | pdata = dev->platform_data; | 169 | pdata = dev->platform_data; |
170 | if (!pdata || !pdata->base) { | ||
171 | dev_err(dev, "incorrect or missing platform data\n"); | ||
172 | return -EINVAL; | ||
173 | } | ||
170 | 174 | ||
171 | mutex_init(&ts->lock); | 175 | mutex_init(&ts->lock); |
172 | dev_set_drvdata(dev, ts); | 176 | dev_set_drvdata(dev, ts); |
@@ -174,12 +178,7 @@ int __max730x_probe(struct max7301 *ts) | |||
174 | /* Power up the chip and disable IRQ output */ | 178 | /* Power up the chip and disable IRQ output */ |
175 | ts->write(dev, 0x04, 0x01); | 179 | ts->write(dev, 0x04, 0x01); |
176 | 180 | ||
177 | if (pdata) { | 181 | ts->input_pullup_active = pdata->input_pullup_active; |
178 | ts->input_pullup_active = pdata->input_pullup_active; | ||
179 | ts->chip.base = pdata->base; | ||
180 | } else { | ||
181 | ts->chip.base = -1; | ||
182 | } | ||
183 | ts->chip.label = dev->driver->name; | 182 | ts->chip.label = dev->driver->name; |
184 | 183 | ||
185 | ts->chip.direction_input = max7301_direction_input; | 184 | ts->chip.direction_input = max7301_direction_input; |
@@ -187,6 +186,7 @@ int __max730x_probe(struct max7301 *ts) | |||
187 | ts->chip.direction_output = max7301_direction_output; | 186 | ts->chip.direction_output = max7301_direction_output; |
188 | ts->chip.set = max7301_set; | 187 | ts->chip.set = max7301_set; |
189 | 188 | ||
189 | ts->chip.base = pdata->base; | ||
190 | ts->chip.ngpio = PIN_NUMBER; | 190 | ts->chip.ngpio = PIN_NUMBER; |
191 | ts->chip.can_sleep = 1; | 191 | ts->chip.can_sleep = 1; |
192 | ts->chip.dev = dev; | 192 | ts->chip.dev = dev; |
@@ -226,7 +226,7 @@ exit_destroy: | |||
226 | } | 226 | } |
227 | EXPORT_SYMBOL_GPL(__max730x_probe); | 227 | EXPORT_SYMBOL_GPL(__max730x_probe); |
228 | 228 | ||
229 | int __max730x_remove(struct device *dev) | 229 | int __devexit __max730x_remove(struct device *dev) |
230 | { | 230 | { |
231 | struct max7301 *ts = dev_get_drvdata(dev); | 231 | struct max7301 *ts = dev_get_drvdata(dev); |
232 | int ret; | 232 | int ret; |
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c index 1e0467ce4c3..9504120812a 100644 --- a/drivers/gpio/gpio-max732x.c +++ b/drivers/gpio/gpio-max732x.c | |||
@@ -526,7 +526,7 @@ static void max732x_irq_teardown(struct max732x_chip *chip) | |||
526 | } | 526 | } |
527 | #endif | 527 | #endif |
528 | 528 | ||
529 | static int max732x_setup_gpio(struct max732x_chip *chip, | 529 | static int __devinit max732x_setup_gpio(struct max732x_chip *chip, |
530 | const struct i2c_device_id *id, | 530 | const struct i2c_device_id *id, |
531 | unsigned gpio_start) | 531 | unsigned gpio_start) |
532 | { | 532 | { |
@@ -574,7 +574,7 @@ static int max732x_setup_gpio(struct max732x_chip *chip, | |||
574 | return port; | 574 | return port; |
575 | } | 575 | } |
576 | 576 | ||
577 | static int max732x_probe(struct i2c_client *client, | 577 | static int __devinit max732x_probe(struct i2c_client *client, |
578 | const struct i2c_device_id *id) | 578 | const struct i2c_device_id *id) |
579 | { | 579 | { |
580 | struct max732x_platform_data *pdata; | 580 | struct max732x_platform_data *pdata; |
@@ -651,7 +651,7 @@ out_failed: | |||
651 | return ret; | 651 | return ret; |
652 | } | 652 | } |
653 | 653 | ||
654 | static int max732x_remove(struct i2c_client *client) | 654 | static int __devexit max732x_remove(struct i2c_client *client) |
655 | { | 655 | { |
656 | struct max732x_platform_data *pdata = client->dev.platform_data; | 656 | struct max732x_platform_data *pdata = client->dev.platform_data; |
657 | struct max732x_chip *chip = i2c_get_clientdata(client); | 657 | struct max732x_chip *chip = i2c_get_clientdata(client); |
@@ -690,7 +690,7 @@ static struct i2c_driver max732x_driver = { | |||
690 | .owner = THIS_MODULE, | 690 | .owner = THIS_MODULE, |
691 | }, | 691 | }, |
692 | .probe = max732x_probe, | 692 | .probe = max732x_probe, |
693 | .remove = max732x_remove, | 693 | .remove = __devexit_p(max732x_remove), |
694 | .id_table = max732x_id, | 694 | .id_table = max732x_id, |
695 | }; | 695 | }; |
696 | 696 | ||
diff --git a/drivers/gpio/gpio-mc33880.c b/drivers/gpio/gpio-mc33880.c index 6a8fdc26ae6..b3b4652e89e 100644 --- a/drivers/gpio/gpio-mc33880.c +++ b/drivers/gpio/gpio-mc33880.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <linux/spi/mc33880.h> | 26 | #include <linux/spi/mc33880.h> |
27 | #include <linux/gpio.h> | 27 | #include <linux/gpio.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/module.h> | ||
30 | 29 | ||
31 | #define DRIVER_NAME "mc33880" | 30 | #define DRIVER_NAME "mc33880" |
32 | 31 | ||
@@ -80,7 +79,7 @@ static void mc33880_set(struct gpio_chip *chip, unsigned offset, int value) | |||
80 | mutex_unlock(&mc->lock); | 79 | mutex_unlock(&mc->lock); |
81 | } | 80 | } |
82 | 81 | ||
83 | static int mc33880_probe(struct spi_device *spi) | 82 | static int __devinit mc33880_probe(struct spi_device *spi) |
84 | { | 83 | { |
85 | struct mc33880 *mc; | 84 | struct mc33880 *mc; |
86 | struct mc33880_platform_data *pdata; | 85 | struct mc33880_platform_data *pdata; |
@@ -147,7 +146,7 @@ exit_destroy: | |||
147 | return ret; | 146 | return ret; |
148 | } | 147 | } |
149 | 148 | ||
150 | static int mc33880_remove(struct spi_device *spi) | 149 | static int __devexit mc33880_remove(struct spi_device *spi) |
151 | { | 150 | { |
152 | struct mc33880 *mc; | 151 | struct mc33880 *mc; |
153 | int ret; | 152 | int ret; |
@@ -175,7 +174,7 @@ static struct spi_driver mc33880_driver = { | |||
175 | .owner = THIS_MODULE, | 174 | .owner = THIS_MODULE, |
176 | }, | 175 | }, |
177 | .probe = mc33880_probe, | 176 | .probe = mc33880_probe, |
178 | .remove = mc33880_remove, | 177 | .remove = __devexit_p(mc33880_remove), |
179 | }; | 178 | }; |
180 | 179 | ||
181 | static int __init mc33880_init(void) | 180 | static int __init mc33880_init(void) |
diff --git a/drivers/gpio/gpio-mc9s08dz60.c b/drivers/gpio/gpio-mc9s08dz60.c deleted file mode 100644 index 0ab700046a2..00000000000 --- a/drivers/gpio/gpio-mc9s08dz60.c +++ /dev/null | |||
@@ -1,146 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright 2009-2012 Freescale Semiconductor, Inc. All Rights Reserved. | ||
3 | * | ||
4 | * Author: Wu Guoxing <b39297@freescale.com> | ||
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 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/i2c.h> | ||
21 | #include <linux/gpio.h> | ||
22 | |||
23 | #define GPIO_GROUP_NUM 2 | ||
24 | #define GPIO_NUM_PER_GROUP 8 | ||
25 | #define GPIO_NUM (GPIO_GROUP_NUM*GPIO_NUM_PER_GROUP) | ||
26 | |||
27 | struct mc9s08dz60 { | ||
28 | struct i2c_client *client; | ||
29 | struct gpio_chip chip; | ||
30 | }; | ||
31 | |||
32 | static inline struct mc9s08dz60 *to_mc9s08dz60(struct gpio_chip *gc) | ||
33 | { | ||
34 | return container_of(gc, struct mc9s08dz60, chip); | ||
35 | } | ||
36 | |||
37 | |||
38 | static void mc9s_gpio_to_reg_and_bit(int offset, u8 *reg, u8 *bit) | ||
39 | { | ||
40 | *reg = 0x20 + offset / GPIO_NUM_PER_GROUP; | ||
41 | *bit = offset % GPIO_NUM_PER_GROUP; | ||
42 | } | ||
43 | |||
44 | static int mc9s08dz60_get_value(struct gpio_chip *gc, unsigned offset) | ||
45 | { | ||
46 | u8 reg, bit; | ||
47 | s32 value; | ||
48 | struct mc9s08dz60 *mc9s = to_mc9s08dz60(gc); | ||
49 | |||
50 | mc9s_gpio_to_reg_and_bit(offset, ®, &bit); | ||
51 | value = i2c_smbus_read_byte_data(mc9s->client, reg); | ||
52 | |||
53 | return (value >= 0) ? (value >> bit) & 0x1 : 0; | ||
54 | } | ||
55 | |||
56 | static int mc9s08dz60_set(struct mc9s08dz60 *mc9s, unsigned offset, int val) | ||
57 | { | ||
58 | u8 reg, bit; | ||
59 | s32 value; | ||
60 | |||
61 | mc9s_gpio_to_reg_and_bit(offset, ®, &bit); | ||
62 | value = i2c_smbus_read_byte_data(mc9s->client, reg); | ||
63 | if (value >= 0) { | ||
64 | if (val) | ||
65 | value |= 1 << bit; | ||
66 | else | ||
67 | value &= ~(1 << bit); | ||
68 | |||
69 | return i2c_smbus_write_byte_data(mc9s->client, reg, value); | ||
70 | } else | ||
71 | return value; | ||
72 | |||
73 | } | ||
74 | |||
75 | |||
76 | static void mc9s08dz60_set_value(struct gpio_chip *gc, unsigned offset, int val) | ||
77 | { | ||
78 | struct mc9s08dz60 *mc9s = to_mc9s08dz60(gc); | ||
79 | |||
80 | mc9s08dz60_set(mc9s, offset, val); | ||
81 | } | ||
82 | |||
83 | static int mc9s08dz60_direction_output(struct gpio_chip *gc, | ||
84 | unsigned offset, int val) | ||
85 | { | ||
86 | struct mc9s08dz60 *mc9s = to_mc9s08dz60(gc); | ||
87 | |||
88 | return mc9s08dz60_set(mc9s, offset, val); | ||
89 | } | ||
90 | |||
91 | static int mc9s08dz60_probe(struct i2c_client *client, | ||
92 | const struct i2c_device_id *id) | ||
93 | { | ||
94 | struct mc9s08dz60 *mc9s; | ||
95 | |||
96 | mc9s = devm_kzalloc(&client->dev, sizeof(*mc9s), GFP_KERNEL); | ||
97 | if (!mc9s) | ||
98 | return -ENOMEM; | ||
99 | |||
100 | mc9s->chip.label = client->name; | ||
101 | mc9s->chip.base = -1; | ||
102 | mc9s->chip.dev = &client->dev; | ||
103 | mc9s->chip.owner = THIS_MODULE; | ||
104 | mc9s->chip.ngpio = GPIO_NUM; | ||
105 | mc9s->chip.can_sleep = 1; | ||
106 | mc9s->chip.get = mc9s08dz60_get_value; | ||
107 | mc9s->chip.set = mc9s08dz60_set_value; | ||
108 | mc9s->chip.direction_output = mc9s08dz60_direction_output; | ||
109 | mc9s->client = client; | ||
110 | i2c_set_clientdata(client, mc9s); | ||
111 | |||
112 | return gpiochip_add(&mc9s->chip); | ||
113 | } | ||
114 | |||
115 | static int mc9s08dz60_remove(struct i2c_client *client) | ||
116 | { | ||
117 | struct mc9s08dz60 *mc9s; | ||
118 | |||
119 | mc9s = i2c_get_clientdata(client); | ||
120 | |||
121 | return gpiochip_remove(&mc9s->chip); | ||
122 | } | ||
123 | |||
124 | static const struct i2c_device_id mc9s08dz60_id[] = { | ||
125 | {"mc9s08dz60", 0}, | ||
126 | {}, | ||
127 | }; | ||
128 | |||
129 | MODULE_DEVICE_TABLE(i2c, mc9s08dz60_id); | ||
130 | |||
131 | static struct i2c_driver mc9s08dz60_i2c_driver = { | ||
132 | .driver = { | ||
133 | .owner = THIS_MODULE, | ||
134 | .name = "mc9s08dz60", | ||
135 | }, | ||
136 | .probe = mc9s08dz60_probe, | ||
137 | .remove = mc9s08dz60_remove, | ||
138 | .id_table = mc9s08dz60_id, | ||
139 | }; | ||
140 | |||
141 | module_i2c_driver(mc9s08dz60_i2c_driver); | ||
142 | |||
143 | MODULE_AUTHOR("Freescale Semiconductor, Inc. " | ||
144 | "Wu Guoxing <b39297@freescale.com>"); | ||
145 | MODULE_DESCRIPTION("mc9s08dz60 gpio function on mx35 3ds board"); | ||
146 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c index 3cea0ea79e8..1ef46e6c2a2 100644 --- a/drivers/gpio/gpio-mcp23s08.c +++ b/drivers/gpio/gpio-mcp23s08.c | |||
@@ -5,7 +5,6 @@ | |||
5 | #include <linux/kernel.h> | 5 | #include <linux/kernel.h> |
6 | #include <linux/device.h> | 6 | #include <linux/device.h> |
7 | #include <linux/mutex.h> | 7 | #include <linux/mutex.h> |
8 | #include <linux/module.h> | ||
9 | #include <linux/gpio.h> | 8 | #include <linux/gpio.h> |
10 | #include <linux/i2c.h> | 9 | #include <linux/i2c.h> |
11 | #include <linux/spi/spi.h> | 10 | #include <linux/spi/spi.h> |
@@ -77,7 +76,7 @@ struct mcp23s08_driver_data { | |||
77 | 76 | ||
78 | /*----------------------------------------------------------------------*/ | 77 | /*----------------------------------------------------------------------*/ |
79 | 78 | ||
80 | #if IS_ENABLED(CONFIG_I2C) | 79 | #ifdef CONFIG_I2C |
81 | 80 | ||
82 | static int mcp23008_read(struct mcp23s08 *mcp, unsigned reg) | 81 | static int mcp23008_read(struct mcp23s08 *mcp, unsigned reg) |
83 | { | 82 | { |
@@ -353,7 +352,7 @@ static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip) | |||
353 | chip->base + t, bank, t, label, | 352 | chip->base + t, bank, t, label, |
354 | (mcp->cache[MCP_IODIR] & mask) ? "in " : "out", | 353 | (mcp->cache[MCP_IODIR] & mask) ? "in " : "out", |
355 | (mcp->cache[MCP_GPIO] & mask) ? "hi" : "lo", | 354 | (mcp->cache[MCP_GPIO] & mask) ? "hi" : "lo", |
356 | (mcp->cache[MCP_GPPU] & mask) ? "up" : " "); | 355 | (mcp->cache[MCP_GPPU] & mask) ? " " : "up"); |
357 | /* NOTE: ignoring the irq-related registers */ | 356 | /* NOTE: ignoring the irq-related registers */ |
358 | seq_printf(s, "\n"); | 357 | seq_printf(s, "\n"); |
359 | } | 358 | } |
@@ -399,7 +398,7 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, | |||
399 | break; | 398 | break; |
400 | #endif /* CONFIG_SPI_MASTER */ | 399 | #endif /* CONFIG_SPI_MASTER */ |
401 | 400 | ||
402 | #if IS_ENABLED(CONFIG_I2C) | 401 | #ifdef CONFIG_I2C |
403 | case MCP_TYPE_008: | 402 | case MCP_TYPE_008: |
404 | mcp->ops = &mcp23008_ops; | 403 | mcp->ops = &mcp23008_ops; |
405 | mcp->chip.ngpio = 8; | 404 | mcp->chip.ngpio = 8; |
@@ -473,9 +472,9 @@ fail: | |||
473 | 472 | ||
474 | /*----------------------------------------------------------------------*/ | 473 | /*----------------------------------------------------------------------*/ |
475 | 474 | ||
476 | #if IS_ENABLED(CONFIG_I2C) | 475 | #ifdef CONFIG_I2C |
477 | 476 | ||
478 | static int mcp230xx_probe(struct i2c_client *client, | 477 | static int __devinit mcp230xx_probe(struct i2c_client *client, |
479 | const struct i2c_device_id *id) | 478 | const struct i2c_device_id *id) |
480 | { | 479 | { |
481 | struct mcp23s08_platform_data *pdata; | 480 | struct mcp23s08_platform_data *pdata; |
@@ -508,7 +507,7 @@ fail: | |||
508 | return status; | 507 | return status; |
509 | } | 508 | } |
510 | 509 | ||
511 | static int mcp230xx_remove(struct i2c_client *client) | 510 | static int __devexit mcp230xx_remove(struct i2c_client *client) |
512 | { | 511 | { |
513 | struct mcp23s08 *mcp = i2c_get_clientdata(client); | 512 | struct mcp23s08 *mcp = i2c_get_clientdata(client); |
514 | int status; | 513 | int status; |
@@ -533,7 +532,7 @@ static struct i2c_driver mcp230xx_driver = { | |||
533 | .owner = THIS_MODULE, | 532 | .owner = THIS_MODULE, |
534 | }, | 533 | }, |
535 | .probe = mcp230xx_probe, | 534 | .probe = mcp230xx_probe, |
536 | .remove = mcp230xx_remove, | 535 | .remove = __devexit_p(mcp230xx_remove), |
537 | .id_table = mcp230xx_id, | 536 | .id_table = mcp230xx_id, |
538 | }; | 537 | }; |
539 | 538 | ||
diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c index b73366523fa..a9016f56ed7 100644 --- a/drivers/gpio/gpio-ml-ioh.c +++ b/drivers/gpio/gpio-ml-ioh.c | |||
@@ -14,22 +14,10 @@ | |||
14 | * along with this program; if not, write to the Free Software | 14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
16 | */ | 16 | */ |
17 | #include <linux/module.h> | ||
18 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
19 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
20 | #include <linux/pci.h> | 19 | #include <linux/pci.h> |
21 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/irq.h> | ||
24 | |||
25 | #define IOH_EDGE_FALLING 0 | ||
26 | #define IOH_EDGE_RISING BIT(0) | ||
27 | #define IOH_LEVEL_L BIT(1) | ||
28 | #define IOH_LEVEL_H (BIT(0) | BIT(1)) | ||
29 | #define IOH_EDGE_BOTH BIT(2) | ||
30 | #define IOH_IM_MASK (BIT(0) | BIT(1) | BIT(2)) | ||
31 | |||
32 | #define IOH_IRQ_BASE 0 | ||
33 | 21 | ||
34 | #define PCI_VENDOR_ID_ROHM 0x10DB | 22 | #define PCI_VENDOR_ID_ROHM 0x10DB |
35 | 23 | ||
@@ -58,22 +46,12 @@ struct ioh_regs { | |||
58 | 46 | ||
59 | /** | 47 | /** |
60 | * struct ioh_gpio_reg_data - The register store data. | 48 | * struct ioh_gpio_reg_data - The register store data. |
61 | * @ien_reg To store contents of interrupt enable register. | ||
62 | * @imask_reg: To store contents of interrupt mask regist | ||
63 | * @po_reg: To store contents of PO register. | 49 | * @po_reg: To store contents of PO register. |
64 | * @pm_reg: To store contents of PM register. | 50 | * @pm_reg: To store contents of PM register. |
65 | * @im0_reg: To store contents of interrupt mode regist0 | ||
66 | * @im1_reg: To store contents of interrupt mode regist1 | ||
67 | * @use_sel_reg: To store contents of GPIO_USE_SEL0~3 | ||
68 | */ | 51 | */ |
69 | struct ioh_gpio_reg_data { | 52 | struct ioh_gpio_reg_data { |
70 | u32 ien_reg; | ||
71 | u32 imask_reg; | ||
72 | u32 po_reg; | 53 | u32 po_reg; |
73 | u32 pm_reg; | 54 | u32 pm_reg; |
74 | u32 im0_reg; | ||
75 | u32 im1_reg; | ||
76 | u32 use_sel_reg; | ||
77 | }; | 55 | }; |
78 | 56 | ||
79 | /** | 57 | /** |
@@ -84,10 +62,7 @@ struct ioh_gpio_reg_data { | |||
84 | * @gpio: Data for GPIO infrastructure. | 62 | * @gpio: Data for GPIO infrastructure. |
85 | * @ioh_gpio_reg: Memory mapped Register data is saved here | 63 | * @ioh_gpio_reg: Memory mapped Register data is saved here |
86 | * when suspend. | 64 | * when suspend. |
87 | * @gpio_use_sel: Save GPIO_USE_SEL1~4 register for PM | ||
88 | * @ch: Indicate GPIO channel | 65 | * @ch: Indicate GPIO channel |
89 | * @irq_base: Save base of IRQ number for interrupt | ||
90 | * @spinlock: Used for register access protection | ||
91 | */ | 66 | */ |
92 | struct ioh_gpio { | 67 | struct ioh_gpio { |
93 | void __iomem *base; | 68 | void __iomem *base; |
@@ -95,10 +70,8 @@ struct ioh_gpio { | |||
95 | struct device *dev; | 70 | struct device *dev; |
96 | struct gpio_chip gpio; | 71 | struct gpio_chip gpio; |
97 | struct ioh_gpio_reg_data ioh_gpio_reg; | 72 | struct ioh_gpio_reg_data ioh_gpio_reg; |
98 | u32 gpio_use_sel; | 73 | struct mutex lock; |
99 | int ch; | 74 | int ch; |
100 | int irq_base; | ||
101 | spinlock_t spinlock; | ||
102 | }; | 75 | }; |
103 | 76 | ||
104 | static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12}; | 77 | static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12}; |
@@ -107,9 +80,8 @@ static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
107 | { | 80 | { |
108 | u32 reg_val; | 81 | u32 reg_val; |
109 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); | 82 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); |
110 | unsigned long flags; | ||
111 | 83 | ||
112 | spin_lock_irqsave(&chip->spinlock, flags); | 84 | mutex_lock(&chip->lock); |
113 | reg_val = ioread32(&chip->reg->regs[chip->ch].po); | 85 | reg_val = ioread32(&chip->reg->regs[chip->ch].po); |
114 | if (val) | 86 | if (val) |
115 | reg_val |= (1 << nr); | 87 | reg_val |= (1 << nr); |
@@ -117,7 +89,7 @@ static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
117 | reg_val &= ~(1 << nr); | 89 | reg_val &= ~(1 << nr); |
118 | 90 | ||
119 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); | 91 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); |
120 | spin_unlock_irqrestore(&chip->spinlock, flags); | 92 | mutex_unlock(&chip->lock); |
121 | } | 93 | } |
122 | 94 | ||
123 | static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) | 95 | static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) |
@@ -133,9 +105,8 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
133 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); | 105 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); |
134 | u32 pm; | 106 | u32 pm; |
135 | u32 reg_val; | 107 | u32 reg_val; |
136 | unsigned long flags; | ||
137 | 108 | ||
138 | spin_lock_irqsave(&chip->spinlock, flags); | 109 | mutex_lock(&chip->lock); |
139 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & | 110 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & |
140 | ((1 << num_ports[chip->ch]) - 1); | 111 | ((1 << num_ports[chip->ch]) - 1); |
141 | pm |= (1 << nr); | 112 | pm |= (1 << nr); |
@@ -148,7 +119,7 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
148 | reg_val &= ~(1 << nr); | 119 | reg_val &= ~(1 << nr); |
149 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); | 120 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); |
150 | 121 | ||
151 | spin_unlock_irqrestore(&chip->spinlock, flags); | 122 | mutex_unlock(&chip->lock); |
152 | 123 | ||
153 | return 0; | 124 | return 0; |
154 | } | 125 | } |
@@ -157,14 +128,13 @@ static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
157 | { | 128 | { |
158 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); | 129 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); |
159 | u32 pm; | 130 | u32 pm; |
160 | unsigned long flags; | ||
161 | 131 | ||
162 | spin_lock_irqsave(&chip->spinlock, flags); | 132 | mutex_lock(&chip->lock); |
163 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & | 133 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & |
164 | ((1 << num_ports[chip->ch]) - 1); | 134 | ((1 << num_ports[chip->ch]) - 1); |
165 | pm &= ~(1 << nr); | 135 | pm &= ~(1 << nr); |
166 | iowrite32(pm, &chip->reg->regs[chip->ch].pm); | 136 | iowrite32(pm, &chip->reg->regs[chip->ch].pm); |
167 | spin_unlock_irqrestore(&chip->spinlock, flags); | 137 | mutex_unlock(&chip->lock); |
168 | 138 | ||
169 | return 0; | 139 | return 0; |
170 | } | 140 | } |
@@ -175,25 +145,8 @@ static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
175 | */ | 145 | */ |
176 | static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip) | 146 | static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip) |
177 | { | 147 | { |
178 | int i; | 148 | chip->ioh_gpio_reg.po_reg = ioread32(&chip->reg->regs[chip->ch].po); |
179 | 149 | chip->ioh_gpio_reg.pm_reg = ioread32(&chip->reg->regs[chip->ch].pm); | |
180 | for (i = 0; i < 8; i ++, chip++) { | ||
181 | chip->ioh_gpio_reg.po_reg = | ||
182 | ioread32(&chip->reg->regs[chip->ch].po); | ||
183 | chip->ioh_gpio_reg.pm_reg = | ||
184 | ioread32(&chip->reg->regs[chip->ch].pm); | ||
185 | chip->ioh_gpio_reg.ien_reg = | ||
186 | ioread32(&chip->reg->regs[chip->ch].ien); | ||
187 | chip->ioh_gpio_reg.imask_reg = | ||
188 | ioread32(&chip->reg->regs[chip->ch].imask); | ||
189 | chip->ioh_gpio_reg.im0_reg = | ||
190 | ioread32(&chip->reg->regs[chip->ch].im_0); | ||
191 | chip->ioh_gpio_reg.im1_reg = | ||
192 | ioread32(&chip->reg->regs[chip->ch].im_1); | ||
193 | if (i < 4) | ||
194 | chip->ioh_gpio_reg.use_sel_reg = | ||
195 | ioread32(&chip->reg->ioh_sel_reg[i]); | ||
196 | } | ||
197 | } | 150 | } |
198 | 151 | ||
199 | /* | 152 | /* |
@@ -201,34 +154,13 @@ static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip) | |||
201 | */ | 154 | */ |
202 | static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip) | 155 | static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip) |
203 | { | 156 | { |
204 | int i; | 157 | /* to store contents of PO register */ |
205 | 158 | iowrite32(chip->ioh_gpio_reg.po_reg, &chip->reg->regs[chip->ch].po); | |
206 | for (i = 0; i < 8; i ++, chip++) { | 159 | /* to store contents of PM register */ |
207 | iowrite32(chip->ioh_gpio_reg.po_reg, | 160 | iowrite32(chip->ioh_gpio_reg.pm_reg, &chip->reg->regs[chip->ch].pm); |
208 | &chip->reg->regs[chip->ch].po); | ||
209 | iowrite32(chip->ioh_gpio_reg.pm_reg, | ||
210 | &chip->reg->regs[chip->ch].pm); | ||
211 | iowrite32(chip->ioh_gpio_reg.ien_reg, | ||
212 | &chip->reg->regs[chip->ch].ien); | ||
213 | iowrite32(chip->ioh_gpio_reg.imask_reg, | ||
214 | &chip->reg->regs[chip->ch].imask); | ||
215 | iowrite32(chip->ioh_gpio_reg.im0_reg, | ||
216 | &chip->reg->regs[chip->ch].im_0); | ||
217 | iowrite32(chip->ioh_gpio_reg.im1_reg, | ||
218 | &chip->reg->regs[chip->ch].im_1); | ||
219 | if (i < 4) | ||
220 | iowrite32(chip->ioh_gpio_reg.use_sel_reg, | ||
221 | &chip->reg->ioh_sel_reg[i]); | ||
222 | } | ||
223 | } | 161 | } |
224 | #endif | 162 | #endif |
225 | 163 | ||
226 | static int ioh_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) | ||
227 | { | ||
228 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); | ||
229 | return chip->irq_base + offset; | ||
230 | } | ||
231 | |||
232 | static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port) | 164 | static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port) |
233 | { | 165 | { |
234 | struct gpio_chip *gpio = &chip->gpio; | 166 | struct gpio_chip *gpio = &chip->gpio; |
@@ -243,178 +175,16 @@ static void ioh_gpio_setup(struct ioh_gpio *chip, int num_port) | |||
243 | gpio->base = -1; | 175 | gpio->base = -1; |
244 | gpio->ngpio = num_port; | 176 | gpio->ngpio = num_port; |
245 | gpio->can_sleep = 0; | 177 | gpio->can_sleep = 0; |
246 | gpio->to_irq = ioh_gpio_to_irq; | ||
247 | } | 178 | } |
248 | 179 | ||
249 | static int ioh_irq_type(struct irq_data *d, unsigned int type) | 180 | static int __devinit ioh_gpio_probe(struct pci_dev *pdev, |
250 | { | ||
251 | u32 im; | ||
252 | void __iomem *im_reg; | ||
253 | u32 ien; | ||
254 | u32 im_pos; | ||
255 | int ch; | ||
256 | unsigned long flags; | ||
257 | u32 val; | ||
258 | int irq = d->irq; | ||
259 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
260 | struct ioh_gpio *chip = gc->private; | ||
261 | |||
262 | ch = irq - chip->irq_base; | ||
263 | if (irq <= chip->irq_base + 7) { | ||
264 | im_reg = &chip->reg->regs[chip->ch].im_0; | ||
265 | im_pos = ch; | ||
266 | } else { | ||
267 | im_reg = &chip->reg->regs[chip->ch].im_1; | ||
268 | im_pos = ch - 8; | ||
269 | } | ||
270 | dev_dbg(chip->dev, "%s:irq=%d type=%d ch=%d pos=%d type=%d\n", | ||
271 | __func__, irq, type, ch, im_pos, type); | ||
272 | |||
273 | spin_lock_irqsave(&chip->spinlock, flags); | ||
274 | |||
275 | switch (type) { | ||
276 | case IRQ_TYPE_EDGE_RISING: | ||
277 | val = IOH_EDGE_RISING; | ||
278 | break; | ||
279 | case IRQ_TYPE_EDGE_FALLING: | ||
280 | val = IOH_EDGE_FALLING; | ||
281 | break; | ||
282 | case IRQ_TYPE_EDGE_BOTH: | ||
283 | val = IOH_EDGE_BOTH; | ||
284 | break; | ||
285 | case IRQ_TYPE_LEVEL_HIGH: | ||
286 | val = IOH_LEVEL_H; | ||
287 | break; | ||
288 | case IRQ_TYPE_LEVEL_LOW: | ||
289 | val = IOH_LEVEL_L; | ||
290 | break; | ||
291 | case IRQ_TYPE_PROBE: | ||
292 | goto end; | ||
293 | default: | ||
294 | dev_warn(chip->dev, "%s: unknown type(%dd)", | ||
295 | __func__, type); | ||
296 | goto end; | ||
297 | } | ||
298 | |||
299 | /* Set interrupt mode */ | ||
300 | im = ioread32(im_reg) & ~(IOH_IM_MASK << (im_pos * 4)); | ||
301 | iowrite32(im | (val << (im_pos * 4)), im_reg); | ||
302 | |||
303 | /* iclr */ | ||
304 | iowrite32(BIT(ch), &chip->reg->regs[chip->ch].iclr); | ||
305 | |||
306 | /* IMASKCLR */ | ||
307 | iowrite32(BIT(ch), &chip->reg->regs[chip->ch].imaskclr); | ||
308 | |||
309 | /* Enable interrupt */ | ||
310 | ien = ioread32(&chip->reg->regs[chip->ch].ien); | ||
311 | iowrite32(ien | BIT(ch), &chip->reg->regs[chip->ch].ien); | ||
312 | end: | ||
313 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | static void ioh_irq_unmask(struct irq_data *d) | ||
319 | { | ||
320 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
321 | struct ioh_gpio *chip = gc->private; | ||
322 | |||
323 | iowrite32(1 << (d->irq - chip->irq_base), | ||
324 | &chip->reg->regs[chip->ch].imaskclr); | ||
325 | } | ||
326 | |||
327 | static void ioh_irq_mask(struct irq_data *d) | ||
328 | { | ||
329 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
330 | struct ioh_gpio *chip = gc->private; | ||
331 | |||
332 | iowrite32(1 << (d->irq - chip->irq_base), | ||
333 | &chip->reg->regs[chip->ch].imask); | ||
334 | } | ||
335 | |||
336 | static void ioh_irq_disable(struct irq_data *d) | ||
337 | { | ||
338 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
339 | struct ioh_gpio *chip = gc->private; | ||
340 | unsigned long flags; | ||
341 | u32 ien; | ||
342 | |||
343 | spin_lock_irqsave(&chip->spinlock, flags); | ||
344 | ien = ioread32(&chip->reg->regs[chip->ch].ien); | ||
345 | ien &= ~(1 << (d->irq - chip->irq_base)); | ||
346 | iowrite32(ien, &chip->reg->regs[chip->ch].ien); | ||
347 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
348 | } | ||
349 | |||
350 | static void ioh_irq_enable(struct irq_data *d) | ||
351 | { | ||
352 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
353 | struct ioh_gpio *chip = gc->private; | ||
354 | unsigned long flags; | ||
355 | u32 ien; | ||
356 | |||
357 | spin_lock_irqsave(&chip->spinlock, flags); | ||
358 | ien = ioread32(&chip->reg->regs[chip->ch].ien); | ||
359 | ien |= 1 << (d->irq - chip->irq_base); | ||
360 | iowrite32(ien, &chip->reg->regs[chip->ch].ien); | ||
361 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
362 | } | ||
363 | |||
364 | static irqreturn_t ioh_gpio_handler(int irq, void *dev_id) | ||
365 | { | ||
366 | struct ioh_gpio *chip = dev_id; | ||
367 | u32 reg_val; | ||
368 | int i, j; | ||
369 | int ret = IRQ_NONE; | ||
370 | |||
371 | for (i = 0; i < 8; i++, chip++) { | ||
372 | reg_val = ioread32(&chip->reg->regs[i].istatus); | ||
373 | for (j = 0; j < num_ports[i]; j++) { | ||
374 | if (reg_val & BIT(j)) { | ||
375 | dev_dbg(chip->dev, | ||
376 | "%s:[%d]:irq=%d status=0x%x\n", | ||
377 | __func__, j, irq, reg_val); | ||
378 | iowrite32(BIT(j), | ||
379 | &chip->reg->regs[chip->ch].iclr); | ||
380 | generic_handle_irq(chip->irq_base + j); | ||
381 | ret = IRQ_HANDLED; | ||
382 | } | ||
383 | } | ||
384 | } | ||
385 | return ret; | ||
386 | } | ||
387 | |||
388 | static void ioh_gpio_alloc_generic_chip(struct ioh_gpio *chip, | ||
389 | unsigned int irq_start, unsigned int num) | ||
390 | { | ||
391 | struct irq_chip_generic *gc; | ||
392 | struct irq_chip_type *ct; | ||
393 | |||
394 | gc = irq_alloc_generic_chip("ioh_gpio", 1, irq_start, chip->base, | ||
395 | handle_simple_irq); | ||
396 | gc->private = chip; | ||
397 | ct = gc->chip_types; | ||
398 | |||
399 | ct->chip.irq_mask = ioh_irq_mask; | ||
400 | ct->chip.irq_unmask = ioh_irq_unmask; | ||
401 | ct->chip.irq_set_type = ioh_irq_type; | ||
402 | ct->chip.irq_disable = ioh_irq_disable; | ||
403 | ct->chip.irq_enable = ioh_irq_enable; | ||
404 | |||
405 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, | ||
406 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); | ||
407 | } | ||
408 | |||
409 | static int ioh_gpio_probe(struct pci_dev *pdev, | ||
410 | const struct pci_device_id *id) | 181 | const struct pci_device_id *id) |
411 | { | 182 | { |
412 | int ret; | 183 | int ret; |
413 | int i, j; | 184 | int i; |
414 | struct ioh_gpio *chip; | 185 | struct ioh_gpio *chip; |
415 | void __iomem *base; | 186 | void __iomem *base; |
416 | void *chip_save; | 187 | void __iomem *chip_save; |
417 | int irq_base; | ||
418 | 188 | ||
419 | ret = pci_enable_device(pdev); | 189 | ret = pci_enable_device(pdev); |
420 | if (ret) { | 190 | if (ret) { |
@@ -429,7 +199,7 @@ static int ioh_gpio_probe(struct pci_dev *pdev, | |||
429 | } | 199 | } |
430 | 200 | ||
431 | base = pci_iomap(pdev, 1, 0); | 201 | base = pci_iomap(pdev, 1, 0); |
432 | if (!base) { | 202 | if (base == 0) { |
433 | dev_err(&pdev->dev, "%s : pci_iomap failed", __func__); | 203 | dev_err(&pdev->dev, "%s : pci_iomap failed", __func__); |
434 | ret = -ENOMEM; | 204 | ret = -ENOMEM; |
435 | goto err_iomap; | 205 | goto err_iomap; |
@@ -448,7 +218,7 @@ static int ioh_gpio_probe(struct pci_dev *pdev, | |||
448 | chip->base = base; | 218 | chip->base = base; |
449 | chip->reg = chip->base; | 219 | chip->reg = chip->base; |
450 | chip->ch = i; | 220 | chip->ch = i; |
451 | spin_lock_init(&chip->spinlock); | 221 | mutex_init(&chip->lock); |
452 | ioh_gpio_setup(chip, num_ports[i]); | 222 | ioh_gpio_setup(chip, num_ports[i]); |
453 | ret = gpiochip_add(&chip->gpio); | 223 | ret = gpiochip_add(&chip->gpio); |
454 | if (ret) { | 224 | if (ret) { |
@@ -458,41 +228,10 @@ static int ioh_gpio_probe(struct pci_dev *pdev, | |||
458 | } | 228 | } |
459 | 229 | ||
460 | chip = chip_save; | 230 | chip = chip_save; |
461 | for (j = 0; j < 8; j++, chip++) { | ||
462 | irq_base = irq_alloc_descs(-1, IOH_IRQ_BASE, num_ports[j], | ||
463 | NUMA_NO_NODE); | ||
464 | if (irq_base < 0) { | ||
465 | dev_warn(&pdev->dev, | ||
466 | "ml_ioh_gpio: Failed to get IRQ base num\n"); | ||
467 | chip->irq_base = -1; | ||
468 | goto err_irq_alloc_descs; | ||
469 | } | ||
470 | chip->irq_base = irq_base; | ||
471 | ioh_gpio_alloc_generic_chip(chip, irq_base, num_ports[j]); | ||
472 | } | ||
473 | |||
474 | chip = chip_save; | ||
475 | ret = request_irq(pdev->irq, ioh_gpio_handler, | ||
476 | IRQF_SHARED, KBUILD_MODNAME, chip); | ||
477 | if (ret != 0) { | ||
478 | dev_err(&pdev->dev, | ||
479 | "%s request_irq failed\n", __func__); | ||
480 | goto err_request_irq; | ||
481 | } | ||
482 | |||
483 | pci_set_drvdata(pdev, chip); | 231 | pci_set_drvdata(pdev, chip); |
484 | 232 | ||
485 | return 0; | 233 | return 0; |
486 | 234 | ||
487 | err_request_irq: | ||
488 | chip = chip_save; | ||
489 | err_irq_alloc_descs: | ||
490 | while (--j >= 0) { | ||
491 | chip--; | ||
492 | irq_free_descs(chip->irq_base, num_ports[j]); | ||
493 | } | ||
494 | |||
495 | chip = chip_save; | ||
496 | err_gpiochip_add: | 235 | err_gpiochip_add: |
497 | while (--i >= 0) { | 236 | while (--i >= 0) { |
498 | chip--; | 237 | chip--; |
@@ -517,19 +256,15 @@ err_pci_enable: | |||
517 | return ret; | 256 | return ret; |
518 | } | 257 | } |
519 | 258 | ||
520 | static void ioh_gpio_remove(struct pci_dev *pdev) | 259 | static void __devexit ioh_gpio_remove(struct pci_dev *pdev) |
521 | { | 260 | { |
522 | int err; | 261 | int err; |
523 | int i; | 262 | int i; |
524 | struct ioh_gpio *chip = pci_get_drvdata(pdev); | 263 | struct ioh_gpio *chip = pci_get_drvdata(pdev); |
525 | void *chip_save; | 264 | void __iomem *chip_save; |
526 | 265 | ||
527 | chip_save = chip; | 266 | chip_save = chip; |
528 | |||
529 | free_irq(pdev->irq, chip); | ||
530 | |||
531 | for (i = 0; i < 8; i++, chip++) { | 267 | for (i = 0; i < 8; i++, chip++) { |
532 | irq_free_descs(chip->irq_base, num_ports[i]); | ||
533 | err = gpiochip_remove(&chip->gpio); | 268 | err = gpiochip_remove(&chip->gpio); |
534 | if (err) | 269 | if (err) |
535 | dev_err(&pdev->dev, "Failed gpiochip_remove\n"); | 270 | dev_err(&pdev->dev, "Failed gpiochip_remove\n"); |
@@ -547,11 +282,9 @@ static int ioh_gpio_suspend(struct pci_dev *pdev, pm_message_t state) | |||
547 | { | 282 | { |
548 | s32 ret; | 283 | s32 ret; |
549 | struct ioh_gpio *chip = pci_get_drvdata(pdev); | 284 | struct ioh_gpio *chip = pci_get_drvdata(pdev); |
550 | unsigned long flags; | ||
551 | 285 | ||
552 | spin_lock_irqsave(&chip->spinlock, flags); | ||
553 | ioh_gpio_save_reg_conf(chip); | 286 | ioh_gpio_save_reg_conf(chip); |
554 | spin_unlock_irqrestore(&chip->spinlock, flags); | 287 | ioh_gpio_restore_reg_conf(chip); |
555 | 288 | ||
556 | ret = pci_save_state(pdev); | 289 | ret = pci_save_state(pdev); |
557 | if (ret) { | 290 | if (ret) { |
@@ -571,7 +304,6 @@ static int ioh_gpio_resume(struct pci_dev *pdev) | |||
571 | { | 304 | { |
572 | s32 ret; | 305 | s32 ret; |
573 | struct ioh_gpio *chip = pci_get_drvdata(pdev); | 306 | struct ioh_gpio *chip = pci_get_drvdata(pdev); |
574 | unsigned long flags; | ||
575 | 307 | ||
576 | ret = pci_enable_wake(pdev, PCI_D0, 0); | 308 | ret = pci_enable_wake(pdev, PCI_D0, 0); |
577 | 309 | ||
@@ -583,11 +315,9 @@ static int ioh_gpio_resume(struct pci_dev *pdev) | |||
583 | } | 315 | } |
584 | pci_restore_state(pdev); | 316 | pci_restore_state(pdev); |
585 | 317 | ||
586 | spin_lock_irqsave(&chip->spinlock, flags); | ||
587 | iowrite32(0x01, &chip->reg->srst); | 318 | iowrite32(0x01, &chip->reg->srst); |
588 | iowrite32(0x00, &chip->reg->srst); | 319 | iowrite32(0x00, &chip->reg->srst); |
589 | ioh_gpio_restore_reg_conf(chip); | 320 | ioh_gpio_restore_reg_conf(chip); |
590 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
591 | 321 | ||
592 | return 0; | 322 | return 0; |
593 | } | 323 | } |
@@ -606,12 +336,22 @@ static struct pci_driver ioh_gpio_driver = { | |||
606 | .name = "ml_ioh_gpio", | 336 | .name = "ml_ioh_gpio", |
607 | .id_table = ioh_gpio_pcidev_id, | 337 | .id_table = ioh_gpio_pcidev_id, |
608 | .probe = ioh_gpio_probe, | 338 | .probe = ioh_gpio_probe, |
609 | .remove = ioh_gpio_remove, | 339 | .remove = __devexit_p(ioh_gpio_remove), |
610 | .suspend = ioh_gpio_suspend, | 340 | .suspend = ioh_gpio_suspend, |
611 | .resume = ioh_gpio_resume | 341 | .resume = ioh_gpio_resume |
612 | }; | 342 | }; |
613 | 343 | ||
614 | module_pci_driver(ioh_gpio_driver); | 344 | static int __init ioh_gpio_pci_init(void) |
345 | { | ||
346 | return pci_register_driver(&ioh_gpio_driver); | ||
347 | } | ||
348 | module_init(ioh_gpio_pci_init); | ||
349 | |||
350 | static void __exit ioh_gpio_pci_exit(void) | ||
351 | { | ||
352 | pci_unregister_driver(&ioh_gpio_driver); | ||
353 | } | ||
354 | module_exit(ioh_gpio_pci_exit); | ||
615 | 355 | ||
616 | MODULE_DESCRIPTION("OKI SEMICONDUCTOR ML-IOH series GPIO Driver"); | 356 | MODULE_DESCRIPTION("OKI SEMICONDUCTOR ML-IOH series GPIO Driver"); |
617 | MODULE_LICENSE("GPL"); | 357 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/gpio/gpio-mm-lantiq.c b/drivers/gpio/gpio-mm-lantiq.c deleted file mode 100644 index 2983dfbd066..00000000000 --- a/drivers/gpio/gpio-mm-lantiq.c +++ /dev/null | |||
@@ -1,158 +0,0 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify it | ||
3 | * under the terms of the GNU General Public License version 2 as published | ||
4 | * by the Free Software Foundation. | ||
5 | * | ||
6 | * Copyright (C) 2012 John Crispin <blogic@openwrt.org> | ||
7 | */ | ||
8 | |||
9 | #include <linux/init.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/types.h> | ||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/mutex.h> | ||
14 | #include <linux/gpio.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/of_gpio.h> | ||
17 | #include <linux/io.h> | ||
18 | #include <linux/slab.h> | ||
19 | |||
20 | #include <lantiq_soc.h> | ||
21 | |||
22 | /* | ||
23 | * By attaching hardware latches to the EBU it is possible to create output | ||
24 | * only gpios. This driver configures a special memory address, which when | ||
25 | * written to outputs 16 bit to the latches. | ||
26 | */ | ||
27 | |||
28 | #define LTQ_EBU_BUSCON 0x1e7ff /* 16 bit access, slowest timing */ | ||
29 | #define LTQ_EBU_WP 0x80000000 /* write protect bit */ | ||
30 | |||
31 | struct ltq_mm { | ||
32 | struct of_mm_gpio_chip mmchip; | ||
33 | u16 shadow; /* shadow the latches state */ | ||
34 | }; | ||
35 | |||
36 | /** | ||
37 | * ltq_mm_apply() - write the shadow value to the ebu address. | ||
38 | * @chip: Pointer to our private data structure. | ||
39 | * | ||
40 | * Write the shadow value to the EBU to set the gpios. We need to set the | ||
41 | * global EBU lock to make sure that PCI/MTD dont break. | ||
42 | */ | ||
43 | static void ltq_mm_apply(struct ltq_mm *chip) | ||
44 | { | ||
45 | unsigned long flags; | ||
46 | |||
47 | spin_lock_irqsave(&ebu_lock, flags); | ||
48 | ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1); | ||
49 | __raw_writew(chip->shadow, chip->mmchip.regs); | ||
50 | ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1); | ||
51 | spin_unlock_irqrestore(&ebu_lock, flags); | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * ltq_mm_set() - gpio_chip->set - set gpios. | ||
56 | * @gc: Pointer to gpio_chip device structure. | ||
57 | * @gpio: GPIO signal number. | ||
58 | * @val: Value to be written to specified signal. | ||
59 | * | ||
60 | * Set the shadow value and call ltq_mm_apply. | ||
61 | */ | ||
62 | static void ltq_mm_set(struct gpio_chip *gc, unsigned offset, int value) | ||
63 | { | ||
64 | struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); | ||
65 | struct ltq_mm *chip = | ||
66 | container_of(mm_gc, struct ltq_mm, mmchip); | ||
67 | |||
68 | if (value) | ||
69 | chip->shadow |= (1 << offset); | ||
70 | else | ||
71 | chip->shadow &= ~(1 << offset); | ||
72 | ltq_mm_apply(chip); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * ltq_mm_dir_out() - gpio_chip->dir_out - set gpio direction. | ||
77 | * @gc: Pointer to gpio_chip device structure. | ||
78 | * @gpio: GPIO signal number. | ||
79 | * @val: Value to be written to specified signal. | ||
80 | * | ||
81 | * Same as ltq_mm_set, always returns 0. | ||
82 | */ | ||
83 | static int ltq_mm_dir_out(struct gpio_chip *gc, unsigned offset, int value) | ||
84 | { | ||
85 | ltq_mm_set(gc, offset, value); | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * ltq_mm_save_regs() - Set initial values of GPIO pins | ||
92 | * @mm_gc: pointer to memory mapped GPIO chip structure | ||
93 | */ | ||
94 | static void ltq_mm_save_regs(struct of_mm_gpio_chip *mm_gc) | ||
95 | { | ||
96 | struct ltq_mm *chip = | ||
97 | container_of(mm_gc, struct ltq_mm, mmchip); | ||
98 | |||
99 | /* tell the ebu controller which memory address we will be using */ | ||
100 | ltq_ebu_w32(CPHYSADDR(chip->mmchip.regs) | 0x1, LTQ_EBU_ADDRSEL1); | ||
101 | |||
102 | ltq_mm_apply(chip); | ||
103 | } | ||
104 | |||
105 | static int ltq_mm_probe(struct platform_device *pdev) | ||
106 | { | ||
107 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
108 | struct ltq_mm *chip; | ||
109 | const __be32 *shadow; | ||
110 | int ret = 0; | ||
111 | |||
112 | if (!res) { | ||
113 | dev_err(&pdev->dev, "failed to get memory resource\n"); | ||
114 | return -ENOENT; | ||
115 | } | ||
116 | |||
117 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | ||
118 | if (!chip) | ||
119 | return -ENOMEM; | ||
120 | |||
121 | chip->mmchip.gc.ngpio = 16; | ||
122 | chip->mmchip.gc.label = "gpio-mm-ltq"; | ||
123 | chip->mmchip.gc.direction_output = ltq_mm_dir_out; | ||
124 | chip->mmchip.gc.set = ltq_mm_set; | ||
125 | chip->mmchip.save_regs = ltq_mm_save_regs; | ||
126 | |||
127 | /* store the shadow value if one was passed by the devicetree */ | ||
128 | shadow = of_get_property(pdev->dev.of_node, "lantiq,shadow", NULL); | ||
129 | if (shadow) | ||
130 | chip->shadow = be32_to_cpu(*shadow); | ||
131 | |||
132 | ret = of_mm_gpiochip_add(pdev->dev.of_node, &chip->mmchip); | ||
133 | if (ret) | ||
134 | kfree(chip); | ||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | static const struct of_device_id ltq_mm_match[] = { | ||
139 | { .compatible = "lantiq,gpio-mm" }, | ||
140 | {}, | ||
141 | }; | ||
142 | MODULE_DEVICE_TABLE(of, ltq_mm_match); | ||
143 | |||
144 | static struct platform_driver ltq_mm_driver = { | ||
145 | .probe = ltq_mm_probe, | ||
146 | .driver = { | ||
147 | .name = "gpio-mm-ltq", | ||
148 | .owner = THIS_MODULE, | ||
149 | .of_match_table = ltq_mm_match, | ||
150 | }, | ||
151 | }; | ||
152 | |||
153 | static int __init ltq_mm_init(void) | ||
154 | { | ||
155 | return platform_driver_register(<q_mm_driver); | ||
156 | } | ||
157 | |||
158 | subsys_initcall(ltq_mm_init); | ||
diff --git a/drivers/gpio/gpio-mpc5200.c b/drivers/gpio/gpio-mpc5200.c index 42647f26c9e..52d3ed20810 100644 --- a/drivers/gpio/gpio-mpc5200.c +++ b/drivers/gpio/gpio-mpc5200.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/of_gpio.h> | 23 | #include <linux/of_gpio.h> |
24 | #include <linux/io.h> | 24 | #include <linux/io.h> |
25 | #include <linux/of_platform.h> | 25 | #include <linux/of_platform.h> |
26 | #include <linux/module.h> | ||
27 | 26 | ||
28 | #include <asm/gpio.h> | 27 | #include <asm/gpio.h> |
29 | #include <asm/mpc52xx.h> | 28 | #include <asm/mpc52xx.h> |
@@ -148,7 +147,7 @@ mpc52xx_wkup_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | |||
148 | return 0; | 147 | return 0; |
149 | } | 148 | } |
150 | 149 | ||
151 | static int mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev) | 150 | static int __devinit mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev) |
152 | { | 151 | { |
153 | struct mpc52xx_gpiochip *chip; | 152 | struct mpc52xx_gpiochip *chip; |
154 | struct mpc52xx_gpio_wkup __iomem *regs; | 153 | struct mpc52xx_gpio_wkup __iomem *regs; |
@@ -308,7 +307,7 @@ mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | |||
308 | return 0; | 307 | return 0; |
309 | } | 308 | } |
310 | 309 | ||
311 | static int mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev) | 310 | static int __devinit mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev) |
312 | { | 311 | { |
313 | struct mpc52xx_gpiochip *chip; | 312 | struct mpc52xx_gpiochip *chip; |
314 | struct gpio_chip *gc; | 313 | struct gpio_chip *gc; |
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c deleted file mode 100644 index 9ae29cc0d17..00000000000 --- a/drivers/gpio/gpio-mpc8xxx.c +++ /dev/null | |||
@@ -1,389 +0,0 @@ | |||
1 | /* | ||
2 | * GPIOs on MPC512x/8349/8572/8610 and compatible | ||
3 | * | ||
4 | * Copyright (C) 2008 Peter Korsgaard <jacmet@sunsite.dk> | ||
5 | * | ||
6 | * This file is licensed under the terms of the GNU General Public License | ||
7 | * version 2. This program is licensed "as is" without any warranty of any | ||
8 | * kind, whether express or implied. | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/spinlock.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/of_gpio.h> | ||
17 | #include <linux/gpio.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/irq.h> | ||
20 | |||
21 | #define MPC8XXX_GPIO_PINS 32 | ||
22 | |||
23 | #define GPIO_DIR 0x00 | ||
24 | #define GPIO_ODR 0x04 | ||
25 | #define GPIO_DAT 0x08 | ||
26 | #define GPIO_IER 0x0c | ||
27 | #define GPIO_IMR 0x10 | ||
28 | #define GPIO_ICR 0x14 | ||
29 | #define GPIO_ICR2 0x18 | ||
30 | |||
31 | struct mpc8xxx_gpio_chip { | ||
32 | struct of_mm_gpio_chip mm_gc; | ||
33 | spinlock_t lock; | ||
34 | |||
35 | /* | ||
36 | * shadowed data register to be able to clear/set output pins in | ||
37 | * open drain mode safely | ||
38 | */ | ||
39 | u32 data; | ||
40 | struct irq_domain *irq; | ||
41 | const void *of_dev_id_data; | ||
42 | }; | ||
43 | |||
44 | static inline u32 mpc8xxx_gpio2mask(unsigned int gpio) | ||
45 | { | ||
46 | return 1u << (MPC8XXX_GPIO_PINS - 1 - gpio); | ||
47 | } | ||
48 | |||
49 | static inline struct mpc8xxx_gpio_chip * | ||
50 | to_mpc8xxx_gpio_chip(struct of_mm_gpio_chip *mm) | ||
51 | { | ||
52 | return container_of(mm, struct mpc8xxx_gpio_chip, mm_gc); | ||
53 | } | ||
54 | |||
55 | static void mpc8xxx_gpio_save_regs(struct of_mm_gpio_chip *mm) | ||
56 | { | ||
57 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
58 | |||
59 | mpc8xxx_gc->data = in_be32(mm->regs + GPIO_DAT); | ||
60 | } | ||
61 | |||
62 | /* Workaround GPIO 1 errata on MPC8572/MPC8536. The status of GPIOs | ||
63 | * defined as output cannot be determined by reading GPDAT register, | ||
64 | * so we use shadow data register instead. The status of input pins | ||
65 | * is determined by reading GPDAT register. | ||
66 | */ | ||
67 | static int mpc8572_gpio_get(struct gpio_chip *gc, unsigned int gpio) | ||
68 | { | ||
69 | u32 val; | ||
70 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
71 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
72 | |||
73 | val = in_be32(mm->regs + GPIO_DAT) & ~in_be32(mm->regs + GPIO_DIR); | ||
74 | |||
75 | return (val | mpc8xxx_gc->data) & mpc8xxx_gpio2mask(gpio); | ||
76 | } | ||
77 | |||
78 | static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio) | ||
79 | { | ||
80 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
81 | |||
82 | return in_be32(mm->regs + GPIO_DAT) & mpc8xxx_gpio2mask(gpio); | ||
83 | } | ||
84 | |||
85 | static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) | ||
86 | { | ||
87 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
88 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
89 | unsigned long flags; | ||
90 | |||
91 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
92 | |||
93 | if (val) | ||
94 | mpc8xxx_gc->data |= mpc8xxx_gpio2mask(gpio); | ||
95 | else | ||
96 | mpc8xxx_gc->data &= ~mpc8xxx_gpio2mask(gpio); | ||
97 | |||
98 | out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data); | ||
99 | |||
100 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
101 | } | ||
102 | |||
103 | static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) | ||
104 | { | ||
105 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
106 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
107 | unsigned long flags; | ||
108 | |||
109 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
110 | |||
111 | clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio)); | ||
112 | |||
113 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | static int mpc8xxx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | ||
119 | { | ||
120 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
121 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
122 | unsigned long flags; | ||
123 | |||
124 | mpc8xxx_gpio_set(gc, gpio, val); | ||
125 | |||
126 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
127 | |||
128 | setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio)); | ||
129 | |||
130 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
131 | |||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | static int mpc5121_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) | ||
136 | { | ||
137 | /* GPIO 28..31 are input only on MPC5121 */ | ||
138 | if (gpio >= 28) | ||
139 | return -EINVAL; | ||
140 | |||
141 | return mpc8xxx_gpio_dir_out(gc, gpio, val); | ||
142 | } | ||
143 | |||
144 | static int mpc8xxx_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | ||
145 | { | ||
146 | struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc); | ||
147 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm); | ||
148 | |||
149 | if (mpc8xxx_gc->irq && offset < MPC8XXX_GPIO_PINS) | ||
150 | return irq_create_mapping(mpc8xxx_gc->irq, offset); | ||
151 | else | ||
152 | return -ENXIO; | ||
153 | } | ||
154 | |||
155 | static void mpc8xxx_gpio_irq_cascade(unsigned int irq, struct irq_desc *desc) | ||
156 | { | ||
157 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_desc_get_handler_data(desc); | ||
158 | struct irq_chip *chip = irq_desc_get_chip(desc); | ||
159 | struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; | ||
160 | unsigned int mask; | ||
161 | |||
162 | mask = in_be32(mm->regs + GPIO_IER) & in_be32(mm->regs + GPIO_IMR); | ||
163 | if (mask) | ||
164 | generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq, | ||
165 | 32 - ffs(mask))); | ||
166 | if (chip->irq_eoi) | ||
167 | chip->irq_eoi(&desc->irq_data); | ||
168 | } | ||
169 | |||
170 | static void mpc8xxx_irq_unmask(struct irq_data *d) | ||
171 | { | ||
172 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d); | ||
173 | struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; | ||
174 | unsigned long flags; | ||
175 | |||
176 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
177 | |||
178 | setbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d))); | ||
179 | |||
180 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
181 | } | ||
182 | |||
183 | static void mpc8xxx_irq_mask(struct irq_data *d) | ||
184 | { | ||
185 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d); | ||
186 | struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; | ||
187 | unsigned long flags; | ||
188 | |||
189 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
190 | |||
191 | clrbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d))); | ||
192 | |||
193 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
194 | } | ||
195 | |||
196 | static void mpc8xxx_irq_ack(struct irq_data *d) | ||
197 | { | ||
198 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d); | ||
199 | struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; | ||
200 | |||
201 | out_be32(mm->regs + GPIO_IER, mpc8xxx_gpio2mask(irqd_to_hwirq(d))); | ||
202 | } | ||
203 | |||
204 | static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type) | ||
205 | { | ||
206 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d); | ||
207 | struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; | ||
208 | unsigned long flags; | ||
209 | |||
210 | switch (flow_type) { | ||
211 | case IRQ_TYPE_EDGE_FALLING: | ||
212 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
213 | setbits32(mm->regs + GPIO_ICR, | ||
214 | mpc8xxx_gpio2mask(irqd_to_hwirq(d))); | ||
215 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
216 | break; | ||
217 | |||
218 | case IRQ_TYPE_EDGE_BOTH: | ||
219 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
220 | clrbits32(mm->regs + GPIO_ICR, | ||
221 | mpc8xxx_gpio2mask(irqd_to_hwirq(d))); | ||
222 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
223 | break; | ||
224 | |||
225 | default: | ||
226 | return -EINVAL; | ||
227 | } | ||
228 | |||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static int mpc512x_irq_set_type(struct irq_data *d, unsigned int flow_type) | ||
233 | { | ||
234 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d); | ||
235 | struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; | ||
236 | unsigned long gpio = irqd_to_hwirq(d); | ||
237 | void __iomem *reg; | ||
238 | unsigned int shift; | ||
239 | unsigned long flags; | ||
240 | |||
241 | if (gpio < 16) { | ||
242 | reg = mm->regs + GPIO_ICR; | ||
243 | shift = (15 - gpio) * 2; | ||
244 | } else { | ||
245 | reg = mm->regs + GPIO_ICR2; | ||
246 | shift = (15 - (gpio % 16)) * 2; | ||
247 | } | ||
248 | |||
249 | switch (flow_type) { | ||
250 | case IRQ_TYPE_EDGE_FALLING: | ||
251 | case IRQ_TYPE_LEVEL_LOW: | ||
252 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
253 | clrsetbits_be32(reg, 3 << shift, 2 << shift); | ||
254 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
255 | break; | ||
256 | |||
257 | case IRQ_TYPE_EDGE_RISING: | ||
258 | case IRQ_TYPE_LEVEL_HIGH: | ||
259 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
260 | clrsetbits_be32(reg, 3 << shift, 1 << shift); | ||
261 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
262 | break; | ||
263 | |||
264 | case IRQ_TYPE_EDGE_BOTH: | ||
265 | spin_lock_irqsave(&mpc8xxx_gc->lock, flags); | ||
266 | clrbits32(reg, 3 << shift); | ||
267 | spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags); | ||
268 | break; | ||
269 | |||
270 | default: | ||
271 | return -EINVAL; | ||
272 | } | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | static struct irq_chip mpc8xxx_irq_chip = { | ||
278 | .name = "mpc8xxx-gpio", | ||
279 | .irq_unmask = mpc8xxx_irq_unmask, | ||
280 | .irq_mask = mpc8xxx_irq_mask, | ||
281 | .irq_ack = mpc8xxx_irq_ack, | ||
282 | .irq_set_type = mpc8xxx_irq_set_type, | ||
283 | }; | ||
284 | |||
285 | static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int virq, | ||
286 | irq_hw_number_t hw) | ||
287 | { | ||
288 | struct mpc8xxx_gpio_chip *mpc8xxx_gc = h->host_data; | ||
289 | |||
290 | if (mpc8xxx_gc->of_dev_id_data) | ||
291 | mpc8xxx_irq_chip.irq_set_type = mpc8xxx_gc->of_dev_id_data; | ||
292 | |||
293 | irq_set_chip_data(virq, h->host_data); | ||
294 | irq_set_chip_and_handler(virq, &mpc8xxx_irq_chip, handle_level_irq); | ||
295 | irq_set_irq_type(virq, IRQ_TYPE_NONE); | ||
296 | |||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | static struct irq_domain_ops mpc8xxx_gpio_irq_ops = { | ||
301 | .map = mpc8xxx_gpio_irq_map, | ||
302 | .xlate = irq_domain_xlate_twocell, | ||
303 | }; | ||
304 | |||
305 | static struct of_device_id mpc8xxx_gpio_ids[] __initdata = { | ||
306 | { .compatible = "fsl,mpc8349-gpio", }, | ||
307 | { .compatible = "fsl,mpc8572-gpio", }, | ||
308 | { .compatible = "fsl,mpc8610-gpio", }, | ||
309 | { .compatible = "fsl,mpc5121-gpio", .data = mpc512x_irq_set_type, }, | ||
310 | { .compatible = "fsl,pq3-gpio", }, | ||
311 | { .compatible = "fsl,qoriq-gpio", }, | ||
312 | {} | ||
313 | }; | ||
314 | |||
315 | static void __init mpc8xxx_add_controller(struct device_node *np) | ||
316 | { | ||
317 | struct mpc8xxx_gpio_chip *mpc8xxx_gc; | ||
318 | struct of_mm_gpio_chip *mm_gc; | ||
319 | struct gpio_chip *gc; | ||
320 | const struct of_device_id *id; | ||
321 | unsigned hwirq; | ||
322 | int ret; | ||
323 | |||
324 | mpc8xxx_gc = kzalloc(sizeof(*mpc8xxx_gc), GFP_KERNEL); | ||
325 | if (!mpc8xxx_gc) { | ||
326 | ret = -ENOMEM; | ||
327 | goto err; | ||
328 | } | ||
329 | |||
330 | spin_lock_init(&mpc8xxx_gc->lock); | ||
331 | |||
332 | mm_gc = &mpc8xxx_gc->mm_gc; | ||
333 | gc = &mm_gc->gc; | ||
334 | |||
335 | mm_gc->save_regs = mpc8xxx_gpio_save_regs; | ||
336 | gc->ngpio = MPC8XXX_GPIO_PINS; | ||
337 | gc->direction_input = mpc8xxx_gpio_dir_in; | ||
338 | gc->direction_output = of_device_is_compatible(np, "fsl,mpc5121-gpio") ? | ||
339 | mpc5121_gpio_dir_out : mpc8xxx_gpio_dir_out; | ||
340 | gc->get = of_device_is_compatible(np, "fsl,mpc8572-gpio") ? | ||
341 | mpc8572_gpio_get : mpc8xxx_gpio_get; | ||
342 | gc->set = mpc8xxx_gpio_set; | ||
343 | gc->to_irq = mpc8xxx_gpio_to_irq; | ||
344 | |||
345 | ret = of_mm_gpiochip_add(np, mm_gc); | ||
346 | if (ret) | ||
347 | goto err; | ||
348 | |||
349 | hwirq = irq_of_parse_and_map(np, 0); | ||
350 | if (hwirq == NO_IRQ) | ||
351 | goto skip_irq; | ||
352 | |||
353 | mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS, | ||
354 | &mpc8xxx_gpio_irq_ops, mpc8xxx_gc); | ||
355 | if (!mpc8xxx_gc->irq) | ||
356 | goto skip_irq; | ||
357 | |||
358 | id = of_match_node(mpc8xxx_gpio_ids, np); | ||
359 | if (id) | ||
360 | mpc8xxx_gc->of_dev_id_data = id->data; | ||
361 | |||
362 | /* ack and mask all irqs */ | ||
363 | out_be32(mm_gc->regs + GPIO_IER, 0xffffffff); | ||
364 | out_be32(mm_gc->regs + GPIO_IMR, 0); | ||
365 | |||
366 | irq_set_handler_data(hwirq, mpc8xxx_gc); | ||
367 | irq_set_chained_handler(hwirq, mpc8xxx_gpio_irq_cascade); | ||
368 | |||
369 | skip_irq: | ||
370 | return; | ||
371 | |||
372 | err: | ||
373 | pr_err("%s: registration failed with status %d\n", | ||
374 | np->full_name, ret); | ||
375 | kfree(mpc8xxx_gc); | ||
376 | |||
377 | return; | ||
378 | } | ||
379 | |||
380 | static int __init mpc8xxx_add_gpiochips(void) | ||
381 | { | ||
382 | struct device_node *np; | ||
383 | |||
384 | for_each_matching_node(np, mpc8xxx_gpio_ids) | ||
385 | mpc8xxx_add_controller(np); | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | arch_initcall(mpc8xxx_add_gpiochips); | ||
diff --git a/drivers/gpio/gpio-msic.c b/drivers/gpio/gpio-msic.c deleted file mode 100644 index 27ea7b9257f..00000000000 --- a/drivers/gpio/gpio-msic.c +++ /dev/null | |||
@@ -1,339 +0,0 @@ | |||
1 | /* | ||
2 | * Intel Medfield MSIC GPIO driver> | ||
3 | * Copyright (c) 2011, Intel Corporation. | ||
4 | * | ||
5 | * Author: Mathias Nyman <mathias.nyman@linux.intel.com> | ||
6 | * Based on intel_pmic_gpio.c | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms and conditions of the GNU General Public License, | ||
10 | * version 2, as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
15 | * more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License along with | ||
18 | * this program; if not, write to the Free Software Foundation, Inc., | ||
19 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/gpio.h> | ||
29 | #include <linux/platform_device.h> | ||
30 | #include <linux/mfd/intel_msic.h> | ||
31 | |||
32 | /* the offset for the mapping of global gpio pin to irq */ | ||
33 | #define MSIC_GPIO_IRQ_OFFSET 0x100 | ||
34 | |||
35 | #define MSIC_GPIO_DIR_IN 0 | ||
36 | #define MSIC_GPIO_DIR_OUT BIT(5) | ||
37 | #define MSIC_GPIO_TRIG_FALL BIT(1) | ||
38 | #define MSIC_GPIO_TRIG_RISE BIT(2) | ||
39 | |||
40 | /* masks for msic gpio output GPIOxxxxCTLO registers */ | ||
41 | #define MSIC_GPIO_DIR_MASK BIT(5) | ||
42 | #define MSIC_GPIO_DRV_MASK BIT(4) | ||
43 | #define MSIC_GPIO_REN_MASK BIT(3) | ||
44 | #define MSIC_GPIO_RVAL_MASK (BIT(2) | BIT(1)) | ||
45 | #define MSIC_GPIO_DOUT_MASK BIT(0) | ||
46 | |||
47 | /* masks for msic gpio input GPIOxxxxCTLI registers */ | ||
48 | #define MSIC_GPIO_GLBYP_MASK BIT(5) | ||
49 | #define MSIC_GPIO_DBNC_MASK (BIT(4) | BIT(3)) | ||
50 | #define MSIC_GPIO_INTCNT_MASK (BIT(2) | BIT(1)) | ||
51 | #define MSIC_GPIO_DIN_MASK BIT(0) | ||
52 | |||
53 | #define MSIC_NUM_GPIO 24 | ||
54 | |||
55 | struct msic_gpio { | ||
56 | struct platform_device *pdev; | ||
57 | struct mutex buslock; | ||
58 | struct gpio_chip chip; | ||
59 | int irq; | ||
60 | unsigned irq_base; | ||
61 | unsigned long trig_change_mask; | ||
62 | unsigned trig_type; | ||
63 | }; | ||
64 | |||
65 | /* | ||
66 | * MSIC has 24 gpios, 16 low voltage (1.2-1.8v) and 8 high voltage (3v). | ||
67 | * Both the high and low voltage gpios are divided in two banks. | ||
68 | * GPIOs are numbered with GPIO0LV0 as gpio_base in the following order: | ||
69 | * GPIO0LV0..GPIO0LV7: low voltage, bank 0, gpio_base | ||
70 | * GPIO1LV0..GPIO1LV7: low voltage, bank 1, gpio_base + 8 | ||
71 | * GPIO0HV0..GPIO0HV3: high voltage, bank 0, gpio_base + 16 | ||
72 | * GPIO1HV0..GPIO1HV3: high voltage, bank 1, gpio_base + 20 | ||
73 | */ | ||
74 | |||
75 | static int msic_gpio_to_ireg(unsigned offset) | ||
76 | { | ||
77 | if (offset >= MSIC_NUM_GPIO) | ||
78 | return -EINVAL; | ||
79 | |||
80 | if (offset < 8) | ||
81 | return INTEL_MSIC_GPIO0LV0CTLI - offset; | ||
82 | if (offset < 16) | ||
83 | return INTEL_MSIC_GPIO1LV0CTLI - offset + 8; | ||
84 | if (offset < 20) | ||
85 | return INTEL_MSIC_GPIO0HV0CTLI - offset + 16; | ||
86 | |||
87 | return INTEL_MSIC_GPIO1HV0CTLI - offset + 20; | ||
88 | } | ||
89 | |||
90 | static int msic_gpio_to_oreg(unsigned offset) | ||
91 | { | ||
92 | if (offset >= MSIC_NUM_GPIO) | ||
93 | return -EINVAL; | ||
94 | |||
95 | if (offset < 8) | ||
96 | return INTEL_MSIC_GPIO0LV0CTLO - offset; | ||
97 | if (offset < 16) | ||
98 | return INTEL_MSIC_GPIO1LV0CTLO - offset + 8; | ||
99 | if (offset < 20) | ||
100 | return INTEL_MSIC_GPIO0HV0CTLO - offset + 16; | ||
101 | |||
102 | return INTEL_MSIC_GPIO1HV0CTLO - offset + 20; | ||
103 | } | ||
104 | |||
105 | static int msic_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
106 | { | ||
107 | int reg; | ||
108 | |||
109 | reg = msic_gpio_to_oreg(offset); | ||
110 | if (reg < 0) | ||
111 | return reg; | ||
112 | |||
113 | return intel_msic_reg_update(reg, MSIC_GPIO_DIR_IN, MSIC_GPIO_DIR_MASK); | ||
114 | } | ||
115 | |||
116 | static int msic_gpio_direction_output(struct gpio_chip *chip, | ||
117 | unsigned offset, int value) | ||
118 | { | ||
119 | int reg; | ||
120 | unsigned mask; | ||
121 | |||
122 | value = (!!value) | MSIC_GPIO_DIR_OUT; | ||
123 | mask = MSIC_GPIO_DIR_MASK | MSIC_GPIO_DOUT_MASK; | ||
124 | |||
125 | reg = msic_gpio_to_oreg(offset); | ||
126 | if (reg < 0) | ||
127 | return reg; | ||
128 | |||
129 | return intel_msic_reg_update(reg, value, mask); | ||
130 | } | ||
131 | |||
132 | static int msic_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
133 | { | ||
134 | u8 r; | ||
135 | int ret; | ||
136 | int reg; | ||
137 | |||
138 | reg = msic_gpio_to_ireg(offset); | ||
139 | if (reg < 0) | ||
140 | return reg; | ||
141 | |||
142 | ret = intel_msic_reg_read(reg, &r); | ||
143 | if (ret < 0) | ||
144 | return ret; | ||
145 | |||
146 | return r & MSIC_GPIO_DIN_MASK; | ||
147 | } | ||
148 | |||
149 | static void msic_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
150 | { | ||
151 | int reg; | ||
152 | |||
153 | reg = msic_gpio_to_oreg(offset); | ||
154 | if (reg < 0) | ||
155 | return; | ||
156 | |||
157 | intel_msic_reg_update(reg, !!value , MSIC_GPIO_DOUT_MASK); | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * This is called from genirq with mg->buslock locked and | ||
162 | * irq_desc->lock held. We can not access the scu bus here, so we | ||
163 | * store the change and update in the bus_sync_unlock() function below | ||
164 | */ | ||
165 | static int msic_irq_type(struct irq_data *data, unsigned type) | ||
166 | { | ||
167 | struct msic_gpio *mg = irq_data_get_irq_chip_data(data); | ||
168 | u32 gpio = data->irq - mg->irq_base; | ||
169 | |||
170 | if (gpio >= mg->chip.ngpio) | ||
171 | return -EINVAL; | ||
172 | |||
173 | /* mark for which gpio the trigger changed, protected by buslock */ | ||
174 | mg->trig_change_mask |= (1 << gpio); | ||
175 | mg->trig_type = type; | ||
176 | |||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | static int msic_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
181 | { | ||
182 | struct msic_gpio *mg = container_of(chip, struct msic_gpio, chip); | ||
183 | return mg->irq_base + offset; | ||
184 | } | ||
185 | |||
186 | static void msic_bus_lock(struct irq_data *data) | ||
187 | { | ||
188 | struct msic_gpio *mg = irq_data_get_irq_chip_data(data); | ||
189 | mutex_lock(&mg->buslock); | ||
190 | } | ||
191 | |||
192 | static void msic_bus_sync_unlock(struct irq_data *data) | ||
193 | { | ||
194 | struct msic_gpio *mg = irq_data_get_irq_chip_data(data); | ||
195 | int offset; | ||
196 | int reg; | ||
197 | u8 trig = 0; | ||
198 | |||
199 | /* We can only get one change at a time as the buslock covers the | ||
200 | entire transaction. The irq_desc->lock is dropped before we are | ||
201 | called but that is fine */ | ||
202 | if (mg->trig_change_mask) { | ||
203 | offset = __ffs(mg->trig_change_mask); | ||
204 | |||
205 | reg = msic_gpio_to_ireg(offset); | ||
206 | if (reg < 0) | ||
207 | goto out; | ||
208 | |||
209 | if (mg->trig_type & IRQ_TYPE_EDGE_RISING) | ||
210 | trig |= MSIC_GPIO_TRIG_RISE; | ||
211 | if (mg->trig_type & IRQ_TYPE_EDGE_FALLING) | ||
212 | trig |= MSIC_GPIO_TRIG_FALL; | ||
213 | |||
214 | intel_msic_reg_update(reg, trig, MSIC_GPIO_INTCNT_MASK); | ||
215 | mg->trig_change_mask = 0; | ||
216 | } | ||
217 | out: | ||
218 | mutex_unlock(&mg->buslock); | ||
219 | } | ||
220 | |||
221 | /* Firmware does all the masking and unmasking for us, no masking here. */ | ||
222 | static void msic_irq_unmask(struct irq_data *data) { } | ||
223 | |||
224 | static void msic_irq_mask(struct irq_data *data) { } | ||
225 | |||
226 | static struct irq_chip msic_irqchip = { | ||
227 | .name = "MSIC-GPIO", | ||
228 | .irq_mask = msic_irq_mask, | ||
229 | .irq_unmask = msic_irq_unmask, | ||
230 | .irq_set_type = msic_irq_type, | ||
231 | .irq_bus_lock = msic_bus_lock, | ||
232 | .irq_bus_sync_unlock = msic_bus_sync_unlock, | ||
233 | }; | ||
234 | |||
235 | static void msic_gpio_irq_handler(unsigned irq, struct irq_desc *desc) | ||
236 | { | ||
237 | struct irq_data *data = irq_desc_get_irq_data(desc); | ||
238 | struct msic_gpio *mg = irq_data_get_irq_handler_data(data); | ||
239 | struct irq_chip *chip = irq_data_get_irq_chip(data); | ||
240 | struct intel_msic *msic = pdev_to_intel_msic(mg->pdev); | ||
241 | int i; | ||
242 | int bitnr; | ||
243 | u8 pin; | ||
244 | unsigned long pending = 0; | ||
245 | |||
246 | for (i = 0; i < (mg->chip.ngpio / BITS_PER_BYTE); i++) { | ||
247 | intel_msic_irq_read(msic, INTEL_MSIC_GPIO0LVIRQ + i, &pin); | ||
248 | pending = pin; | ||
249 | |||
250 | if (pending) { | ||
251 | for_each_set_bit(bitnr, &pending, BITS_PER_BYTE) | ||
252 | generic_handle_irq(mg->irq_base + | ||
253 | (i * BITS_PER_BYTE) + bitnr); | ||
254 | } | ||
255 | } | ||
256 | chip->irq_eoi(data); | ||
257 | } | ||
258 | |||
259 | static int platform_msic_gpio_probe(struct platform_device *pdev) | ||
260 | { | ||
261 | struct device *dev = &pdev->dev; | ||
262 | struct intel_msic_gpio_pdata *pdata = dev->platform_data; | ||
263 | struct msic_gpio *mg; | ||
264 | int irq = platform_get_irq(pdev, 0); | ||
265 | int retval; | ||
266 | int i; | ||
267 | |||
268 | if (irq < 0) { | ||
269 | dev_err(dev, "no IRQ line\n"); | ||
270 | return -EINVAL; | ||
271 | } | ||
272 | |||
273 | if (!pdata || !pdata->gpio_base) { | ||
274 | dev_err(dev, "incorrect or missing platform data\n"); | ||
275 | return -EINVAL; | ||
276 | } | ||
277 | |||
278 | mg = kzalloc(sizeof(*mg), GFP_KERNEL); | ||
279 | if (!mg) | ||
280 | return -ENOMEM; | ||
281 | |||
282 | dev_set_drvdata(dev, mg); | ||
283 | |||
284 | mg->pdev = pdev; | ||
285 | mg->irq = irq; | ||
286 | mg->irq_base = pdata->gpio_base + MSIC_GPIO_IRQ_OFFSET; | ||
287 | mg->chip.label = "msic_gpio"; | ||
288 | mg->chip.direction_input = msic_gpio_direction_input; | ||
289 | mg->chip.direction_output = msic_gpio_direction_output; | ||
290 | mg->chip.get = msic_gpio_get; | ||
291 | mg->chip.set = msic_gpio_set; | ||
292 | mg->chip.to_irq = msic_gpio_to_irq; | ||
293 | mg->chip.base = pdata->gpio_base; | ||
294 | mg->chip.ngpio = MSIC_NUM_GPIO; | ||
295 | mg->chip.can_sleep = 1; | ||
296 | mg->chip.dev = dev; | ||
297 | |||
298 | mutex_init(&mg->buslock); | ||
299 | |||
300 | retval = gpiochip_add(&mg->chip); | ||
301 | if (retval) { | ||
302 | dev_err(dev, "Adding MSIC gpio chip failed\n"); | ||
303 | goto err; | ||
304 | } | ||
305 | |||
306 | for (i = 0; i < mg->chip.ngpio; i++) { | ||
307 | irq_set_chip_data(i + mg->irq_base, mg); | ||
308 | irq_set_chip_and_handler_name(i + mg->irq_base, | ||
309 | &msic_irqchip, | ||
310 | handle_simple_irq, | ||
311 | "demux"); | ||
312 | } | ||
313 | irq_set_chained_handler(mg->irq, msic_gpio_irq_handler); | ||
314 | irq_set_handler_data(mg->irq, mg); | ||
315 | |||
316 | return 0; | ||
317 | err: | ||
318 | kfree(mg); | ||
319 | return retval; | ||
320 | } | ||
321 | |||
322 | static struct platform_driver platform_msic_gpio_driver = { | ||
323 | .driver = { | ||
324 | .name = "msic_gpio", | ||
325 | .owner = THIS_MODULE, | ||
326 | }, | ||
327 | .probe = platform_msic_gpio_probe, | ||
328 | }; | ||
329 | |||
330 | static int __init platform_msic_gpio_init(void) | ||
331 | { | ||
332 | return platform_driver_register(&platform_msic_gpio_driver); | ||
333 | } | ||
334 | |||
335 | subsys_initcall(platform_msic_gpio_init); | ||
336 | |||
337 | MODULE_AUTHOR("Mathias Nyman <mathias.nyman@linux.intel.com>"); | ||
338 | MODULE_DESCRIPTION("Intel Medfield MSIC GPIO driver"); | ||
339 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/gpio/gpio-msm-v2.c b/drivers/gpio/gpio-msm-v2.c index 55a7e7769af..5cb1227d69c 100644 --- a/drivers/gpio/gpio-msm-v2.c +++ b/drivers/gpio/gpio-msm-v2.c | |||
@@ -317,7 +317,9 @@ static void msm_summary_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
317 | 317 | ||
318 | chained_irq_enter(chip, desc); | 318 | chained_irq_enter(chip, desc); |
319 | 319 | ||
320 | for_each_set_bit(i, msm_gpio.enabled_irqs, NR_GPIO_IRQS) { | 320 | for (i = find_first_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS); |
321 | i < NR_GPIO_IRQS; | ||
322 | i = find_next_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS, i + 1)) { | ||
321 | if (readl(GPIO_INTR_STATUS(i)) & BIT(INTR_STATUS)) | 323 | if (readl(GPIO_INTR_STATUS(i)) & BIT(INTR_STATUS)) |
322 | generic_handle_irq(msm_gpio_to_irq(&msm_gpio.gpio_chip, | 324 | generic_handle_irq(msm_gpio_to_irq(&msm_gpio.gpio_chip, |
323 | i)); | 325 | i)); |
@@ -352,7 +354,7 @@ static struct irq_chip msm_gpio_irq_chip = { | |||
352 | .irq_set_wake = msm_gpio_irq_set_wake, | 354 | .irq_set_wake = msm_gpio_irq_set_wake, |
353 | }; | 355 | }; |
354 | 356 | ||
355 | static int msm_gpio_probe(struct platform_device *dev) | 357 | static int __devinit msm_gpio_probe(struct platform_device *dev) |
356 | { | 358 | { |
357 | int i, irq, ret; | 359 | int i, irq, ret; |
358 | 360 | ||
@@ -376,7 +378,7 @@ static int msm_gpio_probe(struct platform_device *dev) | |||
376 | return 0; | 378 | return 0; |
377 | } | 379 | } |
378 | 380 | ||
379 | static int msm_gpio_remove(struct platform_device *dev) | 381 | static int __devexit msm_gpio_remove(struct platform_device *dev) |
380 | { | 382 | { |
381 | int ret = gpiochip_remove(&msm_gpio.gpio_chip); | 383 | int ret = gpiochip_remove(&msm_gpio.gpio_chip); |
382 | 384 | ||
@@ -390,7 +392,7 @@ static int msm_gpio_remove(struct platform_device *dev) | |||
390 | 392 | ||
391 | static struct platform_driver msm_gpio_driver = { | 393 | static struct platform_driver msm_gpio_driver = { |
392 | .probe = msm_gpio_probe, | 394 | .probe = msm_gpio_probe, |
393 | .remove = msm_gpio_remove, | 395 | .remove = __devexit_p(msm_gpio_remove), |
394 | .driver = { | 396 | .driver = { |
395 | .name = "msmgpio", | 397 | .name = "msmgpio", |
396 | .owner = THIS_MODULE, | 398 | .owner = THIS_MODULE, |
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c deleted file mode 100644 index 7d9bd94be8d..00000000000 --- a/drivers/gpio/gpio-mvebu.c +++ /dev/null | |||
@@ -1,691 +0,0 @@ | |||
1 | /* | ||
2 | * GPIO driver for Marvell SoCs | ||
3 | * | ||
4 | * Copyright (C) 2012 Marvell | ||
5 | * | ||
6 | * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | ||
7 | * Andrew Lunn <andrew@lunn.ch> | ||
8 | * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> | ||
9 | * | ||
10 | * This file is licensed under the terms of the GNU General Public | ||
11 | * License version 2. This program is licensed "as is" without any | ||
12 | * warranty of any kind, whether express or implied. | ||
13 | * | ||
14 | * This driver is a fairly straightforward GPIO driver for the | ||
15 | * complete family of Marvell EBU SoC platforms (Orion, Dove, | ||
16 | * Kirkwood, Discovery, Armada 370/XP). The only complexity of this | ||
17 | * driver is the different register layout that exists between the | ||
18 | * non-SMP platforms (Orion, Dove, Kirkwood, Armada 370) and the SMP | ||
19 | * platforms (MV78200 from the Discovery family and the Armada | ||
20 | * XP). Therefore, this driver handles three variants of the GPIO | ||
21 | * block: | ||
22 | * - the basic variant, called "orion-gpio", with the simplest | ||
23 | * register set. Used on Orion, Dove, Kirkwoord, Armada 370 and | ||
24 | * non-SMP Discovery systems | ||
25 | * - the mv78200 variant for MV78200 Discovery systems. This variant | ||
26 | * turns the edge mask and level mask registers into CPU0 edge | ||
27 | * mask/level mask registers, and adds CPU1 edge mask/level mask | ||
28 | * registers. | ||
29 | * - the armadaxp variant for Armada XP systems. This variant keeps | ||
30 | * the normal cause/edge mask/level mask registers when the global | ||
31 | * interrupts are used, but adds per-CPU cause/edge mask/level mask | ||
32 | * registers n a separate memory area for the per-CPU GPIO | ||
33 | * interrupts. | ||
34 | */ | ||
35 | |||
36 | #include <linux/module.h> | ||
37 | #include <linux/gpio.h> | ||
38 | #include <linux/irq.h> | ||
39 | #include <linux/slab.h> | ||
40 | #include <linux/irqdomain.h> | ||
41 | #include <linux/io.h> | ||
42 | #include <linux/of_irq.h> | ||
43 | #include <linux/of_device.h> | ||
44 | #include <linux/pinctrl/consumer.h> | ||
45 | |||
46 | /* | ||
47 | * GPIO unit register offsets. | ||
48 | */ | ||
49 | #define GPIO_OUT_OFF 0x0000 | ||
50 | #define GPIO_IO_CONF_OFF 0x0004 | ||
51 | #define GPIO_BLINK_EN_OFF 0x0008 | ||
52 | #define GPIO_IN_POL_OFF 0x000c | ||
53 | #define GPIO_DATA_IN_OFF 0x0010 | ||
54 | #define GPIO_EDGE_CAUSE_OFF 0x0014 | ||
55 | #define GPIO_EDGE_MASK_OFF 0x0018 | ||
56 | #define GPIO_LEVEL_MASK_OFF 0x001c | ||
57 | |||
58 | /* The MV78200 has per-CPU registers for edge mask and level mask */ | ||
59 | #define GPIO_EDGE_MASK_MV78200_OFF(cpu) ((cpu) ? 0x30 : 0x18) | ||
60 | #define GPIO_LEVEL_MASK_MV78200_OFF(cpu) ((cpu) ? 0x34 : 0x1C) | ||
61 | |||
62 | /* The Armada XP has per-CPU registers for interrupt cause, interrupt | ||
63 | * mask and interrupt level mask. Those are relative to the | ||
64 | * percpu_membase. */ | ||
65 | #define GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu) ((cpu) * 0x4) | ||
66 | #define GPIO_EDGE_MASK_ARMADAXP_OFF(cpu) (0x10 + (cpu) * 0x4) | ||
67 | #define GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu) (0x20 + (cpu) * 0x4) | ||
68 | |||
69 | #define MVEBU_GPIO_SOC_VARIANT_ORION 0x1 | ||
70 | #define MVEBU_GPIO_SOC_VARIANT_MV78200 0x2 | ||
71 | #define MVEBU_GPIO_SOC_VARIANT_ARMADAXP 0x3 | ||
72 | |||
73 | #define MVEBU_MAX_GPIO_PER_BANK 32 | ||
74 | |||
75 | struct mvebu_gpio_chip { | ||
76 | struct gpio_chip chip; | ||
77 | spinlock_t lock; | ||
78 | void __iomem *membase; | ||
79 | void __iomem *percpu_membase; | ||
80 | unsigned int irqbase; | ||
81 | struct irq_domain *domain; | ||
82 | int soc_variant; | ||
83 | }; | ||
84 | |||
85 | /* | ||
86 | * Functions returning addresses of individual registers for a given | ||
87 | * GPIO controller. | ||
88 | */ | ||
89 | static inline void __iomem *mvebu_gpioreg_out(struct mvebu_gpio_chip *mvchip) | ||
90 | { | ||
91 | return mvchip->membase + GPIO_OUT_OFF; | ||
92 | } | ||
93 | |||
94 | static inline void __iomem *mvebu_gpioreg_blink(struct mvebu_gpio_chip *mvchip) | ||
95 | { | ||
96 | return mvchip->membase + GPIO_BLINK_EN_OFF; | ||
97 | } | ||
98 | |||
99 | static inline void __iomem *mvebu_gpioreg_io_conf(struct mvebu_gpio_chip *mvchip) | ||
100 | { | ||
101 | return mvchip->membase + GPIO_IO_CONF_OFF; | ||
102 | } | ||
103 | |||
104 | static inline void __iomem *mvebu_gpioreg_in_pol(struct mvebu_gpio_chip *mvchip) | ||
105 | { | ||
106 | return mvchip->membase + GPIO_IN_POL_OFF; | ||
107 | } | ||
108 | |||
109 | static inline void __iomem *mvebu_gpioreg_data_in(struct mvebu_gpio_chip *mvchip) | ||
110 | { | ||
111 | return mvchip->membase + GPIO_DATA_IN_OFF; | ||
112 | } | ||
113 | |||
114 | static inline void __iomem *mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvchip) | ||
115 | { | ||
116 | int cpu; | ||
117 | |||
118 | switch(mvchip->soc_variant) { | ||
119 | case MVEBU_GPIO_SOC_VARIANT_ORION: | ||
120 | case MVEBU_GPIO_SOC_VARIANT_MV78200: | ||
121 | return mvchip->membase + GPIO_EDGE_CAUSE_OFF; | ||
122 | case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: | ||
123 | cpu = smp_processor_id(); | ||
124 | return mvchip->percpu_membase + GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu); | ||
125 | default: | ||
126 | BUG(); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | static inline void __iomem *mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvchip) | ||
131 | { | ||
132 | int cpu; | ||
133 | |||
134 | switch(mvchip->soc_variant) { | ||
135 | case MVEBU_GPIO_SOC_VARIANT_ORION: | ||
136 | return mvchip->membase + GPIO_EDGE_MASK_OFF; | ||
137 | case MVEBU_GPIO_SOC_VARIANT_MV78200: | ||
138 | cpu = smp_processor_id(); | ||
139 | return mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(cpu); | ||
140 | case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: | ||
141 | cpu = smp_processor_id(); | ||
142 | return mvchip->percpu_membase + GPIO_EDGE_MASK_ARMADAXP_OFF(cpu); | ||
143 | default: | ||
144 | BUG(); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | static void __iomem *mvebu_gpioreg_level_mask(struct mvebu_gpio_chip *mvchip) | ||
149 | { | ||
150 | int cpu; | ||
151 | |||
152 | switch(mvchip->soc_variant) { | ||
153 | case MVEBU_GPIO_SOC_VARIANT_ORION: | ||
154 | return mvchip->membase + GPIO_LEVEL_MASK_OFF; | ||
155 | case MVEBU_GPIO_SOC_VARIANT_MV78200: | ||
156 | cpu = smp_processor_id(); | ||
157 | return mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(cpu); | ||
158 | case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: | ||
159 | cpu = smp_processor_id(); | ||
160 | return mvchip->percpu_membase + GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu); | ||
161 | default: | ||
162 | BUG(); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | /* | ||
167 | * Functions implementing the gpio_chip methods | ||
168 | */ | ||
169 | |||
170 | static int mvebu_gpio_request(struct gpio_chip *chip, unsigned pin) | ||
171 | { | ||
172 | return pinctrl_request_gpio(chip->base + pin); | ||
173 | } | ||
174 | |||
175 | static void mvebu_gpio_free(struct gpio_chip *chip, unsigned pin) | ||
176 | { | ||
177 | pinctrl_free_gpio(chip->base + pin); | ||
178 | } | ||
179 | |||
180 | static void mvebu_gpio_set(struct gpio_chip *chip, unsigned pin, int value) | ||
181 | { | ||
182 | struct mvebu_gpio_chip *mvchip = | ||
183 | container_of(chip, struct mvebu_gpio_chip, chip); | ||
184 | unsigned long flags; | ||
185 | u32 u; | ||
186 | |||
187 | spin_lock_irqsave(&mvchip->lock, flags); | ||
188 | u = readl_relaxed(mvebu_gpioreg_out(mvchip)); | ||
189 | if (value) | ||
190 | u |= 1 << pin; | ||
191 | else | ||
192 | u &= ~(1 << pin); | ||
193 | writel_relaxed(u, mvebu_gpioreg_out(mvchip)); | ||
194 | spin_unlock_irqrestore(&mvchip->lock, flags); | ||
195 | } | ||
196 | |||
197 | static int mvebu_gpio_get(struct gpio_chip *chip, unsigned pin) | ||
198 | { | ||
199 | struct mvebu_gpio_chip *mvchip = | ||
200 | container_of(chip, struct mvebu_gpio_chip, chip); | ||
201 | u32 u; | ||
202 | |||
203 | if (readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin)) { | ||
204 | u = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) ^ | ||
205 | readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); | ||
206 | } else { | ||
207 | u = readl_relaxed(mvebu_gpioreg_out(mvchip)); | ||
208 | } | ||
209 | |||
210 | return (u >> pin) & 1; | ||
211 | } | ||
212 | |||
213 | static void mvebu_gpio_blink(struct gpio_chip *chip, unsigned pin, int value) | ||
214 | { | ||
215 | struct mvebu_gpio_chip *mvchip = | ||
216 | container_of(chip, struct mvebu_gpio_chip, chip); | ||
217 | unsigned long flags; | ||
218 | u32 u; | ||
219 | |||
220 | spin_lock_irqsave(&mvchip->lock, flags); | ||
221 | u = readl_relaxed(mvebu_gpioreg_blink(mvchip)); | ||
222 | if (value) | ||
223 | u |= 1 << pin; | ||
224 | else | ||
225 | u &= ~(1 << pin); | ||
226 | writel_relaxed(u, mvebu_gpioreg_blink(mvchip)); | ||
227 | spin_unlock_irqrestore(&mvchip->lock, flags); | ||
228 | } | ||
229 | |||
230 | static int mvebu_gpio_direction_input(struct gpio_chip *chip, unsigned pin) | ||
231 | { | ||
232 | struct mvebu_gpio_chip *mvchip = | ||
233 | container_of(chip, struct mvebu_gpio_chip, chip); | ||
234 | unsigned long flags; | ||
235 | int ret; | ||
236 | u32 u; | ||
237 | |||
238 | /* Check with the pinctrl driver whether this pin is usable as | ||
239 | * an input GPIO */ | ||
240 | ret = pinctrl_gpio_direction_input(chip->base + pin); | ||
241 | if (ret) | ||
242 | return ret; | ||
243 | |||
244 | spin_lock_irqsave(&mvchip->lock, flags); | ||
245 | u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)); | ||
246 | u |= 1 << pin; | ||
247 | writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip)); | ||
248 | spin_unlock_irqrestore(&mvchip->lock, flags); | ||
249 | |||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | static int mvebu_gpio_direction_output(struct gpio_chip *chip, unsigned pin, | ||
254 | int value) | ||
255 | { | ||
256 | struct mvebu_gpio_chip *mvchip = | ||
257 | container_of(chip, struct mvebu_gpio_chip, chip); | ||
258 | unsigned long flags; | ||
259 | int ret; | ||
260 | u32 u; | ||
261 | |||
262 | /* Check with the pinctrl driver whether this pin is usable as | ||
263 | * an output GPIO */ | ||
264 | ret = pinctrl_gpio_direction_output(chip->base + pin); | ||
265 | if (ret) | ||
266 | return ret; | ||
267 | |||
268 | mvebu_gpio_blink(chip, pin, 0); | ||
269 | mvebu_gpio_set(chip, pin, value); | ||
270 | |||
271 | spin_lock_irqsave(&mvchip->lock, flags); | ||
272 | u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)); | ||
273 | u &= ~(1 << pin); | ||
274 | writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip)); | ||
275 | spin_unlock_irqrestore(&mvchip->lock, flags); | ||
276 | |||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned pin) | ||
281 | { | ||
282 | struct mvebu_gpio_chip *mvchip = | ||
283 | container_of(chip, struct mvebu_gpio_chip, chip); | ||
284 | return irq_create_mapping(mvchip->domain, pin); | ||
285 | } | ||
286 | |||
287 | /* | ||
288 | * Functions implementing the irq_chip methods | ||
289 | */ | ||
290 | static void mvebu_gpio_irq_ack(struct irq_data *d) | ||
291 | { | ||
292 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
293 | struct mvebu_gpio_chip *mvchip = gc->private; | ||
294 | u32 mask = ~(1 << (d->irq - gc->irq_base)); | ||
295 | |||
296 | irq_gc_lock(gc); | ||
297 | writel_relaxed(mask, mvebu_gpioreg_edge_cause(mvchip)); | ||
298 | irq_gc_unlock(gc); | ||
299 | } | ||
300 | |||
301 | static void mvebu_gpio_edge_irq_mask(struct irq_data *d) | ||
302 | { | ||
303 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
304 | struct mvebu_gpio_chip *mvchip = gc->private; | ||
305 | u32 mask = 1 << (d->irq - gc->irq_base); | ||
306 | |||
307 | irq_gc_lock(gc); | ||
308 | gc->mask_cache &= ~mask; | ||
309 | writel_relaxed(gc->mask_cache, mvebu_gpioreg_edge_mask(mvchip)); | ||
310 | irq_gc_unlock(gc); | ||
311 | } | ||
312 | |||
313 | static void mvebu_gpio_edge_irq_unmask(struct irq_data *d) | ||
314 | { | ||
315 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
316 | struct mvebu_gpio_chip *mvchip = gc->private; | ||
317 | u32 mask = 1 << (d->irq - gc->irq_base); | ||
318 | |||
319 | irq_gc_lock(gc); | ||
320 | gc->mask_cache |= mask; | ||
321 | writel_relaxed(gc->mask_cache, mvebu_gpioreg_edge_mask(mvchip)); | ||
322 | irq_gc_unlock(gc); | ||
323 | } | ||
324 | |||
325 | static void mvebu_gpio_level_irq_mask(struct irq_data *d) | ||
326 | { | ||
327 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
328 | struct mvebu_gpio_chip *mvchip = gc->private; | ||
329 | u32 mask = 1 << (d->irq - gc->irq_base); | ||
330 | |||
331 | irq_gc_lock(gc); | ||
332 | gc->mask_cache &= ~mask; | ||
333 | writel_relaxed(gc->mask_cache, mvebu_gpioreg_level_mask(mvchip)); | ||
334 | irq_gc_unlock(gc); | ||
335 | } | ||
336 | |||
337 | static void mvebu_gpio_level_irq_unmask(struct irq_data *d) | ||
338 | { | ||
339 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
340 | struct mvebu_gpio_chip *mvchip = gc->private; | ||
341 | u32 mask = 1 << (d->irq - gc->irq_base); | ||
342 | |||
343 | irq_gc_lock(gc); | ||
344 | gc->mask_cache |= mask; | ||
345 | writel_relaxed(gc->mask_cache, mvebu_gpioreg_level_mask(mvchip)); | ||
346 | irq_gc_unlock(gc); | ||
347 | } | ||
348 | |||
349 | /***************************************************************************** | ||
350 | * MVEBU GPIO IRQ | ||
351 | * | ||
352 | * GPIO_IN_POL register controls whether GPIO_DATA_IN will hold the same | ||
353 | * value of the line or the opposite value. | ||
354 | * | ||
355 | * Level IRQ handlers: DATA_IN is used directly as cause register. | ||
356 | * Interrupt are masked by LEVEL_MASK registers. | ||
357 | * Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE. | ||
358 | * Interrupt are masked by EDGE_MASK registers. | ||
359 | * Both-edge handlers: Similar to regular Edge handlers, but also swaps | ||
360 | * the polarity to catch the next line transaction. | ||
361 | * This is a race condition that might not perfectly | ||
362 | * work on some use cases. | ||
363 | * | ||
364 | * Every eight GPIO lines are grouped (OR'ed) before going up to main | ||
365 | * cause register. | ||
366 | * | ||
367 | * EDGE cause mask | ||
368 | * data-in /--------| |-----| |----\ | ||
369 | * -----| |----- ---- to main cause reg | ||
370 | * X \----------------| |----/ | ||
371 | * polarity LEVEL mask | ||
372 | * | ||
373 | ****************************************************************************/ | ||
374 | |||
375 | static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type) | ||
376 | { | ||
377 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
378 | struct irq_chip_type *ct = irq_data_get_chip_type(d); | ||
379 | struct mvebu_gpio_chip *mvchip = gc->private; | ||
380 | int pin; | ||
381 | u32 u; | ||
382 | |||
383 | pin = d->hwirq; | ||
384 | |||
385 | u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin); | ||
386 | if (!u) { | ||
387 | return -EINVAL; | ||
388 | } | ||
389 | |||
390 | type &= IRQ_TYPE_SENSE_MASK; | ||
391 | if (type == IRQ_TYPE_NONE) | ||
392 | return -EINVAL; | ||
393 | |||
394 | /* Check if we need to change chip and handler */ | ||
395 | if (!(ct->type & type)) | ||
396 | if (irq_setup_alt_chip(d, type)) | ||
397 | return -EINVAL; | ||
398 | |||
399 | /* | ||
400 | * Configure interrupt polarity. | ||
401 | */ | ||
402 | switch(type) { | ||
403 | case IRQ_TYPE_EDGE_RISING: | ||
404 | case IRQ_TYPE_LEVEL_HIGH: | ||
405 | u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); | ||
406 | u &= ~(1 << pin); | ||
407 | writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); | ||
408 | break; | ||
409 | case IRQ_TYPE_EDGE_FALLING: | ||
410 | case IRQ_TYPE_LEVEL_LOW: | ||
411 | u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); | ||
412 | u |= 1 << pin; | ||
413 | writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); | ||
414 | break; | ||
415 | case IRQ_TYPE_EDGE_BOTH: { | ||
416 | u32 v; | ||
417 | |||
418 | v = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)) ^ | ||
419 | readl_relaxed(mvebu_gpioreg_data_in(mvchip)); | ||
420 | |||
421 | /* | ||
422 | * set initial polarity based on current input level | ||
423 | */ | ||
424 | u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); | ||
425 | if (v & (1 << pin)) | ||
426 | u |= 1 << pin; /* falling */ | ||
427 | else | ||
428 | u &= ~(1 << pin); /* rising */ | ||
429 | writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip)); | ||
430 | break; | ||
431 | } | ||
432 | } | ||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | static void mvebu_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | ||
437 | { | ||
438 | struct mvebu_gpio_chip *mvchip = irq_get_handler_data(irq); | ||
439 | u32 cause, type; | ||
440 | int i; | ||
441 | |||
442 | if (mvchip == NULL) | ||
443 | return; | ||
444 | |||
445 | cause = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) & | ||
446 | readl_relaxed(mvebu_gpioreg_level_mask(mvchip)); | ||
447 | cause |= readl_relaxed(mvebu_gpioreg_edge_cause(mvchip)) & | ||
448 | readl_relaxed(mvebu_gpioreg_edge_mask(mvchip)); | ||
449 | |||
450 | for (i = 0; i < mvchip->chip.ngpio; i++) { | ||
451 | int irq; | ||
452 | |||
453 | irq = mvchip->irqbase + i; | ||
454 | |||
455 | if (!(cause & (1 << i))) | ||
456 | continue; | ||
457 | |||
458 | type = irqd_get_trigger_type(irq_get_irq_data(irq)); | ||
459 | if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) { | ||
460 | /* Swap polarity (race with GPIO line) */ | ||
461 | u32 polarity; | ||
462 | |||
463 | polarity = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); | ||
464 | polarity ^= 1 << i; | ||
465 | writel_relaxed(polarity, mvebu_gpioreg_in_pol(mvchip)); | ||
466 | } | ||
467 | generic_handle_irq(irq); | ||
468 | } | ||
469 | } | ||
470 | |||
471 | static struct of_device_id mvebu_gpio_of_match[] = { | ||
472 | { | ||
473 | .compatible = "marvell,orion-gpio", | ||
474 | .data = (void*) MVEBU_GPIO_SOC_VARIANT_ORION, | ||
475 | }, | ||
476 | { | ||
477 | .compatible = "marvell,mv78200-gpio", | ||
478 | .data = (void*) MVEBU_GPIO_SOC_VARIANT_MV78200, | ||
479 | }, | ||
480 | { | ||
481 | .compatible = "marvell,armadaxp-gpio", | ||
482 | .data = (void*) MVEBU_GPIO_SOC_VARIANT_ARMADAXP, | ||
483 | }, | ||
484 | { | ||
485 | /* sentinel */ | ||
486 | }, | ||
487 | }; | ||
488 | MODULE_DEVICE_TABLE(of, mvebu_gpio_of_match); | ||
489 | |||
490 | static int mvebu_gpio_probe(struct platform_device *pdev) | ||
491 | { | ||
492 | struct mvebu_gpio_chip *mvchip; | ||
493 | const struct of_device_id *match; | ||
494 | struct device_node *np = pdev->dev.of_node; | ||
495 | struct resource *res; | ||
496 | struct irq_chip_generic *gc; | ||
497 | struct irq_chip_type *ct; | ||
498 | unsigned int ngpios; | ||
499 | int soc_variant; | ||
500 | int i, cpu, id; | ||
501 | |||
502 | match = of_match_device(mvebu_gpio_of_match, &pdev->dev); | ||
503 | if (match) | ||
504 | soc_variant = (int) match->data; | ||
505 | else | ||
506 | soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; | ||
507 | |||
508 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
509 | if (! res) { | ||
510 | dev_err(&pdev->dev, "Cannot get memory resource\n"); | ||
511 | return -ENODEV; | ||
512 | } | ||
513 | |||
514 | mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL); | ||
515 | if (! mvchip){ | ||
516 | dev_err(&pdev->dev, "Cannot allocate memory\n"); | ||
517 | return -ENOMEM; | ||
518 | } | ||
519 | |||
520 | if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) { | ||
521 | dev_err(&pdev->dev, "Missing ngpios OF property\n"); | ||
522 | return -ENODEV; | ||
523 | } | ||
524 | |||
525 | id = of_alias_get_id(pdev->dev.of_node, "gpio"); | ||
526 | if (id < 0) { | ||
527 | dev_err(&pdev->dev, "Couldn't get OF id\n"); | ||
528 | return id; | ||
529 | } | ||
530 | |||
531 | mvchip->soc_variant = soc_variant; | ||
532 | mvchip->chip.label = dev_name(&pdev->dev); | ||
533 | mvchip->chip.dev = &pdev->dev; | ||
534 | mvchip->chip.request = mvebu_gpio_request; | ||
535 | mvchip->chip.free = mvebu_gpio_free; | ||
536 | mvchip->chip.direction_input = mvebu_gpio_direction_input; | ||
537 | mvchip->chip.get = mvebu_gpio_get; | ||
538 | mvchip->chip.direction_output = mvebu_gpio_direction_output; | ||
539 | mvchip->chip.set = mvebu_gpio_set; | ||
540 | mvchip->chip.to_irq = mvebu_gpio_to_irq; | ||
541 | mvchip->chip.base = id * MVEBU_MAX_GPIO_PER_BANK; | ||
542 | mvchip->chip.ngpio = ngpios; | ||
543 | mvchip->chip.can_sleep = 0; | ||
544 | mvchip->chip.of_node = np; | ||
545 | |||
546 | spin_lock_init(&mvchip->lock); | ||
547 | mvchip->membase = devm_request_and_ioremap(&pdev->dev, res); | ||
548 | if (! mvchip->membase) { | ||
549 | dev_err(&pdev->dev, "Cannot ioremap\n"); | ||
550 | kfree(mvchip->chip.label); | ||
551 | return -ENOMEM; | ||
552 | } | ||
553 | |||
554 | /* The Armada XP has a second range of registers for the | ||
555 | * per-CPU registers */ | ||
556 | if (soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) { | ||
557 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
558 | if (! res) { | ||
559 | dev_err(&pdev->dev, "Cannot get memory resource\n"); | ||
560 | kfree(mvchip->chip.label); | ||
561 | return -ENODEV; | ||
562 | } | ||
563 | |||
564 | mvchip->percpu_membase = devm_request_and_ioremap(&pdev->dev, res); | ||
565 | if (! mvchip->percpu_membase) { | ||
566 | dev_err(&pdev->dev, "Cannot ioremap\n"); | ||
567 | kfree(mvchip->chip.label); | ||
568 | return -ENOMEM; | ||
569 | } | ||
570 | } | ||
571 | |||
572 | /* | ||
573 | * Mask and clear GPIO interrupts. | ||
574 | */ | ||
575 | switch(soc_variant) { | ||
576 | case MVEBU_GPIO_SOC_VARIANT_ORION: | ||
577 | writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF); | ||
578 | writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF); | ||
579 | writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF); | ||
580 | break; | ||
581 | case MVEBU_GPIO_SOC_VARIANT_MV78200: | ||
582 | writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF); | ||
583 | for (cpu = 0; cpu < 2; cpu++) { | ||
584 | writel_relaxed(0, mvchip->membase + | ||
585 | GPIO_EDGE_MASK_MV78200_OFF(cpu)); | ||
586 | writel_relaxed(0, mvchip->membase + | ||
587 | GPIO_LEVEL_MASK_MV78200_OFF(cpu)); | ||
588 | } | ||
589 | break; | ||
590 | case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: | ||
591 | writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF); | ||
592 | writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF); | ||
593 | writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF); | ||
594 | for (cpu = 0; cpu < 4; cpu++) { | ||
595 | writel_relaxed(0, mvchip->percpu_membase + | ||
596 | GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu)); | ||
597 | writel_relaxed(0, mvchip->percpu_membase + | ||
598 | GPIO_EDGE_MASK_ARMADAXP_OFF(cpu)); | ||
599 | writel_relaxed(0, mvchip->percpu_membase + | ||
600 | GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu)); | ||
601 | } | ||
602 | break; | ||
603 | default: | ||
604 | BUG(); | ||
605 | } | ||
606 | |||
607 | gpiochip_add(&mvchip->chip); | ||
608 | |||
609 | /* Some gpio controllers do not provide irq support */ | ||
610 | if (!of_irq_count(np)) | ||
611 | return 0; | ||
612 | |||
613 | /* Setup the interrupt handlers. Each chip can have up to 4 | ||
614 | * interrupt handlers, with each handler dealing with 8 GPIO | ||
615 | * pins. */ | ||
616 | for (i = 0; i < 4; i++) { | ||
617 | int irq; | ||
618 | irq = platform_get_irq(pdev, i); | ||
619 | if (irq < 0) | ||
620 | continue; | ||
621 | irq_set_handler_data(irq, mvchip); | ||
622 | irq_set_chained_handler(irq, mvebu_gpio_irq_handler); | ||
623 | } | ||
624 | |||
625 | mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1); | ||
626 | if (mvchip->irqbase < 0) { | ||
627 | dev_err(&pdev->dev, "no irqs\n"); | ||
628 | kfree(mvchip->chip.label); | ||
629 | return -ENOMEM; | ||
630 | } | ||
631 | |||
632 | gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase, | ||
633 | mvchip->membase, handle_level_irq); | ||
634 | if (! gc) { | ||
635 | dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n"); | ||
636 | kfree(mvchip->chip.label); | ||
637 | return -ENOMEM; | ||
638 | } | ||
639 | |||
640 | gc->private = mvchip; | ||
641 | ct = &gc->chip_types[0]; | ||
642 | ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW; | ||
643 | ct->chip.irq_mask = mvebu_gpio_level_irq_mask; | ||
644 | ct->chip.irq_unmask = mvebu_gpio_level_irq_unmask; | ||
645 | ct->chip.irq_set_type = mvebu_gpio_irq_set_type; | ||
646 | ct->chip.name = mvchip->chip.label; | ||
647 | |||
648 | ct = &gc->chip_types[1]; | ||
649 | ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; | ||
650 | ct->chip.irq_ack = mvebu_gpio_irq_ack; | ||
651 | ct->chip.irq_mask = mvebu_gpio_edge_irq_mask; | ||
652 | ct->chip.irq_unmask = mvebu_gpio_edge_irq_unmask; | ||
653 | ct->chip.irq_set_type = mvebu_gpio_irq_set_type; | ||
654 | ct->handler = handle_edge_irq; | ||
655 | ct->chip.name = mvchip->chip.label; | ||
656 | |||
657 | irq_setup_generic_chip(gc, IRQ_MSK(ngpios), 0, | ||
658 | IRQ_NOREQUEST, IRQ_LEVEL | IRQ_NOPROBE); | ||
659 | |||
660 | /* Setup irq domain on top of the generic chip. */ | ||
661 | mvchip->domain = irq_domain_add_simple(np, mvchip->chip.ngpio, | ||
662 | mvchip->irqbase, | ||
663 | &irq_domain_simple_ops, | ||
664 | mvchip); | ||
665 | if (!mvchip->domain) { | ||
666 | dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n", | ||
667 | mvchip->chip.label); | ||
668 | irq_remove_generic_chip(gc, IRQ_MSK(ngpios), IRQ_NOREQUEST, | ||
669 | IRQ_LEVEL | IRQ_NOPROBE); | ||
670 | kfree(gc); | ||
671 | kfree(mvchip->chip.label); | ||
672 | return -ENODEV; | ||
673 | } | ||
674 | |||
675 | return 0; | ||
676 | } | ||
677 | |||
678 | static struct platform_driver mvebu_gpio_driver = { | ||
679 | .driver = { | ||
680 | .name = "mvebu-gpio", | ||
681 | .owner = THIS_MODULE, | ||
682 | .of_match_table = mvebu_gpio_of_match, | ||
683 | }, | ||
684 | .probe = mvebu_gpio_probe, | ||
685 | }; | ||
686 | |||
687 | static int __init mvebu_gpio_init(void) | ||
688 | { | ||
689 | return platform_driver_register(&mvebu_gpio_driver); | ||
690 | } | ||
691 | postcore_initcall(mvebu_gpio_init); | ||
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index 7877335c4cc..4340acae3bd 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c | |||
@@ -23,22 +23,18 @@ | |||
23 | #include <linux/interrupt.h> | 23 | #include <linux/interrupt.h> |
24 | #include <linux/io.h> | 24 | #include <linux/io.h> |
25 | #include <linux/irq.h> | 25 | #include <linux/irq.h> |
26 | #include <linux/irqdomain.h> | ||
27 | #include <linux/gpio.h> | 26 | #include <linux/gpio.h> |
28 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
29 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
30 | #include <linux/basic_mmio_gpio.h> | 29 | #include <linux/basic_mmio_gpio.h> |
31 | #include <linux/of.h> | 30 | #include <linux/of.h> |
32 | #include <linux/of_device.h> | 31 | #include <linux/of_device.h> |
33 | #include <linux/module.h> | ||
34 | #include <asm-generic/bug.h> | 32 | #include <asm-generic/bug.h> |
35 | #include <asm/mach/irq.h> | ||
36 | 33 | ||
37 | enum mxc_gpio_hwtype { | 34 | enum mxc_gpio_hwtype { |
38 | IMX1_GPIO, /* runs on i.mx1 */ | 35 | IMX1_GPIO, /* runs on i.mx1 */ |
39 | IMX21_GPIO, /* runs on i.mx21 and i.mx27 */ | 36 | IMX21_GPIO, /* runs on i.mx21 and i.mx27 */ |
40 | IMX31_GPIO, /* runs on i.mx31 */ | 37 | IMX31_GPIO, /* runs on all other i.mx */ |
41 | IMX35_GPIO, /* runs on all other i.mx */ | ||
42 | }; | 38 | }; |
43 | 39 | ||
44 | /* device type dependent stuff */ | 40 | /* device type dependent stuff */ |
@@ -50,7 +46,6 @@ struct mxc_gpio_hwdata { | |||
50 | unsigned icr2_reg; | 46 | unsigned icr2_reg; |
51 | unsigned imr_reg; | 47 | unsigned imr_reg; |
52 | unsigned isr_reg; | 48 | unsigned isr_reg; |
53 | int edge_sel_reg; | ||
54 | unsigned low_level; | 49 | unsigned low_level; |
55 | unsigned high_level; | 50 | unsigned high_level; |
56 | unsigned rise_edge; | 51 | unsigned rise_edge; |
@@ -62,7 +57,7 @@ struct mxc_gpio_port { | |||
62 | void __iomem *base; | 57 | void __iomem *base; |
63 | int irq; | 58 | int irq; |
64 | int irq_high; | 59 | int irq_high; |
65 | struct irq_domain *domain; | 60 | int virtual_irq_start; |
66 | struct bgpio_chip bgc; | 61 | struct bgpio_chip bgc; |
67 | u32 both_edges; | 62 | u32 both_edges; |
68 | }; | 63 | }; |
@@ -75,7 +70,6 @@ static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = { | |||
75 | .icr2_reg = 0x2c, | 70 | .icr2_reg = 0x2c, |
76 | .imr_reg = 0x30, | 71 | .imr_reg = 0x30, |
77 | .isr_reg = 0x34, | 72 | .isr_reg = 0x34, |
78 | .edge_sel_reg = -EINVAL, | ||
79 | .low_level = 0x03, | 73 | .low_level = 0x03, |
80 | .high_level = 0x02, | 74 | .high_level = 0x02, |
81 | .rise_edge = 0x00, | 75 | .rise_edge = 0x00, |
@@ -90,22 +84,6 @@ static struct mxc_gpio_hwdata imx31_gpio_hwdata = { | |||
90 | .icr2_reg = 0x10, | 84 | .icr2_reg = 0x10, |
91 | .imr_reg = 0x14, | 85 | .imr_reg = 0x14, |
92 | .isr_reg = 0x18, | 86 | .isr_reg = 0x18, |
93 | .edge_sel_reg = -EINVAL, | ||
94 | .low_level = 0x00, | ||
95 | .high_level = 0x01, | ||
96 | .rise_edge = 0x02, | ||
97 | .fall_edge = 0x03, | ||
98 | }; | ||
99 | |||
100 | static struct mxc_gpio_hwdata imx35_gpio_hwdata = { | ||
101 | .dr_reg = 0x00, | ||
102 | .gdir_reg = 0x04, | ||
103 | .psr_reg = 0x08, | ||
104 | .icr1_reg = 0x0c, | ||
105 | .icr2_reg = 0x10, | ||
106 | .imr_reg = 0x14, | ||
107 | .isr_reg = 0x18, | ||
108 | .edge_sel_reg = 0x1c, | ||
109 | .low_level = 0x00, | 87 | .low_level = 0x00, |
110 | .high_level = 0x01, | 88 | .high_level = 0x01, |
111 | .rise_edge = 0x02, | 89 | .rise_edge = 0x02, |
@@ -122,13 +100,12 @@ static struct mxc_gpio_hwdata *mxc_gpio_hwdata; | |||
122 | #define GPIO_ICR2 (mxc_gpio_hwdata->icr2_reg) | 100 | #define GPIO_ICR2 (mxc_gpio_hwdata->icr2_reg) |
123 | #define GPIO_IMR (mxc_gpio_hwdata->imr_reg) | 101 | #define GPIO_IMR (mxc_gpio_hwdata->imr_reg) |
124 | #define GPIO_ISR (mxc_gpio_hwdata->isr_reg) | 102 | #define GPIO_ISR (mxc_gpio_hwdata->isr_reg) |
125 | #define GPIO_EDGE_SEL (mxc_gpio_hwdata->edge_sel_reg) | ||
126 | 103 | ||
127 | #define GPIO_INT_LOW_LEV (mxc_gpio_hwdata->low_level) | 104 | #define GPIO_INT_LOW_LEV (mxc_gpio_hwdata->low_level) |
128 | #define GPIO_INT_HIGH_LEV (mxc_gpio_hwdata->high_level) | 105 | #define GPIO_INT_HIGH_LEV (mxc_gpio_hwdata->high_level) |
129 | #define GPIO_INT_RISE_EDGE (mxc_gpio_hwdata->rise_edge) | 106 | #define GPIO_INT_RISE_EDGE (mxc_gpio_hwdata->rise_edge) |
130 | #define GPIO_INT_FALL_EDGE (mxc_gpio_hwdata->fall_edge) | 107 | #define GPIO_INT_FALL_EDGE (mxc_gpio_hwdata->fall_edge) |
131 | #define GPIO_INT_BOTH_EDGES 0x4 | 108 | #define GPIO_INT_NONE 0x4 |
132 | 109 | ||
133 | static struct platform_device_id mxc_gpio_devtype[] = { | 110 | static struct platform_device_id mxc_gpio_devtype[] = { |
134 | { | 111 | { |
@@ -141,9 +118,6 @@ static struct platform_device_id mxc_gpio_devtype[] = { | |||
141 | .name = "imx31-gpio", | 118 | .name = "imx31-gpio", |
142 | .driver_data = IMX31_GPIO, | 119 | .driver_data = IMX31_GPIO, |
143 | }, { | 120 | }, { |
144 | .name = "imx35-gpio", | ||
145 | .driver_data = IMX35_GPIO, | ||
146 | }, { | ||
147 | /* sentinel */ | 121 | /* sentinel */ |
148 | } | 122 | } |
149 | }; | 123 | }; |
@@ -152,7 +126,6 @@ static const struct of_device_id mxc_gpio_dt_ids[] = { | |||
152 | { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devtype[IMX1_GPIO], }, | 126 | { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devtype[IMX1_GPIO], }, |
153 | { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, | 127 | { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], }, |
154 | { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, | 128 | { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], }, |
155 | { .compatible = "fsl,imx35-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], }, | ||
156 | { /* sentinel */ } | 129 | { /* sentinel */ } |
157 | }; | 130 | }; |
158 | 131 | ||
@@ -167,15 +140,14 @@ static LIST_HEAD(mxc_gpio_ports); | |||
167 | 140 | ||
168 | static int gpio_set_irq_type(struct irq_data *d, u32 type) | 141 | static int gpio_set_irq_type(struct irq_data *d, u32 type) |
169 | { | 142 | { |
143 | u32 gpio = irq_to_gpio(d->irq); | ||
170 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | 144 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
171 | struct mxc_gpio_port *port = gc->private; | 145 | struct mxc_gpio_port *port = gc->private; |
172 | u32 bit, val; | 146 | u32 bit, val; |
173 | u32 gpio_idx = d->hwirq; | ||
174 | u32 gpio = port->bgc.gc.base + gpio_idx; | ||
175 | int edge; | 147 | int edge; |
176 | void __iomem *reg = port->base; | 148 | void __iomem *reg = port->base; |
177 | 149 | ||
178 | port->both_edges &= ~(1 << gpio_idx); | 150 | port->both_edges &= ~(1 << (gpio & 31)); |
179 | switch (type) { | 151 | switch (type) { |
180 | case IRQ_TYPE_EDGE_RISING: | 152 | case IRQ_TYPE_EDGE_RISING: |
181 | edge = GPIO_INT_RISE_EDGE; | 153 | edge = GPIO_INT_RISE_EDGE; |
@@ -184,19 +156,15 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type) | |||
184 | edge = GPIO_INT_FALL_EDGE; | 156 | edge = GPIO_INT_FALL_EDGE; |
185 | break; | 157 | break; |
186 | case IRQ_TYPE_EDGE_BOTH: | 158 | case IRQ_TYPE_EDGE_BOTH: |
187 | if (GPIO_EDGE_SEL >= 0) { | 159 | val = gpio_get_value(gpio); |
188 | edge = GPIO_INT_BOTH_EDGES; | 160 | if (val) { |
161 | edge = GPIO_INT_LOW_LEV; | ||
162 | pr_debug("mxc: set GPIO %d to low trigger\n", gpio); | ||
189 | } else { | 163 | } else { |
190 | val = gpio_get_value(gpio); | 164 | edge = GPIO_INT_HIGH_LEV; |
191 | if (val) { | 165 | pr_debug("mxc: set GPIO %d to high trigger\n", gpio); |
192 | edge = GPIO_INT_LOW_LEV; | ||
193 | pr_debug("mxc: set GPIO %d to low trigger\n", gpio); | ||
194 | } else { | ||
195 | edge = GPIO_INT_HIGH_LEV; | ||
196 | pr_debug("mxc: set GPIO %d to high trigger\n", gpio); | ||
197 | } | ||
198 | port->both_edges |= 1 << gpio_idx; | ||
199 | } | 166 | } |
167 | port->both_edges |= 1 << (gpio & 31); | ||
200 | break; | 168 | break; |
201 | case IRQ_TYPE_LEVEL_LOW: | 169 | case IRQ_TYPE_LEVEL_LOW: |
202 | edge = GPIO_INT_LOW_LEV; | 170 | edge = GPIO_INT_LOW_LEV; |
@@ -208,24 +176,11 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type) | |||
208 | return -EINVAL; | 176 | return -EINVAL; |
209 | } | 177 | } |
210 | 178 | ||
211 | if (GPIO_EDGE_SEL >= 0) { | 179 | reg += GPIO_ICR1 + ((gpio & 0x10) >> 2); /* lower or upper register */ |
212 | val = readl(port->base + GPIO_EDGE_SEL); | 180 | bit = gpio & 0xf; |
213 | if (edge == GPIO_INT_BOTH_EDGES) | 181 | val = readl(reg) & ~(0x3 << (bit << 1)); |
214 | writel(val | (1 << gpio_idx), | 182 | writel(val | (edge << (bit << 1)), reg); |
215 | port->base + GPIO_EDGE_SEL); | 183 | writel(1 << (gpio & 0x1f), port->base + GPIO_ISR); |
216 | else | ||
217 | writel(val & ~(1 << gpio_idx), | ||
218 | port->base + GPIO_EDGE_SEL); | ||
219 | } | ||
220 | |||
221 | if (edge != GPIO_INT_BOTH_EDGES) { | ||
222 | reg += GPIO_ICR1 + ((gpio_idx & 0x10) >> 2); /* lower or upper register */ | ||
223 | bit = gpio_idx & 0xf; | ||
224 | val = readl(reg) & ~(0x3 << (bit << 1)); | ||
225 | writel(val | (edge << (bit << 1)), reg); | ||
226 | } | ||
227 | |||
228 | writel(1 << gpio_idx, port->base + GPIO_ISR); | ||
229 | 184 | ||
230 | return 0; | 185 | return 0; |
231 | } | 186 | } |
@@ -258,13 +213,15 @@ static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio) | |||
258 | /* handle 32 interrupts in one status register */ | 213 | /* handle 32 interrupts in one status register */ |
259 | static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat) | 214 | static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat) |
260 | { | 215 | { |
216 | u32 gpio_irq_no_base = port->virtual_irq_start; | ||
217 | |||
261 | while (irq_stat != 0) { | 218 | while (irq_stat != 0) { |
262 | int irqoffset = fls(irq_stat) - 1; | 219 | int irqoffset = fls(irq_stat) - 1; |
263 | 220 | ||
264 | if (port->both_edges & (1 << irqoffset)) | 221 | if (port->both_edges & (1 << irqoffset)) |
265 | mxc_flip_edge(port, irqoffset); | 222 | mxc_flip_edge(port, irqoffset); |
266 | 223 | ||
267 | generic_handle_irq(irq_find_mapping(port->domain, irqoffset)); | 224 | generic_handle_irq(gpio_irq_no_base + irqoffset); |
268 | 225 | ||
269 | irq_stat &= ~(1 << irqoffset); | 226 | irq_stat &= ~(1 << irqoffset); |
270 | } | 227 | } |
@@ -275,15 +232,10 @@ static void mx3_gpio_irq_handler(u32 irq, struct irq_desc *desc) | |||
275 | { | 232 | { |
276 | u32 irq_stat; | 233 | u32 irq_stat; |
277 | struct mxc_gpio_port *port = irq_get_handler_data(irq); | 234 | struct mxc_gpio_port *port = irq_get_handler_data(irq); |
278 | struct irq_chip *chip = irq_get_chip(irq); | ||
279 | |||
280 | chained_irq_enter(chip, desc); | ||
281 | 235 | ||
282 | irq_stat = readl(port->base + GPIO_ISR) & readl(port->base + GPIO_IMR); | 236 | irq_stat = readl(port->base + GPIO_ISR) & readl(port->base + GPIO_IMR); |
283 | 237 | ||
284 | mxc_gpio_irq_handler(port, irq_stat); | 238 | mxc_gpio_irq_handler(port, irq_stat); |
285 | |||
286 | chained_irq_exit(chip, desc); | ||
287 | } | 239 | } |
288 | 240 | ||
289 | /* MX2 has one interrupt *for all* gpio ports */ | 241 | /* MX2 has one interrupt *for all* gpio ports */ |
@@ -315,9 +267,10 @@ static void mx2_gpio_irq_handler(u32 irq, struct irq_desc *desc) | |||
315 | */ | 267 | */ |
316 | static int gpio_set_wake_irq(struct irq_data *d, u32 enable) | 268 | static int gpio_set_wake_irq(struct irq_data *d, u32 enable) |
317 | { | 269 | { |
270 | u32 gpio = irq_to_gpio(d->irq); | ||
271 | u32 gpio_idx = gpio & 0x1F; | ||
318 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | 272 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
319 | struct mxc_gpio_port *port = gc->private; | 273 | struct mxc_gpio_port *port = gc->private; |
320 | u32 gpio_idx = d->hwirq; | ||
321 | 274 | ||
322 | if (enable) { | 275 | if (enable) { |
323 | if (port->irq_high && (gpio_idx >= 16)) | 276 | if (port->irq_high && (gpio_idx >= 16)) |
@@ -334,12 +287,12 @@ static int gpio_set_wake_irq(struct irq_data *d, u32 enable) | |||
334 | return 0; | 287 | return 0; |
335 | } | 288 | } |
336 | 289 | ||
337 | static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base) | 290 | static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port) |
338 | { | 291 | { |
339 | struct irq_chip_generic *gc; | 292 | struct irq_chip_generic *gc; |
340 | struct irq_chip_type *ct; | 293 | struct irq_chip_type *ct; |
341 | 294 | ||
342 | gc = irq_alloc_generic_chip("gpio-mxc", 1, irq_base, | 295 | gc = irq_alloc_generic_chip("gpio-mxc", 1, port->virtual_irq_start, |
343 | port->base, handle_level_irq); | 296 | port->base, handle_level_irq); |
344 | gc->private = port; | 297 | gc->private = port; |
345 | 298 | ||
@@ -356,7 +309,7 @@ static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base) | |||
356 | IRQ_NOREQUEST, 0); | 309 | IRQ_NOREQUEST, 0); |
357 | } | 310 | } |
358 | 311 | ||
359 | static void mxc_gpio_get_hw(struct platform_device *pdev) | 312 | static void __devinit mxc_gpio_get_hw(struct platform_device *pdev) |
360 | { | 313 | { |
361 | const struct of_device_id *of_id = | 314 | const struct of_device_id *of_id = |
362 | of_match_device(mxc_gpio_dt_ids, &pdev->dev); | 315 | of_match_device(mxc_gpio_dt_ids, &pdev->dev); |
@@ -376,9 +329,7 @@ static void mxc_gpio_get_hw(struct platform_device *pdev) | |||
376 | return; | 329 | return; |
377 | } | 330 | } |
378 | 331 | ||
379 | if (hwtype == IMX35_GPIO) | 332 | if (hwtype == IMX31_GPIO) |
380 | mxc_gpio_hwdata = &imx35_gpio_hwdata; | ||
381 | else if (hwtype == IMX31_GPIO) | ||
382 | mxc_gpio_hwdata = &imx31_gpio_hwdata; | 333 | mxc_gpio_hwdata = &imx31_gpio_hwdata; |
383 | else | 334 | else |
384 | mxc_gpio_hwdata = &imx1_imx21_gpio_hwdata; | 335 | mxc_gpio_hwdata = &imx1_imx21_gpio_hwdata; |
@@ -386,21 +337,11 @@ static void mxc_gpio_get_hw(struct platform_device *pdev) | |||
386 | mxc_gpio_hwtype = hwtype; | 337 | mxc_gpio_hwtype = hwtype; |
387 | } | 338 | } |
388 | 339 | ||
389 | static int mxc_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | 340 | static int __devinit mxc_gpio_probe(struct platform_device *pdev) |
390 | { | ||
391 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
392 | struct mxc_gpio_port *port = | ||
393 | container_of(bgc, struct mxc_gpio_port, bgc); | ||
394 | |||
395 | return irq_find_mapping(port->domain, offset); | ||
396 | } | ||
397 | |||
398 | static int mxc_gpio_probe(struct platform_device *pdev) | ||
399 | { | 341 | { |
400 | struct device_node *np = pdev->dev.of_node; | 342 | struct device_node *np = pdev->dev.of_node; |
401 | struct mxc_gpio_port *port; | 343 | struct mxc_gpio_port *port; |
402 | struct resource *iores; | 344 | struct resource *iores; |
403 | int irq_base; | ||
404 | int err; | 345 | int err; |
405 | 346 | ||
406 | mxc_gpio_get_hw(pdev); | 347 | mxc_gpio_get_hw(pdev); |
@@ -439,12 +380,10 @@ static int mxc_gpio_probe(struct platform_device *pdev) | |||
439 | writel(~0, port->base + GPIO_ISR); | 380 | writel(~0, port->base + GPIO_ISR); |
440 | 381 | ||
441 | if (mxc_gpio_hwtype == IMX21_GPIO) { | 382 | if (mxc_gpio_hwtype == IMX21_GPIO) { |
442 | /* | 383 | /* setup one handler for all GPIO interrupts */ |
443 | * Setup one handler for all GPIO interrupts. Actually setting | 384 | if (pdev->id == 0) |
444 | * the handler is needed only once, but doing it for every port | 385 | irq_set_chained_handler(port->irq, |
445 | * is more robust and easier. | 386 | mx2_gpio_irq_handler); |
446 | */ | ||
447 | irq_set_chained_handler(port->irq, mx2_gpio_irq_handler); | ||
448 | } else { | 387 | } else { |
449 | /* setup one handler for each entry */ | 388 | /* setup one handler for each entry */ |
450 | irq_set_chained_handler(port->irq, mx3_gpio_irq_handler); | 389 | irq_set_chained_handler(port->irq, mx3_gpio_irq_handler); |
@@ -460,42 +399,32 @@ static int mxc_gpio_probe(struct platform_device *pdev) | |||
460 | err = bgpio_init(&port->bgc, &pdev->dev, 4, | 399 | err = bgpio_init(&port->bgc, &pdev->dev, 4, |
461 | port->base + GPIO_PSR, | 400 | port->base + GPIO_PSR, |
462 | port->base + GPIO_DR, NULL, | 401 | port->base + GPIO_DR, NULL, |
463 | port->base + GPIO_GDIR, NULL, 0); | 402 | port->base + GPIO_GDIR, NULL, false); |
464 | if (err) | 403 | if (err) |
465 | goto out_iounmap; | 404 | goto out_iounmap; |
466 | 405 | ||
467 | port->bgc.gc.to_irq = mxc_gpio_to_irq; | 406 | port->bgc.gc.base = pdev->id * 32; |
468 | port->bgc.gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : | 407 | port->bgc.dir = port->bgc.read_reg(port->bgc.reg_dir); |
469 | pdev->id * 32; | 408 | port->bgc.data = port->bgc.read_reg(port->bgc.reg_set); |
470 | 409 | ||
471 | err = gpiochip_add(&port->bgc.gc); | 410 | err = gpiochip_add(&port->bgc.gc); |
472 | if (err) | 411 | if (err) |
473 | goto out_bgpio_remove; | 412 | goto out_bgpio_remove; |
474 | 413 | ||
475 | irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); | 414 | /* |
476 | if (irq_base < 0) { | 415 | * In dt case, we use gpio number range dynamically |
477 | err = irq_base; | 416 | * allocated by gpio core. |
478 | goto out_gpiochip_remove; | 417 | */ |
479 | } | 418 | port->virtual_irq_start = MXC_GPIO_IRQ_START + (np ? port->bgc.gc.base : |
480 | 419 | pdev->id * 32); | |
481 | port->domain = irq_domain_add_legacy(np, 32, irq_base, 0, | ||
482 | &irq_domain_simple_ops, NULL); | ||
483 | if (!port->domain) { | ||
484 | err = -ENODEV; | ||
485 | goto out_irqdesc_free; | ||
486 | } | ||
487 | 420 | ||
488 | /* gpio-mxc can be a generic irq chip */ | 421 | /* gpio-mxc can be a generic irq chip */ |
489 | mxc_gpio_init_gc(port, irq_base); | 422 | mxc_gpio_init_gc(port); |
490 | 423 | ||
491 | list_add_tail(&port->node, &mxc_gpio_ports); | 424 | list_add_tail(&port->node, &mxc_gpio_ports); |
492 | 425 | ||
493 | return 0; | 426 | return 0; |
494 | 427 | ||
495 | out_irqdesc_free: | ||
496 | irq_free_descs(irq_base, 32); | ||
497 | out_gpiochip_remove: | ||
498 | WARN_ON(gpiochip_remove(&port->bgc.gc) < 0); | ||
499 | out_bgpio_remove: | 428 | out_bgpio_remove: |
500 | bgpio_remove(&port->bgc); | 429 | bgpio_remove(&port->bgc); |
501 | out_iounmap: | 430 | out_iounmap: |
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c index fa2a63cad32..af55a8577c2 100644 --- a/drivers/gpio/gpio-mxs.c +++ b/drivers/gpio/gpio-mxs.c | |||
@@ -24,27 +24,23 @@ | |||
24 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/io.h> | 25 | #include <linux/io.h> |
26 | #include <linux/irq.h> | 26 | #include <linux/irq.h> |
27 | #include <linux/irqdomain.h> | ||
28 | #include <linux/gpio.h> | 27 | #include <linux/gpio.h> |
29 | #include <linux/of.h> | ||
30 | #include <linux/of_address.h> | ||
31 | #include <linux/of_device.h> | ||
32 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
33 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
34 | #include <linux/basic_mmio_gpio.h> | 30 | #include <linux/basic_mmio_gpio.h> |
35 | #include <linux/module.h> | 31 | #include <mach/mxs.h> |
36 | 32 | ||
37 | #define MXS_SET 0x4 | 33 | #define MXS_SET 0x4 |
38 | #define MXS_CLR 0x8 | 34 | #define MXS_CLR 0x8 |
39 | 35 | ||
40 | #define PINCTRL_DOUT(p) ((is_imx23_gpio(p) ? 0x0500 : 0x0700) + (p->id) * 0x10) | 36 | #define PINCTRL_DOUT(n) ((cpu_is_mx23() ? 0x0500 : 0x0700) + (n) * 0x10) |
41 | #define PINCTRL_DIN(p) ((is_imx23_gpio(p) ? 0x0600 : 0x0900) + (p->id) * 0x10) | 37 | #define PINCTRL_DIN(n) ((cpu_is_mx23() ? 0x0600 : 0x0900) + (n) * 0x10) |
42 | #define PINCTRL_DOE(p) ((is_imx23_gpio(p) ? 0x0700 : 0x0b00) + (p->id) * 0x10) | 38 | #define PINCTRL_DOE(n) ((cpu_is_mx23() ? 0x0700 : 0x0b00) + (n) * 0x10) |
43 | #define PINCTRL_PIN2IRQ(p) ((is_imx23_gpio(p) ? 0x0800 : 0x1000) + (p->id) * 0x10) | 39 | #define PINCTRL_PIN2IRQ(n) ((cpu_is_mx23() ? 0x0800 : 0x1000) + (n) * 0x10) |
44 | #define PINCTRL_IRQEN(p) ((is_imx23_gpio(p) ? 0x0900 : 0x1100) + (p->id) * 0x10) | 40 | #define PINCTRL_IRQEN(n) ((cpu_is_mx23() ? 0x0900 : 0x1100) + (n) * 0x10) |
45 | #define PINCTRL_IRQLEV(p) ((is_imx23_gpio(p) ? 0x0a00 : 0x1200) + (p->id) * 0x10) | 41 | #define PINCTRL_IRQLEV(n) ((cpu_is_mx23() ? 0x0a00 : 0x1200) + (n) * 0x10) |
46 | #define PINCTRL_IRQPOL(p) ((is_imx23_gpio(p) ? 0x0b00 : 0x1300) + (p->id) * 0x10) | 42 | #define PINCTRL_IRQPOL(n) ((cpu_is_mx23() ? 0x0b00 : 0x1300) + (n) * 0x10) |
47 | #define PINCTRL_IRQSTAT(p) ((is_imx23_gpio(p) ? 0x0c00 : 0x1400) + (p->id) * 0x10) | 43 | #define PINCTRL_IRQSTAT(n) ((cpu_is_mx23() ? 0x0c00 : 0x1400) + (n) * 0x10) |
48 | 44 | ||
49 | #define GPIO_INT_FALL_EDGE 0x0 | 45 | #define GPIO_INT_FALL_EDGE 0x0 |
50 | #define GPIO_INT_LOW_LEV 0x1 | 46 | #define GPIO_INT_LOW_LEV 0x1 |
@@ -53,35 +49,20 @@ | |||
53 | #define GPIO_INT_LEV_MASK (1 << 0) | 49 | #define GPIO_INT_LEV_MASK (1 << 0) |
54 | #define GPIO_INT_POL_MASK (1 << 1) | 50 | #define GPIO_INT_POL_MASK (1 << 1) |
55 | 51 | ||
56 | enum mxs_gpio_id { | ||
57 | IMX23_GPIO, | ||
58 | IMX28_GPIO, | ||
59 | }; | ||
60 | |||
61 | struct mxs_gpio_port { | 52 | struct mxs_gpio_port { |
62 | void __iomem *base; | 53 | void __iomem *base; |
63 | int id; | 54 | int id; |
64 | int irq; | 55 | int irq; |
65 | struct irq_domain *domain; | 56 | int virtual_irq_start; |
66 | struct bgpio_chip bgc; | 57 | struct bgpio_chip bgc; |
67 | enum mxs_gpio_id devid; | ||
68 | }; | 58 | }; |
69 | 59 | ||
70 | static inline int is_imx23_gpio(struct mxs_gpio_port *port) | ||
71 | { | ||
72 | return port->devid == IMX23_GPIO; | ||
73 | } | ||
74 | |||
75 | static inline int is_imx28_gpio(struct mxs_gpio_port *port) | ||
76 | { | ||
77 | return port->devid == IMX28_GPIO; | ||
78 | } | ||
79 | |||
80 | /* Note: This driver assumes 32 GPIOs are handled in one register */ | 60 | /* Note: This driver assumes 32 GPIOs are handled in one register */ |
81 | 61 | ||
82 | static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) | 62 | static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) |
83 | { | 63 | { |
84 | u32 pin_mask = 1 << d->hwirq; | 64 | u32 gpio = irq_to_gpio(d->irq); |
65 | u32 pin_mask = 1 << (gpio & 31); | ||
85 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | 66 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); |
86 | struct mxs_gpio_port *port = gc->private; | 67 | struct mxs_gpio_port *port = gc->private; |
87 | void __iomem *pin_addr; | 68 | void __iomem *pin_addr; |
@@ -105,21 +86,21 @@ static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) | |||
105 | } | 86 | } |
106 | 87 | ||
107 | /* set level or edge */ | 88 | /* set level or edge */ |
108 | pin_addr = port->base + PINCTRL_IRQLEV(port); | 89 | pin_addr = port->base + PINCTRL_IRQLEV(port->id); |
109 | if (edge & GPIO_INT_LEV_MASK) | 90 | if (edge & GPIO_INT_LEV_MASK) |
110 | writel(pin_mask, pin_addr + MXS_SET); | 91 | writel(pin_mask, pin_addr + MXS_SET); |
111 | else | 92 | else |
112 | writel(pin_mask, pin_addr + MXS_CLR); | 93 | writel(pin_mask, pin_addr + MXS_CLR); |
113 | 94 | ||
114 | /* set polarity */ | 95 | /* set polarity */ |
115 | pin_addr = port->base + PINCTRL_IRQPOL(port); | 96 | pin_addr = port->base + PINCTRL_IRQPOL(port->id); |
116 | if (edge & GPIO_INT_POL_MASK) | 97 | if (edge & GPIO_INT_POL_MASK) |
117 | writel(pin_mask, pin_addr + MXS_SET); | 98 | writel(pin_mask, pin_addr + MXS_SET); |
118 | else | 99 | else |
119 | writel(pin_mask, pin_addr + MXS_CLR); | 100 | writel(pin_mask, pin_addr + MXS_CLR); |
120 | 101 | ||
121 | writel(pin_mask, | 102 | writel(1 << (gpio & 0x1f), |
122 | port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); | 103 | port->base + PINCTRL_IRQSTAT(port->id) + MXS_CLR); |
123 | 104 | ||
124 | return 0; | 105 | return 0; |
125 | } | 106 | } |
@@ -129,15 +110,16 @@ static void mxs_gpio_irq_handler(u32 irq, struct irq_desc *desc) | |||
129 | { | 110 | { |
130 | u32 irq_stat; | 111 | u32 irq_stat; |
131 | struct mxs_gpio_port *port = irq_get_handler_data(irq); | 112 | struct mxs_gpio_port *port = irq_get_handler_data(irq); |
113 | u32 gpio_irq_no_base = port->virtual_irq_start; | ||
132 | 114 | ||
133 | desc->irq_data.chip->irq_ack(&desc->irq_data); | 115 | desc->irq_data.chip->irq_ack(&desc->irq_data); |
134 | 116 | ||
135 | irq_stat = readl(port->base + PINCTRL_IRQSTAT(port)) & | 117 | irq_stat = readl(port->base + PINCTRL_IRQSTAT(port->id)) & |
136 | readl(port->base + PINCTRL_IRQEN(port)); | 118 | readl(port->base + PINCTRL_IRQEN(port->id)); |
137 | 119 | ||
138 | while (irq_stat != 0) { | 120 | while (irq_stat != 0) { |
139 | int irqoffset = fls(irq_stat) - 1; | 121 | int irqoffset = fls(irq_stat) - 1; |
140 | generic_handle_irq(irq_find_mapping(port->domain, irqoffset)); | 122 | generic_handle_irq(gpio_irq_no_base + irqoffset); |
141 | irq_stat &= ~(1 << irqoffset); | 123 | irq_stat &= ~(1 << irqoffset); |
142 | } | 124 | } |
143 | } | 125 | } |
@@ -164,12 +146,12 @@ static int mxs_gpio_set_wake_irq(struct irq_data *d, unsigned int enable) | |||
164 | return 0; | 146 | return 0; |
165 | } | 147 | } |
166 | 148 | ||
167 | static void __init mxs_gpio_init_gc(struct mxs_gpio_port *port, int irq_base) | 149 | static void __init mxs_gpio_init_gc(struct mxs_gpio_port *port) |
168 | { | 150 | { |
169 | struct irq_chip_generic *gc; | 151 | struct irq_chip_generic *gc; |
170 | struct irq_chip_type *ct; | 152 | struct irq_chip_type *ct; |
171 | 153 | ||
172 | gc = irq_alloc_generic_chip("gpio-mxs", 1, irq_base, | 154 | gc = irq_alloc_generic_chip("gpio-mxs", 1, port->virtual_irq_start, |
173 | port->base, handle_level_irq); | 155 | port->base, handle_level_irq); |
174 | gc->private = port; | 156 | gc->private = port; |
175 | 157 | ||
@@ -179,8 +161,8 @@ static void __init mxs_gpio_init_gc(struct mxs_gpio_port *port, int irq_base) | |||
179 | ct->chip.irq_unmask = irq_gc_mask_set_bit; | 161 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
180 | ct->chip.irq_set_type = mxs_gpio_set_irq_type; | 162 | ct->chip.irq_set_type = mxs_gpio_set_irq_type; |
181 | ct->chip.irq_set_wake = mxs_gpio_set_wake_irq; | 163 | ct->chip.irq_set_wake = mxs_gpio_set_wake_irq; |
182 | ct->regs.ack = PINCTRL_IRQSTAT(port) + MXS_CLR; | 164 | ct->regs.ack = PINCTRL_IRQSTAT(port->id) + MXS_CLR; |
183 | ct->regs.mask = PINCTRL_IRQEN(port); | 165 | ct->regs.mask = PINCTRL_IRQEN(port->id); |
184 | 166 | ||
185 | irq_setup_generic_chip(gc, IRQ_MSK(32), 0, IRQ_NOREQUEST, 0); | 167 | irq_setup_generic_chip(gc, IRQ_MSK(32), 0, IRQ_NOREQUEST, 0); |
186 | } | 168 | } |
@@ -191,111 +173,77 @@ static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | |||
191 | struct mxs_gpio_port *port = | 173 | struct mxs_gpio_port *port = |
192 | container_of(bgc, struct mxs_gpio_port, bgc); | 174 | container_of(bgc, struct mxs_gpio_port, bgc); |
193 | 175 | ||
194 | return irq_find_mapping(port->domain, offset); | 176 | return port->virtual_irq_start + offset; |
195 | } | 177 | } |
196 | 178 | ||
197 | static struct platform_device_id mxs_gpio_ids[] = { | 179 | static int __devinit mxs_gpio_probe(struct platform_device *pdev) |
198 | { | ||
199 | .name = "imx23-gpio", | ||
200 | .driver_data = IMX23_GPIO, | ||
201 | }, { | ||
202 | .name = "imx28-gpio", | ||
203 | .driver_data = IMX28_GPIO, | ||
204 | }, { | ||
205 | /* sentinel */ | ||
206 | } | ||
207 | }; | ||
208 | MODULE_DEVICE_TABLE(platform, mxs_gpio_ids); | ||
209 | |||
210 | static const struct of_device_id mxs_gpio_dt_ids[] = { | ||
211 | { .compatible = "fsl,imx23-gpio", .data = (void *) IMX23_GPIO, }, | ||
212 | { .compatible = "fsl,imx28-gpio", .data = (void *) IMX28_GPIO, }, | ||
213 | { /* sentinel */ } | ||
214 | }; | ||
215 | MODULE_DEVICE_TABLE(of, mxs_gpio_dt_ids); | ||
216 | |||
217 | static int mxs_gpio_probe(struct platform_device *pdev) | ||
218 | { | 180 | { |
219 | const struct of_device_id *of_id = | ||
220 | of_match_device(mxs_gpio_dt_ids, &pdev->dev); | ||
221 | struct device_node *np = pdev->dev.of_node; | ||
222 | struct device_node *parent; | ||
223 | static void __iomem *base; | 181 | static void __iomem *base; |
224 | struct mxs_gpio_port *port; | 182 | struct mxs_gpio_port *port; |
225 | struct resource *iores = NULL; | 183 | struct resource *iores = NULL; |
226 | int irq_base; | ||
227 | int err; | 184 | int err; |
228 | 185 | ||
229 | port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); | 186 | port = kzalloc(sizeof(struct mxs_gpio_port), GFP_KERNEL); |
230 | if (!port) | 187 | if (!port) |
231 | return -ENOMEM; | 188 | return -ENOMEM; |
232 | 189 | ||
233 | if (np) { | 190 | port->id = pdev->id; |
234 | port->id = of_alias_get_id(np, "gpio"); | 191 | port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32; |
235 | if (port->id < 0) | ||
236 | return port->id; | ||
237 | port->devid = (enum mxs_gpio_id) of_id->data; | ||
238 | } else { | ||
239 | port->id = pdev->id; | ||
240 | port->devid = pdev->id_entry->driver_data; | ||
241 | } | ||
242 | |||
243 | port->irq = platform_get_irq(pdev, 0); | ||
244 | if (port->irq < 0) | ||
245 | return port->irq; | ||
246 | 192 | ||
247 | /* | 193 | /* |
248 | * map memory region only once, as all the gpio ports | 194 | * map memory region only once, as all the gpio ports |
249 | * share the same one | 195 | * share the same one |
250 | */ | 196 | */ |
251 | if (!base) { | 197 | if (!base) { |
252 | if (np) { | 198 | iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
253 | parent = of_get_parent(np); | 199 | if (!iores) { |
254 | base = of_iomap(parent, 0); | 200 | err = -ENODEV; |
255 | of_node_put(parent); | 201 | goto out_kfree; |
256 | } else { | 202 | } |
257 | iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 203 | |
258 | base = devm_request_and_ioremap(&pdev->dev, iores); | 204 | if (!request_mem_region(iores->start, resource_size(iores), |
205 | pdev->name)) { | ||
206 | err = -EBUSY; | ||
207 | goto out_kfree; | ||
208 | } | ||
209 | |||
210 | base = ioremap(iores->start, resource_size(iores)); | ||
211 | if (!base) { | ||
212 | err = -ENOMEM; | ||
213 | goto out_release_mem; | ||
259 | } | 214 | } |
260 | if (!base) | ||
261 | return -EADDRNOTAVAIL; | ||
262 | } | 215 | } |
263 | port->base = base; | 216 | port->base = base; |
264 | 217 | ||
218 | port->irq = platform_get_irq(pdev, 0); | ||
219 | if (port->irq < 0) { | ||
220 | err = -EINVAL; | ||
221 | goto out_iounmap; | ||
222 | } | ||
223 | |||
265 | /* | 224 | /* |
266 | * select the pin interrupt functionality but initially | 225 | * select the pin interrupt functionality but initially |
267 | * disable the interrupts | 226 | * disable the interrupts |
268 | */ | 227 | */ |
269 | writel(~0U, port->base + PINCTRL_PIN2IRQ(port)); | 228 | writel(~0U, port->base + PINCTRL_PIN2IRQ(port->id)); |
270 | writel(0, port->base + PINCTRL_IRQEN(port)); | 229 | writel(0, port->base + PINCTRL_IRQEN(port->id)); |
271 | 230 | ||
272 | /* clear address has to be used to clear IRQSTAT bits */ | 231 | /* clear address has to be used to clear IRQSTAT bits */ |
273 | writel(~0U, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); | 232 | writel(~0U, port->base + PINCTRL_IRQSTAT(port->id) + MXS_CLR); |
274 | |||
275 | irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); | ||
276 | if (irq_base < 0) | ||
277 | return irq_base; | ||
278 | |||
279 | port->domain = irq_domain_add_legacy(np, 32, irq_base, 0, | ||
280 | &irq_domain_simple_ops, NULL); | ||
281 | if (!port->domain) { | ||
282 | err = -ENODEV; | ||
283 | goto out_irqdesc_free; | ||
284 | } | ||
285 | 233 | ||
286 | /* gpio-mxs can be a generic irq chip */ | 234 | /* gpio-mxs can be a generic irq chip */ |
287 | mxs_gpio_init_gc(port, irq_base); | 235 | mxs_gpio_init_gc(port); |
288 | 236 | ||
289 | /* setup one handler for each entry */ | 237 | /* setup one handler for each entry */ |
290 | irq_set_chained_handler(port->irq, mxs_gpio_irq_handler); | 238 | irq_set_chained_handler(port->irq, mxs_gpio_irq_handler); |
291 | irq_set_handler_data(port->irq, port); | 239 | irq_set_handler_data(port->irq, port); |
292 | 240 | ||
293 | err = bgpio_init(&port->bgc, &pdev->dev, 4, | 241 | err = bgpio_init(&port->bgc, &pdev->dev, 4, |
294 | port->base + PINCTRL_DIN(port), | 242 | port->base + PINCTRL_DIN(port->id), |
295 | port->base + PINCTRL_DOUT(port), NULL, | 243 | port->base + PINCTRL_DOUT(port->id), NULL, |
296 | port->base + PINCTRL_DOE(port), NULL, 0); | 244 | port->base + PINCTRL_DOE(port->id), NULL, false); |
297 | if (err) | 245 | if (err) |
298 | goto out_irqdesc_free; | 246 | goto out_iounmap; |
299 | 247 | ||
300 | port->bgc.gc.to_irq = mxs_gpio_to_irq; | 248 | port->bgc.gc.to_irq = mxs_gpio_to_irq; |
301 | port->bgc.gc.base = port->id * 32; | 249 | port->bgc.gc.base = port->id * 32; |
@@ -308,8 +256,15 @@ static int mxs_gpio_probe(struct platform_device *pdev) | |||
308 | 256 | ||
309 | out_bgpio_remove: | 257 | out_bgpio_remove: |
310 | bgpio_remove(&port->bgc); | 258 | bgpio_remove(&port->bgc); |
311 | out_irqdesc_free: | 259 | out_iounmap: |
312 | irq_free_descs(irq_base, 32); | 260 | if (iores) |
261 | iounmap(port->base); | ||
262 | out_release_mem: | ||
263 | if (iores) | ||
264 | release_mem_region(iores->start, resource_size(iores)); | ||
265 | out_kfree: | ||
266 | kfree(port); | ||
267 | dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err); | ||
313 | return err; | 268 | return err; |
314 | } | 269 | } |
315 | 270 | ||
@@ -317,10 +272,8 @@ static struct platform_driver mxs_gpio_driver = { | |||
317 | .driver = { | 272 | .driver = { |
318 | .name = "gpio-mxs", | 273 | .name = "gpio-mxs", |
319 | .owner = THIS_MODULE, | 274 | .owner = THIS_MODULE, |
320 | .of_match_table = mxs_gpio_dt_ids, | ||
321 | }, | 275 | }, |
322 | .probe = mxs_gpio_probe, | 276 | .probe = mxs_gpio_probe, |
323 | .id_table = mxs_gpio_ids, | ||
324 | }; | 277 | }; |
325 | 278 | ||
326 | static int __init mxs_gpio_init(void) | 279 | static int __init mxs_gpio_init(void) |
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index f1fbedb2a6f..118ec12d2d5 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c | |||
@@ -19,46 +19,31 @@ | |||
19 | #include <linux/err.h> | 19 | #include <linux/err.h> |
20 | #include <linux/clk.h> | 20 | #include <linux/clk.h> |
21 | #include <linux/io.h> | 21 | #include <linux/io.h> |
22 | #include <linux/device.h> | 22 | #include <linux/slab.h> |
23 | #include <linux/pm_runtime.h> | 23 | #include <linux/pm_runtime.h> |
24 | #include <linux/pm.h> | ||
25 | #include <linux/of.h> | ||
26 | #include <linux/of_device.h> | ||
27 | #include <linux/irqdomain.h> | ||
28 | #include <linux/gpio.h> | ||
29 | #include <linux/platform_data/gpio-omap.h> | ||
30 | 24 | ||
25 | #include <mach/hardware.h> | ||
26 | #include <asm/irq.h> | ||
27 | #include <mach/irqs.h> | ||
28 | #include <mach/gpio.h> | ||
31 | #include <asm/mach/irq.h> | 29 | #include <asm/mach/irq.h> |
32 | 30 | ||
33 | #define OFF_MODE 1 | ||
34 | |||
35 | static LIST_HEAD(omap_gpio_list); | ||
36 | |||
37 | struct gpio_regs { | ||
38 | u32 irqenable1; | ||
39 | u32 irqenable2; | ||
40 | u32 wake_en; | ||
41 | u32 ctrl; | ||
42 | u32 oe; | ||
43 | u32 leveldetect0; | ||
44 | u32 leveldetect1; | ||
45 | u32 risingdetect; | ||
46 | u32 fallingdetect; | ||
47 | u32 dataout; | ||
48 | u32 debounce; | ||
49 | u32 debounce_en; | ||
50 | }; | ||
51 | |||
52 | struct gpio_bank { | 31 | struct gpio_bank { |
53 | struct list_head node; | 32 | unsigned long pbase; |
54 | void __iomem *base; | 33 | void __iomem *base; |
55 | u16 irq; | 34 | u16 irq; |
56 | int irq_base; | 35 | u16 virtual_irq_start; |
57 | struct irq_domain *domain; | 36 | int method; |
37 | u32 suspend_wakeup; | ||
38 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) | ||
39 | u32 saved_wakeup; | ||
40 | #endif | ||
58 | u32 non_wakeup_gpios; | 41 | u32 non_wakeup_gpios; |
59 | u32 enabled_non_wakeup_gpios; | 42 | u32 enabled_non_wakeup_gpios; |
60 | struct gpio_regs context; | 43 | |
61 | u32 saved_datain; | 44 | u32 saved_datain; |
45 | u32 saved_fallingdetect; | ||
46 | u32 saved_risingdetect; | ||
62 | u32 level_mask; | 47 | u32 level_mask; |
63 | u32 toggle_mask; | 48 | u32 toggle_mask; |
64 | spinlock_t lock; | 49 | spinlock_t lock; |
@@ -66,31 +51,44 @@ struct gpio_bank { | |||
66 | struct clk *dbck; | 51 | struct clk *dbck; |
67 | u32 mod_usage; | 52 | u32 mod_usage; |
68 | u32 dbck_enable_mask; | 53 | u32 dbck_enable_mask; |
69 | bool dbck_enabled; | ||
70 | struct device *dev; | 54 | struct device *dev; |
71 | bool is_mpuio; | ||
72 | bool dbck_flag; | 55 | bool dbck_flag; |
73 | bool loses_context; | ||
74 | int stride; | 56 | int stride; |
75 | u32 width; | 57 | u32 width; |
76 | int context_loss_count; | ||
77 | int power_mode; | ||
78 | bool workaround_enabled; | ||
79 | 58 | ||
80 | void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable); | 59 | void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable); |
81 | int (*get_context_loss_count)(struct device *dev); | ||
82 | 60 | ||
83 | struct omap_gpio_reg_offs *regs; | 61 | struct omap_gpio_reg_offs *regs; |
84 | }; | 62 | }; |
85 | 63 | ||
64 | #ifdef CONFIG_ARCH_OMAP3 | ||
65 | struct omap3_gpio_regs { | ||
66 | u32 irqenable1; | ||
67 | u32 irqenable2; | ||
68 | u32 wake_en; | ||
69 | u32 ctrl; | ||
70 | u32 oe; | ||
71 | u32 leveldetect0; | ||
72 | u32 leveldetect1; | ||
73 | u32 risingdetect; | ||
74 | u32 fallingdetect; | ||
75 | u32 dataout; | ||
76 | }; | ||
77 | |||
78 | static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS]; | ||
79 | #endif | ||
80 | |||
81 | /* | ||
82 | * TODO: Cleanup gpio_bank usage as it is having information | ||
83 | * related to all instances of the device | ||
84 | */ | ||
85 | static struct gpio_bank *gpio_bank; | ||
86 | |||
87 | /* TODO: Analyze removing gpio_bank_count usage from driver code */ | ||
88 | int gpio_bank_count; | ||
89 | |||
86 | #define GPIO_INDEX(bank, gpio) (gpio % bank->width) | 90 | #define GPIO_INDEX(bank, gpio) (gpio % bank->width) |
87 | #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio)) | 91 | #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio)) |
88 | #define GPIO_MOD_CTRL_BIT BIT(0) | ||
89 | |||
90 | static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq) | ||
91 | { | ||
92 | return gpio_irq - bank->irq_base + bank->chip.base; | ||
93 | } | ||
94 | 92 | ||
95 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) | 93 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) |
96 | { | 94 | { |
@@ -104,7 +102,6 @@ static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) | |||
104 | else | 102 | else |
105 | l &= ~(1 << gpio); | 103 | l &= ~(1 << gpio); |
106 | __raw_writel(l, reg); | 104 | __raw_writel(l, reg); |
107 | bank->context.oe = l; | ||
108 | } | 105 | } |
109 | 106 | ||
110 | 107 | ||
@@ -114,13 +111,10 @@ static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable) | |||
114 | void __iomem *reg = bank->base; | 111 | void __iomem *reg = bank->base; |
115 | u32 l = GPIO_BIT(bank, gpio); | 112 | u32 l = GPIO_BIT(bank, gpio); |
116 | 113 | ||
117 | if (enable) { | 114 | if (enable) |
118 | reg += bank->regs->set_dataout; | 115 | reg += bank->regs->set_dataout; |
119 | bank->context.dataout |= l; | 116 | else |
120 | } else { | ||
121 | reg += bank->regs->clr_dataout; | 117 | reg += bank->regs->clr_dataout; |
122 | bank->context.dataout &= ~l; | ||
123 | } | ||
124 | 118 | ||
125 | __raw_writel(l, reg); | 119 | __raw_writel(l, reg); |
126 | } | 120 | } |
@@ -138,60 +132,29 @@ static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable) | |||
138 | else | 132 | else |
139 | l &= ~gpio_bit; | 133 | l &= ~gpio_bit; |
140 | __raw_writel(l, reg); | 134 | __raw_writel(l, reg); |
141 | bank->context.dataout = l; | ||
142 | } | 135 | } |
143 | 136 | ||
144 | static int _get_gpio_datain(struct gpio_bank *bank, int offset) | 137 | static int _get_gpio_datain(struct gpio_bank *bank, int gpio) |
145 | { | 138 | { |
146 | void __iomem *reg = bank->base + bank->regs->datain; | 139 | void __iomem *reg = bank->base + bank->regs->datain; |
147 | 140 | ||
148 | return (__raw_readl(reg) & (1 << offset)) != 0; | 141 | return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; |
149 | } | 142 | } |
150 | 143 | ||
151 | static int _get_gpio_dataout(struct gpio_bank *bank, int offset) | 144 | static int _get_gpio_dataout(struct gpio_bank *bank, int gpio) |
152 | { | 145 | { |
153 | void __iomem *reg = bank->base + bank->regs->dataout; | 146 | void __iomem *reg = bank->base + bank->regs->dataout; |
154 | 147 | ||
155 | return (__raw_readl(reg) & (1 << offset)) != 0; | 148 | return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; |
156 | } | 149 | } |
157 | 150 | ||
158 | static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) | 151 | #define MOD_REG_BIT(reg, bit_mask, set) \ |
159 | { | 152 | do { \ |
160 | int l = __raw_readl(base + reg); | 153 | int l = __raw_readl(base + reg); \ |
161 | 154 | if (set) l |= bit_mask; \ | |
162 | if (set) | 155 | else l &= ~bit_mask; \ |
163 | l |= mask; | 156 | __raw_writel(l, base + reg); \ |
164 | else | 157 | } while(0) |
165 | l &= ~mask; | ||
166 | |||
167 | __raw_writel(l, base + reg); | ||
168 | } | ||
169 | |||
170 | static inline void _gpio_dbck_enable(struct gpio_bank *bank) | ||
171 | { | ||
172 | if (bank->dbck_enable_mask && !bank->dbck_enabled) { | ||
173 | clk_enable(bank->dbck); | ||
174 | bank->dbck_enabled = true; | ||
175 | |||
176 | __raw_writel(bank->dbck_enable_mask, | ||
177 | bank->base + bank->regs->debounce_en); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | static inline void _gpio_dbck_disable(struct gpio_bank *bank) | ||
182 | { | ||
183 | if (bank->dbck_enable_mask && bank->dbck_enabled) { | ||
184 | /* | ||
185 | * Disable debounce before cutting it's clock. If debounce is | ||
186 | * enabled but the clock is not, GPIO module seems to be unable | ||
187 | * to detect events and generate interrupts at least on OMAP3. | ||
188 | */ | ||
189 | __raw_writel(0, bank->base + bank->regs->debounce_en); | ||
190 | |||
191 | clk_disable(bank->dbck); | ||
192 | bank->dbck_enabled = false; | ||
193 | } | ||
194 | } | ||
195 | 158 | ||
196 | /** | 159 | /** |
197 | * _set_gpio_debounce - low level gpio debounce time | 160 | * _set_gpio_debounce - low level gpio debounce time |
@@ -221,108 +184,70 @@ static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, | |||
221 | 184 | ||
222 | l = GPIO_BIT(bank, gpio); | 185 | l = GPIO_BIT(bank, gpio); |
223 | 186 | ||
224 | clk_enable(bank->dbck); | ||
225 | reg = bank->base + bank->regs->debounce; | 187 | reg = bank->base + bank->regs->debounce; |
226 | __raw_writel(debounce, reg); | 188 | __raw_writel(debounce, reg); |
227 | 189 | ||
228 | reg = bank->base + bank->regs->debounce_en; | 190 | reg = bank->base + bank->regs->debounce_en; |
229 | val = __raw_readl(reg); | 191 | val = __raw_readl(reg); |
230 | 192 | ||
231 | if (debounce) | 193 | if (debounce) { |
232 | val |= l; | 194 | val |= l; |
233 | else | 195 | clk_enable(bank->dbck); |
196 | } else { | ||
234 | val &= ~l; | 197 | val &= ~l; |
198 | clk_disable(bank->dbck); | ||
199 | } | ||
235 | bank->dbck_enable_mask = val; | 200 | bank->dbck_enable_mask = val; |
236 | 201 | ||
237 | __raw_writel(val, reg); | 202 | __raw_writel(val, reg); |
238 | clk_disable(bank->dbck); | ||
239 | /* | ||
240 | * Enable debounce clock per module. | ||
241 | * This call is mandatory because in omap_gpio_request() when | ||
242 | * *_runtime_get_sync() is called, _gpio_dbck_enable() within | ||
243 | * runtime callbck fails to turn on dbck because dbck_enable_mask | ||
244 | * used within _gpio_dbck_enable() is still not initialized at | ||
245 | * that point. Therefore we have to enable dbck here. | ||
246 | */ | ||
247 | _gpio_dbck_enable(bank); | ||
248 | if (bank->dbck_enable_mask) { | ||
249 | bank->context.debounce = debounce; | ||
250 | bank->context.debounce_en = val; | ||
251 | } | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * _clear_gpio_debounce - clear debounce settings for a gpio | ||
256 | * @bank: the gpio bank we're acting upon | ||
257 | * @gpio: the gpio number on this @gpio | ||
258 | * | ||
259 | * If a gpio is using debounce, then clear the debounce enable bit and if | ||
260 | * this is the only gpio in this bank using debounce, then clear the debounce | ||
261 | * time too. The debounce clock will also be disabled when calling this function | ||
262 | * if this is the only gpio in the bank using debounce. | ||
263 | */ | ||
264 | static void _clear_gpio_debounce(struct gpio_bank *bank, unsigned gpio) | ||
265 | { | ||
266 | u32 gpio_bit = GPIO_BIT(bank, gpio); | ||
267 | |||
268 | if (!bank->dbck_flag) | ||
269 | return; | ||
270 | |||
271 | if (!(bank->dbck_enable_mask & gpio_bit)) | ||
272 | return; | ||
273 | |||
274 | bank->dbck_enable_mask &= ~gpio_bit; | ||
275 | bank->context.debounce_en &= ~gpio_bit; | ||
276 | __raw_writel(bank->context.debounce_en, | ||
277 | bank->base + bank->regs->debounce_en); | ||
278 | |||
279 | if (!bank->dbck_enable_mask) { | ||
280 | bank->context.debounce = 0; | ||
281 | __raw_writel(bank->context.debounce, bank->base + | ||
282 | bank->regs->debounce); | ||
283 | clk_disable(bank->dbck); | ||
284 | bank->dbck_enabled = false; | ||
285 | } | ||
286 | } | 203 | } |
287 | 204 | ||
288 | static inline void set_gpio_trigger(struct gpio_bank *bank, int gpio, | 205 | #ifdef CONFIG_ARCH_OMAP2PLUS |
289 | unsigned trigger) | 206 | static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio, |
207 | int trigger) | ||
290 | { | 208 | { |
291 | void __iomem *base = bank->base; | 209 | void __iomem *base = bank->base; |
292 | u32 gpio_bit = 1 << gpio; | 210 | u32 gpio_bit = 1 << gpio; |
293 | 211 | ||
294 | _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, | 212 | if (cpu_is_omap44xx()) { |
295 | trigger & IRQ_TYPE_LEVEL_LOW); | 213 | MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit, |
296 | _gpio_rmw(base, bank->regs->leveldetect1, gpio_bit, | 214 | trigger & IRQ_TYPE_LEVEL_LOW); |
297 | trigger & IRQ_TYPE_LEVEL_HIGH); | 215 | MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit, |
298 | _gpio_rmw(base, bank->regs->risingdetect, gpio_bit, | 216 | trigger & IRQ_TYPE_LEVEL_HIGH); |
299 | trigger & IRQ_TYPE_EDGE_RISING); | 217 | MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit, |
300 | _gpio_rmw(base, bank->regs->fallingdetect, gpio_bit, | 218 | trigger & IRQ_TYPE_EDGE_RISING); |
301 | trigger & IRQ_TYPE_EDGE_FALLING); | 219 | MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit, |
302 | 220 | trigger & IRQ_TYPE_EDGE_FALLING); | |
303 | bank->context.leveldetect0 = | 221 | } else { |
304 | __raw_readl(bank->base + bank->regs->leveldetect0); | 222 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit, |
305 | bank->context.leveldetect1 = | 223 | trigger & IRQ_TYPE_LEVEL_LOW); |
306 | __raw_readl(bank->base + bank->regs->leveldetect1); | 224 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit, |
307 | bank->context.risingdetect = | 225 | trigger & IRQ_TYPE_LEVEL_HIGH); |
308 | __raw_readl(bank->base + bank->regs->risingdetect); | 226 | MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit, |
309 | bank->context.fallingdetect = | 227 | trigger & IRQ_TYPE_EDGE_RISING); |
310 | __raw_readl(bank->base + bank->regs->fallingdetect); | 228 | MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit, |
311 | 229 | trigger & IRQ_TYPE_EDGE_FALLING); | |
230 | } | ||
312 | if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { | 231 | if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { |
313 | _gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0); | 232 | if (cpu_is_omap44xx()) { |
314 | bank->context.wake_en = | 233 | MOD_REG_BIT(OMAP4_GPIO_IRQWAKEN0, gpio_bit, |
315 | __raw_readl(bank->base + bank->regs->wkup_en); | 234 | trigger != 0); |
235 | } else { | ||
236 | /* | ||
237 | * GPIO wakeup request can only be generated on edge | ||
238 | * transitions | ||
239 | */ | ||
240 | if (trigger & IRQ_TYPE_EDGE_BOTH) | ||
241 | __raw_writel(1 << gpio, bank->base | ||
242 | + OMAP24XX_GPIO_SETWKUENA); | ||
243 | else | ||
244 | __raw_writel(1 << gpio, bank->base | ||
245 | + OMAP24XX_GPIO_CLEARWKUENA); | ||
246 | } | ||
316 | } | 247 | } |
317 | |||
318 | /* This part needs to be executed always for OMAP{34xx, 44xx} */ | 248 | /* This part needs to be executed always for OMAP{34xx, 44xx} */ |
319 | if (!bank->regs->irqctrl) { | 249 | if (cpu_is_omap34xx() || cpu_is_omap44xx() || |
320 | /* On omap24xx proceed only when valid GPIO bit is set */ | 250 | (bank->non_wakeup_gpios & gpio_bit)) { |
321 | if (bank->non_wakeup_gpios) { | ||
322 | if (!(bank->non_wakeup_gpios & gpio_bit)) | ||
323 | goto exit; | ||
324 | } | ||
325 | |||
326 | /* | 251 | /* |
327 | * Log the edge gpio and manually trigger the IRQ | 252 | * Log the edge gpio and manually trigger the IRQ |
328 | * after resume if the input level changes | 253 | * after resume if the input level changes |
@@ -335,11 +260,17 @@ static inline void set_gpio_trigger(struct gpio_bank *bank, int gpio, | |||
335 | bank->enabled_non_wakeup_gpios &= ~gpio_bit; | 260 | bank->enabled_non_wakeup_gpios &= ~gpio_bit; |
336 | } | 261 | } |
337 | 262 | ||
338 | exit: | 263 | if (cpu_is_omap44xx()) { |
339 | bank->level_mask = | 264 | bank->level_mask = |
340 | __raw_readl(bank->base + bank->regs->leveldetect0) | | 265 | __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) | |
341 | __raw_readl(bank->base + bank->regs->leveldetect1); | 266 | __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1); |
267 | } else { | ||
268 | bank->level_mask = | ||
269 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) | | ||
270 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); | ||
271 | } | ||
342 | } | 272 | } |
273 | #endif | ||
343 | 274 | ||
344 | #ifdef CONFIG_ARCH_OMAP1 | 275 | #ifdef CONFIG_ARCH_OMAP1 |
345 | /* | 276 | /* |
@@ -351,10 +282,23 @@ static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) | |||
351 | void __iomem *reg = bank->base; | 282 | void __iomem *reg = bank->base; |
352 | u32 l = 0; | 283 | u32 l = 0; |
353 | 284 | ||
354 | if (!bank->regs->irqctrl) | 285 | switch (bank->method) { |
286 | case METHOD_MPUIO: | ||
287 | reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride; | ||
288 | break; | ||
289 | #ifdef CONFIG_ARCH_OMAP15XX | ||
290 | case METHOD_GPIO_1510: | ||
291 | reg += OMAP1510_GPIO_INT_CONTROL; | ||
292 | break; | ||
293 | #endif | ||
294 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) | ||
295 | case METHOD_GPIO_7XX: | ||
296 | reg += OMAP7XX_GPIO_INT_CONTROL; | ||
297 | break; | ||
298 | #endif | ||
299 | default: | ||
355 | return; | 300 | return; |
356 | 301 | } | |
357 | reg += bank->regs->irqctrl; | ||
358 | 302 | ||
359 | l = __raw_readl(reg); | 303 | l = __raw_readl(reg); |
360 | if ((l >> gpio) & 1) | 304 | if ((l >> gpio) & 1) |
@@ -364,22 +308,17 @@ static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) | |||
364 | 308 | ||
365 | __raw_writel(l, reg); | 309 | __raw_writel(l, reg); |
366 | } | 310 | } |
367 | #else | ||
368 | static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {} | ||
369 | #endif | 311 | #endif |
370 | 312 | ||
371 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, | 313 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) |
372 | unsigned trigger) | ||
373 | { | 314 | { |
374 | void __iomem *reg = bank->base; | 315 | void __iomem *reg = bank->base; |
375 | void __iomem *base = bank->base; | ||
376 | u32 l = 0; | 316 | u32 l = 0; |
377 | 317 | ||
378 | if (bank->regs->leveldetect0 && bank->regs->wkup_en) { | 318 | switch (bank->method) { |
379 | set_gpio_trigger(bank, gpio, trigger); | 319 | #ifdef CONFIG_ARCH_OMAP1 |
380 | } else if (bank->regs->irqctrl) { | 320 | case METHOD_MPUIO: |
381 | reg += bank->regs->irqctrl; | 321 | reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride; |
382 | |||
383 | l = __raw_readl(reg); | 322 | l = __raw_readl(reg); |
384 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) | 323 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
385 | bank->toggle_mask |= 1 << gpio; | 324 | bank->toggle_mask |= 1 << gpio; |
@@ -388,15 +327,29 @@ static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, | |||
388 | else if (trigger & IRQ_TYPE_EDGE_FALLING) | 327 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
389 | l &= ~(1 << gpio); | 328 | l &= ~(1 << gpio); |
390 | else | 329 | else |
391 | return -EINVAL; | 330 | goto bad; |
392 | 331 | break; | |
393 | __raw_writel(l, reg); | 332 | #endif |
394 | } else if (bank->regs->edgectrl1) { | 333 | #ifdef CONFIG_ARCH_OMAP15XX |
334 | case METHOD_GPIO_1510: | ||
335 | reg += OMAP1510_GPIO_INT_CONTROL; | ||
336 | l = __raw_readl(reg); | ||
337 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) | ||
338 | bank->toggle_mask |= 1 << gpio; | ||
339 | if (trigger & IRQ_TYPE_EDGE_RISING) | ||
340 | l |= 1 << gpio; | ||
341 | else if (trigger & IRQ_TYPE_EDGE_FALLING) | ||
342 | l &= ~(1 << gpio); | ||
343 | else | ||
344 | goto bad; | ||
345 | break; | ||
346 | #endif | ||
347 | #ifdef CONFIG_ARCH_OMAP16XX | ||
348 | case METHOD_GPIO_1610: | ||
395 | if (gpio & 0x08) | 349 | if (gpio & 0x08) |
396 | reg += bank->regs->edgectrl2; | 350 | reg += OMAP1610_GPIO_EDGE_CTRL2; |
397 | else | 351 | else |
398 | reg += bank->regs->edgectrl1; | 352 | reg += OMAP1610_GPIO_EDGE_CTRL1; |
399 | |||
400 | gpio &= 0x07; | 353 | gpio &= 0x07; |
401 | l = __raw_readl(reg); | 354 | l = __raw_readl(reg); |
402 | l &= ~(3 << (gpio << 1)); | 355 | l &= ~(3 << (gpio << 1)); |
@@ -404,38 +357,63 @@ static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, | |||
404 | l |= 2 << (gpio << 1); | 357 | l |= 2 << (gpio << 1); |
405 | if (trigger & IRQ_TYPE_EDGE_FALLING) | 358 | if (trigger & IRQ_TYPE_EDGE_FALLING) |
406 | l |= 1 << (gpio << 1); | 359 | l |= 1 << (gpio << 1); |
407 | 360 | if (trigger) | |
408 | /* Enable wake-up during idle for dynamic tick */ | 361 | /* Enable wake-up during idle for dynamic tick */ |
409 | _gpio_rmw(base, bank->regs->wkup_en, 1 << gpio, trigger); | 362 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA); |
410 | bank->context.wake_en = | 363 | else |
411 | __raw_readl(bank->base + bank->regs->wkup_en); | 364 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA); |
412 | __raw_writel(l, reg); | 365 | break; |
366 | #endif | ||
367 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) | ||
368 | case METHOD_GPIO_7XX: | ||
369 | reg += OMAP7XX_GPIO_INT_CONTROL; | ||
370 | l = __raw_readl(reg); | ||
371 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) | ||
372 | bank->toggle_mask |= 1 << gpio; | ||
373 | if (trigger & IRQ_TYPE_EDGE_RISING) | ||
374 | l |= 1 << gpio; | ||
375 | else if (trigger & IRQ_TYPE_EDGE_FALLING) | ||
376 | l &= ~(1 << gpio); | ||
377 | else | ||
378 | goto bad; | ||
379 | break; | ||
380 | #endif | ||
381 | #ifdef CONFIG_ARCH_OMAP2PLUS | ||
382 | case METHOD_GPIO_24XX: | ||
383 | case METHOD_GPIO_44XX: | ||
384 | set_24xx_gpio_triggering(bank, gpio, trigger); | ||
385 | return 0; | ||
386 | #endif | ||
387 | default: | ||
388 | goto bad; | ||
413 | } | 389 | } |
390 | __raw_writel(l, reg); | ||
414 | return 0; | 391 | return 0; |
392 | bad: | ||
393 | return -EINVAL; | ||
415 | } | 394 | } |
416 | 395 | ||
417 | static int gpio_irq_type(struct irq_data *d, unsigned type) | 396 | static int gpio_irq_type(struct irq_data *d, unsigned type) |
418 | { | 397 | { |
419 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); | 398 | struct gpio_bank *bank; |
420 | unsigned gpio = 0; | 399 | unsigned gpio; |
421 | int retval; | 400 | int retval; |
422 | unsigned long flags; | 401 | unsigned long flags; |
423 | 402 | ||
424 | #ifdef CONFIG_ARCH_OMAP1 | 403 | if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE) |
425 | if (d->irq > IH_MPUIO_BASE) | ||
426 | gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE); | 404 | gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE); |
427 | #endif | 405 | else |
428 | 406 | gpio = d->irq - IH_GPIO_BASE; | |
429 | if (!gpio) | ||
430 | gpio = irq_to_gpio(bank, d->irq); | ||
431 | 407 | ||
432 | if (type & ~IRQ_TYPE_SENSE_MASK) | 408 | if (type & ~IRQ_TYPE_SENSE_MASK) |
433 | return -EINVAL; | 409 | return -EINVAL; |
434 | 410 | ||
435 | if (!bank->regs->leveldetect0 && | 411 | /* OMAP1 allows only only edge triggering */ |
436 | (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) | 412 | if (!cpu_class_is_omap2() |
413 | && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) | ||
437 | return -EINVAL; | 414 | return -EINVAL; |
438 | 415 | ||
416 | bank = irq_data_get_irq_chip_data(d); | ||
439 | spin_lock_irqsave(&bank->lock, flags); | 417 | spin_lock_irqsave(&bank->lock, flags); |
440 | retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type); | 418 | retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type); |
441 | spin_unlock_irqrestore(&bank->lock, flags); | 419 | spin_unlock_irqrestore(&bank->lock, flags); |
@@ -492,7 +470,6 @@ static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) | |||
492 | if (bank->regs->set_irqenable) { | 470 | if (bank->regs->set_irqenable) { |
493 | reg += bank->regs->set_irqenable; | 471 | reg += bank->regs->set_irqenable; |
494 | l = gpio_mask; | 472 | l = gpio_mask; |
495 | bank->context.irqenable1 |= gpio_mask; | ||
496 | } else { | 473 | } else { |
497 | reg += bank->regs->irqenable; | 474 | reg += bank->regs->irqenable; |
498 | l = __raw_readl(reg); | 475 | l = __raw_readl(reg); |
@@ -500,7 +477,6 @@ static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) | |||
500 | l &= ~gpio_mask; | 477 | l &= ~gpio_mask; |
501 | else | 478 | else |
502 | l |= gpio_mask; | 479 | l |= gpio_mask; |
503 | bank->context.irqenable1 = l; | ||
504 | } | 480 | } |
505 | 481 | ||
506 | __raw_writel(l, reg); | 482 | __raw_writel(l, reg); |
@@ -514,7 +490,6 @@ static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) | |||
514 | if (bank->regs->clr_irqenable) { | 490 | if (bank->regs->clr_irqenable) { |
515 | reg += bank->regs->clr_irqenable; | 491 | reg += bank->regs->clr_irqenable; |
516 | l = gpio_mask; | 492 | l = gpio_mask; |
517 | bank->context.irqenable1 &= ~gpio_mask; | ||
518 | } else { | 493 | } else { |
519 | reg += bank->regs->irqenable; | 494 | reg += bank->regs->irqenable; |
520 | l = __raw_readl(reg); | 495 | l = __raw_readl(reg); |
@@ -522,7 +497,6 @@ static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) | |||
522 | l |= gpio_mask; | 497 | l |= gpio_mask; |
523 | else | 498 | else |
524 | l &= ~gpio_mask; | 499 | l &= ~gpio_mask; |
525 | bank->context.irqenable1 = l; | ||
526 | } | 500 | } |
527 | 501 | ||
528 | __raw_writel(l, reg); | 502 | __raw_writel(l, reg); |
@@ -530,10 +504,7 @@ static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) | |||
530 | 504 | ||
531 | static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) | 505 | static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) |
532 | { | 506 | { |
533 | if (enable) | 507 | _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); |
534 | _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); | ||
535 | else | ||
536 | _disable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); | ||
537 | } | 508 | } |
538 | 509 | ||
539 | /* | 510 | /* |
@@ -550,18 +521,17 @@ static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) | |||
550 | unsigned long flags; | 521 | unsigned long flags; |
551 | 522 | ||
552 | if (bank->non_wakeup_gpios & gpio_bit) { | 523 | if (bank->non_wakeup_gpios & gpio_bit) { |
553 | dev_err(bank->dev, | 524 | dev_err(bank->dev, |
554 | "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio); | 525 | "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio); |
555 | return -EINVAL; | 526 | return -EINVAL; |
556 | } | 527 | } |
557 | 528 | ||
558 | spin_lock_irqsave(&bank->lock, flags); | 529 | spin_lock_irqsave(&bank->lock, flags); |
559 | if (enable) | 530 | if (enable) |
560 | bank->context.wake_en |= gpio_bit; | 531 | bank->suspend_wakeup |= gpio_bit; |
561 | else | 532 | else |
562 | bank->context.wake_en &= ~gpio_bit; | 533 | bank->suspend_wakeup &= ~gpio_bit; |
563 | 534 | ||
564 | __raw_writel(bank->context.wake_en, bank->base + bank->regs->wkup_en); | ||
565 | spin_unlock_irqrestore(&bank->lock, flags); | 535 | spin_unlock_irqrestore(&bank->lock, flags); |
566 | 536 | ||
567 | return 0; | 537 | return 0; |
@@ -573,16 +543,19 @@ static void _reset_gpio(struct gpio_bank *bank, int gpio) | |||
573 | _set_gpio_irqenable(bank, gpio, 0); | 543 | _set_gpio_irqenable(bank, gpio, 0); |
574 | _clear_gpio_irqstatus(bank, gpio); | 544 | _clear_gpio_irqstatus(bank, gpio); |
575 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); | 545 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); |
576 | _clear_gpio_debounce(bank, gpio); | ||
577 | } | 546 | } |
578 | 547 | ||
579 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ | 548 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ |
580 | static int gpio_wake_enable(struct irq_data *d, unsigned int enable) | 549 | static int gpio_wake_enable(struct irq_data *d, unsigned int enable) |
581 | { | 550 | { |
582 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); | 551 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
583 | unsigned int gpio = irq_to_gpio(bank, d->irq); | 552 | struct gpio_bank *bank; |
553 | int retval; | ||
584 | 554 | ||
585 | return _set_gpio_wakeup(bank, gpio, enable); | 555 | bank = irq_data_get_irq_chip_data(d); |
556 | retval = _set_gpio_wakeup(bank, gpio, enable); | ||
557 | |||
558 | return retval; | ||
586 | } | 559 | } |
587 | 560 | ||
588 | static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) | 561 | static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) |
@@ -590,39 +563,38 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) | |||
590 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); | 563 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
591 | unsigned long flags; | 564 | unsigned long flags; |
592 | 565 | ||
593 | /* | ||
594 | * If this is the first gpio_request for the bank, | ||
595 | * enable the bank module. | ||
596 | */ | ||
597 | if (!bank->mod_usage) | ||
598 | pm_runtime_get_sync(bank->dev); | ||
599 | |||
600 | spin_lock_irqsave(&bank->lock, flags); | 566 | spin_lock_irqsave(&bank->lock, flags); |
567 | |||
601 | /* Set trigger to none. You need to enable the desired trigger with | 568 | /* Set trigger to none. You need to enable the desired trigger with |
602 | * request_irq() or set_irq_type(). | 569 | * request_irq() or set_irq_type(). |
603 | */ | 570 | */ |
604 | _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); | 571 | _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); |
605 | 572 | ||
606 | if (bank->regs->pinctrl) { | 573 | #ifdef CONFIG_ARCH_OMAP15XX |
607 | void __iomem *reg = bank->base + bank->regs->pinctrl; | 574 | if (bank->method == METHOD_GPIO_1510) { |
575 | void __iomem *reg; | ||
608 | 576 | ||
609 | /* Claim the pin for MPU */ | 577 | /* Claim the pin for MPU */ |
578 | reg = bank->base + OMAP1510_GPIO_PIN_CONTROL; | ||
610 | __raw_writel(__raw_readl(reg) | (1 << offset), reg); | 579 | __raw_writel(__raw_readl(reg) | (1 << offset), reg); |
611 | } | 580 | } |
612 | 581 | #endif | |
613 | if (bank->regs->ctrl && !bank->mod_usage) { | 582 | if (!cpu_class_is_omap1()) { |
614 | void __iomem *reg = bank->base + bank->regs->ctrl; | 583 | if (!bank->mod_usage) { |
615 | u32 ctrl; | 584 | void __iomem *reg = bank->base; |
616 | 585 | u32 ctrl; | |
617 | ctrl = __raw_readl(reg); | 586 | |
618 | /* Module is enabled, clocks are not gated */ | 587 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
619 | ctrl &= ~GPIO_MOD_CTRL_BIT; | 588 | reg += OMAP24XX_GPIO_CTRL; |
620 | __raw_writel(ctrl, reg); | 589 | else if (cpu_is_omap44xx()) |
621 | bank->context.ctrl = ctrl; | 590 | reg += OMAP4_GPIO_CTRL; |
591 | ctrl = __raw_readl(reg); | ||
592 | /* Module is enabled, clocks are not gated */ | ||
593 | ctrl &= 0xFFFFFFFE; | ||
594 | __raw_writel(ctrl, reg); | ||
595 | } | ||
596 | bank->mod_usage |= 1 << offset; | ||
622 | } | 597 | } |
623 | |||
624 | bank->mod_usage |= 1 << offset; | ||
625 | |||
626 | spin_unlock_irqrestore(&bank->lock, flags); | 598 | spin_unlock_irqrestore(&bank->lock, flags); |
627 | 599 | ||
628 | return 0; | 600 | return 0; |
@@ -631,40 +603,48 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) | |||
631 | static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) | 603 | static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) |
632 | { | 604 | { |
633 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); | 605 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
634 | void __iomem *base = bank->base; | ||
635 | unsigned long flags; | 606 | unsigned long flags; |
636 | 607 | ||
637 | spin_lock_irqsave(&bank->lock, flags); | 608 | spin_lock_irqsave(&bank->lock, flags); |
638 | 609 | #ifdef CONFIG_ARCH_OMAP16XX | |
639 | if (bank->regs->wkup_en) { | 610 | if (bank->method == METHOD_GPIO_1610) { |
640 | /* Disable wake-up during idle for dynamic tick */ | 611 | /* Disable wake-up during idle for dynamic tick */ |
641 | _gpio_rmw(base, bank->regs->wkup_en, 1 << offset, 0); | 612 | void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
642 | bank->context.wake_en = | 613 | __raw_writel(1 << offset, reg); |
643 | __raw_readl(bank->base + bank->regs->wkup_en); | ||
644 | } | 614 | } |
645 | 615 | #endif | |
646 | bank->mod_usage &= ~(1 << offset); | 616 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
647 | 617 | if (bank->method == METHOD_GPIO_24XX) { | |
648 | if (bank->regs->ctrl && !bank->mod_usage) { | 618 | /* Disable wake-up during idle for dynamic tick */ |
649 | void __iomem *reg = bank->base + bank->regs->ctrl; | 619 | void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
650 | u32 ctrl; | 620 | __raw_writel(1 << offset, reg); |
651 | 621 | } | |
652 | ctrl = __raw_readl(reg); | 622 | #endif |
653 | /* Module is disabled, clocks are gated */ | 623 | #ifdef CONFIG_ARCH_OMAP4 |
654 | ctrl |= GPIO_MOD_CTRL_BIT; | 624 | if (bank->method == METHOD_GPIO_44XX) { |
655 | __raw_writel(ctrl, reg); | 625 | /* Disable wake-up during idle for dynamic tick */ |
656 | bank->context.ctrl = ctrl; | 626 | void __iomem *reg = bank->base + OMAP4_GPIO_IRQWAKEN0; |
627 | __raw_writel(1 << offset, reg); | ||
628 | } | ||
629 | #endif | ||
630 | if (!cpu_class_is_omap1()) { | ||
631 | bank->mod_usage &= ~(1 << offset); | ||
632 | if (!bank->mod_usage) { | ||
633 | void __iomem *reg = bank->base; | ||
634 | u32 ctrl; | ||
635 | |||
636 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) | ||
637 | reg += OMAP24XX_GPIO_CTRL; | ||
638 | else if (cpu_is_omap44xx()) | ||
639 | reg += OMAP4_GPIO_CTRL; | ||
640 | ctrl = __raw_readl(reg); | ||
641 | /* Module is disabled, clocks are gated */ | ||
642 | ctrl |= 1; | ||
643 | __raw_writel(ctrl, reg); | ||
644 | } | ||
657 | } | 645 | } |
658 | |||
659 | _reset_gpio(bank, bank->chip.base + offset); | 646 | _reset_gpio(bank, bank->chip.base + offset); |
660 | spin_unlock_irqrestore(&bank->lock, flags); | 647 | spin_unlock_irqrestore(&bank->lock, flags); |
661 | |||
662 | /* | ||
663 | * If this is the last gpio to be freed in the bank, | ||
664 | * disable the bank module. | ||
665 | */ | ||
666 | if (!bank->mod_usage) | ||
667 | pm_runtime_put(bank->dev); | ||
668 | } | 648 | } |
669 | 649 | ||
670 | /* | 650 | /* |
@@ -682,6 +662,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
682 | u32 isr; | 662 | u32 isr; |
683 | unsigned int gpio_irq, gpio_index; | 663 | unsigned int gpio_irq, gpio_index; |
684 | struct gpio_bank *bank; | 664 | struct gpio_bank *bank; |
665 | u32 retrigger = 0; | ||
685 | int unmasked = 0; | 666 | int unmasked = 0; |
686 | struct irq_chip *chip = irq_desc_get_chip(desc); | 667 | struct irq_chip *chip = irq_desc_get_chip(desc); |
687 | 668 | ||
@@ -689,7 +670,6 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
689 | 670 | ||
690 | bank = irq_get_handler_data(irq); | 671 | bank = irq_get_handler_data(irq); |
691 | isr_reg = bank->base + bank->regs->irqstatus; | 672 | isr_reg = bank->base + bank->regs->irqstatus; |
692 | pm_runtime_get_sync(bank->dev); | ||
693 | 673 | ||
694 | if (WARN_ON(!isr_reg)) | 674 | if (WARN_ON(!isr_reg)) |
695 | goto exit; | 675 | goto exit; |
@@ -701,8 +681,12 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
701 | enabled = _get_gpio_irqbank_mask(bank); | 681 | enabled = _get_gpio_irqbank_mask(bank); |
702 | isr_saved = isr = __raw_readl(isr_reg) & enabled; | 682 | isr_saved = isr = __raw_readl(isr_reg) & enabled; |
703 | 683 | ||
704 | if (bank->level_mask) | 684 | if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO)) |
685 | isr &= 0x0000ffff; | ||
686 | |||
687 | if (cpu_class_is_omap2()) { | ||
705 | level_mask = bank->level_mask & enabled; | 688 | level_mask = bank->level_mask & enabled; |
689 | } | ||
706 | 690 | ||
707 | /* clear edge sensitive interrupts before handler(s) are | 691 | /* clear edge sensitive interrupts before handler(s) are |
708 | called so that we don't miss any interrupt occurred while | 692 | called so that we don't miss any interrupt occurred while |
@@ -718,18 +702,19 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
718 | chained_irq_exit(chip, desc); | 702 | chained_irq_exit(chip, desc); |
719 | } | 703 | } |
720 | 704 | ||
705 | isr |= retrigger; | ||
706 | retrigger = 0; | ||
721 | if (!isr) | 707 | if (!isr) |
722 | break; | 708 | break; |
723 | 709 | ||
724 | gpio_irq = bank->irq_base; | 710 | gpio_irq = bank->virtual_irq_start; |
725 | for (; isr != 0; isr >>= 1, gpio_irq++) { | 711 | for (; isr != 0; isr >>= 1, gpio_irq++) { |
726 | int gpio = irq_to_gpio(bank, gpio_irq); | 712 | gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq)); |
727 | 713 | ||
728 | if (!(isr & 1)) | 714 | if (!(isr & 1)) |
729 | continue; | 715 | continue; |
730 | 716 | ||
731 | gpio_index = GPIO_INDEX(bank, gpio); | 717 | #ifdef CONFIG_ARCH_OMAP1 |
732 | |||
733 | /* | 718 | /* |
734 | * Some chips can't respond to both rising and falling | 719 | * Some chips can't respond to both rising and falling |
735 | * at the same time. If this irq was requested with | 720 | * at the same time. If this irq was requested with |
@@ -739,6 +724,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
739 | */ | 724 | */ |
740 | if (bank->toggle_mask & (1 << gpio_index)) | 725 | if (bank->toggle_mask & (1 << gpio_index)) |
741 | _toggle_gpio_edge_triggering(bank, gpio_index); | 726 | _toggle_gpio_edge_triggering(bank, gpio_index); |
727 | #endif | ||
742 | 728 | ||
743 | generic_handle_irq(gpio_irq); | 729 | generic_handle_irq(gpio_irq); |
744 | } | 730 | } |
@@ -750,13 +736,12 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
750 | exit: | 736 | exit: |
751 | if (!unmasked) | 737 | if (!unmasked) |
752 | chained_irq_exit(chip, desc); | 738 | chained_irq_exit(chip, desc); |
753 | pm_runtime_put(bank->dev); | ||
754 | } | 739 | } |
755 | 740 | ||
756 | static void gpio_irq_shutdown(struct irq_data *d) | 741 | static void gpio_irq_shutdown(struct irq_data *d) |
757 | { | 742 | { |
743 | unsigned int gpio = d->irq - IH_GPIO_BASE; | ||
758 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); | 744 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
759 | unsigned int gpio = irq_to_gpio(bank, d->irq); | ||
760 | unsigned long flags; | 745 | unsigned long flags; |
761 | 746 | ||
762 | spin_lock_irqsave(&bank->lock, flags); | 747 | spin_lock_irqsave(&bank->lock, flags); |
@@ -766,16 +751,16 @@ static void gpio_irq_shutdown(struct irq_data *d) | |||
766 | 751 | ||
767 | static void gpio_ack_irq(struct irq_data *d) | 752 | static void gpio_ack_irq(struct irq_data *d) |
768 | { | 753 | { |
754 | unsigned int gpio = d->irq - IH_GPIO_BASE; | ||
769 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); | 755 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
770 | unsigned int gpio = irq_to_gpio(bank, d->irq); | ||
771 | 756 | ||
772 | _clear_gpio_irqstatus(bank, gpio); | 757 | _clear_gpio_irqstatus(bank, gpio); |
773 | } | 758 | } |
774 | 759 | ||
775 | static void gpio_mask_irq(struct irq_data *d) | 760 | static void gpio_mask_irq(struct irq_data *d) |
776 | { | 761 | { |
762 | unsigned int gpio = d->irq - IH_GPIO_BASE; | ||
777 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); | 763 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
778 | unsigned int gpio = irq_to_gpio(bank, d->irq); | ||
779 | unsigned long flags; | 764 | unsigned long flags; |
780 | 765 | ||
781 | spin_lock_irqsave(&bank->lock, flags); | 766 | spin_lock_irqsave(&bank->lock, flags); |
@@ -786,8 +771,8 @@ static void gpio_mask_irq(struct irq_data *d) | |||
786 | 771 | ||
787 | static void gpio_unmask_irq(struct irq_data *d) | 772 | static void gpio_unmask_irq(struct irq_data *d) |
788 | { | 773 | { |
774 | unsigned int gpio = d->irq - IH_GPIO_BASE; | ||
789 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); | 775 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
790 | unsigned int gpio = irq_to_gpio(bank, d->irq); | ||
791 | unsigned int irq_mask = GPIO_BIT(bank, gpio); | 776 | unsigned int irq_mask = GPIO_BIT(bank, gpio); |
792 | u32 trigger = irqd_get_trigger_type(d); | 777 | u32 trigger = irqd_get_trigger_type(d); |
793 | unsigned long flags; | 778 | unsigned long flags; |
@@ -819,6 +804,14 @@ static struct irq_chip gpio_irq_chip = { | |||
819 | 804 | ||
820 | /*---------------------------------------------------------------------*/ | 805 | /*---------------------------------------------------------------------*/ |
821 | 806 | ||
807 | #ifdef CONFIG_ARCH_OMAP1 | ||
808 | |||
809 | #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO) | ||
810 | |||
811 | #ifdef CONFIG_ARCH_OMAP16XX | ||
812 | |||
813 | #include <linux/platform_device.h> | ||
814 | |||
822 | static int omap_mpuio_suspend_noirq(struct device *dev) | 815 | static int omap_mpuio_suspend_noirq(struct device *dev) |
823 | { | 816 | { |
824 | struct platform_device *pdev = to_platform_device(dev); | 817 | struct platform_device *pdev = to_platform_device(dev); |
@@ -828,7 +821,8 @@ static int omap_mpuio_suspend_noirq(struct device *dev) | |||
828 | unsigned long flags; | 821 | unsigned long flags; |
829 | 822 | ||
830 | spin_lock_irqsave(&bank->lock, flags); | 823 | spin_lock_irqsave(&bank->lock, flags); |
831 | __raw_writel(0xffff & ~bank->context.wake_en, mask_reg); | 824 | bank->saved_wakeup = __raw_readl(mask_reg); |
825 | __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg); | ||
832 | spin_unlock_irqrestore(&bank->lock, flags); | 826 | spin_unlock_irqrestore(&bank->lock, flags); |
833 | 827 | ||
834 | return 0; | 828 | return 0; |
@@ -843,7 +837,7 @@ static int omap_mpuio_resume_noirq(struct device *dev) | |||
843 | unsigned long flags; | 837 | unsigned long flags; |
844 | 838 | ||
845 | spin_lock_irqsave(&bank->lock, flags); | 839 | spin_lock_irqsave(&bank->lock, flags); |
846 | __raw_writel(bank->context.wake_en, mask_reg); | 840 | __raw_writel(bank->saved_wakeup, mask_reg); |
847 | spin_unlock_irqrestore(&bank->lock, flags); | 841 | spin_unlock_irqrestore(&bank->lock, flags); |
848 | 842 | ||
849 | return 0; | 843 | return 0; |
@@ -871,16 +865,32 @@ static struct platform_device omap_mpuio_device = { | |||
871 | /* could list the /proc/iomem resources */ | 865 | /* could list the /proc/iomem resources */ |
872 | }; | 866 | }; |
873 | 867 | ||
874 | static inline void mpuio_init(struct gpio_bank *bank) | 868 | static inline void mpuio_init(void) |
875 | { | 869 | { |
870 | struct gpio_bank *bank = &gpio_bank[0]; | ||
876 | platform_set_drvdata(&omap_mpuio_device, bank); | 871 | platform_set_drvdata(&omap_mpuio_device, bank); |
877 | 872 | ||
878 | if (platform_driver_register(&omap_mpuio_driver) == 0) | 873 | if (platform_driver_register(&omap_mpuio_driver) == 0) |
879 | (void) platform_device_register(&omap_mpuio_device); | 874 | (void) platform_device_register(&omap_mpuio_device); |
880 | } | 875 | } |
881 | 876 | ||
877 | #else | ||
878 | static inline void mpuio_init(void) {} | ||
879 | #endif /* 16xx */ | ||
880 | |||
881 | #else | ||
882 | |||
883 | #define bank_is_mpuio(bank) 0 | ||
884 | static inline void mpuio_init(void) {} | ||
885 | |||
886 | #endif | ||
887 | |||
882 | /*---------------------------------------------------------------------*/ | 888 | /*---------------------------------------------------------------------*/ |
883 | 889 | ||
890 | /* REVISIT these are stupid implementations! replace by ones that | ||
891 | * don't switch on METHOD_* and which mostly avoid spinlocks | ||
892 | */ | ||
893 | |||
884 | static int gpio_input(struct gpio_chip *chip, unsigned offset) | 894 | static int gpio_input(struct gpio_chip *chip, unsigned offset) |
885 | { | 895 | { |
886 | struct gpio_bank *bank; | 896 | struct gpio_bank *bank; |
@@ -903,15 +913,19 @@ static int gpio_is_input(struct gpio_bank *bank, int mask) | |||
903 | static int gpio_get(struct gpio_chip *chip, unsigned offset) | 913 | static int gpio_get(struct gpio_chip *chip, unsigned offset) |
904 | { | 914 | { |
905 | struct gpio_bank *bank; | 915 | struct gpio_bank *bank; |
916 | void __iomem *reg; | ||
917 | int gpio; | ||
906 | u32 mask; | 918 | u32 mask; |
907 | 919 | ||
920 | gpio = chip->base + offset; | ||
908 | bank = container_of(chip, struct gpio_bank, chip); | 921 | bank = container_of(chip, struct gpio_bank, chip); |
909 | mask = (1 << offset); | 922 | reg = bank->base; |
923 | mask = GPIO_BIT(bank, gpio); | ||
910 | 924 | ||
911 | if (gpio_is_input(bank, mask)) | 925 | if (gpio_is_input(bank, mask)) |
912 | return _get_gpio_datain(bank, offset); | 926 | return _get_gpio_datain(bank, gpio); |
913 | else | 927 | else |
914 | return _get_gpio_dataout(bank, offset); | 928 | return _get_gpio_dataout(bank, gpio); |
915 | } | 929 | } |
916 | 930 | ||
917 | static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) | 931 | static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) |
@@ -935,6 +949,12 @@ static int gpio_debounce(struct gpio_chip *chip, unsigned offset, | |||
935 | 949 | ||
936 | bank = container_of(chip, struct gpio_bank, chip); | 950 | bank = container_of(chip, struct gpio_bank, chip); |
937 | 951 | ||
952 | if (!bank->dbck) { | ||
953 | bank->dbck = clk_get(bank->dev, "dbclk"); | ||
954 | if (IS_ERR(bank->dbck)) | ||
955 | dev_err(bank->dev, "Could not get gpio dbck\n"); | ||
956 | } | ||
957 | |||
938 | spin_lock_irqsave(&bank->lock, flags); | 958 | spin_lock_irqsave(&bank->lock, flags); |
939 | _set_gpio_debounce(bank, offset, debounce); | 959 | _set_gpio_debounce(bank, offset, debounce); |
940 | spin_unlock_irqrestore(&bank->lock, flags); | 960 | spin_unlock_irqrestore(&bank->lock, flags); |
@@ -958,7 +978,7 @@ static int gpio_2irq(struct gpio_chip *chip, unsigned offset) | |||
958 | struct gpio_bank *bank; | 978 | struct gpio_bank *bank; |
959 | 979 | ||
960 | bank = container_of(chip, struct gpio_bank, chip); | 980 | bank = container_of(chip, struct gpio_bank, chip); |
961 | return bank->irq_base + offset; | 981 | return bank->virtual_irq_start + offset; |
962 | } | 982 | } |
963 | 983 | ||
964 | /*---------------------------------------------------------------------*/ | 984 | /*---------------------------------------------------------------------*/ |
@@ -983,36 +1003,81 @@ static void __init omap_gpio_show_rev(struct gpio_bank *bank) | |||
983 | */ | 1003 | */ |
984 | static struct lock_class_key gpio_lock_class; | 1004 | static struct lock_class_key gpio_lock_class; |
985 | 1005 | ||
986 | static void omap_gpio_mod_init(struct gpio_bank *bank) | 1006 | static inline int init_gpio_info(struct platform_device *pdev) |
987 | { | 1007 | { |
988 | void __iomem *base = bank->base; | 1008 | /* TODO: Analyze removing gpio_bank_count usage from driver code */ |
989 | u32 l = 0xffffffff; | 1009 | gpio_bank = kzalloc(gpio_bank_count * sizeof(struct gpio_bank), |
990 | 1010 | GFP_KERNEL); | |
991 | if (bank->width == 16) | 1011 | if (!gpio_bank) { |
992 | l = 0xffff; | 1012 | dev_err(&pdev->dev, "Memory alloc failed for gpio_bank\n"); |
993 | 1013 | return -ENOMEM; | |
994 | if (bank->is_mpuio) { | ||
995 | __raw_writel(l, bank->base + bank->regs->irqenable); | ||
996 | return; | ||
997 | } | 1014 | } |
1015 | return 0; | ||
1016 | } | ||
998 | 1017 | ||
999 | _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->irqenable_inv); | 1018 | /* TODO: Cleanup cpu_is_* checks */ |
1000 | _gpio_rmw(base, bank->regs->irqstatus, l, !bank->regs->irqenable_inv); | 1019 | static void omap_gpio_mod_init(struct gpio_bank *bank, int id) |
1001 | if (bank->regs->debounce_en) | 1020 | { |
1002 | __raw_writel(0, base + bank->regs->debounce_en); | 1021 | if (cpu_class_is_omap2()) { |
1003 | 1022 | if (cpu_is_omap44xx()) { | |
1004 | /* Save OE default value (0xffffffff) in the context */ | 1023 | __raw_writel(0xffffffff, bank->base + |
1005 | bank->context.oe = __raw_readl(bank->base + bank->regs->direction); | 1024 | OMAP4_GPIO_IRQSTATUSCLR0); |
1006 | /* Initialize interface clk ungated, module enabled */ | 1025 | __raw_writel(0x00000000, bank->base + |
1007 | if (bank->regs->ctrl) | 1026 | OMAP4_GPIO_DEBOUNCENABLE); |
1008 | __raw_writel(0, base + bank->regs->ctrl); | 1027 | /* Initialize interface clk ungated, module enabled */ |
1028 | __raw_writel(0, bank->base + OMAP4_GPIO_CTRL); | ||
1029 | } else if (cpu_is_omap34xx()) { | ||
1030 | __raw_writel(0x00000000, bank->base + | ||
1031 | OMAP24XX_GPIO_IRQENABLE1); | ||
1032 | __raw_writel(0xffffffff, bank->base + | ||
1033 | OMAP24XX_GPIO_IRQSTATUS1); | ||
1034 | __raw_writel(0x00000000, bank->base + | ||
1035 | OMAP24XX_GPIO_DEBOUNCE_EN); | ||
1036 | |||
1037 | /* Initialize interface clk ungated, module enabled */ | ||
1038 | __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL); | ||
1039 | } else if (cpu_is_omap24xx()) { | ||
1040 | static const u32 non_wakeup_gpios[] = { | ||
1041 | 0xe203ffc0, 0x08700040 | ||
1042 | }; | ||
1043 | if (id < ARRAY_SIZE(non_wakeup_gpios)) | ||
1044 | bank->non_wakeup_gpios = non_wakeup_gpios[id]; | ||
1045 | } | ||
1046 | } else if (cpu_class_is_omap1()) { | ||
1047 | if (bank_is_mpuio(bank)) | ||
1048 | __raw_writew(0xffff, bank->base + | ||
1049 | OMAP_MPUIO_GPIO_MASKIT / bank->stride); | ||
1050 | if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) { | ||
1051 | __raw_writew(0xffff, bank->base | ||
1052 | + OMAP1510_GPIO_INT_MASK); | ||
1053 | __raw_writew(0x0000, bank->base | ||
1054 | + OMAP1510_GPIO_INT_STATUS); | ||
1055 | } | ||
1056 | if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) { | ||
1057 | __raw_writew(0x0000, bank->base | ||
1058 | + OMAP1610_GPIO_IRQENABLE1); | ||
1059 | __raw_writew(0xffff, bank->base | ||
1060 | + OMAP1610_GPIO_IRQSTATUS1); | ||
1061 | __raw_writew(0x0014, bank->base | ||
1062 | + OMAP1610_GPIO_SYSCONFIG); | ||
1009 | 1063 | ||
1010 | bank->dbck = clk_get(bank->dev, "dbclk"); | 1064 | /* |
1011 | if (IS_ERR(bank->dbck)) | 1065 | * Enable system clock for GPIO module. |
1012 | dev_err(bank->dev, "Could not get gpio dbck\n"); | 1066 | * The CAM_CLK_CTRL *is* really the right place. |
1067 | */ | ||
1068 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, | ||
1069 | ULPD_CAM_CLK_CTRL); | ||
1070 | } | ||
1071 | if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) { | ||
1072 | __raw_writel(0xffffffff, bank->base | ||
1073 | + OMAP7XX_GPIO_INT_MASK); | ||
1074 | __raw_writel(0x00000000, bank->base | ||
1075 | + OMAP7XX_GPIO_INT_STATUS); | ||
1076 | } | ||
1077 | } | ||
1013 | } | 1078 | } |
1014 | 1079 | ||
1015 | static void | 1080 | static __init void |
1016 | omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start, | 1081 | omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start, |
1017 | unsigned int num) | 1082 | unsigned int num) |
1018 | { | 1083 | { |
@@ -1021,19 +1086,14 @@ omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start, | |||
1021 | 1086 | ||
1022 | gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base, | 1087 | gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base, |
1023 | handle_simple_irq); | 1088 | handle_simple_irq); |
1024 | if (!gc) { | ||
1025 | dev_err(bank->dev, "Memory alloc failed for gc\n"); | ||
1026 | return; | ||
1027 | } | ||
1028 | |||
1029 | ct = gc->chip_types; | 1089 | ct = gc->chip_types; |
1030 | 1090 | ||
1031 | /* NOTE: No ack required, reading IRQ status clears it. */ | 1091 | /* NOTE: No ack required, reading IRQ status clears it. */ |
1032 | ct->chip.irq_mask = irq_gc_mask_set_bit; | 1092 | ct->chip.irq_mask = irq_gc_mask_set_bit; |
1033 | ct->chip.irq_unmask = irq_gc_mask_clr_bit; | 1093 | ct->chip.irq_unmask = irq_gc_mask_clr_bit; |
1034 | ct->chip.irq_set_type = gpio_irq_type; | 1094 | ct->chip.irq_set_type = gpio_irq_type; |
1035 | 1095 | /* REVISIT: assuming only 16xx supports MPUIO wake events */ | |
1036 | if (bank->regs->wkup_en) | 1096 | if (cpu_is_omap16xx()) |
1037 | ct->chip.irq_set_wake = gpio_wake_enable, | 1097 | ct->chip.irq_set_wake = gpio_wake_enable, |
1038 | 1098 | ||
1039 | ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride; | 1099 | ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride; |
@@ -1041,11 +1101,12 @@ omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start, | |||
1041 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); | 1101 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); |
1042 | } | 1102 | } |
1043 | 1103 | ||
1044 | static void omap_gpio_chip_init(struct gpio_bank *bank) | 1104 | static void __devinit omap_gpio_chip_init(struct gpio_bank *bank) |
1045 | { | 1105 | { |
1046 | int j; | 1106 | int j; |
1047 | static int gpio; | 1107 | static int gpio; |
1048 | 1108 | ||
1109 | bank->mod_usage = 0; | ||
1049 | /* | 1110 | /* |
1050 | * REVISIT eventually switch from OMAP-specific gpio structs | 1111 | * REVISIT eventually switch from OMAP-specific gpio structs |
1051 | * over to the generic ones | 1112 | * over to the generic ones |
@@ -1058,10 +1119,11 @@ static void omap_gpio_chip_init(struct gpio_bank *bank) | |||
1058 | bank->chip.set_debounce = gpio_debounce; | 1119 | bank->chip.set_debounce = gpio_debounce; |
1059 | bank->chip.set = gpio_set; | 1120 | bank->chip.set = gpio_set; |
1060 | bank->chip.to_irq = gpio_2irq; | 1121 | bank->chip.to_irq = gpio_2irq; |
1061 | if (bank->is_mpuio) { | 1122 | if (bank_is_mpuio(bank)) { |
1062 | bank->chip.label = "mpuio"; | 1123 | bank->chip.label = "mpuio"; |
1063 | if (bank->regs->wkup_en) | 1124 | #ifdef CONFIG_ARCH_OMAP16XX |
1064 | bank->chip.dev = &omap_mpuio_device.dev; | 1125 | bank->chip.dev = &omap_mpuio_device.dev; |
1126 | #endif | ||
1065 | bank->chip.base = OMAP_MPUIO(0); | 1127 | bank->chip.base = OMAP_MPUIO(0); |
1066 | } else { | 1128 | } else { |
1067 | bank->chip.label = "gpio"; | 1129 | bank->chip.label = "gpio"; |
@@ -1072,10 +1134,11 @@ static void omap_gpio_chip_init(struct gpio_bank *bank) | |||
1072 | 1134 | ||
1073 | gpiochip_add(&bank->chip); | 1135 | gpiochip_add(&bank->chip); |
1074 | 1136 | ||
1075 | for (j = bank->irq_base; j < bank->irq_base + bank->width; j++) { | 1137 | for (j = bank->virtual_irq_start; |
1138 | j < bank->virtual_irq_start + bank->width; j++) { | ||
1076 | irq_set_lockdep_class(j, &gpio_lock_class); | 1139 | irq_set_lockdep_class(j, &gpio_lock_class); |
1077 | irq_set_chip_data(j, bank); | 1140 | irq_set_chip_data(j, bank); |
1078 | if (bank->is_mpuio) { | 1141 | if (bank_is_mpuio(bank)) { |
1079 | omap_mpuio_alloc_gc(bank, j, bank->width); | 1142 | omap_mpuio_alloc_gc(bank, j, bank->width); |
1080 | } else { | 1143 | } else { |
1081 | irq_set_chip(j, &gpio_irq_chip); | 1144 | irq_set_chip(j, &gpio_irq_chip); |
@@ -1087,57 +1150,45 @@ static void omap_gpio_chip_init(struct gpio_bank *bank) | |||
1087 | irq_set_handler_data(bank->irq, bank); | 1150 | irq_set_handler_data(bank->irq, bank); |
1088 | } | 1151 | } |
1089 | 1152 | ||
1090 | static const struct of_device_id omap_gpio_match[]; | 1153 | static int __devinit omap_gpio_probe(struct platform_device *pdev) |
1091 | |||
1092 | static int omap_gpio_probe(struct platform_device *pdev) | ||
1093 | { | 1154 | { |
1094 | struct device *dev = &pdev->dev; | 1155 | static int gpio_init_done; |
1095 | struct device_node *node = dev->of_node; | 1156 | struct omap_gpio_platform_data *pdata; |
1096 | const struct of_device_id *match; | ||
1097 | const struct omap_gpio_platform_data *pdata; | ||
1098 | struct resource *res; | 1157 | struct resource *res; |
1158 | int id; | ||
1099 | struct gpio_bank *bank; | 1159 | struct gpio_bank *bank; |
1100 | int ret = 0; | ||
1101 | 1160 | ||
1102 | match = of_match_device(of_match_ptr(omap_gpio_match), dev); | 1161 | if (!pdev->dev.platform_data) |
1103 | |||
1104 | pdata = match ? match->data : dev->platform_data; | ||
1105 | if (!pdata) | ||
1106 | return -EINVAL; | 1162 | return -EINVAL; |
1107 | 1163 | ||
1108 | bank = devm_kzalloc(dev, sizeof(struct gpio_bank), GFP_KERNEL); | 1164 | pdata = pdev->dev.platform_data; |
1109 | if (!bank) { | 1165 | |
1110 | dev_err(dev, "Memory alloc failed\n"); | 1166 | if (!gpio_init_done) { |
1111 | return -ENOMEM; | 1167 | int ret; |
1168 | |||
1169 | ret = init_gpio_info(pdev); | ||
1170 | if (ret) | ||
1171 | return ret; | ||
1112 | } | 1172 | } |
1113 | 1173 | ||
1174 | id = pdev->id; | ||
1175 | bank = &gpio_bank[id]; | ||
1176 | |||
1114 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 1177 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
1115 | if (unlikely(!res)) { | 1178 | if (unlikely(!res)) { |
1116 | dev_err(dev, "Invalid IRQ resource\n"); | 1179 | dev_err(&pdev->dev, "GPIO Bank %i Invalid IRQ resource\n", id); |
1117 | return -ENODEV; | 1180 | return -ENODEV; |
1118 | } | 1181 | } |
1119 | 1182 | ||
1120 | bank->irq = res->start; | 1183 | bank->irq = res->start; |
1121 | bank->dev = dev; | 1184 | bank->virtual_irq_start = pdata->virtual_irq_start; |
1185 | bank->method = pdata->bank_type; | ||
1186 | bank->dev = &pdev->dev; | ||
1122 | bank->dbck_flag = pdata->dbck_flag; | 1187 | bank->dbck_flag = pdata->dbck_flag; |
1123 | bank->stride = pdata->bank_stride; | 1188 | bank->stride = pdata->bank_stride; |
1124 | bank->width = pdata->bank_width; | 1189 | bank->width = pdata->bank_width; |
1125 | bank->is_mpuio = pdata->is_mpuio; | ||
1126 | bank->non_wakeup_gpios = pdata->non_wakeup_gpios; | ||
1127 | bank->loses_context = pdata->loses_context; | ||
1128 | bank->regs = pdata->regs; | ||
1129 | #ifdef CONFIG_OF_GPIO | ||
1130 | bank->chip.of_node = of_node_get(node); | ||
1131 | #endif | ||
1132 | 1190 | ||
1133 | bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0); | 1191 | bank->regs = pdata->regs; |
1134 | if (bank->irq_base < 0) { | ||
1135 | dev_err(dev, "Couldn't allocate IRQ numbers\n"); | ||
1136 | return -ENODEV; | ||
1137 | } | ||
1138 | |||
1139 | bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base, | ||
1140 | 0, &irq_domain_simple_ops, NULL); | ||
1141 | 1192 | ||
1142 | if (bank->regs->set_dataout && bank->regs->clr_dataout) | 1193 | if (bank->regs->set_dataout && bank->regs->clr_dataout) |
1143 | bank->set_dataout = _set_gpio_dataout_reg; | 1194 | bank->set_dataout = _set_gpio_dataout_reg; |
@@ -1149,375 +1200,369 @@ static int omap_gpio_probe(struct platform_device *pdev) | |||
1149 | /* Static mapping, never released */ | 1200 | /* Static mapping, never released */ |
1150 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1201 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1151 | if (unlikely(!res)) { | 1202 | if (unlikely(!res)) { |
1152 | dev_err(dev, "Invalid mem resource\n"); | 1203 | dev_err(&pdev->dev, "GPIO Bank %i Invalid mem resource\n", id); |
1153 | return -ENODEV; | 1204 | return -ENODEV; |
1154 | } | 1205 | } |
1155 | 1206 | ||
1156 | if (!devm_request_mem_region(dev, res->start, resource_size(res), | 1207 | bank->base = ioremap(res->start, resource_size(res)); |
1157 | pdev->name)) { | ||
1158 | dev_err(dev, "Region already claimed\n"); | ||
1159 | return -EBUSY; | ||
1160 | } | ||
1161 | |||
1162 | bank->base = devm_ioremap(dev, res->start, resource_size(res)); | ||
1163 | if (!bank->base) { | 1208 | if (!bank->base) { |
1164 | dev_err(dev, "Could not ioremap\n"); | 1209 | dev_err(&pdev->dev, "Could not ioremap gpio bank%i\n", id); |
1165 | return -ENOMEM; | 1210 | return -ENOMEM; |
1166 | } | 1211 | } |
1167 | 1212 | ||
1168 | platform_set_drvdata(pdev, bank); | ||
1169 | |||
1170 | pm_runtime_enable(bank->dev); | 1213 | pm_runtime_enable(bank->dev); |
1171 | pm_runtime_irq_safe(bank->dev); | ||
1172 | pm_runtime_get_sync(bank->dev); | 1214 | pm_runtime_get_sync(bank->dev); |
1173 | 1215 | ||
1174 | if (bank->is_mpuio) | 1216 | omap_gpio_mod_init(bank, id); |
1175 | mpuio_init(bank); | ||
1176 | |||
1177 | omap_gpio_mod_init(bank); | ||
1178 | omap_gpio_chip_init(bank); | 1217 | omap_gpio_chip_init(bank); |
1179 | omap_gpio_show_rev(bank); | 1218 | omap_gpio_show_rev(bank); |
1180 | 1219 | ||
1181 | if (bank->loses_context) | 1220 | if (!gpio_init_done) |
1182 | bank->get_context_loss_count = pdata->get_context_loss_count; | 1221 | gpio_init_done = 1; |
1183 | |||
1184 | pm_runtime_put(bank->dev); | ||
1185 | 1222 | ||
1186 | list_add_tail(&bank->node, &omap_gpio_list); | 1223 | return 0; |
1187 | |||
1188 | return ret; | ||
1189 | } | 1224 | } |
1190 | 1225 | ||
1191 | #ifdef CONFIG_ARCH_OMAP2PLUS | 1226 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
1192 | 1227 | static int omap_gpio_suspend(void) | |
1193 | #if defined(CONFIG_PM_RUNTIME) | ||
1194 | static void omap_gpio_restore_context(struct gpio_bank *bank); | ||
1195 | |||
1196 | static int omap_gpio_runtime_suspend(struct device *dev) | ||
1197 | { | 1228 | { |
1198 | struct platform_device *pdev = to_platform_device(dev); | 1229 | int i; |
1199 | struct gpio_bank *bank = platform_get_drvdata(pdev); | ||
1200 | u32 l1 = 0, l2 = 0; | ||
1201 | unsigned long flags; | ||
1202 | u32 wake_low, wake_hi; | ||
1203 | |||
1204 | spin_lock_irqsave(&bank->lock, flags); | ||
1205 | 1230 | ||
1206 | /* | 1231 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
1207 | * Only edges can generate a wakeup event to the PRCM. | 1232 | return 0; |
1208 | * | ||
1209 | * Therefore, ensure any wake-up capable GPIOs have | ||
1210 | * edge-detection enabled before going idle to ensure a wakeup | ||
1211 | * to the PRCM is generated on a GPIO transition. (c.f. 34xx | ||
1212 | * NDA TRM 25.5.3.1) | ||
1213 | * | ||
1214 | * The normal values will be restored upon ->runtime_resume() | ||
1215 | * by writing back the values saved in bank->context. | ||
1216 | */ | ||
1217 | wake_low = bank->context.leveldetect0 & bank->context.wake_en; | ||
1218 | if (wake_low) | ||
1219 | __raw_writel(wake_low | bank->context.fallingdetect, | ||
1220 | bank->base + bank->regs->fallingdetect); | ||
1221 | wake_hi = bank->context.leveldetect1 & bank->context.wake_en; | ||
1222 | if (wake_hi) | ||
1223 | __raw_writel(wake_hi | bank->context.risingdetect, | ||
1224 | bank->base + bank->regs->risingdetect); | ||
1225 | |||
1226 | if (!bank->enabled_non_wakeup_gpios) | ||
1227 | goto update_gpio_context_count; | ||
1228 | |||
1229 | if (bank->power_mode != OFF_MODE) { | ||
1230 | bank->power_mode = 0; | ||
1231 | goto update_gpio_context_count; | ||
1232 | } | ||
1233 | /* | ||
1234 | * If going to OFF, remove triggering for all | ||
1235 | * non-wakeup GPIOs. Otherwise spurious IRQs will be | ||
1236 | * generated. See OMAP2420 Errata item 1.101. | ||
1237 | */ | ||
1238 | bank->saved_datain = __raw_readl(bank->base + | ||
1239 | bank->regs->datain); | ||
1240 | l1 = bank->context.fallingdetect; | ||
1241 | l2 = bank->context.risingdetect; | ||
1242 | |||
1243 | l1 &= ~bank->enabled_non_wakeup_gpios; | ||
1244 | l2 &= ~bank->enabled_non_wakeup_gpios; | ||
1245 | |||
1246 | __raw_writel(l1, bank->base + bank->regs->fallingdetect); | ||
1247 | __raw_writel(l2, bank->base + bank->regs->risingdetect); | ||
1248 | |||
1249 | bank->workaround_enabled = true; | ||
1250 | 1233 | ||
1251 | update_gpio_context_count: | 1234 | for (i = 0; i < gpio_bank_count; i++) { |
1252 | if (bank->get_context_loss_count) | 1235 | struct gpio_bank *bank = &gpio_bank[i]; |
1253 | bank->context_loss_count = | 1236 | void __iomem *wake_status; |
1254 | bank->get_context_loss_count(bank->dev); | 1237 | void __iomem *wake_clear; |
1238 | void __iomem *wake_set; | ||
1239 | unsigned long flags; | ||
1240 | |||
1241 | switch (bank->method) { | ||
1242 | #ifdef CONFIG_ARCH_OMAP16XX | ||
1243 | case METHOD_GPIO_1610: | ||
1244 | wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE; | ||
1245 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; | ||
1246 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; | ||
1247 | break; | ||
1248 | #endif | ||
1249 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) | ||
1250 | case METHOD_GPIO_24XX: | ||
1251 | wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN; | ||
1252 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; | ||
1253 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; | ||
1254 | break; | ||
1255 | #endif | ||
1256 | #ifdef CONFIG_ARCH_OMAP4 | ||
1257 | case METHOD_GPIO_44XX: | ||
1258 | wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0; | ||
1259 | wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0; | ||
1260 | wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0; | ||
1261 | break; | ||
1262 | #endif | ||
1263 | default: | ||
1264 | continue; | ||
1265 | } | ||
1255 | 1266 | ||
1256 | _gpio_dbck_disable(bank); | 1267 | spin_lock_irqsave(&bank->lock, flags); |
1257 | spin_unlock_irqrestore(&bank->lock, flags); | 1268 | bank->saved_wakeup = __raw_readl(wake_status); |
1269 | __raw_writel(0xffffffff, wake_clear); | ||
1270 | __raw_writel(bank->suspend_wakeup, wake_set); | ||
1271 | spin_unlock_irqrestore(&bank->lock, flags); | ||
1272 | } | ||
1258 | 1273 | ||
1259 | return 0; | 1274 | return 0; |
1260 | } | 1275 | } |
1261 | 1276 | ||
1262 | static int omap_gpio_runtime_resume(struct device *dev) | 1277 | static void omap_gpio_resume(void) |
1263 | { | 1278 | { |
1264 | struct platform_device *pdev = to_platform_device(dev); | 1279 | int i; |
1265 | struct gpio_bank *bank = platform_get_drvdata(pdev); | ||
1266 | int context_lost_cnt_after; | ||
1267 | u32 l = 0, gen, gen0, gen1; | ||
1268 | unsigned long flags; | ||
1269 | 1280 | ||
1270 | spin_lock_irqsave(&bank->lock, flags); | 1281 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
1271 | _gpio_dbck_enable(bank); | 1282 | return; |
1272 | 1283 | ||
1273 | /* | 1284 | for (i = 0; i < gpio_bank_count; i++) { |
1274 | * In ->runtime_suspend(), level-triggered, wakeup-enabled | 1285 | struct gpio_bank *bank = &gpio_bank[i]; |
1275 | * GPIOs were set to edge trigger also in order to be able to | 1286 | void __iomem *wake_clear; |
1276 | * generate a PRCM wakeup. Here we restore the | 1287 | void __iomem *wake_set; |
1277 | * pre-runtime_suspend() values for edge triggering. | 1288 | unsigned long flags; |
1278 | */ | 1289 | |
1279 | __raw_writel(bank->context.fallingdetect, | 1290 | switch (bank->method) { |
1280 | bank->base + bank->regs->fallingdetect); | 1291 | #ifdef CONFIG_ARCH_OMAP16XX |
1281 | __raw_writel(bank->context.risingdetect, | 1292 | case METHOD_GPIO_1610: |
1282 | bank->base + bank->regs->risingdetect); | 1293 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
1283 | 1294 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; | |
1284 | if (bank->get_context_loss_count) { | 1295 | break; |
1285 | context_lost_cnt_after = | 1296 | #endif |
1286 | bank->get_context_loss_count(bank->dev); | 1297 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
1287 | if (context_lost_cnt_after != bank->context_loss_count) { | 1298 | case METHOD_GPIO_24XX: |
1288 | omap_gpio_restore_context(bank); | 1299 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
1289 | } else { | 1300 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
1290 | spin_unlock_irqrestore(&bank->lock, flags); | 1301 | break; |
1291 | return 0; | 1302 | #endif |
1303 | #ifdef CONFIG_ARCH_OMAP4 | ||
1304 | case METHOD_GPIO_44XX: | ||
1305 | wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0; | ||
1306 | wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0; | ||
1307 | break; | ||
1308 | #endif | ||
1309 | default: | ||
1310 | continue; | ||
1292 | } | 1311 | } |
1293 | } | ||
1294 | 1312 | ||
1295 | if (!bank->workaround_enabled) { | 1313 | spin_lock_irqsave(&bank->lock, flags); |
1314 | __raw_writel(0xffffffff, wake_clear); | ||
1315 | __raw_writel(bank->saved_wakeup, wake_set); | ||
1296 | spin_unlock_irqrestore(&bank->lock, flags); | 1316 | spin_unlock_irqrestore(&bank->lock, flags); |
1297 | return 0; | ||
1298 | } | 1317 | } |
1318 | } | ||
1299 | 1319 | ||
1300 | __raw_writel(bank->context.fallingdetect, | 1320 | static struct syscore_ops omap_gpio_syscore_ops = { |
1301 | bank->base + bank->regs->fallingdetect); | 1321 | .suspend = omap_gpio_suspend, |
1302 | __raw_writel(bank->context.risingdetect, | 1322 | .resume = omap_gpio_resume, |
1303 | bank->base + bank->regs->risingdetect); | 1323 | }; |
1304 | l = __raw_readl(bank->base + bank->regs->datain); | ||
1305 | 1324 | ||
1306 | /* | 1325 | #endif |
1307 | * Check if any of the non-wakeup interrupt GPIOs have changed | ||
1308 | * state. If so, generate an IRQ by software. This is | ||
1309 | * horribly racy, but it's the best we can do to work around | ||
1310 | * this silicon bug. | ||
1311 | */ | ||
1312 | l ^= bank->saved_datain; | ||
1313 | l &= bank->enabled_non_wakeup_gpios; | ||
1314 | 1326 | ||
1315 | /* | 1327 | #ifdef CONFIG_ARCH_OMAP2PLUS |
1316 | * No need to generate IRQs for the rising edge for gpio IRQs | ||
1317 | * configured with falling edge only; and vice versa. | ||
1318 | */ | ||
1319 | gen0 = l & bank->context.fallingdetect; | ||
1320 | gen0 &= bank->saved_datain; | ||
1321 | 1328 | ||
1322 | gen1 = l & bank->context.risingdetect; | 1329 | static int workaround_enabled; |
1323 | gen1 &= ~(bank->saved_datain); | ||
1324 | 1330 | ||
1325 | /* FIXME: Consider GPIO IRQs with level detections properly! */ | 1331 | void omap2_gpio_prepare_for_idle(int off_mode) |
1326 | gen = l & (~(bank->context.fallingdetect) & | 1332 | { |
1327 | ~(bank->context.risingdetect)); | 1333 | int i, c = 0; |
1328 | /* Consider all GPIO IRQs needed to be updated */ | 1334 | int min = 0; |
1329 | gen |= gen0 | gen1; | ||
1330 | 1335 | ||
1331 | if (gen) { | 1336 | if (cpu_is_omap34xx()) |
1332 | u32 old0, old1; | 1337 | min = 1; |
1333 | 1338 | ||
1334 | old0 = __raw_readl(bank->base + bank->regs->leveldetect0); | 1339 | for (i = min; i < gpio_bank_count; i++) { |
1335 | old1 = __raw_readl(bank->base + bank->regs->leveldetect1); | 1340 | struct gpio_bank *bank = &gpio_bank[i]; |
1341 | u32 l1 = 0, l2 = 0; | ||
1342 | int j; | ||
1336 | 1343 | ||
1337 | if (!bank->regs->irqstatus_raw0) { | 1344 | for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++) |
1338 | __raw_writel(old0 | gen, bank->base + | 1345 | clk_disable(bank->dbck); |
1339 | bank->regs->leveldetect0); | ||
1340 | __raw_writel(old1 | gen, bank->base + | ||
1341 | bank->regs->leveldetect1); | ||
1342 | } | ||
1343 | 1346 | ||
1344 | if (bank->regs->irqstatus_raw0) { | 1347 | if (!off_mode) |
1345 | __raw_writel(old0 | l, bank->base + | 1348 | continue; |
1346 | bank->regs->leveldetect0); | ||
1347 | __raw_writel(old1 | l, bank->base + | ||
1348 | bank->regs->leveldetect1); | ||
1349 | } | ||
1350 | __raw_writel(old0, bank->base + bank->regs->leveldetect0); | ||
1351 | __raw_writel(old1, bank->base + bank->regs->leveldetect1); | ||
1352 | } | ||
1353 | 1349 | ||
1354 | bank->workaround_enabled = false; | 1350 | /* If going to OFF, remove triggering for all |
1355 | spin_unlock_irqrestore(&bank->lock, flags); | 1351 | * non-wakeup GPIOs. Otherwise spurious IRQs will be |
1352 | * generated. See OMAP2420 Errata item 1.101. */ | ||
1353 | if (!(bank->enabled_non_wakeup_gpios)) | ||
1354 | continue; | ||
1356 | 1355 | ||
1357 | return 0; | 1356 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
1358 | } | 1357 | bank->saved_datain = __raw_readl(bank->base + |
1359 | #endif /* CONFIG_PM_RUNTIME */ | 1358 | OMAP24XX_GPIO_DATAIN); |
1359 | l1 = __raw_readl(bank->base + | ||
1360 | OMAP24XX_GPIO_FALLINGDETECT); | ||
1361 | l2 = __raw_readl(bank->base + | ||
1362 | OMAP24XX_GPIO_RISINGDETECT); | ||
1363 | } | ||
1360 | 1364 | ||
1361 | void omap2_gpio_prepare_for_idle(int pwr_mode) | 1365 | if (cpu_is_omap44xx()) { |
1362 | { | 1366 | bank->saved_datain = __raw_readl(bank->base + |
1363 | struct gpio_bank *bank; | 1367 | OMAP4_GPIO_DATAIN); |
1368 | l1 = __raw_readl(bank->base + | ||
1369 | OMAP4_GPIO_FALLINGDETECT); | ||
1370 | l2 = __raw_readl(bank->base + | ||
1371 | OMAP4_GPIO_RISINGDETECT); | ||
1372 | } | ||
1364 | 1373 | ||
1365 | list_for_each_entry(bank, &omap_gpio_list, node) { | 1374 | bank->saved_fallingdetect = l1; |
1366 | if (!bank->mod_usage || !bank->loses_context) | 1375 | bank->saved_risingdetect = l2; |
1367 | continue; | 1376 | l1 &= ~bank->enabled_non_wakeup_gpios; |
1377 | l2 &= ~bank->enabled_non_wakeup_gpios; | ||
1368 | 1378 | ||
1369 | bank->power_mode = pwr_mode; | 1379 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
1380 | __raw_writel(l1, bank->base + | ||
1381 | OMAP24XX_GPIO_FALLINGDETECT); | ||
1382 | __raw_writel(l2, bank->base + | ||
1383 | OMAP24XX_GPIO_RISINGDETECT); | ||
1384 | } | ||
1370 | 1385 | ||
1371 | pm_runtime_put_sync_suspend(bank->dev); | 1386 | if (cpu_is_omap44xx()) { |
1387 | __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT); | ||
1388 | __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT); | ||
1389 | } | ||
1390 | |||
1391 | c++; | ||
1392 | } | ||
1393 | if (!c) { | ||
1394 | workaround_enabled = 0; | ||
1395 | return; | ||
1372 | } | 1396 | } |
1397 | workaround_enabled = 1; | ||
1373 | } | 1398 | } |
1374 | 1399 | ||
1375 | void omap2_gpio_resume_after_idle(void) | 1400 | void omap2_gpio_resume_after_idle(void) |
1376 | { | 1401 | { |
1377 | struct gpio_bank *bank; | 1402 | int i; |
1403 | int min = 0; | ||
1378 | 1404 | ||
1379 | list_for_each_entry(bank, &omap_gpio_list, node) { | 1405 | if (cpu_is_omap34xx()) |
1380 | if (!bank->mod_usage || !bank->loses_context) | 1406 | min = 1; |
1381 | continue; | 1407 | for (i = min; i < gpio_bank_count; i++) { |
1408 | struct gpio_bank *bank = &gpio_bank[i]; | ||
1409 | u32 l = 0, gen, gen0, gen1; | ||
1410 | int j; | ||
1382 | 1411 | ||
1383 | pm_runtime_get_sync(bank->dev); | 1412 | for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++) |
1384 | } | 1413 | clk_enable(bank->dbck); |
1385 | } | ||
1386 | 1414 | ||
1387 | #if defined(CONFIG_PM_RUNTIME) | 1415 | if (!workaround_enabled) |
1388 | static void omap_gpio_restore_context(struct gpio_bank *bank) | 1416 | continue; |
1389 | { | ||
1390 | __raw_writel(bank->context.wake_en, | ||
1391 | bank->base + bank->regs->wkup_en); | ||
1392 | __raw_writel(bank->context.ctrl, bank->base + bank->regs->ctrl); | ||
1393 | __raw_writel(bank->context.leveldetect0, | ||
1394 | bank->base + bank->regs->leveldetect0); | ||
1395 | __raw_writel(bank->context.leveldetect1, | ||
1396 | bank->base + bank->regs->leveldetect1); | ||
1397 | __raw_writel(bank->context.risingdetect, | ||
1398 | bank->base + bank->regs->risingdetect); | ||
1399 | __raw_writel(bank->context.fallingdetect, | ||
1400 | bank->base + bank->regs->fallingdetect); | ||
1401 | if (bank->regs->set_dataout && bank->regs->clr_dataout) | ||
1402 | __raw_writel(bank->context.dataout, | ||
1403 | bank->base + bank->regs->set_dataout); | ||
1404 | else | ||
1405 | __raw_writel(bank->context.dataout, | ||
1406 | bank->base + bank->regs->dataout); | ||
1407 | __raw_writel(bank->context.oe, bank->base + bank->regs->direction); | ||
1408 | |||
1409 | if (bank->dbck_enable_mask) { | ||
1410 | __raw_writel(bank->context.debounce, bank->base + | ||
1411 | bank->regs->debounce); | ||
1412 | __raw_writel(bank->context.debounce_en, | ||
1413 | bank->base + bank->regs->debounce_en); | ||
1414 | } | ||
1415 | 1417 | ||
1416 | __raw_writel(bank->context.irqenable1, | 1418 | if (!(bank->enabled_non_wakeup_gpios)) |
1417 | bank->base + bank->regs->irqenable); | 1419 | continue; |
1418 | __raw_writel(bank->context.irqenable2, | ||
1419 | bank->base + bank->regs->irqenable2); | ||
1420 | } | ||
1421 | #endif /* CONFIG_PM_RUNTIME */ | ||
1422 | #else | ||
1423 | #define omap_gpio_runtime_suspend NULL | ||
1424 | #define omap_gpio_runtime_resume NULL | ||
1425 | #endif | ||
1426 | 1420 | ||
1427 | static const struct dev_pm_ops gpio_pm_ops = { | 1421 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
1428 | SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume, | 1422 | __raw_writel(bank->saved_fallingdetect, |
1429 | NULL) | 1423 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
1430 | }; | 1424 | __raw_writel(bank->saved_risingdetect, |
1425 | bank->base + OMAP24XX_GPIO_RISINGDETECT); | ||
1426 | l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN); | ||
1427 | } | ||
1431 | 1428 | ||
1432 | #if defined(CONFIG_OF) | 1429 | if (cpu_is_omap44xx()) { |
1433 | static struct omap_gpio_reg_offs omap2_gpio_regs = { | 1430 | __raw_writel(bank->saved_fallingdetect, |
1434 | .revision = OMAP24XX_GPIO_REVISION, | 1431 | bank->base + OMAP4_GPIO_FALLINGDETECT); |
1435 | .direction = OMAP24XX_GPIO_OE, | 1432 | __raw_writel(bank->saved_risingdetect, |
1436 | .datain = OMAP24XX_GPIO_DATAIN, | 1433 | bank->base + OMAP4_GPIO_RISINGDETECT); |
1437 | .dataout = OMAP24XX_GPIO_DATAOUT, | 1434 | l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN); |
1438 | .set_dataout = OMAP24XX_GPIO_SETDATAOUT, | 1435 | } |
1439 | .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT, | ||
1440 | .irqstatus = OMAP24XX_GPIO_IRQSTATUS1, | ||
1441 | .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2, | ||
1442 | .irqenable = OMAP24XX_GPIO_IRQENABLE1, | ||
1443 | .irqenable2 = OMAP24XX_GPIO_IRQENABLE2, | ||
1444 | .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1, | ||
1445 | .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1, | ||
1446 | .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL, | ||
1447 | .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN, | ||
1448 | .ctrl = OMAP24XX_GPIO_CTRL, | ||
1449 | .wkup_en = OMAP24XX_GPIO_WAKE_EN, | ||
1450 | .leveldetect0 = OMAP24XX_GPIO_LEVELDETECT0, | ||
1451 | .leveldetect1 = OMAP24XX_GPIO_LEVELDETECT1, | ||
1452 | .risingdetect = OMAP24XX_GPIO_RISINGDETECT, | ||
1453 | .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT, | ||
1454 | }; | ||
1455 | 1436 | ||
1456 | static struct omap_gpio_reg_offs omap4_gpio_regs = { | 1437 | /* Check if any of the non-wakeup interrupt GPIOs have changed |
1457 | .revision = OMAP4_GPIO_REVISION, | 1438 | * state. If so, generate an IRQ by software. This is |
1458 | .direction = OMAP4_GPIO_OE, | 1439 | * horribly racy, but it's the best we can do to work around |
1459 | .datain = OMAP4_GPIO_DATAIN, | 1440 | * this silicon bug. */ |
1460 | .dataout = OMAP4_GPIO_DATAOUT, | 1441 | l ^= bank->saved_datain; |
1461 | .set_dataout = OMAP4_GPIO_SETDATAOUT, | 1442 | l &= bank->enabled_non_wakeup_gpios; |
1462 | .clr_dataout = OMAP4_GPIO_CLEARDATAOUT, | ||
1463 | .irqstatus = OMAP4_GPIO_IRQSTATUS0, | ||
1464 | .irqstatus2 = OMAP4_GPIO_IRQSTATUS1, | ||
1465 | .irqenable = OMAP4_GPIO_IRQSTATUSSET0, | ||
1466 | .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1, | ||
1467 | .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0, | ||
1468 | .clr_irqenable = OMAP4_GPIO_IRQSTATUSCLR0, | ||
1469 | .debounce = OMAP4_GPIO_DEBOUNCINGTIME, | ||
1470 | .debounce_en = OMAP4_GPIO_DEBOUNCENABLE, | ||
1471 | .ctrl = OMAP4_GPIO_CTRL, | ||
1472 | .wkup_en = OMAP4_GPIO_IRQWAKEN0, | ||
1473 | .leveldetect0 = OMAP4_GPIO_LEVELDETECT0, | ||
1474 | .leveldetect1 = OMAP4_GPIO_LEVELDETECT1, | ||
1475 | .risingdetect = OMAP4_GPIO_RISINGDETECT, | ||
1476 | .fallingdetect = OMAP4_GPIO_FALLINGDETECT, | ||
1477 | }; | ||
1478 | 1443 | ||
1479 | const static struct omap_gpio_platform_data omap2_pdata = { | 1444 | /* |
1480 | .regs = &omap2_gpio_regs, | 1445 | * No need to generate IRQs for the rising edge for gpio IRQs |
1481 | .bank_width = 32, | 1446 | * configured with falling edge only; and vice versa. |
1482 | .dbck_flag = false, | 1447 | */ |
1483 | }; | 1448 | gen0 = l & bank->saved_fallingdetect; |
1449 | gen0 &= bank->saved_datain; | ||
1450 | |||
1451 | gen1 = l & bank->saved_risingdetect; | ||
1452 | gen1 &= ~(bank->saved_datain); | ||
1453 | |||
1454 | /* FIXME: Consider GPIO IRQs with level detections properly! */ | ||
1455 | gen = l & (~(bank->saved_fallingdetect) & | ||
1456 | ~(bank->saved_risingdetect)); | ||
1457 | /* Consider all GPIO IRQs needed to be updated */ | ||
1458 | gen |= gen0 | gen1; | ||
1459 | |||
1460 | if (gen) { | ||
1461 | u32 old0, old1; | ||
1462 | |||
1463 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { | ||
1464 | old0 = __raw_readl(bank->base + | ||
1465 | OMAP24XX_GPIO_LEVELDETECT0); | ||
1466 | old1 = __raw_readl(bank->base + | ||
1467 | OMAP24XX_GPIO_LEVELDETECT1); | ||
1468 | __raw_writel(old0 | gen, bank->base + | ||
1469 | OMAP24XX_GPIO_LEVELDETECT0); | ||
1470 | __raw_writel(old1 | gen, bank->base + | ||
1471 | OMAP24XX_GPIO_LEVELDETECT1); | ||
1472 | __raw_writel(old0, bank->base + | ||
1473 | OMAP24XX_GPIO_LEVELDETECT0); | ||
1474 | __raw_writel(old1, bank->base + | ||
1475 | OMAP24XX_GPIO_LEVELDETECT1); | ||
1476 | } | ||
1477 | |||
1478 | if (cpu_is_omap44xx()) { | ||
1479 | old0 = __raw_readl(bank->base + | ||
1480 | OMAP4_GPIO_LEVELDETECT0); | ||
1481 | old1 = __raw_readl(bank->base + | ||
1482 | OMAP4_GPIO_LEVELDETECT1); | ||
1483 | __raw_writel(old0 | l, bank->base + | ||
1484 | OMAP4_GPIO_LEVELDETECT0); | ||
1485 | __raw_writel(old1 | l, bank->base + | ||
1486 | OMAP4_GPIO_LEVELDETECT1); | ||
1487 | __raw_writel(old0, bank->base + | ||
1488 | OMAP4_GPIO_LEVELDETECT0); | ||
1489 | __raw_writel(old1, bank->base + | ||
1490 | OMAP4_GPIO_LEVELDETECT1); | ||
1491 | } | ||
1492 | } | ||
1493 | } | ||
1484 | 1494 | ||
1485 | const static struct omap_gpio_platform_data omap3_pdata = { | 1495 | } |
1486 | .regs = &omap2_gpio_regs, | ||
1487 | .bank_width = 32, | ||
1488 | .dbck_flag = true, | ||
1489 | }; | ||
1490 | 1496 | ||
1491 | const static struct omap_gpio_platform_data omap4_pdata = { | 1497 | #endif |
1492 | .regs = &omap4_gpio_regs, | ||
1493 | .bank_width = 32, | ||
1494 | .dbck_flag = true, | ||
1495 | }; | ||
1496 | 1498 | ||
1497 | static const struct of_device_id omap_gpio_match[] = { | 1499 | #ifdef CONFIG_ARCH_OMAP3 |
1498 | { | 1500 | /* save the registers of bank 2-6 */ |
1499 | .compatible = "ti,omap4-gpio", | 1501 | void omap_gpio_save_context(void) |
1500 | .data = &omap4_pdata, | 1502 | { |
1501 | }, | 1503 | int i; |
1502 | { | 1504 | |
1503 | .compatible = "ti,omap3-gpio", | 1505 | /* saving banks from 2-6 only since GPIO1 is in WKUP */ |
1504 | .data = &omap3_pdata, | 1506 | for (i = 1; i < gpio_bank_count; i++) { |
1505 | }, | 1507 | struct gpio_bank *bank = &gpio_bank[i]; |
1506 | { | 1508 | gpio_context[i].irqenable1 = |
1507 | .compatible = "ti,omap2-gpio", | 1509 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1); |
1508 | .data = &omap2_pdata, | 1510 | gpio_context[i].irqenable2 = |
1509 | }, | 1511 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2); |
1510 | { }, | 1512 | gpio_context[i].wake_en = |
1511 | }; | 1513 | __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN); |
1512 | MODULE_DEVICE_TABLE(of, omap_gpio_match); | 1514 | gpio_context[i].ctrl = |
1515 | __raw_readl(bank->base + OMAP24XX_GPIO_CTRL); | ||
1516 | gpio_context[i].oe = | ||
1517 | __raw_readl(bank->base + OMAP24XX_GPIO_OE); | ||
1518 | gpio_context[i].leveldetect0 = | ||
1519 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0); | ||
1520 | gpio_context[i].leveldetect1 = | ||
1521 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); | ||
1522 | gpio_context[i].risingdetect = | ||
1523 | __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT); | ||
1524 | gpio_context[i].fallingdetect = | ||
1525 | __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT); | ||
1526 | gpio_context[i].dataout = | ||
1527 | __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT); | ||
1528 | } | ||
1529 | } | ||
1530 | |||
1531 | /* restore the required registers of bank 2-6 */ | ||
1532 | void omap_gpio_restore_context(void) | ||
1533 | { | ||
1534 | int i; | ||
1535 | |||
1536 | for (i = 1; i < gpio_bank_count; i++) { | ||
1537 | struct gpio_bank *bank = &gpio_bank[i]; | ||
1538 | __raw_writel(gpio_context[i].irqenable1, | ||
1539 | bank->base + OMAP24XX_GPIO_IRQENABLE1); | ||
1540 | __raw_writel(gpio_context[i].irqenable2, | ||
1541 | bank->base + OMAP24XX_GPIO_IRQENABLE2); | ||
1542 | __raw_writel(gpio_context[i].wake_en, | ||
1543 | bank->base + OMAP24XX_GPIO_WAKE_EN); | ||
1544 | __raw_writel(gpio_context[i].ctrl, | ||
1545 | bank->base + OMAP24XX_GPIO_CTRL); | ||
1546 | __raw_writel(gpio_context[i].oe, | ||
1547 | bank->base + OMAP24XX_GPIO_OE); | ||
1548 | __raw_writel(gpio_context[i].leveldetect0, | ||
1549 | bank->base + OMAP24XX_GPIO_LEVELDETECT0); | ||
1550 | __raw_writel(gpio_context[i].leveldetect1, | ||
1551 | bank->base + OMAP24XX_GPIO_LEVELDETECT1); | ||
1552 | __raw_writel(gpio_context[i].risingdetect, | ||
1553 | bank->base + OMAP24XX_GPIO_RISINGDETECT); | ||
1554 | __raw_writel(gpio_context[i].fallingdetect, | ||
1555 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); | ||
1556 | __raw_writel(gpio_context[i].dataout, | ||
1557 | bank->base + OMAP24XX_GPIO_DATAOUT); | ||
1558 | } | ||
1559 | } | ||
1513 | #endif | 1560 | #endif |
1514 | 1561 | ||
1515 | static struct platform_driver omap_gpio_driver = { | 1562 | static struct platform_driver omap_gpio_driver = { |
1516 | .probe = omap_gpio_probe, | 1563 | .probe = omap_gpio_probe, |
1517 | .driver = { | 1564 | .driver = { |
1518 | .name = "omap_gpio", | 1565 | .name = "omap_gpio", |
1519 | .pm = &gpio_pm_ops, | ||
1520 | .of_match_table = of_match_ptr(omap_gpio_match), | ||
1521 | }, | 1566 | }, |
1522 | }; | 1567 | }; |
1523 | 1568 | ||
@@ -1531,3 +1576,17 @@ static int __init omap_gpio_drv_reg(void) | |||
1531 | return platform_driver_register(&omap_gpio_driver); | 1576 | return platform_driver_register(&omap_gpio_driver); |
1532 | } | 1577 | } |
1533 | postcore_initcall(omap_gpio_drv_reg); | 1578 | postcore_initcall(omap_gpio_drv_reg); |
1579 | |||
1580 | static int __init omap_gpio_sysinit(void) | ||
1581 | { | ||
1582 | mpuio_init(); | ||
1583 | |||
1584 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) | ||
1585 | if (cpu_is_omap16xx() || cpu_class_is_omap2()) | ||
1586 | register_syscore_ops(&omap_gpio_syscore_ops); | ||
1587 | #endif | ||
1588 | |||
1589 | return 0; | ||
1590 | } | ||
1591 | |||
1592 | arch_initcall(omap_gpio_sysinit); | ||
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index cc102d25ee2..0550dcb8581 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include <linux/gpio.h> | 16 | #include <linux/gpio.h> |
17 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/irq.h> | 18 | #include <linux/irq.h> |
19 | #include <linux/irqdomain.h> | ||
20 | #include <linux/i2c.h> | 19 | #include <linux/i2c.h> |
21 | #include <linux/i2c/pca953x.h> | 20 | #include <linux/i2c/pca953x.h> |
22 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
@@ -29,8 +28,6 @@ | |||
29 | #define PCA953X_INVERT 2 | 28 | #define PCA953X_INVERT 2 |
30 | #define PCA953X_DIRECTION 3 | 29 | #define PCA953X_DIRECTION 3 |
31 | 30 | ||
32 | #define REG_ADDR_AI 0x80 | ||
33 | |||
34 | #define PCA957X_IN 0 | 31 | #define PCA957X_IN 0 |
35 | #define PCA957X_INVRT 1 | 32 | #define PCA957X_INVRT 1 |
36 | #define PCA957X_BKEN 2 | 33 | #define PCA957X_BKEN 2 |
@@ -66,25 +63,24 @@ static const struct i2c_device_id pca953x_id[] = { | |||
66 | { "pca6107", 8 | PCA953X_TYPE | PCA_INT, }, | 63 | { "pca6107", 8 | PCA953X_TYPE | PCA_INT, }, |
67 | { "tca6408", 8 | PCA953X_TYPE | PCA_INT, }, | 64 | { "tca6408", 8 | PCA953X_TYPE | PCA_INT, }, |
68 | { "tca6416", 16 | PCA953X_TYPE | PCA_INT, }, | 65 | { "tca6416", 16 | PCA953X_TYPE | PCA_INT, }, |
69 | { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, | 66 | /* NYET: { "tca6424", 24, }, */ |
70 | { } | 67 | { } |
71 | }; | 68 | }; |
72 | MODULE_DEVICE_TABLE(i2c, pca953x_id); | 69 | MODULE_DEVICE_TABLE(i2c, pca953x_id); |
73 | 70 | ||
74 | struct pca953x_chip { | 71 | struct pca953x_chip { |
75 | unsigned gpio_start; | 72 | unsigned gpio_start; |
76 | u32 reg_output; | 73 | uint16_t reg_output; |
77 | u32 reg_direction; | 74 | uint16_t reg_direction; |
78 | struct mutex i2c_lock; | 75 | struct mutex i2c_lock; |
79 | 76 | ||
80 | #ifdef CONFIG_GPIO_PCA953X_IRQ | 77 | #ifdef CONFIG_GPIO_PCA953X_IRQ |
81 | struct mutex irq_lock; | 78 | struct mutex irq_lock; |
82 | u32 irq_mask; | 79 | uint16_t irq_mask; |
83 | u32 irq_stat; | 80 | uint16_t irq_stat; |
84 | u32 irq_trig_raise; | 81 | uint16_t irq_trig_raise; |
85 | u32 irq_trig_fall; | 82 | uint16_t irq_trig_fall; |
86 | int irq_base; | 83 | int irq_base; |
87 | struct irq_domain *domain; | ||
88 | #endif | 84 | #endif |
89 | 85 | ||
90 | struct i2c_client *client; | 86 | struct i2c_client *client; |
@@ -93,19 +89,12 @@ struct pca953x_chip { | |||
93 | int chip_type; | 89 | int chip_type; |
94 | }; | 90 | }; |
95 | 91 | ||
96 | static int pca953x_write_reg(struct pca953x_chip *chip, int reg, u32 val) | 92 | static int pca953x_write_reg(struct pca953x_chip *chip, int reg, uint16_t val) |
97 | { | 93 | { |
98 | int ret = 0; | 94 | int ret = 0; |
99 | 95 | ||
100 | if (chip->gpio_chip.ngpio <= 8) | 96 | if (chip->gpio_chip.ngpio <= 8) |
101 | ret = i2c_smbus_write_byte_data(chip->client, reg, val); | 97 | ret = i2c_smbus_write_byte_data(chip->client, reg, val); |
102 | else if (chip->gpio_chip.ngpio == 24) { | ||
103 | cpu_to_le32s(&val); | ||
104 | ret = i2c_smbus_write_i2c_block_data(chip->client, | ||
105 | (reg << 2) | REG_ADDR_AI, | ||
106 | 3, | ||
107 | (u8 *) &val); | ||
108 | } | ||
109 | else { | 98 | else { |
110 | switch (chip->chip_type) { | 99 | switch (chip->chip_type) { |
111 | case PCA953X_TYPE: | 100 | case PCA953X_TYPE: |
@@ -132,38 +121,28 @@ static int pca953x_write_reg(struct pca953x_chip *chip, int reg, u32 val) | |||
132 | return 0; | 121 | return 0; |
133 | } | 122 | } |
134 | 123 | ||
135 | static int pca953x_read_reg(struct pca953x_chip *chip, int reg, u32 *val) | 124 | static int pca953x_read_reg(struct pca953x_chip *chip, int reg, uint16_t *val) |
136 | { | 125 | { |
137 | int ret; | 126 | int ret; |
138 | 127 | ||
139 | if (chip->gpio_chip.ngpio <= 8) { | 128 | if (chip->gpio_chip.ngpio <= 8) |
140 | ret = i2c_smbus_read_byte_data(chip->client, reg); | 129 | ret = i2c_smbus_read_byte_data(chip->client, reg); |
141 | *val = ret; | 130 | else |
142 | } | ||
143 | else if (chip->gpio_chip.ngpio == 24) { | ||
144 | *val = 0; | ||
145 | ret = i2c_smbus_read_i2c_block_data(chip->client, | ||
146 | (reg << 2) | REG_ADDR_AI, | ||
147 | 3, | ||
148 | (u8 *) val); | ||
149 | le32_to_cpus(val); | ||
150 | } else { | ||
151 | ret = i2c_smbus_read_word_data(chip->client, reg << 1); | 131 | ret = i2c_smbus_read_word_data(chip->client, reg << 1); |
152 | *val = ret; | ||
153 | } | ||
154 | 132 | ||
155 | if (ret < 0) { | 133 | if (ret < 0) { |
156 | dev_err(&chip->client->dev, "failed reading register\n"); | 134 | dev_err(&chip->client->dev, "failed reading register\n"); |
157 | return ret; | 135 | return ret; |
158 | } | 136 | } |
159 | 137 | ||
138 | *val = (uint16_t)ret; | ||
160 | return 0; | 139 | return 0; |
161 | } | 140 | } |
162 | 141 | ||
163 | static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) | 142 | static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) |
164 | { | 143 | { |
165 | struct pca953x_chip *chip; | 144 | struct pca953x_chip *chip; |
166 | uint reg_val; | 145 | uint16_t reg_val; |
167 | int ret, offset = 0; | 146 | int ret, offset = 0; |
168 | 147 | ||
169 | chip = container_of(gc, struct pca953x_chip, gpio_chip); | 148 | chip = container_of(gc, struct pca953x_chip, gpio_chip); |
@@ -194,7 +173,7 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc, | |||
194 | unsigned off, int val) | 173 | unsigned off, int val) |
195 | { | 174 | { |
196 | struct pca953x_chip *chip; | 175 | struct pca953x_chip *chip; |
197 | uint reg_val; | 176 | uint16_t reg_val; |
198 | int ret, offset = 0; | 177 | int ret, offset = 0; |
199 | 178 | ||
200 | chip = container_of(gc, struct pca953x_chip, gpio_chip); | 179 | chip = container_of(gc, struct pca953x_chip, gpio_chip); |
@@ -244,7 +223,7 @@ exit: | |||
244 | static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) | 223 | static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) |
245 | { | 224 | { |
246 | struct pca953x_chip *chip; | 225 | struct pca953x_chip *chip; |
247 | u32 reg_val; | 226 | uint16_t reg_val; |
248 | int ret, offset = 0; | 227 | int ret, offset = 0; |
249 | 228 | ||
250 | chip = container_of(gc, struct pca953x_chip, gpio_chip); | 229 | chip = container_of(gc, struct pca953x_chip, gpio_chip); |
@@ -274,7 +253,7 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) | |||
274 | static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) | 253 | static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) |
275 | { | 254 | { |
276 | struct pca953x_chip *chip; | 255 | struct pca953x_chip *chip; |
277 | u32 reg_val; | 256 | uint16_t reg_val; |
278 | int ret, offset = 0; | 257 | int ret, offset = 0; |
279 | 258 | ||
280 | chip = container_of(gc, struct pca953x_chip, gpio_chip); | 259 | chip = container_of(gc, struct pca953x_chip, gpio_chip); |
@@ -335,14 +314,14 @@ static void pca953x_irq_mask(struct irq_data *d) | |||
335 | { | 314 | { |
336 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); | 315 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); |
337 | 316 | ||
338 | chip->irq_mask &= ~(1 << d->hwirq); | 317 | chip->irq_mask &= ~(1 << (d->irq - chip->irq_base)); |
339 | } | 318 | } |
340 | 319 | ||
341 | static void pca953x_irq_unmask(struct irq_data *d) | 320 | static void pca953x_irq_unmask(struct irq_data *d) |
342 | { | 321 | { |
343 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); | 322 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); |
344 | 323 | ||
345 | chip->irq_mask |= 1 << d->hwirq; | 324 | chip->irq_mask |= 1 << (d->irq - chip->irq_base); |
346 | } | 325 | } |
347 | 326 | ||
348 | static void pca953x_irq_bus_lock(struct irq_data *d) | 327 | static void pca953x_irq_bus_lock(struct irq_data *d) |
@@ -355,8 +334,8 @@ static void pca953x_irq_bus_lock(struct irq_data *d) | |||
355 | static void pca953x_irq_bus_sync_unlock(struct irq_data *d) | 334 | static void pca953x_irq_bus_sync_unlock(struct irq_data *d) |
356 | { | 335 | { |
357 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); | 336 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); |
358 | u32 new_irqs; | 337 | uint16_t new_irqs; |
359 | u32 level; | 338 | uint16_t level; |
360 | 339 | ||
361 | /* Look for any newly setup interrupt */ | 340 | /* Look for any newly setup interrupt */ |
362 | new_irqs = chip->irq_trig_fall | chip->irq_trig_raise; | 341 | new_irqs = chip->irq_trig_fall | chip->irq_trig_raise; |
@@ -374,7 +353,8 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) | |||
374 | static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) | 353 | static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) |
375 | { | 354 | { |
376 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); | 355 | struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); |
377 | u32 mask = 1 << d->hwirq; | 356 | uint16_t level = d->irq - chip->irq_base; |
357 | uint16_t mask = 1 << level; | ||
378 | 358 | ||
379 | if (!(type & IRQ_TYPE_EDGE_BOTH)) { | 359 | if (!(type & IRQ_TYPE_EDGE_BOTH)) { |
380 | dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", | 360 | dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", |
@@ -404,12 +384,12 @@ static struct irq_chip pca953x_irq_chip = { | |||
404 | .irq_set_type = pca953x_irq_set_type, | 384 | .irq_set_type = pca953x_irq_set_type, |
405 | }; | 385 | }; |
406 | 386 | ||
407 | static u32 pca953x_irq_pending(struct pca953x_chip *chip) | 387 | static uint16_t pca953x_irq_pending(struct pca953x_chip *chip) |
408 | { | 388 | { |
409 | u32 cur_stat; | 389 | uint16_t cur_stat; |
410 | u32 old_stat; | 390 | uint16_t old_stat; |
411 | u32 pending; | 391 | uint16_t pending; |
412 | u32 trigger; | 392 | uint16_t trigger; |
413 | int ret, offset = 0; | 393 | int ret, offset = 0; |
414 | 394 | ||
415 | switch (chip->chip_type) { | 395 | switch (chip->chip_type) { |
@@ -445,8 +425,8 @@ static u32 pca953x_irq_pending(struct pca953x_chip *chip) | |||
445 | static irqreturn_t pca953x_irq_handler(int irq, void *devid) | 425 | static irqreturn_t pca953x_irq_handler(int irq, void *devid) |
446 | { | 426 | { |
447 | struct pca953x_chip *chip = devid; | 427 | struct pca953x_chip *chip = devid; |
448 | u32 pending; | 428 | uint16_t pending; |
449 | u32 level; | 429 | uint16_t level; |
450 | 430 | ||
451 | pending = pca953x_irq_pending(chip); | 431 | pending = pca953x_irq_pending(chip); |
452 | 432 | ||
@@ -455,7 +435,7 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid) | |||
455 | 435 | ||
456 | do { | 436 | do { |
457 | level = __ffs(pending); | 437 | level = __ffs(pending); |
458 | handle_nested_irq(irq_find_mapping(chip->domain, level)); | 438 | handle_nested_irq(level + chip->irq_base); |
459 | 439 | ||
460 | pending &= ~(1 << level); | 440 | pending &= ~(1 << level); |
461 | } while (pending); | 441 | } while (pending); |
@@ -469,7 +449,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
469 | { | 449 | { |
470 | struct i2c_client *client = chip->client; | 450 | struct i2c_client *client = chip->client; |
471 | int ret, offset = 0; | 451 | int ret, offset = 0; |
472 | u32 temporary; | ||
473 | 452 | ||
474 | if (irq_base != -1 | 453 | if (irq_base != -1 |
475 | && (id->driver_data & PCA_INT)) { | 454 | && (id->driver_data & PCA_INT)) { |
@@ -483,8 +462,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
483 | offset = PCA957X_IN; | 462 | offset = PCA957X_IN; |
484 | break; | 463 | break; |
485 | } | 464 | } |
486 | ret = pca953x_read_reg(chip, offset, &temporary); | 465 | ret = pca953x_read_reg(chip, offset, &chip->irq_stat); |
487 | chip->irq_stat = temporary; | ||
488 | if (ret) | 466 | if (ret) |
489 | goto out_failed; | 467 | goto out_failed; |
490 | 468 | ||
@@ -500,17 +478,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
500 | if (chip->irq_base < 0) | 478 | if (chip->irq_base < 0) |
501 | goto out_failed; | 479 | goto out_failed; |
502 | 480 | ||
503 | chip->domain = irq_domain_add_legacy(client->dev.of_node, | ||
504 | chip->gpio_chip.ngpio, | ||
505 | chip->irq_base, | ||
506 | 0, | ||
507 | &irq_domain_simple_ops, | ||
508 | NULL); | ||
509 | if (!chip->domain) { | ||
510 | ret = -ENODEV; | ||
511 | goto out_irqdesc_free; | ||
512 | } | ||
513 | |||
514 | for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) { | 481 | for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) { |
515 | int irq = lvl + chip->irq_base; | 482 | int irq = lvl + chip->irq_base; |
516 | 483 | ||
@@ -533,7 +500,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
533 | if (ret) { | 500 | if (ret) { |
534 | dev_err(&client->dev, "failed to request irq %d\n", | 501 | dev_err(&client->dev, "failed to request irq %d\n", |
535 | client->irq); | 502 | client->irq); |
536 | goto out_irqdesc_free; | 503 | goto out_failed; |
537 | } | 504 | } |
538 | 505 | ||
539 | chip->gpio_chip.to_irq = pca953x_gpio_to_irq; | 506 | chip->gpio_chip.to_irq = pca953x_gpio_to_irq; |
@@ -541,8 +508,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
541 | 508 | ||
542 | return 0; | 509 | return 0; |
543 | 510 | ||
544 | out_irqdesc_free: | ||
545 | irq_free_descs(chip->irq_base, chip->gpio_chip.ngpio); | ||
546 | out_failed: | 511 | out_failed: |
547 | chip->irq_base = -1; | 512 | chip->irq_base = -1; |
548 | return ret; | 513 | return ret; |
@@ -581,8 +546,8 @@ static void pca953x_irq_teardown(struct pca953x_chip *chip) | |||
581 | * Translate OpenFirmware node properties into platform_data | 546 | * Translate OpenFirmware node properties into platform_data |
582 | * WARNING: This is DEPRECATED and will be removed eventually! | 547 | * WARNING: This is DEPRECATED and will be removed eventually! |
583 | */ | 548 | */ |
584 | static void | 549 | void |
585 | pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, u32 *invert) | 550 | pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert) |
586 | { | 551 | { |
587 | struct device_node *node; | 552 | struct device_node *node; |
588 | const __be32 *val; | 553 | const __be32 *val; |
@@ -609,14 +574,14 @@ pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, u32 *invert) | |||
609 | *invert = *val; | 574 | *invert = *val; |
610 | } | 575 | } |
611 | #else | 576 | #else |
612 | static void | 577 | void |
613 | pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, u32 *invert) | 578 | pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert) |
614 | { | 579 | { |
615 | *gpio_base = -1; | 580 | *gpio_base = -1; |
616 | } | 581 | } |
617 | #endif | 582 | #endif |
618 | 583 | ||
619 | static int device_pca953x_init(struct pca953x_chip *chip, u32 invert) | 584 | static int __devinit device_pca953x_init(struct pca953x_chip *chip, int invert) |
620 | { | 585 | { |
621 | int ret; | 586 | int ret; |
622 | 587 | ||
@@ -631,14 +596,17 @@ static int device_pca953x_init(struct pca953x_chip *chip, u32 invert) | |||
631 | 596 | ||
632 | /* set platform specific polarity inversion */ | 597 | /* set platform specific polarity inversion */ |
633 | ret = pca953x_write_reg(chip, PCA953X_INVERT, invert); | 598 | ret = pca953x_write_reg(chip, PCA953X_INVERT, invert); |
599 | if (ret) | ||
600 | goto out; | ||
601 | return 0; | ||
634 | out: | 602 | out: |
635 | return ret; | 603 | return ret; |
636 | } | 604 | } |
637 | 605 | ||
638 | static int device_pca957x_init(struct pca953x_chip *chip, u32 invert) | 606 | static int __devinit device_pca957x_init(struct pca953x_chip *chip, int invert) |
639 | { | 607 | { |
640 | int ret; | 608 | int ret; |
641 | u32 val = 0; | 609 | uint16_t val = 0; |
642 | 610 | ||
643 | /* Let every port in proper state, that could save power */ | 611 | /* Let every port in proper state, that could save power */ |
644 | pca953x_write_reg(chip, PCA957X_PUPD, 0x0); | 612 | pca953x_write_reg(chip, PCA957X_PUPD, 0x0); |
@@ -666,14 +634,13 @@ out: | |||
666 | return ret; | 634 | return ret; |
667 | } | 635 | } |
668 | 636 | ||
669 | static int pca953x_probe(struct i2c_client *client, | 637 | static int __devinit pca953x_probe(struct i2c_client *client, |
670 | const struct i2c_device_id *id) | 638 | const struct i2c_device_id *id) |
671 | { | 639 | { |
672 | struct pca953x_platform_data *pdata; | 640 | struct pca953x_platform_data *pdata; |
673 | struct pca953x_chip *chip; | 641 | struct pca953x_chip *chip; |
674 | int irq_base = 0; | 642 | int irq_base=0, invert=0; |
675 | int ret; | 643 | int ret = 0; |
676 | u32 invert = 0; | ||
677 | 644 | ||
678 | chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL); | 645 | chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL); |
679 | if (chip == NULL) | 646 | if (chip == NULL) |
@@ -706,10 +673,10 @@ static int pca953x_probe(struct i2c_client *client, | |||
706 | pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK); | 673 | pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK); |
707 | 674 | ||
708 | if (chip->chip_type == PCA953X_TYPE) | 675 | if (chip->chip_type == PCA953X_TYPE) |
709 | ret = device_pca953x_init(chip, invert); | 676 | device_pca953x_init(chip, invert); |
677 | else if (chip->chip_type == PCA957X_TYPE) | ||
678 | device_pca957x_init(chip, invert); | ||
710 | else | 679 | else |
711 | ret = device_pca957x_init(chip, invert); | ||
712 | if (ret) | ||
713 | goto out_failed; | 680 | goto out_failed; |
714 | 681 | ||
715 | ret = pca953x_irq_setup(chip, id, irq_base); | 682 | ret = pca953x_irq_setup(chip, id, irq_base); |
@@ -765,38 +732,9 @@ static int pca953x_remove(struct i2c_client *client) | |||
765 | return 0; | 732 | return 0; |
766 | } | 733 | } |
767 | 734 | ||
768 | static const struct of_device_id pca953x_dt_ids[] = { | ||
769 | { .compatible = "nxp,pca9534", }, | ||
770 | { .compatible = "nxp,pca9535", }, | ||
771 | { .compatible = "nxp,pca9536", }, | ||
772 | { .compatible = "nxp,pca9537", }, | ||
773 | { .compatible = "nxp,pca9538", }, | ||
774 | { .compatible = "nxp,pca9539", }, | ||
775 | { .compatible = "nxp,pca9554", }, | ||
776 | { .compatible = "nxp,pca9555", }, | ||
777 | { .compatible = "nxp,pca9556", }, | ||
778 | { .compatible = "nxp,pca9557", }, | ||
779 | { .compatible = "nxp,pca9574", }, | ||
780 | { .compatible = "nxp,pca9575", }, | ||
781 | |||
782 | { .compatible = "maxim,max7310", }, | ||
783 | { .compatible = "maxim,max7312", }, | ||
784 | { .compatible = "maxim,max7313", }, | ||
785 | { .compatible = "maxim,max7315", }, | ||
786 | |||
787 | { .compatible = "ti,pca6107", }, | ||
788 | { .compatible = "ti,tca6408", }, | ||
789 | { .compatible = "ti,tca6416", }, | ||
790 | { .compatible = "ti,tca6424", }, | ||
791 | { } | ||
792 | }; | ||
793 | |||
794 | MODULE_DEVICE_TABLE(of, pca953x_dt_ids); | ||
795 | |||
796 | static struct i2c_driver pca953x_driver = { | 735 | static struct i2c_driver pca953x_driver = { |
797 | .driver = { | 736 | .driver = { |
798 | .name = "pca953x", | 737 | .name = "pca953x", |
799 | .of_match_table = pca953x_dt_ids, | ||
800 | }, | 738 | }, |
801 | .probe = pca953x_probe, | 739 | .probe = pca953x_probe, |
802 | .remove = pca953x_remove, | 740 | .remove = pca953x_remove, |
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c index a19b7457a72..7369fdda92b 100644 --- a/drivers/gpio/gpio-pcf857x.c +++ b/drivers/gpio/gpio-pcf857x.c | |||
@@ -23,12 +23,6 @@ | |||
23 | #include <linux/gpio.h> | 23 | #include <linux/gpio.h> |
24 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
25 | #include <linux/i2c/pcf857x.h> | 25 | #include <linux/i2c/pcf857x.h> |
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/irq.h> | ||
28 | #include <linux/irqdomain.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/workqueue.h> | ||
32 | 26 | ||
33 | 27 | ||
34 | static const struct i2c_device_id pcf857x_id[] = { | 28 | static const struct i2c_device_id pcf857x_id[] = { |
@@ -65,34 +59,62 @@ struct pcf857x { | |||
65 | struct gpio_chip chip; | 59 | struct gpio_chip chip; |
66 | struct i2c_client *client; | 60 | struct i2c_client *client; |
67 | struct mutex lock; /* protect 'out' */ | 61 | struct mutex lock; /* protect 'out' */ |
68 | struct work_struct work; /* irq demux work */ | ||
69 | struct irq_domain *irq_domain; /* for irq demux */ | ||
70 | spinlock_t slock; /* protect irq demux */ | ||
71 | unsigned out; /* software latch */ | 62 | unsigned out; /* software latch */ |
72 | unsigned status; /* current status */ | ||
73 | int irq; /* real irq number */ | ||
74 | |||
75 | int (*write)(struct i2c_client *client, unsigned data); | ||
76 | int (*read)(struct i2c_client *client); | ||
77 | }; | 63 | }; |
78 | 64 | ||
79 | /*-------------------------------------------------------------------------*/ | 65 | /*-------------------------------------------------------------------------*/ |
80 | 66 | ||
81 | /* Talk to 8-bit I/O expander */ | 67 | /* Talk to 8-bit I/O expander */ |
82 | 68 | ||
83 | static int i2c_write_le8(struct i2c_client *client, unsigned data) | 69 | static int pcf857x_input8(struct gpio_chip *chip, unsigned offset) |
70 | { | ||
71 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); | ||
72 | int status; | ||
73 | |||
74 | mutex_lock(&gpio->lock); | ||
75 | gpio->out |= (1 << offset); | ||
76 | status = i2c_smbus_write_byte(gpio->client, gpio->out); | ||
77 | mutex_unlock(&gpio->lock); | ||
78 | |||
79 | return status; | ||
80 | } | ||
81 | |||
82 | static int pcf857x_get8(struct gpio_chip *chip, unsigned offset) | ||
84 | { | 83 | { |
85 | return i2c_smbus_write_byte(client, data); | 84 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); |
85 | s32 value; | ||
86 | |||
87 | value = i2c_smbus_read_byte(gpio->client); | ||
88 | return (value < 0) ? 0 : (value & (1 << offset)); | ||
89 | } | ||
90 | |||
91 | static int pcf857x_output8(struct gpio_chip *chip, unsigned offset, int value) | ||
92 | { | ||
93 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); | ||
94 | unsigned bit = 1 << offset; | ||
95 | int status; | ||
96 | |||
97 | mutex_lock(&gpio->lock); | ||
98 | if (value) | ||
99 | gpio->out |= bit; | ||
100 | else | ||
101 | gpio->out &= ~bit; | ||
102 | status = i2c_smbus_write_byte(gpio->client, gpio->out); | ||
103 | mutex_unlock(&gpio->lock); | ||
104 | |||
105 | return status; | ||
86 | } | 106 | } |
87 | 107 | ||
88 | static int i2c_read_le8(struct i2c_client *client) | 108 | static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value) |
89 | { | 109 | { |
90 | return (int)i2c_smbus_read_byte(client); | 110 | pcf857x_output8(chip, offset, value); |
91 | } | 111 | } |
92 | 112 | ||
113 | /*-------------------------------------------------------------------------*/ | ||
114 | |||
93 | /* Talk to 16-bit I/O expander */ | 115 | /* Talk to 16-bit I/O expander */ |
94 | 116 | ||
95 | static int i2c_write_le16(struct i2c_client *client, unsigned word) | 117 | static int i2c_write_le16(struct i2c_client *client, u16 word) |
96 | { | 118 | { |
97 | u8 buf[2] = { word & 0xff, word >> 8, }; | 119 | u8 buf[2] = { word & 0xff, word >> 8, }; |
98 | int status; | 120 | int status; |
@@ -112,31 +134,29 @@ static int i2c_read_le16(struct i2c_client *client) | |||
112 | return (buf[1] << 8) | buf[0]; | 134 | return (buf[1] << 8) | buf[0]; |
113 | } | 135 | } |
114 | 136 | ||
115 | /*-------------------------------------------------------------------------*/ | 137 | static int pcf857x_input16(struct gpio_chip *chip, unsigned offset) |
116 | |||
117 | static int pcf857x_input(struct gpio_chip *chip, unsigned offset) | ||
118 | { | 138 | { |
119 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); | 139 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); |
120 | int status; | 140 | int status; |
121 | 141 | ||
122 | mutex_lock(&gpio->lock); | 142 | mutex_lock(&gpio->lock); |
123 | gpio->out |= (1 << offset); | 143 | gpio->out |= (1 << offset); |
124 | status = gpio->write(gpio->client, gpio->out); | 144 | status = i2c_write_le16(gpio->client, gpio->out); |
125 | mutex_unlock(&gpio->lock); | 145 | mutex_unlock(&gpio->lock); |
126 | 146 | ||
127 | return status; | 147 | return status; |
128 | } | 148 | } |
129 | 149 | ||
130 | static int pcf857x_get(struct gpio_chip *chip, unsigned offset) | 150 | static int pcf857x_get16(struct gpio_chip *chip, unsigned offset) |
131 | { | 151 | { |
132 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); | 152 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); |
133 | int value; | 153 | int value; |
134 | 154 | ||
135 | value = gpio->read(gpio->client); | 155 | value = i2c_read_le16(gpio->client); |
136 | return (value < 0) ? 0 : (value & (1 << offset)); | 156 | return (value < 0) ? 0 : (value & (1 << offset)); |
137 | } | 157 | } |
138 | 158 | ||
139 | static int pcf857x_output(struct gpio_chip *chip, unsigned offset, int value) | 159 | static int pcf857x_output16(struct gpio_chip *chip, unsigned offset, int value) |
140 | { | 160 | { |
141 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); | 161 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); |
142 | unsigned bit = 1 << offset; | 162 | unsigned bit = 1 << offset; |
@@ -147,109 +167,15 @@ static int pcf857x_output(struct gpio_chip *chip, unsigned offset, int value) | |||
147 | gpio->out |= bit; | 167 | gpio->out |= bit; |
148 | else | 168 | else |
149 | gpio->out &= ~bit; | 169 | gpio->out &= ~bit; |
150 | status = gpio->write(gpio->client, gpio->out); | 170 | status = i2c_write_le16(gpio->client, gpio->out); |
151 | mutex_unlock(&gpio->lock); | 171 | mutex_unlock(&gpio->lock); |
152 | 172 | ||
153 | return status; | 173 | return status; |
154 | } | 174 | } |
155 | 175 | ||
156 | static void pcf857x_set(struct gpio_chip *chip, unsigned offset, int value) | 176 | static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value) |
157 | { | 177 | { |
158 | pcf857x_output(chip, offset, value); | 178 | pcf857x_output16(chip, offset, value); |
159 | } | ||
160 | |||
161 | /*-------------------------------------------------------------------------*/ | ||
162 | |||
163 | static int pcf857x_to_irq(struct gpio_chip *chip, unsigned offset) | ||
164 | { | ||
165 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); | ||
166 | |||
167 | return irq_create_mapping(gpio->irq_domain, offset); | ||
168 | } | ||
169 | |||
170 | static void pcf857x_irq_demux_work(struct work_struct *work) | ||
171 | { | ||
172 | struct pcf857x *gpio = container_of(work, | ||
173 | struct pcf857x, | ||
174 | work); | ||
175 | unsigned long change, i, status, flags; | ||
176 | |||
177 | status = gpio->read(gpio->client); | ||
178 | |||
179 | spin_lock_irqsave(&gpio->slock, flags); | ||
180 | |||
181 | change = gpio->status ^ status; | ||
182 | for_each_set_bit(i, &change, gpio->chip.ngpio) | ||
183 | generic_handle_irq(irq_find_mapping(gpio->irq_domain, i)); | ||
184 | gpio->status = status; | ||
185 | |||
186 | spin_unlock_irqrestore(&gpio->slock, flags); | ||
187 | } | ||
188 | |||
189 | static irqreturn_t pcf857x_irq_demux(int irq, void *data) | ||
190 | { | ||
191 | struct pcf857x *gpio = data; | ||
192 | |||
193 | /* | ||
194 | * pcf857x can't read/write data here, | ||
195 | * since i2c data access might go to sleep. | ||
196 | */ | ||
197 | schedule_work(&gpio->work); | ||
198 | |||
199 | return IRQ_HANDLED; | ||
200 | } | ||
201 | |||
202 | static int pcf857x_irq_domain_map(struct irq_domain *domain, unsigned int virq, | ||
203 | irq_hw_number_t hw) | ||
204 | { | ||
205 | irq_set_chip_and_handler(virq, | ||
206 | &dummy_irq_chip, | ||
207 | handle_level_irq); | ||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static struct irq_domain_ops pcf857x_irq_domain_ops = { | ||
212 | .map = pcf857x_irq_domain_map, | ||
213 | }; | ||
214 | |||
215 | static void pcf857x_irq_domain_cleanup(struct pcf857x *gpio) | ||
216 | { | ||
217 | if (gpio->irq_domain) | ||
218 | irq_domain_remove(gpio->irq_domain); | ||
219 | |||
220 | if (gpio->irq) | ||
221 | free_irq(gpio->irq, gpio); | ||
222 | } | ||
223 | |||
224 | static int pcf857x_irq_domain_init(struct pcf857x *gpio, | ||
225 | struct pcf857x_platform_data *pdata, | ||
226 | struct i2c_client *client) | ||
227 | { | ||
228 | int status; | ||
229 | |||
230 | gpio->irq_domain = irq_domain_add_linear(client->dev.of_node, | ||
231 | gpio->chip.ngpio, | ||
232 | &pcf857x_irq_domain_ops, | ||
233 | NULL); | ||
234 | if (!gpio->irq_domain) | ||
235 | goto fail; | ||
236 | |||
237 | /* enable real irq */ | ||
238 | status = request_irq(client->irq, pcf857x_irq_demux, 0, | ||
239 | dev_name(&client->dev), gpio); | ||
240 | if (status) | ||
241 | goto fail; | ||
242 | |||
243 | /* enable gpio_to_irq() */ | ||
244 | INIT_WORK(&gpio->work, pcf857x_irq_demux_work); | ||
245 | gpio->chip.to_irq = pcf857x_to_irq; | ||
246 | gpio->irq = client->irq; | ||
247 | |||
248 | return 0; | ||
249 | |||
250 | fail: | ||
251 | pcf857x_irq_domain_cleanup(gpio); | ||
252 | return -EINVAL; | ||
253 | } | 179 | } |
254 | 180 | ||
255 | /*-------------------------------------------------------------------------*/ | 181 | /*-------------------------------------------------------------------------*/ |
@@ -272,26 +198,11 @@ static int pcf857x_probe(struct i2c_client *client, | |||
272 | return -ENOMEM; | 198 | return -ENOMEM; |
273 | 199 | ||
274 | mutex_init(&gpio->lock); | 200 | mutex_init(&gpio->lock); |
275 | spin_lock_init(&gpio->slock); | 201 | |
276 | 202 | gpio->chip.base = pdata ? pdata->gpio_base : -1; | |
277 | gpio->chip.base = pdata ? pdata->gpio_base : -1; | 203 | gpio->chip.can_sleep = 1; |
278 | gpio->chip.can_sleep = 1; | 204 | gpio->chip.dev = &client->dev; |
279 | gpio->chip.dev = &client->dev; | 205 | gpio->chip.owner = THIS_MODULE; |
280 | gpio->chip.owner = THIS_MODULE; | ||
281 | gpio->chip.get = pcf857x_get; | ||
282 | gpio->chip.set = pcf857x_set; | ||
283 | gpio->chip.direction_input = pcf857x_input; | ||
284 | gpio->chip.direction_output = pcf857x_output; | ||
285 | gpio->chip.ngpio = id->driver_data; | ||
286 | |||
287 | /* enable gpio_to_irq() if platform has settings */ | ||
288 | if (pdata && client->irq) { | ||
289 | status = pcf857x_irq_domain_init(gpio, pdata, client); | ||
290 | if (status < 0) { | ||
291 | dev_err(&client->dev, "irq_domain init failed\n"); | ||
292 | goto fail; | ||
293 | } | ||
294 | } | ||
295 | 206 | ||
296 | /* NOTE: the OnSemi jlc1562b is also largely compatible with | 207 | /* NOTE: the OnSemi jlc1562b is also largely compatible with |
297 | * these parts, notably for output. It has a low-resolution | 208 | * these parts, notably for output. It has a low-resolution |
@@ -304,9 +215,12 @@ static int pcf857x_probe(struct i2c_client *client, | |||
304 | * | 215 | * |
305 | * NOTE: we don't distinguish here between *4 and *4a parts. | 216 | * NOTE: we don't distinguish here between *4 and *4a parts. |
306 | */ | 217 | */ |
218 | gpio->chip.ngpio = id->driver_data; | ||
307 | if (gpio->chip.ngpio == 8) { | 219 | if (gpio->chip.ngpio == 8) { |
308 | gpio->write = i2c_write_le8; | 220 | gpio->chip.direction_input = pcf857x_input8; |
309 | gpio->read = i2c_read_le8; | 221 | gpio->chip.get = pcf857x_get8; |
222 | gpio->chip.direction_output = pcf857x_output8; | ||
223 | gpio->chip.set = pcf857x_set8; | ||
310 | 224 | ||
311 | if (!i2c_check_functionality(client->adapter, | 225 | if (!i2c_check_functionality(client->adapter, |
312 | I2C_FUNC_SMBUS_BYTE)) | 226 | I2C_FUNC_SMBUS_BYTE)) |
@@ -323,8 +237,10 @@ static int pcf857x_probe(struct i2c_client *client, | |||
323 | * NOTE: we don't distinguish here between '75 and '75c parts. | 237 | * NOTE: we don't distinguish here between '75 and '75c parts. |
324 | */ | 238 | */ |
325 | } else if (gpio->chip.ngpio == 16) { | 239 | } else if (gpio->chip.ngpio == 16) { |
326 | gpio->write = i2c_write_le16; | 240 | gpio->chip.direction_input = pcf857x_input16; |
327 | gpio->read = i2c_read_le16; | 241 | gpio->chip.get = pcf857x_get16; |
242 | gpio->chip.direction_output = pcf857x_output16; | ||
243 | gpio->chip.set = pcf857x_set16; | ||
328 | 244 | ||
329 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) | 245 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) |
330 | status = -EIO; | 246 | status = -EIO; |
@@ -362,12 +278,23 @@ static int pcf857x_probe(struct i2c_client *client, | |||
362 | * all-ones reset state. Otherwise it flags pins to be driven low. | 278 | * all-ones reset state. Otherwise it flags pins to be driven low. |
363 | */ | 279 | */ |
364 | gpio->out = pdata ? ~pdata->n_latch : ~0; | 280 | gpio->out = pdata ? ~pdata->n_latch : ~0; |
365 | gpio->status = gpio->out; | ||
366 | 281 | ||
367 | status = gpiochip_add(&gpio->chip); | 282 | status = gpiochip_add(&gpio->chip); |
368 | if (status < 0) | 283 | if (status < 0) |
369 | goto fail; | 284 | goto fail; |
370 | 285 | ||
286 | /* NOTE: these chips can issue "some pin-changed" IRQs, which we | ||
287 | * don't yet even try to use. Among other issues, the relevant | ||
288 | * genirq state isn't available to modular drivers; and most irq | ||
289 | * methods can't be called from sleeping contexts. | ||
290 | */ | ||
291 | |||
292 | dev_info(&client->dev, "gpios %d..%d on a %s%s\n", | ||
293 | gpio->chip.base, | ||
294 | gpio->chip.base + gpio->chip.ngpio - 1, | ||
295 | client->name, | ||
296 | client->irq ? " (irq ignored)" : ""); | ||
297 | |||
371 | /* Let platform code set up the GPIOs and their users. | 298 | /* Let platform code set up the GPIOs and their users. |
372 | * Now is the first time anyone could use them. | 299 | * Now is the first time anyone could use them. |
373 | */ | 300 | */ |
@@ -379,17 +306,11 @@ static int pcf857x_probe(struct i2c_client *client, | |||
379 | dev_warn(&client->dev, "setup --> %d\n", status); | 306 | dev_warn(&client->dev, "setup --> %d\n", status); |
380 | } | 307 | } |
381 | 308 | ||
382 | dev_info(&client->dev, "probed\n"); | ||
383 | |||
384 | return 0; | 309 | return 0; |
385 | 310 | ||
386 | fail: | 311 | fail: |
387 | dev_dbg(&client->dev, "probe error %d for '%s'\n", | 312 | dev_dbg(&client->dev, "probe error %d for '%s'\n", |
388 | status, client->name); | 313 | status, client->name); |
389 | |||
390 | if (pdata && client->irq) | ||
391 | pcf857x_irq_domain_cleanup(gpio); | ||
392 | |||
393 | kfree(gpio); | 314 | kfree(gpio); |
394 | return status; | 315 | return status; |
395 | } | 316 | } |
@@ -411,9 +332,6 @@ static int pcf857x_remove(struct i2c_client *client) | |||
411 | } | 332 | } |
412 | } | 333 | } |
413 | 334 | ||
414 | if (pdata && client->irq) | ||
415 | pcf857x_irq_domain_cleanup(gpio); | ||
416 | |||
417 | status = gpiochip_remove(&gpio->chip); | 335 | status = gpiochip_remove(&gpio->chip); |
418 | if (status == 0) | 336 | if (status == 0) |
419 | kfree(gpio); | 337 | kfree(gpio); |
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c index cdf599687cf..36919e77c49 100644 --- a/drivers/gpio/gpio-pch.c +++ b/drivers/gpio/gpio-pch.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. | 2 | * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
@@ -14,21 +14,12 @@ | |||
14 | * along with this program; if not, write to the Free Software | 14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
16 | */ | 16 | */ |
17 | #include <linux/module.h> | ||
18 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
19 | #include <linux/pci.h> | 18 | #include <linux/pci.h> |
20 | #include <linux/gpio.h> | 19 | #include <linux/gpio.h> |
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/irq.h> | ||
23 | 20 | ||
24 | #define PCH_EDGE_FALLING 0 | 21 | #define PCH_GPIO_ALL_PINS 0xfff /* Mask for GPIO pins 0 to 11 */ |
25 | #define PCH_EDGE_RISING BIT(0) | 22 | #define GPIO_NUM_PINS 12 /* Specifies number of GPIO PINS GPIO0-GPIO11 */ |
26 | #define PCH_LEVEL_L BIT(1) | ||
27 | #define PCH_LEVEL_H (BIT(0) | BIT(1)) | ||
28 | #define PCH_EDGE_BOTH BIT(2) | ||
29 | #define PCH_IM_MASK (BIT(0) | BIT(1) | BIT(2)) | ||
30 | |||
31 | #define PCH_IRQ_BASE 24 | ||
32 | 23 | ||
33 | struct pch_regs { | 24 | struct pch_regs { |
34 | u32 ien; | 25 | u32 ien; |
@@ -42,43 +33,18 @@ struct pch_regs { | |||
42 | u32 pm; | 33 | u32 pm; |
43 | u32 im0; | 34 | u32 im0; |
44 | u32 im1; | 35 | u32 im1; |
45 | u32 reserved[3]; | 36 | u32 reserved[4]; |
46 | u32 gpio_use_sel; | ||
47 | u32 reset; | 37 | u32 reset; |
48 | }; | 38 | }; |
49 | 39 | ||
50 | enum pch_type_t { | ||
51 | INTEL_EG20T_PCH, | ||
52 | OKISEMI_ML7223m_IOH, /* LAPIS Semiconductor ML7223 IOH PCIe Bus-m */ | ||
53 | OKISEMI_ML7223n_IOH /* LAPIS Semiconductor ML7223 IOH PCIe Bus-n */ | ||
54 | }; | ||
55 | |||
56 | /* Specifies number of GPIO PINS */ | ||
57 | static int gpio_pins[] = { | ||
58 | [INTEL_EG20T_PCH] = 12, | ||
59 | [OKISEMI_ML7223m_IOH] = 8, | ||
60 | [OKISEMI_ML7223n_IOH] = 8, | ||
61 | }; | ||
62 | |||
63 | /** | 40 | /** |
64 | * struct pch_gpio_reg_data - The register store data. | 41 | * struct pch_gpio_reg_data - The register store data. |
65 | * @ien_reg: To store contents of IEN register. | ||
66 | * @imask_reg: To store contents of IMASK register. | ||
67 | * @po_reg: To store contents of PO register. | 42 | * @po_reg: To store contents of PO register. |
68 | * @pm_reg: To store contents of PM register. | 43 | * @pm_reg: To store contents of PM register. |
69 | * @im0_reg: To store contents of IM0 register. | ||
70 | * @im1_reg: To store contents of IM1 register. | ||
71 | * @gpio_use_sel_reg : To store contents of GPIO_USE_SEL register. | ||
72 | * (Only ML7223 Bus-n) | ||
73 | */ | 44 | */ |
74 | struct pch_gpio_reg_data { | 45 | struct pch_gpio_reg_data { |
75 | u32 ien_reg; | ||
76 | u32 imask_reg; | ||
77 | u32 po_reg; | 46 | u32 po_reg; |
78 | u32 pm_reg; | 47 | u32 pm_reg; |
79 | u32 im0_reg; | ||
80 | u32 im1_reg; | ||
81 | u32 gpio_use_sel_reg; | ||
82 | }; | 48 | }; |
83 | 49 | ||
84 | /** | 50 | /** |
@@ -89,10 +55,6 @@ struct pch_gpio_reg_data { | |||
89 | * @gpio: Data for GPIO infrastructure. | 55 | * @gpio: Data for GPIO infrastructure. |
90 | * @pch_gpio_reg: Memory mapped Register data is saved here | 56 | * @pch_gpio_reg: Memory mapped Register data is saved here |
91 | * when suspend. | 57 | * when suspend. |
92 | * @lock: Used for register access protection | ||
93 | * @irq_base: Save base of IRQ number for interrupt | ||
94 | * @ioh: IOH ID | ||
95 | * @spinlock: Used for register access protection | ||
96 | */ | 58 | */ |
97 | struct pch_gpio { | 59 | struct pch_gpio { |
98 | void __iomem *base; | 60 | void __iomem *base; |
@@ -100,18 +62,15 @@ struct pch_gpio { | |||
100 | struct device *dev; | 62 | struct device *dev; |
101 | struct gpio_chip gpio; | 63 | struct gpio_chip gpio; |
102 | struct pch_gpio_reg_data pch_gpio_reg; | 64 | struct pch_gpio_reg_data pch_gpio_reg; |
103 | int irq_base; | 65 | struct mutex lock; |
104 | enum pch_type_t ioh; | ||
105 | spinlock_t spinlock; | ||
106 | }; | 66 | }; |
107 | 67 | ||
108 | static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | 68 | static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) |
109 | { | 69 | { |
110 | u32 reg_val; | 70 | u32 reg_val; |
111 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); | 71 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); |
112 | unsigned long flags; | ||
113 | 72 | ||
114 | spin_lock_irqsave(&chip->spinlock, flags); | 73 | mutex_lock(&chip->lock); |
115 | reg_val = ioread32(&chip->reg->po); | 74 | reg_val = ioread32(&chip->reg->po); |
116 | if (val) | 75 | if (val) |
117 | reg_val |= (1 << nr); | 76 | reg_val |= (1 << nr); |
@@ -119,7 +78,7 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
119 | reg_val &= ~(1 << nr); | 78 | reg_val &= ~(1 << nr); |
120 | 79 | ||
121 | iowrite32(reg_val, &chip->reg->po); | 80 | iowrite32(reg_val, &chip->reg->po); |
122 | spin_unlock_irqrestore(&chip->spinlock, flags); | 81 | mutex_unlock(&chip->lock); |
123 | } | 82 | } |
124 | 83 | ||
125 | static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr) | 84 | static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr) |
@@ -135,10 +94,9 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
135 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); | 94 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); |
136 | u32 pm; | 95 | u32 pm; |
137 | u32 reg_val; | 96 | u32 reg_val; |
138 | unsigned long flags; | ||
139 | 97 | ||
140 | spin_lock_irqsave(&chip->spinlock, flags); | 98 | mutex_lock(&chip->lock); |
141 | pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); | 99 | pm = ioread32(&chip->reg->pm) & PCH_GPIO_ALL_PINS; |
142 | pm |= (1 << nr); | 100 | pm |= (1 << nr); |
143 | iowrite32(pm, &chip->reg->pm); | 101 | iowrite32(pm, &chip->reg->pm); |
144 | 102 | ||
@@ -148,7 +106,8 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
148 | else | 106 | else |
149 | reg_val &= ~(1 << nr); | 107 | reg_val &= ~(1 << nr); |
150 | iowrite32(reg_val, &chip->reg->po); | 108 | iowrite32(reg_val, &chip->reg->po); |
151 | spin_unlock_irqrestore(&chip->spinlock, flags); | 109 | |
110 | mutex_unlock(&chip->lock); | ||
152 | 111 | ||
153 | return 0; | 112 | return 0; |
154 | } | 113 | } |
@@ -157,13 +116,12 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
157 | { | 116 | { |
158 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); | 117 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); |
159 | u32 pm; | 118 | u32 pm; |
160 | unsigned long flags; | ||
161 | 119 | ||
162 | spin_lock_irqsave(&chip->spinlock, flags); | 120 | mutex_lock(&chip->lock); |
163 | pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); | 121 | pm = ioread32(&chip->reg->pm) & PCH_GPIO_ALL_PINS; /*bits 0-11*/ |
164 | pm &= ~(1 << nr); | 122 | pm &= ~(1 << nr); |
165 | iowrite32(pm, &chip->reg->pm); | 123 | iowrite32(pm, &chip->reg->pm); |
166 | spin_unlock_irqrestore(&chip->spinlock, flags); | 124 | mutex_unlock(&chip->lock); |
167 | 125 | ||
168 | return 0; | 126 | return 0; |
169 | } | 127 | } |
@@ -173,16 +131,8 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
173 | */ | 131 | */ |
174 | static void pch_gpio_save_reg_conf(struct pch_gpio *chip) | 132 | static void pch_gpio_save_reg_conf(struct pch_gpio *chip) |
175 | { | 133 | { |
176 | chip->pch_gpio_reg.ien_reg = ioread32(&chip->reg->ien); | ||
177 | chip->pch_gpio_reg.imask_reg = ioread32(&chip->reg->imask); | ||
178 | chip->pch_gpio_reg.po_reg = ioread32(&chip->reg->po); | 134 | chip->pch_gpio_reg.po_reg = ioread32(&chip->reg->po); |
179 | chip->pch_gpio_reg.pm_reg = ioread32(&chip->reg->pm); | 135 | chip->pch_gpio_reg.pm_reg = ioread32(&chip->reg->pm); |
180 | chip->pch_gpio_reg.im0_reg = ioread32(&chip->reg->im0); | ||
181 | if (chip->ioh == INTEL_EG20T_PCH) | ||
182 | chip->pch_gpio_reg.im1_reg = ioread32(&chip->reg->im1); | ||
183 | if (chip->ioh == OKISEMI_ML7223n_IOH) | ||
184 | chip->pch_gpio_reg.gpio_use_sel_reg =\ | ||
185 | ioread32(&chip->reg->gpio_use_sel); | ||
186 | } | 136 | } |
187 | 137 | ||
188 | /* | 138 | /* |
@@ -190,24 +140,10 @@ static void pch_gpio_save_reg_conf(struct pch_gpio *chip) | |||
190 | */ | 140 | */ |
191 | static void pch_gpio_restore_reg_conf(struct pch_gpio *chip) | 141 | static void pch_gpio_restore_reg_conf(struct pch_gpio *chip) |
192 | { | 142 | { |
193 | iowrite32(chip->pch_gpio_reg.ien_reg, &chip->reg->ien); | ||
194 | iowrite32(chip->pch_gpio_reg.imask_reg, &chip->reg->imask); | ||
195 | /* to store contents of PO register */ | 143 | /* to store contents of PO register */ |
196 | iowrite32(chip->pch_gpio_reg.po_reg, &chip->reg->po); | 144 | iowrite32(chip->pch_gpio_reg.po_reg, &chip->reg->po); |
197 | /* to store contents of PM register */ | 145 | /* to store contents of PM register */ |
198 | iowrite32(chip->pch_gpio_reg.pm_reg, &chip->reg->pm); | 146 | iowrite32(chip->pch_gpio_reg.pm_reg, &chip->reg->pm); |
199 | iowrite32(chip->pch_gpio_reg.im0_reg, &chip->reg->im0); | ||
200 | if (chip->ioh == INTEL_EG20T_PCH) | ||
201 | iowrite32(chip->pch_gpio_reg.im1_reg, &chip->reg->im1); | ||
202 | if (chip->ioh == OKISEMI_ML7223n_IOH) | ||
203 | iowrite32(chip->pch_gpio_reg.gpio_use_sel_reg, | ||
204 | &chip->reg->gpio_use_sel); | ||
205 | } | ||
206 | |||
207 | static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) | ||
208 | { | ||
209 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); | ||
210 | return chip->irq_base + offset; | ||
211 | } | 147 | } |
212 | 148 | ||
213 | static void pch_gpio_setup(struct pch_gpio *chip) | 149 | static void pch_gpio_setup(struct pch_gpio *chip) |
@@ -215,7 +151,6 @@ static void pch_gpio_setup(struct pch_gpio *chip) | |||
215 | struct gpio_chip *gpio = &chip->gpio; | 151 | struct gpio_chip *gpio = &chip->gpio; |
216 | 152 | ||
217 | gpio->label = dev_name(chip->dev); | 153 | gpio->label = dev_name(chip->dev); |
218 | gpio->dev = chip->dev; | ||
219 | gpio->owner = THIS_MODULE; | 154 | gpio->owner = THIS_MODULE; |
220 | gpio->direction_input = pch_gpio_direction_input; | 155 | gpio->direction_input = pch_gpio_direction_input; |
221 | gpio->get = pch_gpio_get; | 156 | gpio->get = pch_gpio_get; |
@@ -223,136 +158,15 @@ static void pch_gpio_setup(struct pch_gpio *chip) | |||
223 | gpio->set = pch_gpio_set; | 158 | gpio->set = pch_gpio_set; |
224 | gpio->dbg_show = NULL; | 159 | gpio->dbg_show = NULL; |
225 | gpio->base = -1; | 160 | gpio->base = -1; |
226 | gpio->ngpio = gpio_pins[chip->ioh]; | 161 | gpio->ngpio = GPIO_NUM_PINS; |
227 | gpio->can_sleep = 0; | 162 | gpio->can_sleep = 0; |
228 | gpio->to_irq = pch_gpio_to_irq; | ||
229 | } | ||
230 | |||
231 | static int pch_irq_type(struct irq_data *d, unsigned int type) | ||
232 | { | ||
233 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
234 | struct pch_gpio *chip = gc->private; | ||
235 | u32 im, im_pos, val; | ||
236 | u32 __iomem *im_reg; | ||
237 | unsigned long flags; | ||
238 | int ch, irq = d->irq; | ||
239 | |||
240 | ch = irq - chip->irq_base; | ||
241 | if (irq <= chip->irq_base + 7) { | ||
242 | im_reg = &chip->reg->im0; | ||
243 | im_pos = ch; | ||
244 | } else { | ||
245 | im_reg = &chip->reg->im1; | ||
246 | im_pos = ch - 8; | ||
247 | } | ||
248 | dev_dbg(chip->dev, "%s:irq=%d type=%d ch=%d pos=%d\n", | ||
249 | __func__, irq, type, ch, im_pos); | ||
250 | |||
251 | spin_lock_irqsave(&chip->spinlock, flags); | ||
252 | |||
253 | switch (type) { | ||
254 | case IRQ_TYPE_EDGE_RISING: | ||
255 | val = PCH_EDGE_RISING; | ||
256 | break; | ||
257 | case IRQ_TYPE_EDGE_FALLING: | ||
258 | val = PCH_EDGE_FALLING; | ||
259 | break; | ||
260 | case IRQ_TYPE_EDGE_BOTH: | ||
261 | val = PCH_EDGE_BOTH; | ||
262 | break; | ||
263 | case IRQ_TYPE_LEVEL_HIGH: | ||
264 | val = PCH_LEVEL_H; | ||
265 | break; | ||
266 | case IRQ_TYPE_LEVEL_LOW: | ||
267 | val = PCH_LEVEL_L; | ||
268 | break; | ||
269 | default: | ||
270 | goto unlock; | ||
271 | } | ||
272 | |||
273 | /* Set interrupt mode */ | ||
274 | im = ioread32(im_reg) & ~(PCH_IM_MASK << (im_pos * 4)); | ||
275 | iowrite32(im | (val << (im_pos * 4)), im_reg); | ||
276 | |||
277 | /* And the handler */ | ||
278 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) | ||
279 | __irq_set_handler_locked(d->irq, handle_level_irq); | ||
280 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) | ||
281 | __irq_set_handler_locked(d->irq, handle_edge_irq); | ||
282 | |||
283 | unlock: | ||
284 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | static void pch_irq_unmask(struct irq_data *d) | ||
289 | { | ||
290 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
291 | struct pch_gpio *chip = gc->private; | ||
292 | |||
293 | iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imaskclr); | ||
294 | } | ||
295 | |||
296 | static void pch_irq_mask(struct irq_data *d) | ||
297 | { | ||
298 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
299 | struct pch_gpio *chip = gc->private; | ||
300 | |||
301 | iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->imask); | ||
302 | } | ||
303 | |||
304 | static void pch_irq_ack(struct irq_data *d) | ||
305 | { | ||
306 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
307 | struct pch_gpio *chip = gc->private; | ||
308 | |||
309 | iowrite32(1 << (d->irq - chip->irq_base), &chip->reg->iclr); | ||
310 | } | ||
311 | |||
312 | static irqreturn_t pch_gpio_handler(int irq, void *dev_id) | ||
313 | { | ||
314 | struct pch_gpio *chip = dev_id; | ||
315 | u32 reg_val = ioread32(&chip->reg->istatus); | ||
316 | int i, ret = IRQ_NONE; | ||
317 | |||
318 | for (i = 0; i < gpio_pins[chip->ioh]; i++) { | ||
319 | if (reg_val & BIT(i)) { | ||
320 | dev_dbg(chip->dev, "%s:[%d]:irq=%d status=0x%x\n", | ||
321 | __func__, i, irq, reg_val); | ||
322 | generic_handle_irq(chip->irq_base + i); | ||
323 | ret = IRQ_HANDLED; | ||
324 | } | ||
325 | } | ||
326 | return ret; | ||
327 | } | 163 | } |
328 | 164 | ||
329 | static void pch_gpio_alloc_generic_chip(struct pch_gpio *chip, | 165 | static int __devinit pch_gpio_probe(struct pci_dev *pdev, |
330 | unsigned int irq_start, unsigned int num) | ||
331 | { | ||
332 | struct irq_chip_generic *gc; | ||
333 | struct irq_chip_type *ct; | ||
334 | |||
335 | gc = irq_alloc_generic_chip("pch_gpio", 1, irq_start, chip->base, | ||
336 | handle_simple_irq); | ||
337 | gc->private = chip; | ||
338 | ct = gc->chip_types; | ||
339 | |||
340 | ct->chip.irq_ack = pch_irq_ack; | ||
341 | ct->chip.irq_mask = pch_irq_mask; | ||
342 | ct->chip.irq_unmask = pch_irq_unmask; | ||
343 | ct->chip.irq_set_type = pch_irq_type; | ||
344 | |||
345 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, | ||
346 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); | ||
347 | } | ||
348 | |||
349 | static int pch_gpio_probe(struct pci_dev *pdev, | ||
350 | const struct pci_device_id *id) | 166 | const struct pci_device_id *id) |
351 | { | 167 | { |
352 | s32 ret; | 168 | s32 ret; |
353 | struct pch_gpio *chip; | 169 | struct pch_gpio *chip; |
354 | int irq_base; | ||
355 | u32 msk; | ||
356 | 170 | ||
357 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 171 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
358 | if (chip == NULL) | 172 | if (chip == NULL) |
@@ -372,22 +186,15 @@ static int pch_gpio_probe(struct pci_dev *pdev, | |||
372 | } | 186 | } |
373 | 187 | ||
374 | chip->base = pci_iomap(pdev, 1, 0); | 188 | chip->base = pci_iomap(pdev, 1, 0); |
375 | if (!chip->base) { | 189 | if (chip->base == 0) { |
376 | dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); | 190 | dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); |
377 | ret = -ENOMEM; | 191 | ret = -ENOMEM; |
378 | goto err_iomap; | 192 | goto err_iomap; |
379 | } | 193 | } |
380 | 194 | ||
381 | if (pdev->device == 0x8803) | ||
382 | chip->ioh = INTEL_EG20T_PCH; | ||
383 | else if (pdev->device == 0x8014) | ||
384 | chip->ioh = OKISEMI_ML7223m_IOH; | ||
385 | else if (pdev->device == 0x8043) | ||
386 | chip->ioh = OKISEMI_ML7223n_IOH; | ||
387 | |||
388 | chip->reg = chip->base; | 195 | chip->reg = chip->base; |
389 | pci_set_drvdata(pdev, chip); | 196 | pci_set_drvdata(pdev, chip); |
390 | spin_lock_init(&chip->spinlock); | 197 | mutex_init(&chip->lock); |
391 | pch_gpio_setup(chip); | 198 | pch_gpio_setup(chip); |
392 | ret = gpiochip_add(&chip->gpio); | 199 | ret = gpiochip_add(&chip->gpio); |
393 | if (ret) { | 200 | if (ret) { |
@@ -395,39 +202,8 @@ static int pch_gpio_probe(struct pci_dev *pdev, | |||
395 | goto err_gpiochip_add; | 202 | goto err_gpiochip_add; |
396 | } | 203 | } |
397 | 204 | ||
398 | irq_base = irq_alloc_descs(-1, 0, gpio_pins[chip->ioh], NUMA_NO_NODE); | ||
399 | if (irq_base < 0) { | ||
400 | dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n"); | ||
401 | chip->irq_base = -1; | ||
402 | goto end; | ||
403 | } | ||
404 | chip->irq_base = irq_base; | ||
405 | |||
406 | /* Mask all interrupts, but enable them */ | ||
407 | msk = (1 << gpio_pins[chip->ioh]) - 1; | ||
408 | iowrite32(msk, &chip->reg->imask); | ||
409 | iowrite32(msk, &chip->reg->ien); | ||
410 | |||
411 | ret = request_irq(pdev->irq, pch_gpio_handler, | ||
412 | IRQF_SHARED, KBUILD_MODNAME, chip); | ||
413 | if (ret != 0) { | ||
414 | dev_err(&pdev->dev, | ||
415 | "%s request_irq failed\n", __func__); | ||
416 | goto err_request_irq; | ||
417 | } | ||
418 | |||
419 | pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]); | ||
420 | |||
421 | end: | ||
422 | return 0; | 205 | return 0; |
423 | 206 | ||
424 | err_request_irq: | ||
425 | irq_free_descs(irq_base, gpio_pins[chip->ioh]); | ||
426 | |||
427 | ret = gpiochip_remove(&chip->gpio); | ||
428 | if (ret) | ||
429 | dev_err(&pdev->dev, "%s gpiochip_remove failed\n", __func__); | ||
430 | |||
431 | err_gpiochip_add: | 207 | err_gpiochip_add: |
432 | pci_iounmap(pdev, chip->base); | 208 | pci_iounmap(pdev, chip->base); |
433 | 209 | ||
@@ -443,17 +219,11 @@ err_pci_enable: | |||
443 | return ret; | 219 | return ret; |
444 | } | 220 | } |
445 | 221 | ||
446 | static void pch_gpio_remove(struct pci_dev *pdev) | 222 | static void __devexit pch_gpio_remove(struct pci_dev *pdev) |
447 | { | 223 | { |
448 | int err; | 224 | int err; |
449 | struct pch_gpio *chip = pci_get_drvdata(pdev); | 225 | struct pch_gpio *chip = pci_get_drvdata(pdev); |
450 | 226 | ||
451 | if (chip->irq_base != -1) { | ||
452 | free_irq(pdev->irq, chip); | ||
453 | |||
454 | irq_free_descs(chip->irq_base, gpio_pins[chip->ioh]); | ||
455 | } | ||
456 | |||
457 | err = gpiochip_remove(&chip->gpio); | 227 | err = gpiochip_remove(&chip->gpio); |
458 | if (err) | 228 | if (err) |
459 | dev_err(&pdev->dev, "Failed gpiochip_remove\n"); | 229 | dev_err(&pdev->dev, "Failed gpiochip_remove\n"); |
@@ -469,11 +239,9 @@ static int pch_gpio_suspend(struct pci_dev *pdev, pm_message_t state) | |||
469 | { | 239 | { |
470 | s32 ret; | 240 | s32 ret; |
471 | struct pch_gpio *chip = pci_get_drvdata(pdev); | 241 | struct pch_gpio *chip = pci_get_drvdata(pdev); |
472 | unsigned long flags; | ||
473 | 242 | ||
474 | spin_lock_irqsave(&chip->spinlock, flags); | ||
475 | pch_gpio_save_reg_conf(chip); | 243 | pch_gpio_save_reg_conf(chip); |
476 | spin_unlock_irqrestore(&chip->spinlock, flags); | 244 | pch_gpio_restore_reg_conf(chip); |
477 | 245 | ||
478 | ret = pci_save_state(pdev); | 246 | ret = pci_save_state(pdev); |
479 | if (ret) { | 247 | if (ret) { |
@@ -493,7 +261,6 @@ static int pch_gpio_resume(struct pci_dev *pdev) | |||
493 | { | 261 | { |
494 | s32 ret; | 262 | s32 ret; |
495 | struct pch_gpio *chip = pci_get_drvdata(pdev); | 263 | struct pch_gpio *chip = pci_get_drvdata(pdev); |
496 | unsigned long flags; | ||
497 | 264 | ||
498 | ret = pci_enable_wake(pdev, PCI_D0, 0); | 265 | ret = pci_enable_wake(pdev, PCI_D0, 0); |
499 | 266 | ||
@@ -505,11 +272,9 @@ static int pch_gpio_resume(struct pci_dev *pdev) | |||
505 | } | 272 | } |
506 | pci_restore_state(pdev); | 273 | pci_restore_state(pdev); |
507 | 274 | ||
508 | spin_lock_irqsave(&chip->spinlock, flags); | ||
509 | iowrite32(0x01, &chip->reg->reset); | 275 | iowrite32(0x01, &chip->reg->reset); |
510 | iowrite32(0x00, &chip->reg->reset); | 276 | iowrite32(0x00, &chip->reg->reset); |
511 | pch_gpio_restore_reg_conf(chip); | 277 | pch_gpio_restore_reg_conf(chip); |
512 | spin_unlock_irqrestore(&chip->spinlock, flags); | ||
513 | 278 | ||
514 | return 0; | 279 | return 0; |
515 | } | 280 | } |
@@ -522,8 +287,6 @@ static int pch_gpio_resume(struct pci_dev *pdev) | |||
522 | static DEFINE_PCI_DEVICE_TABLE(pch_gpio_pcidev_id) = { | 287 | static DEFINE_PCI_DEVICE_TABLE(pch_gpio_pcidev_id) = { |
523 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8803) }, | 288 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8803) }, |
524 | { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8014) }, | 289 | { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8014) }, |
525 | { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8043) }, | ||
526 | { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8803) }, | ||
527 | { 0, } | 290 | { 0, } |
528 | }; | 291 | }; |
529 | MODULE_DEVICE_TABLE(pci, pch_gpio_pcidev_id); | 292 | MODULE_DEVICE_TABLE(pci, pch_gpio_pcidev_id); |
@@ -532,12 +295,22 @@ static struct pci_driver pch_gpio_driver = { | |||
532 | .name = "pch_gpio", | 295 | .name = "pch_gpio", |
533 | .id_table = pch_gpio_pcidev_id, | 296 | .id_table = pch_gpio_pcidev_id, |
534 | .probe = pch_gpio_probe, | 297 | .probe = pch_gpio_probe, |
535 | .remove = pch_gpio_remove, | 298 | .remove = __devexit_p(pch_gpio_remove), |
536 | .suspend = pch_gpio_suspend, | 299 | .suspend = pch_gpio_suspend, |
537 | .resume = pch_gpio_resume | 300 | .resume = pch_gpio_resume |
538 | }; | 301 | }; |
539 | 302 | ||
540 | module_pci_driver(pch_gpio_driver); | 303 | static int __init pch_gpio_pci_init(void) |
304 | { | ||
305 | return pci_register_driver(&pch_gpio_driver); | ||
306 | } | ||
307 | module_init(pch_gpio_pci_init); | ||
308 | |||
309 | static void __exit pch_gpio_pci_exit(void) | ||
310 | { | ||
311 | pci_unregister_driver(&pch_gpio_driver); | ||
312 | } | ||
313 | module_exit(pch_gpio_pci_exit); | ||
541 | 314 | ||
542 | MODULE_DESCRIPTION("PCH GPIO PCI Driver"); | 315 | MODULE_DESCRIPTION("PCH GPIO PCI Driver"); |
543 | MODULE_LICENSE("GPL"); | 316 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c index c1720de18a4..2c5a18f32bf 100644 --- a/drivers/gpio/gpio-pl061.c +++ b/drivers/gpio/gpio-pl061.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
13 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/list.h> | ||
15 | #include <linux/io.h> | 16 | #include <linux/io.h> |
16 | #include <linux/ioport.h> | 17 | #include <linux/ioport.h> |
17 | #include <linux/irq.h> | 18 | #include <linux/irq.h> |
@@ -22,8 +23,6 @@ | |||
22 | #include <linux/amba/bus.h> | 23 | #include <linux/amba/bus.h> |
23 | #include <linux/amba/pl061.h> | 24 | #include <linux/amba/pl061.h> |
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
25 | #include <linux/pm.h> | ||
26 | #include <asm/mach/irq.h> | ||
27 | 26 | ||
28 | #define GPIODIR 0x400 | 27 | #define GPIODIR 0x400 |
29 | #define GPIOIS 0x404 | 28 | #define GPIOIS 0x404 |
@@ -36,28 +35,25 @@ | |||
36 | 35 | ||
37 | #define PL061_GPIO_NR 8 | 36 | #define PL061_GPIO_NR 8 |
38 | 37 | ||
39 | #ifdef CONFIG_PM | ||
40 | struct pl061_context_save_regs { | ||
41 | u8 gpio_data; | ||
42 | u8 gpio_dir; | ||
43 | u8 gpio_is; | ||
44 | u8 gpio_ibe; | ||
45 | u8 gpio_iev; | ||
46 | u8 gpio_ie; | ||
47 | }; | ||
48 | #endif | ||
49 | |||
50 | struct pl061_gpio { | 38 | struct pl061_gpio { |
51 | spinlock_t lock; | 39 | /* We use a list of pl061_gpio structs for each trigger IRQ in the main |
40 | * interrupts controller of the system. We need this to support systems | ||
41 | * in which more that one PL061s are connected to the same IRQ. The ISR | ||
42 | * interates through this list to find the source of the interrupt. | ||
43 | */ | ||
44 | struct list_head list; | ||
45 | |||
46 | /* Each of the two spinlocks protects a different set of hardware | ||
47 | * regiters and data structurs. This decouples the code of the IRQ from | ||
48 | * the GPIO code. This also makes the case of a GPIO routine call from | ||
49 | * the IRQ code simpler. | ||
50 | */ | ||
51 | spinlock_t lock; /* GPIO registers */ | ||
52 | spinlock_t irq_lock; /* IRQ registers */ | ||
52 | 53 | ||
53 | void __iomem *base; | 54 | void __iomem *base; |
54 | int irq_base; | 55 | unsigned irq_base; |
55 | struct irq_chip_generic *irq_gc; | ||
56 | struct gpio_chip gc; | 56 | struct gpio_chip gc; |
57 | |||
58 | #ifdef CONFIG_PM | ||
59 | struct pl061_context_save_regs csave_regs; | ||
60 | #endif | ||
61 | }; | 57 | }; |
62 | 58 | ||
63 | static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) | 59 | static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) |
@@ -122,16 +118,46 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset) | |||
122 | { | 118 | { |
123 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); | 119 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
124 | 120 | ||
125 | if (chip->irq_base <= 0) | 121 | if (chip->irq_base == (unsigned) -1) |
126 | return -EINVAL; | 122 | return -EINVAL; |
127 | 123 | ||
128 | return chip->irq_base + offset; | 124 | return chip->irq_base + offset; |
129 | } | 125 | } |
130 | 126 | ||
127 | /* | ||
128 | * PL061 GPIO IRQ | ||
129 | */ | ||
130 | static void pl061_irq_disable(struct irq_data *d) | ||
131 | { | ||
132 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); | ||
133 | int offset = d->irq - chip->irq_base; | ||
134 | unsigned long flags; | ||
135 | u8 gpioie; | ||
136 | |||
137 | spin_lock_irqsave(&chip->irq_lock, flags); | ||
138 | gpioie = readb(chip->base + GPIOIE); | ||
139 | gpioie &= ~(1 << offset); | ||
140 | writeb(gpioie, chip->base + GPIOIE); | ||
141 | spin_unlock_irqrestore(&chip->irq_lock, flags); | ||
142 | } | ||
143 | |||
144 | static void pl061_irq_enable(struct irq_data *d) | ||
145 | { | ||
146 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); | ||
147 | int offset = d->irq - chip->irq_base; | ||
148 | unsigned long flags; | ||
149 | u8 gpioie; | ||
150 | |||
151 | spin_lock_irqsave(&chip->irq_lock, flags); | ||
152 | gpioie = readb(chip->base + GPIOIE); | ||
153 | gpioie |= 1 << offset; | ||
154 | writeb(gpioie, chip->base + GPIOIE); | ||
155 | spin_unlock_irqrestore(&chip->irq_lock, flags); | ||
156 | } | ||
157 | |||
131 | static int pl061_irq_type(struct irq_data *d, unsigned trigger) | 158 | static int pl061_irq_type(struct irq_data *d, unsigned trigger) |
132 | { | 159 | { |
133 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | 160 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); |
134 | struct pl061_gpio *chip = gc->private; | ||
135 | int offset = d->irq - chip->irq_base; | 161 | int offset = d->irq - chip->irq_base; |
136 | unsigned long flags; | 162 | unsigned long flags; |
137 | u8 gpiois, gpioibe, gpioiev; | 163 | u8 gpiois, gpioibe, gpioiev; |
@@ -139,7 +165,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) | |||
139 | if (offset < 0 || offset >= PL061_GPIO_NR) | 165 | if (offset < 0 || offset >= PL061_GPIO_NR) |
140 | return -EINVAL; | 166 | return -EINVAL; |
141 | 167 | ||
142 | raw_spin_lock_irqsave(&gc->lock, flags); | 168 | spin_lock_irqsave(&chip->irq_lock, flags); |
143 | 169 | ||
144 | gpioiev = readb(chip->base + GPIOIEV); | 170 | gpioiev = readb(chip->base + GPIOIEV); |
145 | 171 | ||
@@ -168,178 +194,143 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) | |||
168 | 194 | ||
169 | writeb(gpioiev, chip->base + GPIOIEV); | 195 | writeb(gpioiev, chip->base + GPIOIEV); |
170 | 196 | ||
171 | raw_spin_unlock_irqrestore(&gc->lock, flags); | 197 | spin_unlock_irqrestore(&chip->irq_lock, flags); |
172 | 198 | ||
173 | return 0; | 199 | return 0; |
174 | } | 200 | } |
175 | 201 | ||
202 | static struct irq_chip pl061_irqchip = { | ||
203 | .name = "GPIO", | ||
204 | .irq_enable = pl061_irq_enable, | ||
205 | .irq_disable = pl061_irq_disable, | ||
206 | .irq_set_type = pl061_irq_type, | ||
207 | }; | ||
208 | |||
176 | static void pl061_irq_handler(unsigned irq, struct irq_desc *desc) | 209 | static void pl061_irq_handler(unsigned irq, struct irq_desc *desc) |
177 | { | 210 | { |
178 | unsigned long pending; | 211 | struct list_head *chip_list = irq_get_handler_data(irq); |
179 | int offset; | 212 | struct list_head *ptr; |
180 | struct pl061_gpio *chip = irq_desc_get_handler_data(desc); | 213 | struct pl061_gpio *chip; |
181 | struct irq_chip *irqchip = irq_desc_get_chip(desc); | 214 | |
215 | desc->irq_data.chip->irq_ack(&desc->irq_data); | ||
216 | list_for_each(ptr, chip_list) { | ||
217 | unsigned long pending; | ||
218 | int offset; | ||
182 | 219 | ||
183 | chained_irq_enter(irqchip, desc); | 220 | chip = list_entry(ptr, struct pl061_gpio, list); |
221 | pending = readb(chip->base + GPIOMIS); | ||
222 | writeb(pending, chip->base + GPIOIC); | ||
223 | |||
224 | if (pending == 0) | ||
225 | continue; | ||
184 | 226 | ||
185 | pending = readb(chip->base + GPIOMIS); | ||
186 | writeb(pending, chip->base + GPIOIC); | ||
187 | if (pending) { | ||
188 | for_each_set_bit(offset, &pending, PL061_GPIO_NR) | 227 | for_each_set_bit(offset, &pending, PL061_GPIO_NR) |
189 | generic_handle_irq(pl061_to_irq(&chip->gc, offset)); | 228 | generic_handle_irq(pl061_to_irq(&chip->gc, offset)); |
190 | } | 229 | } |
191 | 230 | desc->irq_data.chip->irq_unmask(&desc->irq_data); | |
192 | chained_irq_exit(irqchip, desc); | ||
193 | } | ||
194 | |||
195 | static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base) | ||
196 | { | ||
197 | struct irq_chip_type *ct; | ||
198 | |||
199 | chip->irq_gc = irq_alloc_generic_chip("gpio-pl061", 1, irq_base, | ||
200 | chip->base, handle_simple_irq); | ||
201 | chip->irq_gc->private = chip; | ||
202 | |||
203 | ct = chip->irq_gc->chip_types; | ||
204 | ct->chip.irq_mask = irq_gc_mask_clr_bit; | ||
205 | ct->chip.irq_unmask = irq_gc_mask_set_bit; | ||
206 | ct->chip.irq_set_type = pl061_irq_type; | ||
207 | ct->chip.irq_set_wake = irq_gc_set_wake; | ||
208 | ct->regs.mask = GPIOIE; | ||
209 | |||
210 | irq_setup_generic_chip(chip->irq_gc, IRQ_MSK(PL061_GPIO_NR), | ||
211 | IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); | ||
212 | } | 231 | } |
213 | 232 | ||
214 | static int pl061_probe(struct amba_device *adev, const struct amba_id *id) | 233 | static int pl061_probe(struct amba_device *dev, const struct amba_id *id) |
215 | { | 234 | { |
216 | struct device *dev = &adev->dev; | 235 | struct pl061_platform_data *pdata; |
217 | struct pl061_platform_data *pdata = dev->platform_data; | ||
218 | struct pl061_gpio *chip; | 236 | struct pl061_gpio *chip; |
237 | struct list_head *chip_list; | ||
219 | int ret, irq, i; | 238 | int ret, irq, i; |
239 | static DECLARE_BITMAP(init_irq, NR_IRQS); | ||
220 | 240 | ||
221 | chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); | 241 | pdata = dev->dev.platform_data; |
242 | if (pdata == NULL) | ||
243 | return -ENODEV; | ||
244 | |||
245 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | ||
222 | if (chip == NULL) | 246 | if (chip == NULL) |
223 | return -ENOMEM; | 247 | return -ENOMEM; |
224 | 248 | ||
225 | if (pdata) { | 249 | if (!request_mem_region(dev->res.start, |
226 | chip->gc.base = pdata->gpio_base; | 250 | resource_size(&dev->res), "pl061")) { |
227 | chip->irq_base = pdata->irq_base; | 251 | ret = -EBUSY; |
228 | } else if (adev->dev.of_node) { | 252 | goto free_mem; |
229 | chip->gc.base = -1; | 253 | } |
230 | chip->irq_base = 0; | ||
231 | } else | ||
232 | return -ENODEV; | ||
233 | |||
234 | if (!devm_request_mem_region(dev, adev->res.start, | ||
235 | resource_size(&adev->res), "pl061")) | ||
236 | return -EBUSY; | ||
237 | 254 | ||
238 | chip->base = devm_ioremap(dev, adev->res.start, | 255 | chip->base = ioremap(dev->res.start, resource_size(&dev->res)); |
239 | resource_size(&adev->res)); | 256 | if (chip->base == NULL) { |
240 | if (chip->base == NULL) | 257 | ret = -ENOMEM; |
241 | return -ENOMEM; | 258 | goto release_region; |
259 | } | ||
242 | 260 | ||
243 | spin_lock_init(&chip->lock); | 261 | spin_lock_init(&chip->lock); |
262 | spin_lock_init(&chip->irq_lock); | ||
263 | INIT_LIST_HEAD(&chip->list); | ||
244 | 264 | ||
245 | chip->gc.direction_input = pl061_direction_input; | 265 | chip->gc.direction_input = pl061_direction_input; |
246 | chip->gc.direction_output = pl061_direction_output; | 266 | chip->gc.direction_output = pl061_direction_output; |
247 | chip->gc.get = pl061_get_value; | 267 | chip->gc.get = pl061_get_value; |
248 | chip->gc.set = pl061_set_value; | 268 | chip->gc.set = pl061_set_value; |
249 | chip->gc.to_irq = pl061_to_irq; | 269 | chip->gc.to_irq = pl061_to_irq; |
270 | chip->gc.base = pdata->gpio_base; | ||
250 | chip->gc.ngpio = PL061_GPIO_NR; | 271 | chip->gc.ngpio = PL061_GPIO_NR; |
251 | chip->gc.label = dev_name(dev); | 272 | chip->gc.label = dev_name(&dev->dev); |
252 | chip->gc.dev = dev; | 273 | chip->gc.dev = &dev->dev; |
253 | chip->gc.owner = THIS_MODULE; | 274 | chip->gc.owner = THIS_MODULE; |
254 | 275 | ||
276 | chip->irq_base = pdata->irq_base; | ||
277 | |||
255 | ret = gpiochip_add(&chip->gc); | 278 | ret = gpiochip_add(&chip->gc); |
256 | if (ret) | 279 | if (ret) |
257 | return ret; | 280 | goto iounmap; |
258 | 281 | ||
259 | /* | 282 | /* |
260 | * irq_chip support | 283 | * irq_chip support |
261 | */ | 284 | */ |
262 | 285 | ||
263 | if (chip->irq_base <= 0) | 286 | if (chip->irq_base == (unsigned) -1) |
264 | return 0; | 287 | return 0; |
265 | 288 | ||
266 | pl061_init_gc(chip, chip->irq_base); | ||
267 | |||
268 | writeb(0, chip->base + GPIOIE); /* disable irqs */ | 289 | writeb(0, chip->base + GPIOIE); /* disable irqs */ |
269 | irq = adev->irq[0]; | 290 | irq = dev->irq[0]; |
270 | if (irq < 0) | 291 | if (irq < 0) { |
271 | return -ENODEV; | 292 | ret = -ENODEV; |
272 | 293 | goto iounmap; | |
294 | } | ||
273 | irq_set_chained_handler(irq, pl061_irq_handler); | 295 | irq_set_chained_handler(irq, pl061_irq_handler); |
274 | irq_set_handler_data(irq, chip); | 296 | if (!test_and_set_bit(irq, init_irq)) { /* list initialized? */ |
275 | 297 | chip_list = kmalloc(sizeof(*chip_list), GFP_KERNEL); | |
276 | for (i = 0; i < PL061_GPIO_NR; i++) { | 298 | if (chip_list == NULL) { |
277 | if (pdata) { | 299 | clear_bit(irq, init_irq); |
278 | if (pdata->directions & (1 << i)) | 300 | ret = -ENOMEM; |
279 | pl061_direction_output(&chip->gc, i, | 301 | goto iounmap; |
280 | pdata->values & (1 << i)); | ||
281 | else | ||
282 | pl061_direction_input(&chip->gc, i); | ||
283 | } | 302 | } |
284 | } | 303 | INIT_LIST_HEAD(chip_list); |
285 | 304 | irq_set_handler_data(irq, chip_list); | |
286 | amba_set_drvdata(adev, chip); | 305 | } else |
306 | chip_list = irq_get_handler_data(irq); | ||
307 | list_add(&chip->list, chip_list); | ||
287 | 308 | ||
288 | return 0; | 309 | for (i = 0; i < PL061_GPIO_NR; i++) { |
289 | } | 310 | if (pdata->directions & (1 << i)) |
311 | pl061_direction_output(&chip->gc, i, | ||
312 | pdata->values & (1 << i)); | ||
313 | else | ||
314 | pl061_direction_input(&chip->gc, i); | ||
290 | 315 | ||
291 | #ifdef CONFIG_PM | 316 | irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip, |
292 | static int pl061_suspend(struct device *dev) | 317 | handle_simple_irq); |
293 | { | 318 | set_irq_flags(i+chip->irq_base, IRQF_VALID); |
294 | struct pl061_gpio *chip = dev_get_drvdata(dev); | 319 | irq_set_chip_data(i + chip->irq_base, chip); |
295 | int offset; | ||
296 | |||
297 | chip->csave_regs.gpio_data = 0; | ||
298 | chip->csave_regs.gpio_dir = readb(chip->base + GPIODIR); | ||
299 | chip->csave_regs.gpio_is = readb(chip->base + GPIOIS); | ||
300 | chip->csave_regs.gpio_ibe = readb(chip->base + GPIOIBE); | ||
301 | chip->csave_regs.gpio_iev = readb(chip->base + GPIOIEV); | ||
302 | chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE); | ||
303 | |||
304 | for (offset = 0; offset < PL061_GPIO_NR; offset++) { | ||
305 | if (chip->csave_regs.gpio_dir & (1 << offset)) | ||
306 | chip->csave_regs.gpio_data |= | ||
307 | pl061_get_value(&chip->gc, offset) << offset; | ||
308 | } | 320 | } |
309 | 321 | ||
310 | return 0; | 322 | return 0; |
311 | } | ||
312 | 323 | ||
313 | static int pl061_resume(struct device *dev) | 324 | iounmap: |
314 | { | 325 | iounmap(chip->base); |
315 | struct pl061_gpio *chip = dev_get_drvdata(dev); | 326 | release_region: |
316 | int offset; | 327 | release_mem_region(dev->res.start, resource_size(&dev->res)); |
317 | 328 | free_mem: | |
318 | for (offset = 0; offset < PL061_GPIO_NR; offset++) { | 329 | kfree(chip); |
319 | if (chip->csave_regs.gpio_dir & (1 << offset)) | ||
320 | pl061_direction_output(&chip->gc, offset, | ||
321 | chip->csave_regs.gpio_data & | ||
322 | (1 << offset)); | ||
323 | else | ||
324 | pl061_direction_input(&chip->gc, offset); | ||
325 | } | ||
326 | |||
327 | writeb(chip->csave_regs.gpio_is, chip->base + GPIOIS); | ||
328 | writeb(chip->csave_regs.gpio_ibe, chip->base + GPIOIBE); | ||
329 | writeb(chip->csave_regs.gpio_iev, chip->base + GPIOIEV); | ||
330 | writeb(chip->csave_regs.gpio_ie, chip->base + GPIOIE); | ||
331 | 330 | ||
332 | return 0; | 331 | return ret; |
333 | } | 332 | } |
334 | 333 | ||
335 | static const struct dev_pm_ops pl061_dev_pm_ops = { | ||
336 | .suspend = pl061_suspend, | ||
337 | .resume = pl061_resume, | ||
338 | .freeze = pl061_suspend, | ||
339 | .restore = pl061_resume, | ||
340 | }; | ||
341 | #endif | ||
342 | |||
343 | static struct amba_id pl061_ids[] = { | 334 | static struct amba_id pl061_ids[] = { |
344 | { | 335 | { |
345 | .id = 0x00041061, | 336 | .id = 0x00041061, |
@@ -348,14 +339,9 @@ static struct amba_id pl061_ids[] = { | |||
348 | { 0, 0 }, | 339 | { 0, 0 }, |
349 | }; | 340 | }; |
350 | 341 | ||
351 | MODULE_DEVICE_TABLE(amba, pl061_ids); | ||
352 | |||
353 | static struct amba_driver pl061_gpio_driver = { | 342 | static struct amba_driver pl061_gpio_driver = { |
354 | .drv = { | 343 | .drv = { |
355 | .name = "pl061_gpio", | 344 | .name = "pl061_gpio", |
356 | #ifdef CONFIG_PM | ||
357 | .pm = &pl061_dev_pm_ops, | ||
358 | #endif | ||
359 | }, | 345 | }, |
360 | .id_table = pl061_ids, | 346 | .id_table = pl061_ids, |
361 | .probe = pl061_probe, | 347 | .probe = pl061_probe, |
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c deleted file mode 100644 index 8325f580c0f..00000000000 --- a/drivers/gpio/gpio-pxa.c +++ /dev/null | |||
@@ -1,700 +0,0 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/plat-pxa/gpio.c | ||
3 | * | ||
4 | * Generic PXA GPIO handling | ||
5 | * | ||
6 | * Author: Nicolas Pitre | ||
7 | * Created: Jun 15, 2001 | ||
8 | * Copyright: MontaVista Software Inc. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | */ | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/clk.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/gpio.h> | ||
18 | #include <linux/gpio-pxa.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/irq.h> | ||
21 | #include <linux/irqdomain.h> | ||
22 | #include <linux/io.h> | ||
23 | #include <linux/of.h> | ||
24 | #include <linux/of_device.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <linux/syscore_ops.h> | ||
27 | #include <linux/slab.h> | ||
28 | |||
29 | #include <asm/mach/irq.h> | ||
30 | |||
31 | #include <mach/irqs.h> | ||
32 | |||
33 | /* | ||
34 | * We handle the GPIOs by banks, each bank covers up to 32 GPIOs with | ||
35 | * one set of registers. The register offsets are organized below: | ||
36 | * | ||
37 | * GPLR GPDR GPSR GPCR GRER GFER GEDR | ||
38 | * BANK 0 - 0x0000 0x000C 0x0018 0x0024 0x0030 0x003C 0x0048 | ||
39 | * BANK 1 - 0x0004 0x0010 0x001C 0x0028 0x0034 0x0040 0x004C | ||
40 | * BANK 2 - 0x0008 0x0014 0x0020 0x002C 0x0038 0x0044 0x0050 | ||
41 | * | ||
42 | * BANK 3 - 0x0100 0x010C 0x0118 0x0124 0x0130 0x013C 0x0148 | ||
43 | * BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C | ||
44 | * BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x0150 | ||
45 | * | ||
46 | * NOTE: | ||
47 | * BANK 3 is only available on PXA27x and later processors. | ||
48 | * BANK 4 and 5 are only available on PXA935 | ||
49 | */ | ||
50 | |||
51 | #define GPLR_OFFSET 0x00 | ||
52 | #define GPDR_OFFSET 0x0C | ||
53 | #define GPSR_OFFSET 0x18 | ||
54 | #define GPCR_OFFSET 0x24 | ||
55 | #define GRER_OFFSET 0x30 | ||
56 | #define GFER_OFFSET 0x3C | ||
57 | #define GEDR_OFFSET 0x48 | ||
58 | #define GAFR_OFFSET 0x54 | ||
59 | #define ED_MASK_OFFSET 0x9C /* GPIO edge detection for AP side */ | ||
60 | |||
61 | #define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2)) | ||
62 | |||
63 | int pxa_last_gpio; | ||
64 | static int irq_base; | ||
65 | |||
66 | #ifdef CONFIG_OF | ||
67 | static struct irq_domain *domain; | ||
68 | static struct device_node *pxa_gpio_of_node; | ||
69 | #endif | ||
70 | |||
71 | struct pxa_gpio_chip { | ||
72 | struct gpio_chip chip; | ||
73 | void __iomem *regbase; | ||
74 | char label[10]; | ||
75 | |||
76 | unsigned long irq_mask; | ||
77 | unsigned long irq_edge_rise; | ||
78 | unsigned long irq_edge_fall; | ||
79 | int (*set_wake)(unsigned int gpio, unsigned int on); | ||
80 | |||
81 | #ifdef CONFIG_PM | ||
82 | unsigned long saved_gplr; | ||
83 | unsigned long saved_gpdr; | ||
84 | unsigned long saved_grer; | ||
85 | unsigned long saved_gfer; | ||
86 | #endif | ||
87 | }; | ||
88 | |||
89 | enum { | ||
90 | PXA25X_GPIO = 0, | ||
91 | PXA26X_GPIO, | ||
92 | PXA27X_GPIO, | ||
93 | PXA3XX_GPIO, | ||
94 | PXA93X_GPIO, | ||
95 | MMP_GPIO = 0x10, | ||
96 | }; | ||
97 | |||
98 | static DEFINE_SPINLOCK(gpio_lock); | ||
99 | static struct pxa_gpio_chip *pxa_gpio_chips; | ||
100 | static int gpio_type; | ||
101 | static void __iomem *gpio_reg_base; | ||
102 | |||
103 | #define for_each_gpio_chip(i, c) \ | ||
104 | for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++) | ||
105 | |||
106 | static inline void __iomem *gpio_chip_base(struct gpio_chip *c) | ||
107 | { | ||
108 | return container_of(c, struct pxa_gpio_chip, chip)->regbase; | ||
109 | } | ||
110 | |||
111 | static inline struct pxa_gpio_chip *gpio_to_pxachip(unsigned gpio) | ||
112 | { | ||
113 | return &pxa_gpio_chips[gpio_to_bank(gpio)]; | ||
114 | } | ||
115 | |||
116 | static inline int gpio_is_pxa_type(int type) | ||
117 | { | ||
118 | return (type & MMP_GPIO) == 0; | ||
119 | } | ||
120 | |||
121 | static inline int gpio_is_mmp_type(int type) | ||
122 | { | ||
123 | return (type & MMP_GPIO) != 0; | ||
124 | } | ||
125 | |||
126 | /* GPIO86/87/88/89 on PXA26x have their direction bits in PXA_GPDR(2 inverted, | ||
127 | * as well as their Alternate Function value being '1' for GPIO in GAFRx. | ||
128 | */ | ||
129 | static inline int __gpio_is_inverted(int gpio) | ||
130 | { | ||
131 | if ((gpio_type == PXA26X_GPIO) && (gpio > 85)) | ||
132 | return 1; | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | /* | ||
137 | * On PXA25x and PXA27x, GAFRx and GPDRx together decide the alternate | ||
138 | * function of a GPIO, and GPDRx cannot be altered once configured. It | ||
139 | * is attributed as "occupied" here (I know this terminology isn't | ||
140 | * accurate, you are welcome to propose a better one :-) | ||
141 | */ | ||
142 | static inline int __gpio_is_occupied(unsigned gpio) | ||
143 | { | ||
144 | struct pxa_gpio_chip *pxachip; | ||
145 | void __iomem *base; | ||
146 | unsigned long gafr = 0, gpdr = 0; | ||
147 | int ret, af = 0, dir = 0; | ||
148 | |||
149 | pxachip = gpio_to_pxachip(gpio); | ||
150 | base = gpio_chip_base(&pxachip->chip); | ||
151 | gpdr = readl_relaxed(base + GPDR_OFFSET); | ||
152 | |||
153 | switch (gpio_type) { | ||
154 | case PXA25X_GPIO: | ||
155 | case PXA26X_GPIO: | ||
156 | case PXA27X_GPIO: | ||
157 | gafr = readl_relaxed(base + GAFR_OFFSET); | ||
158 | af = (gafr >> ((gpio & 0xf) * 2)) & 0x3; | ||
159 | dir = gpdr & GPIO_bit(gpio); | ||
160 | |||
161 | if (__gpio_is_inverted(gpio)) | ||
162 | ret = (af != 1) || (dir == 0); | ||
163 | else | ||
164 | ret = (af != 0) || (dir != 0); | ||
165 | break; | ||
166 | default: | ||
167 | ret = gpdr & GPIO_bit(gpio); | ||
168 | break; | ||
169 | } | ||
170 | return ret; | ||
171 | } | ||
172 | |||
173 | static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
174 | { | ||
175 | return chip->base + offset + irq_base; | ||
176 | } | ||
177 | |||
178 | int pxa_irq_to_gpio(int irq) | ||
179 | { | ||
180 | return irq - irq_base; | ||
181 | } | ||
182 | |||
183 | static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
184 | { | ||
185 | void __iomem *base = gpio_chip_base(chip); | ||
186 | uint32_t value, mask = 1 << offset; | ||
187 | unsigned long flags; | ||
188 | |||
189 | spin_lock_irqsave(&gpio_lock, flags); | ||
190 | |||
191 | value = readl_relaxed(base + GPDR_OFFSET); | ||
192 | if (__gpio_is_inverted(chip->base + offset)) | ||
193 | value |= mask; | ||
194 | else | ||
195 | value &= ~mask; | ||
196 | writel_relaxed(value, base + GPDR_OFFSET); | ||
197 | |||
198 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
199 | return 0; | ||
200 | } | ||
201 | |||
202 | static int pxa_gpio_direction_output(struct gpio_chip *chip, | ||
203 | unsigned offset, int value) | ||
204 | { | ||
205 | void __iomem *base = gpio_chip_base(chip); | ||
206 | uint32_t tmp, mask = 1 << offset; | ||
207 | unsigned long flags; | ||
208 | |||
209 | writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); | ||
210 | |||
211 | spin_lock_irqsave(&gpio_lock, flags); | ||
212 | |||
213 | tmp = readl_relaxed(base + GPDR_OFFSET); | ||
214 | if (__gpio_is_inverted(chip->base + offset)) | ||
215 | tmp &= ~mask; | ||
216 | else | ||
217 | tmp |= mask; | ||
218 | writel_relaxed(tmp, base + GPDR_OFFSET); | ||
219 | |||
220 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
225 | { | ||
226 | return readl_relaxed(gpio_chip_base(chip) + GPLR_OFFSET) & (1 << offset); | ||
227 | } | ||
228 | |||
229 | static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
230 | { | ||
231 | writel_relaxed(1 << offset, gpio_chip_base(chip) + | ||
232 | (value ? GPSR_OFFSET : GPCR_OFFSET)); | ||
233 | } | ||
234 | |||
235 | #ifdef CONFIG_OF_GPIO | ||
236 | static int pxa_gpio_of_xlate(struct gpio_chip *gc, | ||
237 | const struct of_phandle_args *gpiospec, | ||
238 | u32 *flags) | ||
239 | { | ||
240 | if (gpiospec->args[0] > pxa_last_gpio) | ||
241 | return -EINVAL; | ||
242 | |||
243 | if (gc != &pxa_gpio_chips[gpiospec->args[0] / 32].chip) | ||
244 | return -EINVAL; | ||
245 | |||
246 | if (flags) | ||
247 | *flags = gpiospec->args[1]; | ||
248 | |||
249 | return gpiospec->args[0] % 32; | ||
250 | } | ||
251 | #endif | ||
252 | |||
253 | static int pxa_init_gpio_chip(int gpio_end, | ||
254 | int (*set_wake)(unsigned int, unsigned int)) | ||
255 | { | ||
256 | int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1; | ||
257 | struct pxa_gpio_chip *chips; | ||
258 | |||
259 | chips = kzalloc(nbanks * sizeof(struct pxa_gpio_chip), GFP_KERNEL); | ||
260 | if (chips == NULL) { | ||
261 | pr_err("%s: failed to allocate GPIO chips\n", __func__); | ||
262 | return -ENOMEM; | ||
263 | } | ||
264 | |||
265 | for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) { | ||
266 | struct gpio_chip *c = &chips[i].chip; | ||
267 | |||
268 | sprintf(chips[i].label, "gpio-%d", i); | ||
269 | chips[i].regbase = gpio_reg_base + BANK_OFF(i); | ||
270 | chips[i].set_wake = set_wake; | ||
271 | |||
272 | c->base = gpio; | ||
273 | c->label = chips[i].label; | ||
274 | |||
275 | c->direction_input = pxa_gpio_direction_input; | ||
276 | c->direction_output = pxa_gpio_direction_output; | ||
277 | c->get = pxa_gpio_get; | ||
278 | c->set = pxa_gpio_set; | ||
279 | c->to_irq = pxa_gpio_to_irq; | ||
280 | #ifdef CONFIG_OF_GPIO | ||
281 | c->of_node = pxa_gpio_of_node; | ||
282 | c->of_xlate = pxa_gpio_of_xlate; | ||
283 | c->of_gpio_n_cells = 2; | ||
284 | #endif | ||
285 | |||
286 | /* number of GPIOs on last bank may be less than 32 */ | ||
287 | c->ngpio = (gpio + 31 > gpio_end) ? (gpio_end - gpio + 1) : 32; | ||
288 | gpiochip_add(c); | ||
289 | } | ||
290 | pxa_gpio_chips = chips; | ||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | /* Update only those GRERx and GFERx edge detection register bits if those | ||
295 | * bits are set in c->irq_mask | ||
296 | */ | ||
297 | static inline void update_edge_detect(struct pxa_gpio_chip *c) | ||
298 | { | ||
299 | uint32_t grer, gfer; | ||
300 | |||
301 | grer = readl_relaxed(c->regbase + GRER_OFFSET) & ~c->irq_mask; | ||
302 | gfer = readl_relaxed(c->regbase + GFER_OFFSET) & ~c->irq_mask; | ||
303 | grer |= c->irq_edge_rise & c->irq_mask; | ||
304 | gfer |= c->irq_edge_fall & c->irq_mask; | ||
305 | writel_relaxed(grer, c->regbase + GRER_OFFSET); | ||
306 | writel_relaxed(gfer, c->regbase + GFER_OFFSET); | ||
307 | } | ||
308 | |||
309 | static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type) | ||
310 | { | ||
311 | struct pxa_gpio_chip *c; | ||
312 | int gpio = pxa_irq_to_gpio(d->irq); | ||
313 | unsigned long gpdr, mask = GPIO_bit(gpio); | ||
314 | |||
315 | c = gpio_to_pxachip(gpio); | ||
316 | |||
317 | if (type == IRQ_TYPE_PROBE) { | ||
318 | /* Don't mess with enabled GPIOs using preconfigured edges or | ||
319 | * GPIOs set to alternate function or to output during probe | ||
320 | */ | ||
321 | if ((c->irq_edge_rise | c->irq_edge_fall) & GPIO_bit(gpio)) | ||
322 | return 0; | ||
323 | |||
324 | if (__gpio_is_occupied(gpio)) | ||
325 | return 0; | ||
326 | |||
327 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; | ||
328 | } | ||
329 | |||
330 | gpdr = readl_relaxed(c->regbase + GPDR_OFFSET); | ||
331 | |||
332 | if (__gpio_is_inverted(gpio)) | ||
333 | writel_relaxed(gpdr | mask, c->regbase + GPDR_OFFSET); | ||
334 | else | ||
335 | writel_relaxed(gpdr & ~mask, c->regbase + GPDR_OFFSET); | ||
336 | |||
337 | if (type & IRQ_TYPE_EDGE_RISING) | ||
338 | c->irq_edge_rise |= mask; | ||
339 | else | ||
340 | c->irq_edge_rise &= ~mask; | ||
341 | |||
342 | if (type & IRQ_TYPE_EDGE_FALLING) | ||
343 | c->irq_edge_fall |= mask; | ||
344 | else | ||
345 | c->irq_edge_fall &= ~mask; | ||
346 | |||
347 | update_edge_detect(c); | ||
348 | |||
349 | pr_debug("%s: IRQ%d (GPIO%d) - edge%s%s\n", __func__, d->irq, gpio, | ||
350 | ((type & IRQ_TYPE_EDGE_RISING) ? " rising" : ""), | ||
351 | ((type & IRQ_TYPE_EDGE_FALLING) ? " falling" : "")); | ||
352 | return 0; | ||
353 | } | ||
354 | |||
355 | static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc) | ||
356 | { | ||
357 | struct pxa_gpio_chip *c; | ||
358 | int loop, gpio, gpio_base, n; | ||
359 | unsigned long gedr; | ||
360 | struct irq_chip *chip = irq_desc_get_chip(desc); | ||
361 | |||
362 | chained_irq_enter(chip, desc); | ||
363 | |||
364 | do { | ||
365 | loop = 0; | ||
366 | for_each_gpio_chip(gpio, c) { | ||
367 | gpio_base = c->chip.base; | ||
368 | |||
369 | gedr = readl_relaxed(c->regbase + GEDR_OFFSET); | ||
370 | gedr = gedr & c->irq_mask; | ||
371 | writel_relaxed(gedr, c->regbase + GEDR_OFFSET); | ||
372 | |||
373 | for_each_set_bit(n, &gedr, BITS_PER_LONG) { | ||
374 | loop = 1; | ||
375 | |||
376 | generic_handle_irq(gpio_to_irq(gpio_base + n)); | ||
377 | } | ||
378 | } | ||
379 | } while (loop); | ||
380 | |||
381 | chained_irq_exit(chip, desc); | ||
382 | } | ||
383 | |||
384 | static void pxa_ack_muxed_gpio(struct irq_data *d) | ||
385 | { | ||
386 | int gpio = pxa_irq_to_gpio(d->irq); | ||
387 | struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); | ||
388 | |||
389 | writel_relaxed(GPIO_bit(gpio), c->regbase + GEDR_OFFSET); | ||
390 | } | ||
391 | |||
392 | static void pxa_mask_muxed_gpio(struct irq_data *d) | ||
393 | { | ||
394 | int gpio = pxa_irq_to_gpio(d->irq); | ||
395 | struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); | ||
396 | uint32_t grer, gfer; | ||
397 | |||
398 | c->irq_mask &= ~GPIO_bit(gpio); | ||
399 | |||
400 | grer = readl_relaxed(c->regbase + GRER_OFFSET) & ~GPIO_bit(gpio); | ||
401 | gfer = readl_relaxed(c->regbase + GFER_OFFSET) & ~GPIO_bit(gpio); | ||
402 | writel_relaxed(grer, c->regbase + GRER_OFFSET); | ||
403 | writel_relaxed(gfer, c->regbase + GFER_OFFSET); | ||
404 | } | ||
405 | |||
406 | static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on) | ||
407 | { | ||
408 | int gpio = pxa_irq_to_gpio(d->irq); | ||
409 | struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); | ||
410 | |||
411 | if (c->set_wake) | ||
412 | return c->set_wake(gpio, on); | ||
413 | else | ||
414 | return 0; | ||
415 | } | ||
416 | |||
417 | static void pxa_unmask_muxed_gpio(struct irq_data *d) | ||
418 | { | ||
419 | int gpio = pxa_irq_to_gpio(d->irq); | ||
420 | struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); | ||
421 | |||
422 | c->irq_mask |= GPIO_bit(gpio); | ||
423 | update_edge_detect(c); | ||
424 | } | ||
425 | |||
426 | static struct irq_chip pxa_muxed_gpio_chip = { | ||
427 | .name = "GPIO", | ||
428 | .irq_ack = pxa_ack_muxed_gpio, | ||
429 | .irq_mask = pxa_mask_muxed_gpio, | ||
430 | .irq_unmask = pxa_unmask_muxed_gpio, | ||
431 | .irq_set_type = pxa_gpio_irq_type, | ||
432 | .irq_set_wake = pxa_gpio_set_wake, | ||
433 | }; | ||
434 | |||
435 | static int pxa_gpio_nums(void) | ||
436 | { | ||
437 | int count = 0; | ||
438 | |||
439 | #ifdef CONFIG_ARCH_PXA | ||
440 | if (cpu_is_pxa25x()) { | ||
441 | #ifdef CONFIG_CPU_PXA26x | ||
442 | count = 89; | ||
443 | gpio_type = PXA26X_GPIO; | ||
444 | #elif defined(CONFIG_PXA25x) | ||
445 | count = 84; | ||
446 | gpio_type = PXA26X_GPIO; | ||
447 | #endif /* CONFIG_CPU_PXA26x */ | ||
448 | } else if (cpu_is_pxa27x()) { | ||
449 | count = 120; | ||
450 | gpio_type = PXA27X_GPIO; | ||
451 | } else if (cpu_is_pxa93x()) { | ||
452 | count = 191; | ||
453 | gpio_type = PXA93X_GPIO; | ||
454 | } else if (cpu_is_pxa3xx()) { | ||
455 | count = 127; | ||
456 | gpio_type = PXA3XX_GPIO; | ||
457 | } | ||
458 | #endif /* CONFIG_ARCH_PXA */ | ||
459 | |||
460 | #ifdef CONFIG_ARCH_MMP | ||
461 | if (cpu_is_pxa168() || cpu_is_pxa910()) { | ||
462 | count = 127; | ||
463 | gpio_type = MMP_GPIO; | ||
464 | } else if (cpu_is_mmp2()) { | ||
465 | count = 191; | ||
466 | gpio_type = MMP_GPIO; | ||
467 | } | ||
468 | #endif /* CONFIG_ARCH_MMP */ | ||
469 | return count; | ||
470 | } | ||
471 | |||
472 | #ifdef CONFIG_OF | ||
473 | static struct of_device_id pxa_gpio_dt_ids[] = { | ||
474 | { .compatible = "mrvl,pxa-gpio" }, | ||
475 | { .compatible = "mrvl,mmp-gpio", .data = (void *)MMP_GPIO }, | ||
476 | {} | ||
477 | }; | ||
478 | |||
479 | static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq, | ||
480 | irq_hw_number_t hw) | ||
481 | { | ||
482 | irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, | ||
483 | handle_edge_irq); | ||
484 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
485 | return 0; | ||
486 | } | ||
487 | |||
488 | const struct irq_domain_ops pxa_irq_domain_ops = { | ||
489 | .map = pxa_irq_domain_map, | ||
490 | .xlate = irq_domain_xlate_twocell, | ||
491 | }; | ||
492 | |||
493 | static int pxa_gpio_probe_dt(struct platform_device *pdev) | ||
494 | { | ||
495 | int ret, nr_banks, nr_gpios; | ||
496 | struct device_node *prev, *next, *np = pdev->dev.of_node; | ||
497 | const struct of_device_id *of_id = | ||
498 | of_match_device(pxa_gpio_dt_ids, &pdev->dev); | ||
499 | |||
500 | if (!of_id) { | ||
501 | dev_err(&pdev->dev, "Failed to find gpio controller\n"); | ||
502 | return -EFAULT; | ||
503 | } | ||
504 | gpio_type = (int)of_id->data; | ||
505 | |||
506 | next = of_get_next_child(np, NULL); | ||
507 | prev = next; | ||
508 | if (!next) { | ||
509 | dev_err(&pdev->dev, "Failed to find child gpio node\n"); | ||
510 | ret = -EINVAL; | ||
511 | goto err; | ||
512 | } | ||
513 | for (nr_banks = 1; ; nr_banks++) { | ||
514 | next = of_get_next_child(np, prev); | ||
515 | if (!next) | ||
516 | break; | ||
517 | prev = next; | ||
518 | } | ||
519 | of_node_put(prev); | ||
520 | nr_gpios = nr_banks << 5; | ||
521 | pxa_last_gpio = nr_gpios - 1; | ||
522 | |||
523 | irq_base = irq_alloc_descs(-1, 0, nr_gpios, 0); | ||
524 | if (irq_base < 0) { | ||
525 | dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); | ||
526 | goto err; | ||
527 | } | ||
528 | domain = irq_domain_add_legacy(np, nr_gpios, irq_base, 0, | ||
529 | &pxa_irq_domain_ops, NULL); | ||
530 | pxa_gpio_of_node = np; | ||
531 | return 0; | ||
532 | err: | ||
533 | iounmap(gpio_reg_base); | ||
534 | return ret; | ||
535 | } | ||
536 | #else | ||
537 | #define pxa_gpio_probe_dt(pdev) (-1) | ||
538 | #endif | ||
539 | |||
540 | static int pxa_gpio_probe(struct platform_device *pdev) | ||
541 | { | ||
542 | struct pxa_gpio_chip *c; | ||
543 | struct resource *res; | ||
544 | struct clk *clk; | ||
545 | struct pxa_gpio_platform_data *info; | ||
546 | int gpio, irq, ret, use_of = 0; | ||
547 | int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; | ||
548 | |||
549 | ret = pxa_gpio_probe_dt(pdev); | ||
550 | if (ret < 0) { | ||
551 | pxa_last_gpio = pxa_gpio_nums(); | ||
552 | #ifdef CONFIG_ARCH_PXA | ||
553 | if (gpio_is_pxa_type(gpio_type)) | ||
554 | irq_base = PXA_GPIO_TO_IRQ(0); | ||
555 | #endif | ||
556 | #ifdef CONFIG_ARCH_MMP | ||
557 | if (gpio_is_mmp_type(gpio_type)) | ||
558 | irq_base = MMP_GPIO_TO_IRQ(0); | ||
559 | #endif | ||
560 | } else { | ||
561 | use_of = 1; | ||
562 | } | ||
563 | |||
564 | if (!pxa_last_gpio) | ||
565 | return -EINVAL; | ||
566 | |||
567 | irq0 = platform_get_irq_byname(pdev, "gpio0"); | ||
568 | irq1 = platform_get_irq_byname(pdev, "gpio1"); | ||
569 | irq_mux = platform_get_irq_byname(pdev, "gpio_mux"); | ||
570 | if ((irq0 > 0 && irq1 <= 0) || (irq0 <= 0 && irq1 > 0) | ||
571 | || (irq_mux <= 0)) | ||
572 | return -EINVAL; | ||
573 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
574 | if (!res) | ||
575 | return -EINVAL; | ||
576 | gpio_reg_base = ioremap(res->start, resource_size(res)); | ||
577 | if (!gpio_reg_base) | ||
578 | return -EINVAL; | ||
579 | |||
580 | if (irq0 > 0) | ||
581 | gpio_offset = 2; | ||
582 | |||
583 | clk = clk_get(&pdev->dev, NULL); | ||
584 | if (IS_ERR(clk)) { | ||
585 | dev_err(&pdev->dev, "Error %ld to get gpio clock\n", | ||
586 | PTR_ERR(clk)); | ||
587 | iounmap(gpio_reg_base); | ||
588 | return PTR_ERR(clk); | ||
589 | } | ||
590 | ret = clk_prepare_enable(clk); | ||
591 | if (ret) { | ||
592 | clk_put(clk); | ||
593 | iounmap(gpio_reg_base); | ||
594 | return ret; | ||
595 | } | ||
596 | |||
597 | /* Initialize GPIO chips */ | ||
598 | info = dev_get_platdata(&pdev->dev); | ||
599 | pxa_init_gpio_chip(pxa_last_gpio, info ? info->gpio_set_wake : NULL); | ||
600 | |||
601 | /* clear all GPIO edge detects */ | ||
602 | for_each_gpio_chip(gpio, c) { | ||
603 | writel_relaxed(0, c->regbase + GFER_OFFSET); | ||
604 | writel_relaxed(0, c->regbase + GRER_OFFSET); | ||
605 | writel_relaxed(~0,c->regbase + GEDR_OFFSET); | ||
606 | /* unmask GPIO edge detect for AP side */ | ||
607 | if (gpio_is_mmp_type(gpio_type)) | ||
608 | writel_relaxed(~0, c->regbase + ED_MASK_OFFSET); | ||
609 | } | ||
610 | |||
611 | if (!use_of) { | ||
612 | #ifdef CONFIG_ARCH_PXA | ||
613 | irq = gpio_to_irq(0); | ||
614 | irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, | ||
615 | handle_edge_irq); | ||
616 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
617 | irq_set_chained_handler(IRQ_GPIO0, pxa_gpio_demux_handler); | ||
618 | |||
619 | irq = gpio_to_irq(1); | ||
620 | irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, | ||
621 | handle_edge_irq); | ||
622 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
623 | irq_set_chained_handler(IRQ_GPIO1, pxa_gpio_demux_handler); | ||
624 | #endif | ||
625 | |||
626 | for (irq = gpio_to_irq(gpio_offset); | ||
627 | irq <= gpio_to_irq(pxa_last_gpio); irq++) { | ||
628 | irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, | ||
629 | handle_edge_irq); | ||
630 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); | ||
631 | } | ||
632 | } | ||
633 | |||
634 | irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler); | ||
635 | return 0; | ||
636 | } | ||
637 | |||
638 | static struct platform_driver pxa_gpio_driver = { | ||
639 | .probe = pxa_gpio_probe, | ||
640 | .driver = { | ||
641 | .name = "pxa-gpio", | ||
642 | .of_match_table = of_match_ptr(pxa_gpio_dt_ids), | ||
643 | }, | ||
644 | }; | ||
645 | |||
646 | static int __init pxa_gpio_init(void) | ||
647 | { | ||
648 | return platform_driver_register(&pxa_gpio_driver); | ||
649 | } | ||
650 | postcore_initcall(pxa_gpio_init); | ||
651 | |||
652 | #ifdef CONFIG_PM | ||
653 | static int pxa_gpio_suspend(void) | ||
654 | { | ||
655 | struct pxa_gpio_chip *c; | ||
656 | int gpio; | ||
657 | |||
658 | for_each_gpio_chip(gpio, c) { | ||
659 | c->saved_gplr = readl_relaxed(c->regbase + GPLR_OFFSET); | ||
660 | c->saved_gpdr = readl_relaxed(c->regbase + GPDR_OFFSET); | ||
661 | c->saved_grer = readl_relaxed(c->regbase + GRER_OFFSET); | ||
662 | c->saved_gfer = readl_relaxed(c->regbase + GFER_OFFSET); | ||
663 | |||
664 | /* Clear GPIO transition detect bits */ | ||
665 | writel_relaxed(0xffffffff, c->regbase + GEDR_OFFSET); | ||
666 | } | ||
667 | return 0; | ||
668 | } | ||
669 | |||
670 | static void pxa_gpio_resume(void) | ||
671 | { | ||
672 | struct pxa_gpio_chip *c; | ||
673 | int gpio; | ||
674 | |||
675 | for_each_gpio_chip(gpio, c) { | ||
676 | /* restore level with set/clear */ | ||
677 | writel_relaxed( c->saved_gplr, c->regbase + GPSR_OFFSET); | ||
678 | writel_relaxed(~c->saved_gplr, c->regbase + GPCR_OFFSET); | ||
679 | |||
680 | writel_relaxed(c->saved_grer, c->regbase + GRER_OFFSET); | ||
681 | writel_relaxed(c->saved_gfer, c->regbase + GFER_OFFSET); | ||
682 | writel_relaxed(c->saved_gpdr, c->regbase + GPDR_OFFSET); | ||
683 | } | ||
684 | } | ||
685 | #else | ||
686 | #define pxa_gpio_suspend NULL | ||
687 | #define pxa_gpio_resume NULL | ||
688 | #endif | ||
689 | |||
690 | struct syscore_ops pxa_gpio_syscore_ops = { | ||
691 | .suspend = pxa_gpio_suspend, | ||
692 | .resume = pxa_gpio_resume, | ||
693 | }; | ||
694 | |||
695 | static int __init pxa_gpio_sysinit(void) | ||
696 | { | ||
697 | register_syscore_ops(&pxa_gpio_syscore_ops); | ||
698 | return 0; | ||
699 | } | ||
700 | postcore_initcall(pxa_gpio_sysinit); | ||
diff --git a/drivers/gpio/gpio-rc5t583.c b/drivers/gpio/gpio-rc5t583.c deleted file mode 100644 index e63d6a397e1..00000000000 --- a/drivers/gpio/gpio-rc5t583.c +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | /* | ||
2 | * GPIO driver for RICOH583 power management chip. | ||
3 | * | ||
4 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. | ||
5 | * Author: Laxman dewangan <ldewangan@nvidia.com> | ||
6 | * | ||
7 | * Based on code | ||
8 | * Copyright (C) 2011 RICOH COMPANY,LTD | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms and conditions of the GNU General Public License, | ||
12 | * version 2, as published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
17 | * more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | * | ||
22 | */ | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/device.h> | ||
29 | #include <linux/gpio.h> | ||
30 | #include <linux/mfd/rc5t583.h> | ||
31 | |||
32 | struct rc5t583_gpio { | ||
33 | struct gpio_chip gpio_chip; | ||
34 | struct rc5t583 *rc5t583; | ||
35 | }; | ||
36 | |||
37 | static inline struct rc5t583_gpio *to_rc5t583_gpio(struct gpio_chip *chip) | ||
38 | { | ||
39 | return container_of(chip, struct rc5t583_gpio, gpio_chip); | ||
40 | } | ||
41 | |||
42 | static int rc5t583_gpio_get(struct gpio_chip *gc, unsigned int offset) | ||
43 | { | ||
44 | struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); | ||
45 | struct device *parent = rc5t583_gpio->rc5t583->dev; | ||
46 | uint8_t val = 0; | ||
47 | int ret; | ||
48 | |||
49 | ret = rc5t583_read(parent, RC5T583_GPIO_MON_IOIN, &val); | ||
50 | if (ret < 0) | ||
51 | return ret; | ||
52 | |||
53 | return !!(val & BIT(offset)); | ||
54 | } | ||
55 | |||
56 | static void rc5t583_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) | ||
57 | { | ||
58 | struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); | ||
59 | struct device *parent = rc5t583_gpio->rc5t583->dev; | ||
60 | if (val) | ||
61 | rc5t583_set_bits(parent, RC5T583_GPIO_IOOUT, BIT(offset)); | ||
62 | else | ||
63 | rc5t583_clear_bits(parent, RC5T583_GPIO_IOOUT, BIT(offset)); | ||
64 | } | ||
65 | |||
66 | static int rc5t583_gpio_dir_input(struct gpio_chip *gc, unsigned int offset) | ||
67 | { | ||
68 | struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); | ||
69 | struct device *parent = rc5t583_gpio->rc5t583->dev; | ||
70 | int ret; | ||
71 | |||
72 | ret = rc5t583_clear_bits(parent, RC5T583_GPIO_IOSEL, BIT(offset)); | ||
73 | if (ret < 0) | ||
74 | return ret; | ||
75 | |||
76 | /* Set pin to gpio mode */ | ||
77 | return rc5t583_clear_bits(parent, RC5T583_GPIO_PGSEL, BIT(offset)); | ||
78 | } | ||
79 | |||
80 | static int rc5t583_gpio_dir_output(struct gpio_chip *gc, unsigned offset, | ||
81 | int value) | ||
82 | { | ||
83 | struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); | ||
84 | struct device *parent = rc5t583_gpio->rc5t583->dev; | ||
85 | int ret; | ||
86 | |||
87 | rc5t583_gpio_set(gc, offset, value); | ||
88 | ret = rc5t583_set_bits(parent, RC5T583_GPIO_IOSEL, BIT(offset)); | ||
89 | if (ret < 0) | ||
90 | return ret; | ||
91 | |||
92 | /* Set pin to gpio mode */ | ||
93 | return rc5t583_clear_bits(parent, RC5T583_GPIO_PGSEL, BIT(offset)); | ||
94 | } | ||
95 | |||
96 | static int rc5t583_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | ||
97 | { | ||
98 | struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); | ||
99 | |||
100 | if ((offset >= 0) && (offset < 8)) | ||
101 | return rc5t583_gpio->rc5t583->irq_base + | ||
102 | RC5T583_IRQ_GPIO0 + offset; | ||
103 | return -EINVAL; | ||
104 | } | ||
105 | |||
106 | static void rc5t583_gpio_free(struct gpio_chip *gc, unsigned offset) | ||
107 | { | ||
108 | struct rc5t583_gpio *rc5t583_gpio = to_rc5t583_gpio(gc); | ||
109 | struct device *parent = rc5t583_gpio->rc5t583->dev; | ||
110 | |||
111 | rc5t583_set_bits(parent, RC5T583_GPIO_PGSEL, BIT(offset)); | ||
112 | } | ||
113 | |||
114 | static int rc5t583_gpio_probe(struct platform_device *pdev) | ||
115 | { | ||
116 | struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent); | ||
117 | struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev); | ||
118 | struct rc5t583_gpio *rc5t583_gpio; | ||
119 | |||
120 | rc5t583_gpio = devm_kzalloc(&pdev->dev, sizeof(*rc5t583_gpio), | ||
121 | GFP_KERNEL); | ||
122 | if (!rc5t583_gpio) { | ||
123 | dev_warn(&pdev->dev, "Mem allocation for rc5t583_gpio failed"); | ||
124 | return -ENOMEM; | ||
125 | } | ||
126 | |||
127 | rc5t583_gpio->gpio_chip.label = "gpio-rc5t583", | ||
128 | rc5t583_gpio->gpio_chip.owner = THIS_MODULE, | ||
129 | rc5t583_gpio->gpio_chip.free = rc5t583_gpio_free, | ||
130 | rc5t583_gpio->gpio_chip.direction_input = rc5t583_gpio_dir_input, | ||
131 | rc5t583_gpio->gpio_chip.direction_output = rc5t583_gpio_dir_output, | ||
132 | rc5t583_gpio->gpio_chip.set = rc5t583_gpio_set, | ||
133 | rc5t583_gpio->gpio_chip.get = rc5t583_gpio_get, | ||
134 | rc5t583_gpio->gpio_chip.to_irq = rc5t583_gpio_to_irq, | ||
135 | rc5t583_gpio->gpio_chip.ngpio = RC5T583_MAX_GPIO, | ||
136 | rc5t583_gpio->gpio_chip.can_sleep = 1, | ||
137 | rc5t583_gpio->gpio_chip.dev = &pdev->dev; | ||
138 | rc5t583_gpio->gpio_chip.base = -1; | ||
139 | rc5t583_gpio->rc5t583 = rc5t583; | ||
140 | |||
141 | if (pdata && pdata->gpio_base) | ||
142 | rc5t583_gpio->gpio_chip.base = pdata->gpio_base; | ||
143 | |||
144 | platform_set_drvdata(pdev, rc5t583_gpio); | ||
145 | |||
146 | return gpiochip_add(&rc5t583_gpio->gpio_chip); | ||
147 | } | ||
148 | |||
149 | static int rc5t583_gpio_remove(struct platform_device *pdev) | ||
150 | { | ||
151 | struct rc5t583_gpio *rc5t583_gpio = platform_get_drvdata(pdev); | ||
152 | |||
153 | return gpiochip_remove(&rc5t583_gpio->gpio_chip); | ||
154 | } | ||
155 | |||
156 | static struct platform_driver rc5t583_gpio_driver = { | ||
157 | .driver = { | ||
158 | .name = "rc5t583-gpio", | ||
159 | .owner = THIS_MODULE, | ||
160 | }, | ||
161 | .probe = rc5t583_gpio_probe, | ||
162 | .remove = rc5t583_gpio_remove, | ||
163 | }; | ||
164 | |||
165 | static int __init rc5t583_gpio_init(void) | ||
166 | { | ||
167 | return platform_driver_register(&rc5t583_gpio_driver); | ||
168 | } | ||
169 | subsys_initcall(rc5t583_gpio_init); | ||
170 | |||
171 | static void __exit rc5t583_gpio_exit(void) | ||
172 | { | ||
173 | platform_driver_unregister(&rc5t583_gpio_driver); | ||
174 | } | ||
175 | module_exit(rc5t583_gpio_exit); | ||
176 | |||
177 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | ||
178 | MODULE_DESCRIPTION("GPIO interface for RC5T583"); | ||
179 | MODULE_LICENSE("GPL v2"); | ||
180 | MODULE_ALIAS("platform:rc5t583-gpio"); | ||
diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c index 1bf55f67f7a..2762698e020 100644 --- a/drivers/gpio/gpio-rdc321x.c +++ b/drivers/gpio/gpio-rdc321x.c | |||
@@ -128,7 +128,7 @@ static int rdc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) | |||
128 | /* | 128 | /* |
129 | * Cache the initial value of both GPIO data registers | 129 | * Cache the initial value of both GPIO data registers |
130 | */ | 130 | */ |
131 | static int rdc321x_gpio_probe(struct platform_device *pdev) | 131 | static int __devinit rdc321x_gpio_probe(struct platform_device *pdev) |
132 | { | 132 | { |
133 | int err; | 133 | int err; |
134 | struct resource *r; | 134 | struct resource *r; |
@@ -170,7 +170,6 @@ static int rdc321x_gpio_probe(struct platform_device *pdev) | |||
170 | rdc321x_gpio_dev->reg2_data_base = r->start + 0x4; | 170 | rdc321x_gpio_dev->reg2_data_base = r->start + 0x4; |
171 | 171 | ||
172 | rdc321x_gpio_dev->chip.label = "rdc321x-gpio"; | 172 | rdc321x_gpio_dev->chip.label = "rdc321x-gpio"; |
173 | rdc321x_gpio_dev->chip.owner = THIS_MODULE; | ||
174 | rdc321x_gpio_dev->chip.direction_input = rdc_gpio_direction_input; | 173 | rdc321x_gpio_dev->chip.direction_input = rdc_gpio_direction_input; |
175 | rdc321x_gpio_dev->chip.direction_output = rdc_gpio_config; | 174 | rdc321x_gpio_dev->chip.direction_output = rdc_gpio_config; |
176 | rdc321x_gpio_dev->chip.get = rdc_gpio_get_value; | 175 | rdc321x_gpio_dev->chip.get = rdc_gpio_get_value; |
@@ -206,7 +205,7 @@ out_free: | |||
206 | return err; | 205 | return err; |
207 | } | 206 | } |
208 | 207 | ||
209 | static int rdc321x_gpio_remove(struct platform_device *pdev) | 208 | static int __devexit rdc321x_gpio_remove(struct platform_device *pdev) |
210 | { | 209 | { |
211 | int ret; | 210 | int ret; |
212 | struct rdc321x_gpio *rdc321x_gpio_dev = platform_get_drvdata(pdev); | 211 | struct rdc321x_gpio *rdc321x_gpio_dev = platform_get_drvdata(pdev); |
@@ -225,10 +224,21 @@ static struct platform_driver rdc321x_gpio_driver = { | |||
225 | .driver.name = "rdc321x-gpio", | 224 | .driver.name = "rdc321x-gpio", |
226 | .driver.owner = THIS_MODULE, | 225 | .driver.owner = THIS_MODULE, |
227 | .probe = rdc321x_gpio_probe, | 226 | .probe = rdc321x_gpio_probe, |
228 | .remove = rdc321x_gpio_remove, | 227 | .remove = __devexit_p(rdc321x_gpio_remove), |
229 | }; | 228 | }; |
230 | 229 | ||
231 | module_platform_driver(rdc321x_gpio_driver); | 230 | static int __init rdc321x_gpio_init(void) |
231 | { | ||
232 | return platform_driver_register(&rdc321x_gpio_driver); | ||
233 | } | ||
234 | |||
235 | static void __exit rdc321x_gpio_exit(void) | ||
236 | { | ||
237 | platform_driver_unregister(&rdc321x_gpio_driver); | ||
238 | } | ||
239 | |||
240 | module_init(rdc321x_gpio_init); | ||
241 | module_exit(rdc321x_gpio_exit); | ||
232 | 242 | ||
233 | MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>"); | 243 | MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>"); |
234 | MODULE_DESCRIPTION("RDC321x GPIO driver"); | 244 | MODULE_DESCRIPTION("RDC321x GPIO driver"); |
diff --git a/drivers/gpio/gpio-sa1100.c b/drivers/gpio/gpio-sa1100.c deleted file mode 100644 index 8ea3b33d4b4..00000000000 --- a/drivers/gpio/gpio-sa1100.c +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* | ||
2 | * linux/arch/arm/mach-sa1100/gpio.c | ||
3 | * | ||
4 | * Generic SA-1100 GPIO handling | ||
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 version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/gpio.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/module.h> | ||
13 | |||
14 | #include <mach/hardware.h> | ||
15 | #include <mach/irqs.h> | ||
16 | |||
17 | static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
18 | { | ||
19 | return GPLR & GPIO_GPIO(offset); | ||
20 | } | ||
21 | |||
22 | static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
23 | { | ||
24 | if (value) | ||
25 | GPSR = GPIO_GPIO(offset); | ||
26 | else | ||
27 | GPCR = GPIO_GPIO(offset); | ||
28 | } | ||
29 | |||
30 | static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset) | ||
31 | { | ||
32 | unsigned long flags; | ||
33 | |||
34 | local_irq_save(flags); | ||
35 | GPDR &= ~GPIO_GPIO(offset); | ||
36 | local_irq_restore(flags); | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int value) | ||
41 | { | ||
42 | unsigned long flags; | ||
43 | |||
44 | local_irq_save(flags); | ||
45 | sa1100_gpio_set(chip, offset, value); | ||
46 | GPDR |= GPIO_GPIO(offset); | ||
47 | local_irq_restore(flags); | ||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset) | ||
52 | { | ||
53 | return offset < 11 ? (IRQ_GPIO0 + offset) : (IRQ_GPIO11 - 11 + offset); | ||
54 | } | ||
55 | |||
56 | static struct gpio_chip sa1100_gpio_chip = { | ||
57 | .label = "gpio", | ||
58 | .direction_input = sa1100_direction_input, | ||
59 | .direction_output = sa1100_direction_output, | ||
60 | .set = sa1100_gpio_set, | ||
61 | .get = sa1100_gpio_get, | ||
62 | .to_irq = sa1100_to_irq, | ||
63 | .base = 0, | ||
64 | .ngpio = GPIO_MAX + 1, | ||
65 | }; | ||
66 | |||
67 | void __init sa1100_init_gpio(void) | ||
68 | { | ||
69 | gpiochip_add(&sa1100_gpio_chip); | ||
70 | } | ||
diff --git a/drivers/gpio/gpio-samsung.c b/drivers/gpio/gpio-samsung.c deleted file mode 100644 index 01f7fe95559..00000000000 --- a/drivers/gpio/gpio-samsung.c +++ /dev/null | |||
@@ -1,3284 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009-2011 Samsung Electronics Co., Ltd. | ||
3 | * http://www.samsung.com/ | ||
4 | * | ||
5 | * Copyright 2008 Openmoko, Inc. | ||
6 | * Copyright 2008 Simtec Electronics | ||
7 | * Ben Dooks <ben@simtec.co.uk> | ||
8 | * http://armlinux.simtec.co.uk/ | ||
9 | * | ||
10 | * SAMSUNG - GPIOlib support | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License version 2 as | ||
14 | * published by the Free Software Foundation. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/irq.h> | ||
19 | #include <linux/io.h> | ||
20 | #include <linux/gpio.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/ioport.h> | ||
27 | #include <linux/of.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/of_address.h> | ||
30 | |||
31 | #include <asm/irq.h> | ||
32 | |||
33 | #include <mach/hardware.h> | ||
34 | #include <mach/map.h> | ||
35 | #include <mach/regs-clock.h> | ||
36 | #include <mach/regs-gpio.h> | ||
37 | |||
38 | #include <plat/cpu.h> | ||
39 | #include <plat/gpio-core.h> | ||
40 | #include <plat/gpio-cfg.h> | ||
41 | #include <plat/gpio-cfg-helpers.h> | ||
42 | #include <plat/gpio-fns.h> | ||
43 | #include <plat/pm.h> | ||
44 | |||
45 | int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip, | ||
46 | unsigned int off, samsung_gpio_pull_t pull) | ||
47 | { | ||
48 | void __iomem *reg = chip->base + 0x08; | ||
49 | int shift = off * 2; | ||
50 | u32 pup; | ||
51 | |||
52 | pup = __raw_readl(reg); | ||
53 | pup &= ~(3 << shift); | ||
54 | pup |= pull << shift; | ||
55 | __raw_writel(pup, reg); | ||
56 | |||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip, | ||
61 | unsigned int off) | ||
62 | { | ||
63 | void __iomem *reg = chip->base + 0x08; | ||
64 | int shift = off * 2; | ||
65 | u32 pup = __raw_readl(reg); | ||
66 | |||
67 | pup >>= shift; | ||
68 | pup &= 0x3; | ||
69 | |||
70 | return (__force samsung_gpio_pull_t)pup; | ||
71 | } | ||
72 | |||
73 | int s3c2443_gpio_setpull(struct samsung_gpio_chip *chip, | ||
74 | unsigned int off, samsung_gpio_pull_t pull) | ||
75 | { | ||
76 | switch (pull) { | ||
77 | case S3C_GPIO_PULL_NONE: | ||
78 | pull = 0x01; | ||
79 | break; | ||
80 | case S3C_GPIO_PULL_UP: | ||
81 | pull = 0x00; | ||
82 | break; | ||
83 | case S3C_GPIO_PULL_DOWN: | ||
84 | pull = 0x02; | ||
85 | break; | ||
86 | } | ||
87 | return samsung_gpio_setpull_updown(chip, off, pull); | ||
88 | } | ||
89 | |||
90 | samsung_gpio_pull_t s3c2443_gpio_getpull(struct samsung_gpio_chip *chip, | ||
91 | unsigned int off) | ||
92 | { | ||
93 | samsung_gpio_pull_t pull; | ||
94 | |||
95 | pull = samsung_gpio_getpull_updown(chip, off); | ||
96 | |||
97 | switch (pull) { | ||
98 | case 0x00: | ||
99 | pull = S3C_GPIO_PULL_UP; | ||
100 | break; | ||
101 | case 0x01: | ||
102 | case 0x03: | ||
103 | pull = S3C_GPIO_PULL_NONE; | ||
104 | break; | ||
105 | case 0x02: | ||
106 | pull = S3C_GPIO_PULL_DOWN; | ||
107 | break; | ||
108 | } | ||
109 | |||
110 | return pull; | ||
111 | } | ||
112 | |||
113 | static int s3c24xx_gpio_setpull_1(struct samsung_gpio_chip *chip, | ||
114 | unsigned int off, samsung_gpio_pull_t pull, | ||
115 | samsung_gpio_pull_t updown) | ||
116 | { | ||
117 | void __iomem *reg = chip->base + 0x08; | ||
118 | u32 pup = __raw_readl(reg); | ||
119 | |||
120 | if (pull == updown) | ||
121 | pup &= ~(1 << off); | ||
122 | else if (pull == S3C_GPIO_PULL_NONE) | ||
123 | pup |= (1 << off); | ||
124 | else | ||
125 | return -EINVAL; | ||
126 | |||
127 | __raw_writel(pup, reg); | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | static samsung_gpio_pull_t s3c24xx_gpio_getpull_1(struct samsung_gpio_chip *chip, | ||
132 | unsigned int off, | ||
133 | samsung_gpio_pull_t updown) | ||
134 | { | ||
135 | void __iomem *reg = chip->base + 0x08; | ||
136 | u32 pup = __raw_readl(reg); | ||
137 | |||
138 | pup &= (1 << off); | ||
139 | return pup ? S3C_GPIO_PULL_NONE : updown; | ||
140 | } | ||
141 | |||
142 | samsung_gpio_pull_t s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip *chip, | ||
143 | unsigned int off) | ||
144 | { | ||
145 | return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_UP); | ||
146 | } | ||
147 | |||
148 | int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip *chip, | ||
149 | unsigned int off, samsung_gpio_pull_t pull) | ||
150 | { | ||
151 | return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_UP); | ||
152 | } | ||
153 | |||
154 | samsung_gpio_pull_t s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip *chip, | ||
155 | unsigned int off) | ||
156 | { | ||
157 | return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_DOWN); | ||
158 | } | ||
159 | |||
160 | int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip *chip, | ||
161 | unsigned int off, samsung_gpio_pull_t pull) | ||
162 | { | ||
163 | return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_DOWN); | ||
164 | } | ||
165 | |||
166 | static int exynos_gpio_setpull(struct samsung_gpio_chip *chip, | ||
167 | unsigned int off, samsung_gpio_pull_t pull) | ||
168 | { | ||
169 | if (pull == S3C_GPIO_PULL_UP) | ||
170 | pull = 3; | ||
171 | |||
172 | return samsung_gpio_setpull_updown(chip, off, pull); | ||
173 | } | ||
174 | |||
175 | static samsung_gpio_pull_t exynos_gpio_getpull(struct samsung_gpio_chip *chip, | ||
176 | unsigned int off) | ||
177 | { | ||
178 | samsung_gpio_pull_t pull; | ||
179 | |||
180 | pull = samsung_gpio_getpull_updown(chip, off); | ||
181 | |||
182 | if (pull == 3) | ||
183 | pull = S3C_GPIO_PULL_UP; | ||
184 | |||
185 | return pull; | ||
186 | } | ||
187 | |||
188 | /* | ||
189 | * samsung_gpio_setcfg_2bit - Samsung 2bit style GPIO configuration. | ||
190 | * @chip: The gpio chip that is being configured. | ||
191 | * @off: The offset for the GPIO being configured. | ||
192 | * @cfg: The configuration value to set. | ||
193 | * | ||
194 | * This helper deal with the GPIO cases where the control register | ||
195 | * has two bits of configuration per gpio, which have the following | ||
196 | * functions: | ||
197 | * 00 = input | ||
198 | * 01 = output | ||
199 | * 1x = special function | ||
200 | */ | ||
201 | |||
202 | static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip *chip, | ||
203 | unsigned int off, unsigned int cfg) | ||
204 | { | ||
205 | void __iomem *reg = chip->base; | ||
206 | unsigned int shift = off * 2; | ||
207 | u32 con; | ||
208 | |||
209 | if (samsung_gpio_is_cfg_special(cfg)) { | ||
210 | cfg &= 0xf; | ||
211 | if (cfg > 3) | ||
212 | return -EINVAL; | ||
213 | |||
214 | cfg <<= shift; | ||
215 | } | ||
216 | |||
217 | con = __raw_readl(reg); | ||
218 | con &= ~(0x3 << shift); | ||
219 | con |= cfg; | ||
220 | __raw_writel(con, reg); | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | /* | ||
226 | * samsung_gpio_getcfg_2bit - Samsung 2bit style GPIO configuration read. | ||
227 | * @chip: The gpio chip that is being configured. | ||
228 | * @off: The offset for the GPIO being configured. | ||
229 | * | ||
230 | * The reverse of samsung_gpio_setcfg_2bit(). Will return a value which | ||
231 | * could be directly passed back to samsung_gpio_setcfg_2bit(), from the | ||
232 | * S3C_GPIO_SPECIAL() macro. | ||
233 | */ | ||
234 | |||
235 | static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip *chip, | ||
236 | unsigned int off) | ||
237 | { | ||
238 | u32 con; | ||
239 | |||
240 | con = __raw_readl(chip->base); | ||
241 | con >>= off * 2; | ||
242 | con &= 3; | ||
243 | |||
244 | /* this conversion works for IN and OUT as well as special mode */ | ||
245 | return S3C_GPIO_SPECIAL(con); | ||
246 | } | ||
247 | |||
248 | /* | ||
249 | * samsung_gpio_setcfg_4bit - Samsung 4bit single register GPIO config. | ||
250 | * @chip: The gpio chip that is being configured. | ||
251 | * @off: The offset for the GPIO being configured. | ||
252 | * @cfg: The configuration value to set. | ||
253 | * | ||
254 | * This helper deal with the GPIO cases where the control register has 4 bits | ||
255 | * of control per GPIO, generally in the form of: | ||
256 | * 0000 = Input | ||
257 | * 0001 = Output | ||
258 | * others = Special functions (dependent on bank) | ||
259 | * | ||
260 | * Note, since the code to deal with the case where there are two control | ||
261 | * registers instead of one, we do not have a separate set of functions for | ||
262 | * each case. | ||
263 | */ | ||
264 | |||
265 | static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip *chip, | ||
266 | unsigned int off, unsigned int cfg) | ||
267 | { | ||
268 | void __iomem *reg = chip->base; | ||
269 | unsigned int shift = (off & 7) * 4; | ||
270 | u32 con; | ||
271 | |||
272 | if (off < 8 && chip->chip.ngpio > 8) | ||
273 | reg -= 4; | ||
274 | |||
275 | if (samsung_gpio_is_cfg_special(cfg)) { | ||
276 | cfg &= 0xf; | ||
277 | cfg <<= shift; | ||
278 | } | ||
279 | |||
280 | con = __raw_readl(reg); | ||
281 | con &= ~(0xf << shift); | ||
282 | con |= cfg; | ||
283 | __raw_writel(con, reg); | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | /* | ||
289 | * samsung_gpio_getcfg_4bit - Samsung 4bit single register GPIO config read. | ||
290 | * @chip: The gpio chip that is being configured. | ||
291 | * @off: The offset for the GPIO being configured. | ||
292 | * | ||
293 | * The reverse of samsung_gpio_setcfg_4bit(), turning a gpio configuration | ||
294 | * register setting into a value the software can use, such as could be passed | ||
295 | * to samsung_gpio_setcfg_4bit(). | ||
296 | * | ||
297 | * @sa samsung_gpio_getcfg_2bit | ||
298 | */ | ||
299 | |||
300 | static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip *chip, | ||
301 | unsigned int off) | ||
302 | { | ||
303 | void __iomem *reg = chip->base; | ||
304 | unsigned int shift = (off & 7) * 4; | ||
305 | u32 con; | ||
306 | |||
307 | if (off < 8 && chip->chip.ngpio > 8) | ||
308 | reg -= 4; | ||
309 | |||
310 | con = __raw_readl(reg); | ||
311 | con >>= shift; | ||
312 | con &= 0xf; | ||
313 | |||
314 | /* this conversion works for IN and OUT as well as special mode */ | ||
315 | return S3C_GPIO_SPECIAL(con); | ||
316 | } | ||
317 | |||
318 | #ifdef CONFIG_PLAT_S3C24XX | ||
319 | /* | ||
320 | * s3c24xx_gpio_setcfg_abank - S3C24XX style GPIO configuration (Bank A) | ||
321 | * @chip: The gpio chip that is being configured. | ||
322 | * @off: The offset for the GPIO being configured. | ||
323 | * @cfg: The configuration value to set. | ||
324 | * | ||
325 | * This helper deal with the GPIO cases where the control register | ||
326 | * has one bit of configuration for the gpio, where setting the bit | ||
327 | * means the pin is in special function mode and unset means output. | ||
328 | */ | ||
329 | |||
330 | static int s3c24xx_gpio_setcfg_abank(struct samsung_gpio_chip *chip, | ||
331 | unsigned int off, unsigned int cfg) | ||
332 | { | ||
333 | void __iomem *reg = chip->base; | ||
334 | unsigned int shift = off; | ||
335 | u32 con; | ||
336 | |||
337 | if (samsung_gpio_is_cfg_special(cfg)) { | ||
338 | cfg &= 0xf; | ||
339 | |||
340 | /* Map output to 0, and SFN2 to 1 */ | ||
341 | cfg -= 1; | ||
342 | if (cfg > 1) | ||
343 | return -EINVAL; | ||
344 | |||
345 | cfg <<= shift; | ||
346 | } | ||
347 | |||
348 | con = __raw_readl(reg); | ||
349 | con &= ~(0x1 << shift); | ||
350 | con |= cfg; | ||
351 | __raw_writel(con, reg); | ||
352 | |||
353 | return 0; | ||
354 | } | ||
355 | |||
356 | /* | ||
357 | * s3c24xx_gpio_getcfg_abank - S3C24XX style GPIO configuration read (Bank A) | ||
358 | * @chip: The gpio chip that is being configured. | ||
359 | * @off: The offset for the GPIO being configured. | ||
360 | * | ||
361 | * The reverse of s3c24xx_gpio_setcfg_abank() turning an GPIO into a usable | ||
362 | * GPIO configuration value. | ||
363 | * | ||
364 | * @sa samsung_gpio_getcfg_2bit | ||
365 | * @sa samsung_gpio_getcfg_4bit | ||
366 | */ | ||
367 | |||
368 | static unsigned s3c24xx_gpio_getcfg_abank(struct samsung_gpio_chip *chip, | ||
369 | unsigned int off) | ||
370 | { | ||
371 | u32 con; | ||
372 | |||
373 | con = __raw_readl(chip->base); | ||
374 | con >>= off; | ||
375 | con &= 1; | ||
376 | con++; | ||
377 | |||
378 | return S3C_GPIO_SFN(con); | ||
379 | } | ||
380 | #endif | ||
381 | |||
382 | #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450) | ||
383 | static int s5p64x0_gpio_setcfg_rbank(struct samsung_gpio_chip *chip, | ||
384 | unsigned int off, unsigned int cfg) | ||
385 | { | ||
386 | void __iomem *reg = chip->base; | ||
387 | unsigned int shift; | ||
388 | u32 con; | ||
389 | |||
390 | switch (off) { | ||
391 | case 0: | ||
392 | case 1: | ||
393 | case 2: | ||
394 | case 3: | ||
395 | case 4: | ||
396 | case 5: | ||
397 | shift = (off & 7) * 4; | ||
398 | reg -= 4; | ||
399 | break; | ||
400 | case 6: | ||
401 | shift = ((off + 1) & 7) * 4; | ||
402 | reg -= 4; | ||
403 | default: | ||
404 | shift = ((off + 1) & 7) * 4; | ||
405 | break; | ||
406 | } | ||
407 | |||
408 | if (samsung_gpio_is_cfg_special(cfg)) { | ||
409 | cfg &= 0xf; | ||
410 | cfg <<= shift; | ||
411 | } | ||
412 | |||
413 | con = __raw_readl(reg); | ||
414 | con &= ~(0xf << shift); | ||
415 | con |= cfg; | ||
416 | __raw_writel(con, reg); | ||
417 | |||
418 | return 0; | ||
419 | } | ||
420 | #endif | ||
421 | |||
422 | static void __init samsung_gpiolib_set_cfg(struct samsung_gpio_cfg *chipcfg, | ||
423 | int nr_chips) | ||
424 | { | ||
425 | for (; nr_chips > 0; nr_chips--, chipcfg++) { | ||
426 | if (!chipcfg->set_config) | ||
427 | chipcfg->set_config = samsung_gpio_setcfg_4bit; | ||
428 | if (!chipcfg->get_config) | ||
429 | chipcfg->get_config = samsung_gpio_getcfg_4bit; | ||
430 | if (!chipcfg->set_pull) | ||
431 | chipcfg->set_pull = samsung_gpio_setpull_updown; | ||
432 | if (!chipcfg->get_pull) | ||
433 | chipcfg->get_pull = samsung_gpio_getpull_updown; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | struct samsung_gpio_cfg s3c24xx_gpiocfg_default = { | ||
438 | .set_config = samsung_gpio_setcfg_2bit, | ||
439 | .get_config = samsung_gpio_getcfg_2bit, | ||
440 | }; | ||
441 | |||
442 | #ifdef CONFIG_PLAT_S3C24XX | ||
443 | static struct samsung_gpio_cfg s3c24xx_gpiocfg_banka = { | ||
444 | .set_config = s3c24xx_gpio_setcfg_abank, | ||
445 | .get_config = s3c24xx_gpio_getcfg_abank, | ||
446 | }; | ||
447 | #endif | ||
448 | |||
449 | #if defined(CONFIG_ARCH_EXYNOS4) || defined(CONFIG_ARCH_EXYNOS5) | ||
450 | static struct samsung_gpio_cfg exynos_gpio_cfg = { | ||
451 | .set_pull = exynos_gpio_setpull, | ||
452 | .get_pull = exynos_gpio_getpull, | ||
453 | .set_config = samsung_gpio_setcfg_4bit, | ||
454 | .get_config = samsung_gpio_getcfg_4bit, | ||
455 | }; | ||
456 | #endif | ||
457 | |||
458 | #if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450) | ||
459 | static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = { | ||
460 | .cfg_eint = 0x3, | ||
461 | .set_config = s5p64x0_gpio_setcfg_rbank, | ||
462 | .get_config = samsung_gpio_getcfg_4bit, | ||
463 | .set_pull = samsung_gpio_setpull_updown, | ||
464 | .get_pull = samsung_gpio_getpull_updown, | ||
465 | }; | ||
466 | #endif | ||
467 | |||
468 | static struct samsung_gpio_cfg samsung_gpio_cfgs[] = { | ||
469 | [0] = { | ||
470 | .cfg_eint = 0x0, | ||
471 | }, | ||
472 | [1] = { | ||
473 | .cfg_eint = 0x3, | ||
474 | }, | ||
475 | [2] = { | ||
476 | .cfg_eint = 0x7, | ||
477 | }, | ||
478 | [3] = { | ||
479 | .cfg_eint = 0xF, | ||
480 | }, | ||
481 | [4] = { | ||
482 | .cfg_eint = 0x0, | ||
483 | .set_config = samsung_gpio_setcfg_2bit, | ||
484 | .get_config = samsung_gpio_getcfg_2bit, | ||
485 | }, | ||
486 | [5] = { | ||
487 | .cfg_eint = 0x2, | ||
488 | .set_config = samsung_gpio_setcfg_2bit, | ||
489 | .get_config = samsung_gpio_getcfg_2bit, | ||
490 | }, | ||
491 | [6] = { | ||
492 | .cfg_eint = 0x3, | ||
493 | .set_config = samsung_gpio_setcfg_2bit, | ||
494 | .get_config = samsung_gpio_getcfg_2bit, | ||
495 | }, | ||
496 | [7] = { | ||
497 | .set_config = samsung_gpio_setcfg_2bit, | ||
498 | .get_config = samsung_gpio_getcfg_2bit, | ||
499 | }, | ||
500 | [8] = { | ||
501 | .set_pull = exynos_gpio_setpull, | ||
502 | .get_pull = exynos_gpio_getpull, | ||
503 | }, | ||
504 | [9] = { | ||
505 | .cfg_eint = 0x3, | ||
506 | .set_pull = exynos_gpio_setpull, | ||
507 | .get_pull = exynos_gpio_getpull, | ||
508 | } | ||
509 | }; | ||
510 | |||
511 | /* | ||
512 | * Default routines for controlling GPIO, based on the original S3C24XX | ||
513 | * GPIO functions which deal with the case where each gpio bank of the | ||
514 | * chip is as following: | ||
515 | * | ||
516 | * base + 0x00: Control register, 2 bits per gpio | ||
517 | * gpio n: 2 bits starting at (2*n) | ||
518 | * 00 = input, 01 = output, others mean special-function | ||
519 | * base + 0x04: Data register, 1 bit per gpio | ||
520 | * bit n: data bit n | ||
521 | */ | ||
522 | |||
523 | static int samsung_gpiolib_2bit_input(struct gpio_chip *chip, unsigned offset) | ||
524 | { | ||
525 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
526 | void __iomem *base = ourchip->base; | ||
527 | unsigned long flags; | ||
528 | unsigned long con; | ||
529 | |||
530 | samsung_gpio_lock(ourchip, flags); | ||
531 | |||
532 | con = __raw_readl(base + 0x00); | ||
533 | con &= ~(3 << (offset * 2)); | ||
534 | |||
535 | __raw_writel(con, base + 0x00); | ||
536 | |||
537 | samsung_gpio_unlock(ourchip, flags); | ||
538 | return 0; | ||
539 | } | ||
540 | |||
541 | static int samsung_gpiolib_2bit_output(struct gpio_chip *chip, | ||
542 | unsigned offset, int value) | ||
543 | { | ||
544 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
545 | void __iomem *base = ourchip->base; | ||
546 | unsigned long flags; | ||
547 | unsigned long dat; | ||
548 | unsigned long con; | ||
549 | |||
550 | samsung_gpio_lock(ourchip, flags); | ||
551 | |||
552 | dat = __raw_readl(base + 0x04); | ||
553 | dat &= ~(1 << offset); | ||
554 | if (value) | ||
555 | dat |= 1 << offset; | ||
556 | __raw_writel(dat, base + 0x04); | ||
557 | |||
558 | con = __raw_readl(base + 0x00); | ||
559 | con &= ~(3 << (offset * 2)); | ||
560 | con |= 1 << (offset * 2); | ||
561 | |||
562 | __raw_writel(con, base + 0x00); | ||
563 | __raw_writel(dat, base + 0x04); | ||
564 | |||
565 | samsung_gpio_unlock(ourchip, flags); | ||
566 | return 0; | ||
567 | } | ||
568 | |||
569 | /* | ||
570 | * The samsung_gpiolib_4bit routines are to control the gpio banks where | ||
571 | * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the | ||
572 | * following example: | ||
573 | * | ||
574 | * base + 0x00: Control register, 4 bits per gpio | ||
575 | * gpio n: 4 bits starting at (4*n) | ||
576 | * 0000 = input, 0001 = output, others mean special-function | ||
577 | * base + 0x04: Data register, 1 bit per gpio | ||
578 | * bit n: data bit n | ||
579 | * | ||
580 | * Note, since the data register is one bit per gpio and is at base + 0x4 | ||
581 | * we can use samsung_gpiolib_get and samsung_gpiolib_set to change the | ||
582 | * state of the output. | ||
583 | */ | ||
584 | |||
585 | static int samsung_gpiolib_4bit_input(struct gpio_chip *chip, | ||
586 | unsigned int offset) | ||
587 | { | ||
588 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
589 | void __iomem *base = ourchip->base; | ||
590 | unsigned long con; | ||
591 | |||
592 | con = __raw_readl(base + GPIOCON_OFF); | ||
593 | if (ourchip->bitmap_gpio_int & BIT(offset)) | ||
594 | con |= 0xf << con_4bit_shift(offset); | ||
595 | else | ||
596 | con &= ~(0xf << con_4bit_shift(offset)); | ||
597 | __raw_writel(con, base + GPIOCON_OFF); | ||
598 | |||
599 | pr_debug("%s: %p: CON now %08lx\n", __func__, base, con); | ||
600 | |||
601 | return 0; | ||
602 | } | ||
603 | |||
604 | static int samsung_gpiolib_4bit_output(struct gpio_chip *chip, | ||
605 | unsigned int offset, int value) | ||
606 | { | ||
607 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
608 | void __iomem *base = ourchip->base; | ||
609 | unsigned long con; | ||
610 | unsigned long dat; | ||
611 | |||
612 | con = __raw_readl(base + GPIOCON_OFF); | ||
613 | con &= ~(0xf << con_4bit_shift(offset)); | ||
614 | con |= 0x1 << con_4bit_shift(offset); | ||
615 | |||
616 | dat = __raw_readl(base + GPIODAT_OFF); | ||
617 | |||
618 | if (value) | ||
619 | dat |= 1 << offset; | ||
620 | else | ||
621 | dat &= ~(1 << offset); | ||
622 | |||
623 | __raw_writel(dat, base + GPIODAT_OFF); | ||
624 | __raw_writel(con, base + GPIOCON_OFF); | ||
625 | __raw_writel(dat, base + GPIODAT_OFF); | ||
626 | |||
627 | pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat); | ||
628 | |||
629 | return 0; | ||
630 | } | ||
631 | |||
632 | /* | ||
633 | * The next set of routines are for the case where the GPIO configuration | ||
634 | * registers are 4 bits per GPIO but there is more than one register (the | ||
635 | * bank has more than 8 GPIOs. | ||
636 | * | ||
637 | * This case is the similar to the 4 bit case, but the registers are as | ||
638 | * follows: | ||
639 | * | ||
640 | * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs) | ||
641 | * gpio n: 4 bits starting at (4*n) | ||
642 | * 0000 = input, 0001 = output, others mean special-function | ||
643 | * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs) | ||
644 | * gpio n: 4 bits starting at (4*n) | ||
645 | * 0000 = input, 0001 = output, others mean special-function | ||
646 | * base + 0x08: Data register, 1 bit per gpio | ||
647 | * bit n: data bit n | ||
648 | * | ||
649 | * To allow us to use the samsung_gpiolib_get and samsung_gpiolib_set | ||
650 | * routines we store the 'base + 0x4' address so that these routines see | ||
651 | * the data register at ourchip->base + 0x04. | ||
652 | */ | ||
653 | |||
654 | static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip, | ||
655 | unsigned int offset) | ||
656 | { | ||
657 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
658 | void __iomem *base = ourchip->base; | ||
659 | void __iomem *regcon = base; | ||
660 | unsigned long con; | ||
661 | |||
662 | if (offset > 7) | ||
663 | offset -= 8; | ||
664 | else | ||
665 | regcon -= 4; | ||
666 | |||
667 | con = __raw_readl(regcon); | ||
668 | con &= ~(0xf << con_4bit_shift(offset)); | ||
669 | __raw_writel(con, regcon); | ||
670 | |||
671 | pr_debug("%s: %p: CON %08lx\n", __func__, base, con); | ||
672 | |||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip, | ||
677 | unsigned int offset, int value) | ||
678 | { | ||
679 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
680 | void __iomem *base = ourchip->base; | ||
681 | void __iomem *regcon = base; | ||
682 | unsigned long con; | ||
683 | unsigned long dat; | ||
684 | unsigned con_offset = offset; | ||
685 | |||
686 | if (con_offset > 7) | ||
687 | con_offset -= 8; | ||
688 | else | ||
689 | regcon -= 4; | ||
690 | |||
691 | con = __raw_readl(regcon); | ||
692 | con &= ~(0xf << con_4bit_shift(con_offset)); | ||
693 | con |= 0x1 << con_4bit_shift(con_offset); | ||
694 | |||
695 | dat = __raw_readl(base + GPIODAT_OFF); | ||
696 | |||
697 | if (value) | ||
698 | dat |= 1 << offset; | ||
699 | else | ||
700 | dat &= ~(1 << offset); | ||
701 | |||
702 | __raw_writel(dat, base + GPIODAT_OFF); | ||
703 | __raw_writel(con, regcon); | ||
704 | __raw_writel(dat, base + GPIODAT_OFF); | ||
705 | |||
706 | pr_debug("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat); | ||
707 | |||
708 | return 0; | ||
709 | } | ||
710 | |||
711 | #ifdef CONFIG_PLAT_S3C24XX | ||
712 | /* The next set of routines are for the case of s3c24xx bank a */ | ||
713 | |||
714 | static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset) | ||
715 | { | ||
716 | return -EINVAL; | ||
717 | } | ||
718 | |||
719 | static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip, | ||
720 | unsigned offset, int value) | ||
721 | { | ||
722 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
723 | void __iomem *base = ourchip->base; | ||
724 | unsigned long flags; | ||
725 | unsigned long dat; | ||
726 | unsigned long con; | ||
727 | |||
728 | local_irq_save(flags); | ||
729 | |||
730 | con = __raw_readl(base + 0x00); | ||
731 | dat = __raw_readl(base + 0x04); | ||
732 | |||
733 | dat &= ~(1 << offset); | ||
734 | if (value) | ||
735 | dat |= 1 << offset; | ||
736 | |||
737 | __raw_writel(dat, base + 0x04); | ||
738 | |||
739 | con &= ~(1 << offset); | ||
740 | |||
741 | __raw_writel(con, base + 0x00); | ||
742 | __raw_writel(dat, base + 0x04); | ||
743 | |||
744 | local_irq_restore(flags); | ||
745 | return 0; | ||
746 | } | ||
747 | #endif | ||
748 | |||
749 | /* The next set of routines are for the case of s5p64x0 bank r */ | ||
750 | |||
751 | static int s5p64x0_gpiolib_rbank_input(struct gpio_chip *chip, | ||
752 | unsigned int offset) | ||
753 | { | ||
754 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
755 | void __iomem *base = ourchip->base; | ||
756 | void __iomem *regcon = base; | ||
757 | unsigned long con; | ||
758 | unsigned long flags; | ||
759 | |||
760 | switch (offset) { | ||
761 | case 6: | ||
762 | offset += 1; | ||
763 | case 0: | ||
764 | case 1: | ||
765 | case 2: | ||
766 | case 3: | ||
767 | case 4: | ||
768 | case 5: | ||
769 | regcon -= 4; | ||
770 | break; | ||
771 | default: | ||
772 | offset -= 7; | ||
773 | break; | ||
774 | } | ||
775 | |||
776 | samsung_gpio_lock(ourchip, flags); | ||
777 | |||
778 | con = __raw_readl(regcon); | ||
779 | con &= ~(0xf << con_4bit_shift(offset)); | ||
780 | __raw_writel(con, regcon); | ||
781 | |||
782 | samsung_gpio_unlock(ourchip, flags); | ||
783 | |||
784 | return 0; | ||
785 | } | ||
786 | |||
787 | static int s5p64x0_gpiolib_rbank_output(struct gpio_chip *chip, | ||
788 | unsigned int offset, int value) | ||
789 | { | ||
790 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
791 | void __iomem *base = ourchip->base; | ||
792 | void __iomem *regcon = base; | ||
793 | unsigned long con; | ||
794 | unsigned long dat; | ||
795 | unsigned long flags; | ||
796 | unsigned con_offset = offset; | ||
797 | |||
798 | switch (con_offset) { | ||
799 | case 6: | ||
800 | con_offset += 1; | ||
801 | case 0: | ||
802 | case 1: | ||
803 | case 2: | ||
804 | case 3: | ||
805 | case 4: | ||
806 | case 5: | ||
807 | regcon -= 4; | ||
808 | break; | ||
809 | default: | ||
810 | con_offset -= 7; | ||
811 | break; | ||
812 | } | ||
813 | |||
814 | samsung_gpio_lock(ourchip, flags); | ||
815 | |||
816 | con = __raw_readl(regcon); | ||
817 | con &= ~(0xf << con_4bit_shift(con_offset)); | ||
818 | con |= 0x1 << con_4bit_shift(con_offset); | ||
819 | |||
820 | dat = __raw_readl(base + GPIODAT_OFF); | ||
821 | if (value) | ||
822 | dat |= 1 << offset; | ||
823 | else | ||
824 | dat &= ~(1 << offset); | ||
825 | |||
826 | __raw_writel(con, regcon); | ||
827 | __raw_writel(dat, base + GPIODAT_OFF); | ||
828 | |||
829 | samsung_gpio_unlock(ourchip, flags); | ||
830 | |||
831 | return 0; | ||
832 | } | ||
833 | |||
834 | static void samsung_gpiolib_set(struct gpio_chip *chip, | ||
835 | unsigned offset, int value) | ||
836 | { | ||
837 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
838 | void __iomem *base = ourchip->base; | ||
839 | unsigned long flags; | ||
840 | unsigned long dat; | ||
841 | |||
842 | samsung_gpio_lock(ourchip, flags); | ||
843 | |||
844 | dat = __raw_readl(base + 0x04); | ||
845 | dat &= ~(1 << offset); | ||
846 | if (value) | ||
847 | dat |= 1 << offset; | ||
848 | __raw_writel(dat, base + 0x04); | ||
849 | |||
850 | samsung_gpio_unlock(ourchip, flags); | ||
851 | } | ||
852 | |||
853 | static int samsung_gpiolib_get(struct gpio_chip *chip, unsigned offset) | ||
854 | { | ||
855 | struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip); | ||
856 | unsigned long val; | ||
857 | |||
858 | val = __raw_readl(ourchip->base + 0x04); | ||
859 | val >>= offset; | ||
860 | val &= 1; | ||
861 | |||
862 | return val; | ||
863 | } | ||
864 | |||
865 | /* | ||
866 | * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios | ||
867 | * for use with the configuration calls, and other parts of the s3c gpiolib | ||
868 | * support code. | ||
869 | * | ||
870 | * Not all s3c support code will need this, as some configurations of cpu | ||
871 | * may only support one or two different configuration options and have an | ||
872 | * easy gpio to samsung_gpio_chip mapping function. If this is the case, then | ||
873 | * the machine support file should provide its own samsung_gpiolib_getchip() | ||
874 | * and any other necessary functions. | ||
875 | */ | ||
876 | |||
877 | #ifdef CONFIG_S3C_GPIO_TRACK | ||
878 | struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END]; | ||
879 | |||
880 | static __init void s3c_gpiolib_track(struct samsung_gpio_chip *chip) | ||
881 | { | ||
882 | unsigned int gpn; | ||
883 | int i; | ||
884 | |||
885 | gpn = chip->chip.base; | ||
886 | for (i = 0; i < chip->chip.ngpio; i++, gpn++) { | ||
887 | BUG_ON(gpn >= ARRAY_SIZE(s3c_gpios)); | ||
888 | s3c_gpios[gpn] = chip; | ||
889 | } | ||
890 | } | ||
891 | #endif /* CONFIG_S3C_GPIO_TRACK */ | ||
892 | |||
893 | /* | ||
894 | * samsung_gpiolib_add() - add the Samsung gpio_chip. | ||
895 | * @chip: The chip to register | ||
896 | * | ||
897 | * This is a wrapper to gpiochip_add() that takes our specific gpio chip | ||
898 | * information and makes the necessary alterations for the platform and | ||
899 | * notes the information for use with the configuration systems and any | ||
900 | * other parts of the system. | ||
901 | */ | ||
902 | |||
903 | static void __init samsung_gpiolib_add(struct samsung_gpio_chip *chip) | ||
904 | { | ||
905 | struct gpio_chip *gc = &chip->chip; | ||
906 | int ret; | ||
907 | |||
908 | BUG_ON(!chip->base); | ||
909 | BUG_ON(!gc->label); | ||
910 | BUG_ON(!gc->ngpio); | ||
911 | |||
912 | spin_lock_init(&chip->lock); | ||
913 | |||
914 | if (!gc->direction_input) | ||
915 | gc->direction_input = samsung_gpiolib_2bit_input; | ||
916 | if (!gc->direction_output) | ||
917 | gc->direction_output = samsung_gpiolib_2bit_output; | ||
918 | if (!gc->set) | ||
919 | gc->set = samsung_gpiolib_set; | ||
920 | if (!gc->get) | ||
921 | gc->get = samsung_gpiolib_get; | ||
922 | |||
923 | #ifdef CONFIG_PM | ||
924 | if (chip->pm != NULL) { | ||
925 | if (!chip->pm->save || !chip->pm->resume) | ||
926 | pr_err("gpio: %s has missing PM functions\n", | ||
927 | gc->label); | ||
928 | } else | ||
929 | pr_err("gpio: %s has no PM function\n", gc->label); | ||
930 | #endif | ||
931 | |||
932 | /* gpiochip_add() prints own failure message on error. */ | ||
933 | ret = gpiochip_add(gc); | ||
934 | if (ret >= 0) | ||
935 | s3c_gpiolib_track(chip); | ||
936 | } | ||
937 | |||
938 | #if defined(CONFIG_PLAT_S3C24XX) && defined(CONFIG_OF) | ||
939 | static int s3c24xx_gpio_xlate(struct gpio_chip *gc, | ||
940 | const struct of_phandle_args *gpiospec, u32 *flags) | ||
941 | { | ||
942 | unsigned int pin; | ||
943 | |||
944 | if (WARN_ON(gc->of_gpio_n_cells < 3)) | ||
945 | return -EINVAL; | ||
946 | |||
947 | if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) | ||
948 | return -EINVAL; | ||
949 | |||
950 | if (gpiospec->args[0] > gc->ngpio) | ||
951 | return -EINVAL; | ||
952 | |||
953 | pin = gc->base + gpiospec->args[0]; | ||
954 | |||
955 | if (s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(gpiospec->args[1]))) | ||
956 | pr_warn("gpio_xlate: failed to set pin function\n"); | ||
957 | if (s3c_gpio_setpull(pin, gpiospec->args[2] & 0xffff)) | ||
958 | pr_warn("gpio_xlate: failed to set pin pull up/down\n"); | ||
959 | |||
960 | if (flags) | ||
961 | *flags = gpiospec->args[2] >> 16; | ||
962 | |||
963 | return gpiospec->args[0]; | ||
964 | } | ||
965 | |||
966 | static const struct of_device_id s3c24xx_gpio_dt_match[] __initdata = { | ||
967 | { .compatible = "samsung,s3c24xx-gpio", }, | ||
968 | {} | ||
969 | }; | ||
970 | |||
971 | static __init void s3c24xx_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip, | ||
972 | u64 base, u64 offset) | ||
973 | { | ||
974 | struct gpio_chip *gc = &chip->chip; | ||
975 | u64 address; | ||
976 | |||
977 | if (!of_have_populated_dt()) | ||
978 | return; | ||
979 | |||
980 | address = chip->base ? base + ((u32)chip->base & 0xfff) : base + offset; | ||
981 | gc->of_node = of_find_matching_node_by_address(NULL, | ||
982 | s3c24xx_gpio_dt_match, address); | ||
983 | if (!gc->of_node) { | ||
984 | pr_info("gpio: device tree node not found for gpio controller" | ||
985 | " with base address %08llx\n", address); | ||
986 | return; | ||
987 | } | ||
988 | gc->of_gpio_n_cells = 3; | ||
989 | gc->of_xlate = s3c24xx_gpio_xlate; | ||
990 | } | ||
991 | #else | ||
992 | static __init void s3c24xx_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip, | ||
993 | u64 base, u64 offset) | ||
994 | { | ||
995 | return; | ||
996 | } | ||
997 | #endif /* defined(CONFIG_PLAT_S3C24XX) && defined(CONFIG_OF) */ | ||
998 | |||
999 | static void __init s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip *chip, | ||
1000 | int nr_chips, void __iomem *base) | ||
1001 | { | ||
1002 | int i; | ||
1003 | struct gpio_chip *gc = &chip->chip; | ||
1004 | |||
1005 | for (i = 0 ; i < nr_chips; i++, chip++) { | ||
1006 | /* skip banks not present on SoC */ | ||
1007 | if (chip->chip.base >= S3C_GPIO_END) | ||
1008 | continue; | ||
1009 | |||
1010 | if (!chip->config) | ||
1011 | chip->config = &s3c24xx_gpiocfg_default; | ||
1012 | if (!chip->pm) | ||
1013 | chip->pm = __gpio_pm(&samsung_gpio_pm_2bit); | ||
1014 | if ((base != NULL) && (chip->base == NULL)) | ||
1015 | chip->base = base + ((i) * 0x10); | ||
1016 | |||
1017 | if (!gc->direction_input) | ||
1018 | gc->direction_input = samsung_gpiolib_2bit_input; | ||
1019 | if (!gc->direction_output) | ||
1020 | gc->direction_output = samsung_gpiolib_2bit_output; | ||
1021 | |||
1022 | samsung_gpiolib_add(chip); | ||
1023 | |||
1024 | s3c24xx_gpiolib_attach_ofnode(chip, S3C24XX_PA_GPIO, i * 0x10); | ||
1025 | } | ||
1026 | } | ||
1027 | |||
1028 | static void __init samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip *chip, | ||
1029 | int nr_chips, void __iomem *base, | ||
1030 | unsigned int offset) | ||
1031 | { | ||
1032 | int i; | ||
1033 | |||
1034 | for (i = 0 ; i < nr_chips; i++, chip++) { | ||
1035 | chip->chip.direction_input = samsung_gpiolib_2bit_input; | ||
1036 | chip->chip.direction_output = samsung_gpiolib_2bit_output; | ||
1037 | |||
1038 | if (!chip->config) | ||
1039 | chip->config = &samsung_gpio_cfgs[7]; | ||
1040 | if (!chip->pm) | ||
1041 | chip->pm = __gpio_pm(&samsung_gpio_pm_2bit); | ||
1042 | if ((base != NULL) && (chip->base == NULL)) | ||
1043 | chip->base = base + ((i) * offset); | ||
1044 | |||
1045 | samsung_gpiolib_add(chip); | ||
1046 | } | ||
1047 | } | ||
1048 | |||
1049 | /* | ||
1050 | * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config. | ||
1051 | * @chip: The gpio chip that is being configured. | ||
1052 | * @nr_chips: The no of chips (gpio ports) for the GPIO being configured. | ||
1053 | * | ||
1054 | * This helper deal with the GPIO cases where the control register has 4 bits | ||
1055 | * of control per GPIO, generally in the form of: | ||
1056 | * 0000 = Input | ||
1057 | * 0001 = Output | ||
1058 | * others = Special functions (dependent on bank) | ||
1059 | * | ||
1060 | * Note, since the code to deal with the case where there are two control | ||
1061 | * registers instead of one, we do not have a separate set of function | ||
1062 | * (samsung_gpiolib_add_4bit2_chips)for each case. | ||
1063 | */ | ||
1064 | |||
1065 | static void __init samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip *chip, | ||
1066 | int nr_chips, void __iomem *base) | ||
1067 | { | ||
1068 | int i; | ||
1069 | |||
1070 | for (i = 0 ; i < nr_chips; i++, chip++) { | ||
1071 | chip->chip.direction_input = samsung_gpiolib_4bit_input; | ||
1072 | chip->chip.direction_output = samsung_gpiolib_4bit_output; | ||
1073 | |||
1074 | if (!chip->config) | ||
1075 | chip->config = &samsung_gpio_cfgs[2]; | ||
1076 | if (!chip->pm) | ||
1077 | chip->pm = __gpio_pm(&samsung_gpio_pm_4bit); | ||
1078 | if ((base != NULL) && (chip->base == NULL)) | ||
1079 | chip->base = base + ((i) * 0x20); | ||
1080 | |||
1081 | chip->bitmap_gpio_int = 0; | ||
1082 | |||
1083 | samsung_gpiolib_add(chip); | ||
1084 | } | ||
1085 | } | ||
1086 | |||
1087 | static void __init samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip *chip, | ||
1088 | int nr_chips) | ||
1089 | { | ||
1090 | for (; nr_chips > 0; nr_chips--, chip++) { | ||
1091 | chip->chip.direction_input = samsung_gpiolib_4bit2_input; | ||
1092 | chip->chip.direction_output = samsung_gpiolib_4bit2_output; | ||
1093 | |||
1094 | if (!chip->config) | ||
1095 | chip->config = &samsung_gpio_cfgs[2]; | ||
1096 | if (!chip->pm) | ||
1097 | chip->pm = __gpio_pm(&samsung_gpio_pm_4bit); | ||
1098 | |||
1099 | samsung_gpiolib_add(chip); | ||
1100 | } | ||
1101 | } | ||
1102 | |||
1103 | static void __init s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip *chip, | ||
1104 | int nr_chips) | ||
1105 | { | ||
1106 | for (; nr_chips > 0; nr_chips--, chip++) { | ||
1107 | chip->chip.direction_input = s5p64x0_gpiolib_rbank_input; | ||
1108 | chip->chip.direction_output = s5p64x0_gpiolib_rbank_output; | ||
1109 | |||
1110 | if (!chip->pm) | ||
1111 | chip->pm = __gpio_pm(&samsung_gpio_pm_4bit); | ||
1112 | |||
1113 | samsung_gpiolib_add(chip); | ||
1114 | } | ||
1115 | } | ||
1116 | |||
1117 | int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset) | ||
1118 | { | ||
1119 | struct samsung_gpio_chip *samsung_chip = container_of(chip, struct samsung_gpio_chip, chip); | ||
1120 | |||
1121 | return samsung_chip->irq_base + offset; | ||
1122 | } | ||
1123 | |||
1124 | #ifdef CONFIG_PLAT_S3C24XX | ||
1125 | static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset) | ||
1126 | { | ||
1127 | if (offset < 4) | ||
1128 | return IRQ_EINT0 + offset; | ||
1129 | |||
1130 | if (offset < 8) | ||
1131 | return IRQ_EINT4 + offset - 4; | ||
1132 | |||
1133 | return -EINVAL; | ||
1134 | } | ||
1135 | #endif | ||
1136 | |||
1137 | #ifdef CONFIG_PLAT_S3C64XX | ||
1138 | static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin) | ||
1139 | { | ||
1140 | return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO; | ||
1141 | } | ||
1142 | |||
1143 | static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin) | ||
1144 | { | ||
1145 | return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO; | ||
1146 | } | ||
1147 | #endif | ||
1148 | |||
1149 | struct samsung_gpio_chip s3c24xx_gpios[] = { | ||
1150 | #ifdef CONFIG_PLAT_S3C24XX | ||
1151 | { | ||
1152 | .config = &s3c24xx_gpiocfg_banka, | ||
1153 | .chip = { | ||
1154 | .base = S3C2410_GPA(0), | ||
1155 | .owner = THIS_MODULE, | ||
1156 | .label = "GPIOA", | ||
1157 | .ngpio = 24, | ||
1158 | .direction_input = s3c24xx_gpiolib_banka_input, | ||
1159 | .direction_output = s3c24xx_gpiolib_banka_output, | ||
1160 | }, | ||
1161 | }, { | ||
1162 | .chip = { | ||
1163 | .base = S3C2410_GPB(0), | ||
1164 | .owner = THIS_MODULE, | ||
1165 | .label = "GPIOB", | ||
1166 | .ngpio = 16, | ||
1167 | }, | ||
1168 | }, { | ||
1169 | .chip = { | ||
1170 | .base = S3C2410_GPC(0), | ||
1171 | .owner = THIS_MODULE, | ||
1172 | .label = "GPIOC", | ||
1173 | .ngpio = 16, | ||
1174 | }, | ||
1175 | }, { | ||
1176 | .chip = { | ||
1177 | .base = S3C2410_GPD(0), | ||
1178 | .owner = THIS_MODULE, | ||
1179 | .label = "GPIOD", | ||
1180 | .ngpio = 16, | ||
1181 | }, | ||
1182 | }, { | ||
1183 | .chip = { | ||
1184 | .base = S3C2410_GPE(0), | ||
1185 | .label = "GPIOE", | ||
1186 | .owner = THIS_MODULE, | ||
1187 | .ngpio = 16, | ||
1188 | }, | ||
1189 | }, { | ||
1190 | .chip = { | ||
1191 | .base = S3C2410_GPF(0), | ||
1192 | .owner = THIS_MODULE, | ||
1193 | .label = "GPIOF", | ||
1194 | .ngpio = 8, | ||
1195 | .to_irq = s3c24xx_gpiolib_fbank_to_irq, | ||
1196 | }, | ||
1197 | }, { | ||
1198 | .irq_base = IRQ_EINT8, | ||
1199 | .chip = { | ||
1200 | .base = S3C2410_GPG(0), | ||
1201 | .owner = THIS_MODULE, | ||
1202 | .label = "GPIOG", | ||
1203 | .ngpio = 16, | ||
1204 | .to_irq = samsung_gpiolib_to_irq, | ||
1205 | }, | ||
1206 | }, { | ||
1207 | .chip = { | ||
1208 | .base = S3C2410_GPH(0), | ||
1209 | .owner = THIS_MODULE, | ||
1210 | .label = "GPIOH", | ||
1211 | .ngpio = 11, | ||
1212 | }, | ||
1213 | }, | ||
1214 | /* GPIOS for the S3C2443 and later devices. */ | ||
1215 | { | ||
1216 | .base = S3C2440_GPJCON, | ||
1217 | .chip = { | ||
1218 | .base = S3C2410_GPJ(0), | ||
1219 | .owner = THIS_MODULE, | ||
1220 | .label = "GPIOJ", | ||
1221 | .ngpio = 16, | ||
1222 | }, | ||
1223 | }, { | ||
1224 | .base = S3C2443_GPKCON, | ||
1225 | .chip = { | ||
1226 | .base = S3C2410_GPK(0), | ||
1227 | .owner = THIS_MODULE, | ||
1228 | .label = "GPIOK", | ||
1229 | .ngpio = 16, | ||
1230 | }, | ||
1231 | }, { | ||
1232 | .base = S3C2443_GPLCON, | ||
1233 | .chip = { | ||
1234 | .base = S3C2410_GPL(0), | ||
1235 | .owner = THIS_MODULE, | ||
1236 | .label = "GPIOL", | ||
1237 | .ngpio = 15, | ||
1238 | }, | ||
1239 | }, { | ||
1240 | .base = S3C2443_GPMCON, | ||
1241 | .chip = { | ||
1242 | .base = S3C2410_GPM(0), | ||
1243 | .owner = THIS_MODULE, | ||
1244 | .label = "GPIOM", | ||
1245 | .ngpio = 2, | ||
1246 | }, | ||
1247 | }, | ||
1248 | #endif | ||
1249 | }; | ||
1250 | |||
1251 | /* | ||
1252 | * GPIO bank summary: | ||
1253 | * | ||
1254 | * Bank GPIOs Style SlpCon ExtInt Group | ||
1255 | * A 8 4Bit Yes 1 | ||
1256 | * B 7 4Bit Yes 1 | ||
1257 | * C 8 4Bit Yes 2 | ||
1258 | * D 5 4Bit Yes 3 | ||
1259 | * E 5 4Bit Yes None | ||
1260 | * F 16 2Bit Yes 4 [1] | ||
1261 | * G 7 4Bit Yes 5 | ||
1262 | * H 10 4Bit[2] Yes 6 | ||
1263 | * I 16 2Bit Yes None | ||
1264 | * J 12 2Bit Yes None | ||
1265 | * K 16 4Bit[2] No None | ||
1266 | * L 15 4Bit[2] No None | ||
1267 | * M 6 4Bit No IRQ_EINT | ||
1268 | * N 16 2Bit No IRQ_EINT | ||
1269 | * O 16 2Bit Yes 7 | ||
1270 | * P 15 2Bit Yes 8 | ||
1271 | * Q 9 2Bit Yes 9 | ||
1272 | * | ||
1273 | * [1] BANKF pins 14,15 do not form part of the external interrupt sources | ||
1274 | * [2] BANK has two control registers, GPxCON0 and GPxCON1 | ||
1275 | */ | ||
1276 | |||
1277 | static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = { | ||
1278 | #ifdef CONFIG_PLAT_S3C64XX | ||
1279 | { | ||
1280 | .chip = { | ||
1281 | .base = S3C64XX_GPA(0), | ||
1282 | .ngpio = S3C64XX_GPIO_A_NR, | ||
1283 | .label = "GPA", | ||
1284 | }, | ||
1285 | }, { | ||
1286 | .chip = { | ||
1287 | .base = S3C64XX_GPB(0), | ||
1288 | .ngpio = S3C64XX_GPIO_B_NR, | ||
1289 | .label = "GPB", | ||
1290 | }, | ||
1291 | }, { | ||
1292 | .chip = { | ||
1293 | .base = S3C64XX_GPC(0), | ||
1294 | .ngpio = S3C64XX_GPIO_C_NR, | ||
1295 | .label = "GPC", | ||
1296 | }, | ||
1297 | }, { | ||
1298 | .chip = { | ||
1299 | .base = S3C64XX_GPD(0), | ||
1300 | .ngpio = S3C64XX_GPIO_D_NR, | ||
1301 | .label = "GPD", | ||
1302 | }, | ||
1303 | }, { | ||
1304 | .config = &samsung_gpio_cfgs[0], | ||
1305 | .chip = { | ||
1306 | .base = S3C64XX_GPE(0), | ||
1307 | .ngpio = S3C64XX_GPIO_E_NR, | ||
1308 | .label = "GPE", | ||
1309 | }, | ||
1310 | }, { | ||
1311 | .base = S3C64XX_GPG_BASE, | ||
1312 | .chip = { | ||
1313 | .base = S3C64XX_GPG(0), | ||
1314 | .ngpio = S3C64XX_GPIO_G_NR, | ||
1315 | .label = "GPG", | ||
1316 | }, | ||
1317 | }, { | ||
1318 | .base = S3C64XX_GPM_BASE, | ||
1319 | .config = &samsung_gpio_cfgs[1], | ||
1320 | .chip = { | ||
1321 | .base = S3C64XX_GPM(0), | ||
1322 | .ngpio = S3C64XX_GPIO_M_NR, | ||
1323 | .label = "GPM", | ||
1324 | .to_irq = s3c64xx_gpiolib_mbank_to_irq, | ||
1325 | }, | ||
1326 | }, | ||
1327 | #endif | ||
1328 | }; | ||
1329 | |||
1330 | static struct samsung_gpio_chip s3c64xx_gpios_4bit2[] = { | ||
1331 | #ifdef CONFIG_PLAT_S3C64XX | ||
1332 | { | ||
1333 | .base = S3C64XX_GPH_BASE + 0x4, | ||
1334 | .chip = { | ||
1335 | .base = S3C64XX_GPH(0), | ||
1336 | .ngpio = S3C64XX_GPIO_H_NR, | ||
1337 | .label = "GPH", | ||
1338 | }, | ||
1339 | }, { | ||
1340 | .base = S3C64XX_GPK_BASE + 0x4, | ||
1341 | .config = &samsung_gpio_cfgs[0], | ||
1342 | .chip = { | ||
1343 | .base = S3C64XX_GPK(0), | ||
1344 | .ngpio = S3C64XX_GPIO_K_NR, | ||
1345 | .label = "GPK", | ||
1346 | }, | ||
1347 | }, { | ||
1348 | .base = S3C64XX_GPL_BASE + 0x4, | ||
1349 | .config = &samsung_gpio_cfgs[1], | ||
1350 | .chip = { | ||
1351 | .base = S3C64XX_GPL(0), | ||
1352 | .ngpio = S3C64XX_GPIO_L_NR, | ||
1353 | .label = "GPL", | ||
1354 | .to_irq = s3c64xx_gpiolib_lbank_to_irq, | ||
1355 | }, | ||
1356 | }, | ||
1357 | #endif | ||
1358 | }; | ||
1359 | |||
1360 | static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = { | ||
1361 | #ifdef CONFIG_PLAT_S3C64XX | ||
1362 | { | ||
1363 | .base = S3C64XX_GPF_BASE, | ||
1364 | .config = &samsung_gpio_cfgs[6], | ||
1365 | .chip = { | ||
1366 | .base = S3C64XX_GPF(0), | ||
1367 | .ngpio = S3C64XX_GPIO_F_NR, | ||
1368 | .label = "GPF", | ||
1369 | }, | ||
1370 | }, { | ||
1371 | .config = &samsung_gpio_cfgs[7], | ||
1372 | .chip = { | ||
1373 | .base = S3C64XX_GPI(0), | ||
1374 | .ngpio = S3C64XX_GPIO_I_NR, | ||
1375 | .label = "GPI", | ||
1376 | }, | ||
1377 | }, { | ||
1378 | .config = &samsung_gpio_cfgs[7], | ||
1379 | .chip = { | ||
1380 | .base = S3C64XX_GPJ(0), | ||
1381 | .ngpio = S3C64XX_GPIO_J_NR, | ||
1382 | .label = "GPJ", | ||
1383 | }, | ||
1384 | }, { | ||
1385 | .config = &samsung_gpio_cfgs[6], | ||
1386 | .chip = { | ||
1387 | .base = S3C64XX_GPO(0), | ||
1388 | .ngpio = S3C64XX_GPIO_O_NR, | ||
1389 | .label = "GPO", | ||
1390 | }, | ||
1391 | }, { | ||
1392 | .config = &samsung_gpio_cfgs[6], | ||
1393 | .chip = { | ||
1394 | .base = S3C64XX_GPP(0), | ||
1395 | .ngpio = S3C64XX_GPIO_P_NR, | ||
1396 | .label = "GPP", | ||
1397 | }, | ||
1398 | }, { | ||
1399 | .config = &samsung_gpio_cfgs[6], | ||
1400 | .chip = { | ||
1401 | .base = S3C64XX_GPQ(0), | ||
1402 | .ngpio = S3C64XX_GPIO_Q_NR, | ||
1403 | .label = "GPQ", | ||
1404 | }, | ||
1405 | }, { | ||
1406 | .base = S3C64XX_GPN_BASE, | ||
1407 | .irq_base = IRQ_EINT(0), | ||
1408 | .config = &samsung_gpio_cfgs[5], | ||
1409 | .chip = { | ||
1410 | .base = S3C64XX_GPN(0), | ||
1411 | .ngpio = S3C64XX_GPIO_N_NR, | ||
1412 | .label = "GPN", | ||
1413 | .to_irq = samsung_gpiolib_to_irq, | ||
1414 | }, | ||
1415 | }, | ||
1416 | #endif | ||
1417 | }; | ||
1418 | |||
1419 | /* | ||
1420 | * S5P6440 GPIO bank summary: | ||
1421 | * | ||
1422 | * Bank GPIOs Style SlpCon ExtInt Group | ||
1423 | * A 6 4Bit Yes 1 | ||
1424 | * B 7 4Bit Yes 1 | ||
1425 | * C 8 4Bit Yes 2 | ||
1426 | * F 2 2Bit Yes 4 [1] | ||
1427 | * G 7 4Bit Yes 5 | ||
1428 | * H 10 4Bit[2] Yes 6 | ||
1429 | * I 16 2Bit Yes None | ||
1430 | * J 12 2Bit Yes None | ||
1431 | * N 16 2Bit No IRQ_EINT | ||
1432 | * P 8 2Bit Yes 8 | ||
1433 | * R 15 4Bit[2] Yes 8 | ||
1434 | */ | ||
1435 | |||
1436 | static struct samsung_gpio_chip s5p6440_gpios_4bit[] = { | ||
1437 | #ifdef CONFIG_CPU_S5P6440 | ||
1438 | { | ||
1439 | .chip = { | ||
1440 | .base = S5P6440_GPA(0), | ||
1441 | .ngpio = S5P6440_GPIO_A_NR, | ||
1442 | .label = "GPA", | ||
1443 | }, | ||
1444 | }, { | ||
1445 | .chip = { | ||
1446 | .base = S5P6440_GPB(0), | ||
1447 | .ngpio = S5P6440_GPIO_B_NR, | ||
1448 | .label = "GPB", | ||
1449 | }, | ||
1450 | }, { | ||
1451 | .chip = { | ||
1452 | .base = S5P6440_GPC(0), | ||
1453 | .ngpio = S5P6440_GPIO_C_NR, | ||
1454 | .label = "GPC", | ||
1455 | }, | ||
1456 | }, { | ||
1457 | .base = S5P64X0_GPG_BASE, | ||
1458 | .chip = { | ||
1459 | .base = S5P6440_GPG(0), | ||
1460 | .ngpio = S5P6440_GPIO_G_NR, | ||
1461 | .label = "GPG", | ||
1462 | }, | ||
1463 | }, | ||
1464 | #endif | ||
1465 | }; | ||
1466 | |||
1467 | static struct samsung_gpio_chip s5p6440_gpios_4bit2[] = { | ||
1468 | #ifdef CONFIG_CPU_S5P6440 | ||
1469 | { | ||
1470 | .base = S5P64X0_GPH_BASE + 0x4, | ||
1471 | .chip = { | ||
1472 | .base = S5P6440_GPH(0), | ||
1473 | .ngpio = S5P6440_GPIO_H_NR, | ||
1474 | .label = "GPH", | ||
1475 | }, | ||
1476 | }, | ||
1477 | #endif | ||
1478 | }; | ||
1479 | |||
1480 | static struct samsung_gpio_chip s5p6440_gpios_rbank[] = { | ||
1481 | #ifdef CONFIG_CPU_S5P6440 | ||
1482 | { | ||
1483 | .base = S5P64X0_GPR_BASE + 0x4, | ||
1484 | .config = &s5p64x0_gpio_cfg_rbank, | ||
1485 | .chip = { | ||
1486 | .base = S5P6440_GPR(0), | ||
1487 | .ngpio = S5P6440_GPIO_R_NR, | ||
1488 | .label = "GPR", | ||
1489 | }, | ||
1490 | }, | ||
1491 | #endif | ||
1492 | }; | ||
1493 | |||
1494 | static struct samsung_gpio_chip s5p6440_gpios_2bit[] = { | ||
1495 | #ifdef CONFIG_CPU_S5P6440 | ||
1496 | { | ||
1497 | .base = S5P64X0_GPF_BASE, | ||
1498 | .config = &samsung_gpio_cfgs[6], | ||
1499 | .chip = { | ||
1500 | .base = S5P6440_GPF(0), | ||
1501 | .ngpio = S5P6440_GPIO_F_NR, | ||
1502 | .label = "GPF", | ||
1503 | }, | ||
1504 | }, { | ||
1505 | .base = S5P64X0_GPI_BASE, | ||
1506 | .config = &samsung_gpio_cfgs[4], | ||
1507 | .chip = { | ||
1508 | .base = S5P6440_GPI(0), | ||
1509 | .ngpio = S5P6440_GPIO_I_NR, | ||
1510 | .label = "GPI", | ||
1511 | }, | ||
1512 | }, { | ||
1513 | .base = S5P64X0_GPJ_BASE, | ||
1514 | .config = &samsung_gpio_cfgs[4], | ||
1515 | .chip = { | ||
1516 | .base = S5P6440_GPJ(0), | ||
1517 | .ngpio = S5P6440_GPIO_J_NR, | ||
1518 | .label = "GPJ", | ||
1519 | }, | ||
1520 | }, { | ||
1521 | .base = S5P64X0_GPN_BASE, | ||
1522 | .config = &samsung_gpio_cfgs[5], | ||
1523 | .chip = { | ||
1524 | .base = S5P6440_GPN(0), | ||
1525 | .ngpio = S5P6440_GPIO_N_NR, | ||
1526 | .label = "GPN", | ||
1527 | }, | ||
1528 | }, { | ||
1529 | .base = S5P64X0_GPP_BASE, | ||
1530 | .config = &samsung_gpio_cfgs[6], | ||
1531 | .chip = { | ||
1532 | .base = S5P6440_GPP(0), | ||
1533 | .ngpio = S5P6440_GPIO_P_NR, | ||
1534 | .label = "GPP", | ||
1535 | }, | ||
1536 | }, | ||
1537 | #endif | ||
1538 | }; | ||
1539 | |||
1540 | /* | ||
1541 | * S5P6450 GPIO bank summary: | ||
1542 | * | ||
1543 | * Bank GPIOs Style SlpCon ExtInt Group | ||
1544 | * A 6 4Bit Yes 1 | ||
1545 | * B 7 4Bit Yes 1 | ||
1546 | * C 8 4Bit Yes 2 | ||
1547 | * D 8 4Bit Yes None | ||
1548 | * F 2 2Bit Yes None | ||
1549 | * G 14 4Bit[2] Yes 5 | ||
1550 | * H 10 4Bit[2] Yes 6 | ||
1551 | * I 16 2Bit Yes None | ||
1552 | * J 12 2Bit Yes None | ||
1553 | * K 5 4Bit Yes None | ||
1554 | * N 16 2Bit No IRQ_EINT | ||
1555 | * P 11 2Bit Yes 8 | ||
1556 | * Q 14 2Bit Yes None | ||
1557 | * R 15 4Bit[2] Yes None | ||
1558 | * S 8 2Bit Yes None | ||
1559 | * | ||
1560 | * [1] BANKF pins 14,15 do not form part of the external interrupt sources | ||
1561 | * [2] BANK has two control registers, GPxCON0 and GPxCON1 | ||
1562 | */ | ||
1563 | |||
1564 | static struct samsung_gpio_chip s5p6450_gpios_4bit[] = { | ||
1565 | #ifdef CONFIG_CPU_S5P6450 | ||
1566 | { | ||
1567 | .chip = { | ||
1568 | .base = S5P6450_GPA(0), | ||
1569 | .ngpio = S5P6450_GPIO_A_NR, | ||
1570 | .label = "GPA", | ||
1571 | }, | ||
1572 | }, { | ||
1573 | .chip = { | ||
1574 | .base = S5P6450_GPB(0), | ||
1575 | .ngpio = S5P6450_GPIO_B_NR, | ||
1576 | .label = "GPB", | ||
1577 | }, | ||
1578 | }, { | ||
1579 | .chip = { | ||
1580 | .base = S5P6450_GPC(0), | ||
1581 | .ngpio = S5P6450_GPIO_C_NR, | ||
1582 | .label = "GPC", | ||
1583 | }, | ||
1584 | }, { | ||
1585 | .chip = { | ||
1586 | .base = S5P6450_GPD(0), | ||
1587 | .ngpio = S5P6450_GPIO_D_NR, | ||
1588 | .label = "GPD", | ||
1589 | }, | ||
1590 | }, { | ||
1591 | .base = S5P6450_GPK_BASE, | ||
1592 | .chip = { | ||
1593 | .base = S5P6450_GPK(0), | ||
1594 | .ngpio = S5P6450_GPIO_K_NR, | ||
1595 | .label = "GPK", | ||
1596 | }, | ||
1597 | }, | ||
1598 | #endif | ||
1599 | }; | ||
1600 | |||
1601 | static struct samsung_gpio_chip s5p6450_gpios_4bit2[] = { | ||
1602 | #ifdef CONFIG_CPU_S5P6450 | ||
1603 | { | ||
1604 | .base = S5P64X0_GPG_BASE + 0x4, | ||
1605 | .chip = { | ||
1606 | .base = S5P6450_GPG(0), | ||
1607 | .ngpio = S5P6450_GPIO_G_NR, | ||
1608 | .label = "GPG", | ||
1609 | }, | ||
1610 | }, { | ||
1611 | .base = S5P64X0_GPH_BASE + 0x4, | ||
1612 | .chip = { | ||
1613 | .base = S5P6450_GPH(0), | ||
1614 | .ngpio = S5P6450_GPIO_H_NR, | ||
1615 | .label = "GPH", | ||
1616 | }, | ||
1617 | }, | ||
1618 | #endif | ||
1619 | }; | ||
1620 | |||
1621 | static struct samsung_gpio_chip s5p6450_gpios_rbank[] = { | ||
1622 | #ifdef CONFIG_CPU_S5P6450 | ||
1623 | { | ||
1624 | .base = S5P64X0_GPR_BASE + 0x4, | ||
1625 | .config = &s5p64x0_gpio_cfg_rbank, | ||
1626 | .chip = { | ||
1627 | .base = S5P6450_GPR(0), | ||
1628 | .ngpio = S5P6450_GPIO_R_NR, | ||
1629 | .label = "GPR", | ||
1630 | }, | ||
1631 | }, | ||
1632 | #endif | ||
1633 | }; | ||
1634 | |||
1635 | static struct samsung_gpio_chip s5p6450_gpios_2bit[] = { | ||
1636 | #ifdef CONFIG_CPU_S5P6450 | ||
1637 | { | ||
1638 | .base = S5P64X0_GPF_BASE, | ||
1639 | .config = &samsung_gpio_cfgs[6], | ||
1640 | .chip = { | ||
1641 | .base = S5P6450_GPF(0), | ||
1642 | .ngpio = S5P6450_GPIO_F_NR, | ||
1643 | .label = "GPF", | ||
1644 | }, | ||
1645 | }, { | ||
1646 | .base = S5P64X0_GPI_BASE, | ||
1647 | .config = &samsung_gpio_cfgs[4], | ||
1648 | .chip = { | ||
1649 | .base = S5P6450_GPI(0), | ||
1650 | .ngpio = S5P6450_GPIO_I_NR, | ||
1651 | .label = "GPI", | ||
1652 | }, | ||
1653 | }, { | ||
1654 | .base = S5P64X0_GPJ_BASE, | ||
1655 | .config = &samsung_gpio_cfgs[4], | ||
1656 | .chip = { | ||
1657 | .base = S5P6450_GPJ(0), | ||
1658 | .ngpio = S5P6450_GPIO_J_NR, | ||
1659 | .label = "GPJ", | ||
1660 | }, | ||
1661 | }, { | ||
1662 | .base = S5P64X0_GPN_BASE, | ||
1663 | .config = &samsung_gpio_cfgs[5], | ||
1664 | .chip = { | ||
1665 | .base = S5P6450_GPN(0), | ||
1666 | .ngpio = S5P6450_GPIO_N_NR, | ||
1667 | .label = "GPN", | ||
1668 | }, | ||
1669 | }, { | ||
1670 | .base = S5P64X0_GPP_BASE, | ||
1671 | .config = &samsung_gpio_cfgs[6], | ||
1672 | .chip = { | ||
1673 | .base = S5P6450_GPP(0), | ||
1674 | .ngpio = S5P6450_GPIO_P_NR, | ||
1675 | .label = "GPP", | ||
1676 | }, | ||
1677 | }, { | ||
1678 | .base = S5P6450_GPQ_BASE, | ||
1679 | .config = &samsung_gpio_cfgs[5], | ||
1680 | .chip = { | ||
1681 | .base = S5P6450_GPQ(0), | ||
1682 | .ngpio = S5P6450_GPIO_Q_NR, | ||
1683 | .label = "GPQ", | ||
1684 | }, | ||
1685 | }, { | ||
1686 | .base = S5P6450_GPS_BASE, | ||
1687 | .config = &samsung_gpio_cfgs[6], | ||
1688 | .chip = { | ||
1689 | .base = S5P6450_GPS(0), | ||
1690 | .ngpio = S5P6450_GPIO_S_NR, | ||
1691 | .label = "GPS", | ||
1692 | }, | ||
1693 | }, | ||
1694 | #endif | ||
1695 | }; | ||
1696 | |||
1697 | /* | ||
1698 | * S5PC100 GPIO bank summary: | ||
1699 | * | ||
1700 | * Bank GPIOs Style INT Type | ||
1701 | * A0 8 4Bit GPIO_INT0 | ||
1702 | * A1 5 4Bit GPIO_INT1 | ||
1703 | * B 8 4Bit GPIO_INT2 | ||
1704 | * C 5 4Bit GPIO_INT3 | ||
1705 | * D 7 4Bit GPIO_INT4 | ||
1706 | * E0 8 4Bit GPIO_INT5 | ||
1707 | * E1 6 4Bit GPIO_INT6 | ||
1708 | * F0 8 4Bit GPIO_INT7 | ||
1709 | * F1 8 4Bit GPIO_INT8 | ||
1710 | * F2 8 4Bit GPIO_INT9 | ||
1711 | * F3 4 4Bit GPIO_INT10 | ||
1712 | * G0 8 4Bit GPIO_INT11 | ||
1713 | * G1 3 4Bit GPIO_INT12 | ||
1714 | * G2 7 4Bit GPIO_INT13 | ||
1715 | * G3 7 4Bit GPIO_INT14 | ||
1716 | * H0 8 4Bit WKUP_INT | ||
1717 | * H1 8 4Bit WKUP_INT | ||
1718 | * H2 8 4Bit WKUP_INT | ||
1719 | * H3 8 4Bit WKUP_INT | ||
1720 | * I 8 4Bit GPIO_INT15 | ||
1721 | * J0 8 4Bit GPIO_INT16 | ||
1722 | * J1 5 4Bit GPIO_INT17 | ||
1723 | * J2 8 4Bit GPIO_INT18 | ||
1724 | * J3 8 4Bit GPIO_INT19 | ||
1725 | * J4 4 4Bit GPIO_INT20 | ||
1726 | * K0 8 4Bit None | ||
1727 | * K1 6 4Bit None | ||
1728 | * K2 8 4Bit None | ||
1729 | * K3 8 4Bit None | ||
1730 | * L0 8 4Bit None | ||
1731 | * L1 8 4Bit None | ||
1732 | * L2 8 4Bit None | ||
1733 | * L3 8 4Bit None | ||
1734 | */ | ||
1735 | |||
1736 | static struct samsung_gpio_chip s5pc100_gpios_4bit[] = { | ||
1737 | #ifdef CONFIG_CPU_S5PC100 | ||
1738 | { | ||
1739 | .chip = { | ||
1740 | .base = S5PC100_GPA0(0), | ||
1741 | .ngpio = S5PC100_GPIO_A0_NR, | ||
1742 | .label = "GPA0", | ||
1743 | }, | ||
1744 | }, { | ||
1745 | .chip = { | ||
1746 | .base = S5PC100_GPA1(0), | ||
1747 | .ngpio = S5PC100_GPIO_A1_NR, | ||
1748 | .label = "GPA1", | ||
1749 | }, | ||
1750 | }, { | ||
1751 | .chip = { | ||
1752 | .base = S5PC100_GPB(0), | ||
1753 | .ngpio = S5PC100_GPIO_B_NR, | ||
1754 | .label = "GPB", | ||
1755 | }, | ||
1756 | }, { | ||
1757 | .chip = { | ||
1758 | .base = S5PC100_GPC(0), | ||
1759 | .ngpio = S5PC100_GPIO_C_NR, | ||
1760 | .label = "GPC", | ||
1761 | }, | ||
1762 | }, { | ||
1763 | .chip = { | ||
1764 | .base = S5PC100_GPD(0), | ||
1765 | .ngpio = S5PC100_GPIO_D_NR, | ||
1766 | .label = "GPD", | ||
1767 | }, | ||
1768 | }, { | ||
1769 | .chip = { | ||
1770 | .base = S5PC100_GPE0(0), | ||
1771 | .ngpio = S5PC100_GPIO_E0_NR, | ||
1772 | .label = "GPE0", | ||
1773 | }, | ||
1774 | }, { | ||
1775 | .chip = { | ||
1776 | .base = S5PC100_GPE1(0), | ||
1777 | .ngpio = S5PC100_GPIO_E1_NR, | ||
1778 | .label = "GPE1", | ||
1779 | }, | ||
1780 | }, { | ||
1781 | .chip = { | ||
1782 | .base = S5PC100_GPF0(0), | ||
1783 | .ngpio = S5PC100_GPIO_F0_NR, | ||
1784 | .label = "GPF0", | ||
1785 | }, | ||
1786 | }, { | ||
1787 | .chip = { | ||
1788 | .base = S5PC100_GPF1(0), | ||
1789 | .ngpio = S5PC100_GPIO_F1_NR, | ||
1790 | .label = "GPF1", | ||
1791 | }, | ||
1792 | }, { | ||
1793 | .chip = { | ||
1794 | .base = S5PC100_GPF2(0), | ||
1795 | .ngpio = S5PC100_GPIO_F2_NR, | ||
1796 | .label = "GPF2", | ||
1797 | }, | ||
1798 | }, { | ||
1799 | .chip = { | ||
1800 | .base = S5PC100_GPF3(0), | ||
1801 | .ngpio = S5PC100_GPIO_F3_NR, | ||
1802 | .label = "GPF3", | ||
1803 | }, | ||
1804 | }, { | ||
1805 | .chip = { | ||
1806 | .base = S5PC100_GPG0(0), | ||
1807 | .ngpio = S5PC100_GPIO_G0_NR, | ||
1808 | .label = "GPG0", | ||
1809 | }, | ||
1810 | }, { | ||
1811 | .chip = { | ||
1812 | .base = S5PC100_GPG1(0), | ||
1813 | .ngpio = S5PC100_GPIO_G1_NR, | ||
1814 | .label = "GPG1", | ||
1815 | }, | ||
1816 | }, { | ||
1817 | .chip = { | ||
1818 | .base = S5PC100_GPG2(0), | ||
1819 | .ngpio = S5PC100_GPIO_G2_NR, | ||
1820 | .label = "GPG2", | ||
1821 | }, | ||
1822 | }, { | ||
1823 | .chip = { | ||
1824 | .base = S5PC100_GPG3(0), | ||
1825 | .ngpio = S5PC100_GPIO_G3_NR, | ||
1826 | .label = "GPG3", | ||
1827 | }, | ||
1828 | }, { | ||
1829 | .chip = { | ||
1830 | .base = S5PC100_GPI(0), | ||
1831 | .ngpio = S5PC100_GPIO_I_NR, | ||
1832 | .label = "GPI", | ||
1833 | }, | ||
1834 | }, { | ||
1835 | .chip = { | ||
1836 | .base = S5PC100_GPJ0(0), | ||
1837 | .ngpio = S5PC100_GPIO_J0_NR, | ||
1838 | .label = "GPJ0", | ||
1839 | }, | ||
1840 | }, { | ||
1841 | .chip = { | ||
1842 | .base = S5PC100_GPJ1(0), | ||
1843 | .ngpio = S5PC100_GPIO_J1_NR, | ||
1844 | .label = "GPJ1", | ||
1845 | }, | ||
1846 | }, { | ||
1847 | .chip = { | ||
1848 | .base = S5PC100_GPJ2(0), | ||
1849 | .ngpio = S5PC100_GPIO_J2_NR, | ||
1850 | .label = "GPJ2", | ||
1851 | }, | ||
1852 | }, { | ||
1853 | .chip = { | ||
1854 | .base = S5PC100_GPJ3(0), | ||
1855 | .ngpio = S5PC100_GPIO_J3_NR, | ||
1856 | .label = "GPJ3", | ||
1857 | }, | ||
1858 | }, { | ||
1859 | .chip = { | ||
1860 | .base = S5PC100_GPJ4(0), | ||
1861 | .ngpio = S5PC100_GPIO_J4_NR, | ||
1862 | .label = "GPJ4", | ||
1863 | }, | ||
1864 | }, { | ||
1865 | .chip = { | ||
1866 | .base = S5PC100_GPK0(0), | ||
1867 | .ngpio = S5PC100_GPIO_K0_NR, | ||
1868 | .label = "GPK0", | ||
1869 | }, | ||
1870 | }, { | ||
1871 | .chip = { | ||
1872 | .base = S5PC100_GPK1(0), | ||
1873 | .ngpio = S5PC100_GPIO_K1_NR, | ||
1874 | .label = "GPK1", | ||
1875 | }, | ||
1876 | }, { | ||
1877 | .chip = { | ||
1878 | .base = S5PC100_GPK2(0), | ||
1879 | .ngpio = S5PC100_GPIO_K2_NR, | ||
1880 | .label = "GPK2", | ||
1881 | }, | ||
1882 | }, { | ||
1883 | .chip = { | ||
1884 | .base = S5PC100_GPK3(0), | ||
1885 | .ngpio = S5PC100_GPIO_K3_NR, | ||
1886 | .label = "GPK3", | ||
1887 | }, | ||
1888 | }, { | ||
1889 | .chip = { | ||
1890 | .base = S5PC100_GPL0(0), | ||
1891 | .ngpio = S5PC100_GPIO_L0_NR, | ||
1892 | .label = "GPL0", | ||
1893 | }, | ||
1894 | }, { | ||
1895 | .chip = { | ||
1896 | .base = S5PC100_GPL1(0), | ||
1897 | .ngpio = S5PC100_GPIO_L1_NR, | ||
1898 | .label = "GPL1", | ||
1899 | }, | ||
1900 | }, { | ||
1901 | .chip = { | ||
1902 | .base = S5PC100_GPL2(0), | ||
1903 | .ngpio = S5PC100_GPIO_L2_NR, | ||
1904 | .label = "GPL2", | ||
1905 | }, | ||
1906 | }, { | ||
1907 | .chip = { | ||
1908 | .base = S5PC100_GPL3(0), | ||
1909 | .ngpio = S5PC100_GPIO_L3_NR, | ||
1910 | .label = "GPL3", | ||
1911 | }, | ||
1912 | }, { | ||
1913 | .chip = { | ||
1914 | .base = S5PC100_GPL4(0), | ||
1915 | .ngpio = S5PC100_GPIO_L4_NR, | ||
1916 | .label = "GPL4", | ||
1917 | }, | ||
1918 | }, { | ||
1919 | .base = (S5P_VA_GPIO + 0xC00), | ||
1920 | .irq_base = IRQ_EINT(0), | ||
1921 | .chip = { | ||
1922 | .base = S5PC100_GPH0(0), | ||
1923 | .ngpio = S5PC100_GPIO_H0_NR, | ||
1924 | .label = "GPH0", | ||
1925 | .to_irq = samsung_gpiolib_to_irq, | ||
1926 | }, | ||
1927 | }, { | ||
1928 | .base = (S5P_VA_GPIO + 0xC20), | ||
1929 | .irq_base = IRQ_EINT(8), | ||
1930 | .chip = { | ||
1931 | .base = S5PC100_GPH1(0), | ||
1932 | .ngpio = S5PC100_GPIO_H1_NR, | ||
1933 | .label = "GPH1", | ||
1934 | .to_irq = samsung_gpiolib_to_irq, | ||
1935 | }, | ||
1936 | }, { | ||
1937 | .base = (S5P_VA_GPIO + 0xC40), | ||
1938 | .irq_base = IRQ_EINT(16), | ||
1939 | .chip = { | ||
1940 | .base = S5PC100_GPH2(0), | ||
1941 | .ngpio = S5PC100_GPIO_H2_NR, | ||
1942 | .label = "GPH2", | ||
1943 | .to_irq = samsung_gpiolib_to_irq, | ||
1944 | }, | ||
1945 | }, { | ||
1946 | .base = (S5P_VA_GPIO + 0xC60), | ||
1947 | .irq_base = IRQ_EINT(24), | ||
1948 | .chip = { | ||
1949 | .base = S5PC100_GPH3(0), | ||
1950 | .ngpio = S5PC100_GPIO_H3_NR, | ||
1951 | .label = "GPH3", | ||
1952 | .to_irq = samsung_gpiolib_to_irq, | ||
1953 | }, | ||
1954 | }, | ||
1955 | #endif | ||
1956 | }; | ||
1957 | |||
1958 | /* | ||
1959 | * Followings are the gpio banks in S5PV210/S5PC110 | ||
1960 | * | ||
1961 | * The 'config' member when left to NULL, is initialized to the default | ||
1962 | * structure samsung_gpio_cfgs[3] in the init function below. | ||
1963 | * | ||
1964 | * The 'base' member is also initialized in the init function below. | ||
1965 | * Note: The initialization of 'base' member of samsung_gpio_chip structure | ||
1966 | * uses the above macro and depends on the banks being listed in order here. | ||
1967 | */ | ||
1968 | |||
1969 | static struct samsung_gpio_chip s5pv210_gpios_4bit[] = { | ||
1970 | #ifdef CONFIG_CPU_S5PV210 | ||
1971 | { | ||
1972 | .chip = { | ||
1973 | .base = S5PV210_GPA0(0), | ||
1974 | .ngpio = S5PV210_GPIO_A0_NR, | ||
1975 | .label = "GPA0", | ||
1976 | }, | ||
1977 | }, { | ||
1978 | .chip = { | ||
1979 | .base = S5PV210_GPA1(0), | ||
1980 | .ngpio = S5PV210_GPIO_A1_NR, | ||
1981 | .label = "GPA1", | ||
1982 | }, | ||
1983 | }, { | ||
1984 | .chip = { | ||
1985 | .base = S5PV210_GPB(0), | ||
1986 | .ngpio = S5PV210_GPIO_B_NR, | ||
1987 | .label = "GPB", | ||
1988 | }, | ||
1989 | }, { | ||
1990 | .chip = { | ||
1991 | .base = S5PV210_GPC0(0), | ||
1992 | .ngpio = S5PV210_GPIO_C0_NR, | ||
1993 | .label = "GPC0", | ||
1994 | }, | ||
1995 | }, { | ||
1996 | .chip = { | ||
1997 | .base = S5PV210_GPC1(0), | ||
1998 | .ngpio = S5PV210_GPIO_C1_NR, | ||
1999 | .label = "GPC1", | ||
2000 | }, | ||
2001 | }, { | ||
2002 | .chip = { | ||
2003 | .base = S5PV210_GPD0(0), | ||
2004 | .ngpio = S5PV210_GPIO_D0_NR, | ||
2005 | .label = "GPD0", | ||
2006 | }, | ||
2007 | }, { | ||
2008 | .chip = { | ||
2009 | .base = S5PV210_GPD1(0), | ||
2010 | .ngpio = S5PV210_GPIO_D1_NR, | ||
2011 | .label = "GPD1", | ||
2012 | }, | ||
2013 | }, { | ||
2014 | .chip = { | ||
2015 | .base = S5PV210_GPE0(0), | ||
2016 | .ngpio = S5PV210_GPIO_E0_NR, | ||
2017 | .label = "GPE0", | ||
2018 | }, | ||
2019 | }, { | ||
2020 | .chip = { | ||
2021 | .base = S5PV210_GPE1(0), | ||
2022 | .ngpio = S5PV210_GPIO_E1_NR, | ||
2023 | .label = "GPE1", | ||
2024 | }, | ||
2025 | }, { | ||
2026 | .chip = { | ||
2027 | .base = S5PV210_GPF0(0), | ||
2028 | .ngpio = S5PV210_GPIO_F0_NR, | ||
2029 | .label = "GPF0", | ||
2030 | }, | ||
2031 | }, { | ||
2032 | .chip = { | ||
2033 | .base = S5PV210_GPF1(0), | ||
2034 | .ngpio = S5PV210_GPIO_F1_NR, | ||
2035 | .label = "GPF1", | ||
2036 | }, | ||
2037 | }, { | ||
2038 | .chip = { | ||
2039 | .base = S5PV210_GPF2(0), | ||
2040 | .ngpio = S5PV210_GPIO_F2_NR, | ||
2041 | .label = "GPF2", | ||
2042 | }, | ||
2043 | }, { | ||
2044 | .chip = { | ||
2045 | .base = S5PV210_GPF3(0), | ||
2046 | .ngpio = S5PV210_GPIO_F3_NR, | ||
2047 | .label = "GPF3", | ||
2048 | }, | ||
2049 | }, { | ||
2050 | .chip = { | ||
2051 | .base = S5PV210_GPG0(0), | ||
2052 | .ngpio = S5PV210_GPIO_G0_NR, | ||
2053 | .label = "GPG0", | ||
2054 | }, | ||
2055 | }, { | ||
2056 | .chip = { | ||
2057 | .base = S5PV210_GPG1(0), | ||
2058 | .ngpio = S5PV210_GPIO_G1_NR, | ||
2059 | .label = "GPG1", | ||
2060 | }, | ||
2061 | }, { | ||
2062 | .chip = { | ||
2063 | .base = S5PV210_GPG2(0), | ||
2064 | .ngpio = S5PV210_GPIO_G2_NR, | ||
2065 | .label = "GPG2", | ||
2066 | }, | ||
2067 | }, { | ||
2068 | .chip = { | ||
2069 | .base = S5PV210_GPG3(0), | ||
2070 | .ngpio = S5PV210_GPIO_G3_NR, | ||
2071 | .label = "GPG3", | ||
2072 | }, | ||
2073 | }, { | ||
2074 | .chip = { | ||
2075 | .base = S5PV210_GPI(0), | ||
2076 | .ngpio = S5PV210_GPIO_I_NR, | ||
2077 | .label = "GPI", | ||
2078 | }, | ||
2079 | }, { | ||
2080 | .chip = { | ||
2081 | .base = S5PV210_GPJ0(0), | ||
2082 | .ngpio = S5PV210_GPIO_J0_NR, | ||
2083 | .label = "GPJ0", | ||
2084 | }, | ||
2085 | }, { | ||
2086 | .chip = { | ||
2087 | .base = S5PV210_GPJ1(0), | ||
2088 | .ngpio = S5PV210_GPIO_J1_NR, | ||
2089 | .label = "GPJ1", | ||
2090 | }, | ||
2091 | }, { | ||
2092 | .chip = { | ||
2093 | .base = S5PV210_GPJ2(0), | ||
2094 | .ngpio = S5PV210_GPIO_J2_NR, | ||
2095 | .label = "GPJ2", | ||
2096 | }, | ||
2097 | }, { | ||
2098 | .chip = { | ||
2099 | .base = S5PV210_GPJ3(0), | ||
2100 | .ngpio = S5PV210_GPIO_J3_NR, | ||
2101 | .label = "GPJ3", | ||
2102 | }, | ||
2103 | }, { | ||
2104 | .chip = { | ||
2105 | .base = S5PV210_GPJ4(0), | ||
2106 | .ngpio = S5PV210_GPIO_J4_NR, | ||
2107 | .label = "GPJ4", | ||
2108 | }, | ||
2109 | }, { | ||
2110 | .chip = { | ||
2111 | .base = S5PV210_MP01(0), | ||
2112 | .ngpio = S5PV210_GPIO_MP01_NR, | ||
2113 | .label = "MP01", | ||
2114 | }, | ||
2115 | }, { | ||
2116 | .chip = { | ||
2117 | .base = S5PV210_MP02(0), | ||
2118 | .ngpio = S5PV210_GPIO_MP02_NR, | ||
2119 | .label = "MP02", | ||
2120 | }, | ||
2121 | }, { | ||
2122 | .chip = { | ||
2123 | .base = S5PV210_MP03(0), | ||
2124 | .ngpio = S5PV210_GPIO_MP03_NR, | ||
2125 | .label = "MP03", | ||
2126 | }, | ||
2127 | }, { | ||
2128 | .chip = { | ||
2129 | .base = S5PV210_MP04(0), | ||
2130 | .ngpio = S5PV210_GPIO_MP04_NR, | ||
2131 | .label = "MP04", | ||
2132 | }, | ||
2133 | }, { | ||
2134 | .chip = { | ||
2135 | .base = S5PV210_MP05(0), | ||
2136 | .ngpio = S5PV210_GPIO_MP05_NR, | ||
2137 | .label = "MP05", | ||
2138 | }, | ||
2139 | }, { | ||
2140 | .base = (S5P_VA_GPIO + 0xC00), | ||
2141 | .irq_base = IRQ_EINT(0), | ||
2142 | .chip = { | ||
2143 | .base = S5PV210_GPH0(0), | ||
2144 | .ngpio = S5PV210_GPIO_H0_NR, | ||
2145 | .label = "GPH0", | ||
2146 | .to_irq = samsung_gpiolib_to_irq, | ||
2147 | }, | ||
2148 | }, { | ||
2149 | .base = (S5P_VA_GPIO + 0xC20), | ||
2150 | .irq_base = IRQ_EINT(8), | ||
2151 | .chip = { | ||
2152 | .base = S5PV210_GPH1(0), | ||
2153 | .ngpio = S5PV210_GPIO_H1_NR, | ||
2154 | .label = "GPH1", | ||
2155 | .to_irq = samsung_gpiolib_to_irq, | ||
2156 | }, | ||
2157 | }, { | ||
2158 | .base = (S5P_VA_GPIO + 0xC40), | ||
2159 | .irq_base = IRQ_EINT(16), | ||
2160 | .chip = { | ||
2161 | .base = S5PV210_GPH2(0), | ||
2162 | .ngpio = S5PV210_GPIO_H2_NR, | ||
2163 | .label = "GPH2", | ||
2164 | .to_irq = samsung_gpiolib_to_irq, | ||
2165 | }, | ||
2166 | }, { | ||
2167 | .base = (S5P_VA_GPIO + 0xC60), | ||
2168 | .irq_base = IRQ_EINT(24), | ||
2169 | .chip = { | ||
2170 | .base = S5PV210_GPH3(0), | ||
2171 | .ngpio = S5PV210_GPIO_H3_NR, | ||
2172 | .label = "GPH3", | ||
2173 | .to_irq = samsung_gpiolib_to_irq, | ||
2174 | }, | ||
2175 | }, | ||
2176 | #endif | ||
2177 | }; | ||
2178 | |||
2179 | /* | ||
2180 | * Followings are the gpio banks in EXYNOS SoCs | ||
2181 | * | ||
2182 | * The 'config' member when left to NULL, is initialized to the default | ||
2183 | * structure exynos_gpio_cfg in the init function below. | ||
2184 | * | ||
2185 | * The 'base' member is also initialized in the init function below. | ||
2186 | * Note: The initialization of 'base' member of samsung_gpio_chip structure | ||
2187 | * uses the above macro and depends on the banks being listed in order here. | ||
2188 | */ | ||
2189 | |||
2190 | #ifdef CONFIG_ARCH_EXYNOS4 | ||
2191 | static struct samsung_gpio_chip exynos4_gpios_1[] = { | ||
2192 | { | ||
2193 | .chip = { | ||
2194 | .base = EXYNOS4_GPA0(0), | ||
2195 | .ngpio = EXYNOS4_GPIO_A0_NR, | ||
2196 | .label = "GPA0", | ||
2197 | }, | ||
2198 | }, { | ||
2199 | .chip = { | ||
2200 | .base = EXYNOS4_GPA1(0), | ||
2201 | .ngpio = EXYNOS4_GPIO_A1_NR, | ||
2202 | .label = "GPA1", | ||
2203 | }, | ||
2204 | }, { | ||
2205 | .chip = { | ||
2206 | .base = EXYNOS4_GPB(0), | ||
2207 | .ngpio = EXYNOS4_GPIO_B_NR, | ||
2208 | .label = "GPB", | ||
2209 | }, | ||
2210 | }, { | ||
2211 | .chip = { | ||
2212 | .base = EXYNOS4_GPC0(0), | ||
2213 | .ngpio = EXYNOS4_GPIO_C0_NR, | ||
2214 | .label = "GPC0", | ||
2215 | }, | ||
2216 | }, { | ||
2217 | .chip = { | ||
2218 | .base = EXYNOS4_GPC1(0), | ||
2219 | .ngpio = EXYNOS4_GPIO_C1_NR, | ||
2220 | .label = "GPC1", | ||
2221 | }, | ||
2222 | }, { | ||
2223 | .chip = { | ||
2224 | .base = EXYNOS4_GPD0(0), | ||
2225 | .ngpio = EXYNOS4_GPIO_D0_NR, | ||
2226 | .label = "GPD0", | ||
2227 | }, | ||
2228 | }, { | ||
2229 | .chip = { | ||
2230 | .base = EXYNOS4_GPD1(0), | ||
2231 | .ngpio = EXYNOS4_GPIO_D1_NR, | ||
2232 | .label = "GPD1", | ||
2233 | }, | ||
2234 | }, { | ||
2235 | .chip = { | ||
2236 | .base = EXYNOS4_GPE0(0), | ||
2237 | .ngpio = EXYNOS4_GPIO_E0_NR, | ||
2238 | .label = "GPE0", | ||
2239 | }, | ||
2240 | }, { | ||
2241 | .chip = { | ||
2242 | .base = EXYNOS4_GPE1(0), | ||
2243 | .ngpio = EXYNOS4_GPIO_E1_NR, | ||
2244 | .label = "GPE1", | ||
2245 | }, | ||
2246 | }, { | ||
2247 | .chip = { | ||
2248 | .base = EXYNOS4_GPE2(0), | ||
2249 | .ngpio = EXYNOS4_GPIO_E2_NR, | ||
2250 | .label = "GPE2", | ||
2251 | }, | ||
2252 | }, { | ||
2253 | .chip = { | ||
2254 | .base = EXYNOS4_GPE3(0), | ||
2255 | .ngpio = EXYNOS4_GPIO_E3_NR, | ||
2256 | .label = "GPE3", | ||
2257 | }, | ||
2258 | }, { | ||
2259 | .chip = { | ||
2260 | .base = EXYNOS4_GPE4(0), | ||
2261 | .ngpio = EXYNOS4_GPIO_E4_NR, | ||
2262 | .label = "GPE4", | ||
2263 | }, | ||
2264 | }, { | ||
2265 | .chip = { | ||
2266 | .base = EXYNOS4_GPF0(0), | ||
2267 | .ngpio = EXYNOS4_GPIO_F0_NR, | ||
2268 | .label = "GPF0", | ||
2269 | }, | ||
2270 | }, { | ||
2271 | .chip = { | ||
2272 | .base = EXYNOS4_GPF1(0), | ||
2273 | .ngpio = EXYNOS4_GPIO_F1_NR, | ||
2274 | .label = "GPF1", | ||
2275 | }, | ||
2276 | }, { | ||
2277 | .chip = { | ||
2278 | .base = EXYNOS4_GPF2(0), | ||
2279 | .ngpio = EXYNOS4_GPIO_F2_NR, | ||
2280 | .label = "GPF2", | ||
2281 | }, | ||
2282 | }, { | ||
2283 | .chip = { | ||
2284 | .base = EXYNOS4_GPF3(0), | ||
2285 | .ngpio = EXYNOS4_GPIO_F3_NR, | ||
2286 | .label = "GPF3", | ||
2287 | }, | ||
2288 | }, | ||
2289 | }; | ||
2290 | #endif | ||
2291 | |||
2292 | #ifdef CONFIG_ARCH_EXYNOS4 | ||
2293 | static struct samsung_gpio_chip exynos4_gpios_2[] = { | ||
2294 | { | ||
2295 | .chip = { | ||
2296 | .base = EXYNOS4_GPJ0(0), | ||
2297 | .ngpio = EXYNOS4_GPIO_J0_NR, | ||
2298 | .label = "GPJ0", | ||
2299 | }, | ||
2300 | }, { | ||
2301 | .chip = { | ||
2302 | .base = EXYNOS4_GPJ1(0), | ||
2303 | .ngpio = EXYNOS4_GPIO_J1_NR, | ||
2304 | .label = "GPJ1", | ||
2305 | }, | ||
2306 | }, { | ||
2307 | .chip = { | ||
2308 | .base = EXYNOS4_GPK0(0), | ||
2309 | .ngpio = EXYNOS4_GPIO_K0_NR, | ||
2310 | .label = "GPK0", | ||
2311 | }, | ||
2312 | }, { | ||
2313 | .chip = { | ||
2314 | .base = EXYNOS4_GPK1(0), | ||
2315 | .ngpio = EXYNOS4_GPIO_K1_NR, | ||
2316 | .label = "GPK1", | ||
2317 | }, | ||
2318 | }, { | ||
2319 | .chip = { | ||
2320 | .base = EXYNOS4_GPK2(0), | ||
2321 | .ngpio = EXYNOS4_GPIO_K2_NR, | ||
2322 | .label = "GPK2", | ||
2323 | }, | ||
2324 | }, { | ||
2325 | .chip = { | ||
2326 | .base = EXYNOS4_GPK3(0), | ||
2327 | .ngpio = EXYNOS4_GPIO_K3_NR, | ||
2328 | .label = "GPK3", | ||
2329 | }, | ||
2330 | }, { | ||
2331 | .chip = { | ||
2332 | .base = EXYNOS4_GPL0(0), | ||
2333 | .ngpio = EXYNOS4_GPIO_L0_NR, | ||
2334 | .label = "GPL0", | ||
2335 | }, | ||
2336 | }, { | ||
2337 | .chip = { | ||
2338 | .base = EXYNOS4_GPL1(0), | ||
2339 | .ngpio = EXYNOS4_GPIO_L1_NR, | ||
2340 | .label = "GPL1", | ||
2341 | }, | ||
2342 | }, { | ||
2343 | .chip = { | ||
2344 | .base = EXYNOS4_GPL2(0), | ||
2345 | .ngpio = EXYNOS4_GPIO_L2_NR, | ||
2346 | .label = "GPL2", | ||
2347 | }, | ||
2348 | }, { | ||
2349 | .config = &samsung_gpio_cfgs[8], | ||
2350 | .chip = { | ||
2351 | .base = EXYNOS4_GPY0(0), | ||
2352 | .ngpio = EXYNOS4_GPIO_Y0_NR, | ||
2353 | .label = "GPY0", | ||
2354 | }, | ||
2355 | }, { | ||
2356 | .config = &samsung_gpio_cfgs[8], | ||
2357 | .chip = { | ||
2358 | .base = EXYNOS4_GPY1(0), | ||
2359 | .ngpio = EXYNOS4_GPIO_Y1_NR, | ||
2360 | .label = "GPY1", | ||
2361 | }, | ||
2362 | }, { | ||
2363 | .config = &samsung_gpio_cfgs[8], | ||
2364 | .chip = { | ||
2365 | .base = EXYNOS4_GPY2(0), | ||
2366 | .ngpio = EXYNOS4_GPIO_Y2_NR, | ||
2367 | .label = "GPY2", | ||
2368 | }, | ||
2369 | }, { | ||
2370 | .config = &samsung_gpio_cfgs[8], | ||
2371 | .chip = { | ||
2372 | .base = EXYNOS4_GPY3(0), | ||
2373 | .ngpio = EXYNOS4_GPIO_Y3_NR, | ||
2374 | .label = "GPY3", | ||
2375 | }, | ||
2376 | }, { | ||
2377 | .config = &samsung_gpio_cfgs[8], | ||
2378 | .chip = { | ||
2379 | .base = EXYNOS4_GPY4(0), | ||
2380 | .ngpio = EXYNOS4_GPIO_Y4_NR, | ||
2381 | .label = "GPY4", | ||
2382 | }, | ||
2383 | }, { | ||
2384 | .config = &samsung_gpio_cfgs[8], | ||
2385 | .chip = { | ||
2386 | .base = EXYNOS4_GPY5(0), | ||
2387 | .ngpio = EXYNOS4_GPIO_Y5_NR, | ||
2388 | .label = "GPY5", | ||
2389 | }, | ||
2390 | }, { | ||
2391 | .config = &samsung_gpio_cfgs[8], | ||
2392 | .chip = { | ||
2393 | .base = EXYNOS4_GPY6(0), | ||
2394 | .ngpio = EXYNOS4_GPIO_Y6_NR, | ||
2395 | .label = "GPY6", | ||
2396 | }, | ||
2397 | }, { | ||
2398 | .config = &samsung_gpio_cfgs[9], | ||
2399 | .irq_base = IRQ_EINT(0), | ||
2400 | .chip = { | ||
2401 | .base = EXYNOS4_GPX0(0), | ||
2402 | .ngpio = EXYNOS4_GPIO_X0_NR, | ||
2403 | .label = "GPX0", | ||
2404 | .to_irq = samsung_gpiolib_to_irq, | ||
2405 | }, | ||
2406 | }, { | ||
2407 | .config = &samsung_gpio_cfgs[9], | ||
2408 | .irq_base = IRQ_EINT(8), | ||
2409 | .chip = { | ||
2410 | .base = EXYNOS4_GPX1(0), | ||
2411 | .ngpio = EXYNOS4_GPIO_X1_NR, | ||
2412 | .label = "GPX1", | ||
2413 | .to_irq = samsung_gpiolib_to_irq, | ||
2414 | }, | ||
2415 | }, { | ||
2416 | .config = &samsung_gpio_cfgs[9], | ||
2417 | .irq_base = IRQ_EINT(16), | ||
2418 | .chip = { | ||
2419 | .base = EXYNOS4_GPX2(0), | ||
2420 | .ngpio = EXYNOS4_GPIO_X2_NR, | ||
2421 | .label = "GPX2", | ||
2422 | .to_irq = samsung_gpiolib_to_irq, | ||
2423 | }, | ||
2424 | }, { | ||
2425 | .config = &samsung_gpio_cfgs[9], | ||
2426 | .irq_base = IRQ_EINT(24), | ||
2427 | .chip = { | ||
2428 | .base = EXYNOS4_GPX3(0), | ||
2429 | .ngpio = EXYNOS4_GPIO_X3_NR, | ||
2430 | .label = "GPX3", | ||
2431 | .to_irq = samsung_gpiolib_to_irq, | ||
2432 | }, | ||
2433 | }, | ||
2434 | }; | ||
2435 | #endif | ||
2436 | |||
2437 | #ifdef CONFIG_ARCH_EXYNOS4 | ||
2438 | static struct samsung_gpio_chip exynos4_gpios_3[] = { | ||
2439 | { | ||
2440 | .chip = { | ||
2441 | .base = EXYNOS4_GPZ(0), | ||
2442 | .ngpio = EXYNOS4_GPIO_Z_NR, | ||
2443 | .label = "GPZ", | ||
2444 | }, | ||
2445 | }, | ||
2446 | }; | ||
2447 | #endif | ||
2448 | |||
2449 | #ifdef CONFIG_ARCH_EXYNOS5 | ||
2450 | static struct samsung_gpio_chip exynos5_gpios_1[] = { | ||
2451 | { | ||
2452 | .chip = { | ||
2453 | .base = EXYNOS5_GPA0(0), | ||
2454 | .ngpio = EXYNOS5_GPIO_A0_NR, | ||
2455 | .label = "GPA0", | ||
2456 | }, | ||
2457 | }, { | ||
2458 | .chip = { | ||
2459 | .base = EXYNOS5_GPA1(0), | ||
2460 | .ngpio = EXYNOS5_GPIO_A1_NR, | ||
2461 | .label = "GPA1", | ||
2462 | }, | ||
2463 | }, { | ||
2464 | .chip = { | ||
2465 | .base = EXYNOS5_GPA2(0), | ||
2466 | .ngpio = EXYNOS5_GPIO_A2_NR, | ||
2467 | .label = "GPA2", | ||
2468 | }, | ||
2469 | }, { | ||
2470 | .chip = { | ||
2471 | .base = EXYNOS5_GPB0(0), | ||
2472 | .ngpio = EXYNOS5_GPIO_B0_NR, | ||
2473 | .label = "GPB0", | ||
2474 | }, | ||
2475 | }, { | ||
2476 | .chip = { | ||
2477 | .base = EXYNOS5_GPB1(0), | ||
2478 | .ngpio = EXYNOS5_GPIO_B1_NR, | ||
2479 | .label = "GPB1", | ||
2480 | }, | ||
2481 | }, { | ||
2482 | .chip = { | ||
2483 | .base = EXYNOS5_GPB2(0), | ||
2484 | .ngpio = EXYNOS5_GPIO_B2_NR, | ||
2485 | .label = "GPB2", | ||
2486 | }, | ||
2487 | }, { | ||
2488 | .chip = { | ||
2489 | .base = EXYNOS5_GPB3(0), | ||
2490 | .ngpio = EXYNOS5_GPIO_B3_NR, | ||
2491 | .label = "GPB3", | ||
2492 | }, | ||
2493 | }, { | ||
2494 | .chip = { | ||
2495 | .base = EXYNOS5_GPC0(0), | ||
2496 | .ngpio = EXYNOS5_GPIO_C0_NR, | ||
2497 | .label = "GPC0", | ||
2498 | }, | ||
2499 | }, { | ||
2500 | .chip = { | ||
2501 | .base = EXYNOS5_GPC1(0), | ||
2502 | .ngpio = EXYNOS5_GPIO_C1_NR, | ||
2503 | .label = "GPC1", | ||
2504 | }, | ||
2505 | }, { | ||
2506 | .chip = { | ||
2507 | .base = EXYNOS5_GPC2(0), | ||
2508 | .ngpio = EXYNOS5_GPIO_C2_NR, | ||
2509 | .label = "GPC2", | ||
2510 | }, | ||
2511 | }, { | ||
2512 | .chip = { | ||
2513 | .base = EXYNOS5_GPC3(0), | ||
2514 | .ngpio = EXYNOS5_GPIO_C3_NR, | ||
2515 | .label = "GPC3", | ||
2516 | }, | ||
2517 | }, { | ||
2518 | .chip = { | ||
2519 | .base = EXYNOS5_GPD0(0), | ||
2520 | .ngpio = EXYNOS5_GPIO_D0_NR, | ||
2521 | .label = "GPD0", | ||
2522 | }, | ||
2523 | }, { | ||
2524 | .chip = { | ||
2525 | .base = EXYNOS5_GPD1(0), | ||
2526 | .ngpio = EXYNOS5_GPIO_D1_NR, | ||
2527 | .label = "GPD1", | ||
2528 | }, | ||
2529 | }, { | ||
2530 | .chip = { | ||
2531 | .base = EXYNOS5_GPY0(0), | ||
2532 | .ngpio = EXYNOS5_GPIO_Y0_NR, | ||
2533 | .label = "GPY0", | ||
2534 | }, | ||
2535 | }, { | ||
2536 | .chip = { | ||
2537 | .base = EXYNOS5_GPY1(0), | ||
2538 | .ngpio = EXYNOS5_GPIO_Y1_NR, | ||
2539 | .label = "GPY1", | ||
2540 | }, | ||
2541 | }, { | ||
2542 | .chip = { | ||
2543 | .base = EXYNOS5_GPY2(0), | ||
2544 | .ngpio = EXYNOS5_GPIO_Y2_NR, | ||
2545 | .label = "GPY2", | ||
2546 | }, | ||
2547 | }, { | ||
2548 | .chip = { | ||
2549 | .base = EXYNOS5_GPY3(0), | ||
2550 | .ngpio = EXYNOS5_GPIO_Y3_NR, | ||
2551 | .label = "GPY3", | ||
2552 | }, | ||
2553 | }, { | ||
2554 | .chip = { | ||
2555 | .base = EXYNOS5_GPY4(0), | ||
2556 | .ngpio = EXYNOS5_GPIO_Y4_NR, | ||
2557 | .label = "GPY4", | ||
2558 | }, | ||
2559 | }, { | ||
2560 | .chip = { | ||
2561 | .base = EXYNOS5_GPY5(0), | ||
2562 | .ngpio = EXYNOS5_GPIO_Y5_NR, | ||
2563 | .label = "GPY5", | ||
2564 | }, | ||
2565 | }, { | ||
2566 | .chip = { | ||
2567 | .base = EXYNOS5_GPY6(0), | ||
2568 | .ngpio = EXYNOS5_GPIO_Y6_NR, | ||
2569 | .label = "GPY6", | ||
2570 | }, | ||
2571 | }, { | ||
2572 | .chip = { | ||
2573 | .base = EXYNOS5_GPC4(0), | ||
2574 | .ngpio = EXYNOS5_GPIO_C4_NR, | ||
2575 | .label = "GPC4", | ||
2576 | }, | ||
2577 | }, { | ||
2578 | .config = &samsung_gpio_cfgs[9], | ||
2579 | .irq_base = IRQ_EINT(0), | ||
2580 | .chip = { | ||
2581 | .base = EXYNOS5_GPX0(0), | ||
2582 | .ngpio = EXYNOS5_GPIO_X0_NR, | ||
2583 | .label = "GPX0", | ||
2584 | .to_irq = samsung_gpiolib_to_irq, | ||
2585 | }, | ||
2586 | }, { | ||
2587 | .config = &samsung_gpio_cfgs[9], | ||
2588 | .irq_base = IRQ_EINT(8), | ||
2589 | .chip = { | ||
2590 | .base = EXYNOS5_GPX1(0), | ||
2591 | .ngpio = EXYNOS5_GPIO_X1_NR, | ||
2592 | .label = "GPX1", | ||
2593 | .to_irq = samsung_gpiolib_to_irq, | ||
2594 | }, | ||
2595 | }, { | ||
2596 | .config = &samsung_gpio_cfgs[9], | ||
2597 | .irq_base = IRQ_EINT(16), | ||
2598 | .chip = { | ||
2599 | .base = EXYNOS5_GPX2(0), | ||
2600 | .ngpio = EXYNOS5_GPIO_X2_NR, | ||
2601 | .label = "GPX2", | ||
2602 | .to_irq = samsung_gpiolib_to_irq, | ||
2603 | }, | ||
2604 | }, { | ||
2605 | .config = &samsung_gpio_cfgs[9], | ||
2606 | .irq_base = IRQ_EINT(24), | ||
2607 | .chip = { | ||
2608 | .base = EXYNOS5_GPX3(0), | ||
2609 | .ngpio = EXYNOS5_GPIO_X3_NR, | ||
2610 | .label = "GPX3", | ||
2611 | .to_irq = samsung_gpiolib_to_irq, | ||
2612 | }, | ||
2613 | }, | ||
2614 | }; | ||
2615 | #endif | ||
2616 | |||
2617 | #ifdef CONFIG_ARCH_EXYNOS5 | ||
2618 | static struct samsung_gpio_chip exynos5_gpios_2[] = { | ||
2619 | { | ||
2620 | .chip = { | ||
2621 | .base = EXYNOS5_GPE0(0), | ||
2622 | .ngpio = EXYNOS5_GPIO_E0_NR, | ||
2623 | .label = "GPE0", | ||
2624 | }, | ||
2625 | }, { | ||
2626 | .chip = { | ||
2627 | .base = EXYNOS5_GPE1(0), | ||
2628 | .ngpio = EXYNOS5_GPIO_E1_NR, | ||
2629 | .label = "GPE1", | ||
2630 | }, | ||
2631 | }, { | ||
2632 | .chip = { | ||
2633 | .base = EXYNOS5_GPF0(0), | ||
2634 | .ngpio = EXYNOS5_GPIO_F0_NR, | ||
2635 | .label = "GPF0", | ||
2636 | }, | ||
2637 | }, { | ||
2638 | .chip = { | ||
2639 | .base = EXYNOS5_GPF1(0), | ||
2640 | .ngpio = EXYNOS5_GPIO_F1_NR, | ||
2641 | .label = "GPF1", | ||
2642 | }, | ||
2643 | }, { | ||
2644 | .chip = { | ||
2645 | .base = EXYNOS5_GPG0(0), | ||
2646 | .ngpio = EXYNOS5_GPIO_G0_NR, | ||
2647 | .label = "GPG0", | ||
2648 | }, | ||
2649 | }, { | ||
2650 | .chip = { | ||
2651 | .base = EXYNOS5_GPG1(0), | ||
2652 | .ngpio = EXYNOS5_GPIO_G1_NR, | ||
2653 | .label = "GPG1", | ||
2654 | }, | ||
2655 | }, { | ||
2656 | .chip = { | ||
2657 | .base = EXYNOS5_GPG2(0), | ||
2658 | .ngpio = EXYNOS5_GPIO_G2_NR, | ||
2659 | .label = "GPG2", | ||
2660 | }, | ||
2661 | }, { | ||
2662 | .chip = { | ||
2663 | .base = EXYNOS5_GPH0(0), | ||
2664 | .ngpio = EXYNOS5_GPIO_H0_NR, | ||
2665 | .label = "GPH0", | ||
2666 | }, | ||
2667 | }, { | ||
2668 | .chip = { | ||
2669 | .base = EXYNOS5_GPH1(0), | ||
2670 | .ngpio = EXYNOS5_GPIO_H1_NR, | ||
2671 | .label = "GPH1", | ||
2672 | |||
2673 | }, | ||
2674 | }, | ||
2675 | }; | ||
2676 | #endif | ||
2677 | |||
2678 | #ifdef CONFIG_ARCH_EXYNOS5 | ||
2679 | static struct samsung_gpio_chip exynos5_gpios_3[] = { | ||
2680 | { | ||
2681 | .chip = { | ||
2682 | .base = EXYNOS5_GPV0(0), | ||
2683 | .ngpio = EXYNOS5_GPIO_V0_NR, | ||
2684 | .label = "GPV0", | ||
2685 | }, | ||
2686 | }, { | ||
2687 | .chip = { | ||
2688 | .base = EXYNOS5_GPV1(0), | ||
2689 | .ngpio = EXYNOS5_GPIO_V1_NR, | ||
2690 | .label = "GPV1", | ||
2691 | }, | ||
2692 | }, { | ||
2693 | .chip = { | ||
2694 | .base = EXYNOS5_GPV2(0), | ||
2695 | .ngpio = EXYNOS5_GPIO_V2_NR, | ||
2696 | .label = "GPV2", | ||
2697 | }, | ||
2698 | }, { | ||
2699 | .chip = { | ||
2700 | .base = EXYNOS5_GPV3(0), | ||
2701 | .ngpio = EXYNOS5_GPIO_V3_NR, | ||
2702 | .label = "GPV3", | ||
2703 | }, | ||
2704 | }, { | ||
2705 | .chip = { | ||
2706 | .base = EXYNOS5_GPV4(0), | ||
2707 | .ngpio = EXYNOS5_GPIO_V4_NR, | ||
2708 | .label = "GPV4", | ||
2709 | }, | ||
2710 | }, | ||
2711 | }; | ||
2712 | #endif | ||
2713 | |||
2714 | #ifdef CONFIG_ARCH_EXYNOS5 | ||
2715 | static struct samsung_gpio_chip exynos5_gpios_4[] = { | ||
2716 | { | ||
2717 | .chip = { | ||
2718 | .base = EXYNOS5_GPZ(0), | ||
2719 | .ngpio = EXYNOS5_GPIO_Z_NR, | ||
2720 | .label = "GPZ", | ||
2721 | }, | ||
2722 | }, | ||
2723 | }; | ||
2724 | #endif | ||
2725 | |||
2726 | |||
2727 | #if defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) | ||
2728 | static int exynos_gpio_xlate(struct gpio_chip *gc, | ||
2729 | const struct of_phandle_args *gpiospec, u32 *flags) | ||
2730 | { | ||
2731 | unsigned int pin; | ||
2732 | |||
2733 | if (WARN_ON(gc->of_gpio_n_cells < 4)) | ||
2734 | return -EINVAL; | ||
2735 | |||
2736 | if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) | ||
2737 | return -EINVAL; | ||
2738 | |||
2739 | if (gpiospec->args[0] > gc->ngpio) | ||
2740 | return -EINVAL; | ||
2741 | |||
2742 | pin = gc->base + gpiospec->args[0]; | ||
2743 | |||
2744 | if (s3c_gpio_cfgpin(pin, S3C_GPIO_SFN(gpiospec->args[1]))) | ||
2745 | pr_warn("gpio_xlate: failed to set pin function\n"); | ||
2746 | if (s3c_gpio_setpull(pin, gpiospec->args[2] & 0xffff)) | ||
2747 | pr_warn("gpio_xlate: failed to set pin pull up/down\n"); | ||
2748 | if (s5p_gpio_set_drvstr(pin, gpiospec->args[3])) | ||
2749 | pr_warn("gpio_xlate: failed to set pin drive strength\n"); | ||
2750 | |||
2751 | if (flags) | ||
2752 | *flags = gpiospec->args[2] >> 16; | ||
2753 | |||
2754 | return gpiospec->args[0]; | ||
2755 | } | ||
2756 | |||
2757 | static const struct of_device_id exynos_gpio_dt_match[] __initdata = { | ||
2758 | { .compatible = "samsung,exynos4-gpio", }, | ||
2759 | {} | ||
2760 | }; | ||
2761 | |||
2762 | static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip, | ||
2763 | u64 base, u64 offset) | ||
2764 | { | ||
2765 | struct gpio_chip *gc = &chip->chip; | ||
2766 | u64 address; | ||
2767 | |||
2768 | if (!of_have_populated_dt()) | ||
2769 | return; | ||
2770 | |||
2771 | address = chip->base ? base + ((u32)chip->base & 0xfff) : base + offset; | ||
2772 | gc->of_node = of_find_matching_node_by_address(NULL, | ||
2773 | exynos_gpio_dt_match, address); | ||
2774 | if (!gc->of_node) { | ||
2775 | pr_info("gpio: device tree node not found for gpio controller" | ||
2776 | " with base address %08llx\n", address); | ||
2777 | return; | ||
2778 | } | ||
2779 | gc->of_gpio_n_cells = 4; | ||
2780 | gc->of_xlate = exynos_gpio_xlate; | ||
2781 | } | ||
2782 | #elif defined(CONFIG_ARCH_EXYNOS) | ||
2783 | static __init void exynos_gpiolib_attach_ofnode(struct samsung_gpio_chip *chip, | ||
2784 | u64 base, u64 offset) | ||
2785 | { | ||
2786 | return; | ||
2787 | } | ||
2788 | #endif /* defined(CONFIG_ARCH_EXYNOS) && defined(CONFIG_OF) */ | ||
2789 | |||
2790 | static __init void exynos4_gpiolib_init(void) | ||
2791 | { | ||
2792 | #ifdef CONFIG_CPU_EXYNOS4210 | ||
2793 | struct samsung_gpio_chip *chip; | ||
2794 | int i, nr_chips; | ||
2795 | void __iomem *gpio_base1, *gpio_base2, *gpio_base3; | ||
2796 | int group = 0; | ||
2797 | void __iomem *gpx_base; | ||
2798 | |||
2799 | /* gpio part1 */ | ||
2800 | gpio_base1 = ioremap(EXYNOS4_PA_GPIO1, SZ_4K); | ||
2801 | if (gpio_base1 == NULL) { | ||
2802 | pr_err("unable to ioremap for gpio_base1\n"); | ||
2803 | goto err_ioremap1; | ||
2804 | } | ||
2805 | |||
2806 | chip = exynos4_gpios_1; | ||
2807 | nr_chips = ARRAY_SIZE(exynos4_gpios_1); | ||
2808 | |||
2809 | for (i = 0; i < nr_chips; i++, chip++) { | ||
2810 | if (!chip->config) { | ||
2811 | chip->config = &exynos_gpio_cfg; | ||
2812 | chip->group = group++; | ||
2813 | } | ||
2814 | exynos_gpiolib_attach_ofnode(chip, | ||
2815 | EXYNOS4_PA_GPIO1, i * 0x20); | ||
2816 | } | ||
2817 | samsung_gpiolib_add_4bit_chips(exynos4_gpios_1, | ||
2818 | nr_chips, gpio_base1); | ||
2819 | |||
2820 | /* gpio part2 */ | ||
2821 | gpio_base2 = ioremap(EXYNOS4_PA_GPIO2, SZ_4K); | ||
2822 | if (gpio_base2 == NULL) { | ||
2823 | pr_err("unable to ioremap for gpio_base2\n"); | ||
2824 | goto err_ioremap2; | ||
2825 | } | ||
2826 | |||
2827 | /* need to set base address for gpx */ | ||
2828 | chip = &exynos4_gpios_2[16]; | ||
2829 | gpx_base = gpio_base2 + 0xC00; | ||
2830 | for (i = 0; i < 4; i++, chip++, gpx_base += 0x20) | ||
2831 | chip->base = gpx_base; | ||
2832 | |||
2833 | chip = exynos4_gpios_2; | ||
2834 | nr_chips = ARRAY_SIZE(exynos4_gpios_2); | ||
2835 | |||
2836 | for (i = 0; i < nr_chips; i++, chip++) { | ||
2837 | if (!chip->config) { | ||
2838 | chip->config = &exynos_gpio_cfg; | ||
2839 | chip->group = group++; | ||
2840 | } | ||
2841 | exynos_gpiolib_attach_ofnode(chip, | ||
2842 | EXYNOS4_PA_GPIO2, i * 0x20); | ||
2843 | } | ||
2844 | samsung_gpiolib_add_4bit_chips(exynos4_gpios_2, | ||
2845 | nr_chips, gpio_base2); | ||
2846 | |||
2847 | /* gpio part3 */ | ||
2848 | gpio_base3 = ioremap(EXYNOS4_PA_GPIO3, SZ_256); | ||
2849 | if (gpio_base3 == NULL) { | ||
2850 | pr_err("unable to ioremap for gpio_base3\n"); | ||
2851 | goto err_ioremap3; | ||
2852 | } | ||
2853 | |||
2854 | chip = exynos4_gpios_3; | ||
2855 | nr_chips = ARRAY_SIZE(exynos4_gpios_3); | ||
2856 | |||
2857 | for (i = 0; i < nr_chips; i++, chip++) { | ||
2858 | if (!chip->config) { | ||
2859 | chip->config = &exynos_gpio_cfg; | ||
2860 | chip->group = group++; | ||
2861 | } | ||
2862 | exynos_gpiolib_attach_ofnode(chip, | ||
2863 | EXYNOS4_PA_GPIO3, i * 0x20); | ||
2864 | } | ||
2865 | samsung_gpiolib_add_4bit_chips(exynos4_gpios_3, | ||
2866 | nr_chips, gpio_base3); | ||
2867 | |||
2868 | #if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT) | ||
2869 | s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS); | ||
2870 | s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS); | ||
2871 | #endif | ||
2872 | |||
2873 | return; | ||
2874 | |||
2875 | err_ioremap3: | ||
2876 | iounmap(gpio_base2); | ||
2877 | err_ioremap2: | ||
2878 | iounmap(gpio_base1); | ||
2879 | err_ioremap1: | ||
2880 | return; | ||
2881 | #endif /* CONFIG_CPU_EXYNOS4210 */ | ||
2882 | } | ||
2883 | |||
2884 | static __init void exynos5_gpiolib_init(void) | ||
2885 | { | ||
2886 | #ifdef CONFIG_SOC_EXYNOS5250 | ||
2887 | struct samsung_gpio_chip *chip; | ||
2888 | int i, nr_chips; | ||
2889 | void __iomem *gpio_base1, *gpio_base2, *gpio_base3, *gpio_base4; | ||
2890 | int group = 0; | ||
2891 | void __iomem *gpx_base; | ||
2892 | |||
2893 | /* gpio part1 */ | ||
2894 | gpio_base1 = ioremap(EXYNOS5_PA_GPIO1, SZ_4K); | ||
2895 | if (gpio_base1 == NULL) { | ||
2896 | pr_err("unable to ioremap for gpio_base1\n"); | ||
2897 | goto err_ioremap1; | ||
2898 | } | ||
2899 | |||
2900 | /* need to set base address for gpc4 */ | ||
2901 | exynos5_gpios_1[20].base = gpio_base1 + 0x2E0; | ||
2902 | |||
2903 | /* need to set base address for gpx */ | ||
2904 | chip = &exynos5_gpios_1[21]; | ||
2905 | gpx_base = gpio_base1 + 0xC00; | ||
2906 | for (i = 0; i < 4; i++, chip++, gpx_base += 0x20) | ||
2907 | chip->base = gpx_base; | ||
2908 | |||
2909 | chip = exynos5_gpios_1; | ||
2910 | nr_chips = ARRAY_SIZE(exynos5_gpios_1); | ||
2911 | |||
2912 | for (i = 0; i < nr_chips; i++, chip++) { | ||
2913 | if (!chip->config) { | ||
2914 | chip->config = &exynos_gpio_cfg; | ||
2915 | chip->group = group++; | ||
2916 | } | ||
2917 | exynos_gpiolib_attach_ofnode(chip, | ||
2918 | EXYNOS5_PA_GPIO1, i * 0x20); | ||
2919 | } | ||
2920 | samsung_gpiolib_add_4bit_chips(exynos5_gpios_1, | ||
2921 | nr_chips, gpio_base1); | ||
2922 | |||
2923 | /* gpio part2 */ | ||
2924 | gpio_base2 = ioremap(EXYNOS5_PA_GPIO2, SZ_4K); | ||
2925 | if (gpio_base2 == NULL) { | ||
2926 | pr_err("unable to ioremap for gpio_base2\n"); | ||
2927 | goto err_ioremap2; | ||
2928 | } | ||
2929 | |||
2930 | chip = exynos5_gpios_2; | ||
2931 | nr_chips = ARRAY_SIZE(exynos5_gpios_2); | ||
2932 | |||
2933 | for (i = 0; i < nr_chips; i++, chip++) { | ||
2934 | if (!chip->config) { | ||
2935 | chip->config = &exynos_gpio_cfg; | ||
2936 | chip->group = group++; | ||
2937 | } | ||
2938 | exynos_gpiolib_attach_ofnode(chip, | ||
2939 | EXYNOS5_PA_GPIO2, i * 0x20); | ||
2940 | } | ||
2941 | samsung_gpiolib_add_4bit_chips(exynos5_gpios_2, | ||
2942 | nr_chips, gpio_base2); | ||
2943 | |||
2944 | /* gpio part3 */ | ||
2945 | gpio_base3 = ioremap(EXYNOS5_PA_GPIO3, SZ_4K); | ||
2946 | if (gpio_base3 == NULL) { | ||
2947 | pr_err("unable to ioremap for gpio_base3\n"); | ||
2948 | goto err_ioremap3; | ||
2949 | } | ||
2950 | |||
2951 | /* need to set base address for gpv */ | ||
2952 | exynos5_gpios_3[0].base = gpio_base3; | ||
2953 | exynos5_gpios_3[1].base = gpio_base3 + 0x20; | ||
2954 | exynos5_gpios_3[2].base = gpio_base3 + 0x60; | ||
2955 | exynos5_gpios_3[3].base = gpio_base3 + 0x80; | ||
2956 | exynos5_gpios_3[4].base = gpio_base3 + 0xC0; | ||
2957 | |||
2958 | chip = exynos5_gpios_3; | ||
2959 | nr_chips = ARRAY_SIZE(exynos5_gpios_3); | ||
2960 | |||
2961 | for (i = 0; i < nr_chips; i++, chip++) { | ||
2962 | if (!chip->config) { | ||
2963 | chip->config = &exynos_gpio_cfg; | ||
2964 | chip->group = group++; | ||
2965 | } | ||
2966 | exynos_gpiolib_attach_ofnode(chip, | ||
2967 | EXYNOS5_PA_GPIO3, i * 0x20); | ||
2968 | } | ||
2969 | samsung_gpiolib_add_4bit_chips(exynos5_gpios_3, | ||
2970 | nr_chips, gpio_base3); | ||
2971 | |||
2972 | /* gpio part4 */ | ||
2973 | gpio_base4 = ioremap(EXYNOS5_PA_GPIO4, SZ_4K); | ||
2974 | if (gpio_base4 == NULL) { | ||
2975 | pr_err("unable to ioremap for gpio_base4\n"); | ||
2976 | goto err_ioremap4; | ||
2977 | } | ||
2978 | |||
2979 | chip = exynos5_gpios_4; | ||
2980 | nr_chips = ARRAY_SIZE(exynos5_gpios_4); | ||
2981 | |||
2982 | for (i = 0; i < nr_chips; i++, chip++) { | ||
2983 | if (!chip->config) { | ||
2984 | chip->config = &exynos_gpio_cfg; | ||
2985 | chip->group = group++; | ||
2986 | } | ||
2987 | exynos_gpiolib_attach_ofnode(chip, | ||
2988 | EXYNOS5_PA_GPIO4, i * 0x20); | ||
2989 | } | ||
2990 | samsung_gpiolib_add_4bit_chips(exynos5_gpios_4, | ||
2991 | nr_chips, gpio_base4); | ||
2992 | return; | ||
2993 | |||
2994 | err_ioremap4: | ||
2995 | iounmap(gpio_base3); | ||
2996 | err_ioremap3: | ||
2997 | iounmap(gpio_base2); | ||
2998 | err_ioremap2: | ||
2999 | iounmap(gpio_base1); | ||
3000 | err_ioremap1: | ||
3001 | return; | ||
3002 | |||
3003 | #endif /* CONFIG_SOC_EXYNOS5250 */ | ||
3004 | } | ||
3005 | |||
3006 | /* TODO: cleanup soc_is_* */ | ||
3007 | static __init int samsung_gpiolib_init(void) | ||
3008 | { | ||
3009 | struct samsung_gpio_chip *chip; | ||
3010 | int i, nr_chips; | ||
3011 | int group = 0; | ||
3012 | |||
3013 | #ifdef CONFIG_PINCTRL_SAMSUNG | ||
3014 | /* | ||
3015 | * This gpio driver includes support for device tree support and there | ||
3016 | * are platforms using it. In order to maintain compatibility with those | ||
3017 | * platforms, and to allow non-dt Exynos4210 platforms to use this | ||
3018 | * gpiolib support, a check is added to find out if there is a active | ||
3019 | * pin-controller driver support available. If it is available, this | ||
3020 | * gpiolib support is ignored and the gpiolib support available in | ||
3021 | * pin-controller driver is used. This is a temporary check and will go | ||
3022 | * away when all of the Exynos4210 platforms have switched to using | ||
3023 | * device tree and the pin-ctrl driver. | ||
3024 | */ | ||
3025 | struct device_node *pctrl_np; | ||
3026 | static const struct of_device_id exynos_pinctrl_ids[] = { | ||
3027 | { .compatible = "samsung,pinctrl-exynos4210", }, | ||
3028 | { .compatible = "samsung,pinctrl-exynos4x12", }, | ||
3029 | }; | ||
3030 | for_each_matching_node(pctrl_np, exynos_pinctrl_ids) | ||
3031 | if (pctrl_np && of_device_is_available(pctrl_np)) | ||
3032 | return -ENODEV; | ||
3033 | #endif | ||
3034 | |||
3035 | samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs)); | ||
3036 | |||
3037 | if (soc_is_s3c24xx()) { | ||
3038 | s3c24xx_gpiolib_add_chips(s3c24xx_gpios, | ||
3039 | ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO); | ||
3040 | } else if (soc_is_s3c64xx()) { | ||
3041 | samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit, | ||
3042 | ARRAY_SIZE(s3c64xx_gpios_2bit), | ||
3043 | S3C64XX_VA_GPIO + 0xE0, 0x20); | ||
3044 | samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit, | ||
3045 | ARRAY_SIZE(s3c64xx_gpios_4bit), | ||
3046 | S3C64XX_VA_GPIO); | ||
3047 | samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2, | ||
3048 | ARRAY_SIZE(s3c64xx_gpios_4bit2)); | ||
3049 | } else if (soc_is_s5p6440()) { | ||
3050 | samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit, | ||
3051 | ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0); | ||
3052 | samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit, | ||
3053 | ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO); | ||
3054 | samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2, | ||
3055 | ARRAY_SIZE(s5p6440_gpios_4bit2)); | ||
3056 | s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank, | ||
3057 | ARRAY_SIZE(s5p6440_gpios_rbank)); | ||
3058 | } else if (soc_is_s5p6450()) { | ||
3059 | samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit, | ||
3060 | ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0); | ||
3061 | samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit, | ||
3062 | ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO); | ||
3063 | samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2, | ||
3064 | ARRAY_SIZE(s5p6450_gpios_4bit2)); | ||
3065 | s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank, | ||
3066 | ARRAY_SIZE(s5p6450_gpios_rbank)); | ||
3067 | } else if (soc_is_s5pc100()) { | ||
3068 | group = 0; | ||
3069 | chip = s5pc100_gpios_4bit; | ||
3070 | nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit); | ||
3071 | |||
3072 | for (i = 0; i < nr_chips; i++, chip++) { | ||
3073 | if (!chip->config) { | ||
3074 | chip->config = &samsung_gpio_cfgs[3]; | ||
3075 | chip->group = group++; | ||
3076 | } | ||
3077 | } | ||
3078 | samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO); | ||
3079 | #if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT) | ||
3080 | s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR); | ||
3081 | #endif | ||
3082 | } else if (soc_is_s5pv210()) { | ||
3083 | group = 0; | ||
3084 | chip = s5pv210_gpios_4bit; | ||
3085 | nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit); | ||
3086 | |||
3087 | for (i = 0; i < nr_chips; i++, chip++) { | ||
3088 | if (!chip->config) { | ||
3089 | chip->config = &samsung_gpio_cfgs[3]; | ||
3090 | chip->group = group++; | ||
3091 | } | ||
3092 | } | ||
3093 | samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO); | ||
3094 | #if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT) | ||
3095 | s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR); | ||
3096 | #endif | ||
3097 | } else if (soc_is_exynos4210()) { | ||
3098 | exynos4_gpiolib_init(); | ||
3099 | } else if (soc_is_exynos5250()) { | ||
3100 | exynos5_gpiolib_init(); | ||
3101 | } else { | ||
3102 | WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n"); | ||
3103 | return -ENODEV; | ||
3104 | } | ||
3105 | |||
3106 | return 0; | ||
3107 | } | ||
3108 | core_initcall(samsung_gpiolib_init); | ||
3109 | |||
3110 | int s3c_gpio_cfgpin(unsigned int pin, unsigned int config) | ||
3111 | { | ||
3112 | struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); | ||
3113 | unsigned long flags; | ||
3114 | int offset; | ||
3115 | int ret; | ||
3116 | |||
3117 | if (!chip) | ||
3118 | return -EINVAL; | ||
3119 | |||
3120 | offset = pin - chip->chip.base; | ||
3121 | |||
3122 | samsung_gpio_lock(chip, flags); | ||
3123 | ret = samsung_gpio_do_setcfg(chip, offset, config); | ||
3124 | samsung_gpio_unlock(chip, flags); | ||
3125 | |||
3126 | return ret; | ||
3127 | } | ||
3128 | EXPORT_SYMBOL(s3c_gpio_cfgpin); | ||
3129 | |||
3130 | int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr, | ||
3131 | unsigned int cfg) | ||
3132 | { | ||
3133 | int ret; | ||
3134 | |||
3135 | for (; nr > 0; nr--, start++) { | ||
3136 | ret = s3c_gpio_cfgpin(start, cfg); | ||
3137 | if (ret != 0) | ||
3138 | return ret; | ||
3139 | } | ||
3140 | |||
3141 | return 0; | ||
3142 | } | ||
3143 | EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range); | ||
3144 | |||
3145 | int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr, | ||
3146 | unsigned int cfg, samsung_gpio_pull_t pull) | ||
3147 | { | ||
3148 | int ret; | ||
3149 | |||
3150 | for (; nr > 0; nr--, start++) { | ||
3151 | s3c_gpio_setpull(start, pull); | ||
3152 | ret = s3c_gpio_cfgpin(start, cfg); | ||
3153 | if (ret != 0) | ||
3154 | return ret; | ||
3155 | } | ||
3156 | |||
3157 | return 0; | ||
3158 | } | ||
3159 | EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range); | ||
3160 | |||
3161 | unsigned s3c_gpio_getcfg(unsigned int pin) | ||
3162 | { | ||
3163 | struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); | ||
3164 | unsigned long flags; | ||
3165 | unsigned ret = 0; | ||
3166 | int offset; | ||
3167 | |||
3168 | if (chip) { | ||
3169 | offset = pin - chip->chip.base; | ||
3170 | |||
3171 | samsung_gpio_lock(chip, flags); | ||
3172 | ret = samsung_gpio_do_getcfg(chip, offset); | ||
3173 | samsung_gpio_unlock(chip, flags); | ||
3174 | } | ||
3175 | |||
3176 | return ret; | ||
3177 | } | ||
3178 | EXPORT_SYMBOL(s3c_gpio_getcfg); | ||
3179 | |||
3180 | int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull) | ||
3181 | { | ||
3182 | struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); | ||
3183 | unsigned long flags; | ||
3184 | int offset, ret; | ||
3185 | |||
3186 | if (!chip) | ||
3187 | return -EINVAL; | ||
3188 | |||
3189 | offset = pin - chip->chip.base; | ||
3190 | |||
3191 | samsung_gpio_lock(chip, flags); | ||
3192 | ret = samsung_gpio_do_setpull(chip, offset, pull); | ||
3193 | samsung_gpio_unlock(chip, flags); | ||
3194 | |||
3195 | return ret; | ||
3196 | } | ||
3197 | EXPORT_SYMBOL(s3c_gpio_setpull); | ||
3198 | |||
3199 | samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin) | ||
3200 | { | ||
3201 | struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); | ||
3202 | unsigned long flags; | ||
3203 | int offset; | ||
3204 | u32 pup = 0; | ||
3205 | |||
3206 | if (chip) { | ||
3207 | offset = pin - chip->chip.base; | ||
3208 | |||
3209 | samsung_gpio_lock(chip, flags); | ||
3210 | pup = samsung_gpio_do_getpull(chip, offset); | ||
3211 | samsung_gpio_unlock(chip, flags); | ||
3212 | } | ||
3213 | |||
3214 | return (__force samsung_gpio_pull_t)pup; | ||
3215 | } | ||
3216 | EXPORT_SYMBOL(s3c_gpio_getpull); | ||
3217 | |||
3218 | #ifdef CONFIG_S5P_GPIO_DRVSTR | ||
3219 | s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin) | ||
3220 | { | ||
3221 | struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); | ||
3222 | unsigned int off; | ||
3223 | void __iomem *reg; | ||
3224 | int shift; | ||
3225 | u32 drvstr; | ||
3226 | |||
3227 | if (!chip) | ||
3228 | return -EINVAL; | ||
3229 | |||
3230 | off = pin - chip->chip.base; | ||
3231 | shift = off * 2; | ||
3232 | reg = chip->base + 0x0C; | ||
3233 | |||
3234 | drvstr = __raw_readl(reg); | ||
3235 | drvstr = drvstr >> shift; | ||
3236 | drvstr &= 0x3; | ||
3237 | |||
3238 | return (__force s5p_gpio_drvstr_t)drvstr; | ||
3239 | } | ||
3240 | EXPORT_SYMBOL(s5p_gpio_get_drvstr); | ||
3241 | |||
3242 | int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr) | ||
3243 | { | ||
3244 | struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); | ||
3245 | unsigned int off; | ||
3246 | void __iomem *reg; | ||
3247 | int shift; | ||
3248 | u32 tmp; | ||
3249 | |||
3250 | if (!chip) | ||
3251 | return -EINVAL; | ||
3252 | |||
3253 | off = pin - chip->chip.base; | ||
3254 | shift = off * 2; | ||
3255 | reg = chip->base + 0x0C; | ||
3256 | |||
3257 | tmp = __raw_readl(reg); | ||
3258 | tmp &= ~(0x3 << shift); | ||
3259 | tmp |= drvstr << shift; | ||
3260 | |||
3261 | __raw_writel(tmp, reg); | ||
3262 | |||
3263 | return 0; | ||
3264 | } | ||
3265 | EXPORT_SYMBOL(s5p_gpio_set_drvstr); | ||
3266 | #endif /* CONFIG_S5P_GPIO_DRVSTR */ | ||
3267 | |||
3268 | #ifdef CONFIG_PLAT_S3C24XX | ||
3269 | unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change) | ||
3270 | { | ||
3271 | unsigned long flags; | ||
3272 | unsigned long misccr; | ||
3273 | |||
3274 | local_irq_save(flags); | ||
3275 | misccr = __raw_readl(S3C24XX_MISCCR); | ||
3276 | misccr &= ~clear; | ||
3277 | misccr ^= change; | ||
3278 | __raw_writel(misccr, S3C24XX_MISCCR); | ||
3279 | local_irq_restore(flags); | ||
3280 | |||
3281 | return misccr; | ||
3282 | } | ||
3283 | EXPORT_SYMBOL(s3c2410_modify_misccr); | ||
3284 | #endif | ||
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c index edae963f462..16351584549 100644 --- a/drivers/gpio/gpio-sch.c +++ b/drivers/gpio/gpio-sch.c | |||
@@ -185,7 +185,7 @@ static struct gpio_chip sch_gpio_resume = { | |||
185 | .set = sch_gpio_resume_set, | 185 | .set = sch_gpio_resume_set, |
186 | }; | 186 | }; |
187 | 187 | ||
188 | static int sch_gpio_probe(struct platform_device *pdev) | 188 | static int __devinit sch_gpio_probe(struct platform_device *pdev) |
189 | { | 189 | { |
190 | struct resource *res; | 190 | struct resource *res; |
191 | int err, id; | 191 | int err, id; |
@@ -232,17 +232,8 @@ static int 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 | |||
243 | default: | 235 | default: |
244 | err = -ENODEV; | 236 | return -ENODEV; |
245 | goto err_sch_gpio_core; | ||
246 | } | 237 | } |
247 | 238 | ||
248 | sch_gpio_core.dev = &pdev->dev; | 239 | sch_gpio_core.dev = &pdev->dev; |
@@ -271,7 +262,7 @@ err_sch_gpio_core: | |||
271 | return err; | 262 | return err; |
272 | } | 263 | } |
273 | 264 | ||
274 | static int sch_gpio_remove(struct platform_device *pdev) | 265 | static int __devexit sch_gpio_remove(struct platform_device *pdev) |
275 | { | 266 | { |
276 | struct resource *res; | 267 | struct resource *res; |
277 | if (gpio_ba) { | 268 | if (gpio_ba) { |
@@ -303,10 +294,21 @@ static struct platform_driver sch_gpio_driver = { | |||
303 | .owner = THIS_MODULE, | 294 | .owner = THIS_MODULE, |
304 | }, | 295 | }, |
305 | .probe = sch_gpio_probe, | 296 | .probe = sch_gpio_probe, |
306 | .remove = sch_gpio_remove, | 297 | .remove = __devexit_p(sch_gpio_remove), |
307 | }; | 298 | }; |
308 | 299 | ||
309 | module_platform_driver(sch_gpio_driver); | 300 | static int __init sch_gpio_init(void) |
301 | { | ||
302 | return platform_driver_register(&sch_gpio_driver); | ||
303 | } | ||
304 | |||
305 | static void __exit sch_gpio_exit(void) | ||
306 | { | ||
307 | platform_driver_unregister(&sch_gpio_driver); | ||
308 | } | ||
309 | |||
310 | module_init(sch_gpio_init); | ||
311 | module_exit(sch_gpio_exit); | ||
310 | 312 | ||
311 | MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>"); | 313 | MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>"); |
312 | MODULE_DESCRIPTION("GPIO interface for Intel Poulsbo SCH"); | 314 | MODULE_DESCRIPTION("GPIO interface for Intel Poulsbo SCH"); |
diff --git a/drivers/gpio/gpio-sodaville.c b/drivers/gpio/gpio-sodaville.c deleted file mode 100644 index 88f374ac775..00000000000 --- a/drivers/gpio/gpio-sodaville.c +++ /dev/null | |||
@@ -1,289 +0,0 @@ | |||
1 | /* | ||
2 | * GPIO interface for Intel Sodaville SoCs. | ||
3 | * | ||
4 | * Copyright (c) 2010, 2011 Intel Corporation | ||
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 2 as published | ||
8 | * by the Free Software Foundation. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/errno.h> | ||
13 | #include <linux/gpio.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/irq.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/pci.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/of_irq.h> | ||
23 | #include <linux/basic_mmio_gpio.h> | ||
24 | |||
25 | #define DRV_NAME "sdv_gpio" | ||
26 | #define SDV_NUM_PUB_GPIOS 12 | ||
27 | #define PCI_DEVICE_ID_SDV_GPIO 0x2e67 | ||
28 | #define GPIO_BAR 0 | ||
29 | |||
30 | #define GPOUTR 0x00 | ||
31 | #define GPOER 0x04 | ||
32 | #define GPINR 0x08 | ||
33 | |||
34 | #define GPSTR 0x0c | ||
35 | #define GPIT1R0 0x10 | ||
36 | #define GPIO_INT 0x14 | ||
37 | #define GPIT1R1 0x18 | ||
38 | |||
39 | #define GPMUXCTL 0x1c | ||
40 | |||
41 | struct sdv_gpio_chip_data { | ||
42 | int irq_base; | ||
43 | void __iomem *gpio_pub_base; | ||
44 | struct irq_domain *id; | ||
45 | struct irq_chip_generic *gc; | ||
46 | struct bgpio_chip bgpio; | ||
47 | }; | ||
48 | |||
49 | static int sdv_gpio_pub_set_type(struct irq_data *d, unsigned int type) | ||
50 | { | ||
51 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | ||
52 | struct sdv_gpio_chip_data *sd = gc->private; | ||
53 | void __iomem *type_reg; | ||
54 | u32 reg; | ||
55 | |||
56 | if (d->hwirq < 8) | ||
57 | type_reg = sd->gpio_pub_base + GPIT1R0; | ||
58 | else | ||
59 | type_reg = sd->gpio_pub_base + GPIT1R1; | ||
60 | |||
61 | reg = readl(type_reg); | ||
62 | |||
63 | switch (type) { | ||
64 | case IRQ_TYPE_LEVEL_HIGH: | ||
65 | reg &= ~BIT(4 * (d->hwirq % 8)); | ||
66 | break; | ||
67 | |||
68 | case IRQ_TYPE_LEVEL_LOW: | ||
69 | reg |= BIT(4 * (d->hwirq % 8)); | ||
70 | break; | ||
71 | |||
72 | default: | ||
73 | return -EINVAL; | ||
74 | } | ||
75 | |||
76 | writel(reg, type_reg); | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static irqreturn_t sdv_gpio_pub_irq_handler(int irq, void *data) | ||
81 | { | ||
82 | struct sdv_gpio_chip_data *sd = data; | ||
83 | u32 irq_stat = readl(sd->gpio_pub_base + GPSTR); | ||
84 | |||
85 | irq_stat &= readl(sd->gpio_pub_base + GPIO_INT); | ||
86 | if (!irq_stat) | ||
87 | return IRQ_NONE; | ||
88 | |||
89 | while (irq_stat) { | ||
90 | u32 irq_bit = __fls(irq_stat); | ||
91 | |||
92 | irq_stat &= ~BIT(irq_bit); | ||
93 | generic_handle_irq(irq_find_mapping(sd->id, irq_bit)); | ||
94 | } | ||
95 | |||
96 | return IRQ_HANDLED; | ||
97 | } | ||
98 | |||
99 | static int sdv_xlate(struct irq_domain *h, struct device_node *node, | ||
100 | const u32 *intspec, u32 intsize, irq_hw_number_t *out_hwirq, | ||
101 | u32 *out_type) | ||
102 | { | ||
103 | u32 line, type; | ||
104 | |||
105 | if (node != h->of_node) | ||
106 | return -EINVAL; | ||
107 | |||
108 | if (intsize < 2) | ||
109 | return -EINVAL; | ||
110 | |||
111 | line = *intspec; | ||
112 | *out_hwirq = line; | ||
113 | |||
114 | intspec++; | ||
115 | type = *intspec; | ||
116 | |||
117 | switch (type) { | ||
118 | case IRQ_TYPE_LEVEL_LOW: | ||
119 | case IRQ_TYPE_LEVEL_HIGH: | ||
120 | *out_type = type; | ||
121 | break; | ||
122 | default: | ||
123 | return -EINVAL; | ||
124 | } | ||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | static struct irq_domain_ops irq_domain_sdv_ops = { | ||
129 | .xlate = sdv_xlate, | ||
130 | }; | ||
131 | |||
132 | static int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd, | ||
133 | struct pci_dev *pdev) | ||
134 | { | ||
135 | struct irq_chip_type *ct; | ||
136 | int ret; | ||
137 | |||
138 | sd->irq_base = irq_alloc_descs(-1, 0, SDV_NUM_PUB_GPIOS, -1); | ||
139 | if (sd->irq_base < 0) | ||
140 | return sd->irq_base; | ||
141 | |||
142 | /* mask + ACK all interrupt sources */ | ||
143 | writel(0, sd->gpio_pub_base + GPIO_INT); | ||
144 | writel((1 << 11) - 1, sd->gpio_pub_base + GPSTR); | ||
145 | |||
146 | ret = request_irq(pdev->irq, sdv_gpio_pub_irq_handler, IRQF_SHARED, | ||
147 | "sdv_gpio", sd); | ||
148 | if (ret) | ||
149 | goto out_free_desc; | ||
150 | |||
151 | /* | ||
152 | * This gpio irq controller latches level irqs. Testing shows that if | ||
153 | * we unmask & ACK the IRQ before the source of the interrupt is gone | ||
154 | * then the interrupt is active again. | ||
155 | */ | ||
156 | sd->gc = irq_alloc_generic_chip("sdv-gpio", 1, sd->irq_base, | ||
157 | sd->gpio_pub_base, handle_fasteoi_irq); | ||
158 | if (!sd->gc) { | ||
159 | ret = -ENOMEM; | ||
160 | goto out_free_irq; | ||
161 | } | ||
162 | |||
163 | sd->gc->private = sd; | ||
164 | ct = sd->gc->chip_types; | ||
165 | ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW; | ||
166 | ct->regs.eoi = GPSTR; | ||
167 | ct->regs.mask = GPIO_INT; | ||
168 | ct->chip.irq_mask = irq_gc_mask_clr_bit; | ||
169 | ct->chip.irq_unmask = irq_gc_mask_set_bit; | ||
170 | ct->chip.irq_eoi = irq_gc_eoi; | ||
171 | ct->chip.irq_set_type = sdv_gpio_pub_set_type; | ||
172 | |||
173 | irq_setup_generic_chip(sd->gc, IRQ_MSK(SDV_NUM_PUB_GPIOS), | ||
174 | IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST, | ||
175 | IRQ_LEVEL | IRQ_NOPROBE); | ||
176 | |||
177 | sd->id = irq_domain_add_legacy(pdev->dev.of_node, SDV_NUM_PUB_GPIOS, | ||
178 | sd->irq_base, 0, &irq_domain_sdv_ops, sd); | ||
179 | if (!sd->id) | ||
180 | goto out_free_irq; | ||
181 | return 0; | ||
182 | out_free_irq: | ||
183 | free_irq(pdev->irq, sd); | ||
184 | out_free_desc: | ||
185 | irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS); | ||
186 | return ret; | ||
187 | } | ||
188 | |||
189 | static int sdv_gpio_probe(struct pci_dev *pdev, | ||
190 | const struct pci_device_id *pci_id) | ||
191 | { | ||
192 | struct sdv_gpio_chip_data *sd; | ||
193 | unsigned long addr; | ||
194 | const void *prop; | ||
195 | int len; | ||
196 | int ret; | ||
197 | u32 mux_val; | ||
198 | |||
199 | sd = kzalloc(sizeof(struct sdv_gpio_chip_data), GFP_KERNEL); | ||
200 | if (!sd) | ||
201 | return -ENOMEM; | ||
202 | ret = pci_enable_device(pdev); | ||
203 | if (ret) { | ||
204 | dev_err(&pdev->dev, "can't enable device.\n"); | ||
205 | goto done; | ||
206 | } | ||
207 | |||
208 | ret = pci_request_region(pdev, GPIO_BAR, DRV_NAME); | ||
209 | if (ret) { | ||
210 | dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR); | ||
211 | goto disable_pci; | ||
212 | } | ||
213 | |||
214 | addr = pci_resource_start(pdev, GPIO_BAR); | ||
215 | if (!addr) | ||
216 | goto release_reg; | ||
217 | sd->gpio_pub_base = ioremap(addr, pci_resource_len(pdev, GPIO_BAR)); | ||
218 | |||
219 | prop = of_get_property(pdev->dev.of_node, "intel,muxctl", &len); | ||
220 | if (prop && len == 4) { | ||
221 | mux_val = of_read_number(prop, 1); | ||
222 | writel(mux_val, sd->gpio_pub_base + GPMUXCTL); | ||
223 | } | ||
224 | |||
225 | ret = bgpio_init(&sd->bgpio, &pdev->dev, 4, | ||
226 | sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR, | ||
227 | NULL, sd->gpio_pub_base + GPOER, NULL, 0); | ||
228 | if (ret) | ||
229 | goto unmap; | ||
230 | sd->bgpio.gc.ngpio = SDV_NUM_PUB_GPIOS; | ||
231 | |||
232 | ret = gpiochip_add(&sd->bgpio.gc); | ||
233 | if (ret < 0) { | ||
234 | dev_err(&pdev->dev, "gpiochip_add() failed.\n"); | ||
235 | goto unmap; | ||
236 | } | ||
237 | |||
238 | ret = sdv_register_irqsupport(sd, pdev); | ||
239 | if (ret) | ||
240 | goto unmap; | ||
241 | |||
242 | pci_set_drvdata(pdev, sd); | ||
243 | dev_info(&pdev->dev, "Sodaville GPIO driver registered.\n"); | ||
244 | return 0; | ||
245 | |||
246 | unmap: | ||
247 | iounmap(sd->gpio_pub_base); | ||
248 | release_reg: | ||
249 | pci_release_region(pdev, GPIO_BAR); | ||
250 | disable_pci: | ||
251 | pci_disable_device(pdev); | ||
252 | done: | ||
253 | kfree(sd); | ||
254 | return ret; | ||
255 | } | ||
256 | |||
257 | static void sdv_gpio_remove(struct pci_dev *pdev) | ||
258 | { | ||
259 | struct sdv_gpio_chip_data *sd = pci_get_drvdata(pdev); | ||
260 | |||
261 | free_irq(pdev->irq, sd); | ||
262 | irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS); | ||
263 | |||
264 | if (gpiochip_remove(&sd->bgpio.gc)) | ||
265 | dev_err(&pdev->dev, "gpiochip_remove() failed.\n"); | ||
266 | |||
267 | pci_release_region(pdev, GPIO_BAR); | ||
268 | iounmap(sd->gpio_pub_base); | ||
269 | pci_disable_device(pdev); | ||
270 | kfree(sd); | ||
271 | } | ||
272 | |||
273 | static DEFINE_PCI_DEVICE_TABLE(sdv_gpio_pci_ids) = { | ||
274 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_SDV_GPIO) }, | ||
275 | { 0, }, | ||
276 | }; | ||
277 | |||
278 | static struct pci_driver sdv_gpio_driver = { | ||
279 | .name = DRV_NAME, | ||
280 | .id_table = sdv_gpio_pci_ids, | ||
281 | .probe = sdv_gpio_probe, | ||
282 | .remove = sdv_gpio_remove, | ||
283 | }; | ||
284 | |||
285 | module_pci_driver(sdv_gpio_driver); | ||
286 | |||
287 | MODULE_AUTHOR("Hans J. Koch <hjk@linutronix.de>"); | ||
288 | MODULE_DESCRIPTION("GPIO interface for Intel Sodaville SoCs"); | ||
289 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/gpio/gpio-spear-spics.c b/drivers/gpio/gpio-spear-spics.c deleted file mode 100644 index 5f45fc4ed5d..00000000000 --- a/drivers/gpio/gpio-spear-spics.c +++ /dev/null | |||
@@ -1,217 +0,0 @@ | |||
1 | /* | ||
2 | * SPEAr platform SPI chipselect abstraction over gpiolib | ||
3 | * | ||
4 | * Copyright (C) 2012 ST Microelectronics | ||
5 | * Shiraz Hashim <shiraz.hashim@st.com> | ||
6 | * | ||
7 | * This file is licensed under the terms of the GNU General Public | ||
8 | * License version 2. This program is licensed "as is" without any | ||
9 | * warranty of any kind, whether express or implied. | ||
10 | */ | ||
11 | |||
12 | #include <linux/err.h> | ||
13 | #include <linux/gpio.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/of.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/types.h> | ||
19 | |||
20 | /* maximum chipselects */ | ||
21 | #define NUM_OF_GPIO 4 | ||
22 | |||
23 | /* | ||
24 | * Provision is available on some SPEAr SoCs to control ARM PL022 spi cs | ||
25 | * through system registers. This register lies outside spi (pl022) | ||
26 | * address space into system registers. | ||
27 | * | ||
28 | * It provides control for spi chip select lines so that any chipselect | ||
29 | * (out of 4 possible chipselects in pl022) can be made low to select | ||
30 | * the particular slave. | ||
31 | */ | ||
32 | |||
33 | /** | ||
34 | * struct spear_spics - represents spi chip select control | ||
35 | * @base: base address | ||
36 | * @perip_cfg: configuration register | ||
37 | * @sw_enable_bit: bit to enable s/w control over chipselects | ||
38 | * @cs_value_bit: bit to program high or low chipselect | ||
39 | * @cs_enable_mask: mask to select bits required to select chipselect | ||
40 | * @cs_enable_shift: bit pos of cs_enable_mask | ||
41 | * @use_count: use count of a spi controller cs lines | ||
42 | * @last_off: stores last offset caller of set_value() | ||
43 | * @chip: gpio_chip abstraction | ||
44 | */ | ||
45 | struct spear_spics { | ||
46 | void __iomem *base; | ||
47 | u32 perip_cfg; | ||
48 | u32 sw_enable_bit; | ||
49 | u32 cs_value_bit; | ||
50 | u32 cs_enable_mask; | ||
51 | u32 cs_enable_shift; | ||
52 | unsigned long use_count; | ||
53 | int last_off; | ||
54 | struct gpio_chip chip; | ||
55 | }; | ||
56 | |||
57 | /* gpio framework specific routines */ | ||
58 | static int spics_get_value(struct gpio_chip *chip, unsigned offset) | ||
59 | { | ||
60 | return -ENXIO; | ||
61 | } | ||
62 | |||
63 | static void spics_set_value(struct gpio_chip *chip, unsigned offset, int value) | ||
64 | { | ||
65 | struct spear_spics *spics = container_of(chip, struct spear_spics, | ||
66 | chip); | ||
67 | u32 tmp; | ||
68 | |||
69 | /* select chip select from register */ | ||
70 | tmp = readl_relaxed(spics->base + spics->perip_cfg); | ||
71 | if (spics->last_off != offset) { | ||
72 | spics->last_off = offset; | ||
73 | tmp &= ~(spics->cs_enable_mask << spics->cs_enable_shift); | ||
74 | tmp |= offset << spics->cs_enable_shift; | ||
75 | } | ||
76 | |||
77 | /* toggle chip select line */ | ||
78 | tmp &= ~(0x1 << spics->cs_value_bit); | ||
79 | tmp |= value << spics->cs_value_bit; | ||
80 | writel_relaxed(tmp, spics->base + spics->perip_cfg); | ||
81 | } | ||
82 | |||
83 | static int spics_direction_input(struct gpio_chip *chip, unsigned offset) | ||
84 | { | ||
85 | return -ENXIO; | ||
86 | } | ||
87 | |||
88 | static int spics_direction_output(struct gpio_chip *chip, unsigned offset, | ||
89 | int value) | ||
90 | { | ||
91 | spics_set_value(chip, offset, value); | ||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | static int spics_request(struct gpio_chip *chip, unsigned offset) | ||
96 | { | ||
97 | struct spear_spics *spics = container_of(chip, struct spear_spics, | ||
98 | chip); | ||
99 | u32 tmp; | ||
100 | |||
101 | if (!spics->use_count++) { | ||
102 | tmp = readl_relaxed(spics->base + spics->perip_cfg); | ||
103 | tmp |= 0x1 << spics->sw_enable_bit; | ||
104 | tmp |= 0x1 << spics->cs_value_bit; | ||
105 | writel_relaxed(tmp, spics->base + spics->perip_cfg); | ||
106 | } | ||
107 | |||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | static void spics_free(struct gpio_chip *chip, unsigned offset) | ||
112 | { | ||
113 | struct spear_spics *spics = container_of(chip, struct spear_spics, | ||
114 | chip); | ||
115 | u32 tmp; | ||
116 | |||
117 | if (!--spics->use_count) { | ||
118 | tmp = readl_relaxed(spics->base + spics->perip_cfg); | ||
119 | tmp &= ~(0x1 << spics->sw_enable_bit); | ||
120 | writel_relaxed(tmp, spics->base + spics->perip_cfg); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | static int spics_gpio_probe(struct platform_device *pdev) | ||
125 | { | ||
126 | struct device_node *np = pdev->dev.of_node; | ||
127 | struct spear_spics *spics; | ||
128 | struct resource *res; | ||
129 | int ret; | ||
130 | |||
131 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
132 | if (!res) { | ||
133 | dev_err(&pdev->dev, "invalid IORESOURCE_MEM\n"); | ||
134 | return -EBUSY; | ||
135 | } | ||
136 | |||
137 | spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); | ||
138 | if (!spics) { | ||
139 | dev_err(&pdev->dev, "memory allocation fail\n"); | ||
140 | return -ENOMEM; | ||
141 | } | ||
142 | |||
143 | spics->base = devm_request_and_ioremap(&pdev->dev, res); | ||
144 | if (!spics->base) { | ||
145 | dev_err(&pdev->dev, "request and ioremap fail\n"); | ||
146 | return -ENOMEM; | ||
147 | } | ||
148 | |||
149 | if (of_property_read_u32(np, "st-spics,peripcfg-reg", | ||
150 | &spics->perip_cfg)) | ||
151 | goto err_dt_data; | ||
152 | if (of_property_read_u32(np, "st-spics,sw-enable-bit", | ||
153 | &spics->sw_enable_bit)) | ||
154 | goto err_dt_data; | ||
155 | if (of_property_read_u32(np, "st-spics,cs-value-bit", | ||
156 | &spics->cs_value_bit)) | ||
157 | goto err_dt_data; | ||
158 | if (of_property_read_u32(np, "st-spics,cs-enable-mask", | ||
159 | &spics->cs_enable_mask)) | ||
160 | goto err_dt_data; | ||
161 | if (of_property_read_u32(np, "st-spics,cs-enable-shift", | ||
162 | &spics->cs_enable_shift)) | ||
163 | goto err_dt_data; | ||
164 | |||
165 | platform_set_drvdata(pdev, spics); | ||
166 | |||
167 | spics->chip.ngpio = NUM_OF_GPIO; | ||
168 | spics->chip.base = -1; | ||
169 | spics->chip.request = spics_request; | ||
170 | spics->chip.free = spics_free; | ||
171 | spics->chip.direction_input = spics_direction_input; | ||
172 | spics->chip.direction_output = spics_direction_output; | ||
173 | spics->chip.get = spics_get_value; | ||
174 | spics->chip.set = spics_set_value; | ||
175 | spics->chip.label = dev_name(&pdev->dev); | ||
176 | spics->chip.dev = &pdev->dev; | ||
177 | spics->chip.owner = THIS_MODULE; | ||
178 | spics->last_off = -1; | ||
179 | |||
180 | ret = gpiochip_add(&spics->chip); | ||
181 | if (ret) { | ||
182 | dev_err(&pdev->dev, "unable to add gpio chip\n"); | ||
183 | return ret; | ||
184 | } | ||
185 | |||
186 | dev_info(&pdev->dev, "spear spics registered\n"); | ||
187 | return 0; | ||
188 | |||
189 | err_dt_data: | ||
190 | dev_err(&pdev->dev, "DT probe failed\n"); | ||
191 | return -EINVAL; | ||
192 | } | ||
193 | |||
194 | static const struct of_device_id spics_gpio_of_match[] = { | ||
195 | { .compatible = "st,spear-spics-gpio" }, | ||
196 | {} | ||
197 | }; | ||
198 | MODULE_DEVICE_TABLE(of, spics_gpio_of_match); | ||
199 | |||
200 | static struct platform_driver spics_gpio_driver = { | ||
201 | .probe = spics_gpio_probe, | ||
202 | .driver = { | ||
203 | .owner = THIS_MODULE, | ||
204 | .name = "spear-spics-gpio", | ||
205 | .of_match_table = spics_gpio_of_match, | ||
206 | }, | ||
207 | }; | ||
208 | |||
209 | static int __init spics_gpio_init(void) | ||
210 | { | ||
211 | return platform_driver_register(&spics_gpio_driver); | ||
212 | } | ||
213 | subsys_initcall(spics_gpio_init); | ||
214 | |||
215 | MODULE_AUTHOR("Shiraz Hashim <shiraz.hashim@st.com>"); | ||
216 | MODULE_DESCRIPTION("ST Microlectronics SPEAr SPI Chip Select Abstraction"); | ||
217 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpio/gpio-sta2x11.c b/drivers/gpio/gpio-sta2x11.c deleted file mode 100644 index 558542552aa..00000000000 --- a/drivers/gpio/gpio-sta2x11.c +++ /dev/null | |||
@@ -1,436 +0,0 @@ | |||
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 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 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 | if (gpio_pdata) | ||
387 | for (i = 0; i < GSTA_NR_GPIO; i++) | ||
388 | gsta_set_config(chip, i, gpio_pdata->pinconfig[i]); | ||
389 | |||
390 | /* 384 was used in previous code: be compatible for other drivers */ | ||
391 | err = irq_alloc_descs(-1, 384, GSTA_NR_GPIO, NUMA_NO_NODE); | ||
392 | if (err < 0) { | ||
393 | dev_warn(&dev->dev, "sta2x11 gpio: Can't get irq base (%i)\n", | ||
394 | -err); | ||
395 | return err; | ||
396 | } | ||
397 | chip->irq_base = err; | ||
398 | gsta_alloc_irq_chip(chip); | ||
399 | |||
400 | err = request_irq(pdev->irq, gsta_gpio_handler, | ||
401 | IRQF_SHARED, KBUILD_MODNAME, chip); | ||
402 | if (err < 0) { | ||
403 | dev_err(&dev->dev, "sta2x11 gpio: Can't request irq (%i)\n", | ||
404 | -err); | ||
405 | goto err_free_descs; | ||
406 | } | ||
407 | |||
408 | err = gpiochip_add(&chip->gpio); | ||
409 | if (err < 0) { | ||
410 | dev_err(&dev->dev, "sta2x11 gpio: Can't register (%i)\n", | ||
411 | -err); | ||
412 | goto err_free_irq; | ||
413 | } | ||
414 | |||
415 | platform_set_drvdata(dev, chip); | ||
416 | return 0; | ||
417 | |||
418 | err_free_irq: | ||
419 | free_irq(pdev->irq, chip); | ||
420 | err_free_descs: | ||
421 | irq_free_descs(chip->irq_base, GSTA_NR_GPIO); | ||
422 | return err; | ||
423 | } | ||
424 | |||
425 | static struct platform_driver sta2x11_gpio_platform_driver = { | ||
426 | .driver = { | ||
427 | .name = "sta2x11-gpio", | ||
428 | .owner = THIS_MODULE, | ||
429 | }, | ||
430 | .probe = gsta_probe, | ||
431 | }; | ||
432 | |||
433 | module_platform_driver(sta2x11_gpio_platform_driver); | ||
434 | |||
435 | MODULE_LICENSE("GPL v2"); | ||
436 | MODULE_DESCRIPTION("sta2x11_gpio GPIO driver"); | ||
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c index 770476a9da8..4c980b57332 100644 --- a/drivers/gpio/gpio-stmpe.c +++ b/drivers/gpio/gpio-stmpe.c | |||
@@ -11,9 +11,7 @@ | |||
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/gpio.h> | 12 | #include <linux/gpio.h> |
13 | #include <linux/irq.h> | 13 | #include <linux/irq.h> |
14 | #include <linux/irqdomain.h> | ||
15 | #include <linux/interrupt.h> | 14 | #include <linux/interrupt.h> |
16 | #include <linux/of.h> | ||
17 | #include <linux/mfd/stmpe.h> | 15 | #include <linux/mfd/stmpe.h> |
18 | 16 | ||
19 | /* | 17 | /* |
@@ -30,7 +28,6 @@ struct stmpe_gpio { | |||
30 | struct stmpe *stmpe; | 28 | struct stmpe *stmpe; |
31 | struct device *dev; | 29 | struct device *dev; |
32 | struct mutex irq_lock; | 30 | struct mutex irq_lock; |
33 | struct irq_domain *domain; | ||
34 | 31 | ||
35 | int irq_base; | 32 | int irq_base; |
36 | unsigned norequest_mask; | 33 | unsigned norequest_mask; |
@@ -57,7 +54,7 @@ static int stmpe_gpio_get(struct gpio_chip *chip, unsigned offset) | |||
57 | if (ret < 0) | 54 | if (ret < 0) |
58 | return ret; | 55 | return ret; |
59 | 56 | ||
60 | return !!(ret & mask); | 57 | return ret & mask; |
61 | } | 58 | } |
62 | 59 | ||
63 | static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val) | 60 | static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val) |
@@ -68,14 +65,7 @@ static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val) | |||
68 | u8 reg = stmpe->regs[which] - (offset / 8); | 65 | u8 reg = stmpe->regs[which] - (offset / 8); |
69 | u8 mask = 1 << (offset % 8); | 66 | u8 mask = 1 << (offset % 8); |
70 | 67 | ||
71 | /* | 68 | stmpe_reg_write(stmpe, reg, mask); |
72 | * Some variants have single register for gpio set/clear functionality. | ||
73 | * For them we need to write 0 to clear and 1 to set. | ||
74 | */ | ||
75 | if (stmpe->regs[STMPE_IDX_GPSR_LSB] == stmpe->regs[STMPE_IDX_GPCR_LSB]) | ||
76 | stmpe_set_bits(stmpe, reg, mask, val ? mask : 0); | ||
77 | else | ||
78 | stmpe_reg_write(stmpe, reg, mask); | ||
79 | } | 69 | } |
80 | 70 | ||
81 | static int stmpe_gpio_direction_output(struct gpio_chip *chip, | 71 | static int stmpe_gpio_direction_output(struct gpio_chip *chip, |
@@ -106,7 +96,7 @@ static int stmpe_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | |||
106 | { | 96 | { |
107 | struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); | 97 | struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); |
108 | 98 | ||
109 | return irq_create_mapping(stmpe_gpio->domain, offset); | 99 | return stmpe_gpio->irq_base + offset; |
110 | } | 100 | } |
111 | 101 | ||
112 | static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset) | 102 | static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset) |
@@ -135,17 +125,13 @@ static struct gpio_chip template_chip = { | |||
135 | static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type) | 125 | static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
136 | { | 126 | { |
137 | struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); | 127 | struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); |
138 | int offset = d->hwirq; | 128 | int offset = d->irq - stmpe_gpio->irq_base; |
139 | int regoffset = offset / 8; | 129 | int regoffset = offset / 8; |
140 | int mask = 1 << (offset % 8); | 130 | int mask = 1 << (offset % 8); |
141 | 131 | ||
142 | if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) | 132 | if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) |
143 | return -EINVAL; | 133 | return -EINVAL; |
144 | 134 | ||
145 | /* STMPE801 doesn't have RE and FE registers */ | ||
146 | if (stmpe_gpio->stmpe->partnum == STMPE801) | ||
147 | return 0; | ||
148 | |||
149 | if (type == IRQ_TYPE_EDGE_RISING) | 135 | if (type == IRQ_TYPE_EDGE_RISING) |
150 | stmpe_gpio->regs[REG_RE][regoffset] |= mask; | 136 | stmpe_gpio->regs[REG_RE][regoffset] |= mask; |
151 | else | 137 | else |
@@ -179,11 +165,6 @@ static void stmpe_gpio_irq_sync_unlock(struct irq_data *d) | |||
179 | int i, j; | 165 | int i, j; |
180 | 166 | ||
181 | for (i = 0; i < CACHE_NR_REGS; i++) { | 167 | for (i = 0; i < CACHE_NR_REGS; i++) { |
182 | /* STMPE801 doesn't have RE and FE registers */ | ||
183 | if ((stmpe->partnum == STMPE801) && | ||
184 | (i != REG_IE)) | ||
185 | continue; | ||
186 | |||
187 | for (j = 0; j < num_banks; j++) { | 168 | for (j = 0; j < num_banks; j++) { |
188 | u8 old = stmpe_gpio->oldregs[i][j]; | 169 | u8 old = stmpe_gpio->oldregs[i][j]; |
189 | u8 new = stmpe_gpio->regs[i][j]; | 170 | u8 new = stmpe_gpio->regs[i][j]; |
@@ -202,7 +183,7 @@ static void stmpe_gpio_irq_sync_unlock(struct irq_data *d) | |||
202 | static void stmpe_gpio_irq_mask(struct irq_data *d) | 183 | static void stmpe_gpio_irq_mask(struct irq_data *d) |
203 | { | 184 | { |
204 | struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); | 185 | struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); |
205 | int offset = d->hwirq; | 186 | int offset = d->irq - stmpe_gpio->irq_base; |
206 | int regoffset = offset / 8; | 187 | int regoffset = offset / 8; |
207 | int mask = 1 << (offset % 8); | 188 | int mask = 1 << (offset % 8); |
208 | 189 | ||
@@ -212,7 +193,7 @@ static void stmpe_gpio_irq_mask(struct irq_data *d) | |||
212 | static void stmpe_gpio_irq_unmask(struct irq_data *d) | 193 | static void stmpe_gpio_irq_unmask(struct irq_data *d) |
213 | { | 194 | { |
214 | struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); | 195 | struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); |
215 | int offset = d->hwirq; | 196 | int offset = d->irq - stmpe_gpio->irq_base; |
216 | int regoffset = offset / 8; | 197 | int regoffset = offset / 8; |
217 | int mask = 1 << (offset % 8); | 198 | int mask = 1 << (offset % 8); |
218 | 199 | ||
@@ -254,86 +235,66 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev) | |||
254 | while (stat) { | 235 | while (stat) { |
255 | int bit = __ffs(stat); | 236 | int bit = __ffs(stat); |
256 | int line = bank * 8 + bit; | 237 | int line = bank * 8 + bit; |
257 | int virq = irq_find_mapping(stmpe_gpio->domain, line); | ||
258 | 238 | ||
259 | handle_nested_irq(virq); | 239 | handle_nested_irq(stmpe_gpio->irq_base + line); |
260 | stat &= ~(1 << bit); | 240 | stat &= ~(1 << bit); |
261 | } | 241 | } |
262 | 242 | ||
263 | stmpe_reg_write(stmpe, statmsbreg + i, status[i]); | 243 | stmpe_reg_write(stmpe, statmsbreg + i, status[i]); |
264 | 244 | stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB] + i, | |
265 | /* Edge detect register is not present on 801 */ | 245 | status[i]); |
266 | if (stmpe->partnum != STMPE801) | ||
267 | stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB] | ||
268 | + i, status[i]); | ||
269 | } | 246 | } |
270 | 247 | ||
271 | return IRQ_HANDLED; | 248 | return IRQ_HANDLED; |
272 | } | 249 | } |
273 | 250 | ||
274 | int stmpe_gpio_irq_map(struct irq_domain *d, unsigned int virq, | 251 | static int __devinit stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio) |
275 | irq_hw_number_t hwirq) | ||
276 | { | 252 | { |
277 | struct stmpe_gpio *stmpe_gpio = d->host_data; | 253 | int base = stmpe_gpio->irq_base; |
278 | 254 | int irq; | |
279 | if (!stmpe_gpio) | ||
280 | return -EINVAL; | ||
281 | 255 | ||
282 | irq_set_chip_data(hwirq, stmpe_gpio); | 256 | for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) { |
283 | irq_set_chip_and_handler(hwirq, &stmpe_gpio_irq_chip, | 257 | irq_set_chip_data(irq, stmpe_gpio); |
284 | handle_simple_irq); | 258 | irq_set_chip_and_handler(irq, &stmpe_gpio_irq_chip, |
285 | irq_set_nested_thread(hwirq, 1); | 259 | handle_simple_irq); |
260 | irq_set_nested_thread(irq, 1); | ||
286 | #ifdef CONFIG_ARM | 261 | #ifdef CONFIG_ARM |
287 | set_irq_flags(hwirq, IRQF_VALID); | 262 | set_irq_flags(irq, IRQF_VALID); |
288 | #else | 263 | #else |
289 | irq_set_noprobe(hwirq); | 264 | irq_set_noprobe(irq); |
290 | #endif | 265 | #endif |
266 | } | ||
291 | 267 | ||
292 | return 0; | 268 | return 0; |
293 | } | 269 | } |
294 | 270 | ||
295 | void stmpe_gpio_irq_unmap(struct irq_domain *d, unsigned int virq) | 271 | static void stmpe_gpio_irq_remove(struct stmpe_gpio *stmpe_gpio) |
296 | { | ||
297 | #ifdef CONFIG_ARM | ||
298 | set_irq_flags(virq, 0); | ||
299 | #endif | ||
300 | irq_set_chip_and_handler(virq, NULL, NULL); | ||
301 | irq_set_chip_data(virq, NULL); | ||
302 | } | ||
303 | |||
304 | static const struct irq_domain_ops stmpe_gpio_irq_simple_ops = { | ||
305 | .unmap = stmpe_gpio_irq_unmap, | ||
306 | .map = stmpe_gpio_irq_map, | ||
307 | .xlate = irq_domain_xlate_twocell, | ||
308 | }; | ||
309 | |||
310 | static int stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio) | ||
311 | { | 272 | { |
312 | int base = stmpe_gpio->irq_base; | 273 | int base = stmpe_gpio->irq_base; |
274 | int irq; | ||
313 | 275 | ||
314 | stmpe_gpio->domain = irq_domain_add_simple(NULL, | 276 | for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) { |
315 | stmpe_gpio->chip.ngpio, base, | 277 | #ifdef CONFIG_ARM |
316 | &stmpe_gpio_irq_simple_ops, stmpe_gpio); | 278 | set_irq_flags(irq, 0); |
317 | if (!stmpe_gpio->domain) { | 279 | #endif |
318 | dev_err(stmpe_gpio->dev, "failed to create irqdomain\n"); | 280 | irq_set_chip_and_handler(irq, NULL, NULL); |
319 | return -ENOSYS; | 281 | irq_set_chip_data(irq, NULL); |
320 | } | 282 | } |
321 | |||
322 | return 0; | ||
323 | } | 283 | } |
324 | 284 | ||
325 | static int stmpe_gpio_probe(struct platform_device *pdev) | 285 | static int __devinit stmpe_gpio_probe(struct platform_device *pdev) |
326 | { | 286 | { |
327 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); | 287 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); |
328 | struct device_node *np = pdev->dev.of_node; | ||
329 | struct stmpe_gpio_platform_data *pdata; | 288 | struct stmpe_gpio_platform_data *pdata; |
330 | struct stmpe_gpio *stmpe_gpio; | 289 | struct stmpe_gpio *stmpe_gpio; |
331 | int ret; | 290 | int ret; |
332 | int irq = 0; | 291 | int irq; |
333 | 292 | ||
334 | pdata = stmpe->pdata->gpio; | 293 | pdata = stmpe->pdata->gpio; |
335 | 294 | ||
336 | irq = platform_get_irq(pdev, 0); | 295 | irq = platform_get_irq(pdev, 0); |
296 | if (irq < 0) | ||
297 | return irq; | ||
337 | 298 | ||
338 | stmpe_gpio = kzalloc(sizeof(struct stmpe_gpio), GFP_KERNEL); | 299 | stmpe_gpio = kzalloc(sizeof(struct stmpe_gpio), GFP_KERNEL); |
339 | if (!stmpe_gpio) | 300 | if (!stmpe_gpio) |
@@ -343,39 +304,28 @@ static int stmpe_gpio_probe(struct platform_device *pdev) | |||
343 | 304 | ||
344 | stmpe_gpio->dev = &pdev->dev; | 305 | stmpe_gpio->dev = &pdev->dev; |
345 | stmpe_gpio->stmpe = stmpe; | 306 | stmpe_gpio->stmpe = stmpe; |
307 | stmpe_gpio->norequest_mask = pdata ? pdata->norequest_mask : 0; | ||
308 | |||
346 | stmpe_gpio->chip = template_chip; | 309 | stmpe_gpio->chip = template_chip; |
347 | stmpe_gpio->chip.ngpio = stmpe->num_gpios; | 310 | stmpe_gpio->chip.ngpio = stmpe->num_gpios; |
348 | stmpe_gpio->chip.dev = &pdev->dev; | 311 | stmpe_gpio->chip.dev = &pdev->dev; |
349 | stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1; | 312 | stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1; |
350 | 313 | ||
351 | if (pdata) | 314 | stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0); |
352 | stmpe_gpio->norequest_mask = pdata->norequest_mask; | ||
353 | else if (np) | ||
354 | of_property_read_u32(np, "st,norequest-mask", | ||
355 | &stmpe_gpio->norequest_mask); | ||
356 | |||
357 | if (irq >= 0) | ||
358 | stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0); | ||
359 | else | ||
360 | dev_info(&pdev->dev, | ||
361 | "device configured in no-irq mode; " | ||
362 | "irqs are not available\n"); | ||
363 | 315 | ||
364 | ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO); | 316 | ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO); |
365 | if (ret) | 317 | if (ret) |
366 | goto out_free; | 318 | goto out_free; |
367 | 319 | ||
368 | if (irq >= 0) { | 320 | ret = stmpe_gpio_irq_init(stmpe_gpio); |
369 | ret = stmpe_gpio_irq_init(stmpe_gpio); | 321 | if (ret) |
370 | if (ret) | 322 | goto out_disable; |
371 | goto out_disable; | ||
372 | 323 | ||
373 | ret = request_threaded_irq(irq, NULL, stmpe_gpio_irq, | 324 | ret = request_threaded_irq(irq, NULL, stmpe_gpio_irq, IRQF_ONESHOT, |
374 | IRQF_ONESHOT, "stmpe-gpio", stmpe_gpio); | 325 | "stmpe-gpio", stmpe_gpio); |
375 | if (ret) { | 326 | if (ret) { |
376 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); | 327 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); |
377 | goto out_disable; | 328 | goto out_removeirq; |
378 | } | ||
379 | } | 329 | } |
380 | 330 | ||
381 | ret = gpiochip_add(&stmpe_gpio->chip); | 331 | ret = gpiochip_add(&stmpe_gpio->chip); |
@@ -392,8 +342,9 @@ static int stmpe_gpio_probe(struct platform_device *pdev) | |||
392 | return 0; | 342 | return 0; |
393 | 343 | ||
394 | out_freeirq: | 344 | out_freeirq: |
395 | if (irq >= 0) | 345 | free_irq(irq, stmpe_gpio); |
396 | free_irq(irq, stmpe_gpio); | 346 | out_removeirq: |
347 | stmpe_gpio_irq_remove(stmpe_gpio); | ||
397 | out_disable: | 348 | out_disable: |
398 | stmpe_disable(stmpe, STMPE_BLOCK_GPIO); | 349 | stmpe_disable(stmpe, STMPE_BLOCK_GPIO); |
399 | out_free: | 350 | out_free: |
@@ -401,7 +352,7 @@ out_free: | |||
401 | return ret; | 352 | return ret; |
402 | } | 353 | } |
403 | 354 | ||
404 | static int stmpe_gpio_remove(struct platform_device *pdev) | 355 | static int __devexit stmpe_gpio_remove(struct platform_device *pdev) |
405 | { | 356 | { |
406 | struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev); | 357 | struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev); |
407 | struct stmpe *stmpe = stmpe_gpio->stmpe; | 358 | struct stmpe *stmpe = stmpe_gpio->stmpe; |
@@ -421,9 +372,8 @@ static int stmpe_gpio_remove(struct platform_device *pdev) | |||
421 | 372 | ||
422 | stmpe_disable(stmpe, STMPE_BLOCK_GPIO); | 373 | stmpe_disable(stmpe, STMPE_BLOCK_GPIO); |
423 | 374 | ||
424 | if (irq >= 0) | 375 | free_irq(irq, stmpe_gpio); |
425 | free_irq(irq, stmpe_gpio); | 376 | stmpe_gpio_irq_remove(stmpe_gpio); |
426 | |||
427 | platform_set_drvdata(pdev, NULL); | 377 | platform_set_drvdata(pdev, NULL); |
428 | kfree(stmpe_gpio); | 378 | kfree(stmpe_gpio); |
429 | 379 | ||
@@ -434,7 +384,7 @@ static struct platform_driver stmpe_gpio_driver = { | |||
434 | .driver.name = "stmpe-gpio", | 384 | .driver.name = "stmpe-gpio", |
435 | .driver.owner = THIS_MODULE, | 385 | .driver.owner = THIS_MODULE, |
436 | .probe = stmpe_gpio_probe, | 386 | .probe = stmpe_gpio_probe, |
437 | .remove = stmpe_gpio_remove, | 387 | .remove = __devexit_p(stmpe_gpio_remove), |
438 | }; | 388 | }; |
439 | 389 | ||
440 | static int __init stmpe_gpio_init(void) | 390 | static int __init stmpe_gpio_init(void) |
diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c deleted file mode 100644 index 85841ee70b1..00000000000 --- a/drivers/gpio/gpio-stp-xway.c +++ /dev/null | |||
@@ -1,301 +0,0 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify it | ||
3 | * under the terms of the GNU General Public License version 2 as published | ||
4 | * by the Free Software Foundation. | ||
5 | * | ||
6 | * Copyright (C) 2012 John Crispin <blogic@openwrt.org> | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | #include <linux/slab.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/types.h> | ||
14 | #include <linux/of_platform.h> | ||
15 | #include <linux/mutex.h> | ||
16 | #include <linux/gpio.h> | ||
17 | #include <linux/io.h> | ||
18 | #include <linux/of_gpio.h> | ||
19 | #include <linux/clk.h> | ||
20 | #include <linux/err.h> | ||
21 | |||
22 | #include <lantiq_soc.h> | ||
23 | |||
24 | /* | ||
25 | * The Serial To Parallel (STP) is found on MIPS based Lantiq socs. It is a | ||
26 | * peripheral controller used to drive external shift register cascades. At most | ||
27 | * 3 groups of 8 bits can be driven. The hardware is able to allow the DSL modem | ||
28 | * to drive the 2 LSBs of the cascade automatically. | ||
29 | */ | ||
30 | |||
31 | /* control register 0 */ | ||
32 | #define XWAY_STP_CON0 0x00 | ||
33 | /* control register 1 */ | ||
34 | #define XWAY_STP_CON1 0x04 | ||
35 | /* data register 0 */ | ||
36 | #define XWAY_STP_CPU0 0x08 | ||
37 | /* data register 1 */ | ||
38 | #define XWAY_STP_CPU1 0x0C | ||
39 | /* access register */ | ||
40 | #define XWAY_STP_AR 0x10 | ||
41 | |||
42 | /* software or hardware update select bit */ | ||
43 | #define XWAY_STP_CON_SWU BIT(31) | ||
44 | |||
45 | /* automatic update rates */ | ||
46 | #define XWAY_STP_2HZ 0 | ||
47 | #define XWAY_STP_4HZ BIT(23) | ||
48 | #define XWAY_STP_8HZ BIT(24) | ||
49 | #define XWAY_STP_10HZ (BIT(24) | BIT(23)) | ||
50 | #define XWAY_STP_SPEED_MASK (0xf << 23) | ||
51 | |||
52 | /* clock source for automatic update */ | ||
53 | #define XWAY_STP_UPD_FPI BIT(31) | ||
54 | #define XWAY_STP_UPD_MASK (BIT(31) | BIT(30)) | ||
55 | |||
56 | /* let the adsl core drive the 2 LSBs */ | ||
57 | #define XWAY_STP_ADSL_SHIFT 24 | ||
58 | #define XWAY_STP_ADSL_MASK 0x3 | ||
59 | |||
60 | /* 2 groups of 3 bits can be driven by the phys */ | ||
61 | #define XWAY_STP_PHY_MASK 0x3 | ||
62 | #define XWAY_STP_PHY1_SHIFT 27 | ||
63 | #define XWAY_STP_PHY2_SHIFT 15 | ||
64 | |||
65 | /* STP has 3 groups of 8 bits */ | ||
66 | #define XWAY_STP_GROUP0 BIT(0) | ||
67 | #define XWAY_STP_GROUP1 BIT(1) | ||
68 | #define XWAY_STP_GROUP2 BIT(2) | ||
69 | #define XWAY_STP_GROUP_MASK (0x7) | ||
70 | |||
71 | /* Edge configuration bits */ | ||
72 | #define XWAY_STP_FALLING BIT(26) | ||
73 | #define XWAY_STP_EDGE_MASK BIT(26) | ||
74 | |||
75 | #define xway_stp_r32(m, reg) __raw_readl(m + reg) | ||
76 | #define xway_stp_w32(m, val, reg) __raw_writel(val, m + reg) | ||
77 | #define xway_stp_w32_mask(m, clear, set, reg) \ | ||
78 | ltq_w32((ltq_r32(m + reg) & ~(clear)) | (set), \ | ||
79 | m + reg) | ||
80 | |||
81 | struct xway_stp { | ||
82 | struct gpio_chip gc; | ||
83 | void __iomem *virt; | ||
84 | u32 edge; /* rising or falling edge triggered shift register */ | ||
85 | u32 shadow; /* shadow the shift registers state */ | ||
86 | u8 groups; /* we can drive 1-3 groups of 8bit each */ | ||
87 | u8 dsl; /* the 2 LSBs can be driven by the dsl core */ | ||
88 | u8 phy1; /* 3 bits can be driven by phy1 */ | ||
89 | u8 phy2; /* 3 bits can be driven by phy2 */ | ||
90 | u8 reserved; /* mask out the hw driven bits in gpio_request */ | ||
91 | }; | ||
92 | |||
93 | /** | ||
94 | * xway_stp_set() - gpio_chip->set - set gpios. | ||
95 | * @gc: Pointer to gpio_chip device structure. | ||
96 | * @gpio: GPIO signal number. | ||
97 | * @val: Value to be written to specified signal. | ||
98 | * | ||
99 | * Set the shadow value and call ltq_ebu_apply. | ||
100 | */ | ||
101 | static void xway_stp_set(struct gpio_chip *gc, unsigned gpio, int val) | ||
102 | { | ||
103 | struct xway_stp *chip = | ||
104 | container_of(gc, struct xway_stp, gc); | ||
105 | |||
106 | if (val) | ||
107 | chip->shadow |= BIT(gpio); | ||
108 | else | ||
109 | chip->shadow &= ~BIT(gpio); | ||
110 | xway_stp_w32(chip->virt, chip->shadow, XWAY_STP_CPU0); | ||
111 | xway_stp_w32_mask(chip->virt, 0, XWAY_STP_CON_SWU, XWAY_STP_CON0); | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * xway_stp_dir_out() - gpio_chip->dir_out - set gpio direction. | ||
116 | * @gc: Pointer to gpio_chip device structure. | ||
117 | * @gpio: GPIO signal number. | ||
118 | * @val: Value to be written to specified signal. | ||
119 | * | ||
120 | * Same as xway_stp_set, always returns 0. | ||
121 | */ | ||
122 | static int xway_stp_dir_out(struct gpio_chip *gc, unsigned gpio, int val) | ||
123 | { | ||
124 | xway_stp_set(gc, gpio, val); | ||
125 | |||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | /** | ||
130 | * xway_stp_request() - gpio_chip->request | ||
131 | * @gc: Pointer to gpio_chip device structure. | ||
132 | * @gpio: GPIO signal number. | ||
133 | * | ||
134 | * We mask out the HW driven pins | ||
135 | */ | ||
136 | static int xway_stp_request(struct gpio_chip *gc, unsigned gpio) | ||
137 | { | ||
138 | struct xway_stp *chip = | ||
139 | container_of(gc, struct xway_stp, gc); | ||
140 | |||
141 | if ((gpio < 8) && (chip->reserved & BIT(gpio))) { | ||
142 | dev_err(gc->dev, "GPIO %d is driven by hardware\n", gpio); | ||
143 | return -ENODEV; | ||
144 | } | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | /** | ||
150 | * xway_stp_hw_init() - Configure the STP unit and enable the clock gate | ||
151 | * @virt: pointer to the remapped register range | ||
152 | */ | ||
153 | static int xway_stp_hw_init(struct xway_stp *chip) | ||
154 | { | ||
155 | /* sane defaults */ | ||
156 | xway_stp_w32(chip->virt, 0, XWAY_STP_AR); | ||
157 | xway_stp_w32(chip->virt, 0, XWAY_STP_CPU0); | ||
158 | xway_stp_w32(chip->virt, 0, XWAY_STP_CPU1); | ||
159 | xway_stp_w32(chip->virt, XWAY_STP_CON_SWU, XWAY_STP_CON0); | ||
160 | xway_stp_w32(chip->virt, 0, XWAY_STP_CON1); | ||
161 | |||
162 | /* apply edge trigger settings for the shift register */ | ||
163 | xway_stp_w32_mask(chip->virt, XWAY_STP_EDGE_MASK, | ||
164 | chip->edge, XWAY_STP_CON0); | ||
165 | |||
166 | /* apply led group settings */ | ||
167 | xway_stp_w32_mask(chip->virt, XWAY_STP_GROUP_MASK, | ||
168 | chip->groups, XWAY_STP_CON1); | ||
169 | |||
170 | /* tell the hardware which pins are controlled by the dsl modem */ | ||
171 | xway_stp_w32_mask(chip->virt, | ||
172 | XWAY_STP_ADSL_MASK << XWAY_STP_ADSL_SHIFT, | ||
173 | chip->dsl << XWAY_STP_ADSL_SHIFT, | ||
174 | XWAY_STP_CON0); | ||
175 | |||
176 | /* tell the hardware which pins are controlled by the phys */ | ||
177 | xway_stp_w32_mask(chip->virt, | ||
178 | XWAY_STP_PHY_MASK << XWAY_STP_PHY1_SHIFT, | ||
179 | chip->phy1 << XWAY_STP_PHY1_SHIFT, | ||
180 | XWAY_STP_CON0); | ||
181 | xway_stp_w32_mask(chip->virt, | ||
182 | XWAY_STP_PHY_MASK << XWAY_STP_PHY2_SHIFT, | ||
183 | chip->phy2 << XWAY_STP_PHY2_SHIFT, | ||
184 | XWAY_STP_CON1); | ||
185 | |||
186 | /* mask out the hw driven bits in gpio_request */ | ||
187 | chip->reserved = (chip->phy2 << 5) | (chip->phy1 << 2) | chip->dsl; | ||
188 | |||
189 | /* | ||
190 | * if we have pins that are driven by hw, we need to tell the stp what | ||
191 | * clock to use as a timer. | ||
192 | */ | ||
193 | if (chip->reserved) | ||
194 | xway_stp_w32_mask(chip->virt, XWAY_STP_UPD_MASK, | ||
195 | XWAY_STP_UPD_FPI, XWAY_STP_CON1); | ||
196 | |||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | static int xway_stp_probe(struct platform_device *pdev) | ||
201 | { | ||
202 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
203 | const __be32 *shadow, *groups, *dsl, *phy; | ||
204 | struct xway_stp *chip; | ||
205 | struct clk *clk; | ||
206 | int ret = 0; | ||
207 | |||
208 | if (!res) { | ||
209 | dev_err(&pdev->dev, "failed to request STP resource\n"); | ||
210 | return -ENOENT; | ||
211 | } | ||
212 | |||
213 | chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); | ||
214 | if (!chip) | ||
215 | return -ENOMEM; | ||
216 | |||
217 | chip->virt = devm_request_and_ioremap(&pdev->dev, res); | ||
218 | if (!chip->virt) { | ||
219 | dev_err(&pdev->dev, "failed to remap STP memory\n"); | ||
220 | return -ENOMEM; | ||
221 | } | ||
222 | chip->gc.dev = &pdev->dev; | ||
223 | chip->gc.label = "stp-xway"; | ||
224 | chip->gc.direction_output = xway_stp_dir_out; | ||
225 | chip->gc.set = xway_stp_set; | ||
226 | chip->gc.request = xway_stp_request; | ||
227 | chip->gc.base = -1; | ||
228 | chip->gc.owner = THIS_MODULE; | ||
229 | |||
230 | /* store the shadow value if one was passed by the devicetree */ | ||
231 | shadow = of_get_property(pdev->dev.of_node, "lantiq,shadow", NULL); | ||
232 | if (shadow) | ||
233 | chip->shadow = be32_to_cpu(*shadow); | ||
234 | |||
235 | /* find out which gpio groups should be enabled */ | ||
236 | groups = of_get_property(pdev->dev.of_node, "lantiq,groups", NULL); | ||
237 | if (groups) | ||
238 | chip->groups = be32_to_cpu(*groups) & XWAY_STP_GROUP_MASK; | ||
239 | else | ||
240 | chip->groups = XWAY_STP_GROUP0; | ||
241 | chip->gc.ngpio = fls(chip->groups) * 8; | ||
242 | |||
243 | /* find out which gpios are controlled by the dsl core */ | ||
244 | dsl = of_get_property(pdev->dev.of_node, "lantiq,dsl", NULL); | ||
245 | if (dsl) | ||
246 | chip->dsl = be32_to_cpu(*dsl) & XWAY_STP_ADSL_MASK; | ||
247 | |||
248 | /* find out which gpios are controlled by the phys */ | ||
249 | if (of_machine_is_compatible("lantiq,ar9") || | ||
250 | of_machine_is_compatible("lantiq,gr9") || | ||
251 | of_machine_is_compatible("lantiq,vr9")) { | ||
252 | phy = of_get_property(pdev->dev.of_node, "lantiq,phy1", NULL); | ||
253 | if (phy) | ||
254 | chip->phy1 = be32_to_cpu(*phy) & XWAY_STP_PHY_MASK; | ||
255 | phy = of_get_property(pdev->dev.of_node, "lantiq,phy2", NULL); | ||
256 | if (phy) | ||
257 | chip->phy2 = be32_to_cpu(*phy) & XWAY_STP_PHY_MASK; | ||
258 | } | ||
259 | |||
260 | /* check which edge trigger we should use, default to a falling edge */ | ||
261 | if (!of_find_property(pdev->dev.of_node, "lantiq,rising", NULL)) | ||
262 | chip->edge = XWAY_STP_FALLING; | ||
263 | |||
264 | clk = clk_get(&pdev->dev, NULL); | ||
265 | if (IS_ERR(clk)) { | ||
266 | dev_err(&pdev->dev, "Failed to get clock\n"); | ||
267 | return PTR_ERR(clk); | ||
268 | } | ||
269 | clk_enable(clk); | ||
270 | |||
271 | ret = xway_stp_hw_init(chip); | ||
272 | if (!ret) | ||
273 | ret = gpiochip_add(&chip->gc); | ||
274 | |||
275 | if (!ret) | ||
276 | dev_info(&pdev->dev, "Init done\n"); | ||
277 | |||
278 | return ret; | ||
279 | } | ||
280 | |||
281 | static const struct of_device_id xway_stp_match[] = { | ||
282 | { .compatible = "lantiq,gpio-stp-xway" }, | ||
283 | {}, | ||
284 | }; | ||
285 | MODULE_DEVICE_TABLE(of, xway_stp_match); | ||
286 | |||
287 | static struct platform_driver xway_stp_driver = { | ||
288 | .probe = xway_stp_probe, | ||
289 | .driver = { | ||
290 | .name = "gpio-stp-xway", | ||
291 | .owner = THIS_MODULE, | ||
292 | .of_match_table = xway_stp_match, | ||
293 | }, | ||
294 | }; | ||
295 | |||
296 | int __init xway_stp_init(void) | ||
297 | { | ||
298 | return platform_driver_register(&xway_stp_driver); | ||
299 | } | ||
300 | |||
301 | subsys_initcall(xway_stp_init); | ||
diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c index 796b6c42fa7..a4f73534394 100644 --- a/drivers/gpio/gpio-sx150x.c +++ b/drivers/gpio/gpio-sx150x.c | |||
@@ -311,9 +311,11 @@ static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | |||
311 | 311 | ||
312 | static void sx150x_irq_mask(struct irq_data *d) | 312 | static void sx150x_irq_mask(struct irq_data *d) |
313 | { | 313 | { |
314 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); | 314 | struct irq_chip *ic = irq_data_get_irq_chip(d); |
315 | struct sx150x_chip *chip; | ||
315 | unsigned n; | 316 | unsigned n; |
316 | 317 | ||
318 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
317 | n = d->irq - chip->irq_base; | 319 | n = d->irq - chip->irq_base; |
318 | chip->irq_masked |= (1 << n); | 320 | chip->irq_masked |= (1 << n); |
319 | chip->irq_update = n; | 321 | chip->irq_update = n; |
@@ -321,22 +323,27 @@ static void sx150x_irq_mask(struct irq_data *d) | |||
321 | 323 | ||
322 | static void sx150x_irq_unmask(struct irq_data *d) | 324 | static void sx150x_irq_unmask(struct irq_data *d) |
323 | { | 325 | { |
324 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); | 326 | struct irq_chip *ic = irq_data_get_irq_chip(d); |
327 | struct sx150x_chip *chip; | ||
325 | unsigned n; | 328 | unsigned n; |
326 | 329 | ||
330 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
327 | n = d->irq - chip->irq_base; | 331 | n = d->irq - chip->irq_base; |
332 | |||
328 | chip->irq_masked &= ~(1 << n); | 333 | chip->irq_masked &= ~(1 << n); |
329 | chip->irq_update = n; | 334 | chip->irq_update = n; |
330 | } | 335 | } |
331 | 336 | ||
332 | static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) | 337 | static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) |
333 | { | 338 | { |
334 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); | 339 | struct irq_chip *ic = irq_data_get_irq_chip(d); |
340 | struct sx150x_chip *chip; | ||
335 | unsigned n, val = 0; | 341 | unsigned n, val = 0; |
336 | 342 | ||
337 | if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) | 343 | if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) |
338 | return -EINVAL; | 344 | return -EINVAL; |
339 | 345 | ||
346 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
340 | n = d->irq - chip->irq_base; | 347 | n = d->irq - chip->irq_base; |
341 | 348 | ||
342 | if (flow_type & IRQ_TYPE_EDGE_RISING) | 349 | if (flow_type & IRQ_TYPE_EDGE_RISING) |
@@ -384,16 +391,22 @@ static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id) | |||
384 | 391 | ||
385 | static void sx150x_irq_bus_lock(struct irq_data *d) | 392 | static void sx150x_irq_bus_lock(struct irq_data *d) |
386 | { | 393 | { |
387 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); | 394 | struct irq_chip *ic = irq_data_get_irq_chip(d); |
395 | struct sx150x_chip *chip; | ||
396 | |||
397 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
388 | 398 | ||
389 | mutex_lock(&chip->lock); | 399 | mutex_lock(&chip->lock); |
390 | } | 400 | } |
391 | 401 | ||
392 | static void sx150x_irq_bus_sync_unlock(struct irq_data *d) | 402 | static void sx150x_irq_bus_sync_unlock(struct irq_data *d) |
393 | { | 403 | { |
394 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); | 404 | struct irq_chip *ic = irq_data_get_irq_chip(d); |
405 | struct sx150x_chip *chip; | ||
395 | unsigned n; | 406 | unsigned n; |
396 | 407 | ||
408 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
409 | |||
397 | if (chip->irq_update == NO_UPDATE_PENDING) | 410 | if (chip->irq_update == NO_UPDATE_PENDING) |
398 | goto out; | 411 | goto out; |
399 | 412 | ||
@@ -538,7 +551,6 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip, | |||
538 | 551 | ||
539 | for (n = 0; n < chip->dev_cfg->ngpios; ++n) { | 552 | for (n = 0; n < chip->dev_cfg->ngpios; ++n) { |
540 | irq = irq_base + n; | 553 | irq = irq_base + n; |
541 | irq_set_chip_data(irq, chip); | ||
542 | irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); | 554 | irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); |
543 | irq_set_nested_thread(irq, 1); | 555 | irq_set_nested_thread(irq, 1); |
544 | #ifdef CONFIG_ARM | 556 | #ifdef CONFIG_ARM |
@@ -575,7 +587,7 @@ static void sx150x_remove_irq_chip(struct sx150x_chip *chip) | |||
575 | } | 587 | } |
576 | } | 588 | } |
577 | 589 | ||
578 | static int sx150x_probe(struct i2c_client *client, | 590 | static int __devinit sx150x_probe(struct i2c_client *client, |
579 | const struct i2c_device_id *id) | 591 | const struct i2c_device_id *id) |
580 | { | 592 | { |
581 | static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA | | 593 | static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA | |
@@ -622,7 +634,7 @@ probe_fail_pre_gpiochip_add: | |||
622 | return rc; | 634 | return rc; |
623 | } | 635 | } |
624 | 636 | ||
625 | static int sx150x_remove(struct i2c_client *client) | 637 | static int __devexit sx150x_remove(struct i2c_client *client) |
626 | { | 638 | { |
627 | struct sx150x_chip *chip; | 639 | struct sx150x_chip *chip; |
628 | int rc; | 640 | int rc; |
@@ -646,7 +658,7 @@ static struct i2c_driver sx150x_driver = { | |||
646 | .owner = THIS_MODULE | 658 | .owner = THIS_MODULE |
647 | }, | 659 | }, |
648 | .probe = sx150x_probe, | 660 | .probe = sx150x_probe, |
649 | .remove = sx150x_remove, | 661 | .remove = __devexit_p(sx150x_remove), |
650 | .id_table = sx150x_id, | 662 | .id_table = sx150x_id, |
651 | }; | 663 | }; |
652 | 664 | ||
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c index c0595bbf326..2a82e8999a4 100644 --- a/drivers/gpio/gpio-tc3589x.c +++ b/drivers/gpio/gpio-tc3589x.c | |||
@@ -11,9 +11,7 @@ | |||
11 | #include <linux/platform_device.h> | 11 | #include <linux/platform_device.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/gpio.h> | 13 | #include <linux/gpio.h> |
14 | #include <linux/of.h> | ||
15 | #include <linux/irq.h> | 14 | #include <linux/irq.h> |
16 | #include <linux/irqdomain.h> | ||
17 | #include <linux/interrupt.h> | 15 | #include <linux/interrupt.h> |
18 | #include <linux/mfd/tc3589x.h> | 16 | #include <linux/mfd/tc3589x.h> |
19 | 17 | ||
@@ -31,7 +29,6 @@ struct tc3589x_gpio { | |||
31 | struct tc3589x *tc3589x; | 29 | struct tc3589x *tc3589x; |
32 | struct device *dev; | 30 | struct device *dev; |
33 | struct mutex irq_lock; | 31 | struct mutex irq_lock; |
34 | struct irq_domain *domain; | ||
35 | 32 | ||
36 | int irq_base; | 33 | int irq_base; |
37 | 34 | ||
@@ -95,28 +92,11 @@ static int tc3589x_gpio_direction_input(struct gpio_chip *chip, | |||
95 | return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0); | 92 | return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0); |
96 | } | 93 | } |
97 | 94 | ||
98 | /** | ||
99 | * tc3589x_gpio_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ | ||
100 | * | ||
101 | * @tc3589x_gpio: tc3589x_gpio_irq controller to operate on. | ||
102 | * @irq: index of the interrupt requested in the chip IRQs | ||
103 | * | ||
104 | * Useful for drivers to request their own IRQs. | ||
105 | */ | ||
106 | static int tc3589x_gpio_irq_get_virq(struct tc3589x_gpio *tc3589x_gpio, | ||
107 | int irq) | ||
108 | { | ||
109 | if (!tc3589x_gpio) | ||
110 | return -EINVAL; | ||
111 | |||
112 | return irq_create_mapping(tc3589x_gpio->domain, irq); | ||
113 | } | ||
114 | |||
115 | static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | 95 | static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
116 | { | 96 | { |
117 | struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); | 97 | struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); |
118 | 98 | ||
119 | return tc3589x_gpio_irq_get_virq(tc3589x_gpio, offset); | 99 | return tc3589x_gpio->irq_base + offset; |
120 | } | 100 | } |
121 | 101 | ||
122 | static struct gpio_chip template_chip = { | 102 | static struct gpio_chip template_chip = { |
@@ -133,7 +113,7 @@ static struct gpio_chip template_chip = { | |||
133 | static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) | 113 | static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
134 | { | 114 | { |
135 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); | 115 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); |
136 | int offset = d->hwirq; | 116 | int offset = d->irq - tc3589x_gpio->irq_base; |
137 | int regoffset = offset / 8; | 117 | int regoffset = offset / 8; |
138 | int mask = 1 << (offset % 8); | 118 | int mask = 1 << (offset % 8); |
139 | 119 | ||
@@ -195,7 +175,7 @@ static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d) | |||
195 | static void tc3589x_gpio_irq_mask(struct irq_data *d) | 175 | static void tc3589x_gpio_irq_mask(struct irq_data *d) |
196 | { | 176 | { |
197 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); | 177 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); |
198 | int offset = d->hwirq; | 178 | int offset = d->irq - tc3589x_gpio->irq_base; |
199 | int regoffset = offset / 8; | 179 | int regoffset = offset / 8; |
200 | int mask = 1 << (offset % 8); | 180 | int mask = 1 << (offset % 8); |
201 | 181 | ||
@@ -205,7 +185,7 @@ static void tc3589x_gpio_irq_mask(struct irq_data *d) | |||
205 | static void tc3589x_gpio_irq_unmask(struct irq_data *d) | 185 | static void tc3589x_gpio_irq_unmask(struct irq_data *d) |
206 | { | 186 | { |
207 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); | 187 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); |
208 | int offset = d->hwirq; | 188 | int offset = d->irq - tc3589x_gpio->irq_base; |
209 | int regoffset = offset / 8; | 189 | int regoffset = offset / 8; |
210 | int mask = 1 << (offset % 8); | 190 | int mask = 1 << (offset % 8); |
211 | 191 | ||
@@ -242,9 +222,8 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev) | |||
242 | while (stat) { | 222 | while (stat) { |
243 | int bit = __ffs(stat); | 223 | int bit = __ffs(stat); |
244 | int line = i * 8 + bit; | 224 | int line = i * 8 + bit; |
245 | int virq = tc3589x_gpio_irq_get_virq(tc3589x_gpio, line); | ||
246 | 225 | ||
247 | handle_nested_irq(virq); | 226 | handle_nested_irq(tc3589x_gpio->irq_base + line); |
248 | stat &= ~(1 << bit); | 227 | stat &= ~(1 << bit); |
249 | } | 228 | } |
250 | 229 | ||
@@ -254,76 +233,51 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev) | |||
254 | return IRQ_HANDLED; | 233 | return IRQ_HANDLED; |
255 | } | 234 | } |
256 | 235 | ||
257 | static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int virq, | 236 | static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio) |
258 | irq_hw_number_t hwirq) | ||
259 | { | 237 | { |
260 | struct tc3589x *tc3589x_gpio = d->host_data; | 238 | int base = tc3589x_gpio->irq_base; |
239 | int irq; | ||
261 | 240 | ||
262 | irq_set_chip_data(virq, tc3589x_gpio); | 241 | for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) { |
263 | irq_set_chip_and_handler(virq, &tc3589x_gpio_irq_chip, | 242 | irq_set_chip_data(irq, tc3589x_gpio); |
264 | handle_simple_irq); | 243 | irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip, |
265 | irq_set_nested_thread(virq, 1); | 244 | handle_simple_irq); |
245 | irq_set_nested_thread(irq, 1); | ||
266 | #ifdef CONFIG_ARM | 246 | #ifdef CONFIG_ARM |
267 | set_irq_flags(virq, IRQF_VALID); | 247 | set_irq_flags(irq, IRQF_VALID); |
268 | #else | 248 | #else |
269 | irq_set_noprobe(virq); | 249 | irq_set_noprobe(irq); |
270 | #endif | 250 | #endif |
251 | } | ||
271 | 252 | ||
272 | return 0; | 253 | return 0; |
273 | } | 254 | } |
274 | 255 | ||
275 | static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int virq) | 256 | static void tc3589x_gpio_irq_remove(struct tc3589x_gpio *tc3589x_gpio) |
276 | { | ||
277 | #ifdef CONFIG_ARM | ||
278 | set_irq_flags(virq, 0); | ||
279 | #endif | ||
280 | irq_set_chip_and_handler(virq, NULL, NULL); | ||
281 | irq_set_chip_data(virq, NULL); | ||
282 | } | ||
283 | |||
284 | static struct irq_domain_ops tc3589x_irq_ops = { | ||
285 | .map = tc3589x_gpio_irq_map, | ||
286 | .unmap = tc3589x_gpio_irq_unmap, | ||
287 | .xlate = irq_domain_xlate_twocell, | ||
288 | }; | ||
289 | |||
290 | static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio, | ||
291 | struct device_node *np) | ||
292 | { | 257 | { |
293 | int base = tc3589x_gpio->irq_base; | 258 | int base = tc3589x_gpio->irq_base; |
259 | int irq; | ||
294 | 260 | ||
295 | /* | 261 | for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) { |
296 | * If this results in a linear domain, irq_create_mapping() will | 262 | #ifdef CONFIG_ARM |
297 | * take care of allocating IRQ descriptors at runtime. When a base | 263 | set_irq_flags(irq, 0); |
298 | * is provided, the IRQ descriptors will be allocated when the | 264 | #endif |
299 | * domain is instantiated. | 265 | irq_set_chip_and_handler(irq, NULL, NULL); |
300 | */ | 266 | irq_set_chip_data(irq, NULL); |
301 | tc3589x_gpio->domain = irq_domain_add_simple(np, | ||
302 | tc3589x_gpio->chip.ngpio, base, &tc3589x_irq_ops, | ||
303 | tc3589x_gpio); | ||
304 | if (!tc3589x_gpio->domain) { | ||
305 | dev_err(tc3589x_gpio->dev, "Failed to create irqdomain\n"); | ||
306 | return -ENOSYS; | ||
307 | } | 267 | } |
308 | |||
309 | return 0; | ||
310 | } | 268 | } |
311 | 269 | ||
312 | static int tc3589x_gpio_probe(struct platform_device *pdev) | 270 | static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) |
313 | { | 271 | { |
314 | struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); | 272 | struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); |
315 | struct tc3589x_gpio_platform_data *pdata; | 273 | struct tc3589x_gpio_platform_data *pdata; |
316 | struct device_node *np = pdev->dev.of_node; | ||
317 | struct tc3589x_gpio *tc3589x_gpio; | 274 | struct tc3589x_gpio *tc3589x_gpio; |
318 | int ret; | 275 | int ret; |
319 | int irq; | 276 | int irq; |
320 | 277 | ||
321 | pdata = tc3589x->pdata->gpio; | 278 | pdata = tc3589x->pdata->gpio; |
322 | 279 | if (!pdata) | |
323 | if (!(pdata || np)) { | 280 | return -ENODEV; |
324 | dev_err(&pdev->dev, "No platform data or Device Tree found\n"); | ||
325 | return -EINVAL; | ||
326 | } | ||
327 | 281 | ||
328 | irq = platform_get_irq(pdev, 0); | 282 | irq = platform_get_irq(pdev, 0); |
329 | if (irq < 0) | 283 | if (irq < 0) |
@@ -341,14 +295,9 @@ static int tc3589x_gpio_probe(struct platform_device *pdev) | |||
341 | tc3589x_gpio->chip = template_chip; | 295 | tc3589x_gpio->chip = template_chip; |
342 | tc3589x_gpio->chip.ngpio = tc3589x->num_gpio; | 296 | tc3589x_gpio->chip.ngpio = tc3589x->num_gpio; |
343 | tc3589x_gpio->chip.dev = &pdev->dev; | 297 | tc3589x_gpio->chip.dev = &pdev->dev; |
344 | tc3589x_gpio->chip.base = (pdata) ? pdata->gpio_base : -1; | 298 | tc3589x_gpio->chip.base = pdata->gpio_base; |
345 | 299 | ||
346 | #ifdef CONFIG_OF_GPIO | 300 | tc3589x_gpio->irq_base = tc3589x->irq_base + TC3589x_INT_GPIO(0); |
347 | tc3589x_gpio->chip.of_node = np; | ||
348 | #endif | ||
349 | |||
350 | tc3589x_gpio->irq_base = tc3589x->irq_base ? | ||
351 | tc3589x->irq_base + TC3589x_INT_GPIO(0) : 0; | ||
352 | 301 | ||
353 | /* Bring the GPIO module out of reset */ | 302 | /* Bring the GPIO module out of reset */ |
354 | ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, | 303 | ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, |
@@ -356,7 +305,7 @@ static int tc3589x_gpio_probe(struct platform_device *pdev) | |||
356 | if (ret < 0) | 305 | if (ret < 0) |
357 | goto out_free; | 306 | goto out_free; |
358 | 307 | ||
359 | ret = tc3589x_gpio_irq_init(tc3589x_gpio, np); | 308 | ret = tc3589x_gpio_irq_init(tc3589x_gpio); |
360 | if (ret) | 309 | if (ret) |
361 | goto out_free; | 310 | goto out_free; |
362 | 311 | ||
@@ -364,7 +313,7 @@ static int tc3589x_gpio_probe(struct platform_device *pdev) | |||
364 | "tc3589x-gpio", tc3589x_gpio); | 313 | "tc3589x-gpio", tc3589x_gpio); |
365 | if (ret) { | 314 | if (ret) { |
366 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); | 315 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); |
367 | goto out_free; | 316 | goto out_removeirq; |
368 | } | 317 | } |
369 | 318 | ||
370 | ret = gpiochip_add(&tc3589x_gpio->chip); | 319 | ret = gpiochip_add(&tc3589x_gpio->chip); |
@@ -373,7 +322,7 @@ static int tc3589x_gpio_probe(struct platform_device *pdev) | |||
373 | goto out_freeirq; | 322 | goto out_freeirq; |
374 | } | 323 | } |
375 | 324 | ||
376 | if (pdata && pdata->setup) | 325 | if (pdata->setup) |
377 | pdata->setup(tc3589x, tc3589x_gpio->chip.base); | 326 | pdata->setup(tc3589x, tc3589x_gpio->chip.base); |
378 | 327 | ||
379 | platform_set_drvdata(pdev, tc3589x_gpio); | 328 | platform_set_drvdata(pdev, tc3589x_gpio); |
@@ -382,12 +331,14 @@ static int tc3589x_gpio_probe(struct platform_device *pdev) | |||
382 | 331 | ||
383 | out_freeirq: | 332 | out_freeirq: |
384 | free_irq(irq, tc3589x_gpio); | 333 | free_irq(irq, tc3589x_gpio); |
334 | out_removeirq: | ||
335 | tc3589x_gpio_irq_remove(tc3589x_gpio); | ||
385 | out_free: | 336 | out_free: |
386 | kfree(tc3589x_gpio); | 337 | kfree(tc3589x_gpio); |
387 | return ret; | 338 | return ret; |
388 | } | 339 | } |
389 | 340 | ||
390 | static int tc3589x_gpio_remove(struct platform_device *pdev) | 341 | static int __devexit tc3589x_gpio_remove(struct platform_device *pdev) |
391 | { | 342 | { |
392 | struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev); | 343 | struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev); |
393 | struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; | 344 | struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; |
@@ -395,7 +346,7 @@ static int tc3589x_gpio_remove(struct platform_device *pdev) | |||
395 | int irq = platform_get_irq(pdev, 0); | 346 | int irq = platform_get_irq(pdev, 0); |
396 | int ret; | 347 | int ret; |
397 | 348 | ||
398 | if (pdata && pdata->remove) | 349 | if (pdata->remove) |
399 | pdata->remove(tc3589x, tc3589x_gpio->chip.base); | 350 | pdata->remove(tc3589x, tc3589x_gpio->chip.base); |
400 | 351 | ||
401 | ret = gpiochip_remove(&tc3589x_gpio->chip); | 352 | ret = gpiochip_remove(&tc3589x_gpio->chip); |
@@ -406,6 +357,7 @@ static int tc3589x_gpio_remove(struct platform_device *pdev) | |||
406 | } | 357 | } |
407 | 358 | ||
408 | free_irq(irq, tc3589x_gpio); | 359 | free_irq(irq, tc3589x_gpio); |
360 | tc3589x_gpio_irq_remove(tc3589x_gpio); | ||
409 | 361 | ||
410 | platform_set_drvdata(pdev, NULL); | 362 | platform_set_drvdata(pdev, NULL); |
411 | kfree(tc3589x_gpio); | 363 | kfree(tc3589x_gpio); |
@@ -417,7 +369,7 @@ static struct platform_driver tc3589x_gpio_driver = { | |||
417 | .driver.name = "tc3589x-gpio", | 369 | .driver.name = "tc3589x-gpio", |
418 | .driver.owner = THIS_MODULE, | 370 | .driver.owner = THIS_MODULE, |
419 | .probe = tc3589x_gpio_probe, | 371 | .probe = tc3589x_gpio_probe, |
420 | .remove = tc3589x_gpio_remove, | 372 | .remove = __devexit_p(tc3589x_gpio_remove), |
421 | }; | 373 | }; |
422 | 374 | ||
423 | static int __init tc3589x_gpio_init(void) | 375 | static int __init tc3589x_gpio_init(void) |
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index 63cb643d4b5..3a0893f9cdc 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c | |||
@@ -6,6 +6,8 @@ | |||
6 | * Author: | 6 | * Author: |
7 | * Erik Gilling <konkers@google.com> | 7 | * Erik Gilling <konkers@google.com> |
8 | * | 8 | * |
9 | * Copyright (c) 2011 NVIDIA Corporation. | ||
10 | * | ||
9 | * This software is licensed under the terms of the GNU General Public | 11 | * This software is licensed under the terms of the GNU General Public |
10 | * License version 2, as published by the Free Software Foundation, and | 12 | * License version 2, as published by the Free Software Foundation, and |
11 | * may be copied, distributed, and modified under those terms. | 13 | * may be copied, distributed, and modified under those terms. |
@@ -20,24 +22,24 @@ | |||
20 | #include <linux/init.h> | 22 | #include <linux/init.h> |
21 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
22 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/delay.h> | ||
26 | |||
23 | #include <linux/io.h> | 27 | #include <linux/io.h> |
24 | #include <linux/gpio.h> | 28 | #include <linux/gpio.h> |
25 | #include <linux/of_device.h> | 29 | #include <linux/of.h> |
26 | #include <linux/platform_device.h> | 30 | #include <linux/syscore_ops.h> |
27 | #include <linux/module.h> | ||
28 | #include <linux/irqdomain.h> | ||
29 | #include <linux/pinctrl/consumer.h> | ||
30 | #include <linux/pm.h> | ||
31 | 31 | ||
32 | #include <asm/mach/irq.h> | 32 | #include <asm/mach/irq.h> |
33 | 33 | ||
34 | #include <mach/iomap.h> | ||
35 | #include <mach/pinmux.h> | ||
36 | |||
37 | #include "../../../arch/arm/mach-tegra/pm-irq.h" | ||
38 | |||
34 | #define GPIO_BANK(x) ((x) >> 5) | 39 | #define GPIO_BANK(x) ((x) >> 5) |
35 | #define GPIO_PORT(x) (((x) >> 3) & 0x3) | 40 | #define GPIO_PORT(x) (((x) >> 3) & 0x3) |
36 | #define GPIO_BIT(x) ((x) & 0x7) | 41 | #define GPIO_BIT(x) ((x) & 0x7) |
37 | 42 | ||
38 | #define GPIO_REG(x) (GPIO_BANK(x) * tegra_gpio_bank_stride + \ | ||
39 | GPIO_PORT(x) * 4) | ||
40 | |||
41 | #define GPIO_CNF(x) (GPIO_REG(x) + 0x00) | 43 | #define GPIO_CNF(x) (GPIO_REG(x) + 0x00) |
42 | #define GPIO_OE(x) (GPIO_REG(x) + 0x10) | 44 | #define GPIO_OE(x) (GPIO_REG(x) + 0x10) |
43 | #define GPIO_OUT(x) (GPIO_REG(x) + 0X20) | 45 | #define GPIO_OUT(x) (GPIO_REG(x) + 0X20) |
@@ -47,12 +49,29 @@ | |||
47 | #define GPIO_INT_LVL(x) (GPIO_REG(x) + 0x60) | 49 | #define GPIO_INT_LVL(x) (GPIO_REG(x) + 0x60) |
48 | #define GPIO_INT_CLR(x) (GPIO_REG(x) + 0x70) | 50 | #define GPIO_INT_CLR(x) (GPIO_REG(x) + 0x70) |
49 | 51 | ||
50 | #define GPIO_MSK_CNF(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x00) | 52 | #if defined(CONFIG_ARCH_TEGRA_2x_SOC) |
51 | #define GPIO_MSK_OE(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x10) | 53 | #define GPIO_REG(x) (IO_TO_VIRT(TEGRA_GPIO_BASE) + \ |
52 | #define GPIO_MSK_OUT(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0X20) | 54 | GPIO_BANK(x) * 0x80 + \ |
53 | #define GPIO_MSK_INT_STA(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x40) | 55 | GPIO_PORT(x) * 4) |
54 | #define GPIO_MSK_INT_ENB(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x50) | 56 | |
55 | #define GPIO_MSK_INT_LVL(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x60) | 57 | #define GPIO_MSK_CNF(x) (GPIO_REG(x) + 0x800) |
58 | #define GPIO_MSK_OE(x) (GPIO_REG(x) + 0x810) | ||
59 | #define GPIO_MSK_OUT(x) (GPIO_REG(x) + 0X820) | ||
60 | #define GPIO_MSK_INT_STA(x) (GPIO_REG(x) + 0x840) | ||
61 | #define GPIO_MSK_INT_ENB(x) (GPIO_REG(x) + 0x850) | ||
62 | #define GPIO_MSK_INT_LVL(x) (GPIO_REG(x) + 0x860) | ||
63 | #else | ||
64 | #define GPIO_REG(x) (IO_TO_VIRT(TEGRA_GPIO_BASE) + \ | ||
65 | GPIO_BANK(x) * 0x100 + \ | ||
66 | GPIO_PORT(x) * 4) | ||
67 | |||
68 | #define GPIO_MSK_CNF(x) (GPIO_REG(x) + 0x80) | ||
69 | #define GPIO_MSK_OE(x) (GPIO_REG(x) + 0x90) | ||
70 | #define GPIO_MSK_OUT(x) (GPIO_REG(x) + 0XA0) | ||
71 | #define GPIO_MSK_INT_STA(x) (GPIO_REG(x) + 0xC0) | ||
72 | #define GPIO_MSK_INT_ENB(x) (GPIO_REG(x) + 0xD0) | ||
73 | #define GPIO_MSK_INT_LVL(x) (GPIO_REG(x) + 0xE0) | ||
74 | #endif | ||
56 | 75 | ||
57 | #define GPIO_INT_LVL_MASK 0x010101 | 76 | #define GPIO_INT_LVL_MASK 0x010101 |
58 | #define GPIO_INT_LVL_EDGE_RISING 0x000101 | 77 | #define GPIO_INT_LVL_EDGE_RISING 0x000101 |
@@ -74,26 +93,28 @@ struct tegra_gpio_bank { | |||
74 | #endif | 93 | #endif |
75 | }; | 94 | }; |
76 | 95 | ||
77 | static struct irq_domain *irq_domain; | 96 | static struct tegra_gpio_bank tegra_gpio_banks[] = { |
78 | static void __iomem *regs; | 97 | {.bank = 0, .irq = INT_GPIO1}, |
79 | static u32 tegra_gpio_bank_count; | 98 | {.bank = 1, .irq = INT_GPIO2}, |
80 | static u32 tegra_gpio_bank_stride; | 99 | {.bank = 2, .irq = INT_GPIO3}, |
81 | static u32 tegra_gpio_upper_offset; | 100 | {.bank = 3, .irq = INT_GPIO4}, |
82 | static struct tegra_gpio_bank *tegra_gpio_banks; | 101 | {.bank = 4, .irq = INT_GPIO5}, |
83 | 102 | {.bank = 5, .irq = INT_GPIO6}, | |
84 | static inline void tegra_gpio_writel(u32 val, u32 reg) | 103 | {.bank = 6, .irq = INT_GPIO7}, |
85 | { | 104 | #ifndef CONFIG_ARCH_TEGRA_2x_SOC |
86 | __raw_writel(val, regs + reg); | 105 | {.bank = 7, .irq = INT_GPIO8}, |
87 | } | 106 | #endif |
107 | }; | ||
88 | 108 | ||
89 | static inline u32 tegra_gpio_readl(u32 reg) | 109 | static int tegra_gpio_compose(int bank, int port, int bit) |
90 | { | 110 | { |
91 | return __raw_readl(regs + reg); | 111 | return (bank << 5) | ((port & 0x3) << 3) | (bit & 0x7); |
92 | } | 112 | } |
93 | 113 | ||
94 | static int tegra_gpio_compose(int bank, int port, int bit) | 114 | void tegra_gpio_set_tristate(int gpio_nr, enum tegra_tristate ts) |
95 | { | 115 | { |
96 | return (bank << 5) | ((port & 0x3) << 3) | (bit & 0x7); | 116 | int pin_group = tegra_pinmux_get_pingroup(gpio_nr); |
117 | tegra_pinmux_set_tristate(pin_group, ts); | ||
97 | } | 118 | } |
98 | 119 | ||
99 | static void tegra_gpio_mask_write(u32 reg, int gpio, int value) | 120 | static void tegra_gpio_mask_write(u32 reg, int gpio, int value) |
@@ -103,28 +124,55 @@ static void tegra_gpio_mask_write(u32 reg, int gpio, int value) | |||
103 | val = 0x100 << GPIO_BIT(gpio); | 124 | val = 0x100 << GPIO_BIT(gpio); |
104 | if (value) | 125 | if (value) |
105 | val |= 1 << GPIO_BIT(gpio); | 126 | val |= 1 << GPIO_BIT(gpio); |
106 | tegra_gpio_writel(val, reg); | 127 | __raw_writel(val, reg); |
107 | } | 128 | } |
108 | 129 | ||
109 | static void tegra_gpio_enable(int gpio) | 130 | int tegra_gpio_get_bank_int_nr(int gpio) |
110 | { | 131 | { |
111 | tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1); | 132 | int bank; |
133 | int irq; | ||
134 | if (gpio >= TEGRA_NR_GPIOS) { | ||
135 | pr_warn("%s : Invalid gpio ID - %d\n", __func__, gpio); | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | bank = gpio >> 5; | ||
139 | irq = tegra_gpio_banks[bank].irq; | ||
140 | return irq; | ||
112 | } | 141 | } |
113 | 142 | ||
114 | static void tegra_gpio_disable(int gpio) | 143 | void tegra_gpio_enable(int gpio) |
115 | { | 144 | { |
116 | tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 0); | 145 | if (gpio >= TEGRA_NR_GPIOS) { |
146 | pr_warn("%s : Invalid gpio ID - %d\n", __func__, gpio); | ||
147 | return; | ||
148 | } | ||
149 | tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1); | ||
117 | } | 150 | } |
151 | EXPORT_SYMBOL_GPL(tegra_gpio_enable); | ||
118 | 152 | ||
119 | static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset) | 153 | void tegra_gpio_disable(int gpio) |
120 | { | 154 | { |
121 | return pinctrl_request_gpio(offset); | 155 | if (gpio >= TEGRA_NR_GPIOS) { |
156 | pr_warn("%s : Invalid gpio ID - %d\n", __func__, gpio); | ||
157 | return; | ||
158 | } | ||
159 | tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 0); | ||
122 | } | 160 | } |
161 | EXPORT_SYMBOL_GPL(tegra_gpio_disable); | ||
123 | 162 | ||
124 | static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset) | 163 | void tegra_gpio_init_configure(unsigned gpio, bool is_input, int value) |
125 | { | 164 | { |
126 | pinctrl_free_gpio(offset); | 165 | if (gpio >= TEGRA_NR_GPIOS) { |
127 | tegra_gpio_disable(offset); | 166 | pr_warn("%s : Invalid gpio ID - %d\n", __func__, gpio); |
167 | return; | ||
168 | } | ||
169 | if (is_input) { | ||
170 | tegra_gpio_mask_write(GPIO_MSK_OE(gpio), gpio, 0); | ||
171 | } else { | ||
172 | tegra_gpio_mask_write(GPIO_MSK_OUT(gpio), gpio, value); | ||
173 | tegra_gpio_mask_write(GPIO_MSK_OE(gpio), gpio, 1); | ||
174 | } | ||
175 | tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1); | ||
128 | } | 176 | } |
129 | 177 | ||
130 | static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 178 | static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
@@ -134,18 +182,15 @@ static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | |||
134 | 182 | ||
135 | static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset) | 183 | static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset) |
136 | { | 184 | { |
137 | /* If gpio is in output mode then read from the out value */ | 185 | if ((__raw_readl(GPIO_OE(offset)) >> GPIO_BIT(offset)) & 0x1) |
138 | if ((tegra_gpio_readl(GPIO_OE(offset)) >> GPIO_BIT(offset)) & 1) | 186 | return (__raw_readl(GPIO_OUT(offset)) >> |
139 | return (tegra_gpio_readl(GPIO_OUT(offset)) >> | 187 | GPIO_BIT(offset)) & 0x1; |
140 | GPIO_BIT(offset)) & 0x1; | 188 | return (__raw_readl(GPIO_IN(offset)) >> GPIO_BIT(offset)) & 0x1; |
141 | |||
142 | return (tegra_gpio_readl(GPIO_IN(offset)) >> GPIO_BIT(offset)) & 0x1; | ||
143 | } | 189 | } |
144 | 190 | ||
145 | static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | 191 | static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
146 | { | 192 | { |
147 | tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0); | 193 | tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0); |
148 | tegra_gpio_enable(offset); | ||
149 | return 0; | 194 | return 0; |
150 | } | 195 | } |
151 | 196 | ||
@@ -154,51 +199,65 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset, | |||
154 | { | 199 | { |
155 | tegra_gpio_set(chip, offset, value); | 200 | tegra_gpio_set(chip, offset, value); |
156 | tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1); | 201 | tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1); |
157 | tegra_gpio_enable(offset); | ||
158 | return 0; | 202 | return 0; |
159 | } | 203 | } |
160 | 204 | ||
205 | static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, | ||
206 | unsigned debounce) | ||
207 | { | ||
208 | return -ENOSYS; | ||
209 | } | ||
210 | |||
161 | static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | 211 | static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
162 | { | 212 | { |
163 | return irq_find_mapping(irq_domain, offset); | 213 | return TEGRA_GPIO_TO_IRQ(offset); |
164 | } | 214 | } |
165 | 215 | ||
166 | static struct gpio_chip tegra_gpio_chip = { | 216 | static struct gpio_chip tegra_gpio_chip = { |
167 | .label = "tegra-gpio", | 217 | .label = "tegra-gpio", |
168 | .request = tegra_gpio_request, | ||
169 | .free = tegra_gpio_free, | ||
170 | .direction_input = tegra_gpio_direction_input, | 218 | .direction_input = tegra_gpio_direction_input, |
171 | .get = tegra_gpio_get, | 219 | .get = tegra_gpio_get, |
172 | .direction_output = tegra_gpio_direction_output, | 220 | .direction_output = tegra_gpio_direction_output, |
173 | .set = tegra_gpio_set, | 221 | .set = tegra_gpio_set, |
222 | .set_debounce = tegra_gpio_set_debounce, | ||
174 | .to_irq = tegra_gpio_to_irq, | 223 | .to_irq = tegra_gpio_to_irq, |
175 | .base = 0, | 224 | .base = 0, |
225 | .ngpio = TEGRA_NR_GPIOS, | ||
176 | }; | 226 | }; |
177 | 227 | ||
178 | static void tegra_gpio_irq_ack(struct irq_data *d) | 228 | static void tegra_gpio_irq_ack(struct irq_data *d) |
179 | { | 229 | { |
180 | int gpio = d->hwirq; | 230 | int gpio = d->irq - INT_GPIO_BASE; |
231 | |||
232 | __raw_writel(1 << GPIO_BIT(gpio), GPIO_INT_CLR(gpio)); | ||
181 | 233 | ||
182 | tegra_gpio_writel(1 << GPIO_BIT(gpio), GPIO_INT_CLR(gpio)); | 234 | #ifdef CONFIG_TEGRA_FPGA_PLATFORM |
235 | /* FPGA platforms have a serializer between the GPIO | ||
236 | block and interrupt controller. Allow time for | ||
237 | clearing of the GPIO interrupt to propagate to the | ||
238 | interrupt controller before re-enabling the IRQ | ||
239 | to prevent double interrupts. */ | ||
240 | udelay(15); | ||
241 | #endif | ||
183 | } | 242 | } |
184 | 243 | ||
185 | static void tegra_gpio_irq_mask(struct irq_data *d) | 244 | static void tegra_gpio_irq_mask(struct irq_data *d) |
186 | { | 245 | { |
187 | int gpio = d->hwirq; | 246 | int gpio = d->irq - INT_GPIO_BASE; |
188 | 247 | ||
189 | tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 0); | 248 | tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 0); |
190 | } | 249 | } |
191 | 250 | ||
192 | static void tegra_gpio_irq_unmask(struct irq_data *d) | 251 | static void tegra_gpio_irq_unmask(struct irq_data *d) |
193 | { | 252 | { |
194 | int gpio = d->hwirq; | 253 | int gpio = d->irq - INT_GPIO_BASE; |
195 | 254 | ||
196 | tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 1); | 255 | tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 1); |
197 | } | 256 | } |
198 | 257 | ||
199 | static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) | 258 | static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
200 | { | 259 | { |
201 | int gpio = d->hwirq; | 260 | int gpio = d->irq - INT_GPIO_BASE; |
202 | struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 261 | struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
203 | int port = GPIO_PORT(gpio); | 262 | int port = GPIO_PORT(gpio); |
204 | int lvl_type; | 263 | int lvl_type; |
@@ -232,21 +291,20 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) | |||
232 | 291 | ||
233 | spin_lock_irqsave(&bank->lvl_lock[port], flags); | 292 | spin_lock_irqsave(&bank->lvl_lock[port], flags); |
234 | 293 | ||
235 | val = tegra_gpio_readl(GPIO_INT_LVL(gpio)); | 294 | val = __raw_readl(GPIO_INT_LVL(gpio)); |
236 | val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio)); | 295 | val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio)); |
237 | val |= lvl_type << GPIO_BIT(gpio); | 296 | val |= lvl_type << GPIO_BIT(gpio); |
238 | tegra_gpio_writel(val, GPIO_INT_LVL(gpio)); | 297 | __raw_writel(val, GPIO_INT_LVL(gpio)); |
239 | 298 | ||
240 | spin_unlock_irqrestore(&bank->lvl_lock[port], flags); | 299 | spin_unlock_irqrestore(&bank->lvl_lock[port], flags); |
241 | 300 | ||
242 | tegra_gpio_mask_write(GPIO_MSK_OE(gpio), gpio, 0); | ||
243 | tegra_gpio_enable(gpio); | ||
244 | |||
245 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) | 301 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
246 | __irq_set_handler_locked(d->irq, handle_level_irq); | 302 | __irq_set_handler_locked(d->irq, handle_level_irq); |
247 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) | 303 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
248 | __irq_set_handler_locked(d->irq, handle_edge_irq); | 304 | __irq_set_handler_locked(d->irq, handle_edge_irq); |
249 | 305 | ||
306 | tegra_pm_irq_set_wake_type(d->irq, type); | ||
307 | |||
250 | return 0; | 308 | return 0; |
251 | } | 309 | } |
252 | 310 | ||
@@ -255,7 +313,6 @@ static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
255 | struct tegra_gpio_bank *bank; | 313 | struct tegra_gpio_bank *bank; |
256 | int port; | 314 | int port; |
257 | int pin; | 315 | int pin; |
258 | int unmasked = 0; | ||
259 | struct irq_chip *chip = irq_desc_get_chip(desc); | 316 | struct irq_chip *chip = irq_desc_get_chip(desc); |
260 | 317 | ||
261 | chained_irq_enter(chip, desc); | 318 | chained_irq_enter(chip, desc); |
@@ -264,33 +321,19 @@ static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
264 | 321 | ||
265 | for (port = 0; port < 4; port++) { | 322 | for (port = 0; port < 4; port++) { |
266 | int gpio = tegra_gpio_compose(bank->bank, port, 0); | 323 | int gpio = tegra_gpio_compose(bank->bank, port, 0); |
267 | unsigned long sta = tegra_gpio_readl(GPIO_INT_STA(gpio)) & | 324 | unsigned long sta = __raw_readl(GPIO_INT_STA(gpio)) & |
268 | tegra_gpio_readl(GPIO_INT_ENB(gpio)); | 325 | __raw_readl(GPIO_INT_ENB(gpio)); |
269 | u32 lvl = tegra_gpio_readl(GPIO_INT_LVL(gpio)); | ||
270 | |||
271 | for_each_set_bit(pin, &sta, 8) { | ||
272 | tegra_gpio_writel(1 << pin, GPIO_INT_CLR(gpio)); | ||
273 | |||
274 | /* if gpio is edge triggered, clear condition | ||
275 | * before executing the hander so that we don't | ||
276 | * miss edges | ||
277 | */ | ||
278 | if (lvl & (0x100 << pin)) { | ||
279 | unmasked = 1; | ||
280 | chained_irq_exit(chip, desc); | ||
281 | } | ||
282 | 326 | ||
327 | for_each_set_bit(pin, &sta, 8) | ||
283 | generic_handle_irq(gpio_to_irq(gpio + pin)); | 328 | generic_handle_irq(gpio_to_irq(gpio + pin)); |
284 | } | ||
285 | } | 329 | } |
286 | 330 | ||
287 | if (!unmasked) | 331 | chained_irq_exit(chip, desc); |
288 | chained_irq_exit(chip, desc); | ||
289 | 332 | ||
290 | } | 333 | } |
291 | 334 | ||
292 | #ifdef CONFIG_PM_SLEEP | 335 | #ifdef CONFIG_PM_SLEEP |
293 | static int tegra_gpio_resume(struct device *dev) | 336 | static void tegra_gpio_resume(void) |
294 | { | 337 | { |
295 | unsigned long flags; | 338 | unsigned long flags; |
296 | int b; | 339 | int b; |
@@ -298,179 +341,125 @@ static int tegra_gpio_resume(struct device *dev) | |||
298 | 341 | ||
299 | local_irq_save(flags); | 342 | local_irq_save(flags); |
300 | 343 | ||
301 | for (b = 0; b < tegra_gpio_bank_count; b++) { | 344 | for (b = 0; b < ARRAY_SIZE(tegra_gpio_banks); b++) { |
302 | struct tegra_gpio_bank *bank = &tegra_gpio_banks[b]; | 345 | struct tegra_gpio_bank *bank = &tegra_gpio_banks[b]; |
303 | 346 | ||
304 | for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { | 347 | for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { |
305 | unsigned int gpio = (b<<5) | (p<<3); | 348 | unsigned int gpio = (b<<5) | (p<<3); |
306 | tegra_gpio_writel(bank->cnf[p], GPIO_CNF(gpio)); | 349 | __raw_writel(bank->cnf[p], GPIO_CNF(gpio)); |
307 | tegra_gpio_writel(bank->out[p], GPIO_OUT(gpio)); | 350 | __raw_writel(bank->out[p], GPIO_OUT(gpio)); |
308 | tegra_gpio_writel(bank->oe[p], GPIO_OE(gpio)); | 351 | __raw_writel(bank->oe[p], GPIO_OE(gpio)); |
309 | tegra_gpio_writel(bank->int_lvl[p], GPIO_INT_LVL(gpio)); | 352 | __raw_writel(bank->int_lvl[p], GPIO_INT_LVL(gpio)); |
310 | tegra_gpio_writel(bank->int_enb[p], GPIO_INT_ENB(gpio)); | 353 | __raw_writel(bank->int_enb[p], GPIO_INT_ENB(gpio)); |
311 | } | 354 | } |
312 | } | 355 | } |
313 | 356 | ||
314 | local_irq_restore(flags); | 357 | local_irq_restore(flags); |
315 | return 0; | ||
316 | } | 358 | } |
317 | 359 | ||
318 | static int tegra_gpio_suspend(struct device *dev) | 360 | static int tegra_gpio_suspend(void) |
319 | { | 361 | { |
320 | unsigned long flags; | 362 | unsigned long flags; |
321 | int b; | 363 | int b; |
322 | int p; | 364 | int p; |
323 | 365 | ||
324 | local_irq_save(flags); | 366 | local_irq_save(flags); |
325 | for (b = 0; b < tegra_gpio_bank_count; b++) { | 367 | for (b = 0; b < ARRAY_SIZE(tegra_gpio_banks); b++) { |
326 | struct tegra_gpio_bank *bank = &tegra_gpio_banks[b]; | 368 | struct tegra_gpio_bank *bank = &tegra_gpio_banks[b]; |
327 | 369 | ||
328 | for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { | 370 | for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { |
329 | unsigned int gpio = (b<<5) | (p<<3); | 371 | unsigned int gpio = (b<<5) | (p<<3); |
330 | bank->cnf[p] = tegra_gpio_readl(GPIO_CNF(gpio)); | 372 | bank->cnf[p] = __raw_readl(GPIO_CNF(gpio)); |
331 | bank->out[p] = tegra_gpio_readl(GPIO_OUT(gpio)); | 373 | bank->out[p] = __raw_readl(GPIO_OUT(gpio)); |
332 | bank->oe[p] = tegra_gpio_readl(GPIO_OE(gpio)); | 374 | bank->oe[p] = __raw_readl(GPIO_OE(gpio)); |
333 | bank->int_enb[p] = tegra_gpio_readl(GPIO_INT_ENB(gpio)); | 375 | bank->int_enb[p] = __raw_readl(GPIO_INT_ENB(gpio)); |
334 | bank->int_lvl[p] = tegra_gpio_readl(GPIO_INT_LVL(gpio)); | 376 | bank->int_lvl[p] = __raw_readl(GPIO_INT_LVL(gpio)); |
335 | } | 377 | } |
336 | } | 378 | } |
337 | local_irq_restore(flags); | 379 | local_irq_restore(flags); |
380 | |||
338 | return 0; | 381 | return 0; |
339 | } | 382 | } |
340 | 383 | ||
341 | static int tegra_gpio_wake_enable(struct irq_data *d, unsigned int enable) | 384 | static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable) |
342 | { | 385 | { |
343 | struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 386 | struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); |
344 | return irq_set_irq_wake(bank->irq, enable); | 387 | int ret = 0; |
388 | |||
389 | ret = tegra_pm_irq_set_wake(d->irq, enable); | ||
390 | |||
391 | if (ret) | ||
392 | return ret; | ||
393 | |||
394 | ret = irq_set_irq_wake(bank->irq, enable); | ||
395 | |||
396 | if (ret) | ||
397 | tegra_pm_irq_set_wake(d->irq, !enable); | ||
398 | |||
399 | return ret; | ||
345 | } | 400 | } |
401 | #else | ||
402 | #define tegra_gpio_irq_set_wake NULL | ||
403 | #define tegra_gpio_suspend NULL | ||
404 | #define tegra_gpio_resume NULL | ||
346 | #endif | 405 | #endif |
347 | 406 | ||
407 | static struct syscore_ops tegra_gpio_syscore_ops = { | ||
408 | .suspend = tegra_gpio_suspend, | ||
409 | .resume = tegra_gpio_resume, | ||
410 | }; | ||
411 | |||
412 | int tegra_gpio_resume_init(void) | ||
413 | { | ||
414 | register_syscore_ops(&tegra_gpio_syscore_ops); | ||
415 | |||
416 | return 0; | ||
417 | } | ||
418 | |||
348 | static struct irq_chip tegra_gpio_irq_chip = { | 419 | static struct irq_chip tegra_gpio_irq_chip = { |
349 | .name = "GPIO", | 420 | .name = "GPIO", |
350 | .irq_ack = tegra_gpio_irq_ack, | 421 | .irq_ack = tegra_gpio_irq_ack, |
351 | .irq_mask = tegra_gpio_irq_mask, | 422 | .irq_mask = tegra_gpio_irq_mask, |
352 | .irq_unmask = tegra_gpio_irq_unmask, | 423 | .irq_unmask = tegra_gpio_irq_unmask, |
353 | .irq_set_type = tegra_gpio_irq_set_type, | 424 | .irq_set_type = tegra_gpio_irq_set_type, |
354 | #ifdef CONFIG_PM_SLEEP | 425 | .irq_set_wake = tegra_gpio_irq_set_wake, |
355 | .irq_set_wake = tegra_gpio_wake_enable, | 426 | .flags = IRQCHIP_MASK_ON_SUSPEND, |
356 | #endif | ||
357 | }; | ||
358 | |||
359 | static const struct dev_pm_ops tegra_gpio_pm_ops = { | ||
360 | SET_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume) | ||
361 | }; | ||
362 | |||
363 | struct tegra_gpio_soc_config { | ||
364 | u32 bank_stride; | ||
365 | u32 upper_offset; | ||
366 | }; | ||
367 | |||
368 | static struct tegra_gpio_soc_config tegra20_gpio_config = { | ||
369 | .bank_stride = 0x80, | ||
370 | .upper_offset = 0x800, | ||
371 | }; | ||
372 | |||
373 | static struct tegra_gpio_soc_config tegra30_gpio_config = { | ||
374 | .bank_stride = 0x100, | ||
375 | .upper_offset = 0x80, | ||
376 | }; | 427 | }; |
377 | 428 | ||
378 | static struct of_device_id tegra_gpio_of_match[] = { | ||
379 | { .compatible = "nvidia,tegra30-gpio", .data = &tegra30_gpio_config }, | ||
380 | { .compatible = "nvidia,tegra20-gpio", .data = &tegra20_gpio_config }, | ||
381 | { }, | ||
382 | }; | ||
383 | 429 | ||
384 | /* This lock class tells lockdep that GPIO irqs are in a different | 430 | /* This lock class tells lockdep that GPIO irqs are in a different |
385 | * category than their parents, so it won't report false recursion. | 431 | * category than their parents, so it won't report false recursion. |
386 | */ | 432 | */ |
387 | static struct lock_class_key gpio_lock_class; | 433 | static struct lock_class_key gpio_lock_class; |
388 | 434 | ||
389 | static int tegra_gpio_probe(struct platform_device *pdev) | 435 | static int __init tegra_gpio_init(void) |
390 | { | 436 | { |
391 | const struct of_device_id *match; | ||
392 | struct tegra_gpio_soc_config *config; | ||
393 | struct resource *res; | ||
394 | struct tegra_gpio_bank *bank; | 437 | struct tegra_gpio_bank *bank; |
395 | int gpio; | 438 | int gpio; |
396 | int i; | 439 | int i; |
397 | int j; | 440 | int j; |
398 | 441 | ||
399 | match = of_match_device(tegra_gpio_of_match, &pdev->dev); | 442 | for (i = 0; i < ARRAY_SIZE(tegra_gpio_banks); i++) { |
400 | if (match) | ||
401 | config = (struct tegra_gpio_soc_config *)match->data; | ||
402 | else | ||
403 | config = &tegra20_gpio_config; | ||
404 | |||
405 | tegra_gpio_bank_stride = config->bank_stride; | ||
406 | tegra_gpio_upper_offset = config->upper_offset; | ||
407 | |||
408 | for (;;) { | ||
409 | res = platform_get_resource(pdev, IORESOURCE_IRQ, tegra_gpio_bank_count); | ||
410 | if (!res) | ||
411 | break; | ||
412 | tegra_gpio_bank_count++; | ||
413 | } | ||
414 | if (!tegra_gpio_bank_count) { | ||
415 | dev_err(&pdev->dev, "Missing IRQ resource\n"); | ||
416 | return -ENODEV; | ||
417 | } | ||
418 | |||
419 | tegra_gpio_chip.ngpio = tegra_gpio_bank_count * 32; | ||
420 | |||
421 | tegra_gpio_banks = devm_kzalloc(&pdev->dev, | ||
422 | tegra_gpio_bank_count * sizeof(*tegra_gpio_banks), | ||
423 | GFP_KERNEL); | ||
424 | if (!tegra_gpio_banks) { | ||
425 | dev_err(&pdev->dev, "Couldn't allocate bank structure\n"); | ||
426 | return -ENODEV; | ||
427 | } | ||
428 | |||
429 | irq_domain = irq_domain_add_linear(pdev->dev.of_node, | ||
430 | tegra_gpio_chip.ngpio, | ||
431 | &irq_domain_simple_ops, NULL); | ||
432 | if (!irq_domain) | ||
433 | return -ENODEV; | ||
434 | |||
435 | for (i = 0; i < tegra_gpio_bank_count; i++) { | ||
436 | res = platform_get_resource(pdev, IORESOURCE_IRQ, i); | ||
437 | if (!res) { | ||
438 | dev_err(&pdev->dev, "Missing IRQ resource\n"); | ||
439 | return -ENODEV; | ||
440 | } | ||
441 | |||
442 | bank = &tegra_gpio_banks[i]; | ||
443 | bank->bank = i; | ||
444 | bank->irq = res->start; | ||
445 | } | ||
446 | |||
447 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
448 | if (!res) { | ||
449 | dev_err(&pdev->dev, "Missing MEM resource\n"); | ||
450 | return -ENODEV; | ||
451 | } | ||
452 | |||
453 | regs = devm_request_and_ioremap(&pdev->dev, res); | ||
454 | if (!regs) { | ||
455 | dev_err(&pdev->dev, "Couldn't ioremap regs\n"); | ||
456 | return -ENODEV; | ||
457 | } | ||
458 | |||
459 | for (i = 0; i < tegra_gpio_bank_count; i++) { | ||
460 | for (j = 0; j < 4; j++) { | 443 | for (j = 0; j < 4; j++) { |
461 | int gpio = tegra_gpio_compose(i, j, 0); | 444 | int gpio = tegra_gpio_compose(i, j, 0); |
462 | tegra_gpio_writel(0x00, GPIO_INT_ENB(gpio)); | 445 | __raw_writel(0x00, GPIO_INT_ENB(gpio)); |
446 | __raw_writel(0x00, GPIO_INT_STA(gpio)); | ||
463 | } | 447 | } |
464 | } | 448 | } |
465 | 449 | ||
466 | #ifdef CONFIG_OF_GPIO | 450 | #ifdef CONFIG_OF_GPIO |
467 | tegra_gpio_chip.of_node = pdev->dev.of_node; | 451 | /* |
468 | #endif | 452 | * This isn't ideal, but it gets things hooked up until this |
453 | * driver is converted into a platform_device | ||
454 | */ | ||
455 | tegra_gpio_chip.of_node = of_find_compatible_node(NULL, NULL, | ||
456 | "nvidia,tegra20-gpio"); | ||
457 | #endif /* CONFIG_OF_GPIO */ | ||
469 | 458 | ||
470 | gpiochip_add(&tegra_gpio_chip); | 459 | gpiochip_add(&tegra_gpio_chip); |
471 | 460 | ||
472 | for (gpio = 0; gpio < tegra_gpio_chip.ngpio; gpio++) { | 461 | for (gpio = 0; gpio < TEGRA_NR_GPIOS; gpio++) { |
473 | int irq = irq_create_mapping(irq_domain, gpio); | 462 | int irq = TEGRA_GPIO_TO_IRQ(gpio); |
474 | /* No validity check; all Tegra GPIOs are valid IRQs */ | 463 | /* No validity check; all Tegra GPIOs are valid IRQs */ |
475 | 464 | ||
476 | bank = &tegra_gpio_banks[GPIO_BANK(gpio)]; | 465 | bank = &tegra_gpio_banks[GPIO_BANK(gpio)]; |
@@ -482,34 +471,35 @@ static int tegra_gpio_probe(struct platform_device *pdev) | |||
482 | set_irq_flags(irq, IRQF_VALID); | 471 | set_irq_flags(irq, IRQF_VALID); |
483 | } | 472 | } |
484 | 473 | ||
485 | for (i = 0; i < tegra_gpio_bank_count; i++) { | 474 | for (i = 0; i < ARRAY_SIZE(tegra_gpio_banks); i++) { |
486 | bank = &tegra_gpio_banks[i]; | 475 | bank = &tegra_gpio_banks[i]; |
487 | 476 | ||
488 | irq_set_chained_handler(bank->irq, tegra_gpio_irq_handler); | ||
489 | irq_set_handler_data(bank->irq, bank); | ||
490 | |||
491 | for (j = 0; j < 4; j++) | 477 | for (j = 0; j < 4; j++) |
492 | spin_lock_init(&bank->lvl_lock[j]); | 478 | spin_lock_init(&bank->lvl_lock[j]); |
479 | |||
480 | irq_set_handler_data(bank->irq, bank); | ||
481 | irq_set_chained_handler(bank->irq, tegra_gpio_irq_handler); | ||
482 | |||
493 | } | 483 | } |
494 | 484 | ||
495 | return 0; | 485 | return 0; |
496 | } | 486 | } |
497 | 487 | ||
498 | static struct platform_driver tegra_gpio_driver = { | 488 | postcore_initcall(tegra_gpio_init); |
499 | .driver = { | ||
500 | .name = "tegra-gpio", | ||
501 | .owner = THIS_MODULE, | ||
502 | .pm = &tegra_gpio_pm_ops, | ||
503 | .of_match_table = tegra_gpio_of_match, | ||
504 | }, | ||
505 | .probe = tegra_gpio_probe, | ||
506 | }; | ||
507 | 489 | ||
508 | static int __init tegra_gpio_init(void) | 490 | void __init tegra_gpio_config(struct tegra_gpio_table *table, int num) |
509 | { | 491 | { |
510 | return platform_driver_register(&tegra_gpio_driver); | 492 | int i; |
493 | |||
494 | for (i = 0; i < num; i++) { | ||
495 | int gpio = table[i].gpio; | ||
496 | |||
497 | if (table[i].enable) | ||
498 | tegra_gpio_enable(gpio); | ||
499 | else | ||
500 | tegra_gpio_disable(gpio); | ||
501 | } | ||
511 | } | 502 | } |
512 | postcore_initcall(tegra_gpio_init); | ||
513 | 503 | ||
514 | #ifdef CONFIG_DEBUG_FS | 504 | #ifdef CONFIG_DEBUG_FS |
515 | 505 | ||
@@ -521,19 +511,20 @@ static int dbg_gpio_show(struct seq_file *s, void *unused) | |||
521 | int i; | 511 | int i; |
522 | int j; | 512 | int j; |
523 | 513 | ||
524 | for (i = 0; i < tegra_gpio_bank_count; i++) { | 514 | seq_printf(s, "Bank:Port CNF OE OUT IN INT_STA INT_ENB INT_LVL\n"); |
515 | for (i = 0; i < ARRAY_SIZE(tegra_gpio_banks); i++) { | ||
525 | for (j = 0; j < 4; j++) { | 516 | for (j = 0; j < 4; j++) { |
526 | int gpio = tegra_gpio_compose(i, j, 0); | 517 | int gpio = tegra_gpio_compose(i, j, 0); |
527 | seq_printf(s, | 518 | seq_printf(s, |
528 | "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", | 519 | "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", |
529 | i, j, | 520 | i, j, |
530 | tegra_gpio_readl(GPIO_CNF(gpio)), | 521 | __raw_readl(GPIO_CNF(gpio)), |
531 | tegra_gpio_readl(GPIO_OE(gpio)), | 522 | __raw_readl(GPIO_OE(gpio)), |
532 | tegra_gpio_readl(GPIO_OUT(gpio)), | 523 | __raw_readl(GPIO_OUT(gpio)), |
533 | tegra_gpio_readl(GPIO_IN(gpio)), | 524 | __raw_readl(GPIO_IN(gpio)), |
534 | tegra_gpio_readl(GPIO_INT_STA(gpio)), | 525 | __raw_readl(GPIO_INT_STA(gpio)), |
535 | tegra_gpio_readl(GPIO_INT_ENB(gpio)), | 526 | __raw_readl(GPIO_INT_ENB(gpio)), |
536 | tegra_gpio_readl(GPIO_INT_LVL(gpio))); | 527 | __raw_readl(GPIO_INT_LVL(gpio))); |
537 | } | 528 | } |
538 | } | 529 | } |
539 | return 0; | 530 | return 0; |
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c index 702cca9284f..c593bd46bfb 100644 --- a/drivers/gpio/gpio-timberdale.c +++ b/drivers/gpio/gpio-timberdale.c | |||
@@ -116,7 +116,7 @@ static void timbgpio_irq_disable(struct irq_data *d) | |||
116 | unsigned long flags; | 116 | unsigned long flags; |
117 | 117 | ||
118 | spin_lock_irqsave(&tgpio->lock, flags); | 118 | spin_lock_irqsave(&tgpio->lock, flags); |
119 | tgpio->last_ier &= ~(1UL << offset); | 119 | tgpio->last_ier &= ~(1 << offset); |
120 | iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); | 120 | iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); |
121 | spin_unlock_irqrestore(&tgpio->lock, flags); | 121 | spin_unlock_irqrestore(&tgpio->lock, flags); |
122 | } | 122 | } |
@@ -128,7 +128,7 @@ static void timbgpio_irq_enable(struct irq_data *d) | |||
128 | unsigned long flags; | 128 | unsigned long flags; |
129 | 129 | ||
130 | spin_lock_irqsave(&tgpio->lock, flags); | 130 | spin_lock_irqsave(&tgpio->lock, flags); |
131 | tgpio->last_ier |= 1UL << offset; | 131 | tgpio->last_ier |= 1 << offset; |
132 | iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); | 132 | iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); |
133 | spin_unlock_irqrestore(&tgpio->lock, flags); | 133 | spin_unlock_irqrestore(&tgpio->lock, flags); |
134 | } | 134 | } |
@@ -222,7 +222,7 @@ static struct irq_chip timbgpio_irqchip = { | |||
222 | .irq_set_type = timbgpio_irq_type, | 222 | .irq_set_type = timbgpio_irq_type, |
223 | }; | 223 | }; |
224 | 224 | ||
225 | static int timbgpio_probe(struct platform_device *pdev) | 225 | static int __devinit timbgpio_probe(struct platform_device *pdev) |
226 | { | 226 | { |
227 | int err, i; | 227 | int err, i; |
228 | struct gpio_chip *gc; | 228 | struct gpio_chip *gc; |
@@ -316,7 +316,7 @@ err_mem: | |||
316 | return err; | 316 | return err; |
317 | } | 317 | } |
318 | 318 | ||
319 | static int timbgpio_remove(struct platform_device *pdev) | 319 | static int __devexit timbgpio_remove(struct platform_device *pdev) |
320 | { | 320 | { |
321 | int err; | 321 | int err; |
322 | struct timbgpio_platform_data *pdata = pdev->dev.platform_data; | 322 | struct timbgpio_platform_data *pdata = pdev->dev.platform_data; |
@@ -359,7 +359,18 @@ static struct platform_driver timbgpio_platform_driver = { | |||
359 | 359 | ||
360 | /*--------------------------------------------------------------------------*/ | 360 | /*--------------------------------------------------------------------------*/ |
361 | 361 | ||
362 | module_platform_driver(timbgpio_platform_driver); | 362 | static int __init timbgpio_init(void) |
363 | { | ||
364 | return platform_driver_register(&timbgpio_platform_driver); | ||
365 | } | ||
366 | |||
367 | static void __exit timbgpio_exit(void) | ||
368 | { | ||
369 | platform_driver_unregister(&timbgpio_platform_driver); | ||
370 | } | ||
371 | |||
372 | module_init(timbgpio_init); | ||
373 | module_exit(timbgpio_exit); | ||
363 | 374 | ||
364 | MODULE_DESCRIPTION("Timberdale GPIO driver"); | 375 | MODULE_DESCRIPTION("Timberdale GPIO driver"); |
365 | MODULE_LICENSE("GPL v2"); | 376 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/gpio/gpio-tnetv107x.c b/drivers/gpio/gpio-tnetv107x.c deleted file mode 100644 index 3fa3e2867e1..00000000000 --- a/drivers/gpio/gpio-tnetv107x.c +++ /dev/null | |||
@@ -1,205 +0,0 @@ | |||
1 | /* | ||
2 | * Texas Instruments TNETV107X GPIO Controller | ||
3 | * | ||
4 | * Copyright (C) 2010 Texas Instruments | ||
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 as | ||
8 | * published by the Free Software Foundation version 2. | ||
9 | * | ||
10 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
11 | * kind, whether express or implied; without even the implied warranty | ||
12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | */ | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/gpio.h> | ||
18 | |||
19 | #include <mach/common.h> | ||
20 | #include <mach/tnetv107x.h> | ||
21 | |||
22 | struct tnetv107x_gpio_regs { | ||
23 | u32 idver; | ||
24 | u32 data_in[3]; | ||
25 | u32 data_out[3]; | ||
26 | u32 direction[3]; | ||
27 | u32 enable[3]; | ||
28 | }; | ||
29 | |||
30 | #define gpio_reg_index(gpio) ((gpio) >> 5) | ||
31 | #define gpio_reg_bit(gpio) BIT((gpio) & 0x1f) | ||
32 | |||
33 | #define gpio_reg_rmw(reg, mask, val) \ | ||
34 | __raw_writel((__raw_readl(reg) & ~(mask)) | (val), (reg)) | ||
35 | |||
36 | #define gpio_reg_set_bit(reg, gpio) \ | ||
37 | gpio_reg_rmw((reg) + gpio_reg_index(gpio), 0, gpio_reg_bit(gpio)) | ||
38 | |||
39 | #define gpio_reg_clear_bit(reg, gpio) \ | ||
40 | gpio_reg_rmw((reg) + gpio_reg_index(gpio), gpio_reg_bit(gpio), 0) | ||
41 | |||
42 | #define gpio_reg_get_bit(reg, gpio) \ | ||
43 | (__raw_readl((reg) + gpio_reg_index(gpio)) & gpio_reg_bit(gpio)) | ||
44 | |||
45 | #define chip2controller(chip) \ | ||
46 | container_of(chip, struct davinci_gpio_controller, chip) | ||
47 | |||
48 | #define TNETV107X_GPIO_CTLRS DIV_ROUND_UP(TNETV107X_N_GPIO, 32) | ||
49 | |||
50 | static struct davinci_gpio_controller chips[TNETV107X_GPIO_CTLRS]; | ||
51 | |||
52 | static int tnetv107x_gpio_request(struct gpio_chip *chip, unsigned offset) | ||
53 | { | ||
54 | struct davinci_gpio_controller *ctlr = chip2controller(chip); | ||
55 | struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; | ||
56 | unsigned gpio = chip->base + offset; | ||
57 | unsigned long flags; | ||
58 | |||
59 | spin_lock_irqsave(&ctlr->lock, flags); | ||
60 | |||
61 | gpio_reg_set_bit(regs->enable, gpio); | ||
62 | |||
63 | spin_unlock_irqrestore(&ctlr->lock, flags); | ||
64 | |||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static void tnetv107x_gpio_free(struct gpio_chip *chip, unsigned offset) | ||
69 | { | ||
70 | struct davinci_gpio_controller *ctlr = chip2controller(chip); | ||
71 | struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; | ||
72 | unsigned gpio = chip->base + offset; | ||
73 | unsigned long flags; | ||
74 | |||
75 | spin_lock_irqsave(&ctlr->lock, flags); | ||
76 | |||
77 | gpio_reg_clear_bit(regs->enable, gpio); | ||
78 | |||
79 | spin_unlock_irqrestore(&ctlr->lock, flags); | ||
80 | } | ||
81 | |||
82 | static int tnetv107x_gpio_dir_in(struct gpio_chip *chip, unsigned offset) | ||
83 | { | ||
84 | struct davinci_gpio_controller *ctlr = chip2controller(chip); | ||
85 | struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; | ||
86 | unsigned gpio = chip->base + offset; | ||
87 | unsigned long flags; | ||
88 | |||
89 | spin_lock_irqsave(&ctlr->lock, flags); | ||
90 | |||
91 | gpio_reg_set_bit(regs->direction, gpio); | ||
92 | |||
93 | spin_unlock_irqrestore(&ctlr->lock, flags); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | static int tnetv107x_gpio_dir_out(struct gpio_chip *chip, | ||
99 | unsigned offset, int value) | ||
100 | { | ||
101 | struct davinci_gpio_controller *ctlr = chip2controller(chip); | ||
102 | struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; | ||
103 | unsigned gpio = chip->base + offset; | ||
104 | unsigned long flags; | ||
105 | |||
106 | spin_lock_irqsave(&ctlr->lock, flags); | ||
107 | |||
108 | if (value) | ||
109 | gpio_reg_set_bit(regs->data_out, gpio); | ||
110 | else | ||
111 | gpio_reg_clear_bit(regs->data_out, gpio); | ||
112 | |||
113 | gpio_reg_clear_bit(regs->direction, gpio); | ||
114 | |||
115 | spin_unlock_irqrestore(&ctlr->lock, flags); | ||
116 | |||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static int tnetv107x_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
121 | { | ||
122 | struct davinci_gpio_controller *ctlr = chip2controller(chip); | ||
123 | struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; | ||
124 | unsigned gpio = chip->base + offset; | ||
125 | int ret; | ||
126 | |||
127 | ret = gpio_reg_get_bit(regs->data_in, gpio); | ||
128 | |||
129 | return ret ? 1 : 0; | ||
130 | } | ||
131 | |||
132 | static void tnetv107x_gpio_set(struct gpio_chip *chip, | ||
133 | unsigned offset, int value) | ||
134 | { | ||
135 | struct davinci_gpio_controller *ctlr = chip2controller(chip); | ||
136 | struct tnetv107x_gpio_regs __iomem *regs = ctlr->regs; | ||
137 | unsigned gpio = chip->base + offset; | ||
138 | unsigned long flags; | ||
139 | |||
140 | spin_lock_irqsave(&ctlr->lock, flags); | ||
141 | |||
142 | if (value) | ||
143 | gpio_reg_set_bit(regs->data_out, gpio); | ||
144 | else | ||
145 | gpio_reg_clear_bit(regs->data_out, gpio); | ||
146 | |||
147 | spin_unlock_irqrestore(&ctlr->lock, flags); | ||
148 | } | ||
149 | |||
150 | static int __init tnetv107x_gpio_setup(void) | ||
151 | { | ||
152 | int i, base; | ||
153 | unsigned ngpio; | ||
154 | struct davinci_soc_info *soc_info = &davinci_soc_info; | ||
155 | struct tnetv107x_gpio_regs *regs; | ||
156 | struct davinci_gpio_controller *ctlr; | ||
157 | |||
158 | if (soc_info->gpio_type != GPIO_TYPE_TNETV107X) | ||
159 | return 0; | ||
160 | |||
161 | ngpio = soc_info->gpio_num; | ||
162 | if (ngpio == 0) { | ||
163 | pr_err("GPIO setup: how many GPIOs?\n"); | ||
164 | return -EINVAL; | ||
165 | } | ||
166 | |||
167 | if (WARN_ON(TNETV107X_N_GPIO < ngpio)) | ||
168 | ngpio = TNETV107X_N_GPIO; | ||
169 | |||
170 | regs = ioremap(soc_info->gpio_base, SZ_4K); | ||
171 | if (WARN_ON(!regs)) | ||
172 | return -EINVAL; | ||
173 | |||
174 | for (i = 0, base = 0; base < ngpio; i++, base += 32) { | ||
175 | ctlr = &chips[i]; | ||
176 | |||
177 | ctlr->chip.label = "tnetv107x"; | ||
178 | ctlr->chip.can_sleep = 0; | ||
179 | ctlr->chip.base = base; | ||
180 | ctlr->chip.ngpio = ngpio - base; | ||
181 | if (ctlr->chip.ngpio > 32) | ||
182 | ctlr->chip.ngpio = 32; | ||
183 | |||
184 | ctlr->chip.request = tnetv107x_gpio_request; | ||
185 | ctlr->chip.free = tnetv107x_gpio_free; | ||
186 | ctlr->chip.direction_input = tnetv107x_gpio_dir_in; | ||
187 | ctlr->chip.get = tnetv107x_gpio_get; | ||
188 | ctlr->chip.direction_output = tnetv107x_gpio_dir_out; | ||
189 | ctlr->chip.set = tnetv107x_gpio_set; | ||
190 | |||
191 | spin_lock_init(&ctlr->lock); | ||
192 | |||
193 | ctlr->regs = regs; | ||
194 | ctlr->set_data = ®s->data_out[i]; | ||
195 | ctlr->clr_data = ®s->data_out[i]; | ||
196 | ctlr->in_data = ®s->data_in[i]; | ||
197 | |||
198 | gpiochip_add(&ctlr->chip); | ||
199 | } | ||
200 | |||
201 | soc_info->gpio_ctlrs = chips; | ||
202 | soc_info->gpio_ctlrs_num = DIV_ROUND_UP(ngpio, 32); | ||
203 | return 0; | ||
204 | } | ||
205 | pure_initcall(tnetv107x_gpio_setup); | ||
diff --git a/drivers/gpio/gpio-tps6586x.c b/drivers/gpio/gpio-tps6586x.c deleted file mode 100644 index 29e8e750bd4..00000000000 --- a/drivers/gpio/gpio-tps6586x.c +++ /dev/null | |||
@@ -1,167 +0,0 @@ | |||
1 | /* | ||
2 | * TI TPS6586x GPIO driver | ||
3 | * | ||
4 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. | ||
5 | * Author: Laxman dewangan <ldewangan@nvidia.com> | ||
6 | * | ||
7 | * Based on tps6586x.c | ||
8 | * Copyright (c) 2010 CompuLab Ltd. | ||
9 | * Mike Rapoport <mike@compulab.co.il> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms and conditions of the GNU General Public License, | ||
13 | * version 2, as published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
18 | * more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | */ | ||
23 | |||
24 | #include <linux/errno.h> | ||
25 | #include <linux/gpio.h> | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/mfd/tps6586x.h> | ||
29 | #include <linux/of_device.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | |||
32 | /* GPIO control registers */ | ||
33 | #define TPS6586X_GPIOSET1 0x5d | ||
34 | #define TPS6586X_GPIOSET2 0x5e | ||
35 | |||
36 | struct tps6586x_gpio { | ||
37 | struct gpio_chip gpio_chip; | ||
38 | struct device *parent; | ||
39 | }; | ||
40 | |||
41 | static inline struct tps6586x_gpio *to_tps6586x_gpio(struct gpio_chip *chip) | ||
42 | { | ||
43 | return container_of(chip, struct tps6586x_gpio, gpio_chip); | ||
44 | } | ||
45 | |||
46 | static int tps6586x_gpio_get(struct gpio_chip *gc, unsigned offset) | ||
47 | { | ||
48 | struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); | ||
49 | uint8_t val; | ||
50 | int ret; | ||
51 | |||
52 | ret = tps6586x_read(tps6586x_gpio->parent, TPS6586X_GPIOSET2, &val); | ||
53 | if (ret) | ||
54 | return ret; | ||
55 | |||
56 | return !!(val & (1 << offset)); | ||
57 | } | ||
58 | |||
59 | static void tps6586x_gpio_set(struct gpio_chip *gc, unsigned offset, | ||
60 | int value) | ||
61 | { | ||
62 | struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); | ||
63 | |||
64 | tps6586x_update(tps6586x_gpio->parent, TPS6586X_GPIOSET2, | ||
65 | value << offset, 1 << offset); | ||
66 | } | ||
67 | |||
68 | static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset, | ||
69 | int value) | ||
70 | { | ||
71 | struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); | ||
72 | uint8_t val, mask; | ||
73 | |||
74 | tps6586x_gpio_set(gc, offset, value); | ||
75 | |||
76 | val = 0x1 << (offset * 2); | ||
77 | mask = 0x3 << (offset * 2); | ||
78 | |||
79 | return tps6586x_update(tps6586x_gpio->parent, TPS6586X_GPIOSET1, | ||
80 | val, mask); | ||
81 | } | ||
82 | |||
83 | static int tps6586x_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | ||
84 | { | ||
85 | struct tps6586x_gpio *tps6586x_gpio = to_tps6586x_gpio(gc); | ||
86 | |||
87 | return tps6586x_irq_get_virq(tps6586x_gpio->parent, | ||
88 | TPS6586X_INT_PLDO_0 + offset); | ||
89 | } | ||
90 | |||
91 | static int tps6586x_gpio_probe(struct platform_device *pdev) | ||
92 | { | ||
93 | struct tps6586x_platform_data *pdata; | ||
94 | struct tps6586x_gpio *tps6586x_gpio; | ||
95 | int ret; | ||
96 | |||
97 | pdata = dev_get_platdata(pdev->dev.parent); | ||
98 | tps6586x_gpio = devm_kzalloc(&pdev->dev, | ||
99 | sizeof(*tps6586x_gpio), GFP_KERNEL); | ||
100 | if (!tps6586x_gpio) { | ||
101 | dev_err(&pdev->dev, "Could not allocate tps6586x_gpio\n"); | ||
102 | return -ENOMEM; | ||
103 | } | ||
104 | |||
105 | tps6586x_gpio->parent = pdev->dev.parent; | ||
106 | |||
107 | tps6586x_gpio->gpio_chip.owner = THIS_MODULE; | ||
108 | tps6586x_gpio->gpio_chip.label = pdev->name; | ||
109 | tps6586x_gpio->gpio_chip.dev = &pdev->dev; | ||
110 | tps6586x_gpio->gpio_chip.ngpio = 4; | ||
111 | tps6586x_gpio->gpio_chip.can_sleep = 1; | ||
112 | |||
113 | /* FIXME: add handling of GPIOs as dedicated inputs */ | ||
114 | tps6586x_gpio->gpio_chip.direction_output = tps6586x_gpio_output; | ||
115 | tps6586x_gpio->gpio_chip.set = tps6586x_gpio_set; | ||
116 | tps6586x_gpio->gpio_chip.get = tps6586x_gpio_get; | ||
117 | tps6586x_gpio->gpio_chip.to_irq = tps6586x_gpio_to_irq; | ||
118 | |||
119 | #ifdef CONFIG_OF_GPIO | ||
120 | tps6586x_gpio->gpio_chip.of_node = pdev->dev.parent->of_node; | ||
121 | #endif | ||
122 | if (pdata && pdata->gpio_base) | ||
123 | tps6586x_gpio->gpio_chip.base = pdata->gpio_base; | ||
124 | else | ||
125 | tps6586x_gpio->gpio_chip.base = -1; | ||
126 | |||
127 | ret = gpiochip_add(&tps6586x_gpio->gpio_chip); | ||
128 | if (ret < 0) { | ||
129 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | ||
130 | return ret; | ||
131 | } | ||
132 | |||
133 | platform_set_drvdata(pdev, tps6586x_gpio); | ||
134 | |||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | static int tps6586x_gpio_remove(struct platform_device *pdev) | ||
139 | { | ||
140 | struct tps6586x_gpio *tps6586x_gpio = platform_get_drvdata(pdev); | ||
141 | |||
142 | return gpiochip_remove(&tps6586x_gpio->gpio_chip); | ||
143 | } | ||
144 | |||
145 | static struct platform_driver tps6586x_gpio_driver = { | ||
146 | .driver.name = "tps6586x-gpio", | ||
147 | .driver.owner = THIS_MODULE, | ||
148 | .probe = tps6586x_gpio_probe, | ||
149 | .remove = tps6586x_gpio_remove, | ||
150 | }; | ||
151 | |||
152 | static int __init tps6586x_gpio_init(void) | ||
153 | { | ||
154 | return platform_driver_register(&tps6586x_gpio_driver); | ||
155 | } | ||
156 | subsys_initcall(tps6586x_gpio_init); | ||
157 | |||
158 | static void __exit tps6586x_gpio_exit(void) | ||
159 | { | ||
160 | platform_driver_unregister(&tps6586x_gpio_driver); | ||
161 | } | ||
162 | module_exit(tps6586x_gpio_exit); | ||
163 | |||
164 | MODULE_ALIAS("platform:tps6586x-gpio"); | ||
165 | MODULE_DESCRIPTION("GPIO interface for TPS6586X PMIC"); | ||
166 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | ||
167 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c index 5083825a034..7eef648a335 100644 --- a/drivers/gpio/gpio-tps65910.c +++ b/drivers/gpio/gpio-tps65910.c | |||
@@ -18,27 +18,14 @@ | |||
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> | ||
22 | #include <linux/mfd/tps65910.h> | 21 | #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 | } | ||
34 | 22 | ||
35 | static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) | 23 | static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) |
36 | { | 24 | { |
37 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); | 25 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); |
38 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; | 26 | uint8_t val; |
39 | unsigned int val; | ||
40 | 27 | ||
41 | tps65910_reg_read(tps65910, TPS65910_GPIO0 + offset, &val); | 28 | tps65910->read(tps65910, TPS65910_GPIO0 + offset, 1, &val); |
42 | 29 | ||
43 | if (val & GPIO_STS_MASK) | 30 | if (val & GPIO_STS_MASK) |
44 | return 1; | 31 | return 1; |
@@ -49,173 +36,83 @@ static int tps65910_gpio_get(struct gpio_chip *gc, unsigned offset) | |||
49 | static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset, | 36 | static void tps65910_gpio_set(struct gpio_chip *gc, unsigned offset, |
50 | int value) | 37 | int value) |
51 | { | 38 | { |
52 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); | 39 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); |
53 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; | ||
54 | 40 | ||
55 | if (value) | 41 | if (value) |
56 | tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset, | 42 | tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset, |
57 | GPIO_SET_MASK); | 43 | GPIO_SET_MASK); |
58 | else | 44 | else |
59 | tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset, | 45 | tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset, |
60 | GPIO_SET_MASK); | 46 | GPIO_SET_MASK); |
61 | } | 47 | } |
62 | 48 | ||
63 | static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset, | 49 | static int tps65910_gpio_output(struct gpio_chip *gc, unsigned offset, |
64 | int value) | 50 | int value) |
65 | { | 51 | { |
66 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); | 52 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); |
67 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; | ||
68 | 53 | ||
69 | /* Set the initial value */ | 54 | /* Set the initial value */ |
70 | tps65910_gpio_set(gc, offset, value); | 55 | tps65910_gpio_set(gc, offset, value); |
71 | 56 | ||
72 | return tps65910_reg_set_bits(tps65910, TPS65910_GPIO0 + offset, | 57 | return tps65910_set_bits(tps65910, TPS65910_GPIO0 + offset, |
73 | GPIO_CFG_MASK); | 58 | GPIO_CFG_MASK); |
74 | } | 59 | } |
75 | 60 | ||
76 | static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset) | 61 | static int tps65910_gpio_input(struct gpio_chip *gc, unsigned offset) |
77 | { | 62 | { |
78 | struct tps65910_gpio *tps65910_gpio = to_tps65910_gpio(gc); | 63 | struct tps65910 *tps65910 = container_of(gc, struct tps65910, gpio); |
79 | struct tps65910 *tps65910 = tps65910_gpio->tps65910; | ||
80 | 64 | ||
81 | return tps65910_reg_clear_bits(tps65910, TPS65910_GPIO0 + offset, | 65 | return tps65910_clear_bits(tps65910, TPS65910_GPIO0 + offset, |
82 | GPIO_CFG_MASK); | 66 | GPIO_CFG_MASK); |
83 | } | 67 | } |
84 | 68 | ||
85 | #ifdef CONFIG_OF | 69 | void tps65910_gpio_init(struct tps65910 *tps65910, int gpio_base) |
86 | static struct tps65910_board *tps65910_parse_dt_for_gpio(struct device *dev, | ||
87 | struct tps65910 *tps65910, int chip_ngpio) | ||
88 | { | 70 | { |
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); | ||
92 | int ret; | 71 | int ret; |
93 | int idx; | 72 | struct tps65910_board *board_data; |
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 | } | ||
102 | 73 | ||
103 | for (idx = 0; idx < ngpio; idx++) | 74 | if (!gpio_base) |
104 | tps65910_board->en_gpio_sleep[idx] = (prop_array[idx] != 0); | 75 | return; |
105 | 76 | ||
106 | return tps65910_board; | 77 | tps65910->gpio.owner = THIS_MODULE; |
107 | } | 78 | tps65910->gpio.label = tps65910->i2c_client->name; |
108 | #else | 79 | tps65910->gpio.dev = tps65910->dev; |
109 | static struct tps65910_board *tps65910_parse_dt_for_gpio(struct device *dev, | 80 | tps65910->gpio.base = gpio_base; |
110 | struct tps65910 *tps65910, int chip_ngpio) | ||
111 | { | ||
112 | return NULL; | ||
113 | } | ||
114 | #endif | ||
115 | |||
116 | static int 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; | ||
135 | 81 | ||
136 | switch(tps65910_chip_id(tps65910)) { | 82 | switch(tps65910_chip_id(tps65910)) { |
137 | case TPS65910: | 83 | case TPS65910: |
138 | tps65910_gpio->gpio_chip.ngpio = TPS65910_NUM_GPIO; | 84 | tps65910->gpio.ngpio = TPS65910_NUM_GPIO; |
139 | break; | 85 | break; |
140 | case TPS65911: | 86 | case TPS65911: |
141 | tps65910_gpio->gpio_chip.ngpio = TPS65911_NUM_GPIO; | 87 | tps65910->gpio.ngpio = TPS65911_NUM_GPIO; |
142 | break; | 88 | break; |
143 | default: | 89 | default: |
144 | return -EINVAL; | 90 | return; |
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 | #ifdef CONFIG_OF_GPIO | ||
153 | tps65910_gpio->gpio_chip.of_node = tps65910->dev->of_node; | ||
154 | #endif | ||
155 | if (pdata && pdata->gpio_base) | ||
156 | tps65910_gpio->gpio_chip.base = pdata->gpio_base; | ||
157 | else | ||
158 | tps65910_gpio->gpio_chip.base = -1; | ||
159 | |||
160 | if (!pdata && tps65910->dev->of_node) | ||
161 | pdata = tps65910_parse_dt_for_gpio(&pdev->dev, tps65910, | ||
162 | tps65910_gpio->gpio_chip.ngpio); | ||
163 | |||
164 | if (!pdata) | ||
165 | goto skip_init; | ||
166 | |||
167 | /* Configure sleep control for gpios if provided */ | ||
168 | for (i = 0; i < tps65910_gpio->gpio_chip.ngpio; ++i) { | ||
169 | if (!pdata->en_gpio_sleep[i]) | ||
170 | continue; | ||
171 | |||
172 | ret = tps65910_reg_set_bits(tps65910, | ||
173 | TPS65910_GPIO0 + i, GPIO_SLEEP_MASK); | ||
174 | if (ret < 0) | ||
175 | dev_warn(tps65910->dev, | ||
176 | "GPIO Sleep setting failed with err %d\n", ret); | ||
177 | } | 91 | } |
178 | 92 | tps65910->gpio.can_sleep = 1; | |
179 | skip_init: | 93 | |
180 | ret = gpiochip_add(&tps65910_gpio->gpio_chip); | 94 | tps65910->gpio.direction_input = tps65910_gpio_input; |
181 | if (ret < 0) { | 95 | tps65910->gpio.direction_output = tps65910_gpio_output; |
182 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | 96 | tps65910->gpio.set = tps65910_gpio_set; |
183 | return ret; | 97 | tps65910->gpio.get = tps65910_gpio_get; |
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 | } | ||
184 | } | 112 | } |
185 | 113 | ||
186 | platform_set_drvdata(pdev, tps65910_gpio); | 114 | ret = gpiochip_add(&tps65910->gpio); |
187 | |||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | static int tps65910_gpio_remove(struct platform_device *pdev) | ||
192 | { | ||
193 | struct tps65910_gpio *tps65910_gpio = platform_get_drvdata(pdev); | ||
194 | 115 | ||
195 | return gpiochip_remove(&tps65910_gpio->gpio_chip); | 116 | if (ret) |
117 | dev_warn(tps65910->dev, "GPIO registration failed: %d\n", ret); | ||
196 | } | 118 | } |
197 | |||
198 | static struct platform_driver tps65910_gpio_driver = { | ||
199 | .driver.name = "tps65910-gpio", | ||
200 | .driver.owner = THIS_MODULE, | ||
201 | .probe = tps65910_gpio_probe, | ||
202 | .remove = tps65910_gpio_remove, | ||
203 | }; | ||
204 | |||
205 | static int __init tps65910_gpio_init(void) | ||
206 | { | ||
207 | return platform_driver_register(&tps65910_gpio_driver); | ||
208 | } | ||
209 | subsys_initcall(tps65910_gpio_init); | ||
210 | |||
211 | static void __exit tps65910_gpio_exit(void) | ||
212 | { | ||
213 | platform_driver_unregister(&tps65910_gpio_driver); | ||
214 | } | ||
215 | module_exit(tps65910_gpio_exit); | ||
216 | |||
217 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); | ||
218 | MODULE_AUTHOR("Jorge Eduardo Candelaria jedu@slimlogic.co.uk>"); | ||
219 | MODULE_DESCRIPTION("GPIO interface for TPS65910/TPS6511 PMICs"); | ||
220 | MODULE_LICENSE("GPL v2"); | ||
221 | MODULE_ALIAS("platform:tps65910-gpio"); | ||
diff --git a/drivers/gpio/gpio-tps65912.c b/drivers/gpio/gpio-tps65912.c index 30a5844a7dc..79e66c00235 100644 --- a/drivers/gpio/gpio-tps65912.c +++ b/drivers/gpio/gpio-tps65912.c | |||
@@ -70,6 +70,7 @@ static int tps65912_gpio_input(struct gpio_chip *gc, unsigned offset) | |||
70 | 70 | ||
71 | return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset, | 71 | return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset, |
72 | GPIO_CFG_MASK); | 72 | GPIO_CFG_MASK); |
73 | |||
73 | } | 74 | } |
74 | 75 | ||
75 | static struct gpio_chip template_chip = { | 76 | static struct gpio_chip template_chip = { |
@@ -84,15 +85,14 @@ static struct gpio_chip template_chip = { | |||
84 | .base = -1, | 85 | .base = -1, |
85 | }; | 86 | }; |
86 | 87 | ||
87 | static int tps65912_gpio_probe(struct platform_device *pdev) | 88 | static int __devinit tps65912_gpio_probe(struct platform_device *pdev) |
88 | { | 89 | { |
89 | struct tps65912 *tps65912 = dev_get_drvdata(pdev->dev.parent); | 90 | struct tps65912 *tps65912 = dev_get_drvdata(pdev->dev.parent); |
90 | struct tps65912_board *pdata = tps65912->dev->platform_data; | 91 | struct tps65912_board *pdata = tps65912->dev->platform_data; |
91 | struct tps65912_gpio_data *tps65912_gpio; | 92 | struct tps65912_gpio_data *tps65912_gpio; |
92 | int ret; | 93 | int ret; |
93 | 94 | ||
94 | tps65912_gpio = devm_kzalloc(&pdev->dev, sizeof(*tps65912_gpio), | 95 | tps65912_gpio = kzalloc(sizeof(*tps65912_gpio), GFP_KERNEL); |
95 | GFP_KERNEL); | ||
96 | if (tps65912_gpio == NULL) | 96 | if (tps65912_gpio == NULL) |
97 | return -ENOMEM; | 97 | return -ENOMEM; |
98 | 98 | ||
@@ -105,19 +105,28 @@ static int tps65912_gpio_probe(struct platform_device *pdev) | |||
105 | ret = gpiochip_add(&tps65912_gpio->gpio_chip); | 105 | ret = gpiochip_add(&tps65912_gpio->gpio_chip); |
106 | if (ret < 0) { | 106 | if (ret < 0) { |
107 | dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret); | 107 | dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret); |
108 | return ret; | 108 | goto err; |
109 | } | 109 | } |
110 | 110 | ||
111 | platform_set_drvdata(pdev, tps65912_gpio); | 111 | platform_set_drvdata(pdev, tps65912_gpio); |
112 | 112 | ||
113 | return ret; | 113 | return ret; |
114 | |||
115 | err: | ||
116 | kfree(tps65912_gpio); | ||
117 | return ret; | ||
114 | } | 118 | } |
115 | 119 | ||
116 | static int tps65912_gpio_remove(struct platform_device *pdev) | 120 | static int __devexit tps65912_gpio_remove(struct platform_device *pdev) |
117 | { | 121 | { |
118 | struct tps65912_gpio_data *tps65912_gpio = platform_get_drvdata(pdev); | 122 | struct tps65912_gpio_data *tps65912_gpio = platform_get_drvdata(pdev); |
123 | int ret; | ||
124 | |||
125 | ret = gpiochip_remove(&tps65912_gpio->gpio_chip); | ||
126 | if (ret == 0) | ||
127 | kfree(tps65912_gpio); | ||
119 | 128 | ||
120 | return gpiochip_remove(&tps65912_gpio->gpio_chip); | 129 | return ret; |
121 | } | 130 | } |
122 | 131 | ||
123 | static struct platform_driver tps65912_gpio_driver = { | 132 | static struct platform_driver tps65912_gpio_driver = { |
@@ -126,7 +135,7 @@ static struct platform_driver tps65912_gpio_driver = { | |||
126 | .owner = THIS_MODULE, | 135 | .owner = THIS_MODULE, |
127 | }, | 136 | }, |
128 | .probe = tps65912_gpio_probe, | 137 | .probe = tps65912_gpio_probe, |
129 | .remove = tps65912_gpio_remove, | 138 | .remove = __devexit_p(tps65912_gpio_remove), |
130 | }; | 139 | }; |
131 | 140 | ||
132 | static int __init tps65912_gpio_init(void) | 141 | static int __init tps65912_gpio_init(void) |
diff --git a/drivers/gpio/gpio-ts5500.c b/drivers/gpio/gpio-ts5500.c deleted file mode 100644 index cc53cab8df2..00000000000 --- a/drivers/gpio/gpio-ts5500.c +++ /dev/null | |||
@@ -1,466 +0,0 @@ | |||
1 | /* | ||
2 | * Digital I/O driver for Technologic Systems TS-5500 | ||
3 | * | ||
4 | * Copyright (c) 2012 Savoir-faire Linux Inc. | ||
5 | * Vivien Didelot <vivien.didelot@savoirfairelinux.com> | ||
6 | * | ||
7 | * Technologic Systems platforms have pin blocks, exposing several Digital | ||
8 | * Input/Output lines (DIO). This driver aims to support single pin blocks. | ||
9 | * In that sense, the support is not limited to the TS-5500 blocks. | ||
10 | * Actually, the following platforms have DIO support: | ||
11 | * | ||
12 | * TS-5500: | ||
13 | * Documentation: http://wiki.embeddedarm.com/wiki/TS-5500 | ||
14 | * Blocks: DIO1, DIO2 and LCD port. | ||
15 | * | ||
16 | * TS-5600: | ||
17 | * Documentation: http://wiki.embeddedarm.com/wiki/TS-5600 | ||
18 | * Blocks: LCD port (identical to TS-5500 LCD). | ||
19 | * | ||
20 | * This program is free software; you can redistribute it and/or modify | ||
21 | * it under the terms of the GNU General Public License version 2 as | ||
22 | * published by the Free Software Foundation. | ||
23 | */ | ||
24 | |||
25 | #include <linux/bitops.h> | ||
26 | #include <linux/gpio.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/platform_data/gpio-ts5500.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/slab.h> | ||
32 | |||
33 | /* List of supported Technologic Systems platforms DIO blocks */ | ||
34 | enum ts5500_blocks { TS5500_DIO1, TS5500_DIO2, TS5500_LCD, TS5600_LCD }; | ||
35 | |||
36 | struct ts5500_priv { | ||
37 | const struct ts5500_dio *pinout; | ||
38 | struct gpio_chip gpio_chip; | ||
39 | spinlock_t lock; | ||
40 | bool strap; | ||
41 | u8 hwirq; | ||
42 | }; | ||
43 | |||
44 | /* | ||
45 | * Hex 7D is used to control several blocks (e.g. DIO2 and LCD port). | ||
46 | * This flag ensures that the region has been requested by this driver. | ||
47 | */ | ||
48 | static bool hex7d_reserved; | ||
49 | |||
50 | /* | ||
51 | * This structure is used to describe capabilities of DIO lines, | ||
52 | * such as available directions and connected interrupt (if any). | ||
53 | */ | ||
54 | struct ts5500_dio { | ||
55 | const u8 value_addr; | ||
56 | const u8 value_mask; | ||
57 | const u8 control_addr; | ||
58 | const u8 control_mask; | ||
59 | const bool no_input; | ||
60 | const bool no_output; | ||
61 | const u8 irq; | ||
62 | }; | ||
63 | |||
64 | #define TS5500_DIO_IN_OUT(vaddr, vbit, caddr, cbit) \ | ||
65 | { \ | ||
66 | .value_addr = vaddr, \ | ||
67 | .value_mask = BIT(vbit), \ | ||
68 | .control_addr = caddr, \ | ||
69 | .control_mask = BIT(cbit), \ | ||
70 | } | ||
71 | |||
72 | #define TS5500_DIO_IN(addr, bit) \ | ||
73 | { \ | ||
74 | .value_addr = addr, \ | ||
75 | .value_mask = BIT(bit), \ | ||
76 | .no_output = true, \ | ||
77 | } | ||
78 | |||
79 | #define TS5500_DIO_IN_IRQ(addr, bit, _irq) \ | ||
80 | { \ | ||
81 | .value_addr = addr, \ | ||
82 | .value_mask = BIT(bit), \ | ||
83 | .no_output = true, \ | ||
84 | .irq = _irq, \ | ||
85 | } | ||
86 | |||
87 | #define TS5500_DIO_OUT(addr, bit) \ | ||
88 | { \ | ||
89 | .value_addr = addr, \ | ||
90 | .value_mask = BIT(bit), \ | ||
91 | .no_input = true, \ | ||
92 | } | ||
93 | |||
94 | /* | ||
95 | * Input/Output DIO lines are programmed in groups of 4. Their values are | ||
96 | * available through 4 consecutive bits in a value port, whereas the direction | ||
97 | * of these 4 lines is driven by only 1 bit in a control port. | ||
98 | */ | ||
99 | #define TS5500_DIO_GROUP(vaddr, vbitfrom, caddr, cbit) \ | ||
100 | TS5500_DIO_IN_OUT(vaddr, vbitfrom + 0, caddr, cbit), \ | ||
101 | TS5500_DIO_IN_OUT(vaddr, vbitfrom + 1, caddr, cbit), \ | ||
102 | TS5500_DIO_IN_OUT(vaddr, vbitfrom + 2, caddr, cbit), \ | ||
103 | TS5500_DIO_IN_OUT(vaddr, vbitfrom + 3, caddr, cbit) | ||
104 | |||
105 | /* | ||
106 | * TS-5500 DIO1 block | ||
107 | * | ||
108 | * value control dir hw | ||
109 | * addr bit addr bit in out irq name pin offset | ||
110 | * | ||
111 | * 0x7b 0 0x7a 0 x x DIO1_0 1 0 | ||
112 | * 0x7b 1 0x7a 0 x x DIO1_1 3 1 | ||
113 | * 0x7b 2 0x7a 0 x x DIO1_2 5 2 | ||
114 | * 0x7b 3 0x7a 0 x x DIO1_3 7 3 | ||
115 | * 0x7b 4 0x7a 1 x x DIO1_4 9 4 | ||
116 | * 0x7b 5 0x7a 1 x x DIO1_5 11 5 | ||
117 | * 0x7b 6 0x7a 1 x x DIO1_6 13 6 | ||
118 | * 0x7b 7 0x7a 1 x x DIO1_7 15 7 | ||
119 | * 0x7c 0 0x7a 5 x x DIO1_8 4 8 | ||
120 | * 0x7c 1 0x7a 5 x x DIO1_9 6 9 | ||
121 | * 0x7c 2 0x7a 5 x x DIO1_10 8 10 | ||
122 | * 0x7c 3 0x7a 5 x x DIO1_11 10 11 | ||
123 | * 0x7c 4 x DIO1_12 12 12 | ||
124 | * 0x7c 5 x 7 DIO1_13 14 13 | ||
125 | */ | ||
126 | static const struct ts5500_dio ts5500_dio1[] = { | ||
127 | TS5500_DIO_GROUP(0x7b, 0, 0x7a, 0), | ||
128 | TS5500_DIO_GROUP(0x7b, 4, 0x7a, 1), | ||
129 | TS5500_DIO_GROUP(0x7c, 0, 0x7a, 5), | ||
130 | TS5500_DIO_IN(0x7c, 4), | ||
131 | TS5500_DIO_IN_IRQ(0x7c, 5, 7), | ||
132 | }; | ||
133 | |||
134 | /* | ||
135 | * TS-5500 DIO2 block | ||
136 | * | ||
137 | * value control dir hw | ||
138 | * addr bit addr bit in out irq name pin offset | ||
139 | * | ||
140 | * 0x7e 0 0x7d 0 x x DIO2_0 1 0 | ||
141 | * 0x7e 1 0x7d 0 x x DIO2_1 3 1 | ||
142 | * 0x7e 2 0x7d 0 x x DIO2_2 5 2 | ||
143 | * 0x7e 3 0x7d 0 x x DIO2_3 7 3 | ||
144 | * 0x7e 4 0x7d 1 x x DIO2_4 9 4 | ||
145 | * 0x7e 5 0x7d 1 x x DIO2_5 11 5 | ||
146 | * 0x7e 6 0x7d 1 x x DIO2_6 13 6 | ||
147 | * 0x7e 7 0x7d 1 x x DIO2_7 15 7 | ||
148 | * 0x7f 0 0x7d 5 x x DIO2_8 4 8 | ||
149 | * 0x7f 1 0x7d 5 x x DIO2_9 6 9 | ||
150 | * 0x7f 2 0x7d 5 x x DIO2_10 8 10 | ||
151 | * 0x7f 3 0x7d 5 x x DIO2_11 10 11 | ||
152 | * 0x7f 4 x 6 DIO2_13 14 12 | ||
153 | */ | ||
154 | static const struct ts5500_dio ts5500_dio2[] = { | ||
155 | TS5500_DIO_GROUP(0x7e, 0, 0x7d, 0), | ||
156 | TS5500_DIO_GROUP(0x7e, 4, 0x7d, 1), | ||
157 | TS5500_DIO_GROUP(0x7f, 0, 0x7d, 5), | ||
158 | TS5500_DIO_IN_IRQ(0x7f, 4, 6), | ||
159 | }; | ||
160 | |||
161 | /* | ||
162 | * TS-5500 LCD port used as DIO block | ||
163 | * TS-5600 LCD port is identical | ||
164 | * | ||
165 | * value control dir hw | ||
166 | * addr bit addr bit in out irq name pin offset | ||
167 | * | ||
168 | * 0x72 0 0x7d 2 x x LCD_0 8 0 | ||
169 | * 0x72 1 0x7d 2 x x LCD_1 7 1 | ||
170 | * 0x72 2 0x7d 2 x x LCD_2 10 2 | ||
171 | * 0x72 3 0x7d 2 x x LCD_3 9 3 | ||
172 | * 0x72 4 0x7d 3 x x LCD_4 12 4 | ||
173 | * 0x72 5 0x7d 3 x x LCD_5 11 5 | ||
174 | * 0x72 6 0x7d 3 x x LCD_6 14 6 | ||
175 | * 0x72 7 0x7d 3 x x LCD_7 13 7 | ||
176 | * 0x73 0 x LCD_EN 5 8 | ||
177 | * 0x73 6 x LCD_WR 6 9 | ||
178 | * 0x73 7 x 1 LCD_RS 3 10 | ||
179 | */ | ||
180 | static const struct ts5500_dio ts5500_lcd[] = { | ||
181 | TS5500_DIO_GROUP(0x72, 0, 0x7d, 2), | ||
182 | TS5500_DIO_GROUP(0x72, 4, 0x7d, 3), | ||
183 | TS5500_DIO_OUT(0x73, 0), | ||
184 | TS5500_DIO_IN(0x73, 6), | ||
185 | TS5500_DIO_IN_IRQ(0x73, 7, 1), | ||
186 | }; | ||
187 | |||
188 | static inline struct ts5500_priv *ts5500_gc_to_priv(struct gpio_chip *chip) | ||
189 | { | ||
190 | return container_of(chip, struct ts5500_priv, gpio_chip); | ||
191 | } | ||
192 | |||
193 | static inline void ts5500_set_mask(u8 mask, u8 addr) | ||
194 | { | ||
195 | u8 val = inb(addr); | ||
196 | val |= mask; | ||
197 | outb(val, addr); | ||
198 | } | ||
199 | |||
200 | static inline void ts5500_clear_mask(u8 mask, u8 addr) | ||
201 | { | ||
202 | u8 val = inb(addr); | ||
203 | val &= ~mask; | ||
204 | outb(val, addr); | ||
205 | } | ||
206 | |||
207 | static int ts5500_gpio_input(struct gpio_chip *chip, unsigned offset) | ||
208 | { | ||
209 | struct ts5500_priv *priv = ts5500_gc_to_priv(chip); | ||
210 | const struct ts5500_dio line = priv->pinout[offset]; | ||
211 | unsigned long flags; | ||
212 | |||
213 | if (line.no_input) | ||
214 | return -ENXIO; | ||
215 | |||
216 | if (line.no_output) | ||
217 | return 0; | ||
218 | |||
219 | spin_lock_irqsave(&priv->lock, flags); | ||
220 | ts5500_clear_mask(line.control_mask, line.control_addr); | ||
221 | spin_unlock_irqrestore(&priv->lock, flags); | ||
222 | |||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | static int ts5500_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
227 | { | ||
228 | struct ts5500_priv *priv = ts5500_gc_to_priv(chip); | ||
229 | const struct ts5500_dio line = priv->pinout[offset]; | ||
230 | |||
231 | return !!(inb(line.value_addr) & line.value_mask); | ||
232 | } | ||
233 | |||
234 | static int ts5500_gpio_output(struct gpio_chip *chip, unsigned offset, int val) | ||
235 | { | ||
236 | struct ts5500_priv *priv = ts5500_gc_to_priv(chip); | ||
237 | const struct ts5500_dio line = priv->pinout[offset]; | ||
238 | unsigned long flags; | ||
239 | |||
240 | if (line.no_output) | ||
241 | return -ENXIO; | ||
242 | |||
243 | spin_lock_irqsave(&priv->lock, flags); | ||
244 | if (!line.no_input) | ||
245 | ts5500_set_mask(line.control_mask, line.control_addr); | ||
246 | |||
247 | if (val) | ||
248 | ts5500_set_mask(line.value_mask, line.value_addr); | ||
249 | else | ||
250 | ts5500_clear_mask(line.value_mask, line.value_addr); | ||
251 | spin_unlock_irqrestore(&priv->lock, flags); | ||
252 | |||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | static void ts5500_gpio_set(struct gpio_chip *chip, unsigned offset, int val) | ||
257 | { | ||
258 | struct ts5500_priv *priv = ts5500_gc_to_priv(chip); | ||
259 | const struct ts5500_dio line = priv->pinout[offset]; | ||
260 | unsigned long flags; | ||
261 | |||
262 | spin_lock_irqsave(&priv->lock, flags); | ||
263 | if (val) | ||
264 | ts5500_set_mask(line.value_mask, line.value_addr); | ||
265 | else | ||
266 | ts5500_clear_mask(line.value_mask, line.value_addr); | ||
267 | spin_unlock_irqrestore(&priv->lock, flags); | ||
268 | } | ||
269 | |||
270 | static int ts5500_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
271 | { | ||
272 | struct ts5500_priv *priv = ts5500_gc_to_priv(chip); | ||
273 | const struct ts5500_dio *block = priv->pinout; | ||
274 | const struct ts5500_dio line = block[offset]; | ||
275 | |||
276 | /* Only one pin is connected to an interrupt */ | ||
277 | if (line.irq) | ||
278 | return line.irq; | ||
279 | |||
280 | /* As this pin is input-only, we may strap it to another in/out pin */ | ||
281 | if (priv->strap) | ||
282 | return priv->hwirq; | ||
283 | |||
284 | return -ENXIO; | ||
285 | } | ||
286 | |||
287 | static int ts5500_enable_irq(struct ts5500_priv *priv) | ||
288 | { | ||
289 | int ret = 0; | ||
290 | unsigned long flags; | ||
291 | |||
292 | spin_lock_irqsave(&priv->lock, flags); | ||
293 | if (priv->hwirq == 7) | ||
294 | ts5500_set_mask(BIT(7), 0x7a); /* DIO1_13 on IRQ7 */ | ||
295 | else if (priv->hwirq == 6) | ||
296 | ts5500_set_mask(BIT(7), 0x7d); /* DIO2_13 on IRQ6 */ | ||
297 | else if (priv->hwirq == 1) | ||
298 | ts5500_set_mask(BIT(6), 0x7d); /* LCD_RS on IRQ1 */ | ||
299 | else | ||
300 | ret = -EINVAL; | ||
301 | spin_unlock_irqrestore(&priv->lock, flags); | ||
302 | |||
303 | return ret; | ||
304 | } | ||
305 | |||
306 | static void ts5500_disable_irq(struct ts5500_priv *priv) | ||
307 | { | ||
308 | unsigned long flags; | ||
309 | |||
310 | spin_lock_irqsave(&priv->lock, flags); | ||
311 | if (priv->hwirq == 7) | ||
312 | ts5500_clear_mask(BIT(7), 0x7a); /* DIO1_13 on IRQ7 */ | ||
313 | else if (priv->hwirq == 6) | ||
314 | ts5500_clear_mask(BIT(7), 0x7d); /* DIO2_13 on IRQ6 */ | ||
315 | else if (priv->hwirq == 1) | ||
316 | ts5500_clear_mask(BIT(6), 0x7d); /* LCD_RS on IRQ1 */ | ||
317 | else | ||
318 | dev_err(priv->gpio_chip.dev, "invalid hwirq %d\n", priv->hwirq); | ||
319 | spin_unlock_irqrestore(&priv->lock, flags); | ||
320 | } | ||
321 | |||
322 | static int ts5500_dio_probe(struct platform_device *pdev) | ||
323 | { | ||
324 | enum ts5500_blocks block = platform_get_device_id(pdev)->driver_data; | ||
325 | struct ts5500_dio_platform_data *pdata = pdev->dev.platform_data; | ||
326 | struct device *dev = &pdev->dev; | ||
327 | const char *name = dev_name(dev); | ||
328 | struct ts5500_priv *priv; | ||
329 | struct resource *res; | ||
330 | unsigned long flags; | ||
331 | int ret; | ||
332 | |||
333 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
334 | if (!res) { | ||
335 | dev_err(dev, "missing IRQ resource\n"); | ||
336 | return -EINVAL; | ||
337 | } | ||
338 | |||
339 | priv = devm_kzalloc(dev, sizeof(struct ts5500_priv), GFP_KERNEL); | ||
340 | if (!priv) | ||
341 | return -ENOMEM; | ||
342 | |||
343 | platform_set_drvdata(pdev, priv); | ||
344 | priv->hwirq = res->start; | ||
345 | spin_lock_init(&priv->lock); | ||
346 | |||
347 | priv->gpio_chip.owner = THIS_MODULE; | ||
348 | priv->gpio_chip.label = name; | ||
349 | priv->gpio_chip.dev = dev; | ||
350 | priv->gpio_chip.direction_input = ts5500_gpio_input; | ||
351 | priv->gpio_chip.direction_output = ts5500_gpio_output; | ||
352 | priv->gpio_chip.get = ts5500_gpio_get; | ||
353 | priv->gpio_chip.set = ts5500_gpio_set; | ||
354 | priv->gpio_chip.to_irq = ts5500_gpio_to_irq; | ||
355 | priv->gpio_chip.base = -1; | ||
356 | if (pdata) { | ||
357 | priv->gpio_chip.base = pdata->base; | ||
358 | priv->strap = pdata->strap; | ||
359 | } | ||
360 | |||
361 | switch (block) { | ||
362 | case TS5500_DIO1: | ||
363 | priv->pinout = ts5500_dio1; | ||
364 | priv->gpio_chip.ngpio = ARRAY_SIZE(ts5500_dio1); | ||
365 | |||
366 | if (!devm_request_region(dev, 0x7a, 3, name)) { | ||
367 | dev_err(dev, "failed to request %s ports\n", name); | ||
368 | return -EBUSY; | ||
369 | } | ||
370 | break; | ||
371 | case TS5500_DIO2: | ||
372 | priv->pinout = ts5500_dio2; | ||
373 | priv->gpio_chip.ngpio = ARRAY_SIZE(ts5500_dio2); | ||
374 | |||
375 | if (!devm_request_region(dev, 0x7e, 2, name)) { | ||
376 | dev_err(dev, "failed to request %s ports\n", name); | ||
377 | return -EBUSY; | ||
378 | } | ||
379 | |||
380 | if (hex7d_reserved) | ||
381 | break; | ||
382 | |||
383 | if (!devm_request_region(dev, 0x7d, 1, name)) { | ||
384 | dev_err(dev, "failed to request %s 7D\n", name); | ||
385 | return -EBUSY; | ||
386 | } | ||
387 | |||
388 | hex7d_reserved = true; | ||
389 | break; | ||
390 | case TS5500_LCD: | ||
391 | case TS5600_LCD: | ||
392 | priv->pinout = ts5500_lcd; | ||
393 | priv->gpio_chip.ngpio = ARRAY_SIZE(ts5500_lcd); | ||
394 | |||
395 | if (!devm_request_region(dev, 0x72, 2, name)) { | ||
396 | dev_err(dev, "failed to request %s ports\n", name); | ||
397 | return -EBUSY; | ||
398 | } | ||
399 | |||
400 | if (!hex7d_reserved) { | ||
401 | if (!devm_request_region(dev, 0x7d, 1, name)) { | ||
402 | dev_err(dev, "failed to request %s 7D\n", name); | ||
403 | return -EBUSY; | ||
404 | } | ||
405 | |||
406 | hex7d_reserved = true; | ||
407 | } | ||
408 | |||
409 | /* Ensure usage of LCD port as DIO */ | ||
410 | spin_lock_irqsave(&priv->lock, flags); | ||
411 | ts5500_clear_mask(BIT(4), 0x7d); | ||
412 | spin_unlock_irqrestore(&priv->lock, flags); | ||
413 | break; | ||
414 | } | ||
415 | |||
416 | ret = gpiochip_add(&priv->gpio_chip); | ||
417 | if (ret) { | ||
418 | dev_err(dev, "failed to register the gpio chip\n"); | ||
419 | return ret; | ||
420 | } | ||
421 | |||
422 | ret = ts5500_enable_irq(priv); | ||
423 | if (ret) { | ||
424 | dev_err(dev, "invalid interrupt %d\n", priv->hwirq); | ||
425 | goto cleanup; | ||
426 | } | ||
427 | |||
428 | return 0; | ||
429 | cleanup: | ||
430 | if (gpiochip_remove(&priv->gpio_chip)) | ||
431 | dev_err(dev, "failed to remove gpio chip\n"); | ||
432 | return ret; | ||
433 | } | ||
434 | |||
435 | static int ts5500_dio_remove(struct platform_device *pdev) | ||
436 | { | ||
437 | struct ts5500_priv *priv = platform_get_drvdata(pdev); | ||
438 | |||
439 | ts5500_disable_irq(priv); | ||
440 | return gpiochip_remove(&priv->gpio_chip); | ||
441 | } | ||
442 | |||
443 | static struct platform_device_id ts5500_dio_ids[] = { | ||
444 | { "ts5500-dio1", TS5500_DIO1 }, | ||
445 | { "ts5500-dio2", TS5500_DIO2 }, | ||
446 | { "ts5500-dio-lcd", TS5500_LCD }, | ||
447 | { "ts5600-dio-lcd", TS5600_LCD }, | ||
448 | { } | ||
449 | }; | ||
450 | MODULE_DEVICE_TABLE(platform, ts5500_dio_ids); | ||
451 | |||
452 | static struct platform_driver ts5500_dio_driver = { | ||
453 | .driver = { | ||
454 | .name = "ts5500-dio", | ||
455 | .owner = THIS_MODULE, | ||
456 | }, | ||
457 | .probe = ts5500_dio_probe, | ||
458 | .remove = ts5500_dio_remove, | ||
459 | .id_table = ts5500_dio_ids, | ||
460 | }; | ||
461 | |||
462 | module_platform_driver(ts5500_dio_driver); | ||
463 | |||
464 | MODULE_LICENSE("GPL"); | ||
465 | MODULE_AUTHOR("Savoir-faire Linux Inc. <kernel@savoirfairelinux.com>"); | ||
466 | MODULE_DESCRIPTION("Technologic Systems TS-5500 Digital I/O driver"); | ||
diff --git a/drivers/gpio/gpio-twl4030.c b/drivers/gpio/gpio-twl4030.c index 9572aa137e6..b8b4f228757 100644 --- a/drivers/gpio/gpio-twl4030.c +++ b/drivers/gpio/gpio-twl4030.c | |||
@@ -32,8 +32,6 @@ | |||
32 | #include <linux/irq.h> | 32 | #include <linux/irq.h> |
33 | #include <linux/gpio.h> | 33 | #include <linux/gpio.h> |
34 | #include <linux/platform_device.h> | 34 | #include <linux/platform_device.h> |
35 | #include <linux/of.h> | ||
36 | #include <linux/irqdomain.h> | ||
37 | 35 | ||
38 | #include <linux/i2c/twl.h> | 36 | #include <linux/i2c/twl.h> |
39 | 37 | ||
@@ -51,7 +49,6 @@ | |||
51 | 49 | ||
52 | 50 | ||
53 | static struct gpio_chip twl_gpiochip; | 51 | static struct gpio_chip twl_gpiochip; |
54 | static int twl4030_gpio_base; | ||
55 | static int twl4030_gpio_irq_base; | 52 | static int twl4030_gpio_irq_base; |
56 | 53 | ||
57 | /* genirq interfaces are not available to modules */ | 54 | /* genirq interfaces are not available to modules */ |
@@ -88,15 +85,11 @@ static inline int gpio_twl4030_write(u8 address, u8 data) | |||
88 | /*----------------------------------------------------------------------*/ | 85 | /*----------------------------------------------------------------------*/ |
89 | 86 | ||
90 | /* | 87 | /* |
91 | * LED register offsets from TWL_MODULE_LED base | 88 | * LED register offsets (use TWL4030_MODULE_{LED,PWMA,PWMB})) |
92 | * PWMs A and B are dedicated to LEDs A and B, respectively. | 89 | * PWMs A and B are dedicated to LEDs A and B, respectively. |
93 | */ | 90 | */ |
94 | 91 | ||
95 | #define TWL4030_LED_LEDEN_REG 0x00 | 92 | #define TWL4030_LED_LEDEN 0x0 |
96 | #define TWL4030_PWMAON_REG 0x01 | ||
97 | #define TWL4030_PWMAOFF_REG 0x02 | ||
98 | #define TWL4030_PWMBON_REG 0x03 | ||
99 | #define TWL4030_PWMBOFF_REG 0x04 | ||
100 | 93 | ||
101 | /* LEDEN bits */ | 94 | /* LEDEN bits */ |
102 | #define LEDEN_LEDAON BIT(0) | 95 | #define LEDEN_LEDAON BIT(0) |
@@ -108,6 +101,9 @@ static inline int gpio_twl4030_write(u8 address, u8 data) | |||
108 | #define LEDEN_PWM_LENGTHA BIT(6) | 101 | #define LEDEN_PWM_LENGTHA BIT(6) |
109 | #define LEDEN_PWM_LENGTHB BIT(7) | 102 | #define LEDEN_PWM_LENGTHB BIT(7) |
110 | 103 | ||
104 | #define TWL4030_PWMx_PWMxON 0x0 | ||
105 | #define TWL4030_PWMx_PWMxOFF 0x1 | ||
106 | |||
111 | #define PWMxON_LENGTH BIT(7) | 107 | #define PWMxON_LENGTH BIT(7) |
112 | 108 | ||
113 | /*----------------------------------------------------------------------*/ | 109 | /*----------------------------------------------------------------------*/ |
@@ -146,7 +142,7 @@ static void twl4030_led_set_value(int led, int value) | |||
146 | else | 142 | else |
147 | cached_leden |= mask; | 143 | cached_leden |= mask; |
148 | status = twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden, | 144 | status = twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden, |
149 | TWL4030_LED_LEDEN_REG); | 145 | TWL4030_LED_LEDEN); |
150 | mutex_unlock(&gpio_lock); | 146 | mutex_unlock(&gpio_lock); |
151 | } | 147 | } |
152 | 148 | ||
@@ -217,33 +213,33 @@ static int twl_request(struct gpio_chip *chip, unsigned offset) | |||
217 | if (offset >= TWL4030_GPIO_MAX) { | 213 | if (offset >= TWL4030_GPIO_MAX) { |
218 | u8 ledclr_mask = LEDEN_LEDAON | LEDEN_LEDAEXT | 214 | u8 ledclr_mask = LEDEN_LEDAON | LEDEN_LEDAEXT |
219 | | LEDEN_LEDAPWM | LEDEN_PWM_LENGTHA; | 215 | | LEDEN_LEDAPWM | LEDEN_PWM_LENGTHA; |
220 | u8 reg = TWL4030_PWMAON_REG; | 216 | u8 module = TWL4030_MODULE_PWMA; |
221 | 217 | ||
222 | offset -= TWL4030_GPIO_MAX; | 218 | offset -= TWL4030_GPIO_MAX; |
223 | if (offset) { | 219 | if (offset) { |
224 | ledclr_mask <<= 1; | 220 | ledclr_mask <<= 1; |
225 | reg = TWL4030_PWMBON_REG; | 221 | module = TWL4030_MODULE_PWMB; |
226 | } | 222 | } |
227 | 223 | ||
228 | /* initialize PWM to always-drive */ | 224 | /* initialize PWM to always-drive */ |
229 | /* Configure PWM OFF register first */ | 225 | status = twl_i2c_write_u8(module, 0x7f, |
230 | status = twl_i2c_write_u8(TWL4030_MODULE_LED, 0x7f, reg + 1); | 226 | TWL4030_PWMx_PWMxOFF); |
231 | if (status < 0) | 227 | if (status < 0) |
232 | goto done; | 228 | goto done; |
233 | 229 | status = twl_i2c_write_u8(module, 0x7f, | |
234 | /* Followed by PWM ON register */ | 230 | TWL4030_PWMx_PWMxON); |
235 | status = twl_i2c_write_u8(TWL4030_MODULE_LED, 0x7f, reg); | ||
236 | if (status < 0) | 231 | if (status < 0) |
237 | goto done; | 232 | goto done; |
238 | 233 | ||
239 | /* init LED to not-driven (high) */ | 234 | /* init LED to not-driven (high) */ |
240 | status = twl_i2c_read_u8(TWL4030_MODULE_LED, &cached_leden, | 235 | module = TWL4030_MODULE_LED; |
241 | TWL4030_LED_LEDEN_REG); | 236 | status = twl_i2c_read_u8(module, &cached_leden, |
237 | TWL4030_LED_LEDEN); | ||
242 | if (status < 0) | 238 | if (status < 0) |
243 | goto done; | 239 | goto done; |
244 | cached_leden &= ~ledclr_mask; | 240 | cached_leden &= ~ledclr_mask; |
245 | status = twl_i2c_write_u8(TWL4030_MODULE_LED, cached_leden, | 241 | status = twl_i2c_write_u8(module, cached_leden, |
246 | TWL4030_LED_LEDEN_REG); | 242 | TWL4030_LED_LEDEN); |
247 | if (status < 0) | 243 | if (status < 0) |
248 | goto done; | 244 | goto done; |
249 | 245 | ||
@@ -260,8 +256,7 @@ static int twl_request(struct gpio_chip *chip, unsigned offset) | |||
260 | * and vMMC2 power supplies based on card presence. | 256 | * and vMMC2 power supplies based on card presence. |
261 | */ | 257 | */ |
262 | pdata = chip->dev->platform_data; | 258 | pdata = chip->dev->platform_data; |
263 | if (pdata) | 259 | value |= pdata->mmc_cd & 0x03; |
264 | value |= pdata->mmc_cd & 0x03; | ||
265 | 260 | ||
266 | status = gpio_twl4030_write(REG_GPIO_CTRL, value); | 261 | status = gpio_twl4030_write(REG_GPIO_CTRL, value); |
267 | } | 262 | } |
@@ -353,15 +348,15 @@ static struct gpio_chip twl_gpiochip = { | |||
353 | 348 | ||
354 | /*----------------------------------------------------------------------*/ | 349 | /*----------------------------------------------------------------------*/ |
355 | 350 | ||
356 | static int gpio_twl4030_pulls(u32 ups, u32 downs) | 351 | static int __devinit gpio_twl4030_pulls(u32 ups, u32 downs) |
357 | { | 352 | { |
358 | u8 message[5]; | 353 | u8 message[6]; |
359 | unsigned i, gpio_bit; | 354 | unsigned i, gpio_bit; |
360 | 355 | ||
361 | /* For most pins, a pulldown was enabled by default. | 356 | /* For most pins, a pulldown was enabled by default. |
362 | * We should have data that's specific to this board. | 357 | * We should have data that's specific to this board. |
363 | */ | 358 | */ |
364 | for (gpio_bit = 1, i = 0; i < 5; i++) { | 359 | for (gpio_bit = 1, i = 1; i < 6; i++) { |
365 | u8 bit_mask; | 360 | u8 bit_mask; |
366 | unsigned j; | 361 | unsigned j; |
367 | 362 | ||
@@ -378,18 +373,18 @@ static int gpio_twl4030_pulls(u32 ups, u32 downs) | |||
378 | REG_GPIOPUPDCTR1, 5); | 373 | REG_GPIOPUPDCTR1, 5); |
379 | } | 374 | } |
380 | 375 | ||
381 | static int gpio_twl4030_debounce(u32 debounce, u8 mmc_cd) | 376 | static int __devinit gpio_twl4030_debounce(u32 debounce, u8 mmc_cd) |
382 | { | 377 | { |
383 | u8 message[3]; | 378 | u8 message[4]; |
384 | 379 | ||
385 | /* 30 msec of debouncing is always used for MMC card detect, | 380 | /* 30 msec of debouncing is always used for MMC card detect, |
386 | * and is optional for everything else. | 381 | * and is optional for everything else. |
387 | */ | 382 | */ |
388 | message[0] = (debounce & 0xff) | (mmc_cd & 0x03); | 383 | message[1] = (debounce & 0xff) | (mmc_cd & 0x03); |
389 | debounce >>= 8; | 384 | debounce >>= 8; |
390 | message[1] = (debounce & 0xff); | 385 | message[2] = (debounce & 0xff); |
391 | debounce >>= 8; | 386 | debounce >>= 8; |
392 | message[2] = (debounce & 0x03); | 387 | message[3] = (debounce & 0x03); |
393 | 388 | ||
394 | return twl_i2c_write(TWL4030_MODULE_GPIO, message, | 389 | return twl_i2c_write(TWL4030_MODULE_GPIO, message, |
395 | REG_GPIO_DEBEN1, 3); | 390 | REG_GPIO_DEBEN1, 3); |
@@ -397,69 +392,26 @@ static int gpio_twl4030_debounce(u32 debounce, u8 mmc_cd) | |||
397 | 392 | ||
398 | static int gpio_twl4030_remove(struct platform_device *pdev); | 393 | static int gpio_twl4030_remove(struct platform_device *pdev); |
399 | 394 | ||
400 | static struct twl4030_gpio_platform_data *of_gpio_twl4030(struct device *dev) | 395 | static int __devinit gpio_twl4030_probe(struct platform_device *pdev) |
401 | { | ||
402 | struct twl4030_gpio_platform_data *omap_twl_info; | ||
403 | |||
404 | omap_twl_info = devm_kzalloc(dev, sizeof(*omap_twl_info), GFP_KERNEL); | ||
405 | if (!omap_twl_info) | ||
406 | return NULL; | ||
407 | |||
408 | omap_twl_info->use_leds = of_property_read_bool(dev->of_node, | ||
409 | "ti,use-leds"); | ||
410 | |||
411 | of_property_read_u32(dev->of_node, "ti,debounce", | ||
412 | &omap_twl_info->debounce); | ||
413 | of_property_read_u32(dev->of_node, "ti,mmc-cd", | ||
414 | (u32 *)&omap_twl_info->mmc_cd); | ||
415 | of_property_read_u32(dev->of_node, "ti,pullups", | ||
416 | &omap_twl_info->pullups); | ||
417 | of_property_read_u32(dev->of_node, "ti,pulldowns", | ||
418 | &omap_twl_info->pulldowns); | ||
419 | |||
420 | return omap_twl_info; | ||
421 | } | ||
422 | |||
423 | static int gpio_twl4030_probe(struct platform_device *pdev) | ||
424 | { | 396 | { |
425 | struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data; | 397 | struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data; |
426 | struct device_node *node = pdev->dev.of_node; | 398 | int ret; |
427 | int ret, irq_base; | ||
428 | 399 | ||
429 | /* maybe setup IRQs */ | 400 | /* maybe setup IRQs */ |
430 | if (is_module()) { | 401 | if (pdata->irq_base) { |
431 | dev_err(&pdev->dev, "can't dispatch IRQs from modules\n"); | 402 | if (is_module()) { |
432 | goto no_irqs; | 403 | dev_err(&pdev->dev, |
433 | } | 404 | "can't dispatch IRQs from modules\n"); |
434 | 405 | goto no_irqs; | |
435 | irq_base = irq_alloc_descs(-1, 0, TWL4030_GPIO_MAX, 0); | 406 | } |
436 | if (irq_base < 0) { | 407 | ret = twl4030_sih_setup(TWL4030_MODULE_GPIO); |
437 | dev_err(&pdev->dev, "Failed to alloc irq_descs\n"); | 408 | if (ret < 0) |
438 | return irq_base; | 409 | return ret; |
410 | WARN_ON(ret != pdata->irq_base); | ||
411 | twl4030_gpio_irq_base = ret; | ||
439 | } | 412 | } |
440 | 413 | ||
441 | irq_domain_add_legacy(node, TWL4030_GPIO_MAX, irq_base, 0, | ||
442 | &irq_domain_simple_ops, NULL); | ||
443 | |||
444 | ret = twl4030_sih_setup(&pdev->dev, TWL4030_MODULE_GPIO, irq_base); | ||
445 | if (ret < 0) | ||
446 | return ret; | ||
447 | |||
448 | twl4030_gpio_irq_base = irq_base; | ||
449 | |||
450 | no_irqs: | 414 | no_irqs: |
451 | twl_gpiochip.base = -1; | ||
452 | twl_gpiochip.ngpio = TWL4030_GPIO_MAX; | ||
453 | twl_gpiochip.dev = &pdev->dev; | ||
454 | |||
455 | if (node) | ||
456 | pdata = of_gpio_twl4030(&pdev->dev); | ||
457 | |||
458 | if (pdata == NULL) { | ||
459 | dev_err(&pdev->dev, "Platform data is missing\n"); | ||
460 | return -ENXIO; | ||
461 | } | ||
462 | |||
463 | /* | 415 | /* |
464 | * NOTE: boards may waste power if they don't set pullups | 416 | * NOTE: boards may waste power if they don't set pullups |
465 | * and pulldowns correctly ... default for non-ULPI pins is | 417 | * and pulldowns correctly ... default for non-ULPI pins is |
@@ -469,15 +421,20 @@ no_irqs: | |||
469 | ret = gpio_twl4030_pulls(pdata->pullups, pdata->pulldowns); | 421 | ret = gpio_twl4030_pulls(pdata->pullups, pdata->pulldowns); |
470 | if (ret) | 422 | if (ret) |
471 | dev_dbg(&pdev->dev, "pullups %.05x %.05x --> %d\n", | 423 | dev_dbg(&pdev->dev, "pullups %.05x %.05x --> %d\n", |
472 | pdata->pullups, pdata->pulldowns, ret); | 424 | pdata->pullups, pdata->pulldowns, |
425 | ret); | ||
473 | 426 | ||
474 | ret = gpio_twl4030_debounce(pdata->debounce, pdata->mmc_cd); | 427 | ret = gpio_twl4030_debounce(pdata->debounce, pdata->mmc_cd); |
475 | if (ret) | 428 | if (ret) |
476 | dev_dbg(&pdev->dev, "debounce %.03x %.01x --> %d\n", | 429 | dev_dbg(&pdev->dev, "debounce %.03x %.01x --> %d\n", |
477 | pdata->debounce, pdata->mmc_cd, ret); | 430 | pdata->debounce, pdata->mmc_cd, |
431 | ret); | ||
478 | 432 | ||
479 | /* | 433 | twl_gpiochip.base = pdata->gpio_base; |
480 | * NOTE: we assume VIBRA_CTL.VIBRA_EN, in MODULE_AUDIO_VOICE, | 434 | twl_gpiochip.ngpio = TWL4030_GPIO_MAX; |
435 | twl_gpiochip.dev = &pdev->dev; | ||
436 | |||
437 | /* NOTE: we assume VIBRA_CTL.VIBRA_EN, in MODULE_AUDIO_VOICE, | ||
481 | * is (still) clear if use_leds is set. | 438 | * is (still) clear if use_leds is set. |
482 | */ | 439 | */ |
483 | if (pdata->use_leds) | 440 | if (pdata->use_leds) |
@@ -485,36 +442,32 @@ no_irqs: | |||
485 | 442 | ||
486 | ret = gpiochip_add(&twl_gpiochip); | 443 | ret = gpiochip_add(&twl_gpiochip); |
487 | if (ret < 0) { | 444 | if (ret < 0) { |
488 | dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); | 445 | dev_err(&pdev->dev, |
446 | "could not register gpiochip, %d\n", | ||
447 | ret); | ||
489 | twl_gpiochip.ngpio = 0; | 448 | twl_gpiochip.ngpio = 0; |
490 | gpio_twl4030_remove(pdev); | 449 | gpio_twl4030_remove(pdev); |
491 | goto out; | 450 | } else if (pdata->setup) { |
492 | } | ||
493 | |||
494 | twl4030_gpio_base = twl_gpiochip.base; | ||
495 | |||
496 | if (pdata && pdata->setup) { | ||
497 | int status; | 451 | int status; |
498 | 452 | ||
499 | status = pdata->setup(&pdev->dev, | 453 | status = pdata->setup(&pdev->dev, |
500 | twl4030_gpio_base, TWL4030_GPIO_MAX); | 454 | pdata->gpio_base, TWL4030_GPIO_MAX); |
501 | if (status) | 455 | if (status) |
502 | dev_dbg(&pdev->dev, "setup --> %d\n", status); | 456 | dev_dbg(&pdev->dev, "setup --> %d\n", status); |
503 | } | 457 | } |
504 | 458 | ||
505 | out: | ||
506 | return ret; | 459 | return ret; |
507 | } | 460 | } |
508 | 461 | ||
509 | /* Cannot use as gpio_twl4030_probe() calls us */ | 462 | /* Cannot use __devexit as gpio_twl4030_probe() calls us */ |
510 | static int gpio_twl4030_remove(struct platform_device *pdev) | 463 | static int gpio_twl4030_remove(struct platform_device *pdev) |
511 | { | 464 | { |
512 | struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data; | 465 | struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data; |
513 | int status; | 466 | int status; |
514 | 467 | ||
515 | if (pdata && pdata->teardown) { | 468 | if (pdata->teardown) { |
516 | status = pdata->teardown(&pdev->dev, | 469 | status = pdata->teardown(&pdev->dev, |
517 | twl4030_gpio_base, TWL4030_GPIO_MAX); | 470 | pdata->gpio_base, TWL4030_GPIO_MAX); |
518 | if (status) { | 471 | if (status) { |
519 | dev_dbg(&pdev->dev, "teardown --> %d\n", status); | 472 | dev_dbg(&pdev->dev, "teardown --> %d\n", status); |
520 | return status; | 473 | return status; |
@@ -533,21 +486,12 @@ static int gpio_twl4030_remove(struct platform_device *pdev) | |||
533 | return -EIO; | 486 | return -EIO; |
534 | } | 487 | } |
535 | 488 | ||
536 | static const struct of_device_id twl_gpio_match[] = { | ||
537 | { .compatible = "ti,twl4030-gpio", }, | ||
538 | { }, | ||
539 | }; | ||
540 | MODULE_DEVICE_TABLE(of, twl_gpio_match); | ||
541 | |||
542 | /* Note: this hardware lives inside an I2C-based multi-function device. */ | 489 | /* Note: this hardware lives inside an I2C-based multi-function device. */ |
543 | MODULE_ALIAS("platform:twl4030_gpio"); | 490 | MODULE_ALIAS("platform:twl4030_gpio"); |
544 | 491 | ||
545 | static struct platform_driver gpio_twl4030_driver = { | 492 | static struct platform_driver gpio_twl4030_driver = { |
546 | .driver = { | 493 | .driver.name = "twl4030_gpio", |
547 | .name = "twl4030_gpio", | 494 | .driver.owner = THIS_MODULE, |
548 | .owner = THIS_MODULE, | ||
549 | .of_match_table = of_match_ptr(twl_gpio_match), | ||
550 | }, | ||
551 | .probe = gpio_twl4030_probe, | 495 | .probe = gpio_twl4030_probe, |
552 | .remove = gpio_twl4030_remove, | 496 | .remove = gpio_twl4030_remove, |
553 | }; | 497 | }; |
diff --git a/drivers/gpio/gpio-twl6040.c b/drivers/gpio/gpio-twl6040.c deleted file mode 100644 index 0be82c6dd79..00000000000 --- a/drivers/gpio/gpio-twl6040.c +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | /* | ||
2 | * Access to GPOs on TWL6040 chip | ||
3 | * | ||
4 | * Copyright (C) 2012 Texas Instruments, Inc. | ||
5 | * | ||
6 | * Authors: | ||
7 | * Sergio Aguirre <saaguirre@ti.com> | ||
8 | * Peter Ujfalusi <peter.ujfalusi@ti.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | |||
25 | #include <linux/module.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/kthread.h> | ||
28 | #include <linux/irq.h> | ||
29 | #include <linux/gpio.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/of.h> | ||
32 | |||
33 | #include <linux/mfd/twl6040.h> | ||
34 | |||
35 | static struct gpio_chip twl6040gpo_chip; | ||
36 | |||
37 | static int twl6040gpo_get(struct gpio_chip *chip, unsigned offset) | ||
38 | { | ||
39 | struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent); | ||
40 | int ret = 0; | ||
41 | |||
42 | ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL); | ||
43 | if (ret < 0) | ||
44 | return ret; | ||
45 | |||
46 | return (ret >> offset) & 1; | ||
47 | } | ||
48 | |||
49 | static int twl6040gpo_direction_out(struct gpio_chip *chip, unsigned offset, | ||
50 | int value) | ||
51 | { | ||
52 | /* This only drives GPOs, and can't change direction */ | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | static void twl6040gpo_set(struct gpio_chip *chip, unsigned offset, int value) | ||
57 | { | ||
58 | struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent); | ||
59 | int ret; | ||
60 | u8 gpoctl; | ||
61 | |||
62 | ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL); | ||
63 | if (ret < 0) | ||
64 | return; | ||
65 | |||
66 | if (value) | ||
67 | gpoctl = ret | (1 << offset); | ||
68 | else | ||
69 | gpoctl = ret & ~(1 << offset); | ||
70 | |||
71 | twl6040_reg_write(twl6040, TWL6040_REG_GPOCTL, gpoctl); | ||
72 | } | ||
73 | |||
74 | static struct gpio_chip twl6040gpo_chip = { | ||
75 | .label = "twl6040", | ||
76 | .owner = THIS_MODULE, | ||
77 | .get = twl6040gpo_get, | ||
78 | .direction_output = twl6040gpo_direction_out, | ||
79 | .set = twl6040gpo_set, | ||
80 | .can_sleep = 1, | ||
81 | }; | ||
82 | |||
83 | /*----------------------------------------------------------------------*/ | ||
84 | |||
85 | static int gpo_twl6040_probe(struct platform_device *pdev) | ||
86 | { | ||
87 | struct twl6040_gpo_data *pdata = pdev->dev.platform_data; | ||
88 | struct device *twl6040_core_dev = pdev->dev.parent; | ||
89 | struct twl6040 *twl6040 = dev_get_drvdata(twl6040_core_dev); | ||
90 | int ret; | ||
91 | |||
92 | if (pdata) | ||
93 | twl6040gpo_chip.base = pdata->gpio_base; | ||
94 | else | ||
95 | twl6040gpo_chip.base = -1; | ||
96 | |||
97 | if (twl6040_get_revid(twl6040) < TWL6041_REV_ES2_0) | ||
98 | twl6040gpo_chip.ngpio = 3; /* twl6040 have 3 GPO */ | ||
99 | else | ||
100 | twl6040gpo_chip.ngpio = 1; /* twl6041 have 1 GPO */ | ||
101 | |||
102 | twl6040gpo_chip.dev = &pdev->dev; | ||
103 | #ifdef CONFIG_OF_GPIO | ||
104 | twl6040gpo_chip.of_node = twl6040_core_dev->of_node; | ||
105 | #endif | ||
106 | |||
107 | ret = gpiochip_add(&twl6040gpo_chip); | ||
108 | if (ret < 0) { | ||
109 | dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); | ||
110 | twl6040gpo_chip.ngpio = 0; | ||
111 | } | ||
112 | |||
113 | return ret; | ||
114 | } | ||
115 | |||
116 | static int gpo_twl6040_remove(struct platform_device *pdev) | ||
117 | { | ||
118 | return gpiochip_remove(&twl6040gpo_chip); | ||
119 | } | ||
120 | |||
121 | /* Note: this hardware lives inside an I2C-based multi-function device. */ | ||
122 | MODULE_ALIAS("platform:twl6040-gpo"); | ||
123 | |||
124 | static struct platform_driver gpo_twl6040_driver = { | ||
125 | .driver = { | ||
126 | .name = "twl6040-gpo", | ||
127 | .owner = THIS_MODULE, | ||
128 | }, | ||
129 | .probe = gpo_twl6040_probe, | ||
130 | .remove = gpo_twl6040_remove, | ||
131 | }; | ||
132 | |||
133 | module_platform_driver(gpo_twl6040_driver); | ||
134 | |||
135 | MODULE_AUTHOR("Texas Instruments, Inc."); | ||
136 | MODULE_DESCRIPTION("GPO interface for TWL6040"); | ||
137 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpio/gpio-ucb1400.c b/drivers/gpio/gpio-ucb1400.c index 26405efe0f9..50e6bd1392c 100644 --- a/drivers/gpio/gpio-ucb1400.c +++ b/drivers/gpio/gpio-ucb1400.c | |||
@@ -103,12 +103,23 @@ static struct platform_driver ucb1400_gpio_driver = { | |||
103 | }, | 103 | }, |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static int __init ucb1400_gpio_init(void) | ||
107 | { | ||
108 | return platform_driver_register(&ucb1400_gpio_driver); | ||
109 | } | ||
110 | |||
111 | static void __exit ucb1400_gpio_exit(void) | ||
112 | { | ||
113 | platform_driver_unregister(&ucb1400_gpio_driver); | ||
114 | } | ||
115 | |||
106 | void __init ucb1400_gpio_set_data(struct ucb1400_gpio_data *data) | 116 | void __init ucb1400_gpio_set_data(struct ucb1400_gpio_data *data) |
107 | { | 117 | { |
108 | ucbdata = data; | 118 | ucbdata = data; |
109 | } | 119 | } |
110 | 120 | ||
111 | module_platform_driver(ucb1400_gpio_driver); | 121 | module_init(ucb1400_gpio_init); |
122 | module_exit(ucb1400_gpio_exit); | ||
112 | 123 | ||
113 | MODULE_DESCRIPTION("Philips UCB1400 GPIO driver"); | 124 | MODULE_DESCRIPTION("Philips UCB1400 GPIO driver"); |
114 | MODULE_LICENSE("GPL"); | 125 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c deleted file mode 100644 index 59d72391de2..00000000000 --- a/drivers/gpio/gpio-viperboard.c +++ /dev/null | |||
@@ -1,517 +0,0 @@ | |||
1 | /* | ||
2 | * Nano River Technologies viperboard GPIO lib driver | ||
3 | * | ||
4 | * (C) 2012 by Lemonage GmbH | ||
5 | * Author: Lars Poeschel <poeschel@lemonage.de> | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/mutex.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | |||
23 | #include <linux/usb.h> | ||
24 | #include <linux/gpio.h> | ||
25 | |||
26 | #include <linux/mfd/viperboard.h> | ||
27 | |||
28 | #define VPRBRD_GPIOA_CLK_1MHZ 0 | ||
29 | #define VPRBRD_GPIOA_CLK_100KHZ 1 | ||
30 | #define VPRBRD_GPIOA_CLK_10KHZ 2 | ||
31 | #define VPRBRD_GPIOA_CLK_1KHZ 3 | ||
32 | #define VPRBRD_GPIOA_CLK_100HZ 4 | ||
33 | #define VPRBRD_GPIOA_CLK_10HZ 5 | ||
34 | |||
35 | #define VPRBRD_GPIOA_FREQ_DEFAULT 1000 | ||
36 | |||
37 | #define VPRBRD_GPIOA_CMD_CONT 0x00 | ||
38 | #define VPRBRD_GPIOA_CMD_PULSE 0x01 | ||
39 | #define VPRBRD_GPIOA_CMD_PWM 0x02 | ||
40 | #define VPRBRD_GPIOA_CMD_SETOUT 0x03 | ||
41 | #define VPRBRD_GPIOA_CMD_SETIN 0x04 | ||
42 | #define VPRBRD_GPIOA_CMD_SETINT 0x05 | ||
43 | #define VPRBRD_GPIOA_CMD_GETIN 0x06 | ||
44 | |||
45 | #define VPRBRD_GPIOB_CMD_SETDIR 0x00 | ||
46 | #define VPRBRD_GPIOB_CMD_SETVAL 0x01 | ||
47 | |||
48 | struct vprbrd_gpioa_msg { | ||
49 | u8 cmd; | ||
50 | u8 clk; | ||
51 | u8 offset; | ||
52 | u8 t1; | ||
53 | u8 t2; | ||
54 | u8 invert; | ||
55 | u8 pwmlevel; | ||
56 | u8 outval; | ||
57 | u8 risefall; | ||
58 | u8 answer; | ||
59 | u8 __fill; | ||
60 | } __packed; | ||
61 | |||
62 | struct vprbrd_gpiob_msg { | ||
63 | u8 cmd; | ||
64 | u16 val; | ||
65 | u16 mask; | ||
66 | } __packed; | ||
67 | |||
68 | struct vprbrd_gpio { | ||
69 | struct gpio_chip gpioa; /* gpio a related things */ | ||
70 | u32 gpioa_out; | ||
71 | u32 gpioa_val; | ||
72 | struct gpio_chip gpiob; /* gpio b related things */ | ||
73 | u32 gpiob_out; | ||
74 | u32 gpiob_val; | ||
75 | struct vprbrd *vb; | ||
76 | }; | ||
77 | |||
78 | /* gpioa sampling clock module parameter */ | ||
79 | static unsigned char gpioa_clk; | ||
80 | static unsigned int gpioa_freq = VPRBRD_GPIOA_FREQ_DEFAULT; | ||
81 | module_param(gpioa_freq, uint, 0); | ||
82 | MODULE_PARM_DESC(gpioa_freq, | ||
83 | "gpio-a sampling freq in Hz (default is 1000Hz) valid values: 10, 100, 1000, 10000, 100000, 1000000"); | ||
84 | |||
85 | /* ----- begin of gipo a chip -------------------------------------------- */ | ||
86 | |||
87 | static int vprbrd_gpioa_get(struct gpio_chip *chip, | ||
88 | unsigned offset) | ||
89 | { | ||
90 | int ret, answer, error = 0; | ||
91 | struct vprbrd_gpio *gpio = | ||
92 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
93 | struct vprbrd *vb = gpio->vb; | ||
94 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
95 | |||
96 | /* if io is set to output, just return the saved value */ | ||
97 | if (gpio->gpioa_out & (1 << offset)) | ||
98 | return gpio->gpioa_val & (1 << offset); | ||
99 | |||
100 | mutex_lock(&vb->lock); | ||
101 | |||
102 | gamsg->cmd = VPRBRD_GPIOA_CMD_GETIN; | ||
103 | gamsg->clk = 0x00; | ||
104 | gamsg->offset = offset; | ||
105 | gamsg->t1 = 0x00; | ||
106 | gamsg->t2 = 0x00; | ||
107 | gamsg->invert = 0x00; | ||
108 | gamsg->pwmlevel = 0x00; | ||
109 | gamsg->outval = 0x00; | ||
110 | gamsg->risefall = 0x00; | ||
111 | gamsg->answer = 0x00; | ||
112 | gamsg->__fill = 0x00; | ||
113 | |||
114 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
115 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
116 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
117 | VPRBRD_USB_TIMEOUT_MS); | ||
118 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
119 | error = -EREMOTEIO; | ||
120 | |||
121 | ret = usb_control_msg(vb->usb_dev, usb_rcvctrlpipe(vb->usb_dev, 0), | ||
122 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_IN, 0x0000, | ||
123 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
124 | VPRBRD_USB_TIMEOUT_MS); | ||
125 | answer = gamsg->answer & 0x01; | ||
126 | |||
127 | mutex_unlock(&vb->lock); | ||
128 | |||
129 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
130 | error = -EREMOTEIO; | ||
131 | |||
132 | if (error) | ||
133 | return error; | ||
134 | |||
135 | return answer; | ||
136 | } | ||
137 | |||
138 | static void vprbrd_gpioa_set(struct gpio_chip *chip, | ||
139 | unsigned offset, int value) | ||
140 | { | ||
141 | int ret; | ||
142 | struct vprbrd_gpio *gpio = | ||
143 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
144 | struct vprbrd *vb = gpio->vb; | ||
145 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
146 | |||
147 | if (gpio->gpioa_out & (1 << offset)) { | ||
148 | if (value) | ||
149 | gpio->gpioa_val |= (1 << offset); | ||
150 | else | ||
151 | gpio->gpioa_val &= ~(1 << offset); | ||
152 | |||
153 | mutex_lock(&vb->lock); | ||
154 | |||
155 | gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT; | ||
156 | gamsg->clk = 0x00; | ||
157 | gamsg->offset = offset; | ||
158 | gamsg->t1 = 0x00; | ||
159 | gamsg->t2 = 0x00; | ||
160 | gamsg->invert = 0x00; | ||
161 | gamsg->pwmlevel = 0x00; | ||
162 | gamsg->outval = value; | ||
163 | gamsg->risefall = 0x00; | ||
164 | gamsg->answer = 0x00; | ||
165 | gamsg->__fill = 0x00; | ||
166 | |||
167 | ret = usb_control_msg(vb->usb_dev, | ||
168 | usb_sndctrlpipe(vb->usb_dev, 0), | ||
169 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, | ||
170 | 0x0000, 0x0000, gamsg, | ||
171 | sizeof(struct vprbrd_gpioa_msg), VPRBRD_USB_TIMEOUT_MS); | ||
172 | |||
173 | mutex_unlock(&vb->lock); | ||
174 | |||
175 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
176 | dev_err(chip->dev, "usb error setting pin value\n"); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | static int vprbrd_gpioa_direction_input(struct gpio_chip *chip, | ||
181 | unsigned offset) | ||
182 | { | ||
183 | int ret; | ||
184 | struct vprbrd_gpio *gpio = | ||
185 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
186 | struct vprbrd *vb = gpio->vb; | ||
187 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
188 | |||
189 | gpio->gpioa_out &= ~(1 << offset); | ||
190 | |||
191 | mutex_lock(&vb->lock); | ||
192 | |||
193 | gamsg->cmd = VPRBRD_GPIOA_CMD_SETIN; | ||
194 | gamsg->clk = gpioa_clk; | ||
195 | gamsg->offset = offset; | ||
196 | gamsg->t1 = 0x00; | ||
197 | gamsg->t2 = 0x00; | ||
198 | gamsg->invert = 0x00; | ||
199 | gamsg->pwmlevel = 0x00; | ||
200 | gamsg->outval = 0x00; | ||
201 | gamsg->risefall = 0x00; | ||
202 | gamsg->answer = 0x00; | ||
203 | gamsg->__fill = 0x00; | ||
204 | |||
205 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
206 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
207 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
208 | VPRBRD_USB_TIMEOUT_MS); | ||
209 | |||
210 | mutex_unlock(&vb->lock); | ||
211 | |||
212 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
213 | return -EREMOTEIO; | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | static int vprbrd_gpioa_direction_output(struct gpio_chip *chip, | ||
219 | unsigned offset, int value) | ||
220 | { | ||
221 | int ret; | ||
222 | struct vprbrd_gpio *gpio = | ||
223 | container_of(chip, struct vprbrd_gpio, gpioa); | ||
224 | struct vprbrd *vb = gpio->vb; | ||
225 | struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf; | ||
226 | |||
227 | gpio->gpioa_out |= (1 << offset); | ||
228 | if (value) | ||
229 | gpio->gpioa_val |= (1 << offset); | ||
230 | else | ||
231 | gpio->gpioa_val &= ~(1 << offset); | ||
232 | |||
233 | mutex_lock(&vb->lock); | ||
234 | |||
235 | gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT; | ||
236 | gamsg->clk = 0x00; | ||
237 | gamsg->offset = offset; | ||
238 | gamsg->t1 = 0x00; | ||
239 | gamsg->t2 = 0x00; | ||
240 | gamsg->invert = 0x00; | ||
241 | gamsg->pwmlevel = 0x00; | ||
242 | gamsg->outval = value; | ||
243 | gamsg->risefall = 0x00; | ||
244 | gamsg->answer = 0x00; | ||
245 | gamsg->__fill = 0x00; | ||
246 | |||
247 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
248 | VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
249 | 0x0000, gamsg, sizeof(struct vprbrd_gpioa_msg), | ||
250 | VPRBRD_USB_TIMEOUT_MS); | ||
251 | |||
252 | mutex_unlock(&vb->lock); | ||
253 | |||
254 | if (ret != sizeof(struct vprbrd_gpioa_msg)) | ||
255 | return -EREMOTEIO; | ||
256 | |||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | /* ----- end of gpio a chip ---------------------------------------------- */ | ||
261 | |||
262 | /* ----- begin of gipo b chip -------------------------------------------- */ | ||
263 | |||
264 | static int vprbrd_gpiob_setdir(struct vprbrd *vb, unsigned offset, | ||
265 | unsigned dir) | ||
266 | { | ||
267 | struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; | ||
268 | int ret; | ||
269 | |||
270 | gbmsg->cmd = VPRBRD_GPIOB_CMD_SETDIR; | ||
271 | gbmsg->val = cpu_to_be16(dir << offset); | ||
272 | gbmsg->mask = cpu_to_be16(0x0001 << offset); | ||
273 | |||
274 | ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0), | ||
275 | VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_OUT, 0x0000, | ||
276 | 0x0000, gbmsg, sizeof(struct vprbrd_gpiob_msg), | ||
277 | VPRBRD_USB_TIMEOUT_MS); | ||
278 | |||
279 | if (ret != sizeof(struct vprbrd_gpiob_msg)) | ||
280 | return -EREMOTEIO; | ||
281 | |||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | static int vprbrd_gpiob_get(struct gpio_chip *chip, | ||
286 | unsigned offset) | ||
287 | { | ||
288 | int ret; | ||
289 | u16 val; | ||
290 | struct vprbrd_gpio *gpio = | ||
291 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
292 | struct vprbrd *vb = gpio->vb; | ||
293 | struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; | ||
294 | |||
295 | /* if io is set to output, just return the saved value */ | ||
296 | if (gpio->gpiob_out & (1 << offset)) | ||
297 | return gpio->gpiob_val & (1 << offset); | ||
298 | |||
299 | mutex_lock(&vb->lock); | ||
300 | |||
301 | ret = usb_control_msg(vb->usb_dev, usb_rcvctrlpipe(vb->usb_dev, 0), | ||
302 | VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_IN, 0x0000, | ||
303 | 0x0000, gbmsg, sizeof(struct vprbrd_gpiob_msg), | ||
304 | VPRBRD_USB_TIMEOUT_MS); | ||
305 | val = gbmsg->val; | ||
306 | |||
307 | mutex_unlock(&vb->lock); | ||
308 | |||
309 | if (ret != sizeof(struct vprbrd_gpiob_msg)) | ||
310 | return ret; | ||
311 | |||
312 | /* cache the read values */ | ||
313 | gpio->gpiob_val = be16_to_cpu(val); | ||
314 | |||
315 | return (gpio->gpiob_val >> offset) & 0x1; | ||
316 | } | ||
317 | |||
318 | static void vprbrd_gpiob_set(struct gpio_chip *chip, | ||
319 | unsigned offset, int value) | ||
320 | { | ||
321 | int ret; | ||
322 | struct vprbrd_gpio *gpio = | ||
323 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
324 | struct vprbrd *vb = gpio->vb; | ||
325 | struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf; | ||
326 | |||
327 | if (gpio->gpiob_out & (1 << offset)) { | ||
328 | if (value) | ||
329 | gpio->gpiob_val |= (1 << offset); | ||
330 | else | ||
331 | gpio->gpiob_val &= ~(1 << offset); | ||
332 | |||
333 | mutex_lock(&vb->lock); | ||
334 | |||
335 | gbmsg->cmd = VPRBRD_GPIOB_CMD_SETVAL; | ||
336 | gbmsg->val = cpu_to_be16(value << offset); | ||
337 | gbmsg->mask = cpu_to_be16(0x0001 << offset); | ||
338 | |||
339 | ret = usb_control_msg(vb->usb_dev, | ||
340 | usb_sndctrlpipe(vb->usb_dev, 0), | ||
341 | VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_OUT, | ||
342 | 0x0000, 0x0000, gbmsg, | ||
343 | sizeof(struct vprbrd_gpiob_msg), VPRBRD_USB_TIMEOUT_MS); | ||
344 | |||
345 | mutex_unlock(&vb->lock); | ||
346 | |||
347 | if (ret != sizeof(struct vprbrd_gpiob_msg)) | ||
348 | dev_err(chip->dev, "usb error setting pin value\n"); | ||
349 | } | ||
350 | } | ||
351 | |||
352 | static int vprbrd_gpiob_direction_input(struct gpio_chip *chip, | ||
353 | unsigned offset) | ||
354 | { | ||
355 | int ret; | ||
356 | struct vprbrd_gpio *gpio = | ||
357 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
358 | struct vprbrd *vb = gpio->vb; | ||
359 | |||
360 | gpio->gpiob_out &= ~(1 << offset); | ||
361 | |||
362 | mutex_lock(&vb->lock); | ||
363 | |||
364 | ret = vprbrd_gpiob_setdir(vb, offset, 0); | ||
365 | |||
366 | mutex_unlock(&vb->lock); | ||
367 | |||
368 | if (ret) | ||
369 | dev_err(chip->dev, "usb error setting pin to input\n"); | ||
370 | |||
371 | return ret; | ||
372 | } | ||
373 | |||
374 | static int vprbrd_gpiob_direction_output(struct gpio_chip *chip, | ||
375 | unsigned offset, int value) | ||
376 | { | ||
377 | int ret; | ||
378 | struct vprbrd_gpio *gpio = | ||
379 | container_of(chip, struct vprbrd_gpio, gpiob); | ||
380 | struct vprbrd *vb = gpio->vb; | ||
381 | |||
382 | gpio->gpiob_out |= (1 << offset); | ||
383 | if (value) | ||
384 | gpio->gpiob_val |= (1 << offset); | ||
385 | else | ||
386 | gpio->gpiob_val &= ~(1 << offset); | ||
387 | |||
388 | mutex_lock(&vb->lock); | ||
389 | |||
390 | ret = vprbrd_gpiob_setdir(vb, offset, 1); | ||
391 | if (ret) | ||
392 | dev_err(chip->dev, "usb error setting pin to output\n"); | ||
393 | |||
394 | mutex_unlock(&vb->lock); | ||
395 | |||
396 | vprbrd_gpiob_set(chip, offset, value); | ||
397 | |||
398 | return ret; | ||
399 | } | ||
400 | |||
401 | /* ----- end of gpio b chip ---------------------------------------------- */ | ||
402 | |||
403 | static int vprbrd_gpio_probe(struct platform_device *pdev) | ||
404 | { | ||
405 | struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent); | ||
406 | struct vprbrd_gpio *vb_gpio; | ||
407 | int ret; | ||
408 | |||
409 | vb_gpio = devm_kzalloc(&pdev->dev, sizeof(*vb_gpio), GFP_KERNEL); | ||
410 | if (vb_gpio == NULL) | ||
411 | return -ENOMEM; | ||
412 | |||
413 | vb_gpio->vb = vb; | ||
414 | /* registering gpio a */ | ||
415 | vb_gpio->gpioa.label = "viperboard gpio a"; | ||
416 | vb_gpio->gpioa.dev = &pdev->dev; | ||
417 | vb_gpio->gpioa.owner = THIS_MODULE; | ||
418 | vb_gpio->gpioa.base = -1; | ||
419 | vb_gpio->gpioa.ngpio = 16; | ||
420 | vb_gpio->gpioa.can_sleep = 1; | ||
421 | vb_gpio->gpioa.set = vprbrd_gpioa_set; | ||
422 | vb_gpio->gpioa.get = vprbrd_gpioa_get; | ||
423 | vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input; | ||
424 | vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output; | ||
425 | ret = gpiochip_add(&vb_gpio->gpioa); | ||
426 | if (ret < 0) { | ||
427 | dev_err(vb_gpio->gpioa.dev, "could not add gpio a"); | ||
428 | goto err_gpioa; | ||
429 | } | ||
430 | |||
431 | /* registering gpio b */ | ||
432 | vb_gpio->gpiob.label = "viperboard gpio b"; | ||
433 | vb_gpio->gpiob.dev = &pdev->dev; | ||
434 | vb_gpio->gpiob.owner = THIS_MODULE; | ||
435 | vb_gpio->gpiob.base = -1; | ||
436 | vb_gpio->gpiob.ngpio = 16; | ||
437 | vb_gpio->gpiob.can_sleep = 1; | ||
438 | vb_gpio->gpiob.set = vprbrd_gpiob_set; | ||
439 | vb_gpio->gpiob.get = vprbrd_gpiob_get; | ||
440 | vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input; | ||
441 | vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output; | ||
442 | ret = gpiochip_add(&vb_gpio->gpiob); | ||
443 | if (ret < 0) { | ||
444 | dev_err(vb_gpio->gpiob.dev, "could not add gpio b"); | ||
445 | goto err_gpiob; | ||
446 | } | ||
447 | |||
448 | platform_set_drvdata(pdev, vb_gpio); | ||
449 | |||
450 | return ret; | ||
451 | |||
452 | err_gpiob: | ||
453 | ret = gpiochip_remove(&vb_gpio->gpioa); | ||
454 | |||
455 | err_gpioa: | ||
456 | return ret; | ||
457 | } | ||
458 | |||
459 | static int vprbrd_gpio_remove(struct platform_device *pdev) | ||
460 | { | ||
461 | struct vprbrd_gpio *vb_gpio = platform_get_drvdata(pdev); | ||
462 | int ret; | ||
463 | |||
464 | ret = gpiochip_remove(&vb_gpio->gpiob); | ||
465 | if (ret == 0) | ||
466 | ret = gpiochip_remove(&vb_gpio->gpioa); | ||
467 | |||
468 | return ret; | ||
469 | } | ||
470 | |||
471 | static struct platform_driver vprbrd_gpio_driver = { | ||
472 | .driver.name = "viperboard-gpio", | ||
473 | .driver.owner = THIS_MODULE, | ||
474 | .probe = vprbrd_gpio_probe, | ||
475 | .remove = vprbrd_gpio_remove, | ||
476 | }; | ||
477 | |||
478 | static int __init vprbrd_gpio_init(void) | ||
479 | { | ||
480 | switch (gpioa_freq) { | ||
481 | case 1000000: | ||
482 | gpioa_clk = VPRBRD_GPIOA_CLK_1MHZ; | ||
483 | break; | ||
484 | case 100000: | ||
485 | gpioa_clk = VPRBRD_GPIOA_CLK_100KHZ; | ||
486 | break; | ||
487 | case 10000: | ||
488 | gpioa_clk = VPRBRD_GPIOA_CLK_10KHZ; | ||
489 | break; | ||
490 | case 1000: | ||
491 | gpioa_clk = VPRBRD_GPIOA_CLK_1KHZ; | ||
492 | break; | ||
493 | case 100: | ||
494 | gpioa_clk = VPRBRD_GPIOA_CLK_100HZ; | ||
495 | break; | ||
496 | case 10: | ||
497 | gpioa_clk = VPRBRD_GPIOA_CLK_10HZ; | ||
498 | break; | ||
499 | default: | ||
500 | pr_warn("invalid gpioa_freq (%d)\n", gpioa_freq); | ||
501 | gpioa_clk = VPRBRD_GPIOA_CLK_1KHZ; | ||
502 | } | ||
503 | |||
504 | return platform_driver_register(&vprbrd_gpio_driver); | ||
505 | } | ||
506 | subsys_initcall(vprbrd_gpio_init); | ||
507 | |||
508 | static void __exit vprbrd_gpio_exit(void) | ||
509 | { | ||
510 | platform_driver_unregister(&vprbrd_gpio_driver); | ||
511 | } | ||
512 | module_exit(vprbrd_gpio_exit); | ||
513 | |||
514 | MODULE_AUTHOR("Lars Poeschel <poeschel@lemonage.de>"); | ||
515 | MODULE_DESCRIPTION("GPIO driver for Nano River Techs Viperboard"); | ||
516 | MODULE_LICENSE("GPL"); | ||
517 | MODULE_ALIAS("platform:viperboard-gpio"); | ||
diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c index 9902732a382..98723cb9ac6 100644 --- a/drivers/gpio/gpio-vr41xx.c +++ b/drivers/gpio/gpio-vr41xx.c | |||
@@ -490,7 +490,7 @@ static struct gpio_chip vr41xx_gpio_chip = { | |||
490 | .to_irq = vr41xx_gpio_to_irq, | 490 | .to_irq = vr41xx_gpio_to_irq, |
491 | }; | 491 | }; |
492 | 492 | ||
493 | static int giu_probe(struct platform_device *pdev) | 493 | static int __devinit giu_probe(struct platform_device *pdev) |
494 | { | 494 | { |
495 | struct resource *res; | 495 | struct resource *res; |
496 | unsigned int trigger, i, pin; | 496 | unsigned int trigger, i, pin; |
@@ -552,7 +552,7 @@ static int giu_probe(struct platform_device *pdev) | |||
552 | return cascade_irq(irq, giu_get_irq); | 552 | return cascade_irq(irq, giu_get_irq); |
553 | } | 553 | } |
554 | 554 | ||
555 | static int giu_remove(struct platform_device *pdev) | 555 | static int __devexit giu_remove(struct platform_device *pdev) |
556 | { | 556 | { |
557 | if (giu_base) { | 557 | if (giu_base) { |
558 | iounmap(giu_base); | 558 | iounmap(giu_base); |
@@ -564,11 +564,22 @@ static int giu_remove(struct platform_device *pdev) | |||
564 | 564 | ||
565 | static struct platform_driver giu_device_driver = { | 565 | static struct platform_driver giu_device_driver = { |
566 | .probe = giu_probe, | 566 | .probe = giu_probe, |
567 | .remove = giu_remove, | 567 | .remove = __devexit_p(giu_remove), |
568 | .driver = { | 568 | .driver = { |
569 | .name = "GIU", | 569 | .name = "GIU", |
570 | .owner = THIS_MODULE, | 570 | .owner = THIS_MODULE, |
571 | }, | 571 | }, |
572 | }; | 572 | }; |
573 | 573 | ||
574 | module_platform_driver(giu_device_driver); | 574 | static int __init vr41xx_giu_init(void) |
575 | { | ||
576 | return platform_driver_register(&giu_device_driver); | ||
577 | } | ||
578 | |||
579 | static void __exit vr41xx_giu_exit(void) | ||
580 | { | ||
581 | platform_driver_unregister(&giu_device_driver); | ||
582 | } | ||
583 | |||
584 | module_init(vr41xx_giu_init); | ||
585 | module_exit(vr41xx_giu_exit); | ||
diff --git a/drivers/gpio/gpio-vt8500.c b/drivers/gpio/gpio-vt8500.c deleted file mode 100644 index b53320a16fc..00000000000 --- a/drivers/gpio/gpio-vt8500.c +++ /dev/null | |||
@@ -1,318 +0,0 @@ | |||
1 | /* drivers/gpio/gpio-vt8500.c | ||
2 | * | ||
3 | * Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz> | ||
4 | * Based on arch/arm/mach-vt8500/gpio.c: | ||
5 | * - Copyright (C) 2010 Alexey Charkov <alchark@gmail.com> | ||
6 | * | ||
7 | * This software is licensed under the terms of the GNU General Public | ||
8 | * License version 2, as published by the Free Software Foundation, and | ||
9 | * may be copied, distributed, and modified under those terms. | ||
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 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/io.h> | ||
21 | #include <linux/gpio.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/bitops.h> | ||
24 | #include <linux/of.h> | ||
25 | #include <linux/of_address.h> | ||
26 | #include <linux/of_irq.h> | ||
27 | #include <linux/of_device.h> | ||
28 | |||
29 | /* | ||
30 | We handle GPIOs by bank, each bank containing up to 32 GPIOs covered | ||
31 | by one set of registers (although not all may be valid). | ||
32 | |||
33 | Because different SoC's have different register offsets, we pass the | ||
34 | register offsets as data in vt8500_gpio_dt_ids[]. | ||
35 | |||
36 | A value of NO_REG is used to indicate that this register is not | ||
37 | supported. Only used for ->en at the moment. | ||
38 | */ | ||
39 | |||
40 | #define NO_REG 0xFFFF | ||
41 | |||
42 | /* | ||
43 | * struct vt8500_gpio_bank_regoffsets | ||
44 | * @en: offset to enable register of the bank | ||
45 | * @dir: offset to direction register of the bank | ||
46 | * @data_out: offset to the data out register of the bank | ||
47 | * @data_in: offset to the data in register of the bank | ||
48 | * @ngpio: highest valid pin in this bank | ||
49 | */ | ||
50 | |||
51 | struct vt8500_gpio_bank_regoffsets { | ||
52 | unsigned int en; | ||
53 | unsigned int dir; | ||
54 | unsigned int data_out; | ||
55 | unsigned int data_in; | ||
56 | unsigned char ngpio; | ||
57 | }; | ||
58 | |||
59 | struct vt8500_gpio_data { | ||
60 | unsigned int num_banks; | ||
61 | struct vt8500_gpio_bank_regoffsets banks[]; | ||
62 | }; | ||
63 | |||
64 | #define VT8500_BANK(__en, __dir, __out, __in, __ngpio) \ | ||
65 | { \ | ||
66 | .en = __en, \ | ||
67 | .dir = __dir, \ | ||
68 | .data_out = __out, \ | ||
69 | .data_in = __in, \ | ||
70 | .ngpio = __ngpio, \ | ||
71 | } | ||
72 | |||
73 | static struct vt8500_gpio_data vt8500_data = { | ||
74 | .num_banks = 7, | ||
75 | .banks = { | ||
76 | VT8500_BANK(0x00, 0x20, 0x40, 0x60, 26), | ||
77 | VT8500_BANK(0x04, 0x24, 0x44, 0x64, 28), | ||
78 | VT8500_BANK(0x08, 0x28, 0x48, 0x68, 31), | ||
79 | VT8500_BANK(0x0C, 0x2C, 0x4C, 0x6C, 19), | ||
80 | VT8500_BANK(0x10, 0x30, 0x50, 0x70, 19), | ||
81 | VT8500_BANK(0x14, 0x34, 0x54, 0x74, 23), | ||
82 | VT8500_BANK(NO_REG, 0x3C, 0x5C, 0x7C, 9), | ||
83 | }, | ||
84 | }; | ||
85 | |||
86 | static struct vt8500_gpio_data wm8505_data = { | ||
87 | .num_banks = 10, | ||
88 | .banks = { | ||
89 | VT8500_BANK(0x40, 0x68, 0x90, 0xB8, 8), | ||
90 | VT8500_BANK(0x44, 0x6C, 0x94, 0xBC, 32), | ||
91 | VT8500_BANK(0x48, 0x70, 0x98, 0xC0, 6), | ||
92 | VT8500_BANK(0x4C, 0x74, 0x9C, 0xC4, 16), | ||
93 | VT8500_BANK(0x50, 0x78, 0xA0, 0xC8, 25), | ||
94 | VT8500_BANK(0x54, 0x7C, 0xA4, 0xCC, 5), | ||
95 | VT8500_BANK(0x58, 0x80, 0xA8, 0xD0, 5), | ||
96 | VT8500_BANK(0x5C, 0x84, 0xAC, 0xD4, 12), | ||
97 | VT8500_BANK(0x60, 0x88, 0xB0, 0xD8, 16), | ||
98 | VT8500_BANK(0x64, 0x8C, 0xB4, 0xDC, 22), | ||
99 | VT8500_BANK(0x500, 0x504, 0x508, 0x50C, 6), | ||
100 | }, | ||
101 | }; | ||
102 | |||
103 | /* | ||
104 | * No information about which bits are valid so we just make | ||
105 | * them all available until its figured out. | ||
106 | */ | ||
107 | static struct vt8500_gpio_data wm8650_data = { | ||
108 | .num_banks = 9, | ||
109 | .banks = { | ||
110 | VT8500_BANK(0x40, 0x80, 0xC0, 0x00, 32), | ||
111 | VT8500_BANK(0x44, 0x84, 0xC4, 0x04, 32), | ||
112 | VT8500_BANK(0x48, 0x88, 0xC8, 0x08, 32), | ||
113 | VT8500_BANK(0x4C, 0x8C, 0xCC, 0x0C, 32), | ||
114 | VT8500_BANK(0x50, 0x90, 0xD0, 0x10, 32), | ||
115 | VT8500_BANK(0x54, 0x94, 0xD4, 0x14, 32), | ||
116 | VT8500_BANK(0x58, 0x98, 0xD8, 0x18, 32), | ||
117 | VT8500_BANK(0x5C, 0x9C, 0xDC, 0x1C, 32), | ||
118 | VT8500_BANK(0x7C, 0xBC, 0xFC, 0x3C, 32), | ||
119 | VT8500_BANK(0x500, 0x504, 0x508, 0x50C, 6), | ||
120 | }, | ||
121 | }; | ||
122 | |||
123 | struct vt8500_gpio_chip { | ||
124 | struct gpio_chip chip; | ||
125 | |||
126 | const struct vt8500_gpio_bank_regoffsets *regs; | ||
127 | void __iomem *base; | ||
128 | }; | ||
129 | |||
130 | |||
131 | #define to_vt8500(__chip) container_of(__chip, struct vt8500_gpio_chip, chip) | ||
132 | |||
133 | static int vt8500_gpio_request(struct gpio_chip *chip, unsigned offset) | ||
134 | { | ||
135 | u32 val; | ||
136 | struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip); | ||
137 | |||
138 | if (vt8500_chip->regs->en == NO_REG) | ||
139 | return 0; | ||
140 | |||
141 | val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->en); | ||
142 | val |= BIT(offset); | ||
143 | writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->en); | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static void vt8500_gpio_free(struct gpio_chip *chip, unsigned offset) | ||
149 | { | ||
150 | struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip); | ||
151 | u32 val; | ||
152 | |||
153 | if (vt8500_chip->regs->en == NO_REG) | ||
154 | return; | ||
155 | |||
156 | val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->en); | ||
157 | val &= ~BIT(offset); | ||
158 | writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->en); | ||
159 | } | ||
160 | |||
161 | static int vt8500_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
162 | { | ||
163 | struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip); | ||
164 | |||
165 | u32 val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->dir); | ||
166 | val &= ~BIT(offset); | ||
167 | writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->dir); | ||
168 | |||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | static int vt8500_gpio_direction_output(struct gpio_chip *chip, unsigned offset, | ||
173 | int value) | ||
174 | { | ||
175 | struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip); | ||
176 | |||
177 | u32 val = readl_relaxed(vt8500_chip->base + vt8500_chip->regs->dir); | ||
178 | val |= BIT(offset); | ||
179 | writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->dir); | ||
180 | |||
181 | if (value) { | ||
182 | val = readl_relaxed(vt8500_chip->base + | ||
183 | vt8500_chip->regs->data_out); | ||
184 | val |= BIT(offset); | ||
185 | writel_relaxed(val, vt8500_chip->base + | ||
186 | vt8500_chip->regs->data_out); | ||
187 | } | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static int vt8500_gpio_get_value(struct gpio_chip *chip, unsigned offset) | ||
192 | { | ||
193 | struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip); | ||
194 | |||
195 | return (readl_relaxed(vt8500_chip->base + vt8500_chip->regs->data_in) >> | ||
196 | offset) & 1; | ||
197 | } | ||
198 | |||
199 | static void vt8500_gpio_set_value(struct gpio_chip *chip, unsigned offset, | ||
200 | int value) | ||
201 | { | ||
202 | struct vt8500_gpio_chip *vt8500_chip = to_vt8500(chip); | ||
203 | |||
204 | u32 val = readl_relaxed(vt8500_chip->base + | ||
205 | vt8500_chip->regs->data_out); | ||
206 | if (value) | ||
207 | val |= BIT(offset); | ||
208 | else | ||
209 | val &= ~BIT(offset); | ||
210 | |||
211 | writel_relaxed(val, vt8500_chip->base + vt8500_chip->regs->data_out); | ||
212 | } | ||
213 | |||
214 | static int vt8500_of_xlate(struct gpio_chip *gc, | ||
215 | const struct of_phandle_args *gpiospec, u32 *flags) | ||
216 | { | ||
217 | /* bank if specificed in gpiospec->args[0] */ | ||
218 | if (flags) | ||
219 | *flags = gpiospec->args[2]; | ||
220 | |||
221 | return gpiospec->args[1]; | ||
222 | } | ||
223 | |||
224 | static int vt8500_add_chips(struct platform_device *pdev, void __iomem *base, | ||
225 | const struct vt8500_gpio_data *data) | ||
226 | { | ||
227 | struct vt8500_gpio_chip *vtchip; | ||
228 | struct gpio_chip *chip; | ||
229 | int i; | ||
230 | int pin_cnt = 0; | ||
231 | |||
232 | vtchip = devm_kzalloc(&pdev->dev, | ||
233 | sizeof(struct vt8500_gpio_chip) * data->num_banks, | ||
234 | GFP_KERNEL); | ||
235 | if (!vtchip) { | ||
236 | pr_err("%s: failed to allocate chip memory\n", __func__); | ||
237 | return -ENOMEM; | ||
238 | } | ||
239 | |||
240 | for (i = 0; i < data->num_banks; i++) { | ||
241 | vtchip[i].base = base; | ||
242 | vtchip[i].regs = &data->banks[i]; | ||
243 | |||
244 | chip = &vtchip[i].chip; | ||
245 | |||
246 | chip->of_xlate = vt8500_of_xlate; | ||
247 | chip->of_gpio_n_cells = 3; | ||
248 | chip->of_node = pdev->dev.of_node; | ||
249 | |||
250 | chip->request = vt8500_gpio_request; | ||
251 | chip->free = vt8500_gpio_free; | ||
252 | chip->direction_input = vt8500_gpio_direction_input; | ||
253 | chip->direction_output = vt8500_gpio_direction_output; | ||
254 | chip->get = vt8500_gpio_get_value; | ||
255 | chip->set = vt8500_gpio_set_value; | ||
256 | chip->can_sleep = 0; | ||
257 | chip->base = pin_cnt; | ||
258 | chip->ngpio = data->banks[i].ngpio; | ||
259 | |||
260 | pin_cnt += data->banks[i].ngpio; | ||
261 | |||
262 | gpiochip_add(chip); | ||
263 | } | ||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | static struct of_device_id vt8500_gpio_dt_ids[] = { | ||
268 | { .compatible = "via,vt8500-gpio", .data = &vt8500_data, }, | ||
269 | { .compatible = "wm,wm8505-gpio", .data = &wm8505_data, }, | ||
270 | { .compatible = "wm,wm8650-gpio", .data = &wm8650_data, }, | ||
271 | { /* Sentinel */ }, | ||
272 | }; | ||
273 | |||
274 | static int vt8500_gpio_probe(struct platform_device *pdev) | ||
275 | { | ||
276 | void __iomem *gpio_base; | ||
277 | struct device_node *np; | ||
278 | const struct of_device_id *of_id = | ||
279 | of_match_device(vt8500_gpio_dt_ids, &pdev->dev); | ||
280 | |||
281 | if (!of_id) { | ||
282 | dev_err(&pdev->dev, "Failed to find gpio controller\n"); | ||
283 | return -ENODEV; | ||
284 | } | ||
285 | |||
286 | np = pdev->dev.of_node; | ||
287 | if (!np) { | ||
288 | dev_err(&pdev->dev, "Missing GPIO description in devicetree\n"); | ||
289 | return -EFAULT; | ||
290 | } | ||
291 | |||
292 | gpio_base = of_iomap(np, 0); | ||
293 | if (!gpio_base) { | ||
294 | dev_err(&pdev->dev, "Unable to map GPIO registers\n"); | ||
295 | of_node_put(np); | ||
296 | return -ENOMEM; | ||
297 | } | ||
298 | |||
299 | vt8500_add_chips(pdev, gpio_base, of_id->data); | ||
300 | |||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | static struct platform_driver vt8500_gpio_driver = { | ||
305 | .probe = vt8500_gpio_probe, | ||
306 | .driver = { | ||
307 | .name = "vt8500-gpio", | ||
308 | .owner = THIS_MODULE, | ||
309 | .of_match_table = vt8500_gpio_dt_ids, | ||
310 | }, | ||
311 | }; | ||
312 | |||
313 | module_platform_driver(vt8500_gpio_driver); | ||
314 | |||
315 | MODULE_DESCRIPTION("VT8500 GPIO Driver"); | ||
316 | MODULE_AUTHOR("Tony Prisk <linux@prisktech.co.nz>"); | ||
317 | MODULE_LICENSE("GPL v2"); | ||
318 | MODULE_DEVICE_TABLE(of, vt8500_gpio_dt_ids); | ||
diff --git a/drivers/gpio/gpio-vx855.c b/drivers/gpio/gpio-vx855.c index 2b7252cb242..ef5aabd8b8b 100644 --- a/drivers/gpio/gpio-vx855.c +++ b/drivers/gpio/gpio-vx855.c | |||
@@ -219,7 +219,7 @@ static void vx855gpio_gpio_setup(struct vx855_gpio *vg) | |||
219 | } | 219 | } |
220 | 220 | ||
221 | /* This platform device is ordinarily registered by the vx855 mfd driver */ | 221 | /* This platform device is ordinarily registered by the vx855 mfd driver */ |
222 | static int vx855gpio_probe(struct platform_device *pdev) | 222 | static __devinit int vx855gpio_probe(struct platform_device *pdev) |
223 | { | 223 | { |
224 | struct resource *res_gpi; | 224 | struct resource *res_gpi; |
225 | struct resource *res_gpo; | 225 | struct resource *res_gpo; |
@@ -284,7 +284,7 @@ out_release: | |||
284 | return ret; | 284 | return ret; |
285 | } | 285 | } |
286 | 286 | ||
287 | static int vx855gpio_remove(struct platform_device *pdev) | 287 | static int __devexit vx855gpio_remove(struct platform_device *pdev) |
288 | { | 288 | { |
289 | struct vx855_gpio *vg = platform_get_drvdata(pdev); | 289 | struct vx855_gpio *vg = platform_get_drvdata(pdev); |
290 | struct resource *res; | 290 | struct resource *res; |
@@ -312,10 +312,20 @@ static struct platform_driver vx855gpio_driver = { | |||
312 | .owner = THIS_MODULE, | 312 | .owner = THIS_MODULE, |
313 | }, | 313 | }, |
314 | .probe = vx855gpio_probe, | 314 | .probe = vx855gpio_probe, |
315 | .remove = vx855gpio_remove, | 315 | .remove = __devexit_p(vx855gpio_remove), |
316 | }; | 316 | }; |
317 | 317 | ||
318 | module_platform_driver(vx855gpio_driver); | 318 | static int vx855gpio_init(void) |
319 | { | ||
320 | return platform_driver_register(&vx855gpio_driver); | ||
321 | } | ||
322 | module_init(vx855gpio_init); | ||
323 | |||
324 | static void vx855gpio_exit(void) | ||
325 | { | ||
326 | platform_driver_unregister(&vx855gpio_driver); | ||
327 | } | ||
328 | module_exit(vx855gpio_exit); | ||
319 | 329 | ||
320 | MODULE_LICENSE("GPL"); | 330 | MODULE_LICENSE("GPL"); |
321 | MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>"); | 331 | MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>"); |
diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c index 2a743e10ecb..deb949e75ec 100644 --- a/drivers/gpio/gpio-wm831x.c +++ b/drivers/gpio/gpio-wm831x.c | |||
@@ -102,8 +102,10 @@ 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 | return irq_create_mapping(wm831x->irq_domain, | 105 | if (!wm831x->irq_base) |
106 | WM831X_IRQ_GPIO_1 + offset); | 106 | return -EINVAL; |
107 | |||
108 | return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset; | ||
107 | } | 109 | } |
108 | 110 | ||
109 | static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, | 111 | static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, |
@@ -243,15 +245,14 @@ static struct gpio_chip template_chip = { | |||
243 | .can_sleep = 1, | 245 | .can_sleep = 1, |
244 | }; | 246 | }; |
245 | 247 | ||
246 | static int wm831x_gpio_probe(struct platform_device *pdev) | 248 | static int __devinit wm831x_gpio_probe(struct platform_device *pdev) |
247 | { | 249 | { |
248 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 250 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
249 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 251 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
250 | struct wm831x_gpio *wm831x_gpio; | 252 | struct wm831x_gpio *wm831x_gpio; |
251 | int ret; | 253 | int ret; |
252 | 254 | ||
253 | wm831x_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm831x_gpio), | 255 | wm831x_gpio = kzalloc(sizeof(*wm831x_gpio), GFP_KERNEL); |
254 | GFP_KERNEL); | ||
255 | if (wm831x_gpio == NULL) | 256 | if (wm831x_gpio == NULL) |
256 | return -ENOMEM; | 257 | return -ENOMEM; |
257 | 258 | ||
@@ -266,27 +267,37 @@ static int wm831x_gpio_probe(struct platform_device *pdev) | |||
266 | 267 | ||
267 | ret = gpiochip_add(&wm831x_gpio->gpio_chip); | 268 | ret = gpiochip_add(&wm831x_gpio->gpio_chip); |
268 | if (ret < 0) { | 269 | if (ret < 0) { |
269 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | 270 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", |
270 | return ret; | 271 | ret); |
272 | goto err; | ||
271 | } | 273 | } |
272 | 274 | ||
273 | platform_set_drvdata(pdev, wm831x_gpio); | 275 | platform_set_drvdata(pdev, wm831x_gpio); |
274 | 276 | ||
275 | return ret; | 277 | return ret; |
278 | |||
279 | err: | ||
280 | kfree(wm831x_gpio); | ||
281 | return ret; | ||
276 | } | 282 | } |
277 | 283 | ||
278 | static int wm831x_gpio_remove(struct platform_device *pdev) | 284 | static int __devexit wm831x_gpio_remove(struct platform_device *pdev) |
279 | { | 285 | { |
280 | struct wm831x_gpio *wm831x_gpio = platform_get_drvdata(pdev); | 286 | struct wm831x_gpio *wm831x_gpio = platform_get_drvdata(pdev); |
287 | int ret; | ||
281 | 288 | ||
282 | return gpiochip_remove(&wm831x_gpio->gpio_chip); | 289 | ret = gpiochip_remove(&wm831x_gpio->gpio_chip); |
290 | if (ret == 0) | ||
291 | kfree(wm831x_gpio); | ||
292 | |||
293 | return ret; | ||
283 | } | 294 | } |
284 | 295 | ||
285 | static struct platform_driver wm831x_gpio_driver = { | 296 | static struct platform_driver wm831x_gpio_driver = { |
286 | .driver.name = "wm831x-gpio", | 297 | .driver.name = "wm831x-gpio", |
287 | .driver.owner = THIS_MODULE, | 298 | .driver.owner = THIS_MODULE, |
288 | .probe = wm831x_gpio_probe, | 299 | .probe = wm831x_gpio_probe, |
289 | .remove = wm831x_gpio_remove, | 300 | .remove = __devexit_p(wm831x_gpio_remove), |
290 | }; | 301 | }; |
291 | 302 | ||
292 | static int __init wm831x_gpio_init(void) | 303 | static int __init wm831x_gpio_init(void) |
diff --git a/drivers/gpio/gpio-wm8350.c b/drivers/gpio/gpio-wm8350.c index 0b598cf3df9..a06af515483 100644 --- a/drivers/gpio/gpio-wm8350.c +++ b/drivers/gpio/gpio-wm8350.c | |||
@@ -109,15 +109,14 @@ static struct gpio_chip template_chip = { | |||
109 | .can_sleep = 1, | 109 | .can_sleep = 1, |
110 | }; | 110 | }; |
111 | 111 | ||
112 | static int wm8350_gpio_probe(struct platform_device *pdev) | 112 | static int __devinit wm8350_gpio_probe(struct platform_device *pdev) |
113 | { | 113 | { |
114 | struct wm8350 *wm8350 = dev_get_drvdata(pdev->dev.parent); | 114 | struct wm8350 *wm8350 = dev_get_drvdata(pdev->dev.parent); |
115 | struct wm8350_platform_data *pdata = wm8350->dev->platform_data; | 115 | struct wm8350_platform_data *pdata = wm8350->dev->platform_data; |
116 | struct wm8350_gpio_data *wm8350_gpio; | 116 | struct wm8350_gpio_data *wm8350_gpio; |
117 | int ret; | 117 | int ret; |
118 | 118 | ||
119 | wm8350_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8350_gpio), | 119 | wm8350_gpio = kzalloc(sizeof(*wm8350_gpio), GFP_KERNEL); |
120 | GFP_KERNEL); | ||
121 | if (wm8350_gpio == NULL) | 120 | if (wm8350_gpio == NULL) |
122 | return -ENOMEM; | 121 | return -ENOMEM; |
123 | 122 | ||
@@ -132,27 +131,37 @@ static int wm8350_gpio_probe(struct platform_device *pdev) | |||
132 | 131 | ||
133 | ret = gpiochip_add(&wm8350_gpio->gpio_chip); | 132 | ret = gpiochip_add(&wm8350_gpio->gpio_chip); |
134 | if (ret < 0) { | 133 | if (ret < 0) { |
135 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | 134 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", |
136 | return ret; | 135 | ret); |
136 | goto err; | ||
137 | } | 137 | } |
138 | 138 | ||
139 | platform_set_drvdata(pdev, wm8350_gpio); | 139 | platform_set_drvdata(pdev, wm8350_gpio); |
140 | 140 | ||
141 | return ret; | 141 | return ret; |
142 | |||
143 | err: | ||
144 | kfree(wm8350_gpio); | ||
145 | return ret; | ||
142 | } | 146 | } |
143 | 147 | ||
144 | static int wm8350_gpio_remove(struct platform_device *pdev) | 148 | static int __devexit wm8350_gpio_remove(struct platform_device *pdev) |
145 | { | 149 | { |
146 | struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev); | 150 | struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev); |
151 | int ret; | ||
152 | |||
153 | ret = gpiochip_remove(&wm8350_gpio->gpio_chip); | ||
154 | if (ret == 0) | ||
155 | kfree(wm8350_gpio); | ||
147 | 156 | ||
148 | return gpiochip_remove(&wm8350_gpio->gpio_chip); | 157 | return ret; |
149 | } | 158 | } |
150 | 159 | ||
151 | static struct platform_driver wm8350_gpio_driver = { | 160 | static struct platform_driver wm8350_gpio_driver = { |
152 | .driver.name = "wm8350-gpio", | 161 | .driver.name = "wm8350-gpio", |
153 | .driver.owner = THIS_MODULE, | 162 | .driver.owner = THIS_MODULE, |
154 | .probe = wm8350_gpio_probe, | 163 | .probe = wm8350_gpio_probe, |
155 | .remove = wm8350_gpio_remove, | 164 | .remove = __devexit_p(wm8350_gpio_remove), |
156 | }; | 165 | }; |
157 | 166 | ||
158 | static int __init wm8350_gpio_init(void) | 167 | static int __init wm8350_gpio_init(void) |
diff --git a/drivers/gpio/gpio-wm8994.c b/drivers/gpio/gpio-wm8994.c index ae409fd94af..96198f3fab7 100644 --- a/drivers/gpio/gpio-wm8994.c +++ b/drivers/gpio/gpio-wm8994.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/mfd/core.h> | 19 | #include <linux/mfd/core.h> |
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/seq_file.h> | 21 | #include <linux/seq_file.h> |
22 | #include <linux/regmap.h> | ||
23 | 22 | ||
24 | #include <linux/mfd/wm8994/core.h> | 23 | #include <linux/mfd/wm8994/core.h> |
25 | #include <linux/mfd/wm8994/pdata.h> | 24 | #include <linux/mfd/wm8994/pdata.h> |
@@ -90,11 +89,8 @@ static int wm8994_gpio_direction_out(struct gpio_chip *chip, | |||
90 | struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); | 89 | struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); |
91 | struct wm8994 *wm8994 = wm8994_gpio->wm8994; | 90 | struct wm8994 *wm8994 = wm8994_gpio->wm8994; |
92 | 91 | ||
93 | if (value) | ||
94 | value = WM8994_GPN_LVL; | ||
95 | |||
96 | return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, | 92 | return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, |
97 | WM8994_GPN_DIR | WM8994_GPN_LVL, value); | 93 | WM8994_GPN_DIR, 0); |
98 | } | 94 | } |
99 | 95 | ||
100 | static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 96 | static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
@@ -113,65 +109,14 @@ static int wm8994_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | |||
113 | struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); | 109 | struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); |
114 | struct wm8994 *wm8994 = wm8994_gpio->wm8994; | 110 | struct wm8994 *wm8994 = wm8994_gpio->wm8994; |
115 | 111 | ||
116 | return regmap_irq_get_virq(wm8994->irq_data, offset); | 112 | if (!wm8994->irq_base) |
113 | return -EINVAL; | ||
114 | |||
115 | return wm8994->irq_base + offset; | ||
117 | } | 116 | } |
118 | 117 | ||
119 | 118 | ||
120 | #ifdef CONFIG_DEBUG_FS | 119 | #ifdef CONFIG_DEBUG_FS |
121 | static const char *wm8994_gpio_fn(u16 fn) | ||
122 | { | ||
123 | switch (fn) { | ||
124 | case WM8994_GP_FN_PIN_SPECIFIC: | ||
125 | return "pin-specific"; | ||
126 | case WM8994_GP_FN_GPIO: | ||
127 | return "GPIO"; | ||
128 | case WM8994_GP_FN_SDOUT: | ||
129 | return "SDOUT"; | ||
130 | case WM8994_GP_FN_IRQ: | ||
131 | return "IRQ"; | ||
132 | case WM8994_GP_FN_TEMPERATURE: | ||
133 | return "Temperature"; | ||
134 | case WM8994_GP_FN_MICBIAS1_DET: | ||
135 | return "MICBIAS1 detect"; | ||
136 | case WM8994_GP_FN_MICBIAS1_SHORT: | ||
137 | return "MICBIAS1 short"; | ||
138 | case WM8994_GP_FN_MICBIAS2_DET: | ||
139 | return "MICBIAS2 detect"; | ||
140 | case WM8994_GP_FN_MICBIAS2_SHORT: | ||
141 | return "MICBIAS2 short"; | ||
142 | case WM8994_GP_FN_FLL1_LOCK: | ||
143 | return "FLL1 lock"; | ||
144 | case WM8994_GP_FN_FLL2_LOCK: | ||
145 | return "FLL2 lock"; | ||
146 | case WM8994_GP_FN_SRC1_LOCK: | ||
147 | return "SRC1 lock"; | ||
148 | case WM8994_GP_FN_SRC2_LOCK: | ||
149 | return "SRC2 lock"; | ||
150 | case WM8994_GP_FN_DRC1_ACT: | ||
151 | return "DRC1 activity"; | ||
152 | case WM8994_GP_FN_DRC2_ACT: | ||
153 | return "DRC2 activity"; | ||
154 | case WM8994_GP_FN_DRC3_ACT: | ||
155 | return "DRC3 activity"; | ||
156 | case WM8994_GP_FN_WSEQ_STATUS: | ||
157 | return "Write sequencer"; | ||
158 | case WM8994_GP_FN_FIFO_ERROR: | ||
159 | return "FIFO error"; | ||
160 | case WM8994_GP_FN_OPCLK: | ||
161 | return "OPCLK"; | ||
162 | case WM8994_GP_FN_THW: | ||
163 | return "Thermal warning"; | ||
164 | case WM8994_GP_FN_DCS_DONE: | ||
165 | return "DC servo"; | ||
166 | case WM8994_GP_FN_FLL1_OUT: | ||
167 | return "FLL1 output"; | ||
168 | case WM8994_GP_FN_FLL2_OUT: | ||
169 | return "FLL1 output"; | ||
170 | default: | ||
171 | return "Unknown"; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) | 120 | static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
176 | { | 121 | { |
177 | struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); | 122 | struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip); |
@@ -203,29 +148,8 @@ static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) | |||
203 | continue; | 148 | continue; |
204 | } | 149 | } |
205 | 150 | ||
206 | if (reg & WM8994_GPN_DIR) | 151 | /* No decode yet; note that GPIO2 is special */ |
207 | seq_printf(s, "in "); | 152 | seq_printf(s, "(%x)\n", reg); |
208 | else | ||
209 | seq_printf(s, "out "); | ||
210 | |||
211 | if (reg & WM8994_GPN_PU) | ||
212 | seq_printf(s, "pull up "); | ||
213 | |||
214 | if (reg & WM8994_GPN_PD) | ||
215 | seq_printf(s, "pull down "); | ||
216 | |||
217 | if (reg & WM8994_GPN_POL) | ||
218 | seq_printf(s, "inverted "); | ||
219 | else | ||
220 | seq_printf(s, "noninverted "); | ||
221 | |||
222 | if (reg & WM8994_GPN_OP_CFG) | ||
223 | seq_printf(s, "open drain "); | ||
224 | else | ||
225 | seq_printf(s, "CMOS "); | ||
226 | |||
227 | seq_printf(s, "%s (%x)\n", | ||
228 | wm8994_gpio_fn(reg & WM8994_GPN_FN_MASK), reg); | ||
229 | } | 153 | } |
230 | } | 154 | } |
231 | #else | 155 | #else |
@@ -245,15 +169,14 @@ static struct gpio_chip template_chip = { | |||
245 | .can_sleep = 1, | 169 | .can_sleep = 1, |
246 | }; | 170 | }; |
247 | 171 | ||
248 | static int wm8994_gpio_probe(struct platform_device *pdev) | 172 | static int __devinit wm8994_gpio_probe(struct platform_device *pdev) |
249 | { | 173 | { |
250 | struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent); | 174 | struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent); |
251 | struct wm8994_pdata *pdata = wm8994->dev->platform_data; | 175 | struct wm8994_pdata *pdata = wm8994->dev->platform_data; |
252 | struct wm8994_gpio *wm8994_gpio; | 176 | struct wm8994_gpio *wm8994_gpio; |
253 | int ret; | 177 | int ret; |
254 | 178 | ||
255 | wm8994_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8994_gpio), | 179 | wm8994_gpio = kzalloc(sizeof(*wm8994_gpio), GFP_KERNEL); |
256 | GFP_KERNEL); | ||
257 | if (wm8994_gpio == NULL) | 180 | if (wm8994_gpio == NULL) |
258 | return -ENOMEM; | 181 | return -ENOMEM; |
259 | 182 | ||
@@ -278,21 +201,27 @@ static int wm8994_gpio_probe(struct platform_device *pdev) | |||
278 | return ret; | 201 | return ret; |
279 | 202 | ||
280 | err: | 203 | err: |
204 | kfree(wm8994_gpio); | ||
281 | return ret; | 205 | return ret; |
282 | } | 206 | } |
283 | 207 | ||
284 | static int wm8994_gpio_remove(struct platform_device *pdev) | 208 | static int __devexit wm8994_gpio_remove(struct platform_device *pdev) |
285 | { | 209 | { |
286 | struct wm8994_gpio *wm8994_gpio = platform_get_drvdata(pdev); | 210 | struct wm8994_gpio *wm8994_gpio = platform_get_drvdata(pdev); |
211 | int ret; | ||
287 | 212 | ||
288 | return gpiochip_remove(&wm8994_gpio->gpio_chip); | 213 | ret = gpiochip_remove(&wm8994_gpio->gpio_chip); |
214 | if (ret == 0) | ||
215 | kfree(wm8994_gpio); | ||
216 | |||
217 | return ret; | ||
289 | } | 218 | } |
290 | 219 | ||
291 | static struct platform_driver wm8994_gpio_driver = { | 220 | static struct platform_driver wm8994_gpio_driver = { |
292 | .driver.name = "wm8994-gpio", | 221 | .driver.name = "wm8994-gpio", |
293 | .driver.owner = THIS_MODULE, | 222 | .driver.owner = THIS_MODULE, |
294 | .probe = wm8994_gpio_probe, | 223 | .probe = wm8994_gpio_probe, |
295 | .remove = wm8994_gpio_remove, | 224 | .remove = __devexit_p(wm8994_gpio_remove), |
296 | }; | 225 | }; |
297 | 226 | ||
298 | static int __init wm8994_gpio_init(void) | 227 | static int __init wm8994_gpio_init(void) |
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 9ae7aa8ca48..846fbd5e31b 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c | |||
@@ -14,7 +14,6 @@ | |||
14 | 14 | ||
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
17 | #include <linux/module.h> | ||
18 | #include <linux/of_device.h> | 17 | #include <linux/of_device.h> |
19 | #include <linux/of_platform.h> | 18 | #include <linux/of_platform.h> |
20 | #include <linux/of_gpio.h> | 19 | #include <linux/of_gpio.h> |
@@ -159,7 +158,7 @@ static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc) | |||
159 | * driver data structure. It returns 0, if the driver is bound to the GPIO | 158 | * driver data structure. It returns 0, if the driver is bound to the GPIO |
160 | * device, or a negative value if there is an error. | 159 | * device, or a negative value if there is an error. |
161 | */ | 160 | */ |
162 | static int xgpio_of_probe(struct device_node *np) | 161 | static int __devinit xgpio_of_probe(struct device_node *np) |
163 | { | 162 | { |
164 | struct xgpio_instance *chip; | 163 | struct xgpio_instance *chip; |
165 | int status = 0; | 164 | int status = 0; |
@@ -206,10 +205,11 @@ static int xgpio_of_probe(struct device_node *np) | |||
206 | np->full_name, status); | 205 | np->full_name, status); |
207 | return status; | 206 | return status; |
208 | } | 207 | } |
208 | pr_info("XGpio: %s: registered\n", np->full_name); | ||
209 | return 0; | 209 | return 0; |
210 | } | 210 | } |
211 | 211 | ||
212 | static struct of_device_id xgpio_of_match[] = { | 212 | static struct of_device_id xgpio_of_match[] __devinitdata = { |
213 | { .compatible = "xlnx,xps-gpio-1.00.a", }, | 213 | { .compatible = "xlnx,xps-gpio-1.00.a", }, |
214 | { /* end of list */ }, | 214 | { /* end of list */ }, |
215 | }; | 215 | }; |
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c deleted file mode 100644 index cbad6e908d3..00000000000 --- a/drivers/gpio/gpiolib-acpi.c +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | /* | ||
2 | * ACPI helpers for GPIO API | ||
3 | * | ||
4 | * Copyright (C) 2012, Intel Corporation | ||
5 | * Authors: Mathias Nyman <mathias.nyman@linux.intel.com> | ||
6 | * Mika Westerberg <mika.westerberg@linux.intel.com> | ||
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 | |||
13 | #include <linux/errno.h> | ||
14 | #include <linux/gpio.h> | ||
15 | #include <linux/export.h> | ||
16 | #include <linux/acpi_gpio.h> | ||
17 | #include <linux/acpi.h> | ||
18 | |||
19 | static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) | ||
20 | { | ||
21 | if (!gc->dev) | ||
22 | return false; | ||
23 | |||
24 | return ACPI_HANDLE(gc->dev) == data; | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * acpi_get_gpio() - Translate ACPI GPIO pin to GPIO number usable with GPIO API | ||
29 | * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") | ||
30 | * @pin: ACPI GPIO pin number (0-based, controller-relative) | ||
31 | * | ||
32 | * Returns GPIO number to use with Linux generic GPIO API, or errno error value | ||
33 | */ | ||
34 | |||
35 | int acpi_get_gpio(char *path, int pin) | ||
36 | { | ||
37 | struct gpio_chip *chip; | ||
38 | acpi_handle handle; | ||
39 | acpi_status status; | ||
40 | |||
41 | status = acpi_get_handle(NULL, path, &handle); | ||
42 | if (ACPI_FAILURE(status)) | ||
43 | return -ENODEV; | ||
44 | |||
45 | chip = gpiochip_find(handle, acpi_gpiochip_find); | ||
46 | if (!chip) | ||
47 | return -ENODEV; | ||
48 | |||
49 | if (!gpio_is_valid(chip->base + pin)) | ||
50 | return -EINVAL; | ||
51 | |||
52 | return chip->base + pin; | ||
53 | } | ||
54 | EXPORT_SYMBOL_GPL(acpi_get_gpio); | ||
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c deleted file mode 100644 index d542a141811..00000000000 --- a/drivers/gpio/gpiolib-of.c +++ /dev/null | |||
@@ -1,291 +0,0 @@ | |||
1 | /* | ||
2 | * OF helpers for the GPIO API | ||
3 | * | ||
4 | * Copyright (c) 2007-2008 MontaVista Software, Inc. | ||
5 | * | ||
6 | * Author: Anton Vorontsov <avorontsov@ru.mvista.com> | ||
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 as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/device.h> | ||
15 | #include <linux/errno.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/io.h> | ||
18 | #include <linux/gpio.h> | ||
19 | #include <linux/of.h> | ||
20 | #include <linux/of_address.h> | ||
21 | #include <linux/of_gpio.h> | ||
22 | #include <linux/pinctrl/pinctrl.h> | ||
23 | #include <linux/slab.h> | ||
24 | |||
25 | /* Private data structure for of_gpiochip_find_and_xlate */ | ||
26 | struct gg_data { | ||
27 | enum of_gpio_flags *flags; | ||
28 | struct of_phandle_args gpiospec; | ||
29 | |||
30 | int out_gpio; | ||
31 | }; | ||
32 | |||
33 | /* Private function for resolving node pointer to gpio_chip */ | ||
34 | static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data) | ||
35 | { | ||
36 | struct gg_data *gg_data = data; | ||
37 | int ret; | ||
38 | |||
39 | if ((gc->of_node != gg_data->gpiospec.np) || | ||
40 | (gc->of_gpio_n_cells != gg_data->gpiospec.args_count) || | ||
41 | (!gc->of_xlate)) | ||
42 | return false; | ||
43 | |||
44 | ret = gc->of_xlate(gc, &gg_data->gpiospec, gg_data->flags); | ||
45 | if (ret < 0) | ||
46 | return false; | ||
47 | |||
48 | gg_data->out_gpio = ret + gc->base; | ||
49 | return true; | ||
50 | } | ||
51 | |||
52 | /** | ||
53 | * of_get_named_gpio_flags() - Get a GPIO number and flags to use with GPIO API | ||
54 | * @np: device node to get GPIO from | ||
55 | * @propname: property name containing gpio specifier(s) | ||
56 | * @index: index of the GPIO | ||
57 | * @flags: a flags pointer to fill in | ||
58 | * | ||
59 | * Returns GPIO number to use with Linux generic GPIO API, or one of the errno | ||
60 | * value on the error condition. If @flags is not NULL the function also fills | ||
61 | * in flags for the GPIO. | ||
62 | */ | ||
63 | int of_get_named_gpio_flags(struct device_node *np, const char *propname, | ||
64 | int index, enum of_gpio_flags *flags) | ||
65 | { | ||
66 | /* Return -EPROBE_DEFER to support probe() functions to be called | ||
67 | * later when the GPIO actually becomes available | ||
68 | */ | ||
69 | struct gg_data gg_data = { .flags = flags, .out_gpio = -EPROBE_DEFER }; | ||
70 | int ret; | ||
71 | |||
72 | /* .of_xlate might decide to not fill in the flags, so clear it. */ | ||
73 | if (flags) | ||
74 | *flags = 0; | ||
75 | |||
76 | ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index, | ||
77 | &gg_data.gpiospec); | ||
78 | if (ret) { | ||
79 | pr_debug("%s: can't parse gpios property\n", __func__); | ||
80 | return ret; | ||
81 | } | ||
82 | |||
83 | gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); | ||
84 | |||
85 | of_node_put(gg_data.gpiospec.np); | ||
86 | pr_debug("%s exited with status %d\n", __func__, gg_data.out_gpio); | ||
87 | return gg_data.out_gpio; | ||
88 | } | ||
89 | EXPORT_SYMBOL(of_get_named_gpio_flags); | ||
90 | |||
91 | /** | ||
92 | * of_gpio_named_count - Count GPIOs for a device | ||
93 | * @np: device node to count GPIOs for | ||
94 | * @propname: property name containing gpio specifier(s) | ||
95 | * | ||
96 | * The function returns the count of GPIOs specified for a node. | ||
97 | * | ||
98 | * Note that the empty GPIO specifiers counts too. For example, | ||
99 | * | ||
100 | * gpios = <0 | ||
101 | * &pio1 1 2 | ||
102 | * 0 | ||
103 | * &pio2 3 4>; | ||
104 | * | ||
105 | * defines four GPIOs (so this function will return 4), two of which | ||
106 | * are not specified. | ||
107 | */ | ||
108 | unsigned int of_gpio_named_count(struct device_node *np, const char* propname) | ||
109 | { | ||
110 | unsigned int cnt = 0; | ||
111 | |||
112 | do { | ||
113 | int ret; | ||
114 | |||
115 | ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", | ||
116 | cnt, NULL); | ||
117 | /* A hole in the gpios = <> counts anyway. */ | ||
118 | if (ret < 0 && ret != -EEXIST) | ||
119 | break; | ||
120 | } while (++cnt); | ||
121 | |||
122 | return cnt; | ||
123 | } | ||
124 | EXPORT_SYMBOL(of_gpio_named_count); | ||
125 | |||
126 | /** | ||
127 | * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags | ||
128 | * @gc: pointer to the gpio_chip structure | ||
129 | * @np: device node of the GPIO chip | ||
130 | * @gpio_spec: gpio specifier as found in the device tree | ||
131 | * @flags: a flags pointer to fill in | ||
132 | * | ||
133 | * This is simple translation function, suitable for the most 1:1 mapped | ||
134 | * gpio chips. This function performs only one sanity check: whether gpio | ||
135 | * is less than ngpios (that is specified in the gpio_chip). | ||
136 | */ | ||
137 | int of_gpio_simple_xlate(struct gpio_chip *gc, | ||
138 | const struct of_phandle_args *gpiospec, u32 *flags) | ||
139 | { | ||
140 | /* | ||
141 | * We're discouraging gpio_cells < 2, since that way you'll have to | ||
142 | * write your own xlate function (that will have to retrive the GPIO | ||
143 | * number and the flags from a single gpio cell -- this is possible, | ||
144 | * but not recommended). | ||
145 | */ | ||
146 | if (gc->of_gpio_n_cells < 2) { | ||
147 | WARN_ON(1); | ||
148 | return -EINVAL; | ||
149 | } | ||
150 | |||
151 | if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) | ||
152 | return -EINVAL; | ||
153 | |||
154 | if (gpiospec->args[0] >= gc->ngpio) | ||
155 | return -EINVAL; | ||
156 | |||
157 | if (flags) | ||
158 | *flags = gpiospec->args[1]; | ||
159 | |||
160 | return gpiospec->args[0]; | ||
161 | } | ||
162 | EXPORT_SYMBOL(of_gpio_simple_xlate); | ||
163 | |||
164 | /** | ||
165 | * of_mm_gpiochip_add - Add memory mapped GPIO chip (bank) | ||
166 | * @np: device node of the GPIO chip | ||
167 | * @mm_gc: pointer to the of_mm_gpio_chip allocated structure | ||
168 | * | ||
169 | * To use this function you should allocate and fill mm_gc with: | ||
170 | * | ||
171 | * 1) In the gpio_chip structure: | ||
172 | * - all the callbacks | ||
173 | * - of_gpio_n_cells | ||
174 | * - of_xlate callback (optional) | ||
175 | * | ||
176 | * 3) In the of_mm_gpio_chip structure: | ||
177 | * - save_regs callback (optional) | ||
178 | * | ||
179 | * If succeeded, this function will map bank's memory and will | ||
180 | * do all necessary work for you. Then you'll able to use .regs | ||
181 | * to manage GPIOs from the callbacks. | ||
182 | */ | ||
183 | int of_mm_gpiochip_add(struct device_node *np, | ||
184 | struct of_mm_gpio_chip *mm_gc) | ||
185 | { | ||
186 | int ret = -ENOMEM; | ||
187 | struct gpio_chip *gc = &mm_gc->gc; | ||
188 | |||
189 | gc->label = kstrdup(np->full_name, GFP_KERNEL); | ||
190 | if (!gc->label) | ||
191 | goto err0; | ||
192 | |||
193 | mm_gc->regs = of_iomap(np, 0); | ||
194 | if (!mm_gc->regs) | ||
195 | goto err1; | ||
196 | |||
197 | gc->base = -1; | ||
198 | |||
199 | if (mm_gc->save_regs) | ||
200 | mm_gc->save_regs(mm_gc); | ||
201 | |||
202 | mm_gc->gc.of_node = np; | ||
203 | |||
204 | ret = gpiochip_add(gc); | ||
205 | if (ret) | ||
206 | goto err2; | ||
207 | |||
208 | return 0; | ||
209 | err2: | ||
210 | iounmap(mm_gc->regs); | ||
211 | err1: | ||
212 | kfree(gc->label); | ||
213 | err0: | ||
214 | pr_err("%s: GPIO chip registration failed with status %d\n", | ||
215 | np->full_name, ret); | ||
216 | return ret; | ||
217 | } | ||
218 | EXPORT_SYMBOL(of_mm_gpiochip_add); | ||
219 | |||
220 | #ifdef CONFIG_PINCTRL | ||
221 | static void of_gpiochip_add_pin_range(struct gpio_chip *chip) | ||
222 | { | ||
223 | struct device_node *np = chip->of_node; | ||
224 | struct of_phandle_args pinspec; | ||
225 | struct pinctrl_dev *pctldev; | ||
226 | int index = 0, ret; | ||
227 | |||
228 | if (!np) | ||
229 | return; | ||
230 | |||
231 | do { | ||
232 | ret = of_parse_phandle_with_args(np, "gpio-ranges", | ||
233 | "#gpio-range-cells", index, &pinspec); | ||
234 | if (ret) | ||
235 | break; | ||
236 | |||
237 | pctldev = of_pinctrl_get(pinspec.np); | ||
238 | if (!pctldev) | ||
239 | break; | ||
240 | |||
241 | /* | ||
242 | * This assumes that the n GPIO pins are consecutive in the | ||
243 | * GPIO number space, and that the pins are also consecutive | ||
244 | * in their local number space. Currently it is not possible | ||
245 | * to add different ranges for one and the same GPIO chip, | ||
246 | * as the code assumes that we have one consecutive range | ||
247 | * on both, mapping 1-to-1. | ||
248 | * | ||
249 | * TODO: make the OF bindings handle multiple sparse ranges | ||
250 | * on the same GPIO chip. | ||
251 | */ | ||
252 | ret = gpiochip_add_pin_range(chip, | ||
253 | pinctrl_dev_get_name(pctldev), | ||
254 | 0, /* offset in gpiochip */ | ||
255 | pinspec.args[0], | ||
256 | pinspec.args[1]); | ||
257 | |||
258 | if (ret) | ||
259 | break; | ||
260 | |||
261 | } while (index++); | ||
262 | } | ||
263 | |||
264 | #else | ||
265 | static void of_gpiochip_add_pin_range(struct gpio_chip *chip) {} | ||
266 | #endif | ||
267 | |||
268 | void of_gpiochip_add(struct gpio_chip *chip) | ||
269 | { | ||
270 | if ((!chip->of_node) && (chip->dev)) | ||
271 | chip->of_node = chip->dev->of_node; | ||
272 | |||
273 | if (!chip->of_node) | ||
274 | return; | ||
275 | |||
276 | if (!chip->of_xlate) { | ||
277 | chip->of_gpio_n_cells = 2; | ||
278 | chip->of_xlate = of_gpio_simple_xlate; | ||
279 | } | ||
280 | |||
281 | of_gpiochip_add_pin_range(chip); | ||
282 | of_node_get(chip->of_node); | ||
283 | } | ||
284 | |||
285 | void of_gpiochip_remove(struct gpio_chip *chip) | ||
286 | { | ||
287 | gpiochip_remove_pin_ranges(chip); | ||
288 | |||
289 | if (chip->of_node) | ||
290 | of_node_put(chip->of_node); | ||
291 | } | ||
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 199fca15f27..a0fa0b25d21 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -116,7 +116,7 @@ static int gpio_ensure_requested(struct gpio_desc *desc, unsigned offset) | |||
116 | } | 116 | } |
117 | 117 | ||
118 | /* caller holds gpio_lock *OR* gpio is marked as requested */ | 118 | /* caller holds gpio_lock *OR* gpio is marked as requested */ |
119 | struct gpio_chip *gpio_to_chip(unsigned gpio) | 119 | static inline struct gpio_chip *gpio_to_chip(unsigned gpio) |
120 | { | 120 | { |
121 | return gpio_desc[gpio].chip; | 121 | return gpio_desc[gpio].chip; |
122 | } | 122 | } |
@@ -191,32 +191,6 @@ err: | |||
191 | return ret; | 191 | return ret; |
192 | } | 192 | } |
193 | 193 | ||
194 | /* caller ensures gpio is valid and requested, chip->get_direction may sleep */ | ||
195 | static int gpio_get_direction(unsigned gpio) | ||
196 | { | ||
197 | struct gpio_chip *chip; | ||
198 | struct gpio_desc *desc = &gpio_desc[gpio]; | ||
199 | int status = -EINVAL; | ||
200 | |||
201 | chip = gpio_to_chip(gpio); | ||
202 | gpio -= chip->base; | ||
203 | |||
204 | if (!chip->get_direction) | ||
205 | return status; | ||
206 | |||
207 | status = chip->get_direction(chip, gpio); | ||
208 | if (status > 0) { | ||
209 | /* GPIOF_DIR_IN, or other positive */ | ||
210 | status = 1; | ||
211 | clear_bit(FLAG_IS_OUT, &desc->flags); | ||
212 | } | ||
213 | if (status == 0) { | ||
214 | /* GPIOF_DIR_OUT */ | ||
215 | set_bit(FLAG_IS_OUT, &desc->flags); | ||
216 | } | ||
217 | return status; | ||
218 | } | ||
219 | |||
220 | #ifdef CONFIG_GPIO_SYSFS | 194 | #ifdef CONFIG_GPIO_SYSFS |
221 | 195 | ||
222 | /* lock protects against unexport_gpio() being called while | 196 | /* lock protects against unexport_gpio() being called while |
@@ -249,7 +223,6 @@ static ssize_t gpio_direction_show(struct device *dev, | |||
249 | struct device_attribute *attr, char *buf) | 223 | struct device_attribute *attr, char *buf) |
250 | { | 224 | { |
251 | const struct gpio_desc *desc = dev_get_drvdata(dev); | 225 | const struct gpio_desc *desc = dev_get_drvdata(dev); |
252 | unsigned gpio = desc - gpio_desc; | ||
253 | ssize_t status; | 226 | ssize_t status; |
254 | 227 | ||
255 | mutex_lock(&sysfs_lock); | 228 | mutex_lock(&sysfs_lock); |
@@ -257,7 +230,6 @@ static ssize_t gpio_direction_show(struct device *dev, | |||
257 | if (!test_bit(FLAG_EXPORT, &desc->flags)) | 230 | if (!test_bit(FLAG_EXPORT, &desc->flags)) |
258 | status = -EIO; | 231 | status = -EIO; |
259 | else | 232 | else |
260 | gpio_get_direction(gpio); | ||
261 | status = sprintf(buf, "%s\n", | 233 | status = sprintf(buf, "%s\n", |
262 | test_bit(FLAG_IS_OUT, &desc->flags) | 234 | test_bit(FLAG_IS_OUT, &desc->flags) |
263 | ? "out" : "in"); | 235 | ? "out" : "in"); |
@@ -651,11 +623,9 @@ static ssize_t export_store(struct class *class, | |||
651 | */ | 623 | */ |
652 | 624 | ||
653 | status = gpio_request(gpio, "sysfs"); | 625 | status = gpio_request(gpio, "sysfs"); |
654 | if (status < 0) { | 626 | if (status < 0) |
655 | if (status == -EPROBE_DEFER) | ||
656 | status = -ENODEV; | ||
657 | goto done; | 627 | goto done; |
658 | } | 628 | |
659 | status = gpio_export(gpio, true); | 629 | status = gpio_export(gpio, true); |
660 | if (status < 0) | 630 | if (status < 0) |
661 | gpio_free(gpio); | 631 | gpio_free(gpio); |
@@ -732,9 +702,8 @@ int gpio_export(unsigned gpio, bool direction_may_change) | |||
732 | { | 702 | { |
733 | unsigned long flags; | 703 | unsigned long flags; |
734 | struct gpio_desc *desc; | 704 | struct gpio_desc *desc; |
735 | int status; | 705 | int status = -EINVAL; |
736 | const char *ioname = NULL; | 706 | const char *ioname = NULL; |
737 | struct device *dev; | ||
738 | 707 | ||
739 | /* can't export until sysfs is available ... */ | 708 | /* can't export until sysfs is available ... */ |
740 | if (!gpio_class.p) { | 709 | if (!gpio_class.p) { |
@@ -742,66 +711,59 @@ int gpio_export(unsigned gpio, bool direction_may_change) | |||
742 | return -ENOENT; | 711 | return -ENOENT; |
743 | } | 712 | } |
744 | 713 | ||
745 | if (!gpio_is_valid(gpio)) { | 714 | if (!gpio_is_valid(gpio)) |
746 | pr_debug("%s: gpio %d is not valid\n", __func__, gpio); | 715 | goto done; |
747 | return -EINVAL; | ||
748 | } | ||
749 | 716 | ||
750 | mutex_lock(&sysfs_lock); | 717 | mutex_lock(&sysfs_lock); |
751 | 718 | ||
752 | spin_lock_irqsave(&gpio_lock, flags); | 719 | spin_lock_irqsave(&gpio_lock, flags); |
753 | desc = &gpio_desc[gpio]; | 720 | desc = &gpio_desc[gpio]; |
754 | if (!test_bit(FLAG_REQUESTED, &desc->flags) || | 721 | if (test_bit(FLAG_REQUESTED, &desc->flags) |
755 | test_bit(FLAG_EXPORT, &desc->flags)) { | 722 | && !test_bit(FLAG_EXPORT, &desc->flags)) { |
756 | spin_unlock_irqrestore(&gpio_lock, flags); | 723 | status = 0; |
757 | pr_debug("%s: gpio %d unavailable (requested=%d, exported=%d)\n", | 724 | if (!desc->chip->direction_input |
758 | __func__, gpio, | 725 | || !desc->chip->direction_output) |
759 | test_bit(FLAG_REQUESTED, &desc->flags), | 726 | direction_may_change = false; |
760 | test_bit(FLAG_EXPORT, &desc->flags)); | ||
761 | status = -EPERM; | ||
762 | goto fail_unlock; | ||
763 | } | 727 | } |
764 | |||
765 | if (!desc->chip->direction_input || !desc->chip->direction_output) | ||
766 | direction_may_change = false; | ||
767 | spin_unlock_irqrestore(&gpio_lock, flags); | 728 | spin_unlock_irqrestore(&gpio_lock, flags); |
768 | 729 | ||
769 | if (desc->chip->names && desc->chip->names[gpio - desc->chip->base]) | 730 | if (desc->chip->names && desc->chip->names[gpio - desc->chip->base]) |
770 | ioname = desc->chip->names[gpio - desc->chip->base]; | 731 | ioname = desc->chip->names[gpio - desc->chip->base]; |
771 | 732 | ||
772 | dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), | 733 | if (status == 0) { |
773 | desc, ioname ? ioname : "gpio%u", gpio); | 734 | struct device *dev; |
774 | if (IS_ERR(dev)) { | 735 | |
775 | status = PTR_ERR(dev); | 736 | dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), |
776 | goto fail_unlock; | 737 | desc, ioname ? ioname : "gpio%u", gpio); |
777 | } | 738 | if (!IS_ERR(dev)) { |
778 | 739 | status = sysfs_create_group(&dev->kobj, | |
779 | status = sysfs_create_group(&dev->kobj, &gpio_attr_group); | 740 | &gpio_attr_group); |
780 | if (status) | 741 | |
781 | goto fail_unregister_device; | 742 | if (!status && direction_may_change) |
782 | 743 | status = device_create_file(dev, | |
783 | if (direction_may_change) { | 744 | &dev_attr_direction); |
784 | status = device_create_file(dev, &dev_attr_direction); | 745 | |
785 | if (status) | 746 | if (!status && gpio_to_irq(gpio) >= 0 |
786 | goto fail_unregister_device; | 747 | && (direction_may_change |
787 | } | 748 | || !test_bit(FLAG_IS_OUT, |
788 | 749 | &desc->flags))) | |
789 | if (gpio_to_irq(gpio) >= 0 && (direction_may_change || | 750 | status = device_create_file(dev, |
790 | !test_bit(FLAG_IS_OUT, &desc->flags))) { | 751 | &dev_attr_edge); |
791 | status = device_create_file(dev, &dev_attr_edge); | 752 | |
792 | if (status) | 753 | if (status != 0) |
793 | goto fail_unregister_device; | 754 | device_unregister(dev); |
755 | } else | ||
756 | status = PTR_ERR(dev); | ||
757 | if (status == 0) | ||
758 | set_bit(FLAG_EXPORT, &desc->flags); | ||
794 | } | 759 | } |
795 | 760 | ||
796 | set_bit(FLAG_EXPORT, &desc->flags); | ||
797 | mutex_unlock(&sysfs_lock); | 761 | mutex_unlock(&sysfs_lock); |
798 | return 0; | ||
799 | 762 | ||
800 | fail_unregister_device: | 763 | done: |
801 | device_unregister(dev); | 764 | if (status) |
802 | fail_unlock: | 765 | pr_debug("%s: gpio%d status %d\n", __func__, gpio, status); |
803 | mutex_unlock(&sysfs_lock); | 766 | |
804 | pr_debug("%s: gpio%d status %d\n", __func__, gpio, status); | ||
805 | return status; | 767 | return status; |
806 | } | 768 | } |
807 | EXPORT_SYMBOL_GPL(gpio_export); | 769 | EXPORT_SYMBOL_GPL(gpio_export); |
@@ -913,7 +875,6 @@ void gpio_unexport(unsigned gpio) | |||
913 | { | 875 | { |
914 | struct gpio_desc *desc; | 876 | struct gpio_desc *desc; |
915 | int status = 0; | 877 | int status = 0; |
916 | struct device *dev = NULL; | ||
917 | 878 | ||
918 | if (!gpio_is_valid(gpio)) { | 879 | if (!gpio_is_valid(gpio)) { |
919 | status = -EINVAL; | 880 | status = -EINVAL; |
@@ -925,20 +886,19 @@ void gpio_unexport(unsigned gpio) | |||
925 | desc = &gpio_desc[gpio]; | 886 | desc = &gpio_desc[gpio]; |
926 | 887 | ||
927 | if (test_bit(FLAG_EXPORT, &desc->flags)) { | 888 | if (test_bit(FLAG_EXPORT, &desc->flags)) { |
889 | struct device *dev = NULL; | ||
928 | 890 | ||
929 | dev = class_find_device(&gpio_class, NULL, desc, match_export); | 891 | dev = class_find_device(&gpio_class, NULL, desc, match_export); |
930 | if (dev) { | 892 | if (dev) { |
931 | gpio_setup_irq(desc, dev, 0); | 893 | gpio_setup_irq(desc, dev, 0); |
932 | clear_bit(FLAG_EXPORT, &desc->flags); | 894 | clear_bit(FLAG_EXPORT, &desc->flags); |
895 | put_device(dev); | ||
896 | device_unregister(dev); | ||
933 | } else | 897 | } else |
934 | status = -ENODEV; | 898 | status = -ENODEV; |
935 | } | 899 | } |
936 | 900 | ||
937 | mutex_unlock(&sysfs_lock); | 901 | mutex_unlock(&sysfs_lock); |
938 | if (dev) { | ||
939 | device_unregister(dev); | ||
940 | put_device(dev); | ||
941 | } | ||
942 | done: | 902 | done: |
943 | if (status) | 903 | if (status) |
944 | pr_debug("%s: gpio%d status %d\n", __func__, gpio, status); | 904 | pr_debug("%s: gpio%d status %d\n", __func__, gpio, status); |
@@ -1111,7 +1071,6 @@ int gpiochip_add(struct gpio_chip *chip) | |||
1111 | * inputs (often with pullups enabled) so power | 1071 | * inputs (often with pullups enabled) so power |
1112 | * usage is minimized. Linux code should set the | 1072 | * usage is minimized. Linux code should set the |
1113 | * gpio direction first thing; but until it does, | 1073 | * gpio direction first thing; but until it does, |
1114 | * and in case chip->get_direction is not set, | ||
1115 | * we may expose the wrong direction in sysfs. | 1074 | * we may expose the wrong direction in sysfs. |
1116 | */ | 1075 | */ |
1117 | gpio_desc[id].flags = !chip->direction_input | 1076 | gpio_desc[id].flags = !chip->direction_input |
@@ -1120,10 +1079,6 @@ int gpiochip_add(struct gpio_chip *chip) | |||
1120 | } | 1079 | } |
1121 | } | 1080 | } |
1122 | 1081 | ||
1123 | #ifdef CONFIG_PINCTRL | ||
1124 | INIT_LIST_HEAD(&chip->pin_ranges); | ||
1125 | #endif | ||
1126 | |||
1127 | of_gpiochip_add(chip); | 1082 | of_gpiochip_add(chip); |
1128 | 1083 | ||
1129 | unlock: | 1084 | unlock: |
@@ -1136,10 +1091,6 @@ unlock: | |||
1136 | if (status) | 1091 | if (status) |
1137 | goto fail; | 1092 | goto fail; |
1138 | 1093 | ||
1139 | pr_debug("gpiochip_add: registered GPIOs %d to %d on device: %s\n", | ||
1140 | chip->base, chip->base + chip->ngpio - 1, | ||
1141 | chip->label ? : "generic"); | ||
1142 | |||
1143 | return 0; | 1094 | return 0; |
1144 | fail: | 1095 | fail: |
1145 | /* failures here can mean systems won't boot... */ | 1096 | /* failures here can mean systems won't boot... */ |
@@ -1164,7 +1115,6 @@ int gpiochip_remove(struct gpio_chip *chip) | |||
1164 | 1115 | ||
1165 | spin_lock_irqsave(&gpio_lock, flags); | 1116 | spin_lock_irqsave(&gpio_lock, flags); |
1166 | 1117 | ||
1167 | gpiochip_remove_pin_ranges(chip); | ||
1168 | of_gpiochip_remove(chip); | 1118 | of_gpiochip_remove(chip); |
1169 | 1119 | ||
1170 | for (id = chip->base; id < chip->base + chip->ngpio; id++) { | 1120 | for (id = chip->base; id < chip->base + chip->ngpio; id++) { |
@@ -1199,8 +1149,7 @@ EXPORT_SYMBOL_GPL(gpiochip_remove); | |||
1199 | * more gpio_chips. | 1149 | * more gpio_chips. |
1200 | */ | 1150 | */ |
1201 | struct gpio_chip *gpiochip_find(void *data, | 1151 | struct gpio_chip *gpiochip_find(void *data, |
1202 | int (*match)(struct gpio_chip *chip, | 1152 | int (*match)(struct gpio_chip *chip, void *data)) |
1203 | void *data)) | ||
1204 | { | 1153 | { |
1205 | struct gpio_chip *chip = NULL; | 1154 | struct gpio_chip *chip = NULL; |
1206 | unsigned long flags; | 1155 | unsigned long flags; |
@@ -1222,77 +1171,6 @@ struct gpio_chip *gpiochip_find(void *data, | |||
1222 | } | 1171 | } |
1223 | EXPORT_SYMBOL_GPL(gpiochip_find); | 1172 | EXPORT_SYMBOL_GPL(gpiochip_find); |
1224 | 1173 | ||
1225 | #ifdef CONFIG_PINCTRL | ||
1226 | |||
1227 | /** | ||
1228 | * gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping | ||
1229 | * @chip: the gpiochip to add the range for | ||
1230 | * @pinctrl_name: the dev_name() of the pin controller to map to | ||
1231 | * @gpio_offset: the start offset in the current gpio_chip number space | ||
1232 | * @pin_offset: the start offset in the pin controller number space | ||
1233 | * @npins: the number of pins from the offset of each pin space (GPIO and | ||
1234 | * pin controller) to accumulate in this range | ||
1235 | */ | ||
1236 | int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, | ||
1237 | unsigned int gpio_offset, unsigned int pin_offset, | ||
1238 | unsigned int npins) | ||
1239 | { | ||
1240 | struct gpio_pin_range *pin_range; | ||
1241 | int ret; | ||
1242 | |||
1243 | pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); | ||
1244 | if (!pin_range) { | ||
1245 | pr_err("%s: GPIO chip: failed to allocate pin ranges\n", | ||
1246 | chip->label); | ||
1247 | return -ENOMEM; | ||
1248 | } | ||
1249 | |||
1250 | /* Use local offset as range ID */ | ||
1251 | pin_range->range.id = gpio_offset; | ||
1252 | pin_range->range.gc = chip; | ||
1253 | pin_range->range.name = chip->label; | ||
1254 | pin_range->range.base = chip->base + gpio_offset; | ||
1255 | pin_range->range.pin_base = pin_offset; | ||
1256 | pin_range->range.npins = npins; | ||
1257 | pin_range->pctldev = pinctrl_find_and_add_gpio_range(pinctl_name, | ||
1258 | &pin_range->range); | ||
1259 | if (IS_ERR(pin_range->pctldev)) { | ||
1260 | ret = PTR_ERR(pin_range->pctldev); | ||
1261 | pr_err("%s: GPIO chip: could not create pin range\n", | ||
1262 | chip->label); | ||
1263 | kfree(pin_range); | ||
1264 | return ret; | ||
1265 | } | ||
1266 | pr_debug("GPIO chip %s: created GPIO range %d->%d ==> %s PIN %d->%d\n", | ||
1267 | chip->label, gpio_offset, gpio_offset + npins - 1, | ||
1268 | pinctl_name, | ||
1269 | pin_offset, pin_offset + npins - 1); | ||
1270 | |||
1271 | list_add_tail(&pin_range->node, &chip->pin_ranges); | ||
1272 | |||
1273 | return 0; | ||
1274 | } | ||
1275 | EXPORT_SYMBOL_GPL(gpiochip_add_pin_range); | ||
1276 | |||
1277 | /** | ||
1278 | * gpiochip_remove_pin_ranges() - remove all the GPIO <-> pin mappings | ||
1279 | * @chip: the chip to remove all the mappings for | ||
1280 | */ | ||
1281 | void gpiochip_remove_pin_ranges(struct gpio_chip *chip) | ||
1282 | { | ||
1283 | struct gpio_pin_range *pin_range, *tmp; | ||
1284 | |||
1285 | list_for_each_entry_safe(pin_range, tmp, &chip->pin_ranges, node) { | ||
1286 | list_del(&pin_range->node); | ||
1287 | pinctrl_remove_gpio_range(pin_range->pctldev, | ||
1288 | &pin_range->range); | ||
1289 | kfree(pin_range); | ||
1290 | } | ||
1291 | } | ||
1292 | EXPORT_SYMBOL_GPL(gpiochip_remove_pin_ranges); | ||
1293 | |||
1294 | #endif /* CONFIG_PINCTRL */ | ||
1295 | |||
1296 | /* These "optional" allocation calls help prevent drivers from stomping | 1174 | /* These "optional" allocation calls help prevent drivers from stomping |
1297 | * on each other, and help provide better diagnostics in debugfs. | 1175 | * on each other, and help provide better diagnostics in debugfs. |
1298 | * They're called even less than the "set direction" calls. | 1176 | * They're called even less than the "set direction" calls. |
@@ -1301,15 +1179,13 @@ int gpio_request(unsigned gpio, const char *label) | |||
1301 | { | 1179 | { |
1302 | struct gpio_desc *desc; | 1180 | struct gpio_desc *desc; |
1303 | struct gpio_chip *chip; | 1181 | struct gpio_chip *chip; |
1304 | int status = -EPROBE_DEFER; | 1182 | int status = -EINVAL; |
1305 | unsigned long flags; | 1183 | unsigned long flags; |
1306 | 1184 | ||
1307 | spin_lock_irqsave(&gpio_lock, flags); | 1185 | spin_lock_irqsave(&gpio_lock, flags); |
1308 | 1186 | ||
1309 | if (!gpio_is_valid(gpio)) { | 1187 | if (!gpio_is_valid(gpio)) |
1310 | status = -EINVAL; | ||
1311 | goto done; | 1188 | goto done; |
1312 | } | ||
1313 | desc = &gpio_desc[gpio]; | 1189 | desc = &gpio_desc[gpio]; |
1314 | chip = desc->chip; | 1190 | chip = desc->chip; |
1315 | if (chip == NULL) | 1191 | if (chip == NULL) |
@@ -1341,15 +1217,9 @@ int gpio_request(unsigned gpio, const char *label) | |||
1341 | desc_set_label(desc, NULL); | 1217 | desc_set_label(desc, NULL); |
1342 | module_put(chip->owner); | 1218 | module_put(chip->owner); |
1343 | clear_bit(FLAG_REQUESTED, &desc->flags); | 1219 | clear_bit(FLAG_REQUESTED, &desc->flags); |
1344 | goto done; | ||
1345 | } | 1220 | } |
1346 | } | 1221 | } |
1347 | if (chip->get_direction) { | 1222 | |
1348 | /* chip->get_direction may sleep */ | ||
1349 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
1350 | gpio_get_direction(gpio); | ||
1351 | spin_lock_irqsave(&gpio_lock, flags); | ||
1352 | } | ||
1353 | done: | 1223 | done: |
1354 | if (status) | 1224 | if (status) |
1355 | pr_debug("gpio_request: gpio-%d (%s) status %d\n", | 1225 | pr_debug("gpio_request: gpio-%d (%s) status %d\n", |
@@ -1425,18 +1295,8 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) | |||
1425 | (flags & GPIOF_INIT_HIGH) ? 1 : 0); | 1295 | (flags & GPIOF_INIT_HIGH) ? 1 : 0); |
1426 | 1296 | ||
1427 | if (err) | 1297 | if (err) |
1428 | goto free_gpio; | 1298 | gpio_free(gpio); |
1429 | |||
1430 | if (flags & GPIOF_EXPORT) { | ||
1431 | err = gpio_export(gpio, flags & GPIOF_EXPORT_CHANGEABLE); | ||
1432 | if (err) | ||
1433 | goto free_gpio; | ||
1434 | } | ||
1435 | |||
1436 | return 0; | ||
1437 | 1299 | ||
1438 | free_gpio: | ||
1439 | gpio_free(gpio); | ||
1440 | return err; | 1300 | return err; |
1441 | } | 1301 | } |
1442 | EXPORT_SYMBOL_GPL(gpio_request_one); | 1302 | EXPORT_SYMBOL_GPL(gpio_request_one); |
@@ -1714,7 +1574,6 @@ int __gpio_get_value(unsigned gpio) | |||
1714 | int value; | 1574 | int value; |
1715 | 1575 | ||
1716 | chip = gpio_to_chip(gpio); | 1576 | chip = gpio_to_chip(gpio); |
1717 | /* Should be using gpio_get_value_cansleep() */ | ||
1718 | WARN_ON(chip->can_sleep); | 1577 | WARN_ON(chip->can_sleep); |
1719 | value = chip->get ? chip->get(chip, gpio - chip->base) : 0; | 1578 | value = chip->get ? chip->get(chip, gpio - chip->base) : 0; |
1720 | trace_gpio_value(gpio, 1, value); | 1579 | trace_gpio_value(gpio, 1, value); |
@@ -1787,7 +1646,6 @@ void __gpio_set_value(unsigned gpio, int value) | |||
1787 | struct gpio_chip *chip; | 1646 | struct gpio_chip *chip; |
1788 | 1647 | ||
1789 | chip = gpio_to_chip(gpio); | 1648 | chip = gpio_to_chip(gpio); |
1790 | /* Should be using gpio_set_value_cansleep() */ | ||
1791 | WARN_ON(chip->can_sleep); | 1649 | WARN_ON(chip->can_sleep); |
1792 | trace_gpio_value(gpio, 0, value); | 1650 | trace_gpio_value(gpio, 0, value); |
1793 | if (test_bit(FLAG_OPEN_DRAIN, &gpio_desc[gpio].flags)) | 1651 | if (test_bit(FLAG_OPEN_DRAIN, &gpio_desc[gpio].flags)) |
@@ -1885,7 +1743,6 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip) | |||
1885 | if (!test_bit(FLAG_REQUESTED, &gdesc->flags)) | 1743 | if (!test_bit(FLAG_REQUESTED, &gdesc->flags)) |
1886 | continue; | 1744 | continue; |
1887 | 1745 | ||
1888 | gpio_get_direction(gpio); | ||
1889 | is_out = test_bit(FLAG_IS_OUT, &gdesc->flags); | 1746 | is_out = test_bit(FLAG_IS_OUT, &gdesc->flags); |
1890 | seq_printf(s, " gpio-%-3d (%-20.20s) %s %s", | 1747 | seq_printf(s, " gpio-%-3d (%-20.20s) %s %s", |
1891 | gpio, gdesc->label, | 1748 | gpio, gdesc->label, |
@@ -1897,102 +1754,56 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip) | |||
1897 | } | 1754 | } |
1898 | } | 1755 | } |
1899 | 1756 | ||
1900 | static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) | 1757 | static int gpiolib_show(struct seq_file *s, void *unused) |
1901 | { | 1758 | { |
1902 | struct gpio_chip *chip = NULL; | 1759 | struct gpio_chip *chip = NULL; |
1903 | unsigned int gpio; | 1760 | unsigned gpio; |
1904 | void *ret = NULL; | 1761 | int started = 0; |
1905 | loff_t index = 0; | ||
1906 | 1762 | ||
1907 | /* REVISIT this isn't locked against gpio_chip removal ... */ | 1763 | /* REVISIT this isn't locked against gpio_chip removal ... */ |
1908 | 1764 | ||
1909 | for (gpio = 0; gpio_is_valid(gpio); gpio++) { | 1765 | for (gpio = 0; gpio_is_valid(gpio); gpio++) { |
1910 | if (gpio_desc[gpio].chip == chip) | 1766 | struct device *dev; |
1911 | continue; | ||
1912 | 1767 | ||
1768 | if (chip == gpio_desc[gpio].chip) | ||
1769 | continue; | ||
1913 | chip = gpio_desc[gpio].chip; | 1770 | chip = gpio_desc[gpio].chip; |
1914 | if (!chip) | 1771 | if (!chip) |
1915 | continue; | 1772 | continue; |
1916 | 1773 | ||
1917 | if (index++ >= *pos) { | 1774 | seq_printf(s, "%sGPIOs %d-%d", |
1918 | ret = chip; | 1775 | started ? "\n" : "", |
1919 | break; | 1776 | chip->base, chip->base + chip->ngpio - 1); |
1920 | } | 1777 | dev = chip->dev; |
1778 | if (dev) | ||
1779 | seq_printf(s, ", %s/%s", | ||
1780 | dev->bus ? dev->bus->name : "no-bus", | ||
1781 | dev_name(dev)); | ||
1782 | if (chip->label) | ||
1783 | seq_printf(s, ", %s", chip->label); | ||
1784 | if (chip->can_sleep) | ||
1785 | seq_printf(s, ", can sleep"); | ||
1786 | seq_printf(s, ":\n"); | ||
1787 | |||
1788 | started = 1; | ||
1789 | if (chip->dbg_show) | ||
1790 | chip->dbg_show(s, chip); | ||
1791 | else | ||
1792 | gpiolib_dbg_show(s, chip); | ||
1921 | } | 1793 | } |
1922 | |||
1923 | s->private = ""; | ||
1924 | |||
1925 | return ret; | ||
1926 | } | ||
1927 | |||
1928 | static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) | ||
1929 | { | ||
1930 | struct gpio_chip *chip = v; | ||
1931 | unsigned int gpio; | ||
1932 | void *ret = NULL; | ||
1933 | |||
1934 | /* skip GPIOs provided by the current chip */ | ||
1935 | for (gpio = chip->base + chip->ngpio; gpio_is_valid(gpio); gpio++) { | ||
1936 | chip = gpio_desc[gpio].chip; | ||
1937 | if (chip) { | ||
1938 | ret = chip; | ||
1939 | break; | ||
1940 | } | ||
1941 | } | ||
1942 | |||
1943 | s->private = "\n"; | ||
1944 | ++*pos; | ||
1945 | |||
1946 | return ret; | ||
1947 | } | ||
1948 | |||
1949 | static void gpiolib_seq_stop(struct seq_file *s, void *v) | ||
1950 | { | ||
1951 | } | ||
1952 | |||
1953 | static int gpiolib_seq_show(struct seq_file *s, void *v) | ||
1954 | { | ||
1955 | struct gpio_chip *chip = v; | ||
1956 | struct device *dev; | ||
1957 | |||
1958 | seq_printf(s, "%sGPIOs %d-%d", (char *)s->private, | ||
1959 | chip->base, chip->base + chip->ngpio - 1); | ||
1960 | dev = chip->dev; | ||
1961 | if (dev) | ||
1962 | seq_printf(s, ", %s/%s", dev->bus ? dev->bus->name : "no-bus", | ||
1963 | dev_name(dev)); | ||
1964 | if (chip->label) | ||
1965 | seq_printf(s, ", %s", chip->label); | ||
1966 | if (chip->can_sleep) | ||
1967 | seq_printf(s, ", can sleep"); | ||
1968 | seq_printf(s, ":\n"); | ||
1969 | |||
1970 | if (chip->dbg_show) | ||
1971 | chip->dbg_show(s, chip); | ||
1972 | else | ||
1973 | gpiolib_dbg_show(s, chip); | ||
1974 | |||
1975 | return 0; | 1794 | return 0; |
1976 | } | 1795 | } |
1977 | 1796 | ||
1978 | static const struct seq_operations gpiolib_seq_ops = { | ||
1979 | .start = gpiolib_seq_start, | ||
1980 | .next = gpiolib_seq_next, | ||
1981 | .stop = gpiolib_seq_stop, | ||
1982 | .show = gpiolib_seq_show, | ||
1983 | }; | ||
1984 | |||
1985 | static int gpiolib_open(struct inode *inode, struct file *file) | 1797 | static int gpiolib_open(struct inode *inode, struct file *file) |
1986 | { | 1798 | { |
1987 | return seq_open(file, &gpiolib_seq_ops); | 1799 | return single_open(file, gpiolib_show, NULL); |
1988 | } | 1800 | } |
1989 | 1801 | ||
1990 | static const struct file_operations gpiolib_operations = { | 1802 | static const struct file_operations gpiolib_operations = { |
1991 | .owner = THIS_MODULE, | ||
1992 | .open = gpiolib_open, | 1803 | .open = gpiolib_open, |
1993 | .read = seq_read, | 1804 | .read = seq_read, |
1994 | .llseek = seq_lseek, | 1805 | .llseek = seq_lseek, |
1995 | .release = seq_release, | 1806 | .release = single_release, |
1996 | }; | 1807 | }; |
1997 | 1808 | ||
1998 | static int __init gpiolib_debugfs_init(void) | 1809 | static int __init gpiolib_debugfs_init(void) |