Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 MediaTek Inc. |
| 3 | * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <dt-bindings/phy/phy.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/io.h> |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 20 | #include <linux/iopoll.h> |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/of_address.h> |
Chunfeng Yun | e4b227c | 2017-12-28 16:40:36 +0530 | [diff] [blame] | 23 | #include <linux/of_device.h> |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 24 | #include <linux/phy/phy.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 27 | /* version V1 sub-banks offset base address */ |
| 28 | /* banks shared by multiple phys */ |
| 29 | #define SSUSB_SIFSLV_V1_SPLLC 0x000 /* shared by u3 phys */ |
| 30 | #define SSUSB_SIFSLV_V1_U2FREQ 0x100 /* shared by u2 phys */ |
Chunfeng Yun | 554a56f | 2017-09-21 18:31:48 +0800 | [diff] [blame] | 31 | #define SSUSB_SIFSLV_V1_CHIP 0x300 /* shared by u3 phys */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 32 | /* u2 phy bank */ |
| 33 | #define SSUSB_SIFSLV_V1_U2PHY_COM 0x000 |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 34 | /* u3/pcie/sata phy banks */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 35 | #define SSUSB_SIFSLV_V1_U3PHYD 0x000 |
| 36 | #define SSUSB_SIFSLV_V1_U3PHYA 0x200 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 37 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 38 | /* version V2 sub-banks offset base address */ |
| 39 | /* u2 phy banks */ |
| 40 | #define SSUSB_SIFSLV_V2_MISC 0x000 |
| 41 | #define SSUSB_SIFSLV_V2_U2FREQ 0x100 |
| 42 | #define SSUSB_SIFSLV_V2_U2PHY_COM 0x300 |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 43 | /* u3/pcie/sata phy banks */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 44 | #define SSUSB_SIFSLV_V2_SPLLC 0x000 |
| 45 | #define SSUSB_SIFSLV_V2_CHIP 0x100 |
| 46 | #define SSUSB_SIFSLV_V2_U3PHYD 0x200 |
| 47 | #define SSUSB_SIFSLV_V2_U3PHYA 0x400 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 48 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 49 | #define U3P_USBPHYACR0 0x000 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 50 | #define PA0_RG_U2PLL_FORCE_ON BIT(15) |
Chunfeng Yun | c0250fe | 2017-03-31 15:35:32 +0800 | [diff] [blame] | 51 | #define PA0_RG_USB20_INTR_EN BIT(5) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 52 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 53 | #define U3P_USBPHYACR2 0x008 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 54 | #define PA2_RG_SIF_U2PLL_FORCE_EN BIT(18) |
| 55 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 56 | #define U3P_USBPHYACR5 0x014 |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 57 | #define PA5_RG_U2_HSTX_SRCAL_EN BIT(15) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 58 | #define PA5_RG_U2_HSTX_SRCTRL GENMASK(14, 12) |
| 59 | #define PA5_RG_U2_HSTX_SRCTRL_VAL(x) ((0x7 & (x)) << 12) |
| 60 | #define PA5_RG_U2_HS_100U_U3_EN BIT(11) |
| 61 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 62 | #define U3P_USBPHYACR6 0x018 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 63 | #define PA6_RG_U2_BC11_SW_EN BIT(23) |
| 64 | #define PA6_RG_U2_OTG_VBUSCMP_EN BIT(20) |
Chunfeng Yun | 43f53b1 | 2015-12-04 10:08:56 +0800 | [diff] [blame] | 65 | #define PA6_RG_U2_SQTH GENMASK(3, 0) |
| 66 | #define PA6_RG_U2_SQTH_VAL(x) (0xf & (x)) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 67 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 68 | #define U3P_U2PHYACR4 0x020 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 69 | #define P2C_RG_USB20_GPIO_CTL BIT(9) |
| 70 | #define P2C_USB20_GPIO_MODE BIT(8) |
| 71 | #define P2C_U2_GPIO_CTR_MSK (P2C_RG_USB20_GPIO_CTL | P2C_USB20_GPIO_MODE) |
| 72 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 73 | #define U3D_U2PHYDCR0 0x060 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 74 | #define P2C_RG_SIF_U2PLL_FORCE_ON BIT(24) |
| 75 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 76 | #define U3P_U2PHYDTM0 0x068 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 77 | #define P2C_FORCE_UART_EN BIT(26) |
| 78 | #define P2C_FORCE_DATAIN BIT(23) |
| 79 | #define P2C_FORCE_DM_PULLDOWN BIT(21) |
| 80 | #define P2C_FORCE_DP_PULLDOWN BIT(20) |
| 81 | #define P2C_FORCE_XCVRSEL BIT(19) |
| 82 | #define P2C_FORCE_SUSPENDM BIT(18) |
| 83 | #define P2C_FORCE_TERMSEL BIT(17) |
| 84 | #define P2C_RG_DATAIN GENMASK(13, 10) |
| 85 | #define P2C_RG_DATAIN_VAL(x) ((0xf & (x)) << 10) |
| 86 | #define P2C_RG_DMPULLDOWN BIT(7) |
| 87 | #define P2C_RG_DPPULLDOWN BIT(6) |
| 88 | #define P2C_RG_XCVRSEL GENMASK(5, 4) |
| 89 | #define P2C_RG_XCVRSEL_VAL(x) ((0x3 & (x)) << 4) |
| 90 | #define P2C_RG_SUSPENDM BIT(3) |
| 91 | #define P2C_RG_TERMSEL BIT(2) |
| 92 | #define P2C_DTM0_PART_MASK \ |
| 93 | (P2C_FORCE_DATAIN | P2C_FORCE_DM_PULLDOWN | \ |
| 94 | P2C_FORCE_DP_PULLDOWN | P2C_FORCE_XCVRSEL | \ |
| 95 | P2C_FORCE_TERMSEL | P2C_RG_DMPULLDOWN | \ |
| 96 | P2C_RG_DPPULLDOWN | P2C_RG_TERMSEL) |
| 97 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 98 | #define U3P_U2PHYDTM1 0x06C |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 99 | #define P2C_RG_UART_EN BIT(16) |
Chunfeng Yun | 5954a10 | 2017-09-21 18:31:49 +0800 | [diff] [blame] | 100 | #define P2C_FORCE_IDDIG BIT(9) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 101 | #define P2C_RG_VBUSVALID BIT(5) |
| 102 | #define P2C_RG_SESSEND BIT(4) |
| 103 | #define P2C_RG_AVALID BIT(2) |
Chunfeng Yun | 5954a10 | 2017-09-21 18:31:49 +0800 | [diff] [blame] | 104 | #define P2C_RG_IDDIG BIT(1) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 105 | |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 106 | #define U3P_U3_CHIP_GPIO_CTLD 0x0c |
| 107 | #define P3C_REG_IP_SW_RST BIT(31) |
| 108 | #define P3C_MCU_BUS_CK_GATE_EN BIT(30) |
| 109 | #define P3C_FORCE_IP_SW_RST BIT(29) |
| 110 | |
| 111 | #define U3P_U3_CHIP_GPIO_CTLE 0x10 |
| 112 | #define P3C_RG_SWRST_U3_PHYD BIT(25) |
| 113 | #define P3C_RG_SWRST_U3_PHYD_FORCE_EN BIT(24) |
| 114 | |
| 115 | #define U3P_U3_PHYA_REG0 0x000 |
| 116 | #define P3A_RG_CLKDRV_OFF GENMASK(3, 2) |
| 117 | #define P3A_RG_CLKDRV_OFF_VAL(x) ((0x3 & (x)) << 2) |
| 118 | |
| 119 | #define U3P_U3_PHYA_REG1 0x004 |
| 120 | #define P3A_RG_CLKDRV_AMP GENMASK(31, 29) |
| 121 | #define P3A_RG_CLKDRV_AMP_VAL(x) ((0x7 & (x)) << 29) |
| 122 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 123 | #define U3P_U3_PHYA_REG6 0x018 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 124 | #define P3A_RG_TX_EIDLE_CM GENMASK(31, 28) |
| 125 | #define P3A_RG_TX_EIDLE_CM_VAL(x) ((0xf & (x)) << 28) |
| 126 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 127 | #define U3P_U3_PHYA_REG9 0x024 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 128 | #define P3A_RG_RX_DAC_MUX GENMASK(5, 1) |
| 129 | #define P3A_RG_RX_DAC_MUX_VAL(x) ((0x1f & (x)) << 1) |
| 130 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 131 | #define U3P_U3_PHYA_DA_REG0 0x100 |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 132 | #define P3A_RG_XTAL_EXT_PE2H GENMASK(17, 16) |
| 133 | #define P3A_RG_XTAL_EXT_PE2H_VAL(x) ((0x3 & (x)) << 16) |
| 134 | #define P3A_RG_XTAL_EXT_PE1H GENMASK(13, 12) |
| 135 | #define P3A_RG_XTAL_EXT_PE1H_VAL(x) ((0x3 & (x)) << 12) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 136 | #define P3A_RG_XTAL_EXT_EN_U3 GENMASK(11, 10) |
| 137 | #define P3A_RG_XTAL_EXT_EN_U3_VAL(x) ((0x3 & (x)) << 10) |
| 138 | |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 139 | #define U3P_U3_PHYA_DA_REG4 0x108 |
| 140 | #define P3A_RG_PLL_DIVEN_PE2H GENMASK(21, 19) |
| 141 | #define P3A_RG_PLL_BC_PE2H GENMASK(7, 6) |
| 142 | #define P3A_RG_PLL_BC_PE2H_VAL(x) ((0x3 & (x)) << 6) |
| 143 | |
| 144 | #define U3P_U3_PHYA_DA_REG5 0x10c |
| 145 | #define P3A_RG_PLL_BR_PE2H GENMASK(29, 28) |
| 146 | #define P3A_RG_PLL_BR_PE2H_VAL(x) ((0x3 & (x)) << 28) |
| 147 | #define P3A_RG_PLL_IC_PE2H GENMASK(15, 12) |
| 148 | #define P3A_RG_PLL_IC_PE2H_VAL(x) ((0xf & (x)) << 12) |
| 149 | |
| 150 | #define U3P_U3_PHYA_DA_REG6 0x110 |
| 151 | #define P3A_RG_PLL_IR_PE2H GENMASK(19, 16) |
| 152 | #define P3A_RG_PLL_IR_PE2H_VAL(x) ((0xf & (x)) << 16) |
| 153 | |
| 154 | #define U3P_U3_PHYA_DA_REG7 0x114 |
| 155 | #define P3A_RG_PLL_BP_PE2H GENMASK(19, 16) |
| 156 | #define P3A_RG_PLL_BP_PE2H_VAL(x) ((0xf & (x)) << 16) |
| 157 | |
| 158 | #define U3P_U3_PHYA_DA_REG20 0x13c |
| 159 | #define P3A_RG_PLL_DELTA1_PE2H GENMASK(31, 16) |
| 160 | #define P3A_RG_PLL_DELTA1_PE2H_VAL(x) ((0xffff & (x)) << 16) |
| 161 | |
| 162 | #define U3P_U3_PHYA_DA_REG25 0x148 |
| 163 | #define P3A_RG_PLL_DELTA_PE2H GENMASK(15, 0) |
| 164 | #define P3A_RG_PLL_DELTA_PE2H_VAL(x) (0xffff & (x)) |
| 165 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 166 | #define U3P_U3_PHYD_LFPS1 0x00c |
Chunfeng Yun | 98cd83a | 2017-03-31 15:35:28 +0800 | [diff] [blame] | 167 | #define P3D_RG_FWAKE_TH GENMASK(21, 16) |
| 168 | #define P3D_RG_FWAKE_TH_VAL(x) ((0x3f & (x)) << 16) |
| 169 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 170 | #define U3P_U3_PHYD_CDR1 0x05c |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 171 | #define P3D_RG_CDR_BIR_LTD1 GENMASK(28, 24) |
| 172 | #define P3D_RG_CDR_BIR_LTD1_VAL(x) ((0x1f & (x)) << 24) |
| 173 | #define P3D_RG_CDR_BIR_LTD0 GENMASK(12, 8) |
| 174 | #define P3D_RG_CDR_BIR_LTD0_VAL(x) ((0x1f & (x)) << 8) |
| 175 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 176 | #define U3P_U3_PHYD_RXDET1 0x128 |
Chunfeng Yun | 1969f69 | 2017-03-31 15:35:27 +0800 | [diff] [blame] | 177 | #define P3D_RG_RXDET_STB2_SET GENMASK(17, 9) |
| 178 | #define P3D_RG_RXDET_STB2_SET_VAL(x) ((0x1ff & (x)) << 9) |
| 179 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 180 | #define U3P_U3_PHYD_RXDET2 0x12c |
Chunfeng Yun | 1969f69 | 2017-03-31 15:35:27 +0800 | [diff] [blame] | 181 | #define P3D_RG_RXDET_STB2_SET_P3 GENMASK(8, 0) |
| 182 | #define P3D_RG_RXDET_STB2_SET_P3_VAL(x) (0x1ff & (x)) |
| 183 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 184 | #define U3P_SPLLC_XTALCTL3 0x018 |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 185 | #define XC3_RG_U3_XTAL_RX_PWD BIT(9) |
| 186 | #define XC3_RG_U3_FRC_XTAL_RX_PWD BIT(8) |
| 187 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 188 | #define U3P_U2FREQ_FMCR0 0x00 |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 189 | #define P2F_RG_MONCLK_SEL GENMASK(27, 26) |
| 190 | #define P2F_RG_MONCLK_SEL_VAL(x) ((0x3 & (x)) << 26) |
| 191 | #define P2F_RG_FREQDET_EN BIT(24) |
| 192 | #define P2F_RG_CYCLECNT GENMASK(23, 0) |
| 193 | #define P2F_RG_CYCLECNT_VAL(x) ((P2F_RG_CYCLECNT) & (x)) |
| 194 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 195 | #define U3P_U2FREQ_VALUE 0x0c |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 196 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 197 | #define U3P_U2FREQ_FMMONR1 0x10 |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 198 | #define P2F_USB_FM_VALID BIT(0) |
| 199 | #define P2F_RG_FRCK_EN BIT(8) |
| 200 | |
| 201 | #define U3P_REF_CLK 26 /* MHZ */ |
| 202 | #define U3P_SLEW_RATE_COEF 28 |
| 203 | #define U3P_SR_COEF_DIVISOR 1000 |
| 204 | #define U3P_FM_DET_CYCLE_CNT 1024 |
| 205 | |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 206 | /* SATA register setting */ |
| 207 | #define PHYD_CTRL_SIGNAL_MODE4 0x1c |
| 208 | /* CDR Charge Pump P-path current adjustment */ |
| 209 | #define RG_CDR_BICLTD1_GEN1_MSK GENMASK(23, 20) |
| 210 | #define RG_CDR_BICLTD1_GEN1_VAL(x) ((0xf & (x)) << 20) |
| 211 | #define RG_CDR_BICLTD0_GEN1_MSK GENMASK(11, 8) |
| 212 | #define RG_CDR_BICLTD0_GEN1_VAL(x) ((0xf & (x)) << 8) |
| 213 | |
| 214 | #define PHYD_DESIGN_OPTION2 0x24 |
| 215 | /* Symbol lock count selection */ |
| 216 | #define RG_LOCK_CNT_SEL_MSK GENMASK(5, 4) |
| 217 | #define RG_LOCK_CNT_SEL_VAL(x) ((0x3 & (x)) << 4) |
| 218 | |
| 219 | #define PHYD_DESIGN_OPTION9 0x40 |
| 220 | /* COMWAK GAP width window */ |
| 221 | #define RG_TG_MAX_MSK GENMASK(20, 16) |
| 222 | #define RG_TG_MAX_VAL(x) ((0x1f & (x)) << 16) |
| 223 | /* COMINIT GAP width window */ |
| 224 | #define RG_T2_MAX_MSK GENMASK(13, 8) |
| 225 | #define RG_T2_MAX_VAL(x) ((0x3f & (x)) << 8) |
| 226 | /* COMWAK GAP width window */ |
| 227 | #define RG_TG_MIN_MSK GENMASK(7, 5) |
| 228 | #define RG_TG_MIN_VAL(x) ((0x7 & (x)) << 5) |
| 229 | /* COMINIT GAP width window */ |
| 230 | #define RG_T2_MIN_MSK GENMASK(4, 0) |
| 231 | #define RG_T2_MIN_VAL(x) (0x1f & (x)) |
| 232 | |
| 233 | #define ANA_RG_CTRL_SIGNAL1 0x4c |
| 234 | /* TX driver tail current control for 0dB de-empahsis mdoe for Gen1 speed */ |
| 235 | #define RG_IDRV_0DB_GEN1_MSK GENMASK(13, 8) |
| 236 | #define RG_IDRV_0DB_GEN1_VAL(x) ((0x3f & (x)) << 8) |
| 237 | |
| 238 | #define ANA_RG_CTRL_SIGNAL4 0x58 |
| 239 | #define RG_CDR_BICLTR_GEN1_MSK GENMASK(23, 20) |
| 240 | #define RG_CDR_BICLTR_GEN1_VAL(x) ((0xf & (x)) << 20) |
| 241 | /* Loop filter R1 resistance adjustment for Gen1 speed */ |
| 242 | #define RG_CDR_BR_GEN2_MSK GENMASK(10, 8) |
| 243 | #define RG_CDR_BR_GEN2_VAL(x) ((0x7 & (x)) << 8) |
| 244 | |
| 245 | #define ANA_RG_CTRL_SIGNAL6 0x60 |
| 246 | /* I-path capacitance adjustment for Gen1 */ |
| 247 | #define RG_CDR_BC_GEN1_MSK GENMASK(28, 24) |
| 248 | #define RG_CDR_BC_GEN1_VAL(x) ((0x1f & (x)) << 24) |
| 249 | #define RG_CDR_BIRLTR_GEN1_MSK GENMASK(4, 0) |
| 250 | #define RG_CDR_BIRLTR_GEN1_VAL(x) (0x1f & (x)) |
| 251 | |
| 252 | #define ANA_EQ_EYE_CTRL_SIGNAL1 0x6c |
| 253 | /* RX Gen1 LEQ tuning step */ |
| 254 | #define RG_EQ_DLEQ_LFI_GEN1_MSK GENMASK(11, 8) |
| 255 | #define RG_EQ_DLEQ_LFI_GEN1_VAL(x) ((0xf & (x)) << 8) |
| 256 | |
| 257 | #define ANA_EQ_EYE_CTRL_SIGNAL4 0xd8 |
| 258 | #define RG_CDR_BIRLTD0_GEN1_MSK GENMASK(20, 16) |
| 259 | #define RG_CDR_BIRLTD0_GEN1_VAL(x) ((0x1f & (x)) << 16) |
| 260 | |
| 261 | #define ANA_EQ_EYE_CTRL_SIGNAL5 0xdc |
| 262 | #define RG_CDR_BIRLTD0_GEN3_MSK GENMASK(4, 0) |
| 263 | #define RG_CDR_BIRLTD0_GEN3_VAL(x) (0x1f & (x)) |
| 264 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 265 | enum mtk_phy_version { |
| 266 | MTK_PHY_V1 = 1, |
| 267 | MTK_PHY_V2, |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 268 | }; |
| 269 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 270 | struct mtk_phy_pdata { |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 271 | /* avoid RX sensitivity level degradation only for mt8173 */ |
| 272 | bool avoid_rx_sen_degradation; |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 273 | enum mtk_phy_version version; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | struct u2phy_banks { |
| 277 | void __iomem *misc; |
| 278 | void __iomem *fmreg; |
| 279 | void __iomem *com; |
| 280 | }; |
| 281 | |
| 282 | struct u3phy_banks { |
| 283 | void __iomem *spllc; |
| 284 | void __iomem *chip; |
| 285 | void __iomem *phyd; /* include u3phyd_bank2 */ |
| 286 | void __iomem *phya; /* include u3phya_da */ |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 287 | }; |
| 288 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 289 | struct mtk_phy_instance { |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 290 | struct phy *phy; |
| 291 | void __iomem *port_base; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 292 | union { |
| 293 | struct u2phy_banks u2_banks; |
| 294 | struct u3phy_banks u3_banks; |
| 295 | }; |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 296 | struct clk *ref_clk; /* reference clock of anolog phy */ |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 297 | u32 index; |
| 298 | u8 type; |
| 299 | }; |
| 300 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 301 | struct mtk_tphy { |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 302 | struct device *dev; |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 303 | void __iomem *sif_base; /* only shared sif */ |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 304 | /* deprecated, use @ref_clk instead in phy instance */ |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 305 | struct clk *u3phya_ref; /* reference clock of usb3 anolog phy */ |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 306 | const struct mtk_phy_pdata *pdata; |
| 307 | struct mtk_phy_instance **phys; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 308 | int nphys; |
| 309 | }; |
| 310 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 311 | static void hs_slew_rate_calibrate(struct mtk_tphy *tphy, |
| 312 | struct mtk_phy_instance *instance) |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 313 | { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 314 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 315 | void __iomem *fmreg = u2_banks->fmreg; |
| 316 | void __iomem *com = u2_banks->com; |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 317 | int calibration_val; |
| 318 | int fm_out; |
| 319 | u32 tmp; |
| 320 | |
| 321 | /* enable USB ring oscillator */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 322 | tmp = readl(com + U3P_USBPHYACR5); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 323 | tmp |= PA5_RG_U2_HSTX_SRCAL_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 324 | writel(tmp, com + U3P_USBPHYACR5); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 325 | udelay(1); |
| 326 | |
| 327 | /*enable free run clock */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 328 | tmp = readl(fmreg + U3P_U2FREQ_FMMONR1); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 329 | tmp |= P2F_RG_FRCK_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 330 | writel(tmp, fmreg + U3P_U2FREQ_FMMONR1); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 331 | |
| 332 | /* set cycle count as 1024, and select u2 channel */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 333 | tmp = readl(fmreg + U3P_U2FREQ_FMCR0); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 334 | tmp &= ~(P2F_RG_CYCLECNT | P2F_RG_MONCLK_SEL); |
| 335 | tmp |= P2F_RG_CYCLECNT_VAL(U3P_FM_DET_CYCLE_CNT); |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 336 | if (tphy->pdata->version == MTK_PHY_V1) |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 337 | tmp |= P2F_RG_MONCLK_SEL_VAL(instance->index >> 1); |
| 338 | |
| 339 | writel(tmp, fmreg + U3P_U2FREQ_FMCR0); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 340 | |
| 341 | /* enable frequency meter */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 342 | tmp = readl(fmreg + U3P_U2FREQ_FMCR0); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 343 | tmp |= P2F_RG_FREQDET_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 344 | writel(tmp, fmreg + U3P_U2FREQ_FMCR0); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 345 | |
| 346 | /* ignore return value */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 347 | readl_poll_timeout(fmreg + U3P_U2FREQ_FMMONR1, tmp, |
| 348 | (tmp & P2F_USB_FM_VALID), 10, 200); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 349 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 350 | fm_out = readl(fmreg + U3P_U2FREQ_VALUE); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 351 | |
| 352 | /* disable frequency meter */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 353 | tmp = readl(fmreg + U3P_U2FREQ_FMCR0); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 354 | tmp &= ~P2F_RG_FREQDET_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 355 | writel(tmp, fmreg + U3P_U2FREQ_FMCR0); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 356 | |
| 357 | /*disable free run clock */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 358 | tmp = readl(fmreg + U3P_U2FREQ_FMMONR1); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 359 | tmp &= ~P2F_RG_FRCK_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 360 | writel(tmp, fmreg + U3P_U2FREQ_FMMONR1); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 361 | |
| 362 | if (fm_out) { |
| 363 | /* ( 1024 / FM_OUT ) x reference clock frequency x 0.028 */ |
| 364 | tmp = U3P_FM_DET_CYCLE_CNT * U3P_REF_CLK * U3P_SLEW_RATE_COEF; |
| 365 | tmp /= fm_out; |
| 366 | calibration_val = DIV_ROUND_CLOSEST(tmp, U3P_SR_COEF_DIVISOR); |
| 367 | } else { |
| 368 | /* if FM detection fail, set default value */ |
| 369 | calibration_val = 4; |
| 370 | } |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 371 | dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d\n", |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 372 | instance->index, fm_out, calibration_val); |
| 373 | |
| 374 | /* set HS slew rate */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 375 | tmp = readl(com + U3P_USBPHYACR5); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 376 | tmp &= ~PA5_RG_U2_HSTX_SRCTRL; |
| 377 | tmp |= PA5_RG_U2_HSTX_SRCTRL_VAL(calibration_val); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 378 | writel(tmp, com + U3P_USBPHYACR5); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 379 | |
| 380 | /* disable USB ring oscillator */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 381 | tmp = readl(com + U3P_USBPHYACR5); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 382 | tmp &= ~PA5_RG_U2_HSTX_SRCAL_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 383 | writel(tmp, com + U3P_USBPHYACR5); |
Chunfeng Yun | 75f072f | 2015-12-04 10:11:05 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 386 | static void u3_phy_instance_init(struct mtk_tphy *tphy, |
| 387 | struct mtk_phy_instance *instance) |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 388 | { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 389 | struct u3phy_banks *u3_banks = &instance->u3_banks; |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 390 | u32 tmp; |
| 391 | |
| 392 | /* gating PCIe Analog XTAL clock */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 393 | tmp = readl(u3_banks->spllc + U3P_SPLLC_XTALCTL3); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 394 | tmp |= XC3_RG_U3_XTAL_RX_PWD | XC3_RG_U3_FRC_XTAL_RX_PWD; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 395 | writel(tmp, u3_banks->spllc + U3P_SPLLC_XTALCTL3); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 396 | |
| 397 | /* gating XSQ */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 398 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG0); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 399 | tmp &= ~P3A_RG_XTAL_EXT_EN_U3; |
| 400 | tmp |= P3A_RG_XTAL_EXT_EN_U3_VAL(2); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 401 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG0); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 402 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 403 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_REG9); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 404 | tmp &= ~P3A_RG_RX_DAC_MUX; |
| 405 | tmp |= P3A_RG_RX_DAC_MUX_VAL(4); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 406 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_REG9); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 407 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 408 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_REG6); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 409 | tmp &= ~P3A_RG_TX_EIDLE_CM; |
| 410 | tmp |= P3A_RG_TX_EIDLE_CM_VAL(0xe); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 411 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_REG6); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 412 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 413 | tmp = readl(u3_banks->phyd + U3P_U3_PHYD_CDR1); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 414 | tmp &= ~(P3D_RG_CDR_BIR_LTD0 | P3D_RG_CDR_BIR_LTD1); |
| 415 | tmp |= P3D_RG_CDR_BIR_LTD0_VAL(0xc) | P3D_RG_CDR_BIR_LTD1_VAL(0x3); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 416 | writel(tmp, u3_banks->phyd + U3P_U3_PHYD_CDR1); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 417 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 418 | tmp = readl(u3_banks->phyd + U3P_U3_PHYD_LFPS1); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 419 | tmp &= ~P3D_RG_FWAKE_TH; |
| 420 | tmp |= P3D_RG_FWAKE_TH_VAL(0x34); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 421 | writel(tmp, u3_banks->phyd + U3P_U3_PHYD_LFPS1); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 422 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 423 | tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RXDET1); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 424 | tmp &= ~P3D_RG_RXDET_STB2_SET; |
| 425 | tmp |= P3D_RG_RXDET_STB2_SET_VAL(0x10); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 426 | writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET1); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 427 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 428 | tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RXDET2); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 429 | tmp &= ~P3D_RG_RXDET_STB2_SET_P3; |
| 430 | tmp |= P3D_RG_RXDET_STB2_SET_P3_VAL(0x10); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 431 | writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET2); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 432 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 433 | dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 434 | } |
| 435 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 436 | static void u2_phy_instance_init(struct mtk_tphy *tphy, |
| 437 | struct mtk_phy_instance *instance) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 438 | { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 439 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 440 | void __iomem *com = u2_banks->com; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 441 | u32 index = instance->index; |
| 442 | u32 tmp; |
| 443 | |
Chunfeng Yun | 00c0092 | 2017-12-07 19:53:34 +0800 | [diff] [blame] | 444 | /* switch to USB function, and enable usb pll */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 445 | tmp = readl(com + U3P_U2PHYDTM0); |
Chunfeng Yun | 00c0092 | 2017-12-07 19:53:34 +0800 | [diff] [blame] | 446 | tmp &= ~(P2C_FORCE_UART_EN | P2C_FORCE_SUSPENDM); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 447 | tmp |= P2C_RG_XCVRSEL_VAL(1) | P2C_RG_DATAIN_VAL(0); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 448 | writel(tmp, com + U3P_U2PHYDTM0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 449 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 450 | tmp = readl(com + U3P_U2PHYDTM1); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 451 | tmp &= ~P2C_RG_UART_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 452 | writel(tmp, com + U3P_U2PHYDTM1); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 453 | |
Chunfeng Yun | c0250fe | 2017-03-31 15:35:32 +0800 | [diff] [blame] | 454 | tmp = readl(com + U3P_USBPHYACR0); |
| 455 | tmp |= PA0_RG_USB20_INTR_EN; |
| 456 | writel(tmp, com + U3P_USBPHYACR0); |
| 457 | |
| 458 | /* disable switch 100uA current to SSUSB */ |
| 459 | tmp = readl(com + U3P_USBPHYACR5); |
| 460 | tmp &= ~PA5_RG_U2_HS_100U_U3_EN; |
| 461 | writel(tmp, com + U3P_USBPHYACR5); |
| 462 | |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 463 | if (!index) { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 464 | tmp = readl(com + U3P_U2PHYACR4); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 465 | tmp &= ~P2C_U2_GPIO_CTR_MSK; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 466 | writel(tmp, com + U3P_U2PHYACR4); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 467 | } |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 468 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 469 | if (tphy->pdata->avoid_rx_sen_degradation) { |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 470 | if (!index) { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 471 | tmp = readl(com + U3P_USBPHYACR2); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 472 | tmp |= PA2_RG_SIF_U2PLL_FORCE_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 473 | writel(tmp, com + U3P_USBPHYACR2); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 474 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 475 | tmp = readl(com + U3D_U2PHYDCR0); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 476 | tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 477 | writel(tmp, com + U3D_U2PHYDCR0); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 478 | } else { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 479 | tmp = readl(com + U3D_U2PHYDCR0); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 480 | tmp |= P2C_RG_SIF_U2PLL_FORCE_ON; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 481 | writel(tmp, com + U3D_U2PHYDCR0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 482 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 483 | tmp = readl(com + U3P_U2PHYDTM0); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 484 | tmp |= P2C_RG_SUSPENDM | P2C_FORCE_SUSPENDM; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 485 | writel(tmp, com + U3P_U2PHYDTM0); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 486 | } |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 487 | } |
| 488 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 489 | tmp = readl(com + U3P_USBPHYACR6); |
Chunfeng Yun | 43f53b1 | 2015-12-04 10:08:56 +0800 | [diff] [blame] | 490 | tmp &= ~PA6_RG_U2_BC11_SW_EN; /* DP/DM BC1.1 path Disable */ |
| 491 | tmp &= ~PA6_RG_U2_SQTH; |
| 492 | tmp |= PA6_RG_U2_SQTH_VAL(2); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 493 | writel(tmp, com + U3P_USBPHYACR6); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 494 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 495 | dev_dbg(tphy->dev, "%s(%d)\n", __func__, index); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 496 | } |
| 497 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 498 | static void u2_phy_instance_power_on(struct mtk_tphy *tphy, |
| 499 | struct mtk_phy_instance *instance) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 500 | { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 501 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 502 | void __iomem *com = u2_banks->com; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 503 | u32 index = instance->index; |
| 504 | u32 tmp; |
| 505 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 506 | tmp = readl(com + U3P_U2PHYDTM0); |
Chunfeng Yun | 00c0092 | 2017-12-07 19:53:34 +0800 | [diff] [blame] | 507 | tmp &= ~(P2C_RG_XCVRSEL | P2C_RG_DATAIN | P2C_DTM0_PART_MASK); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 508 | writel(tmp, com + U3P_U2PHYDTM0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 509 | |
| 510 | /* OTG Enable */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 511 | tmp = readl(com + U3P_USBPHYACR6); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 512 | tmp |= PA6_RG_U2_OTG_VBUSCMP_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 513 | writel(tmp, com + U3P_USBPHYACR6); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 514 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 515 | tmp = readl(com + U3P_U2PHYDTM1); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 516 | tmp |= P2C_RG_VBUSVALID | P2C_RG_AVALID; |
| 517 | tmp &= ~P2C_RG_SESSEND; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 518 | writel(tmp, com + U3P_U2PHYDTM1); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 519 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 520 | if (tphy->pdata->avoid_rx_sen_degradation && index) { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 521 | tmp = readl(com + U3D_U2PHYDCR0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 522 | tmp |= P2C_RG_SIF_U2PLL_FORCE_ON; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 523 | writel(tmp, com + U3D_U2PHYDCR0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 524 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 525 | tmp = readl(com + U3P_U2PHYDTM0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 526 | tmp |= P2C_RG_SUSPENDM | P2C_FORCE_SUSPENDM; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 527 | writel(tmp, com + U3P_U2PHYDTM0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 528 | } |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 529 | dev_dbg(tphy->dev, "%s(%d)\n", __func__, index); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 530 | } |
| 531 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 532 | static void u2_phy_instance_power_off(struct mtk_tphy *tphy, |
| 533 | struct mtk_phy_instance *instance) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 534 | { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 535 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 536 | void __iomem *com = u2_banks->com; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 537 | u32 index = instance->index; |
| 538 | u32 tmp; |
| 539 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 540 | tmp = readl(com + U3P_U2PHYDTM0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 541 | tmp &= ~(P2C_RG_XCVRSEL | P2C_RG_DATAIN); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 542 | writel(tmp, com + U3P_U2PHYDTM0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 543 | |
| 544 | /* OTG Disable */ |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 545 | tmp = readl(com + U3P_USBPHYACR6); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 546 | tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 547 | writel(tmp, com + U3P_USBPHYACR6); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 548 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 549 | tmp = readl(com + U3P_U2PHYDTM1); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 550 | tmp &= ~(P2C_RG_VBUSVALID | P2C_RG_AVALID); |
| 551 | tmp |= P2C_RG_SESSEND; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 552 | writel(tmp, com + U3P_U2PHYDTM1); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 553 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 554 | if (tphy->pdata->avoid_rx_sen_degradation && index) { |
Chunfeng Yun | 00c0092 | 2017-12-07 19:53:34 +0800 | [diff] [blame] | 555 | tmp = readl(com + U3P_U2PHYDTM0); |
| 556 | tmp &= ~(P2C_RG_SUSPENDM | P2C_FORCE_SUSPENDM); |
| 557 | writel(tmp, com + U3P_U2PHYDTM0); |
| 558 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 559 | tmp = readl(com + U3D_U2PHYDCR0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 560 | tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 561 | writel(tmp, com + U3D_U2PHYDCR0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 562 | } |
| 563 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 564 | dev_dbg(tphy->dev, "%s(%d)\n", __func__, index); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 565 | } |
| 566 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 567 | static void u2_phy_instance_exit(struct mtk_tphy *tphy, |
| 568 | struct mtk_phy_instance *instance) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 569 | { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 570 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 571 | void __iomem *com = u2_banks->com; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 572 | u32 index = instance->index; |
| 573 | u32 tmp; |
| 574 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 575 | if (tphy->pdata->avoid_rx_sen_degradation && index) { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 576 | tmp = readl(com + U3D_U2PHYDCR0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 577 | tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 578 | writel(tmp, com + U3D_U2PHYDCR0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 579 | |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 580 | tmp = readl(com + U3P_U2PHYDTM0); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 581 | tmp &= ~P2C_FORCE_SUSPENDM; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 582 | writel(tmp, com + U3P_U2PHYDTM0); |
| 583 | } |
| 584 | } |
| 585 | |
Chunfeng Yun | 5954a10 | 2017-09-21 18:31:49 +0800 | [diff] [blame] | 586 | static void u2_phy_instance_set_mode(struct mtk_tphy *tphy, |
| 587 | struct mtk_phy_instance *instance, |
| 588 | enum phy_mode mode) |
| 589 | { |
| 590 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 591 | u32 tmp; |
| 592 | |
| 593 | tmp = readl(u2_banks->com + U3P_U2PHYDTM1); |
| 594 | switch (mode) { |
| 595 | case PHY_MODE_USB_DEVICE: |
| 596 | tmp |= P2C_FORCE_IDDIG | P2C_RG_IDDIG; |
| 597 | break; |
| 598 | case PHY_MODE_USB_HOST: |
| 599 | tmp |= P2C_FORCE_IDDIG; |
| 600 | tmp &= ~P2C_RG_IDDIG; |
| 601 | break; |
| 602 | case PHY_MODE_USB_OTG: |
| 603 | tmp &= ~(P2C_FORCE_IDDIG | P2C_RG_IDDIG); |
| 604 | break; |
| 605 | default: |
| 606 | return; |
| 607 | } |
| 608 | writel(tmp, u2_banks->com + U3P_U2PHYDTM1); |
| 609 | } |
| 610 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 611 | static void pcie_phy_instance_init(struct mtk_tphy *tphy, |
| 612 | struct mtk_phy_instance *instance) |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 613 | { |
| 614 | struct u3phy_banks *u3_banks = &instance->u3_banks; |
| 615 | u32 tmp; |
| 616 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 617 | if (tphy->pdata->version != MTK_PHY_V1) |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 618 | return; |
| 619 | |
| 620 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG0); |
| 621 | tmp &= ~(P3A_RG_XTAL_EXT_PE1H | P3A_RG_XTAL_EXT_PE2H); |
| 622 | tmp |= P3A_RG_XTAL_EXT_PE1H_VAL(0x2) | P3A_RG_XTAL_EXT_PE2H_VAL(0x2); |
| 623 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG0); |
| 624 | |
| 625 | /* ref clk drive */ |
| 626 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_REG1); |
| 627 | tmp &= ~P3A_RG_CLKDRV_AMP; |
| 628 | tmp |= P3A_RG_CLKDRV_AMP_VAL(0x4); |
| 629 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_REG1); |
| 630 | |
| 631 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_REG0); |
| 632 | tmp &= ~P3A_RG_CLKDRV_OFF; |
| 633 | tmp |= P3A_RG_CLKDRV_OFF_VAL(0x1); |
| 634 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_REG0); |
| 635 | |
| 636 | /* SSC delta -5000ppm */ |
| 637 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG20); |
| 638 | tmp &= ~P3A_RG_PLL_DELTA1_PE2H; |
| 639 | tmp |= P3A_RG_PLL_DELTA1_PE2H_VAL(0x3c); |
| 640 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG20); |
| 641 | |
| 642 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG25); |
| 643 | tmp &= ~P3A_RG_PLL_DELTA_PE2H; |
| 644 | tmp |= P3A_RG_PLL_DELTA_PE2H_VAL(0x36); |
| 645 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG25); |
| 646 | |
| 647 | /* change pll BW 0.6M */ |
| 648 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG5); |
| 649 | tmp &= ~(P3A_RG_PLL_BR_PE2H | P3A_RG_PLL_IC_PE2H); |
| 650 | tmp |= P3A_RG_PLL_BR_PE2H_VAL(0x1) | P3A_RG_PLL_IC_PE2H_VAL(0x1); |
| 651 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG5); |
| 652 | |
| 653 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG4); |
| 654 | tmp &= ~(P3A_RG_PLL_DIVEN_PE2H | P3A_RG_PLL_BC_PE2H); |
| 655 | tmp |= P3A_RG_PLL_BC_PE2H_VAL(0x3); |
| 656 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG4); |
| 657 | |
| 658 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG6); |
| 659 | tmp &= ~P3A_RG_PLL_IR_PE2H; |
| 660 | tmp |= P3A_RG_PLL_IR_PE2H_VAL(0x2); |
| 661 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG6); |
| 662 | |
| 663 | tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG7); |
| 664 | tmp &= ~P3A_RG_PLL_BP_PE2H; |
| 665 | tmp |= P3A_RG_PLL_BP_PE2H_VAL(0xa); |
| 666 | writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG7); |
| 667 | |
| 668 | /* Tx Detect Rx Timing: 10us -> 5us */ |
| 669 | tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RXDET1); |
| 670 | tmp &= ~P3D_RG_RXDET_STB2_SET; |
| 671 | tmp |= P3D_RG_RXDET_STB2_SET_VAL(0x10); |
| 672 | writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET1); |
| 673 | |
| 674 | tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RXDET2); |
| 675 | tmp &= ~P3D_RG_RXDET_STB2_SET_P3; |
| 676 | tmp |= P3D_RG_RXDET_STB2_SET_P3_VAL(0x10); |
| 677 | writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET2); |
| 678 | |
| 679 | /* wait for PCIe subsys register to active */ |
| 680 | usleep_range(2500, 3000); |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 681 | dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 682 | } |
| 683 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 684 | static void pcie_phy_instance_power_on(struct mtk_tphy *tphy, |
| 685 | struct mtk_phy_instance *instance) |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 686 | { |
| 687 | struct u3phy_banks *bank = &instance->u3_banks; |
| 688 | u32 tmp; |
| 689 | |
| 690 | tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLD); |
Chunfeng Yun | 4036325 | 2018-03-12 13:25:38 +0800 | [diff] [blame^] | 691 | tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_REG_IP_SW_RST); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 692 | writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLD); |
| 693 | |
| 694 | tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLE); |
| 695 | tmp &= ~(P3C_RG_SWRST_U3_PHYD_FORCE_EN | P3C_RG_SWRST_U3_PHYD); |
| 696 | writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLE); |
| 697 | } |
| 698 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 699 | static void pcie_phy_instance_power_off(struct mtk_tphy *tphy, |
| 700 | struct mtk_phy_instance *instance) |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 701 | |
| 702 | { |
| 703 | struct u3phy_banks *bank = &instance->u3_banks; |
| 704 | u32 tmp; |
| 705 | |
| 706 | tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLD); |
| 707 | tmp |= P3C_FORCE_IP_SW_RST | P3C_REG_IP_SW_RST; |
| 708 | writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLD); |
| 709 | |
| 710 | tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLE); |
| 711 | tmp |= P3C_RG_SWRST_U3_PHYD_FORCE_EN | P3C_RG_SWRST_U3_PHYD; |
| 712 | writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLE); |
| 713 | } |
| 714 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 715 | static void sata_phy_instance_init(struct mtk_tphy *tphy, |
| 716 | struct mtk_phy_instance *instance) |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 717 | { |
| 718 | struct u3phy_banks *u3_banks = &instance->u3_banks; |
| 719 | void __iomem *phyd = u3_banks->phyd; |
| 720 | u32 tmp; |
| 721 | |
| 722 | /* charge current adjustment */ |
| 723 | tmp = readl(phyd + ANA_RG_CTRL_SIGNAL6); |
| 724 | tmp &= ~(RG_CDR_BIRLTR_GEN1_MSK | RG_CDR_BC_GEN1_MSK); |
| 725 | tmp |= RG_CDR_BIRLTR_GEN1_VAL(0x6) | RG_CDR_BC_GEN1_VAL(0x1a); |
| 726 | writel(tmp, phyd + ANA_RG_CTRL_SIGNAL6); |
| 727 | |
| 728 | tmp = readl(phyd + ANA_EQ_EYE_CTRL_SIGNAL4); |
| 729 | tmp &= ~RG_CDR_BIRLTD0_GEN1_MSK; |
| 730 | tmp |= RG_CDR_BIRLTD0_GEN1_VAL(0x18); |
| 731 | writel(tmp, phyd + ANA_EQ_EYE_CTRL_SIGNAL4); |
| 732 | |
| 733 | tmp = readl(phyd + ANA_EQ_EYE_CTRL_SIGNAL5); |
| 734 | tmp &= ~RG_CDR_BIRLTD0_GEN3_MSK; |
| 735 | tmp |= RG_CDR_BIRLTD0_GEN3_VAL(0x06); |
| 736 | writel(tmp, phyd + ANA_EQ_EYE_CTRL_SIGNAL5); |
| 737 | |
| 738 | tmp = readl(phyd + ANA_RG_CTRL_SIGNAL4); |
| 739 | tmp &= ~(RG_CDR_BICLTR_GEN1_MSK | RG_CDR_BR_GEN2_MSK); |
| 740 | tmp |= RG_CDR_BICLTR_GEN1_VAL(0x0c) | RG_CDR_BR_GEN2_VAL(0x07); |
| 741 | writel(tmp, phyd + ANA_RG_CTRL_SIGNAL4); |
| 742 | |
| 743 | tmp = readl(phyd + PHYD_CTRL_SIGNAL_MODE4); |
| 744 | tmp &= ~(RG_CDR_BICLTD0_GEN1_MSK | RG_CDR_BICLTD1_GEN1_MSK); |
| 745 | tmp |= RG_CDR_BICLTD0_GEN1_VAL(0x08) | RG_CDR_BICLTD1_GEN1_VAL(0x02); |
| 746 | writel(tmp, phyd + PHYD_CTRL_SIGNAL_MODE4); |
| 747 | |
| 748 | tmp = readl(phyd + PHYD_DESIGN_OPTION2); |
| 749 | tmp &= ~RG_LOCK_CNT_SEL_MSK; |
| 750 | tmp |= RG_LOCK_CNT_SEL_VAL(0x02); |
| 751 | writel(tmp, phyd + PHYD_DESIGN_OPTION2); |
| 752 | |
| 753 | tmp = readl(phyd + PHYD_DESIGN_OPTION9); |
| 754 | tmp &= ~(RG_T2_MIN_MSK | RG_TG_MIN_MSK | |
| 755 | RG_T2_MAX_MSK | RG_TG_MAX_MSK); |
| 756 | tmp |= RG_T2_MIN_VAL(0x12) | RG_TG_MIN_VAL(0x04) | |
| 757 | RG_T2_MAX_VAL(0x31) | RG_TG_MAX_VAL(0x0e); |
| 758 | writel(tmp, phyd + PHYD_DESIGN_OPTION9); |
| 759 | |
| 760 | tmp = readl(phyd + ANA_RG_CTRL_SIGNAL1); |
| 761 | tmp &= ~RG_IDRV_0DB_GEN1_MSK; |
| 762 | tmp |= RG_IDRV_0DB_GEN1_VAL(0x20); |
| 763 | writel(tmp, phyd + ANA_RG_CTRL_SIGNAL1); |
| 764 | |
| 765 | tmp = readl(phyd + ANA_EQ_EYE_CTRL_SIGNAL1); |
| 766 | tmp &= ~RG_EQ_DLEQ_LFI_GEN1_MSK; |
| 767 | tmp |= RG_EQ_DLEQ_LFI_GEN1_VAL(0x03); |
| 768 | writel(tmp, phyd + ANA_EQ_EYE_CTRL_SIGNAL1); |
| 769 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 770 | dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index); |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 771 | } |
| 772 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 773 | static void phy_v1_banks_init(struct mtk_tphy *tphy, |
| 774 | struct mtk_phy_instance *instance) |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 775 | { |
| 776 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 777 | struct u3phy_banks *u3_banks = &instance->u3_banks; |
| 778 | |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 779 | switch (instance->type) { |
| 780 | case PHY_TYPE_USB2: |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 781 | u2_banks->misc = NULL; |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 782 | u2_banks->fmreg = tphy->sif_base + SSUSB_SIFSLV_V1_U2FREQ; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 783 | u2_banks->com = instance->port_base + SSUSB_SIFSLV_V1_U2PHY_COM; |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 784 | break; |
| 785 | case PHY_TYPE_USB3: |
| 786 | case PHY_TYPE_PCIE: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 787 | u3_banks->spllc = tphy->sif_base + SSUSB_SIFSLV_V1_SPLLC; |
Chunfeng Yun | 554a56f | 2017-09-21 18:31:48 +0800 | [diff] [blame] | 788 | u3_banks->chip = tphy->sif_base + SSUSB_SIFSLV_V1_CHIP; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 789 | u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V1_U3PHYD; |
| 790 | u3_banks->phya = instance->port_base + SSUSB_SIFSLV_V1_U3PHYA; |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 791 | break; |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 792 | case PHY_TYPE_SATA: |
| 793 | u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V1_U3PHYD; |
| 794 | break; |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 795 | default: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 796 | dev_err(tphy->dev, "incompatible PHY type\n"); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 797 | return; |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 801 | static void phy_v2_banks_init(struct mtk_tphy *tphy, |
| 802 | struct mtk_phy_instance *instance) |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 803 | { |
| 804 | struct u2phy_banks *u2_banks = &instance->u2_banks; |
| 805 | struct u3phy_banks *u3_banks = &instance->u3_banks; |
| 806 | |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 807 | switch (instance->type) { |
| 808 | case PHY_TYPE_USB2: |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 809 | u2_banks->misc = instance->port_base + SSUSB_SIFSLV_V2_MISC; |
| 810 | u2_banks->fmreg = instance->port_base + SSUSB_SIFSLV_V2_U2FREQ; |
| 811 | u2_banks->com = instance->port_base + SSUSB_SIFSLV_V2_U2PHY_COM; |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 812 | break; |
| 813 | case PHY_TYPE_USB3: |
| 814 | case PHY_TYPE_PCIE: |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 815 | u3_banks->spllc = instance->port_base + SSUSB_SIFSLV_V2_SPLLC; |
| 816 | u3_banks->chip = instance->port_base + SSUSB_SIFSLV_V2_CHIP; |
| 817 | u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V2_U3PHYD; |
| 818 | u3_banks->phya = instance->port_base + SSUSB_SIFSLV_V2_U3PHYA; |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 819 | break; |
| 820 | default: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 821 | dev_err(tphy->dev, "incompatible PHY type\n"); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 822 | return; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 826 | static int mtk_phy_init(struct phy *phy) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 827 | { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 828 | struct mtk_phy_instance *instance = phy_get_drvdata(phy); |
| 829 | struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 830 | int ret; |
| 831 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 832 | ret = clk_prepare_enable(tphy->u3phya_ref); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 833 | if (ret) { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 834 | dev_err(tphy->dev, "failed to enable u3phya_ref\n"); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 835 | return ret; |
| 836 | } |
| 837 | |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 838 | ret = clk_prepare_enable(instance->ref_clk); |
| 839 | if (ret) { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 840 | dev_err(tphy->dev, "failed to enable ref_clk\n"); |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 841 | return ret; |
| 842 | } |
| 843 | |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 844 | switch (instance->type) { |
| 845 | case PHY_TYPE_USB2: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 846 | u2_phy_instance_init(tphy, instance); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 847 | break; |
| 848 | case PHY_TYPE_USB3: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 849 | u3_phy_instance_init(tphy, instance); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 850 | break; |
| 851 | case PHY_TYPE_PCIE: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 852 | pcie_phy_instance_init(tphy, instance); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 853 | break; |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 854 | case PHY_TYPE_SATA: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 855 | sata_phy_instance_init(tphy, instance); |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 856 | break; |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 857 | default: |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 858 | dev_err(tphy->dev, "incompatible PHY type\n"); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 859 | return -EINVAL; |
| 860 | } |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 861 | |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 862 | return 0; |
| 863 | } |
| 864 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 865 | static int mtk_phy_power_on(struct phy *phy) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 866 | { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 867 | struct mtk_phy_instance *instance = phy_get_drvdata(phy); |
| 868 | struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 869 | |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 870 | if (instance->type == PHY_TYPE_USB2) { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 871 | u2_phy_instance_power_on(tphy, instance); |
| 872 | hs_slew_rate_calibrate(tphy, instance); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 873 | } else if (instance->type == PHY_TYPE_PCIE) { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 874 | pcie_phy_instance_power_on(tphy, instance); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 875 | } |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 876 | |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 877 | return 0; |
| 878 | } |
| 879 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 880 | static int mtk_phy_power_off(struct phy *phy) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 881 | { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 882 | struct mtk_phy_instance *instance = phy_get_drvdata(phy); |
| 883 | struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 884 | |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 885 | if (instance->type == PHY_TYPE_USB2) |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 886 | u2_phy_instance_power_off(tphy, instance); |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 887 | else if (instance->type == PHY_TYPE_PCIE) |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 888 | pcie_phy_instance_power_off(tphy, instance); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 889 | |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 890 | return 0; |
| 891 | } |
| 892 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 893 | static int mtk_phy_exit(struct phy *phy) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 894 | { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 895 | struct mtk_phy_instance *instance = phy_get_drvdata(phy); |
| 896 | struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 897 | |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 898 | if (instance->type == PHY_TYPE_USB2) |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 899 | u2_phy_instance_exit(tphy, instance); |
Chunfeng Yun | 04466ef | 2017-03-31 15:35:29 +0800 | [diff] [blame] | 900 | |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 901 | clk_disable_unprepare(instance->ref_clk); |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 902 | clk_disable_unprepare(tphy->u3phya_ref); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 903 | return 0; |
| 904 | } |
| 905 | |
Chunfeng Yun | 5954a10 | 2017-09-21 18:31:49 +0800 | [diff] [blame] | 906 | static int mtk_phy_set_mode(struct phy *phy, enum phy_mode mode) |
| 907 | { |
| 908 | struct mtk_phy_instance *instance = phy_get_drvdata(phy); |
| 909 | struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent); |
| 910 | |
| 911 | if (instance->type == PHY_TYPE_USB2) |
| 912 | u2_phy_instance_set_mode(tphy, instance, mode); |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 917 | static struct phy *mtk_phy_xlate(struct device *dev, |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 918 | struct of_phandle_args *args) |
| 919 | { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 920 | struct mtk_tphy *tphy = dev_get_drvdata(dev); |
| 921 | struct mtk_phy_instance *instance = NULL; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 922 | struct device_node *phy_np = args->np; |
| 923 | int index; |
| 924 | |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 925 | if (args->args_count != 1) { |
| 926 | dev_err(dev, "invalid number of cells in 'phy' property\n"); |
| 927 | return ERR_PTR(-EINVAL); |
| 928 | } |
| 929 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 930 | for (index = 0; index < tphy->nphys; index++) |
| 931 | if (phy_np == tphy->phys[index]->phy->dev.of_node) { |
| 932 | instance = tphy->phys[index]; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 933 | break; |
| 934 | } |
| 935 | |
| 936 | if (!instance) { |
| 937 | dev_err(dev, "failed to find appropriate phy\n"); |
| 938 | return ERR_PTR(-EINVAL); |
| 939 | } |
| 940 | |
| 941 | instance->type = args->args[0]; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 942 | if (!(instance->type == PHY_TYPE_USB2 || |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 943 | instance->type == PHY_TYPE_USB3 || |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 944 | instance->type == PHY_TYPE_PCIE || |
| 945 | instance->type == PHY_TYPE_SATA)) { |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 946 | dev_err(dev, "unsupported device type: %d\n", instance->type); |
| 947 | return ERR_PTR(-EINVAL); |
| 948 | } |
| 949 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 950 | if (tphy->pdata->version == MTK_PHY_V1) { |
| 951 | phy_v1_banks_init(tphy, instance); |
| 952 | } else if (tphy->pdata->version == MTK_PHY_V2) { |
| 953 | phy_v2_banks_init(tphy, instance); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 954 | } else { |
| 955 | dev_err(dev, "phy version is not supported\n"); |
| 956 | return ERR_PTR(-EINVAL); |
| 957 | } |
| 958 | |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 959 | return instance->phy; |
| 960 | } |
| 961 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 962 | static const struct phy_ops mtk_tphy_ops = { |
| 963 | .init = mtk_phy_init, |
| 964 | .exit = mtk_phy_exit, |
| 965 | .power_on = mtk_phy_power_on, |
| 966 | .power_off = mtk_phy_power_off, |
Chunfeng Yun | 5954a10 | 2017-09-21 18:31:49 +0800 | [diff] [blame] | 967 | .set_mode = mtk_phy_set_mode, |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 968 | .owner = THIS_MODULE, |
| 969 | }; |
| 970 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 971 | static const struct mtk_phy_pdata tphy_v1_pdata = { |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 972 | .avoid_rx_sen_degradation = false, |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 973 | .version = MTK_PHY_V1, |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 974 | }; |
| 975 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 976 | static const struct mtk_phy_pdata tphy_v2_pdata = { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 977 | .avoid_rx_sen_degradation = false, |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 978 | .version = MTK_PHY_V2, |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 979 | }; |
| 980 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 981 | static const struct mtk_phy_pdata mt8173_pdata = { |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 982 | .avoid_rx_sen_degradation = true, |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 983 | .version = MTK_PHY_V1, |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 984 | }; |
| 985 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 986 | static const struct of_device_id mtk_tphy_id_table[] = { |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 987 | { .compatible = "mediatek,mt2701-u3phy", .data = &tphy_v1_pdata }, |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 988 | { .compatible = "mediatek,mt2712-u3phy", .data = &tphy_v2_pdata }, |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 989 | { .compatible = "mediatek,mt8173-u3phy", .data = &mt8173_pdata }, |
Ryder Lee | 44a6d6c | 2017-08-03 18:01:00 +0800 | [diff] [blame] | 990 | { .compatible = "mediatek,generic-tphy-v1", .data = &tphy_v1_pdata }, |
Ryder Lee | 4ab26cb | 2017-08-03 18:01:01 +0800 | [diff] [blame] | 991 | { .compatible = "mediatek,generic-tphy-v2", .data = &tphy_v2_pdata }, |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 992 | { }, |
| 993 | }; |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 994 | MODULE_DEVICE_TABLE(of, mtk_tphy_id_table); |
Chunfeng Yun | e1d7653 | 2016-04-20 08:14:02 +0800 | [diff] [blame] | 995 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 996 | static int mtk_tphy_probe(struct platform_device *pdev) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 997 | { |
| 998 | struct device *dev = &pdev->dev; |
| 999 | struct device_node *np = dev->of_node; |
| 1000 | struct device_node *child_np; |
| 1001 | struct phy_provider *provider; |
| 1002 | struct resource *sif_res; |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1003 | struct mtk_tphy *tphy; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1004 | struct resource res; |
Julia Lawall | 2bb80cc | 2015-11-16 12:33:15 +0100 | [diff] [blame] | 1005 | int port, retval; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1006 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1007 | tphy = devm_kzalloc(dev, sizeof(*tphy), GFP_KERNEL); |
| 1008 | if (!tphy) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1009 | return -ENOMEM; |
| 1010 | |
Chunfeng Yun | e4b227c | 2017-12-28 16:40:36 +0530 | [diff] [blame] | 1011 | tphy->pdata = of_device_get_match_data(dev); |
| 1012 | if (!tphy->pdata) |
| 1013 | return -EINVAL; |
| 1014 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1015 | tphy->nphys = of_get_child_count(np); |
| 1016 | tphy->phys = devm_kcalloc(dev, tphy->nphys, |
| 1017 | sizeof(*tphy->phys), GFP_KERNEL); |
| 1018 | if (!tphy->phys) |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1019 | return -ENOMEM; |
| 1020 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1021 | tphy->dev = dev; |
| 1022 | platform_set_drvdata(pdev, tphy); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1023 | |
Chunfeng Yun | 93a04f4 | 2017-12-07 19:53:35 +0800 | [diff] [blame] | 1024 | sif_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1025 | /* SATA phy of V1 needn't it if not shared with PCIe or USB */ |
| 1026 | if (sif_res && tphy->pdata->version == MTK_PHY_V1) { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 1027 | /* get banks shared by multiple phys */ |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1028 | tphy->sif_base = devm_ioremap_resource(dev, sif_res); |
| 1029 | if (IS_ERR(tphy->sif_base)) { |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 1030 | dev_err(dev, "failed to remap sif regs\n"); |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1031 | return PTR_ERR(tphy->sif_base); |
Chunfeng Yun | 8d6e1957 | 2017-03-31 15:35:31 +0800 | [diff] [blame] | 1032 | } |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1033 | } |
| 1034 | |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 1035 | /* it's deprecated, make it optional for backward compatibility */ |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1036 | tphy->u3phya_ref = devm_clk_get(dev, "u3phya_ref"); |
| 1037 | if (IS_ERR(tphy->u3phya_ref)) { |
| 1038 | if (PTR_ERR(tphy->u3phya_ref) == -EPROBE_DEFER) |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 1039 | return -EPROBE_DEFER; |
| 1040 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1041 | tphy->u3phya_ref = NULL; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | port = 0; |
| 1045 | for_each_child_of_node(np, child_np) { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1046 | struct mtk_phy_instance *instance; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1047 | struct phy *phy; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1048 | |
| 1049 | instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL); |
Julia Lawall | 2bb80cc | 2015-11-16 12:33:15 +0100 | [diff] [blame] | 1050 | if (!instance) { |
| 1051 | retval = -ENOMEM; |
| 1052 | goto put_child; |
| 1053 | } |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1054 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1055 | tphy->phys[port] = instance; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1056 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1057 | phy = devm_phy_create(dev, child_np, &mtk_tphy_ops); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1058 | if (IS_ERR(phy)) { |
| 1059 | dev_err(dev, "failed to create phy\n"); |
Julia Lawall | 2bb80cc | 2015-11-16 12:33:15 +0100 | [diff] [blame] | 1060 | retval = PTR_ERR(phy); |
| 1061 | goto put_child; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | retval = of_address_to_resource(child_np, 0, &res); |
| 1065 | if (retval) { |
| 1066 | dev_err(dev, "failed to get address resource(id-%d)\n", |
| 1067 | port); |
Julia Lawall | 2bb80cc | 2015-11-16 12:33:15 +0100 | [diff] [blame] | 1068 | goto put_child; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | instance->port_base = devm_ioremap_resource(&phy->dev, &res); |
| 1072 | if (IS_ERR(instance->port_base)) { |
| 1073 | dev_err(dev, "failed to remap phy regs\n"); |
Julia Lawall | 2bb80cc | 2015-11-16 12:33:15 +0100 | [diff] [blame] | 1074 | retval = PTR_ERR(instance->port_base); |
| 1075 | goto put_child; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | instance->phy = phy; |
| 1079 | instance->index = port; |
| 1080 | phy_set_drvdata(phy, instance); |
| 1081 | port++; |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 1082 | |
| 1083 | /* if deprecated clock is provided, ignore instance's one */ |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1084 | if (tphy->u3phya_ref) |
Chunfeng Yun | 15de15c | 2017-03-31 15:35:30 +0800 | [diff] [blame] | 1085 | continue; |
| 1086 | |
| 1087 | instance->ref_clk = devm_clk_get(&phy->dev, "ref"); |
| 1088 | if (IS_ERR(instance->ref_clk)) { |
| 1089 | dev_err(dev, "failed to get ref_clk(id-%d)\n", port); |
| 1090 | retval = PTR_ERR(instance->ref_clk); |
| 1091 | goto put_child; |
| 1092 | } |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1093 | } |
| 1094 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1095 | provider = devm_of_phy_provider_register(dev, mtk_phy_xlate); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1096 | |
| 1097 | return PTR_ERR_OR_ZERO(provider); |
Julia Lawall | 2bb80cc | 2015-11-16 12:33:15 +0100 | [diff] [blame] | 1098 | put_child: |
| 1099 | of_node_put(child_np); |
| 1100 | return retval; |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1103 | static struct platform_driver mtk_tphy_driver = { |
| 1104 | .probe = mtk_tphy_probe, |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1105 | .driver = { |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1106 | .name = "mtk-tphy", |
| 1107 | .of_match_table = mtk_tphy_id_table, |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1108 | }, |
| 1109 | }; |
| 1110 | |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1111 | module_platform_driver(mtk_tphy_driver); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1112 | |
| 1113 | MODULE_AUTHOR("Chunfeng Yun <chunfeng.yun@mediatek.com>"); |
Chunfeng Yun | cd4ec4b | 2017-08-03 18:01:02 +0800 | [diff] [blame] | 1114 | MODULE_DESCRIPTION("MediaTek T-PHY driver"); |
Chunfeng Yun | dc7f190 | 2015-09-29 11:01:36 +0800 | [diff] [blame] | 1115 | MODULE_LICENSE("GPL v2"); |