1*7769e6a4Smpi /* $OpenBSD: joy_isa.c,v 1.8 2022/02/21 10:24:28 mpi Exp $ */
2d46fa18dSderaadt /* $NetBSD: joy.c,v 1.3 1996/05/05 19:46:15 christos Exp $ */
3d46fa18dSderaadt
4d46fa18dSderaadt /*-
5d46fa18dSderaadt * Copyright (c) 1995 Jean-Marc Zucconi
6d46fa18dSderaadt * All rights reserved.
7d46fa18dSderaadt *
8d46fa18dSderaadt * Ported to NetBSD by Matthieu Herrb <matthieu@laas.fr>
9d46fa18dSderaadt *
10d46fa18dSderaadt * Redistribution and use in source and binary forms, with or without
11d46fa18dSderaadt * modification, are permitted provided that the following conditions
12d46fa18dSderaadt * are met:
13d46fa18dSderaadt * 1. Redistributions of source code must retain the above copyright
14d46fa18dSderaadt * notice, this list of conditions and the following disclaimer
15d46fa18dSderaadt * in this position and unchanged.
16d46fa18dSderaadt * 2. Redistributions in binary form must reproduce the above copyright
17d46fa18dSderaadt * notice, this list of conditions and the following disclaimer in the
18d46fa18dSderaadt * documentation and/or other materials provided with the distribution.
19d46fa18dSderaadt * 3. The name of the author may not be used to endorse or promote products
2047369814Sderaadt * derived from this software without specific prior written permission
21d46fa18dSderaadt *
22d46fa18dSderaadt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23d46fa18dSderaadt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24d46fa18dSderaadt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25d46fa18dSderaadt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26d46fa18dSderaadt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27d46fa18dSderaadt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28d46fa18dSderaadt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29d46fa18dSderaadt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30d46fa18dSderaadt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31d46fa18dSderaadt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32d46fa18dSderaadt *
33d46fa18dSderaadt */
34d46fa18dSderaadt
35d46fa18dSderaadt #include <sys/param.h>
36d46fa18dSderaadt #include <sys/systm.h>
37d46fa18dSderaadt #include <sys/kernel.h>
38d46fa18dSderaadt #include <sys/device.h>
39d46fa18dSderaadt #include <sys/errno.h>
40d46fa18dSderaadt
41d46fa18dSderaadt #include <machine/cpu.h>
42d46fa18dSderaadt #include <machine/pio.h>
43d46fa18dSderaadt #include <machine/cpufunc.h>
44d46fa18dSderaadt #include <machine/joystick.h>
45d46fa18dSderaadt #include <machine/conf.h>
46d46fa18dSderaadt
47d46fa18dSderaadt #include <dev/isa/isavar.h>
48d46fa18dSderaadt #include <dev/isa/isareg.h>
490b09e840Smartin #include <dev/ic/i8253reg.h>
50d46fa18dSderaadt #include <i386/isa/joyreg.h>
51d46fa18dSderaadt
52c4071fd1Smillert int joy_isa_probe(struct device *, void *, void *);
53c4071fd1Smillert void joy_isa_attach(struct device *, struct device *, void *);
54d46fa18dSderaadt
55*7769e6a4Smpi const struct cfattach joy_isa_ca = {
56d46fa18dSderaadt sizeof(struct joy_softc), joy_isa_probe, joy_isa_attach
57d46fa18dSderaadt };
58d46fa18dSderaadt
59d46fa18dSderaadt int
joy_isa_probe(struct device * parent,void * match,void * aux)6008f75f72Sjsg joy_isa_probe(struct device *parent, void *match, void *aux)
61d46fa18dSderaadt {
62d46fa18dSderaadt struct isa_attach_args *ia = aux;
63d46fa18dSderaadt #ifdef WANT_JOYSTICK_CONNECTED
64d46fa18dSderaadt int iobase = ia->ia_iobase;
65d46fa18dSderaadt
66d46fa18dSderaadt outb(iobase, 0xff);
67d46fa18dSderaadt DELAY(10000); /* 10 ms delay */
68d46fa18dSderaadt return (inb(iobase) & 0x0f) != 0x0f;
69d46fa18dSderaadt #else
70d46fa18dSderaadt ia->ia_iosize = JOY_NPORTS;
71d46fa18dSderaadt ia->ia_msize = 0;
72d46fa18dSderaadt return 1;
73d46fa18dSderaadt #endif
74d46fa18dSderaadt }
75d46fa18dSderaadt
76d46fa18dSderaadt void
joy_isa_attach(struct device * parent,struct device * self,void * aux)7708f75f72Sjsg joy_isa_attach(struct device *parent, struct device *self, void *aux)
78d46fa18dSderaadt {
79d46fa18dSderaadt struct joy_softc *sc = (void *) self;
80d46fa18dSderaadt struct isa_attach_args *ia = aux;
81d46fa18dSderaadt int iobase = ia->ia_iobase;
82d46fa18dSderaadt
83d46fa18dSderaadt sc->port = iobase;
84d46fa18dSderaadt sc->timeout[0] = sc->timeout[1] = 0;
85d46fa18dSderaadt outb(iobase, 0xff);
86d46fa18dSderaadt DELAY(10000); /* 10 ms delay */
87aee38620Sderaadt #if 0
88d46fa18dSderaadt printf(": joystick%sconnected\n",
89d46fa18dSderaadt (inb(iobase) & 0x0f) == 0x0f ? " not " : " ");
90aee38620Sderaadt #else
91aee38620Sderaadt printf("\n");
92aee38620Sderaadt #endif
93d46fa18dSderaadt }
94