• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 /**
10  * @addtogroup MIPI CSI
11  * @{
12  *
13  * @brief Defines standard MIPI CSI APIs for display driver development.
14  *
15  * This MIPI CSI module abstracts MIPI CSI capabilities of different system platforms to provide stable APIs
16  * for display driver development. You can use this module to obtain/release the MIPI CSI device handle,
17  * initialize the MIPI CSI device, and send/receive commands that interact with display peripherals.
18  *
19  * @since 1.0
20  */
21 
22 /**
23  * @file mipi_csi_if.h
24  *
25  * @brief Declares standard MIPI CSI APIs for display driver development.
26  *
27  *
28  *
29  * @since 1.0
30  */
31 
32 #ifndef MIPI_CSI_IF_H
33 #define MIPI_CSI_IF_H
34 
35 #include "platform_if.h"
36 
37 #ifdef __cplusplus
38 #if __cplusplus
39 extern "C" {
40 #endif
41 #endif /* __cplusplus */
42 
43 /**
44  * @brief Maximum number of lanes supported by MIPI RX's Mipi device.
45  *
46  * @since 1.0
47  */
48 #define MIPI_LANE_NUM                4
49 
50 /**
51  * @brief The maximum number of lanes supported by the LVDS device of Mipi Rx.
52  *
53  * @since 1.0
54  */
55 #define LVDS_LANE_NUM                4
56 
57 /**
58  * @brief Defines the maximum number of virtual channels supported.
59  *
60  * @since 1.0
61  */
62 #define WDR_VC_NUM                   4
63 
64 /**
65  * @brief Define the number of synchronization codes for each virtual channel of LVDS.
66  *
67  * @since 1.0
68  */
69 #define SYNC_CODE_NUM                4
70 
71 /**
72  * @brief Maximum 3 groups of extended data types.
73  *
74  * @since 1.0
75  */
76 #define MAX_EXT_DATA_TYPE_NUM        3
77 
78 /**
79  * @brief Lane distribution of Mipi Rx.
80  *
81  * @since 1.0
82  */
83 typedef enum {
84     LANE_DIVIDE_MODE_0 = 0,
85     LANE_DIVIDE_MODE_1 = 1,
86     LANE_DIVIDE_MODE_BUTT
87 } LaneDivideMode;
88 
89 /**
90  * @brief MIPI RX input interface type.
91  *
92  * @since 1.0
93  */
94 typedef enum {
95     /** mipi */
96     INPUT_MODE_MIPI    = 0x0,
97     /** SUB_LVDS */
98     INPUT_MODE_SUBLVDS = 0x1,
99     /** LVDS */
100     INPUT_MODE_LVDS    = 0x2,
101     /* HISPI */
102     INPUT_MODE_HISPI   = 0x3,
103     /** CMOS */
104     INPUT_MODE_CMOS    = 0x4,
105     /** BT601 */
106     INPUT_MODE_BT601   = 0x5,
107     /** BT656 */
108     INPUT_MODE_BT656   = 0x6,
109     /** BT1120 */
110     INPUT_MODE_BT1120  = 0x7,
111     /** MIPI Bypass */
112     INPUT_MODE_BYPASS  = 0x8,
113     INPUT_MODE_BUTT
114 } InputMode;
115 
116 /**
117  * @brief Mipi Rx, SLVS input rate.
118  *
119  * @since 1.0
120  */
121 typedef enum {
122     /** output 1 pixel per clock */
123     MIPI_DATA_RATE_X1 = 0,
124     /** output 2 pixel per clock */
125     MIPI_DATA_RATE_X2 = 1,
126     MIPI_DATA_RATE_BUTT
127 } MipiDataRate;
128 
129 /**
130  * @brief Mipi crop area properties.
131  *
132  * @since 1.0
133  */
134 typedef struct {
135     int x;
136     int y;
137     unsigned int width;
138     unsigned int height;
139 } ImgRect;
140 
141 /**
142  * @brief Type of data transmitted.
143  *
144  * @since 1.0
145  */
146 typedef enum {
147     DATA_TYPE_RAW_8BIT = 0,
148     DATA_TYPE_RAW_10BIT,
149     DATA_TYPE_RAW_12BIT,
150     DATA_TYPE_RAW_14BIT,
151     DATA_TYPE_RAW_16BIT,
152     DATA_TYPE_YUV420_8BIT_NORMAL,
153     DATA_TYPE_YUV420_8BIT_LEGACY,
154     DATA_TYPE_YUV422_8BIT,
155     /** yuv422 8bit transform user define 16bit raw */
156     DATA_TYPE_YUV422_PACKED,
157     DATA_TYPE_BUTT
158 } DataType;
159 
160 /**
161  * @brief Define YUV and RAW data format and bit depth.
162  *
163  * @since 1.0
164  */
165 typedef struct {
166     uint8_t devno;
167     unsigned int num;
168     unsigned int extDataBitWidth[MAX_EXT_DATA_TYPE_NUM];
169     unsigned int extDataType[MAX_EXT_DATA_TYPE_NUM];
170 } ExtDataType;
171 
172 /**
173  * @brief MIPI D-PHY WDR MODE defines
174  *
175  * @since 1.0
176  */
177 typedef enum {
178     HI_MIPI_WDR_MODE_NONE = 0x0,
179     /** Virtual Channel */
180     HI_MIPI_WDR_MODE_VC   = 0x1,
181     /** Data Type */
182     HI_MIPI_WDR_MODE_DT   = 0x2,
183     /** DOL Mode */
184     HI_MIPI_WDR_MODE_DOL  = 0x3,
185     HI_MIPI_WDR_MODE_BUTT
186 } MipiWdrMode;
187 
188 /**
189  * @brief Mipi device properties.
190  *
191  * @since 1.0
192  */
193 typedef struct {
194     /** data type: 8/10/12/14/16 bit */
195     DataType inputDataType;
196     /** MIPI WDR mode */
197     MipiWdrMode wdrMode;
198     /** laneId: -1 - disable */
199     short laneId[MIPI_LANE_NUM];
200 
201     union {
202         /** used by the HI_MIPI_WDR_MODE_DT */
203         short dataType[WDR_VC_NUM];
204     };
205 } MipiDevAttr;
206 
207 /**
208  * @brief LVDS WDR mode.
209  *
210  * @since 1.0
211  */
212 typedef enum {
213     HI_WDR_MODE_NONE = 0x0,
214     HI_WDR_MODE_2F = 0x1,
215     HI_WDR_MODE_3F = 0x2,
216     HI_WDR_MODE_4F = 0x3,
217     HI_WDR_MODE_DOL_2F = 0x4,
218     HI_WDR_MODE_DOL_3F = 0x5,
219     HI_WDR_MODE_DOL_4F = 0x6,
220     HI_WDR_MODE_BUTT
221 } WdrMode;
222 
223 /**
224  * @brief LVDS synchronization mode.
225  *
226  * @since 1.0
227  */
228 typedef enum {
229     /** sensor SOL, EOL, SOF, EOF */
230     LVDS_SYNC_MODE_SOF = 0,
231     /** SAV, EAV */
232     LVDS_SYNC_MODE_SAV,
233     LVDS_SYNC_MODE_BUTT
234 } LvdsSyncMode;
235 
236 /**
237  * @brief LVDS Vsync type.
238  *
239  * @since 1.0
240  */
241 typedef enum {
242     LVDS_VSYNC_NORMAL   = 0x00,
243     LVDS_VSYNC_SHARE    = 0x01,
244     LVDS_VSYNC_HCONNECT = 0x02,
245     LVDS_VSYNC_BUTT
246 } LvdsVsyncType;
247 
248 /**
249  * @brief LVDS Vsync column synchronization parameters.
250  *
251  * @since 1.0
252  */
253 typedef struct {
254     LvdsVsyncType syncType;
255 
256     /* hconnect vsync blanking len, valid when the syncType is LVDS_VSYNC_HCONNECT */
257     unsigned short hblank1;
258     unsigned short hblank2;
259 } LvdsVsyncAttr;
260 
261 /**
262  * @brief Frame ID type.
263  *
264  * @since 1.0
265  */
266 typedef enum {
267     LVDS_FID_NONE    = 0x00,
268     /** frame identification id in SAV 4th */
269     LVDS_FID_IN_SAV  = 0x01,
270     /** frame identification id in first data */
271     LVDS_FID_IN_DATA = 0x02,
272     LVDS_FID_BUTT
273 } LvdsFidType;
274 
275 /**
276  * @brief Frame ID configuration information.
277  *
278  * @since 1.0
279  */
280 typedef struct {
281     LvdsFidType fidType;
282 
283     /** Sony DOL has the Frame Information Line, in DOL H-Connection mode,
284         should configure this flag as false to disable output the Frame Information Line */
285     unsigned char outputFil;
286 } LvdsFidAttr;
287 
288 /**
289  * @brief LVDS bit size end mode.
290  *
291  * @since 1.0
292  */
293 typedef enum {
294     LVDS_ENDIAN_LITTLE = 0x0,
295     LVDS_ENDIAN_BIG = 0x1,
296     LVDS_ENDIAN_BUTT
297 } LvdsBitEndian;
298 
299 /**
300  * @brief LVDS / SubLVDS / HiSPi device properties.
301  *
302  * @since 1.0
303  */
304 typedef struct {
305     /** data type: 8/10/12/14 bit */
306     DataType inputDataType;
307     /** WDR mode */
308     WdrMode wdrMode;
309 
310     /** sync mode: SOF, SAV */
311     LvdsSyncMode syncMode;
312     /** normal, share, hconnect */
313     LvdsVsyncAttr vsyncAttr;
314     /** frame identification code */
315     LvdsFidAttr fidAttr;
316 
317     /** data endian: little/big */
318     LvdsBitEndian dataEndian;
319     /** sync code endian: little/big */
320     LvdsBitEndian syncCodeEndian;
321     /** laneId: -1 - disable */
322     short laneId[LVDS_LANE_NUM];
323 
324     /** each vc has 4 params, syncCode[i]:
325         syncMode is SYNC_MODE_SOF: SOF, EOF, SOL, EOL
326         syncMode is SYNC_MODE_SAV: invalid sav, invalid eav, valid sav, valid eav */
327     unsigned short syncCode[LVDS_LANE_NUM][WDR_VC_NUM][SYNC_CODE_NUM];
328 } LvdsDevAttr;
329 
330 /**
331  * @brief The attribute of the combo device.
332  *
333  * Since MIPI RX can interface with CSI-2, LVDS, HiSPi and other timing, Mipi Rx is called a combo device.
334  *
335  * @since 1.0
336  */
337 typedef struct {
338     /** device number */
339     uint8_t devno;
340     /** input mode: MIPI/LVDS/SUBLVDS/HISPI/DC */
341     InputMode inputMode;
342     MipiDataRate dataRate;
343     /** MIPI Rx device crop area (corresponding to the oringnal sensor input image size) */
344     ImgRect imgRect;
345 
346     union {
347         MipiDevAttr mipiAttr;
348         LvdsDevAttr lvdsAttr;
349     };
350 } ComboDevAttr;
351 
352 /**
353  * @brief PHY common mode voltage mode.
354  *
355  * @since 1.0
356  */
357 typedef enum {
358     PHY_CMV_GE1200MV = 0x00,
359     PHY_CMV_LT1200MV = 0x01,
360     PHY_CMV_BUTT
361 } PhyCmvMode;
362 
363 /**
364  * @brief Obtains the MIPI CSI device handle with a specified channel ID.
365  *
366  * @param id Indicates the MIPI CSI channel ID.
367  *
368  * @return Returns the MIPI CSI device handle if the operation is successful; returns <b>NULL</b> otherwise.
369  *
370  * @since 1.0
371  */
372 DevHandle MipiCsiOpen(uint8_t id);
373 
374 /**
375  * @brief Releases the MIPI CSI device handle.
376  *
377  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
378  *
379  * @since 1.0
380  */
381 void MipiCsiClose(DevHandle handle);
382 
383 /**
384  * @brief Set the parameters of Mipi, CMOS or LVDS camera to the controller.
385  *
386  * The parameters including working mode, image area, image depth, data rate and physical channel.
387  *
388  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
389  * @param pAttr Indicates the pointer to the attribute.
390  *
391  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
392  *
393  * @since 1.0
394  */
395 int32_t MipiCsiSetComboDevAttr(DevHandle handle, ComboDevAttr *pAttr);
396 
397 /**
398  * @brief Set common mode voltage mode.
399  *
400  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
401  * @param devno There are 2 device numbers in total, pointing to 0 or 1.
402  * @param cmvMode Common mode voltage mode parameters.
403  *
404  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
405  *
406  * @since 1.0
407  */
408 int32_t MipiCsiSetPhyCmvmode(DevHandle handle, uint8_t devno, PhyCmvMode cmvMode);
409 
410 /**
411  * @brief Reset sensor.
412  *
413  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
414  * @param snsResetSource The reset signal line number of sensor is called the reset source of sensor in software.
415  * sns is the abbreviation of sensor.
416  *
417  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
418  *
419  * @since 1.0
420  */
421 int32_t MipiCsiResetSensor(DevHandle handle, uint8_t snsResetSource);
422 
423 /**
424  * @brief Unreset sensor.
425  *
426  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
427  * @param snsResetSource The reset signal line number of sensor is called the reset source of sensor in software.
428  * sns is the abbreviation of sensor.
429  *
430  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
431  *
432  * @since 1.0
433  */
434 int32_t MipiCsiUnresetSensor(DevHandle handle, uint8_t snsResetSource);
435 
436 /**
437  * @brief Reset Mipi Rx.
438  *
439  * Different s32WorkingViNum have different enSnsType.
440  *
441  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
442  * @param comboDev MIPI RX or LVDS device type.
443  *
444  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
445  *
446  * @since 1.0
447  */
448 int32_t MipiCsiResetRx(DevHandle handle, uint8_t comboDev);
449 
450 /**
451  * @brief Uneset MIPI RX.
452  *
453  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
454  * @param comboDev MIPI RX or LVDS device type.
455  *
456  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
457  *
458  * @since 1.0
459  */
460 int32_t MipiCsiUnresetRx(DevHandle handle, uint8_t comboDev);
461 
462 /**
463  * @brief Set the lane distribution of Mipi Rx.
464  *
465  * Select the specific mode according to the form of hardware connection.
466  *
467  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
468  * @param laneDivideMode Lane division mode parameters.
469  *
470  * @since 1.0
471  */
472 int32_t MipiCsiSetHsMode(DevHandle handle, LaneDivideMode laneDivideMode);
473 
474 /**
475  * @brief Enable Mipi clock.
476  *
477  * Decide whether to use Mipi or LVDS according to the ensnstype parameter
478  * passed by the upper layer function.
479  *
480  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
481  * @param comboDev MIPI RX or LVDS device type.
482  *
483  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
484  *
485  * @since 1.0
486  */
487 int32_t MipiCsiEnableClock(DevHandle handle, uint8_t comboDev);
488 
489 /**
490  * @brief Disable the clock of Mipi device.
491  *
492  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
493  * @param comboDev MIPI RX or LVDS device type.
494  *
495  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
496  *
497  * @since 1.0
498  */
499 int32_t MipiCsiDisableClock(DevHandle handle, uint8_t comboDev);
500 
501 /**
502  * @brief Enable the sensor clock on Mipi.
503  *
504  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
505  * @param snsClkSource The clock signal line number of sensor, which is called the clock source of sensor in software.
506  * sns is the abbreviation of sensor.
507  *
508  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
509  *
510  * @since 1.0
511  */
512 int32_t MipiCsiEnableSensorClock(DevHandle handle, uint8_t snsClkSource);
513 
514 /**
515  * @brief Disable the sensor clock.
516  *
517  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
518  * @param snsClkSource The clock signal line number of sensor, which is called the clock source of sensor in software.
519  * sns is the abbreviation of sensor.
520  *
521  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
522  *
523  * @since 1.0
524  */
525 int32_t MipiCsiDisableSensorClock(DevHandle handle, uint8_t snsClkSource);
526 
527 /**
528  * @brief Set YUV and RAW data format and bit depth.
529  *
530  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
531  * @param dataType Pointer to image data format.
532  *
533  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
534  *
535  * @since 1.0
536  */
537 int32_t MipiCsiSetExtDataType(DevHandle handle, ExtDataType* dataType);
538 
539 /**
540  * @brief Sets additional parameters for a MIPI CSI device.
541  *
542  * @param handle Indicates the MIPI CSI device handle obtained via {@link MipiCsiOpen}.
543  * @param drvData Indicates the pointer to the additional parameters.
544  *
545  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
546  *
547  * @since 1.0
548  */
549 int32_t MipiCsiSetDrvData(DevHandle handle, void *drvData);
550 
551 #ifdef __cplusplus
552 #if __cplusplus
553 }
554 #endif
555 #endif /* __cplusplus */
556 
557 #endif /* MIPI_CSI_IF_H */
558