parport: daisy: use new parport device model
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Wed, 13 Feb 2019 08:47:06 +0000 (08:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Feb 2019 18:45:56 +0000 (19:45 +0100)
Modify parport daisy driver to use the new parallel port device model.

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/parport/daisy.c
drivers/parport/probe.c
drivers/parport/share.c
include/linux/parport.h

index 5484a46dafda857a7e64207ccac4a8249cf1512c..56dd83a45e55dc21360f729c488a213a2a258241 100644 (file)
@@ -213,10 +213,12 @@ void parport_daisy_fini(struct parport *port)
 struct pardevice *parport_open(int devnum, const char *name)
 {
        struct daisydev *p = topology;
+       struct pardev_cb par_cb;
        struct parport *port;
        struct pardevice *dev;
        int daisy;
 
+       memset(&par_cb, 0, sizeof(par_cb));
        spin_lock(&topology_lock);
        while (p && p->devnum != devnum)
                p = p->next;
@@ -230,7 +232,7 @@ struct pardevice *parport_open(int devnum, const char *name)
        port = parport_get_port(p->port);
        spin_unlock(&topology_lock);
 
-       dev = parport_register_device(port, name, NULL, NULL, NULL, 0, NULL);
+       dev = parport_register_dev_model(port, name, &par_cb, devnum);
        parport_put_port(port);
        if (!dev)
                return NULL;
@@ -480,3 +482,31 @@ static int assign_addrs(struct parport *port)
        kfree(deviceid);
        return detected;
 }
+
+static int daisy_drv_probe(struct pardevice *par_dev)
+{
+       struct device_driver *drv = par_dev->dev.driver;
+
+       if (strcmp(drv->name, "daisy_drv"))
+               return -ENODEV;
+       if (strcmp(par_dev->name, daisy_dev_name))
+               return -ENODEV;
+
+       return 0;
+}
+
+static struct parport_driver daisy_driver = {
+       .name = "daisy_drv",
+       .probe = daisy_drv_probe,
+       .devmodel = true,
+};
+
+int daisy_drv_init(void)
+{
+       return parport_register_driver(&daisy_driver);
+}
+
+void daisy_drv_exit(void)
+{
+       parport_unregister_driver(&daisy_driver);
+}
index e035174ba205d12dbc6e529c6ec85c8bda9e5d21..e5e6a463a9412e167a9e2b2c34f4a6cfb3a1cb2a 100644 (file)
@@ -257,7 +257,7 @@ static ssize_t parport_read_device_id (struct parport *port, char *buffer,
 ssize_t parport_device_id (int devnum, char *buffer, size_t count)
 {
        ssize_t retval = -ENXIO;
-       struct pardevice *dev = parport_open (devnum, "Device ID probe");
+       struct pardevice *dev = parport_open(devnum, daisy_dev_name);
        if (!dev)
                return -ENXIO;
 
index 5dc53d420ca8ca805c0c036c23e3c1a3fc42ac00..0171b8dbcdcd5f57c54eeee19eed23d65dbd8897 100644 (file)
@@ -137,11 +137,19 @@ static struct bus_type parport_bus_type = {
 
 int parport_bus_init(void)
 {
-       return bus_register(&parport_bus_type);
+       int retval;
+
+       retval = bus_register(&parport_bus_type);
+       if (retval)
+               return retval;
+       daisy_drv_init();
+
+       return 0;
 }
 
 void parport_bus_exit(void)
 {
+       daisy_drv_exit();
        bus_unregister(&parport_bus_type);
 }
 
index 397607a0c0ebef2969a3c4ea81893be860c8aacc..f41f1d041e2c5e325e4d817781e13ed60695276c 100644 (file)
@@ -460,6 +460,7 @@ extern size_t parport_ieee1284_epp_read_addr (struct parport *,
                                              void *, size_t, int);
 
 /* IEEE1284.3 functions */
+#define daisy_dev_name "Device ID probe"
 extern int parport_daisy_init (struct parport *port);
 extern void parport_daisy_fini (struct parport *port);
 extern struct pardevice *parport_open (int devnum, const char *name);
@@ -468,6 +469,18 @@ extern ssize_t parport_device_id (int devnum, char *buffer, size_t len);
 extern void parport_daisy_deselect_all (struct parport *port);
 extern int parport_daisy_select (struct parport *port, int daisy, int mode);
 
+#ifdef CONFIG_PARPORT_1284
+extern int daisy_drv_init(void);
+extern void daisy_drv_exit(void);
+#else
+static inline int daisy_drv_init(void)
+{
+       return 0;
+}
+
+static inline void daisy_drv_exit(void) {}
+#endif
+
 /* Lowlevel drivers _can_ call this support function to handle irqs.  */
 static inline void parport_generic_irq(struct parport *port)
 {