echoaudio_gml.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /****************************************************************************
  2. Copyright Echo Digital Audio Corporation (c) 1998 - 2004
  3. All rights reserved
  4. www.echoaudio.com
  5. This file is part of Echo Digital Audio's generic driver library.
  6. Echo Digital Audio's generic driver library is free software;
  7. you can redistribute it and/or modify it under the terms of
  8. the GNU General Public License as published by the Free Software
  9. Foundation.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. MA 02111-1307, USA.
  18. *************************************************************************
  19. Translation from C++ and adaptation for use in ALSA-Driver
  20. were made by Giuliano Pochini <pochini@shiny.it>
  21. ****************************************************************************/
  22. /* These functions are common for Gina24, Layla24 and Mona cards */
  23. /* ASIC status check - some cards have one or two ASICs that need to be
  24. loaded. Once that load is complete, this function is called to see if
  25. the load was successful.
  26. If this load fails, it does not necessarily mean that the hardware is
  27. defective - the external box may be disconnected or turned off. */
  28. static int check_asic_status(struct echoaudio *chip)
  29. {
  30. u32 asic_status;
  31. send_vector(chip, DSP_VC_TEST_ASIC);
  32. /* The DSP will return a value to indicate whether or not the
  33. ASIC is currently loaded */
  34. if (read_dsp(chip, &asic_status) < 0) {
  35. DE_INIT(("check_asic_status: failed on read_dsp\n"));
  36. chip->asic_loaded = FALSE;
  37. return -EIO;
  38. }
  39. chip->asic_loaded = (asic_status == ASIC_ALREADY_LOADED);
  40. return chip->asic_loaded ? 0 : -EIO;
  41. }
  42. /* Most configuration of Gina24, Layla24, or Mona is accomplished by writing
  43. the control register. write_control_reg sends the new control register
  44. value to the DSP. */
  45. static int write_control_reg(struct echoaudio *chip, u32 value, char force)
  46. {
  47. /* Handle the digital input auto-mute */
  48. if (chip->digital_in_automute)
  49. value |= GML_DIGITAL_IN_AUTO_MUTE;
  50. else
  51. value &= ~GML_DIGITAL_IN_AUTO_MUTE;
  52. DE_ACT(("write_control_reg: 0x%x\n", value));
  53. /* Write the control register */
  54. value = cpu_to_le32(value);
  55. if (value != chip->comm_page->control_register || force) {
  56. if (wait_handshake(chip))
  57. return -EIO;
  58. chip->comm_page->control_register = value;
  59. clear_handshake(chip);
  60. return send_vector(chip, DSP_VC_WRITE_CONTROL_REG);
  61. }
  62. return 0;
  63. }
  64. /* Gina24, Layla24, and Mona support digital input auto-mute. If the digital
  65. input auto-mute is enabled, the DSP will only enable the digital inputs if
  66. the card is syncing to a valid clock on the ADAT or S/PDIF inputs.
  67. If the auto-mute is disabled, the digital inputs are enabled regardless of
  68. what the input clock is set or what is connected. */
  69. static int set_input_auto_mute(struct echoaudio *chip, int automute)
  70. {
  71. DE_ACT(("set_input_auto_mute %d\n", automute));
  72. chip->digital_in_automute = automute;
  73. /* Re-set the input clock to the current value - indirectly causes
  74. the auto-mute flag to be sent to the DSP */
  75. return set_input_clock(chip, chip->input_clock);
  76. }
  77. /* S/PDIF coax / S/PDIF optical / ADAT - switch */
  78. static int set_digital_mode(struct echoaudio *chip, u8 mode)
  79. {
  80. u8 previous_mode;
  81. int err, i, o;
  82. if (chip->bad_board)
  83. return -EIO;
  84. /* All audio channels must be closed before changing the digital mode */
  85. snd_assert(!chip->pipe_alloc_mask, return -EAGAIN);
  86. snd_assert(chip->digital_modes & (1 << mode), return -EINVAL);
  87. previous_mode = chip->digital_mode;
  88. err = dsp_set_digital_mode(chip, mode);
  89. /* If we successfully changed the digital mode from or to ADAT,
  90. then make sure all output, input and monitor levels are
  91. updated by the DSP comm object. */
  92. if (err >= 0 && previous_mode != mode &&
  93. (previous_mode == DIGITAL_MODE_ADAT || mode == DIGITAL_MODE_ADAT)) {
  94. spin_lock_irq(&chip->lock);
  95. for (o = 0; o < num_busses_out(chip); o++)
  96. for (i = 0; i < num_busses_in(chip); i++)
  97. set_monitor_gain(chip, o, i,
  98. chip->monitor_gain[o][i]);
  99. #ifdef ECHOCARD_HAS_INPUT_GAIN
  100. for (i = 0; i < num_busses_in(chip); i++)
  101. set_input_gain(chip, i, chip->input_gain[i]);
  102. update_input_line_level(chip);
  103. #endif
  104. for (o = 0; o < num_busses_out(chip); o++)
  105. set_output_gain(chip, o, chip->output_gain[o]);
  106. update_output_line_level(chip);
  107. spin_unlock_irq(&chip->lock);
  108. }
  109. return err;
  110. }
  111. /* Set the S/PDIF output format */
  112. static int set_professional_spdif(struct echoaudio *chip, char prof)
  113. {
  114. u32 control_reg;
  115. int err;
  116. /* Clear the current S/PDIF flags */
  117. control_reg = le32_to_cpu(chip->comm_page->control_register);
  118. control_reg &= GML_SPDIF_FORMAT_CLEAR_MASK;
  119. /* Set the new S/PDIF flags depending on the mode */
  120. control_reg |= GML_SPDIF_TWO_CHANNEL | GML_SPDIF_24_BIT |
  121. GML_SPDIF_COPY_PERMIT;
  122. if (prof) {
  123. /* Professional mode */
  124. control_reg |= GML_SPDIF_PRO_MODE;
  125. switch (chip->sample_rate) {
  126. case 32000:
  127. control_reg |= GML_SPDIF_SAMPLE_RATE0 |
  128. GML_SPDIF_SAMPLE_RATE1;
  129. break;
  130. case 44100:
  131. control_reg |= GML_SPDIF_SAMPLE_RATE0;
  132. break;
  133. case 48000:
  134. control_reg |= GML_SPDIF_SAMPLE_RATE1;
  135. break;
  136. }
  137. } else {
  138. /* Consumer mode */
  139. switch (chip->sample_rate) {
  140. case 32000:
  141. control_reg |= GML_SPDIF_SAMPLE_RATE0 |
  142. GML_SPDIF_SAMPLE_RATE1;
  143. break;
  144. case 48000:
  145. control_reg |= GML_SPDIF_SAMPLE_RATE1;
  146. break;
  147. }
  148. }
  149. if ((err = write_control_reg(chip, control_reg, FALSE)))
  150. return err;
  151. chip->professional_spdif = prof;
  152. DE_ACT(("set_professional_spdif to %s\n",
  153. prof ? "Professional" : "Consumer"));
  154. return 0;
  155. }