Commit a7d801afc3d4d1c8aaa0449f17b9f9ce62e16236

Authored by Jean Delvare
Committed by Linus Torvalds
1 parent c15a3837d2

legacy PC parports support parport->dev

Give legacy parallel ports a platform device in the device tree.

This is a quick and dirty implementation; it doesn't actually convert the
legacy parport code to the device driver model (by splitting out probing from
device creation).  But at least parallel port device drivers will finally have
a device to work with.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 39 additions and 0 deletions Side-by-side Diff

drivers/parport/parport_pc.c
... ... @@ -53,6 +53,7 @@
53 53 #include <linux/slab.h>
54 54 #include <linux/pci.h>
55 55 #include <linux/pnp.h>
  56 +#include <linux/platform_device.h>
56 57 #include <linux/sysctl.h>
57 58  
58 59 #include <asm/io.h>
59 60  
... ... @@ -2156,7 +2157,18 @@
2156 2157 struct resource *base_res;
2157 2158 struct resource *ECR_res = NULL;
2158 2159 struct resource *EPP_res = NULL;
  2160 + struct platform_device *pdev = NULL;
2159 2161  
  2162 + if (!dev) {
  2163 + /* We need a physical device to attach to, but none was
  2164 + * provided. Create our own. */
  2165 + pdev = platform_device_register_simple("parport_pc",
  2166 + base, NULL, 0);
  2167 + if (IS_ERR(pdev))
  2168 + return NULL;
  2169 + dev = &pdev->dev;
  2170 + }
  2171 +
2160 2172 ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL);
2161 2173 if (!ops)
2162 2174 goto out1;
... ... @@ -2359,6 +2371,8 @@
2359 2371 out2:
2360 2372 kfree (ops);
2361 2373 out1:
  2374 + if (pdev)
  2375 + platform_device_unregister(pdev);
2362 2376 return NULL;
2363 2377 }
2364 2378  
... ... @@ -3106,6 +3120,21 @@
3106 3120 };
3107 3121  
3108 3122  
  3123 +static int __devinit parport_pc_platform_probe(struct platform_device *pdev)
  3124 +{
  3125 + /* Always succeed, the actual probing is done in
  3126 + * parport_pc_probe_port(). */
  3127 + return 0;
  3128 +}
  3129 +
  3130 +static struct platform_driver parport_pc_platform_driver = {
  3131 + .driver = {
  3132 + .owner = THIS_MODULE,
  3133 + .name = "parport_pc",
  3134 + },
  3135 + .probe = parport_pc_platform_probe,
  3136 +};
  3137 +
3109 3138 /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
3110 3139 static int __devinit __attribute__((unused))
3111 3140 parport_pc_find_isa_ports (int autoirq, int autodma)
3112 3141  
... ... @@ -3381,9 +3410,15 @@
3381 3410  
3382 3411 static int __init parport_pc_init(void)
3383 3412 {
  3413 + int err;
  3414 +
3384 3415 if (parse_parport_params())
3385 3416 return -EINVAL;
3386 3417  
  3418 + err = platform_driver_register(&parport_pc_platform_driver);
  3419 + if (err)
  3420 + return err;
  3421 +
3387 3422 if (io[0]) {
3388 3423 int i;
3389 3424 /* Only probe the ports we were given. */
... ... @@ -3408,6 +3443,7 @@
3408 3443 pci_unregister_driver (&parport_pc_pci_driver);
3409 3444 if (pnp_registered_parport)
3410 3445 pnp_unregister_driver (&parport_pc_pnp_driver);
  3446 + platform_driver_unregister(&parport_pc_platform_driver);
3411 3447  
3412 3448 spin_lock(&ports_lock);
3413 3449 while (!list_empty(&ports_list)) {
... ... @@ -3416,6 +3452,9 @@
3416 3452 priv = list_entry(ports_list.next,
3417 3453 struct parport_pc_private, list);
3418 3454 port = priv->port;
  3455 + if (port->dev && port->dev->bus == &platform_bus_type)
  3456 + platform_device_unregister(
  3457 + to_platform_device(port->dev));
3419 3458 spin_unlock(&ports_lock);
3420 3459 parport_pc_unregister_port(port);
3421 3460 spin_lock(&ports_lock);