cx18-audio.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "cx18-driver.h"
  19. #include "cx18-io.h"
  20. #include "cx18-cards.h"
  21. #include "cx18-audio.h"
  22. #define CX18_AUDIO_ENABLE 0xc72014
  23. #define CX18_AI1_MUX_MASK 0x30
  24. #define CX18_AI1_MUX_I2S1 0x00
  25. #define CX18_AI1_MUX_I2S2 0x10
  26. #define CX18_AI1_MUX_843_I2S 0x20
  27. /* Selects the audio input and output according to the current
  28. settings. */
  29. int cx18_audio_set_io(struct cx18 *cx)
  30. {
  31. const struct cx18_card_audio_input *in;
  32. u32 u, v;
  33. int err;
  34. /* Determine which input to use */
  35. if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags))
  36. in = &cx->card->radio_input;
  37. else
  38. in = &cx->card->audio_inputs[cx->audio_input];
  39. /* handle muxer chips */
  40. v4l2_subdev_call(cx->sd_extmux, audio, s_routing,
  41. (u32) in->muxer_input, 0, 0);
  42. err = cx18_call_hw_err(cx, cx->card->hw_audio_ctrl,
  43. audio, s_routing, in->audio_input, 0, 0);
  44. if (err)
  45. return err;
  46. /* FIXME - this internal mux should be abstracted to a subdev */
  47. u = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
  48. v = u & ~CX18_AI1_MUX_MASK;
  49. switch (in->audio_input) {
  50. case CX18_AV_AUDIO_SERIAL1:
  51. v |= CX18_AI1_MUX_I2S1;
  52. break;
  53. case CX18_AV_AUDIO_SERIAL2:
  54. v |= CX18_AI1_MUX_I2S2;
  55. break;
  56. default:
  57. v |= CX18_AI1_MUX_843_I2S;
  58. break;
  59. }
  60. if (v == u) {
  61. /* force a toggle of some AI1 MUX control bits */
  62. u &= ~CX18_AI1_MUX_MASK;
  63. switch (in->audio_input) {
  64. case CX18_AV_AUDIO_SERIAL1:
  65. u |= CX18_AI1_MUX_843_I2S;
  66. break;
  67. case CX18_AV_AUDIO_SERIAL2:
  68. u |= CX18_AI1_MUX_843_I2S;
  69. break;
  70. default:
  71. u |= CX18_AI1_MUX_I2S1;
  72. break;
  73. }
  74. cx18_write_reg_expect(cx, u | 0xb00, CX18_AUDIO_ENABLE,
  75. u, CX18_AI1_MUX_MASK);
  76. }
  77. cx18_write_reg_expect(cx, v | 0xb00, CX18_AUDIO_ENABLE,
  78. v, CX18_AI1_MUX_MASK);
  79. return 0;
  80. }