linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFT] Sonypi: convert to the new platform device interface
@ 2005-12-13  7:19 Dmitry Torokhov
  2005-12-13 18:32 ` Mattia Dongili
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2005-12-13  7:19 UTC (permalink / raw)
  To: LKML; +Cc: Stelian Pop

Hi,

Now that we allow manual binding and unbinding devices through sysfs it
is better if main device initialization is done in ->probe() instead of
module_init(). The following patch converts sonypi driver to this model.

The patch compiles but I was unable to test it since I don't have the
hardware...

-- 
Dmitry

Sonypi: convert to the new platform device interface

Do not use platform_device_register_simple() as it is going away,
implement ->probe() and -remove() functions so manual binding and
unbinding would work.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

Index: work/drivers/char/sonypi.c
===================================================================
--- work.orig/drivers/char/sonypi.c
+++ work/drivers/char/sonypi.c
@@ -471,7 +471,6 @@ struct sonypi_keypress {
 
 static struct sonypi_device {
 	struct pci_dev *dev;
-	struct platform_device *pdev;
 	u16 irq;
 	u16 bits;
 	u16 ioport1;
@@ -1165,45 +1164,12 @@ static int sonypi_disable(void)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int old_camera_power;
-
-static int sonypi_suspend(struct platform_device *dev, pm_message_t state)
-{
-	old_camera_power = sonypi_device.camera_power;
-	sonypi_disable();
-
-	return 0;
-}
-
-static int sonypi_resume(struct platform_device *dev)
-{
-	sonypi_enable(old_camera_power);
-	return 0;
-}
-#endif
-
-static void sonypi_shutdown(struct platform_device *dev)
-{
-	sonypi_disable();
-}
-
-static struct platform_driver sonypi_driver = {
-#ifdef CONFIG_PM
-	.suspend	= sonypi_suspend,
-	.resume		= sonypi_resume,
-#endif
-	.shutdown	= sonypi_shutdown,
-	.driver		= {
-		.name	= "sonypi",
-	},
-};
-
 static int __devinit sonypi_create_input_devices(void)
 {
 	struct input_dev *jog_dev;
 	struct input_dev *key_dev;
 	int i;
+	int error;
 
 	sonypi_device.input_jog_dev = jog_dev = input_allocate_device();
 	if (!jog_dev)
@@ -1219,9 +1185,8 @@ static int __devinit sonypi_create_input
 
 	sonypi_device.input_key_dev = key_dev = input_allocate_device();
 	if (!key_dev) {
-		input_free_device(jog_dev);
-		sonypi_device.input_jog_dev = NULL;
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto err_free_jogdev;
 	}
 
 	key_dev->name = "Sony Vaio Keys";
@@ -1234,56 +1199,122 @@ static int __devinit sonypi_create_input
 		if (sonypi_inputkeys[i].inputev)
 			set_bit(sonypi_inputkeys[i].inputev, key_dev->keybit);
 
-	input_register_device(jog_dev);
-	input_register_device(key_dev);
+	error = input_register_device(jog_dev);
+	if (error)
+		goto err_free_keydev;
+
+	error = input_register_device(key_dev);
+	if (error)
+		goto err_unregister_jogdev;
 
 	return 0;
+
+ err_unregister_jogdev:
+	input_unregister_device(jog_dev);
+	/* Set to NULL so we don't free it again below */
+	jog_dev = NULL;
+ err_free_keydev:
+	input_free_device(key_dev);
+	sonypi_device.input_key_dev = NULL;
+ err_free_jogdev:
+	input_unregister_device(jog_dev);
+	sonypi_device.input_jog_dev = NULL;
+
+	return error;
 }
 
-static int __devinit sonypi_probe(void)
+static int __devinit sonypi_setup_ioports(struct sonypi_device *dev,
+				const struct sonypi_ioport_list *ioport_list)
 {
-	int i, ret;
-	struct sonypi_ioport_list *ioport_list;
-	struct sonypi_irq_list *irq_list;
-	struct pci_dev *pcidev;
+	while (ioport_list->port1) {
 
-	if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				     PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
-		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
-	else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-					  PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
-		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE3;
-	else
-		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
+		if (request_region(ioport_list->port1,
+				   sonypi_device.region_size,
+				   "Sony Programable I/O Device")) {
+			dev->ioport1 = ioport_list->port1;
+			dev->ioport2 = ioport_list->port2;
+			return 0;
+		}
+		ioport_list++;
+	}
 
-	sonypi_device.dev = pcidev;
+	return -EBUSY;
+}
+
+static int __devinit sonypi_setup_irq(struct sonypi_device *dev,
+				      const struct sonypi_irq_list *irq_list)
+{
+	while (irq_list->irq) {
+
+		if (!request_irq(dev->irq, sonypi_irq,
+				 SA_SHIRQ, "sonypi", sonypi_irq)) {
+			dev->irq = irq_list->irq;
+			dev->bits = irq_list->bits;
+			return 0;
+		}
+		irq_list++;
+	}
+
+	return -EBUSY;
+}
+
+static void __devinit sonypi_display_info(void)
+{
+	printk(KERN_INFO "sonypi: detected type%d model, "
+	       "verbose = %d, fnkeyinit = %s, camera = %s, "
+	       "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
+	       sonypi_device.model,
+	       verbose,
+	       fnkeyinit ? "on" : "off",
+	       camera ? "on" : "off",
+	       compat ? "on" : "off",
+	       mask,
+	       useinput ? "on" : "off",
+	       SONYPI_ACPI_ACTIVE ? "on" : "off");
+	printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
+	       sonypi_device.irq,
+	       sonypi_device.ioport1, sonypi_device.ioport2);
+
+	if (minor == -1)
+		printk(KERN_INFO "sonypi: device allocated minor is %d\n",
+		       sonypi_misc_device.minor);
+}
+
+static int __devinit sonypi_probe(struct platform_device *dev)
+{
+	const struct sonypi_ioport_list *ioport_list;
+	const struct sonypi_irq_list *irq_list;
+	struct pci_dev *pcidev;
+	int error;
 
 	spin_lock_init(&sonypi_device.fifo_lock);
 	sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
 					 &sonypi_device.fifo_lock);
 	if (IS_ERR(sonypi_device.fifo)) {
 		printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
-		ret = PTR_ERR(sonypi_device.fifo);
-		goto out_fifo;
+		return PTR_ERR(sonypi_device.fifo);
 	}
 
 	init_waitqueue_head(&sonypi_device.fifo_proc_list);
 	init_MUTEX(&sonypi_device.lock);
 	sonypi_device.bluetooth_power = -1;
 
+	if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+				     PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
+		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
+	else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+					  PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
+		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE3;
+	else
+		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
+
 	if (pcidev && pci_enable_device(pcidev)) {
 		printk(KERN_ERR "sonypi: pci_enable_device failed\n");
-		ret = -EIO;
-		goto out_pcienable;
-	}
-
-	if (minor != -1)
-		sonypi_misc_device.minor = minor;
-	if ((ret = misc_register(&sonypi_misc_device))) {
-		printk(KERN_ERR "sonypi: misc_register failed\n");
-		goto out_miscreg;
+		error = -EIO;
+		goto err_free_fifo;
 	}
 
+	sonypi_device.dev = pcidev;
 
 	if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) {
 		ioport_list = sonypi_type1_ioport_list;
@@ -1302,43 +1333,31 @@ static int __devinit sonypi_probe(void)
 		irq_list = sonypi_type3_irq_list;
 	}
 
-	for (i = 0; ioport_list[i].port1; i++) {
-		if (request_region(ioport_list[i].port1,
-				   sonypi_device.region_size,
-				   "Sony Programable I/O Device")) {
-			/* get the ioport */
-			sonypi_device.ioport1 = ioport_list[i].port1;
-			sonypi_device.ioport2 = ioport_list[i].port2;
-			break;
-		}
+	error = sonypi_setup_ioports(&sonypi_device, ioport_list);
+	if (error) {
+		printk(KERN_ERR "sonypi: failed to request ioports\n");
+		goto err_disable_pcidev;
 	}
-	if (!sonypi_device.ioport1) {
-		printk(KERN_ERR "sonypi: request_region failed\n");
-		ret = -ENODEV;
-		goto out_reqreg;
-	}
-
-	for (i = 0; irq_list[i].irq; i++) {
-
-		sonypi_device.irq = irq_list[i].irq;
-		sonypi_device.bits = irq_list[i].bits;
 
-		if (!request_irq(sonypi_device.irq, sonypi_irq,
-				 SA_SHIRQ, "sonypi", sonypi_irq))
-			break;
+	error = sonypi_setup_irq(&sonypi_device, irq_list);
+	if (error) {
+		printk(KERN_ERR "sonypi: request_irq failed\n");
+		goto err_free_ioports;
 	}
 
-	if (!irq_list[i].irq) {
-		printk(KERN_ERR "sonypi: request_irq failed\n");
-		ret = -ENODEV;
-		goto out_reqirq;
+	if (minor != -1)
+		sonypi_misc_device.minor = minor;
+	error = misc_register(&sonypi_misc_device);
+	if (error) {
+		printk(KERN_ERR "sonypi: misc_register failed\n");
+		goto err_free_irq;
 	}
 
 	if (useinput) {
 
-		ret = sonypi_create_input_devices();
-		if (ret)
-			goto out_inputdevices;
+		error = sonypi_create_input_devices();
+		if (error)
+			goto err_miscdev_unregister;
 
 		spin_lock_init(&sonypi_device.input_fifo_lock);
 		sonypi_device.input_fifo =
@@ -1346,90 +1365,105 @@ static int __devinit sonypi_probe(void)
 				    &sonypi_device.input_fifo_lock);
 		if (IS_ERR(sonypi_device.input_fifo)) {
 			printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
-			ret = PTR_ERR(sonypi_device.input_fifo);
-			goto out_infifo;
+			error = PTR_ERR(sonypi_device.input_fifo);
+			goto err_inpdev_unregister;
 		}
 
 		INIT_WORK(&sonypi_device.input_work, input_keyrelease, NULL);
 	}
 
-	sonypi_device.pdev = platform_device_register_simple("sonypi", -1,
-							     NULL, 0);
-	if (IS_ERR(sonypi_device.pdev)) {
-		ret = PTR_ERR(sonypi_device.pdev);
-		goto out_platformdev;
-	}
-
+	sonypi_display_info();
 	sonypi_enable(0);
 
-	printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver"
-	       "v%s.\n", SONYPI_DRIVER_VERSION);
-	printk(KERN_INFO "sonypi: detected type%d model, "
-	       "verbose = %d, fnkeyinit = %s, camera = %s, "
-	       "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
-	       sonypi_device.model,
-	       verbose,
-	       fnkeyinit ? "on" : "off",
-	       camera ? "on" : "off",
-	       compat ? "on" : "off",
-	       mask,
-	       useinput ? "on" : "off",
-	       SONYPI_ACPI_ACTIVE ? "on" : "off");
-	printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
-	       sonypi_device.irq,
-	       sonypi_device.ioport1, sonypi_device.ioport2);
-
-	if (minor == -1)
-		printk(KERN_INFO "sonypi: device allocated minor is %d\n",
-		       sonypi_misc_device.minor);
-
 	return 0;
 
-out_platformdev:
-	kfifo_free(sonypi_device.input_fifo);
-out_infifo:
+ err_inpdev_unregister:
 	input_unregister_device(sonypi_device.input_key_dev);
 	input_unregister_device(sonypi_device.input_jog_dev);
-out_inputdevices:
+ err_miscdev_unregister:
+	misc_deregister(&sonypi_misc_device);
+ err_free_irq:
 	free_irq(sonypi_device.irq, sonypi_irq);
-out_reqirq:
+ err_free_ioports:
 	release_region(sonypi_device.ioport1, sonypi_device.region_size);
-out_reqreg:
-	misc_deregister(&sonypi_misc_device);
-out_miscreg:
-	if (pcidev)
+ err_disable_pcidev:
+	if (pcidev) {
 		pci_disable_device(pcidev);
-out_pcienable:
+		pci_dev_put(sonypi_device.dev);
+	}
+ err_free_fifo:
 	kfifo_free(sonypi_device.fifo);
-out_fifo:
-	pci_dev_put(sonypi_device.dev);
-	return ret;
+
+	return error;
 }
 
-static void __devexit sonypi_remove(void)
+static int __devexit sonypi_remove(struct platform_device *dev)
 {
 	sonypi_disable();
 
 	synchronize_sched();  /* Allow sonypi interrupt to complete. */
 	flush_scheduled_work();
 
-	platform_device_unregister(sonypi_device.pdev);
-
 	if (useinput) {
 		input_unregister_device(sonypi_device.input_key_dev);
 		input_unregister_device(sonypi_device.input_jog_dev);
 		kfifo_free(sonypi_device.input_fifo);
 	}
 
+	misc_deregister(&sonypi_misc_device);
+
 	free_irq(sonypi_device.irq, sonypi_irq);
 	release_region(sonypi_device.ioport1, sonypi_device.region_size);
-	misc_deregister(&sonypi_misc_device);
-	if (sonypi_device.dev)
+
+	if (sonypi_device.dev) {
 		pci_disable_device(sonypi_device.dev);
+		pci_dev_put(sonypi_device.dev);
+	}
+
 	kfifo_free(sonypi_device.fifo);
-	pci_dev_put(sonypi_device.dev);
-	printk(KERN_INFO "sonypi: removed.\n");
+
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int old_camera_power;
+
+static int sonypi_suspend(struct platform_device *dev, pm_message_t state)
+{
+	old_camera_power = sonypi_device.camera_power;
+	sonypi_disable();
+
+	return 0;
+}
+
+static int sonypi_resume(struct platform_device *dev)
+{
+	sonypi_enable(old_camera_power);
+	return 0;
 }
+#else
+#define sonypi_suspend	NULL
+#define sonypi_resume	NULL
+#endif
+
+static void sonypi_shutdown(struct platform_device *dev)
+{
+	sonypi_disable();
+}
+
+static struct platform_driver sonypi_driver = {
+	.driver		= {
+		.name	= "sonypi",
+		.owner	= THIS_MODULE,
+	},
+	.probe		= sonypi_probe,
+	.remove		= __devexit_p(sonypi_remove),
+	.shutdown	= sonypi_shutdown,
+	.suspend	= sonypi_suspend,
+	.resume		= sonypi_resume,
+};
+
+static struct platform_device *sonypi_platform_device;
 
 static struct dmi_system_id __initdata sonypi_dmi_table[] = {
 	{
@@ -1451,26 +1485,43 @@ static struct dmi_system_id __initdata s
 
 static int __init sonypi_init(void)
 {
-	int ret;
+	int error;
+
+	printk(KERN_INFO
+		"sonypi: Sony Programmable I/O Controller Driver v%s.\n",
+		SONYPI_DRIVER_VERSION);
 
 	if (!dmi_check_system(sonypi_dmi_table))
 		return -ENODEV;
 
-	ret = platform_driver_register(&sonypi_driver);
-	if (ret)
-		return ret;
+	error = platform_driver_register(&sonypi_driver);
+	if (error)
+		return error;
+
+	sonypi_platform_device = platform_device_alloc("sonypi", -1);
+	if (!sonypi_platform_device) {
+		error = -ENOMEM;
+		goto err_driver_unregister;
+	}
 
-	ret = sonypi_probe();
-	if (ret)
-		platform_driver_unregister(&sonypi_driver);
+	error = platform_device_add(sonypi_platform_device);
+	if (error)
+		goto err_free_device;
 
-	return ret;
+	return 0;
+
+ err_free_device:
+	platform_device_put(sonypi_platform_device);
+ err_driver_unregister:
+	platform_driver_unregister(&sonypi_driver);
+	return error;
 }
 
 static void __exit sonypi_exit(void)
 {
+	platform_device_unregister(sonypi_platform_device);
 	platform_driver_unregister(&sonypi_driver);
-	sonypi_remove();
+	printk(KERN_INFO "sonypi: removed.\n");
 }
 
 module_init(sonypi_init);

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-13  7:19 [RFT] Sonypi: convert to the new platform device interface Dmitry Torokhov
@ 2005-12-13 18:32 ` Mattia Dongili
  2005-12-13 19:04   ` Dmitry Torokhov
  0 siblings, 1 reply; 15+ messages in thread
From: Mattia Dongili @ 2005-12-13 18:32 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: LKML, Stelian Pop

On Tue, Dec 13, 2005 at 02:19:40AM -0500, Dmitry Torokhov wrote:
> Hi,
> 
> Now that we allow manual binding and unbinding devices through sysfs it
> is better if main device initialization is done in ->probe() instead of
> module_init(). The following patch converts sonypi driver to this model.
> 
> The patch compiles but I was unable to test it since I don't have the
> hardware...
[...]
> +static int __devinit sonypi_setup_irq(struct sonypi_device *dev,
> +				      const struct sonypi_irq_list *irq_list)
> +{
> +	while (irq_list->irq) {
> +
> +		if (!request_irq(dev->irq, sonypi_irq,
                                 ^^^^^^^^
this should be irq_list->irq

other than that seems to work here on a type2 model:

sonypi: Sony Programmable I/O Controller Driver v1.26.
sonypi: trying irq 11
input: Sony Vaio Jogdial as /class/input/input8
input: Sony Vaio Keys as /class/input/input9
sonypi: detected type2 model, verbose = 1, fnkeyinit = off, camera = off, compat = off, mask = 0xffffffff, useinput = on, acpi = on
sonypi: enabled at irq=11, port1=0x1080, port2=0x1084
sonypi: device allocated minor is 63
sonypi: unknown event port1=0x0f,port2=0x05

Oh, there seems to be a spurious interrupt happening at modules
insertion (I suspect sonypi_enable triggering and ignoring it), but this
happens with the old module too and I never noticed it before. Wouldn't
make more sense to print the warning even if verbose=0 to be able to
catch it timely? I mean it's since 2.4 times I don't enable verbose mode
in sonypi...

-- 
mattia
:wq!

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-13 18:32 ` Mattia Dongili
@ 2005-12-13 19:04   ` Dmitry Torokhov
  2005-12-13 20:30     ` sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface) Stelian Pop
  2005-12-25 21:09     ` [RFT] Sonypi: convert to the new platform device interface Jan Engelhardt
  0 siblings, 2 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2005-12-13 19:04 UTC (permalink / raw)
  To: Dmitry Torokhov, LKML, Stelian Pop

On 12/13/05, Mattia Dongili <malattia@linux.it> wrote:
> On Tue, Dec 13, 2005 at 02:19:40AM -0500, Dmitry Torokhov wrote:
> > Hi,
> >
> > Now that we allow manual binding and unbinding devices through sysfs it
> > is better if main device initialization is done in ->probe() instead of
> > module_init(). The following patch converts sonypi driver to this model.
> >
> > The patch compiles but I was unable to test it since I don't have the
> > hardware...
> [...]
> > +static int __devinit sonypi_setup_irq(struct sonypi_device *dev,
> > +                                   const struct sonypi_irq_list *irq_list)
> > +{
> > +     while (irq_list->irq) {
> > +
> > +             if (!request_irq(dev->irq, sonypi_irq,
>                                 ^^^^^^^^
> this should be irq_list->irq
>
> other than that seems to work here on a type2 model:
>
> sonypi: Sony Programmable I/O Controller Driver v1.26.
> sonypi: trying irq 11
> input: Sony Vaio Jogdial as /class/input/input8
> input: Sony Vaio Keys as /class/input/input9
> sonypi: detected type2 model, verbose = 1, fnkeyinit = off, camera = off, compat = off, mask = 0xffffffff, useinput = on, acpi = on
> sonypi: enabled at irq=11, port1=0x1080, port2=0x1084
> sonypi: device allocated minor is 63
> sonypi: unknown event port1=0x0f,port2=0x05
>

Thank you very much for testing and debugging the patch. I will fix
the irq thing and repost.

> Oh, there seems to be a spurious interrupt happening at modules
> insertion (I suspect sonypi_enable triggering and ignoring it), but this
> happens with the old module too and I never noticed it before. Wouldn't
> make more sense to print the warning even if verbose=0 to be able to
> catch it timely? I mean it's since 2.4 times I don't enable verbose mode
> in sonypi...
>

Probably, let's see what Stelian will say.

--
Dmitry

^ permalink raw reply	[flat|nested] 15+ messages in thread

* sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface)
  2005-12-13 19:04   ` Dmitry Torokhov
@ 2005-12-13 20:30     ` Stelian Pop
  2005-12-13 20:48       ` Dmitry Torokhov
  2005-12-25 21:09     ` [RFT] Sonypi: convert to the new platform device interface Jan Engelhardt
  1 sibling, 1 reply; 15+ messages in thread
From: Stelian Pop @ 2005-12-13 20:30 UTC (permalink / raw)
  To: dtor_core; +Cc: Mattia Dongili, LKML

Le mardi 13 décembre 2005 à 14:04 -0500, Dmitry Torokhov a écrit :

> On 12/13/05, Mattia Dongili <malattia@linux.it> wrote:
>                            ^^^^^^^^
> > this should be irq_list->irq
> >
> > other than that seems to work here on a type2 model:

Thanks you very much for testing Mattia. Oh, and thanks to you too
Dmitry for your continuous maintenance :)

This is probably an appropriate moment to announce my resignation from
the sonypi maintainership.

After five years, I found myself less and less interested in working on
this driver, and more and more frustrated by the Sony complete lack of
support. They ignored all the requests for documentation I and several
others made, both from outside and from inside Sony. They also keep
changing the hardware interfaces, so it has become increasingly
difficult to support the newer Vaios in sonypi. 

At this point, I wouldn't recommend anyone buying a Sony laptop. Other
manufacturers are more Linux-friendly and overall their laptops are much
better supported under Linux than the Sony's.

I already did the switch myself a few months ago, buying an Apple
Powerbook, and today I am very glad I did.

I am still answering to the sonypi related questions for the time being
but if someone is interested in taking over, just contact me. Otherwise,
I will submit a patch marking the driver as unmaintained in a few days.
 
The meye driver (MotionEye camera for the PictureBook C1 series) is also
going the same path, but since the hardware is not produced anymore (and
hasn't been for a long time now), I don't expect it to find another
maintainer.

> > sonypi: unknown event port1=0x0f,port2=0x05
[...]
> > Oh, there seems to be a spurious interrupt happening at modules
> > insertion (I suspect sonypi_enable triggering and ignoring it), but this
> > happens with the old module too and I never noticed it before. Wouldn't
> > make more sense to print the warning even if verbose=0 to be able to
> > catch it timely? I mean it's since 2.4 times I don't enable verbose mode
> > in sonypi...
> >
> Probably, let's see what Stelian will say.

This is the "ok I'm loaded" event. I am not sure this event is available
on all the sonypi supported platforms, that's why it hasn't been defined
as a known event. And it doesn't make much sense to forward it anyways.

I would leave it like it is now.

Stelian.
-- 
Stelian Pop <stelian@popies.net>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface)
  2005-12-13 20:30     ` sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface) Stelian Pop
@ 2005-12-13 20:48       ` Dmitry Torokhov
  2005-12-13 21:55         ` Stelian Pop
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2005-12-13 20:48 UTC (permalink / raw)
  To: Stelian Pop; +Cc: Mattia Dongili, LKML

On 12/13/05, Stelian Pop <stelian@popies.net> wrote:
> Le mardi 13 décembre 2005 à 14:04 -0500, Dmitry Torokhov a >
> > > sonypi: unknown event port1=0x0f,port2=0x05
> [...]
> > > Oh, there seems to be a spurious interrupt happening at modules
> > > insertion (I suspect sonypi_enable triggering and ignoring it), but this
> > > happens with the old module too and I never noticed it before. Wouldn't
> > > make more sense to print the warning even if verbose=0 to be able to
> > > catch it timely? I mean it's since 2.4 times I don't enable verbose mode
> > > in sonypi...
> > >
> > Probably, let's see what Stelian will say.
>
> This is the "ok I'm loaded" event. I am not sure this event is available
> on all the sonypi supported platforms, that's why it hasn't been defined
> as a known event. And it doesn't make much sense to forward it anyways.
>
> I would leave it like it is now.
>

But when it is reported is it the same event? If so we could just not
warn when we see it (but still dont forward it to the userspace).

--
Dmitry

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface)
  2005-12-13 20:48       ` Dmitry Torokhov
@ 2005-12-13 21:55         ` Stelian Pop
  2005-12-13 22:06           ` Dmitry Torokhov
  0 siblings, 1 reply; 15+ messages in thread
From: Stelian Pop @ 2005-12-13 21:55 UTC (permalink / raw)
  To: dtor_core; +Cc: Mattia Dongili, LKML

Le mardi 13 décembre 2005 à 15:48 -0500, Dmitry Torokhov a écrit :
> On 12/13/05, Stelian Pop <stelian@popies.net> wrote:
> > Le mardi 13 décembre 2005 à 14:04 -0500, Dmitry Torokhov a >
> > > > sonypi: unknown event port1=0x0f,port2=0x05
> > [...]
> > > > Oh, there seems to be a spurious interrupt happening at modules
> > > > insertion (I suspect sonypi_enable triggering and ignoring it), but this
> > > > happens with the old module too and I never noticed it before. Wouldn't
> > > > make more sense to print the warning even if verbose=0 to be able to
> > > > catch it timely? I mean it's since 2.4 times I don't enable verbose mode
> > > > in sonypi...
> > > >
> > > Probably, let's see what Stelian will say.
> >
> > This is the "ok I'm loaded" event. I am not sure this event is available
> > on all the sonypi supported platforms, that's why it hasn't been defined
> > as a known event. And it doesn't make much sense to forward it anyways.
> >
> > I would leave it like it is now.
> >
> 
> But when it is reported is it the same event? 

I don't follow you here... 

> If so we could just not
> warn when we see it (but still dont forward it to the userspace).

The warning is only present if 'verbose > 0', so in normal conditions
you won't see it.

Stelian.
-- 
Stelian Pop <stelian@popies.net>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface)
  2005-12-13 21:55         ` Stelian Pop
@ 2005-12-13 22:06           ` Dmitry Torokhov
  2005-12-14  6:46             ` Stelian Pop
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2005-12-13 22:06 UTC (permalink / raw)
  To: Stelian Pop; +Cc: Mattia Dongili, LKML

On 12/13/05, Stelian Pop <stelian@popies.net> wrote:
> Le mardi 13 décembre 2005 à 15:48 -0500, Dmitry Torokhov a écrit :
> > On 12/13/05, Stelian Pop <stelian@popies.net> wrote:
> > > Le mardi 13 décembre 2005 à 14:04 -0500, Dmitry Torokhov a >
> > > > > sonypi: unknown event port1=0x0f,port2=0x05
> > > [...]
> > > > > Oh, there seems to be a spurious interrupt happening at modules
> > > > > insertion (I suspect sonypi_enable triggering and ignoring it), but this
> > > > > happens with the old module too and I never noticed it before. Wouldn't
> > > > > make more sense to print the warning even if verbose=0 to be able to
> > > > > catch it timely? I mean it's since 2.4 times I don't enable verbose mode
> > > > > in sonypi...
> > > > >
> > > > Probably, let's see what Stelian will say.
> > >
> > > This is the "ok I'm loaded" event. I am not sure this event is available
> > > on all the sonypi supported platforms, that's why it hasn't been defined
> > > as a known event. And it doesn't make much sense to forward it anyways.
> > >
> > > I would leave it like it is now.
> > >
> >
> > But when it is reported is it the same event?
>
> I don't follow you here...
>

I was talking about that "ok, i'm loaded" event. When it is reported
is it the same v1,v2 pair all the time? If it is the same we could
suppress "unknown" message in verbose mode.

--
Dmitry

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface)
  2005-12-13 22:06           ` Dmitry Torokhov
@ 2005-12-14  6:46             ` Stelian Pop
  0 siblings, 0 replies; 15+ messages in thread
From: Stelian Pop @ 2005-12-14  6:46 UTC (permalink / raw)
  To: dtor_core; +Cc: Mattia Dongili, LKML

Le mardi 13 décembre 2005 à 17:06 -0500, Dmitry Torokhov a écrit :
> On 12/13/05, Stelian Pop <stelian@popies.net> wrote:
> > Le mardi 13 décembre 2005 à 15:48 -0500, Dmitry Torokhov a écrit :
> > > On 12/13/05, Stelian Pop <stelian@popies.net> wrote:
> > > > Le mardi 13 décembre 2005 à 14:04 -0500, Dmitry Torokhov a >
> > > > > > sonypi: unknown event port1=0x0f,port2=0x05
> > > > [...]
> > > > > > Oh, there seems to be a spurious interrupt happening at modules
> > > > > > insertion (I suspect sonypi_enable triggering and ignoring it), but this
> > > > > > happens with the old module too and I never noticed it before. Wouldn't
> > > > > > make more sense to print the warning even if verbose=0 to be able to
> > > > > > catch it timely? I mean it's since 2.4 times I don't enable verbose mode
> > > > > > in sonypi...
> > > > > >
> > > > > Probably, let's see what Stelian will say.
> > > >
> > > > This is the "ok I'm loaded" event. I am not sure this event is available
> > > > on all the sonypi supported platforms, that's why it hasn't been defined
> > > > as a known event. And it doesn't make much sense to forward it anyways.
> > > >
> > > > I would leave it like it is now.
> > > >
> > >
> > > But when it is reported is it the same event?
> >
> > I don't follow you here...
> >
> 
> I was talking about that "ok, i'm loaded" event. When it is reported
> is it the same v1,v2 pair all the time?

I have no idea. That's one of the problems with the sonypi events:
different laptops behave differently, and sometimes Sony even changes
the meaning of some events...

>  If it is the same we could
> suppress "unknown" message in verbose mode.

Why would you want to suppress a message in verbose mode ? The verbose
option is there exactly for that: show the user all the data coming from
the hardware, and depending on the verbose value only show the data
which hasn't been decoded, or all of it.

I don't think that adding a special hack for this event in an already
hacky driver has some added value.

Stelian.
-- 
Stelian Pop <stelian@popies.net>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-13 19:04   ` Dmitry Torokhov
  2005-12-13 20:30     ` sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface) Stelian Pop
@ 2005-12-25 21:09     ` Jan Engelhardt
  2005-12-25 21:17       ` Dmitry Torokhov
  1 sibling, 1 reply; 15+ messages in thread
From: Jan Engelhardt @ 2005-12-25 21:09 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: LKML, Stelian Pop


>> > The patch compiles but I was unable to test it since I don't have the
>> > hardware...
>>
>> other than that seems to work here on a type2 model:

It does not work here on a SONY VAIO U3. After loading the sonypi module, 
neither mev nor showkey return something for the special stuff like 
jogwheel, jogbutton or Fn keys respectively.

Running 2.6.15-rc7, this appeared in the kernel log:
Dec 25 22:06:14 takeshi kernel: sonypi: request_irq failed


Jan Engelhardt
-- 
| Alphagate Systems, http://alphagate.hopto.org/
| jengelh's site, http://jengelh.hopto.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-25 21:09     ` [RFT] Sonypi: convert to the new platform device interface Jan Engelhardt
@ 2005-12-25 21:17       ` Dmitry Torokhov
  2005-12-27 18:02         ` Jan Engelhardt
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2005-12-25 21:17 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: LKML, Stelian Pop

On Sunday 25 December 2005 16:09, Jan Engelhardt wrote:
> 
> >> > The patch compiles but I was unable to test it since I don't have the
> >> > hardware...
> >>
> >> other than that seems to work here on a type2 model:
> 
> It does not work here on a SONY VAIO U3. After loading the sonypi module, 
> neither mev nor showkey return something for the special stuff like 
> jogwheel, jogbutton or Fn keys respectively.
> 
> Running 2.6.15-rc7, this appeared in the kernel log:
> Dec 25 22:06:14 takeshi kernel: sonypi: request_irq failed
> 

Jan,

You did make the changes Maattia Dongili was talking about, didn't you?
Just in case I am sending corrected patch.

-- 
Dmitry

Sonypi: convert to the new platform device interface

Do not use platform_device_register_simple() as it is going away,
implement ->probe() and ->remove() functions so manual binding and
unbinding will work with this driver.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/char/sonypi.c |  358 ++++++++++++++++++++++++++++----------------------
 1 files changed, 206 insertions(+), 152 deletions(-)

Index: work/drivers/char/sonypi.c
===================================================================
--- work.orig/drivers/char/sonypi.c
+++ work/drivers/char/sonypi.c
@@ -471,7 +471,6 @@ struct sonypi_keypress {
 
 static struct sonypi_device {
 	struct pci_dev *dev;
-	struct platform_device *pdev;
 	u16 irq;
 	u16 bits;
 	u16 ioport1;
@@ -1165,45 +1164,12 @@ static int sonypi_disable(void)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int old_camera_power;
-
-static int sonypi_suspend(struct platform_device *dev, pm_message_t state)
-{
-	old_camera_power = sonypi_device.camera_power;
-	sonypi_disable();
-
-	return 0;
-}
-
-static int sonypi_resume(struct platform_device *dev)
-{
-	sonypi_enable(old_camera_power);
-	return 0;
-}
-#endif
-
-static void sonypi_shutdown(struct platform_device *dev)
-{
-	sonypi_disable();
-}
-
-static struct platform_driver sonypi_driver = {
-#ifdef CONFIG_PM
-	.suspend	= sonypi_suspend,
-	.resume		= sonypi_resume,
-#endif
-	.shutdown	= sonypi_shutdown,
-	.driver		= {
-		.name	= "sonypi",
-	},
-};
-
 static int __devinit sonypi_create_input_devices(void)
 {
 	struct input_dev *jog_dev;
 	struct input_dev *key_dev;
 	int i;
+	int error;
 
 	sonypi_device.input_jog_dev = jog_dev = input_allocate_device();
 	if (!jog_dev)
@@ -1219,9 +1185,8 @@ static int __devinit sonypi_create_input
 
 	sonypi_device.input_key_dev = key_dev = input_allocate_device();
 	if (!key_dev) {
-		input_free_device(jog_dev);
-		sonypi_device.input_jog_dev = NULL;
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto err_free_jogdev;
 	}
 
 	key_dev->name = "Sony Vaio Keys";
@@ -1234,56 +1199,122 @@ static int __devinit sonypi_create_input
 		if (sonypi_inputkeys[i].inputev)
 			set_bit(sonypi_inputkeys[i].inputev, key_dev->keybit);
 
-	input_register_device(jog_dev);
-	input_register_device(key_dev);
+	error = input_register_device(jog_dev);
+	if (error)
+		goto err_free_keydev;
+
+	error = input_register_device(key_dev);
+	if (error)
+		goto err_unregister_jogdev;
 
 	return 0;
+
+ err_unregister_jogdev:
+	input_unregister_device(jog_dev);
+	/* Set to NULL so we don't free it again below */
+	jog_dev = NULL;
+ err_free_keydev:
+	input_free_device(key_dev);
+	sonypi_device.input_key_dev = NULL;
+ err_free_jogdev:
+	input_free_device(jog_dev);
+	sonypi_device.input_jog_dev = NULL;
+
+	return error;
 }
 
-static int __devinit sonypi_probe(void)
+static int __devinit sonypi_setup_ioports(struct sonypi_device *dev,
+				const struct sonypi_ioport_list *ioport_list)
 {
-	int i, ret;
-	struct sonypi_ioport_list *ioport_list;
-	struct sonypi_irq_list *irq_list;
-	struct pci_dev *pcidev;
+	while (ioport_list->port1) {
 
-	if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				     PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
-		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
-	else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-					  PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
-		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE3;
-	else
-		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
+		if (request_region(ioport_list->port1,
+				   sonypi_device.region_size,
+				   "Sony Programable I/O Device")) {
+			dev->ioport1 = ioport_list->port1;
+			dev->ioport2 = ioport_list->port2;
+			return 0;
+		}
+		ioport_list++;
+	}
 
-	sonypi_device.dev = pcidev;
+	return -EBUSY;
+}
+
+static int __devinit sonypi_setup_irq(struct sonypi_device *dev,
+				      const struct sonypi_irq_list *irq_list)
+{
+	while (irq_list->irq) {
+
+		if (!request_irq(irq_list->irq, sonypi_irq,
+				 SA_SHIRQ, "sonypi", sonypi_irq)) {
+			dev->irq = irq_list->irq;
+			dev->bits = irq_list->bits;
+			return 0;
+		}
+		irq_list++;
+	}
+
+	return -EBUSY;
+}
+
+static void __devinit sonypi_display_info(void)
+{
+	printk(KERN_INFO "sonypi: detected type%d model, "
+	       "verbose = %d, fnkeyinit = %s, camera = %s, "
+	       "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
+	       sonypi_device.model,
+	       verbose,
+	       fnkeyinit ? "on" : "off",
+	       camera ? "on" : "off",
+	       compat ? "on" : "off",
+	       mask,
+	       useinput ? "on" : "off",
+	       SONYPI_ACPI_ACTIVE ? "on" : "off");
+	printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
+	       sonypi_device.irq,
+	       sonypi_device.ioport1, sonypi_device.ioport2);
+
+	if (minor == -1)
+		printk(KERN_INFO "sonypi: device allocated minor is %d\n",
+		       sonypi_misc_device.minor);
+}
+
+static int __devinit sonypi_probe(struct platform_device *dev)
+{
+	const struct sonypi_ioport_list *ioport_list;
+	const struct sonypi_irq_list *irq_list;
+	struct pci_dev *pcidev;
+	int error;
 
 	spin_lock_init(&sonypi_device.fifo_lock);
 	sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
 					 &sonypi_device.fifo_lock);
 	if (IS_ERR(sonypi_device.fifo)) {
 		printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
-		ret = PTR_ERR(sonypi_device.fifo);
-		goto out_fifo;
+		return PTR_ERR(sonypi_device.fifo);
 	}
 
 	init_waitqueue_head(&sonypi_device.fifo_proc_list);
 	init_MUTEX(&sonypi_device.lock);
 	sonypi_device.bluetooth_power = -1;
 
+	if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+				     PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
+		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
+	else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
+					  PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
+		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE3;
+	else
+		sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
+
 	if (pcidev && pci_enable_device(pcidev)) {
 		printk(KERN_ERR "sonypi: pci_enable_device failed\n");
-		ret = -EIO;
-		goto out_pcienable;
-	}
-
-	if (minor != -1)
-		sonypi_misc_device.minor = minor;
-	if ((ret = misc_register(&sonypi_misc_device))) {
-		printk(KERN_ERR "sonypi: misc_register failed\n");
-		goto out_miscreg;
+		error = -EIO;
+		goto err_put_pcidev;
 	}
 
+	sonypi_device.dev = pcidev;
 
 	if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) {
 		ioport_list = sonypi_type1_ioport_list;
@@ -1302,43 +1333,36 @@ static int __devinit sonypi_probe(void)
 		irq_list = sonypi_type3_irq_list;
 	}
 
-	for (i = 0; ioport_list[i].port1; i++) {
-		if (request_region(ioport_list[i].port1,
-				   sonypi_device.region_size,
-				   "Sony Programable I/O Device")) {
-			/* get the ioport */
-			sonypi_device.ioport1 = ioport_list[i].port1;
-			sonypi_device.ioport2 = ioport_list[i].port2;
-			break;
-		}
-	}
-	if (!sonypi_device.ioport1) {
-		printk(KERN_ERR "sonypi: request_region failed\n");
-		ret = -ENODEV;
-		goto out_reqreg;
+	error = sonypi_setup_ioports(&sonypi_device, ioport_list);
+	if (error) {
+		printk(KERN_ERR "sonypi: failed to request ioports\n");
+		goto err_disable_pcidev;
 	}
 
-	for (i = 0; irq_list[i].irq; i++) {
-
-		sonypi_device.irq = irq_list[i].irq;
-		sonypi_device.bits = irq_list[i].bits;
-
-		if (!request_irq(sonypi_device.irq, sonypi_irq,
-				 SA_SHIRQ, "sonypi", sonypi_irq))
-			break;
+	error = sonypi_setup_irq(&sonypi_device, irq_list);
+	if (error) {
+		printk(KERN_ERR "sonypi: request_irq failed\n");
+		goto err_free_ioports;
 	}
 
-	if (!irq_list[i].irq) {
-		printk(KERN_ERR "sonypi: request_irq failed\n");
-		ret = -ENODEV;
-		goto out_reqirq;
+	if (minor != -1)
+		sonypi_misc_device.minor = minor;
+	error = misc_register(&sonypi_misc_device);
+	if (error) {
+		printk(KERN_ERR "sonypi: misc_register failed\n");
+		goto err_free_irq;
 	}
 
+	sonypi_display_info();
+
 	if (useinput) {
 
-		ret = sonypi_create_input_devices();
-		if (ret)
-			goto out_inputdevices;
+		error = sonypi_create_input_devices();
+		if (error) {
+			printk(KERN_ERR
+				"sonypi: failed to create input devices\n");
+			goto err_miscdev_unregister;
+		}
 
 		spin_lock_init(&sonypi_device.input_fifo_lock);
 		sonypi_device.input_fifo =
@@ -1346,90 +1370,103 @@ static int __devinit sonypi_probe(void)
 				    &sonypi_device.input_fifo_lock);
 		if (IS_ERR(sonypi_device.input_fifo)) {
 			printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
-			ret = PTR_ERR(sonypi_device.input_fifo);
-			goto out_infifo;
+			error = PTR_ERR(sonypi_device.input_fifo);
+			goto err_inpdev_unregister;
 		}
 
 		INIT_WORK(&sonypi_device.input_work, input_keyrelease, NULL);
 	}
 
-	sonypi_device.pdev = platform_device_register_simple("sonypi", -1,
-							     NULL, 0);
-	if (IS_ERR(sonypi_device.pdev)) {
-		ret = PTR_ERR(sonypi_device.pdev);
-		goto out_platformdev;
-	}
-
 	sonypi_enable(0);
 
-	printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver"
-	       "v%s.\n", SONYPI_DRIVER_VERSION);
-	printk(KERN_INFO "sonypi: detected type%d model, "
-	       "verbose = %d, fnkeyinit = %s, camera = %s, "
-	       "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
-	       sonypi_device.model,
-	       verbose,
-	       fnkeyinit ? "on" : "off",
-	       camera ? "on" : "off",
-	       compat ? "on" : "off",
-	       mask,
-	       useinput ? "on" : "off",
-	       SONYPI_ACPI_ACTIVE ? "on" : "off");
-	printk(KERN_INFO "sonypi: enabled at irq=%d, port1=0x%x, port2=0x%x\n",
-	       sonypi_device.irq,
-	       sonypi_device.ioport1, sonypi_device.ioport2);
-
-	if (minor == -1)
-		printk(KERN_INFO "sonypi: device allocated minor is %d\n",
-		       sonypi_misc_device.minor);
-
 	return 0;
 
-out_platformdev:
-	kfifo_free(sonypi_device.input_fifo);
-out_infifo:
+ err_inpdev_unregister:
 	input_unregister_device(sonypi_device.input_key_dev);
 	input_unregister_device(sonypi_device.input_jog_dev);
-out_inputdevices:
+ err_miscdev_unregister:
+	misc_deregister(&sonypi_misc_device);
+ err_free_irq:
 	free_irq(sonypi_device.irq, sonypi_irq);
-out_reqirq:
+ err_free_ioports:
 	release_region(sonypi_device.ioport1, sonypi_device.region_size);
-out_reqreg:
-	misc_deregister(&sonypi_misc_device);
-out_miscreg:
+ err_disable_pcidev:
 	if (pcidev)
 		pci_disable_device(pcidev);
-out_pcienable:
+ err_put_pcidev:
+	pci_dev_put(pcidev);
 	kfifo_free(sonypi_device.fifo);
-out_fifo:
-	pci_dev_put(sonypi_device.dev);
-	return ret;
+
+	return error;
 }
 
-static void __devexit sonypi_remove(void)
+static int __devexit sonypi_remove(struct platform_device *dev)
 {
 	sonypi_disable();
 
 	synchronize_sched();  /* Allow sonypi interrupt to complete. */
 	flush_scheduled_work();
 
-	platform_device_unregister(sonypi_device.pdev);
-
 	if (useinput) {
 		input_unregister_device(sonypi_device.input_key_dev);
 		input_unregister_device(sonypi_device.input_jog_dev);
 		kfifo_free(sonypi_device.input_fifo);
 	}
 
+	misc_deregister(&sonypi_misc_device);
+
 	free_irq(sonypi_device.irq, sonypi_irq);
 	release_region(sonypi_device.ioport1, sonypi_device.region_size);
-	misc_deregister(&sonypi_misc_device);
-	if (sonypi_device.dev)
+
+	if (sonypi_device.dev) {
 		pci_disable_device(sonypi_device.dev);
+		pci_dev_put(sonypi_device.dev);
+	}
+
 	kfifo_free(sonypi_device.fifo);
-	pci_dev_put(sonypi_device.dev);
-	printk(KERN_INFO "sonypi: removed.\n");
+
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int old_camera_power;
+
+static int sonypi_suspend(struct platform_device *dev, pm_message_t state)
+{
+	old_camera_power = sonypi_device.camera_power;
+	sonypi_disable();
+
+	return 0;
+}
+
+static int sonypi_resume(struct platform_device *dev)
+{
+	sonypi_enable(old_camera_power);
+	return 0;
 }
+#else
+#define sonypi_suspend	NULL
+#define sonypi_resume	NULL
+#endif
+
+static void sonypi_shutdown(struct platform_device *dev)
+{
+	sonypi_disable();
+}
+
+static struct platform_driver sonypi_driver = {
+	.driver		= {
+		.name	= "sonypi",
+		.owner	= THIS_MODULE,
+	},
+	.probe		= sonypi_probe,
+	.remove		= __devexit_p(sonypi_remove),
+	.shutdown	= sonypi_shutdown,
+	.suspend	= sonypi_suspend,
+	.resume		= sonypi_resume,
+};
+
+static struct platform_device *sonypi_platform_device;
 
 static struct dmi_system_id __initdata sonypi_dmi_table[] = {
 	{
@@ -1451,26 +1488,43 @@ static struct dmi_system_id __initdata s
 
 static int __init sonypi_init(void)
 {
-	int ret;
+	int error;
+
+	printk(KERN_INFO
+		"sonypi: Sony Programmable I/O Controller Driver v%s.\n",
+		SONYPI_DRIVER_VERSION);
 
 	if (!dmi_check_system(sonypi_dmi_table))
 		return -ENODEV;
 
-	ret = platform_driver_register(&sonypi_driver);
-	if (ret)
-		return ret;
+	error = platform_driver_register(&sonypi_driver);
+	if (error)
+		return error;
+
+	sonypi_platform_device = platform_device_alloc("sonypi", -1);
+	if (!sonypi_platform_device) {
+		error = -ENOMEM;
+		goto err_driver_unregister;
+	}
 
-	ret = sonypi_probe();
-	if (ret)
-		platform_driver_unregister(&sonypi_driver);
+	error = platform_device_add(sonypi_platform_device);
+	if (error)
+		goto err_free_device;
 
-	return ret;
+	return 0;
+
+ err_free_device:
+	platform_device_put(sonypi_platform_device);
+ err_driver_unregister:
+	platform_driver_unregister(&sonypi_driver);
+	return error;
 }
 
 static void __exit sonypi_exit(void)
 {
+	platform_device_unregister(sonypi_platform_device);
 	platform_driver_unregister(&sonypi_driver);
-	sonypi_remove();
+	printk(KERN_INFO "sonypi: removed.\n");
 }
 
 module_init(sonypi_init);



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-25 21:17       ` Dmitry Torokhov
@ 2005-12-27 18:02         ` Jan Engelhardt
  2005-12-27 22:18           ` Dmitry Torokhov
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Engelhardt @ 2005-12-27 18:02 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: LKML, Stelian Pop

>> It does not work here on a SONY VAIO U3. After loading the sonypi module, 
>> neither mev nor showkey return something for the special stuff like 
>> jogwheel, jogbutton or Fn keys respectively.
>> 
>> Running 2.6.15-rc7, this appeared in the kernel log:
>> Dec 25 22:06:14 takeshi kernel: sonypi: request_irq failed
>
>Just in case I am sending corrected patch.
>
Ok now it works. (Just like with the old sonypi :-)

However, there are some things that remain unresolved:
- the "mousewheel" reports only once every 2 seconds when constantly
  wheeling (in mev)
- pressing the jogdial button produces a keyboard event (keycode 158) 
  rather than a mousebutton 3 event

BTW, how can I use the Fn keys on console (keycodes 466-477) for arbitrary 
shell commands?
Such a feature, among which special combinations like Ctrl+Alt+Del also 
belong, are handled by the kernel which leaves almost no room for 
user-defined userspace action. Any idea?



Jan Engelhardt
-- 
| Alphagate Systems, http://alphagate.hopto.org/
| jengelh's site, http://jengelh.hopto.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-27 18:02         ` Jan Engelhardt
@ 2005-12-27 22:18           ` Dmitry Torokhov
  2005-12-27 22:53             ` Stelian Pop
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Torokhov @ 2005-12-27 22:18 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: LKML, Stelian Pop

On 12/27/05, Jan Engelhardt <jengelh@linux01.gwdg.de> wrote:
> >> It does not work here on a SONY VAIO U3. After loading the sonypi module,
> >> neither mev nor showkey return something for the special stuff like
> >> jogwheel, jogbutton or Fn keys respectively.
> >>
> >> Running 2.6.15-rc7, this appeared in the kernel log:
> >> Dec 25 22:06:14 takeshi kernel: sonypi: request_irq failed
> >
> >Just in case I am sending corrected patch.
> >
> Ok now it works. (Just like with the old sonypi :-)
>

The issues enumerated below are existed before my patch, did I
understand this correctly?

> However, there are some things that remain unresolved:
> - the "mousewheel" reports only once every 2 seconds when constantly
>  wheeling (in mev)
> - pressing the jogdial button produces a keyboard event (keycode 158)
>  rather than a mousebutton 3 event
>

158 is KEY_BACK and is generated on type2 models.. If you load the
driver with verbose=1 what does it say when you press jog dial?

> BTW, how can I use the Fn keys on console (keycodes 466-477) for arbitrary
> shell commands?
> Such a feature, among which special combinations like Ctrl+Alt+Del also
> belong, are handled by the kernel which leaves almost no room for
> user-defined userspace action. Any idea?
>

There are daemons that read corersponding /dev/input/eventX and act on
it. The in-kernel keyboard driver ignores keycodes above 255.

--
Dmitry

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-27 22:18           ` Dmitry Torokhov
@ 2005-12-27 22:53             ` Stelian Pop
  2006-01-15 20:48               ` Jan Engelhardt
  0 siblings, 1 reply; 15+ messages in thread
From: Stelian Pop @ 2005-12-27 22:53 UTC (permalink / raw)
  To: dtor_core; +Cc: Jan Engelhardt, LKML

Le mardi 27 décembre 2005 à 17:18 -0500, Dmitry Torokhov a écrit :

> > However, there are some things that remain unresolved:
> > - the "mousewheel" reports only once every 2 seconds when constantly
> >  wheeling (in mev)

could be because scrolling the wheel generates several kinds of events
(up, down but also fast up, fast down etc), and only some of them get
interpreted. Verify the events by using the verbose=1 parameter.

> > - pressing the jogdial button produces a keyboard event (keycode 158)
> >  rather than a mousebutton 3 event
> >
> 158 is KEY_BACK and is generated on type2 models.. If you load the
> driver with verbose=1 what does it say when you press jog dial?

If you don't have a Back button then you can adjust the 'mask' module
parameter in order to detect only the events you are interested in. And
before you ask yes, Sony reused the same codes for several types of
events...

> > BTW, how can I use the Fn keys on console (keycodes 466-477) for arbitrary
> > shell commands?
> > Such a feature, among which special combinations like Ctrl+Alt+Del also
> > belong, are handled by the kernel which leaves almost no room for
> > user-defined userspace action. Any idea?
> >
> There are daemons that read corersponding /dev/input/eventX and act on
> it. The in-kernel keyboard driver ignores keycodes above 255.

And also daemons more sonypi specific which read /dev/sonypi instead,
like sonypid, sonypidd, jogdiald, kde etc.

Stelian.
-- 
Stelian Pop <stelian@popies.net>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2005-12-27 22:53             ` Stelian Pop
@ 2006-01-15 20:48               ` Jan Engelhardt
  2006-01-16  4:48                 ` Dmitry Torokhov
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Engelhardt @ 2006-01-15 20:48 UTC (permalink / raw)
  To: Stelian Pop; +Cc: dtor_core, LKML


On Dec 27 2005 23:53, Stelian Pop wrote:

>[sonypi3]


When is this going to be merged?


Jan Engelhardt
-- 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFT] Sonypi: convert to the new platform device interface
  2006-01-15 20:48               ` Jan Engelhardt
@ 2006-01-16  4:48                 ` Dmitry Torokhov
  0 siblings, 0 replies; 15+ messages in thread
From: Dmitry Torokhov @ 2006-01-16  4:48 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Stelian Pop, LKML

On Sunday 15 January 2006 15:48, Jan Engelhardt wrote:
> 
> On Dec 27 2005 23:53, Stelian Pop wrote:
> 
> >[sonypi3]
> 
> 
> When is this going to be merged?
>

It's in Linus's tree.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-01-16  4:48 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-13  7:19 [RFT] Sonypi: convert to the new platform device interface Dmitry Torokhov
2005-12-13 18:32 ` Mattia Dongili
2005-12-13 19:04   ` Dmitry Torokhov
2005-12-13 20:30     ` sonypi searching new maintainer (Was: Re: [RFT] Sonypi: convert to the new platform device interface) Stelian Pop
2005-12-13 20:48       ` Dmitry Torokhov
2005-12-13 21:55         ` Stelian Pop
2005-12-13 22:06           ` Dmitry Torokhov
2005-12-14  6:46             ` Stelian Pop
2005-12-25 21:09     ` [RFT] Sonypi: convert to the new platform device interface Jan Engelhardt
2005-12-25 21:17       ` Dmitry Torokhov
2005-12-27 18:02         ` Jan Engelhardt
2005-12-27 22:18           ` Dmitry Torokhov
2005-12-27 22:53             ` Stelian Pop
2006-01-15 20:48               ` Jan Engelhardt
2006-01-16  4:48                 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).