• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# MIPI CSI<a name="title_MIPI_CSIDes"></a>
2
3## Overview<a name="section1_MIPI_CSIDes"></a>
4
5Defined by the Mobile Industry Processor Interface (MIPI) Alliance, the Camera Serial Interface (CSI) is a specification that allows data to be transmitted from the camera to the host processor on mobile platforms. As the second release, the MIPI CSI-2 consists of the application layer, protocol layer, and physical layer. It supports a maximum of four-lane data transmission and a single-lane transmission rate of 1 Gbit/s.
6
7The physical layer supports the high speed (HS) and low power (LP) modes. Using low-voltage differential signaling (LVDS), the HS mode delivers 80 Mbit/s to 1 Gbit/s transmission speed but high power consumption. The unidirectional LP mode provides lower power consumption but lower transmission speed (< 10 Mbit/s). The blend of the two modes ensures high-speed transmission of massive data (such as images) and minimized power consumption when less data is transmitted.
8
9The figure below shows a simplified CSI. The D-PHY transmits data by using one pair of source-synchronized differential clocks and one to four pairs of differential data lanes. Data is transmitted in Double Data Rate (DDR) mode, that is, data is transmitted on both the rising and falling edges of the clock.
10
11**Figure 1** CSI TX and RX interfaces<a name="fig1_MIPI_CSIDes"></a>
12![](figures/CSI_TX-RX_interface.png)
13
14### ComboDevAttr Structure<a name="section1.1_MIPI_CSIDes"></a>
15
16**Table 1** ComboDevAttr structure
17
18<a name="table1_MIPI_CSIDes"></a>
19
20| Name     | Description                                                 |
21| --------- | ----------------------------------------------------- |
22| devno     | Device number.                                               |
23| inputMode | Input mode, which can be MIPI, LVDS, sub-LVDS, HiSPI, or DC.                |
24| dataRate  | Input rate of the MIPI RX scalable low voltage signaling (SLVS).                                |
25| imgRect   | Crop area of the MIPI RX device (same as the size of the input image of the sensor).|
26| MIPIAttr  | Attributes of the MIPI device.                                         |
27| lvdsAttr  | Attributes of the LVDS, sub-LVDS, or HiSPi device.                           |
28
29### ExtDataType Structure<a name="section1.2_MIPI_CSIDes"></a>
30
31**Table 2** ExtDataType structure
32
33<a name="table2_MIPI_CSIDes"></a>
34
35| Name           | Description                           |
36| --------------- | ------------------------------- |
37| devno           | Device number.                         |
38| num             | Sensor number.                       |
39| extDataBitWidth | Bit depth of an image.                     |
40| extDataType     | Pointer to the YUV, raw data format, and bit depth.|
41
42### Available APIs<a name="section1.3_MIPI_CSIDes"></a>
43
44**Table 3** MIPI CSI APIs
45
46<a name="table3_MIPI_CSIDes"></a>
47
48  | Category| API|
49| -------- | -------- |
50| Opening or closing the MIPI CSI controller operation handle| **MipiCsiOpen**: opens the MIPI CSI controller operation handle.<br>**MipiCsiClose**: closes the MIPI CSI controller operation handle.|
51| Setting MIPI CSI parameters| **MipiCsiSetComboDevAttr**: sets parameters of the MIPI, CMOS, or LVDS camera to the controller. The parameters include the working mode, image area, image depth, data rate, and physical channel.<br>**MipiCsiSetExtDataType** (optional): sets the YUV and RAW data formats and bit depths.<br>**MipiCsiSetHsMode**: sets the MIPI RX lane distribution. Set the mode based on the hardware connection.<br>**MipiCsiSetPhyCmvmode**: sets the common-mode voltage (CMV) mode.|
52| Resetting a sensor or deasserting the reset of a sensor| **MipiCsiResetSensor**: resets a sensor.<br>**MipiCsiUnresetSensor**: deasserts the reset of a sensor.|
53| Resetting the MIPI RX or deasserting the reset of the MIPI RX| **MipiCsiResetRx**: resets the MIPI&amp;nbsp;RX. The value of **enSnsType** varies depending on the value of **s32WorkingViNum**.<br>**MipiCsiUnresetRx**: deasserts the reset on the MIPI&amp;nbsp;RX.|
54| Enabling or disabling the MIPI clock| **MipiCsiEnableClock**: enables the MIPI clock. The **enSnsType** passed by the upper-layer function during electrophoresis determines whether MIPI or LVDS is used.<br>**MipiCsiDisableClock**: disables the MIPI clock.|
55| Enabling or disabling the MIPI sensor clock| **MipiCsiEnableSensorClock**: enables the MIPI sensor clock.<br>**MipiCsiDisableSensorClock**: disables the MIPI sensor clock.|
56
57
58## Usage Guidelines<a name="section2_MIPI_CSIDes"></a>
59
60### How to Use<a name="section2.1_MIPI_CSIDes"></a>
61
62The figure below illustrates how to use the APIs.
63
64**Figure 2** Using MIPI CSI driver APIs
65
66![](figures/using-MIPI-CSI-process.png)
67
68### Opening the MIPI CSI Controller Operation Handle<a name="section2.2_MIPI_CSIDes"></a>
69
70Before starting MIPI CSI communication, call **MipiCsiOpen** to open the MIPI CSI device handle. This function returns the MIPI CSI device handle with the specified lane ID.
71
72```c
73DevHandle MipiCsiOpen(uint8_t id);
74```
75
76**Table 4** Description of MipiCsiOpen
77
78<a name="table4_MIPI_CSIDes"></a>
79
80| Parameter      | Description                                       |
81| ---------- | ----------------------------------------------- |
82| id         | MIPI CSI lane ID.                                 |
83| **Return Value**| **Description**                                 |
84| NULL       | The operation fails.                                       |
85| Device handle  | MIPI CSI device handle with the specified lane ID. The data type is **DevHandle**.|
86
87For example, open the controller operation handle for MIPI CSI lane 0:
88
89```c
90DevHandle mipiCsiHandle = NULL;  /* Device handle */
91id = 0; /* MIPI CSI lane ID */
92
93/* Open the controller operation handle. */
94MipiCsiHandle = MipiCsiOpen(id);
95if (MipiCsiHandle == NULL) {
96    HDF_LOGE("MipiCsiOpen: failed\n");
97    return;
98}
99```
100
101### Setting MIPI CSI Parameters<a name="section2.3_MIPI_CSIDes"></a>
102
103-   Set MIPI CSI parameters.
104
105    ```c
106    int32_t MipiCsiSetComboDevAttr(DevHandle handle, ComboDevAttr *pAttr);
107    ```
108
109    **Table 5** Description of MipiCsiSetComboDevAttr
110
111    <a name="table5_MIPI_CSIDes"></a>
112
113    | Parameter      | Description                  |
114    | ---------- | -------------------------- |
115    | handle     | Controller operation handle.            |
116    | pAttr      | Pointer to the MIPI CSI structure.|
117    | **Return Value**| **Description**            |
118    | 0          | The operation is successful.                  |
119    | Negative value      | The operation fails.                  |
120
121    ```c
122    int32_t ret;
123    struct ComboDevAttr attr;
124
125    /* The current configuration is as follows: */
126    (void)memset_s(&attr, sizeof(ComboDevAttr), 0, sizeof(ComboDevAttr));
127    attr.devno = 0; /* Device 0 */
128    attr.inputMode = INPUT_MODE_MIPI; /* The input mode is MIPI. */
129    attr.dataRate = MIPI_DATA_RATE_X1; /* The data rate is 1 pixel per clock cycle. */
130    attr.imgRect.x = 0; /* The value 0 indicates the upper left position of the image sensor. */
131    attr.imgRect.y = 0; /* The value 0 indicates the upper right position of the image sensor. */
132    attr.imgRect.width = 2592; /* The width of the image sensor is 2592. */
133    attr.imgRect.height = 1944; /* The height of the image sensor is 1944. */
134    /* Write the MIPI CSI configuration. */
135    ret = MipiCsiSetComboDevAttr(MipiCsiHandle, &attr);
136    if (ret != 0) {
137        HDF_LOGE("%s: MipiCsiSetComboDevAttr fail! ret=%d\n", __func__, ret);
138        return -1;
139    }
140    ```
141
142-   Set the YUV, RAW data format, and bit depth.
143
144    ```c
145    int32_t MipiCsiSetExtDataType(DevHandle handle, ExtDataType* dataType);
146    ```
147
148    **Table 6** Description of MipiCsiSetExtDataType
149
150    <a name="table6_MIPI_CSIDes"></a>
151
152    | Parameter      | Description                       |
153    | ---------- | ------------------------------- |
154    | handle     | Controller operation handle.                 |
155    | dataType   | Pointer to the YUV, raw data format, and bit depth.|
156    | **Return Value**| **Description**                 |
157    | 0          | The operation is successful.                       |
158    | Negative value      | The operation fails.                       |
159
160    ```c
161    int32_t ret;
162    struct ExtDataType dataType;
163
164    /* Set the YUV, raw data format, and bit depth. */
165    dataType.devno = 0; /* Device 0 */
166    dataType.num = 0;   /* sensor 0 */
167    dataType.extDataBitWidth[0] = 12; /* Bit depth array element 0 */
168    dataType.extDataBitWidth[1] = 12; /* Bit depth array element 1 */
169    dataType.extDataBitWidth[2] = 12; /* Bit depth array element 2 */
170
171    dataType.extDataType[0] = 0x39; /* Define YUV, raw data format, and bit depth element 0. */
172    dataType.extDataType[1] = 0x39; /* Define YUV, raw data format, and bit depth element 1. */
173    dataType.extDataType[2] = 0x39; /* Define YUV, raw data format, and bit depth element 2. */
174    /* Set the YUV, raw data format, and bit depth. */
175    ret = MipiCsiSetExtDataType(MipiCsiHandle, &dataType);
176    if (ret != 0) {
177        HDF_LOGE("%s: MipiCsiSetExtDataType fail! ret=%d\n", __func__, ret);
178        return -1;
179    }
180    ```
181
182-   Set the MIPI RX lane distribution.
183
184    ```c
185    int32_t MipiCsiSetHsMode(DevHandle handle, LaneDivideMode laneDivideMode);
186    ```
187
188    **Table 7** Description of MipiCsiSetHsMode
189
190    <a name="table7_MIPI_CSIDes"></a>
191
192    | Parameter          | Description      |
193    | -------------- | -------------- |
194    | handle         | Controller operation handle.|
195    | laneDivideMode | Lane mode.  |
196    | **Return Value**    | **Description**|
197    | 0              | The operation is successful.      |
198    | Negative value          | The operation fails.      |
199
200    ```c
201    int32_t ret;
202    enum LaneDivideMode mode;
203
204    /* Set the lane mode to 0. */
205    mode = LANE_DIVIDE_MODE_0;
206    /* Set the MIPI RX lane distribution. */
207    ret = MipiCsiSetHsMode(MipiCsiHandle, mode);
208    if (ret != 0) {
209        HDF_LOGE("%s: MipiCsiSetHsMode fail! ret=%d\n", __func__, ret);
210        return -1;
211    }
212    ```
213
214-   Set the CMV mode.
215
216    ```c
217    int32_t MipiCsiSetPhyCmvmode(DevHandle handle, uint8_t devno, PhyCmvMode cmvMode);
218    ```
219
220    **Table 8** Description of MipiCsiSetPhyCmvmode
221
222    <a name="table8_MIPI_CSIDes"></a>
223
224    | Parameter      | Description        |
225    | ---------- | ---------------- |
226    | handle     | Controller operation handle.  |
227    | cmvMode    | CMV mode.|
228    | devno      | Device number.        |
229    | **Return Value**| **Description**  |
230    | 0          | The operation is successful.        |
231    | Negative value      | The operation fails.        |
232
233    ```c
234    int32_t ret;
235    enum PhyCmvMode mode;
236    uint8_t devno;
237
238    /* Set the CMV mode to 0. */
239    mode = PHY_CMV_GE1200MV;
240    /* The device number is 0. */
241    devno = 0;
242    /* Set the CMV mode. */
243    ret = MipiCsiSetPhyCmvmode(MipiCsiHandle, devno, mode);
244    if (ret != 0) {
245        HDF_LOGE("%s: MipiCsiSetPhyCmvmode fail! ret=%d\n", __func__, ret);
246        return -1;
247    }
248    ```
249
250### Resetting a Sensor or Deasserting the Reset of a Sensor<a name="section2.4_MIPI_CSIDes"></a>
251
252-   Reset a sensor.
253
254    ```c
255    int32_t MipiCsiResetSensor(DevHandle handle, uint8_t snsResetSource);
256    ```
257
258    **Table 9** Description of MipiCsiResetSensor
259
260    <a name="table9_MIPI_CSIDes"></a>
261
262    | Parameter          | Description                                        |
263    | -------------- | ------------------------------------------------ |
264    | handle         | Controller operation handle.                                  |
265    | snsResetSource | Sensor's reset signal cable number, which is called reset source of the sensor in software.|
266    | **Return Value**    | **Description**                                  |
267    | 0              | The operation is successful.                                        |
268    | Negative value          | The operation fails.                                        |
269
270    ```c
271    int32_t ret;
272    uint8_t snsResetSource;
273
274    /* The sensor's reset signal cable number is 0. */
275    snsResetSource = 0;
276    /* Reset the sensor. */
277    ret = MipiCsiResetSensor(MipiCsiHandle, snsResetSource);
278    if (ret != 0) {
279        HDF_LOGE("%s: MipiCsiResetSensor fail! ret=%d\n", __func__, ret);
280        return -1;
281    }
282    ```
283
284-   Deassert the reset of a sensor.
285
286    ```c
287    int32_t MipiCsiUnresetSensor(DevHandle handle, uint8_t snsResetSource);
288    ```
289
290    **Table 10** Description of MipiCsiUnresetSensor
291
292    <a name="table10_MIPI_CSIDes"></a>
293
294    | Parameter          | Description                                        |
295    | -------------- | ------------------------------------------------ |
296    | handle         | Controller operation handle.                                  |
297    | snsResetSource | Sensor's reset signal cable number, which is called reset source of the sensor in software.|
298    | **Return Value**    | **Description**                                  |
299    | 0              | The operation is successful.                                    |
300    | Negative value          | The operation fails.                                    |
301
302    ```c
303    int32_t ret;
304    uint8_t snsResetSource;
305
306    /* The sensor's reset signal cable number is 0. */
307    snsResetSource = 0;
308    /* Deassert the reset of the sensor. */
309    ret = MipiCsiUnresetSensor(MipiCsiHandle, snsResetSource);
310    if (ret != 0) {
311        HDF_LOGE("%s: MipiCsiUnresetSensor fail! ret=%d\n", __func__, ret);
312        return -1;
313    }
314    ```
315
316### Resetting the MIPI RX or Deasserting the Reset of the MIPI RX<a name="section2.5_MIPI_CSIDes"></a>
317
318-   Reset the MIPI RX.
319
320    ```c
321    int32_t MipiCsiResetRx(DevHandle handle, uint8_t comboDev);
322    ```
323
324    **Table 11** Description of MipiCsiResetRx
325
326    <a name="table11_MIPI_CSIDes"></a>
327
328    | Parameter      | Description             |
329    | ---------- | --------------------- |
330    | handle     | Controller operation handle.       |
331    | comboDev   | MIPI RX or LVDS channel number.|
332    | **Return Value**| **Description**       |
333    | 0          | The operation is successful.             |
334    | Negative value      | The operation fails.             |
335
336    ```c
337    int32_t ret;
338    uint8_t comboDev;
339
340    /* The channel number is 0.*/
341    comboDev = 0;
342    /* Reset the MIPI RX. */
343    ret = MipiCsiResetRx(MipiCsiHandle, comboDev);
344    if (ret != 0) {
345        HDF_LOGE("%s: MipiCsiResetRx fail! ret=%d\n", __func__, ret);
346        return -1;
347    }
348    ```
349
350-   Deassert the reset of the MIPI RX.
351
352    ```c
353    int32_t MipiCsiUnresetRx(DevHandle handle, uint8_t comboDev);
354    ```
355
356    **Table 12** Description of MipiCsiUnresetRx
357
358    <a name="table12_MIPI_CSIDes"></a>
359
360    | Parameter      | Description             |
361    | ---------- | --------------------- |
362    | handle     | Controller operation handle.       |
363    | comboDev   | MIPI RX or LVDS channel number.|
364    | **Return Value**| **Description**       |
365    | 0          | The operation is successful.         |
366    | Negative value      | The operation fails.         |
367
368    ```c
369    int32_t ret;
370    uint8_t comboDev;
371
372    /* The channel number is 0.*/
373    comboDev = 0;
374    /* Deassert the reset of the MIPI RX. */
375    ret = MipiCsiUnresetRx(MipiCsiHandle, comboDev);
376    if (ret != 0) {
377        HDF_LOGE("%s: MipiCsiUnresetRx fail! ret=%d\n", __func__, ret);
378        return -1;
379    }
380    ```
381
382### Enabling or Disabling the MIPI Clock<a name="section2.6_MIPI_CSIDes"></a>
383
384-   Enable the MIPI clock.
385
386    ```c
387    int32_t MipiCsiEnableClock(DevHandle handle, uint8_t comboDev);
388    ```
389
390    **Table 13** Description of MipiCsiEnableClock
391
392    <a name="table13_MIPI_CSIDes"></a>
393
394    | Parameter      | Description      |
395    | ---------- | -------------- |
396    | handle     | Controller operation handle.|
397    | comboDev   | Channel number.      |
398    | **Return Value**| **Description**|
399    | 0          | The operation is successful.      |
400    | Negative value      | The operation fails.      |
401
402    ```c
403    int32_t ret;
404    uint8_t comboDev;
405
406    /* The channel number is 0.*/
407    comboDev = 0;
408    /* Enable the MIPI clock. */
409    ret = MipiCsiEnableClock(MipiCsiHandle, comboDev);
410    if (ret != 0) {
411        HDF_LOGE("%s: MipiCsiEnableClock fail! ret=%d\n", __func__, ret);
412        return -1;
413    }
414    ```
415
416-   Disable the MIPI clock.
417
418    ```c
419    int32_t MipiCsiDisableClock(DevHandle handle, uint8_t comboDev);
420    ```
421
422    **Table 14** Description of MipiCsiDisableClock
423
424    <a name="table14_MIPI_CSIDes"></a>
425
426    | Parameter      | Description      |
427    | ---------- | -------------- |
428    | handle     | Controller operation handle.|
429    | comboDev   | Channel number.      |
430    | **Return Value**| **Description**|
431    | 0          | The operation is successful.      |
432    | Negative value      | The operation fails.      |
433
434    ```c
435    int32_t ret;
436    uint8_t comboDev;
437
438    /* The channel number is 0.*/
439    comboDev = 0;
440    /* Disable the MIPI clock. */
441    ret = MipiCsiDisableClock(MipiCsiHandle, comboDev);
442    if (ret != 0) {
443        HDF_LOGE("%s: MipiCsiDisableClock fail! ret=%d\n", __func__, ret);
444        return -1;
445    }
446    ```
447
448### Enabling or Disabling the MIPI Sensor Clock<a name="section2.7_MIPI_CSIDes"></a>
449
450-   Enable the MIPI sensor clock.
451
452    ```c
453    int32_t MipiCsiEnableSensorClock(DevHandle handle, uint8_t snsClkSource);
454    ```
455
456    **Table 15** Description of MipiCsiEnableSensorClock
457
458    <a name="table15_MIPI_CSIDes"></a>
459
460    | Parameter        | Description                                        |
461    | ------------ | ------------------------------------------------ |
462    | handle       | Controller operation handle.                                  |
463    | snsClkSource | Sensor's clock signal cable number, which is called clock source of the sensor in software.|
464    | **Return Value**  | **Description**                                  |
465    | 0            | The operation is successful.                                        |
466    | Negative value        | The operation fails.                                        |
467
468    ```c
469    int32_t ret;
470    uint8_t snsClkSource;
471
472    /* The sensor's clock signal cable number is 0. */
473    snsClkSource = 0;
474    /* Enable the MIPI sensor clock. */
475    ret = MipiCsiEnableSensorClock(MipiCsiHandle, snsClkSource);
476    if (ret != 0) {
477        HDF_LOGE("%s: MipiCsiEnableSensorClock fail! ret=%d\n", __func__, ret);
478        return -1;
479    }
480    ```
481
482-   Disable the MIPI sensor clock.
483
484    ```c
485    int32_t MipiCsiDisableSensorClock(DevHandle handle, uint8_t snsClkSource);
486    ```
487
488    **Table 16** Description of MipiCsiDisableSensorClock
489
490    <a name="table16_MIPI_CSIDes"></a>
491
492    | Parameter        | Description                                        |
493    | ------------ | ------------------------------------------------ |
494    | handle       | Controller operation handle.                                  |
495    | snsClkSource | Sensor's clock signal cable number, which is called clock source of the sensor in software.|
496    | **Return Value**  | **Description**                                  |
497    | 0            | The operation is successful.                                        |
498    | Negative value        | The operation fails.                                        |
499
500    ```c
501    int32_t ret;
502    uint8_t snsClkSource;
503
504    /* The sensor's clock signal cable number is 0. */
505    snsClkSource = 0;
506    /* Disable the MIPI sensor clock. */
507    ret = MipiCsiDisableSensorClock(MipiCsiHandle, snsClkSource);
508    if (ret != 0) {
509        HDF_LOGE("%s: MipiCsiDisableSensorClock fail! ret=%d\n", __func__, ret);
510        return -1;
511    }
512    ```
513
514### Closing a MIPI CSI Controller Operation Handle<a name="section2.8_MIPI_CSIDes"></a>
515
516After the MIPI CSI communication, close the MIPI CSI controller handle by calling the following function:
517
518```c
519void MipiCsiClose(DevHandle handle);
520```
521
522This function releases the resources requested by **MipiCsiOpen**.
523
524**Table 17** Description of MipiCsiClose
525
526<a name="table17_MIPI_CSIDes"></a>
527
528 | Parameter        | Description                                        |
529 | ------------ | ------------------------------------------------ |
530 | handle       | MIPI CSI controller operation handle.                                 |
531
532```c
533MipiCsiClose(MIPIHandle); /* Close the operation handle of the MIPI CSI controller. */
534```
535
536## Development Example<a name="section3_MIPI_CSIDes"></a>
537
538The sample code is as follows:
539
540```c
541#include "hdf.h"
542#include "MIPI_csi_if.h"
543
544void PalMipiCsiTestSample(void)
545{
546    uint8_t id;
547    int32_t ret;
548    uint8_t comboDev;
549    uint8_t snsClkSource;
550    uint8_t devno;
551    enum LaneDivideMode mode;
552    enum PhyCmvMode mode;
553    struct ComboDevAttr attr;
554    struct ExtDataType dataType;
555    DevHandle MipiCsiHandle = NULL;
556
557    /* Controller ID */
558    id = 0;
559    /* Open the controller operation handle. */
560    MipiCsiHandle = MipiCsiOpen(id);
561    if (MipiCsiHandle == NULL) {
562        HDF_LOGE("MipiCsiOpen: failed!\n");
563        return;
564    }
565
566    /* Set the lane mode to 0. */
567    mode = LANE_DIVIDE_MODE_0;
568    /* Set the MIPI RX lane distribution. */
569    ret = MipiCsiSetHsMode(MipiCsiHandle, mode);
570    if (ret != 0) {
571        HDF_LOGE("%s: MipiCsiSetHsMode fail! ret=%d\n", __func__, ret);
572        return;
573    }
574
575    /* The channel number is 0.*/
576    comboDev = 0;
577    /* Enable the MIPI clock. */
578    ret = MipiCsiEnableClock(MipiCsiHandle, comboDev);
579    if (ret != 0) {
580        HDF_LOGE("%s: MipiCsiEnableClock fail! ret=%d\n", __func__, ret);
581        return;
582    }
583
584    /* Reset the MIPI RX. */
585    ret = MipiCsiResetRx(MipiCsiHandle, comboDev);
586    if (ret != 0) {
587        HDF_LOGE("%s: MipiCsiResetRx fail! ret=%d\n", __func__, ret);
588        return;
589    }
590
591    /* The sensor's clock signal cable number is 0. */
592    snsClkSource = 0;
593    /* Enable the MIPI sensor clock. */
594    ret = MipiCsiEnableSensorClock(MipiCsiHandle, snsClkSource);
595    if (ret != 0) {
596        HDF_LOGE("%s: MipiCsiEnableSensorClock fail! ret=%d\n", __func__, ret);
597        return;
598    }
599
600    /* Reset the sensor. */
601    ret = MipiCsiResetSensor(MipiCsiHandle, snsResetSource);
602    if (ret != 0) {
603        HDF_LOGE("%s: MipiCsiResetSensor fail! ret=%d\n", __func__, ret);
604        return;
605    }
606
607    /* Set MIPI parameters. */
608    (void)memset_s(&attr, sizeof(ComboDevAttr), 0, sizeof(ComboDevAttr));
609    attr.devno = 0; /* Device 0 */
610    attr.inputMode = INPUT_MODE_MIPI; /* The input mode is MIPI. */
611    attr.dataRate = MIPI_DATA_RATE_X1; /* The data rate is 1 pixel per clock cycle. */
612    attr.imgRect.x = 0; /* The value 0 indicates the upper left position of the image sensor. */
613    attr.imgRect.y = 0; /* The value 0 indicates the upper right position of the image sensor. */
614    attr.imgRect.width = 2592; /* The width of the image sensor is 2592. */
615    attr.imgRect.height = 1944; /* The height of the image sensor is 1944. */
616    /* Write the MIPI CSI configuration. */
617    ret = MipiCsiSetComboDevAttr(MipiCsiHandle, &attr);
618    if (ret != 0) {
619        HDF_LOGE("%s: MipiCsiSetComboDevAttr fail! ret=%d\n", __func__, ret);
620        return;
621    }
622
623    /* Set the CMV mode to 0. */
624    mode = PHY_CMV_GE1200MV;
625    /* The device number is 0. */
626    devno = 0;
627    /* Set the CMV mode. */
628    ret = MipiCsiSetPhyCmvmode(MipiCsiHandle, devno, mode);
629    if (ret != 0) {
630        HDF_LOGE("%s: MipiCsiSetPhyCmvmode fail! ret=%d\n", __func__, ret);
631        return;
632    }
633
634    /* The channel number is 0.*/
635    comboDev = 0;
636    /* Deassert the reset of the MIPI RX. */
637    ret = MipiCsiUnresetRx(MipiCsiHandle, comboDev);
638    if (ret != 0) {
639        HDF_LOGE("%s: MipiCsiUnresetRx fail! ret=%d\n", __func__, ret);
640        return;
641    }
642
643    /* Disable the MIPI clock. */
644    ret = MipiCsiDisableClock(MipiCsiHandle, comboDev);
645    if (ret != 0) {
646        HDF_LOGE("%s: MipiCsiDisableClock fail! ret=%d\n", __func__, ret);
647        return;
648    }
649
650    /* The sensor's reset signal cable number is 0. */
651    snsResetSource = 0;
652    /* Deassert the reset of the sensor. */
653    ret = MipiCsiUnresetSensor(MipiCsiHandle, snsResetSource);
654    if (ret != 0) {
655        HDF_LOGE("%s: MipiCsiUnresetSensor fail! ret=%d\n", __func__, ret);
656        return;
657    }
658
659    /* Disable the MIPI sensor clock. */
660    ret = MipiCsiDisableSensorClock(MipiCsiHandle, snsClkSource);
661    if (ret != 0) {
662        HDF_LOGE("%s: MipiCsiDisableSensorClock fail! ret=%d\n", __func__, ret);
663        return;
664    }
665
666    /* Close the MIPI CSI device handle. */
667    MipiCsiClose(MipiCsiHandle);
668}
669```
670