Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / drivers / staging / media / davinci_vpfe / dm365_isif.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2012 Texas Instruments Inc
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation version 2.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * Contributors:
15  *      Manjunath Hadli <manjunath.hadli@ti.com>
16  *      Prabhakar Lad <prabhakar.lad@ti.com>
17  */
18
19 #ifndef _DAVINCI_VPFE_DM365_ISIF_H
20 #define _DAVINCI_VPFE_DM365_ISIF_H
21
22 #include <linux/platform_device.h>
23
24 #include <mach/mux.h>
25
26 #include <media/davinci/vpfe_types.h>
27 #include <media/v4l2-ctrls.h>
28 #include <media/v4l2-device.h>
29
30 #include "davinci_vpfe_user.h"
31 #include "dm365_isif_regs.h"
32 #include "vpfe_video.h"
33
34 #define ISIF_CULLING_HCAPT_ODD          0xff
35 #define ISIF_CULLING_HCAPT_EVEN         0xff
36 #define ISIF_CULLING_VCAPT              0xff
37
38 #define ISIF_CADU_BITS                  0x07ff
39 #define ISIF_CADL_BITS                  0x0ffff
40
41 enum isif_pixfmt {
42         ISIF_PIXFMT_RAW = 0,
43         ISIF_PIXFMT_YCBCR_16BIT = 1,
44         ISIF_PIXFMT_YCBCR_8BIT = 2,
45 };
46
47 enum isif_frmfmt {
48         ISIF_FRMFMT_PROGRESSIVE = 0,
49         ISIF_FRMFMT_INTERLACED = 1,
50 };
51
52 /* PIXEL ORDER IN MEMORY from LSB to MSB */
53 /* only applicable for 8-bit input mode  */
54 enum isif_pixorder {
55         ISIF_PIXORDER_YCBYCR = 0,
56         ISIF_PIXORDER_CBYCRY = 1,
57 };
58
59 enum isif_buftype {
60         ISIF_BUFTYPE_FLD_INTERLEAVED = 0,
61         ISIF_BUFTYPE_FLD_SEPARATED = 1,
62 };
63
64 struct isif_ycbcr_config {
65         /* v4l2 pixel format */
66         unsigned long v4l2_pix_fmt;
67         /* isif pixel format */
68         enum isif_pixfmt pix_fmt;
69         /* isif frame format */
70         enum isif_frmfmt frm_fmt;
71         /* isif crop window */
72         struct v4l2_rect win;
73         /* field polarity */
74         enum vpfe_pin_pol fid_pol;
75         /* interface VD polarity */
76         enum vpfe_pin_pol vd_pol;
77         /* interface HD polarity */
78         enum vpfe_pin_pol hd_pol;
79         /* isif pix order. Only used for ycbcr capture */
80         enum isif_pixorder pix_order;
81         /* isif buffer type. Only used for ycbcr capture */
82         enum isif_buftype buf_type;
83 };
84
85 enum isif_cfa_pattern {
86         ISIF_CFA_PAT_MOSAIC = 0,
87         ISIF_CFA_PAT_STRIPE = 1,
88 };
89
90 enum isif_data_msb {
91         /* MSB b15 */
92         ISIF_BIT_MSB_15 = 0,
93         /* MSB b14 */
94         ISIF_BIT_MSB_14 = 1,
95         /* MSB b13 */
96         ISIF_BIT_MSB_13 = 2,
97         /* MSB b12 */
98         ISIF_BIT_MSB_12 = 3,
99         /* MSB b11 */
100         ISIF_BIT_MSB_11 = 4,
101         /* MSB b10 */
102         ISIF_BIT_MSB_10 = 5,
103         /* MSB b9 */
104         ISIF_BIT_MSB_9 = 6,
105         /* MSB b8 */
106         ISIF_BIT_MSB_8 = 7,
107         /* MSB b7 */
108         ISIF_BIT_MSB_7 = 8,
109 };
110
111 struct isif_params_raw {
112         /* v4l2 pixel format */
113         unsigned long v4l2_pix_fmt;
114         /* isif pixel format */
115         enum isif_pixfmt pix_fmt;
116         /* isif frame format */
117         enum isif_frmfmt frm_fmt;
118         /* video window */
119         struct v4l2_rect win;
120         /* field polarity */
121         enum vpfe_pin_pol fid_pol;
122         /* interface VD polarity */
123         enum vpfe_pin_pol vd_pol;
124         /* interface HD polarity */
125         enum vpfe_pin_pol hd_pol;
126         /* buffer type. Applicable for interlaced mode */
127         enum isif_buftype buf_type;
128         /* cfa pattern */
129         enum isif_cfa_pattern cfa_pat;
130         /* Data MSB position */
131         enum isif_data_msb data_msb;
132         /* Enable horizontal flip */
133         unsigned char horz_flip_en;
134         /* Enable image invert vertically */
135         unsigned char image_invert_en;
136         unsigned char dpcm_predictor;
137         struct vpfe_isif_raw_config config_params;
138 };
139
140 enum isif_data_pack {
141         ISIF_PACK_16BIT = 0,
142         ISIF_PACK_12BIT = 1,
143         ISIF_PACK_8BIT = 2,
144 };
145
146 struct isif_gain_values {
147         unsigned int cr_gain;
148         unsigned int cgr_gain;
149         unsigned int cgb_gain;
150         unsigned int cb_gain;
151         unsigned int offset;
152 };
153
154 struct isif_oper_config {
155         struct isif_ycbcr_config ycbcr;
156         struct isif_params_raw bayer;
157         enum isif_data_pack data_pack;
158         struct isif_gain_values isif_gain_params;
159         void __iomem *base_addr;
160         void __iomem *linear_tbl0_addr;
161         void __iomem *linear_tbl1_addr;
162 };
163
164 #define ISIF_PAD_SINK      0
165 #define ISIF_PAD_SOURCE    1
166
167 #define ISIF_PADS_NUM      2
168
169 enum isif_input_entity {
170         ISIF_INPUT_NONE = 0,
171         ISIF_INPUT_PARALLEL = 1,
172 };
173
174 #define ISIF_OUTPUT_NONE        (0)
175 #define ISIF_OUTPUT_MEMORY      (1 << 0)
176 #define ISIF_OUTPUT_IPIPEIF     (1 << 1)
177
178 struct vpfe_isif_device {
179         struct v4l2_subdev              subdev;
180         struct media_pad                pads[ISIF_PADS_NUM];
181         struct v4l2_mbus_framefmt       formats[ISIF_PADS_NUM];
182         enum isif_input_entity          input;
183         unsigned int                    output;
184         struct v4l2_ctrl_handler        ctrls;
185         struct v4l2_rect                crop;
186         struct isif_oper_config         isif_cfg;
187         struct vpfe_video_device        video_out;
188 };
189
190 enum v4l2_field vpfe_isif_get_fid(struct vpfe_device *vpfe_dev);
191 void vpfe_isif_unregister_entities(struct vpfe_isif_device *isif);
192 int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
193                                 struct v4l2_device *dev);
194 int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev);
195 void vpfe_isif_cleanup(struct vpfe_isif_device *vpfe_isif,
196                        struct platform_device *pdev);
197 void vpfe_isif_vidint1_isr(struct vpfe_isif_device *isif);
198 void vpfe_isif_buffer_isr(struct vpfe_isif_device *isif);
199
200 #endif          /* _DAVINCI_VPFE_DM365_ISIF_H */