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_SAB1		MMS_REG(0x1, 0x022)
32 #define LAN865x_MAC_SAB2		MMS_REG(0x1, 0x024)
33 #define LAN865x_MAC_SAT2		MMS_REG(0x1, 0x025)
34 
35 #define LAN865x_MAC_TXRX_ON             1
36 #define LAN865x_MAC_TXRX_OFF            0
37 
38 /* Memory Map Sector (MMS) 10 (0xA) */
39 #define LAN865x_DEVID MMS_REG(0xA, 0x094)
40 
41 struct lan865x_config_plca {
42 	bool enable : 1; /* 1 - PLCA enable, 0 - CSMA/CD enable */
43 	uint8_t node_id  /* PLCA node id range: 0 to 254 */;
44 	uint8_t node_count;  /* PLCA node count range: 1 to 255 */
45 	uint8_t burst_count;  /* PLCA burst count range: 0x0 to 0xFF */
46 	uint8_t burst_timer;  /* PLCA burst timer */
47 	uint8_t to_timer;  /* PLCA TO value */
48 };
49 
50 struct lan865x_config {
51 	struct spi_dt_spec spi;
52 	struct gpio_dt_spec interrupt;
53 	struct gpio_dt_spec reset;
54 	int32_t timeout;
55 
56 	/* PLCA */
57 	struct lan865x_config_plca *plca;
58 
59 	/* MAC */
60 	bool tx_cut_through_mode; /* 1 - tx cut through, 0 - Store and forward */
61 	bool rx_cut_through_mode; /* 1 - rx cut through, 0 - Store and forward */
62 };
63 
64 struct lan865x_data {
65 	struct net_if *iface;
66 	struct gpio_callback gpio_int_callback;
67 	struct k_sem tx_rx_sem;
68 	struct k_sem int_sem;
69 	struct oa_tc6 *tc6;
70 	uint16_t chip_id;
71 	uint8_t silicon_rev;
72 	uint8_t mac_address[6];
73 	bool iface_initialized;
74 	bool reset;
75 
76 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ETH_LAN865X_IRQ_THREAD_STACK_SIZE);
77 	struct k_thread thread;
78 	k_tid_t tid_int;
79 };
80 
81 #endif /* ETH_LAN865X_PRIV_H__ */
82