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