aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/twl-core.c
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@ti.com>2013-01-16 08:53:52 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2013-02-13 18:22:50 -0500
commit3c3302794cc79b363779a762051ebe8670812791 (patch)
tree1726b75b546886a8d43968577d391736be0232fa /drivers/mfd/twl-core.c
parent050cde1363a3fc59f2a2f1cac6ef050393a00c99 (diff)
mfd: twl-core: Use the lookup table to find the correct subchip for the modules
Instead of using SUB_CHIP_ID* or magic numbers use the twl_mapping table to look for the subchip ID. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/twl-core.c')
-rw-r--r--drivers/mfd/twl-core.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index fa1a5a0fa759..f07317b35e4a 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -68,11 +68,6 @@
68 68
69#define TWL_NUM_SLAVES 4 69#define TWL_NUM_SLAVES 4
70 70
71#define SUB_CHIP_ID0 0
72#define SUB_CHIP_ID1 1
73#define SUB_CHIP_ID2 2
74#define SUB_CHIP_ID3 3
75
76/* Base Address defns for twl4030_map[] */ 71/* Base Address defns for twl4030_map[] */
77 72
78/* subchip/slave 0 - USB ID */ 73/* subchip/slave 0 - USB ID */
@@ -493,13 +488,20 @@ int twl_get_hfclk_rate(void)
493EXPORT_SYMBOL_GPL(twl_get_hfclk_rate); 488EXPORT_SYMBOL_GPL(twl_get_hfclk_rate);
494 489
495static struct device * 490static struct device *
496add_numbered_child(unsigned chip, const char *name, int num, 491add_numbered_child(unsigned mod_no, const char *name, int num,
497 void *pdata, unsigned pdata_len, 492 void *pdata, unsigned pdata_len,
498 bool can_wakeup, int irq0, int irq1) 493 bool can_wakeup, int irq0, int irq1)
499{ 494{
500 struct platform_device *pdev; 495 struct platform_device *pdev;
501 struct twl_client *twl = &twl_modules[chip]; 496 struct twl_client *twl;
502 int status; 497 int status, sid;
498
499 if (unlikely(mod_no >= twl_get_last_module())) {
500 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
501 return ERR_PTR(-EPERM);
502 }
503 sid = twl_map[mod_no].sid;
504 twl = &twl_modules[sid];
503 505
504 pdev = platform_device_alloc(name, num); 506 pdev = platform_device_alloc(name, num);
505 if (!pdev) { 507 if (!pdev) {
@@ -544,11 +546,11 @@ err:
544 return &pdev->dev; 546 return &pdev->dev;
545} 547}
546 548
547static inline struct device *add_child(unsigned chip, const char *name, 549static inline struct device *add_child(unsigned mod_no, const char *name,
548 void *pdata, unsigned pdata_len, 550 void *pdata, unsigned pdata_len,
549 bool can_wakeup, int irq0, int irq1) 551 bool can_wakeup, int irq0, int irq1)
550{ 552{
551 return add_numbered_child(chip, name, -1, pdata, pdata_len, 553 return add_numbered_child(mod_no, name, -1, pdata, pdata_len,
552 can_wakeup, irq0, irq1); 554 can_wakeup, irq0, irq1);
553} 555}
554 556
@@ -557,7 +559,6 @@ add_regulator_linked(int num, struct regulator_init_data *pdata,
557 struct regulator_consumer_supply *consumers, 559 struct regulator_consumer_supply *consumers,
558 unsigned num_consumers, unsigned long features) 560 unsigned num_consumers, unsigned long features)
559{ 561{
560 unsigned sub_chip_id;
561 struct twl_regulator_driver_data drv_data; 562 struct twl_regulator_driver_data drv_data;
562 563
563 /* regulator framework demands init_data ... */ 564 /* regulator framework demands init_data ... */
@@ -584,8 +585,7 @@ add_regulator_linked(int num, struct regulator_init_data *pdata,
584 } 585 }
585 586
586 /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */ 587 /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */
587 sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid; 588 return add_numbered_child(TWL_MODULE_PM_MASTER, "twl_reg", num,
588 return add_numbered_child(sub_chip_id, "twl_reg", num,
589 pdata, sizeof(*pdata), false, 0, 0); 589 pdata, sizeof(*pdata), false, 0, 0);
590} 590}
591 591
@@ -607,10 +607,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
607 unsigned long features) 607 unsigned long features)
608{ 608{
609 struct device *child; 609 struct device *child;
610 unsigned sub_chip_id;
611 610
612 if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) { 611 if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) {
613 child = add_child(SUB_CHIP_ID1, "twl4030_gpio", 612 child = add_child(TWL4030_MODULE_GPIO, "twl4030_gpio",
614 pdata->gpio, sizeof(*pdata->gpio), 613 pdata->gpio, sizeof(*pdata->gpio),
615 false, irq_base + GPIO_INTR_OFFSET, 0); 614 false, irq_base + GPIO_INTR_OFFSET, 0);
616 if (IS_ERR(child)) 615 if (IS_ERR(child))
@@ -618,7 +617,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
618 } 617 }
619 618
620 if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) { 619 if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) {
621 child = add_child(SUB_CHIP_ID2, "twl4030_keypad", 620 child = add_child(TWL4030_MODULE_KEYPAD, "twl4030_keypad",
622 pdata->keypad, sizeof(*pdata->keypad), 621 pdata->keypad, sizeof(*pdata->keypad),
623 true, irq_base + KEYPAD_INTR_OFFSET, 0); 622 true, irq_base + KEYPAD_INTR_OFFSET, 0);
624 if (IS_ERR(child)) 623 if (IS_ERR(child))
@@ -627,7 +626,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
627 626
628 if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc && 627 if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc &&
629 twl_class_is_4030()) { 628 twl_class_is_4030()) {
630 child = add_child(SUB_CHIP_ID2, "twl4030_madc", 629 child = add_child(TWL4030_MODULE_MADC, "twl4030_madc",
631 pdata->madc, sizeof(*pdata->madc), 630 pdata->madc, sizeof(*pdata->madc),
632 true, irq_base + MADC_INTR_OFFSET, 0); 631 true, irq_base + MADC_INTR_OFFSET, 0);
633 if (IS_ERR(child)) 632 if (IS_ERR(child))
@@ -642,22 +641,21 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
642 * Eventually, Linux might become more aware of such 641 * Eventually, Linux might become more aware of such
643 * HW security concerns, and "least privilege". 642 * HW security concerns, and "least privilege".
644 */ 643 */
645 sub_chip_id = twl_map[TWL_MODULE_RTC].sid; 644 child = add_child(TWL_MODULE_RTC, "twl_rtc", NULL, 0,
646 child = add_child(sub_chip_id, "twl_rtc", NULL, 0,
647 true, irq_base + RTC_INTR_OFFSET, 0); 645 true, irq_base + RTC_INTR_OFFSET, 0);
648 if (IS_ERR(child)) 646 if (IS_ERR(child))
649 return PTR_ERR(child); 647 return PTR_ERR(child);
650 } 648 }
651 649
652 if (IS_ENABLED(CONFIG_PWM_TWL)) { 650 if (IS_ENABLED(CONFIG_PWM_TWL)) {
653 child = add_child(SUB_CHIP_ID1, "twl-pwm", NULL, 0, 651 child = add_child(TWL_MODULE_PWM, "twl-pwm", NULL, 0,
654 false, 0, 0); 652 false, 0, 0);
655 if (IS_ERR(child)) 653 if (IS_ERR(child))
656 return PTR_ERR(child); 654 return PTR_ERR(child);
657 } 655 }
658 656
659 if (IS_ENABLED(CONFIG_PWM_TWL_LED)) { 657 if (IS_ENABLED(CONFIG_PWM_TWL_LED)) {
660 child = add_child(SUB_CHIP_ID1, "twl-pwmled", NULL, 0, 658 child = add_child(TWL_MODULE_LED, "twl-pwmled", NULL, 0,
661 false, 0, 0); 659 false, 0, 0);
662 if (IS_ERR(child)) 660 if (IS_ERR(child))
663 return PTR_ERR(child); 661 return PTR_ERR(child);
@@ -709,7 +707,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
709 707
710 } 708 }
711 709
712 child = add_child(SUB_CHIP_ID0, "twl4030_usb", 710 child = add_child(TWL_MODULE_USB, "twl4030_usb",
713 pdata->usb, sizeof(*pdata->usb), true, 711 pdata->usb, sizeof(*pdata->usb), true,
714 /* irq0 = USB_PRES, irq1 = USB */ 712 /* irq0 = USB_PRES, irq1 = USB */
715 irq_base + USB_PRES_INTR_OFFSET, 713 irq_base + USB_PRES_INTR_OFFSET,
@@ -758,7 +756,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
758 756
759 pdata->usb->features = features; 757 pdata->usb->features = features;
760 758
761 child = add_child(SUB_CHIP_ID0, "twl6030_usb", 759 child = add_child(TWL_MODULE_USB, "twl6030_usb",
762 pdata->usb, sizeof(*pdata->usb), true, 760 pdata->usb, sizeof(*pdata->usb), true,
763 /* irq1 = VBUS_PRES, irq0 = USB ID */ 761 /* irq1 = VBUS_PRES, irq0 = USB ID */
764 irq_base + USBOTG_INTR_OFFSET, 762 irq_base + USBOTG_INTR_OFFSET,
@@ -783,22 +781,22 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
783 } 781 }
784 782
785 if (IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) { 783 if (IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) {
786 child = add_child(SUB_CHIP_ID3, "twl4030_wdt", NULL, 0, 784 child = add_child(TWL_MODULE_PM_RECEIVER, "twl4030_wdt", NULL,
787 false, 0, 0); 785 0, false, 0, 0);
788 if (IS_ERR(child)) 786 if (IS_ERR(child))
789 return PTR_ERR(child); 787 return PTR_ERR(child);
790 } 788 }
791 789
792 if (IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) { 790 if (IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) {
793 child = add_child(SUB_CHIP_ID3, "twl4030_pwrbutton", NULL, 0, 791 child = add_child(TWL_MODULE_PM_MASTER, "twl4030_pwrbutton",
794 true, irq_base + 8 + 0, 0); 792 NULL, 0, true, irq_base + 8 + 0, 0);
795 if (IS_ERR(child)) 793 if (IS_ERR(child))
796 return PTR_ERR(child); 794 return PTR_ERR(child);
797 } 795 }
798 796
799 if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio && 797 if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio &&
800 twl_class_is_4030()) { 798 twl_class_is_4030()) {
801 child = add_child(SUB_CHIP_ID1, "twl4030-audio", 799 child = add_child(TWL4030_MODULE_AUDIO_VOICE, "twl4030-audio",
802 pdata->audio, sizeof(*pdata->audio), 800 pdata->audio, sizeof(*pdata->audio),
803 false, 0, 0); 801 false, 0, 0);
804 if (IS_ERR(child)) 802 if (IS_ERR(child))
@@ -1038,7 +1036,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
1038 1036
1039 if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci && 1037 if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci &&
1040 !(features & (TPS_SUBSET | TWL5031))) { 1038 !(features & (TPS_SUBSET | TWL5031))) {
1041 child = add_child(SUB_CHIP_ID3, "twl4030_bci", 1039 child = add_child(TWL_MODULE_MAIN_CHARGE, "twl4030_bci",
1042 pdata->bci, sizeof(*pdata->bci), false, 1040 pdata->bci, sizeof(*pdata->bci), false,
1043 /* irq0 = CHG_PRES, irq1 = BCI */ 1041 /* irq0 = CHG_PRES, irq1 = BCI */
1044 irq_base + BCI_PRES_INTR_OFFSET, 1042 irq_base + BCI_PRES_INTR_OFFSET,