Skip to contentSkip to conversation

Corrected drivermodel for i8042.c

PATCH Pavel Machek 3 participants 4 messages Nov 16, 2003 – Nov 21, 2003 Input drivers

lore
Share & tools
lore
#0 lore raw

Hi!

Here's (slightly) better patch. i8042_controller_init() can not be __init when it is called from _resume() function.
Pavel

drivers/input/serio/i8042.c +37 -4
@@ -18,6 +18,7 @@
 #include <linux/reboot.h>
 #include <linux/init.h>
 #include <linux/serio.h>
+#include <linux/sysdev.h>
 
 #include <asm/io.h>
 
@@ -398,18 +399,15 @@
  * desired.
  */
 	
-static int __init i8042_controller_init(void)
+static int i8042_controller_init(void)
 {
-
 /*
  * Test the i8042. We need to know if it thinks it's working correctly
  * before doing anything else.
  */
 
 	i8042_flush();
-
 	if (i8042_reset) {
-
 		unsigned char param;
 
 		if (i8042_command(&param, I8042_CMD_CTL_TEST)) {
@@ -783,6 +781,33 @@
 	values->mux = index;
 }
 
+static int i8042_resume_port(struct serio *port)
+{
+	struct serio_dev *dev = port->dev;
+	if (dev) {
+		dev->disconnect(port);
+		dev->connect(port, dev);
+	}	
+}
+
+static int i8042_resume(struct sys_device *dev)
+{
+	if (i8042_controller_init())
+		printk(KERN_ERR "i8042: resume failed\n");
+	i8042_resume_port(&i8042_kbd_port);
+	return 0;
+}
+
+static struct sysdev_class kbc_sysclass = {
+	set_kset_name("i8042"),
+	.resume = i8042_resume,
+};
+
+static struct sys_device device_i8042 = {
+	.id	= 0,
+	.cls	= &kbc_sysclass,
+};
+
 int __init i8042_init(void)
 {
 	int i;
@@ -819,6 +845,14 @@
 
 	register_reboot_notifier(&i8042_notifier);
 
+	{
+		int error = sysdev_class_register(&kbc_sysclass);
+		if (!error)
+			error = sys_device_register(&device_i8042);
+		if (error)
+			printk(KERN_CRIT "Unable to register i8042 to driver model\n");
+	}
+
 	return 0;
 }
 
Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#1 lore raw

drivers/input/serio/i8042.c line 791

Quoted 9 lines · Pavel Machek
drivers/input/serio/i8042.c +8 -0
+static int i8042_resume_port(struct serio *port)
+{
+	struct serio_dev *dev = port->dev;
+	if (dev) {
+		dev->disconnect(port);
+		dev->connect(port, dev);
+	}
+}

You want to do that event if there was nothing attached to the port as a mouse might get plugged in while the box is suspended. I think serio_rescan() is more appropriate (it will do a disconnect if needed for you).

Overall there is a problem with disconnect/connect method as it will cause a new input device created for the same hardware if old input device is held open by some process. If ever serio_reconnect patches will make in the tree then serio_reconnect() can be used instead of serio_rescan() as it will try to keep the same input device.

Dmitry

#2 lore raw

Hi!

Quoted 5 lines
Quoted 5 lines
drivers/input/serio/i8042.c +5 -0
+static int i8042_resume_port(struct serio *port)
+{
+	struct serio_dev *dev = port->dev;
+	if (dev) {
+		dev->disconnect(port);
Quoted 8 lines

drivers/input/serio/i8042.c line 791

Quoted 3 lines
drivers/input/serio/i8042.c +3 -0
+		dev->connect(port, dev);
+	}
+}

You want to do that event if there was nothing attached to the port as a mouse might get plugged in while the box is suspended. I think serio_rescan() is more appropriate (it will do a disconnect if needed for you).

I tried doing _rescan() but could not figure it out :-(.

Quoted 4 lines

Overall there is a problem with disconnect/connect method as it will cause a new input device created for the same hardware if old input device is held open by some process. If ever serio_reconnect patches will make in the tree then serio_reconnect() can be used instead of

Where can I get _reconnect() patches?

Signature · 2 lines
				Pavel
Written on sharp zaurus, because my Velo1 broke. If you have Velo you don't need...
#3 lore raw
Quoted 16 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 5 lines
drivers/input/serio/i8042.c +5 -0
+static int i8042_resume_port(struct serio *port)
+{
+	struct serio_dev *dev = port->dev;
+	if (dev) {
+		dev->disconnect(port);
Quoted 8 lines

drivers/input/serio/i8042.c line 791

Quoted 3 lines
drivers/input/serio/i8042.c +3 -0
+		dev->connect(port, dev);
+	}
+}

You want to do that event if there was nothing attached to the port as a mouse might get plugged in while the box is suspended. I think serio_rescan() is more appropriate (it will do a disconnect if needed for you).

Quoted 8 lines

I tried doing _rescan() but could not figure it out :-(.

Quoted 4 lines

Overall there is a problem with disconnect/connect method as it will cause a new input device created for the same hardware if old input device is held open by some process. If ever serio_reconnect patches will make in the tree then serio_reconnect() can be used instead of

Where can I get _reconnect() patches?

Please take a look in -mm tree serio-* patches. I believe if you apply them and then copy psmouse_pm_callback into i8042_resume_port it should work.

Dmitry