blob: 63a03bbcdf8c0e030c66b088fe81cd12edff6e16 [file] [log] [blame]
developer69bcd592024-03-25 14:26:39 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Common part for Airoha AN8855 gigabit switch
4 *
5 * Copyright (C) 2023 Airoha Inc. All Rights Reserved.
6 *
7 * Author: Min Yao <min.yao@airoha.com>
8 */
9
10#ifndef _AN8855_PHY_H_
11#define _AN8855_PHY_H_
12
13#include <linux/bitops.h>
14
15/*phy calibration use*/
16#define DEV_1E 0x1E
17/*global device 0x1f, always set P0*/
18#define DEV_1F 0x1F
19
20/************IEXT/REXT CAL***************/
21/* bits range: for example BITS(16,23) = 0xFF0000*/
22#define BITS(m, n) (~(BIT(m) - 1) & ((BIT(n) - 1) | BIT(n)))
23#define ANACAL_INIT 0x01
24#define ANACAL_ERROR 0xFD
25#define ANACAL_SATURATION 0xFE
26#define ANACAL_FINISH 0xFF
27#define ANACAL_PAIR_A 0
28#define ANACAL_PAIR_B 1
29#define ANACAL_PAIR_C 2
30#define ANACAL_PAIR_D 3
31#define DAC_IN_0V 0x00
32#define DAC_IN_2V 0xf0
33#define TX_AMP_OFFSET_0MV 0x20
34#define TX_AMP_OFFSET_VALID_BITS 6
35
36#define R0 0
37#define PHY0 0
38#define PHY1 1
39#define PHY2 2
40#define PHY3 3
41#define PHY4 4
42#define ANA_TEST_MODE BITS(8, 15)
43#define TST_TCLK_SEL BITs(6, 7)
44#define ANA_TEST_VGA_RG 0x100
45
46#define FORCE_MDI_CROSS_OVER BITS(3, 4)
47#define T10_TEST_CTL_RG 0x145
48#define RG_185 0x185
49#define RG_TX_SLEW BIT(0)
50#define ANA_CAL_0 0xdb
51#define RG_CAL_CKINV BIT(12)
52#define RG_ANA_CALEN BIT(8)
53#define RG_REXT_CALEN BIT(4)
54#define RG_ZCALEN_A BIT(0)
55#define ANA_CAL_1 0xdc
56#define RG_ZCALEN_B BIT(12)
57#define RG_ZCALEN_C BIT(8)
58#define RG_ZCALEN_D BIT(4)
59#define RG_TXVOS_CALEN BIT(0)
60#define ANA_CAL_6 0xe1
61#define RG_CAL_REFSEL BIT(4)
62#define RG_CAL_COMP_PWD BIT(0)
63#define ANA_CAL_5 0xe0
64#define RG_REXT_TRIM BITs(8, 13)
65#define RG_ZCAL_CTRL BITs(0, 5)
66#define RG_17A 0x17a
67#define AD_CAL_COMP_OUT BIT(8)
68#define RG_17B 0x17b
69#define AD_CAL_CLK bit(0)
70#define RG_17C 0x17c
71#define DA_CALIN_FLAG bit(0)
72/************R50 CAL****************************/
73#define RG_174 0x174
74#define RG_R50OHM_RSEL_TX_A_EN BIT[15]
75#define CR_R50OHM_RSEL_TX_A BITS[8:14]
76#define RG_R50OHM_RSEL_TX_B_EN BIT[7]
77#define CR_R50OHM_RSEL_TX_B BITS[6:0]
78#define RG_175 0x175
79#define RG_R50OHM_RSEL_TX_C_EN BITS[15]
80#define CR_R50OHM_RSEL_TX_C BITS[8:14]
81#define RG_R50OHM_RSEL_TX_D_EN BIT[7]
82#define CR_R50OHM_RSEL_TX_D BITS[0:6]
83/**********TX offset Calibration***************************/
84#define RG_95 0x96
85#define BYPASS_TX_OFFSET_CAL BIT(15)
86#define RG_3E 0x3e
87#define BYPASS_PD_TXVLD_A BIT(15)
88#define BYPASS_PD_TXVLD_B BIT(14)
89#define BYPASS_PD_TXVLD_C BIT(13)
90#define BYPASS_PD_TXVLD_D BIT(12)
91#define BYPASS_PD_TX_10M BIT(11)
92#define POWER_DOWN_TXVLD_A BIT(7)
93#define POWER_DOWN_TXVLD_B BIT(6)
94#define POWER_DOWN_TXVLD_C BIT(5)
95#define POWER_DOWN_TXVLD_D BIT(4)
96#define POWER_DOWN_TX_10M BIT(3)
97#define RG_DD 0xdd
98#define RG_TXG_CALEN_A BIT(12)
99#define RG_TXG_CALEN_B BIT(8)
100#define RG_TXG_CALEN_C BIT(4)
101#define RG_TXG_CALEN_D BIT(0)
102#define RG_17D 0x17D
103#define FORCE_DASN_DAC_IN0_A BIT(15)
104#define DASN_DAC_IN0_A BITS(0, 9)
105#define RG_17E 0x17E
106#define FORCE_DASN_DAC_IN0_B BIT(15)
107#define DASN_DAC_IN0_B BITS(0, 9)
108#define RG_17F 0x17F
109
110#define FORCE_DASN_DAC_IN0_C BIT(15)
111#define DASN_DAC_IN0_C BITS(0, 9)
112#define RG_180 0x180
113#define FORCE_DASN_DAC_IN0_D BIT(15)
114#define DASN_DAC_IN0_D BITS(0, 9)
115
116#define RG_181 0x181
117#define FORCE_DASN_DAC_IN1_A BIT(15)
118#define DASN_DAC_IN1_A BITS(0, 9)
119#define RG_182 0x182
120#define FORCE_DASN_DAC_IN1_B BIT(15)
121#define DASN_DAC_IN1_B BITS(0, 9)
122#define RG_183 0x183
123#define FORCE_DASN_DAC_IN1_C BIT(15)
124#define DASN_DAC_IN1_C BITS(0, 9)
125#define RG_184 0x184
126#define FORCE_DASN_DAC_IN1_D BIT(15)
127#define DASN_DAC_IN1_D BITS(0, 9)
128#define RG_172 0x172
129#define CR_TX_AMP_OFFSET_A BITS(8, 13)
130#define CR_TX_AMP_OFFSET_B BITS(0, 5)
131#define RG_173 0x173
132#define CR_TX_AMP_OFFSET_C BITS(8, 13)
133#define CR_TX_AMP_OFFSET_D BITS(0, 5)
134/**********TX Amp Calibration ***************************/
135#define RG_12 0x12
136#define DA_TX_I2MPB_A_GBE BITS(10, 15)
137#define RG_17 0x17
138#define DA_TX_I2MPB_B_GBE BITS(8, 13)
139#define RG_19 0x19
140#define DA_TX_I2MPB_C_GBE BITS(8, 13)
141#define RG_21 0x21
142#define DA_TX_I2MPB_D_GBE BITS(8, 13)
143#define TX_AMP_MAX 0x3f
144#define TX_AMP_MAX_OFFSET 0xb
145#define TX_AMP_HIGHEST_TS ((TX_AMP_MAX) + 3)
146#define TX_AMP_LOWEST_TS (0 - 3)
147#define TX_AMP_HIGH_TS (TX_AMP_MAX)
148#define TX_AMP_LOW_TS 0
149
150/* PHY Extend Register 0x14 bitmap of define */
151#define PHY_EXT_REG_14 0x14
152
153/* Fields of PHY_EXT_REG_14 */
154#define PHY_EN_DOWN_SHFIT BIT(4)
155
156/* PHY Extend Register 0x17 bitmap of define */
157#define PHY_EXT_REG_17 0x17
158
159/* Fields of PHY_EXT_REG_17 */
160#define PHY_LINKDOWN_POWER_SAVING_EN BIT(4)
161
162/* PHY PMA Register 0x17 bitmap of define */
163#define SLV_DSP_READY_TIME_S 15
164#define SLV_DSP_READY_TIME_M (0xff << SLV_DSP_READY_TIME_S)
165
166/* PHY PMA Register 0x18 bitmap of define */
167#define ENABLE_RANDOM_UPDATE_TRIGGER BIT(8)
168
169/* PHY EEE Register bitmap of define */
170#define PHY_DEV07 0x07
171#define PHY_DEV07_REG_03C 0x3c
172
173/* PHY DEV 0x1e Register bitmap of define */
174#define PHY_DEV1E 0x1e
175#define PHY_DEV1F 0x1f
176
177/* Proprietory Control Register of Internal Phy device 0x1e */
178#define PHY_TX_MLT3_BASE 0x0
179#define PHY_DEV1E_REG_13 0x13
180#define PHY_DEV1E_REG_14 0x14
181#define PHY_DEV1E_REG_41 0x41
182#define PHY_DEV1E_REG_A6 0xa6
183#define RXADC_CONTROL_3 0xc2
184#define PHY_DEV1E_REG_0C6 0xc6
185#define RXADC_LDO_CONTROL_2 0xd3
186#define PHY_DEV1E_REG_0FE 0xfe
187#define PHY_DEV1E_REG_123 0x123
188#define PHY_DEV1E_REG_189 0x189
189#define PHY_DEV1E_REG_234 0x234
190
191/* Proprietory Control Register of Internal Phy device 0x1f */
192#define PHY_DEV1F_REG_44 0x44
193#define PHY_DEV1F_REG_268 0x268
194#define PHY_DEV1F_REG_269 0x269
195#define PHY_DEV1F_REG_26A 0x26A
196#define TXVLD_DA_271 0x271
197#define TXVLD_DA_272 0x272
198#define TXVLD_DA_273 0x273
199
200/* Fields of PHY_DEV1E_REG_0C6 */
201#define PHY_POWER_SAVING_S 8
202#define PHY_POWER_SAVING_M 0x300
203#define PHY_POWER_SAVING_TX 0x0
204
205/* Fields of PHY_DEV1E_REG_189 */
206#define DESCRAMBLER_CLEAR_EN 0x1
207
208/* Fields of PHY_DEV1E_REG_234 */
209#define TR_OPEN_LOOP_EN BIT(0)
210
211/* Internal GPHY Page Control Register */
212#define PHY_CL22_PAGE_CTRL 0x1f
213#define PHY_TR_PAGE 0x52b5
214
215/* Internal GPHY Token Ring Access Registers */
216#define PHY_TR_CTRL 0x10
217#define PHY_TR_LOW_DATA 0x11
218#define PHY_TR_HIGH_DATA 0x12
219
220/* Fields of PHY_TR_CTRL */
221#define PHY_TR_PKT_XMT_STA BIT(15)
222#define PHY_TR_WR_S 13
223#define PHY_TR_CH_ADDR_S 11
224#define PHY_TR_NODE_ADDR_S 7
225#define PHY_TR_DATA_ADDR_S 1
226
227enum phy_tr_wr {
228 PHY_TR_WRITE = 0,
229 PHY_TR_READ = 1,
230};
231
232/* Helper macro for GPHY Token Ring Access */
233#define PHY_TR_LOW_VAL(x) ((x) & 0xffff)
234#define PHY_TR_HIGH_VAL(x) (((x) & 0xff0000) >> 16)
235
236/* Token Ring Channels */
237#define PMA_CH 0x1
238#define DSP_CH 0x2
239
240/* Token Ring Nodes */
241#define PMA_NOD 0xf
242#define DSP_NOD 0xd
243
244/* Token Ring register range */
245enum tr_pma_reg_addr {
246 PMA_MIN = 0x0,
247 PMA_01 = 0x1,
248 PMA_17 = 0x17,
249 PMA_18 = 0x18,
250 PMA_MAX = 0x3d,
251};
252
253enum tr_dsp_reg_addr {
254 DSP_MIN = 0x0,
255 DSP_06 = 0x6,
256 DSP_08 = 0x8,
257 DSP_0f = 0xf,
258 DSP_10 = 0x10,
259 DSP_MAX = 0x3e,
260};
261#endif /* _AN8855_REGS_H_ */