Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015-2016 Marvell International Ltd. |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 10 | #include <asm/io.h> |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 11 | #include <asm/ptrace.h> |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 12 | #include <asm/arch/cpu.h> |
| 13 | #include <asm/arch/soc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 15 | |
Marek BehĂșn | 19ce44c | 2018-08-17 12:58:51 +0200 | [diff] [blame] | 16 | #include "comphy_core.h" |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 17 | #include "comphy_hpipe.h" |
| 18 | #include "sata.h" |
| 19 | #include "utmi_phy.h" |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | #define SD_ADDR(base, lane) (base + 0x1000 * lane) |
| 24 | #define HPIPE_ADDR(base, lane) (SD_ADDR(base, lane) + 0x800) |
| 25 | #define COMPHY_ADDR(base, lane) (base + 0x28 * lane) |
| 26 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 27 | /* Firmware related definitions used for SMC calls */ |
| 28 | #define MV_SIP_COMPHY_POWER_ON 0x82000001 |
| 29 | #define MV_SIP_COMPHY_POWER_OFF 0x82000002 |
| 30 | #define MV_SIP_COMPHY_PLL_LOCK 0x82000003 |
| 31 | |
Igal Liberman | 67d1a3f | 2020-10-18 17:11:13 +0300 | [diff] [blame] | 32 | /* Used to distinguish between different possible callers (U-boot/Linux) */ |
| 33 | #define COMPHY_CALLER_UBOOT (0x1 << 21) |
| 34 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 35 | #define COMPHY_FW_MODE_FORMAT(mode) ((mode) << 12) |
| 36 | #define COMPHY_FW_FORMAT(mode, idx, speeds) \ |
| 37 | (((mode) << 12) | ((idx) << 8) | ((speeds) << 2)) |
Grzegorz Jaszczyk | c42b5a3 | 2020-10-18 17:11:12 +0300 | [diff] [blame] | 38 | |
| 39 | #define COMPHY_FW_PCIE_FORMAT(pcie_width, clk_src, mode, speeds) \ |
Igal Liberman | 67d1a3f | 2020-10-18 17:11:13 +0300 | [diff] [blame] | 40 | (COMPHY_CALLER_UBOOT | ((pcie_width) << 18) | \ |
| 41 | ((clk_src) << 17) | COMPHY_FW_FORMAT(mode, 0, speeds)) |
Grzegorz Jaszczyk | c42b5a3 | 2020-10-18 17:11:12 +0300 | [diff] [blame] | 42 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 43 | #define COMPHY_SATA_MODE 0x1 |
| 44 | #define COMPHY_SGMII_MODE 0x2 /* SGMII 1G */ |
| 45 | #define COMPHY_HS_SGMII_MODE 0x3 /* SGMII 2.5G */ |
| 46 | #define COMPHY_USB3H_MODE 0x4 |
| 47 | #define COMPHY_USB3D_MODE 0x5 |
| 48 | #define COMPHY_PCIE_MODE 0x6 |
| 49 | #define COMPHY_RXAUI_MODE 0x7 |
| 50 | #define COMPHY_XFI_MODE 0x8 |
| 51 | #define COMPHY_SFI_MODE 0x9 |
| 52 | #define COMPHY_USB3_MODE 0xa |
| 53 | #define COMPHY_AP_MODE 0xb |
| 54 | |
| 55 | /* Comphy unit index macro */ |
| 56 | #define COMPHY_UNIT_ID0 0 |
| 57 | #define COMPHY_UNIT_ID1 1 |
| 58 | #define COMPHY_UNIT_ID2 2 |
| 59 | #define COMPHY_UNIT_ID3 3 |
| 60 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 61 | struct utmi_phy_data { |
| 62 | void __iomem *utmi_base_addr; |
| 63 | void __iomem *usb_cfg_addr; |
| 64 | void __iomem *utmi_cfg_addr; |
| 65 | u32 utmi_phy_port; |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * For CP-110 we have 2 Selector registers "PHY Selectors", |
| 70 | * and "PIPE Selectors". |
| 71 | * PIPE selector include USB and PCIe options. |
| 72 | * PHY selector include the Ethernet and SATA options, every Ethernet |
| 73 | * option has different options, for example: serdes lane2 had option |
Stefan Roese | b8b7c67 | 2017-04-24 18:45:29 +0300 | [diff] [blame] | 74 | * Eth_port_0 that include (SGMII0, RXAUI0, SFI) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 75 | */ |
| 76 | struct comphy_mux_data cp110_comphy_phy_mux_data[] = { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 77 | /* Lane 0 */ |
| 78 | {4, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII1, 0x1}, |
| 79 | {COMPHY_TYPE_SATA1, 0x4} } }, |
| 80 | /* Lane 1 */ |
| 81 | {4, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII2, 0x1}, |
| 82 | {COMPHY_TYPE_SATA0, 0x4} } }, |
| 83 | /* Lane 2 */ |
| 84 | {6, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII0, 0x1}, |
| 85 | {COMPHY_TYPE_RXAUI0, 0x1}, {COMPHY_TYPE_SFI, 0x1}, |
| 86 | {COMPHY_TYPE_SATA0, 0x4} } }, |
| 87 | /* Lane 3 */ |
| 88 | {8, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_RXAUI1, 0x1}, |
| 89 | {COMPHY_TYPE_SGMII1, 0x2}, {COMPHY_TYPE_SATA1, 0x4} } }, |
| 90 | /* Lane 4 */ |
| 91 | {7, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII0, 0x2}, |
| 92 | {COMPHY_TYPE_RXAUI0, 0x2}, {COMPHY_TYPE_SFI, 0x2}, |
| 93 | {COMPHY_TYPE_SGMII1, 0x1} } }, |
| 94 | /* Lane 5 */ |
| 95 | {6, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII2, 0x1}, |
| 96 | {COMPHY_TYPE_RXAUI1, 0x2}, {COMPHY_TYPE_SATA1, 0x4} } }, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | struct comphy_mux_data cp110_comphy_pipe_mux_data[] = { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 100 | /* Lane 0 */ |
| 101 | {2, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_PEX0, 0x4} } }, |
| 102 | /* Lane 1 */ |
| 103 | {4, {{COMPHY_TYPE_UNCONNECTED, 0x0}, |
| 104 | {COMPHY_TYPE_USB3_HOST0, 0x1}, {COMPHY_TYPE_USB3_DEVICE, 0x2}, |
| 105 | {COMPHY_TYPE_PEX0, 0x4} } }, |
| 106 | /* Lane 2 */ |
| 107 | {3, {{COMPHY_TYPE_UNCONNECTED, 0x0}, |
| 108 | {COMPHY_TYPE_USB3_HOST0, 0x1}, {COMPHY_TYPE_PEX0, 0x4} } }, |
| 109 | /* Lane 3 */ |
| 110 | {3, {{COMPHY_TYPE_UNCONNECTED, 0x0}, |
| 111 | {COMPHY_TYPE_USB3_HOST1, 0x1}, {COMPHY_TYPE_PEX0, 0x4} } }, |
| 112 | /* Lane 4 */ |
| 113 | {4, {{COMPHY_TYPE_UNCONNECTED, 0x0}, |
| 114 | {COMPHY_TYPE_USB3_HOST1, 0x1}, |
| 115 | {COMPHY_TYPE_USB3_DEVICE, 0x2}, {COMPHY_TYPE_PEX1, 0x4} } }, |
| 116 | /* Lane 5 */ |
| 117 | {2, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_PEX2, 0x4} } }, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | static u32 polling_with_timeout(void __iomem *addr, u32 val, |
| 121 | u32 mask, unsigned long usec_timout) |
| 122 | { |
| 123 | u32 data; |
| 124 | |
| 125 | do { |
| 126 | udelay(1); |
| 127 | data = readl(addr) & mask; |
| 128 | } while (data != val && --usec_timout > 0); |
| 129 | |
| 130 | if (usec_timout == 0) |
| 131 | return data; |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 136 | static int comphy_usb3_power_up(u32 lane, void __iomem *hpipe_base, |
| 137 | void __iomem *comphy_base) |
| 138 | { |
| 139 | u32 mask, data, ret = 1; |
| 140 | void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane); |
| 141 | void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane); |
| 142 | void __iomem *addr; |
| 143 | |
| 144 | debug_enter(); |
| 145 | debug("stage: RFU configurations - hard reset comphy\n"); |
| 146 | /* RFU configurations - hard reset comphy */ |
| 147 | mask = COMMON_PHY_CFG1_PWR_UP_MASK; |
| 148 | data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET; |
| 149 | mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK; |
| 150 | data |= 0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET; |
| 151 | mask |= COMMON_PHY_CFG1_PWR_ON_RESET_MASK; |
| 152 | data |= 0x0 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET; |
| 153 | mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK; |
| 154 | data |= 0x0 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET; |
| 155 | mask |= COMMON_PHY_PHY_MODE_MASK; |
| 156 | data |= 0x1 << COMMON_PHY_PHY_MODE_OFFSET; |
| 157 | reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask); |
| 158 | |
| 159 | /* release from hard reset */ |
| 160 | mask = COMMON_PHY_CFG1_PWR_ON_RESET_MASK; |
| 161 | data = 0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET; |
| 162 | mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK; |
| 163 | data |= 0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET; |
| 164 | reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask); |
| 165 | |
| 166 | /* Wait 1ms - until band gap and ref clock ready */ |
| 167 | mdelay(1); |
| 168 | |
| 169 | /* Start comphy Configuration */ |
| 170 | debug("stage: Comphy configuration\n"); |
| 171 | /* Set PIPE soft reset */ |
| 172 | mask = HPIPE_RST_CLK_CTRL_PIPE_RST_MASK; |
| 173 | data = 0x1 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET; |
| 174 | /* Set PHY datapath width mode for V0 */ |
| 175 | mask |= HPIPE_RST_CLK_CTRL_FIXED_PCLK_MASK; |
| 176 | data |= 0x0 << HPIPE_RST_CLK_CTRL_FIXED_PCLK_OFFSET; |
| 177 | /* Set Data bus width USB mode for V0 */ |
| 178 | mask |= HPIPE_RST_CLK_CTRL_PIPE_WIDTH_MASK; |
| 179 | data |= 0x0 << HPIPE_RST_CLK_CTRL_PIPE_WIDTH_OFFSET; |
| 180 | /* Set CORE_CLK output frequency for 250Mhz */ |
| 181 | mask |= HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_MASK; |
| 182 | data |= 0x0 << HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_OFFSET; |
| 183 | reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG, data, mask); |
| 184 | /* Set PLL ready delay for 0x2 */ |
| 185 | reg_set(hpipe_addr + HPIPE_CLK_SRC_LO_REG, |
| 186 | 0x2 << HPIPE_CLK_SRC_LO_PLL_RDY_DL_OFFSET, |
| 187 | HPIPE_CLK_SRC_LO_PLL_RDY_DL_MASK); |
| 188 | /* Set reference clock to come from group 1 - 25Mhz */ |
| 189 | reg_set(hpipe_addr + HPIPE_MISC_REG, |
| 190 | 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET, |
| 191 | HPIPE_MISC_REFCLK_SEL_MASK); |
| 192 | /* Set reference frequcency select - 0x2 */ |
| 193 | mask = HPIPE_PWR_PLL_REF_FREQ_MASK; |
| 194 | data = 0x2 << HPIPE_PWR_PLL_REF_FREQ_OFFSET; |
| 195 | /* Set PHY mode to USB - 0x5 */ |
| 196 | mask |= HPIPE_PWR_PLL_PHY_MODE_MASK; |
| 197 | data |= 0x5 << HPIPE_PWR_PLL_PHY_MODE_OFFSET; |
| 198 | reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask); |
| 199 | /* Set the amount of time spent in the LoZ state - set for 0x7 */ |
| 200 | reg_set(hpipe_addr + HPIPE_GLOBAL_PM_CTRL, |
| 201 | 0x7 << HPIPE_GLOBAL_PM_RXDLOZ_WAIT_OFFSET, |
| 202 | HPIPE_GLOBAL_PM_RXDLOZ_WAIT_MASK); |
| 203 | /* Set max PHY generation setting - 5Gbps */ |
| 204 | reg_set(hpipe_addr + HPIPE_INTERFACE_REG, |
| 205 | 0x1 << HPIPE_INTERFACE_GEN_MAX_OFFSET, |
| 206 | HPIPE_INTERFACE_GEN_MAX_MASK); |
| 207 | /* Set select data width 20Bit (SEL_BITS[2:0]) */ |
| 208 | reg_set(hpipe_addr + HPIPE_LOOPBACK_REG, |
| 209 | 0x1 << HPIPE_LOOPBACK_SEL_OFFSET, |
| 210 | HPIPE_LOOPBACK_SEL_MASK); |
| 211 | /* select de-emphasize 3.5db */ |
| 212 | reg_set(hpipe_addr + HPIPE_LANE_CONFIG0_REG, |
| 213 | 0x1 << HPIPE_LANE_CONFIG0_TXDEEMPH0_OFFSET, |
| 214 | HPIPE_LANE_CONFIG0_TXDEEMPH0_MASK); |
| 215 | /* override tx margining from the MAC */ |
| 216 | reg_set(hpipe_addr + HPIPE_TST_MODE_CTRL_REG, |
| 217 | 0x1 << HPIPE_TST_MODE_CTRL_MODE_MARGIN_OFFSET, |
| 218 | HPIPE_TST_MODE_CTRL_MODE_MARGIN_MASK); |
| 219 | |
| 220 | /* Start analog paramters from ETP(HW) */ |
| 221 | debug("stage: Analog paramters from ETP(HW)\n"); |
| 222 | /* Set Pin DFE_PAT_DIS -> Bit[1]: PIN_DFE_PAT_DIS = 0x0 */ |
| 223 | mask = HPIPE_LANE_CFG4_DFE_CTRL_MASK; |
| 224 | data = 0x1 << HPIPE_LANE_CFG4_DFE_CTRL_OFFSET; |
| 225 | /* Set Override PHY DFE control pins for 0x1 */ |
| 226 | mask |= HPIPE_LANE_CFG4_DFE_OVER_MASK; |
| 227 | data |= 0x1 << HPIPE_LANE_CFG4_DFE_OVER_OFFSET; |
| 228 | /* Set Spread Spectrum Clock Enable fot 0x1 */ |
| 229 | mask |= HPIPE_LANE_CFG4_SSC_CTRL_MASK; |
| 230 | data |= 0x1 << HPIPE_LANE_CFG4_SSC_CTRL_OFFSET; |
| 231 | reg_set(hpipe_addr + HPIPE_LANE_CFG4_REG, data, mask); |
| 232 | /* End of analog parameters */ |
| 233 | |
| 234 | debug("stage: Comphy power up\n"); |
| 235 | /* Release from PIPE soft reset */ |
| 236 | reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG, |
| 237 | 0x0 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET, |
| 238 | HPIPE_RST_CLK_CTRL_PIPE_RST_MASK); |
| 239 | |
| 240 | /* wait 15ms - for comphy calibration done */ |
| 241 | debug("stage: Check PLL\n"); |
| 242 | /* Read lane status */ |
| 243 | addr = hpipe_addr + HPIPE_LANE_STATUS1_REG; |
| 244 | data = HPIPE_LANE_STATUS1_PCLK_EN_MASK; |
| 245 | mask = data; |
| 246 | data = polling_with_timeout(addr, data, mask, 15000); |
| 247 | if (data != 0) { |
| 248 | debug("Read from reg = %p - value = 0x%x\n", |
| 249 | hpipe_addr + HPIPE_LANE_STATUS1_REG, data); |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 250 | pr_err("HPIPE_LANE_STATUS1_PCLK_EN_MASK is 0\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 251 | ret = 0; |
| 252 | } |
| 253 | |
| 254 | debug_exit(); |
| 255 | return ret; |
| 256 | } |
| 257 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 258 | static int comphy_smc(u32 function_id, void __iomem *comphy_base_addr, |
| 259 | u32 lane, u32 mode) |
| 260 | { |
| 261 | struct pt_regs pregs = {0}; |
| 262 | |
| 263 | pregs.regs[0] = function_id; |
| 264 | pregs.regs[1] = (unsigned long)comphy_base_addr; |
| 265 | pregs.regs[2] = lane; |
| 266 | pregs.regs[3] = mode; |
| 267 | |
| 268 | smc_call(&pregs); |
| 269 | |
| 270 | /* |
| 271 | * TODO: Firmware return 0 on success, temporary map it to u-boot |
| 272 | * convention, but after all comphy will be reworked the convention in |
| 273 | * u-boot should be change and this conversion removed |
| 274 | */ |
| 275 | return pregs.regs[0] ? 0 : 1; |
| 276 | } |
| 277 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 278 | static int comphy_sata_power_up(u32 lane, void __iomem *hpipe_base, |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 279 | void __iomem *comphy_base_addr, int cp_index, |
| 280 | u32 type) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 281 | { |
| 282 | u32 mask, data, i, ret = 1; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 283 | void __iomem *sata_base = NULL; |
| 284 | int sata_node = -1; /* Set to -1 in order to read the first sata node */ |
| 285 | |
| 286 | debug_enter(); |
| 287 | |
| 288 | /* |
| 289 | * Assumption - each CP has only one SATA controller |
| 290 | * Calling fdt_node_offset_by_compatible first time (with sata_node = -1 |
| 291 | * will return the first node always. |
| 292 | * In order to parse each CPs SATA node, fdt_node_offset_by_compatible |
| 293 | * must be called again (according to the CP id) |
| 294 | */ |
Igal Liberman | c8855ce | 2017-04-24 18:45:32 +0300 | [diff] [blame] | 295 | for (i = 0; i < (cp_index + 1); i++) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 296 | sata_node = fdt_node_offset_by_compatible( |
| 297 | gd->fdt_blob, sata_node, "marvell,armada-8k-ahci"); |
| 298 | |
| 299 | if (sata_node == 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 300 | pr_err("SATA node not found in FDT\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | sata_base = (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 305 | gd->fdt_blob, sata_node, "reg", 0, NULL, true); |
| 306 | if (sata_base == NULL) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 307 | pr_err("SATA address not found in FDT\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | debug("SATA address found in FDT %p\n", sata_base); |
| 312 | |
| 313 | debug("stage: MAC configuration - power down comphy\n"); |
| 314 | /* |
| 315 | * MAC configuration powe down comphy use indirect address for |
| 316 | * vendor spesific SATA control register |
| 317 | */ |
| 318 | reg_set(sata_base + SATA3_VENDOR_ADDRESS, |
| 319 | SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET, |
| 320 | SATA3_VENDOR_ADDR_MASK); |
| 321 | /* SATA 0 power down */ |
| 322 | mask = SATA3_CTRL_SATA0_PD_MASK; |
| 323 | data = 0x1 << SATA3_CTRL_SATA0_PD_OFFSET; |
| 324 | /* SATA 1 power down */ |
| 325 | mask |= SATA3_CTRL_SATA1_PD_MASK; |
| 326 | data |= 0x1 << SATA3_CTRL_SATA1_PD_OFFSET; |
| 327 | /* SATA SSU disable */ |
| 328 | mask |= SATA3_CTRL_SATA1_ENABLE_MASK; |
| 329 | data |= 0x0 << SATA3_CTRL_SATA1_ENABLE_OFFSET; |
| 330 | /* SATA port 1 disable */ |
| 331 | mask |= SATA3_CTRL_SATA_SSU_MASK; |
| 332 | data |= 0x0 << SATA3_CTRL_SATA_SSU_OFFSET; |
| 333 | reg_set(sata_base + SATA3_VENDOR_DATA, data, mask); |
| 334 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 335 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, comphy_base_addr, lane, type); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 336 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 337 | /* |
| 338 | * MAC configuration power up comphy - power up PLL/TX/RX |
| 339 | * use indirect address for vendor spesific SATA control register |
| 340 | */ |
| 341 | reg_set(sata_base + SATA3_VENDOR_ADDRESS, |
| 342 | SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET, |
| 343 | SATA3_VENDOR_ADDR_MASK); |
| 344 | /* SATA 0 power up */ |
| 345 | mask = SATA3_CTRL_SATA0_PD_MASK; |
| 346 | data = 0x0 << SATA3_CTRL_SATA0_PD_OFFSET; |
| 347 | /* SATA 1 power up */ |
| 348 | mask |= SATA3_CTRL_SATA1_PD_MASK; |
| 349 | data |= 0x0 << SATA3_CTRL_SATA1_PD_OFFSET; |
| 350 | /* SATA SSU enable */ |
| 351 | mask |= SATA3_CTRL_SATA1_ENABLE_MASK; |
| 352 | data |= 0x1 << SATA3_CTRL_SATA1_ENABLE_OFFSET; |
| 353 | /* SATA port 1 enable */ |
| 354 | mask |= SATA3_CTRL_SATA_SSU_MASK; |
| 355 | data |= 0x1 << SATA3_CTRL_SATA_SSU_OFFSET; |
| 356 | reg_set(sata_base + SATA3_VENDOR_DATA, data, mask); |
| 357 | |
| 358 | /* MBUS request size and interface select register */ |
| 359 | reg_set(sata_base + SATA3_VENDOR_ADDRESS, |
| 360 | SATA_MBUS_SIZE_SELECT_REG << SATA3_VENDOR_ADDR_OFSSET, |
| 361 | SATA3_VENDOR_ADDR_MASK); |
| 362 | /* Mbus regret enable */ |
| 363 | reg_set(sata_base + SATA3_VENDOR_DATA, |
| 364 | 0x1 << SATA_MBUS_REGRET_EN_OFFSET, SATA_MBUS_REGRET_EN_MASK); |
| 365 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 366 | ret = comphy_smc(MV_SIP_COMPHY_PLL_LOCK, comphy_base_addr, lane, type); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 367 | |
| 368 | debug_exit(); |
| 369 | return ret; |
| 370 | } |
| 371 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 372 | static int comphy_rxauii_power_up(u32 lane, void __iomem *hpipe_base, |
| 373 | void __iomem *comphy_base) |
| 374 | { |
| 375 | u32 mask, data, ret = 1; |
| 376 | void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane); |
| 377 | void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane); |
| 378 | void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane); |
| 379 | void __iomem *addr; |
| 380 | |
| 381 | debug_enter(); |
| 382 | debug("stage: RFU configurations - hard reset comphy\n"); |
| 383 | /* RFU configurations - hard reset comphy */ |
| 384 | mask = COMMON_PHY_CFG1_PWR_UP_MASK; |
| 385 | data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET; |
| 386 | mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK; |
| 387 | data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET; |
| 388 | reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask); |
| 389 | |
| 390 | if (lane == 2) { |
| 391 | reg_set(comphy_base + COMMON_PHY_SD_CTRL1, |
| 392 | 0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET, |
| 393 | COMMON_PHY_SD_CTRL1_RXAUI0_MASK); |
| 394 | } |
| 395 | if (lane == 4) { |
| 396 | reg_set(comphy_base + COMMON_PHY_SD_CTRL1, |
| 397 | 0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET, |
| 398 | COMMON_PHY_SD_CTRL1_RXAUI1_MASK); |
| 399 | } |
| 400 | |
| 401 | /* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */ |
| 402 | mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; |
| 403 | data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; |
| 404 | mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK; |
| 405 | data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET; |
| 406 | mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK; |
| 407 | data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET; |
| 408 | mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; |
| 409 | data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; |
| 410 | mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; |
| 411 | data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; |
| 412 | mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK; |
| 413 | data |= 0x0 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET; |
| 414 | mask |= SD_EXTERNAL_CONFIG0_MEDIA_MODE_MASK; |
| 415 | data |= 0x1 << SD_EXTERNAL_CONFIG0_MEDIA_MODE_OFFSET; |
| 416 | reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); |
| 417 | |
| 418 | /* release from hard reset */ |
| 419 | mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; |
| 420 | data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; |
| 421 | mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; |
| 422 | data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; |
| 423 | mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; |
| 424 | data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; |
| 425 | reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); |
| 426 | |
| 427 | mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK; |
| 428 | data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET; |
| 429 | mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK; |
| 430 | data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET; |
| 431 | reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); |
| 432 | |
| 433 | /* Wait 1ms - until band gap and ref clock ready */ |
| 434 | mdelay(1); |
| 435 | |
| 436 | /* Start comphy Configuration */ |
| 437 | debug("stage: Comphy configuration\n"); |
| 438 | /* set reference clock */ |
| 439 | reg_set(hpipe_addr + HPIPE_MISC_REG, |
| 440 | 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET, |
| 441 | HPIPE_MISC_REFCLK_SEL_MASK); |
| 442 | /* Power and PLL Control */ |
| 443 | mask = HPIPE_PWR_PLL_REF_FREQ_MASK; |
| 444 | data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET; |
| 445 | mask |= HPIPE_PWR_PLL_PHY_MODE_MASK; |
| 446 | data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET; |
| 447 | reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask); |
| 448 | /* Loopback register */ |
| 449 | reg_set(hpipe_addr + HPIPE_LOOPBACK_REG, |
| 450 | 0x1 << HPIPE_LOOPBACK_SEL_OFFSET, HPIPE_LOOPBACK_SEL_MASK); |
| 451 | /* rx control 1 */ |
| 452 | mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK; |
| 453 | data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET; |
| 454 | mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK; |
| 455 | data |= 0x1 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET; |
| 456 | reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask); |
| 457 | /* DTL Control */ |
| 458 | reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG, |
| 459 | 0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET, |
| 460 | HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK); |
| 461 | |
| 462 | /* Set analog paramters from ETP(HW) */ |
| 463 | debug("stage: Analog paramters from ETP(HW)\n"); |
| 464 | /* SERDES External Configuration 2 */ |
| 465 | reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG, |
| 466 | 0x1 << SD_EXTERNAL_CONFIG2_PIN_DFE_EN_OFFSET, |
| 467 | SD_EXTERNAL_CONFIG2_PIN_DFE_EN_MASK); |
| 468 | /* 0x7-DFE Resolution control */ |
| 469 | reg_set(hpipe_addr + HPIPE_DFE_REG0, 0x1 << HPIPE_DFE_RES_FORCE_OFFSET, |
| 470 | HPIPE_DFE_RES_FORCE_MASK); |
| 471 | /* 0xd-G1_Setting_0 */ |
| 472 | reg_set(hpipe_addr + HPIPE_G1_SET_0_REG, |
| 473 | 0xd << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET, |
| 474 | HPIPE_G1_SET_0_G1_TX_EMPH1_MASK); |
| 475 | /* 0xE-G1_Setting_1 */ |
| 476 | mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK; |
| 477 | data = 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET; |
| 478 | mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK; |
| 479 | data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET; |
| 480 | mask |= HPIPE_G1_SET_1_G1_RX_DFE_EN_MASK; |
| 481 | data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DFE_EN_OFFSET; |
| 482 | reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask); |
| 483 | /* 0xA-DFE_Reg3 */ |
| 484 | mask = HPIPE_DFE_F3_F5_DFE_EN_MASK; |
| 485 | data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET; |
| 486 | mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK; |
| 487 | data |= 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET; |
| 488 | reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask); |
| 489 | |
| 490 | /* 0x111-G1_Setting_4 */ |
| 491 | mask = HPIPE_G1_SETTINGS_4_G1_DFE_RES_MASK; |
| 492 | data = 0x1 << HPIPE_G1_SETTINGS_4_G1_DFE_RES_OFFSET; |
| 493 | reg_set(hpipe_addr + HPIPE_G1_SETTINGS_4_REG, data, mask); |
| 494 | |
| 495 | debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n"); |
| 496 | /* SERDES External Configuration */ |
| 497 | mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK; |
| 498 | data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET; |
| 499 | mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK; |
| 500 | data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET; |
| 501 | mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK; |
| 502 | data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET; |
| 503 | reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask); |
| 504 | |
| 505 | |
| 506 | /* check PLL rx & tx ready */ |
| 507 | addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; |
| 508 | data = SD_EXTERNAL_STATUS0_PLL_RX_MASK | |
| 509 | SD_EXTERNAL_STATUS0_PLL_TX_MASK; |
| 510 | mask = data; |
| 511 | data = polling_with_timeout(addr, data, mask, 15000); |
| 512 | if (data != 0) { |
| 513 | debug("Read from reg = %p - value = 0x%x\n", |
| 514 | sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 515 | pr_err("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n", |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 516 | (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK), |
| 517 | (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK)); |
| 518 | ret = 0; |
| 519 | } |
| 520 | |
| 521 | /* RX init */ |
| 522 | reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, |
| 523 | 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET, |
| 524 | SD_EXTERNAL_CONFIG1_RX_INIT_MASK); |
| 525 | |
| 526 | /* check that RX init done */ |
| 527 | addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG; |
| 528 | data = SD_EXTERNAL_STATUS0_RX_INIT_MASK; |
| 529 | mask = data; |
| 530 | data = polling_with_timeout(addr, data, mask, 100); |
| 531 | if (data != 0) { |
| 532 | debug("Read from reg = %p - value = 0x%x\n", |
| 533 | sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data); |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 534 | pr_err("SD_EXTERNAL_STATUS0_RX_INIT is 0\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 535 | ret = 0; |
| 536 | } |
| 537 | |
| 538 | debug("stage: RF Reset\n"); |
| 539 | /* RF Reset */ |
| 540 | mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK; |
| 541 | data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET; |
| 542 | mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK; |
| 543 | data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET; |
| 544 | reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask); |
| 545 | |
| 546 | debug_exit(); |
| 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | static void comphy_utmi_power_down(u32 utmi_index, void __iomem *utmi_base_addr, |
| 551 | void __iomem *usb_cfg_addr, |
| 552 | void __iomem *utmi_cfg_addr, |
| 553 | u32 utmi_phy_port) |
| 554 | { |
| 555 | u32 mask, data; |
| 556 | |
| 557 | debug_enter(); |
| 558 | debug("stage: UTMI %d - Power down transceiver (power down Phy), Power down PLL, and SuspendDM\n", |
| 559 | utmi_index); |
| 560 | /* Power down UTMI PHY */ |
| 561 | reg_set(utmi_cfg_addr, 0x0 << UTMI_PHY_CFG_PU_OFFSET, |
| 562 | UTMI_PHY_CFG_PU_MASK); |
| 563 | |
| 564 | /* |
| 565 | * If UTMI connected to USB Device, configure mux prior to PHY init |
| 566 | * (Device can be connected to UTMI0 or to UTMI1) |
| 567 | */ |
Stefan Roese | b781f57 | 2017-04-24 18:45:23 +0300 | [diff] [blame] | 568 | if (utmi_phy_port == UTMI_PHY_TO_USB3_DEVICE0) { |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 569 | debug("stage: UTMI %d - Enable Device mode and configure UTMI mux\n", |
| 570 | utmi_index); |
| 571 | /* USB3 Device UTMI enable */ |
| 572 | mask = UTMI_USB_CFG_DEVICE_EN_MASK; |
| 573 | data = 0x1 << UTMI_USB_CFG_DEVICE_EN_OFFSET; |
| 574 | /* USB3 Device UTMI MUX */ |
| 575 | mask |= UTMI_USB_CFG_DEVICE_MUX_MASK; |
| 576 | data |= utmi_index << UTMI_USB_CFG_DEVICE_MUX_OFFSET; |
| 577 | reg_set(usb_cfg_addr, data, mask); |
| 578 | } |
| 579 | |
| 580 | /* Set Test suspendm mode */ |
| 581 | mask = UTMI_CTRL_STATUS0_SUSPENDM_MASK; |
| 582 | data = 0x1 << UTMI_CTRL_STATUS0_SUSPENDM_OFFSET; |
| 583 | /* Enable Test UTMI select */ |
| 584 | mask |= UTMI_CTRL_STATUS0_TEST_SEL_MASK; |
| 585 | data |= 0x1 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET; |
| 586 | reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, data, mask); |
| 587 | |
| 588 | /* Wait for UTMI power down */ |
| 589 | mdelay(1); |
| 590 | |
| 591 | debug_exit(); |
| 592 | return; |
| 593 | } |
| 594 | |
| 595 | static void comphy_utmi_phy_config(u32 utmi_index, void __iomem *utmi_base_addr, |
| 596 | void __iomem *usb_cfg_addr, |
| 597 | void __iomem *utmi_cfg_addr, |
| 598 | u32 utmi_phy_port) |
| 599 | { |
| 600 | u32 mask, data; |
| 601 | |
| 602 | debug_exit(); |
| 603 | debug("stage: Configure UTMI PHY %d registers\n", utmi_index); |
| 604 | /* Reference Clock Divider Select */ |
| 605 | mask = UTMI_PLL_CTRL_REFDIV_MASK; |
| 606 | data = 0x5 << UTMI_PLL_CTRL_REFDIV_OFFSET; |
| 607 | /* Feedback Clock Divider Select - 90 for 25Mhz*/ |
| 608 | mask |= UTMI_PLL_CTRL_FBDIV_MASK; |
| 609 | data |= 0x60 << UTMI_PLL_CTRL_FBDIV_OFFSET; |
| 610 | /* Select LPFR - 0x0 for 25Mhz/5=5Mhz*/ |
| 611 | mask |= UTMI_PLL_CTRL_SEL_LPFR_MASK; |
| 612 | data |= 0x0 << UTMI_PLL_CTRL_SEL_LPFR_OFFSET; |
| 613 | reg_set(utmi_base_addr + UTMI_PLL_CTRL_REG, data, mask); |
| 614 | |
| 615 | /* Impedance Calibration Threshold Setting */ |
| 616 | reg_set(utmi_base_addr + UTMI_CALIB_CTRL_REG, |
Igal Liberman | 32af216 | 2017-04-30 20:16:55 +0300 | [diff] [blame^] | 617 | 0x7 << UTMI_CALIB_CTRL_IMPCAL_VTH_OFFSET, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 618 | UTMI_CALIB_CTRL_IMPCAL_VTH_MASK); |
| 619 | |
| 620 | /* Set LS TX driver strength coarse control */ |
Igal Liberman | 32af216 | 2017-04-30 20:16:55 +0300 | [diff] [blame^] | 621 | mask = UTMI_TX_CH_CTRL_AMP_MASK; |
| 622 | data = 0x4 << UTMI_TX_CH_CTRL_AMP_OFFSET; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 623 | reg_set(utmi_base_addr + UTMI_TX_CH_CTRL_REG, data, mask); |
| 624 | |
| 625 | /* Enable SQ */ |
| 626 | mask = UTMI_RX_CH_CTRL0_SQ_DET_MASK; |
| 627 | data = 0x0 << UTMI_RX_CH_CTRL0_SQ_DET_OFFSET; |
| 628 | /* Enable analog squelch detect */ |
| 629 | mask |= UTMI_RX_CH_CTRL0_SQ_ANA_DTC_MASK; |
| 630 | data |= 0x1 << UTMI_RX_CH_CTRL0_SQ_ANA_DTC_OFFSET; |
| 631 | reg_set(utmi_base_addr + UTMI_RX_CH_CTRL0_REG, data, mask); |
| 632 | |
| 633 | /* Set External squelch calibration number */ |
| 634 | mask = UTMI_RX_CH_CTRL1_SQ_AMP_CAL_MASK; |
| 635 | data = 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_OFFSET; |
| 636 | /* Enable the External squelch calibration */ |
| 637 | mask |= UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_MASK; |
| 638 | data |= 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_OFFSET; |
| 639 | reg_set(utmi_base_addr + UTMI_RX_CH_CTRL1_REG, data, mask); |
| 640 | |
| 641 | /* Set Control VDAT Reference Voltage - 0.325V */ |
| 642 | mask = UTMI_CHGDTC_CTRL_VDAT_MASK; |
| 643 | data = 0x1 << UTMI_CHGDTC_CTRL_VDAT_OFFSET; |
| 644 | /* Set Control VSRC Reference Voltage - 0.6V */ |
| 645 | mask |= UTMI_CHGDTC_CTRL_VSRC_MASK; |
| 646 | data |= 0x1 << UTMI_CHGDTC_CTRL_VSRC_OFFSET; |
| 647 | reg_set(utmi_base_addr + UTMI_CHGDTC_CTRL_REG, data, mask); |
| 648 | |
| 649 | debug_exit(); |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | static int comphy_utmi_power_up(u32 utmi_index, void __iomem *utmi_base_addr, |
| 654 | void __iomem *usb_cfg_addr, |
| 655 | void __iomem *utmi_cfg_addr, u32 utmi_phy_port) |
| 656 | { |
| 657 | u32 data, mask, ret = 1; |
| 658 | void __iomem *addr; |
| 659 | |
| 660 | debug_enter(); |
| 661 | debug("stage: UTMI %d - Power up transceiver(Power up Phy), and exit SuspendDM\n", |
| 662 | utmi_index); |
| 663 | /* Power UP UTMI PHY */ |
| 664 | reg_set(utmi_cfg_addr, 0x1 << UTMI_PHY_CFG_PU_OFFSET, |
| 665 | UTMI_PHY_CFG_PU_MASK); |
| 666 | /* Disable Test UTMI select */ |
| 667 | reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, |
| 668 | 0x0 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET, |
| 669 | UTMI_CTRL_STATUS0_TEST_SEL_MASK); |
| 670 | |
| 671 | debug("stage: Polling for PLL and impedance calibration done, and PLL ready done\n"); |
| 672 | addr = utmi_base_addr + UTMI_CALIB_CTRL_REG; |
| 673 | data = UTMI_CALIB_CTRL_IMPCAL_DONE_MASK; |
| 674 | mask = data; |
| 675 | data = polling_with_timeout(addr, data, mask, 100); |
| 676 | if (data != 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 677 | pr_err("Impedance calibration is not done\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 678 | debug("Read from reg = %p - value = 0x%x\n", addr, data); |
| 679 | ret = 0; |
| 680 | } |
| 681 | |
| 682 | data = UTMI_CALIB_CTRL_PLLCAL_DONE_MASK; |
| 683 | mask = data; |
| 684 | data = polling_with_timeout(addr, data, mask, 100); |
| 685 | if (data != 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 686 | pr_err("PLL calibration is not done\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 687 | debug("Read from reg = %p - value = 0x%x\n", addr, data); |
| 688 | ret = 0; |
| 689 | } |
| 690 | |
| 691 | addr = utmi_base_addr + UTMI_PLL_CTRL_REG; |
| 692 | data = UTMI_PLL_CTRL_PLL_RDY_MASK; |
| 693 | mask = data; |
| 694 | data = polling_with_timeout(addr, data, mask, 100); |
| 695 | if (data != 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 696 | pr_err("PLL is not ready\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 697 | debug("Read from reg = %p - value = 0x%x\n", addr, data); |
| 698 | ret = 0; |
| 699 | } |
| 700 | |
| 701 | if (ret) |
| 702 | debug("Passed\n"); |
| 703 | else |
| 704 | debug("\n"); |
| 705 | |
| 706 | debug_exit(); |
| 707 | return ret; |
| 708 | } |
| 709 | |
| 710 | /* |
| 711 | * comphy_utmi_phy_init initialize the UTMI PHY |
| 712 | * the init split in 3 parts: |
| 713 | * 1. Power down transceiver and PLL |
| 714 | * 2. UTMI PHY configure |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 715 | * 3. Power up transceiver and PLL |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 716 | * Note: - Power down/up should be once for both UTMI PHYs |
| 717 | * - comphy_dedicated_phys_init call this function if at least there is |
| 718 | * one UTMI PHY exists in FDT blob. access to cp110_utmi_data[0] is |
| 719 | * legal |
| 720 | */ |
| 721 | static void comphy_utmi_phy_init(u32 utmi_phy_count, |
| 722 | struct utmi_phy_data *cp110_utmi_data) |
| 723 | { |
| 724 | u32 i; |
| 725 | |
| 726 | debug_enter(); |
| 727 | /* UTMI Power down */ |
| 728 | for (i = 0; i < utmi_phy_count; i++) { |
| 729 | comphy_utmi_power_down(i, cp110_utmi_data[i].utmi_base_addr, |
| 730 | cp110_utmi_data[i].usb_cfg_addr, |
| 731 | cp110_utmi_data[i].utmi_cfg_addr, |
| 732 | cp110_utmi_data[i].utmi_phy_port); |
| 733 | } |
| 734 | /* PLL Power down */ |
| 735 | debug("stage: UTMI PHY power down PLL\n"); |
| 736 | for (i = 0; i < utmi_phy_count; i++) { |
| 737 | reg_set(cp110_utmi_data[i].usb_cfg_addr, |
| 738 | 0x0 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK); |
| 739 | } |
| 740 | /* UTMI configure */ |
| 741 | for (i = 0; i < utmi_phy_count; i++) { |
| 742 | comphy_utmi_phy_config(i, cp110_utmi_data[i].utmi_base_addr, |
| 743 | cp110_utmi_data[i].usb_cfg_addr, |
| 744 | cp110_utmi_data[i].utmi_cfg_addr, |
| 745 | cp110_utmi_data[i].utmi_phy_port); |
| 746 | } |
| 747 | /* UTMI Power up */ |
| 748 | for (i = 0; i < utmi_phy_count; i++) { |
| 749 | if (!comphy_utmi_power_up(i, cp110_utmi_data[i].utmi_base_addr, |
| 750 | cp110_utmi_data[i].usb_cfg_addr, |
| 751 | cp110_utmi_data[i].utmi_cfg_addr, |
| 752 | cp110_utmi_data[i].utmi_phy_port)) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 753 | pr_err("Failed to initialize UTMI PHY %d\n", i); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 754 | continue; |
| 755 | } |
| 756 | printf("UTMI PHY %d initialized to ", i); |
Stefan Roese | b781f57 | 2017-04-24 18:45:23 +0300 | [diff] [blame] | 757 | if (cp110_utmi_data[i].utmi_phy_port == |
| 758 | UTMI_PHY_TO_USB3_DEVICE0) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 759 | printf("USB Device\n"); |
| 760 | else |
| 761 | printf("USB Host%d\n", |
| 762 | cp110_utmi_data[i].utmi_phy_port); |
| 763 | } |
| 764 | /* PLL Power up */ |
| 765 | debug("stage: UTMI PHY power up PLL\n"); |
| 766 | for (i = 0; i < utmi_phy_count; i++) { |
| 767 | reg_set(cp110_utmi_data[i].usb_cfg_addr, |
| 768 | 0x1 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK); |
| 769 | } |
| 770 | |
| 771 | debug_exit(); |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | /* |
| 776 | * comphy_dedicated_phys_init initialize the dedicated PHYs |
| 777 | * - not muxed SerDes lanes e.g. UTMI PHY |
| 778 | */ |
| 779 | void comphy_dedicated_phys_init(void) |
| 780 | { |
| 781 | struct utmi_phy_data cp110_utmi_data[MAX_UTMI_PHY_COUNT]; |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 782 | int node = -1; |
| 783 | int node_idx; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 784 | |
| 785 | debug_enter(); |
| 786 | debug("Initialize USB UTMI PHYs\n"); |
| 787 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 788 | for (node_idx = 0; node_idx < MAX_UTMI_PHY_COUNT;) { |
| 789 | /* Find the UTMI phy node in device tree */ |
| 790 | node = fdt_node_offset_by_compatible(gd->fdt_blob, node, |
| 791 | "marvell,mvebu-utmi-2.6.0"); |
| 792 | if (node <= 0) |
| 793 | break; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 794 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 795 | /* check if node is enabled */ |
| 796 | if (!fdtdec_get_is_enabled(gd->fdt_blob, node)) |
| 797 | continue; |
| 798 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 799 | /* get base address of UTMI phy */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 800 | cp110_utmi_data[node_idx].utmi_base_addr = |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 801 | (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 802 | gd->fdt_blob, node, "reg", 0, NULL, true); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 803 | if (!cp110_utmi_data[node_idx].utmi_base_addr) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 804 | pr_err("UTMI PHY base address is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 805 | continue; |
| 806 | } |
| 807 | |
| 808 | /* get usb config address */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 809 | cp110_utmi_data[node_idx].usb_cfg_addr = |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 810 | (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 811 | gd->fdt_blob, node, "reg", 1, NULL, true); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 812 | if (!cp110_utmi_data[node_idx].usb_cfg_addr) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 813 | pr_err("UTMI PHY base address is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 814 | continue; |
| 815 | } |
| 816 | |
| 817 | /* get UTMI config address */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 818 | cp110_utmi_data[node_idx].utmi_cfg_addr = |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 819 | (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 820 | gd->fdt_blob, node, "reg", 2, NULL, true); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 821 | if (!cp110_utmi_data[node_idx].utmi_cfg_addr) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 822 | pr_err("UTMI PHY base address is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 823 | continue; |
| 824 | } |
| 825 | |
| 826 | /* |
| 827 | * get the port number (to check if the utmi connected to |
| 828 | * host/device) |
| 829 | */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 830 | cp110_utmi_data[node_idx].utmi_phy_port = fdtdec_get_int( |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 831 | gd->fdt_blob, node, "utmi-port", UTMI_PHY_INVALID); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 832 | if (cp110_utmi_data[node_idx].utmi_phy_port == |
| 833 | UTMI_PHY_INVALID) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 834 | pr_err("UTMI PHY port type is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 835 | continue; |
| 836 | } |
| 837 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 838 | /* count valid UTMI unit */ |
| 839 | node_idx++; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 842 | if (node_idx > 0) |
| 843 | comphy_utmi_phy_init(node_idx, cp110_utmi_data); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 844 | |
| 845 | debug_exit(); |
| 846 | } |
| 847 | |
| 848 | static void comphy_mux_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, |
| 849 | struct comphy_map *serdes_map) |
| 850 | { |
| 851 | void __iomem *comphy_base_addr; |
| 852 | struct comphy_map comphy_map_pipe_data[MAX_LANE_OPTIONS]; |
| 853 | struct comphy_map comphy_map_phy_data[MAX_LANE_OPTIONS]; |
| 854 | u32 lane, comphy_max_count; |
| 855 | |
| 856 | comphy_max_count = ptr_chip_cfg->comphy_lanes_count; |
| 857 | comphy_base_addr = ptr_chip_cfg->comphy_base_addr; |
| 858 | |
| 859 | /* |
| 860 | * Copy the SerDes map configuration for PIPE map and PHY map |
| 861 | * the comphy_mux_init modify the type of the lane if the type |
| 862 | * is not valid because we have 2 selectores run the |
| 863 | * comphy_mux_init twice and after that update the original |
| 864 | * serdes_map |
| 865 | */ |
| 866 | for (lane = 0; lane < comphy_max_count; lane++) { |
| 867 | comphy_map_pipe_data[lane].type = serdes_map[lane].type; |
| 868 | comphy_map_pipe_data[lane].speed = serdes_map[lane].speed; |
| 869 | comphy_map_phy_data[lane].type = serdes_map[lane].type; |
| 870 | comphy_map_phy_data[lane].speed = serdes_map[lane].speed; |
| 871 | } |
| 872 | ptr_chip_cfg->mux_data = cp110_comphy_phy_mux_data; |
| 873 | comphy_mux_init(ptr_chip_cfg, comphy_map_phy_data, |
| 874 | comphy_base_addr + COMMON_SELECTOR_PHY_OFFSET); |
| 875 | |
| 876 | ptr_chip_cfg->mux_data = cp110_comphy_pipe_mux_data; |
| 877 | comphy_mux_init(ptr_chip_cfg, comphy_map_pipe_data, |
| 878 | comphy_base_addr + COMMON_SELECTOR_PIPE_OFFSET); |
| 879 | /* Fix the type after check the PHY and PIPE configuration */ |
| 880 | for (lane = 0; lane < comphy_max_count; lane++) { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 881 | if ((comphy_map_pipe_data[lane].type == COMPHY_TYPE_UNCONNECTED) && |
| 882 | (comphy_map_phy_data[lane].type == COMPHY_TYPE_UNCONNECTED)) |
| 883 | serdes_map[lane].type = COMPHY_TYPE_UNCONNECTED; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
| 887 | int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, |
| 888 | struct comphy_map *serdes_map) |
| 889 | { |
| 890 | struct comphy_map *ptr_comphy_map; |
| 891 | void __iomem *comphy_base_addr, *hpipe_base_addr; |
| 892 | u32 comphy_max_count, lane, ret = 0; |
| 893 | u32 pcie_width = 0; |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 894 | u32 mode; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 895 | |
| 896 | debug_enter(); |
| 897 | |
| 898 | comphy_max_count = ptr_chip_cfg->comphy_lanes_count; |
| 899 | comphy_base_addr = ptr_chip_cfg->comphy_base_addr; |
| 900 | hpipe_base_addr = ptr_chip_cfg->hpipe3_base_addr; |
| 901 | |
| 902 | /* Config Comphy mux configuration */ |
| 903 | comphy_mux_cp110_init(ptr_chip_cfg, serdes_map); |
| 904 | |
| 905 | /* Check if the first 4 lanes configured as By-4 */ |
| 906 | for (lane = 0, ptr_comphy_map = serdes_map; lane < 4; |
| 907 | lane++, ptr_comphy_map++) { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 908 | if (ptr_comphy_map->type != COMPHY_TYPE_PEX0) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 909 | break; |
| 910 | pcie_width++; |
| 911 | } |
| 912 | |
| 913 | for (lane = 0, ptr_comphy_map = serdes_map; lane < comphy_max_count; |
| 914 | lane++, ptr_comphy_map++) { |
| 915 | debug("Initialize serdes number %d\n", lane); |
| 916 | debug("Serdes type = 0x%x\n", ptr_comphy_map->type); |
| 917 | if (lane == 4) { |
| 918 | /* |
| 919 | * PCIe lanes above the first 4 lanes, can be only |
| 920 | * by1 |
| 921 | */ |
| 922 | pcie_width = 1; |
| 923 | } |
| 924 | switch (ptr_comphy_map->type) { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 925 | case COMPHY_TYPE_UNCONNECTED: |
| 926 | case COMPHY_TYPE_IGNORE: |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 927 | continue; |
| 928 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 929 | case COMPHY_TYPE_PEX0: |
| 930 | case COMPHY_TYPE_PEX1: |
| 931 | case COMPHY_TYPE_PEX2: |
| 932 | case COMPHY_TYPE_PEX3: |
Grzegorz Jaszczyk | c42b5a3 | 2020-10-18 17:11:12 +0300 | [diff] [blame] | 933 | mode = COMPHY_FW_PCIE_FORMAT(pcie_width, |
| 934 | ptr_comphy_map->clk_src, |
| 935 | COMPHY_PCIE_MODE, |
| 936 | ptr_comphy_map->speed); |
| 937 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 938 | ptr_chip_cfg->comphy_base_addr, lane, |
| 939 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 940 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 941 | case COMPHY_TYPE_SATA0: |
| 942 | case COMPHY_TYPE_SATA1: |
| 943 | case COMPHY_TYPE_SATA2: |
| 944 | case COMPHY_TYPE_SATA3: |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 945 | mode = COMPHY_FW_MODE_FORMAT(COMPHY_SATA_MODE); |
| 946 | ret = comphy_sata_power_up(lane, hpipe_base_addr, |
| 947 | comphy_base_addr, |
| 948 | ptr_chip_cfg->cp_index, |
| 949 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 950 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 951 | case COMPHY_TYPE_USB3_HOST0: |
| 952 | case COMPHY_TYPE_USB3_HOST1: |
| 953 | case COMPHY_TYPE_USB3_DEVICE: |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 954 | ret = comphy_usb3_power_up(lane, hpipe_base_addr, |
| 955 | comphy_base_addr); |
| 956 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 957 | case COMPHY_TYPE_SGMII0: |
| 958 | case COMPHY_TYPE_SGMII1: |
| 959 | if (ptr_comphy_map->speed == COMPHY_SPEED_INVALID) { |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 960 | debug("Warning: "); |
| 961 | debug("SGMII PHY speed in lane %d is invalid,", |
| 962 | lane); |
| 963 | debug(" set PHY speed to 1.25G\n"); |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 964 | ptr_comphy_map->speed = COMPHY_SPEED_1_25G; |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /* |
| 968 | * UINIT_ID not relevant for SGMII0 and SGMII1 - will be |
| 969 | * ignored by firmware |
| 970 | */ |
| 971 | mode = COMPHY_FW_FORMAT(COMPHY_SGMII_MODE, |
| 972 | COMPHY_UNIT_ID0, |
| 973 | ptr_comphy_map->speed); |
| 974 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 975 | ptr_chip_cfg->comphy_base_addr, lane, |
| 976 | mode); |
| 977 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 978 | case COMPHY_TYPE_SGMII2: |
| 979 | case COMPHY_TYPE_SGMII3: |
| 980 | if (ptr_comphy_map->speed == COMPHY_SPEED_INVALID) { |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 981 | debug("Warning: SGMII PHY speed in lane %d is invalid, set PHY speed to 1.25G\n", |
| 982 | lane); |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 983 | ptr_comphy_map->speed = COMPHY_SPEED_1_25G; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 984 | } |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 985 | |
| 986 | mode = COMPHY_FW_FORMAT(COMPHY_SGMII_MODE, |
| 987 | COMPHY_UNIT_ID2, |
| 988 | ptr_comphy_map->speed); |
| 989 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 990 | ptr_chip_cfg->comphy_base_addr, lane, |
| 991 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 992 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 993 | case COMPHY_TYPE_SFI: |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 994 | mode = COMPHY_FW_FORMAT(COMPHY_SFI_MODE, |
| 995 | COMPHY_UNIT_ID0, |
| 996 | ptr_comphy_map->speed); |
| 997 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 998 | ptr_chip_cfg->comphy_base_addr, lane, |
| 999 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 1000 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 1001 | case COMPHY_TYPE_RXAUI0: |
| 1002 | case COMPHY_TYPE_RXAUI1: |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 1003 | ret = comphy_rxauii_power_up(lane, hpipe_base_addr, |
| 1004 | comphy_base_addr); |
| 1005 | break; |
| 1006 | default: |
| 1007 | debug("Unknown SerDes type, skip initialize SerDes %d\n", |
| 1008 | lane); |
| 1009 | break; |
| 1010 | } |
| 1011 | if (ret == 0) { |
| 1012 | /* |
Stefan Roese | 4fbca01 | 2017-04-24 18:45:25 +0300 | [diff] [blame] | 1013 | * If interface wans't initialized, set the lane to |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 1014 | * COMPHY_TYPE_UNCONNECTED state. |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 1015 | */ |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 1016 | ptr_comphy_map->type = COMPHY_TYPE_UNCONNECTED; |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1017 | pr_err("PLL is not locked - Failed to initialize lane %d\n", |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 1018 | lane); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | debug_exit(); |
| 1023 | return 0; |
| 1024 | } |