]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/ti/am335x/am335x_usb_phy.c
Move Ti AM335x to dev/extres/clk framework.
[FreeBSD/FreeBSD.git] / sys / arm / ti / am335x / am335x_usb_phy.c
1 /*-
2  *
3  * Copyright (c) 2020 Oskar Holmlund <oskar.holmlund@ohdata.se>
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
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
21  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22  * 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  * $FreeBSD$
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/bus.h>
35 #include <sys/fbio.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/rman.h>
39 #include <sys/resource.h>
40 #include <machine/bus.h>
41 #include <vm/vm.h>
42 #include <vm/vm_extern.h>
43 #include <vm/vm_kern.h>
44 #include <vm/pmap.h>
45
46 #include <dev/fdt/simplebus.h>
47
48 #include <dev/ofw/ofw_bus.h>
49 #include <dev/ofw/ofw_bus_subr.h>
50
51 #define TI_AM335X_USB_PHY               1
52 #define TI_AM335X_USB_PHY_END           0
53
54 static struct ofw_compat_data compat_data[] = {
55         { "ti,am335x-usb-phy",  TI_AM335X_USB_PHY },
56         { NULL,                 TI_AM335X_USB_PHY_END }
57 };
58
59 struct ti_usb_phy_softc {
60         device_t                dev;
61 };
62
63 static int ti_usb_phy_probe(device_t dev);
64 static int ti_usb_phy_attach(device_t dev);
65 static int ti_usb_phy_detach(device_t dev);
66
67 static int
68 ti_usb_phy_probe(device_t dev)
69 {
70         if (!ofw_bus_status_okay(dev))
71                 return (ENXIO);
72
73         if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
74                 return (ENXIO);
75
76         device_set_desc(dev, "TI AM335x USB PHY");
77         if (!bootverbose)
78                 device_quiet(dev);
79
80         return (BUS_PROBE_DEFAULT);
81 }
82
83 static int
84 ti_usb_phy_attach(device_t dev)
85 {
86         struct ti_usb_phy_softc *sc;
87         phandle_t node;
88
89         sc = device_get_softc(dev);
90         sc->dev = dev;
91         node = ofw_bus_get_node(dev);
92
93         /* FIXME: Add dev/extres/phy/ interface */
94
95         return (bus_generic_attach(dev));
96 }
97
98 static int
99 ti_usb_phy_detach(device_t dev)
100 {
101         return (EBUSY);
102 }
103
104 static device_method_t ti_usb_phy_methods[] = {
105         /* Device interface */
106         DEVMETHOD(device_probe,         ti_usb_phy_probe),
107         DEVMETHOD(device_attach,        ti_usb_phy_attach),
108         DEVMETHOD(device_detach,        ti_usb_phy_detach),
109
110         DEVMETHOD_END
111 };
112
113 DEFINE_CLASS_1(ti_usb_phy, ti_usb_phy_driver, ti_usb_phy_methods,
114     sizeof(struct ti_usb_phy_softc), simplebus_driver);
115
116 static devclass_t ti_usb_phy_devclass;
117
118 EARLY_DRIVER_MODULE(ti_usb_phy, simplebus, ti_usb_phy_driver,
119     ti_usb_phy_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
120 MODULE_VERSION(ti_usb_phy, 1);
121 MODULE_DEPEND(ti_usb_phy, ti_sysc, 1, 1, 1);