pvrusb2-audio.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. *
  3. * $Id$
  4. *
  5. * Copyright (C) 2005 Mike Isely <isely@pobox.com>
  6. * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
  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
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include "pvrusb2-audio.h"
  23. #include "pvrusb2-hdw-internal.h"
  24. #include "pvrusb2-debug.h"
  25. #include <linux/videodev2.h>
  26. #include <media/msp3400.h>
  27. #include <media/v4l2-common.h>
  28. struct pvr2_msp3400_handler {
  29. struct pvr2_hdw *hdw;
  30. struct pvr2_i2c_client *client;
  31. struct pvr2_i2c_handler i2c_handler;
  32. unsigned long stale_mask;
  33. };
  34. /* This function selects the correct audio input source */
  35. static void set_stereo(struct pvr2_msp3400_handler *ctxt)
  36. {
  37. struct pvr2_hdw *hdw = ctxt->hdw;
  38. struct v4l2_routing route;
  39. pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
  40. if (hdw->input_val == PVR2_CVAL_INPUT_TV) {
  41. struct v4l2_tuner vt;
  42. memset(&vt,0,sizeof(vt));
  43. vt.audmode = hdw->audiomode_val;
  44. pvr2_i2c_client_cmd(ctxt->client,VIDIOC_S_TUNER,&vt);
  45. }
  46. route.input = MSP_INPUT_DEFAULT;
  47. route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
  48. switch (hdw->input_val) {
  49. case PVR2_CVAL_INPUT_TV:
  50. break;
  51. case PVR2_CVAL_INPUT_RADIO:
  52. /* Assume that msp34xx also handle FM decoding, in which case
  53. we're still using the tuner. */
  54. /* HV: actually it is more likely to be the SCART2 input if
  55. the ivtv experience is any indication. */
  56. route.input = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1,
  57. MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
  58. break;
  59. case PVR2_CVAL_INPUT_SVIDEO:
  60. case PVR2_CVAL_INPUT_COMPOSITE:
  61. /* SCART 1 input */
  62. route.input = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
  63. MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
  64. break;
  65. }
  66. pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
  67. }
  68. static int check_stereo(struct pvr2_msp3400_handler *ctxt)
  69. {
  70. struct pvr2_hdw *hdw = ctxt->hdw;
  71. return (hdw->input_dirty ||
  72. hdw->audiomode_dirty);
  73. }
  74. struct pvr2_msp3400_ops {
  75. void (*update)(struct pvr2_msp3400_handler *);
  76. int (*check)(struct pvr2_msp3400_handler *);
  77. };
  78. static const struct pvr2_msp3400_ops msp3400_ops[] = {
  79. { .update = set_stereo, .check = check_stereo},
  80. };
  81. static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
  82. {
  83. unsigned long msk;
  84. unsigned int idx;
  85. for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]);
  86. idx++) {
  87. msk = 1 << idx;
  88. if (ctxt->stale_mask & msk) continue;
  89. if (msp3400_ops[idx].check(ctxt)) {
  90. ctxt->stale_mask |= msk;
  91. }
  92. }
  93. return ctxt->stale_mask != 0;
  94. }
  95. static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
  96. {
  97. unsigned long msk;
  98. unsigned int idx;
  99. for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]);
  100. idx++) {
  101. msk = 1 << idx;
  102. if (!(ctxt->stale_mask & msk)) continue;
  103. ctxt->stale_mask &= ~msk;
  104. msp3400_ops[idx].update(ctxt);
  105. }
  106. }
  107. static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt)
  108. {
  109. ctxt->client->handler = NULL;
  110. kfree(ctxt);
  111. }
  112. static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt,
  113. char *buf,unsigned int cnt)
  114. {
  115. return scnprintf(buf,cnt,"handler: pvrusb2-audio v4l2");
  116. }
  117. static const struct pvr2_i2c_handler_functions msp3400_funcs = {
  118. .detach = (void (*)(void *))pvr2_msp3400_detach,
  119. .check = (int (*)(void *))msp3400_check,
  120. .update = (void (*)(void *))msp3400_update,
  121. .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_msp3400_describe,
  122. };
  123. int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
  124. {
  125. struct pvr2_msp3400_handler *ctxt;
  126. if (cp->handler) return 0;
  127. ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL);
  128. if (!ctxt) return 0;
  129. memset(ctxt,0,sizeof(*ctxt));
  130. ctxt->i2c_handler.func_data = ctxt;
  131. ctxt->i2c_handler.func_table = &msp3400_funcs;
  132. ctxt->client = cp;
  133. ctxt->hdw = hdw;
  134. ctxt->stale_mask = (1 << (sizeof(msp3400_ops)/
  135. sizeof(msp3400_ops[0]))) - 1;
  136. cp->handler = &ctxt->i2c_handler;
  137. pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
  138. cp->client->addr);
  139. return !0;
  140. }
  141. /*
  142. Stuff for Emacs to see, in order to encourage consistent editing style:
  143. *** Local Variables: ***
  144. *** mode: c ***
  145. *** fill-column: 70 ***
  146. *** tab-width: 8 ***
  147. *** c-basic-offset: 8 ***
  148. *** End: ***
  149. */