The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm64/rockchip/rk_dwc3.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.Org>
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 
   28 /*
   29  * Rockchip DWC3 glue
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __FBSDID("$FreeBSD$");
   34 
   35 #include <sys/param.h>
   36 #include <sys/systm.h>
   37 #include <sys/bus.h>
   38 #include <sys/rman.h>
   39 #include <sys/kernel.h>
   40 #include <sys/module.h>
   41 #include <sys/gpio.h>
   42 #include <machine/bus.h>
   43 
   44 #include <dev/fdt/simplebus.h>
   45 
   46 #include <dev/fdt/fdt_common.h>
   47 #include <dev/ofw/ofw_bus.h>
   48 #include <dev/ofw/ofw_bus_subr.h>
   49 #include <dev/ofw/ofw_subr.h>
   50 
   51 #include <dev/extres/clk/clk.h>
   52 #include <dev/extres/hwreset/hwreset.h>
   53 #include <dev/extres/phy/phy_usb.h>
   54 #include <dev/extres/syscon/syscon.h>
   55 
   56 enum rk_dwc3_type {
   57         RK3399 = 1,
   58 };
   59 
   60 static struct ofw_compat_data compat_data[] = {
   61         { "rockchip,rk3399-dwc3",       RK3399 },
   62         { NULL,                         0 }
   63 };
   64 
   65 struct rk_dwc3_softc {
   66         struct simplebus_softc  sc;
   67         device_t                dev;
   68         clk_t                   clk_ref;
   69         clk_t                   clk_suspend;
   70         clk_t                   clk_bus;
   71         clk_t                   clk_axi_perf;
   72         clk_t                   clk_usb3;
   73         clk_t                   clk_grf;
   74         hwreset_t               rst_usb3;
   75         enum rk_dwc3_type       type;
   76 };
   77 
   78 static int
   79 rk_dwc3_probe(device_t dev)
   80 {
   81         phandle_t node;
   82 
   83         if (!ofw_bus_status_okay(dev))
   84                 return (ENXIO);
   85 
   86         if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
   87                 return (ENXIO);
   88 
   89         /* Binding says that we need a child node for the actual dwc3 controller */
   90         node = ofw_bus_get_node(dev);
   91         if (OF_child(node) <= 0)
   92                 return (ENXIO);
   93 
   94         device_set_desc(dev, "Rockchip RK3399 DWC3");
   95         return (BUS_PROBE_DEFAULT);
   96 }
   97 
   98 static int
   99 rk_dwc3_attach(device_t dev)
  100 {
  101         struct rk_dwc3_softc *sc;
  102         device_t cdev;
  103         phandle_t node, child;
  104         int err;
  105 
  106         sc = device_get_softc(dev);
  107         sc->dev = dev;
  108         node = ofw_bus_get_node(dev);
  109         sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
  110 
  111         /* Mandatory clocks */
  112         if (clk_get_by_ofw_name(dev, 0, "ref_clk", &sc->clk_ref) != 0) {
  113                 device_printf(dev, "Cannot get ref_clk clock\n");
  114                 return (ENXIO);
  115         }
  116         err = clk_enable(sc->clk_ref);
  117         if (err != 0) {
  118                 device_printf(dev, "Could not enable clock %s\n",
  119                     clk_get_name(sc->clk_ref));
  120                 return (ENXIO);
  121         }
  122         if (clk_get_by_ofw_name(dev, 0, "suspend_clk", &sc->clk_suspend) != 0) {
  123                 device_printf(dev, "Cannot get suspend_clk clock\n");
  124                 return (ENXIO);
  125         }
  126         err = clk_enable(sc->clk_suspend);
  127         if (err != 0) {
  128                 device_printf(dev, "Could not enable clock %s\n",
  129                     clk_get_name(sc->clk_suspend));
  130                 return (ENXIO);
  131         }
  132         if (clk_get_by_ofw_name(dev, 0, "bus_clk", &sc->clk_bus) != 0) {
  133                 device_printf(dev, "Cannot get bus_clk clock\n");
  134                 return (ENXIO);
  135         }
  136         err = clk_enable(sc->clk_bus);
  137         if (err != 0) {
  138                 device_printf(dev, "Could not enable clock %s\n",
  139                     clk_get_name(sc->clk_bus));
  140                 return (ENXIO);
  141         }
  142         if (clk_get_by_ofw_name(dev, 0, "grf_clk", &sc->clk_grf) == 0) {
  143                 err = clk_enable(sc->clk_grf);
  144                 if (err != 0) {
  145                         device_printf(dev, "Could not enable clock %s\n",
  146                             clk_get_name(sc->clk_grf));
  147                         return (ENXIO);
  148                 }
  149         }
  150         /* Optional clocks */
  151         if (clk_get_by_ofw_name(dev, 0, "aclk_usb3_rksoc_axi_perf", &sc->clk_axi_perf) == 0) {
  152                 err = clk_enable(sc->clk_axi_perf);
  153                 if (err != 0) {
  154                         device_printf(dev, "Could not enable clock %s\n",
  155                           clk_get_name(sc->clk_axi_perf));
  156                         return (ENXIO);
  157                 }
  158         }
  159         if (clk_get_by_ofw_name(dev, 0, "aclk_usb3", &sc->clk_usb3) == 0) {
  160                 err = clk_enable(sc->clk_usb3);
  161                 if (err != 0) {
  162                         device_printf(dev, "Could not enable clock %s\n",
  163                           clk_get_name(sc->clk_usb3));
  164                         return (ENXIO);
  165                 }
  166         }
  167 
  168         /* Put module out of reset */
  169         if (hwreset_get_by_ofw_name(dev, node, "usb3-otg", &sc->rst_usb3) == 0) {
  170                 if (hwreset_deassert(sc->rst_usb3) != 0) {
  171                         device_printf(dev, "Cannot deassert reset\n");
  172                         return (ENXIO);
  173                 }
  174         }
  175 
  176         simplebus_init(dev, node);
  177         if (simplebus_fill_ranges(node, &sc->sc) < 0) {
  178                 device_printf(dev, "could not get ranges\n");
  179                 return (ENXIO);
  180         }
  181 
  182         for (child = OF_child(node); child > 0; child = OF_peer(child)) {
  183                 cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
  184                 if (cdev != NULL)
  185                         device_probe_and_attach(cdev);
  186         }
  187 
  188         return (bus_generic_attach(dev));
  189 }
  190 
  191 static device_method_t rk_dwc3_methods[] = {
  192         /* Device interface */
  193         DEVMETHOD(device_probe,         rk_dwc3_probe),
  194         DEVMETHOD(device_attach,        rk_dwc3_attach),
  195 
  196         DEVMETHOD_END
  197 };
  198 
  199 DEFINE_CLASS_1(rk_dwc3, rk_dwc3_driver, rk_dwc3_methods,
  200     sizeof(struct rk_dwc3_softc), simplebus_driver);
  201 DRIVER_MODULE(rk_dwc3, simplebus, rk_dwc3_driver, 0, 0);

Cache object: 067bf6eb4d4b774e24a46084d41d0bd2


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.