3 * arch/arm/mach-u300/gpio.c
6 * Copyright (C) 2007-2009 ST-Ericsson AB
7 * License terms: GNU General Public License (GPL) version 2
9 * This can driver either of the two basic GPIO cores
10 * available in the U300 platforms:
11 * COH 901 335 - Used in DB3150 (U300 1.0) and DB3200 (U330 1.0)
12 * COH 901 571/3 - Used in DB3210 (U365 2.0) and DB3350 (U335 1.0)
13 * Notice that you also have inline macros in <asm-arch/gpio.h>
14 * Author: Linus Walleij <linus.walleij@stericsson.com>
15 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
18 #include <linux/module.h>
19 #include <linux/interrupt.h>
20 #include <linux/delay.h>
21 #include <linux/errno.h>
23 #include <linux/clk.h>
24 #include <linux/err.h>
25 #include <linux/platform_device.h>
26 #include <linux/gpio.h>
28 /* Reference to GPIO block clock */
29 static struct clk
*clk
;
32 static struct resource
*memres
;
33 static void __iomem
*virtbase
;
34 static struct device
*gpiodev
;
36 struct u300_gpio_port
{
43 static struct u300_gpio_port gpio_ports
[] = {
56 #ifdef U300_COH901571_3
65 #ifdef CONFIG_MACH_U300_BS335
80 #ifdef U300_COH901571_3
82 /* Default input value */
83 #define DEFAULT_OUTPUT_LOW 0
84 #define DEFAULT_OUTPUT_HIGH 1
86 /* GPIO Pull-Up status */
87 #define DISABLE_PULL_UP 0
88 #define ENABLE_PULL_UP 1
90 #define GPIO_NOT_USED 0
94 struct u300_gpio_configuration_data
{
95 unsigned char pin_usage
;
96 unsigned char default_output_value
;
97 unsigned char pull_up
;
100 /* Initial configuration */
101 const struct u300_gpio_configuration_data
102 u300_gpio_config
[U300_GPIO_NUM_PORTS
][U300_GPIO_PINS_PER_PORT
] = {
103 #ifdef CONFIG_MACH_U300_BS335
104 /* Port 0, pins 0-7 */
106 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
107 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
108 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
109 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
110 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
111 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
112 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
113 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
115 /* Port 1, pins 0-7 */
117 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
118 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
119 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
120 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
121 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
122 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
123 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
124 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
126 /* Port 2, pins 0-7 */
128 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
129 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
130 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
131 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
132 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
133 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
134 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
135 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
137 /* Port 3, pins 0-7 */
139 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
140 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
141 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
142 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
143 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
144 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
145 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
146 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
148 /* Port 4, pins 0-7 */
150 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
151 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
152 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
153 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
154 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
155 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
156 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
157 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
159 /* Port 5, pins 0-7 */
161 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
162 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
163 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
164 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
165 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
166 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
167 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
168 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
170 /* Port 6, pind 0-7 */
172 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
173 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
174 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
175 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
176 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
177 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
178 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
179 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
183 #ifdef CONFIG_MACH_U300_BS365
184 /* Port 0, pins 0-7 */
186 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
187 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
188 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
189 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
190 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
191 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
192 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
193 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
195 /* Port 1, pins 0-7 */
197 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
198 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
199 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
200 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
201 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
202 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
203 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
204 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
206 /* Port 2, pins 0-7 */
208 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
209 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
210 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
211 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
212 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
213 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
214 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
215 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
217 /* Port 3, pins 0-7 */
219 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
220 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
221 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
222 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
223 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
224 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
225 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
226 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
228 /* Port 4, pins 0-7 */
230 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
231 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
232 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
233 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
234 /* These 4 pins doesn't exist on DB3210 */
235 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
236 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
237 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
238 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
245 /* No users == we can power down GPIO */
246 static int gpio_users
;
249 int (*callback
)(void *);
254 static struct gpio_struct gpio_pin
[U300_GPIO_MAX
];
257 * Let drivers register callback in order to get notified when there is
258 * an interrupt on the gpio pin
260 int gpio_register_callback(unsigned gpio
, int (*func
)(void *arg
), void *data
)
262 if (gpio_pin
[gpio
].callback
)
263 dev_warn(gpiodev
, "%s: WARNING: callback already "
264 "registered for gpio pin#%d\n", __func__
, gpio
);
265 gpio_pin
[gpio
].callback
= func
;
266 gpio_pin
[gpio
].data
= data
;
270 EXPORT_SYMBOL(gpio_register_callback
);
272 int gpio_unregister_callback(unsigned gpio
)
274 if (!gpio_pin
[gpio
].callback
)
275 dev_warn(gpiodev
, "%s: WARNING: callback already "
276 "unregistered for gpio pin#%d\n", __func__
, gpio
);
277 gpio_pin
[gpio
].callback
= NULL
;
278 gpio_pin
[gpio
].data
= NULL
;
282 EXPORT_SYMBOL(gpio_unregister_callback
);
284 /* Non-zero means valid */
285 int gpio_is_valid(int number
)
288 number
< (U300_GPIO_NUM_PORTS
* U300_GPIO_PINS_PER_PORT
))
292 EXPORT_SYMBOL(gpio_is_valid
);
294 int gpio_request(unsigned gpio
, const char *label
)
296 if (gpio_pin
[gpio
].users
)
299 gpio_pin
[gpio
].users
++;
305 EXPORT_SYMBOL(gpio_request
);
307 void gpio_free(unsigned gpio
)
310 gpio_pin
[gpio
].users
--;
311 if (unlikely(gpio_pin
[gpio
].users
< 0)) {
312 dev_warn(gpiodev
, "warning: gpio#%d release mismatch\n",
314 gpio_pin
[gpio
].users
= 0;
319 EXPORT_SYMBOL(gpio_free
);
321 /* This returns zero or nonzero */
322 int gpio_get_value(unsigned gpio
)
324 return readl(virtbase
+ U300_GPIO_PXPDIR
+
325 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
) & (1 << (gpio
& 0x07));
327 EXPORT_SYMBOL(gpio_get_value
);
330 * We hope that the compiler will optimize away the unused branch
331 * in case "value" is a constant
333 void gpio_set_value(unsigned gpio
, int value
)
338 local_irq_save(flags
);
341 val
= readl(virtbase
+ U300_GPIO_PXPDOR
+
342 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
)
343 & (1 << (gpio
& 0x07));
344 writel(val
| (1 << (gpio
& 0x07)), virtbase
+
346 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
349 val
= readl(virtbase
+ U300_GPIO_PXPDOR
+
350 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
)
351 & (1 << (gpio
& 0x07));
352 writel(val
& ~(1 << (gpio
& 0x07)), virtbase
+
354 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
356 local_irq_restore(flags
);
358 EXPORT_SYMBOL(gpio_set_value
);
360 int gpio_direction_input(unsigned gpio
)
365 if (gpio
> U300_GPIO_MAX
)
368 local_irq_save(flags
);
369 val
= readl(virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
370 U300_GPIO_PORTX_SPACING
);
371 /* Mask out this pin*/
372 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((gpio
& 0x07) << 1));
373 /* This is not needed since it sets the bits to zero.*/
374 /* val |= (U300_GPIO_PXPCR_PIN_MODE_INPUT << (gpio*2)); */
375 writel(val
, virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
376 U300_GPIO_PORTX_SPACING
);
377 local_irq_restore(flags
);
380 EXPORT_SYMBOL(gpio_direction_input
);
382 int gpio_direction_output(unsigned gpio
, int value
)
387 if (gpio
> U300_GPIO_MAX
)
390 local_irq_save(flags
);
391 val
= readl(virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
392 U300_GPIO_PORTX_SPACING
);
393 /* Mask out this pin */
394 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((gpio
& 0x07) << 1));
396 * FIXME: configure for push/pull, open drain or open source per pin
397 * in setup. The current driver will only support push/pull.
399 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
400 << ((gpio
& 0x07) << 1));
401 writel(val
, virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
402 U300_GPIO_PORTX_SPACING
);
403 gpio_set_value(gpio
, value
);
404 local_irq_restore(flags
);
407 EXPORT_SYMBOL(gpio_direction_output
);
410 * Enable an IRQ, edge is rising edge (!= 0) or falling edge (==0).
412 void enable_irq_on_gpio_pin(unsigned gpio
, int edge
)
416 local_irq_save(flags
);
418 val
= readl(virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
419 U300_GPIO_PORTX_SPACING
);
420 val
|= (1 << (gpio
& 0x07));
421 writel(val
, virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
422 U300_GPIO_PORTX_SPACING
);
423 val
= readl(virtbase
+ U300_GPIO_PXICR
+ PIN_TO_PORT(gpio
) *
424 U300_GPIO_PORTX_SPACING
);
426 val
|= (1 << (gpio
& 0x07));
428 val
&= ~(1 << (gpio
& 0x07));
429 writel(val
, virtbase
+ U300_GPIO_PXICR
+ PIN_TO_PORT(gpio
) *
430 U300_GPIO_PORTX_SPACING
);
431 local_irq_restore(flags
);
433 EXPORT_SYMBOL(enable_irq_on_gpio_pin
);
435 void disable_irq_on_gpio_pin(unsigned gpio
)
440 local_irq_save(flags
);
441 val
= readl(virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
442 U300_GPIO_PORTX_SPACING
);
443 val
&= ~(1 << (gpio
& 0x07));
444 writel(val
, virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
445 U300_GPIO_PORTX_SPACING
);
446 local_irq_restore(flags
);
448 EXPORT_SYMBOL(disable_irq_on_gpio_pin
);
450 /* Enable (value == 0) or disable (value == 1) internal pullup */
451 void gpio_pullup(unsigned gpio
, int value
)
456 local_irq_save(flags
);
458 val
= readl(virtbase
+ U300_GPIO_PXPER
+ PIN_TO_PORT(gpio
) *
459 U300_GPIO_PORTX_SPACING
);
460 writel(val
| (1 << (gpio
& 0x07)), virtbase
+ U300_GPIO_PXPER
+
461 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
463 val
= readl(virtbase
+ U300_GPIO_PXPER
+ PIN_TO_PORT(gpio
) *
464 U300_GPIO_PORTX_SPACING
);
465 writel(val
& ~(1 << (gpio
& 0x07)), virtbase
+ U300_GPIO_PXPER
+
466 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
468 local_irq_restore(flags
);
470 EXPORT_SYMBOL(gpio_pullup
);
472 static irqreturn_t
gpio_irq_handler(int irq
, void *dev_id
)
474 struct u300_gpio_port
*port
= dev_id
;
478 /* Read event register */
479 val
= readl(virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
480 U300_GPIO_PORTX_SPACING
);
481 /* Mask with enable register */
482 val
&= readl(virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
483 U300_GPIO_PORTX_SPACING
);
484 /* Mask relevant bits */
485 val
&= U300_GPIO_PXIEV_ALL_IRQ_EVENT_MASK
;
486 /* ACK IRQ (clear event) */
487 writel(val
, virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
488 U300_GPIO_PORTX_SPACING
);
494 /* mask off this pin */
496 gpio
= (port
->number
<< 3) + pin
;
498 if (gpio_pin
[gpio
].callback
)
499 (void)gpio_pin
[gpio
].callback(gpio_pin
[gpio
].data
);
501 dev_dbg(gpiodev
, "stray GPIO IRQ on line %d\n",
507 static void gpio_set_initial_values(void)
509 #ifdef U300_COH901571_3
514 /* Write default values to all pins */
515 for (i
= 0; i
< U300_GPIO_NUM_PORTS
; i
++) {
517 for (j
= 0; j
< 8; j
++)
518 val
|= (u32
) (u300_gpio_config
[i
][j
].default_output_value
!= DEFAULT_OUTPUT_LOW
) << j
;
519 local_irq_save(flags
);
520 writel(val
, virtbase
+ U300_GPIO_PXPDOR
+ i
* U300_GPIO_PORTX_SPACING
);
521 local_irq_restore(flags
);
525 * Put all pins that are set to either 'GPIO_OUT' or 'GPIO_NOT_USED'
526 * to output and 'GPIO_IN' to input for each port. And initialize
527 * default value on outputs.
529 for (i
= 0; i
< U300_GPIO_NUM_PORTS
; i
++) {
530 for (j
= 0; j
< U300_GPIO_PINS_PER_PORT
; j
++) {
531 local_irq_save(flags
);
532 val
= readl(virtbase
+ U300_GPIO_PXPCR
+
533 i
* U300_GPIO_PORTX_SPACING
);
534 /* Mask out this pin */
535 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< (j
<< 1));
537 if (u300_gpio_config
[i
][j
].pin_usage
!= GPIO_IN
)
538 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
<< (j
<< 1));
539 writel(val
, virtbase
+ U300_GPIO_PXPCR
+
540 i
* U300_GPIO_PORTX_SPACING
);
541 local_irq_restore(flags
);
545 /* Enable or disable the internal pull-ups in the GPIO ASIC block */
546 for (i
= 0; i
< U300_GPIO_MAX
; i
++) {
548 for (j
= 0; j
< 8; j
++)
549 val
|= (u32
)((u300_gpio_config
[i
][j
].pull_up
== DISABLE_PULL_UP
) << j
);
550 local_irq_save(flags
);
551 writel(val
, virtbase
+ U300_GPIO_PXPER
+ i
* U300_GPIO_PORTX_SPACING
);
552 local_irq_restore(flags
);
557 static int __init
gpio_probe(struct platform_device
*pdev
)
564 gpiodev
= &pdev
->dev
;
565 memset(gpio_pin
, 0, sizeof(gpio_pin
));
568 clk
= clk_get(&pdev
->dev
, NULL
);
571 dev_err(gpiodev
, "could not get GPIO clock\n");
574 err
= clk_enable(clk
);
576 dev_err(gpiodev
, "could not enable GPIO clock\n");
577 goto err_no_clk_enable
;
580 memres
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
582 goto err_no_resource
;
584 if (request_mem_region(memres
->start
, memres
->end
- memres
->start
, "GPIO Controller")
587 goto err_no_ioregion
;
590 virtbase
= ioremap(memres
->start
, resource_size(memres
));
595 dev_info(gpiodev
, "remapped 0x%08x to %p\n",
596 memres
->start
, virtbase
);
598 #ifdef U300_COH901335
599 dev_info(gpiodev
, "initializing GPIO Controller COH 901 335\n");
600 /* Turn on the GPIO block */
601 writel(U300_GPIO_CR_BLOCK_CLOCK_ENABLE
, virtbase
+ U300_GPIO_CR
);
604 #ifdef U300_COH901571_3
605 dev_info(gpiodev
, "initializing GPIO Controller COH 901 571/3\n");
606 val
= readl(virtbase
+ U300_GPIO_CR
);
607 dev_info(gpiodev
, "COH901571/3 block version: %d, " \
608 "number of cores: %d\n",
609 ((val
& 0x0000FE00) >> 9),
610 ((val
& 0x000001FC) >> 2));
611 writel(U300_GPIO_CR_BLOCK_CLKRQ_ENABLE
, virtbase
+ U300_GPIO_CR
);
614 gpio_set_initial_values();
616 for (num_irqs
= 0 ; num_irqs
< U300_GPIO_NUM_PORTS
; num_irqs
++) {
618 gpio_ports
[num_irqs
].irq
=
619 platform_get_irq_byname(pdev
,
620 gpio_ports
[num_irqs
].name
);
622 err
= request_irq(gpio_ports
[num_irqs
].irq
,
623 gpio_irq_handler
, IRQF_DISABLED
,
624 gpio_ports
[num_irqs
].name
,
625 &gpio_ports
[num_irqs
]);
627 dev_err(gpiodev
, "cannot allocate IRQ for %s!\n",
628 gpio_ports
[num_irqs
].name
);
631 /* Turns off PortX_irq_force */
632 writel(0x0, virtbase
+ U300_GPIO_PXIFR
+
633 num_irqs
* U300_GPIO_PORTX_SPACING
);
639 for (i
= 0; i
< num_irqs
; i
++)
640 free_irq(gpio_ports
[i
].irq
, &gpio_ports
[i
]);
643 release_mem_region(memres
->start
, memres
->end
- memres
->start
);
650 dev_info(gpiodev
, "module ERROR:%d\n", err
);
654 static int __exit
gpio_remove(struct platform_device
*pdev
)
658 /* Turn off the GPIO block */
659 writel(0x00000000U
, virtbase
+ U300_GPIO_CR
);
660 for (i
= 0 ; i
< U300_GPIO_NUM_PORTS
; i
++)
661 free_irq(gpio_ports
[i
].irq
, &gpio_ports
[i
]);
663 release_mem_region(memres
->start
, memres
->end
- memres
->start
);
669 static struct platform_driver gpio_driver
= {
673 .remove
= __exit_p(gpio_remove
),
677 static int __init
u300_gpio_init(void)
679 return platform_driver_probe(&gpio_driver
, gpio_probe
);
682 static void __exit
u300_gpio_exit(void)
684 platform_driver_unregister(&gpio_driver
);
687 arch_initcall(u300_gpio_init
);
688 module_exit(u300_gpio_exit
);
690 MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
692 #ifdef U300_COH901571_3
693 MODULE_DESCRIPTION("ST-Ericsson AB COH 901 571/3 GPIO driver");
696 #ifdef U300_COH901335
697 MODULE_DESCRIPTION("ST-Ericsson AB COH 901 335 GPIO driver");
700 MODULE_LICENSE("GPL");