compat.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/config.h>
  10. #include <linux/module.h>
  11. #include <linux/isapnp.h>
  12. #include <linux/string.h>
  13. static void pnp_convert_id(char *buf, unsigned short vendor, unsigned short device)
  14. {
  15. sprintf(buf, "%c%c%c%x%x%x%x",
  16. 'A' + ((vendor >> 2) & 0x3f) - 1,
  17. 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
  18. 'A' + ((vendor >> 8) & 0x1f) - 1,
  19. (device >> 4) & 0x0f,
  20. device & 0x0f,
  21. (device >> 12) & 0x0f,
  22. (device >> 8) & 0x0f);
  23. }
  24. struct pnp_card *pnp_find_card(unsigned short vendor,
  25. unsigned short device,
  26. struct pnp_card *from)
  27. {
  28. char id[8];
  29. char any[8];
  30. struct list_head *list;
  31. pnp_convert_id(id, vendor, device);
  32. pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
  33. list = from ? from->global_list.next : pnp_cards.next;
  34. while (list != &pnp_cards) {
  35. struct pnp_card *card = global_to_pnp_card(list);
  36. if (compare_pnp_id(card->id,id) || (memcmp(id,any,7)==0))
  37. return card;
  38. list = list->next;
  39. }
  40. return NULL;
  41. }
  42. struct pnp_dev *pnp_find_dev(struct pnp_card *card,
  43. unsigned short vendor,
  44. unsigned short function,
  45. struct pnp_dev *from)
  46. {
  47. char id[8];
  48. char any[8];
  49. pnp_convert_id(id, vendor, function);
  50. pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
  51. if (card == NULL) { /* look for a logical device from all cards */
  52. struct list_head *list;
  53. list = pnp_global.next;
  54. if (from)
  55. list = from->global_list.next;
  56. while (list != &pnp_global) {
  57. struct pnp_dev *dev = global_to_pnp_dev(list);
  58. if (compare_pnp_id(dev->id,id) || (memcmp(id,any,7)==0))
  59. return dev;
  60. list = list->next;
  61. }
  62. } else {
  63. struct list_head *list;
  64. list = card->devices.next;
  65. if (from) {
  66. list = from->card_list.next;
  67. if (from->card != card) /* something is wrong */
  68. return NULL;
  69. }
  70. while (list != &card->devices) {
  71. struct pnp_dev *dev = card_to_pnp_dev(list);
  72. if (compare_pnp_id(dev->id,id))
  73. return dev;
  74. list = list->next;
  75. }
  76. }
  77. return NULL;
  78. }
  79. EXPORT_SYMBOL(pnp_find_card);
  80. EXPORT_SYMBOL(pnp_find_dev);