19 #include <linux/kernel.h>
22 #include <linux/errno.h>
26 #include <linux/module.h>
28 #include <mach/hardware.h>
29 #include <mach/platform.h>
31 #include <mach/irqs.h>
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)
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)
84 "p0.0",
"p0.1",
"p0.2",
"p0.3",
85 "p0.4",
"p0.5",
"p0.6",
"p0.7"
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",
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",
105 "gpio00",
"gpio01",
"gpio02",
"gpio03",
110 "gpi00",
"gpi01",
"gpi02",
"gpi03",
111 "gpi04",
"gpi05",
"gpi06",
"gpi07",
114 "gpi16",
"gpi17",
"gpi18",
"gpi19",
115 "gpi20",
"gpi21",
"gpi22",
"gpi23",
116 "gpi24",
"gpi25",
"gpi26",
"gpi27",
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"
129 static struct gpio_regs gpio_grp_regs_p0 = {
137 static struct gpio_regs gpio_grp_regs_p1 = {
145 static struct gpio_regs gpio_grp_regs_p2 = {
153 static struct gpio_regs gpio_grp_regs_p3 = {
168 struct gpio_chip *gpc)
185 unsigned pin,
int input)
196 unsigned pin,
int high)
207 unsigned pin,
int high)
218 unsigned pin,
int high)
260 static int lpc32xx_gpio_dir_input_p012(
struct gpio_chip *
chip,
265 __set_gpio_dir_p012(group, pin, 1);
270 static int lpc32xx_gpio_dir_input_p3(
struct gpio_chip *
chip,
275 __set_gpio_dir_p3(group, pin, 1);
280 static int lpc32xx_gpio_dir_in_always(
struct gpio_chip *
chip,
286 static int lpc32xx_gpio_get_value_p012(
struct gpio_chip *
chip,
unsigned pin)
290 return __get_gpio_state_p012(group, pin);
293 static int lpc32xx_gpio_get_value_p3(
struct gpio_chip *
chip,
unsigned pin)
297 return __get_gpio_state_p3(group, pin);
300 static int lpc32xx_gpi_get_value(
struct gpio_chip *
chip,
unsigned pin)
304 return __get_gpi_state_p3(group, pin);
307 static int lpc32xx_gpio_dir_output_p012(
struct gpio_chip *
chip,
unsigned pin,
312 __set_gpio_level_p012(group, pin, value);
313 __set_gpio_dir_p012(group, pin, 0);
318 static int lpc32xx_gpio_dir_output_p3(
struct gpio_chip *
chip,
unsigned pin,
323 __set_gpio_level_p3(group, pin, value);
324 __set_gpio_dir_p3(group, pin, 0);
329 static int lpc32xx_gpio_dir_out_always(
struct gpio_chip *
chip,
unsigned pin,
334 __set_gpo_level_p3(group, pin, value);
338 static void lpc32xx_gpio_set_value_p012(
struct gpio_chip *
chip,
unsigned pin,
343 __set_gpio_level_p012(group, pin, value);
346 static void lpc32xx_gpio_set_value_p3(
struct gpio_chip *
chip,
unsigned pin,
351 __set_gpio_level_p3(group, pin, value);
354 static void lpc32xx_gpo_set_value(
struct gpio_chip *
chip,
unsigned pin,
359 __set_gpo_level_p3(group, pin, value);
362 static int lpc32xx_gpo_get_value(
struct gpio_chip *
chip,
unsigned pin)
366 return __get_gpo_state_p3(group, pin);
369 static int lpc32xx_gpio_request(
struct gpio_chip *
chip,
unsigned pin)
371 if (pin < chip->ngpio)
377 static int lpc32xx_gpio_to_irq_p01(
struct gpio_chip *chip,
unsigned offset)
382 static const char lpc32xx_gpio_to_irq_gpio_p3_table[] = {
391 static int lpc32xx_gpio_to_irq_gpio_p3(
struct gpio_chip *chip,
unsigned offset)
393 if (offset <
ARRAY_SIZE(lpc32xx_gpio_to_irq_gpio_p3_table))
394 return lpc32xx_gpio_to_irq_gpio_p3_table[
offset];
398 static const char lpc32xx_gpio_to_irq_gpi_p3_table[] = {
430 static int lpc32xx_gpio_to_irq_gpi_p3(
struct gpio_chip *chip,
unsigned offset)
432 if (offset <
ARRAY_SIZE(lpc32xx_gpio_to_irq_gpi_p3_table))
433 return lpc32xx_gpio_to_irq_gpi_p3_table[
offset];
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,
449 .names = gpio_p0_names,
452 .gpio_grp = &gpio_grp_regs_p0,
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,
465 .names = gpio_p1_names,
468 .gpio_grp = &gpio_grp_regs_p1,
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,
480 .names = gpio_p2_names,
483 .gpio_grp = &gpio_grp_regs_p2,
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,
496 .names = gpio_p3_names,
499 .gpio_grp = &gpio_grp_regs_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,
510 .names = gpi_p3_names,
513 .gpio_grp = &gpio_grp_regs_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,
524 .names = gpo_p3_names,
527 .gpio_grp = &gpio_grp_regs_p3,
531 static int lpc32xx_of_xlate(
struct gpio_chip *
gc,
537 (gc != &lpc32xx_gpiochip[bank].chip)))
541 *flags = gpiospec->
args[2];
542 return gpiospec->
args[1];
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;
563 { .compatible =
"nxp,lpc3220-gpio", },
570 .name =
"lpc32xx-gpio",
574 .probe = lpc32xx_gpio_probe,