Skip to content

Commit f1ad85d

Browse files
committed
driver: modem: gsm_ppp: Use DTS
1 parent 1f90e3e commit f1ad85d

File tree

14 files changed

+41
-15
lines changed

14 files changed

+41
-15
lines changed

drivers/modem/Kconfig.gsm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2020 Intel Corporation
2+
# Copyright (c) 2021 G-Technologies Sdn. Bhd.
23
# SPDX-License-Identifier: Apache-2.0
34

45
config MODEM_GSM_PPP
@@ -29,8 +30,6 @@ config MODEM_GSM_SIMCOM
2930

3031
endchoice
3132

32-
config MODEM_GSM_UART_NAME
33-
string "UART device name the modem is connected to"
3433

3534
config MODEM_GSM_RX_STACK_SIZE
3635
int "Size of the stack allocated for receiving data from modem"

drivers/modem/gsm_ppp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
7+
#define DT_DRV_COMPAT gsm_ppp
78

89
#include <logging/log.h>
910
LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL);
@@ -29,6 +30,8 @@ LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL);
2930
#include <time.h>
3031
#endif
3132

33+
#define GSM_UART_DEV_ID DT_INST_BUS(0)
34+
#define GSM_UART_DEV_NAME DT_INST_BUS_LABEL(0)
3235
#define GSM_CMD_READ_BUF 128
3336
#define GSM_CMD_AT_TIMEOUT K_SECONDS(2)
3437
#define GSM_CMD_SETUP_TIMEOUT K_SECONDS(6)
@@ -1067,7 +1070,7 @@ static void mux_setup(struct k_work *work)
10671070
{
10681071
struct gsm_modem *gsm = CONTAINER_OF(work, struct gsm_modem,
10691072
gsm_configure_work);
1070-
const struct device *uart = device_get_binding(CONFIG_MODEM_GSM_UART_NAME);
1073+
const struct device *uart = DEVICE_DT_GET(GSM_UART_DEV_ID);
10711074
int ret;
10721075

10731076
/* We need to call this to reactivate mux ISR. Note: This is only called
@@ -1226,7 +1229,7 @@ void gsm_ppp_start(const struct device *dev)
12261229

12271230
/* Re-init underlying UART comms */
12281231
int r = modem_iface_uart_init_dev(&gsm->context.iface,
1229-
device_get_binding(CONFIG_MODEM_GSM_UART_NAME));
1232+
DEVICE_DT_GET(GSM_UART_DEV_ID));
12301233
if (r) {
12311234
LOG_ERR("modem_iface_uart_init returned %d", r);
12321235
return;
@@ -1303,7 +1306,7 @@ static int gsm_init(const struct device *dev)
13031306
gsm->gsm_data.rx_rb_buf_len = sizeof(gsm->gsm_rx_rb_buf);
13041307

13051308
r = modem_iface_uart_init(&gsm->context.iface, &gsm->gsm_data,
1306-
device_get_binding(CONFIG_MODEM_GSM_UART_NAME));
1309+
DEVICE_DT_GET(GSM_UART_DEV_ID));
13071310
if (r < 0) {
13081311
LOG_DBG("iface uart error %d", r);
13091312
return r;

drivers/net/ppp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static int ppp_start(const struct device *dev)
862862

863863
dev_name = mux->name;
864864
#elif IS_ENABLED(CONFIG_MODEM_GSM_PPP)
865-
dev_name = CONFIG_MODEM_GSM_UART_NAME;
865+
dev_name = DT_BUS_LABEL(DT_INST(0, gsm_ppp));
866866
#else
867867
dev_name = CONFIG_NET_PPP_UART_NAME;
868868
#endif

dts/bindings/modem/gsm-ppp.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2021 G-Technologies Sdn. Bhd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: GSM PPP modem
5+
6+
compatible: "gsm,ppp"
7+
8+
include: uart-device.yaml
9+
10+
properties:
11+
label:
12+
required: true
13+

samples/net/cloud/tagoio_http_post/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Modem support or you can add a shield. Currently, the overlay was created to
8989
allow modems with PPP support. This was tested using ``SIMcom SIM808 EVB``.
9090
Additionally you need fill ``CONFIG_MODEM_GSM_UART_NAME`` with the UART label
9191
``CONFIG_MODEM_GSM_APN`` with the correspondent Access Point Name (APN) at
92+
Additionally you need to add a modem subnode under the UART in the dts, see
93+
:zephyr_file:`samples/net/gsm_modem/boards/frdm_uart2_dts.overlay`
94+
and fill ``CONFIG_MODEM_GSM_APN`` with the correspondent Access Point Name
95+
(APN) at
9296
:zephyr_file:`samples/net/cloud/tagoio_http_post/overlay-modem.conf` file.
9397

9498
.. zephyr-app-commands::

samples/net/cloud/tagoio_http_post/overlay-modem.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ CONFIG_MODEM_SHELL=y
77
CONFIG_MODEM_CMD_HANDLER_MAX_PARAM_COUNT=20
88
CONFIG_MODEM_GSM_PPP=y
99
CONFIG_MODEM_GSM_RX_STACK_SIZE=1024
10-
CONFIG_MODEM_GSM_UART_NAME="<your board UART port label>"
1110
CONFIG_MODEM_GSM_APN="<your Access Point Name (APN)>"
1211

1312
# Network management events

samples/net/gsm_modem/boards/frdm_uart2_dts.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
&uart2 {
77
status = "okay";
88
current-speed = <115200>;
9+
gsm: gsm_modem {
10+
compatible = "gsm,ppp";
11+
label = "gsm modem";
12+
};
913
};

samples/net/gsm_modem/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ CONFIG_SERIAL=y
44
# GSM modem support
55
CONFIG_MODEM=y
66
CONFIG_MODEM_GSM_PPP=y
7-
CONFIG_MODEM_GSM_UART_NAME="UART_1"
87

98
# PPP networking support
109
CONFIG_NET_PPP=y

samples/net/gsm_modem/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ static void event_handler(struct net_mgmt_event_callback *cb,
9393
int main(void)
9494
{
9595
const struct device *uart_dev =
96-
device_get_binding(CONFIG_MODEM_GSM_UART_NAME);
96+
DEVICE_DT_GET(DT_BUS(DT_INST(0, gsm_ppp)));
9797

9898
gsm_dev = device_get_binding(GSM_MODEM_DEVICE_NAME);
9999

100100
LOG_INF("Board '%s' APN '%s' UART '%s' device %p (%s)",
101101
CONFIG_BOARD, CONFIG_MODEM_GSM_APN,
102-
CONFIG_MODEM_GSM_UART_NAME, uart_dev, GSM_MODEM_DEVICE_NAME);
102+
DT_BUS_LABEL(DT_INST(0, gsm_ppp)), uart_dev, GSM_MODEM_DEVICE_NAME);
103103

104104
net_mgmt_init_event_callback(&mgmt_cb, event_handler,
105105
NET_EVENT_L4_CONNECTED |

samples/subsys/mgmt/updatehub/arduino.overlay

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
&arduino_serial {
88
status = "okay";
9-
label = "arduino_serial";
9+
gsm: gsm_modem {
10+
compatible = "gsm,ppp";
11+
};
1012

1113
current-speed = <115200>;
1214
};

0 commit comments

Comments
 (0)