xref: /linux/drivers/zorro/names.c (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *	Zorro Device Name Tables
4  *
5  *	Copyright (C) 1999--2000 Geert Uytterhoeven
6  *
7  *	Based on the PCI version:
8  *
9  *	Copyright 1992--1999 Drew Eckhardt, Frederic Potter,
10  *	David Mosberger-Tang, Martin Mares
11  */
12 
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/zorro.h>
17 
18 #include "zorro.h"
19 
20 struct zorro_prod_info {
21 	__u16 prod;
22 	unsigned short seen;
23 	const char *name;
24 };
25 
26 struct zorro_manuf_info {
27 	__u16 manuf;
28 	unsigned short nr;
29 	const char *name;
30 	struct zorro_prod_info *prods;
31 };
32 
33 /*
34  * This is ridiculous, but we want the strings in
35  * the .init section so that they don't take up
36  * real memory.. Parse the same file multiple times
37  * to get all the info.
38  */
39 #define MANUF( manuf, name )		static char __manufstr_##manuf[] __initdata = name;
40 #define ENDMANUF()
41 #define PRODUCT( manuf, prod, name ) 	static char __prodstr_##manuf##prod[] __initdata = name;
42 #include "devlist.h"
43 
44 
45 #define MANUF( manuf, name )		static struct zorro_prod_info __prods_##manuf[] __initdata = {
46 #define ENDMANUF()			};
47 #define PRODUCT( manuf, prod, name )	{ 0x##prod, 0, __prodstr_##manuf##prod },
48 #include "devlist.h"
49 
50 static struct zorro_manuf_info __initdata zorro_manuf_list[] = {
51 #define MANUF( manuf, name )		{ 0x##manuf, ARRAY_SIZE(__prods_##manuf), __manufstr_##manuf, __prods_##manuf },
52 #define ENDMANUF()
53 #define PRODUCT( manuf, prod, name )
54 #include "devlist.h"
55 };
56 
57 #define MANUFS ARRAY_SIZE(zorro_manuf_list)
58 
59 void __init zorro_name_device(struct zorro_dev *dev)
60 {
61 	const struct zorro_manuf_info *manuf_p = zorro_manuf_list;
62 	int i = MANUFS;
63 	char *name = dev->name;
64 
65 	do {
66 		if (manuf_p->manuf == ZORRO_MANUF(dev->id))
67 			goto match_manuf;
68 		manuf_p++;
69 	} while (--i);
70 
71 	/* Couldn't find either the manufacturer nor the product */
72 	return;
73 
74 	match_manuf: {
75 		struct zorro_prod_info *prod_p = manuf_p->prods;
76 		int i = manuf_p->nr;
77 
78 		while (i > 0) {
79 			if (prod_p->prod ==
80 			    ((ZORRO_PROD(dev->id)<<8) | ZORRO_EPC(dev->id)))
81 				goto match_prod;
82 			prod_p++;
83 			i--;
84 		}
85 
86 		/* Ok, found the manufacturer, but unknown product */
87 		sprintf(name, "Zorro device %08x (%s)", dev->id, manuf_p->name);
88 		return;
89 
90 		/* Full match */
91 		match_prod: {
92 			char *n = name + sprintf(name, "%s %s", manuf_p->name, prod_p->name);
93 			int nr = prod_p->seen + 1;
94 			prod_p->seen = nr;
95 			if (nr > 1)
96 				sprintf(n, " (#%d)", nr);
97 		}
98 	}
99 }
100