]> Git Repo - J-linux.git/blob - drivers/media/platform/atmel/atmel-isc.h
Merge tag 'trace-v5.13-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[J-linux.git] / drivers / media / platform / atmel / atmel-isc.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Microchip Image Sensor Controller (ISC) driver header file
4  *
5  * Copyright (C) 2016-2019 Microchip Technology, Inc.
6  *
7  * Author: Songjun Wu
8  * Author: Eugen Hristev <[email protected]>
9  *
10  */
11 #ifndef _ATMEL_ISC_H_
12
13 #define ISC_MAX_SUPPORT_WIDTH   2592
14 #define ISC_MAX_SUPPORT_HEIGHT  1944
15
16 #define ISC_CLK_MAX_DIV         255
17
18 enum isc_clk_id {
19         ISC_ISPCK = 0,
20         ISC_MCK = 1,
21 };
22
23 struct isc_clk {
24         struct clk_hw   hw;
25         struct clk      *clk;
26         struct regmap   *regmap;
27         spinlock_t      lock;   /* serialize access to clock registers */
28         u8              id;
29         u8              parent_id;
30         u32             div;
31         struct device   *dev;
32 };
33
34 #define to_isc_clk(v) container_of(v, struct isc_clk, hw)
35
36 struct isc_buffer {
37         struct vb2_v4l2_buffer  vb;
38         struct list_head        list;
39 };
40
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;
46
47         u32 pfe_cfg0;
48
49         struct list_head list;
50 };
51
52 /*
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
56                         the ISC.
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
62  */
63
64 struct isc_format {
65         u32     fourcc;
66         u32     mbus_code;
67         u32     cfa_baycfg;
68
69         bool    sd_support;
70         u32     pfe_cfg0_bps;
71 };
72
73 /* Pipeline bitmap */
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)
85
86 #define GAM_ENABLES     (GAM_RENABLE | GAM_GENABLE | GAM_BENABLE | GAM_ENABLE)
87
88 /*
89  * struct fmt_config - ISC format configuration and internal pipeline
90                         This structure represents the internal configuration
91                         of the ISC.
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
94                         configuration.
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
101  */
102 struct fmt_config {
103         struct isc_format       *sd_format;
104
105         u32                     fourcc;
106         u8                      bpp;
107
108         u32                     rlp_cfg_mode;
109         u32                     dcfg_imode;
110         u32                     dctrl_dview;
111
112         u32                     bits_pipeline;
113 };
114
115 #define HIST_ENTRIES            512
116 #define HIST_BAYER              (ISC_HIS_CFG_MODE_B + 1)
117
118 enum{
119         HIST_INIT = 0,
120         HIST_ENABLED,
121         HIST_DISABLED,
122 };
123
124 struct isc_ctrls {
125         struct v4l2_ctrl_handler handler;
126
127         u32 brightness;
128         u32 contrast;
129         u8 gamma_index;
130 #define ISC_WB_NONE     0
131 #define ISC_WB_AUTO     1
132 #define ISC_WB_ONETIME  2
133         u8 awb;
134
135         /* one for each component : GR, R, GB, B */
136         u32 gain[HIST_BAYER];
137         s32 offset[HIST_BAYER];
138
139         u32 hist_entry[HIST_ENTRIES];
140         u32 hist_count[HIST_BAYER];
141         u8 hist_id;
142         u8 hist_stat;
143 #define HIST_MIN_INDEX          0
144 #define HIST_MAX_INDEX          1
145         u32 hist_minmax[HIST_BAYER][2];
146 };
147
148 #define ISC_PIPE_LINE_NODE_NUM  11
149
150 /*
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
156  *
157  * @dev:                Registered device driver
158  * @v4l2_dev:           v4l2 registered device
159  * @video_dev:          registered video device
160  *
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
168  *
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
172  *
173  * @config:             current ISC format configuration
174  * @try_config:         the current ISC try format , not yet activated
175  *
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
179  *                      analysis
180  *
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
185  *
186  * @pipeline:           configuration of the ISC pipeline
187  *
188  * @current_subdev:     current subdevice: the sensor
189  * @subdev_entities:    list of subdevice entitites
190  */
191 struct isc_device {
192         struct regmap           *regmap;
193         struct clk              *hclock;
194         struct clk              *ispck;
195         struct isc_clk          isc_clks[2];
196
197         struct device           *dev;
198         struct v4l2_device      v4l2_dev;
199         struct video_device     video_dev;
200
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;
206         bool                    stop;
207         struct completion       comp;
208
209         struct v4l2_format      fmt;
210         struct isc_format       **user_formats;
211         unsigned int            num_user_formats;
212
213         struct fmt_config       config;
214         struct fmt_config       try_config;
215
216         struct isc_ctrls        ctrls;
217         struct work_struct      awb_work;
218
219         struct mutex            lock; /* serialize access to file operations */
220         spinlock_t              awb_lock; /* serialize access to DMA buffers from awb work queue */
221
222         struct regmap_field     *pipeline[ISC_PIPE_LINE_NODE_NUM];
223
224         struct isc_subdev_entity        *current_subdev;
225         struct list_head                subdev_entities;
226
227         struct {
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;
247         };
248 };
249
250 #define GAMMA_MAX       2
251 #define GAMMA_ENTRIES   64
252
253 #define ATMEL_ISC_NAME "atmel-isc"
254
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;
260
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);
266
267 #endif
This page took 0.045717 seconds and 4 git commands to generate.