Lines Matching +full:multi +full:- +full:attr

1 // SPDX-License-Identifier: GPL-2.0-only
3 * ds.c -- 16-bit PCMCIA core support
10 * (C) 2003 - 2010 Dominik Brodowski
23 #include <linux/dma-mapping.h>
45 const struct pcmcia_device_id *did = p_drv->id_table; in pcmcia_check_driver()
49 if (!p_drv->probe || !p_drv->remove) in pcmcia_check_driver()
51 "function\n", p_drv->name); in pcmcia_check_driver()
53 while (did && did->match_flags) { in pcmcia_check_driver()
55 if (!did->prod_id[i]) in pcmcia_check_driver()
58 hash = crc32(0, did->prod_id[i], strlen(did->prod_id[i])); in pcmcia_check_driver()
59 if (hash == did->prod_id_hash[i]) in pcmcia_check_driver()
64 "be 0x%x\n", p_drv->name, did->prod_id[i], in pcmcia_check_driver()
65 did->prod_id_hash[i], hash); in pcmcia_check_driver()
86 * new_id_store() - add a new PCMCIA device ID to this driver and re-probe devices
109 return -EINVAL; in new_id_store()
113 return -ENOMEM; in new_id_store()
115 dynid->id.match_flags = match_flags; in new_id_store()
116 dynid->id.manf_id = manf_id; in new_id_store()
117 dynid->id.card_id = card_id; in new_id_store()
118 dynid->id.func_id = func_id; in new_id_store()
119 dynid->id.function = function; in new_id_store()
120 dynid->id.device_no = device_no; in new_id_store()
121 memcpy(dynid->id.prod_id_hash, prod_id_hash, sizeof(__u32) * 4); in new_id_store()
123 mutex_lock(&pdrv->dynids.lock); in new_id_store()
124 list_add_tail(&dynid->node, &pdrv->dynids.list); in new_id_store()
125 mutex_unlock(&pdrv->dynids.lock); in new_id_store()
127 retval = driver_attach(&pdrv->drv); in new_id_store()
140 mutex_lock(&drv->dynids.lock); in pcmcia_free_dynids()
141 list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { in pcmcia_free_dynids()
142 list_del(&dynid->node); in pcmcia_free_dynids()
145 mutex_unlock(&drv->dynids.lock); in pcmcia_free_dynids()
152 if (drv->probe != NULL) in pcmcia_create_newid_file()
153 error = driver_create_file(&drv->drv, &driver_attr_new_id); in pcmcia_create_newid_file()
160 driver_remove_file(&drv->drv, &driver_attr_new_id); in pcmcia_remove_newid_file()
164 * pcmcia_register_driver - register a PCMCIA driver with the bus core
174 return -EINVAL; in pcmcia_register_driver()
179 driver->drv.bus = &pcmcia_bus_type; in pcmcia_register_driver()
180 driver->drv.owner = driver->owner; in pcmcia_register_driver()
181 driver->drv.name = driver->name; in pcmcia_register_driver()
182 mutex_init(&driver->dynids.lock); in pcmcia_register_driver()
183 INIT_LIST_HEAD(&driver->dynids.list); in pcmcia_register_driver()
185 pr_debug("registering driver %s\n", driver->name); in pcmcia_register_driver()
187 error = driver_register(&driver->drv); in pcmcia_register_driver()
193 driver_unregister(&driver->drv); in pcmcia_register_driver()
200 * pcmcia_unregister_driver - unregister a PCMCIA driver with the bus core
205 pr_debug("unregistering driver %s\n", driver->name); in pcmcia_unregister_driver()
207 driver_unregister(&driver->drv); in pcmcia_unregister_driver()
218 tmp_dev = get_device(&p_dev->dev); in pcmcia_get_dev()
227 put_device(&p_dev->dev); in pcmcia_put_dev()
242 pcmcia_put_socket(p_dev->socket); in pcmcia_release_dev()
244 kfree(p_dev->prod_id[i]); in pcmcia_release_dev()
245 kfree(p_dev->devname); in pcmcia_release_dev()
246 kref_put(&p_dev->function_config->ref, pcmcia_release_function); in pcmcia_release_dev()
261 return -ENODEV; in pcmcia_device_probe()
264 p_drv = to_pcmcia_drv(dev->driver); in pcmcia_device_probe()
265 s = p_dev->socket; in pcmcia_device_probe()
267 dev_dbg(dev, "trying to bind to %s\n", p_drv->name); in pcmcia_device_probe()
269 if ((!p_drv->probe) || (!p_dev->function_config) || in pcmcia_device_probe()
270 (!try_module_get(p_drv->owner))) { in pcmcia_device_probe()
271 ret = -EINVAL; in pcmcia_device_probe()
276 ret = pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_CONFIG, in pcmcia_device_probe()
279 p_dev->config_base = cis_config.base; in pcmcia_device_probe()
280 p_dev->config_regs = cis_config.rmask[0]; in pcmcia_device_probe()
281 dev_dbg(dev, "base %x, regs %x", p_dev->config_base, in pcmcia_device_probe()
282 p_dev->config_regs); in pcmcia_device_probe()
286 p_dev->config_base = 0; in pcmcia_device_probe()
287 p_dev->config_regs = 0; in pcmcia_device_probe()
290 ret = p_drv->probe(p_dev); in pcmcia_device_probe()
293 p_drv->name, ret); in pcmcia_device_probe()
296 dev_dbg(dev, "%s bound: Vpp %d.%d, idx %x, IRQ %d", p_drv->name, in pcmcia_device_probe()
297 p_dev->vpp/10, p_dev->vpp%10, p_dev->config_index, p_dev->irq); in pcmcia_device_probe()
299 p_dev->resource[0], p_dev->resource[1], p_dev->resource[2], in pcmcia_device_probe()
300 p_dev->resource[3], p_dev->resource[4]); in pcmcia_device_probe()
302 mutex_lock(&s->ops_mutex); in pcmcia_device_probe()
303 if ((s->pcmcia_pfc) && in pcmcia_device_probe()
304 (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) in pcmcia_device_probe()
306 mutex_unlock(&s->ops_mutex); in pcmcia_device_probe()
310 module_put(p_drv->owner); in pcmcia_device_probe()
326 dev_dbg(leftover ? &leftover->dev : &s->dev, in pcmcia_card_remove()
327 "pcmcia_card_remove(%d) %s\n", s->sock, in pcmcia_card_remove()
328 leftover ? leftover->devname : ""); in pcmcia_card_remove()
330 mutex_lock(&s->ops_mutex); in pcmcia_card_remove()
332 s->device_count = 0; in pcmcia_card_remove()
334 s->device_count = 1; in pcmcia_card_remove()
335 mutex_unlock(&s->ops_mutex); in pcmcia_card_remove()
338 list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) { in pcmcia_card_remove()
342 mutex_lock(&s->ops_mutex); in pcmcia_card_remove()
343 list_del(&p_dev->socket_device_list); in pcmcia_card_remove()
344 mutex_unlock(&s->ops_mutex); in pcmcia_card_remove()
346 dev_dbg(&p_dev->dev, "unregistering device\n"); in pcmcia_card_remove()
347 device_unregister(&p_dev->dev); in pcmcia_card_remove()
360 p_drv = to_pcmcia_drv(dev->driver); in pcmcia_device_remove()
365 * pseudo multi-function card, we need to unbind in pcmcia_device_remove()
368 if ((p_dev->socket->pcmcia_pfc) && in pcmcia_device_remove()
369 (p_dev->socket->device_count > 0) && in pcmcia_device_remove()
370 (p_dev->device_no == 0)) in pcmcia_device_remove()
371 pcmcia_card_remove(p_dev->socket, p_dev); in pcmcia_device_remove()
374 if (p_drv->remove) in pcmcia_device_remove()
375 p_drv->remove(p_dev); in pcmcia_device_remove()
378 if (p_dev->_irq || p_dev->_io || p_dev->_locked) in pcmcia_device_remove()
381 p_drv->name); in pcmcia_device_remove()
384 if (p_dev->_win & CLIENT_WIN_REQ(i)) in pcmcia_device_remove()
387 p_drv->name); in pcmcia_device_remove()
391 module_put(p_drv->owner); in pcmcia_device_remove()
396 * pcmcia_device_query -- determine information about a pcmcia device
407 return -ENOMEM; in pcmcia_device_query()
409 if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, in pcmcia_device_query()
411 mutex_lock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
412 p_dev->manf_id = manf_id.manf; in pcmcia_device_query()
413 p_dev->card_id = manf_id.card; in pcmcia_device_query()
414 p_dev->has_manf_id = 1; in pcmcia_device_query()
415 p_dev->has_card_id = 1; in pcmcia_device_query()
416 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
419 if (!pccard_read_tuple(p_dev->socket, p_dev->func, in pcmcia_device_query()
421 mutex_lock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
422 p_dev->func_id = func_id.func; in pcmcia_device_query()
423 p_dev->has_func_id = 1; in pcmcia_device_query()
424 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
428 * probably memory cards (from pcmcia-cs) */ in pcmcia_device_query()
434 return -ENOMEM; in pcmcia_device_query()
436 if (!pccard_read_tuple(p_dev->socket, p_dev->func, in pcmcia_device_query()
438 dev_dbg(&p_dev->dev, in pcmcia_device_query()
441 mutex_lock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
442 p_dev->func_id = CISTPL_FUNCID_MEMORY; in pcmcia_device_query()
443 p_dev->has_func_id = 1; in pcmcia_device_query()
444 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
449 if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_VERS_1, in pcmcia_device_query()
451 mutex_lock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
452 for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) { in pcmcia_device_query()
457 tmp = vers1->str + vers1->ofs[i]; in pcmcia_device_query()
467 tmp = p_dev->prod_id[i]; in pcmcia_device_query()
468 p_dev->prod_id[i] = new; in pcmcia_device_query()
471 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_device_query()
489 pr_debug("adding device to %d, function %d\n", s->sock, function); in pcmcia_device_add()
495 mutex_lock(&s->ops_mutex); in pcmcia_device_add()
496 p_dev->device_no = (s->device_count++); in pcmcia_device_add()
497 mutex_unlock(&s->ops_mutex); in pcmcia_device_add()
500 if ((p_dev->device_no >= 2) && (function == 0)) in pcmcia_device_add()
504 if (p_dev->device_no >= 4) in pcmcia_device_add()
507 p_dev->socket = s; in pcmcia_device_add()
508 p_dev->func = function; in pcmcia_device_add()
510 p_dev->dev.bus = &pcmcia_bus_type; in pcmcia_device_add()
511 p_dev->dev.parent = s->dev.parent; in pcmcia_device_add()
512 p_dev->dev.release = pcmcia_release_dev; in pcmcia_device_add()
514 p_dev->dma_mask = 0; in pcmcia_device_add()
515 p_dev->dev.dma_mask = &p_dev->dma_mask; in pcmcia_device_add()
516 dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no); in pcmcia_device_add()
517 if (!dev_name(&p_dev->dev)) in pcmcia_device_add()
519 p_dev->devname = kasprintf(GFP_KERNEL, "pcmcia%s", dev_name(&p_dev->dev)); in pcmcia_device_add()
520 if (!p_dev->devname) in pcmcia_device_add()
522 dev_dbg(&p_dev->dev, "devname is %s\n", p_dev->devname); in pcmcia_device_add()
524 mutex_lock(&s->ops_mutex); in pcmcia_device_add()
527 * p_dev->function_config must be the same for all card functions. in pcmcia_device_add()
531 list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list) in pcmcia_device_add()
532 if (p_dev->func == tmp_dev->func) { in pcmcia_device_add()
533 p_dev->function_config = tmp_dev->function_config; in pcmcia_device_add()
534 p_dev->irq = tmp_dev->irq; in pcmcia_device_add()
535 kref_get(&p_dev->function_config->ref); in pcmcia_device_add()
539 list_add(&p_dev->socket_device_list, &s->devices_list); in pcmcia_device_add()
542 dev_warn(&p_dev->dev, in pcmcia_device_add()
543 "IRQ setup failed -- device might not work\n"); in pcmcia_device_add()
545 if (!p_dev->function_config) { in pcmcia_device_add()
547 dev_dbg(&p_dev->dev, "creating config_t\n"); in pcmcia_device_add()
550 mutex_unlock(&s->ops_mutex); in pcmcia_device_add()
553 p_dev->function_config = c; in pcmcia_device_add()
554 kref_init(&c->ref); in pcmcia_device_add()
556 c->io[i].name = p_dev->devname; in pcmcia_device_add()
557 c->io[i].flags = IORESOURCE_IO; in pcmcia_device_add()
560 c->mem[i].name = p_dev->devname; in pcmcia_device_add()
561 c->mem[i].flags = IORESOURCE_MEM; in pcmcia_device_add()
565 p_dev->resource[i] = &p_dev->function_config->io[i]; in pcmcia_device_add()
567 p_dev->resource[i] = &p_dev->function_config->mem[i-MAX_IO_WIN]; in pcmcia_device_add()
569 mutex_unlock(&s->ops_mutex); in pcmcia_device_add()
571 dev_notice(&p_dev->dev, "pcmcia: registering new device %s (IRQ: %d)\n", in pcmcia_device_add()
572 p_dev->devname, p_dev->irq); in pcmcia_device_add()
576 if (device_register(&p_dev->dev)) in pcmcia_device_add()
582 mutex_lock(&s->ops_mutex); in pcmcia_device_add()
583 list_del(&p_dev->socket_device_list); in pcmcia_device_add()
584 mutex_unlock(&s->ops_mutex); in pcmcia_device_add()
587 mutex_lock(&s->ops_mutex); in pcmcia_device_add()
588 s->device_count--; in pcmcia_device_add()
589 mutex_unlock(&s->ops_mutex); in pcmcia_device_add()
592 kfree(p_dev->prod_id[i]); in pcmcia_device_add()
593 kfree(p_dev->devname); in pcmcia_device_add()
606 int ret = -EAGAIN; in pcmcia_card_add()
608 mutex_lock(&s->ops_mutex); in pcmcia_card_add()
609 if (!(s->resource_setup_done)) { in pcmcia_card_add()
610 dev_dbg(&s->dev, in pcmcia_card_add()
612 mutex_unlock(&s->ops_mutex); in pcmcia_card_add()
613 return -EAGAIN; /* try again, but later... */ in pcmcia_card_add()
617 dev_dbg(&s->dev, "validating mem resources failed, " in pcmcia_card_add()
619 mutex_unlock(&s->ops_mutex); in pcmcia_card_add()
620 return -EAGAIN; /* try again, but later... */ in pcmcia_card_add()
622 mutex_unlock(&s->ops_mutex); in pcmcia_card_add()
633 if (ret == -EIO) { in pcmcia_card_add()
634 dev_info(&s->dev, "no CIS, assuming an anonymous memory card.\n"); in pcmcia_card_add()
641 dev_dbg(&s->dev, "invalid CIS or invalid resources\n"); in pcmcia_card_add()
642 return -ENODEV; in pcmcia_card_add()
650 s->functions = no_funcs; in pcmcia_card_add()
662 if (!p_dev->dev.driver) { in pcmcia_requery_callback()
675 if (!(s->state & SOCKET_PRESENT)) in pcmcia_requery()
678 if (s->functions == 0) { in pcmcia_requery()
690 if (s->fake_cis) { in pcmcia_requery()
695 old_funcs = s->functions; in pcmcia_requery()
703 /* we need to re-start */ in pcmcia_requery()
705 s->functions = 0; in pcmcia_requery()
711 * call pcmcia_device_add() -- which will fail if both in pcmcia_requery()
713 mutex_lock(&s->ops_mutex); in pcmcia_requery()
714 has_pfc = s->pcmcia_pfc; in pcmcia_requery()
715 mutex_unlock(&s->ops_mutex); in pcmcia_requery()
719 /* we re-scan all devices, not just the ones connected to this in pcmcia_requery()
722 dev_warn(&s->dev, "rescanning the bus failed\n"); in pcmcia_requery()
729 * pcmcia_load_firmware - load CIS from userspace if device-provided is broken
733 * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if
739 struct pcmcia_socket *s = dev->socket; in pcmcia_load_firmware()
741 int ret = -ENOMEM; in pcmcia_load_firmware()
746 return -EINVAL; in pcmcia_load_firmware()
748 dev_dbg(&dev->dev, "trying to load CIS file %s\n", filename); in pcmcia_load_firmware()
750 if (request_firmware(&fw, filename, &dev->dev) == 0) { in pcmcia_load_firmware()
751 if (fw->size >= CISTPL_MAX_CIS_SIZE) { in pcmcia_load_firmware()
752 ret = -EINVAL; in pcmcia_load_firmware()
753 dev_err(&dev->dev, "pcmcia: CIS override is too big\n"); in pcmcia_load_firmware()
757 if (!pcmcia_replace_cis(s, fw->data, fw->size)) in pcmcia_load_firmware()
760 dev_err(&dev->dev, "pcmcia: CIS override failed\n"); in pcmcia_load_firmware()
764 /* we need to re-start if the number of functions changed */ in pcmcia_load_firmware()
765 old_funcs = s->functions; in pcmcia_load_firmware()
771 ret = -EBUSY; in pcmcia_load_firmware()
790 return -ENODEV; in pcmcia_load_firmware()
799 if (did->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID) { in pcmcia_devmatch()
800 if ((!dev->has_manf_id) || (dev->manf_id != did->manf_id)) in pcmcia_devmatch()
804 if (did->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID) { in pcmcia_devmatch()
805 if ((!dev->has_card_id) || (dev->card_id != did->card_id)) in pcmcia_devmatch()
809 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION) { in pcmcia_devmatch()
810 if (dev->func != did->function) in pcmcia_devmatch()
814 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1) { in pcmcia_devmatch()
815 if (!dev->prod_id[0]) in pcmcia_devmatch()
817 if (strcmp(did->prod_id[0], dev->prod_id[0])) in pcmcia_devmatch()
821 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2) { in pcmcia_devmatch()
822 if (!dev->prod_id[1]) in pcmcia_devmatch()
824 if (strcmp(did->prod_id[1], dev->prod_id[1])) in pcmcia_devmatch()
828 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3) { in pcmcia_devmatch()
829 if (!dev->prod_id[2]) in pcmcia_devmatch()
831 if (strcmp(did->prod_id[2], dev->prod_id[2])) in pcmcia_devmatch()
835 if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4) { in pcmcia_devmatch()
836 if (!dev->prod_id[3]) in pcmcia_devmatch()
838 if (strcmp(did->prod_id[3], dev->prod_id[3])) in pcmcia_devmatch()
842 if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { in pcmcia_devmatch()
843 dev_dbg(&dev->dev, "this is a pseudo-multi-function device\n"); in pcmcia_devmatch()
844 mutex_lock(&dev->socket->ops_mutex); in pcmcia_devmatch()
845 dev->socket->pcmcia_pfc = 1; in pcmcia_devmatch()
846 mutex_unlock(&dev->socket->ops_mutex); in pcmcia_devmatch()
847 if (dev->device_no != did->device_no) in pcmcia_devmatch()
851 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { in pcmcia_devmatch()
854 if ((!dev->has_func_id) || (dev->func_id != did->func_id)) in pcmcia_devmatch()
857 /* if this is a pseudo-multi-function device, in pcmcia_devmatch()
859 if (dev->socket->pcmcia_pfc) in pcmcia_devmatch()
861 if (dev->device_no) in pcmcia_devmatch()
865 * after it has re-checked that there is no possible module in pcmcia_devmatch()
868 mutex_lock(&dev->socket->ops_mutex); in pcmcia_devmatch()
869 ret = dev->allow_func_id_match; in pcmcia_devmatch()
870 mutex_unlock(&dev->socket->ops_mutex); in pcmcia_devmatch()
873 dev_dbg(&dev->dev, in pcmcia_devmatch()
879 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { in pcmcia_devmatch()
880 dev_dbg(&dev->dev, "device needs a fake CIS\n"); in pcmcia_devmatch()
881 if (!dev->socket->fake_cis) in pcmcia_devmatch()
882 if (pcmcia_load_firmware(dev, did->cisfile)) in pcmcia_devmatch()
886 if (did->match_flags & PCMCIA_DEV_ID_MATCH_ANONYMOUS) { in pcmcia_devmatch()
889 if (dev->prod_id[i]) in pcmcia_devmatch()
891 if (dev->has_manf_id || dev->has_card_id || dev->has_func_id) in pcmcia_devmatch()
903 const struct pcmcia_device_id *did = p_drv->id_table; in pcmcia_bus_match()
907 mutex_lock(&p_drv->dynids.lock); in pcmcia_bus_match()
908 list_for_each_entry(dynid, &p_drv->dynids.list, node) { in pcmcia_bus_match()
909 dev_dbg(dev, "trying to match to %s\n", drv->name); in pcmcia_bus_match()
910 if (pcmcia_devmatch(p_dev, &dynid->id)) { in pcmcia_bus_match()
911 dev_dbg(dev, "matched to %s\n", drv->name); in pcmcia_bus_match()
912 mutex_unlock(&p_drv->dynids.lock); in pcmcia_bus_match()
916 mutex_unlock(&p_drv->dynids.lock); in pcmcia_bus_match()
918 while (did && did->match_flags) { in pcmcia_bus_match()
919 dev_dbg(dev, "trying to match to %s\n", drv->name); in pcmcia_bus_match()
921 dev_dbg(dev, "matched to %s\n", drv->name); in pcmcia_bus_match()
937 return -ENODEV; in pcmcia_bus_uevent()
943 if (!p_dev->prod_id[i]) in pcmcia_bus_uevent()
945 hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i])); in pcmcia_bus_uevent()
948 if (add_uevent_var(env, "SOCKET_NO=%u", p_dev->socket->sock)) in pcmcia_bus_uevent()
949 return -ENOMEM; in pcmcia_bus_uevent()
951 if (add_uevent_var(env, "DEVICE_NO=%02X", p_dev->device_no)) in pcmcia_bus_uevent()
952 return -ENOMEM; in pcmcia_bus_uevent()
956 p_dev->has_manf_id ? p_dev->manf_id : 0, in pcmcia_bus_uevent()
957 p_dev->has_card_id ? p_dev->card_id : 0, in pcmcia_bus_uevent()
958 p_dev->has_func_id ? p_dev->func_id : 0, in pcmcia_bus_uevent()
959 p_dev->func, in pcmcia_bus_uevent()
960 p_dev->device_no, in pcmcia_bus_uevent()
965 return -ENOMEM; in pcmcia_bus_uevent()
995 /************************ per-device sysfs output ***************************/
998 static ssize_t field##_show (struct device *dev, struct device_attribute *attr, char *buf) \
1001 return p_dev->test ? sysfs_emit(buf, format, p_dev->field) : -ENODEV; \
1006 static ssize_t name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
1009 return p_dev->field ? sysfs_emit(buf, "%s\n", p_dev->field) : -ENODEV; \
1021 static ssize_t function_show(struct device *dev, struct device_attribute *attr, in function_show() argument
1025 return p_dev->socket ? sysfs_emit(buf, "0x%02x\n", p_dev->func) : -ENODEV; in function_show()
1030 struct device_attribute *attr, char *buf) in resources_show() argument
1036 at += sysfs_emit_at(buf, at, "%pr\n", p_dev->resource[i]); in resources_show()
1042 static ssize_t pm_state_show(struct device *dev, struct device_attribute *attr, char *buf) in pm_state_show() argument
1046 if (p_dev->suspended) in pm_state_show()
1052 static ssize_t pm_state_store(struct device *dev, struct device_attribute *attr, in pm_state_store() argument
1059 return -EINVAL; in pm_state_store()
1061 if ((!p_dev->suspended) && !strncmp(buf, "off", 3)) in pm_state_store()
1063 else if (p_dev->suspended && !strncmp(buf, "on", 2)) in pm_state_store()
1070 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) in modalias_show() argument
1078 if (!p_dev->prod_id[i]) in modalias_show()
1080 hash[i] = crc32(0, p_dev->prod_id[i], in modalias_show()
1081 strlen(p_dev->prod_id[i])); in modalias_show()
1084 p_dev->has_manf_id ? p_dev->manf_id : 0, in modalias_show()
1085 p_dev->has_card_id ? p_dev->card_id : 0, in modalias_show()
1086 p_dev->has_func_id ? p_dev->func_id : 0, in modalias_show()
1087 p_dev->func, p_dev->device_no, in modalias_show()
1093 struct device_attribute *attr, const char *buf, size_t count) in allow_func_id_match_store() argument
1098 return -EINVAL; in allow_func_id_match_store()
1100 mutex_lock(&p_dev->socket->ops_mutex); in allow_func_id_match_store()
1101 p_dev->allow_func_id_match = 1; in allow_func_id_match_store()
1102 mutex_unlock(&p_dev->socket->ops_mutex); in allow_func_id_match_store()
1103 pcmcia_parse_uevents(p_dev->socket, PCMCIA_UEVENT_REQUERY); in allow_func_id_match_store()
1110 &dev_attr_resources.attr,
1111 &dev_attr_pm_state.attr,
1112 &dev_attr_function.attr,
1113 &dev_attr_func_id.attr,
1114 &dev_attr_manf_id.attr,
1115 &dev_attr_card_id.attr,
1116 &dev_attr_prod_id1.attr,
1117 &dev_attr_prod_id2.attr,
1118 &dev_attr_prod_id3.attr,
1119 &dev_attr_prod_id4.attr,
1120 &dev_attr_modalias.attr,
1121 &dev_attr_allow_func_id_match.attr,
1134 mutex_lock(&p_dev->socket->ops_mutex); in pcmcia_dev_suspend()
1135 if (p_dev->suspended) { in pcmcia_dev_suspend()
1136 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_dev_suspend()
1139 p_dev->suspended = 1; in pcmcia_dev_suspend()
1140 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_dev_suspend()
1144 if (dev->driver) in pcmcia_dev_suspend()
1145 p_drv = to_pcmcia_drv(dev->driver); in pcmcia_dev_suspend()
1150 if (p_drv->suspend) { in pcmcia_dev_suspend()
1151 ret = p_drv->suspend(p_dev); in pcmcia_dev_suspend()
1155 p_dev->devname, p_drv->name, ret); in pcmcia_dev_suspend()
1156 mutex_lock(&p_dev->socket->ops_mutex); in pcmcia_dev_suspend()
1157 p_dev->suspended = 0; in pcmcia_dev_suspend()
1158 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_dev_suspend()
1163 if (p_dev->device_no == p_dev->func) { in pcmcia_dev_suspend()
1179 mutex_lock(&p_dev->socket->ops_mutex); in pcmcia_dev_resume()
1180 if (!p_dev->suspended) { in pcmcia_dev_resume()
1181 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_dev_resume()
1184 p_dev->suspended = 0; in pcmcia_dev_resume()
1185 mutex_unlock(&p_dev->socket->ops_mutex); in pcmcia_dev_resume()
1189 if (dev->driver) in pcmcia_dev_resume()
1190 p_drv = to_pcmcia_drv(dev->driver); in pcmcia_dev_resume()
1195 if (p_dev->device_no == p_dev->func) { in pcmcia_dev_resume()
1202 if (p_drv->resume) in pcmcia_dev_resume()
1203 ret = p_drv->resume(p_dev); in pcmcia_dev_resume()
1215 if (p_dev->socket != skt || p_dev->suspended) in pcmcia_bus_suspend_callback()
1226 if (p_dev->socket != skt || !p_dev->suspended) in pcmcia_bus_resume_callback()
1236 dev_dbg(&skt->dev, "resuming socket %d\n", skt->sock); in pcmcia_bus_resume()
1243 dev_dbg(&skt->dev, "suspending socket %d\n", skt->sock); in pcmcia_bus_suspend()
1247 return -EIO; in pcmcia_bus_suspend()
1254 atomic_set(&skt->present, 0); in pcmcia_bus_remove()
1257 mutex_lock(&skt->ops_mutex); in pcmcia_bus_remove()
1260 mutex_unlock(&skt->ops_mutex); in pcmcia_bus_remove()
1267 atomic_set(&skt->present, 1); in pcmcia_bus_add()
1269 mutex_lock(&skt->ops_mutex); in pcmcia_bus_add()
1270 skt->pcmcia_pfc = 0; in pcmcia_bus_add()
1272 mutex_unlock(&skt->ops_mutex); in pcmcia_bus_add()
1284 dev_dbg(&skt->dev, "cis mismatch - different card\n"); in pcmcia_bus_early_resume()
1289 mutex_lock(&skt->ops_mutex); in pcmcia_bus_early_resume()
1291 kfree(skt->fake_cis); in pcmcia_bus_early_resume()
1292 skt->fake_cis = NULL; in pcmcia_bus_early_resume()
1293 skt->functions = 0; in pcmcia_bus_early_resume()
1294 mutex_unlock(&skt->ops_mutex); in pcmcia_bus_early_resume()
1305 * non-NULL. Furthermore, the device driver most likely is unbound
1318 if (atomic_read(&p_dev->socket->present) != 0) in pcmcia_dev_present()
1346 return -ENODEV; in pcmcia_bus_add_socket()
1349 ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); in pcmcia_bus_add_socket()
1356 INIT_LIST_HEAD(&socket->devices_list); in pcmcia_bus_add_socket()
1357 socket->pcmcia_pfc = 0; in pcmcia_bus_add_socket()
1358 socket->device_count = 0; in pcmcia_bus_add_socket()
1359 atomic_set(&socket->present, 0); in pcmcia_bus_add_socket()
1381 mutex_lock(&socket->skt_mutex); in pcmcia_bus_remove_socket()
1384 mutex_unlock(&socket->skt_mutex); in pcmcia_bus_remove_socket()
1386 sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); in pcmcia_bus_remove_socket()