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