xref: /utopia/UTPA2-700.0.x/mxlib/include/drvMSPI.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
4 // All rights reserved.
5 //
6 // Unless otherwise stipulated in writing, any and all information contained
7 // herein regardless in any format shall remain the sole proprietary of
8 // MStar Semiconductor Inc. and be kept in strict confidence
9 // ("MStar Confidential Information") by the recipient.
10 // Any unauthorized act including without limitation unauthorized disclosure,
11 // copying, use, reproduction, sale, distribution, modification, disassembling,
12 // reverse engineering and compiling of the contents of MStar Confidential
13 // Information is unlawful and strictly prohibited. MStar hereby reserves the
14 // rights to any and all damages, losses, costs and expenses resulting therefrom.
15 //
16 ////////////////////////////////////////////////////////////////////////////////
17 
18 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 ///
20 /// @file   drvMSPI.h
21 /// @brief  Master SPI Driver Interface
22 /// @author MStar Semiconductor Inc.
23 ///////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 /*! \defgroup G_MSPI MSPI interface
26    *  \ingroup  G_PERIPHERAL
27 
28     \brief
29 
30     MSPI is a synchronous serial interface and can connect to a variety of external device.
31 
32     <b>Features</b>
33 
34      - Generic SPI protocol with half duplex
35      - Supports Motorola SPI compatible timing(CPHA/CPOL)
36      - 8-Byte write buffer and 8-Byte read buffer
37      - Configurable Bit width from one bit to 8 bits in a byte transfer
38      - Supports up to 8 slave device select signals
39      - Supports 3-wire mode
40      - Supports an internal RIU (Register Interface Unit) interface. RIU is an in-house protocol of MSTAR
41 
42     <b>MSPI Block Diagram</b> \n
43     \image html drvMSPI_pic.png
44 
45      \defgroup G_MSPI_INIT Initialization Task relative
46      \ingroup  G_MSPI
47      \defgroup G_MSPI_COMMON Common Task relative
48      \ingroup  G_MSPI
49      *! \defgroup G_MSPI_CONTROL Control relative
50      *  \ingroup  G_MSPI
51      *! \defgroup G_MSPI_OTHER  other relative
52      *  \ingroup  G_MSPI
53      \defgroup G_MSPI_ToBeModified MSPI api to be modified
54      \ingroup  G_MSPI
55      \defgroup G_MSPI_ToBeRemove MSPI api to be removed
56      \ingroup  G_MSPI
57 */
58 
59 
60 
61 #ifndef _DRV_MSPI_H_
62 #define _DRV_MSPI_H_
63 #include "MsCommon.h"
64 
65 
66 #ifdef __cplusplus
67 extern "C"
68 {
69 #endif
70 
71 #include "MsTypes.h"
72 //-------------------------------------------------------------------------------------------------
73 //  Driver Capability
74 //-------------------------------------------------------------------------------------------------
75 
76 //-------------------------------------------------------------------------------------------------
77 //  Macro and Define
78 //-------------------------------------------------------------------------------------------------
79 #define MSPI_UTOPIA20                  (0)
80 #define MSPI_READ_OPERATION    0
81 #define MSPI_WRITE_OPERATION   1
82 #define MSPI_CMD_TYPE          3
83 
84 // config bit map
85 #define MSPI_DC_CONFIG        1
86 #define MSPI_CLK_CONFIG       2
87 #define MSPI_FRAME_CONFIG     4
88 
89 //-------------------------------------------------------------------------------------------------
90 //  Type and Structure
91 //-------------------------------------------------------------------------------------------------
92 typedef struct
93 {
94     MS_U8 u8TrStart;      //time from trigger to first SPI clock
95     MS_U8 u8TrEnd;        //time from last SPI clock to transferred done
96     MS_U8 u8TB;           //time between byte to byte transfer
97     MS_U8 u8TRW;          //time between last write and first read
98 } MSPI_DCConfig;
99 
100 typedef struct
101 {
102     MS_U8 u8WBitConfig[8];      //bits will be transferred in write buffer
103     MS_U8 u8RBitConfig[8];      //bits Will be transferred in read buffer
104 } MSPI_FrameConfig;
105 
106 
107 typedef struct
108 {
109 	MS_U8 U8Clock;
110 	MS_BOOL BClkPolarity;
111 	MS_BOOL BClkPhase;
112     MS_U32 u32MAXClk;
113 } MSPI_CLKConfig;
114 
115 typedef struct
116 {
117 	MSPI_DCConfig  tMSPI_DCConfig[MSPI_CMD_TYPE];
118 	MSPI_FrameConfig  tMSPI_FrameConfig[MSPI_CMD_TYPE];
119 	MSPI_CLKConfig tMSPI_ClockConfig[MSPI_CMD_TYPE];
120 	MS_U8 U8ChipSel;
121 	MS_BOOL BLsbFirst;
122 	void (*MSPIIntHandler)(void); // interrupt handler
123 	MS_BOOL BIntEnable;   // interrupt mode enable or polling mode
124 	MS_U8 U8BitMapofConfig[MSPI_CMD_TYPE];
125     MS_U32 u32DevId;
126 } MSPI_config;
127 
128 typedef struct
129 {
130     MS_U16 PadCs;
131 }stMSPI_csPdCfg;
132 typedef enum _MSPI_ERRORNOn
133 {
134      E_MSPI_OK = 0
135     ,E_MSPI_INIT_FLOW_ERROR =1
136     ,E_MSPI_DCCONFIG_ERROR =2
137     ,E_MSPI_CLKCONFIG_ERROR =4
138     ,E_MSPI_FRAMECONFIG_ERROR =8
139     ,E_MSPI_OPERATION_ERROR = 0x10
140     ,E_MSPI_PARAM_OVERFLOW = 0x20
141     ,E_MSPI_MMIO_ERROR = 0x40
142     ,E_MSPI_HW_NOT_SUPPORT = 0x80
143     ,E_MSPI_NULL
144 }MSPI_ErrorNo;
145 
146 typedef enum
147 {
148     E_MSPI_DBGLV_NONE,    //disable all the debug message
149     E_MSPI_DBGLV_INFO,    //information
150     E_MSPI_DBGLV_NOTICE,  //normal but significant condition
151     E_MSPI_DBGLV_WARNING, //warning conditions
152     E_MSPI_DBGLV_ERR,     //error conditions
153     E_MSPI_DBGLV_CRIT,    //critical conditions
154     E_MSPI_DBGLV_ALERT,   //action must be taken immediately
155     E_MSPI_DBGLV_EMERG,   //system is unusable
156     E_MSPI_DBGLV_DEBUG,   //debug-level messages
157 } MSPI_DbgLv;
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 // include utopia v2  header files here
161 ////////////////////////////////////////////////////////////////////////////////
162 #include "drvMSPI_v2.h"
163 
164 //-------------------------------------------------------------------------------------------------
165 //  Function and Variable
166 //-------------------------------------------------------------------------------------------------
167 //------------------------------------------------------------------------------
168 /// @ingroup G_MSPI_INIT
169 /// Description : MSPI initial EXt
170 /// @return E_MSPI_OK :
171 /// @return >1 : failed to initial
172 //------------------------------------------------------------------------------
173 MSPI_ErrorNo MDrv_MSPI_Init_Ext(MS_U8 u8HWNum); // ToBeRemove
174 
175 //------------------------------------------------------------------------------
176 /// @ingroup G_MSPI_INIT
177 /// Description : MSPI initial
178 /// @return E_MSPI_OK :
179 /// @return >1 : failed to initial
180 //------------------------------------------------------------------------------
181 MSPI_ErrorNo MDrv_MSPI_Init(MSPI_config *tMSPIConfig, MS_U8 u8HWNum);
182 
183 //-------------------------------------------------------------------------------------------------
184 /// @ingroup G_MSPI_COMMON
185 /// Description : read data from MSPI
186 /// @param pData \b IN :pointer to receive data from MSPI read buffer
187 /// @param u16Size \ b OTU : read data size
188 /// @return the errorno of operation
189 //-------------------------------------------------------------------------------------------------
190 MSPI_ErrorNo MDrv_MSPI_Read(MS_U8 *pData, MS_U16 u16Size);
191 
192 //------------------------------------------------------------------------------
193 /// @ingroup G_MSPI_COMMON
194 /// Description : read data from MSPI
195 /// @param pData \b OUT :pointer to write  data to MSPI write buffer
196 /// @param u16Size \ b OTU : write data size
197 /// @return the errorno of operation
198 //------------------------------------------------------------------------------
199 MSPI_ErrorNo MDrv_MSPI_Write(MS_U8 *pData, MS_U16 u16Size);
200 
201 //------------------------------------------------------------------------------
202 /// @ingroup G_MSPI_ToBeRemove
203 /// Description : config spi transfer timing
204 /// @param ptDCConfig    \b OUT  struct pointer of transfer timing config
205 /// @return E_MSPI_OK : succeed
206 /// @return E_MSPI_DCCONFIG_ERROR : failed to config transfer timing
207 //------------------------------------------------------------------------------
208 MSPI_ErrorNo MDrv_MSPI_DCConfig(MSPI_DCConfig *ptDCConfig); // ToBeRemove
209 
210 //------------------------------------------------------------------------------
211 /// @ingroup G_MSPI_ToBeRemove
212 /// Description : config spi clock setting
213 /// @param ptCLKConfig    \b OUT  struct pointer of clock config
214 /// @return E_MSPI_OK : succeed
215 /// @return E_MSPI_CLKCONFIG_ERROR : failed to config spi clock
216 //------------------------------------------------------------------------------
217 MSPI_ErrorNo MDrv_MSPI_CLKConfig(MSPI_CLKConfig *ptCLKConfig); // ToBeRemove
218 
219 
220 //------------------------------------------------------------------------------
221 /// @ingroup G_MSPI_ToBeRemove
222 /// Description : config spi transfer timing
223 /// @param ptDCConfig    \b OUT  struct pointer of bits of buffer tranferred to slave config
224 /// @return E_MSPI_OK : succeed
225 /// @return E_MSPI_FRAMECONFIG_ERROR : failed to config transfered bit per buffer
226 //------------------------------------------------------------------------------
227 MSPI_ErrorNo MDrv_MSPI_FRAMEConfig(MSPI_FrameConfig *ptFrameConfig); // ToBeRemove
228 
229 //------------------------------------------------------------------------------
230 /// Description : Enable Slave device
231 //------------------------------------------------------------------------------
232 //-------------------------------------------------------------------------------------------------
233 /// @ingroup G_MSPI_COMMON
234 /// Description : read data from MSPI
235 /// @param pData \b IN :pointer to receive data from MSPI read buffer
236 /// @param u16Size \ b OTU : read data size
237 /// @return the errorno of operation
238 //-------------------------------------------------------------------------------------------------
239 void MDrv_MSPI_SlaveEnable(MS_BOOL Enable);
240 
241 //------------------------------------------------------------------------------
242 /// Description :
243 /// @return TRUE : chip support
244 /// @return FALSE:
245 //------------------------------------------------------------------------------
246 //-------------------------------------------------------------------------------------------------
247 /// @ingroup G_MSPI_COMMON
248 /// Description : read data from MSPI
249 /// @param pData \b IN :pointer to receive data from MSPI read buffer
250 /// @param u16Size \ b OTU : read data size
251 /// @return the errorno of operation
252 //-------------------------------------------------------------------------------------------------
253 MS_BOOL MDrv_MSPI_HW_Support(void);
254 
255 //-------------------------------------------------------------------------------------------------
256 /// @ingroup G_MSPI_COMMON
257 /// Description : read data from MSPI
258 /// @param pData \b IN :pointer to receive data from MSPI read buffer
259 /// @param u16Size \ b OTU : read data size
260 /// @return the errorno of operation
261 //-------------------------------------------------------------------------------------------------
262 MS_U32 MDrv_MSPI_SetPowerState(EN_POWER_MODE enPowerState);
263 
264 //-------------------------------------------------------------------------------------------------
265 /// @ingroup G_MSPI_COMMON
266 /// Description : read data from MSPI
267 /// @param pData \b IN :pointer to receive data from MSPI read buffer
268 /// @param u16Size \ b OTU : read data size
269 /// @return the errorno of operation
270 //-------------------------------------------------------------------------------------------------
271 MS_BOOL MDrv_MSPI_SetDbgLevel(MS_U8 u8DbgLevel);
272 
273 //==================================================================
274 //         Master SPI API with slave device id to support multiple slave device
275 //==================================================================
276 //-------------------------------------------------------------------------------------------------
277 /// @ingroup G_MSPI_INIT
278 /// Description : read data from MSPI
279 /// @param pData \b IN :pointer to receive data from MSPI read buffer
280 /// @param u16Size \ b OTU : read data size
281 /// @return the errorno of operation
282 //-------------------------------------------------------------------------------------------------
283 MSPI_ErrorNo MDrv_MasterSPI_Init(MSPI_config *tMSPIConfig, MS_U8 u8HWNum);
284 //-------------------------------------------------------------------------------------------------
285 /// @ingroup G_MSPI_COMMON
286 /// Description : read data from MSPI
287 /// @param pData \b IN :pointer to receive data from MSPI read buffer
288 /// @param u16Size \ b OTU : read data size
289 /// @return the errorno of operation
290 //-------------------------------------------------------------------------------------------------
291 MSPI_ErrorNo MDrv_MasterSPI_Read(MS_U32 u32DevID, MS_U8 *pData, MS_U16 u16Size);
292 //-------------------------------------------------------------------------------------------------
293 /// @ingroup G_MSPI_COMMON
294 /// Description : read data from MSPI
295 /// @param pData \b IN :pointer to receive data from MSPI read buffer
296 /// @param u16Size \ b OTU : read data size
297 /// @return the errorno of operation
298 //-------------------------------------------------------------------------------------------------
299 MSPI_ErrorNo MDrv_MasterSPI_Write(MS_U32 u32DevID, MS_U8 *pData, MS_U16 u16Size);
300 //-------------------------------------------------------------------------------------------------
301 /// MOBF Encrypt
302 /// @ingroup G_MSPI_ToBeRemove
303 /// @param u32Key \b IN: Key
304 /// @param bEnable \b IN: TRUE/FLASE
305 /// @return DRVAESDMA_OK : Success
306 /// @return Others : Fail
307 //-------------------------------------------------------------------------------------------------
308 MSPI_ErrorNo MDrv_MasterSPI_DCConfig(MS_U32 u32DevID, MSPI_DCConfig *ptDCConfig); // ToBeRemove
309 //-------------------------------------------------------------------------------------------------
310 /// MOBF Encrypt
311 /// @ingroup G_MSPI_ToBeRemove
312 /// @param u32Key \b IN: Key
313 /// @param bEnable \b IN: TRUE/FLASE
314 /// @return DRVAESDMA_OK : Success
315 /// @return Others : Fail
316 //-------------------------------------------------------------------------------------------------
317 MSPI_ErrorNo MDrv_MasterSPI_CLKConfig(MS_U32 u32DevID, MSPI_CLKConfig *ptCLKConfig); // ToBeRemove
318 //-------------------------------------------------------------------------------------------------
319 /// MOBF Encrypt
320 /// @ingroup G_MSPI_ToBeRemove
321 /// @param u32Key \b IN: Key
322 /// @param bEnable \b IN: TRUE/FLASE
323 /// @return DRVAESDMA_OK : Success
324 /// @return Others : Fail
325 //-------------------------------------------------------------------------------------------------
326 MSPI_ErrorNo MDrv_MasterSPI_FRAMEConfig(MS_U32 u32DevID, MSPI_FrameConfig *ptFrameConfig); // ToBeRemove
327 //-------------------------------------------------------------------------------------------------
328 /// @ingroup G_MSPI_COMMON
329 /// Description : read data from MSPI
330 /// @param pData \b IN :pointer to receive data from MSPI read buffer
331 /// @param u16Size \ b OTU : read data size
332 /// @return the errorno of operation
333 //-------------------------------------------------------------------------------------------------
334 MSPI_ErrorNo MDrv_MasterSPI_SlaveEnable(MS_U32 u32DevID, MS_BOOL Enable);
335 //-------------------------------------------------------------------------------------------------
336 /// MOBF Encrypt
337 /// @ingroup G_MSPI_ToBeRemove
338 /// @param u32Key \b IN: Key
339 /// @param bEnable \b IN: TRUE/FLASE
340 /// @return DRVAESDMA_OK : Success
341 /// @return Others : Fail
342 //-------------------------------------------------------------------------------------------------
343 MS_BOOL MDrv_MasterSPI_CsPadConfig(MS_U32 u32DevID, MS_U32 u32CsPad); // ToBeRemove
344 //-------------------------------------------------------------------------------------------------
345 /// MOBF Encrypt
346 /// @ingroup G_MSPI_ToBeRemove
347 /// @param u32Key \b IN: Key
348 /// @param bEnable \b IN: TRUE/FLASE
349 /// @return DRVAESDMA_OK : Success
350 /// @return Others : Fail
351 //-------------------------------------------------------------------------------------------------
352 MS_BOOL MDrv_MasterSPI_MaxClkConfig(MS_U32 u32DevID, MS_U32 u32MaxClk); // ToBeRemove
353 
354 //------------------------------------------------------------------------------
355 /// Description : config mspi info for local dimming
356 /// @param stMspi_Info      \b IN   mspi info struct
357 /// @return E_MSPI_OK : succeed
358 /// @return E_MSPI_FRAMECONFIG_ERROR : failed to config mspi
359 //------------------------------------------------------------------------------
360 MSPI_ErrorNo MDrv_MSPI_Info_Config(ST_DRV_MSPI_INFO *stMspi_Info);
361 //-------------------------------------------------------------------------------------------------
362 /// MOBF Encrypt
363 /// @ingroup G_MSPI_ToBeRemove
364 /// @param Direct \b IN: read or write flag 0:read 1:write
365 /// @param u8Bytes \b IN: set read/write trigger buffer bytes size
366 /// @return DRVAESDMA_OK : Success
367 /// @return Others : Fail
368 //-------------------------------------------------------------------------------------------------
369 MSPI_ErrorNo MDrv_MSPI_RWBytes(MS_BOOL Direct, MS_U8 u8Bytes);
370 #ifdef __cplusplus
371 }
372 #endif
373 
374 #endif // _DRV_MSPI_H_
375 
376