Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 08d6ec2 | 2012-02-27 10:52:49 +0000 | [diff] [blame] | 2 | /* |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 4 | * Copyright (c) 2009-2015 NVIDIA Corporation |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 5 | * Copyright (c) 2013 Lucas Stach |
Simon Glass | 08d6ec2 | 2012-02-27 10:52:49 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 10 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 11 | #include <linux/errno.h> |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm-generic/gpio.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch-tegra/usb.h> |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 16 | #include <asm/arch-tegra/clk_rst.h> |
Simon Glass | 08d6ec2 | 2012-02-27 10:52:49 +0000 | [diff] [blame] | 17 | #include <usb.h> |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 18 | #include <usb/ulpi.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 19 | #include <linux/libfdt.h> |
Simon Glass | 08d6ec2 | 2012-02-27 10:52:49 +0000 | [diff] [blame] | 20 | |
| 21 | #include "ehci.h" |
Simon Glass | 08d6ec2 | 2012-02-27 10:52:49 +0000 | [diff] [blame] | 22 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 23 | #define USB1_ADDR_MASK 0xFFFF0000 |
| 24 | |
| 25 | #define HOSTPC1_DEVLC 0x84 |
| 26 | #define HOSTPC1_PSPD(x) (((x) >> 25) & 0x3) |
| 27 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 28 | #ifdef CONFIG_USB_ULPI |
| 29 | #ifndef CONFIG_USB_ULPI_VIEWPORT |
| 30 | #error "To use CONFIG_USB_ULPI on Tegra Boards you have to also \ |
| 31 | define CONFIG_USB_ULPI_VIEWPORT" |
| 32 | #endif |
| 33 | #endif |
| 34 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 35 | /* Parameters we need for USB */ |
| 36 | enum { |
| 37 | PARAM_DIVN, /* PLL FEEDBACK DIVIDer */ |
| 38 | PARAM_DIVM, /* PLL INPUT DIVIDER */ |
| 39 | PARAM_DIVP, /* POST DIVIDER (2^N) */ |
| 40 | PARAM_CPCON, /* BASE PLLC CHARGE Pump setup ctrl */ |
| 41 | PARAM_LFCON, /* BASE PLLC LOOP FILter setup ctrl */ |
| 42 | PARAM_ENABLE_DELAY_COUNT, /* PLL-U Enable Delay Count */ |
| 43 | PARAM_STABLE_COUNT, /* PLL-U STABLE count */ |
| 44 | PARAM_ACTIVE_DELAY_COUNT, /* PLL-U Active delay count */ |
| 45 | PARAM_XTAL_FREQ_COUNT, /* PLL-U XTAL frequency count */ |
| 46 | PARAM_DEBOUNCE_A_TIME, /* 10MS DELAY for BIAS_DEBOUNCE_A */ |
| 47 | PARAM_BIAS_TIME, /* 20US DELAY AFter bias cell op */ |
| 48 | |
| 49 | PARAM_COUNT |
| 50 | }; |
| 51 | |
| 52 | /* Possible port types (dual role mode) */ |
| 53 | enum dr_mode { |
| 54 | DR_MODE_NONE = 0, |
| 55 | DR_MODE_HOST, /* supports host operation */ |
| 56 | DR_MODE_DEVICE, /* supports device operation */ |
| 57 | DR_MODE_OTG, /* supports both */ |
| 58 | }; |
| 59 | |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 60 | enum usb_ctlr_type { |
| 61 | USB_CTLR_T20, |
| 62 | USB_CTLR_T30, |
| 63 | USB_CTLR_T114, |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 64 | USB_CTLR_T210, |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 65 | |
| 66 | USB_CTRL_COUNT, |
| 67 | }; |
| 68 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 69 | /* Information about a USB port */ |
| 70 | struct fdt_usb { |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 71 | struct ehci_ctrl ehci; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 72 | struct usb_ctlr *reg; /* address of registers in physical memory */ |
| 73 | unsigned utmi:1; /* 1 if port has external tranceiver, else 0 */ |
| 74 | unsigned ulpi:1; /* 1 if port has external ULPI transceiver */ |
| 75 | unsigned enabled:1; /* 1 to enable, 0 to disable */ |
| 76 | unsigned has_legacy_mode:1; /* 1 if this port has legacy mode */ |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 77 | enum usb_ctlr_type type; |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 78 | enum usb_init_type init_type; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 79 | enum dr_mode dr_mode; /* dual role mode */ |
| 80 | enum periph_id periph_id;/* peripheral id */ |
Simon Glass | fec09c5 | 2015-01-05 20:05:39 -0700 | [diff] [blame] | 81 | struct gpio_desc vbus_gpio; /* GPIO for vbus enable */ |
| 82 | struct gpio_desc phy_reset_gpio; /* GPIO to reset ULPI phy */ |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 85 | /* |
| 86 | * This table has USB timing parameters for each Oscillator frequency we |
| 87 | * support. There are four sets of values: |
| 88 | * |
| 89 | * 1. PLLU configuration information (reference clock is osc/clk_m and |
| 90 | * PLLU-FOs are fixed at 12MHz/60MHz/480MHz). |
| 91 | * |
| 92 | * Reference frequency 13.0MHz 19.2MHz 12.0MHz 26.0MHz |
| 93 | * ---------------------------------------------------------------------- |
| 94 | * DIVN 960 (0x3c0) 200 (0c8) 960 (3c0h) 960 (3c0) |
| 95 | * DIVM 13 (0d) 4 (04) 12 (0c) 26 (1a) |
| 96 | * Filter frequency (MHz) 1 4.8 6 2 |
| 97 | * CPCON 1100b 0011b 1100b 1100b |
| 98 | * LFCON0 0 0 0 0 |
| 99 | * |
| 100 | * 2. PLL CONFIGURATION & PARAMETERS for different clock generators: |
| 101 | * |
| 102 | * Reference frequency 13.0MHz 19.2MHz 12.0MHz 26.0MHz |
| 103 | * --------------------------------------------------------------------------- |
| 104 | * PLLU_ENABLE_DLY_COUNT 02 (0x02) 03 (03) 02 (02) 04 (04) |
| 105 | * PLLU_STABLE_COUNT 51 (33) 75 (4B) 47 (2F) 102 (66) |
| 106 | * PLL_ACTIVE_DLY_COUNT 05 (05) 06 (06) 04 (04) 09 (09) |
| 107 | * XTAL_FREQ_COUNT 127 (7F) 187 (BB) 118 (76) 254 (FE) |
| 108 | * |
| 109 | * 3. Debounce values IdDig, Avalid, Bvalid, VbusValid, VbusWakeUp, and |
| 110 | * SessEnd. Each of these signals have their own debouncer and for each of |
| 111 | * those one out of two debouncing times can be chosen (BIAS_DEBOUNCE_A or |
| 112 | * BIAS_DEBOUNCE_B). |
| 113 | * |
| 114 | * The values of DEBOUNCE_A and DEBOUNCE_B are calculated as follows: |
| 115 | * 0xffff -> No debouncing at all |
| 116 | * <n> ms = <n> *1000 / (1/19.2MHz) / 4 |
| 117 | * |
| 118 | * So to program a 1 ms debounce for BIAS_DEBOUNCE_A, we have: |
| 119 | * BIAS_DEBOUNCE_A[15:0] = 1000 * 19.2 / 4 = 4800 = 0x12c0 |
| 120 | * |
| 121 | * We need to use only DebounceA for BOOTROM. We don't need the DebounceB |
| 122 | * values, so we can keep those to default. |
| 123 | * |
| 124 | * 4. The 20 microsecond delay after bias cell operation. |
| 125 | */ |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 126 | static const unsigned T20_usb_pll[CLOCK_OSC_FREQ_COUNT][PARAM_COUNT] = { |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 127 | /* DivN, DivM, DivP, CPCON, LFCON, Delays Debounce, Bias */ |
| 128 | { 0x3C0, 0x0D, 0x00, 0xC, 0, 0x02, 0x33, 0x05, 0x7F, 0x7EF4, 5 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 129 | { 0x3C0, 0x0D, 0x00, 0xC, 0, 0x02, 0x33, 0x05, 0x7F, 0x7EF4, 5 }, |
| 130 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 131 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 132 | { 0x0C8, 0x04, 0x00, 0x3, 0, 0x03, 0x4B, 0x06, 0xBB, 0xBB80, 7 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 133 | { 0x0C8, 0x04, 0x00, 0x3, 0, 0x03, 0x4B, 0x06, 0xBB, 0xBB80, 7 }, |
| 134 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 135 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 136 | { 0x3C0, 0x0C, 0x00, 0xC, 0, 0x02, 0x2F, 0x04, 0x76, 0x7530, 5 }, |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 137 | { 0x3C0, 0x0C, 0x00, 0xC, 0, 0x02, 0x2F, 0x04, 0x76, 0x7530, 5 }, |
Tom Warren | 27bce71 | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 138 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 139 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 140 | { 0x3C0, 0x1A, 0x00, 0xC, 0, 0x04, 0x66, 0x09, 0xFE, 0xFDE8, 9 } |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 143 | static const unsigned T30_usb_pll[CLOCK_OSC_FREQ_COUNT][PARAM_COUNT] = { |
| 144 | /* DivN, DivM, DivP, CPCON, LFCON, Delays Debounce, Bias */ |
| 145 | { 0x3C0, 0x0D, 0x00, 0xC, 1, 0x02, 0x33, 0x09, 0x7F, 0x7EF4, 5 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 146 | { 0x3C0, 0x0D, 0x00, 0xC, 1, 0x02, 0x33, 0x09, 0x7F, 0x7EF4, 5 }, |
| 147 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 148 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 149 | { 0x0C8, 0x04, 0x00, 0x3, 0, 0x03, 0x4B, 0x0C, 0xBB, 0xBB80, 7 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 150 | { 0x0C8, 0x04, 0x00, 0x3, 0, 0x03, 0x4B, 0x0C, 0xBB, 0xBB80, 7 }, |
| 151 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 152 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 153 | { 0x3C0, 0x0C, 0x00, 0xC, 1, 0x02, 0x2F, 0x08, 0x76, 0x7530, 5 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 154 | { 0x3C0, 0x0C, 0x00, 0xC, 1, 0x02, 0x2F, 0x08, 0x76, 0x7530, 5 }, |
| 155 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Tom Warren | 27bce71 | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 156 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 157 | { 0x3C0, 0x1A, 0x00, 0xC, 1, 0x04, 0x66, 0x09, 0xFE, 0xFDE8, 9 } |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | static const unsigned T114_usb_pll[CLOCK_OSC_FREQ_COUNT][PARAM_COUNT] = { |
| 161 | /* DivN, DivM, DivP, CPCON, LFCON, Delays Debounce, Bias */ |
| 162 | { 0x3C0, 0x0D, 0x00, 0xC, 2, 0x02, 0x33, 0x09, 0x7F, 0x7EF4, 6 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 163 | { 0x3C0, 0x0D, 0x00, 0xC, 2, 0x02, 0x33, 0x09, 0x7F, 0x7EF4, 6 }, |
| 164 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 165 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 166 | { 0x0C8, 0x04, 0x00, 0x3, 2, 0x03, 0x4B, 0x0C, 0xBB, 0xBB80, 8 }, |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 167 | { 0x0C8, 0x04, 0x00, 0x3, 2, 0x03, 0x4B, 0x0C, 0xBB, 0xBB80, 8 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 168 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 169 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
| 170 | { 0x3C0, 0x0C, 0x00, 0xC, 2, 0x02, 0x2F, 0x08, 0x76, 0x7530, 5 }, |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 171 | { 0x3C0, 0x0C, 0x00, 0xC, 2, 0x02, 0x2F, 0x08, 0x76, 0x7530, 5 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 172 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Tom Warren | 27bce71 | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 173 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0x0000, 0 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 174 | { 0x3C0, 0x1A, 0x00, 0xC, 2, 0x04, 0x66, 0x09, 0xFE, 0xFDE8, 11 } |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 175 | }; |
| 176 | |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 177 | /* NOTE: 13/26MHz settings are N/A for T210, so dupe 12MHz settings for now */ |
| 178 | static const unsigned T210_usb_pll[CLOCK_OSC_FREQ_COUNT][PARAM_COUNT] = { |
| 179 | /* DivN, DivM, DivP, KCP, KVCO, Delays Debounce, Bias */ |
Tom Warren | 27bce71 | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 180 | { 0x028, 0x01, 0x01, 0x0, 0, 0x02, 0x2F, 0x08, 0x76, 32500, 5 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 181 | { 0x028, 0x01, 0x01, 0x0, 0, 0x02, 0x2F, 0x08, 0x76, 32500, 5 }, |
| 182 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0, 0 }, |
| 183 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0, 0 }, |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 184 | { 0x019, 0x01, 0x01, 0x0, 0, 0x03, 0x4B, 0x0C, 0xBB, 48000, 8 }, |
Tom Warren | 27bce71 | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 185 | { 0x019, 0x02, 0x01, 0x0, 0, 0x05, 0x96, 0x18, 0x177, 96000, 15 }, |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 186 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0, 0 }, |
| 187 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0, 0 }, |
| 188 | { 0x028, 0x01, 0x01, 0x0, 0, 0x02, 0x2F, 0x08, 0x76, 30000, 5 }, |
| 189 | { 0x028, 0x04, 0x01, 0x0, 0, 0x04, 0x66, 0x09, 0xFE, 120000, 20 }, |
| 190 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0, 0 }, |
| 191 | { 0x000, 0x00, 0x00, 0x0, 0, 0x00, 0x00, 0x00, 0x00, 0, 0 }, |
| 192 | { 0x028, 0x01, 0x01, 0x0, 0, 0x02, 0x2F, 0x08, 0x76, 65000, 5 } |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 195 | /* UTMIP Idle Wait Delay */ |
| 196 | static const u8 utmip_idle_wait_delay = 17; |
| 197 | |
| 198 | /* UTMIP Elastic limit */ |
| 199 | static const u8 utmip_elastic_limit = 16; |
| 200 | |
| 201 | /* UTMIP High Speed Sync Start Delay */ |
| 202 | static const u8 utmip_hs_sync_start_delay = 9; |
Simon Glass | 08d6ec2 | 2012-02-27 10:52:49 +0000 | [diff] [blame] | 203 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 204 | struct fdt_usb_controller { |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 205 | /* flag to determine whether controller supports hostpc register */ |
| 206 | u32 has_hostpc:1; |
| 207 | const unsigned *pll_parameter; |
| 208 | }; |
| 209 | |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 210 | static struct fdt_usb_controller fdt_usb_controllers[USB_CTRL_COUNT] = { |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 211 | { |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 212 | .has_hostpc = 0, |
| 213 | .pll_parameter = (const unsigned *)T20_usb_pll, |
| 214 | }, |
| 215 | { |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 216 | .has_hostpc = 1, |
| 217 | .pll_parameter = (const unsigned *)T30_usb_pll, |
| 218 | }, |
| 219 | { |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 220 | .has_hostpc = 1, |
| 221 | .pll_parameter = (const unsigned *)T114_usb_pll, |
| 222 | }, |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 223 | { |
| 224 | .has_hostpc = 1, |
| 225 | .pll_parameter = (const unsigned *)T210_usb_pll, |
| 226 | }, |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 227 | }; |
| 228 | |
Jim Lin | 5a057e3 | 2012-06-24 20:40:57 +0000 | [diff] [blame] | 229 | /* |
| 230 | * A known hardware issue where Connect Status Change bit of PORTSC register |
| 231 | * of USB1 controller will be set after Port Reset. |
| 232 | * We have to clear it in order for later device enumeration to proceed. |
Jim Lin | 5a057e3 | 2012-06-24 20:40:57 +0000 | [diff] [blame] | 233 | */ |
Simon Glass | dc9f3ed | 2015-03-25 12:22:27 -0600 | [diff] [blame] | 234 | static void tegra_ehci_powerup_fixup(struct ehci_ctrl *ctrl, |
| 235 | uint32_t *status_reg, uint32_t *reg) |
Jim Lin | 5a057e3 | 2012-06-24 20:40:57 +0000 | [diff] [blame] | 236 | { |
Simon Glass | 66a79f3 | 2015-03-25 12:22:22 -0600 | [diff] [blame] | 237 | struct fdt_usb *config = ctrl->priv; |
| 238 | struct fdt_usb_controller *controller; |
| 239 | |
| 240 | controller = &fdt_usb_controllers[config->type]; |
Jim Lin | 5a057e3 | 2012-06-24 20:40:57 +0000 | [diff] [blame] | 241 | mdelay(50); |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 242 | /* This is to avoid PORT_ENABLE bit to be cleared in "ehci-hcd.c". */ |
| 243 | if (controller->has_hostpc) |
| 244 | *reg |= EHCI_PS_PE; |
| 245 | |
Simon Glass | 57c76c3 | 2015-03-25 12:22:45 -0600 | [diff] [blame] | 246 | if (!config->has_legacy_mode) |
Jim Lin | 5a057e3 | 2012-06-24 20:40:57 +0000 | [diff] [blame] | 247 | return; |
| 248 | /* For EHCI_PS_CSC to be cleared in ehci_hcd.c */ |
| 249 | if (ehci_readl(status_reg) & EHCI_PS_CSC) |
| 250 | *reg |= EHCI_PS_CSC; |
| 251 | } |
Simon Glass | 08d6ec2 | 2012-02-27 10:52:49 +0000 | [diff] [blame] | 252 | |
Simon Glass | dc9f3ed | 2015-03-25 12:22:27 -0600 | [diff] [blame] | 253 | static void tegra_ehci_set_usbmode(struct ehci_ctrl *ctrl) |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 254 | { |
Simon Glass | 2d387ab | 2015-03-25 12:22:23 -0600 | [diff] [blame] | 255 | struct fdt_usb *config = ctrl->priv; |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 256 | struct usb_ctlr *usbctlr; |
| 257 | uint32_t tmp; |
| 258 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 259 | usbctlr = config->reg; |
| 260 | |
| 261 | tmp = ehci_readl(&usbctlr->usb_mode); |
| 262 | tmp |= USBMODE_CM_HC; |
| 263 | ehci_writel(&usbctlr->usb_mode, tmp); |
| 264 | } |
| 265 | |
Simon Glass | dc9f3ed | 2015-03-25 12:22:27 -0600 | [diff] [blame] | 266 | static int tegra_ehci_get_port_speed(struct ehci_ctrl *ctrl, uint32_t reg) |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 267 | { |
Simon Glass | 66a79f3 | 2015-03-25 12:22:22 -0600 | [diff] [blame] | 268 | struct fdt_usb *config = ctrl->priv; |
| 269 | struct fdt_usb_controller *controller; |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 270 | uint32_t tmp; |
| 271 | uint32_t *reg_ptr; |
| 272 | |
Simon Glass | 66a79f3 | 2015-03-25 12:22:22 -0600 | [diff] [blame] | 273 | controller = &fdt_usb_controllers[config->type]; |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 274 | if (controller->has_hostpc) { |
Simon Glass | c78c765 | 2015-03-25 12:22:18 -0600 | [diff] [blame] | 275 | reg_ptr = (uint32_t *)((u8 *)&ctrl->hcor->or_usbcmd + |
| 276 | HOSTPC1_DEVLC); |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 277 | tmp = ehci_readl(reg_ptr); |
| 278 | return HOSTPC1_PSPD(tmp); |
| 279 | } else |
| 280 | return PORTSC_PSPD(reg); |
| 281 | } |
| 282 | |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 283 | /* Set up VBUS for host/device mode */ |
| 284 | static void set_up_vbus(struct fdt_usb *config, enum usb_init_type init) |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 285 | { |
| 286 | /* |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 287 | * If we are an OTG port initializing in host mode, |
| 288 | * check if remote host is driving VBus and bail out in this case. |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 289 | */ |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 290 | if (init == USB_INIT_HOST && |
| 291 | config->dr_mode == DR_MODE_OTG && |
| 292 | (readl(&config->reg->phy_vbus_sensors) & VBUS_VLD_STS)) { |
| 293 | printf("tegrausb: VBUS input active; not enabling as host\n"); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 294 | return; |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 295 | } |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 296 | |
Simon Glass | fec09c5 | 2015-01-05 20:05:39 -0700 | [diff] [blame] | 297 | if (dm_gpio_is_valid(&config->vbus_gpio)) { |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 298 | int vbus_value; |
| 299 | |
Simon Glass | fec09c5 | 2015-01-05 20:05:39 -0700 | [diff] [blame] | 300 | vbus_value = (init == USB_INIT_HOST); |
| 301 | dm_gpio_set_value(&config->vbus_gpio, vbus_value); |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 302 | |
Simon Glass | fec09c5 | 2015-01-05 20:05:39 -0700 | [diff] [blame] | 303 | debug("set_up_vbus: GPIO %d %d\n", |
| 304 | gpio_get_number(&config->vbus_gpio), vbus_value); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 308 | static void usbf_reset_controller(struct fdt_usb *config, |
| 309 | struct usb_ctlr *usbctlr) |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 310 | { |
| 311 | /* Reset the USB controller with 2us delay */ |
| 312 | reset_periph(config->periph_id, 2); |
| 313 | |
| 314 | /* |
| 315 | * Set USB1_NO_LEGACY_MODE to 1, Registers are accessible under |
| 316 | * base address |
| 317 | */ |
| 318 | if (config->has_legacy_mode) |
| 319 | setbits_le32(&usbctlr->usb1_legacy_ctrl, USB1_NO_LEGACY_MODE); |
| 320 | |
| 321 | /* Put UTMIP1/3 in reset */ |
| 322 | setbits_le32(&usbctlr->susp_ctrl, UTMIP_RESET); |
| 323 | |
| 324 | /* Enable the UTMIP PHY */ |
| 325 | if (config->utmi) |
| 326 | setbits_le32(&usbctlr->susp_ctrl, UTMIP_PHY_ENB); |
| 327 | } |
| 328 | |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 329 | static const unsigned *get_pll_timing(struct fdt_usb_controller *controller) |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 330 | { |
| 331 | const unsigned *timing; |
| 332 | |
| 333 | timing = controller->pll_parameter + |
| 334 | clock_get_osc_freq() * PARAM_COUNT; |
| 335 | |
| 336 | return timing; |
| 337 | } |
| 338 | |
Stephen Warren | 600246c | 2014-04-30 15:09:56 -0600 | [diff] [blame] | 339 | /* select the PHY to use with a USB controller */ |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 340 | static void init_phy_mux(struct fdt_usb *config, uint pts, |
| 341 | enum usb_init_type init) |
Stephen Warren | 600246c | 2014-04-30 15:09:56 -0600 | [diff] [blame] | 342 | { |
| 343 | struct usb_ctlr *usbctlr = config->reg; |
| 344 | |
| 345 | #if defined(CONFIG_TEGRA20) |
| 346 | if (config->periph_id == PERIPH_ID_USBD) { |
| 347 | clrsetbits_le32(&usbctlr->port_sc1, PTS1_MASK, |
Marcel Ziswiler | afc106e | 2014-10-04 01:46:10 +0200 | [diff] [blame] | 348 | pts << PTS1_SHIFT); |
Stephen Warren | 600246c | 2014-04-30 15:09:56 -0600 | [diff] [blame] | 349 | clrbits_le32(&usbctlr->port_sc1, STS1); |
| 350 | } else { |
| 351 | clrsetbits_le32(&usbctlr->port_sc1, PTS_MASK, |
Marcel Ziswiler | afc106e | 2014-10-04 01:46:10 +0200 | [diff] [blame] | 352 | pts << PTS_SHIFT); |
Stephen Warren | 600246c | 2014-04-30 15:09:56 -0600 | [diff] [blame] | 353 | clrbits_le32(&usbctlr->port_sc1, STS); |
| 354 | } |
| 355 | #else |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 356 | /* Set to Host mode (if applicable) after Controller Reset was done */ |
Stephen Warren | 600246c | 2014-04-30 15:09:56 -0600 | [diff] [blame] | 357 | clrsetbits_le32(&usbctlr->usb_mode, USBMODE_CM_HC, |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 358 | (init == USB_INIT_HOST) ? USBMODE_CM_HC : 0); |
| 359 | /* |
| 360 | * Select PHY interface after setting host mode. |
| 361 | * For device mode, the ordering requirement is not an issue, since |
| 362 | * only the first USB controller supports device mode, and that USB |
| 363 | * controller can only talk to a UTMI PHY, so the PHY selection is |
| 364 | * already made at reset time, so this write is a no-op. |
| 365 | */ |
Stephen Warren | 600246c | 2014-04-30 15:09:56 -0600 | [diff] [blame] | 366 | clrsetbits_le32(&usbctlr->hostpc1_devlc, PTS_MASK, |
| 367 | pts << PTS_SHIFT); |
| 368 | clrbits_le32(&usbctlr->hostpc1_devlc, STS); |
| 369 | #endif |
| 370 | } |
| 371 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 372 | /* set up the UTMI USB controller with the parameters provided */ |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 373 | static int init_utmi_usb_controller(struct fdt_usb *config, |
| 374 | enum usb_init_type init) |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 375 | { |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 376 | struct fdt_usb_controller *controller; |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 377 | u32 b_sess_valid_mask, val; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 378 | int loop_count; |
| 379 | const unsigned *timing; |
| 380 | struct usb_ctlr *usbctlr = config->reg; |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 381 | struct clk_rst_ctlr *clkrst; |
| 382 | struct usb_ctlr *usb1ctlr; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 383 | |
| 384 | clock_enable(config->periph_id); |
| 385 | |
| 386 | /* Reset the usb controller */ |
| 387 | usbf_reset_controller(config, usbctlr); |
| 388 | |
| 389 | /* Stop crystal clock by setting UTMIP_PHY_XTAL_CLOCKEN low */ |
| 390 | clrbits_le32(&usbctlr->utmip_misc_cfg1, UTMIP_PHY_XTAL_CLOCKEN); |
| 391 | |
| 392 | /* Follow the crystal clock disable by >100ns delay */ |
| 393 | udelay(1); |
| 394 | |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 395 | b_sess_valid_mask = (VBUS_B_SESS_VLD_SW_VALUE | VBUS_B_SESS_VLD_SW_EN); |
| 396 | clrsetbits_le32(&usbctlr->phy_vbus_sensors, b_sess_valid_mask, |
| 397 | (init == USB_INIT_DEVICE) ? b_sess_valid_mask : 0); |
| 398 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 399 | /* |
| 400 | * To Use the A Session Valid for cable detection logic, VBUS_WAKEUP |
| 401 | * mux must be switched to actually use a_sess_vld threshold. |
| 402 | */ |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 403 | if (config->dr_mode == DR_MODE_OTG && |
Simon Glass | fec09c5 | 2015-01-05 20:05:39 -0700 | [diff] [blame] | 404 | dm_gpio_is_valid(&config->vbus_gpio)) |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 405 | clrsetbits_le32(&usbctlr->usb1_legacy_ctrl, |
| 406 | VBUS_SENSE_CTL_MASK, |
| 407 | VBUS_SENSE_CTL_A_SESS_VLD << VBUS_SENSE_CTL_SHIFT); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 408 | |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 409 | controller = &fdt_usb_controllers[config->type]; |
| 410 | debug("controller=%p, type=%d\n", controller, config->type); |
| 411 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 412 | /* |
| 413 | * PLL Delay CONFIGURATION settings. The following parameters control |
| 414 | * the bring up of the plls. |
| 415 | */ |
Simon Glass | 92a419e | 2015-03-25 12:22:20 -0600 | [diff] [blame] | 416 | timing = get_pll_timing(controller); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 417 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 418 | if (!controller->has_hostpc) { |
| 419 | val = readl(&usbctlr->utmip_misc_cfg1); |
| 420 | clrsetbits_le32(&val, UTMIP_PLLU_STABLE_COUNT_MASK, |
| 421 | timing[PARAM_STABLE_COUNT] << |
| 422 | UTMIP_PLLU_STABLE_COUNT_SHIFT); |
| 423 | clrsetbits_le32(&val, UTMIP_PLL_ACTIVE_DLY_COUNT_MASK, |
| 424 | timing[PARAM_ACTIVE_DELAY_COUNT] << |
| 425 | UTMIP_PLL_ACTIVE_DLY_COUNT_SHIFT); |
| 426 | writel(val, &usbctlr->utmip_misc_cfg1); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 427 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 428 | /* Set PLL enable delay count and crystal frequency count */ |
| 429 | val = readl(&usbctlr->utmip_pll_cfg1); |
| 430 | clrsetbits_le32(&val, UTMIP_PLLU_ENABLE_DLY_COUNT_MASK, |
| 431 | timing[PARAM_ENABLE_DELAY_COUNT] << |
| 432 | UTMIP_PLLU_ENABLE_DLY_COUNT_SHIFT); |
| 433 | clrsetbits_le32(&val, UTMIP_XTAL_FREQ_COUNT_MASK, |
| 434 | timing[PARAM_XTAL_FREQ_COUNT] << |
| 435 | UTMIP_XTAL_FREQ_COUNT_SHIFT); |
| 436 | writel(val, &usbctlr->utmip_pll_cfg1); |
| 437 | } else { |
| 438 | clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 439 | |
| 440 | val = readl(&clkrst->crc_utmip_pll_cfg2); |
| 441 | clrsetbits_le32(&val, UTMIP_PLLU_STABLE_COUNT_MASK, |
| 442 | timing[PARAM_STABLE_COUNT] << |
| 443 | UTMIP_PLLU_STABLE_COUNT_SHIFT); |
| 444 | clrsetbits_le32(&val, UTMIP_PLL_ACTIVE_DLY_COUNT_MASK, |
| 445 | timing[PARAM_ACTIVE_DELAY_COUNT] << |
| 446 | UTMIP_PLL_ACTIVE_DLY_COUNT_SHIFT); |
| 447 | writel(val, &clkrst->crc_utmip_pll_cfg2); |
| 448 | |
| 449 | /* Set PLL enable delay count and crystal frequency count */ |
| 450 | val = readl(&clkrst->crc_utmip_pll_cfg1); |
| 451 | clrsetbits_le32(&val, UTMIP_PLLU_ENABLE_DLY_COUNT_MASK, |
| 452 | timing[PARAM_ENABLE_DELAY_COUNT] << |
| 453 | UTMIP_PLLU_ENABLE_DLY_COUNT_SHIFT); |
| 454 | clrsetbits_le32(&val, UTMIP_XTAL_FREQ_COUNT_MASK, |
| 455 | timing[PARAM_XTAL_FREQ_COUNT] << |
| 456 | UTMIP_XTAL_FREQ_COUNT_SHIFT); |
| 457 | writel(val, &clkrst->crc_utmip_pll_cfg1); |
| 458 | |
| 459 | /* Disable Power Down state for PLL */ |
| 460 | clrbits_le32(&clkrst->crc_utmip_pll_cfg1, |
| 461 | PLLU_POWERDOWN | PLL_ENABLE_POWERDOWN | |
| 462 | PLL_ACTIVE_POWERDOWN); |
| 463 | |
| 464 | /* Recommended PHY settings for EYE diagram */ |
| 465 | val = readl(&usbctlr->utmip_xcvr_cfg0); |
| 466 | clrsetbits_le32(&val, UTMIP_XCVR_SETUP_MASK, |
| 467 | 0x4 << UTMIP_XCVR_SETUP_SHIFT); |
| 468 | clrsetbits_le32(&val, UTMIP_XCVR_SETUP_MSB_MASK, |
| 469 | 0x3 << UTMIP_XCVR_SETUP_MSB_SHIFT); |
| 470 | clrsetbits_le32(&val, UTMIP_XCVR_HSSLEW_MSB_MASK, |
| 471 | 0x8 << UTMIP_XCVR_HSSLEW_MSB_SHIFT); |
| 472 | writel(val, &usbctlr->utmip_xcvr_cfg0); |
| 473 | clrsetbits_le32(&usbctlr->utmip_xcvr_cfg1, |
| 474 | UTMIP_XCVR_TERM_RANGE_ADJ_MASK, |
| 475 | 0x7 << UTMIP_XCVR_TERM_RANGE_ADJ_SHIFT); |
| 476 | |
| 477 | /* Some registers can be controlled from USB1 only. */ |
| 478 | if (config->periph_id != PERIPH_ID_USBD) { |
| 479 | clock_enable(PERIPH_ID_USBD); |
| 480 | /* Disable Reset if in Reset state */ |
| 481 | reset_set_enable(PERIPH_ID_USBD, 0); |
| 482 | } |
| 483 | usb1ctlr = (struct usb_ctlr *) |
Thierry Reding | 4375b44 | 2015-03-20 12:41:27 +0100 | [diff] [blame] | 484 | ((unsigned long)config->reg & USB1_ADDR_MASK); |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 485 | val = readl(&usb1ctlr->utmip_bias_cfg0); |
| 486 | setbits_le32(&val, UTMIP_HSDISCON_LEVEL_MSB); |
| 487 | clrsetbits_le32(&val, UTMIP_HSDISCON_LEVEL_MASK, |
| 488 | 0x1 << UTMIP_HSDISCON_LEVEL_SHIFT); |
| 489 | clrsetbits_le32(&val, UTMIP_HSSQUELCH_LEVEL_MASK, |
| 490 | 0x2 << UTMIP_HSSQUELCH_LEVEL_SHIFT); |
| 491 | writel(val, &usb1ctlr->utmip_bias_cfg0); |
| 492 | |
| 493 | /* Miscellaneous setting mentioned in Programming Guide */ |
| 494 | clrbits_le32(&usbctlr->utmip_misc_cfg0, |
| 495 | UTMIP_SUSPEND_EXIT_ON_EDGE); |
| 496 | } |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 497 | |
| 498 | /* Setting the tracking length time */ |
| 499 | clrsetbits_le32(&usbctlr->utmip_bias_cfg1, |
| 500 | UTMIP_BIAS_PDTRK_COUNT_MASK, |
| 501 | timing[PARAM_BIAS_TIME] << UTMIP_BIAS_PDTRK_COUNT_SHIFT); |
| 502 | |
| 503 | /* Program debounce time for VBUS to become valid */ |
| 504 | clrsetbits_le32(&usbctlr->utmip_debounce_cfg0, |
| 505 | UTMIP_DEBOUNCE_CFG0_MASK, |
| 506 | timing[PARAM_DEBOUNCE_A_TIME] << UTMIP_DEBOUNCE_CFG0_SHIFT); |
| 507 | |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 508 | if (timing[PARAM_DEBOUNCE_A_TIME] > 0xFFFF) { |
| 509 | clrsetbits_le32(&usbctlr->utmip_debounce_cfg0, |
| 510 | UTMIP_DEBOUNCE_CFG0_MASK, |
| 511 | (timing[PARAM_DEBOUNCE_A_TIME] >> 1) |
| 512 | << UTMIP_DEBOUNCE_CFG0_SHIFT); |
| 513 | clrsetbits_le32(&usbctlr->utmip_bias_cfg1, |
| 514 | UTMIP_BIAS_DEBOUNCE_TIMESCALE_MASK, |
| 515 | 1 << UTMIP_BIAS_DEBOUNCE_TIMESCALE_SHIFT); |
| 516 | } |
| 517 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 518 | setbits_le32(&usbctlr->utmip_tx_cfg0, UTMIP_FS_PREAMBLE_J); |
| 519 | |
| 520 | /* Disable battery charge enabling bit */ |
| 521 | setbits_le32(&usbctlr->utmip_bat_chrg_cfg0, UTMIP_PD_CHRG); |
| 522 | |
| 523 | clrbits_le32(&usbctlr->utmip_xcvr_cfg0, UTMIP_XCVR_LSBIAS_SE); |
| 524 | setbits_le32(&usbctlr->utmip_spare_cfg0, FUSE_SETUP_SEL); |
| 525 | |
| 526 | /* |
| 527 | * Configure the UTMIP_IDLE_WAIT and UTMIP_ELASTIC_LIMIT |
| 528 | * Setting these fields, together with default values of the |
| 529 | * other fields, results in programming the registers below as |
| 530 | * follows: |
| 531 | * UTMIP_HSRX_CFG0 = 0x9168c000 |
| 532 | * UTMIP_HSRX_CFG1 = 0x13 |
| 533 | */ |
| 534 | |
| 535 | /* Set PLL enable delay count and Crystal frequency count */ |
| 536 | val = readl(&usbctlr->utmip_hsrx_cfg0); |
| 537 | clrsetbits_le32(&val, UTMIP_IDLE_WAIT_MASK, |
| 538 | utmip_idle_wait_delay << UTMIP_IDLE_WAIT_SHIFT); |
| 539 | clrsetbits_le32(&val, UTMIP_ELASTIC_LIMIT_MASK, |
| 540 | utmip_elastic_limit << UTMIP_ELASTIC_LIMIT_SHIFT); |
| 541 | writel(val, &usbctlr->utmip_hsrx_cfg0); |
| 542 | |
| 543 | /* Configure the UTMIP_HS_SYNC_START_DLY */ |
| 544 | clrsetbits_le32(&usbctlr->utmip_hsrx_cfg1, |
| 545 | UTMIP_HS_SYNC_START_DLY_MASK, |
| 546 | utmip_hs_sync_start_delay << UTMIP_HS_SYNC_START_DLY_SHIFT); |
| 547 | |
| 548 | /* Preceed the crystal clock disable by >100ns delay. */ |
| 549 | udelay(1); |
| 550 | |
| 551 | /* Resuscitate crystal clock by setting UTMIP_PHY_XTAL_CLOCKEN */ |
| 552 | setbits_le32(&usbctlr->utmip_misc_cfg1, UTMIP_PHY_XTAL_CLOCKEN); |
| 553 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 554 | if (controller->has_hostpc) { |
| 555 | if (config->periph_id == PERIPH_ID_USBD) |
| 556 | clrbits_le32(&clkrst->crc_utmip_pll_cfg2, |
| 557 | UTMIP_FORCE_PD_SAMP_A_POWERDOWN); |
Stefan Agner | afc492b | 2014-03-02 19:46:48 +0100 | [diff] [blame] | 558 | if (config->periph_id == PERIPH_ID_USB2) |
| 559 | clrbits_le32(&clkrst->crc_utmip_pll_cfg2, |
| 560 | UTMIP_FORCE_PD_SAMP_B_POWERDOWN); |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 561 | if (config->periph_id == PERIPH_ID_USB3) |
| 562 | clrbits_le32(&clkrst->crc_utmip_pll_cfg2, |
| 563 | UTMIP_FORCE_PD_SAMP_C_POWERDOWN); |
| 564 | } |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 565 | /* Finished the per-controller init. */ |
| 566 | |
| 567 | /* De-assert UTMIP_RESET to bring out of reset. */ |
| 568 | clrbits_le32(&usbctlr->susp_ctrl, UTMIP_RESET); |
| 569 | |
| 570 | /* Wait for the phy clock to become valid in 100 ms */ |
| 571 | for (loop_count = 100000; loop_count != 0; loop_count--) { |
| 572 | if (readl(&usbctlr->susp_ctrl) & USB_PHY_CLK_VALID) |
| 573 | break; |
| 574 | udelay(1); |
| 575 | } |
| 576 | if (!loop_count) |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 577 | return -ETIMEDOUT; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 578 | |
| 579 | /* Disable ICUSB FS/LS transceiver */ |
| 580 | clrbits_le32(&usbctlr->icusb_ctrl, IC_ENB1); |
| 581 | |
| 582 | /* Select UTMI parallel interface */ |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 583 | init_phy_mux(config, PTS_UTMI, init); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 584 | |
| 585 | /* Deassert power down state */ |
| 586 | clrbits_le32(&usbctlr->utmip_xcvr_cfg0, UTMIP_FORCE_PD_POWERDOWN | |
| 587 | UTMIP_FORCE_PD2_POWERDOWN | UTMIP_FORCE_PDZI_POWERDOWN); |
| 588 | clrbits_le32(&usbctlr->utmip_xcvr_cfg1, UTMIP_FORCE_PDDISC_POWERDOWN | |
| 589 | UTMIP_FORCE_PDCHRP_POWERDOWN | UTMIP_FORCE_PDDR_POWERDOWN); |
| 590 | |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 591 | if (controller->has_hostpc) { |
| 592 | /* |
| 593 | * BIAS Pad Power Down is common among all 3 USB |
| 594 | * controllers and can be controlled from USB1 only. |
| 595 | */ |
| 596 | usb1ctlr = (struct usb_ctlr *) |
Thierry Reding | 4375b44 | 2015-03-20 12:41:27 +0100 | [diff] [blame] | 597 | ((unsigned long)config->reg & USB1_ADDR_MASK); |
Jim Lin | 2fefb8b | 2013-06-21 19:05:47 +0800 | [diff] [blame] | 598 | clrbits_le32(&usb1ctlr->utmip_bias_cfg0, UTMIP_BIASPD); |
| 599 | udelay(25); |
| 600 | clrbits_le32(&usb1ctlr->utmip_bias_cfg1, |
| 601 | UTMIP_FORCE_PDTRK_POWERDOWN); |
| 602 | } |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | #ifdef CONFIG_USB_ULPI |
| 607 | /* if board file does not set a ULPI reference frequency we default to 24MHz */ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 608 | #ifndef CFG_ULPI_REF_CLK |
| 609 | #define CFG_ULPI_REF_CLK 24000000 |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 610 | #endif |
| 611 | |
| 612 | /* set up the ULPI USB controller with the parameters provided */ |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 613 | static int init_ulpi_usb_controller(struct fdt_usb *config, |
| 614 | enum usb_init_type init) |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 615 | { |
| 616 | u32 val; |
| 617 | int loop_count; |
| 618 | struct ulpi_viewport ulpi_vp; |
| 619 | struct usb_ctlr *usbctlr = config->reg; |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 620 | int ret; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 621 | |
| 622 | /* set up ULPI reference clock on pllp_out4 */ |
| 623 | clock_enable(PERIPH_ID_DEV2_OUT); |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 624 | clock_set_pllout(CLOCK_ID_PERIPH, PLL_OUT4, CFG_ULPI_REF_CLK); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 625 | |
| 626 | /* reset ULPI phy */ |
Simon Glass | fec09c5 | 2015-01-05 20:05:39 -0700 | [diff] [blame] | 627 | if (dm_gpio_is_valid(&config->phy_reset_gpio)) { |
Stephen Warren | 7c25975 | 2016-09-15 12:19:37 -0600 | [diff] [blame] | 628 | /* |
| 629 | * This GPIO is typically active-low, and marked as such in |
| 630 | * device tree. dm_gpio_set_value() takes this into account |
| 631 | * and inverts the value we pass here if required. In other |
| 632 | * words, this first call logically asserts the reset signal, |
| 633 | * which typically results in driving the physical GPIO low, |
| 634 | * and the second call logically de-asserts the reset signal, |
| 635 | * which typically results in driver the GPIO high. |
| 636 | */ |
Simon Glass | fec09c5 | 2015-01-05 20:05:39 -0700 | [diff] [blame] | 637 | dm_gpio_set_value(&config->phy_reset_gpio, 1); |
Stephen Warren | 7c25975 | 2016-09-15 12:19:37 -0600 | [diff] [blame] | 638 | mdelay(5); |
| 639 | dm_gpio_set_value(&config->phy_reset_gpio, 0); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /* Reset the usb controller */ |
| 643 | clock_enable(config->periph_id); |
| 644 | usbf_reset_controller(config, usbctlr); |
| 645 | |
| 646 | /* enable pinmux bypass */ |
| 647 | setbits_le32(&usbctlr->ulpi_timing_ctrl_0, |
| 648 | ULPI_CLKOUT_PINMUX_BYP | ULPI_OUTPUT_PINMUX_BYP); |
| 649 | |
| 650 | /* Select ULPI parallel interface */ |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 651 | init_phy_mux(config, PTS_ULPI, init); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 652 | |
| 653 | /* enable ULPI transceiver */ |
| 654 | setbits_le32(&usbctlr->susp_ctrl, ULPI_PHY_ENB); |
| 655 | |
| 656 | /* configure ULPI transceiver timings */ |
| 657 | val = 0; |
| 658 | writel(val, &usbctlr->ulpi_timing_ctrl_1); |
| 659 | |
| 660 | val |= ULPI_DATA_TRIMMER_SEL(4); |
| 661 | val |= ULPI_STPDIRNXT_TRIMMER_SEL(4); |
| 662 | val |= ULPI_DIR_TRIMMER_SEL(4); |
| 663 | writel(val, &usbctlr->ulpi_timing_ctrl_1); |
| 664 | udelay(10); |
| 665 | |
| 666 | val |= ULPI_DATA_TRIMMER_LOAD; |
| 667 | val |= ULPI_STPDIRNXT_TRIMMER_LOAD; |
| 668 | val |= ULPI_DIR_TRIMMER_LOAD; |
| 669 | writel(val, &usbctlr->ulpi_timing_ctrl_1); |
| 670 | |
| 671 | /* set up phy for host operation with external vbus supply */ |
| 672 | ulpi_vp.port_num = 0; |
| 673 | ulpi_vp.viewport_addr = (u32)&usbctlr->ulpi_viewport; |
| 674 | |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 675 | ret = ulpi_init(&ulpi_vp); |
| 676 | if (ret) { |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 677 | printf("Tegra ULPI viewport init failed\n"); |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 678 | return ret; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | ulpi_set_vbus(&ulpi_vp, 1, 1); |
| 682 | ulpi_set_vbus_indicator(&ulpi_vp, 1, 1, 0); |
| 683 | |
| 684 | /* enable wakeup events */ |
| 685 | setbits_le32(&usbctlr->port_sc1, WKCN | WKDS | WKOC); |
| 686 | |
| 687 | /* Enable and wait for the phy clock to become valid in 100 ms */ |
| 688 | setbits_le32(&usbctlr->susp_ctrl, USB_SUSP_CLR); |
| 689 | for (loop_count = 100000; loop_count != 0; loop_count--) { |
| 690 | if (readl(&usbctlr->susp_ctrl) & USB_PHY_CLK_VALID) |
| 691 | break; |
| 692 | udelay(1); |
| 693 | } |
| 694 | if (!loop_count) |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 695 | return -ETIMEDOUT; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 696 | clrbits_le32(&usbctlr->susp_ctrl, USB_SUSP_CLR); |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | #else |
Stephen Warren | 8b263f9 | 2014-04-30 15:09:57 -0600 | [diff] [blame] | 701 | static int init_ulpi_usb_controller(struct fdt_usb *config, |
| 702 | enum usb_init_type init) |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 703 | { |
| 704 | printf("No code to set up ULPI controller, please enable" |
| 705 | "CONFIG_USB_ULPI and CONFIG_USB_ULPI_VIEWPORT"); |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 706 | return -ENOSYS; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 707 | } |
| 708 | #endif |
| 709 | |
| 710 | static void config_clock(const u32 timing[]) |
| 711 | { |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 712 | debug("%s: DIVM = %d, DIVN = %d, DIVP = %d, cpcon/lfcon = %d/%d\n", |
| 713 | __func__, timing[PARAM_DIVM], timing[PARAM_DIVN], |
| 714 | timing[PARAM_DIVP], timing[PARAM_CPCON], timing[PARAM_LFCON]); |
| 715 | |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 716 | clock_start_pll(CLOCK_ID_USB, |
| 717 | timing[PARAM_DIVM], timing[PARAM_DIVN], timing[PARAM_DIVP], |
| 718 | timing[PARAM_CPCON], timing[PARAM_LFCON]); |
| 719 | } |
| 720 | |
Simon Glass | 0971778 | 2015-08-11 08:33:29 -0600 | [diff] [blame] | 721 | static int fdt_decode_usb(struct udevice *dev, struct fdt_usb *config) |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 722 | { |
| 723 | const char *phy, *mode; |
| 724 | |
Johan Jonker | 8d5d8e0 | 2023-03-13 01:32:04 +0100 | [diff] [blame] | 725 | config->reg = dev_read_addr_ptr(dev); |
Simon Glass | 4c36be0 | 2017-07-25 08:30:04 -0600 | [diff] [blame] | 726 | debug("reg=%p\n", config->reg); |
| 727 | mode = dev_read_string(dev, "dr_mode"); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 728 | if (mode) { |
| 729 | if (0 == strcmp(mode, "host")) |
| 730 | config->dr_mode = DR_MODE_HOST; |
| 731 | else if (0 == strcmp(mode, "peripheral")) |
| 732 | config->dr_mode = DR_MODE_DEVICE; |
| 733 | else if (0 == strcmp(mode, "otg")) |
| 734 | config->dr_mode = DR_MODE_OTG; |
| 735 | else { |
| 736 | debug("%s: Cannot decode dr_mode '%s'\n", __func__, |
| 737 | mode); |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 738 | return -EINVAL; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 739 | } |
| 740 | } else { |
| 741 | config->dr_mode = DR_MODE_HOST; |
| 742 | } |
| 743 | |
Simon Glass | 4c36be0 | 2017-07-25 08:30:04 -0600 | [diff] [blame] | 744 | phy = dev_read_string(dev, "phy_type"); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 745 | config->utmi = phy && 0 == strcmp("utmi", phy); |
| 746 | config->ulpi = phy && 0 == strcmp("ulpi", phy); |
Simon Glass | 4c36be0 | 2017-07-25 08:30:04 -0600 | [diff] [blame] | 747 | config->has_legacy_mode = dev_read_bool(dev, "nvidia,has-legacy-mode"); |
Simon Glass | c3f2650 | 2017-07-25 08:30:00 -0600 | [diff] [blame] | 748 | config->periph_id = clock_decode_periph_id(dev); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 749 | if (config->periph_id == PERIPH_ID_NONE) { |
| 750 | debug("%s: Missing/invalid peripheral ID\n", __func__); |
Simon Glass | 6f7d342 | 2015-03-25 12:22:46 -0600 | [diff] [blame] | 751 | return -EINVAL; |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 752 | } |
Simon Glass | 4c36be0 | 2017-07-25 08:30:04 -0600 | [diff] [blame] | 753 | gpio_request_by_name(dev, "nvidia,vbus-gpio", 0, &config->vbus_gpio, |
| 754 | GPIOD_IS_OUT); |
| 755 | gpio_request_by_name(dev, "nvidia,phy-reset-gpio", 0, |
| 756 | &config->phy_reset_gpio, GPIOD_IS_OUT); |
| 757 | debug("legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, vbus=%d, phy_reset=%d, dr_mode=%d, reg=%p\n", |
| 758 | config->has_legacy_mode, config->utmi, config->ulpi, |
| 759 | config->periph_id, gpio_get_number(&config->vbus_gpio), |
| 760 | gpio_get_number(&config->phy_reset_gpio), config->dr_mode, |
| 761 | config->reg); |
Lucas Stach | 26c3216 | 2013-02-07 07:16:29 +0000 | [diff] [blame] | 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
Simon Glass | 2bd08a9 | 2015-03-25 12:22:47 -0600 | [diff] [blame] | 766 | int usb_common_init(struct fdt_usb *config, enum usb_init_type init) |
| 767 | { |
| 768 | int ret = 0; |
| 769 | |
| 770 | switch (init) { |
| 771 | case USB_INIT_HOST: |
| 772 | switch (config->dr_mode) { |
| 773 | case DR_MODE_HOST: |
| 774 | case DR_MODE_OTG: |
| 775 | break; |
| 776 | default: |
| 777 | printf("tegrausb: Invalid dr_mode %d for host mode\n", |
| 778 | config->dr_mode); |
| 779 | return -1; |
| 780 | } |
| 781 | break; |
| 782 | case USB_INIT_DEVICE: |
| 783 | if (config->periph_id != PERIPH_ID_USBD) { |
| 784 | printf("tegrausb: Device mode only supported on first USB controller\n"); |
| 785 | return -1; |
| 786 | } |
| 787 | if (!config->utmi) { |
| 788 | printf("tegrausb: Device mode only supported with UTMI PHY\n"); |
| 789 | return -1; |
| 790 | } |
| 791 | switch (config->dr_mode) { |
| 792 | case DR_MODE_DEVICE: |
| 793 | case DR_MODE_OTG: |
| 794 | break; |
| 795 | default: |
| 796 | printf("tegrausb: Invalid dr_mode %d for device mode\n", |
| 797 | config->dr_mode); |
| 798 | return -1; |
| 799 | } |
| 800 | break; |
| 801 | default: |
| 802 | printf("tegrausb: Unknown USB_INIT_* %d\n", init); |
| 803 | return -1; |
| 804 | } |
| 805 | |
Simon Glass | 2bd08a9 | 2015-03-25 12:22:47 -0600 | [diff] [blame] | 806 | debug("%d, %d\n", config->utmi, config->ulpi); |
| 807 | if (config->utmi) |
| 808 | ret = init_utmi_usb_controller(config, init); |
| 809 | else if (config->ulpi) |
| 810 | ret = init_ulpi_usb_controller(config, init); |
| 811 | if (ret) |
| 812 | return ret; |
| 813 | |
| 814 | set_up_vbus(config, init); |
| 815 | |
| 816 | config->init_type = init; |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | void usb_common_uninit(struct fdt_usb *priv) |
| 822 | { |
| 823 | struct usb_ctlr *usbctlr; |
| 824 | |
| 825 | usbctlr = priv->reg; |
| 826 | |
| 827 | /* Stop controller */ |
| 828 | writel(0, &usbctlr->usb_cmd); |
| 829 | udelay(1000); |
| 830 | |
| 831 | /* Initiate controller reset */ |
| 832 | writel(2, &usbctlr->usb_cmd); |
| 833 | udelay(1000); |
| 834 | } |
| 835 | |
Simon Glass | dc9f3ed | 2015-03-25 12:22:27 -0600 | [diff] [blame] | 836 | static const struct ehci_ops tegra_ehci_ops = { |
| 837 | .set_usb_mode = tegra_ehci_set_usbmode, |
| 838 | .get_port_speed = tegra_ehci_get_port_speed, |
| 839 | .powerup_fixup = tegra_ehci_powerup_fixup, |
| 840 | }; |
| 841 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 842 | static int ehci_usb_of_to_plat(struct udevice *dev) |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 843 | { |
| 844 | struct fdt_usb *priv = dev_get_priv(dev); |
| 845 | int ret; |
| 846 | |
Simon Glass | 0971778 | 2015-08-11 08:33:29 -0600 | [diff] [blame] | 847 | ret = fdt_decode_usb(dev, priv); |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 848 | if (ret) |
| 849 | return ret; |
| 850 | |
| 851 | priv->type = dev_get_driver_data(dev); |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | static int ehci_usb_probe(struct udevice *dev) |
| 857 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 858 | struct usb_plat *plat = dev_get_plat(dev); |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 859 | struct fdt_usb *priv = dev_get_priv(dev); |
| 860 | struct ehci_hccr *hccr; |
| 861 | struct ehci_hcor *hcor; |
| 862 | static bool clk_done; |
| 863 | int ret; |
| 864 | |
| 865 | ret = usb_common_init(priv, plat->init_type); |
| 866 | if (ret) |
| 867 | return ret; |
| 868 | hccr = (struct ehci_hccr *)&priv->reg->cap_length; |
| 869 | hcor = (struct ehci_hcor *)&priv->reg->usb_cmd; |
| 870 | if (!clk_done) { |
| 871 | config_clock(get_pll_timing(&fdt_usb_controllers[priv->type])); |
| 872 | clk_done = true; |
| 873 | } |
| 874 | |
| 875 | return ehci_register(dev, hccr, hcor, &tegra_ehci_ops, 0, |
| 876 | plat->init_type); |
| 877 | } |
| 878 | |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 879 | static const struct udevice_id ehci_usb_ids[] = { |
| 880 | { .compatible = "nvidia,tegra20-ehci", .data = USB_CTLR_T20 }, |
| 881 | { .compatible = "nvidia,tegra30-ehci", .data = USB_CTLR_T30 }, |
| 882 | { .compatible = "nvidia,tegra114-ehci", .data = USB_CTLR_T114 }, |
Tom Warren | ab0cc6b | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 883 | { .compatible = "nvidia,tegra210-ehci", .data = USB_CTLR_T210 }, |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 884 | { } |
| 885 | }; |
| 886 | |
| 887 | U_BOOT_DRIVER(usb_ehci) = { |
| 888 | .name = "ehci_tegra", |
| 889 | .id = UCLASS_USB, |
| 890 | .of_match = ehci_usb_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 891 | .of_to_plat = ehci_usb_of_to_plat, |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 892 | .probe = ehci_usb_probe, |
Masahiro Yamada | d41919b | 2016-09-06 22:17:34 +0900 | [diff] [blame] | 893 | .remove = ehci_deregister, |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 894 | .ops = &ehci_usb_ops, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 895 | .plat_auto = sizeof(struct usb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 896 | .priv_auto = sizeof(struct fdt_usb), |
Simon Glass | 9c57477 | 2015-03-25 12:22:48 -0600 | [diff] [blame] | 897 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 898 | }; |