Lines Matching +full:ctx +full:- +full:gpios
4 * SPDX-License-Identifier: Apache-2.0
26 struct lan865x_data *ctx = dev->data; in lan865x_mac_rxtx_control() local
33 return oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_NCR, ctl); in lan865x_mac_rxtx_control()
39 struct lan865x_data *ctx = dev->data; in lan865x_iface_init() local
41 net_if_set_link_addr(iface, ctx->mac_address, sizeof(ctx->mac_address), in lan865x_iface_init()
44 if (ctx->iface == NULL) { in lan865x_iface_init()
45 ctx->iface = iface; in lan865x_iface_init()
51 ctx->iface_initialized = true; in lan865x_iface_init()
65 const struct lan865x_config *cfg = dev->config; in lan865x_set_config()
66 struct lan865x_data *ctx = dev->data; in lan865x_set_config() local
67 int ret = -ENOTSUP; in lan865x_set_config()
70 return oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_NCFGR, in lan865x_set_config()
75 memcpy(ctx->mac_address, config->mac_address.addr, in lan865x_set_config()
76 sizeof(ctx->mac_address)); in lan865x_set_config()
80 return net_if_set_link_addr(ctx->iface, ctx->mac_address, in lan865x_set_config()
81 sizeof(ctx->mac_address), in lan865x_set_config()
91 if (config->t1s_param.type == ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG) { in lan865x_set_config()
92 cfg->plca->enable = config->t1s_param.plca.enable; in lan865x_set_config()
93 cfg->plca->node_id = config->t1s_param.plca.node_id; in lan865x_set_config()
94 cfg->plca->node_count = config->t1s_param.plca.node_count; in lan865x_set_config()
95 cfg->plca->burst_count = config->t1s_param.plca.burst_count; in lan865x_set_config()
96 cfg->plca->burst_timer = config->t1s_param.plca.burst_timer; in lan865x_set_config()
97 cfg->plca->to_timer = config->t1s_param.plca.to_timer; in lan865x_set_config()
100 /* Reset is required to re-program PLCA new configuration */ in lan865x_set_config()
109 struct lan865x_data *ctx = dev->data; in lan865x_wait_for_reset() local
113 for (i = 0; !ctx->reset && i < LAN865X_RESET_TIMEOUT; i++) { in lan865x_wait_for_reset()
119 return -ENODEV; in lan865x_wait_for_reset()
127 const struct lan865x_config *cfg = dev->config; in lan865x_gpio_reset()
128 struct lan865x_data *ctx = dev->data; in lan865x_gpio_reset() local
130 ctx->reset = false; in lan865x_gpio_reset()
131 ctx->tc6->protected = false; in lan865x_gpio_reset()
135 gpio_pin_set_dt(&cfg->reset, 1); in lan865x_gpio_reset()
137 /* deassert - end of reset indicated by IRQ_N low */ in lan865x_gpio_reset()
138 gpio_pin_set_dt(&cfg->reset, 0); in lan865x_gpio_reset()
145 struct lan865x_data *ctx = dev->data; in lan865x_check_spi() local
149 ret = oa_tc6_reg_read(ctx->tc6, LAN865x_DEVID, &val); in lan865x_check_spi()
151 return -ENODEV; in lan865x_check_spi()
154 ctx->silicon_rev = val & LAN865X_REV_MASK; in lan865x_check_spi()
155 if (ctx->silicon_rev != 1 && ctx->silicon_rev != 2) { in lan865x_check_spi()
156 return -ENODEV; in lan865x_check_spi()
159 ctx->chip_id = (val >> 4) & 0xFFFF; in lan865x_check_spi()
160 if (ctx->chip_id != LAN8650_DEVID && ctx->chip_id != LAN8651_DEVID) { in lan865x_check_spi()
161 return -ENODEV; in lan865x_check_spi()
171 struct lan865x_data *ctx = dev->data; in lan865x_read_indirect_reg() local
174 oa_tc6_reg_write(ctx->tc6, 0x000400D8, addr); in lan865x_read_indirect_reg()
175 oa_tc6_reg_write(ctx->tc6, 0x000400DA, 0x02); in lan865x_read_indirect_reg()
177 oa_tc6_reg_read(ctx->tc6, 0x000400D9, &val); in lan865x_read_indirect_reg()
231 struct lan865x_data *ctx = dev->data; in lan865x_init_chip() local
236 oa_tc6_set_protected_ctrl(ctx->tc6, true); in lan865x_init_chip()
240 offset1 = (int8_t)((uint8_t)value1 - 0x20); in lan865x_init_chip()
247 offset2 = (int8_t)((uint8_t)value2 - 0x20); in lan865x_init_chip()
281 oa_tc6_reg_write(ctx->tc6, MMS_REG(lan865x_conf[i].mms, in lan865x_init_chip()
288 /* Implementation of pseudo code from AN1760 - END */
293 struct lan865x_data *ctx = dev->data; in lan865x_config_plca() local
297 oa_tc6_reg_write(ctx->tc6, 0x00040087, 0x0083u); /* COL_DET_CTRL0 */ in lan865x_config_plca()
305 oa_tc6_reg_write(ctx->tc6, 0x0004CA02, val); /* PLCA_CONTROL_1_REGISTER */ in lan865x_config_plca()
309 oa_tc6_reg_write(ctx->tc6, 0x0004CA05, val); /* PLCA_BURST_MODE_REGISTER */ in lan865x_config_plca()
312 oa_tc6_reg_write(ctx->tc6, 0x0004CA01, BIT(15)); /* PLCA_CONTROL_0_REGISTER */ in lan865x_config_plca()
319 struct lan865x_data *ctx = dev->data; in lan865x_write_macaddress() local
320 uint8_t *mac = &ctx->mac_address[0]; in lan865x_write_macaddress()
325 oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_SAB2, val); in lan865x_write_macaddress()
329 oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_SAT2, val); in lan865x_write_macaddress()
332 * SPEC_ADD1_BOTTOM - setting unique lower MAC address, back off time is in lan865x_write_macaddress()
336 oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_SAB1, val); in lan865x_write_macaddress()
341 struct lan865x_data *ctx = dev->data; in lan865x_set_specific_multicast_addr() local
347 ret = oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_HRT, mac_h_hash); in lan865x_set_specific_multicast_addr()
352 ret = oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_HRB, mac_l_hash); in lan865x_set_specific_multicast_addr()
357 return oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_NCFGR, in lan865x_set_specific_multicast_addr()
363 const struct lan865x_config *cfg = dev->config; in lan865x_default_config()
374 if (cfg->plca->enable) { in lan865x_default_config()
375 ret = lan865x_config_plca(dev, cfg->plca->node_id, in lan865x_default_config()
376 cfg->plca->node_count, in lan865x_default_config()
377 cfg->plca->burst_count, in lan865x_default_config()
378 cfg->plca->burst_timer); in lan865x_default_config()
393 struct lan865x_data *ctx = in lan865x_int_callback() local
396 k_sem_give(&ctx->int_sem); in lan865x_int_callback()
401 const struct lan865x_config *cfg = dev->config; in lan865x_read_chunks()
402 struct lan865x_data *ctx = dev->data; in lan865x_read_chunks() local
403 struct oa_tc6 *tc6 = ctx->tc6; in lan865x_read_chunks()
407 pkt = net_pkt_rx_alloc(K_MSEC(cfg->timeout)); in lan865x_read_chunks()
413 k_sem_take(&ctx->tx_rx_sem, K_FOREVER); in lan865x_read_chunks()
416 eth_stats_update_errors_rx(ctx->iface); in lan865x_read_chunks()
418 k_sem_give(&ctx->tx_rx_sem); in lan865x_read_chunks()
423 ret = net_recv_data(ctx->iface, pkt); in lan865x_read_chunks()
428 k_sem_give(&ctx->tx_rx_sem); in lan865x_read_chunks()
433 struct lan865x_data *ctx = dev->data; in lan865x_int_thread() local
434 struct oa_tc6 *tc6 = ctx->tc6; in lan865x_int_thread()
439 k_sem_take(&ctx->int_sem, K_FOREVER); in lan865x_int_thread()
440 if (!ctx->reset) { in lan865x_int_thread()
444 lan865x_default_config(dev, ctx->silicon_rev); in lan865x_int_thread()
450 ctx->reset = true; in lan865x_int_thread()
452 * According to OA T1S standard - it is mandatory to in lan865x_int_thread()
462 * OPEN Alliance 10BASE-T1x standard it is deasserted when first in lan865x_int_thread()
469 } while (tc6->rca > 0); in lan865x_int_thread()
472 if (ret == -EIO) { in lan865x_int_thread()
480 const struct lan865x_config *cfg = dev->config; in lan865x_init()
481 struct lan865x_data *ctx = dev->data; in lan865x_init() local
484 __ASSERT(cfg->spi.config.frequency <= LAN865X_SPI_MAX_FREQUENCY, in lan865x_init()
487 if (!spi_is_ready_dt(&cfg->spi)) { in lan865x_init()
488 LOG_ERR("SPI bus %s not ready", cfg->spi.bus->name); in lan865x_init()
489 return -ENODEV; in lan865x_init()
492 if (!gpio_is_ready_dt(&cfg->interrupt)) { in lan865x_init()
494 cfg->interrupt.port->name); in lan865x_init()
495 return -ENODEV; in lan865x_init()
508 ret = gpio_pin_configure_dt(&cfg->interrupt, GPIO_INPUT); in lan865x_init()
514 gpio_init_callback(&(ctx->gpio_int_callback), lan865x_int_callback, in lan865x_init()
515 BIT(cfg->interrupt.pin)); in lan865x_init()
517 ret = gpio_add_callback(cfg->interrupt.port, &ctx->gpio_int_callback); in lan865x_init()
523 gpio_pin_interrupt_configure_dt(&cfg->interrupt, GPIO_INT_EDGE_TO_ACTIVE); in lan865x_init()
525 /* Start interruption-poll thread */ in lan865x_init()
526 ctx->tid_int = in lan865x_init()
527 k_thread_create(&ctx->thread, ctx->thread_stack, in lan865x_init()
533 k_thread_name_set(ctx->tid_int, "lan865x_interrupt"); in lan865x_init()
535 /* Perform HW reset - 'rst-gpios' required property set in DT */ in lan865x_init()
536 if (!gpio_is_ready_dt(&cfg->reset)) { in lan865x_init()
538 cfg->reset.port->name); in lan865x_init()
539 return -ENODEV; in lan865x_init()
542 ret = gpio_pin_configure_dt(&cfg->reset, GPIO_OUTPUT_INACTIVE); in lan865x_init()
553 struct lan865x_data *ctx = dev->data; in lan865x_port_send() local
554 struct oa_tc6 *tc6 = ctx->tc6; in lan865x_port_send()
557 k_sem_take(&ctx->tx_rx_sem, K_FOREVER); in lan865x_port_send()
560 /* Check if rca > 0 during half-duplex TX transmission */ in lan865x_port_send()
561 if (tc6->rca > 0) { in lan865x_port_send()
562 k_sem_give(&ctx->int_sem); in lan865x_port_send()
565 k_sem_give(&ctx->tx_rx_sem); in lan865x_port_send()