aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/da9052-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mfd/da9052-core.c')
-rw-r--r--drivers/mfd/da9052-core.c271
1 files changed, 8 insertions, 263 deletions
diff --git a/drivers/mfd/da9052-core.c b/drivers/mfd/da9052-core.c
index c96cdbc0daff..2153f9bba9ef 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
37static bool da9052_reg_readable(struct device *dev, unsigned int reg) 26static 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}
426EXPORT_SYMBOL_GPL(da9052_adc_manual_read); 415EXPORT_SYMBOL_GPL(da9052_adc_manual_read);
427 416
428static 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
437int da9052_adc_read_temp(struct da9052 *da9052) 417int 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}
448EXPORT_SYMBOL_GPL(da9052_adc_read_temp); 428EXPORT_SYMBOL_GPL(da9052_adc_read_temp);
449 429
450static struct resource da9052_rtc_resource = {
451 .name = "ALM",
452 .start = DA9052_IRQ_ALARM,
453 .end = DA9052_IRQ_ALARM,
454 .flags = IORESOURCE_IRQ,
455};
456
457static struct resource da9052_onkey_resource = {
458 .name = "ONKEY",
459 .start = DA9052_IRQ_NONKEY,
460 .end = DA9052_IRQ_NONKEY,
461 .flags = IORESOURCE_IRQ,
462};
463
464static 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
503static 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
518static struct mfd_cell __devinitdata da9052_subdev_info[] = { 430static struct mfd_cell __devinitdata da9052_subdev_info[] = {
519 { 431 {
520 .name = "da9052-regulator", 432 .name = "da9052-regulator",
@@ -574,13 +486,9 @@ static struct mfd_cell __devinitdata 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 __devinitdata 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
618static 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
749static 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
759struct regmap_config da9052_regmap_config = { 522struct regmap_config da9052_regmap_config = {
760 .reg_bits = 8, 523 .reg_bits = 8,
761 .val_bits = 8, 524 .val_bits = 8,
@@ -769,15 +532,10 @@ struct regmap_config da9052_regmap_config = {
769}; 532};
770EXPORT_SYMBOL_GPL(da9052_regmap_config); 533EXPORT_SYMBOL_GPL(da9052_regmap_config);
771 534
772static int da9052_map_irq(struct da9052 *da9052, int irq)
773{
774 return regmap_irq_get_virq(da9052->irq_data, irq);
775}
776
777int __devinit da9052_device_init(struct da9052 *da9052, u8 chip_id) 535int __devinit da9052_device_init(struct da9052 *da9052, u8 chip_id)
778{ 536{
779 struct da9052_pdata *pdata = da9052->dev->platform_data; 537 struct da9052_pdata *pdata = da9052->dev->platform_data;
780 int ret, i; 538 int ret;
781 539
782 mutex_init(&da9052->auxadc_lock); 540 mutex_init(&da9052->auxadc_lock);
783 init_completion(&da9052->done); 541 init_completion(&da9052->done);
@@ -787,22 +545,12 @@ int __devinit da9052_device_init(struct da9052 *da9052, u8 chip_id)
787 545
788 da9052->chip_id = chip_id; 546 da9052->chip_id = chip_id;
789 547
790 ret = regmap_add_irq_chip(da9052->regmap, da9052->chip_irq, 548 ret = da9052_irq_init(da9052);
791 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 549 if (ret != 0) {
792 -1, &da9052_regmap_irq_chip, 550 dev_err(da9052->dev, "da9052_irq_init failed: %d\n", ret);
793 &da9052->irq_data); 551 return ret;
794 if (ret < 0) {
795 dev_err(da9052->dev, "regmap_add_irq_chip failed: %d\n", ret);
796 goto regmap_err;
797 } 552 }
798 553
799 i = da9052_map_irq(da9052, DA9052_IRQ_ADC_EOM);
800 ret = request_threaded_irq(i, NULL, da9052_auxadc_irq,
801 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
802 "adc-irq", da9052);
803 if (ret != 0)
804 dev_err(da9052->dev, "DA9052 ADC IRQ failed ret=%d\n", ret);
805
806 ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info, 554 ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info,
807 ARRAY_SIZE(da9052_subdev_info), NULL, 0, NULL); 555 ARRAY_SIZE(da9052_subdev_info), NULL, 0, NULL);
808 if (ret) { 556 if (ret) {
@@ -813,18 +561,15 @@ int __devinit da9052_device_init(struct da9052 *da9052, u8 chip_id)
813 return 0; 561 return 0;
814 562
815err: 563err:
816 free_irq(da9052_map_irq(da9052, DA9052_IRQ_ADC_EOM), da9052); 564 da9052_irq_exit(da9052);
817 regmap_del_irq_chip(da9052->chip_irq, da9052->irq_data); 565
818 mfd_remove_devices(da9052->dev);
819regmap_err:
820 return ret; 566 return ret;
821} 567}
822 568
823void da9052_device_exit(struct da9052 *da9052) 569void da9052_device_exit(struct da9052 *da9052)
824{ 570{
825 free_irq(da9052_map_irq(da9052, DA9052_IRQ_ADC_EOM), da9052);
826 regmap_del_irq_chip(da9052->chip_irq, da9052->irq_data);
827 mfd_remove_devices(da9052->dev); 571 mfd_remove_devices(da9052->dev);
572 da9052_irq_exit(da9052);
828} 573}
829 574
830MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); 575MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");