mia_dsp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. static int set_input_clock(struct echoaudio *chip, u16 clock);
  23. static int set_professional_spdif(struct echoaudio *chip, char prof);
  24. static int update_flags(struct echoaudio *chip);
  25. static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
  26. int gain);
  27. static int update_vmixer_level(struct echoaudio *chip);
  28. static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
  29. {
  30. int err;
  31. if (snd_BUG_ON((subdevice_id & 0xfff0) != MIA))
  32. return -ENODEV;
  33. if ((err = init_dsp_comm_page(chip))) {
  34. dev_err(chip->card->dev,
  35. "init_hw - could not initialize DSP comm page\n");
  36. return err;
  37. }
  38. chip->device_id = device_id;
  39. chip->subdevice_id = subdevice_id;
  40. chip->bad_board = true;
  41. chip->dsp_code_to_load = FW_MIA_DSP;
  42. /* Since this card has no ASIC, mark it as loaded so everything
  43. works OK */
  44. chip->asic_loaded = true;
  45. if ((subdevice_id & 0x0000f) == MIA_MIDI_REV)
  46. chip->has_midi = true;
  47. chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL |
  48. ECHO_CLOCK_BIT_SPDIF;
  49. if ((err = load_firmware(chip)) < 0)
  50. return err;
  51. chip->bad_board = false;
  52. return err;
  53. }
  54. static int set_mixer_defaults(struct echoaudio *chip)
  55. {
  56. return init_line_levels(chip);
  57. }
  58. static u32 detect_input_clocks(const struct echoaudio *chip)
  59. {
  60. u32 clocks_from_dsp, clock_bits;
  61. /* Map the DSP clock detect bits to the generic driver clock
  62. detect bits */
  63. clocks_from_dsp = le32_to_cpu(chip->comm_page->status_clocks);
  64. clock_bits = ECHO_CLOCK_BIT_INTERNAL;
  65. if (clocks_from_dsp & GLDM_CLOCK_DETECT_BIT_SPDIF)
  66. clock_bits |= ECHO_CLOCK_BIT_SPDIF;
  67. return clock_bits;
  68. }
  69. /* The Mia has no ASIC. Just do nothing */
  70. static int load_asic(struct echoaudio *chip)
  71. {
  72. return 0;
  73. }
  74. static int set_sample_rate(struct echoaudio *chip, u32 rate)
  75. {
  76. u32 control_reg;
  77. switch (rate) {
  78. case 96000:
  79. control_reg = MIA_96000;
  80. break;
  81. case 88200:
  82. control_reg = MIA_88200;
  83. break;
  84. case 48000:
  85. control_reg = MIA_48000;
  86. break;
  87. case 44100:
  88. control_reg = MIA_44100;
  89. break;
  90. case 32000:
  91. control_reg = MIA_32000;
  92. break;
  93. default:
  94. dev_err(chip->card->dev,
  95. "set_sample_rate: %d invalid!\n", rate);
  96. return -EINVAL;
  97. }
  98. /* Override the clock setting if this Mia is set to S/PDIF clock */
  99. if (chip->input_clock == ECHO_CLOCK_SPDIF)
  100. control_reg |= MIA_SPDIF;
  101. /* Set the control register if it has changed */
  102. if (control_reg != le32_to_cpu(chip->comm_page->control_register)) {
  103. if (wait_handshake(chip))
  104. return -EIO;
  105. chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */
  106. chip->comm_page->control_register = cpu_to_le32(control_reg);
  107. chip->sample_rate = rate;
  108. clear_handshake(chip);
  109. return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
  110. }
  111. return 0;
  112. }
  113. static int set_input_clock(struct echoaudio *chip, u16 clock)
  114. {
  115. dev_dbg(chip->card->dev, "set_input_clock(%d)\n", clock);
  116. if (snd_BUG_ON(clock != ECHO_CLOCK_INTERNAL &&
  117. clock != ECHO_CLOCK_SPDIF))
  118. return -EINVAL;
  119. chip->input_clock = clock;
  120. return set_sample_rate(chip, chip->sample_rate);
  121. }
  122. /* This function routes the sound from a virtual channel to a real output */
  123. static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
  124. int gain)
  125. {
  126. int index;
  127. if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
  128. output >= num_busses_out(chip)))
  129. return -EINVAL;
  130. if (wait_handshake(chip))
  131. return -EIO;
  132. chip->vmixer_gain[output][pipe] = gain;
  133. index = output * num_pipes_out(chip) + pipe;
  134. chip->comm_page->vmixer[index] = gain;
  135. dev_dbg(chip->card->dev,
  136. "set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
  137. return 0;
  138. }
  139. /* Tell the DSP to read and update virtual mixer levels in comm page. */
  140. static int update_vmixer_level(struct echoaudio *chip)
  141. {
  142. if (wait_handshake(chip))
  143. return -EIO;
  144. clear_handshake(chip);
  145. return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
  146. }
  147. /* Tell the DSP to reread the flags from the comm page */
  148. static int update_flags(struct echoaudio *chip)
  149. {
  150. if (wait_handshake(chip))
  151. return -EIO;
  152. clear_handshake(chip);
  153. return send_vector(chip, DSP_VC_UPDATE_FLAGS);
  154. }
  155. static int set_professional_spdif(struct echoaudio *chip, char prof)
  156. {
  157. dev_dbg(chip->card->dev, "set_professional_spdif %d\n", prof);
  158. if (prof)
  159. chip->comm_page->flags |=
  160. cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
  161. else
  162. chip->comm_page->flags &=
  163. ~cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
  164. chip->professional_spdif = prof;
  165. return update_flags(chip);
  166. }