4 * Copyright (C) 2007-2009 ST-Ericsson AB
5 * License terms: GNU General Public License (GPL) version 2
6 * This can driver either of the two basic GPIO cores
7 * available in the U300 platforms:
8 * COH 901 335 - Used in DB3150 (U300 1.0) and DB3200 (U330 1.0)
9 * COH 901 571/3 - Used in DB3210 (U365 2.0) and DB3350 (U335 1.0)
10 * Notice that you also have inline macros in <asm-arch/gpio.h>
11 * Author: Linus Walleij <linus.walleij@stericsson.com>
12 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
15 #include <linux/module.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <linux/errno.h>
20 #include <linux/clk.h>
21 #include <linux/err.h>
22 #include <linux/platform_device.h>
23 #include <linux/gpio.h>
25 /* Reference to GPIO block clock */
26 static struct clk
*clk
;
29 static struct resource
*memres
;
30 static void __iomem
*virtbase
;
31 static struct device
*gpiodev
;
33 struct u300_gpio_port
{
40 static struct u300_gpio_port gpio_ports
[] = {
53 #ifdef U300_COH901571_3
62 #ifdef CONFIG_MACH_U300_BS335
77 #ifdef U300_COH901571_3
79 /* Default input value */
80 #define DEFAULT_OUTPUT_LOW 0
81 #define DEFAULT_OUTPUT_HIGH 1
83 /* GPIO Pull-Up status */
84 #define DISABLE_PULL_UP 0
85 #define ENABLE_PULL_UP 1
87 #define GPIO_NOT_USED 0
91 struct u300_gpio_configuration_data
{
92 unsigned char pin_usage
;
93 unsigned char default_output_value
;
94 unsigned char pull_up
;
97 /* Initial configuration */
98 const struct u300_gpio_configuration_data
99 u300_gpio_config
[U300_GPIO_NUM_PORTS
][U300_GPIO_PINS_PER_PORT
] = {
100 #ifdef CONFIG_MACH_U300_BS335
101 /* Port 0, pins 0-7 */
103 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
104 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
105 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
106 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
107 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
108 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
109 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
110 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
112 /* Port 1, pins 0-7 */
114 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
115 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
116 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
117 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
118 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
119 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
120 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
121 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
123 /* Port 2, pins 0-7 */
125 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
126 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
127 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
128 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
129 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
130 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
131 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
132 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
134 /* Port 3, pins 0-7 */
136 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
137 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
138 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
139 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
140 {GPIO_IN
, 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
}
145 /* Port 4, pins 0-7 */
147 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
148 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
149 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
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
}
156 /* Port 5, pins 0-7 */
158 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
159 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
160 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
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
}
167 /* Port 6, pind 0-7 */
169 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
170 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
171 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
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
}
180 #ifdef CONFIG_MACH_U300_BS365
181 /* Port 0, pins 0-7 */
183 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
184 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
185 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
186 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
187 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
188 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
189 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
190 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
192 /* Port 1, pins 0-7 */
194 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
195 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
196 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
197 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
198 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
199 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
200 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
201 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
203 /* Port 2, pins 0-7 */
205 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
206 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
207 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
208 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
209 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
210 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
211 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
212 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
214 /* Port 3, pins 0-7 */
216 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
217 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
218 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
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
}
225 /* Port 4, pins 0-7 */
227 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
228 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
229 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
230 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
231 /* These 4 pins doesn't exist on DB3210 */
232 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
233 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
234 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
235 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
242 /* No users == we can power down GPIO */
243 static int gpio_users
;
246 int (*callback
)(void *);
251 static struct gpio_struct gpio_pin
[U300_GPIO_MAX
];
254 * Let drivers register callback in order to get notified when there is
255 * an interrupt on the gpio pin
257 int gpio_register_callback(unsigned gpio
, int (*func
)(void *arg
), void *data
)
259 if (gpio_pin
[gpio
].callback
)
260 dev_warn(gpiodev
, "%s: WARNING: callback already "
261 "registered for gpio pin#%d\n", __func__
, gpio
);
262 gpio_pin
[gpio
].callback
= func
;
263 gpio_pin
[gpio
].data
= data
;
267 EXPORT_SYMBOL(gpio_register_callback
);
269 int gpio_unregister_callback(unsigned gpio
)
271 if (!gpio_pin
[gpio
].callback
)
272 dev_warn(gpiodev
, "%s: WARNING: callback already "
273 "unregistered for gpio pin#%d\n", __func__
, gpio
);
274 gpio_pin
[gpio
].callback
= NULL
;
275 gpio_pin
[gpio
].data
= NULL
;
279 EXPORT_SYMBOL(gpio_unregister_callback
);
281 /* Non-zero means valid */
282 int gpio_is_valid(int number
)
285 number
< (U300_GPIO_NUM_PORTS
* U300_GPIO_PINS_PER_PORT
))
289 EXPORT_SYMBOL(gpio_is_valid
);
291 int gpio_request(unsigned gpio
, const char *label
)
293 if (gpio_pin
[gpio
].users
)
296 gpio_pin
[gpio
].users
++;
302 EXPORT_SYMBOL(gpio_request
);
304 void gpio_free(unsigned gpio
)
307 gpio_pin
[gpio
].users
--;
308 if (unlikely(gpio_pin
[gpio
].users
< 0)) {
309 dev_warn(gpiodev
, "warning: gpio#%d release mismatch\n",
311 gpio_pin
[gpio
].users
= 0;
316 EXPORT_SYMBOL(gpio_free
);
318 /* This returns zero or nonzero */
319 int gpio_get_value(unsigned gpio
)
321 return readl(virtbase
+ U300_GPIO_PXPDIR
+
322 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
) & (1 << (gpio
& 0x07));
324 EXPORT_SYMBOL(gpio_get_value
);
327 * We hope that the compiler will optimize away the unused branch
328 * in case "value" is a constant
330 void gpio_set_value(unsigned gpio
, int value
)
335 local_irq_save(flags
);
338 val
= readl(virtbase
+ U300_GPIO_PXPDOR
+
339 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
)
340 & (1 << (gpio
& 0x07));
341 writel(val
| (1 << (gpio
& 0x07)), virtbase
+
343 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
346 val
= readl(virtbase
+ U300_GPIO_PXPDOR
+
347 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
)
348 & (1 << (gpio
& 0x07));
349 writel(val
& ~(1 << (gpio
& 0x07)), virtbase
+
351 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
353 local_irq_restore(flags
);
355 EXPORT_SYMBOL(gpio_set_value
);
357 int gpio_direction_input(unsigned gpio
)
362 if (gpio
> U300_GPIO_MAX
)
365 local_irq_save(flags
);
366 val
= readl(virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
367 U300_GPIO_PORTX_SPACING
);
368 /* Mask out this pin*/
369 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((gpio
& 0x07) << 1));
370 /* This is not needed since it sets the bits to zero.*/
371 /* val |= (U300_GPIO_PXPCR_PIN_MODE_INPUT << (gpio*2)); */
372 writel(val
, virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
373 U300_GPIO_PORTX_SPACING
);
374 local_irq_restore(flags
);
377 EXPORT_SYMBOL(gpio_direction_input
);
379 int gpio_direction_output(unsigned gpio
, int value
)
384 if (gpio
> U300_GPIO_MAX
)
387 local_irq_save(flags
);
388 val
= readl(virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
389 U300_GPIO_PORTX_SPACING
);
390 /* Mask out this pin */
391 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((gpio
& 0x07) << 1));
393 * FIXME: configure for push/pull, open drain or open source per pin
394 * in setup. The current driver will only support push/pull.
396 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
397 << ((gpio
& 0x07) << 1));
398 writel(val
, virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
399 U300_GPIO_PORTX_SPACING
);
400 gpio_set_value(gpio
, value
);
401 local_irq_restore(flags
);
404 EXPORT_SYMBOL(gpio_direction_output
);
407 * Enable an IRQ, edge is rising edge (!= 0) or falling edge (==0).
409 void enable_irq_on_gpio_pin(unsigned gpio
, int edge
)
413 local_irq_save(flags
);
415 val
= readl(virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
416 U300_GPIO_PORTX_SPACING
);
417 val
|= (1 << (gpio
& 0x07));
418 writel(val
, virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
419 U300_GPIO_PORTX_SPACING
);
420 val
= readl(virtbase
+ U300_GPIO_PXICR
+ PIN_TO_PORT(gpio
) *
421 U300_GPIO_PORTX_SPACING
);
423 val
|= (1 << (gpio
& 0x07));
425 val
&= ~(1 << (gpio
& 0x07));
426 writel(val
, virtbase
+ U300_GPIO_PXICR
+ PIN_TO_PORT(gpio
) *
427 U300_GPIO_PORTX_SPACING
);
428 local_irq_restore(flags
);
430 EXPORT_SYMBOL(enable_irq_on_gpio_pin
);
432 void disable_irq_on_gpio_pin(unsigned gpio
)
437 local_irq_save(flags
);
438 val
= readl(virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
439 U300_GPIO_PORTX_SPACING
);
440 val
&= ~(1 << (gpio
& 0x07));
441 writel(val
, virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
442 U300_GPIO_PORTX_SPACING
);
443 local_irq_restore(flags
);
445 EXPORT_SYMBOL(disable_irq_on_gpio_pin
);
447 /* Enable (value == 0) or disable (value == 1) internal pullup */
448 void gpio_pullup(unsigned gpio
, int value
)
453 local_irq_save(flags
);
455 val
= readl(virtbase
+ U300_GPIO_PXPER
+ PIN_TO_PORT(gpio
) *
456 U300_GPIO_PORTX_SPACING
);
457 writel(val
| (1 << (gpio
& 0x07)), virtbase
+ U300_GPIO_PXPER
+
458 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
460 val
= readl(virtbase
+ U300_GPIO_PXPER
+ PIN_TO_PORT(gpio
) *
461 U300_GPIO_PORTX_SPACING
);
462 writel(val
& ~(1 << (gpio
& 0x07)), virtbase
+ U300_GPIO_PXPER
+
463 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
465 local_irq_restore(flags
);
467 EXPORT_SYMBOL(gpio_pullup
);
469 static irqreturn_t
gpio_irq_handler(int irq
, void *dev_id
)
471 struct u300_gpio_port
*port
= dev_id
;
475 /* Read event register */
476 val
= readl(virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
477 U300_GPIO_PORTX_SPACING
);
478 /* Mask with enable register */
479 val
&= readl(virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
480 U300_GPIO_PORTX_SPACING
);
481 /* Mask relevant bits */
482 val
&= U300_GPIO_PXIEV_ALL_IRQ_EVENT_MASK
;
483 /* ACK IRQ (clear event) */
484 writel(val
, virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
485 U300_GPIO_PORTX_SPACING
);
491 /* mask off this pin */
493 gpio
= (port
->number
<< 3) + pin
;
495 if (gpio_pin
[gpio
].callback
)
496 (void)gpio_pin
[gpio
].callback(gpio_pin
[gpio
].data
);
498 dev_dbg(gpiodev
, "stray GPIO IRQ on line %d\n",
504 static void gpio_set_initial_values(void)
506 #ifdef U300_COH901571_3
511 /* Write default values to all pins */
512 for (i
= 0; i
< U300_GPIO_NUM_PORTS
; i
++) {
514 for (j
= 0; j
< 8; j
++)
515 val
|= (u32
) (u300_gpio_config
[i
][j
].default_output_value
!= DEFAULT_OUTPUT_LOW
) << j
;
516 local_irq_save(flags
);
517 writel(val
, virtbase
+ U300_GPIO_PXPDOR
+ i
* U300_GPIO_PORTX_SPACING
);
518 local_irq_restore(flags
);
522 * Put all pins that are set to either 'GPIO_OUT' or 'GPIO_NOT_USED'
523 * to output and 'GPIO_IN' to input for each port. And initialize
524 * default value on outputs.
526 for (i
= 0; i
< U300_GPIO_NUM_PORTS
; i
++) {
527 for (j
= 0; j
< U300_GPIO_PINS_PER_PORT
; j
++) {
528 local_irq_save(flags
);
529 val
= readl(virtbase
+ U300_GPIO_PXPCR
+
530 i
* U300_GPIO_PORTX_SPACING
);
531 /* Mask out this pin */
532 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< (j
<< 1));
534 if (u300_gpio_config
[i
][j
].pin_usage
!= GPIO_IN
)
535 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
<< (j
<< 1));
536 writel(val
, virtbase
+ U300_GPIO_PXPCR
+
537 i
* U300_GPIO_PORTX_SPACING
);
538 local_irq_restore(flags
);
542 /* Enable or disable the internal pull-ups in the GPIO ASIC block */
543 for (i
= 0; i
< U300_GPIO_MAX
; i
++) {
545 for (j
= 0; j
< 8; j
++)
546 val
|= (u32
)((u300_gpio_config
[i
][j
].pull_up
== DISABLE_PULL_UP
) << j
);
547 local_irq_save(flags
);
548 writel(val
, virtbase
+ U300_GPIO_PXPER
+ i
* U300_GPIO_PORTX_SPACING
);
549 local_irq_restore(flags
);
554 static int __init
gpio_probe(struct platform_device
*pdev
)
561 gpiodev
= &pdev
->dev
;
562 memset(gpio_pin
, 0, sizeof(gpio_pin
));
565 clk
= clk_get(&pdev
->dev
, NULL
);
568 dev_err(gpiodev
, "could not get GPIO clock\n");
571 err
= clk_enable(clk
);
573 dev_err(gpiodev
, "could not enable GPIO clock\n");
574 goto err_no_clk_enable
;
577 memres
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
579 goto err_no_resource
;
581 if (request_mem_region(memres
->start
, memres
->end
- memres
->start
, "GPIO Controller")
584 goto err_no_ioregion
;
587 virtbase
= ioremap(memres
->start
, resource_size(memres
));
592 dev_info(gpiodev
, "remapped 0x%08x to %p\n",
593 memres
->start
, virtbase
);
595 #ifdef U300_COH901335
596 dev_info(gpiodev
, "initializing GPIO Controller COH 901 335\n");
597 /* Turn on the GPIO block */
598 writel(U300_GPIO_CR_BLOCK_CLOCK_ENABLE
, virtbase
+ U300_GPIO_CR
);
601 #ifdef U300_COH901571_3
602 dev_info(gpiodev
, "initializing GPIO Controller COH 901 571/3\n");
603 val
= readl(virtbase
+ U300_GPIO_CR
);
604 dev_info(gpiodev
, "COH901571/3 block version: %d, " \
605 "number of cores: %d\n",
606 ((val
& 0x0000FE00) >> 9),
607 ((val
& 0x000001FC) >> 2));
608 writel(U300_GPIO_CR_BLOCK_CLKRQ_ENABLE
, virtbase
+ U300_GPIO_CR
);
611 gpio_set_initial_values();
613 for (num_irqs
= 0 ; num_irqs
< U300_GPIO_NUM_PORTS
; num_irqs
++) {
615 gpio_ports
[num_irqs
].irq
=
616 platform_get_irq_byname(pdev
,
617 gpio_ports
[num_irqs
].name
);
619 err
= request_irq(gpio_ports
[num_irqs
].irq
,
620 gpio_irq_handler
, IRQF_DISABLED
,
621 gpio_ports
[num_irqs
].name
,
622 &gpio_ports
[num_irqs
]);
624 dev_err(gpiodev
, "cannot allocate IRQ for %s!\n",
625 gpio_ports
[num_irqs
].name
);
628 /* Turns off PortX_irq_force */
629 writel(0x0, virtbase
+ U300_GPIO_PXIFR
+
630 num_irqs
* U300_GPIO_PORTX_SPACING
);
636 for (i
= 0; i
< num_irqs
; i
++)
637 free_irq(gpio_ports
[i
].irq
, &gpio_ports
[i
]);
640 release_mem_region(memres
->start
, memres
->end
- memres
->start
);
647 dev_info(gpiodev
, "module ERROR:%d\n", err
);
651 static int __exit
gpio_remove(struct platform_device
*pdev
)
655 /* Turn off the GPIO block */
656 writel(0x00000000U
, virtbase
+ U300_GPIO_CR
);
657 for (i
= 0 ; i
< U300_GPIO_NUM_PORTS
; i
++)
658 free_irq(gpio_ports
[i
].irq
, &gpio_ports
[i
]);
660 release_mem_region(memres
->start
, memres
->end
- memres
->start
);
666 static struct platform_driver gpio_driver
= {
670 .remove
= __exit_p(gpio_remove
),
674 static int __init
u300_gpio_init(void)
676 return platform_driver_probe(&gpio_driver
, gpio_probe
);
679 static void __exit
u300_gpio_exit(void)
681 platform_driver_unregister(&gpio_driver
);
684 arch_initcall(u300_gpio_init
);
685 module_exit(u300_gpio_exit
);
687 MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
689 #ifdef U300_COH901571_3
690 MODULE_DESCRIPTION("ST-Ericsson AB COH 901 571/3 GPIO driver");
693 #ifdef U300_COH901335
694 MODULE_DESCRIPTION("ST-Ericsson AB COH 901 335 GPIO driver");
697 MODULE_LICENSE("GPL");