1 // SPDX-License-Identifier: GPL-2.0
3 * compat.c - A series of functions to make it easier to convert drivers that use
4 * the old isapnp APIs. If possible use the new APIs instead.
6 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
9 #include <linux/module.h>
10 #include <linux/isapnp.h>
11 #include <linux/string.h>
13 static void pnp_convert_id(char *buf
, unsigned short vendor
,
14 unsigned short device
)
16 sprintf(buf
, "%c%c%c%x%x%x%x",
17 'A' + ((vendor
>> 2) & 0x3f) - 1,
18 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
19 'A' + ((vendor
>> 8) & 0x1f) - 1,
20 (device
>> 4) & 0x0f, device
& 0x0f,
21 (device
>> 12) & 0x0f, (device
>> 8) & 0x0f);
24 struct pnp_dev
*pnp_find_dev(struct pnp_card
*card
, unsigned short vendor
,
25 unsigned short function
, struct pnp_dev
*from
)
30 pnp_convert_id(id
, vendor
, function
);
31 pnp_convert_id(any
, ISAPNP_ANY_ID
, ISAPNP_ANY_ID
);
32 if (card
== NULL
) { /* look for a logical device from all cards */
33 struct list_head
*list
;
35 list
= pnp_global
.next
;
37 list
= from
->global_list
.next
;
39 while (list
!= &pnp_global
) {
40 struct pnp_dev
*dev
= global_to_pnp_dev(list
);
42 if (compare_pnp_id(dev
->id
, id
) ||
43 (memcmp(id
, any
, 7) == 0))
48 struct list_head
*list
;
50 list
= card
->devices
.next
;
52 list
= from
->card_list
.next
;
53 if (from
->card
!= card
) /* something is wrong */
56 while (list
!= &card
->devices
) {
57 struct pnp_dev
*dev
= card_to_pnp_dev(list
);
59 if (compare_pnp_id(dev
->id
, id
))
66 EXPORT_SYMBOL(pnp_find_dev
);