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 */ 52d37f020eSStefan Roese {PHY_TYPE_XAUI0, 0x1}, {PHY_TYPE_RXAUI0, 0x1}, {PHY_TYPE_SFI, 0x2}, 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 */ 363*c01f9fe8SIgal Liberman mask = HPIPE_G3_SET_1_G3_RX_SELMUPI_MASK; 364*c01f9fe8SIgal Liberman data = 0x1 << HPIPE_G3_SET_1_G3_RX_SELMUPI_OFFSET; 365c0132f60SStefan Roese 366*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_RX_SELMUPF_MASK; 367*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G3_SET_1_G3_RX_SELMUPF_OFFSET; 368c0132f60SStefan Roese 369*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_SAMPLER_INPAIRX2_EN_MASK; 370*c01f9fe8SIgal Liberman data |= 0x0 << HPIPE_G3_SET_1_G3_SAMPLER_INPAIRX2_EN_OFFSET; 371*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G3_SET_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"); 696*c01f9fe8SIgal Liberman /* Set analog parameters from ETP(HW) */ 697*c01f9fe8SIgal Liberman /* G1 settings */ 698*c01f9fe8SIgal Liberman mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK; 699*c01f9fe8SIgal Liberman data = 0x0 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET; 700*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK; 701*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET; 702*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SET_1_G1_RX_SELMUFI_MASK; 703*c01f9fe8SIgal Liberman data |= 0x0 << HPIPE_G1_SET_1_G1_RX_SELMUFI_OFFSET; 704*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SET_1_G1_RX_SELMUFF_MASK; 705*c01f9fe8SIgal Liberman data |= 0x3 << HPIPE_G1_SET_1_G1_RX_SELMUFF_OFFSET; 706*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SET_1_G1_RX_DIGCK_DIV_MASK; 707*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DIGCK_DIV_OFFSET; 708*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask); 709*c01f9fe8SIgal Liberman 710*c01f9fe8SIgal Liberman mask = HPIPE_G1_SETTINGS_3_G1_FFE_CAP_SEL_MASK; 711*c01f9fe8SIgal Liberman data = 0xf << HPIPE_G1_SETTINGS_3_G1_FFE_CAP_SEL_OFFSET; 712*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SETTINGS_3_G1_FFE_RES_SEL_MASK; 713*c01f9fe8SIgal Liberman data |= 0x2 << HPIPE_G1_SETTINGS_3_G1_FFE_RES_SEL_OFFSET; 714*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SETTINGS_3_G1_FFE_SETTING_FORCE_MASK; 715*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SETTINGS_3_G1_FFE_SETTING_FORCE_OFFSET; 716*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SETTINGS_3_G1_FFE_DEG_RES_LEVEL_MASK; 717*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SETTINGS_3_G1_FFE_DEG_RES_LEVEL_OFFSET; 718*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SETTINGS_3_G1_FFE_LOAD_RES_LEVEL_MASK; 719*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SETTINGS_3_G1_FFE_LOAD_RES_LEVEL_OFFSET; 720*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G1_SETTINGS_3_REG, data, mask); 721*c01f9fe8SIgal Liberman 722*c01f9fe8SIgal Liberman /* G2 settings */ 723*c01f9fe8SIgal Liberman mask = HPIPE_G2_SET_1_G2_RX_SELMUPI_MASK; 724*c01f9fe8SIgal Liberman data = 0x0 << HPIPE_G2_SET_1_G2_RX_SELMUPI_OFFSET; 725*c01f9fe8SIgal Liberman mask |= HPIPE_G2_SET_1_G2_RX_SELMUPP_MASK; 726*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G2_SET_1_G2_RX_SELMUPP_OFFSET; 727*c01f9fe8SIgal Liberman mask |= HPIPE_G2_SET_1_G2_RX_SELMUFI_MASK; 728*c01f9fe8SIgal Liberman data |= 0x0 << HPIPE_G2_SET_1_G2_RX_SELMUFI_OFFSET; 729*c01f9fe8SIgal Liberman mask |= HPIPE_G2_SET_1_G2_RX_SELMUFF_MASK; 730*c01f9fe8SIgal Liberman data |= 0x3 << HPIPE_G2_SET_1_G2_RX_SELMUFF_OFFSET; 731*c01f9fe8SIgal Liberman mask |= HPIPE_G2_SET_1_G2_RX_DIGCK_DIV_MASK; 732*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G2_SET_1_G2_RX_DIGCK_DIV_OFFSET; 733*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G2_SET_1_REG, data, mask); 734*c01f9fe8SIgal Liberman 735*c01f9fe8SIgal Liberman /* G3 settings */ 736*c01f9fe8SIgal Liberman mask = HPIPE_G3_SET_1_G3_RX_SELMUPI_MASK; 737*c01f9fe8SIgal Liberman data = 0x2 << HPIPE_G3_SET_1_G3_RX_SELMUPI_OFFSET; 738*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_RX_SELMUPF_MASK; 739*c01f9fe8SIgal Liberman data |= 0x2 << HPIPE_G3_SET_1_G3_RX_SELMUPF_OFFSET; 740*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_RX_SELMUFI_MASK; 741*c01f9fe8SIgal Liberman data |= 0x3 << HPIPE_G3_SET_1_G3_RX_SELMUFI_OFFSET; 742*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_RX_SELMUFF_MASK; 743*c01f9fe8SIgal Liberman data |= 0x3 << HPIPE_G3_SET_1_G3_RX_SELMUFF_OFFSET; 744*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_RX_DFE_EN_MASK; 745*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G3_SET_1_G3_RX_DFE_EN_OFFSET; 746*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_RX_DIGCK_DIV_MASK; 747*c01f9fe8SIgal Liberman data |= 0x2 << HPIPE_G3_SET_1_G3_RX_DIGCK_DIV_OFFSET; 748*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_1_G3_SAMPLER_INPAIRX2_EN_MASK; 749*c01f9fe8SIgal Liberman data |= 0x0 << HPIPE_G3_SET_1_G3_SAMPLER_INPAIRX2_EN_OFFSET; 750*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G3_SET_1_REG, data, mask); 751*c01f9fe8SIgal Liberman 752*c01f9fe8SIgal Liberman /* DTL Control */ 753*c01f9fe8SIgal Liberman mask = HPIPE_PWR_CTR_DTL_SQ_DET_EN_MASK; 754*c01f9fe8SIgal Liberman data = 0x1 << HPIPE_PWR_CTR_DTL_SQ_DET_EN_OFFSET; 755*c01f9fe8SIgal Liberman mask |= HPIPE_PWR_CTR_DTL_SQ_PLOOP_EN_MASK; 756*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_PWR_CTR_DTL_SQ_PLOOP_EN_OFFSET; 757*c01f9fe8SIgal Liberman mask |= HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK; 758*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET; 759*c01f9fe8SIgal Liberman mask |= HPIPE_PWR_CTR_DTL_CLAMPING_SEL_MASK; 760*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_PWR_CTR_DTL_CLAMPING_SEL_OFFSET; 761*c01f9fe8SIgal Liberman mask |= HPIPE_PWR_CTR_DTL_INTPCLK_DIV_FORCE_MASK; 762*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_PWR_CTR_DTL_INTPCLK_DIV_FORCE_OFFSET; 763*c01f9fe8SIgal Liberman mask |= HPIPE_PWR_CTR_DTL_CLK_MODE_MASK; 764*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_PWR_CTR_DTL_CLK_MODE_OFFSET; 765*c01f9fe8SIgal Liberman mask |= HPIPE_PWR_CTR_DTL_CLK_MODE_FORCE_MASK; 766*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_PWR_CTR_DTL_CLK_MODE_FORCE_OFFSET; 767*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, data, mask); 768*c01f9fe8SIgal Liberman 769*c01f9fe8SIgal Liberman /* Trigger sampler enable pulse (by toggleing the bit) */ 770*c01f9fe8SIgal Liberman mask = HPIPE_SMAPLER_MASK; 771*c01f9fe8SIgal Liberman data = 0x1 << HPIPE_SMAPLER_OFFSET; 772*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_SAMPLER_N_PROC_CALIB_CTRL_REG, data, mask); 773*c01f9fe8SIgal Liberman mask = HPIPE_SMAPLER_MASK; 774*c01f9fe8SIgal Liberman data = 0x0 << HPIPE_SMAPLER_OFFSET; 775*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_SAMPLER_N_PROC_CALIB_CTRL_REG, data, mask); 776*c01f9fe8SIgal Liberman 777*c01f9fe8SIgal Liberman /* VDD Calibration Control 3 */ 778*c01f9fe8SIgal Liberman mask = HPIPE_EXT_SELLV_RXSAMPL_MASK; 779*c01f9fe8SIgal Liberman data = 0x10 << HPIPE_EXT_SELLV_RXSAMPL_OFFSET; 780*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_VDD_CAL_CTRL_REG, data, mask); 781*c01f9fe8SIgal Liberman 782*c01f9fe8SIgal Liberman /* DFE Resolution Control */ 783*c01f9fe8SIgal Liberman mask = HPIPE_DFE_RES_FORCE_MASK; 784*c01f9fe8SIgal Liberman data = 0x1 << HPIPE_DFE_RES_FORCE_OFFSET; 785*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_DFE_REG0, data, mask); 786*c01f9fe8SIgal Liberman 787*c01f9fe8SIgal Liberman /* DFE F3-F5 Coefficient Control */ 788*c01f9fe8SIgal Liberman mask = HPIPE_DFE_F3_F5_DFE_EN_MASK; 789*c01f9fe8SIgal Liberman data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET; 790*c01f9fe8SIgal Liberman mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK; 791*c01f9fe8SIgal Liberman data = 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET; 792*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask); 793*c01f9fe8SIgal Liberman 794*c01f9fe8SIgal Liberman /* G3 Setting 3 */ 795*c01f9fe8SIgal Liberman mask = HPIPE_G3_FFE_CAP_SEL_MASK; 796*c01f9fe8SIgal Liberman data = 0xf << HPIPE_G3_FFE_CAP_SEL_OFFSET; 797*c01f9fe8SIgal Liberman mask |= HPIPE_G3_FFE_RES_SEL_MASK; 798*c01f9fe8SIgal Liberman data |= 0x4 << HPIPE_G3_FFE_RES_SEL_OFFSET; 799*c01f9fe8SIgal Liberman mask |= HPIPE_G3_FFE_SETTING_FORCE_MASK; 800*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G3_FFE_SETTING_FORCE_OFFSET; 801*c01f9fe8SIgal Liberman mask |= HPIPE_G3_FFE_DEG_RES_LEVEL_MASK; 802*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G3_FFE_DEG_RES_LEVEL_OFFSET; 803*c01f9fe8SIgal Liberman mask |= HPIPE_G3_FFE_LOAD_RES_LEVEL_MASK; 804*c01f9fe8SIgal Liberman data |= 0x3 << HPIPE_G3_FFE_LOAD_RES_LEVEL_OFFSET; 805*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G3_SETTING_3_REG, data, mask); 806*c01f9fe8SIgal Liberman 807*c01f9fe8SIgal Liberman /* G3 Setting 4 */ 808*c01f9fe8SIgal Liberman mask = HPIPE_G3_DFE_RES_MASK; 809*c01f9fe8SIgal Liberman data = 0x2 << HPIPE_G3_DFE_RES_OFFSET; 810*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G3_SETTING_4_REG, data, mask); 811*c01f9fe8SIgal Liberman 812*c01f9fe8SIgal Liberman /* Offset Phase Control */ 813*c01f9fe8SIgal Liberman mask = HPIPE_OS_PH_OFFSET_MASK; 814*c01f9fe8SIgal Liberman data = 0x5c << HPIPE_OS_PH_OFFSET_OFFSET; 815*c01f9fe8SIgal Liberman mask |= HPIPE_OS_PH_OFFSET_FORCE_MASK; 816*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_OS_PH_OFFSET_FORCE_OFFSET; 817*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_PHASE_CONTROL_REG, data, mask); 818*c01f9fe8SIgal Liberman mask = HPIPE_OS_PH_VALID_MASK; 819*c01f9fe8SIgal Liberman data = 0x1 << HPIPE_OS_PH_VALID_OFFSET; 820*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_PHASE_CONTROL_REG, data, mask); 821*c01f9fe8SIgal Liberman mask = HPIPE_OS_PH_VALID_MASK; 822*c01f9fe8SIgal Liberman data = 0x0 << HPIPE_OS_PH_VALID_OFFSET; 823*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_PHASE_CONTROL_REG, data, mask); 824*c01f9fe8SIgal Liberman 825*c01f9fe8SIgal Liberman /* Set G1 TX amplitude and TX post emphasis value */ 826*c01f9fe8SIgal Liberman mask = HPIPE_G1_SET_0_G1_TX_AMP_MASK; 827*c01f9fe8SIgal Liberman data = 0x8 << HPIPE_G1_SET_0_G1_TX_AMP_OFFSET; 828*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SET_0_G1_TX_AMP_ADJ_MASK; 829*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SET_0_G1_TX_AMP_ADJ_OFFSET; 830*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SET_0_G1_TX_EMPH1_MASK; 831*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET; 832*c01f9fe8SIgal Liberman mask |= HPIPE_G1_SET_0_G1_TX_EMPH1_EN_MASK; 833*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G1_SET_0_G1_TX_EMPH1_EN_OFFSET; 834*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G1_SET_0_REG, data, mask); 835*c01f9fe8SIgal Liberman 836*c01f9fe8SIgal Liberman /* Set G2 TX amplitude and TX post emphasis value */ 837*c01f9fe8SIgal Liberman mask = HPIPE_G2_SET_0_G2_TX_AMP_MASK; 838*c01f9fe8SIgal Liberman data = 0xa << HPIPE_G2_SET_0_G2_TX_AMP_OFFSET; 839*c01f9fe8SIgal Liberman mask |= HPIPE_G2_SET_0_G2_TX_AMP_ADJ_MASK; 840*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G2_SET_0_G2_TX_AMP_ADJ_OFFSET; 841*c01f9fe8SIgal Liberman mask |= HPIPE_G2_SET_0_G2_TX_EMPH1_MASK; 842*c01f9fe8SIgal Liberman data |= 0x2 << HPIPE_G2_SET_0_G2_TX_EMPH1_OFFSET; 843*c01f9fe8SIgal Liberman mask |= HPIPE_G2_SET_0_G2_TX_EMPH1_EN_MASK; 844*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G2_SET_0_G2_TX_EMPH1_EN_OFFSET; 845*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G2_SET_0_REG, data, mask); 846*c01f9fe8SIgal Liberman 847*c01f9fe8SIgal Liberman /* Set G3 TX amplitude and TX post emphasis value */ 848*c01f9fe8SIgal Liberman mask = HPIPE_G3_SET_0_G3_TX_AMP_MASK; 849*c01f9fe8SIgal Liberman data = 0xe << HPIPE_G3_SET_0_G3_TX_AMP_OFFSET; 850*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_0_G3_TX_AMP_ADJ_MASK; 851*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G3_SET_0_G3_TX_AMP_ADJ_OFFSET; 852*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_0_G3_TX_EMPH1_MASK; 853*c01f9fe8SIgal Liberman data |= 0x6 << HPIPE_G3_SET_0_G3_TX_EMPH1_OFFSET; 854*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_0_G3_TX_EMPH1_EN_MASK; 855*c01f9fe8SIgal Liberman data |= 0x1 << HPIPE_G3_SET_0_G3_TX_EMPH1_EN_OFFSET; 856*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_0_G3_TX_SLEW_RATE_SEL_MASK; 857*c01f9fe8SIgal Liberman data |= 0x4 << HPIPE_G3_SET_0_G3_TX_SLEW_RATE_SEL_OFFSET; 858*c01f9fe8SIgal Liberman mask |= HPIPE_G3_SET_0_G3_TX_SLEW_CTRL_EN_MASK; 859*c01f9fe8SIgal Liberman data |= 0x0 << HPIPE_G3_SET_0_G3_TX_SLEW_CTRL_EN_OFFSET; 860*c01f9fe8SIgal Liberman reg_set(hpipe_addr + HPIPE_G3_SET_0_REG, data, mask); 861*c01f9fe8SIgal Liberman 862*c01f9fe8SIgal Liberman /* SERDES External Configuration 2 register */ 863*c01f9fe8SIgal Liberman mask = SD_EXTERNAL_CONFIG2_SSC_ENABLE_MASK; 864*c01f9fe8SIgal Liberman data = 0x1 << SD_EXTERNAL_CONFIG2_SSC_ENABLE_OFFSET; 865*c01f9fe8SIgal Liberman reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG, data, mask); 866c0132f60SStefan Roese 867c0132f60SStefan Roese /* DFE reset sequence */ 868c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_CTR_REG, 869c0132f60SStefan Roese 0x1 << HPIPE_PWR_CTR_RST_DFE_OFFSET, 870c0132f60SStefan Roese HPIPE_PWR_CTR_RST_DFE_MASK); 871c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_CTR_REG, 872c0132f60SStefan Roese 0x0 << HPIPE_PWR_CTR_RST_DFE_OFFSET, 873c0132f60SStefan Roese HPIPE_PWR_CTR_RST_DFE_MASK); 874c0132f60SStefan Roese /* SW reset for interupt logic */ 875c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_CTR_REG, 876c0132f60SStefan Roese 0x1 << HPIPE_PWR_CTR_SFT_RST_OFFSET, 877c0132f60SStefan Roese HPIPE_PWR_CTR_SFT_RST_MASK); 878c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_CTR_REG, 879c0132f60SStefan Roese 0x0 << HPIPE_PWR_CTR_SFT_RST_OFFSET, 880c0132f60SStefan Roese HPIPE_PWR_CTR_SFT_RST_MASK); 881c0132f60SStefan Roese 882c0132f60SStefan Roese debug("stage: Comphy power up\n"); 883c0132f60SStefan Roese /* 884c0132f60SStefan Roese * MAC configuration power up comphy - power up PLL/TX/RX 885c0132f60SStefan Roese * use indirect address for vendor spesific SATA control register 886c0132f60SStefan Roese */ 887c0132f60SStefan Roese reg_set(sata_base + SATA3_VENDOR_ADDRESS, 888c0132f60SStefan Roese SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET, 889c0132f60SStefan Roese SATA3_VENDOR_ADDR_MASK); 890c0132f60SStefan Roese /* SATA 0 power up */ 891c0132f60SStefan Roese mask = SATA3_CTRL_SATA0_PD_MASK; 892c0132f60SStefan Roese data = 0x0 << SATA3_CTRL_SATA0_PD_OFFSET; 893c0132f60SStefan Roese /* SATA 1 power up */ 894c0132f60SStefan Roese mask |= SATA3_CTRL_SATA1_PD_MASK; 895c0132f60SStefan Roese data |= 0x0 << SATA3_CTRL_SATA1_PD_OFFSET; 896c0132f60SStefan Roese /* SATA SSU enable */ 897c0132f60SStefan Roese mask |= SATA3_CTRL_SATA1_ENABLE_MASK; 898c0132f60SStefan Roese data |= 0x1 << SATA3_CTRL_SATA1_ENABLE_OFFSET; 899c0132f60SStefan Roese /* SATA port 1 enable */ 900c0132f60SStefan Roese mask |= SATA3_CTRL_SATA_SSU_MASK; 901c0132f60SStefan Roese data |= 0x1 << SATA3_CTRL_SATA_SSU_OFFSET; 902c0132f60SStefan Roese reg_set(sata_base + SATA3_VENDOR_DATA, data, mask); 903c0132f60SStefan Roese 904c0132f60SStefan Roese /* MBUS request size and interface select register */ 905c0132f60SStefan Roese reg_set(sata_base + SATA3_VENDOR_ADDRESS, 906c0132f60SStefan Roese SATA_MBUS_SIZE_SELECT_REG << SATA3_VENDOR_ADDR_OFSSET, 907c0132f60SStefan Roese SATA3_VENDOR_ADDR_MASK); 908c0132f60SStefan Roese /* Mbus regret enable */ 909c0132f60SStefan Roese reg_set(sata_base + SATA3_VENDOR_DATA, 910c0132f60SStefan Roese 0x1 << SATA_MBUS_REGRET_EN_OFFSET, SATA_MBUS_REGRET_EN_MASK); 911c0132f60SStefan Roese 912c0132f60SStefan Roese debug("stage: Check PLL\n"); 913c0132f60SStefan Roese 914c0132f60SStefan Roese addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; 915c0132f60SStefan Roese data = SD_EXTERNAL_STATUS0_PLL_TX_MASK & 916c0132f60SStefan Roese SD_EXTERNAL_STATUS0_PLL_RX_MASK; 917c0132f60SStefan Roese mask = data; 918c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 15000); 919c0132f60SStefan Roese if (data != 0) { 920c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", 921c0132f60SStefan Roese hpipe_addr + HPIPE_LANE_STATUS1_REG, data); 922c0132f60SStefan Roese error("SD_EXTERNAL_STATUS0_PLL_TX is %d, SD_EXTERNAL_STATUS0_PLL_RX is %d\n", 923c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK), 924c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK)); 925c0132f60SStefan Roese ret = 0; 926c0132f60SStefan Roese } 927c0132f60SStefan Roese 928c0132f60SStefan Roese debug_exit(); 929c0132f60SStefan Roese return ret; 930c0132f60SStefan Roese } 931c0132f60SStefan Roese 932c0132f60SStefan Roese static int comphy_sgmii_power_up(u32 lane, u32 sgmii_speed, 933c0132f60SStefan Roese void __iomem *hpipe_base, 934c0132f60SStefan Roese void __iomem *comphy_base) 935c0132f60SStefan Roese { 936c0132f60SStefan Roese u32 mask, data, ret = 1; 937c0132f60SStefan Roese void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane); 938c0132f60SStefan Roese void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane); 939c0132f60SStefan Roese void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane); 940c0132f60SStefan Roese void __iomem *addr; 941c0132f60SStefan Roese 942c0132f60SStefan Roese debug_enter(); 943c0132f60SStefan Roese debug("stage: RFU configurations - hard reset comphy\n"); 944c0132f60SStefan Roese /* RFU configurations - hard reset comphy */ 945c0132f60SStefan Roese mask = COMMON_PHY_CFG1_PWR_UP_MASK; 946c0132f60SStefan Roese data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET; 947c0132f60SStefan Roese mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK; 948c0132f60SStefan Roese data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET; 949c0132f60SStefan Roese reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask); 950c0132f60SStefan Roese 951c0132f60SStefan Roese /* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */ 952c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; 953c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; 954c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK; 955c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK; 956c0132f60SStefan Roese if (sgmii_speed == PHY_SPEED_1_25G) { 957c0132f60SStefan Roese data |= 0x6 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET; 958c0132f60SStefan Roese data |= 0x6 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET; 959c0132f60SStefan Roese } else { 960c0132f60SStefan Roese /* 3.125G */ 961c0132f60SStefan Roese data |= 0x8 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET; 962c0132f60SStefan Roese data |= 0x8 << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET; 963c0132f60SStefan Roese } 964c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; 965c0132f60SStefan Roese data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; 966c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; 967c0132f60SStefan Roese data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; 968c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK; 969c0132f60SStefan Roese data |= 1 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET; 970c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); 971c0132f60SStefan Roese 972c0132f60SStefan Roese /* release from hard reset */ 973c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; 974c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; 975c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; 976c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; 977c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; 978c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; 979c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 980c0132f60SStefan Roese 981c0132f60SStefan Roese /* release from hard reset */ 982c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; 983c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; 984c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; 985c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; 986c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 987c0132f60SStefan Roese 988c0132f60SStefan Roese 989c0132f60SStefan Roese /* Wait 1ms - until band gap and ref clock ready */ 990c0132f60SStefan Roese mdelay(1); 991c0132f60SStefan Roese 992c0132f60SStefan Roese /* Start comphy Configuration */ 993c0132f60SStefan Roese debug("stage: Comphy configuration\n"); 994c0132f60SStefan Roese /* set reference clock */ 995c0132f60SStefan Roese mask = HPIPE_MISC_REFCLK_SEL_MASK; 996c0132f60SStefan Roese data = 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET; 997c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_MISC_REG, data, mask); 998c0132f60SStefan Roese /* Power and PLL Control */ 999c0132f60SStefan Roese mask = HPIPE_PWR_PLL_REF_FREQ_MASK; 1000c0132f60SStefan Roese data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET; 1001c0132f60SStefan Roese mask |= HPIPE_PWR_PLL_PHY_MODE_MASK; 1002c0132f60SStefan Roese data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET; 1003c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask); 1004c0132f60SStefan Roese /* Loopback register */ 1005c0132f60SStefan Roese mask = HPIPE_LOOPBACK_SEL_MASK; 1006c0132f60SStefan Roese data = 0x1 << HPIPE_LOOPBACK_SEL_OFFSET; 1007c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_LOOPBACK_REG, data, mask); 1008c0132f60SStefan Roese /* rx control 1 */ 1009c0132f60SStefan Roese mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK; 1010c0132f60SStefan Roese data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET; 1011c0132f60SStefan Roese mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK; 1012c0132f60SStefan Roese data |= 0x0 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET; 1013c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask); 1014c0132f60SStefan Roese /* DTL Control */ 1015c0132f60SStefan Roese mask = HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK; 1016c0132f60SStefan Roese data = 0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET; 1017c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, data, mask); 1018c0132f60SStefan Roese 1019c0132f60SStefan Roese /* Set analog paramters from ETP(HW) - for now use the default datas */ 1020c0132f60SStefan Roese debug("stage: Analog paramters from ETP(HW)\n"); 1021c0132f60SStefan Roese 1022c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SET_0_REG, 1023c0132f60SStefan Roese 0x1 << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET, 1024c0132f60SStefan Roese HPIPE_G1_SET_0_G1_TX_EMPH1_MASK); 1025c0132f60SStefan Roese 1026c0132f60SStefan Roese debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n"); 1027c0132f60SStefan Roese /* SERDES External Configuration */ 1028c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; 1029c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; 1030c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; 1031c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; 1032c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; 1033c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; 1034c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); 1035c0132f60SStefan Roese 1036c0132f60SStefan Roese /* check PLL rx & tx ready */ 1037c0132f60SStefan Roese addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; 1038c0132f60SStefan Roese data = SD_EXTERNAL_STATUS0_PLL_RX_MASK | 1039c0132f60SStefan Roese SD_EXTERNAL_STATUS0_PLL_TX_MASK; 1040c0132f60SStefan Roese mask = data; 1041c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 15000); 1042c0132f60SStefan Roese if (data != 0) { 1043c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", 1044c0132f60SStefan Roese sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); 1045c0132f60SStefan Roese error("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n", 1046c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK), 1047c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK)); 1048c0132f60SStefan Roese ret = 0; 1049c0132f60SStefan Roese } 1050c0132f60SStefan Roese 1051c0132f60SStefan Roese /* RX init */ 1052c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK; 1053c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET; 1054c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1055c0132f60SStefan Roese 1056c0132f60SStefan Roese /* check that RX init done */ 1057c0132f60SStefan Roese addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; 1058c0132f60SStefan Roese data = SD_EXTERNAL_STATUS0_RX_INIT_MASK; 1059c0132f60SStefan Roese mask = data; 1060c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 100); 1061c0132f60SStefan Roese if (data != 0) { 1062c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); 1063c0132f60SStefan Roese error("SD_EXTERNAL_STATUS0_RX_INIT is 0\n"); 1064c0132f60SStefan Roese ret = 0; 1065c0132f60SStefan Roese } 1066c0132f60SStefan Roese 1067c0132f60SStefan Roese debug("stage: RF Reset\n"); 1068c0132f60SStefan Roese /* RF Reset */ 1069c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK; 1070c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET; 1071c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; 1072c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; 1073c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1074c0132f60SStefan Roese 1075c0132f60SStefan Roese debug_exit(); 1076c0132f60SStefan Roese return ret; 1077c0132f60SStefan Roese } 1078c0132f60SStefan Roese 1079cb686454SStefan Roese static int comphy_sfi_power_up(u32 lane, void __iomem *hpipe_base, 1080c0132f60SStefan Roese void __iomem *comphy_base) 1081c0132f60SStefan Roese { 1082c0132f60SStefan Roese u32 mask, data, ret = 1; 1083c0132f60SStefan Roese void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane); 1084c0132f60SStefan Roese void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane); 1085c0132f60SStefan Roese void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane); 1086c0132f60SStefan Roese void __iomem *addr; 1087c0132f60SStefan Roese 1088c0132f60SStefan Roese debug_enter(); 1089c0132f60SStefan Roese debug("stage: RFU configurations - hard reset comphy\n"); 1090c0132f60SStefan Roese /* RFU configurations - hard reset comphy */ 1091c0132f60SStefan Roese mask = COMMON_PHY_CFG1_PWR_UP_MASK; 1092c0132f60SStefan Roese data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET; 1093c0132f60SStefan Roese mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK; 1094c0132f60SStefan Roese data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET; 1095c0132f60SStefan Roese reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask); 1096c0132f60SStefan Roese 1097c0132f60SStefan Roese /* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */ 1098c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; 1099c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; 1100c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK; 1101c0132f60SStefan Roese data |= 0xE << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET; 1102c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK; 1103c0132f60SStefan Roese data |= 0xE << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET; 1104c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; 1105c0132f60SStefan Roese data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; 1106c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; 1107c0132f60SStefan Roese data |= 0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; 1108c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK; 1109c0132f60SStefan Roese data |= 0 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET; 1110c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); 1111c0132f60SStefan Roese 1112c0132f60SStefan Roese /* release from hard reset */ 1113c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; 1114c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; 1115c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; 1116c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; 1117c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; 1118c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; 1119c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1120c0132f60SStefan Roese 1121c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; 1122c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; 1123c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; 1124c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; 1125c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1126c0132f60SStefan Roese 1127c0132f60SStefan Roese 1128c0132f60SStefan Roese /* Wait 1ms - until band gap and ref clock ready */ 1129c0132f60SStefan Roese mdelay(1); 1130c0132f60SStefan Roese 1131c0132f60SStefan Roese /* Start comphy Configuration */ 1132c0132f60SStefan Roese debug("stage: Comphy configuration\n"); 1133c0132f60SStefan Roese /* set reference clock */ 1134c0132f60SStefan Roese mask = HPIPE_MISC_ICP_FORCE_MASK; 1135c0132f60SStefan Roese data = 0x1 << HPIPE_MISC_ICP_FORCE_OFFSET; 1136c0132f60SStefan Roese mask |= HPIPE_MISC_REFCLK_SEL_MASK; 1137c0132f60SStefan Roese data |= 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET; 1138c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_MISC_REG, data, mask); 1139c0132f60SStefan Roese /* Power and PLL Control */ 1140c0132f60SStefan Roese mask = HPIPE_PWR_PLL_REF_FREQ_MASK; 1141c0132f60SStefan Roese data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET; 1142c0132f60SStefan Roese mask |= HPIPE_PWR_PLL_PHY_MODE_MASK; 1143c0132f60SStefan Roese data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET; 1144c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask); 1145c0132f60SStefan Roese /* Loopback register */ 1146c0132f60SStefan Roese mask = HPIPE_LOOPBACK_SEL_MASK; 1147c0132f60SStefan Roese data = 0x1 << HPIPE_LOOPBACK_SEL_OFFSET; 1148c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_LOOPBACK_REG, data, mask); 1149c0132f60SStefan Roese /* rx control 1 */ 1150c0132f60SStefan Roese mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK; 1151c0132f60SStefan Roese data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET; 1152c0132f60SStefan Roese mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK; 1153c0132f60SStefan Roese data |= 0x1 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET; 1154c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask); 1155c0132f60SStefan Roese /* DTL Control */ 1156c0132f60SStefan Roese mask = HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK; 1157c0132f60SStefan Roese data = 0x1 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET; 1158c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, data, mask); 1159c0132f60SStefan Roese 1160c0132f60SStefan Roese /* Set analog paramters from ETP(HW) */ 1161c0132f60SStefan Roese debug("stage: Analog paramters from ETP(HW)\n"); 1162c0132f60SStefan Roese /* SERDES External Configuration 2 */ 1163c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG2_PIN_DFE_EN_MASK; 1164c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG2_PIN_DFE_EN_OFFSET; 1165c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG, data, mask); 1166c0132f60SStefan Roese /* 0x7-DFE Resolution control */ 1167c0132f60SStefan Roese mask = HPIPE_DFE_RES_FORCE_MASK; 1168c0132f60SStefan Roese data = 0x1 << HPIPE_DFE_RES_FORCE_OFFSET; 1169c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_DFE_REG0, data, mask); 1170c0132f60SStefan Roese /* 0xd-G1_Setting_0 */ 1171c0132f60SStefan Roese mask = HPIPE_G1_SET_0_G1_TX_AMP_MASK; 1172c0132f60SStefan Roese data = 0x1c << HPIPE_G1_SET_0_G1_TX_AMP_OFFSET; 1173c0132f60SStefan Roese mask |= HPIPE_G1_SET_0_G1_TX_EMPH1_MASK; 1174c0132f60SStefan Roese data |= 0xe << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET; 1175c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SET_0_REG, data, mask); 1176c0132f60SStefan Roese /* Genration 1 setting 2 (G1_Setting_2) */ 1177c0132f60SStefan Roese mask = HPIPE_G1_SET_2_G1_TX_EMPH0_MASK; 1178c0132f60SStefan Roese data = 0x0 << HPIPE_G1_SET_2_G1_TX_EMPH0_OFFSET; 1179c0132f60SStefan Roese mask |= HPIPE_G1_SET_2_G1_TX_EMPH0_EN_MASK; 1180c0132f60SStefan Roese data |= 0x1 << HPIPE_G1_SET_2_G1_TX_EMPH0_EN_OFFSET; 1181c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SET_2_REG, data, mask); 1182c0132f60SStefan Roese /* Transmitter Slew Rate Control register (tx_reg1) */ 1183c0132f60SStefan Roese mask = HPIPE_TX_REG1_TX_EMPH_RES_MASK; 1184c0132f60SStefan Roese data = 0x3 << HPIPE_TX_REG1_TX_EMPH_RES_OFFSET; 1185c0132f60SStefan Roese mask |= HPIPE_TX_REG1_SLC_EN_MASK; 1186c0132f60SStefan Roese data |= 0x3f << HPIPE_TX_REG1_SLC_EN_OFFSET; 1187c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_TX_REG1_REG, data, mask); 1188c0132f60SStefan Roese /* Impedance Calibration Control register (cal_reg1) */ 1189c0132f60SStefan Roese mask = HPIPE_CAL_REG_1_EXT_TXIMP_MASK; 1190c0132f60SStefan Roese data = 0xe << HPIPE_CAL_REG_1_EXT_TXIMP_OFFSET; 1191c0132f60SStefan Roese mask |= HPIPE_CAL_REG_1_EXT_TXIMP_EN_MASK; 1192c0132f60SStefan Roese data |= 0x1 << HPIPE_CAL_REG_1_EXT_TXIMP_EN_OFFSET; 1193c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_CAL_REG1_REG, data, mask); 1194c0132f60SStefan Roese /* Generation 1 Setting 5 (g1_setting_5) */ 1195c0132f60SStefan Roese mask = HPIPE_G1_SETTING_5_G1_ICP_MASK; 1196c0132f60SStefan Roese data = 0 << HPIPE_CAL_REG_1_EXT_TXIMP_OFFSET; 1197c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SETTING_5_REG, data, mask); 1198c0132f60SStefan Roese /* 0xE-G1_Setting_1 */ 1199c0132f60SStefan Roese mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK; 1200c0132f60SStefan Roese data = 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET; 1201c0132f60SStefan Roese mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK; 1202c0132f60SStefan Roese data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET; 1203c0132f60SStefan Roese mask |= HPIPE_G1_SET_1_G1_RX_DFE_EN_MASK; 1204c0132f60SStefan Roese data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DFE_EN_OFFSET; 1205c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask); 1206c0132f60SStefan Roese /* 0xA-DFE_Reg3 */ 1207c0132f60SStefan Roese mask = HPIPE_DFE_F3_F5_DFE_EN_MASK; 1208c0132f60SStefan Roese data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET; 1209c0132f60SStefan Roese mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK; 1210c0132f60SStefan Roese data |= 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET; 1211c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask); 1212c0132f60SStefan Roese 1213c0132f60SStefan Roese /* 0x111-G1_Setting_4 */ 1214c0132f60SStefan Roese mask = HPIPE_G1_SETTINGS_4_G1_DFE_RES_MASK; 1215c0132f60SStefan Roese data = 0x1 << HPIPE_G1_SETTINGS_4_G1_DFE_RES_OFFSET; 1216c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SETTINGS_4_REG, data, mask); 1217c0132f60SStefan Roese /* Genration 1 setting 3 (G1_Setting_3) */ 1218c0132f60SStefan Roese mask = HPIPE_G1_SETTINGS_3_G1_FBCK_SEL_MASK; 1219c0132f60SStefan Roese data = 0x1 << HPIPE_G1_SETTINGS_3_G1_FBCK_SEL_OFFSET; 1220c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SETTINGS_3_REG, data, mask); 1221c0132f60SStefan Roese 1222c0132f60SStefan Roese debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n"); 1223c0132f60SStefan Roese /* SERDES External Configuration */ 1224c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; 1225c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; 1226c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; 1227c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; 1228c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; 1229c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; 1230c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); 1231c0132f60SStefan Roese 1232c0132f60SStefan Roese 1233c0132f60SStefan Roese /* check PLL rx & tx ready */ 1234c0132f60SStefan Roese addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; 1235c0132f60SStefan Roese data = SD_EXTERNAL_STATUS0_PLL_RX_MASK | 1236c0132f60SStefan Roese SD_EXTERNAL_STATUS0_PLL_TX_MASK; 1237c0132f60SStefan Roese mask = data; 1238c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 15000); 1239c0132f60SStefan Roese if (data != 0) { 1240c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); 1241c0132f60SStefan Roese error("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n", 1242c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK), 1243c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK)); 1244c0132f60SStefan Roese ret = 0; 1245c0132f60SStefan Roese } 1246c0132f60SStefan Roese 1247c0132f60SStefan Roese /* RX init */ 1248c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK; 1249c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET; 1250c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1251c0132f60SStefan Roese 1252c0132f60SStefan Roese 1253c0132f60SStefan Roese /* check that RX init done */ 1254c0132f60SStefan Roese addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; 1255c0132f60SStefan Roese data = SD_EXTERNAL_STATUS0_RX_INIT_MASK; 1256c0132f60SStefan Roese mask = data; 1257c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 100); 1258c0132f60SStefan Roese if (data != 0) { 1259c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", 1260c0132f60SStefan Roese sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); 1261c0132f60SStefan Roese error("SD_EXTERNAL_STATUS0_RX_INIT is 0\n"); 1262c0132f60SStefan Roese ret = 0; 1263c0132f60SStefan Roese } 1264c0132f60SStefan Roese 1265c0132f60SStefan Roese debug("stage: RF Reset\n"); 1266c0132f60SStefan Roese /* RF Reset */ 1267c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK; 1268c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET; 1269c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; 1270c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; 1271c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1272c0132f60SStefan Roese 1273c0132f60SStefan Roese debug_exit(); 1274c0132f60SStefan Roese return ret; 1275c0132f60SStefan Roese } 1276c0132f60SStefan Roese 1277c0132f60SStefan Roese static int comphy_rxauii_power_up(u32 lane, void __iomem *hpipe_base, 1278c0132f60SStefan Roese void __iomem *comphy_base) 1279c0132f60SStefan Roese { 1280c0132f60SStefan Roese u32 mask, data, ret = 1; 1281c0132f60SStefan Roese void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane); 1282c0132f60SStefan Roese void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane); 1283c0132f60SStefan Roese void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane); 1284c0132f60SStefan Roese void __iomem *addr; 1285c0132f60SStefan Roese 1286c0132f60SStefan Roese debug_enter(); 1287c0132f60SStefan Roese debug("stage: RFU configurations - hard reset comphy\n"); 1288c0132f60SStefan Roese /* RFU configurations - hard reset comphy */ 1289c0132f60SStefan Roese mask = COMMON_PHY_CFG1_PWR_UP_MASK; 1290c0132f60SStefan Roese data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET; 1291c0132f60SStefan Roese mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK; 1292c0132f60SStefan Roese data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET; 1293c0132f60SStefan Roese reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask); 1294c0132f60SStefan Roese 1295c0132f60SStefan Roese if (lane == 2) { 1296c0132f60SStefan Roese reg_set(comphy_base + COMMON_PHY_SD_CTRL1, 1297c0132f60SStefan Roese 0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET, 1298c0132f60SStefan Roese COMMON_PHY_SD_CTRL1_RXAUI0_MASK); 1299c0132f60SStefan Roese } 1300c0132f60SStefan Roese if (lane == 4) { 1301c0132f60SStefan Roese reg_set(comphy_base + COMMON_PHY_SD_CTRL1, 1302c0132f60SStefan Roese 0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET, 1303c0132f60SStefan Roese COMMON_PHY_SD_CTRL1_RXAUI1_MASK); 1304c0132f60SStefan Roese } 1305c0132f60SStefan Roese 1306c0132f60SStefan Roese /* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */ 1307c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; 1308c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; 1309c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK; 1310c0132f60SStefan Roese data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET; 1311c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK; 1312c0132f60SStefan Roese data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET; 1313c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; 1314c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; 1315c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; 1316c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; 1317c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK; 1318c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET; 1319c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_MEDIA_MODE_MASK; 1320c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG0_MEDIA_MODE_OFFSET; 1321c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); 1322c0132f60SStefan Roese 1323c0132f60SStefan Roese /* release from hard reset */ 1324c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; 1325c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; 1326c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; 1327c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; 1328c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; 1329c0132f60SStefan Roese data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; 1330c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1331c0132f60SStefan Roese 1332c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; 1333c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; 1334c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; 1335c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; 1336c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1337c0132f60SStefan Roese 1338c0132f60SStefan Roese /* Wait 1ms - until band gap and ref clock ready */ 1339c0132f60SStefan Roese mdelay(1); 1340c0132f60SStefan Roese 1341c0132f60SStefan Roese /* Start comphy Configuration */ 1342c0132f60SStefan Roese debug("stage: Comphy configuration\n"); 1343c0132f60SStefan Roese /* set reference clock */ 1344c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_MISC_REG, 1345c0132f60SStefan Roese 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET, 1346c0132f60SStefan Roese HPIPE_MISC_REFCLK_SEL_MASK); 1347c0132f60SStefan Roese /* Power and PLL Control */ 1348c0132f60SStefan Roese mask = HPIPE_PWR_PLL_REF_FREQ_MASK; 1349c0132f60SStefan Roese data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET; 1350c0132f60SStefan Roese mask |= HPIPE_PWR_PLL_PHY_MODE_MASK; 1351c0132f60SStefan Roese data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET; 1352c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask); 1353c0132f60SStefan Roese /* Loopback register */ 1354c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_LOOPBACK_REG, 1355c0132f60SStefan Roese 0x1 << HPIPE_LOOPBACK_SEL_OFFSET, HPIPE_LOOPBACK_SEL_MASK); 1356c0132f60SStefan Roese /* rx control 1 */ 1357c0132f60SStefan Roese mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK; 1358c0132f60SStefan Roese data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET; 1359c0132f60SStefan Roese mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK; 1360c0132f60SStefan Roese data |= 0x1 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET; 1361c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask); 1362c0132f60SStefan Roese /* DTL Control */ 1363c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, 1364c0132f60SStefan Roese 0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET, 1365c0132f60SStefan Roese HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK); 1366c0132f60SStefan Roese 1367c0132f60SStefan Roese /* Set analog paramters from ETP(HW) */ 1368c0132f60SStefan Roese debug("stage: Analog paramters from ETP(HW)\n"); 1369c0132f60SStefan Roese /* SERDES External Configuration 2 */ 1370c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG, 1371c0132f60SStefan Roese 0x1 << SD_EXTERNAL_CONFIG2_PIN_DFE_EN_OFFSET, 1372c0132f60SStefan Roese SD_EXTERNAL_CONFIG2_PIN_DFE_EN_MASK); 1373c0132f60SStefan Roese /* 0x7-DFE Resolution control */ 1374c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_DFE_REG0, 0x1 << HPIPE_DFE_RES_FORCE_OFFSET, 1375c0132f60SStefan Roese HPIPE_DFE_RES_FORCE_MASK); 1376c0132f60SStefan Roese /* 0xd-G1_Setting_0 */ 1377c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SET_0_REG, 1378c0132f60SStefan Roese 0xd << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET, 1379c0132f60SStefan Roese HPIPE_G1_SET_0_G1_TX_EMPH1_MASK); 1380c0132f60SStefan Roese /* 0xE-G1_Setting_1 */ 1381c0132f60SStefan Roese mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK; 1382c0132f60SStefan Roese data = 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET; 1383c0132f60SStefan Roese mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK; 1384c0132f60SStefan Roese data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET; 1385c0132f60SStefan Roese mask |= HPIPE_G1_SET_1_G1_RX_DFE_EN_MASK; 1386c0132f60SStefan Roese data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DFE_EN_OFFSET; 1387c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask); 1388c0132f60SStefan Roese /* 0xA-DFE_Reg3 */ 1389c0132f60SStefan Roese mask = HPIPE_DFE_F3_F5_DFE_EN_MASK; 1390c0132f60SStefan Roese data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET; 1391c0132f60SStefan Roese mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK; 1392c0132f60SStefan Roese data |= 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET; 1393c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask); 1394c0132f60SStefan Roese 1395c0132f60SStefan Roese /* 0x111-G1_Setting_4 */ 1396c0132f60SStefan Roese mask = HPIPE_G1_SETTINGS_4_G1_DFE_RES_MASK; 1397c0132f60SStefan Roese data = 0x1 << HPIPE_G1_SETTINGS_4_G1_DFE_RES_OFFSET; 1398c0132f60SStefan Roese reg_set(hpipe_addr + HPIPE_G1_SETTINGS_4_REG, data, mask); 1399c0132f60SStefan Roese 1400c0132f60SStefan Roese debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n"); 1401c0132f60SStefan Roese /* SERDES External Configuration */ 1402c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; 1403c0132f60SStefan Roese data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; 1404c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; 1405c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; 1406c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; 1407c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; 1408c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); 1409c0132f60SStefan Roese 1410c0132f60SStefan Roese 1411c0132f60SStefan Roese /* check PLL rx & tx ready */ 1412c0132f60SStefan Roese addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; 1413c0132f60SStefan Roese data = SD_EXTERNAL_STATUS0_PLL_RX_MASK | 1414c0132f60SStefan Roese SD_EXTERNAL_STATUS0_PLL_TX_MASK; 1415c0132f60SStefan Roese mask = data; 1416c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 15000); 1417c0132f60SStefan Roese if (data != 0) { 1418c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", 1419c0132f60SStefan Roese sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); 1420c0132f60SStefan Roese error("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n", 1421c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK), 1422c0132f60SStefan Roese (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK)); 1423c0132f60SStefan Roese ret = 0; 1424c0132f60SStefan Roese } 1425c0132f60SStefan Roese 1426c0132f60SStefan Roese /* RX init */ 1427c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, 1428c0132f60SStefan Roese 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET, 1429c0132f60SStefan Roese SD_EXTERNAL_CONFIG1_RX_INIT_MASK); 1430c0132f60SStefan Roese 1431c0132f60SStefan Roese /* check that RX init done */ 1432c0132f60SStefan Roese addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; 1433c0132f60SStefan Roese data = SD_EXTERNAL_STATUS0_RX_INIT_MASK; 1434c0132f60SStefan Roese mask = data; 1435c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 100); 1436c0132f60SStefan Roese if (data != 0) { 1437c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", 1438c0132f60SStefan Roese sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); 1439c0132f60SStefan Roese error("SD_EXTERNAL_STATUS0_RX_INIT is 0\n"); 1440c0132f60SStefan Roese ret = 0; 1441c0132f60SStefan Roese } 1442c0132f60SStefan Roese 1443c0132f60SStefan Roese debug("stage: RF Reset\n"); 1444c0132f60SStefan Roese /* RF Reset */ 1445c0132f60SStefan Roese mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK; 1446c0132f60SStefan Roese data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET; 1447c0132f60SStefan Roese mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; 1448c0132f60SStefan Roese data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; 1449c0132f60SStefan Roese reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); 1450c0132f60SStefan Roese 1451c0132f60SStefan Roese debug_exit(); 1452c0132f60SStefan Roese return ret; 1453c0132f60SStefan Roese } 1454c0132f60SStefan Roese 1455c0132f60SStefan Roese static void comphy_utmi_power_down(u32 utmi_index, void __iomem *utmi_base_addr, 1456c0132f60SStefan Roese void __iomem *usb_cfg_addr, 1457c0132f60SStefan Roese void __iomem *utmi_cfg_addr, 1458c0132f60SStefan Roese u32 utmi_phy_port) 1459c0132f60SStefan Roese { 1460c0132f60SStefan Roese u32 mask, data; 1461c0132f60SStefan Roese 1462c0132f60SStefan Roese debug_enter(); 1463c0132f60SStefan Roese debug("stage: UTMI %d - Power down transceiver (power down Phy), Power down PLL, and SuspendDM\n", 1464c0132f60SStefan Roese utmi_index); 1465c0132f60SStefan Roese /* Power down UTMI PHY */ 1466c0132f60SStefan Roese reg_set(utmi_cfg_addr, 0x0 << UTMI_PHY_CFG_PU_OFFSET, 1467c0132f60SStefan Roese UTMI_PHY_CFG_PU_MASK); 1468c0132f60SStefan Roese 1469c0132f60SStefan Roese /* 1470c0132f60SStefan Roese * If UTMI connected to USB Device, configure mux prior to PHY init 1471c0132f60SStefan Roese * (Device can be connected to UTMI0 or to UTMI1) 1472c0132f60SStefan Roese */ 1473e89acc4bSStefan Roese if (utmi_phy_port == UTMI_PHY_TO_USB3_DEVICE0) { 1474c0132f60SStefan Roese debug("stage: UTMI %d - Enable Device mode and configure UTMI mux\n", 1475c0132f60SStefan Roese utmi_index); 1476c0132f60SStefan Roese /* USB3 Device UTMI enable */ 1477c0132f60SStefan Roese mask = UTMI_USB_CFG_DEVICE_EN_MASK; 1478c0132f60SStefan Roese data = 0x1 << UTMI_USB_CFG_DEVICE_EN_OFFSET; 1479c0132f60SStefan Roese /* USB3 Device UTMI MUX */ 1480c0132f60SStefan Roese mask |= UTMI_USB_CFG_DEVICE_MUX_MASK; 1481c0132f60SStefan Roese data |= utmi_index << UTMI_USB_CFG_DEVICE_MUX_OFFSET; 1482c0132f60SStefan Roese reg_set(usb_cfg_addr, data, mask); 1483c0132f60SStefan Roese } 1484c0132f60SStefan Roese 1485c0132f60SStefan Roese /* Set Test suspendm mode */ 1486c0132f60SStefan Roese mask = UTMI_CTRL_STATUS0_SUSPENDM_MASK; 1487c0132f60SStefan Roese data = 0x1 << UTMI_CTRL_STATUS0_SUSPENDM_OFFSET; 1488c0132f60SStefan Roese /* Enable Test UTMI select */ 1489c0132f60SStefan Roese mask |= UTMI_CTRL_STATUS0_TEST_SEL_MASK; 1490c0132f60SStefan Roese data |= 0x1 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET; 1491c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, data, mask); 1492c0132f60SStefan Roese 1493c0132f60SStefan Roese /* Wait for UTMI power down */ 1494c0132f60SStefan Roese mdelay(1); 1495c0132f60SStefan Roese 1496c0132f60SStefan Roese debug_exit(); 1497c0132f60SStefan Roese return; 1498c0132f60SStefan Roese } 1499c0132f60SStefan Roese 1500c0132f60SStefan Roese static void comphy_utmi_phy_config(u32 utmi_index, void __iomem *utmi_base_addr, 1501c0132f60SStefan Roese void __iomem *usb_cfg_addr, 1502c0132f60SStefan Roese void __iomem *utmi_cfg_addr, 1503c0132f60SStefan Roese u32 utmi_phy_port) 1504c0132f60SStefan Roese { 1505c0132f60SStefan Roese u32 mask, data; 1506c0132f60SStefan Roese 1507c0132f60SStefan Roese debug_exit(); 1508c0132f60SStefan Roese debug("stage: Configure UTMI PHY %d registers\n", utmi_index); 1509c0132f60SStefan Roese /* Reference Clock Divider Select */ 1510c0132f60SStefan Roese mask = UTMI_PLL_CTRL_REFDIV_MASK; 1511c0132f60SStefan Roese data = 0x5 << UTMI_PLL_CTRL_REFDIV_OFFSET; 1512c0132f60SStefan Roese /* Feedback Clock Divider Select - 90 for 25Mhz*/ 1513c0132f60SStefan Roese mask |= UTMI_PLL_CTRL_FBDIV_MASK; 1514c0132f60SStefan Roese data |= 0x60 << UTMI_PLL_CTRL_FBDIV_OFFSET; 1515c0132f60SStefan Roese /* Select LPFR - 0x0 for 25Mhz/5=5Mhz*/ 1516c0132f60SStefan Roese mask |= UTMI_PLL_CTRL_SEL_LPFR_MASK; 1517c0132f60SStefan Roese data |= 0x0 << UTMI_PLL_CTRL_SEL_LPFR_OFFSET; 1518c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_PLL_CTRL_REG, data, mask); 1519c0132f60SStefan Roese 1520c0132f60SStefan Roese /* Impedance Calibration Threshold Setting */ 1521c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_CALIB_CTRL_REG, 1522c0132f60SStefan Roese 0x6 << UTMI_CALIB_CTRL_IMPCAL_VTH_OFFSET, 1523c0132f60SStefan Roese UTMI_CALIB_CTRL_IMPCAL_VTH_MASK); 1524c0132f60SStefan Roese 1525c0132f60SStefan Roese /* Set LS TX driver strength coarse control */ 1526c0132f60SStefan Roese mask = UTMI_TX_CH_CTRL_DRV_EN_LS_MASK; 1527c0132f60SStefan Roese data = 0x3 << UTMI_TX_CH_CTRL_DRV_EN_LS_OFFSET; 1528c0132f60SStefan Roese /* Set LS TX driver fine adjustment */ 1529c0132f60SStefan Roese mask |= UTMI_TX_CH_CTRL_IMP_SEL_LS_MASK; 1530c0132f60SStefan Roese data |= 0x3 << UTMI_TX_CH_CTRL_IMP_SEL_LS_OFFSET; 1531c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_TX_CH_CTRL_REG, data, mask); 1532c0132f60SStefan Roese 1533c0132f60SStefan Roese /* Enable SQ */ 1534c0132f60SStefan Roese mask = UTMI_RX_CH_CTRL0_SQ_DET_MASK; 1535c0132f60SStefan Roese data = 0x0 << UTMI_RX_CH_CTRL0_SQ_DET_OFFSET; 1536c0132f60SStefan Roese /* Enable analog squelch detect */ 1537c0132f60SStefan Roese mask |= UTMI_RX_CH_CTRL0_SQ_ANA_DTC_MASK; 1538c0132f60SStefan Roese data |= 0x1 << UTMI_RX_CH_CTRL0_SQ_ANA_DTC_OFFSET; 1539c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_RX_CH_CTRL0_REG, data, mask); 1540c0132f60SStefan Roese 1541c0132f60SStefan Roese /* Set External squelch calibration number */ 1542c0132f60SStefan Roese mask = UTMI_RX_CH_CTRL1_SQ_AMP_CAL_MASK; 1543c0132f60SStefan Roese data = 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_OFFSET; 1544c0132f60SStefan Roese /* Enable the External squelch calibration */ 1545c0132f60SStefan Roese mask |= UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_MASK; 1546c0132f60SStefan Roese data |= 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_OFFSET; 1547c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_RX_CH_CTRL1_REG, data, mask); 1548c0132f60SStefan Roese 1549c0132f60SStefan Roese /* Set Control VDAT Reference Voltage - 0.325V */ 1550c0132f60SStefan Roese mask = UTMI_CHGDTC_CTRL_VDAT_MASK; 1551c0132f60SStefan Roese data = 0x1 << UTMI_CHGDTC_CTRL_VDAT_OFFSET; 1552c0132f60SStefan Roese /* Set Control VSRC Reference Voltage - 0.6V */ 1553c0132f60SStefan Roese mask |= UTMI_CHGDTC_CTRL_VSRC_MASK; 1554c0132f60SStefan Roese data |= 0x1 << UTMI_CHGDTC_CTRL_VSRC_OFFSET; 1555c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_CHGDTC_CTRL_REG, data, mask); 1556c0132f60SStefan Roese 1557c0132f60SStefan Roese debug_exit(); 1558c0132f60SStefan Roese return; 1559c0132f60SStefan Roese } 1560c0132f60SStefan Roese 1561c0132f60SStefan Roese static int comphy_utmi_power_up(u32 utmi_index, void __iomem *utmi_base_addr, 1562c0132f60SStefan Roese void __iomem *usb_cfg_addr, 1563c0132f60SStefan Roese void __iomem *utmi_cfg_addr, u32 utmi_phy_port) 1564c0132f60SStefan Roese { 1565c0132f60SStefan Roese u32 data, mask, ret = 1; 1566c0132f60SStefan Roese void __iomem *addr; 1567c0132f60SStefan Roese 1568c0132f60SStefan Roese debug_enter(); 1569c0132f60SStefan Roese debug("stage: UTMI %d - Power up transceiver(Power up Phy), and exit SuspendDM\n", 1570c0132f60SStefan Roese utmi_index); 1571c0132f60SStefan Roese /* Power UP UTMI PHY */ 1572c0132f60SStefan Roese reg_set(utmi_cfg_addr, 0x1 << UTMI_PHY_CFG_PU_OFFSET, 1573c0132f60SStefan Roese UTMI_PHY_CFG_PU_MASK); 1574c0132f60SStefan Roese /* Disable Test UTMI select */ 1575c0132f60SStefan Roese reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, 1576c0132f60SStefan Roese 0x0 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET, 1577c0132f60SStefan Roese UTMI_CTRL_STATUS0_TEST_SEL_MASK); 1578c0132f60SStefan Roese 1579c0132f60SStefan Roese debug("stage: Polling for PLL and impedance calibration done, and PLL ready done\n"); 1580c0132f60SStefan Roese addr = utmi_base_addr + UTMI_CALIB_CTRL_REG; 1581c0132f60SStefan Roese data = UTMI_CALIB_CTRL_IMPCAL_DONE_MASK; 1582c0132f60SStefan Roese mask = data; 1583c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 100); 1584c0132f60SStefan Roese if (data != 0) { 1585c0132f60SStefan Roese error("Impedance calibration is not done\n"); 1586c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", addr, data); 1587c0132f60SStefan Roese ret = 0; 1588c0132f60SStefan Roese } 1589c0132f60SStefan Roese 1590c0132f60SStefan Roese data = UTMI_CALIB_CTRL_PLLCAL_DONE_MASK; 1591c0132f60SStefan Roese mask = data; 1592c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 100); 1593c0132f60SStefan Roese if (data != 0) { 1594c0132f60SStefan Roese error("PLL calibration is not done\n"); 1595c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", addr, data); 1596c0132f60SStefan Roese ret = 0; 1597c0132f60SStefan Roese } 1598c0132f60SStefan Roese 1599c0132f60SStefan Roese addr = utmi_base_addr + UTMI_PLL_CTRL_REG; 1600c0132f60SStefan Roese data = UTMI_PLL_CTRL_PLL_RDY_MASK; 1601c0132f60SStefan Roese mask = data; 1602c0132f60SStefan Roese data = polling_with_timeout(addr, data, mask, 100); 1603c0132f60SStefan Roese if (data != 0) { 1604c0132f60SStefan Roese error("PLL is not ready\n"); 1605c0132f60SStefan Roese debug("Read from reg = %p - value = 0x%x\n", addr, data); 1606c0132f60SStefan Roese ret = 0; 1607c0132f60SStefan Roese } 1608c0132f60SStefan Roese 1609c0132f60SStefan Roese if (ret) 1610c0132f60SStefan Roese debug("Passed\n"); 1611c0132f60SStefan Roese else 1612c0132f60SStefan Roese debug("\n"); 1613c0132f60SStefan Roese 1614c0132f60SStefan Roese debug_exit(); 1615c0132f60SStefan Roese return ret; 1616c0132f60SStefan Roese } 1617c0132f60SStefan Roese 1618c0132f60SStefan Roese /* 1619c0132f60SStefan Roese * comphy_utmi_phy_init initialize the UTMI PHY 1620c0132f60SStefan Roese * the init split in 3 parts: 1621c0132f60SStefan Roese * 1. Power down transceiver and PLL 1622c0132f60SStefan Roese * 2. UTMI PHY configure 1623c0132f60SStefan Roese * 3. Powe up transceiver and PLL 1624c0132f60SStefan Roese * Note: - Power down/up should be once for both UTMI PHYs 1625c0132f60SStefan Roese * - comphy_dedicated_phys_init call this function if at least there is 1626c0132f60SStefan Roese * one UTMI PHY exists in FDT blob. access to cp110_utmi_data[0] is 1627c0132f60SStefan Roese * legal 1628c0132f60SStefan Roese */ 1629c0132f60SStefan Roese static void comphy_utmi_phy_init(u32 utmi_phy_count, 1630c0132f60SStefan Roese struct utmi_phy_data *cp110_utmi_data) 1631c0132f60SStefan Roese { 1632c0132f60SStefan Roese u32 i; 1633c0132f60SStefan Roese 1634c0132f60SStefan Roese debug_enter(); 1635c0132f60SStefan Roese /* UTMI Power down */ 1636c0132f60SStefan Roese for (i = 0; i < utmi_phy_count; i++) { 1637c0132f60SStefan Roese comphy_utmi_power_down(i, cp110_utmi_data[i].utmi_base_addr, 1638c0132f60SStefan Roese cp110_utmi_data[i].usb_cfg_addr, 1639c0132f60SStefan Roese cp110_utmi_data[i].utmi_cfg_addr, 1640c0132f60SStefan Roese cp110_utmi_data[i].utmi_phy_port); 1641c0132f60SStefan Roese } 1642c0132f60SStefan Roese /* PLL Power down */ 1643c0132f60SStefan Roese debug("stage: UTMI PHY power down PLL\n"); 1644c0132f60SStefan Roese for (i = 0; i < utmi_phy_count; i++) { 1645c0132f60SStefan Roese reg_set(cp110_utmi_data[i].usb_cfg_addr, 1646c0132f60SStefan Roese 0x0 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK); 1647c0132f60SStefan Roese } 1648c0132f60SStefan Roese /* UTMI configure */ 1649c0132f60SStefan Roese for (i = 0; i < utmi_phy_count; i++) { 1650c0132f60SStefan Roese comphy_utmi_phy_config(i, cp110_utmi_data[i].utmi_base_addr, 1651c0132f60SStefan Roese cp110_utmi_data[i].usb_cfg_addr, 1652c0132f60SStefan Roese cp110_utmi_data[i].utmi_cfg_addr, 1653c0132f60SStefan Roese cp110_utmi_data[i].utmi_phy_port); 1654c0132f60SStefan Roese } 1655c0132f60SStefan Roese /* UTMI Power up */ 1656c0132f60SStefan Roese for (i = 0; i < utmi_phy_count; i++) { 1657c0132f60SStefan Roese if (!comphy_utmi_power_up(i, cp110_utmi_data[i].utmi_base_addr, 1658c0132f60SStefan Roese cp110_utmi_data[i].usb_cfg_addr, 1659c0132f60SStefan Roese cp110_utmi_data[i].utmi_cfg_addr, 1660c0132f60SStefan Roese cp110_utmi_data[i].utmi_phy_port)) { 1661c0132f60SStefan Roese error("Failed to initialize UTMI PHY %d\n", i); 1662c0132f60SStefan Roese continue; 1663c0132f60SStefan Roese } 1664c0132f60SStefan Roese printf("UTMI PHY %d initialized to ", i); 1665e89acc4bSStefan Roese if (cp110_utmi_data[i].utmi_phy_port == 1666e89acc4bSStefan Roese UTMI_PHY_TO_USB3_DEVICE0) 1667c0132f60SStefan Roese printf("USB Device\n"); 1668c0132f60SStefan Roese else 1669c0132f60SStefan Roese printf("USB Host%d\n", 1670c0132f60SStefan Roese cp110_utmi_data[i].utmi_phy_port); 1671c0132f60SStefan Roese } 1672c0132f60SStefan Roese /* PLL Power up */ 1673c0132f60SStefan Roese debug("stage: UTMI PHY power up PLL\n"); 1674c0132f60SStefan Roese for (i = 0; i < utmi_phy_count; i++) { 1675c0132f60SStefan Roese reg_set(cp110_utmi_data[i].usb_cfg_addr, 1676c0132f60SStefan Roese 0x1 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK); 1677c0132f60SStefan Roese } 1678c0132f60SStefan Roese 1679c0132f60SStefan Roese debug_exit(); 1680c0132f60SStefan Roese return; 1681c0132f60SStefan Roese } 1682c0132f60SStefan Roese 1683c0132f60SStefan Roese /* 1684c0132f60SStefan Roese * comphy_dedicated_phys_init initialize the dedicated PHYs 1685c0132f60SStefan Roese * - not muxed SerDes lanes e.g. UTMI PHY 1686c0132f60SStefan Roese */ 1687c0132f60SStefan Roese void comphy_dedicated_phys_init(void) 1688c0132f60SStefan Roese { 1689c0132f60SStefan Roese struct utmi_phy_data cp110_utmi_data[MAX_UTMI_PHY_COUNT]; 1690c0132f60SStefan Roese int node; 1691c0132f60SStefan Roese int i; 1692c0132f60SStefan Roese 1693c0132f60SStefan Roese debug_enter(); 1694c0132f60SStefan Roese debug("Initialize USB UTMI PHYs\n"); 1695c0132f60SStefan Roese 1696c0132f60SStefan Roese /* Find the UTMI phy node in device tree and go over them */ 1697c0132f60SStefan Roese node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, 1698c0132f60SStefan Roese "marvell,mvebu-utmi-2.6.0"); 1699c0132f60SStefan Roese 1700c0132f60SStefan Roese i = 0; 1701c0132f60SStefan Roese while (node > 0) { 1702c0132f60SStefan Roese /* get base address of UTMI phy */ 1703c0132f60SStefan Roese cp110_utmi_data[i].utmi_base_addr = 1704c0132f60SStefan Roese (void __iomem *)fdtdec_get_addr_size_auto_noparent( 1705c0132f60SStefan Roese gd->fdt_blob, node, "reg", 0, NULL, true); 1706c0132f60SStefan Roese if (cp110_utmi_data[i].utmi_base_addr == NULL) { 1707c0132f60SStefan Roese error("UTMI PHY base address is invalid\n"); 1708c0132f60SStefan Roese i++; 1709c0132f60SStefan Roese continue; 1710c0132f60SStefan Roese } 1711c0132f60SStefan Roese 1712c0132f60SStefan Roese /* get usb config address */ 1713c0132f60SStefan Roese cp110_utmi_data[i].usb_cfg_addr = 1714c0132f60SStefan Roese (void __iomem *)fdtdec_get_addr_size_auto_noparent( 1715c0132f60SStefan Roese gd->fdt_blob, node, "reg", 1, NULL, true); 1716c0132f60SStefan Roese if (cp110_utmi_data[i].usb_cfg_addr == NULL) { 1717c0132f60SStefan Roese error("UTMI PHY base address is invalid\n"); 1718c0132f60SStefan Roese i++; 1719c0132f60SStefan Roese continue; 1720c0132f60SStefan Roese } 1721c0132f60SStefan Roese 1722c0132f60SStefan Roese /* get UTMI config address */ 1723c0132f60SStefan Roese cp110_utmi_data[i].utmi_cfg_addr = 1724c0132f60SStefan Roese (void __iomem *)fdtdec_get_addr_size_auto_noparent( 1725c0132f60SStefan Roese gd->fdt_blob, node, "reg", 2, NULL, true); 1726c0132f60SStefan Roese if (cp110_utmi_data[i].utmi_cfg_addr == NULL) { 1727c0132f60SStefan Roese error("UTMI PHY base address is invalid\n"); 1728c0132f60SStefan Roese i++; 1729c0132f60SStefan Roese continue; 1730c0132f60SStefan Roese } 1731c0132f60SStefan Roese 1732c0132f60SStefan Roese /* 1733c0132f60SStefan Roese * get the port number (to check if the utmi connected to 1734c0132f60SStefan Roese * host/device) 1735c0132f60SStefan Roese */ 1736c0132f60SStefan Roese cp110_utmi_data[i].utmi_phy_port = fdtdec_get_int( 1737c0132f60SStefan Roese gd->fdt_blob, node, "utmi-port", UTMI_PHY_INVALID); 1738c0132f60SStefan Roese if (cp110_utmi_data[i].utmi_phy_port == UTMI_PHY_INVALID) { 1739c0132f60SStefan Roese error("UTMI PHY port type is invalid\n"); 1740c0132f60SStefan Roese i++; 1741c0132f60SStefan Roese continue; 1742c0132f60SStefan Roese } 1743c0132f60SStefan Roese 1744c0132f60SStefan Roese node = fdt_node_offset_by_compatible( 1745c0132f60SStefan Roese gd->fdt_blob, node, "marvell,mvebu-utmi-2.6.0"); 1746c0132f60SStefan Roese i++; 1747c0132f60SStefan Roese } 1748c0132f60SStefan Roese 1749c0132f60SStefan Roese if (i > 0) 1750c0132f60SStefan Roese comphy_utmi_phy_init(i, cp110_utmi_data); 1751c0132f60SStefan Roese 1752c0132f60SStefan Roese debug_exit(); 1753c0132f60SStefan Roese } 1754c0132f60SStefan Roese 1755c0132f60SStefan Roese static void comphy_mux_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, 1756c0132f60SStefan Roese struct comphy_map *serdes_map) 1757c0132f60SStefan Roese { 1758c0132f60SStefan Roese void __iomem *comphy_base_addr; 1759c0132f60SStefan Roese struct comphy_map comphy_map_pipe_data[MAX_LANE_OPTIONS]; 1760c0132f60SStefan Roese struct comphy_map comphy_map_phy_data[MAX_LANE_OPTIONS]; 1761c0132f60SStefan Roese u32 lane, comphy_max_count; 1762c0132f60SStefan Roese 1763c0132f60SStefan Roese comphy_max_count = ptr_chip_cfg->comphy_lanes_count; 1764c0132f60SStefan Roese comphy_base_addr = ptr_chip_cfg->comphy_base_addr; 1765c0132f60SStefan Roese 1766c0132f60SStefan Roese /* 1767c0132f60SStefan Roese * Copy the SerDes map configuration for PIPE map and PHY map 1768c0132f60SStefan Roese * the comphy_mux_init modify the type of the lane if the type 1769c0132f60SStefan Roese * is not valid because we have 2 selectores run the 1770c0132f60SStefan Roese * comphy_mux_init twice and after that update the original 1771c0132f60SStefan Roese * serdes_map 1772c0132f60SStefan Roese */ 1773c0132f60SStefan Roese for (lane = 0; lane < comphy_max_count; lane++) { 1774c0132f60SStefan Roese comphy_map_pipe_data[lane].type = serdes_map[lane].type; 1775c0132f60SStefan Roese comphy_map_pipe_data[lane].speed = serdes_map[lane].speed; 1776c0132f60SStefan Roese comphy_map_phy_data[lane].type = serdes_map[lane].type; 1777c0132f60SStefan Roese comphy_map_phy_data[lane].speed = serdes_map[lane].speed; 1778c0132f60SStefan Roese } 1779c0132f60SStefan Roese ptr_chip_cfg->mux_data = cp110_comphy_phy_mux_data; 1780c0132f60SStefan Roese comphy_mux_init(ptr_chip_cfg, comphy_map_phy_data, 1781c0132f60SStefan Roese comphy_base_addr + COMMON_SELECTOR_PHY_OFFSET); 1782c0132f60SStefan Roese 1783c0132f60SStefan Roese ptr_chip_cfg->mux_data = cp110_comphy_pipe_mux_data; 1784c0132f60SStefan Roese comphy_mux_init(ptr_chip_cfg, comphy_map_pipe_data, 1785c0132f60SStefan Roese comphy_base_addr + COMMON_SELECTOR_PIPE_OFFSET); 1786c0132f60SStefan Roese /* Fix the type after check the PHY and PIPE configuration */ 1787c0132f60SStefan Roese for (lane = 0; lane < comphy_max_count; lane++) { 1788c0132f60SStefan Roese if ((comphy_map_pipe_data[lane].type == PHY_TYPE_UNCONNECTED) && 1789c0132f60SStefan Roese (comphy_map_phy_data[lane].type == PHY_TYPE_UNCONNECTED)) 1790c0132f60SStefan Roese serdes_map[lane].type = PHY_TYPE_UNCONNECTED; 1791c0132f60SStefan Roese } 1792c0132f60SStefan Roese } 1793c0132f60SStefan Roese 1794c0132f60SStefan Roese int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, 1795c0132f60SStefan Roese struct comphy_map *serdes_map) 1796c0132f60SStefan Roese { 1797c0132f60SStefan Roese struct comphy_map *ptr_comphy_map; 1798c0132f60SStefan Roese void __iomem *comphy_base_addr, *hpipe_base_addr; 1799c0132f60SStefan Roese u32 comphy_max_count, lane, ret = 0; 1800c0132f60SStefan Roese u32 pcie_width = 0; 1801c0132f60SStefan Roese 1802c0132f60SStefan Roese debug_enter(); 1803c0132f60SStefan Roese 1804c0132f60SStefan Roese comphy_max_count = ptr_chip_cfg->comphy_lanes_count; 1805c0132f60SStefan Roese comphy_base_addr = ptr_chip_cfg->comphy_base_addr; 1806c0132f60SStefan Roese hpipe_base_addr = ptr_chip_cfg->hpipe3_base_addr; 1807c0132f60SStefan Roese 1808c0132f60SStefan Roese /* Config Comphy mux configuration */ 1809c0132f60SStefan Roese comphy_mux_cp110_init(ptr_chip_cfg, serdes_map); 1810c0132f60SStefan Roese 1811c0132f60SStefan Roese /* Check if the first 4 lanes configured as By-4 */ 1812c0132f60SStefan Roese for (lane = 0, ptr_comphy_map = serdes_map; lane < 4; 1813c0132f60SStefan Roese lane++, ptr_comphy_map++) { 1814c0132f60SStefan Roese if (ptr_comphy_map->type != PHY_TYPE_PEX0) 1815c0132f60SStefan Roese break; 1816c0132f60SStefan Roese pcie_width++; 1817c0132f60SStefan Roese } 1818c0132f60SStefan Roese 1819c0132f60SStefan Roese for (lane = 0, ptr_comphy_map = serdes_map; lane < comphy_max_count; 1820c0132f60SStefan Roese lane++, ptr_comphy_map++) { 1821c0132f60SStefan Roese debug("Initialize serdes number %d\n", lane); 1822c0132f60SStefan Roese debug("Serdes type = 0x%x\n", ptr_comphy_map->type); 1823c0132f60SStefan Roese if (lane == 4) { 1824c0132f60SStefan Roese /* 1825c0132f60SStefan Roese * PCIe lanes above the first 4 lanes, can be only 1826c0132f60SStefan Roese * by1 1827c0132f60SStefan Roese */ 1828c0132f60SStefan Roese pcie_width = 1; 1829c0132f60SStefan Roese } 1830c0132f60SStefan Roese switch (ptr_comphy_map->type) { 1831c0132f60SStefan Roese case PHY_TYPE_UNCONNECTED: 18326ecc0b1cSStefan Roese case PHY_TYPE_IGNORE: 1833c0132f60SStefan Roese continue; 1834c0132f60SStefan Roese break; 1835c0132f60SStefan Roese case PHY_TYPE_PEX0: 1836c0132f60SStefan Roese case PHY_TYPE_PEX1: 1837c0132f60SStefan Roese case PHY_TYPE_PEX2: 1838c0132f60SStefan Roese case PHY_TYPE_PEX3: 1839c0132f60SStefan Roese ret = comphy_pcie_power_up( 1840c0132f60SStefan Roese lane, pcie_width, ptr_comphy_map->clk_src, 18417dda98e0SStefan Roese serdes_map->end_point, 1842c0132f60SStefan Roese hpipe_base_addr, comphy_base_addr); 1843c0132f60SStefan Roese break; 1844c0132f60SStefan Roese case PHY_TYPE_SATA0: 1845c0132f60SStefan Roese case PHY_TYPE_SATA1: 1846c0132f60SStefan Roese case PHY_TYPE_SATA2: 1847c0132f60SStefan Roese case PHY_TYPE_SATA3: 1848c0132f60SStefan Roese ret = comphy_sata_power_up( 1849c0132f60SStefan Roese lane, hpipe_base_addr, comphy_base_addr, 1850c0132f60SStefan Roese ptr_chip_cfg->comphy_index); 1851c0132f60SStefan Roese break; 1852c0132f60SStefan Roese case PHY_TYPE_USB3_HOST0: 1853c0132f60SStefan Roese case PHY_TYPE_USB3_HOST1: 1854c0132f60SStefan Roese case PHY_TYPE_USB3_DEVICE: 1855c0132f60SStefan Roese ret = comphy_usb3_power_up(lane, hpipe_base_addr, 1856c0132f60SStefan Roese comphy_base_addr); 1857c0132f60SStefan Roese break; 1858c0132f60SStefan Roese case PHY_TYPE_SGMII0: 1859c0132f60SStefan Roese case PHY_TYPE_SGMII1: 1860c0132f60SStefan Roese case PHY_TYPE_SGMII2: 1861c0132f60SStefan Roese case PHY_TYPE_SGMII3: 1862c0132f60SStefan Roese if (ptr_comphy_map->speed == PHY_SPEED_INVALID) { 1863c0132f60SStefan Roese debug("Warning: SGMII PHY speed in lane %d is invalid, set PHY speed to 1.25G\n", 1864c0132f60SStefan Roese lane); 1865c0132f60SStefan Roese ptr_comphy_map->speed = PHY_SPEED_1_25G; 1866c0132f60SStefan Roese } 1867c0132f60SStefan Roese ret = comphy_sgmii_power_up( 1868c0132f60SStefan Roese lane, ptr_comphy_map->speed, hpipe_base_addr, 1869c0132f60SStefan Roese comphy_base_addr); 1870c0132f60SStefan Roese break; 1871cb686454SStefan Roese case PHY_TYPE_SFI: 1872cb686454SStefan Roese ret = comphy_sfi_power_up(lane, hpipe_base_addr, 1873c0132f60SStefan Roese comphy_base_addr); 1874c0132f60SStefan Roese break; 1875c0132f60SStefan Roese case PHY_TYPE_RXAUI0: 1876c0132f60SStefan Roese case PHY_TYPE_RXAUI1: 1877c0132f60SStefan Roese ret = comphy_rxauii_power_up(lane, hpipe_base_addr, 1878c0132f60SStefan Roese comphy_base_addr); 1879c0132f60SStefan Roese break; 1880c0132f60SStefan Roese default: 1881c0132f60SStefan Roese debug("Unknown SerDes type, skip initialize SerDes %d\n", 1882c0132f60SStefan Roese lane); 1883c0132f60SStefan Roese break; 1884c0132f60SStefan Roese } 1885c0132f60SStefan Roese if (ret == 0) { 1886c0132f60SStefan Roese /* 1887d37f020eSStefan Roese * If interface wans't initialized, set the lane to 1888c0132f60SStefan Roese * PHY_TYPE_UNCONNECTED state. 1889c0132f60SStefan Roese */ 1890c0132f60SStefan Roese ptr_comphy_map->type = PHY_TYPE_UNCONNECTED; 1891c0132f60SStefan Roese error("PLL is not locked - Failed to initialize lane %d\n", 1892c0132f60SStefan Roese lane); 1893c0132f60SStefan Roese } 1894c0132f60SStefan Roese } 1895c0132f60SStefan Roese 1896c0132f60SStefan Roese debug_exit(); 1897c0132f60SStefan Roese return 0; 1898c0132f60SStefan Roese } 1899