• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 #ifndef MIPI_DSI_CORE_H
10 #define MIPI_DSI_CORE_H
11 
12 #include "osal_mutex.h"
13 #include "hdf_base.h"
14 #include "hdf_device.h"
15 #include "hdf_device_desc.h"
16 #include "hdf_object.h"
17 #include "mipi_dsi_if.h"
18 
19 #ifdef __cplusplus
20 #if __cplusplus
21 extern "C" {
22 #endif
23 #endif /* __cplusplus */
24 
25 
26 #define MAX_CNTLR_CNT 4
27 
28 struct MipiDsiCntlr {
29     struct IDeviceIoService service;
30     struct HdfDeviceObject *device;
31     unsigned int devNo; /* device number */
32     struct MipiCfg cfg;
33     struct MipiDsiCntlrMethod *ops;
34     struct OsalMutex lock;
35     void *priv; /* be struct mipi_dsi_device */
36 };
37 
38 struct MipiDsiCntlrMethod {
39     int32_t (*setCntlrCfg)(struct MipiDsiCntlr *cntlr);
40     int32_t (*setCmd)(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd);
41     int32_t (*getCmd)(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd, uint32_t readLen, uint8_t *out);
42     void (*toHs)(struct MipiDsiCntlr *cntlr);
43     void (*toLp)(struct MipiDsiCntlr *cntlr);
44     void (*enterUlps)(struct MipiDsiCntlr *cntlr);
45     void (*exitUlps)(struct MipiDsiCntlr *cntlr);
46     int32_t (*powerControl)(struct MipiDsiCntlr *cntlr, uint8_t enable);
47     int32_t (*attach)(struct MipiDsiCntlr *cntlr, uint8_t *name);
48     int32_t (*setDrvData)(struct MipiDsiCntlr *cntlr, void *panelData);
49 };
50 
51 int32_t MipiDsiRegisterCntlr(struct MipiDsiCntlr *cntlr, struct HdfDeviceObject *device);
52 void MipiDsiUnregisterCntlr(struct MipiDsiCntlr *cntlr);
53 
54 /**
55   * @brief Turn HdfDeviceObject to an MipiDsiCntlr.
56  *
57  * @param device Indicates a HdfDeviceObject.
58  *
59  * @return Retrns the pointer of the MipiDsiCntlr on success; returns NULL otherwise.
60  * @since 1.0
61  */
62 struct MipiDsiCntlr *MipiDsiCntlrFromDevice(const struct HdfDeviceObject *device);
63 
64 /**
65  * @brief Obtains the MIPI DSI device handle with a specified channel ID.
66  *
67  * @param id Indicates the MIPI DSI channel ID.
68  *
69  * @return Returns the MIPI DSI device if the operation is successful; returns <b>NULL</b> otherwise.
70  *
71  * @since 1.0
72  */
73 struct MipiDsiCntlr *MipiDsiCntlrOpen(uint8_t id);
74 
75 /**
76  * @brief Releases the MIPI DSI device handle.
77  *
78  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
79  *
80  * @since 1.0
81  */
82 void MipiDsiCntlrClose(struct MipiDsiCntlr *cntlr);
83 
84 /**
85  * @brief Sets configuration parameters for a MIPI DSI device.
86  *
87  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
88  * @param cfg Indicates the pointer to the configuration parameters.
89  *
90  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
91  *
92  * @since 1.0
93  */
94 int32_t MipiDsiCntlrSetCfg(struct MipiDsiCntlr *cntlr, const struct MipiCfg *cfg);
95 
96 /**
97  * @brief Obtains the configuration parameters of a MIPI DSI device.
98  *
99  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
100  * @param cfg Indicates the pointer to the configuration parameters.
101  *
102  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
103  *
104  * @since 1.0
105  */
106 int32_t MipiDsiCntlrGetCfg(struct MipiDsiCntlr *cntlr, struct MipiCfg *cfg);
107 
108 /**
109  * @brief Sets LP mode for a MIPI DSI device.
110  *
111  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
112  *
113  * @since 1.0
114  */
115 void MipiDsiCntlrSetLpMode(struct MipiDsiCntlr *cntlr);
116 
117 /**
118  * @brief Sets the high-speed (HS) mode for a MIPI DSI device.
119  *
120  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
121  *
122  * @since 1.0
123  */
124 void MipiDsiCntlrSetHsMode(struct MipiDsiCntlr *cntlr);
125 
126 /**
127  * @brief Sends a display command set (DCS) command used for sending the initial parameters of a peripheral.
128  *
129  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
130  * @param cmd Indicates the pointer to the command to be sent.
131  *
132  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
133  *
134  * @since 1.0
135  */
136 int32_t MipiDsiCntlrTx(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd);
137 
138 /**
139 * @brief Receives a DCS command used for reading data, such as the status and parameters of a peripheral
140  *
141  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
142  * @param cmd Indicates the pointer to the command to be received.
143  * @param readLen Indicates the length of the data to read, in bytes.
144  * @param out Indicates the pointer to the read data.
145  *
146  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
147  *
148  * @since 1.0
149  */
150 int32_t MipiDsiCntlrRx(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd, int32_t readLen, uint8_t *out);
151 
152 /**
153 * @brief attach a DSI device to its DSI host
154  *
155  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
156  * @param name Indicates the name of a peripheral.
157  *
158  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
159  *
160  * @since 1.0
161  */
162 int32_t MipiDsiCntlrAttach(struct MipiDsiCntlr *cntlr, uint8_t *name);
163 
164 /**
165  * @brief Sets additional parameters for a MIPI DSI device.
166  *
167  * @param cntlr Indicates the MIPI DSI device obtained via {@link MipiDsiOpen}.
168  * @param panelData Indicates the pointer to the additional parameters.
169  *
170  * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
171  *
172  * @since 1.0
173  */
174 int32_t MipiDsiCntlrSetDrvData(struct MipiDsiCntlr *cntlr, void *panelData);
175 
176 void MipiDsiCntlrEnterUlps(struct MipiDsiCntlr *cntlr);
177 void MipiDsiCntlrExitUlps(struct MipiDsiCntlr *cntlr);
178 int32_t MipiDsiCntlrPowerControl(struct MipiDsiCntlr *cntlr, uint8_t enable);
179 
180 #ifdef __cplusplus
181 #if __cplusplus
182 }
183 #endif
184 #endif /* __cplusplus */
185 
186 #endif
187