29 #include <linux/slab.h>
33 #include <linux/module.h>
108 .edge_sel_reg = 0x1c,
118 #define GPIO_DR (mxc_gpio_hwdata->dr_reg)
119 #define GPIO_GDIR (mxc_gpio_hwdata->gdir_reg)
120 #define GPIO_PSR (mxc_gpio_hwdata->psr_reg)
121 #define GPIO_ICR1 (mxc_gpio_hwdata->icr1_reg)
122 #define GPIO_ICR2 (mxc_gpio_hwdata->icr2_reg)
123 #define GPIO_IMR (mxc_gpio_hwdata->imr_reg)
124 #define GPIO_ISR (mxc_gpio_hwdata->isr_reg)
125 #define GPIO_EDGE_SEL (mxc_gpio_hwdata->edge_sel_reg)
127 #define GPIO_INT_LOW_LEV (mxc_gpio_hwdata->low_level)
128 #define GPIO_INT_HIGH_LEV (mxc_gpio_hwdata->high_level)
129 #define GPIO_INT_RISE_EDGE (mxc_gpio_hwdata->rise_edge)
130 #define GPIO_INT_FALL_EDGE (mxc_gpio_hwdata->fall_edge)
131 #define GPIO_INT_BOTH_EDGES 0x4
138 .name =
"imx21-gpio",
141 .name =
"imx31-gpio",
144 .name =
"imx35-gpio",
152 { .compatible =
"fsl,imx1-gpio", .data = &mxc_gpio_devtype[
IMX1_GPIO], },
153 { .compatible =
"fsl,imx21-gpio", .data = &mxc_gpio_devtype[
IMX21_GPIO], },
154 { .compatible =
"fsl,imx31-gpio", .data = &mxc_gpio_devtype[
IMX31_GPIO], },
155 { .compatible =
"fsl,imx35-gpio", .data = &mxc_gpio_devtype[
IMX35_GPIO], },
170 struct irq_chip_generic *
gc = irq_data_get_irq_chip_data(d);
193 pr_debug(
"mxc: set GPIO %d to low trigger\n", gpio);
196 pr_debug(
"mxc: set GPIO %d to high trigger\n", gpio);
214 writel(val | (1 << gpio_idx),
217 writel(val & ~(1 << gpio_idx),
222 reg +=
GPIO_ICR1 + ((gpio_idx & 0x10) >> 2);
223 bit = gpio_idx & 0xf;
224 val =
readl(reg) & ~(0x3 << (bit << 1));
225 writel(val | (edge << (bit << 1)), reg);
242 edge = (val >> (bit << 1)) & 3;
243 val &= ~(0x3 << (bit << 1));
246 pr_debug(
"mxc: switch GPIO %d to low trigger\n", gpio);
249 pr_debug(
"mxc: switch GPIO %d to high trigger\n", gpio);
251 pr_err(
"mxc: invalid configuration for GPIO %d: %x\n",
255 writel(val | (edge << (bit << 1)), reg);
261 while (irq_stat != 0) {
262 int irqoffset = fls(irq_stat) - 1;
265 mxc_flip_edge(port, irqoffset);
269 irq_stat &= ~(1 << irqoffset);
280 chained_irq_enter(chip, desc);
284 mxc_gpio_irq_handler(port, irq_stat);
286 chained_irq_exit(chip, desc);
292 u32 irq_msk, irq_stat;
303 mxc_gpio_irq_handler(port, irq_stat);
318 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
323 if (port->
irq_high && (gpio_idx >= 16))
326 enable_irq_wake(port->
irq);
328 if (port->
irq_high && (gpio_idx >= 16))
331 disable_irq_wake(port->
irq);
339 struct irq_chip_generic *gc;
340 struct irq_chip_type *
ct;
350 ct->chip.irq_set_type = gpio_set_irq_type;
351 ct->chip.irq_set_wake = gpio_set_wake_irq;
367 hwtype = pdev->
id_entry->driver_data;
380 mxc_gpio_hwdata = &imx35_gpio_hwdata;
382 mxc_gpio_hwdata = &imx31_gpio_hwdata;
384 mxc_gpio_hwdata = &imx1_imx21_gpio_hwdata;
389 static int mxc_gpio_to_irq(
struct gpio_chip *gc,
unsigned offset)
406 mxc_gpio_get_hw(pdev);
427 goto out_release_mem;
447 irq_set_chained_handler(port->
irq, mx2_gpio_irq_handler);
450 irq_set_chained_handler(port->
irq, mx3_gpio_irq_handler);
454 irq_set_chained_handler(port->
irq_high,
455 mx3_gpio_irq_handler);
467 port->
bgc.gc.to_irq = mxc_gpio_to_irq;
473 goto out_bgpio_remove;
478 goto out_gpiochip_remove;
485 goto out_irqdesc_free;
489 mxc_gpio_init_gc(port, irq_base);
507 dev_info(&pdev->
dev,
"%s failed with errno %d\n", __func__, err);
515 .of_match_table = mxc_gpio_dt_ids,
517 .probe = mxc_gpio_probe,
518 .id_table = mxc_gpio_devtype,
521 static int __init gpio_mxc_init(
void)
528 "Daniel Mack <danielncaiaq.de>, "