compat.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * compat.c - A series of functions to make it easier to convert drivers that use
  3. * the old isapnp APIs. If possible use the new APIs instead.
  4. *
  5. * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
  6. *
  7. */
  8. /* TODO: see if more isapnp functions are needed here */
  9. #include <linux/module.h>
  10. #include <linux/isapnp.h>
  11. #include <linux/string.h>
  12. static void pnp_convert_id(char *buf, unsigned short vendor, 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,
  19. device & 0x0f,
  20. (device >> 12) & 0x0f,
  21. (device >> 8) & 0x0f);
  22. }
  23. struct pnp_card *pnp_find_card(unsigned short vendor,
  24. unsigned short device,
  25. struct pnp_card *from)
  26. {
  27. char id[8];
  28. char any[8];
  29. struct list_head *list;
  30. pnp_convert_id(id, vendor, device);
  31. pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
  32. list = from ? from->global_list.next : pnp_cards.next;
  33. while (list != &pnp_cards) {
  34. struct pnp_card *card = global_to_pnp_card(list);
  35. if (compare_pnp_id(card->id,id) || (memcmp(id,any,7)==0))
  36. return card;
  37. list = list->next;
  38. }
  39. return NULL;
  40. }
  41. struct pnp_dev *pnp_find_dev(struct pnp_card *card,
  42. unsigned short vendor,
  43. unsigned short function,
  44. struct pnp_dev *from)
  45. {
  46. char id[8];
  47. char any[8];
  48. pnp_convert_id(id, vendor, function);
  49. pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
  50. if (card == NULL) { /* look for a logical device from all cards */
  51. struct list_head *list;
  52. list = pnp_global.next;
  53. if (from)
  54. list = from->global_list.next;
  55. while (list != &pnp_global) {
  56. struct pnp_dev *dev = global_to_pnp_dev(list);
  57. if (compare_pnp_id(dev->id,id) || (memcmp(id,any,7)==0))
  58. return dev;
  59. list = list->next;
  60. }
  61. } else {
  62. struct list_head *list;
  63. list = card->devices.next;
  64. if (from) {
  65. list = from->card_list.next;
  66. if (from->card != card) /* something is wrong */
  67. return NULL;
  68. }
  69. while (list != &card->devices) {
  70. struct pnp_dev *dev = card_to_pnp_dev(list);
  71. if (compare_pnp_id(dev->id,id))
  72. return dev;
  73. list = list->next;
  74. }
  75. }
  76. return NULL;
  77. }
  78. EXPORT_SYMBOL(pnp_find_card);
  79. EXPORT_SYMBOL(pnp_find_dev);