digi00x-proc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * digi00x-proc.c - a part of driver for Digidesign Digi 002/003 family
  3. *
  4. * Copyright (c) 2014-2015 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #include "digi00x.h"
  9. static int get_optical_iface_mode(struct snd_dg00x *dg00x,
  10. enum snd_dg00x_optical_mode *mode)
  11. {
  12. __be32 data;
  13. int err;
  14. err = snd_fw_transaction(dg00x->unit, TCODE_READ_QUADLET_REQUEST,
  15. DG00X_ADDR_BASE + DG00X_OFFSET_OPT_IFACE_MODE,
  16. &data, sizeof(data), 0);
  17. if (err >= 0)
  18. *mode = be32_to_cpu(data) & 0x01;
  19. return err;
  20. }
  21. static void proc_read_clock(struct snd_info_entry *entry,
  22. struct snd_info_buffer *buf)
  23. {
  24. static const char *const source_name[] = {
  25. [SND_DG00X_CLOCK_INTERNAL] = "internal",
  26. [SND_DG00X_CLOCK_SPDIF] = "s/pdif",
  27. [SND_DG00X_CLOCK_ADAT] = "adat",
  28. [SND_DG00X_CLOCK_WORD] = "word clock",
  29. };
  30. static const char *const optical_name[] = {
  31. [SND_DG00X_OPT_IFACE_MODE_ADAT] = "adat",
  32. [SND_DG00X_OPT_IFACE_MODE_SPDIF] = "s/pdif",
  33. };
  34. struct snd_dg00x *dg00x = entry->private_data;
  35. enum snd_dg00x_optical_mode mode;
  36. unsigned int rate;
  37. enum snd_dg00x_clock clock;
  38. bool detect;
  39. if (get_optical_iface_mode(dg00x, &mode) < 0)
  40. return;
  41. if (snd_dg00x_stream_get_local_rate(dg00x, &rate) < 0)
  42. return;
  43. if (snd_dg00x_stream_get_clock(dg00x, &clock) < 0)
  44. return;
  45. snd_iprintf(buf, "Optical mode: %s\n", optical_name[mode]);
  46. snd_iprintf(buf, "Sampling Rate: %d\n", rate);
  47. snd_iprintf(buf, "Clock Source: %s\n", source_name[clock]);
  48. if (clock == SND_DG00X_CLOCK_INTERNAL)
  49. return;
  50. if (snd_dg00x_stream_check_external_clock(dg00x, &detect) < 0)
  51. return;
  52. snd_iprintf(buf, "External source: %s\n", detect ? "detected" : "not");
  53. if (!detect)
  54. return;
  55. if (snd_dg00x_stream_get_external_rate(dg00x, &rate) >= 0)
  56. snd_iprintf(buf, "External sampling rate: %d\n", rate);
  57. }
  58. void snd_dg00x_proc_init(struct snd_dg00x *dg00x)
  59. {
  60. struct snd_info_entry *root, *entry;
  61. /*
  62. * All nodes are automatically removed at snd_card_disconnect(),
  63. * by following to link list.
  64. */
  65. root = snd_info_create_card_entry(dg00x->card, "firewire",
  66. dg00x->card->proc_root);
  67. if (root == NULL)
  68. return;
  69. root->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  70. if (snd_info_register(root) < 0) {
  71. snd_info_free_entry(root);
  72. return;
  73. }
  74. entry = snd_info_create_card_entry(dg00x->card, "clock", root);
  75. if (entry == NULL) {
  76. snd_info_free_entry(root);
  77. return;
  78. }
  79. snd_info_set_text_ops(entry, dg00x, proc_read_clock);
  80. if (snd_info_register(entry) < 0) {
  81. snd_info_free_entry(entry);
  82. snd_info_free_entry(root);
  83. }
  84. }