linux/drivers/media/video/soc_mediabus.c
<<
>>
Prefs
   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
  20static const struct soc_mbus_pixelfmt mbus_fmt[] = {
  21        [MBUS_IDX(YUYV8_2X8_LE)] = {
  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,
  27        },
  28        [MBUS_IDX(YVYU8_2X8_LE)] = {
  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,
  34        },
  35        [MBUS_IDX(YUYV8_2X8_BE)] = {
  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,
  41        },
  42        [MBUS_IDX(YVYU8_2X8_BE)] = {
  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,
  48        },
  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,
  55        },
  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,
  62        },
  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,
  69        },
  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,
  76        },
  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,
  83        },
  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,
  90        },
  91        [MBUS_IDX(GREY8_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,
  97        },
  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,
 104        },
 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,
 111        },
 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,
 118        },
 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,
 125        },
 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,
 132        },
 133};
 134
 135s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf)
 136{
 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:
 143                return width * 2;
 144        }
 145        return -EINVAL;
 146}
 147EXPORT_SYMBOL(soc_mbus_bytes_per_line);
 148
 149const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
 150        enum v4l2_mbus_pixelcode code)
 151{
 152        if (code - V4L2_MBUS_FMT_FIXED > ARRAY_SIZE(mbus_fmt) ||
 153            code <= V4L2_MBUS_FMT_FIXED)
 154                return NULL;
 155        return mbus_fmt + code - V4L2_MBUS_FMT_FIXED - 1;
 156}
 157EXPORT_SYMBOL(soc_mbus_get_fmtdesc);
 158
 159static int __init soc_mbus_init(void)
 160{
 161        return 0;
 162}
 163
 164static void __exit soc_mbus_exit(void)
 165{
 166}
 167
 168module_init(soc_mbus_init);
 169module_exit(soc_mbus_exit);
 170
 171MODULE_DESCRIPTION("soc-camera media bus interface");
 172MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
 173MODULE_LICENSE("GPL v2");
 174