Skip to content

Commit 9d2f8a1

Browse files
ycsinnashif
authored andcommitted
drivers: modem: gsm_ppp: Use DTS
Convert the gsm_ppp driver to use DTS. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent 6c98d41 commit 9d2f8a1

File tree

19 files changed

+87
-29
lines changed

19 files changed

+87
-29
lines changed

drivers/modem/Kconfig.gsm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ config MODEM_GSM_SIMCOM
2929

3030
endchoice
3131

32-
config MODEM_GSM_UART_NAME
33-
string "UART device name the modem is connected to"
34-
3532
config MODEM_GSM_RX_STACK_SIZE
3633
int "Size of the stack allocated for receiving data from modem"
3734
default 512

drivers/modem/gsm_ppp.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#define DT_DRV_COMPAT zephyr_gsm_ppp
8+
79
#include <logging/log.h>
810
LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL);
911

@@ -24,6 +26,7 @@ LOG_MODULE_REGISTER(modem_gsm, CONFIG_MODEM_LOG_LEVEL);
2426

2527
#include <stdio.h>
2628

29+
#define GSM_UART_NODE DT_INST_BUS(0)
2730
#define GSM_CMD_READ_BUF 128
2831
#define GSM_CMD_AT_TIMEOUT K_SECONDS(2)
2932
#define GSM_CMD_SETUP_TIMEOUT K_SECONDS(6)
@@ -522,8 +525,7 @@ static struct net_if *ppp_net_if(void)
522525
static void set_ppp_carrier_on(struct gsm_modem *gsm)
523526
{
524527
static const struct ppp_api *api;
525-
const struct device *ppp_dev =
526-
device_get_binding(CONFIG_NET_PPP_DRV_NAME);
528+
const struct device *ppp_dev = DEVICE_DT_GET(DT_INST(0, zephyr_gsm_ppp));
527529
struct net_if *iface = gsm->iface;
528530
int ret;
529531

@@ -821,7 +823,7 @@ static void mux_setup(struct k_work *work)
821823
{
822824
struct gsm_modem *gsm = CONTAINER_OF(work, struct gsm_modem,
823825
gsm_configure_work);
824-
const struct device *uart = device_get_binding(CONFIG_MODEM_GSM_UART_NAME);
826+
const struct device *uart = DEVICE_DT_GET(GSM_UART_NODE);
825827
int ret;
826828

827829
/* We need to call this to reactivate mux ISR. Note: This is only called
@@ -980,7 +982,7 @@ void gsm_ppp_start(const struct device *dev)
980982

981983
/* Re-init underlying UART comms */
982984
int r = modem_iface_uart_init_dev(&gsm->context.iface,
983-
device_get_binding(CONFIG_MODEM_GSM_UART_NAME));
985+
DEVICE_DT_GET(GSM_UART_NODE));
984986
if (r) {
985987
LOG_ERR("modem_iface_uart_init returned %d", r);
986988
return;
@@ -1057,7 +1059,7 @@ static int gsm_init(const struct device *dev)
10571059
gsm->gsm_data.rx_rb_buf_len = sizeof(gsm->gsm_rx_rb_buf);
10581060

10591061
r = modem_iface_uart_init(&gsm->context.iface, &gsm->gsm_data,
1060-
device_get_binding(CONFIG_MODEM_GSM_UART_NAME));
1062+
DEVICE_DT_GET(GSM_UART_NODE));
10611063
if (r < 0) {
10621064
LOG_DBG("iface uart error %d", r);
10631065
return r;
@@ -1091,5 +1093,5 @@ static int gsm_init(const struct device *dev)
10911093
return 0;
10921094
}
10931095

1094-
DEVICE_DEFINE(gsm_ppp, GSM_MODEM_DEVICE_NAME, gsm_init, NULL, &gsm, NULL,
1095-
POST_KERNEL, CONFIG_MODEM_GSM_INIT_PRIORITY, NULL);
1096+
DEVICE_DT_DEFINE(DT_INST(0, zephyr_gsm_ppp), gsm_init, NULL, &gsm, NULL,
1097+
POST_KERNEL, CONFIG_MODEM_GSM_INIT_PRIORITY, NULL);

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, zephyr_gsm_ppp));
866866
#else
867867
dev_name = CONFIG_NET_PPP_UART_NAME;
868868
#endif
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2021 G-Technologies Sdn. Bhd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: GSM PPP modem
5+
6+
compatible: "zephyr,gsm-ppp"
7+
8+
include: uart-device.yaml

include/drivers/gsm_ppp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#ifndef GSM_PPP_H_
88
#define GSM_PPP_H_
99

10-
#define GSM_MODEM_DEVICE_NAME "modem_gsm"
11-
1210
/** @cond INTERNAL_HIDDEN */
1311
struct device;
1412
void gsm_ppp_start(const struct device *dev);

samples/net/cloud/tagoio_http_post/README.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,27 @@ Modem
8787
The Modem support is quite similar to WIFI, you need a board with an embedded
8888
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``.
90-
Additionally you need fill ``CONFIG_MODEM_GSM_UART_NAME`` with the UART label
91-
``CONFIG_MODEM_GSM_APN`` with the correspondent Access Point Name (APN) at
92-
:zephyr_file:`samples/net/cloud/tagoio_http_post/overlay-modem.conf` file.
90+
Additionally you need fill ``CONFIG_MODEM_GSM_APN`` with the correspondent Access
91+
Point Name (APN) at
92+
:zephyr_file:`samples/net/cloud/tagoio_http_post/overlay-modem.conf` file. A
93+
DTC overlay file should be used to configure the glue between the modem and the
94+
uart port. It can reside at boards directory, with the board name, or it can be
95+
a special designator like defined at ``arduino.overlay``.
9396

9497
.. zephyr-app-commands::
9598
:zephyr-app: samples/net/cloud/tagoio_http_post
96-
:board: [sam4e_xpro | frdm_k64f]
99+
:board: sam4e_xpro
97100
:gen-args: -DOVERLAY_CONFIG=overlay-modem.conf
98101
:goals: build flash
99102
:compact:
100103

104+
.. zephyr-app-commands::
105+
:zephyr-app: samples/net/cloud/tagoio_http_post
106+
:board: frdm_k64f
107+
:gen-args: -DOVERLAY_CONFIG=overlay-modem.conf -DDTC_OVERLAY_FILE=arduino.overlay
108+
:goals: build flash
109+
:compact:
110+
101111
In a terminal window you can check if communication is happen:
102112

103113
.. code-block:: console
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2021 G-Technologies Sdn. Bhd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&arduino_serial {
8+
status = "okay";
9+
current-speed = <115200>;
10+
11+
gsm: gsm-modem {
12+
compatible = "zephyr,gsm-ppp";
13+
label = "gsm_ppp";
14+
};
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2021 G-Technologies Sdn. Bhd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&usart1 {
8+
status = "okay";
9+
current-speed = <115200>;
10+
11+
gsm: gsm-modem {
12+
compatible = "zephyr,gsm-ppp";
13+
label = "gsm_ppp";
14+
};
15+
};

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/cloud/tagoio_http_post/sample.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ tests:
1616
platform_allow: frdm_k64f nucleo_f767zi
1717
sample.net.cloud.tagoio_http_post.modem:
1818
extra_args: OVERLAY_CONFIG="overlay-modem.conf"
19-
platform_allow: sam4e_xpro frdm_k64f
19+
platform_allow: sam4e_xpro
20+
sample.net.cloud.tagoio_http_post.modem.arduino:
21+
extra_args: OVERLAY_CONFIG="overlay-modem.conf" DTC_OVERLAY_FILE="arduino.overlay"
22+
platform_allow: frdm_k64f

0 commit comments

Comments
 (0)