aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-pxa
diff options
context:
space:
mode:
authorRobert Jarzmik <robert.jarzmik@free.fr>2008-11-15 10:09:59 -0500
committerEric Miao <eric.miao@marvell.com>2008-12-02 01:43:48 -0500
commit4aa89f973f515a9e456bcf23e448d5904d428d7d (patch)
treeb5cfad4147dbb501b19117346b84ed98a0acaf57 /arch/arm/mach-pxa
parentc96763d4dc2f4032369f068a5d185238e01da478 (diff)
[ARM] pxa/MioA701: improve power supply sources
Take advantage of the newly created wm97xx battery driver and remove useless code in mioa701 board code. Add also the ac connection detect capability after the matching gpio was discovered. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Eric Miao <eric.miao@marvell.com>
Diffstat (limited to 'arch/arm/mach-pxa')
-rw-r--r--arch/arm/mach-pxa/mioa701.c142
1 files changed, 26 insertions, 116 deletions
diff --git a/arch/arm/mach-pxa/mioa701.c b/arch/arm/mach-pxa/mioa701.c
index 04a2cb38b075..9207f10dfd13 100644
--- a/arch/arm/mach-pxa/mioa701.c
+++ b/arch/arm/mach-pxa/mioa701.c
@@ -34,7 +34,7 @@
34#include <linux/irq.h> 34#include <linux/irq.h>
35#include <linux/pda_power.h> 35#include <linux/pda_power.h>
36#include <linux/power_supply.h> 36#include <linux/power_supply.h>
37#include <linux/wm97xx.h> 37#include <linux/wm97xx_batt.h>
38#include <linux/mtd/physmap.h> 38#include <linux/mtd/physmap.h>
39 39
40#include <asm/mach-types.h> 40#include <asm/mach-types.h>
@@ -680,13 +680,19 @@ static char *supplicants[] = {
680 "mioa701_battery" 680 "mioa701_battery"
681}; 681};
682 682
683static int is_ac_connected(void)
684{
685 return gpio_get_value(GPIO96_AC_DETECT);
686}
687
683static void mioa701_set_charge(int flags) 688static void mioa701_set_charge(int flags)
684{ 689{
685 gpio_set_value(GPIO9_CHARGE_EN, (flags == PDA_POWER_CHARGE_USB)); 690 gpio_set_value(GPIO9_CHARGE_EN, (flags == PDA_POWER_CHARGE_USB));
686} 691}
687 692
688static struct pda_power_pdata power_pdata = { 693static struct pda_power_pdata power_pdata = {
689 .is_ac_online = is_usb_connected, 694 .is_ac_online = is_ac_connected,
695 .is_usb_online = is_usb_connected,
690 .set_charge = mioa701_set_charge, 696 .set_charge = mioa701_set_charge,
691 .supplied_to = supplicants, 697 .supplied_to = supplicants,
692 .num_supplicants = ARRAY_SIZE(supplicants), 698 .num_supplicants = ARRAY_SIZE(supplicants),
@@ -695,6 +701,13 @@ static struct pda_power_pdata power_pdata = {
695static struct resource power_resources[] = { 701static struct resource power_resources[] = {
696 [0] = { 702 [0] = {
697 .name = "ac", 703 .name = "ac",
704 .start = gpio_to_irq(GPIO96_AC_DETECT),
705 .end = gpio_to_irq(GPIO96_AC_DETECT),
706 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
707 IORESOURCE_IRQ_LOWEDGE,
708 },
709 [1] = {
710 .name = "usb",
698 .start = gpio_to_irq(GPIO13_nUSB_DETECT), 711 .start = gpio_to_irq(GPIO13_nUSB_DETECT),
699 .end = gpio_to_irq(GPIO13_nUSB_DETECT), 712 .end = gpio_to_irq(GPIO13_nUSB_DETECT),
700 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE | 713 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
@@ -712,121 +725,18 @@ static struct platform_device power_dev = {
712 }, 725 },
713}; 726};
714 727
715#if defined(CONFIG_PDA_POWER) && defined(CONFIG_TOUCHSCREEN_WM97XX) 728static struct wm97xx_batt_info mioa701_battery_data = {
716static struct wm97xx *battery_wm; 729 .batt_aux = WM97XX_AUX_ID1,
717 730 .temp_aux = -1,
718static enum power_supply_property battery_props[] = { 731 .charge_gpio = -1,
719 POWER_SUPPLY_PROP_STATUS, 732 .min_voltage = 0xc00,
720 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 733 .max_voltage = 0xfc0,
721 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 734 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LION,
722 POWER_SUPPLY_PROP_VOLTAGE_NOW, 735 .batt_div = 1,
723 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, /* Necessary for apm */ 736 .batt_mult = 1,
724}; 737 .batt_name = "mioa701_battery",
725
726static int get_battery_voltage(void)
727{
728 int adc = -1;
729
730 if (battery_wm)
731 adc = wm97xx_read_aux_adc(battery_wm, WM97XX_AUX_ID1);
732 return adc;
733}
734
735static int get_battery_status(struct power_supply *b)
736{
737 int status;
738
739 if (is_usb_connected())
740 status = POWER_SUPPLY_STATUS_CHARGING;
741 else
742 status = POWER_SUPPLY_STATUS_DISCHARGING;
743
744 return status;
745}
746
747static int get_property(struct power_supply *b,
748 enum power_supply_property psp,
749 union power_supply_propval *val)
750{
751 int rc = 0;
752
753 switch (psp) {
754 case POWER_SUPPLY_PROP_STATUS:
755 val->intval = get_battery_status(b);
756 break;
757 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
758 val->intval = 0xfd0;
759 break;
760 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
761 val->intval = 0xc00;
762 break;
763 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
764 val->intval = get_battery_voltage();
765 break;
766 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
767 val->intval = 100;
768 break;
769 default:
770 val->intval = -1;
771 rc = -1;
772 }
773
774 return rc;
775};
776
777static struct power_supply battery_ps = {
778 .name = "mioa701_battery",
779 .type = POWER_SUPPLY_TYPE_BATTERY,
780 .get_property = get_property,
781 .properties = battery_props,
782 .num_properties = ARRAY_SIZE(battery_props),
783}; 738};
784 739
785static int battery_probe(struct platform_device *pdev)
786{
787 struct wm97xx *wm = platform_get_drvdata(pdev);
788 int rc;
789
790 battery_wm = wm;
791
792 rc = power_supply_register(NULL, &battery_ps);
793 if (rc)
794 dev_err(&pdev->dev,
795 "Could not register mioa701 battery -> %d\n", rc);
796 return rc;
797}
798
799static int battery_remove(struct platform_device *pdev)
800{
801 battery_wm = NULL;
802 return 0;
803}
804
805static struct platform_driver mioa701_battery_driver = {
806 .driver = {
807 .name = "wm97xx-battery",
808 },
809 .probe = battery_probe,
810 .remove = battery_remove
811};
812
813static int __init mioa701_battery_init(void)
814{
815 int rc;
816
817 rc = platform_driver_register(&mioa701_battery_driver);
818 if (rc)
819 printk(KERN_ERR "Could not register mioa701 battery driver\n");
820 return rc;
821}
822
823#else
824static int __init mioa701_battery_init(void)
825{
826 return 0;
827}
828#endif
829
830/* 740/*
831 * Camera interface 741 * Camera interface
832 */ 742 */
@@ -926,12 +836,12 @@ static void __init mioa701_machine_init(void)
926 set_pxa_fb_info(&mioa701_pxafb_info); 836 set_pxa_fb_info(&mioa701_pxafb_info);
927 pxa_set_mci_info(&mioa701_mci_info); 837 pxa_set_mci_info(&mioa701_mci_info);
928 pxa_set_keypad_info(&mioa701_keypad_info); 838 pxa_set_keypad_info(&mioa701_keypad_info);
839 wm97xx_bat_set_pdata(&mioa701_battery_data);
929 udc_init(); 840 udc_init();
930 pm_power_off = mioa701_poweroff; 841 pm_power_off = mioa701_poweroff;
931 arm_pm_restart = mioa701_restart; 842 arm_pm_restart = mioa701_restart;
932 platform_add_devices(devices, ARRAY_SIZE(devices)); 843 platform_add_devices(devices, ARRAY_SIZE(devices));
933 gsm_init(); 844 gsm_init();
934 mioa701_battery_init();
935 845
936 pxa_set_i2c_info(&i2c_pdata); 846 pxa_set_i2c_info(&i2c_pdata);
937 pxa_set_camera_info(&mioa701_pxacamera_platform_data); 847 pxa_set_camera_info(&mioa701_pxacamera_platform_data);