aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/pcmcia
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2005-11-14 15:23:14 -0500
committerDominik Brodowski <linux@dominikbrodowski.net>2006-01-05 18:03:10 -0500
commitcc3b4866bee996c922e875b8c8efe9f0d8803aae (patch)
tree6632837b6986f33566f75ed971cecbdc210e3201 /drivers/char/pcmcia
parent8e9e793d68fcda6cc84c18cedf85ca0f91d801a8 (diff)
[PATCH] pcmcia: unify detach, REMOVAL_EVENT handlers into one remove callback
Unify the "detach" and REMOVAL_EVENT handlers to one "remove" function. Old functionality is preserved, for the moment. Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/char/pcmcia')
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c55
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c52
-rw-r--r--drivers/char/pcmcia/synclink_cs.c34
3 files changed, 42 insertions, 99 deletions
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 05e93054c98c..8a064f2f005d 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -66,7 +66,7 @@ static char *version = "cm4000_cs.c v2.4.0gm5 - All bugs added by Harald Welte";
66#define T_100MSEC msecs_to_jiffies(100) 66#define T_100MSEC msecs_to_jiffies(100)
67#define T_500MSEC msecs_to_jiffies(500) 67#define T_500MSEC msecs_to_jiffies(500)
68 68
69static void cm4000_detach(dev_link_t *link); 69static void cm4000_detach(struct pcmcia_device *p_dev);
70static void cm4000_release(dev_link_t *link); 70static void cm4000_release(dev_link_t *link);
71 71
72static int major; /* major number we get from the kernel */ 72static int major; /* major number we get from the kernel */
@@ -1888,11 +1888,6 @@ static int cm4000_event(event_t event, int priority,
1888 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 1888 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1889 cm4000_config(link, devno); 1889 cm4000_config(link, devno);
1890 break; 1890 break;
1891 case CS_EVENT_CARD_REMOVAL:
1892 DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n");
1893 link->state &= ~DEV_PRESENT;
1894 stop_monitor(dev);
1895 break;
1896 default: 1891 default:
1897 DEBUGP(5, dev, "unknown event %.2x\n", event); 1892 DEBUGP(5, dev, "unknown event %.2x\n", event);
1898 break; 1893 break;
@@ -1978,7 +1973,7 @@ static dev_link_t *cm4000_attach(void)
1978 i = pcmcia_register_client(&link->handle, &client_reg); 1973 i = pcmcia_register_client(&link->handle, &client_reg);
1979 if (i) { 1974 if (i) {
1980 cs_error(link->handle, RegisterClient, i); 1975 cs_error(link->handle, RegisterClient, i);
1981 cm4000_detach(link); 1976 cm4000_detach(link->handle);
1982 return NULL; 1977 return NULL;
1983 } 1978 }
1984 1979
@@ -1990,39 +1985,28 @@ static dev_link_t *cm4000_attach(void)
1990 return link; 1985 return link;
1991} 1986}
1992 1987
1993static void cm4000_detach_by_devno(int devno, dev_link_t * link) 1988static void cm4000_detach(struct pcmcia_device *p_dev)
1994{ 1989{
1990 dev_link_t *link = dev_to_instance(p_dev);
1995 struct cm4000_dev *dev = link->priv; 1991 struct cm4000_dev *dev = link->priv;
1992 int devno;
1996 1993
1997 DEBUGP(3, dev, "-> detach_by_devno(devno=%d)\n", devno); 1994 /* find device */
1995 for (devno = 0; devno < CM4000_MAX_DEV; devno++)
1996 if (dev_table[devno] == link)
1997 break;
1998 if (devno == CM4000_MAX_DEV)
1999 return;
1998 2000
1999 if (link->state & DEV_CONFIG) { 2001 link->state &= ~DEV_PRESENT;
2000 DEBUGP(5, dev, "device still configured (try to release it)\n"); 2002 stop_monitor(dev);
2001 cm4000_release(link);
2002 }
2003 2003
2004 if (link->handle) { 2004 if (link->state & DEV_CONFIG)
2005 pcmcia_deregister_client(link->handle); 2005 cm4000_release(link);
2006 }
2007 2006
2008 dev_table[devno] = NULL; 2007 dev_table[devno] = NULL;
2009 kfree(dev); 2008 kfree(dev);
2010 return;
2011}
2012
2013static void cm4000_detach(dev_link_t * link)
2014{
2015 int i;
2016 2009
2017 /* find device */
2018 for (i = 0; i < CM4000_MAX_DEV; i++)
2019 if (dev_table[i] == link)
2020 break;
2021
2022 if (i == CM4000_MAX_DEV)
2023 return;
2024
2025 cm4000_detach_by_devno(i, link);
2026 return; 2010 return;
2027} 2011}
2028 2012
@@ -2048,7 +2032,7 @@ static struct pcmcia_driver cm4000_driver = {
2048 .name = "cm4000_cs", 2032 .name = "cm4000_cs",
2049 }, 2033 },
2050 .attach = cm4000_attach, 2034 .attach = cm4000_attach,
2051 .detach = cm4000_detach, 2035 .remove = cm4000_detach,
2052 .suspend = cm4000_suspend, 2036 .suspend = cm4000_suspend,
2053 .resume = cm4000_resume, 2037 .resume = cm4000_resume,
2054 .event = cm4000_event, 2038 .event = cm4000_event,
@@ -2071,13 +2055,8 @@ static int __init cmm_init(void)
2071 2055
2072static void __exit cmm_exit(void) 2056static void __exit cmm_exit(void)
2073{ 2057{
2074 int i;
2075
2076 printk(KERN_INFO MODULE_NAME ": unloading\n"); 2058 printk(KERN_INFO MODULE_NAME ": unloading\n");
2077 pcmcia_unregister_driver(&cm4000_driver); 2059 pcmcia_unregister_driver(&cm4000_driver);
2078 for (i = 0; i < CM4000_MAX_DEV; i++)
2079 if (dev_table[i])
2080 cm4000_detach_by_devno(i, dev_table[i]);
2081 unregister_chrdev(major, DEVICE_NAME); 2060 unregister_chrdev(major, DEVICE_NAME);
2082}; 2061};
2083 2062
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 3622fd39c47b..e08ab949c116 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -65,7 +65,7 @@ static char *version =
65#define POLL_PERIOD msecs_to_jiffies(10) 65#define POLL_PERIOD msecs_to_jiffies(10)
66 66
67static void reader_release(dev_link_t *link); 67static void reader_release(dev_link_t *link);
68static void reader_detach(dev_link_t *link); 68static void reader_detach(struct pcmcia_device *p_dev);
69 69
70static int major; 70static int major;
71 71
@@ -652,10 +652,6 @@ static int reader_event(event_t event, int priority,
652 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 652 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
653 reader_config(link, devno); 653 reader_config(link, devno);
654 break; 654 break;
655 case CS_EVENT_CARD_REMOVAL:
656 DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n");
657 link->state &= ~DEV_PRESENT;
658 break;
659 655
660 default: 656 default:
661 DEBUGP(5, dev, "reader_event: unknown event %.2x\n", 657 DEBUGP(5, dev, "reader_event: unknown event %.2x\n",
@@ -734,7 +730,7 @@ static dev_link_t *reader_attach(void)
734 i = pcmcia_register_client(&link->handle, &client_reg); 730 i = pcmcia_register_client(&link->handle, &client_reg);
735 if (i) { 731 if (i) {
736 cs_error(link->handle, RegisterClient, i); 732 cs_error(link->handle, RegisterClient, i);
737 reader_detach(link); 733 reader_detach(link->handle);
738 return NULL; 734 return NULL;
739 } 735 }
740 init_waitqueue_head(&dev->devq); 736 init_waitqueue_head(&dev->devq);
@@ -747,36 +743,28 @@ static dev_link_t *reader_attach(void)
747 return link; 743 return link;
748} 744}
749 745
750static void reader_detach_by_devno(int devno, dev_link_t *link) 746static void reader_detach(struct pcmcia_device *p_dev)
751{ 747{
748 dev_link_t *link = dev_to_instance(p_dev);
752 struct reader_dev *dev = link->priv; 749 struct reader_dev *dev = link->priv;
753 750 int devno;
754 if (link->state & DEV_CONFIG) {
755 DEBUGP(5, dev, "device still configured (try to release it)\n");
756 reader_release(link);
757 }
758
759 pcmcia_deregister_client(link->handle);
760 dev_table[devno] = NULL;
761 DEBUGP(5, dev, "freeing dev=%p\n", dev);
762 cm4040_stop_poll(dev);
763 kfree(dev);
764 return;
765}
766
767static void reader_detach(dev_link_t *link)
768{
769 int i;
770 751
771 /* find device */ 752 /* find device */
772 for (i = 0; i < CM_MAX_DEV; i++) { 753 for (devno = 0; devno < CM_MAX_DEV; devno++) {
773 if (dev_table[i] == link) 754 if (dev_table[devno] == link)
774 break; 755 break;
775 } 756 }
776 if (i == CM_MAX_DEV) 757 if (devno == CM_MAX_DEV)
777 return; 758 return;
778 759
779 reader_detach_by_devno(i, link); 760 link->state &= ~DEV_PRESENT;
761
762 if (link->state & DEV_CONFIG)
763 reader_release(link);
764
765 dev_table[devno] = NULL;
766 kfree(dev);
767
780 return; 768 return;
781} 769}
782 770
@@ -803,7 +791,7 @@ static struct pcmcia_driver reader_driver = {
803 .name = "cm4040_cs", 791 .name = "cm4040_cs",
804 }, 792 },
805 .attach = reader_attach, 793 .attach = reader_attach,
806 .detach = reader_detach, 794 .remove = reader_detach,
807 .suspend = reader_suspend, 795 .suspend = reader_suspend,
808 .resume = reader_resume, 796 .resume = reader_resume,
809 .event = reader_event, 797 .event = reader_event,
@@ -825,14 +813,8 @@ static int __init cm4040_init(void)
825 813
826static void __exit cm4040_exit(void) 814static void __exit cm4040_exit(void)
827{ 815{
828 int i;
829
830 printk(KERN_INFO MODULE_NAME ": unloading\n"); 816 printk(KERN_INFO MODULE_NAME ": unloading\n");
831 pcmcia_unregister_driver(&reader_driver); 817 pcmcia_unregister_driver(&reader_driver);
832 for (i = 0; i < CM_MAX_DEV; i++) {
833 if (dev_table[i])
834 reader_detach_by_devno(i, dev_table[i]);
835 }
836 unregister_chrdev(major, DEVICE_NAME); 818 unregister_chrdev(major, DEVICE_NAME);
837} 819}
838 820
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 776103e56042..34597144d9c1 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -489,7 +489,7 @@ static void mgslpc_release(u_long arg);
489static int mgslpc_event(event_t event, int priority, 489static int mgslpc_event(event_t event, int priority,
490 event_callback_args_t *args); 490 event_callback_args_t *args);
491static dev_link_t *mgslpc_attach(void); 491static dev_link_t *mgslpc_attach(void);
492static void mgslpc_detach(dev_link_t *); 492static void mgslpc_detach(struct pcmcia_device *p_dev);
493 493
494static dev_info_t dev_info = "synclink_cs"; 494static dev_info_t dev_info = "synclink_cs";
495static dev_link_t *dev_list = NULL; 495static dev_link_t *dev_list = NULL;
@@ -598,7 +598,7 @@ static dev_link_t *mgslpc_attach(void)
598 ret = pcmcia_register_client(&link->handle, &client_reg); 598 ret = pcmcia_register_client(&link->handle, &client_reg);
599 if (ret != CS_SUCCESS) { 599 if (ret != CS_SUCCESS) {
600 cs_error(link->handle, RegisterClient, ret); 600 cs_error(link->handle, RegisterClient, ret);
601 mgslpc_detach(link); 601 mgslpc_detach(link->handle);
602 return NULL; 602 return NULL;
603 } 603 }
604 604
@@ -736,17 +736,16 @@ static void mgslpc_release(u_long arg)
736 pcmcia_release_io(link->handle, &link->io); 736 pcmcia_release_io(link->handle, &link->io);
737 if (link->irq.AssignedIRQ) 737 if (link->irq.AssignedIRQ)
738 pcmcia_release_irq(link->handle, &link->irq); 738 pcmcia_release_irq(link->handle, &link->irq);
739 if (link->state & DEV_STALE_LINK)
740 mgslpc_detach(link);
741} 739}
742 740
743static void mgslpc_detach(dev_link_t *link) 741static void mgslpc_detach(struct pcmcia_device *p_dev)
744{ 742{
743 dev_link_t *link = dev_to_instance(p_dev);
745 dev_link_t **linkp; 744 dev_link_t **linkp;
746 745
747 if (debug_level >= DEBUG_LEVEL_INFO) 746 if (debug_level >= DEBUG_LEVEL_INFO)
748 printk("mgslpc_detach(0x%p)\n", link); 747 printk("mgslpc_detach(0x%p)\n", link);
749 748
750 /* find device */ 749 /* find device */
751 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) 750 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
752 if (*linkp == link) break; 751 if (*linkp == link) break;
@@ -754,20 +753,10 @@ static void mgslpc_detach(dev_link_t *link)
754 return; 753 return;
755 754
756 if (link->state & DEV_CONFIG) { 755 if (link->state & DEV_CONFIG) {
757 /* device is configured/active, mark it so when 756 ((MGSLPC_INFO *)link->priv)->stop = 1;
758 * release() is called a proper detach() occurs. 757 mgslpc_release((u_long)link);
759 */
760 if (debug_level >= DEBUG_LEVEL_INFO)
761 printk(KERN_DEBUG "synclinkpc: detach postponed, '%s' "
762 "still locked\n", link->dev->dev_name);
763 link->state |= DEV_STALE_LINK;
764 return;
765 } 758 }
766 759
767 /* Break the link with Card Services */
768 if (link->handle)
769 pcmcia_deregister_client(link->handle);
770
771 /* Unlink device structure, and free it */ 760 /* Unlink device structure, and free it */
772 *linkp = link->next; 761 *linkp = link->next;
773 mgslpc_remove_device((MGSLPC_INFO *)link->priv); 762 mgslpc_remove_device((MGSLPC_INFO *)link->priv);
@@ -809,13 +798,6 @@ static int mgslpc_event(event_t event, int priority,
809 printk("mgslpc_event(0x%06x)\n", event); 798 printk("mgslpc_event(0x%06x)\n", event);
810 799
811 switch (event) { 800 switch (event) {
812 case CS_EVENT_CARD_REMOVAL:
813 link->state &= ~DEV_PRESENT;
814 if (link->state & DEV_CONFIG) {
815 ((MGSLPC_INFO *)link->priv)->stop = 1;
816 mgslpc_release((u_long)link);
817 }
818 break;
819 case CS_EVENT_CARD_INSERTION: 801 case CS_EVENT_CARD_INSERTION:
820 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 802 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
821 mgslpc_config(link); 803 mgslpc_config(link);
@@ -3102,7 +3084,7 @@ static struct pcmcia_driver mgslpc_driver = {
3102 }, 3084 },
3103 .attach = mgslpc_attach, 3085 .attach = mgslpc_attach,
3104 .event = mgslpc_event, 3086 .event = mgslpc_event,
3105 .detach = mgslpc_detach, 3087 .remove = mgslpc_detach,
3106 .id_table = mgslpc_ids, 3088 .id_table = mgslpc_ids,
3107 .suspend = mgslpc_suspend, 3089 .suspend = mgslpc_suspend,
3108 .resume = mgslpc_resume, 3090 .resume = mgslpc_resume,