xref: /openbsd-src/sys/dev/fdt/pluart_fdt.c (revision c90a81c56dcebd6a1b73fe4aff9b03385b8e63b3)
1 /*	$OpenBSD: pluart_fdt.c,v 1.2 2018/08/06 10:52:30 patrick Exp $	*/
2 /*
3  * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
4  * Copyright (c) 2005 Dale Rahn <drahn@dalerahn.com>
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/tty.h>
22 
23 #include <machine/bus.h>
24 #include <machine/fdt.h>
25 
26 #include <dev/ic/pluartvar.h>
27 
28 #include <dev/ofw/fdt.h>
29 #include <dev/ofw/openfirm.h>
30 
31 int	pluart_fdt_match(struct device *, void *, void *);
32 void	pluart_fdt_attach(struct device *, struct device *, void *);
33 
34 struct cfattach pluart_fdt_ca = {
35 	sizeof(struct pluart_softc), pluart_fdt_match, pluart_fdt_attach
36 };
37 
38 void
39 pluart_init_cons(void)
40 {
41 	struct fdt_reg reg;
42 	void *node;
43 
44 	if ((node = fdt_find_cons("arm,pl011")) == NULL)
45 		return;
46 	if (fdt_get_reg(node, 0, &reg))
47 		return;
48 
49 	pluartcnattach(fdt_cons_bs_tag, reg.addr, B115200, TTYDEF_CFLAG);
50 }
51 
52 int
53 pluart_fdt_match(struct device *parent, void *self, void *aux)
54 {
55 	struct fdt_attach_args *faa = aux;
56 
57 	return OF_is_compatible(faa->fa_node, "arm,pl011");
58 }
59 
60 void
61 pluart_fdt_attach(struct device *parent, struct device *self, void *aux)
62 {
63 	struct fdt_attach_args *faa = aux;
64 	struct pluart_softc *sc = (struct pluart_softc *) self;
65 
66 	if (faa->fa_nreg < 1) {
67 		printf(": no registers\n");
68 		return;
69 	}
70 
71 	sc->sc_irq = fdt_intr_establish(faa->fa_node, IPL_TTY, pluart_intr,
72 	    sc, sc->sc_dev.dv_xname);
73 
74 	sc->sc_iot = faa->fa_iot;
75 	if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size,
76 	    0, &sc->sc_ioh))
77 		panic("pluartattach: bus_space_map failed!");
78 
79 	pluart_attach_common(sc, stdout_node == faa->fa_node);
80 }
81