aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/pcmcia
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2005-11-14 15:25:51 -0500
committerDominik Brodowski <linux@dominikbrodowski.net>2006-01-05 18:03:24 -0500
commitf8cfa618dccbdc6dab5297f75779566a388a98fd (patch)
treeb91e0952038dafc6e03bf8b1d8948b1fdefec031 /drivers/char/pcmcia
parentb463581154f3f3eecda27cae60df813fefcd84d3 (diff)
[PATCH] pcmcia: unify attach, EVENT_CARD_INSERTION handlers into one probe callback
Unify the EVENT_CARD_INSERTION and "attach" callbacks to one unified probe() callback. As all in-kernel drivers are changed to this new callback, there will be no temporary backwards-compatibility. Inside a probe() function, each driver _must_ set struct pcmcia_device *p_dev->instance and instance->handle correctly. With these patches, the basic driver interface for 16-bit PCMCIA drivers now has the classic four callbacks known also from other buses: int (*probe) (struct pcmcia_device *dev); void (*remove) (struct pcmcia_device *dev); int (*suspend) (struct pcmcia_device *dev); int (*resume) (struct pcmcia_device *dev); Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/char/pcmcia')
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c68
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c67
-rw-r--r--drivers/char/pcmcia/synclink_cs.c49
3 files changed, 30 insertions, 154 deletions
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 8a064f2f005d..649677b5dc36 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -66,7 +66,6 @@ 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(struct pcmcia_device *p_dev);
70static void cm4000_release(dev_link_t *link); 69static void cm4000_release(dev_link_t *link);
71 70
72static int major; /* major number we get from the kernel */ 71static int major; /* major number we get from the kernel */
@@ -156,7 +155,6 @@ struct cm4000_dev {
156 /*sbuf*/ 512*sizeof(char) - \ 155 /*sbuf*/ 512*sizeof(char) - \
157 /*queue*/ 4*sizeof(wait_queue_head_t)) 156 /*queue*/ 4*sizeof(wait_queue_head_t))
158 157
159static dev_info_t dev_info = MODULE_NAME;
160static dev_link_t *dev_table[CM4000_MAX_DEV]; 158static dev_link_t *dev_table[CM4000_MAX_DEV];
161 159
162/* This table doesn't use spaces after the comma between fields and thus 160/* This table doesn't use spaces after the comma between fields and thus
@@ -1864,38 +1862,6 @@ cs_release:
1864 link->state &= ~DEV_CONFIG_PENDING; 1862 link->state &= ~DEV_CONFIG_PENDING;
1865} 1863}
1866 1864
1867static int cm4000_event(event_t event, int priority,
1868 event_callback_args_t *args)
1869{
1870 dev_link_t *link;
1871 struct cm4000_dev *dev;
1872 int devno;
1873
1874 link = args->client_data;
1875 dev = link->priv;
1876
1877 DEBUGP(3, dev, "-> cm4000_event\n");
1878 for (devno = 0; devno < CM4000_MAX_DEV; devno++)
1879 if (dev_table[devno] == link)
1880 break;
1881
1882 if (devno == CM4000_MAX_DEV)
1883 return CS_BAD_ADAPTER;
1884
1885 switch (event) {
1886 case CS_EVENT_CARD_INSERTION:
1887 DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n");
1888 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1889 cm4000_config(link, devno);
1890 break;
1891 default:
1892 DEBUGP(5, dev, "unknown event %.2x\n", event);
1893 break;
1894 }
1895 DEBUGP(3, dev, "<- cm4000_event\n");
1896 return CS_SUCCESS;
1897}
1898
1899static int cm4000_suspend(struct pcmcia_device *p_dev) 1865static int cm4000_suspend(struct pcmcia_device *p_dev)
1900{ 1866{
1901 dev_link_t *link = dev_to_instance(p_dev); 1867 dev_link_t *link = dev_to_instance(p_dev);
@@ -1935,11 +1901,10 @@ static void cm4000_release(dev_link_t *link)
1935 pcmcia_release_io(link->handle, &link->io); 1901 pcmcia_release_io(link->handle, &link->io);
1936} 1902}
1937 1903
1938static dev_link_t *cm4000_attach(void) 1904static int cm4000_attach(struct pcmcia_device *p_dev)
1939{ 1905{
1940 struct cm4000_dev *dev; 1906 struct cm4000_dev *dev;
1941 dev_link_t *link; 1907 dev_link_t *link;
1942 client_reg_t client_reg;
1943 int i; 1908 int i;
1944 1909
1945 for (i = 0; i < CM4000_MAX_DEV; i++) 1910 for (i = 0; i < CM4000_MAX_DEV; i++)
@@ -1948,41 +1913,31 @@ static dev_link_t *cm4000_attach(void)
1948 1913
1949 if (i == CM4000_MAX_DEV) { 1914 if (i == CM4000_MAX_DEV) {
1950 printk(KERN_NOTICE MODULE_NAME ": all devices in use\n"); 1915 printk(KERN_NOTICE MODULE_NAME ": all devices in use\n");
1951 return NULL; 1916 return -ENODEV;
1952 } 1917 }
1953 1918
1954 /* create a new cm4000_cs device */ 1919 /* create a new cm4000_cs device */
1955 dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL); 1920 dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL);
1956 if (dev == NULL) 1921 if (dev == NULL)
1957 return NULL; 1922 return -ENOMEM;
1958 1923
1959 link = &dev->link; 1924 link = &dev->link;
1960 link->priv = dev; 1925 link->priv = dev;
1961 link->conf.IntType = INT_MEMORY_AND_IO; 1926 link->conf.IntType = INT_MEMORY_AND_IO;
1962 dev_table[i] = link; 1927 dev_table[i] = link;
1963 1928
1964 /* register with card services */
1965 client_reg.dev_info = &dev_info;
1966 client_reg.EventMask =
1967 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
1968 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
1969 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
1970 client_reg.Version = 0x0210;
1971 client_reg.event_callback_args.client_data = link;
1972
1973 i = pcmcia_register_client(&link->handle, &client_reg);
1974 if (i) {
1975 cs_error(link->handle, RegisterClient, i);
1976 cm4000_detach(link->handle);
1977 return NULL;
1978 }
1979
1980 init_waitqueue_head(&dev->devq); 1929 init_waitqueue_head(&dev->devq);
1981 init_waitqueue_head(&dev->ioq); 1930 init_waitqueue_head(&dev->ioq);
1982 init_waitqueue_head(&dev->atrq); 1931 init_waitqueue_head(&dev->atrq);
1983 init_waitqueue_head(&dev->readq); 1932 init_waitqueue_head(&dev->readq);
1984 1933
1985 return link; 1934 link->handle = p_dev;
1935 p_dev->instance = link;
1936
1937 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1938 cm4000_config(link, i);
1939
1940 return 0;
1986} 1941}
1987 1942
1988static void cm4000_detach(struct pcmcia_device *p_dev) 1943static void cm4000_detach(struct pcmcia_device *p_dev)
@@ -2031,11 +1986,10 @@ static struct pcmcia_driver cm4000_driver = {
2031 .drv = { 1986 .drv = {
2032 .name = "cm4000_cs", 1987 .name = "cm4000_cs",
2033 }, 1988 },
2034 .attach = cm4000_attach, 1989 .probe = cm4000_attach,
2035 .remove = cm4000_detach, 1990 .remove = cm4000_detach,
2036 .suspend = cm4000_suspend, 1991 .suspend = cm4000_suspend,
2037 .resume = cm4000_resume, 1992 .resume = cm4000_resume,
2038 .event = cm4000_event,
2039 .id_table = cm4000_ids, 1993 .id_table = cm4000_ids,
2040}; 1994};
2041 1995
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index e08ab949c116..46eb371bf17e 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -65,7 +65,6 @@ 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(struct pcmcia_device *p_dev);
69 68
70static int major; 69static int major;
71 70
@@ -86,7 +85,6 @@ struct reader_dev {
86 struct timer_list poll_timer; 85 struct timer_list poll_timer;
87}; 86};
88 87
89static dev_info_t dev_info = MODULE_NAME;
90static dev_link_t *dev_table[CM_MAX_DEV]; 88static dev_link_t *dev_table[CM_MAX_DEV];
91 89
92#ifndef PCMCIA_DEBUG 90#ifndef PCMCIA_DEBUG
@@ -629,39 +627,6 @@ cs_release:
629 link->state &= ~DEV_CONFIG_PENDING; 627 link->state &= ~DEV_CONFIG_PENDING;
630} 628}
631 629
632static int reader_event(event_t event, int priority,
633 event_callback_args_t *args)
634{
635 dev_link_t *link;
636 struct reader_dev *dev;
637 int devno;
638
639 link = args->client_data;
640 dev = link->priv;
641 DEBUGP(3, dev, "-> reader_event\n");
642 for (devno = 0; devno < CM_MAX_DEV; devno++) {
643 if (dev_table[devno] == link)
644 break;
645 }
646 if (devno == CM_MAX_DEV)
647 return CS_BAD_ADAPTER;
648
649 switch (event) {
650 case CS_EVENT_CARD_INSERTION:
651 DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n");
652 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
653 reader_config(link, devno);
654 break;
655
656 default:
657 DEBUGP(5, dev, "reader_event: unknown event %.2x\n",
658 event);
659 break;
660 }
661 DEBUGP(3, dev, "<- reader_event\n");
662 return CS_SUCCESS;
663}
664
665static int reader_suspend(struct pcmcia_device *p_dev) 630static int reader_suspend(struct pcmcia_device *p_dev)
666{ 631{
667 dev_link_t *link = dev_to_instance(p_dev); 632 dev_link_t *link = dev_to_instance(p_dev);
@@ -691,11 +656,10 @@ static void reader_release(dev_link_t *link)
691 pcmcia_release_io(link->handle, &link->io); 656 pcmcia_release_io(link->handle, &link->io);
692} 657}
693 658
694static dev_link_t *reader_attach(void) 659static int reader_attach(struct pcmcia_device *p_dev)
695{ 660{
696 struct reader_dev *dev; 661 struct reader_dev *dev;
697 dev_link_t *link; 662 dev_link_t *link;
698 client_reg_t client_reg;
699 int i; 663 int i;
700 664
701 for (i = 0; i < CM_MAX_DEV; i++) { 665 for (i = 0; i < CM_MAX_DEV; i++) {
@@ -704,11 +668,11 @@ static dev_link_t *reader_attach(void)
704 } 668 }
705 669
706 if (i == CM_MAX_DEV) 670 if (i == CM_MAX_DEV)
707 return NULL; 671 return -ENODEV;
708 672
709 dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL); 673 dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL);
710 if (dev == NULL) 674 if (dev == NULL)
711 return NULL; 675 return -ENOMEM;
712 676
713 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT; 677 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
714 dev->buffer_status = 0; 678 dev->buffer_status = 0;
@@ -719,20 +683,6 @@ static dev_link_t *reader_attach(void)
719 link->conf.IntType = INT_MEMORY_AND_IO; 683 link->conf.IntType = INT_MEMORY_AND_IO;
720 dev_table[i] = link; 684 dev_table[i] = link;
721 685
722 client_reg.dev_info = &dev_info;
723 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
724 client_reg.EventMask=
725 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
726 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
727 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
728 client_reg.Version = 0x0210;
729 client_reg.event_callback_args.client_data = link;
730 i = pcmcia_register_client(&link->handle, &client_reg);
731 if (i) {
732 cs_error(link->handle, RegisterClient, i);
733 reader_detach(link->handle);
734 return NULL;
735 }
736 init_waitqueue_head(&dev->devq); 686 init_waitqueue_head(&dev->devq);
737 init_waitqueue_head(&dev->poll_wait); 687 init_waitqueue_head(&dev->poll_wait);
738 init_waitqueue_head(&dev->read_wait); 688 init_waitqueue_head(&dev->read_wait);
@@ -740,7 +690,13 @@ static dev_link_t *reader_attach(void)
740 init_timer(&dev->poll_timer); 690 init_timer(&dev->poll_timer);
741 dev->poll_timer.function = &cm4040_do_poll; 691 dev->poll_timer.function = &cm4040_do_poll;
742 692
743 return link; 693 link->handle = p_dev;
694 p_dev->instance = link;
695
696 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
697 reader_config(link, i);
698
699 return 0;
744} 700}
745 701
746static void reader_detach(struct pcmcia_device *p_dev) 702static void reader_detach(struct pcmcia_device *p_dev)
@@ -790,11 +746,10 @@ static struct pcmcia_driver reader_driver = {
790 .drv = { 746 .drv = {
791 .name = "cm4040_cs", 747 .name = "cm4040_cs",
792 }, 748 },
793 .attach = reader_attach, 749 .probe = reader_attach,
794 .remove = reader_detach, 750 .remove = reader_detach,
795 .suspend = reader_suspend, 751 .suspend = reader_suspend,
796 .resume = reader_resume, 752 .resume = reader_resume,
797 .event = reader_event,
798 .id_table = cm4040_ids, 753 .id_table = cm4040_ids,
799}; 754};
800 755
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index dc38b1d0a725..cf45b100eff1 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -486,13 +486,8 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout);
486 486
487static void mgslpc_config(dev_link_t *link); 487static void mgslpc_config(dev_link_t *link);
488static void mgslpc_release(u_long arg); 488static void mgslpc_release(u_long arg);
489static int mgslpc_event(event_t event, int priority,
490 event_callback_args_t *args);
491static dev_link_t *mgslpc_attach(void);
492static void mgslpc_detach(struct pcmcia_device *p_dev); 489static void mgslpc_detach(struct pcmcia_device *p_dev);
493 490
494static dev_info_t dev_info = "synclink_cs";
495
496/* 491/*
497 * 1st function defined in .text section. Calling this function in 492 * 1st function defined in .text section. Calling this function in
498 * init_module() followed by a breakpoint allows a remote debugger 493 * init_module() followed by a breakpoint allows a remote debugger
@@ -538,12 +533,10 @@ static void ldisc_receive_buf(struct tty_struct *tty,
538 } 533 }
539} 534}
540 535
541static dev_link_t *mgslpc_attach(void) 536static int mgslpc_attach(struct pcmcia_device *p_dev)
542{ 537{
543 MGSLPC_INFO *info; 538 MGSLPC_INFO *info;
544 dev_link_t *link; 539 dev_link_t *link;
545 client_reg_t client_reg;
546 int ret;
547 540
548 if (debug_level >= DEBUG_LEVEL_INFO) 541 if (debug_level >= DEBUG_LEVEL_INFO)
549 printk("mgslpc_attach\n"); 542 printk("mgslpc_attach\n");
@@ -551,7 +544,7 @@ static dev_link_t *mgslpc_attach(void)
551 info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); 544 info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
552 if (!info) { 545 if (!info) {
553 printk("Error can't allocate device instance data\n"); 546 printk("Error can't allocate device instance data\n");
554 return NULL; 547 return -ENOMEM;
555 } 548 }
556 549
557 memset(info, 0, sizeof(MGSLPC_INFO)); 550 memset(info, 0, sizeof(MGSLPC_INFO));
@@ -586,23 +579,15 @@ static dev_link_t *mgslpc_attach(void)
586 link->conf.Vcc = 50; 579 link->conf.Vcc = 50;
587 link->conf.IntType = INT_MEMORY_AND_IO; 580 link->conf.IntType = INT_MEMORY_AND_IO;
588 581
589 /* Register with Card Services */ 582 link->handle = p_dev;
590 link->next = NULL; 583 p_dev->instance = link;
591
592 client_reg.dev_info = &dev_info;
593 client_reg.Version = 0x0210;
594 client_reg.event_callback_args.client_data = link;
595 584
596 ret = pcmcia_register_client(&link->handle, &client_reg); 585 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
597 if (ret != CS_SUCCESS) { 586 mgslpc_config(link);
598 cs_error(link->handle, RegisterClient, ret);
599 mgslpc_detach(link->handle);
600 return NULL;
601 }
602 587
603 mgslpc_add_device(info); 588 mgslpc_add_device(info);
604 589
605 return link; 590 return 0;
606} 591}
607 592
608/* Card has been inserted. 593/* Card has been inserted.
@@ -778,23 +763,6 @@ static int mgslpc_resume(struct pcmcia_device *dev)
778} 763}
779 764
780 765
781static int mgslpc_event(event_t event, int priority,
782 event_callback_args_t *args)
783{
784 dev_link_t *link = args->client_data;
785
786 if (debug_level >= DEBUG_LEVEL_INFO)
787 printk("mgslpc_event(0x%06x)\n", event);
788
789 switch (event) {
790 case CS_EVENT_CARD_INSERTION:
791 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
792 mgslpc_config(link);
793 break;
794 }
795 return 0;
796}
797
798static inline int mgslpc_paranoia_check(MGSLPC_INFO *info, 766static inline int mgslpc_paranoia_check(MGSLPC_INFO *info,
799 char *name, const char *routine) 767 char *name, const char *routine)
800{ 768{
@@ -3071,8 +3039,7 @@ static struct pcmcia_driver mgslpc_driver = {
3071 .drv = { 3039 .drv = {
3072 .name = "synclink_cs", 3040 .name = "synclink_cs",
3073 }, 3041 },
3074 .attach = mgslpc_attach, 3042 .probe = mgslpc_attach,
3075 .event = mgslpc_event,
3076 .remove = mgslpc_detach, 3043 .remove = mgslpc_detach,
3077 .id_table = mgslpc_ids, 3044 .id_table = mgslpc_ids,
3078 .suspend = mgslpc_suspend, 3045 .suspend = mgslpc_suspend,