aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pcmcia/ds.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pcmcia/ds.c')
-rw-r--r--drivers/pcmcia/ds.c97
1 files changed, 81 insertions, 16 deletions
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 5b302e822ef5..45df12eda3c5 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -250,6 +250,8 @@ int pcmcia_register_driver(struct pcmcia_driver *driver)
250 driver->drv.bus = &pcmcia_bus_type; 250 driver->drv.bus = &pcmcia_bus_type;
251 driver->drv.owner = driver->owner; 251 driver->drv.owner = driver->owner;
252 252
253 ds_dbg(3, "registering driver %s\n", driver->drv.name);
254
253 return driver_register(&driver->drv); 255 return driver_register(&driver->drv);
254} 256}
255EXPORT_SYMBOL(pcmcia_register_driver); 257EXPORT_SYMBOL(pcmcia_register_driver);
@@ -259,6 +261,7 @@ EXPORT_SYMBOL(pcmcia_register_driver);
259 */ 261 */
260void pcmcia_unregister_driver(struct pcmcia_driver *driver) 262void pcmcia_unregister_driver(struct pcmcia_driver *driver)
261{ 263{
264 ds_dbg(3, "unregistering driver %s\n", driver->drv.name);
262 driver_unregister(&driver->drv); 265 driver_unregister(&driver->drv);
263} 266}
264EXPORT_SYMBOL(pcmcia_unregister_driver); 267EXPORT_SYMBOL(pcmcia_unregister_driver);
@@ -284,13 +287,14 @@ void pcmcia_put_dev(struct pcmcia_device *p_dev)
284static void pcmcia_release_function(struct kref *ref) 287static void pcmcia_release_function(struct kref *ref)
285{ 288{
286 struct config_t *c = container_of(ref, struct config_t, ref); 289 struct config_t *c = container_of(ref, struct config_t, ref);
290 ds_dbg(1, "releasing config_t\n");
287 kfree(c); 291 kfree(c);
288} 292}
289 293
290static void pcmcia_release_dev(struct device *dev) 294static void pcmcia_release_dev(struct device *dev)
291{ 295{
292 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 296 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
293 ds_dbg(1, "releasing dev %p\n", p_dev); 297 ds_dbg(1, "releasing device %s\n", p_dev->dev.bus_id);
294 pcmcia_put_socket(p_dev->socket); 298 pcmcia_put_socket(p_dev->socket);
295 kfree(p_dev->devname); 299 kfree(p_dev->devname);
296 kref_put(&p_dev->function_config->ref, pcmcia_release_function); 300 kref_put(&p_dev->function_config->ref, pcmcia_release_function);
@@ -300,6 +304,8 @@ static void pcmcia_release_dev(struct device *dev)
300static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc) 304static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc)
301{ 305{
302 if (!s->pcmcia_state.device_add_pending) { 306 if (!s->pcmcia_state.device_add_pending) {
307 ds_dbg(1, "scheduling to add %s secondary"
308 " device to %d\n", mfc ? "mfc" : "pfc", s->sock);
303 s->pcmcia_state.device_add_pending = 1; 309 s->pcmcia_state.device_add_pending = 1;
304 s->pcmcia_state.mfc_pfc = mfc; 310 s->pcmcia_state.mfc_pfc = mfc;
305 schedule_work(&s->device_add); 311 schedule_work(&s->device_add);
@@ -324,6 +330,9 @@ static int pcmcia_device_probe(struct device * dev)
324 p_drv = to_pcmcia_drv(dev->driver); 330 p_drv = to_pcmcia_drv(dev->driver);
325 s = p_dev->socket; 331 s = p_dev->socket;
326 332
333 ds_dbg(1, "trying to bind %s to %s\n", p_dev->dev.bus_id,
334 p_drv->drv.name);
335
327 if ((!p_drv->probe) || (!p_dev->function_config) || 336 if ((!p_drv->probe) || (!p_dev->function_config) ||
328 (!try_module_get(p_drv->owner))) { 337 (!try_module_get(p_drv->owner))) {
329 ret = -EINVAL; 338 ret = -EINVAL;
@@ -343,8 +352,11 @@ static int pcmcia_device_probe(struct device * dev)
343 } 352 }
344 353
345 ret = p_drv->probe(p_dev); 354 ret = p_drv->probe(p_dev);
346 if (ret) 355 if (ret) {
356 ds_dbg(1, "binding %s to %s failed with %d\n",
357 p_dev->dev.bus_id, p_drv->drv.name, ret);
347 goto put_module; 358 goto put_module;
359 }
348 360
349 /* handle pseudo multifunction devices: 361 /* handle pseudo multifunction devices:
350 * there are at most two pseudo multifunction devices. 362 * there are at most two pseudo multifunction devices.
@@ -376,8 +388,8 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le
376 struct pcmcia_device *tmp; 388 struct pcmcia_device *tmp;
377 unsigned long flags; 389 unsigned long flags;
378 390
379 ds_dbg(2, "unbind_request(%d)\n", s->sock); 391 ds_dbg(2, "pcmcia_card_remove(%d) %s\n", s->sock,
380 392 leftover ? leftover->devname : "");
381 393
382 if (!leftover) 394 if (!leftover)
383 s->device_count = 0; 395 s->device_count = 0;
@@ -394,6 +406,7 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le
394 p_dev->_removed=1; 406 p_dev->_removed=1;
395 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 407 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
396 408
409 ds_dbg(2, "unregistering device %s\n", p_dev->dev.bus_id);
397 device_unregister(&p_dev->dev); 410 device_unregister(&p_dev->dev);
398 } 411 }
399 412
@@ -410,6 +423,8 @@ static int pcmcia_device_remove(struct device * dev)
410 p_dev = to_pcmcia_dev(dev); 423 p_dev = to_pcmcia_dev(dev);
411 p_drv = to_pcmcia_drv(dev->driver); 424 p_drv = to_pcmcia_drv(dev->driver);
412 425
426 ds_dbg(1, "removing device %s\n", p_dev->dev.bus_id);
427
413 /* If we're removing the primary module driving a 428 /* If we're removing the primary module driving a
414 * pseudo multi-function card, we need to unbind 429 * pseudo multi-function card, we need to unbind
415 * all devices 430 * all devices
@@ -542,6 +557,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
542 557
543 mutex_lock(&device_add_lock); 558 mutex_lock(&device_add_lock);
544 559
560 ds_dbg(3, "adding device to %d, function %d\n", s->sock, function);
561
545 /* max of 4 devices per card */ 562 /* max of 4 devices per card */
546 if (s->device_count == 4) 563 if (s->device_count == 4)
547 goto err_put; 564 goto err_put;
@@ -563,8 +580,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
563 if (!p_dev->devname) 580 if (!p_dev->devname)
564 goto err_free; 581 goto err_free;
565 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id); 582 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
583 ds_dbg(3, "devname is %s\n", p_dev->devname);
566 584
567 /* compat */
568 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 585 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
569 586
570 /* 587 /*
@@ -584,6 +601,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
584 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 601 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
585 602
586 if (!p_dev->function_config) { 603 if (!p_dev->function_config) {
604 ds_dbg(3, "creating config_t for %s\n", p_dev->dev.bus_id);
587 p_dev->function_config = kzalloc(sizeof(struct config_t), 605 p_dev->function_config = kzalloc(sizeof(struct config_t),
588 GFP_KERNEL); 606 GFP_KERNEL);
589 if (!p_dev->function_config) 607 if (!p_dev->function_config)
@@ -627,11 +645,16 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
627 unsigned int no_funcs, i; 645 unsigned int no_funcs, i;
628 int ret = 0; 646 int ret = 0;
629 647
630 if (!(s->resource_setup_done)) 648 if (!(s->resource_setup_done)) {
649 ds_dbg(3, "no resources available, delaying card_add\n");
631 return -EAGAIN; /* try again, but later... */ 650 return -EAGAIN; /* try again, but later... */
651 }
632 652
633 if (pcmcia_validate_mem(s)) 653 if (pcmcia_validate_mem(s)) {
654 ds_dbg(3, "validating mem resources failed, "
655 "delaying card_add\n");
634 return -EAGAIN; /* try again, but later... */ 656 return -EAGAIN; /* try again, but later... */
657 }
635 658
636 ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo); 659 ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo);
637 if (ret || !cisinfo.Chains) { 660 if (ret || !cisinfo.Chains) {
@@ -655,6 +678,7 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
655static void pcmcia_delayed_add_device(void *data) 678static void pcmcia_delayed_add_device(void *data)
656{ 679{
657 struct pcmcia_socket *s = data; 680 struct pcmcia_socket *s = data;
681 ds_dbg(1, "adding additional device to %d\n", s->sock);
658 pcmcia_device_add(s, s->pcmcia_state.mfc_pfc); 682 pcmcia_device_add(s, s->pcmcia_state.mfc_pfc);
659 s->pcmcia_state.device_add_pending = 0; 683 s->pcmcia_state.device_add_pending = 0;
660 s->pcmcia_state.mfc_pfc = 0; 684 s->pcmcia_state.mfc_pfc = 0;
@@ -663,8 +687,11 @@ static void pcmcia_delayed_add_device(void *data)
663static int pcmcia_requery(struct device *dev, void * _data) 687static int pcmcia_requery(struct device *dev, void * _data)
664{ 688{
665 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 689 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
666 if (!p_dev->dev.driver) 690 if (!p_dev->dev.driver) {
691 ds_dbg(1, "update device information for %s\n",
692 p_dev->dev.bus_id);
667 pcmcia_device_query(p_dev); 693 pcmcia_device_query(p_dev);
694 }
668 695
669 return 0; 696 return 0;
670} 697}
@@ -676,6 +703,8 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis)
676 unsigned long flags; 703 unsigned long flags;
677 704
678 /* must be called with skt_mutex held */ 705 /* must be called with skt_mutex held */
706 ds_dbg(0, "re-scanning socket %d\n", skt->sock);
707
679 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 708 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
680 if (list_empty(&skt->devices_list)) 709 if (list_empty(&skt->devices_list))
681 no_devices = 1; 710 no_devices = 1;
@@ -731,26 +760,38 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
731 if (!filename) 760 if (!filename)
732 return -EINVAL; 761 return -EINVAL;
733 762
734 ds_dbg(1, "trying to load firmware %s\n", filename); 763 ds_dbg(1, "trying to load CIS file %s\n", filename);
735 764
736 if (strlen(filename) > 14) 765 if (strlen(filename) > 14) {
766 printk(KERN_WARNING "pcmcia: CIS filename is too long\n");
737 return -EINVAL; 767 return -EINVAL;
768 }
738 769
739 snprintf(path, 20, "%s", filename); 770 snprintf(path, 20, "%s", filename);
740 771
741 if (request_firmware(&fw, path, &dev->dev) == 0) { 772 if (request_firmware(&fw, path, &dev->dev) == 0) {
742 if (fw->size >= CISTPL_MAX_CIS_SIZE) 773 if (fw->size >= CISTPL_MAX_CIS_SIZE) {
774 ret = -EINVAL;
775 printk(KERN_ERR "pcmcia: CIS override is too big\n");
743 goto release; 776 goto release;
777 }
744 778
745 cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL); 779 cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL);
746 if (!cis) 780 if (!cis) {
781 ret = -ENOMEM;
747 goto release; 782 goto release;
783 }
748 784
749 cis->Length = fw->size + 1; 785 cis->Length = fw->size + 1;
750 memcpy(cis->Data, fw->data, fw->size); 786 memcpy(cis->Data, fw->data, fw->size);
751 787
752 if (!pcmcia_replace_cis(s, cis)) 788 if (!pcmcia_replace_cis(s, cis))
753 ret = 0; 789 ret = 0;
790 else {
791 printk(KERN_ERR "pcmcia: CIS override failed\n");
792 goto release;
793 }
794
754 795
755 /* update information */ 796 /* update information */
756 pcmcia_device_query(dev); 797 pcmcia_device_query(dev);
@@ -851,11 +892,14 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
851 * after it has re-checked that there is no possible module 892 * after it has re-checked that there is no possible module
852 * with a prod_id/manf_id/card_id match. 893 * with a prod_id/manf_id/card_id match.
853 */ 894 */
895 ds_dbg(0, "skipping FUNC_ID match for %s until userspace "
896 "interaction\n", dev->dev.bus_id);
854 if (!dev->allow_func_id_match) 897 if (!dev->allow_func_id_match)
855 return 0; 898 return 0;
856 } 899 }
857 900
858 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { 901 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
902 ds_dbg(0, "device %s needs a fake CIS\n", dev->dev.bus_id);
859 if (!dev->socket->fake_cis) 903 if (!dev->socket->fake_cis)
860 pcmcia_load_firmware(dev, did->cisfile); 904 pcmcia_load_firmware(dev, did->cisfile);
861 905
@@ -885,13 +929,21 @@ static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
885 929
886#ifdef CONFIG_PCMCIA_IOCTL 930#ifdef CONFIG_PCMCIA_IOCTL
887 /* matching by cardmgr */ 931 /* matching by cardmgr */
888 if (p_dev->cardmgr == p_drv) 932 if (p_dev->cardmgr == p_drv) {
933 ds_dbg(0, "cardmgr matched %s to %s\n", dev->bus_id,
934 drv->name);
889 return 1; 935 return 1;
936 }
890#endif 937#endif
891 938
892 while (did && did->match_flags) { 939 while (did && did->match_flags) {
893 if (pcmcia_devmatch(p_dev, did)) 940 ds_dbg(3, "trying to match %s to %s\n", dev->bus_id,
941 drv->name);
942 if (pcmcia_devmatch(p_dev, did)) {
943 ds_dbg(0, "matched %s to %s\n", dev->bus_id,
944 drv->name);
894 return 1; 945 return 1;
946 }
895 did++; 947 did++;
896 } 948 }
897 949
@@ -1082,6 +1134,8 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
1082 struct pcmcia_driver *p_drv = NULL; 1134 struct pcmcia_driver *p_drv = NULL;
1083 int ret = 0; 1135 int ret = 0;
1084 1136
1137 ds_dbg(2, "suspending %s\n", dev->bus_id);
1138
1085 if (dev->driver) 1139 if (dev->driver)
1086 p_drv = to_pcmcia_drv(dev->driver); 1140 p_drv = to_pcmcia_drv(dev->driver);
1087 1141
@@ -1090,12 +1144,18 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
1090 1144
1091 if (p_drv->suspend) { 1145 if (p_drv->suspend) {
1092 ret = p_drv->suspend(p_dev); 1146 ret = p_drv->suspend(p_dev);
1093 if (ret) 1147 if (ret) {
1148 printk(KERN_ERR "pcmcia: device %s (driver %s) did "
1149 "not want to go to sleep (%d)\n",
1150 p_dev->devname, p_drv->drv.name, ret);
1094 goto out; 1151 goto out;
1152 }
1095 } 1153 }
1096 1154
1097 if (p_dev->device_no == p_dev->func) 1155 if (p_dev->device_no == p_dev->func) {
1156 ds_dbg(2, "releasing configuration for %s\n", dev->bus_id);
1098 pcmcia_release_configuration(p_dev); 1157 pcmcia_release_configuration(p_dev);
1158 }
1099 1159
1100 out: 1160 out:
1101 if (!ret) 1161 if (!ret)
@@ -1110,6 +1170,8 @@ static int pcmcia_dev_resume(struct device * dev)
1110 struct pcmcia_driver *p_drv = NULL; 1170 struct pcmcia_driver *p_drv = NULL;
1111 int ret = 0; 1171 int ret = 0;
1112 1172
1173 ds_dbg(2, "resuming %s\n", dev->bus_id);
1174
1113 if (dev->driver) 1175 if (dev->driver)
1114 p_drv = to_pcmcia_drv(dev->driver); 1176 p_drv = to_pcmcia_drv(dev->driver);
1115 1177
@@ -1117,6 +1179,7 @@ static int pcmcia_dev_resume(struct device * dev)
1117 goto out; 1179 goto out;
1118 1180
1119 if (p_dev->device_no == p_dev->func) { 1181 if (p_dev->device_no == p_dev->func) {
1182 ds_dbg(2, "requesting configuration for %s\n", dev->bus_id);
1120 ret = pcmcia_request_configuration(p_dev, &p_dev->conf); 1183 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
1121 if (ret) 1184 if (ret)
1122 goto out; 1185 goto out;
@@ -1158,12 +1221,14 @@ static int pcmcia_bus_resume_callback(struct device *dev, void * _data)
1158 1221
1159static int pcmcia_bus_resume(struct pcmcia_socket *skt) 1222static int pcmcia_bus_resume(struct pcmcia_socket *skt)
1160{ 1223{
1224 ds_dbg(2, "resuming socket %d\n", skt->sock);
1161 bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback); 1225 bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback);
1162 return 0; 1226 return 0;
1163} 1227}
1164 1228
1165static int pcmcia_bus_suspend(struct pcmcia_socket *skt) 1229static int pcmcia_bus_suspend(struct pcmcia_socket *skt)
1166{ 1230{
1231 ds_dbg(2, "suspending socket %d\n", skt->sock);
1167 if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt, 1232 if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt,
1168 pcmcia_bus_suspend_callback)) { 1233 pcmcia_bus_suspend_callback)) {
1169 pcmcia_bus_resume(skt); 1234 pcmcia_bus_resume(skt);