blob: 6b6f72e4066c503cd214a8913676a20d63888576 [file] [log] [blame]
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -03001/*
2 * Samsung S5P SoC series camera interface (camera capture) driver
3 *
4 * Copyright (c) 2010 Samsung Electronics Co., Ltd
5 * Author: Sylwester Nawrocki, <s.nawrocki@samsung.com>
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 version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/version.h>
15#include <linux/types.h>
16#include <linux/errno.h>
17#include <linux/bug.h>
18#include <linux/interrupt.h>
19#include <linux/device.h>
20#include <linux/platform_device.h>
21#include <linux/list.h>
22#include <linux/slab.h>
23#include <linux/clk.h>
24#include <linux/i2c.h>
25
26#include <linux/videodev2.h>
27#include <media/v4l2-device.h>
28#include <media/v4l2-ioctl.h>
29#include <media/v4l2-mem2mem.h>
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -030030#include <media/videobuf2-core.h>
31#include <media/videobuf2-dma-contig.h>
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -030032
33#include "fimc-core.h"
34
35static struct v4l2_subdev *fimc_subdev_register(struct fimc_dev *fimc,
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -030036 struct s5p_fimc_isp_info *isp_info)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -030037{
38 struct i2c_adapter *i2c_adap;
39 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
40 struct v4l2_subdev *sd = NULL;
41
42 i2c_adap = i2c_get_adapter(isp_info->i2c_bus_num);
43 if (!i2c_adap)
44 return ERR_PTR(-ENOMEM);
45
46 sd = v4l2_i2c_new_subdev_board(&vid_cap->v4l2_dev, i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -030047 isp_info->board_info, NULL);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -030048 if (!sd) {
49 v4l2_err(&vid_cap->v4l2_dev, "failed to acquire subdev\n");
50 return NULL;
51 }
52
53 v4l2_info(&vid_cap->v4l2_dev, "subdevice %s registered successfuly\n",
54 isp_info->board_info->type);
55
56 return sd;
57}
58
59static void fimc_subdev_unregister(struct fimc_dev *fimc)
60{
61 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
62 struct i2c_client *client;
63
64 if (vid_cap->input_index < 0)
65 return; /* Subdevice already released or not registered. */
66
67 if (vid_cap->sd) {
68 v4l2_device_unregister_subdev(vid_cap->sd);
69 client = v4l2_get_subdevdata(vid_cap->sd);
70 i2c_unregister_device(client);
71 i2c_put_adapter(client->adapter);
72 vid_cap->sd = NULL;
73 }
74
75 vid_cap->input_index = -1;
76}
77
78/**
79 * fimc_subdev_attach - attach v4l2_subdev to camera host interface
80 *
81 * @fimc: FIMC device information
82 * @index: index to the array of available subdevices,
83 * -1 for full array search or non negative value
84 * to select specific subdevice
85 */
86static int fimc_subdev_attach(struct fimc_dev *fimc, int index)
87{
88 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -030089 struct s5p_platform_fimc *pdata = fimc->pdata;
90 struct s5p_fimc_isp_info *isp_info;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -030091 struct v4l2_subdev *sd;
92 int i;
93
94 for (i = 0; i < FIMC_MAX_CAMIF_CLIENTS; ++i) {
95 isp_info = pdata->isp_info[i];
96
97 if (!isp_info || (index >= 0 && i != index))
98 continue;
99
100 sd = fimc_subdev_register(fimc, isp_info);
101 if (sd) {
102 vid_cap->sd = sd;
103 vid_cap->input_index = i;
104
105 return 0;
106 }
107 }
108
109 vid_cap->input_index = -1;
110 vid_cap->sd = NULL;
111 v4l2_err(&vid_cap->v4l2_dev, "fimc%d: sensor attach failed\n",
112 fimc->id);
113 return -ENODEV;
114}
115
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300116static int fimc_isp_subdev_init(struct fimc_dev *fimc, unsigned int index)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300117{
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300118 struct s5p_fimc_isp_info *isp_info;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300119 int ret;
120
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300121 if (index >= FIMC_MAX_CAMIF_CLIENTS)
122 return -EINVAL;
123
124 isp_info = fimc->pdata->isp_info[index];
125 if (!isp_info)
126 return -EINVAL;
127
128 if (isp_info->clk_frequency)
129 clk_set_rate(fimc->clock[CLK_CAM], isp_info->clk_frequency);
130
131 ret = clk_enable(fimc->clock[CLK_CAM]);
132 if (ret)
133 return ret;
134
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300135 ret = fimc_subdev_attach(fimc, index);
136 if (ret)
137 return ret;
138
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300139 ret = fimc_hw_set_camera_polarity(fimc, isp_info);
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300140 if (ret)
141 return ret;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300142
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300143 ret = v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 1);
144 if (!ret)
145 return ret;
146
147 /* enabling power failed so unregister subdev */
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300148 fimc_subdev_unregister(fimc);
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300149
150 v4l2_err(&fimc->vid_cap.v4l2_dev, "ISP initialization failed: %d\n",
151 ret);
152
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300153 return ret;
154}
155
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300156static int fimc_stop_capture(struct fimc_dev *fimc)
157{
158 unsigned long flags;
159 struct fimc_vid_cap *cap;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300160 struct fimc_vid_buffer *buf;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300161
162 cap = &fimc->vid_cap;
163
164 if (!fimc_capture_active(fimc))
165 return 0;
166
167 spin_lock_irqsave(&fimc->slock, flags);
168 set_bit(ST_CAPT_SHUT, &fimc->state);
169 fimc_deactivate_capture(fimc);
170 spin_unlock_irqrestore(&fimc->slock, flags);
171
172 wait_event_timeout(fimc->irq_queue,
Sungchun Kangba107952010-12-30 02:35:28 -0300173 !test_bit(ST_CAPT_SHUT, &fimc->state),
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300174 FIMC_SHUTDOWN_TIMEOUT);
175
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300176 v4l2_subdev_call(cap->sd, video, s_stream, 0);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300177
178 spin_lock_irqsave(&fimc->slock, flags);
179 fimc->state &= ~(1 << ST_CAPT_RUN | 1 << ST_CAPT_PEND |
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300180 1 << ST_CAPT_SHUT | 1 << ST_CAPT_STREAM);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300181
182 fimc->vid_cap.active_buf_cnt = 0;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300183
184 /* Release buffers that were enqueued in the driver by videobuf2. */
185 while (!list_empty(&cap->pending_buf_q)) {
186 buf = pending_queue_pop(cap);
187 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
188 }
189
190 while (!list_empty(&cap->active_buf_q)) {
191 buf = active_queue_pop(cap);
192 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
193 }
194
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300195 spin_unlock_irqrestore(&fimc->slock, flags);
196
197 dbg("state: 0x%lx", fimc->state);
198 return 0;
199}
200
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300201static int start_streaming(struct vb2_queue *q)
202{
203 struct fimc_ctx *ctx = q->drv_priv;
204 struct fimc_dev *fimc = ctx->fimc_dev;
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300205 struct s5p_fimc_isp_info *isp_info;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300206 int ret;
207
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300208 fimc_hw_reset(fimc);
209
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300210 ret = v4l2_subdev_call(fimc->vid_cap.sd, video, s_stream, 1);
211 if (ret && ret != -ENOIOCTLCMD)
212 return ret;
213
214 ret = fimc_prepare_config(ctx, ctx->state);
215 if (ret)
216 return ret;
217
218 isp_info = fimc->pdata->isp_info[fimc->vid_cap.input_index];
219 fimc_hw_set_camera_type(fimc, isp_info);
220 fimc_hw_set_camera_source(fimc, isp_info);
221 fimc_hw_set_camera_offset(fimc, &ctx->s_frame);
222
223 if (ctx->state & FIMC_PARAMS) {
224 ret = fimc_set_scaler_info(ctx);
225 if (ret) {
226 err("Scaler setup error");
227 return ret;
228 }
229 fimc_hw_set_input_path(ctx);
Hyunwoong Kimb241c6d2010-12-28 11:27:13 -0300230 fimc_hw_set_prescaler(ctx);
Sylwester Nawrocki70f66ea2010-12-28 11:37:55 -0300231 fimc_hw_set_mainscaler(ctx);
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300232 fimc_hw_set_target_format(ctx);
233 fimc_hw_set_rotation(ctx);
234 fimc_hw_set_effect(ctx);
235 }
236
237 fimc_hw_set_output_path(ctx);
238 fimc_hw_set_out_dma(ctx);
239
240 INIT_LIST_HEAD(&fimc->vid_cap.pending_buf_q);
241 INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q);
242 fimc->vid_cap.active_buf_cnt = 0;
243 fimc->vid_cap.frame_count = 0;
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300244 fimc->vid_cap.buf_index = 0;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300245
246 set_bit(ST_CAPT_PEND, &fimc->state);
247
248 return 0;
249}
250
251static int stop_streaming(struct vb2_queue *q)
252{
253 struct fimc_ctx *ctx = q->drv_priv;
254 struct fimc_dev *fimc = ctx->fimc_dev;
255 unsigned long flags;
256
257 spin_lock_irqsave(&fimc->slock, flags);
258 if (!fimc_capture_running(fimc) && !fimc_capture_pending(fimc)) {
259 spin_unlock_irqrestore(&fimc->slock, flags);
260 return -EINVAL;
261 }
262 spin_unlock_irqrestore(&fimc->slock, flags);
263
264 return fimc_stop_capture(fimc);
265}
266
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300267static unsigned int get_plane_size(struct fimc_frame *fr, unsigned int plane)
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300268{
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300269 if (!fr || plane >= fr->fmt->memplanes)
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300270 return 0;
271
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300272 dbg("%s: w: %d. h: %d. depth[%d]: %d",
273 __func__, fr->width, fr->height, plane, fr->fmt->depth[plane]);
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300274
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300275 return fr->f_width * fr->f_height * fr->fmt->depth[plane] / 8;
276
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300277}
278
279static int queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
280 unsigned int *num_planes, unsigned long sizes[],
281 void *allocators[])
282{
283 struct fimc_ctx *ctx = vq->drv_priv;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300284 struct fimc_fmt *fmt = ctx->d_frame.fmt;
285 int i;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300286
287 if (!fmt)
288 return -EINVAL;
289
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300290 *num_planes = fmt->memplanes;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300291
292 dbg("%s, buffer count=%d, plane count=%d",
293 __func__, *num_buffers, *num_planes);
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300294
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300295 for (i = 0; i < fmt->memplanes; i++) {
296 sizes[i] = get_plane_size(&ctx->d_frame, i);
297 dbg("plane: %u, plane_size: %lu", i, sizes[i]);
298 allocators[i] = ctx->fimc_dev->alloc_ctx;
299 }
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300300
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300301 return 0;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300302}
303
304static int buffer_init(struct vb2_buffer *vb)
305{
306 /* TODO: */
307 return 0;
308}
309
310static int buffer_prepare(struct vb2_buffer *vb)
311{
312 struct vb2_queue *vq = vb->vb2_queue;
313 struct fimc_ctx *ctx = vq->drv_priv;
314 struct v4l2_device *v4l2_dev = &ctx->fimc_dev->m2m.v4l2_dev;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300315 int i;
316
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300317 if (!ctx->d_frame.fmt || vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
318 return -EINVAL;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300319
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300320 for (i = 0; i < ctx->d_frame.fmt->memplanes; i++) {
321 unsigned long size = get_plane_size(&ctx->d_frame, i);
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300322
323 if (vb2_plane_size(vb, i) < size) {
324 v4l2_err(v4l2_dev, "User buffer too small (%ld < %ld)\n",
325 vb2_plane_size(vb, i), size);
326 return -EINVAL;
327 }
328
329 vb2_set_plane_payload(vb, i, size);
330 }
331
332 return 0;
333}
334
335static void buffer_queue(struct vb2_buffer *vb)
336{
337 struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
338 struct fimc_dev *fimc = ctx->fimc_dev;
339 struct fimc_vid_buffer *buf
340 = container_of(vb, struct fimc_vid_buffer, vb);
341 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
342 unsigned long flags;
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300343 int min_bufs;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300344
345 spin_lock_irqsave(&fimc->slock, flags);
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300346 fimc_prepare_addr(ctx, &buf->vb, &ctx->d_frame, &buf->paddr);
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300347
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300348 if (!test_bit(ST_CAPT_STREAM, &fimc->state)
349 && vid_cap->active_buf_cnt < FIMC_MAX_OUT_BUFS) {
350 /* Setup the buffer directly for processing. */
351 int buf_id = (vid_cap->reqbufs_count == 1) ? -1 :
352 vid_cap->buf_index;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300353
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300354 fimc_hw_set_output_addr(fimc, &buf->paddr, buf_id);
355 buf->index = vid_cap->buf_index;
356 active_queue_add(vid_cap, buf);
357
358 if (++vid_cap->buf_index >= FIMC_MAX_OUT_BUFS)
359 vid_cap->buf_index = 0;
360 } else {
361 fimc_pending_queue_add(vid_cap, buf);
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300362 }
Sungchun Kang8ec737f2011-02-07 15:59:46 -0300363
364 min_bufs = vid_cap->reqbufs_count > 1 ? 2 : 1;
365
366 if (vid_cap->active_buf_cnt >= min_bufs &&
367 !test_and_set_bit(ST_CAPT_STREAM, &fimc->state))
368 fimc_activate_capture(ctx);
369
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300370 spin_unlock_irqrestore(&fimc->slock, flags);
371}
372
373static void fimc_lock(struct vb2_queue *vq)
374{
375 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
376 mutex_lock(&ctx->fimc_dev->lock);
377}
378
379static void fimc_unlock(struct vb2_queue *vq)
380{
381 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
382 mutex_unlock(&ctx->fimc_dev->lock);
383}
384
385static struct vb2_ops fimc_capture_qops = {
386 .queue_setup = queue_setup,
387 .buf_prepare = buffer_prepare,
388 .buf_queue = buffer_queue,
389 .buf_init = buffer_init,
390 .wait_prepare = fimc_unlock,
391 .wait_finish = fimc_lock,
392 .start_streaming = start_streaming,
393 .stop_streaming = stop_streaming,
394};
395
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300396static int fimc_capture_open(struct file *file)
397{
398 struct fimc_dev *fimc = video_drvdata(file);
399 int ret = 0;
400
401 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
402
403 /* Return if the corresponding video mem2mem node is already opened. */
404 if (fimc_m2m_active(fimc))
405 return -EBUSY;
406
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300407 if (++fimc->vid_cap.refcnt == 1) {
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300408 ret = fimc_isp_subdev_init(fimc, 0);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300409 if (ret) {
410 fimc->vid_cap.refcnt--;
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300411 return -EIO;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300412 }
413 }
414
415 file->private_data = fimc->vid_cap.ctx;
416
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300417 return 0;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300418}
419
420static int fimc_capture_close(struct file *file)
421{
422 struct fimc_dev *fimc = video_drvdata(file);
423
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300424 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
425
426 if (--fimc->vid_cap.refcnt == 0) {
427 fimc_stop_capture(fimc);
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300428 vb2_queue_release(&fimc->vid_cap.vbq);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300429
430 v4l2_err(&fimc->vid_cap.v4l2_dev, "releasing ISP\n");
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300431
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300432 v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 0);
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300433 clk_disable(fimc->clock[CLK_CAM]);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300434 fimc_subdev_unregister(fimc);
435 }
436
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300437 return 0;
438}
439
440static unsigned int fimc_capture_poll(struct file *file,
441 struct poll_table_struct *wait)
442{
443 struct fimc_ctx *ctx = file->private_data;
444 struct fimc_dev *fimc = ctx->fimc_dev;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300445
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300446 return vb2_poll(&fimc->vid_cap.vbq, file, wait);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300447}
448
449static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma)
450{
451 struct fimc_ctx *ctx = file->private_data;
452 struct fimc_dev *fimc = ctx->fimc_dev;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300453
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300454 return vb2_mmap(&fimc->vid_cap.vbq, vma);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300455}
456
457/* video device file operations */
458static const struct v4l2_file_operations fimc_capture_fops = {
459 .owner = THIS_MODULE,
460 .open = fimc_capture_open,
461 .release = fimc_capture_close,
462 .poll = fimc_capture_poll,
463 .unlocked_ioctl = video_ioctl2,
464 .mmap = fimc_capture_mmap,
465};
466
467static int fimc_vidioc_querycap_capture(struct file *file, void *priv,
468 struct v4l2_capability *cap)
469{
470 struct fimc_ctx *ctx = file->private_data;
471 struct fimc_dev *fimc = ctx->fimc_dev;
472
473 strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
474 strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
475 cap->bus_info[0] = 0;
476 cap->version = KERNEL_VERSION(1, 0, 0);
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300477 cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE |
478 V4L2_CAP_VIDEO_CAPTURE_MPLANE;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300479
480 return 0;
481}
482
483/* Synchronize formats of the camera interface input and attached sensor. */
484static int sync_capture_fmt(struct fimc_ctx *ctx)
485{
486 struct fimc_frame *frame = &ctx->s_frame;
487 struct fimc_dev *fimc = ctx->fimc_dev;
488 struct v4l2_mbus_framefmt *fmt = &fimc->vid_cap.fmt;
489 int ret;
490
491 fmt->width = ctx->d_frame.o_width;
492 fmt->height = ctx->d_frame.o_height;
493
494 ret = v4l2_subdev_call(fimc->vid_cap.sd, video, s_mbus_fmt, fmt);
495 if (ret == -ENOIOCTLCMD) {
496 err("s_mbus_fmt failed");
497 return ret;
498 }
499 dbg("w: %d, h: %d, code= %d", fmt->width, fmt->height, fmt->code);
500
501 frame->fmt = find_mbus_format(fmt, FMT_FLAGS_CAM);
502 if (!frame->fmt) {
503 err("fimc source format not found\n");
504 return -EINVAL;
505 }
506
507 frame->f_width = fmt->width;
508 frame->f_height = fmt->height;
509 frame->width = fmt->width;
510 frame->height = fmt->height;
511 frame->o_width = fmt->width;
512 frame->o_height = fmt->height;
513 frame->offs_h = 0;
514 frame->offs_v = 0;
515
516 return 0;
517}
518
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300519static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
520 struct v4l2_format *f)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300521{
522 struct fimc_ctx *ctx = priv;
523 struct fimc_dev *fimc = ctx->fimc_dev;
524 struct fimc_frame *frame;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300525 struct v4l2_pix_format_mplane *pix;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300526 int ret;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300527 int i;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300528
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300529 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300530 return -EINVAL;
531
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300532 ret = fimc_vidioc_try_fmt_mplane(file, priv, f);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300533 if (ret)
534 return ret;
535
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300536 if (vb2_is_streaming(&fimc->vid_cap.vbq) || fimc_capture_active(fimc))
537 return -EBUSY;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300538
539 frame = &ctx->d_frame;
540
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300541 pix = &f->fmt.pix_mp;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300542 frame->fmt = find_format(f, FMT_FLAGS_M2M | FMT_FLAGS_CAM);
543 if (!frame->fmt) {
544 err("fimc target format not found\n");
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300545 return -EINVAL;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300546 }
547
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300548 for (i = 0; i < frame->fmt->colplanes; i++)
549 frame->payload[i] = pix->plane_fmt[i].bytesperline * pix->height;
550
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300551 /* Output DMA frame pixel size and offsets. */
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300552 frame->f_width = pix->plane_fmt[0].bytesperline * 8
553 / frame->fmt->depth[0];
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300554 frame->f_height = pix->height;
555 frame->width = pix->width;
556 frame->height = pix->height;
557 frame->o_width = pix->width;
558 frame->o_height = pix->height;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300559 frame->offs_h = 0;
560 frame->offs_v = 0;
561
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300562 ctx->state |= (FIMC_PARAMS | FIMC_DST_FMT);
563
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300564 ret = sync_capture_fmt(ctx);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300565 return ret;
566}
567
568static int fimc_cap_enum_input(struct file *file, void *priv,
569 struct v4l2_input *i)
570{
571 struct fimc_ctx *ctx = priv;
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300572 struct s5p_platform_fimc *pldata = ctx->fimc_dev->pdata;
573 struct s5p_fimc_isp_info *isp_info;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300574
575 if (i->index >= FIMC_MAX_CAMIF_CLIENTS)
576 return -EINVAL;
577
578 isp_info = pldata->isp_info[i->index];
579 if (isp_info == NULL)
580 return -EINVAL;
581
582 i->type = V4L2_INPUT_TYPE_CAMERA;
583 strncpy(i->name, isp_info->board_info->type, 32);
584 return 0;
585}
586
587static int fimc_cap_s_input(struct file *file, void *priv,
588 unsigned int i)
589{
590 struct fimc_ctx *ctx = priv;
591 struct fimc_dev *fimc = ctx->fimc_dev;
Sylwester Nawrockidf7e09a2010-12-27 14:42:15 -0300592 struct s5p_platform_fimc *pdata = fimc->pdata;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300593
594 if (fimc_capture_active(ctx->fimc_dev))
595 return -EBUSY;
596
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300597 if (i >= FIMC_MAX_CAMIF_CLIENTS || !pdata->isp_info[i])
598 return -EINVAL;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300599
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300600
601 if (fimc->vid_cap.sd) {
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300602 int ret = v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 0);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300603 if (ret)
604 err("s_power failed: %d", ret);
Sylwester Nawrockia25be182010-12-27 15:34:43 -0300605
606 clk_disable(fimc->clock[CLK_CAM]);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300607 }
608
609 /* Release the attached sensor subdevice. */
610 fimc_subdev_unregister(fimc);
611
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300612 return fimc_isp_subdev_init(fimc, i);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300613}
614
615static int fimc_cap_g_input(struct file *file, void *priv,
616 unsigned int *i)
617{
618 struct fimc_ctx *ctx = priv;
619 struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
620
621 *i = cap->input_index;
622 return 0;
623}
624
625static int fimc_cap_streamon(struct file *file, void *priv,
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300626 enum v4l2_buf_type type)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300627{
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300628 struct fimc_ctx *ctx = priv;
629 struct fimc_dev *fimc = ctx->fimc_dev;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300630
631 if (fimc_capture_active(fimc) || !fimc->vid_cap.sd)
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300632 return -EBUSY;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300633
634 if (!(ctx->state & FIMC_DST_FMT)) {
635 v4l2_err(&fimc->vid_cap.v4l2_dev, "Format is not set\n");
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300636 return -EINVAL;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300637 }
638
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300639 return vb2_streamon(&fimc->vid_cap.vbq, type);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300640}
641
642static int fimc_cap_streamoff(struct file *file, void *priv,
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300643 enum v4l2_buf_type type)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300644{
645 struct fimc_ctx *ctx = priv;
646 struct fimc_dev *fimc = ctx->fimc_dev;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300647
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300648 return vb2_streamoff(&fimc->vid_cap.vbq, type);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300649}
650
651static int fimc_cap_reqbufs(struct file *file, void *priv,
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300652 struct v4l2_requestbuffers *reqbufs)
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300653{
654 struct fimc_ctx *ctx = priv;
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300655 struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300656 int ret;
657
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300658
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300659 ret = vb2_reqbufs(&cap->vbq, reqbufs);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300660 if (!ret)
661 cap->reqbufs_count = reqbufs->count;
662
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300663 return ret;
664}
665
666static int fimc_cap_querybuf(struct file *file, void *priv,
667 struct v4l2_buffer *buf)
668{
669 struct fimc_ctx *ctx = priv;
670 struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
671
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300672 return vb2_querybuf(&cap->vbq, buf);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300673}
674
675static int fimc_cap_qbuf(struct file *file, void *priv,
676 struct v4l2_buffer *buf)
677{
678 struct fimc_ctx *ctx = priv;
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300679 struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap;
680 return vb2_qbuf(&cap->vbq, buf);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300681}
682
683static int fimc_cap_dqbuf(struct file *file, void *priv,
684 struct v4l2_buffer *buf)
685{
686 struct fimc_ctx *ctx = priv;
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300687 return vb2_dqbuf(&ctx->fimc_dev->vid_cap.vbq, buf,
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300688 file->f_flags & O_NONBLOCK);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300689}
690
691static int fimc_cap_s_ctrl(struct file *file, void *priv,
692 struct v4l2_control *ctrl)
693{
694 struct fimc_ctx *ctx = priv;
695 int ret = -EINVAL;
696
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300697 /* Allow any controls but 90/270 rotation while streaming */
698 if (!fimc_capture_active(ctx->fimc_dev) ||
699 ctrl->id != V4L2_CID_ROTATE ||
700 (ctrl->value != 90 && ctrl->value != 270)) {
701 ret = check_ctrl_val(ctx, ctrl);
702 if (!ret) {
703 ret = fimc_s_ctrl(ctx, ctrl);
704 if (!ret)
705 ctx->state |= FIMC_PARAMS;
706 }
707 }
708 if (ret == -EINVAL)
709 ret = v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
710 core, s_ctrl, ctrl);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300711 return ret;
712}
713
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300714static int fimc_cap_cropcap(struct file *file, void *fh,
715 struct v4l2_cropcap *cr)
716{
717 struct fimc_frame *f;
718 struct fimc_ctx *ctx = fh;
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300719
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300720 if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300721 return -EINVAL;
722
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300723 f = &ctx->s_frame;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300724
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300725 cr->bounds.left = 0;
726 cr->bounds.top = 0;
727 cr->bounds.width = f->o_width;
728 cr->bounds.height = f->o_height;
729 cr->defrect = cr->bounds;
730
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300731 return 0;
732}
733
734static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
735{
736 struct fimc_frame *f;
737 struct fimc_ctx *ctx = file->private_data;
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300738
739 f = &ctx->s_frame;
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300740
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300741 cr->c.left = f->offs_h;
742 cr->c.top = f->offs_v;
743 cr->c.width = f->width;
744 cr->c.height = f->height;
745
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300746 return 0;
747}
748
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300749static int fimc_cap_s_crop(struct file *file, void *fh,
750 struct v4l2_crop *cr)
751{
752 struct fimc_frame *f;
753 struct fimc_ctx *ctx = file->private_data;
754 struct fimc_dev *fimc = ctx->fimc_dev;
755 int ret = -EINVAL;
756
757 if (fimc_capture_active(fimc))
758 return -EBUSY;
759
760 ret = fimc_try_crop(ctx, cr);
761 if (ret)
762 return ret;
763
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300764 if (!(ctx->state & FIMC_DST_FMT)) {
765 v4l2_err(&fimc->vid_cap.v4l2_dev,
766 "Capture color format not set\n");
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300767 return -EINVAL; /* TODO: make sure this is the right value */
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300768 }
769
770 f = &ctx->s_frame;
771 /* Check for the pixel scaling ratio when cropping input image. */
Hyunwoong Kim1b09f292010-12-28 22:12:43 -0300772 ret = fimc_check_scaler_ratio(cr->c.width, cr->c.height,
773 ctx->d_frame.width, ctx->d_frame.height,
774 ctx->rotation);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300775 if (ret) {
776 v4l2_err(&fimc->vid_cap.v4l2_dev, "Out of the scaler range");
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300777 return ret;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300778 }
779
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300780 f->offs_h = cr->c.left;
781 f->offs_v = cr->c.top;
782 f->width = cr->c.width;
783 f->height = cr->c.height;
784
785 return 0;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300786}
787
788
789static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
790 .vidioc_querycap = fimc_vidioc_querycap_capture,
791
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300792 .vidioc_enum_fmt_vid_cap_mplane = fimc_vidioc_enum_fmt_mplane,
793 .vidioc_try_fmt_vid_cap_mplane = fimc_vidioc_try_fmt_mplane,
794 .vidioc_s_fmt_vid_cap_mplane = fimc_cap_s_fmt_mplane,
795 .vidioc_g_fmt_vid_cap_mplane = fimc_vidioc_g_fmt_mplane,
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300796
797 .vidioc_reqbufs = fimc_cap_reqbufs,
798 .vidioc_querybuf = fimc_cap_querybuf,
799
800 .vidioc_qbuf = fimc_cap_qbuf,
801 .vidioc_dqbuf = fimc_cap_dqbuf,
802
803 .vidioc_streamon = fimc_cap_streamon,
804 .vidioc_streamoff = fimc_cap_streamoff,
805
806 .vidioc_queryctrl = fimc_vidioc_queryctrl,
807 .vidioc_g_ctrl = fimc_vidioc_g_ctrl,
808 .vidioc_s_ctrl = fimc_cap_s_ctrl,
809
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300810 .vidioc_g_crop = fimc_cap_g_crop,
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300811 .vidioc_s_crop = fimc_cap_s_crop,
Sylwester Nawrockie004e022010-11-25 11:01:51 -0300812 .vidioc_cropcap = fimc_cap_cropcap,
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300813
814 .vidioc_enum_input = fimc_cap_enum_input,
815 .vidioc_s_input = fimc_cap_s_input,
816 .vidioc_g_input = fimc_cap_g_input,
817};
818
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300819/* fimc->lock must be already initialized */
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300820int fimc_register_capture_device(struct fimc_dev *fimc)
821{
822 struct v4l2_device *v4l2_dev = &fimc->vid_cap.v4l2_dev;
823 struct video_device *vfd;
824 struct fimc_vid_cap *vid_cap;
825 struct fimc_ctx *ctx;
826 struct v4l2_format f;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300827 struct fimc_frame *fr;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300828 struct vb2_queue *q;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300829 int ret;
830
831 ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
832 if (!ctx)
833 return -ENOMEM;
834
835 ctx->fimc_dev = fimc;
836 ctx->in_path = FIMC_CAMERA;
837 ctx->out_path = FIMC_DMA;
838 ctx->state = FIMC_CTX_CAP;
839
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300840 /* Default format of the output frames */
841 f.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
842 fr = &ctx->d_frame;
843 fr->fmt = find_format(&f, FMT_FLAGS_M2M);
844 fr->width = fr->f_width = fr->o_width = 640;
845 fr->height = fr->f_height = fr->o_height = 480;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300846
847 if (!v4l2_dev->name[0])
848 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
849 "%s.capture", dev_name(&fimc->pdev->dev));
850
851 ret = v4l2_device_register(NULL, v4l2_dev);
852 if (ret)
853 goto err_info;
854
855 vfd = video_device_alloc();
856 if (!vfd) {
857 v4l2_err(v4l2_dev, "Failed to allocate video device\n");
858 goto err_v4l2_reg;
859 }
860
861 snprintf(vfd->name, sizeof(vfd->name), "%s:cap",
862 dev_name(&fimc->pdev->dev));
863
864 vfd->fops = &fimc_capture_fops;
865 vfd->ioctl_ops = &fimc_capture_ioctl_ops;
866 vfd->minor = -1;
867 vfd->release = video_device_release;
Sylwester Nawrocki8293ebf2010-12-01 10:25:18 -0300868 vfd->lock = &fimc->lock;
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300869 video_set_drvdata(vfd, fimc);
870
871 vid_cap = &fimc->vid_cap;
872 vid_cap->vfd = vfd;
873 vid_cap->active_buf_cnt = 0;
874 vid_cap->reqbufs_count = 0;
875 vid_cap->refcnt = 0;
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300876 /* Default color format for image sensor */
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300877 vid_cap->fmt.code = V4L2_MBUS_FMT_YUYV8_2X8;
878
879 INIT_LIST_HEAD(&vid_cap->pending_buf_q);
880 INIT_LIST_HEAD(&vid_cap->active_buf_q);
881 spin_lock_init(&ctx->slock);
882 vid_cap->ctx = ctx;
883
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300884 q = &fimc->vid_cap.vbq;
885 memset(q, 0, sizeof(*q));
Sylwester Nawrockief7af592010-12-08 14:05:08 -0300886 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
Sylwester Nawrocki2dab38e2010-12-01 10:14:59 -0300887 q->io_modes = VB2_MMAP | VB2_USERPTR;
888 q->drv_priv = fimc->vid_cap.ctx;
889 q->ops = &fimc_capture_qops;
890 q->mem_ops = &vb2_dma_contig_memops;
891 q->buf_struct_size = sizeof(struct fimc_vid_buffer);
892
893 vb2_queue_init(q);
Sylwester Nawrocki5f3cc442010-10-07 10:06:16 -0300894
895 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
896 if (ret) {
897 v4l2_err(v4l2_dev, "Failed to register video device\n");
898 goto err_vd_reg;
899 }
900
901 v4l2_info(v4l2_dev,
902 "FIMC capture driver registered as /dev/video%d\n",
903 vfd->num);
904
905 return 0;
906
907err_vd_reg:
908 video_device_release(vfd);
909err_v4l2_reg:
910 v4l2_device_unregister(v4l2_dev);
911err_info:
912 dev_err(&fimc->pdev->dev, "failed to install\n");
913 return ret;
914}
915
916void fimc_unregister_capture_device(struct fimc_dev *fimc)
917{
918 struct fimc_vid_cap *capture = &fimc->vid_cap;
919
920 if (capture->vfd)
921 video_unregister_device(capture->vfd);
922
923 kfree(capture->ctx);
924}