1 /* $OpenBSD: apio.c,v 1.1 2002/03/14 19:18:29 jason Exp $ */ 2 3 /* 4 * Copyright (c) 2002 Jason L. Wright (jason@thought.net) 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Jason L. Wright 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * Driver for Aurora 210SJ parallel ports. 36 */ 37 38 #include <sys/types.h> 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/kernel.h> 42 #include <sys/device.h> 43 #include <sys/conf.h> 44 #include <sys/timeout.h> 45 #include <sys/tty.h> 46 47 #include <machine/bus.h> 48 #include <machine/autoconf.h> 49 #include <machine/openfirm.h> 50 51 #include <dev/sbus/sbusvar.h> 52 #include <dev/sbus/asioreg.h> 53 #include <dev/ic/lptvar.h> 54 #include "apio.h" 55 #include "lpt.h" 56 57 struct apio_softc { 58 struct device sc_dev; 59 bus_space_tag_t sc_bt; 60 bus_space_handle_t sc_csr_h; 61 bus_space_handle_t sc_clk_h; 62 bus_space_handle_t sc_lpt_h; 63 void *sc_ih; 64 struct device *sc_port; 65 }; 66 67 struct apio_attach_args { 68 char *aaa_name; 69 bus_space_tag_t aaa_iot; 70 bus_space_handle_t aaa_ioh; 71 bus_space_handle_t aaa_clkh; 72 u_int32_t aaa_pri; 73 u_int8_t aaa_inten; 74 }; 75 76 int apio_match(struct device *, void *, void *); 77 void apio_attach(struct device *, struct device *, void *); 78 int apio_print(void *, const char *); 79 void apio_intr_enable(struct device *, u_int8_t); 80 81 struct cfattach apio_ca = { 82 sizeof(struct apio_softc), apio_match, apio_attach 83 }; 84 85 struct cfdriver apio_cd = { 86 NULL, "apio", DV_DULL 87 }; 88 89 int 90 apio_match(parent, match, aux) 91 struct device *parent; 92 void *match; 93 void *aux; 94 { 95 struct sbus_attach_args *sa = aux; 96 97 if (strcmp(sa->sa_name, "pio1") == 0) 98 return (1); 99 return (0); 100 } 101 102 void 103 apio_attach(parent, self, aux) 104 struct device *parent, *self; 105 void *aux; 106 { 107 struct apio_softc *sc = (void *)self; 108 struct sbus_attach_args *sa = aux; 109 struct apio_attach_args aaa; 110 char *model; 111 112 sc->sc_bt = sa->sa_bustag; 113 114 model = getpropstring(sa->sa_node, "model"); 115 if (model == NULL) { 116 printf(": empty model, unsupported\n"); 117 return; 118 } 119 if (strcmp(model, "210sj") != 0) { 120 printf(": unsupported model %s\n", model); 121 return; 122 } 123 124 if (sa->sa_nreg < 3) { 125 printf(": %d registers expected, got %d\n", 126 3, sa->sa_nreg); 127 return; 128 } 129 130 if (sbus_bus_map(sa->sa_bustag, 131 sa->sa_reg[0].sbr_slot, 132 sa->sa_reg[0].sbr_offset, 133 sa->sa_reg[0].sbr_size, 134 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_csr_h)) { 135 printf(": couldn't map csr\n"); 136 return; 137 } 138 139 if (sbus_bus_map(sa->sa_bustag, 140 sa->sa_reg[1].sbr_slot, 141 sa->sa_reg[1].sbr_offset, 142 sa->sa_reg[1].sbr_size, 143 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_clk_h)) { 144 printf(": couldn't map clk\n"); 145 return; 146 } 147 148 if (sbus_bus_map(sa->sa_bustag, 149 sa->sa_reg[2].sbr_slot, 150 sa->sa_reg[2].sbr_offset, 151 sa->sa_reg[2].sbr_size, 152 BUS_SPACE_MAP_LINEAR, 0, &sc->sc_lpt_h)) { 153 printf(": couldn't map clk\n"); 154 return; 155 } 156 157 printf(": %s\n", model); 158 159 aaa.aaa_name = "lpt"; 160 aaa.aaa_iot = sc->sc_bt; 161 aaa.aaa_ioh = sc->sc_lpt_h; 162 aaa.aaa_clkh = sc->sc_clk_h; 163 aaa.aaa_inten = ASIO_CSR_SJ_PAR_INTEN; 164 aaa.aaa_pri = sa->sa_intr[0].sbi_pri; 165 sc->sc_port = config_found(self, &aaa, apio_print); 166 } 167 168 int 169 apio_print(aux, name) 170 void *aux; 171 const char *name; 172 { 173 struct apio_attach_args *aaa; 174 175 if (name != NULL) 176 printf("%s at %s", aaa->aaa_name, name); 177 return (UNCONF); 178 } 179 180 #if NLPT_APIO > 0 181 int lpt_apio_match(struct device *, void *, void *); 182 void lpt_apio_attach(struct device *, struct device *, void *); 183 int lpt_apio_intr(void *); 184 185 struct lpt_apio_softc { 186 struct lpt_softc sc_lpt; 187 bus_space_handle_t sc_clk_h; 188 void *sc_ih; 189 }; 190 191 struct cfattach lpt_apio_ca = { 192 sizeof(struct lpt_apio_softc), lpt_apio_match, lpt_apio_attach 193 }; 194 195 void 196 apio_intr_enable(dv, en) 197 struct device *dv; 198 u_int8_t en; 199 { 200 struct apio_softc *sc = (struct apio_softc *)dv; 201 u_int8_t csr; 202 203 csr = bus_space_read_1(sc->sc_bt, sc->sc_csr_h, 0); 204 csr &= ~(ASIO_CSR_SBUS_INT7 | ASIO_CSR_SBUS_INT6); 205 csr |= ASIO_CSR_SBUS_INT5 | en; 206 bus_space_write_1(sc->sc_bt, sc->sc_csr_h, 0, csr); 207 } 208 209 int 210 lpt_apio_match(parent, match, aux) 211 struct device *parent; 212 void *match; 213 void *aux; 214 { 215 return (1); 216 } 217 218 void 219 lpt_apio_attach(parent, self, aux) 220 struct device *parent, *self; 221 void *aux; 222 { 223 struct lpt_apio_softc *sc = (struct lpt_apio_softc *)self; 224 struct apio_attach_args *aaa = aux; 225 226 sc->sc_lpt.sc_state = 0; 227 sc->sc_lpt.sc_iot = aaa->aaa_iot; 228 sc->sc_lpt.sc_ioh = aaa->aaa_ioh; 229 sc->sc_clk_h = aaa->aaa_clkh; 230 sc->sc_ih = bus_intr_establish(aaa->aaa_iot, aaa->aaa_pri, 231 IPL_TTY, 0, lpt_apio_intr, sc); 232 if (sc->sc_ih == NULL) { 233 printf(": cannot allocate intr\n"); 234 return; 235 } 236 apio_intr_enable(parent, aaa->aaa_inten); 237 238 lpt_attach_common(&sc->sc_lpt); 239 } 240 241 int 242 lpt_apio_intr(vsc) 243 void *vsc; 244 { 245 struct lpt_apio_softc *sc = vsc; 246 int r; 247 248 r = lptintr(&sc->sc_lpt); 249 bus_space_read_1(sc->sc_lpt.sc_iot, sc->sc_clk_h, 0); 250 return (r); 251 } 252 #endif 253