From b340a9024ec1a12ada5e3ae602f292fa93572937 Mon Sep 17 00:00:00 2001 From: Umesh Vats Date: Wed, 3 Mar 2021 11:58:11 -0800 Subject: [PATCH] Bluetooth: Add retry for XO GPIO request Add retries for XO GPIO requests. Change-Id: If6bf4568559bf712274bc3988424f35c8d0e6a93 Signed-off-by: Umesh Vats --- drivers/bluetooth/btpower.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btpower.c b/drivers/bluetooth/btpower.c index 206e16adfd13..0ce0cc63cc70 100644 --- a/drivers/bluetooth/btpower.c +++ b/drivers/bluetooth/btpower.c @@ -41,6 +41,7 @@ #define PWR_SRC_NOT_AVAILABLE -2 #define DEFAULT_INVALID_VALUE -1 #define PWR_SRC_INIT_STATE_IDX 0 +#define XO_RESET_RETRY_COUNT_MAX 5 #define PWR_SRC_LOG_UNSUPPORTED {DEFAULT_INVALID_VALUE, DEFAULT_INVALID_VALUE} @@ -361,6 +362,7 @@ static int bt_configure_gpios(int on) int bt_debug_gpio = bt_power_pdata->bt_gpio_debug; int xo_reset_gpio = bt_power_pdata->xo_gpio_sys_rst; int assert_dbg_gpio = 0; + int retry = 0; if (on) { rc = gpio_request(bt_reset_gpio, "bt_sys_rst_n"); @@ -430,9 +432,18 @@ static int bt_configure_gpios(int on) pr_info("xo_reset_gpio(%d)\n", xo_reset_gpio); if (xo_reset_gpio > 0) { +retry_gpio_req: rc = gpio_request(xo_reset_gpio, "xo_reset_gpio_n"); if (rc) { - pr_err("%s: unable to request gpio %d (%d)\n", + if (retry++ < XO_RESET_RETRY_COUNT_MAX) { + /* wait for ~(10 - 20) ms */ + usleep_range(10000, 20000); + goto retry_gpio_req; + } + } + + if (rc) { + pr_err("%s: unable to request XO reset gpio %d (%d)\n", __func__, xo_reset_gpio, rc); } else { pr_info("%s: gpio_request for xo_reset_gpio succeed\n",