[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#321772: Module ns558 needs to be loaded twice to work properly



reassign 321772 kernel-source-2.6.8
tag 321772 +patch
thanks

On Sun, Aug 07, 2005 at 04:07:24PM +0200, Fabian Greffrath wrote:
> Package: kernel-image-2.6.8-2-k7
> Version: 2.6.8-16
> 
> I am filing this bug against this specific kernel version, although I do 
> not know, if other kernel versions are affected, too!
> 
> My system consists of an ASUS A7N8X (Targa Edition, Rev 1.04, Bios 1028) 
> running a nForce2 chipset.
> There is a Gravis Gamepad Pro (Rev 4) connected to the board's gameport.
> 
> I have the modules "joydev" and "grip" loaded, "analog" is not loaded.
> 
> 
> This is what I have to do to get the gameport working:
> 
> # modprobe -v ns558
> insmod /lib/modules/2.6.8-2-k7/kernel/drivers/input/gameport/ns558.ko
> 
> #dmesg
> (...)
> input: Gravis GamePad Pro on isa0201/gameport0
> gameport: NS558 ISA at 0x201 speed 685 kHz
> pnp: Device 00:11 disabled.
> ns558: probe of 00:11 failed with error -16
> 
> -> this is quite strange, because the gameport chipset (ns558) ist the 
> isapnp version!
> 
> # ls /dev/input/js*
> ls: /dev/input/js*: No such file or directory
> 
> # modprobe -vr ns558
> rmmod /lib/modules/2.6.8-2-k7/kernel/drivers/input/gameport/ns558.ko
> 
> # modprobe -v ns558
> insmod /lib/modules/2.6.8-2-k7/kernel/drivers/input/gameport/ns558.ko
> 
> #dmesg
> (...)
> pnp: Device 00:11 activated.
> input: Gravis GamePad Pro on pnp00:11/gameport0
> gameport: NS558 PnP at pnp00:11 io 0x201 speed 685 kHz
> 
> # ls /dev/input/js*
> /dev/input/js0
> 
> 
> So I have to insmod, rmmod and insmod again the module "ns558" in order 
> to get it working properly!


I strongly suspect that this patch fixes this problem
http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=f6397cecadc52779902bdd8f8cd3ea5af3a19ad1

That patch also depends on this patch, which 
seems to fix some more insmod/rmmod nastiness
http://www.kernel.org/git/?p=linux/kernel/git/torvalds/old-2.6-bkcvs.git;a=blobdiff;h=7c5c6318eeb9ffad3b1798fca4e1a13b8239689e;hp=f31ce0bad57942b7a66f01540b3816ed2ced8762;hb=913a66fbd55ce7ed0191d267306d6fa3181d98b1;f=drivers/input/gameport/ns558.c

I've attached thes second patches as ns558-load.diff and
the first patch as  ns558-pnp.diff. (They need to be
applied in that order). If I make images are you in a position
to test them. Alternatively, you could try 
linux-image-2.6.12-1-k7 image from unstable.

> BTW: He seems to have just the same problem: 
> http://lists.debian.org/debian-user/2005/02/msg03092.html

-- 
Horms
From: Vojtech Pavlik <vojtech@suse.cz>
Date: Sun, 29 May 2005 07:25:01 +0000 (-0500)
Subject: Input: Probe PnP gameports first, ISA after that.
X-Git-Tag: v2.6.12-rc6
X-Git-Url: http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=f6397cecadc52779902bdd8f8cd3ea5af3a19ad1

  Input: Probe PnP gameports first, ISA after that.
  
  Signed-off-by: Vojtech Pavlik <vojtech@suse.cz>
  Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -258,18 +258,18 @@ static int __init ns558_init(void)
 {
 	int i = 0;
 
+	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
+		pnp_registered = 1;
+
 /*
- * Probe ISA ports first so that PnP gets to choose free port addresses
- * not occupied by the ISA ports.
+ * Probe ISA ports after PnP, so that PnP ports that are already
+ * enabled get detected as PnP. This may be suboptimal in multi-device
+ * configurations, but saves hassle with simple setups.
  */
 
 	while (ns558_isa_portlist[i])
 		ns558_isa_probe(ns558_isa_portlist[i++]);
 
-	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
-		pnp_registered = 1;
-
-
 	return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0;
 }
 
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -44,20 +44,16 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@u
 MODULE_DESCRIPTION("Classic gameport (ISA/PnP) driver");
 MODULE_LICENSE("GPL");
 
-#define NS558_ISA	1
-#define NS558_PNP	2
-
 static int ns558_isa_portlist[] = { 0x201, 0x200, 0x202, 0x203, 0x204, 0x205, 0x207, 0x209,
 				    0x20b, 0x20c, 0x20e, 0x20f, 0x211, 0x219, 0x101, 0 };
 
 struct ns558 {
 	int type;
+	int io;
 	int size;
 	struct pnp_dev *dev;
+	struct gameport *gameport;
 	struct list_head node;
-	struct gameport gameport;
-	char phys[32];
-	char name[32];
 };
 
 static LIST_HEAD(ns558_list);
@@ -68,18 +64,19 @@ static LIST_HEAD(ns558_list);
  * A joystick must be attached for this to work.
  */
 
-static void ns558_isa_probe(int io)
+static int ns558_isa_probe(int io)
 {
 	int i, j, b;
 	unsigned char c, u, v;
-	struct ns558 *port;
+	struct ns558 *ns558;
+	struct gameport *port;
 
 /*
  * No one should be using this address.
  */
 
 	if (!request_region(io, 1, "ns558-isa"))
-		return;
+		return -EBUSY;
 
 /*
  * We must not be able to write arbitrary values to the port.
@@ -90,8 +87,8 @@ static void ns558_isa_probe(int io)
 	outb(~c & ~3, io);
 	if (~(u = v = inb(io)) & 3) {
 		outb(c, io);
-		i = 0;
-		goto out;
+		release_region(io, 1);
+		return -ENODEV;
 	}
 /*
  * After a trigger, there must be at least some bits changing.
@@ -101,8 +98,8 @@ static void ns558_isa_probe(int io)
 
 	if (u == v) {
 		outb(c, io);
-		i = 0;
-		goto out;
+		release_region(io, 1);
+		return -ENODEV;
 	}
 	msleep(3);
 /*
@@ -113,8 +110,8 @@ static void ns558_isa_probe(int io)
 	for (i = 0; i < 1000; i++)
 		if ((u ^ inb(io)) & 0xf) {
 			outb(c, io);
-			i = 0;
-			goto out;
+			release_region(io, 1);
+			return -ENODEV;
 		}
 /*
  * And now find the number of mirrors of the port.
@@ -122,17 +119,17 @@ static void ns558_isa_probe(int io)
 
 	for (i = 1; i < 5; i++) {
 
-		release_region(io & (-1 << (i-1)), (1 << (i-1)));
+		release_region(io & (-1 << (i - 1)), (1 << (i - 1)));
 
-		if (!request_region(io & (-1 << i), (1 << i), "ns558-isa"))	/* Don't disturb anyone */
-			break;
+		if (!request_region(io & (-1 << i), (1 << i), "ns558-isa"))
+			break;				/* Don't disturb anyone */
 
 		outb(0xff, io & (-1 << i));
 		for (j = b = 0; j < 1000; j++)
 			if (inb(io & (-1 << i)) != inb((io & (-1 << i)) + (1 << i) - 1)) b++;
 		msleep(3);
 
-		if (b > 300) {					/* We allow 30% difference */
+		if (b > 300) {				/* We allow 30% difference */
 			release_region(io & (-1 << i), (1 << i));
 			break;
 		}
@@ -142,35 +139,33 @@ static void ns558_isa_probe(int io)
 
 	if (i != 4) {
 		if (!request_region(io & (-1 << i), (1 << i), "ns558-isa"))
-			return;
+			return -EBUSY;
 	}
 
-	if (!(port = kmalloc(sizeof(struct ns558), GFP_KERNEL))) {
+	ns558 = kcalloc(1, sizeof(struct ns558), GFP_KERNEL);
+	port = gameport_allocate_port();
+	if (!ns558 || !port) {
 		printk(KERN_ERR "ns558: Memory allocation failed.\n");
-		goto out;
+		release_region(io & (-1 << i), (1 << i));
+		kfree(ns558);
+		gameport_free_port(port);
+		return -ENOMEM;
 	}
-	memset(port, 0, sizeof(struct ns558));
 
-	port->type = NS558_ISA;
-	port->size = (1 << i);
-	port->gameport.io = io;
-	port->gameport.phys = port->phys;
-	port->gameport.name = port->name;
-	port->gameport.id.bustype = BUS_ISA;
-
-	sprintf(port->phys, "isa%04x/gameport0", io & (-1 << i));
-	sprintf(port->name, "NS558 ISA");
-
-	gameport_register_port(&port->gameport);
-
-	printk(KERN_INFO "gameport: NS558 ISA at %#x", port->gameport.io);
-	if (port->size > 1) printk(" size %d", port->size);
-	printk(" speed %d kHz\n", port->gameport.speed);
-
-	list_add(&port->node, &ns558_list);
-	return;
-out:
-	release_region(io & (-1 << i), (1 << i));
+	memset(ns558, 0, sizeof(struct ns558));
+	ns558->io = io;
+	ns558->size = 1 << i;
+	ns558->gameport = port;
+
+	port->io = io;
+	gameport_set_name(port, "NS558 ISA Gameport");
+	gameport_set_phys(port, "isa%04x/gameport0", io & (-1 << i));
+
+	gameport_register_port(port);
+
+	list_add(&ns558->node, &ns558_list);
+
+	return 0;
 }
 
 #ifdef CONFIG_PNP
@@ -206,46 +201,42 @@ MODULE_DEVICE_TABLE(pnp, pnp_devids);
 static int ns558_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *did)
 {
 	int ioport, iolen;
-	struct ns558 *port;
+	struct ns558 *ns558;
+	struct gameport *port;
 
 	if (!pnp_port_valid(dev, 0)) {
 		printk(KERN_WARNING "ns558: No i/o ports on a gameport? Weird\n");
 		return -ENODEV;
 	}
 
-	ioport = pnp_port_start(dev,0);
-	iolen = pnp_port_len(dev,0);
+	ioport = pnp_port_start(dev, 0);
+	iolen = pnp_port_len(dev, 0);
 
 	if (!request_region(ioport, iolen, "ns558-pnp"))
 		return -EBUSY;
 
-	if (!(port = kmalloc(sizeof(struct ns558), GFP_KERNEL))) {
-		printk(KERN_ERR "ns558: Memory allocation failed.\n");
+	ns558 = kcalloc(1, sizeof(struct ns558), GFP_KERNEL);
+	port = gameport_allocate_port();
+	if (!ns558 || !port) {
+		printk(KERN_ERR "ns558: Memory allocation failed\n");
+		kfree(ns558);
+		gameport_free_port(port);
 		return -ENOMEM;
 	}
-	memset(port, 0, sizeof(struct ns558));
 
-	port->type = NS558_PNP;
-	port->size = iolen;
-	port->dev = dev;
+	ns558->io = ioport;
+	ns558->size = iolen;
+	ns558->dev = dev;
+	ns558->gameport = port;
+
+	gameport_set_name(port, "NS558 PnP Gameport");
+	gameport_set_phys(port, "pnp%s/gameport0", dev->dev.bus_id);
+	port->dev.parent = &dev->dev;
+	port->io = ioport;
 
-	port->gameport.io = ioport;
-	port->gameport.phys = port->phys;
-	port->gameport.name = port->name;
-	port->gameport.id.bustype = BUS_ISAPNP;
-	port->gameport.id.version = 0x100;
+	gameport_register_port(port);
 
-	sprintf(port->phys, "pnp%s/gameport0", dev->dev.bus_id);
-	sprintf(port->name, "%s", "NS558 PnP Gameport");
-
-	gameport_register_port(&port->gameport);
-
-	printk(KERN_INFO "gameport: NS558 PnP at pnp%s io %#x",
-		dev->dev.bus_id, port->gameport.io);
-	if (iolen > 1) printk(" size %d", iolen);
-	printk(" speed %d kHz\n", port->gameport.speed);
-
-	list_add_tail(&port->node, &ns558_list);
+	list_add_tail(&ns558->node, &ns558_list);
 	return 0;
 }
 
@@ -261,43 +252,39 @@ static struct pnp_driver ns558_pnp_drive
 
 #endif
 
-int __init ns558_init(void)
+static int pnp_registered = 0;
+
+static int __init ns558_init(void)
 {
 	int i = 0;
 
 /*
- * Probe for ISA ports.
+ * Probe ISA ports first so that PnP gets to choose free port addresses
+ * not occupied by the ISA ports.
  */
 
 	while (ns558_isa_portlist[i])
 		ns558_isa_probe(ns558_isa_portlist[i++]);
 
-	pnp_register_driver(&ns558_pnp_driver);
-	return list_empty(&ns558_list) ? -ENODEV : 0;
-}
+	if (pnp_register_driver(&ns558_pnp_driver) >= 0)
+		pnp_registered = 1;
 
-void __exit ns558_exit(void)
-{
-	struct ns558 *port;
 
-	list_for_each_entry(port, &ns558_list, node) {
-		gameport_unregister_port(&port->gameport);
-		switch (port->type) {
+	return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0;
+}
 
-#ifdef CONFIG_PNP
-			case NS558_PNP:
-				/* fall through */
-#endif
-			case NS558_ISA:
-				release_region(port->gameport.io & ~(port->size - 1), port->size);
-				kfree(port);
-				break;
+static void __exit ns558_exit(void)
+{
+	struct ns558 *ns558;
 
-			default:
-				break;
-		}
+	list_for_each_entry(ns558, &ns558_list, node) {
+		gameport_unregister_port(ns558->gameport);
+		release_region(ns558->io & ~(ns558->size - 1), ns558->size);
+		kfree(ns558);
 	}
-	pnp_unregister_driver(&ns558_pnp_driver);
+
+	if (pnp_registered)
+		pnp_unregister_driver(&ns558_pnp_driver);
 }
 
 module_init(ns558_init);

Reply to: