18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Cadence Sierra PHY Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2018 Cadence Design Systems 68c2ecf20Sopenharmony_ci * Author: Alan Douglas <adouglas@cadence.com> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#include <linux/clk.h> 108c2ecf20Sopenharmony_ci#include <linux/delay.h> 118c2ecf20Sopenharmony_ci#include <linux/err.h> 128c2ecf20Sopenharmony_ci#include <linux/io.h> 138c2ecf20Sopenharmony_ci#include <linux/module.h> 148c2ecf20Sopenharmony_ci#include <linux/phy/phy.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 178c2ecf20Sopenharmony_ci#include <linux/regmap.h> 188c2ecf20Sopenharmony_ci#include <linux/reset.h> 198c2ecf20Sopenharmony_ci#include <linux/slab.h> 208c2ecf20Sopenharmony_ci#include <linux/of.h> 218c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 228c2ecf20Sopenharmony_ci#include <dt-bindings/phy/phy.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* PHY register offsets */ 258c2ecf20Sopenharmony_ci#define SIERRA_COMMON_CDB_OFFSET 0x0 268c2ecf20Sopenharmony_ci#define SIERRA_MACRO_ID_REG 0x0 278c2ecf20Sopenharmony_ci#define SIERRA_CMN_PLLLC_MODE_PREG 0x48 288c2ecf20Sopenharmony_ci#define SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG 0x49 298c2ecf20Sopenharmony_ci#define SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG 0x4A 308c2ecf20Sopenharmony_ci#define SIERRA_CMN_PLLLC_LOCK_CNTSTART_PREG 0x4B 318c2ecf20Sopenharmony_ci#define SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG 0x4F 328c2ecf20Sopenharmony_ci#define SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG 0x50 338c2ecf20Sopenharmony_ci#define SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG 0x62 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define SIERRA_LANE_CDB_OFFSET(ln, block_offset, reg_offset) \ 368c2ecf20Sopenharmony_ci ((0x4000 << (block_offset)) + \ 378c2ecf20Sopenharmony_ci (((ln) << 9) << (reg_offset))) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define SIERRA_DET_STANDEC_A_PREG 0x000 408c2ecf20Sopenharmony_ci#define SIERRA_DET_STANDEC_B_PREG 0x001 418c2ecf20Sopenharmony_ci#define SIERRA_DET_STANDEC_C_PREG 0x002 428c2ecf20Sopenharmony_ci#define SIERRA_DET_STANDEC_D_PREG 0x003 438c2ecf20Sopenharmony_ci#define SIERRA_DET_STANDEC_E_PREG 0x004 448c2ecf20Sopenharmony_ci#define SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG 0x008 458c2ecf20Sopenharmony_ci#define SIERRA_PSM_A0IN_TMR_PREG 0x009 468c2ecf20Sopenharmony_ci#define SIERRA_PSM_DIAG_PREG 0x015 478c2ecf20Sopenharmony_ci#define SIERRA_PSC_TX_A0_PREG 0x028 488c2ecf20Sopenharmony_ci#define SIERRA_PSC_TX_A1_PREG 0x029 498c2ecf20Sopenharmony_ci#define SIERRA_PSC_TX_A2_PREG 0x02A 508c2ecf20Sopenharmony_ci#define SIERRA_PSC_TX_A3_PREG 0x02B 518c2ecf20Sopenharmony_ci#define SIERRA_PSC_RX_A0_PREG 0x030 528c2ecf20Sopenharmony_ci#define SIERRA_PSC_RX_A1_PREG 0x031 538c2ecf20Sopenharmony_ci#define SIERRA_PSC_RX_A2_PREG 0x032 548c2ecf20Sopenharmony_ci#define SIERRA_PSC_RX_A3_PREG 0x033 558c2ecf20Sopenharmony_ci#define SIERRA_PLLCTRL_SUBRATE_PREG 0x03A 568c2ecf20Sopenharmony_ci#define SIERRA_PLLCTRL_GEN_D_PREG 0x03E 578c2ecf20Sopenharmony_ci#define SIERRA_PLLCTRL_CPGAIN_MODE_PREG 0x03F 588c2ecf20Sopenharmony_ci#define SIERRA_PLLCTRL_STATUS_PREG 0x044 598c2ecf20Sopenharmony_ci#define SIERRA_CLKPATH_BIASTRIM_PREG 0x04B 608c2ecf20Sopenharmony_ci#define SIERRA_DFE_BIASTRIM_PREG 0x04C 618c2ecf20Sopenharmony_ci#define SIERRA_DRVCTRL_ATTEN_PREG 0x06A 628c2ecf20Sopenharmony_ci#define SIERRA_CLKPATHCTRL_TMR_PREG 0x081 638c2ecf20Sopenharmony_ci#define SIERRA_RX_CREQ_FLTR_A_MODE3_PREG 0x085 648c2ecf20Sopenharmony_ci#define SIERRA_RX_CREQ_FLTR_A_MODE2_PREG 0x086 658c2ecf20Sopenharmony_ci#define SIERRA_RX_CREQ_FLTR_A_MODE1_PREG 0x087 668c2ecf20Sopenharmony_ci#define SIERRA_RX_CREQ_FLTR_A_MODE0_PREG 0x088 678c2ecf20Sopenharmony_ci#define SIERRA_CREQ_CCLKDET_MODE01_PREG 0x08E 688c2ecf20Sopenharmony_ci#define SIERRA_RX_CTLE_MAINTENANCE_PREG 0x091 698c2ecf20Sopenharmony_ci#define SIERRA_CREQ_FSMCLK_SEL_PREG 0x092 708c2ecf20Sopenharmony_ci#define SIERRA_CREQ_EQ_CTRL_PREG 0x093 718c2ecf20Sopenharmony_ci#define SIERRA_CREQ_SPARE_PREG 0x096 728c2ecf20Sopenharmony_ci#define SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG 0x097 738c2ecf20Sopenharmony_ci#define SIERRA_CTLELUT_CTRL_PREG 0x098 748c2ecf20Sopenharmony_ci#define SIERRA_DFE_ECMP_RATESEL_PREG 0x0C0 758c2ecf20Sopenharmony_ci#define SIERRA_DFE_SMP_RATESEL_PREG 0x0C1 768c2ecf20Sopenharmony_ci#define SIERRA_DEQ_PHALIGN_CTRL 0x0C4 778c2ecf20Sopenharmony_ci#define SIERRA_DEQ_CONCUR_CTRL1_PREG 0x0C8 788c2ecf20Sopenharmony_ci#define SIERRA_DEQ_CONCUR_CTRL2_PREG 0x0C9 798c2ecf20Sopenharmony_ci#define SIERRA_DEQ_EPIPWR_CTRL2_PREG 0x0CD 808c2ecf20Sopenharmony_ci#define SIERRA_DEQ_FAST_MAINT_CYCLES_PREG 0x0CE 818c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ERRCMP_CTRL_PREG 0x0D0 828c2ecf20Sopenharmony_ci#define SIERRA_DEQ_OFFSET_CTRL_PREG 0x0D8 838c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GAIN_CTRL_PREG 0x0E0 848c2ecf20Sopenharmony_ci#define SIERRA_DEQ_VGATUNE_CTRL_PREG 0x0E1 858c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT0 0x0E8 868c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT1 0x0E9 878c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT2 0x0EA 888c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT3 0x0EB 898c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT4 0x0EC 908c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT5 0x0ED 918c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT6 0x0EE 928c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT7 0x0EF 938c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT8 0x0F0 948c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT9 0x0F1 958c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT10 0x0F2 968c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT11 0x0F3 978c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT12 0x0F4 988c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT13 0x0F5 998c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT14 0x0F6 1008c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT15 0x0F7 1018c2ecf20Sopenharmony_ci#define SIERRA_DEQ_GLUT16 0x0F8 1028c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT0 0x108 1038c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT1 0x109 1048c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT2 0x10A 1058c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT3 0x10B 1068c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT4 0x10C 1078c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT5 0x10D 1088c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT6 0x10E 1098c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT7 0x10F 1108c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT8 0x110 1118c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT9 0x111 1128c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT10 0x112 1138c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT11 0x113 1148c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT12 0x114 1158c2ecf20Sopenharmony_ci#define SIERRA_DEQ_ALUT13 0x115 1168c2ecf20Sopenharmony_ci#define SIERRA_DEQ_DFETAP_CTRL_PREG 0x128 1178c2ecf20Sopenharmony_ci#define SIERRA_DFE_EN_1010_IGNORE_PREG 0x134 1188c2ecf20Sopenharmony_ci#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150 1198c2ecf20Sopenharmony_ci#define SIERRA_DEQ_TAU_CTRL2_PREG 0x151 1208c2ecf20Sopenharmony_ci#define SIERRA_DEQ_PICTRL_PREG 0x161 1218c2ecf20Sopenharmony_ci#define SIERRA_CPICAL_TMRVAL_MODE1_PREG 0x170 1228c2ecf20Sopenharmony_ci#define SIERRA_CPICAL_TMRVAL_MODE0_PREG 0x171 1238c2ecf20Sopenharmony_ci#define SIERRA_CPICAL_PICNT_MODE1_PREG 0x174 1248c2ecf20Sopenharmony_ci#define SIERRA_CPI_OUTBUF_RATESEL_PREG 0x17C 1258c2ecf20Sopenharmony_ci#define SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG 0x183 1268c2ecf20Sopenharmony_ci#define SIERRA_LFPSDET_SUPPORT_PREG 0x188 1278c2ecf20Sopenharmony_ci#define SIERRA_LFPSFILT_NS_PREG 0x18A 1288c2ecf20Sopenharmony_ci#define SIERRA_LFPSFILT_RD_PREG 0x18B 1298c2ecf20Sopenharmony_ci#define SIERRA_LFPSFILT_MP_PREG 0x18C 1308c2ecf20Sopenharmony_ci#define SIERRA_SIGDET_SUPPORT_PREG 0x190 1318c2ecf20Sopenharmony_ci#define SIERRA_SDFILT_H2L_A_PREG 0x191 1328c2ecf20Sopenharmony_ci#define SIERRA_SDFILT_L2H_PREG 0x193 1338c2ecf20Sopenharmony_ci#define SIERRA_RXBUFFER_CTLECTRL_PREG 0x19E 1348c2ecf20Sopenharmony_ci#define SIERRA_RXBUFFER_RCDFECTRL_PREG 0x19F 1358c2ecf20Sopenharmony_ci#define SIERRA_RXBUFFER_DFECTRL_PREG 0x1A0 1368c2ecf20Sopenharmony_ci#define SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG 0x14F 1378c2ecf20Sopenharmony_ci#define SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG 0x150 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define SIERRA_PHY_CONFIG_CTRL_OFFSET(block_offset) \ 1408c2ecf20Sopenharmony_ci (0xc000 << (block_offset)) 1418c2ecf20Sopenharmony_ci#define SIERRA_PHY_PLL_CFG 0xe 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci#define SIERRA_MACRO_ID 0x00007364 1448c2ecf20Sopenharmony_ci#define SIERRA_MAX_LANES 16 1458c2ecf20Sopenharmony_ci#define PLL_LOCK_TIME 100000 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic const struct reg_field macro_id_type = 1488c2ecf20Sopenharmony_ci REG_FIELD(SIERRA_MACRO_ID_REG, 0, 15); 1498c2ecf20Sopenharmony_cistatic const struct reg_field phy_pll_cfg_1 = 1508c2ecf20Sopenharmony_ci REG_FIELD(SIERRA_PHY_PLL_CFG, 1, 1); 1518c2ecf20Sopenharmony_cistatic const struct reg_field pllctrl_lock = 1528c2ecf20Sopenharmony_ci REG_FIELD(SIERRA_PLLCTRL_STATUS_PREG, 0, 0); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistruct cdns_sierra_inst { 1558c2ecf20Sopenharmony_ci struct phy *phy; 1568c2ecf20Sopenharmony_ci u32 phy_type; 1578c2ecf20Sopenharmony_ci u32 num_lanes; 1588c2ecf20Sopenharmony_ci u32 mlane; 1598c2ecf20Sopenharmony_ci struct reset_control *lnk_rst; 1608c2ecf20Sopenharmony_ci}; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistruct cdns_reg_pairs { 1638c2ecf20Sopenharmony_ci u16 val; 1648c2ecf20Sopenharmony_ci u32 off; 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistruct cdns_sierra_data { 1688c2ecf20Sopenharmony_ci u32 id_value; 1698c2ecf20Sopenharmony_ci u8 block_offset_shift; 1708c2ecf20Sopenharmony_ci u8 reg_offset_shift; 1718c2ecf20Sopenharmony_ci u32 pcie_cmn_regs; 1728c2ecf20Sopenharmony_ci u32 pcie_ln_regs; 1738c2ecf20Sopenharmony_ci u32 usb_cmn_regs; 1748c2ecf20Sopenharmony_ci u32 usb_ln_regs; 1758c2ecf20Sopenharmony_ci const struct cdns_reg_pairs *pcie_cmn_vals; 1768c2ecf20Sopenharmony_ci const struct cdns_reg_pairs *pcie_ln_vals; 1778c2ecf20Sopenharmony_ci const struct cdns_reg_pairs *usb_cmn_vals; 1788c2ecf20Sopenharmony_ci const struct cdns_reg_pairs *usb_ln_vals; 1798c2ecf20Sopenharmony_ci}; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistruct cdns_regmap_cdb_context { 1828c2ecf20Sopenharmony_ci struct device *dev; 1838c2ecf20Sopenharmony_ci void __iomem *base; 1848c2ecf20Sopenharmony_ci u8 reg_offset_shift; 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistruct cdns_sierra_phy { 1888c2ecf20Sopenharmony_ci struct device *dev; 1898c2ecf20Sopenharmony_ci struct regmap *regmap; 1908c2ecf20Sopenharmony_ci struct cdns_sierra_data *init_data; 1918c2ecf20Sopenharmony_ci struct cdns_sierra_inst phys[SIERRA_MAX_LANES]; 1928c2ecf20Sopenharmony_ci struct reset_control *phy_rst; 1938c2ecf20Sopenharmony_ci struct reset_control *apb_rst; 1948c2ecf20Sopenharmony_ci struct regmap *regmap_lane_cdb[SIERRA_MAX_LANES]; 1958c2ecf20Sopenharmony_ci struct regmap *regmap_phy_config_ctrl; 1968c2ecf20Sopenharmony_ci struct regmap *regmap_common_cdb; 1978c2ecf20Sopenharmony_ci struct regmap_field *macro_id_type; 1988c2ecf20Sopenharmony_ci struct regmap_field *phy_pll_cfg_1; 1998c2ecf20Sopenharmony_ci struct regmap_field *pllctrl_lock[SIERRA_MAX_LANES]; 2008c2ecf20Sopenharmony_ci struct clk *clk; 2018c2ecf20Sopenharmony_ci struct clk *cmn_refclk_dig_div; 2028c2ecf20Sopenharmony_ci struct clk *cmn_refclk1_dig_div; 2038c2ecf20Sopenharmony_ci int nsubnodes; 2048c2ecf20Sopenharmony_ci u32 num_lanes; 2058c2ecf20Sopenharmony_ci bool autoconf; 2068c2ecf20Sopenharmony_ci}; 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic int cdns_regmap_write(void *context, unsigned int reg, unsigned int val) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci struct cdns_regmap_cdb_context *ctx = context; 2118c2ecf20Sopenharmony_ci u32 offset = reg << ctx->reg_offset_shift; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci writew(val, ctx->base + offset); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci return 0; 2168c2ecf20Sopenharmony_ci} 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_cistatic int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val) 2198c2ecf20Sopenharmony_ci{ 2208c2ecf20Sopenharmony_ci struct cdns_regmap_cdb_context *ctx = context; 2218c2ecf20Sopenharmony_ci u32 offset = reg << ctx->reg_offset_shift; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci *val = readw(ctx->base + offset); 2248c2ecf20Sopenharmony_ci return 0; 2258c2ecf20Sopenharmony_ci} 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci#define SIERRA_LANE_CDB_REGMAP_CONF(n) \ 2288c2ecf20Sopenharmony_ci{ \ 2298c2ecf20Sopenharmony_ci .name = "sierra_lane" n "_cdb", \ 2308c2ecf20Sopenharmony_ci .reg_stride = 1, \ 2318c2ecf20Sopenharmony_ci .fast_io = true, \ 2328c2ecf20Sopenharmony_ci .reg_write = cdns_regmap_write, \ 2338c2ecf20Sopenharmony_ci .reg_read = cdns_regmap_read, \ 2348c2ecf20Sopenharmony_ci} 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_cistatic const struct regmap_config cdns_sierra_lane_cdb_config[] = { 2378c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("0"), 2388c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("1"), 2398c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("2"), 2408c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("3"), 2418c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("4"), 2428c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("5"), 2438c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("6"), 2448c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("7"), 2458c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("8"), 2468c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("9"), 2478c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("10"), 2488c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("11"), 2498c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("12"), 2508c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("13"), 2518c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("14"), 2528c2ecf20Sopenharmony_ci SIERRA_LANE_CDB_REGMAP_CONF("15"), 2538c2ecf20Sopenharmony_ci}; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_cistatic const struct regmap_config cdns_sierra_common_cdb_config = { 2568c2ecf20Sopenharmony_ci .name = "sierra_common_cdb", 2578c2ecf20Sopenharmony_ci .reg_stride = 1, 2588c2ecf20Sopenharmony_ci .fast_io = true, 2598c2ecf20Sopenharmony_ci .reg_write = cdns_regmap_write, 2608c2ecf20Sopenharmony_ci .reg_read = cdns_regmap_read, 2618c2ecf20Sopenharmony_ci}; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistatic const struct regmap_config cdns_sierra_phy_config_ctrl_config = { 2648c2ecf20Sopenharmony_ci .name = "sierra_phy_config_ctrl", 2658c2ecf20Sopenharmony_ci .reg_stride = 1, 2668c2ecf20Sopenharmony_ci .fast_io = true, 2678c2ecf20Sopenharmony_ci .reg_write = cdns_regmap_write, 2688c2ecf20Sopenharmony_ci .reg_read = cdns_regmap_read, 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic int cdns_sierra_phy_init(struct phy *gphy) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); 2748c2ecf20Sopenharmony_ci struct cdns_sierra_phy *phy = dev_get_drvdata(gphy->dev.parent); 2758c2ecf20Sopenharmony_ci struct regmap *regmap; 2768c2ecf20Sopenharmony_ci int i, j; 2778c2ecf20Sopenharmony_ci const struct cdns_reg_pairs *cmn_vals, *ln_vals; 2788c2ecf20Sopenharmony_ci u32 num_cmn_regs, num_ln_regs; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci /* Initialise the PHY registers, unless auto configured */ 2818c2ecf20Sopenharmony_ci if (phy->autoconf) 2828c2ecf20Sopenharmony_ci return 0; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci clk_set_rate(phy->cmn_refclk_dig_div, 25000000); 2858c2ecf20Sopenharmony_ci clk_set_rate(phy->cmn_refclk1_dig_div, 25000000); 2868c2ecf20Sopenharmony_ci if (ins->phy_type == PHY_TYPE_PCIE) { 2878c2ecf20Sopenharmony_ci num_cmn_regs = phy->init_data->pcie_cmn_regs; 2888c2ecf20Sopenharmony_ci num_ln_regs = phy->init_data->pcie_ln_regs; 2898c2ecf20Sopenharmony_ci cmn_vals = phy->init_data->pcie_cmn_vals; 2908c2ecf20Sopenharmony_ci ln_vals = phy->init_data->pcie_ln_vals; 2918c2ecf20Sopenharmony_ci } else if (ins->phy_type == PHY_TYPE_USB3) { 2928c2ecf20Sopenharmony_ci num_cmn_regs = phy->init_data->usb_cmn_regs; 2938c2ecf20Sopenharmony_ci num_ln_regs = phy->init_data->usb_ln_regs; 2948c2ecf20Sopenharmony_ci cmn_vals = phy->init_data->usb_cmn_vals; 2958c2ecf20Sopenharmony_ci ln_vals = phy->init_data->usb_ln_vals; 2968c2ecf20Sopenharmony_ci } else { 2978c2ecf20Sopenharmony_ci return -EINVAL; 2988c2ecf20Sopenharmony_ci } 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci regmap = phy->regmap_common_cdb; 3018c2ecf20Sopenharmony_ci for (j = 0; j < num_cmn_regs ; j++) 3028c2ecf20Sopenharmony_ci regmap_write(regmap, cmn_vals[j].off, cmn_vals[j].val); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci for (i = 0; i < ins->num_lanes; i++) { 3058c2ecf20Sopenharmony_ci for (j = 0; j < num_ln_regs ; j++) { 3068c2ecf20Sopenharmony_ci regmap = phy->regmap_lane_cdb[i + ins->mlane]; 3078c2ecf20Sopenharmony_ci regmap_write(regmap, ln_vals[j].off, ln_vals[j].val); 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci } 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci return 0; 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic int cdns_sierra_phy_on(struct phy *gphy) 3158c2ecf20Sopenharmony_ci{ 3168c2ecf20Sopenharmony_ci struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent); 3178c2ecf20Sopenharmony_ci struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); 3188c2ecf20Sopenharmony_ci struct device *dev = sp->dev; 3198c2ecf20Sopenharmony_ci u32 val; 3208c2ecf20Sopenharmony_ci int ret; 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci ret = reset_control_deassert(sp->phy_rst); 3238c2ecf20Sopenharmony_ci if (ret) { 3248c2ecf20Sopenharmony_ci dev_err(dev, "Failed to take the PHY out of reset\n"); 3258c2ecf20Sopenharmony_ci return ret; 3268c2ecf20Sopenharmony_ci } 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci /* Take the PHY lane group out of reset */ 3298c2ecf20Sopenharmony_ci ret = reset_control_deassert(ins->lnk_rst); 3308c2ecf20Sopenharmony_ci if (ret) { 3318c2ecf20Sopenharmony_ci dev_err(dev, "Failed to take the PHY lane out of reset\n"); 3328c2ecf20Sopenharmony_ci return ret; 3338c2ecf20Sopenharmony_ci } 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci ret = regmap_field_read_poll_timeout(sp->pllctrl_lock[ins->mlane], 3368c2ecf20Sopenharmony_ci val, val, 1000, PLL_LOCK_TIME); 3378c2ecf20Sopenharmony_ci if (ret < 0) 3388c2ecf20Sopenharmony_ci dev_err(dev, "PLL lock of lane failed\n"); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci return ret; 3418c2ecf20Sopenharmony_ci} 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_cistatic int cdns_sierra_phy_off(struct phy *gphy) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci struct cdns_sierra_inst *ins = phy_get_drvdata(gphy); 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci return reset_control_assert(ins->lnk_rst); 3488c2ecf20Sopenharmony_ci} 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_cistatic int cdns_sierra_phy_reset(struct phy *gphy) 3518c2ecf20Sopenharmony_ci{ 3528c2ecf20Sopenharmony_ci struct cdns_sierra_phy *sp = dev_get_drvdata(gphy->dev.parent); 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci reset_control_assert(sp->phy_rst); 3558c2ecf20Sopenharmony_ci reset_control_deassert(sp->phy_rst); 3568c2ecf20Sopenharmony_ci return 0; 3578c2ecf20Sopenharmony_ci}; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_cistatic const struct phy_ops ops = { 3608c2ecf20Sopenharmony_ci .init = cdns_sierra_phy_init, 3618c2ecf20Sopenharmony_ci .power_on = cdns_sierra_phy_on, 3628c2ecf20Sopenharmony_ci .power_off = cdns_sierra_phy_off, 3638c2ecf20Sopenharmony_ci .reset = cdns_sierra_phy_reset, 3648c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 3658c2ecf20Sopenharmony_ci}; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_cistatic int cdns_sierra_get_optional(struct cdns_sierra_inst *inst, 3688c2ecf20Sopenharmony_ci struct device_node *child) 3698c2ecf20Sopenharmony_ci{ 3708c2ecf20Sopenharmony_ci if (of_property_read_u32(child, "reg", &inst->mlane)) 3718c2ecf20Sopenharmony_ci return -EINVAL; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci if (of_property_read_u32(child, "cdns,num-lanes", &inst->num_lanes)) 3748c2ecf20Sopenharmony_ci return -EINVAL; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci if (of_property_read_u32(child, "cdns,phy-type", &inst->phy_type)) 3778c2ecf20Sopenharmony_ci return -EINVAL; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci return 0; 3808c2ecf20Sopenharmony_ci} 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_cistatic const struct of_device_id cdns_sierra_id_table[]; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistatic struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base, 3858c2ecf20Sopenharmony_ci u32 block_offset, u8 reg_offset_shift, 3868c2ecf20Sopenharmony_ci const struct regmap_config *config) 3878c2ecf20Sopenharmony_ci{ 3888c2ecf20Sopenharmony_ci struct cdns_regmap_cdb_context *ctx; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 3918c2ecf20Sopenharmony_ci if (!ctx) 3928c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci ctx->dev = dev; 3958c2ecf20Sopenharmony_ci ctx->base = base + block_offset; 3968c2ecf20Sopenharmony_ci ctx->reg_offset_shift = reg_offset_shift; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci return devm_regmap_init(dev, NULL, ctx, config); 3998c2ecf20Sopenharmony_ci} 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_cistatic int cdns_regfield_init(struct cdns_sierra_phy *sp) 4028c2ecf20Sopenharmony_ci{ 4038c2ecf20Sopenharmony_ci struct device *dev = sp->dev; 4048c2ecf20Sopenharmony_ci struct regmap_field *field; 4058c2ecf20Sopenharmony_ci struct regmap *regmap; 4068c2ecf20Sopenharmony_ci int i; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci regmap = sp->regmap_common_cdb; 4098c2ecf20Sopenharmony_ci field = devm_regmap_field_alloc(dev, regmap, macro_id_type); 4108c2ecf20Sopenharmony_ci if (IS_ERR(field)) { 4118c2ecf20Sopenharmony_ci dev_err(dev, "MACRO_ID_TYPE reg field init failed\n"); 4128c2ecf20Sopenharmony_ci return PTR_ERR(field); 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci sp->macro_id_type = field; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci regmap = sp->regmap_phy_config_ctrl; 4178c2ecf20Sopenharmony_ci field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg_1); 4188c2ecf20Sopenharmony_ci if (IS_ERR(field)) { 4198c2ecf20Sopenharmony_ci dev_err(dev, "PHY_PLL_CFG_1 reg field init failed\n"); 4208c2ecf20Sopenharmony_ci return PTR_ERR(field); 4218c2ecf20Sopenharmony_ci } 4228c2ecf20Sopenharmony_ci sp->phy_pll_cfg_1 = field; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci for (i = 0; i < SIERRA_MAX_LANES; i++) { 4258c2ecf20Sopenharmony_ci regmap = sp->regmap_lane_cdb[i]; 4268c2ecf20Sopenharmony_ci field = devm_regmap_field_alloc(dev, regmap, pllctrl_lock); 4278c2ecf20Sopenharmony_ci if (IS_ERR(field)) { 4288c2ecf20Sopenharmony_ci dev_err(dev, "P%d_ENABLE reg field init failed\n", i); 4298c2ecf20Sopenharmony_ci return PTR_ERR(field); 4308c2ecf20Sopenharmony_ci } 4318c2ecf20Sopenharmony_ci sp->pllctrl_lock[i] = field; 4328c2ecf20Sopenharmony_ci } 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci return 0; 4358c2ecf20Sopenharmony_ci} 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_cistatic int cdns_regmap_init_blocks(struct cdns_sierra_phy *sp, 4388c2ecf20Sopenharmony_ci void __iomem *base, u8 block_offset_shift, 4398c2ecf20Sopenharmony_ci u8 reg_offset_shift) 4408c2ecf20Sopenharmony_ci{ 4418c2ecf20Sopenharmony_ci struct device *dev = sp->dev; 4428c2ecf20Sopenharmony_ci struct regmap *regmap; 4438c2ecf20Sopenharmony_ci u32 block_offset; 4448c2ecf20Sopenharmony_ci int i; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci for (i = 0; i < SIERRA_MAX_LANES; i++) { 4478c2ecf20Sopenharmony_ci block_offset = SIERRA_LANE_CDB_OFFSET(i, block_offset_shift, 4488c2ecf20Sopenharmony_ci reg_offset_shift); 4498c2ecf20Sopenharmony_ci regmap = cdns_regmap_init(dev, base, block_offset, 4508c2ecf20Sopenharmony_ci reg_offset_shift, 4518c2ecf20Sopenharmony_ci &cdns_sierra_lane_cdb_config[i]); 4528c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 4538c2ecf20Sopenharmony_ci dev_err(dev, "Failed to init lane CDB regmap\n"); 4548c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 4558c2ecf20Sopenharmony_ci } 4568c2ecf20Sopenharmony_ci sp->regmap_lane_cdb[i] = regmap; 4578c2ecf20Sopenharmony_ci } 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci regmap = cdns_regmap_init(dev, base, SIERRA_COMMON_CDB_OFFSET, 4608c2ecf20Sopenharmony_ci reg_offset_shift, 4618c2ecf20Sopenharmony_ci &cdns_sierra_common_cdb_config); 4628c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 4638c2ecf20Sopenharmony_ci dev_err(dev, "Failed to init common CDB regmap\n"); 4648c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 4658c2ecf20Sopenharmony_ci } 4668c2ecf20Sopenharmony_ci sp->regmap_common_cdb = regmap; 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci block_offset = SIERRA_PHY_CONFIG_CTRL_OFFSET(block_offset_shift); 4698c2ecf20Sopenharmony_ci regmap = cdns_regmap_init(dev, base, block_offset, reg_offset_shift, 4708c2ecf20Sopenharmony_ci &cdns_sierra_phy_config_ctrl_config); 4718c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) { 4728c2ecf20Sopenharmony_ci dev_err(dev, "Failed to init PHY config and control regmap\n"); 4738c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci sp->regmap_phy_config_ctrl = regmap; 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci return 0; 4788c2ecf20Sopenharmony_ci} 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_cistatic int cdns_sierra_phy_probe(struct platform_device *pdev) 4818c2ecf20Sopenharmony_ci{ 4828c2ecf20Sopenharmony_ci struct cdns_sierra_phy *sp; 4838c2ecf20Sopenharmony_ci struct phy_provider *phy_provider; 4848c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 4858c2ecf20Sopenharmony_ci const struct of_device_id *match; 4868c2ecf20Sopenharmony_ci struct cdns_sierra_data *data; 4878c2ecf20Sopenharmony_ci unsigned int id_value; 4888c2ecf20Sopenharmony_ci struct resource *res; 4898c2ecf20Sopenharmony_ci int i, ret, node = 0; 4908c2ecf20Sopenharmony_ci void __iomem *base; 4918c2ecf20Sopenharmony_ci struct clk *clk; 4928c2ecf20Sopenharmony_ci struct device_node *dn = dev->of_node, *child; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci if (of_get_child_count(dn) == 0) 4958c2ecf20Sopenharmony_ci return -ENODEV; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci /* Get init data for this PHY */ 4988c2ecf20Sopenharmony_ci match = of_match_device(cdns_sierra_id_table, dev); 4998c2ecf20Sopenharmony_ci if (!match) 5008c2ecf20Sopenharmony_ci return -EINVAL; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci data = (struct cdns_sierra_data *)match->data; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci sp = devm_kzalloc(dev, sizeof(*sp), GFP_KERNEL); 5058c2ecf20Sopenharmony_ci if (!sp) 5068c2ecf20Sopenharmony_ci return -ENOMEM; 5078c2ecf20Sopenharmony_ci dev_set_drvdata(dev, sp); 5088c2ecf20Sopenharmony_ci sp->dev = dev; 5098c2ecf20Sopenharmony_ci sp->init_data = data; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 5128c2ecf20Sopenharmony_ci base = devm_ioremap_resource(dev, res); 5138c2ecf20Sopenharmony_ci if (IS_ERR(base)) { 5148c2ecf20Sopenharmony_ci dev_err(dev, "missing \"reg\"\n"); 5158c2ecf20Sopenharmony_ci return PTR_ERR(base); 5168c2ecf20Sopenharmony_ci } 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci ret = cdns_regmap_init_blocks(sp, base, data->block_offset_shift, 5198c2ecf20Sopenharmony_ci data->reg_offset_shift); 5208c2ecf20Sopenharmony_ci if (ret) 5218c2ecf20Sopenharmony_ci return ret; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci ret = cdns_regfield_init(sp); 5248c2ecf20Sopenharmony_ci if (ret) 5258c2ecf20Sopenharmony_ci return ret; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, sp); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci sp->clk = devm_clk_get_optional(dev, "phy_clk"); 5308c2ecf20Sopenharmony_ci if (IS_ERR(sp->clk)) { 5318c2ecf20Sopenharmony_ci dev_err(dev, "failed to get clock phy_clk\n"); 5328c2ecf20Sopenharmony_ci return PTR_ERR(sp->clk); 5338c2ecf20Sopenharmony_ci } 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci sp->phy_rst = devm_reset_control_get(dev, "sierra_reset"); 5368c2ecf20Sopenharmony_ci if (IS_ERR(sp->phy_rst)) { 5378c2ecf20Sopenharmony_ci dev_err(dev, "failed to get reset\n"); 5388c2ecf20Sopenharmony_ci return PTR_ERR(sp->phy_rst); 5398c2ecf20Sopenharmony_ci } 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci sp->apb_rst = devm_reset_control_get_optional(dev, "sierra_apb"); 5428c2ecf20Sopenharmony_ci if (IS_ERR(sp->apb_rst)) { 5438c2ecf20Sopenharmony_ci dev_err(dev, "failed to get apb reset\n"); 5448c2ecf20Sopenharmony_ci return PTR_ERR(sp->apb_rst); 5458c2ecf20Sopenharmony_ci } 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci clk = devm_clk_get_optional(dev, "cmn_refclk_dig_div"); 5488c2ecf20Sopenharmony_ci if (IS_ERR(clk)) { 5498c2ecf20Sopenharmony_ci dev_err(dev, "cmn_refclk_dig_div clock not found\n"); 5508c2ecf20Sopenharmony_ci ret = PTR_ERR(clk); 5518c2ecf20Sopenharmony_ci return ret; 5528c2ecf20Sopenharmony_ci } 5538c2ecf20Sopenharmony_ci sp->cmn_refclk_dig_div = clk; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci clk = devm_clk_get_optional(dev, "cmn_refclk1_dig_div"); 5568c2ecf20Sopenharmony_ci if (IS_ERR(clk)) { 5578c2ecf20Sopenharmony_ci dev_err(dev, "cmn_refclk1_dig_div clock not found\n"); 5588c2ecf20Sopenharmony_ci ret = PTR_ERR(clk); 5598c2ecf20Sopenharmony_ci return ret; 5608c2ecf20Sopenharmony_ci } 5618c2ecf20Sopenharmony_ci sp->cmn_refclk1_dig_div = clk; 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci ret = clk_prepare_enable(sp->clk); 5648c2ecf20Sopenharmony_ci if (ret) 5658c2ecf20Sopenharmony_ci return ret; 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* Enable APB */ 5688c2ecf20Sopenharmony_ci reset_control_deassert(sp->apb_rst); 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci /* Check that PHY is present */ 5718c2ecf20Sopenharmony_ci regmap_field_read(sp->macro_id_type, &id_value); 5728c2ecf20Sopenharmony_ci if (sp->init_data->id_value != id_value) { 5738c2ecf20Sopenharmony_ci ret = -EINVAL; 5748c2ecf20Sopenharmony_ci goto clk_disable; 5758c2ecf20Sopenharmony_ci } 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci sp->autoconf = of_property_read_bool(dn, "cdns,autoconf"); 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci for_each_available_child_of_node(dn, child) { 5808c2ecf20Sopenharmony_ci struct phy *gphy; 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci sp->phys[node].lnk_rst = 5838c2ecf20Sopenharmony_ci of_reset_control_array_get_exclusive(child); 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci if (IS_ERR(sp->phys[node].lnk_rst)) { 5868c2ecf20Sopenharmony_ci dev_err(dev, "failed to get reset %s\n", 5878c2ecf20Sopenharmony_ci child->full_name); 5888c2ecf20Sopenharmony_ci ret = PTR_ERR(sp->phys[node].lnk_rst); 5898c2ecf20Sopenharmony_ci goto put_child2; 5908c2ecf20Sopenharmony_ci } 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci if (!sp->autoconf) { 5938c2ecf20Sopenharmony_ci ret = cdns_sierra_get_optional(&sp->phys[node], child); 5948c2ecf20Sopenharmony_ci if (ret) { 5958c2ecf20Sopenharmony_ci dev_err(dev, "missing property in node %s\n", 5968c2ecf20Sopenharmony_ci child->name); 5978c2ecf20Sopenharmony_ci goto put_child; 5988c2ecf20Sopenharmony_ci } 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci sp->num_lanes += sp->phys[node].num_lanes; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci gphy = devm_phy_create(dev, child, &ops); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci if (IS_ERR(gphy)) { 6068c2ecf20Sopenharmony_ci ret = PTR_ERR(gphy); 6078c2ecf20Sopenharmony_ci goto put_child; 6088c2ecf20Sopenharmony_ci } 6098c2ecf20Sopenharmony_ci sp->phys[node].phy = gphy; 6108c2ecf20Sopenharmony_ci phy_set_drvdata(gphy, &sp->phys[node]); 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci node++; 6138c2ecf20Sopenharmony_ci } 6148c2ecf20Sopenharmony_ci sp->nsubnodes = node; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci if (sp->num_lanes > SIERRA_MAX_LANES) { 6178c2ecf20Sopenharmony_ci ret = -EINVAL; 6188c2ecf20Sopenharmony_ci dev_err(dev, "Invalid lane configuration\n"); 6198c2ecf20Sopenharmony_ci goto put_child2; 6208c2ecf20Sopenharmony_ci } 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci /* If more than one subnode, configure the PHY as multilink */ 6238c2ecf20Sopenharmony_ci if (!sp->autoconf && sp->nsubnodes > 1) 6248c2ecf20Sopenharmony_ci regmap_field_write(sp->phy_pll_cfg_1, 0x1); 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci pm_runtime_enable(dev); 6278c2ecf20Sopenharmony_ci phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 6288c2ecf20Sopenharmony_ci return PTR_ERR_OR_ZERO(phy_provider); 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ciput_child: 6318c2ecf20Sopenharmony_ci node++; 6328c2ecf20Sopenharmony_ciput_child2: 6338c2ecf20Sopenharmony_ci for (i = 0; i < node; i++) 6348c2ecf20Sopenharmony_ci reset_control_put(sp->phys[i].lnk_rst); 6358c2ecf20Sopenharmony_ci of_node_put(child); 6368c2ecf20Sopenharmony_ciclk_disable: 6378c2ecf20Sopenharmony_ci clk_disable_unprepare(sp->clk); 6388c2ecf20Sopenharmony_ci reset_control_assert(sp->apb_rst); 6398c2ecf20Sopenharmony_ci return ret; 6408c2ecf20Sopenharmony_ci} 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_cistatic int cdns_sierra_phy_remove(struct platform_device *pdev) 6438c2ecf20Sopenharmony_ci{ 6448c2ecf20Sopenharmony_ci struct cdns_sierra_phy *phy = platform_get_drvdata(pdev); 6458c2ecf20Sopenharmony_ci int i; 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci reset_control_assert(phy->phy_rst); 6488c2ecf20Sopenharmony_ci reset_control_assert(phy->apb_rst); 6498c2ecf20Sopenharmony_ci pm_runtime_disable(&pdev->dev); 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci /* 6528c2ecf20Sopenharmony_ci * The device level resets will be put automatically. 6538c2ecf20Sopenharmony_ci * Need to put the subnode resets here though. 6548c2ecf20Sopenharmony_ci */ 6558c2ecf20Sopenharmony_ci for (i = 0; i < phy->nsubnodes; i++) { 6568c2ecf20Sopenharmony_ci reset_control_assert(phy->phys[i].lnk_rst); 6578c2ecf20Sopenharmony_ci reset_control_put(phy->phys[i].lnk_rst); 6588c2ecf20Sopenharmony_ci } 6598c2ecf20Sopenharmony_ci return 0; 6608c2ecf20Sopenharmony_ci} 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci/* refclk100MHz_32b_PCIe_cmn_pll_ext_ssc */ 6638c2ecf20Sopenharmony_cistatic const struct cdns_reg_pairs cdns_pcie_cmn_regs_ext_ssc[] = { 6648c2ecf20Sopenharmony_ci {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG}, 6658c2ecf20Sopenharmony_ci {0x2106, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG}, 6668c2ecf20Sopenharmony_ci {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE1_PREG}, 6678c2ecf20Sopenharmony_ci {0x8A06, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}, 6688c2ecf20Sopenharmony_ci {0x1B1B, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG} 6698c2ecf20Sopenharmony_ci}; 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci/* refclk100MHz_32b_PCIe_ln_ext_ssc */ 6728c2ecf20Sopenharmony_cistatic const struct cdns_reg_pairs cdns_pcie_ln_regs_ext_ssc[] = { 6738c2ecf20Sopenharmony_ci {0x813E, SIERRA_CLKPATHCTRL_TMR_PREG}, 6748c2ecf20Sopenharmony_ci {0x8047, SIERRA_RX_CREQ_FLTR_A_MODE3_PREG}, 6758c2ecf20Sopenharmony_ci {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE2_PREG}, 6768c2ecf20Sopenharmony_ci {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG}, 6778c2ecf20Sopenharmony_ci {0x808F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG}, 6788c2ecf20Sopenharmony_ci {0x033C, SIERRA_RX_CTLE_MAINTENANCE_PREG}, 6798c2ecf20Sopenharmony_ci {0x44CC, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG} 6808c2ecf20Sopenharmony_ci}; 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci/* refclk100MHz_20b_USB_cmn_pll_ext_ssc */ 6838c2ecf20Sopenharmony_cistatic const struct cdns_reg_pairs cdns_usb_cmn_regs_ext_ssc[] = { 6848c2ecf20Sopenharmony_ci {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE1_PREG}, 6858c2ecf20Sopenharmony_ci {0x2085, SIERRA_CMN_PLLLC_LF_COEFF_MODE0_PREG}, 6868c2ecf20Sopenharmony_ci {0x0000, SIERRA_CMN_PLLLC_BWCAL_MODE0_PREG}, 6878c2ecf20Sopenharmony_ci {0x0000, SIERRA_CMN_PLLLC_SS_TIME_STEPSIZE_MODE_PREG} 6888c2ecf20Sopenharmony_ci}; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci/* refclk100MHz_20b_USB_ln_ext_ssc */ 6918c2ecf20Sopenharmony_cistatic const struct cdns_reg_pairs cdns_usb_ln_regs_ext_ssc[] = { 6928c2ecf20Sopenharmony_ci {0xFE0A, SIERRA_DET_STANDEC_A_PREG}, 6938c2ecf20Sopenharmony_ci {0x000F, SIERRA_DET_STANDEC_B_PREG}, 6948c2ecf20Sopenharmony_ci {0x55A5, SIERRA_DET_STANDEC_C_PREG}, 6958c2ecf20Sopenharmony_ci {0x69ad, SIERRA_DET_STANDEC_D_PREG}, 6968c2ecf20Sopenharmony_ci {0x0241, SIERRA_DET_STANDEC_E_PREG}, 6978c2ecf20Sopenharmony_ci {0x0110, SIERRA_PSM_LANECAL_DLY_A1_RESETS_PREG}, 6988c2ecf20Sopenharmony_ci {0x0014, SIERRA_PSM_A0IN_TMR_PREG}, 6998c2ecf20Sopenharmony_ci {0xCF00, SIERRA_PSM_DIAG_PREG}, 7008c2ecf20Sopenharmony_ci {0x001F, SIERRA_PSC_TX_A0_PREG}, 7018c2ecf20Sopenharmony_ci {0x0007, SIERRA_PSC_TX_A1_PREG}, 7028c2ecf20Sopenharmony_ci {0x0003, SIERRA_PSC_TX_A2_PREG}, 7038c2ecf20Sopenharmony_ci {0x0003, SIERRA_PSC_TX_A3_PREG}, 7048c2ecf20Sopenharmony_ci {0x0FFF, SIERRA_PSC_RX_A0_PREG}, 7058c2ecf20Sopenharmony_ci {0x0003, SIERRA_PSC_RX_A1_PREG}, 7068c2ecf20Sopenharmony_ci {0x0003, SIERRA_PSC_RX_A2_PREG}, 7078c2ecf20Sopenharmony_ci {0x0001, SIERRA_PSC_RX_A3_PREG}, 7088c2ecf20Sopenharmony_ci {0x0001, SIERRA_PLLCTRL_SUBRATE_PREG}, 7098c2ecf20Sopenharmony_ci {0x0406, SIERRA_PLLCTRL_GEN_D_PREG}, 7108c2ecf20Sopenharmony_ci {0x5233, SIERRA_PLLCTRL_CPGAIN_MODE_PREG}, 7118c2ecf20Sopenharmony_ci {0x00CA, SIERRA_CLKPATH_BIASTRIM_PREG}, 7128c2ecf20Sopenharmony_ci {0x2512, SIERRA_DFE_BIASTRIM_PREG}, 7138c2ecf20Sopenharmony_ci {0x0000, SIERRA_DRVCTRL_ATTEN_PREG}, 7148c2ecf20Sopenharmony_ci {0x823E, SIERRA_CLKPATHCTRL_TMR_PREG}, 7158c2ecf20Sopenharmony_ci {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE1_PREG}, 7168c2ecf20Sopenharmony_ci {0x078F, SIERRA_RX_CREQ_FLTR_A_MODE0_PREG}, 7178c2ecf20Sopenharmony_ci {0x7B3C, SIERRA_CREQ_CCLKDET_MODE01_PREG}, 7188c2ecf20Sopenharmony_ci {0x023C, SIERRA_RX_CTLE_MAINTENANCE_PREG}, 7198c2ecf20Sopenharmony_ci {0x3232, SIERRA_CREQ_FSMCLK_SEL_PREG}, 7208c2ecf20Sopenharmony_ci {0x0000, SIERRA_CREQ_EQ_CTRL_PREG}, 7218c2ecf20Sopenharmony_ci {0x0000, SIERRA_CREQ_SPARE_PREG}, 7228c2ecf20Sopenharmony_ci {0xCC44, SIERRA_CREQ_EQ_OPEN_EYE_THRESH_PREG}, 7238c2ecf20Sopenharmony_ci {0x8452, SIERRA_CTLELUT_CTRL_PREG}, 7248c2ecf20Sopenharmony_ci {0x4121, SIERRA_DFE_ECMP_RATESEL_PREG}, 7258c2ecf20Sopenharmony_ci {0x4121, SIERRA_DFE_SMP_RATESEL_PREG}, 7268c2ecf20Sopenharmony_ci {0x0003, SIERRA_DEQ_PHALIGN_CTRL}, 7278c2ecf20Sopenharmony_ci {0x3200, SIERRA_DEQ_CONCUR_CTRL1_PREG}, 7288c2ecf20Sopenharmony_ci {0x5064, SIERRA_DEQ_CONCUR_CTRL2_PREG}, 7298c2ecf20Sopenharmony_ci {0x0030, SIERRA_DEQ_EPIPWR_CTRL2_PREG}, 7308c2ecf20Sopenharmony_ci {0x0048, SIERRA_DEQ_FAST_MAINT_CYCLES_PREG}, 7318c2ecf20Sopenharmony_ci {0x5A5A, SIERRA_DEQ_ERRCMP_CTRL_PREG}, 7328c2ecf20Sopenharmony_ci {0x02F5, SIERRA_DEQ_OFFSET_CTRL_PREG}, 7338c2ecf20Sopenharmony_ci {0x02F5, SIERRA_DEQ_GAIN_CTRL_PREG}, 7348c2ecf20Sopenharmony_ci {0x9999, SIERRA_DEQ_VGATUNE_CTRL_PREG}, 7358c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT0}, 7368c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT1}, 7378c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT2}, 7388c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT3}, 7398c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT4}, 7408c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT5}, 7418c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT6}, 7428c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT7}, 7438c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT8}, 7448c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT9}, 7458c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT10}, 7468c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT11}, 7478c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT12}, 7488c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT13}, 7498c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT14}, 7508c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT15}, 7518c2ecf20Sopenharmony_ci {0x0014, SIERRA_DEQ_GLUT16}, 7528c2ecf20Sopenharmony_ci {0x0BAE, SIERRA_DEQ_ALUT0}, 7538c2ecf20Sopenharmony_ci {0x0AEB, SIERRA_DEQ_ALUT1}, 7548c2ecf20Sopenharmony_ci {0x0A28, SIERRA_DEQ_ALUT2}, 7558c2ecf20Sopenharmony_ci {0x0965, SIERRA_DEQ_ALUT3}, 7568c2ecf20Sopenharmony_ci {0x08A2, SIERRA_DEQ_ALUT4}, 7578c2ecf20Sopenharmony_ci {0x07DF, SIERRA_DEQ_ALUT5}, 7588c2ecf20Sopenharmony_ci {0x071C, SIERRA_DEQ_ALUT6}, 7598c2ecf20Sopenharmony_ci {0x0659, SIERRA_DEQ_ALUT7}, 7608c2ecf20Sopenharmony_ci {0x0596, SIERRA_DEQ_ALUT8}, 7618c2ecf20Sopenharmony_ci {0x0514, SIERRA_DEQ_ALUT9}, 7628c2ecf20Sopenharmony_ci {0x0492, SIERRA_DEQ_ALUT10}, 7638c2ecf20Sopenharmony_ci {0x0410, SIERRA_DEQ_ALUT11}, 7648c2ecf20Sopenharmony_ci {0x038E, SIERRA_DEQ_ALUT12}, 7658c2ecf20Sopenharmony_ci {0x030C, SIERRA_DEQ_ALUT13}, 7668c2ecf20Sopenharmony_ci {0x03F4, SIERRA_DEQ_DFETAP_CTRL_PREG}, 7678c2ecf20Sopenharmony_ci {0x0001, SIERRA_DFE_EN_1010_IGNORE_PREG}, 7688c2ecf20Sopenharmony_ci {0x3C01, SIERRA_DEQ_TAU_CTRL1_FAST_MAINT_PREG}, 7698c2ecf20Sopenharmony_ci {0x3C40, SIERRA_DEQ_TAU_CTRL1_SLOW_MAINT_PREG}, 7708c2ecf20Sopenharmony_ci {0x1C08, SIERRA_DEQ_TAU_CTRL2_PREG}, 7718c2ecf20Sopenharmony_ci {0x0033, SIERRA_DEQ_PICTRL_PREG}, 7728c2ecf20Sopenharmony_ci {0x0400, SIERRA_CPICAL_TMRVAL_MODE1_PREG}, 7738c2ecf20Sopenharmony_ci {0x0330, SIERRA_CPICAL_TMRVAL_MODE0_PREG}, 7748c2ecf20Sopenharmony_ci {0x01FF, SIERRA_CPICAL_PICNT_MODE1_PREG}, 7758c2ecf20Sopenharmony_ci {0x0009, SIERRA_CPI_OUTBUF_RATESEL_PREG}, 7768c2ecf20Sopenharmony_ci {0x3232, SIERRA_CPICAL_RES_STARTCODE_MODE23_PREG}, 7778c2ecf20Sopenharmony_ci {0x0005, SIERRA_LFPSDET_SUPPORT_PREG}, 7788c2ecf20Sopenharmony_ci {0x000F, SIERRA_LFPSFILT_NS_PREG}, 7798c2ecf20Sopenharmony_ci {0x0009, SIERRA_LFPSFILT_RD_PREG}, 7808c2ecf20Sopenharmony_ci {0x0001, SIERRA_LFPSFILT_MP_PREG}, 7818c2ecf20Sopenharmony_ci {0x6013, SIERRA_SIGDET_SUPPORT_PREG}, 7828c2ecf20Sopenharmony_ci {0x8013, SIERRA_SDFILT_H2L_A_PREG}, 7838c2ecf20Sopenharmony_ci {0x8009, SIERRA_SDFILT_L2H_PREG}, 7848c2ecf20Sopenharmony_ci {0x0024, SIERRA_RXBUFFER_CTLECTRL_PREG}, 7858c2ecf20Sopenharmony_ci {0x0020, SIERRA_RXBUFFER_RCDFECTRL_PREG}, 7868c2ecf20Sopenharmony_ci {0x4243, SIERRA_RXBUFFER_DFECTRL_PREG} 7878c2ecf20Sopenharmony_ci}; 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_cistatic const struct cdns_sierra_data cdns_map_sierra = { 7908c2ecf20Sopenharmony_ci SIERRA_MACRO_ID, 7918c2ecf20Sopenharmony_ci 0x2, 7928c2ecf20Sopenharmony_ci 0x2, 7938c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc), 7948c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc), 7958c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc), 7968c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc), 7978c2ecf20Sopenharmony_ci cdns_pcie_cmn_regs_ext_ssc, 7988c2ecf20Sopenharmony_ci cdns_pcie_ln_regs_ext_ssc, 7998c2ecf20Sopenharmony_ci cdns_usb_cmn_regs_ext_ssc, 8008c2ecf20Sopenharmony_ci cdns_usb_ln_regs_ext_ssc, 8018c2ecf20Sopenharmony_ci}; 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_cistatic const struct cdns_sierra_data cdns_ti_map_sierra = { 8048c2ecf20Sopenharmony_ci SIERRA_MACRO_ID, 8058c2ecf20Sopenharmony_ci 0x0, 8068c2ecf20Sopenharmony_ci 0x1, 8078c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_pcie_cmn_regs_ext_ssc), 8088c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_pcie_ln_regs_ext_ssc), 8098c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_usb_cmn_regs_ext_ssc), 8108c2ecf20Sopenharmony_ci ARRAY_SIZE(cdns_usb_ln_regs_ext_ssc), 8118c2ecf20Sopenharmony_ci cdns_pcie_cmn_regs_ext_ssc, 8128c2ecf20Sopenharmony_ci cdns_pcie_ln_regs_ext_ssc, 8138c2ecf20Sopenharmony_ci cdns_usb_cmn_regs_ext_ssc, 8148c2ecf20Sopenharmony_ci cdns_usb_ln_regs_ext_ssc, 8158c2ecf20Sopenharmony_ci}; 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_cistatic const struct of_device_id cdns_sierra_id_table[] = { 8188c2ecf20Sopenharmony_ci { 8198c2ecf20Sopenharmony_ci .compatible = "cdns,sierra-phy-t0", 8208c2ecf20Sopenharmony_ci .data = &cdns_map_sierra, 8218c2ecf20Sopenharmony_ci }, 8228c2ecf20Sopenharmony_ci { 8238c2ecf20Sopenharmony_ci .compatible = "ti,sierra-phy-t0", 8248c2ecf20Sopenharmony_ci .data = &cdns_ti_map_sierra, 8258c2ecf20Sopenharmony_ci }, 8268c2ecf20Sopenharmony_ci {} 8278c2ecf20Sopenharmony_ci}; 8288c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, cdns_sierra_id_table); 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_cistatic struct platform_driver cdns_sierra_driver = { 8318c2ecf20Sopenharmony_ci .probe = cdns_sierra_phy_probe, 8328c2ecf20Sopenharmony_ci .remove = cdns_sierra_phy_remove, 8338c2ecf20Sopenharmony_ci .driver = { 8348c2ecf20Sopenharmony_ci .name = "cdns-sierra-phy", 8358c2ecf20Sopenharmony_ci .of_match_table = cdns_sierra_id_table, 8368c2ecf20Sopenharmony_ci }, 8378c2ecf20Sopenharmony_ci}; 8388c2ecf20Sopenharmony_cimodule_platform_driver(cdns_sierra_driver); 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:cdns_sierra"); 8418c2ecf20Sopenharmony_ciMODULE_AUTHOR("Cadence Design Systems"); 8428c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("CDNS sierra phy driver"); 8438c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 844