Re: [PATCH 2/2] power: supply: bq25790: Introduce the BQ25790 charger driver

2020-08-05 Thread Dan Carpenter
Hi Dan,

url:
https://github.com/0day-ci/linux/commits/Dan-Murphy/dt-bindings-power-Add-the-bq25790-dt-bindings/20200730-225910
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git 
for-next
config: x86_64-randconfig-m001-20200731 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 
Reported-by: Dan Carpenter 

smatch warnings:
drivers/power/supply/bq25790_charger.c:170 bq25790_usb_work() warn: ignoring 
unreachable code.
drivers/power/supply/bq25790_charger.c:624 bq25790_get_property() warn: should 
this be a bitwise op?
drivers/power/supply/bq25790_charger.c:904 bq25790_hw_init() error: buffer 
overflow 'bq25790_watchdog_time' 8 <= 8

# 
https://github.com/0day-ci/linux/commit/e5cf0f04730928b191aff54ab64bdd2167b2ecd4
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout e5cf0f04730928b191aff54ab64bdd2167b2ecd4
vim +170 drivers/power/supply/bq25790_charger.c

e5cf0f04730928 Dan Murphy 2020-07-30  154  static void bq25790_usb_work(struct 
work_struct *data)
e5cf0f04730928 Dan Murphy 2020-07-30  155  {
e5cf0f04730928 Dan Murphy 2020-07-30  156   struct bq25790_device *bq =
e5cf0f04730928 Dan Murphy 2020-07-30  157   
container_of(data, struct bq25790_device, usb_work);
e5cf0f04730928 Dan Murphy 2020-07-30  158  
e5cf0f04730928 Dan Murphy 2020-07-30  159   switch (bq->usb_event) {
e5cf0f04730928 Dan Murphy 2020-07-30  160   case USB_EVENT_ID:
e5cf0f04730928 Dan Murphy 2020-07-30  161   break;
e5cf0f04730928 Dan Murphy 2020-07-30  162  
e5cf0f04730928 Dan Murphy 2020-07-30  163   case USB_EVENT_NONE:
e5cf0f04730928 Dan Murphy 2020-07-30  164   
power_supply_changed(bq->charger);
e5cf0f04730928 Dan Murphy 2020-07-30  165   break;
e5cf0f04730928 Dan Murphy 2020-07-30  166   }
e5cf0f04730928 Dan Murphy 2020-07-30  167  
e5cf0f04730928 Dan Murphy 2020-07-30  168   return;
^^
e5cf0f04730928 Dan Murphy 2020-07-30  169  
e5cf0f04730928 Dan Murphy 2020-07-30 @170   dev_err(bq->dev, "Error 
switching to charger mode.\n");

^^^
Unreachable.

e5cf0f04730928 Dan Murphy 2020-07-30  171  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


Re: [PATCH 2/2] power: supply: bq25790: Introduce the BQ25790 charger driver

2020-07-30 Thread Ricardo Rivera-Matos

Signed-off-by: Ricardo Rivera-Matos 

On 7/30/20 9:58 AM, Dan Murphy wrote:

BQ25790 is a highly integrated switch-mode buck-boost charger
for 1-4 cell Li-ion battery and Li-polymer battery.

Signed-off-by: Dan Murphy 
---
  drivers/power/supply/Kconfig   |8 +
  drivers/power/supply/Makefile  |1 +
  drivers/power/supply/bq25790_charger.c | 1117 
  drivers/power/supply/bq25790_charger.h |  150 
  4 files changed, 1276 insertions(+)
  create mode 100644 drivers/power/supply/bq25790_charger.c
  create mode 100644 drivers/power/supply/bq25790_charger.h

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index faf2830aa152..802c644d92be 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -623,6 +623,14 @@ config CHARGER_BQ2515X
  rail, ADC for battery and system monitoring, and push-button
  controller.
  
+config CHARGER_BQ25790

+   tristate "TI BQ25790 battery charger driver"
+   depends on I2C
+   depends on GPIOLIB || COMPILE_TEST
+   select REGMAP_I2C
+   help
+ Say Y to enable support for the TI BQ25790 battery charger.
+
  config CHARGER_BQ25890
tristate "TI BQ25890 battery charger driver"
depends on I2C
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index b3c694a65114..ae269b9f624b 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_CHARGER_BQ24257) += bq24257_charger.o
  obj-$(CONFIG_CHARGER_BQ24735) += bq24735-charger.o
  obj-$(CONFIG_CHARGER_BQ2515X) += bq2515x_charger.o
  obj-$(CONFIG_CHARGER_BQ25890) += bq25890_charger.o
+obj-$(CONFIG_CHARGER_BQ25790)  += bq25790_charger.o
  obj-$(CONFIG_CHARGER_SMB347)  += smb347-charger.o
  obj-$(CONFIG_CHARGER_TPS65090)+= tps65090-charger.o
  obj-$(CONFIG_CHARGER_TPS65217)+= tps65217_charger.o
diff --git a/drivers/power/supply/bq25790_charger.c 
b/drivers/power/supply/bq25790_charger.c
new file mode 100644
index ..92fa859ef55c
--- /dev/null
+++ b/drivers/power/supply/bq25790_charger.c
@@ -0,0 +1,1117 @@
+// SPDX-License-Identifier: GPL-2.0
+// BQ25790 driver
+// Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "bq25790_charger.h"
+
+#define BQ25790_NUM_WD_VAL 8
+
+struct bq25790_init_data {
+   u32 ichg;
+   u32 ilim;
+   u32 vreg;
+   u32 iterm;
+   u32 iprechg;
+   u32 vlim;
+   u32 ichg_max;
+   u32 vreg_max;
+};
+
+struct bq25790_state {
+   bool online;
+   u8 chrg_status;
+   u8 chrg_type;
+   u8 health;
+   u8 chrg_fault;
+   u8 vsys_status;
+   u8 vbus_status;
+   u8 fault_0;
+   u8 fault_1;
+   u32 vbat_adc;
+   u32 vbus_adc;
+   u32 ibat_adc;
+};
+
+struct bq25790_device {
+   struct i2c_client *client;
+   struct device *dev;
+   struct power_supply *charger;
+   struct power_supply *battery;
+   struct mutex lock;
+
+   struct usb_phy *usb2_phy;
+   struct usb_phy *usb3_phy;
+   struct notifier_block usb_nb;
+   struct work_struct usb_work;
+   unsigned long usb_event;
+   struct regmap *regmap;
+
+   char model_name[I2C_NAME_SIZE];
+   int device_id;
+
+   struct bq25790_init_data init_data;
+   struct bq25790_state state;
+   int watchdog_timer;
+};
+
+static struct reg_default bq25790_reg_defs[] = {
+   {BQ25790_INPUT_V_LIM, 0x24},
+   {BQ25790_INPUT_I_LIM_MSB, 0x01},
+   {BQ25790_INPUT_I_LIM_LSB, 0x2c},
+   {BQ25790_PRECHRG_CTRL, 0xc3},
+   {BQ25790_TERM_CTRL, 0x5},
+   {BQ25790_VOTG_REG, 0xdc},
+   {BQ25790_IOTG_REG, 0x4b},
+   {BQ25790_TIMER_CTRL, 0x3d},
+   {BQ25790_CHRG_CTRL_0, 0xa2},
+   {BQ25790_CHRG_CTRL_1, 0x85},
+   {BQ25790_CHRG_CTRL_2, 0x40},
+   {BQ25790_CHRG_CTRL_3, 0x12},
+   {BQ25790_CHRG_CTRL_5, 0x16},
+   {BQ25790_MPPT_CTRL, 0xaa},
+   {BQ25790_TEMP_CTRL, 0xc0},
+   {BQ25790_NTC_CTRL_0, 0x7a},
+   {BQ25790_NTC_CTRL_1, 0x54},
+   {BQ25790_ICO_I_LIM, 0x0},
+   {BQ25790_CHRG_STAT_0, 0x0},
+   {BQ25790_CHRG_STAT_1, 0x0},
+   {BQ25790_CHRG_STAT_2, 0x0},
+   {BQ25790_CHRG_STAT_3, 0x0},
+   {BQ25790_CHRG_STAT_4, 0x0},
+   {BQ25790_FAULT_STAT_0, 0x0},
+   {BQ25790_FAULT_STAT_1, 0x0},
+   {BQ25790_CHRG_FLAG_0, 0x0},
+   {BQ25790_CHRG_FLAG_1, 0x0},
+   {BQ25790_CHRG_FLAG_2, 0x0},
+   {BQ25790_CHRG_FLAG_3, 0x0},
+   {BQ25790_FAULT_FLAG_0, 0x0},
+   {BQ25790_FAULT_FLAG_1, 0x0},
+   {BQ25790_CHRG_MSK_0, 0x0},
+   {BQ25790_CHRG_MSK_1, 0x0},
+   {BQ25790_CHRG_MSK_2, 0x0},
+   {BQ25790_CHRG_MSK_3, 0x0},
+   {BQ25790_FAULT_MSK_0, 0x0},
+   {BQ25790_FAULT_MSK_1, 0x0},
+   {BQ25790_ADC_CTRL, 0x30},
+   

[PATCH 2/2] power: supply: bq25790: Introduce the BQ25790 charger driver

2020-07-30 Thread Dan Murphy
BQ25790 is a highly integrated switch-mode buck-boost charger
for 1-4 cell Li-ion battery and Li-polymer battery.

Signed-off-by: Dan Murphy 
---
 drivers/power/supply/Kconfig   |8 +
 drivers/power/supply/Makefile  |1 +
 drivers/power/supply/bq25790_charger.c | 1117 
 drivers/power/supply/bq25790_charger.h |  150 
 4 files changed, 1276 insertions(+)
 create mode 100644 drivers/power/supply/bq25790_charger.c
 create mode 100644 drivers/power/supply/bq25790_charger.h

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index faf2830aa152..802c644d92be 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -623,6 +623,14 @@ config CHARGER_BQ2515X
  rail, ADC for battery and system monitoring, and push-button
  controller.
 
+config CHARGER_BQ25790
+   tristate "TI BQ25790 battery charger driver"
+   depends on I2C
+   depends on GPIOLIB || COMPILE_TEST
+   select REGMAP_I2C
+   help
+ Say Y to enable support for the TI BQ25790 battery charger.
+
 config CHARGER_BQ25890
tristate "TI BQ25890 battery charger driver"
depends on I2C
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index b3c694a65114..ae269b9f624b 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -84,6 +84,7 @@ obj-$(CONFIG_CHARGER_BQ24257) += bq24257_charger.o
 obj-$(CONFIG_CHARGER_BQ24735)  += bq24735-charger.o
 obj-$(CONFIG_CHARGER_BQ2515X)  += bq2515x_charger.o
 obj-$(CONFIG_CHARGER_BQ25890)  += bq25890_charger.o
+obj-$(CONFIG_CHARGER_BQ25790)  += bq25790_charger.o
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
 obj-$(CONFIG_CHARGER_TPS65217) += tps65217_charger.o
diff --git a/drivers/power/supply/bq25790_charger.c 
b/drivers/power/supply/bq25790_charger.c
new file mode 100644
index ..92fa859ef55c
--- /dev/null
+++ b/drivers/power/supply/bq25790_charger.c
@@ -0,0 +1,1117 @@
+// SPDX-License-Identifier: GPL-2.0
+// BQ25790 driver
+// Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "bq25790_charger.h"
+
+#define BQ25790_NUM_WD_VAL 8
+
+struct bq25790_init_data {
+   u32 ichg;
+   u32 ilim;
+   u32 vreg;
+   u32 iterm;
+   u32 iprechg;
+   u32 vlim;
+   u32 ichg_max;
+   u32 vreg_max;
+};
+
+struct bq25790_state {
+   bool online;
+   u8 chrg_status;
+   u8 chrg_type;
+   u8 health;
+   u8 chrg_fault;
+   u8 vsys_status;
+   u8 vbus_status;
+   u8 fault_0;
+   u8 fault_1;
+   u32 vbat_adc;
+   u32 vbus_adc;
+   u32 ibat_adc;
+};
+
+struct bq25790_device {
+   struct i2c_client *client;
+   struct device *dev;
+   struct power_supply *charger;
+   struct power_supply *battery;
+   struct mutex lock;
+
+   struct usb_phy *usb2_phy;
+   struct usb_phy *usb3_phy;
+   struct notifier_block usb_nb;
+   struct work_struct usb_work;
+   unsigned long usb_event;
+   struct regmap *regmap;
+
+   char model_name[I2C_NAME_SIZE];
+   int device_id;
+
+   struct bq25790_init_data init_data;
+   struct bq25790_state state;
+   int watchdog_timer;
+};
+
+static struct reg_default bq25790_reg_defs[] = {
+   {BQ25790_INPUT_V_LIM, 0x24},
+   {BQ25790_INPUT_I_LIM_MSB, 0x01},
+   {BQ25790_INPUT_I_LIM_LSB, 0x2c},
+   {BQ25790_PRECHRG_CTRL, 0xc3},
+   {BQ25790_TERM_CTRL, 0x5},
+   {BQ25790_VOTG_REG, 0xdc},
+   {BQ25790_IOTG_REG, 0x4b},
+   {BQ25790_TIMER_CTRL, 0x3d},
+   {BQ25790_CHRG_CTRL_0, 0xa2},
+   {BQ25790_CHRG_CTRL_1, 0x85},
+   {BQ25790_CHRG_CTRL_2, 0x40},
+   {BQ25790_CHRG_CTRL_3, 0x12},
+   {BQ25790_CHRG_CTRL_5, 0x16},
+   {BQ25790_MPPT_CTRL, 0xaa},
+   {BQ25790_TEMP_CTRL, 0xc0},
+   {BQ25790_NTC_CTRL_0, 0x7a},
+   {BQ25790_NTC_CTRL_1, 0x54},
+   {BQ25790_ICO_I_LIM, 0x0},
+   {BQ25790_CHRG_STAT_0, 0x0},
+   {BQ25790_CHRG_STAT_1, 0x0},
+   {BQ25790_CHRG_STAT_2, 0x0},
+   {BQ25790_CHRG_STAT_3, 0x0},
+   {BQ25790_CHRG_STAT_4, 0x0},
+   {BQ25790_FAULT_STAT_0, 0x0},
+   {BQ25790_FAULT_STAT_1, 0x0},
+   {BQ25790_CHRG_FLAG_0, 0x0},
+   {BQ25790_CHRG_FLAG_1, 0x0},
+   {BQ25790_CHRG_FLAG_2, 0x0},
+   {BQ25790_CHRG_FLAG_3, 0x0},
+   {BQ25790_FAULT_FLAG_0, 0x0},
+   {BQ25790_FAULT_FLAG_1, 0x0},
+   {BQ25790_CHRG_MSK_0, 0x0},
+   {BQ25790_CHRG_MSK_1, 0x0},
+   {BQ25790_CHRG_MSK_2, 0x0},
+   {BQ25790_CHRG_MSK_3, 0x0},
+   {BQ25790_FAULT_MSK_0, 0x0},
+   {BQ25790_FAULT_MSK_1, 0x0},
+   {BQ25790_ADC_CTRL, 0x30},
+   {BQ25790_FN_DISABE_0, 0x0},
+   {BQ25790_FN_DISABE_1, 0x0},
+   {BQ25790_ADC_IBUS, 0x0},
+