0303-V4L2-Request-maximum-resolution-from-GPU.patch 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. From 5646e586e0494722d5d0783b573819b6d238c71b Mon Sep 17 00:00:00 2001
  2. From: Dave Stevenson <6by9@users.noreply.github.com>
  3. Date: Sat, 16 Apr 2016 23:09:54 +0100
  4. Subject: [PATCH 303/381] V4L2: Request maximum resolution from GPU
  5. Get resolution information about the sensors from the GPU
  6. and advertise it correctly.
  7. Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
  8. ---
  9. drivers/media/platform/bcm2835/bcm2835-camera.c | 59 +++++++++++++++++--------
  10. drivers/media/platform/bcm2835/bcm2835-camera.h | 3 +-
  11. 2 files changed, 43 insertions(+), 19 deletions(-)
  12. --- a/drivers/media/platform/bcm2835/bcm2835-camera.c
  13. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
  14. @@ -38,8 +38,6 @@
  15. #define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  16. #define MIN_WIDTH 16
  17. #define MIN_HEIGHT 16
  18. -#define MAX_WIDTH 2592
  19. -#define MAX_HEIGHT 1944
  20. #define MIN_BUFFER_SIZE (80*1024)
  21. #define MAX_VIDEO_MODE_WIDTH 1280
  22. @@ -729,11 +727,11 @@ static int vidioc_try_fmt_vid_overlay(st
  23. f->fmt.win.clipcount = 0;
  24. f->fmt.win.bitmap = NULL;
  25. - v4l_bound_align_image(&f->fmt.win.w.width, MIN_WIDTH, MAX_WIDTH, 1,
  26. - &f->fmt.win.w.height, MIN_HEIGHT, MAX_HEIGHT,
  27. + v4l_bound_align_image(&f->fmt.win.w.width, MIN_WIDTH, dev->max_width, 1,
  28. + &f->fmt.win.w.height, MIN_HEIGHT, dev->max_height,
  29. 1, 0);
  30. - v4l_bound_align_image(&f->fmt.win.w.left, MIN_WIDTH, MAX_WIDTH, 1,
  31. - &f->fmt.win.w.top, MIN_HEIGHT, MAX_HEIGHT,
  32. + v4l_bound_align_image(&f->fmt.win.w.left, MIN_WIDTH, dev->max_width, 1,
  33. + &f->fmt.win.w.top, MIN_HEIGHT, dev->max_height,
  34. 1, 0);
  35. v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  36. @@ -961,8 +959,9 @@ static int vidioc_try_fmt_vid_cap(struct
  37. "Clipping/aligning %dx%d format %08X\n",
  38. f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  39. - v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  40. - &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  41. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, dev->max_width, 1,
  42. + &f->fmt.pix.height, MIN_HEIGHT, dev->max_height,
  43. + 1, 0);
  44. f->fmt.pix.bytesperline = f->fmt.pix.width * mfmt->ybbp;
  45. /* Image buffer has to be padded to allow for alignment, even though
  46. @@ -1301,9 +1300,10 @@ static int vidioc_s_fmt_vid_cap(struct f
  47. int vidioc_enum_framesizes(struct file *file, void *fh,
  48. struct v4l2_frmsizeenum *fsize)
  49. {
  50. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  51. static const struct v4l2_frmsize_stepwise sizes = {
  52. - MIN_WIDTH, MAX_WIDTH, 2,
  53. - MIN_HEIGHT, MAX_HEIGHT, 2
  54. + MIN_WIDTH, 0, 2,
  55. + MIN_HEIGHT, 0, 2
  56. };
  57. int i;
  58. @@ -1316,6 +1316,8 @@ int vidioc_enum_framesizes(struct file *
  59. return -EINVAL;
  60. fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  61. fsize->stepwise = sizes;
  62. + fsize->stepwise.max_width = dev->max_width;
  63. + fsize->stepwise.max_height = dev->max_height;
  64. return 0;
  65. }
  66. @@ -1323,6 +1325,7 @@ int vidioc_enum_framesizes(struct file *
  67. static int vidioc_enum_frameintervals(struct file *file, void *priv,
  68. struct v4l2_frmivalenum *fival)
  69. {
  70. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  71. int i;
  72. if (fival->index)
  73. @@ -1335,8 +1338,8 @@ static int vidioc_enum_frameintervals(st
  74. return -EINVAL;
  75. /* regarding width & height - we support any within range */
  76. - if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  77. - fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  78. + if (fival->width < MIN_WIDTH || fival->width > dev->max_width ||
  79. + fival->height < MIN_HEIGHT || fival->height > dev->max_height)
  80. return -EINVAL;
  81. fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  82. @@ -1499,12 +1502,17 @@ static struct video_device vdev_template
  83. .release = video_device_release_empty,
  84. };
  85. -static int get_num_cameras(struct vchiq_mmal_instance *instance)
  86. +/* Returns the number of cameras, and also the max resolution supported
  87. + * by those cameras.
  88. + */
  89. +static int get_num_cameras(struct vchiq_mmal_instance *instance,
  90. + unsigned int resolutions[][2], int num_resolutions)
  91. {
  92. int ret;
  93. struct vchiq_mmal_component *cam_info_component;
  94. struct mmal_parameter_camera_info_t cam_info = {0};
  95. int param_size = sizeof(cam_info);
  96. + int i;
  97. /* create a camera_info component */
  98. ret = vchiq_mmal_component_init(instance, "camera_info",
  99. @@ -1520,6 +1528,14 @@ static int get_num_cameras(struct vchiq_
  100. &param_size)) {
  101. pr_info("Failed to get camera info\n");
  102. }
  103. + for (i = 0;
  104. + i < (cam_info.num_cameras > num_resolutions ?
  105. + cam_info.num_cameras :
  106. + num_resolutions);
  107. + i++) {
  108. + resolutions[i][0] = cam_info.cameras[i].max_width;
  109. + resolutions[i][1] = cam_info.cameras[i].max_height;
  110. + }
  111. vchiq_mmal_component_finalise(instance,
  112. cam_info_component);
  113. @@ -1528,12 +1544,13 @@ static int get_num_cameras(struct vchiq_
  114. }
  115. static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  116. - struct vchiq_mmal_component *camera)
  117. + struct vchiq_mmal_component *camera,
  118. + struct bm2835_mmal_dev *dev)
  119. {
  120. int ret;
  121. struct mmal_parameter_camera_config cam_config = {
  122. - .max_stills_w = MAX_WIDTH,
  123. - .max_stills_h = MAX_HEIGHT,
  124. + .max_stills_w = dev->max_width,
  125. + .max_stills_h = dev->max_height,
  126. .stills_yuv422 = 1,
  127. .one_shot_stills = 1,
  128. .max_preview_video_w = (max_video_width > 1920) ?
  129. @@ -1576,7 +1593,8 @@ static int __init mmal_init(struct bm283
  130. }
  131. ret = set_camera_parameters(dev->instance,
  132. - dev->component[MMAL_COMPONENT_CAMERA]);
  133. + dev->component[MMAL_COMPONENT_CAMERA],
  134. + dev);
  135. if (ret < 0)
  136. goto unreg_camera;
  137. @@ -1838,12 +1856,15 @@ static int __init bm2835_mmal_init(void)
  138. int camera;
  139. unsigned int num_cameras;
  140. struct vchiq_mmal_instance *instance;
  141. + unsigned int resolutions[MAX_BCM2835_CAMERAS][2];
  142. ret = vchiq_mmal_init(&instance);
  143. if (ret < 0)
  144. return ret;
  145. - num_cameras = get_num_cameras(instance);
  146. + num_cameras = get_num_cameras(instance,
  147. + resolutions,
  148. + MAX_BCM2835_CAMERAS);
  149. if (num_cameras > MAX_BCM2835_CAMERAS)
  150. num_cameras = MAX_BCM2835_CAMERAS;
  151. @@ -1853,6 +1874,8 @@ static int __init bm2835_mmal_init(void)
  152. return -ENOMEM;
  153. dev->camera_num = camera;
  154. + dev->max_width = resolutions[camera][0];
  155. + dev->max_height = resolutions[camera][1];
  156. /* setup device defaults */
  157. dev->overlay.w.left = 150;
  158. --- a/drivers/media/platform/bcm2835/bcm2835-camera.h
  159. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
  160. @@ -107,7 +107,8 @@ struct bm2835_mmal_dev {
  161. } capture;
  162. unsigned int camera_num;
  163. -
  164. + unsigned int max_width;
  165. + unsigned int max_height;
  166. };
  167. int bm2835_mmal_init_controls(