compat.c 2.1 KB

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