1/*- 2 * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: stable/10/sys/arm/samsung/exynos/exynos5_ehci.c 266341 2014-05-17 19:37:04Z ian $"); |
29 30#include "opt_bus.h" 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36#include <sys/bus.h> 37#include <sys/condvar.h> 38#include <sys/rman.h> |
39#include <sys/gpio.h> |
40 41#include <dev/ofw/ofw_bus.h> 42#include <dev/ofw/ofw_bus_subr.h> 43 44#include <dev/usb/usb.h> 45#include <dev/usb/usbdi.h> 46#include <dev/usb/usb_busdma.h> 47#include <dev/usb/usb_process.h> 48#include <dev/usb/usb_controller.h> 49#include <dev/usb/usb_bus.h> 50#include <dev/usb/controller/ehci.h> 51#include <dev/usb/controller/ehcireg.h> 52 53#include <dev/fdt/fdt_common.h> 54 55#include <machine/bus.h> 56#include <machine/resource.h> 57 |
58#include "gpio_if.h" 59 |
60#include "opt_platform.h" 61 62/* GPIO control */ |
63#define GPIO_OUTPUT 1 64#define GPIO_INPUT 0 |
65#define PIN_USB 161 |
66 67/* PWR control */ 68#define EXYNOS5_PWR_USBHOST_PHY 0x708 69#define PHY_POWER_ON 1 70#define PHY_POWER_OFF 0 71 72/* SYSREG */ 73#define EXYNOS5_SYSREG_USB2_PHY 0x0 --- 10 unchanged lines hidden (view full) --- 84#define HOST_CTRL_RESET_PHY_ALL (1U << 31) 85 86/* Forward declarations */ 87static int exynos_ehci_attach(device_t dev); 88static int exynos_ehci_detach(device_t dev); 89static int exynos_ehci_probe(device_t dev); 90 91struct exynos_ehci_softc { |
92 device_t dev; |
93 ehci_softc_t base; |
94 struct resource *res[5]; |
95 bus_space_tag_t host_bst; 96 bus_space_tag_t pwr_bst; 97 bus_space_tag_t sysreg_bst; |
98 bus_space_handle_t host_bsh; 99 bus_space_handle_t pwr_bsh; 100 bus_space_handle_t sysreg_bsh; |
101 102}; 103 104static struct resource_spec exynos_ehci_spec[] = { 105 { SYS_RES_MEMORY, 0, RF_ACTIVE }, 106 { SYS_RES_MEMORY, 1, RF_ACTIVE }, 107 { SYS_RES_MEMORY, 2, RF_ACTIVE }, 108 { SYS_RES_MEMORY, 3, RF_ACTIVE }, |
109 { SYS_RES_IRQ, 0, RF_ACTIVE }, 110 { -1, 0 } 111}; 112 113static device_method_t ehci_methods[] = { 114 /* Device interface */ 115 DEVMETHOD(device_probe, exynos_ehci_probe), 116 DEVMETHOD(device_attach, exynos_ehci_attach), --- 35 unchanged lines hidden (view full) --- 152 153 device_set_desc(dev, "Exynos integrated USB controller"); 154 return (BUS_PROBE_DEFAULT); 155} 156 157static int 158gpio_ctrl(struct exynos_ehci_softc *esc, int dir, int power) 159{ |
160 device_t gpio_dev; |
161 |
162 /* Get the GPIO device, we need this to give power to USB */ 163 gpio_dev = devclass_get_device(devclass_find("gpio"), 0); 164 if (gpio_dev == NULL) { 165 device_printf(esc->dev, "cant find gpio_dev\n"); 166 return (1); 167 } |
168 |
169 if (power) 170 GPIO_PIN_SET(gpio_dev, PIN_USB, GPIO_PIN_HIGH); 171 else 172 GPIO_PIN_SET(gpio_dev, PIN_USB, GPIO_PIN_LOW); |
173 |
174 if (dir) 175 GPIO_PIN_SETFLAGS(gpio_dev, PIN_USB, GPIO_PIN_OUTPUT); 176 else 177 GPIO_PIN_SETFLAGS(gpio_dev, PIN_USB, GPIO_PIN_INPUT); 178 |
179 return (0); 180} 181 182static int 183phy_init(struct exynos_ehci_softc *esc) 184{ 185 int reg; 186 --- 34 unchanged lines hidden (view full) --- 221exynos_ehci_attach(device_t dev) 222{ 223 struct exynos_ehci_softc *esc; 224 ehci_softc_t *sc; 225 bus_space_handle_t bsh; 226 int err; 227 228 esc = device_get_softc(dev); |
229 esc->dev = dev; |
230 sc = &esc->base; 231 sc->sc_bus.parent = dev; 232 sc->sc_bus.devices = sc->sc_devices; 233 sc->sc_bus.devices_max = EHCI_MAX_DEVICES; 234 235 if (bus_alloc_resources(dev, exynos_ehci_spec, esc->res)) { 236 device_printf(dev, "could not allocate resources\n"); 237 return (ENXIO); --- 11 unchanged lines hidden (view full) --- 249 /* PWR registers */ 250 esc->pwr_bst = rman_get_bustag(esc->res[2]); 251 esc->pwr_bsh = rman_get_bushandle(esc->res[2]); 252 253 /* SYSREG */ 254 esc->sysreg_bst = rman_get_bustag(esc->res[3]); 255 esc->sysreg_bsh = rman_get_bushandle(esc->res[3]); 256 |
257 /* get all DMA memory */ 258 if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(dev), 259 &ehci_iterate_hw_softc)) 260 return (ENXIO); 261 262 /* 263 * Set handle to USB related registers subregion used by 264 * generic EHCI driver. 265 */ 266 err = bus_space_subregion(sc->sc_io_tag, bsh, 0x0, 267 sc->sc_io_size, &sc->sc_io_hdl); 268 if (err != 0) 269 return (ENXIO); 270 271 phy_init(esc); 272 273 /* Setup interrupt handler */ |
274 err = bus_setup_intr(dev, esc->res[4], INTR_TYPE_BIO | INTR_MPSAFE, |
275 NULL, (driver_intr_t *)ehci_interrupt, sc, 276 &sc->sc_intr_hdl); 277 if (err) { 278 device_printf(dev, "Could not setup irq, " 279 "%d\n", err); 280 return (1); 281 } 282 283 /* Add USB device */ 284 sc->sc_bus.bdev = device_add_child(dev, "usbus", -1); 285 if (!sc->sc_bus.bdev) { 286 device_printf(dev, "Could not add USB device\n"); |
287 err = bus_teardown_intr(dev, esc->res[4], |
288 sc->sc_intr_hdl); 289 if (err) 290 device_printf(dev, "Could not tear down irq," 291 " %d\n", err); 292 return (1); 293 } 294 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); 295 --- 4 unchanged lines hidden (view full) --- 300 sc->sc_flags |= EHCI_SCFLG_DONEINIT; 301 err = device_probe_and_attach(sc->sc_bus.bdev); 302 } else { 303 device_printf(dev, "USB init failed err=%d\n", err); 304 305 device_delete_child(dev, sc->sc_bus.bdev); 306 sc->sc_bus.bdev = NULL; 307 |
308 err = bus_teardown_intr(dev, esc->res[4], |
309 sc->sc_intr_hdl); 310 if (err) 311 device_printf(dev, "Could not tear down irq," 312 " %d\n", err); 313 return (1); 314 } 315 return (0); 316} --- 22 unchanged lines hidden (view full) --- 339 /* 340 * Disable interrupts that might have been switched on in 341 * ehci_init. 342 */ 343 if (sc->sc_io_tag && sc->sc_io_hdl) 344 bus_space_write_4(sc->sc_io_tag, sc->sc_io_hdl, 345 EHCI_USBINTR, 0); 346 |
347 if (esc->res[4] && sc->sc_intr_hdl) { 348 err = bus_teardown_intr(dev, esc->res[4], |
349 sc->sc_intr_hdl); 350 if (err) { 351 device_printf(dev, "Could not tear down irq," 352 " %d\n", err); 353 return (err); 354 } 355 sc->sc_intr_hdl = NULL; 356 } --- 13 unchanged lines hidden --- |