names.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/zorro.h>
  16. struct zorro_prod_info {
  17. __u16 prod;
  18. unsigned short seen;
  19. const char *name;
  20. };
  21. struct zorro_manuf_info {
  22. __u16 manuf;
  23. unsigned short nr;
  24. const char *name;
  25. struct zorro_prod_info *prods;
  26. };
  27. /*
  28. * This is ridiculous, but we want the strings in
  29. * the .init section so that they don't take up
  30. * real memory.. Parse the same file multiple times
  31. * to get all the info.
  32. */
  33. #define MANUF( manuf, name ) static char __manufstr_##manuf[] __initdata = name;
  34. #define ENDMANUF()
  35. #define PRODUCT( manuf, prod, name ) static char __prodstr_##manuf##prod[] __initdata = name;
  36. #include "devlist.h"
  37. #define MANUF( manuf, name ) static struct zorro_prod_info __prods_##manuf[] __initdata = {
  38. #define ENDMANUF() };
  39. #define PRODUCT( manuf, prod, name ) { 0x##prod, 0, __prodstr_##manuf##prod },
  40. #include "devlist.h"
  41. static struct zorro_manuf_info __initdata zorro_manuf_list[] = {
  42. #define MANUF( manuf, name ) { 0x##manuf, ARRAY_SIZE(__prods_##manuf), __manufstr_##manuf, __prods_##manuf },
  43. #define ENDMANUF()
  44. #define PRODUCT( manuf, prod, name )
  45. #include "devlist.h"
  46. };
  47. #define MANUFS ARRAY_SIZE(zorro_manuf_list)
  48. void __init zorro_name_device(struct zorro_dev *dev)
  49. {
  50. const struct zorro_manuf_info *manuf_p = zorro_manuf_list;
  51. int i = MANUFS;
  52. char *name = dev->name;
  53. do {
  54. if (manuf_p->manuf == ZORRO_MANUF(dev->id))
  55. goto match_manuf;
  56. manuf_p++;
  57. } while (--i);
  58. /* Couldn't find either the manufacturer nor the product */
  59. return;
  60. match_manuf: {
  61. struct zorro_prod_info *prod_p = manuf_p->prods;
  62. int i = manuf_p->nr;
  63. while (i > 0) {
  64. if (prod_p->prod ==
  65. ((ZORRO_PROD(dev->id)<<8) | ZORRO_EPC(dev->id)))
  66. goto match_prod;
  67. prod_p++;
  68. i--;
  69. }
  70. /* Ok, found the manufacturer, but unknown product */
  71. sprintf(name, "Zorro device %08x (%s)", dev->id, manuf_p->name);
  72. return;
  73. /* Full match */
  74. match_prod: {
  75. char *n = name + sprintf(name, "%s %s", manuf_p->name, prod_p->name);
  76. int nr = prod_p->seen + 1;
  77. prod_p->seen = nr;
  78. if (nr > 1)
  79. sprintf(n, " (#%d)", nr);
  80. }
  81. }
  82. }