blob: 2a28037dc3da4e18ae0bebbf3a38a0a5908bc0fb [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Custom IDEAS, Inc. <www.cideas.com>
4 * Jon Diekema <diekema@cideas.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00007 */
8
9#include <common.h>
10#include <ioports.h>
11#include <mpc8260.h>
12#include <asm/cpm_8260.h>
13#include <configs/sacsng.h>
14
15#include "clkinit.h"
16
Wolfgang Denkd87080b2006-03-31 18:32:53 +020017DECLARE_GLOBAL_DATA_PTR;
18
wdenkc6097192002-11-03 00:24:07 +000019int Daq64xSampling = 0;
20
21
22void Daq_BRG_Reset(uint brg)
23{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020024 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +000025 volatile uint *brg_ptr;
26
27 brg_ptr = (uint *)&immr->im_brgc1;
28
29 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +000030 brg_ptr = (uint *)&immr->im_brgc5;
31 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +000032 }
33 brg_ptr += brg;
34 *brg_ptr |= CPM_BRG_RST;
35 *brg_ptr &= ~CPM_BRG_RST;
36}
37
38void Daq_BRG_Disable(uint brg)
39{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020040 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +000041 volatile uint *brg_ptr;
42
43 brg_ptr = (uint *)&immr->im_brgc1;
44
45 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +000046 brg_ptr = (uint *)&immr->im_brgc5;
47 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +000048 }
49 brg_ptr += brg;
50 *brg_ptr &= ~CPM_BRG_EN;
51}
52
53void Daq_BRG_Enable(uint brg)
54{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +000056 volatile uint *brg_ptr;
57
58 brg_ptr = (uint *)&immr->im_brgc1;
59 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +000060 brg_ptr = (uint *)&immr->im_brgc5;
61 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +000062 }
63 brg_ptr += brg;
64 *brg_ptr |= CPM_BRG_EN;
65}
66
67uint Daq_BRG_Get_Div16(uint brg)
68{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020069 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +000070 uint *brg_ptr;
71
72 brg_ptr = (uint *)&immr->im_brgc1;
73 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +000074 brg_ptr = (uint *)&immr->im_brgc5;
75 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +000076 }
77 brg_ptr += brg;
78
79 if (*brg_ptr & CPM_BRG_DIV16) {
wdenk8bde7f72003-06-27 21:31:46 +000080 /* DIV16 active */
York Sun472d5462013-04-01 11:29:11 -070081 return true;
wdenkc6097192002-11-03 00:24:07 +000082 }
83 else {
wdenk8bde7f72003-06-27 21:31:46 +000084 /* DIV16 inactive */
York Sun472d5462013-04-01 11:29:11 -070085 return false;
wdenkc6097192002-11-03 00:24:07 +000086 }
87}
88
89void Daq_BRG_Set_Div16(uint brg, uint div16)
90{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020091 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +000092 uint *brg_ptr;
93
94 brg_ptr = (uint *)&immr->im_brgc1;
95 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +000096 brg_ptr = (uint *)&immr->im_brgc5;
97 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +000098 }
99 brg_ptr += brg;
100
101 if (div16) {
wdenk8bde7f72003-06-27 21:31:46 +0000102 /* DIV16 active */
103 *brg_ptr |= CPM_BRG_DIV16;
wdenkc6097192002-11-03 00:24:07 +0000104 }
105 else {
wdenk8bde7f72003-06-27 21:31:46 +0000106 /* DIV16 inactive */
107 *brg_ptr &= ~CPM_BRG_DIV16;
wdenkc6097192002-11-03 00:24:07 +0000108 }
109}
110
111uint Daq_BRG_Get_Count(uint brg)
112{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200113 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +0000114 uint *brg_ptr;
115 uint brg_cnt;
116
117 brg_ptr = (uint *)&immr->im_brgc1;
118 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +0000119 brg_ptr = (uint *)&immr->im_brgc5;
120 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +0000121 }
122 brg_ptr += brg;
123
124 /* Get the clock divider
125 *
126 * Note: A clock divider of 0 means divide by 1,
127 * therefore we need to add 1 to the count.
128 */
129 brg_cnt = (*brg_ptr & CPM_BRG_CD_MASK) >> CPM_BRG_DIV16_SHIFT;
130 brg_cnt++;
131 if (*brg_ptr & CPM_BRG_DIV16) {
wdenk8bde7f72003-06-27 21:31:46 +0000132 brg_cnt *= 16;
wdenkc6097192002-11-03 00:24:07 +0000133 }
134
135 return (brg_cnt);
136}
137
138void Daq_BRG_Set_Count(uint brg, uint brg_cnt)
139{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200140 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +0000141 uint *brg_ptr;
142
143 brg_ptr = (uint *)&immr->im_brgc1;
144 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +0000145 brg_ptr = (uint *)&immr->im_brgc5;
146 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +0000147 }
148 brg_ptr += brg;
149
150 /*
151 * Note: A clock divider of 0 means divide by 1,
152 * therefore we need to subtract 1 from the count.
153 */
154 if (brg_cnt > 4096) {
wdenk8bde7f72003-06-27 21:31:46 +0000155 /* Prescale = Divide by 16 */
156 *brg_ptr = (*brg_ptr & ~CPM_BRG_CD_MASK) |
wdenkc6097192002-11-03 00:24:07 +0000157 (((brg_cnt / 16) - 1) << CPM_BRG_DIV16_SHIFT);
158 *brg_ptr |= CPM_BRG_DIV16;
159 }
160 else {
wdenk8bde7f72003-06-27 21:31:46 +0000161 /* Prescale = Divide by 1 */
162 *brg_ptr = (*brg_ptr & ~CPM_BRG_CD_MASK) |
wdenkc6097192002-11-03 00:24:07 +0000163 ((brg_cnt - 1) << CPM_BRG_DIV16_SHIFT);
164 *brg_ptr &= ~CPM_BRG_DIV16;
165 }
166}
167
168uint Daq_BRG_Get_ExtClk(uint brg)
169{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200170 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +0000171 uint *brg_ptr;
172
173 brg_ptr = (uint *)&immr->im_brgc1;
174 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +0000175 brg_ptr = (uint *)&immr->im_brgc5;
176 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +0000177 }
178 brg_ptr += brg;
179
180 return ((*brg_ptr & CPM_BRG_EXTC_MASK) >> CPM_BRG_EXTC_SHIFT);
181}
182
183char* Daq_BRG_Get_ExtClk_Description(uint brg)
184{
185 uint extc;
186
187 extc = Daq_BRG_Get_ExtClk(brg);
188
189 switch (brg + 1) {
wdenk8bde7f72003-06-27 21:31:46 +0000190 case 1:
191 case 2:
192 case 5:
193 case 6: {
194 switch (extc) {
195 case 0: {
196 return ("BRG_INT");
197 }
198 case 1: {
199 return ("CLK3");
200 }
201 case 2: {
202 return ("CLK5");
203 }
204 }
205 return ("??1245??");
206 }
207 case 3:
208 case 4:
209 case 7:
210 case 8: {
211 switch (extc) {
212 case 0: {
213 return ("BRG_INT");
214 }
215 case 1: {
216 return ("CLK9");
217 }
218 case 2: {
219 return ("CLK15");
220 }
221 }
222 return ("??3478??");
223 }
wdenkc6097192002-11-03 00:24:07 +0000224 }
225 return ("??9876??");
226}
227
228void Daq_BRG_Set_ExtClk(uint brg, uint extc)
229{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200230 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +0000231 uint *brg_ptr;
232
233 brg_ptr = (uint *)&immr->im_brgc1;
234 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +0000235 brg_ptr = (uint *)&immr->im_brgc5;
236 brg -= 4;
wdenkc6097192002-11-03 00:24:07 +0000237 }
238 brg_ptr += brg;
239
240 *brg_ptr = (*brg_ptr & ~CPM_BRG_EXTC_MASK) |
wdenk8bde7f72003-06-27 21:31:46 +0000241 ((extc << CPM_BRG_EXTC_SHIFT) & CPM_BRG_EXTC_MASK);
wdenkc6097192002-11-03 00:24:07 +0000242}
243
244uint Daq_BRG_Rate(uint brg)
245{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200246 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +0000247 uint *brg_ptr;
248 uint brg_cnt;
249 uint brg_freq = 0;
250
251 brg_ptr = (uint *)&immr->im_brgc1;
252 brg_ptr += brg;
253 if (brg >= 5) {
wdenk8bde7f72003-06-27 21:31:46 +0000254 brg_ptr = (uint *)&immr->im_brgc5;
255 brg_ptr += (brg - 4);
wdenkc6097192002-11-03 00:24:07 +0000256 }
257
258 brg_cnt = Daq_BRG_Get_Count(brg);
259
260 switch (Daq_BRG_Get_ExtClk(brg)) {
wdenk8bde7f72003-06-27 21:31:46 +0000261 case CPM_BRG_EXTC_CLK3:
262 case CPM_BRG_EXTC_CLK5: {
wdenkc6097192002-11-03 00:24:07 +0000263 brg_freq = brg_cnt;
264 break;
265 }
266 default: {
267 brg_freq = (uint)BRG_INT_CLK / brg_cnt;
268 }
269 }
270 return (brg_freq);
271}
272
273uint Daq_Get_SampleRate(void)
wdenkc6097192002-11-03 00:24:07 +0000274{
275 /*
276 * Read the BRG's to return the actual sample rate.
277 */
278 return (Daq_BRG_Rate(MCLK_BRG) / (MCLK_DIVISOR * SCLK_DIVISOR));
279}
280
wdenkeb9401e2002-11-11 02:11:37 +0000281void Daq_Init_Clocks(int sample_rate, int sample_64x)
wdenkc6097192002-11-03 00:24:07 +0000282{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200283 volatile ioport_t *iopa = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 0 /* port A */);
wdenkeb9401e2002-11-11 02:11:37 +0000284 uint mclk_divisor; /* MCLK divisor */
wdenk8bde7f72003-06-27 21:31:46 +0000285 int flag; /* Interrupt state */
wdenkc6097192002-11-03 00:24:07 +0000286
287 /* Save off the clocking data */
288 Daq64xSampling = sample_64x;
289
290 /*
291 * Limit the sample rate to some sensible values.
292 */
wdenkeb9401e2002-11-11 02:11:37 +0000293 if (sample_rate > MAX_64x_SAMPLE_RATE) {
wdenk8bde7f72003-06-27 21:31:46 +0000294 sample_rate = MAX_64x_SAMPLE_RATE;
wdenkc6097192002-11-03 00:24:07 +0000295 }
296 if (sample_rate < MIN_SAMPLE_RATE) {
wdenk8bde7f72003-06-27 21:31:46 +0000297 sample_rate = MIN_SAMPLE_RATE;
wdenkc6097192002-11-03 00:24:07 +0000298 }
299
300 /*
301 * Initialize the MCLK/SCLK/LRCLK baud rate generators.
302 */
303
304 /* Setup MCLK */
305 Daq_BRG_Set_ExtClk(MCLK_BRG, CPM_BRG_EXTC_BRGCLK);
306
307 /* Setup SCLK */
308# ifdef RUN_SCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +0000309 Daq_BRG_Set_ExtClk(SCLK_BRG, CPM_BRG_EXTC_BRGCLK);
wdenkc6097192002-11-03 00:24:07 +0000310# else
wdenk8bde7f72003-06-27 21:31:46 +0000311 Daq_BRG_Set_ExtClk(SCLK_BRG, CPM_BRG_EXTC_CLK9);
wdenkc6097192002-11-03 00:24:07 +0000312# endif
313
314 /* Setup LRCLK */
315# ifdef RUN_LRCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +0000316 Daq_BRG_Set_ExtClk(LRCLK_BRG, CPM_BRG_EXTC_BRGCLK);
wdenkc6097192002-11-03 00:24:07 +0000317# else
wdenk8bde7f72003-06-27 21:31:46 +0000318 Daq_BRG_Set_ExtClk(LRCLK_BRG, CPM_BRG_EXTC_CLK5);
wdenkc6097192002-11-03 00:24:07 +0000319# endif
320
wdenkeb9401e2002-11-11 02:11:37 +0000321 /*
322 * Dynamically adjust MCLK based on the new sample rate.
323 */
324
325 /* Compute the divisors */
326 mclk_divisor = BRG_INT_CLK / (sample_rate * MCLK_DIVISOR * SCLK_DIVISOR);
327
328 /*
329 * Disable interrupt and save the current state
330 */
331 flag = disable_interrupts();
332
333 /* Setup MCLK */
334 Daq_BRG_Set_Count(MCLK_BRG, mclk_divisor);
335
336 /* Setup SCLK */
337# ifdef RUN_SCLK_ON_BRG_INT
338 Daq_BRG_Set_Count(SCLK_BRG, mclk_divisor * MCLK_DIVISOR);
339# else
340 Daq_BRG_Set_Count(SCLK_BRG, MCLK_DIVISOR);
341# endif
342
343# ifdef RUN_LRCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +0000344 Daq_BRG_Set_Count(LRCLK_BRG,
wdenkeb9401e2002-11-11 02:11:37 +0000345 mclk_divisor * MCLK_DIVISOR * SCLK_DIVISOR);
346# else
347 Daq_BRG_Set_Count(LRCLK_BRG, SCLK_DIVISOR);
348# endif
349
350 /*
351 * Restore the Interrupt state
352 */
353 if (flag) {
wdenk8bde7f72003-06-27 21:31:46 +0000354 enable_interrupts();
wdenkeb9401e2002-11-11 02:11:37 +0000355 }
wdenkc6097192002-11-03 00:24:07 +0000356
357 /* Enable the clock drivers */
358 iopa->pdat &= ~SLRCLK_EN_MASK;
359}
360
361void Daq_Stop_Clocks(void)
362
363{
364#ifdef TIGHTEN_UP_BRG_TIMING
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200365 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkeb9401e2002-11-11 02:11:37 +0000366 register uint mclk_brg; /* MCLK BRG value */
367 register uint sclk_brg; /* SCLK BRG value */
368 register uint lrclk_brg; /* LRCLK BRG value */
369 unsigned long flag; /* Interrupt flags */
wdenkc6097192002-11-03 00:24:07 +0000370#endif
371
372# ifdef TIGHTEN_UP_BRG_TIMING
wdenk8bde7f72003-06-27 21:31:46 +0000373 /*
374 * Obtain MCLK BRG reset/disabled value
375 */
wdenkc6097192002-11-03 00:24:07 +0000376# if (MCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000377 mclk_brg = (*IM_BRGC1 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000378# endif
379# if (MCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000380 mclk_brg = (*IM_BRGC2 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000381# endif
382# if (MCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000383 mclk_brg = (*IM_BRGC3 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000384# endif
385# if (MCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000386 mclk_brg = (*IM_BRGC4 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000387# endif
388# if (MCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000389 mclk_brg = (*IM_BRGC5 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000390# endif
391# if (MCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000392 mclk_brg = (*IM_BRGC6 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000393# endif
394# if (MCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000395 mclk_brg = (*IM_BRGC7 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000396# endif
397# if (MCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000398 mclk_brg = (*IM_BRGC8 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000399# endif
400
wdenk8bde7f72003-06-27 21:31:46 +0000401 /*
402 * Obtain SCLK BRG reset/disabled value
403 */
wdenkc6097192002-11-03 00:24:07 +0000404# if (SCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000405 sclk_brg = (*IM_BRGC1 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000406# endif
407# if (SCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000408 sclk_brg = (*IM_BRGC2 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000409# endif
410# if (SCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000411 sclk_brg = (*IM_BRGC3 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000412# endif
413# if (SCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000414 sclk_brg = (*IM_BRGC4 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000415# endif
416# if (SCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000417 sclk_brg = (*IM_BRGC5 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000418# endif
419# if (SCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000420 sclk_brg = (*IM_BRGC6 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000421# endif
422# if (SCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000423 sclk_brg = (*IM_BRGC7 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000424# endif
425# if (SCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000426 sclk_brg = (*IM_BRGC8 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000427# endif
428
wdenk8bde7f72003-06-27 21:31:46 +0000429 /*
430 * Obtain LRCLK BRG reset/disabled value
431 */
wdenkc6097192002-11-03 00:24:07 +0000432# if (LRCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000433 lrclk_brg = (*IM_BRGC1 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000434# endif
435# if (LRCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000436 lrclk_brg = (*IM_BRGC2 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000437# endif
438# if (LRCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000439 lrclk_brg = (*IM_BRGC3 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000440# endif
441# if (LRCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000442 lrclk_brg = (*IM_BRGC4 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000443# endif
444# if (LRCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000445 lrclk_brg = (*IM_BRGC5 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000446# endif
447# if (LRCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000448 lrclk_brg = (*IM_BRGC6 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000449# endif
450# if (LRCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000451 lrclk_brg = (*IM_BRGC7 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000452# endif
453# if (LRCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000454 lrclk_brg = (*IM_BRGC8 | CPM_BRG_RST) & ~CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000455# endif
wdenk8bde7f72003-06-27 21:31:46 +0000456
wdenkeb9401e2002-11-11 02:11:37 +0000457 /*
458 * Disable interrupt and save the current state
459 */
460 flag = disable_interrupts();
461
wdenk8bde7f72003-06-27 21:31:46 +0000462 /*
463 * Set reset on MCLK BRG
464 */
wdenkeb9401e2002-11-11 02:11:37 +0000465# if (MCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000466 *IM_BRGC1 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000467# endif
468# if (MCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000469 *IM_BRGC2 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000470# endif
471# if (MCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000472 *IM_BRGC3 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000473# endif
474# if (MCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000475 *IM_BRGC4 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000476# endif
477# if (MCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000478 *IM_BRGC5 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000479# endif
480# if (MCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000481 *IM_BRGC6 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000482# endif
483# if (MCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000484 *IM_BRGC7 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000485# endif
486# if (MCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000487 *IM_BRGC8 = mclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000488# endif
489
wdenk8bde7f72003-06-27 21:31:46 +0000490 /*
491 * Set reset on SCLK BRG
492 */
wdenkeb9401e2002-11-11 02:11:37 +0000493# if (SCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000494 *IM_BRGC1 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000495# endif
496# if (SCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000497 *IM_BRGC2 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000498# endif
499# if (SCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000500 *IM_BRGC3 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000501# endif
502# if (SCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000503 *IM_BRGC4 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000504# endif
505# if (SCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000506 *IM_BRGC5 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000507# endif
508# if (SCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000509 *IM_BRGC6 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000510# endif
511# if (SCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000512 *IM_BRGC7 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000513# endif
514# if (SCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000515 *IM_BRGC8 = sclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000516# endif
517
wdenk8bde7f72003-06-27 21:31:46 +0000518 /*
519 * Set reset on LRCLK BRG
520 */
wdenkeb9401e2002-11-11 02:11:37 +0000521# if (LRCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000522 *IM_BRGC1 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000523# endif
524# if (LRCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000525 *IM_BRGC2 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000526# endif
527# if (LRCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000528 *IM_BRGC3 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000529# endif
530# if (LRCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000531 *IM_BRGC4 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000532# endif
533# if (LRCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000534 *IM_BRGC5 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000535# endif
536# if (LRCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000537 *IM_BRGC6 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000538# endif
539# if (LRCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000540 *IM_BRGC7 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000541# endif
542# if (LRCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000543 *IM_BRGC8 = lrclk_brg;
wdenkeb9401e2002-11-11 02:11:37 +0000544# endif
wdenk8bde7f72003-06-27 21:31:46 +0000545
546 /*
547 * Clear reset on MCLK BRG
548 */
wdenkeb9401e2002-11-11 02:11:37 +0000549# if (MCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000550 *IM_BRGC1 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000551# endif
552# if (MCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000553 *IM_BRGC2 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000554# endif
555# if (MCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000556 *IM_BRGC3 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000557# endif
558# if (MCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000559 *IM_BRGC4 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000560# endif
561# if (MCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000562 *IM_BRGC5 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000563# endif
564# if (MCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000565 *IM_BRGC6 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000566# endif
567# if (MCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000568 *IM_BRGC7 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000569# endif
570# if (MCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000571 *IM_BRGC8 = mclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000572# endif
573
wdenk8bde7f72003-06-27 21:31:46 +0000574 /*
575 * Clear reset on SCLK BRG
576 */
wdenkeb9401e2002-11-11 02:11:37 +0000577# if (SCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000578 *IM_BRGC1 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000579# endif
580# if (SCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000581 *IM_BRGC2 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000582# endif
583# if (SCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000584 *IM_BRGC3 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000585# endif
586# if (SCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000587 *IM_BRGC4 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000588# endif
589# if (SCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000590 *IM_BRGC5 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000591# endif
592# if (SCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000593 *IM_BRGC6 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000594# endif
595# if (SCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000596 *IM_BRGC7 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000597# endif
598# if (SCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000599 *IM_BRGC8 = sclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000600# endif
601
wdenk8bde7f72003-06-27 21:31:46 +0000602 /*
603 * Clear reset on LRCLK BRG
604 */
wdenkeb9401e2002-11-11 02:11:37 +0000605# if (LRCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000606 *IM_BRGC1 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000607# endif
608# if (LRCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000609 *IM_BRGC2 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000610# endif
611# if (LRCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000612 *IM_BRGC3 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000613# endif
614# if (LRCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000615 *IM_BRGC4 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000616# endif
617# if (LRCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000618 *IM_BRGC5 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000619# endif
620# if (LRCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000621 *IM_BRGC6 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000622# endif
623# if (LRCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000624 *IM_BRGC7 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000625# endif
626# if (LRCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000627 *IM_BRGC8 = lrclk_brg & ~CPM_BRG_RST;
wdenkeb9401e2002-11-11 02:11:37 +0000628# endif
wdenk8bde7f72003-06-27 21:31:46 +0000629
wdenkeb9401e2002-11-11 02:11:37 +0000630 /*
631 * Restore the Interrupt state
632 */
633 if (flag) {
wdenk8bde7f72003-06-27 21:31:46 +0000634 enable_interrupts();
wdenkeb9401e2002-11-11 02:11:37 +0000635 }
wdenkc6097192002-11-03 00:24:07 +0000636# else
wdenk8bde7f72003-06-27 21:31:46 +0000637 /*
638 * Reset the clocks
639 */
640 Daq_BRG_Reset(MCLK_BRG);
641 Daq_BRG_Reset(SCLK_BRG);
642 Daq_BRG_Reset(LRCLK_BRG);
wdenkc6097192002-11-03 00:24:07 +0000643# endif
644}
645
646void Daq_Start_Clocks(int sample_rate)
647
648{
649#ifdef TIGHTEN_UP_BRG_TIMING
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200650 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +0000651
wdenkeb9401e2002-11-11 02:11:37 +0000652 register uint mclk_brg; /* MCLK BRG value */
653 register uint sclk_brg; /* SCLK BRG value */
654 register uint temp_lrclk_brg; /* Temporary LRCLK BRG value */
655 register uint real_lrclk_brg; /* Permanent LRCLK BRG value */
wdenkc6097192002-11-03 00:24:07 +0000656 uint lrclk_brg; /* LRCLK BRG value */
wdenkc6097192002-11-03 00:24:07 +0000657 unsigned long flags; /* Interrupt flags */
658 uint sclk_cnt; /* SCLK count */
659 uint delay_cnt; /* Delay count */
660#endif
661
662# ifdef TIGHTEN_UP_BRG_TIMING
wdenk8bde7f72003-06-27 21:31:46 +0000663 /*
664 * Obtain the enabled MCLK BRG value
665 */
wdenkc6097192002-11-03 00:24:07 +0000666# if (MCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000667 mclk_brg = (*IM_BRGC1 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000668# endif
669# if (MCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000670 mclk_brg = (*IM_BRGC2 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000671# endif
672# if (MCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000673 mclk_brg = (*IM_BRGC3 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000674# endif
675# if (MCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000676 mclk_brg = (*IM_BRGC4 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000677# endif
678# if (MCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000679 mclk_brg = (*IM_BRGC5 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000680# endif
681# if (MCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000682 mclk_brg = (*IM_BRGC6 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000683# endif
684# if (MCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000685 mclk_brg = (*IM_BRGC7 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000686# endif
687# if (MCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000688 mclk_brg = (*IM_BRGC8 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000689# endif
690
wdenk8bde7f72003-06-27 21:31:46 +0000691 /*
692 * Obtain the enabled SCLK BRG value
693 */
wdenkc6097192002-11-03 00:24:07 +0000694# if (SCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000695 sclk_brg = (*IM_BRGC1 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000696# endif
697# if (SCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000698 sclk_brg = (*IM_BRGC2 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000699# endif
700# if (SCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000701 sclk_brg = (*IM_BRGC3 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000702# endif
703# if (SCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000704 sclk_brg = (*IM_BRGC4 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000705# endif
706# if (SCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000707 sclk_brg = (*IM_BRGC5 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000708# endif
709# if (SCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000710 sclk_brg = (*IM_BRGC6 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000711# endif
712# if (SCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000713 sclk_brg = (*IM_BRGC7 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000714# endif
715# if (SCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000716 sclk_brg = (*IM_BRGC8 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000717# endif
718
wdenk8bde7f72003-06-27 21:31:46 +0000719 /*
720 * Obtain the enabled LRCLK BRG value
721 */
wdenkc6097192002-11-03 00:24:07 +0000722# if (LRCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000723 lrclk_brg = (*IM_BRGC1 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000724# endif
725# if (LRCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000726 lrclk_brg = (*IM_BRGC2 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000727# endif
728# if (LRCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000729 lrclk_brg = (*IM_BRGC3 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000730# endif
731# if (LRCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000732 lrclk_brg = (*IM_BRGC4 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000733# endif
734# if (LRCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000735 lrclk_brg = (*IM_BRGC5 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000736# endif
737# if (LRCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000738 lrclk_brg = (*IM_BRGC6 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000739# endif
740# if (LRCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000741 lrclk_brg = (*IM_BRGC7 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000742# endif
743# if (LRCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000744 lrclk_brg = (*IM_BRGC8 & ~CPM_BRG_RST) | CPM_BRG_EN;
wdenkc6097192002-11-03 00:24:07 +0000745# endif
746
747 /* Save off the real LRCLK value */
748 real_lrclk_brg = lrclk_brg;
749
750 /* Obtain the current SCLK count */
751 sclk_cnt = ((sclk_brg & 0x00001FFE) >> 1) + 1;
752
753 /* Compute the delay as a function of SCLK count */
wdenk8bde7f72003-06-27 21:31:46 +0000754 delay_cnt = ((sclk_cnt / 4) - 2) * 10 + 6;
wdenkeb9401e2002-11-11 02:11:37 +0000755 if (DaqSampleRate == 43402) {
wdenkc6097192002-11-03 00:24:07 +0000756 delay_cnt++;
757 }
758
wdenk8bde7f72003-06-27 21:31:46 +0000759 /* Clear out the count */
wdenkc6097192002-11-03 00:24:07 +0000760 temp_lrclk_brg = sclk_brg & ~0x00001FFE;
761
wdenk8bde7f72003-06-27 21:31:46 +0000762 /* Insert the count */
wdenkc6097192002-11-03 00:24:07 +0000763 temp_lrclk_brg |= ((delay_cnt + (sclk_cnt / 2) - 1) << 1) & 0x00001FFE;
764
wdenkeb9401e2002-11-11 02:11:37 +0000765 /*
766 * Disable interrupt and save the current state
767 */
768 flag = disable_interrupts();
769
wdenk8bde7f72003-06-27 21:31:46 +0000770 /*
771 * Enable MCLK BRG
772 */
wdenkc6097192002-11-03 00:24:07 +0000773# if (MCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000774 *IM_BRGC1 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000775# endif
776# if (MCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000777 *IM_BRGC2 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000778# endif
779# if (MCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000780 *IM_BRGC3 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000781# endif
782# if (MCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000783 *IM_BRGC4 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000784# endif
785# if (MCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000786 *IM_BRGC5 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000787# endif
788# if (MCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000789 *IM_BRGC6 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000790# endif
791# if (MCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000792 *IM_BRGC7 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000793# endif
794# if (MCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000795 *IM_BRGC8 = mclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000796# endif
797
wdenk8bde7f72003-06-27 21:31:46 +0000798 /*
799 * Enable SCLK BRG
800 */
wdenkc6097192002-11-03 00:24:07 +0000801# if (SCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000802 *IM_BRGC1 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000803# endif
804# if (SCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000805 *IM_BRGC2 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000806# endif
807# if (SCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000808 *IM_BRGC3 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000809# endif
810# if (SCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000811 *IM_BRGC4 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000812# endif
813# if (SCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000814 *IM_BRGC5 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000815# endif
816# if (SCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000817 *IM_BRGC6 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000818# endif
819# if (SCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000820 *IM_BRGC7 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000821# endif
822# if (SCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000823 *IM_BRGC8 = sclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000824# endif
825
wdenk8bde7f72003-06-27 21:31:46 +0000826 /*
827 * Enable LRCLK BRG (1st time - temporary)
828 */
wdenkc6097192002-11-03 00:24:07 +0000829# if (LRCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000830 *IM_BRGC1 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000831# endif
832# if (LRCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000833 *IM_BRGC2 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000834# endif
835# if (LRCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000836 *IM_BRGC3 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000837# endif
838# if (LRCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000839 *IM_BRGC4 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000840# endif
841# if (LRCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000842 *IM_BRGC5 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000843# endif
844# if (LRCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000845 *IM_BRGC6 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000846# endif
847# if (LRCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000848 *IM_BRGC7 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000849# endif
850# if (LRCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000851 *IM_BRGC8 = temp_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000852# endif
wdenk8bde7f72003-06-27 21:31:46 +0000853
854 /*
855 * Enable LRCLK BRG (2nd time - permanent)
856 */
wdenkc6097192002-11-03 00:24:07 +0000857# if (LRCLK_BRG == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000858 *IM_BRGC1 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000859# endif
860# if (LRCLK_BRG == 1)
wdenk8bde7f72003-06-27 21:31:46 +0000861 *IM_BRGC2 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000862# endif
863# if (LRCLK_BRG == 2)
wdenk8bde7f72003-06-27 21:31:46 +0000864 *IM_BRGC3 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000865# endif
866# if (LRCLK_BRG == 3)
wdenk8bde7f72003-06-27 21:31:46 +0000867 *IM_BRGC4 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000868# endif
869# if (LRCLK_BRG == 4)
wdenk8bde7f72003-06-27 21:31:46 +0000870 *IM_BRGC5 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000871# endif
872# if (LRCLK_BRG == 5)
wdenk8bde7f72003-06-27 21:31:46 +0000873 *IM_BRGC6 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000874# endif
875# if (LRCLK_BRG == 6)
wdenk8bde7f72003-06-27 21:31:46 +0000876 *IM_BRGC7 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000877# endif
878# if (LRCLK_BRG == 7)
wdenk8bde7f72003-06-27 21:31:46 +0000879 *IM_BRGC8 = real_lrclk_brg;
wdenkc6097192002-11-03 00:24:07 +0000880# endif
wdenkeb9401e2002-11-11 02:11:37 +0000881
882 /*
883 * Restore the Interrupt state
884 */
885 if (flag) {
886 enable_interrupts();
wdenk8bde7f72003-06-27 21:31:46 +0000887 }
wdenkc6097192002-11-03 00:24:07 +0000888# else
wdenk8bde7f72003-06-27 21:31:46 +0000889 /*
890 * Enable the clocks
891 */
892 Daq_BRG_Enable(LRCLK_BRG);
893 Daq_BRG_Enable(SCLK_BRG);
894 Daq_BRG_Enable(MCLK_BRG);
wdenkc6097192002-11-03 00:24:07 +0000895# endif
896}
897
898void Daq_Display_Clocks(void)
899
900{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200901 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkc6097192002-11-03 00:24:07 +0000902 uint mclk_divisor; /* Detected MCLK divisor */
903 uint sclk_divisor; /* Detected SCLK divisor */
904
905 printf("\nBRG:\n");
906 if (immr->im_brgc4 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000907 printf("\tbrgc4\t0x%08x @ 0x%08x, %5d count, %d extc, %8s, MCLK\n",
wdenkc6097192002-11-03 00:24:07 +0000908 immr->im_brgc4,
909 (uint)&(immr->im_brgc4),
910 Daq_BRG_Get_Count(3),
911 Daq_BRG_Get_ExtClk(3),
912 Daq_BRG_Get_ExtClk_Description(3));
913 }
914 if (immr->im_brgc8 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000915 printf("\tbrgc8\t0x%08x @ 0x%08x, %5d count, %d extc, %8s, SCLK\n",
wdenkc6097192002-11-03 00:24:07 +0000916 immr->im_brgc8,
917 (uint)&(immr->im_brgc8),
918 Daq_BRG_Get_Count(7),
919 Daq_BRG_Get_ExtClk(7),
920 Daq_BRG_Get_ExtClk_Description(7));
921 }
922 if (immr->im_brgc6 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000923 printf("\tbrgc6\t0x%08x @ 0x%08x, %5d count, %d extc, %8s, LRCLK\n",
wdenkc6097192002-11-03 00:24:07 +0000924 immr->im_brgc6,
925 (uint)&(immr->im_brgc6),
926 Daq_BRG_Get_Count(5),
927 Daq_BRG_Get_ExtClk(5),
928 Daq_BRG_Get_ExtClk_Description(5));
929 }
930 if (immr->im_brgc1 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000931 printf("\tbrgc1\t0x%08x @ 0x%08x, %5d count, %d extc, %8s, SMC1\n",
wdenkc6097192002-11-03 00:24:07 +0000932 immr->im_brgc1,
933 (uint)&(immr->im_brgc1),
934 Daq_BRG_Get_Count(0),
935 Daq_BRG_Get_ExtClk(0),
936 Daq_BRG_Get_ExtClk_Description(0));
937 }
938 if (immr->im_brgc2 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000939 printf("\tbrgc2\t0x%08x @ 0x%08x, %5d count, %d extc, %8s, SMC2\n",
wdenkc6097192002-11-03 00:24:07 +0000940 immr->im_brgc2,
941 (uint)&(immr->im_brgc2),
942 Daq_BRG_Get_Count(1),
943 Daq_BRG_Get_ExtClk(1),
944 Daq_BRG_Get_ExtClk_Description(1));
945 }
946 if (immr->im_brgc3 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000947 printf("\tbrgc3\t0x%08x @ 0x%08x, %5d count, %d extc, %8s, SCC1\n",
wdenkc6097192002-11-03 00:24:07 +0000948 immr->im_brgc3,
949 (uint)&(immr->im_brgc3),
950 Daq_BRG_Get_Count(2),
951 Daq_BRG_Get_ExtClk(2),
952 Daq_BRG_Get_ExtClk_Description(2));
953 }
954 if (immr->im_brgc5 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000955 printf("\tbrgc5\t0x%08x @ 0x%08x, %5d count, %d extc, %8s\n",
wdenkc6097192002-11-03 00:24:07 +0000956 immr->im_brgc5,
957 (uint)&(immr->im_brgc5),
958 Daq_BRG_Get_Count(4),
959 Daq_BRG_Get_ExtClk(4),
960 Daq_BRG_Get_ExtClk_Description(4));
961 }
962 if (immr->im_brgc7 != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000963 printf("\tbrgc7\t0x%08x @ 0x%08x, %5d count, %d extc, %8s\n",
wdenkc6097192002-11-03 00:24:07 +0000964 immr->im_brgc7,
965 (uint)&(immr->im_brgc7),
966 Daq_BRG_Get_Count(6),
967 Daq_BRG_Get_ExtClk(6),
968 Daq_BRG_Get_ExtClk_Description(6));
969 }
970
971# ifdef RUN_SCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +0000972 mclk_divisor = Daq_BRG_Rate(MCLK_BRG) / Daq_BRG_Rate(SCLK_BRG);
wdenkc6097192002-11-03 00:24:07 +0000973# else
wdenk8bde7f72003-06-27 21:31:46 +0000974 mclk_divisor = Daq_BRG_Get_Count(SCLK_BRG);
wdenkc6097192002-11-03 00:24:07 +0000975# endif
976# ifdef RUN_LRCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +0000977 sclk_divisor = Daq_BRG_Rate(SCLK_BRG) / Daq_BRG_Rate(LRCLK_BRG);
wdenkc6097192002-11-03 00:24:07 +0000978# else
wdenk8bde7f72003-06-27 21:31:46 +0000979 sclk_divisor = Daq_BRG_Get_Count(LRCLK_BRG);
wdenkc6097192002-11-03 00:24:07 +0000980# endif
981
982 printf("\nADC/DAC Clocking (%d/%d):\n", sclk_divisor, mclk_divisor);
983 printf("\tMCLK %8d Hz, or %3dx SCLK, or %3dx LRCLK\n",
984 Daq_BRG_Rate(MCLK_BRG),
985 mclk_divisor,
986 mclk_divisor * sclk_divisor);
987# ifdef RUN_SCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +0000988 printf("\tSCLK %8d Hz, or %3dx LRCLK\n",
wdenkc6097192002-11-03 00:24:07 +0000989 Daq_BRG_Rate(SCLK_BRG),
990 sclk_divisor);
991# else
wdenk8bde7f72003-06-27 21:31:46 +0000992 printf("\tSCLK %8d Hz, or %3dx LRCLK\n",
wdenkc6097192002-11-03 00:24:07 +0000993 Daq_BRG_Rate(MCLK_BRG) / mclk_divisor,
994 sclk_divisor);
995# endif
996# ifdef RUN_LRCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +0000997 printf("\tLRCLK %8d Hz\n",
wdenkc6097192002-11-03 00:24:07 +0000998 Daq_BRG_Rate(LRCLK_BRG));
999# else
1000# ifdef RUN_SCLK_ON_BRG_INT
wdenk8bde7f72003-06-27 21:31:46 +00001001 printf("\tLRCLK %8d Hz\n",
wdenkc6097192002-11-03 00:24:07 +00001002 Daq_BRG_Rate(SCLK_BRG) / sclk_divisor);
1003# else
wdenk8bde7f72003-06-27 21:31:46 +00001004 printf("\tLRCLK %8d Hz\n",
wdenkc6097192002-11-03 00:24:07 +00001005 Daq_BRG_Rate(MCLK_BRG) / (mclk_divisor * sclk_divisor));
1006# endif
1007# endif
1008 printf("\n");
1009}