pvrusb2-video-v4l.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Copyright (C) 2005 Mike Isely <[email protected]>
  5. * Copyright (C) 2004 Aurelien Alleaume <[email protected]>
  6. */
  7. /*
  8. This source file is specifically designed to interface with the
  9. saa711x support that is available in the v4l available starting
  10. with linux 2.6.15.
  11. */
  12. #include "pvrusb2-video-v4l.h"
  13. #include "pvrusb2-hdw-internal.h"
  14. #include "pvrusb2-debug.h"
  15. #include <linux/videodev2.h>
  16. #include <media/v4l2-common.h>
  17. #include <media/i2c/saa7115.h>
  18. #include <linux/errno.h>
  19. struct routing_scheme {
  20. const int *def;
  21. unsigned int cnt;
  22. };
  23. static const int routing_scheme0[] = {
  24. [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
  25. /* In radio mode, we mute the video, but point at one
  26. spot just to stay consistent */
  27. [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
  28. [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE5,
  29. [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2,
  30. };
  31. static const struct routing_scheme routing_def0 = {
  32. .def = routing_scheme0,
  33. .cnt = ARRAY_SIZE(routing_scheme0),
  34. };
  35. static const int routing_scheme1[] = {
  36. [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
  37. [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
  38. [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE3,
  39. [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2, /* or SVIDEO0, it seems */
  40. };
  41. static const struct routing_scheme routing_def1 = {
  42. .def = routing_scheme1,
  43. .cnt = ARRAY_SIZE(routing_scheme1),
  44. };
  45. static const struct routing_scheme *routing_schemes[] = {
  46. [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
  47. [PVR2_ROUTING_SCHEME_ONAIR] = &routing_def1,
  48. };
  49. void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
  50. {
  51. if (hdw->input_dirty || hdw->force_dirty) {
  52. const struct routing_scheme *sp;
  53. unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
  54. u32 input;
  55. pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_input(%d)",
  56. hdw->input_val);
  57. sp = (sid < ARRAY_SIZE(routing_schemes)) ?
  58. routing_schemes[sid] : NULL;
  59. if ((sp == NULL) ||
  60. (hdw->input_val < 0) ||
  61. (hdw->input_val >= sp->cnt)) {
  62. pvr2_trace(PVR2_TRACE_ERROR_LEGS,
  63. "*** WARNING *** subdev v4l2 set_input: Invalid routing scheme (%u) and/or input (%d)",
  64. sid, hdw->input_val);
  65. return;
  66. }
  67. input = sp->def[hdw->input_val];
  68. sd->ops->video->s_routing(sd, input, 0, 0);
  69. }
  70. }