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 "sata.h" |
| 18 | #include "utmi_phy.h" |
| 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 22 | /* Firmware related definitions used for SMC calls */ |
| 23 | #define MV_SIP_COMPHY_POWER_ON 0x82000001 |
| 24 | #define MV_SIP_COMPHY_POWER_OFF 0x82000002 |
| 25 | #define MV_SIP_COMPHY_PLL_LOCK 0x82000003 |
Grzegorz Jaszczyk | a8e6b49 | 2018-04-03 16:59:12 +0200 | [diff] [blame] | 26 | #define MV_SIP_COMPHY_XFI_TRAIN 0x82000004 |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 27 | |
Igal Liberman | 67d1a3f | 2020-10-18 17:11:13 +0300 | [diff] [blame] | 28 | /* Used to distinguish between different possible callers (U-boot/Linux) */ |
| 29 | #define COMPHY_CALLER_UBOOT (0x1 << 21) |
| 30 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 31 | #define COMPHY_FW_MODE_FORMAT(mode) ((mode) << 12) |
| 32 | #define COMPHY_FW_FORMAT(mode, idx, speeds) \ |
| 33 | (((mode) << 12) | ((idx) << 8) | ((speeds) << 2)) |
Grzegorz Jaszczyk | c42b5a3 | 2020-10-18 17:11:12 +0300 | [diff] [blame] | 34 | |
| 35 | #define COMPHY_FW_PCIE_FORMAT(pcie_width, clk_src, mode, speeds) \ |
Igal Liberman | 67d1a3f | 2020-10-18 17:11:13 +0300 | [diff] [blame] | 36 | (COMPHY_CALLER_UBOOT | ((pcie_width) << 18) | \ |
| 37 | ((clk_src) << 17) | COMPHY_FW_FORMAT(mode, 0, speeds)) |
Grzegorz Jaszczyk | c42b5a3 | 2020-10-18 17:11:12 +0300 | [diff] [blame] | 38 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 39 | #define COMPHY_SATA_MODE 0x1 |
| 40 | #define COMPHY_SGMII_MODE 0x2 /* SGMII 1G */ |
| 41 | #define COMPHY_HS_SGMII_MODE 0x3 /* SGMII 2.5G */ |
| 42 | #define COMPHY_USB3H_MODE 0x4 |
| 43 | #define COMPHY_USB3D_MODE 0x5 |
| 44 | #define COMPHY_PCIE_MODE 0x6 |
| 45 | #define COMPHY_RXAUI_MODE 0x7 |
| 46 | #define COMPHY_XFI_MODE 0x8 |
| 47 | #define COMPHY_SFI_MODE 0x9 |
| 48 | #define COMPHY_USB3_MODE 0xa |
| 49 | #define COMPHY_AP_MODE 0xb |
| 50 | |
| 51 | /* Comphy unit index macro */ |
| 52 | #define COMPHY_UNIT_ID0 0 |
| 53 | #define COMPHY_UNIT_ID1 1 |
| 54 | #define COMPHY_UNIT_ID2 2 |
| 55 | #define COMPHY_UNIT_ID3 3 |
| 56 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 57 | struct utmi_phy_data { |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 58 | void __iomem *utmi_pll_addr; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 59 | void __iomem *utmi_base_addr; |
| 60 | void __iomem *usb_cfg_addr; |
| 61 | void __iomem *utmi_cfg_addr; |
| 62 | u32 utmi_phy_port; |
| 63 | }; |
| 64 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 65 | static u32 polling_with_timeout(void __iomem *addr, u32 val, |
| 66 | u32 mask, unsigned long usec_timout) |
| 67 | { |
| 68 | u32 data; |
| 69 | |
| 70 | do { |
| 71 | udelay(1); |
| 72 | data = readl(addr) & mask; |
| 73 | } while (data != val && --usec_timout > 0); |
| 74 | |
| 75 | if (usec_timout == 0) |
| 76 | return data; |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Grzegorz Jaszczyk | a8e6b49 | 2018-04-03 16:59:12 +0200 | [diff] [blame] | 81 | static int comphy_smc(u32 function_id, void __iomem *comphy_base_addr, |
| 82 | u32 lane, u32 mode) |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 83 | { |
Grzegorz Jaszczyk | a8e6b49 | 2018-04-03 16:59:12 +0200 | [diff] [blame] | 84 | struct pt_regs pregs = {0}; |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 85 | |
Grzegorz Jaszczyk | a8e6b49 | 2018-04-03 16:59:12 +0200 | [diff] [blame] | 86 | pregs.regs[0] = function_id; |
| 87 | pregs.regs[1] = (unsigned long)comphy_base_addr; |
| 88 | pregs.regs[2] = lane; |
| 89 | pregs.regs[3] = mode; |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 90 | |
Grzegorz Jaszczyk | a8e6b49 | 2018-04-03 16:59:12 +0200 | [diff] [blame] | 91 | smc_call(&pregs); |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 92 | |
Grzegorz Jaszczyk | a8e6b49 | 2018-04-03 16:59:12 +0200 | [diff] [blame] | 93 | /* |
| 94 | * TODO: Firmware return 0 on success, temporary map it to u-boot |
| 95 | * convention, but after all comphy will be reworked the convention in |
| 96 | * u-boot should be change and this conversion removed |
| 97 | */ |
| 98 | return pregs.regs[0] ? 0 : 1; |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* This function performs RX training for all FFE possible values. |
| 102 | * We get the result for each FFE and eventually the best FFE will |
| 103 | * be used and set to the HW. |
| 104 | * |
| 105 | * Return '1' on succsess. |
| 106 | * Return '0' on failure. |
| 107 | */ |
| 108 | int comphy_cp110_sfi_rx_training(struct chip_serdes_phy_config *ptr_chip_cfg, |
| 109 | u32 lane) |
| 110 | { |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 111 | int ret; |
Igal Liberman | d7297e3 | 2018-05-14 11:20:54 +0300 | [diff] [blame^] | 112 | u32 type = ptr_chip_cfg->comphy_map_data[lane].type; |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 113 | |
| 114 | debug_enter(); |
| 115 | |
Igal Liberman | d7297e3 | 2018-05-14 11:20:54 +0300 | [diff] [blame^] | 116 | if (type != COMPHY_TYPE_SFI0 && type != COMPHY_TYPE_SFI1) { |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 117 | pr_err("Comphy %d isn't configured to SFI\n", lane); |
| 118 | return 0; |
| 119 | } |
| 120 | |
Grzegorz Jaszczyk | a8e6b49 | 2018-04-03 16:59:12 +0200 | [diff] [blame] | 121 | /* Mode is not relevant for xfi training */ |
| 122 | ret = comphy_smc(MV_SIP_COMPHY_XFI_TRAIN, |
| 123 | ptr_chip_cfg->comphy_base_addr, lane, 0); |
Igal Liberman | 6795a66 | 2021-03-23 11:57:57 +0100 | [diff] [blame] | 124 | |
| 125 | debug_exit(); |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 130 | static int comphy_sata_power_up(u32 lane, void __iomem *hpipe_base, |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 131 | void __iomem *comphy_base_addr, int cp_index, |
| 132 | u32 type) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 133 | { |
| 134 | u32 mask, data, i, ret = 1; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 135 | void __iomem *sata_base = NULL; |
| 136 | int sata_node = -1; /* Set to -1 in order to read the first sata node */ |
| 137 | |
| 138 | debug_enter(); |
| 139 | |
| 140 | /* |
| 141 | * Assumption - each CP has only one SATA controller |
| 142 | * Calling fdt_node_offset_by_compatible first time (with sata_node = -1 |
| 143 | * will return the first node always. |
| 144 | * In order to parse each CPs SATA node, fdt_node_offset_by_compatible |
| 145 | * must be called again (according to the CP id) |
| 146 | */ |
Igal Liberman | c8855ce | 2017-04-24 18:45:32 +0300 | [diff] [blame] | 147 | for (i = 0; i < (cp_index + 1); i++) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 148 | sata_node = fdt_node_offset_by_compatible( |
| 149 | gd->fdt_blob, sata_node, "marvell,armada-8k-ahci"); |
| 150 | |
| 151 | if (sata_node == 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 152 | pr_err("SATA node not found in FDT\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | sata_base = (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 157 | gd->fdt_blob, sata_node, "reg", 0, NULL, true); |
| 158 | if (sata_base == NULL) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 159 | pr_err("SATA address not found in FDT\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | debug("SATA address found in FDT %p\n", sata_base); |
| 164 | |
| 165 | debug("stage: MAC configuration - power down comphy\n"); |
| 166 | /* |
| 167 | * MAC configuration powe down comphy use indirect address for |
| 168 | * vendor spesific SATA control register |
| 169 | */ |
| 170 | reg_set(sata_base + SATA3_VENDOR_ADDRESS, |
| 171 | SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET, |
| 172 | SATA3_VENDOR_ADDR_MASK); |
| 173 | /* SATA 0 power down */ |
| 174 | mask = SATA3_CTRL_SATA0_PD_MASK; |
| 175 | data = 0x1 << SATA3_CTRL_SATA0_PD_OFFSET; |
| 176 | /* SATA 1 power down */ |
| 177 | mask |= SATA3_CTRL_SATA1_PD_MASK; |
| 178 | data |= 0x1 << SATA3_CTRL_SATA1_PD_OFFSET; |
| 179 | /* SATA SSU disable */ |
| 180 | mask |= SATA3_CTRL_SATA1_ENABLE_MASK; |
| 181 | data |= 0x0 << SATA3_CTRL_SATA1_ENABLE_OFFSET; |
| 182 | /* SATA port 1 disable */ |
| 183 | mask |= SATA3_CTRL_SATA_SSU_MASK; |
| 184 | data |= 0x0 << SATA3_CTRL_SATA_SSU_OFFSET; |
| 185 | reg_set(sata_base + SATA3_VENDOR_DATA, data, mask); |
| 186 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 187 | 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] | 188 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 189 | /* |
| 190 | * MAC configuration power up comphy - power up PLL/TX/RX |
| 191 | * use indirect address for vendor spesific SATA control register |
| 192 | */ |
| 193 | reg_set(sata_base + SATA3_VENDOR_ADDRESS, |
| 194 | SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET, |
| 195 | SATA3_VENDOR_ADDR_MASK); |
| 196 | /* SATA 0 power up */ |
| 197 | mask = SATA3_CTRL_SATA0_PD_MASK; |
| 198 | data = 0x0 << SATA3_CTRL_SATA0_PD_OFFSET; |
| 199 | /* SATA 1 power up */ |
| 200 | mask |= SATA3_CTRL_SATA1_PD_MASK; |
| 201 | data |= 0x0 << SATA3_CTRL_SATA1_PD_OFFSET; |
| 202 | /* SATA SSU enable */ |
| 203 | mask |= SATA3_CTRL_SATA1_ENABLE_MASK; |
| 204 | data |= 0x1 << SATA3_CTRL_SATA1_ENABLE_OFFSET; |
| 205 | /* SATA port 1 enable */ |
| 206 | mask |= SATA3_CTRL_SATA_SSU_MASK; |
| 207 | data |= 0x1 << SATA3_CTRL_SATA_SSU_OFFSET; |
| 208 | reg_set(sata_base + SATA3_VENDOR_DATA, data, mask); |
| 209 | |
| 210 | /* MBUS request size and interface select register */ |
| 211 | reg_set(sata_base + SATA3_VENDOR_ADDRESS, |
| 212 | SATA_MBUS_SIZE_SELECT_REG << SATA3_VENDOR_ADDR_OFSSET, |
| 213 | SATA3_VENDOR_ADDR_MASK); |
| 214 | /* Mbus regret enable */ |
| 215 | reg_set(sata_base + SATA3_VENDOR_DATA, |
| 216 | 0x1 << SATA_MBUS_REGRET_EN_OFFSET, SATA_MBUS_REGRET_EN_MASK); |
| 217 | |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 218 | 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] | 219 | |
| 220 | debug_exit(); |
| 221 | return ret; |
| 222 | } |
| 223 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 224 | static void comphy_utmi_power_down(u32 utmi_index, void __iomem *utmi_base_addr, |
| 225 | void __iomem *usb_cfg_addr, |
| 226 | void __iomem *utmi_cfg_addr, |
| 227 | u32 utmi_phy_port) |
| 228 | { |
| 229 | u32 mask, data; |
| 230 | |
| 231 | debug_enter(); |
| 232 | debug("stage: UTMI %d - Power down transceiver (power down Phy), Power down PLL, and SuspendDM\n", |
| 233 | utmi_index); |
| 234 | /* Power down UTMI PHY */ |
| 235 | reg_set(utmi_cfg_addr, 0x0 << UTMI_PHY_CFG_PU_OFFSET, |
| 236 | UTMI_PHY_CFG_PU_MASK); |
| 237 | |
| 238 | /* |
| 239 | * If UTMI connected to USB Device, configure mux prior to PHY init |
| 240 | * (Device can be connected to UTMI0 or to UTMI1) |
| 241 | */ |
Stefan Roese | b781f57 | 2017-04-24 18:45:23 +0300 | [diff] [blame] | 242 | if (utmi_phy_port == UTMI_PHY_TO_USB3_DEVICE0) { |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 243 | debug("stage: UTMI %d - Enable Device mode and configure UTMI mux\n", |
| 244 | utmi_index); |
| 245 | /* USB3 Device UTMI enable */ |
| 246 | mask = UTMI_USB_CFG_DEVICE_EN_MASK; |
| 247 | data = 0x1 << UTMI_USB_CFG_DEVICE_EN_OFFSET; |
| 248 | /* USB3 Device UTMI MUX */ |
| 249 | mask |= UTMI_USB_CFG_DEVICE_MUX_MASK; |
| 250 | data |= utmi_index << UTMI_USB_CFG_DEVICE_MUX_OFFSET; |
| 251 | reg_set(usb_cfg_addr, data, mask); |
| 252 | } |
| 253 | |
| 254 | /* Set Test suspendm mode */ |
| 255 | mask = UTMI_CTRL_STATUS0_SUSPENDM_MASK; |
| 256 | data = 0x1 << UTMI_CTRL_STATUS0_SUSPENDM_OFFSET; |
| 257 | /* Enable Test UTMI select */ |
| 258 | mask |= UTMI_CTRL_STATUS0_TEST_SEL_MASK; |
| 259 | data |= 0x1 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET; |
| 260 | reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, data, mask); |
| 261 | |
| 262 | /* Wait for UTMI power down */ |
| 263 | mdelay(1); |
| 264 | |
| 265 | debug_exit(); |
| 266 | return; |
| 267 | } |
| 268 | |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 269 | static void comphy_utmi_phy_config(u32 utmi_index, void __iomem *utmi_pll_addr, |
| 270 | void __iomem *utmi_base_addr, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 271 | void __iomem *usb_cfg_addr, |
| 272 | void __iomem *utmi_cfg_addr, |
| 273 | u32 utmi_phy_port) |
| 274 | { |
| 275 | u32 mask, data; |
| 276 | |
| 277 | debug_exit(); |
| 278 | debug("stage: Configure UTMI PHY %d registers\n", utmi_index); |
| 279 | /* Reference Clock Divider Select */ |
| 280 | mask = UTMI_PLL_CTRL_REFDIV_MASK; |
| 281 | data = 0x5 << UTMI_PLL_CTRL_REFDIV_OFFSET; |
| 282 | /* Feedback Clock Divider Select - 90 for 25Mhz*/ |
| 283 | mask |= UTMI_PLL_CTRL_FBDIV_MASK; |
| 284 | data |= 0x60 << UTMI_PLL_CTRL_FBDIV_OFFSET; |
| 285 | /* Select LPFR - 0x0 for 25Mhz/5=5Mhz*/ |
| 286 | mask |= UTMI_PLL_CTRL_SEL_LPFR_MASK; |
| 287 | data |= 0x0 << UTMI_PLL_CTRL_SEL_LPFR_OFFSET; |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 288 | reg_set(utmi_pll_addr + UTMI_PLL_CTRL_REG, data, mask); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 289 | |
| 290 | /* Impedance Calibration Threshold Setting */ |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 291 | reg_set(utmi_pll_addr + UTMI_CALIB_CTRL_REG, |
Igal Liberman | 32af216 | 2017-04-30 20:16:55 +0300 | [diff] [blame] | 292 | 0x7 << UTMI_CALIB_CTRL_IMPCAL_VTH_OFFSET, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 293 | UTMI_CALIB_CTRL_IMPCAL_VTH_MASK); |
| 294 | |
| 295 | /* Set LS TX driver strength coarse control */ |
Igal Liberman | 32af216 | 2017-04-30 20:16:55 +0300 | [diff] [blame] | 296 | mask = UTMI_TX_CH_CTRL_AMP_MASK; |
| 297 | data = 0x4 << UTMI_TX_CH_CTRL_AMP_OFFSET; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 298 | reg_set(utmi_base_addr + UTMI_TX_CH_CTRL_REG, data, mask); |
| 299 | |
| 300 | /* Enable SQ */ |
| 301 | mask = UTMI_RX_CH_CTRL0_SQ_DET_MASK; |
| 302 | data = 0x0 << UTMI_RX_CH_CTRL0_SQ_DET_OFFSET; |
| 303 | /* Enable analog squelch detect */ |
| 304 | mask |= UTMI_RX_CH_CTRL0_SQ_ANA_DTC_MASK; |
| 305 | data |= 0x1 << UTMI_RX_CH_CTRL0_SQ_ANA_DTC_OFFSET; |
| 306 | reg_set(utmi_base_addr + UTMI_RX_CH_CTRL0_REG, data, mask); |
| 307 | |
| 308 | /* Set External squelch calibration number */ |
| 309 | mask = UTMI_RX_CH_CTRL1_SQ_AMP_CAL_MASK; |
| 310 | data = 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_OFFSET; |
| 311 | /* Enable the External squelch calibration */ |
| 312 | mask |= UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_MASK; |
| 313 | data |= 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_OFFSET; |
| 314 | reg_set(utmi_base_addr + UTMI_RX_CH_CTRL1_REG, data, mask); |
| 315 | |
| 316 | /* Set Control VDAT Reference Voltage - 0.325V */ |
| 317 | mask = UTMI_CHGDTC_CTRL_VDAT_MASK; |
| 318 | data = 0x1 << UTMI_CHGDTC_CTRL_VDAT_OFFSET; |
| 319 | /* Set Control VSRC Reference Voltage - 0.6V */ |
| 320 | mask |= UTMI_CHGDTC_CTRL_VSRC_MASK; |
| 321 | data |= 0x1 << UTMI_CHGDTC_CTRL_VSRC_OFFSET; |
| 322 | reg_set(utmi_base_addr + UTMI_CHGDTC_CTRL_REG, data, mask); |
| 323 | |
| 324 | debug_exit(); |
| 325 | return; |
| 326 | } |
| 327 | |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 328 | static int comphy_utmi_power_up(u32 utmi_index, void __iomem *utmi_pll_addr, |
| 329 | void __iomem *utmi_base_addr, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 330 | void __iomem *usb_cfg_addr, |
| 331 | void __iomem *utmi_cfg_addr, u32 utmi_phy_port) |
| 332 | { |
| 333 | u32 data, mask, ret = 1; |
| 334 | void __iomem *addr; |
| 335 | |
| 336 | debug_enter(); |
| 337 | debug("stage: UTMI %d - Power up transceiver(Power up Phy), and exit SuspendDM\n", |
| 338 | utmi_index); |
| 339 | /* Power UP UTMI PHY */ |
| 340 | reg_set(utmi_cfg_addr, 0x1 << UTMI_PHY_CFG_PU_OFFSET, |
| 341 | UTMI_PHY_CFG_PU_MASK); |
| 342 | /* Disable Test UTMI select */ |
| 343 | reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, |
| 344 | 0x0 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET, |
| 345 | UTMI_CTRL_STATUS0_TEST_SEL_MASK); |
| 346 | |
| 347 | debug("stage: Polling for PLL and impedance calibration done, and PLL ready done\n"); |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 348 | addr = utmi_pll_addr + UTMI_CALIB_CTRL_REG; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 349 | data = UTMI_CALIB_CTRL_IMPCAL_DONE_MASK; |
| 350 | mask = data; |
| 351 | data = polling_with_timeout(addr, data, mask, 100); |
| 352 | if (data != 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 353 | pr_err("Impedance calibration is not done\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 354 | debug("Read from reg = %p - value = 0x%x\n", addr, data); |
| 355 | ret = 0; |
| 356 | } |
| 357 | |
| 358 | data = UTMI_CALIB_CTRL_PLLCAL_DONE_MASK; |
| 359 | mask = data; |
| 360 | data = polling_with_timeout(addr, data, mask, 100); |
| 361 | if (data != 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 362 | pr_err("PLL calibration is not done\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 363 | debug("Read from reg = %p - value = 0x%x\n", addr, data); |
| 364 | ret = 0; |
| 365 | } |
| 366 | |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 367 | addr = utmi_pll_addr + UTMI_PLL_CTRL_REG; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 368 | data = UTMI_PLL_CTRL_PLL_RDY_MASK; |
| 369 | mask = data; |
| 370 | data = polling_with_timeout(addr, data, mask, 100); |
| 371 | if (data != 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 372 | pr_err("PLL is not ready\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 373 | debug("Read from reg = %p - value = 0x%x\n", addr, data); |
| 374 | ret = 0; |
| 375 | } |
| 376 | |
| 377 | if (ret) |
| 378 | debug("Passed\n"); |
| 379 | else |
| 380 | debug("\n"); |
| 381 | |
| 382 | debug_exit(); |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * comphy_utmi_phy_init initialize the UTMI PHY |
| 388 | * the init split in 3 parts: |
| 389 | * 1. Power down transceiver and PLL |
| 390 | * 2. UTMI PHY configure |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 391 | * 3. Power up transceiver and PLL |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 392 | * Note: - Power down/up should be once for both UTMI PHYs |
| 393 | * - comphy_dedicated_phys_init call this function if at least there is |
| 394 | * one UTMI PHY exists in FDT blob. access to cp110_utmi_data[0] is |
| 395 | * legal |
| 396 | */ |
| 397 | static void comphy_utmi_phy_init(u32 utmi_phy_count, |
| 398 | struct utmi_phy_data *cp110_utmi_data) |
| 399 | { |
| 400 | u32 i; |
| 401 | |
| 402 | debug_enter(); |
| 403 | /* UTMI Power down */ |
| 404 | for (i = 0; i < utmi_phy_count; i++) { |
| 405 | comphy_utmi_power_down(i, cp110_utmi_data[i].utmi_base_addr, |
| 406 | cp110_utmi_data[i].usb_cfg_addr, |
| 407 | cp110_utmi_data[i].utmi_cfg_addr, |
| 408 | cp110_utmi_data[i].utmi_phy_port); |
| 409 | } |
| 410 | /* PLL Power down */ |
| 411 | debug("stage: UTMI PHY power down PLL\n"); |
| 412 | for (i = 0; i < utmi_phy_count; i++) { |
| 413 | reg_set(cp110_utmi_data[i].usb_cfg_addr, |
| 414 | 0x0 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK); |
| 415 | } |
| 416 | /* UTMI configure */ |
| 417 | for (i = 0; i < utmi_phy_count; i++) { |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 418 | comphy_utmi_phy_config(i, cp110_utmi_data[i].utmi_pll_addr, |
| 419 | cp110_utmi_data[i].utmi_base_addr, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 420 | cp110_utmi_data[i].usb_cfg_addr, |
| 421 | cp110_utmi_data[i].utmi_cfg_addr, |
| 422 | cp110_utmi_data[i].utmi_phy_port); |
| 423 | } |
| 424 | /* UTMI Power up */ |
| 425 | for (i = 0; i < utmi_phy_count; i++) { |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 426 | if (!comphy_utmi_power_up(i, cp110_utmi_data[i].utmi_pll_addr, |
| 427 | cp110_utmi_data[i].utmi_base_addr, |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 428 | cp110_utmi_data[i].usb_cfg_addr, |
| 429 | cp110_utmi_data[i].utmi_cfg_addr, |
| 430 | cp110_utmi_data[i].utmi_phy_port)) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 431 | pr_err("Failed to initialize UTMI PHY %d\n", i); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 432 | continue; |
| 433 | } |
| 434 | printf("UTMI PHY %d initialized to ", i); |
Stefan Roese | b781f57 | 2017-04-24 18:45:23 +0300 | [diff] [blame] | 435 | if (cp110_utmi_data[i].utmi_phy_port == |
| 436 | UTMI_PHY_TO_USB3_DEVICE0) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 437 | printf("USB Device\n"); |
| 438 | else |
| 439 | printf("USB Host%d\n", |
| 440 | cp110_utmi_data[i].utmi_phy_port); |
| 441 | } |
| 442 | /* PLL Power up */ |
| 443 | debug("stage: UTMI PHY power up PLL\n"); |
| 444 | for (i = 0; i < utmi_phy_count; i++) { |
| 445 | reg_set(cp110_utmi_data[i].usb_cfg_addr, |
| 446 | 0x1 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK); |
| 447 | } |
| 448 | |
| 449 | debug_exit(); |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * comphy_dedicated_phys_init initialize the dedicated PHYs |
| 455 | * - not muxed SerDes lanes e.g. UTMI PHY |
| 456 | */ |
| 457 | void comphy_dedicated_phys_init(void) |
| 458 | { |
| 459 | struct utmi_phy_data cp110_utmi_data[MAX_UTMI_PHY_COUNT]; |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 460 | int node = -1; |
| 461 | int node_idx; |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 462 | int parent = -1; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 463 | |
| 464 | debug_enter(); |
| 465 | debug("Initialize USB UTMI PHYs\n"); |
| 466 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 467 | for (node_idx = 0; node_idx < MAX_UTMI_PHY_COUNT;) { |
| 468 | /* Find the UTMI phy node in device tree */ |
| 469 | node = fdt_node_offset_by_compatible(gd->fdt_blob, node, |
| 470 | "marvell,mvebu-utmi-2.6.0"); |
| 471 | if (node <= 0) |
| 472 | break; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 473 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 474 | /* check if node is enabled */ |
| 475 | if (!fdtdec_get_is_enabled(gd->fdt_blob, node)) |
| 476 | continue; |
| 477 | |
Grzegorz Jaszczyk | 85bb206 | 2019-02-27 15:35:58 +0100 | [diff] [blame] | 478 | parent = fdt_parent_offset(gd->fdt_blob, node); |
| 479 | if (parent <= 0) |
| 480 | break; |
| 481 | |
| 482 | /* get base address of UTMI PLL */ |
| 483 | cp110_utmi_data[node_idx].utmi_pll_addr = |
| 484 | (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 485 | gd->fdt_blob, parent, "reg", 0, NULL, true); |
| 486 | if (!cp110_utmi_data[node_idx].utmi_pll_addr) { |
| 487 | pr_err("UTMI PHY PLL address is invalid\n"); |
| 488 | continue; |
| 489 | } |
| 490 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 491 | /* get base address of UTMI phy */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 492 | cp110_utmi_data[node_idx].utmi_base_addr = |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 493 | (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 494 | gd->fdt_blob, node, "reg", 0, NULL, true); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 495 | if (!cp110_utmi_data[node_idx].utmi_base_addr) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 496 | pr_err("UTMI PHY base address is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 497 | continue; |
| 498 | } |
| 499 | |
| 500 | /* get usb config address */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 501 | cp110_utmi_data[node_idx].usb_cfg_addr = |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 502 | (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 503 | gd->fdt_blob, node, "reg", 1, NULL, true); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 504 | if (!cp110_utmi_data[node_idx].usb_cfg_addr) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 505 | pr_err("UTMI PHY base address is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 506 | continue; |
| 507 | } |
| 508 | |
| 509 | /* get UTMI config address */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 510 | cp110_utmi_data[node_idx].utmi_cfg_addr = |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 511 | (void __iomem *)fdtdec_get_addr_size_auto_noparent( |
| 512 | gd->fdt_blob, node, "reg", 2, NULL, true); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 513 | if (!cp110_utmi_data[node_idx].utmi_cfg_addr) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 514 | pr_err("UTMI PHY base address is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 515 | continue; |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * get the port number (to check if the utmi connected to |
| 520 | * host/device) |
| 521 | */ |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 522 | cp110_utmi_data[node_idx].utmi_phy_port = fdtdec_get_int( |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 523 | gd->fdt_blob, node, "utmi-port", UTMI_PHY_INVALID); |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 524 | if (cp110_utmi_data[node_idx].utmi_phy_port == |
| 525 | UTMI_PHY_INVALID) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 526 | pr_err("UTMI PHY port type is invalid\n"); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 527 | continue; |
| 528 | } |
| 529 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 530 | /* count valid UTMI unit */ |
| 531 | node_idx++; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Omri Itach | 561930c | 2017-04-06 12:54:16 +0300 | [diff] [blame] | 534 | if (node_idx > 0) |
| 535 | comphy_utmi_phy_init(node_idx, cp110_utmi_data); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 536 | |
| 537 | debug_exit(); |
| 538 | } |
| 539 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 540 | int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, |
| 541 | struct comphy_map *serdes_map) |
| 542 | { |
| 543 | struct comphy_map *ptr_comphy_map; |
| 544 | void __iomem *comphy_base_addr, *hpipe_base_addr; |
Igal Liberman | d009fee | 2018-05-09 18:50:29 +0300 | [diff] [blame] | 545 | u32 comphy_max_count, lane, id, ret = 0; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 546 | u32 pcie_width = 0; |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 547 | u32 mode; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 548 | |
| 549 | debug_enter(); |
| 550 | |
| 551 | comphy_max_count = ptr_chip_cfg->comphy_lanes_count; |
| 552 | comphy_base_addr = ptr_chip_cfg->comphy_base_addr; |
| 553 | hpipe_base_addr = ptr_chip_cfg->hpipe3_base_addr; |
| 554 | |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 555 | /* Check if the first 4 lanes configured as By-4 */ |
| 556 | for (lane = 0, ptr_comphy_map = serdes_map; lane < 4; |
| 557 | lane++, ptr_comphy_map++) { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 558 | if (ptr_comphy_map->type != COMPHY_TYPE_PEX0) |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 559 | break; |
| 560 | pcie_width++; |
| 561 | } |
| 562 | |
| 563 | for (lane = 0, ptr_comphy_map = serdes_map; lane < comphy_max_count; |
| 564 | lane++, ptr_comphy_map++) { |
| 565 | debug("Initialize serdes number %d\n", lane); |
| 566 | debug("Serdes type = 0x%x\n", ptr_comphy_map->type); |
| 567 | if (lane == 4) { |
| 568 | /* |
| 569 | * PCIe lanes above the first 4 lanes, can be only |
| 570 | * by1 |
| 571 | */ |
| 572 | pcie_width = 1; |
| 573 | } |
| 574 | switch (ptr_comphy_map->type) { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 575 | case COMPHY_TYPE_UNCONNECTED: |
Igal Liberman | d622f8e | 2018-11-19 09:58:32 +0200 | [diff] [blame] | 576 | mode = COMPHY_TYPE_UNCONNECTED | COMPHY_CALLER_UBOOT; |
Christine Gharzuzi | c63fa15 | 2018-05-23 12:10:36 +0300 | [diff] [blame] | 577 | ret = comphy_smc(MV_SIP_COMPHY_POWER_OFF, |
| 578 | ptr_chip_cfg->comphy_base_addr, |
Igal Liberman | d622f8e | 2018-11-19 09:58:32 +0200 | [diff] [blame] | 579 | lane, mode); |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 580 | case COMPHY_TYPE_IGNORE: |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 581 | continue; |
| 582 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 583 | case COMPHY_TYPE_PEX0: |
| 584 | case COMPHY_TYPE_PEX1: |
| 585 | case COMPHY_TYPE_PEX2: |
| 586 | case COMPHY_TYPE_PEX3: |
Grzegorz Jaszczyk | c42b5a3 | 2020-10-18 17:11:12 +0300 | [diff] [blame] | 587 | mode = COMPHY_FW_PCIE_FORMAT(pcie_width, |
| 588 | ptr_comphy_map->clk_src, |
| 589 | COMPHY_PCIE_MODE, |
| 590 | ptr_comphy_map->speed); |
| 591 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 592 | ptr_chip_cfg->comphy_base_addr, lane, |
| 593 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 594 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 595 | case COMPHY_TYPE_SATA0: |
| 596 | case COMPHY_TYPE_SATA1: |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 597 | mode = COMPHY_FW_MODE_FORMAT(COMPHY_SATA_MODE); |
| 598 | ret = comphy_sata_power_up(lane, hpipe_base_addr, |
| 599 | comphy_base_addr, |
| 600 | ptr_chip_cfg->cp_index, |
| 601 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 602 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 603 | case COMPHY_TYPE_USB3_HOST0: |
| 604 | case COMPHY_TYPE_USB3_HOST1: |
Grzegorz Jaszczyk | e165970 | 2018-03-29 12:30:20 +0200 | [diff] [blame] | 605 | mode = COMPHY_FW_MODE_FORMAT(COMPHY_USB3H_MODE); |
| 606 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 607 | ptr_chip_cfg->comphy_base_addr, lane, |
| 608 | mode); |
| 609 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 610 | case COMPHY_TYPE_USB3_DEVICE: |
Grzegorz Jaszczyk | e165970 | 2018-03-29 12:30:20 +0200 | [diff] [blame] | 611 | mode = COMPHY_FW_MODE_FORMAT(COMPHY_USB3D_MODE); |
| 612 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 613 | ptr_chip_cfg->comphy_base_addr, lane, |
| 614 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 615 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 616 | case COMPHY_TYPE_SGMII0: |
| 617 | case COMPHY_TYPE_SGMII1: |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 618 | case COMPHY_TYPE_SGMII2: |
Igal Liberman | d009fee | 2018-05-09 18:50:29 +0300 | [diff] [blame] | 619 | /* Calculate SGMII ID */ |
| 620 | id = ptr_comphy_map->type - COMPHY_TYPE_SGMII0; |
| 621 | |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 622 | if (ptr_comphy_map->speed == COMPHY_SPEED_INVALID) { |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 623 | debug("Warning: SGMII PHY speed in lane %d is invalid, set PHY speed to 1.25G\n", |
| 624 | lane); |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 625 | ptr_comphy_map->speed = COMPHY_SPEED_1_25G; |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 626 | } |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 627 | |
Igal Liberman | d009fee | 2018-05-09 18:50:29 +0300 | [diff] [blame] | 628 | mode = COMPHY_FW_FORMAT(COMPHY_SGMII_MODE, id, |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 629 | ptr_comphy_map->speed); |
| 630 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 631 | ptr_chip_cfg->comphy_base_addr, lane, |
| 632 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 633 | break; |
Igal Liberman | d7297e3 | 2018-05-14 11:20:54 +0300 | [diff] [blame^] | 634 | case COMPHY_TYPE_SFI0: |
| 635 | case COMPHY_TYPE_SFI1: |
| 636 | /* Calculate SFI id */ |
| 637 | id = ptr_comphy_map->type - COMPHY_TYPE_SFI0; |
| 638 | mode = COMPHY_FW_FORMAT(COMPHY_SFI_MODE, id, |
Grzegorz Jaszczyk | 7928a8e | 2020-10-18 17:11:11 +0300 | [diff] [blame] | 639 | ptr_comphy_map->speed); |
| 640 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
Igal Liberman | d7297e3 | 2018-05-14 11:20:54 +0300 | [diff] [blame^] | 641 | ptr_chip_cfg->comphy_base_addr, lane, mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 642 | break; |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 643 | case COMPHY_TYPE_RXAUI0: |
| 644 | case COMPHY_TYPE_RXAUI1: |
Grzegorz Jaszczyk | beb4a91 | 2018-03-27 12:52:24 +0200 | [diff] [blame] | 645 | mode = COMPHY_FW_MODE_FORMAT(COMPHY_RXAUI_MODE); |
| 646 | ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, |
| 647 | ptr_chip_cfg->comphy_base_addr, lane, |
| 648 | mode); |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 649 | break; |
| 650 | default: |
| 651 | debug("Unknown SerDes type, skip initialize SerDes %d\n", |
| 652 | lane); |
| 653 | break; |
| 654 | } |
| 655 | if (ret == 0) { |
| 656 | /* |
Stefan Roese | 4fbca01 | 2017-04-24 18:45:25 +0300 | [diff] [blame] | 657 | * If interface wans't initialized, set the lane to |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 658 | * COMPHY_TYPE_UNCONNECTED state. |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 659 | */ |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 660 | ptr_comphy_map->type = COMPHY_TYPE_UNCONNECTED; |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 661 | pr_err("PLL is not locked - Failed to initialize lane %d\n", |
Stefan Roese | 648391c | 2016-08-30 16:48:20 +0200 | [diff] [blame] | 662 | lane); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | debug_exit(); |
| 667 | return 0; |
| 668 | } |