Skip to content

Commit b8541c5

Browse files
SeppoTakalocfriedt
authored andcommitted
modem: modem_cellular: Allow PPP interface to wake up the device
Allow PPP device to wake up the underlying cellular modem. Signed-off-by: Seppo Takalo <[email protected]>
1 parent f66dd94 commit b8541c5

File tree

4 files changed

+60
-19
lines changed

4 files changed

+60
-19
lines changed

drivers/modem/modem_cellular.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
29162916
&modem_cellular_api);
29172917

29182918
#define MODEM_CELLULAR_DEVICE_QUECTEL_BG9X(inst) \
2919-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
2919+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
29202920
\
29212921
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
29222922
.chat_delimiter = "\r", \
@@ -2936,7 +2936,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
29362936
&quectel_bg9x_shutdown_chat_script)
29372937

29382938
#define MODEM_CELLULAR_DEVICE_QUECTEL_EG25_G(inst) \
2939-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
2939+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
29402940
\
29412941
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
29422942
.chat_delimiter = "\r", \
@@ -2955,7 +2955,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
29552955
&quectel_eg25_g_periodic_chat_script, NULL)
29562956

29572957
#define MODEM_CELLULAR_DEVICE_QUECTEL_EG800Q(inst) \
2958-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
2958+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
29592959
\
29602960
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
29612961
.chat_delimiter = "\r", \
@@ -2974,7 +2974,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
29742974
&quectel_eg800q_periodic_chat_script, NULL)
29752975

29762976
#define MODEM_CELLULAR_DEVICE_SIMCOM_SIM7080(inst) \
2977-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
2977+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
29782978
\
29792979
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
29802980
.chat_delimiter = "\r", \
@@ -2993,7 +2993,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
29932993
&simcom_sim7080_periodic_chat_script, NULL)
29942994

29952995
#define MODEM_CELLULAR_DEVICE_SIMCOM_A76XX(inst) \
2996-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
2996+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
29972997
\
29982998
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
29992999
.chat_delimiter = "\r", \
@@ -3013,7 +3013,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
30133013
&simcom_a76xx_shutdown_chat_script)
30143014

30153015
#define MODEM_CELLULAR_DEVICE_U_BLOX_SARA_R4(inst) \
3016-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
3016+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
30173017
\
30183018
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
30193019
.chat_delimiter = "\r", \
@@ -3032,7 +3032,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
30323032
&u_blox_sara_r4_periodic_chat_script, NULL)
30333033

30343034
#define MODEM_CELLULAR_DEVICE_U_BLOX_SARA_R5(inst) \
3035-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
3035+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
30363036
\
30373037
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
30383038
.chat_delimiter = "\r", \
@@ -3051,7 +3051,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
30513051
&u_blox_sara_r5_periodic_chat_script, NULL)
30523052

30533053
#define MODEM_CELLULAR_DEVICE_U_BLOX_LARA_R6(inst) \
3054-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
3054+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
30553055
\
30563056
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
30573057
.chat_delimiter = "\r", \
@@ -3071,7 +3071,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
30713071
NULL)
30723072

30733073
#define MODEM_CELLULAR_DEVICE_SWIR_HL7800(inst) \
3074-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
3074+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
30753075
\
30763076
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
30773077
.chat_delimiter = "\r", \
@@ -3090,7 +3090,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
30903090
&swir_hl7800_periodic_chat_script, NULL)
30913091

30923092
#define MODEM_CELLULAR_DEVICE_TELIT_ME910G1(inst) \
3093-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
3093+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
30943094
\
30953095
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
30963096
.chat_delimiter = "\r", \
@@ -3109,7 +3109,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
31093109
NULL)
31103110

31113111
#define MODEM_CELLULAR_DEVICE_TELIT_ME310G1(inst) \
3112-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
3112+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
31133113
\
31143114
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
31153115
.chat_delimiter = "\r", \
@@ -3128,7 +3128,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
31283128
&telit_me310g1_shutdown_chat_script)
31293129

31303130
#define MODEM_CELLULAR_DEVICE_NORDIC_NRF91_SLM(inst) \
3131-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 1500); \
3131+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 1500); \
31323132
\
31333133
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
31343134
.chat_delimiter = "\r\n", \
@@ -3145,7 +3145,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
31453145
&nordic_nrf91_slm_periodic_chat_script, NULL)
31463146

31473147
#define MODEM_CELLULAR_DEVICE_SQN_GM02S(inst) \
3148-
MODEM_PPP_DEFINE(MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
3148+
MODEM_DT_INST_PPP_DEFINE(inst, MODEM_CELLULAR_INST_NAME(ppp, inst), NULL, 98, 1500, 64); \
31493149
\
31503150
static struct modem_cellular_data MODEM_CELLULAR_INST_NAME(data, inst) = { \
31513151
.chat_delimiter = "\r", \

include/zephyr/modem/ppp.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ struct modem_ppp {
123123
#endif
124124
};
125125

126+
struct modem_ppp_config {
127+
const struct device *dev;
128+
};
129+
126130
/**
127131
* @endcond
128132
*/
@@ -172,13 +176,17 @@ int modem_ppp_init_internal(const struct device *dev);
172176
* network device instance, and binds the modem_ppp instance to the PPP L2
173177
* instance.
174178
*
179+
* If underlying cellular device is given, the PPP interface will manage the
180+
* power state of the cellular device when starting and stopping the PPP.
181+
*
182+
* @param _dev Cellular device instance for power management or NULL if not used
175183
* @param _name Name of the statically defined modem_ppp instance
176184
* @param _init_iface Hook for the PPP L2 network interface init function
177185
* @param _prio Initialization priority of the PPP L2 net iface
178186
* @param _mtu Max size of net_pkt data sent and received on PPP L2 net iface
179187
* @param _buf_size Size of partial PPP frame transmit and receive buffers
180188
*/
181-
#define MODEM_PPP_DEFINE(_name, _init_iface, _prio, _mtu, _buf_size) \
189+
#define MODEM_DEV_PPP_DEFINE(_dev, _name, _init_iface, _prio, _mtu, _buf_size) \
182190
extern const struct ppp_api modem_ppp_ppp_api; \
183191
\
184192
static uint8_t _CONCAT(_name, _receive_buf)[_buf_size]; \
@@ -189,11 +197,30 @@ int modem_ppp_init_internal(const struct device *dev);
189197
.receive_buf = _CONCAT(_name, _receive_buf), \
190198
.transmit_buf = _CONCAT(_name, _transmit_buf), \
191199
.buf_size = _buf_size, \
200+
}; \
201+
static const struct modem_ppp_config _CONCAT(_name, _config) = { \
202+
.dev = _dev, \
192203
}; \
193204
\
194-
NET_DEVICE_INIT(_CONCAT(ppp_net_dev_, _name), "modem_ppp_" # _name, \
195-
modem_ppp_init_internal, NULL, &_name, NULL, _prio, &modem_ppp_ppp_api, \
196-
PPP_L2, NET_L2_GET_CTX_TYPE(PPP_L2), _mtu)
205+
NET_DEVICE_INIT(_CONCAT(ppp_net_dev_, _name), "modem_ppp_" #_name, \
206+
modem_ppp_init_internal, NULL, &_name, &_CONCAT(_name, _config), _prio, \
207+
&modem_ppp_ppp_api, PPP_L2, NET_L2_GET_CTX_TYPE(PPP_L2), _mtu)
208+
209+
/**
210+
* @brief Define a modem PPP module for cellular device tree instance.
211+
*
212+
* @see MODEM_DEV_PPP_DEFINE
213+
*/
214+
#define MODEM_DT_INST_PPP_DEFINE(inst, _name, _init_iface, _prio, _mtu, _buf_size) \
215+
MODEM_DEV_PPP_DEFINE(DEVICE_DT_INST_GET(inst), _name, _init_iface, _prio, _mtu, _buf_size)
216+
217+
/**
218+
* @brief Define a modem PPP module without a device and bind it to a network interface.
219+
*
220+
* @see MODEM_DEV_PPP_DEFINE
221+
*/
222+
#define MODEM_PPP_DEFINE(_name, _init_iface, _prio, _mtu, _buf_size) \
223+
MODEM_DEV_PPP_DEFINE(NULL, _name, _init_iface, _prio, _mtu, _buf_size)
197224

198225
/**
199226
* @}

subsys/modem/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ config MODEM_PPP
7171
select MODEM_PIPE
7272
select RING_BUFFER
7373
select CRC
74+
select PM_DEVICE_RUNTIME_ASYNC if PM_DEVICE_RUNTIME
7475

7576
if MODEM_PPP
7677

subsys/modem/modem_ppp.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <zephyr/net/ppp.h>
88
#include <zephyr/sys/crc.h>
99
#include <zephyr/modem/ppp.h>
10+
#include <zephyr/pm/device_runtime.h>
1011
#include <string.h>
1112

1213
#include <zephyr/logging/log.h>
@@ -445,12 +446,24 @@ static void modem_ppp_ppp_api_init(struct net_if *iface)
445446

446447
static int modem_ppp_ppp_api_start(const struct device *dev)
447448
{
448-
return 0;
449+
const struct modem_ppp_config *config = (const struct modem_ppp_config *)dev->config;
450+
451+
if (config == NULL || config->dev == NULL) {
452+
return 0;
453+
}
454+
455+
return pm_device_runtime_get(config->dev);
449456
}
450457

451458
static int modem_ppp_ppp_api_stop(const struct device *dev)
452459
{
453-
return 0;
460+
const struct modem_ppp_config *config = (const struct modem_ppp_config *)dev->config;
461+
462+
if (config == NULL || config->dev == NULL) {
463+
return 0;
464+
}
465+
466+
return pm_device_runtime_put_async(config->dev, K_NO_WAIT);
454467
}
455468

456469
static int modem_ppp_ppp_api_send(const struct device *dev, struct net_pkt *pkt)

0 commit comments

Comments
 (0)