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 /* LAN8650/1 configuration fixup from AN1760 */
38 #define LAN865X_FIXUP_REG        MMS_REG(0x1, 0x077)
39 #define LAN865X_FIXUP_VALUE      0x0028
40 
41 #define LAN865x_MAC_TXRX_ON  1
42 #define LAN865x_MAC_TXRX_OFF 0
43 
44 /* Memory Map Sector (MMS) 10 (0xA) */
45 #define LAN865x_DEVID MMS_REG(0xA, 0x094)
46 
47 struct lan865x_config {
48 	const struct device *phy;
49 	struct spi_dt_spec spi;
50 	struct gpio_dt_spec interrupt;
51 	struct gpio_dt_spec reset;
52 	int32_t timeout;
53 
54 	/* MAC */
55 	bool tx_cut_through_mode; /* 1 - tx cut through, 0 - Store and forward */
56 	bool rx_cut_through_mode; /* 1 - rx cut through, 0 - Store and forward */
57 };
58 
59 struct lan865x_data {
60 	struct net_if *iface;
61 	struct gpio_callback gpio_int_callback;
62 	struct k_sem tx_rx_sem;
63 	struct k_sem int_sem;
64 	struct oa_tc6 *tc6;
65 	uint16_t chip_id;
66 	uint8_t silicon_rev;
67 	uint8_t mac_address[6];
68 	bool iface_initialized;
69 	bool reset;
70 
71 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ETH_LAN865X_IRQ_THREAD_STACK_SIZE);
72 	struct k_thread thread;
73 	k_tid_t tid_int;
74 };
75 
76 #endif /* ETH_LAN865X_PRIV_H__ */
77