power: bq2419x: report input current limit
Venkat Reddy Talla [Wed, 23 Dec 2015 05:32:46 +0000 (10:32 +0530)]
Adding api to report input current limit based on
cable connected to device.
Also reporting SW configured current limit if value
is less than or equal to 2000mA and reporting HW limit
2100mA if current limit is more than 2000mA.

Bug 200159736

Change-Id: I6e0573e67e297f441e36f528ca5e1facea365d33
Signed-off-by: Venkat Reddy Talla <vreddytalla@nvidia.com>
Reviewed-on: http://git-master/r/926208
GVS: Gerrit_Virtual_Submit
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>

Documentation/devicetree/bindings/power/bq2419x-charger.txt
drivers/power/bq2419x-charger-st8.c
drivers/power/bq2419x-charger.c
include/linux/power/bq2419x-charger.h

index 7018c8f..6a4f010 100644 (file)
@@ -53,6 +53,8 @@ Optional properties:
 -ti,auto-recharge-time-suspend: time setting in seconds to register
                       rtc alarm timer to wake the device from LP0.
 -extcon-name: the extcon name to be used for USB VBUS detection
+-ti,charge-hw-current-limit-milliamp: maximum hardware input charge
+                current limit in milliamp
 
 Subnode properties:
 ==================
index 7ff245b..ae5fbbc 100644 (file)
@@ -58,6 +58,7 @@
 #define BQ2419x_OTG_ENABLE_TIME                (30*HZ)
 #define BQ2419x_TEMP_H_CHG_DISABLE     50
 #define BQ2419x_TEMP_L_CHG_DISABLE     0
+#define BQ2419x_SW_CHG_CURRENT_LIMIT   2000
 
 /* input current limit */
 static const unsigned int iinlim[] = {
@@ -121,6 +122,7 @@ struct bq2419x_chip {
        struct bq2419x_vbus_platform_data *vbus_pdata;
        struct bq2419x_charger_platform_data *charger_pdata;
        int                             last_input_voltage;
+       int charge_hw_current_limit;
 };
 
 static int current_to_reg(const unsigned int *tbl,
@@ -1464,11 +1466,23 @@ static int bq2419x_charging_restart(struct battery_charger_dev *bc_dev)
        return ret;
 }
 
+static int bq2419x_get_input_current_limit(struct battery_charger_dev *bc_dev)
+{
+       struct bq2419x_chip *bq2419x = battery_charger_get_drvdata(bc_dev);
+
+       if (!bq2419x->cable_connected)
+               return 0;
+
+       return (bq2419x->in_current_limit <= BQ2419x_SW_CHG_CURRENT_LIMIT) ?
+               bq2419x->in_current_limit : bq2419x->charge_hw_current_limit;
+}
+
 static struct battery_charging_ops bq2419x_charger_bci_ops = {
        .get_charging_status = bq2419x_charger_get_status,
        .restart_charging = bq2419x_charging_restart,
        .thermal_configure = bq2419x_charger_thermal_configure,
        .input_voltage_configure = bq2419x_charger_input_voltage_configure,
+       .get_input_current_limit = bq2419x_get_input_current_limit,
 };
 
 static struct battery_charger_info bq2419x_charger_bci = {
@@ -1655,6 +1669,13 @@ static struct bq2419x_platform_data *bq2419x_dt_parse(struct i2c_client *client,
                bcharger_pdata->temp_polling_time_sec =
                                                temp_polling_time;
 
+               ret = of_property_read_u32(batt_reg_node,
+                               "ti,charge-hw-current-limit-milliamp", &pval);
+               if (!ret)
+                       pdata->bcharger_pdata->charge_hw_current_limit = pval;
+               else
+                       pdata->bcharger_pdata->charge_hw_current_limit = 2100;
+
                count = of_property_count_u32(child, "ti,soc-range");
                soc_range_len = (count > 0) ? count : 0;
 
@@ -1913,6 +1934,8 @@ static int bq2419x_probe(struct i2c_client *client,
        bq2419x->auto_recharge_time_supend =
                        pdata->bcharger_pdata->auto_recharge_time_supend;
        bq2419x->thermal_chg_disable = false;
+       bq2419x->charge_hw_current_limit =
+                       pdata->bcharger_pdata->charge_hw_current_limit;
 
        bq2419x_process_charger_plat_data(bq2419x, pdata->bcharger_pdata);
 
index 7533ad8..1dce55d 100644 (file)
@@ -62,6 +62,7 @@
 #define BQ2419X_PC_USB_LP0_THRESHOLD   95
 #define BQ2419x_TEMP_H_CHG_DISABLE     50
 #define BQ2419x_TEMP_L_CHG_DISABLE     0
+#define BQ2419x_SW_CHG_CURRENT_LIMIT   2000
 
 /* input current limit */
 static const unsigned int iinlim[] = {
@@ -140,6 +141,7 @@ struct bq2419x_chip {
        int                             last_input_voltage;
        int                             wdt_refresh_timeout;
        int                             wdt_time_sec;
+       int                             charge_hw_current_limit;
 };
 
 static int current_to_reg(const unsigned int *tbl,
@@ -1600,7 +1602,8 @@ static int bq2419x_get_input_current_limit(struct battery_charger_dev *bc_dev)
        if (!bq2419x->cable_connected)
                return 0;
 
-       return bq2419x->in_current_limit;
+       return (bq2419x->in_current_limit <= BQ2419x_SW_CHG_CURRENT_LIMIT) ?
+               bq2419x->in_current_limit : bq2419x->charge_hw_current_limit;
 }
 
 static int bq2419x_charger_termination_configure(
@@ -1864,6 +1867,13 @@ static struct bq2419x_platform_data *bq2419x_dt_parse(struct i2c_client *client,
                if (!ret)
                        pdata->bcharger_pdata->wdt_timeout = wdt_timeout;
 
+               ret = of_property_read_u32(batt_reg_node,
+                               "ti,charge-hw-current-limit-milliamp", &pval);
+               if (!ret)
+                       pdata->bcharger_pdata->charge_hw_current_limit = pval;
+               else
+                       pdata->bcharger_pdata->charge_hw_current_limit = 2100;
+
                count = of_property_count_u32(batt_reg_node, "ti,soc-range");
                soc_range_len = (count > 0) ? count : 0;
 
@@ -2134,6 +2144,8 @@ static int bq2419x_probe(struct i2c_client *client,
        bq2419x->auto_rechg_power_on_time =
                        pdata->bcharger_pdata->auto_rechg_power_on_time;
        bq2419x->wdt_time_sec = pdata->bcharger_pdata->wdt_timeout;
+       bq2419x->charge_hw_current_limit =
+                       pdata->bcharger_pdata->charge_hw_current_limit;
 
        bq2419x_process_charger_plat_data(bq2419x, pdata->bcharger_pdata);
 
index 1ff5f46..63d2114 100644 (file)
@@ -173,6 +173,7 @@ struct bq2419x_charger_platform_data {
        u32 auto_rechg_power_on_time;
        int min_system_voltage_limit_mV;
        int n_soc_profile;
+       int charge_hw_current_limit;
 };
 
 /*