1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #ifndef _isp_capture_defs_h
17 #define _isp_capture_defs_h
18 
19 #define _ISP_CAPTURE_REG_ALIGN                    4  /* assuming 32 bit control bus width */
20 #define _ISP_CAPTURE_BITS_PER_ELEM                32  /* only for data, not SOP */
21 #define _ISP_CAPTURE_BYTES_PER_ELEM               (_ISP_CAPTURE_BITS_PER_ELEM / 8)
22 #define _ISP_CAPTURE_BYTES_PER_WORD               32		/* 256/8 */
23 #define _ISP_CAPTURE_ELEM_PER_WORD                _ISP_CAPTURE_BYTES_PER_WORD / _ISP_CAPTURE_BYTES_PER_ELEM
24 
25 /* --------------------------------------------------*/
26 
27 #define NOF_IRQS                                  2
28 
29 /* --------------------------------------------------*/
30 /* REGISTER INFO */
31 /* --------------------------------------------------*/
32 
33 // Number of registers
34 #define CAPT_NOF_REGS                             16
35 
36 // Register id's of MMIO slave accessible registers
37 #define CAPT_START_MODE_REG_ID                    0
38 #define CAPT_START_ADDR_REG_ID                    1
39 #define CAPT_MEM_REGION_SIZE_REG_ID               2
40 #define CAPT_NUM_MEM_REGIONS_REG_ID               3
41 #define CAPT_INIT_REG_ID                          4
42 #define CAPT_START_REG_ID                         5
43 #define CAPT_STOP_REG_ID                          6
44 
45 #define CAPT_PACKET_LENGTH_REG_ID                 7
46 #define CAPT_RECEIVED_LENGTH_REG_ID               8
47 #define CAPT_RECEIVED_SHORT_PACKETS_REG_ID        9
48 #define CAPT_RECEIVED_LONG_PACKETS_REG_ID         10
49 #define CAPT_LAST_COMMAND_REG_ID                  11
50 #define CAPT_NEXT_COMMAND_REG_ID                  12
51 #define CAPT_LAST_ACKNOWLEDGE_REG_ID              13
52 #define CAPT_NEXT_ACKNOWLEDGE_REG_ID              14
53 #define CAPT_FSM_STATE_INFO_REG_ID                15
54 
55 // Register width
56 #define CAPT_START_MODE_REG_WIDTH                 1
57 
58 #define CAPT_START_REG_WIDTH                      1
59 #define CAPT_STOP_REG_WIDTH                       1
60 
61 /* --------------------------------------------------*/
62 /* FSM */
63 /* --------------------------------------------------*/
64 #define CAPT_WRITE2MEM_FSM_STATE_BITS             2
65 #define CAPT_SYNCHRONIZER_FSM_STATE_BITS          3
66 
67 #define CAPT_PACKET_LENGTH_REG_WIDTH              17
68 #define CAPT_RECEIVED_LENGTH_REG_WIDTH            17
69 #define CAPT_RECEIVED_SHORT_PACKETS_REG_WIDTH     32
70 #define CAPT_RECEIVED_LONG_PACKETS_REG_WIDTH      32
71 #define CAPT_LAST_COMMAND_REG_WIDTH               32
72 #define CAPT_LAST_ACKNOWLEDGE_REG_WIDTH           32
73 #define CAPT_NEXT_ACKNOWLEDGE_REG_WIDTH           32
74 #define CAPT_FSM_STATE_INFO_REG_WIDTH             ((CAPT_WRITE2MEM_FSM_STATE_BITS * 3) + (CAPT_SYNCHRONIZER_FSM_STATE_BITS * 3))
75 
76 /* register reset value */
77 #define CAPT_START_MODE_REG_RSTVAL                0
78 #define CAPT_START_ADDR_REG_RSTVAL                0
79 #define CAPT_MEM_REGION_SIZE_REG_RSTVAL           128
80 #define CAPT_NUM_MEM_REGIONS_REG_RSTVAL           3
81 #define CAPT_INIT_REG_RSTVAL                      0
82 
83 #define CAPT_START_REG_RSTVAL                     0
84 #define CAPT_STOP_REG_RSTVAL                      0
85 
86 #define CAPT_PACKET_LENGTH_REG_RSTVAL             0
87 #define CAPT_RECEIVED_LENGTH_REG_RSTVAL           0
88 #define CAPT_RECEIVED_SHORT_PACKETS_REG_RSTVAL    0
89 #define CAPT_RECEIVED_LONG_PACKETS_REG_RSTVAL     0
90 #define CAPT_LAST_COMMAND_REG_RSTVAL              0
91 #define CAPT_NEXT_COMMAND_REG_RSTVAL              0
92 #define CAPT_LAST_ACKNOWLEDGE_REG_RSTVAL          0
93 #define CAPT_NEXT_ACKNOWLEDGE_REG_RSTVAL          0
94 #define CAPT_FSM_STATE_INFO_REG_RSTVAL            0
95 
96 /* bit definitions */
97 #define CAPT_INIT_RST_REG_BIT                     0
98 #define CAPT_INIT_FLUSH_BIT                       1
99 #define CAPT_INIT_RESYNC_BIT                      2
100 #define CAPT_INIT_RESTART_BIT                     3
101 #define CAPT_INIT_RESTART_MEM_ADDR_LSB            4
102 
103 #define CAPT_INIT_RST_REG_IDX                     CAPT_INIT_RST_REG_BIT
104 #define CAPT_INIT_RST_REG_BITS                    1
105 #define CAPT_INIT_FLUSH_IDX                       CAPT_INIT_FLUSH_BIT
106 #define CAPT_INIT_FLUSH_BITS                      1
107 #define CAPT_INIT_RESYNC_IDX                      CAPT_INIT_RESYNC_BIT
108 #define CAPT_INIT_RESYNC_BITS                     1
109 #define CAPT_INIT_RESTART_IDX                     CAPT_INIT_RESTART_BIT
110 #define CAPT_INIT_RESTART_BITS									1
111 #define CAPT_INIT_RESTART_MEM_ADDR_IDX            CAPT_INIT_RESTART_MEM_ADDR_LSB
112 
113 /* --------------------------------------------------*/
114 /* TOKEN INFO */
115 /* --------------------------------------------------*/
116 #define CAPT_TOKEN_ID_LSB                         0
117 #define CAPT_TOKEN_ID_MSB                         3
118 #define CAPT_TOKEN_WIDTH                         (CAPT_TOKEN_ID_MSB - CAPT_TOKEN_ID_LSB  + 1) /* 4 */
119 
120 /* Command tokens IDs */
121 #define CAPT_START_TOKEN_ID                       0 /* 0000b */
122 #define CAPT_STOP_TOKEN_ID                        1 /* 0001b */
123 #define CAPT_FREEZE_TOKEN_ID                      2 /* 0010b */
124 #define CAPT_RESUME_TOKEN_ID                      3 /* 0011b */
125 #define CAPT_INIT_TOKEN_ID                        8 /* 1000b */
126 
127 #define CAPT_START_TOKEN_BIT                      0
128 #define CAPT_STOP_TOKEN_BIT                       0
129 #define CAPT_FREEZE_TOKEN_BIT                     0
130 #define CAPT_RESUME_TOKEN_BIT                     0
131 #define CAPT_INIT_TOKEN_BIT                       0
132 
133 /* Acknowledge token IDs */
134 #define CAPT_END_OF_PACKET_RECEIVED_TOKEN_ID      0 /* 0000b */
135 #define CAPT_END_OF_PACKET_WRITTEN_TOKEN_ID       1 /* 0001b */
136 #define CAPT_END_OF_REGION_WRITTEN_TOKEN_ID       2 /* 0010b */
137 #define CAPT_FLUSH_DONE_TOKEN_ID                  3 /* 0011b */
138 #define CAPT_PREMATURE_SOP_TOKEN_ID               4 /* 0100b */
139 #define CAPT_MISSING_SOP_TOKEN_ID                 5 /* 0101b */
140 #define CAPT_UNDEF_PH_TOKEN_ID                    6 /* 0110b */
141 #define CAPT_STOP_ACK_TOKEN_ID                    7 /* 0111b */
142 
143 #define CAPT_PACKET_LENGTH_TOKEN_MSB             19
144 #define CAPT_PACKET_LENGTH_TOKEN_LSB              4
145 #define CAPT_SUPER_PACKET_LENGTH_TOKEN_MSB       20
146 #define CAPT_SUPER_PACKET_LENGTH_TOKEN_LSB        4
147 #define CAPT_PACKET_DATA_FORMAT_ID_TOKEN_MSB     25
148 #define CAPT_PACKET_DATA_FORMAT_ID_TOKEN_LSB     20
149 #define CAPT_PACKET_CH_ID_TOKEN_MSB              27
150 #define CAPT_PACKET_CH_ID_TOKEN_LSB              26
151 #define CAPT_PACKET_MEM_REGION_ID_TOKEN_MSB      29
152 #define CAPT_PACKET_MEM_REGION_ID_TOKEN_LSB      21
153 
154 /*  bit definition */
155 #define CAPT_CMD_IDX                              CAPT_TOKEN_ID_LSB
156 #define	CAPT_CMD_BITS                             (CAPT_TOKEN_ID_MSB - CAPT_TOKEN_ID_LSB + 1)
157 #define CAPT_SOP_IDX                              32
158 #define CAPT_SOP_BITS                             1
159 #define CAPT_PKT_INFO_IDX                         16
160 #define CAPT_PKT_INFO_BITS                        8
161 #define CAPT_PKT_TYPE_IDX                         0
162 #define CAPT_PKT_TYPE_BITS                        6
163 #define CAPT_HEADER_DATA_IDX                      0
164 #define CAPT_HEADER_DATA_BITS                     16
165 #define CAPT_PKT_DATA_IDX                         0
166 #define CAPT_PKT_DATA_BITS                        32
167 #define CAPT_WORD_CNT_IDX                         0
168 #define CAPT_WORD_CNT_BITS                        16
169 #define CAPT_ACK_TOKEN_ID_IDX                     0
170 #define CAPT_ACK_TOKEN_ID_BITS                    4
171 //#define CAPT_ACK_PKT_LEN_IDX                      CAPT_PACKET_LENGTH_TOKEN_LSB
172 //#define CAPT_ACK_PKT_LEN_BITS                     (CAPT_PACKET_LENGTH_TOKEN_MSB - CAPT_PACKET_LENGTH_TOKEN_LSB + 1)
173 //#define CAPT_ACK_PKT_INFO_IDX                     20
174 //#define CAPT_ACK_PKT_INFO_BITS                    8
175 //#define CAPT_ACK_MEM_REG_ID1_IDX                  20			/* for capt_end_of_packet_written */
176 //#define CAPT_ACK_MEM_REG_ID2_IDX                  4       /* for capt_end_of_region_written */
177 #define CAPT_ACK_PKT_LEN_IDX                      CAPT_PACKET_LENGTH_TOKEN_LSB
178 #define CAPT_ACK_PKT_LEN_BITS                     (CAPT_PACKET_LENGTH_TOKEN_MSB - CAPT_PACKET_LENGTH_TOKEN_LSB + 1)
179 #define CAPT_ACK_SUPER_PKT_LEN_IDX                CAPT_SUPER_PACKET_LENGTH_TOKEN_LSB
180 #define CAPT_ACK_SUPER_PKT_LEN_BITS               (CAPT_SUPER_PACKET_LENGTH_TOKEN_MSB - CAPT_SUPER_PACKET_LENGTH_TOKEN_LSB + 1)
181 #define CAPT_ACK_PKT_INFO_IDX                     CAPT_PACKET_DATA_FORMAT_ID_TOKEN_LSB
182 #define CAPT_ACK_PKT_INFO_BITS                    (CAPT_PACKET_CH_ID_TOKEN_MSB - CAPT_PACKET_DATA_FORMAT_ID_TOKEN_LSB + 1)
183 #define CAPT_ACK_MEM_REGION_ID_IDX                CAPT_PACKET_MEM_REGION_ID_TOKEN_LSB
184 #define CAPT_ACK_MEM_REGION_ID_BITS               (CAPT_PACKET_MEM_REGION_ID_TOKEN_MSB - CAPT_PACKET_MEM_REGION_ID_TOKEN_LSB + 1)
185 #define CAPT_ACK_PKT_TYPE_IDX                     CAPT_PACKET_DATA_FORMAT_ID_TOKEN_LSB
186 #define CAPT_ACK_PKT_TYPE_BITS                    (CAPT_PACKET_DATA_FORMAT_ID_TOKEN_MSB - CAPT_PACKET_DATA_FORMAT_ID_TOKEN_LSB + 1)
187 #define CAPT_INIT_TOKEN_INIT_IDX                  4
188 #define CAPT_INIT_TOKEN_INIT_BITS                 22
189 
190 /* --------------------------------------------------*/
191 /* MIPI */
192 /* --------------------------------------------------*/
193 
194 #define CAPT_WORD_COUNT_WIDTH                     16
195 #define CAPT_PKT_CODE_WIDTH                       6
196 #define CAPT_CHN_NO_WIDTH                         2
197 #define CAPT_ERROR_INFO_WIDTH                     8
198 
199 #define LONG_PKTCODE_MAX                          63
200 #define LONG_PKTCODE_MIN                          16
201 #define SHORT_PKTCODE_MAX                         15
202 
203 /* --------------------------------------------------*/
204 /* Packet Info */
205 /* --------------------------------------------------*/
206 #define CAPT_START_OF_FRAME                       0
207 #define CAPT_END_OF_FRAME                         1
208 #define CAPT_START_OF_LINE                        2
209 #define CAPT_END_OF_LINE                          3
210 #define CAPT_LINE_PAYLOAD                         4
211 #define CAPT_GEN_SH_PKT                           5
212 
213 /* --------------------------------------------------*/
214 /* Packet Data Type */
215 /* --------------------------------------------------*/
216 
217 #define CAPT_YUV420_8_DATA                       24   /* 01 1000 YUV420 8-bit                                        */
218 #define CAPT_YUV420_10_DATA                      25   /* 01 1001  YUV420 10-bit                                      */
219 #define CAPT_YUV420_8L_DATA                      26   /* 01 1010   YUV420 8-bit legacy                               */
220 #define CAPT_YUV422_8_DATA                       30   /* 01 1110   YUV422 8-bit                                      */
221 #define CAPT_YUV422_10_DATA                      31   /* 01 1111   YUV422 10-bit                                     */
222 #define CAPT_RGB444_DATA                         32   /* 10 0000   RGB444                                            */
223 #define CAPT_RGB555_DATA						 33   /* 10 0001   RGB555                                            */
224 #define CAPT_RGB565_DATA						 34   /* 10 0010   RGB565                                            */
225 #define CAPT_RGB666_DATA						 35   /* 10 0011   RGB666                                            */
226 #define CAPT_RGB888_DATA						 36   /* 10 0100   RGB888                                            */
227 #define CAPT_RAW6_DATA							 40   /* 10 1000   RAW6                                              */
228 #define CAPT_RAW7_DATA							 41   /* 10 1001   RAW7                                              */
229 #define CAPT_RAW8_DATA							 42   /* 10 1010   RAW8                                              */
230 #define CAPT_RAW10_DATA						 43   /* 10 1011   RAW10                                             */
231 #define CAPT_RAW12_DATA						 44   /* 10 1100   RAW12                                             */
232 #define CAPT_RAW14_DATA						 45   /* 10 1101   RAW14                                             */
233 #define CAPT_USR_DEF_1_DATA						 48   /* 11 0000    JPEG [User Defined 8-bit Data Type 1]            */
234 #define CAPT_USR_DEF_2_DATA						 49   /* 11 0001    User Defined 8-bit Data Type 2                   */
235 #define CAPT_USR_DEF_3_DATA						 50   /* 11 0010    User Defined 8-bit Data Type 3                   */
236 #define CAPT_USR_DEF_4_DATA						 51   /* 11 0011    User Defined 8-bit Data Type 4                   */
237 #define CAPT_USR_DEF_5_DATA						 52   /* 11 0100    User Defined 8-bit Data Type 5                   */
238 #define CAPT_USR_DEF_6_DATA						 53   /* 11 0101    User Defined 8-bit Data Type 6                   */
239 #define CAPT_USR_DEF_7_DATA						 54   /* 11 0110    User Defined 8-bit Data Type 7                   */
240 #define CAPT_USR_DEF_8_DATA						 55   /* 11 0111    User Defined 8-bit Data Type 8                   */
241 #define CAPT_Emb_DATA							 18   /* 01 0010    embedded eight bit non image data                */
242 #define CAPT_SOF_DATA							 0   /* 00 0000    frame start                                      */
243 #define CAPT_EOF_DATA							 1   /* 00 0001    frame end                                        */
244 #define CAPT_SOL_DATA							 2   /* 00 0010    line start                                       */
245 #define CAPT_EOL_DATA							 3   /* 00 0011    line end                                         */
246 #define CAPT_GEN_SH1_DATA						 8   /* 00 1000  Generic Short Packet Code 1                        */
247 #define CAPT_GEN_SH2_DATA						 9   /* 00 1001    Generic Short Packet Code 2                      */
248 #define CAPT_GEN_SH3_DATA						 10   /* 00 1010    Generic Short Packet Code 3                      */
249 #define CAPT_GEN_SH4_DATA						 11   /* 00 1011    Generic Short Packet Code 4                      */
250 #define CAPT_GEN_SH5_DATA						 12   /* 00 1100    Generic Short Packet Code 5                      */
251 #define CAPT_GEN_SH6_DATA						 13   /* 00 1101    Generic Short Packet Code 6                      */
252 #define CAPT_GEN_SH7_DATA						 14   /* 00 1110    Generic Short Packet Code 7                      */
253 #define CAPT_GEN_SH8_DATA						 15   /* 00 1111    Generic Short Packet Code 8                      */
254 #define CAPT_YUV420_8_CSPS_DATA					 28   /* 01 1100   YUV420 8-bit (Chroma Shifted Pixel Sampling)      */
255 #define CAPT_YUV420_10_CSPS_DATA					 29   /* 01 1101   YUV420 10-bit (Chroma Shifted Pixel Sampling)     */
256 #define CAPT_RESERVED_DATA_TYPE_MIN              56
257 #define CAPT_RESERVED_DATA_TYPE_MAX              63
258 #define CAPT_GEN_LONG_RESERVED_DATA_TYPE_MIN     19
259 #define CAPT_GEN_LONG_RESERVED_DATA_TYPE_MAX     23
260 #define CAPT_YUV_RESERVED_DATA_TYPE              27
261 #define CAPT_RGB_RESERVED_DATA_TYPE_MIN          37
262 #define CAPT_RGB_RESERVED_DATA_TYPE_MAX          39
263 #define CAPT_RAW_RESERVED_DATA_TYPE_MIN          46
264 #define CAPT_RAW_RESERVED_DATA_TYPE_MAX          47
265 
266 /* --------------------------------------------------*/
267 /* Capture Unit State */
268 /* --------------------------------------------------*/
269 #define CAPT_FREE_RUN                             0
270 #define CAPT_NO_SYNC                              1
271 #define CAPT_SYNC_SWP                             2
272 #define CAPT_SYNC_MWP                             3
273 #define CAPT_SYNC_WAIT                            4
274 #define CAPT_FREEZE                               5
275 #define CAPT_RUN                                  6
276 
277 /* --------------------------------------------------*/
278 
279 #endif /* _isp_capture_defs_h */
280