]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/mcbsp-lld.git/blob - include/mcbsp_pvt.h
9bbe7d0aaab61abeb0e3916eff63cd12e4a9ac6f
[keystone-rtos/mcbsp-lld.git] / include / mcbsp_pvt.h
1 /*
2  * mcbsp_pvt.h
3  *
4  * McBSP Driver internal header file
5  *
6  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
7  *
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *
13  *    Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  *    Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the
19  *    distribution.
20  *
21  *    Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37 */
38 /**
39  *  \file     mcbsp_pvt.h
40  *
41  *  \brief    Header file conataining the driver internal definitions and data
42  *            structures.
43  *
44  *            (C) Copyright 2012, Texas Instruments, Inc
45  *
46  */
48 #ifndef _MCBSP_PVT_H_
49 #define _MCBSP_PVT_H_
52 /*============================================================================*/
53 /*                        INCLUDE FILES                                       */
54 /*============================================================================*/
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
60 /* MCBSP LLD includes */
61 #include <ti/csl/cslr_mcbsp.h>
62 #include <ti/sdo/edma3/drv/edma3_drv.h>
63 #include <ti/drv/mcbsp/mcbsp_drv.h>
64 #include <ti/csl/cslr_device.h>
66 /*============================================================================*/
67 /*                            MACRO DEFINTIONS                                */
68 /*============================================================================*/
70 #define Mcbsp_MAXLINKCNT               (2u)
71 /**<  Maximum number of EDMA jobs linked at a time (Must be 2).               */
73 #define Mcbsp_TXEVENTQUE               (1u)
74 /**<  Transmit EDMA channel event queue number                                */
76 #define Mcbsp_RXEVENTQUE               (2u)
77 /**<  Receive EDMA channel event queue number                                 */
79 #define Mcbsp_CNT_MAX_VAL              (0xFFFFu)
80 /**<  Max possible value of aCnt, bCnt and cCnt                               */
82 #define Mcbsp_STATUS_INVALID           (0xFFFF)
83 /**<  Generic invalidate status                                               */
85 #define Mcbsp_STATUS_VALID             (0x1)
86 /**<  Generic validate status                                                 */
88 #define Mcbsp_MAX_IOBUF_SIZE           (32768u)
89 /**< Maximum sixe of the I/O buffer programmable                              */
91 #define Mcbsp_FRAME_LENGTH             (127u)
92 /**< No of frames Max supported by the mcbsp                                  */
94 #ifndef CSL_MCBSP_PER_CNT
95 #define CSL_MCBSP_PER_CNT CSL_MCBSP_CNT
96 #endif
97 /*============================================================================*/
98 /*                         ENUMERATED DATA TYPES                              */
99 /*============================================================================*/
101 /**
102  *  \brief Mcbsp driver state
103  *
104  *   Mcbsp driver state enums used to track the driver and channel state.
105  */
106 typedef enum Mcbsp_DriverState_t
108     Mcbsp_DriverState_DELETED,
109     Mcbsp_DriverState_CREATED,
110     Mcbsp_DriverState_INITIALIZED,
111     Mcbsp_DriverState_OPENED,
112     Mcbsp_DriverState_CLOSED,
113     Mcbsp_DriverState_DEINITIALIZED
114 }Mcbsp_DriverState;
115 /**< Mcbsp driver and channel states                              */
117 /**
118  * \brief Mcbsp SPCR control enums
119  *
120  *  These enums are used to control the settings of the SPCR register.
121  */
122 typedef enum Mcbsp_SpcrCtrl_t
124     Mcbsp_SpcrCtrl_RX_ENABLE   = (1u),
125     /**< To enable receiver in resetControl Function              */
127     Mcbsp_SpcrCtrl_TX_ENABLE   = (2u),
128     /**< To enable Transmitter in resetControl Function           */
130     Mcbsp_SpcrCtrl_RX_DISABLE  = (4u),
131     /**< To disable Receiver in resetControl Function             */
133     Mcbsp_SpcrCtrl_TX_DISABLE  = (8u),
134     /**< To disable Transmitter in resetControl Function          */
136     Mcbsp_SpcrCtrl_FSYNC_ENABLE = (16u),
137     /**< To enable Frame Sync Generation in resetControl Function */
139     Mcbsp_SpcrCtrl_SRG_ENABLE   = (32u),
140     /**< To enable Sample Rate Generator in resetControl Function */
142     Mcbsp_SpcrCtrl_FSYNC_DISABLE = (64u),
143     /**< To disable Frame Sync Generation in resetControl Function*/
145     Mcbsp_SpcrCtrl_SRG_DISABLE = (128u)
146     /**< To disable Sample Rate Generator in resetControl Function*/
147 }Mcbsp_SpcrCtrl;
148 /**< Mcbsp SPCR control enums                                     */
150 /*============================================================================*/
151 /*                              DATA STRUCTURES                               */
152 /*============================================================================*/
154 typedef struct Mcbsp_Object_t Mcbsp_Object;
156 /**
157  * \brief Mcbsp channel Object
158  *
159  *  This structure maintains the current channel state. It also holds
160  *  information on DMA channel being used and holds the application
161  *  callback function to be called in case of an interrupt.
162  *
163  *  This structure is initialized by mdCreateChan and a pointer to this
164  *  is passed down to all other channel related functions. Lifetime of
165  *  the data structure is from its creation by mdCreateChan till it
166  *  is invalidated by mdDeleteChan.each instance object will have two channel
167  *  object one for TX and one for the RX channel.
168  */
169 typedef struct Mcbsp_ChannelObj_t
171     uint16_t                    mode;
172     /**< Mode of operation of the channel (MCBSP_MODE_INPUT or MCBSP_MODE_OUTPUT)           */
174     Mcbsp_DriverState           chanState;
175     /**< operational state of the channel (opened/closed)                     */
177     Mcbsp_Object               *devHandle;
178     /**< Pointer to McBSP device driver instance object                       */
180     Mcbsp_CallbackFxn           cbFxn;
181     /**< Driver call back function to be called once a I/O buffer is processed*/
183     void*                       cbArg;
184     /**< Callback Function argument                                           */
186     void*                       edmaHandle;
187     /**< Handle to the EDMA3 driver(given by application)                     */
189     uint32_t                    edmaEventQue;
190     /**< EDMA event queue to be used by the channel                           */
192     EDMA3_RM_TccCallback        edmaCallback;
193     /**< Edma callback function pointer                                       */
195     uint32_t                    xferChan;
196     /**< eDMA  ChannelID                                                      */
198     uint32_t                    tcc ;
199     /**< EDMA transfer completion code                                        */
201     uint32_t                    pramTbl[Mcbsp_MAXLINKCNT];
202     /**< Logical channel numbers of EDMA, which are used for linking          */
204     uint32_t                    pramTblAddr[Mcbsp_MAXLINKCNT];
205     /**<  Physical address of logical channel numbers of EDMA, which          *
206      * are used for linking                                                   */
208     void*                       ptrQPendList;
209     /**< Queue to hold the pending I/O buffers received from the application  */
211     void*                       ptrQFloatList;
212     /**< Queue to manage floating I/O buffers in DMA                          */
214     Mcbsp_IOBuf                *tempIOBuf;
215     /**< Temporary I/O buffer holder                                          */
217     Mcbsp_IOBuf                *dataIOBuf;
218     /**< Temporary I/O buffer holder used to load the next buffer in to EDMA  */
220     uint32_t                    submitCount;
221     /**< Number of submit calls pending in the driver                         */
223     Mcbsp_BufferFormat          dataFormat;
224     /**< Application supplied buffer format                                   */
226     Bool                        nextFlag;
227     /**< Flag to indicate if the state machine can be stopped or not          */
229     volatile Bool               bMuteON;
230     /**< Flag to set the mute ON/OFF status                                   */
232     volatile Bool               paused;
233     /**< Flag to indicate if the audio is paused or not                       */
235     volatile Bool               flush;
236     /**< Flag to indicate if the Driver IO request flush is set               */
238     volatile Bool               isTempIOBufValid;
239     /**< Flag to indicate whether a valid buffer is available in tempIOBuf    */
241     Bool                        enableHwFifo;
242     /**< whether the FIFO has to be enabled for this channel                  */
244     Mcbsp_GblErrCallback        gblErrCbk;
245     /**< Callback to called in case an error occurs(supplied by application)  */
247     uint32_t                    userDataBufferSize;
248     /**< Size of the data buffer to be transferred                            */
250     void*                       loopJobBuffer;
251     /**< Buffer to be transferred when the loop job is running                */
253     uint16_t                    loopJobLength;
254     /**<Length of userloop job for each serialiser                            */
256     uint32_t                    userLoopJobLength;
257     /**< user specified loop job length to be used if supplied                */
259     uint32_t                    nextLinkParamSetToBeUpdated;
260     /**<  Used to store the next index of link param to be updated            */
262     volatile Bool               loopjobUpdatedinParamset;
263     /**< Used to prevent updating second paramset with loopjob for            *
264      * last dataIOBuf edma callback                                           */
266     uint16_t                    roundedWordWidth;
267     /**< Word length bytes to be transferred for DMA transaction              */
269     uint16_t                    currentDataSize;
270     /**< data buffer size of the currently transferring buffer                */
272     Mcbsp_DataConfig            chanConfig;
273     /**< settings to configure the TX or RX hardware sections                 */
275     Mcbsp_ClkSetup              clkSetup;
276     /**< clock setup for the RX or the TX section                             */
278     Bool                        userLoopJob;
279     /**< Option to indicate if the user loop job is used or driver loop job   */
281     int32_t                     currentError;
282     /**< Current I/O buffer error status                                      */
284     uint32_t                   numEnabledChannels;
285     /**<  Number of channels enabled with multichannel mode                   */
287 }Mcbsp_ChannelObj;
288 /**< Mcbsp channel Object                                                     */
290 /**
291  * \brief   Mcbsp instance Object
292  *
293  * \note    This data structure holds the information pertaining to an instance
294  *          of the Mcbsp device.it holds information like the current device
295  *          state, handle to the McBSP channels. The data structure is
296  *          initialized during "mdBindDev", which is called during DSP-BIOS
297  *          initialization, and is persistent till it is invalidated by
298  *          "mdUnBindDev".
299  */
300 typedef struct
302     Bool                        inUse;
303     /**< Variable to indicate if the instance is in use or not                */
305     int32_t                     instNum;
306     /**< Instance number of the current instance                              */
308     Mcbsp_DriverState           devState;
309     /**< operational state of the driver (created/deleted)                    */
311     Mcbsp_DevMode               mode;
312     /**< Operating mode of the Mcbsp driver(Mcbsp)                            */
314     Mcbsp_OpMode                opMode;
315     /**< Operational mode of the driver(INT/DMA/POLLING)                      */
317     Bool                        enablecache;
318     /**< Buffer operations to be performed by the driver or not               */
320     Mcbsp_HwInfo_Unpadded       hwInfo;
321     /**< McBSP handle for initial port configuration                          */
323     Bool                        stopSmFsXmt;
324     /**< TX state machine status(Stopped/Running)                             */
326     Bool                        stopSmFsRcv;
327     /**< RX state machine status(Stopped/Running)                             */
329     Mcbsp_ChannelObj            xmtObj;
330     /**< Transmit channel object                                              */
332     Mcbsp_ChannelObj            rcvObj;
333     /**< Receive channel object                                               */
335     Mcbsp_srgConfig             srgrConfig;
336     /**< configuration settings for the Sample rate generator                 */
338     Bool                        txSrgEnable;
339     /**< Flag to indicate if the TX section needs the sample rate generator to*
340      * be enabled                                                             */
342     Bool                        rxSrgEnable;
343     /**< Flag to indicate if the RX section needs the sample rate generator to*
344      * be enabled                                                             */
345     
346     Bool                        srgConfigured;
347     /**< Flag to indicate if the SRGR settings are configured or not          */
349     volatile Bool               srgEnabled;
350     /**< Flag to indicate if the sample rate generator is enabled and running */
352     Bool                        txFsgEnable;
353     /**< Flag to indicate if the TX section needs the frame sync generator to *
354      * be enabled                                                             */
356     Bool                        rxFsgEnable;
357     /**< Flag to indicate if the RX section needs the frame sync generator to *
358      * be enabled                                                             */
360     Bool                        fsgConfigured;
361     /**< Flag to indicate if the Framesync generator is configured or not     */
362     
363     volatile Bool               fsgEnabled;
364     /**< Flag to indicate if the frame sync generator is enabled and running  */
366     uint32_t                    retryCount;
367     /**< The retry count value to be used when waiting for the TX empty to be *
368      * set                                                                    */
370     Bool                        loopJobMode;
371     /**< Variable to check if the loop job mode is enabled or not             */
373 }Mcbsp_Object_Unpadded;
375 struct Mcbsp_Object_t
377     /** Data structure without padding, so sizeof() can compute padding */
378     Mcbsp_Object_Unpadded obj;
379     /** Pad out to end of MCBSP_MAX_CACHE_ALIGN bytes to prevent something else
380      * from being placed on same cache line as Mcbsp_Object. Note that pad[0]
381      * is illegal, so must add full MCBSP_MAX_CACHE_ALIGN if structure is
382      * already padded by chance. */
383     uint8_t                 pad[MCBSP_MAX_CACHE_ALIGN - 
384                             (sizeof(Mcbsp_Object_Unpadded) % MCBSP_MAX_CACHE_ALIGN)];
385 };
386 /**< Mcbsp instance Object                                                    */
389 int32_t Mcbsp_localResetCtrl(Mcbsp_Object_Unpadded *instHandle, uint32_t selectMask);
391 void Mcbsp_localCompleteCurrentIo(Mcbsp_ChannelObj *chanHandle);
393 void Mcbsp_localEdmaCallback(uint32_t tcc, EDMA3_RM_TccStatus status, void* data);
395 void Mcbsp_localAbortReset(Mcbsp_ChannelObj *chanHandle);
397 void Mcbsp_localGetNextIndex(uint32_t *index);
399 int32_t Mcbsp_localSetupEdmaDuringOpen(Mcbsp_ChannelObj *chanHandle);
401 int32_t Mcbsp_localSubmitIoctl(Mcbsp_ChannelObj *chanHandle,
402                              Mcbsp_IOCTL       cmd,
403                              void*               arg,
404                              void*               param);
406 int32_t Mcbsp_localUpdtDtPktToLnkPrms(Mcbsp_ChannelObj *chanHandle,
407                                     Mcbsp_IOBuf       *const ioBuf);
409 int32_t Mcbsp_localEdmaChanPaRAMsetup(Mcbsp_ChannelObj *chanHandle);
411 int32_t Mcbsp_localEdmaProcessPkt(Mcbsp_ChannelObj *chanHandle,
412                                 Mcbsp_IOBuf       *ioBuf);
414 void Mcbsp_localCancelAndAbortAllIo(Mcbsp_ChannelObj *chanHandle);
416 void Mcbsp_localAbortReset(Mcbsp_ChannelObj *chanHandle);
418 int32_t Mcbsp_localGetIndicesSyncType(Mcbsp_ChannelObj   *chanHandle,
419                                     volatile int16_t     *bIndex,
420                                     volatile int16_t     *cIndex,
421                                     volatile uint16_t    *aCnt,
422                                     volatile uint16_t    *bCnt,
423                                     volatile uint16_t    *cCnt,
424                                     EDMA3_DRV_SyncType *syncType,
425                                     Bool                forLoopJobBuf);
427 void Mcbsp_localGetNextIndex(uint32_t *index);
428 int32_t Mcbsp_localConfigureSrgr(Mcbsp_Object_Unpadded *instHandle,
429                                Mcbsp_ChannelObj *chanHandle);
430 int32_t Mcbsp_localConfigureRcvChannel(Mcbsp_Object_Unpadded *instHandle,
431                                      Mcbsp_ChanParams *params);
432 int32_t Mcbsp_localConfigureXmtChannel(Mcbsp_Object_Unpadded *instHandle,
433                                      Mcbsp_ChanParams *params);
434 void Mcbsp_localLoadPktToEdma(Mcbsp_ChannelObj *chanHandle,Mcbsp_IOBuf *ioBuf); 
435 int32_t Mcbsp_localModifySampleRate(Mcbsp_ChannelObj *chanHandle,void* arg);
437 #ifndef MCBSP_LOOPJOB_ENABLE
438 void Mcbsp_TxFifo(int32_t arg0,int32_t arg1);
439 #endif /* MCBSP_LOOPJOB_ENABLE */
441 #ifdef __cplusplus
443 #endif /* extern "C" */
445 #endif /* _MCBSP_PVT_H_ */
446 /*============================================================================*/
447 /*                         END OF FILE                                        */
448 /*============================================================================*/