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