hdpvr-control.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Hauppauge HD PVR USB driver - video 4 linux 2 interface
  3. *
  4. * Copyright (C) 2008 Janne Grunau (j@jannau.net)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, version 2.
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/usb.h>
  17. #include <linux/mutex.h>
  18. #include <linux/videodev2.h>
  19. #include <media/v4l2-common.h>
  20. #include "hdpvr.h"
  21. int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf)
  22. {
  23. int ret;
  24. char request_type = 0x38, snd_request = 0x01;
  25. mutex_lock(&dev->usbc_mutex);
  26. dev->usbc_buf[0] = valbuf;
  27. ret = usb_control_msg(dev->udev,
  28. usb_sndctrlpipe(dev->udev, 0),
  29. snd_request, 0x00 | request_type,
  30. value, CTRL_DEFAULT_INDEX,
  31. dev->usbc_buf, 1, 10000);
  32. mutex_unlock(&dev->usbc_mutex);
  33. v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
  34. "config call request for value 0x%x returned %d\n", value,
  35. ret);
  36. return ret < 0 ? ret : 0;
  37. }
  38. int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf)
  39. {
  40. int ret;
  41. vidinf->valid = false;
  42. mutex_lock(&dev->usbc_mutex);
  43. ret = usb_control_msg(dev->udev,
  44. usb_rcvctrlpipe(dev->udev, 0),
  45. 0x81, 0x80 | 0x38,
  46. 0x1400, 0x0003,
  47. dev->usbc_buf, 5,
  48. 1000);
  49. #ifdef HDPVR_DEBUG
  50. if (hdpvr_debug & MSG_INFO)
  51. v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
  52. "get video info returned: %d, %5ph\n", ret,
  53. dev->usbc_buf);
  54. #endif
  55. mutex_unlock(&dev->usbc_mutex);
  56. if (ret < 0)
  57. return ret;
  58. vidinf->width = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
  59. vidinf->height = dev->usbc_buf[3] << 8 | dev->usbc_buf[2];
  60. vidinf->fps = dev->usbc_buf[4];
  61. vidinf->valid = vidinf->width && vidinf->height && vidinf->fps;
  62. return 0;
  63. }
  64. int get_input_lines_info(struct hdpvr_device *dev)
  65. {
  66. int ret, lines;
  67. mutex_lock(&dev->usbc_mutex);
  68. ret = usb_control_msg(dev->udev,
  69. usb_rcvctrlpipe(dev->udev, 0),
  70. 0x81, 0x80 | 0x38,
  71. 0x1800, 0x0003,
  72. dev->usbc_buf, 3,
  73. 1000);
  74. #ifdef HDPVR_DEBUG
  75. if (hdpvr_debug & MSG_INFO)
  76. v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
  77. "get input lines info returned: %d, %3ph\n", ret,
  78. dev->usbc_buf);
  79. #else
  80. (void)ret; /* suppress compiler warning */
  81. #endif
  82. lines = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
  83. mutex_unlock(&dev->usbc_mutex);
  84. return lines;
  85. }
  86. int hdpvr_set_bitrate(struct hdpvr_device *dev)
  87. {
  88. int ret;
  89. mutex_lock(&dev->usbc_mutex);
  90. memset(dev->usbc_buf, 0, 4);
  91. dev->usbc_buf[0] = dev->options.bitrate;
  92. dev->usbc_buf[2] = dev->options.peak_bitrate;
  93. ret = usb_control_msg(dev->udev,
  94. usb_sndctrlpipe(dev->udev, 0),
  95. 0x01, 0x38, CTRL_BITRATE_VALUE,
  96. CTRL_DEFAULT_INDEX, dev->usbc_buf, 4, 1000);
  97. mutex_unlock(&dev->usbc_mutex);
  98. return ret;
  99. }
  100. int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
  101. enum v4l2_mpeg_audio_encoding codec)
  102. {
  103. int ret = 0;
  104. if (dev->flags & HDPVR_FLAG_AC3_CAP) {
  105. mutex_lock(&dev->usbc_mutex);
  106. memset(dev->usbc_buf, 0, 2);
  107. dev->usbc_buf[0] = input;
  108. if (codec == V4L2_MPEG_AUDIO_ENCODING_AAC)
  109. dev->usbc_buf[1] = 0;
  110. else if (codec == V4L2_MPEG_AUDIO_ENCODING_AC3)
  111. dev->usbc_buf[1] = 1;
  112. else {
  113. mutex_unlock(&dev->usbc_mutex);
  114. v4l2_err(&dev->v4l2_dev, "invalid audio codec %d\n",
  115. codec);
  116. ret = -EINVAL;
  117. goto error;
  118. }
  119. ret = usb_control_msg(dev->udev,
  120. usb_sndctrlpipe(dev->udev, 0),
  121. 0x01, 0x38, CTRL_AUDIO_INPUT_VALUE,
  122. CTRL_DEFAULT_INDEX, dev->usbc_buf, 2,
  123. 1000);
  124. mutex_unlock(&dev->usbc_mutex);
  125. if (ret == 2)
  126. ret = 0;
  127. } else
  128. ret = hdpvr_config_call(dev, CTRL_AUDIO_INPUT_VALUE, input);
  129. error:
  130. return ret;
  131. }
  132. int hdpvr_set_options(struct hdpvr_device *dev)
  133. {
  134. hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, dev->options.video_std);
  135. hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE,
  136. dev->options.video_input+1);
  137. hdpvr_set_audio(dev, dev->options.audio_input+1,
  138. dev->options.audio_codec);
  139. hdpvr_set_bitrate(dev);
  140. hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
  141. dev->options.bitrate_mode);
  142. hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, dev->options.gop_mode);
  143. hdpvr_config_call(dev, CTRL_BRIGHTNESS, dev->options.brightness);
  144. hdpvr_config_call(dev, CTRL_CONTRAST, dev->options.contrast);
  145. hdpvr_config_call(dev, CTRL_HUE, dev->options.hue);
  146. hdpvr_config_call(dev, CTRL_SATURATION, dev->options.saturation);
  147. hdpvr_config_call(dev, CTRL_SHARPNESS, dev->options.sharpness);
  148. return 0;
  149. }