]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/pnp/isapnp/compat.c
Merge tag 'staging-4.15-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[mirror_ubuntu-bionic-kernel.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
BH
24struct pnp_card *pnp_find_card(unsigned short vendor, unsigned short device,
25 struct pnp_card *from)
1da177e4
LT
26{
27 char id[8];
28 char any[8];
29 struct list_head *list;
07d4e9af 30
1da177e4
LT
31 pnp_convert_id(id, vendor, device);
32 pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
33
34 list = from ? from->global_list.next : pnp_cards.next;
35
36 while (list != &pnp_cards) {
37 struct pnp_card *card = global_to_pnp_card(list);
07d4e9af 38
9dd78466 39 if (compare_pnp_id(card->id, id) || (memcmp(id, any, 7) == 0))
1da177e4
LT
40 return card;
41 list = list->next;
42 }
43 return NULL;
44}
45
07d4e9af 46struct pnp_dev *pnp_find_dev(struct pnp_card *card, unsigned short vendor,
9dd78466 47 unsigned short function, struct pnp_dev *from)
1da177e4
LT
48{
49 char id[8];
50 char any[8];
07d4e9af 51
1da177e4
LT
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);
07d4e9af
BH
63
64 if (compare_pnp_id(dev->id, id) ||
65 (memcmp(id, any, 7) == 0))
1da177e4
LT
66 return dev;
67 list = list->next;
68 }
69 } else {
70 struct list_head *list;
71
72 list = card->devices.next;
73 if (from) {
74 list = from->card_list.next;
75 if (from->card != card) /* something is wrong */
76 return NULL;
77 }
78 while (list != &card->devices) {
79 struct pnp_dev *dev = card_to_pnp_dev(list);
07d4e9af 80
9dd78466 81 if (compare_pnp_id(dev->id, id))
1da177e4
LT
82 return dev;
83 list = list->next;
84 }
85 }
86 return NULL;
87}
88
89EXPORT_SYMBOL(pnp_find_card);
90EXPORT_SYMBOL(pnp_find_dev);