Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | #define MBUS_IDX(f) (V4L2_MBUS_FMT_ ## f - V4L2_MBUS_FMT_FIXED - 1) |
| 19 | |
| 20 | static const struct soc_mbus_pixelfmt mbus_fmt[] = { |
Guennadi Liakhovetski | ace6e97 | 2010-07-22 16:52:51 -0300 | [diff] [blame] | 21 | [MBUS_IDX(YUYV8_2X8)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 27 | }, |
Guennadi Liakhovetski | ace6e97 | 2010-07-22 16:52:51 -0300 | [diff] [blame] | 28 | [MBUS_IDX(YVYU8_2X8)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 34 | }, |
Guennadi Liakhovetski | ace6e97 | 2010-07-22 16:52:51 -0300 | [diff] [blame] | 35 | [MBUS_IDX(UYVY8_2X8)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 41 | }, |
Guennadi Liakhovetski | ace6e97 | 2010-07-22 16:52:51 -0300 | [diff] [blame] | 42 | [MBUS_IDX(VYUY8_2X8)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 48 | }, |
| 49 | [MBUS_IDX(RGB555_2X8_PADHI_LE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 55 | }, |
| 56 | [MBUS_IDX(RGB555_2X8_PADHI_BE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 62 | }, |
| 63 | [MBUS_IDX(RGB565_2X8_LE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 69 | }, |
| 70 | [MBUS_IDX(RGB565_2X8_BE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 76 | }, |
| 77 | [MBUS_IDX(SBGGR8_1X8)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 83 | }, |
| 84 | [MBUS_IDX(SBGGR10_1X10)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 90 | }, |
Laurent Pinchart | 07670433 | 2010-09-28 07:01:44 -0300 | [diff] [blame^] | 91 | [MBUS_IDX(Y8_1X8)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 97 | }, |
| 98 | [MBUS_IDX(Y10_1X10)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 104 | }, |
| 105 | [MBUS_IDX(SBGGR10_2X8_PADHI_LE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 111 | }, |
| 112 | [MBUS_IDX(SBGGR10_2X8_PADLO_LE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 118 | }, |
| 119 | [MBUS_IDX(SBGGR10_2X8_PADHI_BE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
Guennadi Liakhovetski | 81355e4 | 2009-12-24 14:12:15 +0100 | [diff] [blame] | 125 | }, |
| 126 | [MBUS_IDX(SBGGR10_2X8_PADLO_BE)] = { |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 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, |
| 132 | }, |
| 133 | }; |
| 134 | |
Alberto Panizzo | 48a3c77 | 2011-01-12 08:16:19 -0300 | [diff] [blame] | 135 | int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf) |
| 136 | { |
| 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; |
| 144 | } |
| 145 | return -EINVAL; |
| 146 | } |
| 147 | EXPORT_SYMBOL(soc_mbus_samples_per_pixel); |
| 148 | |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 149 | s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf) |
| 150 | { |
| 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; |
| 158 | } |
| 159 | return -EINVAL; |
| 160 | } |
| 161 | EXPORT_SYMBOL(soc_mbus_bytes_per_line); |
| 162 | |
| 163 | const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc( |
| 164 | enum v4l2_mbus_pixelcode code) |
| 165 | { |
Baruch Siach | 84f3751 | 2010-02-19 14:09:25 -0300 | [diff] [blame] | 166 | if (code - V4L2_MBUS_FMT_FIXED > ARRAY_SIZE(mbus_fmt) || |
| 167 | code <= V4L2_MBUS_FMT_FIXED) |
Guennadi Liakhovetski | 9a74251 | 2009-12-11 11:41:28 -0300 | [diff] [blame] | 168 | return NULL; |
| 169 | return mbus_fmt + code - V4L2_MBUS_FMT_FIXED - 1; |
| 170 | } |
| 171 | EXPORT_SYMBOL(soc_mbus_get_fmtdesc); |
| 172 | |
| 173 | static int __init soc_mbus_init(void) |
| 174 | { |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static void __exit soc_mbus_exit(void) |
| 179 | { |
| 180 | } |
| 181 | |
| 182 | module_init(soc_mbus_init); |
| 183 | module_exit(soc_mbus_exit); |
| 184 | |
| 185 | MODULE_DESCRIPTION("soc-camera media bus interface"); |
| 186 | MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>"); |
| 187 | MODULE_LICENSE("GPL v2"); |