blob: 89dce097a827a57d918702b0a4cd415b48ee409e [file] [log] [blame]
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -03001/*
2 * soc-camera media bus helper routines
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#include <linux/kernel.h>
12#include <linux/module.h>
13
14#include <media/v4l2-device.h>
15#include <media/v4l2-mediabus.h>
16#include <media/soc_mediabus.h>
17
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030018static const struct soc_mbus_lookup mbus_fmt[] = {
19{
20 .code = V4L2_MBUS_FMT_YUYV8_2X8,
21 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030022 .fourcc = V4L2_PIX_FMT_YUYV,
23 .name = "YUYV",
24 .bits_per_sample = 8,
25 .packing = SOC_MBUS_PACKING_2X8_PADHI,
26 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030027 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010028 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030029}, {
30 .code = V4L2_MBUS_FMT_YVYU8_2X8,
31 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030032 .fourcc = V4L2_PIX_FMT_YVYU,
33 .name = "YVYU",
34 .bits_per_sample = 8,
35 .packing = SOC_MBUS_PACKING_2X8_PADHI,
36 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030037 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010038 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030039}, {
40 .code = V4L2_MBUS_FMT_UYVY8_2X8,
41 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030042 .fourcc = V4L2_PIX_FMT_UYVY,
43 .name = "UYVY",
44 .bits_per_sample = 8,
45 .packing = SOC_MBUS_PACKING_2X8_PADHI,
46 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030047 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010048 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030049}, {
50 .code = V4L2_MBUS_FMT_VYUY8_2X8,
51 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030052 .fourcc = V4L2_PIX_FMT_VYUY,
53 .name = "VYUY",
54 .bits_per_sample = 8,
55 .packing = SOC_MBUS_PACKING_2X8_PADHI,
56 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030057 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010058 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030059}, {
60 .code = V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE,
61 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030062 .fourcc = V4L2_PIX_FMT_RGB555,
63 .name = "RGB555",
64 .bits_per_sample = 8,
65 .packing = SOC_MBUS_PACKING_2X8_PADHI,
66 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030067 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010068 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030069}, {
70 .code = V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE,
71 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030072 .fourcc = V4L2_PIX_FMT_RGB555X,
73 .name = "RGB555X",
74 .bits_per_sample = 8,
75 .packing = SOC_MBUS_PACKING_2X8_PADHI,
76 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030077 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010078 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030079}, {
80 .code = V4L2_MBUS_FMT_RGB565_2X8_LE,
81 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030082 .fourcc = V4L2_PIX_FMT_RGB565,
83 .name = "RGB565",
84 .bits_per_sample = 8,
85 .packing = SOC_MBUS_PACKING_2X8_PADHI,
86 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030087 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010088 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030089}, {
90 .code = V4L2_MBUS_FMT_RGB565_2X8_BE,
91 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030092 .fourcc = V4L2_PIX_FMT_RGB565X,
93 .name = "RGB565X",
94 .bits_per_sample = 8,
95 .packing = SOC_MBUS_PACKING_2X8_PADHI,
96 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030097 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +010098 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030099}, {
100 .code = V4L2_MBUS_FMT_SBGGR8_1X8,
101 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300102 .fourcc = V4L2_PIX_FMT_SBGGR8,
103 .name = "Bayer 8 BGGR",
104 .bits_per_sample = 8,
105 .packing = SOC_MBUS_PACKING_NONE,
106 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300107 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +0100108 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300109}, {
110 .code = V4L2_MBUS_FMT_SBGGR10_1X10,
111 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300112 .fourcc = V4L2_PIX_FMT_SBGGR10,
113 .name = "Bayer 10 BGGR",
114 .bits_per_sample = 10,
115 .packing = SOC_MBUS_PACKING_EXTEND16,
116 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300117 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +0100118 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300119}, {
120 .code = V4L2_MBUS_FMT_Y8_1X8,
121 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300122 .fourcc = V4L2_PIX_FMT_GREY,
123 .name = "Grey",
124 .bits_per_sample = 8,
125 .packing = SOC_MBUS_PACKING_NONE,
126 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300127 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +0100128 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300129}, {
130 .code = V4L2_MBUS_FMT_Y10_1X10,
131 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300132 .fourcc = V4L2_PIX_FMT_Y10,
133 .name = "Grey 10bit",
134 .bits_per_sample = 10,
135 .packing = SOC_MBUS_PACKING_EXTEND16,
136 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300137 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +0100138 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300139}, {
140 .code = V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE,
141 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300142 .fourcc = V4L2_PIX_FMT_SBGGR10,
143 .name = "Bayer 10 BGGR",
144 .bits_per_sample = 8,
145 .packing = SOC_MBUS_PACKING_2X8_PADHI,
146 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300147 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +0100148 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300149}, {
150 .code = V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_LE,
151 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300152 .fourcc = V4L2_PIX_FMT_SBGGR10,
153 .name = "Bayer 10 BGGR",
154 .bits_per_sample = 8,
155 .packing = SOC_MBUS_PACKING_2X8_PADLO,
156 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300157 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +0100158 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300159}, {
160 .code = V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE,
161 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300162 .fourcc = V4L2_PIX_FMT_SBGGR10,
163 .name = "Bayer 10 BGGR",
164 .bits_per_sample = 8,
165 .packing = SOC_MBUS_PACKING_2X8_PADHI,
166 .order = SOC_MBUS_ORDER_BE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300167 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski81355e42009-12-24 14:12:15 +0100168 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300169}, {
170 .code = V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE,
171 .fmt = {
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300172 .fourcc = V4L2_PIX_FMT_SBGGR10,
173 .name = "Bayer 10 BGGR",
174 .bits_per_sample = 8,
175 .packing = SOC_MBUS_PACKING_2X8_PADLO,
176 .order = SOC_MBUS_ORDER_BE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300177 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300178 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300179}, {
180 .code = V4L2_MBUS_FMT_JPEG_1X8,
181 .fmt = {
Kassey Li64149de2011-05-20 04:08:39 -0300182 .fourcc = V4L2_PIX_FMT_JPEG,
183 .name = "JPEG",
184 .bits_per_sample = 8,
185 .packing = SOC_MBUS_PACKING_VARIABLE,
186 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300187 .layout = SOC_MBUS_LAYOUT_PACKED,
Kassey Li64149de2011-05-20 04:08:39 -0300188 },
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300189}, {
190 .code = V4L2_MBUS_FMT_RGB444_2X8_PADHI_BE,
191 .fmt = {
192 .fourcc = V4L2_PIX_FMT_RGB444,
193 .name = "RGB444",
194 .bits_per_sample = 8,
195 .packing = SOC_MBUS_PACKING_2X8_PADHI,
196 .order = SOC_MBUS_ORDER_BE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300197 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300198 },
199}, {
200 .code = V4L2_MBUS_FMT_YUYV8_1_5X8,
201 .fmt = {
202 .fourcc = V4L2_PIX_FMT_YUV420,
203 .name = "YUYV 4:2:0",
204 .bits_per_sample = 8,
205 .packing = SOC_MBUS_PACKING_1_5X8,
206 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300207 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300208 },
209}, {
210 .code = V4L2_MBUS_FMT_YVYU8_1_5X8,
211 .fmt = {
212 .fourcc = V4L2_PIX_FMT_YVU420,
213 .name = "YVYU 4:2:0",
214 .bits_per_sample = 8,
215 .packing = SOC_MBUS_PACKING_1_5X8,
216 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300217 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300218 },
219}, {
220 .code = V4L2_MBUS_FMT_UYVY8_1X16,
221 .fmt = {
222 .fourcc = V4L2_PIX_FMT_UYVY,
223 .name = "UYVY 16bit",
224 .bits_per_sample = 16,
225 .packing = SOC_MBUS_PACKING_EXTEND16,
226 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300227 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300228 },
229}, {
230 .code = V4L2_MBUS_FMT_VYUY8_1X16,
231 .fmt = {
232 .fourcc = V4L2_PIX_FMT_VYUY,
233 .name = "VYUY 16bit",
234 .bits_per_sample = 16,
235 .packing = SOC_MBUS_PACKING_EXTEND16,
236 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300237 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300238 },
239}, {
240 .code = V4L2_MBUS_FMT_YUYV8_1X16,
241 .fmt = {
242 .fourcc = V4L2_PIX_FMT_YUYV,
243 .name = "YUYV 16bit",
244 .bits_per_sample = 16,
245 .packing = SOC_MBUS_PACKING_EXTEND16,
246 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300247 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300248 },
249}, {
250 .code = V4L2_MBUS_FMT_YVYU8_1X16,
251 .fmt = {
252 .fourcc = V4L2_PIX_FMT_YVYU,
253 .name = "YVYU 16bit",
254 .bits_per_sample = 16,
255 .packing = SOC_MBUS_PACKING_EXTEND16,
256 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300257 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300258 },
259}, {
260 .code = V4L2_MBUS_FMT_SGRBG8_1X8,
261 .fmt = {
262 .fourcc = V4L2_PIX_FMT_SGRBG8,
263 .name = "Bayer 8 GRBG",
264 .bits_per_sample = 8,
265 .packing = SOC_MBUS_PACKING_NONE,
266 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300267 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300268 },
269}, {
270 .code = V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
271 .fmt = {
272 .fourcc = V4L2_PIX_FMT_SGRBG10DPCM8,
273 .name = "Bayer 10 BGGR DPCM 8",
274 .bits_per_sample = 8,
275 .packing = SOC_MBUS_PACKING_NONE,
276 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300277 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300278 },
279}, {
280 .code = V4L2_MBUS_FMT_SGBRG10_1X10,
281 .fmt = {
282 .fourcc = V4L2_PIX_FMT_SGBRG10,
283 .name = "Bayer 10 GBRG",
284 .bits_per_sample = 10,
285 .packing = SOC_MBUS_PACKING_EXTEND16,
286 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300287 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300288 },
289}, {
290 .code = V4L2_MBUS_FMT_SGRBG10_1X10,
291 .fmt = {
292 .fourcc = V4L2_PIX_FMT_SGRBG10,
293 .name = "Bayer 10 GRBG",
294 .bits_per_sample = 10,
295 .packing = SOC_MBUS_PACKING_EXTEND16,
296 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300297 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300298 },
299}, {
300 .code = V4L2_MBUS_FMT_SRGGB10_1X10,
301 .fmt = {
302 .fourcc = V4L2_PIX_FMT_SRGGB10,
303 .name = "Bayer 10 RGGB",
304 .bits_per_sample = 10,
305 .packing = SOC_MBUS_PACKING_EXTEND16,
306 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300307 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300308 },
309}, {
310 .code = V4L2_MBUS_FMT_SBGGR12_1X12,
311 .fmt = {
312 .fourcc = V4L2_PIX_FMT_SBGGR12,
313 .name = "Bayer 12 BGGR",
314 .bits_per_sample = 12,
315 .packing = SOC_MBUS_PACKING_EXTEND16,
316 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300317 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300318 },
319}, {
320 .code = V4L2_MBUS_FMT_SGBRG12_1X12,
321 .fmt = {
322 .fourcc = V4L2_PIX_FMT_SGBRG12,
323 .name = "Bayer 12 GBRG",
324 .bits_per_sample = 12,
325 .packing = SOC_MBUS_PACKING_EXTEND16,
326 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300327 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300328 },
329}, {
330 .code = V4L2_MBUS_FMT_SGRBG12_1X12,
331 .fmt = {
332 .fourcc = V4L2_PIX_FMT_SGRBG12,
333 .name = "Bayer 12 GRBG",
334 .bits_per_sample = 12,
335 .packing = SOC_MBUS_PACKING_EXTEND16,
336 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300337 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300338 },
339}, {
340 .code = V4L2_MBUS_FMT_SRGGB12_1X12,
341 .fmt = {
342 .fourcc = V4L2_PIX_FMT_SRGGB12,
343 .name = "Bayer 12 RGGB",
344 .bits_per_sample = 12,
345 .packing = SOC_MBUS_PACKING_EXTEND16,
346 .order = SOC_MBUS_ORDER_LE,
Laurent Pinchartad3b81f2012-03-21 08:03:23 -0300347 .layout = SOC_MBUS_LAYOUT_PACKED,
Guennadi Liakhovetskie23b9612011-05-17 10:44:03 -0300348 },
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300349},
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300350};
351
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -0300352int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf,
353 unsigned int *numerator, unsigned int *denominator)
Alberto Panizzo48a3c772011-01-12 08:16:19 -0300354{
355 switch (mf->packing) {
356 case SOC_MBUS_PACKING_NONE:
357 case SOC_MBUS_PACKING_EXTEND16:
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -0300358 *numerator = 1;
359 *denominator = 1;
360 return 0;
Alberto Panizzo48a3c772011-01-12 08:16:19 -0300361 case SOC_MBUS_PACKING_2X8_PADHI:
362 case SOC_MBUS_PACKING_2X8_PADLO:
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -0300363 *numerator = 2;
364 *denominator = 1;
365 return 0;
366 case SOC_MBUS_PACKING_1_5X8:
367 *numerator = 3;
368 *denominator = 2;
369 return 0;
Kassey Li64149de2011-05-20 04:08:39 -0300370 case SOC_MBUS_PACKING_VARIABLE:
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -0300371 *numerator = 0;
372 *denominator = 1;
Kassey Li64149de2011-05-20 04:08:39 -0300373 return 0;
Alberto Panizzo48a3c772011-01-12 08:16:19 -0300374 }
375 return -EINVAL;
376}
377EXPORT_SYMBOL(soc_mbus_samples_per_pixel);
378
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300379s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf)
380{
Laurent Pinchart4e0e6202012-03-21 08:03:24 -0300381 if (mf->layout != SOC_MBUS_LAYOUT_PACKED)
382 return width * mf->bits_per_sample / 8;
383
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300384 switch (mf->packing) {
385 case SOC_MBUS_PACKING_NONE:
386 return width * mf->bits_per_sample / 8;
387 case SOC_MBUS_PACKING_2X8_PADHI:
388 case SOC_MBUS_PACKING_2X8_PADLO:
389 case SOC_MBUS_PACKING_EXTEND16:
390 return width * 2;
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -0300391 case SOC_MBUS_PACKING_1_5X8:
392 return width * 3 / 2;
Kassey Li64149de2011-05-20 04:08:39 -0300393 case SOC_MBUS_PACKING_VARIABLE:
394 return 0;
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300395 }
396 return -EINVAL;
397}
398EXPORT_SYMBOL(soc_mbus_bytes_per_line);
399
Laurent Pinchart8929c962012-03-21 08:03:25 -0300400s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf,
401 u32 bytes_per_line, u32 height)
402{
403 if (mf->layout == SOC_MBUS_LAYOUT_PACKED)
404 return bytes_per_line * height;
405
406 switch (mf->packing) {
407 case SOC_MBUS_PACKING_2X8_PADHI:
408 case SOC_MBUS_PACKING_2X8_PADLO:
409 return bytes_per_line * height * 2;
410 case SOC_MBUS_PACKING_1_5X8:
411 return bytes_per_line * height * 3 / 2;
412 default:
413 return -EINVAL;
414 }
415}
416EXPORT_SYMBOL(soc_mbus_image_size);
417
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300418const struct soc_mbus_pixelfmt *soc_mbus_find_fmtdesc(
419 enum v4l2_mbus_pixelcode code,
420 const struct soc_mbus_lookup *lookup,
421 int n)
422{
423 int i;
424
425 for (i = 0; i < n; i++)
426 if (lookup[i].code == code)
427 return &lookup[i].fmt;
428
429 return NULL;
430}
431EXPORT_SYMBOL(soc_mbus_find_fmtdesc);
432
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300433const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
434 enum v4l2_mbus_pixelcode code)
435{
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -0300436 return soc_mbus_find_fmtdesc(code, mbus_fmt, ARRAY_SIZE(mbus_fmt));
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300437}
438EXPORT_SYMBOL(soc_mbus_get_fmtdesc);
439
Guennadi Liakhovetski32c69fcc2011-07-26 11:38:01 -0300440unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
441 unsigned int flags)
442{
443 unsigned long common_flags;
444 bool hsync = true, vsync = true, pclk, data, mode;
445 bool mipi_lanes, mipi_clock;
446
447 common_flags = cfg->flags & flags;
448
449 switch (cfg->type) {
450 case V4L2_MBUS_PARALLEL:
451 hsync = common_flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH |
452 V4L2_MBUS_HSYNC_ACTIVE_LOW);
453 vsync = common_flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH |
454 V4L2_MBUS_VSYNC_ACTIVE_LOW);
455 case V4L2_MBUS_BT656:
456 pclk = common_flags & (V4L2_MBUS_PCLK_SAMPLE_RISING |
457 V4L2_MBUS_PCLK_SAMPLE_FALLING);
458 data = common_flags & (V4L2_MBUS_DATA_ACTIVE_HIGH |
459 V4L2_MBUS_DATA_ACTIVE_LOW);
460 mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
461 return (!hsync || !vsync || !pclk || !data || !mode) ?
462 0 : common_flags;
463 case V4L2_MBUS_CSI2:
464 mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
465 mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
466 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
467 return (!mipi_lanes || !mipi_clock) ? 0 : common_flags;
468 }
469 return 0;
470}
471EXPORT_SYMBOL(soc_mbus_config_compatible);
472
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300473static int __init soc_mbus_init(void)
474{
475 return 0;
476}
477
478static void __exit soc_mbus_exit(void)
479{
480}
481
482module_init(soc_mbus_init);
483module_exit(soc_mbus_exit);
484
485MODULE_DESCRIPTION("soc-camera media bus interface");
486MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
487MODULE_LICENSE("GPL v2");