pvrusb2-cx2584x-v4l.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. struct routing_scheme_item {
  34. int vid;
  35. int aud;
  36. };
  37. struct routing_scheme {
  38. const struct routing_scheme_item *def;
  39. unsigned int cnt;
  40. };
  41. static const struct routing_scheme_item routing_scheme0[] = {
  42. [PVR2_CVAL_INPUT_TV] = {
  43. .vid = CX25840_COMPOSITE7,
  44. .aud = CX25840_AUDIO8,
  45. },
  46. [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
  47. .vid = CX25840_COMPOSITE3,
  48. .aud = CX25840_AUDIO_SERIAL,
  49. },
  50. [PVR2_CVAL_INPUT_COMPOSITE] = {
  51. .vid = CX25840_COMPOSITE3,
  52. .aud = CX25840_AUDIO_SERIAL,
  53. },
  54. [PVR2_CVAL_INPUT_SVIDEO] = {
  55. .vid = CX25840_SVIDEO1,
  56. .aud = CX25840_AUDIO_SERIAL,
  57. },
  58. };
  59. static const struct routing_scheme routing_def0 = {
  60. .def = routing_scheme0,
  61. .cnt = ARRAY_SIZE(routing_scheme0),
  62. };
  63. /* Specific to gotview device */
  64. static const struct routing_scheme_item routing_schemegv[] = {
  65. [PVR2_CVAL_INPUT_TV] = {
  66. .vid = CX25840_COMPOSITE2,
  67. .aud = CX25840_AUDIO5,
  68. },
  69. [PVR2_CVAL_INPUT_RADIO] = {
  70. /* line-in is used for radio and composite. A GPIO is
  71. used to switch between the two choices. */
  72. .vid = CX25840_COMPOSITE1,
  73. .aud = CX25840_AUDIO_SERIAL,
  74. },
  75. [PVR2_CVAL_INPUT_COMPOSITE] = {
  76. .vid = CX25840_COMPOSITE1,
  77. .aud = CX25840_AUDIO_SERIAL,
  78. },
  79. [PVR2_CVAL_INPUT_SVIDEO] = {
  80. .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
  81. .aud = CX25840_AUDIO_SERIAL,
  82. },
  83. };
  84. static const struct routing_scheme routing_defgv = {
  85. .def = routing_schemegv,
  86. .cnt = ARRAY_SIZE(routing_schemegv),
  87. };
  88. /* Specific to grabster av400 device */
  89. static const struct routing_scheme_item routing_schemeav400[] = {
  90. [PVR2_CVAL_INPUT_COMPOSITE] = {
  91. .vid = CX25840_COMPOSITE1,
  92. .aud = CX25840_AUDIO_SERIAL,
  93. },
  94. [PVR2_CVAL_INPUT_SVIDEO] = {
  95. .vid = (CX25840_SVIDEO_LUMA2|CX25840_SVIDEO_CHROMA4),
  96. .aud = CX25840_AUDIO_SERIAL,
  97. },
  98. };
  99. static const struct routing_scheme routing_defav400 = {
  100. .def = routing_schemeav400,
  101. .cnt = ARRAY_SIZE(routing_schemeav400),
  102. };
  103. static const struct routing_scheme *routing_schemes[] = {
  104. [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
  105. [PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
  106. [PVR2_ROUTING_SCHEME_AV400] = &routing_defav400,
  107. };
  108. void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
  109. {
  110. pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
  111. if (hdw->input_dirty || hdw->force_dirty) {
  112. enum cx25840_video_input vid_input;
  113. enum cx25840_audio_input aud_input;
  114. const struct routing_scheme *sp;
  115. unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
  116. sp = (sid < ARRAY_SIZE(routing_schemes)) ?
  117. routing_schemes[sid] : NULL;
  118. if ((sp == NULL) ||
  119. (hdw->input_val < 0) ||
  120. (hdw->input_val >= sp->cnt)) {
  121. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  122. "*** WARNING *** subdev cx2584x set_input:"
  123. " Invalid routing scheme (%u)"
  124. " and/or input (%d)",
  125. sid, hdw->input_val);
  126. return;
  127. }
  128. vid_input = sp->def[hdw->input_val].vid;
  129. aud_input = sp->def[hdw->input_val].aud;
  130. pvr2_trace(PVR2_TRACE_CHIPS,
  131. "subdev cx2584x set_input vid=0x%x aud=0x%x",
  132. vid_input, aud_input);
  133. sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
  134. sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
  135. }
  136. }