pvrusb2-video-v4l.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. saa711x support that is available in the v4l available starting
  24. with linux 2.6.15.
  25. */
  26. #include "pvrusb2-video-v4l.h"
  27. #include "pvrusb2-hdw-internal.h"
  28. #include "pvrusb2-debug.h"
  29. #include <linux/videodev2.h>
  30. #include <media/v4l2-common.h>
  31. #include <media/saa7115.h>
  32. #include <linux/errno.h>
  33. struct routing_scheme {
  34. const int *def;
  35. unsigned int cnt;
  36. };
  37. static const int routing_scheme0[] = {
  38. [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
  39. /* In radio mode, we mute the video, but point at one
  40. spot just to stay consistent */
  41. [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
  42. [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE5,
  43. [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2,
  44. };
  45. static const struct routing_scheme routing_def0 = {
  46. .def = routing_scheme0,
  47. .cnt = ARRAY_SIZE(routing_scheme0),
  48. };
  49. static const int routing_scheme1[] = {
  50. [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
  51. [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
  52. [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE3,
  53. [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2, /* or SVIDEO0, it seems */
  54. };
  55. static const struct routing_scheme routing_def1 = {
  56. .def = routing_scheme1,
  57. .cnt = ARRAY_SIZE(routing_scheme1),
  58. };
  59. static const struct routing_scheme *routing_schemes[] = {
  60. [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
  61. [PVR2_ROUTING_SCHEME_ONAIR] = &routing_def1,
  62. };
  63. void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
  64. {
  65. if (hdw->input_dirty || hdw->force_dirty) {
  66. const struct routing_scheme *sp;
  67. unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
  68. u32 input;
  69. pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_input(%d)",
  70. hdw->input_val);
  71. sp = (sid < ARRAY_SIZE(routing_schemes)) ?
  72. routing_schemes[sid] : NULL;
  73. if ((sp == NULL) ||
  74. (hdw->input_val < 0) ||
  75. (hdw->input_val >= sp->cnt)) {
  76. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  77. "*** WARNING *** subdev v4l2 set_input:"
  78. " Invalid routing scheme (%u)"
  79. " and/or input (%d)",
  80. sid, hdw->input_val);
  81. return;
  82. }
  83. input = sp->def[hdw->input_val];
  84. sd->ops->video->s_routing(sd, input, 0, 0);
  85. }
  86. }