0233-V4L2-driver-updates-1393.patch 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. From 5490e6a851eec9f80f887c43f2e2031197527476 Mon Sep 17 00:00:00 2001
  2. From: 6by9 <6by9@users.noreply.github.com>
  3. Date: Fri, 8 Apr 2016 18:15:43 +0100
  4. Subject: [PATCH 233/381] V4L2 driver updates (#1393)
  5. * BCM2835-V4L2: Correct ISO control and add V4L2_CID_ISO_SENSITIVITY_AUTO
  6. https://github.com/raspberrypi/linux/issues/1251
  7. V4L2_CID_ISO_SENSITIVITY was not advertising ISO*1000 as it should.
  8. V4L2_CID_ISO_SENSITIVITY_AUTO was not implemented, so was taking
  9. V4L2_CID_ISO_SENSITIVITY as 0 for auto mode.
  10. Still accepts 0 for auto, but also abides by the new parameter.
  11. Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
  12. * BCM2835-V4L2: Add a video_nr parameter.
  13. Adds a kernel parameter "video_nr" to specify the preferred
  14. /dev/videoX device node.
  15. https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=136120&p=905545
  16. Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
  17. * BCM2835-V4L2: Add support for multiple cameras
  18. Ask GPU on load how many cameras have been detected, and
  19. enumerate that number of devices.
  20. Only applicable on the Compute Module as no other device
  21. exposes multiple CSI2 interfaces.
  22. Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
  23. * BCM2835-V4L2: Add control of the overlay location and alpha.
  24. Actually do something useful in vidioc_s_fmt_vid_overlay and
  25. vidioc_try_fmt_vid_overlay, rather than effectively having
  26. read-only fields.
  27. Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
  28. * BCM2835-V4L2: V4L2-Compliance failure fix
  29. VIDIOC_TRY_FMT was failing due to bytesperline not
  30. being set correctly by default.
  31. Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
  32. * BCM2835-V4L2: Make all module parameters static
  33. Clean up to correct variable scope
  34. Signed-off-by: Dave Stevenson <6by9@users.noreply.github.com>
  35. ---
  36. drivers/media/platform/bcm2835/bcm2835-camera.c | 372 +++++++++++++++--------
  37. drivers/media/platform/bcm2835/bcm2835-camera.h | 19 +-
  38. drivers/media/platform/bcm2835/controls.c | 31 +-
  39. drivers/media/platform/bcm2835/mmal-parameters.h | 33 ++
  40. 4 files changed, 320 insertions(+), 135 deletions(-)
  41. --- a/drivers/media/platform/bcm2835/bcm2835-camera.c
  42. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
  43. @@ -45,6 +45,8 @@
  44. #define MAX_VIDEO_MODE_WIDTH 1280
  45. #define MAX_VIDEO_MODE_HEIGHT 720
  46. +#define MAX_BCM2835_CAMERAS 2
  47. +
  48. MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  49. MODULE_AUTHOR("Vincent Sanders");
  50. MODULE_LICENSE("GPL");
  51. @@ -54,8 +56,13 @@ int bcm2835_v4l2_debug;
  52. module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  53. MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  54. -int max_video_width = MAX_VIDEO_MODE_WIDTH;
  55. -int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  56. +#define UNSET (-1)
  57. +static int video_nr[] = {[0 ... (MAX_BCM2835_CAMERAS - 1)] = UNSET };
  58. +module_param_array(video_nr, int, NULL, 0644);
  59. +MODULE_PARM_DESC(video_nr, "videoX start numbers, -1 is autodetect");
  60. +
  61. +static int max_video_width = MAX_VIDEO_MODE_WIDTH;
  62. +static int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  63. module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  64. MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  65. module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  66. @@ -70,11 +77,12 @@ MODULE_PARM_DESC(max_video_height, "Thre
  67. * our function table list (actually switch to an alternate set, but same
  68. * result).
  69. */
  70. -int gst_v4l2src_is_broken = 0;
  71. +static int gst_v4l2src_is_broken;
  72. module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  73. MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  74. -static struct bm2835_mmal_dev *gdev; /* global device data */
  75. +/* global device data array */
  76. +static struct bm2835_mmal_dev *gdev[MAX_BCM2835_CAMERAS];
  77. #define FPS_MIN 1
  78. #define FPS_MAX 90
  79. @@ -413,6 +421,17 @@ static int enable_camera(struct bm2835_m
  80. {
  81. int ret;
  82. if (!dev->camera_use_count) {
  83. + ret = vchiq_mmal_port_parameter_set(
  84. + dev->instance,
  85. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  86. + MMAL_PARAMETER_CAMERA_NUM, &dev->camera_num,
  87. + sizeof(dev->camera_num));
  88. + if (ret < 0) {
  89. + v4l2_err(&dev->v4l2_dev,
  90. + "Failed setting camera num, ret %d\n", ret);
  91. + return -EINVAL;
  92. + }
  93. +
  94. ret = vchiq_mmal_component_enable(
  95. dev->instance,
  96. dev->component[MMAL_COMPONENT_CAMERA]);
  97. @@ -647,6 +666,30 @@ static struct vb2_ops bm2835_mmal_video_
  98. IOCTL operations
  99. ------------------------------------------------------------------*/
  100. +static int set_overlay_params(struct bm2835_mmal_dev *dev,
  101. + struct vchiq_mmal_port *port)
  102. +{
  103. + int ret;
  104. + struct mmal_parameter_displayregion prev_config = {
  105. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  106. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  107. + .layer = PREVIEW_LAYER,
  108. + .alpha = dev->overlay.global_alpha,
  109. + .fullscreen = 0,
  110. + .dest_rect = {
  111. + .x = dev->overlay.w.left,
  112. + .y = dev->overlay.w.top,
  113. + .width = dev->overlay.w.width,
  114. + .height = dev->overlay.w.height,
  115. + },
  116. + };
  117. + ret = vchiq_mmal_port_parameter_set(dev->instance, port,
  118. + MMAL_PARAMETER_DISPLAYREGION,
  119. + &prev_config, sizeof(prev_config));
  120. +
  121. + return ret;
  122. +}
  123. +
  124. /* overlay ioctl */
  125. static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  126. struct v4l2_fmtdesc *f)
  127. @@ -678,10 +721,31 @@ static int vidioc_g_fmt_vid_overlay(stru
  128. static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  129. struct v4l2_format *f)
  130. {
  131. - /* Only support one format so get the current one. */
  132. - vidioc_g_fmt_vid_overlay(file, priv, f);
  133. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  134. - /* todo: allow the size and/or offset to be changed. */
  135. + f->fmt.win.field = V4L2_FIELD_NONE;
  136. + f->fmt.win.chromakey = 0;
  137. + f->fmt.win.clips = NULL;
  138. + f->fmt.win.clipcount = 0;
  139. + f->fmt.win.bitmap = NULL;
  140. +
  141. + v4l_bound_align_image(&f->fmt.win.w.width, MIN_WIDTH, MAX_WIDTH, 1,
  142. + &f->fmt.win.w.height, MIN_HEIGHT, MAX_HEIGHT,
  143. + 1, 0);
  144. + v4l_bound_align_image(&f->fmt.win.w.left, MIN_WIDTH, MAX_WIDTH, 1,
  145. + &f->fmt.win.w.top, MIN_HEIGHT, MAX_HEIGHT,
  146. + 1, 0);
  147. +
  148. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  149. + "Overlay: Now w/h %dx%d l/t %dx%d\n",
  150. + f->fmt.win.w.width, f->fmt.win.w.height,
  151. + f->fmt.win.w.left, f->fmt.win.w.top);
  152. +
  153. + v4l2_dump_win_format(1,
  154. + bcm2835_v4l2_debug,
  155. + &dev->v4l2_dev,
  156. + &f->fmt.win,
  157. + __func__);
  158. return 0;
  159. }
  160. @@ -693,8 +757,11 @@ static int vidioc_s_fmt_vid_overlay(stru
  161. vidioc_try_fmt_vid_overlay(file, priv, f);
  162. dev->overlay = f->fmt.win;
  163. + if (dev->component[MMAL_COMPONENT_PREVIEW]->enabled) {
  164. + set_overlay_params(dev,
  165. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  166. + }
  167. - /* todo: program the preview port parameters */
  168. return 0;
  169. }
  170. @@ -704,20 +771,6 @@ static int vidioc_overlay(struct file *f
  171. struct bm2835_mmal_dev *dev = video_drvdata(file);
  172. struct vchiq_mmal_port *src;
  173. struct vchiq_mmal_port *dst;
  174. - struct mmal_parameter_displayregion prev_config = {
  175. - .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  176. - MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  177. - .layer = PREVIEW_LAYER,
  178. - .alpha = 255,
  179. - .fullscreen = 0,
  180. - .dest_rect = {
  181. - .x = dev->overlay.w.left,
  182. - .y = dev->overlay.w.top,
  183. - .width = dev->overlay.w.width,
  184. - .height = dev->overlay.w.height,
  185. - },
  186. - };
  187. -
  188. if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  189. (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  190. return 0; /* already in requested state */
  191. @@ -749,9 +802,7 @@ static int vidioc_overlay(struct file *f
  192. if (ret < 0)
  193. goto error;
  194. - ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  195. - MMAL_PARAMETER_DISPLAYREGION,
  196. - &prev_config, sizeof(prev_config));
  197. + ret = set_overlay_params(dev, dst);
  198. if (ret < 0)
  199. goto error;
  200. @@ -782,6 +833,9 @@ static int vidioc_g_fbuf(struct file *fi
  201. struct vchiq_mmal_port *preview_port =
  202. &dev->component[MMAL_COMPONENT_CAMERA]->
  203. output[MMAL_CAMERA_PORT_PREVIEW];
  204. +
  205. + a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY |
  206. + V4L2_FBUF_CAP_GLOBAL_ALPHA;
  207. a->flags = V4L2_FBUF_FLAG_OVERLAY;
  208. a->fmt.width = preview_port->es.video.width;
  209. a->fmt.height = preview_port->es.video.height;
  210. @@ -1445,6 +1499,34 @@ static struct video_device vdev_template
  211. .release = video_device_release_empty,
  212. };
  213. +static int get_num_cameras(struct vchiq_mmal_instance *instance)
  214. +{
  215. + int ret;
  216. + struct vchiq_mmal_component *cam_info_component;
  217. + struct mmal_parameter_camera_info_t cam_info = {0};
  218. + int param_size = sizeof(cam_info);
  219. +
  220. + /* create a camera_info component */
  221. + ret = vchiq_mmal_component_init(instance, "camera_info",
  222. + &cam_info_component);
  223. + if (ret < 0)
  224. + /* Unusual failure - let's guess one camera. */
  225. + return 1;
  226. +
  227. + if (vchiq_mmal_port_parameter_get(instance,
  228. + &cam_info_component->control,
  229. + MMAL_PARAMETER_CAMERA_INFO,
  230. + &cam_info,
  231. + &param_size)) {
  232. + pr_info("Failed to get camera info\n");
  233. + }
  234. +
  235. + vchiq_mmal_component_finalise(instance,
  236. + cam_info_component);
  237. +
  238. + return cam_info.num_cameras;
  239. +}
  240. +
  241. static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  242. struct vchiq_mmal_component *camera)
  243. {
  244. @@ -1685,7 +1767,9 @@ static int __init bm2835_mmal_init_devic
  245. /* video device needs to be able to access instance data */
  246. video_set_drvdata(vfd, dev);
  247. - ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  248. + ret = video_register_device(vfd,
  249. + VFL_TYPE_GRABBER,
  250. + video_nr[dev->camera_num]);
  251. if (ret < 0)
  252. return ret;
  253. @@ -1696,10 +1780,52 @@ static int __init bm2835_mmal_init_devic
  254. return 0;
  255. }
  256. +void bcm2835_cleanup_instance(struct bm2835_mmal_dev *dev)
  257. +{
  258. + if (!dev)
  259. + return;
  260. +
  261. + v4l2_info(&dev->v4l2_dev, "unregistering %s\n",
  262. + video_device_node_name(&dev->vdev));
  263. +
  264. + video_unregister_device(&dev->vdev);
  265. +
  266. + if (dev->capture.encode_component) {
  267. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  268. + "mmal_exit - disconnect tunnel\n");
  269. + vchiq_mmal_port_connect_tunnel(dev->instance,
  270. + dev->capture.camera_port, NULL);
  271. + vchiq_mmal_component_disable(dev->instance,
  272. + dev->capture.encode_component);
  273. + }
  274. + vchiq_mmal_component_disable(dev->instance,
  275. + dev->component[MMAL_COMPONENT_CAMERA]);
  276. +
  277. + vchiq_mmal_component_finalise(dev->instance,
  278. + dev->
  279. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  280. +
  281. + vchiq_mmal_component_finalise(dev->instance,
  282. + dev->
  283. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  284. +
  285. + vchiq_mmal_component_finalise(dev->instance,
  286. + dev->component[MMAL_COMPONENT_PREVIEW]);
  287. +
  288. + vchiq_mmal_component_finalise(dev->instance,
  289. + dev->component[MMAL_COMPONENT_CAMERA]);
  290. +
  291. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  292. +
  293. + v4l2_device_unregister(&dev->v4l2_dev);
  294. +
  295. + kfree(dev);
  296. +}
  297. +
  298. static struct v4l2_format default_v4l2_format = {
  299. .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  300. .fmt.pix.width = 1024,
  301. - .fmt.pix.bytesperline = 1024,
  302. + .fmt.pix.bytesperline = 0,
  303. .fmt.pix.height = 768,
  304. .fmt.pix.sizeimage = 1024*768,
  305. };
  306. @@ -1709,76 +1835,93 @@ static int __init bm2835_mmal_init(void)
  307. int ret;
  308. struct bm2835_mmal_dev *dev;
  309. struct vb2_queue *q;
  310. + int camera;
  311. + unsigned int num_cameras;
  312. + struct vchiq_mmal_instance *instance;
  313. - dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  314. - if (!dev)
  315. - return -ENOMEM;
  316. -
  317. - /* setup device defaults */
  318. - dev->overlay.w.left = 150;
  319. - dev->overlay.w.top = 50;
  320. - dev->overlay.w.width = 1024;
  321. - dev->overlay.w.height = 768;
  322. - dev->overlay.clipcount = 0;
  323. - dev->overlay.field = V4L2_FIELD_NONE;
  324. -
  325. - dev->capture.fmt = &formats[3]; /* JPEG */
  326. -
  327. - /* v4l device registration */
  328. - snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  329. - "%s", BM2835_MMAL_MODULE_NAME);
  330. - ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  331. - if (ret)
  332. - goto free_dev;
  333. -
  334. - /* setup v4l controls */
  335. - ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  336. - if (ret < 0)
  337. - goto unreg_dev;
  338. - dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  339. -
  340. - /* mmal init */
  341. - ret = mmal_init(dev);
  342. + ret = vchiq_mmal_init(&instance);
  343. if (ret < 0)
  344. - goto unreg_dev;
  345. + return ret;
  346. - /* initialize queue */
  347. - q = &dev->capture.vb_vidq;
  348. - memset(q, 0, sizeof(*q));
  349. - q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  350. - q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  351. - q->drv_priv = dev;
  352. - q->buf_struct_size = sizeof(struct mmal_buffer);
  353. - q->ops = &bm2835_mmal_video_qops;
  354. - q->mem_ops = &vb2_vmalloc_memops;
  355. - q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  356. - ret = vb2_queue_init(q);
  357. - if (ret < 0)
  358. - goto unreg_dev;
  359. + num_cameras = get_num_cameras(instance);
  360. + if (num_cameras > MAX_BCM2835_CAMERAS)
  361. + num_cameras = MAX_BCM2835_CAMERAS;
  362. +
  363. + for (camera = 0; camera < num_cameras; camera++) {
  364. + dev = kzalloc(sizeof(struct bm2835_mmal_dev), GFP_KERNEL);
  365. + if (!dev)
  366. + return -ENOMEM;
  367. +
  368. + dev->camera_num = camera;
  369. +
  370. + /* setup device defaults */
  371. + dev->overlay.w.left = 150;
  372. + dev->overlay.w.top = 50;
  373. + dev->overlay.w.width = 1024;
  374. + dev->overlay.w.height = 768;
  375. + dev->overlay.clipcount = 0;
  376. + dev->overlay.field = V4L2_FIELD_NONE;
  377. + dev->overlay.global_alpha = 255;
  378. +
  379. + dev->capture.fmt = &formats[3]; /* JPEG */
  380. +
  381. + /* v4l device registration */
  382. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  383. + "%s", BM2835_MMAL_MODULE_NAME);
  384. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  385. + if (ret)
  386. + goto free_dev;
  387. - /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  388. - mutex_init(&dev->mutex);
  389. + /* setup v4l controls */
  390. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  391. + if (ret < 0)
  392. + goto unreg_dev;
  393. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  394. +
  395. + /* mmal init */
  396. + dev->instance = instance;
  397. + ret = mmal_init(dev);
  398. + if (ret < 0)
  399. + goto unreg_dev;
  400. +
  401. + /* initialize queue */
  402. + q = &dev->capture.vb_vidq;
  403. + memset(q, 0, sizeof(*q));
  404. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  405. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  406. + q->drv_priv = dev;
  407. + q->buf_struct_size = sizeof(struct mmal_buffer);
  408. + q->ops = &bm2835_mmal_video_qops;
  409. + q->mem_ops = &vb2_vmalloc_memops;
  410. + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  411. + ret = vb2_queue_init(q);
  412. + if (ret < 0)
  413. + goto unreg_dev;
  414. +
  415. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  416. + mutex_init(&dev->mutex);
  417. +
  418. + /* initialise video devices */
  419. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  420. + if (ret < 0)
  421. + goto unreg_dev;
  422. +
  423. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  424. + * format, but currently the APIs don't join up.
  425. + */
  426. + ret = mmal_setup_components(dev, &default_v4l2_format);
  427. + if (ret < 0) {
  428. + v4l2_err(&dev->v4l2_dev,
  429. + "%s: could not setup components\n", __func__);
  430. + goto unreg_dev;
  431. + }
  432. - /* initialise video devices */
  433. - ret = bm2835_mmal_init_device(dev, &dev->vdev);
  434. - if (ret < 0)
  435. - goto unreg_dev;
  436. + v4l2_info(&dev->v4l2_dev,
  437. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  438. + BM2835_MMAL_VERSION);
  439. - /* Really want to call vidioc_s_fmt_vid_cap with the default
  440. - * format, but currently the APIs don't join up.
  441. - */
  442. - ret = mmal_setup_components(dev, &default_v4l2_format);
  443. - if (ret < 0) {
  444. - v4l2_err(&dev->v4l2_dev,
  445. - "%s: could not setup components\n", __func__);
  446. - goto unreg_dev;
  447. + gdev[camera] = dev;
  448. }
  449. -
  450. - v4l2_info(&dev->v4l2_dev,
  451. - "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  452. - BM2835_MMAL_VERSION);
  453. -
  454. - gdev = dev;
  455. return 0;
  456. unreg_dev:
  457. @@ -1788,8 +1931,11 @@ unreg_dev:
  458. free_dev:
  459. kfree(dev);
  460. - v4l2_err(&dev->v4l2_dev,
  461. - "%s: error %d while loading driver\n",
  462. + for ( ; camera > 0; camera--) {
  463. + bcm2835_cleanup_instance(gdev[camera]);
  464. + gdev[camera] = NULL;
  465. + }
  466. + pr_info("%s: error %d while loading driver\n",
  467. BM2835_MMAL_MODULE_NAME, ret);
  468. return ret;
  469. @@ -1797,46 +1943,14 @@ free_dev:
  470. static void __exit bm2835_mmal_exit(void)
  471. {
  472. - if (!gdev)
  473. - return;
  474. -
  475. - v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  476. - video_device_node_name(&gdev->vdev));
  477. + int camera;
  478. + struct vchiq_mmal_instance *instance = gdev[0]->instance;
  479. - video_unregister_device(&gdev->vdev);
  480. -
  481. - if (gdev->capture.encode_component) {
  482. - v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  483. - "mmal_exit - disconnect tunnel\n");
  484. - vchiq_mmal_port_connect_tunnel(gdev->instance,
  485. - gdev->capture.camera_port, NULL);
  486. - vchiq_mmal_component_disable(gdev->instance,
  487. - gdev->capture.encode_component);
  488. + for (camera = 0; camera < MAX_BCM2835_CAMERAS; camera++) {
  489. + bcm2835_cleanup_instance(gdev[camera]);
  490. + gdev[camera] = NULL;
  491. }
  492. - vchiq_mmal_component_disable(gdev->instance,
  493. - gdev->component[MMAL_COMPONENT_CAMERA]);
  494. -
  495. - vchiq_mmal_component_finalise(gdev->instance,
  496. - gdev->
  497. - component[MMAL_COMPONENT_VIDEO_ENCODE]);
  498. -
  499. - vchiq_mmal_component_finalise(gdev->instance,
  500. - gdev->
  501. - component[MMAL_COMPONENT_IMAGE_ENCODE]);
  502. -
  503. - vchiq_mmal_component_finalise(gdev->instance,
  504. - gdev->component[MMAL_COMPONENT_PREVIEW]);
  505. -
  506. - vchiq_mmal_component_finalise(gdev->instance,
  507. - gdev->component[MMAL_COMPONENT_CAMERA]);
  508. -
  509. - vchiq_mmal_finalise(gdev->instance);
  510. -
  511. - v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  512. -
  513. - v4l2_device_unregister(&gdev->v4l2_dev);
  514. -
  515. - kfree(gdev);
  516. + vchiq_mmal_finalise(instance);
  517. }
  518. module_init(bm2835_mmal_init);
  519. --- a/drivers/media/platform/bcm2835/bcm2835-camera.h
  520. +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
  521. @@ -15,7 +15,7 @@
  522. * core driver device
  523. */
  524. -#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  525. +#define V4L2_CTRL_COUNT 29 /* number of v4l controls */
  526. enum {
  527. MMAL_COMPONENT_CAMERA = 0,
  528. @@ -58,6 +58,8 @@ struct bm2835_mmal_dev {
  529. enum mmal_parameter_exposuremeteringmode metering_mode;
  530. unsigned int manual_shutter_speed;
  531. bool exp_auto_priority;
  532. + bool manual_iso_enabled;
  533. + uint32_t iso;
  534. /* allocated mmal instance and components */
  535. struct vchiq_mmal_instance *instance;
  536. @@ -104,6 +106,8 @@ struct bm2835_mmal_dev {
  537. } capture;
  538. + unsigned int camera_num;
  539. +
  540. };
  541. int bm2835_mmal_init_controls(
  542. @@ -124,3 +128,16 @@ int set_framerate_params(struct bm2835_m
  543. (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  544. (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  545. }
  546. +#define v4l2_dump_win_format(level, debug, dev, win_fmt, desc) \
  547. +{ \
  548. + v4l2_dbg(level, debug, dev, \
  549. +"%s: w %u h %u l %u t %u field %u chromakey %06X clip %p " \
  550. +"clipcount %u bitmap %p\n", \
  551. + desc == NULL ? "" : desc, \
  552. + (win_fmt)->w.width, (win_fmt)->w.height, \
  553. + (win_fmt)->w.left, (win_fmt)->w.top, \
  554. + (win_fmt)->field, \
  555. + (win_fmt)->chromakey, \
  556. + (win_fmt)->clips, (win_fmt)->clipcount, \
  557. + (win_fmt)->bitmap); \
  558. +}
  559. --- a/drivers/media/platform/bcm2835/controls.c
  560. +++ b/drivers/media/platform/bcm2835/controls.c
  561. @@ -49,10 +49,13 @@ static const s64 ev_bias_qmenu[] = {
  562. 4000
  563. };
  564. -/* Supported ISO values
  565. +/* Supported ISO values (*1000)
  566. * ISOO = auto ISO
  567. */
  568. static const s64 iso_qmenu[] = {
  569. + 0, 100000, 200000, 400000, 800000,
  570. +};
  571. +static const uint32_t iso_values[] = {
  572. 0, 100, 200, 400, 800,
  573. };
  574. @@ -201,7 +204,7 @@ static int ctrl_set_value(struct bm2835_
  575. &u32_value, sizeof(u32_value));
  576. }
  577. -static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  578. +static int ctrl_set_iso(struct bm2835_mmal_dev *dev,
  579. struct v4l2_ctrl *ctrl,
  580. const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  581. {
  582. @@ -211,12 +214,23 @@ static int ctrl_set_value_menu(struct bm
  583. if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  584. return 1;
  585. + if (ctrl->id == V4L2_CID_ISO_SENSITIVITY)
  586. + dev->iso = iso_values[ctrl->val];
  587. + else if (ctrl->id == V4L2_CID_ISO_SENSITIVITY_AUTO)
  588. + dev->manual_iso_enabled =
  589. + (ctrl->val == V4L2_ISO_SENSITIVITY_MANUAL ?
  590. + true :
  591. + false);
  592. +
  593. control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  594. - u32_value = mmal_ctrl->imenu[ctrl->val];
  595. + if (dev->manual_iso_enabled)
  596. + u32_value = dev->iso;
  597. + else
  598. + u32_value = 0;
  599. return vchiq_mmal_port_parameter_set(dev->instance, control,
  600. - mmal_ctrl->mmal_id,
  601. + MMAL_PARAMETER_ISO,
  602. &u32_value, sizeof(u32_value));
  603. }
  604. @@ -956,7 +970,14 @@ static const struct bm2835_mmal_v4l2_ctr
  605. V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  606. 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  607. MMAL_PARAMETER_ISO,
  608. - &ctrl_set_value_menu,
  609. + &ctrl_set_iso,
  610. + false
  611. + },
  612. + {
  613. + V4L2_CID_ISO_SENSITIVITY_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  614. + 0, 1, V4L2_ISO_SENSITIVITY_AUTO, 1, NULL,
  615. + MMAL_PARAMETER_ISO,
  616. + &ctrl_set_iso,
  617. false
  618. },
  619. {
  620. --- a/drivers/media/platform/bcm2835/mmal-parameters.h
  621. +++ b/drivers/media/platform/bcm2835/mmal-parameters.h
  622. @@ -654,3 +654,36 @@ struct mmal_parameter_imagefx_parameters
  623. u32 num_effect_params;
  624. u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  625. };
  626. +
  627. +#define MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS 4
  628. +#define MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES 2
  629. +#define MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN 16
  630. +
  631. +struct mmal_parameter_camera_info_camera_t {
  632. + u32 port_id;
  633. + u32 max_width;
  634. + u32 max_height;
  635. + u32 lens_present;
  636. + u8 camera_name[MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN];
  637. +};
  638. +
  639. +enum mmal_parameter_camera_info_flash_type_t {
  640. + /* Make values explicit to ensure they match values in config ini */
  641. + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_XENON = 0,
  642. + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_LED = 1,
  643. + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_OTHER = 2,
  644. + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_MAX = 0x7FFFFFFF
  645. +};
  646. +
  647. +struct mmal_parameter_camera_info_flash_t {
  648. + enum mmal_parameter_camera_info_flash_type_t flash_type;
  649. +};
  650. +
  651. +struct mmal_parameter_camera_info_t {
  652. + u32 num_cameras;
  653. + u32 num_flashes;
  654. + struct mmal_parameter_camera_info_camera_t
  655. + cameras[MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS];
  656. + struct mmal_parameter_camera_info_flash_t
  657. + flashes[MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES];
  658. +};