xref: /freebsd/sys/arm/ti/am335x/am335x_usb_phy.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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 
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/bus.h>
30 #include <sys/fbio.h>
31 #include <sys/kernel.h>
32 #include <sys/module.h>
33 #include <sys/rman.h>
34 #include <sys/resource.h>
35 #include <machine/bus.h>
36 #include <vm/vm.h>
37 #include <vm/vm_extern.h>
38 #include <vm/vm_kern.h>
39 #include <vm/pmap.h>
40 
41 #include <dev/fdt/simplebus.h>
42 
43 #include <dev/ofw/ofw_bus.h>
44 #include <dev/ofw/ofw_bus_subr.h>
45 
46 #define TI_AM335X_USB_PHY		1
47 #define TI_AM335X_USB_PHY_END		0
48 
49 static struct ofw_compat_data compat_data[] = {
50 	{ "ti,am335x-usb-phy",	TI_AM335X_USB_PHY },
51 	{ NULL,			TI_AM335X_USB_PHY_END }
52 };
53 
54 struct ti_usb_phy_softc {
55 	device_t		dev;
56 };
57 
58 static int ti_usb_phy_probe(device_t dev);
59 static int ti_usb_phy_attach(device_t dev);
60 static int ti_usb_phy_detach(device_t dev);
61 
62 static int
63 ti_usb_phy_probe(device_t dev)
64 {
65 	if (!ofw_bus_status_okay(dev))
66 		return (ENXIO);
67 
68 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
69 		return (ENXIO);
70 
71 	device_set_desc(dev, "TI AM335x USB PHY");
72 	if (!bootverbose)
73 		device_quiet(dev);
74 
75 	return (BUS_PROBE_DEFAULT);
76 }
77 
78 static int
79 ti_usb_phy_attach(device_t dev)
80 {
81 	struct ti_usb_phy_softc *sc;
82 
83 	sc = device_get_softc(dev);
84 	sc->dev = dev;
85 
86 	/* FIXME: Add dev/phy/ interface */
87 
88 	return (bus_generic_attach(dev));
89 }
90 
91 static int
92 ti_usb_phy_detach(device_t dev)
93 {
94 	return (EBUSY);
95 }
96 
97 static device_method_t ti_usb_phy_methods[] = {
98 	/* Device interface */
99 	DEVMETHOD(device_probe,		ti_usb_phy_probe),
100 	DEVMETHOD(device_attach,	ti_usb_phy_attach),
101 	DEVMETHOD(device_detach,	ti_usb_phy_detach),
102 
103 	DEVMETHOD_END
104 };
105 
106 DEFINE_CLASS_1(ti_usb_phy, ti_usb_phy_driver, ti_usb_phy_methods,
107     sizeof(struct ti_usb_phy_softc), simplebus_driver);
108 
109 EARLY_DRIVER_MODULE(ti_usb_phy, simplebus, ti_usb_phy_driver, 0, 0,
110     BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
111 MODULE_VERSION(ti_usb_phy, 1);
112 MODULE_DEPEND(ti_usb_phy, ti_sysc, 1, 1, 1);
113