Lines Matching +full:static +full:- +full:address
4 * SPDX-License-Identifier: Apache-2.0
24 static int lan865x_mac_rxtx_control(const struct device *dev, bool en) in lan865x_mac_rxtx_control()
26 struct lan865x_data *ctx = dev->data; in lan865x_mac_rxtx_control()
33 return oa_tc6_reg_write(ctx->tc6, LAN865x_MAC_NCR, ctl); in lan865x_mac_rxtx_control()
36 static void lan865x_iface_init(struct net_if *iface) in lan865x_iface_init()
39 struct lan865x_data *ctx = dev->data; in lan865x_iface_init()
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()
54 static enum ethernet_hw_caps lan865x_port_get_capabilities(const struct device *dev) in lan865x_port_get_capabilities()
60 static int lan865x_gpio_reset(const struct device *dev);
61 static void lan865x_write_macaddress(const struct device *dev);
62 static int lan865x_set_config(const struct device *dev, enum ethernet_config_type type, in lan865x_set_config()
65 const struct lan865x_config *cfg = dev->config; in lan865x_set_config()
66 struct lan865x_data *ctx = dev->data; in lan865x_set_config()
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()
107 static int lan865x_wait_for_reset(const struct device *dev) in lan865x_wait_for_reset()
109 struct lan865x_data *ctx = dev->data; in lan865x_wait_for_reset()
113 for (i = 0; !ctx->reset && i < LAN865X_RESET_TIMEOUT; i++) { in lan865x_wait_for_reset()
119 return -ENODEV; in lan865x_wait_for_reset()
125 static int lan865x_gpio_reset(const struct device *dev) in lan865x_gpio_reset()
127 const struct lan865x_config *cfg = dev->config; in lan865x_gpio_reset()
128 struct lan865x_data *ctx = dev->data; in lan865x_gpio_reset()
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()
143 static int lan865x_check_spi(const struct device *dev) in lan865x_check_spi()
145 struct lan865x_data *ctx = dev->data; in lan865x_check_spi()
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()
168 static uint8_t lan865x_read_indirect_reg(const struct device *dev, uint8_t addr, in lan865x_read_indirect_reg()
171 struct lan865x_data *ctx = dev->data; in lan865x_read_indirect_reg()
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()
186 static oa_mem_map_t lan865x_conf[] = {
187 { .mms = 0x1, .address = 0x00, .value = 0x0000 },
188 { .mms = 0x4, .address = 0xD0, .value = 0x3F31 },
189 { .mms = 0x4, .address = 0xE0, .value = 0xC000 },
190 { .mms = 0x4, .address = 0x84, .value = 0x0000 }, /* cfgparam1 */
191 { .mms = 0x4, .address = 0x8A, .value = 0x0000 }, /* cfgparam2 */
192 { .mms = 0x4, .address = 0xE9, .value = 0x9E50 },
193 { .mms = 0x4, .address = 0xF5, .value = 0x1CF8 },
194 { .mms = 0x4, .address = 0xF4, .value = 0xC020 },
195 { .mms = 0x4, .address = 0xF8, .value = 0xB900 },
196 { .mms = 0x4, .address = 0xF9, .value = 0x4E53 },
197 { .mms = 0x4, .address = 0x91, .value = 0x9660 },
198 { .mms = 0x4, .address = 0x77, .value = 0x0028 },
199 { .mms = 0x4, .address = 0x43, .value = 0x00FF },
200 { .mms = 0x4, .address = 0x44, .value = 0xFFFF },
201 { .mms = 0x4, .address = 0x45, .value = 0x0000 },
202 { .mms = 0x4, .address = 0x53, .value = 0x00FF },
203 { .mms = 0x4, .address = 0x54, .value = 0xFFFF },
204 { .mms = 0x4, .address = 0x55, .value = 0x0000 },
205 { .mms = 0x4, .address = 0x40, .value = 0x0002 },
206 { .mms = 0x4, .address = 0x50, .value = 0x0002 },
207 { .mms = 0x4, .address = 0xAD, .value = 0x0000 }, /* cfgparam3 */
208 { .mms = 0x4, .address = 0xAE, .value = 0x0000 }, /* cfgparam4 */
209 { .mms = 0x4, .address = 0xAF, .value = 0x0000 }, /* cfgparam5 */
210 { .mms = 0x4, .address = 0xB0, .value = 0x0103 },
211 { .mms = 0x4, .address = 0xB1, .value = 0x0910 },
212 { .mms = 0x4, .address = 0xB2, .value = 0x1D26 },
213 { .mms = 0x4, .address = 0xB3, .value = 0x002A },
214 { .mms = 0x4, .address = 0xB4, .value = 0x0103 },
215 { .mms = 0x4, .address = 0xB5, .value = 0x070D },
216 { .mms = 0x4, .address = 0xB6, .value = 0x1720 },
217 { .mms = 0x4, .address = 0xB7, .value = 0x0027 },
218 { .mms = 0x4, .address = 0xB8, .value = 0x0509 },
219 { .mms = 0x4, .address = 0xB9, .value = 0x0E13 },
220 { .mms = 0x4, .address = 0xBA, .value = 0x1C25 },
221 { .mms = 0x4, .address = 0xBB, .value = 0x002B },
222 { .mms = 0x4, .address = 0x0C, .value = 0x0100 },
223 { .mms = 0x4, .address = 0x81, .value = 0x00E0 },
227 static int lan865x_init_chip(const struct device *dev, uint8_t silicon_rev) in lan865x_init_chip()
231 struct lan865x_data *ctx = dev->data; in lan865x_init_chip()
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()
282 lan865x_conf[i].address), in lan865x_init_chip()
288 /* Implementation of pseudo code from AN1760 - END */
290 static int lan865x_config_plca(const struct device *dev, uint8_t node_id, in lan865x_config_plca()
293 struct lan865x_data *ctx = dev->data; in lan865x_config_plca()
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()
317 static void lan865x_write_macaddress(const struct device *dev) in lan865x_write_macaddress()
319 struct lan865x_data *ctx = dev->data; in lan865x_write_macaddress()
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()
339 static int lan865x_set_specific_multicast_addr(const struct device *dev) in lan865x_set_specific_multicast_addr()
341 struct lan865x_data *ctx = dev->data; in lan865x_set_specific_multicast_addr()
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()
361 static int lan865x_default_config(const struct device *dev, uint8_t silicon_rev) in lan865x_default_config()
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()
386 static void lan865x_int_callback(const struct device *dev, in lan865x_int_callback()
396 k_sem_give(&ctx->int_sem); in lan865x_int_callback()
399 static void lan865x_read_chunks(const struct device *dev) in lan865x_read_chunks()
401 const struct lan865x_config *cfg = dev->config; in lan865x_read_chunks()
402 struct lan865x_data *ctx = dev->data; in lan865x_read_chunks()
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()
431 static void lan865x_int_thread(const struct device *dev) in lan865x_int_thread()
433 struct lan865x_data *ctx = dev->data; in lan865x_int_thread()
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()
478 static int lan865x_init(const struct device *dev) in lan865x_init()
480 const struct lan865x_config *cfg = dev->config; in lan865x_init()
481 struct lan865x_data *ctx = dev->data; in lan865x_init()
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()
551 static int lan865x_port_send(const struct device *dev, struct net_pkt *pkt) in lan865x_port_send()
553 struct lan865x_data *ctx = dev->data; in lan865x_port_send()
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()
575 static const struct ethernet_api lan865x_api_func = {
583 static struct lan865x_config_plca lan865x_config_plca_##inst = { \
592 static const struct lan865x_config lan865x_config_##inst = { \
605 static struct lan865x_data lan865x_data_##inst = { \