Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 1 | /* |
| 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 Pinchart | 2ef2d5a | 2010-03-15 19:33:31 -0300 | [diff] [blame] | 14 | #include <linux/v4l2-mediabus.h> |
Mauro Carvalho Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 15 | #include <linux/bitops.h> |
| 16 | |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 17 | |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 18 | /* 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 Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 25 | #define V4L2_MBUS_MASTER BIT(0) |
| 26 | #define V4L2_MBUS_SLAVE BIT(1) |
Sylwester Nawrocki | 3c6938f | 2011-09-19 12:58:54 -0300 | [diff] [blame] | 27 | /* |
| 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 Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 33 | #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 Nawrocki | 3c6938f | 2011-09-19 12:58:54 -0300 | [diff] [blame] | 41 | /* FIELD = 0/1 - Field1 (odd)/Field2 (even) */ |
Mauro Carvalho Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 42 | #define V4L2_MBUS_FIELD_EVEN_HIGH BIT(10) |
Sylwester Nawrocki | 3c6938f | 2011-09-19 12:58:54 -0300 | [diff] [blame] | 43 | /* FIELD = 1/0 - Field1 (odd)/Field2 (even) */ |
Mauro Carvalho Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 44 | #define V4L2_MBUS_FIELD_EVEN_LOW BIT(11) |
Lad, Prabhakar | d1d70aa6 | 2013-08-11 02:02:24 -0300 | [diff] [blame] | 45 | /* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */ |
Mauro Carvalho Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 46 | #define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH BIT(12) |
| 47 | #define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW BIT(13) |
Jacopo Mondi | 9b04fcc | 2018-07-09 10:19:19 -0400 | [diff] [blame] | 48 | #define V4L2_MBUS_DATA_ENABLE_HIGH BIT(14) |
| 49 | #define V4L2_MBUS_DATA_ENABLE_LOW BIT(15) |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 50 | |
| 51 | /* Serial flags */ |
| 52 | /* How many lanes the client can use */ |
Mauro Carvalho Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 53 | #define V4L2_MBUS_CSI2_1_LANE BIT(0) |
| 54 | #define V4L2_MBUS_CSI2_2_LANE BIT(1) |
| 55 | #define V4L2_MBUS_CSI2_3_LANE BIT(2) |
| 56 | #define V4L2_MBUS_CSI2_4_LANE BIT(3) |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 57 | /* On which channels it can send video data */ |
Mauro Carvalho Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 58 | #define V4L2_MBUS_CSI2_CHANNEL_0 BIT(4) |
| 59 | #define V4L2_MBUS_CSI2_CHANNEL_1 BIT(5) |
| 60 | #define V4L2_MBUS_CSI2_CHANNEL_2 BIT(6) |
| 61 | #define V4L2_MBUS_CSI2_CHANNEL_3 BIT(7) |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 62 | /* Does it support only continuous or also non-continuous clock mode */ |
Mauro Carvalho Chehab | 2120961 | 2017-09-28 09:51:42 -0400 | [diff] [blame] | 63 | #define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK BIT(8) |
| 64 | #define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK BIT(9) |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 65 | |
| 66 | #define V4L2_MBUS_CSI2_LANES (V4L2_MBUS_CSI2_1_LANE | V4L2_MBUS_CSI2_2_LANE | \ |
| 67 | V4L2_MBUS_CSI2_3_LANE | V4L2_MBUS_CSI2_4_LANE) |
| 68 | #define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | V4L2_MBUS_CSI2_CHANNEL_1 | \ |
| 69 | V4L2_MBUS_CSI2_CHANNEL_2 | V4L2_MBUS_CSI2_CHANNEL_3) |
| 70 | |
| 71 | /** |
Mauro Carvalho Chehab | 98d00bd | 2015-08-22 09:04:46 -0300 | [diff] [blame] | 72 | * enum v4l2_mbus_type - media bus type |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 73 | * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync |
| 74 | * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can |
| 75 | * also be used for BT.1120 |
Sakari Ailus | 97bbdf0 | 2015-02-25 14:39:11 -0500 | [diff] [blame] | 76 | * @V4L2_MBUS_CSI1: MIPI CSI-1 serial interface |
| 77 | * @V4L2_MBUS_CCP2: CCP2 (Compact Camera Port 2) |
Sakari Ailus | 2d95e7e | 2018-07-03 17:19:27 -0400 | [diff] [blame^] | 78 | * @V4L2_MBUS_CSI2_DPHY: MIPI CSI-2 serial interface, with D-PHY |
| 79 | * @V4L2_MBUS_CSI2_CPHY: MIPI CSI-2 serial interface, with C-PHY |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 80 | */ |
| 81 | enum v4l2_mbus_type { |
| 82 | V4L2_MBUS_PARALLEL, |
| 83 | V4L2_MBUS_BT656, |
Sakari Ailus | 97bbdf0 | 2015-02-25 14:39:11 -0500 | [diff] [blame] | 84 | V4L2_MBUS_CSI1, |
| 85 | V4L2_MBUS_CCP2, |
Sakari Ailus | 2d95e7e | 2018-07-03 17:19:27 -0400 | [diff] [blame^] | 86 | V4L2_MBUS_CSI2_DPHY, |
| 87 | V4L2_MBUS_CSI2_CPHY, |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /** |
Mauro Carvalho Chehab | 98d00bd | 2015-08-22 09:04:46 -0300 | [diff] [blame] | 91 | * struct v4l2_mbus_config - media bus configuration |
Guennadi Liakhovetski | 91c7953 | 2011-07-01 14:31:17 -0300 | [diff] [blame] | 92 | * @type: in: interface type |
| 93 | * @flags: in / out: configuration flags, depending on @type |
| 94 | */ |
| 95 | struct v4l2_mbus_config { |
| 96 | enum v4l2_mbus_type type; |
| 97 | unsigned int flags; |
| 98 | }; |
| 99 | |
Mauro Carvalho Chehab | 4839c58 | 2017-09-28 18:39:32 -0400 | [diff] [blame] | 100 | /** |
| 101 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct |
| 102 | * v4l2_pix_format fields from a &struct v4l2_mbus_framefmt. |
| 103 | * |
| 104 | * @pix_fmt: pointer to &struct v4l2_pix_format to be filled |
| 105 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model |
| 106 | */ |
Hans Verkuil | 3a21cee | 2010-05-08 17:08:58 -0300 | [diff] [blame] | 107 | static inline void v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt, |
| 108 | const struct v4l2_mbus_framefmt *mbus_fmt) |
| 109 | { |
| 110 | pix_fmt->width = mbus_fmt->width; |
| 111 | pix_fmt->height = mbus_fmt->height; |
| 112 | pix_fmt->field = mbus_fmt->field; |
| 113 | pix_fmt->colorspace = mbus_fmt->colorspace; |
Hans Verkuil | 11ff030 | 2014-11-17 09:10:33 -0300 | [diff] [blame] | 114 | pix_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc; |
| 115 | pix_fmt->quantization = mbus_fmt->quantization; |
Hans Verkuil | 74fdcb2 | 2015-04-28 08:49:09 -0300 | [diff] [blame] | 116 | pix_fmt->xfer_func = mbus_fmt->xfer_func; |
Hans Verkuil | 3a21cee | 2010-05-08 17:08:58 -0300 | [diff] [blame] | 117 | } |
| 118 | |
Mauro Carvalho Chehab | 4839c58 | 2017-09-28 18:39:32 -0400 | [diff] [blame] | 119 | /** |
| 120 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct |
| 121 | * v4l2_mbus_framefmt from a &struct v4l2_pix_format and a |
| 122 | * data format code. |
| 123 | * |
| 124 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled |
| 125 | * @pix_fmt: pointer to &struct v4l2_pix_format to be used as model |
| 126 | * @code: data format code (from &enum v4l2_mbus_pixelcode) |
| 127 | */ |
Hans Verkuil | 3a21cee | 2010-05-08 17:08:58 -0300 | [diff] [blame] | 128 | static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt, |
| 129 | const struct v4l2_pix_format *pix_fmt, |
Boris BREZILLON | 32b32ce | 2014-11-10 14:28:28 -0300 | [diff] [blame] | 130 | u32 code) |
Hans Verkuil | 3a21cee | 2010-05-08 17:08:58 -0300 | [diff] [blame] | 131 | { |
| 132 | mbus_fmt->width = pix_fmt->width; |
| 133 | mbus_fmt->height = pix_fmt->height; |
| 134 | mbus_fmt->field = pix_fmt->field; |
| 135 | mbus_fmt->colorspace = pix_fmt->colorspace; |
Hans Verkuil | 11ff030 | 2014-11-17 09:10:33 -0300 | [diff] [blame] | 136 | mbus_fmt->ycbcr_enc = pix_fmt->ycbcr_enc; |
| 137 | mbus_fmt->quantization = pix_fmt->quantization; |
Hans Verkuil | 74fdcb2 | 2015-04-28 08:49:09 -0300 | [diff] [blame] | 138 | mbus_fmt->xfer_func = pix_fmt->xfer_func; |
Hans Verkuil | 3a21cee | 2010-05-08 17:08:58 -0300 | [diff] [blame] | 139 | mbus_fmt->code = code; |
| 140 | } |
| 141 | |
Mauro Carvalho Chehab | 4839c58 | 2017-09-28 18:39:32 -0400 | [diff] [blame] | 142 | /** |
| 143 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct |
| 144 | * v4l2_pix_format_mplane fields from a media bus structure. |
| 145 | * |
| 146 | * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be filled |
| 147 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be used as model |
| 148 | */ |
Todor Tomov | f192301 | 2017-07-07 04:48:47 -0400 | [diff] [blame] | 149 | static inline void v4l2_fill_pix_format_mplane( |
| 150 | struct v4l2_pix_format_mplane *pix_mp_fmt, |
| 151 | const struct v4l2_mbus_framefmt *mbus_fmt) |
| 152 | { |
| 153 | pix_mp_fmt->width = mbus_fmt->width; |
| 154 | pix_mp_fmt->height = mbus_fmt->height; |
| 155 | pix_mp_fmt->field = mbus_fmt->field; |
| 156 | pix_mp_fmt->colorspace = mbus_fmt->colorspace; |
| 157 | pix_mp_fmt->ycbcr_enc = mbus_fmt->ycbcr_enc; |
| 158 | pix_mp_fmt->quantization = mbus_fmt->quantization; |
| 159 | pix_mp_fmt->xfer_func = mbus_fmt->xfer_func; |
| 160 | } |
| 161 | |
Mauro Carvalho Chehab | 4839c58 | 2017-09-28 18:39:32 -0400 | [diff] [blame] | 162 | /** |
| 163 | * v4l2_fill_pix_format - Ancillary routine that fills a &struct |
| 164 | * v4l2_mbus_framefmt from a &struct v4l2_pix_format_mplane. |
| 165 | * |
| 166 | * @mbus_fmt: pointer to &struct v4l2_mbus_framefmt to be filled |
| 167 | * @pix_mp_fmt: pointer to &struct v4l2_pix_format_mplane to be used as model |
| 168 | */ |
Todor Tomov | f192301 | 2017-07-07 04:48:47 -0400 | [diff] [blame] | 169 | static inline void v4l2_fill_mbus_format_mplane( |
| 170 | struct v4l2_mbus_framefmt *mbus_fmt, |
| 171 | const struct v4l2_pix_format_mplane *pix_mp_fmt) |
| 172 | { |
| 173 | mbus_fmt->width = pix_mp_fmt->width; |
| 174 | mbus_fmt->height = pix_mp_fmt->height; |
| 175 | mbus_fmt->field = pix_mp_fmt->field; |
| 176 | mbus_fmt->colorspace = pix_mp_fmt->colorspace; |
| 177 | mbus_fmt->ycbcr_enc = pix_mp_fmt->ycbcr_enc; |
| 178 | mbus_fmt->quantization = pix_mp_fmt->quantization; |
| 179 | mbus_fmt->xfer_func = pix_mp_fmt->xfer_func; |
| 180 | } |
| 181 | |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 182 | #endif |