Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Allwinner SUNXI "glue layer" |
| 4 | * |
| 5 | * Copyright © 2015 Hans de Goede <hdegoede@redhat.com> |
| 6 | * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi> |
| 7 | * |
| 8 | * Based on the sw_usb "Allwinner OTG Dual Role Controller" code. |
| 9 | * Copyright 2007-2012 (C) Allwinner Technology Co., Ltd. |
| 10 | * javen <javen@allwinnertech.com> |
| 11 | * |
| 12 | * Based on the DA8xx "glue layer" code. |
| 13 | * Copyright (c) 2008-2009 MontaVista Software, Inc. <source@mvista.com> |
| 14 | * Copyright (C) 2005-2006 by Texas Instruments |
| 15 | * |
| 16 | * This file is part of the Inventra Controller Driver for Linux. |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 17 | */ |
| 18 | #include <common.h> |
Simon Glass | 9d92245 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 19 | #include <dm.h> |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 20 | #include <asm/arch/cpu.h> |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 21 | #include <asm/arch/clock.h> |
Hans de Goede | 52defe8 | 2015-02-16 22:13:43 +0100 | [diff] [blame] | 22 | #include <asm/arch/gpio.h> |
Hans de Goede | 2aacc42 | 2015-04-27 15:05:10 +0200 | [diff] [blame] | 23 | #include <asm/arch/usb_phy.h> |
Hans de Goede | 52defe8 | 2015-02-16 22:13:43 +0100 | [diff] [blame] | 24 | #include <asm-generic/gpio.h> |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 25 | #include <dm/lists.h> |
| 26 | #include <dm/root.h> |
Hans de Goede | d42faf3 | 2015-06-17 15:49:26 +0200 | [diff] [blame] | 27 | #include <linux/usb/musb.h> |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 28 | #include "linux-compat.h" |
| 29 | #include "musb_core.h" |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 30 | #include "musb_uboot.h" |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 31 | |
| 32 | /****************************************************************************** |
| 33 | ****************************************************************************** |
| 34 | * From the Allwinner driver |
| 35 | ****************************************************************************** |
| 36 | ******************************************************************************/ |
| 37 | |
| 38 | /****************************************************************************** |
| 39 | * From include/sunxi_usb_bsp.h |
| 40 | ******************************************************************************/ |
| 41 | |
| 42 | /* reg offsets */ |
| 43 | #define USBC_REG_o_ISCR 0x0400 |
| 44 | #define USBC_REG_o_PHYCTL 0x0404 |
| 45 | #define USBC_REG_o_PHYBIST 0x0408 |
| 46 | #define USBC_REG_o_PHYTUNE 0x040c |
| 47 | |
| 48 | #define USBC_REG_o_VEND0 0x0043 |
| 49 | |
| 50 | /* Interface Status and Control */ |
| 51 | #define USBC_BP_ISCR_VBUS_VALID_FROM_DATA 30 |
| 52 | #define USBC_BP_ISCR_VBUS_VALID_FROM_VBUS 29 |
| 53 | #define USBC_BP_ISCR_EXT_ID_STATUS 28 |
| 54 | #define USBC_BP_ISCR_EXT_DM_STATUS 27 |
| 55 | #define USBC_BP_ISCR_EXT_DP_STATUS 26 |
| 56 | #define USBC_BP_ISCR_MERGED_VBUS_STATUS 25 |
| 57 | #define USBC_BP_ISCR_MERGED_ID_STATUS 24 |
| 58 | |
| 59 | #define USBC_BP_ISCR_ID_PULLUP_EN 17 |
| 60 | #define USBC_BP_ISCR_DPDM_PULLUP_EN 16 |
| 61 | #define USBC_BP_ISCR_FORCE_ID 14 |
| 62 | #define USBC_BP_ISCR_FORCE_VBUS_VALID 12 |
| 63 | #define USBC_BP_ISCR_VBUS_VALID_SRC 10 |
| 64 | |
| 65 | #define USBC_BP_ISCR_HOSC_EN 7 |
| 66 | #define USBC_BP_ISCR_VBUS_CHANGE_DETECT 6 |
| 67 | #define USBC_BP_ISCR_ID_CHANGE_DETECT 5 |
| 68 | #define USBC_BP_ISCR_DPDM_CHANGE_DETECT 4 |
| 69 | #define USBC_BP_ISCR_IRQ_ENABLE 3 |
| 70 | #define USBC_BP_ISCR_VBUS_CHANGE_DETECT_EN 2 |
| 71 | #define USBC_BP_ISCR_ID_CHANGE_DETECT_EN 1 |
| 72 | #define USBC_BP_ISCR_DPDM_CHANGE_DETECT_EN 0 |
| 73 | |
| 74 | /****************************************************************************** |
| 75 | * From usbc/usbc.c |
| 76 | ******************************************************************************/ |
| 77 | |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 78 | struct sunxi_glue { |
| 79 | struct musb_host_data mdata; |
| 80 | struct sunxi_ccm_reg *ccm; |
| 81 | struct device dev; |
| 82 | }; |
| 83 | #define to_sunxi_glue(d) container_of(d, struct sunxi_glue, dev) |
| 84 | |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 85 | static u32 USBC_WakeUp_ClearChangeDetect(u32 reg_val) |
| 86 | { |
| 87 | u32 temp = reg_val; |
| 88 | |
| 89 | temp &= ~(1 << USBC_BP_ISCR_VBUS_CHANGE_DETECT); |
| 90 | temp &= ~(1 << USBC_BP_ISCR_ID_CHANGE_DETECT); |
| 91 | temp &= ~(1 << USBC_BP_ISCR_DPDM_CHANGE_DETECT); |
| 92 | |
| 93 | return temp; |
| 94 | } |
| 95 | |
| 96 | static void USBC_EnableIdPullUp(__iomem void *base) |
| 97 | { |
| 98 | u32 reg_val; |
| 99 | |
| 100 | reg_val = musb_readl(base, USBC_REG_o_ISCR); |
| 101 | reg_val |= (1 << USBC_BP_ISCR_ID_PULLUP_EN); |
| 102 | reg_val = USBC_WakeUp_ClearChangeDetect(reg_val); |
| 103 | musb_writel(base, USBC_REG_o_ISCR, reg_val); |
| 104 | } |
| 105 | |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 106 | static void USBC_EnableDpDmPullUp(__iomem void *base) |
| 107 | { |
| 108 | u32 reg_val; |
| 109 | |
| 110 | reg_val = musb_readl(base, USBC_REG_o_ISCR); |
| 111 | reg_val |= (1 << USBC_BP_ISCR_DPDM_PULLUP_EN); |
| 112 | reg_val = USBC_WakeUp_ClearChangeDetect(reg_val); |
| 113 | musb_writel(base, USBC_REG_o_ISCR, reg_val); |
| 114 | } |
| 115 | |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 116 | static void USBC_ForceIdToLow(__iomem void *base) |
| 117 | { |
| 118 | u32 reg_val; |
| 119 | |
| 120 | reg_val = musb_readl(base, USBC_REG_o_ISCR); |
| 121 | reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_ID); |
| 122 | reg_val |= (0x02 << USBC_BP_ISCR_FORCE_ID); |
| 123 | reg_val = USBC_WakeUp_ClearChangeDetect(reg_val); |
| 124 | musb_writel(base, USBC_REG_o_ISCR, reg_val); |
| 125 | } |
| 126 | |
| 127 | static void USBC_ForceIdToHigh(__iomem void *base) |
| 128 | { |
| 129 | u32 reg_val; |
| 130 | |
| 131 | reg_val = musb_readl(base, USBC_REG_o_ISCR); |
| 132 | reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_ID); |
| 133 | reg_val |= (0x03 << USBC_BP_ISCR_FORCE_ID); |
| 134 | reg_val = USBC_WakeUp_ClearChangeDetect(reg_val); |
| 135 | musb_writel(base, USBC_REG_o_ISCR, reg_val); |
| 136 | } |
| 137 | |
Hans de Goede | e1abfa4 | 2015-06-14 11:55:28 +0200 | [diff] [blame] | 138 | static void USBC_ForceVbusValidToLow(__iomem void *base) |
| 139 | { |
| 140 | u32 reg_val; |
| 141 | |
| 142 | reg_val = musb_readl(base, USBC_REG_o_ISCR); |
| 143 | reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_VBUS_VALID); |
| 144 | reg_val |= (0x02 << USBC_BP_ISCR_FORCE_VBUS_VALID); |
| 145 | reg_val = USBC_WakeUp_ClearChangeDetect(reg_val); |
| 146 | musb_writel(base, USBC_REG_o_ISCR, reg_val); |
| 147 | } |
| 148 | |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 149 | static void USBC_ForceVbusValidToHigh(__iomem void *base) |
| 150 | { |
| 151 | u32 reg_val; |
| 152 | |
| 153 | reg_val = musb_readl(base, USBC_REG_o_ISCR); |
| 154 | reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_VBUS_VALID); |
| 155 | reg_val |= (0x03 << USBC_BP_ISCR_FORCE_VBUS_VALID); |
| 156 | reg_val = USBC_WakeUp_ClearChangeDetect(reg_val); |
| 157 | musb_writel(base, USBC_REG_o_ISCR, reg_val); |
| 158 | } |
| 159 | |
| 160 | static void USBC_ConfigFIFO_Base(void) |
| 161 | { |
| 162 | u32 reg_value; |
| 163 | |
| 164 | /* config usb fifo, 8kb mode */ |
| 165 | reg_value = readl(SUNXI_SRAMC_BASE + 0x04); |
| 166 | reg_value &= ~(0x03 << 0); |
| 167 | reg_value |= (1 << 0); |
| 168 | writel(reg_value, SUNXI_SRAMC_BASE + 0x04); |
| 169 | } |
| 170 | |
| 171 | /****************************************************************************** |
Siarhei Siamashka | 6047a3a | 2015-10-25 06:44:47 +0200 | [diff] [blame] | 172 | * Needed for the DFU polling magic |
| 173 | ******************************************************************************/ |
| 174 | |
| 175 | static u8 last_int_usb; |
| 176 | |
| 177 | bool dfu_usb_get_reset(void) |
| 178 | { |
| 179 | return !!(last_int_usb & MUSB_INTR_RESET); |
| 180 | } |
| 181 | |
| 182 | /****************************************************************************** |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 183 | * MUSB Glue code |
| 184 | ******************************************************************************/ |
| 185 | |
| 186 | static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci) |
| 187 | { |
| 188 | struct musb *musb = __hci; |
| 189 | irqreturn_t retval = IRQ_NONE; |
| 190 | |
| 191 | /* read and flush interrupts */ |
| 192 | musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); |
Siarhei Siamashka | 6047a3a | 2015-10-25 06:44:47 +0200 | [diff] [blame] | 193 | last_int_usb = musb->int_usb; |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 194 | if (musb->int_usb) |
| 195 | musb_writeb(musb->mregs, MUSB_INTRUSB, musb->int_usb); |
| 196 | musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); |
| 197 | if (musb->int_tx) |
| 198 | musb_writew(musb->mregs, MUSB_INTRTX, musb->int_tx); |
| 199 | musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); |
| 200 | if (musb->int_rx) |
| 201 | musb_writew(musb->mregs, MUSB_INTRRX, musb->int_rx); |
| 202 | |
| 203 | if (musb->int_usb || musb->int_tx || musb->int_rx) |
| 204 | retval |= musb_interrupt(musb); |
| 205 | |
| 206 | return retval; |
| 207 | } |
| 208 | |
Hans de Goede | e1abfa4 | 2015-06-14 11:55:28 +0200 | [diff] [blame] | 209 | /* musb_core does not call enable / disable in a balanced manner <sigh> */ |
| 210 | static bool enabled = false; |
| 211 | |
Hans de Goede | 1583723 | 2015-06-17 21:33:54 +0200 | [diff] [blame] | 212 | static int sunxi_musb_enable(struct musb *musb) |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 213 | { |
Chen-Yu Tsai | 57075a4 | 2016-09-07 14:25:21 +0800 | [diff] [blame] | 214 | int ret; |
| 215 | |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 216 | pr_debug("%s():\n", __func__); |
| 217 | |
Maxime Ripard | 1feda63 | 2015-08-04 17:04:10 +0200 | [diff] [blame] | 218 | musb_ep_select(musb->mregs, 0); |
| 219 | musb_writeb(musb->mregs, MUSB_FADDR, 0); |
| 220 | |
Hans de Goede | e1abfa4 | 2015-06-14 11:55:28 +0200 | [diff] [blame] | 221 | if (enabled) |
Hans de Goede | 1583723 | 2015-06-17 21:33:54 +0200 | [diff] [blame] | 222 | return 0; |
Hans de Goede | e1abfa4 | 2015-06-14 11:55:28 +0200 | [diff] [blame] | 223 | |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 224 | /* select PIO mode */ |
| 225 | musb_writeb(musb->mregs, USBC_REG_o_VEND0, 0); |
| 226 | |
Hans de Goede | b41972e | 2015-06-14 16:48:56 +0200 | [diff] [blame] | 227 | if (is_host_enabled(musb)) { |
Chen-Yu Tsai | 57075a4 | 2016-09-07 14:25:21 +0800 | [diff] [blame] | 228 | ret = sunxi_usb_phy_vbus_detect(0); |
| 229 | if (ret == 1) { |
| 230 | printf("A charger is plugged into the OTG: "); |
| 231 | return -ENODEV; |
Hans de Goede | b41972e | 2015-06-14 16:48:56 +0200 | [diff] [blame] | 232 | } |
Chen-Yu Tsai | 57075a4 | 2016-09-07 14:25:21 +0800 | [diff] [blame] | 233 | ret = sunxi_usb_phy_id_detect(0); |
| 234 | if (ret == 1) { |
Hans de Goede | 71cbe0d | 2015-06-14 17:40:37 +0200 | [diff] [blame] | 235 | printf("No host cable detected: "); |
| 236 | return -ENODEV; |
| 237 | } |
Chen-Yu Tsai | 57075a4 | 2016-09-07 14:25:21 +0800 | [diff] [blame] | 238 | sunxi_usb_phy_power_on(0); /* port power on */ |
Hans de Goede | b41972e | 2015-06-14 16:48:56 +0200 | [diff] [blame] | 239 | } |
Hans de Goede | e1abfa4 | 2015-06-14 11:55:28 +0200 | [diff] [blame] | 240 | |
| 241 | USBC_ForceVbusValidToHigh(musb->mregs); |
| 242 | |
| 243 | enabled = true; |
Hans de Goede | 1583723 | 2015-06-17 21:33:54 +0200 | [diff] [blame] | 244 | return 0; |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void sunxi_musb_disable(struct musb *musb) |
| 248 | { |
| 249 | pr_debug("%s():\n", __func__); |
| 250 | |
Hans de Goede | e1abfa4 | 2015-06-14 11:55:28 +0200 | [diff] [blame] | 251 | if (!enabled) |
| 252 | return; |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 253 | |
Chen-Yu Tsai | 57075a4 | 2016-09-07 14:25:21 +0800 | [diff] [blame] | 254 | if (is_host_enabled(musb)) |
| 255 | sunxi_usb_phy_power_off(0); /* port power off */ |
| 256 | |
Hans de Goede | e1abfa4 | 2015-06-14 11:55:28 +0200 | [diff] [blame] | 257 | USBC_ForceVbusValidToLow(musb->mregs); |
| 258 | mdelay(200); /* Wait for the current session to timeout */ |
| 259 | |
| 260 | enabled = false; |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static int sunxi_musb_init(struct musb *musb) |
| 264 | { |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 265 | struct sunxi_glue *glue = to_sunxi_glue(musb->controller); |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 266 | |
| 267 | pr_debug("%s():\n", __func__); |
| 268 | |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 269 | musb->isr = sunxi_musb_interrupt; |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 270 | |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 271 | setbits_le32(&glue->ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0); |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 272 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 273 | setbits_le32(&glue->ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0); |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 274 | #endif |
Hans de Goede | 7b79865 | 2015-04-27 14:54:47 +0200 | [diff] [blame] | 275 | sunxi_usb_phy_init(0); |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 276 | |
| 277 | USBC_ConfigFIFO_Base(); |
| 278 | USBC_EnableDpDmPullUp(musb->mregs); |
| 279 | USBC_EnableIdPullUp(musb->mregs); |
| 280 | |
| 281 | if (is_host_enabled(musb)) { |
| 282 | /* Host mode */ |
| 283 | USBC_ForceIdToLow(musb->mregs); |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 284 | } else { |
| 285 | /* Peripheral mode */ |
| 286 | USBC_ForceIdToHigh(musb->mregs); |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 287 | } |
Hans de Goede | b1b912d | 2015-02-11 09:05:18 +0100 | [diff] [blame] | 288 | USBC_ForceVbusValidToHigh(musb->mregs); |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Hans de Goede | d42faf3 | 2015-06-17 15:49:26 +0200 | [diff] [blame] | 293 | static const struct musb_platform_ops sunxi_musb_ops = { |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 294 | .init = sunxi_musb_init, |
Hans de Goede | 28a15ef | 2015-01-11 20:34:48 +0100 | [diff] [blame] | 295 | .enable = sunxi_musb_enable, |
| 296 | .disable = sunxi_musb_disable, |
| 297 | }; |
Hans de Goede | d42faf3 | 2015-06-17 15:49:26 +0200 | [diff] [blame] | 298 | |
| 299 | static struct musb_hdrc_config musb_config = { |
| 300 | .multipoint = 1, |
| 301 | .dyn_fifo = 1, |
| 302 | .num_eps = 6, |
| 303 | .ram_bits = 11, |
| 304 | }; |
| 305 | |
| 306 | static struct musb_hdrc_platform_data musb_plat = { |
Paul Kocialkowski | 95de1e2 | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 307 | #if defined(CONFIG_USB_MUSB_HOST) |
Hans de Goede | d42faf3 | 2015-06-17 15:49:26 +0200 | [diff] [blame] | 308 | .mode = MUSB_HOST, |
| 309 | #else |
| 310 | .mode = MUSB_PERIPHERAL, |
| 311 | #endif |
| 312 | .config = &musb_config, |
| 313 | .power = 250, |
| 314 | .platform_ops = &sunxi_musb_ops, |
| 315 | }; |
| 316 | |
Hans de Goede | 7c22e26 | 2016-09-17 16:02:38 +0200 | [diff] [blame] | 317 | static int musb_usb_probe(struct udevice *dev) |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 318 | { |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 319 | struct sunxi_glue *glue = dev_get_priv(dev); |
| 320 | struct musb_host_data *host = &glue->mdata; |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 321 | struct usb_bus_priv *priv = dev_get_uclass_priv(dev); |
Chen-Yu Tsai | f4f9896 | 2017-12-30 20:44:07 +0800 | [diff] [blame] | 322 | void *base = dev_read_addr_ptr(dev); |
Hans de Goede | 56a2085 | 2015-06-18 22:45:34 +0200 | [diff] [blame] | 323 | int ret; |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 324 | |
Chen-Yu Tsai | f4f9896 | 2017-12-30 20:44:07 +0800 | [diff] [blame] | 325 | if (!base) |
| 326 | return -EINVAL; |
| 327 | |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 328 | glue->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 329 | if (IS_ERR(glue->ccm)) |
| 330 | return PTR_ERR(glue->ccm); |
| 331 | |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 332 | priv->desc_before_addr = true; |
| 333 | |
Maxime Ripard | 3a61b08 | 2017-09-05 22:10:35 +0200 | [diff] [blame] | 334 | #ifdef CONFIG_USB_MUSB_HOST |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 335 | host->host = musb_init_controller(&musb_plat, &glue->dev, base); |
Hans de Goede | 38b4a3e | 2016-04-02 20:46:09 +0200 | [diff] [blame] | 336 | if (!host->host) |
| 337 | return -EIO; |
| 338 | |
Hans de Goede | 56a2085 | 2015-06-18 22:45:34 +0200 | [diff] [blame] | 339 | ret = musb_lowlevel_init(host); |
Maxime Ripard | 3a61b08 | 2017-09-05 22:10:35 +0200 | [diff] [blame] | 340 | if (!ret) |
| 341 | printf("Allwinner mUSB OTG (Host)\n"); |
| 342 | #else |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 343 | ret = musb_register(&musb_plat, &glue->dev, base); |
Maxime Ripard | 3a61b08 | 2017-09-05 22:10:35 +0200 | [diff] [blame] | 344 | if (!ret) |
| 345 | printf("Allwinner mUSB OTG (Peripheral)\n"); |
| 346 | #endif |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 347 | |
Hans de Goede | 56a2085 | 2015-06-18 22:45:34 +0200 | [diff] [blame] | 348 | return ret; |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Hans de Goede | 7c22e26 | 2016-09-17 16:02:38 +0200 | [diff] [blame] | 351 | static int musb_usb_remove(struct udevice *dev) |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 352 | { |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 353 | struct sunxi_glue *glue = dev_get_priv(dev); |
| 354 | struct musb_host_data *host = &glue->mdata; |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 355 | |
| 356 | musb_stop(host->host); |
| 357 | |
Hans de Goede | bca4c3c | 2016-06-05 16:53:04 +0200 | [diff] [blame] | 358 | sunxi_usb_phy_exit(0); |
| 359 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 360 | clrbits_le32(&glue->ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0); |
Hans de Goede | bca4c3c | 2016-06-05 16:53:04 +0200 | [diff] [blame] | 361 | #endif |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 362 | clrbits_le32(&glue->ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0); |
Hans de Goede | bca4c3c | 2016-06-05 16:53:04 +0200 | [diff] [blame] | 363 | |
Hans de Goede | 7c22e26 | 2016-09-17 16:02:38 +0200 | [diff] [blame] | 364 | free(host->host); |
| 365 | host->host = NULL; |
| 366 | |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Maxime Ripard | 3a61b08 | 2017-09-05 22:10:35 +0200 | [diff] [blame] | 370 | static const struct udevice_id sunxi_musb_ids[] = { |
| 371 | { .compatible = "allwinner,sun4i-a10-musb" }, |
| 372 | { .compatible = "allwinner,sun6i-a31-musb" }, |
| 373 | { .compatible = "allwinner,sun8i-a33-musb" }, |
| 374 | { .compatible = "allwinner,sun8i-h3-musb" }, |
| 375 | { } |
| 376 | }; |
| 377 | |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 378 | U_BOOT_DRIVER(usb_musb) = { |
Maxime Ripard | 3a61b08 | 2017-09-05 22:10:35 +0200 | [diff] [blame] | 379 | .name = "sunxi-musb", |
| 380 | #ifdef CONFIG_USB_MUSB_HOST |
| 381 | .id = UCLASS_USB, |
| 382 | #else |
| 383 | .id = UCLASS_USB_DEV_GENERIC, |
| 384 | #endif |
| 385 | .of_match = sunxi_musb_ids, |
| 386 | .probe = musb_usb_probe, |
| 387 | .remove = musb_usb_remove, |
| 388 | #ifdef CONFIG_USB_MUSB_HOST |
| 389 | .ops = &musb_usb_ops, |
| 390 | #endif |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 391 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
Jagan Teki | 831cc98 | 2018-05-07 13:03:17 +0530 | [diff] [blame^] | 392 | .priv_auto_alloc_size = sizeof(struct sunxi_glue), |
Hans de Goede | 91183ba | 2015-06-17 17:44:58 +0200 | [diff] [blame] | 393 | }; |