2 * Atmel Image Sensor Controller (ISC) driver
4 * Copyright (C) 2016 Atmel
6 * Author: Songjun Wu <songjun.wu@microchip.com>
8 * This program is free software; you may redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * Sensor-->PFE-->WB-->CFA-->CC-->GAM-->CSC-->CBC-->SUB-->RLP-->DMA
14 * ISC video pipeline integrates the following submodules:
15 * PFE: Parallel Front End to sample the camera sensor input stream
16 * WB: Programmable white balance in the Bayer domain
17 * CFA: Color filter array interpolation module
18 * CC: Programmable color correction
19 * GAM: Gamma correction
20 * CSC: Programmable color space conversion
21 * CBC: Contrast and Brightness control
22 * SUB: This module performs YCbCr444 to YCbCr420 chrominance subsampling
23 * RLP: This module performs rounding, range limiting
24 * and packing of the incoming data
27 #include <linux/clk.h>
28 #include <linux/clkdev.h>
29 #include <linux/clk-provider.h>
30 #include <linux/delay.h>
31 #include <linux/interrupt.h>
32 #include <linux/module.h>
34 #include <linux/platform_device.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/regmap.h>
37 #include <linux/videodev2.h>
39 #include <media/v4l2-device.h>
40 #include <media/v4l2-image-sizes.h>
41 #include <media/v4l2-ioctl.h>
42 #include <media/v4l2-of.h>
43 #include <media/v4l2-subdev.h>
44 #include <media/videobuf2-dma-contig.h>
46 #include "atmel-isc-regs.h"
48 #define ATMEL_ISC_NAME "atmel_isc"
50 #define ISC_MAX_SUPPORT_WIDTH 2592
51 #define ISC_MAX_SUPPORT_HEIGHT 1944
53 #define ISC_CLK_MAX_DIV 255
63 struct regmap
*regmap
;
70 #define to_isc_clk(hw) container_of(hw, struct isc_clk, hw)
73 struct vb2_v4l2_buffer vb
;
74 struct list_head list
;
77 struct isc_subdev_entity
{
78 struct v4l2_subdev
*sd
;
79 struct v4l2_async_subdev
*asd
;
80 struct v4l2_async_notifier notifier
;
81 struct v4l2_subdev_pad_config
*config
;
85 struct list_head list
;
89 * struct isc_format - ISC media bus format information
90 * @fourcc: Fourcc code for this format
91 * @mbus_code: V4L2 media bus format code.
92 * @bpp: Bytes per pixel (when stored in memory)
93 * @reg_bps: reg value for bits per sample
94 * (when transferred over a bus)
95 * @support: Indicates format supported by subdev
110 #define ISC_PIPE_LINE_NODE_NUM 11
113 struct regmap
*regmap
;
116 struct isc_clk isc_clks
[2];
119 struct v4l2_device v4l2_dev
;
120 struct video_device video_dev
;
122 struct vb2_queue vb2_vidq
;
123 spinlock_t dma_queue_lock
;
124 struct list_head dma_queue
;
125 struct isc_buffer
*cur_frm
;
126 unsigned int sequence
;
128 struct completion comp
;
130 struct v4l2_format fmt
;
131 struct isc_format
**user_formats
;
132 unsigned int num_user_formats
;
133 const struct isc_format
*current_fmt
;
137 struct regmap_field
*pipeline
[ISC_PIPE_LINE_NODE_NUM
];
139 struct isc_subdev_entity
*current_subdev
;
140 struct list_head subdev_entities
;
143 static struct isc_format isc_formats
[] = {
144 { V4L2_PIX_FMT_SBGGR8
, MEDIA_BUS_FMT_SBGGR8_1X8
,
145 1, ISC_PFE_CFG0_BPS_EIGHT
, ISC_RLP_CFG_MODE_DAT8
,
146 ISC_DCFG_IMODE_PACKED8
, ISC_DCTRL_DVIEW_PACKED
, false },
147 { V4L2_PIX_FMT_SGBRG8
, MEDIA_BUS_FMT_SGBRG8_1X8
,
148 1, ISC_PFE_CFG0_BPS_EIGHT
, ISC_RLP_CFG_MODE_DAT8
,
149 ISC_DCFG_IMODE_PACKED8
, ISC_DCTRL_DVIEW_PACKED
, false },
150 { V4L2_PIX_FMT_SGRBG8
, MEDIA_BUS_FMT_SGRBG8_1X8
,
151 1, ISC_PFE_CFG0_BPS_EIGHT
, ISC_RLP_CFG_MODE_DAT8
,
152 ISC_DCFG_IMODE_PACKED8
, ISC_DCTRL_DVIEW_PACKED
, false },
153 { V4L2_PIX_FMT_SRGGB8
, MEDIA_BUS_FMT_SRGGB8_1X8
,
154 1, ISC_PFE_CFG0_BPS_EIGHT
, ISC_RLP_CFG_MODE_DAT8
,
155 ISC_DCFG_IMODE_PACKED8
, ISC_DCTRL_DVIEW_PACKED
, false },
157 { V4L2_PIX_FMT_SBGGR10
, MEDIA_BUS_FMT_SBGGR10_1X10
,
158 2, ISC_PFG_CFG0_BPS_TEN
, ISC_RLP_CFG_MODE_DAT10
,
159 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
160 { V4L2_PIX_FMT_SGBRG10
, MEDIA_BUS_FMT_SGBRG10_1X10
,
161 2, ISC_PFG_CFG0_BPS_TEN
, ISC_RLP_CFG_MODE_DAT10
,
162 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
163 { V4L2_PIX_FMT_SGRBG10
, MEDIA_BUS_FMT_SGRBG10_1X10
,
164 2, ISC_PFG_CFG0_BPS_TEN
, ISC_RLP_CFG_MODE_DAT10
,
165 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
166 { V4L2_PIX_FMT_SRGGB10
, MEDIA_BUS_FMT_SRGGB10_1X10
,
167 2, ISC_PFG_CFG0_BPS_TEN
, ISC_RLP_CFG_MODE_DAT10
,
168 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
170 { V4L2_PIX_FMT_SBGGR12
, MEDIA_BUS_FMT_SBGGR12_1X12
,
171 2, ISC_PFG_CFG0_BPS_TWELVE
, ISC_RLP_CFG_MODE_DAT12
,
172 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
173 { V4L2_PIX_FMT_SGBRG12
, MEDIA_BUS_FMT_SGBRG12_1X12
,
174 2, ISC_PFG_CFG0_BPS_TWELVE
, ISC_RLP_CFG_MODE_DAT12
,
175 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
176 { V4L2_PIX_FMT_SGRBG12
, MEDIA_BUS_FMT_SGRBG12_1X12
,
177 2, ISC_PFG_CFG0_BPS_TWELVE
, ISC_RLP_CFG_MODE_DAT12
,
178 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
179 { V4L2_PIX_FMT_SRGGB12
, MEDIA_BUS_FMT_SRGGB12_1X12
,
180 2, ISC_PFG_CFG0_BPS_TWELVE
, ISC_RLP_CFG_MODE_DAT12
,
181 ISC_DCFG_IMODE_PACKED16
, ISC_DCTRL_DVIEW_PACKED
, false },
183 { V4L2_PIX_FMT_YUYV
, MEDIA_BUS_FMT_YUYV8_2X8
,
184 2, ISC_PFE_CFG0_BPS_EIGHT
, ISC_RLP_CFG_MODE_DAT8
,
185 ISC_DCFG_IMODE_PACKED8
, ISC_DCTRL_DVIEW_PACKED
, false },
188 static int isc_clk_enable(struct clk_hw
*hw
)
190 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
191 u32 id
= isc_clk
->id
;
192 struct regmap
*regmap
= isc_clk
->regmap
;
194 dev_dbg(isc_clk
->dev
, "ISC CLK: %s, div = %d, parent id = %d\n",
195 __func__
, isc_clk
->div
, isc_clk
->parent_id
);
197 regmap_update_bits(regmap
, ISC_CLKCFG
,
198 ISC_CLKCFG_DIV_MASK(id
) | ISC_CLKCFG_SEL_MASK(id
),
199 (isc_clk
->div
<< ISC_CLKCFG_DIV_SHIFT(id
)) |
200 (isc_clk
->parent_id
<< ISC_CLKCFG_SEL_SHIFT(id
)));
202 regmap_write(regmap
, ISC_CLKEN
, ISC_CLK(id
));
207 static void isc_clk_disable(struct clk_hw
*hw
)
209 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
210 u32 id
= isc_clk
->id
;
212 regmap_write(isc_clk
->regmap
, ISC_CLKDIS
, ISC_CLK(id
));
215 static int isc_clk_is_enabled(struct clk_hw
*hw
)
217 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
220 regmap_read(isc_clk
->regmap
, ISC_CLKSR
, &status
);
222 return status
& ISC_CLK(isc_clk
->id
) ? 1 : 0;
226 isc_clk_recalc_rate(struct clk_hw
*hw
, unsigned long parent_rate
)
228 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
230 return DIV_ROUND_CLOSEST(parent_rate
, isc_clk
->div
+ 1);
233 static int isc_clk_determine_rate(struct clk_hw
*hw
,
234 struct clk_rate_request
*req
)
236 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
237 long best_rate
= -EINVAL
;
241 for (i
= 0; i
< clk_hw_get_num_parents(hw
); i
++) {
242 struct clk_hw
*parent
;
243 unsigned long parent_rate
;
245 parent
= clk_hw_get_parent_by_index(hw
, i
);
249 parent_rate
= clk_hw_get_rate(parent
);
253 for (div
= 1; div
< ISC_CLK_MAX_DIV
+ 2; div
++) {
257 rate
= DIV_ROUND_CLOSEST(parent_rate
, div
);
258 diff
= abs(req
->rate
- rate
);
260 if (best_diff
< 0 || best_diff
> diff
) {
263 req
->best_parent_rate
= parent_rate
;
264 req
->best_parent_hw
= parent
;
267 if (!best_diff
|| rate
< req
->rate
)
275 dev_dbg(isc_clk
->dev
,
276 "ISC CLK: %s, best_rate = %ld, parent clk: %s @ %ld\n",
278 __clk_get_name((req
->best_parent_hw
)->clk
),
279 req
->best_parent_rate
);
284 req
->rate
= best_rate
;
289 static int isc_clk_set_parent(struct clk_hw
*hw
, u8 index
)
291 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
293 if (index
>= clk_hw_get_num_parents(hw
))
296 isc_clk
->parent_id
= index
;
301 static u8
isc_clk_get_parent(struct clk_hw
*hw
)
303 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
305 return isc_clk
->parent_id
;
308 static int isc_clk_set_rate(struct clk_hw
*hw
,
310 unsigned long parent_rate
)
312 struct isc_clk
*isc_clk
= to_isc_clk(hw
);
318 div
= DIV_ROUND_CLOSEST(parent_rate
, rate
);
319 if (div
> (ISC_CLK_MAX_DIV
+ 1) || !div
)
322 isc_clk
->div
= div
- 1;
327 static const struct clk_ops isc_clk_ops
= {
328 .enable
= isc_clk_enable
,
329 .disable
= isc_clk_disable
,
330 .is_enabled
= isc_clk_is_enabled
,
331 .recalc_rate
= isc_clk_recalc_rate
,
332 .determine_rate
= isc_clk_determine_rate
,
333 .set_parent
= isc_clk_set_parent
,
334 .get_parent
= isc_clk_get_parent
,
335 .set_rate
= isc_clk_set_rate
,
338 static int isc_clk_register(struct isc_device
*isc
, unsigned int id
)
340 struct regmap
*regmap
= isc
->regmap
;
341 struct device_node
*np
= isc
->dev
->of_node
;
342 struct isc_clk
*isc_clk
;
343 struct clk_init_data init
;
344 const char *clk_name
= np
->name
;
345 const char *parent_names
[3];
348 num_parents
= of_clk_get_parent_count(np
);
349 if (num_parents
< 1 || num_parents
> 3)
352 if (num_parents
> 2 && id
== ISC_ISPCK
)
355 of_clk_parent_fill(np
, parent_names
, num_parents
);
358 of_property_read_string(np
, "clock-output-names", &clk_name
);
360 clk_name
= "isc-ispck";
362 init
.parent_names
= parent_names
;
363 init
.num_parents
= num_parents
;
364 init
.name
= clk_name
;
365 init
.ops
= &isc_clk_ops
;
366 init
.flags
= CLK_SET_RATE_GATE
| CLK_SET_PARENT_GATE
;
368 isc_clk
= &isc
->isc_clks
[id
];
369 isc_clk
->hw
.init
= &init
;
370 isc_clk
->regmap
= regmap
;
372 isc_clk
->dev
= isc
->dev
;
374 isc_clk
->clk
= clk_register(isc
->dev
, &isc_clk
->hw
);
375 if (IS_ERR(isc_clk
->clk
)) {
376 dev_err(isc
->dev
, "%s: clock register fail\n", clk_name
);
377 return PTR_ERR(isc_clk
->clk
);
378 } else if (id
== ISC_MCK
)
379 of_clk_add_provider(np
, of_clk_src_simple_get
, isc_clk
->clk
);
384 static int isc_clk_init(struct isc_device
*isc
)
389 for (i
= 0; i
< ARRAY_SIZE(isc
->isc_clks
); i
++)
390 isc
->isc_clks
[i
].clk
= ERR_PTR(-EINVAL
);
392 for (i
= 0; i
< ARRAY_SIZE(isc
->isc_clks
); i
++) {
393 ret
= isc_clk_register(isc
, i
);
401 static void isc_clk_cleanup(struct isc_device
*isc
)
405 of_clk_del_provider(isc
->dev
->of_node
);
407 for (i
= 0; i
< ARRAY_SIZE(isc
->isc_clks
); i
++) {
408 struct isc_clk
*isc_clk
= &isc
->isc_clks
[i
];
410 if (!IS_ERR(isc_clk
->clk
))
411 clk_unregister(isc_clk
->clk
);
415 static int isc_queue_setup(struct vb2_queue
*vq
,
416 unsigned int *nbuffers
, unsigned int *nplanes
,
417 unsigned int sizes
[], struct device
*alloc_devs
[])
419 struct isc_device
*isc
= vb2_get_drv_priv(vq
);
420 unsigned int size
= isc
->fmt
.fmt
.pix
.sizeimage
;
423 return sizes
[0] < size
? -EINVAL
: 0;
431 static int isc_buffer_prepare(struct vb2_buffer
*vb
)
433 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
434 struct isc_device
*isc
= vb2_get_drv_priv(vb
->vb2_queue
);
435 unsigned long size
= isc
->fmt
.fmt
.pix
.sizeimage
;
437 if (vb2_plane_size(vb
, 0) < size
) {
438 v4l2_err(&isc
->v4l2_dev
, "buffer too small (%lu < %lu)\n",
439 vb2_plane_size(vb
, 0), size
);
443 vb2_set_plane_payload(vb
, 0, size
);
445 vbuf
->field
= isc
->fmt
.fmt
.pix
.field
;
450 static inline void isc_start_dma(struct regmap
*regmap
,
451 struct isc_buffer
*frm
, u32 dview
)
455 addr
= vb2_dma_contig_plane_dma_addr(&frm
->vb
.vb2_buf
, 0);
457 regmap_write(regmap
, ISC_DCTRL
, dview
| ISC_DCTRL_IE_IS
);
458 regmap_write(regmap
, ISC_DAD0
, addr
);
459 regmap_write(regmap
, ISC_CTRLEN
, ISC_CTRL_CAPTURE
);
462 static void isc_set_pipeline(struct isc_device
*isc
, u32 pipeline
)
467 for (i
= 0; i
< ISC_PIPE_LINE_NODE_NUM
; i
++) {
468 val
= pipeline
& BIT(i
) ? 1 : 0;
469 regmap_field_write(isc
->pipeline
[i
], val
);
473 static int isc_configure(struct isc_device
*isc
)
475 struct regmap
*regmap
= isc
->regmap
;
476 const struct isc_format
*current_fmt
= isc
->current_fmt
;
477 struct isc_subdev_entity
*subdev
= isc
->current_subdev
;
481 val
= current_fmt
->reg_bps
| subdev
->pfe_cfg0
|
482 ISC_PFE_CFG0_MODE_PROGRESSIVE
;
483 mask
= ISC_PFE_CFG0_BPS_MASK
| ISC_PFE_CFG0_HPOL_LOW
|
484 ISC_PFE_CFG0_VPOL_LOW
| ISC_PFE_CFG0_PPOL_LOW
|
485 ISC_PFE_CFG0_MODE_MASK
;
487 regmap_update_bits(regmap
, ISC_PFE_CFG0
, mask
, val
);
489 regmap_update_bits(regmap
, ISC_RLP_CFG
, ISC_RLP_CFG_MODE_MASK
,
490 current_fmt
->reg_rlp_mode
);
492 regmap_update_bits(regmap
, ISC_DCFG
, ISC_DCFG_IMODE_MASK
,
493 current_fmt
->reg_dcfg_imode
);
495 /* Disable the pipeline */
496 isc_set_pipeline(isc
, 0x0);
499 regmap_write(regmap
, ISC_CTRLEN
, ISC_CTRL_UPPRO
);
501 regmap_read(regmap
, ISC_CTRLSR
, &val
);
502 while ((val
& ISC_CTRL_UPPRO
) && counter
--) {
503 usleep_range(1000, 2000);
504 regmap_read(regmap
, ISC_CTRLSR
, &val
);
513 static int isc_start_streaming(struct vb2_queue
*vq
, unsigned int count
)
515 struct isc_device
*isc
= vb2_get_drv_priv(vq
);
516 struct regmap
*regmap
= isc
->regmap
;
517 struct isc_buffer
*buf
;
522 /* Enable stream on the sub device */
523 ret
= v4l2_subdev_call(isc
->current_subdev
->sd
, video
, s_stream
, 1);
524 if (ret
&& ret
!= -ENOIOCTLCMD
) {
525 v4l2_err(&isc
->v4l2_dev
, "stream on failed in subdev\n");
526 goto err_start_stream
;
529 pm_runtime_get_sync(isc
->dev
);
531 /* Disable all the interrupts */
532 regmap_write(isc
->regmap
, ISC_INTDIS
, (u32
)~0UL);
534 /* Clean the interrupt status register */
535 regmap_read(regmap
, ISC_INTSR
, &val
);
537 ret
= isc_configure(isc
);
541 /* Enable DMA interrupt */
542 regmap_write(regmap
, ISC_INTEN
, ISC_INT_DDONE
);
544 spin_lock_irqsave(&isc
->dma_queue_lock
, flags
);
548 reinit_completion(&isc
->comp
);
550 isc
->cur_frm
= list_first_entry(&isc
->dma_queue
,
551 struct isc_buffer
, list
);
552 list_del(&isc
->cur_frm
->list
);
554 isc_start_dma(regmap
, isc
->cur_frm
, isc
->current_fmt
->reg_dctrl_dview
);
556 spin_unlock_irqrestore(&isc
->dma_queue_lock
, flags
);
561 pm_runtime_put_sync(isc
->dev
);
563 v4l2_subdev_call(isc
->current_subdev
->sd
, video
, s_stream
, 0);
566 spin_lock_irqsave(&isc
->dma_queue_lock
, flags
);
567 list_for_each_entry(buf
, &isc
->dma_queue
, list
)
568 vb2_buffer_done(&buf
->vb
.vb2_buf
, VB2_BUF_STATE_QUEUED
);
569 INIT_LIST_HEAD(&isc
->dma_queue
);
570 spin_unlock_irqrestore(&isc
->dma_queue_lock
, flags
);
575 static void isc_stop_streaming(struct vb2_queue
*vq
)
577 struct isc_device
*isc
= vb2_get_drv_priv(vq
);
579 struct isc_buffer
*buf
;
584 /* Wait until the end of the current frame */
585 if (isc
->cur_frm
&& !wait_for_completion_timeout(&isc
->comp
, 5 * HZ
))
586 v4l2_err(&isc
->v4l2_dev
,
587 "Timeout waiting for end of the capture\n");
589 /* Disable DMA interrupt */
590 regmap_write(isc
->regmap
, ISC_INTDIS
, ISC_INT_DDONE
);
592 pm_runtime_put_sync(isc
->dev
);
594 /* Disable stream on the sub device */
595 ret
= v4l2_subdev_call(isc
->current_subdev
->sd
, video
, s_stream
, 0);
596 if (ret
&& ret
!= -ENOIOCTLCMD
)
597 v4l2_err(&isc
->v4l2_dev
, "stream off failed in subdev\n");
599 /* Release all active buffers */
600 spin_lock_irqsave(&isc
->dma_queue_lock
, flags
);
601 if (unlikely(isc
->cur_frm
)) {
602 vb2_buffer_done(&isc
->cur_frm
->vb
.vb2_buf
,
603 VB2_BUF_STATE_ERROR
);
606 list_for_each_entry(buf
, &isc
->dma_queue
, list
)
607 vb2_buffer_done(&buf
->vb
.vb2_buf
, VB2_BUF_STATE_ERROR
);
608 INIT_LIST_HEAD(&isc
->dma_queue
);
609 spin_unlock_irqrestore(&isc
->dma_queue_lock
, flags
);
612 static void isc_buffer_queue(struct vb2_buffer
*vb
)
614 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
615 struct isc_buffer
*buf
= container_of(vbuf
, struct isc_buffer
, vb
);
616 struct isc_device
*isc
= vb2_get_drv_priv(vb
->vb2_queue
);
619 spin_lock_irqsave(&isc
->dma_queue_lock
, flags
);
620 list_add_tail(&buf
->list
, &isc
->dma_queue
);
621 spin_unlock_irqrestore(&isc
->dma_queue_lock
, flags
);
624 static struct vb2_ops isc_vb2_ops
= {
625 .queue_setup
= isc_queue_setup
,
626 .wait_prepare
= vb2_ops_wait_prepare
,
627 .wait_finish
= vb2_ops_wait_finish
,
628 .buf_prepare
= isc_buffer_prepare
,
629 .start_streaming
= isc_start_streaming
,
630 .stop_streaming
= isc_stop_streaming
,
631 .buf_queue
= isc_buffer_queue
,
634 static int isc_querycap(struct file
*file
, void *priv
,
635 struct v4l2_capability
*cap
)
637 struct isc_device
*isc
= video_drvdata(file
);
639 strcpy(cap
->driver
, ATMEL_ISC_NAME
);
640 strcpy(cap
->card
, "Atmel Image Sensor Controller");
641 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
),
642 "platform:%s", isc
->v4l2_dev
.name
);
647 static int isc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
648 struct v4l2_fmtdesc
*f
)
650 struct isc_device
*isc
= video_drvdata(file
);
651 u32 index
= f
->index
;
653 if (index
>= isc
->num_user_formats
)
656 f
->pixelformat
= isc
->user_formats
[index
]->fourcc
;
661 static int isc_g_fmt_vid_cap(struct file
*file
, void *priv
,
662 struct v4l2_format
*fmt
)
664 struct isc_device
*isc
= video_drvdata(file
);
671 static struct isc_format
*find_format_by_fourcc(struct isc_device
*isc
,
674 unsigned int num_formats
= isc
->num_user_formats
;
675 struct isc_format
*fmt
;
678 for (i
= 0; i
< num_formats
; i
++) {
679 fmt
= isc
->user_formats
[i
];
680 if (fmt
->fourcc
== fourcc
)
687 static int isc_try_fmt(struct isc_device
*isc
, struct v4l2_format
*f
,
688 struct isc_format
**current_fmt
)
690 struct isc_format
*isc_fmt
;
691 struct v4l2_pix_format
*pixfmt
= &f
->fmt
.pix
;
692 struct v4l2_subdev_format format
= {
693 .which
= V4L2_SUBDEV_FORMAT_TRY
,
697 if (f
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
700 isc_fmt
= find_format_by_fourcc(isc
, pixfmt
->pixelformat
);
702 v4l2_warn(&isc
->v4l2_dev
, "Format 0x%x not found\n",
703 pixfmt
->pixelformat
);
704 isc_fmt
= isc
->user_formats
[isc
->num_user_formats
- 1];
705 pixfmt
->pixelformat
= isc_fmt
->fourcc
;
708 /* Limit to Atmel ISC hardware capabilities */
709 if (pixfmt
->width
> ISC_MAX_SUPPORT_WIDTH
)
710 pixfmt
->width
= ISC_MAX_SUPPORT_WIDTH
;
711 if (pixfmt
->height
> ISC_MAX_SUPPORT_HEIGHT
)
712 pixfmt
->height
= ISC_MAX_SUPPORT_HEIGHT
;
714 v4l2_fill_mbus_format(&format
.format
, pixfmt
, isc_fmt
->mbus_code
);
715 ret
= v4l2_subdev_call(isc
->current_subdev
->sd
, pad
, set_fmt
,
716 isc
->current_subdev
->config
, &format
);
720 v4l2_fill_pix_format(pixfmt
, &format
.format
);
722 pixfmt
->field
= V4L2_FIELD_NONE
;
723 pixfmt
->bytesperline
= pixfmt
->width
* isc_fmt
->bpp
;
724 pixfmt
->sizeimage
= pixfmt
->bytesperline
* pixfmt
->height
;
727 *current_fmt
= isc_fmt
;
732 static int isc_set_fmt(struct isc_device
*isc
, struct v4l2_format
*f
)
734 struct v4l2_subdev_format format
= {
735 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
737 struct isc_format
*current_fmt
;
740 ret
= isc_try_fmt(isc
, f
, ¤t_fmt
);
744 v4l2_fill_mbus_format(&format
.format
, &f
->fmt
.pix
,
745 current_fmt
->mbus_code
);
746 ret
= v4l2_subdev_call(isc
->current_subdev
->sd
, pad
,
747 set_fmt
, NULL
, &format
);
752 isc
->current_fmt
= current_fmt
;
757 static int isc_s_fmt_vid_cap(struct file
*file
, void *priv
,
758 struct v4l2_format
*f
)
760 struct isc_device
*isc
= video_drvdata(file
);
762 if (vb2_is_streaming(&isc
->vb2_vidq
))
765 return isc_set_fmt(isc
, f
);
768 static int isc_try_fmt_vid_cap(struct file
*file
, void *priv
,
769 struct v4l2_format
*f
)
771 struct isc_device
*isc
= video_drvdata(file
);
773 return isc_try_fmt(isc
, f
, NULL
);
776 static int isc_enum_input(struct file
*file
, void *priv
,
777 struct v4l2_input
*inp
)
782 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
784 strcpy(inp
->name
, "Camera");
789 static int isc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
796 static int isc_s_input(struct file
*file
, void *priv
, unsigned int i
)
804 static int isc_g_parm(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
806 struct isc_device
*isc
= video_drvdata(file
);
808 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
811 return v4l2_subdev_call(isc
->current_subdev
->sd
, video
, g_parm
, a
);
814 static int isc_s_parm(struct file
*file
, void *fh
, struct v4l2_streamparm
*a
)
816 struct isc_device
*isc
= video_drvdata(file
);
818 if (a
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
821 return v4l2_subdev_call(isc
->current_subdev
->sd
, video
, s_parm
, a
);
824 static int isc_enum_framesizes(struct file
*file
, void *fh
,
825 struct v4l2_frmsizeenum
*fsize
)
827 struct isc_device
*isc
= video_drvdata(file
);
828 const struct isc_format
*isc_fmt
;
829 struct v4l2_subdev_frame_size_enum fse
= {
830 .index
= fsize
->index
,
831 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
835 isc_fmt
= find_format_by_fourcc(isc
, fsize
->pixel_format
);
839 fse
.code
= isc_fmt
->mbus_code
;
841 ret
= v4l2_subdev_call(isc
->current_subdev
->sd
, pad
, enum_frame_size
,
846 fsize
->type
= V4L2_FRMSIZE_TYPE_DISCRETE
;
847 fsize
->discrete
.width
= fse
.max_width
;
848 fsize
->discrete
.height
= fse
.max_height
;
853 static int isc_enum_frameintervals(struct file
*file
, void *fh
,
854 struct v4l2_frmivalenum
*fival
)
856 struct isc_device
*isc
= video_drvdata(file
);
857 const struct isc_format
*isc_fmt
;
858 struct v4l2_subdev_frame_interval_enum fie
= {
859 .index
= fival
->index
,
860 .width
= fival
->width
,
861 .height
= fival
->height
,
862 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
866 isc_fmt
= find_format_by_fourcc(isc
, fival
->pixel_format
);
870 fie
.code
= isc_fmt
->mbus_code
;
872 ret
= v4l2_subdev_call(isc
->current_subdev
->sd
, pad
,
873 enum_frame_interval
, NULL
, &fie
);
877 fival
->type
= V4L2_FRMIVAL_TYPE_DISCRETE
;
878 fival
->discrete
= fie
.interval
;
883 static const struct v4l2_ioctl_ops isc_ioctl_ops
= {
884 .vidioc_querycap
= isc_querycap
,
885 .vidioc_enum_fmt_vid_cap
= isc_enum_fmt_vid_cap
,
886 .vidioc_g_fmt_vid_cap
= isc_g_fmt_vid_cap
,
887 .vidioc_s_fmt_vid_cap
= isc_s_fmt_vid_cap
,
888 .vidioc_try_fmt_vid_cap
= isc_try_fmt_vid_cap
,
890 .vidioc_enum_input
= isc_enum_input
,
891 .vidioc_g_input
= isc_g_input
,
892 .vidioc_s_input
= isc_s_input
,
894 .vidioc_reqbufs
= vb2_ioctl_reqbufs
,
895 .vidioc_querybuf
= vb2_ioctl_querybuf
,
896 .vidioc_qbuf
= vb2_ioctl_qbuf
,
897 .vidioc_expbuf
= vb2_ioctl_expbuf
,
898 .vidioc_dqbuf
= vb2_ioctl_dqbuf
,
899 .vidioc_create_bufs
= vb2_ioctl_create_bufs
,
900 .vidioc_prepare_buf
= vb2_ioctl_prepare_buf
,
901 .vidioc_streamon
= vb2_ioctl_streamon
,
902 .vidioc_streamoff
= vb2_ioctl_streamoff
,
904 .vidioc_g_parm
= isc_g_parm
,
905 .vidioc_s_parm
= isc_s_parm
,
906 .vidioc_enum_framesizes
= isc_enum_framesizes
,
907 .vidioc_enum_frameintervals
= isc_enum_frameintervals
,
910 static int isc_open(struct file
*file
)
912 struct isc_device
*isc
= video_drvdata(file
);
913 struct v4l2_subdev
*sd
= isc
->current_subdev
->sd
;
916 if (mutex_lock_interruptible(&isc
->lock
))
919 ret
= v4l2_fh_open(file
);
923 if (!v4l2_fh_is_singular_file(file
))
926 ret
= v4l2_subdev_call(sd
, core
, s_power
, 1);
927 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
928 v4l2_fh_release(file
);
933 mutex_unlock(&isc
->lock
);
937 static int isc_release(struct file
*file
)
939 struct isc_device
*isc
= video_drvdata(file
);
940 struct v4l2_subdev
*sd
= isc
->current_subdev
->sd
;
944 mutex_lock(&isc
->lock
);
946 fh_singular
= v4l2_fh_is_singular_file(file
);
948 ret
= _vb2_fop_release(file
, NULL
);
951 v4l2_subdev_call(sd
, core
, s_power
, 0);
953 mutex_unlock(&isc
->lock
);
958 static const struct v4l2_file_operations isc_fops
= {
959 .owner
= THIS_MODULE
,
961 .release
= isc_release
,
962 .unlocked_ioctl
= video_ioctl2
,
963 .read
= vb2_fop_read
,
964 .mmap
= vb2_fop_mmap
,
965 .poll
= vb2_fop_poll
,
968 static irqreturn_t
isc_interrupt(int irq
, void *dev_id
)
970 struct isc_device
*isc
= (struct isc_device
*)dev_id
;
971 struct regmap
*regmap
= isc
->regmap
;
972 u32 isc_intsr
, isc_intmask
, pending
;
973 irqreturn_t ret
= IRQ_NONE
;
975 spin_lock(&isc
->dma_queue_lock
);
977 regmap_read(regmap
, ISC_INTSR
, &isc_intsr
);
978 regmap_read(regmap
, ISC_INTMASK
, &isc_intmask
);
980 pending
= isc_intsr
& isc_intmask
;
982 if (likely(pending
& ISC_INT_DDONE
)) {
984 struct vb2_v4l2_buffer
*vbuf
= &isc
->cur_frm
->vb
;
985 struct vb2_buffer
*vb
= &vbuf
->vb2_buf
;
987 vb
->timestamp
= ktime_get_ns();
988 vbuf
->sequence
= isc
->sequence
++;
989 vb2_buffer_done(vb
, VB2_BUF_STATE_DONE
);
993 if (!list_empty(&isc
->dma_queue
) && !isc
->stop
) {
994 isc
->cur_frm
= list_first_entry(&isc
->dma_queue
,
995 struct isc_buffer
, list
);
996 list_del(&isc
->cur_frm
->list
);
998 isc_start_dma(regmap
, isc
->cur_frm
,
999 isc
->current_fmt
->reg_dctrl_dview
);
1003 complete(&isc
->comp
);
1008 spin_unlock(&isc
->dma_queue_lock
);
1013 static int isc_async_bound(struct v4l2_async_notifier
*notifier
,
1014 struct v4l2_subdev
*subdev
,
1015 struct v4l2_async_subdev
*asd
)
1017 struct isc_device
*isc
= container_of(notifier
->v4l2_dev
,
1018 struct isc_device
, v4l2_dev
);
1019 struct isc_subdev_entity
*subdev_entity
=
1020 container_of(notifier
, struct isc_subdev_entity
, notifier
);
1022 if (video_is_registered(&isc
->video_dev
)) {
1023 v4l2_err(&isc
->v4l2_dev
, "only supports one sub-device.\n");
1027 subdev_entity
->sd
= subdev
;
1032 static void isc_async_unbind(struct v4l2_async_notifier
*notifier
,
1033 struct v4l2_subdev
*subdev
,
1034 struct v4l2_async_subdev
*asd
)
1036 struct isc_device
*isc
= container_of(notifier
->v4l2_dev
,
1037 struct isc_device
, v4l2_dev
);
1039 video_unregister_device(&isc
->video_dev
);
1040 if (isc
->current_subdev
->config
)
1041 v4l2_subdev_free_pad_config(isc
->current_subdev
->config
);
1044 static struct isc_format
*find_format_by_code(unsigned int code
, int *index
)
1046 struct isc_format
*fmt
= &isc_formats
[0];
1049 for (i
= 0; i
< ARRAY_SIZE(isc_formats
); i
++) {
1050 if (fmt
->mbus_code
== code
) {
1061 static int isc_formats_init(struct isc_device
*isc
)
1063 struct isc_format
*fmt
;
1064 struct v4l2_subdev
*subdev
= isc
->current_subdev
->sd
;
1065 int num_fmts
= 0, i
, j
;
1066 struct v4l2_subdev_mbus_code_enum mbus_code
= {
1067 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
1070 fmt
= &isc_formats
[0];
1071 for (i
= 0; i
< ARRAY_SIZE(isc_formats
); i
++) {
1072 fmt
->support
= false;
1076 while (!v4l2_subdev_call(subdev
, pad
, enum_mbus_code
,
1077 NULL
, &mbus_code
)) {
1079 fmt
= find_format_by_code(mbus_code
.code
, &i
);
1083 fmt
->support
= true;
1090 isc
->num_user_formats
= num_fmts
;
1091 isc
->user_formats
= devm_kcalloc(isc
->dev
,
1092 num_fmts
, sizeof(struct isc_format
*),
1094 if (!isc
->user_formats
) {
1095 v4l2_err(&isc
->v4l2_dev
, "could not allocate memory\n");
1099 fmt
= &isc_formats
[0];
1100 for (i
= 0, j
= 0; i
< ARRAY_SIZE(isc_formats
); i
++) {
1102 isc
->user_formats
[j
++] = fmt
;
1110 static int isc_set_default_fmt(struct isc_device
*isc
)
1112 struct v4l2_format f
= {
1113 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
1116 .height
= VGA_HEIGHT
,
1117 .field
= V4L2_FIELD_NONE
,
1118 .pixelformat
= isc
->user_formats
[0]->fourcc
,
1122 return isc_set_fmt(isc
, &f
);
1125 static int isc_async_complete(struct v4l2_async_notifier
*notifier
)
1127 struct isc_device
*isc
= container_of(notifier
->v4l2_dev
,
1128 struct isc_device
, v4l2_dev
);
1129 struct isc_subdev_entity
*sd_entity
;
1130 struct video_device
*vdev
= &isc
->video_dev
;
1131 struct vb2_queue
*q
= &isc
->vb2_vidq
;
1134 isc
->current_subdev
= container_of(notifier
,
1135 struct isc_subdev_entity
, notifier
);
1136 sd_entity
= isc
->current_subdev
;
1138 mutex_init(&isc
->lock
);
1139 init_completion(&isc
->comp
);
1141 /* Initialize videobuf2 queue */
1142 q
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1143 q
->io_modes
= VB2_MMAP
| VB2_DMABUF
| VB2_READ
;
1145 q
->buf_struct_size
= sizeof(struct isc_buffer
);
1146 q
->ops
= &isc_vb2_ops
;
1147 q
->mem_ops
= &vb2_dma_contig_memops
;
1148 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1149 q
->lock
= &isc
->lock
;
1150 q
->min_buffers_needed
= 1;
1153 ret
= vb2_queue_init(q
);
1155 v4l2_err(&isc
->v4l2_dev
,
1156 "vb2_queue_init() failed: %d\n", ret
);
1160 /* Init video dma queues */
1161 INIT_LIST_HEAD(&isc
->dma_queue
);
1162 spin_lock_init(&isc
->dma_queue_lock
);
1164 sd_entity
->config
= v4l2_subdev_alloc_pad_config(sd_entity
->sd
);
1165 if (sd_entity
->config
== NULL
)
1168 ret
= isc_formats_init(isc
);
1170 v4l2_err(&isc
->v4l2_dev
,
1171 "Init format failed: %d\n", ret
);
1175 ret
= v4l2_subdev_call(sd_entity
->sd
, core
, s_power
, 1);
1176 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
1179 ret
= isc_set_default_fmt(isc
);
1181 v4l2_err(&isc
->v4l2_dev
, "Could not set default format\n");
1185 ret
= v4l2_subdev_call(sd_entity
->sd
, core
, s_power
, 0);
1186 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
1189 /* Register video device */
1190 strlcpy(vdev
->name
, ATMEL_ISC_NAME
, sizeof(vdev
->name
));
1191 vdev
->release
= video_device_release_empty
;
1192 vdev
->fops
= &isc_fops
;
1193 vdev
->ioctl_ops
= &isc_ioctl_ops
;
1194 vdev
->v4l2_dev
= &isc
->v4l2_dev
;
1195 vdev
->vfl_dir
= VFL_DIR_RX
;
1197 vdev
->lock
= &isc
->lock
;
1198 vdev
->ctrl_handler
= isc
->current_subdev
->sd
->ctrl_handler
;
1199 vdev
->device_caps
= V4L2_CAP_STREAMING
| V4L2_CAP_VIDEO_CAPTURE
;
1200 video_set_drvdata(vdev
, isc
);
1202 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1204 v4l2_err(&isc
->v4l2_dev
,
1205 "video_register_device failed: %d\n", ret
);
1212 static void isc_subdev_cleanup(struct isc_device
*isc
)
1214 struct isc_subdev_entity
*subdev_entity
;
1216 list_for_each_entry(subdev_entity
, &isc
->subdev_entities
, list
)
1217 v4l2_async_notifier_unregister(&subdev_entity
->notifier
);
1219 INIT_LIST_HEAD(&isc
->subdev_entities
);
1222 static int isc_pipeline_init(struct isc_device
*isc
)
1224 struct device
*dev
= isc
->dev
;
1225 struct regmap
*regmap
= isc
->regmap
;
1226 struct regmap_field
*regs
;
1229 /* WB-->CFA-->CC-->GAM-->CSC-->CBC-->SUB422-->SUB420 */
1230 const struct reg_field regfields
[ISC_PIPE_LINE_NODE_NUM
] = {
1231 REG_FIELD(ISC_WB_CTRL
, 0, 0),
1232 REG_FIELD(ISC_CFA_CTRL
, 0, 0),
1233 REG_FIELD(ISC_CC_CTRL
, 0, 0),
1234 REG_FIELD(ISC_GAM_CTRL
, 0, 0),
1235 REG_FIELD(ISC_GAM_CTRL
, 1, 1),
1236 REG_FIELD(ISC_GAM_CTRL
, 2, 2),
1237 REG_FIELD(ISC_GAM_CTRL
, 3, 3),
1238 REG_FIELD(ISC_CSC_CTRL
, 0, 0),
1239 REG_FIELD(ISC_CBC_CTRL
, 0, 0),
1240 REG_FIELD(ISC_SUB422_CTRL
, 0, 0),
1241 REG_FIELD(ISC_SUB420_CTRL
, 0, 0),
1244 for (i
= 0; i
< ISC_PIPE_LINE_NODE_NUM
; i
++) {
1245 regs
= devm_regmap_field_alloc(dev
, regmap
, regfields
[i
]);
1247 return PTR_ERR(regs
);
1249 isc
->pipeline
[i
] = regs
;
1255 static int isc_parse_dt(struct device
*dev
, struct isc_device
*isc
)
1257 struct device_node
*np
= dev
->of_node
;
1258 struct device_node
*epn
= NULL
, *rem
;
1259 struct v4l2_of_endpoint v4l2_epn
;
1260 struct isc_subdev_entity
*subdev_entity
;
1264 INIT_LIST_HEAD(&isc
->subdev_entities
);
1267 epn
= of_graph_get_next_endpoint(np
, epn
);
1271 rem
= of_graph_get_remote_port_parent(epn
);
1273 dev_notice(dev
, "Remote device at %s not found\n",
1274 of_node_full_name(epn
));
1278 ret
= v4l2_of_parse_endpoint(epn
, &v4l2_epn
);
1282 dev_err(dev
, "Could not parse the endpoint\n");
1286 subdev_entity
= devm_kzalloc(dev
,
1287 sizeof(*subdev_entity
), GFP_KERNEL
);
1288 if (subdev_entity
== NULL
) {
1294 subdev_entity
->asd
= devm_kzalloc(dev
,
1295 sizeof(*subdev_entity
->asd
), GFP_KERNEL
);
1296 if (subdev_entity
->asd
== NULL
) {
1302 flags
= v4l2_epn
.bus
.parallel
.flags
;
1304 if (flags
& V4L2_MBUS_HSYNC_ACTIVE_LOW
)
1305 subdev_entity
->pfe_cfg0
= ISC_PFE_CFG0_HPOL_LOW
;
1307 if (flags
& V4L2_MBUS_VSYNC_ACTIVE_LOW
)
1308 subdev_entity
->pfe_cfg0
|= ISC_PFE_CFG0_VPOL_LOW
;
1310 if (flags
& V4L2_MBUS_PCLK_SAMPLE_FALLING
)
1311 subdev_entity
->pfe_cfg0
|= ISC_PFE_CFG0_PPOL_LOW
;
1313 subdev_entity
->asd
->match_type
= V4L2_ASYNC_MATCH_OF
;
1314 subdev_entity
->asd
->match
.of
.node
= rem
;
1315 list_add_tail(&subdev_entity
->list
, &isc
->subdev_entities
);
1322 /* regmap configuration */
1323 #define ATMEL_ISC_REG_MAX 0xbfc
1324 static const struct regmap_config isc_regmap_config
= {
1328 .max_register
= ATMEL_ISC_REG_MAX
,
1331 static int atmel_isc_probe(struct platform_device
*pdev
)
1333 struct device
*dev
= &pdev
->dev
;
1334 struct isc_device
*isc
;
1335 struct resource
*res
;
1336 void __iomem
*io_base
;
1337 struct isc_subdev_entity
*subdev_entity
;
1341 isc
= devm_kzalloc(dev
, sizeof(*isc
), GFP_KERNEL
);
1345 platform_set_drvdata(pdev
, isc
);
1348 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1349 io_base
= devm_ioremap_resource(dev
, res
);
1350 if (IS_ERR(io_base
))
1351 return PTR_ERR(io_base
);
1353 isc
->regmap
= devm_regmap_init_mmio(dev
, io_base
, &isc_regmap_config
);
1354 if (IS_ERR(isc
->regmap
)) {
1355 ret
= PTR_ERR(isc
->regmap
);
1356 dev_err(dev
, "failed to init register map: %d\n", ret
);
1360 irq
= platform_get_irq(pdev
, 0);
1361 if (IS_ERR_VALUE(irq
)) {
1363 dev_err(dev
, "failed to get irq: %d\n", ret
);
1367 ret
= devm_request_irq(dev
, irq
, isc_interrupt
, 0,
1368 ATMEL_ISC_NAME
, isc
);
1370 dev_err(dev
, "can't register ISR for IRQ %u (ret=%i)\n",
1375 ret
= isc_pipeline_init(isc
);
1379 isc
->hclock
= devm_clk_get(dev
, "hclock");
1380 if (IS_ERR(isc
->hclock
)) {
1381 ret
= PTR_ERR(isc
->hclock
);
1382 dev_err(dev
, "failed to get hclock: %d\n", ret
);
1386 ret
= isc_clk_init(isc
);
1388 dev_err(dev
, "failed to init isc clock: %d\n", ret
);
1392 isc
->ispck
= isc
->isc_clks
[ISC_ISPCK
].clk
;
1394 /* ispck should be greater or equal to hclock */
1395 ret
= clk_set_rate(isc
->ispck
, clk_get_rate(isc
->hclock
));
1397 dev_err(dev
, "failed to set ispck rate: %d\n", ret
);
1401 ret
= v4l2_device_register(dev
, &isc
->v4l2_dev
);
1403 dev_err(dev
, "unable to register v4l2 device.\n");
1407 ret
= isc_parse_dt(dev
, isc
);
1409 dev_err(dev
, "fail to parse device tree\n");
1410 goto unregister_v4l2_device
;
1413 if (list_empty(&isc
->subdev_entities
)) {
1414 dev_err(dev
, "no subdev found\n");
1415 goto unregister_v4l2_device
;
1418 list_for_each_entry(subdev_entity
, &isc
->subdev_entities
, list
) {
1419 subdev_entity
->notifier
.subdevs
= &subdev_entity
->asd
;
1420 subdev_entity
->notifier
.num_subdevs
= 1;
1421 subdev_entity
->notifier
.bound
= isc_async_bound
;
1422 subdev_entity
->notifier
.unbind
= isc_async_unbind
;
1423 subdev_entity
->notifier
.complete
= isc_async_complete
;
1425 ret
= v4l2_async_notifier_register(&isc
->v4l2_dev
,
1426 &subdev_entity
->notifier
);
1428 dev_err(dev
, "fail to register async notifier\n");
1429 goto cleanup_subdev
;
1432 if (video_is_registered(&isc
->video_dev
))
1436 pm_runtime_enable(dev
);
1441 isc_subdev_cleanup(isc
);
1443 unregister_v4l2_device
:
1444 v4l2_device_unregister(&isc
->v4l2_dev
);
1447 isc_clk_cleanup(isc
);
1452 static int atmel_isc_remove(struct platform_device
*pdev
)
1454 struct isc_device
*isc
= platform_get_drvdata(pdev
);
1456 pm_runtime_disable(&pdev
->dev
);
1458 isc_subdev_cleanup(isc
);
1460 v4l2_device_unregister(&isc
->v4l2_dev
);
1462 isc_clk_cleanup(isc
);
1467 static int isc_runtime_suspend(struct device
*dev
)
1469 struct isc_device
*isc
= dev_get_drvdata(dev
);
1471 clk_disable_unprepare(isc
->ispck
);
1472 clk_disable_unprepare(isc
->hclock
);
1477 static int isc_runtime_resume(struct device
*dev
)
1479 struct isc_device
*isc
= dev_get_drvdata(dev
);
1482 ret
= clk_prepare_enable(isc
->hclock
);
1486 return clk_prepare_enable(isc
->ispck
);
1489 static const struct dev_pm_ops atmel_isc_dev_pm_ops
= {
1490 SET_RUNTIME_PM_OPS(isc_runtime_suspend
, isc_runtime_resume
, NULL
)
1493 static const struct of_device_id atmel_isc_of_match
[] = {
1494 { .compatible
= "atmel,sama5d2-isc" },
1497 MODULE_DEVICE_TABLE(of
, atmel_isc_of_match
);
1499 static struct platform_driver atmel_isc_driver
= {
1500 .probe
= atmel_isc_probe
,
1501 .remove
= atmel_isc_remove
,
1503 .name
= ATMEL_ISC_NAME
,
1504 .pm
= &atmel_isc_dev_pm_ops
,
1505 .of_match_table
= of_match_ptr(atmel_isc_of_match
),
1509 module_platform_driver(atmel_isc_driver
);
1511 MODULE_AUTHOR("Songjun Wu <songjun.wu@microchip.com>");
1512 MODULE_DESCRIPTION("The V4L2 driver for Atmel-ISC");
1513 MODULE_LICENSE("GPL v2");
1514 MODULE_SUPPORTED_DEVICE("video");