Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015-2016 Marvell International Ltd. |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +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> |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/cpu.h> |
| 11 | #include <asm/arch/soc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 12 | #include <linux/delay.h> |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 13 | |
| 14 | #include "comphy_a3700.h" |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Marek Behún | 817c2ce | 2018-04-24 17:21:23 +0200 | [diff] [blame] | 18 | struct comphy_mux_data a3700_comphy_mux_data[] = { |
| 19 | /* Lane 0 */ |
| 20 | { |
| 21 | 4, |
| 22 | { |
| 23 | { PHY_TYPE_UNCONNECTED, 0x0 }, |
| 24 | { PHY_TYPE_SGMII1, 0x0 }, |
| 25 | { PHY_TYPE_USB3_HOST0, 0x1 }, |
| 26 | { PHY_TYPE_USB3_DEVICE, 0x1 } |
| 27 | } |
| 28 | }, |
| 29 | /* Lane 1 */ |
| 30 | { |
| 31 | 3, |
| 32 | { |
| 33 | { PHY_TYPE_UNCONNECTED, 0x0}, |
| 34 | { PHY_TYPE_SGMII0, 0x0}, |
| 35 | { PHY_TYPE_PEX0, 0x1} |
| 36 | } |
| 37 | }, |
| 38 | /* Lane 2 */ |
| 39 | { |
| 40 | 4, |
| 41 | { |
| 42 | { PHY_TYPE_UNCONNECTED, 0x0}, |
| 43 | { PHY_TYPE_SATA0, 0x0}, |
| 44 | { PHY_TYPE_USB3_HOST0, 0x1}, |
| 45 | { PHY_TYPE_USB3_DEVICE, 0x1} |
| 46 | } |
| 47 | }, |
| 48 | }; |
| 49 | |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 50 | struct sgmii_phy_init_data_fix { |
| 51 | u16 addr; |
| 52 | u16 value; |
| 53 | }; |
| 54 | |
| 55 | /* Changes to 40M1G25 mode data required for running 40M3G125 init mode */ |
| 56 | static struct sgmii_phy_init_data_fix sgmii_phy_init_fix[] = { |
| 57 | {0x005, 0x07CC}, {0x015, 0x0000}, {0x01B, 0x0000}, {0x01D, 0x0000}, |
| 58 | {0x01E, 0x0000}, {0x01F, 0x0000}, {0x020, 0x0000}, {0x021, 0x0030}, |
| 59 | {0x026, 0x0888}, {0x04D, 0x0152}, {0x04F, 0xA020}, {0x050, 0x07CC}, |
| 60 | {0x053, 0xE9CA}, {0x055, 0xBD97}, {0x071, 0x3015}, {0x076, 0x03AA}, |
| 61 | {0x07C, 0x0FDF}, {0x0C2, 0x3030}, {0x0C3, 0x8000}, {0x0E2, 0x5550}, |
| 62 | {0x0E3, 0x12A4}, {0x0E4, 0x7D00}, {0x0E6, 0x0C83}, {0x101, 0xFCC0}, |
| 63 | {0x104, 0x0C10} |
| 64 | }; |
| 65 | |
| 66 | /* 40M1G25 mode init data */ |
| 67 | static u16 sgmii_phy_init[512] = { |
| 68 | /* 0 1 2 3 4 5 6 7 */ |
| 69 | /*-----------------------------------------------------------*/ |
| 70 | /* 8 9 A B C D E F */ |
| 71 | 0x3110, 0xFD83, 0x6430, 0x412F, 0x82C0, 0x06FA, 0x4500, 0x6D26, /* 00 */ |
| 72 | 0xAFC0, 0x8000, 0xC000, 0x0000, 0x2000, 0x49CC, 0x0BC9, 0x2A52, /* 08 */ |
| 73 | 0x0BD2, 0x0CDE, 0x13D2, 0x0CE8, 0x1149, 0x10E0, 0x0000, 0x0000, /* 10 */ |
| 74 | 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x4134, 0x0D2D, 0xFFFF, /* 18 */ |
| 75 | 0xFFE0, 0x4030, 0x1016, 0x0030, 0x0000, 0x0800, 0x0866, 0x0000, /* 20 */ |
| 76 | 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, /* 28 */ |
| 77 | 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 30 */ |
| 78 | 0x0000, 0x0000, 0x000F, 0x6A62, 0x1988, 0x3100, 0x3100, 0x3100, /* 38 */ |
| 79 | 0x3100, 0xA708, 0x2430, 0x0830, 0x1030, 0x4610, 0xFF00, 0xFF00, /* 40 */ |
| 80 | 0x0060, 0x1000, 0x0400, 0x0040, 0x00F0, 0x0155, 0x1100, 0xA02A, /* 48 */ |
| 81 | 0x06FA, 0x0080, 0xB008, 0xE3ED, 0x5002, 0xB592, 0x7A80, 0x0001, /* 50 */ |
| 82 | 0x020A, 0x8820, 0x6014, 0x8054, 0xACAA, 0xFC88, 0x2A02, 0x45CF, /* 58 */ |
| 83 | 0x000F, 0x1817, 0x2860, 0x064F, 0x0000, 0x0204, 0x1800, 0x6000, /* 60 */ |
| 84 | 0x810F, 0x4F23, 0x4000, 0x4498, 0x0850, 0x0000, 0x000E, 0x1002, /* 68 */ |
| 85 | 0x9D3A, 0x3009, 0xD066, 0x0491, 0x0001, 0x6AB0, 0x0399, 0x3780, /* 70 */ |
| 86 | 0x0040, 0x5AC0, 0x4A80, 0x0000, 0x01DF, 0x0000, 0x0007, 0x0000, /* 78 */ |
| 87 | 0x2D54, 0x00A1, 0x4000, 0x0100, 0xA20A, 0x0000, 0x0000, 0x0000, /* 80 */ |
| 88 | 0x0000, 0x0000, 0x0000, 0x7400, 0x0E81, 0x1000, 0x1242, 0x0210, /* 88 */ |
| 89 | 0x80DF, 0x0F1F, 0x2F3F, 0x4F5F, 0x6F7F, 0x0F1F, 0x2F3F, 0x4F5F, /* 90 */ |
| 90 | 0x6F7F, 0x4BAD, 0x0000, 0x0000, 0x0800, 0x0000, 0x2400, 0xB651, /* 98 */ |
| 91 | 0xC9E0, 0x4247, 0x0A24, 0x0000, 0xAF19, 0x1004, 0x0000, 0x0000, /* A0 */ |
| 92 | 0x0000, 0x0013, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* A8 */ |
| 93 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* B0 */ |
| 94 | 0x0000, 0x0000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0000, 0x0000, /* B8 */ |
| 95 | 0x0000, 0x0000, 0x3010, 0xFA00, 0x0000, 0x0000, 0x0000, 0x0003, /* C0 */ |
| 96 | 0x1618, 0x8200, 0x8000, 0x0400, 0x050F, 0x0000, 0x0000, 0x0000, /* C8 */ |
| 97 | 0x4C93, 0x0000, 0x1000, 0x1120, 0x0010, 0x1242, 0x1242, 0x1E00, /* D0 */ |
| 98 | 0x0000, 0x0000, 0x0000, 0x00F8, 0x0000, 0x0041, 0x0800, 0x0000, /* D8 */ |
| 99 | 0x82A0, 0x572E, 0x2490, 0x14A9, 0x4E00, 0x0000, 0x0803, 0x0541, /* E0 */ |
| 100 | 0x0C15, 0x0000, 0x0000, 0x0400, 0x2626, 0x0000, 0x0000, 0x4200, /* E8 */ |
| 101 | 0x0000, 0xAA55, 0x1020, 0x0000, 0x0000, 0x5010, 0x0000, 0x0000, /* F0 */ |
| 102 | 0x0000, 0x0000, 0x5000, 0x0000, 0x0000, 0x0000, 0x02F2, 0x0000, /* F8 */ |
| 103 | 0x101F, 0xFDC0, 0x4000, 0x8010, 0x0110, 0x0006, 0x0000, 0x0000, /*100 */ |
| 104 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*108 */ |
| 105 | 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04C6, 0x0000, /*110 */ |
| 106 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*118 */ |
| 107 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*120 */ |
| 108 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*128 */ |
| 109 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*130 */ |
| 110 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*138 */ |
| 111 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*140 */ |
| 112 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*148 */ |
| 113 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*150 */ |
| 114 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*158 */ |
| 115 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*160 */ |
| 116 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*168 */ |
| 117 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*170 */ |
| 118 | 0x0000, 0x0000, 0x0000, 0x00F0, 0x08A2, 0x3112, 0x0A14, 0x0000, /*178 */ |
| 119 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*180 */ |
| 120 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*188 */ |
| 121 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*190 */ |
| 122 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*198 */ |
| 123 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A0 */ |
| 124 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A8 */ |
| 125 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B0 */ |
| 126 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B8 */ |
| 127 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C0 */ |
| 128 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C8 */ |
| 129 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D0 */ |
| 130 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D8 */ |
| 131 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E0 */ |
| 132 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E8 */ |
| 133 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1F0 */ |
| 134 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 /*1F8 */ |
| 135 | }; |
| 136 | |
| 137 | /* |
| 138 | * comphy_poll_reg |
| 139 | * |
| 140 | * return: 1 on success, 0 on timeout |
| 141 | */ |
Marek Behún | 69fb636 | 2018-04-24 17:21:15 +0200 | [diff] [blame] | 142 | static u32 comphy_poll_reg(void *addr, u32 val, u32 mask, u8 op_type) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 143 | { |
Marek Behún | 69fb636 | 2018-04-24 17:21:15 +0200 | [diff] [blame] | 144 | u32 rval = 0xDEAD, timeout; |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 145 | |
Marek Behún | 69fb636 | 2018-04-24 17:21:15 +0200 | [diff] [blame] | 146 | for (timeout = PLL_LOCK_TIMEOUT; timeout > 0; timeout--) { |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 147 | if (op_type == POLL_16B_REG) |
| 148 | rval = readw(addr); /* 16 bit */ |
| 149 | else |
| 150 | rval = readl(addr) ; /* 32 bit */ |
| 151 | |
| 152 | if ((rval & mask) == val) |
| 153 | return 1; |
| 154 | |
| 155 | udelay(10000); |
| 156 | } |
| 157 | |
| 158 | debug("Time out waiting (%p = %#010x)\n", addr, rval); |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * comphy_pcie_power_up |
| 164 | * |
| 165 | * return: 1 if PLL locked (OK), 0 otherwise (FAIL) |
| 166 | */ |
| 167 | static int comphy_pcie_power_up(u32 speed, u32 invert) |
| 168 | { |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 169 | int ret; |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 170 | |
| 171 | debug_enter(); |
| 172 | |
| 173 | /* |
| 174 | * 1. Enable max PLL. |
| 175 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 176 | reg_set16(phy_addr(PCIE, LANE_CFG1), bf_use_max_pll_rate, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * 2. Select 20 bit SERDES interface. |
| 180 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 181 | reg_set16(phy_addr(PCIE, GLOB_CLK_SRC_LO), bf_cfg_sel_20b, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 182 | |
| 183 | /* |
| 184 | * 3. Force to use reg setting for PCIe mode |
| 185 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 186 | reg_set16(phy_addr(PCIE, MISC_REG1), bf_sel_bits_pcie_force, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * 4. Change RX wait |
| 190 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 191 | reg_set16(phy_addr(PCIE, PWR_MGM_TIM1), 0x10C, 0xFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * 5. Enable idle sync |
| 195 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 196 | reg_set16(phy_addr(PCIE, UNIT_CTRL), 0x60 | rb_idle_sync_en, 0xFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * 6. Enable the output of 100M/125M/500M clock |
| 200 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 201 | reg_set16(phy_addr(PCIE, MISC_REG0), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 202 | 0xA00D | rb_clk500m_en | rb_clk100m_125m_en, 0xFFFF); |
| 203 | |
| 204 | /* |
| 205 | * 7. Enable TX |
| 206 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 207 | reg_set(PCIE_REF_CLK_ADDR, 0x1342, 0xFFFFFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * 8. Check crystal jumper setting and program the Power and PLL |
| 211 | * Control accordingly |
| 212 | */ |
| 213 | if (get_ref_clk() == 40) { |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 214 | /* 40 MHz */ |
| 215 | reg_set16(phy_addr(PCIE, PWR_PLL_CTRL), 0xFC63, 0xFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 216 | } else { |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 217 | /* 25 MHz */ |
| 218 | reg_set16(phy_addr(PCIE, PWR_PLL_CTRL), 0xFC62, 0xFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* |
| 222 | * 9. Override Speed_PLL value and use MAC PLL |
| 223 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 224 | reg_set16(phy_addr(PCIE, KVCO_CAL_CTRL), 0x0040 | rb_use_max_pll_rate, |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 225 | 0xFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 226 | |
| 227 | /* |
| 228 | * 10. Check the Polarity invert bit |
| 229 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 230 | if (invert & PHY_POLARITY_TXD_INVERT) |
| 231 | reg_set16(phy_addr(PCIE, SYNC_PATTERN), phy_txd_inv, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 232 | |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 233 | if (invert & PHY_POLARITY_RXD_INVERT) |
| 234 | reg_set16(phy_addr(PCIE, SYNC_PATTERN), phy_rxd_inv, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * 11. Release SW reset |
| 238 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 239 | reg_set16(phy_addr(PCIE, GLOB_PHY_CTRL0), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 240 | rb_mode_core_clk_freq_sel | rb_mode_pipe_width_32, |
| 241 | bf_soft_rst | bf_mode_refdiv); |
| 242 | |
| 243 | /* Wait for > 55 us to allow PCLK be enabled */ |
| 244 | udelay(PLL_SET_DELAY_US); |
| 245 | |
| 246 | /* Assert PCLK enabled */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 247 | ret = comphy_poll_reg(phy_addr(PCIE, LANE_STAT1), /* address */ |
| 248 | rb_txdclk_pclk_en, /* value */ |
| 249 | rb_txdclk_pclk_en, /* mask */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 250 | POLL_16B_REG); /* 16bit */ |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 251 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 252 | printf("Failed to lock PCIe PLL\n"); |
| 253 | |
| 254 | debug_exit(); |
| 255 | |
| 256 | /* Return the status of the PLL */ |
| 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | /* |
Marek Behún | fbf651d | 2018-04-24 17:21:17 +0200 | [diff] [blame] | 261 | * reg_set_indirect |
| 262 | * |
| 263 | * return: void |
| 264 | */ |
| 265 | static void reg_set_indirect(u32 reg, u16 data, u16 mask) |
| 266 | { |
| 267 | reg_set(rh_vsreg_addr, reg, 0xFFFFFFFF); |
| 268 | reg_set(rh_vsreg_data, data, mask); |
| 269 | } |
| 270 | |
| 271 | /* |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 272 | * comphy_sata_power_up |
| 273 | * |
| 274 | * return: 1 if PLL locked (OK), 0 otherwise (FAIL) |
| 275 | */ |
zachary | ba42e84 | 2020-08-28 16:56:29 +0200 | [diff] [blame] | 276 | static int comphy_sata_power_up(u32 invert) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 277 | { |
Marek Behún | fbf651d | 2018-04-24 17:21:17 +0200 | [diff] [blame] | 278 | int ret; |
zachary | ba42e84 | 2020-08-28 16:56:29 +0200 | [diff] [blame] | 279 | u32 data = 0; |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 280 | |
| 281 | debug_enter(); |
| 282 | |
| 283 | /* |
zachary | ba42e84 | 2020-08-28 16:56:29 +0200 | [diff] [blame] | 284 | * 0. Check the Polarity invert bits |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 285 | */ |
zachary | ba42e84 | 2020-08-28 16:56:29 +0200 | [diff] [blame] | 286 | if (invert & PHY_POLARITY_TXD_INVERT) |
| 287 | data |= bs_txd_inv; |
| 288 | |
| 289 | if (invert & PHY_POLARITY_RXD_INVERT) |
| 290 | data |= bs_rxd_inv; |
| 291 | |
| 292 | reg_set_indirect(vphy_sync_pattern_reg, data, bs_txd_inv | bs_rxd_inv); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * 1. Select 40-bit data width width |
| 296 | */ |
Marek Behún | fbf651d | 2018-04-24 17:21:17 +0200 | [diff] [blame] | 297 | reg_set_indirect(vphy_loopback_reg0, 0x800, bs_phyintf_40bit); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 298 | |
| 299 | /* |
| 300 | * 2. Select reference clock and PHY mode (SATA) |
| 301 | */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 302 | if (get_ref_clk() == 40) { |
Marek Behún | fbf651d | 2018-04-24 17:21:17 +0200 | [diff] [blame] | 303 | /* 40 MHz */ |
| 304 | reg_set_indirect(vphy_power_reg0, 0x3, 0x00FF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 305 | } else { |
Marek Behún | fbf651d | 2018-04-24 17:21:17 +0200 | [diff] [blame] | 306 | /* 20 MHz */ |
| 307 | reg_set_indirect(vphy_power_reg0, 0x1, 0x00FF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* |
| 311 | * 3. Use maximum PLL rate (no power save) |
| 312 | */ |
Marek Behún | fbf651d | 2018-04-24 17:21:17 +0200 | [diff] [blame] | 313 | reg_set_indirect(vphy_calctl_reg, bs_max_pll_rate, bs_max_pll_rate); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * 4. Reset reserved bit (??) |
| 317 | */ |
Marek Behún | fbf651d | 2018-04-24 17:21:17 +0200 | [diff] [blame] | 318 | reg_set_indirect(vphy_reserve_reg, 0, bs_phyctrl_frm_pin); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 319 | |
| 320 | /* |
| 321 | * 5. Set vendor-specific configuration (??) |
| 322 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 323 | reg_set(rh_vs0_a, vsata_ctrl_reg, 0xFFFFFFFF); |
| 324 | reg_set(rh_vs0_d, bs_phy_pu_pll, bs_phy_pu_pll); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 325 | |
| 326 | /* Wait for > 55 us to allow PLL be enabled */ |
| 327 | udelay(PLL_SET_DELAY_US); |
| 328 | |
| 329 | /* Assert SATA PLL enabled */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 330 | reg_set(rh_vsreg_addr, vphy_loopback_reg0, 0xFFFFFFFF); |
| 331 | ret = comphy_poll_reg(rh_vsreg_data, /* address */ |
| 332 | bs_pll_ready_tx, /* value */ |
| 333 | bs_pll_ready_tx, /* mask */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 334 | POLL_32B_REG); /* 32bit */ |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 335 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 336 | printf("Failed to lock SATA PLL\n"); |
| 337 | |
| 338 | debug_exit(); |
| 339 | |
| 340 | return ret; |
| 341 | } |
| 342 | |
| 343 | /* |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 344 | * usb3_reg_set16 |
| 345 | * |
| 346 | * return: void |
| 347 | */ |
| 348 | static void usb3_reg_set16(u32 reg, u16 data, u16 mask, u32 lane) |
| 349 | { |
| 350 | /* |
| 351 | * When Lane 2 PHY is for USB3, access the PHY registers |
| 352 | * through indirect Address and Data registers INDIR_ACC_PHY_ADDR |
| 353 | * (RD00E0178h [31:0]) and INDIR_ACC_PHY_DATA (RD00E017Ch [31:0]) |
| 354 | * within the SATA Host Controller registers, Lane 2 base register |
| 355 | * offset is 0x200 |
| 356 | */ |
| 357 | |
| 358 | if (lane == 2) |
| 359 | reg_set_indirect(USB3PHY_LANE2_REG_BASE_OFFSET + reg, data, |
| 360 | mask); |
| 361 | else |
| 362 | reg_set16(phy_addr(USB3, reg), data, mask); |
| 363 | } |
| 364 | |
| 365 | /* |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 366 | * comphy_usb3_power_up |
| 367 | * |
| 368 | * return: 1 if PLL locked (OK), 0 otherwise (FAIL) |
| 369 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 370 | static int comphy_usb3_power_up(u32 lane, u32 type, u32 speed, u32 invert) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 371 | { |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 372 | int ret; |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 373 | |
| 374 | debug_enter(); |
| 375 | |
| 376 | /* |
| 377 | * 1. Power up OTG module |
| 378 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 379 | reg_set(USB2_PHY_OTG_CTRL_ADDR, rb_pu_otg, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 380 | |
| 381 | /* |
| 382 | * 2. Set counter for 100us pulse in USB3 Host and Device |
| 383 | * restore default burst size limit (Reference Clock 31:24) |
| 384 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 385 | reg_set(USB3_CTRPUL_VAL_REG, 0x8 << 24, rb_usb3_ctr_100ns); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 386 | |
| 387 | |
| 388 | /* 0xd005c300 = 0x1001 */ |
| 389 | /* set PRD_TXDEEMPH (3.5db de-emph) */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 390 | usb3_reg_set16(LANE_CFG0, 0x1, 0xFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 391 | |
| 392 | /* |
zachary | 2684a39 | 2018-04-24 17:21:20 +0200 | [diff] [blame] | 393 | * Set BIT0: enable transmitter in high impedance mode |
| 394 | * Set BIT[3:4]: delay 2 clock cycles for HiZ off latency |
| 395 | * Set BIT6: Tx detect Rx at HiZ mode |
| 396 | * Unset BIT15: set to 0 to set USB3 De-emphasize level to -3.5db |
| 397 | * together with bit 0 of COMPHY_REG_LANE_CFG0_ADDR |
| 398 | * register |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 399 | */ |
zachary | 2684a39 | 2018-04-24 17:21:20 +0200 | [diff] [blame] | 400 | usb3_reg_set16(LANE_CFG1, |
| 401 | tx_det_rx_mode | gen2_tx_data_dly_deft |
| 402 | | tx_elec_idle_mode_en, |
| 403 | prd_txdeemph1_mask | tx_det_rx_mode |
| 404 | | gen2_tx_data_dly_mask | tx_elec_idle_mode_en, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 405 | |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 406 | /* 0xd005c310 = 0x93: set Spread Spectrum Clock Enabled */ |
| 407 | usb3_reg_set16(LANE_CFG4, bf_spread_spectrum_clock_en, 0x80, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 408 | |
| 409 | /* |
| 410 | * set Override Margining Controls From the MAC: Use margining signals |
| 411 | * from lane configuration |
| 412 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 413 | usb3_reg_set16(TEST_MODE_CTRL, rb_mode_margin_override, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 414 | |
| 415 | /* set Lane-to-Lane Bundle Clock Sampling Period = per PCLK cycles */ |
| 416 | /* set Mode Clock Source = PCLK is generated from REFCLK */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 417 | usb3_reg_set16(GLOB_CLK_SRC_LO, 0x0, 0xFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 418 | |
| 419 | /* set G2 Spread Spectrum Clock Amplitude at 4K */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 420 | usb3_reg_set16(GEN2_SETTINGS_2, g2_tx_ssc_amp, 0xF000, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 421 | |
| 422 | /* |
| 423 | * unset G3 Spread Spectrum Clock Amplitude & set G3 TX and RX Register |
| 424 | * Master Current Select |
| 425 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 426 | usb3_reg_set16(GEN2_SETTINGS_3, 0x0, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * 3. Check crystal jumper setting and program the Power and PLL |
| 430 | * Control accordingly |
Marek Behún | b3b7e21 | 2018-04-24 17:21:19 +0200 | [diff] [blame] | 431 | * 4. Change RX wait |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 432 | */ |
| 433 | if (get_ref_clk() == 40) { |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 434 | /* 40 MHz */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 435 | usb3_reg_set16(PWR_PLL_CTRL, 0xFCA3, 0xFFFF, lane); |
Marek Behún | b3b7e21 | 2018-04-24 17:21:19 +0200 | [diff] [blame] | 436 | usb3_reg_set16(PWR_MGM_TIM1, 0x10C, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 437 | } else { |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 438 | /* 25 MHz */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 439 | usb3_reg_set16(PWR_PLL_CTRL, 0xFCA2, 0xFFFF, lane); |
Marek Behún | b3b7e21 | 2018-04-24 17:21:19 +0200 | [diff] [blame] | 440 | usb3_reg_set16(PWR_MGM_TIM1, 0x107, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /* |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 444 | * 5. Enable idle sync |
| 445 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 446 | usb3_reg_set16(UNIT_CTRL, 0x60 | rb_idle_sync_en, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 447 | |
| 448 | /* |
| 449 | * 6. Enable the output of 500M clock |
| 450 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 451 | usb3_reg_set16(MISC_REG0, 0xA00D | rb_clk500m_en, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 452 | |
| 453 | /* |
| 454 | * 7. Set 20-bit data width |
| 455 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 456 | usb3_reg_set16(DIG_LB_EN, 0x0400, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 457 | |
| 458 | /* |
| 459 | * 8. Override Speed_PLL value and use MAC PLL |
| 460 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 461 | usb3_reg_set16(KVCO_CAL_CTRL, 0x0040 | rb_use_max_pll_rate, 0xFFFF, |
| 462 | lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 463 | |
| 464 | /* |
| 465 | * 9. Check the Polarity invert bit |
| 466 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 467 | if (invert & PHY_POLARITY_TXD_INVERT) |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 468 | usb3_reg_set16(SYNC_PATTERN, phy_txd_inv, 0, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 469 | |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 470 | if (invert & PHY_POLARITY_RXD_INVERT) |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 471 | usb3_reg_set16(SYNC_PATTERN, phy_rxd_inv, 0, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 472 | |
| 473 | /* |
zachary | 2684a39 | 2018-04-24 17:21:20 +0200 | [diff] [blame] | 474 | * 10. Set max speed generation to USB3.0 5Gbps |
| 475 | */ |
| 476 | usb3_reg_set16(SYNC_MASK_GEN, 0x0400, 0x0C00, lane); |
| 477 | |
| 478 | /* |
| 479 | * 11. Set capacitor value for FFE gain peaking to 0xF |
| 480 | */ |
| 481 | usb3_reg_set16(GEN3_SETTINGS_3, 0xF, 0xF, lane); |
| 482 | |
| 483 | /* |
| 484 | * 12. Release SW reset |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 485 | */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 486 | usb3_reg_set16(GLOB_PHY_CTRL0, |
| 487 | rb_mode_core_clk_freq_sel | rb_mode_pipe_width_32 |
| 488 | | 0x20, 0xFFFF, lane); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 489 | |
| 490 | /* Wait for > 55 us to allow PCLK be enabled */ |
| 491 | udelay(PLL_SET_DELAY_US); |
| 492 | |
| 493 | /* Assert PCLK enabled */ |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 494 | if (lane == 2) { |
| 495 | reg_set(rh_vsreg_addr, |
| 496 | LANE_STAT1 + USB3PHY_LANE2_REG_BASE_OFFSET, |
| 497 | 0xFFFFFFFF); |
| 498 | ret = comphy_poll_reg(rh_vsreg_data, /* address */ |
| 499 | rb_txdclk_pclk_en, /* value */ |
| 500 | rb_txdclk_pclk_en, /* mask */ |
| 501 | POLL_32B_REG); /* 32bit */ |
| 502 | } else { |
| 503 | ret = comphy_poll_reg(phy_addr(USB3, LANE_STAT1), /* address */ |
| 504 | rb_txdclk_pclk_en, /* value */ |
| 505 | rb_txdclk_pclk_en, /* mask */ |
| 506 | POLL_16B_REG); /* 16bit */ |
| 507 | } |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 508 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 509 | printf("Failed to lock USB3 PLL\n"); |
| 510 | |
| 511 | /* |
| 512 | * Set Soft ID for Host mode (Device mode works with Hard ID |
| 513 | * detection) |
| 514 | */ |
| 515 | if (type == PHY_TYPE_USB3_HOST0) { |
| 516 | /* |
| 517 | * set BIT0: set ID_MODE of Host/Device = "Soft ID" (BIT1) |
| 518 | * clear BIT1: set SOFT_ID = Host |
| 519 | * set BIT4: set INT_MODE = ID. Interrupt Mode: enable |
| 520 | * interrupt by ID instead of using both interrupts |
| 521 | * of HOST and Device ORed simultaneously |
| 522 | * INT_MODE=ID in order to avoid unexpected |
| 523 | * behaviour or both interrupts together |
| 524 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 525 | reg_set(USB32_CTRL_BASE, |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 526 | usb32_ctrl_id_mode | usb32_ctrl_int_mode, |
| 527 | usb32_ctrl_id_mode | usb32_ctrl_soft_id | |
| 528 | usb32_ctrl_int_mode); |
| 529 | } |
| 530 | |
| 531 | debug_exit(); |
| 532 | |
| 533 | return ret; |
| 534 | } |
| 535 | |
| 536 | /* |
| 537 | * comphy_usb2_power_up |
| 538 | * |
| 539 | * return: 1 if PLL locked (OK), 0 otherwise (FAIL) |
| 540 | */ |
| 541 | static int comphy_usb2_power_up(u8 usb32) |
| 542 | { |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 543 | int ret; |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 544 | |
| 545 | debug_enter(); |
| 546 | |
| 547 | if (usb32 != 0 && usb32 != 1) { |
| 548 | printf("invalid usb32 value: (%d), should be either 0 or 1\n", |
| 549 | usb32); |
| 550 | debug_exit(); |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * 0. Setup PLL. 40MHz clock uses defaults. |
| 556 | * See "PLL Settings for Typical REFCLK" table |
| 557 | */ |
| 558 | if (get_ref_clk() == 25) { |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 559 | reg_set(USB2_PHY_BASE(usb32), 5 | (96 << 16), |
| 560 | 0x3F | (0xFF << 16) | (0x3 << 28)); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /* |
| 564 | * 1. PHY pull up and disable USB2 suspend |
| 565 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 566 | reg_set(USB2_PHY_CTRL_ADDR(usb32), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 567 | RB_USB2PHY_SUSPM(usb32) | RB_USB2PHY_PU(usb32), 0); |
| 568 | |
| 569 | if (usb32 != 0) { |
| 570 | /* |
| 571 | * 2. Power up OTG module |
| 572 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 573 | reg_set(USB2_PHY_OTG_CTRL_ADDR, rb_pu_otg, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 574 | |
| 575 | /* |
| 576 | * 3. Configure PHY charger detection |
| 577 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 578 | reg_set(USB2_PHY_CHRGR_DET_ADDR, 0, |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 579 | rb_cdp_en | rb_dcp_en | rb_pd_en | rb_cdp_dm_auto | |
| 580 | rb_enswitch_dp | rb_enswitch_dm | rb_pu_chrg_dtc); |
| 581 | } |
| 582 | |
| 583 | /* Assert PLL calibration done */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 584 | ret = comphy_poll_reg(USB2_PHY_CAL_CTRL_ADDR(usb32), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 585 | rb_usb2phy_pllcal_done, /* value */ |
| 586 | rb_usb2phy_pllcal_done, /* mask */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 587 | POLL_32B_REG); /* 32bit */ |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 588 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 589 | printf("Failed to end USB2 PLL calibration\n"); |
| 590 | |
| 591 | /* Assert impedance calibration done */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 592 | ret = comphy_poll_reg(USB2_PHY_CAL_CTRL_ADDR(usb32), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 593 | rb_usb2phy_impcal_done, /* value */ |
| 594 | rb_usb2phy_impcal_done, /* mask */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 595 | POLL_32B_REG); /* 32bit */ |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 596 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 597 | printf("Failed to end USB2 impedance calibration\n"); |
| 598 | |
| 599 | /* Assert squetch calibration done */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 600 | ret = comphy_poll_reg(USB2_PHY_RX_CHAN_CTRL1_ADDR(usb32), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 601 | rb_usb2phy_sqcal_done, /* value */ |
| 602 | rb_usb2phy_sqcal_done, /* mask */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 603 | POLL_32B_REG); /* 32bit */ |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 604 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 605 | printf("Failed to end USB2 unknown calibration\n"); |
| 606 | |
| 607 | /* Assert PLL is ready */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 608 | ret = comphy_poll_reg(USB2_PHY_PLL_CTRL0_ADDR(usb32), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 609 | rb_usb2phy_pll_ready, /* value */ |
| 610 | rb_usb2phy_pll_ready, /* mask */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 611 | POLL_32B_REG); /* 32bit */ |
| 612 | |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 613 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 614 | printf("Failed to lock USB2 PLL\n"); |
| 615 | |
| 616 | debug_exit(); |
| 617 | |
| 618 | return ret; |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * comphy_emmc_power_up |
| 623 | * |
| 624 | * return: 1 if PLL locked (OK), 0 otherwise (FAIL) |
| 625 | */ |
| 626 | static int comphy_emmc_power_up(void) |
| 627 | { |
| 628 | debug_enter(); |
| 629 | |
| 630 | /* |
| 631 | * 1. Bus power ON, Bus voltage 1.8V |
| 632 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 633 | reg_set(SDIO_HOST_CTRL1_ADDR, 0xB00, 0xF00); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 634 | |
| 635 | /* |
| 636 | * 2. Set FIFO parameters |
| 637 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 638 | reg_set(SDIO_SDHC_FIFO_ADDR, 0x315, 0xFFFFFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 639 | |
| 640 | /* |
| 641 | * 3. Set Capabilities 1_2 |
| 642 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 643 | reg_set(SDIO_CAP_12_ADDR, 0x25FAC8B2, 0xFFFFFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * 4. Set Endian |
| 647 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 648 | reg_set(SDIO_ENDIAN_ADDR, 0x00c00000, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 649 | |
| 650 | /* |
| 651 | * 4. Init PHY |
| 652 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 653 | reg_set(SDIO_PHY_TIMING_ADDR, 0x80000000, 0x80000000); |
| 654 | reg_set(SDIO_PHY_PAD_CTRL0_ADDR, 0x50000000, 0xF0000000); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 655 | |
| 656 | /* |
| 657 | * 5. DLL reset |
| 658 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 659 | reg_set(SDIO_DLL_RST_ADDR, 0xFFFEFFFF, 0); |
| 660 | reg_set(SDIO_DLL_RST_ADDR, 0x00010000, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 661 | |
| 662 | debug_exit(); |
| 663 | |
| 664 | return 1; |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | * comphy_sgmii_power_up |
| 669 | * |
| 670 | * return: |
| 671 | */ |
| 672 | static void comphy_sgmii_phy_init(u32 lane, u32 speed) |
| 673 | { |
| 674 | const int fix_arr_sz = ARRAY_SIZE(sgmii_phy_init_fix); |
| 675 | int addr, fix_idx; |
| 676 | u16 val; |
| 677 | |
| 678 | fix_idx = 0; |
| 679 | for (addr = 0; addr < 512; addr++) { |
| 680 | /* |
| 681 | * All PHY register values are defined in full for 3.125Gbps |
| 682 | * SERDES speed. The values required for 1.25 Gbps are almost |
| 683 | * the same and only few registers should be "fixed" in |
| 684 | * comparison to 3.125 Gbps values. These register values are |
| 685 | * stored in "sgmii_phy_init_fix" array. |
| 686 | */ |
| 687 | if ((speed != PHY_SPEED_1_25G) && |
| 688 | (sgmii_phy_init_fix[fix_idx].addr == addr)) { |
| 689 | /* Use new value */ |
| 690 | val = sgmii_phy_init_fix[fix_idx].value; |
| 691 | if (fix_idx < fix_arr_sz) |
| 692 | fix_idx++; |
| 693 | } else { |
| 694 | val = sgmii_phy_init[addr]; |
| 695 | } |
| 696 | |
Marek Behún | ee3e2f6 | 2018-04-24 17:21:13 +0200 | [diff] [blame] | 697 | reg_set16(sgmiiphy_addr(lane, addr), val, 0xFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
| 701 | /* |
| 702 | * comphy_sgmii_power_up |
| 703 | * |
| 704 | * return: 1 if PLL locked (OK), 0 otherwise (FAIL) |
| 705 | */ |
| 706 | static int comphy_sgmii_power_up(u32 lane, u32 speed, u32 invert) |
| 707 | { |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 708 | int ret; |
Marek Behún | 3c340ed | 2018-04-24 17:21:24 +0200 | [diff] [blame] | 709 | u32 saved_selector; |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 710 | |
| 711 | debug_enter(); |
| 712 | |
| 713 | /* |
| 714 | * 1. Configure PHY to SATA/SAS mode by setting pin PIN_PIPE_SEL=0 |
| 715 | */ |
Marek Behún | 3c340ed | 2018-04-24 17:21:24 +0200 | [diff] [blame] | 716 | saved_selector = readl(COMPHY_SEL_ADDR); |
| 717 | reg_set(COMPHY_SEL_ADDR, 0, 0xFFFFFFFF); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 718 | |
| 719 | /* |
| 720 | * 2. Reset PHY by setting PHY input port PIN_RESET=1. |
| 721 | * 3. Set PHY input port PIN_TX_IDLE=1, PIN_PU_IVREF=1 to keep |
| 722 | * PHY TXP/TXN output to idle state during PHY initialization |
| 723 | * 4. Set PHY input port PIN_PU_PLL=0, PIN_PU_RX=0, PIN_PU_TX=0. |
| 724 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 725 | reg_set(COMPHY_PHY_CFG1_ADDR(lane), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 726 | rb_pin_reset_comphy | rb_pin_tx_idle | rb_pin_pu_iveref, |
| 727 | rb_pin_reset_core | rb_pin_pu_pll | |
| 728 | rb_pin_pu_rx | rb_pin_pu_tx); |
| 729 | |
| 730 | /* |
| 731 | * 5. Release reset to the PHY by setting PIN_RESET=0. |
| 732 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 733 | reg_set(COMPHY_PHY_CFG1_ADDR(lane), 0, rb_pin_reset_comphy); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 734 | |
| 735 | /* |
| 736 | * 7. Set PIN_PHY_GEN_TX[3:0] and PIN_PHY_GEN_RX[3:0] to decide |
| 737 | * COMPHY bit rate |
| 738 | */ |
| 739 | if (speed == PHY_SPEED_3_125G) { /* 3.125 GHz */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 740 | reg_set(COMPHY_PHY_CFG1_ADDR(lane), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 741 | (0x8 << rf_gen_rx_sel_shift) | |
| 742 | (0x8 << rf_gen_tx_sel_shift), |
| 743 | rf_gen_rx_select | rf_gen_tx_select); |
| 744 | |
| 745 | } else if (speed == PHY_SPEED_1_25G) { /* 1.25 GHz */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 746 | reg_set(COMPHY_PHY_CFG1_ADDR(lane), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 747 | (0x6 << rf_gen_rx_sel_shift) | |
| 748 | (0x6 << rf_gen_tx_sel_shift), |
| 749 | rf_gen_rx_select | rf_gen_tx_select); |
| 750 | } else { |
| 751 | printf("Unsupported COMPHY speed!\n"); |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * 8. Wait 1mS for bandgap and reference clocks to stabilize; |
| 757 | * then start SW programming. |
| 758 | */ |
| 759 | mdelay(10); |
| 760 | |
| 761 | /* 9. Program COMPHY register PHY_MODE */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 762 | reg_set16(sgmiiphy_addr(lane, PWR_PLL_CTRL), |
Marek Behún | ee3e2f6 | 2018-04-24 17:21:13 +0200 | [diff] [blame] | 763 | PHY_MODE_SGMII << rf_phy_mode_shift, rf_phy_mode_mask); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 764 | |
| 765 | /* |
| 766 | * 10. Set COMPHY register REFCLK_SEL to select the correct REFCLK |
| 767 | * source |
| 768 | */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 769 | reg_set16(sgmiiphy_addr(lane, MISC_REG0), 0, rb_ref_clk_sel); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 770 | |
| 771 | /* |
| 772 | * 11. Set correct reference clock frequency in COMPHY register |
| 773 | * REF_FREF_SEL. |
| 774 | */ |
| 775 | if (get_ref_clk() == 40) { |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 776 | reg_set16(sgmiiphy_addr(lane, PWR_PLL_CTRL), |
Marek Behún | ee3e2f6 | 2018-04-24 17:21:13 +0200 | [diff] [blame] | 777 | 0x4 << rf_ref_freq_sel_shift, rf_ref_freq_sel_mask); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 778 | } else { |
| 779 | /* 25MHz */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 780 | reg_set16(sgmiiphy_addr(lane, PWR_PLL_CTRL), |
Marek Behún | ee3e2f6 | 2018-04-24 17:21:13 +0200 | [diff] [blame] | 781 | 0x1 << rf_ref_freq_sel_shift, rf_ref_freq_sel_mask); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /* 12. Program COMPHY register PHY_GEN_MAX[1:0] */ |
| 785 | /* |
| 786 | * This step is mentioned in the flow received from verification team. |
| 787 | * However the PHY_GEN_MAX value is only meaningful for other |
| 788 | * interfaces (not SGMII). For instance, it selects SATA speed |
| 789 | * 1.5/3/6 Gbps or PCIe speed 2.5/5 Gbps |
| 790 | */ |
| 791 | |
| 792 | /* |
| 793 | * 13. Program COMPHY register SEL_BITS to set correct parallel data |
| 794 | * bus width |
| 795 | */ |
| 796 | /* 10bit */ |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 797 | reg_set16(sgmiiphy_addr(lane, DIG_LB_EN), 0, rf_data_width_mask); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * 14. As long as DFE function needs to be enabled in any mode, |
| 801 | * COMPHY register DFE_UPDATE_EN[5:0] shall be programmed to 0x3F |
| 802 | * for real chip during COMPHY power on. |
| 803 | */ |
| 804 | /* |
| 805 | * The step 14 exists (and empty) in the original initialization flow |
| 806 | * obtained from the verification team. According to the functional |
| 807 | * specification DFE_UPDATE_EN already has the default value 0x3F |
| 808 | */ |
| 809 | |
| 810 | /* |
| 811 | * 15. Program COMPHY GEN registers. |
| 812 | * These registers should be programmed based on the lab testing |
| 813 | * result to achieve optimal performance. Please contact the CEA |
| 814 | * group to get the related GEN table during real chip bring-up. |
| 815 | * We only requred to run though the entire registers programming |
| 816 | * flow defined by "comphy_sgmii_phy_init" when the REF clock is |
| 817 | * 40 MHz. For REF clock 25 MHz the default values stored in PHY |
| 818 | * registers are OK. |
| 819 | */ |
| 820 | debug("Running C-DPI phy init %s mode\n", |
| 821 | speed == PHY_SPEED_3_125G ? "2G5" : "1G"); |
| 822 | if (get_ref_clk() == 40) |
| 823 | comphy_sgmii_phy_init(lane, speed); |
| 824 | |
| 825 | /* |
| 826 | * 16. [Simulation Only] should not be used for real chip. |
| 827 | * By pass power up calibration by programming EXT_FORCE_CAL_DONE |
| 828 | * (R02h[9]) to 1 to shorten COMPHY simulation time. |
| 829 | */ |
| 830 | /* |
| 831 | * 17. [Simulation Only: should not be used for real chip] |
| 832 | * Program COMPHY register FAST_DFE_TIMER_EN=1 to shorten RX |
| 833 | * training simulation time. |
| 834 | */ |
| 835 | |
| 836 | /* |
| 837 | * 18. Check the PHY Polarity invert bit |
| 838 | */ |
| 839 | if (invert & PHY_POLARITY_TXD_INVERT) |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 840 | reg_set16(sgmiiphy_addr(lane, SYNC_PATTERN), phy_txd_inv, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 841 | |
| 842 | if (invert & PHY_POLARITY_RXD_INVERT) |
Marek Behún | a89ae13 | 2018-04-24 17:21:14 +0200 | [diff] [blame] | 843 | reg_set16(sgmiiphy_addr(lane, SYNC_PATTERN), phy_rxd_inv, 0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 844 | |
| 845 | /* |
| 846 | * 19. Set PHY input ports PIN_PU_PLL, PIN_PU_TX and PIN_PU_RX to 1 |
| 847 | * to start PHY power up sequence. All the PHY register |
| 848 | * programming should be done before PIN_PU_PLL=1. There should be |
| 849 | * no register programming for normal PHY operation from this point. |
| 850 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 851 | reg_set(COMPHY_PHY_CFG1_ADDR(lane), |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 852 | rb_pin_pu_pll | rb_pin_pu_rx | rb_pin_pu_tx, |
| 853 | rb_pin_pu_pll | rb_pin_pu_rx | rb_pin_pu_tx); |
| 854 | |
| 855 | /* |
| 856 | * 20. Wait for PHY power up sequence to finish by checking output ports |
| 857 | * PIN_PLL_READY_TX=1 and PIN_PLL_READY_RX=1. |
| 858 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 859 | ret = comphy_poll_reg(COMPHY_PHY_STAT1_ADDR(lane), /* address */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 860 | rb_pll_ready_tx | rb_pll_ready_rx, /* value */ |
| 861 | rb_pll_ready_tx | rb_pll_ready_rx, /* mask */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 862 | POLL_32B_REG); /* 32bit */ |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 863 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 864 | printf("Failed to lock PLL for SGMII PHY %d\n", lane); |
| 865 | |
| 866 | /* |
| 867 | * 21. Set COMPHY input port PIN_TX_IDLE=0 |
| 868 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 869 | reg_set(COMPHY_PHY_CFG1_ADDR(lane), 0x0, rb_pin_tx_idle); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 870 | |
| 871 | /* |
| 872 | * 22. After valid data appear on PIN_RXDATA bus, set PIN_RX_INIT=1. |
| 873 | * to start RX initialization. PIN_RX_INIT_DONE will be cleared to |
| 874 | * 0 by the PHY. After RX initialization is done, PIN_RX_INIT_DONE |
| 875 | * will be set to 1 by COMPHY. Set PIN_RX_INIT=0 after |
| 876 | * PIN_RX_INIT_DONE= 1. |
| 877 | * Please refer to RX initialization part for details. |
| 878 | */ |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 879 | reg_set(COMPHY_PHY_CFG1_ADDR(lane), rb_phy_rx_init, 0x0); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 880 | |
Marek Behún | 4c02f73 | 2018-04-24 17:21:12 +0200 | [diff] [blame] | 881 | ret = comphy_poll_reg(COMPHY_PHY_STAT1_ADDR(lane), /* address */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 882 | rb_rx_init_done, /* value */ |
| 883 | rb_rx_init_done, /* mask */ |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 884 | POLL_32B_REG); /* 32bit */ |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 885 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 886 | printf("Failed to init RX of SGMII PHY %d\n", lane); |
| 887 | |
Marek Behún | 3c340ed | 2018-04-24 17:21:24 +0200 | [diff] [blame] | 888 | /* |
| 889 | * Restore saved selector. |
| 890 | */ |
| 891 | reg_set(COMPHY_SEL_ADDR, saved_selector, 0xFFFFFFFF); |
| 892 | |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 893 | debug_exit(); |
| 894 | |
| 895 | return ret; |
| 896 | } |
| 897 | |
| 898 | void comphy_dedicated_phys_init(void) |
| 899 | { |
| 900 | int node, usb32, ret = 1; |
| 901 | const void *blob = gd->fdt_blob; |
| 902 | |
| 903 | debug_enter(); |
| 904 | |
| 905 | for (usb32 = 0; usb32 <= 1; usb32++) { |
| 906 | /* |
| 907 | * There are 2 UTMI PHYs in this SOC. |
| 908 | * One is independendent and one is paired with USB3 port (OTG) |
| 909 | */ |
| 910 | if (usb32 == 0) { |
| 911 | node = fdt_node_offset_by_compatible( |
Marek Behún | 6b37c0c7 | 2018-05-11 10:03:39 +0200 | [diff] [blame] | 912 | blob, -1, "marvell,armada3700-ehci"); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 913 | } else { |
| 914 | node = fdt_node_offset_by_compatible( |
| 915 | blob, -1, "marvell,armada3700-xhci"); |
| 916 | } |
| 917 | |
| 918 | if (node > 0) { |
| 919 | if (fdtdec_get_is_enabled(blob, node)) { |
| 920 | ret = comphy_usb2_power_up(usb32); |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 921 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 922 | printf("Failed to initialize UTMI PHY\n"); |
| 923 | else |
| 924 | debug("UTMI PHY init succeed\n"); |
| 925 | } else { |
| 926 | debug("USB%d node is disabled\n", |
| 927 | usb32 == 0 ? 2 : 3); |
| 928 | } |
| 929 | } else { |
| 930 | debug("No USB%d node in DT\n", usb32 == 0 ? 2 : 3); |
| 931 | } |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | node = fdt_node_offset_by_compatible(blob, -1, |
Stefan Roese | 86928bf | 2017-01-12 16:37:49 +0100 | [diff] [blame] | 935 | "marvell,armada-8k-sdhci"); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 936 | if (node <= 0) { |
Stefan Roese | 86928bf | 2017-01-12 16:37:49 +0100 | [diff] [blame] | 937 | node = fdt_node_offset_by_compatible( |
| 938 | blob, -1, "marvell,armada-3700-sdhci"); |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | if (node > 0) { |
| 942 | if (fdtdec_get_is_enabled(blob, node)) { |
| 943 | ret = comphy_emmc_power_up(); |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 944 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 945 | printf("Failed to initialize SDIO/eMMC PHY\n"); |
| 946 | else |
| 947 | debug("SDIO/eMMC PHY init succeed\n"); |
| 948 | } else { |
| 949 | debug("SDIO/eMMC node is disabled\n"); |
| 950 | } |
| 951 | } else { |
| 952 | debug("No SDIO/eMMC node in DT\n"); |
| 953 | } |
| 954 | |
| 955 | debug_exit(); |
| 956 | } |
| 957 | |
| 958 | int comphy_a3700_init(struct chip_serdes_phy_config *chip_cfg, |
| 959 | struct comphy_map *serdes_map) |
| 960 | { |
| 961 | struct comphy_map *comphy_map; |
| 962 | u32 comphy_max_count = chip_cfg->comphy_lanes_count; |
| 963 | u32 lane, ret = 0; |
| 964 | |
| 965 | debug_enter(); |
| 966 | |
Marek Behún | 817c2ce | 2018-04-24 17:21:23 +0200 | [diff] [blame] | 967 | /* Initialize PHY mux */ |
| 968 | chip_cfg->mux_data = a3700_comphy_mux_data; |
| 969 | comphy_mux_init(chip_cfg, serdes_map, COMPHY_SEL_ADDR); |
| 970 | |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 971 | for (lane = 0, comphy_map = serdes_map; lane < comphy_max_count; |
| 972 | lane++, comphy_map++) { |
| 973 | debug("Initialize serdes number %d\n", lane); |
| 974 | debug("Serdes type = 0x%x invert=%d\n", |
| 975 | comphy_map->type, comphy_map->invert); |
| 976 | |
| 977 | switch (comphy_map->type) { |
| 978 | case PHY_TYPE_UNCONNECTED: |
| 979 | continue; |
| 980 | break; |
| 981 | |
| 982 | case PHY_TYPE_PEX0: |
| 983 | ret = comphy_pcie_power_up(comphy_map->speed, |
| 984 | comphy_map->invert); |
| 985 | break; |
| 986 | |
| 987 | case PHY_TYPE_USB3_HOST0: |
| 988 | case PHY_TYPE_USB3_DEVICE: |
Marek Behún | ef6f36e | 2018-04-24 17:21:18 +0200 | [diff] [blame] | 989 | ret = comphy_usb3_power_up(lane, |
| 990 | comphy_map->type, |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 991 | comphy_map->speed, |
| 992 | comphy_map->invert); |
| 993 | break; |
| 994 | |
| 995 | case PHY_TYPE_SGMII0: |
| 996 | case PHY_TYPE_SGMII1: |
| 997 | ret = comphy_sgmii_power_up(lane, comphy_map->speed, |
| 998 | comphy_map->invert); |
| 999 | break; |
| 1000 | |
zachary | ba42e84 | 2020-08-28 16:56:29 +0200 | [diff] [blame] | 1001 | case PHY_TYPE_SATA0: |
| 1002 | ret = comphy_sata_power_up(comphy_map->invert); |
| 1003 | break; |
| 1004 | |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 1005 | default: |
| 1006 | debug("Unknown SerDes type, skip initialize SerDes %d\n", |
| 1007 | lane); |
| 1008 | ret = 1; |
| 1009 | break; |
| 1010 | } |
Marek Behún | e3183c6 | 2018-04-24 17:21:16 +0200 | [diff] [blame] | 1011 | if (!ret) |
Stefan Roese | 8f64e26 | 2016-05-23 11:12:05 +0200 | [diff] [blame] | 1012 | printf("PLL is not locked - Failed to initialize lane %d\n", |
| 1013 | lane); |
| 1014 | } |
| 1015 | |
| 1016 | debug_exit(); |
| 1017 | return ret; |
| 1018 | } |