2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 #include <xdc/std.h>
37 #include <ti/sysbios/hal/Hwi.h>
39 #include "sap_csl_mcasp.h"
41 #ifndef INV
42 #define INV ((void*)(-1))
43 #endif
45 #define DEVICE_ENTRY(devNum) { \
46 FALSE, \
47 (volatile Uint32*)_MCASP_BASE_PORT##devNum##, \
48 _MCASP_XBUF##devNum##_ADDR, \
49 _MCASP_XBUF0##devNum##_ADDR, \
50 _MCASP_RBUF##devNum##_ADDR, \
51 _MCASP_RBUF0##devNum##_ADDR, \
52 _MCASP_DITCSR##devNum##_ADDR, \
53 _MCASP_DITUDR##devNum##_ADDR \
54 }
56 /******************************************************************************\
57 * static variable definitions
58 \******************************************************************************/
59 static MCASP_Obj _MCASP_deviceTable[_MCASP_PORT_CNT] =
60 {
61 DEVICE_ENTRY(0)
62 ,DEVICE_ENTRY(1)
63 ,DEVICE_ENTRY(2)
64 };
66 // -----------------------------------------------------------------------------
68 void MCASP_reset (MCASP_Handle hMcasp)
69 {
70 int oldMask;
73 oldMask = Hwi_disable ();
75 if (hMcasp == INV) {
76 MCASP_reset ((MCASP_Handle) (&(_MCASP_deviceTable[0])));
77 MCASP_reset ((MCASP_Handle) (&(_MCASP_deviceTable[1])));
78 MCASP_reset ((MCASP_Handle) (&(_MCASP_deviceTable[2])));
79 }
80 else {
81 MCASP_RSETH (hMcasp,PFUNC, MCASP_PFUNC_DEFAULT);
82 MCASP_RSETH (hMcasp,PDIR, MCASP_PDIR_DEFAULT);
83 MCASP_RSETH (hMcasp,AMUTE, MCASP_AMUTE_DEFAULT);
84 MCASP_RSETH (hMcasp,DLBCTL, MCASP_DLBCTL_DEFAULT);
85 MCASP_RSETH (hMcasp,DITCTL, MCASP_DITCTL_DEFAULT);
86 MCASP_RSETH (hMcasp,RMASK, MCASP_RMASK_DEFAULT);
87 MCASP_RSETH (hMcasp,RFMT, MCASP_RFMT_DEFAULT);
88 MCASP_RSETH (hMcasp,AFSRCTL, MCASP_AFSRCTL_DEFAULT);
89 MCASP_RSETH (hMcasp,ACLKRCTL,MCASP_ACLKRCTL_DEFAULT);
90 MCASP_RSETH (hMcasp,AHCLKRCTL,MCASP_AHCLKRCTL_DEFAULT);
91 MCASP_RSETH (hMcasp,RTDM,MCASP_RTDM_DEFAULT);
92 MCASP_RSETH (hMcasp,RINTCTL,MCASP_RINTCTL_DEFAULT);
93 MCASP_RSETH (hMcasp,RCLKCHK,MCASP_RCLKCHK_DEFAULT);
94 MCASP_RSETH (hMcasp,XMASK, MCASP_XMASK_DEFAULT);
95 MCASP_RSETH (hMcasp,XFMT,MCASP_XFMT_DEFAULT);
96 MCASP_RSETH (hMcasp,AFSXCTL,MCASP_AFSXCTL_DEFAULT);
97 MCASP_RSETH (hMcasp,ACLKXCTL,MCASP_ACLKXCTL_DEFAULT);
98 MCASP_RSETH (hMcasp,AHCLKXCTL,MCASP_AHCLKXCTL_DEFAULT);
99 MCASP_RSETH (hMcasp,XTDM,MCASP_XTDM_DEFAULT);
100 MCASP_RSETH (hMcasp,XINTCTL,MCASP_XINTCTL_DEFAULT);
101 MCASP_RSETH (hMcasp,XCLKCHK,MCASP_XCLKCHK_DEFAULT);
102 MCASP_RSETH (hMcasp,SRCTL0,MCASP_SRCTL_DEFAULT);
103 MCASP_RSETH (hMcasp,SRCTL1,MCASP_SRCTL_DEFAULT);
104 MCASP_RSETH (hMcasp,SRCTL2,MCASP_SRCTL_DEFAULT);
105 MCASP_RSETH (hMcasp,SRCTL3,MCASP_SRCTL_DEFAULT);
106 MCASP_RSETH (hMcasp,SRCTL4,MCASP_SRCTL_DEFAULT);
107 MCASP_RSETH (hMcasp,SRCTL5,MCASP_SRCTL_DEFAULT);
108 MCASP_RSETH (hMcasp,SRCTL6,MCASP_SRCTL_DEFAULT);
109 MCASP_RSETH (hMcasp,SRCTL7,MCASP_SRCTL_DEFAULT);
111 MCASP_RSETH (hMcasp,SRCTL8,MCASP_SRCTL_DEFAULT);
112 MCASP_RSETH (hMcasp,SRCTL9,MCASP_SRCTL_DEFAULT);
113 MCASP_RSETH (hMcasp,SRCTL10,MCASP_SRCTL_DEFAULT);
114 MCASP_RSETH (hMcasp,SRCTL11,MCASP_SRCTL_DEFAULT);
115 MCASP_RSETH (hMcasp,SRCTL12,MCASP_SRCTL_DEFAULT);
116 MCASP_RSETH (hMcasp,SRCTL13,MCASP_SRCTL_DEFAULT);
117 MCASP_RSETH (hMcasp,SRCTL14,MCASP_SRCTL_DEFAULT);
118 MCASP_RSETH (hMcasp,SRCTL15,MCASP_SRCTL_DEFAULT);
120 MCASP_RSETH (hMcasp,RSTAT,0x01F7);
121 MCASP_RSETH (hMcasp,XSTAT,0x01F7);
122 MCASP_RSETH (hMcasp,GBLCTL,MCASP_GBLCTL_DEFAULT);
123 }
125 Hwi_restore (oldMask);
126 return;
127 } //MCASP_reset
129 // -----------------------------------------------------------------------------
131 MCASP_Handle MCASP_open (int devNum, Uint32 flags)
132 {
133 MCASP_Handle hMcasp = INV;
134 int oldMask;
137 oldMask = Hwi_disable ();
138 if (!_MCASP_deviceTable[devNum].allocated) {
139 hMcasp = &(_MCASP_deviceTable[devNum]);
140 _MCASP_deviceTable[devNum].allocated = TRUE;
142 if (hMcasp != INV)
143 if (flags & MCASP_OPEN_RESET)
144 MCASP_reset(hMcasp);
145 }
146 Hwi_restore (oldMask);
148 return hMcasp;
149 } //MCASP_open
151 // -----------------------------------------------------------------------------
153 void MCASP_configRcv (MCASP_Handle hMcasp, MCASP_ConfigRcv *config)
154 {
155 volatile Uint32 *base = (volatile Uint32 *)(hMcasp->baseAddr);
156 register int x5,x6,x7,x8,x9,x10,x11,x12;
157 int oldMask;
160 oldMask = Hwi_disable ();
162 /* the compiler generates more efficient code if the loads */
163 /* and stores are grouped together rather than intermixed */
164 x5 = config->rmask;
165 x6 = config->rfmt;
166 x7 = config->afsrctl;
167 x8 = config->aclkrctl;
168 x9 = config->ahclkrctl;
169 x10 = config->rtdm;
170 x11 = config->rintctl;
171 x12 = config->rclkchk;
173 base[_MCASP_RMASK_OFFSET] = x5;
174 base[_MCASP_RFMT_OFFSET] = x6;
175 base[_MCASP_AFSRCTL_OFFSET] = x7;
176 base[_MCASP_ACLKRCTL_OFFSET]= x8;
177 base[_MCASP_AHCLKRCTL_OFFSET]= x9;
178 base[_MCASP_RTDM_OFFSET] = x10;
179 base[_MCASP_RINTCTL_OFFSET] = x11;
180 base[_MCASP_RCLKCHK_OFFSET] = x12;
182 Hwi_restore (oldMask);
184 } //MCASP_configRcv
186 // -----------------------------------------------------------------------------
188 void MCASP_configXmt (MCASP_Handle hMcasp, MCASP_ConfigXmt *config)
189 {
191 volatile Uint32 *base = (volatile Uint32 *)(hMcasp->baseAddr);
192 register int x13,x14,x15,x16,x17,x18,x19,x20;
193 int oldMask;
196 oldMask = Hwi_disable ();
198 /* the compiler generates more efficient code if the loads */
199 /* and stores are grouped together rather than intermixed */
200 x13 = config->xmask;
201 x14 = config->xfmt;
202 x15 = config->afsxctl;
203 x16 = config->aclkxctl;
204 x17 = config->ahclkxctl;
205 x18 = config->xtdm;
206 x19 = config->xintctl;
207 x20 = config->xclkchk;
209 base[_MCASP_XMASK_OFFSET] = x13;
210 base[_MCASP_XFMT_OFFSET] = x14;
211 base[_MCASP_AFSXCTL_OFFSET] = x15;
212 base[_MCASP_ACLKXCTL_OFFSET]= x16;
213 base[_MCASP_AHCLKXCTL_OFFSET]= x17;
214 base[_MCASP_XTDM_OFFSET] = x18;
215 base[_MCASP_XINTCTL_OFFSET] = x19;
216 base[_MCASP_XCLKCHK_OFFSET] = x20;
218 Hwi_restore (oldMask);
219 } //MCASP_configXmt
221 // -----------------------------------------------------------------------------