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