Skip to content

Commit ca2f491

Browse files
galakcarlescufi
authored andcommitted
modem: wncm14a2a: Update driver to use gpio_dt_spec
Simplify the implementation by using gpio_dt_spec. As part of this use logical values of 0/1 for gpio_pin_set_dt and handle any inversions as GPIO flags that might be required at a board level (in dts config). Signed-off-by: Kumar Gala <[email protected]>
1 parent d33b89b commit ca2f491

File tree

3 files changed

+42
-109
lines changed

3 files changed

+42
-109
lines changed

boards/shields/wnc_m14a2a/boards/frdm_k64f.overlay

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
status = "okay";
1818
compatible = "wnc,m14a2a";
1919
label = "wnc-m14a2a";
20-
mdm-boot-mode-sel-gpios = <&arduino_header 7 0>; /* D1 */
21-
mdm-power-gpios = <&arduino_header 8 0>; /* D2 */
22-
mdm-keep-awake-gpios = <&arduino_header 12 0>; /* D6 */
23-
mdm-reset-gpios = <&arduino_header 14 0>; /* D8 */
24-
mdm-shld-trans-ena-gpios = <&arduino_header 15 0>; /* D9 */
20+
mdm-boot-mode-sel-gpios = <&arduino_header 7 GPIO_ACTIVE_HIGH>; /* D1 */
21+
mdm-power-gpios = <&arduino_header 8 GPIO_ACTIVE_LOW>; /* D2 */
22+
mdm-keep-awake-gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; /* D6 */
23+
mdm-reset-gpios = <&arduino_header 14 GPIO_ACTIVE_HIGH>; /* D8 */
24+
mdm-shld-trans-ena-gpios = <&arduino_header 15 GPIO_ACTIVE_HIGH>; /* D9 */
2525
};
2626
};

boards/shields/wnc_m14a2a/boards/nrf52840dk_nrf52840.overlay

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
status = "okay";
4343
compatible = "wnc,m14a2a";
4444
label = "wnc-m14a2a";
45-
mdm-boot-mode-sel-gpios = <&arduino_header 7 0>; /* D1 */
46-
mdm-power-gpios = <&arduino_header 8 0>; /* D2 */
47-
mdm-keep-awake-gpios = <&arduino_header 12 0>; /* D6 */
48-
mdm-reset-gpios = <&arduino_header 14 0>; /* D8 */
49-
mdm-shld-trans-ena-gpios = <&arduino_header 15 0>; /* D9 */
45+
mdm-boot-mode-sel-gpios = <&arduino_header 7 GPIO_ACTIVE_HIGH>; /* D1 */
46+
mdm-power-gpios = <&arduino_header 8 GPIO_ACTIVE_LOW>; /* D2 */
47+
mdm-keep-awake-gpios = <&arduino_header 12 GPIO_ACTIVE_HIGH>; /* D6 */
48+
mdm-reset-gpios = <&arduino_header 14 GPIO_ACTIVE_HIGH>; /* D8 */
49+
mdm-shld-trans-ena-gpios = <&arduino_header 15 GPIO_ACTIVE_HIGH>; /* D9 */
5050
};
5151
};

drivers/modem/wncm14a2a.c

+32-99
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
4343
*/
4444
/* #define ENABLE_VERBOSE_MODEM_RECV_HEXDUMP 1 */
4545

46-
struct mdm_control_pinconfig {
47-
char *dev_name;
48-
gpio_pin_t pin;
49-
gpio_flags_t flags;
50-
};
51-
52-
#define PINCONFIG(name_, pin_, flags_) { \
53-
.dev_name = name_, \
54-
.pin = pin_, \
55-
.flags = flags_ \
56-
}
57-
5846
/* pin settings */
5947
enum mdm_control_pins {
6048
MDM_BOOT_MODE_SEL = 0,
@@ -68,54 +56,10 @@ enum mdm_control_pins {
6856
MAX_MDM_CONTROL_PINS,
6957
};
7058

71-
static const struct mdm_control_pinconfig pinconfig[] = {
72-
/* MDM_BOOT_MODE_SEL */
73-
PINCONFIG(DT_INST_GPIO_LABEL(0, mdm_boot_mode_sel_gpios),
74-
DT_INST_GPIO_PIN(0, mdm_boot_mode_sel_gpios),
75-
DT_INST_GPIO_FLAGS(0, mdm_boot_mode_sel_gpios)),
76-
77-
/* MDM_POWER */
78-
PINCONFIG(DT_INST_GPIO_LABEL(0, mdm_power_gpios),
79-
DT_INST_GPIO_PIN(0, mdm_power_gpios),
80-
DT_INST_GPIO_FLAGS(0, mdm_power_gpios)),
81-
82-
/* MDM_KEEP_AWAKE */
83-
PINCONFIG(DT_INST_GPIO_LABEL(0, mdm_keep_awake_gpios),
84-
DT_INST_GPIO_PIN(0, mdm_keep_awake_gpios),
85-
DT_INST_GPIO_FLAGS(0, mdm_keep_awake_gpios)),
86-
87-
/* MDM_RESET */
88-
PINCONFIG(DT_INST_GPIO_LABEL(0, mdm_reset_gpios),
89-
DT_INST_GPIO_PIN(0, mdm_reset_gpios),
90-
DT_INST_GPIO_FLAGS(0, mdm_reset_gpios)),
91-
92-
/* SHLD_3V3_1V8_SIG_TRANS_ENA */
93-
PINCONFIG(DT_INST_GPIO_LABEL(0, mdm_shld_trans_ena_gpios),
94-
DT_INST_GPIO_PIN(0, mdm_shld_trans_ena_gpios),
95-
DT_INST_GPIO_FLAGS(0, mdm_shld_trans_ena_gpios)),
96-
97-
#if DT_INST_NODE_HAS_PROP(0, mdm_send_ok_gpios)
98-
/* MDM_SEND_OK */
99-
PINCONFIG(DT_INST_GPIO_LABEL(0, mdm_send_ok_gpios),
100-
DT_INST_GPIO_PIN(0, mdm_send_ok_gpios),
101-
DT_INST_GPIO_FLAGS(0, mdm_send_ok_gpios)),
102-
#endif
103-
};
104-
10559
#define MDM_UART_DEV DEVICE_DT_GET(DT_INST_BUS(0))
10660

10761
#define MDM_BOOT_MODE_SPECIAL 0
10862
#define MDM_BOOT_MODE_NORMAL 1
109-
#define MDM_POWER_ENABLE 0
110-
#define MDM_POWER_DISABLE 1
111-
#define MDM_KEEP_AWAKE_DISABLED 0
112-
#define MDM_KEEP_AWAKE_ENABLED 1
113-
#define MDM_RESET_NOT_ASSERTED 0
114-
#define MDM_RESET_ASSERTED 1
115-
#define SHLD_3V3_1V8_SIG_TRANS_DISABLED 0
116-
#define SHLD_3V3_1V8_SIG_TRANS_ENABLED 1
117-
#define MDM_SEND_OK_ENABLED 0
118-
#define MDM_SEND_OK_DISABLED 1
11963

12064
#define MDM_CMD_TIMEOUT (5 * MSEC_PER_SEC)
12165
#define MDM_CMD_SEND_TIMEOUT (10 * MSEC_PER_SEC)
@@ -178,13 +122,14 @@ struct wncm14a2a_socket {
178122
void *recv_user_data;
179123
};
180124

125+
struct wncm14a2a_config {
126+
struct gpio_dt_spec gpio[MAX_MDM_CONTROL_PINS];
127+
};
128+
181129
struct wncm14a2a_iface_ctx {
182130
struct net_if *iface;
183131
uint8_t mac_addr[6];
184132

185-
/* GPIO PORT devices */
186-
const struct device *gpio_port_dev[MAX_MDM_CONTROL_PINS];
187-
188133
/* RX specific attributes */
189134
struct mdm_receiver_context mdm_ctx;
190135

@@ -217,6 +162,19 @@ struct cmd_handler {
217162
void (*func)(struct net_buf **buf, uint16_t len);
218163
};
219164

165+
const static struct wncm14a2a_config wncm14a2a_cfg = {
166+
.gpio = {
167+
GPIO_DT_SPEC_INST_GET(0, mdm_boot_mode_sel_gpios),
168+
GPIO_DT_SPEC_INST_GET(0, mdm_power_gpios),
169+
GPIO_DT_SPEC_INST_GET(0, mdm_keep_awake_gpios),
170+
GPIO_DT_SPEC_INST_GET(0, mdm_reset_gpios),
171+
GPIO_DT_SPEC_INST_GET(0, mdm_shld_trans_ena_gpios),
172+
#if DT_INST_NODE_HAS_PROP(0, mdm_send_ok_gpios)
173+
GPIO_DT_SPEC_INST_GET(0, mdm_send_ok_gpios),
174+
#endif
175+
},
176+
};
177+
220178
static struct wncm14a2a_iface_ctx ictx;
221179

222180
static void wncm14a2a_read_rx(struct net_buf **buf);
@@ -1231,12 +1189,10 @@ static int modem_pin_init(void)
12311189
* (doesn't go through the signal level translator)
12321190
*/
12331191
LOG_DBG("MDM_RESET_PIN -> ASSERTED");
1234-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_RESET],
1235-
pinconfig[MDM_RESET].pin, MDM_RESET_ASSERTED);
1192+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_RESET], 1);
12361193
k_sleep(K_SECONDS(7));
12371194
LOG_DBG("MDM_RESET_PIN -> NOT_ASSERTED");
1238-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_RESET],
1239-
pinconfig[MDM_RESET].pin, MDM_RESET_NOT_ASSERTED);
1195+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_RESET], 0);
12401196

12411197
/* disable signal level translator (necessary
12421198
* for the modem to boot properly). All signals
@@ -1246,32 +1202,22 @@ static int modem_pin_init(void)
12461202
* be in the correct state.
12471203
*/
12481204
LOG_DBG("SIG_TRANS_ENA_PIN -> DISABLED");
1249-
gpio_pin_set_raw(ictx.gpio_port_dev[SHLD_3V3_1V8_SIG_TRANS_ENA],
1250-
pinconfig[SHLD_3V3_1V8_SIG_TRANS_ENA].pin,
1251-
SHLD_3V3_1V8_SIG_TRANS_DISABLED);
1205+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[SHLD_3V3_1V8_SIG_TRANS_ENA], 0);
12521206

12531207
/* While the level translator is disabled and output pins
12541208
* are tristated, make sure the inputs are in the same state
12551209
* as the WNC Module pins so that when the level translator is
12561210
* enabled, there are no differences.
12571211
*/
12581212
LOG_DBG("MDM_BOOT_MODE_SEL_PIN -> NORMAL");
1259-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_BOOT_MODE_SEL],
1260-
pinconfig[MDM_BOOT_MODE_SEL].pin,
1261-
MDM_BOOT_MODE_NORMAL);
1213+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_BOOT_MODE_SEL], MDM_BOOT_MODE_NORMAL);
12621214
LOG_DBG("MDM_POWER_PIN -> ENABLE");
1263-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_POWER],
1264-
pinconfig[MDM_POWER].pin,
1265-
MDM_POWER_ENABLE);
1215+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_POWER], 1);
12661216
LOG_DBG("MDM_KEEP_AWAKE_PIN -> ENABLED");
1267-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_KEEP_AWAKE],
1268-
pinconfig[MDM_KEEP_AWAKE].pin,
1269-
MDM_KEEP_AWAKE_ENABLED);
1217+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_KEEP_AWAKE], 1);
12701218
#if DT_INST_NODE_HAS_PROP(0, mdm_send_ok_gpios)
12711219
LOG_DBG("MDM_SEND_OK_PIN -> ENABLED");
1272-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_SEND_OK],
1273-
pinconfig[MDM_SEND_OK].pin,
1274-
MDM_SEND_OK_ENABLED);
1220+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_SEND_OK], 1);
12751221
#endif
12761222

12771223
/* wait for the WNC Module to perform its initial boot correctly */
@@ -1283,9 +1229,7 @@ static int modem_pin_init(void)
12831229
* When enabled, there will be no changes in the above 4 pins...
12841230
*/
12851231
LOG_DBG("SIG_TRANS_ENA_PIN -> ENABLED");
1286-
gpio_pin_set_raw(ictx.gpio_port_dev[SHLD_3V3_1V8_SIG_TRANS_ENA],
1287-
pinconfig[SHLD_3V3_1V8_SIG_TRANS_ENA].pin,
1288-
SHLD_3V3_1V8_SIG_TRANS_ENABLED);
1232+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[SHLD_3V3_1V8_SIG_TRANS_ENA], 1);
12891233

12901234
LOG_INF("... Done!");
12911235

@@ -1300,14 +1244,10 @@ static void modem_wakeup_pin_fix(void)
13001244
LOG_DBG("Toggling MDM_KEEP_AWAKE_PIN to avoid missed characters");
13011245
k_sleep(K_MSEC(20));
13021246
LOG_DBG("MDM_KEEP_AWAKE_PIN -> DISABLED");
1303-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_KEEP_AWAKE],
1304-
pinconfig[MDM_KEEP_AWAKE].pin,
1305-
MDM_KEEP_AWAKE_DISABLED);
1247+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_KEEP_AWAKE], 0);
13061248
k_sleep(K_SECONDS(2));
13071249
LOG_DBG("MDM_KEEP_AWAKE_PIN -> ENABLED");
1308-
gpio_pin_set_raw(ictx.gpio_port_dev[MDM_KEEP_AWAKE],
1309-
pinconfig[MDM_KEEP_AWAKE].pin,
1310-
MDM_KEEP_AWAKE_ENABLED);
1250+
gpio_pin_set_dt(&wncm14a2a_cfg.gpio[MDM_KEEP_AWAKE], 1);
13111251
k_sleep(K_MSEC(20));
13121252
}
13131253

@@ -1444,10 +1384,6 @@ static int wncm14a2a_init(const struct device *dev)
14441384

14451385
ARG_UNUSED(dev);
14461386

1447-
/* check for valid pinconfig */
1448-
__ASSERT(ARRAY_SIZE(pinconfig) == MAX_MDM_CONTROL_PINS,
1449-
"Incorrect modem pinconfig!");
1450-
14511387
(void)memset(&ictx, 0, sizeof(ictx));
14521388
for (i = 0; i < MDM_MAX_SOCKETS; i++) {
14531389
k_work_init(&ictx.sockets[i].recv_cb_work,
@@ -1465,16 +1401,13 @@ static int wncm14a2a_init(const struct device *dev)
14651401

14661402
/* setup port devices and pin directions */
14671403
for (i = 0; i < MAX_MDM_CONTROL_PINS; i++) {
1468-
ictx.gpio_port_dev[i] =
1469-
device_get_binding(pinconfig[i].dev_name);
1470-
if (!ictx.gpio_port_dev[i]) {
1471-
LOG_ERR("gpio port (%s) not found!",
1472-
pinconfig[i].dev_name);
1404+
if (!device_is_ready(wncm14a2a_cfg.gpio[i].port)) {
1405+
LOG_ERR("gpio port (%s) not ready!",
1406+
wncm14a2a_cfg.gpio[i].port->name);
14731407
return -ENODEV;
14741408
}
14751409

1476-
gpio_pin_configure(ictx.gpio_port_dev[i], pinconfig[i].pin,
1477-
pinconfig[i].flags | GPIO_OUTPUT);
1410+
gpio_pin_configure_dt(&wncm14a2a_cfg.gpio[i], GPIO_OUTPUT);
14781411
}
14791412

14801413
/* Set modem data storage */
@@ -1845,7 +1778,7 @@ static struct net_if_api api_funcs = {
18451778
};
18461779

18471780
NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, wncm14a2a_init, NULL,
1848-
&ictx, NULL,
1781+
&ictx, &wncm14a2a_cfg,
18491782
CONFIG_MODEM_WNCM14A2A_INIT_PRIORITY,
18501783
&api_funcs,
18511784
MDM_MAX_DATA_LENGTH);

0 commit comments

Comments
 (0)