blob: 07f4792aefedfb2f14746799781aab6cedb26106 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stefan Roese8f64e262016-05-23 11:12:05 +02002/*
3 * Copyright (C) 2015-2016 Marvell International Ltd.
Stefan Roese8f64e262016-05-23 11:12:05 +02004 */
5
6#ifndef _COMPHY_A3700_H_
7#define _COMPHY_A3700_H_
8
9#include "comphy.h"
10#include "comphy_hpipe.h"
11
Marek Behún4c02f732018-04-24 17:21:12 +020012#define MVEBU_REG(offs) \
13 ((void __iomem *)(ulong)MVEBU_REGISTER(offs))
Stefan Roese8f64e262016-05-23 11:12:05 +020014
15#define DEFAULT_REFCLK_MHZ 25
16#define PLL_SET_DELAY_US 600
17#define PLL_LOCK_TIMEOUT 1000
18#define POLL_16B_REG 1
19#define POLL_32B_REG 0
20
21/*
22 * COMPHY SB definitions
23 */
24#define COMPHY_SEL_ADDR MVEBU_REG(0x0183FC)
25#define rf_compy_select(lane) (0x1 << (((lane) == 1) ? 4 : 0))
26
27#define COMPHY_PHY_CFG1_ADDR(lane) MVEBU_REG(0x018300 + (lane) * 0x28)
28#define rb_pin_pu_iveref BIT(1)
29#define rb_pin_reset_core BIT(11)
30#define rb_pin_reset_comphy BIT(12)
31#define rb_pin_pu_pll BIT(16)
32#define rb_pin_pu_rx BIT(17)
33#define rb_pin_pu_tx BIT(18)
34#define rb_pin_tx_idle BIT(19)
35#define rf_gen_rx_sel_shift 22
Andre Przywara8dfa4ee2016-11-16 00:50:10 +000036#define rf_gen_rx_select (0x0F << rf_gen_rx_sel_shift)
Stefan Roese8f64e262016-05-23 11:12:05 +020037#define rf_gen_tx_sel_shift 26
Andre Przywara8dfa4ee2016-11-16 00:50:10 +000038#define rf_gen_tx_select (0x0F << rf_gen_tx_sel_shift)
Stefan Roese8f64e262016-05-23 11:12:05 +020039#define rb_phy_rx_init BIT(30)
40
41#define COMPHY_PHY_STAT1_ADDR(lane) MVEBU_REG(0x018318 + (lane) * 0x28)
42#define rb_rx_init_done BIT(0)
43#define rb_pll_ready_rx BIT(2)
44#define rb_pll_ready_tx BIT(3)
45
46/*
47 * PCIe/USB/SGMII definitions
48 */
49#define PCIE_BASE MVEBU_REG(0x070000)
50#define PCIETOP_BASE MVEBU_REG(0x080000)
51#define PCIE_RAMBASE MVEBU_REG(0x08C000)
52#define PCIEPHY_BASE MVEBU_REG(0x01F000)
53#define PCIEPHY_SHFT 2
54
55#define USB32_BASE MVEBU_REG(0x050000) /* usb3 device */
56#define USB32H_BASE MVEBU_REG(0x058000) /* usb3 host */
57#define USB3PHY_BASE MVEBU_REG(0x05C000)
58#define USB2PHY_BASE MVEBU_REG(0x05D000)
59#define USB2PHY2_BASE MVEBU_REG(0x05F000)
60#define USB32_CTRL_BASE MVEBU_REG(0x05D800)
61#define USB3PHY_SHFT 2
Marek Behúnef6f36e2018-04-24 17:21:18 +020062#define USB3PHY_LANE2_REG_BASE_OFFSET 0x200
Stefan Roese8f64e262016-05-23 11:12:05 +020063
Marek Behúnee3e2f62018-04-24 17:21:13 +020064static inline void __iomem *sgmiiphy_addr(u32 lane, u32 addr)
65{
66 addr = (addr & 0x00007FF) * 2;
67 if (lane == 1)
68 return PCIEPHY_BASE + addr;
69 else
70 return USB3PHY_BASE + addr;
71}
Stefan Roese8f64e262016-05-23 11:12:05 +020072
73/* units */
Marek Behúna89ae132018-04-24 17:21:14 +020074enum phy_unit {
75 PCIE = 1,
76 USB3 = 2,
77};
Stefan Roese8f64e262016-05-23 11:12:05 +020078
Marek Behúna89ae132018-04-24 17:21:14 +020079static inline void __iomem *phy_addr(enum phy_unit unit, u32 addr)
80{
81 if (unit == PCIE)
82 return PCIEPHY_BASE + addr * PCIEPHY_SHFT;
83 else
84 return USB3PHY_BASE + addr * USB3PHY_SHFT;
85}
Stefan Roese8f64e262016-05-23 11:12:05 +020086
87/* bit definition for USB32_CTRL_BASE (USB32 Control Mode) */
88#define usb32_ctrl_id_mode BIT(0)
89#define usb32_ctrl_soft_id BIT(1)
90#define usb32_ctrl_int_mode BIT(4)
91
Marek Behúna89ae132018-04-24 17:21:14 +020092#define PWR_PLL_CTRL 0x01
Stefan Roese8f64e262016-05-23 11:12:05 +020093#define rf_phy_mode_shift 5
94#define rf_phy_mode_mask (0x7 << rf_phy_mode_shift)
95#define rf_ref_freq_sel_shift 0
96#define rf_ref_freq_sel_mask (0x1F << rf_ref_freq_sel_shift)
97#define PHY_MODE_SGMII 0x4
98
Marek Behúna89ae132018-04-24 17:21:14 +020099#define KVCO_CAL_CTRL 0x02
Stefan Roese8f64e262016-05-23 11:12:05 +0200100#define rb_use_max_pll_rate BIT(12)
101#define rb_force_calibration_done BIT(9)
102
Marek Behúna89ae132018-04-24 17:21:14 +0200103#define DIG_LB_EN 0x23
Stefan Roese8f64e262016-05-23 11:12:05 +0200104#define rf_data_width_shift 10
105#define rf_data_width_mask (0x3 << rf_data_width_shift)
106
Marek Behúna89ae132018-04-24 17:21:14 +0200107#define SYNC_PATTERN 0x24
Stefan Roese8f64e262016-05-23 11:12:05 +0200108#define phy_txd_inv BIT(10)
109#define phy_rxd_inv BIT(11)
110
Marek Behúna89ae132018-04-24 17:21:14 +0200111#define SYNC_MASK_GEN 0x25
Stefan Roese8f64e262016-05-23 11:12:05 +0200112#define rb_idle_sync_en BIT(12)
113
Marek Behúna89ae132018-04-24 17:21:14 +0200114#define UNIT_CTRL 0x48
115
116#define GEN2_SETTINGS_2 0x3e
Stefan Roese8f64e262016-05-23 11:12:05 +0200117#define g2_tx_ssc_amp BIT(14)
118
Marek Behúna89ae132018-04-24 17:21:14 +0200119#define GEN2_SETTINGS_3 0x3f
Stefan Roese8f64e262016-05-23 11:12:05 +0200120
Marek Behúna89ae132018-04-24 17:21:14 +0200121#define GEN3_SETTINGS_3 0x112
122
123#define MISC_REG0 0x4f
Stefan Roese8f64e262016-05-23 11:12:05 +0200124#define rb_clk100m_125m_en BIT(4)
125#define rb_clk500m_en BIT(7)
126#define rb_ref_clk_sel BIT(10)
127
Marek Behúna89ae132018-04-24 17:21:14 +0200128#define UNIT_IFACE_REF_CLK_CTRL 0x51
Stefan Roese8f64e262016-05-23 11:12:05 +0200129#define rb_ref1m_gen_div_force BIT(8)
130#define rf_ref1m_gen_div_value_shift 0
131#define rf_ref1m_gen_div_value_mask (0xFF << rf_ref1m_gen_div_value_shift)
132
Marek Behúna89ae132018-04-24 17:21:14 +0200133#define UNIT_ERR_CNT_CONST_CTRL 0x6a
Stefan Roese8f64e262016-05-23 11:12:05 +0200134#define rb_fast_dfe_enable BIT(13)
135
Marek Behúna89ae132018-04-24 17:21:14 +0200136#define MISC_REG1 0x73
Stefan Roese8f64e262016-05-23 11:12:05 +0200137#define bf_sel_bits_pcie_force BIT(15)
138
Marek Behúna89ae132018-04-24 17:21:14 +0200139#define LANE_CFG0 0x180
Stefan Roese8f64e262016-05-23 11:12:05 +0200140#define bf_use_max_pll_rate BIT(9)
Marek Behúna89ae132018-04-24 17:21:14 +0200141
142#define LANE_CFG1 0x181
Stefan Roese8f64e262016-05-23 11:12:05 +0200143#define bf_use_max_pll_rate BIT(9)
Marek Behúna89ae132018-04-24 17:21:14 +0200144
145#define LANE_CFG4 0x188
Stefan Roese8f64e262016-05-23 11:12:05 +0200146#define bf_spread_spectrum_clock_en BIT(7)
147
Marek Behúna89ae132018-04-24 17:21:14 +0200148#define LANE_STAT1 0x183
Stefan Roese8f64e262016-05-23 11:12:05 +0200149#define rb_txdclk_pclk_en BIT(0)
150
Marek Behúna89ae132018-04-24 17:21:14 +0200151#define GLOB_PHY_CTRL0 0x1c1
Stefan Roese8f64e262016-05-23 11:12:05 +0200152#define bf_soft_rst BIT(0)
153#define bf_mode_refdiv 0x30
154#define rb_mode_core_clk_freq_sel BIT(9)
155#define rb_mode_pipe_width_32 BIT(3)
156
Marek Behúna89ae132018-04-24 17:21:14 +0200157#define TEST_MODE_CTRL 0x1c2
Stefan Roese8f64e262016-05-23 11:12:05 +0200158#define rb_mode_margin_override BIT(2)
159
Marek Behúna89ae132018-04-24 17:21:14 +0200160#define GLOB_CLK_SRC_LO 0x1c3
Stefan Roese8f64e262016-05-23 11:12:05 +0200161#define bf_cfg_sel_20b BIT(15)
162
Marek Behúna89ae132018-04-24 17:21:14 +0200163#define PWR_MGM_TIM1 0x1d0
Stefan Roese8f64e262016-05-23 11:12:05 +0200164
Marek Behúna89ae132018-04-24 17:21:14 +0200165#define PCIE_REF_CLK_ADDR (PCIE_BASE + 0x4814)
Stefan Roese8f64e262016-05-23 11:12:05 +0200166
167#define USB3_CTRPUL_VAL_REG (0x20 + USB32_BASE)
168#define USB3H_CTRPUL_VAL_REG (0x3454 + USB32H_BASE)
169#define rb_usb3_ctr_100ns 0xff000000
170
171#define USB2_OTG_PHY_CTRL_ADDR (0x820 + USB2PHY_BASE)
172#define rb_usb2phy_suspm BIT(14)
173#define rb_usb2phy_pu BIT(0)
174
175#define USB2_PHY_OTG_CTRL_ADDR (0x34 + USB2PHY_BASE)
176#define rb_pu_otg BIT(4)
177
178#define USB2_PHY_CHRGR_DET_ADDR (0x38 + USB2PHY_BASE)
179#define rb_cdp_en BIT(2)
180#define rb_dcp_en BIT(3)
181#define rb_pd_en BIT(4)
182#define rb_pu_chrg_dtc BIT(5)
183#define rb_cdp_dm_auto BIT(7)
184#define rb_enswitch_dp BIT(12)
185#define rb_enswitch_dm BIT(13)
186
187#define USB2_CAL_CTRL_ADDR (0x8 + USB2PHY_BASE)
188#define rb_usb2phy_pllcal_done BIT(31)
189#define rb_usb2phy_impcal_done BIT(23)
190
191#define USB2_PLL_CTRL0_ADDR (0x0 + USB2PHY_BASE)
192#define rb_usb2phy_pll_ready BIT(31)
193
194#define USB2_RX_CHAN_CTRL1_ADDR (0x18 + USB2PHY_BASE)
195#define rb_usb2phy_sqcal_done BIT(31)
196
197#define USB2_PHY2_CTRL_ADDR (0x804 + USB2PHY2_BASE)
198#define rb_usb2phy2_suspm BIT(7)
199#define rb_usb2phy2_pu BIT(0)
200#define USB2_PHY2_CAL_CTRL_ADDR (0x8 + USB2PHY2_BASE)
201#define USB2_PHY2_PLL_CTRL0_ADDR (0x0 + USB2PHY2_BASE)
202#define USB2_PHY2_RX_CHAN_CTRL1_ADDR (0x18 + USB2PHY2_BASE)
203
204#define USB2_PHY_BASE(usb32) (usb32 == 0 ? USB2PHY2_BASE : USB2PHY_BASE)
205#define USB2_PHY_CTRL_ADDR(usb32) \
206 (usb32 == 0 ? USB2_PHY2_CTRL_ADDR : USB2_OTG_PHY_CTRL_ADDR)
207#define RB_USB2PHY_SUSPM(usb32) \
208 (usb32 == 0 ? rb_usb2phy2_suspm : rb_usb2phy_suspm)
209#define RB_USB2PHY_PU(usb32) \
210 (usb32 == 0 ? rb_usb2phy2_pu : rb_usb2phy_pu)
211#define USB2_PHY_CAL_CTRL_ADDR(usb32) \
212 (usb32 == 0 ? USB2_PHY2_CAL_CTRL_ADDR : USB2_CAL_CTRL_ADDR)
213#define USB2_PHY_RX_CHAN_CTRL1_ADDR(usb32) \
214 (usb32 == 0 ? USB2_PHY2_RX_CHAN_CTRL1_ADDR : USB2_RX_CHAN_CTRL1_ADDR)
215#define USB2_PHY_PLL_CTRL0_ADDR(usb32) \
216 (usb32 == 0 ? USB2_PHY2_PLL_CTRL0_ADDR : USB2_PLL_CTRL0_ADDR)
217
218/*
219 * SATA definitions
220 */
221#define AHCI_BASE MVEBU_REG(0xE0000)
222
223#define rh_vsreg_addr (AHCI_BASE + 0x178)
224#define rh_vsreg_data (AHCI_BASE + 0x17C)
225#define rh_vs0_a (AHCI_BASE + 0xA0)
226#define rh_vs0_d (AHCI_BASE + 0xA4)
227
228#define vphy_sync_pattern_reg 0x224
229#define bs_txd_inv BIT(10)
230#define bs_rxd_inv BIT(11)
231
232#define vphy_loopback_reg0 0x223
233#define bs_phyintf_40bit 0x0C00
234#define bs_pll_ready_tx 0x10
235
236#define vphy_power_reg0 0x201
237
238#define vphy_calctl_reg 0x202
239#define bs_max_pll_rate BIT(12)
240
241#define vphy_reserve_reg 0x0e
242#define bs_phyctrl_frm_pin BIT(13)
243
244#define vsata_ctrl_reg 0x00
245#define bs_phy_pu_pll BIT(6)
246
247/*
248 * SDIO/eMMC definitions
249 */
250#define SDIO_BASE MVEBU_REG(0xD8000)
251
252#define SDIO_HOST_CTRL1_ADDR (SDIO_BASE + 0x28)
253#define SDIO_SDHC_FIFO_ADDR (SDIO_BASE + 0x12C)
254#define SDIO_CAP_12_ADDR (SDIO_BASE + 0x40)
255#define SDIO_ENDIAN_ADDR (SDIO_BASE + 0x1A4)
256#define SDIO_PHY_TIMING_ADDR (SDIO_BASE + 0x170)
257#define SDIO_PHY_PAD_CTRL0_ADDR (SDIO_BASE + 0x178)
258#define SDIO_DLL_RST_ADDR (SDIO_BASE + 0x148)
259
260#endif /* _COMPHY_A3700_H_ */