2 * soc-camera media bus helper routines
4 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
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.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <media/v4l2-device.h>
15 #include <media/v4l2-mediabus.h>
16 #include <media/soc_mediabus.h>
18 #define MBUS_IDX(f) (V4L2_MBUS_FMT_ ## f - V4L2_MBUS_FMT_FIXED - 1)
20 static const struct soc_mbus_pixelfmt mbus_fmt
[] = {
21 [MBUS_IDX(YUYV8_2X8
)] = {
22 .fourcc
= V4L2_PIX_FMT_YUYV
,
25 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
26 .order
= SOC_MBUS_ORDER_LE
,
28 [MBUS_IDX(YVYU8_2X8
)] = {
29 .fourcc
= V4L2_PIX_FMT_YVYU
,
32 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
33 .order
= SOC_MBUS_ORDER_LE
,
35 [MBUS_IDX(UYVY8_2X8
)] = {
36 .fourcc
= V4L2_PIX_FMT_UYVY
,
39 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
40 .order
= SOC_MBUS_ORDER_LE
,
42 [MBUS_IDX(VYUY8_2X8
)] = {
43 .fourcc
= V4L2_PIX_FMT_VYUY
,
46 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
47 .order
= SOC_MBUS_ORDER_LE
,
49 [MBUS_IDX(RGB555_2X8_PADHI_LE
)] = {
50 .fourcc
= V4L2_PIX_FMT_RGB555
,
53 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
54 .order
= SOC_MBUS_ORDER_LE
,
56 [MBUS_IDX(RGB555_2X8_PADHI_BE
)] = {
57 .fourcc
= V4L2_PIX_FMT_RGB555X
,
60 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
61 .order
= SOC_MBUS_ORDER_LE
,
63 [MBUS_IDX(RGB565_2X8_LE
)] = {
64 .fourcc
= V4L2_PIX_FMT_RGB565
,
67 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
68 .order
= SOC_MBUS_ORDER_LE
,
70 [MBUS_IDX(RGB565_2X8_BE
)] = {
71 .fourcc
= V4L2_PIX_FMT_RGB565X
,
74 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
75 .order
= SOC_MBUS_ORDER_LE
,
77 [MBUS_IDX(SBGGR8_1X8
)] = {
78 .fourcc
= V4L2_PIX_FMT_SBGGR8
,
79 .name
= "Bayer 8 BGGR",
81 .packing
= SOC_MBUS_PACKING_NONE
,
82 .order
= SOC_MBUS_ORDER_LE
,
84 [MBUS_IDX(SBGGR10_1X10
)] = {
85 .fourcc
= V4L2_PIX_FMT_SBGGR10
,
86 .name
= "Bayer 10 BGGR",
87 .bits_per_sample
= 10,
88 .packing
= SOC_MBUS_PACKING_EXTEND16
,
89 .order
= SOC_MBUS_ORDER_LE
,
91 [MBUS_IDX(GREY8_1X8
)] = {
92 .fourcc
= V4L2_PIX_FMT_GREY
,
95 .packing
= SOC_MBUS_PACKING_NONE
,
96 .order
= SOC_MBUS_ORDER_LE
,
98 [MBUS_IDX(Y10_1X10
)] = {
99 .fourcc
= V4L2_PIX_FMT_Y10
,
100 .name
= "Grey 10bit",
101 .bits_per_sample
= 10,
102 .packing
= SOC_MBUS_PACKING_EXTEND16
,
103 .order
= SOC_MBUS_ORDER_LE
,
105 [MBUS_IDX(SBGGR10_2X8_PADHI_LE
)] = {
106 .fourcc
= V4L2_PIX_FMT_SBGGR10
,
107 .name
= "Bayer 10 BGGR",
108 .bits_per_sample
= 8,
109 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
110 .order
= SOC_MBUS_ORDER_LE
,
112 [MBUS_IDX(SBGGR10_2X8_PADLO_LE
)] = {
113 .fourcc
= V4L2_PIX_FMT_SBGGR10
,
114 .name
= "Bayer 10 BGGR",
115 .bits_per_sample
= 8,
116 .packing
= SOC_MBUS_PACKING_2X8_PADLO
,
117 .order
= SOC_MBUS_ORDER_LE
,
119 [MBUS_IDX(SBGGR10_2X8_PADHI_BE
)] = {
120 .fourcc
= V4L2_PIX_FMT_SBGGR10
,
121 .name
= "Bayer 10 BGGR",
122 .bits_per_sample
= 8,
123 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
124 .order
= SOC_MBUS_ORDER_BE
,
126 [MBUS_IDX(SBGGR10_2X8_PADLO_BE
)] = {
127 .fourcc
= V4L2_PIX_FMT_SBGGR10
,
128 .name
= "Bayer 10 BGGR",
129 .bits_per_sample
= 8,
130 .packing
= SOC_MBUS_PACKING_2X8_PADLO
,
131 .order
= SOC_MBUS_ORDER_BE
,
135 s32
soc_mbus_bytes_per_line(u32 width
, const struct soc_mbus_pixelfmt
*mf
)
137 switch (mf
->packing
) {
138 case SOC_MBUS_PACKING_NONE
:
139 return width
* mf
->bits_per_sample
/ 8;
140 case SOC_MBUS_PACKING_2X8_PADHI
:
141 case SOC_MBUS_PACKING_2X8_PADLO
:
142 case SOC_MBUS_PACKING_EXTEND16
:
147 EXPORT_SYMBOL(soc_mbus_bytes_per_line
);
149 const struct soc_mbus_pixelfmt
*soc_mbus_get_fmtdesc(
150 enum v4l2_mbus_pixelcode code
)
152 if (code
- V4L2_MBUS_FMT_FIXED
> ARRAY_SIZE(mbus_fmt
) ||
153 code
<= V4L2_MBUS_FMT_FIXED
)
155 return mbus_fmt
+ code
- V4L2_MBUS_FMT_FIXED
- 1;
157 EXPORT_SYMBOL(soc_mbus_get_fmtdesc
);
159 static int __init
soc_mbus_init(void)
164 static void __exit
soc_mbus_exit(void)
168 module_init(soc_mbus_init
);
169 module_exit(soc_mbus_exit
);
171 MODULE_DESCRIPTION("soc-camera media bus interface");
172 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
173 MODULE_LICENSE("GPL v2");