cx18-audio.c 2.5 KB

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