debug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * cb710/debug.c
  3. *
  4. * Copyright by Michał Mirosław, 2008-2009
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/cb710.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #define CB710_REG_COUNT 0x80
  14. static const u16 allow[CB710_REG_COUNT/16] = {
  15. 0xFFF0, 0xFFFF, 0xFFFF, 0xFFFF,
  16. 0xFFF0, 0xFFFF, 0xFFFF, 0xFFFF,
  17. };
  18. static const char *const prefix[ARRAY_SIZE(allow)] = {
  19. "MMC", "MMC", "MMC", "MMC",
  20. "MS?", "MS?", "SM?", "SM?"
  21. };
  22. static inline int allow_reg_read(unsigned block, unsigned offset, unsigned bits)
  23. {
  24. unsigned mask = (1 << bits/8) - 1;
  25. offset *= bits/8;
  26. return ((allow[block] >> offset) & mask) == mask;
  27. }
  28. #define CB710_READ_REGS_TEMPLATE(t) \
  29. static void cb710_read_regs_##t(void __iomem *iobase, \
  30. u##t *reg, unsigned select) \
  31. { \
  32. unsigned i, j; \
  33. \
  34. for (i = 0; i < ARRAY_SIZE(allow); ++i, reg += 16/(t/8)) { \
  35. if (!(select & (1 << i))) \
  36. continue; \
  37. \
  38. for (j = 0; j < 0x10/(t/8); ++j) { \
  39. if (!allow_reg_read(i, j, t)) \
  40. continue; \
  41. reg[j] = ioread##t(iobase \
  42. + (i << 4) + (j * (t/8))); \
  43. } \
  44. } \
  45. }
  46. static const char cb710_regf_8[] = "%02X";
  47. static const char cb710_regf_16[] = "%04X";
  48. static const char cb710_regf_32[] = "%08X";
  49. static const char cb710_xes[] = "xxxxxxxx";
  50. #define CB710_DUMP_REGS_TEMPLATE(t) \
  51. static void cb710_dump_regs_##t(struct device *dev, \
  52. const u##t *reg, unsigned select) \
  53. { \
  54. const char *const xp = &cb710_xes[8 - t/4]; \
  55. const char *const format = cb710_regf_##t; \
  56. \
  57. char msg[100], *p; \
  58. unsigned i, j; \
  59. \
  60. for (i = 0; i < ARRAY_SIZE(allow); ++i, reg += 16/(t/8)) { \
  61. if (!(select & (1 << i))) \
  62. continue; \
  63. p = msg; \
  64. for (j = 0; j < 0x10/(t/8); ++j) { \
  65. *p++ = ' '; \
  66. if (j == 8/(t/8)) \
  67. *p++ = ' '; \
  68. if (allow_reg_read(i, j, t)) \
  69. p += sprintf(p, format, reg[j]); \
  70. else \
  71. p += sprintf(p, "%s", xp); \
  72. } \
  73. dev_dbg(dev, "%s 0x%02X %s\n", prefix[i], i << 4, msg); \
  74. } \
  75. }
  76. #define CB710_READ_AND_DUMP_REGS_TEMPLATE(t) \
  77. static void cb710_read_and_dump_regs_##t(struct cb710_chip *chip, \
  78. unsigned select) \
  79. { \
  80. u##t regs[CB710_REG_COUNT/sizeof(u##t)]; \
  81. \
  82. memset(&regs, 0, sizeof(regs)); \
  83. cb710_read_regs_##t(chip->iobase, regs, select); \
  84. cb710_dump_regs_##t(cb710_chip_dev(chip), regs, select); \
  85. }
  86. #define CB710_REG_ACCESS_TEMPLATES(t) \
  87. CB710_READ_REGS_TEMPLATE(t) \
  88. CB710_DUMP_REGS_TEMPLATE(t) \
  89. CB710_READ_AND_DUMP_REGS_TEMPLATE(t)
  90. CB710_REG_ACCESS_TEMPLATES(8)
  91. CB710_REG_ACCESS_TEMPLATES(16)
  92. CB710_REG_ACCESS_TEMPLATES(32)
  93. void cb710_dump_regs(struct cb710_chip *chip, unsigned select)
  94. {
  95. if (!(select & CB710_DUMP_REGS_MASK))
  96. select = CB710_DUMP_REGS_ALL;
  97. if (!(select & CB710_DUMP_ACCESS_MASK))
  98. select |= CB710_DUMP_ACCESS_8;
  99. if (select & CB710_DUMP_ACCESS_32)
  100. cb710_read_and_dump_regs_32(chip, select);
  101. if (select & CB710_DUMP_ACCESS_16)
  102. cb710_read_and_dump_regs_16(chip, select);
  103. if (select & CB710_DUMP_ACCESS_8)
  104. cb710_read_and_dump_regs_8(chip, select);
  105. }
  106. EXPORT_SYMBOL_GPL(cb710_dump_regs);