xref: /freebsd/sys/arm/ti/am335x/am335x_usb_phy.c (revision 7ef62cebc2f965b0f640263e179276928885e33d)
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 
88 	sc = device_get_softc(dev);
89 	sc->dev = dev;
90 
91 	/* FIXME: Add dev/extres/phy/ interface */
92 
93 	return (bus_generic_attach(dev));
94 }
95 
96 static int
97 ti_usb_phy_detach(device_t dev)
98 {
99 	return (EBUSY);
100 }
101 
102 static device_method_t ti_usb_phy_methods[] = {
103 	/* Device interface */
104 	DEVMETHOD(device_probe,		ti_usb_phy_probe),
105 	DEVMETHOD(device_attach,	ti_usb_phy_attach),
106 	DEVMETHOD(device_detach,	ti_usb_phy_detach),
107 
108 	DEVMETHOD_END
109 };
110 
111 DEFINE_CLASS_1(ti_usb_phy, ti_usb_phy_driver, ti_usb_phy_methods,
112     sizeof(struct ti_usb_phy_softc), simplebus_driver);
113 
114 EARLY_DRIVER_MODULE(ti_usb_phy, simplebus, ti_usb_phy_driver, 0, 0,
115     BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
116 MODULE_VERSION(ti_usb_phy, 1);
117 MODULE_DEPEND(ti_usb_phy, ti_sysc, 1, 1, 1);
118