| 1 |
|
| 2 |
|
| 3 |
#include <device/mmio.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <delay.h> |
| 6 |
#include <device/device.h> |
| 7 |
#include <soc/gpio.h> |
| 8 |
#include <soc/power.h> |
| 9 |
#include <soc/sysreg.h> |
| 10 |
#include <soc/usb.h> |
| 11 |
|
| 12 |
static void reset_dwc3(struct exynos5_usb_drd_dwc3 *dwc3) |
| 13 |
{ |
| 14 |
setbits32(&dwc3->ctl, 0x1 << 11); |
| 15 |
setbits32(&dwc3->usb3pipectl, 0x1 << 31); |
| 16 |
setbits32(&dwc3->usb2phycfg, 0x1 << 31); |
| 17 |
} |
| 18 |
|
| 19 |
void reset_usb_drd_dwc3(void) |
| 20 |
{ |
| 21 |
printk(BIOS_DEBUG, "Starting DWC3 reset for USB DRD\n"); |
| 22 |
reset_dwc3(exynos_usb_drd_dwc3); |
| 23 |
} |
| 24 |
|
| 25 |
static void setup_dwc3(struct exynos5_usb_drd_dwc3 *dwc3) |
| 26 |
{ |
| 27 |
if (!(dwc3->ctl & 0x1 << 11) || |
| 28 |
!(dwc3->usb3pipectl & 0x1 << 31) || |
| 29 |
!(dwc3->usb2phycfg & 0x1 << 31)) { |
| 30 |
printk(BIOS_ERR, "DWC3 at %p not in reset (you need to call " |
| 31 |
"reset_usb_drd_dwc3() first)!\n", dwc3); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
write32(&dwc3->usb3pipectl, |
| 37 |
0x1 << 24 | |
| 38 |
0x4 << 19 | |
| 39 |
0x1 << 18 | |
| 40 |
0x1 << 17 | |
| 41 |
0x1 << 1); |
| 42 |
|
| 43 |
|
| 44 |
write32(&dwc3->usb2phycfg, |
| 45 |
0x9 << 10 | |
| 46 |
0x1 << 8 | |
| 47 |
0x1 << 6); |
| 48 |
|
| 49 |
write32(&dwc3->ctl, |
| 50 |
0x5dc << 19 | |
| 51 |
0x1 << 16 | |
| 52 |
0x1 << 12); |
| 53 |
} |
| 54 |
|
| 55 |
void setup_usb_drd_dwc3(void) |
| 56 |
{ |
| 57 |
setup_dwc3(exynos_usb_drd_dwc3); |
| 58 |
printk(BIOS_DEBUG, "DWC3 setup for USB DRD finished\n"); |
| 59 |
} |
| 60 |
|
| 61 |
static void setup_drd_phy(struct exynos5_usb_drd_phy *phy) |
| 62 |
{ |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
setbits32(&phy->linksystem, 0x1 << 27 | 0x20 << 1); |
| 67 |
|
| 68 |
|
| 69 |
write32(&phy->utmi, 1 << 6); |
| 70 |
|
| 71 |
write32(&phy->clkrst, |
| 72 |
0x88 << 23 | |
| 73 |
0x1 << 20 | |
| 74 |
0x1 << 19 | |
| 75 |
0x68 << 11 | |
| 76 |
0x5 << 5 | |
| 77 |
0x1 << 4 | |
| 78 |
0x3 << 2 | |
| 79 |
0x1 << 1 | |
| 80 |
0x1 << 0); |
| 81 |
|
| 82 |
write32(&phy->param0, |
| 83 |
0x9 << 26 | |
| 84 |
0x3 << 22 | |
| 85 |
0x1 << 20 | |
| 86 |
0x1 << 18 | |
| 87 |
0x3 << 13 | |
| 88 |
0x3 << 9 | |
| 89 |
0x3 << 6 | |
| 90 |
0x4 << 3 | |
| 91 |
0x4 << 0); |
| 92 |
|
| 93 |
write32(&phy->param1, |
| 94 |
0x7f << 19 | |
| 95 |
0x7f << 12 | |
| 96 |
0x20 << 6 | |
| 97 |
0x1c << 0); |
| 98 |
|
| 99 |
|
| 100 |
write32(&phy->test, 0); |
| 101 |
|
| 102 |
|
| 103 |
write32(&phy->utmiclksel, 0x1 << 2); |
| 104 |
|
| 105 |
|
| 106 |
write32(&phy->resume, 0x0); |
| 107 |
|
| 108 |
udelay(10); |
| 109 |
clrbits32(&phy->clkrst, 0x1 << 1); |
| 110 |
} |
| 111 |
|
| 112 |
void setup_usb_drd_phy(void) |
| 113 |
{ |
| 114 |
printk(BIOS_DEBUG, "Powering up USB DRD PHY\n"); |
| 115 |
setbits32(&exynos_power->usb_drd_phy_ctrl, POWER_USB_PHY_CTRL_EN); |
| 116 |
setup_drd_phy(exynos_usb_drd_phy); |
| 117 |
} |
| 118 |
|
| 119 |
void setup_usb_host_phy(int hsic_gpio) |
| 120 |
{ |
| 121 |
unsigned int hostphy_ctrl0; |
| 122 |
|
| 123 |
setbits32(&exynos_sysreg->usb20_phy_cfg, USB20_PHY_CFG_EN); |
| 124 |
setbits32(&exynos_power->usb_host_phy_ctrl, POWER_USB_PHY_CTRL_EN); |
| 125 |
|
| 126 |
printk(BIOS_DEBUG, "Powering up USB HOST PHY (%s HSIC)\n", |
| 127 |
hsic_gpio ? "with" : "without"); |
| 128 |
|
| 129 |
hostphy_ctrl0 = read32(&exynos_usb_host_phy->usbphyctrl0); |
| 130 |
hostphy_ctrl0 &= ~(HOST_CTRL0_FSEL_MASK | |
| 131 |
HOST_CTRL0_COMMONON_N | |
| 132 |
|
| 133 |
HOST_CTRL0_PHYSWRST | |
| 134 |
HOST_CTRL0_PHYSWRSTALL | |
| 135 |
HOST_CTRL0_SIDDQ | |
| 136 |
HOST_CTRL0_FORCESUSPEND | |
| 137 |
HOST_CTRL0_FORCESLEEP); |
| 138 |
hostphy_ctrl0 |= ( |
| 139 |
CLK_24MHZ << 16 | |
| 140 |
|
| 141 |
HOST_CTRL0_LINKSWRST | |
| 142 |
HOST_CTRL0_UTMISWRST); |
| 143 |
write32(&exynos_usb_host_phy->usbphyctrl0, hostphy_ctrl0); |
| 144 |
udelay(10); |
| 145 |
clrbits32(&exynos_usb_host_phy->usbphyctrl0, |
| 146 |
HOST_CTRL0_LINKSWRST | |
| 147 |
HOST_CTRL0_UTMISWRST); |
| 148 |
udelay(20); |
| 149 |
|
| 150 |
|
| 151 |
setbits32(&exynos_usb_host_phy->ehcictrl, |
| 152 |
EHCICTRL_ENAINCRXALIGN | |
| 153 |
EHCICTRL_ENAINCR4 | |
| 154 |
EHCICTRL_ENAINCR8 | |
| 155 |
EHCICTRL_ENAINCR16); |
| 156 |
|
| 157 |
|
| 158 |
if (hsic_gpio) { |
| 159 |
gpio_direction_output(hsic_gpio, 0); |
| 160 |
udelay(100); |
| 161 |
gpio_direction_output(hsic_gpio, 1); |
| 162 |
udelay(5000); |
| 163 |
|
| 164 |
clrbits32(&exynos_usb_host_phy->hsicphyctrl1, |
| 165 |
HOST_CTRL0_SIDDQ | |
| 166 |
HOST_CTRL0_FORCESLEEP | |
| 167 |
HOST_CTRL0_FORCESUSPEND); |
| 168 |
setbits32(&exynos_usb_host_phy->hsicphyctrl1, |
| 169 |
HOST_CTRL0_PHYSWRST); |
| 170 |
udelay(10); |
| 171 |
clrbits32(&exynos_usb_host_phy->hsicphyctrl1, |
| 172 |
HOST_CTRL0_PHYSWRST); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
} |