0001
0002
0003
0004
0005
0006 #ifndef __TEGRA_VI_H__
0007 #define __TEGRA_VI_H__
0008
0009 #include <linux/host1x.h>
0010 #include <linux/list.h>
0011
0012 #include <linux/mutex.h>
0013 #include <linux/spinlock.h>
0014 #include <linux/wait.h>
0015
0016 #include <media/media-entity.h>
0017 #include <media/v4l2-async.h>
0018 #include <media/v4l2-ctrls.h>
0019 #include <media/v4l2-device.h>
0020 #include <media/v4l2-dev.h>
0021 #include <media/v4l2-subdev.h>
0022 #include <media/videobuf2-v4l2.h>
0023
0024 #include "csi.h"
0025
0026 #define V4L2_CID_TEGRA_SYNCPT_TIMEOUT_RETRY (V4L2_CTRL_CLASS_CAMERA | 0x1001)
0027
0028 #define TEGRA_MIN_WIDTH 32U
0029 #define TEGRA_MAX_WIDTH 32768U
0030 #define TEGRA_MIN_HEIGHT 32U
0031 #define TEGRA_MAX_HEIGHT 32768U
0032
0033 #define TEGRA_DEF_WIDTH 1920
0034 #define TEGRA_DEF_HEIGHT 1080
0035 #define TEGRA_IMAGE_FORMAT_DEF 32
0036
0037 #define MAX_FORMAT_NUM 64
0038 #define SURFACE_ALIGN_BYTES 64
0039
0040 enum tegra_vi_pg_mode {
0041 TEGRA_VI_PG_DISABLED = 0,
0042 TEGRA_VI_PG_DIRECT,
0043 TEGRA_VI_PG_PATCH,
0044 };
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 struct tegra_vi_ops {
0055 int (*vi_start_streaming)(struct vb2_queue *vq, u32 count);
0056 void (*vi_stop_streaming)(struct vb2_queue *vq);
0057 };
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 struct tegra_vi_soc {
0070 const struct tegra_video_format *video_formats;
0071 const unsigned int nformats;
0072 const struct tegra_vi_ops *ops;
0073 u32 hw_revision;
0074 unsigned int vi_max_channels;
0075 unsigned int vi_max_clk_hz;
0076 };
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 struct tegra_vi {
0091 struct device *dev;
0092 struct host1x_client client;
0093 void __iomem *iomem;
0094 struct clk *clk;
0095 struct regulator *vdd;
0096 const struct tegra_vi_soc *soc;
0097 const struct tegra_vi_ops *ops;
0098 struct list_head vi_chans;
0099 };
0100
0101
0102
0103
0104
0105
0106
0107
0108 struct tegra_vi_graph_entity {
0109 struct v4l2_async_subdev asd;
0110 struct media_entity *entity;
0111 struct v4l2_subdev *subdev;
0112 };
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171 struct tegra_vi_channel {
0172 struct list_head list;
0173 struct video_device video;
0174
0175 struct mutex video_lock;
0176 struct media_pad pad;
0177
0178 struct tegra_vi *vi;
0179 struct host1x_syncpt *frame_start_sp[GANG_PORTS_MAX];
0180 struct host1x_syncpt *mw_ack_sp[GANG_PORTS_MAX];
0181
0182 spinlock_t sp_incr_lock[GANG_PORTS_MAX];
0183
0184 struct task_struct *kthread_start_capture;
0185 wait_queue_head_t start_wait;
0186 struct task_struct *kthread_finish_capture;
0187 wait_queue_head_t done_wait;
0188
0189 struct v4l2_pix_format format;
0190 const struct tegra_video_format *fmtinfo;
0191 struct vb2_queue queue;
0192 u32 sequence;
0193
0194 struct list_head capture;
0195
0196 spinlock_t start_lock;
0197 struct list_head done;
0198
0199 spinlock_t done_lock;
0200
0201 unsigned char portnos[GANG_PORTS_MAX];
0202 u8 totalports;
0203 u8 numgangports;
0204 struct device_node *of_node;
0205
0206 struct v4l2_ctrl_handler ctrl_handler;
0207 unsigned int syncpt_timeout_retry;
0208 DECLARE_BITMAP(fmts_bitmap, MAX_FORMAT_NUM);
0209 DECLARE_BITMAP(tpg_fmts_bitmap, MAX_FORMAT_NUM);
0210 enum tegra_vi_pg_mode pg_mode;
0211
0212 struct v4l2_async_notifier notifier;
0213 };
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225 struct tegra_channel_buffer {
0226 struct vb2_v4l2_buffer buf;
0227 struct list_head queue;
0228 struct tegra_vi_channel *chan;
0229 dma_addr_t addr;
0230 u32 mw_ack_sp_thresh[GANG_PORTS_MAX];
0231 };
0232
0233
0234
0235
0236
0237
0238 enum tegra_image_dt {
0239 TEGRA_IMAGE_DT_YUV420_8 = 24,
0240 TEGRA_IMAGE_DT_YUV420_10,
0241
0242 TEGRA_IMAGE_DT_YUV420CSPS_8 = 28,
0243 TEGRA_IMAGE_DT_YUV420CSPS_10,
0244 TEGRA_IMAGE_DT_YUV422_8,
0245 TEGRA_IMAGE_DT_YUV422_10,
0246 TEGRA_IMAGE_DT_RGB444,
0247 TEGRA_IMAGE_DT_RGB555,
0248 TEGRA_IMAGE_DT_RGB565,
0249 TEGRA_IMAGE_DT_RGB666,
0250 TEGRA_IMAGE_DT_RGB888,
0251
0252 TEGRA_IMAGE_DT_RAW6 = 40,
0253 TEGRA_IMAGE_DT_RAW7,
0254 TEGRA_IMAGE_DT_RAW8,
0255 TEGRA_IMAGE_DT_RAW10,
0256 TEGRA_IMAGE_DT_RAW12,
0257 TEGRA_IMAGE_DT_RAW14,
0258 };
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270 struct tegra_video_format {
0271 enum tegra_image_dt img_dt;
0272 unsigned int bit_width;
0273 unsigned int code;
0274 unsigned int bpp;
0275 u32 img_fmt;
0276 u32 fourcc;
0277 };
0278
0279 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
0280 extern const struct tegra_vi_soc tegra210_vi_soc;
0281 #endif
0282
0283 struct v4l2_subdev *
0284 tegra_channel_get_remote_csi_subdev(struct tegra_vi_channel *chan);
0285 struct v4l2_subdev *
0286 tegra_channel_get_remote_source_subdev(struct tegra_vi_channel *chan);
0287 int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on);
0288 void tegra_channel_release_buffers(struct tegra_vi_channel *chan,
0289 enum vb2_buffer_state state);
0290 void tegra_channels_cleanup(struct tegra_vi *vi);
0291 #endif