19 #include <linux/resource.h>
21 #include <linux/slab.h>
23 #include <linux/export.h>
34 #define ULPI_VIEWPORT 0x170
36 #define USB_PORTSC1 0x184
37 #define USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
38 #define USB_PORTSC1_PSPD(x) (((x) & 0x3) << 26)
39 #define USB_PORTSC1_PHCD (1 << 23)
40 #define USB_PORTSC1_WKOC (1 << 22)
41 #define USB_PORTSC1_WKDS (1 << 21)
42 #define USB_PORTSC1_WKCN (1 << 20)
43 #define USB_PORTSC1_PTC(x) (((x) & 0xf) << 16)
44 #define USB_PORTSC1_PP (1 << 12)
45 #define USB_PORTSC1_SUSP (1 << 7)
46 #define USB_PORTSC1_PE (1 << 2)
47 #define USB_PORTSC1_CCS (1 << 0)
49 #define USB_SUSP_CTRL 0x400
50 #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3)
51 #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4)
52 #define USB_SUSP_CLR (1 << 5)
53 #define USB_PHY_CLK_VALID (1 << 7)
54 #define UTMIP_RESET (1 << 11)
55 #define UHSIC_RESET (1 << 11)
56 #define UTMIP_PHY_ENABLE (1 << 12)
57 #define ULPI_PHY_ENABLE (1 << 13)
58 #define USB_SUSP_SET (1 << 14)
59 #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
61 #define USB1_LEGACY_CTRL 0x410
62 #define USB1_NO_LEGACY_MODE (1 << 0)
63 #define USB1_VBUS_SENSE_CTL_MASK (3 << 1)
64 #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1)
65 #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \
67 #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1)
68 #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1)
70 #define ULPI_TIMING_CTRL_0 0x424
71 #define ULPI_OUTPUT_PINMUX_BYP (1 << 10)
72 #define ULPI_CLKOUT_PINMUX_BYP (1 << 11)
74 #define ULPI_TIMING_CTRL_1 0x428
75 #define ULPI_DATA_TRIMMER_LOAD (1 << 0)
76 #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1)
77 #define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16)
78 #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17)
79 #define ULPI_DIR_TRIMMER_LOAD (1 << 24)
80 #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25)
82 #define UTMIP_PLL_CFG1 0x804
83 #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
84 #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
86 #define UTMIP_XCVR_CFG0 0x808
87 #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
88 #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
89 #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
90 #define UTMIP_FORCE_PD_POWERDOWN (1 << 14)
91 #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16)
92 #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18)
93 #define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25)
95 #define UTMIP_BIAS_CFG0 0x80c
96 #define UTMIP_OTGPD (1 << 11)
97 #define UTMIP_BIASPD (1 << 10)
99 #define UTMIP_HSRX_CFG0 0x810
100 #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
101 #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
103 #define UTMIP_HSRX_CFG1 0x814
104 #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
106 #define UTMIP_TX_CFG0 0x820
107 #define UTMIP_FS_PREABMLE_J (1 << 19)
108 #define UTMIP_HS_DISCON_DISABLE (1 << 8)
110 #define UTMIP_MISC_CFG0 0x824
111 #define UTMIP_DPDM_OBSERVE (1 << 26)
112 #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27)
113 #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf)
114 #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe)
115 #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd)
116 #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc)
117 #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22)
119 #define UTMIP_MISC_CFG1 0x828
120 #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18)
121 #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6)
123 #define UTMIP_DEBOUNCE_CFG0 0x82c
124 #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
126 #define UTMIP_BAT_CHRG_CFG0 0x830
127 #define UTMIP_PD_CHRG (1 << 0)
129 #define UTMIP_SPARE_CFG0 0x834
130 #define FUSE_SETUP_SEL (1 << 3)
132 #define UTMIP_XCVR_CFG1 0x838
133 #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0)
134 #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2)
135 #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4)
136 #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
138 #define UTMIP_BIAS_CFG1 0x83c
139 #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
142 static int utmip_pad_count;
156 .enable_delay = 0x02,
157 .stable_count = 0x2F,
158 .active_delay = 0x04,
159 .xtal_freq_count = 0x76,
164 .enable_delay = 0x02,
165 .stable_count = 0x33,
166 .active_delay = 0x05,
167 .xtal_freq_count = 0x7F,
172 .enable_delay = 0x03,
173 .stable_count = 0x4B,
174 .active_delay = 0x06,
175 .xtal_freq_count = 0xBB,
180 .enable_delay = 0x04,
181 .stable_count = 0x66,
182 .active_delay = 0x09,
183 .xtal_freq_count = 0xFE,
190 .hssync_start_delay = 9,
191 .idle_wait_delay = 17,
199 .hssync_start_delay = 9,
200 .idle_wait_delay = 17,
218 pr_err(
"%s: can't get utmip pad clock\n", __func__);
227 pr_err(
"%s: can't remap usb registers\n", __func__);
247 clk_prepare_enable(phy->
pad_clk);
251 if (utmip_pad_count++ == 0) {
257 spin_unlock_irqrestore(&utmip_pad_lock, flags);
259 clk_disable_unprepare(phy->
pad_clk);
267 if (!utmip_pad_count) {
268 pr_err(
"%s: utmip pad already powered off\n", __func__);
272 clk_prepare_enable(phy->
pad_clk);
276 if (--utmip_pad_count == 0) {
282 spin_unlock_irqrestore(&utmip_pad_lock, flags);
284 clk_disable_unprepare(phy->
pad_clk);
293 if ((
readl(reg) & mask) == result)
325 pr_err(
"%s: timeout waiting for phy to stabilize\n", __func__);
353 pr_err(
"%s: timeout waiting for phy to stabilize\n", __func__);
414 utmip_pad_power_on(phy);
471 utmi_phy_clk_enable(phy);
487 utmi_phy_clk_disable(phy);
514 return utmip_pad_power_off(phy);
537 static void utmi_phy_restore_start(
struct tegra_usb_phy *phy,
580 clk_prepare_enable(phy->
clk);
610 ret = usb_phy_io_write(phy->
ulpi, 0x40, 0x08);
612 pr_err(
"%s: ulpi write failed\n", __func__);
616 ret = usb_phy_io_write(phy->
ulpi, 0x80, 0x0B);
618 pr_err(
"%s: ulpi write failed\n", __func__);
655 static int tegra_phy_init(
struct usb_phy *
x)
661 if (phy_is_ulpi(phy)) {
662 ulpi_config = phy->
config;
664 if (IS_ERR(phy->
clk)) {
665 pr_err(
"%s: can't get ulpi clock\n", __func__);
671 of_get_named_gpio(phy->
dev->of_node,
672 "nvidia,phy-reset-gpio", 0);
673 if (!gpio_is_valid(ulpi_config->
reset_gpio)) {
674 pr_err(
"%s: invalid reset gpio: %d\n", __func__,
684 err = utmip_pad_open(phy);
690 clk_disable_unprepare(phy->
pll_u);
695 static void tegra_usb_phy_close(
struct usb_phy *x)
699 if (phy_is_ulpi(phy))
702 utmip_pad_close(phy);
703 clk_disable_unprepare(phy->
pll_u);
710 if (phy_is_ulpi(phy))
711 return ulpi_phy_power_on(phy);
713 return utmi_phy_power_on(phy);
716 static int tegra_usb_phy_power_off(
struct tegra_usb_phy *phy)
718 if (phy_is_ulpi(phy))
719 return ulpi_phy_power_off(phy);
721 return utmi_phy_power_off(phy);
728 return tegra_usb_phy_power_off(phy);
730 return tegra_usb_phy_power_on(phy);
737 unsigned long parent_rate;
748 phy->
mode = phy_mode;
752 if (phy_is_ulpi(phy)) {
753 pr_err(
"%s: ulpi phy configuration missing", __func__);
762 if (IS_ERR(phy->
pll_u)) {
763 pr_err(
"Can't get pll_u clock\n");
764 err = PTR_ERR(phy->
pll_u);
767 clk_prepare_enable(phy->
pll_u);
770 for (i = 0; i <
ARRAY_SIZE(tegra_freq_table); i++) {
771 if (tegra_freq_table[i].
freq == parent_rate) {
772 phy->
freq = &tegra_freq_table[
i];
777 pr_err(
"invalid pll_u parent rate %ld\n", parent_rate);
782 phy->
u_phy.init = tegra_phy_init;
783 phy->
u_phy.shutdown = tegra_usb_phy_close;
784 phy->
u_phy.set_suspend = tegra_usb_phy_suspend;
789 clk_disable_unprepare(phy->
pll_u);
799 if (!phy_is_ulpi(phy))
800 utmi_phy_preresume(phy);
806 if (!phy_is_ulpi(phy))
807 utmi_phy_postresume(phy);
814 if (!phy_is_ulpi(phy))
815 utmi_phy_restore_start(phy, port_speed);
821 if (!phy_is_ulpi(phy))
822 utmi_phy_restore_end(phy);
828 if (!phy_is_ulpi(phy))
829 utmi_phy_clk_disable(phy);
835 if (!phy_is_ulpi(phy))
836 utmi_phy_clk_enable(phy);