joy_ofisa.c revision 1.1
1/* $NetBSD: joy_ofisa.c,v 1.1 1998/08/20 07:02:32 thorpej Exp $ */ 2 3/*- 4 * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#include <sys/device.h> 43 44#include <machine/bus.h> 45 46#include <dev/ofw/openfirm.h> 47#include <dev/isa/isavar.h> 48#include <dev/ofisa/ofisavar.h> 49 50#include <arm32/isa/joyvar.h> 51 52#define JOY_NPORTS 1 /* XXX should be in a header file */ 53 54int joy_ofisa_match __P((struct device *, struct cfdata *, void *)); 55void joy_ofisa_attach __P((struct device *, struct device *, void *)); 56 57struct cfattach joy_ofisa_ca = { 58 sizeof(struct joy_softc), joy_ofisa_match, joy_ofisa_attach 59}; 60 61int 62joy_ofisa_match(parent, match, aux) 63 struct device *parent; 64 struct cfdata *match; 65 void *aux; 66{ 67 struct ofisa_attach_args *aa = aux; 68 const char *compatible_strings[] = { 69 "pnpPNP,b02f", /* generic joystick */ 70 NULL, 71 }; 72 int rv = 0; 73 74 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) 75 rv = 1; 76 return (rv); 77} 78 79void 80joy_ofisa_attach(parent, self, aux) 81 struct device *parent, *self; 82 void *aux; 83{ 84 struct joy_softc *sc = (struct joy_softc *)self; 85 struct ofisa_attach_args *aa = aux; 86 struct ofisa_reg_desc reg; 87 char *model = NULL; 88 int n; 89 90 /* 91 * We're living on an OFW. We have to ask the OFW what our 92 * register property looks like. 93 * 94 * We expect: 95 * 96 * 1 i/o register region 97 */ 98 99 n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1); 100 if (n != 1) { 101 printf(": error getting register data\n"); 102 return; 103 } 104 if (reg.type != OFISA_REG_TYPE_IO) { 105 printf(": register type not i/o\n"); 106 return; 107 } 108 if (reg.len != JOY_NPORTS) { 109 printf(": weird register size (%lu, expected %d)\n", 110 (unsigned long)reg.len, JOY_NPORTS); 111 return; 112 } 113 114 sc->sc_iot = aa->iot; 115 116 if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) { 117 printf(": unable to map register space\n"); 118 return; 119 } 120 121 n = OF_getproplen(aa->oba.oba_phandle, "model"); 122 if (n > 0) { 123 model = alloca(n); 124 if (OF_getprop(aa->oba.oba_phandle, "model", model, n) != n) 125 model = NULL; /* safe; alloca */ 126 } 127 if (model != NULL) 128 printf(": %s", model); 129 printf("\n"); 130 131 joyattach(sc); 132} 133