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