]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
twl4030-bci: move to new style registration method
authorFelipe Balbi <felipe.balbi@nokia.com>
Tue, 30 Sep 2008 18:43:07 +0000 (21:43 +0300)
committerTony Lindgren <tony@atomide.com>
Wed, 1 Oct 2008 10:37:39 +0000 (13:37 +0300)
twl4030_bci_battery.c is now moved to new style
registration of twl4030 children.

During the process a few bugfixes came, the main one
is that twl4030-bci was releasing the wrong irq if
battery registration had failed.

Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
arch/arm/mach-omap2/Makefile
arch/arm/mach-omap2/bci.c [deleted file]
arch/arm/mach-omap2/board-3430sdp.c
arch/arm/mach-omap2/board-ldp.c
arch/arm/plat-omap/include/mach/bci.h [deleted file]
drivers/i2c/chips/twl4030-core.c
drivers/power/twl4030_bci_battery.c
include/linux/i2c/twl4030.h

index e18da0c818f36a38b09229aa822622891b03df16..33de217cecb1deee61bb744f25f5c235b713a6a8 100644 (file)
@@ -54,8 +54,7 @@ obj-$(CONFIG_MACH_OMAP_3430SDP)               += board-3430sdp.o \
                                           hsmmc.o \
                                           usb-musb.o \
                                           usb-ehci.o \
-                                          board-3430sdp-flash.o \
-                                          bci.o
+                                          board-3430sdp-flash.o
 obj-$(CONFIG_MACH_OMAP3EVM)            += board-omap3evm.o \
                                           hsmmc.o \
                                           usb-musb.o usb-ehci.o \
@@ -65,7 +64,6 @@ obj-$(CONFIG_MACH_OMAP3_BEAGLE)               += board-omap3beagle.o \
                                           hsmmc.o
 obj-$(CONFIG_MACH_OMAP_LDP)            += board-ldp.o \
                                           hsmmc.o \
-                                          bci.o \
                                           usb-musb.o
 obj-$(CONFIG_MACH_OMAP_APOLLON)                += board-apollon.o \
                                           board-apollon-mmc.o  \
diff --git a/arch/arm/mach-omap2/bci.c b/arch/arm/mach-omap2/bci.c
deleted file mode 100644 (file)
index 9b9f9d2..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * linux/arch/arm/mach-omap2/bci.c
- *
- * TWL4030 BCI platform device setup/initialization
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-#include <mach/bci.h>
-
-#if defined(CONFIG_TWL4030_BCI_BATTERY) || \
-       defined(CONFIG_TWL4030_BCI_BATTERY_MODULE)
-/*
- * Thermistor Calibration for Current Source and MADC
- * Tolerance (for THS05-3H103F)
- */
-static int sdp3430_batt_table[] = {
-/* 0 C*/
-30800, 29500, 28300, 27100,
-26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
-17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
-11600, 11200, 10800, 10400, 10000, 9630,   9280,   8950,   8620,   8310,
-8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,
-5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,
-4040,   3910,   3790,   3670,   3550
-};
-
-static struct twl4030_bci_platform_data sdp3430_bci_data = {
-      .battery_tmp_tbl = sdp3430_batt_table,
-      .tblsize = ARRAY_SIZE(sdp3430_batt_table),
-};
-
-static struct platform_device twl4030_bci_battery_device = {
-       .name           = "twl4030-bci-battery",
-       .id             = -1,
-       .dev            = {
-               .platform_data  = &sdp3430_bci_data,
-       },
-       .num_resources  = 0,
-};
-
-void __init twl4030_bci_battery_init(void)
-{
-       (void) platform_device_register(&twl4030_bci_battery_device);
-}
-#else
-void __init twl4030_bci_battery_init(void)
-{
-}
-#endif
index 661d5d06a249bbc3e53ea94df05d6c363eadd3cb..4264b68a45a4ff90942b65b9d9009c32872a966b 100644 (file)
@@ -300,6 +300,22 @@ static struct omap_board_config_kernel sdp3430_config[] __initdata = {
        { OMAP_TAG_LCD,         &sdp3430_lcd_config },
 };
 
+static int sdp3430_batt_table[] = {
+/* 0 C*/
+30800, 29500, 28300, 27100,
+26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
+17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
+11600, 11200, 10800, 10400, 10000, 9630,   9280,   8950,   8620,   8310,
+8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,
+5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,
+4040,   3910,   3790,   3670,   3550
+};
+
+static struct twl4030_bci_platform_data sdp3430_bci_data = {
+      .battery_tmp_tbl = sdp3430_batt_table,
+      .tblsize         = ARRAY_SIZE(sdp3430_batt_table),
+};
+
 static struct twl4030_gpio_platform_data sdp3430_gpio_data = {
        .gpio_base      = OMAP_MAX_GPIO_LINES,
        .irq_base       = TWL4030_GPIO_IRQ_BASE,
@@ -319,6 +335,7 @@ static struct twl4030_platform_data sdp3430_twldata = {
        .irq_end        = TWL4030_IRQ_END,
 
        /* platform_data for children goes here */
+       .bci            = &sdp3430_bci_data,
        .gpio           = &sdp3430_gpio_data,
        .madc           = &sdp3430_madc_data,
        .keypad         = &sdp3430_kp_data,
@@ -361,7 +378,6 @@ static void __init omap_3430sdp_init(void)
        ads7846_dev_init();
        sdp3430_flash_init();
        msecure_init();
-       twl4030_bci_battery_init();
        omap_serial_init();
        usb_musb_init();
        usb_ehci_init();
index a0e2c7a8550d3349f4338dea77701ec213406abb..35c03b764c2350c2fbbb2c6c921774dfdaba4caf 100644 (file)
@@ -183,6 +183,22 @@ static struct omap_board_config_kernel ldp_config[] __initdata = {
        { OMAP_TAG_UART,        &ldp_uart_config },
 };
 
+static int ldp_batt_table[] = {
+/* 0 C*/
+30800, 29500, 28300, 27100,
+26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900,
+17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100,
+11600, 11200, 10800, 10400, 10000, 9630,   9280,   8950,   8620,   8310,
+8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,
+5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,
+4040,   3910,   3790,   3670,   3550
+};
+
+static struct twl4030_bci_platform_data ldp_bci_data = {
+      .battery_tmp_tbl = ldp_batt_table,
+      .tblsize         = ARRAY_SIZE(ldp_batt_table),
+};
+
 static struct twl4030_usb_data ldp_usb_data = {
        .usb_mode       = T2_USB_MODE_ULPI,
 };
@@ -202,6 +218,7 @@ static struct twl4030_platform_data ldp_twldata = {
        .irq_end        = TWL4030_IRQ_END,
 
        /* platform_data for children goes here */
+       .bci            = &ldp_bci_data,
        .madc           = &ldp_madc_data,
        .usb            = &ldp_usb_data,
        .gpio           = &ldp_gpio_data,
@@ -237,7 +254,6 @@ static void __init omap_ldp_init(void)
                                ARRAY_SIZE(ldp_spi_board_info));
        msecure_init();
        ads7846_dev_init();
-       twl4030_bci_battery_init();
        omap_serial_init();
        usb_musb_init();
        hsmmc_init();
diff --git a/arch/arm/plat-omap/include/mach/bci.h b/arch/arm/plat-omap/include/mach/bci.h
deleted file mode 100644 (file)
index 9baf59e..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- *  arch/arm/plat-omap/include/mach/bci.h
- *
- *  Copyright (C) 2008 Texas Instruments, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#ifndef ASMARM_ARCH_BCI_H
-#define ASMARM_ARCH_BCI_H
-struct twl4030_bci_platform_data {
-       int *battery_tmp_tbl;
-       unsigned int tblsize;
-};
-#endif
-
index efba776cdb11e08128e0a661aad09d6a979561c2..9debab4eccb44228b41d272f8db359ee28f15a31 100644 (file)
 
 #define DRIVER_NAME                    "twl4030"
 
+#if defined(CONFIG_TWL4030_BCI_BATTERY) || \
+       defined(CONFIG_TWL4030_BCI_BATTERY_MODUEL)
+#define twl_has_bci()          true
+#else
+#define twl_has_bci()          false
+#endif
+
 #if defined(CONFIG_KEYBOARD_TWL4030) || defined(CONFIG_KEYBOARD_TWL4030_MODULE)
 #define twl_has_keypad()       true
 #else
@@ -681,6 +688,49 @@ static int add_children(struct twl4030_platform_data *pdata)
        struct twl4030_client   *twl = NULL;
        int                     status = 0;
 
+       if (twl_has_bci() && pdata->bci) {
+               twl = &twl4030_modules[TWL4030_SLAVENUM_NUM3];
+
+               pdev = platform_device_alloc("twl4030_bci", -1);
+               if (!pdev) {
+                       pr_debug("%s: can't alloc bci dev\n", DRIVER_NAME);
+                       status = -ENOMEM;
+                       goto err;
+               }
+
+               if (status == 0) {
+                       pdev->dev.parent = &twl->client->dev;
+                       status = platform_device_add_data(pdev, pdata->bci,
+                                       sizeof(*pdata->bci));
+                       if (status < 0) {
+                               dev_dbg(&twl->client->dev,
+                                       "can't add bci data, %d\n",
+                                       status);
+                               goto err;
+                       }
+               }
+
+               if (status == 0) {
+                       struct resource r = {
+                               .start = TWL4030_PWRIRQ_CHG_PRES,
+                               .flags = IORESOURCE_IRQ,
+                       };
+
+                       status = platform_device_add_resources(pdev, &r, 1);
+               }
+
+               if (status == 0)
+                       status = platform_device_add(pdev);
+
+               if (status < 0) {
+                       platform_device_put(pdev);
+                       dev_dbg(&twl->client->dev,
+                                       "can't create bci dev, %d\n",
+                                       status);
+                       goto err;
+               }
+       }
+
        if (twl_has_gpio() && pdata->gpio) {
                twl = &twl4030_modules[TWL4030_SLAVENUM_NUM1];
 
index 9ab612725c23448961c6191ef19e2e61afb4f665..72a018ba4a3eb6e7f7d19ad09b0c522960787e3c 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/platform_device.h>
 #include <linux/i2c/twl4030.h>
 #include <linux/power_supply.h>
-#include <mach/bci.h>
 #include <linux/i2c/twl4030-madc.h>
 
 #define T2_BATTERY_VOLT                0x04
@@ -583,9 +582,8 @@ static int twl4030battery_current(void)
  */
 static int twl4030backupbatt_voltage(void)
 {
-       int ret, temp;
-       u8 volt;
        struct twl4030_madc_request req;
+       int temp;
 
        req.channels = (1 << 9);
        req.do_avg = 0;
@@ -826,9 +824,11 @@ static int twl4030_bci_battery_get_property(struct power_supply *psy,
                                        enum power_supply_property psp,
                                        union power_supply_propval *val)
 {
-       struct twl4030_bci_device_info *di = to_twl4030_bci_device_info(psy);
+       struct twl4030_bci_device_info *di;
        int status = 0;
 
+       di = to_twl4030_bci_device_info(psy);
+
        switch (psp) {
        case POWER_SUPPLY_PROP_STATUS:
                val->intval = di->charge_status;
@@ -893,6 +893,7 @@ static int __init twl4030_bci_battery_probe(struct platform_device *pdev)
 {
        struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
        struct twl4030_bci_device_info *di;
+       int irq;
        int ret;
 
        therm_tbl = pdata->battery_tmp_tbl;
@@ -938,6 +939,8 @@ static int __init twl4030_bci_battery_probe(struct platform_device *pdev)
        if (ret)
                goto voltage_setup_fail;
 
+       /* REVISIT do we need to request both IRQs ?? */
+
        /* request BCI interruption */
        ret = request_irq(TWL4030_MODIRQ_BCI, twl4030battery_interrupt,
                IRQF_DISABLED, pdev->name, NULL);
@@ -947,17 +950,19 @@ static int __init twl4030_bci_battery_probe(struct platform_device *pdev)
                goto batt_irq_fail;
        }
 
+       irq = platform_get_irq(pdev, 0);
+
        /* request Power interruption */
-       ret = request_irq(TWL4030_PWRIRQ_CHG_PRES, twl4030charger_interrupt,
+       ret = request_irq(irq, twl4030charger_interrupt,
                0, pdev->name, di);
 
        if (ret) {
                dev_dbg(&pdev->dev, "could not request irq %d, status %d\n",
-                       TWL4030_PWRIRQ_CHG_PRES, ret);
+                       irq, ret);
                goto chg_irq_fail;
        }
 
-       ret = power_supply_register(&dev->dev, &di->bat);
+       ret = power_supply_register(&pdev->dev, &di->bat);
        if (ret) {
                dev_dbg(&pdev->dev, "failed to register main battery\n");
                goto batt_failed;
@@ -982,9 +987,8 @@ static int __init twl4030_bci_battery_probe(struct platform_device *pdev)
 bk_batt_failed:
        power_supply_unregister(&di->bat);
 batt_failed:
-       free_irq(TWL4030_MODIRQ_PWR, di);
+       free_irq(irq, di);
 chg_irq_fail:
-prev_setup_err:
        free_irq(TWL4030_MODIRQ_BCI, NULL);
 batt_irq_fail:
 voltage_setup_fail:
@@ -1001,6 +1005,7 @@ temp_setup_fail:
 static int __exit twl4030_bci_battery_remove(struct platform_device *pdev)
 {
        struct twl4030_bci_device_info *di = platform_get_drvdata(pdev);
+       int irq = platform_get_irq(pdev, 0);
 
        twl4030charger_ac_en(DISABLE);
        twl4030charger_usb_en(DISABLE);
@@ -1008,7 +1013,7 @@ static int __exit twl4030_bci_battery_remove(struct platform_device *pdev)
        twl4030battery_hw_presence_en(DISABLE);
 
        free_irq(TWL4030_MODIRQ_BCI, NULL);
-       free_irq(TWL4030_MODIRQ_PWR, di);
+       free_irq(irq, di);
 
        flush_scheduled_work();
        power_supply_unregister(&di->bat);
index 56a941587c43f7d87b9538f025d71513488bdb2e..17467330268ec2f18f7eea177aaa66614920a805 100644 (file)
 #define TWL4030_MODULE_RTC             0x14
 #define TWL4030_MODULE_SECURED_REG     0x15
 
+struct twl4030_bci_platform_data {
+       int *battery_tmp_tbl;
+       unsigned int tblsize;
+};
 
 /* TWL4030_GPIO_MAX (18) GPIOs, with interrupts */
 struct twl4030_gpio_platform_data {
@@ -91,6 +95,7 @@ struct twl4030_usb_data {
 
 struct twl4030_platform_data {
        unsigned                                irq_base, irq_end;
+       struct twl4030_bci_platform_data        *bci;
        struct twl4030_gpio_platform_data       *gpio;
        struct twl4030_madc_platform_data       *madc;
        struct twl4030_keypad_data              *keypad;