1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Copyright (c) 2011-2018 Magewell Electronics Co., Ltd. (Nanjing) 4 * All rights reserved. 5 * Author: Yong Deng <yong.deng@magewell.com> 6 */ 7 8 #ifndef __SUN6I_CSI_H__ 9 #define __SUN6I_CSI_H__ 10 11 #include <media/v4l2-ctrls.h> 12 #include <media/v4l2-device.h> 13 #include <media/v4l2-fwnode.h> 14 15 #include "sun6i_video.h" 16 17 struct sun6i_csi; 18 19 /** 20 * struct sun6i_csi_config - configs for sun6i csi 21 * @pixelformat: v4l2 pixel format (V4L2_PIX_FMT_*) 22 * @code: media bus format code (MEDIA_BUS_FMT_*) 23 * @field: used interlacing type (enum v4l2_field) 24 * @width: frame width 25 * @height: frame height 26 */ 27 struct sun6i_csi_config { 28 u32 pixelformat; 29 u32 code; 30 u32 field; 31 u32 width; 32 u32 height; 33 }; 34 35 struct sun6i_csi { 36 struct device *dev; 37 struct v4l2_ctrl_handler ctrl_handler; 38 struct v4l2_device v4l2_dev; 39 struct media_device media_dev; 40 41 struct v4l2_async_notifier notifier; 42 43 /* video port settings */ 44 struct v4l2_fwnode_endpoint v4l2_ep; 45 46 struct sun6i_csi_config config; 47 48 struct sun6i_video video; 49 }; 50 51 /** 52 * sun6i_csi_is_format_supported() - check if the format supported by csi 53 * @csi: pointer to the csi 54 * @pixformat: v4l2 pixel format (V4L2_PIX_FMT_*) 55 * @mbus_code: media bus format code (MEDIA_BUS_FMT_*) 56 */ 57 bool sun6i_csi_is_format_supported(struct sun6i_csi *csi, u32 pixformat, 58 u32 mbus_code); 59 60 /** 61 * sun6i_csi_set_power() - power on/off the csi 62 * @csi: pointer to the csi 63 * @enable: on/off 64 */ 65 int sun6i_csi_set_power(struct sun6i_csi *csi, bool enable); 66 67 /** 68 * sun6i_csi_update_config() - update the csi register settings 69 * @csi: pointer to the csi 70 * @config: see struct sun6i_csi_config 71 */ 72 int sun6i_csi_update_config(struct sun6i_csi *csi, 73 struct sun6i_csi_config *config); 74 75 /** 76 * sun6i_csi_update_buf_addr() - update the csi frame buffer address 77 * @csi: pointer to the csi 78 * @addr: frame buffer's physical address 79 */ 80 void sun6i_csi_update_buf_addr(struct sun6i_csi *csi, dma_addr_t addr); 81 82 /** 83 * sun6i_csi_set_stream() - start/stop csi streaming 84 * @csi: pointer to the csi 85 * @enable: start/stop 86 */ 87 void sun6i_csi_set_stream(struct sun6i_csi *csi, bool enable); 88 89 /* get bpp form v4l2 pixformat */ 90 static inline int sun6i_csi_get_bpp(unsigned int pixformat) 91 { 92 switch (pixformat) { 93 case V4L2_PIX_FMT_SBGGR8: 94 case V4L2_PIX_FMT_SGBRG8: 95 case V4L2_PIX_FMT_SGRBG8: 96 case V4L2_PIX_FMT_SRGGB8: 97 case V4L2_PIX_FMT_JPEG: 98 return 8; 99 case V4L2_PIX_FMT_SBGGR10: 100 case V4L2_PIX_FMT_SGBRG10: 101 case V4L2_PIX_FMT_SGRBG10: 102 case V4L2_PIX_FMT_SRGGB10: 103 return 10; 104 case V4L2_PIX_FMT_SBGGR12: 105 case V4L2_PIX_FMT_SGBRG12: 106 case V4L2_PIX_FMT_SGRBG12: 107 case V4L2_PIX_FMT_SRGGB12: 108 case V4L2_PIX_FMT_HM12: 109 case V4L2_PIX_FMT_NV12: 110 case V4L2_PIX_FMT_NV21: 111 case V4L2_PIX_FMT_YUV420: 112 case V4L2_PIX_FMT_YVU420: 113 return 12; 114 case V4L2_PIX_FMT_YUYV: 115 case V4L2_PIX_FMT_YVYU: 116 case V4L2_PIX_FMT_UYVY: 117 case V4L2_PIX_FMT_VYUY: 118 case V4L2_PIX_FMT_NV16: 119 case V4L2_PIX_FMT_NV61: 120 case V4L2_PIX_FMT_YUV422P: 121 case V4L2_PIX_FMT_RGB565: 122 case V4L2_PIX_FMT_RGB565X: 123 return 16; 124 case V4L2_PIX_FMT_RGB24: 125 case V4L2_PIX_FMT_BGR24: 126 return 24; 127 case V4L2_PIX_FMT_RGB32: 128 case V4L2_PIX_FMT_BGR32: 129 return 32; 130 default: 131 WARN(1, "Unsupported pixformat: 0x%x\n", pixformat); 132 break; 133 } 134 135 return 0; 136 } 137 138 #endif /* __SUN6I_CSI_H__ */ 139