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 /* Need access to SYSCON registers for PADmuxing */
29 #include <mach/syscon.h>
33 /* Reference to GPIO block clock */
34 static struct clk
*clk
;
37 static struct resource
*memres
;
38 static void __iomem
*virtbase
;
39 static struct device
*gpiodev
;
41 struct u300_gpio_port
{
48 static struct u300_gpio_port gpio_ports
[] = {
61 #ifdef U300_COH901571_3
70 #ifdef CONFIG_MACH_U300_BS335
85 #ifdef U300_COH901571_3
87 /* Default input value */
88 #define DEFAULT_OUTPUT_LOW 0
89 #define DEFAULT_OUTPUT_HIGH 1
91 /* GPIO Pull-Up status */
92 #define DISABLE_PULL_UP 0
93 #define ENABLE_PULL_UP 1
95 #define GPIO_NOT_USED 0
99 struct u300_gpio_configuration_data
{
100 unsigned char pin_usage
;
101 unsigned char default_output_value
;
102 unsigned char pull_up
;
105 /* Initial configuration */
106 const struct u300_gpio_configuration_data
107 u300_gpio_config
[U300_GPIO_NUM_PORTS
][U300_GPIO_PINS_PER_PORT
] = {
108 #ifdef CONFIG_MACH_U300_BS335
109 /* Port 0, pins 0-7 */
111 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
112 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
113 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
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_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
118 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
120 /* Port 1, pins 0-7 */
122 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
123 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
124 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
125 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
126 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
127 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
128 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
129 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
131 /* Port 2, pins 0-7 */
133 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
134 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
135 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
136 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
137 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
138 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
139 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
140 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
142 /* Port 3, pins 0-7 */
144 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
145 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
146 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
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
}
153 /* Port 4, pins 0-7 */
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
},
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
}
164 /* Port 5, pins 0-7 */
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
},
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
}
175 /* Port 6, pind 0-7 */
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
},
180 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
181 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
182 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
183 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
184 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
188 #ifdef CONFIG_MACH_U300_BS365
189 /* Port 0, pins 0-7 */
191 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
192 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
193 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
194 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
195 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
196 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
197 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
198 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
200 /* Port 1, pins 0-7 */
202 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
203 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
204 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
205 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
206 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
207 {GPIO_OUT
, DEFAULT_OUTPUT_HIGH
, DISABLE_PULL_UP
},
208 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
209 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
}
211 /* Port 2, pins 0-7 */
213 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
214 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
215 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_PULL_UP
},
216 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, DISABLE_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
}
222 /* Port 3, pins 0-7 */
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
},
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 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
233 /* Port 4, pins 0-7 */
235 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
236 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
237 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
238 {GPIO_IN
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
239 /* These 4 pins doesn't exist on DB3210 */
240 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
241 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
242 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
},
243 {GPIO_OUT
, DEFAULT_OUTPUT_LOW
, ENABLE_PULL_UP
}
250 /* No users == we can power down GPIO */
251 static int gpio_users
;
254 int (*callback
)(void *);
259 static struct gpio_struct gpio_pin
[U300_GPIO_MAX
];
262 * Let drivers register callback in order to get notified when there is
263 * an interrupt on the gpio pin
265 int gpio_register_callback(unsigned gpio
, int (*func
)(void *arg
), void *data
)
267 if (gpio_pin
[gpio
].callback
)
268 dev_warn(gpiodev
, "%s: WARNING: callback already "
269 "registered for gpio pin#%d\n", __func__
, gpio
);
270 gpio_pin
[gpio
].callback
= func
;
271 gpio_pin
[gpio
].data
= data
;
275 EXPORT_SYMBOL(gpio_register_callback
);
277 int gpio_unregister_callback(unsigned gpio
)
279 if (!gpio_pin
[gpio
].callback
)
280 dev_warn(gpiodev
, "%s: WARNING: callback already "
281 "unregistered for gpio pin#%d\n", __func__
, gpio
);
282 gpio_pin
[gpio
].callback
= NULL
;
283 gpio_pin
[gpio
].data
= NULL
;
287 EXPORT_SYMBOL(gpio_unregister_callback
);
289 int gpio_request(unsigned gpio
, const char *label
)
291 if (gpio_pin
[gpio
].users
)
294 gpio_pin
[gpio
].users
++;
300 EXPORT_SYMBOL(gpio_request
);
302 void gpio_free(unsigned gpio
)
305 gpio_pin
[gpio
].users
--;
306 if (unlikely(gpio_pin
[gpio
].users
< 0)) {
307 dev_warn(gpiodev
, "warning: gpio#%d release mismatch\n",
309 gpio_pin
[gpio
].users
= 0;
314 EXPORT_SYMBOL(gpio_free
);
316 /* This returns zero or nonzero */
317 int gpio_get_value(unsigned gpio
)
319 return readl(virtbase
+ U300_GPIO_PXPDIR
+
320 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
) & (1 << (gpio
& 0x07));
322 EXPORT_SYMBOL(gpio_get_value
);
325 * We hope that the compiler will optimize away the unused branch
326 * in case "value" is a constant
328 void gpio_set_value(unsigned gpio
, int value
)
333 local_irq_save(flags
);
336 val
= readl(virtbase
+ U300_GPIO_PXPDOR
+
337 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
)
338 & (1 << (gpio
& 0x07));
339 writel(val
| (1 << (gpio
& 0x07)), virtbase
+
341 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
344 val
= readl(virtbase
+ U300_GPIO_PXPDOR
+
345 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
)
346 & (1 << (gpio
& 0x07));
347 writel(val
& ~(1 << (gpio
& 0x07)), virtbase
+
349 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
351 local_irq_restore(flags
);
353 EXPORT_SYMBOL(gpio_set_value
);
355 int gpio_direction_input(unsigned gpio
)
360 if (gpio
> U300_GPIO_MAX
)
363 local_irq_save(flags
);
364 val
= readl(virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
365 U300_GPIO_PORTX_SPACING
);
366 /* Mask out this pin*/
367 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((gpio
& 0x07) << 1));
368 /* This is not needed since it sets the bits to zero.*/
369 /* val |= (U300_GPIO_PXPCR_PIN_MODE_INPUT << (gpio*2)); */
370 writel(val
, virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
371 U300_GPIO_PORTX_SPACING
);
372 local_irq_restore(flags
);
375 EXPORT_SYMBOL(gpio_direction_input
);
377 int gpio_direction_output(unsigned gpio
, int value
)
382 if (gpio
> U300_GPIO_MAX
)
385 local_irq_save(flags
);
386 val
= readl(virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
387 U300_GPIO_PORTX_SPACING
);
388 /* Mask out this pin */
389 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((gpio
& 0x07) << 1));
391 * FIXME: configure for push/pull, open drain or open source per pin
392 * in setup. The current driver will only support push/pull.
394 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
395 << ((gpio
& 0x07) << 1));
396 writel(val
, virtbase
+ U300_GPIO_PXPCR
+ PIN_TO_PORT(gpio
) *
397 U300_GPIO_PORTX_SPACING
);
398 gpio_set_value(gpio
, value
);
399 local_irq_restore(flags
);
402 EXPORT_SYMBOL(gpio_direction_output
);
405 * Enable an IRQ, edge is rising edge (!= 0) or falling edge (==0).
407 void enable_irq_on_gpio_pin(unsigned gpio
, int edge
)
411 local_irq_save(flags
);
413 val
= readl(virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
414 U300_GPIO_PORTX_SPACING
);
415 val
|= (1 << (gpio
& 0x07));
416 writel(val
, virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
417 U300_GPIO_PORTX_SPACING
);
418 val
= readl(virtbase
+ U300_GPIO_PXICR
+ PIN_TO_PORT(gpio
) *
419 U300_GPIO_PORTX_SPACING
);
421 val
|= (1 << (gpio
& 0x07));
423 val
&= ~(1 << (gpio
& 0x07));
424 writel(val
, virtbase
+ U300_GPIO_PXICR
+ PIN_TO_PORT(gpio
) *
425 U300_GPIO_PORTX_SPACING
);
426 local_irq_restore(flags
);
428 EXPORT_SYMBOL(enable_irq_on_gpio_pin
);
430 void disable_irq_on_gpio_pin(unsigned gpio
)
435 local_irq_save(flags
);
436 val
= readl(virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
437 U300_GPIO_PORTX_SPACING
);
438 val
&= ~(1 << (gpio
& 0x07));
439 writel(val
, virtbase
+ U300_GPIO_PXIEN
+ PIN_TO_PORT(gpio
) *
440 U300_GPIO_PORTX_SPACING
);
441 local_irq_restore(flags
);
443 EXPORT_SYMBOL(disable_irq_on_gpio_pin
);
445 /* Enable (value == 0) or disable (value == 1) internal pullup */
446 void gpio_pullup(unsigned gpio
, int value
)
451 local_irq_save(flags
);
453 val
= readl(virtbase
+ U300_GPIO_PXPER
+ PIN_TO_PORT(gpio
) *
454 U300_GPIO_PORTX_SPACING
);
455 writel(val
| (1 << (gpio
& 0x07)), virtbase
+ U300_GPIO_PXPER
+
456 PIN_TO_PORT(gpio
) * U300_GPIO_PORTX_SPACING
);
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 local_irq_restore(flags
);
465 EXPORT_SYMBOL(gpio_pullup
);
467 static irqreturn_t
gpio_irq_handler(int irq
, void *dev_id
)
469 struct u300_gpio_port
*port
= dev_id
;
473 /* Read event register */
474 val
= readl(virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
475 U300_GPIO_PORTX_SPACING
);
476 /* Mask with enable register */
477 val
&= readl(virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
478 U300_GPIO_PORTX_SPACING
);
479 /* Mask relevant bits */
480 val
&= U300_GPIO_PXIEV_ALL_IRQ_EVENT_MASK
;
481 /* ACK IRQ (clear event) */
482 writel(val
, virtbase
+ U300_GPIO_PXIEV
+ port
->number
*
483 U300_GPIO_PORTX_SPACING
);
489 /* mask off this pin */
491 gpio
= (port
->number
<< 3) + pin
;
493 if (gpio_pin
[gpio
].callback
)
494 (void)gpio_pin
[gpio
].callback(gpio_pin
[gpio
].data
);
496 dev_dbg(gpiodev
, "stray GPIO IRQ on line %d\n",
502 static void gpio_set_initial_values(void)
504 #ifdef U300_COH901571_3
509 /* Write default values to all pins */
510 for (i
= 0; i
< U300_GPIO_NUM_PORTS
; i
++) {
512 for (j
= 0; j
< 8; j
++)
513 val
|= (u32
) (u300_gpio_config
[i
][j
].default_output_value
!= DEFAULT_OUTPUT_LOW
) << j
;
514 local_irq_save(flags
);
515 writel(val
, virtbase
+ U300_GPIO_PXPDOR
+ i
* U300_GPIO_PORTX_SPACING
);
516 local_irq_restore(flags
);
520 * Put all pins that are set to either 'GPIO_OUT' or 'GPIO_NOT_USED'
521 * to output and 'GPIO_IN' to input for each port. And initalize
522 * default value on outputs.
524 for (i
= 0; i
< U300_GPIO_NUM_PORTS
; i
++) {
525 for (j
= 0; j
< U300_GPIO_PINS_PER_PORT
; j
++) {
526 local_irq_save(flags
);
527 val
= readl(virtbase
+ U300_GPIO_PXPCR
+
528 i
* U300_GPIO_PORTX_SPACING
);
529 /* Mask out this pin */
530 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< (j
<< 1));
532 if (u300_gpio_config
[i
][j
].pin_usage
!= GPIO_IN
)
533 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
<< (j
<< 1));
534 writel(val
, virtbase
+ U300_GPIO_PXPCR
+
535 i
* U300_GPIO_PORTX_SPACING
);
536 local_irq_restore(flags
);
540 /* Enable or disable the internal pull-ups in the GPIO ASIC block */
541 for (i
= 0; i
< U300_GPIO_MAX
; i
++) {
543 for (j
= 0; j
< 8; j
++)
544 val
|= (u32
)((u300_gpio_config
[i
][j
].pull_up
== DISABLE_PULL_UP
)) << j
;
545 local_irq_save(flags
);
546 writel(val
, virtbase
+ U300_GPIO_PXPER
+ i
* U300_GPIO_PORTX_SPACING
);
547 local_irq_restore(flags
);
552 static int __init
gpio_probe(struct platform_device
*pdev
)
559 gpiodev
= &pdev
->dev
;
560 memset(gpio_pin
, 0, sizeof(gpio_pin
));
563 clk
= clk_get(&pdev
->dev
, NULL
);
566 dev_err(gpiodev
, "could not get GPIO clock\n");
569 err
= clk_enable(clk
);
571 dev_err(gpiodev
, "could not enable GPIO clock\n");
572 goto err_no_clk_enable
;
575 memres
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
577 goto err_no_resource
;
579 if (request_mem_region(memres
->start
, memres
->end
- memres
->start
, "GPIO Controller")
582 goto err_no_ioregion
;
585 virtbase
= ioremap(memres
->start
, resource_size(memres
));
590 dev_info(gpiodev
, "remapped 0x%08x to %p\n",
591 memres
->start
, virtbase
);
593 #ifdef U300_COH901335
594 dev_info(gpiodev
, "initializing GPIO Controller COH 901 335\n");
595 /* Turn on the GPIO block */
596 writel(U300_GPIO_CR_BLOCK_CLOCK_ENABLE
, virtbase
+ U300_GPIO_CR
);
599 #ifdef U300_COH901571_3
600 dev_info(gpiodev
, "initializing GPIO Controller COH 901 571/3\n");
601 val
= readl(virtbase
+ U300_GPIO_CR
);
602 dev_info(gpiodev
, "COH901571/3 block version: %d, " \
603 "number of cores: %d\n",
604 ((val
& 0x0000FE00) >> 9),
605 ((val
& 0x000001FC) >> 2));
606 writel(U300_GPIO_CR_BLOCK_CLKRQ_ENABLE
, virtbase
+ U300_GPIO_CR
);
609 /* Set up some padmuxing here */
611 pmx_set_mission_mode_mmc();
613 #ifdef CONFIG_SPI_PL022
614 pmx_set_mission_mode_spi();
617 gpio_set_initial_values();
619 for (num_irqs
= 0 ; num_irqs
< U300_GPIO_NUM_PORTS
; num_irqs
++) {
621 gpio_ports
[num_irqs
].irq
=
622 platform_get_irq_byname(pdev
,
623 gpio_ports
[num_irqs
].name
);
625 err
= request_irq(gpio_ports
[num_irqs
].irq
,
626 gpio_irq_handler
, IRQF_DISABLED
,
627 gpio_ports
[num_irqs
].name
,
628 &gpio_ports
[num_irqs
]);
630 dev_err(gpiodev
, "cannot allocate IRQ for %s!\n",
631 gpio_ports
[num_irqs
].name
);
634 /* Turns off PortX_irq_force */
635 writel(0x0, virtbase
+ U300_GPIO_PXIFR
+
636 num_irqs
* U300_GPIO_PORTX_SPACING
);
642 for (i
= 0; i
< num_irqs
; i
++)
643 free_irq(gpio_ports
[i
].irq
, &gpio_ports
[i
]);
646 release_mem_region(memres
->start
, memres
->end
- memres
->start
);
653 dev_info(gpiodev
, "module ERROR:%d\n", err
);
657 static int __exit
gpio_remove(struct platform_device
*pdev
)
661 /* Turn off the GPIO block */
662 writel(0x00000000U
, virtbase
+ U300_GPIO_CR
);
663 for (i
= 0 ; i
< U300_GPIO_NUM_PORTS
; i
++)
664 free_irq(gpio_ports
[i
].irq
, &gpio_ports
[i
]);
666 release_mem_region(memres
->start
, memres
->end
- memres
->start
);
672 static struct platform_driver gpio_driver
= {
676 .remove
= __exit_p(gpio_remove
),
680 static int __init
u300_gpio_init(void)
682 return platform_driver_probe(&gpio_driver
, gpio_probe
);
685 static void __exit
u300_gpio_exit(void)
687 platform_driver_unregister(&gpio_driver
);
690 arch_initcall(u300_gpio_init
);
691 module_exit(u300_gpio_exit
);
693 MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
695 #ifdef U300_COH901571_3
696 MODULE_DESCRIPTION("ST-Ericsson AB COH 901 571/3 GPIO driver");
699 #ifdef U300_COH901335
700 MODULE_DESCRIPTION("ST-Ericsson AB COH 901 335 GPIO driver");
703 MODULE_LICENSE("GPL");