xref: /openbsd-src/sys/dev/fdt/rkdwusb.c (revision 94673892b7b28179327a9d4cb100f53993b0bd92)
1*94673892Sjsg /*	$OpenBSD: rkdwusb.c,v 1.5 2023/09/22 01:10:44 jsg Exp $	*/
2ff47428dSkettenis /*
3e8df7912Skettenis  * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org>
4ff47428dSkettenis  *
5ff47428dSkettenis  * Permission to use, copy, modify, and distribute this software for any
6ff47428dSkettenis  * purpose with or without fee is hereby granted, provided that the above
7ff47428dSkettenis  * copyright notice and this permission notice appear in all copies.
8ff47428dSkettenis  *
9ff47428dSkettenis  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10ff47428dSkettenis  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11ff47428dSkettenis  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12ff47428dSkettenis  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13ff47428dSkettenis  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14ff47428dSkettenis  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15ff47428dSkettenis  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16ff47428dSkettenis  */
17ff47428dSkettenis 
18ff47428dSkettenis #include <sys/param.h>
19ff47428dSkettenis #include <sys/systm.h>
20ff47428dSkettenis #include <sys/device.h>
21ff47428dSkettenis 
22ff47428dSkettenis #include <machine/bus.h>
23ff47428dSkettenis #include <machine/fdt.h>
24*94673892Sjsg #include <machine/simplebusvar.h>
25ff47428dSkettenis 
26ff47428dSkettenis #include <dev/ofw/openfirm.h>
27ff47428dSkettenis #include <dev/ofw/ofw_clock.h>
28ff47428dSkettenis #include <dev/ofw/fdt.h>
29ff47428dSkettenis 
30ff47428dSkettenis struct rkdwusb_softc {
31ff47428dSkettenis 	struct simplebus_softc	sc_sbus;
32ff47428dSkettenis };
33ff47428dSkettenis 
34ff47428dSkettenis int	rkdwusb_match(struct device *, void *, void *);
35ff47428dSkettenis void	rkdwusb_attach(struct device *, struct device *, void *);
36ff47428dSkettenis 
379fdf0c62Smpi const struct cfattach rkdwusb_ca = {
38ff47428dSkettenis 	sizeof(struct rkdwusb_softc), rkdwusb_match, rkdwusb_attach
39ff47428dSkettenis };
40ff47428dSkettenis 
41ff47428dSkettenis struct cfdriver rkdwusb_cd = {
42ff47428dSkettenis 	NULL, "rkdwusb", DV_DULL
43ff47428dSkettenis };
44ff47428dSkettenis 
45ff47428dSkettenis int
rkdwusb_match(struct device * parent,void * match,void * aux)46ff47428dSkettenis rkdwusb_match(struct device *parent, void *match, void *aux)
47ff47428dSkettenis {
48ff47428dSkettenis 	struct fdt_attach_args *faa = aux;
49ff47428dSkettenis 
50ff47428dSkettenis 	return OF_is_compatible(faa->fa_node, "rockchip,rk3399-dwc3");
51ff47428dSkettenis }
52ff47428dSkettenis 
53ff47428dSkettenis void
rkdwusb_attach(struct device * parent,struct device * self,void * aux)54ff47428dSkettenis rkdwusb_attach(struct device *parent, struct device *self, void *aux)
55ff47428dSkettenis {
56ff47428dSkettenis 	struct rkdwusb_softc *sc = (struct rkdwusb_softc *)self;
57ff47428dSkettenis 	struct fdt_attach_args *faa = aux;
58ff47428dSkettenis 
59ff47428dSkettenis 	clock_enable_all(faa->fa_node);
60347300eaSkettenis 	reset_deassert_all(faa->fa_node);
61ff47428dSkettenis 
62ff47428dSkettenis 	simplebus_attach(parent, &sc->sc_sbus.sc_dev, faa);
63ff47428dSkettenis }
64