blob: 0dc6f4625b920021fa573bfe06918d58c120296c [file] [log] [blame]
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -03001/*
2 * SoC-camera Media Bus API extensions
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 SOC_MEDIABUS_H
12#define SOC_MEDIABUS_H
13
14#include <linux/videodev2.h>
Laurent Pinchart2ef2d5a2010-03-15 19:33:31 -030015#include <linux/v4l2-mediabus.h>
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030016
17/**
18 * enum soc_mbus_packing - data packing types on the media-bus
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -030019 * @SOC_MBUS_PACKING_NONE: no packing, bit-for-bit transfer to RAM, one
20 * sample represents one pixel
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030021 * @SOC_MBUS_PACKING_2X8_PADHI: 16 bits transferred in 2 8-bit samples, in the
22 * possibly incomplete byte high bits are padding
23 * @SOC_MBUS_PACKING_2X8_PADLO: as above, but low bits are padding
24 * @SOC_MBUS_PACKING_EXTEND16: sample width (e.g., 10 bits) has to be extended
25 * to 16 bits
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -030026 * @SOC_MBUS_PACKING_VARIABLE: compressed formats with variable packing
27 * @SOC_MBUS_PACKING_1_5X8: used for packed YUV 4:2:0 formats, where 4
28 * pixels occupy 6 bytes in RAM
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030029 */
30enum soc_mbus_packing {
31 SOC_MBUS_PACKING_NONE,
32 SOC_MBUS_PACKING_2X8_PADHI,
33 SOC_MBUS_PACKING_2X8_PADLO,
34 SOC_MBUS_PACKING_EXTEND16,
Kassey Li64149de2011-05-20 04:08:39 -030035 SOC_MBUS_PACKING_VARIABLE,
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -030036 SOC_MBUS_PACKING_1_5X8,
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030037};
38
39/**
40 * enum soc_mbus_order - sample order on the media bus
41 * @SOC_MBUS_ORDER_LE: least significant sample first
42 * @SOC_MBUS_ORDER_BE: most significant sample first
43 */
44enum soc_mbus_order {
45 SOC_MBUS_ORDER_LE,
46 SOC_MBUS_ORDER_BE,
47};
48
49/**
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030050 * enum soc_mbus_layout - planes layout in memory
51 * @SOC_MBUS_LAYOUT_PACKED: color components packed
52 * @SOC_MBUS_LAYOUT_PLANAR_2Y_U_V: YUV components stored in 3 planes (4:2:2)
53 * @SOC_MBUS_LAYOUT_PLANAR_2Y_C: YUV components stored in a luma and a
54 * chroma plane (C plane is half the size
55 * of Y plane)
56 * @SOC_MBUS_LAYOUT_PLANAR_Y_C: YUV components stored in a luma and a
57 * chroma plane (C plane is the same size
58 * as Y plane)
59 */
60enum soc_mbus_layout {
61 SOC_MBUS_LAYOUT_PACKED = 0,
62 SOC_MBUS_LAYOUT_PLANAR_2Y_U_V,
63 SOC_MBUS_LAYOUT_PLANAR_2Y_C,
64 SOC_MBUS_LAYOUT_PLANAR_Y_C,
65};
66
67/**
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030068 * struct soc_mbus_pixelfmt - Data format on the media bus
69 * @name: Name of the format
70 * @fourcc: Fourcc code, that will be obtained if the data is
71 * stored in memory in the following way:
72 * @packing: Type of sample-packing, that has to be used
73 * @order: Sample order when storing in memory
74 * @bits_per_sample: How many bits the bridge has to sample
75 */
76struct soc_mbus_pixelfmt {
77 const char *name;
78 u32 fourcc;
79 enum soc_mbus_packing packing;
80 enum soc_mbus_order order;
Laurent Pinchartad3b81f2012-03-21 08:03:23 -030081 enum soc_mbus_layout layout;
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030082 u8 bits_per_sample;
83};
84
Guennadi Liakhovetski93f116d2011-05-13 13:21:36 -030085/**
86 * struct soc_mbus_lookup - Lookup FOURCC IDs by mediabus codes for pass-through
87 * @code: mediabus pixel-code
88 * @fmt: pixel format description
89 */
90struct soc_mbus_lookup {
91 enum v4l2_mbus_pixelcode code;
92 struct soc_mbus_pixelfmt fmt;
93};
94
95const struct soc_mbus_pixelfmt *soc_mbus_find_fmtdesc(
96 enum v4l2_mbus_pixelcode code,
97 const struct soc_mbus_lookup *lookup,
98 int n);
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -030099const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
100 enum v4l2_mbus_pixelcode code);
101s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf);
Laurent Pinchart8929c962012-03-21 08:03:25 -0300102s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf,
103 u32 bytes_per_line, u32 height);
Guennadi Liakhovetskicc552b62011-05-20 04:25:09 -0300104int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf,
105 unsigned int *numerator, unsigned int *denominator);
Guennadi Liakhovetski32c69fcc2011-07-26 11:38:01 -0300106unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
107 unsigned int flags);
Guennadi Liakhovetski9a742512009-12-11 11:41:28 -0300108
109#endif