power_supply: bq25700: add function to set current
authorShengfei xu <xsf@rock-chips.com>
Tue, 3 Jan 2017 10:11:33 +0000 (18:11 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 6 Jan 2017 06:41:22 +0000 (14:41 +0800)
This patch is used for updating the charger operations such
like setting charging current and setting input current.

Change-Id: I7c77624102dd2b43bd1c007c2097ab92a5e3de2a
Signed-off-by: Shengfei xu <xsf@rock-chips.com>
drivers/power/bq25700_charger.c
include/linux/power/bq25700-charge.h [new file with mode: 0644]

index d87f173340b1e83021225794634d20d5804d3598..13201768bd48564407eda8698fcb338ef9216347 100644 (file)
@@ -15,6 +15,7 @@
  *
  */
 
+#include <linux/power/bq25700-charge.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/mfd/core.h>
@@ -375,7 +376,7 @@ static const union {
 } bq25700_tables[] = {
        /* range tables */
        [TBL_ICHG] =    { .rt = {0,       8128000, 64000} },
-       /* uA */
+       /* uV */
        [TBL_CHGMAX] = { .rt = {0, 19200000, 16000} },
        /* uV  max charge voltage*/
        [TBL_INPUTVOL] = { .rt = {3200000, 19520000, 64000} },
@@ -425,6 +426,8 @@ static const struct regmap_config bq25700_regmap_config = {
        .val_format_endian = REGMAP_ENDIAN_LITTLE,
 };
 
+static struct bq25700_device *bq25700_charger;
+
 static int bq25700_field_read(struct bq25700_device *charger,
                              enum bq25700_fields field_id)
 {
@@ -623,6 +626,31 @@ static u32 bq25700_find_idx(u32 value, enum bq25700_table_ids id)
        return idx - 1;
 }
 
+void bq25700_charger_set_current(unsigned long event,
+                                int current_value)
+{
+       int idx;
+
+       if (!bq25700_charger) {
+               pr_err("[%s,%d] bq25700_charger is null\n", __func__, __LINE__);
+               return;
+       }
+       switch (event) {
+       case CHARGER_CURRENT_EVENT:
+               idx = bq25700_find_idx(current_value, TBL_ICHG);
+               bq25700_field_write(bq25700_charger, CHARGE_CURRENT, idx);
+               break;
+
+       case INPUT_CURRENT_EVENT:
+               idx = bq25700_find_idx(current_value, TBL_INPUTCUR);
+               bq25700_field_write(bq25700_charger, INPUT_CURRENT, idx);
+               break;
+
+       default:
+               return;
+       }
+}
+
 static int bq25700_fw_read_u32_props(struct bq25700_device *charger)
 {
        int ret;
@@ -1683,6 +1711,7 @@ static int bq25700_probe(struct i2c_client *client,
                goto irq_fail;
 
        bq25700_power_supply_init(charger);
+       bq25700_charger = charger;
 
 irq_fail:
        return ret;
diff --git a/include/linux/power/bq25700-charge.h b/include/linux/power/bq25700-charge.h
new file mode 100644 (file)
index 0000000..5e7d3e4
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __CHARGER_BQ25700_H_
+#define __CHARGER_BQ25700_H_
+
+#define CHARGER_CURRENT_EVENT  0x01
+#define INPUT_CURRENT_EVENT    0x02
+
+void bq25700_charger_set_current(unsigned long event, int current_value);
+
+#endif /* __CHARGER_BQ25700_H_ */