1 /*
2  * Copyright (c) 2021 IP-Logix Inc.
3  *               Arvin Farahmand <arvinf@ip-logix.com>
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __DSA_KSZ8863_H__
8 #define __DSA_KSZ8863_H__
9 
10 /* SPI commands */
11 #define KSZ8863_SPI_CMD_WR (BIT(6))
12 #define KSZ8863_SPI_CMD_RD (BIT(6) | BIT(5))
13 
14 /* PHY registers */
15 #define KSZ8863_BMCR                                 0x00
16 #define KSZ8863_BMSR                                 0x01
17 #define KSZ8863_PHYID1                               0x02
18 #define KSZ8863_PHYID2                               0x03
19 #define KSZ8863_ANAR                                 0x04
20 #define KSZ8863_ANLPAR                               0x05
21 #define KSZ8863_LINKMD                               0x1D
22 #define KSZ8863_PHYSCS                               0x1F
23 
24 /* SWITCH registers */
25 #define KSZ8863_CHIP_ID0                             0x00
26 #define KSZ8863_CHIP_ID1                             0x01
27 #define KSZ8863_GLOBAL_CTRL0                         0x02
28 #define KSZ8863_GLOBAL_CTRL1                         0x03
29 #define KSZ8863_GLOBAL_CTRL2                         0x04
30 #define KSZ8863_GLOBAL_CTRL3                         0x05
31 #define KSZ8863_GLOBAL_CTRL4                         0x06
32 #define KSZ8863_GLOBAL_CTRL5                         0x07
33 #define KSZ8863_GLOBAL_CTRL9                         0x0B
34 #define KSZ8863_GLOBAL_CTRL10                        0x0C
35 #define KSZ8863_GLOBAL_CTRL11                        0x0D
36 #define KSZ8863_GLOBAL_CTRL12                        0x0E
37 #define KSZ8863_GLOBAL_CTRL13                        0x0F
38 #define KSZ8863_PORT1_CTRL0                          0x10
39 #define KSZ8863_PORT1_CTRL1                          0x11
40 #define KSZ8863_PORT1_CTRL2                          0x12
41 #define KSZ8863_PORT1_CTRL3                          0x13
42 #define KSZ8863_PORT1_CTRL4                          0x14
43 #define KSZ8863_PORT1_CTRL5                          0x15
44 #define KSZ8863_PORT1_Q0_IG_LIMIT                    0x16
45 #define KSZ8863_PORT1_Q1_IG_LIMIT                    0x17
46 #define KSZ8863_PORT1_Q2_IG_LIMIT                    0x18
47 #define KSZ8863_PORT1_Q3_IG_LIMIT                    0x19
48 #define KSZ8863_PORT1_PHY_CTRL                       0x1A
49 #define KSZ8863_PORT1_LINKMD                         0x1B
50 #define KSZ8863_PORT1_CTRL12                         0x1C
51 #define KSZ8863_PORT1_CTRL13                         0x1D
52 #define KSZ8863_PORT1_STAT0                          0x1E
53 #define KSZ8863_PORT1_STAT1                          0x1F
54 
55 #define KSZ8863_PORT2_CTRL0                          0x20
56 #define KSZ8863_PORT2_CTRL1                          0x21
57 #define KSZ8863_PORT2_CTRL2                          0x22
58 #define KSZ8863_PORT2_CTRL3                          0x23
59 #define KSZ8863_PORT2_CTRL4                          0x24
60 #define KSZ8863_PORT2_CTRL5                          0x25
61 #define KSZ8863_PORT2_Q0_IG_LIMIT                    0x26
62 #define KSZ8863_PORT2_Q1_IG_LIMIT                    0x27
63 #define KSZ8863_PORT2_Q2_IG_LIMIT                    0x28
64 #define KSZ8863_PORT2_Q3_IG_LIMIT                    0x29
65 #define KSZ8863_PORT2_PHY_CTRL                       0x2A
66 #define KSZ8863_PORT2_LINKMD                         0x2B
67 #define KSZ8863_PORT2_CTRL12                         0x2C
68 #define KSZ8863_PORT2_CTRL13                         0x2D
69 #define KSZ8863_PORT2_STAT0                          0x2E
70 #define KSZ8863_PORT2_STAT1                          0x2F
71 
72 #define KSZ8863_PORT3_CTRL0                          0x30
73 #define KSZ8863_PORT3_CTRL1                          0x31
74 #define KSZ8863_PORT3_CTRL2                          0x32
75 #define KSZ8863_PORT3_CTRL3                          0x33
76 #define KSZ8863_PORT3_CTRL4                          0x34
77 #define KSZ8863_PORT3_CTRL5                          0x35
78 #define KSZ8863_PORT3_Q0_IG_LIMIT                    0x36
79 #define KSZ8863_PORT3_Q1_IG_LIMIT                    0x37
80 #define KSZ8863_PORT3_Q2_IG_LIMIT                    0x38
81 #define KSZ8863_PORT3_Q3_IG_LIMIT                    0x39
82 #define KSZ8863_PORT3_STAT1                          0x3F
83 
84 #define KSZ8863_MAC_ADDR0                            0x70
85 #define KSZ8863_MAC_ADDR1                            0x71
86 #define KSZ8863_MAC_ADDR2                            0x72
87 #define KSZ8863_MAC_ADDR3                            0x73
88 #define KSZ8863_MAC_ADDR4                            0x74
89 #define KSZ8863_MAC_ADDR5                            0x75
90 #define KSZ8863_USER0                                0x76
91 #define KSZ8863_USER1                                0x77
92 #define KSZ8863_USER2                                0x78
93 
94 #define KSZ8863_GLOBAL_CTRL1_TAIL_TAG_EN             BIT(6)
95 #define KSZ8863_GLOBAL_CTRL2_LEG_MAX_PKT_SIZ_CHK_ENA BIT(1)
96 
97 #define KSZ8863_CTRL1_PORTn(n)                       (0x11 + ((n) * 0x10))
98 #define KSZ8863_CTRL1_VLAN_PORTS_MASK                0xF8
99 #define KSZ8863_CTRL2_PORTn(n)                       (0x12 + ((n) * 0x10))
100 #define KSZ8863_CTRL2_TRANSMIT_EN                    BIT(2)
101 #define KSZ8863_CTRL2_RECEIVE_EN                     BIT(1)
102 #define KSZ8863_CTRL2_LEARNING_DIS                   BIT(0)
103 
104 #define KSZ8863_STAT2_PORTn(n)                       (0x1E + ((n) * 0x10))
105 #define KSZ8863_STAT2_LINK_GOOD                      BIT(5)
106 
107 #define KSZ8863_CHIP_ID0_ID_DEFAULT                  0x88
108 #define KSZ8863_CHIP_ID1_ID_DEFAULT                  0x31
109 #define KSZ8863_REGISTER_67                          0x43
110 #define KSZ8863_SOFTWARE_RESET_SET                   BIT(4)
111 #define KSZ8863_SOFTWARE_RESET_CLEAR                 0
112 
113 enum {
114 	/* LAN ports for the ksz8863 switch */
115 	KSZ8863_PORT1 = 0,
116 	KSZ8863_PORT2,
117 	/* SWITCH <-> CPU port */
118 	KSZ8863_PORT3,
119 };
120 
121 #define KSZ8863_REG_IND_CTRL_0                        0x79
122 #define KSZ8863_REG_IND_CTRL_1                        0x7A
123 #define KSZ8863_REG_IND_DATA_8                        0x7B
124 #define KSZ8863_REG_IND_DATA_7                        0x7C
125 #define KSZ8863_REG_IND_DATA_6                        0x7D
126 #define KSZ8863_REG_IND_DATA_5                        0x7E
127 #define KSZ8863_REG_IND_DATA_4                        0x7F
128 #define KSZ8863_REG_IND_DATA_3                        0x80
129 #define KSZ8863_REG_IND_DATA_2                        0x81
130 #define KSZ8863_REG_IND_DATA_1                        0x82
131 #define KSZ8863_REG_IND_DATA_0                        0x83
132 
133 #define KSZ8863_STATIC_MAC_TABLE_VALID                BIT(3)
134 #define KSZ8863_STATIC_MAC_TABLE_OVRD                 BIT(4)
135 #define KSZ8863_STATIC_MAC_TABLE_USE_FID              BIT(5)
136 
137 #define KSZ8XXX_CHIP_ID0                        KSZ8863_CHIP_ID0
138 #define KSZ8XXX_CHIP_ID1                        KSZ8863_CHIP_ID1
139 #define KSZ8XXX_CHIP_ID0_ID_DEFAULT             KSZ8863_CHIP_ID0_ID_DEFAULT
140 #define KSZ8XXX_CHIP_ID1_ID_DEFAULT             KSZ8863_CHIP_ID1_ID_DEFAULT
141 #define KSZ8XXX_FIRST_PORT                      KSZ8863_PORT1
142 #define KSZ8XXX_LAST_PORT                       KSZ8863_PORT3
143 #define KSZ8XXX_CPU_PORT                        KSZ8863_PORT3
144 #define KSZ8XXX_REG_IND_CTRL_0                  KSZ8863_REG_IND_CTRL_0
145 #define KSZ8XXX_REG_IND_CTRL_1                  KSZ8863_REG_IND_CTRL_1
146 #define KSZ8XXX_REG_IND_DATA_8                  KSZ8863_REG_IND_DATA_8
147 #define KSZ8XXX_REG_IND_DATA_7                  KSZ8863_REG_IND_DATA_7
148 #define KSZ8XXX_REG_IND_DATA_6                  KSZ8863_REG_IND_DATA_6
149 #define KSZ8XXX_REG_IND_DATA_5                  KSZ8863_REG_IND_DATA_5
150 #define KSZ8XXX_REG_IND_DATA_4                  KSZ8863_REG_IND_DATA_4
151 #define KSZ8XXX_REG_IND_DATA_3                  KSZ8863_REG_IND_DATA_3
152 #define KSZ8XXX_REG_IND_DATA_2                  KSZ8863_REG_IND_DATA_2
153 #define KSZ8XXX_REG_IND_DATA_1                  KSZ8863_REG_IND_DATA_1
154 #define KSZ8XXX_REG_IND_DATA_0                  KSZ8863_REG_IND_DATA_0
155 #define KSZ8XXX_STATIC_MAC_TABLE_VALID          KSZ8863_STATIC_MAC_TABLE_VALID
156 #define KSZ8XXX_STATIC_MAC_TABLE_OVRD           KSZ8863_STATIC_MAC_TABLE_OVRD
157 #define KSZ8XXX_STAT2_LINK_GOOD                 KSZ8863_STAT2_LINK_GOOD
158 #define KSZ8XXX_RESET_REG                       KSZ8863_REGISTER_67
159 #define KSZ8XXX_RESET_SET                       KSZ8863_SOFTWARE_RESET_SET
160 #define KSZ8XXX_RESET_CLEAR                     KSZ8863_SOFTWARE_RESET_CLEAR
161 #define KSZ8XXX_STAT2_PORTn                     KSZ8863_STAT2_PORTn
162 #define KSZ8XXX_CTRL1_PORTn			KSZ8863_CTRL1_PORTn
163 #define KSZ8XXX_CTRL1_VLAN_PORTS_MASK		KSZ8863_CTRL1_VLAN_PORTS_MASK
164 #define KSZ8XXX_SPI_CMD_RD                      KSZ8863_SPI_CMD_RD
165 #define KSZ8XXX_SPI_CMD_WR                      KSZ8863_SPI_CMD_WR
166 #define KSZ8XXX_SOFT_RESET_DURATION             1000
167 #define KSZ8XXX_HARD_RESET_WAIT                 10000
168 
169 #endif /* __DSA_KSZ8863_H__ */
170