cx18-audio.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * cx18 audio-related functions
  3. *
  4. * Derived from ivtv-audio.c
  5. *
  6. * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. */
  23. #include "cx18-driver.h"
  24. #include "cx18-i2c.h"
  25. #include "cx18-cards.h"
  26. #include "cx18-audio.h"
  27. /* Selects the audio input and output according to the current
  28. settings. */
  29. int cx18_audio_set_io(struct cx18 *cx)
  30. {
  31. struct v4l2_routing route;
  32. u32 audio_input;
  33. int mux_input;
  34. /* Determine which input to use */
  35. if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
  36. audio_input = cx->card->radio_input.audio_input;
  37. mux_input = cx->card->radio_input.muxer_input;
  38. } else {
  39. audio_input =
  40. cx->card->audio_inputs[cx->audio_input].audio_input;
  41. mux_input =
  42. cx->card->audio_inputs[cx->audio_input].muxer_input;
  43. }
  44. /* handle muxer chips */
  45. route.input = mux_input;
  46. route.output = 0;
  47. cx18_i2c_hw(cx, cx->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route);
  48. route.input = audio_input;
  49. return cx18_i2c_hw(cx, cx->card->hw_audio_ctrl,
  50. VIDIOC_INT_S_AUDIO_ROUTING, &route);
  51. }
  52. void cx18_audio_set_route(struct cx18 *cx, struct v4l2_routing *route)
  53. {
  54. cx18_i2c_hw(cx, cx->card->hw_audio_ctrl,
  55. VIDIOC_INT_S_AUDIO_ROUTING, route);
  56. }
  57. void cx18_audio_set_audio_clock_freq(struct cx18 *cx, u8 freq)
  58. {
  59. static u32 freqs[3] = { 44100, 48000, 32000 };
  60. /* The audio clock of the digitizer must match the codec sample
  61. rate otherwise you get some very strange effects. */
  62. if (freq > 2)
  63. return;
  64. cx18_call_i2c_clients(cx, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freqs[freq]);
  65. }