Lines Matching +full:spi +full:- +full:addr
1 /* ENC424J600 Stand-alone Ethernet Controller with SPI
7 * SPDX-License-Identifier: Apache-2.0
17 #include <zephyr/drivers/spi.h>
29 const struct enc424j600_config *config = dev->config; in enc424j600_write_sbc()
40 spi_write_dt(&config->spi, &tx); in enc424j600_write_sbc()
43 static void enc424j600_write_sfru(const struct device *dev, uint8_t addr, in enc424j600_write_sfru() argument
46 const struct enc424j600_config *config = dev->config; in enc424j600_write_sfru()
58 buf[1] = addr; in enc424j600_write_sfru()
62 spi_write_dt(&config->spi, &tx); in enc424j600_write_sfru()
65 static void enc424j600_read_sfru(const struct device *dev, uint8_t addr, in enc424j600_read_sfru() argument
68 const struct enc424j600_config *config = dev->config; in enc424j600_read_sfru()
88 buf[1] = addr; in enc424j600_read_sfru()
90 if (!spi_transceive_dt(&config->spi, &tx, &rx)) { in enc424j600_read_sfru()
93 LOG_DBG("Failure while reading register 0x%02x", addr); in enc424j600_read_sfru()
99 uint16_t addr, uint16_t value) in enc424j600_modify_sfru() argument
101 const struct enc424j600_config *config = dev->config; in enc424j600_modify_sfru()
113 buf[1] = addr; in enc424j600_modify_sfru()
117 spi_write_dt(&config->spi, &tx); in enc424j600_modify_sfru()
120 #define enc424j600_set_sfru(dev, addr, value) \ argument
121 enc424j600_modify_sfru(dev, ENC424J600_NBC_BFSU, addr, value)
123 #define enc424j600_clear_sfru(dev, addr, value) \ argument
124 enc424j600_modify_sfru(dev, ENC424J600_NBC_BFCU, addr, value)
127 static void enc424j600_write_phy(const struct device *dev, uint16_t addr, in enc424j600_write_phy() argument
132 enc424j600_write_sfru(dev, ENC424J600_SFR2_MIREGADRL, addr); in enc424j600_write_phy()
141 static void enc424j600_read_phy(const struct device *dev, uint16_t addr, in enc424j600_read_phy() argument
146 enc424j600_write_sfru(dev, ENC424J600_SFR2_MIREGADRL, addr); in enc424j600_read_phy()
162 const struct enc424j600_config *config = dev->config; in enc424j600_write_mem()
179 if (spi_write_dt(&config->spi, &tx)) { in enc424j600_write_mem()
188 const struct enc424j600_config *config = dev->config; in enc424j600_read_mem()
213 if (spi_transceive_dt(&config->spi, &tx, &rx)) { in enc424j600_read_mem()
226 k_sem_give(&context->int_sem); in enc424j600_gpio_callback()
310 struct enc424j600_runtime *context = dev->data; in enc424j600_tx()
317 k_sem_take(&context->tx_rx_sem, K_FOREVER); in enc424j600_tx()
322 for (frag = pkt->frags; frag; frag = frag->frags) { in enc424j600_tx()
323 enc424j600_write_mem(dev, ENC424J600_NBC_WGPDATA, frag->data, in enc424j600_tx()
324 frag->len); in enc424j600_tx()
342 k_sem_give(&context->tx_rx_sem); in enc424j600_tx()
349 struct enc424j600_runtime *context = dev->data; in enc424j600_rx()
350 const struct enc424j600_config *config = dev->config; in enc424j600_rx()
358 k_sem_take(&context->tx_rx_sem, K_FOREVER); in enc424j600_rx()
361 context->next_pkt_ptr); in enc424j600_rx()
375 context->next_pkt_ptr = sys_get_le16(&info[0]); in enc424j600_rx()
379 context->next_pkt_ptr, frm_len, status); in enc424j600_rx()
381 frm_len -= 4; in enc424j600_rx()
384 eth_stats_update_errors_rx(context->iface); in enc424j600_rx()
389 pkt = net_pkt_rx_alloc_with_buffer(context->iface, frm_len, in enc424j600_rx()
391 K_MSEC(config->timeout)); in enc424j600_rx()
394 eth_stats_update_errors_rx(context->iface); in enc424j600_rx()
398 pkt_buf = pkt->buffer; in enc424j600_rx()
405 data_ptr = pkt_buf->data; in enc424j600_rx()
421 /* One fragment has been written via SPI */ in enc424j600_rx()
422 frm_len -= spi_frame_len; in enc424j600_rx()
423 pkt_buf = pkt_buf->frags; in enc424j600_rx()
426 if (net_recv_data(context->iface, pkt) < 0) { in enc424j600_rx()
431 if (context->next_pkt_ptr == ENC424J600_RXSTART) { in enc424j600_rx()
432 tmp = ENC424J600_RXEND - 1; in enc424j600_rx()
435 tmp = context->next_pkt_ptr - 2; in enc424j600_rx()
440 k_sem_give(&context->tx_rx_sem); in enc424j600_rx()
456 k_sem_take(&context->int_sem, K_FOREVER); in enc424j600_rx_thread()
458 enc424j600_write_sbc(context->dev, ENC424J600_1BC_CLREIE); in enc424j600_rx_thread()
459 enc424j600_read_sfru(context->dev, ENC424J600_SFRX_EIRL, &eir); in enc424j600_rx_thread()
460 enc424j600_read_sfru(context->dev, in enc424j600_rx_thread()
467 enc424j600_rx(context->dev); in enc424j600_rx_thread()
468 enc424j600_read_sfru(context->dev, in enc424j600_rx_thread()
475 enc424j600_clear_sfru(context->dev, in enc424j600_rx_thread()
480 enc424j600_setup_mac(context->dev); in enc424j600_rx_thread()
481 net_eth_carrier_on(context->iface); in enc424j600_rx_thread()
485 if (context->iface_initialized) { in enc424j600_rx_thread()
486 net_eth_carrier_off(context->iface); in enc424j600_rx_thread()
500 enc424j600_write_sbc(context->dev, ENC424J600_1BC_SETEIE); in enc424j600_rx_thread()
510 struct enc424j600_runtime *context = dev->data; in enc424j600_get_config()
515 return -ENOTSUP; in enc424j600_get_config()
518 k_sem_take(&context->tx_rx_sem, K_FOREVER); in enc424j600_get_config()
526 config->l.link_100bt = true; in enc424j600_get_config()
529 config->l.link_10bt = true; in enc424j600_get_config()
532 rc = -EINVAL; in enc424j600_get_config()
539 config->full_duplex = false; in enc424j600_get_config()
543 config->full_duplex = true; in enc424j600_get_config()
547 k_sem_give(&context->tx_rx_sem); in enc424j600_get_config()
563 struct enc424j600_runtime *ctx = dev->data; in enc424j600_set_config()
568 ctx->mac_address[0] = config->mac_address.addr[0]; in enc424j600_set_config()
569 ctx->mac_address[1] = config->mac_address.addr[1]; in enc424j600_set_config()
570 ctx->mac_address[2] = config->mac_address.addr[2]; in enc424j600_set_config()
571 ctx->mac_address[3] = config->mac_address.addr[3]; in enc424j600_set_config()
572 ctx->mac_address[4] = config->mac_address.addr[4]; in enc424j600_set_config()
573 ctx->mac_address[5] = config->mac_address.addr[5]; in enc424j600_set_config()
576 tmp = config->mac_address.addr[0] | config->mac_address.addr[1] << 8; in enc424j600_set_config()
580 tmp = config->mac_address.addr[2] | config->mac_address.addr[3] << 8; in enc424j600_set_config()
584 tmp = config->mac_address.addr[4] | config->mac_address.addr[5] << 8; in enc424j600_set_config()
589 return -ENOTSUP; in enc424j600_set_config()
596 struct enc424j600_runtime *context = dev->data; in enc424j600_iface_init()
598 net_if_set_link_addr(iface, context->mac_address, in enc424j600_iface_init()
599 sizeof(context->mac_address), in enc424j600_iface_init()
601 context->iface = iface; in enc424j600_iface_init()
605 context->iface_initialized = true; in enc424j600_iface_init()
610 struct enc424j600_runtime *context = dev->data; in enc424j600_start_device()
613 if (!context->suspended) { in enc424j600_start_device()
618 k_sem_take(&context->tx_rx_sem, K_FOREVER); in enc424j600_start_device()
631 context->suspended = false; in enc424j600_start_device()
632 k_sem_give(&context->tx_rx_sem); in enc424j600_start_device()
640 struct enc424j600_runtime *context = dev->data; in enc424j600_stop_device()
643 if (context->suspended) { in enc424j600_stop_device()
648 k_sem_take(&context->tx_rx_sem, K_FOREVER); in enc424j600_stop_device()
671 context->suspended = true; in enc424j600_stop_device()
672 k_sem_give(&context->tx_rx_sem); in enc424j600_stop_device()
690 const struct enc424j600_config *config = dev->config; in enc424j600_init()
691 struct enc424j600_runtime *context = dev->data; in enc424j600_init()
695 context->dev = dev; in enc424j600_init()
697 /* SPI config */ in enc424j600_init()
698 if (!spi_is_ready_dt(&config->spi)) { in enc424j600_init()
699 LOG_ERR("SPI master port %s not ready", config->spi.bus->name); in enc424j600_init()
700 return -EINVAL; in enc424j600_init()
704 if (!gpio_is_ready_dt(&config->interrupt)) { in enc424j600_init()
705 LOG_ERR("GPIO port %s not ready", config->interrupt.port->name); in enc424j600_init()
706 return -EINVAL; in enc424j600_init()
709 if (gpio_pin_configure_dt(&config->interrupt, GPIO_INPUT)) { in enc424j600_init()
711 config->interrupt.pin); in enc424j600_init()
712 return -EINVAL; in enc424j600_init()
715 gpio_init_callback(&(context->gpio_cb), enc424j600_gpio_callback, in enc424j600_init()
716 BIT(config->interrupt.pin)); in enc424j600_init()
718 if (gpio_add_callback(config->interrupt.port, &(context->gpio_cb))) { in enc424j600_init()
719 return -EINVAL; in enc424j600_init()
722 gpio_pin_interrupt_configure_dt(&config->interrupt, in enc424j600_init()
725 /* Check SPI connection */ in enc424j600_init()
730 retries--; in enc424j600_init()
734 LOG_ERR("Timeout, failed to establish SPI connection"); in enc424j600_init()
735 return -EIO; in enc424j600_init()
742 retries--; in enc424j600_init()
747 return -EIO; in enc424j600_init()
756 return -EIO; in enc424j600_init()
774 (ENC424J600_RXEND - 1)); in enc424j600_init()
775 context->next_pkt_ptr = ENC424J600_RXSTART; in enc424j600_init()
777 /* Disable user-defined buffer */ in enc424j600_init()
779 (ENC424J600_RXEND - 1)); in enc424j600_init()
781 (ENC424J600_RXEND - 1)); in enc424j600_init()
785 context->mac_address[0] = tmp; in enc424j600_init()
786 context->mac_address[1] = tmp >> 8; in enc424j600_init()
789 context->mac_address[2] = tmp; in enc424j600_init()
790 context->mac_address[3] = tmp >> 8; in enc424j600_init()
793 context->mac_address[4] = tmp; in enc424j600_init()
794 context->mac_address[5] = tmp >> 8; in enc424j600_init()
806 /* Start interruption-poll thread */ in enc424j600_init()
807 k_thread_create(&context->thread, context->thread_stack, in enc424j600_init()
816 context->suspended = false; in enc424j600_init()
830 .spi = SPI_DT_SPEC_INST_GET(0, SPI_WORD_SET(8), 0),