aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pcmcia/cs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pcmcia/cs.c')
-rw-r--r--drivers/pcmcia/cs.c1164
1 files changed, 91 insertions, 1073 deletions
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 48e4f04530d8..e82859d3227a 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -43,36 +43,11 @@
43#include <pcmcia/ds.h> 43#include <pcmcia/ds.h>
44#include "cs_internal.h" 44#include "cs_internal.h"
45 45
46#ifdef CONFIG_PCI
47#define PCI_OPT " [pci]"
48#else
49#define PCI_OPT ""
50#endif
51#ifdef CONFIG_CARDBUS
52#define CB_OPT " [cardbus]"
53#else
54#define CB_OPT ""
55#endif
56#ifdef CONFIG_PM
57#define PM_OPT " [pm]"
58#else
59#define PM_OPT ""
60#endif
61#if !defined(CONFIG_CARDBUS) && !defined(CONFIG_PCI) && !defined(CONFIG_PM)
62#define OPTIONS " none"
63#else
64#define OPTIONS PCI_OPT CB_OPT PM_OPT
65#endif
66
67static const char *release = "Linux Kernel Card Services";
68static const char *options = "options: " OPTIONS;
69
70/*====================================================================*/
71 46
72/* Module parameters */ 47/* Module parameters */
73 48
74MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); 49MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
75MODULE_DESCRIPTION("Linux Kernel Card Services\noptions:" OPTIONS); 50MODULE_DESCRIPTION("Linux Kernel Card Services");
76MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
77 52
78#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444) 53#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
@@ -89,9 +64,6 @@ INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */
89/* Access speed for attribute memory windows */ 64/* Access speed for attribute memory windows */
90INT_MODULE_PARM(cis_speed, 300); /* ns */ 65INT_MODULE_PARM(cis_speed, 300); /* ns */
91 66
92/* Access speed for IO windows */
93INT_MODULE_PARM(io_speed, 0); /* ns */
94
95#ifdef DEBUG 67#ifdef DEBUG
96static int pc_debug; 68static int pc_debug;
97 69
@@ -103,34 +75,26 @@ int cs_debug_level(int level)
103} 75}
104#endif 76#endif
105 77
106/*====================================================================*/
107 78
108socket_state_t dead_socket = { 79socket_state_t dead_socket = {
109 .csc_mask = SS_DETECT, 80 .csc_mask = SS_DETECT,
110}; 81};
82EXPORT_SYMBOL(dead_socket);
111 83
112 84
113/* List of all sockets, protected by a rwsem */ 85/* List of all sockets, protected by a rwsem */
114LIST_HEAD(pcmcia_socket_list); 86LIST_HEAD(pcmcia_socket_list);
115DECLARE_RWSEM(pcmcia_socket_list_rwsem);
116EXPORT_SYMBOL(pcmcia_socket_list); 87EXPORT_SYMBOL(pcmcia_socket_list);
117EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
118
119 88
120#ifdef CONFIG_PCMCIA_PROBE 89DECLARE_RWSEM(pcmcia_socket_list_rwsem);
121/* mask ofIRQs already reserved by other cards, we should avoid using them */ 90EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
122static u8 pcmcia_used_irq[NR_IRQS];
123#endif
124 91
125/*====================================================================
126
127 Low-level PC Card interface drivers need to register with Card
128 Services using these calls.
129
130======================================================================*/
131 92
132/** 93/**
133 * socket drivers are expected to use the following callbacks in their 94 * Low-level PCMCIA socket drivers need to register with the PCCard
95 * core using pcmcia_register_socket.
96 *
97 * socket drivers are expected to use the following callbacks in their
134 * .drv struct: 98 * .drv struct:
135 * - pcmcia_socket_dev_suspend 99 * - pcmcia_socket_dev_suspend
136 * - pcmcia_socket_dev_resume 100 * - pcmcia_socket_dev_resume
@@ -230,8 +194,8 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
230 } 194 }
231 195
232 /* try to obtain a socket number [yes, it gets ugly if we 196 /* try to obtain a socket number [yes, it gets ugly if we
233 * register more than 2^sizeof(unsigned int) pcmcia 197 * register more than 2^sizeof(unsigned int) pcmcia
234 * sockets... but the socket number is deprecated 198 * sockets... but the socket number is deprecated
235 * anyways, so I don't care] */ 199 * anyways, so I don't care] */
236 down_write(&pcmcia_socket_list_rwsem); 200 down_write(&pcmcia_socket_list_rwsem);
237 if (list_empty(&pcmcia_socket_list)) 201 if (list_empty(&pcmcia_socket_list))
@@ -340,54 +304,49 @@ struct pcmcia_socket * pcmcia_get_socket_by_nr(unsigned int nr)
340EXPORT_SYMBOL(pcmcia_get_socket_by_nr); 304EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
341 305
342 306
343/*====================================================================== 307/**
344 308 * socket_setup() and shutdown_socket() are called by the main event
345 socket_setup() and shutdown_socket() are called by the main event 309 * handler when card insertion and removal events are received.
346 handler when card insertion and removal events are received. 310 * socket_setup() turns on socket power and resets the socket, in two stages.
347 socket_setup() turns on socket power and resets the socket, in two stages. 311 * shutdown_socket() unconfigures a socket and turns off socket power.
348 shutdown_socket() unconfigures a socket and turns off socket power. 312 */
349
350======================================================================*/
351
352static void shutdown_socket(struct pcmcia_socket *s) 313static void shutdown_socket(struct pcmcia_socket *s)
353{ 314{
354 cs_dbg(s, 1, "shutdown_socket\n"); 315 cs_dbg(s, 1, "shutdown_socket\n");
355 316
356 /* Blank out the socket state */ 317 /* Blank out the socket state */
357 s->socket = dead_socket; 318 s->socket = dead_socket;
358 s->ops->init(s); 319 s->ops->init(s);
359 s->ops->set_socket(s, &s->socket); 320 s->ops->set_socket(s, &s->socket);
360 s->irq.AssignedIRQ = s->irq.Config = 0; 321 s->irq.AssignedIRQ = s->irq.Config = 0;
361 s->lock_count = 0; 322 s->lock_count = 0;
362 destroy_cis_cache(s); 323 destroy_cis_cache(s);
363#ifdef CONFIG_CARDBUS 324#ifdef CONFIG_CARDBUS
364 cb_free(s); 325 cb_free(s);
365#endif 326#endif
366 s->functions = 0; 327 s->functions = 0;
367 if (s->config) { 328 if (s->config) {
368 kfree(s->config); 329 kfree(s->config);
369 s->config = NULL; 330 s->config = NULL;
370 }
371
372 {
373 int status;
374 s->ops->get_status(s, &status);
375 if (status & SS_POWERON) {
376 printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s);
377 } 331 }
378 }
379} /* shutdown_socket */
380 332
381/*====================================================================== 333 {
334 int status;
335 s->ops->get_status(s, &status);
336 if (status & SS_POWERON) {
337 printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s);
338 }
339 }
340} /* shutdown_socket */
382 341
383 The central event handler. Send_event() sends an event to the
384 16-bit subsystem, which then calls the relevant device drivers.
385 Parse_events() interprets the event bits from
386 a card status change report. Do_shutdown() handles the high
387 priority stuff associated with a card removal.
388
389======================================================================*/
390 342
343/**
344 * The central event handler. Send_event() sends an event to the
345 * 16-bit subsystem, which then calls the relevant device drivers.
346 * Parse_events() interprets the event bits from
347 * a card status change report. Do_shutdown() handles the high
348 * priority stuff associated with a card removal.
349 */
391 350
392/* NOTE: send_event needs to be called with skt->sem held. */ 351/* NOTE: send_event needs to be called with skt->sem held. */
393 352
@@ -746,420 +705,9 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
746 wake_up(&s->thread_wait); 705 wake_up(&s->thread_wait);
747 } 706 }
748} /* pcmcia_parse_events */ 707} /* pcmcia_parse_events */
708EXPORT_SYMBOL(pcmcia_parse_events);
749 709
750 710
751/*======================================================================
752
753 Special stuff for managing IO windows, because they are scarce.
754
755======================================================================*/
756
757static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
758 ioaddr_t num, u_int lines)
759{
760 int i;
761 kio_addr_t try, align;
762
763 align = (*base) ? (lines ? 1<<lines : 0) : 1;
764 if (align && (align < num)) {
765 if (*base) {
766 cs_dbg(s, 0, "odd IO request: num %#x align %#lx\n",
767 num, align);
768 align = 0;
769 } else
770 while (align && (align < num)) align <<= 1;
771 }
772 if (*base & ~(align-1)) {
773 cs_dbg(s, 0, "odd IO request: base %#x align %#lx\n",
774 *base, align);
775 align = 0;
776 }
777 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
778 *base = s->io_offset | (*base & 0x0fff);
779 return 0;
780 }
781 /* Check for an already-allocated window that must conflict with
782 what was asked for. It is a hack because it does not catch all
783 potential conflicts, just the most obvious ones. */
784 for (i = 0; i < MAX_IO_WIN; i++)
785 if ((s->io[i].NumPorts != 0) &&
786 ((s->io[i].BasePort & (align-1)) == *base))
787 return 1;
788 for (i = 0; i < MAX_IO_WIN; i++) {
789 if (s->io[i].NumPorts == 0) {
790 s->io[i].res = find_io_region(*base, num, align, s);
791 if (s->io[i].res) {
792 s->io[i].Attributes = attr;
793 s->io[i].BasePort = *base = s->io[i].res->start;
794 s->io[i].NumPorts = s->io[i].InUse = num;
795 break;
796 } else
797 return 1;
798 } else if (s->io[i].Attributes != attr)
799 continue;
800 /* Try to extend top of window */
801 try = s->io[i].BasePort + s->io[i].NumPorts;
802 if ((*base == 0) || (*base == try))
803 if (adjust_io_region(s->io[i].res, s->io[i].res->start,
804 s->io[i].res->end + num, s) == 0) {
805 *base = try;
806 s->io[i].NumPorts += num;
807 s->io[i].InUse += num;
808 break;
809 }
810 /* Try to extend bottom of window */
811 try = s->io[i].BasePort - num;
812 if ((*base == 0) || (*base == try))
813 if (adjust_io_region(s->io[i].res, s->io[i].res->start - num,
814 s->io[i].res->end, s) == 0) {
815 s->io[i].BasePort = *base = try;
816 s->io[i].NumPorts += num;
817 s->io[i].InUse += num;
818 break;
819 }
820 }
821 return (i == MAX_IO_WIN);
822} /* alloc_io_space */
823
824static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
825 ioaddr_t num)
826{
827 int i;
828
829 for (i = 0; i < MAX_IO_WIN; i++) {
830 if ((s->io[i].BasePort <= base) &&
831 (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) {
832 s->io[i].InUse -= num;
833 /* Free the window if no one else is using it */
834 if (s->io[i].InUse == 0) {
835 s->io[i].NumPorts = 0;
836 release_resource(s->io[i].res);
837 kfree(s->io[i].res);
838 s->io[i].res = NULL;
839 }
840 }
841 }
842}
843
844/*======================================================================
845
846 Access_configuration_register() reads and writes configuration
847 registers in attribute memory. Memory window 0 is reserved for
848 this and the tuple reading services.
849
850======================================================================*/
851
852int pccard_access_configuration_register(struct pcmcia_socket *s,
853 unsigned int function,
854 conf_reg_t *reg)
855{
856 config_t *c;
857 int addr;
858 u_char val;
859
860 if (!s || !s->config)
861 return CS_NO_CARD;
862
863 c = &s->config[function];
864
865 if (c == NULL)
866 return CS_NO_CARD;
867
868 if (!(c->state & CONFIG_LOCKED))
869 return CS_CONFIGURATION_LOCKED;
870
871 addr = (c->ConfigBase + reg->Offset) >> 1;
872
873 switch (reg->Action) {
874 case CS_READ:
875 read_cis_mem(s, 1, addr, 1, &val);
876 reg->Value = val;
877 break;
878 case CS_WRITE:
879 val = reg->Value;
880 write_cis_mem(s, 1, addr, 1, &val);
881 break;
882 default:
883 return CS_BAD_ARGS;
884 break;
885 }
886 return CS_SUCCESS;
887} /* access_configuration_register */
888EXPORT_SYMBOL(pccard_access_configuration_register);
889
890
891/*====================================================================*/
892
893int pccard_get_configuration_info(struct pcmcia_socket *s,
894 unsigned int function,
895 config_info_t *config)
896{
897 config_t *c;
898
899 if (!(s->state & SOCKET_PRESENT))
900 return CS_NO_CARD;
901
902 config->Function = function;
903
904#ifdef CONFIG_CARDBUS
905 if (s->state & SOCKET_CARDBUS) {
906 memset(config, 0, sizeof(config_info_t));
907 config->Vcc = s->socket.Vcc;
908 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
909 config->Option = s->cb_dev->subordinate->number;
910 if (s->state & SOCKET_CARDBUS_CONFIG) {
911 config->Attributes = CONF_VALID_CLIENT;
912 config->IntType = INT_CARDBUS;
913 config->AssignedIRQ = s->irq.AssignedIRQ;
914 if (config->AssignedIRQ)
915 config->Attributes |= CONF_ENABLE_IRQ;
916 config->BasePort1 = s->io[0].BasePort;
917 config->NumPorts1 = s->io[0].NumPorts;
918 }
919 return CS_SUCCESS;
920 }
921#endif
922
923 c = (s->config != NULL) ? &s->config[function] : NULL;
924
925 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
926 config->Attributes = 0;
927 config->Vcc = s->socket.Vcc;
928 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
929 return CS_SUCCESS;
930 }
931
932 /* !!! This is a hack !!! */
933 memcpy(&config->Attributes, &c->Attributes, sizeof(config_t));
934 config->Attributes |= CONF_VALID_CLIENT;
935 config->CardValues = c->CardValues;
936 config->IRQAttributes = c->irq.Attributes;
937 config->AssignedIRQ = s->irq.AssignedIRQ;
938 config->BasePort1 = c->io.BasePort1;
939 config->NumPorts1 = c->io.NumPorts1;
940 config->Attributes1 = c->io.Attributes1;
941 config->BasePort2 = c->io.BasePort2;
942 config->NumPorts2 = c->io.NumPorts2;
943 config->Attributes2 = c->io.Attributes2;
944 config->IOAddrLines = c->io.IOAddrLines;
945
946 return CS_SUCCESS;
947} /* get_configuration_info */
948EXPORT_SYMBOL(pccard_get_configuration_info);
949
950/*======================================================================
951
952 Return information about this version of Card Services.
953
954======================================================================*/
955
956int pcmcia_get_card_services_info(servinfo_t *info)
957{
958 unsigned int socket_count = 0;
959 struct list_head *tmp;
960 info->Signature[0] = 'C';
961 info->Signature[1] = 'S';
962 down_read(&pcmcia_socket_list_rwsem);
963 list_for_each(tmp, &pcmcia_socket_list)
964 socket_count++;
965 up_read(&pcmcia_socket_list_rwsem);
966 info->Count = socket_count;
967 info->Revision = CS_RELEASE_CODE;
968 info->CSLevel = 0x0210;
969 info->VendorString = (char *)release;
970 return CS_SUCCESS;
971} /* get_card_services_info */
972
973
974/*====================================================================*/
975
976int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req)
977{
978 window_t *win;
979 int w;
980
981 if (!s || !(s->state & SOCKET_PRESENT))
982 return CS_NO_CARD;
983 for (w = idx; w < MAX_WIN; w++)
984 if (s->state & SOCKET_WIN_REQ(w)) break;
985 if (w == MAX_WIN)
986 return CS_NO_MORE_ITEMS;
987 win = &s->win[w];
988 req->Base = win->ctl.res->start;
989 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
990 req->AccessSpeed = win->ctl.speed;
991 req->Attributes = 0;
992 if (win->ctl.flags & MAP_ATTRIB)
993 req->Attributes |= WIN_MEMORY_TYPE_AM;
994 if (win->ctl.flags & MAP_ACTIVE)
995 req->Attributes |= WIN_ENABLE;
996 if (win->ctl.flags & MAP_16BIT)
997 req->Attributes |= WIN_DATA_WIDTH_16;
998 if (win->ctl.flags & MAP_USE_WAIT)
999 req->Attributes |= WIN_USE_WAIT;
1000 *handle = win;
1001 return CS_SUCCESS;
1002} /* get_window */
1003EXPORT_SYMBOL(pcmcia_get_window);
1004
1005/*=====================================================================
1006
1007 Return the PCI device associated with a card..
1008
1009======================================================================*/
1010
1011#ifdef CONFIG_CARDBUS
1012
1013struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
1014{
1015 if (!s || !(s->state & SOCKET_CARDBUS))
1016 return NULL;
1017
1018 return s->cb_dev->subordinate;
1019}
1020
1021EXPORT_SYMBOL(pcmcia_lookup_bus);
1022
1023#endif
1024
1025/*======================================================================
1026
1027 Get the current socket state bits. We don't support the latched
1028 SocketState yet: I haven't seen any point for it.
1029
1030======================================================================*/
1031
1032int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status)
1033{
1034 config_t *c;
1035 int val;
1036
1037 s->ops->get_status(s, &val);
1038 status->CardState = status->SocketState = 0;
1039 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
1040 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
1041 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
1042 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
1043 if (s->state & SOCKET_SUSPEND)
1044 status->CardState |= CS_EVENT_PM_SUSPEND;
1045 if (!(s->state & SOCKET_PRESENT))
1046 return CS_NO_CARD;
1047
1048 c = (s->config != NULL) ? &s->config[function] : NULL;
1049 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
1050 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
1051 u_char reg;
1052 if (c->Present & PRESENT_PIN_REPLACE) {
1053 read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
1054 status->CardState |=
1055 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
1056 status->CardState |=
1057 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
1058 status->CardState |=
1059 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
1060 status->CardState |=
1061 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
1062 } else {
1063 /* No PRR? Then assume we're always ready */
1064 status->CardState |= CS_EVENT_READY_CHANGE;
1065 }
1066 if (c->Present & PRESENT_EXT_STATUS) {
1067 read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
1068 status->CardState |=
1069 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
1070 }
1071 return CS_SUCCESS;
1072 }
1073 status->CardState |=
1074 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
1075 status->CardState |=
1076 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
1077 status->CardState |=
1078 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
1079 status->CardState |=
1080 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
1081 return CS_SUCCESS;
1082} /* get_status */
1083EXPORT_SYMBOL(pccard_get_status);
1084
1085/*======================================================================
1086
1087 Change the card address of an already open memory window.
1088
1089======================================================================*/
1090
1091int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
1092{
1093 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1094 return CS_BAD_HANDLE;
1095 req->Page = 0;
1096 req->CardOffset = win->ctl.card_start;
1097 return CS_SUCCESS;
1098} /* get_mem_page */
1099
1100int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
1101{
1102 struct pcmcia_socket *s;
1103 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1104 return CS_BAD_HANDLE;
1105 if (req->Page != 0)
1106 return CS_BAD_PAGE;
1107 s = win->sock;
1108 win->ctl.card_start = req->CardOffset;
1109 if (s->ops->set_mem_map(s, &win->ctl) != 0)
1110 return CS_BAD_OFFSET;
1111 return CS_SUCCESS;
1112} /* map_mem_page */
1113
1114/*======================================================================
1115
1116 Modify a locked socket configuration
1117
1118======================================================================*/
1119
1120int pcmcia_modify_configuration(client_handle_t handle,
1121 modconf_t *mod)
1122{
1123 struct pcmcia_socket *s;
1124 config_t *c;
1125
1126 if (CHECK_HANDLE(handle))
1127 return CS_BAD_HANDLE;
1128 s = SOCKET(handle); c = CONFIG(handle);
1129 if (!(s->state & SOCKET_PRESENT))
1130 return CS_NO_CARD;
1131 if (!(c->state & CONFIG_LOCKED))
1132 return CS_CONFIGURATION_LOCKED;
1133
1134 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
1135 if (mod->Attributes & CONF_ENABLE_IRQ) {
1136 c->Attributes |= CONF_ENABLE_IRQ;
1137 s->socket.io_irq = s->irq.AssignedIRQ;
1138 } else {
1139 c->Attributes &= ~CONF_ENABLE_IRQ;
1140 s->socket.io_irq = 0;
1141 }
1142 s->ops->set_socket(s, &s->socket);
1143 }
1144
1145 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
1146 return CS_BAD_VCC;
1147
1148 /* We only allow changing Vpp1 and Vpp2 to the same value */
1149 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
1150 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
1151 if (mod->Vpp1 != mod->Vpp2)
1152 return CS_BAD_VPP;
1153 c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1;
1154 if (s->ops->set_socket(s, &s->socket))
1155 return CS_BAD_VPP;
1156 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
1157 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
1158 return CS_BAD_VPP;
1159
1160 return CS_SUCCESS;
1161} /* modify_configuration */
1162
1163/* register pcmcia_callback */ 711/* register pcmcia_callback */
1164int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) 712int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
1165{ 713{
@@ -1188,543 +736,16 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
1188} 736}
1189EXPORT_SYMBOL(pccard_register_pcmcia); 737EXPORT_SYMBOL(pccard_register_pcmcia);
1190 738
1191/*====================================================================*/
1192 739
1193int pcmcia_release_configuration(client_handle_t handle) 740/* I'm not sure which "reset" function this is supposed to use,
1194{ 741 * but for now, it uses the low-level interface's reset, not the
1195 pccard_io_map io = { 0, 0, 0, 0, 1 }; 742 * CIS register.
1196 struct pcmcia_socket *s; 743 */
1197 int i;
1198
1199 if (CHECK_HANDLE(handle) ||
1200 !(handle->state & CLIENT_CONFIG_LOCKED))
1201 return CS_BAD_HANDLE;
1202 handle->state &= ~CLIENT_CONFIG_LOCKED;
1203 s = SOCKET(handle);
1204
1205#ifdef CONFIG_CARDBUS
1206 if (handle->state & CLIENT_CARDBUS)
1207 return CS_SUCCESS;
1208#endif
1209
1210 if (!(handle->state & CLIENT_STALE)) {
1211 config_t *c = CONFIG(handle);
1212 if (--(s->lock_count) == 0) {
1213 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
1214 s->socket.Vpp = 0;
1215 s->socket.io_irq = 0;
1216 s->ops->set_socket(s, &s->socket);
1217 }
1218 if (c->state & CONFIG_IO_REQ)
1219 for (i = 0; i < MAX_IO_WIN; i++) {
1220 if (s->io[i].NumPorts == 0)
1221 continue;
1222 s->io[i].Config--;
1223 if (s->io[i].Config != 0)
1224 continue;
1225 io.map = i;
1226 s->ops->set_io_map(s, &io);
1227 }
1228 c->state &= ~CONFIG_LOCKED;
1229 }
1230
1231 return CS_SUCCESS;
1232} /* release_configuration */
1233
1234/*======================================================================
1235
1236 Release_io() releases the I/O ranges allocated by a client. This
1237 may be invoked some time after a card ejection has already dumped
1238 the actual socket configuration, so if the client is "stale", we
1239 don't bother checking the port ranges against the current socket
1240 values.
1241
1242======================================================================*/
1243
1244int pcmcia_release_io(client_handle_t handle, io_req_t *req)
1245{
1246 struct pcmcia_socket *s;
1247
1248 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IO_REQ))
1249 return CS_BAD_HANDLE;
1250 handle->state &= ~CLIENT_IO_REQ;
1251 s = SOCKET(handle);
1252
1253#ifdef CONFIG_CARDBUS
1254 if (handle->state & CLIENT_CARDBUS)
1255 return CS_SUCCESS;
1256#endif
1257
1258 if (!(handle->state & CLIENT_STALE)) {
1259 config_t *c = CONFIG(handle);
1260 if (c->state & CONFIG_LOCKED)
1261 return CS_CONFIGURATION_LOCKED;
1262 if ((c->io.BasePort1 != req->BasePort1) ||
1263 (c->io.NumPorts1 != req->NumPorts1) ||
1264 (c->io.BasePort2 != req->BasePort2) ||
1265 (c->io.NumPorts2 != req->NumPorts2))
1266 return CS_BAD_ARGS;
1267 c->state &= ~CONFIG_IO_REQ;
1268 }
1269
1270 release_io_space(s, req->BasePort1, req->NumPorts1);
1271 if (req->NumPorts2)
1272 release_io_space(s, req->BasePort2, req->NumPorts2);
1273
1274 return CS_SUCCESS;
1275} /* release_io */
1276
1277/*====================================================================*/
1278
1279int pcmcia_release_irq(client_handle_t handle, irq_req_t *req)
1280{
1281 struct pcmcia_socket *s;
1282 if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IRQ_REQ))
1283 return CS_BAD_HANDLE;
1284 handle->state &= ~CLIENT_IRQ_REQ;
1285 s = SOCKET(handle);
1286
1287 if (!(handle->state & CLIENT_STALE)) {
1288 config_t *c = CONFIG(handle);
1289 if (c->state & CONFIG_LOCKED)
1290 return CS_CONFIGURATION_LOCKED;
1291 if (c->irq.Attributes != req->Attributes)
1292 return CS_BAD_ATTRIBUTE;
1293 if (s->irq.AssignedIRQ != req->AssignedIRQ)
1294 return CS_BAD_IRQ;
1295 if (--s->irq.Config == 0) {
1296 c->state &= ~CONFIG_IRQ_REQ;
1297 s->irq.AssignedIRQ = 0;
1298 }
1299 }
1300
1301 if (req->Attributes & IRQ_HANDLE_PRESENT) {
1302 free_irq(req->AssignedIRQ, req->Instance);
1303 }
1304
1305#ifdef CONFIG_PCMCIA_PROBE
1306 pcmcia_used_irq[req->AssignedIRQ]--;
1307#endif
1308
1309 return CS_SUCCESS;
1310} /* cs_release_irq */
1311
1312/*====================================================================*/
1313
1314int pcmcia_release_window(window_handle_t win)
1315{
1316 struct pcmcia_socket *s;
1317
1318 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
1319 return CS_BAD_HANDLE;
1320 s = win->sock;
1321 if (!(win->handle->state & CLIENT_WIN_REQ(win->index)))
1322 return CS_BAD_HANDLE;
1323
1324 /* Shut down memory window */
1325 win->ctl.flags &= ~MAP_ACTIVE;
1326 s->ops->set_mem_map(s, &win->ctl);
1327 s->state &= ~SOCKET_WIN_REQ(win->index);
1328
1329 /* Release system memory */
1330 if (win->ctl.res) {
1331 release_resource(win->ctl.res);
1332 kfree(win->ctl.res);
1333 win->ctl.res = NULL;
1334 }
1335 win->handle->state &= ~CLIENT_WIN_REQ(win->index);
1336
1337 win->magic = 0;
1338
1339 return CS_SUCCESS;
1340} /* release_window */
1341
1342/*====================================================================*/
1343
1344int pcmcia_request_configuration(client_handle_t handle,
1345 config_req_t *req)
1346{
1347 int i;
1348 u_int base;
1349 struct pcmcia_socket *s;
1350 config_t *c;
1351 pccard_io_map iomap;
1352
1353 if (CHECK_HANDLE(handle))
1354 return CS_BAD_HANDLE;
1355 s = SOCKET(handle);
1356 if (!(s->state & SOCKET_PRESENT))
1357 return CS_NO_CARD;
1358
1359#ifdef CONFIG_CARDBUS
1360 if (handle->state & CLIENT_CARDBUS)
1361 return CS_UNSUPPORTED_MODE;
1362#endif
1363
1364 if (req->IntType & INT_CARDBUS)
1365 return CS_UNSUPPORTED_MODE;
1366 c = CONFIG(handle);
1367 if (c->state & CONFIG_LOCKED)
1368 return CS_CONFIGURATION_LOCKED;
1369
1370 /* Do power control. We don't allow changes in Vcc. */
1371 if (s->socket.Vcc != req->Vcc)
1372 return CS_BAD_VCC;
1373 if (req->Vpp1 != req->Vpp2)
1374 return CS_BAD_VPP;
1375 s->socket.Vpp = req->Vpp1;
1376 if (s->ops->set_socket(s, &s->socket))
1377 return CS_BAD_VPP;
1378
1379 c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1;
1380
1381 /* Pick memory or I/O card, DMA mode, interrupt */
1382 c->IntType = req->IntType;
1383 c->Attributes = req->Attributes;
1384 if (req->IntType & INT_MEMORY_AND_IO)
1385 s->socket.flags |= SS_IOCARD;
1386 if (req->IntType & INT_ZOOMED_VIDEO)
1387 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
1388 if (req->Attributes & CONF_ENABLE_DMA)
1389 s->socket.flags |= SS_DMA_MODE;
1390 if (req->Attributes & CONF_ENABLE_SPKR)
1391 s->socket.flags |= SS_SPKR_ENA;
1392 if (req->Attributes & CONF_ENABLE_IRQ)
1393 s->socket.io_irq = s->irq.AssignedIRQ;
1394 else
1395 s->socket.io_irq = 0;
1396 s->ops->set_socket(s, &s->socket);
1397 s->lock_count++;
1398
1399 /* Set up CIS configuration registers */
1400 base = c->ConfigBase = req->ConfigBase;
1401 c->Present = c->CardValues = req->Present;
1402 if (req->Present & PRESENT_COPY) {
1403 c->Copy = req->Copy;
1404 write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
1405 }
1406 if (req->Present & PRESENT_OPTION) {
1407 if (s->functions == 1) {
1408 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
1409 } else {
1410 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
1411 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
1412 if (req->Present & PRESENT_IOBASE_0)
1413 c->Option |= COR_ADDR_DECODE;
1414 }
1415 if (c->state & CONFIG_IRQ_REQ)
1416 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
1417 c->Option |= COR_LEVEL_REQ;
1418 write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
1419 mdelay(40);
1420 }
1421 if (req->Present & PRESENT_STATUS) {
1422 c->Status = req->Status;
1423 write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
1424 }
1425 if (req->Present & PRESENT_PIN_REPLACE) {
1426 c->Pin = req->Pin;
1427 write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
1428 }
1429 if (req->Present & PRESENT_EXT_STATUS) {
1430 c->ExtStatus = req->ExtStatus;
1431 write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
1432 }
1433 if (req->Present & PRESENT_IOBASE_0) {
1434 u_char b = c->io.BasePort1 & 0xff;
1435 write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
1436 b = (c->io.BasePort1 >> 8) & 0xff;
1437 write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
1438 }
1439 if (req->Present & PRESENT_IOSIZE) {
1440 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
1441 write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
1442 }
1443
1444 /* Configure I/O windows */
1445 if (c->state & CONFIG_IO_REQ) {
1446 iomap.speed = io_speed;
1447 for (i = 0; i < MAX_IO_WIN; i++)
1448 if (s->io[i].NumPorts != 0) {
1449 iomap.map = i;
1450 iomap.flags = MAP_ACTIVE;
1451 switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) {
1452 case IO_DATA_PATH_WIDTH_16:
1453 iomap.flags |= MAP_16BIT; break;
1454 case IO_DATA_PATH_WIDTH_AUTO:
1455 iomap.flags |= MAP_AUTOSZ; break;
1456 default:
1457 break;
1458 }
1459 iomap.start = s->io[i].BasePort;
1460 iomap.stop = iomap.start + s->io[i].NumPorts - 1;
1461 s->ops->set_io_map(s, &iomap);
1462 s->io[i].Config++;
1463 }
1464 }
1465
1466 c->state |= CONFIG_LOCKED;
1467 handle->state |= CLIENT_CONFIG_LOCKED;
1468 return CS_SUCCESS;
1469} /* request_configuration */
1470
1471/*======================================================================
1472
1473 Request_io() reserves ranges of port addresses for a socket.
1474 I have not implemented range sharing or alias addressing.
1475
1476======================================================================*/
1477
1478int pcmcia_request_io(client_handle_t handle, io_req_t *req)
1479{
1480 struct pcmcia_socket *s;
1481 config_t *c;
1482
1483 if (CHECK_HANDLE(handle))
1484 return CS_BAD_HANDLE;
1485 s = SOCKET(handle);
1486 if (!(s->state & SOCKET_PRESENT))
1487 return CS_NO_CARD;
1488
1489 if (handle->state & CLIENT_CARDBUS) {
1490#ifdef CONFIG_CARDBUS
1491 handle->state |= CLIENT_IO_REQ;
1492 return CS_SUCCESS;
1493#else
1494 return CS_UNSUPPORTED_FUNCTION;
1495#endif
1496 }
1497
1498 if (!req)
1499 return CS_UNSUPPORTED_MODE;
1500 c = CONFIG(handle);
1501 if (c->state & CONFIG_LOCKED)
1502 return CS_CONFIGURATION_LOCKED;
1503 if (c->state & CONFIG_IO_REQ)
1504 return CS_IN_USE;
1505 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
1506 return CS_BAD_ATTRIBUTE;
1507 if ((req->NumPorts2 > 0) &&
1508 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
1509 return CS_BAD_ATTRIBUTE;
1510
1511 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
1512 req->NumPorts1, req->IOAddrLines))
1513 return CS_IN_USE;
1514
1515 if (req->NumPorts2) {
1516 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
1517 req->NumPorts2, req->IOAddrLines)) {
1518 release_io_space(s, req->BasePort1, req->NumPorts1);
1519 return CS_IN_USE;
1520 }
1521 }
1522
1523 c->io = *req;
1524 c->state |= CONFIG_IO_REQ;
1525 handle->state |= CLIENT_IO_REQ;
1526 return CS_SUCCESS;
1527} /* request_io */
1528
1529/*======================================================================
1530
1531 Request_irq() reserves an irq for this client.
1532
1533 Also, since Linux only reserves irq's when they are actually
1534 hooked, we don't guarantee that an irq will still be available
1535 when the configuration is locked. Now that I think about it,
1536 there might be a way to fix this using a dummy handler.
1537
1538======================================================================*/
1539
1540#ifdef CONFIG_PCMCIA_PROBE
1541static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs)
1542{
1543 return IRQ_NONE;
1544}
1545#endif
1546
1547int pcmcia_request_irq(client_handle_t handle, irq_req_t *req)
1548{
1549 struct pcmcia_socket *s;
1550 config_t *c;
1551 int ret = CS_IN_USE, irq = 0;
1552 struct pcmcia_device *p_dev = handle_to_pdev(handle);
1553
1554 if (CHECK_HANDLE(handle))
1555 return CS_BAD_HANDLE;
1556 s = SOCKET(handle);
1557 if (!(s->state & SOCKET_PRESENT))
1558 return CS_NO_CARD;
1559 c = CONFIG(handle);
1560 if (c->state & CONFIG_LOCKED)
1561 return CS_CONFIGURATION_LOCKED;
1562 if (c->state & CONFIG_IRQ_REQ)
1563 return CS_IN_USE;
1564
1565#ifdef CONFIG_PCMCIA_PROBE
1566 if (s->irq.AssignedIRQ != 0) {
1567 /* If the interrupt is already assigned, it must be the same */
1568 irq = s->irq.AssignedIRQ;
1569 } else {
1570 int try;
1571 u32 mask = s->irq_mask;
1572 void *data = NULL;
1573
1574 for (try = 0; try < 64; try++) {
1575 irq = try % 32;
1576
1577 /* marked as available by driver, and not blocked by userspace? */
1578 if (!((mask >> irq) & 1))
1579 continue;
1580
1581 /* avoid an IRQ which is already used by a PCMCIA card */
1582 if ((try < 32) && pcmcia_used_irq[irq])
1583 continue;
1584
1585 /* register the correct driver, if possible, of check whether
1586 * registering a dummy handle works, i.e. if the IRQ isn't
1587 * marked as used by the kernel resource management core */
1588 ret = request_irq(irq,
1589 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
1590 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
1591 (s->functions > 1) ||
1592 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
1593 p_dev->dev.bus_id,
1594 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
1595 if (!ret) {
1596 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
1597 free_irq(irq, data);
1598 break;
1599 }
1600 }
1601 }
1602#endif
1603 if (ret) {
1604 if (!s->pci_irq)
1605 return ret;
1606 irq = s->pci_irq;
1607 }
1608
1609 if (ret && req->Attributes & IRQ_HANDLE_PRESENT) {
1610 if (request_irq(irq, req->Handler,
1611 ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) ||
1612 (s->functions > 1) ||
1613 (irq == s->pci_irq)) ? SA_SHIRQ : 0,
1614 p_dev->dev.bus_id, req->Instance))
1615 return CS_IN_USE;
1616 }
1617
1618 c->irq.Attributes = req->Attributes;
1619 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
1620 s->irq.Config++;
1621
1622 c->state |= CONFIG_IRQ_REQ;
1623 handle->state |= CLIENT_IRQ_REQ;
1624
1625#ifdef CONFIG_PCMCIA_PROBE
1626 pcmcia_used_irq[irq]++;
1627#endif
1628
1629 return CS_SUCCESS;
1630} /* pcmcia_request_irq */
1631
1632/*======================================================================
1633
1634 Request_window() establishes a mapping between card memory space
1635 and system memory space.
1636
1637======================================================================*/
1638
1639int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle_t *wh)
1640{
1641 struct pcmcia_socket *s;
1642 window_t *win;
1643 u_long align;
1644 int w;
1645
1646 if (CHECK_HANDLE(*handle))
1647 return CS_BAD_HANDLE;
1648 s = (*handle)->Socket;
1649 if (!(s->state & SOCKET_PRESENT))
1650 return CS_NO_CARD;
1651 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
1652 return CS_BAD_ATTRIBUTE;
1653
1654 /* Window size defaults to smallest available */
1655 if (req->Size == 0)
1656 req->Size = s->map_size;
1657 align = (((s->features & SS_CAP_MEM_ALIGN) ||
1658 (req->Attributes & WIN_STRICT_ALIGN)) ?
1659 req->Size : s->map_size);
1660 if (req->Size & (s->map_size-1))
1661 return CS_BAD_SIZE;
1662 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
1663 (req->Base & (align-1)))
1664 return CS_BAD_BASE;
1665 if (req->Base)
1666 align = 0;
1667
1668 /* Allocate system memory window */
1669 for (w = 0; w < MAX_WIN; w++)
1670 if (!(s->state & SOCKET_WIN_REQ(w))) break;
1671 if (w == MAX_WIN)
1672 return CS_OUT_OF_RESOURCE;
1673
1674 win = &s->win[w];
1675 win->magic = WINDOW_MAGIC;
1676 win->index = w;
1677 win->handle = *handle;
1678 win->sock = s;
1679
1680 if (!(s->features & SS_CAP_STATIC_MAP)) {
1681 win->ctl.res = find_mem_region(req->Base, req->Size, align,
1682 (req->Attributes & WIN_MAP_BELOW_1MB), s);
1683 if (!win->ctl.res)
1684 return CS_IN_USE;
1685 }
1686 (*handle)->state |= CLIENT_WIN_REQ(w);
1687
1688 /* Configure the socket controller */
1689 win->ctl.map = w+1;
1690 win->ctl.flags = 0;
1691 win->ctl.speed = req->AccessSpeed;
1692 if (req->Attributes & WIN_MEMORY_TYPE)
1693 win->ctl.flags |= MAP_ATTRIB;
1694 if (req->Attributes & WIN_ENABLE)
1695 win->ctl.flags |= MAP_ACTIVE;
1696 if (req->Attributes & WIN_DATA_WIDTH_16)
1697 win->ctl.flags |= MAP_16BIT;
1698 if (req->Attributes & WIN_USE_WAIT)
1699 win->ctl.flags |= MAP_USE_WAIT;
1700 win->ctl.card_start = 0;
1701 if (s->ops->set_mem_map(s, &win->ctl) != 0)
1702 return CS_BAD_ARGS;
1703 s->state |= SOCKET_WIN_REQ(w);
1704
1705 /* Return window handle */
1706 if (s->features & SS_CAP_STATIC_MAP) {
1707 req->Base = win->ctl.static_start;
1708 } else {
1709 req->Base = win->ctl.res->start;
1710 }
1711 *wh = win;
1712
1713 return CS_SUCCESS;
1714} /* request_window */
1715
1716/*======================================================================
1717
1718 I'm not sure which "reset" function this is supposed to use,
1719 but for now, it uses the low-level interface's reset, not the
1720 CIS register.
1721
1722======================================================================*/
1723 744
1724int pccard_reset_card(struct pcmcia_socket *skt) 745int pccard_reset_card(struct pcmcia_socket *skt)
1725{ 746{
1726 int ret; 747 int ret;
1727 748
1728 cs_dbg(skt, 1, "resetting socket\n"); 749 cs_dbg(skt, 1, "resetting socket\n");
1729 750
1730 down(&skt->skt_sem); 751 down(&skt->skt_sem);
@@ -1757,17 +778,14 @@ int pccard_reset_card(struct pcmcia_socket *skt)
1757} /* reset_card */ 778} /* reset_card */
1758EXPORT_SYMBOL(pccard_reset_card); 779EXPORT_SYMBOL(pccard_reset_card);
1759 780
1760/*======================================================================
1761
1762 These shut down or wake up a socket. They are sort of user
1763 initiated versions of the APM suspend and resume actions.
1764
1765======================================================================*/
1766 781
782/* These shut down or wake up a socket. They are sort of user
783 * initiated versions of the APM suspend and resume actions.
784 */
1767int pcmcia_suspend_card(struct pcmcia_socket *skt) 785int pcmcia_suspend_card(struct pcmcia_socket *skt)
1768{ 786{
1769 int ret; 787 int ret;
1770 788
1771 cs_dbg(skt, 1, "suspending socket\n"); 789 cs_dbg(skt, 1, "suspending socket\n");
1772 790
1773 down(&skt->skt_sem); 791 down(&skt->skt_sem);
@@ -1786,6 +804,8 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
1786 804
1787 return ret; 805 return ret;
1788} /* suspend_card */ 806} /* suspend_card */
807EXPORT_SYMBOL(pcmcia_suspend_card);
808
1789 809
1790int pcmcia_resume_card(struct pcmcia_socket *skt) 810int pcmcia_resume_card(struct pcmcia_socket *skt)
1791{ 811{
@@ -1809,13 +829,10 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
1809 829
1810 return ret; 830 return ret;
1811} /* resume_card */ 831} /* resume_card */
832EXPORT_SYMBOL(pcmcia_resume_card);
1812 833
1813/*======================================================================
1814
1815 These handle user requests to eject or insert a card.
1816
1817======================================================================*/
1818 834
835/* These handle user requests to eject or insert a card. */
1819int pcmcia_eject_card(struct pcmcia_socket *skt) 836int pcmcia_eject_card(struct pcmcia_socket *skt)
1820{ 837{
1821 int ret; 838 int ret;
@@ -1842,6 +859,8 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
1842 859
1843 return ret; 860 return ret;
1844} /* eject_card */ 861} /* eject_card */
862EXPORT_SYMBOL(pcmcia_eject_card);
863
1845 864
1846int pcmcia_insert_card(struct pcmcia_socket *skt) 865int pcmcia_insert_card(struct pcmcia_socket *skt)
1847{ 866{
@@ -1865,37 +884,38 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
1865 884
1866 return ret; 885 return ret;
1867} /* insert_card */ 886} /* insert_card */
887EXPORT_SYMBOL(pcmcia_insert_card);
1868 888
1869/*======================================================================
1870 889
1871 OS-specific module glue goes here 890static int pcmcia_socket_hotplug(struct class_device *dev, char **envp,
1872 891 int num_envp, char *buffer, int buffer_size)
1873======================================================================*/ 892{
1874/* in alpha order */ 893 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
1875EXPORT_SYMBOL(pcmcia_eject_card); 894 int i = 0, length = 0;
1876EXPORT_SYMBOL(pcmcia_get_card_services_info); 895
1877EXPORT_SYMBOL(pcmcia_get_mem_page); 896 if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size,
1878EXPORT_SYMBOL(pcmcia_insert_card); 897 &length, "SOCKET_NO=%u", s->sock))
1879EXPORT_SYMBOL(pcmcia_map_mem_page); 898 return -ENOMEM;
1880EXPORT_SYMBOL(pcmcia_modify_configuration); 899
1881EXPORT_SYMBOL(pcmcia_release_configuration); 900 envp[i] = NULL;
1882EXPORT_SYMBOL(pcmcia_release_io); 901
1883EXPORT_SYMBOL(pcmcia_release_irq); 902 return 0;
1884EXPORT_SYMBOL(pcmcia_release_window); 903}
1885EXPORT_SYMBOL(pcmcia_replace_cis); 904
1886EXPORT_SYMBOL(pcmcia_request_configuration); 905
1887EXPORT_SYMBOL(pcmcia_request_io); 906static struct completion pcmcia_unload;
1888EXPORT_SYMBOL(pcmcia_request_irq); 907
1889EXPORT_SYMBOL(pcmcia_request_window); 908static void pcmcia_release_socket_class(struct class *data)
1890EXPORT_SYMBOL(pcmcia_resume_card); 909{
1891EXPORT_SYMBOL(pcmcia_suspend_card); 910 complete(&pcmcia_unload);
911}
1892 912
1893EXPORT_SYMBOL(dead_socket);
1894EXPORT_SYMBOL(pcmcia_parse_events);
1895 913
1896struct class pcmcia_socket_class = { 914struct class pcmcia_socket_class = {
1897 .name = "pcmcia_socket", 915 .name = "pcmcia_socket",
916 .hotplug = pcmcia_socket_hotplug,
1898 .release = pcmcia_release_socket, 917 .release = pcmcia_release_socket,
918 .class_release = pcmcia_release_socket_class,
1899}; 919};
1900EXPORT_SYMBOL(pcmcia_socket_class); 920EXPORT_SYMBOL(pcmcia_socket_class);
1901 921
@@ -1903,9 +923,8 @@ EXPORT_SYMBOL(pcmcia_socket_class);
1903static int __init init_pcmcia_cs(void) 923static int __init init_pcmcia_cs(void)
1904{ 924{
1905 int ret; 925 int ret;
1906 printk(KERN_INFO "%s\n", release);
1907 printk(KERN_INFO " %s\n", options);
1908 926
927 init_completion(&pcmcia_unload);
1909 ret = class_register(&pcmcia_socket_class); 928 ret = class_register(&pcmcia_socket_class);
1910 if (ret) 929 if (ret)
1911 return (ret); 930 return (ret);
@@ -1914,13 +933,12 @@ static int __init init_pcmcia_cs(void)
1914 933
1915static void __exit exit_pcmcia_cs(void) 934static void __exit exit_pcmcia_cs(void)
1916{ 935{
1917 printk(KERN_INFO "unloading Kernel Card Services\n"); 936 class_interface_unregister(&pccard_sysfs_interface);
1918 class_interface_unregister(&pccard_sysfs_interface); 937 class_unregister(&pcmcia_socket_class);
1919 class_unregister(&pcmcia_socket_class); 938
939 wait_for_completion(&pcmcia_unload);
1920} 940}
1921 941
1922subsys_initcall(init_pcmcia_cs); 942subsys_initcall(init_pcmcia_cs);
1923module_exit(exit_pcmcia_cs); 943module_exit(exit_pcmcia_cs);
1924 944
1925/*====================================================================*/
1926