Linux 6.10
[linux-2.6-block.git] / drivers / pnp / isapnp / compat.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
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.
5 *
6 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
1da177e4 7 */
9dd78466 8
1da177e4
LT
9#include <linux/module.h>
10#include <linux/isapnp.h>
11#include <linux/string.h>
12
9dd78466
BH
13static void pnp_convert_id(char *buf, unsigned short vendor,
14 unsigned short device)
1da177e4
LT
15{
16 sprintf(buf, "%c%c%c%x%x%x%x",
9dd78466
BH
17 'A' + ((vendor >> 2) & 0x3f) - 1,
18 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
19 'A' + ((vendor >> 8) & 0x1f) - 1,
07d4e9af
BH
20 (device >> 4) & 0x0f, device & 0x0f,
21 (device >> 12) & 0x0f, (device >> 8) & 0x0f);
1da177e4
LT
22}
23
07d4e9af 24struct pnp_dev *pnp_find_dev(struct pnp_card *card, unsigned short vendor,
9dd78466 25 unsigned short function, struct pnp_dev *from)
1da177e4
LT
26{
27 char id[8];
28 char any[8];
07d4e9af 29
1da177e4
LT
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;
34
35 list = pnp_global.next;
36 if (from)
37 list = from->global_list.next;
38
39 while (list != &pnp_global) {
40 struct pnp_dev *dev = global_to_pnp_dev(list);
07d4e9af
BH
41
42 if (compare_pnp_id(dev->id, id) ||
43 (memcmp(id, any, 7) == 0))
1da177e4
LT
44 return dev;
45 list = list->next;
46 }
47 } else {
48 struct list_head *list;
49
50 list = card->devices.next;
51 if (from) {
52 list = from->card_list.next;
53 if (from->card != card) /* something is wrong */
54 return NULL;
55 }
56 while (list != &card->devices) {
57 struct pnp_dev *dev = card_to_pnp_dev(list);
07d4e9af 58
9dd78466 59 if (compare_pnp_id(dev->id, id))
1da177e4
LT
60 return dev;
61 list = list->next;
62 }
63 }
64 return NULL;
65}
1da177e4 66EXPORT_SYMBOL(pnp_find_dev);