fimc-isp.h (5601B)
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver 4 * 5 * Copyright (C) 2013 Samsung Electronics Co., Ltd. 6 * 7 * Authors: Sylwester Nawrocki <s.nawrocki@samsung.com> 8 * Younghwan Joo <yhwan.joo@samsung.com> 9 */ 10#ifndef FIMC_ISP_H_ 11#define FIMC_ISP_H_ 12 13#include <linux/io.h> 14#include <linux/platform_device.h> 15#include <linux/sched.h> 16#include <linux/spinlock.h> 17#include <linux/types.h> 18#include <linux/videodev2.h> 19 20#include <media/media-entity.h> 21#include <media/videobuf2-v4l2.h> 22#include <media/v4l2-device.h> 23#include <media/v4l2-mediabus.h> 24#include <media/drv-intf/exynos-fimc.h> 25 26extern int fimc_isp_debug; 27 28#define isp_dbg(level, dev, fmt, arg...) \ 29 v4l2_dbg(level, fimc_isp_debug, dev, fmt, ## arg) 30 31/* FIXME: revisit these constraints */ 32#define FIMC_ISP_SINK_WIDTH_MIN (16 + 8) 33#define FIMC_ISP_SINK_HEIGHT_MIN (12 + 8) 34#define FIMC_ISP_SOURCE_WIDTH_MIN 8 35#define FIMC_ISP_SOURCE_HEIGHT_MIN 8 36#define FIMC_ISP_CAC_MARGIN_WIDTH 16 37#define FIMC_ISP_CAC_MARGIN_HEIGHT 12 38 39#define FIMC_ISP_SINK_WIDTH_MAX (4000 - 16) 40#define FIMC_ISP_SINK_HEIGHT_MAX (4000 + 12) 41#define FIMC_ISP_SOURCE_WIDTH_MAX 4000 42#define FIMC_ISP_SOURCE_HEIGHT_MAX 4000 43 44#define FIMC_ISP_NUM_FORMATS 3 45#define FIMC_ISP_REQ_BUFS_MIN 2 46#define FIMC_ISP_REQ_BUFS_MAX 32 47 48#define FIMC_ISP_SD_PAD_SINK 0 49#define FIMC_ISP_SD_PAD_SRC_FIFO 1 50#define FIMC_ISP_SD_PAD_SRC_DMA 2 51#define FIMC_ISP_SD_PADS_NUM 3 52#define FIMC_ISP_MAX_PLANES 1 53 54/** 55 * struct fimc_isp_frame - source/target frame properties 56 * @width: full image width 57 * @height: full image height 58 * @rect: crop/composition rectangle 59 */ 60struct fimc_isp_frame { 61 u16 width; 62 u16 height; 63 struct v4l2_rect rect; 64}; 65 66struct fimc_isp_ctrls { 67 struct v4l2_ctrl_handler handler; 68 69 /* Auto white balance */ 70 struct v4l2_ctrl *auto_wb; 71 /* Auto ISO control cluster */ 72 struct { 73 struct v4l2_ctrl *auto_iso; 74 struct v4l2_ctrl *iso; 75 }; 76 /* Adjust - contrast */ 77 struct v4l2_ctrl *contrast; 78 /* Adjust - saturation */ 79 struct v4l2_ctrl *saturation; 80 /* Adjust - sharpness */ 81 struct v4l2_ctrl *sharpness; 82 /* Adjust - brightness */ 83 struct v4l2_ctrl *brightness; 84 /* Adjust - hue */ 85 struct v4l2_ctrl *hue; 86 87 /* Auto/manual exposure */ 88 struct v4l2_ctrl *auto_exp; 89 /* Manual exposure value */ 90 struct v4l2_ctrl *exposure; 91 /* AE/AWB lock/unlock */ 92 struct v4l2_ctrl *aewb_lock; 93 /* Exposure metering mode */ 94 struct v4l2_ctrl *exp_metering; 95 /* AFC */ 96 struct v4l2_ctrl *afc; 97 /* ISP image effect */ 98 struct v4l2_ctrl *colorfx; 99}; 100 101struct isp_video_buf { 102 struct vb2_v4l2_buffer vb; 103 dma_addr_t dma_addr[FIMC_ISP_MAX_PLANES]; 104 unsigned int index; 105}; 106 107#define to_isp_video_buf(_b) container_of(_b, struct isp_video_buf, vb) 108 109#define FIMC_ISP_MAX_BUFS 4 110 111/** 112 * struct fimc_is_video - fimc-is video device structure 113 * @ve: video_device structure and media pipeline 114 * @type: video device type (CAPTURE/OUTPUT) 115 * @pad: video device media (sink) pad 116 * @pending_buf_q: pending buffers queue head 117 * @active_buf_q: a queue head of buffers scheduled in hardware 118 * @vb_queue: vb2 buffer queue 119 * @reqbufs_count: the number of buffers requested in REQBUFS ioctl 120 * @buf_count: number of video buffers scheduled in hardware 121 * @buf_mask: bitmask of the queued video buffer indices 122 * @frame_count: counter of frames dequeued to user space 123 * @streaming: is streaming in progress? 124 * @buffers: buffer info 125 * @format: current fimc pixel format 126 * @pixfmt: current pixel format 127 */ 128struct fimc_is_video { 129 struct exynos_video_entity ve; 130 enum v4l2_buf_type type; 131 struct media_pad pad; 132 struct list_head pending_buf_q; 133 struct list_head active_buf_q; 134 struct vb2_queue vb_queue; 135 unsigned int reqbufs_count; 136 unsigned int buf_count; 137 unsigned int buf_mask; 138 unsigned int frame_count; 139 int streaming; 140 struct isp_video_buf *buffers[FIMC_ISP_MAX_BUFS]; 141 const struct fimc_fmt *format; 142 struct v4l2_pix_format_mplane pixfmt; 143}; 144 145/* struct fimc_isp:state bit definitions */ 146#define ST_ISP_VID_CAP_BUF_PREP 0 147#define ST_ISP_VID_CAP_STREAMING 1 148 149/** 150 * struct fimc_isp - FIMC-IS ISP data structure 151 * @pdev: pointer to FIMC-IS platform device 152 * @subdev: ISP v4l2_subdev 153 * @subdev_pads: the ISP subdev media pads 154 * @src_fmt: source mediabus format 155 * @sink_fmt: sink mediabus format 156 * @test_pattern: test pattern controls 157 * @ctrls: v4l2 controls structure 158 * @video_lock: mutex serializing video device operations 159 * @subdev_lock: mutex serializing subdev operations 160 * @cac_margin_x: horizontal CAC margin in pixels 161 * @cac_margin_y: vertical CAC margin in pixels 162 * @state: driver state flags 163 * @video_capture: the ISP block video capture device 164 */ 165struct fimc_isp { 166 struct platform_device *pdev; 167 struct v4l2_subdev subdev; 168 struct media_pad subdev_pads[FIMC_ISP_SD_PADS_NUM]; 169 struct v4l2_mbus_framefmt src_fmt; 170 struct v4l2_mbus_framefmt sink_fmt; 171 struct v4l2_ctrl *test_pattern; 172 struct fimc_isp_ctrls ctrls; 173 174 struct mutex video_lock; 175 struct mutex subdev_lock; 176 177 unsigned int cac_margin_x; 178 unsigned int cac_margin_y; 179 180 unsigned long state; 181 182 struct fimc_is_video video_capture; 183}; 184 185#define ctrl_to_fimc_isp(_ctrl) \ 186 container_of(ctrl->handler, struct fimc_isp, ctrls.handler) 187 188struct fimc_is; 189 190int fimc_isp_subdev_create(struct fimc_isp *isp); 191void fimc_isp_subdev_destroy(struct fimc_isp *isp); 192void fimc_isp_irq_handler(struct fimc_is *is); 193int fimc_is_create_controls(struct fimc_isp *isp); 194int fimc_is_delete_controls(struct fimc_isp *isp); 195const struct fimc_fmt *fimc_isp_find_format(const u32 *pixelformat, 196 const u32 *mbus_code, int index); 197#endif /* FIMC_ISP_H_ */