diff options
Diffstat (limited to 'drivers/mfd/ucb1x00-core.c')
-rw-r--r-- | drivers/mfd/ucb1x00-core.c | 67 |
1 files changed, 24 insertions, 43 deletions
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c index 91c4f25e0e55..febc90cdef7e 100644 --- a/drivers/mfd/ucb1x00-core.c +++ b/drivers/mfd/ucb1x00-core.c | |||
@@ -36,15 +36,6 @@ static DEFINE_MUTEX(ucb1x00_mutex); | |||
36 | static LIST_HEAD(ucb1x00_drivers); | 36 | static LIST_HEAD(ucb1x00_drivers); |
37 | static LIST_HEAD(ucb1x00_devices); | 37 | static LIST_HEAD(ucb1x00_devices); |
38 | 38 | ||
39 | static struct mcp_device_id ucb1x00_id[] = { | ||
40 | { "ucb1x00", 0 }, /* auto-detection */ | ||
41 | { "ucb1200", UCB_ID_1200 }, | ||
42 | { "ucb1300", UCB_ID_1300 }, | ||
43 | { "tc35143", UCB_ID_TC35143 }, | ||
44 | { } | ||
45 | }; | ||
46 | MODULE_DEVICE_TABLE(mcp, ucb1x00_id); | ||
47 | |||
48 | /** | 39 | /** |
49 | * ucb1x00_io_set_dir - set IO direction | 40 | * ucb1x00_io_set_dir - set IO direction |
50 | * @ucb: UCB1x00 structure describing chip | 41 | * @ucb: UCB1x00 structure describing chip |
@@ -157,16 +148,22 @@ static int ucb1x00_gpio_direction_output(struct gpio_chip *chip, unsigned offset | |||
157 | { | 148 | { |
158 | struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio); | 149 | struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio); |
159 | unsigned long flags; | 150 | unsigned long flags; |
151 | unsigned old, mask = 1 << offset; | ||
160 | 152 | ||
161 | spin_lock_irqsave(&ucb->io_lock, flags); | 153 | spin_lock_irqsave(&ucb->io_lock, flags); |
162 | ucb->io_dir |= (1 << offset); | 154 | old = ucb->io_out; |
163 | ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); | ||
164 | |||
165 | if (value) | 155 | if (value) |
166 | ucb->io_out |= 1 << offset; | 156 | ucb->io_out |= mask; |
167 | else | 157 | else |
168 | ucb->io_out &= ~(1 << offset); | 158 | ucb->io_out &= ~mask; |
169 | ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); | 159 | |
160 | if (old != ucb->io_out) | ||
161 | ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); | ||
162 | |||
163 | if (!(ucb->io_dir & mask)) { | ||
164 | ucb->io_dir |= mask; | ||
165 | ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); | ||
166 | } | ||
170 | spin_unlock_irqrestore(&ucb->io_lock, flags); | 167 | spin_unlock_irqrestore(&ucb->io_lock, flags); |
171 | 168 | ||
172 | return 0; | 169 | return 0; |
@@ -536,33 +533,17 @@ static struct class ucb1x00_class = { | |||
536 | 533 | ||
537 | static int ucb1x00_probe(struct mcp *mcp) | 534 | static int ucb1x00_probe(struct mcp *mcp) |
538 | { | 535 | { |
539 | const struct mcp_device_id *mid; | ||
540 | struct ucb1x00 *ucb; | 536 | struct ucb1x00 *ucb; |
541 | struct ucb1x00_driver *drv; | 537 | struct ucb1x00_driver *drv; |
542 | struct ucb1x00_plat_data *pdata; | ||
543 | unsigned int id; | 538 | unsigned int id; |
544 | int ret = -ENODEV; | 539 | int ret = -ENODEV; |
545 | int temp; | 540 | int temp; |
546 | 541 | ||
547 | mcp_enable(mcp); | 542 | mcp_enable(mcp); |
548 | id = mcp_reg_read(mcp, UCB_ID); | 543 | id = mcp_reg_read(mcp, UCB_ID); |
549 | mid = mcp_get_device_id(mcp); | ||
550 | 544 | ||
551 | if (mid && mid->driver_data) { | 545 | if (id != UCB_ID_1200 && id != UCB_ID_1300 && id != UCB_ID_TC35143) { |
552 | if (id != mid->driver_data) { | 546 | printk(KERN_WARNING "UCB1x00 ID not found: %04x\n", id); |
553 | printk(KERN_WARNING "%s wrong ID %04x found: %04x\n", | ||
554 | mid->name, (unsigned int) mid->driver_data, id); | ||
555 | goto err_disable; | ||
556 | } | ||
557 | } else { | ||
558 | mid = &ucb1x00_id[1]; | ||
559 | while (mid->driver_data) { | ||
560 | if (id == mid->driver_data) | ||
561 | break; | ||
562 | mid++; | ||
563 | } | ||
564 | printk(KERN_WARNING "%s ID not found: %04x\n", | ||
565 | ucb1x00_id[0].name, id); | ||
566 | goto err_disable; | 547 | goto err_disable; |
567 | } | 548 | } |
568 | 549 | ||
@@ -571,28 +552,28 @@ static int ucb1x00_probe(struct mcp *mcp) | |||
571 | if (!ucb) | 552 | if (!ucb) |
572 | goto err_disable; | 553 | goto err_disable; |
573 | 554 | ||
574 | pdata = mcp->attached_device.platform_data; | 555 | |
575 | ucb->dev.class = &ucb1x00_class; | 556 | ucb->dev.class = &ucb1x00_class; |
576 | ucb->dev.parent = &mcp->attached_device; | 557 | ucb->dev.parent = &mcp->attached_device; |
577 | dev_set_name(&ucb->dev, mid->name); | 558 | dev_set_name(&ucb->dev, "ucb1x00"); |
578 | 559 | ||
579 | spin_lock_init(&ucb->lock); | 560 | spin_lock_init(&ucb->lock); |
580 | spin_lock_init(&ucb->io_lock); | 561 | spin_lock_init(&ucb->io_lock); |
581 | sema_init(&ucb->adc_sem, 1); | 562 | sema_init(&ucb->adc_sem, 1); |
582 | 563 | ||
583 | ucb->id = mid; | 564 | ucb->id = id; |
584 | ucb->mcp = mcp; | 565 | ucb->mcp = mcp; |
585 | ucb->irq = ucb1x00_detect_irq(ucb); | 566 | ucb->irq = ucb1x00_detect_irq(ucb); |
586 | if (ucb->irq == NO_IRQ) { | 567 | if (ucb->irq == NO_IRQ) { |
587 | printk(KERN_ERR "%s: IRQ probe failed\n", mid->name); | 568 | printk(KERN_ERR "UCB1x00: IRQ probe failed\n"); |
588 | ret = -ENODEV; | 569 | ret = -ENODEV; |
589 | goto err_free; | 570 | goto err_free; |
590 | } | 571 | } |
591 | 572 | ||
592 | ucb->gpio.base = -1; | 573 | ucb->gpio.base = -1; |
593 | if (pdata && (pdata->gpio_base >= 0)) { | 574 | if (mcp->gpio_base != 0) { |
594 | ucb->gpio.label = dev_name(&ucb->dev); | 575 | ucb->gpio.label = dev_name(&ucb->dev); |
595 | ucb->gpio.base = pdata->gpio_base; | 576 | ucb->gpio.base = mcp->gpio_base; |
596 | ucb->gpio.ngpio = 10; | 577 | ucb->gpio.ngpio = 10; |
597 | ucb->gpio.set = ucb1x00_gpio_set; | 578 | ucb->gpio.set = ucb1x00_gpio_set; |
598 | ucb->gpio.get = ucb1x00_gpio_get; | 579 | ucb->gpio.get = ucb1x00_gpio_get; |
@@ -605,10 +586,10 @@ static int ucb1x00_probe(struct mcp *mcp) | |||
605 | dev_info(&ucb->dev, "gpio_base not set so no gpiolib support"); | 586 | dev_info(&ucb->dev, "gpio_base not set so no gpiolib support"); |
606 | 587 | ||
607 | ret = request_irq(ucb->irq, ucb1x00_irq, IRQF_TRIGGER_RISING, | 588 | ret = request_irq(ucb->irq, ucb1x00_irq, IRQF_TRIGGER_RISING, |
608 | mid->name, ucb); | 589 | "UCB1x00", ucb); |
609 | if (ret) { | 590 | if (ret) { |
610 | printk(KERN_ERR "%s: unable to grab irq%d: %d\n", | 591 | printk(KERN_ERR "ucb1x00: unable to grab irq%d: %d\n", |
611 | mid->name, ucb->irq, ret); | 592 | ucb->irq, ret); |
612 | goto err_gpio; | 593 | goto err_gpio; |
613 | } | 594 | } |
614 | 595 | ||
@@ -712,6 +693,7 @@ static int ucb1x00_resume(struct mcp *mcp) | |||
712 | struct ucb1x00 *ucb = mcp_get_drvdata(mcp); | 693 | struct ucb1x00 *ucb = mcp_get_drvdata(mcp); |
713 | struct ucb1x00_dev *dev; | 694 | struct ucb1x00_dev *dev; |
714 | 695 | ||
696 | ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); | ||
715 | ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); | 697 | ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); |
716 | mutex_lock(&ucb1x00_mutex); | 698 | mutex_lock(&ucb1x00_mutex); |
717 | list_for_each_entry(dev, &ucb->devs, dev_node) { | 699 | list_for_each_entry(dev, &ucb->devs, dev_node) { |
@@ -730,7 +712,6 @@ static struct mcp_driver ucb1x00_driver = { | |||
730 | .remove = ucb1x00_remove, | 712 | .remove = ucb1x00_remove, |
731 | .suspend = ucb1x00_suspend, | 713 | .suspend = ucb1x00_suspend, |
732 | .resume = ucb1x00_resume, | 714 | .resume = ucb1x00_resume, |
733 | .id_table = ucb1x00_id, | ||
734 | }; | 715 | }; |
735 | 716 | ||
736 | static int __init ucb1x00_init(void) | 717 | static int __init ucb1x00_init(void) |