Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/usb/controller/dwc_otg_fdt.c
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
* | * | ||||
* Copyright (c) 2012 Hans Petter Selasky. All rights reserved. | * Copyright (c) 2012 Hans Petter Selasky. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
dwc_otg_attach(device_t dev) | dwc_otg_attach(device_t dev) | ||||
{ | { | ||||
struct dwc_otg_fdt_softc *sc = device_get_softc(dev); | struct dwc_otg_fdt_softc *sc = device_get_softc(dev); | ||||
char usb_mode[24]; | char usb_mode[24]; | ||||
int err; | int err; | ||||
int rid; | int rid; | ||||
/* initialise some bus fields */ | |||||
sc->sc_otg.sc_bus.parent = dev; | sc->sc_otg.sc_bus.parent = dev; | ||||
sc->sc_otg.sc_bus.devices = sc->sc_otg.sc_devices; | |||||
sc->sc_otg.sc_bus.devices_max = DWC_OTG_MAX_DEVICES; | |||||
sc->sc_otg.sc_bus.dma_bits = 32; | |||||
/* get USB mode, if any */ | /* get USB mode, if any */ | ||||
if (OF_getprop(ofw_bus_get_node(dev), "dr_mode", | if (OF_getprop(ofw_bus_get_node(dev), "dr_mode", | ||||
&usb_mode, sizeof(usb_mode)) > 0) { | &usb_mode, sizeof(usb_mode)) > 0) { | ||||
/* ensure proper zero termination */ | /* ensure proper zero termination */ | ||||
usb_mode[sizeof(usb_mode) - 1] = 0; | usb_mode[sizeof(usb_mode) - 1] = 0; | ||||
if (strcasecmp(usb_mode, "host") == 0) | if (strcasecmp(usb_mode, "host") == 0) | ||||
sc->sc_otg.sc_mode = DWC_MODE_HOST; | sc->sc_otg.sc_mode = DWC_MODE_HOST; | ||||
else if (strcasecmp(usb_mode, "peripheral") == 0) | else if (strcasecmp(usb_mode, "peripheral") == 0) | ||||
sc->sc_otg.sc_mode = DWC_MODE_DEVICE; | sc->sc_otg.sc_mode = DWC_MODE_DEVICE; | ||||
else if (strcasecmp(usb_mode, "otg") != 0) { | else if (strcasecmp(usb_mode, "otg") != 0) { | ||||
device_printf(dev, "Invalid FDT dr_mode: %s\n", | device_printf(dev, "Invalid FDT dr_mode: %s\n", | ||||
usb_mode); | usb_mode); | ||||
} | } | ||||
} | } | ||||
/* get all DMA memory */ | |||||
if (usb_bus_mem_alloc_all(&sc->sc_otg.sc_bus, | |||||
USB_GET_DMA_TAG(dev), NULL)) { | |||||
return (ENOMEM); | |||||
} | |||||
rid = 0; | rid = 0; | ||||
sc->sc_otg.sc_io_res = | sc->sc_otg.sc_io_res = | ||||
bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); | bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); | ||||
if (!(sc->sc_otg.sc_io_res)) { | if (!(sc->sc_otg.sc_io_res)) | ||||
err = ENOMEM; | |||||
goto error; | goto error; | ||||
} | |||||
sc->sc_otg.sc_io_tag = rman_get_bustag(sc->sc_otg.sc_io_res); | |||||
sc->sc_otg.sc_io_hdl = rman_get_bushandle(sc->sc_otg.sc_io_res); | |||||
sc->sc_otg.sc_io_size = rman_get_size(sc->sc_otg.sc_io_res); | |||||
/* | /* | ||||
* brcm,bcm2708-usb FDT provides two interrupts, we need only the USB | * brcm,bcm2708-usb FDT provides two interrupts, we need only the USB | ||||
* interrupt (VC_USB). The latest FDT for it provides an | * interrupt (VC_USB). The latest FDT for it provides an | ||||
* interrupt-names property and swapped them around, while older ones | * interrupt-names property and swapped them around, while older ones | ||||
* did not have interrupt-names and put the usb interrupt in the second | * did not have interrupt-names and put the usb interrupt in the second | ||||
* position. We'll attempt to use interrupt-names first with a fallback | * position. We'll attempt to use interrupt-names first with a fallback | ||||
* to the old method of assuming the index based on the compatible | * to the old method of assuming the index based on the compatible | ||||
* string. | * string. | ||||
*/ | */ | ||||
if (dwc_otg_irq_index(dev, &rid) != 0) | if (dwc_otg_irq_index(dev, &rid) != 0) | ||||
rid = ofw_bus_is_compatible(dev, "brcm,bcm2708-usb") ? 1 : 0; | rid = ofw_bus_is_compatible(dev, "brcm,bcm2708-usb") ? 1 : 0; | ||||
sc->sc_otg.sc_irq_res = | sc->sc_otg.sc_irq_res = | ||||
bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); | bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); | ||||
if (sc->sc_otg.sc_irq_res == NULL) | if (sc->sc_otg.sc_irq_res == NULL) | ||||
goto error; | goto error; | ||||
sc->sc_otg.sc_bus.bdev = device_add_child(dev, "usbus", -1); | sc->sc_otg.sc_bus.bdev = device_add_child(dev, "usbus", -1); | ||||
if (sc->sc_otg.sc_bus.bdev == NULL) | if (sc->sc_otg.sc_bus.bdev == NULL) | ||||
goto error; | goto error; | ||||
device_set_ivars(sc->sc_otg.sc_bus.bdev, &sc->sc_otg.sc_bus); | |||||
err = bus_setup_intr(dev, sc->sc_otg.sc_irq_res, INTR_TYPE_TTY | INTR_MPSAFE, | |||||
&dwc_otg_filter_interrupt, &dwc_otg_interrupt, sc, &sc->sc_otg.sc_intr_hdl); | |||||
if (err) { | |||||
sc->sc_otg.sc_intr_hdl = NULL; | |||||
goto error; | |||||
} | |||||
err = dwc_otg_init(&sc->sc_otg); | err = dwc_otg_init(&sc->sc_otg); | ||||
if (err == 0) { | if (err == 0) { | ||||
err = device_probe_and_attach(sc->sc_otg.sc_bus.bdev); | err = device_probe_and_attach(sc->sc_otg.sc_bus.bdev); | ||||
} | } | ||||
if (err) | if (err) | ||||
goto error; | goto error; | ||||
return (0); | return (0); | ||||
error: | error: | ||||
dwc_otg_detach(dev); | dwc_otg_detach(dev); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |