Skip to content

Commit 2d81801

Browse files
SeppoTakalorlubos
authored andcommitted
[nrf fromlist] drivers: modem: Implement support for DTR signal
DTR signal on UART extends the power saving by allowing host to indicate the remote end that the UART is not in active state. Upstream PR #: 98145 Signed-off-by: Seppo Takalo <[email protected]>
1 parent 78d68c1 commit 2d81801

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed

drivers/modem/modem_cellular.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ struct modem_cellular_config {
185185
struct gpio_dt_spec power_gpio;
186186
struct gpio_dt_spec reset_gpio;
187187
struct gpio_dt_spec wake_gpio;
188+
struct gpio_dt_spec dtr_gpio;
188189
uint16_t power_pulse_duration_ms;
189190
uint16_t reset_pulse_duration_ms;
190191
uint16_t startup_time_ms;
@@ -2095,6 +2096,7 @@ static int modem_cellular_init(const struct device *dev)
20952096
{
20962097
struct modem_cellular_data *data = (struct modem_cellular_data *)dev->data;
20972098
struct modem_cellular_config *config = (struct modem_cellular_config *)dev->config;
2099+
const struct gpio_dt_spec *dtr_gpio = NULL;
20982100

20992101
data->dev = dev;
21002102

@@ -2118,9 +2120,15 @@ static int modem_cellular_init(const struct device *dev)
21182120
gpio_pin_configure_dt(&config->reset_gpio, GPIO_OUTPUT_ACTIVE);
21192121
}
21202122

2123+
if (modem_cellular_gpio_is_enabled(&config->dtr_gpio)) {
2124+
gpio_pin_configure_dt(&config->dtr_gpio, GPIO_OUTPUT_INACTIVE);
2125+
dtr_gpio = &config->dtr_gpio;
2126+
}
2127+
21212128
{
21222129
const struct modem_backend_uart_config uart_backend_config = {
21232130
.uart = config->uart,
2131+
.dtr_gpio = dtr_gpio,
21242132
.receive_buf = data->uart_backend_receive_buf,
21252133
.receive_buf_size = ARRAY_SIZE(data->uart_backend_receive_buf),
21262134
.transmit_buf = data->uart_backend_transmit_buf,
@@ -2888,6 +2896,7 @@ MODEM_CHAT_SCRIPT_DEFINE(sqn_gm02s_periodic_chat_script,
28882896
.power_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_power_gpios, {}), \
28892897
.reset_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_reset_gpios, {}), \
28902898
.wake_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_wake_gpios, {}), \
2899+
.dtr_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mdm_dtr_gpios, {}), \
28912900
.power_pulse_duration_ms = (power_ms), \
28922901
.reset_pulse_duration_ms = (reset_ms), \
28932902
.startup_time_ms = (startup_ms), \

dts/bindings/modem/zephyr,cellular-modem-device.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ properties:
1717
mdm-wake-gpios:
1818
type: phandle-array
1919
description: GPIO for modem wake
20+
21+
mdm-dtr-gpios:
22+
type: phandle-array
23+
description: |
24+
GPIO for modem data terminal ready.
25+
26+
Asserted (logical high) when UART is active and
27+
deasserted (logical low) when UART is inactive, powered down or in low power mode.

include/zephyr/modem/backend/uart.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct modem_backend_uart_async {
6868

6969
struct modem_backend_uart {
7070
const struct device *uart;
71+
const struct gpio_dt_spec *dtr_gpio;
7172
struct modem_pipe pipe;
7273
struct k_work_delayable receive_ready_work;
7374
struct k_work transmit_idle_work;
@@ -85,6 +86,7 @@ struct modem_backend_uart {
8586

8687
struct modem_backend_uart_config {
8788
const struct device *uart;
89+
const struct gpio_dt_spec *dtr_gpio;
8890
/* Address must be word-aligned when CONFIG_MODEM_BACKEND_UART_ASYNC_HWFC is enabled. */
8991
uint8_t *receive_buf;
9092
uint32_t receive_buf_size;

subsys/modem/backends/modem_backend_uart.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct modem_pipe *modem_backend_uart_init(struct modem_backend_uart *backend,
3939

4040
memset(backend, 0x00, sizeof(*backend));
4141
backend->uart = config->uart;
42+
backend->dtr_gpio = config->dtr_gpio;
4243
k_work_init_delayable(&backend->receive_ready_work,
4344
modem_backend_uart_receive_ready_handler);
4445
k_work_init(&backend->transmit_idle_work, modem_backend_uart_transmit_idle_handler);

subsys/modem/backends/modem_backend_uart_async.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
LOG_MODULE_REGISTER(modem_backend_uart_async, CONFIG_MODEM_MODULES_LOG_LEVEL);
1212

1313
#include <zephyr/kernel.h>
14+
#include <zephyr/drivers/gpio.h>
1415
#include <string.h>
1516

1617
enum {
@@ -157,6 +158,10 @@ static int modem_backend_uart_async_open(void *data)
157158
atomic_clear(&backend->async.common.state);
158159
ring_buf_reset(&backend->async.receive_rb);
159160

161+
if (backend->dtr_gpio) {
162+
gpio_pin_set_dt(backend->dtr_gpio, 1);
163+
}
164+
160165
atomic_set_bit(&backend->async.common.state,
161166
MODEM_BACKEND_UART_ASYNC_STATE_RX_BUF0_USED_BIT);
162167
atomic_set_bit(&backend->async.common.state, MODEM_BACKEND_UART_ASYNC_STATE_RECEIVING_BIT);
@@ -268,6 +273,9 @@ static int modem_backend_uart_async_close(void *data)
268273
atomic_clear_bit(&backend->async.common.state, MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT);
269274
uart_tx_abort(backend->uart);
270275
uart_rx_disable(backend->uart);
276+
if (backend->dtr_gpio) {
277+
gpio_pin_set_dt(backend->dtr_gpio, 0);
278+
}
271279
return 0;
272280
}
273281

subsys/modem/backends/modem_backend_uart_async_hwfc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
LOG_MODULE_REGISTER(modem_backend_uart_async_hwfc, CONFIG_MODEM_MODULES_LOG_LEVEL);
1212

1313
#include <zephyr/kernel.h>
14+
#include <zephyr/drivers/gpio.h>
1415
#include <string.h>
1516

1617
struct rx_buf_t {
@@ -221,6 +222,10 @@ static int modem_backend_uart_async_hwfc_open(void *data)
221222
return -ENOMEM;
222223
}
223224

225+
if (backend->dtr_gpio) {
226+
gpio_pin_set_dt(backend->dtr_gpio, 1);
227+
}
228+
224229
atomic_clear(&backend->async.common.state);
225230
atomic_set_bit(&backend->async.common.state, MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT);
226231

@@ -357,6 +362,9 @@ static int modem_backend_uart_async_hwfc_close(void *data)
357362
uart_rx_disable(backend->uart);
358363
}
359364

365+
if (backend->dtr_gpio) {
366+
gpio_pin_set_dt(backend->dtr_gpio, 0);
367+
}
360368
return 0;
361369
}
362370

0 commit comments

Comments
 (0)