dice-proc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * dice_proc.c - a part of driver for Dice based devices
  3. *
  4. * Copyright (c) Clemens Ladisch
  5. * Copyright (c) 2014 Takashi Sakamoto
  6. *
  7. * Licensed under the terms of the GNU General Public License, version 2.
  8. */
  9. #include "dice.h"
  10. static int dice_proc_read_mem(struct snd_dice *dice, void *buffer,
  11. unsigned int offset_q, unsigned int quadlets)
  12. {
  13. unsigned int i;
  14. int err;
  15. err = snd_fw_transaction(dice->unit, TCODE_READ_BLOCK_REQUEST,
  16. DICE_PRIVATE_SPACE + 4 * offset_q,
  17. buffer, 4 * quadlets, 0);
  18. if (err < 0)
  19. return err;
  20. for (i = 0; i < quadlets; ++i)
  21. be32_to_cpus(&((u32 *)buffer)[i]);
  22. return 0;
  23. }
  24. static const char *str_from_array(const char *const strs[], unsigned int count,
  25. unsigned int i)
  26. {
  27. if (i < count)
  28. return strs[i];
  29. return "(unknown)";
  30. }
  31. static void dice_proc_fixup_string(char *s, unsigned int size)
  32. {
  33. unsigned int i;
  34. for (i = 0; i < size; i += 4)
  35. cpu_to_le32s((u32 *)(s + i));
  36. for (i = 0; i < size - 2; ++i) {
  37. if (s[i] == '\0')
  38. return;
  39. if (s[i] == '\\' && s[i + 1] == '\\') {
  40. s[i + 2] = '\0';
  41. return;
  42. }
  43. }
  44. s[size - 1] = '\0';
  45. }
  46. static void dice_proc_read(struct snd_info_entry *entry,
  47. struct snd_info_buffer *buffer)
  48. {
  49. static const char *const section_names[5] = {
  50. "global", "tx", "rx", "ext_sync", "unused2"
  51. };
  52. static const char *const clock_sources[] = {
  53. "aes1", "aes2", "aes3", "aes4", "aes", "adat", "tdif",
  54. "wc", "arx1", "arx2", "arx3", "arx4", "internal"
  55. };
  56. static const char *const rates[] = {
  57. "32000", "44100", "48000", "88200", "96000", "176400", "192000",
  58. "any low", "any mid", "any high", "none"
  59. };
  60. struct snd_dice *dice = entry->private_data;
  61. u32 sections[ARRAY_SIZE(section_names) * 2];
  62. struct {
  63. u32 number;
  64. u32 size;
  65. } tx_rx_header;
  66. union {
  67. struct {
  68. u32 owner_hi, owner_lo;
  69. u32 notification;
  70. char nick_name[NICK_NAME_SIZE];
  71. u32 clock_select;
  72. u32 enable;
  73. u32 status;
  74. u32 extended_status;
  75. u32 sample_rate;
  76. u32 version;
  77. u32 clock_caps;
  78. char clock_source_names[CLOCK_SOURCE_NAMES_SIZE];
  79. } global;
  80. struct {
  81. u32 iso;
  82. u32 number_audio;
  83. u32 number_midi;
  84. u32 speed;
  85. char names[TX_NAMES_SIZE];
  86. u32 ac3_caps;
  87. u32 ac3_enable;
  88. } tx;
  89. struct {
  90. u32 iso;
  91. u32 seq_start;
  92. u32 number_audio;
  93. u32 number_midi;
  94. char names[RX_NAMES_SIZE];
  95. u32 ac3_caps;
  96. u32 ac3_enable;
  97. } rx;
  98. struct {
  99. u32 clock_source;
  100. u32 locked;
  101. u32 rate;
  102. u32 adat_user_data;
  103. } ext_sync;
  104. } buf;
  105. unsigned int quadlets, stream, i;
  106. if (dice_proc_read_mem(dice, sections, 0, ARRAY_SIZE(sections)) < 0)
  107. return;
  108. snd_iprintf(buffer, "sections:\n");
  109. for (i = 0; i < ARRAY_SIZE(section_names); ++i)
  110. snd_iprintf(buffer, " %s: offset %u, size %u\n",
  111. section_names[i],
  112. sections[i * 2], sections[i * 2 + 1]);
  113. quadlets = min_t(u32, sections[1], sizeof(buf.global) / 4);
  114. if (dice_proc_read_mem(dice, &buf.global, sections[0], quadlets) < 0)
  115. return;
  116. snd_iprintf(buffer, "global:\n");
  117. snd_iprintf(buffer, " owner: %04x:%04x%08x\n",
  118. buf.global.owner_hi >> 16,
  119. buf.global.owner_hi & 0xffff, buf.global.owner_lo);
  120. snd_iprintf(buffer, " notification: %08x\n", buf.global.notification);
  121. dice_proc_fixup_string(buf.global.nick_name, NICK_NAME_SIZE);
  122. snd_iprintf(buffer, " nick name: %s\n", buf.global.nick_name);
  123. snd_iprintf(buffer, " clock select: %s %s\n",
  124. str_from_array(clock_sources, ARRAY_SIZE(clock_sources),
  125. buf.global.clock_select & CLOCK_SOURCE_MASK),
  126. str_from_array(rates, ARRAY_SIZE(rates),
  127. (buf.global.clock_select & CLOCK_RATE_MASK)
  128. >> CLOCK_RATE_SHIFT));
  129. snd_iprintf(buffer, " enable: %u\n", buf.global.enable);
  130. snd_iprintf(buffer, " status: %slocked %s\n",
  131. buf.global.status & STATUS_SOURCE_LOCKED ? "" : "un",
  132. str_from_array(rates, ARRAY_SIZE(rates),
  133. (buf.global.status &
  134. STATUS_NOMINAL_RATE_MASK)
  135. >> CLOCK_RATE_SHIFT));
  136. snd_iprintf(buffer, " ext status: %08x\n", buf.global.extended_status);
  137. snd_iprintf(buffer, " sample rate: %u\n", buf.global.sample_rate);
  138. snd_iprintf(buffer, " version: %u.%u.%u.%u\n",
  139. (buf.global.version >> 24) & 0xff,
  140. (buf.global.version >> 16) & 0xff,
  141. (buf.global.version >> 8) & 0xff,
  142. (buf.global.version >> 0) & 0xff);
  143. if (quadlets >= 90) {
  144. snd_iprintf(buffer, " clock caps:");
  145. for (i = 0; i <= 6; ++i)
  146. if (buf.global.clock_caps & (1 << i))
  147. snd_iprintf(buffer, " %s", rates[i]);
  148. for (i = 0; i <= 12; ++i)
  149. if (buf.global.clock_caps & (1 << (16 + i)))
  150. snd_iprintf(buffer, " %s", clock_sources[i]);
  151. snd_iprintf(buffer, "\n");
  152. dice_proc_fixup_string(buf.global.clock_source_names,
  153. CLOCK_SOURCE_NAMES_SIZE);
  154. snd_iprintf(buffer, " clock source names: %s\n",
  155. buf.global.clock_source_names);
  156. }
  157. if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
  158. return;
  159. quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);
  160. for (stream = 0; stream < tx_rx_header.number; ++stream) {
  161. if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
  162. stream * tx_rx_header.size,
  163. quadlets) < 0)
  164. break;
  165. snd_iprintf(buffer, "tx %u:\n", stream);
  166. snd_iprintf(buffer, " iso channel: %d\n", (int)buf.tx.iso);
  167. snd_iprintf(buffer, " audio channels: %u\n",
  168. buf.tx.number_audio);
  169. snd_iprintf(buffer, " midi ports: %u\n", buf.tx.number_midi);
  170. snd_iprintf(buffer, " speed: S%u\n", 100u << buf.tx.speed);
  171. if (quadlets >= 68) {
  172. dice_proc_fixup_string(buf.tx.names, TX_NAMES_SIZE);
  173. snd_iprintf(buffer, " names: %s\n", buf.tx.names);
  174. }
  175. if (quadlets >= 70) {
  176. snd_iprintf(buffer, " ac3 caps: %08x\n",
  177. buf.tx.ac3_caps);
  178. snd_iprintf(buffer, " ac3 enable: %08x\n",
  179. buf.tx.ac3_enable);
  180. }
  181. }
  182. if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
  183. return;
  184. quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
  185. for (stream = 0; stream < tx_rx_header.number; ++stream) {
  186. if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
  187. stream * tx_rx_header.size,
  188. quadlets) < 0)
  189. break;
  190. snd_iprintf(buffer, "rx %u:\n", stream);
  191. snd_iprintf(buffer, " iso channel: %d\n", (int)buf.rx.iso);
  192. snd_iprintf(buffer, " sequence start: %u\n", buf.rx.seq_start);
  193. snd_iprintf(buffer, " audio channels: %u\n",
  194. buf.rx.number_audio);
  195. snd_iprintf(buffer, " midi ports: %u\n", buf.rx.number_midi);
  196. if (quadlets >= 68) {
  197. dice_proc_fixup_string(buf.rx.names, RX_NAMES_SIZE);
  198. snd_iprintf(buffer, " names: %s\n", buf.rx.names);
  199. }
  200. if (quadlets >= 70) {
  201. snd_iprintf(buffer, " ac3 caps: %08x\n",
  202. buf.rx.ac3_caps);
  203. snd_iprintf(buffer, " ac3 enable: %08x\n",
  204. buf.rx.ac3_enable);
  205. }
  206. }
  207. quadlets = min_t(u32, sections[7], sizeof(buf.ext_sync) / 4);
  208. if (quadlets >= 4) {
  209. if (dice_proc_read_mem(dice, &buf.ext_sync,
  210. sections[6], 4) < 0)
  211. return;
  212. snd_iprintf(buffer, "ext status:\n");
  213. snd_iprintf(buffer, " clock source: %s\n",
  214. str_from_array(clock_sources,
  215. ARRAY_SIZE(clock_sources),
  216. buf.ext_sync.clock_source));
  217. snd_iprintf(buffer, " locked: %u\n", buf.ext_sync.locked);
  218. snd_iprintf(buffer, " rate: %s\n",
  219. str_from_array(rates, ARRAY_SIZE(rates),
  220. buf.ext_sync.rate));
  221. snd_iprintf(buffer, " adat user data: ");
  222. if (buf.ext_sync.adat_user_data & ADAT_USER_DATA_NO_DATA)
  223. snd_iprintf(buffer, "-\n");
  224. else
  225. snd_iprintf(buffer, "%x\n",
  226. buf.ext_sync.adat_user_data);
  227. }
  228. }
  229. void snd_dice_create_proc(struct snd_dice *dice)
  230. {
  231. struct snd_info_entry *entry;
  232. if (!snd_card_proc_new(dice->card, "dice", &entry))
  233. snd_info_set_text_ops(entry, dice, dice_proc_read);
  234. }