1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <common.h>
26#include <asm/u-boot.h>
27#include <ioports.h>
28#include <mpc8260.h>
29#include <i2c.h>
30#include <spi.h>
31#include <command.h>
32
33#ifdef CONFIG_SHOW_BOOT_PROGRESS
34#include <status_led.h>
35#endif
36
37#ifdef CONFIG_ETHER_LOOPBACK_TEST
38extern void eth_loopback_test(void);
39#endif
40
41#include "clkinit.h"
42#include "ioconfig.h"
43
44
45
46
47
48
49
50
51
52
53
54
55
56#define CONFIG_PBI PSDMR_PBI
57#define PESSIMISTIC_SDRAM 0
58#define EAMUX 0
59#define BUFCMD 0
60
61
62
63
64#define INITIAL_SAMPLE_RATE 10016
65#define INITIAL_RIGHT_JUST 0
66#define INITIAL_MCLK_DIVIDE 0
67#define INITIAL_SAMPLE_64X 1
68#define INITIAL_SAMPLE_128X 0
69
70
71
72
73#define I2C_ADC_1_ADDR 0x0E
74#define I2C_ADC_2_ADDR 0x0F
75
76#define ADC_SDATA1_MASK 0x00020000
77#define ADC_SDATA2_MASK 0x00010000
78
79#define ADC_VREF_CAP 100
80#define ADC_INITIAL_DELAY (10 * ADC_VREF_CAP)
81#define ADC_SDATA_DELAY 100
82#define ADC_CAL_DELAY (1000000 / INITIAL_SAMPLE_RATE * 4500)
83
84
85#define ADC_REG1_FRAME_START 0x80
86#define ADC_REG1_GROUND_CAL 0x40
87#define ADC_REG1_ANA_MOD_PDOWN 0x20
88#define ADC_REG1_DIG_MOD_PDOWN 0x10
89
90#define ADC_REG2_128x 0x80
91#define ADC_REG2_CAL 0x40
92#define ADC_REG2_CHANGE_SIGN 0x20
93#define ADC_REG2_LR_DISABLE 0x10
94#define ADC_REG2_HIGH_PASS_DIS 0x08
95#define ADC_REG2_SLAVE_MODE 0x04
96#define ADC_REG2_DFS 0x02
97#define ADC_REG2_MUTE 0x01
98
99#define ADC_REG7_ADDR_ENABLE 0x80
100#define ADC_REG7_PEAK_ENABLE 0x40
101#define ADC_REG7_PEAK_UPDATE 0x20
102#define ADC_REG7_PEAK_FORMAT 0x10
103#define ADC_REG7_DIG_FILT_PDOWN 0x04
104#define ADC_REG7_FIR2_IN_EN 0x02
105#define ADC_REG7_PSYCHO_EN 0x01
106
107
108
109
110
111#define I2C_DAC_ADDR 0x11
112
113#define DAC_RST_MASK 0x00008000
114#define DAC_RESET_DELAY 100
115#define DAC_INITIAL_DELAY 5000
116
117#define DAC_REG1_AMUTE 0x80
118
119#define DAC_REG1_LEFT_JUST_24_BIT (0 << 4)
120#define DAC_REG1_I2S_24_BIT (1 << 4)
121#define DAC_REG1_RIGHT_JUST_16BIT (2 << 4)
122#define DAC_REG1_RIGHT_JUST_24BIT (3 << 4)
123#define DAC_REG1_RIGHT_JUST_20BIT (4 << 4)
124#define DAC_REG1_RIGHT_JUST_18BIT (5 << 4)
125
126#define DAC_REG1_DEM_NO (0 << 2)
127#define DAC_REG1_DEM_44KHZ (1 << 2)
128#define DAC_REG1_DEM_48KHZ (2 << 2)
129#define DAC_REG1_DEM_32KHZ (3 << 2)
130
131#define DAC_REG1_SINGLE 0
132#define DAC_REG1_DOUBLE 1
133#define DAC_REG1_QUAD 2
134#define DAC_REG1_DSD 3
135
136#define DAC_REG5_INVERT_A 0x80
137#define DAC_REG5_INVERT_B 0x40
138#define DAC_REG5_I2C_MODE 0x20
139#define DAC_REG5_POWER_DOWN 0x10
140#define DAC_REG5_MUTEC_A_B 0x08
141#define DAC_REG5_FREEZE 0x04
142#define DAC_REG5_MCLK_DIV 0x02
143#define DAC_REG5_RESERVED 0x01
144
145
146
147
148
149
150
151int checkboard(void)
152{
153 printf ("SACSng\n");
154
155 return 0;
156}
157
158
159
160phys_size_t initdram(int board_type)
161{
162 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
163 volatile memctl8260_t *memctl = &immap->im_memctl;
164 volatile uchar c = 0;
165 volatile uchar *ramaddr = (uchar *)(CONFIG_SYS_SDRAM_BASE + 0x8);
166 uint psdmr = CONFIG_SYS_PSDMR;
167 int i;
168 uint psrt = 14;
169 uint chipselects = 1;
170 uint sdram_size = CONFIG_SYS_SDRAM0_SIZE * 1024 * 1024;
171 uint or = CONFIG_SYS_OR2_PRELIM;
172#ifdef SDRAM_SPD_ADDR
173 uint data_width;
174 uint rows;
175 uint banks;
176 uint cols;
177 uint caslatency;
178 uint width;
179 uint rowst;
180 uint sdam;
181 uint bsma;
182 uint sda10;
183 u_char spd_size;
184 u_char data;
185 u_char cksum;
186 int j;
187#endif
188
189#ifdef SDRAM_SPD_ADDR
190
191 data_width = chipselects = rows = banks = cols = caslatency = psrt = 0;
192
193
194
195
196 i2c_read(SDRAM_SPD_ADDR, 0, 1, &data, 1);
197 spd_size = data;
198 cksum = data;
199 for(j = 1; j < 64; j++) {
200
201 i2c_read(SDRAM_SPD_ADDR, 0, 0, &data, 1);
202 if(j == 5) chipselects = data & 0x0F;
203 else if(j == 6) data_width = data;
204 else if(j == 7) data_width |= data << 8;
205 else if(j == 3) rows = data & 0x0F;
206 else if(j == 4) cols = data & 0x0F;
207 else if(j == 12) {
208
209
210
211
212 switch(data & 0x7F) {
213 default:
214 case 0: psrt = 14 ; break;
215 case 1: psrt = 2; break;
216 case 2: psrt = 6; break;
217 case 3: psrt = 29; break;
218 case 4: psrt = 60; break;
219 case 5: psrt = 120; break;
220 }
221 }
222 else if(j == 17) banks = data;
223 else if(j == 18) {
224 caslatency = 3;
225#if(PESSIMISTIC_SDRAM)
226 if((data & 0x04) != 0) caslatency = 3;
227 else if((data & 0x02) != 0) caslatency = 2;
228 else if((data & 0x01) != 0) caslatency = 1;
229#else
230 if((data & 0x01) != 0) caslatency = 1;
231 else if((data & 0x02) != 0) caslatency = 2;
232 else if((data & 0x04) != 0) caslatency = 3;
233#endif
234 else {
235 printf ("WARNING: Unknown CAS latency 0x%02X, using 3\n",
236 data);
237 }
238 }
239 else if(j == 63) {
240 if(data != cksum) {
241 printf ("WARNING: Configuration data checksum failure:"
242 " is 0x%02x, calculated 0x%02x\n",
243 data, cksum);
244 }
245 }
246 cksum += data;
247 }
248
249
250 if(caslatency < 2) {
251 printf("WARNING: CL was %d, forcing to 2\n", caslatency);
252 caslatency = 2;
253 }
254 if(rows > 14) {
255 printf("WARNING: This doesn't look good, rows = %d, should be <= 14\n", rows);
256 rows = 14;
257 }
258 if(cols > 11) {
259 printf("WARNING: This doesn't look good, columns = %d, should be <= 11\n", cols);
260 cols = 11;
261 }
262
263 if((data_width != 64) && (data_width != 72))
264 {
265 printf("WARNING: SDRAM width unsupported, is %d, expected 64 or 72.\n",
266 data_width);
267 }
268 width = 3;
269
270
271
272 if (banks == 2) banks = 1;
273 else if(banks == 4) banks = 2;
274 else if(banks == 8) banks = 3;
275
276 sdram_size = 1 << (rows + cols + banks + width);
277
278#if(CONFIG_PBI == 0)
279 rowst = ((32 - 6) - (rows + cols + width)) * 2;
280#else
281 rowst = 32 - (rows + banks + cols + width);
282#endif
283
284 or = ~(sdram_size - 1) |
285 ((banks-1) << 13) |
286 (rowst << 9) |
287 ((rows - 9) << 6);
288
289 memctl->memc_or2 = or;
290
291
292
293
294
295
296
297
298
299
300#if(CONFIG_PBI == 0)
301 sdam = cols - 8;
302 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
303 sda10 = sdam + 2;
304#else
305 sdam = cols - 6;
306 bsma = ((31 - width) - 14) - ((rows > cols) ? rows : cols);
307 sda10 = sdam;
308#endif
309#if(PESSIMISTIC_SDRAM)
310 psdmr = (CONFIG_PBI |\
311 PSDMR_RFEN |\
312 PSDMR_RFRC_16_CLK |\
313 PSDMR_PRETOACT_8W |\
314 PSDMR_ACTTORW_8W |\
315 PSDMR_WRC_4C |\
316 PSDMR_EAMUX |\
317 PSDMR_BUFCMD) |\
318 caslatency |\
319 ((caslatency - 1) << 6) | \
320 (sdam << 24) |\
321 (bsma << 21) |\
322 (sda10 << 18);
323#else
324 psdmr = (CONFIG_PBI |\
325 PSDMR_RFEN |\
326 PSDMR_RFRC_7_CLK |\
327 PSDMR_PRETOACT_3W | \
328 PSDMR_ACTTORW_2W | \
329 PSDMR_WRC_1C |
330 EAMUX |\
331 BUFCMD) |\
332 caslatency |\
333 ((caslatency - 1) << 6) | \
334 (sdam << 24) |\
335 (bsma << 21) |\
336 (sda10 << 18);
337#endif
338#endif
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
388 memctl->memc_psrt = psrt;
389
390 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
391 *ramaddr = c;
392
393 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
394 for (i = 0; i < 8; i++)
395 *ramaddr = c;
396
397 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
398 *ramaddr = c;
399
400 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
401 *ramaddr = c;
402
403
404
405
406
407 if(chipselects > 1) {
408 ramaddr += sdram_size;
409
410 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM + sdram_size;
411 memctl->memc_or3 = or;
412
413 memctl->memc_psdmr = psdmr | PSDMR_OP_PREA;
414 *ramaddr = c;
415
416 memctl->memc_psdmr = psdmr | PSDMR_OP_CBRR;
417 for (i = 0; i < 8; i++)
418 *ramaddr = c;
419
420 memctl->memc_psdmr = psdmr | PSDMR_OP_MRW;
421 *ramaddr = c;
422
423 memctl->memc_psdmr = psdmr | PSDMR_OP_NORM | PSDMR_RFEN;
424 *ramaddr = c;
425 }
426
427
428 return (sdram_size * chipselects);
429}
430
431
432
433
434void board_poweroff (void)
435{
436 while (1);
437}
438
439
440#ifdef CONFIG_MISC_INIT_R
441
442int misc_init_r(void)
443{
444
445
446
447 volatile ioport_t *iopa = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 0 );
448 volatile ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, I2C_PORT);
449
450 int reg;
451 char *ep;
452 char str_buf[12] ;
453 int sample_rate;
454 int sample_64x;
455 int sample_128x;
456 int right_just;
457 int mclk_divide;
458 int quiet;
459
460 quiet = 0;
461 if ((ep = getenv("quiet")) != NULL) {
462 quiet = simple_strtol(ep, NULL, 10);
463 }
464 else {
465 setenv("quiet", "0");
466 }
467
468
469
470
471
472
473
474 sample_rate = INITIAL_SAMPLE_RATE;
475 if ((ep = getenv("DaqSampleRate")) != NULL) {
476 sample_rate = simple_strtol(ep, NULL, 10);
477 }
478
479 sample_64x = INITIAL_SAMPLE_64X;
480 sample_128x = INITIAL_SAMPLE_128X;
481 if ((ep = getenv("Daq64xSampling")) != NULL) {
482 sample_64x = simple_strtol(ep, NULL, 10);
483 if (sample_64x) {
484 sample_128x = 0;
485 }
486 else {
487 sample_128x = 1;
488 }
489 }
490 else {
491 if ((ep = getenv("Daq128xSampling")) != NULL) {
492 sample_128x = simple_strtol(ep, NULL, 10);
493 if (sample_128x) {
494 sample_64x = 0;
495 }
496 else {
497 sample_64x = 1;
498 }
499 }
500 }
501
502
503
504
505
506 Daq_Stop_Clocks();
507 udelay((1000000 / sample_rate) * NUM_LRCLKS_TO_STABILIZE);
508
509
510
511
512 Daq_Init_Clocks(sample_rate, sample_64x);
513 sample_rate = Daq_Get_SampleRate();
514
515
516
517
518
519 Daq_Start_Clocks(sample_rate);
520 udelay((1000000 / sample_rate) * NUM_LRCLKS_TO_STABILIZE);
521
522 sprintf(str_buf, "%d", sample_rate);
523 setenv("DaqSampleRate", str_buf);
524
525 if (sample_64x) {
526 setenv("Daq64xSampling", "1");
527 setenv("Daq128xSampling", NULL);
528 }
529 else {
530 setenv("Daq64xSampling", NULL);
531 setenv("Daq128xSampling", "1");
532 }
533
534
535
536
537 if (!quiet) {
538 Daq_Display_Clocks();
539 }
540
541
542
543
544
545 right_just = INITIAL_RIGHT_JUST;
546 if ((ep = getenv("DaqDACRightJustified")) != NULL) {
547 right_just = simple_strtol(ep, NULL, 10);
548 }
549
550 sprintf(str_buf, "%d", right_just);
551 setenv("DaqDACRightJustified", str_buf);
552
553
554
555
556
557 mclk_divide = INITIAL_MCLK_DIVIDE;
558 if ((ep = getenv("DaqDACMClockDivide")) != NULL) {
559 mclk_divide = simple_strtol(ep, NULL, 10);
560 }
561
562 sprintf(str_buf, "%d", mclk_divide);
563 setenv("DaqDACMClockDivide", str_buf);
564
565
566
567
568
569
570
571
572
573
574 if (!quiet) {
575 printf("Initializing the ADC...\n");
576 }
577 udelay(ADC_INITIAL_DELAY);
578
579 iopa->pdat &= ~ADC_SDATA1_MASK;
580 udelay(ADC_SDATA_DELAY);
581
582 i2c_reg_write(0x00, 0x06, I2C_ADC_1_ADDR);
583 i2c_reg_write(I2C_ADC_1_ADDR, 0x07,
584 ADC_REG7_ADDR_ENABLE);
585
586 i2c_reg_write(I2C_ADC_1_ADDR, 0x02,
587 (sample_64x ? 0 : ADC_REG2_128x) |
588 ADC_REG2_HIGH_PASS_DIS |
589 ADC_REG2_SLAVE_MODE);
590
591 reg = i2c_reg_read(I2C_ADC_1_ADDR, 0x06) & 0x7F;
592 if(reg != I2C_ADC_1_ADDR)
593 printf("Init of ADC U10 failed: address is 0x%02X should be 0x%02X\n",
594 reg, I2C_ADC_1_ADDR);
595
596 iopa->pdat &= ~ADC_SDATA2_MASK;
597 udelay(ADC_SDATA_DELAY);
598
599 i2c_reg_write(0x00, 0x06, I2C_ADC_2_ADDR);
600
601 i2c_reg_write(I2C_ADC_2_ADDR, 0x02,
602 (sample_64x ? 0 : ADC_REG2_128x) |
603 ADC_REG2_HIGH_PASS_DIS |
604 ADC_REG2_SLAVE_MODE);
605
606 reg = i2c_reg_read(I2C_ADC_2_ADDR, 0x06) & 0x7F;
607 if(reg != I2C_ADC_2_ADDR)
608 printf("Init of ADC U15 failed: address is 0x%02X should be 0x%02X\n",
609 reg, I2C_ADC_2_ADDR);
610
611 i2c_reg_write(I2C_ADC_1_ADDR, 0x01,
612 ADC_REG1_FRAME_START |
613 ADC_REG1_GROUND_CAL);
614
615 i2c_reg_write(I2C_ADC_1_ADDR, 0x02,
616 (sample_64x ? 0 : ADC_REG2_128x) |
617 ADC_REG2_CAL |
618 ADC_REG2_HIGH_PASS_DIS |
619 ADC_REG2_SLAVE_MODE);
620
621 udelay(ADC_CAL_DELAY);
622 i2c_reg_write(I2C_ADC_1_ADDR, 0x01, 0x00);
623
624
625
626
627
628 i2c_reg_write(I2C_ADC_2_ADDR, 0x07, ADC_REG7_ADDR_ENABLE);
629
630
631
632
633
634
635
636
637
638 if (!quiet) {
639 printf("Initializing the DAC...\n");
640 }
641
642
643
644
645 I2C_SCL(0);
646 I2C_DELAY;
647 I2C_SDA(0);
648 I2C_ACTIVE;
649 I2C_DELAY;
650
651
652 iopa->pdat &= ~DAC_RST_MASK;
653 udelay(DAC_RESET_DELAY);
654
655
656 iopa->pdat |= DAC_RST_MASK;
657 udelay(DAC_INITIAL_DELAY);
658
659
660
661
662
663
664 i2c_reg_write(I2C_DAC_ADDR, 0x05,
665 DAC_REG5_I2C_MODE |
666 DAC_REG5_POWER_DOWN);
667
668
669
670
671
672
673
674
675 i2c_reg_write(I2C_DAC_ADDR, 0x05,
676 DAC_REG5_I2C_MODE |
677 DAC_REG5_POWER_DOWN |
678 (mclk_divide ? DAC_REG5_MCLK_DIV : 0));
679
680
681
682
683
684
685
686
687
688
689 i2c_reg_write(I2C_DAC_ADDR, 0x01,
690 (right_just ? DAC_REG1_RIGHT_JUST_24BIT :
691 DAC_REG1_LEFT_JUST_24_BIT) |
692 DAC_REG1_DEM_NO |
693 (sample_rate >= 50000 ? DAC_REG1_DOUBLE : DAC_REG1_SINGLE));
694
695 sprintf(str_buf, "%d",
696 sample_rate >= 50000 ? DAC_REG1_DOUBLE : DAC_REG1_SINGLE);
697 setenv("DaqDACFunctionalMode", str_buf);
698
699
700
701
702
703
704
705
706 i2c_reg_write(I2C_DAC_ADDR, 0x05,
707 DAC_REG5_I2C_MODE |
708 (mclk_divide ? DAC_REG5_MCLK_DIV : 0));
709
710
711
712
713
714 I2C_SCL(1);
715 I2C_DELAY;
716 I2C_SDA(1);
717 I2C_DELAY;
718 I2C_TRISTATE;
719
720 if (!quiet) {
721 printf("\n");
722 }
723
724#ifdef CONFIG_ETHER_LOOPBACK_TEST
725
726
727
728 eth_loopback_test ();
729#endif
730
731#ifdef CONFIG_SHOW_BOOT_PROGRESS
732
733
734
735 status_led_set(STATUS_LED_RED, STATUS_LED_OFF);
736#endif
737
738 return 0;
739}
740
741#ifdef CONFIG_SHOW_BOOT_PROGRESS
742
743
744
745
746
747
748
749
750static void flash_code(uchar number, uchar modulo, uchar digits)
751{
752 int j;
753
754
755
756
757 if(digits > 1) {
758 flash_code(number / modulo, modulo, digits - 1);
759 }
760
761 number = number % modulo;
762
763
764
765
766 if(number == 0) {
767 status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
768 udelay(1000000);
769 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
770 udelay(200000);
771 } else {
772
773
774
775 for(j = 0; j < number; j++) {
776 status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
777 udelay(100000);
778 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
779 udelay(200000);
780 }
781 }
782
783
784
785 udelay(700000);
786}
787
788static int last_boot_progress;
789
790void show_boot_progress (int status)
791{
792 int i,j;
793 if(status > 0) {
794 last_boot_progress = status;
795 } else {
796
797
798
799
800 if(status < -1)
801 last_boot_progress = -status;
802
803
804
805
806 for(j=0; j<5; j++) {
807
808
809
810
811 status_led_set(STATUS_LED_RED, STATUS_LED_ON);
812 flash_code(last_boot_progress, 5, 3);
813
814
815
816
817
818 for(i=0; i<5; i++) {
819 status_led_set(STATUS_LED_RED, STATUS_LED_OFF);
820 udelay(500000);
821 status_led_set(STATUS_LED_RED, STATUS_LED_ON);
822 udelay(500000);
823 }
824 }
825
826
827
828
829 do_reset (NULL, 0, 0, NULL);
830 }
831}
832#endif
833
834
835
836
837
838#if defined(CONFIG_CMD_SPI)
839
840#define SPI_ADC_CS_MASK 0x00000800
841#define SPI_DAC_CS_MASK 0x00001000
842
843static const u32 cs_mask[] = {
844 SPI_ADC_CS_MASK,
845 SPI_DAC_CS_MASK,
846};
847
848int spi_cs_is_valid(unsigned int bus, unsigned int cs)
849{
850 return bus == 0 && cs < sizeof(cs_mask) / sizeof(cs_mask[0]);
851}
852
853void spi_cs_activate(struct spi_slave *slave)
854{
855 volatile ioport_t *iopd = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3 );
856
857 iopd->pdat &= ~cs_mask[slave->cs];
858}
859
860void spi_cs_deactivate(struct spi_slave *slave)
861{
862 volatile ioport_t *iopd = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3 );
863
864 iopd->pdat |= cs_mask[slave->cs];
865}
866
867#endif
868
869#endif
870