28 #include <linux/bitops.h>
31 #include <linux/slab.h>
32 #include <linux/module.h>
64 #define GIO_RAWBL 0x50
65 #define GIO_RAWBH 0x54
69 #define GIO_IDT(n) (GIO_IDT0 + ((n) * 4))
88 static void em_gio_irq_disable(
struct irq_data *
d)
90 struct em_gio_priv *p = irq_data_get_irq_chip_data(d);
92 em_gio_write(p,
GIO_IDS,
BIT(irqd_to_hwirq(d)));
95 static void em_gio_irq_enable(
struct irq_data *d)
97 struct em_gio_priv *p = irq_data_get_irq_chip_data(d);
99 em_gio_write(p,
GIO_IEN,
BIT(irqd_to_hwirq(d)));
102 #define GIO_ASYNC(x) (x + 8)
112 static int em_gio_irq_set_type(
struct irq_data *d,
unsigned int type)
115 struct em_gio_priv *p = irq_data_get_irq_chip_data(d);
123 offset = irqd_to_hwirq(d);
125 pr_debug(
"gio: sense irq = %d, mode = %d\n", offset, value);
129 shift = (offset & 0x07) << 4;
139 tmp = em_gio_read(p, reg);
140 tmp &= ~(0xf << shift);
141 tmp |= value << shift;
142 em_gio_write(p, reg, tmp);
152 spin_unlock_irqrestore(&p->
sense_lock, flags);
160 unsigned long pending;
161 unsigned int offset, irqs_handled = 0;
163 while ((pending = em_gio_read(p,
GIO_MST))) {
164 offset =
__ffs(pending);
178 static int em_gio_direction_input(
struct gpio_chip *
chip,
unsigned offset)
180 em_gio_write(gpio_to_priv(chip),
GIO_E0,
BIT(offset));
184 static int em_gio_get(
struct gpio_chip *chip,
unsigned offset)
186 return (
int)(em_gio_read(gpio_to_priv(chip),
GIO_I) &
BIT(offset));
189 static void __em_gio_set(
struct gpio_chip *chip,
unsigned int reg,
190 unsigned shift,
int value)
193 em_gio_write(gpio_to_priv(chip), reg,
194 (1 << (shift + 16)) | (value << shift));
197 static void em_gio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
201 __em_gio_set(chip,
GIO_OL, offset, value);
203 __em_gio_set(chip,
GIO_OH, offset - 16, value);
206 static int em_gio_direction_output(
struct gpio_chip *chip,
unsigned offset,
210 em_gio_set(chip, offset, value);
211 em_gio_write(gpio_to_priv(chip),
GIO_E1,
BIT(offset));
215 static int em_gio_to_irq(
struct gpio_chip *chip,
unsigned offset)
220 static int em_gio_irq_domain_map(
struct irq_domain *
h,
unsigned int virq,
225 pr_debug(
"gio: map hw irq = %d, virq = %d\n", (
int)hw, virq);
234 .map = em_gio_irq_domain_map,
248 pr_debug(
"gio: hw base = %d, nr = %d, sw base = %d\n",
254 &em_gio_irq_domain_ops, p);
263 static void em_gio_irq_domain_cleanup(
struct em_gio_priv *p)
276 struct gpio_chip *gpio_chip;
278 const char *
name = dev_name(&pdev->
dev);
283 dev_err(&pdev->
dev,
"failed to allocate driver data\n");
289 platform_set_drvdata(pdev, p);
297 if (!io[0] || !io[1] || !irq[0] || !irq[1] || !pdata) {
298 dev_err(&pdev->
dev,
"missing IRQ, IOMEM or configuration\n");
305 dev_err(&pdev->
dev,
"failed to remap low I/O memory\n");
312 dev_err(&pdev->
dev,
"failed to remap high I/O memory\n");
318 gpio_chip->direction_input = em_gio_direction_input;
319 gpio_chip->get = em_gio_get;
320 gpio_chip->direction_output = em_gio_direction_output;
321 gpio_chip->set = em_gio_set;
322 gpio_chip->to_irq = em_gio_to_irq;
323 gpio_chip->label =
name;
330 irq_chip->
irq_mask = em_gio_irq_disable;
337 ret = em_gio_irq_domain_init(p);
339 dev_err(&pdev->
dev,
"cannot initialize irq domain\n");
344 dev_err(&pdev->
dev,
"failed to request low IRQ\n");
350 dev_err(&pdev->
dev,
"failed to request high IRQ\n");
357 dev_err(&pdev->
dev,
"failed to add GPIO controller\n");
367 em_gio_irq_domain_cleanup(p);
380 struct em_gio_priv *p = platform_get_drvdata(pdev);
393 em_gio_irq_domain_cleanup(p);
401 .probe = em_gio_probe,