@@ -43,18 +43,6 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
43
43
*/
44
44
/* #define ENABLE_VERBOSE_MODEM_RECV_HEXDUMP 1 */
45
45
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
-
58
46
/* pin settings */
59
47
enum mdm_control_pins {
60
48
MDM_BOOT_MODE_SEL = 0 ,
@@ -68,54 +56,10 @@ enum mdm_control_pins {
68
56
MAX_MDM_CONTROL_PINS ,
69
57
};
70
58
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
-
105
59
#define MDM_UART_DEV DEVICE_DT_GET(DT_INST_BUS(0))
106
60
107
61
#define MDM_BOOT_MODE_SPECIAL 0
108
62
#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
119
63
120
64
#define MDM_CMD_TIMEOUT (5 * MSEC_PER_SEC)
121
65
#define MDM_CMD_SEND_TIMEOUT (10 * MSEC_PER_SEC)
@@ -178,13 +122,14 @@ struct wncm14a2a_socket {
178
122
void * recv_user_data ;
179
123
};
180
124
125
+ struct wncm14a2a_config {
126
+ struct gpio_dt_spec gpio [MAX_MDM_CONTROL_PINS ];
127
+ };
128
+
181
129
struct wncm14a2a_iface_ctx {
182
130
struct net_if * iface ;
183
131
uint8_t mac_addr [6 ];
184
132
185
- /* GPIO PORT devices */
186
- const struct device * gpio_port_dev [MAX_MDM_CONTROL_PINS ];
187
-
188
133
/* RX specific attributes */
189
134
struct mdm_receiver_context mdm_ctx ;
190
135
@@ -217,6 +162,19 @@ struct cmd_handler {
217
162
void (* func )(struct net_buf * * buf , uint16_t len );
218
163
};
219
164
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
+
220
178
static struct wncm14a2a_iface_ctx ictx ;
221
179
222
180
static void wncm14a2a_read_rx (struct net_buf * * buf );
@@ -1231,12 +1189,10 @@ static int modem_pin_init(void)
1231
1189
* (doesn't go through the signal level translator)
1232
1190
*/
1233
1191
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 );
1236
1193
k_sleep (K_SECONDS (7 ));
1237
1194
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 );
1240
1196
1241
1197
/* disable signal level translator (necessary
1242
1198
* for the modem to boot properly). All signals
@@ -1246,32 +1202,22 @@ static int modem_pin_init(void)
1246
1202
* be in the correct state.
1247
1203
*/
1248
1204
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 );
1252
1206
1253
1207
/* While the level translator is disabled and output pins
1254
1208
* are tristated, make sure the inputs are in the same state
1255
1209
* as the WNC Module pins so that when the level translator is
1256
1210
* enabled, there are no differences.
1257
1211
*/
1258
1212
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 );
1262
1214
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 );
1266
1216
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 );
1270
1218
#if DT_INST_NODE_HAS_PROP (0 , mdm_send_ok_gpios )
1271
1219
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 );
1275
1221
#endif
1276
1222
1277
1223
/* wait for the WNC Module to perform its initial boot correctly */
@@ -1283,9 +1229,7 @@ static int modem_pin_init(void)
1283
1229
* When enabled, there will be no changes in the above 4 pins...
1284
1230
*/
1285
1231
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 );
1289
1233
1290
1234
LOG_INF ("... Done!" );
1291
1235
@@ -1300,14 +1244,10 @@ static void modem_wakeup_pin_fix(void)
1300
1244
LOG_DBG ("Toggling MDM_KEEP_AWAKE_PIN to avoid missed characters" );
1301
1245
k_sleep (K_MSEC (20 ));
1302
1246
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 );
1306
1248
k_sleep (K_SECONDS (2 ));
1307
1249
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 );
1311
1251
k_sleep (K_MSEC (20 ));
1312
1252
}
1313
1253
@@ -1444,10 +1384,6 @@ static int wncm14a2a_init(const struct device *dev)
1444
1384
1445
1385
ARG_UNUSED (dev );
1446
1386
1447
- /* check for valid pinconfig */
1448
- __ASSERT (ARRAY_SIZE (pinconfig ) == MAX_MDM_CONTROL_PINS ,
1449
- "Incorrect modem pinconfig!" );
1450
-
1451
1387
(void )memset (& ictx , 0 , sizeof (ictx ));
1452
1388
for (i = 0 ; i < MDM_MAX_SOCKETS ; i ++ ) {
1453
1389
k_work_init (& ictx .sockets [i ].recv_cb_work ,
@@ -1465,16 +1401,13 @@ static int wncm14a2a_init(const struct device *dev)
1465
1401
1466
1402
/* setup port devices and pin directions */
1467
1403
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 );
1473
1407
return - ENODEV ;
1474
1408
}
1475
1409
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 );
1478
1411
}
1479
1412
1480
1413
/* Set modem data storage */
@@ -1845,7 +1778,7 @@ static struct net_if_api api_funcs = {
1845
1778
};
1846
1779
1847
1780
NET_DEVICE_DT_INST_OFFLOAD_DEFINE (0 , wncm14a2a_init , NULL ,
1848
- & ictx , NULL ,
1781
+ & ictx , & wncm14a2a_cfg ,
1849
1782
CONFIG_MODEM_WNCM14A2A_INIT_PRIORITY ,
1850
1783
& api_funcs ,
1851
1784
MDM_MAX_DATA_LENGTH );
0 commit comments