joy_isa.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* $OpenBSD: joy_isa.c,v 1.7 2007/08/01 13:18:18 martin Exp $ */
  2. /* $NetBSD: joy.c,v 1.3 1996/05/05 19:46:15 christos Exp $ */
  3. /*-
  4. * Copyright (c) 1995 Jean-Marc Zucconi
  5. * All rights reserved.
  6. *
  7. * Ported to NetBSD by Matthieu Herrb <matthieu@laas.fr>
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer
  14. * in this position and unchanged.
  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. 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 WARRANTIES
  23. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. #include <sys/param.h>
  34. #include <sys/systm.h>
  35. #include <sys/kernel.h>
  36. #include <sys/device.h>
  37. #include <sys/errno.h>
  38. #include <machine/cpu.h>
  39. #include <machine/pio.h>
  40. #include <machine/cpufunc.h>
  41. #include <machine/joystick.h>
  42. #include <machine/conf.h>
  43. #include <dev/isa/isavar.h>
  44. #include <dev/isa/isareg.h>
  45. #include <dev/ic/i8253reg.h>
  46. #include <i386/isa/joyreg.h>
  47. int joy_isa_probe(struct device *, void *, void *);
  48. void joy_isa_attach(struct device *, struct device *, void *);
  49. struct cfattach joy_isa_ca = {
  50. sizeof(struct joy_softc), joy_isa_probe, joy_isa_attach
  51. };
  52. int
  53. joy_isa_probe(struct device *parent, void *match, void *aux)
  54. {
  55. struct isa_attach_args *ia = aux;
  56. #ifdef WANT_JOYSTICK_CONNECTED
  57. int iobase = ia->ia_iobase;
  58. outb(iobase, 0xff);
  59. DELAY(10000); /* 10 ms delay */
  60. return (inb(iobase) & 0x0f) != 0x0f;
  61. #else
  62. ia->ia_iosize = JOY_NPORTS;
  63. ia->ia_msize = 0;
  64. return 1;
  65. #endif
  66. }
  67. void
  68. joy_isa_attach(struct device *parent, struct device *self, void *aux)
  69. {
  70. struct joy_softc *sc = (void *) self;
  71. struct isa_attach_args *ia = aux;
  72. int iobase = ia->ia_iobase;
  73. sc->port = iobase;
  74. sc->timeout[0] = sc->timeout[1] = 0;
  75. outb(iobase, 0xff);
  76. DELAY(10000); /* 10 ms delay */
  77. #if 0
  78. printf(": joystick%sconnected\n",
  79. (inb(iobase) & 0x0f) == 0x0f ? " not " : " ");
  80. #else
  81. printf("\n");
  82. #endif
  83. }