1 /* $OpenBSD: pluart_fdt.c,v 1.3 2019/04/22 10:18:20 kettenis 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 #include <dev/ofw/ofw_pinctrl.h> 31 32 int pluart_fdt_match(struct device *, void *, void *); 33 void pluart_fdt_attach(struct device *, struct device *, void *); 34 35 struct cfattach pluart_fdt_ca = { 36 sizeof(struct pluart_softc), pluart_fdt_match, pluart_fdt_attach 37 }; 38 39 void 40 pluart_init_cons(void) 41 { 42 struct fdt_reg reg; 43 void *node; 44 45 if ((node = fdt_find_cons("arm,pl011")) == NULL) 46 return; 47 if (fdt_get_reg(node, 0, ®)) 48 return; 49 50 pluartcnattach(fdt_cons_bs_tag, reg.addr, B115200, TTYDEF_CFLAG); 51 } 52 53 int 54 pluart_fdt_match(struct device *parent, void *self, void *aux) 55 { 56 struct fdt_attach_args *faa = aux; 57 58 return OF_is_compatible(faa->fa_node, "arm,pl011"); 59 } 60 61 void 62 pluart_fdt_attach(struct device *parent, struct device *self, void *aux) 63 { 64 struct fdt_attach_args *faa = aux; 65 struct pluart_softc *sc = (struct pluart_softc *) self; 66 67 if (faa->fa_nreg < 1) { 68 printf(": no registers\n"); 69 return; 70 } 71 72 sc->sc_irq = fdt_intr_establish(faa->fa_node, IPL_TTY, pluart_intr, 73 sc, sc->sc_dev.dv_xname); 74 75 sc->sc_iot = faa->fa_iot; 76 if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size, 77 0, &sc->sc_ioh)) 78 panic("pluartattach: bus_space_map failed!"); 79 80 pinctrl_byname(faa->fa_node, "default"); 81 82 pluart_attach_common(sc, stdout_node == faa->fa_node); 83 } 84