From c8ae80ba3369b6d99e5dfaf050a6693feab01a8a Mon Sep 17 00:00:00 2001 From: Ashish Chavan Date: Thu, 21 Apr 2022 16:48:43 +0530 Subject: [PATCH] power: BQ256xxx: Add support for debug board detection Disable charging when a debug board is detected. Debug board is reported based on a GPIO state, add support to sample this GPIO and disable charging by setting the VINDP to 5.4V. Change-Id: I8b8a0a833b4f50e24e0223cf9f2510c7e4ec8056 Signed-off-by: Ashish Chavan Signed-off-by: Rakesh Kota Signed-off-by: Monish Chunara --- drivers/power/supply/bq256xx_charger.c | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c index fdf3defc1880..bd1852b4ecf5 100644 --- a/drivers/power/supply/bq256xx_charger.c +++ b/drivers/power/supply/bq256xx_charger.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #define BQ256XX_MANUFACTURER "Texas Instruments" @@ -145,6 +147,8 @@ #define BQ256XX_REG_RST BIT(7) +#define BQ256XX_MAX_INPUT_VOLTAGE_UV 5400000 + /** * struct bq256xx_init_data - * @ichg: fast charge current @@ -261,6 +265,8 @@ struct bq256xx_device { bool irq_waiting; bool resume_completed; + /* debug_board_gpio to deteect the debug board*/ + int debug_board_gpio; }; /** @@ -1544,6 +1550,30 @@ static int bq256xx_power_supply_init(struct bq256xx_device *bq, return 0; } +static int bq256xx_debug_board_detect(struct bq256xx_device *bq) +{ + int ret = 0; + + if (!of_find_property(bq->dev->of_node, "debugboard-detect-gpio", NULL)) + return ret; + + bq->debug_board_gpio = of_get_named_gpio(bq->dev->of_node, + "debugboard-detect-gpio", 0); + if (IS_ERR(&bq->debug_board_gpio)) { + ret = PTR_ERR(&bq->debug_board_gpio); + dev_err(bq->dev, "Failed to initialize debugboard_detecte gpio\n"); + return ret; + } + gpio_direction_input(bq->debug_board_gpio); + if (gpio_get_value(bq->debug_board_gpio)) { + bq->init_data.vindpm = BQ256XX_MAX_INPUT_VOLTAGE_UV; + dev_info(bq->dev, + "debug_board detected, setting vindpm to %d\n", bq->init_data.vindpm); + } + + return ret; +} + static int bq256xx_hw_init(struct bq256xx_device *bq) { struct power_supply_battery_info *bat_info; @@ -1599,6 +1629,10 @@ static int bq256xx_hw_init(struct bq256xx_device *bq) bat_info->constant_charge_voltage_max_uv; } + ret = bq256xx_debug_board_detect(bq); + if (ret) + return ret; + ret = bq->chip_info->bq256xx_set_vindpm(bq, bq->init_data.vindpm); if (ret) return ret;