blob: c072ed1418113f7a9fb1d56bbb260a82a887e5e6 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Media Bus API header
4 *
5 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7
8#ifndef V4L2_MEDIABUS_H
9#define V4L2_MEDIABUS_H
10
11#include <linux/v4l2-mediabus.h>
12#include <linux/bitops.h>
13
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000014/* Parallel flags */
15/*
16 * Can the client run in master or in slave mode. By "Master mode" an operation
17 * mode is meant, when the client (e.g., a camera sensor) is producing
18 * horizontal and vertical synchronisation. In "Slave mode" the host is
19 * providing these signals to the slave.
20 */
21#define V4L2_MBUS_MASTER BIT(0)
22#define V4L2_MBUS_SLAVE BIT(1)
23/*
24 * Signal polarity flags
25 * Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
26 * V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
27 * configuration of hardware that uses [HV]REF signals
28 */
29#define V4L2_MBUS_HSYNC_ACTIVE_HIGH BIT(2)
30#define V4L2_MBUS_HSYNC_ACTIVE_LOW BIT(3)
31#define V4L2_MBUS_VSYNC_ACTIVE_HIGH BIT(4)
32#define V4L2_MBUS_VSYNC_ACTIVE_LOW BIT(5)
33#define V4L2_MBUS_PCLK_SAMPLE_RISING BIT(6)
34#define V4L2_MBUS_PCLK_SAMPLE_FALLING BIT(7)
35#define V4L2_MBUS_DATA_ACTIVE_HIGH BIT(8)
36#define V4L2_MBUS_DATA_ACTIVE_LOW BIT(9)
37/* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
38#define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10)
39/* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
40#define V4L2_MBUS_FIELD_EVEN_LOW BIT(11)
41/* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
42#define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12)
43#define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13)
44#define V4L2_MBUS_DATA_ENABLE_HIGH BIT(14)
45#define V4L2_MBUS_DATA_ENABLE_LOW BIT(15)
46
47/* Serial flags */
48/* How many lanes the client can use */
49#define V4L2_MBUS_CSI2_1_LANE BIT(0)
50#define V4L2_MBUS_CSI2_2_LANE BIT(1)
51#define V4L2_MBUS_CSI2_3_LANE BIT(2)
52#define V4L2_MBUS_CSI2_4_LANE BIT(3)
53/* On which channels it can send video data */
54#define V4L2_MBUS_CSI2_CHANNEL_0 BIT(4)
55#define V4L2_MBUS_CSI2_CHANNEL_1 BIT(5)
56#define V4L2_MBUS_CSI2_CHANNEL_2 BIT(6)
57#define V4L2_MBUS_CSI2_CHANNEL_3 BIT(7)
58/* Does it support only continuous or also non-continuous clock mode */
59#define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK BIT(8)
60#define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(9)
61
David Brazdil0f672f62019-12-10 10:32:29 +000062#define V4L2_MBUS_CSI2_LANES (V4L2_MBUS_CSI2_1_LANE | \
63 V4L2_MBUS_CSI2_2_LANE | \
64 V4L2_MBUS_CSI2_3_LANE | \
65 V4L2_MBUS_CSI2_4_LANE)
66#define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | \
67 V4L2_MBUS_CSI2_CHANNEL_1 | \
68 V4L2_MBUS_CSI2_CHANNEL_2 | \
69 V4L2_MBUS_CSI2_CHANNEL_3)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000070
71/**
72 * enum v4l2_mbus_type - media bus type
David Brazdil0f672f62019-12-10 10:32:29 +000073 * @V4L2_MBUS_UNKNOWN: unknown bus type, no V4L2 mediabus configuration
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000074 * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
75 * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
76 * also be used for BT.1120
77 * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface
78 * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2)
David Brazdil0f672f62019-12-10 10:32:29 +000079 * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY
80 * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY
Olivier Deprez0e641232021-09-23 10:07:05 +020081 * @V4L2_MBUS_INVALID: invalid bus type (keep as last)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000082 */
83enum v4l2_mbus_type {
David Brazdil0f672f62019-12-10 10:32:29 +000084 V4L2_MBUS_UNKNOWN,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000085 V4L2_MBUS_PARALLEL,
86 V4L2_MBUS_BT656,
87 V4L2_MBUS_CSI1,
88 V4L2_MBUS_CCP2,
David Brazdil0f672f62019-12-10 10:32:29 +000089 V4L2_MBUS_CSI2_DPHY,
90 V4L2_MBUS_CSI2_CPHY,
Olivier Deprez0e641232021-09-23 10:07:05 +020091 V4L2_MBUS_INVALID,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000092};
93
94/**
95 * struct v4l2_mbus_config - media bus configuration
96 * @type: in: interface type
97 * @flags: in / out: configuration flags, depending on @type
98 */
99struct v4l2_mbus_config {
100 enum v4l2_mbus_type type;
101 unsigned int flags;
102};
103
104/**
105 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
106 * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt.
107 *
108 * @pix_fmt: pointer to &struct v4l2_pix_format to be filled
109 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
110 */
David Brazdil0f672f62019-12-10 10:32:29 +0000111static inline void
112v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
113 const struct v4l2_mbus_framefmt *mbus_fmt)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000114{
115 pix_fmt->width = mbus_fmt->width;
116 pix_fmt->height = mbus_fmt->height;
117 pix_fmt->field = mbus_fmt->field;
118 pix_fmt->colorspace = mbus_fmt->colorspace;
119 pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
120 pix_fmt->quantization = mbus_fmt->quantization;
121 pix_fmt->xfer_func = mbus_fmt->xfer_func;
122}
123
124/**
125 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
126 * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a
127 * data format code.
128 *
129 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
130 * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model
131 * @code: data format code (from &enum v4l2_mbus_pixelcode)
132 */
133static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
David Brazdil0f672f62019-12-10 10:32:29 +0000134 const struct v4l2_pix_format *pix_fmt,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000135 u32 code)
136{
137 mbus_fmt->width = pix_fmt->width;
138 mbus_fmt->height = pix_fmt->height;
139 mbus_fmt->field = pix_fmt->field;
140 mbus_fmt->colorspace = pix_fmt->colorspace;
141 mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc;
142 mbus_fmt->quantization = pix_fmt->quantization;
143 mbus_fmt->xfer_func = pix_fmt->xfer_func;
144 mbus_fmt->code = code;
145}
146
147/**
148 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
149 * v4l2_pix_format_mplane fields from a media bus structure.
150 *
151 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled
152 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model
153 */
David Brazdil0f672f62019-12-10 10:32:29 +0000154static inline void
155v4l2_fill_pix_format_mplane(struct v4l2_pix_format_mplane *pix_mp_fmt,
156 const struct v4l2_mbus_framefmt *mbus_fmt)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000157{
158 pix_mp_fmt->width = mbus_fmt->width;
159 pix_mp_fmt->height = mbus_fmt->height;
160 pix_mp_fmt->field = mbus_fmt->field;
161 pix_mp_fmt->colorspace = mbus_fmt->colorspace;
162 pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc;
163 pix_mp_fmt->quantization = mbus_fmt->quantization;
164 pix_mp_fmt->xfer_func = mbus_fmt->xfer_func;
165}
166
167/**
168 * v4l2_fill_pix_format - Ancillary routine that fills a &struct
169 * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane.
170 *
171 * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled
172 * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model
173 */
David Brazdil0f672f62019-12-10 10:32:29 +0000174static inline void
175v4l2_fill_mbus_format_mplane(struct v4l2_mbus_framefmt *mbus_fmt,
176 const struct v4l2_pix_format_mplane *pix_mp_fmt)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000177{
178 mbus_fmt->width = pix_mp_fmt->width;
179 mbus_fmt->height = pix_mp_fmt->height;
180 mbus_fmt->field = pix_mp_fmt->field;
181 mbus_fmt->colorspace = pix_mp_fmt->colorspace;
182 mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc;
183 mbus_fmt->quantization = pix_mp_fmt->quantization;
184 mbus_fmt->xfer_func = pix_mp_fmt->xfer_func;
185}
186
187#endif