hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-mpc8xxx.c
....@@ -22,6 +22,7 @@
2222 #include <linux/irq.h>
2323 #include <linux/gpio/driver.h>
2424 #include <linux/bitops.h>
25
+#include <linux/interrupt.h>
2526
2627 #define MPC8XXX_GPIO_PINS 32
2728
....@@ -32,6 +33,7 @@
3233 #define GPIO_IMR 0x10
3334 #define GPIO_ICR 0x14
3435 #define GPIO_ICR2 0x18
36
+#define GPIO_IBE 0x18
3537
3638 struct mpc8xxx_gpio_chip {
3739 struct gpio_chip gc;
....@@ -105,20 +107,19 @@
105107 return -ENXIO;
106108 }
107109
108
-static void mpc8xxx_gpio_irq_cascade(struct irq_desc *desc)
110
+static irqreturn_t mpc8xxx_gpio_irq_cascade(int irq, void *data)
109111 {
110
- struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_desc_get_handler_data(desc);
111
- struct irq_chip *chip = irq_desc_get_chip(desc);
112
+ struct mpc8xxx_gpio_chip *mpc8xxx_gc = data;
112113 struct gpio_chip *gc = &mpc8xxx_gc->gc;
113
- unsigned int mask;
114
+ unsigned long mask;
115
+ int i;
114116
115117 mask = gc->read_reg(mpc8xxx_gc->regs + GPIO_IER)
116118 & gc->read_reg(mpc8xxx_gc->regs + GPIO_IMR);
117
- if (mask)
118
- generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq,
119
- 32 - ffs(mask)));
120
- if (chip->irq_eoi)
121
- chip->irq_eoi(&desc->irq_data);
119
+ for_each_set_bit(i, &mask, 32)
120
+ generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq, 31 - i));
121
+
122
+ return IRQ_HANDLED;
122123 }
123124
124125 static void mpc8xxx_irq_unmask(struct irq_data *d)
....@@ -168,6 +169,7 @@
168169
169170 switch (flow_type) {
170171 case IRQ_TYPE_EDGE_FALLING:
172
+ case IRQ_TYPE_LEVEL_LOW:
171173 raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
172174 gc->write_reg(mpc8xxx_gc->regs + GPIO_ICR,
173175 gc->read_reg(mpc8xxx_gc->regs + GPIO_ICR)
....@@ -291,6 +293,8 @@
291293 { .compatible = "fsl,mpc5121-gpio", .data = &mpc512x_gpio_devtype, },
292294 { .compatible = "fsl,mpc5125-gpio", .data = &mpc5125_gpio_devtype, },
293295 { .compatible = "fsl,pq3-gpio", },
296
+ { .compatible = "fsl,ls1028a-gpio", },
297
+ { .compatible = "fsl,ls1088a-gpio", },
294298 { .compatible = "fsl,qoriq-gpio", },
295299 {}
296300 };
....@@ -359,7 +363,19 @@
359363
360364 gc->to_irq = mpc8xxx_gpio_to_irq;
361365
362
- ret = gpiochip_add_data(gc, mpc8xxx_gc);
366
+ /*
367
+ * The GPIO Input Buffer Enable register(GPIO_IBE) is used to control
368
+ * the input enable of each individual GPIO port. When an individual
369
+ * GPIO port’s direction is set to input (GPIO_GPDIR[DRn=0]), the
370
+ * associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
371
+ * the port value to the GPIO Data Register.
372
+ */
373
+ if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
374
+ of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
375
+ of_device_is_compatible(np, "fsl,ls1088a-gpio"))
376
+ gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0xffffffff);
377
+
378
+ ret = devm_gpiochip_add_data(&pdev->dev, gc, mpc8xxx_gc);
363379 if (ret) {
364380 pr_err("%pOF: GPIO chip registration failed with status %d\n",
365381 np, ret);
....@@ -379,10 +395,20 @@
379395 gc->write_reg(mpc8xxx_gc->regs + GPIO_IER, 0xffffffff);
380396 gc->write_reg(mpc8xxx_gc->regs + GPIO_IMR, 0);
381397
382
- irq_set_chained_handler_and_data(mpc8xxx_gc->irqn,
383
- mpc8xxx_gpio_irq_cascade, mpc8xxx_gc);
398
+ ret = devm_request_irq(&pdev->dev, mpc8xxx_gc->irqn,
399
+ mpc8xxx_gpio_irq_cascade,
400
+ IRQF_NO_THREAD | IRQF_SHARED, "gpio-cascade",
401
+ mpc8xxx_gc);
402
+ if (ret) {
403
+ dev_err(&pdev->dev, "%s: failed to devm_request_irq(%d), ret = %d\n",
404
+ np->full_name, mpc8xxx_gc->irqn, ret);
405
+ goto err;
406
+ }
407
+
384408 return 0;
385409 err:
410
+ if (mpc8xxx_gc->irq)
411
+ irq_domain_remove(mpc8xxx_gc->irq);
386412 iounmap(mpc8xxx_gc->regs);
387413 return ret;
388414 }
....@@ -396,7 +422,6 @@
396422 irq_domain_remove(mpc8xxx_gc->irq);
397423 }
398424
399
- gpiochip_remove(&mpc8xxx_gc->gc);
400425 iounmap(mpc8xxx_gc->regs);
401426
402427 return 0;