]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/arm/mach-pxa/corgi_pm.c
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6-omap-h63xx.git] / arch / arm / mach-pxa / corgi_pm.c
index 599be14754f938f8776ca502340b44df13b416fa..392c38717362751b9614ae88e1db1abff6c229c7 100644 (file)
@@ -16,7 +16,8 @@
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
-#include <asm/apm.h>
+#include <linux/apm-emulation.h>
+
 #include <asm/irq.h>
 #include <asm/mach-types.h>
 #include <asm/hardware.h>
 #include <asm/arch/pxa-regs.h>
 #include "sharpsl.h"
 
+#define SHARPSL_CHARGE_ON_VOLT         0x99  /* 2.9V */
+#define SHARPSL_CHARGE_ON_TEMP         0xe0  /* 2.9V */
+#define SHARPSL_CHARGE_ON_ACIN_HIGH    0x9b  /* 6V */
+#define SHARPSL_CHARGE_ON_ACIN_LOW     0x34  /* 2V */
+#define SHARPSL_FATAL_ACIN_VOLT        182   /* 3.45V */
+#define SHARPSL_FATAL_NOACIN_VOLT      170   /* 3.40V */
+
 static void corgi_charger_init(void)
 {
        pxa_gpio_mode(CORGI_GPIO_ADC_TEMP_ON | GPIO_OUT);
        pxa_gpio_mode(CORGI_GPIO_CHRG_ON | GPIO_OUT);
        pxa_gpio_mode(CORGI_GPIO_CHRG_UKN | GPIO_OUT);
        pxa_gpio_mode(CORGI_GPIO_KEY_INT | GPIO_IN);
-}
-
-static void corgi_charge_led(int val)
-{
-       if (val == SHARPSL_LED_ERROR) {
-               dev_dbg(sharpsl_pm.dev, "Charge LED Error\n");
-       } else if (val == SHARPSL_LED_ON) {
-               dev_dbg(sharpsl_pm.dev, "Charge LED On\n");
-               GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
-       } else {
-               dev_dbg(sharpsl_pm.dev, "Charge LED Off\n");
-               GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
-       }
+       sharpsl_pm_pxa_init();
 }
 
 static void corgi_measure_temp(int on)
@@ -138,15 +134,15 @@ static int corgi_should_wakeup(unsigned int resume_on_alarm)
        dev_dbg(sharpsl_pm.dev, "GPLR0 = %x,%x\n", GPLR0, PEDR);
 
        if ((PEDR & GPIO_bit(CORGI_GPIO_AC_IN))) {
-               if (STATUS_AC_IN()) {
+               if (sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN)) {
                        /* charge on */
                        dev_dbg(sharpsl_pm.dev, "ac insert\n");
                        sharpsl_pm.flags |= SHARPSL_DO_OFFLINE_CHRG;
                } else {
                        /* charge off */
                        dev_dbg(sharpsl_pm.dev, "ac remove\n");
-                       CHARGE_LED_OFF();
-                       CHARGE_OFF();
+                       sharpsl_pm_led(SHARPSL_LED_OFF);
+                       sharpsl_pm.machinfo->charge(0);
                        sharpsl_pm.charge_mode = CHRG_OFF;
                }
        }
@@ -172,28 +168,51 @@ static unsigned long corgi_charger_wakeup(void)
        return ~GPLR0 & ( GPIO_bit(CORGI_GPIO_AC_IN) | GPIO_bit(CORGI_GPIO_KEY_INT) | GPIO_bit(CORGI_GPIO_WAKEUP) );
 }
 
-static int corgi_acin_status(void)
+unsigned long corgipm_read_devdata(int type)
 {
-       return ((GPLR(CORGI_GPIO_AC_IN) & GPIO_bit(CORGI_GPIO_AC_IN)) != 0);
+       switch(type) {
+       case SHARPSL_STATUS_ACIN:
+               return ((GPLR(CORGI_GPIO_AC_IN) & GPIO_bit(CORGI_GPIO_AC_IN)) != 0);
+       case SHARPSL_STATUS_LOCK:
+               return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batlock);
+       case SHARPSL_STATUS_CHRGFULL:
+               return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_batfull);
+       case SHARPSL_STATUS_FATAL:
+               return READ_GPIO_BIT(sharpsl_pm.machinfo->gpio_fatal);
+       case SHARPSL_ACIN_VOLT:
+               return sharpsl_pm_pxa_read_max1111(MAX1111_ACIN_VOLT);
+       case SHARPSL_BATT_TEMP:
+               return sharpsl_pm_pxa_read_max1111(MAX1111_BATT_TEMP);
+       case SHARPSL_BATT_VOLT:
+       default:
+               return sharpsl_pm_pxa_read_max1111(MAX1111_BATT_VOLT);
+       }
 }
 
 static struct sharpsl_charger_machinfo corgi_pm_machinfo = {
        .init            = corgi_charger_init,
+       .exit            = sharpsl_pm_pxa_remove,
        .gpio_batlock    = CORGI_GPIO_BAT_COVER,
        .gpio_acin       = CORGI_GPIO_AC_IN,
        .gpio_batfull    = CORGI_GPIO_CHRG_FULL,
-       .status_acin     = corgi_acin_status,
        .discharge       = corgi_discharge,
        .charge          = corgi_charge,
-       .chargeled       = corgi_charge_led,
        .measure_temp    = corgi_measure_temp,
        .presuspend      = corgi_presuspend,
        .postsuspend     = corgi_postsuspend,
+       .read_devdata    = corgipm_read_devdata,
        .charger_wakeup  = corgi_charger_wakeup,
        .should_wakeup   = corgi_should_wakeup,
-       .bat_levels      = 40,
-       .bat_levels_noac = spitz_battery_levels_noac,
-       .bat_levels_acin = spitz_battery_levels_acin,
+       .backlight_limit = corgibl_limit_intensity,
+       .charge_on_volt   = SHARPSL_CHARGE_ON_VOLT,
+       .charge_on_temp   = SHARPSL_CHARGE_ON_TEMP,
+       .charge_acin_high = SHARPSL_CHARGE_ON_ACIN_HIGH,
+       .charge_acin_low  = SHARPSL_CHARGE_ON_ACIN_LOW,
+       .fatal_acin_volt  = SHARPSL_FATAL_ACIN_VOLT,
+       .fatal_noacin_volt= SHARPSL_FATAL_NOACIN_VOLT,
+       .bat_levels       = 40,
+       .bat_levels_noac  = spitz_battery_levels_noac,
+       .bat_levels_acin  = spitz_battery_levels_acin,
        .status_high_acin = 188,
        .status_low_acin  = 178,
        .status_high_noac = 185,
@@ -210,6 +229,9 @@ static int __devinit corgipm_init(void)
        if (!corgipm_device)
                return -ENOMEM;
 
+       if (!machine_is_corgi())
+           corgi_pm_machinfo.batfull_irq = 1;
+
        corgipm_device->dev.platform_data = &corgi_pm_machinfo;
        ret = platform_device_add(corgipm_device);