diff options
author | Philipp Zabel <philipp.zabel@gmail.com> | 2009-01-31 06:13:57 -0500 |
---|---|---|
committer | Eric Miao <eric.miao@marvell.com> | 2009-04-03 20:24:38 -0400 |
commit | eb650b9ed0f69be075a5a86ef9c4fc2cf7915293 (patch) | |
tree | e616530198070f60581f093b64543e062b7981f4 /arch/arm/mach-pxa/magician.c | |
parent | 20bec8ab1458c24bed0d5492ee15d87807fc415a (diff) |
[ARM] pxa/magician: Enable bq24022 regulator for gpio_vbus and pda_power
With this patch, the bq24022 battery charger is controlled by the USB
gadget framework (via gpio_vbus) when connected to USB.
To compile, this patch depends on the "regulator: Allow init data to be
supplied for bq24022" patch (queued for next in the regulator tree) to
add the init_data field to struct bq24022_mach_info.
It also depends on the "add optional OTG transceiver and voltage
regulator support to pda_power" patch (queued for next in the power
supply tree) to enable charging when connected to the AC charger.
Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Diffstat (limited to 'arch/arm/mach-pxa/magician.c')
-rw-r--r-- | arch/arm/mach-pxa/magician.c | 84 |
1 files changed, 41 insertions, 43 deletions
diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c index d46b36746be2..2f753874f6be 100644 --- a/arch/arm/mach-pxa/magician.c +++ b/arch/arm/mach-pxa/magician.c | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <linux/mtd/physmap.h> | 25 | #include <linux/mtd/physmap.h> |
26 | #include <linux/pda_power.h> | 26 | #include <linux/pda_power.h> |
27 | #include <linux/pwm_backlight.h> | 27 | #include <linux/pwm_backlight.h> |
28 | #include <linux/regulator/bq24022.h> | ||
29 | #include <linux/regulator/machine.h> | ||
28 | #include <linux/usb/gpio_vbus.h> | 30 | #include <linux/usb/gpio_vbus.h> |
29 | 31 | ||
30 | #include <mach/hardware.h> | 32 | #include <mach/hardware.h> |
@@ -553,33 +555,7 @@ static struct platform_device gpio_vbus = { | |||
553 | 555 | ||
554 | static int power_supply_init(struct device *dev) | 556 | static int power_supply_init(struct device *dev) |
555 | { | 557 | { |
556 | int ret; | 558 | return gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC"); |
557 | |||
558 | ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC"); | ||
559 | if (ret) | ||
560 | goto err_cs_ac; | ||
561 | ret = gpio_request(EGPIO_MAGICIAN_CABLE_STATE_USB, "CABLE_STATE_USB"); | ||
562 | if (ret) | ||
563 | goto err_cs_usb; | ||
564 | ret = gpio_request(EGPIO_MAGICIAN_CHARGE_EN, "CHARGE_EN"); | ||
565 | if (ret) | ||
566 | goto err_chg_en; | ||
567 | ret = gpio_request(GPIO30_MAGICIAN_nCHARGE_EN, "nCHARGE_EN"); | ||
568 | if (!ret) | ||
569 | ret = gpio_direction_output(GPIO30_MAGICIAN_nCHARGE_EN, 0); | ||
570 | if (ret) | ||
571 | goto err_nchg_en; | ||
572 | |||
573 | return 0; | ||
574 | |||
575 | err_nchg_en: | ||
576 | gpio_free(EGPIO_MAGICIAN_CHARGE_EN); | ||
577 | err_chg_en: | ||
578 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB); | ||
579 | err_cs_usb: | ||
580 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC); | ||
581 | err_cs_ac: | ||
582 | return ret; | ||
583 | } | 559 | } |
584 | 560 | ||
585 | static int magician_is_ac_online(void) | 561 | static int magician_is_ac_online(void) |
@@ -587,22 +563,8 @@ static int magician_is_ac_online(void) | |||
587 | return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC); | 563 | return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC); |
588 | } | 564 | } |
589 | 565 | ||
590 | static int magician_is_usb_online(void) | ||
591 | { | ||
592 | return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_USB); | ||
593 | } | ||
594 | |||
595 | static void magician_set_charge(int flags) | ||
596 | { | ||
597 | gpio_set_value(GPIO30_MAGICIAN_nCHARGE_EN, !flags); | ||
598 | gpio_set_value(EGPIO_MAGICIAN_CHARGE_EN, flags); | ||
599 | } | ||
600 | |||
601 | static void power_supply_exit(struct device *dev) | 566 | static void power_supply_exit(struct device *dev) |
602 | { | 567 | { |
603 | gpio_free(GPIO30_MAGICIAN_nCHARGE_EN); | ||
604 | gpio_free(EGPIO_MAGICIAN_CHARGE_EN); | ||
605 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_USB); | ||
606 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC); | 568 | gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC); |
607 | } | 569 | } |
608 | 570 | ||
@@ -613,8 +575,6 @@ static char *magician_supplicants[] = { | |||
613 | static struct pda_power_pdata power_supply_info = { | 575 | static struct pda_power_pdata power_supply_info = { |
614 | .init = power_supply_init, | 576 | .init = power_supply_init, |
615 | .is_ac_online = magician_is_ac_online, | 577 | .is_ac_online = magician_is_ac_online, |
616 | .is_usb_online = magician_is_usb_online, | ||
617 | .set_charge = magician_set_charge, | ||
618 | .exit = power_supply_exit, | 578 | .exit = power_supply_exit, |
619 | .supplied_to = magician_supplicants, | 579 | .supplied_to = magician_supplicants, |
620 | .num_supplicants = ARRAY_SIZE(magician_supplicants), | 580 | .num_supplicants = ARRAY_SIZE(magician_supplicants), |
@@ -647,6 +607,43 @@ static struct platform_device power_supply = { | |||
647 | .num_resources = ARRAY_SIZE(power_supply_resources), | 607 | .num_resources = ARRAY_SIZE(power_supply_resources), |
648 | }; | 608 | }; |
649 | 609 | ||
610 | /* | ||
611 | * Battery charger | ||
612 | */ | ||
613 | |||
614 | static struct regulator_consumer_supply bq24022_consumers[] = { | ||
615 | { | ||
616 | .dev = &gpio_vbus.dev, | ||
617 | .supply = "vbus_draw", | ||
618 | }, | ||
619 | { | ||
620 | .dev = &power_supply.dev, | ||
621 | .supply = "ac_draw", | ||
622 | }, | ||
623 | }; | ||
624 | |||
625 | static struct regulator_init_data bq24022_init_data = { | ||
626 | .constraints = { | ||
627 | .max_uA = 500000, | ||
628 | .valid_ops_mask = REGULATOR_CHANGE_CURRENT, | ||
629 | }, | ||
630 | .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers), | ||
631 | .consumer_supplies = bq24022_consumers, | ||
632 | }; | ||
633 | |||
634 | static struct bq24022_mach_info bq24022_info = { | ||
635 | .gpio_nce = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN, | ||
636 | .gpio_iset2 = EGPIO_MAGICIAN_BQ24022_ISET2, | ||
637 | .init_data = &bq24022_init_data, | ||
638 | }; | ||
639 | |||
640 | static struct platform_device bq24022 = { | ||
641 | .name = "bq24022", | ||
642 | .id = -1, | ||
643 | .dev = { | ||
644 | .platform_data = &bq24022_info, | ||
645 | }, | ||
646 | }; | ||
650 | 647 | ||
651 | /* | 648 | /* |
652 | * MMC/SD | 649 | * MMC/SD |
@@ -757,6 +754,7 @@ static struct platform_device *devices[] __initdata = { | |||
757 | &egpio, | 754 | &egpio, |
758 | &backlight, | 755 | &backlight, |
759 | &pasic3, | 756 | &pasic3, |
757 | &bq24022, | ||
760 | &gpio_vbus, | 758 | &gpio_vbus, |
761 | &power_supply, | 759 | &power_supply, |
762 | &strataflash, | 760 | &strataflash, |