joy_ofisa.c revision 1.16
1/* $NetBSD: joy_ofisa.c,v 1.16 2016/12/09 17:18:35 christos Exp $ */ 2 3/*- 4 * Copyright (c) 1996, 1998, 2008 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.16 2016/12/09 17:18:35 christos Exp $"); 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/kernel.h> 38#include <sys/device.h> 39 40#include <sys/bus.h> 41 42#include <dev/ofw/openfirm.h> 43#include <dev/isa/isavar.h> 44#include <dev/ofisa/ofisavar.h> 45 46#include <dev/ic/joyvar.h> 47 48#define JOY_NPORTS 1 /* XXX should be in a header file */ 49 50struct joy_ofisa_softc { 51 struct joy_softc sc_joy; 52 kmutex_t sc_lock; 53}; 54 55static int joy_ofisa_match(device_t, cfdata_t, void *); 56static void joy_ofisa_attach(device_t, device_t, void *); 57 58CFATTACH_DECL_NEW(joy_ofisa, sizeof(struct joy_ofisa_softc), 59 joy_ofisa_match, joy_ofisa_attach, NULL, NULL); 60 61static int 62joy_ofisa_match(device_t parent, cfdata_t match, void *aux) 63{ 64 struct ofisa_attach_args *aa = aux; 65 static const char *const compatible_strings[] = { 66 "pnpPNP,b02f", /* generic joystick */ 67 NULL, 68 }; 69 int rv = 0; 70 71 if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) 72 rv = 1; 73 return rv; 74} 75 76static void 77joy_ofisa_attach(device_t parent, device_t self, void *aux) 78{ 79 struct joy_ofisa_softc *osc = device_private(self); 80 struct joy_softc *sc = &osc->sc_joy; 81 struct ofisa_attach_args *aa = aux; 82 struct ofisa_reg_desc reg; 83 int n; 84 85 /* 86 * We're living on an OFW. We have to ask the OFW what our 87 * register property looks like. 88 * 89 * We expect: 90 * 91 * 1 i/o register region 92 */ 93 94 n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1); 95 if (n != 1) { 96 aprint_error(": error getting register data\n"); 97 return; 98 } 99 if (reg.type != OFISA_REG_TYPE_IO) { 100 aprint_error(": register type not i/o\n"); 101 return; 102 } 103 if (reg.len != JOY_NPORTS) { 104 aprint_error(": weird register size (%lu, expected %d)\n", 105 (unsigned long)reg.len, JOY_NPORTS); 106 return; 107 } 108 109 sc->sc_iot = aa->iot; 110 sc->sc_dev = self; 111 112 if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) { 113 aprint_error(": unable to map register space\n"); 114 return; 115 } 116 117 ofisa_print_model(NULL, aa->oba.oba_phandle); 118 119 mutex_init(&osc->sc_lock, MUTEX_DEFAULT, IPL_NONE); 120 sc->sc_lock = &osc->sc_lock; 121 122 joyattach(sc); 123} 124