[ARM] 5099/1: Tosa: support AC-in detection.
authorDmitry Baryshkov <dbaryshkov@gmail.com>
Sat, 14 Jun 2008 10:43:36 +0000 (11:43 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Mon, 7 Jul 2008 12:22:05 +0000 (13:22 +0100)
Add support for ac-in via pda_power device.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mach-pxa/tosa.c

index 2fe0998ac3fbb101da4a5dfd1ccaefbb7990324a..f3b12d2897a63796934310e34de8e4f50c773883 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
 #include <linux/gpio.h>
+#include <linux/pda_power.h>
 
 #include <asm/setup.h>
 #include <asm/mach-types.h>
@@ -409,6 +410,70 @@ static struct pxaficp_platform_data tosa_ficp_platform_data = {
        .shutdown = tosa_irda_shutdown,
 };
 
+/*
+ * Tosa AC IN
+ */
+static int tosa_power_init(struct device *dev)
+{
+       int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
+       if (ret)
+               goto err_gpio_req;
+
+       ret = gpio_direction_input(TOSA_GPIO_AC_IN);
+       if (ret)
+               goto err_gpio_in;
+
+       return 0;
+
+err_gpio_in:
+       gpio_free(TOSA_GPIO_AC_IN);
+err_gpio_req:
+       return ret;
+}
+
+static void tosa_power_exit(struct device *dev)
+{
+       gpio_free(TOSA_GPIO_AC_IN);
+}
+
+static int tosa_power_ac_online(void)
+{
+       return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
+}
+
+static char *tosa_ac_supplied_to[] = {
+       "main-battery",
+       "backup-battery",
+       "jacket-battery",
+};
+
+static struct pda_power_pdata tosa_power_data = {
+       .init                   = tosa_power_init,
+       .is_ac_online           = tosa_power_ac_online,
+       .exit                   = tosa_power_exit,
+       .supplied_to            = tosa_ac_supplied_to,
+       .num_supplicants        = ARRAY_SIZE(tosa_ac_supplied_to),
+};
+
+static struct resource tosa_power_resource[] = {
+       {
+               .name           = "ac",
+               .start          = gpio_to_irq(TOSA_GPIO_AC_IN),
+               .end            = gpio_to_irq(TOSA_GPIO_AC_IN),
+               .flags          = IORESOURCE_IRQ |
+                                 IORESOURCE_IRQ_HIGHEDGE |
+                                 IORESOURCE_IRQ_LOWEDGE,
+       },
+};
+
+static struct platform_device tosa_power_device = {
+       .name                   = "pda-power",
+       .id                     = -1,
+       .dev.platform_data      = &tosa_power_data,
+       .resource               = tosa_power_resource,
+       .num_resources          = ARRAY_SIZE(tosa_power_resource),
+};
+
 /*
  * Tosa Keyboard
  */
@@ -633,6 +698,7 @@ static struct platform_device *devices[] __initdata = {
        &tosascoop_device,
        &tosascoop_jc_device,
        &tc6393xb_device,
+       &tosa_power_device,
        &tosakbd_device,
        &tosa_gpio_keys_device,
        &tosaled_device,