hamradio: baycom_par: use new parport device model
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Sun, 15 Oct 2017 21:00:52 +0000 (22:00 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 16 Oct 2017 20:16:23 +0000 (21:16 +0100)
Modify baycom driver to use the new parallel port device model.

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/hamradio/baycom_par.c

index e1783832d304b701d7bc007def77b347520c8234..1f7ceafd61ffa4c1ac9d93c9720d5e6863250817 100644 (file)
@@ -311,7 +311,9 @@ static void par96_wakeup(void *handle)
 static int par96_open(struct net_device *dev)
 {
        struct baycom_state *bc = netdev_priv(dev);
+       struct pardev_cb par_cb;
        struct parport *pp;
+       int i;
 
        if (!dev || !bc)
                return -ENXIO;
@@ -332,8 +334,21 @@ static int par96_open(struct net_device *dev)
        }
        memset(&bc->modem, 0, sizeof(bc->modem));
        bc->hdrv.par.bitrate = 9600;
-       bc->pdev = parport_register_device(pp, dev->name, NULL, par96_wakeup, 
-                                par96_interrupt, PARPORT_DEV_EXCL, dev);
+       memset(&par_cb, 0, sizeof(par_cb));
+       par_cb.wakeup = par96_wakeup;
+       par_cb.irq_func = par96_interrupt;
+       par_cb.private = (void *)dev;
+       par_cb.flags = PARPORT_DEV_EXCL;
+       for (i = 0; i < NR_PORTS; i++)
+               if (baycom_device[i] == dev)
+                       break;
+
+       if (i == NR_PORTS) {
+               pr_err("%s: no device found\n", bc_drvname);
+               parport_put_port(pp);
+               return -ENODEV;
+       }
+       bc->pdev = parport_register_dev_model(pp, dev->name, &par_cb, i);
        parport_put_port(pp);
        if (!bc->pdev) {
                printk(KERN_ERR "baycom_par: cannot register parport at 0x%lx\n", dev->base_addr);
@@ -490,12 +505,34 @@ MODULE_LICENSE("GPL");
 
 /* --------------------------------------------------------------------- */
 
+static int baycom_par_probe(struct pardevice *par_dev)
+{
+       struct device_driver *drv = par_dev->dev.driver;
+       int len = strlen(drv->name);
+
+       if (strncmp(par_dev->name, drv->name, len))
+               return -ENODEV;
+
+       return 0;
+}
+
+static struct parport_driver baycom_par_driver = {
+       .name = "bcp",
+       .probe = baycom_par_probe,
+       .devmodel = true,
+};
+
 static int __init init_baycompar(void)
 {
-       int i, found = 0;
+       int i, found = 0, ret;
        char set_hw = 1;
 
        printk(bc_drvinfo);
+
+       ret = parport_register_driver(&baycom_par_driver);
+       if (ret)
+               return ret;
+
        /*
         * register net devices
         */
@@ -524,8 +561,10 @@ static int __init init_baycompar(void)
                baycom_device[i] = dev;
        }
 
-       if (!found)
+       if (!found) {
+               parport_unregister_driver(&baycom_par_driver);
                return -ENXIO;
+       }
        return 0;
 }
 
@@ -539,6 +578,7 @@ static void __exit cleanup_baycompar(void)
                if (dev)
                        hdlcdrv_unregister(dev);
        }
+       parport_unregister_driver(&baycom_par_driver);
 }
 
 module_init(init_baycompar);