Skip to content

Commit a7d801a

Browse files
Jean DelvareLinus Torvalds
authored andcommitted
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>
1 parent c15a383 commit a7d801a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎drivers/parport/parport_pc.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <linux/slab.h>
5454
#include <linux/pci.h>
5555
#include <linux/pnp.h>
56+
#include <linux/platform_device.h>
5657
#include <linux/sysctl.h>
5758

5859
#include <asm/io.h>
@@ -2156,6 +2157,17 @@ struct parport *parport_pc_probe_port (unsigned long int base,
21562157
struct resource *base_res;
21572158
struct resource *ECR_res = NULL;
21582159
struct resource *EPP_res = NULL;
2160+
struct platform_device *pdev = NULL;
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+
}
21592171

21602172
ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL);
21612173
if (!ops)
@@ -2359,6 +2371,8 @@ struct parport *parport_pc_probe_port (unsigned long int base,
23592371
out2:
23602372
kfree (ops);
23612373
out1:
2374+
if (pdev)
2375+
platform_device_unregister(pdev);
23622376
return NULL;
23632377
}
23642378

@@ -3106,6 +3120,21 @@ static struct pnp_driver parport_pc_pnp_driver = {
31063120
};
31073121

31083122

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+
31093138
/* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
31103139
static int __devinit __attribute__((unused))
31113140
parport_pc_find_isa_ports (int autoirq, int autodma)
@@ -3381,9 +3410,15 @@ __setup("parport_init_mode=",parport_init_mode_setup);
33813410

33823411
static int __init parport_pc_init(void)
33833412
{
3413+
int err;
3414+
33843415
if (parse_parport_params())
33853416
return -EINVAL;
33863417

3418+
err = platform_driver_register(&parport_pc_platform_driver);
3419+
if (err)
3420+
return err;
3421+
33873422
if (io[0]) {
33883423
int i;
33893424
/* Only probe the ports we were given. */
@@ -3408,6 +3443,7 @@ static void __exit parport_pc_exit(void)
34083443
pci_unregister_driver (&parport_pc_pci_driver);
34093444
if (pnp_registered_parport)
34103445
pnp_unregister_driver (&parport_pc_pnp_driver);
3446+
platform_driver_unregister(&parport_pc_platform_driver);
34113447

34123448
spin_lock(&ports_lock);
34133449
while (!list_empty(&ports_list)) {
@@ -3416,6 +3452,9 @@ static void __exit parport_pc_exit(void)
34163452
priv = list_entry(ports_list.next,
34173453
struct parport_pc_private, list);
34183454
port = priv->port;
3455+
if (port->dev && port->dev->bus == &platform_bus_type)
3456+
platform_device_unregister(
3457+
to_platform_device(port->dev));
34193458
spin_unlock(&ports_lock);
34203459
parport_pc_unregister_port(port);
34213460
spin_lock(&ports_lock);

0 commit comments

Comments
 (0)