1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Microchip Image Sensor Controller (ISC) driver header file
5 * Copyright (C) 2016-2019 Microchip Technology, Inc.
13 #define ISC_MAX_SUPPORT_WIDTH 2592
14 #define ISC_MAX_SUPPORT_HEIGHT 1944
16 #define ISC_CLK_MAX_DIV 255
26 struct regmap *regmap;
27 spinlock_t lock; /* serialize access to clock registers */
34 #define to_isc_clk(v) container_of(v, struct isc_clk, hw)
37 struct vb2_v4l2_buffer vb;
38 struct list_head list;
41 struct isc_subdev_entity {
42 struct v4l2_subdev *sd;
43 struct v4l2_async_subdev *asd;
44 struct device_node *epn;
45 struct v4l2_async_notifier notifier;
49 struct list_head list;
53 * struct isc_format - ISC media bus format information
54 This structure represents the interface between the ISC
55 and the sensor. It's the input format received by
57 * @fourcc: Fourcc code for this format
58 * @mbus_code: V4L2 media bus format code.
59 * @cfa_baycfg: If this format is RAW BAYER, indicate the type of bayer.
60 this is either BGBG, RGRG, etc.
61 * @pfe_cfg0_bps: Number of hardware data lines connected to the ISC
74 #define WB_ENABLE BIT(0)
75 #define CFA_ENABLE BIT(1)
76 #define CC_ENABLE BIT(2)
77 #define GAM_ENABLE BIT(3)
78 #define GAM_BENABLE BIT(4)
79 #define GAM_GENABLE BIT(5)
80 #define GAM_RENABLE BIT(6)
81 #define CSC_ENABLE BIT(7)
82 #define CBC_ENABLE BIT(8)
83 #define SUB422_ENABLE BIT(9)
84 #define SUB420_ENABLE BIT(10)
86 #define GAM_ENABLES (GAM_RENABLE | GAM_GENABLE | GAM_BENABLE | GAM_ENABLE)
89 * struct fmt_config - ISC format configuration and internal pipeline
90 This structure represents the internal configuration
92 It also holds the format that ISC will present to v4l2.
93 * @sd_format: Pointer to an isc_format struct that holds the sensor
95 * @fourcc: Fourcc code for this format.
96 * @bpp: Bytes per pixel in the current format.
97 * @rlp_cfg_mode: Configuration of the RLP (rounding, limiting packaging)
98 * @dcfg_imode: Configuration of the input of the DMA module
99 * @dctrl_dview: Configuration of the output of the DMA module
100 * @bits_pipeline: Configuration of the pipeline, which modules are enabled
103 struct isc_format *sd_format;
115 #define HIST_ENTRIES 512
116 #define HIST_BAYER (ISC_HIS_CFG_MODE_B + 1)
125 struct v4l2_ctrl_handler handler;
130 #define ISC_WB_NONE 0
131 #define ISC_WB_AUTO 1
132 #define ISC_WB_ONETIME 2
135 /* one for each component : GR, R, GB, B */
136 u32 gain[HIST_BAYER];
137 s32 offset[HIST_BAYER];
139 u32 hist_entry[HIST_ENTRIES];
140 u32 hist_count[HIST_BAYER];
143 #define HIST_MIN_INDEX 0
144 #define HIST_MAX_INDEX 1
145 u32 hist_minmax[HIST_BAYER][2];
148 #define ISC_PIPE_LINE_NODE_NUM 11
151 * struct isc_device - ISC device driver data/config struct
152 * @regmap: Register map
153 * @hclock: Hclock clock input (refer datasheet)
154 * @ispck: iscpck clock (refer datasheet)
155 * @isc_clks: ISC clocks
157 * @dev: Registered device driver
158 * @v4l2_dev: v4l2 registered device
159 * @video_dev: registered video device
161 * @vb2_vidq: video buffer 2 video queue
162 * @dma_queue_lock: lock to serialize the dma buffer queue
163 * @dma_queue: the queue for dma buffers
164 * @cur_frm: current isc frame/buffer
165 * @sequence: current frame number
166 * @stop: true if isc is not streaming, false if streaming
167 * @comp: completion reference that signals frame completion
169 * @fmt: current v42l format
170 * @user_formats: list of formats that are supported and agreed with sd
171 * @num_user_formats: how many formats are in user_formats
173 * @config: current ISC format configuration
174 * @try_config: the current ISC try format , not yet activated
176 * @ctrls: holds information about ISC controls
177 * @do_wb_ctrl: control regarding the DO_WHITE_BALANCE button
178 * @awb_work: workqueue reference for autowhitebalance histogram
181 * @lock: lock for serializing userspace file operations
182 * with ISC operations
183 * @awb_lock: lock for serializing awb work queue operations
184 * with DMA/buffer operations
186 * @pipeline: configuration of the ISC pipeline
188 * @current_subdev: current subdevice: the sensor
189 * @subdev_entities: list of subdevice entitites
192 struct regmap *regmap;
195 struct isc_clk isc_clks[2];
198 struct v4l2_device v4l2_dev;
199 struct video_device video_dev;
201 struct vb2_queue vb2_vidq;
202 spinlock_t dma_queue_lock; /* serialize access to dma queue */
203 struct list_head dma_queue;
204 struct isc_buffer *cur_frm;
205 unsigned int sequence;
207 struct completion comp;
209 struct v4l2_format fmt;
210 struct isc_format **user_formats;
211 unsigned int num_user_formats;
213 struct fmt_config config;
214 struct fmt_config try_config;
216 struct isc_ctrls ctrls;
217 struct work_struct awb_work;
219 struct mutex lock; /* serialize access to file operations */
220 spinlock_t awb_lock; /* serialize access to DMA buffers from awb work queue */
222 struct regmap_field *pipeline[ISC_PIPE_LINE_NODE_NUM];
224 struct isc_subdev_entity *current_subdev;
225 struct list_head subdev_entities;
228 #define ISC_CTRL_DO_WB 1
229 #define ISC_CTRL_R_GAIN 2
230 #define ISC_CTRL_B_GAIN 3
231 #define ISC_CTRL_GR_GAIN 4
232 #define ISC_CTRL_GB_GAIN 5
233 #define ISC_CTRL_R_OFF 6
234 #define ISC_CTRL_B_OFF 7
235 #define ISC_CTRL_GR_OFF 8
236 #define ISC_CTRL_GB_OFF 9
237 struct v4l2_ctrl *awb_ctrl;
238 struct v4l2_ctrl *do_wb_ctrl;
239 struct v4l2_ctrl *r_gain_ctrl;
240 struct v4l2_ctrl *b_gain_ctrl;
241 struct v4l2_ctrl *gr_gain_ctrl;
242 struct v4l2_ctrl *gb_gain_ctrl;
243 struct v4l2_ctrl *r_off_ctrl;
244 struct v4l2_ctrl *b_off_ctrl;
245 struct v4l2_ctrl *gr_off_ctrl;
246 struct v4l2_ctrl *gb_off_ctrl;
251 #define GAMMA_ENTRIES 64
253 #define ATMEL_ISC_NAME "atmel-isc"
255 extern struct isc_format formats_list[];
256 extern const struct isc_format controller_formats[];
257 extern const u32 isc_gamma_table[GAMMA_MAX + 1][GAMMA_ENTRIES];
258 extern const struct regmap_config isc_regmap_config;
259 extern const struct v4l2_async_notifier_operations isc_async_ops;
261 irqreturn_t isc_interrupt(int irq, void *dev_id);
262 int isc_pipeline_init(struct isc_device *isc);
263 int isc_clk_init(struct isc_device *isc);
264 void isc_subdev_cleanup(struct isc_device *isc);
265 void isc_clk_cleanup(struct isc_device *isc);