Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 09 Sep 1999 11:52:31 +0900
From:      Takanori Watanabe <takawata@shidahara1.planet.sci.kobe-u.ac.jp>
To:        hackers@freebsd.org
Subject:   New(bus|pnp)-ifyed joy(4)
Message-ID:  <199909090252.LAA29146@shidahara1.planet.sci.kobe-u.ac.jp>

next in thread | raw e-mail | index | archive | help

Hi, I write patch for joy.c so that it recognize CS4235 Game port by PnP.
API do work,but hardware seems to be uninitialized.
(Read returns only 0x80000000)
Are there any person who review this?

To use PnP Interface,
write simply 
device joy0
and add your GAME port ID to
joy_ids[];


Takanori Watanabe
<a href="http://www.planet.sci.kobe-u.ac.jp/~takawata/key.html">;
Public Key</a>
Key fingerprint =  2C 51 E2 78 2C E1 C5 2D  0F F1 20 A3 11 3A 62 2A 
BTW.


diff -u /home/ctm/src/sys/i386/isa/isa_compat.h ./isa_compat.h
--- /home/ctm/src/sys/i386/isa/isa_compat.h	Thu Sep  9 08:17:07 1999
+++ ./isa_compat.h	Thu Sep  9 09:27:49 1999
@@ -140,7 +140,9 @@
 extern struct isa_driver spigotdriver;
 extern struct isa_driver  gpdriver;
 extern struct isa_driver gscdriver;
+#if 0
 extern struct isa_driver joydriver;
+#endif
 extern struct isa_driver  cydriver;
 extern struct isa_driver dgbdriver;
 extern struct isa_driver dgmdriver;
@@ -371,7 +373,7 @@
 #if NSPIGOT > 0
 	{ INTR_TYPE_MISC, &spigotdriver },
 #endif
-#if NJOY > 0
+#if 0
 	{ INTR_TYPE_MISC, &joydriver },
 #endif
 
diff -u /home/ctm/src/sys/i386/isa/joy.c ./joy.c
--- /home/ctm/src/sys/i386/isa/joy.c	Fri Aug 27 03:17:58 1999
+++ ./joy.c	Thu Sep  9 10:04:56 1999
@@ -35,12 +35,19 @@
 #include <sys/kernel.h>
 #include <sys/uio.h>
 
+
+
 #include <machine/clock.h>
 #include <machine/joystick.h>
+#include <machine/bus.h>
 
-#include <i386/isa/isa.h>
-#include <i386/isa/isa_device.h>
+#include <sys/bus.h>
+#include <sys/rman.h>
+#include <machine/resource.h>
+#include <isa/isareg.h>
+#include <isa/isavar.h>
 #include <i386/isa/timerreg.h>
+#include "isa_if.h"
 
 /* The game port can manage 4 buttons and 4 variable resistors (usually 2
  * joysticks, each with 2 buttons and 2 pots.) via the port at address 0x201.
@@ -65,17 +72,17 @@
 #define JOY_TIMEOUT   2000 /* 2 milliseconds */
 #endif
 
-static struct {
-    int port;
+struct joy_softc{
+    bus_space_tag_t  bt;
+    bus_space_handle_t port;
     int x_off[2], y_off[2];
     int timeout[2];
-} joy[NJOY];
+} ;
 
 
-static int joyprobe (struct isa_device *);
-static int joyattach (struct isa_device *);
+static int joy_probe (device_t);
+static int joy_attach (device_t);
 
-struct isa_driver joydriver = {joyprobe, joyattach, "joy"};
 
 #define CDEV_MAJOR 51
 static	d_open_t	joyopen;
@@ -107,12 +114,17 @@
 
 static int get_tick __P((void));
 
-
+devclass_t joy_devclass;
+static struct isa_pnp_id joy_ids[] = {
+  {0x0100630e,"CS4235 PnP Joystick"},
+  {0}
+};
 static int
-joyprobe (struct isa_device *dev)
+joy_probe (device_t dev)
 {
     static int once;
-
+    if(ISA_PNP_PROBE(device_get_parent(dev),dev,joy_ids)==ENXIO)
+       return ENXIO;
     if (!once++)
 	cdevsw_add(&joy_cdevsw);
 #ifdef WANT_JOYSTICK_CONNECTED
@@ -120,60 +132,77 @@
     DELAY (10000); /*  10 ms delay */
     return (inb (dev->id_iobase) & 0x0f) != 0x0f;
 #else
-    return 1;
+    return 0;
 #endif
 }
 
 static int
-joyattach (struct isa_device *dev)
+joy_attach (device_t dev)
 {
-    int	unit = dev->id_unit;
-
-    joy[unit].port = dev->id_iobase;
-    joy[unit].timeout[0] = joy[unit].timeout[1] = 0;
-    printf("joy%d: joystick\n", unit);
+    int	unit = device_get_unit(dev);
+    int rid=0;
+    struct resource *res;
+    struct joy_softc *joy=device_get_softc(dev);
+    res=bus_alloc_resource(dev,SYS_RES_IOPORT,&rid,0,~0,8,RF_ACTIVE);
+    if(res==NULL)
+      return ENXIO;
+    joy->bt =rman_get_bustag(res);
+    joy->port = rman_get_bushandle(res);
+    joy->timeout[0] = joy->timeout[1] = 0;
+    printf("joy%d : joystick\n ", unit);
     make_dev(&joy_cdevsw, 0, 0, 0, 0600, "joy%d", unit);
-    return 1;
+    return 0;
 }
+static device_method_t joy_methods[]={
+  DEVMETHOD(device_probe,joy_probe),
+  DEVMETHOD(device_attach,joy_attach),
+  {0,0}
+};
+static driver_t joy_isa_driver ={
+  "joy",
+  joy_methods,
+  sizeof (struct joy_softc)
+};
 
+DRIVER_MODULE(joy,isa,joy_isa_driver,joy_devclass,0,0);
 static	int
 joyopen (dev_t dev, int flags, int fmt, struct proc *p)
 {
-    int unit = UNIT (dev);
     int i = joypart (dev);
+    struct joy_softc *joy=devclass_get_softc(joy_devclass,UNIT(dev));
 
-    if (joy[unit].timeout[i])
+    if (joy->timeout[i])
 	return EBUSY;
-    joy[unit].x_off[i] = joy[unit].y_off[i] = 0;
-    joy[unit].timeout[i] = JOY_TIMEOUT;
+    joy->x_off[i] = joy->y_off[i] = 0;
+    joy->timeout[i] = JOY_TIMEOUT;
     return 0;
 }
 static	int
 joyclose (dev_t dev, int flags, int fmt, struct proc *p)
 {
-    int unit = UNIT (dev);
     int i = joypart (dev);
-
-    joy[unit].timeout[i] = 0;
+    struct joy_softc *joy=devclass_get_softc(joy_devclass,UNIT(dev));
+    joy->timeout[i] = 0;
     return 0;
 }
 
 static	int
 joyread (dev_t dev, struct uio *uio, int flag)
 {
-    int unit = UNIT(dev);
-    int port = joy[unit].port;
+    struct joy_softc *joy=devclass_get_softc(joy_devclass,UNIT(dev));
+    int port = joy->port;
+    int bt=joy->bt;
     int i, t0, t1;
     int state = 0, x = 0, y = 0;
     struct joystick c;
 
     disable_intr ();
-    outb (port, 0xff);
+    bus_space_write_1 (bt,port,0, 0xff);
     t0 = get_tick ();
     t1 = t0;
-    i = usec2ticks(joy[unit].timeout[joypart(dev)]);
+    i = usec2ticks(joy->timeout[joypart(dev)]);
     while (t0-t1 < i) {
-	state = inb (port);
+	state = bus_space_read_1 (bt,port,0);
 	if (joypart(dev) == 1)
 	    state >>= 2;
 	t1 = get_tick ();
@@ -187,8 +216,8 @@
 	    break;
     }
     enable_intr ();
-    c.x = x ? joy[unit].x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
-    c.y = y ? joy[unit].y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
+    c.x = x ? joy->x_off[joypart(dev)] + ticks2usec(t0-x) : 0x80000000;
+    c.y = y ? joy->y_off[joypart(dev)] + ticks2usec(t0-y) : 0x80000000;
     state >>= 4;
     c.b1 = ~state & 1;
     c.b2 = ~(state >> 1) & 1;
@@ -198,7 +227,7 @@
 static	int
 joyioctl (dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
 {
-    int unit = UNIT (dev);
+    struct joy_softc *joy=devclass_get_softc(joy_devclass,UNIT(dev));
     int i = joypart (dev);
     int x;
 
@@ -207,22 +236,22 @@
 	x = *(int *) data;
 	if (x < 1 || x > 10000) /* 10ms maximum! */
 	    return EINVAL;
-	joy[unit].timeout[i] = x;
+	joy->timeout[i] = x;
 	break;
     case JOY_GETTIMEOUT:
-	*(int *) data = joy[unit].timeout[i];
+	*(int *) data = joy->timeout[i];
 	break;
     case JOY_SET_X_OFFSET:
-	joy[unit].x_off[i] = *(int *) data;
+	joy->x_off[i] = *(int *) data;
 	break;
     case JOY_SET_Y_OFFSET:
-	joy[unit].y_off[i] = *(int *) data;
+	joy->y_off[i] = *(int *) data;
 	break;
     case JOY_GET_X_OFFSET:
-	*(int *) data = joy[unit].x_off[i];
+	*(int *) data = joy->x_off[i];
 	break;
     case JOY_GET_Y_OFFSET:
-	*(int *) data = joy[unit].y_off[i];
+	*(int *) data = joy->y_off[i];
 	break;
     default:
 	return ENXIO;


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909090252.LAA29146>