1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2016 NextThing Co
4 * Copyright (C) 2016-2019 Bootlin
6 * Author: Maxime Ripard <maxime.ripard@bootlin.com>
12 #include <media/media-device.h>
13 #include <media/v4l2-async.h>
14 #include <media/v4l2-dev.h>
15 #include <media/v4l2-device.h>
16 #include <media/v4l2-fwnode.h>
17 #include <media/videobuf2-core.h>
19 #define CSI_EN_REG 0x00
21 #define CSI_CFG_REG 0x04
22 #define CSI_CFG_INPUT_FMT(fmt) ((fmt) << 20)
23 #define CSI_CFG_OUTPUT_FMT(fmt) ((fmt) << 16)
24 #define CSI_CFG_YUV_DATA_SEQ(seq) ((seq) << 8)
25 #define CSI_CFG_VREF_POL(pol) ((pol) << 2)
26 #define CSI_CFG_HREF_POL(pol) ((pol) << 1)
27 #define CSI_CFG_PCLK_POL(pol) ((pol) << 0)
29 #define CSI_CPT_CTRL_REG 0x08
30 #define CSI_CPT_CTRL_VIDEO_START BIT(1)
31 #define CSI_CPT_CTRL_IMAGE_START BIT(0)
33 #define CSI_BUF_ADDR_REG(fifo, buf) (0x10 + (0x8 * (fifo)) + (0x4 * (buf)))
35 #define CSI_BUF_CTRL_REG 0x28
36 #define CSI_BUF_CTRL_DBN BIT(2)
37 #define CSI_BUF_CTRL_DBS BIT(1)
38 #define CSI_BUF_CTRL_DBE BIT(0)
40 #define CSI_INT_EN_REG 0x30
41 #define CSI_INT_FRM_DONE BIT(1)
42 #define CSI_INT_CPT_DONE BIT(0)
44 #define CSI_INT_STA_REG 0x34
46 #define CSI_WIN_CTRL_W_REG 0x40
47 #define CSI_WIN_CTRL_W_ACTIVE(w) ((w) << 16)
49 #define CSI_WIN_CTRL_H_REG 0x44
50 #define CSI_WIN_CTRL_H_ACTIVE(h) ((h) << 16)
52 #define CSI_BUF_LEN_REG 0x48
54 #define CSI_MAX_BUFFER 2
55 #define CSI_MAX_HEIGHT 8192U
56 #define CSI_MAX_WIDTH 8192U
65 CSI_OUTPUT_RAW_PASSTHROUGH
= 0,
69 CSI_OUTPUT_YUV_422_PLANAR
= 0,
70 CSI_OUTPUT_YUV_420_PLANAR
= 1,
71 CSI_OUTPUT_YUV_422_UV
= 4,
72 CSI_OUTPUT_YUV_420_UV
= 5,
73 CSI_OUTPUT_YUV_422_MACRO
= 8,
74 CSI_OUTPUT_YUV_420_MACRO
= 9,
77 enum csi_yuv_data_seq
{
78 CSI_YUV_DATA_SEQ_YUYV
= 0,
79 CSI_YUV_DATA_SEQ_YVYU
= 1,
80 CSI_YUV_DATA_SEQ_UYVY
= 2,
81 CSI_YUV_DATA_SEQ_VYUY
= 3,
84 enum csi_subdev_pads
{
91 extern const struct v4l2_subdev_ops sun4i_csi_subdev_ops
;
93 struct sun4i_csi_format
{
98 unsigned int num_planes
;
104 const struct sun4i_csi_format
*sun4i_csi_find_format(const u32
*fourcc
,
108 /* Device resources */
111 const struct sun4i_csi_traits
*traits
;
117 struct reset_control
*rst
;
119 struct vb2_v4l2_buffer
*current_buf
[CSI_MAX_BUFFER
];
127 struct v4l2_fwnode_bus_parallel bus
;
130 struct v4l2_device v4l
;
131 struct media_device mdev
;
132 struct video_device vdev
;
133 struct media_pad vdev_pad
;
134 struct v4l2_pix_format_mplane fmt
;
137 struct v4l2_subdev subdev
;
138 struct media_pad subdev_pads
[CSI_SUBDEV_PADS
];
139 struct v4l2_mbus_framefmt subdev_fmt
;
141 /* V4L2 Async variables */
142 struct v4l2_async_subdev asd
;
143 struct v4l2_async_notifier notifier
;
144 struct v4l2_subdev
*src_subdev
;
151 struct vb2_queue queue
;
152 struct list_head buf_list
;
154 unsigned int sequence
;
157 int sun4i_csi_dma_register(struct sun4i_csi
*csi
, int irq
);
158 void sun4i_csi_dma_unregister(struct sun4i_csi
*csi
);
160 int sun4i_csi_v4l2_register(struct sun4i_csi
*csi
);
162 #endif /* _SUN4I_CSI_H_ */