pvrusb2-cx2584x-v4l.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. *
  3. *
  4. * Copyright (C) 2005 Mike Isely <isely@pobox.com>
  5. * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. /*
  22. This source file is specifically designed to interface with the
  23. cx2584x, in kernels 2.6.16 or newer.
  24. */
  25. #include "pvrusb2-cx2584x-v4l.h"
  26. #include "pvrusb2-video-v4l.h"
  27. #include "pvrusb2-hdw-internal.h"
  28. #include "pvrusb2-debug.h"
  29. #include <media/cx25840.h>
  30. #include <linux/videodev2.h>
  31. #include <media/v4l2-common.h>
  32. #include <linux/errno.h>
  33. #include <linux/slab.h>
  34. struct routing_scheme_item {
  35. int vid;
  36. int aud;
  37. };
  38. struct routing_scheme {
  39. const struct routing_scheme_item *def;
  40. unsigned int cnt;
  41. };
  42. static const struct routing_scheme_item routing_scheme0[] = {
  43. [PVR2_CVAL_INPUT_TV] = {
  44. .vid = CX25840_COMPOSITE7,
  45. .aud = CX25840_AUDIO8,
  46. },
  47. [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
  48. .vid = CX25840_COMPOSITE3,
  49. .aud = CX25840_AUDIO_SERIAL,
  50. },
  51. [PVR2_CVAL_INPUT_COMPOSITE] = {
  52. .vid = CX25840_COMPOSITE3,
  53. .aud = CX25840_AUDIO_SERIAL,
  54. },
  55. [PVR2_CVAL_INPUT_SVIDEO] = {
  56. .vid = CX25840_SVIDEO1,
  57. .aud = CX25840_AUDIO_SERIAL,
  58. },
  59. };
  60. static const struct routing_scheme routing_def0 = {
  61. .def = routing_scheme0,
  62. .cnt = ARRAY_SIZE(routing_scheme0),
  63. };
  64. /* Specific to gotview device */
  65. static const struct routing_scheme_item routing_schemegv[] = {
  66. [PVR2_CVAL_INPUT_TV] = {
  67. .vid = CX25840_COMPOSITE2,
  68. .aud = CX25840_AUDIO5,
  69. },
  70. [PVR2_CVAL_INPUT_RADIO] = {
  71. /* line-in is used for radio and composite. A GPIO is
  72. used to switch between the two choices. */
  73. .vid = CX25840_COMPOSITE1,
  74. .aud = CX25840_AUDIO_SERIAL,
  75. },
  76. [PVR2_CVAL_INPUT_COMPOSITE] = {
  77. .vid = CX25840_COMPOSITE1,
  78. .aud = CX25840_AUDIO_SERIAL,
  79. },
  80. [PVR2_CVAL_INPUT_SVIDEO] = {
  81. .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
  82. .aud = CX25840_AUDIO_SERIAL,
  83. },
  84. };
  85. static const struct routing_scheme routing_defgv = {
  86. .def = routing_schemegv,
  87. .cnt = ARRAY_SIZE(routing_schemegv),
  88. };
  89. static const struct routing_scheme *routing_schemes[] = {
  90. [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
  91. [PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
  92. };
  93. void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
  94. {
  95. pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
  96. if (hdw->input_dirty || hdw->force_dirty) {
  97. enum cx25840_video_input vid_input;
  98. enum cx25840_audio_input aud_input;
  99. const struct routing_scheme *sp;
  100. unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
  101. sp = (sid < ARRAY_SIZE(routing_schemes)) ?
  102. routing_schemes[sid] : NULL;
  103. if ((sp == NULL) ||
  104. (hdw->input_val < 0) ||
  105. (hdw->input_val >= sp->cnt)) {
  106. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  107. "*** WARNING *** subdev cx2584x set_input:"
  108. " Invalid routing scheme (%u)"
  109. " and/or input (%d)",
  110. sid, hdw->input_val);
  111. return;
  112. }
  113. vid_input = sp->def[hdw->input_val].vid;
  114. aud_input = sp->def[hdw->input_val].aud;
  115. pvr2_trace(PVR2_TRACE_CHIPS,
  116. "subdev cx2584x set_input vid=0x%x aud=0x%x",
  117. vid_input, aud_input);
  118. sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
  119. sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
  120. }
  121. }
  122. /*
  123. Stuff for Emacs to see, in order to encourage consistent editing style:
  124. *** Local Variables: ***
  125. *** mode: c ***
  126. *** fill-column: 70 ***
  127. *** tab-width: 8 ***
  128. *** c-basic-offset: 8 ***
  129. *** End: ***
  130. */