Skip to content

Commit 394aaaa

Browse files
committed
lib: modem_slm: Power/indicate pins to devicetree
Move power and indicate pins from Kconfig to devicetree. Jira: LRCS-114 Signed-off-by: Tommi Rantanen <[email protected]>
1 parent 24f9d79 commit 394aaaa

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

lib/modem_slm/modem_slm.c

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
LOG_MODULE_REGISTER(mdm_slm, CONFIG_MODEM_SLM_LOG_LEVEL);
1818

19-
BUILD_ASSERT(CONFIG_MODEM_SLM_POWER_PIN >= 0, "Power pin not configured");
19+
BUILD_ASSERT(DT_NODE_HAS_PROP(DT_NODELABEL(slm_gpio_pins), power_gpios), "Power pin not configured");
2020

2121
#define UART_RX_MARGIN_MS 10
2222
#define UART_RX_TIMEOUT_US 2000
@@ -78,6 +78,14 @@ static struct k_work_delayable gpio_power_pin_disable_work;
7878
static slm_ind_handler_t ind_handler;
7979
static slm_ind_handler_t ind_handler_backup;
8080

81+
/* TODO: handle if ncs_slm_gpio is set to other than gpio0 */
82+
static const struct gpio_dt_spec power_pin_member =
83+
GPIO_DT_SPEC_GET_OR(DT_NODELABEL(slm_gpio_pins), power_gpios, {0});
84+
static const struct gpio_dt_spec indicate_pin_member =
85+
GPIO_DT_SPEC_GET_OR(DT_NODELABEL(slm_gpio_pins), indicate_gpios, {0});
86+
static const int power_pin_time_ms =
87+
DT_PROP(DT_NODELABEL(slm_gpio_pins), power_gpios_active_time_ms);
88+
8189
#if defined(CONFIG_MODEM_SLM_SHELL)
8290
static const struct shell *global_shell;
8391
static const char at_usage_str[] = "Usage: slm <at_command>";
@@ -99,20 +107,19 @@ static int indicate_pin_enable(void)
99107
int err = 0;
100108

101109
if (!indicate_pin_enabled) {
102-
err = gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN,
103-
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_LOW);
110+
err = gpio_pin_configure_dt(&indicate_pin_member,
111+
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_LOW);
104112
if (err) {
105113
LOG_ERR("GPIO config error: %d", err);
106114
return err;
107115
}
108116

109-
gpio_init_callback(&gpio_cb, gpio_cb_func, BIT(CONFIG_MODEM_SLM_INDICATE_PIN));
117+
gpio_init_callback(&gpio_cb, gpio_cb_func, BIT(indicate_pin_member.pin));
110118
err = gpio_add_callback(gpio_dev, &gpio_cb);
111119
if (err) {
112120
LOG_WRN("GPIO add callback error: %d", err);
113121
}
114-
err = gpio_pin_interrupt_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN,
115-
GPIO_INT_LEVEL_LOW);
122+
err = gpio_pin_interrupt_configure_dt(&indicate_pin_member, GPIO_INT_LEVEL_LOW);
116123
if (err) {
117124
LOG_WRN("GPIO interrupt configure error: %d", err);
118125
}
@@ -128,9 +135,8 @@ static void indicate_pin_disable(void)
128135
#if (CONFIG_MODEM_SLM_INDICATE_PIN >= 0)
129136
if (indicate_pin_enabled) {
130137
gpio_remove_callback(gpio_dev, &gpio_cb);
131-
gpio_pin_interrupt_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN,
132-
GPIO_INT_DISABLE);
133-
gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN, GPIO_DISCONNECTED);
138+
gpio_pin_interrupt_configure_dt(&indicate_pin_member, GPIO_INT_DISABLE);
139+
gpio_pin_configure_dt(&indicate_pin_member, GPIO_DISCONNECTED);
134140
indicate_pin_enabled = false;
135141
LOG_DBG("Indicate pin disabled");
136142
}
@@ -141,7 +147,7 @@ static void gpio_power_pin_disable_work_fn(struct k_work *work)
141147
{
142148
ARG_UNUSED(work);
143149

144-
if (gpio_pin_set(gpio_dev, CONFIG_MODEM_SLM_POWER_PIN, 0) != 0) {
150+
if (gpio_pin_set_dt(&power_pin_member, 0) != 0) {
145151
LOG_WRN("GPIO set error");
146152
}
147153
/* When SLM is woken up, indicate pin must be enabled */
@@ -537,13 +543,13 @@ static struct gpio_callback gpio_cb;
537543

538544
static void gpio_cb_func(const struct device *dev, struct gpio_callback *gpio_cb, uint32_t pins)
539545
{
540-
if ((BIT(CONFIG_MODEM_SLM_INDICATE_PIN) & pins) == 0) {
546+
if ((BIT(indicate_pin_member.pin) & pins) == 0) {
541547
return;
542548
}
543549

544550
if (k_work_delayable_is_pending(&gpio_power_pin_disable_work)) {
545551
(void)k_work_cancel_delayable(&gpio_power_pin_disable_work);
546-
(void)gpio_pin_set(gpio_dev, CONFIG_MODEM_SLM_POWER_PIN, 0);
552+
(void)gpio_pin_set_dt(&power_pin_member, 0);
547553
} else {
548554
/* Disable indicate pin so that callbacks doesn't keep on coming. */
549555
indicate_pin_disable();
@@ -566,9 +572,10 @@ static int gpio_init(void)
566572
LOG_ERR("GPIO controller not ready");
567573
return -ENODEV;
568574
}
575+
LOG_WRN("power_pin_member %d", power_pin_member.pin);
576+
LOG_WRN("indicate_pin_member %d", indicate_pin_member.pin);
569577

570-
err = gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_POWER_PIN,
571-
GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW);
578+
err = gpio_pin_configure_dt(&power_pin_member, GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW);
572579
if (err) {
573580
LOG_ERR("GPIO config error: %d", err);
574581
return err;
@@ -621,7 +628,7 @@ int modem_slm_uninit(void)
621628
{
622629
rx_disable();
623630

624-
gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_POWER_PIN, GPIO_DISCONNECTED);
631+
gpio_pin_configure_dt(&power_pin_member, GPIO_DISCONNECTED);
625632

626633
indicate_pin_disable();
627634

@@ -646,7 +653,7 @@ int modem_slm_register_ind(slm_ind_handler_t handler, bool wakeup)
646653
* Due to errata 4, Always configure PIN_CNF[n].INPUT before PIN_CNF[n].SENSE.
647654
* At this moment indicate pin has already been configured as INPUT at init_gpio().
648655
*/
649-
nrf_gpio_cfg_sense_set(CONFIG_MODEM_SLM_INDICATE_PIN, NRF_GPIO_PIN_SENSE_LOW);
656+
nrf_gpio_cfg_sense_set(indicate_pin_member.pin, NRF_GPIO_PIN_SENSE_LOW);
650657
}
651658

652659
return 0;
@@ -663,15 +670,15 @@ int modem_slm_power_pin_toggle(void)
663670
return 0;
664671
}
665672

666-
LOG_INF("Enable power pin");
673+
LOG_INF("Enable power pin for %d ms", power_pin_time_ms);
667674

668-
err = gpio_pin_set(gpio_dev, CONFIG_MODEM_SLM_POWER_PIN, 1);
675+
err = gpio_pin_set_dt(&power_pin_member, 1);
669676
if (err) {
670677
LOG_ERR("GPIO set error: %d", err);
671678
} else {
672679
k_work_reschedule(
673680
&gpio_power_pin_disable_work,
674-
K_MSEC(CONFIG_MODEM_SLM_POWER_PIN_TIME));
681+
K_MSEC(power_pin_time_ms));
675682
}
676683

677684
return 0;

0 commit comments

Comments
 (0)