diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/pnp/isapnp/compat.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/pnp/isapnp/compat.c')
-rw-r--r-- | drivers/pnp/isapnp/compat.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/drivers/pnp/isapnp/compat.c b/drivers/pnp/isapnp/compat.c new file mode 100644 index 000000000000..3ff7e76b33bd --- /dev/null +++ b/drivers/pnp/isapnp/compat.c | |||
@@ -0,0 +1,91 @@ | |||
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 | |||
9 | /* TODO: see if more isapnp functions are needed here */ | ||
10 | |||
11 | #include <linux/config.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/isapnp.h> | ||
14 | #include <linux/string.h> | ||
15 | |||
16 | static void pnp_convert_id(char *buf, unsigned short vendor, unsigned short device) | ||
17 | { | ||
18 | sprintf(buf, "%c%c%c%x%x%x%x", | ||
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, | ||
24 | (device >> 12) & 0x0f, | ||
25 | (device >> 8) & 0x0f); | ||
26 | } | ||
27 | |||
28 | struct pnp_card *pnp_find_card(unsigned short vendor, | ||
29 | unsigned short device, | ||
30 | struct pnp_card *from) | ||
31 | { | ||
32 | char id[8]; | ||
33 | char any[8]; | ||
34 | struct list_head *list; | ||
35 | pnp_convert_id(id, vendor, device); | ||
36 | pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID); | ||
37 | |||
38 | list = from ? from->global_list.next : pnp_cards.next; | ||
39 | |||
40 | while (list != &pnp_cards) { | ||
41 | struct pnp_card *card = global_to_pnp_card(list); | ||
42 | if (compare_pnp_id(card->id,id) || (memcmp(id,any,7)==0)) | ||
43 | return card; | ||
44 | list = list->next; | ||
45 | } | ||
46 | return NULL; | ||
47 | } | ||
48 | |||
49 | struct pnp_dev *pnp_find_dev(struct pnp_card *card, | ||
50 | unsigned short vendor, | ||
51 | unsigned short function, | ||
52 | struct pnp_dev *from) | ||
53 | { | ||
54 | char id[8]; | ||
55 | char any[8]; | ||
56 | pnp_convert_id(id, vendor, function); | ||
57 | pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID); | ||
58 | if (card == NULL) { /* look for a logical device from all cards */ | ||
59 | struct list_head *list; | ||
60 | |||
61 | list = pnp_global.next; | ||
62 | if (from) | ||
63 | list = from->global_list.next; | ||
64 | |||
65 | while (list != &pnp_global) { | ||
66 | struct pnp_dev *dev = global_to_pnp_dev(list); | ||
67 | if (compare_pnp_id(dev->id,id) || (memcmp(id,any,7)==0)) | ||
68 | return dev; | ||
69 | list = list->next; | ||
70 | } | ||
71 | } else { | ||
72 | struct list_head *list; | ||
73 | |||
74 | list = card->devices.next; | ||
75 | if (from) { | ||
76 | list = from->card_list.next; | ||
77 | if (from->card != card) /* something is wrong */ | ||
78 | return NULL; | ||
79 | } | ||
80 | while (list != &card->devices) { | ||
81 | struct pnp_dev *dev = card_to_pnp_dev(list); | ||
82 | if (compare_pnp_id(dev->id,id)) | ||
83 | return dev; | ||
84 | list = list->next; | ||
85 | } | ||
86 | } | ||
87 | return NULL; | ||
88 | } | ||
89 | |||
90 | EXPORT_SYMBOL(pnp_find_card); | ||
91 | EXPORT_SYMBOL(pnp_find_dev); | ||