pvrusb2-cx2584x-v4l.c 4.0 KB

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