forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/parport/share.c
....@@ -278,47 +278,32 @@
278278 int __parport_register_driver(struct parport_driver *drv, struct module *owner,
279279 const char *mod_name)
280280 {
281
- if (list_empty(&portlist))
281
+ /* using device model */
282
+ int ret;
283
+
284
+ /* initialize common driver fields */
285
+ drv->driver.name = drv->name;
286
+ drv->driver.bus = &parport_bus_type;
287
+ drv->driver.owner = owner;
288
+ drv->driver.mod_name = mod_name;
289
+ ret = driver_register(&drv->driver);
290
+ if (ret)
291
+ return ret;
292
+
293
+ /*
294
+ * check if bus has any parallel port registered, if
295
+ * none is found then load the lowlevel driver.
296
+ */
297
+ ret = bus_for_each_dev(&parport_bus_type, NULL, NULL,
298
+ port_detect);
299
+ if (!ret)
282300 get_lowlevel_driver();
283301
284
- if (drv->devmodel) {
285
- /* using device model */
286
- int ret;
287
-
288
- /* initialize common driver fields */
289
- drv->driver.name = drv->name;
290
- drv->driver.bus = &parport_bus_type;
291
- drv->driver.owner = owner;
292
- drv->driver.mod_name = mod_name;
293
- ret = driver_register(&drv->driver);
294
- if (ret)
295
- return ret;
296
-
297
- /*
298
- * check if bus has any parallel port registered, if
299
- * none is found then load the lowlevel driver.
300
- */
301
- ret = bus_for_each_dev(&parport_bus_type, NULL, NULL,
302
- port_detect);
303
- if (!ret)
304
- get_lowlevel_driver();
305
-
306
- mutex_lock(&registration_lock);
307
- if (drv->match_port)
308
- bus_for_each_dev(&parport_bus_type, NULL, drv,
309
- port_check);
310
- mutex_unlock(&registration_lock);
311
- } else {
312
- struct parport *port;
313
-
314
- drv->devmodel = false;
315
-
316
- mutex_lock(&registration_lock);
317
- list_for_each_entry(port, &portlist, list)
318
- drv->attach(port);
319
- list_add(&drv->list, &drivers);
320
- mutex_unlock(&registration_lock);
321
- }
302
+ mutex_lock(&registration_lock);
303
+ if (drv->match_port)
304
+ bus_for_each_dev(&parport_bus_type, NULL, drv,
305
+ port_check);
306
+ mutex_unlock(&registration_lock);
322307
323308 return 0;
324309 }
....@@ -353,17 +338,9 @@
353338
354339 void parport_unregister_driver(struct parport_driver *drv)
355340 {
356
- struct parport *port;
357
-
358341 mutex_lock(&registration_lock);
359
- if (drv->devmodel) {
360
- bus_for_each_dev(&parport_bus_type, NULL, drv, port_detach);
361
- driver_unregister(&drv->driver);
362
- } else {
363
- list_del_init(&drv->list);
364
- list_for_each_entry(port, &portlist, list)
365
- drv->detach(port);
366
- }
342
+ bus_for_each_dev(&parport_bus_type, NULL, drv, port_detach);
343
+ driver_unregister(&drv->driver);
367344 mutex_unlock(&registration_lock);
368345 }
369346 EXPORT_SYMBOL(parport_unregister_driver);
....@@ -555,8 +532,8 @@
555532 #endif
556533
557534 if (!port->dev)
558
- printk(KERN_WARNING "%s: fix this legacy no-device port driver!\n",
559
- port->name);
535
+ pr_warn("%s: fix this legacy no-device port driver!\n",
536
+ port->name);
560537
561538 parport_proc_register(port);
562539 mutex_lock(&registration_lock);
....@@ -642,47 +619,48 @@
642619 }
643620 EXPORT_SYMBOL(parport_remove_port);
644621
622
+static void free_pardevice(struct device *dev)
623
+{
624
+ struct pardevice *par_dev = to_pardevice(dev);
625
+
626
+ kfree(par_dev->name);
627
+ kfree(par_dev);
628
+}
629
+
645630 /**
646
- * parport_register_device - register a device on a parallel port
631
+ * parport_register_dev_model - register a device on a parallel port
647632 * @port: port to which the device is attached
648633 * @name: a name to refer to the device
649
- * @pf: preemption callback
650
- * @kf: kick callback (wake-up)
651
- * @irq_func: interrupt handler
652
- * @flags: registration flags
653
- * @handle: data for callback functions
634
+ * @par_dev_cb: struct containing callbacks
635
+ * @id: device number to be given to the device
654636 *
655637 * This function, called by parallel port device drivers,
656638 * declares that a device is connected to a port, and tells the
657639 * system all it needs to know.
658640 *
659
- * The @name is allocated by the caller and must not be
660
- * deallocated until the caller calls @parport_unregister_device
661
- * for that device.
641
+ * The struct pardev_cb contains pointer to callbacks. preemption
642
+ * callback function, @preempt, is called when this device driver
643
+ * has claimed access to the port but another device driver wants
644
+ * to use it. It is given, @private, as its parameter, and should
645
+ * return zero if it is willing for the system to release the port
646
+ * to another driver on its behalf. If it wants to keep control of
647
+ * the port it should return non-zero, and no action will be taken.
648
+ * It is good manners for the driver to try to release the port at
649
+ * the earliest opportunity after its preemption callback rejects a
650
+ * preemption attempt. Note that if a preemption callback is happy
651
+ * for preemption to go ahead, there is no need to release the
652
+ * port; it is done automatically. This function may not block, as
653
+ * it may be called from interrupt context. If the device driver
654
+ * does not support preemption, @preempt can be %NULL.
662655 *
663
- * The preemption callback function, @pf, is called when this
664
- * device driver has claimed access to the port but another
665
- * device driver wants to use it. It is given @handle as its
666
- * parameter, and should return zero if it is willing for the
667
- * system to release the port to another driver on its behalf.
668
- * If it wants to keep control of the port it should return
669
- * non-zero, and no action will be taken. It is good manners for
670
- * the driver to try to release the port at the earliest
671
- * opportunity after its preemption callback rejects a preemption
672
- * attempt. Note that if a preemption callback is happy for
673
- * preemption to go ahead, there is no need to release the port;
674
- * it is done automatically. This function may not block, as it
675
- * may be called from interrupt context. If the device driver
676
- * does not support preemption, @pf can be %NULL.
677
- *
678
- * The wake-up ("kick") callback function, @kf, is called when
656
+ * The wake-up ("kick") callback function, @wakeup, is called when
679657 * the port is available to be claimed for exclusive access; that
680658 * is, parport_claim() is guaranteed to succeed when called from
681659 * inside the wake-up callback function. If the driver wants to
682660 * claim the port it should do so; otherwise, it need not take
683661 * any action. This function may not block, as it may be called
684662 * from interrupt context. If the device driver does not want to
685
- * be explicitly invited to claim the port in this way, @kf can
663
+ * be explicitly invited to claim the port in this way, @wakeup can
686664 * be %NULL.
687665 *
688666 * The interrupt handler, @irq_func, is called when an interrupt
....@@ -710,138 +688,6 @@
710688 * the device on the port, or %NULL if there is not enough memory
711689 * to allocate space for that structure.
712690 **/
713
-
714
-struct pardevice *
715
-parport_register_device(struct parport *port, const char *name,
716
- int (*pf)(void *), void (*kf)(void *),
717
- void (*irq_func)(void *),
718
- int flags, void *handle)
719
-{
720
- struct pardevice *tmp;
721
-
722
- if (port->physport->flags & PARPORT_FLAG_EXCL) {
723
- /* An exclusive device is registered. */
724
- printk(KERN_DEBUG "%s: no more devices allowed\n",
725
- port->name);
726
- return NULL;
727
- }
728
-
729
- if (flags & PARPORT_DEV_LURK) {
730
- if (!pf || !kf) {
731
- printk(KERN_INFO "%s: refused to register lurking device (%s) without callbacks\n", port->name, name);
732
- return NULL;
733
- }
734
- }
735
-
736
- if (flags & PARPORT_DEV_EXCL) {
737
- if (port->physport->devices) {
738
- /*
739
- * If a device is already registered and this new
740
- * device wants exclusive access, then no need to
741
- * continue as we can not grant exclusive access to
742
- * this device.
743
- */
744
- pr_err("%s: cannot grant exclusive access for device %s\n",
745
- port->name, name);
746
- return NULL;
747
- }
748
- }
749
-
750
- /*
751
- * We up our own module reference count, and that of the port
752
- * on which a device is to be registered, to ensure that
753
- * neither of us gets unloaded while we sleep in (e.g.)
754
- * kmalloc.
755
- */
756
- if (!try_module_get(port->ops->owner))
757
- return NULL;
758
-
759
- parport_get_port(port);
760
-
761
- tmp = kmalloc(sizeof(struct pardevice), GFP_KERNEL);
762
- if (!tmp)
763
- goto out;
764
-
765
- tmp->state = kmalloc(sizeof(struct parport_state), GFP_KERNEL);
766
- if (!tmp->state)
767
- goto out_free_pardevice;
768
-
769
- tmp->name = name;
770
- tmp->port = port;
771
- tmp->daisy = -1;
772
- tmp->preempt = pf;
773
- tmp->wakeup = kf;
774
- tmp->private = handle;
775
- tmp->flags = flags;
776
- tmp->irq_func = irq_func;
777
- tmp->waiting = 0;
778
- tmp->timeout = 5 * HZ;
779
- tmp->devmodel = false;
780
-
781
- /* Chain this onto the list */
782
- tmp->prev = NULL;
783
- /*
784
- * This function must not run from an irq handler so we don' t need
785
- * to clear irq on the local CPU. -arca
786
- */
787
- spin_lock(&port->physport->pardevice_lock);
788
-
789
- if (flags & PARPORT_DEV_EXCL) {
790
- if (port->physport->devices) {
791
- spin_unlock(&port->physport->pardevice_lock);
792
- printk(KERN_DEBUG
793
- "%s: cannot grant exclusive access for device %s\n",
794
- port->name, name);
795
- goto out_free_all;
796
- }
797
- port->flags |= PARPORT_FLAG_EXCL;
798
- }
799
-
800
- tmp->next = port->physport->devices;
801
- wmb(); /*
802
- * Make sure that tmp->next is written before it's
803
- * added to the list; see comments marked 'no locking
804
- * required'
805
- */
806
- if (port->physport->devices)
807
- port->physport->devices->prev = tmp;
808
- port->physport->devices = tmp;
809
- spin_unlock(&port->physport->pardevice_lock);
810
-
811
- init_waitqueue_head(&tmp->wait_q);
812
- tmp->timeslice = parport_default_timeslice;
813
- tmp->waitnext = tmp->waitprev = NULL;
814
-
815
- /*
816
- * This has to be run as last thing since init_state may need other
817
- * pardevice fields. -arca
818
- */
819
- port->ops->init_state(tmp, tmp->state);
820
- if (!test_and_set_bit(PARPORT_DEVPROC_REGISTERED, &port->devflags)) {
821
- port->proc_device = tmp;
822
- parport_device_proc_register(tmp);
823
- }
824
- return tmp;
825
-
826
- out_free_all:
827
- kfree(tmp->state);
828
- out_free_pardevice:
829
- kfree(tmp);
830
- out:
831
- parport_put_port(port);
832
- module_put(port->ops->owner);
833
-
834
- return NULL;
835
-}
836
-EXPORT_SYMBOL(parport_register_device);
837
-
838
-static void free_pardevice(struct device *dev)
839
-{
840
- struct pardevice *par_dev = to_pardevice(dev);
841
-
842
- kfree(par_dev->name);
843
- kfree(par_dev);
844
-}
845691
846692 struct pardevice *
847693 parport_register_dev_model(struct parport *port, const char *name,
....@@ -997,7 +843,7 @@
997843
998844 #ifdef PARPORT_PARANOID
999845 if (!dev) {
1000
- printk(KERN_ERR "parport_unregister_device: passed NULL\n");
846
+ pr_err("%s: passed NULL\n", __func__);
1001847 return;
1002848 }
1003849 #endif
....@@ -1047,10 +893,7 @@
1047893 spin_unlock_irq(&port->waitlist_lock);
1048894
1049895 kfree(dev->state);
1050
- if (dev->devmodel)
1051
- device_unregister(&dev->dev);
1052
- else
1053
- kfree(dev);
896
+ device_unregister(&dev->dev);
1054897
1055898 module_put(port->ops->owner);
1056899 parport_put_port(port);
....@@ -1138,8 +981,7 @@
1138981 unsigned long flags;
1139982
1140983 if (port->cad == dev) {
1141
- printk(KERN_INFO "%s: %s already owner\n",
1142
- dev->port->name,dev->name);
984
+ pr_info("%s: %s already owner\n", dev->port->name, dev->name);
1143985 return 0;
1144986 }
1145987
....@@ -1159,9 +1001,8 @@
11591001 * I think we'll actually deadlock rather than
11601002 * get here, but just in case..
11611003 */
1162
- printk(KERN_WARNING
1163
- "%s: %s released port when preempted!\n",
1164
- port->name, oldcad->name);
1004
+ pr_warn("%s: %s released port when preempted!\n",
1005
+ port->name, oldcad->name);
11651006 if (port->cad)
11661007 goto blocked;
11671008 }
....@@ -1261,7 +1102,8 @@
12611102 r = parport_claim(dev);
12621103 if (r == -EAGAIN) {
12631104 #ifdef PARPORT_DEBUG_SHARING
1264
- printk(KERN_DEBUG "%s: parport_claim() returned -EAGAIN\n", dev->name);
1105
+ printk(KERN_DEBUG "%s: parport_claim() returned -EAGAIN\n",
1106
+ dev->name);
12651107 #endif
12661108 /*
12671109 * FIXME!!! Use the proper locking for dev->waiting,
....@@ -1294,7 +1136,7 @@
12941136 if (dev->port->physport->cad != dev)
12951137 printk(KERN_DEBUG "%s: exiting parport_claim_or_block but %s owns port!\n",
12961138 dev->name, dev->port->physport->cad ?
1297
- dev->port->physport->cad->name:"nobody");
1139
+ dev->port->physport->cad->name : "nobody");
12981140 #endif
12991141 }
13001142 dev->waiting = 0;
....@@ -1321,8 +1163,8 @@
13211163 write_lock_irqsave(&port->cad_lock, flags);
13221164 if (port->cad != dev) {
13231165 write_unlock_irqrestore(&port->cad_lock, flags);
1324
- printk(KERN_WARNING "%s: %s tried to release parport when not owner\n",
1325
- port->name, dev->name);
1166
+ pr_warn("%s: %s tried to release parport when not owner\n",
1167
+ port->name, dev->name);
13261168 return;
13271169 }
13281170
....@@ -1362,7 +1204,8 @@
13621204 if (dev->port->cad) /* racy but no matter */
13631205 return;
13641206 } else {
1365
- printk(KERN_ERR "%s: don't know how to wake %s\n", port->name, pd->name);
1207
+ pr_err("%s: don't know how to wake %s\n",
1208
+ port->name, pd->name);
13661209 }
13671210 }
13681211