aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/bluetooth/bluecard_cs.c119
-rw-r--r--drivers/bluetooth/bt3c_cs.c130
-rw-r--r--drivers/bluetooth/btuart_cs.c130
-rw-r--r--drivers/bluetooth/dtl1_cs.c120
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c121
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c133
-rw-r--r--drivers/char/pcmcia/synclink_cs.c116
-rw-r--r--drivers/ide/legacy/ide-cs.c127
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c185
-rw-r--r--drivers/isdn/hisax/avma1_cs.c182
-rw-r--r--drivers/isdn/hisax/elsa_cs.c112
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c143
-rw-r--r--drivers/isdn/hisax/teles_cs.c121
-rw-r--r--drivers/mtd/maps/pcmciamtd.c115
-rw-r--r--drivers/net/pcmcia/3c574_cs.c115
-rw-r--r--drivers/net/pcmcia/3c589_cs.c122
-rw-r--r--drivers/net/pcmcia/axnet_cs.c126
-rw-r--r--drivers/net/pcmcia/com20020_cs.c127
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c166
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c121
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c126
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c161
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c235
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c185
-rw-r--r--drivers/net/wireless/airo_cs.c158
-rw-r--r--drivers/net/wireless/atmel_cs.c162
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c198
-rw-r--r--drivers/net/wireless/netwave_cs.c127
-rw-r--r--drivers/net/wireless/orinoco_cs.c187
-rw-r--r--drivers/net/wireless/ray_cs.c279
-rw-r--r--drivers/net/wireless/ray_cs.h2
-rw-r--r--drivers/net/wireless/spectrum_cs.c173
-rw-r--r--drivers/net/wireless/wavelan_cs.c189
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h6
-rw-r--r--drivers/net/wireless/wl3501.h1
-rw-r--r--drivers/net/wireless/wl3501_cs.c178
-rw-r--r--drivers/parport/parport_cs.c129
-rw-r--r--drivers/pcmcia/Kconfig7
-rw-r--r--drivers/pcmcia/Makefile3
-rw-r--r--drivers/pcmcia/at91_cf.c365
-rw-r--r--drivers/pcmcia/cistpl.c1
-rw-r--r--drivers/pcmcia/cs.c43
-rw-r--r--drivers/pcmcia/cs_internal.h19
-rw-r--r--drivers/pcmcia/ds.c249
-rw-r--r--drivers/pcmcia/ds_internal.h4
-rw-r--r--drivers/pcmcia/i82092.c1
-rw-r--r--drivers/pcmcia/i82365.c1
-rw-r--r--drivers/pcmcia/pcmcia_compat.c65
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c81
-rw-r--r--drivers/pcmcia/pcmcia_resource.c228
-rw-r--r--drivers/pcmcia/pd6729.c1
-rw-r--r--drivers/pcmcia/rsrc_mgr.c5
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c41
-rw-r--r--drivers/pcmcia/sa1100_cerf.c1
-rw-r--r--drivers/pcmcia/socket_sysfs.c10
-rw-r--r--drivers/pcmcia/ti113x.h1
-rw-r--r--drivers/scsi/pcmcia/aha152x_stub.c112
-rw-r--r--drivers/scsi/pcmcia/fdomain_stub.c155
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c136
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.h8
-rw-r--r--drivers/scsi/pcmcia/qlogic_stub.c127
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c124
-rw-r--r--drivers/serial/serial_cs.c229
-rw-r--r--drivers/telephony/ixj_pcmcia.c119
-rw-r--r--drivers/usb/host/sl811_cs.c119
65 files changed, 3008 insertions, 4374 deletions
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 9888bc151755..473a13b22b29 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -65,7 +65,7 @@ MODULE_LICENSE("GPL");
65 65
66 66
67typedef struct bluecard_info_t { 67typedef struct bluecard_info_t {
68 dev_link_t link; 68 struct pcmcia_device *p_dev;
69 dev_node_t node; 69 dev_node_t node;
70 70
71 struct hci_dev *hdev; 71 struct hci_dev *hdev;
@@ -85,8 +85,8 @@ typedef struct bluecard_info_t {
85} bluecard_info_t; 85} bluecard_info_t;
86 86
87 87
88static void bluecard_config(dev_link_t *link); 88static int bluecard_config(struct pcmcia_device *link);
89static void bluecard_release(dev_link_t *link); 89static void bluecard_release(struct pcmcia_device *link);
90 90
91static void bluecard_detach(struct pcmcia_device *p_dev); 91static void bluecard_detach(struct pcmcia_device *p_dev);
92 92
@@ -162,7 +162,7 @@ static void bluecard_detach(struct pcmcia_device *p_dev);
162static void bluecard_activity_led_timeout(u_long arg) 162static void bluecard_activity_led_timeout(u_long arg)
163{ 163{
164 bluecard_info_t *info = (bluecard_info_t *)arg; 164 bluecard_info_t *info = (bluecard_info_t *)arg;
165 unsigned int iobase = info->link.io.BasePort1; 165 unsigned int iobase = info->p_dev->io.BasePort1;
166 166
167 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) 167 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
168 return; 168 return;
@@ -179,7 +179,7 @@ static void bluecard_activity_led_timeout(u_long arg)
179 179
180static void bluecard_enable_activity_led(bluecard_info_t *info) 180static void bluecard_enable_activity_led(bluecard_info_t *info)
181{ 181{
182 unsigned int iobase = info->link.io.BasePort1; 182 unsigned int iobase = info->p_dev->io.BasePort1;
183 183
184 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) 184 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
185 return; 185 return;
@@ -235,7 +235,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
235 } 235 }
236 236
237 do { 237 do {
238 register unsigned int iobase = info->link.io.BasePort1; 238 register unsigned int iobase = info->p_dev->io.BasePort1;
239 register unsigned int offset; 239 register unsigned int offset;
240 register unsigned char command; 240 register unsigned char command;
241 register unsigned long ready_bit; 241 register unsigned long ready_bit;
@@ -244,7 +244,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
244 244
245 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 245 clear_bit(XMIT_WAKEUP, &(info->tx_state));
246 246
247 if (!(info->link.state & DEV_PRESENT)) 247 if (!pcmcia_dev_present(info->p_dev))
248 return; 248 return;
249 249
250 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) { 250 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) {
@@ -382,7 +382,7 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
382 return; 382 return;
383 } 383 }
384 384
385 iobase = info->link.io.BasePort1; 385 iobase = info->p_dev->io.BasePort1;
386 386
387 if (test_bit(XMIT_SENDING_READY, &(info->tx_state))) 387 if (test_bit(XMIT_SENDING_READY, &(info->tx_state)))
388 bluecard_enable_activity_led(info); 388 bluecard_enable_activity_led(info);
@@ -512,7 +512,7 @@ static irqreturn_t bluecard_interrupt(int irq, void *dev_inst, struct pt_regs *r
512 if (!test_bit(CARD_READY, &(info->hw_state))) 512 if (!test_bit(CARD_READY, &(info->hw_state)))
513 return IRQ_HANDLED; 513 return IRQ_HANDLED;
514 514
515 iobase = info->link.io.BasePort1; 515 iobase = info->p_dev->io.BasePort1;
516 516
517 spin_lock(&(info->lock)); 517 spin_lock(&(info->lock));
518 518
@@ -626,7 +626,7 @@ static int bluecard_hci_flush(struct hci_dev *hdev)
626static int bluecard_hci_open(struct hci_dev *hdev) 626static int bluecard_hci_open(struct hci_dev *hdev)
627{ 627{
628 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data); 628 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
629 unsigned int iobase = info->link.io.BasePort1; 629 unsigned int iobase = info->p_dev->io.BasePort1;
630 630
631 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) 631 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
632 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE); 632 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);
@@ -646,7 +646,7 @@ static int bluecard_hci_open(struct hci_dev *hdev)
646static int bluecard_hci_close(struct hci_dev *hdev) 646static int bluecard_hci_close(struct hci_dev *hdev)
647{ 647{
648 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data); 648 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
649 unsigned int iobase = info->link.io.BasePort1; 649 unsigned int iobase = info->p_dev->io.BasePort1;
650 650
651 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags))) 651 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
652 return 0; 652 return 0;
@@ -713,7 +713,7 @@ static int bluecard_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned l
713 713
714static int bluecard_open(bluecard_info_t *info) 714static int bluecard_open(bluecard_info_t *info)
715{ 715{
716 unsigned int iobase = info->link.io.BasePort1; 716 unsigned int iobase = info->p_dev->io.BasePort1;
717 struct hci_dev *hdev; 717 struct hci_dev *hdev;
718 unsigned char id; 718 unsigned char id;
719 719
@@ -831,7 +831,7 @@ static int bluecard_open(bluecard_info_t *info)
831 831
832static int bluecard_close(bluecard_info_t *info) 832static int bluecard_close(bluecard_info_t *info)
833{ 833{
834 unsigned int iobase = info->link.io.BasePort1; 834 unsigned int iobase = info->p_dev->io.BasePort1;
835 struct hci_dev *hdev = info->hdev; 835 struct hci_dev *hdev = info->hdev;
836 836
837 if (!hdev) 837 if (!hdev)
@@ -856,17 +856,16 @@ static int bluecard_close(bluecard_info_t *info)
856 return 0; 856 return 0;
857} 857}
858 858
859static int bluecard_attach(struct pcmcia_device *p_dev) 859static int bluecard_probe(struct pcmcia_device *link)
860{ 860{
861 bluecard_info_t *info; 861 bluecard_info_t *info;
862 dev_link_t *link;
863 862
864 /* Create new info device */ 863 /* Create new info device */
865 info = kzalloc(sizeof(*info), GFP_KERNEL); 864 info = kzalloc(sizeof(*info), GFP_KERNEL);
866 if (!info) 865 if (!info)
867 return -ENOMEM; 866 return -ENOMEM;
868 867
869 link = &info->link; 868 info->p_dev = link;
870 link->priv = info; 869 link->priv = info;
871 870
872 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 871 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -878,32 +877,22 @@ static int bluecard_attach(struct pcmcia_device *p_dev)
878 link->irq.Instance = info; 877 link->irq.Instance = info;
879 878
880 link->conf.Attributes = CONF_ENABLE_IRQ; 879 link->conf.Attributes = CONF_ENABLE_IRQ;
881 link->conf.Vcc = 50;
882 link->conf.IntType = INT_MEMORY_AND_IO; 880 link->conf.IntType = INT_MEMORY_AND_IO;
883 881
884 link->handle = p_dev; 882 return bluecard_config(link);
885 p_dev->instance = link;
886
887 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
888 bluecard_config(link);
889
890 return 0;
891} 883}
892 884
893 885
894static void bluecard_detach(struct pcmcia_device *p_dev) 886static void bluecard_detach(struct pcmcia_device *link)
895{ 887{
896 dev_link_t *link = dev_to_instance(p_dev);
897 bluecard_info_t *info = link->priv; 888 bluecard_info_t *info = link->priv;
898 889
899 if (link->state & DEV_CONFIG) 890 bluecard_release(link);
900 bluecard_release(link);
901
902 kfree(info); 891 kfree(info);
903} 892}
904 893
905 894
906static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 895static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
907{ 896{
908 int i; 897 int i;
909 898
@@ -918,14 +907,12 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse
918 return pcmcia_parse_tuple(handle, tuple, parse); 907 return pcmcia_parse_tuple(handle, tuple, parse);
919} 908}
920 909
921static void bluecard_config(dev_link_t *link) 910static int bluecard_config(struct pcmcia_device *link)
922{ 911{
923 client_handle_t handle = link->handle;
924 bluecard_info_t *info = link->priv; 912 bluecard_info_t *info = link->priv;
925 tuple_t tuple; 913 tuple_t tuple;
926 u_short buf[256]; 914 u_short buf[256];
927 cisparse_t parse; 915 cisparse_t parse;
928 config_info_t config;
929 int i, n, last_ret, last_fn; 916 int i, n, last_ret, last_fn;
930 917
931 tuple.TupleData = (cisdata_t *)buf; 918 tuple.TupleData = (cisdata_t *)buf;
@@ -935,7 +922,7 @@ static void bluecard_config(dev_link_t *link)
935 922
936 /* Get configuration register information */ 923 /* Get configuration register information */
937 tuple.DesiredTuple = CISTPL_CONFIG; 924 tuple.DesiredTuple = CISTPL_CONFIG;
938 last_ret = first_tuple(handle, &tuple, &parse); 925 last_ret = first_tuple(link, &tuple, &parse);
939 if (last_ret != CS_SUCCESS) { 926 if (last_ret != CS_SUCCESS) {
940 last_fn = ParseTuple; 927 last_fn = ParseTuple;
941 goto cs_failed; 928 goto cs_failed;
@@ -943,36 +930,31 @@ static void bluecard_config(dev_link_t *link)
943 link->conf.ConfigBase = parse.config.base; 930 link->conf.ConfigBase = parse.config.base;
944 link->conf.Present = parse.config.rmask[0]; 931 link->conf.Present = parse.config.rmask[0];
945 932
946 /* Configure card */
947 link->state |= DEV_CONFIG;
948 i = pcmcia_get_configuration_info(handle, &config);
949 link->conf.Vcc = config.Vcc;
950
951 link->conf.ConfigIndex = 0x20; 933 link->conf.ConfigIndex = 0x20;
952 link->io.NumPorts1 = 64; 934 link->io.NumPorts1 = 64;
953 link->io.IOAddrLines = 6; 935 link->io.IOAddrLines = 6;
954 936
955 for (n = 0; n < 0x400; n += 0x40) { 937 for (n = 0; n < 0x400; n += 0x40) {
956 link->io.BasePort1 = n ^ 0x300; 938 link->io.BasePort1 = n ^ 0x300;
957 i = pcmcia_request_io(link->handle, &link->io); 939 i = pcmcia_request_io(link, &link->io);
958 if (i == CS_SUCCESS) 940 if (i == CS_SUCCESS)
959 break; 941 break;
960 } 942 }
961 943
962 if (i != CS_SUCCESS) { 944 if (i != CS_SUCCESS) {
963 cs_error(link->handle, RequestIO, i); 945 cs_error(link, RequestIO, i);
964 goto failed; 946 goto failed;
965 } 947 }
966 948
967 i = pcmcia_request_irq(link->handle, &link->irq); 949 i = pcmcia_request_irq(link, &link->irq);
968 if (i != CS_SUCCESS) { 950 if (i != CS_SUCCESS) {
969 cs_error(link->handle, RequestIRQ, i); 951 cs_error(link, RequestIRQ, i);
970 link->irq.AssignedIRQ = 0; 952 link->irq.AssignedIRQ = 0;
971 } 953 }
972 954
973 i = pcmcia_request_configuration(link->handle, &link->conf); 955 i = pcmcia_request_configuration(link, &link->conf);
974 if (i != CS_SUCCESS) { 956 if (i != CS_SUCCESS) {
975 cs_error(link->handle, RequestConfiguration, i); 957 cs_error(link, RequestConfiguration, i);
976 goto failed; 958 goto failed;
977 } 959 }
978 960
@@ -980,57 +962,28 @@ static void bluecard_config(dev_link_t *link)
980 goto failed; 962 goto failed;
981 963
982 strcpy(info->node.dev_name, info->hdev->name); 964 strcpy(info->node.dev_name, info->hdev->name);
983 link->dev = &info->node; 965 link->dev_node = &info->node;
984 link->state &= ~DEV_CONFIG_PENDING;
985 966
986 return; 967 return 0;
987 968
988cs_failed: 969cs_failed:
989 cs_error(link->handle, last_fn, last_ret); 970 cs_error(link, last_fn, last_ret);
990 971
991failed: 972failed:
992 bluecard_release(link); 973 bluecard_release(link);
974 return -ENODEV;
993} 975}
994 976
995 977
996static void bluecard_release(dev_link_t *link) 978static void bluecard_release(struct pcmcia_device *link)
997{ 979{
998 bluecard_info_t *info = link->priv; 980 bluecard_info_t *info = link->priv;
999 981
1000 if (link->state & DEV_PRESENT) 982 bluecard_close(info);
1001 bluecard_close(info);
1002 983
1003 del_timer(&(info->timer)); 984 del_timer(&(info->timer));
1004 985
1005 link->dev = NULL; 986 pcmcia_disable_device(link);
1006
1007 pcmcia_release_configuration(link->handle);
1008 pcmcia_release_io(link->handle, &link->io);
1009 pcmcia_release_irq(link->handle, &link->irq);
1010
1011 link->state &= ~DEV_CONFIG;
1012}
1013
1014static int bluecard_suspend(struct pcmcia_device *dev)
1015{
1016 dev_link_t *link = dev_to_instance(dev);
1017
1018 link->state |= DEV_SUSPEND;
1019 if (link->state & DEV_CONFIG)
1020 pcmcia_release_configuration(link->handle);
1021
1022 return 0;
1023}
1024
1025static int bluecard_resume(struct pcmcia_device *dev)
1026{
1027 dev_link_t *link = dev_to_instance(dev);
1028
1029 link->state &= ~DEV_SUSPEND;
1030 if (DEV_OK(link))
1031 pcmcia_request_configuration(link->handle, &link->conf);
1032
1033 return 0;
1034} 987}
1035 988
1036static struct pcmcia_device_id bluecard_ids[] = { 989static struct pcmcia_device_id bluecard_ids[] = {
@@ -1046,11 +999,9 @@ static struct pcmcia_driver bluecard_driver = {
1046 .drv = { 999 .drv = {
1047 .name = "bluecard_cs", 1000 .name = "bluecard_cs",
1048 }, 1001 },
1049 .probe = bluecard_attach, 1002 .probe = bluecard_probe,
1050 .remove = bluecard_detach, 1003 .remove = bluecard_detach,
1051 .id_table = bluecard_ids, 1004 .id_table = bluecard_ids,
1052 .suspend = bluecard_suspend,
1053 .resume = bluecard_resume,
1054}; 1005};
1055 1006
1056static int __init init_bluecard_cs(void) 1007static int __init init_bluecard_cs(void)
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 7e21b1ff27c4..b94ac2f9f7ba 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -72,7 +72,7 @@ MODULE_LICENSE("GPL");
72 72
73 73
74typedef struct bt3c_info_t { 74typedef struct bt3c_info_t {
75 dev_link_t link; 75 struct pcmcia_device *p_dev;
76 dev_node_t node; 76 dev_node_t node;
77 77
78 struct hci_dev *hdev; 78 struct hci_dev *hdev;
@@ -88,8 +88,8 @@ typedef struct bt3c_info_t {
88} bt3c_info_t; 88} bt3c_info_t;
89 89
90 90
91static void bt3c_config(dev_link_t *link); 91static int bt3c_config(struct pcmcia_device *link);
92static void bt3c_release(dev_link_t *link); 92static void bt3c_release(struct pcmcia_device *link);
93 93
94static void bt3c_detach(struct pcmcia_device *p_dev); 94static void bt3c_detach(struct pcmcia_device *p_dev);
95 95
@@ -191,11 +191,11 @@ static void bt3c_write_wakeup(bt3c_info_t *info)
191 return; 191 return;
192 192
193 do { 193 do {
194 register unsigned int iobase = info->link.io.BasePort1; 194 register unsigned int iobase = info->p_dev->io.BasePort1;
195 register struct sk_buff *skb; 195 register struct sk_buff *skb;
196 register int len; 196 register int len;
197 197
198 if (!(info->link.state & DEV_PRESENT)) 198 if (!pcmcia_dev_present(info->p_dev))
199 break; 199 break;
200 200
201 201
@@ -229,7 +229,7 @@ static void bt3c_receive(bt3c_info_t *info)
229 return; 229 return;
230 } 230 }
231 231
232 iobase = info->link.io.BasePort1; 232 iobase = info->p_dev->io.BasePort1;
233 233
234 avail = bt3c_read(iobase, 0x7006); 234 avail = bt3c_read(iobase, 0x7006);
235 //printk("bt3c_cs: receiving %d bytes\n", avail); 235 //printk("bt3c_cs: receiving %d bytes\n", avail);
@@ -350,7 +350,7 @@ static irqreturn_t bt3c_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
350 return IRQ_NONE; 350 return IRQ_NONE;
351 } 351 }
352 352
353 iobase = info->link.io.BasePort1; 353 iobase = info->p_dev->io.BasePort1;
354 354
355 spin_lock(&(info->lock)); 355 spin_lock(&(info->lock));
356 356
@@ -481,7 +481,7 @@ static int bt3c_load_firmware(bt3c_info_t *info, unsigned char *firmware, int co
481 unsigned int iobase, size, addr, fcs, tmp; 481 unsigned int iobase, size, addr, fcs, tmp;
482 int i, err = 0; 482 int i, err = 0;
483 483
484 iobase = info->link.io.BasePort1; 484 iobase = info->p_dev->io.BasePort1;
485 485
486 /* Reset */ 486 /* Reset */
487 bt3c_io_write(iobase, 0x8040, 0x0404); 487 bt3c_io_write(iobase, 0x8040, 0x0404);
@@ -562,7 +562,6 @@ static int bt3c_open(bt3c_info_t *info)
562{ 562{
563 const struct firmware *firmware; 563 const struct firmware *firmware;
564 struct hci_dev *hdev; 564 struct hci_dev *hdev;
565 client_handle_t handle;
566 int err; 565 int err;
567 566
568 spin_lock_init(&(info->lock)); 567 spin_lock_init(&(info->lock));
@@ -594,10 +593,8 @@ static int bt3c_open(bt3c_info_t *info)
594 593
595 hdev->owner = THIS_MODULE; 594 hdev->owner = THIS_MODULE;
596 595
597 handle = info->link.handle;
598
599 /* Load firmware */ 596 /* Load firmware */
600 err = request_firmware(&firmware, "BT3CPCC.bin", &handle_to_dev(handle)); 597 err = request_firmware(&firmware, "BT3CPCC.bin", &info->p_dev->dev);
601 if (err < 0) { 598 if (err < 0) {
602 BT_ERR("Firmware request failed"); 599 BT_ERR("Firmware request failed");
603 goto error; 600 goto error;
@@ -648,17 +645,16 @@ static int bt3c_close(bt3c_info_t *info)
648 return 0; 645 return 0;
649} 646}
650 647
651static int bt3c_attach(struct pcmcia_device *p_dev) 648static int bt3c_probe(struct pcmcia_device *link)
652{ 649{
653 bt3c_info_t *info; 650 bt3c_info_t *info;
654 dev_link_t *link;
655 651
656 /* Create new info device */ 652 /* Create new info device */
657 info = kzalloc(sizeof(*info), GFP_KERNEL); 653 info = kzalloc(sizeof(*info), GFP_KERNEL);
658 if (!info) 654 if (!info)
659 return -ENOMEM; 655 return -ENOMEM;
660 656
661 link = &info->link; 657 info->p_dev = link;
662 link->priv = info; 658 link->priv = info;
663 659
664 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 660 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -670,31 +666,21 @@ static int bt3c_attach(struct pcmcia_device *p_dev)
670 link->irq.Instance = info; 666 link->irq.Instance = info;
671 667
672 link->conf.Attributes = CONF_ENABLE_IRQ; 668 link->conf.Attributes = CONF_ENABLE_IRQ;
673 link->conf.Vcc = 50;
674 link->conf.IntType = INT_MEMORY_AND_IO; 669 link->conf.IntType = INT_MEMORY_AND_IO;
675 670
676 link->handle = p_dev; 671 return bt3c_config(link);
677 p_dev->instance = link;
678
679 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
680 bt3c_config(link);
681
682 return 0;
683} 672}
684 673
685 674
686static void bt3c_detach(struct pcmcia_device *p_dev) 675static void bt3c_detach(struct pcmcia_device *link)
687{ 676{
688 dev_link_t *link = dev_to_instance(p_dev);
689 bt3c_info_t *info = link->priv; 677 bt3c_info_t *info = link->priv;
690 678
691 if (link->state & DEV_CONFIG) 679 bt3c_release(link);
692 bt3c_release(link);
693
694 kfree(info); 680 kfree(info);
695} 681}
696 682
697static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 683static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
698{ 684{
699 int i; 685 int i;
700 686
@@ -705,30 +691,28 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
705 return pcmcia_parse_tuple(handle, tuple, parse); 691 return pcmcia_parse_tuple(handle, tuple, parse);
706} 692}
707 693
708static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 694static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
709{ 695{
710 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 696 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
711 return CS_NO_MORE_ITEMS; 697 return CS_NO_MORE_ITEMS;
712 return get_tuple(handle, tuple, parse); 698 return get_tuple(handle, tuple, parse);
713} 699}
714 700
715static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 701static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
716{ 702{
717 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 703 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
718 return CS_NO_MORE_ITEMS; 704 return CS_NO_MORE_ITEMS;
719 return get_tuple(handle, tuple, parse); 705 return get_tuple(handle, tuple, parse);
720} 706}
721 707
722static void bt3c_config(dev_link_t *link) 708static int bt3c_config(struct pcmcia_device *link)
723{ 709{
724 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 710 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
725 client_handle_t handle = link->handle;
726 bt3c_info_t *info = link->priv; 711 bt3c_info_t *info = link->priv;
727 tuple_t tuple; 712 tuple_t tuple;
728 u_short buf[256]; 713 u_short buf[256];
729 cisparse_t parse; 714 cisparse_t parse;
730 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 715 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
731 config_info_t config;
732 int i, j, try, last_ret, last_fn; 716 int i, j, try, last_ret, last_fn;
733 717
734 tuple.TupleData = (cisdata_t *)buf; 718 tuple.TupleData = (cisdata_t *)buf;
@@ -738,7 +722,7 @@ static void bt3c_config(dev_link_t *link)
738 722
739 /* Get configuration register information */ 723 /* Get configuration register information */
740 tuple.DesiredTuple = CISTPL_CONFIG; 724 tuple.DesiredTuple = CISTPL_CONFIG;
741 last_ret = first_tuple(handle, &tuple, &parse); 725 last_ret = first_tuple(link, &tuple, &parse);
742 if (last_ret != CS_SUCCESS) { 726 if (last_ret != CS_SUCCESS) {
743 last_fn = ParseTuple; 727 last_fn = ParseTuple;
744 goto cs_failed; 728 goto cs_failed;
@@ -746,11 +730,6 @@ static void bt3c_config(dev_link_t *link)
746 link->conf.ConfigBase = parse.config.base; 730 link->conf.ConfigBase = parse.config.base;
747 link->conf.Present = parse.config.rmask[0]; 731 link->conf.Present = parse.config.rmask[0];
748 732
749 /* Configure card */
750 link->state |= DEV_CONFIG;
751 i = pcmcia_get_configuration_info(handle, &config);
752 link->conf.Vcc = config.Vcc;
753
754 /* First pass: look for a config entry that looks normal. */ 733 /* First pass: look for a config entry that looks normal. */
755 tuple.TupleData = (cisdata_t *)buf; 734 tuple.TupleData = (cisdata_t *)buf;
756 tuple.TupleOffset = 0; 735 tuple.TupleOffset = 0;
@@ -759,59 +738,59 @@ static void bt3c_config(dev_link_t *link)
759 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 738 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
760 /* Two tries: without IO aliases, then with aliases */ 739 /* Two tries: without IO aliases, then with aliases */
761 for (try = 0; try < 2; try++) { 740 for (try = 0; try < 2; try++) {
762 i = first_tuple(handle, &tuple, &parse); 741 i = first_tuple(link, &tuple, &parse);
763 while (i != CS_NO_MORE_ITEMS) { 742 while (i != CS_NO_MORE_ITEMS) {
764 if (i != CS_SUCCESS) 743 if (i != CS_SUCCESS)
765 goto next_entry; 744 goto next_entry;
766 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 745 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
767 link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 746 link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
768 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) { 747 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
769 link->conf.ConfigIndex = cf->index; 748 link->conf.ConfigIndex = cf->index;
770 link->io.BasePort1 = cf->io.win[0].base; 749 link->io.BasePort1 = cf->io.win[0].base;
771 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 750 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
772 i = pcmcia_request_io(link->handle, &link->io); 751 i = pcmcia_request_io(link, &link->io);
773 if (i == CS_SUCCESS) 752 if (i == CS_SUCCESS)
774 goto found_port; 753 goto found_port;
775 } 754 }
776next_entry: 755next_entry:
777 i = next_tuple(handle, &tuple, &parse); 756 i = next_tuple(link, &tuple, &parse);
778 } 757 }
779 } 758 }
780 759
781 /* Second pass: try to find an entry that isn't picky about 760 /* Second pass: try to find an entry that isn't picky about
782 its base address, then try to grab any standard serial port 761 its base address, then try to grab any standard serial port
783 address, and finally try to get any free port. */ 762 address, and finally try to get any free port. */
784 i = first_tuple(handle, &tuple, &parse); 763 i = first_tuple(link, &tuple, &parse);
785 while (i != CS_NO_MORE_ITEMS) { 764 while (i != CS_NO_MORE_ITEMS) {
786 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 765 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
787 link->conf.ConfigIndex = cf->index; 766 link->conf.ConfigIndex = cf->index;
788 for (j = 0; j < 5; j++) { 767 for (j = 0; j < 5; j++) {
789 link->io.BasePort1 = base[j]; 768 link->io.BasePort1 = base[j];
790 link->io.IOAddrLines = base[j] ? 16 : 3; 769 link->io.IOAddrLines = base[j] ? 16 : 3;
791 i = pcmcia_request_io(link->handle, &link->io); 770 i = pcmcia_request_io(link, &link->io);
792 if (i == CS_SUCCESS) 771 if (i == CS_SUCCESS)
793 goto found_port; 772 goto found_port;
794 } 773 }
795 } 774 }
796 i = next_tuple(handle, &tuple, &parse); 775 i = next_tuple(link, &tuple, &parse);
797 } 776 }
798 777
799found_port: 778found_port:
800 if (i != CS_SUCCESS) { 779 if (i != CS_SUCCESS) {
801 BT_ERR("No usable port range found"); 780 BT_ERR("No usable port range found");
802 cs_error(link->handle, RequestIO, i); 781 cs_error(link, RequestIO, i);
803 goto failed; 782 goto failed;
804 } 783 }
805 784
806 i = pcmcia_request_irq(link->handle, &link->irq); 785 i = pcmcia_request_irq(link, &link->irq);
807 if (i != CS_SUCCESS) { 786 if (i != CS_SUCCESS) {
808 cs_error(link->handle, RequestIRQ, i); 787 cs_error(link, RequestIRQ, i);
809 link->irq.AssignedIRQ = 0; 788 link->irq.AssignedIRQ = 0;
810 } 789 }
811 790
812 i = pcmcia_request_configuration(link->handle, &link->conf); 791 i = pcmcia_request_configuration(link, &link->conf);
813 if (i != CS_SUCCESS) { 792 if (i != CS_SUCCESS) {
814 cs_error(link->handle, RequestConfiguration, i); 793 cs_error(link, RequestConfiguration, i);
815 goto failed; 794 goto failed;
816 } 795 }
817 796
@@ -819,55 +798,26 @@ found_port:
819 goto failed; 798 goto failed;
820 799
821 strcpy(info->node.dev_name, info->hdev->name); 800 strcpy(info->node.dev_name, info->hdev->name);
822 link->dev = &info->node; 801 link->dev_node = &info->node;
823 link->state &= ~DEV_CONFIG_PENDING;
824 802
825 return; 803 return 0;
826 804
827cs_failed: 805cs_failed:
828 cs_error(link->handle, last_fn, last_ret); 806 cs_error(link, last_fn, last_ret);
829 807
830failed: 808failed:
831 bt3c_release(link); 809 bt3c_release(link);
810 return -ENODEV;
832} 811}
833 812
834 813
835static void bt3c_release(dev_link_t *link) 814static void bt3c_release(struct pcmcia_device *link)
836{ 815{
837 bt3c_info_t *info = link->priv; 816 bt3c_info_t *info = link->priv;
838 817
839 if (link->state & DEV_PRESENT) 818 bt3c_close(info);
840 bt3c_close(info);
841
842 link->dev = NULL;
843
844 pcmcia_release_configuration(link->handle);
845 pcmcia_release_io(link->handle, &link->io);
846 pcmcia_release_irq(link->handle, &link->irq);
847
848 link->state &= ~DEV_CONFIG;
849}
850
851static int bt3c_suspend(struct pcmcia_device *dev)
852{
853 dev_link_t *link = dev_to_instance(dev);
854 819
855 link->state |= DEV_SUSPEND; 820 pcmcia_disable_device(link);
856 if (link->state & DEV_CONFIG)
857 pcmcia_release_configuration(link->handle);
858
859 return 0;
860}
861
862static int bt3c_resume(struct pcmcia_device *dev)
863{
864 dev_link_t *link = dev_to_instance(dev);
865
866 link->state &= ~DEV_SUSPEND;
867 if (DEV_OK(link))
868 pcmcia_request_configuration(link->handle, &link->conf);
869
870 return 0;
871} 821}
872 822
873 823
@@ -882,11 +832,9 @@ static struct pcmcia_driver bt3c_driver = {
882 .drv = { 832 .drv = {
883 .name = "bt3c_cs", 833 .name = "bt3c_cs",
884 }, 834 },
885 .probe = bt3c_attach, 835 .probe = bt3c_probe,
886 .remove = bt3c_detach, 836 .remove = bt3c_detach,
887 .id_table = bt3c_ids, 837 .id_table = bt3c_ids,
888 .suspend = bt3c_suspend,
889 .resume = bt3c_resume,
890}; 838};
891 839
892static int __init init_bt3c_cs(void) 840static int __init init_bt3c_cs(void)
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index 7b4bff4cfa2d..9ce4c93467e5 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -68,7 +68,7 @@ MODULE_LICENSE("GPL");
68 68
69 69
70typedef struct btuart_info_t { 70typedef struct btuart_info_t {
71 dev_link_t link; 71 struct pcmcia_device *p_dev;
72 dev_node_t node; 72 dev_node_t node;
73 73
74 struct hci_dev *hdev; 74 struct hci_dev *hdev;
@@ -84,8 +84,8 @@ typedef struct btuart_info_t {
84} btuart_info_t; 84} btuart_info_t;
85 85
86 86
87static void btuart_config(dev_link_t *link); 87static int btuart_config(struct pcmcia_device *link);
88static void btuart_release(dev_link_t *link); 88static void btuart_release(struct pcmcia_device *link);
89 89
90static void btuart_detach(struct pcmcia_device *p_dev); 90static void btuart_detach(struct pcmcia_device *p_dev);
91 91
@@ -146,13 +146,13 @@ static void btuart_write_wakeup(btuart_info_t *info)
146 } 146 }
147 147
148 do { 148 do {
149 register unsigned int iobase = info->link.io.BasePort1; 149 register unsigned int iobase = info->p_dev->io.BasePort1;
150 register struct sk_buff *skb; 150 register struct sk_buff *skb;
151 register int len; 151 register int len;
152 152
153 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 153 clear_bit(XMIT_WAKEUP, &(info->tx_state));
154 154
155 if (!(info->link.state & DEV_PRESENT)) 155 if (!pcmcia_dev_present(info->p_dev))
156 return; 156 return;
157 157
158 if (!(skb = skb_dequeue(&(info->txq)))) 158 if (!(skb = skb_dequeue(&(info->txq))))
@@ -187,7 +187,7 @@ static void btuart_receive(btuart_info_t *info)
187 return; 187 return;
188 } 188 }
189 189
190 iobase = info->link.io.BasePort1; 190 iobase = info->p_dev->io.BasePort1;
191 191
192 do { 192 do {
193 info->hdev->stat.byte_rx++; 193 info->hdev->stat.byte_rx++;
@@ -301,7 +301,7 @@ static irqreturn_t btuart_interrupt(int irq, void *dev_inst, struct pt_regs *reg
301 return IRQ_NONE; 301 return IRQ_NONE;
302 } 302 }
303 303
304 iobase = info->link.io.BasePort1; 304 iobase = info->p_dev->io.BasePort1;
305 305
306 spin_lock(&(info->lock)); 306 spin_lock(&(info->lock));
307 307
@@ -357,7 +357,7 @@ static void btuart_change_speed(btuart_info_t *info, unsigned int speed)
357 return; 357 return;
358 } 358 }
359 359
360 iobase = info->link.io.BasePort1; 360 iobase = info->p_dev->io.BasePort1;
361 361
362 spin_lock_irqsave(&(info->lock), flags); 362 spin_lock_irqsave(&(info->lock), flags);
363 363
@@ -481,7 +481,7 @@ static int btuart_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned lon
481static int btuart_open(btuart_info_t *info) 481static int btuart_open(btuart_info_t *info)
482{ 482{
483 unsigned long flags; 483 unsigned long flags;
484 unsigned int iobase = info->link.io.BasePort1; 484 unsigned int iobase = info->p_dev->io.BasePort1;
485 struct hci_dev *hdev; 485 struct hci_dev *hdev;
486 486
487 spin_lock_init(&(info->lock)); 487 spin_lock_init(&(info->lock));
@@ -550,7 +550,7 @@ static int btuart_open(btuart_info_t *info)
550static int btuart_close(btuart_info_t *info) 550static int btuart_close(btuart_info_t *info)
551{ 551{
552 unsigned long flags; 552 unsigned long flags;
553 unsigned int iobase = info->link.io.BasePort1; 553 unsigned int iobase = info->p_dev->io.BasePort1;
554 struct hci_dev *hdev = info->hdev; 554 struct hci_dev *hdev = info->hdev;
555 555
556 if (!hdev) 556 if (!hdev)
@@ -576,17 +576,16 @@ static int btuart_close(btuart_info_t *info)
576 return 0; 576 return 0;
577} 577}
578 578
579static int btuart_attach(struct pcmcia_device *p_dev) 579static int btuart_probe(struct pcmcia_device *link)
580{ 580{
581 btuart_info_t *info; 581 btuart_info_t *info;
582 dev_link_t *link;
583 582
584 /* Create new info device */ 583 /* Create new info device */
585 info = kzalloc(sizeof(*info), GFP_KERNEL); 584 info = kzalloc(sizeof(*info), GFP_KERNEL);
586 if (!info) 585 if (!info)
587 return -ENOMEM; 586 return -ENOMEM;
588 587
589 link = &info->link; 588 info->p_dev = link;
590 link->priv = info; 589 link->priv = info;
591 590
592 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 591 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -598,31 +597,21 @@ static int btuart_attach(struct pcmcia_device *p_dev)
598 link->irq.Instance = info; 597 link->irq.Instance = info;
599 598
600 link->conf.Attributes = CONF_ENABLE_IRQ; 599 link->conf.Attributes = CONF_ENABLE_IRQ;
601 link->conf.Vcc = 50;
602 link->conf.IntType = INT_MEMORY_AND_IO; 600 link->conf.IntType = INT_MEMORY_AND_IO;
603 601
604 link->handle = p_dev; 602 return btuart_config(link);
605 p_dev->instance = link;
606
607 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
608 btuart_config(link);
609
610 return 0;
611} 603}
612 604
613 605
614static void btuart_detach(struct pcmcia_device *p_dev) 606static void btuart_detach(struct pcmcia_device *link)
615{ 607{
616 dev_link_t *link = dev_to_instance(p_dev);
617 btuart_info_t *info = link->priv; 608 btuart_info_t *info = link->priv;
618 609
619 if (link->state & DEV_CONFIG) 610 btuart_release(link);
620 btuart_release(link);
621
622 kfree(info); 611 kfree(info);
623} 612}
624 613
625static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 614static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
626{ 615{
627 int i; 616 int i;
628 617
@@ -633,30 +622,28 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
633 return pcmcia_parse_tuple(handle, tuple, parse); 622 return pcmcia_parse_tuple(handle, tuple, parse);
634} 623}
635 624
636static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 625static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
637{ 626{
638 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 627 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
639 return CS_NO_MORE_ITEMS; 628 return CS_NO_MORE_ITEMS;
640 return get_tuple(handle, tuple, parse); 629 return get_tuple(handle, tuple, parse);
641} 630}
642 631
643static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 632static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
644{ 633{
645 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 634 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
646 return CS_NO_MORE_ITEMS; 635 return CS_NO_MORE_ITEMS;
647 return get_tuple(handle, tuple, parse); 636 return get_tuple(handle, tuple, parse);
648} 637}
649 638
650static void btuart_config(dev_link_t *link) 639static int btuart_config(struct pcmcia_device *link)
651{ 640{
652 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 641 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
653 client_handle_t handle = link->handle;
654 btuart_info_t *info = link->priv; 642 btuart_info_t *info = link->priv;
655 tuple_t tuple; 643 tuple_t tuple;
656 u_short buf[256]; 644 u_short buf[256];
657 cisparse_t parse; 645 cisparse_t parse;
658 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 646 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
659 config_info_t config;
660 int i, j, try, last_ret, last_fn; 647 int i, j, try, last_ret, last_fn;
661 648
662 tuple.TupleData = (cisdata_t *)buf; 649 tuple.TupleData = (cisdata_t *)buf;
@@ -666,7 +653,7 @@ static void btuart_config(dev_link_t *link)
666 653
667 /* Get configuration register information */ 654 /* Get configuration register information */
668 tuple.DesiredTuple = CISTPL_CONFIG; 655 tuple.DesiredTuple = CISTPL_CONFIG;
669 last_ret = first_tuple(handle, &tuple, &parse); 656 last_ret = first_tuple(link, &tuple, &parse);
670 if (last_ret != CS_SUCCESS) { 657 if (last_ret != CS_SUCCESS) {
671 last_fn = ParseTuple; 658 last_fn = ParseTuple;
672 goto cs_failed; 659 goto cs_failed;
@@ -674,11 +661,6 @@ static void btuart_config(dev_link_t *link)
674 link->conf.ConfigBase = parse.config.base; 661 link->conf.ConfigBase = parse.config.base;
675 link->conf.Present = parse.config.rmask[0]; 662 link->conf.Present = parse.config.rmask[0];
676 663
677 /* Configure card */
678 link->state |= DEV_CONFIG;
679 i = pcmcia_get_configuration_info(handle, &config);
680 link->conf.Vcc = config.Vcc;
681
682 /* First pass: look for a config entry that looks normal. */ 664 /* First pass: look for a config entry that looks normal. */
683 tuple.TupleData = (cisdata_t *) buf; 665 tuple.TupleData = (cisdata_t *) buf;
684 tuple.TupleOffset = 0; 666 tuple.TupleOffset = 0;
@@ -687,29 +669,29 @@ static void btuart_config(dev_link_t *link)
687 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 669 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
688 /* Two tries: without IO aliases, then with aliases */ 670 /* Two tries: without IO aliases, then with aliases */
689 for (try = 0; try < 2; try++) { 671 for (try = 0; try < 2; try++) {
690 i = first_tuple(handle, &tuple, &parse); 672 i = first_tuple(link, &tuple, &parse);
691 while (i != CS_NO_MORE_ITEMS) { 673 while (i != CS_NO_MORE_ITEMS) {
692 if (i != CS_SUCCESS) 674 if (i != CS_SUCCESS)
693 goto next_entry; 675 goto next_entry;
694 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 676 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
695 link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 677 link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
696 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) { 678 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
697 link->conf.ConfigIndex = cf->index; 679 link->conf.ConfigIndex = cf->index;
698 link->io.BasePort1 = cf->io.win[0].base; 680 link->io.BasePort1 = cf->io.win[0].base;
699 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 681 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
700 i = pcmcia_request_io(link->handle, &link->io); 682 i = pcmcia_request_io(link, &link->io);
701 if (i == CS_SUCCESS) 683 if (i == CS_SUCCESS)
702 goto found_port; 684 goto found_port;
703 } 685 }
704next_entry: 686next_entry:
705 i = next_tuple(handle, &tuple, &parse); 687 i = next_tuple(link, &tuple, &parse);
706 } 688 }
707 } 689 }
708 690
709 /* Second pass: try to find an entry that isn't picky about 691 /* Second pass: try to find an entry that isn't picky about
710 its base address, then try to grab any standard serial port 692 its base address, then try to grab any standard serial port
711 address, and finally try to get any free port. */ 693 address, and finally try to get any free port. */
712 i = first_tuple(handle, &tuple, &parse); 694 i = first_tuple(link, &tuple, &parse);
713 while (i != CS_NO_MORE_ITEMS) { 695 while (i != CS_NO_MORE_ITEMS) {
714 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) 696 if ((i == CS_SUCCESS) && (cf->io.nwin > 0)
715 && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 697 && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
@@ -717,30 +699,30 @@ next_entry:
717 for (j = 0; j < 5; j++) { 699 for (j = 0; j < 5; j++) {
718 link->io.BasePort1 = base[j]; 700 link->io.BasePort1 = base[j];
719 link->io.IOAddrLines = base[j] ? 16 : 3; 701 link->io.IOAddrLines = base[j] ? 16 : 3;
720 i = pcmcia_request_io(link->handle, &link->io); 702 i = pcmcia_request_io(link, &link->io);
721 if (i == CS_SUCCESS) 703 if (i == CS_SUCCESS)
722 goto found_port; 704 goto found_port;
723 } 705 }
724 } 706 }
725 i = next_tuple(handle, &tuple, &parse); 707 i = next_tuple(link, &tuple, &parse);
726 } 708 }
727 709
728found_port: 710found_port:
729 if (i != CS_SUCCESS) { 711 if (i != CS_SUCCESS) {
730 BT_ERR("No usable port range found"); 712 BT_ERR("No usable port range found");
731 cs_error(link->handle, RequestIO, i); 713 cs_error(link, RequestIO, i);
732 goto failed; 714 goto failed;
733 } 715 }
734 716
735 i = pcmcia_request_irq(link->handle, &link->irq); 717 i = pcmcia_request_irq(link, &link->irq);
736 if (i != CS_SUCCESS) { 718 if (i != CS_SUCCESS) {
737 cs_error(link->handle, RequestIRQ, i); 719 cs_error(link, RequestIRQ, i);
738 link->irq.AssignedIRQ = 0; 720 link->irq.AssignedIRQ = 0;
739 } 721 }
740 722
741 i = pcmcia_request_configuration(link->handle, &link->conf); 723 i = pcmcia_request_configuration(link, &link->conf);
742 if (i != CS_SUCCESS) { 724 if (i != CS_SUCCESS) {
743 cs_error(link->handle, RequestConfiguration, i); 725 cs_error(link, RequestConfiguration, i);
744 goto failed; 726 goto failed;
745 } 727 }
746 728
@@ -748,58 +730,28 @@ found_port:
748 goto failed; 730 goto failed;
749 731
750 strcpy(info->node.dev_name, info->hdev->name); 732 strcpy(info->node.dev_name, info->hdev->name);
751 link->dev = &info->node; 733 link->dev_node = &info->node;
752 link->state &= ~DEV_CONFIG_PENDING;
753 734
754 return; 735 return 0;
755 736
756cs_failed: 737cs_failed:
757 cs_error(link->handle, last_fn, last_ret); 738 cs_error(link, last_fn, last_ret);
758 739
759failed: 740failed:
760 btuart_release(link); 741 btuart_release(link);
742 return -ENODEV;
761} 743}
762 744
763 745
764static void btuart_release(dev_link_t *link) 746static void btuart_release(struct pcmcia_device *link)
765{ 747{
766 btuart_info_t *info = link->priv; 748 btuart_info_t *info = link->priv;
767 749
768 if (link->state & DEV_PRESENT) 750 btuart_close(info);
769 btuart_close(info);
770
771 link->dev = NULL;
772
773 pcmcia_release_configuration(link->handle);
774 pcmcia_release_io(link->handle, &link->io);
775 pcmcia_release_irq(link->handle, &link->irq);
776
777 link->state &= ~DEV_CONFIG;
778}
779
780static int btuart_suspend(struct pcmcia_device *dev)
781{
782 dev_link_t *link = dev_to_instance(dev);
783
784 link->state |= DEV_SUSPEND;
785 if (link->state & DEV_CONFIG)
786 pcmcia_release_configuration(link->handle);
787 751
788 return 0; 752 pcmcia_disable_device(link);
789} 753}
790 754
791static int btuart_resume(struct pcmcia_device *dev)
792{
793 dev_link_t *link = dev_to_instance(dev);
794
795 link->state &= ~DEV_SUSPEND;
796 if (DEV_OK(link))
797 pcmcia_request_configuration(link->handle, &link->conf);
798
799 return 0;
800}
801
802
803static struct pcmcia_device_id btuart_ids[] = { 755static struct pcmcia_device_id btuart_ids[] = {
804 /* don't use this driver. Use serial_cs + hci_uart instead */ 756 /* don't use this driver. Use serial_cs + hci_uart instead */
805 PCMCIA_DEVICE_NULL 757 PCMCIA_DEVICE_NULL
@@ -811,11 +763,9 @@ static struct pcmcia_driver btuart_driver = {
811 .drv = { 763 .drv = {
812 .name = "btuart_cs", 764 .name = "btuart_cs",
813 }, 765 },
814 .probe = btuart_attach, 766 .probe = btuart_probe,
815 .remove = btuart_detach, 767 .remove = btuart_detach,
816 .id_table = btuart_ids, 768 .id_table = btuart_ids,
817 .suspend = btuart_suspend,
818 .resume = btuart_resume,
819}; 769};
820 770
821static int __init init_btuart_cs(void) 771static int __init init_btuart_cs(void)
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 0449bc45ae5e..a71a240611e0 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -68,7 +68,7 @@ MODULE_LICENSE("GPL");
68 68
69 69
70typedef struct dtl1_info_t { 70typedef struct dtl1_info_t {
71 dev_link_t link; 71 struct pcmcia_device *p_dev;
72 dev_node_t node; 72 dev_node_t node;
73 73
74 struct hci_dev *hdev; 74 struct hci_dev *hdev;
@@ -87,8 +87,8 @@ typedef struct dtl1_info_t {
87} dtl1_info_t; 87} dtl1_info_t;
88 88
89 89
90static void dtl1_config(dev_link_t *link); 90static int dtl1_config(struct pcmcia_device *link);
91static void dtl1_release(dev_link_t *link); 91static void dtl1_release(struct pcmcia_device *link);
92 92
93static void dtl1_detach(struct pcmcia_device *p_dev); 93static void dtl1_detach(struct pcmcia_device *p_dev);
94 94
@@ -153,13 +153,13 @@ static void dtl1_write_wakeup(dtl1_info_t *info)
153 } 153 }
154 154
155 do { 155 do {
156 register unsigned int iobase = info->link.io.BasePort1; 156 register unsigned int iobase = info->p_dev->io.BasePort1;
157 register struct sk_buff *skb; 157 register struct sk_buff *skb;
158 register int len; 158 register int len;
159 159
160 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 160 clear_bit(XMIT_WAKEUP, &(info->tx_state));
161 161
162 if (!(info->link.state & DEV_PRESENT)) 162 if (!pcmcia_dev_present(info->p_dev))
163 return; 163 return;
164 164
165 if (!(skb = skb_dequeue(&(info->txq)))) 165 if (!(skb = skb_dequeue(&(info->txq))))
@@ -218,7 +218,7 @@ static void dtl1_receive(dtl1_info_t *info)
218 return; 218 return;
219 } 219 }
220 220
221 iobase = info->link.io.BasePort1; 221 iobase = info->p_dev->io.BasePort1;
222 222
223 do { 223 do {
224 info->hdev->stat.byte_rx++; 224 info->hdev->stat.byte_rx++;
@@ -305,7 +305,7 @@ static irqreturn_t dtl1_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
305 return IRQ_NONE; 305 return IRQ_NONE;
306 } 306 }
307 307
308 iobase = info->link.io.BasePort1; 308 iobase = info->p_dev->io.BasePort1;
309 309
310 spin_lock(&(info->lock)); 310 spin_lock(&(info->lock));
311 311
@@ -458,7 +458,7 @@ static int dtl1_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long
458static int dtl1_open(dtl1_info_t *info) 458static int dtl1_open(dtl1_info_t *info)
459{ 459{
460 unsigned long flags; 460 unsigned long flags;
461 unsigned int iobase = info->link.io.BasePort1; 461 unsigned int iobase = info->p_dev->io.BasePort1;
462 struct hci_dev *hdev; 462 struct hci_dev *hdev;
463 463
464 spin_lock_init(&(info->lock)); 464 spin_lock_init(&(info->lock));
@@ -504,7 +504,7 @@ static int dtl1_open(dtl1_info_t *info)
504 outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */ 504 outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */
505 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR); 505 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR);
506 506
507 info->ri_latch = inb(info->link.io.BasePort1 + UART_MSR) & UART_MSR_RI; 507 info->ri_latch = inb(info->p_dev->io.BasePort1 + UART_MSR) & UART_MSR_RI;
508 508
509 /* Turn on interrupts */ 509 /* Turn on interrupts */
510 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER); 510 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
@@ -529,7 +529,7 @@ static int dtl1_open(dtl1_info_t *info)
529static int dtl1_close(dtl1_info_t *info) 529static int dtl1_close(dtl1_info_t *info)
530{ 530{
531 unsigned long flags; 531 unsigned long flags;
532 unsigned int iobase = info->link.io.BasePort1; 532 unsigned int iobase = info->p_dev->io.BasePort1;
533 struct hci_dev *hdev = info->hdev; 533 struct hci_dev *hdev = info->hdev;
534 534
535 if (!hdev) 535 if (!hdev)
@@ -555,17 +555,16 @@ static int dtl1_close(dtl1_info_t *info)
555 return 0; 555 return 0;
556} 556}
557 557
558static int dtl1_attach(struct pcmcia_device *p_dev) 558static int dtl1_probe(struct pcmcia_device *link)
559{ 559{
560 dtl1_info_t *info; 560 dtl1_info_t *info;
561 dev_link_t *link;
562 561
563 /* Create new info device */ 562 /* Create new info device */
564 info = kzalloc(sizeof(*info), GFP_KERNEL); 563 info = kzalloc(sizeof(*info), GFP_KERNEL);
565 if (!info) 564 if (!info)
566 return -ENOMEM; 565 return -ENOMEM;
567 566
568 link = &info->link; 567 info->p_dev = link;
569 link->priv = info; 568 link->priv = info;
570 569
571 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 570 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -577,31 +576,22 @@ static int dtl1_attach(struct pcmcia_device *p_dev)
577 link->irq.Instance = info; 576 link->irq.Instance = info;
578 577
579 link->conf.Attributes = CONF_ENABLE_IRQ; 578 link->conf.Attributes = CONF_ENABLE_IRQ;
580 link->conf.Vcc = 50;
581 link->conf.IntType = INT_MEMORY_AND_IO; 579 link->conf.IntType = INT_MEMORY_AND_IO;
582 580
583 link->handle = p_dev; 581 return dtl1_config(link);
584 p_dev->instance = link;
585
586 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
587 dtl1_config(link);
588
589 return 0;
590} 582}
591 583
592 584
593static void dtl1_detach(struct pcmcia_device *p_dev) 585static void dtl1_detach(struct pcmcia_device *link)
594{ 586{
595 dev_link_t *link = dev_to_instance(p_dev);
596 dtl1_info_t *info = link->priv; 587 dtl1_info_t *info = link->priv;
597 588
598 if (link->state & DEV_CONFIG) 589 dtl1_release(link);
599 dtl1_release(link);
600 590
601 kfree(info); 591 kfree(info);
602} 592}
603 593
604static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 594static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
605{ 595{
606 int i; 596 int i;
607 597
@@ -612,29 +602,27 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
612 return pcmcia_parse_tuple(handle, tuple, parse); 602 return pcmcia_parse_tuple(handle, tuple, parse);
613} 603}
614 604
615static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 605static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
616{ 606{
617 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 607 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
618 return CS_NO_MORE_ITEMS; 608 return CS_NO_MORE_ITEMS;
619 return get_tuple(handle, tuple, parse); 609 return get_tuple(handle, tuple, parse);
620} 610}
621 611
622static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 612static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
623{ 613{
624 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 614 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
625 return CS_NO_MORE_ITEMS; 615 return CS_NO_MORE_ITEMS;
626 return get_tuple(handle, tuple, parse); 616 return get_tuple(handle, tuple, parse);
627} 617}
628 618
629static void dtl1_config(dev_link_t *link) 619static int dtl1_config(struct pcmcia_device *link)
630{ 620{
631 client_handle_t handle = link->handle;
632 dtl1_info_t *info = link->priv; 621 dtl1_info_t *info = link->priv;
633 tuple_t tuple; 622 tuple_t tuple;
634 u_short buf[256]; 623 u_short buf[256];
635 cisparse_t parse; 624 cisparse_t parse;
636 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 625 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
637 config_info_t config;
638 int i, last_ret, last_fn; 626 int i, last_ret, last_fn;
639 627
640 tuple.TupleData = (cisdata_t *)buf; 628 tuple.TupleData = (cisdata_t *)buf;
@@ -644,7 +632,7 @@ static void dtl1_config(dev_link_t *link)
644 632
645 /* Get configuration register information */ 633 /* Get configuration register information */
646 tuple.DesiredTuple = CISTPL_CONFIG; 634 tuple.DesiredTuple = CISTPL_CONFIG;
647 last_ret = first_tuple(handle, &tuple, &parse); 635 last_ret = first_tuple(link, &tuple, &parse);
648 if (last_ret != CS_SUCCESS) { 636 if (last_ret != CS_SUCCESS) {
649 last_fn = ParseTuple; 637 last_fn = ParseTuple;
650 goto cs_failed; 638 goto cs_failed;
@@ -652,11 +640,6 @@ static void dtl1_config(dev_link_t *link)
652 link->conf.ConfigBase = parse.config.base; 640 link->conf.ConfigBase = parse.config.base;
653 link->conf.Present = parse.config.rmask[0]; 641 link->conf.Present = parse.config.rmask[0];
654 642
655 /* Configure card */
656 link->state |= DEV_CONFIG;
657 i = pcmcia_get_configuration_info(handle, &config);
658 link->conf.Vcc = config.Vcc;
659
660 tuple.TupleData = (cisdata_t *)buf; 643 tuple.TupleData = (cisdata_t *)buf;
661 tuple.TupleOffset = 0; 644 tuple.TupleOffset = 0;
662 tuple.TupleDataMax = 255; 645 tuple.TupleDataMax = 255;
@@ -665,34 +648,34 @@ static void dtl1_config(dev_link_t *link)
665 648
666 /* Look for a generic full-sized window */ 649 /* Look for a generic full-sized window */
667 link->io.NumPorts1 = 8; 650 link->io.NumPorts1 = 8;
668 i = first_tuple(handle, &tuple, &parse); 651 i = first_tuple(link, &tuple, &parse);
669 while (i != CS_NO_MORE_ITEMS) { 652 while (i != CS_NO_MORE_ITEMS) {
670 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { 653 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
671 link->conf.ConfigIndex = cf->index; 654 link->conf.ConfigIndex = cf->index;
672 link->io.BasePort1 = cf->io.win[0].base; 655 link->io.BasePort1 = cf->io.win[0].base;
673 link->io.NumPorts1 = cf->io.win[0].len; /*yo */ 656 link->io.NumPorts1 = cf->io.win[0].len; /*yo */
674 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; 657 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
675 i = pcmcia_request_io(link->handle, &link->io); 658 i = pcmcia_request_io(link, &link->io);
676 if (i == CS_SUCCESS) 659 if (i == CS_SUCCESS)
677 break; 660 break;
678 } 661 }
679 i = next_tuple(handle, &tuple, &parse); 662 i = next_tuple(link, &tuple, &parse);
680 } 663 }
681 664
682 if (i != CS_SUCCESS) { 665 if (i != CS_SUCCESS) {
683 cs_error(link->handle, RequestIO, i); 666 cs_error(link, RequestIO, i);
684 goto failed; 667 goto failed;
685 } 668 }
686 669
687 i = pcmcia_request_irq(link->handle, &link->irq); 670 i = pcmcia_request_irq(link, &link->irq);
688 if (i != CS_SUCCESS) { 671 if (i != CS_SUCCESS) {
689 cs_error(link->handle, RequestIRQ, i); 672 cs_error(link, RequestIRQ, i);
690 link->irq.AssignedIRQ = 0; 673 link->irq.AssignedIRQ = 0;
691 } 674 }
692 675
693 i = pcmcia_request_configuration(link->handle, &link->conf); 676 i = pcmcia_request_configuration(link, &link->conf);
694 if (i != CS_SUCCESS) { 677 if (i != CS_SUCCESS) {
695 cs_error(link->handle, RequestConfiguration, i); 678 cs_error(link, RequestConfiguration, i);
696 goto failed; 679 goto failed;
697 } 680 }
698 681
@@ -700,55 +683,26 @@ static void dtl1_config(dev_link_t *link)
700 goto failed; 683 goto failed;
701 684
702 strcpy(info->node.dev_name, info->hdev->name); 685 strcpy(info->node.dev_name, info->hdev->name);
703 link->dev = &info->node; 686 link->dev_node = &info->node;
704 link->state &= ~DEV_CONFIG_PENDING;
705 687
706 return; 688 return 0;
707 689
708cs_failed: 690cs_failed:
709 cs_error(link->handle, last_fn, last_ret); 691 cs_error(link, last_fn, last_ret);
710 692
711failed: 693failed:
712 dtl1_release(link); 694 dtl1_release(link);
695 return -ENODEV;
713} 696}
714 697
715 698
716static void dtl1_release(dev_link_t *link) 699static void dtl1_release(struct pcmcia_device *link)
717{ 700{
718 dtl1_info_t *info = link->priv; 701 dtl1_info_t *info = link->priv;
719 702
720 if (link->state & DEV_PRESENT) 703 dtl1_close(info);
721 dtl1_close(info);
722
723 link->dev = NULL;
724
725 pcmcia_release_configuration(link->handle);
726 pcmcia_release_io(link->handle, &link->io);
727 pcmcia_release_irq(link->handle, &link->irq);
728
729 link->state &= ~DEV_CONFIG;
730}
731
732static int dtl1_suspend(struct pcmcia_device *dev)
733{
734 dev_link_t *link = dev_to_instance(dev);
735
736 link->state |= DEV_SUSPEND;
737 if (link->state & DEV_CONFIG)
738 pcmcia_release_configuration(link->handle);
739
740 return 0;
741}
742
743static int dtl1_resume(struct pcmcia_device *dev)
744{
745 dev_link_t *link = dev_to_instance(dev);
746 704
747 link->state &= ~DEV_SUSPEND; 705 pcmcia_disable_device(link);
748 if (DEV_OK(link))
749 pcmcia_request_configuration(link->handle, &link->conf);
750
751 return 0;
752} 706}
753 707
754 708
@@ -765,11 +719,9 @@ static struct pcmcia_driver dtl1_driver = {
765 .drv = { 719 .drv = {
766 .name = "dtl1_cs", 720 .name = "dtl1_cs",
767 }, 721 },
768 .probe = dtl1_attach, 722 .probe = dtl1_probe,
769 .remove = dtl1_detach, 723 .remove = dtl1_detach,
770 .id_table = dtl1_ids, 724 .id_table = dtl1_ids,
771 .suspend = dtl1_suspend,
772 .resume = dtl1_resume,
773}; 725};
774 726
775static int __init init_dtl1_cs(void) 727static int __init init_dtl1_cs(void)
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 5fdf18515433..02114a0bd0d9 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -46,7 +46,7 @@
46/* #define ATR_CSUM */ 46/* #define ATR_CSUM */
47 47
48#ifdef PCMCIA_DEBUG 48#ifdef PCMCIA_DEBUG
49#define reader_to_dev(x) (&handle_to_dev(x->link.handle)) 49#define reader_to_dev(x) (&handle_to_dev(x->p_dev->handle))
50static int pc_debug = PCMCIA_DEBUG; 50static int pc_debug = PCMCIA_DEBUG;
51module_param(pc_debug, int, 0600); 51module_param(pc_debug, int, 0600);
52#define DEBUGP(n, rdr, x, args...) do { \ 52#define DEBUGP(n, rdr, x, args...) do { \
@@ -67,7 +67,7 @@ static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte";
67#define T_100MSEC msecs_to_jiffies(100) 67#define T_100MSEC msecs_to_jiffies(100)
68#define T_500MSEC msecs_to_jiffies(500) 68#define T_500MSEC msecs_to_jiffies(500)
69 69
70static void cm4000_release(dev_link_t *link); 70static void cm4000_release(struct pcmcia_device *link);
71 71
72static int major; /* major number we get from the kernel */ 72static int major; /* major number we get from the kernel */
73 73
@@ -106,7 +106,7 @@ static int major; /* major number we get from the kernel */
106#define REG_STOPBITS(x) (x + 7) 106#define REG_STOPBITS(x) (x + 7)
107 107
108struct cm4000_dev { 108struct cm4000_dev {
109 dev_link_t link; /* pcmcia link */ 109 struct pcmcia_device *p_dev;
110 dev_node_t node; /* OS node (major,minor) */ 110 dev_node_t node; /* OS node (major,minor) */
111 111
112 unsigned char atr[MAX_ATR]; 112 unsigned char atr[MAX_ATR];
@@ -149,14 +149,14 @@ struct cm4000_dev {
149#define ZERO_DEV(dev) \ 149#define ZERO_DEV(dev) \
150 memset(&dev->atr_csum,0, \ 150 memset(&dev->atr_csum,0, \
151 sizeof(struct cm4000_dev) - \ 151 sizeof(struct cm4000_dev) - \
152 /*link*/ sizeof(dev_link_t) - \ 152 /*link*/ sizeof(struct pcmcia_device) - \
153 /*node*/ sizeof(dev_node_t) - \ 153 /*node*/ sizeof(dev_node_t) - \
154 /*atr*/ MAX_ATR*sizeof(char) - \ 154 /*atr*/ MAX_ATR*sizeof(char) - \
155 /*rbuf*/ 512*sizeof(char) - \ 155 /*rbuf*/ 512*sizeof(char) - \
156 /*sbuf*/ 512*sizeof(char) - \ 156 /*sbuf*/ 512*sizeof(char) - \
157 /*queue*/ 4*sizeof(wait_queue_head_t)) 157 /*queue*/ 4*sizeof(wait_queue_head_t))
158 158
159static dev_link_t *dev_table[CM4000_MAX_DEV]; 159static struct pcmcia_device *dev_table[CM4000_MAX_DEV];
160static struct class *cmm_class; 160static struct class *cmm_class;
161 161
162/* This table doesn't use spaces after the comma between fields and thus 162/* This table doesn't use spaces after the comma between fields and thus
@@ -454,7 +454,7 @@ static struct card_fixup card_fixups[] = {
454static void set_cardparameter(struct cm4000_dev *dev) 454static void set_cardparameter(struct cm4000_dev *dev)
455{ 455{
456 int i; 456 int i;
457 ioaddr_t iobase = dev->link.io.BasePort1; 457 ioaddr_t iobase = dev->p_dev->io.BasePort1;
458 u_int8_t stopbits = 0x02; /* ISO default */ 458 u_int8_t stopbits = 0x02; /* ISO default */
459 459
460 DEBUGP(3, dev, "-> set_cardparameter\n"); 460 DEBUGP(3, dev, "-> set_cardparameter\n");
@@ -487,7 +487,7 @@ static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
487 unsigned short num_bytes_read; 487 unsigned short num_bytes_read;
488 unsigned char pts_reply[4]; 488 unsigned char pts_reply[4];
489 ssize_t rc; 489 ssize_t rc;
490 ioaddr_t iobase = dev->link.io.BasePort1; 490 ioaddr_t iobase = dev->p_dev->io.BasePort1;
491 491
492 rc = 0; 492 rc = 0;
493 493
@@ -699,7 +699,7 @@ static void terminate_monitor(struct cm4000_dev *dev)
699static void monitor_card(unsigned long p) 699static void monitor_card(unsigned long p)
700{ 700{
701 struct cm4000_dev *dev = (struct cm4000_dev *) p; 701 struct cm4000_dev *dev = (struct cm4000_dev *) p;
702 ioaddr_t iobase = dev->link.io.BasePort1; 702 ioaddr_t iobase = dev->p_dev->io.BasePort1;
703 unsigned short s; 703 unsigned short s;
704 struct ptsreq ptsreq; 704 struct ptsreq ptsreq;
705 int i, atrc; 705 int i, atrc;
@@ -962,7 +962,7 @@ static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
962 loff_t *ppos) 962 loff_t *ppos)
963{ 963{
964 struct cm4000_dev *dev = filp->private_data; 964 struct cm4000_dev *dev = filp->private_data;
965 ioaddr_t iobase = dev->link.io.BasePort1; 965 ioaddr_t iobase = dev->p_dev->io.BasePort1;
966 ssize_t rc; 966 ssize_t rc;
967 int i, j, k; 967 int i, j, k;
968 968
@@ -971,7 +971,7 @@ static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
971 if (count == 0) /* according to manpage */ 971 if (count == 0) /* according to manpage */
972 return 0; 972 return 0;
973 973
974 if ((dev->link.state & DEV_PRESENT) == 0 || /* socket removed */ 974 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */
975 test_bit(IS_CMM_ABSENT, &dev->flags)) 975 test_bit(IS_CMM_ABSENT, &dev->flags))
976 return -ENODEV; 976 return -ENODEV;
977 977
@@ -1083,7 +1083,7 @@ static ssize_t cmm_write(struct file *filp, const char __user *buf,
1083 size_t count, loff_t *ppos) 1083 size_t count, loff_t *ppos)
1084{ 1084{
1085 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data; 1085 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data;
1086 ioaddr_t iobase = dev->link.io.BasePort1; 1086 ioaddr_t iobase = dev->p_dev->io.BasePort1;
1087 unsigned short s; 1087 unsigned short s;
1088 unsigned char tmp; 1088 unsigned char tmp;
1089 unsigned char infolen; 1089 unsigned char infolen;
@@ -1108,7 +1108,7 @@ static ssize_t cmm_write(struct file *filp, const char __user *buf,
1108 1108
1109 sendT0 = dev->proto ? 0 : nr > 5 ? 0x08 : 0; 1109 sendT0 = dev->proto ? 0 : nr > 5 ? 0x08 : 0;
1110 1110
1111 if ((dev->link.state & DEV_PRESENT) == 0 || /* socket removed */ 1111 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */
1112 test_bit(IS_CMM_ABSENT, &dev->flags)) 1112 test_bit(IS_CMM_ABSENT, &dev->flags))
1113 return -ENODEV; 1113 return -ENODEV;
1114 1114
@@ -1440,8 +1440,8 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1440 unsigned long arg) 1440 unsigned long arg)
1441{ 1441{
1442 struct cm4000_dev *dev = filp->private_data; 1442 struct cm4000_dev *dev = filp->private_data;
1443 ioaddr_t iobase = dev->link.io.BasePort1; 1443 ioaddr_t iobase = dev->p_dev->io.BasePort1;
1444 dev_link_t *link; 1444 struct pcmcia_device *link;
1445 int size; 1445 int size;
1446 int rc; 1446 int rc;
1447 void __user *argp = (void __user *)arg; 1447 void __user *argp = (void __user *)arg;
@@ -1458,7 +1458,7 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1458 iminor(inode), ioctl_names[_IOC_NR(cmd)]); 1458 iminor(inode), ioctl_names[_IOC_NR(cmd)]);
1459 1459
1460 link = dev_table[iminor(inode)]; 1460 link = dev_table[iminor(inode)];
1461 if (!(DEV_OK(link))) { 1461 if (!pcmcia_dev_present(link)) {
1462 DEBUGP(4, dev, "DEV_OK false\n"); 1462 DEBUGP(4, dev, "DEV_OK false\n");
1463 return -ENODEV; 1463 return -ENODEV;
1464 } 1464 }
@@ -1660,14 +1660,14 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1660static int cmm_open(struct inode *inode, struct file *filp) 1660static int cmm_open(struct inode *inode, struct file *filp)
1661{ 1661{
1662 struct cm4000_dev *dev; 1662 struct cm4000_dev *dev;
1663 dev_link_t *link; 1663 struct pcmcia_device *link;
1664 int rc, minor = iminor(inode); 1664 int rc, minor = iminor(inode);
1665 1665
1666 if (minor >= CM4000_MAX_DEV) 1666 if (minor >= CM4000_MAX_DEV)
1667 return -ENODEV; 1667 return -ENODEV;
1668 1668
1669 link = dev_table[minor]; 1669 link = dev_table[minor];
1670 if (link == NULL || !(DEV_OK(link))) 1670 if (link == NULL || !pcmcia_dev_present(link))
1671 return -ENODEV; 1671 return -ENODEV;
1672 1672
1673 if (link->open) 1673 if (link->open)
@@ -1709,7 +1709,7 @@ static int cmm_open(struct inode *inode, struct file *filp)
1709static int cmm_close(struct inode *inode, struct file *filp) 1709static int cmm_close(struct inode *inode, struct file *filp)
1710{ 1710{
1711 struct cm4000_dev *dev; 1711 struct cm4000_dev *dev;
1712 dev_link_t *link; 1712 struct pcmcia_device *link;
1713 int minor = iminor(inode); 1713 int minor = iminor(inode);
1714 1714
1715 if (minor >= CM4000_MAX_DEV) 1715 if (minor >= CM4000_MAX_DEV)
@@ -1735,7 +1735,7 @@ static int cmm_close(struct inode *inode, struct file *filp)
1735 return 0; 1735 return 0;
1736} 1736}
1737 1737
1738static void cmm_cm4000_release(dev_link_t * link) 1738static void cmm_cm4000_release(struct pcmcia_device * link)
1739{ 1739{
1740 struct cm4000_dev *dev = link->priv; 1740 struct cm4000_dev *dev = link->priv;
1741 1741
@@ -1759,13 +1759,11 @@ static void cmm_cm4000_release(dev_link_t * link)
1759 1759
1760/*==== Interface to PCMCIA Layer =======================================*/ 1760/*==== Interface to PCMCIA Layer =======================================*/
1761 1761
1762static void cm4000_config(dev_link_t * link, int devno) 1762static int cm4000_config(struct pcmcia_device * link, int devno)
1763{ 1763{
1764 client_handle_t handle = link->handle;
1765 struct cm4000_dev *dev; 1764 struct cm4000_dev *dev;
1766 tuple_t tuple; 1765 tuple_t tuple;
1767 cisparse_t parse; 1766 cisparse_t parse;
1768 config_info_t conf;
1769 u_char buf[64]; 1767 u_char buf[64];
1770 int fail_fn, fail_rc; 1768 int fail_fn, fail_rc;
1771 int rc; 1769 int rc;
@@ -1777,41 +1775,34 @@ static void cm4000_config(dev_link_t * link, int devno)
1777 tuple.TupleDataMax = sizeof(buf); 1775 tuple.TupleDataMax = sizeof(buf);
1778 tuple.TupleOffset = 0; 1776 tuple.TupleOffset = 0;
1779 1777
1780 if ((fail_rc = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) { 1778 if ((fail_rc = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) {
1781 fail_fn = GetFirstTuple; 1779 fail_fn = GetFirstTuple;
1782 goto cs_failed; 1780 goto cs_failed;
1783 } 1781 }
1784 if ((fail_rc = pcmcia_get_tuple_data(handle, &tuple)) != CS_SUCCESS) { 1782 if ((fail_rc = pcmcia_get_tuple_data(link, &tuple)) != CS_SUCCESS) {
1785 fail_fn = GetTupleData; 1783 fail_fn = GetTupleData;
1786 goto cs_failed; 1784 goto cs_failed;
1787 } 1785 }
1788 if ((fail_rc = 1786 if ((fail_rc =
1789 pcmcia_parse_tuple(handle, &tuple, &parse)) != CS_SUCCESS) { 1787 pcmcia_parse_tuple(link, &tuple, &parse)) != CS_SUCCESS) {
1790 fail_fn = ParseTuple; 1788 fail_fn = ParseTuple;
1791 goto cs_failed; 1789 goto cs_failed;
1792 } 1790 }
1793 if ((fail_rc =
1794 pcmcia_get_configuration_info(handle, &conf)) != CS_SUCCESS) {
1795 fail_fn = GetConfigurationInfo;
1796 goto cs_failed;
1797 }
1798 1791
1799 link->state |= DEV_CONFIG;
1800 link->conf.ConfigBase = parse.config.base; 1792 link->conf.ConfigBase = parse.config.base;
1801 link->conf.Present = parse.config.rmask[0]; 1793 link->conf.Present = parse.config.rmask[0];
1802 link->conf.Vcc = conf.Vcc;
1803 1794
1804 link->io.BasePort2 = 0; 1795 link->io.BasePort2 = 0;
1805 link->io.NumPorts2 = 0; 1796 link->io.NumPorts2 = 0;
1806 link->io.Attributes2 = 0; 1797 link->io.Attributes2 = 0;
1807 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 1798 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1808 for (rc = pcmcia_get_first_tuple(handle, &tuple); 1799 for (rc = pcmcia_get_first_tuple(link, &tuple);
1809 rc == CS_SUCCESS; rc = pcmcia_get_next_tuple(handle, &tuple)) { 1800 rc == CS_SUCCESS; rc = pcmcia_get_next_tuple(link, &tuple)) {
1810 1801
1811 rc = pcmcia_get_tuple_data(handle, &tuple); 1802 rc = pcmcia_get_tuple_data(link, &tuple);
1812 if (rc != CS_SUCCESS) 1803 if (rc != CS_SUCCESS)
1813 continue; 1804 continue;
1814 rc = pcmcia_parse_tuple(handle, &tuple, &parse); 1805 rc = pcmcia_parse_tuple(link, &tuple, &parse);
1815 if (rc != CS_SUCCESS) 1806 if (rc != CS_SUCCESS)
1816 continue; 1807 continue;
1817 1808
@@ -1831,7 +1822,7 @@ static void cm4000_config(dev_link_t * link, int devno)
1831 link->io.IOAddrLines = parse.cftable_entry.io.flags 1822 link->io.IOAddrLines = parse.cftable_entry.io.flags
1832 & CISTPL_IO_LINES_MASK; 1823 & CISTPL_IO_LINES_MASK;
1833 1824
1834 rc = pcmcia_request_io(handle, &link->io); 1825 rc = pcmcia_request_io(link, &link->io);
1835 if (rc == CS_SUCCESS) 1826 if (rc == CS_SUCCESS)
1836 break; /* we are done */ 1827 break; /* we are done */
1837 } 1828 }
@@ -1841,7 +1832,7 @@ static void cm4000_config(dev_link_t * link, int devno)
1841 link->conf.IntType = 00000002; 1832 link->conf.IntType = 00000002;
1842 1833
1843 if ((fail_rc = 1834 if ((fail_rc =
1844 pcmcia_request_configuration(handle, &link->conf)) != CS_SUCCESS) { 1835 pcmcia_request_configuration(link, &link->conf)) != CS_SUCCESS) {
1845 fail_fn = RequestConfiguration; 1836 fail_fn = RequestConfiguration;
1846 goto cs_release; 1837 goto cs_release;
1847 } 1838 }
@@ -1851,63 +1842,48 @@ static void cm4000_config(dev_link_t * link, int devno)
1851 dev->node.major = major; 1842 dev->node.major = major;
1852 dev->node.minor = devno; 1843 dev->node.minor = devno;
1853 dev->node.next = NULL; 1844 dev->node.next = NULL;
1854 link->dev = &dev->node; 1845 link->dev_node = &dev->node;
1855 link->state &= ~DEV_CONFIG_PENDING;
1856 1846
1857 return; 1847 return 0;
1858 1848
1859cs_failed: 1849cs_failed:
1860 cs_error(handle, fail_fn, fail_rc); 1850 cs_error(link, fail_fn, fail_rc);
1861cs_release: 1851cs_release:
1862 cm4000_release(link); 1852 cm4000_release(link);
1863 1853 return -ENODEV;
1864 link->state &= ~DEV_CONFIG_PENDING;
1865} 1854}
1866 1855
1867static int cm4000_suspend(struct pcmcia_device *p_dev) 1856static int cm4000_suspend(struct pcmcia_device *link)
1868{ 1857{
1869 dev_link_t *link = dev_to_instance(p_dev);
1870 struct cm4000_dev *dev; 1858 struct cm4000_dev *dev;
1871 1859
1872 dev = link->priv; 1860 dev = link->priv;
1873
1874 link->state |= DEV_SUSPEND;
1875 if (link->state & DEV_CONFIG)
1876 pcmcia_release_configuration(link->handle);
1877 stop_monitor(dev); 1861 stop_monitor(dev);
1878 1862
1879 return 0; 1863 return 0;
1880} 1864}
1881 1865
1882static int cm4000_resume(struct pcmcia_device *p_dev) 1866static int cm4000_resume(struct pcmcia_device *link)
1883{ 1867{
1884 dev_link_t *link = dev_to_instance(p_dev);
1885 struct cm4000_dev *dev; 1868 struct cm4000_dev *dev;
1886 1869
1887 dev = link->priv; 1870 dev = link->priv;
1888
1889 link->state &= ~DEV_SUSPEND;
1890 if (link->state & DEV_CONFIG)
1891 pcmcia_request_configuration(link->handle, &link->conf);
1892
1893 if (link->open) 1871 if (link->open)
1894 start_monitor(dev); 1872 start_monitor(dev);
1895 1873
1896 return 0; 1874 return 0;
1897} 1875}
1898 1876
1899static void cm4000_release(dev_link_t *link) 1877static void cm4000_release(struct pcmcia_device *link)
1900{ 1878{
1901 cmm_cm4000_release(link->priv); /* delay release until device closed */ 1879 cmm_cm4000_release(link->priv); /* delay release until device closed */
1902 pcmcia_release_configuration(link->handle); 1880 pcmcia_disable_device(link);
1903 pcmcia_release_io(link->handle, &link->io);
1904} 1881}
1905 1882
1906static int cm4000_attach(struct pcmcia_device *p_dev) 1883static int cm4000_probe(struct pcmcia_device *link)
1907{ 1884{
1908 struct cm4000_dev *dev; 1885 struct cm4000_dev *dev;
1909 dev_link_t *link; 1886 int i, ret;
1910 int i;
1911 1887
1912 for (i = 0; i < CM4000_MAX_DEV; i++) 1888 for (i = 0; i < CM4000_MAX_DEV; i++)
1913 if (dev_table[i] == NULL) 1889 if (dev_table[i] == NULL)
@@ -1923,7 +1899,7 @@ static int cm4000_attach(struct pcmcia_device *p_dev)
1923 if (dev == NULL) 1899 if (dev == NULL)
1924 return -ENOMEM; 1900 return -ENOMEM;
1925 1901
1926 link = &dev->link; 1902 dev->p_dev = link;
1927 link->priv = dev; 1903 link->priv = dev;
1928 link->conf.IntType = INT_MEMORY_AND_IO; 1904 link->conf.IntType = INT_MEMORY_AND_IO;
1929 dev_table[i] = link; 1905 dev_table[i] = link;
@@ -1933,11 +1909,9 @@ static int cm4000_attach(struct pcmcia_device *p_dev)
1933 init_waitqueue_head(&dev->atrq); 1909 init_waitqueue_head(&dev->atrq);
1934 init_waitqueue_head(&dev->readq); 1910 init_waitqueue_head(&dev->readq);
1935 1911
1936 link->handle = p_dev; 1912 ret = cm4000_config(link, i);
1937 p_dev->instance = link; 1913 if (ret)
1938 1914 return ret;
1939 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1940 cm4000_config(link, i);
1941 1915
1942 class_device_create(cmm_class, NULL, MKDEV(major, i), NULL, 1916 class_device_create(cmm_class, NULL, MKDEV(major, i), NULL,
1943 "cmm%d", i); 1917 "cmm%d", i);
@@ -1945,9 +1919,8 @@ static int cm4000_attach(struct pcmcia_device *p_dev)
1945 return 0; 1919 return 0;
1946} 1920}
1947 1921
1948static void cm4000_detach(struct pcmcia_device *p_dev) 1922static void cm4000_detach(struct pcmcia_device *link)
1949{ 1923{
1950 dev_link_t *link = dev_to_instance(p_dev);
1951 struct cm4000_dev *dev = link->priv; 1924 struct cm4000_dev *dev = link->priv;
1952 int devno; 1925 int devno;
1953 1926
@@ -1958,11 +1931,9 @@ static void cm4000_detach(struct pcmcia_device *p_dev)
1958 if (devno == CM4000_MAX_DEV) 1931 if (devno == CM4000_MAX_DEV)
1959 return; 1932 return;
1960 1933
1961 link->state &= ~DEV_PRESENT;
1962 stop_monitor(dev); 1934 stop_monitor(dev);
1963 1935
1964 if (link->state & DEV_CONFIG) 1936 cm4000_release(link);
1965 cm4000_release(link);
1966 1937
1967 dev_table[devno] = NULL; 1938 dev_table[devno] = NULL;
1968 kfree(dev); 1939 kfree(dev);
@@ -1993,7 +1964,7 @@ static struct pcmcia_driver cm4000_driver = {
1993 .drv = { 1964 .drv = {
1994 .name = "cm4000_cs", 1965 .name = "cm4000_cs",
1995 }, 1966 },
1996 .probe = cm4000_attach, 1967 .probe = cm4000_probe,
1997 .remove = cm4000_detach, 1968 .remove = cm4000_detach,
1998 .suspend = cm4000_suspend, 1969 .suspend = cm4000_suspend,
1999 .resume = cm4000_resume, 1970 .resume = cm4000_resume,
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 466e33bab029..29efa64580a8 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -41,7 +41,7 @@
41 41
42 42
43#ifdef PCMCIA_DEBUG 43#ifdef PCMCIA_DEBUG
44#define reader_to_dev(x) (&handle_to_dev(x->link.handle)) 44#define reader_to_dev(x) (&handle_to_dev(x->p_dev->handle))
45static int pc_debug = PCMCIA_DEBUG; 45static int pc_debug = PCMCIA_DEBUG;
46module_param(pc_debug, int, 0600); 46module_param(pc_debug, int, 0600);
47#define DEBUGP(n, rdr, x, args...) do { \ 47#define DEBUGP(n, rdr, x, args...) do { \
@@ -65,7 +65,7 @@ static char *version =
65/* how often to poll for fifo status change */ 65/* how often to poll for fifo status change */
66#define POLL_PERIOD msecs_to_jiffies(10) 66#define POLL_PERIOD msecs_to_jiffies(10)
67 67
68static void reader_release(dev_link_t *link); 68static void reader_release(struct pcmcia_device *link);
69 69
70static int major; 70static int major;
71static struct class *cmx_class; 71static struct class *cmx_class;
@@ -74,7 +74,7 @@ static struct class *cmx_class;
74#define BS_WRITABLE 0x02 74#define BS_WRITABLE 0x02
75 75
76struct reader_dev { 76struct reader_dev {
77 dev_link_t link; 77 struct pcmcia_device *p_dev;
78 dev_node_t node; 78 dev_node_t node;
79 wait_queue_head_t devq; 79 wait_queue_head_t devq;
80 wait_queue_head_t poll_wait; 80 wait_queue_head_t poll_wait;
@@ -87,7 +87,7 @@ struct reader_dev {
87 struct timer_list poll_timer; 87 struct timer_list poll_timer;
88}; 88};
89 89
90static dev_link_t *dev_table[CM_MAX_DEV]; 90static struct pcmcia_device *dev_table[CM_MAX_DEV];
91 91
92#ifndef PCMCIA_DEBUG 92#ifndef PCMCIA_DEBUG
93#define xoutb outb 93#define xoutb outb
@@ -116,7 +116,7 @@ static inline unsigned char xinb(unsigned short port)
116static void cm4040_do_poll(unsigned long dummy) 116static void cm4040_do_poll(unsigned long dummy)
117{ 117{
118 struct reader_dev *dev = (struct reader_dev *) dummy; 118 struct reader_dev *dev = (struct reader_dev *) dummy;
119 unsigned int obs = xinb(dev->link.io.BasePort1 119 unsigned int obs = xinb(dev->p_dev->io.BasePort1
120 + REG_OFFSET_BUFFER_STATUS); 120 + REG_OFFSET_BUFFER_STATUS);
121 121
122 if ((obs & BSR_BULK_IN_FULL)) { 122 if ((obs & BSR_BULK_IN_FULL)) {
@@ -147,7 +147,7 @@ static void cm4040_stop_poll(struct reader_dev *dev)
147static int wait_for_bulk_out_ready(struct reader_dev *dev) 147static int wait_for_bulk_out_ready(struct reader_dev *dev)
148{ 148{
149 int i, rc; 149 int i, rc;
150 int iobase = dev->link.io.BasePort1; 150 int iobase = dev->p_dev->io.BasePort1;
151 151
152 for (i = 0; i < POLL_LOOP_COUNT; i++) { 152 for (i = 0; i < POLL_LOOP_COUNT; i++) {
153 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS) 153 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
@@ -177,7 +177,7 @@ static int wait_for_bulk_out_ready(struct reader_dev *dev)
177/* Write to Sync Control Register */ 177/* Write to Sync Control Register */
178static int write_sync_reg(unsigned char val, struct reader_dev *dev) 178static int write_sync_reg(unsigned char val, struct reader_dev *dev)
179{ 179{
180 int iobase = dev->link.io.BasePort1; 180 int iobase = dev->p_dev->io.BasePort1;
181 int rc; 181 int rc;
182 182
183 rc = wait_for_bulk_out_ready(dev); 183 rc = wait_for_bulk_out_ready(dev);
@@ -195,7 +195,7 @@ static int write_sync_reg(unsigned char val, struct reader_dev *dev)
195static int wait_for_bulk_in_ready(struct reader_dev *dev) 195static int wait_for_bulk_in_ready(struct reader_dev *dev)
196{ 196{
197 int i, rc; 197 int i, rc;
198 int iobase = dev->link.io.BasePort1; 198 int iobase = dev->p_dev->io.BasePort1;
199 199
200 for (i = 0; i < POLL_LOOP_COUNT; i++) { 200 for (i = 0; i < POLL_LOOP_COUNT; i++) {
201 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS) 201 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
@@ -225,7 +225,7 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
225 size_t count, loff_t *ppos) 225 size_t count, loff_t *ppos)
226{ 226{
227 struct reader_dev *dev = filp->private_data; 227 struct reader_dev *dev = filp->private_data;
228 int iobase = dev->link.io.BasePort1; 228 int iobase = dev->p_dev->io.BasePort1;
229 size_t bytes_to_read; 229 size_t bytes_to_read;
230 unsigned long i; 230 unsigned long i;
231 size_t min_bytes_to_read; 231 size_t min_bytes_to_read;
@@ -246,7 +246,7 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
246 return -EAGAIN; 246 return -EAGAIN;
247 } 247 }
248 248
249 if ((dev->link.state & DEV_PRESENT)==0) 249 if (!pcmcia_dev_present(dev->p_dev))
250 return -ENODEV; 250 return -ENODEV;
251 251
252 for (i = 0; i < 5; i++) { 252 for (i = 0; i < 5; i++) {
@@ -328,7 +328,7 @@ static ssize_t cm4040_write(struct file *filp, const char __user *buf,
328 size_t count, loff_t *ppos) 328 size_t count, loff_t *ppos)
329{ 329{
330 struct reader_dev *dev = filp->private_data; 330 struct reader_dev *dev = filp->private_data;
331 int iobase = dev->link.io.BasePort1; 331 int iobase = dev->p_dev->io.BasePort1;
332 ssize_t rc; 332 ssize_t rc;
333 int i; 333 int i;
334 unsigned int bytes_to_write; 334 unsigned int bytes_to_write;
@@ -351,7 +351,7 @@ static ssize_t cm4040_write(struct file *filp, const char __user *buf,
351 return -EAGAIN; 351 return -EAGAIN;
352 } 352 }
353 353
354 if ((dev->link.state & DEV_PRESENT) == 0) 354 if (!pcmcia_dev_present(dev->p_dev))
355 return -ENODEV; 355 return -ENODEV;
356 356
357 bytes_to_write = count; 357 bytes_to_write = count;
@@ -445,14 +445,14 @@ static unsigned int cm4040_poll(struct file *filp, poll_table *wait)
445static int cm4040_open(struct inode *inode, struct file *filp) 445static int cm4040_open(struct inode *inode, struct file *filp)
446{ 446{
447 struct reader_dev *dev; 447 struct reader_dev *dev;
448 dev_link_t *link; 448 struct pcmcia_device *link;
449 int minor = iminor(inode); 449 int minor = iminor(inode);
450 450
451 if (minor >= CM_MAX_DEV) 451 if (minor >= CM_MAX_DEV)
452 return -ENODEV; 452 return -ENODEV;
453 453
454 link = dev_table[minor]; 454 link = dev_table[minor];
455 if (link == NULL || !(DEV_OK(link))) 455 if (link == NULL || !pcmcia_dev_present(link))
456 return -ENODEV; 456 return -ENODEV;
457 457
458 if (link->open) 458 if (link->open)
@@ -478,7 +478,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)
478static int cm4040_close(struct inode *inode, struct file *filp) 478static int cm4040_close(struct inode *inode, struct file *filp)
479{ 479{
480 struct reader_dev *dev = filp->private_data; 480 struct reader_dev *dev = filp->private_data;
481 dev_link_t *link; 481 struct pcmcia_device *link;
482 int minor = iminor(inode); 482 int minor = iminor(inode);
483 483
484 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode), 484 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode),
@@ -500,7 +500,7 @@ static int cm4040_close(struct inode *inode, struct file *filp)
500 return 0; 500 return 0;
501} 501}
502 502
503static void cm4040_reader_release(dev_link_t *link) 503static void cm4040_reader_release(struct pcmcia_device *link)
504{ 504{
505 struct reader_dev *dev = link->priv; 505 struct reader_dev *dev = link->priv;
506 506
@@ -514,60 +514,49 @@ static void cm4040_reader_release(dev_link_t *link)
514 return; 514 return;
515} 515}
516 516
517static void reader_config(dev_link_t *link, int devno) 517static int reader_config(struct pcmcia_device *link, int devno)
518{ 518{
519 client_handle_t handle;
520 struct reader_dev *dev; 519 struct reader_dev *dev;
521 tuple_t tuple; 520 tuple_t tuple;
522 cisparse_t parse; 521 cisparse_t parse;
523 config_info_t conf;
524 u_char buf[64]; 522 u_char buf[64];
525 int fail_fn, fail_rc; 523 int fail_fn, fail_rc;
526 int rc; 524 int rc;
527 525
528 handle = link->handle;
529
530 tuple.DesiredTuple = CISTPL_CONFIG; 526 tuple.DesiredTuple = CISTPL_CONFIG;
531 tuple.Attributes = 0; 527 tuple.Attributes = 0;
532 tuple.TupleData = buf; 528 tuple.TupleData = buf;
533 tuple.TupleDataMax = sizeof(buf); 529 tuple.TupleDataMax = sizeof(buf);
534 tuple.TupleOffset = 0; 530 tuple.TupleOffset = 0;
535 531
536 if ((fail_rc = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) { 532 if ((fail_rc = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) {
537 fail_fn = GetFirstTuple; 533 fail_fn = GetFirstTuple;
538 goto cs_failed; 534 goto cs_failed;
539 } 535 }
540 if ((fail_rc = pcmcia_get_tuple_data(handle, &tuple)) != CS_SUCCESS) { 536 if ((fail_rc = pcmcia_get_tuple_data(link, &tuple)) != CS_SUCCESS) {
541 fail_fn = GetTupleData; 537 fail_fn = GetTupleData;
542 goto cs_failed; 538 goto cs_failed;
543 } 539 }
544 if ((fail_rc = pcmcia_parse_tuple(handle, &tuple, &parse)) 540 if ((fail_rc = pcmcia_parse_tuple(link, &tuple, &parse))
545 != CS_SUCCESS) { 541 != CS_SUCCESS) {
546 fail_fn = ParseTuple; 542 fail_fn = ParseTuple;
547 goto cs_failed; 543 goto cs_failed;
548 } 544 }
549 if ((fail_rc = pcmcia_get_configuration_info(handle, &conf))
550 != CS_SUCCESS) {
551 fail_fn = GetConfigurationInfo;
552 goto cs_failed;
553 }
554 545
555 link->state |= DEV_CONFIG;
556 link->conf.ConfigBase = parse.config.base; 546 link->conf.ConfigBase = parse.config.base;
557 link->conf.Present = parse.config.rmask[0]; 547 link->conf.Present = parse.config.rmask[0];
558 link->conf.Vcc = conf.Vcc;
559 548
560 link->io.BasePort2 = 0; 549 link->io.BasePort2 = 0;
561 link->io.NumPorts2 = 0; 550 link->io.NumPorts2 = 0;
562 link->io.Attributes2 = 0; 551 link->io.Attributes2 = 0;
563 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 552 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
564 for (rc = pcmcia_get_first_tuple(handle, &tuple); 553 for (rc = pcmcia_get_first_tuple(link, &tuple);
565 rc == CS_SUCCESS; 554 rc == CS_SUCCESS;
566 rc = pcmcia_get_next_tuple(handle, &tuple)) { 555 rc = pcmcia_get_next_tuple(link, &tuple)) {
567 rc = pcmcia_get_tuple_data(handle, &tuple); 556 rc = pcmcia_get_tuple_data(link, &tuple);
568 if (rc != CS_SUCCESS) 557 if (rc != CS_SUCCESS)
569 continue; 558 continue;
570 rc = pcmcia_parse_tuple(handle, &tuple, &parse); 559 rc = pcmcia_parse_tuple(link, &tuple, &parse);
571 if (rc != CS_SUCCESS) 560 if (rc != CS_SUCCESS)
572 continue; 561 continue;
573 562
@@ -585,13 +574,13 @@ static void reader_config(dev_link_t *link, int devno)
585 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 574 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
586 link->io.IOAddrLines = parse.cftable_entry.io.flags 575 link->io.IOAddrLines = parse.cftable_entry.io.flags
587 & CISTPL_IO_LINES_MASK; 576 & CISTPL_IO_LINES_MASK;
588 rc = pcmcia_request_io(handle, &link->io); 577 rc = pcmcia_request_io(link, &link->io);
589 578
590 dev_printk(KERN_INFO, &handle_to_dev(handle), "foo"); 579 dev_printk(KERN_INFO, &handle_to_dev(link), "foo");
591 if (rc == CS_SUCCESS) 580 if (rc == CS_SUCCESS)
592 break; 581 break;
593 else 582 else
594 dev_printk(KERN_INFO, &handle_to_dev(handle), 583 dev_printk(KERN_INFO, &handle_to_dev(link),
595 "pcmcia_request_io failed 0x%x\n", rc); 584 "pcmcia_request_io failed 0x%x\n", rc);
596 } 585 }
597 if (rc != CS_SUCCESS) 586 if (rc != CS_SUCCESS)
@@ -599,10 +588,10 @@ static void reader_config(dev_link_t *link, int devno)
599 588
600 link->conf.IntType = 00000002; 589 link->conf.IntType = 00000002;
601 590
602 if ((fail_rc = pcmcia_request_configuration(handle,&link->conf)) 591 if ((fail_rc = pcmcia_request_configuration(link,&link->conf))
603 !=CS_SUCCESS) { 592 !=CS_SUCCESS) {
604 fail_fn = RequestConfiguration; 593 fail_fn = RequestConfiguration;
605 dev_printk(KERN_INFO, &handle_to_dev(handle), 594 dev_printk(KERN_INFO, &handle_to_dev(link),
606 "pcmcia_request_configuration failed 0x%x\n", 595 "pcmcia_request_configuration failed 0x%x\n",
607 fail_rc); 596 fail_rc);
608 goto cs_release; 597 goto cs_release;
@@ -612,57 +601,31 @@ static void reader_config(dev_link_t *link, int devno)
612 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno); 601 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
613 dev->node.major = major; 602 dev->node.major = major;
614 dev->node.minor = devno; 603 dev->node.minor = devno;
615 dev->node.next = NULL; 604 dev->node.next = &dev->node;
616 link->dev = &dev->node;
617 link->state &= ~DEV_CONFIG_PENDING;
618 605
619 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno, 606 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno,
620 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1); 607 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1);
621 DEBUGP(2, dev, "<- reader_config (succ)\n"); 608 DEBUGP(2, dev, "<- reader_config (succ)\n");
622 609
623 return; 610 return 0;
624 611
625cs_failed: 612cs_failed:
626 cs_error(handle, fail_fn, fail_rc); 613 cs_error(link, fail_fn, fail_rc);
627cs_release: 614cs_release:
628 reader_release(link); 615 reader_release(link);
629 link->state &= ~DEV_CONFIG_PENDING; 616 return -ENODEV;
630}
631
632static int reader_suspend(struct pcmcia_device *p_dev)
633{
634 dev_link_t *link = dev_to_instance(p_dev);
635
636 link->state |= DEV_SUSPEND;
637 if (link->state & DEV_CONFIG)
638 pcmcia_release_configuration(link->handle);
639
640 return 0;
641} 617}
642 618
643static int reader_resume(struct pcmcia_device *p_dev) 619static void reader_release(struct pcmcia_device *link)
644{
645 dev_link_t *link = dev_to_instance(p_dev);
646
647 link->state &= ~DEV_SUSPEND;
648 if (link->state & DEV_CONFIG)
649 pcmcia_request_configuration(link->handle, &link->conf);
650
651 return 0;
652}
653
654static void reader_release(dev_link_t *link)
655{ 620{
656 cm4040_reader_release(link->priv); 621 cm4040_reader_release(link->priv);
657 pcmcia_release_configuration(link->handle); 622 pcmcia_disable_device(link);
658 pcmcia_release_io(link->handle, &link->io);
659} 623}
660 624
661static int reader_attach(struct pcmcia_device *p_dev) 625static int reader_probe(struct pcmcia_device *link)
662{ 626{
663 struct reader_dev *dev; 627 struct reader_dev *dev;
664 dev_link_t *link; 628 int i, ret;
665 int i;
666 629
667 for (i = 0; i < CM_MAX_DEV; i++) { 630 for (i = 0; i < CM_MAX_DEV; i++) {
668 if (dev_table[i] == NULL) 631 if (dev_table[i] == NULL)
@@ -679,8 +642,8 @@ static int reader_attach(struct pcmcia_device *p_dev)
679 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT; 642 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
680 dev->buffer_status = 0; 643 dev->buffer_status = 0;
681 644
682 link = &dev->link;
683 link->priv = dev; 645 link->priv = dev;
646 dev->p_dev = link;
684 647
685 link->conf.IntType = INT_MEMORY_AND_IO; 648 link->conf.IntType = INT_MEMORY_AND_IO;
686 dev_table[i] = link; 649 dev_table[i] = link;
@@ -692,11 +655,9 @@ static int reader_attach(struct pcmcia_device *p_dev)
692 init_timer(&dev->poll_timer); 655 init_timer(&dev->poll_timer);
693 dev->poll_timer.function = &cm4040_do_poll; 656 dev->poll_timer.function = &cm4040_do_poll;
694 657
695 link->handle = p_dev; 658 ret = reader_config(link, i);
696 p_dev->instance = link; 659 if (ret)
697 660 return ret;
698 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
699 reader_config(link, i);
700 661
701 class_device_create(cmx_class, NULL, MKDEV(major, i), NULL, 662 class_device_create(cmx_class, NULL, MKDEV(major, i), NULL,
702 "cmx%d", i); 663 "cmx%d", i);
@@ -704,9 +665,8 @@ static int reader_attach(struct pcmcia_device *p_dev)
704 return 0; 665 return 0;
705} 666}
706 667
707static void reader_detach(struct pcmcia_device *p_dev) 668static void reader_detach(struct pcmcia_device *link)
708{ 669{
709 dev_link_t *link = dev_to_instance(p_dev);
710 struct reader_dev *dev = link->priv; 670 struct reader_dev *dev = link->priv;
711 int devno; 671 int devno;
712 672
@@ -718,10 +678,7 @@ static void reader_detach(struct pcmcia_device *p_dev)
718 if (devno == CM_MAX_DEV) 678 if (devno == CM_MAX_DEV)
719 return; 679 return;
720 680
721 link->state &= ~DEV_PRESENT; 681 reader_release(link);
722
723 if (link->state & DEV_CONFIG)
724 reader_release(link);
725 682
726 dev_table[devno] = NULL; 683 dev_table[devno] = NULL;
727 kfree(dev); 684 kfree(dev);
@@ -753,10 +710,8 @@ static struct pcmcia_driver reader_driver = {
753 .drv = { 710 .drv = {
754 .name = "cm4040_cs", 711 .name = "cm4040_cs",
755 }, 712 },
756 .probe = reader_attach, 713 .probe = reader_probe,
757 .remove = reader_detach, 714 .remove = reader_detach,
758 .suspend = reader_suspend,
759 .resume = reader_resume,
760 .id_table = cm4040_ids, 715 .id_table = cm4040_ids,
761}; 716};
762 717
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index e6b714b6390d..07213454c458 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -228,7 +228,7 @@ typedef struct _mgslpc_info {
228 struct _input_signal_events input_signal_events; 228 struct _input_signal_events input_signal_events;
229 229
230 /* PCMCIA support */ 230 /* PCMCIA support */
231 dev_link_t link; 231 struct pcmcia_device *p_dev;
232 dev_node_t node; 232 dev_node_t node;
233 int stop; 233 int stop;
234 234
@@ -484,7 +484,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout);
484 484
485/* PCMCIA prototypes */ 485/* PCMCIA prototypes */
486 486
487static void mgslpc_config(dev_link_t *link); 487static int mgslpc_config(struct pcmcia_device *link);
488static void mgslpc_release(u_long arg); 488static void mgslpc_release(u_long arg);
489static void mgslpc_detach(struct pcmcia_device *p_dev); 489static void mgslpc_detach(struct pcmcia_device *p_dev);
490 490
@@ -533,14 +533,14 @@ static void ldisc_receive_buf(struct tty_struct *tty,
533 } 533 }
534} 534}
535 535
536static int mgslpc_attach(struct pcmcia_device *p_dev) 536static int mgslpc_probe(struct pcmcia_device *link)
537{ 537{
538 MGSLPC_INFO *info; 538 MGSLPC_INFO *info;
539 dev_link_t *link; 539 int ret;
540 540
541 if (debug_level >= DEBUG_LEVEL_INFO) 541 if (debug_level >= DEBUG_LEVEL_INFO)
542 printk("mgslpc_attach\n"); 542 printk("mgslpc_attach\n");
543 543
544 info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); 544 info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
545 if (!info) { 545 if (!info) {
546 printk("Error can't allocate device instance data\n"); 546 printk("Error can't allocate device instance data\n");
@@ -565,25 +565,22 @@ static int mgslpc_attach(struct pcmcia_device *p_dev)
565 info->imrb_value = 0xffff; 565 info->imrb_value = 0xffff;
566 info->pim_value = 0xff; 566 info->pim_value = 0xff;
567 567
568 link = &info->link; 568 info->p_dev = link;
569 link->priv = info; 569 link->priv = info;
570 570
571 /* Initialize the dev_link_t structure */ 571 /* Initialize the struct pcmcia_device structure */
572 572
573 /* Interrupt setup */ 573 /* Interrupt setup */
574 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 574 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
575 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 575 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
576 link->irq.Handler = NULL; 576 link->irq.Handler = NULL;
577 577
578 link->conf.Attributes = 0; 578 link->conf.Attributes = 0;
579 link->conf.Vcc = 50;
580 link->conf.IntType = INT_MEMORY_AND_IO; 579 link->conf.IntType = INT_MEMORY_AND_IO;
581 580
582 link->handle = p_dev; 581 ret = mgslpc_config(link);
583 p_dev->instance = link; 582 if (ret)
584 583 return ret;
585 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
586 mgslpc_config(link);
587 584
588 mgslpc_add_device(info); 585 mgslpc_add_device(info);
589 586
@@ -596,15 +593,13 @@ static int mgslpc_attach(struct pcmcia_device *p_dev)
596#define CS_CHECK(fn, ret) \ 593#define CS_CHECK(fn, ret) \
597do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 594do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
598 595
599static void mgslpc_config(dev_link_t *link) 596static int mgslpc_config(struct pcmcia_device *link)
600{ 597{
601 client_handle_t handle = link->handle;
602 MGSLPC_INFO *info = link->priv; 598 MGSLPC_INFO *info = link->priv;
603 tuple_t tuple; 599 tuple_t tuple;
604 cisparse_t parse; 600 cisparse_t parse;
605 int last_fn, last_ret; 601 int last_fn, last_ret;
606 u_char buf[64]; 602 u_char buf[64];
607 config_info_t conf;
608 cistpl_cftable_entry_t dflt = { 0 }; 603 cistpl_cftable_entry_t dflt = { 0 };
609 cistpl_cftable_entry_t *cfg; 604 cistpl_cftable_entry_t *cfg;
610 605
@@ -617,27 +612,20 @@ static void mgslpc_config(dev_link_t *link)
617 tuple.TupleData = buf; 612 tuple.TupleData = buf;
618 tuple.TupleDataMax = sizeof(buf); 613 tuple.TupleDataMax = sizeof(buf);
619 tuple.TupleOffset = 0; 614 tuple.TupleOffset = 0;
620 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 615 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
621 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 616 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
622 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 617 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
623 link->conf.ConfigBase = parse.config.base; 618 link->conf.ConfigBase = parse.config.base;
624 link->conf.Present = parse.config.rmask[0]; 619 link->conf.Present = parse.config.rmask[0];
625
626 /* Configure card */
627 link->state |= DEV_CONFIG;
628
629 /* Look up the current Vcc */
630 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
631 link->conf.Vcc = conf.Vcc;
632 620
633 /* get CIS configuration entry */ 621 /* get CIS configuration entry */
634 622
635 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 623 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
636 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 624 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
637 625
638 cfg = &(parse.cftable_entry); 626 cfg = &(parse.cftable_entry);
639 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 627 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
640 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 628 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
641 629
642 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 630 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
643 if (cfg->index == 0) 631 if (cfg->index == 0)
@@ -658,11 +646,10 @@ static void mgslpc_config(dev_link_t *link)
658 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; 646 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
659 link->io.BasePort1 = io->win[0].base; 647 link->io.BasePort1 = io->win[0].base;
660 link->io.NumPorts1 = io->win[0].len; 648 link->io.NumPorts1 = io->win[0].len;
661 CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io)); 649 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
662 } 650 }
663 651
664 link->conf.Attributes = CONF_ENABLE_IRQ; 652 link->conf.Attributes = CONF_ENABLE_IRQ;
665 link->conf.Vcc = 50;
666 link->conf.IntType = INT_MEMORY_AND_IO; 653 link->conf.IntType = INT_MEMORY_AND_IO;
667 link->conf.ConfigIndex = 8; 654 link->conf.ConfigIndex = 8;
668 link->conf.Present = PRESENT_OPTION; 655 link->conf.Present = PRESENT_OPTION;
@@ -670,9 +657,9 @@ static void mgslpc_config(dev_link_t *link)
670 link->irq.Attributes |= IRQ_HANDLE_PRESENT; 657 link->irq.Attributes |= IRQ_HANDLE_PRESENT;
671 link->irq.Handler = mgslpc_isr; 658 link->irq.Handler = mgslpc_isr;
672 link->irq.Instance = info; 659 link->irq.Instance = info;
673 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 660 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
674 661
675 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 662 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
676 663
677 info->io_base = link->io.BasePort1; 664 info->io_base = link->io.BasePort1;
678 info->irq_level = link->irq.AssignedIRQ; 665 info->irq_level = link->irq.AssignedIRQ;
@@ -680,7 +667,7 @@ static void mgslpc_config(dev_link_t *link)
680 /* add to linked list of devices */ 667 /* add to linked list of devices */
681 sprintf(info->node.dev_name, "mgslpc0"); 668 sprintf(info->node.dev_name, "mgslpc0");
682 info->node.major = info->node.minor = 0; 669 info->node.major = info->node.minor = 0;
683 link->dev = &info->node; 670 link->dev_node = &info->node;
684 671
685 printk(KERN_INFO "%s: index 0x%02x:", 672 printk(KERN_INFO "%s: index 0x%02x:",
686 info->node.dev_name, link->conf.ConfigIndex); 673 info->node.dev_name, link->conf.ConfigIndex);
@@ -690,13 +677,12 @@ static void mgslpc_config(dev_link_t *link)
690 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 677 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
691 link->io.BasePort1+link->io.NumPorts1-1); 678 link->io.BasePort1+link->io.NumPorts1-1);
692 printk("\n"); 679 printk("\n");
693 680 return 0;
694 link->state &= ~DEV_CONFIG_PENDING;
695 return;
696 681
697cs_failed: 682cs_failed:
698 cs_error(link->handle, last_fn, last_ret); 683 cs_error(link, last_fn, last_ret);
699 mgslpc_release((u_long)link); 684 mgslpc_release((u_long)link);
685 return -ENODEV;
700} 686}
701 687
702/* Card has been removed. 688/* Card has been removed.
@@ -705,58 +691,38 @@ cs_failed:
705 */ 691 */
706static void mgslpc_release(u_long arg) 692static void mgslpc_release(u_long arg)
707{ 693{
708 dev_link_t *link = (dev_link_t *)arg; 694 struct pcmcia_device *link = (struct pcmcia_device *)arg;
709 695
710 if (debug_level >= DEBUG_LEVEL_INFO) 696 if (debug_level >= DEBUG_LEVEL_INFO)
711 printk("mgslpc_release(0x%p)\n", link); 697 printk("mgslpc_release(0x%p)\n", link);
712
713 /* Unlink the device chain */
714 link->dev = NULL;
715 link->state &= ~DEV_CONFIG;
716 698
717 pcmcia_release_configuration(link->handle); 699 pcmcia_disable_device(link);
718 if (link->io.NumPorts1)
719 pcmcia_release_io(link->handle, &link->io);
720 if (link->irq.AssignedIRQ)
721 pcmcia_release_irq(link->handle, &link->irq);
722} 700}
723 701
724static void mgslpc_detach(struct pcmcia_device *p_dev) 702static void mgslpc_detach(struct pcmcia_device *link)
725{ 703{
726 dev_link_t *link = dev_to_instance(p_dev); 704 if (debug_level >= DEBUG_LEVEL_INFO)
727 705 printk("mgslpc_detach(0x%p)\n", link);
728 if (debug_level >= DEBUG_LEVEL_INFO)
729 printk("mgslpc_detach(0x%p)\n", link);
730 706
731 if (link->state & DEV_CONFIG) { 707 ((MGSLPC_INFO *)link->priv)->stop = 1;
732 ((MGSLPC_INFO *)link->priv)->stop = 1; 708 mgslpc_release((u_long)link);
733 mgslpc_release((u_long)link);
734 }
735 709
736 mgslpc_remove_device((MGSLPC_INFO *)link->priv); 710 mgslpc_remove_device((MGSLPC_INFO *)link->priv);
737} 711}
738 712
739static int mgslpc_suspend(struct pcmcia_device *dev) 713static int mgslpc_suspend(struct pcmcia_device *link)
740{ 714{
741 dev_link_t *link = dev_to_instance(dev);
742 MGSLPC_INFO *info = link->priv; 715 MGSLPC_INFO *info = link->priv;
743 716
744 link->state |= DEV_SUSPEND;
745 info->stop = 1; 717 info->stop = 1;
746 if (link->state & DEV_CONFIG)
747 pcmcia_release_configuration(link->handle);
748 718
749 return 0; 719 return 0;
750} 720}
751 721
752static int mgslpc_resume(struct pcmcia_device *dev) 722static int mgslpc_resume(struct pcmcia_device *link)
753{ 723{
754 dev_link_t *link = dev_to_instance(dev);
755 MGSLPC_INFO *info = link->priv; 724 MGSLPC_INFO *info = link->priv;
756 725
757 link->state &= ~DEV_SUSPEND;
758 if (link->state & DEV_CONFIG)
759 pcmcia_request_configuration(link->handle, &link->conf);
760 info->stop = 0; 726 info->stop = 0;
761 727
762 return 0; 728 return 0;
@@ -1280,7 +1246,7 @@ static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs)
1280 if (!info) 1246 if (!info)
1281 return IRQ_NONE; 1247 return IRQ_NONE;
1282 1248
1283 if (!(info->link.state & DEV_CONFIG)) 1249 if (!(info->p_dev->_locked))
1284 return IRQ_HANDLED; 1250 return IRQ_HANDLED;
1285 1251
1286 spin_lock(&info->lock); 1252 spin_lock(&info->lock);
@@ -3033,7 +2999,7 @@ static struct pcmcia_driver mgslpc_driver = {
3033 .drv = { 2999 .drv = {
3034 .name = "synclink_cs", 3000 .name = "synclink_cs",
3035 }, 3001 },
3036 .probe = mgslpc_attach, 3002 .probe = mgslpc_probe,
3037 .remove = mgslpc_detach, 3003 .remove = mgslpc_detach,
3038 .id_table = mgslpc_ids, 3004 .id_table = mgslpc_ids,
3039 .suspend = mgslpc_suspend, 3005 .suspend = mgslpc_suspend,
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index 6213bd3caee5..4961f1e764a7 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -81,14 +81,14 @@ static const char ide_major[] = {
81}; 81};
82 82
83typedef struct ide_info_t { 83typedef struct ide_info_t {
84 dev_link_t link; 84 struct pcmcia_device *p_dev;
85 int ndev; 85 int ndev;
86 dev_node_t node; 86 dev_node_t node;
87 int hd; 87 int hd;
88} ide_info_t; 88} ide_info_t;
89 89
90static void ide_release(dev_link_t *); 90static void ide_release(struct pcmcia_device *);
91static void ide_config(dev_link_t *); 91static int ide_config(struct pcmcia_device *);
92 92
93static void ide_detach(struct pcmcia_device *p_dev); 93static void ide_detach(struct pcmcia_device *p_dev);
94 94
@@ -103,10 +103,9 @@ static void ide_detach(struct pcmcia_device *p_dev);
103 103
104======================================================================*/ 104======================================================================*/
105 105
106static int ide_attach(struct pcmcia_device *p_dev) 106static int ide_probe(struct pcmcia_device *link)
107{ 107{
108 ide_info_t *info; 108 ide_info_t *info;
109 dev_link_t *link;
110 109
111 DEBUG(0, "ide_attach()\n"); 110 DEBUG(0, "ide_attach()\n");
112 111
@@ -114,7 +113,9 @@ static int ide_attach(struct pcmcia_device *p_dev)
114 info = kzalloc(sizeof(*info), GFP_KERNEL); 113 info = kzalloc(sizeof(*info), GFP_KERNEL);
115 if (!info) 114 if (!info)
116 return -ENOMEM; 115 return -ENOMEM;
117 link = &info->link; link->priv = info; 116
117 info->p_dev = link;
118 link->priv = info;
118 119
119 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 120 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
120 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 121 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
@@ -122,16 +123,9 @@ static int ide_attach(struct pcmcia_device *p_dev)
122 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 123 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
123 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 124 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
124 link->conf.Attributes = CONF_ENABLE_IRQ; 125 link->conf.Attributes = CONF_ENABLE_IRQ;
125 link->conf.Vcc = 50;
126 link->conf.IntType = INT_MEMORY_AND_IO; 126 link->conf.IntType = INT_MEMORY_AND_IO;
127 127
128 link->handle = p_dev; 128 return ide_config(link);
129 p_dev->instance = link;
130
131 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
132 ide_config(link);
133
134 return 0;
135} /* ide_attach */ 129} /* ide_attach */
136 130
137/*====================================================================== 131/*======================================================================
@@ -143,14 +137,11 @@ static int ide_attach(struct pcmcia_device *p_dev)
143 137
144======================================================================*/ 138======================================================================*/
145 139
146static void ide_detach(struct pcmcia_device *p_dev) 140static void ide_detach(struct pcmcia_device *link)
147{ 141{
148 dev_link_t *link = dev_to_instance(p_dev);
149
150 DEBUG(0, "ide_detach(0x%p)\n", link); 142 DEBUG(0, "ide_detach(0x%p)\n", link);
151 143
152 if (link->state & DEV_CONFIG) 144 ide_release(link);
153 ide_release(link);
154 145
155 kfree(link->priv); 146 kfree(link->priv);
156} /* ide_detach */ 147} /* ide_detach */
@@ -177,9 +168,8 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
177#define CS_CHECK(fn, ret) \ 168#define CS_CHECK(fn, ret) \
178do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 169do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
179 170
180static void ide_config(dev_link_t *link) 171static int ide_config(struct pcmcia_device *link)
181{ 172{
182 client_handle_t handle = link->handle;
183 ide_info_t *info = link->priv; 173 ide_info_t *info = link->priv;
184 tuple_t tuple; 174 tuple_t tuple;
185 struct { 175 struct {
@@ -203,34 +193,30 @@ static void ide_config(dev_link_t *link)
203 tuple.TupleDataMax = 255; 193 tuple.TupleDataMax = 255;
204 tuple.Attributes = 0; 194 tuple.Attributes = 0;
205 tuple.DesiredTuple = CISTPL_CONFIG; 195 tuple.DesiredTuple = CISTPL_CONFIG;
206 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 196 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
207 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 197 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
208 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &stk->parse)); 198 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &stk->parse));
209 link->conf.ConfigBase = stk->parse.config.base; 199 link->conf.ConfigBase = stk->parse.config.base;
210 link->conf.Present = stk->parse.config.rmask[0]; 200 link->conf.Present = stk->parse.config.rmask[0];
211 201
212 tuple.DesiredTuple = CISTPL_MANFID; 202 tuple.DesiredTuple = CISTPL_MANFID;
213 if (!pcmcia_get_first_tuple(handle, &tuple) && 203 if (!pcmcia_get_first_tuple(link, &tuple) &&
214 !pcmcia_get_tuple_data(handle, &tuple) && 204 !pcmcia_get_tuple_data(link, &tuple) &&
215 !pcmcia_parse_tuple(handle, &tuple, &stk->parse)) 205 !pcmcia_parse_tuple(link, &tuple, &stk->parse))
216 is_kme = ((stk->parse.manfid.manf == MANFID_KME) && 206 is_kme = ((stk->parse.manfid.manf == MANFID_KME) &&
217 ((stk->parse.manfid.card == PRODID_KME_KXLC005_A) || 207 ((stk->parse.manfid.card == PRODID_KME_KXLC005_A) ||
218 (stk->parse.manfid.card == PRODID_KME_KXLC005_B))); 208 (stk->parse.manfid.card == PRODID_KME_KXLC005_B)));
219 209
220 /* Configure card */
221 link->state |= DEV_CONFIG;
222
223 /* Not sure if this is right... look up the current Vcc */ 210 /* Not sure if this is right... look up the current Vcc */
224 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &stk->conf)); 211 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf));
225 link->conf.Vcc = stk->conf.Vcc;
226 212
227 pass = io_base = ctl_base = 0; 213 pass = io_base = ctl_base = 0;
228 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 214 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
229 tuple.Attributes = 0; 215 tuple.Attributes = 0;
230 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 216 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
231 while (1) { 217 while (1) {
232 if (pcmcia_get_tuple_data(handle, &tuple) != 0) goto next_entry; 218 if (pcmcia_get_tuple_data(link, &tuple) != 0) goto next_entry;
233 if (pcmcia_parse_tuple(handle, &tuple, &stk->parse) != 0) goto next_entry; 219 if (pcmcia_parse_tuple(link, &tuple, &stk->parse) != 0) goto next_entry;
234 220
235 /* Check for matching Vcc, unless we're desperate */ 221 /* Check for matching Vcc, unless we're desperate */
236 if (!pass) { 222 if (!pass) {
@@ -244,10 +230,10 @@ static void ide_config(dev_link_t *link)
244 } 230 }
245 231
246 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 232 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
247 link->conf.Vpp1 = link->conf.Vpp2 = 233 link->conf.Vpp =
248 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 234 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
249 else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 235 else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
250 link->conf.Vpp1 = link->conf.Vpp2 = 236 link->conf.Vpp =
251 stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 237 stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
252 238
253 if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) { 239 if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
@@ -261,14 +247,14 @@ static void ide_config(dev_link_t *link)
261 link->io.NumPorts1 = 8; 247 link->io.NumPorts1 = 8;
262 link->io.BasePort2 = io->win[1].base; 248 link->io.BasePort2 = io->win[1].base;
263 link->io.NumPorts2 = (is_kme) ? 2 : 1; 249 link->io.NumPorts2 = (is_kme) ? 2 : 1;
264 if (pcmcia_request_io(link->handle, &link->io) != 0) 250 if (pcmcia_request_io(link, &link->io) != 0)
265 goto next_entry; 251 goto next_entry;
266 io_base = link->io.BasePort1; 252 io_base = link->io.BasePort1;
267 ctl_base = link->io.BasePort2; 253 ctl_base = link->io.BasePort2;
268 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) { 254 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
269 link->io.NumPorts1 = io->win[0].len; 255 link->io.NumPorts1 = io->win[0].len;
270 link->io.NumPorts2 = 0; 256 link->io.NumPorts2 = 0;
271 if (pcmcia_request_io(link->handle, &link->io) != 0) 257 if (pcmcia_request_io(link, &link->io) != 0)
272 goto next_entry; 258 goto next_entry;
273 io_base = link->io.BasePort1; 259 io_base = link->io.BasePort1;
274 ctl_base = link->io.BasePort1 + 0x0e; 260 ctl_base = link->io.BasePort1 + 0x0e;
@@ -281,16 +267,16 @@ static void ide_config(dev_link_t *link)
281 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 267 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
282 memcpy(&stk->dflt, cfg, sizeof(stk->dflt)); 268 memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
283 if (pass) { 269 if (pass) {
284 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 270 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
285 } else if (pcmcia_get_next_tuple(handle, &tuple) != 0) { 271 } else if (pcmcia_get_next_tuple(link, &tuple) != 0) {
286 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 272 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
287 memset(&stk->dflt, 0, sizeof(stk->dflt)); 273 memset(&stk->dflt, 0, sizeof(stk->dflt));
288 pass++; 274 pass++;
289 } 275 }
290 } 276 }
291 277
292 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 278 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
293 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 279 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
294 280
295 /* disable drive interrupts during IDE probe */ 281 /* disable drive interrupts during IDE probe */
296 outb(0x02, ctl_base); 282 outb(0x02, ctl_base);
@@ -301,12 +287,12 @@ static void ide_config(dev_link_t *link)
301 287
302 /* retry registration in case device is still spinning up */ 288 /* retry registration in case device is still spinning up */
303 for (hd = -1, i = 0; i < 10; i++) { 289 for (hd = -1, i = 0; i < 10; i++) {
304 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, handle); 290 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link);
305 if (hd >= 0) break; 291 if (hd >= 0) break;
306 if (link->io.NumPorts1 == 0x20) { 292 if (link->io.NumPorts1 == 0x20) {
307 outb(0x02, ctl_base + 0x10); 293 outb(0x02, ctl_base + 0x10);
308 hd = idecs_register(io_base + 0x10, ctl_base + 0x10, 294 hd = idecs_register(io_base + 0x10, ctl_base + 0x10,
309 link->irq.AssignedIRQ, handle); 295 link->irq.AssignedIRQ, link);
310 if (hd >= 0) { 296 if (hd >= 0) {
311 io_base += 0x10; 297 io_base += 0x10;
312 ctl_base += 0x10; 298 ctl_base += 0x10;
@@ -328,25 +314,23 @@ static void ide_config(dev_link_t *link)
328 info->node.major = ide_major[hd]; 314 info->node.major = ide_major[hd];
329 info->node.minor = 0; 315 info->node.minor = 0;
330 info->hd = hd; 316 info->hd = hd;
331 link->dev = &info->node; 317 link->dev_node = &info->node;
332 printk(KERN_INFO "ide-cs: %s: Vcc = %d.%d, Vpp = %d.%d\n", 318 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n",
333 info->node.dev_name, link->conf.Vcc / 10, link->conf.Vcc % 10, 319 info->node.dev_name, link->conf.Vpp / 10, link->conf.Vpp % 10);
334 link->conf.Vpp1 / 10, link->conf.Vpp1 % 10);
335 320
336 link->state &= ~DEV_CONFIG_PENDING;
337 kfree(stk); 321 kfree(stk);
338 return; 322 return 0;
339 323
340err_mem: 324err_mem:
341 printk(KERN_NOTICE "ide-cs: ide_config failed memory allocation\n"); 325 printk(KERN_NOTICE "ide-cs: ide_config failed memory allocation\n");
342 goto failed; 326 goto failed;
343 327
344cs_failed: 328cs_failed:
345 cs_error(link->handle, last_fn, last_ret); 329 cs_error(link, last_fn, last_ret);
346failed: 330failed:
347 kfree(stk); 331 kfree(stk);
348 ide_release(link); 332 ide_release(link);
349 link->state &= ~DEV_CONFIG_PENDING; 333 return -ENODEV;
350} /* ide_config */ 334} /* ide_config */
351 335
352/*====================================================================== 336/*======================================================================
@@ -357,7 +341,7 @@ failed:
357 341
358======================================================================*/ 342======================================================================*/
359 343
360void ide_release(dev_link_t *link) 344void ide_release(struct pcmcia_device *link)
361{ 345{
362 ide_info_t *info = link->priv; 346 ide_info_t *info = link->priv;
363 347
@@ -369,37 +353,10 @@ void ide_release(dev_link_t *link)
369 ide_unregister(info->hd); 353 ide_unregister(info->hd);
370 } 354 }
371 info->ndev = 0; 355 info->ndev = 0;
372 link->dev = NULL;
373
374 pcmcia_release_configuration(link->handle);
375 pcmcia_release_io(link->handle, &link->io);
376 pcmcia_release_irq(link->handle, &link->irq);
377
378 link->state &= ~DEV_CONFIG;
379 356
357 pcmcia_disable_device(link);
380} /* ide_release */ 358} /* ide_release */
381 359
382static int ide_suspend(struct pcmcia_device *dev)
383{
384 dev_link_t *link = dev_to_instance(dev);
385
386 link->state |= DEV_SUSPEND;
387 if (link->state & DEV_CONFIG)
388 pcmcia_release_configuration(link->handle);
389
390 return 0;
391}
392
393static int ide_resume(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state &= ~DEV_SUSPEND;
398 if (DEV_OK(link))
399 pcmcia_request_configuration(link->handle, &link->conf);
400
401 return 0;
402}
403 360
404/*====================================================================== 361/*======================================================================
405 362
@@ -459,11 +416,9 @@ static struct pcmcia_driver ide_cs_driver = {
459 .drv = { 416 .drv = {
460 .name = "ide-cs", 417 .name = "ide-cs",
461 }, 418 },
462 .probe = ide_attach, 419 .probe = ide_probe,
463 .remove = ide_detach, 420 .remove = ide_detach,
464 .id_table = ide_ids, 421 .id_table = ide_ids,
465 .suspend = ide_suspend,
466 .resume = ide_resume,
467}; 422};
468 423
469static int __init init_ide_cs(void) 424static int __init init_ide_cs(void)
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index 2a2b03ff096b..7bbfd85ab793 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -51,8 +51,8 @@ MODULE_LICENSE("GPL");
51 handler. 51 handler.
52*/ 52*/
53 53
54static void avmcs_config(dev_link_t *link); 54static int avmcs_config(struct pcmcia_device *link);
55static void avmcs_release(dev_link_t *link); 55static void avmcs_release(struct pcmcia_device *link);
56 56
57/* 57/*
58 The attach() and detach() entry points are used to create and destroy 58 The attach() and detach() entry points are used to create and destroy
@@ -65,10 +65,10 @@ static void avmcs_detach(struct pcmcia_device *p_dev);
65/* 65/*
66 A linked list of "instances" of the skeleton device. Each actual 66 A linked list of "instances" of the skeleton device. Each actual
67 PCMCIA card corresponds to one device instance, and is described 67 PCMCIA card corresponds to one device instance, and is described
68 by one dev_link_t structure (defined in ds.h). 68 by one struct pcmcia_device structure (defined in ds.h).
69 69
70 You may not want to use a linked list for this -- for example, the 70 You may not want to use a linked list for this -- for example, the
71 memory card driver uses an array of dev_link_t pointers, where minor 71 memory card driver uses an array of struct pcmcia_device pointers, where minor
72 device numbers are used to derive the corresponding array index. 72 device numbers are used to derive the corresponding array index.
73*/ 73*/
74 74
@@ -78,7 +78,7 @@ static void avmcs_detach(struct pcmcia_device *p_dev);
78 example, ethernet cards, modems). In other cases, there may be 78 example, ethernet cards, modems). In other cases, there may be
79 many actual or logical devices (SCSI adapters, memory cards with 79 many actual or logical devices (SCSI adapters, memory cards with
80 multiple partitions). The dev_node_t structures need to be kept 80 multiple partitions). The dev_node_t structures need to be kept
81 in a linked list starting at the 'dev' field of a dev_link_t 81 in a linked list starting at the 'dev' field of a struct pcmcia_device
82 structure. We allocate them in the card's private data structure, 82 structure. We allocate them in the card's private data structure,
83 because they generally can't be allocated dynamically. 83 because they generally can't be allocated dynamically.
84*/ 84*/
@@ -99,54 +99,38 @@ typedef struct local_info_t {
99 99
100======================================================================*/ 100======================================================================*/
101 101
102static int avmcs_attach(struct pcmcia_device *p_dev) 102static int avmcs_probe(struct pcmcia_device *p_dev)
103{ 103{
104 dev_link_t *link;
105 local_info_t *local; 104 local_info_t *local;
106 105
107 /* Initialize the dev_link_t structure */
108 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
109 if (!link)
110 goto err;
111 memset(link, 0, sizeof(struct dev_link_t));
112
113 /* The io structure describes IO port mapping */ 106 /* The io structure describes IO port mapping */
114 link->io.NumPorts1 = 16; 107 p_dev->io.NumPorts1 = 16;
115 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 108 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
116 link->io.NumPorts2 = 0; 109 p_dev->io.NumPorts2 = 0;
117 110
118 /* Interrupt setup */ 111 /* Interrupt setup */
119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 112 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
120 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 113 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
114
115 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
121 116
122 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
123
124 /* General socket configuration */ 117 /* General socket configuration */
125 link->conf.Attributes = CONF_ENABLE_IRQ; 118 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
126 link->conf.Vcc = 50; 119 p_dev->conf.IntType = INT_MEMORY_AND_IO;
127 link->conf.IntType = INT_MEMORY_AND_IO; 120 p_dev->conf.ConfigIndex = 1;
128 link->conf.ConfigIndex = 1; 121 p_dev->conf.Present = PRESENT_OPTION;
129 link->conf.Present = PRESENT_OPTION;
130 122
131 /* Allocate space for private device-specific data */ 123 /* Allocate space for private device-specific data */
132 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 124 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
133 if (!local) 125 if (!local)
134 goto err_kfree; 126 goto err;
135 memset(local, 0, sizeof(local_info_t)); 127 memset(local, 0, sizeof(local_info_t));
136 link->priv = local; 128 p_dev->priv = local;
137 129
138 link->handle = p_dev; 130 return avmcs_config(p_dev);
139 p_dev->instance = link;
140 131
141 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
142 avmcs_config(link);
143
144 return 0;
145
146 err_kfree:
147 kfree(link);
148 err: 132 err:
149 return -EINVAL; 133 return -ENOMEM;
150} /* avmcs_attach */ 134} /* avmcs_attach */
151 135
152/*====================================================================== 136/*======================================================================
@@ -158,15 +142,10 @@ static int avmcs_attach(struct pcmcia_device *p_dev)
158 142
159======================================================================*/ 143======================================================================*/
160 144
161static void avmcs_detach(struct pcmcia_device *p_dev) 145static void avmcs_detach(struct pcmcia_device *link)
162{ 146{
163 dev_link_t *link = dev_to_instance(p_dev);
164
165 if (link->state & DEV_CONFIG)
166 avmcs_release(link); 147 avmcs_release(link);
167 148 kfree(link->priv);
168 kfree(link->priv);
169 kfree(link);
170} /* avmcs_detach */ 149} /* avmcs_detach */
171 150
172/*====================================================================== 151/*======================================================================
@@ -177,7 +156,7 @@ static void avmcs_detach(struct pcmcia_device *p_dev)
177 156
178======================================================================*/ 157======================================================================*/
179 158
180static int get_tuple(client_handle_t handle, tuple_t *tuple, 159static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
181 cisparse_t *parse) 160 cisparse_t *parse)
182{ 161{
183 int i = pcmcia_get_tuple_data(handle, tuple); 162 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -185,7 +164,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
185 return pcmcia_parse_tuple(handle, tuple, parse); 164 return pcmcia_parse_tuple(handle, tuple, parse);
186} 165}
187 166
188static int first_tuple(client_handle_t handle, tuple_t *tuple, 167static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
189 cisparse_t *parse) 168 cisparse_t *parse)
190{ 169{
191 int i = pcmcia_get_first_tuple(handle, tuple); 170 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -193,7 +172,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
193 return get_tuple(handle, tuple, parse); 172 return get_tuple(handle, tuple, parse);
194} 173}
195 174
196static int next_tuple(client_handle_t handle, tuple_t *tuple, 175static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
197 cisparse_t *parse) 176 cisparse_t *parse)
198{ 177{
199 int i = pcmcia_get_next_tuple(handle, tuple); 178 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -201,9 +180,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
201 return get_tuple(handle, tuple, parse); 180 return get_tuple(handle, tuple, parse);
202} 181}
203 182
204static void avmcs_config(dev_link_t *link) 183static int avmcs_config(struct pcmcia_device *link)
205{ 184{
206 client_handle_t handle;
207 tuple_t tuple; 185 tuple_t tuple;
208 cisparse_t parse; 186 cisparse_t parse;
209 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 187 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
@@ -213,8 +191,7 @@ static void avmcs_config(dev_link_t *link)
213 char devname[128]; 191 char devname[128];
214 int cardtype; 192 int cardtype;
215 int (*addcard)(unsigned int port, unsigned irq); 193 int (*addcard)(unsigned int port, unsigned irq);
216 194
217 handle = link->handle;
218 dev = link->priv; 195 dev = link->priv;
219 196
220 /* 197 /*
@@ -223,25 +200,21 @@ static void avmcs_config(dev_link_t *link)
223 */ 200 */
224 do { 201 do {
225 tuple.DesiredTuple = CISTPL_CONFIG; 202 tuple.DesiredTuple = CISTPL_CONFIG;
226 i = pcmcia_get_first_tuple(handle, &tuple); 203 i = pcmcia_get_first_tuple(link, &tuple);
227 if (i != CS_SUCCESS) break; 204 if (i != CS_SUCCESS) break;
228 tuple.TupleData = buf; 205 tuple.TupleData = buf;
229 tuple.TupleDataMax = 64; 206 tuple.TupleDataMax = 64;
230 tuple.TupleOffset = 0; 207 tuple.TupleOffset = 0;
231 i = pcmcia_get_tuple_data(handle, &tuple); 208 i = pcmcia_get_tuple_data(link, &tuple);
232 if (i != CS_SUCCESS) break; 209 if (i != CS_SUCCESS) break;
233 i = pcmcia_parse_tuple(handle, &tuple, &parse); 210 i = pcmcia_parse_tuple(link, &tuple, &parse);
234 if (i != CS_SUCCESS) break; 211 if (i != CS_SUCCESS) break;
235 link->conf.ConfigBase = parse.config.base; 212 link->conf.ConfigBase = parse.config.base;
236 } while (0); 213 } while (0);
237 if (i != CS_SUCCESS) { 214 if (i != CS_SUCCESS) {
238 cs_error(link->handle, ParseTuple, i); 215 cs_error(link, ParseTuple, i);
239 link->state &= ~DEV_CONFIG_PENDING; 216 return -ENODEV;
240 return;
241 } 217 }
242
243 /* Configure card */
244 link->state |= DEV_CONFIG;
245 218
246 do { 219 do {
247 220
@@ -252,7 +225,7 @@ static void avmcs_config(dev_link_t *link)
252 tuple.DesiredTuple = CISTPL_VERS_1; 225 tuple.DesiredTuple = CISTPL_VERS_1;
253 226
254 devname[0] = 0; 227 devname[0] = 0;
255 if( !first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 1 ) { 228 if( !first_tuple(link, &tuple, &parse) && parse.version_1.ns > 1 ) {
256 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1], 229 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1],
257 sizeof(devname)); 230 sizeof(devname));
258 } 231 }
@@ -263,7 +236,7 @@ static void avmcs_config(dev_link_t *link)
263 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 236 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
264 tuple.Attributes = 0; 237 tuple.Attributes = 0;
265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 238 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
266 i = first_tuple(handle, &tuple, &parse); 239 i = first_tuple(link, &tuple, &parse);
267 while (i == CS_SUCCESS) { 240 while (i == CS_SUCCESS) {
268 if (cf->io.nwin > 0) { 241 if (cf->io.nwin > 0) {
269 link->conf.ConfigIndex = cf->index; 242 link->conf.ConfigIndex = cf->index;
@@ -273,36 +246,36 @@ static void avmcs_config(dev_link_t *link)
273 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n", 246 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n",
274 link->io.BasePort1, 247 link->io.BasePort1,
275 link->io.BasePort1+link->io.NumPorts1-1); 248 link->io.BasePort1+link->io.NumPorts1-1);
276 i = pcmcia_request_io(link->handle, &link->io); 249 i = pcmcia_request_io(link, &link->io);
277 if (i == CS_SUCCESS) goto found_port; 250 if (i == CS_SUCCESS) goto found_port;
278 } 251 }
279 i = next_tuple(handle, &tuple, &parse); 252 i = next_tuple(link, &tuple, &parse);
280 } 253 }
281 254
282found_port: 255found_port:
283 if (i != CS_SUCCESS) { 256 if (i != CS_SUCCESS) {
284 cs_error(link->handle, RequestIO, i); 257 cs_error(link, RequestIO, i);
285 break; 258 break;
286 } 259 }
287 260
288 /* 261 /*
289 * allocate an interrupt line 262 * allocate an interrupt line
290 */ 263 */
291 i = pcmcia_request_irq(link->handle, &link->irq); 264 i = pcmcia_request_irq(link, &link->irq);
292 if (i != CS_SUCCESS) { 265 if (i != CS_SUCCESS) {
293 cs_error(link->handle, RequestIRQ, i); 266 cs_error(link, RequestIRQ, i);
294 pcmcia_release_io(link->handle, &link->io); 267 /* undo */
268 pcmcia_disable_device(link);
295 break; 269 break;
296 } 270 }
297 271
298 /* 272 /*
299 * configure the PCMCIA socket 273 * configure the PCMCIA socket
300 */ 274 */
301 i = pcmcia_request_configuration(link->handle, &link->conf); 275 i = pcmcia_request_configuration(link, &link->conf);
302 if (i != CS_SUCCESS) { 276 if (i != CS_SUCCESS) {
303 cs_error(link->handle, RequestConfiguration, i); 277 cs_error(link, RequestConfiguration, i);
304 pcmcia_release_io(link->handle, &link->io); 278 pcmcia_disable_device(link);
305 pcmcia_release_irq(link->handle, &link->irq);
306 break; 279 break;
307 } 280 }
308 281
@@ -331,13 +304,12 @@ found_port:
331 304
332 dev->node.major = 64; 305 dev->node.major = 64;
333 dev->node.minor = 0; 306 dev->node.minor = 0;
334 link->dev = &dev->node; 307 link->dev_node = &dev->node;
335 308
336 link->state &= ~DEV_CONFIG_PENDING;
337 /* If any step failed, release any partially configured state */ 309 /* If any step failed, release any partially configured state */
338 if (i != 0) { 310 if (i != 0) {
339 avmcs_release(link); 311 avmcs_release(link);
340 return; 312 return -ENODEV;
341 } 313 }
342 314
343 315
@@ -351,9 +323,10 @@ found_port:
351 printk(KERN_ERR "avm_cs: failed to add AVM-%s-Controller at i/o %#x, irq %d\n", 323 printk(KERN_ERR "avm_cs: failed to add AVM-%s-Controller at i/o %#x, irq %d\n",
352 dev->node.dev_name, link->io.BasePort1, link->irq.AssignedIRQ); 324 dev->node.dev_name, link->io.BasePort1, link->irq.AssignedIRQ);
353 avmcs_release(link); 325 avmcs_release(link);
354 return; 326 return -ENODEV;
355 } 327 }
356 dev->node.minor = i; 328 dev->node.minor = i;
329 return 0;
357 330
358} /* avmcs_config */ 331} /* avmcs_config */
359 332
@@ -365,56 +338,12 @@ found_port:
365 338
366======================================================================*/ 339======================================================================*/
367 340
368static void avmcs_release(dev_link_t *link) 341static void avmcs_release(struct pcmcia_device *link)
369{ 342{
370 b1pcmcia_delcard(link->io.BasePort1, link->irq.AssignedIRQ); 343 b1pcmcia_delcard(link->io.BasePort1, link->irq.AssignedIRQ);
371 344 pcmcia_disable_device(link);
372 /* Unlink the device chain */
373 link->dev = NULL;
374
375 /* Don't bother checking to see if these succeed or not */
376 pcmcia_release_configuration(link->handle);
377 pcmcia_release_io(link->handle, &link->io);
378 pcmcia_release_irq(link->handle, &link->irq);
379 link->state &= ~DEV_CONFIG;
380} /* avmcs_release */ 345} /* avmcs_release */
381 346
382static int avmcs_suspend(struct pcmcia_device *dev)
383{
384 dev_link_t *link = dev_to_instance(dev);
385
386 link->state |= DEV_SUSPEND;
387 if (link->state & DEV_CONFIG)
388 pcmcia_release_configuration(link->handle);
389
390 return 0;
391}
392
393static int avmcs_resume(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state &= ~DEV_SUSPEND;
398 if (link->state & DEV_CONFIG)
399 pcmcia_request_configuration(link->handle, &link->conf);
400
401 return 0;
402}
403
404/*======================================================================
405
406 The card status event handler. Mostly, this schedules other
407 stuff to run after an event is received. A CARD_REMOVAL event
408 also sets some flags to discourage the net drivers from trying
409 to talk to the card any more.
410
411 When a CARD_REMOVAL event is received, we immediately set a flag
412 to block future accesses to this device. All the functions that
413 actually access the device should check this flag to make sure
414 the card is still present.
415
416======================================================================*/
417
418 347
419static struct pcmcia_device_id avmcs_ids[] = { 348static struct pcmcia_device_id avmcs_ids[] = {
420 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335), 349 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
@@ -429,11 +358,9 @@ static struct pcmcia_driver avmcs_driver = {
429 .drv = { 358 .drv = {
430 .name = "avm_cs", 359 .name = "avm_cs",
431 }, 360 },
432 .probe = avmcs_attach, 361 .probe = avmcs_probe,
433 .remove = avmcs_detach, 362 .remove = avmcs_detach,
434 .id_table = avmcs_ids, 363 .id_table = avmcs_ids,
435 .suspend= avmcs_suspend,
436 .resume = avmcs_resume,
437}; 364};
438 365
439static int __init avmcs_init(void) 366static int __init avmcs_init(void)
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 969da40c4248..ac28e3278ad9 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -67,8 +67,8 @@ module_param(isdnprot, int, 0);
67 handler. 67 handler.
68*/ 68*/
69 69
70static void avma1cs_config(dev_link_t *link); 70static int avma1cs_config(struct pcmcia_device *link);
71static void avma1cs_release(dev_link_t *link); 71static void avma1cs_release(struct pcmcia_device *link);
72 72
73/* 73/*
74 The attach() and detach() entry points are used to create and destroy 74 The attach() and detach() entry points are used to create and destroy
@@ -82,10 +82,10 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
82/* 82/*
83 A linked list of "instances" of the skeleton device. Each actual 83 A linked list of "instances" of the skeleton device. Each actual
84 PCMCIA card corresponds to one device instance, and is described 84 PCMCIA card corresponds to one device instance, and is described
85 by one dev_link_t structure (defined in ds.h). 85 by one struct pcmcia_device structure (defined in ds.h).
86 86
87 You may not want to use a linked list for this -- for example, the 87 You may not want to use a linked list for this -- for example, the
88 memory card driver uses an array of dev_link_t pointers, where minor 88 memory card driver uses an array of struct pcmcia_device pointers, where minor
89 device numbers are used to derive the corresponding array index. 89 device numbers are used to derive the corresponding array index.
90*/ 90*/
91 91
@@ -95,7 +95,7 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
95 example, ethernet cards, modems). In other cases, there may be 95 example, ethernet cards, modems). In other cases, there may be
96 many actual or logical devices (SCSI adapters, memory cards with 96 many actual or logical devices (SCSI adapters, memory cards with
97 multiple partitions). The dev_node_t structures need to be kept 97 multiple partitions). The dev_node_t structures need to be kept
98 in a linked list starting at the 'dev' field of a dev_link_t 98 in a linked list starting at the 'dev' field of a struct pcmcia_device
99 structure. We allocate them in the card's private data structure, 99 structure. We allocate them in the card's private data structure,
100 because they generally can't be allocated dynamically. 100 because they generally can't be allocated dynamically.
101*/ 101*/
@@ -116,55 +116,40 @@ typedef struct local_info_t {
116 116
117======================================================================*/ 117======================================================================*/
118 118
119static int avma1cs_attach(struct pcmcia_device *p_dev) 119static int avma1cs_probe(struct pcmcia_device *p_dev)
120{ 120{
121 dev_link_t *link;
122 local_info_t *local; 121 local_info_t *local;
123 122
124 DEBUG(0, "avma1cs_attach()\n"); 123 DEBUG(0, "avma1cs_attach()\n");
125 124
126 /* Initialize the dev_link_t structure */
127 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
128 if (!link)
129 return -ENOMEM;
130 memset(link, 0, sizeof(struct dev_link_t));
131
132 /* Allocate space for private device-specific data */ 125 /* Allocate space for private device-specific data */
133 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 126 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
134 if (!local) { 127 if (!local)
135 kfree(link);
136 return -ENOMEM; 128 return -ENOMEM;
137 } 129
138 memset(local, 0, sizeof(local_info_t)); 130 memset(local, 0, sizeof(local_info_t));
139 link->priv = local; 131 p_dev->priv = local;
140 132
141 /* The io structure describes IO port mapping */ 133 /* The io structure describes IO port mapping */
142 link->io.NumPorts1 = 16; 134 p_dev->io.NumPorts1 = 16;
143 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 135 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
144 link->io.NumPorts2 = 16; 136 p_dev->io.NumPorts2 = 16;
145 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; 137 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
146 link->io.IOAddrLines = 5; 138 p_dev->io.IOAddrLines = 5;
147 139
148 /* Interrupt setup */ 140 /* Interrupt setup */
149 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 141 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
150 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 142 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
151 143
152 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 144 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
153 145
154 /* General socket configuration */ 146 /* General socket configuration */
155 link->conf.Attributes = CONF_ENABLE_IRQ; 147 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
156 link->conf.Vcc = 50; 148 p_dev->conf.IntType = INT_MEMORY_AND_IO;
157 link->conf.IntType = INT_MEMORY_AND_IO; 149 p_dev->conf.ConfigIndex = 1;
158 link->conf.ConfigIndex = 1; 150 p_dev->conf.Present = PRESENT_OPTION;
159 link->conf.Present = PRESENT_OPTION;
160 151
161 link->handle = p_dev; 152 return avma1cs_config(p_dev);
162 p_dev->instance = link;
163
164 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
165 avma1cs_config(link);
166
167 return 0;
168} /* avma1cs_attach */ 153} /* avma1cs_attach */
169 154
170/*====================================================================== 155/*======================================================================
@@ -176,17 +161,11 @@ static int avma1cs_attach(struct pcmcia_device *p_dev)
176 161
177======================================================================*/ 162======================================================================*/
178 163
179static void avma1cs_detach(struct pcmcia_device *p_dev) 164static void avma1cs_detach(struct pcmcia_device *link)
180{ 165{
181 dev_link_t *link = dev_to_instance(p_dev); 166 DEBUG(0, "avma1cs_detach(0x%p)\n", link);
182 167 avma1cs_release(link);
183 DEBUG(0, "avma1cs_detach(0x%p)\n", link); 168 kfree(link->priv);
184
185 if (link->state & DEV_CONFIG)
186 avma1cs_release(link);
187
188 kfree(link->priv);
189 kfree(link);
190} /* avma1cs_detach */ 169} /* avma1cs_detach */
191 170
192/*====================================================================== 171/*======================================================================
@@ -197,7 +176,7 @@ static void avma1cs_detach(struct pcmcia_device *p_dev)
197 176
198======================================================================*/ 177======================================================================*/
199 178
200static int get_tuple(client_handle_t handle, tuple_t *tuple, 179static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
201 cisparse_t *parse) 180 cisparse_t *parse)
202{ 181{
203 int i = pcmcia_get_tuple_data(handle, tuple); 182 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -205,7 +184,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
205 return pcmcia_parse_tuple(handle, tuple, parse); 184 return pcmcia_parse_tuple(handle, tuple, parse);
206} 185}
207 186
208static int first_tuple(client_handle_t handle, tuple_t *tuple, 187static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
209 cisparse_t *parse) 188 cisparse_t *parse)
210{ 189{
211 int i = pcmcia_get_first_tuple(handle, tuple); 190 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -213,7 +192,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
213 return get_tuple(handle, tuple, parse); 192 return get_tuple(handle, tuple, parse);
214} 193}
215 194
216static int next_tuple(client_handle_t handle, tuple_t *tuple, 195static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
217 cisparse_t *parse) 196 cisparse_t *parse)
218{ 197{
219 int i = pcmcia_get_next_tuple(handle, tuple); 198 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -221,9 +200,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
221 return get_tuple(handle, tuple, parse); 200 return get_tuple(handle, tuple, parse);
222} 201}
223 202
224static void avma1cs_config(dev_link_t *link) 203static int avma1cs_config(struct pcmcia_device *link)
225{ 204{
226 client_handle_t handle;
227 tuple_t tuple; 205 tuple_t tuple;
228 cisparse_t parse; 206 cisparse_t parse;
229 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 207 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
@@ -233,8 +211,7 @@ static void avma1cs_config(dev_link_t *link)
233 char devname[128]; 211 char devname[128];
234 IsdnCard_t icard; 212 IsdnCard_t icard;
235 int busy = 0; 213 int busy = 0;
236 214
237 handle = link->handle;
238 dev = link->priv; 215 dev = link->priv;
239 216
240 DEBUG(0, "avma1cs_config(0x%p)\n", link); 217 DEBUG(0, "avma1cs_config(0x%p)\n", link);
@@ -245,25 +222,21 @@ static void avma1cs_config(dev_link_t *link)
245 */ 222 */
246 do { 223 do {
247 tuple.DesiredTuple = CISTPL_CONFIG; 224 tuple.DesiredTuple = CISTPL_CONFIG;
248 i = pcmcia_get_first_tuple(handle, &tuple); 225 i = pcmcia_get_first_tuple(link, &tuple);
249 if (i != CS_SUCCESS) break; 226 if (i != CS_SUCCESS) break;
250 tuple.TupleData = buf; 227 tuple.TupleData = buf;
251 tuple.TupleDataMax = 64; 228 tuple.TupleDataMax = 64;
252 tuple.TupleOffset = 0; 229 tuple.TupleOffset = 0;
253 i = pcmcia_get_tuple_data(handle, &tuple); 230 i = pcmcia_get_tuple_data(link, &tuple);
254 if (i != CS_SUCCESS) break; 231 if (i != CS_SUCCESS) break;
255 i = pcmcia_parse_tuple(handle, &tuple, &parse); 232 i = pcmcia_parse_tuple(link, &tuple, &parse);
256 if (i != CS_SUCCESS) break; 233 if (i != CS_SUCCESS) break;
257 link->conf.ConfigBase = parse.config.base; 234 link->conf.ConfigBase = parse.config.base;
258 } while (0); 235 } while (0);
259 if (i != CS_SUCCESS) { 236 if (i != CS_SUCCESS) {
260 cs_error(link->handle, ParseTuple, i); 237 cs_error(link, ParseTuple, i);
261 link->state &= ~DEV_CONFIG_PENDING; 238 return -ENODEV;
262 return;
263 } 239 }
264
265 /* Configure card */
266 link->state |= DEV_CONFIG;
267 240
268 do { 241 do {
269 242
@@ -274,7 +247,7 @@ static void avma1cs_config(dev_link_t *link)
274 tuple.DesiredTuple = CISTPL_VERS_1; 247 tuple.DesiredTuple = CISTPL_VERS_1;
275 248
276 devname[0] = 0; 249 devname[0] = 0;
277 if( !first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 1 ) { 250 if( !first_tuple(link, &tuple, &parse) && parse.version_1.ns > 1 ) {
278 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1], 251 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1],
279 sizeof(devname)); 252 sizeof(devname));
280 } 253 }
@@ -285,7 +258,7 @@ static void avma1cs_config(dev_link_t *link)
285 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 258 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
286 tuple.Attributes = 0; 259 tuple.Attributes = 0;
287 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 260 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
288 i = first_tuple(handle, &tuple, &parse); 261 i = first_tuple(link, &tuple, &parse);
289 while (i == CS_SUCCESS) { 262 while (i == CS_SUCCESS) {
290 if (cf->io.nwin > 0) { 263 if (cf->io.nwin > 0) {
291 link->conf.ConfigIndex = cf->index; 264 link->conf.ConfigIndex = cf->index;
@@ -295,36 +268,36 @@ static void avma1cs_config(dev_link_t *link)
295 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n", 268 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
296 link->io.BasePort1, 269 link->io.BasePort1,
297 link->io.BasePort1+link->io.NumPorts1 - 1); 270 link->io.BasePort1+link->io.NumPorts1 - 1);
298 i = pcmcia_request_io(link->handle, &link->io); 271 i = pcmcia_request_io(link, &link->io);
299 if (i == CS_SUCCESS) goto found_port; 272 if (i == CS_SUCCESS) goto found_port;
300 } 273 }
301 i = next_tuple(handle, &tuple, &parse); 274 i = next_tuple(link, &tuple, &parse);
302 } 275 }
303 276
304found_port: 277found_port:
305 if (i != CS_SUCCESS) { 278 if (i != CS_SUCCESS) {
306 cs_error(link->handle, RequestIO, i); 279 cs_error(link, RequestIO, i);
307 break; 280 break;
308 } 281 }
309 282
310 /* 283 /*
311 * allocate an interrupt line 284 * allocate an interrupt line
312 */ 285 */
313 i = pcmcia_request_irq(link->handle, &link->irq); 286 i = pcmcia_request_irq(link, &link->irq);
314 if (i != CS_SUCCESS) { 287 if (i != CS_SUCCESS) {
315 cs_error(link->handle, RequestIRQ, i); 288 cs_error(link, RequestIRQ, i);
316 pcmcia_release_io(link->handle, &link->io); 289 /* undo */
290 pcmcia_disable_device(link);
317 break; 291 break;
318 } 292 }
319 293
320 /* 294 /*
321 * configure the PCMCIA socket 295 * configure the PCMCIA socket
322 */ 296 */
323 i = pcmcia_request_configuration(link->handle, &link->conf); 297 i = pcmcia_request_configuration(link, &link->conf);
324 if (i != CS_SUCCESS) { 298 if (i != CS_SUCCESS) {
325 cs_error(link->handle, RequestConfiguration, i); 299 cs_error(link, RequestConfiguration, i);
326 pcmcia_release_io(link->handle, &link->io); 300 pcmcia_disable_device(link);
327 pcmcia_release_irq(link->handle, &link->irq);
328 break; 301 break;
329 } 302 }
330 303
@@ -336,13 +309,12 @@ found_port:
336 strcpy(dev->node.dev_name, "A1"); 309 strcpy(dev->node.dev_name, "A1");
337 dev->node.major = 45; 310 dev->node.major = 45;
338 dev->node.minor = 0; 311 dev->node.minor = 0;
339 link->dev = &dev->node; 312 link->dev_node = &dev->node;
340 313
341 link->state &= ~DEV_CONFIG_PENDING;
342 /* If any step failed, release any partially configured state */ 314 /* If any step failed, release any partially configured state */
343 if (i != 0) { 315 if (i != 0) {
344 avma1cs_release(link); 316 avma1cs_release(link);
345 return; 317 return -ENODEV;
346 } 318 }
347 319
348 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n", 320 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
@@ -357,10 +329,11 @@ found_port:
357 if (i < 0) { 329 if (i < 0) {
358 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1); 330 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1);
359 avma1cs_release(link); 331 avma1cs_release(link);
360 return; 332 return -ENODEV;
361 } 333 }
362 dev->node.minor = i; 334 dev->node.minor = i;
363 335
336 return 0;
364} /* avma1cs_config */ 337} /* avma1cs_config */
365 338
366/*====================================================================== 339/*======================================================================
@@ -371,47 +344,18 @@ found_port:
371 344
372======================================================================*/ 345======================================================================*/
373 346
374static void avma1cs_release(dev_link_t *link) 347static void avma1cs_release(struct pcmcia_device *link)
375{ 348{
376 local_info_t *local = link->priv; 349 local_info_t *local = link->priv;
377 350
378 DEBUG(0, "avma1cs_release(0x%p)\n", link); 351 DEBUG(0, "avma1cs_release(0x%p)\n", link);
379 352
380 /* no unregister function with hisax */ 353 /* now unregister function with hisax */
381 HiSax_closecard(local->node.minor); 354 HiSax_closecard(local->node.minor);
382 355
383 /* Unlink the device chain */ 356 pcmcia_disable_device(link);
384 link->dev = NULL;
385
386 /* Don't bother checking to see if these succeed or not */
387 pcmcia_release_configuration(link->handle);
388 pcmcia_release_io(link->handle, &link->io);
389 pcmcia_release_irq(link->handle, &link->irq);
390 link->state &= ~DEV_CONFIG;
391} /* avma1cs_release */ 357} /* avma1cs_release */
392 358
393static int avma1cs_suspend(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state |= DEV_SUSPEND;
398 if (link->state & DEV_CONFIG)
399 pcmcia_release_configuration(link->handle);
400
401 return 0;
402}
403
404static int avma1cs_resume(struct pcmcia_device *dev)
405{
406 dev_link_t *link = dev_to_instance(dev);
407
408 link->state &= ~DEV_SUSPEND;
409 if (link->state & DEV_CONFIG)
410 pcmcia_request_configuration(link->handle, &link->conf);
411
412 return 0;
413}
414
415 359
416static struct pcmcia_device_id avma1cs_ids[] = { 360static struct pcmcia_device_id avma1cs_ids[] = {
417 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), 361 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
@@ -425,13 +369,11 @@ static struct pcmcia_driver avma1cs_driver = {
425 .drv = { 369 .drv = {
426 .name = "avma1_cs", 370 .name = "avma1_cs",
427 }, 371 },
428 .probe = avma1cs_attach, 372 .probe = avma1cs_probe,
429 .remove = avma1cs_detach, 373 .remove = avma1cs_detach,
430 .id_table = avma1cs_ids, 374 .id_table = avma1cs_ids,
431 .suspend = avma1cs_suspend,
432 .resume = avma1cs_resume,
433}; 375};
434 376
435/*====================================================================*/ 377/*====================================================================*/
436 378
437static int __init init_avma1_cs(void) 379static int __init init_avma1_cs(void)
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index 062fb8f0739f..e18e75be8ed3 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -94,8 +94,8 @@ module_param(protocol, int, 0);
94 handler. 94 handler.
95*/ 95*/
96 96
97static void elsa_cs_config(dev_link_t *link); 97static int elsa_cs_config(struct pcmcia_device *link);
98static void elsa_cs_release(dev_link_t *link); 98static void elsa_cs_release(struct pcmcia_device *link);
99 99
100/* 100/*
101 The attach() and detach() entry points are used to create and destroy 101 The attach() and detach() entry points are used to create and destroy
@@ -111,7 +111,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev);
111 example, ethernet cards, modems). In other cases, there may be 111 example, ethernet cards, modems). In other cases, there may be
112 many actual or logical devices (SCSI adapters, memory cards with 112 many actual or logical devices (SCSI adapters, memory cards with
113 multiple partitions). The dev_node_t structures need to be kept 113 multiple partitions). The dev_node_t structures need to be kept
114 in a linked list starting at the 'dev' field of a dev_link_t 114 in a linked list starting at the 'dev' field of a struct pcmcia_device
115 structure. We allocate them in the card's private data structure, 115 structure. We allocate them in the card's private data structure,
116 because they generally shouldn't be allocated dynamically. 116 because they generally shouldn't be allocated dynamically.
117 In this case, we also provide a flag to indicate if a device is 117 In this case, we also provide a flag to indicate if a device is
@@ -121,7 +121,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev);
121*/ 121*/
122 122
123typedef struct local_info_t { 123typedef struct local_info_t {
124 dev_link_t link; 124 struct pcmcia_device *p_dev;
125 dev_node_t node; 125 dev_node_t node;
126 int busy; 126 int busy;
127 int cardnr; 127 int cardnr;
@@ -139,9 +139,8 @@ typedef struct local_info_t {
139 139
140======================================================================*/ 140======================================================================*/
141 141
142static int elsa_cs_attach(struct pcmcia_device *p_dev) 142static int elsa_cs_probe(struct pcmcia_device *link)
143{ 143{
144 dev_link_t *link;
145 local_info_t *local; 144 local_info_t *local;
146 145
147 DEBUG(0, "elsa_cs_attach()\n"); 146 DEBUG(0, "elsa_cs_attach()\n");
@@ -150,8 +149,11 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
150 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 149 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
151 if (!local) return -ENOMEM; 150 if (!local) return -ENOMEM;
152 memset(local, 0, sizeof(local_info_t)); 151 memset(local, 0, sizeof(local_info_t));
152
153 local->p_dev = link;
154 link->priv = local;
155
153 local->cardnr = -1; 156 local->cardnr = -1;
154 link = &local->link; link->priv = local;
155 157
156 /* Interrupt setup */ 158 /* Interrupt setup */
157 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 159 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
@@ -170,16 +172,9 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
170 link->io.IOAddrLines = 3; 172 link->io.IOAddrLines = 3;
171 173
172 link->conf.Attributes = CONF_ENABLE_IRQ; 174 link->conf.Attributes = CONF_ENABLE_IRQ;
173 link->conf.Vcc = 50;
174 link->conf.IntType = INT_MEMORY_AND_IO; 175 link->conf.IntType = INT_MEMORY_AND_IO;
175 176
176 link->handle = p_dev; 177 return elsa_cs_config(link);
177 p_dev->instance = link;
178
179 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
180 elsa_cs_config(link);
181
182 return 0;
183} /* elsa_cs_attach */ 178} /* elsa_cs_attach */
184 179
185/*====================================================================== 180/*======================================================================
@@ -191,20 +186,16 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
191 186
192======================================================================*/ 187======================================================================*/
193 188
194static void elsa_cs_detach(struct pcmcia_device *p_dev) 189static void elsa_cs_detach(struct pcmcia_device *link)
195{ 190{
196 dev_link_t *link = dev_to_instance(p_dev); 191 local_info_t *info = link->priv;
197 local_info_t *info = link->priv;
198 192
199 DEBUG(0, "elsa_cs_detach(0x%p)\n", link); 193 DEBUG(0, "elsa_cs_detach(0x%p)\n", link);
200 194
201 if (link->state & DEV_CONFIG) { 195 info->busy = 1;
202 info->busy = 1; 196 elsa_cs_release(link);
203 elsa_cs_release(link);
204 }
205
206 kfree(info);
207 197
198 kfree(info);
208} /* elsa_cs_detach */ 199} /* elsa_cs_detach */
209 200
210/*====================================================================== 201/*======================================================================
@@ -214,7 +205,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev)
214 device available to the system. 205 device available to the system.
215 206
216======================================================================*/ 207======================================================================*/
217static int get_tuple(client_handle_t handle, tuple_t *tuple, 208static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
218 cisparse_t *parse) 209 cisparse_t *parse)
219{ 210{
220 int i = pcmcia_get_tuple_data(handle, tuple); 211 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -222,7 +213,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
222 return pcmcia_parse_tuple(handle, tuple, parse); 213 return pcmcia_parse_tuple(handle, tuple, parse);
223} 214}
224 215
225static int first_tuple(client_handle_t handle, tuple_t *tuple, 216static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
226 cisparse_t *parse) 217 cisparse_t *parse)
227{ 218{
228 int i = pcmcia_get_first_tuple(handle, tuple); 219 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -230,7 +221,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
230 return get_tuple(handle, tuple, parse); 221 return get_tuple(handle, tuple, parse);
231} 222}
232 223
233static int next_tuple(client_handle_t handle, tuple_t *tuple, 224static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
234 cisparse_t *parse) 225 cisparse_t *parse)
235{ 226{
236 int i = pcmcia_get_next_tuple(handle, tuple); 227 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -238,9 +229,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
238 return get_tuple(handle, tuple, parse); 229 return get_tuple(handle, tuple, parse);
239} 230}
240 231
241static void elsa_cs_config(dev_link_t *link) 232static int elsa_cs_config(struct pcmcia_device *link)
242{ 233{
243 client_handle_t handle;
244 tuple_t tuple; 234 tuple_t tuple;
245 cisparse_t parse; 235 cisparse_t parse;
246 local_info_t *dev; 236 local_info_t *dev;
@@ -250,7 +240,6 @@ static void elsa_cs_config(dev_link_t *link)
250 IsdnCard_t icard; 240 IsdnCard_t icard;
251 241
252 DEBUG(0, "elsa_config(0x%p)\n", link); 242 DEBUG(0, "elsa_config(0x%p)\n", link);
253 handle = link->handle;
254 dev = link->priv; 243 dev = link->priv;
255 244
256 /* 245 /*
@@ -262,7 +251,7 @@ static void elsa_cs_config(dev_link_t *link)
262 tuple.TupleDataMax = 255; 251 tuple.TupleDataMax = 255;
263 tuple.TupleOffset = 0; 252 tuple.TupleOffset = 0;
264 tuple.Attributes = 0; 253 tuple.Attributes = 0;
265 i = first_tuple(handle, &tuple, &parse); 254 i = first_tuple(link, &tuple, &parse);
266 if (i != CS_SUCCESS) { 255 if (i != CS_SUCCESS) {
267 last_fn = ParseTuple; 256 last_fn = ParseTuple;
268 goto cs_failed; 257 goto cs_failed;
@@ -270,32 +259,29 @@ static void elsa_cs_config(dev_link_t *link)
270 link->conf.ConfigBase = parse.config.base; 259 link->conf.ConfigBase = parse.config.base;
271 link->conf.Present = parse.config.rmask[0]; 260 link->conf.Present = parse.config.rmask[0];
272 261
273 /* Configure card */
274 link->state |= DEV_CONFIG;
275
276 tuple.TupleData = (cisdata_t *)buf; 262 tuple.TupleData = (cisdata_t *)buf;
277 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 263 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
278 tuple.Attributes = 0; 264 tuple.Attributes = 0;
279 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
280 i = first_tuple(handle, &tuple, &parse); 266 i = first_tuple(link, &tuple, &parse);
281 while (i == CS_SUCCESS) { 267 while (i == CS_SUCCESS) {
282 if ( (cf->io.nwin > 0) && cf->io.win[0].base) { 268 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
283 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n"); 269 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
284 link->conf.ConfigIndex = cf->index; 270 link->conf.ConfigIndex = cf->index;
285 link->io.BasePort1 = cf->io.win[0].base; 271 link->io.BasePort1 = cf->io.win[0].base;
286 i = pcmcia_request_io(link->handle, &link->io); 272 i = pcmcia_request_io(link, &link->io);
287 if (i == CS_SUCCESS) break; 273 if (i == CS_SUCCESS) break;
288 } else { 274 } else {
289 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n"); 275 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
290 link->conf.ConfigIndex = cf->index; 276 link->conf.ConfigIndex = cf->index;
291 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) { 277 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
292 link->io.BasePort1 = j; 278 link->io.BasePort1 = j;
293 i = pcmcia_request_io(link->handle, &link->io); 279 i = pcmcia_request_io(link, &link->io);
294 if (i == CS_SUCCESS) break; 280 if (i == CS_SUCCESS) break;
295 } 281 }
296 break; 282 break;
297 } 283 }
298 i = next_tuple(handle, &tuple, &parse); 284 i = next_tuple(link, &tuple, &parse);
299 } 285 }
300 286
301 if (i != CS_SUCCESS) { 287 if (i != CS_SUCCESS) {
@@ -303,14 +289,14 @@ static void elsa_cs_config(dev_link_t *link)
303 goto cs_failed; 289 goto cs_failed;
304 } 290 }
305 291
306 i = pcmcia_request_irq(link->handle, &link->irq); 292 i = pcmcia_request_irq(link, &link->irq);
307 if (i != CS_SUCCESS) { 293 if (i != CS_SUCCESS) {
308 link->irq.AssignedIRQ = 0; 294 link->irq.AssignedIRQ = 0;
309 last_fn = RequestIRQ; 295 last_fn = RequestIRQ;
310 goto cs_failed; 296 goto cs_failed;
311 } 297 }
312 298
313 i = pcmcia_request_configuration(link->handle, &link->conf); 299 i = pcmcia_request_configuration(link, &link->conf);
314 if (i != CS_SUCCESS) { 300 if (i != CS_SUCCESS) {
315 last_fn = RequestConfiguration; 301 last_fn = RequestConfiguration;
316 goto cs_failed; 302 goto cs_failed;
@@ -321,14 +307,11 @@ static void elsa_cs_config(dev_link_t *link)
321 sprintf(dev->node.dev_name, "elsa"); 307 sprintf(dev->node.dev_name, "elsa");
322 dev->node.major = dev->node.minor = 0x0; 308 dev->node.major = dev->node.minor = 0x0;
323 309
324 link->dev = &dev->node; 310 link->dev_node = &dev->node;
325 311
326 /* Finally, report what we've done */ 312 /* Finally, report what we've done */
327 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 313 printk(KERN_INFO "%s: index 0x%02x: ",
328 dev->node.dev_name, link->conf.ConfigIndex, 314 dev->node.dev_name, link->conf.ConfigIndex);
329 link->conf.Vcc/10, link->conf.Vcc%10);
330 if (link->conf.Vpp1)
331 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
332 if (link->conf.Attributes & CONF_ENABLE_IRQ) 315 if (link->conf.Attributes & CONF_ENABLE_IRQ)
333 printk(", irq %d", link->irq.AssignedIRQ); 316 printk(", irq %d", link->irq.AssignedIRQ);
334 if (link->io.NumPorts1) 317 if (link->io.NumPorts1)
@@ -339,8 +322,6 @@ static void elsa_cs_config(dev_link_t *link)
339 link->io.BasePort2+link->io.NumPorts2-1); 322 link->io.BasePort2+link->io.NumPorts2-1);
340 printk("\n"); 323 printk("\n");
341 324
342 link->state &= ~DEV_CONFIG_PENDING;
343
344 icard.para[0] = link->irq.AssignedIRQ; 325 icard.para[0] = link->irq.AssignedIRQ;
345 icard.para[1] = link->io.BasePort1; 326 icard.para[1] = link->io.BasePort1;
346 icard.protocol = protocol; 327 icard.protocol = protocol;
@@ -354,10 +335,11 @@ static void elsa_cs_config(dev_link_t *link)
354 } else 335 } else
355 ((local_info_t*)link->priv)->cardnr = i; 336 ((local_info_t*)link->priv)->cardnr = i;
356 337
357 return; 338 return 0;
358cs_failed: 339cs_failed:
359 cs_error(link->handle, last_fn, i); 340 cs_error(link, last_fn, i);
360 elsa_cs_release(link); 341 elsa_cs_release(link);
342 return -ENODEV;
361} /* elsa_cs_config */ 343} /* elsa_cs_config */
362 344
363/*====================================================================== 345/*======================================================================
@@ -368,7 +350,7 @@ cs_failed:
368 350
369======================================================================*/ 351======================================================================*/
370 352
371static void elsa_cs_release(dev_link_t *link) 353static void elsa_cs_release(struct pcmcia_device *link)
372{ 354{
373 local_info_t *local = link->priv; 355 local_info_t *local = link->priv;
374 356
@@ -380,39 +362,23 @@ static void elsa_cs_release(dev_link_t *link)
380 HiSax_closecard(local->cardnr); 362 HiSax_closecard(local->cardnr);
381 } 363 }
382 } 364 }
383 /* Unlink the device chain */ 365
384 link->dev = NULL; 366 pcmcia_disable_device(link);
385
386 /* Don't bother checking to see if these succeed or not */
387 if (link->win)
388 pcmcia_release_window(link->win);
389 pcmcia_release_configuration(link->handle);
390 pcmcia_release_io(link->handle, &link->io);
391 pcmcia_release_irq(link->handle, &link->irq);
392 link->state &= ~DEV_CONFIG;
393} /* elsa_cs_release */ 367} /* elsa_cs_release */
394 368
395static int elsa_suspend(struct pcmcia_device *p_dev) 369static int elsa_suspend(struct pcmcia_device *link)
396{ 370{
397 dev_link_t *link = dev_to_instance(p_dev);
398 local_info_t *dev = link->priv; 371 local_info_t *dev = link->priv;
399 372
400 link->state |= DEV_SUSPEND;
401 dev->busy = 1; 373 dev->busy = 1;
402 if (link->state & DEV_CONFIG)
403 pcmcia_release_configuration(link->handle);
404 374
405 return 0; 375 return 0;
406} 376}
407 377
408static int elsa_resume(struct pcmcia_device *p_dev) 378static int elsa_resume(struct pcmcia_device *link)
409{ 379{
410 dev_link_t *link = dev_to_instance(p_dev);
411 local_info_t *dev = link->priv; 380 local_info_t *dev = link->priv;
412 381
413 link->state &= ~DEV_SUSPEND;
414 if (link->state & DEV_CONFIG)
415 pcmcia_request_configuration(link->handle, &link->conf);
416 dev->busy = 0; 382 dev->busy = 0;
417 383
418 return 0; 384 return 0;
@@ -430,7 +396,7 @@ static struct pcmcia_driver elsa_cs_driver = {
430 .drv = { 396 .drv = {
431 .name = "elsa_cs", 397 .name = "elsa_cs",
432 }, 398 },
433 .probe = elsa_cs_attach, 399 .probe = elsa_cs_probe,
434 .remove = elsa_cs_detach, 400 .remove = elsa_cs_detach,
435 .id_table = elsa_ids, 401 .id_table = elsa_ids,
436 .suspend = elsa_suspend, 402 .suspend = elsa_suspend,
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 6f5213a18a8d..9bb18f3f7829 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -95,8 +95,8 @@ module_param(protocol, int, 0);
95 event handler. 95 event handler.
96*/ 96*/
97 97
98static void sedlbauer_config(dev_link_t *link); 98static int sedlbauer_config(struct pcmcia_device *link);
99static void sedlbauer_release(dev_link_t *link); 99static void sedlbauer_release(struct pcmcia_device *link);
100 100
101/* 101/*
102 The attach() and detach() entry points are used to create and destroy 102 The attach() and detach() entry points are used to create and destroy
@@ -119,7 +119,7 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev);
119 example, ethernet cards, modems). In other cases, there may be 119 example, ethernet cards, modems). In other cases, there may be
120 many actual or logical devices (SCSI adapters, memory cards with 120 many actual or logical devices (SCSI adapters, memory cards with
121 multiple partitions). The dev_node_t structures need to be kept 121 multiple partitions). The dev_node_t structures need to be kept
122 in a linked list starting at the 'dev' field of a dev_link_t 122 in a linked list starting at the 'dev' field of a struct pcmcia_device
123 structure. We allocate them in the card's private data structure, 123 structure. We allocate them in the card's private data structure,
124 because they generally shouldn't be allocated dynamically. 124 because they generally shouldn't be allocated dynamically.
125 125
@@ -130,7 +130,7 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev);
130*/ 130*/
131 131
132typedef struct local_info_t { 132typedef struct local_info_t {
133 dev_link_t link; 133 struct pcmcia_device *p_dev;
134 dev_node_t node; 134 dev_node_t node;
135 int stop; 135 int stop;
136 int cardnr; 136 int cardnr;
@@ -148,11 +148,10 @@ typedef struct local_info_t {
148 148
149======================================================================*/ 149======================================================================*/
150 150
151static int sedlbauer_attach(struct pcmcia_device *p_dev) 151static int sedlbauer_probe(struct pcmcia_device *link)
152{ 152{
153 local_info_t *local; 153 local_info_t *local;
154 dev_link_t *link; 154
155
156 DEBUG(0, "sedlbauer_attach()\n"); 155 DEBUG(0, "sedlbauer_attach()\n");
157 156
158 /* Allocate space for private device-specific data */ 157 /* Allocate space for private device-specific data */
@@ -160,8 +159,10 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
160 if (!local) return -ENOMEM; 159 if (!local) return -ENOMEM;
161 memset(local, 0, sizeof(local_info_t)); 160 memset(local, 0, sizeof(local_info_t));
162 local->cardnr = -1; 161 local->cardnr = -1;
163 link = &local->link; link->priv = local; 162
164 163 local->p_dev = link;
164 link->priv = local;
165
165 /* Interrupt setup */ 166 /* Interrupt setup */
166 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 167 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
167 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 168 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
@@ -182,18 +183,10 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
182 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 183 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
183 link->io.IOAddrLines = 3; 184 link->io.IOAddrLines = 3;
184 185
185
186 link->conf.Attributes = 0; 186 link->conf.Attributes = 0;
187 link->conf.Vcc = 50;
188 link->conf.IntType = INT_MEMORY_AND_IO; 187 link->conf.IntType = INT_MEMORY_AND_IO;
189 188
190 link->handle = p_dev; 189 return sedlbauer_config(link);
191 p_dev->instance = link;
192
193 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
194 sedlbauer_config(link);
195
196 return 0;
197} /* sedlbauer_attach */ 190} /* sedlbauer_attach */
198 191
199/*====================================================================== 192/*======================================================================
@@ -205,19 +198,15 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
205 198
206======================================================================*/ 199======================================================================*/
207 200
208static void sedlbauer_detach(struct pcmcia_device *p_dev) 201static void sedlbauer_detach(struct pcmcia_device *link)
209{ 202{
210 dev_link_t *link = dev_to_instance(p_dev); 203 DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
211
212 DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
213 204
214 if (link->state & DEV_CONFIG) { 205 ((local_info_t *)link->priv)->stop = 1;
215 ((local_info_t *)link->priv)->stop = 1; 206 sedlbauer_release(link);
216 sedlbauer_release(link);
217 }
218 207
219 /* This points to the parent local_info_t struct */ 208 /* This points to the parent local_info_t struct */
220 kfree(link->priv); 209 kfree(link->priv);
221} /* sedlbauer_detach */ 210} /* sedlbauer_detach */
222 211
223/*====================================================================== 212/*======================================================================
@@ -230,9 +219,8 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev)
230#define CS_CHECK(fn, ret) \ 219#define CS_CHECK(fn, ret) \
231do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 220do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
232 221
233static void sedlbauer_config(dev_link_t *link) 222static int sedlbauer_config(struct pcmcia_device *link)
234{ 223{
235 client_handle_t handle = link->handle;
236 local_info_t *dev = link->priv; 224 local_info_t *dev = link->priv;
237 tuple_t tuple; 225 tuple_t tuple;
238 cisparse_t parse; 226 cisparse_t parse;
@@ -254,18 +242,13 @@ static void sedlbauer_config(dev_link_t *link)
254 tuple.TupleData = buf; 242 tuple.TupleData = buf;
255 tuple.TupleDataMax = sizeof(buf); 243 tuple.TupleDataMax = sizeof(buf);
256 tuple.TupleOffset = 0; 244 tuple.TupleOffset = 0;
257 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 245 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
258 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 246 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
259 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 247 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
260 link->conf.ConfigBase = parse.config.base; 248 link->conf.ConfigBase = parse.config.base;
261 link->conf.Present = parse.config.rmask[0]; 249 link->conf.Present = parse.config.rmask[0];
262
263 /* Configure card */
264 link->state |= DEV_CONFIG;
265 250
266 /* Look up the current Vcc */ 251 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
267 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
268 link->conf.Vcc = conf.Vcc;
269 252
270 /* 253 /*
271 In this loop, we scan the CIS for configuration table entries, 254 In this loop, we scan the CIS for configuration table entries,
@@ -280,12 +263,12 @@ static void sedlbauer_config(dev_link_t *link)
280 will only use the CIS to fill in implementation-defined details. 263 will only use the CIS to fill in implementation-defined details.
281 */ 264 */
282 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
283 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 266 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
284 while (1) { 267 while (1) {
285 cistpl_cftable_entry_t dflt = { 0 }; 268 cistpl_cftable_entry_t dflt = { 0 };
286 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 269 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
287 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 270 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
288 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 271 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
289 goto next_entry; 272 goto next_entry;
290 273
291 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 274 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
@@ -309,10 +292,10 @@ static void sedlbauer_config(dev_link_t *link)
309 } 292 }
310 293
311 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 294 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
312 link->conf.Vpp1 = link->conf.Vpp2 = 295 link->conf.Vpp =
313 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 296 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
314 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 297 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
315 link->conf.Vpp1 = link->conf.Vpp2 = 298 link->conf.Vpp =
316 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 299 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
317 300
318 /* Do we need to allocate an interrupt? */ 301 /* Do we need to allocate an interrupt? */
@@ -339,13 +322,13 @@ static void sedlbauer_config(dev_link_t *link)
339 link->io.NumPorts2 = io->win[1].len; 322 link->io.NumPorts2 = io->win[1].len;
340 } 323 }
341 /* This reserves IO space but doesn't actually enable it */ 324 /* This reserves IO space but doesn't actually enable it */
342 if (pcmcia_request_io(link->handle, &link->io) != 0) 325 if (pcmcia_request_io(link, &link->io) != 0)
343 goto next_entry; 326 goto next_entry;
344 } 327 }
345 328
346 /* 329 /*
347 Now set up a common memory window, if needed. There is room 330 Now set up a common memory window, if needed. There is room
348 in the dev_link_t structure for one memory window handle, 331 in the struct pcmcia_device structure for one memory window handle,
349 but if the base addresses need to be saved, or if multiple 332 but if the base addresses need to be saved, or if multiple
350 windows are needed, the info should go in the private data 333 windows are needed, the info should go in the private data
351 structure for this device. 334 structure for this device.
@@ -366,7 +349,7 @@ static void sedlbauer_config(dev_link_t *link)
366 req.Size = 0x1000; 349 req.Size = 0x1000;
367*/ 350*/
368 req.AccessSpeed = 0; 351 req.AccessSpeed = 0;
369 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 352 if (pcmcia_request_window(&link, &req, &link->win) != 0)
370 goto next_entry; 353 goto next_entry;
371 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 354 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
372 if (pcmcia_map_mem_page(link->win, &map) != 0) 355 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -374,29 +357,25 @@ static void sedlbauer_config(dev_link_t *link)
374 } 357 }
375 /* If we got this far, we're cool! */ 358 /* If we got this far, we're cool! */
376 break; 359 break;
377 360
378 next_entry: 361 next_entry:
379/* new in dummy.cs 2001/01/28 MN 362 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
380 if (link->io.NumPorts1)
381 pcmcia_release_io(link->handle, &link->io);
382*/
383 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
384 } 363 }
385 364
386 /* 365 /*
387 Allocate an interrupt line. Note that this does not assign a 366 Allocate an interrupt line. Note that this does not assign a
388 handler to the interrupt, unless the 'Handler' member of the 367 handler to the interrupt, unless the 'Handler' member of the
389 irq structure is initialized. 368 irq structure is initialized.
390 */ 369 */
391 if (link->conf.Attributes & CONF_ENABLE_IRQ) 370 if (link->conf.Attributes & CONF_ENABLE_IRQ)
392 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 371 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
393 372
394 /* 373 /*
395 This actually configures the PCMCIA socket -- setting up 374 This actually configures the PCMCIA socket -- setting up
396 the I/O windows and the interrupt mapping, and putting the 375 the I/O windows and the interrupt mapping, and putting the
397 card and host interface into "Memory and IO" mode. 376 card and host interface into "Memory and IO" mode.
398 */ 377 */
399 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 378 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
400 379
401 /* 380 /*
402 At this point, the dev_node_t structure(s) need to be 381 At this point, the dev_node_t structure(s) need to be
@@ -404,14 +383,13 @@ static void sedlbauer_config(dev_link_t *link)
404 */ 383 */
405 sprintf(dev->node.dev_name, "sedlbauer"); 384 sprintf(dev->node.dev_name, "sedlbauer");
406 dev->node.major = dev->node.minor = 0; 385 dev->node.major = dev->node.minor = 0;
407 link->dev = &dev->node; 386 link->dev_node = &dev->node;
408 387
409 /* Finally, report what we've done */ 388 /* Finally, report what we've done */
410 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 389 printk(KERN_INFO "%s: index 0x%02x:",
411 dev->node.dev_name, link->conf.ConfigIndex, 390 dev->node.dev_name, link->conf.ConfigIndex);
412 link->conf.Vcc/10, link->conf.Vcc%10); 391 if (link->conf.Vpp)
413 if (link->conf.Vpp1) 392 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
414 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
415 if (link->conf.Attributes & CONF_ENABLE_IRQ) 393 if (link->conf.Attributes & CONF_ENABLE_IRQ)
416 printk(", irq %d", link->irq.AssignedIRQ); 394 printk(", irq %d", link->irq.AssignedIRQ);
417 if (link->io.NumPorts1) 395 if (link->io.NumPorts1)
@@ -424,8 +402,6 @@ static void sedlbauer_config(dev_link_t *link)
424 printk(", mem 0x%06lx-0x%06lx", req.Base, 402 printk(", mem 0x%06lx-0x%06lx", req.Base,
425 req.Base+req.Size-1); 403 req.Base+req.Size-1);
426 printk("\n"); 404 printk("\n");
427
428 link->state &= ~DEV_CONFIG_PENDING;
429 405
430 icard.para[0] = link->irq.AssignedIRQ; 406 icard.para[0] = link->irq.AssignedIRQ;
431 icard.para[1] = link->io.BasePort1; 407 icard.para[1] = link->io.BasePort1;
@@ -437,14 +413,16 @@ static void sedlbauer_config(dev_link_t *link)
437 printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n", 413 printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n",
438 last_ret, link->io.BasePort1); 414 last_ret, link->io.BasePort1);
439 sedlbauer_release(link); 415 sedlbauer_release(link);
416 return -ENODEV;
440 } else 417 } else
441 ((local_info_t*)link->priv)->cardnr = last_ret; 418 ((local_info_t*)link->priv)->cardnr = last_ret;
442 419
443 return; 420 return 0;
444 421
445cs_failed: 422cs_failed:
446 cs_error(link->handle, last_fn, last_ret); 423 cs_error(link, last_fn, last_ret);
447 sedlbauer_release(link); 424 sedlbauer_release(link);
425 return -ENODEV;
448 426
449} /* sedlbauer_config */ 427} /* sedlbauer_config */
450 428
@@ -456,7 +434,7 @@ cs_failed:
456 434
457======================================================================*/ 435======================================================================*/
458 436
459static void sedlbauer_release(dev_link_t *link) 437static void sedlbauer_release(struct pcmcia_device *link)
460{ 438{
461 local_info_t *local = link->priv; 439 local_info_t *local = link->priv;
462 DEBUG(0, "sedlbauer_release(0x%p)\n", link); 440 DEBUG(0, "sedlbauer_release(0x%p)\n", link);
@@ -467,46 +445,23 @@ static void sedlbauer_release(dev_link_t *link)
467 HiSax_closecard(local->cardnr); 445 HiSax_closecard(local->cardnr);
468 } 446 }
469 } 447 }
470 /* Unlink the device chain */
471 link->dev = NULL;
472 448
473 /* 449 pcmcia_disable_device(link);
474 In a normal driver, additional code may be needed to release
475 other kernel data structures associated with this device.
476 */
477
478 /* Don't bother checking to see if these succeed or not */
479 if (link->win)
480 pcmcia_release_window(link->win);
481 pcmcia_release_configuration(link->handle);
482 if (link->io.NumPorts1)
483 pcmcia_release_io(link->handle, &link->io);
484 if (link->irq.AssignedIRQ)
485 pcmcia_release_irq(link->handle, &link->irq);
486 link->state &= ~DEV_CONFIG;
487} /* sedlbauer_release */ 450} /* sedlbauer_release */
488 451
489static int sedlbauer_suspend(struct pcmcia_device *p_dev) 452static int sedlbauer_suspend(struct pcmcia_device *link)
490{ 453{
491 dev_link_t *link = dev_to_instance(p_dev);
492 local_info_t *dev = link->priv; 454 local_info_t *dev = link->priv;
493 455
494 link->state |= DEV_SUSPEND;
495 dev->stop = 1; 456 dev->stop = 1;
496 if (link->state & DEV_CONFIG)
497 pcmcia_release_configuration(link->handle);
498 457
499 return 0; 458 return 0;
500} 459}
501 460
502static int sedlbauer_resume(struct pcmcia_device *p_dev) 461static int sedlbauer_resume(struct pcmcia_device *link)
503{ 462{
504 dev_link_t *link = dev_to_instance(p_dev);
505 local_info_t *dev = link->priv; 463 local_info_t *dev = link->priv;
506 464
507 link->state &= ~DEV_SUSPEND;
508 if (link->state & DEV_CONFIG)
509 pcmcia_request_configuration(link->handle, &link->conf);
510 dev->stop = 0; 465 dev->stop = 0;
511 466
512 return 0; 467 return 0;
@@ -530,7 +485,7 @@ static struct pcmcia_driver sedlbauer_driver = {
530 .drv = { 485 .drv = {
531 .name = "sedlbauer_cs", 486 .name = "sedlbauer_cs",
532 }, 487 },
533 .probe = sedlbauer_attach, 488 .probe = sedlbauer_probe,
534 .remove = sedlbauer_detach, 489 .remove = sedlbauer_detach,
535 .id_table = sedlbauer_ids, 490 .id_table = sedlbauer_ids,
536 .suspend = sedlbauer_suspend, 491 .suspend = sedlbauer_suspend,
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index 4e5c14c7240e..afcc2aeadb34 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -75,8 +75,8 @@ module_param(protocol, int, 0);
75 handler. 75 handler.
76*/ 76*/
77 77
78static void teles_cs_config(dev_link_t *link); 78static int teles_cs_config(struct pcmcia_device *link);
79static void teles_cs_release(dev_link_t *link); 79static void teles_cs_release(struct pcmcia_device *link);
80 80
81/* 81/*
82 The attach() and detach() entry points are used to create and destroy 82 The attach() and detach() entry points are used to create and destroy
@@ -89,10 +89,10 @@ static void teles_detach(struct pcmcia_device *p_dev);
89/* 89/*
90 A linked list of "instances" of the teles_cs device. Each actual 90 A linked list of "instances" of the teles_cs device. Each actual
91 PCMCIA card corresponds to one device instance, and is described 91 PCMCIA card corresponds to one device instance, and is described
92 by one dev_link_t structure (defined in ds.h). 92 by one struct pcmcia_device structure (defined in ds.h).
93 93
94 You may not want to use a linked list for this -- for example, the 94 You may not want to use a linked list for this -- for example, the
95 memory card driver uses an array of dev_link_t pointers, where minor 95 memory card driver uses an array of struct pcmcia_device pointers, where minor
96 device numbers are used to derive the corresponding array index. 96 device numbers are used to derive the corresponding array index.
97*/ 97*/
98 98
@@ -102,7 +102,7 @@ static void teles_detach(struct pcmcia_device *p_dev);
102 example, ethernet cards, modems). In other cases, there may be 102 example, ethernet cards, modems). In other cases, there may be
103 many actual or logical devices (SCSI adapters, memory cards with 103 many actual or logical devices (SCSI adapters, memory cards with
104 multiple partitions). The dev_node_t structures need to be kept 104 multiple partitions). The dev_node_t structures need to be kept
105 in a linked list starting at the 'dev' field of a dev_link_t 105 in a linked list starting at the 'dev' field of a struct pcmcia_device
106 structure. We allocate them in the card's private data structure, 106 structure. We allocate them in the card's private data structure,
107 because they generally shouldn't be allocated dynamically. 107 because they generally shouldn't be allocated dynamically.
108 In this case, we also provide a flag to indicate if a device is 108 In this case, we also provide a flag to indicate if a device is
@@ -112,7 +112,7 @@ static void teles_detach(struct pcmcia_device *p_dev);
112*/ 112*/
113 113
114typedef struct local_info_t { 114typedef struct local_info_t {
115 dev_link_t link; 115 struct pcmcia_device *p_dev;
116 dev_node_t node; 116 dev_node_t node;
117 int busy; 117 int busy;
118 int cardnr; 118 int cardnr;
@@ -130,9 +130,8 @@ typedef struct local_info_t {
130 130
131======================================================================*/ 131======================================================================*/
132 132
133static int teles_attach(struct pcmcia_device *p_dev) 133static int teles_probe(struct pcmcia_device *link)
134{ 134{
135 dev_link_t *link;
136 local_info_t *local; 135 local_info_t *local;
137 136
138 DEBUG(0, "teles_attach()\n"); 137 DEBUG(0, "teles_attach()\n");
@@ -142,7 +141,9 @@ static int teles_attach(struct pcmcia_device *p_dev)
142 if (!local) return -ENOMEM; 141 if (!local) return -ENOMEM;
143 memset(local, 0, sizeof(local_info_t)); 142 memset(local, 0, sizeof(local_info_t));
144 local->cardnr = -1; 143 local->cardnr = -1;
145 link = &local->link; link->priv = local; 144
145 local->p_dev = link;
146 link->priv = local;
146 147
147 /* Interrupt setup */ 148 /* Interrupt setup */
148 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 149 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
@@ -161,16 +162,9 @@ static int teles_attach(struct pcmcia_device *p_dev)
161 link->io.IOAddrLines = 5; 162 link->io.IOAddrLines = 5;
162 163
163 link->conf.Attributes = CONF_ENABLE_IRQ; 164 link->conf.Attributes = CONF_ENABLE_IRQ;
164 link->conf.Vcc = 50;
165 link->conf.IntType = INT_MEMORY_AND_IO; 165 link->conf.IntType = INT_MEMORY_AND_IO;
166 166
167 link->handle = p_dev; 167 return teles_cs_config(link);
168 p_dev->instance = link;
169
170 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
171 teles_cs_config(link);
172
173 return 0;
174} /* teles_attach */ 168} /* teles_attach */
175 169
176/*====================================================================== 170/*======================================================================
@@ -182,20 +176,16 @@ static int teles_attach(struct pcmcia_device *p_dev)
182 176
183======================================================================*/ 177======================================================================*/
184 178
185static void teles_detach(struct pcmcia_device *p_dev) 179static void teles_detach(struct pcmcia_device *link)
186{ 180{
187 dev_link_t *link = dev_to_instance(p_dev); 181 local_info_t *info = link->priv;
188 local_info_t *info = link->priv;
189
190 DEBUG(0, "teles_detach(0x%p)\n", link);
191 182
192 if (link->state & DEV_CONFIG) { 183 DEBUG(0, "teles_detach(0x%p)\n", link);
193 info->busy = 1;
194 teles_cs_release(link);
195 }
196 184
197 kfree(info); 185 info->busy = 1;
186 teles_cs_release(link);
198 187
188 kfree(info);
199} /* teles_detach */ 189} /* teles_detach */
200 190
201/*====================================================================== 191/*======================================================================
@@ -205,7 +195,7 @@ static void teles_detach(struct pcmcia_device *p_dev)
205 device available to the system. 195 device available to the system.
206 196
207======================================================================*/ 197======================================================================*/
208static int get_tuple(client_handle_t handle, tuple_t *tuple, 198static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
209 cisparse_t *parse) 199 cisparse_t *parse)
210{ 200{
211 int i = pcmcia_get_tuple_data(handle, tuple); 201 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -213,7 +203,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
213 return pcmcia_parse_tuple(handle, tuple, parse); 203 return pcmcia_parse_tuple(handle, tuple, parse);
214} 204}
215 205
216static int first_tuple(client_handle_t handle, tuple_t *tuple, 206static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
217 cisparse_t *parse) 207 cisparse_t *parse)
218{ 208{
219 int i = pcmcia_get_first_tuple(handle, tuple); 209 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -221,7 +211,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
221 return get_tuple(handle, tuple, parse); 211 return get_tuple(handle, tuple, parse);
222} 212}
223 213
224static int next_tuple(client_handle_t handle, tuple_t *tuple, 214static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
225 cisparse_t *parse) 215 cisparse_t *parse)
226{ 216{
227 int i = pcmcia_get_next_tuple(handle, tuple); 217 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -229,9 +219,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
229 return get_tuple(handle, tuple, parse); 219 return get_tuple(handle, tuple, parse);
230} 220}
231 221
232static void teles_cs_config(dev_link_t *link) 222static int teles_cs_config(struct pcmcia_device *link)
233{ 223{
234 client_handle_t handle;
235 tuple_t tuple; 224 tuple_t tuple;
236 cisparse_t parse; 225 cisparse_t parse;
237 local_info_t *dev; 226 local_info_t *dev;
@@ -241,7 +230,6 @@ static void teles_cs_config(dev_link_t *link)
241 IsdnCard_t icard; 230 IsdnCard_t icard;
242 231
243 DEBUG(0, "teles_config(0x%p)\n", link); 232 DEBUG(0, "teles_config(0x%p)\n", link);
244 handle = link->handle;
245 dev = link->priv; 233 dev = link->priv;
246 234
247 /* 235 /*
@@ -253,7 +241,7 @@ static void teles_cs_config(dev_link_t *link)
253 tuple.TupleDataMax = 255; 241 tuple.TupleDataMax = 255;
254 tuple.TupleOffset = 0; 242 tuple.TupleOffset = 0;
255 tuple.Attributes = 0; 243 tuple.Attributes = 0;
256 i = first_tuple(handle, &tuple, &parse); 244 i = first_tuple(link, &tuple, &parse);
257 if (i != CS_SUCCESS) { 245 if (i != CS_SUCCESS) {
258 last_fn = ParseTuple; 246 last_fn = ParseTuple;
259 goto cs_failed; 247 goto cs_failed;
@@ -261,32 +249,29 @@ static void teles_cs_config(dev_link_t *link)
261 link->conf.ConfigBase = parse.config.base; 249 link->conf.ConfigBase = parse.config.base;
262 link->conf.Present = parse.config.rmask[0]; 250 link->conf.Present = parse.config.rmask[0];
263 251
264 /* Configure card */
265 link->state |= DEV_CONFIG;
266
267 tuple.TupleData = (cisdata_t *)buf; 252 tuple.TupleData = (cisdata_t *)buf;
268 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 253 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
269 tuple.Attributes = 0; 254 tuple.Attributes = 0;
270 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 255 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
271 i = first_tuple(handle, &tuple, &parse); 256 i = first_tuple(link, &tuple, &parse);
272 while (i == CS_SUCCESS) { 257 while (i == CS_SUCCESS) {
273 if ( (cf->io.nwin > 0) && cf->io.win[0].base) { 258 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
274 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n"); 259 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
275 link->conf.ConfigIndex = cf->index; 260 link->conf.ConfigIndex = cf->index;
276 link->io.BasePort1 = cf->io.win[0].base; 261 link->io.BasePort1 = cf->io.win[0].base;
277 i = pcmcia_request_io(link->handle, &link->io); 262 i = pcmcia_request_io(link, &link->io);
278 if (i == CS_SUCCESS) break; 263 if (i == CS_SUCCESS) break;
279 } else { 264 } else {
280 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n"); 265 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
281 link->conf.ConfigIndex = cf->index; 266 link->conf.ConfigIndex = cf->index;
282 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) { 267 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
283 link->io.BasePort1 = j; 268 link->io.BasePort1 = j;
284 i = pcmcia_request_io(link->handle, &link->io); 269 i = pcmcia_request_io(link, &link->io);
285 if (i == CS_SUCCESS) break; 270 if (i == CS_SUCCESS) break;
286 } 271 }
287 break; 272 break;
288 } 273 }
289 i = next_tuple(handle, &tuple, &parse); 274 i = next_tuple(link, &tuple, &parse);
290 } 275 }
291 276
292 if (i != CS_SUCCESS) { 277 if (i != CS_SUCCESS) {
@@ -294,14 +279,14 @@ static void teles_cs_config(dev_link_t *link)
294 goto cs_failed; 279 goto cs_failed;
295 } 280 }
296 281
297 i = pcmcia_request_irq(link->handle, &link->irq); 282 i = pcmcia_request_irq(link, &link->irq);
298 if (i != CS_SUCCESS) { 283 if (i != CS_SUCCESS) {
299 link->irq.AssignedIRQ = 0; 284 link->irq.AssignedIRQ = 0;
300 last_fn = RequestIRQ; 285 last_fn = RequestIRQ;
301 goto cs_failed; 286 goto cs_failed;
302 } 287 }
303 288
304 i = pcmcia_request_configuration(link->handle, &link->conf); 289 i = pcmcia_request_configuration(link, &link->conf);
305 if (i != CS_SUCCESS) { 290 if (i != CS_SUCCESS) {
306 last_fn = RequestConfiguration; 291 last_fn = RequestConfiguration;
307 goto cs_failed; 292 goto cs_failed;
@@ -312,14 +297,11 @@ static void teles_cs_config(dev_link_t *link)
312 sprintf(dev->node.dev_name, "teles"); 297 sprintf(dev->node.dev_name, "teles");
313 dev->node.major = dev->node.minor = 0x0; 298 dev->node.major = dev->node.minor = 0x0;
314 299
315 link->dev = &dev->node; 300 link->dev_node = &dev->node;
316 301
317 /* Finally, report what we've done */ 302 /* Finally, report what we've done */
318 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 303 printk(KERN_INFO "%s: index 0x%02x:",
319 dev->node.dev_name, link->conf.ConfigIndex, 304 dev->node.dev_name, link->conf.ConfigIndex);
320 link->conf.Vcc/10, link->conf.Vcc%10);
321 if (link->conf.Vpp1)
322 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
323 if (link->conf.Attributes & CONF_ENABLE_IRQ) 305 if (link->conf.Attributes & CONF_ENABLE_IRQ)
324 printk(", irq %d", link->irq.AssignedIRQ); 306 printk(", irq %d", link->irq.AssignedIRQ);
325 if (link->io.NumPorts1) 307 if (link->io.NumPorts1)
@@ -330,8 +312,6 @@ static void teles_cs_config(dev_link_t *link)
330 link->io.BasePort2+link->io.NumPorts2-1); 312 link->io.BasePort2+link->io.NumPorts2-1);
331 printk("\n"); 313 printk("\n");
332 314
333 link->state &= ~DEV_CONFIG_PENDING;
334
335 icard.para[0] = link->irq.AssignedIRQ; 315 icard.para[0] = link->irq.AssignedIRQ;
336 icard.para[1] = link->io.BasePort1; 316 icard.para[1] = link->io.BasePort1;
337 icard.protocol = protocol; 317 icard.protocol = protocol;
@@ -342,13 +322,16 @@ static void teles_cs_config(dev_link_t *link)
342 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n", 322 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
343 i, link->io.BasePort1); 323 i, link->io.BasePort1);
344 teles_cs_release(link); 324 teles_cs_release(link);
345 } else 325 return -ENODEV;
346 ((local_info_t*)link->priv)->cardnr = i; 326 }
327
328 ((local_info_t*)link->priv)->cardnr = i;
329 return 0;
347 330
348 return;
349cs_failed: 331cs_failed:
350 cs_error(link->handle, last_fn, i); 332 cs_error(link, last_fn, i);
351 teles_cs_release(link); 333 teles_cs_release(link);
334 return -ENODEV;
352} /* teles_cs_config */ 335} /* teles_cs_config */
353 336
354/*====================================================================== 337/*======================================================================
@@ -359,7 +342,7 @@ cs_failed:
359 342
360======================================================================*/ 343======================================================================*/
361 344
362static void teles_cs_release(dev_link_t *link) 345static void teles_cs_release(struct pcmcia_device *link)
363{ 346{
364 local_info_t *local = link->priv; 347 local_info_t *local = link->priv;
365 348
@@ -371,39 +354,23 @@ static void teles_cs_release(dev_link_t *link)
371 HiSax_closecard(local->cardnr); 354 HiSax_closecard(local->cardnr);
372 } 355 }
373 } 356 }
374 /* Unlink the device chain */ 357
375 link->dev = NULL; 358 pcmcia_disable_device(link);
376
377 /* Don't bother checking to see if these succeed or not */
378 if (link->win)
379 pcmcia_release_window(link->win);
380 pcmcia_release_configuration(link->handle);
381 pcmcia_release_io(link->handle, &link->io);
382 pcmcia_release_irq(link->handle, &link->irq);
383 link->state &= ~DEV_CONFIG;
384} /* teles_cs_release */ 359} /* teles_cs_release */
385 360
386static int teles_suspend(struct pcmcia_device *p_dev) 361static int teles_suspend(struct pcmcia_device *link)
387{ 362{
388 dev_link_t *link = dev_to_instance(p_dev);
389 local_info_t *dev = link->priv; 363 local_info_t *dev = link->priv;
390 364
391 link->state |= DEV_SUSPEND;
392 dev->busy = 1; 365 dev->busy = 1;
393 if (link->state & DEV_CONFIG)
394 pcmcia_release_configuration(link->handle);
395 366
396 return 0; 367 return 0;
397} 368}
398 369
399static int teles_resume(struct pcmcia_device *p_dev) 370static int teles_resume(struct pcmcia_device *link)
400{ 371{
401 dev_link_t *link = dev_to_instance(p_dev);
402 local_info_t *dev = link->priv; 372 local_info_t *dev = link->priv;
403 373
404 link->state &= ~DEV_SUSPEND;
405 if (link->state & DEV_CONFIG)
406 pcmcia_request_configuration(link->handle, &link->conf);
407 dev->busy = 0; 374 dev->busy = 0;
408 375
409 return 0; 376 return 0;
@@ -421,7 +388,7 @@ static struct pcmcia_driver teles_cs_driver = {
421 .drv = { 388 .drv = {
422 .name = "teles_cs", 389 .name = "teles_cs",
423 }, 390 },
424 .probe = teles_attach, 391 .probe = teles_probe,
425 .remove = teles_detach, 392 .remove = teles_detach,
426 .id_table = teles_ids, 393 .id_table = teles_ids,
427 .suspend = teles_suspend, 394 .suspend = teles_suspend,
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index 8bbc751a6021..d27f4129afd3 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -54,7 +54,7 @@ static const int debug = 0;
54#define MAX_PCMCIA_ADDR 0x4000000 54#define MAX_PCMCIA_ADDR 0x4000000
55 55
56struct pcmciamtd_dev { 56struct pcmciamtd_dev {
57 dev_link_t link; /* PCMCIA link */ 57 struct pcmcia_device *p_dev;
58 dev_node_t node; /* device node */ 58 dev_node_t node; /* device node */
59 caddr_t win_base; /* ioremapped address of PCMCIA window */ 59 caddr_t win_base; /* ioremapped address of PCMCIA window */
60 unsigned int win_size; /* size of window */ 60 unsigned int win_size; /* size of window */
@@ -111,8 +111,8 @@ static caddr_t remap_window(struct map_info *map, unsigned long to)
111 memreq_t mrq; 111 memreq_t mrq;
112 int ret; 112 int ret;
113 113
114 if(!(dev->link.state & DEV_PRESENT)) { 114 if (!pcmcia_dev_present(dev->p_dev)) {
115 DEBUG(1, "device removed state = 0x%4.4X", dev->link.state); 115 DEBUG(1, "device removed");
116 return 0; 116 return 0;
117 } 117 }
118 118
@@ -122,7 +122,7 @@ static caddr_t remap_window(struct map_info *map, unsigned long to)
122 dev->offset, mrq.CardOffset); 122 dev->offset, mrq.CardOffset);
123 mrq.Page = 0; 123 mrq.Page = 0;
124 if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) { 124 if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) {
125 cs_error(dev->link.handle, MapMemPage, ret); 125 cs_error(dev->p_dev, MapMemPage, ret);
126 return NULL; 126 return NULL;
127 } 127 }
128 dev->offset = mrq.CardOffset; 128 dev->offset = mrq.CardOffset;
@@ -238,7 +238,7 @@ static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const v
238 238
239/* read/write{8,16} copy_{from,to} routines with direct access */ 239/* read/write{8,16} copy_{from,to} routines with direct access */
240 240
241#define DEV_REMOVED(x) (!(*(u_int *)x->map_priv_1 & DEV_PRESENT)) 241#define DEV_REMOVED(x) (!(pcmcia_dev_present(((struct pcmciamtd_dev *)map->map_priv_1)->p_dev)))
242 242
243static map_word pcmcia_read8(struct map_info *map, unsigned long ofs) 243static map_word pcmcia_read8(struct map_info *map, unsigned long ofs)
244{ 244{
@@ -319,7 +319,7 @@ static void pcmcia_copy_to(struct map_info *map, unsigned long to, const void *f
319static void pcmciamtd_set_vpp(struct map_info *map, int on) 319static void pcmciamtd_set_vpp(struct map_info *map, int on)
320{ 320{
321 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; 321 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
322 dev_link_t *link = &dev->link; 322 struct pcmcia_device *link = dev->p_dev;
323 modconf_t mod; 323 modconf_t mod;
324 int ret; 324 int ret;
325 325
@@ -328,9 +328,9 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
328 mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0; 328 mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0;
329 329
330 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); 330 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
331 ret = pcmcia_modify_configuration(link->handle, &mod); 331 ret = pcmcia_modify_configuration(link, &mod);
332 if(ret != CS_SUCCESS) { 332 if(ret != CS_SUCCESS) {
333 cs_error(link->handle, ModifyConfiguration, ret); 333 cs_error(link, ModifyConfiguration, ret);
334 } 334 }
335} 335}
336 336
@@ -340,7 +340,7 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
340 * still open, this will be postponed until it is closed. 340 * still open, this will be postponed until it is closed.
341 */ 341 */
342 342
343static void pcmciamtd_release(dev_link_t *link) 343static void pcmciamtd_release(struct pcmcia_device *link)
344{ 344{
345 struct pcmciamtd_dev *dev = link->priv; 345 struct pcmciamtd_dev *dev = link->priv;
346 346
@@ -353,12 +353,11 @@ static void pcmciamtd_release(dev_link_t *link)
353 } 353 }
354 pcmcia_release_window(link->win); 354 pcmcia_release_window(link->win);
355 } 355 }
356 pcmcia_release_configuration(link->handle); 356 pcmcia_disable_device(link);
357 link->state &= ~DEV_CONFIG;
358} 357}
359 358
360 359
361static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_name) 360static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link, int *new_name)
362{ 361{
363 int rc; 362 int rc;
364 tuple_t tuple; 363 tuple_t tuple;
@@ -371,16 +370,16 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
371 tuple.TupleOffset = 0; 370 tuple.TupleOffset = 0;
372 tuple.DesiredTuple = RETURN_FIRST_TUPLE; 371 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
373 372
374 rc = pcmcia_get_first_tuple(link->handle, &tuple); 373 rc = pcmcia_get_first_tuple(link, &tuple);
375 while(rc == CS_SUCCESS) { 374 while(rc == CS_SUCCESS) {
376 rc = pcmcia_get_tuple_data(link->handle, &tuple); 375 rc = pcmcia_get_tuple_data(link, &tuple);
377 if(rc != CS_SUCCESS) { 376 if(rc != CS_SUCCESS) {
378 cs_error(link->handle, GetTupleData, rc); 377 cs_error(link, GetTupleData, rc);
379 break; 378 break;
380 } 379 }
381 rc = pcmcia_parse_tuple(link->handle, &tuple, &parse); 380 rc = pcmcia_parse_tuple(link, &tuple, &parse);
382 if(rc != CS_SUCCESS) { 381 if(rc != CS_SUCCESS) {
383 cs_error(link->handle, ParseTuple, rc); 382 cs_error(link, ParseTuple, rc);
384 break; 383 break;
385 } 384 }
386 385
@@ -451,7 +450,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
451 DEBUG(2, "Unknown tuple code %d", tuple.TupleCode); 450 DEBUG(2, "Unknown tuple code %d", tuple.TupleCode);
452 } 451 }
453 452
454 rc = pcmcia_get_next_tuple(link->handle, &tuple); 453 rc = pcmcia_get_next_tuple(link, &tuple);
455 } 454 }
456 if(!dev->pcmcia_map.size) 455 if(!dev->pcmcia_map.size)
457 dev->pcmcia_map.size = MAX_PCMCIA_ADDR; 456 dev->pcmcia_map.size = MAX_PCMCIA_ADDR;
@@ -488,7 +487,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
488#define CS_CHECK(fn, ret) \ 487#define CS_CHECK(fn, ret) \
489do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 488do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
490 489
491static void pcmciamtd_config(dev_link_t *link) 490static int pcmciamtd_config(struct pcmcia_device *link)
492{ 491{
493 struct pcmciamtd_dev *dev = link->priv; 492 struct pcmciamtd_dev *dev = link->priv;
494 struct mtd_info *mtd = NULL; 493 struct mtd_info *mtd = NULL;
@@ -504,13 +503,10 @@ static void pcmciamtd_config(dev_link_t *link)
504 503
505 DEBUG(3, "link=0x%p", link); 504 DEBUG(3, "link=0x%p", link);
506 505
507 /* Configure card */
508 link->state |= DEV_CONFIG;
509
510 DEBUG(2, "Validating CIS"); 506 DEBUG(2, "Validating CIS");
511 ret = pcmcia_validate_cis(link->handle, &cisinfo); 507 ret = pcmcia_validate_cis(link, &cisinfo);
512 if(ret != CS_SUCCESS) { 508 if(ret != CS_SUCCESS) {
513 cs_error(link->handle, GetTupleData, ret); 509 cs_error(link, GetTupleData, ret);
514 } else { 510 } else {
515 DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains); 511 DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains);
516 } 512 }
@@ -538,7 +534,7 @@ static void pcmciamtd_config(dev_link_t *link)
538 req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16; 534 req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16;
539 req.Base = 0; 535 req.Base = 0;
540 req.AccessSpeed = mem_speed; 536 req.AccessSpeed = mem_speed;
541 link->win = (window_handle_t)link->handle; 537 link->win = (window_handle_t)link;
542 req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR; 538 req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR;
543 dev->win_size = 0; 539 dev->win_size = 0;
544 540
@@ -546,7 +542,7 @@ static void pcmciamtd_config(dev_link_t *link)
546 int ret; 542 int ret;
547 DEBUG(2, "requesting window with size = %dKiB memspeed = %d", 543 DEBUG(2, "requesting window with size = %dKiB memspeed = %d",
548 req.Size >> 10, req.AccessSpeed); 544 req.Size >> 10, req.AccessSpeed);
549 ret = pcmcia_request_window(&link->handle, &req, &link->win); 545 ret = pcmcia_request_window(&link, &req, &link->win);
550 DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); 546 DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size);
551 if(ret) { 547 if(ret) {
552 req.Size >>= 1; 548 req.Size >>= 1;
@@ -562,19 +558,19 @@ static void pcmciamtd_config(dev_link_t *link)
562 if(!dev->win_size) { 558 if(!dev->win_size) {
563 err("Cant allocate memory window"); 559 err("Cant allocate memory window");
564 pcmciamtd_release(link); 560 pcmciamtd_release(link);
565 return; 561 return -ENODEV;
566 } 562 }
567 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); 563 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10);
568 564
569 /* Get write protect status */ 565 /* Get write protect status */
570 CS_CHECK(GetStatus, pcmcia_get_status(link->handle, &status)); 566 CS_CHECK(GetStatus, pcmcia_get_status(link, &status));
571 DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx", 567 DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx",
572 status.CardState, (unsigned long)link->win); 568 status.CardState, (unsigned long)link->win);
573 dev->win_base = ioremap(req.Base, req.Size); 569 dev->win_base = ioremap(req.Base, req.Size);
574 if(!dev->win_base) { 570 if(!dev->win_base) {
575 err("ioremap(%lu, %u) failed", req.Base, req.Size); 571 err("ioremap(%lu, %u) failed", req.Base, req.Size);
576 pcmciamtd_release(link); 572 pcmciamtd_release(link);
577 return; 573 return -ENODEV;
578 } 574 }
579 DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x", 575 DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x",
580 dev, req.Base, dev->win_base, req.Size); 576 dev, req.Base, dev->win_base, req.Size);
@@ -584,17 +580,14 @@ static void pcmciamtd_config(dev_link_t *link)
584 dev->pcmcia_map.map_priv_2 = (unsigned long)link->win; 580 dev->pcmcia_map.map_priv_2 = (unsigned long)link->win;
585 581
586 DEBUG(2, "Getting configuration"); 582 DEBUG(2, "Getting configuration");
587 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link->handle, &t)); 583 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &t));
588 DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2); 584 DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2);
589 dev->vpp = (vpp) ? vpp : t.Vpp1; 585 dev->vpp = (vpp) ? vpp : t.Vpp1;
590 link->conf.Attributes = 0; 586 link->conf.Attributes = 0;
591 link->conf.Vcc = t.Vcc;
592 if(setvpp == 2) { 587 if(setvpp == 2) {
593 link->conf.Vpp1 = dev->vpp; 588 link->conf.Vpp = dev->vpp;
594 link->conf.Vpp2 = dev->vpp;
595 } else { 589 } else {
596 link->conf.Vpp1 = 0; 590 link->conf.Vpp = 0;
597 link->conf.Vpp2 = 0;
598 } 591 }
599 592
600 link->conf.IntType = INT_MEMORY; 593 link->conf.IntType = INT_MEMORY;
@@ -606,9 +599,10 @@ static void pcmciamtd_config(dev_link_t *link)
606 link->conf.ConfigIndex = 0; 599 link->conf.ConfigIndex = 0;
607 link->conf.Present = t.Present; 600 link->conf.Present = t.Present;
608 DEBUG(2, "Setting Configuration"); 601 DEBUG(2, "Setting Configuration");
609 ret = pcmcia_request_configuration(link->handle, &link->conf); 602 ret = pcmcia_request_configuration(link, &link->conf);
610 if(ret != CS_SUCCESS) { 603 if(ret != CS_SUCCESS) {
611 cs_error(link->handle, RequestConfiguration, ret); 604 cs_error(link, RequestConfiguration, ret);
605 return -ENODEV;
612 } 606 }
613 607
614 if(mem_type == 1) { 608 if(mem_type == 1) {
@@ -629,7 +623,7 @@ static void pcmciamtd_config(dev_link_t *link)
629 if(!mtd) { 623 if(!mtd) {
630 DEBUG(1, "Cant find an MTD"); 624 DEBUG(1, "Cant find an MTD");
631 pcmciamtd_release(link); 625 pcmciamtd_release(link);
632 return; 626 return -ENODEV;
633 } 627 }
634 628
635 dev->mtd_info = mtd; 629 dev->mtd_info = mtd;
@@ -654,7 +648,6 @@ static void pcmciamtd_config(dev_link_t *link)
654 use the faster non-remapping read/write functions */ 648 use the faster non-remapping read/write functions */
655 if(mtd->size <= dev->win_size) { 649 if(mtd->size <= dev->win_size) {
656 DEBUG(1, "Using non remapping memory functions"); 650 DEBUG(1, "Using non remapping memory functions");
657 dev->pcmcia_map.map_priv_1 = (unsigned long)&(dev->link.state);
658 dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base; 651 dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base;
659 if (dev->pcmcia_map.bankwidth == 1) { 652 if (dev->pcmcia_map.bankwidth == 1) {
660 dev->pcmcia_map.read = pcmcia_read8; 653 dev->pcmcia_map.read = pcmcia_read8;
@@ -672,19 +665,18 @@ static void pcmciamtd_config(dev_link_t *link)
672 dev->mtd_info = NULL; 665 dev->mtd_info = NULL;
673 err("Couldnt register MTD device"); 666 err("Couldnt register MTD device");
674 pcmciamtd_release(link); 667 pcmciamtd_release(link);
675 return; 668 return -ENODEV;
676 } 669 }
677 snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index); 670 snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index);
678 info("mtd%d: %s", mtd->index, mtd->name); 671 info("mtd%d: %s", mtd->index, mtd->name);
679 link->state &= ~DEV_CONFIG_PENDING; 672 link->dev_node = &dev->node;
680 link->dev = &dev->node; 673 return 0;
681 return;
682 674
683 cs_failed: 675 cs_failed:
684 cs_error(link->handle, last_fn, last_ret); 676 cs_error(link, last_fn, last_ret);
685 err("CS Error, exiting"); 677 err("CS Error, exiting");
686 pcmciamtd_release(link); 678 pcmciamtd_release(link);
687 return; 679 return -ENODEV;
688} 680}
689 681
690 682
@@ -713,21 +705,18 @@ static int pcmciamtd_resume(struct pcmcia_device *dev)
713 * when the device is released. 705 * when the device is released.
714 */ 706 */
715 707
716static void pcmciamtd_detach(struct pcmcia_device *p_dev) 708static void pcmciamtd_detach(struct pcmcia_device *link)
717{ 709{
718 dev_link_t *link = dev_to_instance(p_dev); 710 struct pcmciamtd_dev *dev = link->priv;
719 711
720 DEBUG(3, "link=0x%p", link); 712 DEBUG(3, "link=0x%p", link);
721 713
722 if(link->state & DEV_CONFIG) { 714 if(dev->mtd_info) {
723 struct pcmciamtd_dev *dev = link->priv; 715 del_mtd_device(dev->mtd_info);
724 if(dev->mtd_info) { 716 info("mtd%d: Removed", dev->mtd_info->index);
725 del_mtd_device(dev->mtd_info);
726 info("mtd%d: Removed", dev->mtd_info->index);
727 }
728
729 pcmciamtd_release(link);
730 } 717 }
718
719 pcmciamtd_release(link);
731} 720}
732 721
733 722
@@ -736,10 +725,9 @@ static void pcmciamtd_detach(struct pcmcia_device *p_dev)
736 * with Card Services. 725 * with Card Services.
737 */ 726 */
738 727
739static int pcmciamtd_attach(struct pcmcia_device *p_dev) 728static int pcmciamtd_probe(struct pcmcia_device *link)
740{ 729{
741 struct pcmciamtd_dev *dev; 730 struct pcmciamtd_dev *dev;
742 dev_link_t *link;
743 731
744 /* Create new memory card device */ 732 /* Create new memory card device */
745 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 733 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
@@ -747,20 +735,13 @@ static int pcmciamtd_attach(struct pcmcia_device *p_dev)
747 DEBUG(1, "dev=0x%p", dev); 735 DEBUG(1, "dev=0x%p", dev);
748 736
749 memset(dev, 0, sizeof(*dev)); 737 memset(dev, 0, sizeof(*dev));
750 link = &dev->link; 738 dev->p_dev = link;
751 link->priv = dev; 739 link->priv = dev;
752 740
753 link->conf.Attributes = 0; 741 link->conf.Attributes = 0;
754 link->conf.IntType = INT_MEMORY; 742 link->conf.IntType = INT_MEMORY;
755 743
756 link->next = NULL; 744 return pcmciamtd_config(link);
757 link->handle = p_dev;
758 p_dev->instance = link;
759
760 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
761 pcmciamtd_config(link);
762
763 return 0;
764} 745}
765 746
766static struct pcmcia_device_id pcmciamtd_ids[] = { 747static struct pcmcia_device_id pcmciamtd_ids[] = {
@@ -794,7 +775,7 @@ static struct pcmcia_driver pcmciamtd_driver = {
794 .drv = { 775 .drv = {
795 .name = "pcmciamtd" 776 .name = "pcmciamtd"
796 }, 777 },
797 .probe = pcmciamtd_attach, 778 .probe = pcmciamtd_probe,
798 .remove = pcmciamtd_detach, 779 .remove = pcmciamtd_detach,
799 .owner = THIS_MODULE, 780 .owner = THIS_MODULE,
800 .id_table = pcmciamtd_ids, 781 .id_table = pcmciamtd_ids,
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index ce90becb8bdf..fab93360f017 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -204,7 +204,7 @@ enum Window4 { /* Window 4: Xcvr/media bits. */
204#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */ 204#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
205 205
206struct el3_private { 206struct el3_private {
207 dev_link_t link; 207 struct pcmcia_device *p_dev;
208 dev_node_t node; 208 dev_node_t node;
209 struct net_device_stats stats; 209 struct net_device_stats stats;
210 u16 advertising, partner; /* NWay media advertisement */ 210 u16 advertising, partner; /* NWay media advertisement */
@@ -225,8 +225,8 @@ static char mii_preamble_required = 0;
225 225
226/* Index of functions. */ 226/* Index of functions. */
227 227
228static void tc574_config(dev_link_t *link); 228static int tc574_config(struct pcmcia_device *link);
229static void tc574_release(dev_link_t *link); 229static void tc574_release(struct pcmcia_device *link);
230 230
231static void mdio_sync(kio_addr_t ioaddr, int bits); 231static void mdio_sync(kio_addr_t ioaddr, int bits);
232static int mdio_read(kio_addr_t ioaddr, int phy_id, int location); 232static int mdio_read(kio_addr_t ioaddr, int phy_id, int location);
@@ -256,10 +256,9 @@ static void tc574_detach(struct pcmcia_device *p_dev);
256 with Card Services. 256 with Card Services.
257*/ 257*/
258 258
259static int tc574_attach(struct pcmcia_device *p_dev) 259static int tc574_probe(struct pcmcia_device *link)
260{ 260{
261 struct el3_private *lp; 261 struct el3_private *lp;
262 dev_link_t *link;
263 struct net_device *dev; 262 struct net_device *dev;
264 263
265 DEBUG(0, "3c574_attach()\n"); 264 DEBUG(0, "3c574_attach()\n");
@@ -269,8 +268,8 @@ static int tc574_attach(struct pcmcia_device *p_dev)
269 if (!dev) 268 if (!dev)
270 return -ENOMEM; 269 return -ENOMEM;
271 lp = netdev_priv(dev); 270 lp = netdev_priv(dev);
272 link = &lp->link;
273 link->priv = dev; 271 link->priv = dev;
272 lp->p_dev = link;
274 273
275 spin_lock_init(&lp->window_lock); 274 spin_lock_init(&lp->window_lock);
276 link->io.NumPorts1 = 32; 275 link->io.NumPorts1 = 32;
@@ -280,7 +279,6 @@ static int tc574_attach(struct pcmcia_device *p_dev)
280 link->irq.Handler = &el3_interrupt; 279 link->irq.Handler = &el3_interrupt;
281 link->irq.Instance = dev; 280 link->irq.Instance = dev;
282 link->conf.Attributes = CONF_ENABLE_IRQ; 281 link->conf.Attributes = CONF_ENABLE_IRQ;
283 link->conf.Vcc = 50;
284 link->conf.IntType = INT_MEMORY_AND_IO; 282 link->conf.IntType = INT_MEMORY_AND_IO;
285 link->conf.ConfigIndex = 1; 283 link->conf.ConfigIndex = 1;
286 link->conf.Present = PRESENT_OPTION; 284 link->conf.Present = PRESENT_OPTION;
@@ -298,13 +296,7 @@ static int tc574_attach(struct pcmcia_device *p_dev)
298 dev->watchdog_timeo = TX_TIMEOUT; 296 dev->watchdog_timeo = TX_TIMEOUT;
299#endif 297#endif
300 298
301 link->handle = p_dev; 299 return tc574_config(link);
302 p_dev->instance = link;
303
304 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
305 tc574_config(link);
306
307 return 0;
308} /* tc574_attach */ 300} /* tc574_attach */
309 301
310/* 302/*
@@ -316,18 +308,16 @@ static int tc574_attach(struct pcmcia_device *p_dev)
316 308
317*/ 309*/
318 310
319static void tc574_detach(struct pcmcia_device *p_dev) 311static void tc574_detach(struct pcmcia_device *link)
320{ 312{
321 dev_link_t *link = dev_to_instance(p_dev);
322 struct net_device *dev = link->priv; 313 struct net_device *dev = link->priv;
323 314
324 DEBUG(0, "3c574_detach(0x%p)\n", link); 315 DEBUG(0, "3c574_detach(0x%p)\n", link);
325 316
326 if (link->dev) 317 if (link->dev_node)
327 unregister_netdev(dev); 318 unregister_netdev(dev);
328 319
329 if (link->state & DEV_CONFIG) 320 tc574_release(link);
330 tc574_release(link);
331 321
332 free_netdev(dev); 322 free_netdev(dev);
333} /* tc574_detach */ 323} /* tc574_detach */
@@ -343,9 +333,8 @@ static void tc574_detach(struct pcmcia_device *p_dev)
343 333
344static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 334static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
345 335
346static void tc574_config(dev_link_t *link) 336static int tc574_config(struct pcmcia_device *link)
347{ 337{
348 client_handle_t handle = link->handle;
349 struct net_device *dev = link->priv; 338 struct net_device *dev = link->priv;
350 struct el3_private *lp = netdev_priv(dev); 339 struct el3_private *lp = netdev_priv(dev);
351 tuple_t tuple; 340 tuple_t tuple;
@@ -363,30 +352,27 @@ static void tc574_config(dev_link_t *link)
363 352
364 tuple.Attributes = 0; 353 tuple.Attributes = 0;
365 tuple.DesiredTuple = CISTPL_CONFIG; 354 tuple.DesiredTuple = CISTPL_CONFIG;
366 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 355 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
367 tuple.TupleData = (cisdata_t *)buf; 356 tuple.TupleData = (cisdata_t *)buf;
368 tuple.TupleDataMax = 64; 357 tuple.TupleDataMax = 64;
369 tuple.TupleOffset = 0; 358 tuple.TupleOffset = 0;
370 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 359 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
371 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 360 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
372 link->conf.ConfigBase = parse.config.base; 361 link->conf.ConfigBase = parse.config.base;
373 link->conf.Present = parse.config.rmask[0]; 362 link->conf.Present = parse.config.rmask[0];
374 363
375 /* Configure card */
376 link->state |= DEV_CONFIG;
377
378 link->io.IOAddrLines = 16; 364 link->io.IOAddrLines = 16;
379 for (i = j = 0; j < 0x400; j += 0x20) { 365 for (i = j = 0; j < 0x400; j += 0x20) {
380 link->io.BasePort1 = j ^ 0x300; 366 link->io.BasePort1 = j ^ 0x300;
381 i = pcmcia_request_io(link->handle, &link->io); 367 i = pcmcia_request_io(link, &link->io);
382 if (i == CS_SUCCESS) break; 368 if (i == CS_SUCCESS) break;
383 } 369 }
384 if (i != CS_SUCCESS) { 370 if (i != CS_SUCCESS) {
385 cs_error(link->handle, RequestIO, i); 371 cs_error(link, RequestIO, i);
386 goto failed; 372 goto failed;
387 } 373 }
388 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 374 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
389 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 375 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
390 376
391 dev->irq = link->irq.AssignedIRQ; 377 dev->irq = link->irq.AssignedIRQ;
392 dev->base_addr = link->io.BasePort1; 378 dev->base_addr = link->io.BasePort1;
@@ -397,8 +383,8 @@ static void tc574_config(dev_link_t *link)
397 the hardware address. The future products may include a modem chip 383 the hardware address. The future products may include a modem chip
398 and put the address in the CIS. */ 384 and put the address in the CIS. */
399 tuple.DesiredTuple = 0x88; 385 tuple.DesiredTuple = 0x88;
400 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { 386 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
401 pcmcia_get_tuple_data(handle, &tuple); 387 pcmcia_get_tuple_data(link, &tuple);
402 for (i = 0; i < 3; i++) 388 for (i = 0; i < 3; i++)
403 phys_addr[i] = htons(buf[i]); 389 phys_addr[i] = htons(buf[i]);
404 } else { 390 } else {
@@ -412,9 +398,9 @@ static void tc574_config(dev_link_t *link)
412 } 398 }
413 } 399 }
414 tuple.DesiredTuple = CISTPL_VERS_1; 400 tuple.DesiredTuple = CISTPL_VERS_1;
415 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS && 401 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS &&
416 pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS && 402 pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS &&
417 pcmcia_parse_tuple(handle, &tuple, &parse) == CS_SUCCESS) { 403 pcmcia_parse_tuple(link, &tuple, &parse) == CS_SUCCESS) {
418 cardname = parse.version_1.str + parse.version_1.ofs[1]; 404 cardname = parse.version_1.str + parse.version_1.ofs[1];
419 } else 405 } else
420 cardname = "3Com 3c574"; 406 cardname = "3Com 3c574";
@@ -473,13 +459,12 @@ static void tc574_config(dev_link_t *link)
473 } 459 }
474 } 460 }
475 461
476 link->state &= ~DEV_CONFIG_PENDING; 462 link->dev_node = &lp->node;
477 link->dev = &lp->node; 463 SET_NETDEV_DEV(dev, &handle_to_dev(link));
478 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
479 464
480 if (register_netdev(dev) != 0) { 465 if (register_netdev(dev) != 0) {
481 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n"); 466 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n");
482 link->dev = NULL; 467 link->dev_node = NULL;
483 goto failed; 468 goto failed;
484 } 469 }
485 470
@@ -493,13 +478,13 @@ static void tc574_config(dev_link_t *link)
493 8 << config.u.ram_size, ram_split[config.u.ram_split], 478 8 << config.u.ram_size, ram_split[config.u.ram_split],
494 config.u.autoselect ? "autoselect " : ""); 479 config.u.autoselect ? "autoselect " : "");
495 480
496 return; 481 return 0;
497 482
498cs_failed: 483cs_failed:
499 cs_error(link->handle, last_fn, last_ret); 484 cs_error(link, last_fn, last_ret);
500failed: 485failed:
501 tc574_release(link); 486 tc574_release(link);
502 return; 487 return -ENODEV;
503 488
504} /* tc574_config */ 489} /* tc574_config */
505 490
@@ -509,44 +494,28 @@ failed:
509 still open, this will be postponed until it is closed. 494 still open, this will be postponed until it is closed.
510*/ 495*/
511 496
512static void tc574_release(dev_link_t *link) 497static void tc574_release(struct pcmcia_device *link)
513{ 498{
514 DEBUG(0, "3c574_release(0x%p)\n", link); 499 pcmcia_disable_device(link);
515
516 pcmcia_release_configuration(link->handle);
517 pcmcia_release_io(link->handle, &link->io);
518 pcmcia_release_irq(link->handle, &link->irq);
519
520 link->state &= ~DEV_CONFIG;
521} 500}
522 501
523static int tc574_suspend(struct pcmcia_device *p_dev) 502static int tc574_suspend(struct pcmcia_device *link)
524{ 503{
525 dev_link_t *link = dev_to_instance(p_dev);
526 struct net_device *dev = link->priv; 504 struct net_device *dev = link->priv;
527 505
528 link->state |= DEV_SUSPEND; 506 if (link->open)
529 if (link->state & DEV_CONFIG) { 507 netif_device_detach(dev);
530 if (link->open)
531 netif_device_detach(dev);
532 pcmcia_release_configuration(link->handle);
533 }
534 508
535 return 0; 509 return 0;
536} 510}
537 511
538static int tc574_resume(struct pcmcia_device *p_dev) 512static int tc574_resume(struct pcmcia_device *link)
539{ 513{
540 dev_link_t *link = dev_to_instance(p_dev);
541 struct net_device *dev = link->priv; 514 struct net_device *dev = link->priv;
542 515
543 link->state &= ~DEV_SUSPEND; 516 if (link->open) {
544 if (link->state & DEV_CONFIG) { 517 tc574_reset(dev);
545 pcmcia_request_configuration(link->handle, &link->conf); 518 netif_device_attach(dev);
546 if (link->open) {
547 tc574_reset(dev);
548 netif_device_attach(dev);
549 }
550 } 519 }
551 520
552 return 0; 521 return 0;
@@ -757,9 +726,9 @@ static void tc574_reset(struct net_device *dev)
757static int el3_open(struct net_device *dev) 726static int el3_open(struct net_device *dev)
758{ 727{
759 struct el3_private *lp = netdev_priv(dev); 728 struct el3_private *lp = netdev_priv(dev);
760 dev_link_t *link = &lp->link; 729 struct pcmcia_device *link = lp->p_dev;
761 730
762 if (!DEV_OK(link)) 731 if (!pcmcia_dev_present(link))
763 return -ENODEV; 732 return -ENODEV;
764 733
765 link->open++; 734 link->open++;
@@ -1203,11 +1172,11 @@ static int el3_close(struct net_device *dev)
1203{ 1172{
1204 kio_addr_t ioaddr = dev->base_addr; 1173 kio_addr_t ioaddr = dev->base_addr;
1205 struct el3_private *lp = netdev_priv(dev); 1174 struct el3_private *lp = netdev_priv(dev);
1206 dev_link_t *link = &lp->link; 1175 struct pcmcia_device *link = lp->p_dev;
1207 1176
1208 DEBUG(2, "%s: shutting down ethercard.\n", dev->name); 1177 DEBUG(2, "%s: shutting down ethercard.\n", dev->name);
1209 1178
1210 if (DEV_OK(link)) { 1179 if (pcmcia_dev_present(link)) {
1211 unsigned long flags; 1180 unsigned long flags;
1212 1181
1213 /* Turn off statistics ASAP. We update lp->stats below. */ 1182 /* Turn off statistics ASAP. We update lp->stats below. */
@@ -1246,7 +1215,7 @@ static struct pcmcia_driver tc574_driver = {
1246 .drv = { 1215 .drv = {
1247 .name = "3c574_cs", 1216 .name = "3c574_cs",
1248 }, 1217 },
1249 .probe = tc574_attach, 1218 .probe = tc574_probe,
1250 .remove = tc574_detach, 1219 .remove = tc574_detach,
1251 .id_table = tc574_ids, 1220 .id_table = tc574_ids,
1252 .suspend = tc574_suspend, 1221 .suspend = tc574_suspend,
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 3dba50849da7..875a0fe251e7 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -105,7 +105,7 @@ enum RxFilter {
105#define TX_TIMEOUT ((400*HZ)/1000) 105#define TX_TIMEOUT ((400*HZ)/1000)
106 106
107struct el3_private { 107struct el3_private {
108 dev_link_t link; 108 struct pcmcia_device *p_dev;
109 dev_node_t node; 109 dev_node_t node;
110 struct net_device_stats stats; 110 struct net_device_stats stats;
111 /* For transceiver monitoring */ 111 /* For transceiver monitoring */
@@ -142,8 +142,8 @@ DRV_NAME ".c " DRV_VERSION " 2001/10/13 00:08:50 (David Hinds)";
142 142
143/*====================================================================*/ 143/*====================================================================*/
144 144
145static void tc589_config(dev_link_t *link); 145static int tc589_config(struct pcmcia_device *link);
146static void tc589_release(dev_link_t *link); 146static void tc589_release(struct pcmcia_device *link);
147 147
148static u16 read_eeprom(kio_addr_t ioaddr, int index); 148static u16 read_eeprom(kio_addr_t ioaddr, int index);
149static void tc589_reset(struct net_device *dev); 149static void tc589_reset(struct net_device *dev);
@@ -170,10 +170,9 @@ static void tc589_detach(struct pcmcia_device *p_dev);
170 170
171======================================================================*/ 171======================================================================*/
172 172
173static int tc589_attach(struct pcmcia_device *p_dev) 173static int tc589_probe(struct pcmcia_device *link)
174{ 174{
175 struct el3_private *lp; 175 struct el3_private *lp;
176 dev_link_t *link;
177 struct net_device *dev; 176 struct net_device *dev;
178 177
179 DEBUG(0, "3c589_attach()\n"); 178 DEBUG(0, "3c589_attach()\n");
@@ -183,8 +182,8 @@ static int tc589_attach(struct pcmcia_device *p_dev)
183 if (!dev) 182 if (!dev)
184 return -ENOMEM; 183 return -ENOMEM;
185 lp = netdev_priv(dev); 184 lp = netdev_priv(dev);
186 link = &lp->link;
187 link->priv = dev; 185 link->priv = dev;
186 lp->p_dev = link;
188 187
189 spin_lock_init(&lp->lock); 188 spin_lock_init(&lp->lock);
190 link->io.NumPorts1 = 16; 189 link->io.NumPorts1 = 16;
@@ -194,7 +193,6 @@ static int tc589_attach(struct pcmcia_device *p_dev)
194 link->irq.Handler = &el3_interrupt; 193 link->irq.Handler = &el3_interrupt;
195 link->irq.Instance = dev; 194 link->irq.Instance = dev;
196 link->conf.Attributes = CONF_ENABLE_IRQ; 195 link->conf.Attributes = CONF_ENABLE_IRQ;
197 link->conf.Vcc = 50;
198 link->conf.IntType = INT_MEMORY_AND_IO; 196 link->conf.IntType = INT_MEMORY_AND_IO;
199 link->conf.ConfigIndex = 1; 197 link->conf.ConfigIndex = 1;
200 link->conf.Present = PRESENT_OPTION; 198 link->conf.Present = PRESENT_OPTION;
@@ -213,13 +211,7 @@ static int tc589_attach(struct pcmcia_device *p_dev)
213#endif 211#endif
214 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 212 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
215 213
216 link->handle = p_dev; 214 return tc589_config(link);
217 p_dev->instance = link;
218
219 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
220 tc589_config(link);
221
222 return 0;
223} /* tc589_attach */ 215} /* tc589_attach */
224 216
225/*====================================================================== 217/*======================================================================
@@ -231,18 +223,16 @@ static int tc589_attach(struct pcmcia_device *p_dev)
231 223
232======================================================================*/ 224======================================================================*/
233 225
234static void tc589_detach(struct pcmcia_device *p_dev) 226static void tc589_detach(struct pcmcia_device *link)
235{ 227{
236 dev_link_t *link = dev_to_instance(p_dev);
237 struct net_device *dev = link->priv; 228 struct net_device *dev = link->priv;
238 229
239 DEBUG(0, "3c589_detach(0x%p)\n", link); 230 DEBUG(0, "3c589_detach(0x%p)\n", link);
240 231
241 if (link->dev) 232 if (link->dev_node)
242 unregister_netdev(dev); 233 unregister_netdev(dev);
243 234
244 if (link->state & DEV_CONFIG) 235 tc589_release(link);
245 tc589_release(link);
246 236
247 free_netdev(dev); 237 free_netdev(dev);
248} /* tc589_detach */ 238} /* tc589_detach */
@@ -258,9 +248,8 @@ static void tc589_detach(struct pcmcia_device *p_dev)
258#define CS_CHECK(fn, ret) \ 248#define CS_CHECK(fn, ret) \
259do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 249do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
260 250
261static void tc589_config(dev_link_t *link) 251static int tc589_config(struct pcmcia_device *link)
262{ 252{
263 client_handle_t handle = link->handle;
264 struct net_device *dev = link->priv; 253 struct net_device *dev = link->priv;
265 struct el3_private *lp = netdev_priv(dev); 254 struct el3_private *lp = netdev_priv(dev);
266 tuple_t tuple; 255 tuple_t tuple;
@@ -275,43 +264,40 @@ static void tc589_config(dev_link_t *link)
275 phys_addr = (u16 *)dev->dev_addr; 264 phys_addr = (u16 *)dev->dev_addr;
276 tuple.Attributes = 0; 265 tuple.Attributes = 0;
277 tuple.DesiredTuple = CISTPL_CONFIG; 266 tuple.DesiredTuple = CISTPL_CONFIG;
278 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 267 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
279 tuple.TupleData = (cisdata_t *)buf; 268 tuple.TupleData = (cisdata_t *)buf;
280 tuple.TupleDataMax = sizeof(buf); 269 tuple.TupleDataMax = sizeof(buf);
281 tuple.TupleOffset = 0; 270 tuple.TupleOffset = 0;
282 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 271 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
283 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 272 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
284 link->conf.ConfigBase = parse.config.base; 273 link->conf.ConfigBase = parse.config.base;
285 link->conf.Present = parse.config.rmask[0]; 274 link->conf.Present = parse.config.rmask[0];
286 275
287 /* Is this a 3c562? */ 276 /* Is this a 3c562? */
288 tuple.DesiredTuple = CISTPL_MANFID; 277 tuple.DesiredTuple = CISTPL_MANFID;
289 tuple.Attributes = TUPLE_RETURN_COMMON; 278 tuple.Attributes = TUPLE_RETURN_COMMON;
290 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 279 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) &&
291 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) { 280 (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)) {
292 if (le16_to_cpu(buf[0]) != MANFID_3COM) 281 if (le16_to_cpu(buf[0]) != MANFID_3COM)
293 printk(KERN_INFO "3c589_cs: hmmm, is this really a " 282 printk(KERN_INFO "3c589_cs: hmmm, is this really a "
294 "3Com card??\n"); 283 "3Com card??\n");
295 multi = (le16_to_cpu(buf[1]) == PRODID_3COM_3C562); 284 multi = (le16_to_cpu(buf[1]) == PRODID_3COM_3C562);
296 } 285 }
297
298 /* Configure card */
299 link->state |= DEV_CONFIG;
300 286
301 /* For the 3c562, the base address must be xx00-xx7f */ 287 /* For the 3c562, the base address must be xx00-xx7f */
302 link->io.IOAddrLines = 16; 288 link->io.IOAddrLines = 16;
303 for (i = j = 0; j < 0x400; j += 0x10) { 289 for (i = j = 0; j < 0x400; j += 0x10) {
304 if (multi && (j & 0x80)) continue; 290 if (multi && (j & 0x80)) continue;
305 link->io.BasePort1 = j ^ 0x300; 291 link->io.BasePort1 = j ^ 0x300;
306 i = pcmcia_request_io(link->handle, &link->io); 292 i = pcmcia_request_io(link, &link->io);
307 if (i == CS_SUCCESS) break; 293 if (i == CS_SUCCESS) break;
308 } 294 }
309 if (i != CS_SUCCESS) { 295 if (i != CS_SUCCESS) {
310 cs_error(link->handle, RequestIO, i); 296 cs_error(link, RequestIO, i);
311 goto failed; 297 goto failed;
312 } 298 }
313 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 299 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
314 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 300 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
315 301
316 dev->irq = link->irq.AssignedIRQ; 302 dev->irq = link->irq.AssignedIRQ;
317 dev->base_addr = link->io.BasePort1; 303 dev->base_addr = link->io.BasePort1;
@@ -321,8 +307,8 @@ static void tc589_config(dev_link_t *link)
321 /* The 3c589 has an extra EEPROM for configuration info, including 307 /* The 3c589 has an extra EEPROM for configuration info, including
322 the hardware address. The 3c562 puts the address in the CIS. */ 308 the hardware address. The 3c562 puts the address in the CIS. */
323 tuple.DesiredTuple = 0x88; 309 tuple.DesiredTuple = 0x88;
324 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { 310 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
325 pcmcia_get_tuple_data(handle, &tuple); 311 pcmcia_get_tuple_data(link, &tuple);
326 for (i = 0; i < 3; i++) 312 for (i = 0; i < 3; i++)
327 phys_addr[i] = htons(buf[i]); 313 phys_addr[i] = htons(buf[i]);
328 } else { 314 } else {
@@ -346,13 +332,12 @@ static void tc589_config(dev_link_t *link)
346 else 332 else
347 printk(KERN_ERR "3c589_cs: invalid if_port requested\n"); 333 printk(KERN_ERR "3c589_cs: invalid if_port requested\n");
348 334
349 link->dev = &lp->node; 335 link->dev_node = &lp->node;
350 link->state &= ~DEV_CONFIG_PENDING; 336 SET_NETDEV_DEV(dev, &handle_to_dev(link));
351 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
352 337
353 if (register_netdev(dev) != 0) { 338 if (register_netdev(dev) != 0) {
354 printk(KERN_ERR "3c589_cs: register_netdev() failed\n"); 339 printk(KERN_ERR "3c589_cs: register_netdev() failed\n");
355 link->dev = NULL; 340 link->dev_node = NULL;
356 goto failed; 341 goto failed;
357 } 342 }
358 343
@@ -366,14 +351,13 @@ static void tc589_config(dev_link_t *link)
366 printk(KERN_INFO " %dK FIFO split %s Rx:Tx, %s xcvr\n", 351 printk(KERN_INFO " %dK FIFO split %s Rx:Tx, %s xcvr\n",
367 (fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3], 352 (fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3],
368 if_names[dev->if_port]); 353 if_names[dev->if_port]);
369 return; 354 return 0;
370 355
371cs_failed: 356cs_failed:
372 cs_error(link->handle, last_fn, last_ret); 357 cs_error(link, last_fn, last_ret);
373failed: 358failed:
374 tc589_release(link); 359 tc589_release(link);
375 return; 360 return -ENODEV;
376
377} /* tc589_config */ 361} /* tc589_config */
378 362
379/*====================================================================== 363/*======================================================================
@@ -384,44 +368,28 @@ failed:
384 368
385======================================================================*/ 369======================================================================*/
386 370
387static void tc589_release(dev_link_t *link) 371static void tc589_release(struct pcmcia_device *link)
388{ 372{
389 DEBUG(0, "3c589_release(0x%p)\n", link); 373 pcmcia_disable_device(link);
390
391 pcmcia_release_configuration(link->handle);
392 pcmcia_release_io(link->handle, &link->io);
393 pcmcia_release_irq(link->handle, &link->irq);
394
395 link->state &= ~DEV_CONFIG;
396} 374}
397 375
398static int tc589_suspend(struct pcmcia_device *p_dev) 376static int tc589_suspend(struct pcmcia_device *link)
399{ 377{
400 dev_link_t *link = dev_to_instance(p_dev);
401 struct net_device *dev = link->priv; 378 struct net_device *dev = link->priv;
402 379
403 link->state |= DEV_SUSPEND; 380 if (link->open)
404 if (link->state & DEV_CONFIG) { 381 netif_device_detach(dev);
405 if (link->open)
406 netif_device_detach(dev);
407 pcmcia_release_configuration(link->handle);
408 }
409 382
410 return 0; 383 return 0;
411} 384}
412 385
413static int tc589_resume(struct pcmcia_device *p_dev) 386static int tc589_resume(struct pcmcia_device *link)
414{ 387{
415 dev_link_t *link = dev_to_instance(p_dev);
416 struct net_device *dev = link->priv; 388 struct net_device *dev = link->priv;
417 389
418 link->state &= ~DEV_SUSPEND; 390 if (link->open) {
419 if (link->state & DEV_CONFIG) { 391 tc589_reset(dev);
420 pcmcia_request_configuration(link->handle, &link->conf); 392 netif_device_attach(dev);
421 if (link->open) {
422 tc589_reset(dev);
423 netif_device_attach(dev);
424 }
425 } 393 }
426 394
427 return 0; 395 return 0;
@@ -587,9 +555,9 @@ static int el3_config(struct net_device *dev, struct ifmap *map)
587static int el3_open(struct net_device *dev) 555static int el3_open(struct net_device *dev)
588{ 556{
589 struct el3_private *lp = netdev_priv(dev); 557 struct el3_private *lp = netdev_priv(dev);
590 dev_link_t *link = &lp->link; 558 struct pcmcia_device *link = lp->p_dev;
591 559
592 if (!DEV_OK(link)) 560 if (!pcmcia_dev_present(link))
593 return -ENODEV; 561 return -ENODEV;
594 562
595 link->open++; 563 link->open++;
@@ -848,9 +816,9 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
848{ 816{
849 struct el3_private *lp = netdev_priv(dev); 817 struct el3_private *lp = netdev_priv(dev);
850 unsigned long flags; 818 unsigned long flags;
851 dev_link_t *link = &lp->link; 819 struct pcmcia_device *link = lp->p_dev;
852 820
853 if (DEV_OK(link)) { 821 if (pcmcia_dev_present(link)) {
854 spin_lock_irqsave(&lp->lock, flags); 822 spin_lock_irqsave(&lp->lock, flags);
855 update_stats(dev); 823 update_stats(dev);
856 spin_unlock_irqrestore(&lp->lock, flags); 824 spin_unlock_irqrestore(&lp->lock, flags);
@@ -950,11 +918,11 @@ static int el3_rx(struct net_device *dev)
950static void set_multicast_list(struct net_device *dev) 918static void set_multicast_list(struct net_device *dev)
951{ 919{
952 struct el3_private *lp = netdev_priv(dev); 920 struct el3_private *lp = netdev_priv(dev);
953 dev_link_t *link = &lp->link; 921 struct pcmcia_device *link = lp->p_dev;
954 kio_addr_t ioaddr = dev->base_addr; 922 kio_addr_t ioaddr = dev->base_addr;
955 u16 opts = SetRxFilter | RxStation | RxBroadcast; 923 u16 opts = SetRxFilter | RxStation | RxBroadcast;
956 924
957 if (!(DEV_OK(link))) return; 925 if (!pcmcia_dev_present(link)) return;
958 if (dev->flags & IFF_PROMISC) 926 if (dev->flags & IFF_PROMISC)
959 opts |= RxMulticast | RxProm; 927 opts |= RxMulticast | RxProm;
960 else if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) 928 else if (dev->mc_count || (dev->flags & IFF_ALLMULTI))
@@ -965,12 +933,12 @@ static void set_multicast_list(struct net_device *dev)
965static int el3_close(struct net_device *dev) 933static int el3_close(struct net_device *dev)
966{ 934{
967 struct el3_private *lp = netdev_priv(dev); 935 struct el3_private *lp = netdev_priv(dev);
968 dev_link_t *link = &lp->link; 936 struct pcmcia_device *link = lp->p_dev;
969 kio_addr_t ioaddr = dev->base_addr; 937 kio_addr_t ioaddr = dev->base_addr;
970 938
971 DEBUG(1, "%s: shutting down ethercard.\n", dev->name); 939 DEBUG(1, "%s: shutting down ethercard.\n", dev->name);
972 940
973 if (DEV_OK(link)) { 941 if (pcmcia_dev_present(link)) {
974 /* Turn off statistics ASAP. We update lp->stats below. */ 942 /* Turn off statistics ASAP. We update lp->stats below. */
975 outw(StatsDisable, ioaddr + EL3_CMD); 943 outw(StatsDisable, ioaddr + EL3_CMD);
976 944
@@ -1020,7 +988,7 @@ static struct pcmcia_driver tc589_driver = {
1020 .drv = { 988 .drv = {
1021 .name = "3c589_cs", 989 .name = "3c589_cs",
1022 }, 990 },
1023 .probe = tc589_attach, 991 .probe = tc589_probe,
1024 .remove = tc589_detach, 992 .remove = tc589_detach,
1025 .id_table = tc589_ids, 993 .id_table = tc589_ids,
1026 .suspend = tc589_suspend, 994 .suspend = tc589_suspend,
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 1cc94b2d76c1..56233afcb2b3 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -86,8 +86,8 @@ static char *version =
86 86
87/*====================================================================*/ 87/*====================================================================*/
88 88
89static void axnet_config(dev_link_t *link); 89static int axnet_config(struct pcmcia_device *link);
90static void axnet_release(dev_link_t *link); 90static void axnet_release(struct pcmcia_device *link);
91static int axnet_open(struct net_device *dev); 91static int axnet_open(struct net_device *dev);
92static int axnet_close(struct net_device *dev); 92static int axnet_close(struct net_device *dev);
93static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 93static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -117,7 +117,7 @@ static irqreturn_t ax_interrupt(int irq, void *dev_id, struct pt_regs *regs);
117/*====================================================================*/ 117/*====================================================================*/
118 118
119typedef struct axnet_dev_t { 119typedef struct axnet_dev_t {
120 dev_link_t link; 120 struct pcmcia_device *p_dev;
121 dev_node_t node; 121 dev_node_t node;
122 caddr_t base; 122 caddr_t base;
123 struct timer_list watchdog; 123 struct timer_list watchdog;
@@ -142,10 +142,9 @@ static inline axnet_dev_t *PRIV(struct net_device *dev)
142 142
143======================================================================*/ 143======================================================================*/
144 144
145static int axnet_attach(struct pcmcia_device *p_dev) 145static int axnet_probe(struct pcmcia_device *link)
146{ 146{
147 axnet_dev_t *info; 147 axnet_dev_t *info;
148 dev_link_t *link;
149 struct net_device *dev; 148 struct net_device *dev;
150 149
151 DEBUG(0, "axnet_attach()\n"); 150 DEBUG(0, "axnet_attach()\n");
@@ -157,7 +156,7 @@ static int axnet_attach(struct pcmcia_device *p_dev)
157 return -ENOMEM; 156 return -ENOMEM;
158 157
159 info = PRIV(dev); 158 info = PRIV(dev);
160 link = &info->link; 159 info->p_dev = link;
161 link->priv = dev; 160 link->priv = dev;
162 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 161 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
163 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 162 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
@@ -169,13 +168,7 @@ static int axnet_attach(struct pcmcia_device *p_dev)
169 dev->do_ioctl = &axnet_ioctl; 168 dev->do_ioctl = &axnet_ioctl;
170 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 169 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
171 170
172 link->handle = p_dev; 171 return axnet_config(link);
173 p_dev->instance = link;
174
175 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
176 axnet_config(link);
177
178 return 0;
179} /* axnet_attach */ 172} /* axnet_attach */
180 173
181/*====================================================================== 174/*======================================================================
@@ -187,18 +180,16 @@ static int axnet_attach(struct pcmcia_device *p_dev)
187 180
188======================================================================*/ 181======================================================================*/
189 182
190static void axnet_detach(struct pcmcia_device *p_dev) 183static void axnet_detach(struct pcmcia_device *link)
191{ 184{
192 dev_link_t *link = dev_to_instance(p_dev);
193 struct net_device *dev = link->priv; 185 struct net_device *dev = link->priv;
194 186
195 DEBUG(0, "axnet_detach(0x%p)\n", link); 187 DEBUG(0, "axnet_detach(0x%p)\n", link);
196 188
197 if (link->dev) 189 if (link->dev_node)
198 unregister_netdev(dev); 190 unregister_netdev(dev);
199 191
200 if (link->state & DEV_CONFIG) 192 axnet_release(link);
201 axnet_release(link);
202 193
203 free_netdev(dev); 194 free_netdev(dev);
204} /* axnet_detach */ 195} /* axnet_detach */
@@ -209,7 +200,7 @@ static void axnet_detach(struct pcmcia_device *p_dev)
209 200
210======================================================================*/ 201======================================================================*/
211 202
212static int get_prom(dev_link_t *link) 203static int get_prom(struct pcmcia_device *link)
213{ 204{
214 struct net_device *dev = link->priv; 205 struct net_device *dev = link->priv;
215 kio_addr_t ioaddr = dev->base_addr; 206 kio_addr_t ioaddr = dev->base_addr;
@@ -263,7 +254,7 @@ static int get_prom(dev_link_t *link)
263#define CS_CHECK(fn, ret) \ 254#define CS_CHECK(fn, ret) \
264do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 255do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
265 256
266static int try_io_port(dev_link_t *link) 257static int try_io_port(struct pcmcia_device *link)
267{ 258{
268 int j, ret; 259 int j, ret;
269 if (link->io.NumPorts1 == 32) { 260 if (link->io.NumPorts1 == 32) {
@@ -284,25 +275,23 @@ static int try_io_port(dev_link_t *link)
284 for (j = 0; j < 0x400; j += 0x20) { 275 for (j = 0; j < 0x400; j += 0x20) {
285 link->io.BasePort1 = j ^ 0x300; 276 link->io.BasePort1 = j ^ 0x300;
286 link->io.BasePort2 = (j ^ 0x300) + 0x10; 277 link->io.BasePort2 = (j ^ 0x300) + 0x10;
287 ret = pcmcia_request_io(link->handle, &link->io); 278 ret = pcmcia_request_io(link, &link->io);
288 if (ret == CS_SUCCESS) return ret; 279 if (ret == CS_SUCCESS) return ret;
289 } 280 }
290 return ret; 281 return ret;
291 } else { 282 } else {
292 return pcmcia_request_io(link->handle, &link->io); 283 return pcmcia_request_io(link, &link->io);
293 } 284 }
294} 285}
295 286
296static void axnet_config(dev_link_t *link) 287static int axnet_config(struct pcmcia_device *link)
297{ 288{
298 client_handle_t handle = link->handle;
299 struct net_device *dev = link->priv; 289 struct net_device *dev = link->priv;
300 axnet_dev_t *info = PRIV(dev); 290 axnet_dev_t *info = PRIV(dev);
301 tuple_t tuple; 291 tuple_t tuple;
302 cisparse_t parse; 292 cisparse_t parse;
303 int i, j, last_ret, last_fn; 293 int i, j, last_ret, last_fn;
304 u_short buf[64]; 294 u_short buf[64];
305 config_info_t conf;
306 295
307 DEBUG(0, "axnet_config(0x%p)\n", link); 296 DEBUG(0, "axnet_config(0x%p)\n", link);
308 297
@@ -311,29 +300,22 @@ static void axnet_config(dev_link_t *link)
311 tuple.TupleDataMax = sizeof(buf); 300 tuple.TupleDataMax = sizeof(buf);
312 tuple.TupleOffset = 0; 301 tuple.TupleOffset = 0;
313 tuple.DesiredTuple = CISTPL_CONFIG; 302 tuple.DesiredTuple = CISTPL_CONFIG;
314 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 303 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
315 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 304 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
316 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 305 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
317 link->conf.ConfigBase = parse.config.base; 306 link->conf.ConfigBase = parse.config.base;
318 /* don't trust the CIS on this; Linksys got it wrong */ 307 /* don't trust the CIS on this; Linksys got it wrong */
319 link->conf.Present = 0x63; 308 link->conf.Present = 0x63;
320 309
321 /* Configure card */
322 link->state |= DEV_CONFIG;
323
324 /* Look up current Vcc */
325 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
326 link->conf.Vcc = conf.Vcc;
327
328 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 310 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
329 tuple.Attributes = 0; 311 tuple.Attributes = 0;
330 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 312 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
331 while (last_ret == CS_SUCCESS) { 313 while (last_ret == CS_SUCCESS) {
332 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 314 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
333 cistpl_io_t *io = &(parse.cftable_entry.io); 315 cistpl_io_t *io = &(parse.cftable_entry.io);
334 316
335 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 317 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
336 pcmcia_parse_tuple(handle, &tuple, &parse) != 0 || 318 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
337 cfg->index == 0 || cfg->io.nwin == 0) 319 cfg->index == 0 || cfg->io.nwin == 0)
338 goto next_entry; 320 goto next_entry;
339 321
@@ -355,21 +337,21 @@ static void axnet_config(dev_link_t *link)
355 if (last_ret == CS_SUCCESS) break; 337 if (last_ret == CS_SUCCESS) break;
356 } 338 }
357 next_entry: 339 next_entry:
358 last_ret = pcmcia_get_next_tuple(handle, &tuple); 340 last_ret = pcmcia_get_next_tuple(link, &tuple);
359 } 341 }
360 if (last_ret != CS_SUCCESS) { 342 if (last_ret != CS_SUCCESS) {
361 cs_error(handle, RequestIO, last_ret); 343 cs_error(link, RequestIO, last_ret);
362 goto failed; 344 goto failed;
363 } 345 }
364 346
365 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 347 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
366 348
367 if (link->io.NumPorts2 == 8) { 349 if (link->io.NumPorts2 == 8) {
368 link->conf.Attributes |= CONF_ENABLE_SPKR; 350 link->conf.Attributes |= CONF_ENABLE_SPKR;
369 link->conf.Status = CCSR_AUDIO_ENA; 351 link->conf.Status = CCSR_AUDIO_ENA;
370 } 352 }
371 353
372 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 354 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
373 dev->irq = link->irq.AssignedIRQ; 355 dev->irq = link->irq.AssignedIRQ;
374 dev->base_addr = link->io.BasePort1; 356 dev->base_addr = link->io.BasePort1;
375 357
@@ -406,7 +388,7 @@ static void axnet_config(dev_link_t *link)
406 Bit 2 of CCSR is active low. */ 388 Bit 2 of CCSR is active low. */
407 if (i == 32) { 389 if (i == 32) {
408 conf_reg_t reg = { 0, CS_WRITE, CISREG_CCSR, 0x04 }; 390 conf_reg_t reg = { 0, CS_WRITE, CISREG_CCSR, 0x04 };
409 pcmcia_access_configuration_register(link->handle, &reg); 391 pcmcia_access_configuration_register(link, &reg);
410 for (i = 0; i < 32; i++) { 392 for (i = 0; i < 32; i++) {
411 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1); 393 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
412 if ((j != 0) && (j != 0xffff)) break; 394 if ((j != 0) && (j != 0xffff)) break;
@@ -414,13 +396,12 @@ static void axnet_config(dev_link_t *link)
414 } 396 }
415 397
416 info->phy_id = (i < 32) ? i : -1; 398 info->phy_id = (i < 32) ? i : -1;
417 link->dev = &info->node; 399 link->dev_node = &info->node;
418 link->state &= ~DEV_CONFIG_PENDING; 400 SET_NETDEV_DEV(dev, &handle_to_dev(link));
419 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
420 401
421 if (register_netdev(dev) != 0) { 402 if (register_netdev(dev) != 0) {
422 printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n"); 403 printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n");
423 link->dev = NULL; 404 link->dev_node = NULL;
424 goto failed; 405 goto failed;
425 } 406 }
426 407
@@ -436,14 +417,13 @@ static void axnet_config(dev_link_t *link)
436 } else { 417 } else {
437 printk(KERN_NOTICE " No MII transceivers found!\n"); 418 printk(KERN_NOTICE " No MII transceivers found!\n");
438 } 419 }
439 return; 420 return 0;
440 421
441cs_failed: 422cs_failed:
442 cs_error(link->handle, last_fn, last_ret); 423 cs_error(link, last_fn, last_ret);
443failed: 424failed:
444 axnet_release(link); 425 axnet_release(link);
445 link->state &= ~DEV_CONFIG_PENDING; 426 return -ENODEV;
446 return;
447} /* axnet_config */ 427} /* axnet_config */
448 428
449/*====================================================================== 429/*======================================================================
@@ -454,45 +434,29 @@ failed:
454 434
455======================================================================*/ 435======================================================================*/
456 436
457static void axnet_release(dev_link_t *link) 437static void axnet_release(struct pcmcia_device *link)
458{ 438{
459 DEBUG(0, "axnet_release(0x%p)\n", link); 439 pcmcia_disable_device(link);
460
461 pcmcia_release_configuration(link->handle);
462 pcmcia_release_io(link->handle, &link->io);
463 pcmcia_release_irq(link->handle, &link->irq);
464
465 link->state &= ~DEV_CONFIG;
466} 440}
467 441
468static int axnet_suspend(struct pcmcia_device *p_dev) 442static int axnet_suspend(struct pcmcia_device *link)
469{ 443{
470 dev_link_t *link = dev_to_instance(p_dev);
471 struct net_device *dev = link->priv; 444 struct net_device *dev = link->priv;
472 445
473 link->state |= DEV_SUSPEND; 446 if (link->open)
474 if (link->state & DEV_CONFIG) { 447 netif_device_detach(dev);
475 if (link->open)
476 netif_device_detach(dev);
477 pcmcia_release_configuration(link->handle);
478 }
479 448
480 return 0; 449 return 0;
481} 450}
482 451
483static int axnet_resume(struct pcmcia_device *p_dev) 452static int axnet_resume(struct pcmcia_device *link)
484{ 453{
485 dev_link_t *link = dev_to_instance(p_dev);
486 struct net_device *dev = link->priv; 454 struct net_device *dev = link->priv;
487 455
488 link->state &= ~DEV_SUSPEND; 456 if (link->open) {
489 if (link->state & DEV_CONFIG) { 457 axnet_reset_8390(dev);
490 pcmcia_request_configuration(link->handle, &link->conf); 458 AX88190_init(dev, 1);
491 if (link->open) { 459 netif_device_attach(dev);
492 axnet_reset_8390(dev);
493 AX88190_init(dev, 1);
494 netif_device_attach(dev);
495 }
496 } 460 }
497 461
498 return 0; 462 return 0;
@@ -562,11 +526,11 @@ static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value)
562static int axnet_open(struct net_device *dev) 526static int axnet_open(struct net_device *dev)
563{ 527{
564 axnet_dev_t *info = PRIV(dev); 528 axnet_dev_t *info = PRIV(dev);
565 dev_link_t *link = &info->link; 529 struct pcmcia_device *link = info->p_dev;
566 530
567 DEBUG(2, "axnet_open('%s')\n", dev->name); 531 DEBUG(2, "axnet_open('%s')\n", dev->name);
568 532
569 if (!DEV_OK(link)) 533 if (!pcmcia_dev_present(link))
570 return -ENODEV; 534 return -ENODEV;
571 535
572 link->open++; 536 link->open++;
@@ -588,7 +552,7 @@ static int axnet_open(struct net_device *dev)
588static int axnet_close(struct net_device *dev) 552static int axnet_close(struct net_device *dev)
589{ 553{
590 axnet_dev_t *info = PRIV(dev); 554 axnet_dev_t *info = PRIV(dev);
591 dev_link_t *link = &info->link; 555 struct pcmcia_device *link = info->p_dev;
592 556
593 DEBUG(2, "axnet_close('%s')\n", dev->name); 557 DEBUG(2, "axnet_close('%s')\n", dev->name);
594 558
@@ -833,7 +797,7 @@ static struct pcmcia_driver axnet_cs_driver = {
833 .drv = { 797 .drv = {
834 .name = "axnet_cs", 798 .name = "axnet_cs",
835 }, 799 },
836 .probe = axnet_attach, 800 .probe = axnet_probe,
837 .remove = axnet_detach, 801 .remove = axnet_detach,
838 .id_table = axnet_ids, 802 .id_table = axnet_ids,
839 .suspend = axnet_suspend, 803 .suspend = axnet_suspend,
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index 2827a48ea37c..441de824ab6b 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -118,8 +118,8 @@ MODULE_LICENSE("GPL");
118 118
119/*====================================================================*/ 119/*====================================================================*/
120 120
121static void com20020_config(dev_link_t *link); 121static int com20020_config(struct pcmcia_device *link);
122static void com20020_release(dev_link_t *link); 122static void com20020_release(struct pcmcia_device *link);
123 123
124static void com20020_detach(struct pcmcia_device *p_dev); 124static void com20020_detach(struct pcmcia_device *p_dev);
125 125
@@ -138,9 +138,8 @@ typedef struct com20020_dev_t {
138 138
139======================================================================*/ 139======================================================================*/
140 140
141static int com20020_attach(struct pcmcia_device *p_dev) 141static int com20020_probe(struct pcmcia_device *p_dev)
142{ 142{
143 dev_link_t *link;
144 com20020_dev_t *info; 143 com20020_dev_t *info;
145 struct net_device *dev; 144 struct net_device *dev;
146 struct arcnet_local *lp; 145 struct arcnet_local *lp;
@@ -148,10 +147,6 @@ static int com20020_attach(struct pcmcia_device *p_dev)
148 DEBUG(0, "com20020_attach()\n"); 147 DEBUG(0, "com20020_attach()\n");
149 148
150 /* Create new network device */ 149 /* Create new network device */
151 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
152 if (!link)
153 return -ENOMEM;
154
155 info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL); 150 info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL);
156 if (!info) 151 if (!info)
157 goto fail_alloc_info; 152 goto fail_alloc_info;
@@ -161,7 +156,6 @@ static int com20020_attach(struct pcmcia_device *p_dev)
161 goto fail_alloc_dev; 156 goto fail_alloc_dev;
162 157
163 memset(info, 0, sizeof(struct com20020_dev_t)); 158 memset(info, 0, sizeof(struct com20020_dev_t));
164 memset(link, 0, sizeof(struct dev_link_t));
165 lp = dev->priv; 159 lp = dev->priv;
166 lp->timeout = timeout; 160 lp->timeout = timeout;
167 lp->backplane = backplane; 161 lp->backplane = backplane;
@@ -172,28 +166,23 @@ static int com20020_attach(struct pcmcia_device *p_dev)
172 /* fill in our module parameters as defaults */ 166 /* fill in our module parameters as defaults */
173 dev->dev_addr[0] = node; 167 dev->dev_addr[0] = node;
174 168
175 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 169 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
176 link->io.NumPorts1 = 16; 170 p_dev->io.NumPorts1 = 16;
177 link->io.IOAddrLines = 16; 171 p_dev->io.IOAddrLines = 16;
178 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 172 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
179 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 173 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
180 link->conf.Attributes = CONF_ENABLE_IRQ; 174 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
181 link->conf.Vcc = 50; 175 p_dev->conf.IntType = INT_MEMORY_AND_IO;
182 link->conf.IntType = INT_MEMORY_AND_IO; 176 p_dev->conf.Present = PRESENT_OPTION;
183 link->conf.Present = PRESENT_OPTION;
184
185 link->irq.Instance = info->dev = dev;
186 link->priv = info;
187 177
188 link->state |= DEV_PRESENT; 178 p_dev->irq.Instance = info->dev = dev;
189 com20020_config(link); 179 p_dev->priv = info;
190 180
191 return 0; 181 return com20020_config(p_dev);
192 182
193fail_alloc_dev: 183fail_alloc_dev:
194 kfree(info); 184 kfree(info);
195fail_alloc_info: 185fail_alloc_info:
196 kfree(link);
197 return -ENOMEM; 186 return -ENOMEM;
198} /* com20020_attach */ 187} /* com20020_attach */
199 188
@@ -206,9 +195,8 @@ fail_alloc_info:
206 195
207======================================================================*/ 196======================================================================*/
208 197
209static void com20020_detach(struct pcmcia_device *p_dev) 198static void com20020_detach(struct pcmcia_device *link)
210{ 199{
211 dev_link_t *link = dev_to_instance(p_dev);
212 struct com20020_dev_t *info = link->priv; 200 struct com20020_dev_t *info = link->priv;
213 struct net_device *dev = info->dev; 201 struct net_device *dev = info->dev;
214 202
@@ -216,7 +204,7 @@ static void com20020_detach(struct pcmcia_device *p_dev)
216 204
217 DEBUG(0, "com20020_detach(0x%p)\n", link); 205 DEBUG(0, "com20020_detach(0x%p)\n", link);
218 206
219 if (link->dev) { 207 if (link->dev_node) {
220 DEBUG(1,"unregister...\n"); 208 DEBUG(1,"unregister...\n");
221 209
222 unregister_netdev(dev); 210 unregister_netdev(dev);
@@ -229,8 +217,7 @@ static void com20020_detach(struct pcmcia_device *p_dev)
229 free_irq(dev->irq, dev); 217 free_irq(dev->irq, dev);
230 } 218 }
231 219
232 if (link->state & DEV_CONFIG) 220 com20020_release(link);
233 com20020_release(link);
234 221
235 /* Unlink device structure, free bits */ 222 /* Unlink device structure, free bits */
236 DEBUG(1,"unlinking...\n"); 223 DEBUG(1,"unlinking...\n");
@@ -245,8 +232,6 @@ static void com20020_detach(struct pcmcia_device *p_dev)
245 DEBUG(1,"kfree2...\n"); 232 DEBUG(1,"kfree2...\n");
246 kfree(info); 233 kfree(info);
247 } 234 }
248 DEBUG(1,"kfree3...\n");
249 kfree(link);
250 235
251} /* com20020_detach */ 236} /* com20020_detach */
252 237
@@ -261,10 +246,9 @@ static void com20020_detach(struct pcmcia_device *p_dev)
261#define CS_CHECK(fn, ret) \ 246#define CS_CHECK(fn, ret) \
262do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 247do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
263 248
264static void com20020_config(dev_link_t *link) 249static int com20020_config(struct pcmcia_device *link)
265{ 250{
266 struct arcnet_local *lp; 251 struct arcnet_local *lp;
267 client_handle_t handle;
268 tuple_t tuple; 252 tuple_t tuple;
269 cisparse_t parse; 253 cisparse_t parse;
270 com20020_dev_t *info; 254 com20020_dev_t *info;
@@ -273,7 +257,6 @@ static void com20020_config(dev_link_t *link)
273 u_char buf[64]; 257 u_char buf[64];
274 int ioaddr; 258 int ioaddr;
275 259
276 handle = link->handle;
277 info = link->priv; 260 info = link->priv;
278 dev = info->dev; 261 dev = info->dev;
279 262
@@ -286,14 +269,11 @@ static void com20020_config(dev_link_t *link)
286 tuple.TupleDataMax = 64; 269 tuple.TupleDataMax = 64;
287 tuple.TupleOffset = 0; 270 tuple.TupleOffset = 0;
288 tuple.DesiredTuple = CISTPL_CONFIG; 271 tuple.DesiredTuple = CISTPL_CONFIG;
289 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 272 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
290 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 273 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
291 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 274 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
292 link->conf.ConfigBase = parse.config.base; 275 link->conf.ConfigBase = parse.config.base;
293 276
294 /* Configure card */
295 link->state |= DEV_CONFIG;
296
297 DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1); 277 DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1);
298 i = !CS_SUCCESS; 278 i = !CS_SUCCESS;
299 if (!link->io.BasePort1) 279 if (!link->io.BasePort1)
@@ -301,13 +281,13 @@ static void com20020_config(dev_link_t *link)
301 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10) 281 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10)
302 { 282 {
303 link->io.BasePort1 = ioaddr; 283 link->io.BasePort1 = ioaddr;
304 i = pcmcia_request_io(link->handle, &link->io); 284 i = pcmcia_request_io(link, &link->io);
305 if (i == CS_SUCCESS) 285 if (i == CS_SUCCESS)
306 break; 286 break;
307 } 287 }
308 } 288 }
309 else 289 else
310 i = pcmcia_request_io(link->handle, &link->io); 290 i = pcmcia_request_io(link, &link->io);
311 291
312 if (i != CS_SUCCESS) 292 if (i != CS_SUCCESS)
313 { 293 {
@@ -321,7 +301,7 @@ static void com20020_config(dev_link_t *link)
321 DEBUG(1,"arcnet: request IRQ %d (%Xh/%Xh)\n", 301 DEBUG(1,"arcnet: request IRQ %d (%Xh/%Xh)\n",
322 link->irq.AssignedIRQ, 302 link->irq.AssignedIRQ,
323 link->irq.IRQInfo1, link->irq.IRQInfo2); 303 link->irq.IRQInfo1, link->irq.IRQInfo2);
324 i = pcmcia_request_irq(link->handle, &link->irq); 304 i = pcmcia_request_irq(link, &link->irq);
325 if (i != CS_SUCCESS) 305 if (i != CS_SUCCESS)
326 { 306 {
327 DEBUG(1,"arcnet: requestIRQ failed totally!\n"); 307 DEBUG(1,"arcnet: requestIRQ failed totally!\n");
@@ -330,7 +310,7 @@ static void com20020_config(dev_link_t *link)
330 310
331 dev->irq = link->irq.AssignedIRQ; 311 dev->irq = link->irq.AssignedIRQ;
332 312
333 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 313 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
334 314
335 if (com20020_check(dev)) 315 if (com20020_check(dev))
336 { 316 {
@@ -342,15 +322,14 @@ static void com20020_config(dev_link_t *link)
342 lp->card_name = "PCMCIA COM20020"; 322 lp->card_name = "PCMCIA COM20020";
343 lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */ 323 lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
344 324
345 link->dev = &info->node; 325 link->dev_node = &info->node;
346 link->state &= ~DEV_CONFIG_PENDING; 326 SET_NETDEV_DEV(dev, &handle_to_dev(link));
347 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
348 327
349 i = com20020_found(dev, 0); /* calls register_netdev */ 328 i = com20020_found(dev, 0); /* calls register_netdev */
350 329
351 if (i != 0) { 330 if (i != 0) {
352 DEBUG(1,KERN_NOTICE "com20020_cs: com20020_found() failed\n"); 331 DEBUG(1,KERN_NOTICE "com20020_cs: com20020_found() failed\n");
353 link->dev = NULL; 332 link->dev_node = NULL;
354 goto failed; 333 goto failed;
355 } 334 }
356 335
@@ -358,13 +337,14 @@ static void com20020_config(dev_link_t *link)
358 337
359 DEBUG(1,KERN_INFO "%s: port %#3lx, irq %d\n", 338 DEBUG(1,KERN_INFO "%s: port %#3lx, irq %d\n",
360 dev->name, dev->base_addr, dev->irq); 339 dev->name, dev->base_addr, dev->irq);
361 return; 340 return 0;
362 341
363cs_failed: 342cs_failed:
364 cs_error(link->handle, last_fn, last_ret); 343 cs_error(link, last_fn, last_ret);
365failed: 344failed:
366 DEBUG(1,"com20020_config failed...\n"); 345 DEBUG(1,"com20020_config failed...\n");
367 com20020_release(link); 346 com20020_release(link);
347 return -ENODEV;
368} /* com20020_config */ 348} /* com20020_config */
369 349
370/*====================================================================== 350/*======================================================================
@@ -375,52 +355,33 @@ failed:
375 355
376======================================================================*/ 356======================================================================*/
377 357
378static void com20020_release(dev_link_t *link) 358static void com20020_release(struct pcmcia_device *link)
379{ 359{
380 360 DEBUG(0, "com20020_release(0x%p)\n", link);
381 DEBUG(1,"release...\n"); 361 pcmcia_disable_device(link);
382
383 DEBUG(0, "com20020_release(0x%p)\n", link);
384
385 pcmcia_release_configuration(link->handle);
386 pcmcia_release_io(link->handle, &link->io);
387 pcmcia_release_irq(link->handle, &link->irq);
388
389 link->state &= ~(DEV_CONFIG | DEV_RELEASE_PENDING);
390} 362}
391 363
392static int com20020_suspend(struct pcmcia_device *p_dev) 364static int com20020_suspend(struct pcmcia_device *link)
393{ 365{
394 dev_link_t *link = dev_to_instance(p_dev);
395 com20020_dev_t *info = link->priv; 366 com20020_dev_t *info = link->priv;
396 struct net_device *dev = info->dev; 367 struct net_device *dev = info->dev;
397 368
398 link->state |= DEV_SUSPEND; 369 if (link->open)
399 if (link->state & DEV_CONFIG) { 370 netif_device_detach(dev);
400 if (link->open) {
401 netif_device_detach(dev);
402 }
403 pcmcia_release_configuration(link->handle);
404 }
405 371
406 return 0; 372 return 0;
407} 373}
408 374
409static int com20020_resume(struct pcmcia_device *p_dev) 375static int com20020_resume(struct pcmcia_device *link)
410{ 376{
411 dev_link_t *link = dev_to_instance(p_dev);
412 com20020_dev_t *info = link->priv; 377 com20020_dev_t *info = link->priv;
413 struct net_device *dev = info->dev; 378 struct net_device *dev = info->dev;
414 379
415 link->state &= ~DEV_SUSPEND; 380 if (link->open) {
416 if (link->state & DEV_CONFIG) { 381 int ioaddr = dev->base_addr;
417 pcmcia_request_configuration(link->handle, &link->conf); 382 struct arcnet_local *lp = dev->priv;
418 if (link->open) { 383 ARCRESET;
419 int ioaddr = dev->base_addr; 384 }
420 struct arcnet_local *lp = dev->priv;
421 ARCRESET;
422 }
423 }
424 385
425 return 0; 386 return 0;
426} 387}
@@ -436,7 +397,7 @@ static struct pcmcia_driver com20020_cs_driver = {
436 .drv = { 397 .drv = {
437 .name = "com20020_cs", 398 .name = "com20020_cs",
438 }, 399 },
439 .probe = com20020_attach, 400 .probe = com20020_probe,
440 .remove = com20020_detach, 401 .remove = com20020_detach,
441 .id_table = com20020_ids, 402 .id_table = com20020_ids,
442 .suspend = com20020_suspend, 403 .suspend = com20020_suspend,
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index b7ac14ba8877..09b11761cdfa 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -84,10 +84,10 @@ static char *version = DRV_NAME ".c " DRV_VERSION " 2002/03/23";
84/* 84/*
85 PCMCIA event handlers 85 PCMCIA event handlers
86 */ 86 */
87static void fmvj18x_config(dev_link_t *link); 87static int fmvj18x_config(struct pcmcia_device *link);
88static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id); 88static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id);
89static int fmvj18x_setup_mfc(dev_link_t *link); 89static int fmvj18x_setup_mfc(struct pcmcia_device *link);
90static void fmvj18x_release(dev_link_t *link); 90static void fmvj18x_release(struct pcmcia_device *link);
91static void fmvj18x_detach(struct pcmcia_device *p_dev); 91static void fmvj18x_detach(struct pcmcia_device *p_dev);
92 92
93/* 93/*
@@ -116,7 +116,7 @@ typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN,
116 driver specific data structure 116 driver specific data structure
117*/ 117*/
118typedef struct local_info_t { 118typedef struct local_info_t {
119 dev_link_t link; 119 struct pcmcia_device *p_dev;
120 dev_node_t node; 120 dev_node_t node;
121 struct net_device_stats stats; 121 struct net_device_stats stats;
122 long open_time; 122 long open_time;
@@ -228,10 +228,9 @@ typedef struct local_info_t {
228#define BANK_1U 0x24 /* bank 1 (CONFIG_1) */ 228#define BANK_1U 0x24 /* bank 1 (CONFIG_1) */
229#define BANK_2U 0x28 /* bank 2 (CONFIG_1) */ 229#define BANK_2U 0x28 /* bank 2 (CONFIG_1) */
230 230
231static int fmvj18x_attach(struct pcmcia_device *p_dev) 231static int fmvj18x_probe(struct pcmcia_device *link)
232{ 232{
233 local_info_t *lp; 233 local_info_t *lp;
234 dev_link_t *link;
235 struct net_device *dev; 234 struct net_device *dev;
236 235
237 DEBUG(0, "fmvj18x_attach()\n"); 236 DEBUG(0, "fmvj18x_attach()\n");
@@ -241,8 +240,8 @@ static int fmvj18x_attach(struct pcmcia_device *p_dev)
241 if (!dev) 240 if (!dev)
242 return -ENOMEM; 241 return -ENOMEM;
243 lp = netdev_priv(dev); 242 lp = netdev_priv(dev);
244 link = &lp->link;
245 link->priv = dev; 243 link->priv = dev;
244 lp->p_dev = link;
246 245
247 /* The io structure describes IO port mapping */ 246 /* The io structure describes IO port mapping */
248 link->io.NumPorts1 = 32; 247 link->io.NumPorts1 = 32;
@@ -257,7 +256,6 @@ static int fmvj18x_attach(struct pcmcia_device *p_dev)
257 256
258 /* General socket configuration */ 257 /* General socket configuration */
259 link->conf.Attributes = CONF_ENABLE_IRQ; 258 link->conf.Attributes = CONF_ENABLE_IRQ;
260 link->conf.Vcc = 50;
261 link->conf.IntType = INT_MEMORY_AND_IO; 259 link->conf.IntType = INT_MEMORY_AND_IO;
262 260
263 /* The FMVJ18x specific entries in the device structure. */ 261 /* The FMVJ18x specific entries in the device structure. */
@@ -274,29 +272,21 @@ static int fmvj18x_attach(struct pcmcia_device *p_dev)
274#endif 272#endif
275 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 273 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
276 274
277 link->handle = p_dev; 275 return fmvj18x_config(link);
278 p_dev->instance = link;
279
280 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
281 fmvj18x_config(link);
282
283 return 0;
284} /* fmvj18x_attach */ 276} /* fmvj18x_attach */
285 277
286/*====================================================================*/ 278/*====================================================================*/
287 279
288static void fmvj18x_detach(struct pcmcia_device *p_dev) 280static void fmvj18x_detach(struct pcmcia_device *link)
289{ 281{
290 dev_link_t *link = dev_to_instance(p_dev);
291 struct net_device *dev = link->priv; 282 struct net_device *dev = link->priv;
292 283
293 DEBUG(0, "fmvj18x_detach(0x%p)\n", link); 284 DEBUG(0, "fmvj18x_detach(0x%p)\n", link);
294 285
295 if (link->dev) 286 if (link->dev_node)
296 unregister_netdev(dev); 287 unregister_netdev(dev);
297 288
298 if (link->state & DEV_CONFIG) 289 fmvj18x_release(link);
299 fmvj18x_release(link);
300 290
301 free_netdev(dev); 291 free_netdev(dev);
302} /* fmvj18x_detach */ 292} /* fmvj18x_detach */
@@ -306,7 +296,7 @@ static void fmvj18x_detach(struct pcmcia_device *p_dev)
306#define CS_CHECK(fn, ret) \ 296#define CS_CHECK(fn, ret) \
307do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 297do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
308 298
309static int mfc_try_io_port(dev_link_t *link) 299static int mfc_try_io_port(struct pcmcia_device *link)
310{ 300{
311 int i, ret; 301 int i, ret;
312 static const kio_addr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 302 static const kio_addr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
@@ -318,13 +308,13 @@ static int mfc_try_io_port(dev_link_t *link)
318 link->io.NumPorts2 = 0; 308 link->io.NumPorts2 = 0;
319 printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n"); 309 printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n");
320 } 310 }
321 ret = pcmcia_request_io(link->handle, &link->io); 311 ret = pcmcia_request_io(link, &link->io);
322 if (ret == CS_SUCCESS) return ret; 312 if (ret == CS_SUCCESS) return ret;
323 } 313 }
324 return ret; 314 return ret;
325} 315}
326 316
327static int ungermann_try_io_port(dev_link_t *link) 317static int ungermann_try_io_port(struct pcmcia_device *link)
328{ 318{
329 int ret; 319 int ret;
330 kio_addr_t ioaddr; 320 kio_addr_t ioaddr;
@@ -334,7 +324,7 @@ static int ungermann_try_io_port(dev_link_t *link)
334 */ 324 */
335 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) { 325 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
336 link->io.BasePort1 = ioaddr; 326 link->io.BasePort1 = ioaddr;
337 ret = pcmcia_request_io(link->handle, &link->io); 327 ret = pcmcia_request_io(link, &link->io);
338 if (ret == CS_SUCCESS) { 328 if (ret == CS_SUCCESS) {
339 /* calculate ConfigIndex value */ 329 /* calculate ConfigIndex value */
340 link->conf.ConfigIndex = 330 link->conf.ConfigIndex =
@@ -345,9 +335,8 @@ static int ungermann_try_io_port(dev_link_t *link)
345 return ret; /* RequestIO failed */ 335 return ret; /* RequestIO failed */
346} 336}
347 337
348static void fmvj18x_config(dev_link_t *link) 338static int fmvj18x_config(struct pcmcia_device *link)
349{ 339{
350 client_handle_t handle = link->handle;
351 struct net_device *dev = link->priv; 340 struct net_device *dev = link->priv;
352 local_info_t *lp = netdev_priv(dev); 341 local_info_t *lp = netdev_priv(dev);
353 tuple_t tuple; 342 tuple_t tuple;
@@ -366,42 +355,34 @@ static void fmvj18x_config(dev_link_t *link)
366 registers. 355 registers.
367 */ 356 */
368 tuple.DesiredTuple = CISTPL_CONFIG; 357 tuple.DesiredTuple = CISTPL_CONFIG;
369 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 358 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
370 tuple.TupleData = (u_char *)buf; 359 tuple.TupleData = (u_char *)buf;
371 tuple.TupleDataMax = 64; 360 tuple.TupleDataMax = 64;
372 tuple.TupleOffset = 0; 361 tuple.TupleOffset = 0;
373 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 362 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
374 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 363 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
375
376 /* Configure card */
377 link->state |= DEV_CONFIG;
378 364
379 link->conf.ConfigBase = parse.config.base; 365 link->conf.ConfigBase = parse.config.base;
380 link->conf.Present = parse.config.rmask[0]; 366 link->conf.Present = parse.config.rmask[0];
381 367
382 tuple.DesiredTuple = CISTPL_FUNCE; 368 tuple.DesiredTuple = CISTPL_FUNCE;
383 tuple.TupleOffset = 0; 369 tuple.TupleOffset = 0;
384 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { 370 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
385 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */ 371 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
386 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 372 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
387 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 373 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
388 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 374 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
389 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 375 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
390 link->conf.ConfigIndex = parse.cftable_entry.index; 376 link->conf.ConfigIndex = parse.cftable_entry.index;
391 tuple.DesiredTuple = CISTPL_MANFID; 377 tuple.DesiredTuple = CISTPL_MANFID;
392 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) 378 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS)
393 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 379 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
394 else 380 else
395 buf[0] = 0xffff; 381 buf[0] = 0xffff;
396 switch (le16_to_cpu(buf[0])) { 382 switch (le16_to_cpu(buf[0])) {
397 case MANFID_TDK: 383 case MANFID_TDK:
398 cardtype = TDK; 384 cardtype = TDK;
399 if (le16_to_cpu(buf[1]) == PRODID_TDK_CF010) { 385 if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410
400 cs_status_t status;
401 pcmcia_get_status(handle, &status);
402 if (status.CardState & CS_EVENT_3VCARD)
403 link->conf.Vcc = 33; /* inserted in 3.3V slot */
404 } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410
405 || le16_to_cpu(buf[1]) == PRODID_TDK_NP9610 386 || le16_to_cpu(buf[1]) == PRODID_TDK_NP9610
406 || le16_to_cpu(buf[1]) == PRODID_TDK_MN3200) { 387 || le16_to_cpu(buf[1]) == PRODID_TDK_MN3200) {
407 /* MultiFunction Card */ 388 /* MultiFunction Card */
@@ -429,8 +410,8 @@ static void fmvj18x_config(dev_link_t *link)
429 } else { 410 } else {
430 /* old type card */ 411 /* old type card */
431 tuple.DesiredTuple = CISTPL_MANFID; 412 tuple.DesiredTuple = CISTPL_MANFID;
432 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) 413 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS)
433 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 414 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
434 else 415 else
435 buf[0] = 0xffff; 416 buf[0] = 0xffff;
436 switch (le16_to_cpu(buf[0])) { 417 switch (le16_to_cpu(buf[0])) {
@@ -461,10 +442,10 @@ static void fmvj18x_config(dev_link_t *link)
461 ret = ungermann_try_io_port(link); 442 ret = ungermann_try_io_port(link);
462 if (ret != CS_SUCCESS) goto cs_failed; 443 if (ret != CS_SUCCESS) goto cs_failed;
463 } else { 444 } else {
464 CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io)); 445 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
465 } 446 }
466 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 447 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
467 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 448 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
468 dev->irq = link->irq.AssignedIRQ; 449 dev->irq = link->irq.AssignedIRQ;
469 dev->base_addr = link->io.BasePort1; 450 dev->base_addr = link->io.BasePort1;
470 451
@@ -493,17 +474,17 @@ static void fmvj18x_config(dev_link_t *link)
493 case CONTEC: 474 case CONTEC:
494 tuple.DesiredTuple = CISTPL_FUNCE; 475 tuple.DesiredTuple = CISTPL_FUNCE;
495 tuple.TupleOffset = 0; 476 tuple.TupleOffset = 0;
496 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 477 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
497 tuple.TupleOffset = 0; 478 tuple.TupleOffset = 0;
498 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 479 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
499 if (cardtype == MBH10304) { 480 if (cardtype == MBH10304) {
500 /* MBH10304's CIS_FUNCE is corrupted */ 481 /* MBH10304's CIS_FUNCE is corrupted */
501 node_id = &(tuple.TupleData[5]); 482 node_id = &(tuple.TupleData[5]);
502 card_name = "FMV-J182"; 483 card_name = "FMV-J182";
503 } else { 484 } else {
504 while (tuple.TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID ) { 485 while (tuple.TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID ) {
505 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 486 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
506 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 487 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
507 } 488 }
508 node_id = &(tuple.TupleData[2]); 489 node_id = &(tuple.TupleData[2]);
509 if( cardtype == TDK ) { 490 if( cardtype == TDK ) {
@@ -545,13 +526,12 @@ static void fmvj18x_config(dev_link_t *link)
545 } 526 }
546 527
547 lp->cardtype = cardtype; 528 lp->cardtype = cardtype;
548 link->dev = &lp->node; 529 link->dev_node = &lp->node;
549 link->state &= ~DEV_CONFIG_PENDING; 530 SET_NETDEV_DEV(dev, &handle_to_dev(link));
550 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
551 531
552 if (register_netdev(dev) != 0) { 532 if (register_netdev(dev) != 0) {
553 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n"); 533 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n");
554 link->dev = NULL; 534 link->dev_node = NULL;
555 goto failed; 535 goto failed;
556 } 536 }
557 537
@@ -564,19 +544,18 @@ static void fmvj18x_config(dev_link_t *link)
564 for (i = 0; i < 6; i++) 544 for (i = 0; i < 6; i++)
565 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 545 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
566 546
567 return; 547 return 0;
568 548
569cs_failed: 549cs_failed:
570 /* All Card Services errors end up here */ 550 /* All Card Services errors end up here */
571 cs_error(link->handle, last_fn, last_ret); 551 cs_error(link, last_fn, last_ret);
572failed: 552failed:
573 fmvj18x_release(link); 553 fmvj18x_release(link);
574 link->state &= ~DEV_CONFIG_PENDING; 554 return -ENODEV;
575
576} /* fmvj18x_config */ 555} /* fmvj18x_config */
577/*====================================================================*/ 556/*====================================================================*/
578 557
579static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id) 558static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
580{ 559{
581 win_req_t req; 560 win_req_t req;
582 memreq_t mem; 561 memreq_t mem;
@@ -587,9 +566,9 @@ static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id)
587 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 566 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
588 req.Base = 0; req.Size = 0; 567 req.Base = 0; req.Size = 0;
589 req.AccessSpeed = 0; 568 req.AccessSpeed = 0;
590 i = pcmcia_request_window(&link->handle, &req, &link->win); 569 i = pcmcia_request_window(&link, &req, &link->win);
591 if (i != CS_SUCCESS) { 570 if (i != CS_SUCCESS) {
592 cs_error(link->handle, RequestWindow, i); 571 cs_error(link, RequestWindow, i);
593 return -1; 572 return -1;
594 } 573 }
595 574
@@ -623,13 +602,13 @@ static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id)
623 iounmap(base); 602 iounmap(base);
624 j = pcmcia_release_window(link->win); 603 j = pcmcia_release_window(link->win);
625 if (j != CS_SUCCESS) 604 if (j != CS_SUCCESS)
626 cs_error(link->handle, ReleaseWindow, j); 605 cs_error(link, ReleaseWindow, j);
627 return (i != 0x200) ? 0 : -1; 606 return (i != 0x200) ? 0 : -1;
628 607
629} /* fmvj18x_get_hwinfo */ 608} /* fmvj18x_get_hwinfo */
630/*====================================================================*/ 609/*====================================================================*/
631 610
632static int fmvj18x_setup_mfc(dev_link_t *link) 611static int fmvj18x_setup_mfc(struct pcmcia_device *link)
633{ 612{
634 win_req_t req; 613 win_req_t req;
635 memreq_t mem; 614 memreq_t mem;
@@ -642,9 +621,9 @@ static int fmvj18x_setup_mfc(dev_link_t *link)
642 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 621 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
643 req.Base = 0; req.Size = 0; 622 req.Base = 0; req.Size = 0;
644 req.AccessSpeed = 0; 623 req.AccessSpeed = 0;
645 i = pcmcia_request_window(&link->handle, &req, &link->win); 624 i = pcmcia_request_window(&link, &req, &link->win);
646 if (i != CS_SUCCESS) { 625 if (i != CS_SUCCESS) {
647 cs_error(link->handle, RequestWindow, i); 626 cs_error(link, RequestWindow, i);
648 return -1; 627 return -1;
649 } 628 }
650 629
@@ -666,54 +645,35 @@ static int fmvj18x_setup_mfc(dev_link_t *link)
666 iounmap(base); 645 iounmap(base);
667 j = pcmcia_release_window(link->win); 646 j = pcmcia_release_window(link->win);
668 if (j != CS_SUCCESS) 647 if (j != CS_SUCCESS)
669 cs_error(link->handle, ReleaseWindow, j); 648 cs_error(link, ReleaseWindow, j);
670 return 0; 649 return 0;
671 650
672} 651}
673/*====================================================================*/ 652/*====================================================================*/
674 653
675static void fmvj18x_release(dev_link_t *link) 654static void fmvj18x_release(struct pcmcia_device *link)
676{ 655{
677 656 DEBUG(0, "fmvj18x_release(0x%p)\n", link);
678 DEBUG(0, "fmvj18x_release(0x%p)\n", link); 657 pcmcia_disable_device(link);
679
680 /* Don't bother checking to see if these succeed or not */
681 pcmcia_release_window(link->win);
682 pcmcia_release_configuration(link->handle);
683 pcmcia_release_io(link->handle, &link->io);
684 pcmcia_release_irq(link->handle, &link->irq);
685
686 link->state &= ~DEV_CONFIG;
687} 658}
688 659
689static int fmvj18x_suspend(struct pcmcia_device *p_dev) 660static int fmvj18x_suspend(struct pcmcia_device *link)
690{ 661{
691 dev_link_t *link = dev_to_instance(p_dev);
692 struct net_device *dev = link->priv; 662 struct net_device *dev = link->priv;
693 663
694 link->state |= DEV_SUSPEND; 664 if (link->open)
695 if (link->state & DEV_CONFIG) { 665 netif_device_detach(dev);
696 if (link->open)
697 netif_device_detach(dev);
698 pcmcia_release_configuration(link->handle);
699 }
700
701 666
702 return 0; 667 return 0;
703} 668}
704 669
705static int fmvj18x_resume(struct pcmcia_device *p_dev) 670static int fmvj18x_resume(struct pcmcia_device *link)
706{ 671{
707 dev_link_t *link = dev_to_instance(p_dev);
708 struct net_device *dev = link->priv; 672 struct net_device *dev = link->priv;
709 673
710 link->state &= ~DEV_SUSPEND; 674 if (link->open) {
711 if (link->state & DEV_CONFIG) { 675 fjn_reset(dev);
712 pcmcia_request_configuration(link->handle, &link->conf); 676 netif_device_attach(dev);
713 if (link->open) {
714 fjn_reset(dev);
715 netif_device_attach(dev);
716 }
717 } 677 }
718 678
719 return 0; 679 return 0;
@@ -751,7 +711,7 @@ static struct pcmcia_driver fmvj18x_cs_driver = {
751 .drv = { 711 .drv = {
752 .name = "fmvj18x_cs", 712 .name = "fmvj18x_cs",
753 }, 713 },
754 .probe = fmvj18x_attach, 714 .probe = fmvj18x_probe,
755 .remove = fmvj18x_detach, 715 .remove = fmvj18x_detach,
756 .id_table = fmvj18x_ids, 716 .id_table = fmvj18x_ids,
757 .suspend = fmvj18x_suspend, 717 .suspend = fmvj18x_suspend,
@@ -1148,11 +1108,11 @@ static int fjn_config(struct net_device *dev, struct ifmap *map){
1148static int fjn_open(struct net_device *dev) 1108static int fjn_open(struct net_device *dev)
1149{ 1109{
1150 struct local_info_t *lp = netdev_priv(dev); 1110 struct local_info_t *lp = netdev_priv(dev);
1151 dev_link_t *link = &lp->link; 1111 struct pcmcia_device *link = lp->p_dev;
1152 1112
1153 DEBUG(4, "fjn_open('%s').\n", dev->name); 1113 DEBUG(4, "fjn_open('%s').\n", dev->name);
1154 1114
1155 if (!DEV_OK(link)) 1115 if (!pcmcia_dev_present(link))
1156 return -ENODEV; 1116 return -ENODEV;
1157 1117
1158 link->open++; 1118 link->open++;
@@ -1173,7 +1133,7 @@ static int fjn_open(struct net_device *dev)
1173static int fjn_close(struct net_device *dev) 1133static int fjn_close(struct net_device *dev)
1174{ 1134{
1175 struct local_info_t *lp = netdev_priv(dev); 1135 struct local_info_t *lp = netdev_priv(dev);
1176 dev_link_t *link = &lp->link; 1136 struct pcmcia_device *link = lp->p_dev;
1177 kio_addr_t ioaddr = dev->base_addr; 1137 kio_addr_t ioaddr = dev->base_addr;
1178 1138
1179 DEBUG(4, "fjn_close('%s').\n", dev->name); 1139 DEBUG(4, "fjn_close('%s').\n", dev->name);
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index b9c7e39576f5..b8fe70b85641 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -105,15 +105,15 @@ MODULE_LICENSE("GPL");
105 105
106/*====================================================================*/ 106/*====================================================================*/
107 107
108static void ibmtr_config(dev_link_t *link); 108static int ibmtr_config(struct pcmcia_device *link);
109static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase); 109static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase);
110static void ibmtr_release(dev_link_t *link); 110static void ibmtr_release(struct pcmcia_device *link);
111static void ibmtr_detach(struct pcmcia_device *p_dev); 111static void ibmtr_detach(struct pcmcia_device *p_dev);
112 112
113/*====================================================================*/ 113/*====================================================================*/
114 114
115typedef struct ibmtr_dev_t { 115typedef struct ibmtr_dev_t {
116 dev_link_t link; 116 struct pcmcia_device *p_dev;
117 struct net_device *dev; 117 struct net_device *dev;
118 dev_node_t node; 118 dev_node_t node;
119 window_handle_t sram_win_handle; 119 window_handle_t sram_win_handle;
@@ -138,12 +138,11 @@ static struct ethtool_ops netdev_ethtool_ops = {
138 138
139======================================================================*/ 139======================================================================*/
140 140
141static int ibmtr_attach(struct pcmcia_device *p_dev) 141static int ibmtr_attach(struct pcmcia_device *link)
142{ 142{
143 ibmtr_dev_t *info; 143 ibmtr_dev_t *info;
144 dev_link_t *link;
145 struct net_device *dev; 144 struct net_device *dev;
146 145
147 DEBUG(0, "ibmtr_attach()\n"); 146 DEBUG(0, "ibmtr_attach()\n");
148 147
149 /* Create new token-ring device */ 148 /* Create new token-ring device */
@@ -156,7 +155,7 @@ static int ibmtr_attach(struct pcmcia_device *p_dev)
156 return -ENOMEM; 155 return -ENOMEM;
157 } 156 }
158 157
159 link = &info->link; 158 info->p_dev = link;
160 link->priv = info; 159 link->priv = info;
161 info->ti = netdev_priv(dev); 160 info->ti = netdev_priv(dev);
162 161
@@ -167,21 +166,14 @@ static int ibmtr_attach(struct pcmcia_device *p_dev)
167 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 166 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
168 link->irq.Handler = &tok_interrupt; 167 link->irq.Handler = &tok_interrupt;
169 link->conf.Attributes = CONF_ENABLE_IRQ; 168 link->conf.Attributes = CONF_ENABLE_IRQ;
170 link->conf.Vcc = 50;
171 link->conf.IntType = INT_MEMORY_AND_IO; 169 link->conf.IntType = INT_MEMORY_AND_IO;
172 link->conf.Present = PRESENT_OPTION; 170 link->conf.Present = PRESENT_OPTION;
173 171
174 link->irq.Instance = info->dev = dev; 172 link->irq.Instance = info->dev = dev;
175
176 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
177
178 link->handle = p_dev;
179 p_dev->instance = link;
180 173
181 link->state |= DEV_PRESENT; 174 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
182 ibmtr_config(link);
183 175
184 return 0; 176 return ibmtr_config(link);
185} /* ibmtr_attach */ 177} /* ibmtr_attach */
186 178
187/*====================================================================== 179/*======================================================================
@@ -193,23 +185,22 @@ static int ibmtr_attach(struct pcmcia_device *p_dev)
193 185
194======================================================================*/ 186======================================================================*/
195 187
196static void ibmtr_detach(struct pcmcia_device *p_dev) 188static void ibmtr_detach(struct pcmcia_device *link)
197{ 189{
198 dev_link_t *link = dev_to_instance(p_dev);
199 struct ibmtr_dev_t *info = link->priv; 190 struct ibmtr_dev_t *info = link->priv;
200 struct net_device *dev = info->dev; 191 struct net_device *dev = info->dev;
201 192
202 DEBUG(0, "ibmtr_detach(0x%p)\n", link); 193 DEBUG(0, "ibmtr_detach(0x%p)\n", link);
203 194
204 if (link->dev) 195 if (link->dev_node)
205 unregister_netdev(dev); 196 unregister_netdev(dev);
206 197
207 { 198 {
208 struct tok_info *ti = netdev_priv(dev); 199 struct tok_info *ti = netdev_priv(dev);
209 del_timer_sync(&(ti->tr_timer)); 200 del_timer_sync(&(ti->tr_timer));
210 } 201 }
211 if (link->state & DEV_CONFIG) 202
212 ibmtr_release(link); 203 ibmtr_release(link);
213 204
214 free_netdev(dev); 205 free_netdev(dev);
215 kfree(info); 206 kfree(info);
@@ -226,9 +217,8 @@ static void ibmtr_detach(struct pcmcia_device *p_dev)
226#define CS_CHECK(fn, ret) \ 217#define CS_CHECK(fn, ret) \
227do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 218do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
228 219
229static void ibmtr_config(dev_link_t *link) 220static int ibmtr_config(struct pcmcia_device *link)
230{ 221{
231 client_handle_t handle = link->handle;
232 ibmtr_dev_t *info = link->priv; 222 ibmtr_dev_t *info = link->priv;
233 struct net_device *dev = info->dev; 223 struct net_device *dev = info->dev;
234 struct tok_info *ti = netdev_priv(dev); 224 struct tok_info *ti = netdev_priv(dev);
@@ -246,29 +236,25 @@ static void ibmtr_config(dev_link_t *link)
246 tuple.TupleDataMax = 64; 236 tuple.TupleDataMax = 64;
247 tuple.TupleOffset = 0; 237 tuple.TupleOffset = 0;
248 tuple.DesiredTuple = CISTPL_CONFIG; 238 tuple.DesiredTuple = CISTPL_CONFIG;
249 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 239 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
250 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 240 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
251 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 241 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
252 link->conf.ConfigBase = parse.config.base; 242 link->conf.ConfigBase = parse.config.base;
253
254 /* Configure card */
255 link->state |= DEV_CONFIG;
256
257 link->conf.ConfigIndex = 0x61; 243 link->conf.ConfigIndex = 0x61;
258 244
259 /* Determine if this is PRIMARY or ALTERNATE. */ 245 /* Determine if this is PRIMARY or ALTERNATE. */
260 246
261 /* Try PRIMARY card at 0xA20-0xA23 */ 247 /* Try PRIMARY card at 0xA20-0xA23 */
262 link->io.BasePort1 = 0xA20; 248 link->io.BasePort1 = 0xA20;
263 i = pcmcia_request_io(link->handle, &link->io); 249 i = pcmcia_request_io(link, &link->io);
264 if (i != CS_SUCCESS) { 250 if (i != CS_SUCCESS) {
265 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */ 251 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */
266 link->io.BasePort1 = 0xA24; 252 link->io.BasePort1 = 0xA24;
267 CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io)); 253 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
268 } 254 }
269 dev->base_addr = link->io.BasePort1; 255 dev->base_addr = link->io.BasePort1;
270 256
271 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 257 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
272 dev->irq = link->irq.AssignedIRQ; 258 dev->irq = link->irq.AssignedIRQ;
273 ti->irq = link->irq.AssignedIRQ; 259 ti->irq = link->irq.AssignedIRQ;
274 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq); 260 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq);
@@ -279,7 +265,7 @@ static void ibmtr_config(dev_link_t *link)
279 req.Base = 0; 265 req.Base = 0;
280 req.Size = 0x2000; 266 req.Size = 0x2000;
281 req.AccessSpeed = 250; 267 req.AccessSpeed = 250;
282 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 268 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
283 269
284 mem.CardOffset = mmiobase; 270 mem.CardOffset = mmiobase;
285 mem.Page = 0; 271 mem.Page = 0;
@@ -292,7 +278,7 @@ static void ibmtr_config(dev_link_t *link)
292 req.Base = 0; 278 req.Base = 0;
293 req.Size = sramsize * 1024; 279 req.Size = sramsize * 1024;
294 req.AccessSpeed = 250; 280 req.AccessSpeed = 250;
295 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &info->sram_win_handle)); 281 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &info->sram_win_handle));
296 282
297 mem.CardOffset = srambase; 283 mem.CardOffset = srambase;
298 mem.Page = 0; 284 mem.Page = 0;
@@ -302,21 +288,20 @@ static void ibmtr_config(dev_link_t *link)
302 ti->sram_virt = ioremap(req.Base, req.Size); 288 ti->sram_virt = ioremap(req.Base, req.Size);
303 ti->sram_phys = req.Base; 289 ti->sram_phys = req.Base;
304 290
305 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 291 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
306 292
307 /* Set up the Token-Ring Controller Configuration Register and 293 /* Set up the Token-Ring Controller Configuration Register and
308 turn on the card. Check the "Local Area Network Credit Card 294 turn on the card. Check the "Local Area Network Credit Card
309 Adapters Technical Reference" SC30-3585 for this info. */ 295 Adapters Technical Reference" SC30-3585 for this info. */
310 ibmtr_hw_setup(dev, mmiobase); 296 ibmtr_hw_setup(dev, mmiobase);
311 297
312 link->dev = &info->node; 298 link->dev_node = &info->node;
313 link->state &= ~DEV_CONFIG_PENDING; 299 SET_NETDEV_DEV(dev, &handle_to_dev(link));
314 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
315 300
316 i = ibmtr_probe_card(dev); 301 i = ibmtr_probe_card(dev);
317 if (i != 0) { 302 if (i != 0) {
318 printk(KERN_NOTICE "ibmtr_cs: register_netdev() failed\n"); 303 printk(KERN_NOTICE "ibmtr_cs: register_netdev() failed\n");
319 link->dev = NULL; 304 link->dev_node = NULL;
320 goto failed; 305 goto failed;
321 } 306 }
322 307
@@ -330,12 +315,13 @@ static void ibmtr_config(dev_link_t *link)
330 for (i = 0; i < TR_ALEN; i++) 315 for (i = 0; i < TR_ALEN; i++)
331 printk("%02X", dev->dev_addr[i]); 316 printk("%02X", dev->dev_addr[i]);
332 printk("\n"); 317 printk("\n");
333 return; 318 return 0;
334 319
335cs_failed: 320cs_failed:
336 cs_error(link->handle, last_fn, last_ret); 321 cs_error(link, last_fn, last_ret);
337failed: 322failed:
338 ibmtr_release(link); 323 ibmtr_release(link);
324 return -ENODEV;
339} /* ibmtr_config */ 325} /* ibmtr_config */
340 326
341/*====================================================================== 327/*======================================================================
@@ -346,56 +332,41 @@ failed:
346 332
347======================================================================*/ 333======================================================================*/
348 334
349static void ibmtr_release(dev_link_t *link) 335static void ibmtr_release(struct pcmcia_device *link)
350{ 336{
351 ibmtr_dev_t *info = link->priv; 337 ibmtr_dev_t *info = link->priv;
352 struct net_device *dev = info->dev; 338 struct net_device *dev = info->dev;
353
354 DEBUG(0, "ibmtr_release(0x%p)\n", link);
355 339
356 pcmcia_release_configuration(link->handle); 340 DEBUG(0, "ibmtr_release(0x%p)\n", link);
357 pcmcia_release_io(link->handle, &link->io);
358 pcmcia_release_irq(link->handle, &link->irq);
359 if (link->win) {
360 struct tok_info *ti = netdev_priv(dev);
361 iounmap(ti->mmio);
362 pcmcia_release_window(link->win);
363 pcmcia_release_window(info->sram_win_handle);
364 }
365 341
366 link->state &= ~DEV_CONFIG; 342 if (link->win) {
343 struct tok_info *ti = netdev_priv(dev);
344 iounmap(ti->mmio);
345 pcmcia_release_window(info->sram_win_handle);
346 }
347 pcmcia_disable_device(link);
367} 348}
368 349
369static int ibmtr_suspend(struct pcmcia_device *p_dev) 350static int ibmtr_suspend(struct pcmcia_device *link)
370{ 351{
371 dev_link_t *link = dev_to_instance(p_dev);
372 ibmtr_dev_t *info = link->priv; 352 ibmtr_dev_t *info = link->priv;
373 struct net_device *dev = info->dev; 353 struct net_device *dev = info->dev;
374 354
375 link->state |= DEV_SUSPEND; 355 if (link->open)
376 if (link->state & DEV_CONFIG) { 356 netif_device_detach(dev);
377 if (link->open)
378 netif_device_detach(dev);
379 pcmcia_release_configuration(link->handle);
380 }
381 357
382 return 0; 358 return 0;
383} 359}
384 360
385static int ibmtr_resume(struct pcmcia_device *p_dev) 361static int ibmtr_resume(struct pcmcia_device *link)
386{ 362{
387 dev_link_t *link = dev_to_instance(p_dev);
388 ibmtr_dev_t *info = link->priv; 363 ibmtr_dev_t *info = link->priv;
389 struct net_device *dev = info->dev; 364 struct net_device *dev = info->dev;
390 365
391 link->state &= ~DEV_SUSPEND; 366 if (link->open) {
392 if (link->state & DEV_CONFIG) { 367 ibmtr_probe(dev); /* really? */
393 pcmcia_request_configuration(link->handle, &link->conf); 368 netif_device_attach(dev);
394 if (link->open) { 369 }
395 ibmtr_probe(dev); /* really? */
396 netif_device_attach(dev);
397 }
398 }
399 370
400 return 0; 371 return 0;
401} 372}
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index 787176c57fd9..4260c2128f47 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -362,7 +362,7 @@ typedef struct _mace_statistics {
362} mace_statistics; 362} mace_statistics;
363 363
364typedef struct _mace_private { 364typedef struct _mace_private {
365 dev_link_t link; 365 struct pcmcia_device *p_dev;
366 dev_node_t node; 366 dev_node_t node;
367 struct net_device_stats linux_stats; /* Linux statistics counters */ 367 struct net_device_stats linux_stats; /* Linux statistics counters */
368 mace_statistics mace_stats; /* MACE chip statistics counters */ 368 mace_statistics mace_stats; /* MACE chip statistics counters */
@@ -417,8 +417,8 @@ INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
417Function Prototypes 417Function Prototypes
418---------------------------------------------------------------------------- */ 418---------------------------------------------------------------------------- */
419 419
420static void nmclan_config(dev_link_t *link); 420static int nmclan_config(struct pcmcia_device *link);
421static void nmclan_release(dev_link_t *link); 421static void nmclan_release(struct pcmcia_device *link);
422 422
423static void nmclan_reset(struct net_device *dev); 423static void nmclan_reset(struct net_device *dev);
424static int mace_config(struct net_device *dev, struct ifmap *map); 424static int mace_config(struct net_device *dev, struct ifmap *map);
@@ -443,10 +443,9 @@ nmclan_attach
443 Services. 443 Services.
444---------------------------------------------------------------------------- */ 444---------------------------------------------------------------------------- */
445 445
446static int nmclan_attach(struct pcmcia_device *p_dev) 446static int nmclan_probe(struct pcmcia_device *link)
447{ 447{
448 mace_private *lp; 448 mace_private *lp;
449 dev_link_t *link;
450 struct net_device *dev; 449 struct net_device *dev;
451 450
452 DEBUG(0, "nmclan_attach()\n"); 451 DEBUG(0, "nmclan_attach()\n");
@@ -457,7 +456,7 @@ static int nmclan_attach(struct pcmcia_device *p_dev)
457 if (!dev) 456 if (!dev)
458 return -ENOMEM; 457 return -ENOMEM;
459 lp = netdev_priv(dev); 458 lp = netdev_priv(dev);
460 link = &lp->link; 459 lp->p_dev = link;
461 link->priv = dev; 460 link->priv = dev;
462 461
463 spin_lock_init(&lp->bank_lock); 462 spin_lock_init(&lp->bank_lock);
@@ -469,7 +468,6 @@ static int nmclan_attach(struct pcmcia_device *p_dev)
469 link->irq.Handler = &mace_interrupt; 468 link->irq.Handler = &mace_interrupt;
470 link->irq.Instance = dev; 469 link->irq.Instance = dev;
471 link->conf.Attributes = CONF_ENABLE_IRQ; 470 link->conf.Attributes = CONF_ENABLE_IRQ;
472 link->conf.Vcc = 50;
473 link->conf.IntType = INT_MEMORY_AND_IO; 471 link->conf.IntType = INT_MEMORY_AND_IO;
474 link->conf.ConfigIndex = 1; 472 link->conf.ConfigIndex = 1;
475 link->conf.Present = PRESENT_OPTION; 473 link->conf.Present = PRESENT_OPTION;
@@ -489,13 +487,7 @@ static int nmclan_attach(struct pcmcia_device *p_dev)
489 dev->watchdog_timeo = TX_TIMEOUT; 487 dev->watchdog_timeo = TX_TIMEOUT;
490#endif 488#endif
491 489
492 link->handle = p_dev; 490 return nmclan_config(link);
493 p_dev->instance = link;
494
495 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
496 nmclan_config(link);
497
498 return 0;
499} /* nmclan_attach */ 491} /* nmclan_attach */
500 492
501/* ---------------------------------------------------------------------------- 493/* ----------------------------------------------------------------------------
@@ -506,18 +498,16 @@ nmclan_detach
506 when the device is released. 498 when the device is released.
507---------------------------------------------------------------------------- */ 499---------------------------------------------------------------------------- */
508 500
509static void nmclan_detach(struct pcmcia_device *p_dev) 501static void nmclan_detach(struct pcmcia_device *link)
510{ 502{
511 dev_link_t *link = dev_to_instance(p_dev);
512 struct net_device *dev = link->priv; 503 struct net_device *dev = link->priv;
513 504
514 DEBUG(0, "nmclan_detach(0x%p)\n", link); 505 DEBUG(0, "nmclan_detach(0x%p)\n", link);
515 506
516 if (link->dev) 507 if (link->dev_node)
517 unregister_netdev(dev); 508 unregister_netdev(dev);
518 509
519 if (link->state & DEV_CONFIG) 510 nmclan_release(link);
520 nmclan_release(link);
521 511
522 free_netdev(dev); 512 free_netdev(dev);
523} /* nmclan_detach */ 513} /* nmclan_detach */
@@ -661,9 +651,8 @@ nmclan_config
661#define CS_CHECK(fn, ret) \ 651#define CS_CHECK(fn, ret) \
662 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 652 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
663 653
664static void nmclan_config(dev_link_t *link) 654static int nmclan_config(struct pcmcia_device *link)
665{ 655{
666 client_handle_t handle = link->handle;
667 struct net_device *dev = link->priv; 656 struct net_device *dev = link->priv;
668 mace_private *lp = netdev_priv(dev); 657 mace_private *lp = netdev_priv(dev);
669 tuple_t tuple; 658 tuple_t tuple;
@@ -679,17 +668,14 @@ static void nmclan_config(dev_link_t *link)
679 tuple.TupleDataMax = 64; 668 tuple.TupleDataMax = 64;
680 tuple.TupleOffset = 0; 669 tuple.TupleOffset = 0;
681 tuple.DesiredTuple = CISTPL_CONFIG; 670 tuple.DesiredTuple = CISTPL_CONFIG;
682 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 671 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
683 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 672 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
684 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 673 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
685 link->conf.ConfigBase = parse.config.base; 674 link->conf.ConfigBase = parse.config.base;
686 675
687 /* Configure card */ 676 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
688 link->state |= DEV_CONFIG; 677 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
689 678 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
690 CS_CHECK(RequestIO, pcmcia_request_io(handle, &link->io));
691 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
692 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
693 dev->irq = link->irq.AssignedIRQ; 679 dev->irq = link->irq.AssignedIRQ;
694 dev->base_addr = link->io.BasePort1; 680 dev->base_addr = link->io.BasePort1;
695 681
@@ -700,8 +686,8 @@ static void nmclan_config(dev_link_t *link)
700 tuple.TupleData = buf; 686 tuple.TupleData = buf;
701 tuple.TupleDataMax = 64; 687 tuple.TupleDataMax = 64;
702 tuple.TupleOffset = 0; 688 tuple.TupleOffset = 0;
703 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 689 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
704 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 690 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
705 memcpy(dev->dev_addr, tuple.TupleData, ETHER_ADDR_LEN); 691 memcpy(dev->dev_addr, tuple.TupleData, ETHER_ADDR_LEN);
706 692
707 /* Verify configuration by reading the MACE ID. */ 693 /* Verify configuration by reading the MACE ID. */
@@ -716,8 +702,7 @@ static void nmclan_config(dev_link_t *link)
716 } else { 702 } else {
717 printk(KERN_NOTICE "nmclan_cs: mace id not found: %x %x should" 703 printk(KERN_NOTICE "nmclan_cs: mace id not found: %x %x should"
718 " be 0x40 0x?9\n", sig[0], sig[1]); 704 " be 0x40 0x?9\n", sig[0], sig[1]);
719 link->state &= ~DEV_CONFIG_PENDING; 705 return -ENODEV;
720 return;
721 } 706 }
722 } 707 }
723 708
@@ -730,14 +715,13 @@ static void nmclan_config(dev_link_t *link)
730 else 715 else
731 printk(KERN_NOTICE "nmclan_cs: invalid if_port requested\n"); 716 printk(KERN_NOTICE "nmclan_cs: invalid if_port requested\n");
732 717
733 link->dev = &lp->node; 718 link->dev_node = &lp->node;
734 link->state &= ~DEV_CONFIG_PENDING; 719 SET_NETDEV_DEV(dev, &handle_to_dev(link));
735 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
736 720
737 i = register_netdev(dev); 721 i = register_netdev(dev);
738 if (i != 0) { 722 if (i != 0) {
739 printk(KERN_NOTICE "nmclan_cs: register_netdev() failed\n"); 723 printk(KERN_NOTICE "nmclan_cs: register_netdev() failed\n");
740 link->dev = NULL; 724 link->dev_node = NULL;
741 goto failed; 725 goto failed;
742 } 726 }
743 727
@@ -747,14 +731,13 @@ static void nmclan_config(dev_link_t *link)
747 dev->name, dev->base_addr, dev->irq, if_names[dev->if_port]); 731 dev->name, dev->base_addr, dev->irq, if_names[dev->if_port]);
748 for (i = 0; i < 6; i++) 732 for (i = 0; i < 6; i++)
749 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 733 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
750 return; 734 return 0;
751 735
752cs_failed: 736cs_failed:
753 cs_error(link->handle, last_fn, last_ret); 737 cs_error(link, last_fn, last_ret);
754failed: 738failed:
755 nmclan_release(link); 739 nmclan_release(link);
756 return; 740 return -ENODEV;
757
758} /* nmclan_config */ 741} /* nmclan_config */
759 742
760/* ---------------------------------------------------------------------------- 743/* ----------------------------------------------------------------------------
@@ -763,46 +746,29 @@ nmclan_release
763 net device, and release the PCMCIA configuration. If the device 746 net device, and release the PCMCIA configuration. If the device
764 is still open, this will be postponed until it is closed. 747 is still open, this will be postponed until it is closed.
765---------------------------------------------------------------------------- */ 748---------------------------------------------------------------------------- */
766static void nmclan_release(dev_link_t *link) 749static void nmclan_release(struct pcmcia_device *link)
767{ 750{
768 751 DEBUG(0, "nmclan_release(0x%p)\n", link);
769 DEBUG(0, "nmclan_release(0x%p)\n", link); 752 pcmcia_disable_device(link);
770
771 pcmcia_release_configuration(link->handle);
772 pcmcia_release_io(link->handle, &link->io);
773 pcmcia_release_irq(link->handle, &link->irq);
774
775 link->state &= ~DEV_CONFIG;
776} 753}
777 754
778static int nmclan_suspend(struct pcmcia_device *p_dev) 755static int nmclan_suspend(struct pcmcia_device *link)
779{ 756{
780 dev_link_t *link = dev_to_instance(p_dev);
781 struct net_device *dev = link->priv; 757 struct net_device *dev = link->priv;
782 758
783 link->state |= DEV_SUSPEND; 759 if (link->open)
784 if (link->state & DEV_CONFIG) { 760 netif_device_detach(dev);
785 if (link->open)
786 netif_device_detach(dev);
787 pcmcia_release_configuration(link->handle);
788 }
789
790 761
791 return 0; 762 return 0;
792} 763}
793 764
794static int nmclan_resume(struct pcmcia_device *p_dev) 765static int nmclan_resume(struct pcmcia_device *link)
795{ 766{
796 dev_link_t *link = dev_to_instance(p_dev);
797 struct net_device *dev = link->priv; 767 struct net_device *dev = link->priv;
798 768
799 link->state &= ~DEV_SUSPEND; 769 if (link->open) {
800 if (link->state & DEV_CONFIG) { 770 nmclan_reset(dev);
801 pcmcia_request_configuration(link->handle, &link->conf); 771 netif_device_attach(dev);
802 if (link->open) {
803 nmclan_reset(dev);
804 netif_device_attach(dev);
805 }
806 } 772 }
807 773
808 return 0; 774 return 0;
@@ -818,7 +784,7 @@ static void nmclan_reset(struct net_device *dev)
818 mace_private *lp = netdev_priv(dev); 784 mace_private *lp = netdev_priv(dev);
819 785
820#if RESET_XILINX 786#if RESET_XILINX
821 dev_link_t *link = &lp->link; 787 struct pcmcia_device *link = &lp->link;
822 conf_reg_t reg; 788 conf_reg_t reg;
823 u_long OrigCorValue; 789 u_long OrigCorValue;
824 790
@@ -827,7 +793,7 @@ static void nmclan_reset(struct net_device *dev)
827 reg.Action = CS_READ; 793 reg.Action = CS_READ;
828 reg.Offset = CISREG_COR; 794 reg.Offset = CISREG_COR;
829 reg.Value = 0; 795 reg.Value = 0;
830 pcmcia_access_configuration_register(link->handle, &reg); 796 pcmcia_access_configuration_register(link, &reg);
831 OrigCorValue = reg.Value; 797 OrigCorValue = reg.Value;
832 798
833 /* Reset Xilinx */ 799 /* Reset Xilinx */
@@ -836,12 +802,12 @@ static void nmclan_reset(struct net_device *dev)
836 DEBUG(1, "nmclan_reset: OrigCorValue=0x%lX, resetting...\n", 802 DEBUG(1, "nmclan_reset: OrigCorValue=0x%lX, resetting...\n",
837 OrigCorValue); 803 OrigCorValue);
838 reg.Value = COR_SOFT_RESET; 804 reg.Value = COR_SOFT_RESET;
839 pcmcia_access_configuration_register(link->handle, &reg); 805 pcmcia_access_configuration_register(link, &reg);
840 /* Need to wait for 20 ms for PCMCIA to finish reset. */ 806 /* Need to wait for 20 ms for PCMCIA to finish reset. */
841 807
842 /* Restore original COR configuration index */ 808 /* Restore original COR configuration index */
843 reg.Value = COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK); 809 reg.Value = COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK);
844 pcmcia_access_configuration_register(link->handle, &reg); 810 pcmcia_access_configuration_register(link, &reg);
845 /* Xilinx is now completely reset along with the MACE chip. */ 811 /* Xilinx is now completely reset along with the MACE chip. */
846 lp->tx_free_frames=AM2150_MAX_TX_FRAMES; 812 lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
847 813
@@ -885,9 +851,9 @@ static int mace_open(struct net_device *dev)
885{ 851{
886 kio_addr_t ioaddr = dev->base_addr; 852 kio_addr_t ioaddr = dev->base_addr;
887 mace_private *lp = netdev_priv(dev); 853 mace_private *lp = netdev_priv(dev);
888 dev_link_t *link = &lp->link; 854 struct pcmcia_device *link = lp->p_dev;
889 855
890 if (!DEV_OK(link)) 856 if (!pcmcia_dev_present(link))
891 return -ENODEV; 857 return -ENODEV;
892 858
893 link->open++; 859 link->open++;
@@ -908,7 +874,7 @@ static int mace_close(struct net_device *dev)
908{ 874{
909 kio_addr_t ioaddr = dev->base_addr; 875 kio_addr_t ioaddr = dev->base_addr;
910 mace_private *lp = netdev_priv(dev); 876 mace_private *lp = netdev_priv(dev);
911 dev_link_t *link = &lp->link; 877 struct pcmcia_device *link = lp->p_dev;
912 878
913 DEBUG(2, "%s: shutting down ethercard.\n", dev->name); 879 DEBUG(2, "%s: shutting down ethercard.\n", dev->name);
914 880
@@ -963,12 +929,12 @@ mace_start_xmit
963static void mace_tx_timeout(struct net_device *dev) 929static void mace_tx_timeout(struct net_device *dev)
964{ 930{
965 mace_private *lp = netdev_priv(dev); 931 mace_private *lp = netdev_priv(dev);
966 dev_link_t *link = &lp->link; 932 struct pcmcia_device *link = lp->p_dev;
967 933
968 printk(KERN_NOTICE "%s: transmit timed out -- ", dev->name); 934 printk(KERN_NOTICE "%s: transmit timed out -- ", dev->name);
969#if RESET_ON_TIMEOUT 935#if RESET_ON_TIMEOUT
970 printk("resetting card\n"); 936 printk("resetting card\n");
971 pcmcia_reset_card(link->handle, NULL); 937 pcmcia_reset_card(link, NULL);
972#else /* #if RESET_ON_TIMEOUT */ 938#else /* #if RESET_ON_TIMEOUT */
973 printk("NOT resetting card\n"); 939 printk("NOT resetting card\n");
974#endif /* #if RESET_ON_TIMEOUT */ 940#endif /* #if RESET_ON_TIMEOUT */
@@ -1635,7 +1601,7 @@ static struct pcmcia_driver nmclan_cs_driver = {
1635 .drv = { 1601 .drv = {
1636 .name = "nmclan_cs", 1602 .name = "nmclan_cs",
1637 }, 1603 },
1638 .probe = nmclan_attach, 1604 .probe = nmclan_probe,
1639 .remove = nmclan_detach, 1605 .remove = nmclan_detach,
1640 .id_table = nmclan_ids, 1606 .id_table = nmclan_ids,
1641 .suspend = nmclan_suspend, 1607 .suspend = nmclan_suspend,
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index b46e5f703efa..506e777c5f06 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -103,8 +103,8 @@ module_param_array(hw_addr, int, NULL, 0);
103/*====================================================================*/ 103/*====================================================================*/
104 104
105static void mii_phy_probe(struct net_device *dev); 105static void mii_phy_probe(struct net_device *dev);
106static void pcnet_config(dev_link_t *link); 106static int pcnet_config(struct pcmcia_device *link);
107static void pcnet_release(dev_link_t *link); 107static void pcnet_release(struct pcmcia_device *link);
108static int pcnet_open(struct net_device *dev); 108static int pcnet_open(struct net_device *dev);
109static int pcnet_close(struct net_device *dev); 109static int pcnet_close(struct net_device *dev);
110static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 110static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -113,9 +113,9 @@ static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs);
113static void ei_watchdog(u_long arg); 113static void ei_watchdog(u_long arg);
114static void pcnet_reset_8390(struct net_device *dev); 114static void pcnet_reset_8390(struct net_device *dev);
115static int set_config(struct net_device *dev, struct ifmap *map); 115static int set_config(struct net_device *dev, struct ifmap *map);
116static int setup_shmem_window(dev_link_t *link, int start_pg, 116static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
117 int stop_pg, int cm_offset); 117 int stop_pg, int cm_offset);
118static int setup_dma_config(dev_link_t *link, int start_pg, 118static int setup_dma_config(struct pcmcia_device *link, int start_pg,
119 int stop_pg); 119 int stop_pg);
120 120
121static void pcnet_detach(struct pcmcia_device *p_dev); 121static void pcnet_detach(struct pcmcia_device *p_dev);
@@ -214,7 +214,7 @@ static hw_info_t dl10019_info = { 0, 0, 0, 0, IS_DL10019|HAS_MII };
214static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII }; 214static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };
215 215
216typedef struct pcnet_dev_t { 216typedef struct pcnet_dev_t {
217 dev_link_t link; 217 struct pcmcia_device *p_dev;
218 dev_node_t node; 218 dev_node_t node;
219 u_int flags; 219 u_int flags;
220 void __iomem *base; 220 void __iomem *base;
@@ -240,10 +240,9 @@ static inline pcnet_dev_t *PRIV(struct net_device *dev)
240 240
241======================================================================*/ 241======================================================================*/
242 242
243static int pcnet_probe(struct pcmcia_device *p_dev) 243static int pcnet_probe(struct pcmcia_device *link)
244{ 244{
245 pcnet_dev_t *info; 245 pcnet_dev_t *info;
246 dev_link_t *link;
247 struct net_device *dev; 246 struct net_device *dev;
248 247
249 DEBUG(0, "pcnet_attach()\n"); 248 DEBUG(0, "pcnet_attach()\n");
@@ -252,7 +251,7 @@ static int pcnet_probe(struct pcmcia_device *p_dev)
252 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t)); 251 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t));
253 if (!dev) return -ENOMEM; 252 if (!dev) return -ENOMEM;
254 info = PRIV(dev); 253 info = PRIV(dev);
255 link = &info->link; 254 info->p_dev = link;
256 link->priv = dev; 255 link->priv = dev;
257 256
258 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 257 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
@@ -265,13 +264,7 @@ static int pcnet_probe(struct pcmcia_device *p_dev)
265 dev->stop = &pcnet_close; 264 dev->stop = &pcnet_close;
266 dev->set_config = &set_config; 265 dev->set_config = &set_config;
267 266
268 link->handle = p_dev; 267 return pcnet_config(link);
269 p_dev->instance = link;
270
271 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
272 pcnet_config(link);
273
274 return 0;
275} /* pcnet_attach */ 268} /* pcnet_attach */
276 269
277/*====================================================================== 270/*======================================================================
@@ -283,18 +276,16 @@ static int pcnet_probe(struct pcmcia_device *p_dev)
283 276
284======================================================================*/ 277======================================================================*/
285 278
286static void pcnet_detach(struct pcmcia_device *p_dev) 279static void pcnet_detach(struct pcmcia_device *link)
287{ 280{
288 dev_link_t *link = dev_to_instance(p_dev);
289 struct net_device *dev = link->priv; 281 struct net_device *dev = link->priv;
290 282
291 DEBUG(0, "pcnet_detach(0x%p)\n", link); 283 DEBUG(0, "pcnet_detach(0x%p)\n", link);
292 284
293 if (link->dev) 285 if (link->dev_node)
294 unregister_netdev(dev); 286 unregister_netdev(dev);
295 287
296 if (link->state & DEV_CONFIG) 288 pcnet_release(link);
297 pcnet_release(link);
298 289
299 free_netdev(dev); 290 free_netdev(dev);
300} /* pcnet_detach */ 291} /* pcnet_detach */
@@ -306,7 +297,7 @@ static void pcnet_detach(struct pcmcia_device *p_dev)
306 297
307======================================================================*/ 298======================================================================*/
308 299
309static hw_info_t *get_hwinfo(dev_link_t *link) 300static hw_info_t *get_hwinfo(struct pcmcia_device *link)
310{ 301{
311 struct net_device *dev = link->priv; 302 struct net_device *dev = link->priv;
312 win_req_t req; 303 win_req_t req;
@@ -318,9 +309,9 @@ static hw_info_t *get_hwinfo(dev_link_t *link)
318 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 309 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
319 req.Base = 0; req.Size = 0; 310 req.Base = 0; req.Size = 0;
320 req.AccessSpeed = 0; 311 req.AccessSpeed = 0;
321 i = pcmcia_request_window(&link->handle, &req, &link->win); 312 i = pcmcia_request_window(&link, &req, &link->win);
322 if (i != CS_SUCCESS) { 313 if (i != CS_SUCCESS) {
323 cs_error(link->handle, RequestWindow, i); 314 cs_error(link, RequestWindow, i);
324 return NULL; 315 return NULL;
325 } 316 }
326 317
@@ -343,7 +334,7 @@ static hw_info_t *get_hwinfo(dev_link_t *link)
343 iounmap(virt); 334 iounmap(virt);
344 j = pcmcia_release_window(link->win); 335 j = pcmcia_release_window(link->win);
345 if (j != CS_SUCCESS) 336 if (j != CS_SUCCESS)
346 cs_error(link->handle, ReleaseWindow, j); 337 cs_error(link, ReleaseWindow, j);
347 return (i < NR_INFO) ? hw_info+i : NULL; 338 return (i < NR_INFO) ? hw_info+i : NULL;
348} /* get_hwinfo */ 339} /* get_hwinfo */
349 340
@@ -355,7 +346,7 @@ static hw_info_t *get_hwinfo(dev_link_t *link)
355 346
356======================================================================*/ 347======================================================================*/
357 348
358static hw_info_t *get_prom(dev_link_t *link) 349static hw_info_t *get_prom(struct pcmcia_device *link)
359{ 350{
360 struct net_device *dev = link->priv; 351 struct net_device *dev = link->priv;
361 kio_addr_t ioaddr = dev->base_addr; 352 kio_addr_t ioaddr = dev->base_addr;
@@ -409,7 +400,7 @@ static hw_info_t *get_prom(dev_link_t *link)
409 400
410======================================================================*/ 401======================================================================*/
411 402
412static hw_info_t *get_dl10019(dev_link_t *link) 403static hw_info_t *get_dl10019(struct pcmcia_device *link)
413{ 404{
414 struct net_device *dev = link->priv; 405 struct net_device *dev = link->priv;
415 int i; 406 int i;
@@ -431,7 +422,7 @@ static hw_info_t *get_dl10019(dev_link_t *link)
431 422
432======================================================================*/ 423======================================================================*/
433 424
434static hw_info_t *get_ax88190(dev_link_t *link) 425static hw_info_t *get_ax88190(struct pcmcia_device *link)
435{ 426{
436 struct net_device *dev = link->priv; 427 struct net_device *dev = link->priv;
437 kio_addr_t ioaddr = dev->base_addr; 428 kio_addr_t ioaddr = dev->base_addr;
@@ -464,7 +455,7 @@ static hw_info_t *get_ax88190(dev_link_t *link)
464 455
465======================================================================*/ 456======================================================================*/
466 457
467static hw_info_t *get_hwired(dev_link_t *link) 458static hw_info_t *get_hwired(struct pcmcia_device *link)
468{ 459{
469 struct net_device *dev = link->priv; 460 struct net_device *dev = link->priv;
470 int i; 461 int i;
@@ -491,7 +482,7 @@ static hw_info_t *get_hwired(dev_link_t *link)
491#define CS_CHECK(fn, ret) \ 482#define CS_CHECK(fn, ret) \
492do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 483do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
493 484
494static int try_io_port(dev_link_t *link) 485static int try_io_port(struct pcmcia_device *link)
495{ 486{
496 int j, ret; 487 int j, ret;
497 if (link->io.NumPorts1 == 32) { 488 if (link->io.NumPorts1 == 32) {
@@ -512,18 +503,17 @@ static int try_io_port(dev_link_t *link)
512 for (j = 0; j < 0x400; j += 0x20) { 503 for (j = 0; j < 0x400; j += 0x20) {
513 link->io.BasePort1 = j ^ 0x300; 504 link->io.BasePort1 = j ^ 0x300;
514 link->io.BasePort2 = (j ^ 0x300) + 0x10; 505 link->io.BasePort2 = (j ^ 0x300) + 0x10;
515 ret = pcmcia_request_io(link->handle, &link->io); 506 ret = pcmcia_request_io(link, &link->io);
516 if (ret == CS_SUCCESS) return ret; 507 if (ret == CS_SUCCESS) return ret;
517 } 508 }
518 return ret; 509 return ret;
519 } else { 510 } else {
520 return pcmcia_request_io(link->handle, &link->io); 511 return pcmcia_request_io(link, &link->io);
521 } 512 }
522} 513}
523 514
524static void pcnet_config(dev_link_t *link) 515static int pcnet_config(struct pcmcia_device *link)
525{ 516{
526 client_handle_t handle = link->handle;
527 struct net_device *dev = link->priv; 517 struct net_device *dev = link->priv;
528 pcnet_dev_t *info = PRIV(dev); 518 pcnet_dev_t *info = PRIV(dev);
529 tuple_t tuple; 519 tuple_t tuple;
@@ -531,7 +521,6 @@ static void pcnet_config(dev_link_t *link)
531 int i, last_ret, last_fn, start_pg, stop_pg, cm_offset; 521 int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
532 int manfid = 0, prodid = 0, has_shmem = 0; 522 int manfid = 0, prodid = 0, has_shmem = 0;
533 u_short buf[64]; 523 u_short buf[64];
534 config_info_t conf;
535 hw_info_t *hw_info; 524 hw_info_t *hw_info;
536 525
537 DEBUG(0, "pcnet_config(0x%p)\n", link); 526 DEBUG(0, "pcnet_config(0x%p)\n", link);
@@ -541,36 +530,29 @@ static void pcnet_config(dev_link_t *link)
541 tuple.TupleDataMax = sizeof(buf); 530 tuple.TupleDataMax = sizeof(buf);
542 tuple.TupleOffset = 0; 531 tuple.TupleOffset = 0;
543 tuple.DesiredTuple = CISTPL_CONFIG; 532 tuple.DesiredTuple = CISTPL_CONFIG;
544 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 533 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
545 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 534 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
546 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 535 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
547 link->conf.ConfigBase = parse.config.base; 536 link->conf.ConfigBase = parse.config.base;
548 link->conf.Present = parse.config.rmask[0]; 537 link->conf.Present = parse.config.rmask[0];
549 538
550 /* Configure card */
551 link->state |= DEV_CONFIG;
552
553 /* Look up current Vcc */
554 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
555 link->conf.Vcc = conf.Vcc;
556
557 tuple.DesiredTuple = CISTPL_MANFID; 539 tuple.DesiredTuple = CISTPL_MANFID;
558 tuple.Attributes = TUPLE_RETURN_COMMON; 540 tuple.Attributes = TUPLE_RETURN_COMMON;
559 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 541 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) &&
560 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) { 542 (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)) {
561 manfid = le16_to_cpu(buf[0]); 543 manfid = le16_to_cpu(buf[0]);
562 prodid = le16_to_cpu(buf[1]); 544 prodid = le16_to_cpu(buf[1]);
563 } 545 }
564 546
565 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 547 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
566 tuple.Attributes = 0; 548 tuple.Attributes = 0;
567 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 549 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
568 while (last_ret == CS_SUCCESS) { 550 while (last_ret == CS_SUCCESS) {
569 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 551 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
570 cistpl_io_t *io = &(parse.cftable_entry.io); 552 cistpl_io_t *io = &(parse.cftable_entry.io);
571 553
572 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 554 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
573 pcmcia_parse_tuple(handle, &tuple, &parse) != 0 || 555 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
574 cfg->index == 0 || cfg->io.nwin == 0) 556 cfg->index == 0 || cfg->io.nwin == 0)
575 goto next_entry; 557 goto next_entry;
576 558
@@ -594,14 +576,14 @@ static void pcnet_config(dev_link_t *link)
594 if (last_ret == CS_SUCCESS) break; 576 if (last_ret == CS_SUCCESS) break;
595 } 577 }
596 next_entry: 578 next_entry:
597 last_ret = pcmcia_get_next_tuple(handle, &tuple); 579 last_ret = pcmcia_get_next_tuple(link, &tuple);
598 } 580 }
599 if (last_ret != CS_SUCCESS) { 581 if (last_ret != CS_SUCCESS) {
600 cs_error(handle, RequestIO, last_ret); 582 cs_error(link, RequestIO, last_ret);
601 goto failed; 583 goto failed;
602 } 584 }
603 585
604 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 586 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
605 587
606 if (link->io.NumPorts2 == 8) { 588 if (link->io.NumPorts2 == 8) {
607 link->conf.Attributes |= CONF_ENABLE_SPKR; 589 link->conf.Attributes |= CONF_ENABLE_SPKR;
@@ -611,7 +593,7 @@ static void pcnet_config(dev_link_t *link)
611 (prodid == PRODID_IBM_HOME_AND_AWAY)) 593 (prodid == PRODID_IBM_HOME_AND_AWAY))
612 link->conf.ConfigIndex |= 0x10; 594 link->conf.ConfigIndex |= 0x10;
613 595
614 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 596 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
615 dev->irq = link->irq.AssignedIRQ; 597 dev->irq = link->irq.AssignedIRQ;
616 dev->base_addr = link->io.BasePort1; 598 dev->base_addr = link->io.BasePort1;
617 if (info->flags & HAS_MISC_REG) { 599 if (info->flags & HAS_MISC_REG) {
@@ -679,9 +661,8 @@ static void pcnet_config(dev_link_t *link)
679 info->eth_phy = 0; 661 info->eth_phy = 0;
680 } 662 }
681 663
682 link->dev = &info->node; 664 link->dev_node = &info->node;
683 link->state &= ~DEV_CONFIG_PENDING; 665 SET_NETDEV_DEV(dev, &handle_to_dev(link));
684 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
685 666
686#ifdef CONFIG_NET_POLL_CONTROLLER 667#ifdef CONFIG_NET_POLL_CONTROLLER
687 dev->poll_controller = ei_poll; 668 dev->poll_controller = ei_poll;
@@ -689,7 +670,7 @@ static void pcnet_config(dev_link_t *link)
689 670
690 if (register_netdev(dev) != 0) { 671 if (register_netdev(dev) != 0) {
691 printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n"); 672 printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");
692 link->dev = NULL; 673 link->dev_node = NULL;
693 goto failed; 674 goto failed;
694 } 675 }
695 676
@@ -712,14 +693,13 @@ static void pcnet_config(dev_link_t *link)
712 printk(" hw_addr "); 693 printk(" hw_addr ");
713 for (i = 0; i < 6; i++) 694 for (i = 0; i < 6; i++)
714 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 695 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
715 return; 696 return 0;
716 697
717cs_failed: 698cs_failed:
718 cs_error(link->handle, last_fn, last_ret); 699 cs_error(link, last_fn, last_ret);
719failed: 700failed:
720 pcnet_release(link); 701 pcnet_release(link);
721 link->state &= ~DEV_CONFIG_PENDING; 702 return -ENODEV;
722 return;
723} /* pcnet_config */ 703} /* pcnet_config */
724 704
725/*====================================================================== 705/*======================================================================
@@ -730,21 +710,16 @@ failed:
730 710
731======================================================================*/ 711======================================================================*/
732 712
733static void pcnet_release(dev_link_t *link) 713static void pcnet_release(struct pcmcia_device *link)
734{ 714{
735 pcnet_dev_t *info = PRIV(link->priv); 715 pcnet_dev_t *info = PRIV(link->priv);
736 716
737 DEBUG(0, "pcnet_release(0x%p)\n", link); 717 DEBUG(0, "pcnet_release(0x%p)\n", link);
738 718
739 if (info->flags & USE_SHMEM) { 719 if (info->flags & USE_SHMEM)
740 iounmap(info->base); 720 iounmap(info->base);
741 pcmcia_release_window(link->win);
742 }
743 pcmcia_release_configuration(link->handle);
744 pcmcia_release_io(link->handle, &link->io);
745 pcmcia_release_irq(link->handle, &link->irq);
746 721
747 link->state &= ~DEV_CONFIG; 722 pcmcia_disable_device(link);
748} 723}
749 724
750/*====================================================================== 725/*======================================================================
@@ -756,34 +731,24 @@ static void pcnet_release(dev_link_t *link)
756 731
757======================================================================*/ 732======================================================================*/
758 733
759static int pcnet_suspend(struct pcmcia_device *p_dev) 734static int pcnet_suspend(struct pcmcia_device *link)
760{ 735{
761 dev_link_t *link = dev_to_instance(p_dev);
762 struct net_device *dev = link->priv; 736 struct net_device *dev = link->priv;
763 737
764 link->state |= DEV_SUSPEND; 738 if (link->open)
765 if (link->state & DEV_CONFIG) { 739 netif_device_detach(dev);
766 if (link->open)
767 netif_device_detach(dev);
768 pcmcia_release_configuration(link->handle);
769 }
770 740
771 return 0; 741 return 0;
772} 742}
773 743
774static int pcnet_resume(struct pcmcia_device *p_dev) 744static int pcnet_resume(struct pcmcia_device *link)
775{ 745{
776 dev_link_t *link = dev_to_instance(p_dev);
777 struct net_device *dev = link->priv; 746 struct net_device *dev = link->priv;
778 747
779 link->state &= ~DEV_SUSPEND; 748 if (link->open) {
780 if (link->state & DEV_CONFIG) { 749 pcnet_reset_8390(dev);
781 pcmcia_request_configuration(link->handle, &link->conf); 750 NS8390_init(dev, 1);
782 if (link->open) { 751 netif_device_attach(dev);
783 pcnet_reset_8390(dev);
784 NS8390_init(dev, 1);
785 netif_device_attach(dev);
786 }
787 } 752 }
788 753
789 return 0; 754 return 0;
@@ -1023,11 +988,11 @@ static void mii_phy_probe(struct net_device *dev)
1023static int pcnet_open(struct net_device *dev) 988static int pcnet_open(struct net_device *dev)
1024{ 989{
1025 pcnet_dev_t *info = PRIV(dev); 990 pcnet_dev_t *info = PRIV(dev);
1026 dev_link_t *link = &info->link; 991 struct pcmcia_device *link = info->p_dev;
1027 992
1028 DEBUG(2, "pcnet_open('%s')\n", dev->name); 993 DEBUG(2, "pcnet_open('%s')\n", dev->name);
1029 994
1030 if (!DEV_OK(link)) 995 if (!pcmcia_dev_present(link))
1031 return -ENODEV; 996 return -ENODEV;
1032 997
1033 link->open++; 998 link->open++;
@@ -1051,7 +1016,7 @@ static int pcnet_open(struct net_device *dev)
1051static int pcnet_close(struct net_device *dev) 1016static int pcnet_close(struct net_device *dev)
1052{ 1017{
1053 pcnet_dev_t *info = PRIV(dev); 1018 pcnet_dev_t *info = PRIV(dev);
1054 dev_link_t *link = &info->link; 1019 struct pcmcia_device *link = info->p_dev;
1055 1020
1056 DEBUG(2, "pcnet_close('%s')\n", dev->name); 1021 DEBUG(2, "pcnet_close('%s')\n", dev->name);
1057 1022
@@ -1429,7 +1394,7 @@ static void dma_block_output(struct net_device *dev, int count,
1429 1394
1430/*====================================================================*/ 1395/*====================================================================*/
1431 1396
1432static int setup_dma_config(dev_link_t *link, int start_pg, 1397static int setup_dma_config(struct pcmcia_device *link, int start_pg,
1433 int stop_pg) 1398 int stop_pg)
1434{ 1399{
1435 struct net_device *dev = link->priv; 1400 struct net_device *dev = link->priv;
@@ -1532,7 +1497,7 @@ static void shmem_block_output(struct net_device *dev, int count,
1532 1497
1533/*====================================================================*/ 1498/*====================================================================*/
1534 1499
1535static int setup_shmem_window(dev_link_t *link, int start_pg, 1500static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1536 int stop_pg, int cm_offset) 1501 int stop_pg, int cm_offset)
1537{ 1502{
1538 struct net_device *dev = link->priv; 1503 struct net_device *dev = link->priv;
@@ -1554,7 +1519,7 @@ static int setup_shmem_window(dev_link_t *link, int start_pg,
1554 req.Attributes |= WIN_USE_WAIT; 1519 req.Attributes |= WIN_USE_WAIT;
1555 req.Base = 0; req.Size = window_size; 1520 req.Base = 0; req.Size = window_size;
1556 req.AccessSpeed = mem_speed; 1521 req.AccessSpeed = mem_speed;
1557 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 1522 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
1558 1523
1559 mem.CardOffset = (start_pg << 8) + cm_offset; 1524 mem.CardOffset = (start_pg << 8) + cm_offset;
1560 offset = mem.CardOffset % window_size; 1525 offset = mem.CardOffset % window_size;
@@ -1595,7 +1560,7 @@ static int setup_shmem_window(dev_link_t *link, int start_pg,
1595 return 0; 1560 return 0;
1596 1561
1597cs_failed: 1562cs_failed:
1598 cs_error(link->handle, last_fn, last_ret); 1563 cs_error(link, last_fn, last_ret);
1599failed: 1564failed:
1600 return 1; 1565 return 1;
1601} 1566}
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 8839c4faafd6..e74bf5014ef6 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -49,6 +49,7 @@
49#include <pcmcia/cisreg.h> 49#include <pcmcia/cisreg.h>
50#include <pcmcia/ciscode.h> 50#include <pcmcia/ciscode.h>
51#include <pcmcia/ds.h> 51#include <pcmcia/ds.h>
52#include <pcmcia/ss.h>
52 53
53#include <asm/io.h> 54#include <asm/io.h>
54#include <asm/system.h> 55#include <asm/system.h>
@@ -103,7 +104,7 @@ static const char *version =
103#define MEMORY_WAIT_TIME 8 104#define MEMORY_WAIT_TIME 8
104 105
105struct smc_private { 106struct smc_private {
106 dev_link_t link; 107 struct pcmcia_device *p_dev;
107 spinlock_t lock; 108 spinlock_t lock;
108 u_short manfid; 109 u_short manfid;
109 u_short cardid; 110 u_short cardid;
@@ -278,8 +279,8 @@ enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
278/*====================================================================*/ 279/*====================================================================*/
279 280
280static void smc91c92_detach(struct pcmcia_device *p_dev); 281static void smc91c92_detach(struct pcmcia_device *p_dev);
281static void smc91c92_config(dev_link_t *link); 282static int smc91c92_config(struct pcmcia_device *link);
282static void smc91c92_release(dev_link_t *link); 283static void smc91c92_release(struct pcmcia_device *link);
283 284
284static int smc_open(struct net_device *dev); 285static int smc_open(struct net_device *dev);
285static int smc_close(struct net_device *dev); 286static int smc_close(struct net_device *dev);
@@ -308,10 +309,9 @@ static struct ethtool_ops ethtool_ops;
308 309
309======================================================================*/ 310======================================================================*/
310 311
311static int smc91c92_attach(struct pcmcia_device *p_dev) 312static int smc91c92_probe(struct pcmcia_device *link)
312{ 313{
313 struct smc_private *smc; 314 struct smc_private *smc;
314 dev_link_t *link;
315 struct net_device *dev; 315 struct net_device *dev;
316 316
317 DEBUG(0, "smc91c92_attach()\n"); 317 DEBUG(0, "smc91c92_attach()\n");
@@ -321,7 +321,7 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
321 if (!dev) 321 if (!dev)
322 return -ENOMEM; 322 return -ENOMEM;
323 smc = netdev_priv(dev); 323 smc = netdev_priv(dev);
324 link = &smc->link; 324 smc->p_dev = link;
325 link->priv = dev; 325 link->priv = dev;
326 326
327 spin_lock_init(&smc->lock); 327 spin_lock_init(&smc->lock);
@@ -333,7 +333,6 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
333 link->irq.Handler = &smc_interrupt; 333 link->irq.Handler = &smc_interrupt;
334 link->irq.Instance = dev; 334 link->irq.Instance = dev;
335 link->conf.Attributes = CONF_ENABLE_IRQ; 335 link->conf.Attributes = CONF_ENABLE_IRQ;
336 link->conf.Vcc = 50;
337 link->conf.IntType = INT_MEMORY_AND_IO; 336 link->conf.IntType = INT_MEMORY_AND_IO;
338 337
339 /* The SMC91c92-specific entries in the device structure. */ 338 /* The SMC91c92-specific entries in the device structure. */
@@ -357,13 +356,7 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
357 smc->mii_if.phy_id_mask = 0x1f; 356 smc->mii_if.phy_id_mask = 0x1f;
358 smc->mii_if.reg_num_mask = 0x1f; 357 smc->mii_if.reg_num_mask = 0x1f;
359 358
360 link->handle = p_dev; 359 return smc91c92_config(link);
361 p_dev->instance = link;
362
363 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
364 smc91c92_config(link);
365
366 return 0;
367} /* smc91c92_attach */ 360} /* smc91c92_attach */
368 361
369/*====================================================================== 362/*======================================================================
@@ -375,18 +368,16 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
375 368
376======================================================================*/ 369======================================================================*/
377 370
378static void smc91c92_detach(struct pcmcia_device *p_dev) 371static void smc91c92_detach(struct pcmcia_device *link)
379{ 372{
380 dev_link_t *link = dev_to_instance(p_dev);
381 struct net_device *dev = link->priv; 373 struct net_device *dev = link->priv;
382 374
383 DEBUG(0, "smc91c92_detach(0x%p)\n", link); 375 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
384 376
385 if (link->dev) 377 if (link->dev_node)
386 unregister_netdev(dev); 378 unregister_netdev(dev);
387 379
388 if (link->state & DEV_CONFIG) 380 smc91c92_release(link);
389 smc91c92_release(link);
390 381
391 free_netdev(dev); 382 free_netdev(dev);
392} /* smc91c92_detach */ 383} /* smc91c92_detach */
@@ -414,7 +405,7 @@ static int cvt_ascii_address(struct net_device *dev, char *s)
414 405
415/*====================================================================*/ 406/*====================================================================*/
416 407
417static int first_tuple(client_handle_t handle, tuple_t *tuple, 408static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
418 cisparse_t *parse) 409 cisparse_t *parse)
419{ 410{
420 int i; 411 int i;
@@ -425,7 +416,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
425 return pcmcia_parse_tuple(handle, tuple, parse); 416 return pcmcia_parse_tuple(handle, tuple, parse);
426} 417}
427 418
428static int next_tuple(client_handle_t handle, tuple_t *tuple, 419static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
429 cisparse_t *parse) 420 cisparse_t *parse)
430{ 421{
431 int i; 422 int i;
@@ -447,7 +438,7 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
447 438
448======================================================================*/ 439======================================================================*/
449 440
450static int mhz_3288_power(dev_link_t *link) 441static int mhz_3288_power(struct pcmcia_device *link)
451{ 442{
452 struct net_device *dev = link->priv; 443 struct net_device *dev = link->priv;
453 struct smc_private *smc = netdev_priv(dev); 444 struct smc_private *smc = netdev_priv(dev);
@@ -469,7 +460,7 @@ static int mhz_3288_power(dev_link_t *link)
469 return 0; 460 return 0;
470} 461}
471 462
472static int mhz_mfc_config(dev_link_t *link) 463static int mhz_mfc_config(struct pcmcia_device *link)
473{ 464{
474 struct net_device *dev = link->priv; 465 struct net_device *dev = link->priv;
475 struct smc_private *smc = netdev_priv(dev); 466 struct smc_private *smc = netdev_priv(dev);
@@ -504,7 +495,7 @@ static int mhz_mfc_config(dev_link_t *link)
504 tuple->TupleDataMax = 255; 495 tuple->TupleDataMax = 255;
505 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 496 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
506 497
507 i = first_tuple(link->handle, tuple, parse); 498 i = first_tuple(link, tuple, parse);
508 /* The Megahertz combo cards have modem-like CIS entries, so 499 /* The Megahertz combo cards have modem-like CIS entries, so
509 we have to explicitly try a bunch of port combinations. */ 500 we have to explicitly try a bunch of port combinations. */
510 while (i == CS_SUCCESS) { 501 while (i == CS_SUCCESS) {
@@ -513,11 +504,11 @@ static int mhz_mfc_config(dev_link_t *link)
513 for (k = 0; k < 0x400; k += 0x10) { 504 for (k = 0; k < 0x400; k += 0x10) {
514 if (k & 0x80) continue; 505 if (k & 0x80) continue;
515 link->io.BasePort1 = k ^ 0x300; 506 link->io.BasePort1 = k ^ 0x300;
516 i = pcmcia_request_io(link->handle, &link->io); 507 i = pcmcia_request_io(link, &link->io);
517 if (i == CS_SUCCESS) break; 508 if (i == CS_SUCCESS) break;
518 } 509 }
519 if (i == CS_SUCCESS) break; 510 if (i == CS_SUCCESS) break;
520 i = next_tuple(link->handle, tuple, parse); 511 i = next_tuple(link, tuple, parse);
521 } 512 }
522 if (i != CS_SUCCESS) 513 if (i != CS_SUCCESS)
523 goto free_cfg_mem; 514 goto free_cfg_mem;
@@ -527,7 +518,7 @@ static int mhz_mfc_config(dev_link_t *link)
527 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 518 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
528 req.Base = req.Size = 0; 519 req.Base = req.Size = 0;
529 req.AccessSpeed = 0; 520 req.AccessSpeed = 0;
530 i = pcmcia_request_window(&link->handle, &req, &link->win); 521 i = pcmcia_request_window(&link, &req, &link->win);
531 if (i != CS_SUCCESS) 522 if (i != CS_SUCCESS)
532 goto free_cfg_mem; 523 goto free_cfg_mem;
533 smc->base = ioremap(req.Base, req.Size); 524 smc->base = ioremap(req.Base, req.Size);
@@ -546,9 +537,8 @@ free_cfg_mem:
546 return i; 537 return i;
547} 538}
548 539
549static int mhz_setup(dev_link_t *link) 540static int mhz_setup(struct pcmcia_device *link)
550{ 541{
551 client_handle_t handle = link->handle;
552 struct net_device *dev = link->priv; 542 struct net_device *dev = link->priv;
553 struct smc_cfg_mem *cfg_mem; 543 struct smc_cfg_mem *cfg_mem;
554 tuple_t *tuple; 544 tuple_t *tuple;
@@ -571,13 +561,13 @@ static int mhz_setup(dev_link_t *link)
571 /* Read the station address from the CIS. It is stored as the last 561 /* Read the station address from the CIS. It is stored as the last
572 (fourth) string in the Version 1 Version/ID tuple. */ 562 (fourth) string in the Version 1 Version/ID tuple. */
573 tuple->DesiredTuple = CISTPL_VERS_1; 563 tuple->DesiredTuple = CISTPL_VERS_1;
574 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) { 564 if (first_tuple(link, tuple, parse) != CS_SUCCESS) {
575 rc = -1; 565 rc = -1;
576 goto free_cfg_mem; 566 goto free_cfg_mem;
577 } 567 }
578 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */ 568 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
579 if (next_tuple(handle, tuple, parse) != CS_SUCCESS) 569 if (next_tuple(link, tuple, parse) != CS_SUCCESS)
580 first_tuple(handle, tuple, parse); 570 first_tuple(link, tuple, parse);
581 if (parse->version_1.ns > 3) { 571 if (parse->version_1.ns > 3) {
582 station_addr = parse->version_1.str + parse->version_1.ofs[3]; 572 station_addr = parse->version_1.str + parse->version_1.ofs[3];
583 if (cvt_ascii_address(dev, station_addr) == 0) { 573 if (cvt_ascii_address(dev, station_addr) == 0) {
@@ -588,11 +578,11 @@ static int mhz_setup(dev_link_t *link)
588 578
589 /* Another possibility: for the EM3288, in a special tuple */ 579 /* Another possibility: for the EM3288, in a special tuple */
590 tuple->DesiredTuple = 0x81; 580 tuple->DesiredTuple = 0x81;
591 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) { 581 if (pcmcia_get_first_tuple(link, tuple) != CS_SUCCESS) {
592 rc = -1; 582 rc = -1;
593 goto free_cfg_mem; 583 goto free_cfg_mem;
594 } 584 }
595 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) { 585 if (pcmcia_get_tuple_data(link, tuple) != CS_SUCCESS) {
596 rc = -1; 586 rc = -1;
597 goto free_cfg_mem; 587 goto free_cfg_mem;
598 } 588 }
@@ -616,7 +606,7 @@ free_cfg_mem:
616 606
617======================================================================*/ 607======================================================================*/
618 608
619static void mot_config(dev_link_t *link) 609static void mot_config(struct pcmcia_device *link)
620{ 610{
621 struct net_device *dev = link->priv; 611 struct net_device *dev = link->priv;
622 struct smc_private *smc = netdev_priv(dev); 612 struct smc_private *smc = netdev_priv(dev);
@@ -637,7 +627,7 @@ static void mot_config(dev_link_t *link)
637 mdelay(100); 627 mdelay(100);
638} 628}
639 629
640static int mot_setup(dev_link_t *link) 630static int mot_setup(struct pcmcia_device *link)
641{ 631{
642 struct net_device *dev = link->priv; 632 struct net_device *dev = link->priv;
643 kio_addr_t ioaddr = dev->base_addr; 633 kio_addr_t ioaddr = dev->base_addr;
@@ -671,7 +661,7 @@ static int mot_setup(dev_link_t *link)
671 661
672/*====================================================================*/ 662/*====================================================================*/
673 663
674static int smc_config(dev_link_t *link) 664static int smc_config(struct pcmcia_device *link)
675{ 665{
676 struct net_device *dev = link->priv; 666 struct net_device *dev = link->priv;
677 struct smc_cfg_mem *cfg_mem; 667 struct smc_cfg_mem *cfg_mem;
@@ -696,16 +686,16 @@ static int smc_config(dev_link_t *link)
696 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 686 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
697 687
698 link->io.NumPorts1 = 16; 688 link->io.NumPorts1 = 16;
699 i = first_tuple(link->handle, tuple, parse); 689 i = first_tuple(link, tuple, parse);
700 while (i != CS_NO_MORE_ITEMS) { 690 while (i != CS_NO_MORE_ITEMS) {
701 if (i == CS_SUCCESS) { 691 if (i == CS_SUCCESS) {
702 link->conf.ConfigIndex = cf->index; 692 link->conf.ConfigIndex = cf->index;
703 link->io.BasePort1 = cf->io.win[0].base; 693 link->io.BasePort1 = cf->io.win[0].base;
704 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; 694 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
705 i = pcmcia_request_io(link->handle, &link->io); 695 i = pcmcia_request_io(link, &link->io);
706 if (i == CS_SUCCESS) break; 696 if (i == CS_SUCCESS) break;
707 } 697 }
708 i = next_tuple(link->handle, tuple, parse); 698 i = next_tuple(link, tuple, parse);
709 } 699 }
710 if (i == CS_SUCCESS) 700 if (i == CS_SUCCESS)
711 dev->base_addr = link->io.BasePort1; 701 dev->base_addr = link->io.BasePort1;
@@ -714,9 +704,8 @@ static int smc_config(dev_link_t *link)
714 return i; 704 return i;
715} 705}
716 706
717static int smc_setup(dev_link_t *link) 707static int smc_setup(struct pcmcia_device *link)
718{ 708{
719 client_handle_t handle = link->handle;
720 struct net_device *dev = link->priv; 709 struct net_device *dev = link->priv;
721 struct smc_cfg_mem *cfg_mem; 710 struct smc_cfg_mem *cfg_mem;
722 tuple_t *tuple; 711 tuple_t *tuple;
@@ -739,11 +728,11 @@ static int smc_setup(dev_link_t *link)
739 728
740 /* Check for a LAN function extension tuple */ 729 /* Check for a LAN function extension tuple */
741 tuple->DesiredTuple = CISTPL_FUNCE; 730 tuple->DesiredTuple = CISTPL_FUNCE;
742 i = first_tuple(handle, tuple, parse); 731 i = first_tuple(link, tuple, parse);
743 while (i == CS_SUCCESS) { 732 while (i == CS_SUCCESS) {
744 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID) 733 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
745 break; 734 break;
746 i = next_tuple(handle, tuple, parse); 735 i = next_tuple(link, tuple, parse);
747 } 736 }
748 if (i == CS_SUCCESS) { 737 if (i == CS_SUCCESS) {
749 node_id = (cistpl_lan_node_id_t *)parse->funce.data; 738 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
@@ -756,7 +745,7 @@ static int smc_setup(dev_link_t *link)
756 } 745 }
757 /* Try the third string in the Version 1 Version/ID tuple. */ 746 /* Try the third string in the Version 1 Version/ID tuple. */
758 tuple->DesiredTuple = CISTPL_VERS_1; 747 tuple->DesiredTuple = CISTPL_VERS_1;
759 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) { 748 if (first_tuple(link, tuple, parse) != CS_SUCCESS) {
760 rc = -1; 749 rc = -1;
761 goto free_cfg_mem; 750 goto free_cfg_mem;
762 } 751 }
@@ -774,7 +763,7 @@ free_cfg_mem:
774 763
775/*====================================================================*/ 764/*====================================================================*/
776 765
777static int osi_config(dev_link_t *link) 766static int osi_config(struct pcmcia_device *link)
778{ 767{
779 struct net_device *dev = link->priv; 768 struct net_device *dev = link->priv;
780 static const kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; 769 static const kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
@@ -794,22 +783,21 @@ static int osi_config(dev_link_t *link)
794 783
795 for (i = j = 0; j < 4; j++) { 784 for (i = j = 0; j < 4; j++) {
796 link->io.BasePort2 = com[j]; 785 link->io.BasePort2 = com[j];
797 i = pcmcia_request_io(link->handle, &link->io); 786 i = pcmcia_request_io(link, &link->io);
798 if (i == CS_SUCCESS) break; 787 if (i == CS_SUCCESS) break;
799 } 788 }
800 if (i != CS_SUCCESS) { 789 if (i != CS_SUCCESS) {
801 /* Fallback: turn off hard decode */ 790 /* Fallback: turn off hard decode */
802 link->conf.ConfigIndex = 0x03; 791 link->conf.ConfigIndex = 0x03;
803 link->io.NumPorts2 = 0; 792 link->io.NumPorts2 = 0;
804 i = pcmcia_request_io(link->handle, &link->io); 793 i = pcmcia_request_io(link, &link->io);
805 } 794 }
806 dev->base_addr = link->io.BasePort1 + 0x10; 795 dev->base_addr = link->io.BasePort1 + 0x10;
807 return i; 796 return i;
808} 797}
809 798
810static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid) 799static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
811{ 800{
812 client_handle_t handle = link->handle;
813 struct net_device *dev = link->priv; 801 struct net_device *dev = link->priv;
814 struct smc_cfg_mem *cfg_mem; 802 struct smc_cfg_mem *cfg_mem;
815 tuple_t *tuple; 803 tuple_t *tuple;
@@ -830,12 +818,12 @@ static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
830 818
831 /* Read the station address from tuple 0x90, subtuple 0x04 */ 819 /* Read the station address from tuple 0x90, subtuple 0x04 */
832 tuple->DesiredTuple = 0x90; 820 tuple->DesiredTuple = 0x90;
833 i = pcmcia_get_first_tuple(handle, tuple); 821 i = pcmcia_get_first_tuple(link, tuple);
834 while (i == CS_SUCCESS) { 822 while (i == CS_SUCCESS) {
835 i = pcmcia_get_tuple_data(handle, tuple); 823 i = pcmcia_get_tuple_data(link, tuple);
836 if ((i != CS_SUCCESS) || (buf[0] == 0x04)) 824 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
837 break; 825 break;
838 i = pcmcia_get_next_tuple(handle, tuple); 826 i = pcmcia_get_next_tuple(link, tuple);
839 } 827 }
840 if (i != CS_SUCCESS) { 828 if (i != CS_SUCCESS) {
841 rc = -1; 829 rc = -1;
@@ -868,57 +856,47 @@ free_cfg_mem:
868 return rc; 856 return rc;
869} 857}
870 858
871static int smc91c92_suspend(struct pcmcia_device *p_dev) 859static int smc91c92_suspend(struct pcmcia_device *link)
872{ 860{
873 dev_link_t *link = dev_to_instance(p_dev);
874 struct net_device *dev = link->priv; 861 struct net_device *dev = link->priv;
875 862
876 link->state |= DEV_SUSPEND; 863 if (link->open)
877 if (link->state & DEV_CONFIG) { 864 netif_device_detach(dev);
878 if (link->open)
879 netif_device_detach(dev);
880 pcmcia_release_configuration(link->handle);
881 }
882 865
883 return 0; 866 return 0;
884} 867}
885 868
886static int smc91c92_resume(struct pcmcia_device *p_dev) 869static int smc91c92_resume(struct pcmcia_device *link)
887{ 870{
888 dev_link_t *link = dev_to_instance(p_dev);
889 struct net_device *dev = link->priv; 871 struct net_device *dev = link->priv;
890 struct smc_private *smc = netdev_priv(dev); 872 struct smc_private *smc = netdev_priv(dev);
891 int i; 873 int i;
892 874
893 link->state &= ~DEV_SUSPEND; 875 if ((smc->manfid == MANFID_MEGAHERTZ) &&
894 if (link->state & DEV_CONFIG) { 876 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
895 if ((smc->manfid == MANFID_MEGAHERTZ) && 877 mhz_3288_power(link);
896 (smc->cardid == PRODID_MEGAHERTZ_EM3288)) 878 if (smc->manfid == MANFID_MOTOROLA)
897 mhz_3288_power(link); 879 mot_config(link);
898 pcmcia_request_configuration(link->handle, &link->conf); 880 if ((smc->manfid == MANFID_OSITECH) &&
899 if (smc->manfid == MANFID_MOTOROLA) 881 (smc->cardid != PRODID_OSITECH_SEVEN)) {
900 mot_config(link); 882 /* Power up the card and enable interrupts */
901 if ((smc->manfid == MANFID_OSITECH) && 883 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
902 (smc->cardid != PRODID_OSITECH_SEVEN)) { 884 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
903 /* Power up the card and enable interrupts */ 885 }
904 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR); 886 if (((smc->manfid == MANFID_OSITECH) &&
905 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR); 887 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
906 } 888 ((smc->manfid == MANFID_PSION) &&
907 if (((smc->manfid == MANFID_OSITECH) && 889 (smc->cardid == PRODID_PSION_NET100))) {
908 (smc->cardid == PRODID_OSITECH_SEVEN)) || 890 /* Download the Seven of Diamonds firmware */
909 ((smc->manfid == MANFID_PSION) && 891 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
910 (smc->cardid == PRODID_PSION_NET100))) { 892 outb(__Xilinx7OD[i], link->io.BasePort1+2);
911 /* Download the Seven of Diamonds firmware */ 893 udelay(50);
912 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
913 outb(__Xilinx7OD[i], link->io.BasePort1+2);
914 udelay(50);
915 }
916 }
917 if (link->open) {
918 smc_reset(dev);
919 netif_device_attach(dev);
920 } 894 }
921 } 895 }
896 if (link->open) {
897 smc_reset(dev);
898 netif_device_attach(dev);
899 }
922 900
923 return 0; 901 return 0;
924} 902}
@@ -931,7 +909,7 @@ static int smc91c92_resume(struct pcmcia_device *p_dev)
931 909
932======================================================================*/ 910======================================================================*/
933 911
934static int check_sig(dev_link_t *link) 912static int check_sig(struct pcmcia_device *link)
935{ 913{
936 struct net_device *dev = link->priv; 914 struct net_device *dev = link->priv;
937 kio_addr_t ioaddr = dev->base_addr; 915 kio_addr_t ioaddr = dev->base_addr;
@@ -964,13 +942,15 @@ static int check_sig(dev_link_t *link)
964 } 942 }
965 943
966 if (width) { 944 if (width) {
967 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n"); 945 modconf_t mod = {
968 smc91c92_suspend(link->handle); 946 .Attributes = CONF_IO_CHANGE_WIDTH,
969 pcmcia_release_io(link->handle, &link->io); 947 };
970 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 948 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
971 pcmcia_request_io(link->handle, &link->io); 949
972 smc91c92_resume(link->handle); 950 smc91c92_suspend(link);
973 return check_sig(link); 951 pcmcia_modify_configuration(link, &mod);
952 smc91c92_resume(link);
953 return check_sig(link);
974 } 954 }
975 return -ENODEV; 955 return -ENODEV;
976} 956}
@@ -984,11 +964,10 @@ static int check_sig(dev_link_t *link)
984======================================================================*/ 964======================================================================*/
985 965
986#define CS_EXIT_TEST(ret, svc, label) \ 966#define CS_EXIT_TEST(ret, svc, label) \
987if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; } 967if (ret != CS_SUCCESS) { cs_error(link, svc, ret); goto label; }
988 968
989static void smc91c92_config(dev_link_t *link) 969static int smc91c92_config(struct pcmcia_device *link)
990{ 970{
991 client_handle_t handle = link->handle;
992 struct net_device *dev = link->priv; 971 struct net_device *dev = link->priv;
993 struct smc_private *smc = netdev_priv(dev); 972 struct smc_private *smc = netdev_priv(dev);
994 struct smc_cfg_mem *cfg_mem; 973 struct smc_cfg_mem *cfg_mem;
@@ -1015,21 +994,18 @@ static void smc91c92_config(dev_link_t *link)
1015 tuple->TupleDataMax = 64; 994 tuple->TupleDataMax = 64;
1016 995
1017 tuple->DesiredTuple = CISTPL_CONFIG; 996 tuple->DesiredTuple = CISTPL_CONFIG;
1018 i = first_tuple(handle, tuple, parse); 997 i = first_tuple(link, tuple, parse);
1019 CS_EXIT_TEST(i, ParseTuple, config_failed); 998 CS_EXIT_TEST(i, ParseTuple, config_failed);
1020 link->conf.ConfigBase = parse->config.base; 999 link->conf.ConfigBase = parse->config.base;
1021 link->conf.Present = parse->config.rmask[0]; 1000 link->conf.Present = parse->config.rmask[0];
1022 1001
1023 tuple->DesiredTuple = CISTPL_MANFID; 1002 tuple->DesiredTuple = CISTPL_MANFID;
1024 tuple->Attributes = TUPLE_RETURN_COMMON; 1003 tuple->Attributes = TUPLE_RETURN_COMMON;
1025 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) { 1004 if (first_tuple(link, tuple, parse) == CS_SUCCESS) {
1026 smc->manfid = parse->manfid.manf; 1005 smc->manfid = parse->manfid.manf;
1027 smc->cardid = parse->manfid.card; 1006 smc->cardid = parse->manfid.card;
1028 } 1007 }
1029 1008
1030 /* Configure card */
1031 link->state |= DEV_CONFIG;
1032
1033 if ((smc->manfid == MANFID_OSITECH) && 1009 if ((smc->manfid == MANFID_OSITECH) &&
1034 (smc->cardid != PRODID_OSITECH_SEVEN)) { 1010 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1035 i = osi_config(link); 1011 i = osi_config(link);
@@ -1043,9 +1019,9 @@ static void smc91c92_config(dev_link_t *link)
1043 } 1019 }
1044 CS_EXIT_TEST(i, RequestIO, config_failed); 1020 CS_EXIT_TEST(i, RequestIO, config_failed);
1045 1021
1046 i = pcmcia_request_irq(link->handle, &link->irq); 1022 i = pcmcia_request_irq(link, &link->irq);
1047 CS_EXIT_TEST(i, RequestIRQ, config_failed); 1023 CS_EXIT_TEST(i, RequestIRQ, config_failed);
1048 i = pcmcia_request_configuration(link->handle, &link->conf); 1024 i = pcmcia_request_configuration(link, &link->conf);
1049 CS_EXIT_TEST(i, RequestConfiguration, config_failed); 1025 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
1050 1026
1051 if (smc->manfid == MANFID_MOTOROLA) 1027 if (smc->manfid == MANFID_MOTOROLA)
@@ -1124,13 +1100,12 @@ static void smc91c92_config(dev_link_t *link)
1124 SMC_SELECT_BANK(0); 1100 SMC_SELECT_BANK(0);
1125 } 1101 }
1126 1102
1127 link->dev = &smc->node; 1103 link->dev_node = &smc->node;
1128 link->state &= ~DEV_CONFIG_PENDING; 1104 SET_NETDEV_DEV(dev, &handle_to_dev(link));
1129 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1130 1105
1131 if (register_netdev(dev) != 0) { 1106 if (register_netdev(dev) != 0) {
1132 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n"); 1107 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1133 link->dev = NULL; 1108 link->dev_node = NULL;
1134 goto config_undo; 1109 goto config_undo;
1135 } 1110 }
1136 1111
@@ -1160,15 +1135,14 @@ static void smc91c92_config(dev_link_t *link)
1160 } 1135 }
1161 } 1136 }
1162 kfree(cfg_mem); 1137 kfree(cfg_mem);
1163 return; 1138 return 0;
1164 1139
1165config_undo: 1140config_undo:
1166 unregister_netdev(dev); 1141 unregister_netdev(dev);
1167config_failed: /* CS_EXIT_TEST() calls jump to here... */ 1142config_failed: /* CS_EXIT_TEST() calls jump to here... */
1168 smc91c92_release(link); 1143 smc91c92_release(link);
1169 link->state &= ~DEV_CONFIG_PENDING;
1170 kfree(cfg_mem); 1144 kfree(cfg_mem);
1171 1145 return -ENODEV;
1172} /* smc91c92_config */ 1146} /* smc91c92_config */
1173 1147
1174/*====================================================================== 1148/*======================================================================
@@ -1179,22 +1153,15 @@ config_failed: /* CS_EXIT_TEST() calls jump to here... */
1179 1153
1180======================================================================*/ 1154======================================================================*/
1181 1155
1182static void smc91c92_release(dev_link_t *link) 1156static void smc91c92_release(struct pcmcia_device *link)
1183{ 1157{
1184 1158 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1185 DEBUG(0, "smc91c92_release(0x%p)\n", link); 1159 if (link->win) {
1186 1160 struct net_device *dev = link->priv;
1187 pcmcia_release_configuration(link->handle); 1161 struct smc_private *smc = netdev_priv(dev);
1188 pcmcia_release_io(link->handle, &link->io); 1162 iounmap(smc->base);
1189 pcmcia_release_irq(link->handle, &link->irq); 1163 }
1190 if (link->win) { 1164 pcmcia_disable_device(link);
1191 struct net_device *dev = link->priv;
1192 struct smc_private *smc = netdev_priv(dev);
1193 iounmap(smc->base);
1194 pcmcia_release_window(link->win);
1195 }
1196
1197 link->state &= ~DEV_CONFIG;
1198} 1165}
1199 1166
1200/*====================================================================== 1167/*======================================================================
@@ -1283,7 +1250,7 @@ static void smc_dump(struct net_device *dev)
1283static int smc_open(struct net_device *dev) 1250static int smc_open(struct net_device *dev)
1284{ 1251{
1285 struct smc_private *smc = netdev_priv(dev); 1252 struct smc_private *smc = netdev_priv(dev);
1286 dev_link_t *link = &smc->link; 1253 struct pcmcia_device *link = smc->p_dev;
1287 1254
1288#ifdef PCMCIA_DEBUG 1255#ifdef PCMCIA_DEBUG
1289 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n", 1256 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
@@ -1292,7 +1259,7 @@ static int smc_open(struct net_device *dev)
1292#endif 1259#endif
1293 1260
1294 /* Check that the PCMCIA card is still here. */ 1261 /* Check that the PCMCIA card is still here. */
1295 if (!DEV_OK(link)) 1262 if (!pcmcia_dev_present(link))
1296 return -ENODEV; 1263 return -ENODEV;
1297 /* Physical device present signature. */ 1264 /* Physical device present signature. */
1298 if (check_sig(link) < 0) { 1265 if (check_sig(link) < 0) {
@@ -1320,7 +1287,7 @@ static int smc_open(struct net_device *dev)
1320static int smc_close(struct net_device *dev) 1287static int smc_close(struct net_device *dev)
1321{ 1288{
1322 struct smc_private *smc = netdev_priv(dev); 1289 struct smc_private *smc = netdev_priv(dev);
1323 dev_link_t *link = &smc->link; 1290 struct pcmcia_device *link = smc->p_dev;
1324 kio_addr_t ioaddr = dev->base_addr; 1291 kio_addr_t ioaddr = dev->base_addr;
1325 1292
1326 DEBUG(0, "%s: smc_close(), status %4.4x.\n", 1293 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
@@ -2311,7 +2278,7 @@ static struct pcmcia_driver smc91c92_cs_driver = {
2311 .drv = { 2278 .drv = {
2312 .name = "smc91c92_cs", 2279 .name = "smc91c92_cs",
2313 }, 2280 },
2314 .probe = smc91c92_attach, 2281 .probe = smc91c92_probe,
2315 .remove = smc91c92_detach, 2282 .remove = smc91c92_detach,
2316 .id_table = smc91c92_ids, 2283 .id_table = smc91c92_ids,
2317 .suspend = smc91c92_suspend, 2284 .suspend = smc91c92_suspend,
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index e8f849e12976..71f45056a70c 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -289,9 +289,9 @@ static void mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg,
289 * and ejection events. They are invoked from the event handler. 289 * and ejection events. They are invoked from the event handler.
290 */ 290 */
291 291
292static int has_ce2_string(dev_link_t * link); 292static int has_ce2_string(struct pcmcia_device * link);
293static void xirc2ps_config(dev_link_t * link); 293static int xirc2ps_config(struct pcmcia_device * link);
294static void xirc2ps_release(dev_link_t * link); 294static void xirc2ps_release(struct pcmcia_device * link);
295 295
296/**************** 296/****************
297 * The attach() and detach() entry points are used to create and destroy 297 * The attach() and detach() entry points are used to create and destroy
@@ -313,10 +313,10 @@ static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs
313/**************** 313/****************
314 * A linked list of "instances" of the device. Each actual 314 * A linked list of "instances" of the device. Each actual
315 * PCMCIA card corresponds to one device instance, and is described 315 * PCMCIA card corresponds to one device instance, and is described
316 * by one dev_link_t structure (defined in ds.h). 316 * by one struct pcmcia_device structure (defined in ds.h).
317 * 317 *
318 * You may not want to use a linked list for this -- for example, the 318 * You may not want to use a linked list for this -- for example, the
319 * memory card driver uses an array of dev_link_t pointers, where minor 319 * memory card driver uses an array of struct pcmcia_device pointers, where minor
320 * device numbers are used to derive the corresponding array index. 320 * device numbers are used to derive the corresponding array index.
321 */ 321 */
322 322
@@ -326,13 +326,13 @@ static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs
326 * example, ethernet cards, modems). In other cases, there may be 326 * example, ethernet cards, modems). In other cases, there may be
327 * many actual or logical devices (SCSI adapters, memory cards with 327 * many actual or logical devices (SCSI adapters, memory cards with
328 * multiple partitions). The dev_node_t structures need to be kept 328 * multiple partitions). The dev_node_t structures need to be kept
329 * in a linked list starting at the 'dev' field of a dev_link_t 329 * in a linked list starting at the 'dev' field of a struct pcmcia_device
330 * structure. We allocate them in the card's private data structure, 330 * structure. We allocate them in the card's private data structure,
331 * because they generally can't be allocated dynamically. 331 * because they generally can't be allocated dynamically.
332 */ 332 */
333 333
334typedef struct local_info_t { 334typedef struct local_info_t {
335 dev_link_t link; 335 struct pcmcia_device *p_dev;
336 dev_node_t node; 336 dev_node_t node;
337 struct net_device_stats stats; 337 struct net_device_stats stats;
338 int card_type; 338 int card_type;
@@ -355,7 +355,7 @@ static void do_tx_timeout(struct net_device *dev);
355static struct net_device_stats *do_get_stats(struct net_device *dev); 355static struct net_device_stats *do_get_stats(struct net_device *dev);
356static void set_addresses(struct net_device *dev); 356static void set_addresses(struct net_device *dev);
357static void set_multicast_list(struct net_device *dev); 357static void set_multicast_list(struct net_device *dev);
358static int set_card_type(dev_link_t *link, const void *s); 358static int set_card_type(struct pcmcia_device *link, const void *s);
359static int do_config(struct net_device *dev, struct ifmap *map); 359static int do_config(struct net_device *dev, struct ifmap *map);
360static int do_open(struct net_device *dev); 360static int do_open(struct net_device *dev);
361static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 361static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -368,7 +368,7 @@ static int do_stop(struct net_device *dev);
368 368
369/*=============== Helper functions =========================*/ 369/*=============== Helper functions =========================*/
370static int 370static int
371first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 371first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
372{ 372{
373 int err; 373 int err;
374 374
@@ -379,7 +379,7 @@ first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
379} 379}
380 380
381static int 381static int
382next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 382next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
383{ 383{
384 int err; 384 int err;
385 385
@@ -553,9 +553,8 @@ mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len)
553 */ 553 */
554 554
555static int 555static int
556xirc2ps_attach(struct pcmcia_device *p_dev) 556xirc2ps_probe(struct pcmcia_device *link)
557{ 557{
558 dev_link_t *link;
559 struct net_device *dev; 558 struct net_device *dev;
560 local_info_t *local; 559 local_info_t *local;
561 560
@@ -566,12 +565,11 @@ xirc2ps_attach(struct pcmcia_device *p_dev)
566 if (!dev) 565 if (!dev)
567 return -ENOMEM; 566 return -ENOMEM;
568 local = netdev_priv(dev); 567 local = netdev_priv(dev);
569 link = &local->link; 568 local->p_dev = link;
570 link->priv = dev; 569 link->priv = dev;
571 570
572 /* General socket configuration */ 571 /* General socket configuration */
573 link->conf.Attributes = CONF_ENABLE_IRQ; 572 link->conf.Attributes = CONF_ENABLE_IRQ;
574 link->conf.Vcc = 50;
575 link->conf.IntType = INT_MEMORY_AND_IO; 573 link->conf.IntType = INT_MEMORY_AND_IO;
576 link->conf.ConfigIndex = 1; 574 link->conf.ConfigIndex = 1;
577 link->conf.Present = PRESENT_OPTION; 575 link->conf.Present = PRESENT_OPTION;
@@ -593,13 +591,7 @@ xirc2ps_attach(struct pcmcia_device *p_dev)
593 dev->watchdog_timeo = TX_TIMEOUT; 591 dev->watchdog_timeo = TX_TIMEOUT;
594#endif 592#endif
595 593
596 link->handle = p_dev; 594 return xirc2ps_config(link);
597 p_dev->instance = link;
598
599 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
600 xirc2ps_config(link);
601
602 return 0;
603} /* xirc2ps_attach */ 595} /* xirc2ps_attach */
604 596
605/**************** 597/****************
@@ -610,18 +602,16 @@ xirc2ps_attach(struct pcmcia_device *p_dev)
610 */ 602 */
611 603
612static void 604static void
613xirc2ps_detach(struct pcmcia_device *p_dev) 605xirc2ps_detach(struct pcmcia_device *link)
614{ 606{
615 dev_link_t *link = dev_to_instance(p_dev);
616 struct net_device *dev = link->priv; 607 struct net_device *dev = link->priv;
617 608
618 DEBUG(0, "detach(0x%p)\n", link); 609 DEBUG(0, "detach(0x%p)\n", link);
619 610
620 if (link->dev) 611 if (link->dev_node)
621 unregister_netdev(dev); 612 unregister_netdev(dev);
622 613
623 if (link->state & DEV_CONFIG) 614 xirc2ps_release(link);
624 xirc2ps_release(link);
625 615
626 free_netdev(dev); 616 free_netdev(dev);
627} /* xirc2ps_detach */ 617} /* xirc2ps_detach */
@@ -645,7 +635,7 @@ xirc2ps_detach(struct pcmcia_device *p_dev)
645 * 635 *
646 */ 636 */
647static int 637static int
648set_card_type(dev_link_t *link, const void *s) 638set_card_type(struct pcmcia_device *link, const void *s)
649{ 639{
650 struct net_device *dev = link->priv; 640 struct net_device *dev = link->priv;
651 local_info_t *local = netdev_priv(dev); 641 local_info_t *local = netdev_priv(dev);
@@ -714,9 +704,8 @@ set_card_type(dev_link_t *link, const void *s)
714 * Returns: true if this is a CE2 704 * Returns: true if this is a CE2
715 */ 705 */
716static int 706static int
717has_ce2_string(dev_link_t * link) 707has_ce2_string(struct pcmcia_device * link)
718{ 708{
719 client_handle_t handle = link->handle;
720 tuple_t tuple; 709 tuple_t tuple;
721 cisparse_t parse; 710 cisparse_t parse;
722 u_char buf[256]; 711 u_char buf[256];
@@ -726,7 +715,7 @@ has_ce2_string(dev_link_t * link)
726 tuple.TupleDataMax = 254; 715 tuple.TupleDataMax = 254;
727 tuple.TupleOffset = 0; 716 tuple.TupleOffset = 0;
728 tuple.DesiredTuple = CISTPL_VERS_1; 717 tuple.DesiredTuple = CISTPL_VERS_1;
729 if (!first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 2) { 718 if (!first_tuple(link, &tuple, &parse) && parse.version_1.ns > 2) {
730 if (strstr(parse.version_1.str + parse.version_1.ofs[2], "CE2")) 719 if (strstr(parse.version_1.str + parse.version_1.ofs[2], "CE2"))
731 return 1; 720 return 1;
732 } 721 }
@@ -738,10 +727,9 @@ has_ce2_string(dev_link_t * link)
738 * is received, to configure the PCMCIA socket, and to make the 727 * is received, to configure the PCMCIA socket, and to make the
739 * ethernet device available to the system. 728 * ethernet device available to the system.
740 */ 729 */
741static void 730static int
742xirc2ps_config(dev_link_t * link) 731xirc2ps_config(struct pcmcia_device * link)
743{ 732{
744 client_handle_t handle = link->handle;
745 struct net_device *dev = link->priv; 733 struct net_device *dev = link->priv;
746 local_info_t *local = netdev_priv(dev); 734 local_info_t *local = netdev_priv(dev);
747 tuple_t tuple; 735 tuple_t tuple;
@@ -767,7 +755,7 @@ xirc2ps_config(dev_link_t * link)
767 755
768 /* Is this a valid card */ 756 /* Is this a valid card */
769 tuple.DesiredTuple = CISTPL_MANFID; 757 tuple.DesiredTuple = CISTPL_MANFID;
770 if ((err=first_tuple(handle, &tuple, &parse))) { 758 if ((err=first_tuple(link, &tuple, &parse))) {
771 printk(KNOT_XIRC "manfid not found in CIS\n"); 759 printk(KNOT_XIRC "manfid not found in CIS\n");
772 goto failure; 760 goto failure;
773 } 761 }
@@ -803,15 +791,15 @@ xirc2ps_config(dev_link_t * link)
803 791
804 /* get configuration stuff */ 792 /* get configuration stuff */
805 tuple.DesiredTuple = CISTPL_CONFIG; 793 tuple.DesiredTuple = CISTPL_CONFIG;
806 if ((err=first_tuple(handle, &tuple, &parse))) 794 if ((err=first_tuple(link, &tuple, &parse)))
807 goto cis_error; 795 goto cis_error;
808 link->conf.ConfigBase = parse.config.base; 796 link->conf.ConfigBase = parse.config.base;
809 link->conf.Present = parse.config.rmask[0]; 797 link->conf.Present = parse.config.rmask[0];
810 798
811 /* get the ethernet address from the CIS */ 799 /* get the ethernet address from the CIS */
812 tuple.DesiredTuple = CISTPL_FUNCE; 800 tuple.DesiredTuple = CISTPL_FUNCE;
813 for (err = first_tuple(handle, &tuple, &parse); !err; 801 for (err = first_tuple(link, &tuple, &parse); !err;
814 err = next_tuple(handle, &tuple, &parse)) { 802 err = next_tuple(link, &tuple, &parse)) {
815 /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries: 803 /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries:
816 * the first one with a length of zero the second correct - 804 * the first one with a length of zero the second correct -
817 * so I skip all entries with length 0 */ 805 * so I skip all entries with length 0 */
@@ -821,8 +809,8 @@ xirc2ps_config(dev_link_t * link)
821 } 809 }
822 if (err) { /* not found: try to get the node-id from tuple 0x89 */ 810 if (err) { /* not found: try to get the node-id from tuple 0x89 */
823 tuple.DesiredTuple = 0x89; /* data layout looks like tuple 0x22 */ 811 tuple.DesiredTuple = 0x89; /* data layout looks like tuple 0x22 */
824 if ((err = pcmcia_get_first_tuple(handle, &tuple)) == 0 && 812 if ((err = pcmcia_get_first_tuple(link, &tuple)) == 0 &&
825 (err = pcmcia_get_tuple_data(handle, &tuple)) == 0) { 813 (err = pcmcia_get_tuple_data(link, &tuple)) == 0) {
826 if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID) 814 if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
827 memcpy(&parse, buf, 8); 815 memcpy(&parse, buf, 8);
828 else 816 else
@@ -831,8 +819,8 @@ xirc2ps_config(dev_link_t * link)
831 } 819 }
832 if (err) { /* another try (James Lehmer's CE2 version 4.1)*/ 820 if (err) { /* another try (James Lehmer's CE2 version 4.1)*/
833 tuple.DesiredTuple = CISTPL_FUNCE; 821 tuple.DesiredTuple = CISTPL_FUNCE;
834 for (err = first_tuple(handle, &tuple, &parse); !err; 822 for (err = first_tuple(link, &tuple, &parse); !err;
835 err = next_tuple(handle, &tuple, &parse)) { 823 err = next_tuple(link, &tuple, &parse)) {
836 if (parse.funce.type == 0x02 && parse.funce.data[0] == 1 824 if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
837 && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) { 825 && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
838 buf[1] = 4; 826 buf[1] = 4;
@@ -853,9 +841,6 @@ xirc2ps_config(dev_link_t * link)
853 for (i=0; i < 6; i++) 841 for (i=0; i < 6; i++)
854 dev->dev_addr[i] = node_id->id[i]; 842 dev->dev_addr[i] = node_id->id[i];
855 843
856 /* Configure card */
857 link->state |= DEV_CONFIG;
858
859 link->io.IOAddrLines =10; 844 link->io.IOAddrLines =10;
860 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 845 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
861 link->irq.Attributes = IRQ_HANDLE_PRESENT; 846 link->irq.Attributes = IRQ_HANDLE_PRESENT;
@@ -875,14 +860,14 @@ xirc2ps_config(dev_link_t * link)
875 * Ethernet port */ 860 * Ethernet port */
876 link->io.NumPorts1 = 16; /* no Mako stuff anymore */ 861 link->io.NumPorts1 = 16; /* no Mako stuff anymore */
877 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 862 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
878 for (err = first_tuple(handle, &tuple, &parse); !err; 863 for (err = first_tuple(link, &tuple, &parse); !err;
879 err = next_tuple(handle, &tuple, &parse)) { 864 err = next_tuple(link, &tuple, &parse)) {
880 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) { 865 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
881 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 866 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
882 link->conf.ConfigIndex = cf->index ; 867 link->conf.ConfigIndex = cf->index ;
883 link->io.BasePort2 = cf->io.win[0].base; 868 link->io.BasePort2 = cf->io.win[0].base;
884 link->io.BasePort1 = ioaddr; 869 link->io.BasePort1 = ioaddr;
885 if (!(err=pcmcia_request_io(link->handle, &link->io))) 870 if (!(err=pcmcia_request_io(link, &link->io)))
886 goto port_found; 871 goto port_found;
887 } 872 }
888 } 873 }
@@ -896,15 +881,15 @@ xirc2ps_config(dev_link_t * link)
896 */ 881 */
897 for (pass=0; pass < 2; pass++) { 882 for (pass=0; pass < 2; pass++) {
898 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 883 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
899 for (err = first_tuple(handle, &tuple, &parse); !err; 884 for (err = first_tuple(link, &tuple, &parse); !err;
900 err = next_tuple(handle, &tuple, &parse)){ 885 err = next_tuple(link, &tuple, &parse)){
901 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){ 886 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){
902 link->conf.ConfigIndex = cf->index ; 887 link->conf.ConfigIndex = cf->index ;
903 link->io.BasePort2 = cf->io.win[0].base; 888 link->io.BasePort2 = cf->io.win[0].base;
904 link->io.BasePort1 = link->io.BasePort2 889 link->io.BasePort1 = link->io.BasePort2
905 + (pass ? (cf->index & 0x20 ? -24:8) 890 + (pass ? (cf->index & 0x20 ? -24:8)
906 : (cf->index & 0x20 ? 8:-24)); 891 : (cf->index & 0x20 ? 8:-24));
907 if (!(err=pcmcia_request_io(link->handle, &link->io))) 892 if (!(err=pcmcia_request_io(link, &link->io)))
908 goto port_found; 893 goto port_found;
909 } 894 }
910 } 895 }
@@ -919,12 +904,12 @@ xirc2ps_config(dev_link_t * link)
919 link->io.NumPorts1 = 16; 904 link->io.NumPorts1 = 16;
920 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 905 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
921 link->io.BasePort1 = ioaddr; 906 link->io.BasePort1 = ioaddr;
922 if (!(err=pcmcia_request_io(link->handle, &link->io))) 907 if (!(err=pcmcia_request_io(link, &link->io)))
923 goto port_found; 908 goto port_found;
924 } 909 }
925 link->io.BasePort1 = 0; /* let CS decide */ 910 link->io.BasePort1 = 0; /* let CS decide */
926 if ((err=pcmcia_request_io(link->handle, &link->io))) { 911 if ((err=pcmcia_request_io(link, &link->io))) {
927 cs_error(link->handle, RequestIO, err); 912 cs_error(link, RequestIO, err);
928 goto config_error; 913 goto config_error;
929 } 914 }
930 } 915 }
@@ -936,8 +921,8 @@ xirc2ps_config(dev_link_t * link)
936 * Now allocate an interrupt line. Note that this does not 921 * Now allocate an interrupt line. Note that this does not
937 * actually assign a handler to the interrupt. 922 * actually assign a handler to the interrupt.
938 */ 923 */
939 if ((err=pcmcia_request_irq(link->handle, &link->irq))) { 924 if ((err=pcmcia_request_irq(link, &link->irq))) {
940 cs_error(link->handle, RequestIRQ, err); 925 cs_error(link, RequestIRQ, err);
941 goto config_error; 926 goto config_error;
942 } 927 }
943 928
@@ -945,8 +930,8 @@ xirc2ps_config(dev_link_t * link)
945 * This actually configures the PCMCIA socket -- setting up 930 * This actually configures the PCMCIA socket -- setting up
946 * the I/O windows and the interrupt mapping. 931 * the I/O windows and the interrupt mapping.
947 */ 932 */
948 if ((err=pcmcia_request_configuration(link->handle, &link->conf))) { 933 if ((err=pcmcia_request_configuration(link, &link->conf))) {
949 cs_error(link->handle, RequestConfiguration, err); 934 cs_error(link, RequestConfiguration, err);
950 goto config_error; 935 goto config_error;
951 } 936 }
952 937
@@ -963,15 +948,15 @@ xirc2ps_config(dev_link_t * link)
963 reg.Action = CS_WRITE; 948 reg.Action = CS_WRITE;
964 reg.Offset = CISREG_IOBASE_0; 949 reg.Offset = CISREG_IOBASE_0;
965 reg.Value = link->io.BasePort2 & 0xff; 950 reg.Value = link->io.BasePort2 & 0xff;
966 if ((err = pcmcia_access_configuration_register(link->handle, &reg))) { 951 if ((err = pcmcia_access_configuration_register(link, &reg))) {
967 cs_error(link->handle, AccessConfigurationRegister, err); 952 cs_error(link, AccessConfigurationRegister, err);
968 goto config_error; 953 goto config_error;
969 } 954 }
970 reg.Action = CS_WRITE; 955 reg.Action = CS_WRITE;
971 reg.Offset = CISREG_IOBASE_1; 956 reg.Offset = CISREG_IOBASE_1;
972 reg.Value = (link->io.BasePort2 >> 8) & 0xff; 957 reg.Value = (link->io.BasePort2 >> 8) & 0xff;
973 if ((err = pcmcia_access_configuration_register(link->handle, &reg))) { 958 if ((err = pcmcia_access_configuration_register(link, &reg))) {
974 cs_error(link->handle, AccessConfigurationRegister, err); 959 cs_error(link, AccessConfigurationRegister, err);
975 goto config_error; 960 goto config_error;
976 } 961 }
977 962
@@ -982,15 +967,15 @@ xirc2ps_config(dev_link_t * link)
982 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 967 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
983 req.Base = req.Size = 0; 968 req.Base = req.Size = 0;
984 req.AccessSpeed = 0; 969 req.AccessSpeed = 0;
985 if ((err = pcmcia_request_window(&link->handle, &req, &link->win))) { 970 if ((err = pcmcia_request_window(&link, &req, &link->win))) {
986 cs_error(link->handle, RequestWindow, err); 971 cs_error(link, RequestWindow, err);
987 goto config_error; 972 goto config_error;
988 } 973 }
989 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800; 974 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
990 mem.CardOffset = 0x0; 975 mem.CardOffset = 0x0;
991 mem.Page = 0; 976 mem.Page = 0;
992 if ((err = pcmcia_map_mem_page(link->win, &mem))) { 977 if ((err = pcmcia_map_mem_page(link->win, &mem))) {
993 cs_error(link->handle, MapMemPage, err); 978 cs_error(link, MapMemPage, err);
994 goto config_error; 979 goto config_error;
995 } 980 }
996 981
@@ -1050,13 +1035,12 @@ xirc2ps_config(dev_link_t * link)
1050 if (local->dingo) 1035 if (local->dingo)
1051 do_reset(dev, 1); /* a kludge to make the cem56 work */ 1036 do_reset(dev, 1); /* a kludge to make the cem56 work */
1052 1037
1053 link->dev = &local->node; 1038 link->dev_node = &local->node;
1054 link->state &= ~DEV_CONFIG_PENDING; 1039 SET_NETDEV_DEV(dev, &handle_to_dev(link));
1055 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1056 1040
1057 if ((err=register_netdev(dev))) { 1041 if ((err=register_netdev(dev))) {
1058 printk(KNOT_XIRC "register_netdev() failed\n"); 1042 printk(KNOT_XIRC "register_netdev() failed\n");
1059 link->dev = NULL; 1043 link->dev_node = NULL;
1060 goto config_error; 1044 goto config_error;
1061 } 1045 }
1062 1046
@@ -1069,17 +1053,16 @@ xirc2ps_config(dev_link_t * link)
1069 printk("%c%02X", i?':':' ', dev->dev_addr[i]); 1053 printk("%c%02X", i?':':' ', dev->dev_addr[i]);
1070 printk("\n"); 1054 printk("\n");
1071 1055
1072 return; 1056 return 0;
1073 1057
1074 config_error: 1058 config_error:
1075 link->state &= ~DEV_CONFIG_PENDING;
1076 xirc2ps_release(link); 1059 xirc2ps_release(link);
1077 return; 1060 return -ENODEV;
1078 1061
1079 cis_error: 1062 cis_error:
1080 printk(KNOT_XIRC "unable to parse CIS\n"); 1063 printk(KNOT_XIRC "unable to parse CIS\n");
1081 failure: 1064 failure:
1082 link->state &= ~DEV_CONFIG_PENDING; 1065 return -ENODEV;
1083} /* xirc2ps_config */ 1066} /* xirc2ps_config */
1084 1067
1085/**************** 1068/****************
@@ -1088,57 +1071,41 @@ xirc2ps_config(dev_link_t * link)
1088 * still open, this will be postponed until it is closed. 1071 * still open, this will be postponed until it is closed.
1089 */ 1072 */
1090static void 1073static void
1091xirc2ps_release(dev_link_t *link) 1074xirc2ps_release(struct pcmcia_device *link)
1092{ 1075{
1076 DEBUG(0, "release(0x%p)\n", link);
1093 1077
1094 DEBUG(0, "release(0x%p)\n", link); 1078 if (link->win) {
1095 1079 struct net_device *dev = link->priv;
1096 if (link->win) { 1080 local_info_t *local = netdev_priv(dev);
1097 struct net_device *dev = link->priv; 1081 if (local->dingo)
1098 local_info_t *local = netdev_priv(dev); 1082 iounmap(local->dingo_ccr - 0x0800);
1099 if (local->dingo) 1083 }
1100 iounmap(local->dingo_ccr - 0x0800); 1084 pcmcia_disable_device(link);
1101 pcmcia_release_window(link->win);
1102 }
1103 pcmcia_release_configuration(link->handle);
1104 pcmcia_release_io(link->handle, &link->io);
1105 pcmcia_release_irq(link->handle, &link->irq);
1106 link->state &= ~DEV_CONFIG;
1107
1108} /* xirc2ps_release */ 1085} /* xirc2ps_release */
1109 1086
1110/*====================================================================*/ 1087/*====================================================================*/
1111 1088
1112 1089
1113static int xirc2ps_suspend(struct pcmcia_device *p_dev) 1090static int xirc2ps_suspend(struct pcmcia_device *link)
1114{ 1091{
1115 dev_link_t *link = dev_to_instance(p_dev);
1116 struct net_device *dev = link->priv; 1092 struct net_device *dev = link->priv;
1117 1093
1118 link->state |= DEV_SUSPEND; 1094 if (link->open) {
1119 if (link->state & DEV_CONFIG) { 1095 netif_device_detach(dev);
1120 if (link->open) { 1096 do_powerdown(dev);
1121 netif_device_detach(dev);
1122 do_powerdown(dev);
1123 }
1124 pcmcia_release_configuration(link->handle);
1125 } 1097 }
1126 1098
1127 return 0; 1099 return 0;
1128} 1100}
1129 1101
1130static int xirc2ps_resume(struct pcmcia_device *p_dev) 1102static int xirc2ps_resume(struct pcmcia_device *link)
1131{ 1103{
1132 dev_link_t *link = dev_to_instance(p_dev);
1133 struct net_device *dev = link->priv; 1104 struct net_device *dev = link->priv;
1134 1105
1135 link->state &= ~DEV_SUSPEND; 1106 if (link->open) {
1136 if (link->state & DEV_CONFIG) { 1107 do_reset(dev,1);
1137 pcmcia_request_configuration(link->handle, &link->conf); 1108 netif_device_attach(dev);
1138 if (link->open) {
1139 do_reset(dev,1);
1140 netif_device_attach(dev);
1141 }
1142 } 1109 }
1143 1110
1144 return 0; 1111 return 0;
@@ -1552,13 +1519,13 @@ static int
1552do_open(struct net_device *dev) 1519do_open(struct net_device *dev)
1553{ 1520{
1554 local_info_t *lp = netdev_priv(dev); 1521 local_info_t *lp = netdev_priv(dev);
1555 dev_link_t *link = &lp->link; 1522 struct pcmcia_device *link = lp->p_dev;
1556 1523
1557 DEBUG(0, "do_open(%p)\n", dev); 1524 DEBUG(0, "do_open(%p)\n", dev);
1558 1525
1559 /* Check that the PCMCIA card is still here. */ 1526 /* Check that the PCMCIA card is still here. */
1560 /* Physical device present signature. */ 1527 /* Physical device present signature. */
1561 if (!DEV_OK(link)) 1528 if (!pcmcia_dev_present(link))
1562 return -ENODEV; 1529 return -ENODEV;
1563 1530
1564 /* okay */ 1531 /* okay */
@@ -1882,7 +1849,7 @@ do_stop(struct net_device *dev)
1882{ 1849{
1883 kio_addr_t ioaddr = dev->base_addr; 1850 kio_addr_t ioaddr = dev->base_addr;
1884 local_info_t *lp = netdev_priv(dev); 1851 local_info_t *lp = netdev_priv(dev);
1885 dev_link_t *link = &lp->link; 1852 struct pcmcia_device *link = lp->p_dev;
1886 1853
1887 DEBUG(0, "do_stop(%p)\n", dev); 1854 DEBUG(0, "do_stop(%p)\n", dev);
1888 1855
@@ -1935,7 +1902,7 @@ static struct pcmcia_driver xirc2ps_cs_driver = {
1935 .drv = { 1902 .drv = {
1936 .name = "xirc2ps_cs", 1903 .name = "xirc2ps_cs",
1937 }, 1904 },
1938 .probe = xirc2ps_attach, 1905 .probe = xirc2ps_probe,
1939 .remove = xirc2ps_detach, 1906 .remove = xirc2ps_detach,
1940 .id_table = xirc2ps_ids, 1907 .id_table = xirc2ps_ids,
1941 .suspend = xirc2ps_suspend, 1908 .suspend = xirc2ps_suspend,
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index a496460ce224..af0cbb6c5c0c 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -80,8 +80,8 @@ MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
80 event handler. 80 event handler.
81*/ 81*/
82 82
83static void airo_config(dev_link_t *link); 83static int airo_config(struct pcmcia_device *link);
84static void airo_release(dev_link_t *link); 84static void airo_release(struct pcmcia_device *link);
85 85
86/* 86/*
87 The attach() and detach() entry points are used to create and destroy 87 The attach() and detach() entry points are used to create and destroy
@@ -101,10 +101,10 @@ static void airo_detach(struct pcmcia_device *p_dev);
101/* 101/*
102 A linked list of "instances" of the aironet device. Each actual 102 A linked list of "instances" of the aironet device. Each actual
103 PCMCIA card corresponds to one device instance, and is described 103 PCMCIA card corresponds to one device instance, and is described
104 by one dev_link_t structure (defined in ds.h). 104 by one struct pcmcia_device structure (defined in ds.h).
105 105
106 You may not want to use a linked list for this -- for example, the 106 You may not want to use a linked list for this -- for example, the
107 memory card driver uses an array of dev_link_t pointers, where minor 107 memory card driver uses an array of struct pcmcia_device pointers, where minor
108 device numbers are used to derive the corresponding array index. 108 device numbers are used to derive the corresponding array index.
109*/ 109*/
110 110
@@ -114,7 +114,7 @@ static void airo_detach(struct pcmcia_device *p_dev);
114 example, ethernet cards, modems). In other cases, there may be 114 example, ethernet cards, modems). In other cases, there may be
115 many actual or logical devices (SCSI adapters, memory cards with 115 many actual or logical devices (SCSI adapters, memory cards with
116 multiple partitions). The dev_node_t structures need to be kept 116 multiple partitions). The dev_node_t structures need to be kept
117 in a linked list starting at the 'dev' field of a dev_link_t 117 in a linked list starting at the 'dev' field of a struct pcmcia_device
118 structure. We allocate them in the card's private data structure, 118 structure. We allocate them in the card's private data structure,
119 because they generally shouldn't be allocated dynamically. 119 because they generally shouldn't be allocated dynamically.
120 120
@@ -141,24 +141,16 @@ typedef struct local_info_t {
141 141
142 ======================================================================*/ 142 ======================================================================*/
143 143
144static int airo_attach(struct pcmcia_device *p_dev) 144static int airo_probe(struct pcmcia_device *p_dev)
145{ 145{
146 dev_link_t *link;
147 local_info_t *local; 146 local_info_t *local;
148 147
149 DEBUG(0, "airo_attach()\n"); 148 DEBUG(0, "airo_attach()\n");
150 149
151 /* Initialize the dev_link_t structure */
152 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
153 if (!link) {
154 printk(KERN_ERR "airo_cs: no memory for new device\n");
155 return -ENOMEM;
156 }
157
158 /* Interrupt setup */ 150 /* Interrupt setup */
159 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 151 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
160 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 152 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
161 link->irq.Handler = NULL; 153 p_dev->irq.Handler = NULL;
162 154
163 /* 155 /*
164 General socket configuration defaults can go here. In this 156 General socket configuration defaults can go here. In this
@@ -167,26 +159,18 @@ static int airo_attach(struct pcmcia_device *p_dev)
167 and attributes of IO windows) are fixed by the nature of the 159 and attributes of IO windows) are fixed by the nature of the
168 device, and can be hard-wired here. 160 device, and can be hard-wired here.
169 */ 161 */
170 link->conf.Attributes = 0; 162 p_dev->conf.Attributes = 0;
171 link->conf.Vcc = 50; 163 p_dev->conf.IntType = INT_MEMORY_AND_IO;
172 link->conf.IntType = INT_MEMORY_AND_IO;
173 164
174 /* Allocate space for private device-specific data */ 165 /* Allocate space for private device-specific data */
175 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 166 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
176 if (!local) { 167 if (!local) {
177 printk(KERN_ERR "airo_cs: no memory for new device\n"); 168 printk(KERN_ERR "airo_cs: no memory for new device\n");
178 kfree (link);
179 return -ENOMEM; 169 return -ENOMEM;
180 } 170 }
181 link->priv = local; 171 p_dev->priv = local;
182 172
183 link->handle = p_dev; 173 return airo_config(p_dev);
184 p_dev->instance = link;
185
186 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
187 airo_config(link);
188
189 return 0;
190} /* airo_attach */ 174} /* airo_attach */
191 175
192/*====================================================================== 176/*======================================================================
@@ -198,14 +182,11 @@ static int airo_attach(struct pcmcia_device *p_dev)
198 182
199 ======================================================================*/ 183 ======================================================================*/
200 184
201static void airo_detach(struct pcmcia_device *p_dev) 185static void airo_detach(struct pcmcia_device *link)
202{ 186{
203 dev_link_t *link = dev_to_instance(p_dev);
204
205 DEBUG(0, "airo_detach(0x%p)\n", link); 187 DEBUG(0, "airo_detach(0x%p)\n", link);
206 188
207 if (link->state & DEV_CONFIG) 189 airo_release(link);
208 airo_release(link);
209 190
210 if ( ((local_info_t*)link->priv)->eth_dev ) { 191 if ( ((local_info_t*)link->priv)->eth_dev ) {
211 stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 ); 192 stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 );
@@ -213,7 +194,6 @@ static void airo_detach(struct pcmcia_device *p_dev)
213 ((local_info_t*)link->priv)->eth_dev = NULL; 194 ((local_info_t*)link->priv)->eth_dev = NULL;
214 195
215 kfree(link->priv); 196 kfree(link->priv);
216 kfree(link);
217} /* airo_detach */ 197} /* airo_detach */
218 198
219/*====================================================================== 199/*======================================================================
@@ -227,9 +207,8 @@ static void airo_detach(struct pcmcia_device *p_dev)
227#define CS_CHECK(fn, ret) \ 207#define CS_CHECK(fn, ret) \
228do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 208do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
229 209
230static void airo_config(dev_link_t *link) 210static int airo_config(struct pcmcia_device *link)
231{ 211{
232 client_handle_t handle;
233 tuple_t tuple; 212 tuple_t tuple;
234 cisparse_t parse; 213 cisparse_t parse;
235 local_info_t *dev; 214 local_info_t *dev;
@@ -237,8 +216,7 @@ static void airo_config(dev_link_t *link)
237 u_char buf[64]; 216 u_char buf[64];
238 win_req_t req; 217 win_req_t req;
239 memreq_t map; 218 memreq_t map;
240 219
241 handle = link->handle;
242 dev = link->priv; 220 dev = link->priv;
243 221
244 DEBUG(0, "airo_config(0x%p)\n", link); 222 DEBUG(0, "airo_config(0x%p)\n", link);
@@ -252,15 +230,12 @@ static void airo_config(dev_link_t *link)
252 tuple.TupleData = buf; 230 tuple.TupleData = buf;
253 tuple.TupleDataMax = sizeof(buf); 231 tuple.TupleDataMax = sizeof(buf);
254 tuple.TupleOffset = 0; 232 tuple.TupleOffset = 0;
255 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 233 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
256 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 234 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
257 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 235 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
258 link->conf.ConfigBase = parse.config.base; 236 link->conf.ConfigBase = parse.config.base;
259 link->conf.Present = parse.config.rmask[0]; 237 link->conf.Present = parse.config.rmask[0];
260 238
261 /* Configure card */
262 link->state |= DEV_CONFIG;
263
264 /* 239 /*
265 In this loop, we scan the CIS for configuration table entries, 240 In this loop, we scan the CIS for configuration table entries,
266 each of which describes a valid card configuration, including 241 each of which describes a valid card configuration, including
@@ -274,12 +249,12 @@ static void airo_config(dev_link_t *link)
274 will only use the CIS to fill in implementation-defined details. 249 will only use the CIS to fill in implementation-defined details.
275 */ 250 */
276 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 251 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
277 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 252 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
278 while (1) { 253 while (1) {
279 cistpl_cftable_entry_t dflt = { 0 }; 254 cistpl_cftable_entry_t dflt = { 0 };
280 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 255 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
281 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 256 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
282 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 257 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
283 goto next_entry; 258 goto next_entry;
284 259
285 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 260 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
@@ -294,16 +269,11 @@ static void airo_config(dev_link_t *link)
294 269
295 /* Use power settings for Vcc and Vpp if present */ 270 /* Use power settings for Vcc and Vpp if present */
296 /* Note that the CIS values need to be rescaled */ 271 /* Note that the CIS values need to be rescaled */
297 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM))
298 link->conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000;
299 else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM))
300 link->conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000;
301
302 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 272 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
303 link->conf.Vpp1 = link->conf.Vpp2 = 273 link->conf.Vpp =
304 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 274 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
305 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 275 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
306 link->conf.Vpp1 = link->conf.Vpp2 = 276 link->conf.Vpp =
307 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 277 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
308 278
309 /* Do we need to allocate an interrupt? */ 279 /* Do we need to allocate an interrupt? */
@@ -329,12 +299,12 @@ static void airo_config(dev_link_t *link)
329 } 299 }
330 300
331 /* This reserves IO space but doesn't actually enable it */ 301 /* This reserves IO space but doesn't actually enable it */
332 if (pcmcia_request_io(link->handle, &link->io) != 0) 302 if (pcmcia_request_io(link, &link->io) != 0)
333 goto next_entry; 303 goto next_entry;
334 304
335 /* 305 /*
336 Now set up a common memory window, if needed. There is room 306 Now set up a common memory window, if needed. There is room
337 in the dev_link_t structure for one memory window handle, 307 in the struct pcmcia_device structure for one memory window handle,
338 but if the base addresses need to be saved, or if multiple 308 but if the base addresses need to be saved, or if multiple
339 windows are needed, the info should go in the private data 309 windows are needed, the info should go in the private data
340 structure for this device. 310 structure for this device.
@@ -350,7 +320,7 @@ static void airo_config(dev_link_t *link)
350 req.Base = mem->win[0].host_addr; 320 req.Base = mem->win[0].host_addr;
351 req.Size = mem->win[0].len; 321 req.Size = mem->win[0].len;
352 req.AccessSpeed = 0; 322 req.AccessSpeed = 0;
353 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 323 if (pcmcia_request_window(&link, &req, &link->win) != 0)
354 goto next_entry; 324 goto next_entry;
355 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 325 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
356 if (pcmcia_map_mem_page(link->win, &map) != 0) 326 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -360,7 +330,7 @@ static void airo_config(dev_link_t *link)
360 break; 330 break;
361 331
362 next_entry: 332 next_entry:
363 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 333 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
364 } 334 }
365 335
366 /* 336 /*
@@ -369,33 +339,32 @@ static void airo_config(dev_link_t *link)
369 irq structure is initialized. 339 irq structure is initialized.
370 */ 340 */
371 if (link->conf.Attributes & CONF_ENABLE_IRQ) 341 if (link->conf.Attributes & CONF_ENABLE_IRQ)
372 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 342 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
373 343
374 /* 344 /*
375 This actually configures the PCMCIA socket -- setting up 345 This actually configures the PCMCIA socket -- setting up
376 the I/O windows and the interrupt mapping, and putting the 346 the I/O windows and the interrupt mapping, and putting the
377 card and host interface into "Memory and IO" mode. 347 card and host interface into "Memory and IO" mode.
378 */ 348 */
379 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 349 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
380 ((local_info_t*)link->priv)->eth_dev = 350 ((local_info_t*)link->priv)->eth_dev =
381 init_airo_card( link->irq.AssignedIRQ, 351 init_airo_card( link->irq.AssignedIRQ,
382 link->io.BasePort1, 1, &handle_to_dev(handle) ); 352 link->io.BasePort1, 1, &handle_to_dev(link) );
383 if (!((local_info_t*)link->priv)->eth_dev) goto cs_failed; 353 if (!((local_info_t*)link->priv)->eth_dev) goto cs_failed;
384 354
385 /* 355 /*
386 At this point, the dev_node_t structure(s) need to be 356 At this point, the dev_node_t structure(s) need to be
387 initialized and arranged in a linked list at link->dev. 357 initialized and arranged in a linked list at link->dev_node.
388 */ 358 */
389 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name ); 359 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
390 dev->node.major = dev->node.minor = 0; 360 dev->node.major = dev->node.minor = 0;
391 link->dev = &dev->node; 361 link->dev_node = &dev->node;
392 362
393 /* Finally, report what we've done */ 363 /* Finally, report what we've done */
394 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 364 printk(KERN_INFO "%s: index 0x%02x: ",
395 dev->node.dev_name, link->conf.ConfigIndex, 365 dev->node.dev_name, link->conf.ConfigIndex);
396 link->conf.Vcc/10, link->conf.Vcc%10); 366 if (link->conf.Vpp)
397 if (link->conf.Vpp1) 367 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
398 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
399 if (link->conf.Attributes & CONF_ENABLE_IRQ) 368 if (link->conf.Attributes & CONF_ENABLE_IRQ)
400 printk(", irq %d", link->irq.AssignedIRQ); 369 printk(", irq %d", link->irq.AssignedIRQ);
401 if (link->io.NumPorts1) 370 if (link->io.NumPorts1)
@@ -408,14 +377,12 @@ static void airo_config(dev_link_t *link)
408 printk(", mem 0x%06lx-0x%06lx", req.Base, 377 printk(", mem 0x%06lx-0x%06lx", req.Base,
409 req.Base+req.Size-1); 378 req.Base+req.Size-1);
410 printk("\n"); 379 printk("\n");
411 380 return 0;
412 link->state &= ~DEV_CONFIG_PENDING; 381
413 return;
414
415 cs_failed: 382 cs_failed:
416 cs_error(link->handle, last_fn, last_ret); 383 cs_error(link, last_fn, last_ret);
417 airo_release(link); 384 airo_release(link);
418 385 return -ENODEV;
419} /* airo_config */ 386} /* airo_config */
420 387
421/*====================================================================== 388/*======================================================================
@@ -426,51 +393,26 @@ static void airo_config(dev_link_t *link)
426 393
427 ======================================================================*/ 394 ======================================================================*/
428 395
429static void airo_release(dev_link_t *link) 396static void airo_release(struct pcmcia_device *link)
430{ 397{
431 DEBUG(0, "airo_release(0x%p)\n", link); 398 DEBUG(0, "airo_release(0x%p)\n", link);
432 399 pcmcia_disable_device(link);
433 /* Unlink the device chain */
434 link->dev = NULL;
435
436 /*
437 In a normal driver, additional code may be needed to release
438 other kernel data structures associated with this device.
439 */
440
441 /* Don't bother checking to see if these succeed or not */
442 if (link->win)
443 pcmcia_release_window(link->win);
444 pcmcia_release_configuration(link->handle);
445 if (link->io.NumPorts1)
446 pcmcia_release_io(link->handle, &link->io);
447 if (link->irq.AssignedIRQ)
448 pcmcia_release_irq(link->handle, &link->irq);
449 link->state &= ~DEV_CONFIG;
450} 400}
451 401
452static int airo_suspend(struct pcmcia_device *p_dev) 402static int airo_suspend(struct pcmcia_device *link)
453{ 403{
454 dev_link_t *link = dev_to_instance(p_dev);
455 local_info_t *local = link->priv; 404 local_info_t *local = link->priv;
456 405
457 link->state |= DEV_SUSPEND; 406 netif_device_detach(local->eth_dev);
458 if (link->state & DEV_CONFIG) {
459 netif_device_detach(local->eth_dev);
460 pcmcia_release_configuration(link->handle);
461 }
462 407
463 return 0; 408 return 0;
464} 409}
465 410
466static int airo_resume(struct pcmcia_device *p_dev) 411static int airo_resume(struct pcmcia_device *link)
467{ 412{
468 dev_link_t *link = dev_to_instance(p_dev);
469 local_info_t *local = link->priv; 413 local_info_t *local = link->priv;
470 414
471 link->state &= ~DEV_SUSPEND; 415 if (link->open) {
472 if (link->state & DEV_CONFIG) {
473 pcmcia_request_configuration(link->handle, &link->conf);
474 reset_airo_card(local->eth_dev); 416 reset_airo_card(local->eth_dev);
475 netif_device_attach(local->eth_dev); 417 netif_device_attach(local->eth_dev);
476 } 418 }
@@ -492,7 +434,7 @@ static struct pcmcia_driver airo_driver = {
492 .drv = { 434 .drv = {
493 .name = "airo_cs", 435 .name = "airo_cs",
494 }, 436 },
495 .probe = airo_attach, 437 .probe = airo_probe,
496 .remove = airo_detach, 438 .remove = airo_detach,
497 .id_table = airo_ids, 439 .id_table = airo_ids,
498 .suspend = airo_suspend, 440 .suspend = airo_suspend,
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index d6f4a5a3e55a..26bf1127524d 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -91,8 +91,8 @@ MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA cards");
91 event handler. 91 event handler.
92*/ 92*/
93 93
94static void atmel_config(dev_link_t *link); 94static int atmel_config(struct pcmcia_device *link);
95static void atmel_release(dev_link_t *link); 95static void atmel_release(struct pcmcia_device *link);
96 96
97/* 97/*
98 The attach() and detach() entry points are used to create and destroy 98 The attach() and detach() entry points are used to create and destroy
@@ -112,10 +112,10 @@ static void atmel_detach(struct pcmcia_device *p_dev);
112/* 112/*
113 A linked list of "instances" of the atmelnet device. Each actual 113 A linked list of "instances" of the atmelnet device. Each actual
114 PCMCIA card corresponds to one device instance, and is described 114 PCMCIA card corresponds to one device instance, and is described
115 by one dev_link_t structure (defined in ds.h). 115 by one struct pcmcia_device structure (defined in ds.h).
116 116
117 You may not want to use a linked list for this -- for example, the 117 You may not want to use a linked list for this -- for example, the
118 memory card driver uses an array of dev_link_t pointers, where minor 118 memory card driver uses an array of struct pcmcia_device pointers, where minor
119 device numbers are used to derive the corresponding array index. 119 device numbers are used to derive the corresponding array index.
120*/ 120*/
121 121
@@ -125,7 +125,7 @@ static void atmel_detach(struct pcmcia_device *p_dev);
125 example, ethernet cards, modems). In other cases, there may be 125 example, ethernet cards, modems). In other cases, there may be
126 many actual or logical devices (SCSI adapters, memory cards with 126 many actual or logical devices (SCSI adapters, memory cards with
127 multiple partitions). The dev_node_t structures need to be kept 127 multiple partitions). The dev_node_t structures need to be kept
128 in a linked list starting at the 'dev' field of a dev_link_t 128 in a linked list starting at the 'dev' field of a struct pcmcia_device
129 structure. We allocate them in the card's private data structure, 129 structure. We allocate them in the card's private data structure,
130 because they generally shouldn't be allocated dynamically. 130 because they generally shouldn't be allocated dynamically.
131 131
@@ -152,24 +152,16 @@ typedef struct local_info_t {
152 152
153 ======================================================================*/ 153 ======================================================================*/
154 154
155static int atmel_attach(struct pcmcia_device *p_dev) 155static int atmel_probe(struct pcmcia_device *p_dev)
156{ 156{
157 dev_link_t *link;
158 local_info_t *local; 157 local_info_t *local;
159 158
160 DEBUG(0, "atmel_attach()\n"); 159 DEBUG(0, "atmel_attach()\n");
161 160
162 /* Initialize the dev_link_t structure */
163 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
164 if (!link) {
165 printk(KERN_ERR "atmel_cs: no memory for new device\n");
166 return -ENOMEM;
167 }
168
169 /* Interrupt setup */ 161 /* Interrupt setup */
170 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 162 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
171 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 163 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
172 link->irq.Handler = NULL; 164 p_dev->irq.Handler = NULL;
173 165
174 /* 166 /*
175 General socket configuration defaults can go here. In this 167 General socket configuration defaults can go here. In this
@@ -178,26 +170,18 @@ static int atmel_attach(struct pcmcia_device *p_dev)
178 and attributes of IO windows) are fixed by the nature of the 170 and attributes of IO windows) are fixed by the nature of the
179 device, and can be hard-wired here. 171 device, and can be hard-wired here.
180 */ 172 */
181 link->conf.Attributes = 0; 173 p_dev->conf.Attributes = 0;
182 link->conf.Vcc = 50; 174 p_dev->conf.IntType = INT_MEMORY_AND_IO;
183 link->conf.IntType = INT_MEMORY_AND_IO;
184 175
185 /* Allocate space for private device-specific data */ 176 /* Allocate space for private device-specific data */
186 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 177 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
187 if (!local) { 178 if (!local) {
188 printk(KERN_ERR "atmel_cs: no memory for new device\n"); 179 printk(KERN_ERR "atmel_cs: no memory for new device\n");
189 kfree (link);
190 return -ENOMEM; 180 return -ENOMEM;
191 } 181 }
192 link->priv = local; 182 p_dev->priv = local;
193 183
194 link->handle = p_dev; 184 return atmel_config(p_dev);
195 p_dev->instance = link;
196
197 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
198 atmel_config(link);
199
200 return 0;
201} /* atmel_attach */ 185} /* atmel_attach */
202 186
203/*====================================================================== 187/*======================================================================
@@ -209,17 +193,13 @@ static int atmel_attach(struct pcmcia_device *p_dev)
209 193
210 ======================================================================*/ 194 ======================================================================*/
211 195
212static void atmel_detach(struct pcmcia_device *p_dev) 196static void atmel_detach(struct pcmcia_device *link)
213{ 197{
214 dev_link_t *link = dev_to_instance(p_dev);
215
216 DEBUG(0, "atmel_detach(0x%p)\n", link); 198 DEBUG(0, "atmel_detach(0x%p)\n", link);
217 199
218 if (link->state & DEV_CONFIG) 200 atmel_release(link);
219 atmel_release(link);
220 201
221 kfree(link->priv); 202 kfree(link->priv);
222 kfree(link);
223} 203}
224 204
225/*====================================================================== 205/*======================================================================
@@ -236,19 +216,17 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
236/* Call-back function to interrogate PCMCIA-specific information 216/* Call-back function to interrogate PCMCIA-specific information
237 about the current existance of the card */ 217 about the current existance of the card */
238static int card_present(void *arg) 218static int card_present(void *arg)
239{ 219{
240 dev_link_t *link = (dev_link_t *)arg; 220 struct pcmcia_device *link = (struct pcmcia_device *)arg;
241 if (link->state & DEV_SUSPEND) 221
242 return 0; 222 if (pcmcia_dev_present(link))
243 else if (link->state & DEV_PRESENT)
244 return 1; 223 return 1;
245 224
246 return 0; 225 return 0;
247} 226}
248 227
249static void atmel_config(dev_link_t *link) 228static int atmel_config(struct pcmcia_device *link)
250{ 229{
251 client_handle_t handle;
252 tuple_t tuple; 230 tuple_t tuple;
253 cisparse_t parse; 231 cisparse_t parse;
254 local_info_t *dev; 232 local_info_t *dev;
@@ -256,9 +234,8 @@ static void atmel_config(dev_link_t *link)
256 u_char buf[64]; 234 u_char buf[64];
257 struct pcmcia_device_id *did; 235 struct pcmcia_device_id *did;
258 236
259 handle = link->handle;
260 dev = link->priv; 237 dev = link->priv;
261 did = handle_to_dev(handle).driver_data; 238 did = handle_to_dev(link).driver_data;
262 239
263 DEBUG(0, "atmel_config(0x%p)\n", link); 240 DEBUG(0, "atmel_config(0x%p)\n", link);
264 241
@@ -272,15 +249,12 @@ static void atmel_config(dev_link_t *link)
272 registers. 249 registers.
273 */ 250 */
274 tuple.DesiredTuple = CISTPL_CONFIG; 251 tuple.DesiredTuple = CISTPL_CONFIG;
275 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 252 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
276 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 253 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
277 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 254 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
278 link->conf.ConfigBase = parse.config.base; 255 link->conf.ConfigBase = parse.config.base;
279 link->conf.Present = parse.config.rmask[0]; 256 link->conf.Present = parse.config.rmask[0];
280 257
281 /* Configure card */
282 link->state |= DEV_CONFIG;
283
284 /* 258 /*
285 In this loop, we scan the CIS for configuration table entries, 259 In this loop, we scan the CIS for configuration table entries,
286 each of which describes a valid card configuration, including 260 each of which describes a valid card configuration, including
@@ -294,12 +268,12 @@ static void atmel_config(dev_link_t *link)
294 will only use the CIS to fill in implementation-defined details. 268 will only use the CIS to fill in implementation-defined details.
295 */ 269 */
296 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 270 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
297 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 271 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
298 while (1) { 272 while (1) {
299 cistpl_cftable_entry_t dflt = { 0 }; 273 cistpl_cftable_entry_t dflt = { 0 };
300 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 274 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
301 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 275 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
302 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 276 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
303 goto next_entry; 277 goto next_entry;
304 278
305 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 279 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
@@ -314,16 +288,11 @@ static void atmel_config(dev_link_t *link)
314 288
315 /* Use power settings for Vcc and Vpp if present */ 289 /* Use power settings for Vcc and Vpp if present */
316 /* Note that the CIS values need to be rescaled */ 290 /* Note that the CIS values need to be rescaled */
317 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM))
318 link->conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000;
319 else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM))
320 link->conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000;
321
322 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 291 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
323 link->conf.Vpp1 = link->conf.Vpp2 = 292 link->conf.Vpp =
324 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 293 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
325 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 294 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
326 link->conf.Vpp1 = link->conf.Vpp2 = 295 link->conf.Vpp =
327 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 296 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
328 297
329 /* Do we need to allocate an interrupt? */ 298 /* Do we need to allocate an interrupt? */
@@ -349,14 +318,14 @@ static void atmel_config(dev_link_t *link)
349 } 318 }
350 319
351 /* This reserves IO space but doesn't actually enable it */ 320 /* This reserves IO space but doesn't actually enable it */
352 if (pcmcia_request_io(link->handle, &link->io) != 0) 321 if (pcmcia_request_io(link, &link->io) != 0)
353 goto next_entry; 322 goto next_entry;
354 323
355 /* If we got this far, we're cool! */ 324 /* If we got this far, we're cool! */
356 break; 325 break;
357 326
358 next_entry: 327 next_entry:
359 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 328 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
360 } 329 }
361 330
362 /* 331 /*
@@ -365,14 +334,14 @@ static void atmel_config(dev_link_t *link)
365 irq structure is initialized. 334 irq structure is initialized.
366 */ 335 */
367 if (link->conf.Attributes & CONF_ENABLE_IRQ) 336 if (link->conf.Attributes & CONF_ENABLE_IRQ)
368 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 337 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
369 338
370 /* 339 /*
371 This actually configures the PCMCIA socket -- setting up 340 This actually configures the PCMCIA socket -- setting up
372 the I/O windows and the interrupt mapping, and putting the 341 the I/O windows and the interrupt mapping, and putting the
373 card and host interface into "Memory and IO" mode. 342 card and host interface into "Memory and IO" mode.
374 */ 343 */
375 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 344 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
376 345
377 if (link->irq.AssignedIRQ == 0) { 346 if (link->irq.AssignedIRQ == 0) {
378 printk(KERN_ALERT 347 printk(KERN_ALERT
@@ -384,7 +353,7 @@ static void atmel_config(dev_link_t *link)
384 init_atmel_card(link->irq.AssignedIRQ, 353 init_atmel_card(link->irq.AssignedIRQ,
385 link->io.BasePort1, 354 link->io.BasePort1,
386 did ? did->driver_info : ATMEL_FW_TYPE_NONE, 355 did ? did->driver_info : ATMEL_FW_TYPE_NONE,
387 &handle_to_dev(handle), 356 &handle_to_dev(link),
388 card_present, 357 card_present,
389 link); 358 link);
390 if (!((local_info_t*)link->priv)->eth_dev) 359 if (!((local_info_t*)link->priv)->eth_dev)
@@ -393,18 +362,18 @@ static void atmel_config(dev_link_t *link)
393 362
394 /* 363 /*
395 At this point, the dev_node_t structure(s) need to be 364 At this point, the dev_node_t structure(s) need to be
396 initialized and arranged in a linked list at link->dev. 365 initialized and arranged in a linked list at link->dev_node.
397 */ 366 */
398 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name ); 367 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
399 dev->node.major = dev->node.minor = 0; 368 dev->node.major = dev->node.minor = 0;
400 link->dev = &dev->node; 369 link->dev_node = &dev->node;
401 370
402 link->state &= ~DEV_CONFIG_PENDING; 371 return 0;
403 return; 372
404
405 cs_failed: 373 cs_failed:
406 cs_error(link->handle, last_fn, last_ret); 374 cs_error(link, last_fn, last_ret);
407 atmel_release(link); 375 atmel_release(link);
376 return -ENODEV;
408} 377}
409 378
410/*====================================================================== 379/*======================================================================
@@ -415,53 +384,34 @@ static void atmel_config(dev_link_t *link)
415 384
416 ======================================================================*/ 385 ======================================================================*/
417 386
418static void atmel_release(dev_link_t *link) 387static void atmel_release(struct pcmcia_device *link)
419{ 388{
420 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev; 389 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev;
421 390
422 DEBUG(0, "atmel_release(0x%p)\n", link); 391 DEBUG(0, "atmel_release(0x%p)\n", link);
423 392
424 /* Unlink the device chain */ 393 if (dev)
425 link->dev = NULL;
426
427 if (dev)
428 stop_atmel_card(dev); 394 stop_atmel_card(dev);
429 ((local_info_t*)link->priv)->eth_dev = NULL; 395 ((local_info_t*)link->priv)->eth_dev = NULL;
430 396
431 /* Don't bother checking to see if these succeed or not */ 397 pcmcia_disable_device(link);
432 pcmcia_release_configuration(link->handle);
433 if (link->io.NumPorts1)
434 pcmcia_release_io(link->handle, &link->io);
435 if (link->irq.AssignedIRQ)
436 pcmcia_release_irq(link->handle, &link->irq);
437 link->state &= ~DEV_CONFIG;
438} 398}
439 399
440static int atmel_suspend(struct pcmcia_device *dev) 400static int atmel_suspend(struct pcmcia_device *link)
441{ 401{
442 dev_link_t *link = dev_to_instance(dev);
443 local_info_t *local = link->priv; 402 local_info_t *local = link->priv;
444 403
445 link->state |= DEV_SUSPEND; 404 netif_device_detach(local->eth_dev);
446 if (link->state & DEV_CONFIG) {
447 netif_device_detach(local->eth_dev);
448 pcmcia_release_configuration(link->handle);
449 }
450 405
451 return 0; 406 return 0;
452} 407}
453 408
454static int atmel_resume(struct pcmcia_device *dev) 409static int atmel_resume(struct pcmcia_device *link)
455{ 410{
456 dev_link_t *link = dev_to_instance(dev);
457 local_info_t *local = link->priv; 411 local_info_t *local = link->priv;
458 412
459 link->state &= ~DEV_SUSPEND; 413 atmel_open(local->eth_dev);
460 if (link->state & DEV_CONFIG) { 414 netif_device_attach(local->eth_dev);
461 pcmcia_request_configuration(link->handle, &link->conf);
462 atmel_open(local->eth_dev);
463 netif_device_attach(local->eth_dev);
464 }
465 415
466 return 0; 416 return 0;
467} 417}
@@ -515,7 +465,7 @@ static struct pcmcia_driver atmel_driver = {
515 .drv = { 465 .drv = {
516 .name = "atmel_cs", 466 .name = "atmel_cs",
517 }, 467 },
518 .probe = atmel_attach, 468 .probe = atmel_probe,
519 .remove = atmel_detach, 469 .remove = atmel_detach,
520 .id_table = atmel_ids, 470 .id_table = atmel_ids,
521 .suspend = atmel_suspend, 471 .suspend = atmel_suspend,
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index d335b250923a..55bed923fbe9 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -42,7 +42,7 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
42/* struct local_info::hw_priv */ 42/* struct local_info::hw_priv */
43struct hostap_cs_priv { 43struct hostap_cs_priv {
44 dev_node_t node; 44 dev_node_t node;
45 dev_link_t *link; 45 struct pcmcia_device *link;
46 int sandisk_connectplus; 46 int sandisk_connectplus;
47}; 47};
48 48
@@ -204,15 +204,13 @@ static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
204 204
205static void prism2_detach(struct pcmcia_device *p_dev); 205static void prism2_detach(struct pcmcia_device *p_dev);
206static void prism2_release(u_long arg); 206static void prism2_release(u_long arg);
207static int prism2_config(dev_link_t *link); 207static int prism2_config(struct pcmcia_device *link);
208 208
209 209
210static int prism2_pccard_card_present(local_info_t *local) 210static int prism2_pccard_card_present(local_info_t *local)
211{ 211{
212 struct hostap_cs_priv *hw_priv = local->hw_priv; 212 struct hostap_cs_priv *hw_priv = local->hw_priv;
213 if (hw_priv != NULL && hw_priv->link != NULL && 213 if (hw_priv != NULL && hw_priv->link != NULL && pcmcia_dev_present(hw_priv->link))
214 ((hw_priv->link->state & (DEV_PRESENT | DEV_CONFIG)) ==
215 (DEV_PRESENT | DEV_CONFIG)))
216 return 1; 214 return 1;
217 return 0; 215 return 0;
218} 216}
@@ -237,7 +235,7 @@ static void sandisk_set_iobase(local_info_t *local)
237 reg.Action = CS_WRITE; 235 reg.Action = CS_WRITE;
238 reg.Offset = 0x10; /* 0x3f0 IO base 1 */ 236 reg.Offset = 0x10; /* 0x3f0 IO base 1 */
239 reg.Value = hw_priv->link->io.BasePort1 & 0x00ff; 237 reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
240 res = pcmcia_access_configuration_register(hw_priv->link->handle, 238 res = pcmcia_access_configuration_register(hw_priv->link,
241 &reg); 239 &reg);
242 if (res != CS_SUCCESS) { 240 if (res != CS_SUCCESS) {
243 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -" 241 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
@@ -249,7 +247,7 @@ static void sandisk_set_iobase(local_info_t *local)
249 reg.Action = CS_WRITE; 247 reg.Action = CS_WRITE;
250 reg.Offset = 0x12; /* 0x3f2 IO base 2 */ 248 reg.Offset = 0x12; /* 0x3f2 IO base 2 */
251 reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8; 249 reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
252 res = pcmcia_access_configuration_register(hw_priv->link->handle, 250 res = pcmcia_access_configuration_register(hw_priv->link,
253 &reg); 251 &reg);
254 if (res != CS_SUCCESS) { 252 if (res != CS_SUCCESS) {
255 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -" 253 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
@@ -301,9 +299,9 @@ static int sandisk_enable_wireless(struct net_device *dev)
301 tuple.TupleData = buf; 299 tuple.TupleData = buf;
302 tuple.TupleDataMax = sizeof(buf); 300 tuple.TupleDataMax = sizeof(buf);
303 tuple.TupleOffset = 0; 301 tuple.TupleOffset = 0;
304 if (pcmcia_get_first_tuple(hw_priv->link->handle, &tuple) || 302 if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
305 pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) || 303 pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
306 pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) || 304 pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
307 parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) { 305 parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) {
308 /* No SanDisk manfid found */ 306 /* No SanDisk manfid found */
309 ret = -ENODEV; 307 ret = -ENODEV;
@@ -311,9 +309,9 @@ static int sandisk_enable_wireless(struct net_device *dev)
311 } 309 }
312 310
313 tuple.DesiredTuple = CISTPL_LONGLINK_MFC; 311 tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
314 if (pcmcia_get_first_tuple(hw_priv->link->handle, &tuple) || 312 if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
315 pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) || 313 pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
316 pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) || 314 pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
317 parse->longlink_mfc.nfn < 2) { 315 parse->longlink_mfc.nfn < 2) {
318 /* No multi-function links found */ 316 /* No multi-function links found */
319 ret = -ENODEV; 317 ret = -ENODEV;
@@ -328,7 +326,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
328 reg.Action = CS_WRITE; 326 reg.Action = CS_WRITE;
329 reg.Offset = CISREG_COR; 327 reg.Offset = CISREG_COR;
330 reg.Value = COR_SOFT_RESET; 328 reg.Value = COR_SOFT_RESET;
331 res = pcmcia_access_configuration_register(hw_priv->link->handle, 329 res = pcmcia_access_configuration_register(hw_priv->link,
332 &reg); 330 &reg);
333 if (res != CS_SUCCESS) { 331 if (res != CS_SUCCESS) {
334 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", 332 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
@@ -345,7 +343,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
345 * will be enabled during the first cor_sreset call. 343 * will be enabled during the first cor_sreset call.
346 */ 344 */
347 reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA; 345 reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
348 res = pcmcia_access_configuration_register(hw_priv->link->handle, 346 res = pcmcia_access_configuration_register(hw_priv->link,
349 &reg); 347 &reg);
350 if (res != CS_SUCCESS) { 348 if (res != CS_SUCCESS) {
351 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", 349 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
@@ -380,7 +378,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
380 reg.Action = CS_READ; 378 reg.Action = CS_READ;
381 reg.Offset = CISREG_COR; 379 reg.Offset = CISREG_COR;
382 reg.Value = 0; 380 reg.Value = 0;
383 res = pcmcia_access_configuration_register(hw_priv->link->handle, 381 res = pcmcia_access_configuration_register(hw_priv->link,
384 &reg); 382 &reg);
385 if (res != CS_SUCCESS) { 383 if (res != CS_SUCCESS) {
386 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n", 384 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
@@ -392,7 +390,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
392 390
393 reg.Action = CS_WRITE; 391 reg.Action = CS_WRITE;
394 reg.Value |= COR_SOFT_RESET; 392 reg.Value |= COR_SOFT_RESET;
395 res = pcmcia_access_configuration_register(hw_priv->link->handle, 393 res = pcmcia_access_configuration_register(hw_priv->link,
396 &reg); 394 &reg);
397 if (res != CS_SUCCESS) { 395 if (res != CS_SUCCESS) {
398 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n", 396 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
@@ -405,7 +403,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
405 reg.Value &= ~COR_SOFT_RESET; 403 reg.Value &= ~COR_SOFT_RESET;
406 if (hw_priv->sandisk_connectplus) 404 if (hw_priv->sandisk_connectplus)
407 reg.Value |= COR_IREQ_ENA; 405 reg.Value |= COR_IREQ_ENA;
408 res = pcmcia_access_configuration_register(hw_priv->link->handle, 406 res = pcmcia_access_configuration_register(hw_priv->link,
409 &reg); 407 &reg);
410 if (res != CS_SUCCESS) { 408 if (res != CS_SUCCESS) {
411 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n", 409 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
@@ -439,7 +437,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
439 reg.Action = CS_READ; 437 reg.Action = CS_READ;
440 reg.Offset = CISREG_COR; 438 reg.Offset = CISREG_COR;
441 reg.Value = 0; 439 reg.Value = 0;
442 res = pcmcia_access_configuration_register(hw_priv->link->handle, 440 res = pcmcia_access_configuration_register(hw_priv->link,
443 &reg); 441 &reg);
444 if (res != CS_SUCCESS) { 442 if (res != CS_SUCCESS) {
445 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 " 443 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
@@ -452,7 +450,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
452 450
453 reg.Action = CS_WRITE; 451 reg.Action = CS_WRITE;
454 reg.Value |= COR_SOFT_RESET; 452 reg.Value |= COR_SOFT_RESET;
455 res = pcmcia_access_configuration_register(hw_priv->link->handle, 453 res = pcmcia_access_configuration_register(hw_priv->link,
456 &reg); 454 &reg);
457 if (res != CS_SUCCESS) { 455 if (res != CS_SUCCESS) {
458 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 " 456 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
@@ -466,7 +464,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
466 reg.Action = CS_WRITE; 464 reg.Action = CS_WRITE;
467 reg.Value = hcr; 465 reg.Value = hcr;
468 reg.Offset = CISREG_CCSR; 466 reg.Offset = CISREG_CCSR;
469 res = pcmcia_access_configuration_register(hw_priv->link->handle, 467 res = pcmcia_access_configuration_register(hw_priv->link,
470 &reg); 468 &reg);
471 if (res != CS_SUCCESS) { 469 if (res != CS_SUCCESS) {
472 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 " 470 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
@@ -478,7 +476,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
478 reg.Action = CS_WRITE; 476 reg.Action = CS_WRITE;
479 reg.Offset = CISREG_COR; 477 reg.Offset = CISREG_COR;
480 reg.Value = old_cor & ~COR_SOFT_RESET; 478 reg.Value = old_cor & ~COR_SOFT_RESET;
481 res = pcmcia_access_configuration_register(hw_priv->link->handle, 479 res = pcmcia_access_configuration_register(hw_priv->link,
482 &reg); 480 &reg);
483 if (res != CS_SUCCESS) { 481 if (res != CS_SUCCESS) {
484 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 " 482 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
@@ -501,40 +499,27 @@ static struct prism2_helper_functions prism2_pccard_funcs =
501 499
502/* allocate local data and register with CardServices 500/* allocate local data and register with CardServices
503 * initialize dev_link structure, but do not configure the card yet */ 501 * initialize dev_link structure, but do not configure the card yet */
504static int prism2_attach(struct pcmcia_device *p_dev) 502static int hostap_cs_probe(struct pcmcia_device *p_dev)
505{ 503{
506 dev_link_t *link; 504 int ret;
507
508 link = kmalloc(sizeof(dev_link_t), GFP_KERNEL);
509 if (link == NULL)
510 return -ENOMEM;
511
512 memset(link, 0, sizeof(dev_link_t));
513 505
514 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info); 506 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
515 link->conf.Vcc = 33; 507 p_dev->conf.IntType = INT_MEMORY_AND_IO;
516 link->conf.IntType = INT_MEMORY_AND_IO;
517
518 link->handle = p_dev;
519 p_dev->instance = link;
520 508
521 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 509 ret = prism2_config(p_dev);
522 if (prism2_config(link)) 510 if (ret) {
523 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n"); 511 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
512 }
524 513
525 return 0; 514 return ret;
526} 515}
527 516
528 517
529static void prism2_detach(struct pcmcia_device *p_dev) 518static void prism2_detach(struct pcmcia_device *link)
530{ 519{
531 dev_link_t *link = dev_to_instance(p_dev);
532
533 PDEBUG(DEBUG_FLOW, "prism2_detach\n"); 520 PDEBUG(DEBUG_FLOW, "prism2_detach\n");
534 521
535 if (link->state & DEV_CONFIG) { 522 prism2_release((u_long)link);
536 prism2_release((u_long)link);
537 }
538 523
539 /* release net devices */ 524 /* release net devices */
540 if (link->priv) { 525 if (link->priv) {
@@ -547,7 +532,6 @@ static void prism2_detach(struct pcmcia_device *p_dev)
547 prism2_free_local_data(dev); 532 prism2_free_local_data(dev);
548 kfree(hw_priv); 533 kfree(hw_priv);
549 } 534 }
550 kfree(link);
551} 535}
552 536
553 537
@@ -558,7 +542,7 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
558do { int ret = (retf); \ 542do { int ret = (retf); \
559if (ret != 0) { \ 543if (ret != 0) { \
560 PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \ 544 PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
561 cs_error(link->handle, fn, ret); \ 545 cs_error(link, fn, ret); \
562 goto next_entry; \ 546 goto next_entry; \
563} \ 547} \
564} while (0) 548} while (0)
@@ -566,7 +550,7 @@ if (ret != 0) { \
566 550
567/* run after a CARD_INSERTION event is received to configure the PCMCIA 551/* run after a CARD_INSERTION event is received to configure the PCMCIA
568 * socket and make the device available to the system */ 552 * socket and make the device available to the system */
569static int prism2_config(dev_link_t *link) 553static int prism2_config(struct pcmcia_device *link)
570{ 554{
571 struct net_device *dev; 555 struct net_device *dev;
572 struct hostap_interface *iface; 556 struct hostap_interface *iface;
@@ -595,27 +579,24 @@ static int prism2_config(dev_link_t *link)
595 tuple.TupleData = buf; 579 tuple.TupleData = buf;
596 tuple.TupleDataMax = sizeof(buf); 580 tuple.TupleDataMax = sizeof(buf);
597 tuple.TupleOffset = 0; 581 tuple.TupleOffset = 0;
598 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); 582 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
599 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple)); 583 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
600 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse)); 584 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, parse));
601 link->conf.ConfigBase = parse->config.base; 585 link->conf.ConfigBase = parse->config.base;
602 link->conf.Present = parse->config.rmask[0]; 586 link->conf.Present = parse->config.rmask[0];
603 587
604 CS_CHECK(GetConfigurationInfo, 588 CS_CHECK(GetConfigurationInfo,
605 pcmcia_get_configuration_info(link->handle, &conf)); 589 pcmcia_get_configuration_info(link, &conf));
606 PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info,
607 ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc);
608 link->conf.Vcc = conf.Vcc;
609 590
610 /* Look for an appropriate configuration table entry in the CIS */ 591 /* Look for an appropriate configuration table entry in the CIS */
611 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 592 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
612 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); 593 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
613 for (;;) { 594 for (;;) {
614 cistpl_cftable_entry_t *cfg = &(parse->cftable_entry); 595 cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
615 CFG_CHECK2(GetTupleData, 596 CFG_CHECK2(GetTupleData,
616 pcmcia_get_tuple_data(link->handle, &tuple)); 597 pcmcia_get_tuple_data(link, &tuple));
617 CFG_CHECK2(ParseTuple, 598 CFG_CHECK2(ParseTuple,
618 pcmcia_parse_tuple(link->handle, &tuple, parse)); 599 pcmcia_parse_tuple(link, &tuple, parse));
619 600
620 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 601 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
621 dflt = *cfg; 602 dflt = *cfg;
@@ -650,10 +631,10 @@ static int prism2_config(dev_link_t *link)
650 } 631 }
651 632
652 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 633 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
653 link->conf.Vpp1 = link->conf.Vpp2 = 634 link->conf.Vpp =
654 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 635 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
655 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 636 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
656 link->conf.Vpp1 = link->conf.Vpp2 = 637 link->conf.Vpp =
657 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 638 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
658 639
659 /* Do we need to allocate an interrupt? */ 640 /* Do we need to allocate an interrupt? */
@@ -695,19 +676,19 @@ static int prism2_config(dev_link_t *link)
695 676
696 /* This reserves IO space but doesn't actually enable it */ 677 /* This reserves IO space but doesn't actually enable it */
697 CFG_CHECK2(RequestIO, 678 CFG_CHECK2(RequestIO,
698 pcmcia_request_io(link->handle, &link->io)); 679 pcmcia_request_io(link, &link->io));
699 680
700 /* This configuration table entry is OK */ 681 /* This configuration table entry is OK */
701 break; 682 break;
702 683
703 next_entry: 684 next_entry:
704 CS_CHECK(GetNextTuple, 685 CS_CHECK(GetNextTuple,
705 pcmcia_get_next_tuple(link->handle, &tuple)); 686 pcmcia_get_next_tuple(link, &tuple));
706 } 687 }
707 688
708 /* Need to allocate net_device before requesting IRQ handler */ 689 /* Need to allocate net_device before requesting IRQ handler */
709 dev = prism2_init_local_data(&prism2_pccard_funcs, 0, 690 dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
710 &handle_to_dev(link->handle)); 691 &handle_to_dev(link));
711 if (dev == NULL) 692 if (dev == NULL)
712 goto failed; 693 goto failed;
713 link->priv = dev; 694 link->priv = dev;
@@ -717,7 +698,7 @@ static int prism2_config(dev_link_t *link)
717 local->hw_priv = hw_priv; 698 local->hw_priv = hw_priv;
718 hw_priv->link = link; 699 hw_priv->link = link;
719 strcpy(hw_priv->node.dev_name, dev->name); 700 strcpy(hw_priv->node.dev_name, dev->name);
720 link->dev = &hw_priv->node; 701 link->dev_node = &hw_priv->node;
721 702
722 /* 703 /*
723 * Allocate an interrupt line. Note that this does not assign a 704 * Allocate an interrupt line. Note that this does not assign a
@@ -730,7 +711,7 @@ static int prism2_config(dev_link_t *link)
730 link->irq.Handler = prism2_interrupt; 711 link->irq.Handler = prism2_interrupt;
731 link->irq.Instance = dev; 712 link->irq.Instance = dev;
732 CS_CHECK(RequestIRQ, 713 CS_CHECK(RequestIRQ,
733 pcmcia_request_irq(link->handle, &link->irq)); 714 pcmcia_request_irq(link, &link->irq));
734 } 715 }
735 716
736 /* 717 /*
@@ -739,18 +720,17 @@ static int prism2_config(dev_link_t *link)
739 * card and host interface into "Memory and IO" mode. 720 * card and host interface into "Memory and IO" mode.
740 */ 721 */
741 CS_CHECK(RequestConfiguration, 722 CS_CHECK(RequestConfiguration,
742 pcmcia_request_configuration(link->handle, &link->conf)); 723 pcmcia_request_configuration(link, &link->conf));
743 724
744 dev->irq = link->irq.AssignedIRQ; 725 dev->irq = link->irq.AssignedIRQ;
745 dev->base_addr = link->io.BasePort1; 726 dev->base_addr = link->io.BasePort1;
746 727
747 /* Finally, report what we've done */ 728 /* Finally, report what we've done */
748 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 729 printk(KERN_INFO "%s: index 0x%02x: ",
749 dev_info, link->conf.ConfigIndex, 730 dev_info, link->conf.ConfigIndex);
750 link->conf.Vcc / 10, link->conf.Vcc % 10); 731 if (link->conf.Vpp)
751 if (link->conf.Vpp1) 732 printk(", Vpp %d.%d", link->conf.Vpp / 10,
752 printk(", Vpp %d.%d", link->conf.Vpp1 / 10, 733 link->conf.Vpp % 10);
753 link->conf.Vpp1 % 10);
754 if (link->conf.Attributes & CONF_ENABLE_IRQ) 734 if (link->conf.Attributes & CONF_ENABLE_IRQ)
755 printk(", irq %d", link->irq.AssignedIRQ); 735 printk(", irq %d", link->irq.AssignedIRQ);
756 if (link->io.NumPorts1) 736 if (link->io.NumPorts1)
@@ -761,9 +741,6 @@ static int prism2_config(dev_link_t *link)
761 link->io.BasePort2+link->io.NumPorts2-1); 741 link->io.BasePort2+link->io.NumPorts2-1);
762 printk("\n"); 742 printk("\n");
763 743
764 link->state |= DEV_CONFIG;
765 link->state &= ~DEV_CONFIG_PENDING;
766
767 local->shutdown = 0; 744 local->shutdown = 0;
768 745
769 sandisk_enable_wireless(dev); 746 sandisk_enable_wireless(dev);
@@ -778,7 +755,7 @@ static int prism2_config(dev_link_t *link)
778 return ret; 755 return ret;
779 756
780 cs_failed: 757 cs_failed:
781 cs_error(link->handle, last_fn, last_ret); 758 cs_error(link, last_fn, last_ret);
782 759
783 failed: 760 failed:
784 kfree(parse); 761 kfree(parse);
@@ -790,7 +767,7 @@ static int prism2_config(dev_link_t *link)
790 767
791static void prism2_release(u_long arg) 768static void prism2_release(u_long arg)
792{ 769{
793 dev_link_t *link = (dev_link_t *)arg; 770 struct pcmcia_device *link = (struct pcmcia_device *)arg;
794 771
795 PDEBUG(DEBUG_FLOW, "prism2_release\n"); 772 PDEBUG(DEBUG_FLOW, "prism2_release\n");
796 773
@@ -799,71 +776,54 @@ static void prism2_release(u_long arg)
799 struct hostap_interface *iface; 776 struct hostap_interface *iface;
800 777
801 iface = netdev_priv(dev); 778 iface = netdev_priv(dev);
802 if (link->state & DEV_CONFIG) 779 prism2_hw_shutdown(dev, 0);
803 prism2_hw_shutdown(dev, 0);
804 iface->local->shutdown = 1; 780 iface->local->shutdown = 1;
805 } 781 }
806 782
807 if (link->win) 783 pcmcia_disable_device(link);
808 pcmcia_release_window(link->win);
809 pcmcia_release_configuration(link->handle);
810 if (link->io.NumPorts1)
811 pcmcia_release_io(link->handle, &link->io);
812 if (link->irq.AssignedIRQ)
813 pcmcia_release_irq(link->handle, &link->irq);
814
815 link->state &= ~DEV_CONFIG;
816
817 PDEBUG(DEBUG_FLOW, "release - done\n"); 784 PDEBUG(DEBUG_FLOW, "release - done\n");
818} 785}
819 786
820static int hostap_cs_suspend(struct pcmcia_device *p_dev) 787static int hostap_cs_suspend(struct pcmcia_device *link)
821{ 788{
822 dev_link_t *link = dev_to_instance(p_dev);
823 struct net_device *dev = (struct net_device *) link->priv; 789 struct net_device *dev = (struct net_device *) link->priv;
824 int dev_open = 0; 790 int dev_open = 0;
791 struct hostap_interface *iface = NULL;
825 792
826 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); 793 if (dev)
827 794 iface = netdev_priv(dev);
828 link->state |= DEV_SUSPEND;
829 795
830 if (link->state & DEV_CONFIG) { 796 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
831 struct hostap_interface *iface = netdev_priv(dev); 797 if (iface && iface->local)
832 if (iface && iface->local) 798 dev_open = iface->local->num_dev_open > 0;
833 dev_open = iface->local->num_dev_open > 0; 799 if (dev_open) {
834 if (dev_open) { 800 netif_stop_queue(dev);
835 netif_stop_queue(dev); 801 netif_device_detach(dev);
836 netif_device_detach(dev);
837 }
838 prism2_suspend(dev);
839 pcmcia_release_configuration(link->handle);
840 } 802 }
803 prism2_suspend(dev);
841 804
842 return 0; 805 return 0;
843} 806}
844 807
845static int hostap_cs_resume(struct pcmcia_device *p_dev) 808static int hostap_cs_resume(struct pcmcia_device *link)
846{ 809{
847 dev_link_t *link = dev_to_instance(p_dev);
848 struct net_device *dev = (struct net_device *) link->priv; 810 struct net_device *dev = (struct net_device *) link->priv;
849 int dev_open = 0; 811 int dev_open = 0;
812 struct hostap_interface *iface = NULL;
850 813
851 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); 814 if (dev)
815 iface = netdev_priv(dev);
852 816
853 link->state &= ~DEV_SUSPEND; 817 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
854 if (link->state & DEV_CONFIG) {
855 struct hostap_interface *iface = netdev_priv(dev);
856 if (iface && iface->local)
857 dev_open = iface->local->num_dev_open > 0;
858 818
859 pcmcia_request_configuration(link->handle, &link->conf); 819 if (iface && iface->local)
820 dev_open = iface->local->num_dev_open > 0;
860 821
861 prism2_hw_shutdown(dev, 1); 822 prism2_hw_shutdown(dev, 1);
862 prism2_hw_config(dev, dev_open ? 0 : 1); 823 prism2_hw_config(dev, dev_open ? 0 : 1);
863 if (dev_open) { 824 if (dev_open) {
864 netif_device_attach(dev); 825 netif_device_attach(dev);
865 netif_start_queue(dev); 826 netif_start_queue(dev);
866 }
867 } 827 }
868 828
869 return 0; 829 return 0;
@@ -930,7 +890,7 @@ static struct pcmcia_driver hostap_driver = {
930 .drv = { 890 .drv = {
931 .name = "hostap_cs", 891 .name = "hostap_cs",
932 }, 892 },
933 .probe = prism2_attach, 893 .probe = hostap_cs_probe,
934 .remove = prism2_detach, 894 .remove = prism2_detach,
935 .owner = THIS_MODULE, 895 .owner = THIS_MODULE,
936 .id_table = hostap_cs_ids, 896 .id_table = hostap_cs_ids,
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 75ce6ddb0cf5..9343d970537b 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -190,8 +190,8 @@ module_param(mem_speed, int, 0);
190/*====================================================================*/ 190/*====================================================================*/
191 191
192/* PCMCIA (Card Services) related functions */ 192/* PCMCIA (Card Services) related functions */
193static void netwave_release(dev_link_t *link); /* Card removal */ 193static void netwave_release(struct pcmcia_device *link); /* Card removal */
194static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card 194static int netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
195 insertion */ 195 insertion */
196static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */ 196static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */
197 197
@@ -221,10 +221,10 @@ static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
221static void set_multicast_list(struct net_device *dev); 221static void set_multicast_list(struct net_device *dev);
222 222
223/* 223/*
224 A dev_link_t structure has fields for most things that are needed 224 A struct pcmcia_device structure has fields for most things that are needed
225 to keep track of a socket, but there will usually be some device 225 to keep track of a socket, but there will usually be some device
226 specific information that also needs to be kept track of. The 226 specific information that also needs to be kept track of. The
227 'priv' pointer in a dev_link_t structure can be used to point to 227 'priv' pointer in a struct pcmcia_device structure can be used to point to
228 a device-specific private data structure, like this. 228 a device-specific private data structure, like this.
229 229
230 A driver needs to provide a dev_node_t structure for each device 230 A driver needs to provide a dev_node_t structure for each device
@@ -232,7 +232,7 @@ static void set_multicast_list(struct net_device *dev);
232 example, ethernet cards, modems). In other cases, there may be 232 example, ethernet cards, modems). In other cases, there may be
233 many actual or logical devices (SCSI adapters, memory cards with 233 many actual or logical devices (SCSI adapters, memory cards with
234 multiple partitions). The dev_node_t structures need to be kept 234 multiple partitions). The dev_node_t structures need to be kept
235 in a linked list starting at the 'dev' field of a dev_link_t 235 in a linked list starting at the 'dev' field of a struct pcmcia_device
236 structure. We allocate them in the card's private data structure, 236 structure. We allocate them in the card's private data structure,
237 because they generally can't be allocated dynamically. 237 because they generally can't be allocated dynamically.
238*/ 238*/
@@ -268,7 +268,7 @@ struct site_survey {
268}; 268};
269 269
270typedef struct netwave_private { 270typedef struct netwave_private {
271 dev_link_t link; 271 struct pcmcia_device *p_dev;
272 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */ 272 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
273 dev_node_t node; 273 dev_node_t node;
274 u_char __iomem *ramBase; 274 u_char __iomem *ramBase;
@@ -376,20 +376,19 @@ static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
376 * configure the card at this point -- we wait until we receive a 376 * configure the card at this point -- we wait until we receive a
377 * card insertion event. 377 * card insertion event.
378 */ 378 */
379static int netwave_attach(struct pcmcia_device *p_dev) 379static int netwave_probe(struct pcmcia_device *link)
380{ 380{
381 dev_link_t *link;
382 struct net_device *dev; 381 struct net_device *dev;
383 netwave_private *priv; 382 netwave_private *priv;
384 383
385 DEBUG(0, "netwave_attach()\n"); 384 DEBUG(0, "netwave_attach()\n");
386 385
387 /* Initialize the dev_link_t structure */ 386 /* Initialize the struct pcmcia_device structure */
388 dev = alloc_etherdev(sizeof(netwave_private)); 387 dev = alloc_etherdev(sizeof(netwave_private));
389 if (!dev) 388 if (!dev)
390 return -ENOMEM; 389 return -ENOMEM;
391 priv = netdev_priv(dev); 390 priv = netdev_priv(dev);
392 link = &priv->link; 391 priv->p_dev = link;
393 link->priv = dev; 392 link->priv = dev;
394 393
395 /* The io structure describes IO port mapping */ 394 /* The io structure describes IO port mapping */
@@ -406,7 +405,6 @@ static int netwave_attach(struct pcmcia_device *p_dev)
406 405
407 /* General socket configuration */ 406 /* General socket configuration */
408 link->conf.Attributes = CONF_ENABLE_IRQ; 407 link->conf.Attributes = CONF_ENABLE_IRQ;
409 link->conf.Vcc = 50;
410 link->conf.IntType = INT_MEMORY_AND_IO; 408 link->conf.IntType = INT_MEMORY_AND_IO;
411 link->conf.ConfigIndex = 1; 409 link->conf.ConfigIndex = 1;
412 link->conf.Present = PRESENT_OPTION; 410 link->conf.Present = PRESENT_OPTION;
@@ -430,13 +428,7 @@ static int netwave_attach(struct pcmcia_device *p_dev)
430 dev->stop = &netwave_close; 428 dev->stop = &netwave_close;
431 link->irq.Instance = dev; 429 link->irq.Instance = dev;
432 430
433 link->handle = p_dev; 431 return netwave_pcmcia_config( link);
434 p_dev->instance = link;
435
436 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
437 netwave_pcmcia_config( link);
438
439 return 0;
440} /* netwave_attach */ 432} /* netwave_attach */
441 433
442/* 434/*
@@ -447,17 +439,15 @@ static int netwave_attach(struct pcmcia_device *p_dev)
447 * structures are freed. Otherwise, the structures will be freed 439 * structures are freed. Otherwise, the structures will be freed
448 * when the device is released. 440 * when the device is released.
449 */ 441 */
450static void netwave_detach(struct pcmcia_device *p_dev) 442static void netwave_detach(struct pcmcia_device *link)
451{ 443{
452 dev_link_t *link = dev_to_instance(p_dev);
453 struct net_device *dev = link->priv; 444 struct net_device *dev = link->priv;
454 445
455 DEBUG(0, "netwave_detach(0x%p)\n", link); 446 DEBUG(0, "netwave_detach(0x%p)\n", link);
456 447
457 if (link->state & DEV_CONFIG) 448 netwave_release(link);
458 netwave_release(link);
459 449
460 if (link->dev) 450 if (link->dev_node)
461 unregister_netdev(dev); 451 unregister_netdev(dev);
462 452
463 free_netdev(dev); 453 free_netdev(dev);
@@ -743,8 +733,7 @@ static const struct iw_handler_def netwave_handler_def =
743#define CS_CHECK(fn, ret) \ 733#define CS_CHECK(fn, ret) \
744do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 734do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
745 735
746static void netwave_pcmcia_config(dev_link_t *link) { 736static int netwave_pcmcia_config(struct pcmcia_device *link) {
747 client_handle_t handle = link->handle;
748 struct net_device *dev = link->priv; 737 struct net_device *dev = link->priv;
749 netwave_private *priv = netdev_priv(dev); 738 netwave_private *priv = netdev_priv(dev);
750 tuple_t tuple; 739 tuple_t tuple;
@@ -766,15 +755,12 @@ static void netwave_pcmcia_config(dev_link_t *link) {
766 tuple.TupleDataMax = 64; 755 tuple.TupleDataMax = 64;
767 tuple.TupleOffset = 0; 756 tuple.TupleOffset = 0;
768 tuple.DesiredTuple = CISTPL_CONFIG; 757 tuple.DesiredTuple = CISTPL_CONFIG;
769 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 758 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
770 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 759 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
771 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 760 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
772 link->conf.ConfigBase = parse.config.base; 761 link->conf.ConfigBase = parse.config.base;
773 link->conf.Present = parse.config.rmask[0]; 762 link->conf.Present = parse.config.rmask[0];
774 763
775 /* Configure card */
776 link->state |= DEV_CONFIG;
777
778 /* 764 /*
779 * Try allocating IO ports. This tries a few fixed addresses. 765 * Try allocating IO ports. This tries a few fixed addresses.
780 * If you want, you can also read the card's config table to 766 * If you want, you can also read the card's config table to
@@ -782,11 +768,11 @@ static void netwave_pcmcia_config(dev_link_t *link) {
782 */ 768 */
783 for (i = j = 0x0; j < 0x400; j += 0x20) { 769 for (i = j = 0x0; j < 0x400; j += 0x20) {
784 link->io.BasePort1 = j ^ 0x300; 770 link->io.BasePort1 = j ^ 0x300;
785 i = pcmcia_request_io(link->handle, &link->io); 771 i = pcmcia_request_io(link, &link->io);
786 if (i == CS_SUCCESS) break; 772 if (i == CS_SUCCESS) break;
787 } 773 }
788 if (i != CS_SUCCESS) { 774 if (i != CS_SUCCESS) {
789 cs_error(link->handle, RequestIO, i); 775 cs_error(link, RequestIO, i);
790 goto failed; 776 goto failed;
791 } 777 }
792 778
@@ -794,16 +780,16 @@ static void netwave_pcmcia_config(dev_link_t *link) {
794 * Now allocate an interrupt line. Note that this does not 780 * Now allocate an interrupt line. Note that this does not
795 * actually assign a handler to the interrupt. 781 * actually assign a handler to the interrupt.
796 */ 782 */
797 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 783 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
798 784
799 /* 785 /*
800 * This actually configures the PCMCIA socket -- setting up 786 * This actually configures the PCMCIA socket -- setting up
801 * the I/O windows and the interrupt mapping. 787 * the I/O windows and the interrupt mapping.
802 */ 788 */
803 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 789 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
804 790
805 /* 791 /*
806 * Allocate a 32K memory window. Note that the dev_link_t 792 * Allocate a 32K memory window. Note that the struct pcmcia_device
807 * structure provides space for one window handle -- if your 793 * structure provides space for one window handle -- if your
808 * device needs several windows, you'll need to keep track of 794 * device needs several windows, you'll need to keep track of
809 * the handles in your private data structure, dev->priv. 795 * the handles in your private data structure, dev->priv.
@@ -813,7 +799,7 @@ static void netwave_pcmcia_config(dev_link_t *link) {
813 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE; 799 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
814 req.Base = 0; req.Size = 0x8000; 800 req.Base = 0; req.Size = 0x8000;
815 req.AccessSpeed = mem_speed; 801 req.AccessSpeed = mem_speed;
816 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 802 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
817 mem.CardOffset = 0x20000; mem.Page = 0; 803 mem.CardOffset = 0x20000; mem.Page = 0;
818 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 804 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
819 805
@@ -823,7 +809,7 @@ static void netwave_pcmcia_config(dev_link_t *link) {
823 809
824 dev->irq = link->irq.AssignedIRQ; 810 dev->irq = link->irq.AssignedIRQ;
825 dev->base_addr = link->io.BasePort1; 811 dev->base_addr = link->io.BasePort1;
826 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 812 SET_NETDEV_DEV(dev, &handle_to_dev(link));
827 813
828 if (register_netdev(dev) != 0) { 814 if (register_netdev(dev) != 0) {
829 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n"); 815 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
@@ -831,8 +817,7 @@ static void netwave_pcmcia_config(dev_link_t *link) {
831 } 817 }
832 818
833 strcpy(priv->node.dev_name, dev->name); 819 strcpy(priv->node.dev_name, dev->name);
834 link->dev = &priv->node; 820 link->dev_node = &priv->node;
835 link->state &= ~DEV_CONFIG_PENDING;
836 821
837 /* Reset card before reading physical address */ 822 /* Reset card before reading physical address */
838 netwave_doreset(dev->base_addr, ramBase); 823 netwave_doreset(dev->base_addr, ramBase);
@@ -852,12 +837,13 @@ static void netwave_pcmcia_config(dev_link_t *link) {
852 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n", 837 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
853 get_uint16(ramBase + NETWAVE_EREG_ARW), 838 get_uint16(ramBase + NETWAVE_EREG_ARW),
854 get_uint16(ramBase + NETWAVE_EREG_ARW+2)); 839 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
855 return; 840 return 0;
856 841
857cs_failed: 842cs_failed:
858 cs_error(link->handle, last_fn, last_ret); 843 cs_error(link, last_fn, last_ret);
859failed: 844failed:
860 netwave_release(link); 845 netwave_release(link);
846 return -ENODEV;
861} /* netwave_pcmcia_config */ 847} /* netwave_pcmcia_config */
862 848
863/* 849/*
@@ -867,52 +853,35 @@ failed:
867 * device, and release the PCMCIA configuration. If the device is 853 * device, and release the PCMCIA configuration. If the device is
868 * still open, this will be postponed until it is closed. 854 * still open, this will be postponed until it is closed.
869 */ 855 */
870static void netwave_release(dev_link_t *link) 856static void netwave_release(struct pcmcia_device *link)
871{ 857{
872 struct net_device *dev = link->priv; 858 struct net_device *dev = link->priv;
873 netwave_private *priv = netdev_priv(dev); 859 netwave_private *priv = netdev_priv(dev);
874
875 DEBUG(0, "netwave_release(0x%p)\n", link);
876 860
877 /* Don't bother checking to see if these succeed or not */ 861 DEBUG(0, "netwave_release(0x%p)\n", link);
878 if (link->win) {
879 iounmap(priv->ramBase);
880 pcmcia_release_window(link->win);
881 }
882 pcmcia_release_configuration(link->handle);
883 pcmcia_release_io(link->handle, &link->io);
884 pcmcia_release_irq(link->handle, &link->irq);
885 862
886 link->state &= ~DEV_CONFIG; 863 pcmcia_disable_device(link);
864 if (link->win)
865 iounmap(priv->ramBase);
887} 866}
888 867
889static int netwave_suspend(struct pcmcia_device *p_dev) 868static int netwave_suspend(struct pcmcia_device *link)
890{ 869{
891 dev_link_t *link = dev_to_instance(p_dev);
892 struct net_device *dev = link->priv; 870 struct net_device *dev = link->priv;
893 871
894 link->state |= DEV_SUSPEND; 872 if (link->open)
895 if (link->state & DEV_CONFIG) { 873 netif_device_detach(dev);
896 if (link->open)
897 netif_device_detach(dev);
898 pcmcia_release_configuration(link->handle);
899 }
900 874
901 return 0; 875 return 0;
902} 876}
903 877
904static int netwave_resume(struct pcmcia_device *p_dev) 878static int netwave_resume(struct pcmcia_device *link)
905{ 879{
906 dev_link_t *link = dev_to_instance(p_dev);
907 struct net_device *dev = link->priv; 880 struct net_device *dev = link->priv;
908 881
909 link->state &= ~DEV_SUSPEND; 882 if (link->open) {
910 if (link->state & DEV_CONFIG) { 883 netwave_reset(dev);
911 pcmcia_request_configuration(link->handle, &link->conf); 884 netif_device_attach(dev);
912 if (link->open) {
913 netwave_reset(dev);
914 netif_device_attach(dev);
915 }
916 } 885 }
917 886
918 return 0; 887 return 0;
@@ -1119,7 +1088,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs
1119 u_char __iomem *ramBase; 1088 u_char __iomem *ramBase;
1120 struct net_device *dev = (struct net_device *)dev_id; 1089 struct net_device *dev = (struct net_device *)dev_id;
1121 struct netwave_private *priv = netdev_priv(dev); 1090 struct netwave_private *priv = netdev_priv(dev);
1122 dev_link_t *link = &priv->link; 1091 struct pcmcia_device *link = priv->p_dev;
1123 int i; 1092 int i;
1124 1093
1125 if (!netif_device_present(dev)) 1094 if (!netif_device_present(dev))
@@ -1138,7 +1107,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs
1138 1107
1139 status = inb(iobase + NETWAVE_REG_ASR); 1108 status = inb(iobase + NETWAVE_REG_ASR);
1140 1109
1141 if (!DEV_OK(link)) { 1110 if (!pcmcia_dev_present(link)) {
1142 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x " 1111 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1143 "from removed or suspended card!\n", status); 1112 "from removed or suspended card!\n", status);
1144 break; 1113 break;
@@ -1373,11 +1342,11 @@ static int netwave_rx(struct net_device *dev)
1373 1342
1374static int netwave_open(struct net_device *dev) { 1343static int netwave_open(struct net_device *dev) {
1375 netwave_private *priv = netdev_priv(dev); 1344 netwave_private *priv = netdev_priv(dev);
1376 dev_link_t *link = &priv->link; 1345 struct pcmcia_device *link = priv->p_dev;
1377 1346
1378 DEBUG(1, "netwave_open: starting.\n"); 1347 DEBUG(1, "netwave_open: starting.\n");
1379 1348
1380 if (!DEV_OK(link)) 1349 if (!pcmcia_dev_present(link))
1381 return -ENODEV; 1350 return -ENODEV;
1382 1351
1383 link->open++; 1352 link->open++;
@@ -1390,7 +1359,7 @@ static int netwave_open(struct net_device *dev) {
1390 1359
1391static int netwave_close(struct net_device *dev) { 1360static int netwave_close(struct net_device *dev) {
1392 netwave_private *priv = netdev_priv(dev); 1361 netwave_private *priv = netdev_priv(dev);
1393 dev_link_t *link = &priv->link; 1362 struct pcmcia_device *link = priv->p_dev;
1394 1363
1395 DEBUG(1, "netwave_close: finishing.\n"); 1364 DEBUG(1, "netwave_close: finishing.\n");
1396 1365
@@ -1411,7 +1380,7 @@ static struct pcmcia_driver netwave_driver = {
1411 .drv = { 1380 .drv = {
1412 .name = "netwave_cs", 1381 .name = "netwave_cs",
1413 }, 1382 },
1414 .probe = netwave_attach, 1383 .probe = netwave_probe,
1415 .remove = netwave_detach, 1384 .remove = netwave_detach,
1416 .id_table = netwave_ids, 1385 .id_table = netwave_ids,
1417 .suspend = netwave_suspend, 1386 .suspend = netwave_suspend,
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index ec6f2a48895b..434f7d7ad841 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -49,7 +49,7 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket
49/* PCMCIA specific device information (goes in the card field of 49/* PCMCIA specific device information (goes in the card field of
50 * struct orinoco_private */ 50 * struct orinoco_private */
51struct orinoco_pccard { 51struct orinoco_pccard {
52 dev_link_t link; 52 struct pcmcia_device *p_dev;
53 dev_node_t node; 53 dev_node_t node;
54 54
55 /* Used to handle hard reset */ 55 /* Used to handle hard reset */
@@ -63,8 +63,8 @@ struct orinoco_pccard {
63/* Function prototypes */ 63/* Function prototypes */
64/********************************************************************/ 64/********************************************************************/
65 65
66static void orinoco_cs_config(dev_link_t *link); 66static int orinoco_cs_config(struct pcmcia_device *link);
67static void orinoco_cs_release(dev_link_t *link); 67static void orinoco_cs_release(struct pcmcia_device *link);
68static void orinoco_cs_detach(struct pcmcia_device *p_dev); 68static void orinoco_cs_detach(struct pcmcia_device *p_dev);
69 69
70/********************************************************************/ 70/********************************************************************/
@@ -75,13 +75,13 @@ static int
75orinoco_cs_hard_reset(struct orinoco_private *priv) 75orinoco_cs_hard_reset(struct orinoco_private *priv)
76{ 76{
77 struct orinoco_pccard *card = priv->card; 77 struct orinoco_pccard *card = priv->card;
78 dev_link_t *link = &card->link; 78 struct pcmcia_device *link = card->p_dev;
79 int err; 79 int err;
80 80
81 /* We need atomic ops here, because we're not holding the lock */ 81 /* We need atomic ops here, because we're not holding the lock */
82 set_bit(0, &card->hard_reset_in_progress); 82 set_bit(0, &card->hard_reset_in_progress);
83 83
84 err = pcmcia_reset_card(link->handle, NULL); 84 err = pcmcia_reset_card(link, NULL);
85 if (err) 85 if (err)
86 return err; 86 return err;
87 87
@@ -104,12 +104,11 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
104 * configure the card at this point -- we wait until we receive a card 104 * configure the card at this point -- we wait until we receive a card
105 * insertion event. */ 105 * insertion event. */
106static int 106static int
107orinoco_cs_attach(struct pcmcia_device *p_dev) 107orinoco_cs_probe(struct pcmcia_device *link)
108{ 108{
109 struct net_device *dev; 109 struct net_device *dev;
110 struct orinoco_private *priv; 110 struct orinoco_private *priv;
111 struct orinoco_pccard *card; 111 struct orinoco_pccard *card;
112 dev_link_t *link;
113 112
114 dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset); 113 dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset);
115 if (! dev) 114 if (! dev)
@@ -118,7 +117,7 @@ orinoco_cs_attach(struct pcmcia_device *p_dev)
118 card = priv->card; 117 card = priv->card;
119 118
120 /* Link both structures together */ 119 /* Link both structures together */
121 link = &card->link; 120 card->p_dev = link;
122 link->priv = dev; 121 link->priv = dev;
123 122
124 /* Interrupt setup */ 123 /* Interrupt setup */
@@ -135,16 +134,7 @@ orinoco_cs_attach(struct pcmcia_device *p_dev)
135 link->conf.Attributes = 0; 134 link->conf.Attributes = 0;
136 link->conf.IntType = INT_MEMORY_AND_IO; 135 link->conf.IntType = INT_MEMORY_AND_IO;
137 136
138 /* Register with Card Services */ 137 return orinoco_cs_config(link);
139 link->next = NULL;
140
141 link->handle = p_dev;
142 p_dev->instance = link;
143
144 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
145 orinoco_cs_config(link);
146
147 return 0;
148} /* orinoco_cs_attach */ 138} /* orinoco_cs_attach */
149 139
150/* 140/*
@@ -153,16 +143,14 @@ orinoco_cs_attach(struct pcmcia_device *p_dev)
153 * are freed. Otherwise, the structures will be freed when the device 143 * are freed. Otherwise, the structures will be freed when the device
154 * is released. 144 * is released.
155 */ 145 */
156static void orinoco_cs_detach(struct pcmcia_device *p_dev) 146static void orinoco_cs_detach(struct pcmcia_device *link)
157{ 147{
158 dev_link_t *link = dev_to_instance(p_dev);
159 struct net_device *dev = link->priv; 148 struct net_device *dev = link->priv;
160 149
161 if (link->state & DEV_CONFIG) 150 orinoco_cs_release(link);
162 orinoco_cs_release(link);
163 151
164 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); 152 DEBUG(0, PFX "detach: link=%p link->dev_node=%p\n", link, link->dev_node);
165 if (link->dev) { 153 if (link->dev_node) {
166 DEBUG(0, PFX "About to unregister net device %p\n", 154 DEBUG(0, PFX "About to unregister net device %p\n",
167 dev); 155 dev);
168 unregister_netdev(dev); 156 unregister_netdev(dev);
@@ -180,11 +168,10 @@ static void orinoco_cs_detach(struct pcmcia_device *p_dev)
180 last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \ 168 last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \
181 } while (0) 169 } while (0)
182 170
183static void 171static int
184orinoco_cs_config(dev_link_t *link) 172orinoco_cs_config(struct pcmcia_device *link)
185{ 173{
186 struct net_device *dev = link->priv; 174 struct net_device *dev = link->priv;
187 client_handle_t handle = link->handle;
188 struct orinoco_private *priv = netdev_priv(dev); 175 struct orinoco_private *priv = netdev_priv(dev);
189 struct orinoco_pccard *card = priv->card; 176 struct orinoco_pccard *card = priv->card;
190 hermes_t *hw = &priv->hw; 177 hermes_t *hw = &priv->hw;
@@ -196,7 +183,7 @@ orinoco_cs_config(dev_link_t *link)
196 cisparse_t parse; 183 cisparse_t parse;
197 void __iomem *mem; 184 void __iomem *mem;
198 185
199 CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info)); 186 CS_CHECK(ValidateCIS, pcmcia_validate_cis(link, &info));
200 187
201 /* 188 /*
202 * This reads the card's CONFIG tuple to find its 189 * This reads the card's CONFIG tuple to find its
@@ -207,19 +194,15 @@ orinoco_cs_config(dev_link_t *link)
207 tuple.TupleData = buf; 194 tuple.TupleData = buf;
208 tuple.TupleDataMax = sizeof(buf); 195 tuple.TupleDataMax = sizeof(buf);
209 tuple.TupleOffset = 0; 196 tuple.TupleOffset = 0;
210 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 197 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
211 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 198 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
212 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 199 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
213 link->conf.ConfigBase = parse.config.base; 200 link->conf.ConfigBase = parse.config.base;
214 link->conf.Present = parse.config.rmask[0]; 201 link->conf.Present = parse.config.rmask[0];
215 202
216 /* Configure card */
217 link->state |= DEV_CONFIG;
218
219 /* Look up the current Vcc */ 203 /* Look up the current Vcc */
220 CS_CHECK(GetConfigurationInfo, 204 CS_CHECK(GetConfigurationInfo,
221 pcmcia_get_configuration_info(handle, &conf)); 205 pcmcia_get_configuration_info(link, &conf));
222 link->conf.Vcc = conf.Vcc;
223 206
224 /* 207 /*
225 * In this loop, we scan the CIS for configuration table 208 * In this loop, we scan the CIS for configuration table
@@ -236,13 +219,13 @@ orinoco_cs_config(dev_link_t *link)
236 * implementation-defined details. 219 * implementation-defined details.
237 */ 220 */
238 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 221 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
239 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 222 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
240 while (1) { 223 while (1) {
241 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 224 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
242 cistpl_cftable_entry_t dflt = { .index = 0 }; 225 cistpl_cftable_entry_t dflt = { .index = 0 };
243 226
244 if ( (pcmcia_get_tuple_data(handle, &tuple) != 0) 227 if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
245 || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0)) 228 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
246 goto next_entry; 229 goto next_entry;
247 230
248 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 231 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
@@ -274,10 +257,10 @@ orinoco_cs_config(dev_link_t *link)
274 } 257 }
275 258
276 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 259 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
277 link->conf.Vpp1 = link->conf.Vpp2 = 260 link->conf.Vpp =
278 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 261 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
279 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 262 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
280 link->conf.Vpp1 = link->conf.Vpp2 = 263 link->conf.Vpp =
281 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 264 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
282 265
283 /* Do we need to allocate an interrupt? */ 266 /* Do we need to allocate an interrupt? */
@@ -307,7 +290,7 @@ orinoco_cs_config(dev_link_t *link)
307 } 290 }
308 291
309 /* This reserves IO space but doesn't actually enable it */ 292 /* This reserves IO space but doesn't actually enable it */
310 if (pcmcia_request_io(link->handle, &link->io) != 0) 293 if (pcmcia_request_io(link, &link->io) != 0)
311 goto next_entry; 294 goto next_entry;
312 } 295 }
313 296
@@ -317,9 +300,8 @@ orinoco_cs_config(dev_link_t *link)
317 break; 300 break;
318 301
319 next_entry: 302 next_entry:
320 if (link->io.NumPorts1) 303 pcmcia_disable_device(link);
321 pcmcia_release_io(link->handle, &link->io); 304 last_ret = pcmcia_get_next_tuple(link, &tuple);
322 last_ret = pcmcia_get_next_tuple(handle, &tuple);
323 if (last_ret == CS_NO_MORE_ITEMS) { 305 if (last_ret == CS_NO_MORE_ITEMS) {
324 printk(KERN_ERR PFX "GetNextTuple(): No matching " 306 printk(KERN_ERR PFX "GetNextTuple(): No matching "
325 "CIS configuration. Maybe you need the " 307 "CIS configuration. Maybe you need the "
@@ -333,7 +315,7 @@ orinoco_cs_config(dev_link_t *link)
333 * a handler to the interrupt, unless the 'Handler' member of 315 * a handler to the interrupt, unless the 'Handler' member of
334 * the irq structure is initialized. 316 * the irq structure is initialized.
335 */ 317 */
336 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 318 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
337 319
338 /* We initialize the hermes structure before completing PCMCIA 320 /* We initialize the hermes structure before completing PCMCIA
339 * configuration just in case the interrupt handler gets 321 * configuration just in case the interrupt handler gets
@@ -350,7 +332,7 @@ orinoco_cs_config(dev_link_t *link)
350 * card and host interface into "Memory and IO" mode. 332 * card and host interface into "Memory and IO" mode.
351 */ 333 */
352 CS_CHECK(RequestConfiguration, 334 CS_CHECK(RequestConfiguration,
353 pcmcia_request_configuration(link->handle, &link->conf)); 335 pcmcia_request_configuration(link, &link->conf));
354 336
355 /* Ok, we have the configuration, prepare to register the netdev */ 337 /* Ok, we have the configuration, prepare to register the netdev */
356 dev->base_addr = link->io.BasePort1; 338 dev->base_addr = link->io.BasePort1;
@@ -358,7 +340,7 @@ orinoco_cs_config(dev_link_t *link)
358 SET_MODULE_OWNER(dev); 340 SET_MODULE_OWNER(dev);
359 card->node.major = card->node.minor = 0; 341 card->node.major = card->node.minor = 0;
360 342
361 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 343 SET_NETDEV_DEV(dev, &handle_to_dev(link));
362 /* Tell the stack we exist */ 344 /* Tell the stack we exist */
363 if (register_netdev(dev) != 0) { 345 if (register_netdev(dev) != 0) {
364 printk(KERN_ERR PFX "register_netdev() failed\n"); 346 printk(KERN_ERR PFX "register_netdev() failed\n");
@@ -366,20 +348,18 @@ orinoco_cs_config(dev_link_t *link)
366 } 348 }
367 349
368 /* At this point, the dev_node_t structure(s) needs to be 350 /* At this point, the dev_node_t structure(s) needs to be
369 * initialized and arranged in a linked list at link->dev. */ 351 * initialized and arranged in a linked list at link->dev_node. */
370 strcpy(card->node.dev_name, dev->name); 352 strcpy(card->node.dev_name, dev->name);
371 link->dev = &card->node; /* link->dev being non-NULL is also 353 link->dev_node = &card->node; /* link->dev_node being non-NULL is also
372 used to indicate that the 354 used to indicate that the
373 net_device has been registered */ 355 net_device has been registered */
374 link->state &= ~DEV_CONFIG_PENDING;
375 356
376 /* Finally, report what we've done */ 357 /* Finally, report what we've done */
377 printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d", 358 printk(KERN_DEBUG "%s: index 0x%02x: ",
378 dev->name, link->conf.ConfigIndex, 359 dev->name, link->conf.ConfigIndex);
379 link->conf.Vcc / 10, link->conf.Vcc % 10); 360 if (link->conf.Vpp)
380 if (link->conf.Vpp1) 361 printk(", Vpp %d.%d", link->conf.Vpp / 10,
381 printk(", Vpp %d.%d", link->conf.Vpp1 / 10, 362 link->conf.Vpp % 10);
382 link->conf.Vpp1 % 10);
383 printk(", irq %d", link->irq.AssignedIRQ); 363 printk(", irq %d", link->irq.AssignedIRQ);
384 if (link->io.NumPorts1) 364 if (link->io.NumPorts1)
385 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 365 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
@@ -389,13 +369,14 @@ orinoco_cs_config(dev_link_t *link)
389 link->io.BasePort2 + link->io.NumPorts2 - 1); 369 link->io.BasePort2 + link->io.NumPorts2 - 1);
390 printk("\n"); 370 printk("\n");
391 371
392 return; 372 return 0;
393 373
394 cs_failed: 374 cs_failed:
395 cs_error(link->handle, last_fn, last_ret); 375 cs_error(link, last_fn, last_ret);
396 376
397 failed: 377 failed:
398 orinoco_cs_release(link); 378 orinoco_cs_release(link);
379 return -ENODEV;
399} /* orinoco_cs_config */ 380} /* orinoco_cs_config */
400 381
401/* 382/*
@@ -404,7 +385,7 @@ orinoco_cs_config(dev_link_t *link)
404 * still open, this will be postponed until it is closed. 385 * still open, this will be postponed until it is closed.
405 */ 386 */
406static void 387static void
407orinoco_cs_release(dev_link_t *link) 388orinoco_cs_release(struct pcmcia_device *link)
408{ 389{
409 struct net_device *dev = link->priv; 390 struct net_device *dev = link->priv;
410 struct orinoco_private *priv = netdev_priv(dev); 391 struct orinoco_private *priv = netdev_priv(dev);
@@ -416,88 +397,68 @@ orinoco_cs_release(dev_link_t *link)
416 priv->hw_unavailable++; 397 priv->hw_unavailable++;
417 spin_unlock_irqrestore(&priv->lock, flags); 398 spin_unlock_irqrestore(&priv->lock, flags);
418 399
419 /* Don't bother checking to see if these succeed or not */ 400 pcmcia_disable_device(link);
420 pcmcia_release_configuration(link->handle);
421 if (link->io.NumPorts1)
422 pcmcia_release_io(link->handle, &link->io);
423 if (link->irq.AssignedIRQ)
424 pcmcia_release_irq(link->handle, &link->irq);
425 link->state &= ~DEV_CONFIG;
426 if (priv->hw.iobase) 401 if (priv->hw.iobase)
427 ioport_unmap(priv->hw.iobase); 402 ioport_unmap(priv->hw.iobase);
428} /* orinoco_cs_release */ 403} /* orinoco_cs_release */
429 404
430static int orinoco_cs_suspend(struct pcmcia_device *p_dev) 405static int orinoco_cs_suspend(struct pcmcia_device *link)
431{ 406{
432 dev_link_t *link = dev_to_instance(p_dev);
433 struct net_device *dev = link->priv; 407 struct net_device *dev = link->priv;
434 struct orinoco_private *priv = netdev_priv(dev); 408 struct orinoco_private *priv = netdev_priv(dev);
435 struct orinoco_pccard *card = priv->card; 409 struct orinoco_pccard *card = priv->card;
436 int err = 0; 410 int err = 0;
437 unsigned long flags; 411 unsigned long flags;
438 412
439 link->state |= DEV_SUSPEND; 413 /* This is probably racy, but I can't think of
440 if (link->state & DEV_CONFIG) { 414 a better way, short of rewriting the PCMCIA
441 /* This is probably racy, but I can't think of 415 layer to not suck :-( */
442 a better way, short of rewriting the PCMCIA 416 if (! test_bit(0, &card->hard_reset_in_progress)) {
443 layer to not suck :-( */ 417 spin_lock_irqsave(&priv->lock, flags);
444 if (! test_bit(0, &card->hard_reset_in_progress)) {
445 spin_lock_irqsave(&priv->lock, flags);
446 418
447 err = __orinoco_down(dev); 419 err = __orinoco_down(dev);
448 if (err) 420 if (err)
449 printk(KERN_WARNING "%s: Error %d downing interface\n", 421 printk(KERN_WARNING "%s: Error %d downing interface\n",
450 dev->name, err); 422 dev->name, err);
451 423
452 netif_device_detach(dev); 424 netif_device_detach(dev);
453 priv->hw_unavailable++; 425 priv->hw_unavailable++;
454 426
455 spin_unlock_irqrestore(&priv->lock, flags); 427 spin_unlock_irqrestore(&priv->lock, flags);
456 }
457
458 pcmcia_release_configuration(link->handle);
459 } 428 }
460 429
461 return 0; 430 return 0;
462} 431}
463 432
464static int orinoco_cs_resume(struct pcmcia_device *p_dev) 433static int orinoco_cs_resume(struct pcmcia_device *link)
465{ 434{
466 dev_link_t *link = dev_to_instance(p_dev);
467 struct net_device *dev = link->priv; 435 struct net_device *dev = link->priv;
468 struct orinoco_private *priv = netdev_priv(dev); 436 struct orinoco_private *priv = netdev_priv(dev);
469 struct orinoco_pccard *card = priv->card; 437 struct orinoco_pccard *card = priv->card;
470 int err = 0; 438 int err = 0;
471 unsigned long flags; 439 unsigned long flags;
472 440
473 link->state &= ~DEV_SUSPEND; 441 if (! test_bit(0, &card->hard_reset_in_progress)) {
474 if (link->state & DEV_CONFIG) { 442 err = orinoco_reinit_firmware(dev);
475 /* FIXME: should we double check that this is 443 if (err) {
476 * the same card as we had before */ 444 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
477 pcmcia_request_configuration(link->handle, &link->conf); 445 dev->name, err);
478 446 return -EIO;
479 if (! test_bit(0, &card->hard_reset_in_progress)) { 447 }
480 err = orinoco_reinit_firmware(dev);
481 if (err) {
482 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
483 dev->name, err);
484 return -EIO;
485 }
486
487 spin_lock_irqsave(&priv->lock, flags);
488 448
489 netif_device_attach(dev); 449 spin_lock_irqsave(&priv->lock, flags);
490 priv->hw_unavailable--;
491 450
492 if (priv->open && ! priv->hw_unavailable) { 451 netif_device_attach(dev);
493 err = __orinoco_up(dev); 452 priv->hw_unavailable--;
494 if (err)
495 printk(KERN_ERR "%s: Error %d restarting card\n",
496 dev->name, err);
497 }
498 453
499 spin_unlock_irqrestore(&priv->lock, flags); 454 if (priv->open && ! priv->hw_unavailable) {
455 err = __orinoco_up(dev);
456 if (err)
457 printk(KERN_ERR "%s: Error %d restarting card\n",
458 dev->name, err);
500 } 459 }
460
461 spin_unlock_irqrestore(&priv->lock, flags);
501 } 462 }
502 463
503 return 0; 464 return 0;
@@ -604,7 +565,7 @@ static struct pcmcia_driver orinoco_driver = {
604 .drv = { 565 .drv = {
605 .name = DRIVER_NAME, 566 .name = DRIVER_NAME,
606 }, 567 },
607 .probe = orinoco_cs_attach, 568 .probe = orinoco_cs_probe,
608 .remove = orinoco_cs_detach, 569 .remove = orinoco_cs_detach,
609 .id_table = orinoco_cs_ids, 570 .id_table = orinoco_cs_ids,
610 .suspend = orinoco_cs_suspend, 571 .suspend = orinoco_cs_suspend,
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 7880d8c31aad..879eb427607c 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -90,8 +90,8 @@ module_param(pc_debug, int, 0);
90#define DEBUG(n, args...) 90#define DEBUG(n, args...)
91#endif 91#endif
92/** Prototypes based on PCMCIA skeleton driver *******************************/ 92/** Prototypes based on PCMCIA skeleton driver *******************************/
93static void ray_config(dev_link_t *link); 93static int ray_config(struct pcmcia_device *link);
94static void ray_release(dev_link_t *link); 94static void ray_release(struct pcmcia_device *link);
95static void ray_detach(struct pcmcia_device *p_dev); 95static void ray_detach(struct pcmcia_device *p_dev);
96 96
97/***** Prototypes indicated by device structure ******************************/ 97/***** Prototypes indicated by device structure ******************************/
@@ -190,20 +190,17 @@ static int bc;
190static char *phy_addr = NULL; 190static char *phy_addr = NULL;
191 191
192 192
193/* A linked list of "instances" of the ray device. Each actual 193/* A struct pcmcia_device structure has fields for most things that are needed
194 PCMCIA card corresponds to one device instance, and is described
195 by one dev_link_t structure (defined in ds.h).
196*/
197static dev_link_t *dev_list = NULL;
198
199/* A dev_link_t structure has fields for most things that are needed
200 to keep track of a socket, but there will usually be some device 194 to keep track of a socket, but there will usually be some device
201 specific information that also needs to be kept track of. The 195 specific information that also needs to be kept track of. The
202 'priv' pointer in a dev_link_t structure can be used to point to 196 'priv' pointer in a struct pcmcia_device structure can be used to point to
203 a device-specific private data structure, like this. 197 a device-specific private data structure, like this.
204*/ 198*/
205static unsigned int ray_mem_speed = 500; 199static unsigned int ray_mem_speed = 500;
206 200
201/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
202static struct pcmcia_device *this_device = NULL;
203
207MODULE_AUTHOR("Corey Thomas <corey@world.std.com>"); 204MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
208MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver"); 205MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
209MODULE_LICENSE("GPL"); 206MODULE_LICENSE("GPL");
@@ -306,56 +303,46 @@ static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.
306 configure the card at this point -- we wait until we receive a 303 configure the card at this point -- we wait until we receive a
307 card insertion event. 304 card insertion event.
308=============================================================================*/ 305=============================================================================*/
309static int ray_attach(struct pcmcia_device *p_dev) 306static int ray_probe(struct pcmcia_device *p_dev)
310{ 307{
311 dev_link_t *link;
312 ray_dev_t *local; 308 ray_dev_t *local;
313 struct net_device *dev; 309 struct net_device *dev;
314
315 DEBUG(1, "ray_attach()\n");
316 310
317 /* Initialize the dev_link_t structure */ 311 DEBUG(1, "ray_attach()\n");
318 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
319
320 if (!link)
321 return -ENOMEM;
322 312
323 /* Allocate space for private device-specific data */ 313 /* Allocate space for private device-specific data */
324 dev = alloc_etherdev(sizeof(ray_dev_t)); 314 dev = alloc_etherdev(sizeof(ray_dev_t));
325
326 if (!dev) 315 if (!dev)
327 goto fail_alloc_dev; 316 goto fail_alloc_dev;
328 317
329 local = dev->priv; 318 local = dev->priv;
330 319 local->finder = p_dev;
331 memset(link, 0, sizeof(struct dev_link_t));
332 320
333 /* The io structure describes IO port mapping. None used here */ 321 /* The io structure describes IO port mapping. None used here */
334 link->io.NumPorts1 = 0; 322 p_dev->io.NumPorts1 = 0;
335 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 323 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
336 link->io.IOAddrLines = 5; 324 p_dev->io.IOAddrLines = 5;
337 325
338 /* Interrupt setup. For PCMCIA, driver takes what's given */ 326 /* Interrupt setup. For PCMCIA, driver takes what's given */
339 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 327 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
340 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 328 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
341 link->irq.Handler = &ray_interrupt; 329 p_dev->irq.Handler = &ray_interrupt;
342 330
343 /* General socket configuration */ 331 /* General socket configuration */
344 link->conf.Attributes = CONF_ENABLE_IRQ; 332 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
345 link->conf.Vcc = 50; 333 p_dev->conf.IntType = INT_MEMORY_AND_IO;
346 link->conf.IntType = INT_MEMORY_AND_IO; 334 p_dev->conf.ConfigIndex = 1;
347 link->conf.ConfigIndex = 1; 335 p_dev->conf.Present = PRESENT_OPTION;
348 link->conf.Present = PRESENT_OPTION; 336
349 337 p_dev->priv = dev;
350 link->priv = dev; 338 p_dev->irq.Instance = dev;
351 link->irq.Instance = dev;
352 339
353 local->finder = link; 340 local->finder = p_dev;
354 local->card_status = CARD_INSERTED; 341 local->card_status = CARD_INSERTED;
355 local->authentication_state = UNAUTHENTICATED; 342 local->authentication_state = UNAUTHENTICATED;
356 local->num_multi = 0; 343 local->num_multi = 0;
357 DEBUG(2,"ray_attach link = %p, dev = %p, local = %p, intr = %p\n", 344 DEBUG(2,"ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
358 link,dev,local,&ray_interrupt); 345 p_dev,dev,local,&ray_interrupt);
359 346
360 /* Raylink entries in the device structure */ 347 /* Raylink entries in the device structure */
361 dev->hard_start_xmit = &ray_dev_start_xmit; 348 dev->hard_start_xmit = &ray_dev_start_xmit;
@@ -379,16 +366,10 @@ static int ray_attach(struct pcmcia_device *p_dev)
379 366
380 init_timer(&local->timer); 367 init_timer(&local->timer);
381 368
382 link->handle = p_dev; 369 this_device = p_dev;
383 p_dev->instance = link; 370 return ray_config(p_dev);
384
385 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
386 ray_config(link);
387
388 return 0;
389 371
390fail_alloc_dev: 372fail_alloc_dev:
391 kfree(link);
392 return -ENOMEM; 373 return -ENOMEM;
393} /* ray_attach */ 374} /* ray_attach */
394/*============================================================================= 375/*=============================================================================
@@ -397,37 +378,25 @@ fail_alloc_dev:
397 structures are freed. Otherwise, the structures will be freed 378 structures are freed. Otherwise, the structures will be freed
398 when the device is released. 379 when the device is released.
399=============================================================================*/ 380=============================================================================*/
400static void ray_detach(struct pcmcia_device *p_dev) 381static void ray_detach(struct pcmcia_device *link)
401{ 382{
402 dev_link_t *link = dev_to_instance(p_dev);
403 dev_link_t **linkp;
404 struct net_device *dev; 383 struct net_device *dev;
405 ray_dev_t *local; 384 ray_dev_t *local;
406 385
407 DEBUG(1, "ray_detach(0x%p)\n", link); 386 DEBUG(1, "ray_detach(0x%p)\n", link);
408
409 /* Locate device structure */
410 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
411 if (*linkp == link) break;
412 if (*linkp == NULL)
413 return;
414 387
388 this_device = NULL;
415 dev = link->priv; 389 dev = link->priv;
416 390
417 if (link->state & DEV_CONFIG) { 391 ray_release(link);
418 ray_release(link);
419 392
420 local = (ray_dev_t *)dev->priv; 393 local = (ray_dev_t *)dev->priv;
421 del_timer(&local->timer); 394 del_timer(&local->timer);
422 }
423 395
424 /* Unlink device structure, free pieces */
425 *linkp = link->next;
426 if (link->priv) { 396 if (link->priv) {
427 if (link->dev) unregister_netdev(dev); 397 if (link->dev_node) unregister_netdev(dev);
428 free_netdev(dev); 398 free_netdev(dev);
429 } 399 }
430 kfree(link);
431 DEBUG(2,"ray_cs ray_detach ending\n"); 400 DEBUG(2,"ray_cs ray_detach ending\n");
432} /* ray_detach */ 401} /* ray_detach */
433/*============================================================================= 402/*=============================================================================
@@ -438,9 +407,8 @@ static void ray_detach(struct pcmcia_device *p_dev)
438#define CS_CHECK(fn, ret) \ 407#define CS_CHECK(fn, ret) \
439do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 408do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
440#define MAX_TUPLE_SIZE 128 409#define MAX_TUPLE_SIZE 128
441static void ray_config(dev_link_t *link) 410static int ray_config(struct pcmcia_device *link)
442{ 411{
443 client_handle_t handle = link->handle;
444 tuple_t tuple; 412 tuple_t tuple;
445 cisparse_t parse; 413 cisparse_t parse;
446 int last_fn = 0, last_ret = 0; 414 int last_fn = 0, last_ret = 0;
@@ -455,48 +423,45 @@ static void ray_config(dev_link_t *link)
455 423
456 /* This reads the card's CONFIG tuple to find its configuration regs */ 424 /* This reads the card's CONFIG tuple to find its configuration regs */
457 tuple.DesiredTuple = CISTPL_CONFIG; 425 tuple.DesiredTuple = CISTPL_CONFIG;
458 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 426 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
459 tuple.TupleData = buf; 427 tuple.TupleData = buf;
460 tuple.TupleDataMax = MAX_TUPLE_SIZE; 428 tuple.TupleDataMax = MAX_TUPLE_SIZE;
461 tuple.TupleOffset = 0; 429 tuple.TupleOffset = 0;
462 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 430 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
463 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 431 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
464 link->conf.ConfigBase = parse.config.base; 432 link->conf.ConfigBase = parse.config.base;
465 link->conf.Present = parse.config.rmask[0]; 433 link->conf.Present = parse.config.rmask[0];
466 434
467 /* Determine card type and firmware version */ 435 /* Determine card type and firmware version */
468 buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0; 436 buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0;
469 tuple.DesiredTuple = CISTPL_VERS_1; 437 tuple.DesiredTuple = CISTPL_VERS_1;
470 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 438 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
471 tuple.TupleData = buf; 439 tuple.TupleData = buf;
472 tuple.TupleDataMax = MAX_TUPLE_SIZE; 440 tuple.TupleDataMax = MAX_TUPLE_SIZE;
473 tuple.TupleOffset = 2; 441 tuple.TupleOffset = 2;
474 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 442 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
475 443
476 for (i=0; i<tuple.TupleDataLen - 4; i++) 444 for (i=0; i<tuple.TupleDataLen - 4; i++)
477 if (buf[i] == 0) buf[i] = ' '; 445 if (buf[i] == 0) buf[i] = ' ';
478 printk(KERN_INFO "ray_cs Detected: %s\n",buf); 446 printk(KERN_INFO "ray_cs Detected: %s\n",buf);
479 447
480 /* Configure card */
481 link->state |= DEV_CONFIG;
482
483 /* Now allocate an interrupt line. Note that this does not 448 /* Now allocate an interrupt line. Note that this does not
484 actually assign a handler to the interrupt. 449 actually assign a handler to the interrupt.
485 */ 450 */
486 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 451 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
487 dev->irq = link->irq.AssignedIRQ; 452 dev->irq = link->irq.AssignedIRQ;
488 453
489 /* This actually configures the PCMCIA socket -- setting up 454 /* This actually configures the PCMCIA socket -- setting up
490 the I/O windows and the interrupt mapping. 455 the I/O windows and the interrupt mapping.
491 */ 456 */
492 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 457 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
493 458
494/*** Set up 32k window for shared memory (transmit and control) ************/ 459/*** Set up 32k window for shared memory (transmit and control) ************/
495 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; 460 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
496 req.Base = 0; 461 req.Base = 0;
497 req.Size = 0x8000; 462 req.Size = 0x8000;
498 req.AccessSpeed = ray_mem_speed; 463 req.AccessSpeed = ray_mem_speed;
499 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 464 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
500 mem.CardOffset = 0x0000; mem.Page = 0; 465 mem.CardOffset = 0x0000; mem.Page = 0;
501 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 466 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
502 local->sram = ioremap(req.Base,req.Size); 467 local->sram = ioremap(req.Base,req.Size);
@@ -506,7 +471,7 @@ static void ray_config(dev_link_t *link)
506 req.Base = 0; 471 req.Base = 0;
507 req.Size = 0x4000; 472 req.Size = 0x4000;
508 req.AccessSpeed = ray_mem_speed; 473 req.AccessSpeed = ray_mem_speed;
509 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &local->rmem_handle)); 474 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->rmem_handle));
510 mem.CardOffset = 0x8000; mem.Page = 0; 475 mem.CardOffset = 0x8000; mem.Page = 0;
511 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem)); 476 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem));
512 local->rmem = ioremap(req.Base,req.Size); 477 local->rmem = ioremap(req.Base,req.Size);
@@ -516,7 +481,7 @@ static void ray_config(dev_link_t *link)
516 req.Base = 0; 481 req.Base = 0;
517 req.Size = 0x1000; 482 req.Size = 0x1000;
518 req.AccessSpeed = ray_mem_speed; 483 req.AccessSpeed = ray_mem_speed;
519 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &local->amem_handle)); 484 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->amem_handle));
520 mem.CardOffset = 0x0000; mem.Page = 0; 485 mem.CardOffset = 0x0000; mem.Page = 0;
521 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem)); 486 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem));
522 local->amem = ioremap(req.Base,req.Size); 487 local->amem = ioremap(req.Base,req.Size);
@@ -526,32 +491,32 @@ static void ray_config(dev_link_t *link)
526 DEBUG(3,"ray_config amem=%p\n",local->amem); 491 DEBUG(3,"ray_config amem=%p\n",local->amem);
527 if (ray_init(dev) < 0) { 492 if (ray_init(dev) < 0) {
528 ray_release(link); 493 ray_release(link);
529 return; 494 return -ENODEV;
530 } 495 }
531 496
532 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 497 SET_NETDEV_DEV(dev, &handle_to_dev(link));
533 i = register_netdev(dev); 498 i = register_netdev(dev);
534 if (i != 0) { 499 if (i != 0) {
535 printk("ray_config register_netdev() failed\n"); 500 printk("ray_config register_netdev() failed\n");
536 ray_release(link); 501 ray_release(link);
537 return; 502 return i;
538 } 503 }
539 504
540 strcpy(local->node.dev_name, dev->name); 505 strcpy(local->node.dev_name, dev->name);
541 link->dev = &local->node; 506 link->dev_node = &local->node;
542 507
543 link->state &= ~DEV_CONFIG_PENDING;
544 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ", 508 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ",
545 dev->name, dev->irq); 509 dev->name, dev->irq);
546 for (i = 0; i < 6; i++) 510 for (i = 0; i < 6; i++)
547 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 511 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
548 512
549 return; 513 return 0;
550 514
551cs_failed: 515cs_failed:
552 cs_error(link->handle, last_fn, last_ret); 516 cs_error(link, last_fn, last_ret);
553 517
554 ray_release(link); 518 ray_release(link);
519 return -ENODEV;
555} /* ray_config */ 520} /* ray_config */
556 521
557static inline struct ccs __iomem *ccs_base(ray_dev_t *dev) 522static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
@@ -578,9 +543,9 @@ static int ray_init(struct net_device *dev)
578 UCHAR *p; 543 UCHAR *p;
579 struct ccs __iomem *pccs; 544 struct ccs __iomem *pccs;
580 ray_dev_t *local = (ray_dev_t *)dev->priv; 545 ray_dev_t *local = (ray_dev_t *)dev->priv;
581 dev_link_t *link = local->finder; 546 struct pcmcia_device *link = local->finder;
582 DEBUG(1, "ray_init(0x%p)\n", dev); 547 DEBUG(1, "ray_init(0x%p)\n", dev);
583 if (!(link->state & DEV_PRESENT)) { 548 if (!(pcmcia_dev_present(link))) {
584 DEBUG(0,"ray_init - device not present\n"); 549 DEBUG(0,"ray_init - device not present\n");
585 return -1; 550 return -1;
586 } 551 }
@@ -640,10 +605,10 @@ static int dl_startup_params(struct net_device *dev)
640 int ccsindex; 605 int ccsindex;
641 ray_dev_t *local = (ray_dev_t *)dev->priv; 606 ray_dev_t *local = (ray_dev_t *)dev->priv;
642 struct ccs __iomem *pccs; 607 struct ccs __iomem *pccs;
643 dev_link_t *link = local->finder; 608 struct pcmcia_device *link = local->finder;
644 609
645 DEBUG(1,"dl_startup_params entered\n"); 610 DEBUG(1,"dl_startup_params entered\n");
646 if (!(link->state & DEV_PRESENT)) { 611 if (!(pcmcia_dev_present(link))) {
647 DEBUG(2,"ray_cs dl_startup_params - device not present\n"); 612 DEBUG(2,"ray_cs dl_startup_params - device not present\n");
648 return -1; 613 return -1;
649 } 614 }
@@ -747,9 +712,9 @@ static void verify_dl_startup(u_long data)
747 ray_dev_t *local = (ray_dev_t *)data; 712 ray_dev_t *local = (ray_dev_t *)data;
748 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs; 713 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
749 UCHAR status; 714 UCHAR status;
750 dev_link_t *link = local->finder; 715 struct pcmcia_device *link = local->finder;
751 716
752 if (!(link->state & DEV_PRESENT)) { 717 if (!(pcmcia_dev_present(link))) {
753 DEBUG(2,"ray_cs verify_dl_startup - device not present\n"); 718 DEBUG(2,"ray_cs verify_dl_startup - device not present\n");
754 return; 719 return;
755 } 720 }
@@ -787,8 +752,8 @@ static void start_net(u_long data)
787 ray_dev_t *local = (ray_dev_t *)data; 752 ray_dev_t *local = (ray_dev_t *)data;
788 struct ccs __iomem *pccs; 753 struct ccs __iomem *pccs;
789 int ccsindex; 754 int ccsindex;
790 dev_link_t *link = local->finder; 755 struct pcmcia_device *link = local->finder;
791 if (!(link->state & DEV_PRESENT)) { 756 if (!(pcmcia_dev_present(link))) {
792 DEBUG(2,"ray_cs start_net - device not present\n"); 757 DEBUG(2,"ray_cs start_net - device not present\n");
793 return; 758 return;
794 } 759 }
@@ -814,9 +779,9 @@ static void join_net(u_long data)
814 779
815 struct ccs __iomem *pccs; 780 struct ccs __iomem *pccs;
816 int ccsindex; 781 int ccsindex;
817 dev_link_t *link = local->finder; 782 struct pcmcia_device *link = local->finder;
818 783
819 if (!(link->state & DEV_PRESENT)) { 784 if (!(pcmcia_dev_present(link))) {
820 DEBUG(2,"ray_cs join_net - device not present\n"); 785 DEBUG(2,"ray_cs join_net - device not present\n");
821 return; 786 return;
822 } 787 }
@@ -840,7 +805,7 @@ static void join_net(u_long data)
840 device, and release the PCMCIA configuration. If the device is 805 device, and release the PCMCIA configuration. If the device is
841 still open, this will be postponed until it is closed. 806 still open, this will be postponed until it is closed.
842=============================================================================*/ 807=============================================================================*/
843static void ray_release(dev_link_t *link) 808static void ray_release(struct pcmcia_device *link)
844{ 809{
845 struct net_device *dev = link->priv; 810 struct net_device *dev = link->priv;
846 ray_dev_t *local = dev->priv; 811 ray_dev_t *local = dev->priv;
@@ -849,56 +814,38 @@ static void ray_release(dev_link_t *link)
849 DEBUG(1, "ray_release(0x%p)\n", link); 814 DEBUG(1, "ray_release(0x%p)\n", link);
850 815
851 del_timer(&local->timer); 816 del_timer(&local->timer);
852 link->state &= ~DEV_CONFIG;
853 817
854 iounmap(local->sram); 818 iounmap(local->sram);
855 iounmap(local->rmem); 819 iounmap(local->rmem);
856 iounmap(local->amem); 820 iounmap(local->amem);
857 /* Do bother checking to see if these succeed or not */ 821 /* Do bother checking to see if these succeed or not */
858 i = pcmcia_release_window(link->win);
859 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(link->win) ret = %x\n",i);
860 i = pcmcia_release_window(local->amem_handle); 822 i = pcmcia_release_window(local->amem_handle);
861 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i); 823 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
862 i = pcmcia_release_window(local->rmem_handle); 824 i = pcmcia_release_window(local->rmem_handle);
863 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i); 825 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
864 i = pcmcia_release_configuration(link->handle); 826 pcmcia_disable_device(link);
865 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseConfiguration ret = %x\n",i);
866 i = pcmcia_release_irq(link->handle, &link->irq);
867 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseIRQ ret = %x\n",i);
868 827
869 DEBUG(2,"ray_release ending\n"); 828 DEBUG(2,"ray_release ending\n");
870} 829}
871 830
872static int ray_suspend(struct pcmcia_device *p_dev) 831static int ray_suspend(struct pcmcia_device *link)
873{ 832{
874 dev_link_t *link = dev_to_instance(p_dev);
875 struct net_device *dev = link->priv; 833 struct net_device *dev = link->priv;
876 834
877 link->state |= DEV_SUSPEND; 835 if (link->open)
878 if (link->state & DEV_CONFIG) { 836 netif_device_detach(dev);
879 if (link->open)
880 netif_device_detach(dev);
881
882 pcmcia_release_configuration(link->handle);
883 }
884
885 837
886 return 0; 838 return 0;
887} 839}
888 840
889static int ray_resume(struct pcmcia_device *p_dev) 841static int ray_resume(struct pcmcia_device *link)
890{ 842{
891 dev_link_t *link = dev_to_instance(p_dev);
892 struct net_device *dev = link->priv; 843 struct net_device *dev = link->priv;
893 844
894 link->state &= ~DEV_SUSPEND; 845 if (link->open) {
895 if (link->state & DEV_CONFIG) { 846 ray_reset(dev);
896 pcmcia_request_configuration(link->handle, &link->conf); 847 netif_device_attach(dev);
897 if (link->open) { 848 }
898 ray_reset(dev);
899 netif_device_attach(dev);
900 }
901 }
902 849
903 return 0; 850 return 0;
904} 851}
@@ -910,10 +857,10 @@ int ray_dev_init(struct net_device *dev)
910 int i; 857 int i;
911#endif /* RAY_IMMEDIATE_INIT */ 858#endif /* RAY_IMMEDIATE_INIT */
912 ray_dev_t *local = dev->priv; 859 ray_dev_t *local = dev->priv;
913 dev_link_t *link = local->finder; 860 struct pcmcia_device *link = local->finder;
914 861
915 DEBUG(1,"ray_dev_init(dev=%p)\n",dev); 862 DEBUG(1,"ray_dev_init(dev=%p)\n",dev);
916 if (!(link->state & DEV_PRESENT)) { 863 if (!(pcmcia_dev_present(link))) {
917 DEBUG(2,"ray_dev_init - device not present\n"); 864 DEBUG(2,"ray_dev_init - device not present\n");
918 return -1; 865 return -1;
919 } 866 }
@@ -944,10 +891,10 @@ int ray_dev_init(struct net_device *dev)
944static int ray_dev_config(struct net_device *dev, struct ifmap *map) 891static int ray_dev_config(struct net_device *dev, struct ifmap *map)
945{ 892{
946 ray_dev_t *local = dev->priv; 893 ray_dev_t *local = dev->priv;
947 dev_link_t *link = local->finder; 894 struct pcmcia_device *link = local->finder;
948 /* Dummy routine to satisfy device structure */ 895 /* Dummy routine to satisfy device structure */
949 DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map); 896 DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map);
950 if (!(link->state & DEV_PRESENT)) { 897 if (!(pcmcia_dev_present(link))) {
951 DEBUG(2,"ray_dev_config - device not present\n"); 898 DEBUG(2,"ray_dev_config - device not present\n");
952 return -1; 899 return -1;
953 } 900 }
@@ -958,10 +905,10 @@ static int ray_dev_config(struct net_device *dev, struct ifmap *map)
958static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev) 905static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
959{ 906{
960 ray_dev_t *local = dev->priv; 907 ray_dev_t *local = dev->priv;
961 dev_link_t *link = local->finder; 908 struct pcmcia_device *link = local->finder;
962 short length = skb->len; 909 short length = skb->len;
963 910
964 if (!(link->state & DEV_PRESENT)) { 911 if (!(pcmcia_dev_present(link))) {
965 DEBUG(2,"ray_dev_start_xmit - device not present\n"); 912 DEBUG(2,"ray_dev_start_xmit - device not present\n");
966 return -1; 913 return -1;
967 } 914 }
@@ -1570,7 +1517,7 @@ static int ray_commit(struct net_device *dev,
1570static iw_stats * ray_get_wireless_stats(struct net_device * dev) 1517static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1571{ 1518{
1572 ray_dev_t * local = (ray_dev_t *) dev->priv; 1519 ray_dev_t * local = (ray_dev_t *) dev->priv;
1573 dev_link_t *link = local->finder; 1520 struct pcmcia_device *link = local->finder;
1574 struct status __iomem *p = local->sram + STATUS_BASE; 1521 struct status __iomem *p = local->sram + STATUS_BASE;
1575 1522
1576 if(local == (ray_dev_t *) NULL) 1523 if(local == (ray_dev_t *) NULL)
@@ -1588,7 +1535,7 @@ static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1588 } 1535 }
1589#endif /* WIRELESS_SPY */ 1536#endif /* WIRELESS_SPY */
1590 1537
1591 if((link->state & DEV_PRESENT)) { 1538 if(pcmcia_dev_present(link)) {
1592 local->wstats.qual.noise = readb(&p->rxnoise); 1539 local->wstats.qual.noise = readb(&p->rxnoise);
1593 local->wstats.qual.updated |= 4; 1540 local->wstats.qual.updated |= 4;
1594 } 1541 }
@@ -1657,18 +1604,14 @@ static const struct iw_handler_def ray_handler_def =
1657/*===========================================================================*/ 1604/*===========================================================================*/
1658static int ray_open(struct net_device *dev) 1605static int ray_open(struct net_device *dev)
1659{ 1606{
1660 dev_link_t *link;
1661 ray_dev_t *local = (ray_dev_t *)dev->priv; 1607 ray_dev_t *local = (ray_dev_t *)dev->priv;
1608 struct pcmcia_device *link;
1609 link = local->finder;
1662 1610
1663 DEBUG(1, "ray_open('%s')\n", dev->name); 1611 DEBUG(1, "ray_open('%s')\n", dev->name);
1664 1612
1665 for (link = dev_list; link; link = link->next) 1613 if (link->open == 0)
1666 if (link->priv == dev) break; 1614 local->num_multi = 0;
1667 if (!DEV_OK(link)) {
1668 return -ENODEV;
1669 }
1670
1671 if (link->open == 0) local->num_multi = 0;
1672 link->open++; 1615 link->open++;
1673 1616
1674 /* If the card is not started, time to start it ! - Jean II */ 1617 /* If the card is not started, time to start it ! - Jean II */
@@ -1695,15 +1638,12 @@ static int ray_open(struct net_device *dev)
1695/*===========================================================================*/ 1638/*===========================================================================*/
1696static int ray_dev_close(struct net_device *dev) 1639static int ray_dev_close(struct net_device *dev)
1697{ 1640{
1698 dev_link_t *link; 1641 ray_dev_t *local = (ray_dev_t *)dev->priv;
1642 struct pcmcia_device *link;
1643 link = local->finder;
1699 1644
1700 DEBUG(1, "ray_dev_close('%s')\n", dev->name); 1645 DEBUG(1, "ray_dev_close('%s')\n", dev->name);
1701 1646
1702 for (link = dev_list; link; link = link->next)
1703 if (link->priv == dev) break;
1704 if (link == NULL)
1705 return -ENODEV;
1706
1707 link->open--; 1647 link->open--;
1708 netif_stop_queue(dev); 1648 netif_stop_queue(dev);
1709 1649
@@ -1725,9 +1665,9 @@ static void ray_reset(struct net_device *dev) {
1725static int interrupt_ecf(ray_dev_t *local, int ccs) 1665static int interrupt_ecf(ray_dev_t *local, int ccs)
1726{ 1666{
1727 int i = 50; 1667 int i = 50;
1728 dev_link_t *link = local->finder; 1668 struct pcmcia_device *link = local->finder;
1729 1669
1730 if (!(link->state & DEV_PRESENT)) { 1670 if (!(pcmcia_dev_present(link))) {
1731 DEBUG(2,"ray_cs interrupt_ecf - device not present\n"); 1671 DEBUG(2,"ray_cs interrupt_ecf - device not present\n");
1732 return -1; 1672 return -1;
1733 } 1673 }
@@ -1752,9 +1692,9 @@ static int get_free_tx_ccs(ray_dev_t *local)
1752{ 1692{
1753 int i; 1693 int i;
1754 struct ccs __iomem *pccs = ccs_base(local); 1694 struct ccs __iomem *pccs = ccs_base(local);
1755 dev_link_t *link = local->finder; 1695 struct pcmcia_device *link = local->finder;
1756 1696
1757 if (!(link->state & DEV_PRESENT)) { 1697 if (!(pcmcia_dev_present(link))) {
1758 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n"); 1698 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n");
1759 return ECARDGONE; 1699 return ECARDGONE;
1760 } 1700 }
@@ -1783,9 +1723,9 @@ static int get_free_ccs(ray_dev_t *local)
1783{ 1723{
1784 int i; 1724 int i;
1785 struct ccs __iomem *pccs = ccs_base(local); 1725 struct ccs __iomem *pccs = ccs_base(local);
1786 dev_link_t *link = local->finder; 1726 struct pcmcia_device *link = local->finder;
1787 1727
1788 if (!(link->state & DEV_PRESENT)) { 1728 if (!(pcmcia_dev_present(link))) {
1789 DEBUG(2,"ray_cs get_free_ccs - device not present\n"); 1729 DEBUG(2,"ray_cs get_free_ccs - device not present\n");
1790 return ECARDGONE; 1730 return ECARDGONE;
1791 } 1731 }
@@ -1858,9 +1798,9 @@ static int parse_addr(char *in_str, UCHAR *out)
1858static struct net_device_stats *ray_get_stats(struct net_device *dev) 1798static struct net_device_stats *ray_get_stats(struct net_device *dev)
1859{ 1799{
1860 ray_dev_t *local = (ray_dev_t *)dev->priv; 1800 ray_dev_t *local = (ray_dev_t *)dev->priv;
1861 dev_link_t *link = local->finder; 1801 struct pcmcia_device *link = local->finder;
1862 struct status __iomem *p = local->sram + STATUS_BASE; 1802 struct status __iomem *p = local->sram + STATUS_BASE;
1863 if (!(link->state & DEV_PRESENT)) { 1803 if (!(pcmcia_dev_present(link))) {
1864 DEBUG(2,"ray_cs net_device_stats - device not present\n"); 1804 DEBUG(2,"ray_cs net_device_stats - device not present\n");
1865 return &local->stats; 1805 return &local->stats;
1866 } 1806 }
@@ -1888,12 +1828,12 @@ static struct net_device_stats *ray_get_stats(struct net_device *dev)
1888static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len) 1828static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len)
1889{ 1829{
1890 ray_dev_t *local = (ray_dev_t *)dev->priv; 1830 ray_dev_t *local = (ray_dev_t *)dev->priv;
1891 dev_link_t *link = local->finder; 1831 struct pcmcia_device *link = local->finder;
1892 int ccsindex; 1832 int ccsindex;
1893 int i; 1833 int i;
1894 struct ccs __iomem *pccs; 1834 struct ccs __iomem *pccs;
1895 1835
1896 if (!(link->state & DEV_PRESENT)) { 1836 if (!(pcmcia_dev_present(link))) {
1897 DEBUG(2,"ray_update_parm - device not present\n"); 1837 DEBUG(2,"ray_update_parm - device not present\n");
1898 return; 1838 return;
1899 } 1839 }
@@ -1925,10 +1865,10 @@ static void ray_update_multi_list(struct net_device *dev, int all)
1925 struct ccs __iomem *pccs; 1865 struct ccs __iomem *pccs;
1926 int i = 0; 1866 int i = 0;
1927 ray_dev_t *local = (ray_dev_t *)dev->priv; 1867 ray_dev_t *local = (ray_dev_t *)dev->priv;
1928 dev_link_t *link = local->finder; 1868 struct pcmcia_device *link = local->finder;
1929 void __iomem *p = local->sram + HOST_TO_ECF_BASE; 1869 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
1930 1870
1931 if (!(link->state & DEV_PRESENT)) { 1871 if (!(pcmcia_dev_present(link))) {
1932 DEBUG(2,"ray_update_multi_list - device not present\n"); 1872 DEBUG(2,"ray_update_multi_list - device not present\n");
1933 return; 1873 return;
1934 } 1874 }
@@ -2005,7 +1945,7 @@ static void set_multicast_list(struct net_device *dev)
2005static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs) 1945static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
2006{ 1946{
2007 struct net_device *dev = (struct net_device *)dev_id; 1947 struct net_device *dev = (struct net_device *)dev_id;
2008 dev_link_t *link; 1948 struct pcmcia_device *link;
2009 ray_dev_t *local; 1949 ray_dev_t *local;
2010 struct ccs __iomem *pccs; 1950 struct ccs __iomem *pccs;
2011 struct rcs __iomem *prcs; 1951 struct rcs __iomem *prcs;
@@ -2020,8 +1960,8 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
2020 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev); 1960 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev);
2021 1961
2022 local = (ray_dev_t *)dev->priv; 1962 local = (ray_dev_t *)dev->priv;
2023 link = (dev_link_t *)local->finder; 1963 link = (struct pcmcia_device *)local->finder;
2024 if ( ! (link->state & DEV_PRESENT) || link->state & DEV_SUSPEND ) { 1964 if (!pcmcia_dev_present(link)) {
2025 DEBUG(2,"ray_cs interrupt from device not present or suspended.\n"); 1965 DEBUG(2,"ray_cs interrupt from device not present or suspended.\n");
2026 return IRQ_NONE; 1966 return IRQ_NONE;
2027 } 1967 }
@@ -2540,9 +2480,9 @@ static void release_frag_chain(ray_dev_t *local, struct rcs __iomem * prcs)
2540/*===========================================================================*/ 2480/*===========================================================================*/
2541static void authenticate(ray_dev_t *local) 2481static void authenticate(ray_dev_t *local)
2542{ 2482{
2543 dev_link_t *link = local->finder; 2483 struct pcmcia_device *link = local->finder;
2544 DEBUG(0,"ray_cs Starting authentication.\n"); 2484 DEBUG(0,"ray_cs Starting authentication.\n");
2545 if (!(link->state & DEV_PRESENT)) { 2485 if (!(pcmcia_dev_present(link))) {
2546 DEBUG(2,"ray_cs authenticate - device not present\n"); 2486 DEBUG(2,"ray_cs authenticate - device not present\n");
2547 return; 2487 return;
2548 } 2488 }
@@ -2606,10 +2546,10 @@ static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2606static void associate(ray_dev_t *local) 2546static void associate(ray_dev_t *local)
2607{ 2547{
2608 struct ccs __iomem *pccs; 2548 struct ccs __iomem *pccs;
2609 dev_link_t *link = local->finder; 2549 struct pcmcia_device *link = local->finder;
2610 struct net_device *dev = link->priv; 2550 struct net_device *dev = link->priv;
2611 int ccsindex; 2551 int ccsindex;
2612 if (!(link->state & DEV_PRESENT)) { 2552 if (!(pcmcia_dev_present(link))) {
2613 DEBUG(2,"ray_cs associate - device not present\n"); 2553 DEBUG(2,"ray_cs associate - device not present\n");
2614 return; 2554 return;
2615 } 2555 }
@@ -2689,14 +2629,14 @@ static int ray_cs_proc_read(char *buf, char **start, off_t offset, int len)
2689 * eg ifconfig 2629 * eg ifconfig
2690 */ 2630 */
2691 int i; 2631 int i;
2692 dev_link_t *link; 2632 struct pcmcia_device *link;
2693 struct net_device *dev; 2633 struct net_device *dev;
2694 ray_dev_t *local; 2634 ray_dev_t *local;
2695 UCHAR *p; 2635 UCHAR *p;
2696 struct freq_hop_element *pfh; 2636 struct freq_hop_element *pfh;
2697 UCHAR c[33]; 2637 UCHAR c[33];
2698 2638
2699 link = dev_list; 2639 link = this_device;
2700 if (!link) 2640 if (!link)
2701 return 0; 2641 return 0;
2702 dev = (struct net_device *)link->priv; 2642 dev = (struct net_device *)link->priv;
@@ -2898,7 +2838,7 @@ static struct pcmcia_driver ray_driver = {
2898 .drv = { 2838 .drv = {
2899 .name = "ray_cs", 2839 .name = "ray_cs",
2900 }, 2840 },
2901 .probe = ray_attach, 2841 .probe = ray_probe,
2902 .remove = ray_detach, 2842 .remove = ray_detach,
2903 .id_table = ray_ids, 2843 .id_table = ray_ids,
2904 .suspend = ray_suspend, 2844 .suspend = ray_suspend,
@@ -2940,7 +2880,6 @@ static void __exit exit_ray_cs(void)
2940#endif 2880#endif
2941 2881
2942 pcmcia_unregister_driver(&ray_driver); 2882 pcmcia_unregister_driver(&ray_driver);
2943 BUG_ON(dev_list != NULL);
2944} /* exit_ray_cs */ 2883} /* exit_ray_cs */
2945 2884
2946module_init(init_ray_cs); 2885module_init(init_ray_cs);
diff --git a/drivers/net/wireless/ray_cs.h b/drivers/net/wireless/ray_cs.h
index 42660fe64bfd..bd73ebf03340 100644
--- a/drivers/net/wireless/ray_cs.h
+++ b/drivers/net/wireless/ray_cs.h
@@ -31,7 +31,7 @@ typedef struct ray_dev_t {
31 void __iomem *sram; /* pointer to beginning of shared RAM */ 31 void __iomem *sram; /* pointer to beginning of shared RAM */
32 void __iomem *amem; /* pointer to attribute mem window */ 32 void __iomem *amem; /* pointer to attribute mem window */
33 void __iomem *rmem; /* pointer to receive buffer window */ 33 void __iomem *rmem; /* pointer to receive buffer window */
34 dev_link_t *finder; /* pointer back to dev_link_t for card */ 34 struct pcmcia_device *finder; /* pointer back to struct pcmcia_device for card */
35 struct timer_list timer; 35 struct timer_list timer;
36 long tx_ccs_lock; 36 long tx_ccs_lock;
37 long ccs_lock; 37 long ccs_lock;
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
index 5fa6fbe35bb9..f7b77ce54d7b 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -63,7 +63,7 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket
63/* PCMCIA specific device information (goes in the card field of 63/* PCMCIA specific device information (goes in the card field of
64 * struct orinoco_private */ 64 * struct orinoco_private */
65struct orinoco_pccard { 65struct orinoco_pccard {
66 dev_link_t link; 66 struct pcmcia_device *p_dev;
67 dev_node_t node; 67 dev_node_t node;
68}; 68};
69 69
@@ -71,8 +71,8 @@ struct orinoco_pccard {
71/* Function prototypes */ 71/* Function prototypes */
72/********************************************************************/ 72/********************************************************************/
73 73
74static void spectrum_cs_config(dev_link_t *link); 74static int spectrum_cs_config(struct pcmcia_device *link);
75static void spectrum_cs_release(dev_link_t *link); 75static void spectrum_cs_release(struct pcmcia_device *link);
76 76
77/********************************************************************/ 77/********************************************************************/
78/* Firmware downloader */ 78/* Firmware downloader */
@@ -238,14 +238,14 @@ spectrum_aux_open(hermes_t *hw)
238 * If IDLE is 1, stop the firmware, so that it can be safely rewritten. 238 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
239 */ 239 */
240static int 240static int
241spectrum_reset(dev_link_t *link, int idle) 241spectrum_reset(struct pcmcia_device *link, int idle)
242{ 242{
243 int last_ret, last_fn; 243 int last_ret, last_fn;
244 conf_reg_t reg; 244 conf_reg_t reg;
245 u_int save_cor; 245 u_int save_cor;
246 246
247 /* Doing it if hardware is gone is guaranteed crash */ 247 /* Doing it if hardware is gone is guaranteed crash */
248 if (!(link->state & DEV_CONFIG)) 248 if (pcmcia_dev_present(link))
249 return -ENODEV; 249 return -ENODEV;
250 250
251 /* Save original COR value */ 251 /* Save original COR value */
@@ -253,7 +253,7 @@ spectrum_reset(dev_link_t *link, int idle)
253 reg.Action = CS_READ; 253 reg.Action = CS_READ;
254 reg.Offset = CISREG_COR; 254 reg.Offset = CISREG_COR;
255 CS_CHECK(AccessConfigurationRegister, 255 CS_CHECK(AccessConfigurationRegister,
256 pcmcia_access_configuration_register(link->handle, &reg)); 256 pcmcia_access_configuration_register(link, &reg));
257 save_cor = reg.Value; 257 save_cor = reg.Value;
258 258
259 /* Soft-Reset card */ 259 /* Soft-Reset card */
@@ -261,14 +261,14 @@ spectrum_reset(dev_link_t *link, int idle)
261 reg.Offset = CISREG_COR; 261 reg.Offset = CISREG_COR;
262 reg.Value = (save_cor | COR_SOFT_RESET); 262 reg.Value = (save_cor | COR_SOFT_RESET);
263 CS_CHECK(AccessConfigurationRegister, 263 CS_CHECK(AccessConfigurationRegister,
264 pcmcia_access_configuration_register(link->handle, &reg)); 264 pcmcia_access_configuration_register(link, &reg));
265 udelay(1000); 265 udelay(1000);
266 266
267 /* Read CCSR */ 267 /* Read CCSR */
268 reg.Action = CS_READ; 268 reg.Action = CS_READ;
269 reg.Offset = CISREG_CCSR; 269 reg.Offset = CISREG_CCSR;
270 CS_CHECK(AccessConfigurationRegister, 270 CS_CHECK(AccessConfigurationRegister,
271 pcmcia_access_configuration_register(link->handle, &reg)); 271 pcmcia_access_configuration_register(link, &reg));
272 272
273 /* 273 /*
274 * Start or stop the firmware. Memory width bit should be 274 * Start or stop the firmware. Memory width bit should be
@@ -278,7 +278,7 @@ spectrum_reset(dev_link_t *link, int idle)
278 reg.Offset = CISREG_CCSR; 278 reg.Offset = CISREG_CCSR;
279 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16); 279 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);
280 CS_CHECK(AccessConfigurationRegister, 280 CS_CHECK(AccessConfigurationRegister,
281 pcmcia_access_configuration_register(link->handle, &reg)); 281 pcmcia_access_configuration_register(link, &reg));
282 udelay(1000); 282 udelay(1000);
283 283
284 /* Restore original COR configuration index */ 284 /* Restore original COR configuration index */
@@ -286,12 +286,12 @@ spectrum_reset(dev_link_t *link, int idle)
286 reg.Offset = CISREG_COR; 286 reg.Offset = CISREG_COR;
287 reg.Value = (save_cor & ~COR_SOFT_RESET); 287 reg.Value = (save_cor & ~COR_SOFT_RESET);
288 CS_CHECK(AccessConfigurationRegister, 288 CS_CHECK(AccessConfigurationRegister,
289 pcmcia_access_configuration_register(link->handle, &reg)); 289 pcmcia_access_configuration_register(link, &reg));
290 udelay(1000); 290 udelay(1000);
291 return 0; 291 return 0;
292 292
293 cs_failed: 293 cs_failed:
294 cs_error(link->handle, last_fn, last_ret); 294 cs_error(link, last_fn, last_ret);
295 return -ENODEV; 295 return -ENODEV;
296} 296}
297 297
@@ -441,7 +441,7 @@ spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
441 * care of the PDA - read it and then write it on top of the firmware. 441 * care of the PDA - read it and then write it on top of the firmware.
442 */ 442 */
443static int 443static int
444spectrum_dl_image(hermes_t *hw, dev_link_t *link, 444spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
445 const unsigned char *image) 445 const unsigned char *image)
446{ 446{
447 int ret; 447 int ret;
@@ -505,14 +505,13 @@ spectrum_dl_image(hermes_t *hw, dev_link_t *link,
505 * reset on the card, to make sure it's in a sane state. 505 * reset on the card, to make sure it's in a sane state.
506 */ 506 */
507static int 507static int
508spectrum_dl_firmware(hermes_t *hw, dev_link_t *link) 508spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link)
509{ 509{
510 int ret; 510 int ret;
511 client_handle_t handle = link->handle;
512 const struct firmware *fw_entry; 511 const struct firmware *fw_entry;
513 512
514 if (request_firmware(&fw_entry, primary_fw_name, 513 if (request_firmware(&fw_entry, primary_fw_name,
515 &handle_to_dev(handle)) == 0) { 514 &handle_to_dev(link)) == 0) {
516 primsym = fw_entry->data; 515 primsym = fw_entry->data;
517 } else { 516 } else {
518 printk(KERN_ERR PFX "Cannot find firmware: %s\n", 517 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
@@ -521,7 +520,7 @@ spectrum_dl_firmware(hermes_t *hw, dev_link_t *link)
521 } 520 }
522 521
523 if (request_firmware(&fw_entry, secondary_fw_name, 522 if (request_firmware(&fw_entry, secondary_fw_name,
524 &handle_to_dev(handle)) == 0) { 523 &handle_to_dev(link)) == 0) {
525 secsym = fw_entry->data; 524 secsym = fw_entry->data;
526 } else { 525 } else {
527 printk(KERN_ERR PFX "Cannot find firmware: %s\n", 526 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
@@ -554,12 +553,12 @@ static int
554spectrum_cs_hard_reset(struct orinoco_private *priv) 553spectrum_cs_hard_reset(struct orinoco_private *priv)
555{ 554{
556 struct orinoco_pccard *card = priv->card; 555 struct orinoco_pccard *card = priv->card;
557 dev_link_t *link = &card->link; 556 struct pcmcia_device *link = card->p_dev;
558 int err; 557 int err;
559 558
560 if (!hermes_present(&priv->hw)) { 559 if (!hermes_present(&priv->hw)) {
561 /* The firmware needs to be reloaded */ 560 /* The firmware needs to be reloaded */
562 if (spectrum_dl_firmware(&priv->hw, &card->link) != 0) { 561 if (spectrum_dl_firmware(&priv->hw, link) != 0) {
563 printk(KERN_ERR PFX "Firmware download failed\n"); 562 printk(KERN_ERR PFX "Firmware download failed\n");
564 err = -ENODEV; 563 err = -ENODEV;
565 } 564 }
@@ -584,12 +583,11 @@ spectrum_cs_hard_reset(struct orinoco_private *priv)
584 * configure the card at this point -- we wait until we receive a card 583 * configure the card at this point -- we wait until we receive a card
585 * insertion event. */ 584 * insertion event. */
586static int 585static int
587spectrum_cs_attach(struct pcmcia_device *p_dev) 586spectrum_cs_probe(struct pcmcia_device *link)
588{ 587{
589 struct net_device *dev; 588 struct net_device *dev;
590 struct orinoco_private *priv; 589 struct orinoco_private *priv;
591 struct orinoco_pccard *card; 590 struct orinoco_pccard *card;
592 dev_link_t *link;
593 591
594 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); 592 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
595 if (! dev) 593 if (! dev)
@@ -598,7 +596,7 @@ spectrum_cs_attach(struct pcmcia_device *p_dev)
598 card = priv->card; 596 card = priv->card;
599 597
600 /* Link both structures together */ 598 /* Link both structures together */
601 link = &card->link; 599 card->p_dev = link;
602 link->priv = dev; 600 link->priv = dev;
603 601
604 /* Interrupt setup */ 602 /* Interrupt setup */
@@ -615,13 +613,7 @@ spectrum_cs_attach(struct pcmcia_device *p_dev)
615 link->conf.Attributes = 0; 613 link->conf.Attributes = 0;
616 link->conf.IntType = INT_MEMORY_AND_IO; 614 link->conf.IntType = INT_MEMORY_AND_IO;
617 615
618 link->handle = p_dev; 616 return spectrum_cs_config(link);
619 p_dev->instance = link;
620
621 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
622 spectrum_cs_config(link);
623
624 return 0;
625} /* spectrum_cs_attach */ 617} /* spectrum_cs_attach */
626 618
627/* 619/*
@@ -630,16 +622,14 @@ spectrum_cs_attach(struct pcmcia_device *p_dev)
630 * are freed. Otherwise, the structures will be freed when the device 622 * are freed. Otherwise, the structures will be freed when the device
631 * is released. 623 * is released.
632 */ 624 */
633static void spectrum_cs_detach(struct pcmcia_device *p_dev) 625static void spectrum_cs_detach(struct pcmcia_device *link)
634{ 626{
635 dev_link_t *link = dev_to_instance(p_dev);
636 struct net_device *dev = link->priv; 627 struct net_device *dev = link->priv;
637 628
638 if (link->state & DEV_CONFIG) 629 spectrum_cs_release(link);
639 spectrum_cs_release(link);
640 630
641 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); 631 DEBUG(0, PFX "detach: link=%p link->dev_node=%p\n", link, link->dev_node);
642 if (link->dev) { 632 if (link->dev_node) {
643 DEBUG(0, PFX "About to unregister net device %p\n", 633 DEBUG(0, PFX "About to unregister net device %p\n",
644 dev); 634 dev);
645 unregister_netdev(dev); 635 unregister_netdev(dev);
@@ -653,11 +643,10 @@ static void spectrum_cs_detach(struct pcmcia_device *p_dev)
653 * device available to the system. 643 * device available to the system.
654 */ 644 */
655 645
656static void 646static int
657spectrum_cs_config(dev_link_t *link) 647spectrum_cs_config(struct pcmcia_device *link)
658{ 648{
659 struct net_device *dev = link->priv; 649 struct net_device *dev = link->priv;
660 client_handle_t handle = link->handle;
661 struct orinoco_private *priv = netdev_priv(dev); 650 struct orinoco_private *priv = netdev_priv(dev);
662 struct orinoco_pccard *card = priv->card; 651 struct orinoco_pccard *card = priv->card;
663 hermes_t *hw = &priv->hw; 652 hermes_t *hw = &priv->hw;
@@ -669,7 +658,7 @@ spectrum_cs_config(dev_link_t *link)
669 cisparse_t parse; 658 cisparse_t parse;
670 void __iomem *mem; 659 void __iomem *mem;
671 660
672 CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info)); 661 CS_CHECK(ValidateCIS, pcmcia_validate_cis(link, &info));
673 662
674 /* 663 /*
675 * This reads the card's CONFIG tuple to find its 664 * This reads the card's CONFIG tuple to find its
@@ -680,19 +669,15 @@ spectrum_cs_config(dev_link_t *link)
680 tuple.TupleData = buf; 669 tuple.TupleData = buf;
681 tuple.TupleDataMax = sizeof(buf); 670 tuple.TupleDataMax = sizeof(buf);
682 tuple.TupleOffset = 0; 671 tuple.TupleOffset = 0;
683 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 672 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
684 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 673 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
685 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 674 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
686 link->conf.ConfigBase = parse.config.base; 675 link->conf.ConfigBase = parse.config.base;
687 link->conf.Present = parse.config.rmask[0]; 676 link->conf.Present = parse.config.rmask[0];
688 677
689 /* Configure card */
690 link->state |= DEV_CONFIG;
691
692 /* Look up the current Vcc */ 678 /* Look up the current Vcc */
693 CS_CHECK(GetConfigurationInfo, 679 CS_CHECK(GetConfigurationInfo,
694 pcmcia_get_configuration_info(handle, &conf)); 680 pcmcia_get_configuration_info(link, &conf));
695 link->conf.Vcc = conf.Vcc;
696 681
697 /* 682 /*
698 * In this loop, we scan the CIS for configuration table 683 * In this loop, we scan the CIS for configuration table
@@ -709,13 +694,13 @@ spectrum_cs_config(dev_link_t *link)
709 * implementation-defined details. 694 * implementation-defined details.
710 */ 695 */
711 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 696 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
712 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 697 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
713 while (1) { 698 while (1) {
714 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 699 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
715 cistpl_cftable_entry_t dflt = { .index = 0 }; 700 cistpl_cftable_entry_t dflt = { .index = 0 };
716 701
717 if ( (pcmcia_get_tuple_data(handle, &tuple) != 0) 702 if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
718 || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0)) 703 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
719 goto next_entry; 704 goto next_entry;
720 705
721 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 706 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
@@ -747,10 +732,10 @@ spectrum_cs_config(dev_link_t *link)
747 } 732 }
748 733
749 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 734 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
750 link->conf.Vpp1 = link->conf.Vpp2 = 735 link->conf.Vpp =
751 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 736 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
752 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 737 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
753 link->conf.Vpp1 = link->conf.Vpp2 = 738 link->conf.Vpp =
754 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 739 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
755 740
756 /* Do we need to allocate an interrupt? */ 741 /* Do we need to allocate an interrupt? */
@@ -780,7 +765,7 @@ spectrum_cs_config(dev_link_t *link)
780 } 765 }
781 766
782 /* This reserves IO space but doesn't actually enable it */ 767 /* This reserves IO space but doesn't actually enable it */
783 if (pcmcia_request_io(link->handle, &link->io) != 0) 768 if (pcmcia_request_io(link, &link->io) != 0)
784 goto next_entry; 769 goto next_entry;
785 } 770 }
786 771
@@ -790,9 +775,8 @@ spectrum_cs_config(dev_link_t *link)
790 break; 775 break;
791 776
792 next_entry: 777 next_entry:
793 if (link->io.NumPorts1) 778 pcmcia_disable_device(link);
794 pcmcia_release_io(link->handle, &link->io); 779 last_ret = pcmcia_get_next_tuple(link, &tuple);
795 last_ret = pcmcia_get_next_tuple(handle, &tuple);
796 if (last_ret == CS_NO_MORE_ITEMS) { 780 if (last_ret == CS_NO_MORE_ITEMS) {
797 printk(KERN_ERR PFX "GetNextTuple(): No matching " 781 printk(KERN_ERR PFX "GetNextTuple(): No matching "
798 "CIS configuration. Maybe you need the " 782 "CIS configuration. Maybe you need the "
@@ -806,7 +790,7 @@ spectrum_cs_config(dev_link_t *link)
806 * a handler to the interrupt, unless the 'Handler' member of 790 * a handler to the interrupt, unless the 'Handler' member of
807 * the irq structure is initialized. 791 * the irq structure is initialized.
808 */ 792 */
809 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 793 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
810 794
811 /* We initialize the hermes structure before completing PCMCIA 795 /* We initialize the hermes structure before completing PCMCIA
812 * configuration just in case the interrupt handler gets 796 * configuration just in case the interrupt handler gets
@@ -823,7 +807,7 @@ spectrum_cs_config(dev_link_t *link)
823 * card and host interface into "Memory and IO" mode. 807 * card and host interface into "Memory and IO" mode.
824 */ 808 */
825 CS_CHECK(RequestConfiguration, 809 CS_CHECK(RequestConfiguration,
826 pcmcia_request_configuration(link->handle, &link->conf)); 810 pcmcia_request_configuration(link, &link->conf));
827 811
828 /* Ok, we have the configuration, prepare to register the netdev */ 812 /* Ok, we have the configuration, prepare to register the netdev */
829 dev->base_addr = link->io.BasePort1; 813 dev->base_addr = link->io.BasePort1;
@@ -836,7 +820,7 @@ spectrum_cs_config(dev_link_t *link)
836 goto failed; 820 goto failed;
837 } 821 }
838 822
839 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 823 SET_NETDEV_DEV(dev, &handle_to_dev(link));
840 /* Tell the stack we exist */ 824 /* Tell the stack we exist */
841 if (register_netdev(dev) != 0) { 825 if (register_netdev(dev) != 0) {
842 printk(KERN_ERR PFX "register_netdev() failed\n"); 826 printk(KERN_ERR PFX "register_netdev() failed\n");
@@ -844,20 +828,18 @@ spectrum_cs_config(dev_link_t *link)
844 } 828 }
845 829
846 /* At this point, the dev_node_t structure(s) needs to be 830 /* At this point, the dev_node_t structure(s) needs to be
847 * initialized and arranged in a linked list at link->dev. */ 831 * initialized and arranged in a linked list at link->dev_node. */
848 strcpy(card->node.dev_name, dev->name); 832 strcpy(card->node.dev_name, dev->name);
849 link->dev = &card->node; /* link->dev being non-NULL is also 833 link->dev_node = &card->node; /* link->dev_node being non-NULL is also
850 used to indicate that the 834 used to indicate that the
851 net_device has been registered */ 835 net_device has been registered */
852 link->state &= ~DEV_CONFIG_PENDING;
853 836
854 /* Finally, report what we've done */ 837 /* Finally, report what we've done */
855 printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d", 838 printk(KERN_DEBUG "%s: index 0x%02x: ",
856 dev->name, link->conf.ConfigIndex, 839 dev->name, link->conf.ConfigIndex);
857 link->conf.Vcc / 10, link->conf.Vcc % 10); 840 if (link->conf.Vpp)
858 if (link->conf.Vpp1) 841 printk(", Vpp %d.%d", link->conf.Vpp / 10,
859 printk(", Vpp %d.%d", link->conf.Vpp1 / 10, 842 link->conf.Vpp % 10);
860 link->conf.Vpp1 % 10);
861 printk(", irq %d", link->irq.AssignedIRQ); 843 printk(", irq %d", link->irq.AssignedIRQ);
862 if (link->io.NumPorts1) 844 if (link->io.NumPorts1)
863 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 845 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
@@ -867,13 +849,14 @@ spectrum_cs_config(dev_link_t *link)
867 link->io.BasePort2 + link->io.NumPorts2 - 1); 849 link->io.BasePort2 + link->io.NumPorts2 - 1);
868 printk("\n"); 850 printk("\n");
869 851
870 return; 852 return 0;
871 853
872 cs_failed: 854 cs_failed:
873 cs_error(link->handle, last_fn, last_ret); 855 cs_error(link, last_fn, last_ret);
874 856
875 failed: 857 failed:
876 spectrum_cs_release(link); 858 spectrum_cs_release(link);
859 return -ENODEV;
877} /* spectrum_cs_config */ 860} /* spectrum_cs_config */
878 861
879/* 862/*
@@ -882,7 +865,7 @@ spectrum_cs_config(dev_link_t *link)
882 * still open, this will be postponed until it is closed. 865 * still open, this will be postponed until it is closed.
883 */ 866 */
884static void 867static void
885spectrum_cs_release(dev_link_t *link) 868spectrum_cs_release(struct pcmcia_device *link)
886{ 869{
887 struct net_device *dev = link->priv; 870 struct net_device *dev = link->priv;
888 struct orinoco_private *priv = netdev_priv(dev); 871 struct orinoco_private *priv = netdev_priv(dev);
@@ -894,64 +877,46 @@ spectrum_cs_release(dev_link_t *link)
894 priv->hw_unavailable++; 877 priv->hw_unavailable++;
895 spin_unlock_irqrestore(&priv->lock, flags); 878 spin_unlock_irqrestore(&priv->lock, flags);
896 879
897 /* Don't bother checking to see if these succeed or not */ 880 pcmcia_disable_device(link);
898 pcmcia_release_configuration(link->handle);
899 if (link->io.NumPorts1)
900 pcmcia_release_io(link->handle, &link->io);
901 if (link->irq.AssignedIRQ)
902 pcmcia_release_irq(link->handle, &link->irq);
903 link->state &= ~DEV_CONFIG;
904 if (priv->hw.iobase) 881 if (priv->hw.iobase)
905 ioport_unmap(priv->hw.iobase); 882 ioport_unmap(priv->hw.iobase);
906} /* spectrum_cs_release */ 883} /* spectrum_cs_release */
907 884
908 885
909static int 886static int
910spectrum_cs_suspend(struct pcmcia_device *p_dev) 887spectrum_cs_suspend(struct pcmcia_device *link)
911{ 888{
912 dev_link_t *link = dev_to_instance(p_dev);
913 struct net_device *dev = link->priv; 889 struct net_device *dev = link->priv;
914 struct orinoco_private *priv = netdev_priv(dev); 890 struct orinoco_private *priv = netdev_priv(dev);
915 unsigned long flags; 891 unsigned long flags;
916 int err = 0; 892 int err = 0;
917 893
918 link->state |= DEV_SUSPEND;
919 /* Mark the device as stopped, to block IO until later */ 894 /* Mark the device as stopped, to block IO until later */
920 if (link->state & DEV_CONFIG) { 895 spin_lock_irqsave(&priv->lock, flags);
921 spin_lock_irqsave(&priv->lock, flags);
922
923 err = __orinoco_down(dev);
924 if (err)
925 printk(KERN_WARNING "%s: Error %d downing interface\n",
926 dev->name, err);
927 896
928 netif_device_detach(dev); 897 err = __orinoco_down(dev);
929 priv->hw_unavailable++; 898 if (err)
899 printk(KERN_WARNING "%s: Error %d downing interface\n",
900 dev->name, err);
930 901
931 spin_unlock_irqrestore(&priv->lock, flags); 902 netif_device_detach(dev);
903 priv->hw_unavailable++;
932 904
933 pcmcia_release_configuration(link->handle); 905 spin_unlock_irqrestore(&priv->lock, flags);
934 }
935 906
936 return 0; 907 return 0;
937} 908}
938 909
939static int 910static int
940spectrum_cs_resume(struct pcmcia_device *p_dev) 911spectrum_cs_resume(struct pcmcia_device *link)
941{ 912{
942 dev_link_t *link = dev_to_instance(p_dev);
943 struct net_device *dev = link->priv; 913 struct net_device *dev = link->priv;
944 struct orinoco_private *priv = netdev_priv(dev); 914 struct orinoco_private *priv = netdev_priv(dev);
945 915
946 link->state &= ~DEV_SUSPEND; 916 netif_device_attach(dev);
947 if (link->state & DEV_CONFIG) { 917 priv->hw_unavailable--;
948 /* FIXME: should we double check that this is 918 schedule_work(&priv->reset_work);
949 * the same card as we had before */ 919
950 pcmcia_request_configuration(link->handle, &link->conf);
951 netif_device_attach(dev);
952 priv->hw_unavailable--;
953 schedule_work(&priv->reset_work);
954 }
955 return 0; 920 return 0;
956} 921}
957 922
@@ -979,7 +944,7 @@ static struct pcmcia_driver orinoco_driver = {
979 .drv = { 944 .drv = {
980 .name = DRIVER_NAME, 945 .name = DRIVER_NAME,
981 }, 946 },
982 .probe = spectrum_cs_attach, 947 .probe = spectrum_cs_probe,
983 .remove = spectrum_cs_detach, 948 .remove = spectrum_cs_detach,
984 .suspend = spectrum_cs_suspend, 949 .suspend = spectrum_cs_suspend,
985 .resume = spectrum_cs_resume, 950 .resume = spectrum_cs_resume,
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 98122f3a4bc2..f7724eb2fa7e 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -1005,7 +1005,7 @@ static inline void
1005wv_82593_reconfig(struct net_device * dev) 1005wv_82593_reconfig(struct net_device * dev)
1006{ 1006{
1007 net_local * lp = netdev_priv(dev); 1007 net_local * lp = netdev_priv(dev);
1008 dev_link_t * link = lp->link; 1008 struct pcmcia_device * link = lp->link;
1009 unsigned long flags; 1009 unsigned long flags;
1010 1010
1011 /* Arm the flag, will be cleard in wv_82593_config() */ 1011 /* Arm the flag, will be cleard in wv_82593_config() */
@@ -3744,16 +3744,16 @@ wv_pcmcia_reset(struct net_device * dev)
3744{ 3744{
3745 int i; 3745 int i;
3746 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 }; 3746 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3747 dev_link_t * link = ((net_local *)netdev_priv(dev))->link; 3747 struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
3748 3748
3749#ifdef DEBUG_CONFIG_TRACE 3749#ifdef DEBUG_CONFIG_TRACE
3750 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name); 3750 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3751#endif 3751#endif
3752 3752
3753 i = pcmcia_access_configuration_register(link->handle, &reg); 3753 i = pcmcia_access_configuration_register(link, &reg);
3754 if(i != CS_SUCCESS) 3754 if(i != CS_SUCCESS)
3755 { 3755 {
3756 cs_error(link->handle, AccessConfigurationRegister, i); 3756 cs_error(link, AccessConfigurationRegister, i);
3757 return FALSE; 3757 return FALSE;
3758 } 3758 }
3759 3759
@@ -3764,19 +3764,19 @@ wv_pcmcia_reset(struct net_device * dev)
3764 3764
3765 reg.Action = CS_WRITE; 3765 reg.Action = CS_WRITE;
3766 reg.Value = reg.Value | COR_SW_RESET; 3766 reg.Value = reg.Value | COR_SW_RESET;
3767 i = pcmcia_access_configuration_register(link->handle, &reg); 3767 i = pcmcia_access_configuration_register(link, &reg);
3768 if(i != CS_SUCCESS) 3768 if(i != CS_SUCCESS)
3769 { 3769 {
3770 cs_error(link->handle, AccessConfigurationRegister, i); 3770 cs_error(link, AccessConfigurationRegister, i);
3771 return FALSE; 3771 return FALSE;
3772 } 3772 }
3773 3773
3774 reg.Action = CS_WRITE; 3774 reg.Action = CS_WRITE;
3775 reg.Value = COR_LEVEL_IRQ | COR_CONFIG; 3775 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3776 i = pcmcia_access_configuration_register(link->handle, &reg); 3776 i = pcmcia_access_configuration_register(link, &reg);
3777 if(i != CS_SUCCESS) 3777 if(i != CS_SUCCESS)
3778 { 3778 {
3779 cs_error(link->handle, AccessConfigurationRegister, i); 3779 cs_error(link, AccessConfigurationRegister, i);
3780 return FALSE; 3780 return FALSE;
3781 } 3781 }
3782 3782
@@ -3940,9 +3940,8 @@ wv_hw_reset(struct net_device * dev)
3940 * (called by wavelan_event()) 3940 * (called by wavelan_event())
3941 */ 3941 */
3942static inline int 3942static inline int
3943wv_pcmcia_config(dev_link_t * link) 3943wv_pcmcia_config(struct pcmcia_device * link)
3944{ 3944{
3945 client_handle_t handle = link->handle;
3946 tuple_t tuple; 3945 tuple_t tuple;
3947 cisparse_t parse; 3946 cisparse_t parse;
3948 struct net_device * dev = (struct net_device *) link->priv; 3947 struct net_device * dev = (struct net_device *) link->priv;
@@ -3965,16 +3964,16 @@ wv_pcmcia_config(dev_link_t * link)
3965 { 3964 {
3966 tuple.Attributes = 0; 3965 tuple.Attributes = 0;
3967 tuple.DesiredTuple = CISTPL_CONFIG; 3966 tuple.DesiredTuple = CISTPL_CONFIG;
3968 i = pcmcia_get_first_tuple(handle, &tuple); 3967 i = pcmcia_get_first_tuple(link, &tuple);
3969 if(i != CS_SUCCESS) 3968 if(i != CS_SUCCESS)
3970 break; 3969 break;
3971 tuple.TupleData = (cisdata_t *)buf; 3970 tuple.TupleData = (cisdata_t *)buf;
3972 tuple.TupleDataMax = 64; 3971 tuple.TupleDataMax = 64;
3973 tuple.TupleOffset = 0; 3972 tuple.TupleOffset = 0;
3974 i = pcmcia_get_tuple_data(handle, &tuple); 3973 i = pcmcia_get_tuple_data(link, &tuple);
3975 if(i != CS_SUCCESS) 3974 if(i != CS_SUCCESS)
3976 break; 3975 break;
3977 i = pcmcia_parse_tuple(handle, &tuple, &parse); 3976 i = pcmcia_parse_tuple(link, &tuple, &parse);
3978 if(i != CS_SUCCESS) 3977 if(i != CS_SUCCESS)
3979 break; 3978 break;
3980 link->conf.ConfigBase = parse.config.base; 3979 link->conf.ConfigBase = parse.config.base;
@@ -3983,19 +3982,16 @@ wv_pcmcia_config(dev_link_t * link)
3983 while(0); 3982 while(0);
3984 if(i != CS_SUCCESS) 3983 if(i != CS_SUCCESS)
3985 { 3984 {
3986 cs_error(link->handle, ParseTuple, i); 3985 cs_error(link, ParseTuple, i);
3987 link->state &= ~DEV_CONFIG_PENDING;
3988 return FALSE; 3986 return FALSE;
3989 } 3987 }
3990 3988
3991 /* Configure card */
3992 link->state |= DEV_CONFIG;
3993 do 3989 do
3994 { 3990 {
3995 i = pcmcia_request_io(link->handle, &link->io); 3991 i = pcmcia_request_io(link, &link->io);
3996 if(i != CS_SUCCESS) 3992 if(i != CS_SUCCESS)
3997 { 3993 {
3998 cs_error(link->handle, RequestIO, i); 3994 cs_error(link, RequestIO, i);
3999 break; 3995 break;
4000 } 3996 }
4001 3997
@@ -4003,10 +3999,10 @@ wv_pcmcia_config(dev_link_t * link)
4003 * Now allocate an interrupt line. Note that this does not 3999 * Now allocate an interrupt line. Note that this does not
4004 * actually assign a handler to the interrupt. 4000 * actually assign a handler to the interrupt.
4005 */ 4001 */
4006 i = pcmcia_request_irq(link->handle, &link->irq); 4002 i = pcmcia_request_irq(link, &link->irq);
4007 if(i != CS_SUCCESS) 4003 if(i != CS_SUCCESS)
4008 { 4004 {
4009 cs_error(link->handle, RequestIRQ, i); 4005 cs_error(link, RequestIRQ, i);
4010 break; 4006 break;
4011 } 4007 }
4012 4008
@@ -4015,15 +4011,15 @@ wv_pcmcia_config(dev_link_t * link)
4015 * the I/O windows and the interrupt mapping. 4011 * the I/O windows and the interrupt mapping.
4016 */ 4012 */
4017 link->conf.ConfigIndex = 1; 4013 link->conf.ConfigIndex = 1;
4018 i = pcmcia_request_configuration(link->handle, &link->conf); 4014 i = pcmcia_request_configuration(link, &link->conf);
4019 if(i != CS_SUCCESS) 4015 if(i != CS_SUCCESS)
4020 { 4016 {
4021 cs_error(link->handle, RequestConfiguration, i); 4017 cs_error(link, RequestConfiguration, i);
4022 break; 4018 break;
4023 } 4019 }
4024 4020
4025 /* 4021 /*
4026 * Allocate a small memory window. Note that the dev_link_t 4022 * Allocate a small memory window. Note that the struct pcmcia_device
4027 * structure provides space for one window handle -- if your 4023 * structure provides space for one window handle -- if your
4028 * device needs several windows, you'll need to keep track of 4024 * device needs several windows, you'll need to keep track of
4029 * the handles in your private data structure, link->priv. 4025 * the handles in your private data structure, link->priv.
@@ -4031,10 +4027,10 @@ wv_pcmcia_config(dev_link_t * link)
4031 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 4027 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
4032 req.Base = req.Size = 0; 4028 req.Base = req.Size = 0;
4033 req.AccessSpeed = mem_speed; 4029 req.AccessSpeed = mem_speed;
4034 i = pcmcia_request_window(&link->handle, &req, &link->win); 4030 i = pcmcia_request_window(&link, &req, &link->win);
4035 if(i != CS_SUCCESS) 4031 if(i != CS_SUCCESS)
4036 { 4032 {
4037 cs_error(link->handle, RequestWindow, i); 4033 cs_error(link, RequestWindow, i);
4038 break; 4034 break;
4039 } 4035 }
4040 4036
@@ -4046,7 +4042,7 @@ wv_pcmcia_config(dev_link_t * link)
4046 i = pcmcia_map_mem_page(link->win, &mem); 4042 i = pcmcia_map_mem_page(link->win, &mem);
4047 if(i != CS_SUCCESS) 4043 if(i != CS_SUCCESS)
4048 { 4044 {
4049 cs_error(link->handle, MapMemPage, i); 4045 cs_error(link, MapMemPage, i);
4050 break; 4046 break;
4051 } 4047 }
4052 4048
@@ -4060,7 +4056,7 @@ wv_pcmcia_config(dev_link_t * link)
4060 lp->mem, dev->irq, (u_int) dev->base_addr); 4056 lp->mem, dev->irq, (u_int) dev->base_addr);
4061#endif 4057#endif
4062 4058
4063 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 4059 SET_NETDEV_DEV(dev, &handle_to_dev(link));
4064 i = register_netdev(dev); 4060 i = register_netdev(dev);
4065 if(i != 0) 4061 if(i != 0)
4066 { 4062 {
@@ -4072,7 +4068,6 @@ wv_pcmcia_config(dev_link_t * link)
4072 } 4068 }
4073 while(0); /* Humm... Disguised goto !!! */ 4069 while(0); /* Humm... Disguised goto !!! */
4074 4070
4075 link->state &= ~DEV_CONFIG_PENDING;
4076 /* If any step failed, release any partially configured state */ 4071 /* If any step failed, release any partially configured state */
4077 if(i != 0) 4072 if(i != 0)
4078 { 4073 {
@@ -4081,7 +4076,7 @@ wv_pcmcia_config(dev_link_t * link)
4081 } 4076 }
4082 4077
4083 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name); 4078 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
4084 link->dev = &((net_local *) netdev_priv(dev))->node; 4079 link->dev_node = &((net_local *) netdev_priv(dev))->node;
4085 4080
4086#ifdef DEBUG_CONFIG_TRACE 4081#ifdef DEBUG_CONFIG_TRACE
4087 printk(KERN_DEBUG "<-wv_pcmcia_config()\n"); 4082 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
@@ -4096,26 +4091,20 @@ wv_pcmcia_config(dev_link_t * link)
4096 * still open, this will be postponed until it is closed. 4091 * still open, this will be postponed until it is closed.
4097 */ 4092 */
4098static void 4093static void
4099wv_pcmcia_release(dev_link_t *link) 4094wv_pcmcia_release(struct pcmcia_device *link)
4100{ 4095{
4101 struct net_device * dev = (struct net_device *) link->priv; 4096 struct net_device * dev = (struct net_device *) link->priv;
4102 net_local * lp = netdev_priv(dev); 4097 net_local * lp = netdev_priv(dev);
4103 4098
4104#ifdef DEBUG_CONFIG_TRACE 4099#ifdef DEBUG_CONFIG_TRACE
4105 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link); 4100 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
4106#endif 4101#endif
4107 4102
4108 /* Don't bother checking to see if these succeed or not */ 4103 iounmap(lp->mem);
4109 iounmap(lp->mem); 4104 pcmcia_disable_device(link);
4110 pcmcia_release_window(link->win);
4111 pcmcia_release_configuration(link->handle);
4112 pcmcia_release_io(link->handle, &link->io);
4113 pcmcia_release_irq(link->handle, &link->irq);
4114
4115 link->state &= ~DEV_CONFIG;
4116 4105
4117#ifdef DEBUG_CONFIG_TRACE 4106#ifdef DEBUG_CONFIG_TRACE
4118 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name); 4107 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
4119#endif 4108#endif
4120} 4109}
4121 4110
@@ -4479,7 +4468,7 @@ static int
4479wavelan_open(struct net_device * dev) 4468wavelan_open(struct net_device * dev)
4480{ 4469{
4481 net_local * lp = netdev_priv(dev); 4470 net_local * lp = netdev_priv(dev);
4482 dev_link_t * link = lp->link; 4471 struct pcmcia_device * link = lp->link;
4483 kio_addr_t base = dev->base_addr; 4472 kio_addr_t base = dev->base_addr;
4484 4473
4485#ifdef DEBUG_CALLBACK_TRACE 4474#ifdef DEBUG_CALLBACK_TRACE
@@ -4533,7 +4522,7 @@ wavelan_open(struct net_device * dev)
4533static int 4522static int
4534wavelan_close(struct net_device * dev) 4523wavelan_close(struct net_device * dev)
4535{ 4524{
4536 dev_link_t * link = ((net_local *)netdev_priv(dev))->link; 4525 struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
4537 kio_addr_t base = dev->base_addr; 4526 kio_addr_t base = dev->base_addr;
4538 4527
4539#ifdef DEBUG_CALLBACK_TRACE 4528#ifdef DEBUG_CALLBACK_TRACE
@@ -4587,45 +4576,36 @@ wavelan_close(struct net_device * dev)
4587 * card insertion event. 4576 * card insertion event.
4588 */ 4577 */
4589static int 4578static int
4590wavelan_attach(struct pcmcia_device *p_dev) 4579wavelan_probe(struct pcmcia_device *p_dev)
4591{ 4580{
4592 dev_link_t * link; /* Info for cardmgr */
4593 struct net_device * dev; /* Interface generic data */ 4581 struct net_device * dev; /* Interface generic data */
4594 net_local * lp; /* Interface specific data */ 4582 net_local * lp; /* Interface specific data */
4583 int ret;
4595 4584
4596#ifdef DEBUG_CALLBACK_TRACE 4585#ifdef DEBUG_CALLBACK_TRACE
4597 printk(KERN_DEBUG "-> wavelan_attach()\n"); 4586 printk(KERN_DEBUG "-> wavelan_attach()\n");
4598#endif 4587#endif
4599 4588
4600 /* Initialize the dev_link_t structure */
4601 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4602 if (!link) return -ENOMEM;
4603
4604 /* The io structure describes IO port mapping */ 4589 /* The io structure describes IO port mapping */
4605 link->io.NumPorts1 = 8; 4590 p_dev->io.NumPorts1 = 8;
4606 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 4591 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4607 link->io.IOAddrLines = 3; 4592 p_dev->io.IOAddrLines = 3;
4608 4593
4609 /* Interrupt setup */ 4594 /* Interrupt setup */
4610 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 4595 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4611 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 4596 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
4612 link->irq.Handler = wavelan_interrupt; 4597 p_dev->irq.Handler = wavelan_interrupt;
4613 4598
4614 /* General socket configuration */ 4599 /* General socket configuration */
4615 link->conf.Attributes = CONF_ENABLE_IRQ; 4600 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
4616 link->conf.Vcc = 50; 4601 p_dev->conf.IntType = INT_MEMORY_AND_IO;
4617 link->conf.IntType = INT_MEMORY_AND_IO;
4618
4619 /* Chain drivers */
4620 link->next = NULL;
4621 4602
4622 /* Allocate the generic data structure */ 4603 /* Allocate the generic data structure */
4623 dev = alloc_etherdev(sizeof(net_local)); 4604 dev = alloc_etherdev(sizeof(net_local));
4624 if (!dev) { 4605 if (!dev)
4625 kfree(link);
4626 return -ENOMEM; 4606 return -ENOMEM;
4627 } 4607
4628 link->priv = link->irq.Instance = dev; 4608 p_dev->priv = p_dev->irq.Instance = dev;
4629 4609
4630 lp = netdev_priv(dev); 4610 lp = netdev_priv(dev);
4631 4611
@@ -4642,7 +4622,6 @@ wavelan_attach(struct pcmcia_device *p_dev)
4642 spin_lock_init(&lp->spinlock); 4622 spin_lock_init(&lp->spinlock);
4643 4623
4644 /* back links */ 4624 /* back links */
4645 lp->link = link;
4646 lp->dev = dev; 4625 lp->dev = dev;
4647 4626
4648 /* wavelan NET3 callbacks */ 4627 /* wavelan NET3 callbacks */
@@ -4668,15 +4647,18 @@ wavelan_attach(struct pcmcia_device *p_dev)
4668 /* Other specific data */ 4647 /* Other specific data */
4669 dev->mtu = WAVELAN_MTU; 4648 dev->mtu = WAVELAN_MTU;
4670 4649
4671 link->handle = p_dev; 4650 ret = wv_pcmcia_config(p_dev);
4672 p_dev->instance = link; 4651 if (ret)
4652 return ret;
4673 4653
4674 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 4654 ret = wv_hw_config(dev);
4675 if(wv_pcmcia_config(link) && 4655 if (ret) {
4676 wv_hw_config(dev))
4677 wv_init_info(dev);
4678 else
4679 dev->irq = 0; 4656 dev->irq = 0;
4657 pcmcia_disable_device(p_dev);
4658 return ret;
4659 }
4660
4661 wv_init_info(dev);
4680 4662
4681#ifdef DEBUG_CALLBACK_TRACE 4663#ifdef DEBUG_CALLBACK_TRACE
4682 printk(KERN_DEBUG "<- wavelan_attach()\n"); 4664 printk(KERN_DEBUG "<- wavelan_attach()\n");
@@ -4693,25 +4675,14 @@ wavelan_attach(struct pcmcia_device *p_dev)
4693 * is released. 4675 * is released.
4694 */ 4676 */
4695static void 4677static void
4696wavelan_detach(struct pcmcia_device *p_dev) 4678wavelan_detach(struct pcmcia_device *link)
4697{ 4679{
4698 dev_link_t *link = dev_to_instance(p_dev);
4699
4700#ifdef DEBUG_CALLBACK_TRACE 4680#ifdef DEBUG_CALLBACK_TRACE
4701 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link); 4681 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4702#endif 4682#endif
4703 4683
4704 /* 4684 /* Some others haven't done their job : give them another chance */
4705 * If the device is currently configured and active, we won't 4685 wv_pcmcia_release(link);
4706 * actually delete it yet. Instead, it is marked so that when the
4707 * release() function is called, that will trigger a proper
4708 * detach().
4709 */
4710 if(link->state & DEV_CONFIG)
4711 {
4712 /* Some others haven't done their job : give them another chance */
4713 wv_pcmcia_release(link);
4714 }
4715 4686
4716 /* Free pieces */ 4687 /* Free pieces */
4717 if(link->priv) 4688 if(link->priv)
@@ -4720,23 +4691,21 @@ wavelan_detach(struct pcmcia_device *p_dev)
4720 4691
4721 /* Remove ourselves from the kernel list of ethernet devices */ 4692 /* Remove ourselves from the kernel list of ethernet devices */
4722 /* Warning : can't be called from interrupt, timer or wavelan_close() */ 4693 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4723 if (link->dev) 4694 if (link->dev_node)
4724 unregister_netdev(dev); 4695 unregister_netdev(dev);
4725 link->dev = NULL; 4696 link->dev_node = NULL;
4726 ((net_local *)netdev_priv(dev))->link = NULL; 4697 ((net_local *)netdev_priv(dev))->link = NULL;
4727 ((net_local *)netdev_priv(dev))->dev = NULL; 4698 ((net_local *)netdev_priv(dev))->dev = NULL;
4728 free_netdev(dev); 4699 free_netdev(dev);
4729 } 4700 }
4730 kfree(link);
4731 4701
4732#ifdef DEBUG_CALLBACK_TRACE 4702#ifdef DEBUG_CALLBACK_TRACE
4733 printk(KERN_DEBUG "<- wavelan_detach()\n"); 4703 printk(KERN_DEBUG "<- wavelan_detach()\n");
4734#endif 4704#endif
4735} 4705}
4736 4706
4737static int wavelan_suspend(struct pcmcia_device *p_dev) 4707static int wavelan_suspend(struct pcmcia_device *link)
4738{ 4708{
4739 dev_link_t *link = dev_to_instance(p_dev);
4740 struct net_device * dev = (struct net_device *) link->priv; 4709 struct net_device * dev = (struct net_device *) link->priv;
4741 4710
4742 /* NB: wavelan_close will be called, but too late, so we are 4711 /* NB: wavelan_close will be called, but too late, so we are
@@ -4748,36 +4717,22 @@ static int wavelan_suspend(struct pcmcia_device *p_dev)
4748 /* Stop receiving new messages and wait end of transmission */ 4717 /* Stop receiving new messages and wait end of transmission */
4749 wv_ru_stop(dev); 4718 wv_ru_stop(dev);
4750 4719
4720 if (link->open)
4721 netif_device_detach(dev);
4722
4751 /* Power down the module */ 4723 /* Power down the module */
4752 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT)); 4724 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4753 4725
4754 /* The card is now suspended */
4755 link->state |= DEV_SUSPEND;
4756
4757 if(link->state & DEV_CONFIG)
4758 {
4759 if(link->open)
4760 netif_device_detach(dev);
4761 pcmcia_release_configuration(link->handle);
4762 }
4763
4764 return 0; 4726 return 0;
4765} 4727}
4766 4728
4767static int wavelan_resume(struct pcmcia_device *p_dev) 4729static int wavelan_resume(struct pcmcia_device *link)
4768{ 4730{
4769 dev_link_t *link = dev_to_instance(p_dev);
4770 struct net_device * dev = (struct net_device *) link->priv; 4731 struct net_device * dev = (struct net_device *) link->priv;
4771 4732
4772 link->state &= ~DEV_SUSPEND; 4733 if (link->open) {
4773 if(link->state & DEV_CONFIG) 4734 wv_hw_reset(dev);
4774 { 4735 netif_device_attach(dev);
4775 pcmcia_request_configuration(link->handle, &link->conf);
4776 if(link->open) /* If RESET -> True, If RESUME -> False ? */
4777 {
4778 wv_hw_reset(dev);
4779 netif_device_attach(dev);
4780 }
4781 } 4736 }
4782 4737
4783 return 0; 4738 return 0;
@@ -4798,7 +4753,7 @@ static struct pcmcia_driver wavelan_driver = {
4798 .drv = { 4753 .drv = {
4799 .name = "wavelan_cs", 4754 .name = "wavelan_cs",
4800 }, 4755 },
4801 .probe = wavelan_attach, 4756 .probe = wavelan_probe,
4802 .remove = wavelan_detach, 4757 .remove = wavelan_detach,
4803 .id_table = wavelan_ids, 4758 .id_table = wavelan_ids,
4804 .suspend = wavelan_suspend, 4759 .suspend = wavelan_suspend,
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h
index 451f6271dcbc..c65fe7a391ec 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/net/wireless/wavelan_cs.p.h
@@ -602,7 +602,7 @@ struct net_local
602 dev_node_t node; /* ???? What is this stuff ???? */ 602 dev_node_t node; /* ???? What is this stuff ???? */
603 struct net_device * dev; /* Reverse link... */ 603 struct net_device * dev; /* Reverse link... */
604 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */ 604 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
605 dev_link_t * link; /* pcmcia structure */ 605 struct pcmcia_device * link; /* pcmcia structure */
606 en_stats stats; /* Ethernet interface statistics */ 606 en_stats stats; /* Ethernet interface statistics */
607 int nresets; /* Number of hw resets */ 607 int nresets; /* Number of hw resets */
608 u_char configured; /* If it is configured */ 608 u_char configured; /* If it is configured */
@@ -733,9 +733,9 @@ static int
733static inline void 733static inline void
734 wv_hw_reset(struct net_device *); /* Same, + start receiver unit */ 734 wv_hw_reset(struct net_device *); /* Same, + start receiver unit */
735static inline int 735static inline int
736 wv_pcmcia_config(dev_link_t *); /* Configure the pcmcia interface */ 736 wv_pcmcia_config(struct pcmcia_device *); /* Configure the pcmcia interface */
737static void 737static void
738 wv_pcmcia_release(dev_link_t *);/* Remove a device */ 738 wv_pcmcia_release(struct pcmcia_device *);/* Remove a device */
739/* ---------------------- INTERRUPT HANDLING ---------------------- */ 739/* ---------------------- INTERRUPT HANDLING ---------------------- */
740static irqreturn_t 740static irqreturn_t
741 wavelan_interrupt(int, /* Interrupt handler */ 741 wavelan_interrupt(int, /* Interrupt handler */
diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h
index 4303c50c2ab6..65ceb088f700 100644
--- a/drivers/net/wireless/wl3501.h
+++ b/drivers/net/wireless/wl3501.h
@@ -611,5 +611,6 @@ struct wl3501_card {
611 struct iw_spy_data spy_data; 611 struct iw_spy_data spy_data;
612 struct iw_public_data wireless_data; 612 struct iw_public_data wireless_data;
613 struct dev_node_t node; 613 struct dev_node_t node;
614 struct pcmcia_device *p_dev;
614}; 615};
615#endif 616#endif
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 48e10b0c7e74..e52a650f6737 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -103,8 +103,8 @@ module_param(pc_debug, int, 0);
103 * release a socket, in response to card insertion and ejection events. They 103 * release a socket, in response to card insertion and ejection events. They
104 * are invoked from the wl24 event handler. 104 * are invoked from the wl24 event handler.
105 */ 105 */
106static void wl3501_config(dev_link_t *link); 106static int wl3501_config(struct pcmcia_device *link);
107static void wl3501_release(dev_link_t *link); 107static void wl3501_release(struct pcmcia_device *link);
108 108
109/* 109/*
110 * The dev_info variable is the "key" that is used to match up this 110 * The dev_info variable is the "key" that is used to match up this
@@ -226,17 +226,6 @@ static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
226 iw_set_mgmt_info_element(from->id, to, from->data, from->len); 226 iw_set_mgmt_info_element(from->id, to, from->data, from->len);
227} 227}
228 228
229/*
230 * A linked list of "instances" of the wl24 device. Each actual PCMCIA card
231 * corresponds to one device instance, and is described by one dev_link_t
232 * structure (defined in ds.h).
233 *
234 * You may not want to use a linked list for this -- for example, the memory
235 * card driver uses an array of dev_link_t pointers, where minor device numbers
236 * are used to derive the corresponding array index.
237 */
238static dev_link_t *wl3501_dev_list;
239
240static inline void wl3501_switch_page(struct wl3501_card *this, u8 page) 229static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
241{ 230{
242 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS); 231 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
@@ -1281,15 +1270,10 @@ static int wl3501_close(struct net_device *dev)
1281 struct wl3501_card *this = dev->priv; 1270 struct wl3501_card *this = dev->priv;
1282 int rc = -ENODEV; 1271 int rc = -ENODEV;
1283 unsigned long flags; 1272 unsigned long flags;
1284 dev_link_t *link; 1273 struct pcmcia_device *link;
1274 link = this->p_dev;
1285 1275
1286 spin_lock_irqsave(&this->lock, flags); 1276 spin_lock_irqsave(&this->lock, flags);
1287 /* Check if the device is in wl3501_dev_list */
1288 for (link = wl3501_dev_list; link; link = link->next)
1289 if (link->priv == dev)
1290 break;
1291 if (!link)
1292 goto out;
1293 link->open--; 1277 link->open--;
1294 1278
1295 /* Stop wl3501_hard_start_xmit() from now on */ 1279 /* Stop wl3501_hard_start_xmit() from now on */
@@ -1301,7 +1285,6 @@ static int wl3501_close(struct net_device *dev)
1301 1285
1302 rc = 0; 1286 rc = 0;
1303 printk(KERN_INFO "%s: WL3501 closed\n", dev->name); 1287 printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
1304out:
1305 spin_unlock_irqrestore(&this->lock, flags); 1288 spin_unlock_irqrestore(&this->lock, flags);
1306 return rc; 1289 return rc;
1307} 1290}
@@ -1400,14 +1383,11 @@ static int wl3501_open(struct net_device *dev)
1400 int rc = -ENODEV; 1383 int rc = -ENODEV;
1401 struct wl3501_card *this = dev->priv; 1384 struct wl3501_card *this = dev->priv;
1402 unsigned long flags; 1385 unsigned long flags;
1403 dev_link_t *link; 1386 struct pcmcia_device *link;
1387 link = this->p_dev;
1404 1388
1405 spin_lock_irqsave(&this->lock, flags); 1389 spin_lock_irqsave(&this->lock, flags);
1406 /* Check if the device is in wl3501_dev_list */ 1390 if (!pcmcia_dev_present(link))
1407 for (link = wl3501_dev_list; link; link = link->next)
1408 if (link->priv == dev)
1409 break;
1410 if (!DEV_OK(link))
1411 goto out; 1391 goto out;
1412 netif_device_attach(dev); 1392 netif_device_attach(dev);
1413 link->open++; 1393 link->open++;
@@ -1497,38 +1477,23 @@ static struct ethtool_ops ops = {
1497 * Services. If it has been released, all local data structures are freed. 1477 * Services. If it has been released, all local data structures are freed.
1498 * Otherwise, the structures will be freed when the device is released. 1478 * Otherwise, the structures will be freed when the device is released.
1499 */ 1479 */
1500static void wl3501_detach(struct pcmcia_device *p_dev) 1480static void wl3501_detach(struct pcmcia_device *link)
1501{ 1481{
1502 dev_link_t *link = dev_to_instance(p_dev);
1503 dev_link_t **linkp;
1504 struct net_device *dev = link->priv; 1482 struct net_device *dev = link->priv;
1505 1483
1506 /* Locate device structure */
1507 for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next)
1508 if (*linkp == link)
1509 break;
1510 if (!*linkp)
1511 goto out;
1512
1513 /* If the device is currently configured and active, we won't actually 1484 /* If the device is currently configured and active, we won't actually
1514 * delete it yet. Instead, it is marked so that when the release() 1485 * delete it yet. Instead, it is marked so that when the release()
1515 * function is called, that will trigger a proper detach(). */ 1486 * function is called, that will trigger a proper detach(). */
1516 1487
1517 if (link->state & DEV_CONFIG) { 1488 while (link->open > 0)
1518 while (link->open > 0) 1489 wl3501_close(dev);
1519 wl3501_close(dev);
1520
1521 netif_device_detach(dev);
1522 wl3501_release(link);
1523 }
1524 1490
1525 /* Unlink device structure, free pieces */ 1491 netif_device_detach(dev);
1526 *linkp = link->next; 1492 wl3501_release(link);
1527 1493
1528 if (link->priv) 1494 if (link->priv)
1529 free_netdev(link->priv); 1495 free_netdev(link->priv);
1530 kfree(link); 1496
1531out:
1532 return; 1497 return;
1533} 1498}
1534 1499
@@ -1953,33 +1918,26 @@ static const struct iw_handler_def wl3501_handler_def = {
1953 * The dev_link structure is initialized, but we don't actually configure the 1918 * The dev_link structure is initialized, but we don't actually configure the
1954 * card at this point -- we wait until we receive a card insertion event. 1919 * card at this point -- we wait until we receive a card insertion event.
1955 */ 1920 */
1956static int wl3501_attach(struct pcmcia_device *p_dev) 1921static int wl3501_probe(struct pcmcia_device *p_dev)
1957{ 1922{
1958 dev_link_t *link;
1959 struct net_device *dev; 1923 struct net_device *dev;
1960 struct wl3501_card *this; 1924 struct wl3501_card *this;
1961 1925
1962 /* Initialize the dev_link_t structure */
1963 link = kzalloc(sizeof(*link), GFP_KERNEL);
1964 if (!link)
1965 return -ENOMEM;
1966
1967 /* The io structure describes IO port mapping */ 1926 /* The io structure describes IO port mapping */
1968 link->io.NumPorts1 = 16; 1927 p_dev->io.NumPorts1 = 16;
1969 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 1928 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1970 link->io.IOAddrLines = 5; 1929 p_dev->io.IOAddrLines = 5;
1971 1930
1972 /* Interrupt setup */ 1931 /* Interrupt setup */
1973 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 1932 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
1974 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 1933 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
1975 link->irq.Handler = wl3501_interrupt; 1934 p_dev->irq.Handler = wl3501_interrupt;
1976 1935
1977 /* General socket configuration */ 1936 /* General socket configuration */
1978 link->conf.Attributes = CONF_ENABLE_IRQ; 1937 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
1979 link->conf.Vcc = 50; 1938 p_dev->conf.IntType = INT_MEMORY_AND_IO;
1980 link->conf.IntType = INT_MEMORY_AND_IO; 1939 p_dev->conf.ConfigIndex = 1;
1981 link->conf.ConfigIndex = 1; 1940 p_dev->conf.Present = PRESENT_OPTION;
1982 link->conf.Present = PRESENT_OPTION;
1983 1941
1984 dev = alloc_etherdev(sizeof(struct wl3501_card)); 1942 dev = alloc_etherdev(sizeof(struct wl3501_card));
1985 if (!dev) 1943 if (!dev)
@@ -1992,22 +1950,15 @@ static int wl3501_attach(struct pcmcia_device *p_dev)
1992 dev->get_stats = wl3501_get_stats; 1950 dev->get_stats = wl3501_get_stats;
1993 this = dev->priv; 1951 this = dev->priv;
1994 this->wireless_data.spy_data = &this->spy_data; 1952 this->wireless_data.spy_data = &this->spy_data;
1953 this->p_dev = p_dev;
1995 dev->wireless_data = &this->wireless_data; 1954 dev->wireless_data = &this->wireless_data;
1996 dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def; 1955 dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def;
1997 SET_ETHTOOL_OPS(dev, &ops); 1956 SET_ETHTOOL_OPS(dev, &ops);
1998 netif_stop_queue(dev); 1957 netif_stop_queue(dev);
1999 link->priv = link->irq.Instance = dev; 1958 p_dev->priv = p_dev->irq.Instance = dev;
2000
2001 link->handle = p_dev;
2002 p_dev->instance = link;
2003
2004 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
2005 wl3501_config(link);
2006 1959
2007 return 0; 1960 return wl3501_config(p_dev);
2008out_link: 1961out_link:
2009 kfree(link);
2010 link = NULL;
2011 return -ENOMEM; 1962 return -ENOMEM;
2012} 1963}
2013 1964
@@ -2022,11 +1973,10 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
2022 * received, to configure the PCMCIA socket, and to make the ethernet device 1973 * received, to configure the PCMCIA socket, and to make the ethernet device
2023 * available to the system. 1974 * available to the system.
2024 */ 1975 */
2025static void wl3501_config(dev_link_t *link) 1976static int wl3501_config(struct pcmcia_device *link)
2026{ 1977{
2027 tuple_t tuple; 1978 tuple_t tuple;
2028 cisparse_t parse; 1979 cisparse_t parse;
2029 client_handle_t handle = link->handle;
2030 struct net_device *dev = link->priv; 1980 struct net_device *dev = link->priv;
2031 int i = 0, j, last_fn, last_ret; 1981 int i = 0, j, last_fn, last_ret;
2032 unsigned char bf[64]; 1982 unsigned char bf[64];
@@ -2035,18 +1985,15 @@ static void wl3501_config(dev_link_t *link)
2035 /* This reads the card's CONFIG tuple to find its config registers. */ 1985 /* This reads the card's CONFIG tuple to find its config registers. */
2036 tuple.Attributes = 0; 1986 tuple.Attributes = 0;
2037 tuple.DesiredTuple = CISTPL_CONFIG; 1987 tuple.DesiredTuple = CISTPL_CONFIG;
2038 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1988 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
2039 tuple.TupleData = bf; 1989 tuple.TupleData = bf;
2040 tuple.TupleDataMax = sizeof(bf); 1990 tuple.TupleDataMax = sizeof(bf);
2041 tuple.TupleOffset = 0; 1991 tuple.TupleOffset = 0;
2042 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 1992 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
2043 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 1993 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
2044 link->conf.ConfigBase = parse.config.base; 1994 link->conf.ConfigBase = parse.config.base;
2045 link->conf.Present = parse.config.rmask[0]; 1995 link->conf.Present = parse.config.rmask[0];
2046 1996
2047 /* Configure card */
2048 link->state |= DEV_CONFIG;
2049
2050 /* Try allocating IO ports. This tries a few fixed addresses. If you 1997 /* Try allocating IO ports. This tries a few fixed addresses. If you
2051 * want, you can also read the card's config table to pick addresses -- 1998 * want, you can also read the card's config table to pick addresses --
2052 * see the serial driver for an example. */ 1999 * see the serial driver for an example. */
@@ -2056,28 +2003,28 @@ static void wl3501_config(dev_link_t *link)
2056 * 0x200-0x2ff, and so on, because this seems safer */ 2003 * 0x200-0x2ff, and so on, because this seems safer */
2057 link->io.BasePort1 = j; 2004 link->io.BasePort1 = j;
2058 link->io.BasePort2 = link->io.BasePort1 + 0x10; 2005 link->io.BasePort2 = link->io.BasePort1 + 0x10;
2059 i = pcmcia_request_io(link->handle, &link->io); 2006 i = pcmcia_request_io(link, &link->io);
2060 if (i == CS_SUCCESS) 2007 if (i == CS_SUCCESS)
2061 break; 2008 break;
2062 } 2009 }
2063 if (i != CS_SUCCESS) { 2010 if (i != CS_SUCCESS) {
2064 cs_error(link->handle, RequestIO, i); 2011 cs_error(link, RequestIO, i);
2065 goto failed; 2012 goto failed;
2066 } 2013 }
2067 2014
2068 /* Now allocate an interrupt line. Note that this does not actually 2015 /* Now allocate an interrupt line. Note that this does not actually
2069 * assign a handler to the interrupt. */ 2016 * assign a handler to the interrupt. */
2070 2017
2071 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 2018 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
2072 2019
2073 /* This actually configures the PCMCIA socket -- setting up the I/O 2020 /* This actually configures the PCMCIA socket -- setting up the I/O
2074 * windows and the interrupt mapping. */ 2021 * windows and the interrupt mapping. */
2075 2022
2076 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 2023 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
2077 2024
2078 dev->irq = link->irq.AssignedIRQ; 2025 dev->irq = link->irq.AssignedIRQ;
2079 dev->base_addr = link->io.BasePort1; 2026 dev->base_addr = link->io.BasePort1;
2080 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 2027 SET_NETDEV_DEV(dev, &handle_to_dev(link));
2081 if (register_netdev(dev)) { 2028 if (register_netdev(dev)) {
2082 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n"); 2029 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
2083 goto failed; 2030 goto failed;
@@ -2088,10 +2035,9 @@ static void wl3501_config(dev_link_t *link)
2088 this = dev->priv; 2035 this = dev->priv;
2089 /* 2036 /*
2090 * At this point, the dev_node_t structure(s) should be initialized and 2037 * At this point, the dev_node_t structure(s) should be initialized and
2091 * arranged in a linked list at link->dev. 2038 * arranged in a linked list at link->dev_node.
2092 */ 2039 */
2093 link->dev = &this->node; 2040 link->dev_node = &this->node;
2094 link->state &= ~DEV_CONFIG_PENDING;
2095 2041
2096 this->base_addr = dev->base_addr; 2042 this->base_addr = dev->base_addr;
2097 2043
@@ -2127,13 +2073,13 @@ static void wl3501_config(dev_link_t *link)
2127 spin_lock_init(&this->lock); 2073 spin_lock_init(&this->lock);
2128 init_waitqueue_head(&this->wait); 2074 init_waitqueue_head(&this->wait);
2129 netif_start_queue(dev); 2075 netif_start_queue(dev);
2130 goto out; 2076 return 0;
2077
2131cs_failed: 2078cs_failed:
2132 cs_error(link->handle, last_fn, last_ret); 2079 cs_error(link, last_fn, last_ret);
2133failed: 2080failed:
2134 wl3501_release(link); 2081 wl3501_release(link);
2135out: 2082 return -ENODEV;
2136 return;
2137} 2083}
2138 2084
2139/** 2085/**
@@ -2144,52 +2090,36 @@ out:
2144 * and release the PCMCIA configuration. If the device is still open, this 2090 * and release the PCMCIA configuration. If the device is still open, this
2145 * will be postponed until it is closed. 2091 * will be postponed until it is closed.
2146 */ 2092 */
2147static void wl3501_release(dev_link_t *link) 2093static void wl3501_release(struct pcmcia_device *link)
2148{ 2094{
2149 struct net_device *dev = link->priv; 2095 struct net_device *dev = link->priv;
2150 2096
2151 /* Unlink the device chain */ 2097 /* Unlink the device chain */
2152 if (link->dev) { 2098 if (link->dev_node)
2153 unregister_netdev(dev); 2099 unregister_netdev(dev);
2154 link->dev = NULL;
2155 }
2156 2100
2157 /* Don't bother checking to see if these succeed or not */ 2101 pcmcia_disable_device(link);
2158 pcmcia_release_configuration(link->handle);
2159 pcmcia_release_io(link->handle, &link->io);
2160 pcmcia_release_irq(link->handle, &link->irq);
2161 link->state &= ~DEV_CONFIG;
2162} 2102}
2163 2103
2164static int wl3501_suspend(struct pcmcia_device *p_dev) 2104static int wl3501_suspend(struct pcmcia_device *link)
2165{ 2105{
2166 dev_link_t *link = dev_to_instance(p_dev);
2167 struct net_device *dev = link->priv; 2106 struct net_device *dev = link->priv;
2168 2107
2169 link->state |= DEV_SUSPEND;
2170
2171 wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND); 2108 wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
2172 if (link->state & DEV_CONFIG) { 2109 if (link->open)
2173 if (link->open) 2110 netif_device_detach(dev);
2174 netif_device_detach(dev);
2175 pcmcia_release_configuration(link->handle);
2176 }
2177 2111
2178 return 0; 2112 return 0;
2179} 2113}
2180 2114
2181static int wl3501_resume(struct pcmcia_device *p_dev) 2115static int wl3501_resume(struct pcmcia_device *link)
2182{ 2116{
2183 dev_link_t *link = dev_to_instance(p_dev);
2184 struct net_device *dev = link->priv; 2117 struct net_device *dev = link->priv;
2185 2118
2186 wl3501_pwr_mgmt(dev->priv, WL3501_RESUME); 2119 wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
2187 if (link->state & DEV_CONFIG) { 2120 if (link->open) {
2188 pcmcia_request_configuration(link->handle, &link->conf); 2121 wl3501_reset(dev);
2189 if (link->open) { 2122 netif_device_attach(dev);
2190 wl3501_reset(dev);
2191 netif_device_attach(dev);
2192 }
2193 } 2123 }
2194 2124
2195 return 0; 2125 return 0;
@@ -2207,7 +2137,7 @@ static struct pcmcia_driver wl3501_driver = {
2207 .drv = { 2137 .drv = {
2208 .name = "wl3501_cs", 2138 .name = "wl3501_cs",
2209 }, 2139 },
2210 .probe = wl3501_attach, 2140 .probe = wl3501_probe,
2211 .remove = wl3501_detach, 2141 .remove = wl3501_detach,
2212 .id_table = wl3501_ids, 2142 .id_table = wl3501_ids,
2213 .suspend = wl3501_suspend, 2143 .suspend = wl3501_suspend,
@@ -2221,9 +2151,7 @@ static int __init wl3501_init_module(void)
2221 2151
2222static void __exit wl3501_exit_module(void) 2152static void __exit wl3501_exit_module(void)
2223{ 2153{
2224 dprintk(0, ": unloading");
2225 pcmcia_unregister_driver(&wl3501_driver); 2154 pcmcia_unregister_driver(&wl3501_driver);
2226 BUG_ON(wl3501_dev_list != NULL);
2227} 2155}
2228 2156
2229module_init(wl3501_init_module); 2157module_init(wl3501_init_module);
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 158d92563259..b953d5907c05 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -81,15 +81,15 @@ static char *version =
81#define FORCE_EPP_MODE 0x08 81#define FORCE_EPP_MODE 0x08
82 82
83typedef struct parport_info_t { 83typedef struct parport_info_t {
84 dev_link_t link; 84 struct pcmcia_device *p_dev;
85 int ndev; 85 int ndev;
86 dev_node_t node; 86 dev_node_t node;
87 struct parport *port; 87 struct parport *port;
88} parport_info_t; 88} parport_info_t;
89 89
90static void parport_detach(struct pcmcia_device *p_dev); 90static void parport_detach(struct pcmcia_device *p_dev);
91static void parport_config(dev_link_t *link); 91static int parport_config(struct pcmcia_device *link);
92static void parport_cs_release(dev_link_t *); 92static void parport_cs_release(struct pcmcia_device *);
93 93
94/*====================================================================== 94/*======================================================================
95 95
@@ -99,10 +99,9 @@ static void parport_cs_release(dev_link_t *);
99 99
100======================================================================*/ 100======================================================================*/
101 101
102static int parport_attach(struct pcmcia_device *p_dev) 102static int parport_probe(struct pcmcia_device *link)
103{ 103{
104 parport_info_t *info; 104 parport_info_t *info;
105 dev_link_t *link;
106 105
107 DEBUG(0, "parport_attach()\n"); 106 DEBUG(0, "parport_attach()\n");
108 107
@@ -110,23 +109,17 @@ static int parport_attach(struct pcmcia_device *p_dev)
110 info = kmalloc(sizeof(*info), GFP_KERNEL); 109 info = kmalloc(sizeof(*info), GFP_KERNEL);
111 if (!info) return -ENOMEM; 110 if (!info) return -ENOMEM;
112 memset(info, 0, sizeof(*info)); 111 memset(info, 0, sizeof(*info));
113 link = &info->link; link->priv = info; 112 link->priv = info;
113 info->p_dev = link;
114 114
115 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 115 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
116 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 116 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
117 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 117 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
118 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 118 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
119 link->conf.Attributes = CONF_ENABLE_IRQ; 119 link->conf.Attributes = CONF_ENABLE_IRQ;
120 link->conf.Vcc = 50;
121 link->conf.IntType = INT_MEMORY_AND_IO; 120 link->conf.IntType = INT_MEMORY_AND_IO;
122 121
123 link->handle = p_dev; 122 return parport_config(link);
124 p_dev->instance = link;
125
126 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
127 parport_config(link);
128
129 return 0;
130} /* parport_attach */ 123} /* parport_attach */
131 124
132/*====================================================================== 125/*======================================================================
@@ -138,14 +131,11 @@ static int parport_attach(struct pcmcia_device *p_dev)
138 131
139======================================================================*/ 132======================================================================*/
140 133
141static void parport_detach(struct pcmcia_device *p_dev) 134static void parport_detach(struct pcmcia_device *link)
142{ 135{
143 dev_link_t *link = dev_to_instance(p_dev);
144
145 DEBUG(0, "parport_detach(0x%p)\n", link); 136 DEBUG(0, "parport_detach(0x%p)\n", link);
146 137
147 if (link->state & DEV_CONFIG) 138 parport_cs_release(link);
148 parport_cs_release(link);
149 139
150 kfree(link->priv); 140 kfree(link->priv);
151} /* parport_detach */ 141} /* parport_detach */
@@ -161,14 +151,12 @@ static void parport_detach(struct pcmcia_device *p_dev)
161#define CS_CHECK(fn, ret) \ 151#define CS_CHECK(fn, ret) \
162do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 152do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
163 153
164void parport_config(dev_link_t *link) 154static int parport_config(struct pcmcia_device *link)
165{ 155{
166 client_handle_t handle = link->handle;
167 parport_info_t *info = link->priv; 156 parport_info_t *info = link->priv;
168 tuple_t tuple; 157 tuple_t tuple;
169 u_short buf[128]; 158 u_short buf[128];
170 cisparse_t parse; 159 cisparse_t parse;
171 config_info_t conf;
172 cistpl_cftable_entry_t *cfg = &parse.cftable_entry; 160 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
173 cistpl_cftable_entry_t dflt = { 0 }; 161 cistpl_cftable_entry_t dflt = { 0 };
174 struct parport *p; 162 struct parport *p;
@@ -180,24 +168,18 @@ void parport_config(dev_link_t *link)
180 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 168 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
181 tuple.Attributes = 0; 169 tuple.Attributes = 0;
182 tuple.DesiredTuple = CISTPL_CONFIG; 170 tuple.DesiredTuple = CISTPL_CONFIG;
183 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 171 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
184 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 172 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
185 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 173 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
186 link->conf.ConfigBase = parse.config.base; 174 link->conf.ConfigBase = parse.config.base;
187 link->conf.Present = parse.config.rmask[0]; 175 link->conf.Present = parse.config.rmask[0];
188
189 /* Configure card */
190 link->state |= DEV_CONFIG;
191 176
192 /* Not sure if this is right... look up the current Vcc */
193 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
194
195 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 177 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
196 tuple.Attributes = 0; 178 tuple.Attributes = 0;
197 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 179 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
198 while (1) { 180 while (1) {
199 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 181 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
200 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 182 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
201 goto next_entry; 183 goto next_entry;
202 184
203 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { 185 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
@@ -212,7 +194,7 @@ void parport_config(dev_link_t *link)
212 link->io.BasePort2 = io->win[1].base; 194 link->io.BasePort2 = io->win[1].base;
213 link->io.NumPorts2 = io->win[1].len; 195 link->io.NumPorts2 = io->win[1].len;
214 } 196 }
215 if (pcmcia_request_io(link->handle, &link->io) != 0) 197 if (pcmcia_request_io(link, &link->io) != 0)
216 goto next_entry; 198 goto next_entry;
217 /* If we've got this far, we're done */ 199 /* If we've got this far, we're done */
218 break; 200 break;
@@ -220,15 +202,12 @@ void parport_config(dev_link_t *link)
220 202
221 next_entry: 203 next_entry:
222 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 204 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
223 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 205 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
224 } 206 }
225 207
226 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 208 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
227 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 209 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
228 210
229 release_region(link->io.BasePort1, link->io.NumPorts1);
230 if (link->io.NumPorts2)
231 release_region(link->io.BasePort2, link->io.NumPorts2);
232 p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2, 211 p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2,
233 link->irq.AssignedIRQ, PARPORT_DMA_NONE, 212 link->irq.AssignedIRQ, PARPORT_DMA_NONE,
234 NULL); 213 NULL);
@@ -247,17 +226,15 @@ void parport_config(dev_link_t *link)
247 info->node.minor = p->number; 226 info->node.minor = p->number;
248 info->port = p; 227 info->port = p;
249 strcpy(info->node.dev_name, p->name); 228 strcpy(info->node.dev_name, p->name);
250 link->dev = &info->node; 229 link->dev_node = &info->node;
230
231 return 0;
251 232
252 link->state &= ~DEV_CONFIG_PENDING;
253 return;
254
255cs_failed: 233cs_failed:
256 cs_error(link->handle, last_fn, last_ret); 234 cs_error(link, last_fn, last_ret);
257failed: 235failed:
258 parport_cs_release(link); 236 parport_cs_release(link);
259 link->state &= ~DEV_CONFIG_PENDING; 237 return -ENODEV;
260
261} /* parport_config */ 238} /* parport_config */
262 239
263/*====================================================================== 240/*======================================================================
@@ -268,53 +245,21 @@ failed:
268 245
269======================================================================*/ 246======================================================================*/
270 247
271void parport_cs_release(dev_link_t *link) 248void parport_cs_release(struct pcmcia_device *link)
272{
273 parport_info_t *info = link->priv;
274
275 DEBUG(0, "parport_release(0x%p)\n", link);
276
277 if (info->ndev) {
278 struct parport *p = info->port;
279 parport_pc_unregister_port(p);
280 request_region(link->io.BasePort1, link->io.NumPorts1,
281 info->node.dev_name);
282 if (link->io.NumPorts2)
283 request_region(link->io.BasePort2, link->io.NumPorts2,
284 info->node.dev_name);
285 }
286 info->ndev = 0;
287 link->dev = NULL;
288
289 pcmcia_release_configuration(link->handle);
290 pcmcia_release_io(link->handle, &link->io);
291 pcmcia_release_irq(link->handle, &link->irq);
292
293 link->state &= ~DEV_CONFIG;
294
295} /* parport_cs_release */
296
297static int parport_suspend(struct pcmcia_device *dev)
298{ 249{
299 dev_link_t *link = dev_to_instance(dev); 250 parport_info_t *info = link->priv;
300 251
301 link->state |= DEV_SUSPEND; 252 DEBUG(0, "parport_release(0x%p)\n", link);
302 if (link->state & DEV_CONFIG)
303 pcmcia_release_configuration(link->handle);
304 253
305 return 0; 254 if (info->ndev) {
306} 255 struct parport *p = info->port;
307 256 parport_pc_unregister_port(p);
308static int parport_resume(struct pcmcia_device *dev) 257 }
309{ 258 info->ndev = 0;
310 dev_link_t *link = dev_to_instance(dev);
311 259
312 link->state &= ~DEV_SUSPEND; 260 pcmcia_disable_device(link);
313 if (DEV_OK(link)) 261} /* parport_cs_release */
314 pcmcia_request_configuration(link->handle, &link->conf);
315 262
316 return 0;
317}
318 263
319static struct pcmcia_device_id parport_ids[] = { 264static struct pcmcia_device_id parport_ids[] = {
320 PCMCIA_DEVICE_FUNC_ID(3), 265 PCMCIA_DEVICE_FUNC_ID(3),
@@ -328,11 +273,9 @@ static struct pcmcia_driver parport_cs_driver = {
328 .drv = { 273 .drv = {
329 .name = "parport_cs", 274 .name = "parport_cs",
330 }, 275 },
331 .probe = parport_attach, 276 .probe = parport_probe,
332 .remove = parport_detach, 277 .remove = parport_detach,
333 .id_table = parport_ids, 278 .id_table = parport_ids,
334 .suspend = parport_suspend,
335 .resume = parport_resume,
336}; 279};
337 280
338static int __init init_parport_cs(void) 281static int __init init_parport_cs(void)
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 1f4ad0e7836e..cba6c9eef28e 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -263,6 +263,13 @@ config OMAP_CF
263 Say Y here to support the CompactFlash controller on OMAP. 263 Say Y here to support the CompactFlash controller on OMAP.
264 Note that this doesn't support "True IDE" mode. 264 Note that this doesn't support "True IDE" mode.
265 265
266config AT91_CF
267 tristate "AT91 CompactFlash Controller"
268 depends on PCMCIA && ARCH_AT91RM9200
269 help
270 Say Y here to support the CompactFlash controller on AT91 chips.
271 Or choose M to compile the driver as a module named "at91_cf".
272
266config PCCARD_NONSTATIC 273config PCCARD_NONSTATIC
267 tristate 274 tristate
268 275
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index bcecf5133b7e..4276965517f2 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -10,7 +10,7 @@ pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o
10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o
11obj-$(CONFIG_PCCARD) += pcmcia_core.o 11obj-$(CONFIG_PCCARD) += pcmcia_core.o
12 12
13pcmcia-y += ds.o pcmcia_compat.o pcmcia_resource.o 13pcmcia-y += ds.o pcmcia_resource.o
14pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o 14pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o
15obj-$(CONFIG_PCMCIA) += pcmcia.o 15obj-$(CONFIG_PCMCIA) += pcmcia.o
16 16
@@ -36,6 +36,7 @@ obj-$(CONFIG_PCMCIA_AU1X00) += au1x00_ss.o
36obj-$(CONFIG_PCMCIA_VRC4171) += vrc4171_card.o 36obj-$(CONFIG_PCMCIA_VRC4171) += vrc4171_card.o
37obj-$(CONFIG_PCMCIA_VRC4173) += vrc4173_cardu.o 37obj-$(CONFIG_PCMCIA_VRC4173) += vrc4173_cardu.o
38obj-$(CONFIG_OMAP_CF) += omap_cf.o 38obj-$(CONFIG_OMAP_CF) += omap_cf.o
39obj-$(CONFIG_AT91_CF) += at91_cf.o
39 40
40sa11xx_core-y += soc_common.o sa11xx_base.o 41sa11xx_core-y += soc_common.o sa11xx_base.o
41pxa2xx_core-y += soc_common.o pxa2xx_base.o 42pxa2xx_core-y += soc_common.o pxa2xx_base.o
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
new file mode 100644
index 000000000000..67cc5f7d0c90
--- /dev/null
+++ b/drivers/pcmcia/at91_cf.c
@@ -0,0 +1,365 @@
1/*
2 * at91_cf.c -- AT91 CompactFlash controller driver
3 *
4 * Copyright (C) 2005 David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/platform_device.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/interrupt.h>
19
20#include <pcmcia/ss.h>
21
22#include <asm/hardware.h>
23#include <asm/io.h>
24#include <asm/sizes.h>
25
26#include <asm/arch/at91rm9200.h>
27#include <asm/arch/board.h>
28#include <asm/arch/gpio.h>
29
30
31#define CF_SIZE 0x30000000 /* CS5+CS6: unavailable */
32
33/*
34 * A0..A10 work in each range; A23 indicates I/O space; A25 is CFRNW;
35 * some other bit in {A24,A22..A11} is nREG to flag memory access
36 * (vs attributes). So more than 2KB/region would just be waste.
37 */
38#define CF_ATTR_PHYS (AT91_CF_BASE)
39#define CF_IO_PHYS (AT91_CF_BASE + (1 << 23))
40#define CF_MEM_PHYS (AT91_CF_BASE + 0x017ff800)
41
42/*--------------------------------------------------------------------------*/
43
44static const char driver_name[] = "at91_cf";
45
46struct at91_cf_socket {
47 struct pcmcia_socket socket;
48
49 unsigned present:1;
50
51 struct platform_device *pdev;
52 struct at91_cf_data *board;
53};
54
55#define SZ_2K (2 * SZ_1K)
56
57static inline int at91_cf_present(struct at91_cf_socket *cf)
58{
59 return !at91_get_gpio_value(cf->board->det_pin);
60}
61
62/*--------------------------------------------------------------------------*/
63
64static int at91_cf_ss_init(struct pcmcia_socket *s)
65{
66 return 0;
67}
68
69static irqreturn_t at91_cf_irq(int irq, void *_cf, struct pt_regs *r)
70{
71 struct at91_cf_socket *cf = (struct at91_cf_socket *) _cf;
72
73 if (irq == cf->board->det_pin) {
74 unsigned present = at91_cf_present(cf);
75
76 /* kick pccard as needed */
77 if (present != cf->present) {
78 cf->present = present;
79 pr_debug("%s: card %s\n", driver_name, present ? "present" : "gone");
80 pcmcia_parse_events(&cf->socket, SS_DETECT);
81 }
82 }
83
84 return IRQ_HANDLED;
85}
86
87static int at91_cf_get_status(struct pcmcia_socket *s, u_int *sp)
88{
89 struct at91_cf_socket *cf;
90
91 if (!sp)
92 return -EINVAL;
93
94 cf = container_of(s, struct at91_cf_socket, socket);
95
96 /* NOTE: we assume 3VCARD, not XVCARD... */
97 if (at91_cf_present(cf)) {
98 int rdy = cf->board->irq_pin; /* RDY/nIRQ */
99 int vcc = cf->board->vcc_pin;
100
101 *sp = SS_DETECT | SS_3VCARD;
102 if (!rdy || at91_get_gpio_value(rdy))
103 *sp |= SS_READY;
104 if (!vcc || at91_get_gpio_value(vcc))
105 *sp |= SS_POWERON;
106 } else
107 *sp = 0;
108
109 return 0;
110}
111
112static int at91_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
113{
114 struct at91_cf_socket *cf;
115
116 cf = container_of(sock, struct at91_cf_socket, socket);
117
118 /* switch Vcc if needed and possible */
119 if (cf->board->vcc_pin) {
120 switch (s->Vcc) {
121 case 0:
122 at91_set_gpio_value(cf->board->vcc_pin, 0);
123 break;
124 case 33:
125 at91_set_gpio_value(cf->board->vcc_pin, 1);
126 break;
127 default:
128 return -EINVAL;
129 }
130 }
131
132 /* toggle reset if needed */
133 at91_set_gpio_value(cf->board->rst_pin, s->flags & SS_RESET);
134
135 pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n",
136 driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask);
137
138 return 0;
139}
140
141static int at91_cf_ss_suspend(struct pcmcia_socket *s)
142{
143 return at91_cf_set_socket(s, &dead_socket);
144}
145
146/* we already mapped the I/O region */
147static int at91_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
148{
149 struct at91_cf_socket *cf;
150 u32 csr;
151
152 cf = container_of(s, struct at91_cf_socket, socket);
153 io->flags &= (MAP_ACTIVE | MAP_16BIT | MAP_AUTOSZ);
154
155 /*
156 * Use 16 bit accesses unless/until we need 8-bit i/o space.
157 * Always set CSR4 ... PCMCIA won't always unmap things.
158 */
159 csr = at91_sys_read(AT91_SMC_CSR(4)) & ~AT91_SMC_DBW;
160
161 /*
162 * NOTE: this CF controller ignores IOIS16, so we can't really do
163 * MAP_AUTOSZ. The 16bit mode allows single byte access on either
164 * D0-D7 (even addr) or D8-D15 (odd), so it's close enough for many
165 * purposes (and handles ide-cs).
166 *
167 * The 8bit mode is needed for odd byte access on D0-D7. It seems
168 * some cards only like that way to get at the odd byte, despite
169 * CF 3.0 spec table 35 also giving the D8-D15 option.
170 */
171 if (!(io->flags & (MAP_16BIT|MAP_AUTOSZ))) {
172 csr |= AT91_SMC_DBW_8;
173 pr_debug("%s: 8bit i/o bus\n", driver_name);
174 } else {
175 csr |= AT91_SMC_DBW_16;
176 pr_debug("%s: 16bit i/o bus\n", driver_name);
177 }
178 at91_sys_write(AT91_SMC_CSR(4), csr);
179
180 io->start = cf->socket.io_offset;
181 io->stop = io->start + SZ_2K - 1;
182
183 return 0;
184}
185
186/* pcmcia layer maps/unmaps mem regions */
187static int at91_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map)
188{
189 struct at91_cf_socket *cf;
190
191 if (map->card_start)
192 return -EINVAL;
193
194 cf = container_of(s, struct at91_cf_socket, socket);
195
196 map->flags &= MAP_ACTIVE|MAP_ATTRIB|MAP_16BIT;
197 if (map->flags & MAP_ATTRIB)
198 map->static_start = CF_ATTR_PHYS;
199 else
200 map->static_start = CF_MEM_PHYS;
201
202 return 0;
203}
204
205static struct pccard_operations at91_cf_ops = {
206 .init = at91_cf_ss_init,
207 .suspend = at91_cf_ss_suspend,
208 .get_status = at91_cf_get_status,
209 .set_socket = at91_cf_set_socket,
210 .set_io_map = at91_cf_set_io_map,
211 .set_mem_map = at91_cf_set_mem_map,
212};
213
214/*--------------------------------------------------------------------------*/
215
216static int __init at91_cf_probe(struct device *dev)
217{
218 struct at91_cf_socket *cf;
219 struct at91_cf_data *board = dev->platform_data;
220 struct platform_device *pdev = to_platform_device(dev);
221 unsigned int csa;
222 int status;
223
224 if (!board || !board->det_pin || !board->rst_pin)
225 return -ENODEV;
226
227 cf = kcalloc(1, sizeof *cf, GFP_KERNEL);
228 if (!cf)
229 return -ENOMEM;
230
231 cf->board = board;
232 cf->pdev = pdev;
233 dev_set_drvdata(dev, cf);
234
235 /* CF takes over CS4, CS5, CS6 */
236 csa = at91_sys_read(AT91_EBI_CSA);
237 at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
238
239 /* force poweron defaults for these pins ... */
240 (void) at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
241 (void) at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
242 (void) at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
243 (void) at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
244
245 /* nWAIT is _not_ a default setting */
246 (void) at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
247
248 /*
249 * Static memory controller timing adjustments.
250 * REVISIT: these timings are in terms of MCK cycles, so
251 * when MCK changes (cpufreq etc) so must these values...
252 */
253 at91_sys_write(AT91_SMC_CSR(4), AT91_SMC_ACSS_STD | AT91_SMC_DBW_16 | AT91_SMC_BAT | AT91_SMC_WSEN
254 | AT91_SMC_NWS_(32) /* wait states */
255 | AT91_SMC_RWSETUP_(6) /* setup time */
256 | AT91_SMC_RWHOLD_(4) /* hold time */
257 );
258
259 /* must be a GPIO; ergo must trigger on both edges */
260 status = request_irq(board->det_pin, at91_cf_irq,
261 SA_SAMPLE_RANDOM, driver_name, cf);
262 if (status < 0)
263 goto fail0;
264
265 /*
266 * The card driver will request this irq later as needed.
267 * but it causes lots of "irqNN: nobody cared" messages
268 * unless we report that we handle everything (sigh).
269 * (Note: DK board doesn't wire the IRQ pin...)
270 */
271 if (board->irq_pin) {
272 status = request_irq(board->irq_pin, at91_cf_irq,
273 SA_SHIRQ, driver_name, cf);
274 if (status < 0)
275 goto fail0a;
276 cf->socket.pci_irq = board->irq_pin;
277 }
278 else
279 cf->socket.pci_irq = NR_IRQS + 1;
280
281 /* pcmcia layer only remaps "real" memory not iospace */
282 cf->socket.io_offset = (unsigned long) ioremap(CF_IO_PHYS, SZ_2K);
283 if (!cf->socket.io_offset)
284 goto fail1;
285
286 /* reserve CS4, CS5, and CS6 regions; but use just CS4 */
287 if (!request_mem_region(AT91_CF_BASE, CF_SIZE, driver_name))
288 goto fail1;
289
290 pr_info("%s: irqs det #%d, io #%d\n", driver_name,
291 board->det_pin, board->irq_pin);
292
293 cf->socket.owner = THIS_MODULE;
294 cf->socket.dev.dev = dev;
295 cf->socket.ops = &at91_cf_ops;
296 cf->socket.resource_ops = &pccard_static_ops;
297 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
298 | SS_CAP_MEM_ALIGN;
299 cf->socket.map_size = SZ_2K;
300 cf->socket.io[0].NumPorts = SZ_2K;
301
302 status = pcmcia_register_socket(&cf->socket);
303 if (status < 0)
304 goto fail2;
305
306 return 0;
307
308fail2:
309 iounmap((void __iomem *) cf->socket.io_offset);
310 release_mem_region(AT91_CF_BASE, CF_SIZE);
311fail1:
312 if (board->irq_pin)
313 free_irq(board->irq_pin, cf);
314fail0a:
315 free_irq(board->det_pin, cf);
316fail0:
317 at91_sys_write(AT91_EBI_CSA, csa);
318 kfree(cf);
319 return status;
320}
321
322static int __exit at91_cf_remove(struct device *dev)
323{
324 struct at91_cf_socket *cf = dev_get_drvdata(dev);
325 unsigned int csa;
326
327 pcmcia_unregister_socket(&cf->socket);
328 free_irq(cf->board->irq_pin, cf);
329 free_irq(cf->board->det_pin, cf);
330 iounmap((void __iomem *) cf->socket.io_offset);
331 release_mem_region(AT91_CF_BASE, CF_SIZE);
332
333 csa = at91_sys_read(AT91_EBI_CSA);
334 at91_sys_write(AT91_EBI_CSA, csa & ~AT91_EBI_CS4A);
335
336 kfree(cf);
337 return 0;
338}
339
340static struct device_driver at91_cf_driver = {
341 .name = (char *) driver_name,
342 .bus = &platform_bus_type,
343 .probe = at91_cf_probe,
344 .remove = __exit_p(at91_cf_remove),
345 .suspend = pcmcia_socket_dev_suspend,
346 .resume = pcmcia_socket_dev_resume,
347};
348
349/*--------------------------------------------------------------------------*/
350
351static int __init at91_cf_init(void)
352{
353 return driver_register(&at91_cf_driver);
354}
355module_init(at91_cf_init);
356
357static void __exit at91_cf_exit(void)
358{
359 driver_unregister(&at91_cf_driver);
360}
361module_exit(at91_cf_exit);
362
363MODULE_DESCRIPTION("AT91 Compact Flash Driver");
364MODULE_AUTHOR("David Brownell");
365MODULE_LICENSE("GPL");
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 120fa8da6392..912c03e5eb0a 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -12,7 +12,6 @@
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 */ 13 */
14 14
15#include <linux/config.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/moduleparam.h> 16#include <linux/moduleparam.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 613f2f1fbfdd..3162998579c1 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -16,7 +16,6 @@
16#include <linux/moduleparam.h> 16#include <linux/moduleparam.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/config.h>
20#include <linux/string.h> 19#include <linux/string.h>
21#include <linux/major.h> 20#include <linux/major.h>
22#include <linux/errno.h> 21#include <linux/errno.h>
@@ -111,9 +110,9 @@ int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state)
111 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) { 110 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) {
112 if (socket->dev.dev != dev) 111 if (socket->dev.dev != dev)
113 continue; 112 continue;
114 down(&socket->skt_sem); 113 mutex_lock(&socket->skt_mutex);
115 socket_suspend(socket); 114 socket_suspend(socket);
116 up(&socket->skt_sem); 115 mutex_unlock(&socket->skt_mutex);
117 } 116 }
118 up_read(&pcmcia_socket_list_rwsem); 117 up_read(&pcmcia_socket_list_rwsem);
119 118
@@ -129,9 +128,9 @@ int pcmcia_socket_dev_resume(struct device *dev)
129 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) { 128 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) {
130 if (socket->dev.dev != dev) 129 if (socket->dev.dev != dev)
131 continue; 130 continue;
132 down(&socket->skt_sem); 131 mutex_lock(&socket->skt_mutex);
133 socket_resume(socket); 132 socket_resume(socket);
134 up(&socket->skt_sem); 133 mutex_unlock(&socket->skt_mutex);
135 } 134 }
136 up_read(&pcmcia_socket_list_rwsem); 135 up_read(&pcmcia_socket_list_rwsem);
137 136
@@ -237,7 +236,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
237 init_completion(&socket->socket_released); 236 init_completion(&socket->socket_released);
238 init_completion(&socket->thread_done); 237 init_completion(&socket->thread_done);
239 init_waitqueue_head(&socket->thread_wait); 238 init_waitqueue_head(&socket->thread_wait);
240 init_MUTEX(&socket->skt_sem); 239 mutex_init(&socket->skt_mutex);
241 spin_lock_init(&socket->thread_lock); 240 spin_lock_init(&socket->thread_lock);
242 241
243 ret = kernel_thread(pccardd, socket, CLONE_KERNEL); 242 ret = kernel_thread(pccardd, socket, CLONE_KERNEL);
@@ -406,8 +405,6 @@ static void socket_shutdown(struct pcmcia_socket *s)
406 cb_free(s); 405 cb_free(s);
407#endif 406#endif
408 s->functions = 0; 407 s->functions = 0;
409 kfree(s->config);
410 s->config = NULL;
411 408
412 s->ops->get_status(s, &status); 409 s->ops->get_status(s, &status);
413 if (status & SS_POWERON) { 410 if (status & SS_POWERON) {
@@ -664,7 +661,7 @@ static int pccardd(void *__skt)
664 spin_unlock_irqrestore(&skt->thread_lock, flags); 661 spin_unlock_irqrestore(&skt->thread_lock, flags);
665 662
666 if (events) { 663 if (events) {
667 down(&skt->skt_sem); 664 mutex_lock(&skt->skt_mutex);
668 if (events & SS_DETECT) 665 if (events & SS_DETECT)
669 socket_detect_change(skt); 666 socket_detect_change(skt);
670 if (events & SS_BATDEAD) 667 if (events & SS_BATDEAD)
@@ -673,7 +670,7 @@ static int pccardd(void *__skt)
673 send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); 670 send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW);
674 if (events & SS_READY) 671 if (events & SS_READY)
675 send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); 672 send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW);
676 up(&skt->skt_sem); 673 mutex_unlock(&skt->skt_mutex);
677 continue; 674 continue;
678 } 675 }
679 676
@@ -717,8 +714,8 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
717{ 714{
718 int ret = 0; 715 int ret = 0;
719 716
720 /* s->skt_sem also protects s->callback */ 717 /* s->skt_mutex also protects s->callback */
721 down(&s->skt_sem); 718 mutex_lock(&s->skt_mutex);
722 719
723 if (c) { 720 if (c) {
724 /* registration */ 721 /* registration */
@@ -734,7 +731,7 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
734 } else 731 } else
735 s->callback = NULL; 732 s->callback = NULL;
736 err: 733 err:
737 up(&s->skt_sem); 734 mutex_unlock(&s->skt_mutex);
738 735
739 return ret; 736 return ret;
740} 737}
@@ -752,7 +749,7 @@ int pccard_reset_card(struct pcmcia_socket *skt)
752 749
753 cs_dbg(skt, 1, "resetting socket\n"); 750 cs_dbg(skt, 1, "resetting socket\n");
754 751
755 down(&skt->skt_sem); 752 mutex_lock(&skt->skt_mutex);
756 do { 753 do {
757 if (!(skt->state & SOCKET_PRESENT)) { 754 if (!(skt->state & SOCKET_PRESENT)) {
758 ret = CS_NO_CARD; 755 ret = CS_NO_CARD;
@@ -781,7 +778,7 @@ int pccard_reset_card(struct pcmcia_socket *skt)
781 778
782 ret = CS_SUCCESS; 779 ret = CS_SUCCESS;
783 } while (0); 780 } while (0);
784 up(&skt->skt_sem); 781 mutex_unlock(&skt->skt_mutex);
785 782
786 return ret; 783 return ret;
787} /* reset_card */ 784} /* reset_card */
@@ -797,7 +794,7 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
797 794
798 cs_dbg(skt, 1, "suspending socket\n"); 795 cs_dbg(skt, 1, "suspending socket\n");
799 796
800 down(&skt->skt_sem); 797 mutex_lock(&skt->skt_mutex);
801 do { 798 do {
802 if (!(skt->state & SOCKET_PRESENT)) { 799 if (!(skt->state & SOCKET_PRESENT)) {
803 ret = CS_NO_CARD; 800 ret = CS_NO_CARD;
@@ -814,7 +811,7 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
814 } 811 }
815 ret = socket_suspend(skt); 812 ret = socket_suspend(skt);
816 } while (0); 813 } while (0);
817 up(&skt->skt_sem); 814 mutex_unlock(&skt->skt_mutex);
818 815
819 return ret; 816 return ret;
820} /* suspend_card */ 817} /* suspend_card */
@@ -827,7 +824,7 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
827 824
828 cs_dbg(skt, 1, "waking up socket\n"); 825 cs_dbg(skt, 1, "waking up socket\n");
829 826
830 down(&skt->skt_sem); 827 mutex_lock(&skt->skt_mutex);
831 do { 828 do {
832 if (!(skt->state & SOCKET_PRESENT)) { 829 if (!(skt->state & SOCKET_PRESENT)) {
833 ret = CS_NO_CARD; 830 ret = CS_NO_CARD;
@@ -841,7 +838,7 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
841 if (!ret && skt->callback) 838 if (!ret && skt->callback)
842 skt->callback->resume(skt); 839 skt->callback->resume(skt);
843 } while (0); 840 } while (0);
844 up(&skt->skt_sem); 841 mutex_unlock(&skt->skt_mutex);
845 842
846 return ret; 843 return ret;
847} /* resume_card */ 844} /* resume_card */
@@ -855,7 +852,7 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
855 852
856 cs_dbg(skt, 1, "user eject request\n"); 853 cs_dbg(skt, 1, "user eject request\n");
857 854
858 down(&skt->skt_sem); 855 mutex_lock(&skt->skt_mutex);
859 do { 856 do {
860 if (!(skt->state & SOCKET_PRESENT)) { 857 if (!(skt->state & SOCKET_PRESENT)) {
861 ret = -ENODEV; 858 ret = -ENODEV;
@@ -871,7 +868,7 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
871 socket_remove(skt); 868 socket_remove(skt);
872 ret = 0; 869 ret = 0;
873 } while (0); 870 } while (0);
874 up(&skt->skt_sem); 871 mutex_unlock(&skt->skt_mutex);
875 872
876 return ret; 873 return ret;
877} /* eject_card */ 874} /* eject_card */
@@ -884,7 +881,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
884 881
885 cs_dbg(skt, 1, "user insert request\n"); 882 cs_dbg(skt, 1, "user insert request\n");
886 883
887 down(&skt->skt_sem); 884 mutex_lock(&skt->skt_mutex);
888 do { 885 do {
889 if (skt->state & SOCKET_PRESENT) { 886 if (skt->state & SOCKET_PRESENT) {
890 ret = -EBUSY; 887 ret = -EBUSY;
@@ -896,7 +893,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
896 } 893 }
897 ret = 0; 894 ret = 0;
898 } while (0); 895 } while (0);
899 up(&skt->skt_sem); 896 mutex_unlock(&skt->skt_mutex);
900 897
901 return ret; 898 return ret;
902} /* insert_card */ 899} /* insert_card */
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 7b37eba35bf1..d6164cd583fd 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -15,7 +15,7 @@
15#ifndef _LINUX_CS_INTERNAL_H 15#ifndef _LINUX_CS_INTERNAL_H
16#define _LINUX_CS_INTERNAL_H 16#define _LINUX_CS_INTERNAL_H
17 17
18#include <linux/config.h> 18#include <linux/kref.h>
19 19
20/* Flags in client state */ 20/* Flags in client state */
21#define CLIENT_CONFIG_LOCKED 0x0001 21#define CLIENT_CONFIG_LOCKED 0x0001
@@ -23,7 +23,7 @@
23#define CLIENT_IO_REQ 0x0004 23#define CLIENT_IO_REQ 0x0004
24#define CLIENT_UNBOUND 0x0008 24#define CLIENT_UNBOUND 0x0008
25#define CLIENT_STALE 0x0010 25#define CLIENT_STALE 0x0010
26#define CLIENT_WIN_REQ(i) (0x20<<(i)) 26#define CLIENT_WIN_REQ(i) (0x1<<(i))
27#define CLIENT_CARDBUS 0x8000 27#define CLIENT_CARDBUS 0x8000
28 28
29#define REGION_MAGIC 0xE3C9 29#define REGION_MAGIC 0xE3C9
@@ -31,7 +31,7 @@ typedef struct region_t {
31 u_short region_magic; 31 u_short region_magic;
32 u_short state; 32 u_short state;
33 dev_info_t dev_info; 33 dev_info_t dev_info;
34 client_handle_t mtd; 34 struct pcmcia_device *mtd;
35 u_int MediaID; 35 u_int MediaID;
36 region_info_t info; 36 region_info_t info;
37} region_t; 37} region_t;
@@ -40,12 +40,12 @@ typedef struct region_t {
40 40
41/* Each card function gets one of these guys */ 41/* Each card function gets one of these guys */
42typedef struct config_t { 42typedef struct config_t {
43 struct kref ref;
43 u_int state; 44 u_int state;
44 u_int Attributes; 45 u_int Attributes;
45 u_int IntType; 46 u_int IntType;
46 u_int ConfigBase; 47 u_int ConfigBase;
47 u_char Status, Pin, Copy, Option, ExtStatus; 48 u_char Status, Pin, Copy, Option, ExtStatus;
48 u_int Present;
49 u_int CardValues; 49 u_int CardValues;
50 io_req_t io; 50 io_req_t io;
51 struct { 51 struct {
@@ -95,12 +95,6 @@ static inline void cs_socket_put(struct pcmcia_socket *skt)
95 } 95 }
96} 96}
97 97
98#define CHECK_SOCKET(s) \
99 (((s) >= sockets) || (socket_table[s]->ops == NULL))
100
101#define SOCKET(h) (h->socket)
102#define CONFIG(h) (&SOCKET(h)->config[(h)->func])
103
104/* In cardbus.c */ 98/* In cardbus.c */
105int cb_alloc(struct pcmcia_socket *s); 99int cb_alloc(struct pcmcia_socket *s);
106void cb_free(struct pcmcia_socket *s); 100void cb_free(struct pcmcia_socket *s);
@@ -133,10 +127,9 @@ extern struct class_interface pccard_sysfs_interface;
133extern struct rw_semaphore pcmcia_socket_list_rwsem; 127extern struct rw_semaphore pcmcia_socket_list_rwsem;
134extern struct list_head pcmcia_socket_list; 128extern struct list_head pcmcia_socket_list;
135int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req); 129int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
136int pccard_get_configuration_info(struct pcmcia_socket *s, unsigned int function, config_info_t *config); 130int pccard_get_configuration_info(struct pcmcia_socket *s, struct pcmcia_device *p_dev, config_info_t *config);
137int pccard_reset_card(struct pcmcia_socket *skt); 131int pccard_reset_card(struct pcmcia_socket *skt);
138int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status); 132int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev, cs_status_t *status);
139int pccard_access_configuration_register(struct pcmcia_socket *s, unsigned int function, conf_reg_t *reg);
140 133
141 134
142struct pcmcia_callback{ 135struct pcmcia_callback{
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index bb96ce1db08c..ae10d1eed65e 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -10,10 +10,9 @@
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 * 11 *
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2005 Dominik Brodowski 13 * (C) 2003 - 2006 Dominik Brodowski
14 */ 14 */
15 15
16#include <linux/config.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/init.h> 18#include <linux/init.h>
@@ -23,6 +22,7 @@
23#include <linux/workqueue.h> 22#include <linux/workqueue.h>
24#include <linux/crc32.h> 23#include <linux/crc32.h>
25#include <linux/firmware.h> 24#include <linux/firmware.h>
25#include <linux/kref.h>
26 26
27#define IN_CARD_SERVICES 27#define IN_CARD_SERVICES
28#include <pcmcia/cs_types.h> 28#include <pcmcia/cs_types.h>
@@ -343,12 +343,19 @@ void pcmcia_put_dev(struct pcmcia_device *p_dev)
343 put_device(&p_dev->dev); 343 put_device(&p_dev->dev);
344} 344}
345 345
346static void pcmcia_release_function(struct kref *ref)
347{
348 struct config_t *c = container_of(ref, struct config_t, ref);
349 kfree(c);
350}
351
346static void pcmcia_release_dev(struct device *dev) 352static void pcmcia_release_dev(struct device *dev)
347{ 353{
348 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 354 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
349 ds_dbg(1, "releasing dev %p\n", p_dev); 355 ds_dbg(1, "releasing dev %p\n", p_dev);
350 pcmcia_put_socket(p_dev->socket); 356 pcmcia_put_socket(p_dev->socket);
351 kfree(p_dev->devname); 357 kfree(p_dev->devname);
358 kref_put(&p_dev->function_config->ref, pcmcia_release_function);
352 kfree(p_dev); 359 kfree(p_dev);
353} 360}
354 361
@@ -377,29 +384,12 @@ static int pcmcia_device_probe(struct device * dev)
377 p_drv = to_pcmcia_drv(dev->driver); 384 p_drv = to_pcmcia_drv(dev->driver);
378 s = p_dev->socket; 385 s = p_dev->socket;
379 386
380 if ((!p_drv->probe) || (!try_module_get(p_drv->owner))) { 387 if ((!p_drv->probe) || (!p_dev->function_config) ||
388 (!try_module_get(p_drv->owner))) {
381 ret = -EINVAL; 389 ret = -EINVAL;
382 goto put_dev; 390 goto put_dev;
383 } 391 }
384 392
385 p_dev->state &= ~CLIENT_UNBOUND;
386
387 /* set up the device configuration, if it hasn't been done before */
388 if (!s->functions) {
389 cistpl_longlink_mfc_t mfc;
390 if (pccard_read_tuple(s, p_dev->func, CISTPL_LONGLINK_MFC,
391 &mfc) == CS_SUCCESS)
392 s->functions = mfc.nfn;
393 else
394 s->functions = 1;
395 s->config = kzalloc(sizeof(config_t) * s->functions,
396 GFP_KERNEL);
397 if (!s->config) {
398 ret = -ENOMEM;
399 goto put_module;
400 }
401 }
402
403 ret = p_drv->probe(p_dev); 393 ret = p_drv->probe(p_dev);
404 if (ret) 394 if (ret)
405 goto put_module; 395 goto put_module;
@@ -425,15 +415,61 @@ static int pcmcia_device_probe(struct device * dev)
425} 415}
426 416
427 417
418/*
419 * Removes a PCMCIA card from the device tree and socket list.
420 */
421static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *leftover)
422{
423 struct pcmcia_device *p_dev;
424 struct pcmcia_device *tmp;
425 unsigned long flags;
426
427 ds_dbg(2, "unbind_request(%d)\n", s->sock);
428
429
430 if (!leftover)
431 s->device_count = 0;
432 else
433 s->device_count = 1;
434
435 /* unregister all pcmcia_devices registered with this socket, except leftover */
436 list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) {
437 if (p_dev == leftover)
438 continue;
439
440 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
441 list_del(&p_dev->socket_device_list);
442 p_dev->_removed=1;
443 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
444
445 device_unregister(&p_dev->dev);
446 }
447
448 return;
449}
450
451
428static int pcmcia_device_remove(struct device * dev) 452static int pcmcia_device_remove(struct device * dev)
429{ 453{
430 struct pcmcia_device *p_dev; 454 struct pcmcia_device *p_dev;
431 struct pcmcia_driver *p_drv; 455 struct pcmcia_driver *p_drv;
456 struct pcmcia_device_id *did;
432 int i; 457 int i;
433 458
434 /* detach the "instance" */
435 p_dev = to_pcmcia_dev(dev); 459 p_dev = to_pcmcia_dev(dev);
436 p_drv = to_pcmcia_drv(dev->driver); 460 p_drv = to_pcmcia_drv(dev->driver);
461
462 /* If we're removing the primary module driving a
463 * pseudo multi-function card, we need to unbind
464 * all devices
465 */
466 did = (struct pcmcia_device_id *) p_dev->dev.driver_data;
467 if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) &&
468 (p_dev->socket->device_count != 0) &&
469 (p_dev->device_no == 0))
470 pcmcia_card_remove(p_dev->socket, p_dev);
471
472 /* detach the "instance" */
437 if (!p_drv) 473 if (!p_drv)
438 return 0; 474 return 0;
439 475
@@ -441,17 +477,16 @@ static int pcmcia_device_remove(struct device * dev)
441 p_drv->remove(p_dev); 477 p_drv->remove(p_dev);
442 478
443 /* check for proper unloading */ 479 /* check for proper unloading */
444 if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED)) 480 if (p_dev->_irq || p_dev->_io || p_dev->_locked)
445 printk(KERN_INFO "pcmcia: driver %s did not release config properly\n", 481 printk(KERN_INFO "pcmcia: driver %s did not release config properly\n",
446 p_drv->drv.name); 482 p_drv->drv.name);
447 483
448 for (i = 0; i < MAX_WIN; i++) 484 for (i = 0; i < MAX_WIN; i++)
449 if (p_dev->state & CLIENT_WIN_REQ(i)) 485 if (p_dev->_win & CLIENT_WIN_REQ(i))
450 printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n", 486 printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n",
451 p_drv->drv.name); 487 p_drv->drv.name);
452 488
453 /* references from pcmcia_probe_device */ 489 /* references from pcmcia_probe_device */
454 p_dev->state = CLIENT_UNBOUND;
455 pcmcia_put_dev(p_dev); 490 pcmcia_put_dev(p_dev);
456 module_put(p_drv->owner); 491 module_put(p_drv->owner);
457 492
@@ -460,37 +495,6 @@ static int pcmcia_device_remove(struct device * dev)
460 495
461 496
462/* 497/*
463 * Removes a PCMCIA card from the device tree and socket list.
464 */
465static void pcmcia_card_remove(struct pcmcia_socket *s)
466{
467 struct pcmcia_device *p_dev;
468 unsigned long flags;
469
470 ds_dbg(2, "unbind_request(%d)\n", s->sock);
471
472 s->device_count = 0;
473
474 for (;;) {
475 /* unregister all pcmcia_devices registered with this socket*/
476 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
477 if (list_empty(&s->devices_list)) {
478 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
479 return;
480 }
481 p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list);
482 list_del(&p_dev->socket_device_list);
483 p_dev->state |= CLIENT_STALE;
484 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
485
486 device_unregister(&p_dev->dev);
487 }
488
489 return;
490} /* unbind_request */
491
492
493/*
494 * pcmcia_device_query -- determine information about a pcmcia device 498 * pcmcia_device_query -- determine information about a pcmcia device
495 */ 499 */
496static int pcmcia_device_query(struct pcmcia_device *p_dev) 500static int pcmcia_device_query(struct pcmcia_device *p_dev)
@@ -546,7 +550,7 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
546 tmp = vers1->str + vers1->ofs[i]; 550 tmp = vers1->str + vers1->ofs[i];
547 551
548 length = strlen(tmp) + 1; 552 length = strlen(tmp) + 1;
549 if ((length < 3) || (length > 255)) 553 if ((length < 2) || (length > 255))
550 continue; 554 continue;
551 555
552 p_dev->prod_id[i] = kmalloc(sizeof(char) * length, 556 p_dev->prod_id[i] = kmalloc(sizeof(char) * length,
@@ -571,11 +575,11 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
571 * won't work, this doesn't matter much at the moment: the driver core doesn't 575 * won't work, this doesn't matter much at the moment: the driver core doesn't
572 * support it either. 576 * support it either.
573 */ 577 */
574static DECLARE_MUTEX(device_add_lock); 578static DEFINE_MUTEX(device_add_lock);
575 579
576struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) 580struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
577{ 581{
578 struct pcmcia_device *p_dev; 582 struct pcmcia_device *p_dev, *tmp_dev;
579 unsigned long flags; 583 unsigned long flags;
580 int bus_id_len; 584 int bus_id_len;
581 585
@@ -583,7 +587,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
583 if (!s) 587 if (!s)
584 return NULL; 588 return NULL;
585 589
586 down(&device_add_lock); 590 mutex_lock(&device_add_lock);
587 591
588 /* max of 2 devices per card */ 592 /* max of 2 devices per card */
589 if (s->device_count == 2) 593 if (s->device_count == 2)
@@ -596,6 +600,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
596 p_dev->socket = s; 600 p_dev->socket = s;
597 p_dev->device_no = (s->device_count++); 601 p_dev->device_no = (s->device_count++);
598 p_dev->func = function; 602 p_dev->func = function;
603 if (s->functions <= function)
604 s->functions = function + 1;
599 605
600 p_dev->dev.bus = &pcmcia_bus_type; 606 p_dev->dev.bus = &pcmcia_bus_type;
601 p_dev->dev.parent = s->dev.dev; 607 p_dev->dev.parent = s->dev.dev;
@@ -608,36 +614,55 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
608 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id); 614 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
609 615
610 /* compat */ 616 /* compat */
611 p_dev->state = CLIENT_UNBOUND; 617 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
618
619 /*
620 * p_dev->function_config must be the same for all card functions.
621 * Note that this is serialized by the device_add_lock, so that
622 * only one such struct will be created.
623 */
624 list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list)
625 if (p_dev->func == tmp_dev->func) {
626 p_dev->function_config = tmp_dev->function_config;
627 kref_get(&p_dev->function_config->ref);
628 }
612 629
613 /* Add to the list in pcmcia_bus_socket */ 630 /* Add to the list in pcmcia_bus_socket */
614 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
615 list_add_tail(&p_dev->socket_device_list, &s->devices_list); 631 list_add_tail(&p_dev->socket_device_list, &s->devices_list);
632
616 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 633 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
617 634
635 if (!p_dev->function_config) {
636 p_dev->function_config = kzalloc(sizeof(struct config_t),
637 GFP_KERNEL);
638 if (!p_dev->function_config)
639 goto err_unreg;
640 kref_init(&p_dev->function_config->ref);
641 }
642
618 printk(KERN_NOTICE "pcmcia: registering new device %s\n", 643 printk(KERN_NOTICE "pcmcia: registering new device %s\n",
619 p_dev->devname); 644 p_dev->devname);
620 645
621 pcmcia_device_query(p_dev); 646 pcmcia_device_query(p_dev);
622 647
623 if (device_register(&p_dev->dev)) { 648 if (device_register(&p_dev->dev))
624 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 649 goto err_unreg;
625 list_del(&p_dev->socket_device_list);
626 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
627
628 goto err_free;
629 }
630 650
631 up(&device_add_lock); 651 mutex_unlock(&device_add_lock);
632 652
633 return p_dev; 653 return p_dev;
634 654
655 err_unreg:
656 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
657 list_del(&p_dev->socket_device_list);
658 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
659
635 err_free: 660 err_free:
636 kfree(p_dev->devname); 661 kfree(p_dev->devname);
637 kfree(p_dev); 662 kfree(p_dev);
638 s->device_count--; 663 s->device_count--;
639 err_put: 664 err_put:
640 up(&device_add_lock); 665 mutex_unlock(&device_add_lock);
641 pcmcia_put_socket(s); 666 pcmcia_put_socket(s);
642 667
643 return NULL; 668 return NULL;
@@ -696,7 +721,7 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
696 int no_devices=0; 721 int no_devices=0;
697 unsigned long flags; 722 unsigned long flags;
698 723
699 /* must be called with skt_sem held */ 724 /* must be called with skt_mutex held */
700 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 725 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
701 if (list_empty(&skt->devices_list)) 726 if (list_empty(&skt->devices_list))
702 no_devices=1; 727 no_devices=1;
@@ -819,9 +844,11 @@ static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
819 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv); 844 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv);
820 struct pcmcia_device_id *did = p_drv->id_table; 845 struct pcmcia_device_id *did = p_drv->id_table;
821 846
847#ifdef CONFIG_PCMCIA_IOCTL
822 /* matching by cardmgr */ 848 /* matching by cardmgr */
823 if (p_dev->cardmgr == p_drv) 849 if (p_dev->cardmgr == p_drv)
824 return 1; 850 return 1;
851#endif
825 852
826 while (did && did->match_flags) { 853 while (did && did->match_flags) {
827 if (pcmcia_devmatch(p_dev, did)) 854 if (pcmcia_devmatch(p_dev, did))
@@ -927,7 +954,7 @@ static ssize_t pcmcia_show_pm_state(struct device *dev, struct device_attribute
927{ 954{
928 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 955 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
929 956
930 if (p_dev->dev.power.power_state.event != PM_EVENT_ON) 957 if (p_dev->suspended)
931 return sprintf(buf, "off\n"); 958 return sprintf(buf, "off\n");
932 else 959 else
933 return sprintf(buf, "on\n"); 960 return sprintf(buf, "on\n");
@@ -942,11 +969,9 @@ static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute
942 if (!count) 969 if (!count)
943 return -EINVAL; 970 return -EINVAL;
944 971
945 if ((p_dev->dev.power.power_state.event == PM_EVENT_ON) && 972 if ((!p_dev->suspended) && !strncmp(buf, "off", 3))
946 (!strncmp(buf, "off", 3)))
947 ret = dpm_runtime_suspend(dev, PMSG_SUSPEND); 973 ret = dpm_runtime_suspend(dev, PMSG_SUSPEND);
948 else if ((p_dev->dev.power.power_state.event != PM_EVENT_ON) && 974 else if (p_dev->suspended && !strncmp(buf, "on", 2))
949 (!strncmp(buf, "on", 2)))
950 dpm_runtime_resume(dev); 975 dpm_runtime_resume(dev);
951 976
952 return ret ? ret : count; 977 return ret ? ret : count;
@@ -982,9 +1007,9 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
982 if (!count) 1007 if (!count)
983 return -EINVAL; 1008 return -EINVAL;
984 1009
985 down(&p_dev->socket->skt_sem); 1010 mutex_lock(&p_dev->socket->skt_mutex);
986 p_dev->allow_func_id_match = 1; 1011 p_dev->allow_func_id_match = 1;
987 up(&p_dev->socket->skt_sem); 1012 mutex_unlock(&p_dev->socket->skt_mutex);
988 1013
989 bus_rescan_devices(&pcmcia_bus_type); 1014 bus_rescan_devices(&pcmcia_bus_type);
990 1015
@@ -1012,14 +1037,27 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
1012{ 1037{
1013 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 1038 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
1014 struct pcmcia_driver *p_drv = NULL; 1039 struct pcmcia_driver *p_drv = NULL;
1040 int ret = 0;
1015 1041
1016 if (dev->driver) 1042 if (dev->driver)
1017 p_drv = to_pcmcia_drv(dev->driver); 1043 p_drv = to_pcmcia_drv(dev->driver);
1018 1044
1019 if (p_drv && p_drv->suspend) 1045 if (!p_drv)
1020 return p_drv->suspend(p_dev); 1046 goto out;
1021 1047
1022 return 0; 1048 if (p_drv->suspend) {
1049 ret = p_drv->suspend(p_dev);
1050 if (ret)
1051 goto out;
1052 }
1053
1054 if (p_dev->device_no == p_dev->func)
1055 pcmcia_release_configuration(p_dev);
1056
1057 out:
1058 if (!ret)
1059 p_dev->suspended = 1;
1060 return ret;
1023} 1061}
1024 1062
1025 1063
@@ -1027,14 +1065,27 @@ static int pcmcia_dev_resume(struct device * dev)
1027{ 1065{
1028 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 1066 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
1029 struct pcmcia_driver *p_drv = NULL; 1067 struct pcmcia_driver *p_drv = NULL;
1068 int ret = 0;
1030 1069
1031 if (dev->driver) 1070 if (dev->driver)
1032 p_drv = to_pcmcia_drv(dev->driver); 1071 p_drv = to_pcmcia_drv(dev->driver);
1033 1072
1034 if (p_drv && p_drv->resume) 1073 if (!p_drv)
1035 return p_drv->resume(p_dev); 1074 goto out;
1036 1075
1037 return 0; 1076 if (p_dev->device_no == p_dev->func) {
1077 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
1078 if (ret)
1079 goto out;
1080 }
1081
1082 if (p_drv->resume)
1083 ret = p_drv->resume(p_dev);
1084
1085 out:
1086 if (!ret)
1087 p_dev->suspended = 0;
1088 return ret;
1038} 1089}
1039 1090
1040 1091
@@ -1100,7 +1151,7 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
1100 switch (event) { 1151 switch (event) {
1101 case CS_EVENT_CARD_REMOVAL: 1152 case CS_EVENT_CARD_REMOVAL:
1102 s->pcmcia_state.present = 0; 1153 s->pcmcia_state.present = 0;
1103 pcmcia_card_remove(skt); 1154 pcmcia_card_remove(skt, NULL);
1104 handle_event(skt, event); 1155 handle_event(skt, event);
1105 break; 1156 break;
1106 1157
@@ -1128,6 +1179,32 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
1128} /* ds_event */ 1179} /* ds_event */
1129 1180
1130 1181
1182struct pcmcia_device * pcmcia_dev_present(struct pcmcia_device *_p_dev)
1183{
1184 struct pcmcia_device *p_dev;
1185 struct pcmcia_device *ret = NULL;
1186
1187 p_dev = pcmcia_get_dev(_p_dev);
1188 if (!p_dev)
1189 return NULL;
1190
1191 if (!p_dev->socket->pcmcia_state.present)
1192 goto out;
1193
1194 if (p_dev->_removed)
1195 goto out;
1196
1197 if (p_dev->suspended)
1198 goto out;
1199
1200 ret = p_dev;
1201 out:
1202 pcmcia_put_dev(p_dev);
1203 return ret;
1204}
1205EXPORT_SYMBOL(pcmcia_dev_present);
1206
1207
1131static struct pcmcia_callback pcmcia_bus_callback = { 1208static struct pcmcia_callback pcmcia_bus_callback = {
1132 .owner = THIS_MODULE, 1209 .owner = THIS_MODULE,
1133 .event = ds_event, 1210 .event = ds_event,
diff --git a/drivers/pcmcia/ds_internal.h b/drivers/pcmcia/ds_internal.h
index d359bd25a51c..3a2b25e6ed73 100644
--- a/drivers/pcmcia/ds_internal.h
+++ b/drivers/pcmcia/ds_internal.h
@@ -8,6 +8,8 @@ extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
8 8
9struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function); 9struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function);
10 10
11extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
12
11#ifdef CONFIG_PCMCIA_IOCTL 13#ifdef CONFIG_PCMCIA_IOCTL
12extern void __init pcmcia_setup_ioctl(void); 14extern void __init pcmcia_setup_ioctl(void);
13extern void __exit pcmcia_cleanup_ioctl(void); 15extern void __exit pcmcia_cleanup_ioctl(void);
@@ -15,7 +17,7 @@ extern void handle_event(struct pcmcia_socket *s, event_t event);
15extern int handle_request(struct pcmcia_socket *s, event_t event); 17extern int handle_request(struct pcmcia_socket *s, event_t event);
16#else 18#else
17static inline void __init pcmcia_setup_ioctl(void) { return; } 19static inline void __init pcmcia_setup_ioctl(void) { return; }
18static inline void __init pcmcia_cleanup_ioctl(void) { return; } 20static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
19static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; } 21static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; }
20static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; } 22static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; }
21#endif 23#endif
diff --git a/drivers/pcmcia/i82092.c b/drivers/pcmcia/i82092.c
index 7979c85df3dc..d5f03a338c6c 100644
--- a/drivers/pcmcia/i82092.c
+++ b/drivers/pcmcia/i82092.c
@@ -10,7 +10,6 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/config.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/pci.h> 14#include <linux/pci.h>
16#include <linux/init.h> 15#include <linux/init.h>
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index 35a92d1e4945..bd0308e89815 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -34,7 +34,6 @@
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/config.h>
38#include <linux/types.h> 37#include <linux/types.h>
39#include <linux/fcntl.h> 38#include <linux/fcntl.h>
40#include <linux/string.h> 39#include <linux/string.h>
diff --git a/drivers/pcmcia/pcmcia_compat.c b/drivers/pcmcia/pcmcia_compat.c
deleted file mode 100644
index ebb161c4f819..000000000000
--- a/drivers/pcmcia/pcmcia_compat.c
+++ /dev/null
@@ -1,65 +0,0 @@
1/*
2 * PCMCIA 16-bit compatibility functions
3 *
4 * The initial developer of the original code is David A. Hinds
5 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
7 *
8 * Copyright (C) 2004 Dominik Brodowski
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/config.h>
17#include <linux/module.h>
18#include <linux/init.h>
19
20#define IN_CARD_SERVICES
21#include <pcmcia/cs_types.h>
22#include <pcmcia/cs.h>
23#include <pcmcia/bulkmem.h>
24#include <pcmcia/cistpl.h>
25#include <pcmcia/ds.h>
26#include <pcmcia/ss.h>
27
28#include "cs_internal.h"
29
30int pcmcia_get_first_tuple(struct pcmcia_device *p_dev, tuple_t *tuple)
31{
32 return pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple);
33}
34EXPORT_SYMBOL(pcmcia_get_first_tuple);
35
36int pcmcia_get_next_tuple(struct pcmcia_device *p_dev, tuple_t *tuple)
37{
38 return pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple);
39}
40EXPORT_SYMBOL(pcmcia_get_next_tuple);
41
42int pcmcia_get_tuple_data(struct pcmcia_device *p_dev, tuple_t *tuple)
43{
44 return pccard_get_tuple_data(p_dev->socket, tuple);
45}
46EXPORT_SYMBOL(pcmcia_get_tuple_data);
47
48int pcmcia_parse_tuple(struct pcmcia_device *p_dev, tuple_t *tuple, cisparse_t *parse)
49{
50 return pccard_parse_tuple(tuple, parse);
51}
52EXPORT_SYMBOL(pcmcia_parse_tuple);
53
54int pcmcia_validate_cis(struct pcmcia_device *p_dev, cisinfo_t *info)
55{
56 return pccard_validate_cis(p_dev->socket, p_dev->func, info);
57}
58EXPORT_SYMBOL(pcmcia_validate_cis);
59
60
61int pcmcia_reset_card(struct pcmcia_device *p_dev, client_req_t *req)
62{
63 return pccard_reset_card(p_dev->socket);
64}
65EXPORT_SYMBOL(pcmcia_reset_card);
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index 80969f7e7a0b..c53db7ceda5e 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -18,7 +18,6 @@
18 */ 18 */
19 19
20 20
21#include <linux/config.h>
22#include <linux/kernel.h> 21#include <linux/kernel.h>
23#include <linux/module.h> 22#include <linux/module.h>
24#include <linux/init.h> 23#include <linux/init.h>
@@ -70,10 +69,26 @@ extern int ds_pc_debug;
70#define ds_dbg(lvl, fmt, arg...) do { } while (0) 69#define ds_dbg(lvl, fmt, arg...) do { } while (0)
71#endif 70#endif
72 71
72static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s,
73 unsigned int function)
74{
75 struct pcmcia_device *p_dev = NULL;
76 unsigned long flags;
77
78 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
79 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
80 if (p_dev->func == function) {
81 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
82 return pcmcia_get_dev(p_dev);
83 }
84 }
85 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
86 return NULL;
87}
73 88
74/* backwards-compatible accessing of driver --- by name! */ 89/* backwards-compatible accessing of driver --- by name! */
75 90
76static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info) 91static struct pcmcia_driver *get_pcmcia_driver(dev_info_t *dev_info)
77{ 92{
78 struct device_driver *drv; 93 struct device_driver *drv;
79 struct pcmcia_driver *p_drv; 94 struct pcmcia_driver *p_drv;
@@ -214,7 +229,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
214 * by userspace before, we need to 229 * by userspace before, we need to
215 * return the "instance". */ 230 * return the "instance". */
216 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 231 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
217 bind_info->instance = p_dev->instance; 232 bind_info->instance = p_dev;
218 ret = -EBUSY; 233 ret = -EBUSY;
219 goto err_put_module; 234 goto err_put_module;
220 } else { 235 } else {
@@ -253,9 +268,9 @@ rescan:
253 /* 268 /*
254 * Prevent this racing with a card insertion. 269 * Prevent this racing with a card insertion.
255 */ 270 */
256 down(&s->skt_sem); 271 mutex_lock(&s->skt_mutex);
257 bus_rescan_devices(&pcmcia_bus_type); 272 bus_rescan_devices(&pcmcia_bus_type);
258 up(&s->skt_sem); 273 mutex_unlock(&s->skt_mutex);
259 274
260 /* check whether the driver indeed matched. I don't care if this 275 /* check whether the driver indeed matched. I don't care if this
261 * is racy or not, because it can only happen on cardmgr access 276 * is racy or not, because it can only happen on cardmgr access
@@ -289,6 +304,7 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
289{ 304{
290 dev_node_t *node; 305 dev_node_t *node;
291 struct pcmcia_device *p_dev; 306 struct pcmcia_device *p_dev;
307 struct pcmcia_driver *p_drv;
292 unsigned long flags; 308 unsigned long flags;
293 int ret = 0; 309 int ret = 0;
294 310
@@ -343,16 +359,16 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
343 found: 359 found:
344 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 360 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
345 361
346 if ((!p_dev->instance) || 362 p_drv = to_pcmcia_drv(p_dev->dev.driver);
347 (p_dev->instance->state & DEV_CONFIG_PENDING)) { 363 if (p_drv && !p_dev->_locked) {
348 ret = -EAGAIN; 364 ret = -EAGAIN;
349 goto err_put; 365 goto err_put;
350 } 366 }
351 367
352 if (first) 368 if (first)
353 node = p_dev->instance->dev; 369 node = p_dev->dev_node;
354 else 370 else
355 for (node = p_dev->instance->dev; node; node = node->next) 371 for (node = p_dev->dev_node; node; node = node->next)
356 if (node == bind_info->next) 372 if (node == bind_info->next)
357 break; 373 break;
358 if (!node) { 374 if (!node) {
@@ -583,14 +599,16 @@ static int ds_ioctl(struct inode * inode, struct file * file,
583 if (buf->config.Function && 599 if (buf->config.Function &&
584 (buf->config.Function >= s->functions)) 600 (buf->config.Function >= s->functions))
585 ret = CS_BAD_ARGS; 601 ret = CS_BAD_ARGS;
586 else 602 else {
587 ret = pccard_get_configuration_info(s, 603 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function);
588 buf->config.Function, &buf->config); 604 ret = pccard_get_configuration_info(s, p_dev, &buf->config);
605 pcmcia_put_dev(p_dev);
606 }
589 break; 607 break;
590 case DS_GET_FIRST_TUPLE: 608 case DS_GET_FIRST_TUPLE:
591 down(&s->skt_sem); 609 mutex_lock(&s->skt_mutex);
592 pcmcia_validate_mem(s); 610 pcmcia_validate_mem(s);
593 up(&s->skt_sem); 611 mutex_unlock(&s->skt_mutex);
594 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple); 612 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple);
595 break; 613 break;
596 case DS_GET_NEXT_TUPLE: 614 case DS_GET_NEXT_TUPLE:
@@ -609,16 +627,19 @@ static int ds_ioctl(struct inode * inode, struct file * file,
609 ret = pccard_reset_card(s); 627 ret = pccard_reset_card(s);
610 break; 628 break;
611 case DS_GET_STATUS: 629 case DS_GET_STATUS:
612 if (buf->status.Function && 630 if (buf->status.Function &&
613 (buf->status.Function >= s->functions)) 631 (buf->status.Function >= s->functions))
614 ret = CS_BAD_ARGS; 632 ret = CS_BAD_ARGS;
615 else 633 else {
616 ret = pccard_get_status(s, buf->status.Function, &buf->status); 634 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function);
617 break; 635 ret = pccard_get_status(s, p_dev, &buf->status);
636 pcmcia_put_dev(p_dev);
637 }
638 break;
618 case DS_VALIDATE_CIS: 639 case DS_VALIDATE_CIS:
619 down(&s->skt_sem); 640 mutex_lock(&s->skt_mutex);
620 pcmcia_validate_mem(s); 641 pcmcia_validate_mem(s);
621 up(&s->skt_sem); 642 mutex_unlock(&s->skt_mutex);
622 ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo); 643 ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo);
623 break; 644 break;
624 case DS_SUSPEND_CARD: 645 case DS_SUSPEND_CARD:
@@ -638,12 +659,16 @@ static int ds_ioctl(struct inode * inode, struct file * file,
638 err = -EPERM; 659 err = -EPERM;
639 goto free_out; 660 goto free_out;
640 } 661 }
641 if (buf->conf_reg.Function && 662
642 (buf->conf_reg.Function >= s->functions)) 663 ret = CS_BAD_ARGS;
643 ret = CS_BAD_ARGS; 664
644 else 665 if (!(buf->conf_reg.Function &&
645 ret = pccard_access_configuration_register(s, 666 (buf->conf_reg.Function >= s->functions))) {
646 buf->conf_reg.Function, &buf->conf_reg); 667 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->conf_reg.Function);
668 if (p_dev)
669 ret = pcmcia_access_configuration_register(p_dev, &buf->conf_reg);
670 pcmcia_put_dev(p_dev);
671 }
647 break; 672 break;
648 case DS_GET_FIRST_REGION: 673 case DS_GET_FIRST_REGION:
649 case DS_GET_NEXT_REGION: 674 case DS_GET_NEXT_REGION:
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index 89022ad5b520..45063b4e5b78 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -14,7 +14,6 @@
14 * 14 *
15 */ 15 */
16 16
17#include <linux/config.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/interrupt.h> 19#include <linux/interrupt.h>
@@ -89,7 +88,7 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
89 } 88 }
90 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) { 89 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
91 *base = s->io_offset | (*base & 0x0fff); 90 *base = s->io_offset | (*base & 0x0fff);
92 s->io[0].Attributes = attr; 91 s->io[0].res->flags = (s->io[0].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
93 return 0; 92 return 0;
94 } 93 }
95 /* Check for an already-allocated window that must conflict with 94 /* Check for an already-allocated window that must conflict with
@@ -97,38 +96,36 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
97 * potential conflicts, just the most obvious ones. 96 * potential conflicts, just the most obvious ones.
98 */ 97 */
99 for (i = 0; i < MAX_IO_WIN; i++) 98 for (i = 0; i < MAX_IO_WIN; i++)
100 if ((s->io[i].NumPorts != 0) && 99 if ((s->io[i].res) &&
101 ((s->io[i].BasePort & (align-1)) == *base)) 100 ((s->io[i].res->start & (align-1)) == *base))
102 return 1; 101 return 1;
103 for (i = 0; i < MAX_IO_WIN; i++) { 102 for (i = 0; i < MAX_IO_WIN; i++) {
104 if (s->io[i].NumPorts == 0) { 103 if (!s->io[i].res) {
105 s->io[i].res = pcmcia_find_io_region(*base, num, align, s); 104 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
106 if (s->io[i].res) { 105 if (s->io[i].res) {
107 s->io[i].Attributes = attr; 106 *base = s->io[i].res->start;
108 s->io[i].BasePort = *base = s->io[i].res->start; 107 s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
109 s->io[i].NumPorts = s->io[i].InUse = num; 108 s->io[i].InUse = num;
110 break; 109 break;
111 } else 110 } else
112 return 1; 111 return 1;
113 } else if (s->io[i].Attributes != attr) 112 } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
114 continue; 113 continue;
115 /* Try to extend top of window */ 114 /* Try to extend top of window */
116 try = s->io[i].BasePort + s->io[i].NumPorts; 115 try = s->io[i].res->end + 1;
117 if ((*base == 0) || (*base == try)) 116 if ((*base == 0) || (*base == try))
118 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start, 117 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
119 s->io[i].res->end + num, s) == 0) { 118 s->io[i].res->end + num, s) == 0) {
120 *base = try; 119 *base = try;
121 s->io[i].NumPorts += num;
122 s->io[i].InUse += num; 120 s->io[i].InUse += num;
123 break; 121 break;
124 } 122 }
125 /* Try to extend bottom of window */ 123 /* Try to extend bottom of window */
126 try = s->io[i].BasePort - num; 124 try = s->io[i].res->start - num;
127 if ((*base == 0) || (*base == try)) 125 if ((*base == 0) || (*base == try))
128 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num, 126 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
129 s->io[i].res->end, s) == 0) { 127 s->io[i].res->end, s) == 0) {
130 s->io[i].BasePort = *base = try; 128 *base = try;
131 s->io[i].NumPorts += num;
132 s->io[i].InUse += num; 129 s->io[i].InUse += num;
133 break; 130 break;
134 } 131 }
@@ -143,12 +140,13 @@ static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
143 int i; 140 int i;
144 141
145 for (i = 0; i < MAX_IO_WIN; i++) { 142 for (i = 0; i < MAX_IO_WIN; i++) {
146 if ((s->io[i].BasePort <= base) && 143 if (!s->io[i].res)
147 (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) { 144 continue;
145 if ((s->io[i].res->start <= base) &&
146 (s->io[i].res->end >= base+num-1)) {
148 s->io[i].InUse -= num; 147 s->io[i].InUse -= num;
149 /* Free the window if no one else is using it */ 148 /* Free the window if no one else is using it */
150 if (s->io[i].InUse == 0) { 149 if (s->io[i].InUse == 0) {
151 s->io[i].NumPorts = 0;
152 release_resource(s->io[i].res); 150 release_resource(s->io[i].res);
153 kfree(s->io[i].res); 151 kfree(s->io[i].res);
154 s->io[i].res = NULL; 152 s->io[i].res = NULL;
@@ -165,21 +163,19 @@ static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
165 * this and the tuple reading services. 163 * this and the tuple reading services.
166 */ 164 */
167 165
168int pccard_access_configuration_register(struct pcmcia_socket *s, 166int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
169 unsigned int function,
170 conf_reg_t *reg) 167 conf_reg_t *reg)
171{ 168{
169 struct pcmcia_socket *s;
172 config_t *c; 170 config_t *c;
173 int addr; 171 int addr;
174 u_char val; 172 u_char val;
175 173
176 if (!s || !s->config) 174 if (!p_dev || !p_dev->function_config)
177 return CS_NO_CARD; 175 return CS_NO_CARD;
178 176
179 c = &s->config[function]; 177 s = p_dev->socket;
180 178 c = p_dev->function_config;
181 if (c == NULL)
182 return CS_NO_CARD;
183 179
184 if (!(c->state & CONFIG_LOCKED)) 180 if (!(c->state & CONFIG_LOCKED))
185 return CS_CONFIGURATION_LOCKED; 181 return CS_CONFIGURATION_LOCKED;
@@ -200,20 +196,12 @@ int pccard_access_configuration_register(struct pcmcia_socket *s,
200 break; 196 break;
201 } 197 }
202 return CS_SUCCESS; 198 return CS_SUCCESS;
203} /* pccard_access_configuration_register */ 199} /* pcmcia_access_configuration_register */
204
205int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
206 conf_reg_t *reg)
207{
208 return pccard_access_configuration_register(p_dev->socket,
209 p_dev->func, reg);
210}
211EXPORT_SYMBOL(pcmcia_access_configuration_register); 200EXPORT_SYMBOL(pcmcia_access_configuration_register);
212 201
213 202
214
215int pccard_get_configuration_info(struct pcmcia_socket *s, 203int pccard_get_configuration_info(struct pcmcia_socket *s,
216 unsigned int function, 204 struct pcmcia_device *p_dev,
217 config_info_t *config) 205 config_info_t *config)
218{ 206{
219 config_t *c; 207 config_t *c;
@@ -221,7 +209,7 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
221 if (!(s->state & SOCKET_PRESENT)) 209 if (!(s->state & SOCKET_PRESENT))
222 return CS_NO_CARD; 210 return CS_NO_CARD;
223 211
224 config->Function = function; 212 config->Function = p_dev->func;
225 213
226#ifdef CONFIG_CARDBUS 214#ifdef CONFIG_CARDBUS
227 if (s->state & SOCKET_CARDBUS) { 215 if (s->state & SOCKET_CARDBUS) {
@@ -235,14 +223,14 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
235 config->AssignedIRQ = s->irq.AssignedIRQ; 223 config->AssignedIRQ = s->irq.AssignedIRQ;
236 if (config->AssignedIRQ) 224 if (config->AssignedIRQ)
237 config->Attributes |= CONF_ENABLE_IRQ; 225 config->Attributes |= CONF_ENABLE_IRQ;
238 config->BasePort1 = s->io[0].BasePort; 226 config->BasePort1 = s->io[0].res->start;
239 config->NumPorts1 = s->io[0].NumPorts; 227 config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
240 } 228 }
241 return CS_SUCCESS; 229 return CS_SUCCESS;
242 } 230 }
243#endif 231#endif
244 232
245 c = (s->config != NULL) ? &s->config[function] : NULL; 233 c = (p_dev) ? p_dev->function_config : NULL;
246 234
247 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { 235 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
248 config->Attributes = 0; 236 config->Attributes = 0;
@@ -271,7 +259,7 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
271int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, 259int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
272 config_info_t *config) 260 config_info_t *config)
273{ 261{
274 return pccard_get_configuration_info(p_dev->socket, p_dev->func, 262 return pccard_get_configuration_info(p_dev->socket, p_dev,
275 config); 263 config);
276} 264}
277EXPORT_SYMBOL(pcmcia_get_configuration_info); 265EXPORT_SYMBOL(pcmcia_get_configuration_info);
@@ -317,7 +305,7 @@ EXPORT_SYMBOL(pcmcia_get_window);
317 * SocketState yet: I haven't seen any point for it. 305 * SocketState yet: I haven't seen any point for it.
318 */ 306 */
319 307
320int pccard_get_status(struct pcmcia_socket *s, unsigned int function, 308int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev,
321 cs_status_t *status) 309 cs_status_t *status)
322{ 310{
323 config_t *c; 311 config_t *c;
@@ -334,11 +322,12 @@ int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
334 if (!(s->state & SOCKET_PRESENT)) 322 if (!(s->state & SOCKET_PRESENT))
335 return CS_NO_CARD; 323 return CS_NO_CARD;
336 324
337 c = (s->config != NULL) ? &s->config[function] : NULL; 325 c = (p_dev) ? p_dev->function_config : NULL;
326
338 if ((c != NULL) && (c->state & CONFIG_LOCKED) && 327 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
339 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) { 328 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
340 u_char reg; 329 u_char reg;
341 if (c->Present & PRESENT_PIN_REPLACE) { 330 if (c->CardValues & PRESENT_PIN_REPLACE) {
342 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg); 331 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
343 status->CardState |= 332 status->CardState |=
344 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0; 333 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
@@ -352,7 +341,7 @@ int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
352 /* No PRR? Then assume we're always ready */ 341 /* No PRR? Then assume we're always ready */
353 status->CardState |= CS_EVENT_READY_CHANGE; 342 status->CardState |= CS_EVENT_READY_CHANGE;
354 } 343 }
355 if (c->Present & PRESENT_EXT_STATUS) { 344 if (c->CardValues & PRESENT_EXT_STATUS) {
356 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg); 345 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
357 status->CardState |= 346 status->CardState |=
358 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0; 347 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
@@ -370,11 +359,9 @@ int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
370 return CS_SUCCESS; 359 return CS_SUCCESS;
371} /* pccard_get_status */ 360} /* pccard_get_status */
372 361
373int pcmcia_get_status(client_handle_t handle, cs_status_t *status) 362int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status)
374{ 363{
375 struct pcmcia_socket *s; 364 return pccard_get_status(p_dev->socket, p_dev, status);
376 s = SOCKET(handle);
377 return pccard_get_status(s, handle->func, status);
378} 365}
379EXPORT_SYMBOL(pcmcia_get_status); 366EXPORT_SYMBOL(pcmcia_get_status);
380 367
@@ -422,7 +409,8 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
422 config_t *c; 409 config_t *c;
423 410
424 s = p_dev->socket; 411 s = p_dev->socket;
425 c = CONFIG(p_dev); 412 c = p_dev->function_config;
413
426 if (!(s->state & SOCKET_PRESENT)) 414 if (!(s->state & SOCKET_PRESENT))
427 return CS_NO_CARD; 415 return CS_NO_CARD;
428 if (!(c->state & CONFIG_LOCKED)) 416 if (!(c->state & CONFIG_LOCKED))
@@ -454,6 +442,28 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
454 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) 442 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
455 return CS_BAD_VPP; 443 return CS_BAD_VPP;
456 444
445 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
446 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
447 pccard_io_map io_on;
448 int i;
449
450 io_on.speed = io_speed;
451 for (i = 0; i < MAX_IO_WIN; i++) {
452 if (!s->io[i].res)
453 continue;
454 io_off.map = i;
455 io_on.map = i;
456
457 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
458 io_on.start = s->io[i].res->start;
459 io_on.stop = s->io[i].res->end;
460
461 s->ops->set_io_map(s, &io_off);
462 mdelay(40);
463 s->ops->set_io_map(s, &io_on);
464 }
465 }
466
457 return CS_SUCCESS; 467 return CS_SUCCESS;
458} /* modify_configuration */ 468} /* modify_configuration */
459EXPORT_SYMBOL(pcmcia_modify_configuration); 469EXPORT_SYMBOL(pcmcia_modify_configuration);
@@ -463,23 +473,23 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
463{ 473{
464 pccard_io_map io = { 0, 0, 0, 0, 1 }; 474 pccard_io_map io = { 0, 0, 0, 0, 1 };
465 struct pcmcia_socket *s = p_dev->socket; 475 struct pcmcia_socket *s = p_dev->socket;
476 config_t *c = p_dev->function_config;
466 int i; 477 int i;
467 478
468 if (!(p_dev->state & CLIENT_CONFIG_LOCKED)) 479 if (p_dev->_locked) {
469 return CS_BAD_HANDLE; 480 p_dev->_locked = 0;
470 p_dev->state &= ~CLIENT_CONFIG_LOCKED;
471
472 if (!(p_dev->state & CLIENT_STALE)) {
473 config_t *c = CONFIG(p_dev);
474 if (--(s->lock_count) == 0) { 481 if (--(s->lock_count) == 0) {
475 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */ 482 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
476 s->socket.Vpp = 0; 483 s->socket.Vpp = 0;
477 s->socket.io_irq = 0; 484 s->socket.io_irq = 0;
478 s->ops->set_socket(s, &s->socket); 485 s->ops->set_socket(s, &s->socket);
479 } 486 }
487 }
488 if (c->state & CONFIG_LOCKED) {
489 c->state &= ~CONFIG_LOCKED;
480 if (c->state & CONFIG_IO_REQ) 490 if (c->state & CONFIG_IO_REQ)
481 for (i = 0; i < MAX_IO_WIN; i++) { 491 for (i = 0; i < MAX_IO_WIN; i++) {
482 if (s->io[i].NumPorts == 0) 492 if (!s->io[i].res)
483 continue; 493 continue;
484 s->io[i].Config--; 494 s->io[i].Config--;
485 if (s->io[i].Config != 0) 495 if (s->io[i].Config != 0)
@@ -487,12 +497,10 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
487 io.map = i; 497 io.map = i;
488 s->ops->set_io_map(s, &io); 498 s->ops->set_io_map(s, &io);
489 } 499 }
490 c->state &= ~CONFIG_LOCKED;
491 } 500 }
492 501
493 return CS_SUCCESS; 502 return CS_SUCCESS;
494} /* pcmcia_release_configuration */ 503} /* pcmcia_release_configuration */
495EXPORT_SYMBOL(pcmcia_release_configuration);
496 504
497 505
498/** pcmcia_release_io 506/** pcmcia_release_io
@@ -503,25 +511,23 @@ EXPORT_SYMBOL(pcmcia_release_configuration);
503 * don't bother checking the port ranges against the current socket 511 * don't bother checking the port ranges against the current socket
504 * values. 512 * values.
505 */ 513 */
506int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) 514static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
507{ 515{
508 struct pcmcia_socket *s = p_dev->socket; 516 struct pcmcia_socket *s = p_dev->socket;
517 config_t *c = p_dev->function_config;
509 518
510 if (!(p_dev->state & CLIENT_IO_REQ)) 519 if (!p_dev->_io )
511 return CS_BAD_HANDLE; 520 return CS_BAD_HANDLE;
512 p_dev->state &= ~CLIENT_IO_REQ; 521
513 522 p_dev->_io = 0;
514 if (!(p_dev->state & CLIENT_STALE)) { 523
515 config_t *c = CONFIG(p_dev); 524 if ((c->io.BasePort1 != req->BasePort1) ||
516 if (c->state & CONFIG_LOCKED) 525 (c->io.NumPorts1 != req->NumPorts1) ||
517 return CS_CONFIGURATION_LOCKED; 526 (c->io.BasePort2 != req->BasePort2) ||
518 if ((c->io.BasePort1 != req->BasePort1) || 527 (c->io.NumPorts2 != req->NumPorts2))
519 (c->io.NumPorts1 != req->NumPorts1) || 528 return CS_BAD_ARGS;
520 (c->io.BasePort2 != req->BasePort2) || 529
521 (c->io.NumPorts2 != req->NumPorts2)) 530 c->state &= ~CONFIG_IO_REQ;
522 return CS_BAD_ARGS;
523 c->state &= ~CONFIG_IO_REQ;
524 }
525 531
526 release_io_space(s, req->BasePort1, req->NumPorts1); 532 release_io_space(s, req->BasePort1, req->NumPorts1);
527 if (req->NumPorts2) 533 if (req->NumPorts2)
@@ -529,28 +535,26 @@ int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
529 535
530 return CS_SUCCESS; 536 return CS_SUCCESS;
531} /* pcmcia_release_io */ 537} /* pcmcia_release_io */
532EXPORT_SYMBOL(pcmcia_release_io);
533 538
534 539
535int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) 540static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
536{ 541{
537 struct pcmcia_socket *s = p_dev->socket; 542 struct pcmcia_socket *s = p_dev->socket;
538 if (!(p_dev->state & CLIENT_IRQ_REQ)) 543 config_t *c= p_dev->function_config;
544
545 if (!p_dev->_irq)
539 return CS_BAD_HANDLE; 546 return CS_BAD_HANDLE;
540 p_dev->state &= ~CLIENT_IRQ_REQ; 547 p_dev->_irq = 0;
541 548
542 if (!(p_dev->state & CLIENT_STALE)) { 549 if (c->state & CONFIG_LOCKED)
543 config_t *c = CONFIG(p_dev); 550 return CS_CONFIGURATION_LOCKED;
544 if (c->state & CONFIG_LOCKED) 551 if (c->irq.Attributes != req->Attributes)
545 return CS_CONFIGURATION_LOCKED; 552 return CS_BAD_ATTRIBUTE;
546 if (c->irq.Attributes != req->Attributes) 553 if (s->irq.AssignedIRQ != req->AssignedIRQ)
547 return CS_BAD_ATTRIBUTE; 554 return CS_BAD_IRQ;
548 if (s->irq.AssignedIRQ != req->AssignedIRQ) 555 if (--s->irq.Config == 0) {
549 return CS_BAD_IRQ; 556 c->state &= ~CONFIG_IRQ_REQ;
550 if (--s->irq.Config == 0) { 557 s->irq.AssignedIRQ = 0;
551 c->state &= ~CONFIG_IRQ_REQ;
552 s->irq.AssignedIRQ = 0;
553 }
554 } 558 }
555 559
556 if (req->Attributes & IRQ_HANDLE_PRESENT) { 560 if (req->Attributes & IRQ_HANDLE_PRESENT) {
@@ -563,7 +567,6 @@ int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
563 567
564 return CS_SUCCESS; 568 return CS_SUCCESS;
565} /* pcmcia_release_irq */ 569} /* pcmcia_release_irq */
566EXPORT_SYMBOL(pcmcia_release_irq);
567 570
568 571
569int pcmcia_release_window(window_handle_t win) 572int pcmcia_release_window(window_handle_t win)
@@ -573,7 +576,7 @@ int pcmcia_release_window(window_handle_t win)
573 if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 576 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
574 return CS_BAD_HANDLE; 577 return CS_BAD_HANDLE;
575 s = win->sock; 578 s = win->sock;
576 if (!(win->handle->state & CLIENT_WIN_REQ(win->index))) 579 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
577 return CS_BAD_HANDLE; 580 return CS_BAD_HANDLE;
578 581
579 /* Shut down memory window */ 582 /* Shut down memory window */
@@ -587,7 +590,7 @@ int pcmcia_release_window(window_handle_t win)
587 kfree(win->ctl.res); 590 kfree(win->ctl.res);
588 win->ctl.res = NULL; 591 win->ctl.res = NULL;
589 } 592 }
590 win->handle->state &= ~CLIENT_WIN_REQ(win->index); 593 win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
591 594
592 win->magic = 0; 595 win->magic = 0;
593 596
@@ -610,16 +613,12 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
610 613
611 if (req->IntType & INT_CARDBUS) 614 if (req->IntType & INT_CARDBUS)
612 return CS_UNSUPPORTED_MODE; 615 return CS_UNSUPPORTED_MODE;
613 c = CONFIG(p_dev); 616 c = p_dev->function_config;
614 if (c->state & CONFIG_LOCKED) 617 if (c->state & CONFIG_LOCKED)
615 return CS_CONFIGURATION_LOCKED; 618 return CS_CONFIGURATION_LOCKED;
616 619
617 /* Do power control. We don't allow changes in Vcc. */ 620 /* Do power control. We don't allow changes in Vcc. */
618 if (s->socket.Vcc != req->Vcc) 621 s->socket.Vpp = req->Vpp;
619 return CS_BAD_VCC;
620 if (req->Vpp1 != req->Vpp2)
621 return CS_BAD_VPP;
622 s->socket.Vpp = req->Vpp1;
623 if (s->ops->set_socket(s, &s->socket)) 622 if (s->ops->set_socket(s, &s->socket))
624 return CS_BAD_VPP; 623 return CS_BAD_VPP;
625 624
@@ -643,7 +642,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
643 642
644 /* Set up CIS configuration registers */ 643 /* Set up CIS configuration registers */
645 base = c->ConfigBase = req->ConfigBase; 644 base = c->ConfigBase = req->ConfigBase;
646 c->Present = c->CardValues = req->Present; 645 c->CardValues = req->Present;
647 if (req->Present & PRESENT_COPY) { 646 if (req->Present & PRESENT_COPY) {
648 c->Copy = req->Copy; 647 c->Copy = req->Copy;
649 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy); 648 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
@@ -690,10 +689,10 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
690 if (c->state & CONFIG_IO_REQ) { 689 if (c->state & CONFIG_IO_REQ) {
691 iomap.speed = io_speed; 690 iomap.speed = io_speed;
692 for (i = 0; i < MAX_IO_WIN; i++) 691 for (i = 0; i < MAX_IO_WIN; i++)
693 if (s->io[i].NumPorts != 0) { 692 if (s->io[i].res) {
694 iomap.map = i; 693 iomap.map = i;
695 iomap.flags = MAP_ACTIVE; 694 iomap.flags = MAP_ACTIVE;
696 switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) { 695 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
697 case IO_DATA_PATH_WIDTH_16: 696 case IO_DATA_PATH_WIDTH_16:
698 iomap.flags |= MAP_16BIT; break; 697 iomap.flags |= MAP_16BIT; break;
699 case IO_DATA_PATH_WIDTH_AUTO: 698 case IO_DATA_PATH_WIDTH_AUTO:
@@ -701,15 +700,15 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
701 default: 700 default:
702 break; 701 break;
703 } 702 }
704 iomap.start = s->io[i].BasePort; 703 iomap.start = s->io[i].res->start;
705 iomap.stop = iomap.start + s->io[i].NumPorts - 1; 704 iomap.stop = s->io[i].res->end;
706 s->ops->set_io_map(s, &iomap); 705 s->ops->set_io_map(s, &iomap);
707 s->io[i].Config++; 706 s->io[i].Config++;
708 } 707 }
709 } 708 }
710 709
711 c->state |= CONFIG_LOCKED; 710 c->state |= CONFIG_LOCKED;
712 p_dev->state |= CLIENT_CONFIG_LOCKED; 711 p_dev->_locked = 1;
713 return CS_SUCCESS; 712 return CS_SUCCESS;
714} /* pcmcia_request_configuration */ 713} /* pcmcia_request_configuration */
715EXPORT_SYMBOL(pcmcia_request_configuration); 714EXPORT_SYMBOL(pcmcia_request_configuration);
@@ -730,7 +729,7 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
730 729
731 if (!req) 730 if (!req)
732 return CS_UNSUPPORTED_MODE; 731 return CS_UNSUPPORTED_MODE;
733 c = CONFIG(p_dev); 732 c = p_dev->function_config;
734 if (c->state & CONFIG_LOCKED) 733 if (c->state & CONFIG_LOCKED)
735 return CS_CONFIGURATION_LOCKED; 734 return CS_CONFIGURATION_LOCKED;
736 if (c->state & CONFIG_IO_REQ) 735 if (c->state & CONFIG_IO_REQ)
@@ -755,7 +754,7 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
755 754
756 c->io = *req; 755 c->io = *req;
757 c->state |= CONFIG_IO_REQ; 756 c->state |= CONFIG_IO_REQ;
758 p_dev->state |= CLIENT_IO_REQ; 757 p_dev->_io = 1;
759 return CS_SUCCESS; 758 return CS_SUCCESS;
760} /* pcmcia_request_io */ 759} /* pcmcia_request_io */
761EXPORT_SYMBOL(pcmcia_request_io); 760EXPORT_SYMBOL(pcmcia_request_io);
@@ -786,7 +785,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
786 785
787 if (!(s->state & SOCKET_PRESENT)) 786 if (!(s->state & SOCKET_PRESENT))
788 return CS_NO_CARD; 787 return CS_NO_CARD;
789 c = CONFIG(p_dev); 788 c = p_dev->function_config;
790 if (c->state & CONFIG_LOCKED) 789 if (c->state & CONFIG_LOCKED)
791 return CS_CONFIGURATION_LOCKED; 790 return CS_CONFIGURATION_LOCKED;
792 if (c->state & CONFIG_IRQ_REQ) 791 if (c->state & CONFIG_IRQ_REQ)
@@ -851,7 +850,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
851 s->irq.Config++; 850 s->irq.Config++;
852 851
853 c->state |= CONFIG_IRQ_REQ; 852 c->state |= CONFIG_IRQ_REQ;
854 p_dev->state |= CLIENT_IRQ_REQ; 853 p_dev->_irq = 1;
855 854
856#ifdef CONFIG_PCMCIA_PROBE 855#ifdef CONFIG_PCMCIA_PROBE
857 pcmcia_used_irq[irq]++; 856 pcmcia_used_irq[irq]++;
@@ -911,7 +910,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
911 if (!win->ctl.res) 910 if (!win->ctl.res)
912 return CS_IN_USE; 911 return CS_IN_USE;
913 } 912 }
914 (*p_dev)->state |= CLIENT_WIN_REQ(w); 913 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
915 914
916 /* Configure the socket controller */ 915 /* Configure the socket controller */
917 win->ctl.map = w+1; 916 win->ctl.map = w+1;
@@ -941,3 +940,14 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
941 return CS_SUCCESS; 940 return CS_SUCCESS;
942} /* pcmcia_request_window */ 941} /* pcmcia_request_window */
943EXPORT_SYMBOL(pcmcia_request_window); 942EXPORT_SYMBOL(pcmcia_request_window);
943
944void pcmcia_disable_device(struct pcmcia_device *p_dev) {
945 pcmcia_release_configuration(p_dev);
946 pcmcia_release_io(p_dev, &p_dev->io);
947 pcmcia_release_irq(p_dev, &p_dev->irq);
948 if (&p_dev->win)
949 pcmcia_release_window(p_dev->win);
950
951 p_dev->dev_node = NULL;
952}
953EXPORT_SYMBOL(pcmcia_disable_device);
diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c
index f2789afb22b2..16d1ea7b0a18 100644
--- a/drivers/pcmcia/pd6729.c
+++ b/drivers/pcmcia/pd6729.c
@@ -8,7 +8,6 @@
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/config.h>
12#include <linux/module.h> 11#include <linux/module.h>
13#include <linux/pci.h> 12#include <linux/pci.h>
14#include <linux/init.h> 13#include <linux/init.h>
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index 514609369836..81dfc2cac2b4 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -12,7 +12,6 @@
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 */ 13 */
14 14
15#include <linux/config.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18 17
@@ -22,6 +21,8 @@
22#include "cs_internal.h" 21#include "cs_internal.h"
23 22
24 23
24#ifdef CONFIG_PCMCIA_IOCTL
25
25#ifdef CONFIG_PCMCIA_PROBE 26#ifdef CONFIG_PCMCIA_PROBE
26 27
27static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) 28static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
@@ -98,6 +99,8 @@ int pcmcia_adjust_resource_info(adjust_t *adj)
98} 99}
99EXPORT_SYMBOL(pcmcia_adjust_resource_info); 100EXPORT_SYMBOL(pcmcia_adjust_resource_info);
100 101
102#endif
103
101int pcmcia_validate_mem(struct pcmcia_socket *s) 104int pcmcia_validate_mem(struct pcmcia_socket *s)
102{ 105{
103 if (s->resource_ops->validate_mem) 106 if (s->resource_ops->validate_mem)
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 5301ac60358f..0f8b157c9717 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -12,7 +12,6 @@
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 */ 13 */
14 14
15#include <linux/config.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/moduleparam.h> 16#include <linux/moduleparam.h>
18#include <linux/init.h> 17#include <linux/init.h>
@@ -61,7 +60,7 @@ struct socket_data {
61 unsigned int rsrc_mem_probe; 60 unsigned int rsrc_mem_probe;
62}; 61};
63 62
64static DECLARE_MUTEX(rsrc_sem); 63static DEFINE_MUTEX(rsrc_mutex);
65#define MEM_PROBE_LOW (1 << 0) 64#define MEM_PROBE_LOW (1 << 0)
66#define MEM_PROBE_HIGH (1 << 1) 65#define MEM_PROBE_HIGH (1 << 1)
67 66
@@ -484,7 +483,7 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
484 483
485 484
486/* 485/*
487 * Locking note: Must be called with skt_sem held! 486 * Locking note: Must be called with skt_mutex held!
488 */ 487 */
489static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) 488static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s)
490{ 489{
@@ -495,7 +494,7 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s)
495 if (!probe_mem) 494 if (!probe_mem)
496 return 0; 495 return 0;
497 496
498 down(&rsrc_sem); 497 mutex_lock(&rsrc_mutex);
499 498
500 if (s->features & SS_CAP_PAGE_REGS) 499 if (s->features & SS_CAP_PAGE_REGS)
501 probe_mask = MEM_PROBE_HIGH; 500 probe_mask = MEM_PROBE_HIGH;
@@ -507,7 +506,7 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s)
507 s_data->rsrc_mem_probe |= probe_mask; 506 s_data->rsrc_mem_probe |= probe_mask;
508 } 507 }
509 508
510 up(&rsrc_sem); 509 mutex_unlock(&rsrc_mutex);
511 510
512 return ret; 511 return ret;
513} 512}
@@ -585,7 +584,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
585 struct socket_data *s_data = s->resource_data; 584 struct socket_data *s_data = s->resource_data;
586 int ret = -ENOMEM; 585 int ret = -ENOMEM;
587 586
588 down(&rsrc_sem); 587 mutex_lock(&rsrc_mutex);
589 for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { 588 for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) {
590 unsigned long start = m->base; 589 unsigned long start = m->base;
591 unsigned long end = m->base + m->num - 1; 590 unsigned long end = m->base + m->num - 1;
@@ -596,7 +595,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
596 ret = adjust_resource(res, r_start, r_end - r_start + 1); 595 ret = adjust_resource(res, r_start, r_end - r_start + 1);
597 break; 596 break;
598 } 597 }
599 up(&rsrc_sem); 598 mutex_unlock(&rsrc_mutex);
600 599
601 return ret; 600 return ret;
602} 601}
@@ -630,7 +629,7 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
630 data.offset = base & data.mask; 629 data.offset = base & data.mask;
631 data.map = &s_data->io_db; 630 data.map = &s_data->io_db;
632 631
633 down(&rsrc_sem); 632 mutex_lock(&rsrc_mutex);
634#ifdef CONFIG_PCI 633#ifdef CONFIG_PCI
635 if (s->cb_dev) { 634 if (s->cb_dev) {
636 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, 635 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
@@ -639,7 +638,7 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
639#endif 638#endif
640 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, 639 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
641 1, pcmcia_align, &data); 640 1, pcmcia_align, &data);
642 up(&rsrc_sem); 641 mutex_unlock(&rsrc_mutex);
643 642
644 if (ret != 0) { 643 if (ret != 0) {
645 kfree(res); 644 kfree(res);
@@ -672,7 +671,7 @@ static struct resource * nonstatic_find_mem_region(u_long base, u_long num,
672 min = 0x100000UL + base; 671 min = 0x100000UL + base;
673 } 672 }
674 673
675 down(&rsrc_sem); 674 mutex_lock(&rsrc_mutex);
676#ifdef CONFIG_PCI 675#ifdef CONFIG_PCI
677 if (s->cb_dev) { 676 if (s->cb_dev) {
678 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 677 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num,
@@ -682,7 +681,7 @@ static struct resource * nonstatic_find_mem_region(u_long base, u_long num,
682#endif 681#endif
683 ret = allocate_resource(&iomem_resource, res, num, min, 682 ret = allocate_resource(&iomem_resource, res, num, min,
684 max, 1, pcmcia_align, &data); 683 max, 1, pcmcia_align, &data);
685 up(&rsrc_sem); 684 mutex_unlock(&rsrc_mutex);
686 if (ret == 0 || low) 685 if (ret == 0 || low)
687 break; 686 break;
688 low = 1; 687 low = 1;
@@ -705,7 +704,7 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned
705 if (end < start) 704 if (end < start)
706 return -EINVAL; 705 return -EINVAL;
707 706
708 down(&rsrc_sem); 707 mutex_lock(&rsrc_mutex);
709 switch (action) { 708 switch (action) {
710 case ADD_MANAGED_RESOURCE: 709 case ADD_MANAGED_RESOURCE:
711 ret = add_interval(&data->mem_db, start, size); 710 ret = add_interval(&data->mem_db, start, size);
@@ -723,7 +722,7 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned
723 default: 722 default:
724 ret = -EINVAL; 723 ret = -EINVAL;
725 } 724 }
726 up(&rsrc_sem); 725 mutex_unlock(&rsrc_mutex);
727 726
728 return ret; 727 return ret;
729} 728}
@@ -741,7 +740,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
741 if (end > IO_SPACE_LIMIT) 740 if (end > IO_SPACE_LIMIT)
742 return -EINVAL; 741 return -EINVAL;
743 742
744 down(&rsrc_sem); 743 mutex_lock(&rsrc_mutex);
745 switch (action) { 744 switch (action) {
746 case ADD_MANAGED_RESOURCE: 745 case ADD_MANAGED_RESOURCE:
747 if (add_interval(&data->io_db, start, size) != 0) { 746 if (add_interval(&data->io_db, start, size) != 0) {
@@ -760,7 +759,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
760 ret = -EINVAL; 759 ret = -EINVAL;
761 break; 760 break;
762 } 761 }
763 up(&rsrc_sem); 762 mutex_unlock(&rsrc_mutex);
764 763
765 return ret; 764 return ret;
766} 765}
@@ -867,7 +866,7 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
867 struct socket_data *data = s->resource_data; 866 struct socket_data *data = s->resource_data;
868 struct resource_map *p, *q; 867 struct resource_map *p, *q;
869 868
870 down(&rsrc_sem); 869 mutex_lock(&rsrc_mutex);
871 for (p = data->mem_db.next; p != &data->mem_db; p = q) { 870 for (p = data->mem_db.next; p != &data->mem_db; p = q) {
872 q = p->next; 871 q = p->next;
873 kfree(p); 872 kfree(p);
@@ -876,7 +875,7 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
876 q = p->next; 875 q = p->next;
877 kfree(p); 876 kfree(p);
878 } 877 }
879 up(&rsrc_sem); 878 mutex_unlock(&rsrc_mutex);
880} 879}
881 880
882 881
@@ -901,7 +900,7 @@ static ssize_t show_io_db(struct class_device *class_dev, char *buf)
901 struct resource_map *p; 900 struct resource_map *p;
902 ssize_t ret = 0; 901 ssize_t ret = 0;
903 902
904 down(&rsrc_sem); 903 mutex_lock(&rsrc_mutex);
905 data = s->resource_data; 904 data = s->resource_data;
906 905
907 for (p = data->io_db.next; p != &data->io_db; p = p->next) { 906 for (p = data->io_db.next; p != &data->io_db; p = p->next) {
@@ -913,7 +912,7 @@ static ssize_t show_io_db(struct class_device *class_dev, char *buf)
913 ((unsigned long) p->base + p->num - 1)); 912 ((unsigned long) p->base + p->num - 1));
914 } 913 }
915 914
916 up(&rsrc_sem); 915 mutex_unlock(&rsrc_mutex);
917 return (ret); 916 return (ret);
918} 917}
919 918
@@ -953,7 +952,7 @@ static ssize_t show_mem_db(struct class_device *class_dev, char *buf)
953 struct resource_map *p; 952 struct resource_map *p;
954 ssize_t ret = 0; 953 ssize_t ret = 0;
955 954
956 down(&rsrc_sem); 955 mutex_lock(&rsrc_mutex);
957 data = s->resource_data; 956 data = s->resource_data;
958 957
959 for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { 958 for (p = data->mem_db.next; p != &data->mem_db; p = p->next) {
@@ -965,7 +964,7 @@ static ssize_t show_mem_db(struct class_device *class_dev, char *buf)
965 ((unsigned long) p->base + p->num - 1)); 964 ((unsigned long) p->base + p->num - 1));
966 } 965 }
967 966
968 up(&rsrc_sem); 967 mutex_unlock(&rsrc_mutex);
969 return (ret); 968 return (ret);
970} 969}
971 970
diff --git a/drivers/pcmcia/sa1100_cerf.c b/drivers/pcmcia/sa1100_cerf.c
index 2b3c2895b43d..eb89928f2338 100644
--- a/drivers/pcmcia/sa1100_cerf.c
+++ b/drivers/pcmcia/sa1100_cerf.c
@@ -5,7 +5,6 @@
5 * Based off the Assabet. 5 * Based off the Assabet.
6 * 6 *
7 */ 7 */
8#include <linux/config.h>
9#include <linux/module.h> 8#include <linux/module.h>
10#include <linux/kernel.h> 9#include <linux/kernel.h>
11#include <linux/sched.h> 10#include <linux/sched.h>
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index 5ab1cdef7c48..c5d7476da471 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -12,7 +12,6 @@
12#include <linux/moduleparam.h> 12#include <linux/moduleparam.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/config.h>
16#include <linux/string.h> 15#include <linux/string.h>
17#include <linux/major.h> 16#include <linux/major.h>
18#include <linux/errno.h> 17#include <linux/errno.h>
@@ -25,6 +24,7 @@
25#include <linux/pm.h> 24#include <linux/pm.h>
26#include <linux/pci.h> 25#include <linux/pci.h>
27#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/mutex.h>
28#include <asm/system.h> 28#include <asm/system.h>
29#include <asm/irq.h> 29#include <asm/irq.h>
30 30
@@ -183,7 +183,7 @@ static ssize_t pccard_store_resource(struct class_device *dev, const char *buf,
183 s->resource_setup_done = 1; 183 s->resource_setup_done = 1;
184 spin_unlock_irqrestore(&s->lock, flags); 184 spin_unlock_irqrestore(&s->lock, flags);
185 185
186 down(&s->skt_sem); 186 mutex_lock(&s->skt_mutex);
187 if ((s->callback) && 187 if ((s->callback) &&
188 (s->state & SOCKET_PRESENT) && 188 (s->state & SOCKET_PRESENT) &&
189 !(s->state & SOCKET_CARDBUS)) { 189 !(s->state & SOCKET_CARDBUS)) {
@@ -192,7 +192,7 @@ static ssize_t pccard_store_resource(struct class_device *dev, const char *buf,
192 module_put(s->callback->owner); 192 module_put(s->callback->owner);
193 } 193 }
194 } 194 }
195 up(&s->skt_sem); 195 mutex_unlock(&s->skt_mutex);
196 196
197 return count; 197 return count;
198} 198}
@@ -322,7 +322,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
322 kfree(cis); 322 kfree(cis);
323 323
324 if (!ret) { 324 if (!ret) {
325 down(&s->skt_sem); 325 mutex_lock(&s->skt_mutex);
326 if ((s->callback) && (s->state & SOCKET_PRESENT) && 326 if ((s->callback) && (s->state & SOCKET_PRESENT) &&
327 !(s->state & SOCKET_CARDBUS)) { 327 !(s->state & SOCKET_CARDBUS)) {
328 if (try_module_get(s->callback->owner)) { 328 if (try_module_get(s->callback->owner)) {
@@ -330,7 +330,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
330 module_put(s->callback->owner); 330 module_put(s->callback->owner);
331 } 331 }
332 } 332 }
333 up(&s->skt_sem); 333 mutex_unlock(&s->skt_mutex);
334 } 334 }
335 335
336 336
diff --git a/drivers/pcmcia/ti113x.h b/drivers/pcmcia/ti113x.h
index d5b4ff74462e..7a3d1b8e16b9 100644
--- a/drivers/pcmcia/ti113x.h
+++ b/drivers/pcmcia/ti113x.h
@@ -30,7 +30,6 @@
30#ifndef _LINUX_TI113X_H 30#ifndef _LINUX_TI113X_H
31#define _LINUX_TI113X_H 31#define _LINUX_TI113X_H
32 32
33#include <linux/config.h>
34 33
35/* Register definitions for TI 113X PCI-to-CardBus bridges */ 34/* Register definitions for TI 113X PCI-to-CardBus bridges */
36 35
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index 5609847e254a..ee449b29fc82 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -89,29 +89,29 @@ MODULE_LICENSE("Dual MPL/GPL");
89/*====================================================================*/ 89/*====================================================================*/
90 90
91typedef struct scsi_info_t { 91typedef struct scsi_info_t {
92 dev_link_t link; 92 struct pcmcia_device *p_dev;
93 dev_node_t node; 93 dev_node_t node;
94 struct Scsi_Host *host; 94 struct Scsi_Host *host;
95} scsi_info_t; 95} scsi_info_t;
96 96
97static void aha152x_release_cs(dev_link_t *link); 97static void aha152x_release_cs(struct pcmcia_device *link);
98static void aha152x_detach(struct pcmcia_device *p_dev); 98static void aha152x_detach(struct pcmcia_device *p_dev);
99static void aha152x_config_cs(dev_link_t *link); 99static int aha152x_config_cs(struct pcmcia_device *link);
100 100
101static dev_link_t *dev_list; 101static struct pcmcia_device *dev_list;
102 102
103static int aha152x_attach(struct pcmcia_device *p_dev) 103static int aha152x_probe(struct pcmcia_device *link)
104{ 104{
105 scsi_info_t *info; 105 scsi_info_t *info;
106 dev_link_t *link; 106
107
108 DEBUG(0, "aha152x_attach()\n"); 107 DEBUG(0, "aha152x_attach()\n");
109 108
110 /* Create new SCSI device */ 109 /* Create new SCSI device */
111 info = kmalloc(sizeof(*info), GFP_KERNEL); 110 info = kmalloc(sizeof(*info), GFP_KERNEL);
112 if (!info) return -ENOMEM; 111 if (!info) return -ENOMEM;
113 memset(info, 0, sizeof(*info)); 112 memset(info, 0, sizeof(*info));
114 link = &info->link; link->priv = info; 113 info->p_dev = link;
114 link->priv = info;
115 115
116 link->io.NumPorts1 = 0x20; 116 link->io.NumPorts1 = 0x20;
117 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 117 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -119,41 +119,22 @@ static int aha152x_attach(struct pcmcia_device *p_dev)
119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
120 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 120 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
121 link->conf.Attributes = CONF_ENABLE_IRQ; 121 link->conf.Attributes = CONF_ENABLE_IRQ;
122 link->conf.Vcc = 50;
123 link->conf.IntType = INT_MEMORY_AND_IO; 122 link->conf.IntType = INT_MEMORY_AND_IO;
124 link->conf.Present = PRESENT_OPTION; 123 link->conf.Present = PRESENT_OPTION;
125 124
126 link->handle = p_dev; 125 return aha152x_config_cs(link);
127 p_dev->instance = link;
128
129 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
130 aha152x_config_cs(link);
131
132 return 0;
133} /* aha152x_attach */ 126} /* aha152x_attach */
134 127
135/*====================================================================*/ 128/*====================================================================*/
136 129
137static void aha152x_detach(struct pcmcia_device *p_dev) 130static void aha152x_detach(struct pcmcia_device *link)
138{ 131{
139 dev_link_t *link = dev_to_instance(p_dev);
140 dev_link_t **linkp;
141
142 DEBUG(0, "aha152x_detach(0x%p)\n", link); 132 DEBUG(0, "aha152x_detach(0x%p)\n", link);
143
144 /* Locate device structure */
145 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
146 if (*linkp == link) break;
147 if (*linkp == NULL)
148 return;
149 133
150 if (link->state & DEV_CONFIG) 134 aha152x_release_cs(link);
151 aha152x_release_cs(link);
152 135
153 /* Unlink device structure, free bits */ 136 /* Unlink device structure, free bits */
154 *linkp = link->next;
155 kfree(link->priv); 137 kfree(link->priv);
156
157} /* aha152x_detach */ 138} /* aha152x_detach */
158 139
159/*====================================================================*/ 140/*====================================================================*/
@@ -161,9 +142,8 @@ static void aha152x_detach(struct pcmcia_device *p_dev)
161#define CS_CHECK(fn, ret) \ 142#define CS_CHECK(fn, ret) \
162do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 143do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
163 144
164static void aha152x_config_cs(dev_link_t *link) 145static int aha152x_config_cs(struct pcmcia_device *link)
165{ 146{
166 client_handle_t handle = link->handle;
167 scsi_info_t *info = link->priv; 147 scsi_info_t *info = link->priv;
168 struct aha152x_setup s; 148 struct aha152x_setup s;
169 tuple_t tuple; 149 tuple_t tuple;
@@ -178,19 +158,16 @@ static void aha152x_config_cs(dev_link_t *link)
178 tuple.TupleData = tuple_data; 158 tuple.TupleData = tuple_data;
179 tuple.TupleDataMax = 64; 159 tuple.TupleDataMax = 64;
180 tuple.TupleOffset = 0; 160 tuple.TupleOffset = 0;
181 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 161 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
182 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 162 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
183 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 163 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
184 link->conf.ConfigBase = parse.config.base; 164 link->conf.ConfigBase = parse.config.base;
185 165
186 /* Configure card */
187 link->state |= DEV_CONFIG;
188
189 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 166 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
190 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 167 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
191 while (1) { 168 while (1) {
192 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 169 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
193 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 170 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
194 goto next_entry; 171 goto next_entry;
195 /* For New Media T&J, look for a SCSI window */ 172 /* For New Media T&J, look for a SCSI window */
196 if (parse.cftable_entry.io.win[0].len >= 0x20) 173 if (parse.cftable_entry.io.win[0].len >= 0x20)
@@ -201,15 +178,15 @@ static void aha152x_config_cs(dev_link_t *link)
201 if ((parse.cftable_entry.io.nwin > 0) && 178 if ((parse.cftable_entry.io.nwin > 0) &&
202 (link->io.BasePort1 < 0xffff)) { 179 (link->io.BasePort1 < 0xffff)) {
203 link->conf.ConfigIndex = parse.cftable_entry.index; 180 link->conf.ConfigIndex = parse.cftable_entry.index;
204 i = pcmcia_request_io(handle, &link->io); 181 i = pcmcia_request_io(link, &link->io);
205 if (i == CS_SUCCESS) break; 182 if (i == CS_SUCCESS) break;
206 } 183 }
207 next_entry: 184 next_entry:
208 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 185 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
209 } 186 }
210 187
211 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 188 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
212 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 189 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
213 190
214 /* Set configuration options for the aha152x driver */ 191 /* Set configuration options for the aha152x driver */
215 memset(&s, 0, sizeof(s)); 192 memset(&s, 0, sizeof(s));
@@ -231,53 +208,30 @@ static void aha152x_config_cs(dev_link_t *link)
231 } 208 }
232 209
233 sprintf(info->node.dev_name, "scsi%d", host->host_no); 210 sprintf(info->node.dev_name, "scsi%d", host->host_no);
234 link->dev = &info->node; 211 link->dev_node = &info->node;
235 info->host = host; 212 info->host = host;
236 213
237 link->state &= ~DEV_CONFIG_PENDING; 214 return 0;
238 return; 215
239
240cs_failed: 216cs_failed:
241 cs_error(link->handle, last_fn, last_ret); 217 cs_error(link, last_fn, last_ret);
242 aha152x_release_cs(link); 218 aha152x_release_cs(link);
243 return; 219 return -ENODEV;
244} 220}
245 221
246static void aha152x_release_cs(dev_link_t *link) 222static void aha152x_release_cs(struct pcmcia_device *link)
247{ 223{
248 scsi_info_t *info = link->priv; 224 scsi_info_t *info = link->priv;
249 225
250 aha152x_release(info->host); 226 aha152x_release(info->host);
251 link->dev = NULL; 227 pcmcia_disable_device(link);
252
253 pcmcia_release_configuration(link->handle);
254 pcmcia_release_io(link->handle, &link->io);
255 pcmcia_release_irq(link->handle, &link->irq);
256
257 link->state &= ~DEV_CONFIG;
258} 228}
259 229
260static int aha152x_suspend(struct pcmcia_device *dev) 230static int aha152x_resume(struct pcmcia_device *link)
261{ 231{
262 dev_link_t *link = dev_to_instance(dev);
263
264 link->state |= DEV_SUSPEND;
265 if (link->state & DEV_CONFIG)
266 pcmcia_release_configuration(link->handle);
267
268 return 0;
269}
270
271static int aha152x_resume(struct pcmcia_device *dev)
272{
273 dev_link_t *link = dev_to_instance(dev);
274 scsi_info_t *info = link->priv; 232 scsi_info_t *info = link->priv;
275 233
276 link->state &= ~DEV_SUSPEND; 234 aha152x_host_reset_host(info->host);
277 if (link->state & DEV_CONFIG) {
278 pcmcia_request_configuration(link->handle, &link->conf);
279 aha152x_host_reset_host(info->host);
280 }
281 235
282 return 0; 236 return 0;
283} 237}
@@ -297,10 +251,9 @@ static struct pcmcia_driver aha152x_cs_driver = {
297 .drv = { 251 .drv = {
298 .name = "aha152x_cs", 252 .name = "aha152x_cs",
299 }, 253 },
300 .probe = aha152x_attach, 254 .probe = aha152x_probe,
301 .remove = aha152x_detach, 255 .remove = aha152x_detach,
302 .id_table = aha152x_ids, 256 .id_table = aha152x_ids,
303 .suspend = aha152x_suspend,
304 .resume = aha152x_resume, 257 .resume = aha152x_resume,
305}; 258};
306 259
@@ -317,4 +270,3 @@ static void __exit exit_aha152x_cs(void)
317 270
318module_init(init_aha152x_cs); 271module_init(init_aha152x_cs);
319module_exit(exit_aha152x_cs); 272module_exit(exit_aha152x_cs);
320
diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c
index 788c58d805f3..85f7ffac19a0 100644
--- a/drivers/scsi/pcmcia/fdomain_stub.c
+++ b/drivers/scsi/pcmcia/fdomain_stub.c
@@ -73,57 +73,48 @@ static char *version =
73/*====================================================================*/ 73/*====================================================================*/
74 74
75typedef struct scsi_info_t { 75typedef struct scsi_info_t {
76 dev_link_t link; 76 struct pcmcia_device *p_dev;
77 dev_node_t node; 77 dev_node_t node;
78 struct Scsi_Host *host; 78 struct Scsi_Host *host;
79} scsi_info_t; 79} scsi_info_t;
80 80
81 81
82static void fdomain_release(dev_link_t *link); 82static void fdomain_release(struct pcmcia_device *link);
83static void fdomain_detach(struct pcmcia_device *p_dev); 83static void fdomain_detach(struct pcmcia_device *p_dev);
84static void fdomain_config(dev_link_t *link); 84static int fdomain_config(struct pcmcia_device *link);
85 85
86static int fdomain_attach(struct pcmcia_device *p_dev) 86static int fdomain_probe(struct pcmcia_device *link)
87{ 87{
88 scsi_info_t *info; 88 scsi_info_t *info;
89 dev_link_t *link; 89
90 90 DEBUG(0, "fdomain_attach()\n");
91 DEBUG(0, "fdomain_attach()\n"); 91
92 92 /* Create new SCSI device */
93 /* Create new SCSI device */ 93 info = kzalloc(sizeof(*info), GFP_KERNEL);
94 info = kmalloc(sizeof(*info), GFP_KERNEL); 94 if (!info)
95 if (!info) return -ENOMEM; 95 return -ENOMEM;
96 memset(info, 0, sizeof(*info)); 96
97 link = &info->link; link->priv = info; 97 info->p_dev = link;
98 link->io.NumPorts1 = 0x10; 98 link->priv = info;
99 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 99 link->io.NumPorts1 = 0x10;
100 link->io.IOAddrLines = 10; 100 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
101 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 101 link->io.IOAddrLines = 10;
102 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 102 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
103 link->conf.Attributes = CONF_ENABLE_IRQ; 103 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
104 link->conf.Vcc = 50; 104 link->conf.Attributes = CONF_ENABLE_IRQ;
105 link->conf.IntType = INT_MEMORY_AND_IO; 105 link->conf.IntType = INT_MEMORY_AND_IO;
106 link->conf.Present = PRESENT_OPTION; 106 link->conf.Present = PRESENT_OPTION;
107 107
108 link->handle = p_dev; 108 return fdomain_config(link);
109 p_dev->instance = link;
110
111 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
112 fdomain_config(link);
113
114 return 0;
115} /* fdomain_attach */ 109} /* fdomain_attach */
116 110
117/*====================================================================*/ 111/*====================================================================*/
118 112
119static void fdomain_detach(struct pcmcia_device *p_dev) 113static void fdomain_detach(struct pcmcia_device *link)
120{ 114{
121 dev_link_t *link = dev_to_instance(p_dev);
122
123 DEBUG(0, "fdomain_detach(0x%p)\n", link); 115 DEBUG(0, "fdomain_detach(0x%p)\n", link);
124 116
125 if (link->state & DEV_CONFIG) 117 fdomain_release(link);
126 fdomain_release(link);
127 118
128 kfree(link->priv); 119 kfree(link->priv);
129} /* fdomain_detach */ 120} /* fdomain_detach */
@@ -133,9 +124,8 @@ static void fdomain_detach(struct pcmcia_device *p_dev)
133#define CS_CHECK(fn, ret) \ 124#define CS_CHECK(fn, ret) \
134do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 125do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
135 126
136static void fdomain_config(dev_link_t *link) 127static int fdomain_config(struct pcmcia_device *link)
137{ 128{
138 client_handle_t handle = link->handle;
139 scsi_info_t *info = link->priv; 129 scsi_info_t *info = link->priv;
140 tuple_t tuple; 130 tuple_t tuple;
141 cisparse_t parse; 131 cisparse_t parse;
@@ -150,103 +140,75 @@ static void fdomain_config(dev_link_t *link)
150 tuple.TupleData = tuple_data; 140 tuple.TupleData = tuple_data;
151 tuple.TupleDataMax = 64; 141 tuple.TupleDataMax = 64;
152 tuple.TupleOffset = 0; 142 tuple.TupleOffset = 0;
153 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 143 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
154 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 144 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
155 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 145 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
156 link->conf.ConfigBase = parse.config.base; 146 link->conf.ConfigBase = parse.config.base;
157 147
158 /* Configure card */
159 link->state |= DEV_CONFIG;
160
161 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 148 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
162 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 149 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
163 while (1) { 150 while (1) {
164 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 151 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
165 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 152 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
166 goto next_entry; 153 goto next_entry;
167 link->conf.ConfigIndex = parse.cftable_entry.index; 154 link->conf.ConfigIndex = parse.cftable_entry.index;
168 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 155 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
169 i = pcmcia_request_io(handle, &link->io); 156 i = pcmcia_request_io(link, &link->io);
170 if (i == CS_SUCCESS) break; 157 if (i == CS_SUCCESS) break;
171 next_entry: 158 next_entry:
172 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 159 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
173 } 160 }
174 161
175 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 162 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
176 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 163 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
177 164
178 /* A bad hack... */ 165 /* A bad hack... */
179 release_region(link->io.BasePort1, link->io.NumPorts1); 166 release_region(link->io.BasePort1, link->io.NumPorts1);
180 167
181 /* Set configuration options for the fdomain driver */ 168 /* Set configuration options for the fdomain driver */
182 sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ); 169 sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ);
183 fdomain_setup(str); 170 fdomain_setup(str);
184 171
185 host = __fdomain_16x0_detect(&fdomain_driver_template); 172 host = __fdomain_16x0_detect(&fdomain_driver_template);
186 if (!host) { 173 if (!host) {
187 printk(KERN_INFO "fdomain_cs: no SCSI devices found\n"); 174 printk(KERN_INFO "fdomain_cs: no SCSI devices found\n");
188 goto cs_failed; 175 goto cs_failed;
189 } 176 }
190 177
191 scsi_add_host(host, NULL); /* XXX handle failure */ 178 if (scsi_add_host(host, NULL))
179 goto cs_failed;
192 scsi_scan_host(host); 180 scsi_scan_host(host);
193 181
194 sprintf(info->node.dev_name, "scsi%d", host->host_no); 182 sprintf(info->node.dev_name, "scsi%d", host->host_no);
195 link->dev = &info->node; 183 link->dev_node = &info->node;
196 info->host = host; 184 info->host = host;
197 185
198 link->state &= ~DEV_CONFIG_PENDING; 186 return 0;
199 return; 187
200
201cs_failed: 188cs_failed:
202 cs_error(link->handle, last_fn, last_ret); 189 cs_error(link, last_fn, last_ret);
203 fdomain_release(link); 190 fdomain_release(link);
204 return; 191 return -ENODEV;
205
206} /* fdomain_config */ 192} /* fdomain_config */
207 193
208/*====================================================================*/ 194/*====================================================================*/
209 195
210static void fdomain_release(dev_link_t *link) 196static void fdomain_release(struct pcmcia_device *link)
211{ 197{
212 scsi_info_t *info = link->priv; 198 scsi_info_t *info = link->priv;
213 199
214 DEBUG(0, "fdomain_release(0x%p)\n", link); 200 DEBUG(0, "fdomain_release(0x%p)\n", link);
215 201
216 scsi_remove_host(info->host); 202 scsi_remove_host(info->host);
217 link->dev = NULL; 203 pcmcia_disable_device(link);
218 204 scsi_unregister(info->host);
219 pcmcia_release_configuration(link->handle);
220 pcmcia_release_io(link->handle, &link->io);
221 pcmcia_release_irq(link->handle, &link->irq);
222
223 scsi_unregister(info->host);
224
225 link->state &= ~DEV_CONFIG;
226} 205}
227 206
228/*====================================================================*/ 207/*====================================================================*/
229 208
230static int fdomain_suspend(struct pcmcia_device *dev) 209static int fdomain_resume(struct pcmcia_device *link)
231{ 210{
232 dev_link_t *link = dev_to_instance(dev); 211 fdomain_16x0_bus_reset(NULL);
233
234 link->state |= DEV_SUSPEND;
235 if (link->state & DEV_CONFIG)
236 pcmcia_release_configuration(link->handle);
237
238 return 0;
239}
240
241static int fdomain_resume(struct pcmcia_device *dev)
242{
243 dev_link_t *link = dev_to_instance(dev);
244
245 link->state &= ~DEV_SUSPEND;
246 if (link->state & DEV_CONFIG) {
247 pcmcia_request_configuration(link->handle, &link->conf);
248 fdomain_16x0_bus_reset(NULL);
249 }
250 212
251 return 0; 213 return 0;
252} 214}
@@ -264,10 +226,9 @@ static struct pcmcia_driver fdomain_cs_driver = {
264 .drv = { 226 .drv = {
265 .name = "fdomain_cs", 227 .name = "fdomain_cs",
266 }, 228 },
267 .probe = fdomain_attach, 229 .probe = fdomain_probe,
268 .remove = fdomain_detach, 230 .remove = fdomain_detach,
269 .id_table = fdomain_ids, 231 .id_table = fdomain_ids,
270 .suspend = fdomain_suspend,
271 .resume = fdomain_resume, 232 .resume = fdomain_resume,
272}; 233};
273 234
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 9e3ab3fd5355..231f9c311c69 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -1593,11 +1593,11 @@ static int nsp_eh_host_reset(Scsi_Cmnd *SCpnt)
1593 configure the card at this point -- we wait until we receive a 1593 configure the card at this point -- we wait until we receive a
1594 card insertion event. 1594 card insertion event.
1595======================================================================*/ 1595======================================================================*/
1596static int nsp_cs_attach(struct pcmcia_device *p_dev) 1596static int nsp_cs_probe(struct pcmcia_device *link)
1597{ 1597{
1598 scsi_info_t *info; 1598 scsi_info_t *info;
1599 dev_link_t *link;
1600 nsp_hw_data *data = &nsp_data_base; 1599 nsp_hw_data *data = &nsp_data_base;
1600 int ret;
1601 1601
1602 nsp_dbg(NSP_DEBUG_INIT, "in"); 1602 nsp_dbg(NSP_DEBUG_INIT, "in");
1603 1603
@@ -1605,7 +1605,7 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1605 info = kmalloc(sizeof(*info), GFP_KERNEL); 1605 info = kmalloc(sizeof(*info), GFP_KERNEL);
1606 if (info == NULL) { return -ENOMEM; } 1606 if (info == NULL) { return -ENOMEM; }
1607 memset(info, 0, sizeof(*info)); 1607 memset(info, 0, sizeof(*info));
1608 link = &info->link; 1608 info->p_dev = link;
1609 link->priv = info; 1609 link->priv = info;
1610 data->ScsiInfo = info; 1610 data->ScsiInfo = info;
1611 1611
@@ -1627,18 +1627,13 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1627 1627
1628 /* General socket configuration */ 1628 /* General socket configuration */
1629 link->conf.Attributes = CONF_ENABLE_IRQ; 1629 link->conf.Attributes = CONF_ENABLE_IRQ;
1630 link->conf.Vcc = 50;
1631 link->conf.IntType = INT_MEMORY_AND_IO; 1630 link->conf.IntType = INT_MEMORY_AND_IO;
1632 link->conf.Present = PRESENT_OPTION; 1631 link->conf.Present = PRESENT_OPTION;
1633 1632
1634 link->handle = p_dev; 1633 ret = nsp_cs_config(link);
1635 p_dev->instance = link;
1636
1637 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1638 nsp_cs_config(link);
1639 1634
1640 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link); 1635 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
1641 return 0; 1636 return ret;
1642} /* nsp_cs_attach */ 1637} /* nsp_cs_attach */
1643 1638
1644 1639
@@ -1648,16 +1643,12 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1648 structures are freed. Otherwise, the structures will be freed 1643 structures are freed. Otherwise, the structures will be freed
1649 when the device is released. 1644 when the device is released.
1650======================================================================*/ 1645======================================================================*/
1651static void nsp_cs_detach(struct pcmcia_device *p_dev) 1646static void nsp_cs_detach(struct pcmcia_device *link)
1652{ 1647{
1653 dev_link_t *link = dev_to_instance(p_dev);
1654
1655 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link); 1648 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link);
1656 1649
1657 if (link->state & DEV_CONFIG) { 1650 ((scsi_info_t *)link->priv)->stop = 1;
1658 ((scsi_info_t *)link->priv)->stop = 1; 1651 nsp_cs_release(link);
1659 nsp_cs_release(link);
1660 }
1661 1652
1662 kfree(link->priv); 1653 kfree(link->priv);
1663 link->priv = NULL; 1654 link->priv = NULL;
@@ -1672,9 +1663,9 @@ static void nsp_cs_detach(struct pcmcia_device *p_dev)
1672#define CS_CHECK(fn, ret) \ 1663#define CS_CHECK(fn, ret) \
1673do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 1664do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
1674/*====================================================================*/ 1665/*====================================================================*/
1675static void nsp_cs_config(dev_link_t *link) 1666static int nsp_cs_config(struct pcmcia_device *link)
1676{ 1667{
1677 client_handle_t handle = link->handle; 1668 int ret;
1678 scsi_info_t *info = link->priv; 1669 scsi_info_t *info = link->priv;
1679 tuple_t tuple; 1670 tuple_t tuple;
1680 cisparse_t parse; 1671 cisparse_t parse;
@@ -1698,26 +1689,22 @@ static void nsp_cs_config(dev_link_t *link)
1698 tuple.TupleData = tuple_data; 1689 tuple.TupleData = tuple_data;
1699 tuple.TupleDataMax = sizeof(tuple_data); 1690 tuple.TupleDataMax = sizeof(tuple_data);
1700 tuple.TupleOffset = 0; 1691 tuple.TupleOffset = 0;
1701 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1692 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
1702 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 1693 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
1703 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 1694 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
1704 link->conf.ConfigBase = parse.config.base; 1695 link->conf.ConfigBase = parse.config.base;
1705 link->conf.Present = parse.config.rmask[0]; 1696 link->conf.Present = parse.config.rmask[0];
1706 1697
1707 /* Configure card */
1708 link->state |= DEV_CONFIG;
1709
1710 /* Look up the current Vcc */ 1698 /* Look up the current Vcc */
1711 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf)); 1699 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
1712 link->conf.Vcc = conf.Vcc;
1713 1700
1714 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 1701 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1715 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1702 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
1716 while (1) { 1703 while (1) {
1717 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 1704 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
1718 1705
1719 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 1706 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
1720 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 1707 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
1721 goto next_entry; 1708 goto next_entry;
1722 1709
1723 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; } 1710 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; }
@@ -1743,10 +1730,10 @@ static void nsp_cs_config(dev_link_t *link)
1743 } 1730 }
1744 1731
1745 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1732 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1746 link->conf.Vpp1 = link->conf.Vpp2 = 1733 link->conf.Vpp =
1747 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 1734 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
1748 } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1735 } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1749 link->conf.Vpp1 = link->conf.Vpp2 = 1736 link->conf.Vpp =
1750 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 1737 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
1751 } 1738 }
1752 1739
@@ -1773,7 +1760,7 @@ static void nsp_cs_config(dev_link_t *link)
1773 link->io.NumPorts2 = io->win[1].len; 1760 link->io.NumPorts2 = io->win[1].len;
1774 } 1761 }
1775 /* This reserves IO space but doesn't actually enable it */ 1762 /* This reserves IO space but doesn't actually enable it */
1776 if (pcmcia_request_io(link->handle, &link->io) != 0) 1763 if (pcmcia_request_io(link, &link->io) != 0)
1777 goto next_entry; 1764 goto next_entry;
1778 } 1765 }
1779 1766
@@ -1788,7 +1775,7 @@ static void nsp_cs_config(dev_link_t *link)
1788 req.Size = 0x1000; 1775 req.Size = 0x1000;
1789 } 1776 }
1790 req.AccessSpeed = 0; 1777 req.AccessSpeed = 0;
1791 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 1778 if (pcmcia_request_window(&link, &req, &link->win) != 0)
1792 goto next_entry; 1779 goto next_entry;
1793 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 1780 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
1794 if (pcmcia_map_mem_page(link->win, &map) != 0) 1781 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -1802,17 +1789,14 @@ static void nsp_cs_config(dev_link_t *link)
1802 1789
1803 next_entry: 1790 next_entry:
1804 nsp_dbg(NSP_DEBUG_INIT, "next"); 1791 nsp_dbg(NSP_DEBUG_INIT, "next");
1805 1792 pcmcia_disable_device(link);
1806 if (link->io.NumPorts1) { 1793 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
1807 pcmcia_release_io(link->handle, &link->io);
1808 }
1809 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
1810 } 1794 }
1811 1795
1812 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 1796 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1813 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 1797 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
1814 } 1798 }
1815 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 1799 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
1816 1800
1817 if (free_ports) { 1801 if (free_ports) {
1818 if (link->io.BasePort1) { 1802 if (link->io.BasePort1) {
@@ -1854,16 +1838,19 @@ static void nsp_cs_config(dev_link_t *link)
1854 1838
1855 1839
1856#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)) 1840#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
1857 scsi_add_host (host, NULL); 1841 ret = scsi_add_host (host, NULL);
1842 if (ret)
1843 goto cs_failed;
1844
1858 scsi_scan_host(host); 1845 scsi_scan_host(host);
1859 1846
1860 snprintf(info->node.dev_name, sizeof(info->node.dev_name), "scsi%d", host->host_no); 1847 snprintf(info->node.dev_name, sizeof(info->node.dev_name), "scsi%d", host->host_no);
1861 link->dev = &info->node; 1848 link->dev_node = &info->node;
1862 info->host = host; 1849 info->host = host;
1863 1850
1864#else 1851#else
1865 nsp_dbg(NSP_DEBUG_INIT, "GET_SCSI_INFO"); 1852 nsp_dbg(NSP_DEBUG_INIT, "GET_SCSI_INFO");
1866 tail = &link->dev; 1853 tail = &link->dev_node;
1867 info->ndev = 0; 1854 info->ndev = 0;
1868 1855
1869 nsp_dbg(NSP_DEBUG_INIT, "host=0x%p", host); 1856 nsp_dbg(NSP_DEBUG_INIT, "host=0x%p", host);
@@ -1908,11 +1895,10 @@ static void nsp_cs_config(dev_link_t *link)
1908#endif 1895#endif
1909 1896
1910 /* Finally, report what we've done */ 1897 /* Finally, report what we've done */
1911 printk(KERN_INFO "nsp_cs: index 0x%02x: Vcc %d.%d", 1898 printk(KERN_INFO "nsp_cs: index 0x%02x: ",
1912 link->conf.ConfigIndex, 1899 link->conf.ConfigIndex);
1913 link->conf.Vcc/10, link->conf.Vcc%10); 1900 if (link->conf.Vpp) {
1914 if (link->conf.Vpp1) { 1901 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
1915 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
1916 } 1902 }
1917 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 1903 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1918 printk(", irq %d", link->irq.AssignedIRQ); 1904 printk(", irq %d", link->irq.AssignedIRQ);
@@ -1929,15 +1915,14 @@ static void nsp_cs_config(dev_link_t *link)
1929 req.Base+req.Size-1); 1915 req.Base+req.Size-1);
1930 printk("\n"); 1916 printk("\n");
1931 1917
1932 link->state &= ~DEV_CONFIG_PENDING; 1918 return 0;
1933 return;
1934 1919
1935 cs_failed: 1920 cs_failed:
1936 nsp_dbg(NSP_DEBUG_INIT, "config fail"); 1921 nsp_dbg(NSP_DEBUG_INIT, "config fail");
1937 cs_error(link->handle, last_fn, last_ret); 1922 cs_error(link, last_fn, last_ret);
1938 nsp_cs_release(link); 1923 nsp_cs_release(link);
1939 1924
1940 return; 1925 return -ENODEV;
1941} /* nsp_cs_config */ 1926} /* nsp_cs_config */
1942#undef CS_CHECK 1927#undef CS_CHECK
1943 1928
@@ -1947,7 +1932,7 @@ static void nsp_cs_config(dev_link_t *link)
1947 device, and release the PCMCIA configuration. If the device is 1932 device, and release the PCMCIA configuration. If the device is
1948 still open, this will be postponed until it is closed. 1933 still open, this will be postponed until it is closed.
1949======================================================================*/ 1934======================================================================*/
1950static void nsp_cs_release(dev_link_t *link) 1935static void nsp_cs_release(struct pcmcia_device *link)
1951{ 1936{
1952 scsi_info_t *info = link->priv; 1937 scsi_info_t *info = link->priv;
1953 nsp_hw_data *data = NULL; 1938 nsp_hw_data *data = NULL;
@@ -1968,22 +1953,15 @@ static void nsp_cs_release(dev_link_t *link)
1968#else 1953#else
1969 scsi_unregister_host(&nsp_driver_template); 1954 scsi_unregister_host(&nsp_driver_template);
1970#endif 1955#endif
1971 link->dev = NULL; 1956 link->dev_node = NULL;
1972 1957
1973 if (link->win) { 1958 if (link->win) {
1974 if (data != NULL) { 1959 if (data != NULL) {
1975 iounmap((void *)(data->MmioAddress)); 1960 iounmap((void *)(data->MmioAddress));
1976 } 1961 }
1977 pcmcia_release_window(link->win);
1978 }
1979 pcmcia_release_configuration(link->handle);
1980 if (link->io.NumPorts1) {
1981 pcmcia_release_io(link->handle, &link->io);
1982 } 1962 }
1983 if (link->irq.AssignedIRQ) { 1963 pcmcia_disable_device(link);
1984 pcmcia_release_irq(link->handle, &link->irq); 1964
1985 }
1986 link->state &= ~DEV_CONFIG;
1987#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2)) 1965#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2))
1988 if (info->host != NULL) { 1966 if (info->host != NULL) {
1989 scsi_host_put(info->host); 1967 scsi_host_put(info->host);
@@ -1991,14 +1969,11 @@ static void nsp_cs_release(dev_link_t *link)
1991#endif 1969#endif
1992} /* nsp_cs_release */ 1970} /* nsp_cs_release */
1993 1971
1994static int nsp_cs_suspend(struct pcmcia_device *dev) 1972static int nsp_cs_suspend(struct pcmcia_device *link)
1995{ 1973{
1996 dev_link_t *link = dev_to_instance(dev);
1997 scsi_info_t *info = link->priv; 1974 scsi_info_t *info = link->priv;
1998 nsp_hw_data *data; 1975 nsp_hw_data *data;
1999 1976
2000 link->state |= DEV_SUSPEND;
2001
2002 nsp_dbg(NSP_DEBUG_INIT, "event: suspend"); 1977 nsp_dbg(NSP_DEBUG_INIT, "event: suspend");
2003 1978
2004 if (info->host != NULL) { 1979 if (info->host != NULL) {
@@ -2011,25 +1986,16 @@ static int nsp_cs_suspend(struct pcmcia_device *dev)
2011 1986
2012 info->stop = 1; 1987 info->stop = 1;
2013 1988
2014 if (link->state & DEV_CONFIG)
2015 pcmcia_release_configuration(link->handle);
2016
2017 return 0; 1989 return 0;
2018} 1990}
2019 1991
2020static int nsp_cs_resume(struct pcmcia_device *dev) 1992static int nsp_cs_resume(struct pcmcia_device *link)
2021{ 1993{
2022 dev_link_t *link = dev_to_instance(dev);
2023 scsi_info_t *info = link->priv; 1994 scsi_info_t *info = link->priv;
2024 nsp_hw_data *data; 1995 nsp_hw_data *data;
2025 1996
2026 nsp_dbg(NSP_DEBUG_INIT, "event: resume"); 1997 nsp_dbg(NSP_DEBUG_INIT, "event: resume");
2027 1998
2028 link->state &= ~DEV_SUSPEND;
2029
2030 if (link->state & DEV_CONFIG)
2031 pcmcia_request_configuration(link->handle, &link->conf);
2032
2033 info->stop = 0; 1999 info->stop = 0;
2034 2000
2035 if (info->host != NULL) { 2001 if (info->host != NULL) {
@@ -2065,7 +2031,7 @@ static struct pcmcia_driver nsp_driver = {
2065 .drv = { 2031 .drv = {
2066 .name = "nsp_cs", 2032 .name = "nsp_cs",
2067 }, 2033 },
2068 .probe = nsp_cs_attach, 2034 .probe = nsp_cs_probe,
2069 .remove = nsp_cs_detach, 2035 .remove = nsp_cs_detach,
2070 .id_table = nsp_cs_ids, 2036 .id_table = nsp_cs_ids,
2071 .suspend = nsp_cs_suspend, 2037 .suspend = nsp_cs_suspend,
@@ -2098,19 +2064,7 @@ static int __init nsp_cs_init(void)
2098static void __exit nsp_cs_exit(void) 2064static void __exit nsp_cs_exit(void)
2099{ 2065{
2100 nsp_msg(KERN_INFO, "unloading..."); 2066 nsp_msg(KERN_INFO, "unloading...");
2101
2102#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68))
2103 pcmcia_unregister_driver(&nsp_driver); 2067 pcmcia_unregister_driver(&nsp_driver);
2104#else
2105 unregister_pcmcia_driver(&dev_info);
2106 /* XXX: this really needs to move into generic code.. */
2107 while (dev_list != NULL) {
2108 if (dev_list->state & DEV_CONFIG) {
2109 nsp_cs_release(dev_list);
2110 }
2111 nsp_cs_detach(dev_list);
2112 }
2113#endif
2114} 2068}
2115 2069
2116 2070
diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h
index b66b140a745e..8908b8e5b78a 100644
--- a/drivers/scsi/pcmcia/nsp_cs.h
+++ b/drivers/scsi/pcmcia/nsp_cs.h
@@ -225,7 +225,7 @@
225/*====================================================================*/ 225/*====================================================================*/
226 226
227typedef struct scsi_info_t { 227typedef struct scsi_info_t {
228 dev_link_t link; 228 struct pcmcia_device *p_dev;
229 struct Scsi_Host *host; 229 struct Scsi_Host *host;
230#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)) 230#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
231 dev_node_t node; 231 dev_node_t node;
@@ -297,8 +297,8 @@ typedef struct _nsp_hw_data {
297 297
298/* Card service functions */ 298/* Card service functions */
299static void nsp_cs_detach (struct pcmcia_device *p_dev); 299static void nsp_cs_detach (struct pcmcia_device *p_dev);
300static void nsp_cs_release(dev_link_t *link); 300static void nsp_cs_release(struct pcmcia_device *link);
301static void nsp_cs_config (dev_link_t *link); 301static int nsp_cs_config (struct pcmcia_device *link);
302 302
303/* Linux SCSI subsystem specific functions */ 303/* Linux SCSI subsystem specific functions */
304static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht); 304static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht);
@@ -450,7 +450,7 @@ static inline struct Scsi_Host *scsi_host_hn_get(unsigned short hostno)
450 return host; 450 return host;
451} 451}
452 452
453static void cs_error(client_handle_t handle, int func, int ret) 453static void cs_error(struct pcmcia_device *handle, int func, int ret)
454{ 454{
455 error_info_t err = { func, ret }; 455 error_info_t err = { func, ret };
456 pcmcia_report_error(handle, &err); 456 pcmcia_report_error(handle, &err);
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index dce7e687fd4a..86c2ac6ae623 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -91,18 +91,18 @@ static struct scsi_host_template qlogicfas_driver_template = {
91/*====================================================================*/ 91/*====================================================================*/
92 92
93typedef struct scsi_info_t { 93typedef struct scsi_info_t {
94 dev_link_t link; 94 struct pcmcia_device *p_dev;
95 dev_node_t node; 95 dev_node_t node;
96 struct Scsi_Host *host; 96 struct Scsi_Host *host;
97 unsigned short manf_id; 97 unsigned short manf_id;
98} scsi_info_t; 98} scsi_info_t;
99 99
100static void qlogic_release(dev_link_t *link); 100static void qlogic_release(struct pcmcia_device *link);
101static void qlogic_detach(struct pcmcia_device *p_dev); 101static void qlogic_detach(struct pcmcia_device *p_dev);
102static void qlogic_config(dev_link_t * link); 102static int qlogic_config(struct pcmcia_device * link);
103 103
104static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host, 104static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host,
105 dev_link_t *link, int qbase, int qlirq) 105 struct pcmcia_device *link, int qbase, int qlirq)
106{ 106{
107 int qltyp; /* type of chip */ 107 int qltyp; /* type of chip */
108 int qinitid; 108 int qinitid;
@@ -156,10 +156,9 @@ free_scsi_host:
156err: 156err:
157 return NULL; 157 return NULL;
158} 158}
159static int qlogic_attach(struct pcmcia_device *p_dev) 159static int qlogic_probe(struct pcmcia_device *link)
160{ 160{
161 scsi_info_t *info; 161 scsi_info_t *info;
162 dev_link_t *link;
163 162
164 DEBUG(0, "qlogic_attach()\n"); 163 DEBUG(0, "qlogic_attach()\n");
165 164
@@ -168,7 +167,7 @@ static int qlogic_attach(struct pcmcia_device *p_dev)
168 if (!info) 167 if (!info)
169 return -ENOMEM; 168 return -ENOMEM;
170 memset(info, 0, sizeof(*info)); 169 memset(info, 0, sizeof(*info));
171 link = &info->link; 170 info->p_dev = link;
172 link->priv = info; 171 link->priv = info;
173 link->io.NumPorts1 = 16; 172 link->io.NumPorts1 = 16;
174 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 173 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -176,30 +175,19 @@ static int qlogic_attach(struct pcmcia_device *p_dev)
176 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 175 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
177 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 176 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
178 link->conf.Attributes = CONF_ENABLE_IRQ; 177 link->conf.Attributes = CONF_ENABLE_IRQ;
179 link->conf.Vcc = 50;
180 link->conf.IntType = INT_MEMORY_AND_IO; 178 link->conf.IntType = INT_MEMORY_AND_IO;
181 link->conf.Present = PRESENT_OPTION; 179 link->conf.Present = PRESENT_OPTION;
182 180
183 link->handle = p_dev; 181 return qlogic_config(link);
184 p_dev->instance = link;
185
186 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
187 qlogic_config(link);
188
189 return 0;
190} /* qlogic_attach */ 182} /* qlogic_attach */
191 183
192/*====================================================================*/ 184/*====================================================================*/
193 185
194static void qlogic_detach(struct pcmcia_device *p_dev) 186static void qlogic_detach(struct pcmcia_device *link)
195{ 187{
196 dev_link_t *link = dev_to_instance(p_dev);
197
198 DEBUG(0, "qlogic_detach(0x%p)\n", link); 188 DEBUG(0, "qlogic_detach(0x%p)\n", link);
199 189
200 if (link->state & DEV_CONFIG) 190 qlogic_release(link);
201 qlogic_release(link);
202
203 kfree(link->priv); 191 kfree(link->priv);
204 192
205} /* qlogic_detach */ 193} /* qlogic_detach */
@@ -209,9 +197,8 @@ static void qlogic_detach(struct pcmcia_device *p_dev)
209#define CS_CHECK(fn, ret) \ 197#define CS_CHECK(fn, ret) \
210do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 198do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
211 199
212static void qlogic_config(dev_link_t * link) 200static int qlogic_config(struct pcmcia_device * link)
213{ 201{
214 client_handle_t handle = link->handle;
215 scsi_info_t *info = link->priv; 202 scsi_info_t *info = link->priv;
216 tuple_t tuple; 203 tuple_t tuple;
217 cisparse_t parse; 204 cisparse_t parse;
@@ -225,38 +212,35 @@ static void qlogic_config(dev_link_t * link)
225 tuple.TupleDataMax = 64; 212 tuple.TupleDataMax = 64;
226 tuple.TupleOffset = 0; 213 tuple.TupleOffset = 0;
227 tuple.DesiredTuple = CISTPL_CONFIG; 214 tuple.DesiredTuple = CISTPL_CONFIG;
228 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 215 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
229 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 216 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
230 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 217 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
231 link->conf.ConfigBase = parse.config.base; 218 link->conf.ConfigBase = parse.config.base;
232 219
233 tuple.DesiredTuple = CISTPL_MANFID; 220 tuple.DesiredTuple = CISTPL_MANFID;
234 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) 221 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS))
235 info->manf_id = le16_to_cpu(tuple.TupleData[0]); 222 info->manf_id = le16_to_cpu(tuple.TupleData[0]);
236 223
237 /* Configure card */
238 link->state |= DEV_CONFIG;
239
240 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 224 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
241 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 225 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
242 while (1) { 226 while (1) {
243 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 227 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
244 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 228 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
245 goto next_entry; 229 goto next_entry;
246 link->conf.ConfigIndex = parse.cftable_entry.index; 230 link->conf.ConfigIndex = parse.cftable_entry.index;
247 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 231 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
248 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; 232 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
249 if (link->io.BasePort1 != 0) { 233 if (link->io.BasePort1 != 0) {
250 i = pcmcia_request_io(handle, &link->io); 234 i = pcmcia_request_io(link, &link->io);
251 if (i == CS_SUCCESS) 235 if (i == CS_SUCCESS)
252 break; 236 break;
253 } 237 }
254 next_entry: 238 next_entry:
255 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 239 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
256 } 240 }
257 241
258 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 242 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
259 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 243 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
260 244
261 if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) { 245 if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) {
262 /* set ATAcmd */ 246 /* set ATAcmd */
@@ -275,82 +259,54 @@ static void qlogic_config(dev_link_t * link)
275 259
276 if (!host) { 260 if (!host) {
277 printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name); 261 printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name);
278 goto out; 262 goto cs_failed;
279 } 263 }
280 264
281 sprintf(info->node.dev_name, "scsi%d", host->host_no); 265 sprintf(info->node.dev_name, "scsi%d", host->host_no);
282 link->dev = &info->node; 266 link->dev_node = &info->node;
283 info->host = host; 267 info->host = host;
284 268
285out: 269 return 0;
286 link->state &= ~DEV_CONFIG_PENDING;
287 return;
288 270
289cs_failed: 271cs_failed:
290 cs_error(link->handle, last_fn, last_ret); 272 cs_error(link, last_fn, last_ret);
291 link->dev = NULL; 273 pcmcia_disable_device(link);
292 pcmcia_release_configuration(link->handle); 274 return -ENODEV;
293 pcmcia_release_io(link->handle, &link->io);
294 pcmcia_release_irq(link->handle, &link->irq);
295 link->state &= ~DEV_CONFIG;
296 return;
297 275
298} /* qlogic_config */ 276} /* qlogic_config */
299 277
300/*====================================================================*/ 278/*====================================================================*/
301 279
302static void qlogic_release(dev_link_t *link) 280static void qlogic_release(struct pcmcia_device *link)
303{ 281{
304 scsi_info_t *info = link->priv; 282 scsi_info_t *info = link->priv;
305 283
306 DEBUG(0, "qlogic_release(0x%p)\n", link); 284 DEBUG(0, "qlogic_release(0x%p)\n", link);
307 285
308 scsi_remove_host(info->host); 286 scsi_remove_host(info->host);
309 link->dev = NULL;
310 287
311 free_irq(link->irq.AssignedIRQ, info->host); 288 free_irq(link->irq.AssignedIRQ, info->host);
312 289 pcmcia_disable_device(link);
313 pcmcia_release_configuration(link->handle);
314 pcmcia_release_io(link->handle, &link->io);
315 pcmcia_release_irq(link->handle, &link->irq);
316 290
317 scsi_host_put(info->host); 291 scsi_host_put(info->host);
318
319 link->state &= ~DEV_CONFIG;
320} 292}
321 293
322/*====================================================================*/ 294/*====================================================================*/
323 295
324static int qlogic_suspend(struct pcmcia_device *dev) 296static int qlogic_resume(struct pcmcia_device *link)
325{ 297{
326 dev_link_t *link = dev_to_instance(dev); 298 scsi_info_t *info = link->priv;
327
328 link->state |= DEV_SUSPEND;
329 if (link->state & DEV_CONFIG)
330 pcmcia_release_configuration(link->handle);
331
332 return 0;
333}
334 299
335static int qlogic_resume(struct pcmcia_device *dev) 300 pcmcia_request_configuration(link, &link->conf);
336{ 301 if ((info->manf_id == MANFID_MACNICA) ||
337 dev_link_t *link = dev_to_instance(dev); 302 (info->manf_id == MANFID_PIONEER) ||
338 303 (info->manf_id == 0x0098)) {
339 link->state &= ~DEV_SUSPEND; 304 outb(0x80, link->io.BasePort1 + 0xd);
340 if (link->state & DEV_CONFIG) { 305 outb(0x24, link->io.BasePort1 + 0x9);
341 scsi_info_t *info = link->priv; 306 outb(0x04, link->io.BasePort1 + 0xd);
342
343 pcmcia_request_configuration(link->handle, &link->conf);
344 if ((info->manf_id == MANFID_MACNICA) ||
345 (info->manf_id == MANFID_PIONEER) ||
346 (info->manf_id == 0x0098)) {
347 outb(0x80, link->io.BasePort1 + 0xd);
348 outb(0x24, link->io.BasePort1 + 0x9);
349 outb(0x04, link->io.BasePort1 + 0xd);
350 }
351 /* Ugggglllyyyy!!! */
352 qlogicfas408_bus_reset(NULL);
353 } 307 }
308 /* Ugggglllyyyy!!! */
309 qlogicfas408_bus_reset(NULL);
354 310
355 return 0; 311 return 0;
356} 312}
@@ -382,10 +338,9 @@ static struct pcmcia_driver qlogic_cs_driver = {
382 .drv = { 338 .drv = {
383 .name = "qlogic_cs", 339 .name = "qlogic_cs",
384 }, 340 },
385 .probe = qlogic_attach, 341 .probe = qlogic_probe,
386 .remove = qlogic_detach, 342 .remove = qlogic_detach,
387 .id_table = qlogic_ids, 343 .id_table = qlogic_ids,
388 .suspend = qlogic_suspend,
389 .resume = qlogic_resume, 344 .resume = qlogic_resume,
390}; 345};
391 346
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 3a4dd6f5b81f..9f59827707f0 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -202,7 +202,7 @@ static char *version =
202/* ================================================================== */ 202/* ================================================================== */
203 203
204struct scsi_info_t { 204struct scsi_info_t {
205 dev_link_t link; 205 struct pcmcia_device *p_dev;
206 dev_node_t node; 206 dev_node_t node;
207 struct Scsi_Host *host; 207 struct Scsi_Host *host;
208 unsigned short manf_id; 208 unsigned short manf_id;
@@ -527,7 +527,7 @@ idle_out:
527} 527}
528 528
529static void 529static void
530SYM53C500_release(dev_link_t *link) 530SYM53C500_release(struct pcmcia_device *link)
531{ 531{
532 struct scsi_info_t *info = link->priv; 532 struct scsi_info_t *info = link->priv;
533 struct Scsi_Host *shost = info->host; 533 struct Scsi_Host *shost = info->host;
@@ -550,13 +550,7 @@ SYM53C500_release(dev_link_t *link)
550 if (shost->io_port && shost->n_io_port) 550 if (shost->io_port && shost->n_io_port)
551 release_region(shost->io_port, shost->n_io_port); 551 release_region(shost->io_port, shost->n_io_port);
552 552
553 link->dev = NULL; 553 pcmcia_disable_device(link);
554
555 pcmcia_release_configuration(link->handle);
556 pcmcia_release_io(link->handle, &link->io);
557 pcmcia_release_irq(link->handle, &link->irq);
558
559 link->state &= ~DEV_CONFIG;
560 554
561 scsi_host_put(shost); 555 scsi_host_put(shost);
562} /* SYM53C500_release */ 556} /* SYM53C500_release */
@@ -713,10 +707,9 @@ static struct scsi_host_template sym53c500_driver_template = {
713#define CS_CHECK(fn, ret) \ 707#define CS_CHECK(fn, ret) \
714do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 708do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
715 709
716static void 710static int
717SYM53C500_config(dev_link_t *link) 711SYM53C500_config(struct pcmcia_device *link)
718{ 712{
719 client_handle_t handle = link->handle;
720 struct scsi_info_t *info = link->priv; 713 struct scsi_info_t *info = link->priv;
721 tuple_t tuple; 714 tuple_t tuple;
722 cisparse_t parse; 715 cisparse_t parse;
@@ -733,40 +726,37 @@ SYM53C500_config(dev_link_t *link)
733 tuple.TupleDataMax = 64; 726 tuple.TupleDataMax = 64;
734 tuple.TupleOffset = 0; 727 tuple.TupleOffset = 0;
735 tuple.DesiredTuple = CISTPL_CONFIG; 728 tuple.DesiredTuple = CISTPL_CONFIG;
736 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 729 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
737 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 730 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
738 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 731 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
739 link->conf.ConfigBase = parse.config.base; 732 link->conf.ConfigBase = parse.config.base;
740 733
741 tuple.DesiredTuple = CISTPL_MANFID; 734 tuple.DesiredTuple = CISTPL_MANFID;
742 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 735 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) &&
743 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) 736 (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS))
744 info->manf_id = le16_to_cpu(tuple.TupleData[0]); 737 info->manf_id = le16_to_cpu(tuple.TupleData[0]);
745 738
746 /* Configure card */
747 link->state |= DEV_CONFIG;
748
749 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 739 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
750 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 740 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
751 while (1) { 741 while (1) {
752 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 742 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
753 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 743 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
754 goto next_entry; 744 goto next_entry;
755 link->conf.ConfigIndex = parse.cftable_entry.index; 745 link->conf.ConfigIndex = parse.cftable_entry.index;
756 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 746 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
757 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; 747 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
758 748
759 if (link->io.BasePort1 != 0) { 749 if (link->io.BasePort1 != 0) {
760 i = pcmcia_request_io(handle, &link->io); 750 i = pcmcia_request_io(link, &link->io);
761 if (i == CS_SUCCESS) 751 if (i == CS_SUCCESS)
762 break; 752 break;
763 } 753 }
764next_entry: 754next_entry:
765 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 755 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
766 } 756 }
767 757
768 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 758 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
769 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 759 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
770 760
771 /* 761 /*
772 * That's the trouble with copying liberally from another driver. 762 * That's the trouble with copying liberally from another driver.
@@ -835,7 +825,7 @@ next_entry:
835 data->fast_pio = USE_FAST_PIO; 825 data->fast_pio = USE_FAST_PIO;
836 826
837 sprintf(info->node.dev_name, "scsi%d", host->host_no); 827 sprintf(info->node.dev_name, "scsi%d", host->host_no);
838 link->dev = &info->node; 828 link->dev_node = &info->node;
839 info->host = host; 829 info->host = host;
840 830
841 if (scsi_add_host(host, NULL)) 831 if (scsi_add_host(host, NULL))
@@ -843,7 +833,7 @@ next_entry:
843 833
844 scsi_scan_host(host); 834 scsi_scan_host(host);
845 835
846 goto out; /* SUCCESS */ 836 return 0;
847 837
848err_free_irq: 838err_free_irq:
849 free_irq(irq_level, host); 839 free_irq(irq_level, host);
@@ -852,74 +842,50 @@ err_free_scsi:
852err_release: 842err_release:
853 release_region(port_base, 0x10); 843 release_region(port_base, 0x10);
854 printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n"); 844 printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n");
855 845 return -ENODEV;
856out:
857 link->state &= ~DEV_CONFIG_PENDING;
858 return;
859 846
860cs_failed: 847cs_failed:
861 cs_error(link->handle, last_fn, last_ret); 848 cs_error(link, last_fn, last_ret);
862 SYM53C500_release(link); 849 SYM53C500_release(link);
863 return; 850 return -ENODEV;
864} /* SYM53C500_config */ 851} /* SYM53C500_config */
865 852
866static int sym53c500_suspend(struct pcmcia_device *dev) 853static int sym53c500_resume(struct pcmcia_device *link)
867{
868 dev_link_t *link = dev_to_instance(dev);
869
870 link->state |= DEV_SUSPEND;
871 if (link->state & DEV_CONFIG)
872 pcmcia_release_configuration(link->handle);
873
874 return 0;
875}
876
877static int sym53c500_resume(struct pcmcia_device *dev)
878{ 854{
879 dev_link_t *link = dev_to_instance(dev);
880 struct scsi_info_t *info = link->priv; 855 struct scsi_info_t *info = link->priv;
881 856
882 link->state &= ~DEV_SUSPEND; 857 /* See earlier comment about manufacturer IDs. */
883 if (link->state & DEV_CONFIG) { 858 if ((info->manf_id == MANFID_MACNICA) ||
884 pcmcia_request_configuration(link->handle, &link->conf); 859 (info->manf_id == MANFID_PIONEER) ||
885 860 (info->manf_id == 0x0098)) {
886 /* See earlier comment about manufacturer IDs. */ 861 outb(0x80, link->io.BasePort1 + 0xd);
887 if ((info->manf_id == MANFID_MACNICA) || 862 outb(0x24, link->io.BasePort1 + 0x9);
888 (info->manf_id == MANFID_PIONEER) || 863 outb(0x04, link->io.BasePort1 + 0xd);
889 (info->manf_id == 0x0098)) {
890 outb(0x80, link->io.BasePort1 + 0xd);
891 outb(0x24, link->io.BasePort1 + 0x9);
892 outb(0x04, link->io.BasePort1 + 0xd);
893 }
894 /*
895 * If things don't work after a "resume",
896 * this is a good place to start looking.
897 */
898 SYM53C500_int_host_reset(link->io.BasePort1);
899 } 864 }
865 /*
866 * If things don't work after a "resume",
867 * this is a good place to start looking.
868 */
869 SYM53C500_int_host_reset(link->io.BasePort1);
900 870
901 return 0; 871 return 0;
902} 872}
903 873
904static void 874static void
905SYM53C500_detach(struct pcmcia_device *p_dev) 875SYM53C500_detach(struct pcmcia_device *link)
906{ 876{
907 dev_link_t *link = dev_to_instance(p_dev);
908
909 DEBUG(0, "SYM53C500_detach(0x%p)\n", link); 877 DEBUG(0, "SYM53C500_detach(0x%p)\n", link);
910 878
911 if (link->state & DEV_CONFIG) 879 SYM53C500_release(link);
912 SYM53C500_release(link);
913 880
914 kfree(link->priv); 881 kfree(link->priv);
915 link->priv = NULL; 882 link->priv = NULL;
916} /* SYM53C500_detach */ 883} /* SYM53C500_detach */
917 884
918static int 885static int
919SYM53C500_attach(struct pcmcia_device *p_dev) 886SYM53C500_probe(struct pcmcia_device *link)
920{ 887{
921 struct scsi_info_t *info; 888 struct scsi_info_t *info;
922 dev_link_t *link;
923 889
924 DEBUG(0, "SYM53C500_attach()\n"); 890 DEBUG(0, "SYM53C500_attach()\n");
925 891
@@ -928,7 +894,7 @@ SYM53C500_attach(struct pcmcia_device *p_dev)
928 if (!info) 894 if (!info)
929 return -ENOMEM; 895 return -ENOMEM;
930 memset(info, 0, sizeof(*info)); 896 memset(info, 0, sizeof(*info));
931 link = &info->link; 897 info->p_dev = link;
932 link->priv = info; 898 link->priv = info;
933 link->io.NumPorts1 = 16; 899 link->io.NumPorts1 = 16;
934 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 900 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -936,17 +902,10 @@ SYM53C500_attach(struct pcmcia_device *p_dev)
936 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 902 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
937 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 903 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
938 link->conf.Attributes = CONF_ENABLE_IRQ; 904 link->conf.Attributes = CONF_ENABLE_IRQ;
939 link->conf.Vcc = 50;
940 link->conf.IntType = INT_MEMORY_AND_IO; 905 link->conf.IntType = INT_MEMORY_AND_IO;
941 link->conf.Present = PRESENT_OPTION; 906 link->conf.Present = PRESENT_OPTION;
942 907
943 link->handle = p_dev; 908 return SYM53C500_config(link);
944 p_dev->instance = link;
945
946 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
947 SYM53C500_config(link);
948
949 return 0;
950} /* SYM53C500_attach */ 909} /* SYM53C500_attach */
951 910
952MODULE_AUTHOR("Bob Tracy <rct@frus.com>"); 911MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
@@ -966,10 +925,9 @@ static struct pcmcia_driver sym53c500_cs_driver = {
966 .drv = { 925 .drv = {
967 .name = "sym53c500_cs", 926 .name = "sym53c500_cs",
968 }, 927 },
969 .probe = SYM53C500_attach, 928 .probe = SYM53C500_probe,
970 .remove = SYM53C500_detach, 929 .remove = SYM53C500_detach,
971 .id_table = sym53c500_ids, 930 .id_table = sym53c500_ids,
972 .suspend = sym53c500_suspend,
973 .resume = sym53c500_resume, 931 .resume = sym53c500_resume,
974}; 932};
975 933
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index c30333694fde..2c70773543e0 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -41,6 +41,7 @@
41#include <linux/string.h> 41#include <linux/string.h>
42#include <linux/timer.h> 42#include <linux/timer.h>
43#include <linux/serial_core.h> 43#include <linux/serial_core.h>
44#include <linux/delay.h>
44#include <linux/major.h> 45#include <linux/major.h>
45#include <asm/io.h> 46#include <asm/io.h>
46#include <asm/system.h> 47#include <asm/system.h>
@@ -97,11 +98,13 @@ static const struct multi_id multi_id[] = {
97#define MULTI_COUNT (sizeof(multi_id)/sizeof(struct multi_id)) 98#define MULTI_COUNT (sizeof(multi_id)/sizeof(struct multi_id))
98 99
99struct serial_info { 100struct serial_info {
100 dev_link_t link; 101 struct pcmcia_device *p_dev;
101 int ndev; 102 int ndev;
102 int multi; 103 int multi;
103 int slave; 104 int slave;
104 int manfid; 105 int manfid;
106 int prodid;
107 int c950ctrl;
105 dev_node_t node[4]; 108 dev_node_t node[4];
106 int line[4]; 109 int line[4];
107}; 110};
@@ -113,9 +116,36 @@ struct serial_cfg_mem {
113}; 116};
114 117
115 118
116static void serial_config(dev_link_t * link); 119static int serial_config(struct pcmcia_device * link);
117 120
118 121
122static void wakeup_card(struct serial_info *info)
123{
124 int ctrl = info->c950ctrl;
125
126 if (info->manfid == MANFID_OXSEMI) {
127 outb(12, ctrl + 1);
128 } else if (info->manfid == MANFID_POSSIO && info->prodid == PRODID_POSSIO_GCC) {
129 /* request_region? oxsemi branch does no request_region too... */
130 /* This sequence is needed to properly initialize MC45 attached to OXCF950.
131 * I tried decreasing these msleep()s, but it worked properly (survived
132 * 1000 stop/start operations) with these timeouts (or bigger). */
133 outb(0xA, ctrl + 1);
134 msleep(100);
135 outb(0xE, ctrl + 1);
136 msleep(300);
137 outb(0xC, ctrl + 1);
138 msleep(100);
139 outb(0xE, ctrl + 1);
140 msleep(200);
141 outb(0xF, ctrl + 1);
142 msleep(100);
143 outb(0xE, ctrl + 1);
144 msleep(100);
145 outb(0xC, ctrl + 1);
146 }
147}
148
119/*====================================================================== 149/*======================================================================
120 150
121 After a card is removed, serial_remove() will unregister 151 After a card is removed, serial_remove() will unregister
@@ -123,67 +153,45 @@ static void serial_config(dev_link_t * link);
123 153
124======================================================================*/ 154======================================================================*/
125 155
126static void serial_remove(dev_link_t *link) 156static void serial_remove(struct pcmcia_device *link)
127{ 157{
128 struct serial_info *info = link->priv; 158 struct serial_info *info = link->priv;
129 int i; 159 int i;
130 160
131 link->state &= ~DEV_PRESENT;
132
133 DEBUG(0, "serial_release(0x%p)\n", link); 161 DEBUG(0, "serial_release(0x%p)\n", link);
134 162
135 /* 163 /*
136 * Recheck to see if the device is still configured. 164 * Recheck to see if the device is still configured.
137 */ 165 */
138 if (info->link.state & DEV_CONFIG) { 166 for (i = 0; i < info->ndev; i++)
139 for (i = 0; i < info->ndev; i++) 167 serial8250_unregister_port(info->line[i]);
140 serial8250_unregister_port(info->line[i]);
141 168
142 info->link.dev = NULL; 169 info->p_dev->dev_node = NULL;
143 170
144 if (!info->slave) { 171 if (!info->slave)
145 pcmcia_release_configuration(info->link.handle); 172 pcmcia_disable_device(link);
146 pcmcia_release_io(info->link.handle, &info->link.io);
147 pcmcia_release_irq(info->link.handle, &info->link.irq);
148 }
149
150 info->link.state &= ~DEV_CONFIG;
151 }
152} 173}
153 174
154static int serial_suspend(struct pcmcia_device *dev) 175static int serial_suspend(struct pcmcia_device *link)
155{ 176{
156 dev_link_t *link = dev_to_instance(dev); 177 struct serial_info *info = link->priv;
157 link->state |= DEV_SUSPEND; 178 int i;
158
159 if (link->state & DEV_CONFIG) {
160 struct serial_info *info = link->priv;
161 int i;
162
163 for (i = 0; i < info->ndev; i++)
164 serial8250_suspend_port(info->line[i]);
165 179
166 if (!info->slave) 180 for (i = 0; i < info->ndev; i++)
167 pcmcia_release_configuration(link->handle); 181 serial8250_suspend_port(info->line[i]);
168 }
169 182
170 return 0; 183 return 0;
171} 184}
172 185
173static int serial_resume(struct pcmcia_device *dev) 186static int serial_resume(struct pcmcia_device *link)
174{ 187{
175 dev_link_t *link = dev_to_instance(dev); 188 if (pcmcia_dev_present(link)) {
176 link->state &= ~DEV_SUSPEND;
177
178 if (DEV_OK(link)) {
179 struct serial_info *info = link->priv; 189 struct serial_info *info = link->priv;
180 int i; 190 int i;
181 191
182 if (!info->slave)
183 pcmcia_request_configuration(link->handle, &link->conf);
184
185 for (i = 0; i < info->ndev; i++) 192 for (i = 0; i < info->ndev; i++)
186 serial8250_resume_port(info->line[i]); 193 serial8250_resume_port(info->line[i]);
194 wakeup_card(info);
187 } 195 }
188 196
189 return 0; 197 return 0;
@@ -197,10 +205,9 @@ static int serial_resume(struct pcmcia_device *dev)
197 205
198======================================================================*/ 206======================================================================*/
199 207
200static int serial_probe(struct pcmcia_device *p_dev) 208static int serial_probe(struct pcmcia_device *link)
201{ 209{
202 struct serial_info *info; 210 struct serial_info *info;
203 dev_link_t *link;
204 211
205 DEBUG(0, "serial_attach()\n"); 212 DEBUG(0, "serial_attach()\n");
206 213
@@ -209,7 +216,7 @@ static int serial_probe(struct pcmcia_device *p_dev)
209 if (!info) 216 if (!info)
210 return -ENOMEM; 217 return -ENOMEM;
211 memset(info, 0, sizeof (*info)); 218 memset(info, 0, sizeof (*info));
212 link = &info->link; 219 info->p_dev = link;
213 link->priv = info; 220 link->priv = info;
214 221
215 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 222 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -223,12 +230,7 @@ static int serial_probe(struct pcmcia_device *p_dev)
223 } 230 }
224 link->conf.IntType = INT_MEMORY_AND_IO; 231 link->conf.IntType = INT_MEMORY_AND_IO;
225 232
226 link->handle = p_dev; 233 return serial_config(link);
227 p_dev->instance = link;
228 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
229 serial_config(link);
230
231 return 0;
232} 234}
233 235
234/*====================================================================== 236/*======================================================================
@@ -240,9 +242,8 @@ static int serial_probe(struct pcmcia_device *p_dev)
240 242
241======================================================================*/ 243======================================================================*/
242 244
243static void serial_detach(struct pcmcia_device *p_dev) 245static void serial_detach(struct pcmcia_device *link)
244{ 246{
245 dev_link_t *link = dev_to_instance(p_dev);
246 struct serial_info *info = link->priv; 247 struct serial_info *info = link->priv;
247 248
248 DEBUG(0, "serial_detach(0x%p)\n", link); 249 DEBUG(0, "serial_detach(0x%p)\n", link);
@@ -263,7 +264,7 @@ static void serial_detach(struct pcmcia_device *p_dev)
263 264
264/*====================================================================*/ 265/*====================================================================*/
265 266
266static int setup_serial(client_handle_t handle, struct serial_info * info, 267static int setup_serial(struct pcmcia_device *handle, struct serial_info * info,
267 kio_addr_t iobase, int irq) 268 kio_addr_t iobase, int irq)
268{ 269{
269 struct uart_port port; 270 struct uart_port port;
@@ -298,7 +299,7 @@ static int setup_serial(client_handle_t handle, struct serial_info * info,
298/*====================================================================*/ 299/*====================================================================*/
299 300
300static int 301static int
301first_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse) 302first_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
302{ 303{
303 int i; 304 int i;
304 i = pcmcia_get_first_tuple(handle, tuple); 305 i = pcmcia_get_first_tuple(handle, tuple);
@@ -311,7 +312,7 @@ first_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse)
311} 312}
312 313
313static int 314static int
314next_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse) 315next_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
315{ 316{
316 int i; 317 int i;
317 i = pcmcia_get_next_tuple(handle, tuple); 318 i = pcmcia_get_next_tuple(handle, tuple);
@@ -325,11 +326,10 @@ next_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse)
325 326
326/*====================================================================*/ 327/*====================================================================*/
327 328
328static int simple_config(dev_link_t *link) 329static int simple_config(struct pcmcia_device *link)
329{ 330{
330 static const kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 331 static const kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
331 static const int size_table[2] = { 8, 16 }; 332 static const int size_table[2] = { 8, 16 };
332 client_handle_t handle = link->handle;
333 struct serial_info *info = link->priv; 333 struct serial_info *info = link->priv;
334 struct serial_cfg_mem *cfg_mem; 334 struct serial_cfg_mem *cfg_mem;
335 tuple_t *tuple; 335 tuple_t *tuple;
@@ -350,7 +350,7 @@ static int simple_config(dev_link_t *link)
350 buf = cfg_mem->buf; 350 buf = cfg_mem->buf;
351 351
352 /* If the card is already configured, look up the port and irq */ 352 /* If the card is already configured, look up the port and irq */
353 i = pcmcia_get_configuration_info(handle, &config); 353 i = pcmcia_get_configuration_info(link, &config);
354 if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) { 354 if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) {
355 kio_addr_t port = 0; 355 kio_addr_t port = 0;
356 if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) { 356 if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) {
@@ -363,10 +363,9 @@ static int simple_config(dev_link_t *link)
363 } 363 }
364 if (info->slave) { 364 if (info->slave) {
365 kfree(cfg_mem); 365 kfree(cfg_mem);
366 return setup_serial(handle, info, port, config.AssignedIRQ); 366 return setup_serial(link, info, port, config.AssignedIRQ);
367 } 367 }
368 } 368 }
369 link->conf.Vcc = config.Vcc;
370 369
371 /* First pass: look for a config entry that looks normal. */ 370 /* First pass: look for a config entry that looks normal. */
372 tuple->TupleData = (cisdata_t *) buf; 371 tuple->TupleData = (cisdata_t *) buf;
@@ -377,12 +376,12 @@ static int simple_config(dev_link_t *link)
377 /* Two tries: without IO aliases, then with aliases */ 376 /* Two tries: without IO aliases, then with aliases */
378 for (s = 0; s < 2; s++) { 377 for (s = 0; s < 2; s++) {
379 for (try = 0; try < 2; try++) { 378 for (try = 0; try < 2; try++) {
380 i = first_tuple(handle, tuple, parse); 379 i = first_tuple(link, tuple, parse);
381 while (i != CS_NO_MORE_ITEMS) { 380 while (i != CS_NO_MORE_ITEMS) {
382 if (i != CS_SUCCESS) 381 if (i != CS_SUCCESS)
383 goto next_entry; 382 goto next_entry;
384 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 383 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
385 link->conf.Vpp1 = link->conf.Vpp2 = 384 link->conf.Vpp =
386 cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 385 cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
387 if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[s]) && 386 if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[s]) &&
388 (cf->io.win[0].base != 0)) { 387 (cf->io.win[0].base != 0)) {
@@ -390,19 +389,19 @@ static int simple_config(dev_link_t *link)
390 link->io.BasePort1 = cf->io.win[0].base; 389 link->io.BasePort1 = cf->io.win[0].base;
391 link->io.IOAddrLines = (try == 0) ? 390 link->io.IOAddrLines = (try == 0) ?
392 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 391 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
393 i = pcmcia_request_io(link->handle, &link->io); 392 i = pcmcia_request_io(link, &link->io);
394 if (i == CS_SUCCESS) 393 if (i == CS_SUCCESS)
395 goto found_port; 394 goto found_port;
396 } 395 }
397next_entry: 396next_entry:
398 i = next_tuple(handle, tuple, parse); 397 i = next_tuple(link, tuple, parse);
399 } 398 }
400 } 399 }
401 } 400 }
402 /* Second pass: try to find an entry that isn't picky about 401 /* Second pass: try to find an entry that isn't picky about
403 its base address, then try to grab any standard serial port 402 its base address, then try to grab any standard serial port
404 address, and finally try to get any free port. */ 403 address, and finally try to get any free port. */
405 i = first_tuple(handle, tuple, parse); 404 i = first_tuple(link, tuple, parse);
406 while (i != CS_NO_MORE_ITEMS) { 405 while (i != CS_NO_MORE_ITEMS) {
407 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && 406 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) &&
408 ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 407 ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
@@ -410,50 +409,48 @@ next_entry:
410 for (j = 0; j < 5; j++) { 409 for (j = 0; j < 5; j++) {
411 link->io.BasePort1 = base[j]; 410 link->io.BasePort1 = base[j];
412 link->io.IOAddrLines = base[j] ? 16 : 3; 411 link->io.IOAddrLines = base[j] ? 16 : 3;
413 i = pcmcia_request_io(link->handle, &link->io); 412 i = pcmcia_request_io(link, &link->io);
414 if (i == CS_SUCCESS) 413 if (i == CS_SUCCESS)
415 goto found_port; 414 goto found_port;
416 } 415 }
417 } 416 }
418 i = next_tuple(handle, tuple, parse); 417 i = next_tuple(link, tuple, parse);
419 } 418 }
420 419
421 found_port: 420 found_port:
422 if (i != CS_SUCCESS) { 421 if (i != CS_SUCCESS) {
423 printk(KERN_NOTICE 422 printk(KERN_NOTICE
424 "serial_cs: no usable port range found, giving up\n"); 423 "serial_cs: no usable port range found, giving up\n");
425 cs_error(link->handle, RequestIO, i); 424 cs_error(link, RequestIO, i);
426 kfree(cfg_mem); 425 kfree(cfg_mem);
427 return -1; 426 return -1;
428 } 427 }
429 428
430 i = pcmcia_request_irq(link->handle, &link->irq); 429 i = pcmcia_request_irq(link, &link->irq);
431 if (i != CS_SUCCESS) { 430 if (i != CS_SUCCESS) {
432 cs_error(link->handle, RequestIRQ, i); 431 cs_error(link, RequestIRQ, i);
433 link->irq.AssignedIRQ = 0; 432 link->irq.AssignedIRQ = 0;
434 } 433 }
435 if (info->multi && (info->manfid == MANFID_3COM)) 434 if (info->multi && (info->manfid == MANFID_3COM))
436 link->conf.ConfigIndex &= ~(0x08); 435 link->conf.ConfigIndex &= ~(0x08);
437 i = pcmcia_request_configuration(link->handle, &link->conf); 436 i = pcmcia_request_configuration(link, &link->conf);
438 if (i != CS_SUCCESS) { 437 if (i != CS_SUCCESS) {
439 cs_error(link->handle, RequestConfiguration, i); 438 cs_error(link, RequestConfiguration, i);
440 kfree(cfg_mem); 439 kfree(cfg_mem);
441 return -1; 440 return -1;
442 } 441 }
443 kfree(cfg_mem); 442 kfree(cfg_mem);
444 return setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); 443 return setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
445} 444}
446 445
447static int multi_config(dev_link_t * link) 446static int multi_config(struct pcmcia_device * link)
448{ 447{
449 client_handle_t handle = link->handle;
450 struct serial_info *info = link->priv; 448 struct serial_info *info = link->priv;
451 struct serial_cfg_mem *cfg_mem; 449 struct serial_cfg_mem *cfg_mem;
452 tuple_t *tuple; 450 tuple_t *tuple;
453 u_char *buf; 451 u_char *buf;
454 cisparse_t *parse; 452 cisparse_t *parse;
455 cistpl_cftable_entry_t *cf; 453 cistpl_cftable_entry_t *cf;
456 config_info_t config;
457 int i, rc, base2 = 0; 454 int i, rc, base2 = 0;
458 455
459 cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL); 456 cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL);
@@ -464,14 +461,6 @@ static int multi_config(dev_link_t * link)
464 cf = &parse->cftable_entry; 461 cf = &parse->cftable_entry;
465 buf = cfg_mem->buf; 462 buf = cfg_mem->buf;
466 463
467 i = pcmcia_get_configuration_info(handle, &config);
468 if (i != CS_SUCCESS) {
469 cs_error(handle, GetConfigurationInfo, i);
470 rc = -1;
471 goto free_cfg_mem;
472 }
473 link->conf.Vcc = config.Vcc;
474
475 tuple->TupleData = (cisdata_t *) buf; 464 tuple->TupleData = (cisdata_t *) buf;
476 tuple->TupleOffset = 0; 465 tuple->TupleOffset = 0;
477 tuple->TupleDataMax = 255; 466 tuple->TupleDataMax = 255;
@@ -480,7 +469,7 @@ static int multi_config(dev_link_t * link)
480 469
481 /* First, look for a generic full-sized window */ 470 /* First, look for a generic full-sized window */
482 link->io.NumPorts1 = info->multi * 8; 471 link->io.NumPorts1 = info->multi * 8;
483 i = first_tuple(handle, tuple, parse); 472 i = first_tuple(link, tuple, parse);
484 while (i != CS_NO_MORE_ITEMS) { 473 while (i != CS_NO_MORE_ITEMS) {
485 /* The quad port cards have bad CIS's, so just look for a 474 /* The quad port cards have bad CIS's, so just look for a
486 window larger than 8 ports and assume it will be right */ 475 window larger than 8 ports and assume it will be right */
@@ -490,19 +479,19 @@ static int multi_config(dev_link_t * link)
490 link->io.BasePort1 = cf->io.win[0].base; 479 link->io.BasePort1 = cf->io.win[0].base;
491 link->io.IOAddrLines = 480 link->io.IOAddrLines =
492 cf->io.flags & CISTPL_IO_LINES_MASK; 481 cf->io.flags & CISTPL_IO_LINES_MASK;
493 i = pcmcia_request_io(link->handle, &link->io); 482 i = pcmcia_request_io(link, &link->io);
494 base2 = link->io.BasePort1 + 8; 483 base2 = link->io.BasePort1 + 8;
495 if (i == CS_SUCCESS) 484 if (i == CS_SUCCESS)
496 break; 485 break;
497 } 486 }
498 i = next_tuple(handle, tuple, parse); 487 i = next_tuple(link, tuple, parse);
499 } 488 }
500 489
501 /* If that didn't work, look for two windows */ 490 /* If that didn't work, look for two windows */
502 if (i != CS_SUCCESS) { 491 if (i != CS_SUCCESS) {
503 link->io.NumPorts1 = link->io.NumPorts2 = 8; 492 link->io.NumPorts1 = link->io.NumPorts2 = 8;
504 info->multi = 2; 493 info->multi = 2;
505 i = first_tuple(handle, tuple, parse); 494 i = first_tuple(link, tuple, parse);
506 while (i != CS_NO_MORE_ITEMS) { 495 while (i != CS_NO_MORE_ITEMS) {
507 if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) { 496 if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) {
508 link->conf.ConfigIndex = cf->index; 497 link->conf.ConfigIndex = cf->index;
@@ -510,26 +499,26 @@ static int multi_config(dev_link_t * link)
510 link->io.BasePort2 = cf->io.win[1].base; 499 link->io.BasePort2 = cf->io.win[1].base;
511 link->io.IOAddrLines = 500 link->io.IOAddrLines =
512 cf->io.flags & CISTPL_IO_LINES_MASK; 501 cf->io.flags & CISTPL_IO_LINES_MASK;
513 i = pcmcia_request_io(link->handle, &link->io); 502 i = pcmcia_request_io(link, &link->io);
514 base2 = link->io.BasePort2; 503 base2 = link->io.BasePort2;
515 if (i == CS_SUCCESS) 504 if (i == CS_SUCCESS)
516 break; 505 break;
517 } 506 }
518 i = next_tuple(handle, tuple, parse); 507 i = next_tuple(link, tuple, parse);
519 } 508 }
520 } 509 }
521 510
522 if (i != CS_SUCCESS) { 511 if (i != CS_SUCCESS) {
523 cs_error(link->handle, RequestIO, i); 512 cs_error(link, RequestIO, i);
524 rc = -1; 513 rc = -1;
525 goto free_cfg_mem; 514 goto free_cfg_mem;
526 } 515 }
527 516
528 i = pcmcia_request_irq(link->handle, &link->irq); 517 i = pcmcia_request_irq(link, &link->irq);
529 if (i != CS_SUCCESS) { 518 if (i != CS_SUCCESS) {
530 printk(KERN_NOTICE 519 printk(KERN_NOTICE
531 "serial_cs: no usable port range found, giving up\n"); 520 "serial_cs: no usable port range found, giving up\n");
532 cs_error(link->handle, RequestIRQ, i); 521 cs_error(link, RequestIRQ, i);
533 link->irq.AssignedIRQ = 0; 522 link->irq.AssignedIRQ = 0;
534 } 523 }
535 /* Socket Dual IO: this enables irq's for second port */ 524 /* Socket Dual IO: this enables irq's for second port */
@@ -537,35 +526,43 @@ static int multi_config(dev_link_t * link)
537 link->conf.Present |= PRESENT_EXT_STATUS; 526 link->conf.Present |= PRESENT_EXT_STATUS;
538 link->conf.ExtStatus = ESR_REQ_ATTN_ENA; 527 link->conf.ExtStatus = ESR_REQ_ATTN_ENA;
539 } 528 }
540 i = pcmcia_request_configuration(link->handle, &link->conf); 529 i = pcmcia_request_configuration(link, &link->conf);
541 if (i != CS_SUCCESS) { 530 if (i != CS_SUCCESS) {
542 cs_error(link->handle, RequestConfiguration, i); 531 cs_error(link, RequestConfiguration, i);
543 rc = -1; 532 rc = -1;
544 goto free_cfg_mem; 533 goto free_cfg_mem;
545 } 534 }
546 535
547 /* The Oxford Semiconductor OXCF950 cards are in fact single-port: 536 /* The Oxford Semiconductor OXCF950 cards are in fact single-port:
548 8 registers are for the UART, the others are extra registers */ 537 * 8 registers are for the UART, the others are extra registers.
549 if (info->manfid == MANFID_OXSEMI) { 538 * Siemen's MC45 PCMCIA (Possio's GCC) is OXCF950 based too.
539 */
540 if (info->manfid == MANFID_OXSEMI || (info->manfid == MANFID_POSSIO &&
541 info->prodid == PRODID_POSSIO_GCC)) {
542 int err;
543
550 if (cf->index == 1 || cf->index == 3) { 544 if (cf->index == 1 || cf->index == 3) {
551 setup_serial(handle, info, base2, link->irq.AssignedIRQ); 545 err = setup_serial(link, info, base2,
552 outb(12, link->io.BasePort1 + 1); 546 link->irq.AssignedIRQ);
547 base2 = link->io.BasePort1;
553 } else { 548 } else {
554 setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); 549 err = setup_serial(link, info, link->io.BasePort1,
555 outb(12, base2 + 1); 550 link->irq.AssignedIRQ);
556 } 551 }
552 info->c950ctrl = base2;
553 wakeup_card(info);
557 rc = 0; 554 rc = 0;
558 goto free_cfg_mem; 555 goto free_cfg_mem;
559 } 556 }
560 557
561 setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); 558 setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
562 /* The Nokia cards are not really multiport cards */ 559 /* The Nokia cards are not really multiport cards */
563 if (info->manfid == MANFID_NOKIA) { 560 if (info->manfid == MANFID_NOKIA) {
564 rc = 0; 561 rc = 0;
565 goto free_cfg_mem; 562 goto free_cfg_mem;
566 } 563 }
567 for (i = 0; i < info->multi - 1; i++) 564 for (i = 0; i < info->multi - 1; i++)
568 setup_serial(handle, info, base2 + (8 * i), 565 setup_serial(link, info, base2 + (8 * i),
569 link->irq.AssignedIRQ); 566 link->irq.AssignedIRQ);
570 rc = 0; 567 rc = 0;
571free_cfg_mem: 568free_cfg_mem:
@@ -581,9 +578,8 @@ free_cfg_mem:
581 578
582======================================================================*/ 579======================================================================*/
583 580
584void serial_config(dev_link_t * link) 581static int serial_config(struct pcmcia_device * link)
585{ 582{
586 client_handle_t handle = link->handle;
587 struct serial_info *info = link->priv; 583 struct serial_info *info = link->priv;
588 struct serial_cfg_mem *cfg_mem; 584 struct serial_cfg_mem *cfg_mem;
589 tuple_t *tuple; 585 tuple_t *tuple;
@@ -609,7 +605,7 @@ void serial_config(dev_link_t * link)
609 tuple->Attributes = 0; 605 tuple->Attributes = 0;
610 /* Get configuration register information */ 606 /* Get configuration register information */
611 tuple->DesiredTuple = CISTPL_CONFIG; 607 tuple->DesiredTuple = CISTPL_CONFIG;
612 last_ret = first_tuple(handle, tuple, parse); 608 last_ret = first_tuple(link, tuple, parse);
613 if (last_ret != CS_SUCCESS) { 609 if (last_ret != CS_SUCCESS) {
614 last_fn = ParseTuple; 610 last_fn = ParseTuple;
615 goto cs_failed; 611 goto cs_failed;
@@ -617,18 +613,16 @@ void serial_config(dev_link_t * link)
617 link->conf.ConfigBase = parse->config.base; 613 link->conf.ConfigBase = parse->config.base;
618 link->conf.Present = parse->config.rmask[0]; 614 link->conf.Present = parse->config.rmask[0];
619 615
620 /* Configure card */
621 link->state |= DEV_CONFIG;
622
623 /* Is this a compliant multifunction card? */ 616 /* Is this a compliant multifunction card? */
624 tuple->DesiredTuple = CISTPL_LONGLINK_MFC; 617 tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
625 tuple->Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK; 618 tuple->Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK;
626 info->multi = (first_tuple(handle, tuple, parse) == CS_SUCCESS); 619 info->multi = (first_tuple(link, tuple, parse) == CS_SUCCESS);
627 620
628 /* Is this a multiport card? */ 621 /* Is this a multiport card? */
629 tuple->DesiredTuple = CISTPL_MANFID; 622 tuple->DesiredTuple = CISTPL_MANFID;
630 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) { 623 if (first_tuple(link, tuple, parse) == CS_SUCCESS) {
631 info->manfid = parse->manfid.manf; 624 info->manfid = parse->manfid.manf;
625 info->prodid = le16_to_cpu(buf[1]);
632 for (i = 0; i < MULTI_COUNT; i++) 626 for (i = 0; i < MULTI_COUNT; i++)
633 if ((info->manfid == multi_id[i].manfid) && 627 if ((info->manfid == multi_id[i].manfid) &&
634 (parse->manfid.card == multi_id[i].prodid)) 628 (parse->manfid.card == multi_id[i].prodid))
@@ -641,11 +635,11 @@ void serial_config(dev_link_t * link)
641 multifunction cards that ask for appropriate IO port ranges */ 635 multifunction cards that ask for appropriate IO port ranges */
642 tuple->DesiredTuple = CISTPL_FUNCID; 636 tuple->DesiredTuple = CISTPL_FUNCID;
643 if ((info->multi == 0) && 637 if ((info->multi == 0) &&
644 ((first_tuple(handle, tuple, parse) != CS_SUCCESS) || 638 ((first_tuple(link, tuple, parse) != CS_SUCCESS) ||
645 (parse->funcid.func == CISTPL_FUNCID_MULTI) || 639 (parse->funcid.func == CISTPL_FUNCID_MULTI) ||
646 (parse->funcid.func == CISTPL_FUNCID_SERIAL))) { 640 (parse->funcid.func == CISTPL_FUNCID_SERIAL))) {
647 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 641 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
648 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) { 642 if (first_tuple(link, tuple, parse) == CS_SUCCESS) {
649 if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0)) 643 if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0))
650 info->multi = cf->io.win[0].len >> 3; 644 info->multi = cf->io.win[0].len >> 3;
651 if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) && 645 if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) &&
@@ -664,31 +658,30 @@ void serial_config(dev_link_t * link)
664 658
665 if (info->manfid == MANFID_IBM) { 659 if (info->manfid == MANFID_IBM) {
666 conf_reg_t reg = { 0, CS_READ, 0x800, 0 }; 660 conf_reg_t reg = { 0, CS_READ, 0x800, 0 };
667 last_ret = pcmcia_access_configuration_register(link->handle, &reg); 661 last_ret = pcmcia_access_configuration_register(link, &reg);
668 if (last_ret) { 662 if (last_ret) {
669 last_fn = AccessConfigurationRegister; 663 last_fn = AccessConfigurationRegister;
670 goto cs_failed; 664 goto cs_failed;
671 } 665 }
672 reg.Action = CS_WRITE; 666 reg.Action = CS_WRITE;
673 reg.Value = reg.Value | 1; 667 reg.Value = reg.Value | 1;
674 last_ret = pcmcia_access_configuration_register(link->handle, &reg); 668 last_ret = pcmcia_access_configuration_register(link, &reg);
675 if (last_ret) { 669 if (last_ret) {
676 last_fn = AccessConfigurationRegister; 670 last_fn = AccessConfigurationRegister;
677 goto cs_failed; 671 goto cs_failed;
678 } 672 }
679 } 673 }
680 674
681 link->dev = &info->node[0]; 675 link->dev_node = &info->node[0];
682 link->state &= ~DEV_CONFIG_PENDING;
683 kfree(cfg_mem); 676 kfree(cfg_mem);
684 return; 677 return 0;
685 678
686 cs_failed: 679 cs_failed:
687 cs_error(link->handle, last_fn, last_ret); 680 cs_error(link, last_fn, last_ret);
688 failed: 681 failed:
689 serial_remove(link); 682 serial_remove(link);
690 link->state &= ~DEV_CONFIG_PENDING;
691 kfree(cfg_mem); 683 kfree(cfg_mem);
684 return -ENODEV;
692} 685}
693 686
694static struct pcmcia_device_id serial_ids[] = { 687static struct pcmcia_device_id serial_ids[] = {
@@ -739,6 +732,7 @@ static struct pcmcia_device_id serial_ids[] = {
739 PCMCIA_MFC_DEVICE_PROD_ID1(1, "Motorola MARQUIS", 0xf03e4e77), 732 PCMCIA_MFC_DEVICE_PROD_ID1(1, "Motorola MARQUIS", 0xf03e4e77),
740 PCMCIA_MFC_DEVICE_PROD_ID2(1, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302), 733 PCMCIA_MFC_DEVICE_PROD_ID2(1, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
741 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0301), 734 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0301),
735 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x0276),
742 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0039), 736 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0039),
743 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0006), 737 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0006),
744 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x410a), 738 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x410a),
@@ -757,6 +751,7 @@ static struct pcmcia_device_id serial_ids[] = {
757 PCMCIA_DEVICE_PROD_ID14("MEGAHERTZ", "PCMCIA MODEM", 0xf510db04, 0xbd6c43ef), 751 PCMCIA_DEVICE_PROD_ID14("MEGAHERTZ", "PCMCIA MODEM", 0xf510db04, 0xbd6c43ef),
758 PCMCIA_DEVICE_PROD_ID124("TOSHIBA", "T144PF", "PCMCIA MODEM", 0xb4585a1a, 0x7271409c, 0xbd6c43ef), 752 PCMCIA_DEVICE_PROD_ID124("TOSHIBA", "T144PF", "PCMCIA MODEM", 0xb4585a1a, 0x7271409c, 0xbd6c43ef),
759 PCMCIA_DEVICE_PROD_ID123("FUJITSU", "FC14F ", "MBH10213", 0x6ee5a3d8, 0x30ead12b, 0xb00f05a0), 753 PCMCIA_DEVICE_PROD_ID123("FUJITSU", "FC14F ", "MBH10213", 0x6ee5a3d8, 0x30ead12b, 0xb00f05a0),
754 PCMCIA_DEVICE_PROD_ID123("Novatel Wireless", "Merlin UMTS Modem", "U630", 0x32607776, 0xd9e73b13, 0xe87332e),
760 PCMCIA_DEVICE_PROD_ID13("MEGAHERTZ", "V.34 PCMCIA MODEM", 0xf510db04, 0xbb2cce4a), 755 PCMCIA_DEVICE_PROD_ID13("MEGAHERTZ", "V.34 PCMCIA MODEM", 0xf510db04, 0xbb2cce4a),
761 PCMCIA_DEVICE_PROD_ID12("Brain Boxes", "Bluetooth PC Card", 0xee138382, 0xd4ce9b02), 756 PCMCIA_DEVICE_PROD_ID12("Brain Boxes", "Bluetooth PC Card", 0xee138382, 0xd4ce9b02),
762 PCMCIA_DEVICE_PROD_ID12("CIRRUS LOGIC", "FAX MODEM", 0xe625f451, 0xcecd6dfa), 757 PCMCIA_DEVICE_PROD_ID12("CIRRUS LOGIC", "FAX MODEM", 0xe625f451, 0xcecd6dfa),
diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c
index d3a7b0c3d38b..dda0ca45d904 100644
--- a/drivers/telephony/ixj_pcmcia.c
+++ b/drivers/telephony/ixj_pcmcia.c
@@ -35,73 +35,52 @@ typedef struct ixj_info_t {
35} ixj_info_t; 35} ixj_info_t;
36 36
37static void ixj_detach(struct pcmcia_device *p_dev); 37static void ixj_detach(struct pcmcia_device *p_dev);
38static void ixj_config(dev_link_t * link); 38static int ixj_config(struct pcmcia_device * link);
39static void ixj_cs_release(dev_link_t * link); 39static void ixj_cs_release(struct pcmcia_device * link);
40 40
41static int ixj_attach(struct pcmcia_device *p_dev) 41static int ixj_probe(struct pcmcia_device *p_dev)
42{ 42{
43 dev_link_t *link;
44
45 DEBUG(0, "ixj_attach()\n"); 43 DEBUG(0, "ixj_attach()\n");
46 /* Create new ixj device */ 44 /* Create new ixj device */
47 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); 45 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
48 if (!link) 46 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
49 return -ENOMEM; 47 p_dev->io.IOAddrLines = 3;
50 memset(link, 0, sizeof(struct dev_link_t)); 48 p_dev->conf.IntType = INT_MEMORY_AND_IO;
51 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 49 p_dev->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
52 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 50 if (!p_dev->priv) {
53 link->io.IOAddrLines = 3;
54 link->conf.Vcc = 50;
55 link->conf.IntType = INT_MEMORY_AND_IO;
56 link->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
57 if (!link->priv) {
58 kfree(link);
59 return -ENOMEM; 51 return -ENOMEM;
60 } 52 }
61 memset(link->priv, 0, sizeof(struct ixj_info_t)); 53 memset(p_dev->priv, 0, sizeof(struct ixj_info_t));
62
63 link->handle = p_dev;
64 p_dev->instance = link;
65 54
66 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 55 return ixj_config(p_dev);
67 ixj_config(link);
68
69 return 0;
70} 56}
71 57
72static void ixj_detach(struct pcmcia_device *p_dev) 58static void ixj_detach(struct pcmcia_device *link)
73{ 59{
74 dev_link_t *link = dev_to_instance(p_dev);
75
76 DEBUG(0, "ixj_detach(0x%p)\n", link); 60 DEBUG(0, "ixj_detach(0x%p)\n", link);
77 61
78 link->state &= ~DEV_RELEASE_PENDING; 62 ixj_cs_release(link);
79 if (link->state & DEV_CONFIG)
80 ixj_cs_release(link);
81 63
82 kfree(link->priv); 64 kfree(link->priv);
83 kfree(link);
84} 65}
85 66
86#define CS_CHECK(fn, ret) \ 67#define CS_CHECK(fn, ret) \
87do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 68do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
88 69
89static void ixj_get_serial(dev_link_t * link, IXJ * j) 70static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
90{ 71{
91 client_handle_t handle;
92 tuple_t tuple; 72 tuple_t tuple;
93 u_short buf[128]; 73 u_short buf[128];
94 char *str; 74 char *str;
95 int last_ret, last_fn, i, place; 75 int last_ret, last_fn, i, place;
96 handle = link->handle;
97 DEBUG(0, "ixj_get_serial(0x%p)\n", link); 76 DEBUG(0, "ixj_get_serial(0x%p)\n", link);
98 tuple.TupleData = (cisdata_t *) buf; 77 tuple.TupleData = (cisdata_t *) buf;
99 tuple.TupleOffset = 0; 78 tuple.TupleOffset = 0;
100 tuple.TupleDataMax = 80; 79 tuple.TupleDataMax = 80;
101 tuple.Attributes = 0; 80 tuple.Attributes = 0;
102 tuple.DesiredTuple = CISTPL_VERS_1; 81 tuple.DesiredTuple = CISTPL_VERS_1;
103 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 82 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
104 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 83 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
105 str = (char *) buf; 84 str = (char *) buf;
106 printk("PCMCIA Version %d.%d\n", str[0], str[1]); 85 printk("PCMCIA Version %d.%d\n", str[0], str[1]);
107 str += 2; 86 str += 2;
@@ -149,22 +128,19 @@ static void ixj_get_serial(dev_link_t * link, IXJ * j)
149 return; 128 return;
150} 129}
151 130
152static void ixj_config(dev_link_t * link) 131static int ixj_config(struct pcmcia_device * link)
153{ 132{
154 IXJ *j; 133 IXJ *j;
155 client_handle_t handle;
156 ixj_info_t *info; 134 ixj_info_t *info;
157 tuple_t tuple; 135 tuple_t tuple;
158 u_short buf[128]; 136 u_short buf[128];
159 cisparse_t parse; 137 cisparse_t parse;
160 config_info_t conf;
161 cistpl_cftable_entry_t *cfg = &parse.cftable_entry; 138 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
162 cistpl_cftable_entry_t dflt = 139 cistpl_cftable_entry_t dflt =
163 { 140 {
164 0 141 0
165 }; 142 };
166 int last_ret, last_fn; 143 int last_ret, last_fn;
167 handle = link->handle;
168 info = link->priv; 144 info = link->priv;
169 DEBUG(0, "ixj_config(0x%p)\n", link); 145 DEBUG(0, "ixj_config(0x%p)\n", link);
170 tuple.TupleData = (cisdata_t *) buf; 146 tuple.TupleData = (cisdata_t *) buf;
@@ -172,19 +148,17 @@ static void ixj_config(dev_link_t * link)
172 tuple.TupleDataMax = 255; 148 tuple.TupleDataMax = 255;
173 tuple.Attributes = 0; 149 tuple.Attributes = 0;
174 tuple.DesiredTuple = CISTPL_CONFIG; 150 tuple.DesiredTuple = CISTPL_CONFIG;
175 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 151 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
176 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 152 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
177 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 153 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
178 link->conf.ConfigBase = parse.config.base; 154 link->conf.ConfigBase = parse.config.base;
179 link->conf.Present = parse.config.rmask[0]; 155 link->conf.Present = parse.config.rmask[0];
180 link->state |= DEV_CONFIG;
181 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
182 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 156 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
183 tuple.Attributes = 0; 157 tuple.Attributes = 0;
184 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 158 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
185 while (1) { 159 while (1) {
186 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 160 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
187 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 161 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
188 goto next_entry; 162 goto next_entry;
189 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { 163 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
190 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; 164 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
@@ -195,7 +169,7 @@ static void ixj_config(dev_link_t * link)
195 link->io.BasePort2 = io->win[1].base; 169 link->io.BasePort2 = io->win[1].base;
196 link->io.NumPorts2 = io->win[1].len; 170 link->io.NumPorts2 = io->win[1].len;
197 } 171 }
198 if (pcmcia_request_io(link->handle, &link->io) != 0) 172 if (pcmcia_request_io(link, &link->io) != 0)
199 goto next_entry; 173 goto next_entry;
200 /* If we've got this far, we're done */ 174 /* If we've got this far, we're done */
201 break; 175 break;
@@ -203,10 +177,10 @@ static void ixj_config(dev_link_t * link)
203 next_entry: 177 next_entry:
204 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 178 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
205 dflt = *cfg; 179 dflt = *cfg;
206 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 180 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
207 } 181 }
208 182
209 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 183 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
210 184
211 /* 185 /*
212 * Register the card with the core. 186 * Register the card with the core.
@@ -215,46 +189,21 @@ static void ixj_config(dev_link_t * link)
215 189
216 info->ndev = 1; 190 info->ndev = 1;
217 info->node.major = PHONE_MAJOR; 191 info->node.major = PHONE_MAJOR;
218 link->dev = &info->node; 192 link->dev_node = &info->node;
219 ixj_get_serial(link, j); 193 ixj_get_serial(link, j);
220 link->state &= ~DEV_CONFIG_PENDING; 194 return 0;
221 return;
222 cs_failed: 195 cs_failed:
223 cs_error(link->handle, last_fn, last_ret); 196 cs_error(link, last_fn, last_ret);
224 ixj_cs_release(link); 197 ixj_cs_release(link);
198 return -ENODEV;
225} 199}
226 200
227static void ixj_cs_release(dev_link_t *link) 201static void ixj_cs_release(struct pcmcia_device *link)
228{ 202{
229 ixj_info_t *info = link->priv; 203 ixj_info_t *info = link->priv;
230 DEBUG(0, "ixj_cs_release(0x%p)\n", link); 204 DEBUG(0, "ixj_cs_release(0x%p)\n", link);
231 info->ndev = 0; 205 info->ndev = 0;
232 link->dev = NULL; 206 pcmcia_disable_device(link);
233 pcmcia_release_configuration(link->handle);
234 pcmcia_release_io(link->handle, &link->io);
235 link->state &= ~DEV_CONFIG;
236}
237
238static int ixj_suspend(struct pcmcia_device *dev)
239{
240 dev_link_t *link = dev_to_instance(dev);
241
242 link->state |= DEV_SUSPEND;
243 if (link->state & DEV_CONFIG)
244 pcmcia_release_configuration(link->handle);
245
246 return 0;
247}
248
249static int ixj_resume(struct pcmcia_device *dev)
250{
251 dev_link_t *link = dev_to_instance(dev);
252
253 link->state &= ~DEV_SUSPEND;
254 if (DEV_OK(link))
255 pcmcia_request_configuration(link->handle, &link->conf);
256
257 return 0;
258} 207}
259 208
260static struct pcmcia_device_id ixj_ids[] = { 209static struct pcmcia_device_id ixj_ids[] = {
@@ -268,11 +217,9 @@ static struct pcmcia_driver ixj_driver = {
268 .drv = { 217 .drv = {
269 .name = "ixj_cs", 218 .name = "ixj_cs",
270 }, 219 },
271 .probe = ixj_attach, 220 .probe = ixj_probe,
272 .remove = ixj_detach, 221 .remove = ixj_detach,
273 .id_table = ixj_ids, 222 .id_table = ixj_ids,
274 .suspend = ixj_suspend,
275 .resume = ixj_resume,
276}; 223};
277 224
278static int __init ixj_pcmcia_init(void) 225static int __init ixj_pcmcia_init(void)
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 134d2000128a..302aa1ec312f 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -67,11 +67,11 @@ module_param(pc_debug, int, 0644);
67static const char driver_name[DEV_NAME_LEN] = "sl811_cs"; 67static const char driver_name[DEV_NAME_LEN] = "sl811_cs";
68 68
69typedef struct local_info_t { 69typedef struct local_info_t {
70 dev_link_t link; 70 struct pcmcia_device *p_dev;
71 dev_node_t node; 71 dev_node_t node;
72} local_info_t; 72} local_info_t;
73 73
74static void sl811_cs_release(dev_link_t * link); 74static void sl811_cs_release(struct pcmcia_device * link);
75 75
76/*====================================================================*/ 76/*====================================================================*/
77 77
@@ -138,41 +138,27 @@ static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq)
138 138
139/*====================================================================*/ 139/*====================================================================*/
140 140
141static void sl811_cs_detach(struct pcmcia_device *p_dev) 141static void sl811_cs_detach(struct pcmcia_device *link)
142{ 142{
143 dev_link_t *link = dev_to_instance(p_dev);
144
145 DBG(0, "sl811_cs_detach(0x%p)\n", link); 143 DBG(0, "sl811_cs_detach(0x%p)\n", link);
146 144
147 link->state &= ~DEV_PRESENT; 145 sl811_cs_release(link);
148 if (link->state & DEV_CONFIG)
149 sl811_cs_release(link);
150 146
151 /* This points to the parent local_info_t struct */ 147 /* This points to the parent local_info_t struct */
152 kfree(link->priv); 148 kfree(link->priv);
153} 149}
154 150
155static void sl811_cs_release(dev_link_t * link) 151static void sl811_cs_release(struct pcmcia_device * link)
156{ 152{
157
158 DBG(0, "sl811_cs_release(0x%p)\n", link); 153 DBG(0, "sl811_cs_release(0x%p)\n", link);
159 154
160 /* Unlink the device chain */ 155 pcmcia_disable_device(link);
161 link->dev = NULL;
162
163 platform_device_unregister(&platform_dev); 156 platform_device_unregister(&platform_dev);
164 pcmcia_release_configuration(link->handle);
165 if (link->io.NumPorts1)
166 pcmcia_release_io(link->handle, &link->io);
167 if (link->irq.AssignedIRQ)
168 pcmcia_release_irq(link->handle, &link->irq);
169 link->state &= ~DEV_CONFIG;
170} 157}
171 158
172static void sl811_cs_config(dev_link_t *link) 159static int sl811_cs_config(struct pcmcia_device *link)
173{ 160{
174 client_handle_t handle = link->handle; 161 struct device *parent = &handle_to_dev(link);
175 struct device *parent = &handle_to_dev(handle);
176 local_info_t *dev = link->priv; 162 local_info_t *dev = link->priv;
177 tuple_t tuple; 163 tuple_t tuple;
178 cisparse_t parse; 164 cisparse_t parse;
@@ -188,27 +174,23 @@ static void sl811_cs_config(dev_link_t *link)
188 tuple.TupleData = buf; 174 tuple.TupleData = buf;
189 tuple.TupleDataMax = sizeof(buf); 175 tuple.TupleDataMax = sizeof(buf);
190 tuple.TupleOffset = 0; 176 tuple.TupleOffset = 0;
191 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 177 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
192 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 178 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
193 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 179 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
194 link->conf.ConfigBase = parse.config.base; 180 link->conf.ConfigBase = parse.config.base;
195 link->conf.Present = parse.config.rmask[0]; 181 link->conf.Present = parse.config.rmask[0];
196 182
197 /* Configure card */
198 link->state |= DEV_CONFIG;
199
200 /* Look up the current Vcc */ 183 /* Look up the current Vcc */
201 CS_CHECK(GetConfigurationInfo, 184 CS_CHECK(GetConfigurationInfo,
202 pcmcia_get_configuration_info(handle, &conf)); 185 pcmcia_get_configuration_info(link, &conf));
203 link->conf.Vcc = conf.Vcc;
204 186
205 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 187 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
206 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 188 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
207 while (1) { 189 while (1) {
208 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 190 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
209 191
210 if (pcmcia_get_tuple_data(handle, &tuple) != 0 192 if (pcmcia_get_tuple_data(link, &tuple) != 0
211 || pcmcia_parse_tuple(handle, &tuple, &parse) 193 || pcmcia_parse_tuple(link, &tuple, &parse)
212 != 0) 194 != 0)
213 goto next_entry; 195 goto next_entry;
214 196
@@ -234,10 +216,10 @@ static void sl811_cs_config(dev_link_t *link)
234 } 216 }
235 217
236 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 218 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
237 link->conf.Vpp1 = link->conf.Vpp2 = 219 link->conf.Vpp =
238 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 220 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
239 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 221 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
240 link->conf.Vpp1 = link->conf.Vpp2 = 222 link->conf.Vpp =
241 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 223 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
242 224
243 /* we need an interrupt */ 225 /* we need an interrupt */
@@ -254,15 +236,14 @@ static void sl811_cs_config(dev_link_t *link)
254 link->io.BasePort1 = io->win[0].base; 236 link->io.BasePort1 = io->win[0].base;
255 link->io.NumPorts1 = io->win[0].len; 237 link->io.NumPorts1 = io->win[0].len;
256 238
257 if (pcmcia_request_io(link->handle, &link->io) != 0) 239 if (pcmcia_request_io(link, &link->io) != 0)
258 goto next_entry; 240 goto next_entry;
259 } 241 }
260 break; 242 break;
261 243
262next_entry: 244next_entry:
263 if (link->io.NumPorts1) 245 pcmcia_disable_device(link);
264 pcmcia_release_io(link->handle, &link->io); 246 last_ret = pcmcia_get_next_tuple(link, &tuple);
265 last_ret = pcmcia_get_next_tuple(handle, &tuple);
266 } 247 }
267 248
268 /* require an IRQ and two registers */ 249 /* require an IRQ and two registers */
@@ -270,71 +251,46 @@ next_entry:
270 goto cs_failed; 251 goto cs_failed;
271 if (link->conf.Attributes & CONF_ENABLE_IRQ) 252 if (link->conf.Attributes & CONF_ENABLE_IRQ)
272 CS_CHECK(RequestIRQ, 253 CS_CHECK(RequestIRQ,
273 pcmcia_request_irq(link->handle, &link->irq)); 254 pcmcia_request_irq(link, &link->irq));
274 else 255 else
275 goto cs_failed; 256 goto cs_failed;
276 257
277 CS_CHECK(RequestConfiguration, 258 CS_CHECK(RequestConfiguration,
278 pcmcia_request_configuration(link->handle, &link->conf)); 259 pcmcia_request_configuration(link, &link->conf));
279 260
280 sprintf(dev->node.dev_name, driver_name); 261 sprintf(dev->node.dev_name, driver_name);
281 dev->node.major = dev->node.minor = 0; 262 dev->node.major = dev->node.minor = 0;
282 link->dev = &dev->node; 263 link->dev_node = &dev->node;
283 264
284 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 265 printk(KERN_INFO "%s: index 0x%02x: ",
285 dev->node.dev_name, link->conf.ConfigIndex, 266 dev->node.dev_name, link->conf.ConfigIndex);
286 link->conf.Vcc/10, link->conf.Vcc%10); 267 if (link->conf.Vpp)
287 if (link->conf.Vpp1) 268 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
288 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
289 printk(", irq %d", link->irq.AssignedIRQ); 269 printk(", irq %d", link->irq.AssignedIRQ);
290 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 270 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
291 link->io.BasePort1+link->io.NumPorts1-1); 271 link->io.BasePort1+link->io.NumPorts1-1);
292 printk("\n"); 272 printk("\n");
293 273
294 link->state &= ~DEV_CONFIG_PENDING;
295
296 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ) 274 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ)
297 < 0) { 275 < 0) {
298cs_failed: 276cs_failed:
299 printk("sl811_cs_config failed\n"); 277 printk("sl811_cs_config failed\n");
300 cs_error(link->handle, last_fn, last_ret); 278 cs_error(link, last_fn, last_ret);
301 sl811_cs_release(link); 279 sl811_cs_release(link);
302 link->state &= ~DEV_CONFIG_PENDING; 280 return -ENODEV;
303 } 281 }
304}
305
306static int sl811_suspend(struct pcmcia_device *dev)
307{
308 dev_link_t *link = dev_to_instance(dev);
309
310 link->state |= DEV_SUSPEND;
311 if (link->state & DEV_CONFIG)
312 pcmcia_release_configuration(link->handle);
313
314 return 0;
315}
316
317static int sl811_resume(struct pcmcia_device *dev)
318{
319 dev_link_t *link = dev_to_instance(dev);
320
321 link->state &= ~DEV_SUSPEND;
322 if (link->state & DEV_CONFIG)
323 pcmcia_request_configuration(link->handle, &link->conf);
324
325 return 0; 282 return 0;
326} 283}
327 284
328static int sl811_cs_attach(struct pcmcia_device *p_dev) 285static int sl811_cs_probe(struct pcmcia_device *link)
329{ 286{
330 local_info_t *local; 287 local_info_t *local;
331 dev_link_t *link;
332 288
333 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 289 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
334 if (!local) 290 if (!local)
335 return -ENOMEM; 291 return -ENOMEM;
336 memset(local, 0, sizeof(local_info_t)); 292 memset(local, 0, sizeof(local_info_t));
337 link = &local->link; 293 local->p_dev = link;
338 link->priv = local; 294 link->priv = local;
339 295
340 /* Initialize */ 296 /* Initialize */
@@ -343,16 +299,9 @@ static int sl811_cs_attach(struct pcmcia_device *p_dev)
343 link->irq.Handler = NULL; 299 link->irq.Handler = NULL;
344 300
345 link->conf.Attributes = 0; 301 link->conf.Attributes = 0;
346 link->conf.Vcc = 33;
347 link->conf.IntType = INT_MEMORY_AND_IO; 302 link->conf.IntType = INT_MEMORY_AND_IO;
348 303
349 link->handle = p_dev; 304 return sl811_cs_config(link);
350 p_dev->instance = link;
351
352 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
353 sl811_cs_config(link);
354
355 return 0;
356} 305}
357 306
358static struct pcmcia_device_id sl811_ids[] = { 307static struct pcmcia_device_id sl811_ids[] = {
@@ -366,11 +315,9 @@ static struct pcmcia_driver sl811_cs_driver = {
366 .drv = { 315 .drv = {
367 .name = (char *)driver_name, 316 .name = (char *)driver_name,
368 }, 317 },
369 .probe = sl811_cs_attach, 318 .probe = sl811_cs_probe,
370 .remove = sl811_cs_detach, 319 .remove = sl811_cs_detach,
371 .id_table = sl811_ids, 320 .id_table = sl811_ids,
372 .suspend = sl811_suspend,
373 .resume = sl811_resume,
374}; 321};
375 322
376/*====================================================================*/ 323/*====================================================================*/