sfc: Don't use enums as a bitmask.
[zen-stable.git] / drivers / media / video / soc_mediabus.c
blobed77aa055b633713f696cacb4612857cfa18c308
1 /*
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.
9 */
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,
23 .name = "YUYV",
24 .bits_per_sample = 8,
25 .packing = SOC_MBUS_PACKING_2X8_PADHI,
26 .order = SOC_MBUS_ORDER_LE,
28 [MBUS_IDX(YVYU8_2X8)] = {
29 .fourcc = V4L2_PIX_FMT_YVYU,
30 .name = "YVYU",
31 .bits_per_sample = 8,
32 .packing = SOC_MBUS_PACKING_2X8_PADHI,
33 .order = SOC_MBUS_ORDER_LE,
35 [MBUS_IDX(UYVY8_2X8)] = {
36 .fourcc = V4L2_PIX_FMT_UYVY,
37 .name = "UYVY",
38 .bits_per_sample = 8,
39 .packing = SOC_MBUS_PACKING_2X8_PADHI,
40 .order = SOC_MBUS_ORDER_LE,
42 [MBUS_IDX(VYUY8_2X8)] = {
43 .fourcc = V4L2_PIX_FMT_VYUY,
44 .name = "VYUY",
45 .bits_per_sample = 8,
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,
51 .name = "RGB555",
52 .bits_per_sample = 8,
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,
58 .name = "RGB555X",
59 .bits_per_sample = 8,
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,
65 .name = "RGB565",
66 .bits_per_sample = 8,
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,
72 .name = "RGB565X",
73 .bits_per_sample = 8,
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",
80 .bits_per_sample = 8,
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(Y8_1X8)] = {
92 .fourcc = V4L2_PIX_FMT_GREY,
93 .name = "Grey",
94 .bits_per_sample = 8,
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 int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf)
137 switch (mf->packing) {
138 case SOC_MBUS_PACKING_NONE:
139 case SOC_MBUS_PACKING_EXTEND16:
140 return 1;
141 case SOC_MBUS_PACKING_2X8_PADHI:
142 case SOC_MBUS_PACKING_2X8_PADLO:
143 return 2;
145 return -EINVAL;
147 EXPORT_SYMBOL(soc_mbus_samples_per_pixel);
149 s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf)
151 switch (mf->packing) {
152 case SOC_MBUS_PACKING_NONE:
153 return width * mf->bits_per_sample / 8;
154 case SOC_MBUS_PACKING_2X8_PADHI:
155 case SOC_MBUS_PACKING_2X8_PADLO:
156 case SOC_MBUS_PACKING_EXTEND16:
157 return width * 2;
159 return -EINVAL;
161 EXPORT_SYMBOL(soc_mbus_bytes_per_line);
163 const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
164 enum v4l2_mbus_pixelcode code)
166 if (code - V4L2_MBUS_FMT_FIXED > ARRAY_SIZE(mbus_fmt) ||
167 code <= V4L2_MBUS_FMT_FIXED)
168 return NULL;
169 return mbus_fmt + code - V4L2_MBUS_FMT_FIXED - 1;
171 EXPORT_SYMBOL(soc_mbus_get_fmtdesc);
173 static int __init soc_mbus_init(void)
175 return 0;
178 static void __exit soc_mbus_exit(void)
182 module_init(soc_mbus_init);
183 module_exit(soc_mbus_exit);
185 MODULE_DESCRIPTION("soc-camera media bus interface");
186 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
187 MODULE_LICENSE("GPL v2");