blob: 0f0f0e6cc0372a6da3a4c547a7073a2172017a77 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * (C) Copyright 2002
3 * Custom IDEAS, Inc. <www.cideas.com>
4 * Gerald Van Baren <vanbaren@cideas.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <asm/u-boot.h>
26#include <common.h>
27#include <ioports.h>
28#include <mpc8260.h>
29/*NO// #include <memtest.h> */
30#include <i2c.h>
31#include <spi.h>
32
33#ifdef CONFIG_SHOW_BOOT_PROGRESS
34#include <status_led.h>
35#endif
36
37#include "clkinit.h"
38#include "ioconfig.h" /* I/O configuration table */
39
40/*
41 * PBI Page Based Interleaving
42 * PSDMR_PBI page based interleaving
43 * 0 bank based interleaving
44 * External Address Multiplexing (EAMUX) adds a clock to address cycles
45 * (this can help with marginal board layouts)
46 * PSDMR_EAMUX adds a clock
47 * 0 no extra clock
48 * Buffer Command (BUFCMD) adds a clock to command cycles.
49 * PSDMR_BUFCMD adds a clock
50 * 0 no extra clock
51 */
52#define CONFIG_PBI PSDMR_PBI
53#define PESSIMISTIC_SDRAM 0
54#define EAMUX 0 /* EST requires EAMUX */
55#define BUFCMD 0
56
57/*
58 * ADC/DAC Defines:
59 */
60#define INITIAL_SAMPLE_RATE 10016 /* Initial Daq sample rate */
61#define INITIAL_RIGHT_JUST 0 /* Initial DAC right justification */
62#define INITIAL_MCLK_DIVIDE 0 /* Initial MCLK Divide */
63#define INITIAL_SAMPLE_64X 1 /* Initial 64x clocking mode */
64#define INITIAL_SAMPLE_128X 0 /* Initial 128x clocking mode */
65
66/*
67 * ADC Defines:
68 */
69#define I2C_ADC_1_ADDR 0x0E /* I2C Address of the ADC #1 */
70#define I2C_ADC_2_ADDR 0x0F /* I2C Address of the ADC #2 */
71
72#define ADC_SDATA1_MASK 0x00020000 /* PA14 - CH12SDATA_PU */
73#define ADC_SDATA2_MASK 0x00010000 /* PA15 - CH34SDATA_PU */
74
75#define ADC_VREF_CAP 100 /* VREF capacitor in uF */
76#define ADC_INITIAL_DELAY (10 * ADC_VREF_CAP) /* 10 usec per uF, in usec */
77#define ADC_SDATA_DELAY 100 /* ADC SDATA release delay in usec */
78#define ADC_CAL_DELAY (1000000 / INITIAL_SAMPLE_RATE * 4500)
79 /* Wait at least 4100 LRCLK's */
80
81#define ADC_REG1_FRAME_START 0x80 /* Frame start */
82#define ADC_REG1_GROUND_CAL 0x40 /* Ground calibration enable */
83#define ADC_REG1_ANA_MOD_PDOWN 0x20 /* Analog modulator section in power down */
84#define ADC_REG1_DIG_MOD_PDOWN 0x10 /* Digital modulator section in power down */
85
86#define ADC_REG2_128x 0x80 /* Oversample at 128x */
87#define ADC_REG2_CAL 0x40 /* System calibration enable */
88#define ADC_REG2_CHANGE_SIGN 0x20 /* Change sign enable */
89#define ADC_REG2_LR_DISABLE 0x10 /* Left/Right output disable */
90#define ADC_REG2_HIGH_PASS_DIS 0x08 /* High pass filter disable */
91#define ADC_REG2_SLAVE_MODE 0x04 /* Slave mode */
92#define ADC_REG2_DFS 0x02 /* Digital format select */
93#define ADC_REG2_MUTE 0x01 /* Mute */
94
95#define ADC_REG7_ADDR_ENABLE 0x80 /* Address enable */
96#define ADC_REG7_PEAK_ENABLE 0x40 /* Peak enable */
97#define ADC_REG7_PEAK_UPDATE 0x20 /* Peak update */
98#define ADC_REG7_PEAK_FORMAT 0x10 /* Peak display format */
99#define ADC_REG7_DIG_FILT_PDOWN 0x04 /* Digital filter power down enable */
100#define ADC_REG7_FIR2_IN_EN 0x02 /* External FIR2 input enable */
101#define ADC_REG7_PSYCHO_EN 0x01 /* External pyscho filter input enable */
102
103/*
104 * DAC Defines:
105 */
106
107#define I2C_DAC_ADDR 0x11 /* I2C Address of the DAC */
108
109#define DAC_RST_MASK 0x00008000 /* PA16 - DAC_RST* */
110#define DAC_RESET_DELAY 100 /* DAC reset delay in usec */
111#define DAC_INITIAL_DELAY 5000 /* DAC initialization delay in usec */
112
113#define DAC_REG1_AMUTE 0x80 /* Auto-mute */
114
115#define DAC_REG1_LEFT_JUST_24_BIT (0 << 4) /* Fmt 0: Left justified 24 bit */
116#define DAC_REG1_I2S_24_BIT (1 << 4) /* Fmt 1: I2S up to 24 bit */
117#define DAC_REG1_RIGHT_JUST_16BIT (2 << 4) /* Fmt 2: Right justified 16 bit */
118#define DAC_REG1_RIGHT_JUST_24BIT (3 << 4) /* Fmt 3: Right justified 24 bit */
119#define DAC_REG1_RIGHT_JUST_20BIT (4 << 4) /* Fmt 4: Right justified 20 bit */
120#define DAC_REG1_RIGHT_JUST_18BIT (5 << 4) /* Fmt 5: Right justified 18 bit */
121
122#define DAC_REG1_DEM_NO (0 << 2) /* No De-emphasis */
123#define DAC_REG1_DEM_44KHZ (1 << 2) /* 44.1KHz De-emphasis */
124#define DAC_REG1_DEM_48KHZ (2 << 2) /* 48KHz De-emphasis */
125#define DAC_REG1_DEM_32KHZ (3 << 2) /* 32KHz De-emphasis */
126
127#define DAC_REG1_SINGLE 0 /* 4- 50KHz sample rate */
128#define DAC_REG1_DOUBLE 1 /* 50-100KHz sample rate */
129#define DAC_REG1_QUAD 2 /* 100-200KHz sample rate */
130#define DAC_REG1_DSD 3 /* Direct Stream Data, DSD */
131
132#define DAC_REG5_INVERT_A 0x80 /* Invert channel A */
133#define DAC_REG5_INVERT_B 0x40 /* Invert channel B */
134#define DAC_REG5_I2C_MODE 0x20 /* Control port (I2C) mode */
135#define DAC_REG5_POWER_DOWN 0x10 /* Power down mode */
136#define DAC_REG5_MUTEC_A_B 0x08 /* Mutec A=B */
137#define DAC_REG5_FREEZE 0x04 /* Freeze */
138#define DAC_REG5_MCLK_DIV 0x02 /* MCLK divide by 2 */
139#define DAC_REG5_RESERVED 0x01 /* Reserved */
140
141/* ------------------------------------------------------------------------- */
142
143/*
144 * Check Board Identity:
145 */
146
147int checkboard(void)
148{
149 printf ("SACSng\n");
150
151 return 0;
152}
153
154/* ------------------------------------------------------------------------- */
155
156long int initdram(int board_type)
157{
158 volatile immap_t *immap = (immap_t *)CFG_IMMR;
159 volatile memctl8260_t *memctl = &immap->im_memctl;
160 volatile uchar c = 0;
161 volatile uchar *ramaddr = (uchar *)(CFG_SDRAM_BASE + 0x8);
162 uint psdmr = CFG_PSDMR;
163 int i;
164 uint psrt = 14; /* for no SPD */
165 uint chipselects = 1; /* for no SPD */
166 uint sdram_size = CFG_SDRAM0_SIZE * 1024 * 1024; /* for no SPD */
167 uint or = CFG_OR2_PRELIM; /* for no SPD */
168#ifdef SDRAM_SPD_ADDR
169 uint data_width;
170 uint rows;
171 uint banks;
172 uint cols;
173 uint caslatency;
174 uint width;
175 uint rowst;
176 uint sdam;
177 uint bsma;
178 uint sda10;
179 u_char spd_size;
180 u_char data;
181 u_char cksum;
182 int j;
183#endif
184
185#ifdef SDRAM_SPD_ADDR
186 /* Keep the compiler from complaining about potentially uninitialized vars */
187 data_width = chipselects = rows = banks = cols = caslatency = psrt = 0;
188
189 /*
190 * Read the SDRAM SPD EEPROM via I2C.
191 */
192 i2c_read(SDRAM_SPD_ADDR, 0, 1, &data, 1);
193 spd_size = data;
194 cksum = data;
195 for(j = 1; j < 64; j++) { /* read only the checksummed bytes */
196 /* note: the I2C address autoincrements when alen == 0 */
197 i2c_read(SDRAM_SPD_ADDR, 0, 0, &data, 1);
198 if(j == 5) chipselects = data & 0x0F;
199 else if(j == 6) data_width = data;
200 else if(j == 7) data_width |= data << 8;
201 else if(j == 3) rows = data & 0x0F;
202 else if(j == 4) cols = data & 0x0F;
203 else if(j == 12) {
204 /*
205 * Refresh rate: this assumes the prescaler is set to
206 * approximately 1uSec per tick.
207 */
208 switch(data & 0x7F) {
209 default:
210 case 0: psrt = 14 ; /* 15.625uS */ break;
211 case 1: psrt = 2; /* 3.9uS */ break;
212 case 2: psrt = 6; /* 7.8uS */ break;
213 case 3: psrt = 29; /* 31.3uS */ break;
214 case 4: psrt = 60; /* 62.5uS */ break;
215 case 5: psrt = 120; /* 125uS */ break;
216 }
217 }
218 else if(j == 17) banks = data;
219 else if(j == 18) {
220 caslatency = 3; /* default CL */
221#if(PESSIMISTIC_SDRAM)
222 if((data & 0x04) != 0) caslatency = 3;
223 else if((data & 0x02) != 0) caslatency = 2;
224 else if((data & 0x01) != 0) caslatency = 1;
225#else
226 if((data & 0x01) != 0) caslatency = 1;
227 else if((data & 0x02) != 0) caslatency = 2;
228 else if((data & 0x04) != 0) caslatency = 3;
229#endif
230 else {
231 printf ("WARNING: Unknown CAS latency 0x%02X, using 3\n",
232 data);
233 }
234 }
235 else if(j == 63) {
236 if(data != cksum) {
237 printf ("WARNING: Configuration data checksum failure:"
238 " is 0x%02x, calculated 0x%02x\n",
239 data, cksum);
240 }
241 }
242 cksum += data;
243 }
244
245 /* We don't trust CL less than 2 (only saw it on an old 16MByte DIMM) */
246 if(caslatency < 2) {
247 printf("CL was %d, forcing to 2\n", caslatency);
248 caslatency = 2;
249 }
250 if(rows > 14) {
251 printf("This doesn't look good, rows = %d, should be <= 14\n", rows);
252 rows = 14;
253 }
254 if(cols > 11) {
255 printf("This doesn't look good, columns = %d, should be <= 11\n", cols);
256 cols = 11;
257 }
258
259 if((data_width != 64) && (data_width != 72))
260 {
261 printf("WARNING: SDRAM width unsupported, is %d, expected 64 or 72.\n",
262 data_width);
263 }
264 width = 3; /* 2^3 = 8 bytes = 64 bits wide */
265 /*
266 * Convert banks into log2(banks)
267 */
268 if (banks == 2) banks = 1;
269 else if(banks == 4) banks = 2;
270 else if(banks == 8) banks = 3;
271
272 sdram_size = 1 << (rows + cols + banks + width);
273
274#if(CONFIG_PBI == 0) /* bank-based interleaving */
275 rowst = ((32 - 6) - (rows + cols + width)) * 2;
276#else
277 rowst = 32 - (rows + banks + cols + width);
278#endif
279
280 or = ~(sdram_size - 1) | /* SDAM address mask */
281 ((banks-1) << 13) | /* banks per device */
282 (rowst << 9) | /* rowst */
283 ((rows - 9) << 6); /* numr */
284
285 memctl->memc_or2 = or;
286
287 /*
288 * SDAM specifies the number of columns that are multiplexed
289 * (reference AN2165/D), defined to be (columns - 6) for page
290 * interleave, (columns - 8) for bank interleave.
291 *
292 * BSMA is 14 - max(rows, cols). The bank select lines come
293 * into play above the highest "address" line going into the
294 * the SDRAM.
295 */
296#if(CONFIG_PBI == 0) /* bank-based interleaving */
297 sdam = cols - 8;
298 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
299 sda10 = sdam + 2;
300#else
301 sdam = cols - 6;
302 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
303 sda10 = sdam;
304#endif
305#if(PESSIMISTIC_SDRAM)
306 psdmr = (CONFIG_PBI |\
307 PSDMR_RFEN |\
308 PSDMR_RFRC_16_CLK |\
309 PSDMR_PRETOACT_8W |\
310 PSDMR_ACTTORW_8W |\
311 PSDMR_WRC_4C |\
312 PSDMR_EAMUX |\
313 PSDMR_BUFCMD) |\
314 caslatency |\
315 ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */ \
316 (sdam << 24) |\
317 (bsma << 21) |\
318 (sda10 << 18);
319#else
320 psdmr = (CONFIG_PBI |\
321 PSDMR_RFEN |\
322 PSDMR_RFRC_7_CLK |\
323 PSDMR_PRETOACT_3W | /* 1 for 7E parts (fast PC-133) */ \
324 PSDMR_ACTTORW_2W | /* 1 for 7E parts (fast PC-133) */ \
325 PSDMR_WRC_1C | /* 1 clock + 7nSec */
326 EAMUX |\
327 BUFCMD) |\
328 caslatency |\
329 ((caslatency - 1) << 6) | /* LDOTOPRE is CL - 1 */ \
330 (sdam << 24) |\
331 (bsma << 21) |\
332 (sda10 << 18);
333#endif
334#endif
335
336 /*
337 * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
338 *
339 * "At system reset, initialization software must set up the
340 * programmable parameters in the memory controller banks registers
341 * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
342 * system software should execute the following initialization sequence
343 * for each SDRAM device.
344 *
345 * 1. Issue a PRECHARGE-ALL-BANKS command
346 * 2. Issue eight CBR REFRESH commands
347 * 3. Issue a MODE-SET command to initialize the mode register
348 *
349 * Quote from Micron MT48LC8M16A2 data sheet:
350 *
351 * "...the SDRAM requires a 100uS delay prior to issuing any
352 * command other than a COMMAND INHIBIT or NOP. Starting at some
353 * point during this 100uS period and continuing at least through
354 * the end of this period, COMMAND INHIBIT or NOP commands should
355 * be applied."
356 *
357 * "Once the 100uS delay has been satisfied with at least one COMMAND
358 * INHIBIT or NOP command having been applied, a /PRECHARGE command/
359 * should be applied. All banks must then be precharged, thereby
360 * placing the device in the all banks idle state."
361 *
362 * "Once in the idle state, /two/ AUTO REFRESH cycles must be
363 * performed. After the AUTO REFRESH cycles are complete, the
364 * SDRAM is ready for mode register programming."
365 *
366 * (/emphasis/ mine, gvb)
367 *
368 * The way I interpret this, Micron start up sequence is:
369 * 1. Issue a PRECHARGE-BANK command (initial precharge)
370 * 2. Issue a PRECHARGE-ALL-BANKS command ("all banks ... precharged")
371 * 3. Issue two (presumably, doing eight is OK) CBR REFRESH commands
372 * 4. Issue a MODE-SET command to initialize the mode register
373 *
374 * --------
375 *
376 * The initial commands are executed by setting P/LSDMR[OP] and
377 * accessing the SDRAM with a single-byte transaction."
378 *
379 * The appropriate BRx/ORx registers have already been set when we
380 * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
381 */
382
383 memctl->memc_mptpr = CFG_MPTPR;
384 memctl->memc_psrt = psrt;
385
386 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
387 *ramaddr = c;
388
389 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
390 for (i = 0; i < 8; i++)
391 *ramaddr = c;
392
393 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
394 *ramaddr = c;
395
396 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
397 *ramaddr = c;
398
399 /*
400 * Do it a second time for the second set of chips if the DIMM has
401 * two chip selects (double sided).
402 */
403 if(chipselects > 1) {
404 ramaddr += sdram_size;
405
406 memctl->memc_br3 = CFG_BR3_PRELIM + sdram_size;
407 memctl->memc_or3 = or;
408
409 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
410 *ramaddr = c;
411
412 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
413 for (i = 0; i < 8; i++)
414 *ramaddr = c;
415
416 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
417 *ramaddr = c;
418
419 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
420 *ramaddr = c;
421 }
422
423 /* return total ram size */
424 return (sdram_size * chipselects);
425}
426
427/*-----------------------------------------------------------------------
428 * Board Control Functions
429 */
430void board_poweroff (void)
431{
432 while (1); /* hang forever */
433}
434
435
436#ifdef CONFIG_MISC_INIT_R
437/* ------------------------------------------------------------------------- */
438int misc_init_r(void)
439{
440 /*
441 * Note: iop is used by the I2C macros, and iopa by the ADC/DAC initialization.
442 */
443 volatile ioport_t *iopa = ioport_addr((immap_t *)CFG_IMMR, 0 /* port A */);
444 volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT);
445
446 int reg; /* I2C register value */
447 char *ep; /* Environment pointer */
448 char str_buf[12] ; /* sprintf output buffer */
449 int sample_rate; /* ADC/DAC sample rate */
450 int sample_64x; /* Use 64/4 clocking for the ADC/DAC */
451 int sample_128x; /* Use 128/4 clocking for the ADC/DAC */
452 int right_just; /* Is the data to the DAC right justified? */
453 int mclk_divide; /* MCLK Divide */
454
455 /*
456 * SACSng custom initialization:
457 * Start the ADC and DAC clocks, since the Crystal parts do not
458 * work on the I2C bus until the clocks are running.
459 */
460
461 sample_rate = INITIAL_SAMPLE_RATE;
462 if ((ep = getenv("DaqSampleRate")) != NULL) {
463 sample_rate = simple_strtol(ep, NULL, 10);
464 }
465
466 sample_64x = INITIAL_SAMPLE_64X;
467 sample_128x = INITIAL_SAMPLE_128X;
468 if ((ep = getenv("Daq64xSampling")) != NULL) {
469 sample_64x = simple_strtol(ep, NULL, 10);
470 if (sample_64x) {
471 sample_128x = 0;
472 }
473 else {
474 sample_128x = 1;
475 }
476 }
477 else {
478 if ((ep = getenv("Daq128xSampling")) != NULL) {
479 sample_128x = simple_strtol(ep, NULL, 10);
480 if (sample_128x) {
481 sample_64x = 0;
482 }
483 else {
484 sample_64x = 1;
485 }
486 }
487 }
488
489 Daq_Init_Clocks(sample_rate, sample_64x);
490 sample_rate = Daq_Get_SampleRate();
491 Daq_Start_Clocks(sample_rate);
492
493 sprintf(str_buf, "%d", sample_rate);
494 setenv("DaqSampleRate", str_buf);
495
496 if (sample_64x) {
497 setenv("Daq64xSampling", "1");
498 setenv("Daq128xSampling", NULL);
499 }
500 else {
501 setenv("Daq64xSampling", NULL);
502 setenv("Daq128xSampling", "1");
503 }
504
505 /* Display the ADC/DAC clocking information */
506 Daq_Display_Clocks();
507
508 /*
509 * Determine the DAC data justification
510 */
511
512 right_just = INITIAL_RIGHT_JUST;
513 if ((ep = getenv("DaqDACRightJustified")) != NULL) {
514 right_just = simple_strtol(ep, NULL, 10);
515 }
516
517 sprintf(str_buf, "%d", right_just);
518 setenv("DaqDACRightJustified", str_buf);
519
520 /*
521 * Determine the DAC MCLK Divide
522 */
523
524 mclk_divide = INITIAL_MCLK_DIVIDE;
525 if ((ep = getenv("DaqDACMClockDivide")) != NULL) {
526 mclk_divide = simple_strtol(ep, NULL, 10);
527 }
528
529 sprintf(str_buf, "%d", mclk_divide);
530 setenv("DaqDACMClockDivide", str_buf);
531
532 /*
533 * Initializing the I2C address in the Crystal A/Ds:
534 *
535 * 1) Wait for VREF cap to settle (10uSec per uF)
536 * 2) Release pullup on SDATA
537 * 3) Write the I2C address to register 6
538 * 4) Enable address matching by setting the MSB in register 7
539 */
540
541 printf("Initializing the ADC...\n");
542 udelay(ADC_INITIAL_DELAY); /* 10uSec per uF of VREF cap */
543
544 iopa->pdat &= ~ADC_SDATA1_MASK; /* release SDATA1 */
545 udelay(ADC_SDATA_DELAY); /* arbitrary settling time */
546
547 i2c_reg_write(0x00, 0x06, I2C_ADC_1_ADDR); /* set address */
548 i2c_reg_write(I2C_ADC_1_ADDR, 0x07, /* turn on ADDREN */
549 ADC_REG7_ADDR_ENABLE);
550
551 i2c_reg_write(I2C_ADC_1_ADDR, 0x02, /* 128x, slave mode, !HPEN */
552 (sample_64x ? 0 : ADC_REG2_128x) |
553 ADC_REG2_HIGH_PASS_DIS |
554 ADC_REG2_SLAVE_MODE);
555
556 reg = i2c_reg_read(I2C_ADC_1_ADDR, 0x06) & 0x7F;
557 if(reg != I2C_ADC_1_ADDR)
558 printf("Init of ADC U10 failed: address is 0x%02X should be 0x%02X\n",
559 reg, I2C_ADC_1_ADDR);
560
561 iopa->pdat &= ~ADC_SDATA2_MASK; /* release SDATA2 */
562 udelay(ADC_SDATA_DELAY); /* arbitrary settling time */
563
564 i2c_reg_write(0x00, 0x06, I2C_ADC_2_ADDR); /* set address (do not set ADDREN yet) */
565
566 i2c_reg_write(I2C_ADC_2_ADDR, 0x02, /* 64x, slave mode, !HPEN */
567 (sample_64x ? 0 : ADC_REG2_128x) |
568 ADC_REG2_HIGH_PASS_DIS |
569 ADC_REG2_SLAVE_MODE);
570
571 reg = i2c_reg_read(I2C_ADC_2_ADDR, 0x06) & 0x7F;
572 if(reg != I2C_ADC_2_ADDR)
573 printf("Init of ADC U15 failed: address is 0x%02X should be 0x%02X\n",
574 reg, I2C_ADC_2_ADDR);
575
576 i2c_reg_write(I2C_ADC_1_ADDR, 0x01, /* set FSTART and GNDCAL */
577 ADC_REG1_FRAME_START |
578 ADC_REG1_GROUND_CAL);
579
580 i2c_reg_write(I2C_ADC_1_ADDR, 0x02, /* Start calibration */
581 (sample_64x ? 0 : ADC_REG2_128x) |
582 ADC_REG2_CAL |
583 ADC_REG2_HIGH_PASS_DIS |
584 ADC_REG2_SLAVE_MODE);
585
586 udelay(ADC_CAL_DELAY); /* a minimum of 4100 LRCLKs */
587 i2c_reg_write(I2C_ADC_1_ADDR, 0x01, 0x00); /* remove GNDCAL */
588
589 /*
590 * Now that we have synchronized the ADC's, enable address
591 * selection on the second ADC as well as the first.
592 */
593 i2c_reg_write(I2C_ADC_2_ADDR, 0x07, ADC_REG7_ADDR_ENABLE);
594
595 /*
596 * Initialize the Crystal DAC
597 *
598 * Two of the config lines are used for I2C so we have to set them
599 * to the proper initialization state without inadvertantly
600 * sending an I2C "start" sequence. When we bring the I2C back to
601 * the normal state, we send an I2C "stop" sequence.
602 */
603 printf("Initializing the DAC...\n");
604
605 /*
606 * Bring the I2C clock and data lines low for initialization
607 */
608 I2C_SCL(0);
609 I2C_DELAY;
610 I2C_SDA(0);
611 I2C_ACTIVE;
612 I2C_DELAY;
613
614 /* Reset the DAC */
615 iopa->pdat &= ~DAC_RST_MASK;
616 udelay(DAC_RESET_DELAY);
617
618 /* Release the DAC reset */
619 iopa->pdat |= DAC_RST_MASK;
620 udelay(DAC_INITIAL_DELAY);
621
622 /*
623 * Cause the DAC to:
624 * Enable control port (I2C mode)
625 * Going into power down
626 */
627 i2c_reg_write(I2C_DAC_ADDR, 0x05,
628 DAC_REG5_I2C_MODE |
629 DAC_REG5_POWER_DOWN);
630
631 /*
632 * Cause the DAC to:
633 * Enable control port (I2C mode)
634 * Going into power down
635 * . MCLK divide by 1
636 * . MCLK divide by 2
637 */
638 i2c_reg_write(I2C_DAC_ADDR, 0x05,
639 DAC_REG5_I2C_MODE |
640 DAC_REG5_POWER_DOWN |
641 (mclk_divide ? DAC_REG5_MCLK_DIV : 0));
642
643 /*
644 * Cause the DAC to:
645 * Auto-mute disabled
646 * . Format 0, left justified 24 bits
647 * . Format 3, right justified 24 bits
648 * No de-emphasis
649 * . Single speed mode
650 * . Double speed mode
651 */
652 i2c_reg_write(I2C_DAC_ADDR, 0x01,
653 (right_just ? DAC_REG1_RIGHT_JUST_24BIT :
654 DAC_REG1_LEFT_JUST_24_BIT) |
655 DAC_REG1_DEM_NO |
656 (sample_rate >= 50000 ? DAC_REG1_DOUBLE : DAC_REG1_SINGLE));
657
658 sprintf(str_buf, "%d",
659 sample_rate >= 50000 ? DAC_REG1_DOUBLE : DAC_REG1_SINGLE);
660 setenv("DaqDACFunctionalMode", str_buf);
661
662 /*
663 * Cause the DAC to:
664 * Enable control port (I2C mode)
665 * Remove power down
666 * . MCLK divide by 1
667 * . MCLK divide by 2
668 */
669 i2c_reg_write(I2C_DAC_ADDR, 0x05,
670 DAC_REG5_I2C_MODE |
671 (mclk_divide ? DAC_REG5_MCLK_DIV : 0));
672
673 /*
674 * Create a I2C stop condition:
675 * low->high on data while clock is high.
676 */
677 I2C_SCL(1);
678 I2C_DELAY;
679 I2C_SDA(1);
680 I2C_DELAY;
681 I2C_TRISTATE;
682
683 printf("\n");
684
685#ifdef CONFIG_SHOW_BOOT_PROGRESS
686 /*
687 * Turn off the RED fail LED now that we are up and running.
688 */
689 status_led_set(STATUS_LED_RED, STATUS_LED_OFF);
690#endif
691
692 return 0;
693}
694
695#ifdef CONFIG_SHOW_BOOT_PROGRESS
696/*
697 * Show boot status: flash the LED if something goes wrong, indicating
698 * that last thing that worked and thus, by implication, what is broken.
699 *
700 * This stores the last OK value in RAM so this will not work properly
701 * before RAM is initialized. Since it is being used for indicating
702 * boot status (i.e. after RAM is initialized), that is OK.
703 */
704static void flash_code(uchar number, uchar modulo, uchar digits)
705{
706 int j;
707
708 /*
709 * Recursively do upper digits.
710 */
711 if(digits > 1) {
712 flash_code(number / modulo, modulo, digits - 1);
713 }
714
715 number = number % modulo;
716
717 /*
718 * Zero is indicated by one long flash (dash).
719 */
720 if(number == 0) {
721 status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
722 udelay(1000000);
723 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
724 udelay(200000);
725 } else {
726 /*
727 * Non-zero is indicated by short flashes, one per count.
728 */
729 for(j = 0; j < number; j++) {
730 status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
731 udelay(100000);
732 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
733 udelay(200000);
734 }
735 }
736 /*
737 * Inter-digit pause: we've already waited 200 mSec, wait 1 sec total
738 */
739 udelay(700000);
740}
741
742static int last_boot_progress;
743
744void show_boot_progress (int status)
745{
746 if(status != -1) {
747 last_boot_progress = status;
748 } else {
749 /*
750 * Houston, we have a problem. Blink the last OK status which
751 * indicates where things failed.
752 */
753 status_led_set(STATUS_LED_RED, STATUS_LED_ON);
754 flash_code(last_boot_progress, 5, 3);
755 udelay(1000000);
756 status_led_set(STATUS_LED_RED, STATUS_LED_BLINKING);
757 }
758}
759#endif /* CONFIG_SHOW_BOOT_PROGRESS */
760
761
762/*
763 * The following are used to control the SPI chip selects for the SPI command.
764 */
765#if (CONFIG_COMMANDS & CFG_CMD_SPI)
766
767#define SPI_ADC_CS_MASK 0x00000800
768#define SPI_DAC_CS_MASK 0x00001000
769
770void spi_adc_chipsel(int cs)
771{
772 volatile ioport_t *iopd = ioport_addr((immap_t *)CFG_IMMR, 3 /* port D */);
773
774 if(cs)
775 iopd->pdat &= ~SPI_ADC_CS_MASK; /* activate the chip select */
776 else
777 iopd->pdat |= SPI_ADC_CS_MASK; /* deactivate the chip select */
778}
779
780void spi_dac_chipsel(int cs)
781{
782 volatile ioport_t *iopd = ioport_addr((immap_t *)CFG_IMMR, 3 /* port D */);
783
784 if(cs)
785 iopd->pdat &= ~SPI_DAC_CS_MASK; /* activate the chip select */
786 else
787 iopd->pdat |= SPI_DAC_CS_MASK; /* deactivate the chip select */
788}
789
790/*
791 * The SPI command uses this table of functions for controlling the SPI
792 * chip selects: it calls the appropriate function to control the SPI
793 * chip selects.
794 */
795spi_chipsel_type spi_chipsel[2] = {
796 spi_adc_chipsel,
797 spi_dac_chipsel
798};
799#endif /* CFG_CMD_SPI */
800
801#endif /* CONFIG_MISC_INIT_R */