blob: 9958918e2449527d22e6680357664fafbb14a4f8 [file] [log] [blame]
Josh Wu195ebc42011-06-07 22:40:19 -03001/*
2 * Copyright (c) 2011 Atmel Corporation
3 * Josh Wu, <josh.wu@atmel.com>
4 *
5 * Based on previous work by Lars Haring, <lars.haring@atmel.com>
6 * and Sedji Gaouaou
7 * Based on the bttv driver for Bt848 with respective copyright holders
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/clk.h>
15#include <linux/completion.h>
16#include <linux/delay.h>
17#include <linux/fs.h>
18#include <linux/init.h>
19#include <linux/interrupt.h>
20#include <linux/kernel.h>
21#include <linux/module.h>
Sakari Ailus859969b2016-08-26 20:17:25 -030022#include <linux/of_graph.h>
Josh Wu195ebc42011-06-07 22:40:19 -030023#include <linux/platform_device.h>
Josh Wuf3745a3a2015-05-26 06:54:46 -030024#include <linux/pm_runtime.h>
Josh Wu195ebc42011-06-07 22:40:19 -030025#include <linux/slab.h>
Hans Verkuild12c9082016-08-16 16:56:43 -030026#include <linux/of.h>
Josh Wu195ebc42011-06-07 22:40:19 -030027
Hans Verkuild12c9082016-08-16 16:56:43 -030028#include <linux/videodev2.h>
29#include <media/v4l2-ctrls.h>
30#include <media/v4l2-device.h>
31#include <media/v4l2-dev.h>
32#include <media/v4l2-ioctl.h>
33#include <media/v4l2-event.h>
Sakari Ailus859969b2016-08-26 20:17:25 -030034#include <media/v4l2-fwnode.h>
Josh Wu195ebc42011-06-07 22:40:19 -030035#include <media/videobuf2-dma-contig.h>
Hans Verkuild12c9082016-08-16 16:56:43 -030036#include <media/v4l2-image-sizes.h>
Josh Wu195ebc42011-06-07 22:40:19 -030037
Laurent Pinchart40a78f32015-08-01 06:22:54 -030038#include "atmel-isi.h"
39
Hugues Fruchetec62c9a2017-05-19 07:04:52 -030040#define MAX_SUPPORT_WIDTH 2048U
41#define MAX_SUPPORT_HEIGHT 2048U
Josh Wu195ebc42011-06-07 22:40:19 -030042#define MIN_FRAME_RATE 15
43#define FRAME_INTERVAL_MILLI_SEC (1000 / MIN_FRAME_RATE)
44
Josh Wu195ebc42011-06-07 22:40:19 -030045/* Frame buffer descriptor */
46struct fbd {
47 /* Physical address of the frame buffer */
48 u32 fb_address;
49 /* DMA Control Register(only in HISI2) */
50 u32 dma_ctrl;
51 /* Physical address of the next fbd */
52 u32 next_fbd_address;
53};
54
55static void set_dma_ctrl(struct fbd *fb_desc, u32 ctrl)
56{
57 fb_desc->dma_ctrl = ctrl;
58}
59
60struct isi_dma_desc {
61 struct list_head list;
62 struct fbd *p_fbd;
Mauro Carvalho Chehab8f052322014-08-22 05:52:54 -050063 dma_addr_t fbd_phys;
Josh Wu195ebc42011-06-07 22:40:19 -030064};
65
66/* Frame buffer data */
67struct frame_buffer {
Junghak Sung2d700712015-09-22 10:30:30 -030068 struct vb2_v4l2_buffer vb;
Josh Wu195ebc42011-06-07 22:40:19 -030069 struct isi_dma_desc *p_dma_desc;
70 struct list_head list;
71};
72
Hans Verkuild12c9082016-08-16 16:56:43 -030073struct isi_graph_entity {
74 struct device_node *node;
75
76 struct v4l2_async_subdev asd;
77 struct v4l2_subdev *subdev;
78};
79
80/*
81 * struct isi_format - ISI media bus format information
82 * @fourcc: Fourcc code for this format
83 * @mbus_code: V4L2 media bus format code.
84 * @bpp: Bytes per pixel (when stored in memory)
85 * @swap: Byte swap configuration value
86 * @support: Indicates format supported by subdev
87 * @skip: Skip duplicate format supported by subdev
88 */
89struct isi_format {
90 u32 fourcc;
91 u32 mbus_code;
92 u8 bpp;
93 u32 swap;
94};
95
96
Josh Wu195ebc42011-06-07 22:40:19 -030097struct atmel_isi {
98 /* Protects the access of variables shared with the ISR */
Hans Verkuild12c9082016-08-16 16:56:43 -030099 spinlock_t irqlock;
100 struct device *dev;
Josh Wu195ebc42011-06-07 22:40:19 -0300101 void __iomem *regs;
102
103 int sequence;
Josh Wu195ebc42011-06-07 22:40:19 -0300104
Josh Wu195ebc42011-06-07 22:40:19 -0300105 /* Allocate descriptors for dma buffer use */
106 struct fbd *p_fb_descriptors;
Mauro Carvalho Chehab8f052322014-08-22 05:52:54 -0500107 dma_addr_t fb_descriptors_phys;
Josh Wu195ebc42011-06-07 22:40:19 -0300108 struct list_head dma_desc_head;
Hans Verkuild12c9082016-08-16 16:56:43 -0300109 struct isi_dma_desc dma_desc[VIDEO_MAX_FRAME];
Josh Wu0fb72572015-11-03 03:45:09 -0200110 bool enable_preview_path;
Josh Wu195ebc42011-06-07 22:40:19 -0300111
112 struct completion complete;
Josh Wud8ec0962011-12-08 07:18:49 -0300113 /* ISI peripherial clock */
Josh Wu195ebc42011-06-07 22:40:19 -0300114 struct clk *pclk;
115 unsigned int irq;
116
Josh Wu833e1062014-07-25 07:13:39 -0300117 struct isi_platform_data pdata;
Guennadi Liakhovetskia4e9f102011-07-27 12:18:37 -0300118 u16 width_flags; /* max 12 bits */
Josh Wu195ebc42011-06-07 22:40:19 -0300119
120 struct list_head video_buffer_list;
121 struct frame_buffer *active;
122
Hans Verkuild12c9082016-08-16 16:56:43 -0300123 struct v4l2_device v4l2_dev;
124 struct video_device *vdev;
125 struct v4l2_async_notifier notifier;
126 struct isi_graph_entity entity;
127 struct v4l2_format fmt;
128
129 const struct isi_format **user_formats;
130 unsigned int num_user_formats;
131 const struct isi_format *current_fmt;
132
133 struct mutex lock;
134 struct vb2_queue queue;
Josh Wu195ebc42011-06-07 22:40:19 -0300135};
136
Hans Verkuild12c9082016-08-16 16:56:43 -0300137#define notifier_to_isi(n) container_of(n, struct atmel_isi, notifier)
138
Josh Wu195ebc42011-06-07 22:40:19 -0300139static void isi_writel(struct atmel_isi *isi, u32 reg, u32 val)
140{
141 writel(val, isi->regs + reg);
142}
143static u32 isi_readl(struct atmel_isi *isi, u32 reg)
144{
145 return readl(isi->regs + reg);
146}
147
Hans Verkuild12c9082016-08-16 16:56:43 -0300148static void configure_geometry(struct atmel_isi *isi)
Josh Wu195ebc42011-06-07 22:40:19 -0300149{
Josh Wubd70f262015-11-03 03:45:10 -0200150 u32 cfg2, psize;
Hans Verkuild12c9082016-08-16 16:56:43 -0300151 u32 fourcc = isi->current_fmt->fourcc;
Josh Wu05645a42015-11-03 03:45:12 -0200152
153 isi->enable_preview_path = fourcc == V4L2_PIX_FMT_RGB565 ||
154 fourcc == V4L2_PIX_FMT_RGB32;
Josh Wu195ebc42011-06-07 22:40:19 -0300155
Josh Wuad5f9d12015-09-11 04:00:14 -0300156 /* According to sensor's output format to set cfg2 */
Hans Verkuild12c9082016-08-16 16:56:43 -0300157 cfg2 = isi->current_fmt->swap;
Josh Wu195ebc42011-06-07 22:40:19 -0300158
159 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
Josh Wu195ebc42011-06-07 22:40:19 -0300160 /* Set width */
Hans Verkuild12c9082016-08-16 16:56:43 -0300161 cfg2 |= ((isi->fmt.fmt.pix.width - 1) << ISI_CFG2_IM_HSIZE_OFFSET) &
Josh Wu195ebc42011-06-07 22:40:19 -0300162 ISI_CFG2_IM_HSIZE_MASK;
163 /* Set height */
Hans Verkuild12c9082016-08-16 16:56:43 -0300164 cfg2 |= ((isi->fmt.fmt.pix.height - 1) << ISI_CFG2_IM_VSIZE_OFFSET)
Josh Wu195ebc42011-06-07 22:40:19 -0300165 & ISI_CFG2_IM_VSIZE_MASK;
166 isi_writel(isi, ISI_CFG2, cfg2);
Josh Wubd70f262015-11-03 03:45:10 -0200167
168 /* No down sampling, preview size equal to sensor output size */
Hans Verkuild12c9082016-08-16 16:56:43 -0300169 psize = ((isi->fmt.fmt.pix.width - 1) << ISI_PSIZE_PREV_HSIZE_OFFSET) &
Josh Wubd70f262015-11-03 03:45:10 -0200170 ISI_PSIZE_PREV_HSIZE_MASK;
Hans Verkuild12c9082016-08-16 16:56:43 -0300171 psize |= ((isi->fmt.fmt.pix.height - 1) << ISI_PSIZE_PREV_VSIZE_OFFSET) &
Josh Wubd70f262015-11-03 03:45:10 -0200172 ISI_PSIZE_PREV_VSIZE_MASK;
173 isi_writel(isi, ISI_PSIZE, psize);
174 isi_writel(isi, ISI_PDECF, ISI_PDECF_NO_SAMPLING);
Josh Wu195ebc42011-06-07 22:40:19 -0300175}
176
177static irqreturn_t atmel_isi_handle_streaming(struct atmel_isi *isi)
178{
179 if (isi->active) {
Junghak Sung2d700712015-09-22 10:30:30 -0300180 struct vb2_v4l2_buffer *vbuf = &isi->active->vb;
Josh Wu195ebc42011-06-07 22:40:19 -0300181 struct frame_buffer *buf = isi->active;
182
183 list_del_init(&buf->list);
Junghak Sungd6dd6452015-11-03 08:16:37 -0200184 vbuf->vb2_buf.timestamp = ktime_get_ns();
Junghak Sung2d700712015-09-22 10:30:30 -0300185 vbuf->sequence = isi->sequence++;
Hans Verkuild12c9082016-08-16 16:56:43 -0300186 vbuf->field = V4L2_FIELD_NONE;
Junghak Sung2d700712015-09-22 10:30:30 -0300187 vb2_buffer_done(&vbuf->vb2_buf, VB2_BUF_STATE_DONE);
Josh Wu195ebc42011-06-07 22:40:19 -0300188 }
189
190 if (list_empty(&isi->video_buffer_list)) {
191 isi->active = NULL;
192 } else {
193 /* start next dma frame. */
194 isi->active = list_entry(isi->video_buffer_list.next,
195 struct frame_buffer, list);
Josh Wu0fb72572015-11-03 03:45:09 -0200196 if (!isi->enable_preview_path) {
197 isi_writel(isi, ISI_DMA_C_DSCR,
198 (u32)isi->active->p_dma_desc->fbd_phys);
199 isi_writel(isi, ISI_DMA_C_CTRL,
200 ISI_DMA_CTRL_FETCH | ISI_DMA_CTRL_DONE);
201 isi_writel(isi, ISI_DMA_CHER, ISI_DMA_CHSR_C_CH);
202 } else {
203 isi_writel(isi, ISI_DMA_P_DSCR,
204 (u32)isi->active->p_dma_desc->fbd_phys);
205 isi_writel(isi, ISI_DMA_P_CTRL,
206 ISI_DMA_CTRL_FETCH | ISI_DMA_CTRL_DONE);
207 isi_writel(isi, ISI_DMA_CHER, ISI_DMA_CHSR_P_CH);
208 }
Josh Wu195ebc42011-06-07 22:40:19 -0300209 }
210 return IRQ_HANDLED;
211}
212
213/* ISI interrupt service routine */
214static irqreturn_t isi_interrupt(int irq, void *dev_id)
215{
216 struct atmel_isi *isi = dev_id;
217 u32 status, mask, pending;
218 irqreturn_t ret = IRQ_NONE;
219
Hans Verkuild12c9082016-08-16 16:56:43 -0300220 spin_lock(&isi->irqlock);
Josh Wu195ebc42011-06-07 22:40:19 -0300221
222 status = isi_readl(isi, ISI_STATUS);
223 mask = isi_readl(isi, ISI_INTMASK);
224 pending = status & mask;
225
226 if (pending & ISI_CTRL_SRST) {
227 complete(&isi->complete);
228 isi_writel(isi, ISI_INTDIS, ISI_CTRL_SRST);
229 ret = IRQ_HANDLED;
230 } else if (pending & ISI_CTRL_DIS) {
231 complete(&isi->complete);
232 isi_writel(isi, ISI_INTDIS, ISI_CTRL_DIS);
233 ret = IRQ_HANDLED;
234 } else {
Josh Wu0fb72572015-11-03 03:45:09 -0200235 if (likely(pending & ISI_SR_CXFR_DONE) ||
236 likely(pending & ISI_SR_PXFR_DONE))
Josh Wu195ebc42011-06-07 22:40:19 -0300237 ret = atmel_isi_handle_streaming(isi);
238 }
239
Hans Verkuild12c9082016-08-16 16:56:43 -0300240 spin_unlock(&isi->irqlock);
Josh Wu195ebc42011-06-07 22:40:19 -0300241 return ret;
242}
243
244#define WAIT_ISI_RESET 1
245#define WAIT_ISI_DISABLE 0
246static int atmel_isi_wait_status(struct atmel_isi *isi, int wait_reset)
247{
248 unsigned long timeout;
249 /*
250 * The reset or disable will only succeed if we have a
251 * pixel clock from the camera.
252 */
253 init_completion(&isi->complete);
254
255 if (wait_reset) {
256 isi_writel(isi, ISI_INTEN, ISI_CTRL_SRST);
257 isi_writel(isi, ISI_CTRL, ISI_CTRL_SRST);
258 } else {
259 isi_writel(isi, ISI_INTEN, ISI_CTRL_DIS);
260 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
261 }
262
263 timeout = wait_for_completion_timeout(&isi->complete,
Josh Wud67b4882015-06-17 07:27:08 -0300264 msecs_to_jiffies(500));
Josh Wu195ebc42011-06-07 22:40:19 -0300265 if (timeout == 0)
266 return -ETIMEDOUT;
267
268 return 0;
269}
270
271/* ------------------------------------------------------------------
272 Videobuf operations
273 ------------------------------------------------------------------*/
Hans Verkuildf9ecb02015-10-28 00:50:37 -0200274static int queue_setup(struct vb2_queue *vq,
Guennadi Liakhovetskifc714e702011-08-24 10:30:21 -0300275 unsigned int *nbuffers, unsigned int *nplanes,
Hans Verkuil36c0f8b2016-04-15 09:15:05 -0300276 unsigned int sizes[], struct device *alloc_devs[])
Josh Wu195ebc42011-06-07 22:40:19 -0300277{
Hans Verkuild12c9082016-08-16 16:56:43 -0300278 struct atmel_isi *isi = vb2_get_drv_priv(vq);
Josh Wu195ebc42011-06-07 22:40:19 -0300279 unsigned long size;
Josh Wu195ebc42011-06-07 22:40:19 -0300280
Hans Verkuild12c9082016-08-16 16:56:43 -0300281 size = isi->fmt.fmt.pix.sizeimage;
Josh Wu195ebc42011-06-07 22:40:19 -0300282
Hans Verkuild12c9082016-08-16 16:56:43 -0300283 /* Make sure the image size is large enough. */
284 if (*nplanes)
285 return sizes[0] < size ? -EINVAL : 0;
Josh Wu195ebc42011-06-07 22:40:19 -0300286
287 *nplanes = 1;
288 sizes[0] = size;
Josh Wu195ebc42011-06-07 22:40:19 -0300289
Josh Wu195ebc42011-06-07 22:40:19 -0300290 isi->active = NULL;
291
Hans Verkuild12c9082016-08-16 16:56:43 -0300292 dev_dbg(isi->dev, "%s, count=%d, size=%ld\n", __func__,
Josh Wu195ebc42011-06-07 22:40:19 -0300293 *nbuffers, size);
294
295 return 0;
296}
297
298static int buffer_init(struct vb2_buffer *vb)
299{
Junghak Sung2d700712015-09-22 10:30:30 -0300300 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
301 struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
Josh Wu195ebc42011-06-07 22:40:19 -0300302
303 buf->p_dma_desc = NULL;
304 INIT_LIST_HEAD(&buf->list);
305
306 return 0;
307}
308
309static int buffer_prepare(struct vb2_buffer *vb)
310{
Junghak Sung2d700712015-09-22 10:30:30 -0300311 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
Junghak Sung2d700712015-09-22 10:30:30 -0300312 struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
Hans Verkuild12c9082016-08-16 16:56:43 -0300313 struct atmel_isi *isi = vb2_get_drv_priv(vb->vb2_queue);
Josh Wu195ebc42011-06-07 22:40:19 -0300314 unsigned long size;
315 struct isi_dma_desc *desc;
Josh Wu195ebc42011-06-07 22:40:19 -0300316
Hans Verkuild12c9082016-08-16 16:56:43 -0300317 size = isi->fmt.fmt.pix.sizeimage;
Josh Wu195ebc42011-06-07 22:40:19 -0300318
319 if (vb2_plane_size(vb, 0) < size) {
Hans Verkuild12c9082016-08-16 16:56:43 -0300320 dev_err(isi->dev, "%s data will not fit into plane (%lu < %lu)\n",
Josh Wu195ebc42011-06-07 22:40:19 -0300321 __func__, vb2_plane_size(vb, 0), size);
322 return -EINVAL;
323 }
324
Junghak Sung2d700712015-09-22 10:30:30 -0300325 vb2_set_plane_payload(vb, 0, size);
Josh Wu195ebc42011-06-07 22:40:19 -0300326
327 if (!buf->p_dma_desc) {
328 if (list_empty(&isi->dma_desc_head)) {
Hans Verkuild12c9082016-08-16 16:56:43 -0300329 dev_err(isi->dev, "Not enough dma descriptors.\n");
Josh Wu195ebc42011-06-07 22:40:19 -0300330 return -EINVAL;
331 } else {
332 /* Get an available descriptor */
333 desc = list_entry(isi->dma_desc_head.next,
334 struct isi_dma_desc, list);
335 /* Delete the descriptor since now it is used */
336 list_del_init(&desc->list);
337
338 /* Initialize the dma descriptor */
339 desc->p_fbd->fb_address =
Marek Szyprowskiba7fcb02011-08-29 03:20:56 -0300340 vb2_dma_contig_plane_dma_addr(vb, 0);
Josh Wu195ebc42011-06-07 22:40:19 -0300341 desc->p_fbd->next_fbd_address = 0;
342 set_dma_ctrl(desc->p_fbd, ISI_DMA_CTRL_WB);
343
344 buf->p_dma_desc = desc;
345 }
346 }
347 return 0;
348}
349
350static void buffer_cleanup(struct vb2_buffer *vb)
351{
Junghak Sung2d700712015-09-22 10:30:30 -0300352 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
Hans Verkuild12c9082016-08-16 16:56:43 -0300353 struct atmel_isi *isi = vb2_get_drv_priv(vb->vb2_queue);
Junghak Sung2d700712015-09-22 10:30:30 -0300354 struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
Josh Wu195ebc42011-06-07 22:40:19 -0300355
356 /* This descriptor is available now and we add to head list */
357 if (buf->p_dma_desc)
358 list_add(&buf->p_dma_desc->list, &isi->dma_desc_head);
359}
360
361static void start_dma(struct atmel_isi *isi, struct frame_buffer *buffer)
362{
363 u32 ctrl, cfg1;
364
365 cfg1 = isi_readl(isi, ISI_CFG1);
366 /* Enable irq: cxfr for the codec path, pxfr for the preview path */
367 isi_writel(isi, ISI_INTEN,
368 ISI_SR_CXFR_DONE | ISI_SR_PXFR_DONE);
369
370 /* Check if already in a frame */
Josh Wu0fb72572015-11-03 03:45:09 -0200371 if (!isi->enable_preview_path) {
372 if (isi_readl(isi, ISI_STATUS) & ISI_CTRL_CDC) {
Hans Verkuild12c9082016-08-16 16:56:43 -0300373 dev_err(isi->dev, "Already in frame handling.\n");
Josh Wu0fb72572015-11-03 03:45:09 -0200374 return;
375 }
Josh Wu195ebc42011-06-07 22:40:19 -0300376
Josh Wu0fb72572015-11-03 03:45:09 -0200377 isi_writel(isi, ISI_DMA_C_DSCR,
378 (u32)buffer->p_dma_desc->fbd_phys);
379 isi_writel(isi, ISI_DMA_C_CTRL,
380 ISI_DMA_CTRL_FETCH | ISI_DMA_CTRL_DONE);
381 isi_writel(isi, ISI_DMA_CHER, ISI_DMA_CHSR_C_CH);
382 } else {
383 isi_writel(isi, ISI_DMA_P_DSCR,
384 (u32)buffer->p_dma_desc->fbd_phys);
385 isi_writel(isi, ISI_DMA_P_CTRL,
386 ISI_DMA_CTRL_FETCH | ISI_DMA_CTRL_DONE);
387 isi_writel(isi, ISI_DMA_CHER, ISI_DMA_CHSR_P_CH);
388 }
Josh Wu195ebc42011-06-07 22:40:19 -0300389
Josh Wubd6f2742013-12-10 09:25:47 -0300390 cfg1 &= ~ISI_CFG1_FRATE_DIV_MASK;
Josh Wu195ebc42011-06-07 22:40:19 -0300391 /* Enable linked list */
Josh Wu833e1062014-07-25 07:13:39 -0300392 cfg1 |= isi->pdata.frate | ISI_CFG1_DISCR;
Josh Wu195ebc42011-06-07 22:40:19 -0300393
Josh Wu0fb72572015-11-03 03:45:09 -0200394 /* Enable ISI */
395 ctrl = ISI_CTRL_EN;
396
397 if (!isi->enable_preview_path)
398 ctrl |= ISI_CTRL_CDC;
399
Josh Wu195ebc42011-06-07 22:40:19 -0300400 isi_writel(isi, ISI_CTRL, ctrl);
401 isi_writel(isi, ISI_CFG1, cfg1);
402}
403
404static void buffer_queue(struct vb2_buffer *vb)
405{
Junghak Sung2d700712015-09-22 10:30:30 -0300406 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
Hans Verkuild12c9082016-08-16 16:56:43 -0300407 struct atmel_isi *isi = vb2_get_drv_priv(vb->vb2_queue);
Junghak Sung2d700712015-09-22 10:30:30 -0300408 struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
Josh Wu195ebc42011-06-07 22:40:19 -0300409 unsigned long flags = 0;
410
Hans Verkuild12c9082016-08-16 16:56:43 -0300411 spin_lock_irqsave(&isi->irqlock, flags);
Josh Wu195ebc42011-06-07 22:40:19 -0300412 list_add_tail(&buf->list, &isi->video_buffer_list);
413
Markus Elfringaf28c992017-08-28 06:50:28 -0400414 if (!isi->active) {
Josh Wu195ebc42011-06-07 22:40:19 -0300415 isi->active = buf;
Marek Szyprowskibd323e22011-08-29 08:51:49 -0300416 if (vb2_is_streaming(vb->vb2_queue))
417 start_dma(isi, buf);
Josh Wu195ebc42011-06-07 22:40:19 -0300418 }
Hans Verkuild12c9082016-08-16 16:56:43 -0300419 spin_unlock_irqrestore(&isi->irqlock, flags);
Josh Wu195ebc42011-06-07 22:40:19 -0300420}
421
Marek Szyprowskibd323e22011-08-29 08:51:49 -0300422static int start_streaming(struct vb2_queue *vq, unsigned int count)
Josh Wu195ebc42011-06-07 22:40:19 -0300423{
Hans Verkuild12c9082016-08-16 16:56:43 -0300424 struct atmel_isi *isi = vb2_get_drv_priv(vq);
425 struct frame_buffer *buf, *node;
Laurent Pinchartc7686262013-11-02 21:25:06 -0300426 int ret;
427
Hugues Fruchetec62c9a2017-05-19 07:04:52 -0300428 pm_runtime_get_sync(isi->dev);
429
Hans Verkuild12c9082016-08-16 16:56:43 -0300430 /* Enable stream on the sub device */
431 ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
432 if (ret && ret != -ENOIOCTLCMD) {
433 dev_err(isi->dev, "stream on failed in subdev\n");
434 goto err_start_stream;
435 }
436
Laurent Pinchartc7686262013-11-02 21:25:06 -0300437 /* Reset ISI */
438 ret = atmel_isi_wait_status(isi, WAIT_ISI_RESET);
439 if (ret < 0) {
Hans Verkuild12c9082016-08-16 16:56:43 -0300440 dev_err(isi->dev, "Reset ISI timed out\n");
441 goto err_reset;
Laurent Pinchartc7686262013-11-02 21:25:06 -0300442 }
443 /* Disable all interrupts */
Mauro Carvalho Chehab9842a412014-08-22 05:53:27 -0500444 isi_writel(isi, ISI_INTDIS, (u32)~0UL);
Josh Wu195ebc42011-06-07 22:40:19 -0300445
Hans Verkuild12c9082016-08-16 16:56:43 -0300446 isi->sequence = 0;
447 configure_geometry(isi);
Josh Wuf653da32015-09-11 04:00:15 -0300448
Hans Verkuild12c9082016-08-16 16:56:43 -0300449 spin_lock_irq(&isi->irqlock);
Josh Wu1426f61b2013-10-24 04:27:11 -0300450 /* Clear any pending interrupt */
Mauro Carvalho Chehabb91677a2014-08-26 11:21:43 -0300451 isi_readl(isi, ISI_STATUS);
Josh Wu195ebc42011-06-07 22:40:19 -0300452
Hans Verkuild12c9082016-08-16 16:56:43 -0300453 start_dma(isi, isi->active);
454 spin_unlock_irq(&isi->irqlock);
Josh Wu195ebc42011-06-07 22:40:19 -0300455
456 return 0;
Hans Verkuild12c9082016-08-16 16:56:43 -0300457
458err_reset:
Hans Verkuild12c9082016-08-16 16:56:43 -0300459 v4l2_subdev_call(isi->entity.subdev, video, s_stream, 0);
460
461err_start_stream:
Hugues Fruchetec62c9a2017-05-19 07:04:52 -0300462 pm_runtime_put(isi->dev);
463
Hans Verkuild12c9082016-08-16 16:56:43 -0300464 spin_lock_irq(&isi->irqlock);
465 isi->active = NULL;
466 /* Release all active buffers */
467 list_for_each_entry_safe(buf, node, &isi->video_buffer_list, list) {
468 list_del_init(&buf->list);
469 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
470 }
471 spin_unlock_irq(&isi->irqlock);
472
473 return ret;
Josh Wu195ebc42011-06-07 22:40:19 -0300474}
475
476/* abort streaming and wait for last buffer */
Hans Verkuile37559b2014-04-17 02:47:21 -0300477static void stop_streaming(struct vb2_queue *vq)
Josh Wu195ebc42011-06-07 22:40:19 -0300478{
Hans Verkuild12c9082016-08-16 16:56:43 -0300479 struct atmel_isi *isi = vb2_get_drv_priv(vq);
Josh Wu195ebc42011-06-07 22:40:19 -0300480 struct frame_buffer *buf, *node;
481 int ret = 0;
482 unsigned long timeout;
483
Hans Verkuild12c9082016-08-16 16:56:43 -0300484 /* Disable stream on the sub device */
485 ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 0);
486 if (ret && ret != -ENOIOCTLCMD)
487 dev_err(isi->dev, "stream off failed in subdev\n");
488
489 spin_lock_irq(&isi->irqlock);
Josh Wu195ebc42011-06-07 22:40:19 -0300490 isi->active = NULL;
491 /* Release all active buffers */
492 list_for_each_entry_safe(buf, node, &isi->video_buffer_list, list) {
493 list_del_init(&buf->list);
Junghak Sung2d700712015-09-22 10:30:30 -0300494 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
Josh Wu195ebc42011-06-07 22:40:19 -0300495 }
Hans Verkuild12c9082016-08-16 16:56:43 -0300496 spin_unlock_irq(&isi->irqlock);
Josh Wu195ebc42011-06-07 22:40:19 -0300497
Josh Wu0fb72572015-11-03 03:45:09 -0200498 if (!isi->enable_preview_path) {
499 timeout = jiffies + FRAME_INTERVAL_MILLI_SEC * HZ;
500 /* Wait until the end of the current frame. */
501 while ((isi_readl(isi, ISI_STATUS) & ISI_CTRL_CDC) &&
502 time_before(jiffies, timeout))
503 msleep(1);
Josh Wu195ebc42011-06-07 22:40:19 -0300504
Josh Wu0fb72572015-11-03 03:45:09 -0200505 if (time_after(jiffies, timeout))
Hans Verkuild12c9082016-08-16 16:56:43 -0300506 dev_err(isi->dev,
Josh Wu0fb72572015-11-03 03:45:09 -0200507 "Timeout waiting for finishing codec request\n");
508 }
Josh Wu195ebc42011-06-07 22:40:19 -0300509
510 /* Disable interrupts */
511 isi_writel(isi, ISI_INTDIS,
512 ISI_SR_CXFR_DONE | ISI_SR_PXFR_DONE);
513
514 /* Disable ISI and wait for it is done */
515 ret = atmel_isi_wait_status(isi, WAIT_ISI_DISABLE);
516 if (ret < 0)
Hans Verkuild12c9082016-08-16 16:56:43 -0300517 dev_err(isi->dev, "Disable ISI timed out\n");
Josh Wuf3745a3a2015-05-26 06:54:46 -0300518
Hans Verkuild12c9082016-08-16 16:56:43 -0300519 pm_runtime_put(isi->dev);
Josh Wu195ebc42011-06-07 22:40:19 -0300520}
521
Julia Lawallb7b361f2016-09-08 20:59:10 -0300522static const struct vb2_ops isi_video_qops = {
Josh Wu195ebc42011-06-07 22:40:19 -0300523 .queue_setup = queue_setup,
524 .buf_init = buffer_init,
525 .buf_prepare = buffer_prepare,
526 .buf_cleanup = buffer_cleanup,
527 .buf_queue = buffer_queue,
528 .start_streaming = start_streaming,
529 .stop_streaming = stop_streaming,
Lad, Prabhakar976036d2014-11-26 19:42:27 -0300530 .wait_prepare = vb2_ops_wait_prepare,
531 .wait_finish = vb2_ops_wait_finish,
Josh Wu195ebc42011-06-07 22:40:19 -0300532};
533
Hans Verkuild12c9082016-08-16 16:56:43 -0300534static int isi_g_fmt_vid_cap(struct file *file, void *priv,
535 struct v4l2_format *fmt)
Josh Wu195ebc42011-06-07 22:40:19 -0300536{
Hans Verkuild12c9082016-08-16 16:56:43 -0300537 struct atmel_isi *isi = video_drvdata(file);
Lad, Prabhakar976036d2014-11-26 19:42:27 -0300538
Hans Verkuild12c9082016-08-16 16:56:43 -0300539 *fmt = isi->fmt;
Josh Wu195ebc42011-06-07 22:40:19 -0300540
Hans Verkuild12c9082016-08-16 16:56:43 -0300541 return 0;
Josh Wu195ebc42011-06-07 22:40:19 -0300542}
543
Hans Verkuild12c9082016-08-16 16:56:43 -0300544static const struct isi_format *find_format_by_fourcc(struct atmel_isi *isi,
545 unsigned int fourcc)
Josh Wu195ebc42011-06-07 22:40:19 -0300546{
Hans Verkuild12c9082016-08-16 16:56:43 -0300547 unsigned int num_formats = isi->num_user_formats;
548 const struct isi_format *fmt;
549 unsigned int i;
Josh Wu195ebc42011-06-07 22:40:19 -0300550
Hans Verkuild12c9082016-08-16 16:56:43 -0300551 for (i = 0; i < num_formats; i++) {
552 fmt = isi->user_formats[i];
553 if (fmt->fourcc == fourcc)
554 return fmt;
Josh Wu195ebc42011-06-07 22:40:19 -0300555 }
556
Hans Verkuild12c9082016-08-16 16:56:43 -0300557 return NULL;
Josh Wu195ebc42011-06-07 22:40:19 -0300558}
559
Hans Verkuild12c9082016-08-16 16:56:43 -0300560static int isi_try_fmt(struct atmel_isi *isi, struct v4l2_format *f,
561 const struct isi_format **current_fmt)
Josh Wu195ebc42011-06-07 22:40:19 -0300562{
Hans Verkuild12c9082016-08-16 16:56:43 -0300563 const struct isi_format *isi_fmt;
564 struct v4l2_pix_format *pixfmt = &f->fmt.pix;
Hans Verkuil5eab4982015-04-09 04:05:35 -0300565 struct v4l2_subdev_pad_config pad_cfg;
566 struct v4l2_subdev_format format = {
567 .which = V4L2_SUBDEV_FORMAT_TRY,
568 };
Josh Wu195ebc42011-06-07 22:40:19 -0300569 int ret;
570
Hans Verkuild12c9082016-08-16 16:56:43 -0300571 isi_fmt = find_format_by_fourcc(isi, pixfmt->pixelformat);
572 if (!isi_fmt) {
573 isi_fmt = isi->user_formats[isi->num_user_formats - 1];
574 pixfmt->pixelformat = isi_fmt->fourcc;
Josh Wu195ebc42011-06-07 22:40:19 -0300575 }
576
Hugues Fruchetec62c9a2017-05-19 07:04:52 -0300577 /* Limit to Atmel ISI hardware capabilities */
578 pixfmt->width = clamp(pixfmt->width, 0U, MAX_SUPPORT_WIDTH);
579 pixfmt->height = clamp(pixfmt->height, 0U, MAX_SUPPORT_HEIGHT);
Josh Wu195ebc42011-06-07 22:40:19 -0300580
Hans Verkuild12c9082016-08-16 16:56:43 -0300581 v4l2_fill_mbus_format(&format.format, pixfmt, isi_fmt->mbus_code);
582 ret = v4l2_subdev_call(isi->entity.subdev, pad, set_fmt,
583 &pad_cfg, &format);
Josh Wu195ebc42011-06-07 22:40:19 -0300584 if (ret < 0)
585 return ret;
586
Hans Verkuild12c9082016-08-16 16:56:43 -0300587 v4l2_fill_pix_format(pixfmt, &format.format);
Josh Wu195ebc42011-06-07 22:40:19 -0300588
Hans Verkuild12c9082016-08-16 16:56:43 -0300589 pixfmt->field = V4L2_FIELD_NONE;
590 pixfmt->bytesperline = pixfmt->width * isi_fmt->bpp;
591 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
Josh Wu195ebc42011-06-07 22:40:19 -0300592
Hans Verkuild12c9082016-08-16 16:56:43 -0300593 if (current_fmt)
594 *current_fmt = isi_fmt;
595
596 return 0;
Josh Wu195ebc42011-06-07 22:40:19 -0300597}
598
Hans Verkuild12c9082016-08-16 16:56:43 -0300599static int isi_set_fmt(struct atmel_isi *isi, struct v4l2_format *f)
Josh Wu195ebc42011-06-07 22:40:19 -0300600{
Hans Verkuild12c9082016-08-16 16:56:43 -0300601 struct v4l2_subdev_format format = {
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300602 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
Hans Verkuilebcff5f2015-04-09 04:01:33 -0300603 };
Hans Verkuild12c9082016-08-16 16:56:43 -0300604 const struct isi_format *current_fmt;
Josh Wu195ebc42011-06-07 22:40:19 -0300605 int ret;
Hans Verkuild12c9082016-08-16 16:56:43 -0300606
607 ret = isi_try_fmt(isi, f, &current_fmt);
608 if (ret)
609 return ret;
610
611 v4l2_fill_mbus_format(&format.format, &f->fmt.pix,
612 current_fmt->mbus_code);
613 ret = v4l2_subdev_call(isi->entity.subdev, pad,
614 set_fmt, NULL, &format);
615 if (ret < 0)
616 return ret;
617
618 isi->fmt = *f;
619 isi->current_fmt = current_fmt;
620
621 return 0;
622}
623
624static int isi_s_fmt_vid_cap(struct file *file, void *priv,
625 struct v4l2_format *f)
626{
627 struct atmel_isi *isi = video_drvdata(file);
628
629 if (vb2_is_streaming(&isi->queue))
630 return -EBUSY;
631
632 return isi_set_fmt(isi, f);
633}
634
635static int isi_try_fmt_vid_cap(struct file *file, void *priv,
636 struct v4l2_format *f)
637{
638 struct atmel_isi *isi = video_drvdata(file);
639
640 return isi_try_fmt(isi, f, NULL);
641}
642
643static int isi_enum_fmt_vid_cap(struct file *file, void *priv,
644 struct v4l2_fmtdesc *f)
645{
646 struct atmel_isi *isi = video_drvdata(file);
647
648 if (f->index >= isi->num_user_formats)
649 return -EINVAL;
650
651 f->pixelformat = isi->user_formats[f->index]->fourcc;
652 return 0;
653}
654
655static int isi_querycap(struct file *file, void *priv,
656 struct v4l2_capability *cap)
657{
658 strlcpy(cap->driver, "atmel-isi", sizeof(cap->driver));
659 strlcpy(cap->card, "Atmel Image Sensor Interface", sizeof(cap->card));
660 strlcpy(cap->bus_info, "platform:isi", sizeof(cap->bus_info));
661 return 0;
662}
663
664static int isi_enum_input(struct file *file, void *priv,
665 struct v4l2_input *i)
666{
667 if (i->index != 0)
668 return -EINVAL;
669
670 i->type = V4L2_INPUT_TYPE_CAMERA;
671 strlcpy(i->name, "Camera", sizeof(i->name));
672 return 0;
673}
674
675static int isi_g_input(struct file *file, void *priv, unsigned int *i)
676{
677 *i = 0;
678 return 0;
679}
680
681static int isi_s_input(struct file *file, void *priv, unsigned int i)
682{
683 if (i > 0)
684 return -EINVAL;
685 return 0;
686}
687
688static int isi_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
689{
690 struct atmel_isi *isi = video_drvdata(file);
691
692 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
693 return -EINVAL;
694
695 a->parm.capture.readbuffers = 2;
696 return v4l2_subdev_call(isi->entity.subdev, video, g_parm, a);
697}
698
699static int isi_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
700{
701 struct atmel_isi *isi = video_drvdata(file);
702
703 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
704 return -EINVAL;
705
706 a->parm.capture.readbuffers = 2;
707 return v4l2_subdev_call(isi->entity.subdev, video, s_parm, a);
708}
709
710static int isi_enum_framesizes(struct file *file, void *fh,
711 struct v4l2_frmsizeenum *fsize)
712{
713 struct atmel_isi *isi = video_drvdata(file);
714 const struct isi_format *isi_fmt;
715 struct v4l2_subdev_frame_size_enum fse = {
716 .index = fsize->index,
717 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
718 };
719 int ret;
720
721 isi_fmt = find_format_by_fourcc(isi, fsize->pixel_format);
722 if (!isi_fmt)
723 return -EINVAL;
724
725 fse.code = isi_fmt->mbus_code;
726
727 ret = v4l2_subdev_call(isi->entity.subdev, pad, enum_frame_size,
728 NULL, &fse);
729 if (ret)
730 return ret;
731
732 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
733 fsize->discrete.width = fse.max_width;
734 fsize->discrete.height = fse.max_height;
735
736 return 0;
737}
738
739static int isi_enum_frameintervals(struct file *file, void *fh,
740 struct v4l2_frmivalenum *fival)
741{
742 struct atmel_isi *isi = video_drvdata(file);
743 const struct isi_format *isi_fmt;
744 struct v4l2_subdev_frame_interval_enum fie = {
745 .index = fival->index,
746 .width = fival->width,
747 .height = fival->height,
748 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
749 };
750 int ret;
751
752 isi_fmt = find_format_by_fourcc(isi, fival->pixel_format);
753 if (!isi_fmt)
754 return -EINVAL;
755
756 fie.code = isi_fmt->mbus_code;
757
758 ret = v4l2_subdev_call(isi->entity.subdev, pad,
759 enum_frame_interval, NULL, &fie);
760 if (ret)
761 return ret;
762
763 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
764 fival->discrete = fie.interval;
765
766 return 0;
767}
768
769static void isi_camera_set_bus_param(struct atmel_isi *isi)
770{
Josh Wu195ebc42011-06-07 22:40:19 -0300771 u32 cfg1 = 0;
772
Josh Wu195ebc42011-06-07 22:40:19 -0300773 /* set bus param for ISI */
Hans Verkuild12c9082016-08-16 16:56:43 -0300774 if (isi->pdata.hsync_act_low)
Josh Wu195ebc42011-06-07 22:40:19 -0300775 cfg1 |= ISI_CFG1_HSYNC_POL_ACTIVE_LOW;
Hans Verkuild12c9082016-08-16 16:56:43 -0300776 if (isi->pdata.vsync_act_low)
Josh Wu195ebc42011-06-07 22:40:19 -0300777 cfg1 |= ISI_CFG1_VSYNC_POL_ACTIVE_LOW;
Hans Verkuild12c9082016-08-16 16:56:43 -0300778 if (isi->pdata.pclk_act_falling)
Josh Wu195ebc42011-06-07 22:40:19 -0300779 cfg1 |= ISI_CFG1_PIXCLK_POL_ACTIVE_FALLING;
Josh Wu833e1062014-07-25 07:13:39 -0300780 if (isi->pdata.has_emb_sync)
Josh Wu195ebc42011-06-07 22:40:19 -0300781 cfg1 |= ISI_CFG1_EMB_SYNC;
Josh Wu833e1062014-07-25 07:13:39 -0300782 if (isi->pdata.full_mode)
Josh Wu195ebc42011-06-07 22:40:19 -0300783 cfg1 |= ISI_CFG1_FULL_MODE;
784
Josh Wuce037f12014-11-25 06:30:25 -0300785 cfg1 |= ISI_CFG1_THMASK_BEATS_16;
786
Josh Wuf3745a3a2015-05-26 06:54:46 -0300787 /* Enable PM and peripheral clock before operate isi registers */
Hans Verkuild12c9082016-08-16 16:56:43 -0300788 pm_runtime_get_sync(isi->dev);
Josh Wuf3745a3a2015-05-26 06:54:46 -0300789
Josh Wu195ebc42011-06-07 22:40:19 -0300790 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
791 isi_writel(isi, ISI_CFG1, cfg1);
792
Hans Verkuild12c9082016-08-16 16:56:43 -0300793 pm_runtime_put(isi->dev);
Josh Wu195ebc42011-06-07 22:40:19 -0300794}
795
Josh Wu195ebc42011-06-07 22:40:19 -0300796/* -----------------------------------------------------------------------*/
Laurent Pinchart40a78f32015-08-01 06:22:54 -0300797static int atmel_isi_parse_dt(struct atmel_isi *isi,
Josh Wu8ff19bc2014-07-28 04:25:17 -0300798 struct platform_device *pdev)
799{
Hans Verkuild12c9082016-08-16 16:56:43 -0300800 struct device_node *np = pdev->dev.of_node;
Sakari Ailus859969b2016-08-26 20:17:25 -0300801 struct v4l2_fwnode_endpoint ep;
Josh Wu8ff19bc2014-07-28 04:25:17 -0300802 int err;
803
804 /* Default settings for ISI */
805 isi->pdata.full_mode = 1;
Josh Wu8ff19bc2014-07-28 04:25:17 -0300806 isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL;
807
808 np = of_graph_get_next_endpoint(np, NULL);
809 if (!np) {
810 dev_err(&pdev->dev, "Could not find the endpoint\n");
811 return -EINVAL;
812 }
813
Sakari Ailus859969b2016-08-26 20:17:25 -0300814 err = v4l2_fwnode_endpoint_parse(of_fwnode_handle(np), &ep);
Laurent Pinchart37512392015-08-01 06:22:53 -0300815 of_node_put(np);
Josh Wu8ff19bc2014-07-28 04:25:17 -0300816 if (err) {
817 dev_err(&pdev->dev, "Could not parse the endpoint\n");
Laurent Pinchart37512392015-08-01 06:22:53 -0300818 return err;
Josh Wu8ff19bc2014-07-28 04:25:17 -0300819 }
820
821 switch (ep.bus.parallel.bus_width) {
822 case 8:
823 isi->pdata.data_width_flags = ISI_DATAWIDTH_8;
824 break;
825 case 10:
826 isi->pdata.data_width_flags =
827 ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10;
828 break;
829 default:
830 dev_err(&pdev->dev, "Unsupported bus width: %d\n",
831 ep.bus.parallel.bus_width);
Laurent Pinchart37512392015-08-01 06:22:53 -0300832 return -EINVAL;
Josh Wu8ff19bc2014-07-28 04:25:17 -0300833 }
834
Josh Wuac4033e2015-08-04 06:37:49 -0300835 if (ep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
836 isi->pdata.hsync_act_low = true;
837 if (ep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
838 isi->pdata.vsync_act_low = true;
839 if (ep.bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
840 isi->pdata.pclk_act_falling = true;
841
842 if (ep.bus_type == V4L2_MBUS_BT656)
843 isi->pdata.has_emb_sync = true;
844
Laurent Pinchart37512392015-08-01 06:22:53 -0300845 return 0;
Josh Wu8ff19bc2014-07-28 04:25:17 -0300846}
847
Hans Verkuild12c9082016-08-16 16:56:43 -0300848static int isi_open(struct file *file)
849{
850 struct atmel_isi *isi = video_drvdata(file);
851 struct v4l2_subdev *sd = isi->entity.subdev;
852 int ret;
853
854 if (mutex_lock_interruptible(&isi->lock))
855 return -ERESTARTSYS;
856
857 ret = v4l2_fh_open(file);
858 if (ret < 0)
859 goto unlock;
860
861 if (!v4l2_fh_is_singular_file(file))
862 goto fh_rel;
863
864 ret = v4l2_subdev_call(sd, core, s_power, 1);
865 if (ret < 0 && ret != -ENOIOCTLCMD)
866 goto fh_rel;
867
868 ret = isi_set_fmt(isi, &isi->fmt);
869 if (ret)
870 v4l2_subdev_call(sd, core, s_power, 0);
871fh_rel:
872 if (ret)
873 v4l2_fh_release(file);
874unlock:
875 mutex_unlock(&isi->lock);
876 return ret;
877}
878
879static int isi_release(struct file *file)
880{
881 struct atmel_isi *isi = video_drvdata(file);
882 struct v4l2_subdev *sd = isi->entity.subdev;
883 bool fh_singular;
884 int ret;
885
886 mutex_lock(&isi->lock);
887
888 fh_singular = v4l2_fh_is_singular_file(file);
889
890 ret = _vb2_fop_release(file, NULL);
891
892 if (fh_singular)
893 v4l2_subdev_call(sd, core, s_power, 0);
894
895 mutex_unlock(&isi->lock);
896
897 return ret;
898}
899
900static const struct v4l2_ioctl_ops isi_ioctl_ops = {
901 .vidioc_querycap = isi_querycap,
902
903 .vidioc_try_fmt_vid_cap = isi_try_fmt_vid_cap,
904 .vidioc_g_fmt_vid_cap = isi_g_fmt_vid_cap,
905 .vidioc_s_fmt_vid_cap = isi_s_fmt_vid_cap,
906 .vidioc_enum_fmt_vid_cap = isi_enum_fmt_vid_cap,
907
908 .vidioc_enum_input = isi_enum_input,
909 .vidioc_g_input = isi_g_input,
910 .vidioc_s_input = isi_s_input,
911
912 .vidioc_g_parm = isi_g_parm,
913 .vidioc_s_parm = isi_s_parm,
914 .vidioc_enum_framesizes = isi_enum_framesizes,
915 .vidioc_enum_frameintervals = isi_enum_frameintervals,
916
917 .vidioc_reqbufs = vb2_ioctl_reqbufs,
918 .vidioc_create_bufs = vb2_ioctl_create_bufs,
919 .vidioc_querybuf = vb2_ioctl_querybuf,
920 .vidioc_qbuf = vb2_ioctl_qbuf,
921 .vidioc_dqbuf = vb2_ioctl_dqbuf,
922 .vidioc_expbuf = vb2_ioctl_expbuf,
923 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
924 .vidioc_streamon = vb2_ioctl_streamon,
925 .vidioc_streamoff = vb2_ioctl_streamoff,
926
927 .vidioc_log_status = v4l2_ctrl_log_status,
928 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
929 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
930};
931
932static const struct v4l2_file_operations isi_fops = {
933 .owner = THIS_MODULE,
934 .unlocked_ioctl = video_ioctl2,
935 .open = isi_open,
936 .release = isi_release,
937 .poll = vb2_fop_poll,
938 .mmap = vb2_fop_mmap,
939 .read = vb2_fop_read,
940};
941
942static int isi_set_default_fmt(struct atmel_isi *isi)
943{
944 struct v4l2_format f = {
945 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
946 .fmt.pix = {
947 .width = VGA_WIDTH,
948 .height = VGA_HEIGHT,
949 .field = V4L2_FIELD_NONE,
950 .pixelformat = isi->user_formats[0]->fourcc,
951 },
952 };
953 int ret;
954
955 ret = isi_try_fmt(isi, &f, NULL);
956 if (ret)
957 return ret;
958 isi->current_fmt = isi->user_formats[0];
959 isi->fmt = f;
960 return 0;
961}
962
963static const struct isi_format isi_formats[] = {
964 {
965 .fourcc = V4L2_PIX_FMT_YUYV,
966 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
967 .bpp = 2,
968 .swap = ISI_CFG2_YCC_SWAP_DEFAULT,
969 }, {
970 .fourcc = V4L2_PIX_FMT_YUYV,
971 .mbus_code = MEDIA_BUS_FMT_YVYU8_2X8,
972 .bpp = 2,
973 .swap = ISI_CFG2_YCC_SWAP_MODE_1,
974 }, {
975 .fourcc = V4L2_PIX_FMT_YUYV,
976 .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
977 .bpp = 2,
978 .swap = ISI_CFG2_YCC_SWAP_MODE_2,
979 }, {
980 .fourcc = V4L2_PIX_FMT_YUYV,
981 .mbus_code = MEDIA_BUS_FMT_VYUY8_2X8,
982 .bpp = 2,
983 .swap = ISI_CFG2_YCC_SWAP_MODE_3,
984 }, {
985 .fourcc = V4L2_PIX_FMT_RGB565,
986 .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
987 .bpp = 2,
988 .swap = ISI_CFG2_YCC_SWAP_MODE_2,
989 }, {
990 .fourcc = V4L2_PIX_FMT_RGB565,
991 .mbus_code = MEDIA_BUS_FMT_YVYU8_2X8,
992 .bpp = 2,
993 .swap = ISI_CFG2_YCC_SWAP_MODE_3,
994 }, {
995 .fourcc = V4L2_PIX_FMT_RGB565,
996 .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
997 .bpp = 2,
998 .swap = ISI_CFG2_YCC_SWAP_DEFAULT,
999 }, {
1000 .fourcc = V4L2_PIX_FMT_RGB565,
1001 .mbus_code = MEDIA_BUS_FMT_VYUY8_2X8,
1002 .bpp = 2,
1003 .swap = ISI_CFG2_YCC_SWAP_MODE_1,
1004 },
1005};
1006
1007static int isi_formats_init(struct atmel_isi *isi)
1008{
1009 const struct isi_format *isi_fmts[ARRAY_SIZE(isi_formats)];
1010 unsigned int num_fmts = 0, i, j;
1011 struct v4l2_subdev *subdev = isi->entity.subdev;
1012 struct v4l2_subdev_mbus_code_enum mbus_code = {
1013 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
1014 };
1015
1016 while (!v4l2_subdev_call(subdev, pad, enum_mbus_code,
1017 NULL, &mbus_code)) {
1018 for (i = 0; i < ARRAY_SIZE(isi_formats); i++) {
1019 if (isi_formats[i].mbus_code != mbus_code.code)
1020 continue;
1021
1022 /* Code supported, have we got this fourcc yet? */
1023 for (j = 0; j < num_fmts; j++)
1024 if (isi_fmts[j]->fourcc == isi_formats[i].fourcc)
1025 /* Already available */
1026 break;
1027 if (j == num_fmts)
1028 /* new */
1029 isi_fmts[num_fmts++] = isi_formats + i;
1030 }
1031 mbus_code.index++;
1032 }
1033
1034 if (!num_fmts)
1035 return -ENXIO;
1036
1037 isi->num_user_formats = num_fmts;
1038 isi->user_formats = devm_kcalloc(isi->dev,
1039 num_fmts, sizeof(struct isi_format *),
1040 GFP_KERNEL);
Markus Elfringc38e8652017-08-28 05:46:57 -04001041 if (!isi->user_formats)
Hans Verkuild12c9082016-08-16 16:56:43 -03001042 return -ENOMEM;
Hans Verkuild12c9082016-08-16 16:56:43 -03001043
1044 memcpy(isi->user_formats, isi_fmts,
1045 num_fmts * sizeof(struct isi_format *));
1046 isi->current_fmt = isi->user_formats[0];
1047
1048 return 0;
1049}
1050
1051static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
1052{
1053 struct atmel_isi *isi = notifier_to_isi(notifier);
1054 int ret;
1055
Hugues Fruchetec62c9a2017-05-19 07:04:52 -03001056 isi->vdev->ctrl_handler = isi->entity.subdev->ctrl_handler;
Hans Verkuild12c9082016-08-16 16:56:43 -03001057 ret = isi_formats_init(isi);
1058 if (ret) {
1059 dev_err(isi->dev, "No supported mediabus format found\n");
1060 return ret;
1061 }
1062 isi_camera_set_bus_param(isi);
1063
1064 ret = isi_set_default_fmt(isi);
1065 if (ret) {
1066 dev_err(isi->dev, "Could not set default format\n");
1067 return ret;
1068 }
1069
1070 ret = video_register_device(isi->vdev, VFL_TYPE_GRABBER, -1);
1071 if (ret) {
1072 dev_err(isi->dev, "Failed to register video device\n");
1073 return ret;
1074 }
1075
1076 dev_dbg(isi->dev, "Device registered as %s\n",
1077 video_device_node_name(isi->vdev));
1078 return 0;
1079}
1080
1081static void isi_graph_notify_unbind(struct v4l2_async_notifier *notifier,
1082 struct v4l2_subdev *sd,
1083 struct v4l2_async_subdev *asd)
1084{
1085 struct atmel_isi *isi = notifier_to_isi(notifier);
1086
1087 dev_dbg(isi->dev, "Removing %s\n", video_device_node_name(isi->vdev));
1088
1089 /* Checks internaly if vdev have been init or not */
1090 video_unregister_device(isi->vdev);
1091}
1092
1093static int isi_graph_notify_bound(struct v4l2_async_notifier *notifier,
1094 struct v4l2_subdev *subdev,
1095 struct v4l2_async_subdev *asd)
1096{
1097 struct atmel_isi *isi = notifier_to_isi(notifier);
1098
1099 dev_dbg(isi->dev, "subdev %s bound\n", subdev->name);
1100
1101 isi->entity.subdev = subdev;
1102
1103 return 0;
1104}
1105
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -04001106static const struct v4l2_async_notifier_operations isi_graph_notify_ops = {
1107 .bound = isi_graph_notify_bound,
1108 .unbind = isi_graph_notify_unbind,
1109 .complete = isi_graph_notify_complete,
1110};
1111
Hans Verkuild12c9082016-08-16 16:56:43 -03001112static int isi_graph_parse(struct atmel_isi *isi, struct device_node *node)
1113{
1114 struct device_node *ep = NULL;
1115 struct device_node *remote;
1116
1117 while (1) {
1118 ep = of_graph_get_next_endpoint(node, ep);
1119 if (!ep)
1120 return -EINVAL;
1121
1122 remote = of_graph_get_remote_port_parent(ep);
1123 if (!remote) {
1124 of_node_put(ep);
1125 return -EINVAL;
1126 }
1127
1128 /* Remote node to connect */
1129 isi->entity.node = remote;
Sakari Ailus859969b2016-08-26 20:17:25 -03001130 isi->entity.asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
Mauro Carvalho Chehab4e48afe2017-09-27 10:12:00 -04001131 isi->entity.asd.match.fwnode = of_fwnode_handle(remote);
Hans Verkuild12c9082016-08-16 16:56:43 -03001132 return 0;
1133 }
1134}
1135
1136static int isi_graph_init(struct atmel_isi *isi)
1137{
1138 struct v4l2_async_subdev **subdevs = NULL;
1139 int ret;
1140
1141 /* Parse the graph to extract a list of subdevice DT nodes. */
1142 ret = isi_graph_parse(isi, isi->dev->of_node);
1143 if (ret < 0) {
1144 dev_err(isi->dev, "Graph parsing failed\n");
1145 return ret;
1146 }
1147
1148 /* Register the subdevices notifier. */
1149 subdevs = devm_kzalloc(isi->dev, sizeof(*subdevs), GFP_KERNEL);
Markus Elfringaf28c992017-08-28 06:50:28 -04001150 if (!subdevs) {
Hans Verkuild12c9082016-08-16 16:56:43 -03001151 of_node_put(isi->entity.node);
1152 return -ENOMEM;
1153 }
1154
1155 subdevs[0] = &isi->entity.asd;
1156
1157 isi->notifier.subdevs = subdevs;
1158 isi->notifier.num_subdevs = 1;
Laurent Pinchartb6ee3f02017-08-30 13:18:04 -04001159 isi->notifier.ops = &isi_graph_notify_ops;
Hans Verkuild12c9082016-08-16 16:56:43 -03001160
1161 ret = v4l2_async_notifier_register(&isi->v4l2_dev, &isi->notifier);
1162 if (ret < 0) {
1163 dev_err(isi->dev, "Notifier registration failed\n");
1164 of_node_put(isi->entity.node);
1165 return ret;
1166 }
1167
1168 return 0;
1169}
1170
1171
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001172static int atmel_isi_probe(struct platform_device *pdev)
Josh Wu195ebc42011-06-07 22:40:19 -03001173{
Guenter Roeck0724745f2016-02-09 12:43:42 -02001174 int irq;
Josh Wu195ebc42011-06-07 22:40:19 -03001175 struct atmel_isi *isi;
Hans Verkuild12c9082016-08-16 16:56:43 -03001176 struct vb2_queue *q;
Josh Wu195ebc42011-06-07 22:40:19 -03001177 struct resource *regs;
1178 int ret, i;
Josh Wu195ebc42011-06-07 22:40:19 -03001179
Laurent Pinchartc52c0cb2013-11-25 12:13:50 -03001180 isi = devm_kzalloc(&pdev->dev, sizeof(struct atmel_isi), GFP_KERNEL);
Markus Elfringc38e8652017-08-28 05:46:57 -04001181 if (!isi)
Laurent Pinchartc52c0cb2013-11-25 12:13:50 -03001182 return -ENOMEM;
Josh Wu195ebc42011-06-07 22:40:19 -03001183
Laurent Pinchartc52c0cb2013-11-25 12:13:50 -03001184 isi->pclk = devm_clk_get(&pdev->dev, "isi_clk");
1185 if (IS_ERR(isi->pclk))
1186 return PTR_ERR(isi->pclk);
1187
Laurent Pinchart40a78f32015-08-01 06:22:54 -03001188 ret = atmel_isi_parse_dt(isi, pdev);
1189 if (ret)
1190 return ret;
Josh Wu8ff19bc2014-07-28 04:25:17 -03001191
Josh Wu195ebc42011-06-07 22:40:19 -03001192 isi->active = NULL;
Hans Verkuild12c9082016-08-16 16:56:43 -03001193 isi->dev = &pdev->dev;
1194 mutex_init(&isi->lock);
1195 spin_lock_init(&isi->irqlock);
Josh Wu195ebc42011-06-07 22:40:19 -03001196 INIT_LIST_HEAD(&isi->video_buffer_list);
1197 INIT_LIST_HEAD(&isi->dma_desc_head);
1198
Hans Verkuild12c9082016-08-16 16:56:43 -03001199 q = &isi->queue;
1200
1201 /* Initialize the top-level structure */
1202 ret = v4l2_device_register(&pdev->dev, &isi->v4l2_dev);
1203 if (ret)
1204 return ret;
1205
1206 isi->vdev = video_device_alloc();
Markus Elfringaf28c992017-08-28 06:50:28 -04001207 if (!isi->vdev) {
Hans Verkuild12c9082016-08-16 16:56:43 -03001208 ret = -ENOMEM;
1209 goto err_vdev_alloc;
1210 }
1211
1212 /* video node */
1213 isi->vdev->fops = &isi_fops;
1214 isi->vdev->v4l2_dev = &isi->v4l2_dev;
1215 isi->vdev->queue = &isi->queue;
1216 strlcpy(isi->vdev->name, KBUILD_MODNAME, sizeof(isi->vdev->name));
1217 isi->vdev->release = video_device_release;
1218 isi->vdev->ioctl_ops = &isi_ioctl_ops;
1219 isi->vdev->lock = &isi->lock;
1220 isi->vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
1221 V4L2_CAP_READWRITE;
1222 video_set_drvdata(isi->vdev, isi);
1223
1224 /* buffer queue */
1225 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1226 q->io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF;
1227 q->lock = &isi->lock;
1228 q->drv_priv = isi;
1229 q->buf_struct_size = sizeof(struct frame_buffer);
1230 q->ops = &isi_video_qops;
1231 q->mem_ops = &vb2_dma_contig_memops;
1232 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1233 q->min_buffers_needed = 2;
1234 q->dev = &pdev->dev;
1235
1236 ret = vb2_queue_init(q);
1237 if (ret < 0) {
1238 dev_err(&pdev->dev, "failed to initialize VB2 queue\n");
1239 goto err_vb2_queue;
1240 }
Josh Wu195ebc42011-06-07 22:40:19 -03001241 isi->p_fb_descriptors = dma_alloc_coherent(&pdev->dev,
Hans Verkuild12c9082016-08-16 16:56:43 -03001242 sizeof(struct fbd) * VIDEO_MAX_FRAME,
Josh Wu195ebc42011-06-07 22:40:19 -03001243 &isi->fb_descriptors_phys,
1244 GFP_KERNEL);
1245 if (!isi->p_fb_descriptors) {
Josh Wu195ebc42011-06-07 22:40:19 -03001246 dev_err(&pdev->dev, "Can't allocate descriptors!\n");
Hans Verkuild12c9082016-08-16 16:56:43 -03001247 ret = -ENOMEM;
1248 goto err_dma_alloc;
Josh Wu195ebc42011-06-07 22:40:19 -03001249 }
1250
Hans Verkuild12c9082016-08-16 16:56:43 -03001251 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
Josh Wu195ebc42011-06-07 22:40:19 -03001252 isi->dma_desc[i].p_fbd = isi->p_fb_descriptors + i;
1253 isi->dma_desc[i].fbd_phys = isi->fb_descriptors_phys +
1254 i * sizeof(struct fbd);
1255 list_add(&isi->dma_desc[i].list, &isi->dma_desc_head);
1256 }
1257
Laurent Pinchartc52c0cb2013-11-25 12:13:50 -03001258 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1259 isi->regs = devm_ioremap_resource(&pdev->dev, regs);
1260 if (IS_ERR(isi->regs)) {
1261 ret = PTR_ERR(isi->regs);
Josh Wu195ebc42011-06-07 22:40:19 -03001262 goto err_ioremap;
1263 }
1264
Josh Wu833e1062014-07-25 07:13:39 -03001265 if (isi->pdata.data_width_flags & ISI_DATAWIDTH_8)
Guennadi Liakhovetskia4e9f102011-07-27 12:18:37 -03001266 isi->width_flags = 1 << 7;
Josh Wu833e1062014-07-25 07:13:39 -03001267 if (isi->pdata.data_width_flags & ISI_DATAWIDTH_10)
Guennadi Liakhovetskia4e9f102011-07-27 12:18:37 -03001268 isi->width_flags |= 1 << 9;
1269
Josh Wu195ebc42011-06-07 22:40:19 -03001270 irq = platform_get_irq(pdev, 0);
Guenter Roeck0724745f2016-02-09 12:43:42 -02001271 if (irq < 0) {
Josh Wu195ebc42011-06-07 22:40:19 -03001272 ret = irq;
1273 goto err_req_irq;
1274 }
1275
Laurent Pinchartc52c0cb2013-11-25 12:13:50 -03001276 ret = devm_request_irq(&pdev->dev, irq, isi_interrupt, 0, "isi", isi);
Josh Wu195ebc42011-06-07 22:40:19 -03001277 if (ret) {
1278 dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
1279 goto err_req_irq;
1280 }
1281 isi->irq = irq;
1282
Hans Verkuild12c9082016-08-16 16:56:43 -03001283 ret = isi_graph_init(isi);
1284 if (ret < 0)
1285 goto err_req_irq;
Josh Wu195ebc42011-06-07 22:40:19 -03001286
Josh Wuf3745a3a2015-05-26 06:54:46 -03001287 pm_suspend_ignore_children(&pdev->dev, true);
1288 pm_runtime_enable(&pdev->dev);
Hans Verkuild12c9082016-08-16 16:56:43 -03001289 platform_set_drvdata(pdev, isi);
Josh Wu195ebc42011-06-07 22:40:19 -03001290 return 0;
1291
Josh Wu195ebc42011-06-07 22:40:19 -03001292err_req_irq:
Josh Wu195ebc42011-06-07 22:40:19 -03001293err_ioremap:
Josh Wu195ebc42011-06-07 22:40:19 -03001294 dma_free_coherent(&pdev->dev,
Hans Verkuild12c9082016-08-16 16:56:43 -03001295 sizeof(struct fbd) * VIDEO_MAX_FRAME,
Josh Wu195ebc42011-06-07 22:40:19 -03001296 isi->p_fb_descriptors,
1297 isi->fb_descriptors_phys);
Hans Verkuild12c9082016-08-16 16:56:43 -03001298err_dma_alloc:
1299err_vb2_queue:
1300 video_device_release(isi->vdev);
1301err_vdev_alloc:
1302 v4l2_device_unregister(&isi->v4l2_dev);
Josh Wu195ebc42011-06-07 22:40:19 -03001303
1304 return ret;
1305}
1306
Hans Verkuild12c9082016-08-16 16:56:43 -03001307static int atmel_isi_remove(struct platform_device *pdev)
1308{
1309 struct atmel_isi *isi = platform_get_drvdata(pdev);
1310
1311 dma_free_coherent(&pdev->dev,
1312 sizeof(struct fbd) * VIDEO_MAX_FRAME,
1313 isi->p_fb_descriptors,
1314 isi->fb_descriptors_phys);
1315 pm_runtime_disable(&pdev->dev);
1316 v4l2_async_notifier_unregister(&isi->notifier);
1317 v4l2_device_unregister(&isi->v4l2_dev);
1318
1319 return 0;
1320}
1321
Geert Uytterhoeven18baba62015-09-06 07:08:49 -03001322#ifdef CONFIG_PM
Josh Wuf3745a3a2015-05-26 06:54:46 -03001323static int atmel_isi_runtime_suspend(struct device *dev)
1324{
Hans Verkuild12c9082016-08-16 16:56:43 -03001325 struct atmel_isi *isi = dev_get_drvdata(dev);
Josh Wuf3745a3a2015-05-26 06:54:46 -03001326
1327 clk_disable_unprepare(isi->pclk);
1328
1329 return 0;
1330}
1331static int atmel_isi_runtime_resume(struct device *dev)
1332{
Hans Verkuild12c9082016-08-16 16:56:43 -03001333 struct atmel_isi *isi = dev_get_drvdata(dev);
Josh Wuf3745a3a2015-05-26 06:54:46 -03001334
1335 return clk_prepare_enable(isi->pclk);
1336}
Geert Uytterhoeven18baba62015-09-06 07:08:49 -03001337#endif /* CONFIG_PM */
Josh Wuf3745a3a2015-05-26 06:54:46 -03001338
1339static const struct dev_pm_ops atmel_isi_dev_pm_ops = {
1340 SET_RUNTIME_PM_OPS(atmel_isi_runtime_suspend,
1341 atmel_isi_runtime_resume, NULL)
1342};
1343
Josh Wu8ff19bc2014-07-28 04:25:17 -03001344static const struct of_device_id atmel_isi_of_match[] = {
1345 { .compatible = "atmel,at91sam9g45-isi" },
1346 { }
1347};
1348MODULE_DEVICE_TABLE(of, atmel_isi_of_match);
1349
Josh Wu195ebc42011-06-07 22:40:19 -03001350static struct platform_driver atmel_isi_driver = {
Josh Wu195ebc42011-06-07 22:40:19 -03001351 .driver = {
1352 .name = "atmel_isi",
Josh Wu8ff19bc2014-07-28 04:25:17 -03001353 .of_match_table = of_match_ptr(atmel_isi_of_match),
Josh Wuf3745a3a2015-05-26 06:54:46 -03001354 .pm = &atmel_isi_dev_pm_ops,
Josh Wu195ebc42011-06-07 22:40:19 -03001355 },
Hans Verkuild12c9082016-08-16 16:56:43 -03001356 .probe = atmel_isi_probe,
1357 .remove = atmel_isi_remove,
Josh Wu195ebc42011-06-07 22:40:19 -03001358};
1359
Hans Verkuild12c9082016-08-16 16:56:43 -03001360module_platform_driver(atmel_isi_driver);
Josh Wu195ebc42011-06-07 22:40:19 -03001361
1362MODULE_AUTHOR("Josh Wu <josh.wu@atmel.com>");
1363MODULE_DESCRIPTION("The V4L2 driver for Atmel Linux");
1364MODULE_LICENSE("GPL");
1365MODULE_SUPPORTED_DEVICE("video");