1 /*
2 * Copyright (c) 2023 DENX Software Engineering GmbH
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #ifndef ETH_LAN865X_PRIV_H__
7 #define ETH_LAN865X_PRIV_H__
8
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <zephyr/kernel.h>
12 #include <zephyr/drivers/gpio.h>
13 #include <zephyr/drivers/spi.h>
14 #include <zephyr/net/net_if.h>
15 #include <ethernet/eth_stats.h>
16 #include "oa_tc6.h"
17
18 #define LAN865X_SPI_MAX_FREQUENCY 25000000U
19 #define LAN865X_HW_BOOT_DELAY_MS 7
20 #define LAN8650_DEVID 0x8650
21 #define LAN8651_DEVID 0x8651
22 #define LAN865X_REV_MASK GENMASK(3, 0)
23 #define LAN865X_RESET_TIMEOUT 10
24
25 /* Memory Map Sector (MMS) 1 (0x1) */
26 #define LAN865x_MAC_NCR MMS_REG(0x1, 0x000)
27 #define LAN865x_MAC_NCR_TXEN BIT(3)
28 #define LAN865x_MAC_NCR_RXEN BIT(2)
29 #define LAN865x_MAC_NCFGR MMS_REG(0x1, 0x001)
30 #define LAN865x_MAC_NCFGR_CAF BIT(4)
31 #define LAN865x_MAC_NCFGR_MTIHEN BIT(6)
32 #define LAN865x_MAC_HRB MMS_REG(0x1, 0x020)
33 #define LAN865x_MAC_HRT MMS_REG(0x1, 0x021)
34 #define LAN865x_MAC_SAB1 MMS_REG(0x1, 0x022)
35 #define LAN865x_MAC_SAB2 MMS_REG(0x1, 0x024)
36 #define LAN865x_MAC_SAT2 MMS_REG(0x1, 0x025)
37
38 #define LAN865x_MAC_TXRX_ON 1
39 #define LAN865x_MAC_TXRX_OFF 0
40
41 /* Memory Map Sector (MMS) 10 (0xA) */
42 #define LAN865x_DEVID MMS_REG(0xA, 0x094)
43
44 struct lan865x_config_plca {
45 bool enable : 1; /* 1 - PLCA enable, 0 - CSMA/CD enable */
46 uint8_t node_id /* PLCA node id range: 0 to 254 */;
47 uint8_t node_count; /* PLCA node count range: 1 to 255 */
48 uint8_t burst_count; /* PLCA burst count range: 0x0 to 0xFF */
49 uint8_t burst_timer; /* PLCA burst timer */
50 uint8_t to_timer; /* PLCA TO value */
51 };
52
53 struct lan865x_config {
54 struct spi_dt_spec spi;
55 struct gpio_dt_spec interrupt;
56 struct gpio_dt_spec reset;
57 int32_t timeout;
58
59 /* PLCA */
60 struct lan865x_config_plca *plca;
61
62 /* MAC */
63 bool tx_cut_through_mode; /* 1 - tx cut through, 0 - Store and forward */
64 bool rx_cut_through_mode; /* 1 - rx cut through, 0 - Store and forward */
65 };
66
67 struct lan865x_data {
68 struct net_if *iface;
69 struct gpio_callback gpio_int_callback;
70 struct k_sem tx_rx_sem;
71 struct k_sem int_sem;
72 struct oa_tc6 *tc6;
73 uint16_t chip_id;
74 uint8_t silicon_rev;
75 uint8_t mac_address[6];
76 bool iface_initialized;
77 bool reset;
78
79 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ETH_LAN865X_IRQ_THREAD_STACK_SIZE);
80 struct k_thread thread;
81 k_tid_t tid_int;
82 };
83
lan865x_update_dev_cfg_array(oa_mem_map_t * cfg,uint8_t size,uint32_t addr,uint16_t val)84 static inline void lan865x_update_dev_cfg_array(oa_mem_map_t *cfg, uint8_t size,
85 uint32_t addr, uint16_t val)
86 {
87 for (uint8_t i = 0; i < size; i++) {
88 if (cfg[i].address == addr) {
89 cfg[i].value = val;
90 }
91 }
92 }
93
94 #endif /* ETH_LAN865X_PRIV_H__ */
95