1 /* 2 * linux-5.4/drivers/media/platform/sunxi-vin/utility/bsp_common.c 3 * 4 * Copyright (c) 2007-2017 Allwinnertech Co., Ltd. 5 * 6 * This software is licensed under the terms of the GNU General Public 7 * License version 2, as published by the Free Software Foundation, and 8 * may be copied, distributed, and modified under those terms. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 */ 16 #if 0 17 #include "bsp_common.h" 18 19 enum bus_pixeltype find_bus_type(u32 code) 20 { 21 switch (code) { 22 case MEDIA_BUS_FMT_BGR565_2X8_BE: 23 case MEDIA_BUS_FMT_BGR565_2X8_LE: 24 case MEDIA_BUS_FMT_RGB565_2X8_BE: 25 case MEDIA_BUS_FMT_RGB565_2X8_LE: 26 return BUS_FMT_RGB565; 27 case MEDIA_BUS_FMT_UYVY8_2X8: 28 case MEDIA_BUS_FMT_UYVY8_1X16: 29 return BUS_FMT_UYVY; 30 case MEDIA_BUS_FMT_VYUY8_2X8: 31 case MEDIA_BUS_FMT_VYUY8_1X16: 32 return BUS_FMT_VYUY; 33 case MEDIA_BUS_FMT_YUYV8_2X8: 34 case MEDIA_BUS_FMT_YUYV10_2X10: 35 case MEDIA_BUS_FMT_YUYV8_1X16: 36 case MEDIA_BUS_FMT_YUYV10_1X20: 37 return BUS_FMT_YUYV; 38 case MEDIA_BUS_FMT_YVYU8_2X8: 39 case MEDIA_BUS_FMT_YVYU10_2X10: 40 case MEDIA_BUS_FMT_YVYU8_1X16: 41 case MEDIA_BUS_FMT_YVYU10_1X20: 42 return BUS_FMT_YVYU; 43 case MEDIA_BUS_FMT_SBGGR8_1X8: 44 case MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8: 45 case MEDIA_BUS_FMT_SBGGR10_1X10: 46 case MEDIA_BUS_FMT_SBGGR12_1X12: 47 return BUS_FMT_SBGGR; 48 case MEDIA_BUS_FMT_SGBRG8_1X8: 49 case MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8: 50 case MEDIA_BUS_FMT_SGBRG10_1X10: 51 case MEDIA_BUS_FMT_SGBRG12_1X12: 52 return BUS_FMT_SGBRG; 53 case MEDIA_BUS_FMT_SGRBG8_1X8: 54 case MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8: 55 case MEDIA_BUS_FMT_SGRBG10_1X10: 56 case MEDIA_BUS_FMT_SGRBG12_1X12: 57 return BUS_FMT_SGRBG; 58 case MEDIA_BUS_FMT_SRGGB8_1X8: 59 case MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8: 60 case MEDIA_BUS_FMT_SRGGB10_1X10: 61 case MEDIA_BUS_FMT_SRGGB12_1X12: 62 return BUS_FMT_SRGGB; 63 default: 64 return BUS_FMT_UYVY; 65 } 66 } 67 68 enum bit_width find_bus_width(u32 code) 69 { 70 switch (code) { 71 case MEDIA_BUS_FMT_BGR565_2X8_BE: 72 case MEDIA_BUS_FMT_BGR565_2X8_LE: 73 case MEDIA_BUS_FMT_RGB565_2X8_BE: 74 case MEDIA_BUS_FMT_RGB565_2X8_LE: 75 case MEDIA_BUS_FMT_UYVY8_2X8: 76 case MEDIA_BUS_FMT_VYUY8_2X8: 77 case MEDIA_BUS_FMT_YUYV8_2X8: 78 case MEDIA_BUS_FMT_YVYU8_2X8: 79 case MEDIA_BUS_FMT_SBGGR8_1X8: 80 case MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8: 81 case MEDIA_BUS_FMT_SGBRG8_1X8: 82 case MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8: 83 case MEDIA_BUS_FMT_SGRBG8_1X8: 84 case MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8: 85 case MEDIA_BUS_FMT_SRGGB8_1X8: 86 case MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8: 87 return W_8BIT; 88 case MEDIA_BUS_FMT_YUYV10_2X10: 89 case MEDIA_BUS_FMT_YVYU10_2X10: 90 case MEDIA_BUS_FMT_SBGGR10_1X10: 91 case MEDIA_BUS_FMT_SGBRG10_1X10: 92 case MEDIA_BUS_FMT_SGRBG10_1X10: 93 case MEDIA_BUS_FMT_SRGGB10_1X10: 94 return W_10BIT; 95 case MEDIA_BUS_FMT_SBGGR12_1X12: 96 case MEDIA_BUS_FMT_SGBRG12_1X12: 97 case MEDIA_BUS_FMT_SGRBG12_1X12: 98 case MEDIA_BUS_FMT_SRGGB12_1X12: 99 return W_12BIT; 100 case MEDIA_BUS_FMT_UYVY8_1X16: 101 case MEDIA_BUS_FMT_VYUY8_1X16: 102 case MEDIA_BUS_FMT_YUYV8_1X16: 103 case MEDIA_BUS_FMT_YVYU8_1X16: 104 return W_16BIT; 105 case MEDIA_BUS_FMT_YVYU10_1X20: 106 case MEDIA_BUS_FMT_YUYV10_1X20: 107 return W_20BIT; 108 default: 109 return W_8BIT; 110 } 111 } 112 113 enum bit_width find_bus_precision(u32 code) 114 { 115 switch (code) { 116 case MEDIA_BUS_FMT_BGR565_2X8_BE: 117 case MEDIA_BUS_FMT_BGR565_2X8_LE: 118 case MEDIA_BUS_FMT_RGB565_2X8_BE: 119 case MEDIA_BUS_FMT_RGB565_2X8_LE: 120 case MEDIA_BUS_FMT_SBGGR8_1X8: 121 case MEDIA_BUS_FMT_SGBRG8_1X8: 122 case MEDIA_BUS_FMT_SGRBG8_1X8: 123 case MEDIA_BUS_FMT_SRGGB8_1X8: 124 case MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8: 125 case MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8: 126 case MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8: 127 case MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8: 128 case MEDIA_BUS_FMT_UYVY8_2X8: 129 case MEDIA_BUS_FMT_VYUY8_2X8: 130 case MEDIA_BUS_FMT_YUYV8_2X8: 131 case MEDIA_BUS_FMT_YVYU8_2X8: 132 case MEDIA_BUS_FMT_UYVY8_1X16: 133 case MEDIA_BUS_FMT_VYUY8_1X16: 134 case MEDIA_BUS_FMT_YUYV8_1X16: 135 case MEDIA_BUS_FMT_YVYU8_1X16: 136 return W_8BIT; 137 case MEDIA_BUS_FMT_SBGGR10_1X10: 138 case MEDIA_BUS_FMT_SGBRG10_1X10: 139 case MEDIA_BUS_FMT_SGRBG10_1X10: 140 case MEDIA_BUS_FMT_SRGGB10_1X10: 141 case MEDIA_BUS_FMT_YUYV10_2X10: 142 case MEDIA_BUS_FMT_YVYU10_2X10: 143 case MEDIA_BUS_FMT_YVYU10_1X20: 144 case MEDIA_BUS_FMT_YUYV10_1X20: 145 return W_10BIT; 146 case MEDIA_BUS_FMT_SBGGR12_1X12: 147 case MEDIA_BUS_FMT_SGBRG12_1X12: 148 case MEDIA_BUS_FMT_SGRBG12_1X12: 149 case MEDIA_BUS_FMT_SRGGB12_1X12: 150 return W_12BIT; 151 default: 152 return W_8BIT; 153 } 154 } 155 156 enum pixel_fmt_type find_pixel_fmt_type(unsigned int pix_fmt) 157 { 158 switch (pix_fmt) { 159 case V4L2_PIX_FMT_RGB565: 160 return RGB565; 161 case V4L2_PIX_FMT_RGB24: 162 return RGB888; 163 case V4L2_PIX_FMT_RGB32: 164 return PRGB888; 165 case V4L2_PIX_FMT_YUYV: 166 case V4L2_PIX_FMT_YVYU: 167 case V4L2_PIX_FMT_UYVY: 168 case V4L2_PIX_FMT_VYUY: 169 return YUV422_INTLVD; 170 case V4L2_PIX_FMT_YUV422P: 171 return YUV422_PL; 172 case V4L2_PIX_FMT_YUV420: 173 case V4L2_PIX_FMT_YVU420: 174 case V4L2_PIX_FMT_YUV420M: 175 case V4L2_PIX_FMT_YVU420M: 176 return YUV420_PL; 177 case V4L2_PIX_FMT_NV12: 178 case V4L2_PIX_FMT_NV21: 179 case V4L2_PIX_FMT_NV12M: 180 case V4L2_PIX_FMT_NV21M: 181 return YUV420_SPL; 182 case V4L2_PIX_FMT_NV16: 183 case V4L2_PIX_FMT_NV61: 184 return YUV422_SPL; 185 case V4L2_PIX_FMT_SBGGR8: 186 case V4L2_PIX_FMT_SGBRG8: 187 case V4L2_PIX_FMT_SGRBG8: 188 case V4L2_PIX_FMT_SRGGB8: 189 case V4L2_PIX_FMT_SBGGR10: 190 case V4L2_PIX_FMT_SGBRG10: 191 case V4L2_PIX_FMT_SGRBG10: 192 case V4L2_PIX_FMT_SRGGB10: 193 case V4L2_PIX_FMT_SBGGR12: 194 case V4L2_PIX_FMT_SGBRG12: 195 case V4L2_PIX_FMT_SGRBG12: 196 case V4L2_PIX_FMT_SRGGB12: 197 return BAYER_RGB; 198 default: 199 return BAYER_RGB; 200 } 201 } 202 #endif 203