darla20_dsp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
  23. {
  24. int err;
  25. if (snd_BUG_ON((subdevice_id & 0xfff0) != DARLA20))
  26. return -ENODEV;
  27. if ((err = init_dsp_comm_page(chip))) {
  28. dev_err(chip->card->dev,
  29. "init_hw: could not initialize DSP comm page\n");
  30. return err;
  31. }
  32. chip->device_id = device_id;
  33. chip->subdevice_id = subdevice_id;
  34. chip->bad_board = TRUE;
  35. chip->dsp_code_to_load = FW_DARLA20_DSP;
  36. chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
  37. chip->clock_state = GD_CLOCK_UNDEF;
  38. /* Since this card has no ASIC, mark it as loaded so everything
  39. works OK */
  40. chip->asic_loaded = TRUE;
  41. chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL;
  42. if ((err = load_firmware(chip)) < 0)
  43. return err;
  44. chip->bad_board = FALSE;
  45. return err;
  46. }
  47. static int set_mixer_defaults(struct echoaudio *chip)
  48. {
  49. return init_line_levels(chip);
  50. }
  51. /* The Darla20 has no external clock sources */
  52. static u32 detect_input_clocks(const struct echoaudio *chip)
  53. {
  54. return ECHO_CLOCK_BIT_INTERNAL;
  55. }
  56. /* The Darla20 has no ASIC. Just do nothing */
  57. static int load_asic(struct echoaudio *chip)
  58. {
  59. return 0;
  60. }
  61. static int set_sample_rate(struct echoaudio *chip, u32 rate)
  62. {
  63. u8 clock_state, spdif_status;
  64. if (wait_handshake(chip))
  65. return -EIO;
  66. switch (rate) {
  67. case 44100:
  68. clock_state = GD_CLOCK_44;
  69. spdif_status = GD_SPDIF_STATUS_44;
  70. break;
  71. case 48000:
  72. clock_state = GD_CLOCK_48;
  73. spdif_status = GD_SPDIF_STATUS_48;
  74. break;
  75. default:
  76. clock_state = GD_CLOCK_NOCHANGE;
  77. spdif_status = GD_SPDIF_STATUS_NOCHANGE;
  78. break;
  79. }
  80. if (chip->clock_state == clock_state)
  81. clock_state = GD_CLOCK_NOCHANGE;
  82. if (spdif_status == chip->spdif_status)
  83. spdif_status = GD_SPDIF_STATUS_NOCHANGE;
  84. chip->comm_page->sample_rate = cpu_to_le32(rate);
  85. chip->comm_page->gd_clock_state = clock_state;
  86. chip->comm_page->gd_spdif_status = spdif_status;
  87. chip->comm_page->gd_resampler_state = 3; /* magic number - should always be 3 */
  88. /* Save the new audio state if it changed */
  89. if (clock_state != GD_CLOCK_NOCHANGE)
  90. chip->clock_state = clock_state;
  91. if (spdif_status != GD_SPDIF_STATUS_NOCHANGE)
  92. chip->spdif_status = spdif_status;
  93. chip->sample_rate = rate;
  94. clear_handshake(chip);
  95. return send_vector(chip, DSP_VC_SET_GD_AUDIO_STATE);
  96. }