11 #include <linux/kernel.h>
18 #include <linux/slab.h>
21 #define MPC8XXX_GPIO_PINS 32
29 #define GPIO_ICR2 0x18
44 static inline u32 mpc8xxx_gpio2mask(
unsigned int gpio)
50 to_mpc8xxx_gpio_chip(
struct of_mm_gpio_chip *mm)
55 static void mpc8xxx_gpio_save_regs(
struct of_mm_gpio_chip *mm)
67 static int mpc8572_gpio_get(
struct gpio_chip *
gc,
unsigned int gpio)
70 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
75 return (val | mpc8xxx_gc->
data) & mpc8xxx_gpio2mask(gpio);
78 static int mpc8xxx_gpio_get(
struct gpio_chip *gc,
unsigned int gpio)
80 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
85 static void mpc8xxx_gpio_set(
struct gpio_chip *gc,
unsigned int gpio,
int val)
87 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
94 mpc8xxx_gc->
data |= mpc8xxx_gpio2mask(gpio);
96 mpc8xxx_gc->
data &= ~mpc8xxx_gpio2mask(gpio);
100 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
103 static int mpc8xxx_gpio_dir_in(
struct gpio_chip *gc,
unsigned int gpio)
105 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
111 clrbits32(mm->regs +
GPIO_DIR, mpc8xxx_gpio2mask(gpio));
113 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
118 static int mpc8xxx_gpio_dir_out(
struct gpio_chip *gc,
unsigned int gpio,
int val)
120 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
124 mpc8xxx_gpio_set(gc, gpio, val);
128 setbits32(mm->regs +
GPIO_DIR, mpc8xxx_gpio2mask(gpio));
130 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
135 static int mpc5121_gpio_dir_out(
struct gpio_chip *gc,
unsigned int gpio,
int val)
141 return mpc8xxx_gpio_dir_out(gc, gpio, val);
144 static int mpc8xxx_gpio_to_irq(
struct gpio_chip *gc,
unsigned offset)
146 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
155 static void mpc8xxx_gpio_irq_cascade(
unsigned int irq,
struct irq_desc *
desc)
159 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->
mm_gc;
170 static void mpc8xxx_irq_unmask(
struct irq_data *
d)
173 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->
mm_gc;
178 setbits32(mm->regs +
GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
180 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
183 static void mpc8xxx_irq_mask(
struct irq_data *d)
186 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->
mm_gc;
191 clrbits32(mm->regs +
GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
193 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
196 static void mpc8xxx_irq_ack(
struct irq_data *d)
199 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->
mm_gc;
204 static int mpc8xxx_irq_set_type(
struct irq_data *d,
unsigned int flow_type)
207 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->
mm_gc;
214 mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
215 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
221 mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
222 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
232 static int mpc512x_irq_set_type(
struct irq_data *d,
unsigned int flow_type)
235 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->
mm_gc;
236 unsigned long gpio = irqd_to_hwirq(d);
243 shift = (15 -
gpio) * 2;
246 shift = (15 - (gpio % 16)) * 2;
253 clrsetbits_be32(reg, 3 << shift, 2 << shift);
254 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
260 clrsetbits_be32(reg, 3 << shift, 1 << shift);
261 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
266 clrbits32(reg, 3 << shift);
267 spin_unlock_irqrestore(&mpc8xxx_gc->
lock, flags);
277 static struct irq_chip mpc8xxx_irq_chip = {
278 .name =
"mpc8xxx-gpio",
279 .irq_unmask = mpc8xxx_irq_unmask,
280 .irq_mask = mpc8xxx_irq_mask,
281 .irq_ack = mpc8xxx_irq_ack,
282 .irq_set_type = mpc8xxx_irq_set_type,
285 static int mpc8xxx_gpio_irq_map(
struct irq_domain *
h,
unsigned int virq,
301 .map = mpc8xxx_gpio_irq_map,
306 { .compatible =
"fsl,mpc8349-gpio", },
307 { .compatible =
"fsl,mpc8572-gpio", },
308 { .compatible =
"fsl,mpc8610-gpio", },
309 { .compatible =
"fsl,mpc5121-gpio", .data = mpc512x_irq_set_type, },
310 { .compatible =
"fsl,pq3-gpio", },
311 { .compatible =
"fsl,qoriq-gpio", },
318 struct of_mm_gpio_chip *mm_gc;
319 struct gpio_chip *gc;
324 mpc8xxx_gc = kzalloc(
sizeof(*mpc8xxx_gc),
GFP_KERNEL);
332 mm_gc = &mpc8xxx_gc->
mm_gc;
335 mm_gc->save_regs = mpc8xxx_gpio_save_regs;
337 gc->direction_input = mpc8xxx_gpio_dir_in;
339 mpc5121_gpio_dir_out : mpc8xxx_gpio_dir_out;
341 mpc8572_gpio_get : mpc8xxx_gpio_get;
342 gc->set = mpc8xxx_gpio_set;
343 gc->to_irq = mpc8xxx_gpio_to_irq;
354 &mpc8xxx_gpio_irq_ops, mpc8xxx_gc);
355 if (!mpc8xxx_gc->
irq)
367 irq_set_chained_handler(hwirq, mpc8xxx_gpio_irq_cascade);
373 pr_err(
"%s: registration failed with status %d\n",
380 static int __init mpc8xxx_add_gpiochips(
void)
384 for_each_matching_node(np, mpc8xxx_gpio_ids)
385 mpc8xxx_add_controller(np);