xref: /openbsd-src/sys/dev/fdt/imxdwusb.c (revision 94673892b7b28179327a9d4cb100f53993b0bd92)
1 /*	$OpenBSD: imxdwusb.c,v 1.6 2023/09/22 01:10:44 jsg Exp $	*/
2 /*
3  * Copyright (c) 2017, 2018 Mark Kettenis <kettenis@openbsd.org>
4  * Copyright (c) 2020 Patrick Wildt <patrick@blueri.se>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/param.h>
20 #include <sys/systm.h>
21 #include <sys/device.h>
22 
23 #include <machine/bus.h>
24 #include <machine/fdt.h>
25 #include <machine/simplebusvar.h>
26 
27 #include <dev/ofw/openfirm.h>
28 #include <dev/ofw/ofw_clock.h>
29 #include <dev/ofw/ofw_power.h>
30 #include <dev/ofw/fdt.h>
31 
32 /*
33  * This driver is based on preliminary device tree bindings and will
34  * almost certainly need changes once the official bindings land in
35  * mainline Linux.  Support for these preliminary bindings will be
36  * dropped as soon as official bindings are available.
37  */
38 
39 struct imxdwusb_softc {
40 	struct simplebus_softc	sc_sbus;
41 };
42 
43 int	imxdwusb_match(struct device *, void *, void *);
44 void	imxdwusb_attach(struct device *, struct device *, void *);
45 
46 const struct cfattach imxdwusb_ca = {
47 	sizeof(struct imxdwusb_softc), imxdwusb_match, imxdwusb_attach
48 };
49 
50 struct cfdriver imxdwusb_cd = {
51 	NULL, "imxdwusb", DV_DULL
52 };
53 
54 int
imxdwusb_match(struct device * parent,void * match,void * aux)55 imxdwusb_match(struct device *parent, void *match, void *aux)
56 {
57 	struct fdt_attach_args *faa = aux;
58 
59 	return OF_is_compatible(faa->fa_node, "fsl,imx8mp-dwc3");
60 }
61 
62 void
imxdwusb_attach(struct device * parent,struct device * self,void * aux)63 imxdwusb_attach(struct device *parent, struct device *self, void *aux)
64 {
65 	struct imxdwusb_softc *sc = (struct imxdwusb_softc *)self;
66 	struct fdt_attach_args *faa = aux;
67 
68 	power_domain_enable(faa->fa_node);
69 	clock_enable_all(faa->fa_node);
70 	reset_deassert_all(faa->fa_node);
71 
72 	simplebus_attach(parent, &sc->sc_sbus.sc_dev, faa);
73 }
74