blob: 4d8626c468bc1e35c95d1799f3fbbfff49208509 [file] [log] [blame]
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -03001/*
2 * Media Bus API header
3 *
4 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef V4L2_MEDIABUS_H
12#define V4L2_MEDIABUS_H
13
Laurent Pinchart2ef2d5a2010-03-15 19:33:31 -030014#include <linux/v4l2-mediabus.h>
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040015#include <linux/bitops.h>
16
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030017
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030018/* Parallel flags */
19/*
20 * Can the client run in master or in slave mode. By "Master mode" an operation
21 * mode is meant, when the client (e.g., a camera sensor) is producing
22 * horizontal and vertical synchronisation. In "Slave mode" the host is
23 * providing these signals to the slave.
24 */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040025#define V4L2_MBUS_MASTER BIT(0)
26#define V4L2_MBUS_SLAVE BIT(1)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030027/*
28 * Signal polarity flags
29 * Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
30 * V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
31 * configuration of hardware that uses [HV]REF signals
32 */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040033#define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
34#define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
35#define V4L2_MBUS_VSYNC_ACTIVE_HIGH BIT(4)
36#define V4L2_MBUS_VSYNC_ACTIVE_LOW BIT(5)
37#define V4L2_MBUS_PCLK_SAMPLE_RISING BIT(6)
38#define V4L2_MBUS_PCLK_SAMPLE_FALLING BIT(7)
39#define V4L2_MBUS_DATA_ACTIVE_HIGH BIT(8)
40#define V4L2_MBUS_DATA_ACTIVE_LOW BIT(9)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030041/* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040042#define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030043/* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040044#define V4L2_MBUS_FIELD_EVEN_LOW BIT(11)
Lad, Prabhakard1d70aa62013-08-11 02:02:24 -030045/* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040046#define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12)
47#define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030048
49/* Serial flags */
50/* How many lanes the client can use */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040051#define V4L2_MBUS_CSI2_1_LANE BIT(0)
52#define V4L2_MBUS_CSI2_2_LANE BIT(1)
53#define V4L2_MBUS_CSI2_3_LANE BIT(2)
54#define V4L2_MBUS_CSI2_4_LANE BIT(3)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030055/* On which channels it can send video data */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040056#define V4L2_MBUS_CSI2_CHANNEL_0 BIT(4)
57#define V4L2_MBUS_CSI2_CHANNEL_1 BIT(5)
58#define V4L2_MBUS_CSI2_CHANNEL_2 BIT(6)
59#define V4L2_MBUS_CSI2_CHANNEL_3 BIT(7)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030060/* Does it support only continuous or also non-continuous clock mode */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040061#define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK BIT(8)
62#define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(9)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030063
64#define V4L2_MBUS_CSI2_LANES (V4L2_MBUS_CSI2_1_LANE | V4L2_MBUS_CSI2_2_LANE | \
65 V4L2_MBUS_CSI2_3_LANE | V4L2_MBUS_CSI2_4_LANE)
66#define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | V4L2_MBUS_CSI2_CHANNEL_1 | \
67 V4L2_MBUS_CSI2_CHANNEL_2 | V4L2_MBUS_CSI2_CHANNEL_3)
68
69/**
Mauro Carvalho Chehab98d00bd2015-08-22 09:04:46 -030070 * enum v4l2_mbus_type - media bus type
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030071 * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
72 * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
73 * also be used for BT.1120
Sakari Ailus97bbdf02015-02-25 14:39:11 -050074 * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
75 * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030076 * @V4L2_MBUS_CSI2: MIPI CSI-2 serial interface
77 */
78enum v4l2_mbus_type {
79 V4L2_MBUS_PARALLEL,
80 V4L2_MBUS_BT656,
Sakari Ailus97bbdf02015-02-25 14:39:11 -050081 V4L2_MBUS_CSI1,
82 V4L2_MBUS_CCP2,
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030083 V4L2_MBUS_CSI2,
84};
85
86/**
Mauro Carvalho Chehab98d00bd2015-08-22 09:04:46 -030087 * struct v4l2_mbus_config - media bus configuration
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030088 * @type: in: interface type
89 * @flags: in / out: configuration flags, depending on @type
90 */
91struct v4l2_mbus_config {
92 enum v4l2_mbus_type type;
93 unsigned int flags;
94};
95
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -040096/**
97 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
98 * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
99 *
100 * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
101 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
102 */
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300103static inline void v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
104 const struct v4l2_mbus_framefmt *mbus_fmt)
105{
106 pix_fmt->width = mbus_fmt->width;
107 pix_fmt->height = mbus_fmt->height;
108 pix_fmt->field = mbus_fmt->field;
109 pix_fmt->colorspace = mbus_fmt->colorspace;
Hans Verkuil11ff0302014-11-17 09:10:33 -0300110 pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
111 pix_fmt->quantization = mbus_fmt->quantization;
Hans Verkuil74fdcb22015-04-28 08:49:09 -0300112 pix_fmt->xfer_func = mbus_fmt->xfer_func;
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300113}
114
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400115/**
116 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
117 * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
118 * data format code.
119 *
120 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
121 * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
122 * @code: data format code (from &enum v4l2_mbus_pixelcode)
123 */
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300124static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
125 const struct v4l2_pix_format *pix_fmt,
Boris BREZILLON32b32ce2014-11-10 14:28:28 -0300126 u32 code)
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300127{
128 mbus_fmt->width = pix_fmt->width;
129 mbus_fmt->height = pix_fmt->height;
130 mbus_fmt->field = pix_fmt->field;
131 mbus_fmt->colorspace = pix_fmt->colorspace;
Hans Verkuil11ff0302014-11-17 09:10:33 -0300132 mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
133 mbus_fmt->quantization = pix_fmt->quantization;
Hans Verkuil74fdcb22015-04-28 08:49:09 -0300134 mbus_fmt->xfer_func = pix_fmt->xfer_func;
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300135 mbus_fmt->code = code;
136}
137
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400138/**
139 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
140 * v4l2_pix_format_mplane fields from a media bus structure.
141 *
142 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
143 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
144 */
Todor Tomovf1923012017-07-07 04:48:47 -0400145static inline void v4l2_fill_pix_format_mplane(
146 struct v4l2_pix_format_mplane *pix_mp_fmt,
147 const struct v4l2_mbus_framefmt *mbus_fmt)
148{
149 pix_mp_fmt->width = mbus_fmt->width;
150 pix_mp_fmt->height = mbus_fmt->height;
151 pix_mp_fmt->field = mbus_fmt->field;
152 pix_mp_fmt->colorspace = mbus_fmt->colorspace;
153 pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
154 pix_mp_fmt->quantization = mbus_fmt->quantization;
155 pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
156}
157
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400158/**
159 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
160 * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
161 *
162 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
163 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
164 */
Todor Tomovf1923012017-07-07 04:48:47 -0400165static inline void v4l2_fill_mbus_format_mplane(
166 struct v4l2_mbus_framefmt *mbus_fmt,
167 const struct v4l2_pix_format_mplane *pix_mp_fmt)
168{
169 mbus_fmt->width = pix_mp_fmt->width;
170 mbus_fmt->height = pix_mp_fmt->height;
171 mbus_fmt->field = pix_mp_fmt->field;
172 mbus_fmt->colorspace = pix_mp_fmt->colorspace;
173 mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
174 mbus_fmt->quantization = pix_mp_fmt->quantization;
175 mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
176}
177
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300178#endif