blob: 66cb746ceeb5258bfc83f5fcae03c34e4f9dd841 [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 Liakhovetski91c79532011-07-01 14:31:17 -030017/* Parallel flags */
18/*
19 * Can the client run in master or in slave mode. By "Master mode" an operation
20 * mode is meant, when the client (e.g., a camera sensor) is producing
21 * horizontal and vertical synchronisation. In "Slave mode" the host is
22 * providing these signals to the slave.
23 */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040024#define V4L2_MBUS_MASTER BIT(0)
25#define V4L2_MBUS_SLAVE BIT(1)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030026/*
27 * Signal polarity flags
28 * Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
29 * V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
30 * configuration of hardware that uses [HV]REF signals
31 */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040032#define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
33#define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
34#define V4L2_MBUS_VSYNC_ACTIVE_HIGH BIT(4)
35#define V4L2_MBUS_VSYNC_ACTIVE_LOW BIT(5)
36#define V4L2_MBUS_PCLK_SAMPLE_RISING BIT(6)
37#define V4L2_MBUS_PCLK_SAMPLE_FALLING BIT(7)
38#define V4L2_MBUS_DATA_ACTIVE_HIGH BIT(8)
39#define V4L2_MBUS_DATA_ACTIVE_LOW BIT(9)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030040/* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040041#define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10)
Sylwester Nawrocki3c6938f2011-09-19 12:58:54 -030042/* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040043#define V4L2_MBUS_FIELD_EVEN_LOW BIT(11)
Lad, Prabhakard1d70aa62013-08-11 02:02:24 -030044/* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040045#define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12)
46#define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13)
Jacopo Mondi9b04fcc2018-07-09 10:19:19 -040047#define V4L2_MBUS_DATA_ENABLE_HIGH BIT(14)
48#define V4L2_MBUS_DATA_ENABLE_LOW BIT(15)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030049
50/* Serial flags */
51/* How many lanes the client can use */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040052#define V4L2_MBUS_CSI2_1_LANE BIT(0)
53#define V4L2_MBUS_CSI2_2_LANE BIT(1)
54#define V4L2_MBUS_CSI2_3_LANE BIT(2)
55#define V4L2_MBUS_CSI2_4_LANE BIT(3)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030056/* On which channels it can send video data */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040057#define V4L2_MBUS_CSI2_CHANNEL_0 BIT(4)
58#define V4L2_MBUS_CSI2_CHANNEL_1 BIT(5)
59#define V4L2_MBUS_CSI2_CHANNEL_2 BIT(6)
60#define V4L2_MBUS_CSI2_CHANNEL_3 BIT(7)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030061/* Does it support only continuous or also non-continuous clock mode */
Mauro Carvalho Chehab21209612017-09-28 09:51:42 -040062#define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK BIT(8)
63#define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(9)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030064
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -040065#define V4L2_MBUS_CSI2_LANES (V4L2_MBUS_CSI2_1_LANE | \
66 V4L2_MBUS_CSI2_2_LANE | \
67 V4L2_MBUS_CSI2_3_LANE | \
68 V4L2_MBUS_CSI2_4_LANE)
69#define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | \
70 V4L2_MBUS_CSI2_CHANNEL_1 | \
71 V4L2_MBUS_CSI2_CHANNEL_2 | \
72 V4L2_MBUS_CSI2_CHANNEL_3)
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030073
74/**
Mauro Carvalho Chehab98d00bd2015-08-22 09:04:46 -030075 * enum v4l2_mbus_type - media bus type
Sakari Ailus2835b5b2018-07-31 06:43:14 -040076 * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030077 * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
78 * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
79 * also be used for BT.1120
Sakari Ailus97bbdf02015-02-25 14:39:11 -050080 * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
81 * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
Sakari Ailus2d95e7e2018-07-03 17:19:27 -040082 * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
83 * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030084 */
85enum v4l2_mbus_type {
Sakari Ailus2835b5b2018-07-31 06:43:14 -040086 V4L2_MBUS_UNKNOWN,
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030087 V4L2_MBUS_PARALLEL,
88 V4L2_MBUS_BT656,
Sakari Ailus97bbdf02015-02-25 14:39:11 -050089 V4L2_MBUS_CSI1,
90 V4L2_MBUS_CCP2,
Sakari Ailus2d95e7e2018-07-03 17:19:27 -040091 V4L2_MBUS_CSI2_DPHY,
92 V4L2_MBUS_CSI2_CPHY,
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030093};
94
95/**
Mauro Carvalho Chehab98d00bd2015-08-22 09:04:46 -030096 * struct v4l2_mbus_config - media bus configuration
Guennadi Liakhovetski91c79532011-07-01 14:31:17 -030097 * @type: in: interface type
98 * @flags: in / out: configuration flags, depending on @type
99 */
100struct v4l2_mbus_config {
101 enum v4l2_mbus_type type;
102 unsigned int flags;
103};
104
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400105/**
106 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
107 * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
108 *
109 * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
110 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
111 */
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400112static inline void
113v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
114 const struct v4l2_mbus_framefmt *mbus_fmt)
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300115{
116 pix_fmt->width = mbus_fmt->width;
117 pix_fmt->height = mbus_fmt->height;
118 pix_fmt->field = mbus_fmt->field;
119 pix_fmt->colorspace = mbus_fmt->colorspace;
Hans Verkuil11ff0302014-11-17 09:10:33 -0300120 pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
121 pix_fmt->quantization = mbus_fmt->quantization;
Hans Verkuil74fdcb22015-04-28 08:49:09 -0300122 pix_fmt->xfer_func = mbus_fmt->xfer_func;
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300123}
124
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400125/**
126 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
127 * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
128 * data format code.
129 *
130 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
131 * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
132 * @code: data format code (from &enum v4l2_mbus_pixelcode)
133 */
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300134static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400135 const struct v4l2_pix_format *pix_fmt,
Boris BREZILLON32b32ce2014-11-10 14:28:28 -0300136 u32 code)
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300137{
138 mbus_fmt->width = pix_fmt->width;
139 mbus_fmt->height = pix_fmt->height;
140 mbus_fmt->field = pix_fmt->field;
141 mbus_fmt->colorspace = pix_fmt->colorspace;
Hans Verkuil11ff0302014-11-17 09:10:33 -0300142 mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
143 mbus_fmt->quantization = pix_fmt->quantization;
Hans Verkuil74fdcb22015-04-28 08:49:09 -0300144 mbus_fmt->xfer_func = pix_fmt->xfer_func;
Hans Verkuil3a21cee2010-05-08 17:08:58 -0300145 mbus_fmt->code = code;
146}
147
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400148/**
149 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
150 * v4l2_pix_format_mplane fields from a media bus structure.
151 *
152 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
153 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
154 */
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400155static inline void
156v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt,
157 const struct v4l2_mbus_framefmt *mbus_fmt)
Todor Tomovf1923012017-07-07 04:48:47 -0400158{
159 pix_mp_fmt->width = mbus_fmt->width;
160 pix_mp_fmt->height = mbus_fmt->height;
161 pix_mp_fmt->field = mbus_fmt->field;
162 pix_mp_fmt->colorspace = mbus_fmt->colorspace;
163 pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
164 pix_mp_fmt->quantization = mbus_fmt->quantization;
165 pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
166}
167
Mauro Carvalho Chehab4839c582017-09-28 18:39:32 -0400168/**
169 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
170 * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
171 *
172 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
173 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
174 */
Mauro Carvalho Chehab6087b212018-10-04 17:10:46 -0400175static inline void
176v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt,
177 const struct v4l2_pix_format_mplane *pix_mp_fmt)
Todor Tomovf1923012017-07-07 04:48:47 -0400178{
179 mbus_fmt->width = pix_mp_fmt->width;
180 mbus_fmt->height = pix_mp_fmt->height;
181 mbus_fmt->field = pix_mp_fmt->field;
182 mbus_fmt->colorspace = pix_mp_fmt->colorspace;
183 mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
184 mbus_fmt->quantization = pix_mp_fmt->quantization;
185 mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
186}
187
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300188#endif