Skip to content

Commit 4207534

Browse files
rerickson1nashif
authored andcommitted
modem: hl7800: fix PSM
Fix power-save-mode (PSM) operation. When in PSM, do not bring the networking interface down when an out-of-coverage event occurs. When PSM goes into hibernate, this will cause an out-of-coverage event to occur, even though the device still has access to service. Keeping the networking interface in the up state allows an app to send data whenever it needs to. Signed-off-by: Ryan Erickson <[email protected]>
1 parent 2dcd5b4 commit 4207534

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

drivers/modem/hl7800.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ enum socket_state {
130130
SOCK_CONNECTED,
131131
};
132132

133+
enum hl7800_lpm {
134+
HL7800_LPM_NONE,
135+
HL7800_LPM_EDRX,
136+
HL7800_LPM_PSM,
137+
};
138+
133139
struct mdm_control_pinconfig {
134140
char *dev_name;
135141
gpio_pin_t pin;
@@ -515,6 +521,7 @@ struct hl7800_iface_ctx {
515521
bool allow_sleep;
516522
bool uart_on;
517523
enum mdm_hl7800_sleep_state sleep_state;
524+
enum hl7800_lpm low_power_mode;
518525
enum mdm_hl7800_network_state network_state;
519526
enum net_operator_status operator_status;
520527
void (*event_callback)(enum mdm_hl7800_event event, void *event_data);
@@ -2901,14 +2908,17 @@ static void iface_status_work_cb(struct k_work *work)
29012908
break;
29022909
case HL7800_OUT_OF_COVERAGE:
29032910
default:
2904-
if (ictx.iface && net_if_is_up(ictx.iface)) {
2911+
if (ictx.iface && net_if_is_up(ictx.iface) &&
2912+
(ictx.low_power_mode != HL7800_LPM_PSM)) {
29052913
LOG_DBG("HL7800 iface DOWN");
29062914
net_if_down(ictx.iface);
29072915
}
29082916
break;
29092917
}
29102918

2911-
if (ictx.iface && !net_if_is_up(ictx.iface)) {
2919+
if ((ictx.iface && !net_if_is_up(ictx.iface)) ||
2920+
(ictx.low_power_mode == HL7800_LPM_PSM &&
2921+
ictx.network_state == HL7800_OUT_OF_COVERAGE)) {
29122922
hl7800_stop_rssi_work();
29132923
notify_all_tcp_sockets_closed();
29142924
} else if (ictx.iface && net_if_is_up(ictx.iface)) {
@@ -3516,7 +3526,8 @@ static void sockreadrecv_cb_work(struct k_work *work)
35163526

35173527
sock = CONTAINER_OF(work, struct hl7800_socket, recv_cb_work);
35183528

3519-
LOG_DBG("Sock %d RX CB", sock->socket_id);
3529+
LOG_DBG("Sock %d RX CB (size: %zd)", sock->socket_id,
3530+
(sock->recv_pkt != NULL) ? net_pkt_get_len(sock->recv_pkt) : 0);
35203531
/* return data */
35213532
pkt = sock->recv_pkt;
35223533
sock->recv_pkt = NULL;
@@ -4311,8 +4322,8 @@ static void mdm_vgpio_work_cb(struct k_work *item)
43114322
if (ictx.sleep_state != HL7800_SLEEP_STATE_ASLEEP) {
43124323
set_sleep_state(HL7800_SLEEP_STATE_ASLEEP);
43134324
}
4314-
if (ictx.iface && ictx.initialized &&
4315-
net_if_is_up(ictx.iface)) {
4325+
if (ictx.iface && ictx.initialized && net_if_is_up(ictx.iface) &&
4326+
ictx.low_power_mode != HL7800_LPM_PSM) {
43164327
net_if_down(ictx.iface);
43174328
}
43184329
}
@@ -4736,20 +4747,22 @@ static int modem_reset_and_configure(void)
47364747
}
47374748
#endif
47384749

4750+
ictx.low_power_mode = HL7800_LPM_NONE;
47394751
#ifdef CONFIG_MODEM_HL7800_LOW_POWER_MODE
4740-
47414752
/* enable GPIO6 low power monitoring */
47424753
SEND_AT_CMD_EXPECT_OK("AT+KHWIOCFG=3,1,6");
47434754

47444755
/* Turn on sleep mode */
47454756
SEND_AT_CMD_EXPECT_OK("AT+KSLEEP=1,2,10");
47464757

47474758
#if CONFIG_MODEM_HL7800_PSM
4759+
ictx.low_power_mode = HL7800_LPM_PSM;
47484760
/* Turn off eDRX */
47494761
SEND_AT_CMD_EXPECT_OK("AT+CEDRXS=0");
47504762

47514763
SEND_AT_CMD_EXPECT_OK(TURN_ON_PSM);
47524764
#elif CONFIG_MODEM_HL7800_EDRX
4765+
ictx.low_power_mode = HL7800_LPM_EDRX;
47534766
/* Turn off PSM */
47544767
SEND_AT_CMD_EXPECT_OK("AT+CPSMS=0");
47554768

0 commit comments

Comments
 (0)