digi00x-proc.c 2.3 KB

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