Skip to content

Commit 27ad711

Browse files
Andrei Hutanunashif
authored andcommitted
drivers: modem: quectel-bg9x: fix reset BG95 mdm
In case of BG95 where there is no reset pin, reseting the board which uses a BG95 modem could result in powering-off the modem (as oposed to "reset" the modem). This commit is an attempt to handle this case and re-power the modem. Signed-off-by: Andrei Hutanu <[email protected]>
1 parent 3cf92bc commit 27ad711

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

drivers/modem/quectel-bg9x.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,13 @@ static void modem_rssi_query_work(struct k_work *work)
887887
*/
888888
static void pin_init(void)
889889
{
890+
#if !DT_INST_NODE_HAS_PROP(0, mdm_reset_gpios)
891+
int ret = k_sem_take(&mdata.sem_pin_busy, K_SECONDS(3));
892+
893+
if (ret < 0) {
894+
LOG_DBG("Timeout pin_init()");
895+
}
896+
#endif /* !DT_INST_NODE_HAS_PROP(0, mdm_reset_gpios) */
890897
LOG_INF("Setting Modem Pins");
891898

892899
#if DT_INST_NODE_HAS_PROP(0, mdm_wdisable_gpios)
@@ -910,6 +917,18 @@ static void pin_init(void)
910917
k_sleep(K_SECONDS(2));
911918

912919
LOG_INF("... Done!");
920+
921+
#if !DT_INST_NODE_HAS_PROP(0, mdm_reset_gpios)
922+
k_sem_give(&mdata.sem_pin_busy);
923+
#endif /* !DT_INST_NODE_HAS_PROP(0, mdm_reset_gpios) */
924+
}
925+
926+
MODEM_CMD_DEFINE(on_cmd_unsol_normal_power_down)
927+
{
928+
LOG_INF("Modem powering off. Re-power modem...");
929+
pin_init();
930+
931+
return 0;
913932
}
914933

915934
static const struct modem_cmd response_cmds[] = {
@@ -922,6 +941,7 @@ static const struct modem_cmd unsol_cmds[] = {
922941
MODEM_CMD("+QIURC: \"recv\",", on_cmd_unsol_recv, 1U, ""),
923942
MODEM_CMD("+QIURC: \"closed\",", on_cmd_unsol_close, 1U, ""),
924943
MODEM_CMD(MDM_UNSOL_RDY, on_cmd_unsol_rdy, 0U, ""),
944+
MODEM_CMD("NORMAL POWER DOWN", on_cmd_unsol_normal_power_down, 0U, ""),
925945
};
926946

927947
/* Commands sent to the modem to set it up at boot time. */
@@ -1140,6 +1160,9 @@ static int modem_init(const struct device *dev)
11401160
{
11411161
int ret; ARG_UNUSED(dev);
11421162

1163+
#if !DT_INST_NODE_HAS_PROP(0, mdm_reset_gpios)
1164+
k_sem_init(&mdata.sem_pin_busy, 1, 1);
1165+
#endif /* !DT_INST_NODE_HAS_PROP(0, mdm_reset_gpios) */
11431166
k_sem_init(&mdata.sem_response, 0, 1);
11441167
k_sem_init(&mdata.sem_tx_ready, 0, 1);
11451168
k_sem_init(&mdata.sem_sock_conn, 0, 1);

drivers/modem/quectel-bg9x.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ struct modem_data {
114114
struct k_sem sem_response;
115115
struct k_sem sem_tx_ready;
116116
struct k_sem sem_sock_conn;
117+
#if !DT_INST_NODE_HAS_PROP(0, mdm_reset_gpios)
118+
struct k_sem sem_pin_busy;
119+
#endif
117120
};
118121

119122
/* Socket read callback data */

0 commit comments

Comments
 (0)