roth: power: check battery presence
Syed Rafiuddin [Sun, 30 Dec 2012 14:59:05 +0000 (19:59 +0530)]
check presence of battery based on fg driver

Change-Id: I0b6beb7bc6d3c441d4c93f4037d0a5af108233b7
Signed-off-by: Syed Rafiuddin <srafiuddin@nvidia.com>
Reviewed-on: http://git-master/r/#change,187632
(cherry picked from commit 221766dfd5f5cebf56a84c0c6557bd5e07d34e1d)
Reviewed-on: http://git-master/r/190650
Reviewed-by: Riham Haidar <rhaidar@nvidia.com>
Tested-by: Riham Haidar <rhaidar@nvidia.com>

arch/arm/mach-tegra/board-roth-power.c
drivers/power/bq2419x-charger.c
drivers/power/max17048_battery.c
include/linux/max17048_battery.h
include/linux/mfd/bq2419x.h

index 0862e2a..4e78b7a 100644 (file)
@@ -122,6 +122,7 @@ struct bq2419x_charger_platform_data bq2419x_charger_pdata = {
        .gpio_interrupt = TEGRA_GPIO_PJ0,
        .gpio_status = TEGRA_GPIO_PK0,
        .update_status = max17048_battery_status,
+       .battery_check = max17048_check_battery,
 };
 
 struct max17048_battery_model max17048_mdata = {
index 4379f0e..8b96b1c 100644 (file)
@@ -229,6 +229,7 @@ static int __devinit bq2419x_charger_probe(struct platform_device *pdev)
        struct bq2419x_charger_platform_data *bcharger_pdata = NULL;
        struct bq2419x_charger *charger;
        int ret;
+       int batt_status;
        u32 val;
 
        chip_pdata = dev_get_platdata(pdev->dev.parent);
@@ -246,6 +247,16 @@ static int __devinit bq2419x_charger_probe(struct platform_device *pdev)
                return -ENOMEM;
        }
 
+       if (bcharger_pdata->battery_check) {
+               batt_status = bcharger_pdata->battery_check();
+               if (batt_status < 0) {
+                       dev_err(&pdev->dev, "Battery not detected exiting\n");
+                       return -ENODEV;
+               }
+       } else {
+               dev_err(&pdev->dev, "Battery not detected..exiting\n");
+       }
+
        charger->chip = dev_get_drvdata(pdev->dev.parent);
        charger->dev = &pdev->dev;
        charger->usb_in_current_limit = bcharger_pdata->usb_in_current_limit;
index 6f6248e..a2b4ca4 100644 (file)
@@ -456,6 +456,21 @@ static int max17048_initialize(struct max17048_chip *chip)
        return 0;
 }
 
+int max17048_check_battery()
+{
+       uint16_t version;
+
+       if (!max17048_data)
+               return -ENODEV;
+
+       version = max17048_get_version(max17048_data->client);
+       if (version != MAX17048_VERSION_NO) {
+               return -ENODEV;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(max17048_check_battery);
+
 static int __devinit max17048_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
@@ -474,8 +489,8 @@ static int __devinit max17048_probe(struct i2c_client *client,
        max17048_data = chip;
        i2c_set_clientdata(client, chip);
 
-       version = max17048_get_version(client);
-       if (version != MAX17048_VERSION_NO) {
+       version = max17048_check_battery();
+       if (version < 0) {
                ret = -ENODEV;
                goto error2;
        }
index 40b6bc5..ad29afd 100644 (file)
@@ -37,4 +37,5 @@ struct max17048_platform_data {
 };
 
 void max17048_battery_status(int status, int chrg_type);
+int max17048_check_battery(void);
 #endif
index c8e8f69..405d8a3 100644 (file)
@@ -84,6 +84,7 @@ struct bq2419x_charger_platform_data {
        unsigned use_mains:1;
        unsigned use_usb:1;
        void (*update_status)(int, int);
+       int (*battery_check)(void);
 };
 struct bq2419x_platform_data {
        struct bq2419x_regulator_platform_data *reg_pdata;