xref: /openbsd-src/sys/dev/fdt/qcdwusb.c (revision 3374c67d44f9b75b98444cbf63020f777792342e)
1 /*	$OpenBSD: qcdwusb.c,v 1.1 2022/11/06 12:12:45 patrick Exp $	*/
2 /*
3  * Copyright (c) 2017, 2018 Mark Kettenis <kettenis@openbsd.org>
4  * Copyright (c) 2020, 2022 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 
26 #include <arm64/dev/simplebusvar.h>
27 
28 #include <dev/ofw/openfirm.h>
29 #include <dev/ofw/ofw_clock.h>
30 #include <dev/ofw/ofw_power.h>
31 #include <dev/ofw/fdt.h>
32 
33 struct qcdwusb_softc {
34 	struct simplebus_softc	sc_sbus;
35 };
36 
37 int	qcdwusb_match(struct device *, void *, void *);
38 void	qcdwusb_attach(struct device *, struct device *, void *);
39 
40 const struct cfattach qcdwusb_ca = {
41 	sizeof(struct qcdwusb_softc), qcdwusb_match, qcdwusb_attach
42 };
43 
44 struct cfdriver qcdwusb_cd = {
45 	NULL, "qcdwusb", DV_DULL
46 };
47 
48 int
49 qcdwusb_match(struct device *parent, void *match, void *aux)
50 {
51 	struct fdt_attach_args *faa = aux;
52 
53 	return OF_is_compatible(faa->fa_node, "qcom,dwc3");
54 }
55 
56 void
57 qcdwusb_attach(struct device *parent, struct device *self, void *aux)
58 {
59 	struct qcdwusb_softc *sc = (struct qcdwusb_softc *)self;
60 	struct fdt_attach_args *faa = aux;
61 
62 	power_domain_enable(faa->fa_node);
63 	clock_enable_all(faa->fa_node);
64 	reset_deassert_all(faa->fa_node);
65 
66 	simplebus_attach(parent, &sc->sc_sbus.sc_dev, faa);
67 }
68