diff options
Diffstat (limited to 'drivers/mfd/da9052-core.c')
-rw-r--r-- | drivers/mfd/da9052-core.c | 273 |
1 files changed, 11 insertions, 262 deletions
diff --git a/drivers/mfd/da9052-core.c b/drivers/mfd/da9052-core.c index 689b747416af..a3c9613f9166 100644 --- a/drivers/mfd/da9052-core.c +++ b/drivers/mfd/da9052-core.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
16 | #include <linux/input.h> | 16 | #include <linux/input.h> |
17 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/irq.h> | ||
19 | #include <linux/mfd/core.h> | 18 | #include <linux/mfd/core.h> |
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
21 | #include <linux/module.h> | 20 | #include <linux/module.h> |
@@ -24,16 +23,6 @@ | |||
24 | #include <linux/mfd/da9052/pdata.h> | 23 | #include <linux/mfd/da9052/pdata.h> |
25 | #include <linux/mfd/da9052/reg.h> | 24 | #include <linux/mfd/da9052/reg.h> |
26 | 25 | ||
27 | #define DA9052_NUM_IRQ_REGS 4 | ||
28 | #define DA9052_IRQ_MASK_POS_1 0x01 | ||
29 | #define DA9052_IRQ_MASK_POS_2 0x02 | ||
30 | #define DA9052_IRQ_MASK_POS_3 0x04 | ||
31 | #define DA9052_IRQ_MASK_POS_4 0x08 | ||
32 | #define DA9052_IRQ_MASK_POS_5 0x10 | ||
33 | #define DA9052_IRQ_MASK_POS_6 0x20 | ||
34 | #define DA9052_IRQ_MASK_POS_7 0x40 | ||
35 | #define DA9052_IRQ_MASK_POS_8 0x80 | ||
36 | |||
37 | static bool da9052_reg_readable(struct device *dev, unsigned int reg) | 26 | static bool da9052_reg_readable(struct device *dev, unsigned int reg) |
38 | { | 27 | { |
39 | switch (reg) { | 28 | switch (reg) { |
@@ -425,15 +414,6 @@ err: | |||
425 | } | 414 | } |
426 | EXPORT_SYMBOL_GPL(da9052_adc_manual_read); | 415 | EXPORT_SYMBOL_GPL(da9052_adc_manual_read); |
427 | 416 | ||
428 | static irqreturn_t da9052_auxadc_irq(int irq, void *irq_data) | ||
429 | { | ||
430 | struct da9052 *da9052 = irq_data; | ||
431 | |||
432 | complete(&da9052->done); | ||
433 | |||
434 | return IRQ_HANDLED; | ||
435 | } | ||
436 | |||
437 | int da9052_adc_read_temp(struct da9052 *da9052) | 417 | int da9052_adc_read_temp(struct da9052 *da9052) |
438 | { | 418 | { |
439 | int tbat; | 419 | int tbat; |
@@ -447,74 +427,6 @@ int da9052_adc_read_temp(struct da9052 *da9052) | |||
447 | } | 427 | } |
448 | EXPORT_SYMBOL_GPL(da9052_adc_read_temp); | 428 | EXPORT_SYMBOL_GPL(da9052_adc_read_temp); |
449 | 429 | ||
450 | static struct resource da9052_rtc_resource = { | ||
451 | .name = "ALM", | ||
452 | .start = DA9052_IRQ_ALARM, | ||
453 | .end = DA9052_IRQ_ALARM, | ||
454 | .flags = IORESOURCE_IRQ, | ||
455 | }; | ||
456 | |||
457 | static struct resource da9052_onkey_resource = { | ||
458 | .name = "ONKEY", | ||
459 | .start = DA9052_IRQ_NONKEY, | ||
460 | .end = DA9052_IRQ_NONKEY, | ||
461 | .flags = IORESOURCE_IRQ, | ||
462 | }; | ||
463 | |||
464 | static struct resource da9052_bat_resources[] = { | ||
465 | { | ||
466 | .name = "BATT TEMP", | ||
467 | .start = DA9052_IRQ_TBAT, | ||
468 | .end = DA9052_IRQ_TBAT, | ||
469 | .flags = IORESOURCE_IRQ, | ||
470 | }, | ||
471 | { | ||
472 | .name = "DCIN DET", | ||
473 | .start = DA9052_IRQ_DCIN, | ||
474 | .end = DA9052_IRQ_DCIN, | ||
475 | .flags = IORESOURCE_IRQ, | ||
476 | }, | ||
477 | { | ||
478 | .name = "DCIN REM", | ||
479 | .start = DA9052_IRQ_DCINREM, | ||
480 | .end = DA9052_IRQ_DCINREM, | ||
481 | .flags = IORESOURCE_IRQ, | ||
482 | }, | ||
483 | { | ||
484 | .name = "VBUS DET", | ||
485 | .start = DA9052_IRQ_VBUS, | ||
486 | .end = DA9052_IRQ_VBUS, | ||
487 | .flags = IORESOURCE_IRQ, | ||
488 | }, | ||
489 | { | ||
490 | .name = "VBUS REM", | ||
491 | .start = DA9052_IRQ_VBUSREM, | ||
492 | .end = DA9052_IRQ_VBUSREM, | ||
493 | .flags = IORESOURCE_IRQ, | ||
494 | }, | ||
495 | { | ||
496 | .name = "CHG END", | ||
497 | .start = DA9052_IRQ_CHGEND, | ||
498 | .end = DA9052_IRQ_CHGEND, | ||
499 | .flags = IORESOURCE_IRQ, | ||
500 | }, | ||
501 | }; | ||
502 | |||
503 | static struct resource da9052_tsi_resources[] = { | ||
504 | { | ||
505 | .name = "PENDWN", | ||
506 | .start = DA9052_IRQ_PENDOWN, | ||
507 | .end = DA9052_IRQ_PENDOWN, | ||
508 | .flags = IORESOURCE_IRQ, | ||
509 | }, | ||
510 | { | ||
511 | .name = "TSIRDY", | ||
512 | .start = DA9052_IRQ_TSIREADY, | ||
513 | .end = DA9052_IRQ_TSIREADY, | ||
514 | .flags = IORESOURCE_IRQ, | ||
515 | }, | ||
516 | }; | ||
517 | |||
518 | static struct mfd_cell da9052_subdev_info[] = { | 430 | static struct mfd_cell da9052_subdev_info[] = { |
519 | { | 431 | { |
520 | .name = "da9052-regulator", | 432 | .name = "da9052-regulator", |
@@ -574,13 +486,9 @@ static struct mfd_cell da9052_subdev_info[] = { | |||
574 | }, | 486 | }, |
575 | { | 487 | { |
576 | .name = "da9052-onkey", | 488 | .name = "da9052-onkey", |
577 | .resources = &da9052_onkey_resource, | ||
578 | .num_resources = 1, | ||
579 | }, | 489 | }, |
580 | { | 490 | { |
581 | .name = "da9052-rtc", | 491 | .name = "da9052-rtc", |
582 | .resources = &da9052_rtc_resource, | ||
583 | .num_resources = 1, | ||
584 | }, | 492 | }, |
585 | { | 493 | { |
586 | .name = "da9052-gpio", | 494 | .name = "da9052-gpio", |
@@ -602,160 +510,15 @@ static struct mfd_cell da9052_subdev_info[] = { | |||
602 | }, | 510 | }, |
603 | { | 511 | { |
604 | .name = "da9052-tsi", | 512 | .name = "da9052-tsi", |
605 | .resources = da9052_tsi_resources, | ||
606 | .num_resources = ARRAY_SIZE(da9052_tsi_resources), | ||
607 | }, | 513 | }, |
608 | { | 514 | { |
609 | .name = "da9052-bat", | 515 | .name = "da9052-bat", |
610 | .resources = da9052_bat_resources, | ||
611 | .num_resources = ARRAY_SIZE(da9052_bat_resources), | ||
612 | }, | 516 | }, |
613 | { | 517 | { |
614 | .name = "da9052-watchdog", | 518 | .name = "da9052-watchdog", |
615 | }, | 519 | }, |
616 | }; | 520 | }; |
617 | 521 | ||
618 | static struct regmap_irq da9052_irqs[] = { | ||
619 | [DA9052_IRQ_DCIN] = { | ||
620 | .reg_offset = 0, | ||
621 | .mask = DA9052_IRQ_MASK_POS_1, | ||
622 | }, | ||
623 | [DA9052_IRQ_VBUS] = { | ||
624 | .reg_offset = 0, | ||
625 | .mask = DA9052_IRQ_MASK_POS_2, | ||
626 | }, | ||
627 | [DA9052_IRQ_DCINREM] = { | ||
628 | .reg_offset = 0, | ||
629 | .mask = DA9052_IRQ_MASK_POS_3, | ||
630 | }, | ||
631 | [DA9052_IRQ_VBUSREM] = { | ||
632 | .reg_offset = 0, | ||
633 | .mask = DA9052_IRQ_MASK_POS_4, | ||
634 | }, | ||
635 | [DA9052_IRQ_VDDLOW] = { | ||
636 | .reg_offset = 0, | ||
637 | .mask = DA9052_IRQ_MASK_POS_5, | ||
638 | }, | ||
639 | [DA9052_IRQ_ALARM] = { | ||
640 | .reg_offset = 0, | ||
641 | .mask = DA9052_IRQ_MASK_POS_6, | ||
642 | }, | ||
643 | [DA9052_IRQ_SEQRDY] = { | ||
644 | .reg_offset = 0, | ||
645 | .mask = DA9052_IRQ_MASK_POS_7, | ||
646 | }, | ||
647 | [DA9052_IRQ_COMP1V2] = { | ||
648 | .reg_offset = 0, | ||
649 | .mask = DA9052_IRQ_MASK_POS_8, | ||
650 | }, | ||
651 | [DA9052_IRQ_NONKEY] = { | ||
652 | .reg_offset = 1, | ||
653 | .mask = DA9052_IRQ_MASK_POS_1, | ||
654 | }, | ||
655 | [DA9052_IRQ_IDFLOAT] = { | ||
656 | .reg_offset = 1, | ||
657 | .mask = DA9052_IRQ_MASK_POS_2, | ||
658 | }, | ||
659 | [DA9052_IRQ_IDGND] = { | ||
660 | .reg_offset = 1, | ||
661 | .mask = DA9052_IRQ_MASK_POS_3, | ||
662 | }, | ||
663 | [DA9052_IRQ_CHGEND] = { | ||
664 | .reg_offset = 1, | ||
665 | .mask = DA9052_IRQ_MASK_POS_4, | ||
666 | }, | ||
667 | [DA9052_IRQ_TBAT] = { | ||
668 | .reg_offset = 1, | ||
669 | .mask = DA9052_IRQ_MASK_POS_5, | ||
670 | }, | ||
671 | [DA9052_IRQ_ADC_EOM] = { | ||
672 | .reg_offset = 1, | ||
673 | .mask = DA9052_IRQ_MASK_POS_6, | ||
674 | }, | ||
675 | [DA9052_IRQ_PENDOWN] = { | ||
676 | .reg_offset = 1, | ||
677 | .mask = DA9052_IRQ_MASK_POS_7, | ||
678 | }, | ||
679 | [DA9052_IRQ_TSIREADY] = { | ||
680 | .reg_offset = 1, | ||
681 | .mask = DA9052_IRQ_MASK_POS_8, | ||
682 | }, | ||
683 | [DA9052_IRQ_GPI0] = { | ||
684 | .reg_offset = 2, | ||
685 | .mask = DA9052_IRQ_MASK_POS_1, | ||
686 | }, | ||
687 | [DA9052_IRQ_GPI1] = { | ||
688 | .reg_offset = 2, | ||
689 | .mask = DA9052_IRQ_MASK_POS_2, | ||
690 | }, | ||
691 | [DA9052_IRQ_GPI2] = { | ||
692 | .reg_offset = 2, | ||
693 | .mask = DA9052_IRQ_MASK_POS_3, | ||
694 | }, | ||
695 | [DA9052_IRQ_GPI3] = { | ||
696 | .reg_offset = 2, | ||
697 | .mask = DA9052_IRQ_MASK_POS_4, | ||
698 | }, | ||
699 | [DA9052_IRQ_GPI4] = { | ||
700 | .reg_offset = 2, | ||
701 | .mask = DA9052_IRQ_MASK_POS_5, | ||
702 | }, | ||
703 | [DA9052_IRQ_GPI5] = { | ||
704 | .reg_offset = 2, | ||
705 | .mask = DA9052_IRQ_MASK_POS_6, | ||
706 | }, | ||
707 | [DA9052_IRQ_GPI6] = { | ||
708 | .reg_offset = 2, | ||
709 | .mask = DA9052_IRQ_MASK_POS_7, | ||
710 | }, | ||
711 | [DA9052_IRQ_GPI7] = { | ||
712 | .reg_offset = 2, | ||
713 | .mask = DA9052_IRQ_MASK_POS_8, | ||
714 | }, | ||
715 | [DA9052_IRQ_GPI8] = { | ||
716 | .reg_offset = 3, | ||
717 | .mask = DA9052_IRQ_MASK_POS_1, | ||
718 | }, | ||
719 | [DA9052_IRQ_GPI9] = { | ||
720 | .reg_offset = 3, | ||
721 | .mask = DA9052_IRQ_MASK_POS_2, | ||
722 | }, | ||
723 | [DA9052_IRQ_GPI10] = { | ||
724 | .reg_offset = 3, | ||
725 | .mask = DA9052_IRQ_MASK_POS_3, | ||
726 | }, | ||
727 | [DA9052_IRQ_GPI11] = { | ||
728 | .reg_offset = 3, | ||
729 | .mask = DA9052_IRQ_MASK_POS_4, | ||
730 | }, | ||
731 | [DA9052_IRQ_GPI12] = { | ||
732 | .reg_offset = 3, | ||
733 | .mask = DA9052_IRQ_MASK_POS_5, | ||
734 | }, | ||
735 | [DA9052_IRQ_GPI13] = { | ||
736 | .reg_offset = 3, | ||
737 | .mask = DA9052_IRQ_MASK_POS_6, | ||
738 | }, | ||
739 | [DA9052_IRQ_GPI14] = { | ||
740 | .reg_offset = 3, | ||
741 | .mask = DA9052_IRQ_MASK_POS_7, | ||
742 | }, | ||
743 | [DA9052_IRQ_GPI15] = { | ||
744 | .reg_offset = 3, | ||
745 | .mask = DA9052_IRQ_MASK_POS_8, | ||
746 | }, | ||
747 | }; | ||
748 | |||
749 | static struct regmap_irq_chip da9052_regmap_irq_chip = { | ||
750 | .name = "da9052_irq", | ||
751 | .status_base = DA9052_EVENT_A_REG, | ||
752 | .mask_base = DA9052_IRQ_MASK_A_REG, | ||
753 | .ack_base = DA9052_EVENT_A_REG, | ||
754 | .num_regs = DA9052_NUM_IRQ_REGS, | ||
755 | .irqs = da9052_irqs, | ||
756 | .num_irqs = ARRAY_SIZE(da9052_irqs), | ||
757 | }; | ||
758 | |||
759 | struct regmap_config da9052_regmap_config = { | 522 | struct regmap_config da9052_regmap_config = { |
760 | .reg_bits = 8, | 523 | .reg_bits = 8, |
761 | .val_bits = 8, | 524 | .val_bits = 8, |
@@ -782,45 +545,31 @@ int da9052_device_init(struct da9052 *da9052, u8 chip_id) | |||
782 | 545 | ||
783 | da9052->chip_id = chip_id; | 546 | da9052->chip_id = chip_id; |
784 | 547 | ||
785 | if (!pdata || !pdata->irq_base) | 548 | ret = da9052_irq_init(da9052); |
786 | da9052->irq_base = -1; | 549 | if (ret != 0) { |
787 | else | 550 | dev_err(da9052->dev, "da9052_irq_init failed: %d\n", ret); |
788 | da9052->irq_base = pdata->irq_base; | 551 | return ret; |
789 | 552 | } | |
790 | ret = regmap_add_irq_chip(da9052->regmap, da9052->chip_irq, | ||
791 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, | ||
792 | da9052->irq_base, &da9052_regmap_irq_chip, | ||
793 | &da9052->irq_data); | ||
794 | if (ret < 0) | ||
795 | goto regmap_err; | ||
796 | |||
797 | da9052->irq_base = regmap_irq_chip_get_base(da9052->irq_data); | ||
798 | |||
799 | ret = request_threaded_irq(DA9052_IRQ_ADC_EOM, NULL, da9052_auxadc_irq, | ||
800 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, | ||
801 | "adc irq", da9052); | ||
802 | if (ret != 0) | ||
803 | dev_err(da9052->dev, "DA9052 ADC IRQ failed ret=%d\n", ret); | ||
804 | 553 | ||
805 | ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info, | 554 | ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info, |
806 | ARRAY_SIZE(da9052_subdev_info), NULL, 0, NULL); | 555 | ARRAY_SIZE(da9052_subdev_info), NULL, 0, NULL); |
807 | if (ret) | 556 | if (ret) { |
557 | dev_err(da9052->dev, "mfd_add_devices failed: %d\n", ret); | ||
808 | goto err; | 558 | goto err; |
559 | } | ||
809 | 560 | ||
810 | return 0; | 561 | return 0; |
811 | 562 | ||
812 | err: | 563 | err: |
813 | free_irq(DA9052_IRQ_ADC_EOM, da9052); | 564 | da9052_irq_exit(da9052); |
814 | mfd_remove_devices(da9052->dev); | 565 | |
815 | regmap_err: | ||
816 | return ret; | 566 | return ret; |
817 | } | 567 | } |
818 | 568 | ||
819 | void da9052_device_exit(struct da9052 *da9052) | 569 | void da9052_device_exit(struct da9052 *da9052) |
820 | { | 570 | { |
821 | free_irq(DA9052_IRQ_ADC_EOM, da9052); | ||
822 | regmap_del_irq_chip(da9052->chip_irq, da9052->irq_data); | ||
823 | mfd_remove_devices(da9052->dev); | 571 | mfd_remove_devices(da9052->dev); |
572 | da9052_irq_exit(da9052); | ||
824 | } | 573 | } |
825 | 574 | ||
826 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); | 575 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); |