19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/slab.h>
24 #include <linux/errno.h>
27 #include <linux/device.h>
62 spin_unlock_irqrestore(&ucb->
io_lock, flags);
90 spin_unlock_irqrestore(&ucb->
io_lock, flags);
110 static void ucb1x00_gpio_set(
struct gpio_chip *
chip,
unsigned offset,
int value)
123 ucb1x00_disable(ucb);
124 spin_unlock_irqrestore(&ucb->
io_lock, flags);
127 static int ucb1x00_gpio_get(
struct gpio_chip *chip,
unsigned offset)
134 ucb1x00_disable(ucb);
136 return val & (1 <<
offset);
139 static int ucb1x00_gpio_direction_input(
struct gpio_chip *chip,
unsigned offset)
148 ucb1x00_disable(ucb);
149 spin_unlock_irqrestore(&ucb->
io_lock, flags);
154 static int ucb1x00_gpio_direction_output(
struct gpio_chip *chip,
unsigned offset
172 if (!(ucb->
io_dir & mask)) {
176 ucb1x00_disable(ucb);
177 spin_unlock_irqrestore(&ucb->
io_lock, flags);
182 static int ucb1x00_to_irq(
struct gpio_chip *chip,
unsigned offset)
272 ucb1x00_disable(ucb);
287 struct ucb1x00 *ucb = irq_desc_get_handler_data(desc);
295 for (i = 0; i < 16 && isr; i++, isr >>= 1, irq++)
298 ucb1x00_disable(ucb);
301 static void ucb1x00_irq_update(
struct ucb1x00 *ucb,
unsigned mask)
310 ucb1x00_disable(ucb);
319 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data);
324 ucb1x00_irq_update(ucb, mask);
330 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data);
335 ucb1x00_irq_update(ucb, mask);
341 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data);
365 static int ucb1x00_irq_set_wake(
struct irq_data *data,
unsigned int on)
367 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data);
384 static struct irq_chip ucb1x00_irqchip = {
386 .irq_ack = ucb1x00_irq_noop,
387 .irq_mask = ucb1x00_irq_mask,
388 .irq_unmask = ucb1x00_irq_unmask,
389 .irq_set_type = ucb1x00_irq_set_type,
390 .irq_set_wake = ucb1x00_irq_set_wake,
415 static void ucb1x00_remove_dev(
struct ucb1x00_dev *dev)
417 dev->
drv->remove(dev);
442 static int ucb1x00_detect_irq(
struct ucb1x00 *ucb)
486 static void ucb1x00_release(
struct device *dev)
492 static struct class ucb1x00_class = {
494 .dev_release = ucb1x00_release,
497 static int ucb1x00_probe(
struct mcp *
mcp)
506 if (pdata && pdata->
reset)
524 ucb->
dev.class = &ucb1x00_class;
540 ucb->
irq = ucb1x00_detect_irq(ucb);
541 ucb1x00_disable(ucb);
549 irq_base = pdata ? pdata->
irq_base : 0;
550 ucb->
irq_base = irq_alloc_descs(-1, irq_base, 16, -1);
552 dev_err(&ucb->
dev,
"unable to allocate 16 irqs: %d\n",
557 for (i = 0; i < 16; i++) {
567 irq_set_chained_handler(ucb->
irq, ucb1x00_irq);
570 ucb->
gpio.label = dev_name(&ucb->
dev);
574 ucb->
gpio.ngpio = 10;
575 ucb->
gpio.set = ucb1x00_gpio_set;
576 ucb->
gpio.get = ucb1x00_gpio_get;
577 ucb->
gpio.direction_input = ucb1x00_gpio_direction_input;
578 ucb->
gpio.direction_output = ucb1x00_gpio_direction_output;
579 ucb->
gpio.to_irq = ucb1x00_to_irq;
584 dev_info(&ucb->
dev,
"gpio_base not set so no gpiolib support");
591 INIT_LIST_HEAD(&ucb->
devs);
595 ucb1x00_add_dev(ucb, drv);
602 irq_set_chained_handler(ucb->
irq,
NULL);
611 if (pdata && pdata->
reset)
616 static void ucb1x00_remove(
struct mcp *mcp)
627 ucb1x00_remove_dev(dev);
631 if (ucb->
gpio.base != -1) {
634 dev_err(&ucb->
dev,
"Can't remove gpio chip: %d\n", ret);
637 irq_set_chained_handler(ucb->
irq,
NULL);
641 if (pdata && pdata->
reset)
649 INIT_LIST_HEAD(&drv->
devs);
653 ucb1x00_add_dev(ucb, drv);
667 ucb1x00_remove_dev(dev);
672 static int ucb1x00_suspend(
struct device *dev)
680 if (udev->
drv->suspend)
681 udev->
drv->suspend(udev);
694 ucb1x00_disable(ucb);
697 enable_irq_wake(ucb->
irq);
698 }
else if (pdata && pdata->
reset)
704 static int ucb1x00_resume(
struct device *dev)
727 disable_irq_wake(ucb->
irq);
729 ucb1x00_disable(ucb);
733 if (udev->
drv->resume)
734 udev->
drv->resume(udev);
740 static const struct dev_pm_ops ucb1x00_pm_ops = {
748 .pm = &ucb1x00_pm_ops,
750 .probe = ucb1x00_probe,
751 .remove = ucb1x00_remove,
754 static int __init ucb1x00_init(
void)
765 static void __exit ucb1x00_exit(
void)