20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/slab.h>
30 #define MAX_BUFFER_NUM 32
31 #define MAX_SUPPORT_WIDTH 2048
32 #define MAX_SUPPORT_HEIGHT 2048
33 #define VID_LIMIT_BYTES (16 * 1024 * 1024)
34 #define MIN_FRAME_RATE 15
35 #define FRAME_INTERVAL_MILLI_SEC (1000 / MIN_FRAME_RATE)
54 static void set_dma_ctrl(
struct fbd *fb_desc,
u32 ctrl)
168 list_del_init(&buf->
list);
181 isi->
active->p_dma_desc->fbd_phys);
196 spin_lock(&isi->
lock);
200 pending = status &
mask;
218 ret = atmel_isi_handle_streaming(isi);
221 spin_unlock(&isi->
lock);
225 #define WAIT_ISI_RESET 1
226 #define WAIT_ISI_DISABLE 0
227 static int atmel_isi_wait_status(
struct atmel_isi *isi,
int wait_reset)
237 isi_writel(isi,
ISI_INTEN, ISI_CTRL_SRST);
238 isi_writel(isi,
ISI_CTRL, ISI_CTRL_SRST);
240 isi_writel(isi,
ISI_INTEN, ISI_CTRL_DIS);
241 isi_writel(isi,
ISI_CTRL, ISI_CTRL_DIS);
256 unsigned int *nbuffers,
unsigned int *nplanes,
257 unsigned int sizes[],
void *alloc_ctxs[])
300 INIT_LIST_HEAD(&buf->
list);
316 if (vb2_plane_size(vb, 0) < size) {
317 dev_err(icd->
parent,
"%s data will not fit into plane (%lu < %lu)\n",
318 __func__, vb2_plane_size(vb, 0), size);
322 vb2_set_plane_payload(&buf->
vb, 0, size);
333 list_del_init(&desc->
list);
336 desc->
p_fbd->fb_address =
337 vb2_dma_contig_plane_dma_addr(vb, 0);
338 desc->
p_fbd->next_fbd_address = 0;
347 static void buffer_cleanup(
struct vb2_buffer *vb)
370 dev_err(isi->
icd->parent,
"Already in frame handling.\n");
387 static void buffer_queue(
struct vb2_buffer *vb)
393 unsigned long flags = 0;
403 spin_unlock_irqrestore(&isi->
lock, flags);
406 static int start_streaming(
struct vb2_queue *vq,
unsigned int count)
415 spin_lock_irq(&isi->
lock);
420 isi_writel(isi,
ISI_INTEN, ISI_SR_VSYNC);
422 spin_unlock_irq(&isi->
lock);
435 spin_lock_irq(&isi->
lock);
439 start_dma(isi, isi->
active);
440 spin_unlock_irq(&isi->
lock);
451 static int stop_streaming(
struct vb2_queue *vq)
460 spin_lock_irq(&isi->
lock);
464 list_del_init(&buf->
list);
467 spin_unlock_irq(&isi->
lock);
477 "Timeout waiting for finishing codec request\n");
493 static struct vb2_ops isi_video_qops = {
496 .buf_prepare = buffer_prepare,
497 .buf_cleanup = buffer_cleanup,
498 .buf_queue = buffer_queue,
508 static int isi_camera_init_videobuf(
struct vb2_queue *
q,
515 q->
ops = &isi_video_qops;
527 const struct soc_camera_format_xlate *
xlate;
529 struct v4l2_mbus_framefmt mf;
542 mf.width = pix->
width;
544 mf.field = pix->
field;
546 mf.code = xlate->code;
552 if (mf.code != xlate->code)
555 ret = configure_geometry(isi, pix->
width, pix->
height, xlate->code);
559 pix->
width = mf.width;
561 pix->
field = mf.field;
574 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
575 const struct soc_camera_format_xlate *xlate;
577 struct v4l2_mbus_framefmt mf;
582 if (pixfmt && !xlate) {
594 mf.width = pix->
width;
596 mf.field = pix->
field;
598 mf.code = xlate->code;
604 pix->
width = mf.width;
626 .name =
"Packed YUV422 16 bit",
627 .bits_per_sample = 8,
644 #define ISI_BUS_PARAM (V4L2_MBUS_MASTER | \
645 V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
646 V4L2_MBUS_HSYNC_ACTIVE_LOW | \
647 V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
648 V4L2_MBUS_VSYNC_ACTIVE_LOW | \
649 V4L2_MBUS_PCLK_SAMPLE_RISING | \
650 V4L2_MBUS_PCLK_SAMPLE_FALLING | \
651 V4L2_MBUS_DATA_ACTIVE_HIGH)
656 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
669 "Flags incompatible: camera 0x%x, host 0x%x\n",
685 struct soc_camera_format_xlate *xlate)
687 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
702 "Invalid format code #%u: %d\n", idx, code);
710 "Fail to try the bus parameters.\n");
721 xlate->host_fmt = &isi_camera_formats[0];
725 isi_camera_formats[0].
name, code);
729 if (!isi_camera_packing_supported(fmt))
733 "Providing format %s in pass-through mode\n",
740 xlate->host_fmt =
fmt;
769 dev_dbg(icd->
parent,
"Atmel ISI Camera driver attached to camera %d\n",
785 dev_dbg(icd->
parent,
"Atmel ISI Camera driver detached from camera %d\n",
800 strcpy(cap->
card,
"Atmel Image Sensor Interface");
808 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
822 "Flags incompatible: camera 0x%x, host 0x%x\n",
831 dev_dbg(icd->
parent,
"Flags cam: 0x%x host: 0x%x common: 0x%lx\n",
837 if (isi->
pdata->hsync_act_low)
838 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
840 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
845 if (isi->
pdata->vsync_act_low)
846 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
848 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
853 if (isi->
pdata->pclk_act_falling)
854 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
856 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
862 dev_dbg(icd->
parent,
"camera s_mbus_config(0x%lx) returned %d\n",
868 if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
870 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
872 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
875 if (isi->
pdata->has_emb_sync)
877 if (isi->
pdata->full_mode)
880 isi_writel(isi,
ISI_CTRL, ISI_CTRL_DIS);
888 .add = isi_camera_add_device,
889 .remove = isi_camera_remove_device,
890 .set_fmt = isi_camera_set_fmt,
891 .try_fmt = isi_camera_try_fmt,
892 .get_formats = isi_camera_get_formats,
893 .init_videobuf2 = isi_camera_init_videobuf,
894 .poll = isi_camera_poll,
895 .querycap = isi_camera_querycap,
896 .set_bus_param = isi_camera_set_bus_param,
938 "No config available for Atmel ISI\n");
948 return PTR_ERR(pclk);
952 goto err_clk_prepare_pclk;
957 dev_err(&pdev->
dev,
"Can't allocate interface!\n");
971 if (IS_ERR(isi->
mck)) {
972 dev_err(dev,
"Failed to get isi_mck\n");
973 ret = PTR_ERR(isi->
mck);
979 goto err_clk_prepare_mck;
984 goto err_set_mck_rate;
992 dev_err(&pdev->
dev,
"Can't allocate descriptors!\n");
993 goto err_alloc_descriptors;
999 i *
sizeof(
struct fbd);
1020 isi_writel(isi,
ISI_CTRL, ISI_CTRL_DIS);
1028 ret =
request_irq(irq, isi_interrupt, 0,
"isi", isi);
1030 dev_err(&pdev->
dev,
"Unable to request irq %d\n", irq);
1037 soc_host->
ops = &isi_soc_camera_host_ops;
1038 soc_host->
priv = isi;
1040 soc_host->
nr = pdev->
id;
1044 dev_err(&pdev->
dev,
"Unable to register soc camera host\n");
1045 goto err_register_soc_camera_host;
1049 err_register_soc_camera_host:
1057 sizeof(
struct fbd) * MAX_BUFFER_NUM,
1060 err_alloc_descriptors:
1063 err_clk_prepare_mck:
1069 err_clk_prepare_pclk:
1076 .probe = atmel_isi_probe,
1079 .name =
"atmel_isi",
1084 static int __init atmel_isi_init_module(
void)
1089 static void __exit atmel_isi_exit(
void)