xref: /openbsd-src/sys/dev/fdt/imxgpc.c (revision c90a81c56dcebd6a1b73fe4aff9b03385b8e63b3)
1 /*	$OpenBSD: imxgpc.c,v 1.4 2018/08/06 10:52:30 patrick Exp $	*/
2 /*
3  * Copyright (c) 2016 Mark Kettenis
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21 
22 #include <machine/fdt.h>
23 
24 #include <dev/ofw/openfirm.h>
25 
26 struct imxgpc_softc {
27 	struct device	sc_dev;
28 	struct interrupt_controller sc_ic;
29 };
30 
31 int	imxgpc_match(struct device *, void *, void *);
32 void	imxgpc_attach(struct device *, struct device *, void *);
33 
34 struct cfattach imxgpc_ca = {
35 	sizeof(struct imxgpc_softc), imxgpc_match, imxgpc_attach
36 };
37 
38 struct cfdriver imxgpc_cd = {
39 	NULL, "imxgpc", DV_DULL
40 };
41 
42 int
43 imxgpc_match(struct device *parent, void *match, void *aux)
44 {
45 	struct fdt_attach_args *faa = aux;
46 
47 	return (OF_is_compatible(faa->fa_node, "fsl,imx6q-gpc") ||
48 	    OF_is_compatible(faa->fa_node, "fsl,imx7d-gpc") ||
49 	    OF_is_compatible(faa->fa_node, "fsl,imx8mq-gpc"));
50 }
51 
52 void
53 imxgpc_attach(struct device *parent, struct device *self, void *aux)
54 {
55 	struct fdt_attach_args *faa = aux;
56 	struct imxgpc_softc *sc = (struct imxgpc_softc *)self;
57 
58 	sc->sc_ic.ic_node = faa->fa_node;
59 	sc->sc_ic.ic_cookie = &sc->sc_ic;
60 	sc->sc_ic.ic_establish = fdt_intr_parent_establish;
61 	sc->sc_ic.ic_disestablish = fdt_intr_parent_disestablish;
62 	fdt_intr_register(&sc->sc_ic);
63 
64 	printf("\n");
65 }
66