pvrusb2-video-v4l.c 2.7 KB

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