Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * compat.c - A series of functions to make it easier to convert drivers that use
0004  *            the old isapnp APIs. If possible use the new APIs instead.
0005  *
0006  * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
0007  */
0008 
0009 #include <linux/module.h>
0010 #include <linux/isapnp.h>
0011 #include <linux/string.h>
0012 
0013 static void pnp_convert_id(char *buf, unsigned short vendor,
0014                unsigned short device)
0015 {
0016     sprintf(buf, "%c%c%c%x%x%x%x",
0017         'A' + ((vendor >> 2) & 0x3f) - 1,
0018         'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
0019         'A' + ((vendor >> 8) & 0x1f) - 1,
0020         (device >> 4) & 0x0f, device & 0x0f,
0021         (device >> 12) & 0x0f, (device >> 8) & 0x0f);
0022 }
0023 
0024 struct pnp_dev *pnp_find_dev(struct pnp_card *card, unsigned short vendor,
0025                  unsigned short function, struct pnp_dev *from)
0026 {
0027     char id[8];
0028     char any[8];
0029 
0030     pnp_convert_id(id, vendor, function);
0031     pnp_convert_id(any, ISAPNP_ANY_ID, ISAPNP_ANY_ID);
0032     if (card == NULL) { /* look for a logical device from all cards */
0033         struct list_head *list;
0034 
0035         list = pnp_global.next;
0036         if (from)
0037             list = from->global_list.next;
0038 
0039         while (list != &pnp_global) {
0040             struct pnp_dev *dev = global_to_pnp_dev(list);
0041 
0042             if (compare_pnp_id(dev->id, id) ||
0043                 (memcmp(id, any, 7) == 0))
0044                 return dev;
0045             list = list->next;
0046         }
0047     } else {
0048         struct list_head *list;
0049 
0050         list = card->devices.next;
0051         if (from) {
0052             list = from->card_list.next;
0053             if (from->card != card) /* something is wrong */
0054                 return NULL;
0055         }
0056         while (list != &card->devices) {
0057             struct pnp_dev *dev = card_to_pnp_dev(list);
0058 
0059             if (compare_pnp_id(dev->id, id))
0060                 return dev;
0061             list = list->next;
0062         }
0063     }
0064     return NULL;
0065 }
0066 EXPORT_SYMBOL(pnp_find_dev);