compat.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * compat.c - A series of functions to make it easier to convert drivers that use
  4. * the old isapnp APIs. If possible use the new APIs instead.
  5. *
  6. * Copyright 2002 Adam Belay <[email protected]>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/isapnp.h>
  10. #include <linux/string.h>
  11. static void pnp_convert_id(char *buf, unsigned short vendor,
  12. unsigned short device)
  13. {
  14. sprintf(buf, "%c%c%c%x%x%x%x",
  15. 'A' + ((vendor >> 2) & 0x3f) - 1,
  16. 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
  17. 'A' + ((vendor >> 8) & 0x1f) - 1,
  18. (device >> 4) & 0x0f, device & 0x0f,
  19. (device >> 12) & 0x0f, (device >> 8) & 0x0f);
  20. }
  21. struct pnp_dev *pnp_find_dev(struct pnp_card *card, unsigned short vendor,
  22. unsigned short function, struct pnp_dev *from)
  23. {
  24. char id[8];
  25. char any[8];
  26. pnp_convert_id(id, vendor, function);
  27. pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
  28. if (card == NULL) { /* look for a logical device from all cards */
  29. struct list_head *list;
  30. list = pnp_global.next;
  31. if (from)
  32. list = from->global_list.next;
  33. while (list != &pnp_global) {
  34. struct pnp_dev *dev = global_to_pnp_dev(list);
  35. if (compare_pnp_id(dev->id, id) ||
  36. (memcmp(id, any, 7) == 0))
  37. return dev;
  38. list = list->next;
  39. }
  40. } else {
  41. struct list_head *list;
  42. list = card->devices.next;
  43. if (from) {
  44. list = from->card_list.next;
  45. if (from->card != card) /* something is wrong */
  46. return NULL;
  47. }
  48. while (list != &card->devices) {
  49. struct pnp_dev *dev = card_to_pnp_dev(list);
  50. if (compare_pnp_id(dev->id, id))
  51. return dev;
  52. list = list->next;
  53. }
  54. }
  55. return NULL;
  56. }
  57. EXPORT_SYMBOL(pnp_find_dev);