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