116df8bcbSNeil Armstrong // SPDX-License-Identifier: GPL-2.0 216df8bcbSNeil Armstrong /* 316df8bcbSNeil Armstrong * Meson G12A USB2 PHY driver 416df8bcbSNeil Armstrong * 516df8bcbSNeil Armstrong * Copyright (C) 2017 Martin Blumenstingl <martin.blumenstingl@googlemail.com> 616df8bcbSNeil Armstrong * Copyright (C) 2017 Amlogic, Inc. All rights reserved 716df8bcbSNeil Armstrong * Copyright (C) 2019 BayLibre, SAS 816df8bcbSNeil Armstrong * Author: Neil Armstrong <narmstrong@baylibre.com> 916df8bcbSNeil Armstrong */ 1016df8bcbSNeil Armstrong 1116df8bcbSNeil Armstrong #include <linux/bitfield.h> 1216df8bcbSNeil Armstrong #include <linux/bitops.h> 1316df8bcbSNeil Armstrong #include <linux/clk.h> 1416df8bcbSNeil Armstrong #include <linux/delay.h> 1516df8bcbSNeil Armstrong #include <linux/io.h> 1616df8bcbSNeil Armstrong #include <linux/module.h> 1716df8bcbSNeil Armstrong #include <linux/of_device.h> 1816df8bcbSNeil Armstrong #include <linux/regmap.h> 1916df8bcbSNeil Armstrong #include <linux/reset.h> 2016df8bcbSNeil Armstrong #include <linux/phy/phy.h> 2116df8bcbSNeil Armstrong #include <linux/platform_device.h> 2216df8bcbSNeil Armstrong 2316df8bcbSNeil Armstrong #define PHY_CTRL_R0 0x0 2416df8bcbSNeil Armstrong #define PHY_CTRL_R1 0x4 2516df8bcbSNeil Armstrong #define PHY_CTRL_R2 0x8 2616df8bcbSNeil Armstrong #define PHY_CTRL_R3 0xc 2716df8bcbSNeil Armstrong #define PHY_CTRL_R3_SQUELCH_REF GENMASK(1, 0) 2816df8bcbSNeil Armstrong #define PHY_CTRL_R3_HSDIC_REF GENMASK(3, 2) 2916df8bcbSNeil Armstrong #define PHY_CTRL_R3_DISC_THRESH GENMASK(7, 4) 3016df8bcbSNeil Armstrong 3116df8bcbSNeil Armstrong #define PHY_CTRL_R4 0x10 3216df8bcbSNeil Armstrong #define PHY_CTRL_R4_CALIB_CODE_7_0 GENMASK(7, 0) 3316df8bcbSNeil Armstrong #define PHY_CTRL_R4_CALIB_CODE_15_8 GENMASK(15, 8) 3416df8bcbSNeil Armstrong #define PHY_CTRL_R4_CALIB_CODE_23_16 GENMASK(23, 16) 3516df8bcbSNeil Armstrong #define PHY_CTRL_R4_I_C2L_CAL_EN BIT(24) 3616df8bcbSNeil Armstrong #define PHY_CTRL_R4_I_C2L_CAL_RESET_N BIT(25) 3716df8bcbSNeil Armstrong #define PHY_CTRL_R4_I_C2L_CAL_DONE BIT(26) 3816df8bcbSNeil Armstrong #define PHY_CTRL_R4_TEST_BYPASS_MODE_EN BIT(27) 3916df8bcbSNeil Armstrong #define PHY_CTRL_R4_I_C2L_BIAS_TRIM_1_0 GENMASK(29, 28) 4016df8bcbSNeil Armstrong #define PHY_CTRL_R4_I_C2L_BIAS_TRIM_3_2 GENMASK(31, 30) 4116df8bcbSNeil Armstrong 4216df8bcbSNeil Armstrong #define PHY_CTRL_R5 0x14 4316df8bcbSNeil Armstrong #define PHY_CTRL_R6 0x18 4416df8bcbSNeil Armstrong #define PHY_CTRL_R7 0x1c 4516df8bcbSNeil Armstrong #define PHY_CTRL_R8 0x20 4616df8bcbSNeil Armstrong #define PHY_CTRL_R9 0x24 4716df8bcbSNeil Armstrong #define PHY_CTRL_R10 0x28 4816df8bcbSNeil Armstrong #define PHY_CTRL_R11 0x2c 4916df8bcbSNeil Armstrong #define PHY_CTRL_R12 0x30 5016df8bcbSNeil Armstrong #define PHY_CTRL_R13 0x34 5116df8bcbSNeil Armstrong #define PHY_CTRL_R13_CUSTOM_PATTERN_19 GENMASK(7, 0) 5216df8bcbSNeil Armstrong #define PHY_CTRL_R13_LOAD_STAT BIT(14) 5316df8bcbSNeil Armstrong #define PHY_CTRL_R13_UPDATE_PMA_SIGNALS BIT(15) 5416df8bcbSNeil Armstrong #define PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET GENMASK(20, 16) 5516df8bcbSNeil Armstrong #define PHY_CTRL_R13_CLEAR_HOLD_HS_DISCONNECT BIT(21) 5616df8bcbSNeil Armstrong #define PHY_CTRL_R13_BYPASS_HOST_DISCONNECT_VAL BIT(22) 5716df8bcbSNeil Armstrong #define PHY_CTRL_R13_BYPASS_HOST_DISCONNECT_EN BIT(23) 5816df8bcbSNeil Armstrong #define PHY_CTRL_R13_I_C2L_HS_EN BIT(24) 5916df8bcbSNeil Armstrong #define PHY_CTRL_R13_I_C2L_FS_EN BIT(25) 6016df8bcbSNeil Armstrong #define PHY_CTRL_R13_I_C2L_LS_EN BIT(26) 6116df8bcbSNeil Armstrong #define PHY_CTRL_R13_I_C2L_HS_OE BIT(27) 6216df8bcbSNeil Armstrong #define PHY_CTRL_R13_I_C2L_FS_OE BIT(28) 6316df8bcbSNeil Armstrong #define PHY_CTRL_R13_I_C2L_HS_RX_EN BIT(29) 6416df8bcbSNeil Armstrong #define PHY_CTRL_R13_I_C2L_FSLS_RX_EN BIT(30) 6516df8bcbSNeil Armstrong 6616df8bcbSNeil Armstrong #define PHY_CTRL_R14 0x38 6716df8bcbSNeil Armstrong #define PHY_CTRL_R14_I_RDP_EN BIT(0) 6816df8bcbSNeil Armstrong #define PHY_CTRL_R14_I_RPU_SW1_EN BIT(1) 69014b35d9SJoe Perches #define PHY_CTRL_R14_I_RPU_SW2_EN GENMASK(3, 2) 7016df8bcbSNeil Armstrong #define PHY_CTRL_R14_PG_RSTN BIT(4) 7116df8bcbSNeil Armstrong #define PHY_CTRL_R14_I_C2L_DATA_16_8 BIT(5) 7216df8bcbSNeil Armstrong #define PHY_CTRL_R14_I_C2L_ASSERT_SINGLE_EN_ZERO BIT(6) 7316df8bcbSNeil Armstrong #define PHY_CTRL_R14_BYPASS_CTRL_7_0 GENMASK(15, 8) 7416df8bcbSNeil Armstrong #define PHY_CTRL_R14_BYPASS_CTRL_15_8 GENMASK(23, 16) 7516df8bcbSNeil Armstrong 7616df8bcbSNeil Armstrong #define PHY_CTRL_R15 0x3c 7716df8bcbSNeil Armstrong #define PHY_CTRL_R16 0x40 7816df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_M GENMASK(8, 0) 7916df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_N GENMASK(14, 10) 8016df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_TDC_MODE BIT(20) 8116df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_SDM_EN BIT(21) 8216df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_LOAD BIT(22) 8316df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_DCO_SDM_EN BIT(23) 8416df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_LOCK_LONG GENMASK(25, 24) 8516df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_LOCK_F BIT(26) 8616df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_FAST_LOCK BIT(27) 8716df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_EN BIT(28) 8816df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_RESET BIT(29) 8916df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_LOCK BIT(30) 9016df8bcbSNeil Armstrong #define PHY_CTRL_R16_MPLL_LOCK_DIG BIT(31) 9116df8bcbSNeil Armstrong 9216df8bcbSNeil Armstrong #define PHY_CTRL_R17 0x44 9316df8bcbSNeil Armstrong #define PHY_CTRL_R17_MPLL_FRAC_IN GENMASK(13, 0) 9416df8bcbSNeil Armstrong #define PHY_CTRL_R17_MPLL_FIX_EN BIT(16) 9516df8bcbSNeil Armstrong #define PHY_CTRL_R17_MPLL_LAMBDA1 GENMASK(19, 17) 9616df8bcbSNeil Armstrong #define PHY_CTRL_R17_MPLL_LAMBDA0 GENMASK(22, 20) 9716df8bcbSNeil Armstrong #define PHY_CTRL_R17_MPLL_FILTER_MODE BIT(23) 9816df8bcbSNeil Armstrong #define PHY_CTRL_R17_MPLL_FILTER_PVT2 GENMASK(27, 24) 9916df8bcbSNeil Armstrong #define PHY_CTRL_R17_MPLL_FILTER_PVT1 GENMASK(31, 28) 10016df8bcbSNeil Armstrong 10116df8bcbSNeil Armstrong #define PHY_CTRL_R18 0x48 10216df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_LKW_SEL GENMASK(1, 0) 10316df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_LK_W GENMASK(5, 2) 10416df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_LK_S GENMASK(11, 6) 10516df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_DCO_M_EN BIT(12) 10616df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_DCO_CLK_SEL BIT(13) 10716df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_PFD_GAIN GENMASK(15, 14) 10816df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_ROU GENMASK(18, 16) 10916df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_DATA_SEL GENMASK(21, 19) 11016df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_BIAS_ADJ GENMASK(23, 22) 11116df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_BB_MODE GENMASK(25, 24) 11216df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_ALPHA GENMASK(28, 26) 11316df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_ADJ_LDO GENMASK(30, 29) 11416df8bcbSNeil Armstrong #define PHY_CTRL_R18_MPLL_ACG_RANGE BIT(31) 11516df8bcbSNeil Armstrong 11616df8bcbSNeil Armstrong #define PHY_CTRL_R19 0x4c 11716df8bcbSNeil Armstrong #define PHY_CTRL_R20 0x50 11816df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_IDDET_EN BIT(0) 11916df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_OTG_VBUS_TRIM_2_0 GENMASK(3, 1) 12016df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_OTG_VBUSDET_EN BIT(4) 12116df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_AMON_EN BIT(5) 12216df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_CAL_CODE_R5 BIT(6) 12316df8bcbSNeil Armstrong #define PHY_CTRL_R20_BYPASS_OTG_DET BIT(7) 12416df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_DMON_EN BIT(8) 12516df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_DMON_SEL_3_0 GENMASK(12, 9) 12616df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_EDGE_DRV_EN BIT(13) 12716df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0 GENMASK(15, 14) 12816df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_BGR_ADJ_4_0 GENMASK(20, 16) 12916df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_BGR_START BIT(21) 13016df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_BGR_VREF_4_0 GENMASK(28, 24) 13116df8bcbSNeil Armstrong #define PHY_CTRL_R20_USB2_BGR_DBG_1_0 GENMASK(30, 29) 13216df8bcbSNeil Armstrong #define PHY_CTRL_R20_BYPASS_CAL_DONE_R5 BIT(31) 13316df8bcbSNeil Armstrong 13416df8bcbSNeil Armstrong #define PHY_CTRL_R21 0x54 13516df8bcbSNeil Armstrong #define PHY_CTRL_R21_USB2_BGR_FORCE BIT(0) 13616df8bcbSNeil Armstrong #define PHY_CTRL_R21_USB2_CAL_ACK_EN BIT(1) 13716df8bcbSNeil Armstrong #define PHY_CTRL_R21_USB2_OTG_ACA_EN BIT(2) 13816df8bcbSNeil Armstrong #define PHY_CTRL_R21_USB2_TX_STRG_PD BIT(3) 13916df8bcbSNeil Armstrong #define PHY_CTRL_R21_USB2_OTG_ACA_TRIM_1_0 GENMASK(5, 4) 14016df8bcbSNeil Armstrong #define PHY_CTRL_R21_BYPASS_UTMI_CNTR GENMASK(15, 6) 14116df8bcbSNeil Armstrong #define PHY_CTRL_R21_BYPASS_UTMI_REG GENMASK(25, 20) 14216df8bcbSNeil Armstrong 14316df8bcbSNeil Armstrong #define PHY_CTRL_R22 0x58 14416df8bcbSNeil Armstrong #define PHY_CTRL_R23 0x5c 14516df8bcbSNeil Armstrong 14616df8bcbSNeil Armstrong #define RESET_COMPLETE_TIME 1000 14716df8bcbSNeil Armstrong #define PLL_RESET_COMPLETE_TIME 100 14816df8bcbSNeil Armstrong 14923bcbb41SHanjie Lin enum meson_soc_id { 15023bcbb41SHanjie Lin MESON_SOC_G12A = 0, 15123bcbb41SHanjie Lin MESON_SOC_A1, 15223bcbb41SHanjie Lin }; 15323bcbb41SHanjie Lin 15416df8bcbSNeil Armstrong struct phy_meson_g12a_usb2_priv { 15516df8bcbSNeil Armstrong struct device *dev; 15616df8bcbSNeil Armstrong struct regmap *regmap; 15716df8bcbSNeil Armstrong struct clk *clk; 15816df8bcbSNeil Armstrong struct reset_control *reset; 15923bcbb41SHanjie Lin int soc_id; 16016df8bcbSNeil Armstrong }; 16116df8bcbSNeil Armstrong 16216df8bcbSNeil Armstrong static const struct regmap_config phy_meson_g12a_usb2_regmap_conf = { 16316df8bcbSNeil Armstrong .reg_bits = 8, 16416df8bcbSNeil Armstrong .val_bits = 32, 16516df8bcbSNeil Armstrong .reg_stride = 4, 16616df8bcbSNeil Armstrong .max_register = PHY_CTRL_R23, 16716df8bcbSNeil Armstrong }; 16816df8bcbSNeil Armstrong 16916df8bcbSNeil Armstrong static int phy_meson_g12a_usb2_init(struct phy *phy) 17016df8bcbSNeil Armstrong { 17116df8bcbSNeil Armstrong struct phy_meson_g12a_usb2_priv *priv = phy_get_drvdata(phy); 17216df8bcbSNeil Armstrong int ret; 17323bcbb41SHanjie Lin unsigned int value; 17416df8bcbSNeil Armstrong 17516df8bcbSNeil Armstrong ret = reset_control_reset(priv->reset); 17616df8bcbSNeil Armstrong if (ret) 17716df8bcbSNeil Armstrong return ret; 17816df8bcbSNeil Armstrong 17916df8bcbSNeil Armstrong udelay(RESET_COMPLETE_TIME); 18016df8bcbSNeil Armstrong 18116df8bcbSNeil Armstrong /* usb2_otg_aca_en == 0 */ 18216df8bcbSNeil Armstrong regmap_update_bits(priv->regmap, PHY_CTRL_R21, 18316df8bcbSNeil Armstrong PHY_CTRL_R21_USB2_OTG_ACA_EN, 0); 18416df8bcbSNeil Armstrong 18516df8bcbSNeil Armstrong /* PLL Setup : 24MHz * 20 / 1 = 480MHz */ 18616df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R16, 18716df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R16_MPLL_M, 20) | 18816df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R16_MPLL_N, 1) | 18916df8bcbSNeil Armstrong PHY_CTRL_R16_MPLL_LOAD | 19016df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R16_MPLL_LOCK_LONG, 1) | 19116df8bcbSNeil Armstrong PHY_CTRL_R16_MPLL_FAST_LOCK | 19216df8bcbSNeil Armstrong PHY_CTRL_R16_MPLL_EN | 19316df8bcbSNeil Armstrong PHY_CTRL_R16_MPLL_RESET); 19416df8bcbSNeil Armstrong 19516df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R17, 19616df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R17_MPLL_FRAC_IN, 0) | 19716df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R17_MPLL_LAMBDA1, 7) | 19816df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R17_MPLL_LAMBDA0, 7) | 19916df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R17_MPLL_FILTER_PVT2, 2) | 20016df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R17_MPLL_FILTER_PVT1, 9)); 20116df8bcbSNeil Armstrong 20223bcbb41SHanjie Lin value = FIELD_PREP(PHY_CTRL_R18_MPLL_LKW_SEL, 1) | 20316df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_LK_W, 9) | 20416df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_LK_S, 0x27) | 20516df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_PFD_GAIN, 1) | 20616df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_ROU, 7) | 20716df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_DATA_SEL, 3) | 20816df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_BIAS_ADJ, 1) | 20916df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_BB_MODE, 0) | 21016df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_ALPHA, 3) | 21116df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R18_MPLL_ADJ_LDO, 1) | 21223bcbb41SHanjie Lin PHY_CTRL_R18_MPLL_ACG_RANGE; 21323bcbb41SHanjie Lin 21423bcbb41SHanjie Lin if (priv->soc_id == MESON_SOC_A1) 21523bcbb41SHanjie Lin value |= PHY_CTRL_R18_MPLL_DCO_CLK_SEL; 21623bcbb41SHanjie Lin 21723bcbb41SHanjie Lin regmap_write(priv->regmap, PHY_CTRL_R18, value); 21816df8bcbSNeil Armstrong 21916df8bcbSNeil Armstrong udelay(PLL_RESET_COMPLETE_TIME); 22016df8bcbSNeil Armstrong 22116df8bcbSNeil Armstrong /* UnReset PLL */ 22216df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R16, 22316df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R16_MPLL_M, 20) | 22416df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R16_MPLL_N, 1) | 22516df8bcbSNeil Armstrong PHY_CTRL_R16_MPLL_LOAD | 22616df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R16_MPLL_LOCK_LONG, 1) | 22716df8bcbSNeil Armstrong PHY_CTRL_R16_MPLL_FAST_LOCK | 22816df8bcbSNeil Armstrong PHY_CTRL_R16_MPLL_EN); 22916df8bcbSNeil Armstrong 23016df8bcbSNeil Armstrong /* PHY Tuning */ 23116df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R20, 23216df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R20_USB2_OTG_VBUS_TRIM_2_0, 4) | 23316df8bcbSNeil Armstrong PHY_CTRL_R20_USB2_OTG_VBUSDET_EN | 23416df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R20_USB2_DMON_SEL_3_0, 15) | 23516df8bcbSNeil Armstrong PHY_CTRL_R20_USB2_EDGE_DRV_EN | 23616df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0, 3) | 23716df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R20_USB2_BGR_ADJ_4_0, 0) | 23816df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R20_USB2_BGR_VREF_4_0, 0) | 23916df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R20_USB2_BGR_DBG_1_0, 0)); 24016df8bcbSNeil Armstrong 24123bcbb41SHanjie Lin if (priv->soc_id == MESON_SOC_G12A) 24216df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R4, 24316df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_7_0, 0xf) | 24416df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_15_8, 0xf) | 24516df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_23_16, 0xf) | 24616df8bcbSNeil Armstrong PHY_CTRL_R4_TEST_BYPASS_MODE_EN | 24716df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_1_0, 0) | 24816df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_3_2, 0)); 24923bcbb41SHanjie Lin else if (priv->soc_id == MESON_SOC_A1) { 25023bcbb41SHanjie Lin regmap_write(priv->regmap, PHY_CTRL_R21, 25123bcbb41SHanjie Lin PHY_CTRL_R21_USB2_CAL_ACK_EN | 25223bcbb41SHanjie Lin PHY_CTRL_R21_USB2_TX_STRG_PD | 25323bcbb41SHanjie Lin FIELD_PREP(PHY_CTRL_R21_USB2_OTG_ACA_TRIM_1_0, 2)); 25423bcbb41SHanjie Lin 25523bcbb41SHanjie Lin /* Analog Settings */ 25623bcbb41SHanjie Lin regmap_write(priv->regmap, PHY_CTRL_R13, 25723bcbb41SHanjie Lin FIELD_PREP(PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET, 7)); 25823bcbb41SHanjie Lin } 25916df8bcbSNeil Armstrong 26016df8bcbSNeil Armstrong /* Tuning Disconnect Threshold */ 26116df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R3, 26216df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R3_SQUELCH_REF, 0) | 26316df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R3_HSDIC_REF, 1) | 26416df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R3_DISC_THRESH, 3)); 26516df8bcbSNeil Armstrong 26623bcbb41SHanjie Lin if (priv->soc_id == MESON_SOC_G12A) { 26716df8bcbSNeil Armstrong /* Analog Settings */ 26816df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R14, 0); 26916df8bcbSNeil Armstrong regmap_write(priv->regmap, PHY_CTRL_R13, 27016df8bcbSNeil Armstrong PHY_CTRL_R13_UPDATE_PMA_SIGNALS | 27116df8bcbSNeil Armstrong FIELD_PREP(PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET, 7)); 27223bcbb41SHanjie Lin } 27316df8bcbSNeil Armstrong 27416df8bcbSNeil Armstrong return 0; 27516df8bcbSNeil Armstrong } 27616df8bcbSNeil Armstrong 27716df8bcbSNeil Armstrong static int phy_meson_g12a_usb2_exit(struct phy *phy) 27816df8bcbSNeil Armstrong { 27916df8bcbSNeil Armstrong struct phy_meson_g12a_usb2_priv *priv = phy_get_drvdata(phy); 28016df8bcbSNeil Armstrong 28116df8bcbSNeil Armstrong return reset_control_reset(priv->reset); 28216df8bcbSNeil Armstrong } 28316df8bcbSNeil Armstrong 28416df8bcbSNeil Armstrong /* set_mode is not needed, mode setting is handled via the UTMI bus */ 28516df8bcbSNeil Armstrong static const struct phy_ops phy_meson_g12a_usb2_ops = { 28616df8bcbSNeil Armstrong .init = phy_meson_g12a_usb2_init, 28716df8bcbSNeil Armstrong .exit = phy_meson_g12a_usb2_exit, 28816df8bcbSNeil Armstrong .owner = THIS_MODULE, 28916df8bcbSNeil Armstrong }; 29016df8bcbSNeil Armstrong 29116df8bcbSNeil Armstrong static int phy_meson_g12a_usb2_probe(struct platform_device *pdev) 29216df8bcbSNeil Armstrong { 29316df8bcbSNeil Armstrong struct device *dev = &pdev->dev; 29416df8bcbSNeil Armstrong struct phy_provider *phy_provider; 29516df8bcbSNeil Armstrong struct resource *res; 29616df8bcbSNeil Armstrong struct phy_meson_g12a_usb2_priv *priv; 29716df8bcbSNeil Armstrong struct phy *phy; 29816df8bcbSNeil Armstrong void __iomem *base; 29916df8bcbSNeil Armstrong int ret; 30016df8bcbSNeil Armstrong 30116df8bcbSNeil Armstrong priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 30216df8bcbSNeil Armstrong if (!priv) 30316df8bcbSNeil Armstrong return -ENOMEM; 30416df8bcbSNeil Armstrong 30516df8bcbSNeil Armstrong priv->dev = dev; 30616df8bcbSNeil Armstrong platform_set_drvdata(pdev, priv); 30716df8bcbSNeil Armstrong 30816df8bcbSNeil Armstrong res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 30916df8bcbSNeil Armstrong base = devm_ioremap_resource(dev, res); 31016df8bcbSNeil Armstrong if (IS_ERR(base)) 31116df8bcbSNeil Armstrong return PTR_ERR(base); 31216df8bcbSNeil Armstrong 31323bcbb41SHanjie Lin priv->soc_id = (enum meson_soc_id)of_device_get_match_data(&pdev->dev); 31423bcbb41SHanjie Lin 31516df8bcbSNeil Armstrong priv->regmap = devm_regmap_init_mmio(dev, base, 31616df8bcbSNeil Armstrong &phy_meson_g12a_usb2_regmap_conf); 31716df8bcbSNeil Armstrong if (IS_ERR(priv->regmap)) 31816df8bcbSNeil Armstrong return PTR_ERR(priv->regmap); 31916df8bcbSNeil Armstrong 32016df8bcbSNeil Armstrong priv->clk = devm_clk_get(dev, "xtal"); 32116df8bcbSNeil Armstrong if (IS_ERR(priv->clk)) 32216df8bcbSNeil Armstrong return PTR_ERR(priv->clk); 32316df8bcbSNeil Armstrong 32416df8bcbSNeil Armstrong priv->reset = devm_reset_control_get(dev, "phy"); 32516df8bcbSNeil Armstrong if (IS_ERR(priv->reset)) 32616df8bcbSNeil Armstrong return PTR_ERR(priv->reset); 32716df8bcbSNeil Armstrong 32816df8bcbSNeil Armstrong ret = reset_control_deassert(priv->reset); 32916df8bcbSNeil Armstrong if (ret) 33016df8bcbSNeil Armstrong return ret; 33116df8bcbSNeil Armstrong 33216df8bcbSNeil Armstrong phy = devm_phy_create(dev, NULL, &phy_meson_g12a_usb2_ops); 33316df8bcbSNeil Armstrong if (IS_ERR(phy)) { 33416df8bcbSNeil Armstrong ret = PTR_ERR(phy); 33516df8bcbSNeil Armstrong if (ret != -EPROBE_DEFER) 33616df8bcbSNeil Armstrong dev_err(dev, "failed to create PHY\n"); 33716df8bcbSNeil Armstrong 33816df8bcbSNeil Armstrong return ret; 33916df8bcbSNeil Armstrong } 34016df8bcbSNeil Armstrong 34116df8bcbSNeil Armstrong phy_set_bus_width(phy, 8); 34216df8bcbSNeil Armstrong phy_set_drvdata(phy, priv); 34316df8bcbSNeil Armstrong 34416df8bcbSNeil Armstrong phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 34516df8bcbSNeil Armstrong 34616df8bcbSNeil Armstrong return PTR_ERR_OR_ZERO(phy_provider); 34716df8bcbSNeil Armstrong } 34816df8bcbSNeil Armstrong 34916df8bcbSNeil Armstrong static const struct of_device_id phy_meson_g12a_usb2_of_match[] = { 35023bcbb41SHanjie Lin { 35123bcbb41SHanjie Lin .compatible = "amlogic,g12a-usb2-phy", 35223bcbb41SHanjie Lin .data = (void *)MESON_SOC_G12A, 35323bcbb41SHanjie Lin }, 35423bcbb41SHanjie Lin { 35523bcbb41SHanjie Lin .compatible = "amlogic,a1-usb2-phy", 35623bcbb41SHanjie Lin .data = (void *)MESON_SOC_A1, 35723bcbb41SHanjie Lin }, 35823bcbb41SHanjie Lin { /* Sentinel */ } 35916df8bcbSNeil Armstrong }; 36016df8bcbSNeil Armstrong MODULE_DEVICE_TABLE(of, phy_meson_g12a_usb2_of_match); 36116df8bcbSNeil Armstrong 36216df8bcbSNeil Armstrong static struct platform_driver phy_meson_g12a_usb2_driver = { 36316df8bcbSNeil Armstrong .probe = phy_meson_g12a_usb2_probe, 36416df8bcbSNeil Armstrong .driver = { 36516df8bcbSNeil Armstrong .name = "phy-meson-g12a-usb2", 36616df8bcbSNeil Armstrong .of_match_table = phy_meson_g12a_usb2_of_match, 36716df8bcbSNeil Armstrong }, 36816df8bcbSNeil Armstrong }; 36916df8bcbSNeil Armstrong module_platform_driver(phy_meson_g12a_usb2_driver); 37016df8bcbSNeil Armstrong 37116df8bcbSNeil Armstrong MODULE_AUTHOR("Martin Blumenstingl <martin.blumenstingl@googlemail.com>"); 37216df8bcbSNeil Armstrong MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>"); 37316df8bcbSNeil Armstrong MODULE_DESCRIPTION("Meson G12A USB2 PHY driver"); 37416df8bcbSNeil Armstrong MODULE_LICENSE("GPL v2"); 375