Lines Matching +full:remote +full:- +full:mac +full:- +full:address
1 /* LAN9250 Stand-alone Ethernet Controller with SPI
5 * SPDX-License-Identifier: Apache-2.0
24 static int lan9250_write_sys_reg(const struct device *dev, uint16_t address, uint32_t data) in lan9250_write_sys_reg() argument
26 const struct lan9250_config *config = dev->config; in lan9250_write_sys_reg()
33 sys_put_be16(address, addr); in lan9250_write_sys_reg()
43 return spi_write_dt(&config->spi, &tx); in lan9250_write_sys_reg()
46 static int lan9250_read_sys_reg(const struct device *dev, uint16_t address, uint32_t *value) in lan9250_read_sys_reg() argument
48 const struct lan9250_config *config = dev->config; in lan9250_read_sys_reg()
56 sys_put_be16(address, addr); in lan9250_read_sys_reg()
72 return spi_transceive_dt(&config->spi, &tx, &rx); in lan9250_read_sys_reg()
75 static int lan9250_wait_ready(const struct device *dev, uint16_t address, uint32_t mask, in lan9250_wait_ready() argument
82 lan9250_read_sys_reg(dev, address, &tmp); in lan9250_wait_ready()
89 return -EIO; in lan9250_wait_ready()
94 static int lan9250_read_mac_reg(const struct device *dev, uint8_t address, uint32_t *value) in lan9250_read_mac_reg() argument
98 /* Wait for MAC to be ready and send writing register command and data */ in lan9250_read_mac_reg()
102 address | LAN9250_MAC_CSR_CMD_BUSY | LAN9250_MAC_CSR_CMD_READ); in lan9250_read_mac_reg()
104 /* Wait for MAC to be ready and send writing register command and data */ in lan9250_read_mac_reg()
113 static int lan9250_write_mac_reg(const struct device *dev, uint8_t address, uint32_t data) in lan9250_write_mac_reg() argument
115 /* Wait for MAC to be ready and send writing register command and data */ in lan9250_write_mac_reg()
119 lan9250_write_sys_reg(dev, LAN9250_MAC_CSR_CMD, address | LAN9250_MAC_CSR_CMD_BUSY); in lan9250_write_mac_reg()
121 /* Wait until writing MAC is done */ in lan9250_write_mac_reg()
128 static int lan9250_wait_mac_ready(const struct device *dev, uint8_t address, uint32_t mask, in lan9250_wait_mac_ready() argument
135 lan9250_read_mac_reg(dev, address, &tmp); in lan9250_wait_mac_ready()
141 return -EIO; in lan9250_wait_mac_ready()
146 static int lan9250_read_phy_reg(const struct device *dev, uint8_t address, uint16_t *value) in lan9250_read_phy_reg() argument
155 * https://github.com/microchip-pic-avr-solutions/ethernet-lan9250/ in lan9250_read_phy_reg()
161 * The PHY registers are indirectly accessed through the Host MAC MII Access Register in lan9250_read_phy_reg()
162 * (HMAC_MII_ACC) and Host MAC MII Data Register (HMAC_MII_DATA). in lan9250_read_phy_reg()
164 * Write 32bit value to the indirect MAC registers in lan9250_read_phy_reg()
165 * Where phy_add = 0b00001 & index = address in lan9250_read_phy_reg()
168 lan9250_write_mac_reg(dev, LAN9250_HMAC_MII_ACC, (1 << 11) | ((address & 0x1F) << 6)); in lan9250_read_phy_reg()
174 /* Read 32bit value from the indirect MAC registers */ in lan9250_read_phy_reg()
181 static int lan9250_write_phy_reg(const struct device *dev, uint8_t address, uint16_t data) in lan9250_write_phy_reg() argument
189 * https://github.com/microchip-pic-avr-solutions/ethernet-lan9250/ in lan9250_write_phy_reg()
195 * The PHY registers are indirectly accessed through the Host MAC MII Access Register in lan9250_write_phy_reg()
196 * (HMAC_MII_ACC) and Host MAC MII Data Register (HMAC_MII_DATA). in lan9250_write_phy_reg()
198 * Write 32bit value to the indirect MAC registers in lan9250_write_phy_reg()
199 * Where phy_add = 0b00001 & index = address in lan9250_write_phy_reg()
203 (1 << 11) | ((address & 0x1F) << 6) | LAN9250_HMAC_MII_ACC_MIIW_R); in lan9250_write_phy_reg()
214 struct lan9250_runtime *ctx = dev->data; in lan9250_set_macaddr()
217 ctx->mac_address[0] | (ctx->mac_address[1] << 8) | in lan9250_set_macaddr()
218 (ctx->mac_address[2] << 16) | (ctx->mac_address[3] << 24)); in lan9250_set_macaddr()
220 ctx->mac_address[4] | (ctx->mac_address[5] << 8)); in lan9250_set_macaddr()
260 return -ENODEV; in lan9250_configure()
265 * - TX data FIFO size: 7680 in lan9250_configure()
266 * - RX data FIFO size: 7680 in lan9250_configure()
267 * - TX status FIFO size: 512 in lan9250_configure()
268 * - RX status FIFO size: 512 in lan9250_configure()
273 /* Configure MAC automatic flow control: in lan9250_configure()
276 * https://github.com/microchip-pic-avr-solutions/ethernet-lan9250/ in lan9250_configure()
284 * - Interrupt De-assertion interval: 100 in lan9250_configure()
285 * - Interrupt output to pin in lan9250_configure()
286 * - Interrupt pin active output low in lan9250_configure()
287 * - Interrupt pin push-pull driver in lan9250_configure()
306 * - RX DMA counter: Ethernet maximum packet size in lan9250_configure()
307 * - RX data offset: 4, so that need read dummy before reading data in lan9250_configure()
311 /* Configure remote power management: in lan9250_configure()
313 * - Auto wakeup in lan9250_configure()
314 * - Disable 1588 clock in lan9250_configure()
315 * - Disable 1588 timestamp unit clock in lan9250_configure()
316 * - Energy-detect in lan9250_configure()
317 * - Wake on in lan9250_configure()
318 * - Clear wakeon in lan9250_configure()
327 * - Auto-Negotiation for 10/100 Mbits and Half/Full Duplex in lan9250_configure()
334 /* Configure PHY auto-negotiation advertisement capability: in lan9250_configure()
336 * - Asymmetric pause in lan9250_configure()
337 * - Symmetric pause in lan9250_configure()
338 * - 100Base-X half/full duplex in lan9250_configure()
339 * - 10Base-X half/full duplex in lan9250_configure()
340 * - Select IEEE802.3 in lan9250_configure()
350 * - PHY mode = 111b, enable all capable and auto-nagotiation in lan9250_configure()
351 * - PHY address = 1, default value is fixed to 1 by manufacturer in lan9250_configure()
357 * - Port auto-MDIX determined by bits 14 and 13 in lan9250_configure()
358 * - Auto-MDIX in lan9250_configure()
359 * - Disable SQE tests in lan9250_configure()
368 * - Link up in lan9250_configure()
369 * - Link down in lan9250_configure()
377 * - Fixed to write 0000010b to reserved filed in lan9250_configure()
387 * - Automatically strip the pad field on incoming packets in lan9250_configure()
388 * - TX enable in lan9250_configure()
389 * - RX enable in lan9250_configure()
390 * - Full duplex in lan9250_configure()
391 * - Promiscuous disabled in lan9250_configure()
399 * - TX enable in lan9250_configure()
408 const struct lan9250_config *config = dev->config; in lan9250_write_buf()
421 return spi_transceive_dt(&config->spi, &tx, NULL); in lan9250_write_buf()
426 const struct lan9250_config *config = dev->config; in lan9250_read_buf()
448 return spi_transceive_dt(&config->spi, &tx, &rx); in lan9250_read_buf()
453 const struct lan9250_config *config = dev->config; in lan9250_rx()
454 struct lan9250_runtime *ctx = dev->data; in lan9250_rx()
476 pkt_len -= 4; in lan9250_rx()
480 eth_stats_update_errors_rx(ctx->iface); in lan9250_rx()
484 pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_len, AF_UNSPEC, 0, in lan9250_rx()
485 K_MSEC(config->timeout)); in lan9250_rx()
487 LOG_ERR("%s: Could not allocate rx buffer", dev->name); in lan9250_rx()
488 eth_stats_update_errors_rx(ctx->iface); in lan9250_rx()
492 pkt_buf = pkt->buffer; in lan9250_rx()
495 uint8_t *data_ptr = pkt_buf->data; in lan9250_rx()
503 pkt_len -= data_len; in lan9250_rx()
507 pkt_buf = pkt_buf->frags; in lan9250_rx()
511 net_pkt_set_iface(pkt, ctx->iface); in lan9250_rx()
518 k_sem_give(&ctx->tx_rx_sem); in lan9250_rx()
525 struct lan9250_runtime *ctx = dev->data; in lan9250_tx()
536 k_sem_take(&ctx->tx_rx_sem, K_FOREVER); in lan9250_tx()
547 if (net_pkt_read(pkt, ctx->buf, len)) { in lan9250_tx()
548 return -EIO; in lan9250_tx()
551 lan9250_write_buf(dev, ctx->buf, LAN9250_ALIGN(len)); in lan9250_tx()
557 k_sem_give(&ctx->tx_rx_sem); in lan9250_tx()
566 k_sem_give(&context->int_sem); in lan9250_gpio_callback()
580 k_sem_take(&context->int_sem, K_FOREVER); in lan9250_thread()
583 lan9250_read_sys_reg(context->dev, LAN9250_INT_EN, &ier); in lan9250_thread()
586 lan9250_write_sys_reg(context->dev, LAN9250_INT_EN, 0); in lan9250_thread()
589 lan9250_read_sys_reg(context->dev, LAN9250_INT_STS, &int_sts); in lan9250_thread()
594 lan9250_read_phy_reg(context->dev, LAN9250_PHY_INTERRUPT_SOURCE, &tmp); in lan9250_thread()
597 net_eth_carrier_on(context->iface); in lan9250_thread()
600 net_eth_carrier_off(context->iface); in lan9250_thread()
605 lan9250_write_sys_reg(context->dev, LAN9250_INT_STS, LAN9250_INT_STS_RSFL); in lan9250_thread()
606 lan9250_rx(context->dev); in lan9250_thread()
609 /* Re-enable interrupts */ in lan9250_thread()
610 lan9250_write_sys_reg(context->dev, LAN9250_INT_EN, ier); in lan9250_thread()
624 struct lan9250_runtime *context = dev->data; in lan9250_iface_init()
626 net_if_set_link_addr(iface, context->mac_address, sizeof(context->mac_address), in lan9250_iface_init()
628 context->iface = iface; in lan9250_iface_init()
637 struct lan9250_runtime *ctx = dev->data; in lan9250_set_config()
640 memcpy(ctx->mac_address, config->mac_address.addr, sizeof(ctx->mac_address)); in lan9250_set_config()
642 return net_if_set_link_addr(ctx->iface, ctx->mac_address, sizeof(ctx->mac_address), in lan9250_set_config()
646 return -ENOTSUP; in lan9250_set_config()
658 const struct lan9250_config *config = dev->config; in lan9250_init()
659 struct lan9250_runtime *context = dev->data; in lan9250_init()
661 context->dev = dev; in lan9250_init()
664 if (!spi_is_ready_dt(&config->spi)) { in lan9250_init()
665 LOG_ERR("SPI master port %s not ready", config->spi.bus->name); in lan9250_init()
666 return -EINVAL; in lan9250_init()
670 if (!gpio_is_ready_dt(&config->interrupt)) { in lan9250_init()
671 LOG_ERR("GPIO port %s not ready", config->interrupt.port->name); in lan9250_init()
672 return -EINVAL; in lan9250_init()
675 if (gpio_pin_configure_dt(&config->interrupt, GPIO_INPUT)) { in lan9250_init()
676 LOG_ERR("Unable to configure GPIO pin %u", config->interrupt.pin); in lan9250_init()
677 return -EINVAL; in lan9250_init()
680 gpio_init_callback(&(context->gpio_cb), lan9250_gpio_callback, BIT(config->interrupt.pin)); in lan9250_init()
681 if (gpio_add_callback(config->interrupt.port, &(context->gpio_cb))) { in lan9250_init()
682 return -EINVAL; in lan9250_init()
685 gpio_pin_interrupt_configure_dt(&config->interrupt, GPIO_INT_EDGE_TO_ACTIVE); in lan9250_init()
694 k_thread_create(&context->thread, context->thread_stack, in lan9250_init()