18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. 48c2ecf20Sopenharmony_ci * Copyright (C) 2015 Google, Inc. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/clk.h> 88c2ecf20Sopenharmony_ci#include <linux/clk/tegra.h> 98c2ecf20Sopenharmony_ci#include <linux/delay.h> 108c2ecf20Sopenharmony_ci#include <linux/io.h> 118c2ecf20Sopenharmony_ci#include <linux/mailbox_client.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/of.h> 148c2ecf20Sopenharmony_ci#include <linux/phy/phy.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h> 178c2ecf20Sopenharmony_ci#include <linux/reset.h> 188c2ecf20Sopenharmony_ci#include <linux/slab.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include <soc/tegra/fuse.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include "xusb.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define FUSE_SKU_CALIB_HS_CURR_LEVEL_PADX_SHIFT(x) \ 258c2ecf20Sopenharmony_ci ((x) ? (11 + ((x) - 1) * 6) : 0) 268c2ecf20Sopenharmony_ci#define FUSE_SKU_CALIB_HS_CURR_LEVEL_PAD_MASK 0x3f 278c2ecf20Sopenharmony_ci#define FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_SHIFT 7 288c2ecf20Sopenharmony_ci#define FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_MASK 0xf 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define FUSE_USB_CALIB_EXT_RPD_CTRL_SHIFT 0 318c2ecf20Sopenharmony_ci#define FUSE_USB_CALIB_EXT_RPD_CTRL_MASK 0x1f 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PAD_MUX 0x004 348c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT 16 358c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_MASK 0x3 368c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_XUSB 0x1 378c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT 18 388c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_MASK 0x3 398c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_XUSB 0x1 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PORT_CAP 0x008 428c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DISABLED(x) (0x0 << ((x) * 4)) 438c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_HOST(x) (0x1 << ((x) * 4)) 448c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DEVICE(x) (0x2 << ((x) * 4)) 458c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_OTG(x) (0x3 << ((x) * 4)) 468c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_MASK(x) (0x3 << ((x) * 4)) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define XUSB_PADCTL_SS_PORT_MAP 0x014 498c2ecf20Sopenharmony_ci#define XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(x) (1 << (((x) * 5) + 4)) 508c2ecf20Sopenharmony_ci#define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_SHIFT(x) ((x) * 5) 518c2ecf20Sopenharmony_ci#define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(x) (0x7 << ((x) * 5)) 528c2ecf20Sopenharmony_ci#define XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(x, v) (((v) & 0x7) << ((x) * 5)) 538c2ecf20Sopenharmony_ci#define XUSB_PADCTL_SS_PORT_MAP_PORT_DISABLED 0x7 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define XUSB_PADCTL_ELPG_PROGRAM1 0x024 568c2ecf20Sopenharmony_ci#define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN (1 << 31) 578c2ecf20Sopenharmony_ci#define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY (1 << 30) 588c2ecf20Sopenharmony_ci#define XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN (1 << 29) 598c2ecf20Sopenharmony_ci#define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(x) (1 << (2 + (x) * 3)) 608c2ecf20Sopenharmony_ci#define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(x) \ 618c2ecf20Sopenharmony_ci (1 << (1 + (x) * 3)) 628c2ecf20Sopenharmony_ci#define XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(x) (1 << ((x) * 3)) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB3_PAD_MUX 0x028 658c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(x) (1 << (1 + (x))) 668c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(x) (1 << (8 + (x))) 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL0(x) (0x080 + (x) * 0x40) 698c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIP (1 << 18) 708c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIN (1 << 22) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(x) (0x084 + (x) * 0x40) 738c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT 7 748c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_MASK 0x3 758c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_VAL 0x1 768c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_FIX18 (1 << 6) 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PADX_CTL0(x) (0x088 + (x) * 0x40) 798c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD_ZI (1 << 29) 808c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD2 (1 << 27) 818c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD (1 << 26) 828c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT 0 838c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_MASK 0x3f 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PADX_CTL1(x) (0x08c + (x) * 0x40) 868c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT 26 878c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_MASK 0x1f 888c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT 3 898c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_MASK 0xf 908c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DR (1 << 2) 918c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DISC_OVRD (1 << 1) 928c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_CHRP_OVRD (1 << 0) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0 0x284 958c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD (1 << 11) 968c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT 3 978c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_MASK 0x7 988c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_VAL 0x7 998c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT 0 1008c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_MASK 0x7 1018c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_VAL 0x2 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1 0x288 1048c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_PD_TRK (1 << 26) 1058c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT 19 1068c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_MASK 0x7f 1078c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_VAL 0x0a 1088c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT 12 1098c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_MASK 0x7f 1108c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_VAL 0x1e 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PADX_CTL0(x) (0x300 + (x) * 0x20) 1138c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE (1 << 18) 1148c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1 (1 << 17) 1158c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0 (1 << 16) 1168c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE (1 << 15) 1178c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 (1 << 14) 1188c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 (1 << 13) 1198c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE (1 << 9) 1208c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1 (1 << 8) 1218c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0 (1 << 7) 1228c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE (1 << 6) 1238c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1 (1 << 5) 1248c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0 (1 << 4) 1258c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE (1 << 3) 1268c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1 (1 << 2) 1278c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0 (1 << 1) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PADX_CTL1(x) (0x304 + (x) * 0x20) 1308c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT 0 1318c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_MASK 0xf 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PADX_CTL2(x) (0x308 + (x) * 0x20) 1348c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT 8 1358c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_MASK 0xf 1368c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT 0 1378c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_MASK 0xff 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL 0x340 1408c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL_PD_TRK (1 << 19) 1418c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT 12 1428c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_MASK 0x7f 1438c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_VAL 0x0a 1448c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT 5 1458c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_MASK 0x7f 1468c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_VAL 0x1e 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci#define XUSB_PADCTL_HSIC_STRB_TRIM_CONTROL 0x344 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_P0_CTL1 0x360 1518c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT 20 1528c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK 0xff 1538c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL 0x19 1548c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SATA_VAL 0x1e 1558c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT 16 1568c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK 0x3 1578c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS (1 << 15) 1588c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD (1 << 4) 1598c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE (1 << 3) 1608c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT 1 1618c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK 0x3 1628c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ (1 << 0) 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_P0_CTL2 0x364 1658c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT 4 1668c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK 0xffffff 1678c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL 0x136 1688c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD (1 << 2) 1698c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE (1 << 1) 1708c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN (1 << 0) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_P0_CTL4 0x36c 1738c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_XDIGCLK_EN (1 << 19) 1748c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN (1 << 15) 1758c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT 12 1768c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK 0x3 1778c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL 0x2 1788c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SATA_VAL 0x0 1798c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN (1 << 8) 1808c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT 4 1818c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK 0xf 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_P0_CTL5 0x370 1848c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT 16 1858c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK 0xff 1868c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL 0x2a 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_P0_CTL8 0x37c 1898c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE (1 << 31) 1908c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD (1 << 15) 1918c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN (1 << 13) 1928c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN (1 << 12) 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL1(x) (0x460 + (x) * 0x40) 1958c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT 20 1968c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_MASK 0x3 1978c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_VAL 0x1 1988c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN BIT(18) 1998c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD BIT(13) 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_S0_CTL1 0x860 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_S0_CTL2 0x864 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_S0_CTL4 0x86c 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_S0_CTL5 0x870 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_PLL_S0_CTL8 0x87c 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL1 0x960 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(x) (0xa60 + (x) * 0x40) 2148c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT 16 2158c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_MASK 0x3 2168c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_VAL 0x2 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(x) (0xa64 + (x) * 0x40) 2198c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT 0 2208c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_MASK 0xffff 2218c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_VAL 0x00fc 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PADX_ECTL3(x) (0xa68 + (x) * 0x40) 2248c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL3_RX_DFE_VAL 0xc0077f1f 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(x) (0xa6c + (x) * 0x40) 2278c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT 16 2288c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_MASK 0xffff 2298c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_VAL 0x01c7 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PADX_ECTL6(x) (0xa74 + (x) * 0x40) 2328c2ecf20Sopenharmony_ci#define XUSB_PADCTL_UPHY_USB3_PAD_ECTL6_RX_EQ_CTRL_H_VAL 0xfcf01368 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_VBUS_ID 0xc60 2358c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON (1 << 14) 2368c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT 18 2378c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK 0xf 2388c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_FLOATING 8 2398c2ecf20Sopenharmony_ci#define XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_GROUNDED 0 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_cistruct tegra210_xusb_fuse_calibration { 2428c2ecf20Sopenharmony_ci u32 hs_curr_level[4]; 2438c2ecf20Sopenharmony_ci u32 hs_term_range_adj; 2448c2ecf20Sopenharmony_ci u32 rpd_ctrl; 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistruct tegra210_xusb_padctl { 2488c2ecf20Sopenharmony_ci struct tegra_xusb_padctl base; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci struct tegra210_xusb_fuse_calibration fuse; 2518c2ecf20Sopenharmony_ci}; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_cistatic inline struct tegra210_xusb_padctl * 2548c2ecf20Sopenharmony_cito_tegra210_xusb_padctl(struct tegra_xusb_padctl *padctl) 2558c2ecf20Sopenharmony_ci{ 2568c2ecf20Sopenharmony_ci return container_of(padctl, struct tegra210_xusb_padctl, base); 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* must be called under padctl->lock */ 2608c2ecf20Sopenharmony_cistatic int tegra210_pex_uphy_enable(struct tegra_xusb_padctl *padctl) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci struct tegra_xusb_pcie_pad *pcie = to_pcie_pad(padctl->pcie); 2638c2ecf20Sopenharmony_ci unsigned long timeout; 2648c2ecf20Sopenharmony_ci u32 value; 2658c2ecf20Sopenharmony_ci int err; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci if (pcie->enable > 0) { 2688c2ecf20Sopenharmony_ci pcie->enable++; 2698c2ecf20Sopenharmony_ci return 0; 2708c2ecf20Sopenharmony_ci } 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci err = clk_prepare_enable(pcie->pll); 2738c2ecf20Sopenharmony_ci if (err < 0) 2748c2ecf20Sopenharmony_ci return err; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci err = reset_control_deassert(pcie->rst); 2778c2ecf20Sopenharmony_ci if (err < 0) 2788c2ecf20Sopenharmony_ci goto disable; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 2818c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK << 2828c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT); 2838c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL << 2848c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT; 2858c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL5); 2888c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK << 2898c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT); 2908c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL << 2918c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT; 2928c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL5); 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 2958c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD; 2968c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 2998c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD; 3008c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 3038c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD; 3048c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL4); 3078c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK << 3088c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT) | 3098c2ecf20Sopenharmony_ci (XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK << 3108c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT)); 3118c2ecf20Sopenharmony_ci value |= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL << 3128c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT) | 3138c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN; 3148c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL4); 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3178c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK << 3188c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT) | 3198c2ecf20Sopenharmony_ci (XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK << 3208c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT)); 3218c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL << 3228c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT; 3238c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3268c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ; 3278c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3308c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK << 3318c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT); 3328c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci usleep_range(10, 20); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL4); 3378c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN; 3388c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL4); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 3418c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN; 3428c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 3478c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 3488c2ecf20Sopenharmony_ci if (value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE) 3498c2ecf20Sopenharmony_ci break; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci usleep_range(10, 20); 3528c2ecf20Sopenharmony_ci } 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 3558c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 3568c2ecf20Sopenharmony_ci goto reset; 3578c2ecf20Sopenharmony_ci } 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 3608c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN; 3618c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 3668c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 3678c2ecf20Sopenharmony_ci if (!(value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE)) 3688c2ecf20Sopenharmony_ci break; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci usleep_range(10, 20); 3718c2ecf20Sopenharmony_ci } 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 3748c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 3758c2ecf20Sopenharmony_ci goto reset; 3768c2ecf20Sopenharmony_ci } 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3798c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE; 3808c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 3858c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 3868c2ecf20Sopenharmony_ci if (value & XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS) 3878c2ecf20Sopenharmony_ci break; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci usleep_range(10, 20); 3908c2ecf20Sopenharmony_ci } 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 3938c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 3948c2ecf20Sopenharmony_ci goto reset; 3958c2ecf20Sopenharmony_ci } 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 3988c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN | 3998c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN; 4008c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 4058c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4068c2ecf20Sopenharmony_ci if (value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE) 4078c2ecf20Sopenharmony_ci break; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci usleep_range(10, 20); 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 4138c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 4148c2ecf20Sopenharmony_ci goto reset; 4158c2ecf20Sopenharmony_ci } 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4188c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN; 4198c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 4248c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4258c2ecf20Sopenharmony_ci if (!(value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE)) 4268c2ecf20Sopenharmony_ci break; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci usleep_range(10, 20); 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 4328c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 4338c2ecf20Sopenharmony_ci goto reset; 4348c2ecf20Sopenharmony_ci } 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4378c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN; 4388c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci tegra210_xusb_pll_hw_control_enable(); 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 4438c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD; 4448c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 4478c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD; 4488c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4518c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD; 4528c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci usleep_range(10, 20); 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci tegra210_xusb_pll_hw_sequence_start(); 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci pcie->enable++; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci return 0; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_cireset: 4638c2ecf20Sopenharmony_ci reset_control_assert(pcie->rst); 4648c2ecf20Sopenharmony_cidisable: 4658c2ecf20Sopenharmony_ci clk_disable_unprepare(pcie->pll); 4668c2ecf20Sopenharmony_ci return err; 4678c2ecf20Sopenharmony_ci} 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_cistatic void tegra210_pex_uphy_disable(struct tegra_xusb_padctl *padctl) 4708c2ecf20Sopenharmony_ci{ 4718c2ecf20Sopenharmony_ci struct tegra_xusb_pcie_pad *pcie = to_pcie_pad(padctl->pcie); 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci if (WARN_ON(pcie->enable == 0)) 4768c2ecf20Sopenharmony_ci goto unlock; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci if (--pcie->enable > 0) 4798c2ecf20Sopenharmony_ci goto unlock; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci reset_control_assert(pcie->rst); 4828c2ecf20Sopenharmony_ci clk_disable_unprepare(pcie->pll); 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ciunlock: 4858c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 4868c2ecf20Sopenharmony_ci} 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci/* must be called under padctl->lock */ 4898c2ecf20Sopenharmony_cistatic int tegra210_sata_uphy_enable(struct tegra_xusb_padctl *padctl, bool usb) 4908c2ecf20Sopenharmony_ci{ 4918c2ecf20Sopenharmony_ci struct tegra_xusb_sata_pad *sata = to_sata_pad(padctl->sata); 4928c2ecf20Sopenharmony_ci unsigned long timeout; 4938c2ecf20Sopenharmony_ci u32 value; 4948c2ecf20Sopenharmony_ci int err; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci if (sata->enable > 0) { 4978c2ecf20Sopenharmony_ci sata->enable++; 4988c2ecf20Sopenharmony_ci return 0; 4998c2ecf20Sopenharmony_ci } 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci err = clk_prepare_enable(sata->pll); 5028c2ecf20Sopenharmony_ci if (err < 0) 5038c2ecf20Sopenharmony_ci return err; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci err = reset_control_deassert(sata->rst); 5068c2ecf20Sopenharmony_ci if (err < 0) 5078c2ecf20Sopenharmony_ci goto disable; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 5108c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_MASK << 5118c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT); 5128c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_VAL << 5138c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL2_CAL_CTRL_SHIFT; 5148c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL5); 5178c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_MASK << 5188c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT); 5198c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_VAL << 5208c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL5_DCO_CTRL_SHIFT; 5218c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL5); 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5248c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD; 5258c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 5288c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD; 5298c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 5328c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD; 5338c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL4); 5368c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_MASK << 5378c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT) | 5388c2ecf20Sopenharmony_ci (XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_MASK << 5398c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_REFCLK_SEL_SHIFT)); 5408c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_EN; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci if (usb) 5438c2ecf20Sopenharmony_ci value |= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_USB_VAL << 5448c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT); 5458c2ecf20Sopenharmony_ci else 5468c2ecf20Sopenharmony_ci value |= (XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SATA_VAL << 5478c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL4_TXCLKREF_SEL_SHIFT); 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL4_XDIGCLK_EN; 5508c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL4); 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5538c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_MASK << 5548c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_MDIV_SHIFT) | 5558c2ecf20Sopenharmony_ci (XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_MASK << 5568c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT)); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci if (usb) 5598c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_USB_VAL << 5608c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT; 5618c2ecf20Sopenharmony_ci else 5628c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SATA_VAL << 5638c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_FREQ_NDIV_SHIFT; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5688c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_IDDQ; 5698c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5728c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_MASK << 5738c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL1_SLEEP_SHIFT); 5748c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci usleep_range(10, 20); 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL4); 5798c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL4_REFCLKBUF_EN; 5808c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL4); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 5838c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN; 5848c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 5898c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 5908c2ecf20Sopenharmony_ci if (value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE) 5918c2ecf20Sopenharmony_ci break; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci usleep_range(10, 20); 5948c2ecf20Sopenharmony_ci } 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 5978c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 5988c2ecf20Sopenharmony_ci goto reset; 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 6028c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_EN; 6038c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 6088c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 6098c2ecf20Sopenharmony_ci if (!(value & XUSB_PADCTL_UPHY_PLL_CTL2_CAL_DONE)) 6108c2ecf20Sopenharmony_ci break; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci usleep_range(10, 20); 6138c2ecf20Sopenharmony_ci } 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 6168c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 6178c2ecf20Sopenharmony_ci goto reset; 6188c2ecf20Sopenharmony_ci } 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 6218c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL1_ENABLE; 6228c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 6278c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 6288c2ecf20Sopenharmony_ci if (value & XUSB_PADCTL_UPHY_PLL_CTL1_LOCKDET_STATUS) 6298c2ecf20Sopenharmony_ci break; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci usleep_range(10, 20); 6328c2ecf20Sopenharmony_ci } 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 6358c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 6368c2ecf20Sopenharmony_ci goto reset; 6378c2ecf20Sopenharmony_ci } 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6408c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN | 6418c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN; 6428c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 6478c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6488c2ecf20Sopenharmony_ci if (value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE) 6498c2ecf20Sopenharmony_ci break; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci usleep_range(10, 20); 6528c2ecf20Sopenharmony_ci } 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 6558c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 6568c2ecf20Sopenharmony_ci goto reset; 6578c2ecf20Sopenharmony_ci } 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6608c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_EN; 6618c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci timeout = jiffies + msecs_to_jiffies(100); 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci while (time_before(jiffies, timeout)) { 6668c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6678c2ecf20Sopenharmony_ci if (!(value & XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_DONE)) 6688c2ecf20Sopenharmony_ci break; 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci usleep_range(10, 20); 6718c2ecf20Sopenharmony_ci } 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci if (time_after_eq(jiffies, timeout)) { 6748c2ecf20Sopenharmony_ci err = -ETIMEDOUT; 6758c2ecf20Sopenharmony_ci goto reset; 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6798c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_CLK_EN; 6808c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci tegra210_sata_pll_hw_control_enable(); 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 6858c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL1_PWR_OVRD; 6868c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL1); 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 6898c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL2_CAL_OVRD; 6908c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL2); 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6938c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_UPHY_PLL_CTL8_RCAL_OVRD; 6948c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_S0_CTL8); 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci usleep_range(10, 20); 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci tegra210_sata_pll_hw_sequence_start(); 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci sata->enable++; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci return 0; 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_cireset: 7058c2ecf20Sopenharmony_ci reset_control_assert(sata->rst); 7068c2ecf20Sopenharmony_cidisable: 7078c2ecf20Sopenharmony_ci clk_disable_unprepare(sata->pll); 7088c2ecf20Sopenharmony_ci return err; 7098c2ecf20Sopenharmony_ci} 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_cistatic void tegra210_sata_uphy_disable(struct tegra_xusb_padctl *padctl) 7128c2ecf20Sopenharmony_ci{ 7138c2ecf20Sopenharmony_ci struct tegra_xusb_sata_pad *sata = to_sata_pad(padctl->sata); 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci if (WARN_ON(sata->enable == 0)) 7188c2ecf20Sopenharmony_ci goto unlock; 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci if (--sata->enable > 0) 7218c2ecf20Sopenharmony_ci goto unlock; 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci reset_control_assert(sata->rst); 7248c2ecf20Sopenharmony_ci clk_disable_unprepare(sata->pll); 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ciunlock: 7278c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 7288c2ecf20Sopenharmony_ci} 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_cistatic int tegra210_xusb_padctl_enable(struct tegra_xusb_padctl *padctl) 7318c2ecf20Sopenharmony_ci{ 7328c2ecf20Sopenharmony_ci u32 value; 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci if (padctl->enable++ > 0) 7378c2ecf20Sopenharmony_ci goto out; 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 7408c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN; 7418c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci usleep_range(100, 200); 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 7468c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY; 7478c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci usleep_range(100, 200); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 7528c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN; 7538c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ciout: 7568c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 7578c2ecf20Sopenharmony_ci return 0; 7588c2ecf20Sopenharmony_ci} 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_cistatic int tegra210_xusb_padctl_disable(struct tegra_xusb_padctl *padctl) 7618c2ecf20Sopenharmony_ci{ 7628c2ecf20Sopenharmony_ci u32 value; 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci if (WARN_ON(padctl->enable == 0)) 7678c2ecf20Sopenharmony_ci goto out; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci if (--padctl->enable > 0) 7708c2ecf20Sopenharmony_ci goto out; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 7738c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_VCORE_DOWN; 7748c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci usleep_range(100, 200); 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 7798c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN_EARLY; 7808c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci usleep_range(100, 200); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 7858c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_AUX_MUX_LP0_CLAMP_EN; 7868c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ciout: 7898c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 7908c2ecf20Sopenharmony_ci return 0; 7918c2ecf20Sopenharmony_ci} 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_cistatic int tegra210_hsic_set_idle(struct tegra_xusb_padctl *padctl, 7948c2ecf20Sopenharmony_ci unsigned int index, bool idle) 7958c2ecf20Sopenharmony_ci{ 7968c2ecf20Sopenharmony_ci u32 value; 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL0(index)); 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0 | 8018c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1 | 8028c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE); 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci if (idle) 8058c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 | 8068c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 | 8078c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE; 8088c2ecf20Sopenharmony_ci else 8098c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 | 8108c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 | 8118c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE); 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL0(index)); 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci return 0; 8168c2ecf20Sopenharmony_ci} 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_cistatic int tegra210_usb3_set_lfps_detect(struct tegra_xusb_padctl *padctl, 8198c2ecf20Sopenharmony_ci unsigned int index, bool enable) 8208c2ecf20Sopenharmony_ci{ 8218c2ecf20Sopenharmony_ci struct tegra_xusb_port *port; 8228c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane; 8238c2ecf20Sopenharmony_ci u32 value, offset; 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci port = tegra_xusb_find_port(padctl, "usb3", index); 8268c2ecf20Sopenharmony_ci if (!port) 8278c2ecf20Sopenharmony_ci return -ENODEV; 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci lane = port->lane; 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci if (lane->pad == padctl->pcie) 8328c2ecf20Sopenharmony_ci offset = XUSB_PADCTL_UPHY_MISC_PAD_PX_CTL1(lane->index); 8338c2ecf20Sopenharmony_ci else 8348c2ecf20Sopenharmony_ci offset = XUSB_PADCTL_UPHY_MISC_PAD_S0_CTL1; 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci value = padctl_readl(padctl, offset); 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_MASK << 8398c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT) | 8408c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN | 8418c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD); 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci if (!enable) { 8448c2ecf20Sopenharmony_ci value |= (XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_VAL << 8458c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_IDLE_MODE_SHIFT) | 8468c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_TERM_EN | 8478c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_MISC_PAD_CTL1_AUX_RX_MODE_OVRD; 8488c2ecf20Sopenharmony_ci } 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_ci padctl_writel(padctl, value, offset); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci return 0; 8538c2ecf20Sopenharmony_ci} 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci#define TEGRA210_LANE(_name, _offset, _shift, _mask, _type) \ 8568c2ecf20Sopenharmony_ci { \ 8578c2ecf20Sopenharmony_ci .name = _name, \ 8588c2ecf20Sopenharmony_ci .offset = _offset, \ 8598c2ecf20Sopenharmony_ci .shift = _shift, \ 8608c2ecf20Sopenharmony_ci .mask = _mask, \ 8618c2ecf20Sopenharmony_ci .num_funcs = ARRAY_SIZE(tegra210_##_type##_functions), \ 8628c2ecf20Sopenharmony_ci .funcs = tegra210_##_type##_functions, \ 8638c2ecf20Sopenharmony_ci } 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_cistatic const char *tegra210_usb2_functions[] = { 8668c2ecf20Sopenharmony_ci "snps", 8678c2ecf20Sopenharmony_ci "xusb", 8688c2ecf20Sopenharmony_ci "uart" 8698c2ecf20Sopenharmony_ci}; 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_soc tegra210_usb2_lanes[] = { 8728c2ecf20Sopenharmony_ci TEGRA210_LANE("usb2-0", 0x004, 0, 0x3, usb2), 8738c2ecf20Sopenharmony_ci TEGRA210_LANE("usb2-1", 0x004, 2, 0x3, usb2), 8748c2ecf20Sopenharmony_ci TEGRA210_LANE("usb2-2", 0x004, 4, 0x3, usb2), 8758c2ecf20Sopenharmony_ci TEGRA210_LANE("usb2-3", 0x004, 6, 0x3, usb2), 8768c2ecf20Sopenharmony_ci}; 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_cistatic struct tegra_xusb_lane * 8798c2ecf20Sopenharmony_citegra210_usb2_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np, 8808c2ecf20Sopenharmony_ci unsigned int index) 8818c2ecf20Sopenharmony_ci{ 8828c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_lane *usb2; 8838c2ecf20Sopenharmony_ci int err; 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); 8868c2ecf20Sopenharmony_ci if (!usb2) 8878c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&usb2->base.list); 8908c2ecf20Sopenharmony_ci usb2->base.soc = &pad->soc->lanes[index]; 8918c2ecf20Sopenharmony_ci usb2->base.index = index; 8928c2ecf20Sopenharmony_ci usb2->base.pad = pad; 8938c2ecf20Sopenharmony_ci usb2->base.np = np; 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci err = tegra_xusb_lane_parse_dt(&usb2->base, np); 8968c2ecf20Sopenharmony_ci if (err < 0) { 8978c2ecf20Sopenharmony_ci kfree(usb2); 8988c2ecf20Sopenharmony_ci return ERR_PTR(err); 8998c2ecf20Sopenharmony_ci } 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ci return &usb2->base; 9028c2ecf20Sopenharmony_ci} 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_cistatic void tegra210_usb2_lane_remove(struct tegra_xusb_lane *lane) 9058c2ecf20Sopenharmony_ci{ 9068c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane); 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci kfree(usb2); 9098c2ecf20Sopenharmony_ci} 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_ops tegra210_usb2_lane_ops = { 9128c2ecf20Sopenharmony_ci .probe = tegra210_usb2_lane_probe, 9138c2ecf20Sopenharmony_ci .remove = tegra210_usb2_lane_remove, 9148c2ecf20Sopenharmony_ci}; 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_cistatic int tegra210_usb2_phy_init(struct phy *phy) 9178c2ecf20Sopenharmony_ci{ 9188c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 9198c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 9208c2ecf20Sopenharmony_ci u32 value; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX); 9238c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_MASK << 9248c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT); 9258c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_XUSB << 9268c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_PAD_MUX_USB2_BIAS_PAD_SHIFT; 9278c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_PAD_MUX); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_enable(padctl); 9308c2ecf20Sopenharmony_ci} 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_cistatic int tegra210_usb2_phy_exit(struct phy *phy) 9338c2ecf20Sopenharmony_ci{ 9348c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_disable(lane->pad->padctl); 9378c2ecf20Sopenharmony_ci} 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_cistatic int tegra210_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl, 9408c2ecf20Sopenharmony_ci bool status) 9418c2ecf20Sopenharmony_ci{ 9428c2ecf20Sopenharmony_ci u32 value; 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear"); 9458c2ecf20Sopenharmony_ci 9468c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_VBUS_ID); 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci if (status) { 9498c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON; 9508c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK << 9518c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT); 9528c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_FLOATING << 9538c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT; 9548c2ecf20Sopenharmony_ci } else { 9558c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON; 9568c2ecf20Sopenharmony_ci } 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_VBUS_ID); 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_ci return 0; 9618c2ecf20Sopenharmony_ci} 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_cistatic int tegra210_xusb_padctl_id_override(struct tegra_xusb_padctl *padctl, 9648c2ecf20Sopenharmony_ci bool status) 9658c2ecf20Sopenharmony_ci{ 9668c2ecf20Sopenharmony_ci u32 value; 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ci dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear"); 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_VBUS_ID); 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci if (status) { 9738c2ecf20Sopenharmony_ci if (value & XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON) { 9748c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_VBUS_ON; 9758c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_VBUS_ID); 9768c2ecf20Sopenharmony_ci usleep_range(1000, 2000); 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_VBUS_ID); 9798c2ecf20Sopenharmony_ci } 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK << 9828c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT); 9838c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_GROUNDED << 9848c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT; 9858c2ecf20Sopenharmony_ci } else { 9868c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_MASK << 9878c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT); 9888c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_FLOATING << 9898c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_VBUS_ID_OVERRIDE_SHIFT; 9908c2ecf20Sopenharmony_ci } 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_VBUS_ID); 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_ci return 0; 9958c2ecf20Sopenharmony_ci} 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_cistatic int tegra210_usb2_phy_set_mode(struct phy *phy, enum phy_mode mode, 9988c2ecf20Sopenharmony_ci int submode) 9998c2ecf20Sopenharmony_ci{ 10008c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 10018c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 10028c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_port *port = tegra_xusb_find_usb2_port(padctl, 10038c2ecf20Sopenharmony_ci lane->index); 10048c2ecf20Sopenharmony_ci int err = 0; 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode); 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci if (mode == PHY_MODE_USB_OTG) { 10118c2ecf20Sopenharmony_ci if (submode == USB_ROLE_HOST) { 10128c2ecf20Sopenharmony_ci tegra210_xusb_padctl_id_override(padctl, true); 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci err = regulator_enable(port->supply); 10158c2ecf20Sopenharmony_ci } else if (submode == USB_ROLE_DEVICE) { 10168c2ecf20Sopenharmony_ci tegra210_xusb_padctl_vbus_override(padctl, true); 10178c2ecf20Sopenharmony_ci } else if (submode == USB_ROLE_NONE) { 10188c2ecf20Sopenharmony_ci /* 10198c2ecf20Sopenharmony_ci * When port is peripheral only or role transitions to 10208c2ecf20Sopenharmony_ci * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not 10218c2ecf20Sopenharmony_ci * be enabled. 10228c2ecf20Sopenharmony_ci */ 10238c2ecf20Sopenharmony_ci if (regulator_is_enabled(port->supply)) 10248c2ecf20Sopenharmony_ci regulator_disable(port->supply); 10258c2ecf20Sopenharmony_ci 10268c2ecf20Sopenharmony_ci tegra210_xusb_padctl_id_override(padctl, false); 10278c2ecf20Sopenharmony_ci tegra210_xusb_padctl_vbus_override(padctl, false); 10288c2ecf20Sopenharmony_ci } 10298c2ecf20Sopenharmony_ci } 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ci return err; 10348c2ecf20Sopenharmony_ci} 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_cistatic int tegra210_usb2_phy_power_on(struct phy *phy) 10378c2ecf20Sopenharmony_ci{ 10388c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 10398c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane); 10408c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_pad *pad = to_usb2_pad(lane->pad); 10418c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 10428c2ecf20Sopenharmony_ci struct tegra210_xusb_padctl *priv; 10438c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_port *port; 10448c2ecf20Sopenharmony_ci unsigned int index = lane->index; 10458c2ecf20Sopenharmony_ci u32 value; 10468c2ecf20Sopenharmony_ci int err; 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci port = tegra_xusb_find_usb2_port(padctl, index); 10498c2ecf20Sopenharmony_ci if (!port) { 10508c2ecf20Sopenharmony_ci dev_err(&phy->dev, "no port found for USB2 lane %u\n", index); 10518c2ecf20Sopenharmony_ci return -ENODEV; 10528c2ecf20Sopenharmony_ci } 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci priv = to_tegra210_xusb_padctl(padctl); 10558c2ecf20Sopenharmony_ci 10568c2ecf20Sopenharmony_ci if (port->usb3_port_fake != -1) { 10578c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_MAP); 10588c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK( 10598c2ecf20Sopenharmony_ci port->usb3_port_fake); 10608c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP( 10618c2ecf20Sopenharmony_ci port->usb3_port_fake, index); 10628c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_MAP); 10638c2ecf20Sopenharmony_ci 10648c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 10658c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN( 10668c2ecf20Sopenharmony_ci port->usb3_port_fake); 10678c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci usleep_range(100, 200); 10708c2ecf20Sopenharmony_ci 10718c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 10728c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY( 10738c2ecf20Sopenharmony_ci port->usb3_port_fake); 10748c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci usleep_range(100, 200); 10778c2ecf20Sopenharmony_ci 10788c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 10798c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN( 10808c2ecf20Sopenharmony_ci port->usb3_port_fake); 10818c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 10828c2ecf20Sopenharmony_ci } 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); 10858c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_MASK << 10868c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT) | 10878c2ecf20Sopenharmony_ci (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_MASK << 10888c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT)); 10898c2ecf20Sopenharmony_ci value |= (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_VAL << 10908c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_DISCON_LEVEL_SHIFT); 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_ci if (tegra_sku_info.revision < TEGRA_REVISION_A02) 10938c2ecf20Sopenharmony_ci value |= 10948c2ecf20Sopenharmony_ci (XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_VAL << 10958c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL_SHIFT); 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); 10988c2ecf20Sopenharmony_ci 10998c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP); 11008c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_MASK(index); 11018c2ecf20Sopenharmony_ci if (port->mode == USB_DR_MODE_UNKNOWN) 11028c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DISABLED(index); 11038c2ecf20Sopenharmony_ci else if (port->mode == USB_DR_MODE_PERIPHERAL) 11048c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_DEVICE(index); 11058c2ecf20Sopenharmony_ci else if (port->mode == USB_DR_MODE_HOST) 11068c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_HOST(index); 11078c2ecf20Sopenharmony_ci else if (port->mode == USB_DR_MODE_OTG) 11088c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_PORT_CAP_PORTX_CAP_OTG(index); 11098c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_PORT_CAP); 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); 11128c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_MASK << 11138c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT) | 11148c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD | 11158c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD2 | 11168c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD_ZI); 11178c2ecf20Sopenharmony_ci value |= (priv->fuse.hs_curr_level[index] + 11188c2ecf20Sopenharmony_ci usb2->hs_curr_level_offset) << 11198c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT; 11208c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index)); 11218c2ecf20Sopenharmony_ci 11228c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); 11238c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_MASK << 11248c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT) | 11258c2ecf20Sopenharmony_ci (XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_MASK << 11268c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT) | 11278c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DR | 11288c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_CHRP_OVRD | 11298c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL1_PD_DISC_OVRD); 11308c2ecf20Sopenharmony_ci value |= (priv->fuse.hs_term_range_adj << 11318c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ_SHIFT) | 11328c2ecf20Sopenharmony_ci (priv->fuse.rpd_ctrl << 11338c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_OTG_PAD_CTL1_RPD_CTRL_SHIFT); 11348c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index)); 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci value = padctl_readl(padctl, 11378c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(index)); 11388c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_MASK << 11398c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT); 11408c2ecf20Sopenharmony_ci if (port->mode == USB_DR_MODE_HOST) 11418c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_FIX18; 11428c2ecf20Sopenharmony_ci else 11438c2ecf20Sopenharmony_ci value |= 11448c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_VAL << 11458c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL1_VREG_LEV_SHIFT; 11468c2ecf20Sopenharmony_ci padctl_writel(padctl, value, 11478c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL1(index)); 11488c2ecf20Sopenharmony_ci 11498c2ecf20Sopenharmony_ci if (port->supply && port->mode == USB_DR_MODE_HOST) { 11508c2ecf20Sopenharmony_ci err = regulator_enable(port->supply); 11518c2ecf20Sopenharmony_ci if (err) 11528c2ecf20Sopenharmony_ci return err; 11538c2ecf20Sopenharmony_ci } 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci if (pad->enable > 0) { 11588c2ecf20Sopenharmony_ci pad->enable++; 11598c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 11608c2ecf20Sopenharmony_ci return 0; 11618c2ecf20Sopenharmony_ci } 11628c2ecf20Sopenharmony_ci 11638c2ecf20Sopenharmony_ci err = clk_prepare_enable(pad->clk); 11648c2ecf20Sopenharmony_ci if (err) 11658c2ecf20Sopenharmony_ci goto disable_regulator; 11668c2ecf20Sopenharmony_ci 11678c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); 11688c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_MASK << 11698c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT) | 11708c2ecf20Sopenharmony_ci (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_MASK << 11718c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT)); 11728c2ecf20Sopenharmony_ci value |= (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_VAL << 11738c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_START_TIMER_SHIFT) | 11748c2ecf20Sopenharmony_ci (XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_VAL << 11758c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BIAS_PAD_CTL1_TRK_DONE_RESET_TIMER_SHIFT); 11768c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); 11778c2ecf20Sopenharmony_ci 11788c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); 11798c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD; 11808c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); 11818c2ecf20Sopenharmony_ci 11828c2ecf20Sopenharmony_ci udelay(1); 11838c2ecf20Sopenharmony_ci 11848c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); 11858c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_USB2_BIAS_PAD_CTL1_PD_TRK; 11868c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL1); 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci udelay(50); 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci clk_disable_unprepare(pad->clk); 11918c2ecf20Sopenharmony_ci 11928c2ecf20Sopenharmony_ci pad->enable++; 11938c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 11948c2ecf20Sopenharmony_ci 11958c2ecf20Sopenharmony_ci return 0; 11968c2ecf20Sopenharmony_ci 11978c2ecf20Sopenharmony_cidisable_regulator: 11988c2ecf20Sopenharmony_ci regulator_disable(port->supply); 11998c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 12008c2ecf20Sopenharmony_ci return err; 12018c2ecf20Sopenharmony_ci} 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_cistatic int tegra210_usb2_phy_power_off(struct phy *phy) 12048c2ecf20Sopenharmony_ci{ 12058c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 12068c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_pad *pad = to_usb2_pad(lane->pad); 12078c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 12088c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_port *port; 12098c2ecf20Sopenharmony_ci u32 value; 12108c2ecf20Sopenharmony_ci 12118c2ecf20Sopenharmony_ci port = tegra_xusb_find_usb2_port(padctl, lane->index); 12128c2ecf20Sopenharmony_ci if (!port) { 12138c2ecf20Sopenharmony_ci dev_err(&phy->dev, "no port found for USB2 lane %u\n", 12148c2ecf20Sopenharmony_ci lane->index); 12158c2ecf20Sopenharmony_ci return -ENODEV; 12168c2ecf20Sopenharmony_ci } 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci if (port->usb3_port_fake != -1) { 12218c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 12228c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY( 12238c2ecf20Sopenharmony_ci port->usb3_port_fake); 12248c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci usleep_range(100, 200); 12278c2ecf20Sopenharmony_ci 12288c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 12298c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN( 12308c2ecf20Sopenharmony_ci port->usb3_port_fake); 12318c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 12328c2ecf20Sopenharmony_ci 12338c2ecf20Sopenharmony_ci usleep_range(250, 350); 12348c2ecf20Sopenharmony_ci 12358c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 12368c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN( 12378c2ecf20Sopenharmony_ci port->usb3_port_fake); 12388c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_MAP); 12418c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(port->usb3_port_fake, 12428c2ecf20Sopenharmony_ci XUSB_PADCTL_SS_PORT_MAP_PORT_DISABLED); 12438c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_MAP); 12448c2ecf20Sopenharmony_ci } 12458c2ecf20Sopenharmony_ci 12468c2ecf20Sopenharmony_ci if (WARN_ON(pad->enable == 0)) 12478c2ecf20Sopenharmony_ci goto out; 12488c2ecf20Sopenharmony_ci 12498c2ecf20Sopenharmony_ci if (--pad->enable > 0) 12508c2ecf20Sopenharmony_ci goto out; 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); 12538c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_BIAS_PAD_CTL0_PD; 12548c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0); 12558c2ecf20Sopenharmony_ci 12568c2ecf20Sopenharmony_ciout: 12578c2ecf20Sopenharmony_ci regulator_disable(port->supply); 12588c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 12598c2ecf20Sopenharmony_ci return 0; 12608c2ecf20Sopenharmony_ci} 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_cistatic const struct phy_ops tegra210_usb2_phy_ops = { 12638c2ecf20Sopenharmony_ci .init = tegra210_usb2_phy_init, 12648c2ecf20Sopenharmony_ci .exit = tegra210_usb2_phy_exit, 12658c2ecf20Sopenharmony_ci .power_on = tegra210_usb2_phy_power_on, 12668c2ecf20Sopenharmony_ci .power_off = tegra210_usb2_phy_power_off, 12678c2ecf20Sopenharmony_ci .set_mode = tegra210_usb2_phy_set_mode, 12688c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 12698c2ecf20Sopenharmony_ci}; 12708c2ecf20Sopenharmony_ci 12718c2ecf20Sopenharmony_cistatic struct tegra_xusb_pad * 12728c2ecf20Sopenharmony_citegra210_usb2_pad_probe(struct tegra_xusb_padctl *padctl, 12738c2ecf20Sopenharmony_ci const struct tegra_xusb_pad_soc *soc, 12748c2ecf20Sopenharmony_ci struct device_node *np) 12758c2ecf20Sopenharmony_ci{ 12768c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_pad *usb2; 12778c2ecf20Sopenharmony_ci struct tegra_xusb_pad *pad; 12788c2ecf20Sopenharmony_ci int err; 12798c2ecf20Sopenharmony_ci 12808c2ecf20Sopenharmony_ci usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); 12818c2ecf20Sopenharmony_ci if (!usb2) 12828c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 12838c2ecf20Sopenharmony_ci 12848c2ecf20Sopenharmony_ci pad = &usb2->base; 12858c2ecf20Sopenharmony_ci pad->ops = &tegra210_usb2_lane_ops; 12868c2ecf20Sopenharmony_ci pad->soc = soc; 12878c2ecf20Sopenharmony_ci 12888c2ecf20Sopenharmony_ci err = tegra_xusb_pad_init(pad, padctl, np); 12898c2ecf20Sopenharmony_ci if (err < 0) { 12908c2ecf20Sopenharmony_ci kfree(usb2); 12918c2ecf20Sopenharmony_ci goto out; 12928c2ecf20Sopenharmony_ci } 12938c2ecf20Sopenharmony_ci 12948c2ecf20Sopenharmony_ci usb2->clk = devm_clk_get(&pad->dev, "trk"); 12958c2ecf20Sopenharmony_ci if (IS_ERR(usb2->clk)) { 12968c2ecf20Sopenharmony_ci err = PTR_ERR(usb2->clk); 12978c2ecf20Sopenharmony_ci dev_err(&pad->dev, "failed to get trk clock: %d\n", err); 12988c2ecf20Sopenharmony_ci goto unregister; 12998c2ecf20Sopenharmony_ci } 13008c2ecf20Sopenharmony_ci 13018c2ecf20Sopenharmony_ci err = tegra_xusb_pad_register(pad, &tegra210_usb2_phy_ops); 13028c2ecf20Sopenharmony_ci if (err < 0) 13038c2ecf20Sopenharmony_ci goto unregister; 13048c2ecf20Sopenharmony_ci 13058c2ecf20Sopenharmony_ci dev_set_drvdata(&pad->dev, pad); 13068c2ecf20Sopenharmony_ci 13078c2ecf20Sopenharmony_ci return pad; 13088c2ecf20Sopenharmony_ci 13098c2ecf20Sopenharmony_ciunregister: 13108c2ecf20Sopenharmony_ci device_unregister(&pad->dev); 13118c2ecf20Sopenharmony_ciout: 13128c2ecf20Sopenharmony_ci return ERR_PTR(err); 13138c2ecf20Sopenharmony_ci} 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_cistatic void tegra210_usb2_pad_remove(struct tegra_xusb_pad *pad) 13168c2ecf20Sopenharmony_ci{ 13178c2ecf20Sopenharmony_ci struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad); 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci kfree(usb2); 13208c2ecf20Sopenharmony_ci} 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_ops tegra210_usb2_ops = { 13238c2ecf20Sopenharmony_ci .probe = tegra210_usb2_pad_probe, 13248c2ecf20Sopenharmony_ci .remove = tegra210_usb2_pad_remove, 13258c2ecf20Sopenharmony_ci}; 13268c2ecf20Sopenharmony_ci 13278c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_soc tegra210_usb2_pad = { 13288c2ecf20Sopenharmony_ci .name = "usb2", 13298c2ecf20Sopenharmony_ci .num_lanes = ARRAY_SIZE(tegra210_usb2_lanes), 13308c2ecf20Sopenharmony_ci .lanes = tegra210_usb2_lanes, 13318c2ecf20Sopenharmony_ci .ops = &tegra210_usb2_ops, 13328c2ecf20Sopenharmony_ci}; 13338c2ecf20Sopenharmony_ci 13348c2ecf20Sopenharmony_cistatic const char *tegra210_hsic_functions[] = { 13358c2ecf20Sopenharmony_ci "snps", 13368c2ecf20Sopenharmony_ci "xusb", 13378c2ecf20Sopenharmony_ci}; 13388c2ecf20Sopenharmony_ci 13398c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_soc tegra210_hsic_lanes[] = { 13408c2ecf20Sopenharmony_ci TEGRA210_LANE("hsic-0", 0x004, 14, 0x1, hsic), 13418c2ecf20Sopenharmony_ci}; 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_cistatic struct tegra_xusb_lane * 13448c2ecf20Sopenharmony_citegra210_hsic_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np, 13458c2ecf20Sopenharmony_ci unsigned int index) 13468c2ecf20Sopenharmony_ci{ 13478c2ecf20Sopenharmony_ci struct tegra_xusb_hsic_lane *hsic; 13488c2ecf20Sopenharmony_ci int err; 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci hsic = kzalloc(sizeof(*hsic), GFP_KERNEL); 13518c2ecf20Sopenharmony_ci if (!hsic) 13528c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&hsic->base.list); 13558c2ecf20Sopenharmony_ci hsic->base.soc = &pad->soc->lanes[index]; 13568c2ecf20Sopenharmony_ci hsic->base.index = index; 13578c2ecf20Sopenharmony_ci hsic->base.pad = pad; 13588c2ecf20Sopenharmony_ci hsic->base.np = np; 13598c2ecf20Sopenharmony_ci 13608c2ecf20Sopenharmony_ci err = tegra_xusb_lane_parse_dt(&hsic->base, np); 13618c2ecf20Sopenharmony_ci if (err < 0) { 13628c2ecf20Sopenharmony_ci kfree(hsic); 13638c2ecf20Sopenharmony_ci return ERR_PTR(err); 13648c2ecf20Sopenharmony_ci } 13658c2ecf20Sopenharmony_ci 13668c2ecf20Sopenharmony_ci return &hsic->base; 13678c2ecf20Sopenharmony_ci} 13688c2ecf20Sopenharmony_ci 13698c2ecf20Sopenharmony_cistatic void tegra210_hsic_lane_remove(struct tegra_xusb_lane *lane) 13708c2ecf20Sopenharmony_ci{ 13718c2ecf20Sopenharmony_ci struct tegra_xusb_hsic_lane *hsic = to_hsic_lane(lane); 13728c2ecf20Sopenharmony_ci 13738c2ecf20Sopenharmony_ci kfree(hsic); 13748c2ecf20Sopenharmony_ci} 13758c2ecf20Sopenharmony_ci 13768c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_ops tegra210_hsic_lane_ops = { 13778c2ecf20Sopenharmony_ci .probe = tegra210_hsic_lane_probe, 13788c2ecf20Sopenharmony_ci .remove = tegra210_hsic_lane_remove, 13798c2ecf20Sopenharmony_ci}; 13808c2ecf20Sopenharmony_ci 13818c2ecf20Sopenharmony_cistatic int tegra210_hsic_phy_init(struct phy *phy) 13828c2ecf20Sopenharmony_ci{ 13838c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 13848c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 13858c2ecf20Sopenharmony_ci u32 value; 13868c2ecf20Sopenharmony_ci 13878c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX); 13888c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_MASK << 13898c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT); 13908c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_XUSB << 13918c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_PAD_MUX_HSIC_PAD_TRK_SHIFT; 13928c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB2_PAD_MUX); 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_enable(padctl); 13958c2ecf20Sopenharmony_ci} 13968c2ecf20Sopenharmony_ci 13978c2ecf20Sopenharmony_cistatic int tegra210_hsic_phy_exit(struct phy *phy) 13988c2ecf20Sopenharmony_ci{ 13998c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 14008c2ecf20Sopenharmony_ci 14018c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_disable(lane->pad->padctl); 14028c2ecf20Sopenharmony_ci} 14038c2ecf20Sopenharmony_ci 14048c2ecf20Sopenharmony_cistatic int tegra210_hsic_phy_power_on(struct phy *phy) 14058c2ecf20Sopenharmony_ci{ 14068c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 14078c2ecf20Sopenharmony_ci struct tegra_xusb_hsic_lane *hsic = to_hsic_lane(lane); 14088c2ecf20Sopenharmony_ci struct tegra_xusb_hsic_pad *pad = to_hsic_pad(lane->pad); 14098c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 14108c2ecf20Sopenharmony_ci unsigned int index = lane->index; 14118c2ecf20Sopenharmony_ci u32 value; 14128c2ecf20Sopenharmony_ci int err; 14138c2ecf20Sopenharmony_ci 14148c2ecf20Sopenharmony_ci err = regulator_enable(pad->supply); 14158c2ecf20Sopenharmony_ci if (err) 14168c2ecf20Sopenharmony_ci return err; 14178c2ecf20Sopenharmony_ci 14188c2ecf20Sopenharmony_ci padctl_writel(padctl, hsic->strobe_trim, 14198c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_STRB_TRIM_CONTROL); 14208c2ecf20Sopenharmony_ci 14218c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL1(index)); 14228c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_MASK << 14238c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT); 14248c2ecf20Sopenharmony_ci value |= (hsic->tx_rtune_p << 14258c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL1_TX_RTUNEP_SHIFT); 14268c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL1(index)); 14278c2ecf20Sopenharmony_ci 14288c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL2(index)); 14298c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_MASK << 14308c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT) | 14318c2ecf20Sopenharmony_ci (XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_MASK << 14328c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT)); 14338c2ecf20Sopenharmony_ci value |= (hsic->rx_strobe_trim << 14348c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL2_RX_STROBE_TRIM_SHIFT) | 14358c2ecf20Sopenharmony_ci (hsic->rx_data_trim << 14368c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL2_RX_DATA_TRIM_SHIFT); 14378c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL2(index)); 14388c2ecf20Sopenharmony_ci 14398c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL0(index)); 14408c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA0 | 14418c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPU_DATA1 | 14428c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPU_STROBE | 14438c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0 | 14448c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1 | 14458c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE | 14468c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0 | 14478c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1 | 14488c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE | 14498c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0 | 14508c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1 | 14518c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE); 14528c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA0 | 14538c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPD_DATA1 | 14548c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_RPD_STROBE; 14558c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL0(index)); 14568c2ecf20Sopenharmony_ci 14578c2ecf20Sopenharmony_ci err = clk_prepare_enable(pad->clk); 14588c2ecf20Sopenharmony_ci if (err) 14598c2ecf20Sopenharmony_ci goto disable; 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PAD_TRK_CTL); 14628c2ecf20Sopenharmony_ci value &= ~((XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_MASK << 14638c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT) | 14648c2ecf20Sopenharmony_ci (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_MASK << 14658c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT)); 14668c2ecf20Sopenharmony_ci value |= (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_VAL << 14678c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_START_TIMER_SHIFT) | 14688c2ecf20Sopenharmony_ci (XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_VAL << 14698c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_TRK_CTL_TRK_DONE_RESET_TIMER_SHIFT); 14708c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PAD_TRK_CTL); 14718c2ecf20Sopenharmony_ci 14728c2ecf20Sopenharmony_ci udelay(1); 14738c2ecf20Sopenharmony_ci 14748c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PAD_TRK_CTL); 14758c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_HSIC_PAD_TRK_CTL_PD_TRK; 14768c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PAD_TRK_CTL); 14778c2ecf20Sopenharmony_ci 14788c2ecf20Sopenharmony_ci udelay(50); 14798c2ecf20Sopenharmony_ci 14808c2ecf20Sopenharmony_ci clk_disable_unprepare(pad->clk); 14818c2ecf20Sopenharmony_ci 14828c2ecf20Sopenharmony_ci return 0; 14838c2ecf20Sopenharmony_ci 14848c2ecf20Sopenharmony_cidisable: 14858c2ecf20Sopenharmony_ci regulator_disable(pad->supply); 14868c2ecf20Sopenharmony_ci return err; 14878c2ecf20Sopenharmony_ci} 14888c2ecf20Sopenharmony_ci 14898c2ecf20Sopenharmony_cistatic int tegra210_hsic_phy_power_off(struct phy *phy) 14908c2ecf20Sopenharmony_ci{ 14918c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 14928c2ecf20Sopenharmony_ci struct tegra_xusb_hsic_pad *pad = to_hsic_pad(lane->pad); 14938c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 14948c2ecf20Sopenharmony_ci unsigned int index = lane->index; 14958c2ecf20Sopenharmony_ci u32 value; 14968c2ecf20Sopenharmony_ci 14978c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL0(index)); 14988c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA0 | 14998c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_DATA1 | 15008c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_RX_STROBE | 15018c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA0 | 15028c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_DATA1 | 15038c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_ZI_STROBE | 15048c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA0 | 15058c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_DATA1 | 15068c2ecf20Sopenharmony_ci XUSB_PADCTL_HSIC_PAD_CTL0_PD_TX_STROBE; 15078c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL1(index)); 15088c2ecf20Sopenharmony_ci 15098c2ecf20Sopenharmony_ci regulator_disable(pad->supply); 15108c2ecf20Sopenharmony_ci 15118c2ecf20Sopenharmony_ci return 0; 15128c2ecf20Sopenharmony_ci} 15138c2ecf20Sopenharmony_ci 15148c2ecf20Sopenharmony_cistatic const struct phy_ops tegra210_hsic_phy_ops = { 15158c2ecf20Sopenharmony_ci .init = tegra210_hsic_phy_init, 15168c2ecf20Sopenharmony_ci .exit = tegra210_hsic_phy_exit, 15178c2ecf20Sopenharmony_ci .power_on = tegra210_hsic_phy_power_on, 15188c2ecf20Sopenharmony_ci .power_off = tegra210_hsic_phy_power_off, 15198c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 15208c2ecf20Sopenharmony_ci}; 15218c2ecf20Sopenharmony_ci 15228c2ecf20Sopenharmony_cistatic struct tegra_xusb_pad * 15238c2ecf20Sopenharmony_citegra210_hsic_pad_probe(struct tegra_xusb_padctl *padctl, 15248c2ecf20Sopenharmony_ci const struct tegra_xusb_pad_soc *soc, 15258c2ecf20Sopenharmony_ci struct device_node *np) 15268c2ecf20Sopenharmony_ci{ 15278c2ecf20Sopenharmony_ci struct tegra_xusb_hsic_pad *hsic; 15288c2ecf20Sopenharmony_ci struct tegra_xusb_pad *pad; 15298c2ecf20Sopenharmony_ci int err; 15308c2ecf20Sopenharmony_ci 15318c2ecf20Sopenharmony_ci hsic = kzalloc(sizeof(*hsic), GFP_KERNEL); 15328c2ecf20Sopenharmony_ci if (!hsic) 15338c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 15348c2ecf20Sopenharmony_ci 15358c2ecf20Sopenharmony_ci pad = &hsic->base; 15368c2ecf20Sopenharmony_ci pad->ops = &tegra210_hsic_lane_ops; 15378c2ecf20Sopenharmony_ci pad->soc = soc; 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_ci err = tegra_xusb_pad_init(pad, padctl, np); 15408c2ecf20Sopenharmony_ci if (err < 0) { 15418c2ecf20Sopenharmony_ci kfree(hsic); 15428c2ecf20Sopenharmony_ci goto out; 15438c2ecf20Sopenharmony_ci } 15448c2ecf20Sopenharmony_ci 15458c2ecf20Sopenharmony_ci hsic->clk = devm_clk_get(&pad->dev, "trk"); 15468c2ecf20Sopenharmony_ci if (IS_ERR(hsic->clk)) { 15478c2ecf20Sopenharmony_ci err = PTR_ERR(hsic->clk); 15488c2ecf20Sopenharmony_ci dev_err(&pad->dev, "failed to get trk clock: %d\n", err); 15498c2ecf20Sopenharmony_ci goto unregister; 15508c2ecf20Sopenharmony_ci } 15518c2ecf20Sopenharmony_ci 15528c2ecf20Sopenharmony_ci err = tegra_xusb_pad_register(pad, &tegra210_hsic_phy_ops); 15538c2ecf20Sopenharmony_ci if (err < 0) 15548c2ecf20Sopenharmony_ci goto unregister; 15558c2ecf20Sopenharmony_ci 15568c2ecf20Sopenharmony_ci dev_set_drvdata(&pad->dev, pad); 15578c2ecf20Sopenharmony_ci 15588c2ecf20Sopenharmony_ci return pad; 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_ciunregister: 15618c2ecf20Sopenharmony_ci device_unregister(&pad->dev); 15628c2ecf20Sopenharmony_ciout: 15638c2ecf20Sopenharmony_ci return ERR_PTR(err); 15648c2ecf20Sopenharmony_ci} 15658c2ecf20Sopenharmony_ci 15668c2ecf20Sopenharmony_cistatic void tegra210_hsic_pad_remove(struct tegra_xusb_pad *pad) 15678c2ecf20Sopenharmony_ci{ 15688c2ecf20Sopenharmony_ci struct tegra_xusb_hsic_pad *hsic = to_hsic_pad(pad); 15698c2ecf20Sopenharmony_ci 15708c2ecf20Sopenharmony_ci kfree(hsic); 15718c2ecf20Sopenharmony_ci} 15728c2ecf20Sopenharmony_ci 15738c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_ops tegra210_hsic_ops = { 15748c2ecf20Sopenharmony_ci .probe = tegra210_hsic_pad_probe, 15758c2ecf20Sopenharmony_ci .remove = tegra210_hsic_pad_remove, 15768c2ecf20Sopenharmony_ci}; 15778c2ecf20Sopenharmony_ci 15788c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_soc tegra210_hsic_pad = { 15798c2ecf20Sopenharmony_ci .name = "hsic", 15808c2ecf20Sopenharmony_ci .num_lanes = ARRAY_SIZE(tegra210_hsic_lanes), 15818c2ecf20Sopenharmony_ci .lanes = tegra210_hsic_lanes, 15828c2ecf20Sopenharmony_ci .ops = &tegra210_hsic_ops, 15838c2ecf20Sopenharmony_ci}; 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_cistatic const char *tegra210_pcie_functions[] = { 15868c2ecf20Sopenharmony_ci "pcie-x1", 15878c2ecf20Sopenharmony_ci "usb3-ss", 15888c2ecf20Sopenharmony_ci "sata", 15898c2ecf20Sopenharmony_ci "pcie-x4", 15908c2ecf20Sopenharmony_ci}; 15918c2ecf20Sopenharmony_ci 15928c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_soc tegra210_pcie_lanes[] = { 15938c2ecf20Sopenharmony_ci TEGRA210_LANE("pcie-0", 0x028, 12, 0x3, pcie), 15948c2ecf20Sopenharmony_ci TEGRA210_LANE("pcie-1", 0x028, 14, 0x3, pcie), 15958c2ecf20Sopenharmony_ci TEGRA210_LANE("pcie-2", 0x028, 16, 0x3, pcie), 15968c2ecf20Sopenharmony_ci TEGRA210_LANE("pcie-3", 0x028, 18, 0x3, pcie), 15978c2ecf20Sopenharmony_ci TEGRA210_LANE("pcie-4", 0x028, 20, 0x3, pcie), 15988c2ecf20Sopenharmony_ci TEGRA210_LANE("pcie-5", 0x028, 22, 0x3, pcie), 15998c2ecf20Sopenharmony_ci TEGRA210_LANE("pcie-6", 0x028, 24, 0x3, pcie), 16008c2ecf20Sopenharmony_ci}; 16018c2ecf20Sopenharmony_ci 16028c2ecf20Sopenharmony_cistatic struct tegra_xusb_lane * 16038c2ecf20Sopenharmony_citegra210_pcie_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np, 16048c2ecf20Sopenharmony_ci unsigned int index) 16058c2ecf20Sopenharmony_ci{ 16068c2ecf20Sopenharmony_ci struct tegra_xusb_pcie_lane *pcie; 16078c2ecf20Sopenharmony_ci int err; 16088c2ecf20Sopenharmony_ci 16098c2ecf20Sopenharmony_ci pcie = kzalloc(sizeof(*pcie), GFP_KERNEL); 16108c2ecf20Sopenharmony_ci if (!pcie) 16118c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 16128c2ecf20Sopenharmony_ci 16138c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&pcie->base.list); 16148c2ecf20Sopenharmony_ci pcie->base.soc = &pad->soc->lanes[index]; 16158c2ecf20Sopenharmony_ci pcie->base.index = index; 16168c2ecf20Sopenharmony_ci pcie->base.pad = pad; 16178c2ecf20Sopenharmony_ci pcie->base.np = np; 16188c2ecf20Sopenharmony_ci 16198c2ecf20Sopenharmony_ci err = tegra_xusb_lane_parse_dt(&pcie->base, np); 16208c2ecf20Sopenharmony_ci if (err < 0) { 16218c2ecf20Sopenharmony_ci kfree(pcie); 16228c2ecf20Sopenharmony_ci return ERR_PTR(err); 16238c2ecf20Sopenharmony_ci } 16248c2ecf20Sopenharmony_ci 16258c2ecf20Sopenharmony_ci return &pcie->base; 16268c2ecf20Sopenharmony_ci} 16278c2ecf20Sopenharmony_ci 16288c2ecf20Sopenharmony_cistatic void tegra210_pcie_lane_remove(struct tegra_xusb_lane *lane) 16298c2ecf20Sopenharmony_ci{ 16308c2ecf20Sopenharmony_ci struct tegra_xusb_pcie_lane *pcie = to_pcie_lane(lane); 16318c2ecf20Sopenharmony_ci 16328c2ecf20Sopenharmony_ci kfree(pcie); 16338c2ecf20Sopenharmony_ci} 16348c2ecf20Sopenharmony_ci 16358c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_ops tegra210_pcie_lane_ops = { 16368c2ecf20Sopenharmony_ci .probe = tegra210_pcie_lane_probe, 16378c2ecf20Sopenharmony_ci .remove = tegra210_pcie_lane_remove, 16388c2ecf20Sopenharmony_ci}; 16398c2ecf20Sopenharmony_ci 16408c2ecf20Sopenharmony_cistatic int tegra210_pcie_phy_init(struct phy *phy) 16418c2ecf20Sopenharmony_ci{ 16428c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 16438c2ecf20Sopenharmony_ci 16448c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_enable(lane->pad->padctl); 16458c2ecf20Sopenharmony_ci} 16468c2ecf20Sopenharmony_ci 16478c2ecf20Sopenharmony_cistatic int tegra210_pcie_phy_exit(struct phy *phy) 16488c2ecf20Sopenharmony_ci{ 16498c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 16508c2ecf20Sopenharmony_ci 16518c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_disable(lane->pad->padctl); 16528c2ecf20Sopenharmony_ci} 16538c2ecf20Sopenharmony_ci 16548c2ecf20Sopenharmony_cistatic int tegra210_pcie_phy_power_on(struct phy *phy) 16558c2ecf20Sopenharmony_ci{ 16568c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 16578c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 16588c2ecf20Sopenharmony_ci u32 value; 16598c2ecf20Sopenharmony_ci int err; 16608c2ecf20Sopenharmony_ci 16618c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 16628c2ecf20Sopenharmony_ci 16638c2ecf20Sopenharmony_ci err = tegra210_pex_uphy_enable(padctl); 16648c2ecf20Sopenharmony_ci if (err < 0) 16658c2ecf20Sopenharmony_ci goto unlock; 16668c2ecf20Sopenharmony_ci 16678c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX); 16688c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(lane->index); 16698c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX); 16708c2ecf20Sopenharmony_ci 16718c2ecf20Sopenharmony_ciunlock: 16728c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 16738c2ecf20Sopenharmony_ci return err; 16748c2ecf20Sopenharmony_ci} 16758c2ecf20Sopenharmony_ci 16768c2ecf20Sopenharmony_cistatic int tegra210_pcie_phy_power_off(struct phy *phy) 16778c2ecf20Sopenharmony_ci{ 16788c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 16798c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 16808c2ecf20Sopenharmony_ci u32 value; 16818c2ecf20Sopenharmony_ci 16828c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX); 16838c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_USB3_PAD_MUX_PCIE_IDDQ_DISABLE(lane->index); 16848c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX); 16858c2ecf20Sopenharmony_ci 16868c2ecf20Sopenharmony_ci tegra210_pex_uphy_disable(padctl); 16878c2ecf20Sopenharmony_ci 16888c2ecf20Sopenharmony_ci return 0; 16898c2ecf20Sopenharmony_ci} 16908c2ecf20Sopenharmony_ci 16918c2ecf20Sopenharmony_cistatic const struct phy_ops tegra210_pcie_phy_ops = { 16928c2ecf20Sopenharmony_ci .init = tegra210_pcie_phy_init, 16938c2ecf20Sopenharmony_ci .exit = tegra210_pcie_phy_exit, 16948c2ecf20Sopenharmony_ci .power_on = tegra210_pcie_phy_power_on, 16958c2ecf20Sopenharmony_ci .power_off = tegra210_pcie_phy_power_off, 16968c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 16978c2ecf20Sopenharmony_ci}; 16988c2ecf20Sopenharmony_ci 16998c2ecf20Sopenharmony_cistatic struct tegra_xusb_pad * 17008c2ecf20Sopenharmony_citegra210_pcie_pad_probe(struct tegra_xusb_padctl *padctl, 17018c2ecf20Sopenharmony_ci const struct tegra_xusb_pad_soc *soc, 17028c2ecf20Sopenharmony_ci struct device_node *np) 17038c2ecf20Sopenharmony_ci{ 17048c2ecf20Sopenharmony_ci struct tegra_xusb_pcie_pad *pcie; 17058c2ecf20Sopenharmony_ci struct tegra_xusb_pad *pad; 17068c2ecf20Sopenharmony_ci int err; 17078c2ecf20Sopenharmony_ci 17088c2ecf20Sopenharmony_ci pcie = kzalloc(sizeof(*pcie), GFP_KERNEL); 17098c2ecf20Sopenharmony_ci if (!pcie) 17108c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 17118c2ecf20Sopenharmony_ci 17128c2ecf20Sopenharmony_ci pad = &pcie->base; 17138c2ecf20Sopenharmony_ci pad->ops = &tegra210_pcie_lane_ops; 17148c2ecf20Sopenharmony_ci pad->soc = soc; 17158c2ecf20Sopenharmony_ci 17168c2ecf20Sopenharmony_ci err = tegra_xusb_pad_init(pad, padctl, np); 17178c2ecf20Sopenharmony_ci if (err < 0) { 17188c2ecf20Sopenharmony_ci kfree(pcie); 17198c2ecf20Sopenharmony_ci goto out; 17208c2ecf20Sopenharmony_ci } 17218c2ecf20Sopenharmony_ci 17228c2ecf20Sopenharmony_ci pcie->pll = devm_clk_get(&pad->dev, "pll"); 17238c2ecf20Sopenharmony_ci if (IS_ERR(pcie->pll)) { 17248c2ecf20Sopenharmony_ci err = PTR_ERR(pcie->pll); 17258c2ecf20Sopenharmony_ci dev_err(&pad->dev, "failed to get PLL: %d\n", err); 17268c2ecf20Sopenharmony_ci goto unregister; 17278c2ecf20Sopenharmony_ci } 17288c2ecf20Sopenharmony_ci 17298c2ecf20Sopenharmony_ci pcie->rst = devm_reset_control_get(&pad->dev, "phy"); 17308c2ecf20Sopenharmony_ci if (IS_ERR(pcie->rst)) { 17318c2ecf20Sopenharmony_ci err = PTR_ERR(pcie->rst); 17328c2ecf20Sopenharmony_ci dev_err(&pad->dev, "failed to get PCIe pad reset: %d\n", err); 17338c2ecf20Sopenharmony_ci goto unregister; 17348c2ecf20Sopenharmony_ci } 17358c2ecf20Sopenharmony_ci 17368c2ecf20Sopenharmony_ci err = tegra_xusb_pad_register(pad, &tegra210_pcie_phy_ops); 17378c2ecf20Sopenharmony_ci if (err < 0) 17388c2ecf20Sopenharmony_ci goto unregister; 17398c2ecf20Sopenharmony_ci 17408c2ecf20Sopenharmony_ci dev_set_drvdata(&pad->dev, pad); 17418c2ecf20Sopenharmony_ci 17428c2ecf20Sopenharmony_ci return pad; 17438c2ecf20Sopenharmony_ci 17448c2ecf20Sopenharmony_ciunregister: 17458c2ecf20Sopenharmony_ci device_unregister(&pad->dev); 17468c2ecf20Sopenharmony_ciout: 17478c2ecf20Sopenharmony_ci return ERR_PTR(err); 17488c2ecf20Sopenharmony_ci} 17498c2ecf20Sopenharmony_ci 17508c2ecf20Sopenharmony_cistatic void tegra210_pcie_pad_remove(struct tegra_xusb_pad *pad) 17518c2ecf20Sopenharmony_ci{ 17528c2ecf20Sopenharmony_ci struct tegra_xusb_pcie_pad *pcie = to_pcie_pad(pad); 17538c2ecf20Sopenharmony_ci 17548c2ecf20Sopenharmony_ci kfree(pcie); 17558c2ecf20Sopenharmony_ci} 17568c2ecf20Sopenharmony_ci 17578c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_ops tegra210_pcie_ops = { 17588c2ecf20Sopenharmony_ci .probe = tegra210_pcie_pad_probe, 17598c2ecf20Sopenharmony_ci .remove = tegra210_pcie_pad_remove, 17608c2ecf20Sopenharmony_ci}; 17618c2ecf20Sopenharmony_ci 17628c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_soc tegra210_pcie_pad = { 17638c2ecf20Sopenharmony_ci .name = "pcie", 17648c2ecf20Sopenharmony_ci .num_lanes = ARRAY_SIZE(tegra210_pcie_lanes), 17658c2ecf20Sopenharmony_ci .lanes = tegra210_pcie_lanes, 17668c2ecf20Sopenharmony_ci .ops = &tegra210_pcie_ops, 17678c2ecf20Sopenharmony_ci}; 17688c2ecf20Sopenharmony_ci 17698c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_soc tegra210_sata_lanes[] = { 17708c2ecf20Sopenharmony_ci TEGRA210_LANE("sata-0", 0x028, 30, 0x3, pcie), 17718c2ecf20Sopenharmony_ci}; 17728c2ecf20Sopenharmony_ci 17738c2ecf20Sopenharmony_cistatic struct tegra_xusb_lane * 17748c2ecf20Sopenharmony_citegra210_sata_lane_probe(struct tegra_xusb_pad *pad, struct device_node *np, 17758c2ecf20Sopenharmony_ci unsigned int index) 17768c2ecf20Sopenharmony_ci{ 17778c2ecf20Sopenharmony_ci struct tegra_xusb_sata_lane *sata; 17788c2ecf20Sopenharmony_ci int err; 17798c2ecf20Sopenharmony_ci 17808c2ecf20Sopenharmony_ci sata = kzalloc(sizeof(*sata), GFP_KERNEL); 17818c2ecf20Sopenharmony_ci if (!sata) 17828c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 17838c2ecf20Sopenharmony_ci 17848c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&sata->base.list); 17858c2ecf20Sopenharmony_ci sata->base.soc = &pad->soc->lanes[index]; 17868c2ecf20Sopenharmony_ci sata->base.index = index; 17878c2ecf20Sopenharmony_ci sata->base.pad = pad; 17888c2ecf20Sopenharmony_ci sata->base.np = np; 17898c2ecf20Sopenharmony_ci 17908c2ecf20Sopenharmony_ci err = tegra_xusb_lane_parse_dt(&sata->base, np); 17918c2ecf20Sopenharmony_ci if (err < 0) { 17928c2ecf20Sopenharmony_ci kfree(sata); 17938c2ecf20Sopenharmony_ci return ERR_PTR(err); 17948c2ecf20Sopenharmony_ci } 17958c2ecf20Sopenharmony_ci 17968c2ecf20Sopenharmony_ci return &sata->base; 17978c2ecf20Sopenharmony_ci} 17988c2ecf20Sopenharmony_ci 17998c2ecf20Sopenharmony_cistatic void tegra210_sata_lane_remove(struct tegra_xusb_lane *lane) 18008c2ecf20Sopenharmony_ci{ 18018c2ecf20Sopenharmony_ci struct tegra_xusb_sata_lane *sata = to_sata_lane(lane); 18028c2ecf20Sopenharmony_ci 18038c2ecf20Sopenharmony_ci kfree(sata); 18048c2ecf20Sopenharmony_ci} 18058c2ecf20Sopenharmony_ci 18068c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_ops tegra210_sata_lane_ops = { 18078c2ecf20Sopenharmony_ci .probe = tegra210_sata_lane_probe, 18088c2ecf20Sopenharmony_ci .remove = tegra210_sata_lane_remove, 18098c2ecf20Sopenharmony_ci}; 18108c2ecf20Sopenharmony_ci 18118c2ecf20Sopenharmony_cistatic int tegra210_sata_phy_init(struct phy *phy) 18128c2ecf20Sopenharmony_ci{ 18138c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 18148c2ecf20Sopenharmony_ci 18158c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_enable(lane->pad->padctl); 18168c2ecf20Sopenharmony_ci} 18178c2ecf20Sopenharmony_ci 18188c2ecf20Sopenharmony_cistatic int tegra210_sata_phy_exit(struct phy *phy) 18198c2ecf20Sopenharmony_ci{ 18208c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 18218c2ecf20Sopenharmony_ci 18228c2ecf20Sopenharmony_ci return tegra210_xusb_padctl_disable(lane->pad->padctl); 18238c2ecf20Sopenharmony_ci} 18248c2ecf20Sopenharmony_ci 18258c2ecf20Sopenharmony_cistatic int tegra210_sata_phy_power_on(struct phy *phy) 18268c2ecf20Sopenharmony_ci{ 18278c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 18288c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 18298c2ecf20Sopenharmony_ci u32 value; 18308c2ecf20Sopenharmony_ci int err; 18318c2ecf20Sopenharmony_ci 18328c2ecf20Sopenharmony_ci mutex_lock(&padctl->lock); 18338c2ecf20Sopenharmony_ci 18348c2ecf20Sopenharmony_ci err = tegra210_sata_uphy_enable(padctl, false); 18358c2ecf20Sopenharmony_ci if (err < 0) 18368c2ecf20Sopenharmony_ci goto unlock; 18378c2ecf20Sopenharmony_ci 18388c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX); 18398c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(lane->index); 18408c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX); 18418c2ecf20Sopenharmony_ci 18428c2ecf20Sopenharmony_ciunlock: 18438c2ecf20Sopenharmony_ci mutex_unlock(&padctl->lock); 18448c2ecf20Sopenharmony_ci return err; 18458c2ecf20Sopenharmony_ci} 18468c2ecf20Sopenharmony_ci 18478c2ecf20Sopenharmony_cistatic int tegra210_sata_phy_power_off(struct phy *phy) 18488c2ecf20Sopenharmony_ci{ 18498c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 18508c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = lane->pad->padctl; 18518c2ecf20Sopenharmony_ci u32 value; 18528c2ecf20Sopenharmony_ci 18538c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_USB3_PAD_MUX); 18548c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_USB3_PAD_MUX_SATA_IDDQ_DISABLE(lane->index); 18558c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_USB3_PAD_MUX); 18568c2ecf20Sopenharmony_ci 18578c2ecf20Sopenharmony_ci tegra210_sata_uphy_disable(lane->pad->padctl); 18588c2ecf20Sopenharmony_ci 18598c2ecf20Sopenharmony_ci return 0; 18608c2ecf20Sopenharmony_ci} 18618c2ecf20Sopenharmony_ci 18628c2ecf20Sopenharmony_cistatic const struct phy_ops tegra210_sata_phy_ops = { 18638c2ecf20Sopenharmony_ci .init = tegra210_sata_phy_init, 18648c2ecf20Sopenharmony_ci .exit = tegra210_sata_phy_exit, 18658c2ecf20Sopenharmony_ci .power_on = tegra210_sata_phy_power_on, 18668c2ecf20Sopenharmony_ci .power_off = tegra210_sata_phy_power_off, 18678c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 18688c2ecf20Sopenharmony_ci}; 18698c2ecf20Sopenharmony_ci 18708c2ecf20Sopenharmony_cistatic struct tegra_xusb_pad * 18718c2ecf20Sopenharmony_citegra210_sata_pad_probe(struct tegra_xusb_padctl *padctl, 18728c2ecf20Sopenharmony_ci const struct tegra_xusb_pad_soc *soc, 18738c2ecf20Sopenharmony_ci struct device_node *np) 18748c2ecf20Sopenharmony_ci{ 18758c2ecf20Sopenharmony_ci struct tegra_xusb_sata_pad *sata; 18768c2ecf20Sopenharmony_ci struct tegra_xusb_pad *pad; 18778c2ecf20Sopenharmony_ci int err; 18788c2ecf20Sopenharmony_ci 18798c2ecf20Sopenharmony_ci sata = kzalloc(sizeof(*sata), GFP_KERNEL); 18808c2ecf20Sopenharmony_ci if (!sata) 18818c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 18828c2ecf20Sopenharmony_ci 18838c2ecf20Sopenharmony_ci pad = &sata->base; 18848c2ecf20Sopenharmony_ci pad->ops = &tegra210_sata_lane_ops; 18858c2ecf20Sopenharmony_ci pad->soc = soc; 18868c2ecf20Sopenharmony_ci 18878c2ecf20Sopenharmony_ci err = tegra_xusb_pad_init(pad, padctl, np); 18888c2ecf20Sopenharmony_ci if (err < 0) { 18898c2ecf20Sopenharmony_ci kfree(sata); 18908c2ecf20Sopenharmony_ci goto out; 18918c2ecf20Sopenharmony_ci } 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ci sata->rst = devm_reset_control_get(&pad->dev, "phy"); 18948c2ecf20Sopenharmony_ci if (IS_ERR(sata->rst)) { 18958c2ecf20Sopenharmony_ci err = PTR_ERR(sata->rst); 18968c2ecf20Sopenharmony_ci dev_err(&pad->dev, "failed to get SATA pad reset: %d\n", err); 18978c2ecf20Sopenharmony_ci goto unregister; 18988c2ecf20Sopenharmony_ci } 18998c2ecf20Sopenharmony_ci 19008c2ecf20Sopenharmony_ci err = tegra_xusb_pad_register(pad, &tegra210_sata_phy_ops); 19018c2ecf20Sopenharmony_ci if (err < 0) 19028c2ecf20Sopenharmony_ci goto unregister; 19038c2ecf20Sopenharmony_ci 19048c2ecf20Sopenharmony_ci dev_set_drvdata(&pad->dev, pad); 19058c2ecf20Sopenharmony_ci 19068c2ecf20Sopenharmony_ci return pad; 19078c2ecf20Sopenharmony_ci 19088c2ecf20Sopenharmony_ciunregister: 19098c2ecf20Sopenharmony_ci device_unregister(&pad->dev); 19108c2ecf20Sopenharmony_ciout: 19118c2ecf20Sopenharmony_ci return ERR_PTR(err); 19128c2ecf20Sopenharmony_ci} 19138c2ecf20Sopenharmony_ci 19148c2ecf20Sopenharmony_cistatic void tegra210_sata_pad_remove(struct tegra_xusb_pad *pad) 19158c2ecf20Sopenharmony_ci{ 19168c2ecf20Sopenharmony_ci struct tegra_xusb_sata_pad *sata = to_sata_pad(pad); 19178c2ecf20Sopenharmony_ci 19188c2ecf20Sopenharmony_ci kfree(sata); 19198c2ecf20Sopenharmony_ci} 19208c2ecf20Sopenharmony_ci 19218c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_ops tegra210_sata_ops = { 19228c2ecf20Sopenharmony_ci .probe = tegra210_sata_pad_probe, 19238c2ecf20Sopenharmony_ci .remove = tegra210_sata_pad_remove, 19248c2ecf20Sopenharmony_ci}; 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_soc tegra210_sata_pad = { 19278c2ecf20Sopenharmony_ci .name = "sata", 19288c2ecf20Sopenharmony_ci .num_lanes = ARRAY_SIZE(tegra210_sata_lanes), 19298c2ecf20Sopenharmony_ci .lanes = tegra210_sata_lanes, 19308c2ecf20Sopenharmony_ci .ops = &tegra210_sata_ops, 19318c2ecf20Sopenharmony_ci}; 19328c2ecf20Sopenharmony_ci 19338c2ecf20Sopenharmony_cistatic const struct tegra_xusb_pad_soc * const tegra210_pads[] = { 19348c2ecf20Sopenharmony_ci &tegra210_usb2_pad, 19358c2ecf20Sopenharmony_ci &tegra210_hsic_pad, 19368c2ecf20Sopenharmony_ci &tegra210_pcie_pad, 19378c2ecf20Sopenharmony_ci &tegra210_sata_pad, 19388c2ecf20Sopenharmony_ci}; 19398c2ecf20Sopenharmony_ci 19408c2ecf20Sopenharmony_cistatic int tegra210_usb2_port_enable(struct tegra_xusb_port *port) 19418c2ecf20Sopenharmony_ci{ 19428c2ecf20Sopenharmony_ci return 0; 19438c2ecf20Sopenharmony_ci} 19448c2ecf20Sopenharmony_ci 19458c2ecf20Sopenharmony_cistatic void tegra210_usb2_port_disable(struct tegra_xusb_port *port) 19468c2ecf20Sopenharmony_ci{ 19478c2ecf20Sopenharmony_ci} 19488c2ecf20Sopenharmony_ci 19498c2ecf20Sopenharmony_cistatic struct tegra_xusb_lane * 19508c2ecf20Sopenharmony_citegra210_usb2_port_map(struct tegra_xusb_port *port) 19518c2ecf20Sopenharmony_ci{ 19528c2ecf20Sopenharmony_ci return tegra_xusb_find_lane(port->padctl, "usb2", port->index); 19538c2ecf20Sopenharmony_ci} 19548c2ecf20Sopenharmony_ci 19558c2ecf20Sopenharmony_cistatic const struct tegra_xusb_port_ops tegra210_usb2_port_ops = { 19568c2ecf20Sopenharmony_ci .release = tegra_xusb_usb2_port_release, 19578c2ecf20Sopenharmony_ci .remove = tegra_xusb_usb2_port_remove, 19588c2ecf20Sopenharmony_ci .enable = tegra210_usb2_port_enable, 19598c2ecf20Sopenharmony_ci .disable = tegra210_usb2_port_disable, 19608c2ecf20Sopenharmony_ci .map = tegra210_usb2_port_map, 19618c2ecf20Sopenharmony_ci}; 19628c2ecf20Sopenharmony_ci 19638c2ecf20Sopenharmony_cistatic int tegra210_hsic_port_enable(struct tegra_xusb_port *port) 19648c2ecf20Sopenharmony_ci{ 19658c2ecf20Sopenharmony_ci return 0; 19668c2ecf20Sopenharmony_ci} 19678c2ecf20Sopenharmony_ci 19688c2ecf20Sopenharmony_cistatic void tegra210_hsic_port_disable(struct tegra_xusb_port *port) 19698c2ecf20Sopenharmony_ci{ 19708c2ecf20Sopenharmony_ci} 19718c2ecf20Sopenharmony_ci 19728c2ecf20Sopenharmony_cistatic struct tegra_xusb_lane * 19738c2ecf20Sopenharmony_citegra210_hsic_port_map(struct tegra_xusb_port *port) 19748c2ecf20Sopenharmony_ci{ 19758c2ecf20Sopenharmony_ci return tegra_xusb_find_lane(port->padctl, "hsic", port->index); 19768c2ecf20Sopenharmony_ci} 19778c2ecf20Sopenharmony_ci 19788c2ecf20Sopenharmony_cistatic const struct tegra_xusb_port_ops tegra210_hsic_port_ops = { 19798c2ecf20Sopenharmony_ci .release = tegra_xusb_hsic_port_release, 19808c2ecf20Sopenharmony_ci .enable = tegra210_hsic_port_enable, 19818c2ecf20Sopenharmony_ci .disable = tegra210_hsic_port_disable, 19828c2ecf20Sopenharmony_ci .map = tegra210_hsic_port_map, 19838c2ecf20Sopenharmony_ci}; 19848c2ecf20Sopenharmony_ci 19858c2ecf20Sopenharmony_cistatic int tegra210_usb3_port_enable(struct tegra_xusb_port *port) 19868c2ecf20Sopenharmony_ci{ 19878c2ecf20Sopenharmony_ci struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port); 19888c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = port->padctl; 19898c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = usb3->base.lane; 19908c2ecf20Sopenharmony_ci unsigned int index = port->index; 19918c2ecf20Sopenharmony_ci u32 value; 19928c2ecf20Sopenharmony_ci int err; 19938c2ecf20Sopenharmony_ci 19948c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_MAP); 19958c2ecf20Sopenharmony_ci 19968c2ecf20Sopenharmony_ci if (!usb3->internal) 19978c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(index); 19988c2ecf20Sopenharmony_ci else 19998c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_INTERNAL(index); 20008c2ecf20Sopenharmony_ci 20018c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(index); 20028c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(index, usb3->port); 20038c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_MAP); 20048c2ecf20Sopenharmony_ci 20058c2ecf20Sopenharmony_ci /* 20068c2ecf20Sopenharmony_ci * TODO: move this code into the PCIe/SATA PHY ->power_on() callbacks 20078c2ecf20Sopenharmony_ci * and conditionalize based on mux function? This seems to work, but 20088c2ecf20Sopenharmony_ci * might not be the exact proper sequence. 20098c2ecf20Sopenharmony_ci */ 20108c2ecf20Sopenharmony_ci err = regulator_enable(usb3->supply); 20118c2ecf20Sopenharmony_ci if (err < 0) 20128c2ecf20Sopenharmony_ci return err; 20138c2ecf20Sopenharmony_ci 20148c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(index)); 20158c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_MASK << 20168c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT); 20178c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_VAL << 20188c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PAD_ECTL1_TX_TERM_CTRL_SHIFT; 20198c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_USB3_PADX_ECTL1(index)); 20208c2ecf20Sopenharmony_ci 20218c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(index)); 20228c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_MASK << 20238c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT); 20248c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_VAL << 20258c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PAD_ECTL2_RX_CTLE_SHIFT; 20268c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_USB3_PADX_ECTL2(index)); 20278c2ecf20Sopenharmony_ci 20288c2ecf20Sopenharmony_ci padctl_writel(padctl, XUSB_PADCTL_UPHY_USB3_PAD_ECTL3_RX_DFE_VAL, 20298c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PADX_ECTL3(index)); 20308c2ecf20Sopenharmony_ci 20318c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(index)); 20328c2ecf20Sopenharmony_ci value &= ~(XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_MASK << 20338c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT); 20348c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_VAL << 20358c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PAD_ECTL4_RX_CDR_CTRL_SHIFT; 20368c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_UPHY_USB3_PADX_ECTL4(index)); 20378c2ecf20Sopenharmony_ci 20388c2ecf20Sopenharmony_ci padctl_writel(padctl, XUSB_PADCTL_UPHY_USB3_PAD_ECTL6_RX_EQ_CTRL_H_VAL, 20398c2ecf20Sopenharmony_ci XUSB_PADCTL_UPHY_USB3_PADX_ECTL6(index)); 20408c2ecf20Sopenharmony_ci 20418c2ecf20Sopenharmony_ci if (lane->pad == padctl->sata) 20428c2ecf20Sopenharmony_ci err = tegra210_sata_uphy_enable(padctl, true); 20438c2ecf20Sopenharmony_ci else 20448c2ecf20Sopenharmony_ci err = tegra210_pex_uphy_enable(padctl); 20458c2ecf20Sopenharmony_ci 20468c2ecf20Sopenharmony_ci if (err) { 20478c2ecf20Sopenharmony_ci dev_err(&port->dev, "%s: failed to enable UPHY: %d\n", 20488c2ecf20Sopenharmony_ci __func__, err); 20498c2ecf20Sopenharmony_ci return err; 20508c2ecf20Sopenharmony_ci } 20518c2ecf20Sopenharmony_ci 20528c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 20538c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(index); 20548c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 20558c2ecf20Sopenharmony_ci 20568c2ecf20Sopenharmony_ci usleep_range(100, 200); 20578c2ecf20Sopenharmony_ci 20588c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 20598c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(index); 20608c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 20618c2ecf20Sopenharmony_ci 20628c2ecf20Sopenharmony_ci usleep_range(100, 200); 20638c2ecf20Sopenharmony_ci 20648c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 20658c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(index); 20668c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 20678c2ecf20Sopenharmony_ci 20688c2ecf20Sopenharmony_ci return 0; 20698c2ecf20Sopenharmony_ci} 20708c2ecf20Sopenharmony_ci 20718c2ecf20Sopenharmony_cistatic void tegra210_usb3_port_disable(struct tegra_xusb_port *port) 20728c2ecf20Sopenharmony_ci{ 20738c2ecf20Sopenharmony_ci struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port); 20748c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl = port->padctl; 20758c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane = port->lane; 20768c2ecf20Sopenharmony_ci unsigned int index = port->index; 20778c2ecf20Sopenharmony_ci u32 value; 20788c2ecf20Sopenharmony_ci 20798c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 20808c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN_EARLY(index); 20818c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 20828c2ecf20Sopenharmony_ci 20838c2ecf20Sopenharmony_ci usleep_range(100, 200); 20848c2ecf20Sopenharmony_ci 20858c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 20868c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_CLAMP_EN(index); 20878c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 20888c2ecf20Sopenharmony_ci 20898c2ecf20Sopenharmony_ci usleep_range(250, 350); 20908c2ecf20Sopenharmony_ci 20918c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM1); 20928c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_ELPG_PROGRAM1_SSPX_ELPG_VCORE_DOWN(index); 20938c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM1); 20948c2ecf20Sopenharmony_ci 20958c2ecf20Sopenharmony_ci if (lane->pad == padctl->sata) 20968c2ecf20Sopenharmony_ci tegra210_sata_uphy_disable(padctl); 20978c2ecf20Sopenharmony_ci else 20988c2ecf20Sopenharmony_ci tegra210_pex_uphy_disable(padctl); 20998c2ecf20Sopenharmony_ci 21008c2ecf20Sopenharmony_ci regulator_disable(usb3->supply); 21018c2ecf20Sopenharmony_ci 21028c2ecf20Sopenharmony_ci value = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_MAP); 21038c2ecf20Sopenharmony_ci value &= ~XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP_MASK(index); 21048c2ecf20Sopenharmony_ci value |= XUSB_PADCTL_SS_PORT_MAP_PORTX_MAP(index, 0x7); 21058c2ecf20Sopenharmony_ci padctl_writel(padctl, value, XUSB_PADCTL_SS_PORT_MAP); 21068c2ecf20Sopenharmony_ci} 21078c2ecf20Sopenharmony_ci 21088c2ecf20Sopenharmony_cistatic const struct tegra_xusb_lane_map tegra210_usb3_map[] = { 21098c2ecf20Sopenharmony_ci { 0, "pcie", 6 }, 21108c2ecf20Sopenharmony_ci { 1, "pcie", 5 }, 21118c2ecf20Sopenharmony_ci { 2, "pcie", 0 }, 21128c2ecf20Sopenharmony_ci { 2, "pcie", 3 }, 21138c2ecf20Sopenharmony_ci { 3, "pcie", 4 }, 21148c2ecf20Sopenharmony_ci { 3, "pcie", 4 }, 21158c2ecf20Sopenharmony_ci { 0, NULL, 0 } 21168c2ecf20Sopenharmony_ci}; 21178c2ecf20Sopenharmony_ci 21188c2ecf20Sopenharmony_cistatic struct tegra_xusb_lane * 21198c2ecf20Sopenharmony_citegra210_usb3_port_map(struct tegra_xusb_port *port) 21208c2ecf20Sopenharmony_ci{ 21218c2ecf20Sopenharmony_ci return tegra_xusb_port_find_lane(port, tegra210_usb3_map, "usb3-ss"); 21228c2ecf20Sopenharmony_ci} 21238c2ecf20Sopenharmony_ci 21248c2ecf20Sopenharmony_cistatic const struct tegra_xusb_port_ops tegra210_usb3_port_ops = { 21258c2ecf20Sopenharmony_ci .release = tegra_xusb_usb3_port_release, 21268c2ecf20Sopenharmony_ci .remove = tegra_xusb_usb3_port_remove, 21278c2ecf20Sopenharmony_ci .enable = tegra210_usb3_port_enable, 21288c2ecf20Sopenharmony_ci .disable = tegra210_usb3_port_disable, 21298c2ecf20Sopenharmony_ci .map = tegra210_usb3_port_map, 21308c2ecf20Sopenharmony_ci}; 21318c2ecf20Sopenharmony_ci 21328c2ecf20Sopenharmony_cistatic int tegra210_utmi_port_reset(struct phy *phy) 21338c2ecf20Sopenharmony_ci{ 21348c2ecf20Sopenharmony_ci struct tegra_xusb_padctl *padctl; 21358c2ecf20Sopenharmony_ci struct tegra_xusb_lane *lane; 21368c2ecf20Sopenharmony_ci u32 value; 21378c2ecf20Sopenharmony_ci 21388c2ecf20Sopenharmony_ci lane = phy_get_drvdata(phy); 21398c2ecf20Sopenharmony_ci padctl = lane->pad->padctl; 21408c2ecf20Sopenharmony_ci 21418c2ecf20Sopenharmony_ci value = padctl_readl(padctl, 21428c2ecf20Sopenharmony_ci XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPADX_CTL0(lane->index)); 21438c2ecf20Sopenharmony_ci 21448c2ecf20Sopenharmony_ci if ((value & XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIP) || 21458c2ecf20Sopenharmony_ci (value & XUSB_PADCTL_USB2_BATTERY_CHRG_OTGPAD_CTL0_ZIN)) { 21468c2ecf20Sopenharmony_ci tegra210_xusb_padctl_vbus_override(padctl, false); 21478c2ecf20Sopenharmony_ci tegra210_xusb_padctl_vbus_override(padctl, true); 21488c2ecf20Sopenharmony_ci return 1; 21498c2ecf20Sopenharmony_ci } 21508c2ecf20Sopenharmony_ci 21518c2ecf20Sopenharmony_ci return 0; 21528c2ecf20Sopenharmony_ci} 21538c2ecf20Sopenharmony_ci 21548c2ecf20Sopenharmony_cistatic int 21558c2ecf20Sopenharmony_citegra210_xusb_read_fuse_calibration(struct tegra210_xusb_fuse_calibration *fuse) 21568c2ecf20Sopenharmony_ci{ 21578c2ecf20Sopenharmony_ci unsigned int i; 21588c2ecf20Sopenharmony_ci u32 value; 21598c2ecf20Sopenharmony_ci int err; 21608c2ecf20Sopenharmony_ci 21618c2ecf20Sopenharmony_ci err = tegra_fuse_readl(TEGRA_FUSE_SKU_CALIB_0, &value); 21628c2ecf20Sopenharmony_ci if (err < 0) 21638c2ecf20Sopenharmony_ci return err; 21648c2ecf20Sopenharmony_ci 21658c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(fuse->hs_curr_level); i++) { 21668c2ecf20Sopenharmony_ci fuse->hs_curr_level[i] = 21678c2ecf20Sopenharmony_ci (value >> FUSE_SKU_CALIB_HS_CURR_LEVEL_PADX_SHIFT(i)) & 21688c2ecf20Sopenharmony_ci FUSE_SKU_CALIB_HS_CURR_LEVEL_PAD_MASK; 21698c2ecf20Sopenharmony_ci } 21708c2ecf20Sopenharmony_ci 21718c2ecf20Sopenharmony_ci fuse->hs_term_range_adj = 21728c2ecf20Sopenharmony_ci (value >> FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_SHIFT) & 21738c2ecf20Sopenharmony_ci FUSE_SKU_CALIB_HS_TERM_RANGE_ADJ_MASK; 21748c2ecf20Sopenharmony_ci 21758c2ecf20Sopenharmony_ci err = tegra_fuse_readl(TEGRA_FUSE_USB_CALIB_EXT_0, &value); 21768c2ecf20Sopenharmony_ci if (err < 0) 21778c2ecf20Sopenharmony_ci return err; 21788c2ecf20Sopenharmony_ci 21798c2ecf20Sopenharmony_ci fuse->rpd_ctrl = 21808c2ecf20Sopenharmony_ci (value >> FUSE_USB_CALIB_EXT_RPD_CTRL_SHIFT) & 21818c2ecf20Sopenharmony_ci FUSE_USB_CALIB_EXT_RPD_CTRL_MASK; 21828c2ecf20Sopenharmony_ci 21838c2ecf20Sopenharmony_ci return 0; 21848c2ecf20Sopenharmony_ci} 21858c2ecf20Sopenharmony_ci 21868c2ecf20Sopenharmony_cistatic struct tegra_xusb_padctl * 21878c2ecf20Sopenharmony_citegra210_xusb_padctl_probe(struct device *dev, 21888c2ecf20Sopenharmony_ci const struct tegra_xusb_padctl_soc *soc) 21898c2ecf20Sopenharmony_ci{ 21908c2ecf20Sopenharmony_ci struct tegra210_xusb_padctl *padctl; 21918c2ecf20Sopenharmony_ci int err; 21928c2ecf20Sopenharmony_ci 21938c2ecf20Sopenharmony_ci padctl = devm_kzalloc(dev, sizeof(*padctl), GFP_KERNEL); 21948c2ecf20Sopenharmony_ci if (!padctl) 21958c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 21968c2ecf20Sopenharmony_ci 21978c2ecf20Sopenharmony_ci padctl->base.dev = dev; 21988c2ecf20Sopenharmony_ci padctl->base.soc = soc; 21998c2ecf20Sopenharmony_ci 22008c2ecf20Sopenharmony_ci err = tegra210_xusb_read_fuse_calibration(&padctl->fuse); 22018c2ecf20Sopenharmony_ci if (err < 0) 22028c2ecf20Sopenharmony_ci return ERR_PTR(err); 22038c2ecf20Sopenharmony_ci 22048c2ecf20Sopenharmony_ci return &padctl->base; 22058c2ecf20Sopenharmony_ci} 22068c2ecf20Sopenharmony_ci 22078c2ecf20Sopenharmony_cistatic void tegra210_xusb_padctl_remove(struct tegra_xusb_padctl *padctl) 22088c2ecf20Sopenharmony_ci{ 22098c2ecf20Sopenharmony_ci} 22108c2ecf20Sopenharmony_ci 22118c2ecf20Sopenharmony_cistatic const struct tegra_xusb_padctl_ops tegra210_xusb_padctl_ops = { 22128c2ecf20Sopenharmony_ci .probe = tegra210_xusb_padctl_probe, 22138c2ecf20Sopenharmony_ci .remove = tegra210_xusb_padctl_remove, 22148c2ecf20Sopenharmony_ci .usb3_set_lfps_detect = tegra210_usb3_set_lfps_detect, 22158c2ecf20Sopenharmony_ci .hsic_set_idle = tegra210_hsic_set_idle, 22168c2ecf20Sopenharmony_ci .vbus_override = tegra210_xusb_padctl_vbus_override, 22178c2ecf20Sopenharmony_ci .utmi_port_reset = tegra210_utmi_port_reset, 22188c2ecf20Sopenharmony_ci}; 22198c2ecf20Sopenharmony_ci 22208c2ecf20Sopenharmony_cistatic const char * const tegra210_xusb_padctl_supply_names[] = { 22218c2ecf20Sopenharmony_ci "avdd-pll-utmip", 22228c2ecf20Sopenharmony_ci "avdd-pll-uerefe", 22238c2ecf20Sopenharmony_ci "dvdd-pex-pll", 22248c2ecf20Sopenharmony_ci "hvdd-pex-pll-e", 22258c2ecf20Sopenharmony_ci}; 22268c2ecf20Sopenharmony_ci 22278c2ecf20Sopenharmony_ciconst struct tegra_xusb_padctl_soc tegra210_xusb_padctl_soc = { 22288c2ecf20Sopenharmony_ci .num_pads = ARRAY_SIZE(tegra210_pads), 22298c2ecf20Sopenharmony_ci .pads = tegra210_pads, 22308c2ecf20Sopenharmony_ci .ports = { 22318c2ecf20Sopenharmony_ci .usb2 = { 22328c2ecf20Sopenharmony_ci .ops = &tegra210_usb2_port_ops, 22338c2ecf20Sopenharmony_ci .count = 4, 22348c2ecf20Sopenharmony_ci }, 22358c2ecf20Sopenharmony_ci .hsic = { 22368c2ecf20Sopenharmony_ci .ops = &tegra210_hsic_port_ops, 22378c2ecf20Sopenharmony_ci .count = 1, 22388c2ecf20Sopenharmony_ci }, 22398c2ecf20Sopenharmony_ci .usb3 = { 22408c2ecf20Sopenharmony_ci .ops = &tegra210_usb3_port_ops, 22418c2ecf20Sopenharmony_ci .count = 4, 22428c2ecf20Sopenharmony_ci }, 22438c2ecf20Sopenharmony_ci }, 22448c2ecf20Sopenharmony_ci .ops = &tegra210_xusb_padctl_ops, 22458c2ecf20Sopenharmony_ci .supply_names = tegra210_xusb_padctl_supply_names, 22468c2ecf20Sopenharmony_ci .num_supplies = ARRAY_SIZE(tegra210_xusb_padctl_supply_names), 22478c2ecf20Sopenharmony_ci .need_fake_usb3_port = true, 22488c2ecf20Sopenharmony_ci}; 22498c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(tegra210_xusb_padctl_soc); 22508c2ecf20Sopenharmony_ci 22518c2ecf20Sopenharmony_ciMODULE_AUTHOR("Andrew Bresticker <abrestic@chromium.org>"); 22528c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("NVIDIA Tegra 210 XUSB Pad Controller driver"); 22538c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 2254