Changeset View
Standalone View
sys/arm64/rockchip/rk_xhci.c
- This file was added.
/*- | |||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |||||
* | |||||
* Copyright (c) 2019 Greg V <greg@unrelenting.technology> | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
*/ | |||||
/* | |||||
* The Rockchip glue node for the Synopsys DesignWare USB 3.0 controller | |||||
* enables clocks, deasserts resets, and attaches the actual controller. | |||||
*/ | |||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
#include <sys/param.h> | |||||
#include <sys/systm.h> | |||||
#include <sys/bus.h> | |||||
#include <sys/kernel.h> | |||||
#include <sys/module.h> | |||||
#include <machine/bus.h> | |||||
#include <dev/fdt/simplebus.h> | |||||
#include <dev/ofw/ofw_bus.h> | |||||
#include <dev/ofw/ofw_bus_subr.h> | |||||
#include <dev/extres/clk/clk.h> | |||||
#include <dev/extres/hwreset/hwreset.h> | |||||
static int | |||||
rk_xhci_probe(device_t dev) | |||||
{ | |||||
if (!ofw_bus_status_okay(dev)) | |||||
return (ENXIO); | |||||
if (!(ofw_bus_is_compatible(dev, "rockchip,rk3328-dwc3") || | |||||
ofw_bus_is_compatible(dev, "rockchip,rk3399-dwc3"))) | |||||
return (ENXIO); | |||||
device_set_desc(dev, "Rockchip DWC3 USB 3.0 Controller"); | |||||
device_printf(dev, "probing rk_xhci\n"); | |||||
return (BUS_PROBE_DEFAULT); | |||||
} | |||||
static int | |||||
rk_xhci_attach(device_t dev) | |||||
{ | |||||
size_t off; | |||||
hwreset_t rst; | |||||
clk_t clk; | |||||
phandle_t node; | |||||
node = ofw_bus_get_node(dev); | |||||
if (OF_child(node) <= 0) { | |||||
device_printf(dev, "no child node found\n"); | |||||
return (ENXIO); | |||||
} | |||||
for (off = 0; clk_get_by_ofw_index(dev, 0, off, &clk) == 0; off++) { | |||||
if (bootverbose) | |||||
device_printf(dev, "enabling clock %s\n", | |||||
clk_get_name(clk)); | |||||
manu: The clock are named in the bindings, please use the name instead of this loop.
Also the clock… | |||||
Done Inline ActionsBut not all of the clocks in the device tree are mentioned in the bindings txt, only a list of the ones that "Should" be present (I wonder if that's SHOULD in the RFC 2119 sense :D) Linux actually has a generic driver for multiple glue nodes like this, not just Rockchip's one, and it iterates over all clocks val_packett.cool: But not all of the clocks in the device tree are mentioned in the bindings txt, only a list of… | |||||
Not Done Inline ActionsMhm yeah it seems that the bindings docs don't list "aclk_usb3_rksoc_axi_perf" and "aclk_usb3" but on our side we don't have those clocks defined. manu: Mhm yeah it seems that the bindings docs don't list "aclk_usb3_rksoc_axi_perf" and "aclk_usb3"… | |||||
if (clk_enable(clk) != 0) { | |||||
device_printf(dev, "could not enable clock %s\n", | |||||
clk_get_name(clk)); | |||||
return (ENXIO); | |||||
} | |||||
} | |||||
for (off = 0; hwreset_get_by_ofw_idx(dev, 0, off, &rst) == 0; off++) { | |||||
if (bootverbose) | |||||
Not Done Inline ActionsSame thing here, use the names. manu: Same thing here, use the names.
And same thing for the reset in the cru driver. | |||||
device_printf(dev, "deasserting reset\n"); | |||||
if (hwreset_deassert(rst) != 0) { | |||||
device_printf(dev, "could not deassert reset\n"); | |||||
return (ENXIO); | |||||
} | |||||
} | |||||
simplebus_init(dev, node); | |||||
bus_generic_probe(dev); | |||||
Done Inline ActionsAccording to the bindings (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/usb/rockchip,dwc3.txt?id=4436a3711e3249840e0679e92d3c951bcaf25515) the only requirement is to have a child node (and I think only one), so you need to clean and return ENXIO if no child node is present. manu: According to the bindings (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux. | |||||
/* Attach the actual DWC3 child device */ | |||||
node = OF_child(node); | |||||
simplebus_add_device(dev, node, 0, NULL, -1, NULL); | |||||
return (bus_generic_attach(dev)); | |||||
} | |||||
static device_method_t rk_xhci_methods[] = { | |||||
DEVMETHOD(device_probe, rk_xhci_probe), | |||||
DEVMETHOD(device_attach, rk_xhci_attach), | |||||
DEVMETHOD(device_suspend, bus_generic_suspend), | |||||
DEVMETHOD(device_resume, bus_generic_resume), | |||||
DEVMETHOD(device_shutdown, bus_generic_shutdown), | |||||
DEVMETHOD_END | |||||
}; | |||||
static devclass_t rk_xhci_devclass; | |||||
DEFINE_CLASS_1(rk_xhci, rk_xhci_driver, rk_xhci_methods, | |||||
sizeof(struct simplebus_softc), simplebus_driver); | |||||
DRIVER_MODULE(rk_xhci, simplebus, rk_xhci_driver, rk_xhci_devclass, 0, 0); | |||||
MODULE_DEPEND(rk_xhci, xhci, 1, 1, 1); |
The clock are named in the bindings, please use the name instead of this loop.
Also the clock should be in softc so we can disable them in detach/suspend/resume.
And we don't have the clocks in the cru driver, this needs to go first.