xref: /openbmc/u-boot/drivers/phy/marvell/comphy_cp110.c (revision e89acc4bf1bfa9239e03a737ed8967ffcc71f5f7)
1c0132f60SStefan Roese /*
2c0132f60SStefan Roese  * Copyright (C) 2015-2016 Marvell International Ltd.
3c0132f60SStefan Roese  *
4c0132f60SStefan Roese  * SPDX-License-Identifier:	GPL-2.0+
5c0132f60SStefan Roese  */
6c0132f60SStefan Roese 
7c0132f60SStefan Roese #include <common.h>
8c0132f60SStefan Roese #include <fdtdec.h>
9c0132f60SStefan Roese #include <asm/io.h>
10c0132f60SStefan Roese #include <asm/arch/cpu.h>
11c0132f60SStefan Roese #include <asm/arch/soc.h>
12c0132f60SStefan Roese 
13c0132f60SStefan Roese #include "comphy.h"
14c0132f60SStefan Roese #include "comphy_hpipe.h"
15c0132f60SStefan Roese #include "sata.h"
16c0132f60SStefan Roese #include "utmi_phy.h"
17c0132f60SStefan Roese 
18c0132f60SStefan Roese DECLARE_GLOBAL_DATA_PTR;
19c0132f60SStefan Roese 
20c0132f60SStefan Roese #define SD_ADDR(base, lane)			(base + 0x1000 * lane)
21c0132f60SStefan Roese #define HPIPE_ADDR(base, lane)			(SD_ADDR(base, lane) + 0x800)
22c0132f60SStefan Roese #define COMPHY_ADDR(base, lane)			(base + 0x28 * lane)
23c0132f60SStefan Roese 
24c0132f60SStefan Roese struct utmi_phy_data {
25c0132f60SStefan Roese 	void __iomem *utmi_base_addr;
26c0132f60SStefan Roese 	void __iomem *usb_cfg_addr;
27c0132f60SStefan Roese 	void __iomem *utmi_cfg_addr;
28c0132f60SStefan Roese 	u32 utmi_phy_port;
29c0132f60SStefan Roese };
30c0132f60SStefan Roese 
31c0132f60SStefan Roese /*
32c0132f60SStefan Roese  * For CP-110 we have 2 Selector registers "PHY Selectors",
33c0132f60SStefan Roese  * and "PIPE Selectors".
34c0132f60SStefan Roese  * PIPE selector include USB and PCIe options.
35c0132f60SStefan Roese  * PHY selector include the Ethernet and SATA options, every Ethernet
36c0132f60SStefan Roese  * option has different options, for example: serdes lane2 had option
37cb686454SStefan Roese  * Eth_port_0 that include (SGMII0, XAUI0, RXAUI0, SFI)
38c0132f60SStefan Roese  */
39c0132f60SStefan Roese struct comphy_mux_data cp110_comphy_phy_mux_data[] = {
40c0132f60SStefan Roese 	{4, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII2, 0x1}, /* Lane 0 */
41c0132f60SStefan Roese 	     {PHY_TYPE_XAUI2, 0x1}, {PHY_TYPE_SATA1, 0x4} } },
42c0132f60SStefan Roese 	{4, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII3, 0x1}, /* Lane 1 */
43c0132f60SStefan Roese 	     {PHY_TYPE_XAUI3, 0x1}, {PHY_TYPE_SATA0, 0x4} } },
44c0132f60SStefan Roese 	{6, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII0, 0x1}, /* Lane 2 */
45c0132f60SStefan Roese 	     {PHY_TYPE_XAUI0, 0x1}, {PHY_TYPE_RXAUI0, 0x1},
46cb686454SStefan Roese 	     {PHY_TYPE_SFI, 0x1}, {PHY_TYPE_SATA0, 0x4} } },
47c0132f60SStefan Roese 	{8, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII0, 0x1}, /* Lane 3 */
48c0132f60SStefan Roese 	     {PHY_TYPE_XAUI0, 0x1}, {PHY_TYPE_RXAUI0, 0x1},
49cb686454SStefan Roese 	     {PHY_TYPE_SFI, 0x1}, {PHY_TYPE_XAUI1, 0x1},
50c0132f60SStefan Roese 	     {PHY_TYPE_RXAUI1, 0x1}, {PHY_TYPE_SATA1, 0x4} } },
51c0132f60SStefan Roese 	{7, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII0, 0x2}, /* Lane 4 */
52cb686454SStefan Roese 	     {PHY_TYPE_XAUI0, 0x1}, {PHY_TYPE_RXAUI0, 0x1}, {PHY_TYPE_SFI, 0x1},
53c0132f60SStefan Roese 	     {PHY_TYPE_SGMII2, 0x1}, {PHY_TYPE_XAUI2, 0x1} } },
54c0132f60SStefan Roese 	{6, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_XAUI1, 0x1}, /* Lane 5 */
55c0132f60SStefan Roese 	     {PHY_TYPE_RXAUI1, 0x1}, {PHY_TYPE_SGMII3, 0x1},
56c0132f60SStefan Roese 	     {PHY_TYPE_XAUI3, 0x1}, {PHY_TYPE_SATA1, 0x4} } },
57c0132f60SStefan Roese };
58c0132f60SStefan Roese 
59c0132f60SStefan Roese struct comphy_mux_data cp110_comphy_pipe_mux_data[] = {
60c0132f60SStefan Roese 	{2, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_PEX0, 0x4} } }, /* Lane 0 */
61c0132f60SStefan Roese 	{4, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 1 */
62c0132f60SStefan Roese 	     {PHY_TYPE_USB3_HOST0, 0x1}, {PHY_TYPE_USB3_DEVICE, 0x2},
63c0132f60SStefan Roese 	     {PHY_TYPE_PEX0, 0x4} } },
64c0132f60SStefan Roese 	{3, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 2 */
65c0132f60SStefan Roese 	     {PHY_TYPE_USB3_HOST0, 0x1}, {PHY_TYPE_PEX0, 0x4} } },
66c0132f60SStefan Roese 	{3, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 3 */
67c0132f60SStefan Roese 	     {PHY_TYPE_USB3_HOST1, 0x1}, {PHY_TYPE_PEX0, 0x4} } },
68c0132f60SStefan Roese 	{4, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 4 */
69c0132f60SStefan Roese 	     {PHY_TYPE_USB3_HOST1, 0x1},
70c0132f60SStefan Roese 	     {PHY_TYPE_USB3_DEVICE, 0x2}, {PHY_TYPE_PEX1, 0x4} } },
71c0132f60SStefan Roese 	{2, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_PEX2, 0x4} } }, /* Lane 5 */
72c0132f60SStefan Roese };
73c0132f60SStefan Roese 
74c0132f60SStefan Roese static u32 polling_with_timeout(void __iomem *addr, u32 val,
75c0132f60SStefan Roese 				u32 mask, unsigned long usec_timout)
76c0132f60SStefan Roese {
77c0132f60SStefan Roese 	u32 data;
78c0132f60SStefan Roese 
79c0132f60SStefan Roese 	do {
80c0132f60SStefan Roese 		udelay(1);
81c0132f60SStefan Roese 		data = readl(addr) & mask;
82c0132f60SStefan Roese 	} while (data != val  && --usec_timout > 0);
83c0132f60SStefan Roese 
84c0132f60SStefan Roese 	if (usec_timout == 0)
85c0132f60SStefan Roese 		return data;
86c0132f60SStefan Roese 
87c0132f60SStefan Roese 	return 0;
88c0132f60SStefan Roese }
89c0132f60SStefan Roese 
907dda98e0SStefan Roese static int comphy_pcie_power_up(u32 lane, u32 pcie_width, bool clk_src,
917dda98e0SStefan Roese 				bool is_end_point, void __iomem *hpipe_base,
92c0132f60SStefan Roese 				void __iomem *comphy_base)
93c0132f60SStefan Roese {
94c0132f60SStefan Roese 	u32 mask, data, ret = 1;
95c0132f60SStefan Roese 	void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
96c0132f60SStefan Roese 	void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
97c0132f60SStefan Roese 	void __iomem *addr;
98c0132f60SStefan Roese 	u32 pcie_clk = 0; /* set input by default */
99c0132f60SStefan Roese 
100c0132f60SStefan Roese 	debug_enter();
101c0132f60SStefan Roese 
102c0132f60SStefan Roese 	/*
103c0132f60SStefan Roese 	 * ToDo:
104c0132f60SStefan Roese 	 * Add SAR (Sample-At-Reset) configuration for the PCIe clock
105c0132f60SStefan Roese 	 * direction. SAR code is currently not ported from Marvell
106c0132f60SStefan Roese 	 * U-Boot to mainline version.
107c0132f60SStefan Roese 	 *
108c0132f60SStefan Roese 	 * SerDes Lane 4/5 got the PCIe ref-clock #1,
109c0132f60SStefan Roese 	 * and SerDes Lane 0 got PCIe ref-clock #0
110c0132f60SStefan Roese 	 */
111c0132f60SStefan Roese 	debug("PCIe clock = %x\n", pcie_clk);
1127dda98e0SStefan Roese 	debug("PCIe RC    = %d\n", !is_end_point);
113c0132f60SStefan Roese 	debug("PCIe width = %d\n", pcie_width);
114c0132f60SStefan Roese 
115c0132f60SStefan Roese 	/* enable PCIe by4 and by2 */
116c0132f60SStefan Roese 	if (lane == 0) {
117c0132f60SStefan Roese 		if (pcie_width == 4) {
118c0132f60SStefan Roese 			reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
119c0132f60SStefan Roese 				0x1 << COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET,
120c0132f60SStefan Roese 				COMMON_PHY_SD_CTRL1_PCIE_X4_EN_MASK);
121c0132f60SStefan Roese 		} else if (pcie_width == 2) {
122c0132f60SStefan Roese 			reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
123c0132f60SStefan Roese 				0x1 << COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET,
124c0132f60SStefan Roese 				COMMON_PHY_SD_CTRL1_PCIE_X2_EN_MASK);
125c0132f60SStefan Roese 		}
126c0132f60SStefan Roese 	}
127c0132f60SStefan Roese 
128c0132f60SStefan Roese 	/*
129c0132f60SStefan Roese 	 * If PCIe clock is output and clock source from SerDes lane 5,
130c0132f60SStefan Roese 	 * we need to configure the clock-source MUX.
131c0132f60SStefan Roese 	 * By default, the clock source is from lane 4
132c0132f60SStefan Roese 	 */
133c0132f60SStefan Roese 	if (pcie_clk && clk_src && (lane == 5)) {
134c0132f60SStefan Roese 		reg_set((void __iomem *)DFX_DEV_GEN_CTRL12,
135c0132f60SStefan Roese 			0x3 << DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET,
136c0132f60SStefan Roese 			DFX_DEV_GEN_PCIE_CLK_SRC_MASK);
137c0132f60SStefan Roese 	}
138c0132f60SStefan Roese 
139c0132f60SStefan Roese 	debug("stage: RFU configurations - hard reset comphy\n");
140c0132f60SStefan Roese 	/* RFU configurations - hard reset comphy */
141c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_UP_MASK;
142c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
143c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
144c0132f60SStefan Roese 	data |= 0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
145c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
146c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
147c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
148c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
149c0132f60SStefan Roese 	mask |= COMMON_PHY_PHY_MODE_MASK;
150c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_PHY_MODE_OFFSET;
151c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
152c0132f60SStefan Roese 
153c0132f60SStefan Roese 	/* release from hard reset */
154c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
155c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
156c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
157c0132f60SStefan Roese 	data |= 0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
158c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
159c0132f60SStefan Roese 
160c0132f60SStefan Roese 	/* Wait 1ms - until band gap and ref clock ready */
161c0132f60SStefan Roese 	mdelay(1);
162c0132f60SStefan Roese 	/* Start comphy Configuration */
163c0132f60SStefan Roese 	debug("stage: Comphy configuration\n");
164c0132f60SStefan Roese 	/* Set PIPE soft reset */
165c0132f60SStefan Roese 	mask = HPIPE_RST_CLK_CTRL_PIPE_RST_MASK;
166c0132f60SStefan Roese 	data = 0x1 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET;
167c0132f60SStefan Roese 	/* Set PHY datapath width mode for V0 */
168c0132f60SStefan Roese 	mask |= HPIPE_RST_CLK_CTRL_FIXED_PCLK_MASK;
169c0132f60SStefan Roese 	data |= 0x1 << HPIPE_RST_CLK_CTRL_FIXED_PCLK_OFFSET;
170c0132f60SStefan Roese 	/* Set Data bus width USB mode for V0 */
171c0132f60SStefan Roese 	mask |= HPIPE_RST_CLK_CTRL_PIPE_WIDTH_MASK;
172c0132f60SStefan Roese 	data |= 0x0 << HPIPE_RST_CLK_CTRL_PIPE_WIDTH_OFFSET;
173c0132f60SStefan Roese 	/* Set CORE_CLK output frequency for 250Mhz */
174c0132f60SStefan Roese 	mask |= HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_MASK;
175c0132f60SStefan Roese 	data |= 0x0 << HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_OFFSET;
176c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG, data, mask);
177c0132f60SStefan Roese 	/* Set PLL ready delay for 0x2 */
178c0132f60SStefan Roese 	data = 0x2 << HPIPE_CLK_SRC_LO_PLL_RDY_DL_OFFSET;
179c0132f60SStefan Roese 	mask = HPIPE_CLK_SRC_LO_PLL_RDY_DL_MASK;
180c0132f60SStefan Roese 	if (pcie_width != 1) {
181c0132f60SStefan Roese 		data |= 0x1 << HPIPE_CLK_SRC_LO_BUNDLE_PERIOD_SEL_OFFSET;
182c0132f60SStefan Roese 		mask |= HPIPE_CLK_SRC_LO_BUNDLE_PERIOD_SEL_MASK;
183c0132f60SStefan Roese 		data |= 0x1 << HPIPE_CLK_SRC_LO_BUNDLE_PERIOD_SCALE_OFFSET;
184c0132f60SStefan Roese 		mask |= HPIPE_CLK_SRC_LO_BUNDLE_PERIOD_SCALE_MASK;
185c0132f60SStefan Roese 	}
186c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_CLK_SRC_LO_REG, data, mask);
187c0132f60SStefan Roese 
188c0132f60SStefan Roese 	/* Set PIPE mode interface to PCIe3 - 0x1  & set lane order */
189c0132f60SStefan Roese 	data = 0x1 << HPIPE_CLK_SRC_HI_MODE_PIPE_OFFSET;
190c0132f60SStefan Roese 	mask = HPIPE_CLK_SRC_HI_MODE_PIPE_MASK;
191c0132f60SStefan Roese 	if (pcie_width != 1) {
192c0132f60SStefan Roese 		mask |= HPIPE_CLK_SRC_HI_LANE_STRT_MASK;
193c0132f60SStefan Roese 		mask |= HPIPE_CLK_SRC_HI_LANE_MASTER_MASK;
194c0132f60SStefan Roese 		mask |= HPIPE_CLK_SRC_HI_LANE_BREAK_MASK;
195c0132f60SStefan Roese 		if (lane == 0) {
196c0132f60SStefan Roese 			data |= 0x1 << HPIPE_CLK_SRC_HI_LANE_STRT_OFFSET;
197c0132f60SStefan Roese 			data |= 0x1 << HPIPE_CLK_SRC_HI_LANE_MASTER_OFFSET;
198c0132f60SStefan Roese 		} else if (lane == (pcie_width - 1)) {
199c0132f60SStefan Roese 			data |= 0x1 << HPIPE_CLK_SRC_HI_LANE_BREAK_OFFSET;
200c0132f60SStefan Roese 		}
201c0132f60SStefan Roese 	}
202c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_CLK_SRC_HI_REG, data, mask);
203c0132f60SStefan Roese 	/* Config update polarity equalization */
204c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LANE_EQ_CFG1_REG,
205c0132f60SStefan Roese 		0x1 << HPIPE_CFG_UPDATE_POLARITY_OFFSET,
206c0132f60SStefan Roese 		HPIPE_CFG_UPDATE_POLARITY_MASK);
207c0132f60SStefan Roese 	/* Set PIPE version 4 to mode enable */
208c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_DFE_CTRL_28_REG,
209c0132f60SStefan Roese 		0x1 << HPIPE_DFE_CTRL_28_PIPE4_OFFSET,
210c0132f60SStefan Roese 		HPIPE_DFE_CTRL_28_PIPE4_MASK);
211c0132f60SStefan Roese 	/* TODO: check if pcie clock is output/input - for bringup use input*/
212c0132f60SStefan Roese 	/* Enable PIN clock 100M_125M */
213c0132f60SStefan Roese 	mask = 0;
214c0132f60SStefan Roese 	data = 0;
215c0132f60SStefan Roese 	/* Only if clock is output, configure the clock-source mux */
216c0132f60SStefan Roese 	if (pcie_clk) {
217c0132f60SStefan Roese 		mask |= HPIPE_MISC_CLK100M_125M_MASK;
218c0132f60SStefan Roese 		data |= 0x1 << HPIPE_MISC_CLK100M_125M_OFFSET;
219c0132f60SStefan Roese 	}
220c0132f60SStefan Roese 	/*
221c0132f60SStefan Roese 	 * Set PIN_TXDCLK_2X Clock Frequency Selection for outputs 500MHz
222c0132f60SStefan Roese 	 * clock
223c0132f60SStefan Roese 	 */
224c0132f60SStefan Roese 	mask |= HPIPE_MISC_TXDCLK_2X_MASK;
225c0132f60SStefan Roese 	data |= 0x0 << HPIPE_MISC_TXDCLK_2X_OFFSET;
226c0132f60SStefan Roese 	/* Enable 500MHz Clock */
227c0132f60SStefan Roese 	mask |= HPIPE_MISC_CLK500_EN_MASK;
228c0132f60SStefan Roese 	data |= 0x1 << HPIPE_MISC_CLK500_EN_OFFSET;
229c0132f60SStefan Roese 	if (pcie_clk) { /* output */
230c0132f60SStefan Roese 		/* Set reference clock comes from group 1 */
231c0132f60SStefan Roese 		mask |= HPIPE_MISC_REFCLK_SEL_MASK;
232c0132f60SStefan Roese 		data |= 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET;
233c0132f60SStefan Roese 	} else {
234c0132f60SStefan Roese 		/* Set reference clock comes from group 2 */
235c0132f60SStefan Roese 		mask |= HPIPE_MISC_REFCLK_SEL_MASK;
236c0132f60SStefan Roese 		data |= 0x1 << HPIPE_MISC_REFCLK_SEL_OFFSET;
237c0132f60SStefan Roese 	}
238c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_MISC_REG, data, mask);
239c0132f60SStefan Roese 	if (pcie_clk) { /* output */
240c0132f60SStefan Roese 		/* Set reference frequcency select - 0x2 for 25MHz*/
241c0132f60SStefan Roese 		mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
242c0132f60SStefan Roese 		data = 0x2 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
243c0132f60SStefan Roese 	} else {
244c0132f60SStefan Roese 		/* Set reference frequcency select - 0x0 for 100MHz*/
245c0132f60SStefan Roese 		mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
246c0132f60SStefan Roese 		data = 0x0 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
247c0132f60SStefan Roese 	}
248c0132f60SStefan Roese 	/* Set PHY mode to PCIe */
249c0132f60SStefan Roese 	mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
250c0132f60SStefan Roese 	data |= 0x3 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
251c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
252c0132f60SStefan Roese 
253c0132f60SStefan Roese 	/* ref clock alignment */
254c0132f60SStefan Roese 	if (pcie_width != 1) {
255c0132f60SStefan Roese 		mask = HPIPE_LANE_ALIGN_OFF_MASK;
256c0132f60SStefan Roese 		data = 0x0 << HPIPE_LANE_ALIGN_OFF_OFFSET;
257c0132f60SStefan Roese 		reg_set(hpipe_addr + HPIPE_LANE_ALIGN_REG, data, mask);
258c0132f60SStefan Roese 	}
259c0132f60SStefan Roese 
260c0132f60SStefan Roese 	/*
261c0132f60SStefan Roese 	 * Set the amount of time spent in the LoZ state - set for 0x7 only if
262c0132f60SStefan Roese 	 * the PCIe clock is output
263c0132f60SStefan Roese 	 */
264c0132f60SStefan Roese 	if (pcie_clk) {
265c0132f60SStefan Roese 		reg_set(hpipe_addr + HPIPE_GLOBAL_PM_CTRL,
266c0132f60SStefan Roese 			0x7 << HPIPE_GLOBAL_PM_RXDLOZ_WAIT_OFFSET,
267c0132f60SStefan Roese 			HPIPE_GLOBAL_PM_RXDLOZ_WAIT_MASK);
268c0132f60SStefan Roese 	}
269c0132f60SStefan Roese 
270c0132f60SStefan Roese 	/* Set Maximal PHY Generation Setting(8Gbps) */
271c0132f60SStefan Roese 	mask = HPIPE_INTERFACE_GEN_MAX_MASK;
272c0132f60SStefan Roese 	data = 0x2 << HPIPE_INTERFACE_GEN_MAX_OFFSET;
273c0132f60SStefan Roese 	/* Set Link Train Mode (Tx training control pins are used) */
274c0132f60SStefan Roese 	mask |= HPIPE_INTERFACE_LINK_TRAIN_MASK;
275c0132f60SStefan Roese 	data |= 0x1 << HPIPE_INTERFACE_LINK_TRAIN_OFFSET;
276c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_INTERFACE_REG, data, mask);
277c0132f60SStefan Roese 
278c0132f60SStefan Roese 	/* Set Idle_sync enable */
279c0132f60SStefan Roese 	mask = HPIPE_PCIE_IDLE_SYNC_MASK;
280c0132f60SStefan Roese 	data = 0x1 << HPIPE_PCIE_IDLE_SYNC_OFFSET;
281c0132f60SStefan Roese 	/* Select bits for PCIE Gen3(32bit) */
282c0132f60SStefan Roese 	mask |= HPIPE_PCIE_SEL_BITS_MASK;
283c0132f60SStefan Roese 	data |= 0x2 << HPIPE_PCIE_SEL_BITS_OFFSET;
284c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PCIE_REG0, data, mask);
285c0132f60SStefan Roese 
286c0132f60SStefan Roese 	/* Enable Tx_adapt_g1 */
287c0132f60SStefan Roese 	mask = HPIPE_TX_TRAIN_CTRL_G1_MASK;
288c0132f60SStefan Roese 	data = 0x1 << HPIPE_TX_TRAIN_CTRL_G1_OFFSET;
289c0132f60SStefan Roese 	/* Enable Tx_adapt_gn1 */
290c0132f60SStefan Roese 	mask |= HPIPE_TX_TRAIN_CTRL_GN1_MASK;
291c0132f60SStefan Roese 	data |= 0x1 << HPIPE_TX_TRAIN_CTRL_GN1_OFFSET;
292c0132f60SStefan Roese 	/* Disable Tx_adapt_g0 */
293c0132f60SStefan Roese 	mask |= HPIPE_TX_TRAIN_CTRL_G0_MASK;
294c0132f60SStefan Roese 	data |= 0x0 << HPIPE_TX_TRAIN_CTRL_G0_OFFSET;
295c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_TRAIN_CTRL_REG, data, mask);
296c0132f60SStefan Roese 
297c0132f60SStefan Roese 	/* Set reg_tx_train_chk_init */
298c0132f60SStefan Roese 	mask = HPIPE_TX_TRAIN_CHK_INIT_MASK;
299c0132f60SStefan Roese 	data = 0x0 << HPIPE_TX_TRAIN_CHK_INIT_OFFSET;
300c0132f60SStefan Roese 	/* Enable TX_COE_FM_PIN_PCIE3_EN */
301c0132f60SStefan Roese 	mask |= HPIPE_TX_TRAIN_COE_FM_PIN_PCIE3_MASK;
302c0132f60SStefan Roese 	data |= 0x1 << HPIPE_TX_TRAIN_COE_FM_PIN_PCIE3_OFFSET;
303c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_TRAIN_REG, data, mask);
304c0132f60SStefan Roese 
305c0132f60SStefan Roese 	debug("stage: TRx training parameters\n");
306c0132f60SStefan Roese 	/* Set Preset sweep configurations */
307c0132f60SStefan Roese 	mask = HPIPE_TX_TX_STATUS_CHECK_MODE_MASK;
308c0132f60SStefan Roese 	data = 0x1 << HPIPE_TX_STATUS_CHECK_MODE_OFFSET;
309c0132f60SStefan Roese 
310c0132f60SStefan Roese 	mask |= HPIPE_TX_NUM_OF_PRESET_MASK;
311c0132f60SStefan Roese 	data |= 0x7 << HPIPE_TX_NUM_OF_PRESET_OFFSET;
312c0132f60SStefan Roese 
313c0132f60SStefan Roese 	mask |= HPIPE_TX_SWEEP_PRESET_EN_MASK;
314c0132f60SStefan Roese 	data |= 0x1 << HPIPE_TX_SWEEP_PRESET_EN_OFFSET;
315c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_TRAIN_CTRL_11_REG, data, mask);
316c0132f60SStefan Roese 
317c0132f60SStefan Roese 	/* Tx train start configuration */
318c0132f60SStefan Roese 	mask = HPIPE_TX_TRAIN_START_SQ_EN_MASK;
319c0132f60SStefan Roese 	data = 0x1 << HPIPE_TX_TRAIN_START_SQ_EN_OFFSET;
320c0132f60SStefan Roese 
321c0132f60SStefan Roese 	mask |= HPIPE_TX_TRAIN_START_FRM_DET_EN_MASK;
322c0132f60SStefan Roese 	data |= 0x0 << HPIPE_TX_TRAIN_START_FRM_DET_EN_OFFSET;
323c0132f60SStefan Roese 
324c0132f60SStefan Roese 	mask |= HPIPE_TX_TRAIN_START_FRM_LOCK_EN_MASK;
325c0132f60SStefan Roese 	data |= 0x0 << HPIPE_TX_TRAIN_START_FRM_LOCK_EN_OFFSET;
326c0132f60SStefan Roese 
327c0132f60SStefan Roese 	mask |= HPIPE_TX_TRAIN_WAIT_TIME_EN_MASK;
328c0132f60SStefan Roese 	data |= 0x1 << HPIPE_TX_TRAIN_WAIT_TIME_EN_OFFSET;
329c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_TRAIN_CTRL_5_REG, data, mask);
330c0132f60SStefan Roese 
331c0132f60SStefan Roese 	/* Enable Tx train P2P */
332c0132f60SStefan Roese 	mask = HPIPE_TX_TRAIN_P2P_HOLD_MASK;
333c0132f60SStefan Roese 	data = 0x1 << HPIPE_TX_TRAIN_P2P_HOLD_OFFSET;
334c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_TRAIN_CTRL_0_REG, data, mask);
335c0132f60SStefan Roese 
336c0132f60SStefan Roese 	/* Configure Tx train timeout */
337c0132f60SStefan Roese 	mask = HPIPE_TRX_TRAIN_TIMER_MASK;
338c0132f60SStefan Roese 	data = 0x17 << HPIPE_TRX_TRAIN_TIMER_OFFSET;
339c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_TRAIN_CTRL_4_REG, data, mask);
340c0132f60SStefan Roese 
341c0132f60SStefan Roese 	/* Disable G0/G1/GN1 adaptation */
342c0132f60SStefan Roese 	mask = HPIPE_TX_TRAIN_CTRL_G1_MASK | HPIPE_TX_TRAIN_CTRL_GN1_MASK
343c0132f60SStefan Roese 		| HPIPE_TX_TRAIN_CTRL_G0_OFFSET;
344c0132f60SStefan Roese 	data = 0;
345c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_TRAIN_CTRL_REG, data, mask);
346c0132f60SStefan Roese 
347c0132f60SStefan Roese 	/* Disable DTL frequency loop */
348c0132f60SStefan Roese 	mask = HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK;
349c0132f60SStefan Roese 	data = 0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET;
350c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, data, mask);
351c0132f60SStefan Roese 
352c0132f60SStefan Roese 	/* Configure G3 DFE */
353c0132f60SStefan Roese 	mask = HPIPE_G3_DFE_RES_MASK;
354c0132f60SStefan Roese 	data = 0x3 << HPIPE_G3_DFE_RES_OFFSET;
355c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G3_SETTING_4_REG, data, mask);
356c0132f60SStefan Roese 
357c0132f60SStefan Roese 	/* Force DFE resolution (use GEN table value) */
358c0132f60SStefan Roese 	mask = HPIPE_DFE_RES_FORCE_MASK;
359c0132f60SStefan Roese 	data = 0x1 << HPIPE_DFE_RES_FORCE_OFFSET;
360c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_DFE_REG0,  data, mask);
361c0132f60SStefan Roese 
362c0132f60SStefan Roese 	/* Configure initial and final coefficient value for receiver */
363c0132f60SStefan Roese 	mask = HPIPE_G3_RX_SELMUPI_MASK;
364c0132f60SStefan Roese 	data = 0x1 << HPIPE_G3_RX_SELMUPI_OFFSET;
365c0132f60SStefan Roese 
366c0132f60SStefan Roese 	mask |= HPIPE_G3_RX_SELMUPF_MASK;
367c0132f60SStefan Roese 	data |= 0x1 << HPIPE_G3_RX_SELMUPF_OFFSET;
368c0132f60SStefan Roese 
369c0132f60SStefan Roese 	mask |= HPIPE_G3_SETTING_BIT_MASK;
370c0132f60SStefan Roese 	data |= 0x0 << HPIPE_G3_SETTING_BIT_OFFSET;
371c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G3_SETTINGS_1_REG,  data, mask);
372c0132f60SStefan Roese 
373c0132f60SStefan Roese 	/* Trigger sampler enable pulse */
374c0132f60SStefan Roese 	mask = HPIPE_SMAPLER_MASK;
375c0132f60SStefan Roese 	data = 0x1 << HPIPE_SMAPLER_OFFSET;
376c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_SAMPLER_N_PROC_CALIB_CTRL_REG, data, mask);
377c0132f60SStefan Roese 	udelay(5);
378c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_SAMPLER_N_PROC_CALIB_CTRL_REG, 0, mask);
379c0132f60SStefan Roese 
380c0132f60SStefan Roese 	/* FFE resistor tuning for different bandwidth  */
381c0132f60SStefan Roese 	mask = HPIPE_G3_FFE_DEG_RES_LEVEL_MASK;
382c0132f60SStefan Roese 	data = 0x1 << HPIPE_G3_FFE_DEG_RES_LEVEL_OFFSET;
383c0132f60SStefan Roese 
384c0132f60SStefan Roese 	mask |= HPIPE_G3_FFE_LOAD_RES_LEVEL_MASK;
385c0132f60SStefan Roese 	data |= 0x1 << HPIPE_G3_FFE_LOAD_RES_LEVEL_OFFSET;
386c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G3_SETTING_3_REG, data, mask);
387c0132f60SStefan Roese 
3887dda98e0SStefan Roese 	if (!is_end_point) {
389c0132f60SStefan Roese 		/* Set phy in root complex mode */
390c0132f60SStefan Roese 		mask = HPIPE_CFG_PHY_RC_EP_MASK;
391c0132f60SStefan Roese 		data = 0x1 << HPIPE_CFG_PHY_RC_EP_OFFSET;
392c0132f60SStefan Roese 		reg_set(hpipe_addr + HPIPE_LANE_EQU_CONFIG_0_REG, data, mask);
3937dda98e0SStefan Roese 	}
394c0132f60SStefan Roese 
395c0132f60SStefan Roese 	debug("stage: Comphy power up\n");
396c0132f60SStefan Roese 
397c0132f60SStefan Roese 	/*
398c0132f60SStefan Roese 	 * For PCIe by4 or by2 - release from reset only after finish to
399c0132f60SStefan Roese 	 * configure all lanes
400c0132f60SStefan Roese 	 */
401c0132f60SStefan Roese 	if ((pcie_width == 1) || (lane == (pcie_width - 1))) {
402c0132f60SStefan Roese 		u32 i, start_lane, end_lane;
403c0132f60SStefan Roese 
404c0132f60SStefan Roese 		if (pcie_width != 1) {
405c0132f60SStefan Roese 			/* allows writing to all lanes in one write */
406c0132f60SStefan Roese 			reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
407c0132f60SStefan Roese 				0x0 <<
408c0132f60SStefan Roese 				COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_OFFSET,
409c0132f60SStefan Roese 				COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_MASK);
410c0132f60SStefan Roese 			start_lane = 0;
411c0132f60SStefan Roese 			end_lane = pcie_width;
412c0132f60SStefan Roese 
413c0132f60SStefan Roese 			/*
414c0132f60SStefan Roese 			 * Release from PIPE soft reset
415c0132f60SStefan Roese 			 * for PCIe by4 or by2 - release from soft reset
416c0132f60SStefan Roese 			 * all lanes - can't use read modify write
417c0132f60SStefan Roese 			 */
418c0132f60SStefan Roese 			reg_set(HPIPE_ADDR(hpipe_base, 0) +
419c0132f60SStefan Roese 				HPIPE_RST_CLK_CTRL_REG, 0x24, 0xffffffff);
420c0132f60SStefan Roese 		} else {
421c0132f60SStefan Roese 			start_lane = lane;
422c0132f60SStefan Roese 			end_lane = lane + 1;
423c0132f60SStefan Roese 
424c0132f60SStefan Roese 			/*
425c0132f60SStefan Roese 			 * Release from PIPE soft reset
426c0132f60SStefan Roese 			 * for PCIe by4 or by2 - release from soft reset
427c0132f60SStefan Roese 			 * all lanes
428c0132f60SStefan Roese 			 */
429c0132f60SStefan Roese 			reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG,
430c0132f60SStefan Roese 				0x0 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET,
431c0132f60SStefan Roese 				HPIPE_RST_CLK_CTRL_PIPE_RST_MASK);
432c0132f60SStefan Roese 		}
433c0132f60SStefan Roese 
434c0132f60SStefan Roese 
435c0132f60SStefan Roese 		if (pcie_width != 1) {
436c0132f60SStefan Roese 			/* disable writing to all lanes with one write */
437c0132f60SStefan Roese 			reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
438c0132f60SStefan Roese 				0x3210 <<
439c0132f60SStefan Roese 				COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_OFFSET,
440c0132f60SStefan Roese 				COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_MASK);
441c0132f60SStefan Roese 		}
442c0132f60SStefan Roese 
443c0132f60SStefan Roese 		debug("stage: Check PLL\n");
444c0132f60SStefan Roese 		/* Read lane status */
445c0132f60SStefan Roese 		for (i = start_lane; i < end_lane; i++) {
446c0132f60SStefan Roese 			addr = HPIPE_ADDR(hpipe_base, i) +
447c0132f60SStefan Roese 				HPIPE_LANE_STATUS1_REG;
448c0132f60SStefan Roese 			data = HPIPE_LANE_STATUS1_PCLK_EN_MASK;
449c0132f60SStefan Roese 			mask = data;
450c0132f60SStefan Roese 			data = polling_with_timeout(addr, data, mask, 15000);
451c0132f60SStefan Roese 			if (data != 0) {
452c0132f60SStefan Roese 				debug("Read from reg = %p - value = 0x%x\n",
453c0132f60SStefan Roese 				      hpipe_addr + HPIPE_LANE_STATUS1_REG,
454c0132f60SStefan Roese 				      data);
455c0132f60SStefan Roese 				error("HPIPE_LANE_STATUS1_PCLK_EN_MASK is 0\n");
456c0132f60SStefan Roese 				ret = 0;
457c0132f60SStefan Roese 			}
458c0132f60SStefan Roese 		}
459c0132f60SStefan Roese 	}
460c0132f60SStefan Roese 
461c0132f60SStefan Roese 	debug_exit();
462c0132f60SStefan Roese 	return ret;
463c0132f60SStefan Roese }
464c0132f60SStefan Roese 
465c0132f60SStefan Roese static int comphy_usb3_power_up(u32 lane, void __iomem *hpipe_base,
466c0132f60SStefan Roese 				void __iomem *comphy_base)
467c0132f60SStefan Roese {
468c0132f60SStefan Roese 	u32 mask, data, ret = 1;
469c0132f60SStefan Roese 	void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
470c0132f60SStefan Roese 	void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
471c0132f60SStefan Roese 	void __iomem *addr;
472c0132f60SStefan Roese 
473c0132f60SStefan Roese 	debug_enter();
474c0132f60SStefan Roese 	debug("stage: RFU configurations - hard reset comphy\n");
475c0132f60SStefan Roese 	/* RFU configurations - hard reset comphy */
476c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_UP_MASK;
477c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
478c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
479c0132f60SStefan Roese 	data |= 0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
480c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
481c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
482c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
483c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
484c0132f60SStefan Roese 	mask |= COMMON_PHY_PHY_MODE_MASK;
485c0132f60SStefan Roese 	data |= 0x1 << COMMON_PHY_PHY_MODE_OFFSET;
486c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
487c0132f60SStefan Roese 
488c0132f60SStefan Roese 	/* release from hard reset */
489c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
490c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
491c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
492c0132f60SStefan Roese 	data |= 0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
493c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
494c0132f60SStefan Roese 
495c0132f60SStefan Roese 	/* Wait 1ms - until band gap and ref clock ready */
496c0132f60SStefan Roese 	mdelay(1);
497c0132f60SStefan Roese 
498c0132f60SStefan Roese 	/* Start comphy Configuration */
499c0132f60SStefan Roese 	debug("stage: Comphy configuration\n");
500c0132f60SStefan Roese 	/* Set PIPE soft reset */
501c0132f60SStefan Roese 	mask = HPIPE_RST_CLK_CTRL_PIPE_RST_MASK;
502c0132f60SStefan Roese 	data = 0x1 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET;
503c0132f60SStefan Roese 	/* Set PHY datapath width mode for V0 */
504c0132f60SStefan Roese 	mask |= HPIPE_RST_CLK_CTRL_FIXED_PCLK_MASK;
505c0132f60SStefan Roese 	data |= 0x0 << HPIPE_RST_CLK_CTRL_FIXED_PCLK_OFFSET;
506c0132f60SStefan Roese 	/* Set Data bus width USB mode for V0 */
507c0132f60SStefan Roese 	mask |= HPIPE_RST_CLK_CTRL_PIPE_WIDTH_MASK;
508c0132f60SStefan Roese 	data |= 0x0 << HPIPE_RST_CLK_CTRL_PIPE_WIDTH_OFFSET;
509c0132f60SStefan Roese 	/* Set CORE_CLK output frequency for 250Mhz */
510c0132f60SStefan Roese 	mask |= HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_MASK;
511c0132f60SStefan Roese 	data |= 0x0 << HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_OFFSET;
512c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG, data, mask);
513c0132f60SStefan Roese 	/* Set PLL ready delay for 0x2 */
514c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_CLK_SRC_LO_REG,
515c0132f60SStefan Roese 		0x2 << HPIPE_CLK_SRC_LO_PLL_RDY_DL_OFFSET,
516c0132f60SStefan Roese 		HPIPE_CLK_SRC_LO_PLL_RDY_DL_MASK);
517c0132f60SStefan Roese 	/* Set reference clock to come from group 1 - 25Mhz */
518c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_MISC_REG,
519c0132f60SStefan Roese 		0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET,
520c0132f60SStefan Roese 		HPIPE_MISC_REFCLK_SEL_MASK);
521c0132f60SStefan Roese 	/* Set reference frequcency select - 0x2 */
522c0132f60SStefan Roese 	mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
523c0132f60SStefan Roese 	data = 0x2 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
524c0132f60SStefan Roese 	/* Set PHY mode to USB - 0x5 */
525c0132f60SStefan Roese 	mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
526c0132f60SStefan Roese 	data |= 0x5 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
527c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
528c0132f60SStefan Roese 	/* Set the amount of time spent in the LoZ state - set for 0x7 */
529c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_GLOBAL_PM_CTRL,
530c0132f60SStefan Roese 		0x7 << HPIPE_GLOBAL_PM_RXDLOZ_WAIT_OFFSET,
531c0132f60SStefan Roese 		HPIPE_GLOBAL_PM_RXDLOZ_WAIT_MASK);
532c0132f60SStefan Roese 	/* Set max PHY generation setting - 5Gbps */
533c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_INTERFACE_REG,
534c0132f60SStefan Roese 		0x1 << HPIPE_INTERFACE_GEN_MAX_OFFSET,
535c0132f60SStefan Roese 		HPIPE_INTERFACE_GEN_MAX_MASK);
536c0132f60SStefan Roese 	/* Set select data width 20Bit (SEL_BITS[2:0]) */
537c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LOOPBACK_REG,
538c0132f60SStefan Roese 		0x1 << HPIPE_LOOPBACK_SEL_OFFSET,
539c0132f60SStefan Roese 		HPIPE_LOOPBACK_SEL_MASK);
540c0132f60SStefan Roese 	/* select de-emphasize 3.5db */
541c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LANE_CONFIG0_REG,
542c0132f60SStefan Roese 		0x1 << HPIPE_LANE_CONFIG0_TXDEEMPH0_OFFSET,
543c0132f60SStefan Roese 		HPIPE_LANE_CONFIG0_TXDEEMPH0_MASK);
544c0132f60SStefan Roese 	/* override tx margining from the MAC */
545c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TST_MODE_CTRL_REG,
546c0132f60SStefan Roese 		0x1 << HPIPE_TST_MODE_CTRL_MODE_MARGIN_OFFSET,
547c0132f60SStefan Roese 		HPIPE_TST_MODE_CTRL_MODE_MARGIN_MASK);
548c0132f60SStefan Roese 
549c0132f60SStefan Roese 	/* Start analog paramters from ETP(HW) */
550c0132f60SStefan Roese 	debug("stage: Analog paramters from ETP(HW)\n");
551c0132f60SStefan Roese 	/* Set Pin DFE_PAT_DIS -> Bit[1]: PIN_DFE_PAT_DIS = 0x0 */
552c0132f60SStefan Roese 	mask = HPIPE_LANE_CFG4_DFE_CTRL_MASK;
553c0132f60SStefan Roese 	data = 0x1 << HPIPE_LANE_CFG4_DFE_CTRL_OFFSET;
554c0132f60SStefan Roese 	/* Set Override PHY DFE control pins for 0x1 */
555c0132f60SStefan Roese 	mask |= HPIPE_LANE_CFG4_DFE_OVER_MASK;
556c0132f60SStefan Roese 	data |= 0x1 << HPIPE_LANE_CFG4_DFE_OVER_OFFSET;
557c0132f60SStefan Roese 	/* Set Spread Spectrum Clock Enable fot 0x1 */
558c0132f60SStefan Roese 	mask |= HPIPE_LANE_CFG4_SSC_CTRL_MASK;
559c0132f60SStefan Roese 	data |= 0x1 << HPIPE_LANE_CFG4_SSC_CTRL_OFFSET;
560c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LANE_CFG4_REG, data, mask);
561c0132f60SStefan Roese 	/* End of analog parameters */
562c0132f60SStefan Roese 
563c0132f60SStefan Roese 	debug("stage: Comphy power up\n");
564c0132f60SStefan Roese 	/* Release from PIPE soft reset */
565c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG,
566c0132f60SStefan Roese 		0x0 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET,
567c0132f60SStefan Roese 		HPIPE_RST_CLK_CTRL_PIPE_RST_MASK);
568c0132f60SStefan Roese 
569c0132f60SStefan Roese 	/* wait 15ms - for comphy calibration done */
570c0132f60SStefan Roese 	debug("stage: Check PLL\n");
571c0132f60SStefan Roese 	/* Read lane status */
572c0132f60SStefan Roese 	addr = hpipe_addr + HPIPE_LANE_STATUS1_REG;
573c0132f60SStefan Roese 	data = HPIPE_LANE_STATUS1_PCLK_EN_MASK;
574c0132f60SStefan Roese 	mask = data;
575c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 15000);
576c0132f60SStefan Roese 	if (data != 0) {
577c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n",
578c0132f60SStefan Roese 		      hpipe_addr + HPIPE_LANE_STATUS1_REG, data);
579c0132f60SStefan Roese 		error("HPIPE_LANE_STATUS1_PCLK_EN_MASK is 0\n");
580c0132f60SStefan Roese 		ret = 0;
581c0132f60SStefan Roese 	}
582c0132f60SStefan Roese 
583c0132f60SStefan Roese 	debug_exit();
584c0132f60SStefan Roese 	return ret;
585c0132f60SStefan Roese }
586c0132f60SStefan Roese 
587c0132f60SStefan Roese static int comphy_sata_power_up(u32 lane, void __iomem *hpipe_base,
588c0132f60SStefan Roese 				void __iomem *comphy_base, int comphy_index)
589c0132f60SStefan Roese {
590c0132f60SStefan Roese 	u32 mask, data, i, ret = 1;
591c0132f60SStefan Roese 	void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
592c0132f60SStefan Roese 	void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane);
593c0132f60SStefan Roese 	void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
594c0132f60SStefan Roese 	void __iomem *addr;
595c0132f60SStefan Roese 	void __iomem *sata_base = NULL;
596c0132f60SStefan Roese 	int sata_node = -1; /* Set to -1 in order to read the first sata node */
597c0132f60SStefan Roese 
598c0132f60SStefan Roese 	debug_enter();
599c0132f60SStefan Roese 
600c0132f60SStefan Roese 	/*
601c0132f60SStefan Roese 	 * Assumption - each CP has only one SATA controller
602c0132f60SStefan Roese 	 * Calling fdt_node_offset_by_compatible first time (with sata_node = -1
603c0132f60SStefan Roese 	 * will return the first node always.
604c0132f60SStefan Roese 	 * In order to parse each CPs SATA node, fdt_node_offset_by_compatible
605c0132f60SStefan Roese 	 * must be called again (according to the CP id)
606c0132f60SStefan Roese 	 */
607c0132f60SStefan Roese 	for (i = 0; i < (comphy_index + 1); i++)
608c0132f60SStefan Roese 		sata_node = fdt_node_offset_by_compatible(
609c0132f60SStefan Roese 			gd->fdt_blob, sata_node, "marvell,armada-8k-ahci");
610c0132f60SStefan Roese 
611c0132f60SStefan Roese 	if (sata_node == 0) {
612c0132f60SStefan Roese 		error("SATA node not found in FDT\n");
613c0132f60SStefan Roese 		return 0;
614c0132f60SStefan Roese 	}
615c0132f60SStefan Roese 
616c0132f60SStefan Roese 	sata_base = (void __iomem *)fdtdec_get_addr_size_auto_noparent(
617c0132f60SStefan Roese 		gd->fdt_blob, sata_node, "reg", 0, NULL, true);
618c0132f60SStefan Roese 	if (sata_base == NULL) {
619c0132f60SStefan Roese 		error("SATA address not found in FDT\n");
620c0132f60SStefan Roese 		return 0;
621c0132f60SStefan Roese 	}
622c0132f60SStefan Roese 
623c0132f60SStefan Roese 	debug("SATA address found in FDT %p\n", sata_base);
624c0132f60SStefan Roese 
625c0132f60SStefan Roese 	debug("stage: MAC configuration - power down comphy\n");
626c0132f60SStefan Roese 	/*
627c0132f60SStefan Roese 	 * MAC configuration powe down comphy use indirect address for
628c0132f60SStefan Roese 	 * vendor spesific SATA control register
629c0132f60SStefan Roese 	 */
630c0132f60SStefan Roese 	reg_set(sata_base + SATA3_VENDOR_ADDRESS,
631c0132f60SStefan Roese 		SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET,
632c0132f60SStefan Roese 		SATA3_VENDOR_ADDR_MASK);
633c0132f60SStefan Roese 	/* SATA 0 power down */
634c0132f60SStefan Roese 	mask = SATA3_CTRL_SATA0_PD_MASK;
635c0132f60SStefan Roese 	data = 0x1 << SATA3_CTRL_SATA0_PD_OFFSET;
636c0132f60SStefan Roese 	/* SATA 1 power down */
637c0132f60SStefan Roese 	mask |= SATA3_CTRL_SATA1_PD_MASK;
638c0132f60SStefan Roese 	data |= 0x1 << SATA3_CTRL_SATA1_PD_OFFSET;
639c0132f60SStefan Roese 	/* SATA SSU disable */
640c0132f60SStefan Roese 	mask |= SATA3_CTRL_SATA1_ENABLE_MASK;
641c0132f60SStefan Roese 	data |= 0x0 << SATA3_CTRL_SATA1_ENABLE_OFFSET;
642c0132f60SStefan Roese 	/* SATA port 1 disable */
643c0132f60SStefan Roese 	mask |= SATA3_CTRL_SATA_SSU_MASK;
644c0132f60SStefan Roese 	data |= 0x0 << SATA3_CTRL_SATA_SSU_OFFSET;
645c0132f60SStefan Roese 	reg_set(sata_base + SATA3_VENDOR_DATA, data, mask);
646c0132f60SStefan Roese 
647c0132f60SStefan Roese 	debug("stage: RFU configurations - hard reset comphy\n");
648c0132f60SStefan Roese 	/* RFU configurations - hard reset comphy */
649c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_UP_MASK;
650c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
651c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
652c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
653c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
654c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
655c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
656c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
657c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
658c0132f60SStefan Roese 
659c0132f60SStefan Roese 	/* Set select data  width 40Bit - SATA mode only */
660c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG6_REG,
661c0132f60SStefan Roese 		0x1 << COMMON_PHY_CFG6_IF_40_SEL_OFFSET,
662c0132f60SStefan Roese 		COMMON_PHY_CFG6_IF_40_SEL_MASK);
663c0132f60SStefan Roese 
664c0132f60SStefan Roese 	/* release from hard reset in SD external */
665c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
666c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
667c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
668c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
669c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
670c0132f60SStefan Roese 
671c0132f60SStefan Roese 	/* Wait 1ms - until band gap and ref clock ready */
672c0132f60SStefan Roese 	mdelay(1);
673c0132f60SStefan Roese 
674c0132f60SStefan Roese 	debug("stage: Comphy configuration\n");
675c0132f60SStefan Roese 	/* Start comphy Configuration */
676c0132f60SStefan Roese 	/* Set reference clock to comes from group 1 - choose 25Mhz */
677c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_MISC_REG,
678c0132f60SStefan Roese 		0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET,
679c0132f60SStefan Roese 		HPIPE_MISC_REFCLK_SEL_MASK);
680c0132f60SStefan Roese 	/* Reference frequency select set 1 (for SATA = 25Mhz) */
681c0132f60SStefan Roese 	mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
682c0132f60SStefan Roese 	data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
683c0132f60SStefan Roese 	/* PHY mode select (set SATA = 0x0 */
684c0132f60SStefan Roese 	mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
685c0132f60SStefan Roese 	data |= 0x0 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
686c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
687c0132f60SStefan Roese 	/* Set max PHY generation setting - 6Gbps */
688c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_INTERFACE_REG,
689c0132f60SStefan Roese 		0x2 << HPIPE_INTERFACE_GEN_MAX_OFFSET,
690c0132f60SStefan Roese 		HPIPE_INTERFACE_GEN_MAX_MASK);
691c0132f60SStefan Roese 	/* Set select data  width 40Bit (SEL_BITS[2:0]) */
692c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LOOPBACK_REG,
693c0132f60SStefan Roese 		0x2 << HPIPE_LOOPBACK_SEL_OFFSET, HPIPE_LOOPBACK_SEL_MASK);
694c0132f60SStefan Roese 
695c0132f60SStefan Roese 	debug("stage: Analog paramters from ETP(HW)\n");
696c0132f60SStefan Roese 	/*
697c0132f60SStefan Roese 	 * TODO: Set analog paramters from ETP(HW) - for now use the
698c0132f60SStefan Roese 	 * default datas
699c0132f60SStefan Roese 	 */
700c0132f60SStefan Roese 
701c0132f60SStefan Roese 	/* DFE reset sequence */
702c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_REG,
703c0132f60SStefan Roese 		0x1 << HPIPE_PWR_CTR_RST_DFE_OFFSET,
704c0132f60SStefan Roese 		HPIPE_PWR_CTR_RST_DFE_MASK);
705c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_REG,
706c0132f60SStefan Roese 		0x0 << HPIPE_PWR_CTR_RST_DFE_OFFSET,
707c0132f60SStefan Roese 		HPIPE_PWR_CTR_RST_DFE_MASK);
708c0132f60SStefan Roese 	/* SW reset for interupt logic */
709c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_REG,
710c0132f60SStefan Roese 		0x1 << HPIPE_PWR_CTR_SFT_RST_OFFSET,
711c0132f60SStefan Roese 		HPIPE_PWR_CTR_SFT_RST_MASK);
712c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_REG,
713c0132f60SStefan Roese 		0x0 << HPIPE_PWR_CTR_SFT_RST_OFFSET,
714c0132f60SStefan Roese 		HPIPE_PWR_CTR_SFT_RST_MASK);
715c0132f60SStefan Roese 
716c0132f60SStefan Roese 	debug("stage: Comphy power up\n");
717c0132f60SStefan Roese 	/*
718c0132f60SStefan Roese 	 * MAC configuration power up comphy - power up PLL/TX/RX
719c0132f60SStefan Roese 	 * use indirect address for vendor spesific SATA control register
720c0132f60SStefan Roese 	 */
721c0132f60SStefan Roese 	reg_set(sata_base + SATA3_VENDOR_ADDRESS,
722c0132f60SStefan Roese 		SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET,
723c0132f60SStefan Roese 		SATA3_VENDOR_ADDR_MASK);
724c0132f60SStefan Roese 	/* SATA 0 power up */
725c0132f60SStefan Roese 	mask = SATA3_CTRL_SATA0_PD_MASK;
726c0132f60SStefan Roese 	data = 0x0 << SATA3_CTRL_SATA0_PD_OFFSET;
727c0132f60SStefan Roese 	/* SATA 1 power up */
728c0132f60SStefan Roese 	mask |= SATA3_CTRL_SATA1_PD_MASK;
729c0132f60SStefan Roese 	data |= 0x0 << SATA3_CTRL_SATA1_PD_OFFSET;
730c0132f60SStefan Roese 	/* SATA SSU enable */
731c0132f60SStefan Roese 	mask |= SATA3_CTRL_SATA1_ENABLE_MASK;
732c0132f60SStefan Roese 	data |= 0x1 << SATA3_CTRL_SATA1_ENABLE_OFFSET;
733c0132f60SStefan Roese 	/* SATA port 1 enable */
734c0132f60SStefan Roese 	mask |= SATA3_CTRL_SATA_SSU_MASK;
735c0132f60SStefan Roese 	data |= 0x1 << SATA3_CTRL_SATA_SSU_OFFSET;
736c0132f60SStefan Roese 	reg_set(sata_base + SATA3_VENDOR_DATA, data, mask);
737c0132f60SStefan Roese 
738c0132f60SStefan Roese 	/* MBUS request size and interface select register */
739c0132f60SStefan Roese 	reg_set(sata_base + SATA3_VENDOR_ADDRESS,
740c0132f60SStefan Roese 		SATA_MBUS_SIZE_SELECT_REG << SATA3_VENDOR_ADDR_OFSSET,
741c0132f60SStefan Roese 		SATA3_VENDOR_ADDR_MASK);
742c0132f60SStefan Roese 	/* Mbus regret enable */
743c0132f60SStefan Roese 	reg_set(sata_base + SATA3_VENDOR_DATA,
744c0132f60SStefan Roese 		0x1 << SATA_MBUS_REGRET_EN_OFFSET, SATA_MBUS_REGRET_EN_MASK);
745c0132f60SStefan Roese 
746c0132f60SStefan Roese 	debug("stage: Check PLL\n");
747c0132f60SStefan Roese 
748c0132f60SStefan Roese 	addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
749c0132f60SStefan Roese 	data = SD_EXTERNAL_STATUS0_PLL_TX_MASK &
750c0132f60SStefan Roese 		SD_EXTERNAL_STATUS0_PLL_RX_MASK;
751c0132f60SStefan Roese 	mask = data;
752c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 15000);
753c0132f60SStefan Roese 	if (data != 0) {
754c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n",
755c0132f60SStefan Roese 		      hpipe_addr + HPIPE_LANE_STATUS1_REG, data);
756c0132f60SStefan Roese 		error("SD_EXTERNAL_STATUS0_PLL_TX is %d, SD_EXTERNAL_STATUS0_PLL_RX is %d\n",
757c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK),
758c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK));
759c0132f60SStefan Roese 		ret = 0;
760c0132f60SStefan Roese 	}
761c0132f60SStefan Roese 
762c0132f60SStefan Roese 	debug_exit();
763c0132f60SStefan Roese 	return ret;
764c0132f60SStefan Roese }
765c0132f60SStefan Roese 
766c0132f60SStefan Roese static int comphy_sgmii_power_up(u32 lane, u32 sgmii_speed,
767c0132f60SStefan Roese 				 void __iomem *hpipe_base,
768c0132f60SStefan Roese 				 void __iomem *comphy_base)
769c0132f60SStefan Roese {
770c0132f60SStefan Roese 	u32 mask, data, ret = 1;
771c0132f60SStefan Roese 	void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
772c0132f60SStefan Roese 	void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane);
773c0132f60SStefan Roese 	void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
774c0132f60SStefan Roese 	void __iomem *addr;
775c0132f60SStefan Roese 
776c0132f60SStefan Roese 	debug_enter();
777c0132f60SStefan Roese 	debug("stage: RFU configurations - hard reset comphy\n");
778c0132f60SStefan Roese 	/* RFU configurations - hard reset comphy */
779c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_UP_MASK;
780c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
781c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
782c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
783c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
784c0132f60SStefan Roese 
785c0132f60SStefan Roese 	/* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */
786c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
787c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
788c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK;
789c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK;
790c0132f60SStefan Roese 	if (sgmii_speed == PHY_SPEED_1_25G) {
791c0132f60SStefan Roese 		data |= 0x6 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET;
792c0132f60SStefan Roese 		data |= 0x6 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET;
793c0132f60SStefan Roese 	} else {
794c0132f60SStefan Roese 		/* 3.125G */
795c0132f60SStefan Roese 		data |= 0x8 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET;
796c0132f60SStefan Roese 		data |= 0x8 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET;
797c0132f60SStefan Roese 	}
798c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
799c0132f60SStefan Roese 	data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
800c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
801c0132f60SStefan Roese 	data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
802c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK;
803c0132f60SStefan Roese 	data |= 1 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET;
804c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
805c0132f60SStefan Roese 
806c0132f60SStefan Roese 	/* release from hard reset */
807c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
808c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
809c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
810c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
811c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
812c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
813c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
814c0132f60SStefan Roese 
815c0132f60SStefan Roese 	/* release from hard reset */
816c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
817c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
818c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
819c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
820c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
821c0132f60SStefan Roese 
822c0132f60SStefan Roese 
823c0132f60SStefan Roese 	/* Wait 1ms - until band gap and ref clock ready */
824c0132f60SStefan Roese 	mdelay(1);
825c0132f60SStefan Roese 
826c0132f60SStefan Roese 	/* Start comphy Configuration */
827c0132f60SStefan Roese 	debug("stage: Comphy configuration\n");
828c0132f60SStefan Roese 	/* set reference clock */
829c0132f60SStefan Roese 	mask = HPIPE_MISC_REFCLK_SEL_MASK;
830c0132f60SStefan Roese 	data = 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET;
831c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_MISC_REG, data, mask);
832c0132f60SStefan Roese 	/* Power and PLL Control */
833c0132f60SStefan Roese 	mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
834c0132f60SStefan Roese 	data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
835c0132f60SStefan Roese 	mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
836c0132f60SStefan Roese 	data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
837c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
838c0132f60SStefan Roese 	/* Loopback register */
839c0132f60SStefan Roese 	mask = HPIPE_LOOPBACK_SEL_MASK;
840c0132f60SStefan Roese 	data = 0x1 << HPIPE_LOOPBACK_SEL_OFFSET;
841c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LOOPBACK_REG, data, mask);
842c0132f60SStefan Roese 	/* rx control 1 */
843c0132f60SStefan Roese 	mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK;
844c0132f60SStefan Roese 	data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET;
845c0132f60SStefan Roese 	mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK;
846c0132f60SStefan Roese 	data |= 0x0 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET;
847c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask);
848c0132f60SStefan Roese 	/* DTL Control */
849c0132f60SStefan Roese 	mask = HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK;
850c0132f60SStefan Roese 	data = 0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET;
851c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, data, mask);
852c0132f60SStefan Roese 
853c0132f60SStefan Roese 	/* Set analog paramters from ETP(HW) - for now use the default datas */
854c0132f60SStefan Roese 	debug("stage: Analog paramters from ETP(HW)\n");
855c0132f60SStefan Roese 
856c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SET_0_REG,
857c0132f60SStefan Roese 		0x1 << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET,
858c0132f60SStefan Roese 		HPIPE_G1_SET_0_G1_TX_EMPH1_MASK);
859c0132f60SStefan Roese 
860c0132f60SStefan Roese 	debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n");
861c0132f60SStefan Roese 	/* SERDES External Configuration */
862c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
863c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
864c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
865c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
866c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
867c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
868c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
869c0132f60SStefan Roese 
870c0132f60SStefan Roese 	/* check PLL rx & tx ready */
871c0132f60SStefan Roese 	addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
872c0132f60SStefan Roese 	data = SD_EXTERNAL_STATUS0_PLL_RX_MASK |
873c0132f60SStefan Roese 		SD_EXTERNAL_STATUS0_PLL_TX_MASK;
874c0132f60SStefan Roese 	mask = data;
875c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 15000);
876c0132f60SStefan Roese 	if (data != 0) {
877c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n",
878c0132f60SStefan Roese 		      sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
879c0132f60SStefan Roese 		error("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n",
880c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK),
881c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK));
882c0132f60SStefan Roese 		ret = 0;
883c0132f60SStefan Roese 	}
884c0132f60SStefan Roese 
885c0132f60SStefan Roese 	/* RX init */
886c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK;
887c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET;
888c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
889c0132f60SStefan Roese 
890c0132f60SStefan Roese 	/* check that RX init done */
891c0132f60SStefan Roese 	addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
892c0132f60SStefan Roese 	data = SD_EXTERNAL_STATUS0_RX_INIT_MASK;
893c0132f60SStefan Roese 	mask = data;
894c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 100);
895c0132f60SStefan Roese 	if (data != 0) {
896c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n", sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
897c0132f60SStefan Roese 		error("SD_EXTERNAL_STATUS0_RX_INIT is 0\n");
898c0132f60SStefan Roese 		ret = 0;
899c0132f60SStefan Roese 	}
900c0132f60SStefan Roese 
901c0132f60SStefan Roese 	debug("stage: RF Reset\n");
902c0132f60SStefan Roese 	/* RF Reset */
903c0132f60SStefan Roese 	mask =  SD_EXTERNAL_CONFIG1_RX_INIT_MASK;
904c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET;
905c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
906c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
907c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
908c0132f60SStefan Roese 
909c0132f60SStefan Roese 	debug_exit();
910c0132f60SStefan Roese 	return ret;
911c0132f60SStefan Roese }
912c0132f60SStefan Roese 
913cb686454SStefan Roese static int comphy_sfi_power_up(u32 lane, void __iomem *hpipe_base,
914c0132f60SStefan Roese 			       void __iomem *comphy_base)
915c0132f60SStefan Roese {
916c0132f60SStefan Roese 	u32 mask, data, ret = 1;
917c0132f60SStefan Roese 	void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
918c0132f60SStefan Roese 	void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane);
919c0132f60SStefan Roese 	void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
920c0132f60SStefan Roese 	void __iomem *addr;
921c0132f60SStefan Roese 
922c0132f60SStefan Roese 	debug_enter();
923c0132f60SStefan Roese 	debug("stage: RFU configurations - hard reset comphy\n");
924c0132f60SStefan Roese 	/* RFU configurations - hard reset comphy */
925c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_UP_MASK;
926c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
927c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
928c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
929c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
930c0132f60SStefan Roese 
931c0132f60SStefan Roese 	/* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */
932c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
933c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
934c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK;
935c0132f60SStefan Roese 	data |= 0xE << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET;
936c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK;
937c0132f60SStefan Roese 	data |= 0xE << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET;
938c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
939c0132f60SStefan Roese 	data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
940c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
941c0132f60SStefan Roese 	data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
942c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK;
943c0132f60SStefan Roese 	data |= 0 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET;
944c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
945c0132f60SStefan Roese 
946c0132f60SStefan Roese 	/* release from hard reset */
947c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
948c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
949c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
950c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
951c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
952c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
953c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
954c0132f60SStefan Roese 
955c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
956c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
957c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
958c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
959c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
960c0132f60SStefan Roese 
961c0132f60SStefan Roese 
962c0132f60SStefan Roese 	/* Wait 1ms - until band gap and ref clock ready */
963c0132f60SStefan Roese 	mdelay(1);
964c0132f60SStefan Roese 
965c0132f60SStefan Roese 	/* Start comphy Configuration */
966c0132f60SStefan Roese 	debug("stage: Comphy configuration\n");
967c0132f60SStefan Roese 	/* set reference clock */
968c0132f60SStefan Roese 	mask = HPIPE_MISC_ICP_FORCE_MASK;
969c0132f60SStefan Roese 	data = 0x1 << HPIPE_MISC_ICP_FORCE_OFFSET;
970c0132f60SStefan Roese 	mask |= HPIPE_MISC_REFCLK_SEL_MASK;
971c0132f60SStefan Roese 	data |= 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET;
972c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_MISC_REG, data, mask);
973c0132f60SStefan Roese 	/* Power and PLL Control */
974c0132f60SStefan Roese 	mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
975c0132f60SStefan Roese 	data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
976c0132f60SStefan Roese 	mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
977c0132f60SStefan Roese 	data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
978c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
979c0132f60SStefan Roese 	/* Loopback register */
980c0132f60SStefan Roese 	mask = HPIPE_LOOPBACK_SEL_MASK;
981c0132f60SStefan Roese 	data = 0x1 << HPIPE_LOOPBACK_SEL_OFFSET;
982c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LOOPBACK_REG, data, mask);
983c0132f60SStefan Roese 	/* rx control 1 */
984c0132f60SStefan Roese 	mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK;
985c0132f60SStefan Roese 	data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET;
986c0132f60SStefan Roese 	mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK;
987c0132f60SStefan Roese 	data |= 0x1 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET;
988c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask);
989c0132f60SStefan Roese 	/* DTL Control */
990c0132f60SStefan Roese 	mask = HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK;
991c0132f60SStefan Roese 	data = 0x1 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET;
992c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, data, mask);
993c0132f60SStefan Roese 
994c0132f60SStefan Roese 	/* Set analog paramters from ETP(HW) */
995c0132f60SStefan Roese 	debug("stage: Analog paramters from ETP(HW)\n");
996c0132f60SStefan Roese 	/* SERDES External Configuration 2 */
997c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG2_PIN_DFE_EN_MASK;
998c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG2_PIN_DFE_EN_OFFSET;
999c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG, data, mask);
1000c0132f60SStefan Roese 	/* 0x7-DFE Resolution control */
1001c0132f60SStefan Roese 	mask = HPIPE_DFE_RES_FORCE_MASK;
1002c0132f60SStefan Roese 	data = 0x1 << HPIPE_DFE_RES_FORCE_OFFSET;
1003c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_DFE_REG0, data, mask);
1004c0132f60SStefan Roese 	/* 0xd-G1_Setting_0 */
1005c0132f60SStefan Roese 	mask = HPIPE_G1_SET_0_G1_TX_AMP_MASK;
1006c0132f60SStefan Roese 	data = 0x1c << HPIPE_G1_SET_0_G1_TX_AMP_OFFSET;
1007c0132f60SStefan Roese 	mask |= HPIPE_G1_SET_0_G1_TX_EMPH1_MASK;
1008c0132f60SStefan Roese 	data |= 0xe << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET;
1009c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SET_0_REG, data, mask);
1010c0132f60SStefan Roese 	/* Genration 1 setting 2 (G1_Setting_2) */
1011c0132f60SStefan Roese 	mask = HPIPE_G1_SET_2_G1_TX_EMPH0_MASK;
1012c0132f60SStefan Roese 	data = 0x0 << HPIPE_G1_SET_2_G1_TX_EMPH0_OFFSET;
1013c0132f60SStefan Roese 	mask |= HPIPE_G1_SET_2_G1_TX_EMPH0_EN_MASK;
1014c0132f60SStefan Roese 	data |= 0x1 << HPIPE_G1_SET_2_G1_TX_EMPH0_EN_OFFSET;
1015c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SET_2_REG, data, mask);
1016c0132f60SStefan Roese 	/* Transmitter Slew Rate Control register (tx_reg1) */
1017c0132f60SStefan Roese 	mask = HPIPE_TX_REG1_TX_EMPH_RES_MASK;
1018c0132f60SStefan Roese 	data = 0x3 << HPIPE_TX_REG1_TX_EMPH_RES_OFFSET;
1019c0132f60SStefan Roese 	mask |= HPIPE_TX_REG1_SLC_EN_MASK;
1020c0132f60SStefan Roese 	data |= 0x3f << HPIPE_TX_REG1_SLC_EN_OFFSET;
1021c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_TX_REG1_REG, data, mask);
1022c0132f60SStefan Roese 	/* Impedance Calibration Control register (cal_reg1) */
1023c0132f60SStefan Roese 	mask = HPIPE_CAL_REG_1_EXT_TXIMP_MASK;
1024c0132f60SStefan Roese 	data = 0xe << HPIPE_CAL_REG_1_EXT_TXIMP_OFFSET;
1025c0132f60SStefan Roese 	mask |= HPIPE_CAL_REG_1_EXT_TXIMP_EN_MASK;
1026c0132f60SStefan Roese 	data |= 0x1 << HPIPE_CAL_REG_1_EXT_TXIMP_EN_OFFSET;
1027c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_CAL_REG1_REG, data, mask);
1028c0132f60SStefan Roese 	/* Generation 1 Setting 5 (g1_setting_5) */
1029c0132f60SStefan Roese 	mask = HPIPE_G1_SETTING_5_G1_ICP_MASK;
1030c0132f60SStefan Roese 	data = 0 << HPIPE_CAL_REG_1_EXT_TXIMP_OFFSET;
1031c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SETTING_5_REG, data, mask);
1032c0132f60SStefan Roese 	/* 0xE-G1_Setting_1 */
1033c0132f60SStefan Roese 	mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK;
1034c0132f60SStefan Roese 	data = 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET;
1035c0132f60SStefan Roese 	mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK;
1036c0132f60SStefan Roese 	data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET;
1037c0132f60SStefan Roese 	mask |= HPIPE_G1_SET_1_G1_RX_DFE_EN_MASK;
1038c0132f60SStefan Roese 	data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DFE_EN_OFFSET;
1039c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask);
1040c0132f60SStefan Roese 	/* 0xA-DFE_Reg3 */
1041c0132f60SStefan Roese 	mask = HPIPE_DFE_F3_F5_DFE_EN_MASK;
1042c0132f60SStefan Roese 	data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET;
1043c0132f60SStefan Roese 	mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK;
1044c0132f60SStefan Roese 	data |= 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET;
1045c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask);
1046c0132f60SStefan Roese 
1047c0132f60SStefan Roese 	/* 0x111-G1_Setting_4 */
1048c0132f60SStefan Roese 	mask = HPIPE_G1_SETTINGS_4_G1_DFE_RES_MASK;
1049c0132f60SStefan Roese 	data = 0x1 << HPIPE_G1_SETTINGS_4_G1_DFE_RES_OFFSET;
1050c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SETTINGS_4_REG, data, mask);
1051c0132f60SStefan Roese 	/* Genration 1 setting 3 (G1_Setting_3) */
1052c0132f60SStefan Roese 	mask = HPIPE_G1_SETTINGS_3_G1_FBCK_SEL_MASK;
1053c0132f60SStefan Roese 	data = 0x1 << HPIPE_G1_SETTINGS_3_G1_FBCK_SEL_OFFSET;
1054c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SETTINGS_3_REG, data, mask);
1055c0132f60SStefan Roese 
1056c0132f60SStefan Roese 	debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n");
1057c0132f60SStefan Roese 	/* SERDES External Configuration */
1058c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
1059c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
1060c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
1061c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
1062c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
1063c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
1064c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
1065c0132f60SStefan Roese 
1066c0132f60SStefan Roese 
1067c0132f60SStefan Roese 	/* check PLL rx & tx ready */
1068c0132f60SStefan Roese 	addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
1069c0132f60SStefan Roese 	data = SD_EXTERNAL_STATUS0_PLL_RX_MASK |
1070c0132f60SStefan Roese 		SD_EXTERNAL_STATUS0_PLL_TX_MASK;
1071c0132f60SStefan Roese 	mask = data;
1072c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 15000);
1073c0132f60SStefan Roese 	if (data != 0) {
1074c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n", sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
1075c0132f60SStefan Roese 		error("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n",
1076c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK),
1077c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK));
1078c0132f60SStefan Roese 		ret = 0;
1079c0132f60SStefan Roese 	}
1080c0132f60SStefan Roese 
1081c0132f60SStefan Roese 	/* RX init */
1082c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK;
1083c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET;
1084c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
1085c0132f60SStefan Roese 
1086c0132f60SStefan Roese 
1087c0132f60SStefan Roese 	/* check that RX init done */
1088c0132f60SStefan Roese 	addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
1089c0132f60SStefan Roese 	data = SD_EXTERNAL_STATUS0_RX_INIT_MASK;
1090c0132f60SStefan Roese 	mask = data;
1091c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 100);
1092c0132f60SStefan Roese 	if (data != 0) {
1093c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n",
1094c0132f60SStefan Roese 		      sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
1095c0132f60SStefan Roese 		error("SD_EXTERNAL_STATUS0_RX_INIT is 0\n");
1096c0132f60SStefan Roese 		ret = 0;
1097c0132f60SStefan Roese 	}
1098c0132f60SStefan Roese 
1099c0132f60SStefan Roese 	debug("stage: RF Reset\n");
1100c0132f60SStefan Roese 	/* RF Reset */
1101c0132f60SStefan Roese 	mask =  SD_EXTERNAL_CONFIG1_RX_INIT_MASK;
1102c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET;
1103c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
1104c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
1105c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
1106c0132f60SStefan Roese 
1107c0132f60SStefan Roese 	debug_exit();
1108c0132f60SStefan Roese 	return ret;
1109c0132f60SStefan Roese }
1110c0132f60SStefan Roese 
1111c0132f60SStefan Roese static int comphy_rxauii_power_up(u32 lane, void __iomem *hpipe_base,
1112c0132f60SStefan Roese 				  void __iomem *comphy_base)
1113c0132f60SStefan Roese {
1114c0132f60SStefan Roese 	u32 mask, data, ret = 1;
1115c0132f60SStefan Roese 	void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
1116c0132f60SStefan Roese 	void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane);
1117c0132f60SStefan Roese 	void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
1118c0132f60SStefan Roese 	void __iomem *addr;
1119c0132f60SStefan Roese 
1120c0132f60SStefan Roese 	debug_enter();
1121c0132f60SStefan Roese 	debug("stage: RFU configurations - hard reset comphy\n");
1122c0132f60SStefan Roese 	/* RFU configurations - hard reset comphy */
1123c0132f60SStefan Roese 	mask = COMMON_PHY_CFG1_PWR_UP_MASK;
1124c0132f60SStefan Roese 	data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
1125c0132f60SStefan Roese 	mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
1126c0132f60SStefan Roese 	data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
1127c0132f60SStefan Roese 	reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
1128c0132f60SStefan Roese 
1129c0132f60SStefan Roese 	if (lane == 2) {
1130c0132f60SStefan Roese 		reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
1131c0132f60SStefan Roese 			0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET,
1132c0132f60SStefan Roese 			COMMON_PHY_SD_CTRL1_RXAUI0_MASK);
1133c0132f60SStefan Roese 	}
1134c0132f60SStefan Roese 	if (lane == 4) {
1135c0132f60SStefan Roese 		reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
1136c0132f60SStefan Roese 			0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET,
1137c0132f60SStefan Roese 			COMMON_PHY_SD_CTRL1_RXAUI1_MASK);
1138c0132f60SStefan Roese 	}
1139c0132f60SStefan Roese 
1140c0132f60SStefan Roese 	/* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */
1141c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
1142c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
1143c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK;
1144c0132f60SStefan Roese 	data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET;
1145c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK;
1146c0132f60SStefan Roese 	data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET;
1147c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
1148c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
1149c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
1150c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
1151c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK;
1152c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET;
1153c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_MEDIA_MODE_MASK;
1154c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG0_MEDIA_MODE_OFFSET;
1155c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
1156c0132f60SStefan Roese 
1157c0132f60SStefan Roese 	/* release from hard reset */
1158c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
1159c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
1160c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
1161c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
1162c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
1163c0132f60SStefan Roese 	data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
1164c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
1165c0132f60SStefan Roese 
1166c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
1167c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
1168c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
1169c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
1170c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
1171c0132f60SStefan Roese 
1172c0132f60SStefan Roese 	/* Wait 1ms - until band gap and ref clock ready */
1173c0132f60SStefan Roese 	mdelay(1);
1174c0132f60SStefan Roese 
1175c0132f60SStefan Roese 	/* Start comphy Configuration */
1176c0132f60SStefan Roese 	debug("stage: Comphy configuration\n");
1177c0132f60SStefan Roese 	/* set reference clock */
1178c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_MISC_REG,
1179c0132f60SStefan Roese 		0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET,
1180c0132f60SStefan Roese 		HPIPE_MISC_REFCLK_SEL_MASK);
1181c0132f60SStefan Roese 	/* Power and PLL Control */
1182c0132f60SStefan Roese 	mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
1183c0132f60SStefan Roese 	data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
1184c0132f60SStefan Roese 	mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
1185c0132f60SStefan Roese 	data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
1186c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
1187c0132f60SStefan Roese 	/* Loopback register */
1188c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_LOOPBACK_REG,
1189c0132f60SStefan Roese 		0x1 << HPIPE_LOOPBACK_SEL_OFFSET, HPIPE_LOOPBACK_SEL_MASK);
1190c0132f60SStefan Roese 	/* rx control 1 */
1191c0132f60SStefan Roese 	mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK;
1192c0132f60SStefan Roese 	data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET;
1193c0132f60SStefan Roese 	mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK;
1194c0132f60SStefan Roese 	data |= 0x1 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET;
1195c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask);
1196c0132f60SStefan Roese 	/* DTL Control */
1197c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG,
1198c0132f60SStefan Roese 		0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET,
1199c0132f60SStefan Roese 		HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK);
1200c0132f60SStefan Roese 
1201c0132f60SStefan Roese 	/* Set analog paramters from ETP(HW) */
1202c0132f60SStefan Roese 	debug("stage: Analog paramters from ETP(HW)\n");
1203c0132f60SStefan Roese 	/* SERDES External Configuration 2 */
1204c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG,
1205c0132f60SStefan Roese 		0x1 << SD_EXTERNAL_CONFIG2_PIN_DFE_EN_OFFSET,
1206c0132f60SStefan Roese 		SD_EXTERNAL_CONFIG2_PIN_DFE_EN_MASK);
1207c0132f60SStefan Roese 	/* 0x7-DFE Resolution control */
1208c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_DFE_REG0, 0x1 << HPIPE_DFE_RES_FORCE_OFFSET,
1209c0132f60SStefan Roese 		HPIPE_DFE_RES_FORCE_MASK);
1210c0132f60SStefan Roese 	/* 0xd-G1_Setting_0 */
1211c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SET_0_REG,
1212c0132f60SStefan Roese 		0xd << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET,
1213c0132f60SStefan Roese 		HPIPE_G1_SET_0_G1_TX_EMPH1_MASK);
1214c0132f60SStefan Roese 	/* 0xE-G1_Setting_1 */
1215c0132f60SStefan Roese 	mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK;
1216c0132f60SStefan Roese 	data = 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET;
1217c0132f60SStefan Roese 	mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK;
1218c0132f60SStefan Roese 	data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET;
1219c0132f60SStefan Roese 	mask |= HPIPE_G1_SET_1_G1_RX_DFE_EN_MASK;
1220c0132f60SStefan Roese 	data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DFE_EN_OFFSET;
1221c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask);
1222c0132f60SStefan Roese 	/* 0xA-DFE_Reg3 */
1223c0132f60SStefan Roese 	mask = HPIPE_DFE_F3_F5_DFE_EN_MASK;
1224c0132f60SStefan Roese 	data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET;
1225c0132f60SStefan Roese 	mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK;
1226c0132f60SStefan Roese 	data |= 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET;
1227c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask);
1228c0132f60SStefan Roese 
1229c0132f60SStefan Roese 	/* 0x111-G1_Setting_4 */
1230c0132f60SStefan Roese 	mask = HPIPE_G1_SETTINGS_4_G1_DFE_RES_MASK;
1231c0132f60SStefan Roese 	data = 0x1 << HPIPE_G1_SETTINGS_4_G1_DFE_RES_OFFSET;
1232c0132f60SStefan Roese 	reg_set(hpipe_addr + HPIPE_G1_SETTINGS_4_REG, data, mask);
1233c0132f60SStefan Roese 
1234c0132f60SStefan Roese 	debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n");
1235c0132f60SStefan Roese 	/* SERDES External Configuration */
1236c0132f60SStefan Roese 	mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
1237c0132f60SStefan Roese 	data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
1238c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
1239c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
1240c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
1241c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
1242c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
1243c0132f60SStefan Roese 
1244c0132f60SStefan Roese 
1245c0132f60SStefan Roese 	/* check PLL rx & tx ready */
1246c0132f60SStefan Roese 	addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
1247c0132f60SStefan Roese 	data = SD_EXTERNAL_STATUS0_PLL_RX_MASK |
1248c0132f60SStefan Roese 		SD_EXTERNAL_STATUS0_PLL_TX_MASK;
1249c0132f60SStefan Roese 	mask = data;
1250c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 15000);
1251c0132f60SStefan Roese 	if (data != 0) {
1252c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n",
1253c0132f60SStefan Roese 		      sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
1254c0132f60SStefan Roese 		error("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n",
1255c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK),
1256c0132f60SStefan Roese 		      (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK));
1257c0132f60SStefan Roese 		ret = 0;
1258c0132f60SStefan Roese 	}
1259c0132f60SStefan Roese 
1260c0132f60SStefan Roese 	/* RX init */
1261c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG,
1262c0132f60SStefan Roese 		0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET,
1263c0132f60SStefan Roese 		SD_EXTERNAL_CONFIG1_RX_INIT_MASK);
1264c0132f60SStefan Roese 
1265c0132f60SStefan Roese 	/* check that RX init done */
1266c0132f60SStefan Roese 	addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
1267c0132f60SStefan Roese 	data = SD_EXTERNAL_STATUS0_RX_INIT_MASK;
1268c0132f60SStefan Roese 	mask = data;
1269c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 100);
1270c0132f60SStefan Roese 	if (data != 0) {
1271c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n",
1272c0132f60SStefan Roese 		      sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
1273c0132f60SStefan Roese 		error("SD_EXTERNAL_STATUS0_RX_INIT is 0\n");
1274c0132f60SStefan Roese 		ret = 0;
1275c0132f60SStefan Roese 	}
1276c0132f60SStefan Roese 
1277c0132f60SStefan Roese 	debug("stage: RF Reset\n");
1278c0132f60SStefan Roese 	/* RF Reset */
1279c0132f60SStefan Roese 	mask =  SD_EXTERNAL_CONFIG1_RX_INIT_MASK;
1280c0132f60SStefan Roese 	data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET;
1281c0132f60SStefan Roese 	mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
1282c0132f60SStefan Roese 	data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
1283c0132f60SStefan Roese 	reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
1284c0132f60SStefan Roese 
1285c0132f60SStefan Roese 	debug_exit();
1286c0132f60SStefan Roese 	return ret;
1287c0132f60SStefan Roese }
1288c0132f60SStefan Roese 
1289c0132f60SStefan Roese static void comphy_utmi_power_down(u32 utmi_index, void __iomem *utmi_base_addr,
1290c0132f60SStefan Roese 				   void __iomem *usb_cfg_addr,
1291c0132f60SStefan Roese 				   void __iomem *utmi_cfg_addr,
1292c0132f60SStefan Roese 				   u32 utmi_phy_port)
1293c0132f60SStefan Roese {
1294c0132f60SStefan Roese 	u32 mask, data;
1295c0132f60SStefan Roese 
1296c0132f60SStefan Roese 	debug_enter();
1297c0132f60SStefan Roese 	debug("stage:  UTMI %d - Power down transceiver (power down Phy), Power down PLL, and SuspendDM\n",
1298c0132f60SStefan Roese 	      utmi_index);
1299c0132f60SStefan Roese 	/* Power down UTMI PHY */
1300c0132f60SStefan Roese 	reg_set(utmi_cfg_addr, 0x0 << UTMI_PHY_CFG_PU_OFFSET,
1301c0132f60SStefan Roese 		UTMI_PHY_CFG_PU_MASK);
1302c0132f60SStefan Roese 
1303c0132f60SStefan Roese 	/*
1304c0132f60SStefan Roese 	 * If UTMI connected to USB Device, configure mux prior to PHY init
1305c0132f60SStefan Roese 	 * (Device can be connected to UTMI0 or to UTMI1)
1306c0132f60SStefan Roese 	 */
1307*e89acc4bSStefan Roese 	if (utmi_phy_port == UTMI_PHY_TO_USB3_DEVICE0) {
1308c0132f60SStefan Roese 		debug("stage:  UTMI %d - Enable Device mode and configure UTMI mux\n",
1309c0132f60SStefan Roese 		      utmi_index);
1310c0132f60SStefan Roese 		/* USB3 Device UTMI enable */
1311c0132f60SStefan Roese 		mask = UTMI_USB_CFG_DEVICE_EN_MASK;
1312c0132f60SStefan Roese 		data = 0x1 << UTMI_USB_CFG_DEVICE_EN_OFFSET;
1313c0132f60SStefan Roese 		/* USB3 Device UTMI MUX */
1314c0132f60SStefan Roese 		mask |= UTMI_USB_CFG_DEVICE_MUX_MASK;
1315c0132f60SStefan Roese 		data |= utmi_index << UTMI_USB_CFG_DEVICE_MUX_OFFSET;
1316c0132f60SStefan Roese 		reg_set(usb_cfg_addr,  data, mask);
1317c0132f60SStefan Roese 	}
1318c0132f60SStefan Roese 
1319c0132f60SStefan Roese 	/* Set Test suspendm mode */
1320c0132f60SStefan Roese 	mask = UTMI_CTRL_STATUS0_SUSPENDM_MASK;
1321c0132f60SStefan Roese 	data = 0x1 << UTMI_CTRL_STATUS0_SUSPENDM_OFFSET;
1322c0132f60SStefan Roese 	/* Enable Test UTMI select */
1323c0132f60SStefan Roese 	mask |= UTMI_CTRL_STATUS0_TEST_SEL_MASK;
1324c0132f60SStefan Roese 	data |= 0x1 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET;
1325c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, data, mask);
1326c0132f60SStefan Roese 
1327c0132f60SStefan Roese 	/* Wait for UTMI power down */
1328c0132f60SStefan Roese 	mdelay(1);
1329c0132f60SStefan Roese 
1330c0132f60SStefan Roese 	debug_exit();
1331c0132f60SStefan Roese 	return;
1332c0132f60SStefan Roese }
1333c0132f60SStefan Roese 
1334c0132f60SStefan Roese static void comphy_utmi_phy_config(u32 utmi_index, void __iomem *utmi_base_addr,
1335c0132f60SStefan Roese 				   void __iomem *usb_cfg_addr,
1336c0132f60SStefan Roese 				   void __iomem *utmi_cfg_addr,
1337c0132f60SStefan Roese 				   u32 utmi_phy_port)
1338c0132f60SStefan Roese {
1339c0132f60SStefan Roese 	u32 mask, data;
1340c0132f60SStefan Roese 
1341c0132f60SStefan Roese 	debug_exit();
1342c0132f60SStefan Roese 	debug("stage: Configure UTMI PHY %d registers\n", utmi_index);
1343c0132f60SStefan Roese 	/* Reference Clock Divider Select */
1344c0132f60SStefan Roese 	mask = UTMI_PLL_CTRL_REFDIV_MASK;
1345c0132f60SStefan Roese 	data = 0x5 << UTMI_PLL_CTRL_REFDIV_OFFSET;
1346c0132f60SStefan Roese 	/* Feedback Clock Divider Select - 90 for 25Mhz*/
1347c0132f60SStefan Roese 	mask |= UTMI_PLL_CTRL_FBDIV_MASK;
1348c0132f60SStefan Roese 	data |= 0x60 << UTMI_PLL_CTRL_FBDIV_OFFSET;
1349c0132f60SStefan Roese 	/* Select LPFR - 0x0 for 25Mhz/5=5Mhz*/
1350c0132f60SStefan Roese 	mask |= UTMI_PLL_CTRL_SEL_LPFR_MASK;
1351c0132f60SStefan Roese 	data |= 0x0 << UTMI_PLL_CTRL_SEL_LPFR_OFFSET;
1352c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_PLL_CTRL_REG, data, mask);
1353c0132f60SStefan Roese 
1354c0132f60SStefan Roese 	/* Impedance Calibration Threshold Setting */
1355c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_CALIB_CTRL_REG,
1356c0132f60SStefan Roese 		0x6 << UTMI_CALIB_CTRL_IMPCAL_VTH_OFFSET,
1357c0132f60SStefan Roese 		UTMI_CALIB_CTRL_IMPCAL_VTH_MASK);
1358c0132f60SStefan Roese 
1359c0132f60SStefan Roese 	/* Set LS TX driver strength coarse control */
1360c0132f60SStefan Roese 	mask = UTMI_TX_CH_CTRL_DRV_EN_LS_MASK;
1361c0132f60SStefan Roese 	data = 0x3 << UTMI_TX_CH_CTRL_DRV_EN_LS_OFFSET;
1362c0132f60SStefan Roese 	/* Set LS TX driver fine adjustment */
1363c0132f60SStefan Roese 	mask |= UTMI_TX_CH_CTRL_IMP_SEL_LS_MASK;
1364c0132f60SStefan Roese 	data |= 0x3 << UTMI_TX_CH_CTRL_IMP_SEL_LS_OFFSET;
1365c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_TX_CH_CTRL_REG, data, mask);
1366c0132f60SStefan Roese 
1367c0132f60SStefan Roese 	/* Enable SQ */
1368c0132f60SStefan Roese 	mask = UTMI_RX_CH_CTRL0_SQ_DET_MASK;
1369c0132f60SStefan Roese 	data = 0x0 << UTMI_RX_CH_CTRL0_SQ_DET_OFFSET;
1370c0132f60SStefan Roese 	/* Enable analog squelch detect */
1371c0132f60SStefan Roese 	mask |= UTMI_RX_CH_CTRL0_SQ_ANA_DTC_MASK;
1372c0132f60SStefan Roese 	data |= 0x1 << UTMI_RX_CH_CTRL0_SQ_ANA_DTC_OFFSET;
1373c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_RX_CH_CTRL0_REG, data, mask);
1374c0132f60SStefan Roese 
1375c0132f60SStefan Roese 	/* Set External squelch calibration number */
1376c0132f60SStefan Roese 	mask = UTMI_RX_CH_CTRL1_SQ_AMP_CAL_MASK;
1377c0132f60SStefan Roese 	data = 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_OFFSET;
1378c0132f60SStefan Roese 	/* Enable the External squelch calibration */
1379c0132f60SStefan Roese 	mask |= UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_MASK;
1380c0132f60SStefan Roese 	data |= 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_OFFSET;
1381c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_RX_CH_CTRL1_REG, data, mask);
1382c0132f60SStefan Roese 
1383c0132f60SStefan Roese 	/* Set Control VDAT Reference Voltage - 0.325V */
1384c0132f60SStefan Roese 	mask = UTMI_CHGDTC_CTRL_VDAT_MASK;
1385c0132f60SStefan Roese 	data = 0x1 << UTMI_CHGDTC_CTRL_VDAT_OFFSET;
1386c0132f60SStefan Roese 	/* Set Control VSRC Reference Voltage - 0.6V */
1387c0132f60SStefan Roese 	mask |= UTMI_CHGDTC_CTRL_VSRC_MASK;
1388c0132f60SStefan Roese 	data |= 0x1 << UTMI_CHGDTC_CTRL_VSRC_OFFSET;
1389c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_CHGDTC_CTRL_REG, data, mask);
1390c0132f60SStefan Roese 
1391c0132f60SStefan Roese 	debug_exit();
1392c0132f60SStefan Roese 	return;
1393c0132f60SStefan Roese }
1394c0132f60SStefan Roese 
1395c0132f60SStefan Roese static int comphy_utmi_power_up(u32 utmi_index, void __iomem *utmi_base_addr,
1396c0132f60SStefan Roese 				void __iomem *usb_cfg_addr,
1397c0132f60SStefan Roese 				void __iomem *utmi_cfg_addr, u32 utmi_phy_port)
1398c0132f60SStefan Roese {
1399c0132f60SStefan Roese 	u32 data, mask, ret = 1;
1400c0132f60SStefan Roese 	void __iomem *addr;
1401c0132f60SStefan Roese 
1402c0132f60SStefan Roese 	debug_enter();
1403c0132f60SStefan Roese 	debug("stage: UTMI %d - Power up transceiver(Power up Phy), and exit SuspendDM\n",
1404c0132f60SStefan Roese 	      utmi_index);
1405c0132f60SStefan Roese 	/* Power UP UTMI PHY */
1406c0132f60SStefan Roese 	reg_set(utmi_cfg_addr, 0x1 << UTMI_PHY_CFG_PU_OFFSET,
1407c0132f60SStefan Roese 		UTMI_PHY_CFG_PU_MASK);
1408c0132f60SStefan Roese 	/* Disable Test UTMI select */
1409c0132f60SStefan Roese 	reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG,
1410c0132f60SStefan Roese 		0x0 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET,
1411c0132f60SStefan Roese 		UTMI_CTRL_STATUS0_TEST_SEL_MASK);
1412c0132f60SStefan Roese 
1413c0132f60SStefan Roese 	debug("stage: Polling for PLL and impedance calibration done, and PLL ready done\n");
1414c0132f60SStefan Roese 	addr = utmi_base_addr + UTMI_CALIB_CTRL_REG;
1415c0132f60SStefan Roese 	data = UTMI_CALIB_CTRL_IMPCAL_DONE_MASK;
1416c0132f60SStefan Roese 	mask = data;
1417c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 100);
1418c0132f60SStefan Roese 	if (data != 0) {
1419c0132f60SStefan Roese 		error("Impedance calibration is not done\n");
1420c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n", addr, data);
1421c0132f60SStefan Roese 		ret = 0;
1422c0132f60SStefan Roese 	}
1423c0132f60SStefan Roese 
1424c0132f60SStefan Roese 	data = UTMI_CALIB_CTRL_PLLCAL_DONE_MASK;
1425c0132f60SStefan Roese 	mask = data;
1426c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 100);
1427c0132f60SStefan Roese 	if (data != 0) {
1428c0132f60SStefan Roese 		error("PLL calibration is not done\n");
1429c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n", addr, data);
1430c0132f60SStefan Roese 		ret = 0;
1431c0132f60SStefan Roese 	}
1432c0132f60SStefan Roese 
1433c0132f60SStefan Roese 	addr = utmi_base_addr + UTMI_PLL_CTRL_REG;
1434c0132f60SStefan Roese 	data = UTMI_PLL_CTRL_PLL_RDY_MASK;
1435c0132f60SStefan Roese 	mask = data;
1436c0132f60SStefan Roese 	data = polling_with_timeout(addr, data, mask, 100);
1437c0132f60SStefan Roese 	if (data != 0) {
1438c0132f60SStefan Roese 		error("PLL is not ready\n");
1439c0132f60SStefan Roese 		debug("Read from reg = %p - value = 0x%x\n", addr, data);
1440c0132f60SStefan Roese 		ret = 0;
1441c0132f60SStefan Roese 	}
1442c0132f60SStefan Roese 
1443c0132f60SStefan Roese 	if (ret)
1444c0132f60SStefan Roese 		debug("Passed\n");
1445c0132f60SStefan Roese 	else
1446c0132f60SStefan Roese 		debug("\n");
1447c0132f60SStefan Roese 
1448c0132f60SStefan Roese 	debug_exit();
1449c0132f60SStefan Roese 	return ret;
1450c0132f60SStefan Roese }
1451c0132f60SStefan Roese 
1452c0132f60SStefan Roese /*
1453c0132f60SStefan Roese  * comphy_utmi_phy_init initialize the UTMI PHY
1454c0132f60SStefan Roese  * the init split in 3 parts:
1455c0132f60SStefan Roese  * 1. Power down transceiver and PLL
1456c0132f60SStefan Roese  * 2. UTMI PHY configure
1457c0132f60SStefan Roese  * 3. Powe up transceiver and PLL
1458c0132f60SStefan Roese  * Note: - Power down/up should be once for both UTMI PHYs
1459c0132f60SStefan Roese  *       - comphy_dedicated_phys_init call this function if at least there is
1460c0132f60SStefan Roese  *         one UTMI PHY exists in FDT blob. access to cp110_utmi_data[0] is
1461c0132f60SStefan Roese  *         legal
1462c0132f60SStefan Roese  */
1463c0132f60SStefan Roese static void comphy_utmi_phy_init(u32 utmi_phy_count,
1464c0132f60SStefan Roese 				 struct utmi_phy_data *cp110_utmi_data)
1465c0132f60SStefan Roese {
1466c0132f60SStefan Roese 	u32 i;
1467c0132f60SStefan Roese 
1468c0132f60SStefan Roese 	debug_enter();
1469c0132f60SStefan Roese 	/* UTMI Power down */
1470c0132f60SStefan Roese 	for (i = 0; i < utmi_phy_count; i++) {
1471c0132f60SStefan Roese 		comphy_utmi_power_down(i, cp110_utmi_data[i].utmi_base_addr,
1472c0132f60SStefan Roese 				       cp110_utmi_data[i].usb_cfg_addr,
1473c0132f60SStefan Roese 				       cp110_utmi_data[i].utmi_cfg_addr,
1474c0132f60SStefan Roese 				       cp110_utmi_data[i].utmi_phy_port);
1475c0132f60SStefan Roese 	}
1476c0132f60SStefan Roese 	/* PLL Power down */
1477c0132f60SStefan Roese 	debug("stage: UTMI PHY power down PLL\n");
1478c0132f60SStefan Roese 	for (i = 0; i < utmi_phy_count; i++) {
1479c0132f60SStefan Roese 		reg_set(cp110_utmi_data[i].usb_cfg_addr,
1480c0132f60SStefan Roese 			0x0 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK);
1481c0132f60SStefan Roese 	}
1482c0132f60SStefan Roese 	/* UTMI configure */
1483c0132f60SStefan Roese 	for (i = 0; i < utmi_phy_count; i++) {
1484c0132f60SStefan Roese 		comphy_utmi_phy_config(i, cp110_utmi_data[i].utmi_base_addr,
1485c0132f60SStefan Roese 				       cp110_utmi_data[i].usb_cfg_addr,
1486c0132f60SStefan Roese 				       cp110_utmi_data[i].utmi_cfg_addr,
1487c0132f60SStefan Roese 				       cp110_utmi_data[i].utmi_phy_port);
1488c0132f60SStefan Roese 	}
1489c0132f60SStefan Roese 	/* UTMI Power up */
1490c0132f60SStefan Roese 	for (i = 0; i < utmi_phy_count; i++) {
1491c0132f60SStefan Roese 		if (!comphy_utmi_power_up(i, cp110_utmi_data[i].utmi_base_addr,
1492c0132f60SStefan Roese 					  cp110_utmi_data[i].usb_cfg_addr,
1493c0132f60SStefan Roese 					  cp110_utmi_data[i].utmi_cfg_addr,
1494c0132f60SStefan Roese 					  cp110_utmi_data[i].utmi_phy_port)) {
1495c0132f60SStefan Roese 			error("Failed to initialize UTMI PHY %d\n", i);
1496c0132f60SStefan Roese 			continue;
1497c0132f60SStefan Roese 		}
1498c0132f60SStefan Roese 		printf("UTMI PHY %d initialized to ", i);
1499*e89acc4bSStefan Roese 		if (cp110_utmi_data[i].utmi_phy_port ==
1500*e89acc4bSStefan Roese 		    UTMI_PHY_TO_USB3_DEVICE0)
1501c0132f60SStefan Roese 			printf("USB Device\n");
1502c0132f60SStefan Roese 		else
1503c0132f60SStefan Roese 			printf("USB Host%d\n",
1504c0132f60SStefan Roese 			       cp110_utmi_data[i].utmi_phy_port);
1505c0132f60SStefan Roese 	}
1506c0132f60SStefan Roese 	/* PLL Power up */
1507c0132f60SStefan Roese 	debug("stage: UTMI PHY power up PLL\n");
1508c0132f60SStefan Roese 	for (i = 0; i < utmi_phy_count; i++) {
1509c0132f60SStefan Roese 		reg_set(cp110_utmi_data[i].usb_cfg_addr,
1510c0132f60SStefan Roese 			0x1 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK);
1511c0132f60SStefan Roese 	}
1512c0132f60SStefan Roese 
1513c0132f60SStefan Roese 	debug_exit();
1514c0132f60SStefan Roese 	return;
1515c0132f60SStefan Roese }
1516c0132f60SStefan Roese 
1517c0132f60SStefan Roese /*
1518c0132f60SStefan Roese  * comphy_dedicated_phys_init initialize the dedicated PHYs
1519c0132f60SStefan Roese  * - not muxed SerDes lanes e.g. UTMI PHY
1520c0132f60SStefan Roese  */
1521c0132f60SStefan Roese void comphy_dedicated_phys_init(void)
1522c0132f60SStefan Roese {
1523c0132f60SStefan Roese 	struct utmi_phy_data cp110_utmi_data[MAX_UTMI_PHY_COUNT];
1524c0132f60SStefan Roese 	int node;
1525c0132f60SStefan Roese 	int i;
1526c0132f60SStefan Roese 
1527c0132f60SStefan Roese 	debug_enter();
1528c0132f60SStefan Roese 	debug("Initialize USB UTMI PHYs\n");
1529c0132f60SStefan Roese 
1530c0132f60SStefan Roese 	/* Find the UTMI phy node in device tree and go over them */
1531c0132f60SStefan Roese 	node = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
1532c0132f60SStefan Roese 					     "marvell,mvebu-utmi-2.6.0");
1533c0132f60SStefan Roese 
1534c0132f60SStefan Roese 	i = 0;
1535c0132f60SStefan Roese 	while (node > 0) {
1536c0132f60SStefan Roese 		/* get base address of UTMI phy */
1537c0132f60SStefan Roese 		cp110_utmi_data[i].utmi_base_addr =
1538c0132f60SStefan Roese 			(void __iomem *)fdtdec_get_addr_size_auto_noparent(
1539c0132f60SStefan Roese 				gd->fdt_blob, node, "reg", 0, NULL, true);
1540c0132f60SStefan Roese 		if (cp110_utmi_data[i].utmi_base_addr == NULL) {
1541c0132f60SStefan Roese 			error("UTMI PHY base address is invalid\n");
1542c0132f60SStefan Roese 			i++;
1543c0132f60SStefan Roese 			continue;
1544c0132f60SStefan Roese 		}
1545c0132f60SStefan Roese 
1546c0132f60SStefan Roese 		/* get usb config address */
1547c0132f60SStefan Roese 		cp110_utmi_data[i].usb_cfg_addr =
1548c0132f60SStefan Roese 			(void __iomem *)fdtdec_get_addr_size_auto_noparent(
1549c0132f60SStefan Roese 				gd->fdt_blob, node, "reg", 1, NULL, true);
1550c0132f60SStefan Roese 		if (cp110_utmi_data[i].usb_cfg_addr == NULL) {
1551c0132f60SStefan Roese 			error("UTMI PHY base address is invalid\n");
1552c0132f60SStefan Roese 			i++;
1553c0132f60SStefan Roese 			continue;
1554c0132f60SStefan Roese 		}
1555c0132f60SStefan Roese 
1556c0132f60SStefan Roese 		/* get UTMI config address */
1557c0132f60SStefan Roese 		cp110_utmi_data[i].utmi_cfg_addr =
1558c0132f60SStefan Roese 			(void __iomem *)fdtdec_get_addr_size_auto_noparent(
1559c0132f60SStefan Roese 				gd->fdt_blob, node, "reg", 2, NULL, true);
1560c0132f60SStefan Roese 		if (cp110_utmi_data[i].utmi_cfg_addr == NULL) {
1561c0132f60SStefan Roese 			error("UTMI PHY base address is invalid\n");
1562c0132f60SStefan Roese 			i++;
1563c0132f60SStefan Roese 			continue;
1564c0132f60SStefan Roese 		}
1565c0132f60SStefan Roese 
1566c0132f60SStefan Roese 		/*
1567c0132f60SStefan Roese 		 * get the port number (to check if the utmi connected to
1568c0132f60SStefan Roese 		 * host/device)
1569c0132f60SStefan Roese 		 */
1570c0132f60SStefan Roese 		cp110_utmi_data[i].utmi_phy_port = fdtdec_get_int(
1571c0132f60SStefan Roese 			gd->fdt_blob, node, "utmi-port", UTMI_PHY_INVALID);
1572c0132f60SStefan Roese 		if (cp110_utmi_data[i].utmi_phy_port == UTMI_PHY_INVALID) {
1573c0132f60SStefan Roese 			error("UTMI PHY port type is invalid\n");
1574c0132f60SStefan Roese 			i++;
1575c0132f60SStefan Roese 			continue;
1576c0132f60SStefan Roese 		}
1577c0132f60SStefan Roese 
1578c0132f60SStefan Roese 		node = fdt_node_offset_by_compatible(
1579c0132f60SStefan Roese 			gd->fdt_blob, node, "marvell,mvebu-utmi-2.6.0");
1580c0132f60SStefan Roese 		i++;
1581c0132f60SStefan Roese 	}
1582c0132f60SStefan Roese 
1583c0132f60SStefan Roese 	if (i > 0)
1584c0132f60SStefan Roese 		comphy_utmi_phy_init(i, cp110_utmi_data);
1585c0132f60SStefan Roese 
1586c0132f60SStefan Roese 	debug_exit();
1587c0132f60SStefan Roese }
1588c0132f60SStefan Roese 
1589c0132f60SStefan Roese static void comphy_mux_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
1590c0132f60SStefan Roese 				  struct comphy_map *serdes_map)
1591c0132f60SStefan Roese {
1592c0132f60SStefan Roese 	void __iomem *comphy_base_addr;
1593c0132f60SStefan Roese 	struct comphy_map comphy_map_pipe_data[MAX_LANE_OPTIONS];
1594c0132f60SStefan Roese 	struct comphy_map comphy_map_phy_data[MAX_LANE_OPTIONS];
1595c0132f60SStefan Roese 	u32 lane, comphy_max_count;
1596c0132f60SStefan Roese 
1597c0132f60SStefan Roese 	comphy_max_count = ptr_chip_cfg->comphy_lanes_count;
1598c0132f60SStefan Roese 	comphy_base_addr = ptr_chip_cfg->comphy_base_addr;
1599c0132f60SStefan Roese 
1600c0132f60SStefan Roese 	/*
1601c0132f60SStefan Roese 	 * Copy the SerDes map configuration for PIPE map and PHY map
1602c0132f60SStefan Roese 	 * the comphy_mux_init modify the type of the lane if the type
1603c0132f60SStefan Roese 	 * is not valid because we have 2 selectores run the
1604c0132f60SStefan Roese 	 * comphy_mux_init twice and after that update the original
1605c0132f60SStefan Roese 	 * serdes_map
1606c0132f60SStefan Roese 	 */
1607c0132f60SStefan Roese 	for (lane = 0; lane < comphy_max_count; lane++) {
1608c0132f60SStefan Roese 		comphy_map_pipe_data[lane].type = serdes_map[lane].type;
1609c0132f60SStefan Roese 		comphy_map_pipe_data[lane].speed = serdes_map[lane].speed;
1610c0132f60SStefan Roese 		comphy_map_phy_data[lane].type = serdes_map[lane].type;
1611c0132f60SStefan Roese 		comphy_map_phy_data[lane].speed = serdes_map[lane].speed;
1612c0132f60SStefan Roese 	}
1613c0132f60SStefan Roese 	ptr_chip_cfg->mux_data = cp110_comphy_phy_mux_data;
1614c0132f60SStefan Roese 	comphy_mux_init(ptr_chip_cfg, comphy_map_phy_data,
1615c0132f60SStefan Roese 			comphy_base_addr + COMMON_SELECTOR_PHY_OFFSET);
1616c0132f60SStefan Roese 
1617c0132f60SStefan Roese 	ptr_chip_cfg->mux_data = cp110_comphy_pipe_mux_data;
1618c0132f60SStefan Roese 	comphy_mux_init(ptr_chip_cfg, comphy_map_pipe_data,
1619c0132f60SStefan Roese 			comphy_base_addr + COMMON_SELECTOR_PIPE_OFFSET);
1620c0132f60SStefan Roese 	/* Fix the type after check the PHY and PIPE configuration */
1621c0132f60SStefan Roese 	for (lane = 0; lane < comphy_max_count; lane++) {
1622c0132f60SStefan Roese 		if ((comphy_map_pipe_data[lane].type == PHY_TYPE_UNCONNECTED) &&
1623c0132f60SStefan Roese 		    (comphy_map_phy_data[lane].type == PHY_TYPE_UNCONNECTED))
1624c0132f60SStefan Roese 			serdes_map[lane].type = PHY_TYPE_UNCONNECTED;
1625c0132f60SStefan Roese 	}
1626c0132f60SStefan Roese }
1627c0132f60SStefan Roese 
1628c0132f60SStefan Roese int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
1629c0132f60SStefan Roese 		      struct comphy_map *serdes_map)
1630c0132f60SStefan Roese {
1631c0132f60SStefan Roese 	struct comphy_map *ptr_comphy_map;
1632c0132f60SStefan Roese 	void __iomem *comphy_base_addr, *hpipe_base_addr;
1633c0132f60SStefan Roese 	u32 comphy_max_count, lane, ret = 0;
1634c0132f60SStefan Roese 	u32 pcie_width = 0;
1635c0132f60SStefan Roese 
1636c0132f60SStefan Roese 	debug_enter();
1637c0132f60SStefan Roese 
1638c0132f60SStefan Roese 	comphy_max_count = ptr_chip_cfg->comphy_lanes_count;
1639c0132f60SStefan Roese 	comphy_base_addr = ptr_chip_cfg->comphy_base_addr;
1640c0132f60SStefan Roese 	hpipe_base_addr = ptr_chip_cfg->hpipe3_base_addr;
1641c0132f60SStefan Roese 
1642c0132f60SStefan Roese 	/* Config Comphy mux configuration */
1643c0132f60SStefan Roese 	comphy_mux_cp110_init(ptr_chip_cfg, serdes_map);
1644c0132f60SStefan Roese 
1645c0132f60SStefan Roese 	/* Check if the first 4 lanes configured as By-4 */
1646c0132f60SStefan Roese 	for (lane = 0, ptr_comphy_map = serdes_map; lane < 4;
1647c0132f60SStefan Roese 	     lane++, ptr_comphy_map++) {
1648c0132f60SStefan Roese 		if (ptr_comphy_map->type != PHY_TYPE_PEX0)
1649c0132f60SStefan Roese 			break;
1650c0132f60SStefan Roese 		pcie_width++;
1651c0132f60SStefan Roese 	}
1652c0132f60SStefan Roese 
1653c0132f60SStefan Roese 	for (lane = 0, ptr_comphy_map = serdes_map; lane < comphy_max_count;
1654c0132f60SStefan Roese 	     lane++, ptr_comphy_map++) {
1655c0132f60SStefan Roese 		debug("Initialize serdes number %d\n", lane);
1656c0132f60SStefan Roese 		debug("Serdes type = 0x%x\n", ptr_comphy_map->type);
1657c0132f60SStefan Roese 		if (lane == 4) {
1658c0132f60SStefan Roese 			/*
1659c0132f60SStefan Roese 			 * PCIe lanes above the first 4 lanes, can be only
1660c0132f60SStefan Roese 			 * by1
1661c0132f60SStefan Roese 			 */
1662c0132f60SStefan Roese 			pcie_width = 1;
1663c0132f60SStefan Roese 		}
1664c0132f60SStefan Roese 		switch (ptr_comphy_map->type) {
1665c0132f60SStefan Roese 		case PHY_TYPE_UNCONNECTED:
1666c0132f60SStefan Roese 			continue;
1667c0132f60SStefan Roese 			break;
1668c0132f60SStefan Roese 		case PHY_TYPE_PEX0:
1669c0132f60SStefan Roese 		case PHY_TYPE_PEX1:
1670c0132f60SStefan Roese 		case PHY_TYPE_PEX2:
1671c0132f60SStefan Roese 		case PHY_TYPE_PEX3:
1672c0132f60SStefan Roese 			ret = comphy_pcie_power_up(
1673c0132f60SStefan Roese 				lane, pcie_width, ptr_comphy_map->clk_src,
16747dda98e0SStefan Roese 				serdes_map->end_point,
1675c0132f60SStefan Roese 				hpipe_base_addr, comphy_base_addr);
1676c0132f60SStefan Roese 			break;
1677c0132f60SStefan Roese 		case PHY_TYPE_SATA0:
1678c0132f60SStefan Roese 		case PHY_TYPE_SATA1:
1679c0132f60SStefan Roese 		case PHY_TYPE_SATA2:
1680c0132f60SStefan Roese 		case PHY_TYPE_SATA3:
1681c0132f60SStefan Roese 			ret = comphy_sata_power_up(
1682c0132f60SStefan Roese 				lane, hpipe_base_addr, comphy_base_addr,
1683c0132f60SStefan Roese 				ptr_chip_cfg->comphy_index);
1684c0132f60SStefan Roese 			break;
1685c0132f60SStefan Roese 		case PHY_TYPE_USB3_HOST0:
1686c0132f60SStefan Roese 		case PHY_TYPE_USB3_HOST1:
1687c0132f60SStefan Roese 		case PHY_TYPE_USB3_DEVICE:
1688c0132f60SStefan Roese 			ret = comphy_usb3_power_up(lane, hpipe_base_addr,
1689c0132f60SStefan Roese 						   comphy_base_addr);
1690c0132f60SStefan Roese 			break;
1691c0132f60SStefan Roese 		case PHY_TYPE_SGMII0:
1692c0132f60SStefan Roese 		case PHY_TYPE_SGMII1:
1693c0132f60SStefan Roese 		case PHY_TYPE_SGMII2:
1694c0132f60SStefan Roese 		case PHY_TYPE_SGMII3:
1695c0132f60SStefan Roese 			if (ptr_comphy_map->speed == PHY_SPEED_INVALID) {
1696c0132f60SStefan Roese 				debug("Warning: SGMII PHY speed in lane %d is invalid, set PHY speed to 1.25G\n",
1697c0132f60SStefan Roese 				      lane);
1698c0132f60SStefan Roese 				ptr_comphy_map->speed = PHY_SPEED_1_25G;
1699c0132f60SStefan Roese 			}
1700c0132f60SStefan Roese 			ret = comphy_sgmii_power_up(
1701c0132f60SStefan Roese 				lane, ptr_comphy_map->speed, hpipe_base_addr,
1702c0132f60SStefan Roese 				comphy_base_addr);
1703c0132f60SStefan Roese 			break;
1704cb686454SStefan Roese 		case PHY_TYPE_SFI:
1705cb686454SStefan Roese 			ret = comphy_sfi_power_up(lane, hpipe_base_addr,
1706c0132f60SStefan Roese 						  comphy_base_addr);
1707c0132f60SStefan Roese 			break;
1708c0132f60SStefan Roese 		case PHY_TYPE_RXAUI0:
1709c0132f60SStefan Roese 		case PHY_TYPE_RXAUI1:
1710c0132f60SStefan Roese 			ret = comphy_rxauii_power_up(lane, hpipe_base_addr,
1711c0132f60SStefan Roese 						     comphy_base_addr);
1712c0132f60SStefan Roese 			break;
1713c0132f60SStefan Roese 		default:
1714c0132f60SStefan Roese 			debug("Unknown SerDes type, skip initialize SerDes %d\n",
1715c0132f60SStefan Roese 			      lane);
1716c0132f60SStefan Roese 			break;
1717c0132f60SStefan Roese 		}
1718c0132f60SStefan Roese 		if (ret == 0) {
1719c0132f60SStefan Roese 			/*
1720c0132f60SStefan Roese 			 * If interface wans't initialiuzed, set the lane to
1721c0132f60SStefan Roese 			 * PHY_TYPE_UNCONNECTED state.
1722c0132f60SStefan Roese 			 */
1723c0132f60SStefan Roese 			ptr_comphy_map->type = PHY_TYPE_UNCONNECTED;
1724c0132f60SStefan Roese 			error("PLL is not locked - Failed to initialize lane %d\n",
1725c0132f60SStefan Roese 			      lane);
1726c0132f60SStefan Roese 		}
1727c0132f60SStefan Roese 	}
1728c0132f60SStefan Roese 
1729c0132f60SStefan Roese 	debug_exit();
1730c0132f60SStefan Roese 	return 0;
1731c0132f60SStefan Roese }
1732