@@ -126,22 +126,31 @@ static void spi_read_burst(uint8_t *buf, uint16_t len)
126
126
127
127
static void spi_cris_enter (void )
128
128
{
129
-
129
+ struct w5500_runtime * context = wiz_dev -> driver_data ;
130
+ const struct w5500_config * config = wiz_dev -> config_info ;
131
+
132
+ z_impl_gpio_disable_callback (context -> gpio ,config -> gpio_pin );
130
133
}
131
134
132
135
static void spi_cris_exit (void )
133
136
{
134
-
137
+ struct w5500_runtime * context = wiz_dev -> driver_data ;
138
+ const struct w5500_config * config = wiz_dev -> config_info ;
139
+
140
+ z_impl_gpio_enable_callback (context -> gpio ,config -> gpio_pin );
135
141
}
136
142
137
143
static void spi_cs_select (void )
138
144
{
139
-
145
+ struct w5500_runtime * context = wiz_dev -> driver_data ;
146
+ gpio_pin_set (context -> spi_cs .gpio_dev ,context -> spi_cs .gpio_pin ,0 );
140
147
}
141
148
142
149
static void spi_cs_deselect (void )
143
150
{
144
-
151
+ struct w5500_runtime * context = wiz_dev -> driver_data ;
152
+
153
+ gpio_pin_set (context -> spi_cs .gpio_dev ,context -> spi_cs .gpio_pin ,0 );
145
154
}
146
155
147
156
/* register TCP communication related callback function */
@@ -174,7 +183,7 @@ static void w5500_gpio_callback(struct device *dev,
174
183
struct w5500_runtime * context =
175
184
CONTAINER_OF (cb , struct w5500_runtime , gpio_cb );
176
185
177
- k_sem_give (& context -> int_sem );
186
+ k_sem_give (& context -> int_sem );
178
187
}
179
188
180
189
static int w5500_tx (struct device * dev , struct net_pkt * pkt )
@@ -277,6 +286,20 @@ static enum ethernet_hw_caps w5500_get_capabilities(struct device *dev)
277
286
return ETHERNET_LINK_10BASE_T | ETHERNET_LINK_100BASE_T ;
278
287
}
279
288
289
+ static void w5500_init_phy (struct device * dev )
290
+ {
291
+ const struct w5500_config * config = dev -> config_info ;
292
+
293
+ uint8_t tmp = 0 ;
294
+
295
+ if (config -> full_duplex ) {
296
+ tmp |= PHYCFGR_OPMDC_100F ;
297
+ } else {
298
+ tmp |= PHYCFGR_OPMDC_100H ;
299
+ }
300
+ setPHYCFGR (tmp );
301
+ }
302
+
280
303
static void w5500_iface_init (struct net_if * iface )
281
304
{
282
305
struct device * dev = net_if_get_device (iface );
@@ -301,6 +324,8 @@ static const struct ethernet_api api_funcs = {
301
324
302
325
static int w5500_init (struct device * dev )
303
326
{
327
+ wiz_dev = dev ;
328
+
304
329
const struct w5500_config * config = dev -> config_info ;
305
330
struct w5500_runtime * context = dev -> driver_data ;
306
331
@@ -326,6 +351,36 @@ static int w5500_init(struct device *dev)
326
351
context -> spi_cs .gpio_pin = config -> spi_cs_pin ;
327
352
context -> spi_cfg .cs = & context -> spi_cs ;
328
353
#endif
354
+
355
+ /* Initialize GPIO */
356
+ context -> gpio = device_get_binding ((char * )config -> gpio_port );
357
+ if (!context -> gpio ) {
358
+ LOG_ERR ("GPIO port %s not found" , config -> gpio_port );
359
+ return - EINVAL ;
360
+ }
361
+
362
+ if (gpio_pin_configure (context -> gpio , config -> gpio_pin ,
363
+ GPIO_INPUT | config -> gpio_flags )) {
364
+ LOG_ERR ("Unable to configure GPIO pin %u" , config -> gpio_pin );
365
+ return - EINVAL ;
366
+ }
367
+
368
+ gpio_init_callback (& (context -> gpio_cb ), w5500_gpio_callback ,
369
+ BIT (config -> gpio_pin ));
370
+
371
+ if (gpio_add_callback (context -> gpio , & (context -> gpio_cb ))) {
372
+ return - EINVAL ;
373
+ }
374
+
375
+ gpio_pin_interrupt_configure (context -> gpio ,
376
+ config -> gpio_pin ,
377
+ GPIO_INT_EDGE_TO_ACTIVE );
378
+
379
+ wiz_callback_register ();
380
+ /* read MAC address */
381
+ getPHAR (context -> mac_address );
382
+ w5500_init_phy (dev );
383
+
329
384
/* Start interruption-poll thread */
330
385
k_thread_create (& context -> thread , context -> thread_stack ,
331
386
CONFIG_ETH_W5500_RX_THREAD_STACK_SIZE ,
@@ -347,6 +402,9 @@ static struct w5500_runtime w5500_0_runtime = {
347
402
};
348
403
349
404
static const struct w5500_config w5500_0_config = {
405
+ .gpio_port = DT_INST_GPIO_LABEL (0 , int_gpios ),
406
+ .gpio_pin = DT_INST_GPIO_PIN (0 , int_gpios ),
407
+ .gpio_flags = DT_INST_GPIO_FLAGS (0 , int_gpios ),
350
408
.spi_port = DT_INST_BUS_LABEL (0 ),
351
409
.spi_freq = DT_INST_PROP (0 , spi_max_frequency ),
352
410
.spi_slave = DT_INST_REG_ADDR (0 ),
0 commit comments