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