indigo_dsp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
  23. int gain);
  24. static int update_vmixer_level(struct echoaudio *chip);
  25. static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
  26. {
  27. int err;
  28. DE_INIT(("init_hw() - Indigo\n"));
  29. if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO))
  30. return -ENODEV;
  31. if ((err = init_dsp_comm_page(chip))) {
  32. DE_INIT(("init_hw - could not initialize DSP comm page\n"));
  33. return err;
  34. }
  35. chip->device_id = device_id;
  36. chip->subdevice_id = subdevice_id;
  37. chip->bad_board = TRUE;
  38. chip->dsp_code_to_load = FW_INDIGO_DSP;
  39. /* Since this card has no ASIC, mark it as loaded so everything
  40. works OK */
  41. chip->asic_loaded = TRUE;
  42. chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL;
  43. if ((err = load_firmware(chip)) < 0)
  44. return err;
  45. chip->bad_board = FALSE;
  46. DE_INIT(("init_hw done\n"));
  47. return err;
  48. }
  49. static int set_mixer_defaults(struct echoaudio *chip)
  50. {
  51. return init_line_levels(chip);
  52. }
  53. static u32 detect_input_clocks(const struct echoaudio *chip)
  54. {
  55. return ECHO_CLOCK_BIT_INTERNAL;
  56. }
  57. /* The Indigo has no ASIC. Just do nothing */
  58. static int load_asic(struct echoaudio *chip)
  59. {
  60. return 0;
  61. }
  62. static int set_sample_rate(struct echoaudio *chip, u32 rate)
  63. {
  64. u32 control_reg;
  65. switch (rate) {
  66. case 96000:
  67. control_reg = MIA_96000;
  68. break;
  69. case 88200:
  70. control_reg = MIA_88200;
  71. break;
  72. case 48000:
  73. control_reg = MIA_48000;
  74. break;
  75. case 44100:
  76. control_reg = MIA_44100;
  77. break;
  78. case 32000:
  79. control_reg = MIA_32000;
  80. break;
  81. default:
  82. DE_ACT(("set_sample_rate: %d invalid!\n", rate));
  83. return -EINVAL;
  84. }
  85. /* Set the control register if it has changed */
  86. if (control_reg != le32_to_cpu(chip->comm_page->control_register)) {
  87. if (wait_handshake(chip))
  88. return -EIO;
  89. chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */
  90. chip->comm_page->control_register = cpu_to_le32(control_reg);
  91. chip->sample_rate = rate;
  92. clear_handshake(chip);
  93. return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
  94. }
  95. return 0;
  96. }
  97. /* This function routes the sound from a virtual channel to a real output */
  98. static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
  99. int gain)
  100. {
  101. int index;
  102. if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
  103. output >= num_busses_out(chip)))
  104. return -EINVAL;
  105. if (wait_handshake(chip))
  106. return -EIO;
  107. chip->vmixer_gain[output][pipe] = gain;
  108. index = output * num_pipes_out(chip) + pipe;
  109. chip->comm_page->vmixer[index] = gain;
  110. DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain));
  111. return 0;
  112. }
  113. /* Tell the DSP to read and update virtual mixer levels in comm page. */
  114. static int update_vmixer_level(struct echoaudio *chip)
  115. {
  116. if (wait_handshake(chip))
  117. return -EIO;
  118. clear_handshake(chip);
  119. return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
  120. }