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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
|
diff -uprN u-boot-orig/include/atmel_spi.h u-boot/include/atmel_spi.h
--- u-boot-orig/include/atmel_spi.h 1970-01-01 01:00:00.000000000 +0100
+++ u-boot/include/atmel_spi.h 2007-01-01 18:45:27.000000000 +0100
@@ -0,0 +1,676 @@
+#ifndef __SPI_H_
+#define __SPI_H_
+
+/*! \brief Timeout for spi read and write blocking functions */
+#define SPI_TIMEOUT 10000
+/*! \brief Enable PDC functions for SPI */
+#define SPI_ENABLE_PDC
+
+#define SPI_10_BPT 0x00000002
+#define SPI_11_BPT 0x00000003
+#define SPI_12_BPT 0x00000004
+#define SPI_13_BPT 0x00000005
+#define SPI_14_BPT 0x00000006
+#define SPI_15_BPT 0x00000007
+#define SPI_16_BPT 0x00000008
+#define SPI_8_BPT 0x00000000
+#define SPI_9_BPT 0x00000001
+#define SPI_BITS 4
+#define SPI_BITS_10_BPT 0x00000002
+#define SPI_BITS_11_BPT 0x00000003
+#define SPI_BITS_12_BPT 0x00000004
+#define SPI_BITS_13_BPT 0x00000005
+#define SPI_BITS_14_BPT 0x00000006
+#define SPI_BITS_15_BPT 0x00000007
+#define SPI_BITS_16_BPT 0x00000008
+#define SPI_BITS_8_BPT 0x00000000
+#define SPI_BITS_9_BPT 0x00000001
+#define SPI_BITS_MASK 0x000000f0
+#define SPI_BITS_OFFSET 4
+#define SPI_BITS_SIZE 4
+#define SPI_CPOL 0
+#define SPI_CPOL_MASK 0x00000001
+#define SPI_CPOL_OFFSET 0
+#define SPI_CPOL_SIZE 1
+#define SPI_CR 0x00000000
+#define SPI_CR_LASTXFER 24
+#define SPI_CR_LASTXFER_MASK 0x01000000
+#define SPI_CR_LASTXFER_OFFSET 24
+#define SPI_CR_LASTXFER_SIZE 1
+#define SPI_CR_SPIDIS 1
+#define SPI_CR_SPIDIS_MASK 0x00000002
+#define SPI_CR_SPIDIS_OFFSET 1
+#define SPI_CR_SPIDIS_SIZE 1
+#define SPI_CR_SPIEN 0
+#define SPI_CR_SPIEN_MASK 0x00000001
+#define SPI_CR_SPIEN_OFFSET 0
+#define SPI_CR_SPIEN_SIZE 1
+#define SPI_CR_SWRST 7
+#define SPI_CR_SWRST_MASK 0x00000080
+#define SPI_CR_SWRST_OFFSET 7
+#define SPI_CR_SWRST_SIZE 1
+#define SPI_CSAAT 3
+#define SPI_CSAAT_MASK 0x00000008
+#define SPI_CSAAT_OFFSET 3
+#define SPI_CSAAT_SIZE 1
+#define SPI_CSR0 0x00000030
+#define SPI_CSR0_BITS 4
+#define SPI_CSR0_BITS_10_BPT 0x00000002
+#define SPI_CSR0_BITS_11_BPT 0x00000003
+#define SPI_CSR0_BITS_12_BPT 0x00000004
+#define SPI_CSR0_BITS_13_BPT 0x00000005
+#define SPI_CSR0_BITS_14_BPT 0x00000006
+#define SPI_CSR0_BITS_15_BPT 0x00000007
+#define SPI_CSR0_BITS_16_BPT 0x00000008
+#define SPI_CSR0_BITS_8_BPT 0x00000000
+#define SPI_CSR0_BITS_9_BPT 0x00000001
+#define SPI_CSR0_BITS_MASK 0x000000f0
+#define SPI_CSR0_BITS_OFFSET 4
+#define SPI_CSR0_BITS_SIZE 4
+#define SPI_CSR0_CPOL 0
+#define SPI_CSR0_CPOL_MASK 0x00000001
+#define SPI_CSR0_CPOL_OFFSET 0
+#define SPI_CSR0_CPOL_SIZE 1
+#define SPI_CSR0_CSAAT 3
+#define SPI_CSR0_CSAAT_MASK 0x00000008
+#define SPI_CSR0_CSAAT_OFFSET 3
+#define SPI_CSR0_CSAAT_SIZE 1
+#define SPI_CSR0_DLYBCT 24
+#define SPI_CSR0_DLYBCT_MASK 0xff000000
+#define SPI_CSR0_DLYBCT_OFFSET 24
+#define SPI_CSR0_DLYBCT_SIZE 8
+#define SPI_CSR0_DLYBS 16
+#define SPI_CSR0_DLYBS_MASK 0x00ff0000
+#define SPI_CSR0_DLYBS_OFFSET 16
+#define SPI_CSR0_DLYBS_SIZE 8
+#define SPI_CSR0_NCPHA 1
+#define SPI_CSR0_NCPHA_MASK 0x00000002
+#define SPI_CSR0_NCPHA_OFFSET 1
+#define SPI_CSR0_NCPHA_SIZE 1
+#define SPI_CSR0_SCBR 8
+#define SPI_CSR0_SCBR_MASK 0x0000ff00
+#define SPI_CSR0_SCBR_OFFSET 8
+#define SPI_CSR0_SCBR_SIZE 8
+#define SPI_CSR1 0x00000034
+#define SPI_CSR1_BITS 4
+#define SPI_CSR1_BITS_10_BPT 0x00000002
+#define SPI_CSR1_BITS_11_BPT 0x00000003
+#define SPI_CSR1_BITS_12_BPT 0x00000004
+#define SPI_CSR1_BITS_13_BPT 0x00000005
+#define SPI_CSR1_BITS_14_BPT 0x00000006
+#define SPI_CSR1_BITS_15_BPT 0x00000007
+#define SPI_CSR1_BITS_16_BPT 0x00000008
+#define SPI_CSR1_BITS_8_BPT 0x00000000
+#define SPI_CSR1_BITS_9_BPT 0x00000001
+#define SPI_CSR1_BITS_MASK 0x000000f0
+#define SPI_CSR1_BITS_OFFSET 4
+#define SPI_CSR1_BITS_SIZE 4
+#define SPI_CSR1_CPOL 0
+#define SPI_CSR1_CPOL_MASK 0x00000001
+#define SPI_CSR1_CPOL_OFFSET 0
+#define SPI_CSR1_CPOL_SIZE 1
+#define SPI_CSR1_CSAAT 3
+#define SPI_CSR1_CSAAT_MASK 0x00000008
+#define SPI_CSR1_CSAAT_OFFSET 3
+#define SPI_CSR1_CSAAT_SIZE 1
+#define SPI_CSR1_DLYBCT 24
+#define SPI_CSR1_DLYBCT_MASK 0xff000000
+#define SPI_CSR1_DLYBCT_OFFSET 24
+#define SPI_CSR1_DLYBCT_SIZE 8
+#define SPI_CSR1_DLYBS 16
+#define SPI_CSR1_DLYBS_MASK 0x00ff0000
+#define SPI_CSR1_DLYBS_OFFSET 16
+#define SPI_CSR1_DLYBS_SIZE 8
+#define SPI_CSR1_NCPHA 1
+#define SPI_CSR1_NCPHA_MASK 0x00000002
+#define SPI_CSR1_NCPHA_OFFSET 1
+#define SPI_CSR1_NCPHA_SIZE 1
+#define SPI_CSR1_SCBR 8
+#define SPI_CSR1_SCBR_MASK 0x0000ff00
+#define SPI_CSR1_SCBR_OFFSET 8
+#define SPI_CSR1_SCBR_SIZE 8
+#define SPI_CSR2 0x00000038
+#define SPI_CSR2_BITS 4
+#define SPI_CSR2_BITS_10_BPT 0x00000002
+#define SPI_CSR2_BITS_11_BPT 0x00000003
+#define SPI_CSR2_BITS_12_BPT 0x00000004
+#define SPI_CSR2_BITS_13_BPT 0x00000005
+#define SPI_CSR2_BITS_14_BPT 0x00000006
+#define SPI_CSR2_BITS_15_BPT 0x00000007
+#define SPI_CSR2_BITS_16_BPT 0x00000008
+#define SPI_CSR2_BITS_8_BPT 0x00000000
+#define SPI_CSR2_BITS_9_BPT 0x00000001
+#define SPI_CSR2_BITS_MASK 0x000000f0
+#define SPI_CSR2_BITS_OFFSET 4
+#define SPI_CSR2_BITS_SIZE 4
+#define SPI_CSR2_CPOL 0
+#define SPI_CSR2_CPOL_MASK 0x00000001
+#define SPI_CSR2_CPOL_OFFSET 0
+#define SPI_CSR2_CPOL_SIZE 1
+#define SPI_CSR2_CSAAT 3
+#define SPI_CSR2_CSAAT_MASK 0x00000008
+#define SPI_CSR2_CSAAT_OFFSET 3
+#define SPI_CSR2_CSAAT_SIZE 1
+#define SPI_CSR2_DLYBCT 24
+#define SPI_CSR2_DLYBCT_MASK 0xff000000
+#define SPI_CSR2_DLYBCT_OFFSET 24
+#define SPI_CSR2_DLYBCT_SIZE 8
+#define SPI_CSR2_DLYBS 16
+#define SPI_CSR2_DLYBS_MASK 0x00ff0000
+#define SPI_CSR2_DLYBS_OFFSET 16
+#define SPI_CSR2_DLYBS_SIZE 8
+#define SPI_CSR2_NCPHA 1
+#define SPI_CSR2_NCPHA_MASK 0x00000002
+#define SPI_CSR2_NCPHA_OFFSET 1
+#define SPI_CSR2_NCPHA_SIZE 1
+#define SPI_CSR2_SCBR 8
+#define SPI_CSR2_SCBR_MASK 0x0000ff00
+#define SPI_CSR2_SCBR_OFFSET 8
+#define SPI_CSR2_SCBR_SIZE 8
+#define SPI_CSR3 0x0000003c
+#define SPI_CSR3_BITS 4
+#define SPI_CSR3_BITS_10_BPT 0x00000002
+#define SPI_CSR3_BITS_11_BPT 0x00000003
+#define SPI_CSR3_BITS_12_BPT 0x00000004
+#define SPI_CSR3_BITS_13_BPT 0x00000005
+#define SPI_CSR3_BITS_14_BPT 0x00000006
+#define SPI_CSR3_BITS_15_BPT 0x00000007
+#define SPI_CSR3_BITS_16_BPT 0x00000008
+#define SPI_CSR3_BITS_8_BPT 0x00000000
+#define SPI_CSR3_BITS_9_BPT 0x00000001
+#define SPI_CSR3_BITS_MASK 0x000000f0
+#define SPI_CSR3_BITS_OFFSET 4
+#define SPI_CSR3_BITS_SIZE 4
+#define SPI_CSR3_CPOL 0
+#define SPI_CSR3_CPOL_MASK 0x00000001
+#define SPI_CSR3_CPOL_OFFSET 0
+#define SPI_CSR3_CPOL_SIZE 1
+#define SPI_CSR3_CSAAT 3
+#define SPI_CSR3_CSAAT_MASK 0x00000008
+#define SPI_CSR3_CSAAT_OFFSET 3
+#define SPI_CSR3_CSAAT_SIZE 1
+#define SPI_CSR3_DLYBCT 24
+#define SPI_CSR3_DLYBCT_MASK 0xff000000
+#define SPI_CSR3_DLYBCT_OFFSET 24
+#define SPI_CSR3_DLYBCT_SIZE 8
+#define SPI_CSR3_DLYBS 16
+#define SPI_CSR3_DLYBS_MASK 0x00ff0000
+#define SPI_CSR3_DLYBS_OFFSET 16
+#define SPI_CSR3_DLYBS_SIZE 8
+#define SPI_CSR3_NCPHA 1
+#define SPI_CSR3_NCPHA_MASK 0x00000002
+#define SPI_CSR3_NCPHA_OFFSET 1
+#define SPI_CSR3_NCPHA_SIZE 1
+#define SPI_CSR3_SCBR 8
+#define SPI_CSR3_SCBR_MASK 0x0000ff00
+#define SPI_CSR3_SCBR_OFFSET 8
+#define SPI_CSR3_SCBR_SIZE 8
+#define SPI_DLYBCS 24
+#define SPI_DLYBCS_MASK 0xff000000
+#define SPI_DLYBCS_OFFSET 24
+#define SPI_DLYBCS_SIZE 8
+#define SPI_DLYBCT 24
+#define SPI_DLYBCT_MASK 0xff000000
+#define SPI_DLYBCT_OFFSET 24
+#define SPI_DLYBCT_SIZE 8
+#define SPI_DLYBS 16
+#define SPI_DLYBS_MASK 0x00ff0000
+#define SPI_DLYBS_OFFSET 16
+#define SPI_DLYBS_SIZE 8
+#define SPI_ENDRX 4
+#define SPI_ENDRX_MASK 0x00000010
+#define SPI_ENDRX_OFFSET 4
+#define SPI_ENDRX_SIZE 1
+#define SPI_ENDTX 5
+#define SPI_ENDTX_MASK 0x00000020
+#define SPI_ENDTX_OFFSET 5
+#define SPI_ENDTX_SIZE 1
+#define SPI_FDIV 3
+#define SPI_FDIV_MASK 0x00000008
+#define SPI_FDIV_OFFSET 3
+#define SPI_FDIV_SIZE 1
+#define SPI_IDR 0x00000018
+#define SPI_IDR_ENDRX 4
+#define SPI_IDR_ENDRX_MASK 0x00000010
+#define SPI_IDR_ENDRX_OFFSET 4
+#define SPI_IDR_ENDRX_SIZE 1
+#define SPI_IDR_ENDTX 5
+#define SPI_IDR_ENDTX_MASK 0x00000020
+#define SPI_IDR_ENDTX_OFFSET 5
+#define SPI_IDR_ENDTX_SIZE 1
+#define SPI_IDR_MODF 2
+#define SPI_IDR_MODF_MASK 0x00000004
+#define SPI_IDR_MODF_OFFSET 2
+#define SPI_IDR_MODF_SIZE 1
+#define SPI_IDR_NSSR 8
+#define SPI_IDR_NSSR_MASK 0x00000100
+#define SPI_IDR_NSSR_OFFSET 8
+#define SPI_IDR_NSSR_SIZE 1
+#define SPI_IDR_OVRES 3
+#define SPI_IDR_OVRES_MASK 0x00000008
+#define SPI_IDR_OVRES_OFFSET 3
+#define SPI_IDR_OVRES_SIZE 1
+#define SPI_IDR_RDRF 0
+#define SPI_IDR_RDRF_MASK 0x00000001
+#define SPI_IDR_RDRF_OFFSET 0
+#define SPI_IDR_RDRF_SIZE 1
+#define SPI_IDR_RXBUFF 6
+#define SPI_IDR_RXBUFF_MASK 0x00000040
+#define SPI_IDR_RXBUFF_OFFSET 6
+#define SPI_IDR_RXBUFF_SIZE 1
+#define SPI_IDR_TDRE 1
+#define SPI_IDR_TDRE_MASK 0x00000002
+#define SPI_IDR_TDRE_OFFSET 1
+#define SPI_IDR_TDRE_SIZE 1
+#define SPI_IDR_TXBUFE 7
+#define SPI_IDR_TXBUFE_MASK 0x00000080
+#define SPI_IDR_TXBUFE_OFFSET 7
+#define SPI_IDR_TXBUFE_SIZE 1
+#define SPI_IDR_TXEMPTY 9
+#define SPI_IDR_TXEMPTY_MASK 0x00000200
+#define SPI_IDR_TXEMPTY_OFFSET 9
+#define SPI_IDR_TXEMPTY_SIZE 1
+#define SPI_IER 0x00000014
+#define SPI_IER_ENDRX 4
+#define SPI_IER_ENDRX_MASK 0x00000010
+#define SPI_IER_ENDRX_OFFSET 4
+#define SPI_IER_ENDRX_SIZE 1
+#define SPI_IER_ENDTX 5
+#define SPI_IER_ENDTX_MASK 0x00000020
+#define SPI_IER_ENDTX_OFFSET 5
+#define SPI_IER_ENDTX_SIZE 1
+#define SPI_IER_MODF 2
+#define SPI_IER_MODF_MASK 0x00000004
+#define SPI_IER_MODF_OFFSET 2
+#define SPI_IER_MODF_SIZE 1
+#define SPI_IER_NSSR 8
+#define SPI_IER_NSSR_MASK 0x00000100
+#define SPI_IER_NSSR_OFFSET 8
+#define SPI_IER_NSSR_SIZE 1
+#define SPI_IER_OVRES 3
+#define SPI_IER_OVRES_MASK 0x00000008
+#define SPI_IER_OVRES_OFFSET 3
+#define SPI_IER_OVRES_SIZE 1
+#define SPI_IER_RDRF 0
+#define SPI_IER_RDRF_MASK 0x00000001
+#define SPI_IER_RDRF_OFFSET 0
+#define SPI_IER_RDRF_SIZE 1
+#define SPI_IER_RXBUFF 6
+#define SPI_IER_RXBUFF_MASK 0x00000040
+#define SPI_IER_RXBUFF_OFFSET 6
+#define SPI_IER_RXBUFF_SIZE 1
+#define SPI_IER_TDRE 1
+#define SPI_IER_TDRE_MASK 0x00000002
+#define SPI_IER_TDRE_OFFSET 1
+#define SPI_IER_TDRE_SIZE 1
+#define SPI_IER_TXBUFE 7
+#define SPI_IER_TXBUFE_MASK 0x00000080
+#define SPI_IER_TXBUFE_OFFSET 7
+#define SPI_IER_TXBUFE_SIZE 1
+#define SPI_IER_TXEMPTY 9
+#define SPI_IER_TXEMPTY_MASK 0x00000200
+#define SPI_IER_TXEMPTY_OFFSET 9
+#define SPI_IER_TXEMPTY_SIZE 1
+#define SPI_IMR 0x0000001c
+#define SPI_IMR_ENDRX 4
+#define SPI_IMR_ENDRX_MASK 0x00000010
+#define SPI_IMR_ENDRX_OFFSET 4
+#define SPI_IMR_ENDRX_SIZE 1
+#define SPI_IMR_ENDTX 5
+#define SPI_IMR_ENDTX_MASK 0x00000020
+#define SPI_IMR_ENDTX_OFFSET 5
+#define SPI_IMR_ENDTX_SIZE 1
+#define SPI_IMR_MODF 2
+#define SPI_IMR_MODF_MASK 0x00000004
+#define SPI_IMR_MODF_OFFSET 2
+#define SPI_IMR_MODF_SIZE 1
+#define SPI_IMR_NSSR 8
+#define SPI_IMR_NSSR_MASK 0x00000100
+#define SPI_IMR_NSSR_OFFSET 8
+#define SPI_IMR_NSSR_SIZE 1
+#define SPI_IMR_OVRES 3
+#define SPI_IMR_OVRES_MASK 0x00000008
+#define SPI_IMR_OVRES_OFFSET 3
+#define SPI_IMR_OVRES_SIZE 1
+#define SPI_IMR_RDRF 0
+#define SPI_IMR_RDRF_MASK 0x00000001
+#define SPI_IMR_RDRF_OFFSET 0
+#define SPI_IMR_RDRF_SIZE 1
+#define SPI_IMR_RXBUFF 6
+#define SPI_IMR_RXBUFF_MASK 0x00000040
+#define SPI_IMR_RXBUFF_OFFSET 6
+#define SPI_IMR_RXBUFF_SIZE 1
+#define SPI_IMR_TDRE 1
+#define SPI_IMR_TDRE_MASK 0x00000002
+#define SPI_IMR_TDRE_OFFSET 1
+#define SPI_IMR_TDRE_SIZE 1
+#define SPI_IMR_TXBUFE 7
+#define SPI_IMR_TXBUFE_MASK 0x00000080
+#define SPI_IMR_TXBUFE_OFFSET 7
+#define SPI_IMR_TXBUFE_SIZE 1
+#define SPI_IMR_TXEMPTY 9
+#define SPI_IMR_TXEMPTY_MASK 0x00000200
+#define SPI_IMR_TXEMPTY_OFFSET 9
+#define SPI_IMR_TXEMPTY_SIZE 1
+#define SPI_LASTXFER 24
+#define SPI_LASTXFER_MASK 0x01000000
+#define SPI_LASTXFER_OFFSET 24
+#define SPI_LASTXFER_SIZE 1
+#define SPI_LLB 7
+#define SPI_LLB_MASK 0x00000080
+#define SPI_LLB_OFFSET 7
+#define SPI_LLB_SIZE 1
+#define SPI_MODF 2
+#define SPI_MODFDIS 4
+#define SPI_MODFDIS_MASK 0x00000010
+#define SPI_MODFDIS_OFFSET 4
+#define SPI_MODFDIS_SIZE 1
+#define SPI_MODF_MASK 0x00000004
+#define SPI_MODF_OFFSET 2
+#define SPI_MODF_SIZE 1
+#define SPI_MR 0x00000004
+#define SPI_MR_DLYBCS 24
+#define SPI_MR_DLYBCS_MASK 0xff000000
+#define SPI_MR_DLYBCS_OFFSET 24
+#define SPI_MR_DLYBCS_SIZE 8
+#define SPI_MR_FDIV 3
+#define SPI_MR_FDIV_MASK 0x00000008
+#define SPI_MR_FDIV_OFFSET 3
+#define SPI_MR_FDIV_SIZE 1
+#define SPI_MR_LLB 7
+#define SPI_MR_LLB_MASK 0x00000080
+#define SPI_MR_LLB_OFFSET 7
+#define SPI_MR_LLB_SIZE 1
+#define SPI_MR_MODFDIS 4
+#define SPI_MR_MODFDIS_MASK 0x00000010
+#define SPI_MR_MODFDIS_OFFSET 4
+#define SPI_MR_MODFDIS_SIZE 1
+#define SPI_MR_MSTR 0
+#define SPI_MR_MSTR_MASK 0x00000001
+#define SPI_MR_MSTR_OFFSET 0
+#define SPI_MR_MSTR_SIZE 1
+#define SPI_MR_PCS 16
+#define SPI_MR_PCSDEC 2
+#define SPI_MR_PCSDEC_MASK 0x00000004
+#define SPI_MR_PCSDEC_OFFSET 2
+#define SPI_MR_PCSDEC_SIZE 1
+#define SPI_MR_PCS_MASK 0x000f0000
+#define SPI_MR_PCS_OFFSET 16
+#define SPI_MR_PCS_SIZE 4
+#define SPI_MR_PS 1
+#define SPI_MR_PS_MASK 0x00000002
+#define SPI_MR_PS_OFFSET 1
+#define SPI_MR_PS_SIZE 1
+#define SPI_MSTR 0
+#define SPI_MSTR_MASK 0x00000001
+#define SPI_MSTR_OFFSET 0
+#define SPI_MSTR_SIZE 1
+#define SPI_NCPHA 1
+#define SPI_NCPHA_MASK 0x00000002
+#define SPI_NCPHA_OFFSET 1
+#define SPI_NCPHA_SIZE 1
+#define SPI_NSSR 8
+#define SPI_NSSR_MASK 0x00000100
+#define SPI_NSSR_OFFSET 8
+#define SPI_NSSR_SIZE 1
+#define SPI_OVRES 3
+#define SPI_OVRES_MASK 0x00000008
+#define SPI_OVRES_OFFSET 3
+#define SPI_OVRES_SIZE 1
+#define SPI_PCS 16
+#define SPI_PCSDEC 2
+#define SPI_PCSDEC_MASK 0x00000004
+#define SPI_PCSDEC_OFFSET 2
+#define SPI_PCSDEC_SIZE 1
+#define SPI_PCS_MASK 0x000f0000
+#define SPI_PCS_OFFSET 16
+#define SPI_PCS_SIZE 4
+#define SPI_PS 1
+#define SPI_PS_MASK 0x00000002
+#define SPI_PS_OFFSET 1
+#define SPI_PS_SIZE 1
+#define SPI_PTCR 0x00000120
+#define SPI_PTCR_RXTDIS 1
+#define SPI_PTCR_RXTDIS_MASK 0x00000002
+#define SPI_PTCR_RXTDIS_OFFSET 1
+#define SPI_PTCR_RXTDIS_SIZE 1
+#define SPI_PTCR_RXTEN 0
+#define SPI_PTCR_RXTEN_MASK 0x00000001
+#define SPI_PTCR_RXTEN_OFFSET 0
+#define SPI_PTCR_RXTEN_SIZE 1
+#define SPI_PTCR_TXTDIS 9
+#define SPI_PTCR_TXTDIS_MASK 0x00000200
+#define SPI_PTCR_TXTDIS_OFFSET 9
+#define SPI_PTCR_TXTDIS_SIZE 1
+#define SPI_PTCR_TXTEN 8
+#define SPI_PTCR_TXTEN_MASK 0x00000100
+#define SPI_PTCR_TXTEN_OFFSET 8
+#define SPI_PTCR_TXTEN_SIZE 1
+#define SPI_PTSR 0x00000124
+#define SPI_PTSR_RXTEN 0
+#define SPI_PTSR_RXTEN_MASK 0x00000001
+#define SPI_PTSR_RXTEN_OFFSET 0
+#define SPI_PTSR_RXTEN_SIZE 1
+#define SPI_PTSR_TXTEN 8
+#define SPI_PTSR_TXTEN_MASK 0x00000100
+#define SPI_PTSR_TXTEN_OFFSET 8
+#define SPI_PTSR_TXTEN_SIZE 1
+#define SPI_RCR 0x00000104
+#define SPI_RCR_RXCTR 0
+#define SPI_RCR_RXCTR_MASK 0x0000ffff
+#define SPI_RCR_RXCTR_OFFSET 0
+#define SPI_RCR_RXCTR_SIZE 16
+#define SPI_RD 0
+#define SPI_RDR 0x00000008
+#define SPI_RDRF 0
+#define SPI_RDRF_MASK 0x00000001
+#define SPI_RDRF_OFFSET 0
+#define SPI_RDRF_SIZE 1
+#define SPI_RDR_PCS 16
+#define SPI_RDR_PCS_MASK 0x000f0000
+#define SPI_RDR_PCS_OFFSET 16
+#define SPI_RDR_PCS_SIZE 4
+#define SPI_RDR_RD 0
+#define SPI_RDR_RD_MASK 0x0000ffff
+#define SPI_RDR_RD_OFFSET 0
+#define SPI_RDR_RD_SIZE 16
+#define SPI_RD_MASK 0x0000ffff
+#define SPI_RD_OFFSET 0
+#define SPI_RD_SIZE 16
+#define SPI_RNCR 0x00000114
+#define SPI_RNCR_RXNCR 0
+#define SPI_RNCR_RXNCR_MASK 0x0000ffff
+#define SPI_RNCR_RXNCR_OFFSET 0
+#define SPI_RNCR_RXNCR_SIZE 16
+#define SPI_RNPR 0x00000110
+#define SPI_RPR 0x00000100
+#define SPI_RXBUFF 6
+#define SPI_RXBUFF_MASK 0x00000040
+#define SPI_RXBUFF_OFFSET 6
+#define SPI_RXBUFF_SIZE 1
+#define SPI_RXCTR 0
+#define SPI_RXCTR_MASK 0x0000ffff
+#define SPI_RXCTR_OFFSET 0
+#define SPI_RXCTR_SIZE 16
+#define SPI_RXNCR 0
+#define SPI_RXNCR_MASK 0x0000ffff
+#define SPI_RXNCR_OFFSET 0
+#define SPI_RXNCR_SIZE 16
+#define SPI_RXTDIS 1
+#define SPI_RXTDIS_MASK 0x00000002
+#define SPI_RXTDIS_OFFSET 1
+#define SPI_RXTDIS_SIZE 1
+#define SPI_RXTEN 0
+#define SPI_RXTEN_MASK 0x00000001
+#define SPI_RXTEN_OFFSET 0
+#define SPI_RXTEN_SIZE 1
+#define SPI_SCBR 8
+#define SPI_SCBR_MASK 0x0000ff00
+#define SPI_SCBR_OFFSET 8
+#define SPI_SCBR_SIZE 8
+#define SPI_SPIDIS 1
+#define SPI_SPIDIS_MASK 0x00000002
+#define SPI_SPIDIS_OFFSET 1
+#define SPI_SPIDIS_SIZE 1
+#define SPI_SPIEN 0
+#define SPI_SPIENS 16
+#define SPI_SPIENS_MASK 0x00010000
+#define SPI_SPIENS_OFFSET 16
+#define SPI_SPIENS_SIZE 1
+#define SPI_SPIEN_MASK 0x00000001
+#define SPI_SPIEN_OFFSET 0
+#define SPI_SPIEN_SIZE 1
+#define SPI_SR 0x00000010
+#define SPI_SR_ENDRX 4
+#define SPI_SR_ENDRX_MASK 0x00000010
+#define SPI_SR_ENDRX_OFFSET 4
+#define SPI_SR_ENDRX_SIZE 1
+#define SPI_SR_ENDTX 5
+#define SPI_SR_ENDTX_MASK 0x00000020
+#define SPI_SR_ENDTX_OFFSET 5
+#define SPI_SR_ENDTX_SIZE 1
+#define SPI_SR_MODF 2
+#define SPI_SR_MODF_MASK 0x00000004
+#define SPI_SR_MODF_OFFSET 2
+#define SPI_SR_MODF_SIZE 1
+#define SPI_SR_NSSR 8
+#define SPI_SR_NSSR_MASK 0x00000100
+#define SPI_SR_NSSR_OFFSET 8
+#define SPI_SR_NSSR_SIZE 1
+#define SPI_SR_OVRES 3
+#define SPI_SR_OVRES_MASK 0x00000008
+#define SPI_SR_OVRES_OFFSET 3
+#define SPI_SR_OVRES_SIZE 1
+#define SPI_SR_RDRF 0
+#define SPI_SR_RDRF_MASK 0x00000001
+#define SPI_SR_RDRF_OFFSET 0
+#define SPI_SR_RDRF_SIZE 1
+#define SPI_SR_RXBUFF 6
+#define SPI_SR_RXBUFF_MASK 0x00000040
+#define SPI_SR_RXBUFF_OFFSET 6
+#define SPI_SR_RXBUFF_SIZE 1
+#define SPI_SR_SPIENS 16
+#define SPI_SR_SPIENS_MASK 0x00010000
+#define SPI_SR_SPIENS_OFFSET 16
+#define SPI_SR_SPIENS_SIZE 1
+#define SPI_SR_TDRE 1
+#define SPI_SR_TDRE_MASK 0x00000002
+#define SPI_SR_TDRE_OFFSET 1
+#define SPI_SR_TDRE_SIZE 1
+#define SPI_SR_TXBUFE 7
+#define SPI_SR_TXBUFE_MASK 0x00000080
+#define SPI_SR_TXBUFE_OFFSET 7
+#define SPI_SR_TXBUFE_SIZE 1
+#define SPI_SR_TXEMPTY 9
+#define SPI_SR_TXEMPTY_MASK 0x00000200
+#define SPI_SR_TXEMPTY_OFFSET 9
+#define SPI_SR_TXEMPTY_SIZE 1
+#define SPI_SWRST 7
+#define SPI_SWRST_MASK 0x00000080
+#define SPI_SWRST_OFFSET 7
+#define SPI_SWRST_SIZE 1
+#define SPI_TCR 0x0000010c
+#define SPI_TCR_TXCTR 0
+#define SPI_TCR_TXCTR_MASK 0x0000ffff
+#define SPI_TCR_TXCTR_OFFSET 0
+#define SPI_TCR_TXCTR_SIZE 16
+#define SPI_TD 0
+#define SPI_TDR 0x0000000c
+#define SPI_TDRE 1
+#define SPI_TDRE_MASK 0x00000002
+#define SPI_TDRE_OFFSET 1
+#define SPI_TDRE_SIZE 1
+#define SPI_TDR_LASTXFER 24
+#define SPI_TDR_LASTXFER_MASK 0x01000000
+#define SPI_TDR_LASTXFER_OFFSET 24
+#define SPI_TDR_LASTXFER_SIZE 1
+#define SPI_TDR_PCS 16
+#define SPI_TDR_PCS_MASK 0x000f0000
+#define SPI_TDR_PCS_OFFSET 16
+#define SPI_TDR_PCS_SIZE 4
+#define SPI_TDR_TD 0
+#define SPI_TDR_TD_MASK 0x0000ffff
+#define SPI_TDR_TD_OFFSET 0
+#define SPI_TDR_TD_SIZE 16
+#define SPI_TD_MASK 0x0000ffff
+#define SPI_TD_OFFSET 0
+#define SPI_TD_SIZE 16
+#define SPI_TNCR 0x0000011c
+#define SPI_TNCR_TXNCR 0
+#define SPI_TNCR_TXNCR_MASK 0x0000ffff
+#define SPI_TNCR_TXNCR_OFFSET 0
+#define SPI_TNCR_TXNCR_SIZE 16
+#define SPI_TNPR 0x00000118
+#define SPI_TPR 0x00000108
+#define SPI_TXBUFE 7
+#define SPI_TXBUFE_MASK 0x00000080
+#define SPI_TXBUFE_OFFSET 7
+#define SPI_TXBUFE_SIZE 1
+#define SPI_TXCTR 0
+#define SPI_TXCTR_MASK 0x0000ffff
+#define SPI_TXCTR_OFFSET 0
+#define SPI_TXCTR_SIZE 16
+#define SPI_TXEMPTY 9
+#define SPI_TXEMPTY_MASK 0x00000200
+#define SPI_TXEMPTY_OFFSET 9
+#define SPI_TXEMPTY_SIZE 1
+#define SPI_TXNCR 0
+#define SPI_TXNCR_MASK 0x0000ffff
+#define SPI_TXNCR_OFFSET 0
+#define SPI_TXNCR_SIZE 16
+#define SPI_TXTDIS 9
+#define SPI_TXTDIS_MASK 0x00000200
+#define SPI_TXTDIS_OFFSET 9
+#define SPI_TXTDIS_SIZE 1
+#define SPI_TXTEN 8
+#define SPI_TXTEN_MASK 0x00000100
+#define SPI_TXTEN_OFFSET 8
+#define SPI_TXTEN_SIZE 1
+
+enum {
+ SPI_ERROR = -1,
+ SPI_OK = 0,
+ SPI_ERROR_TIMEOUT = 1,
+ SPI_ERROR_ARGUMENT,
+ SPI_ERROR_OVERRUN,
+ SPI_ERROR_MODE_FAULT,
+ SPI_ERROR_OVERRUN_AND_MODE_FAULT
+};
+
+struct spi_options_t {
+ unsigned char reg;
+ unsigned int baudrate;
+ unsigned char bits;
+ unsigned char spck_delay;
+ unsigned char trans_delay;
+ unsigned char stay_act;
+ unsigned char spi_mode;
+};
+
+struct spi_info {
+ void *regs;
+};
+
+int spi_select_chip(unsigned char chip);
+
+int spi_unselect_chip(unsigned char chip);
+
+int spi_setup_chip_reg(struct spi_options_t *options, unsigned int cpuHz);
+
+void spi_enable(void);
+
+void spi_disable(void);
+
+int spi_write(uchar *addr, int alen, uchar *buffer, int len);
+
+int spi_read(uchar *addr, int alen, uchar *buffer, int len);
+
+#define SPI_BIT(name) (1 << SPI_##name##_OFFSET)
+#define SPI_MKBF(name,value) (((value) & ((1 << SPI_##name##_SIZE) - 1)) << SPI_##name##_OFFSET)
+#define SPI_GETBF(name,value) (((value) >> SPI_##name##_OFFSET) & ((1 << SPI_##name##_SIZE) - 1))
+#define SPI_INSBF(name,value,old) (((old) & ~(((1 << SPI_##name##_SIZE) - 1) << SPI_##name##_OFFSET)) | SPI_MKBF(name, value))
+
+#define spi_readl(port,reg) readl((port)->regs + SPI_##reg)
+#define spi_writel(port,reg,value) writel((value), (port)->regs + SPI_##reg)
+
+#endif /* #ifndef __SPI_H_ */
diff -uprN u-boot-orig/drivers/atmel_spi.c u-boot/drivers/atmel_spi.c
--- u-boot-orig/drivers/atmel_spi.c 1970-01-01 01:00:00.000000000 +0100
+++ u-boot/drivers/atmel_spi.c 2007-01-03 10:01:26.000000000 +0100
@@ -0,0 +1,330 @@
+/*
+ * Copyright (C) 2004-2006 Atmel Corporation
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+
+#ifdef CONFIG_ATMEL_SPI
+
+#include <part.h>
+#include <malloc.h>
+#include <spi.h>
+#include <atmel_spi.h>
+
+#include <asm/io.h>
+#include <asm/errno.h>
+#include <asm/byteorder.h>
+
+#include <asm/arch/memory-map.h>
+#include <asm/arch/platform.h>
+
+
+struct spi_info *spi;
+
+void spi_reset(struct spi_info *spi);
+
+int get_baud_div(struct spi_options_t * options, int busHz);
+
+int spi_selection_mode(unsigned char variable_ps,
+ unsigned char pcs_decode,
+ unsigned char delay);
+
+void spi_reset(struct spi_info *spi)
+{
+ spi_writel(spi, CR, SPI_BIT(CR_SWRST));
+}
+
+void spi_init()
+{
+ const struct device *dev;
+
+#ifdef CFG_SPI0
+ dev = get_device(DEVICE_SPI0);
+#elif CFG_SPI1
+ dev = get_device(DEVICE_SPI1);
+#else
+#error No SPI device available
+#endif
+ if (!dev)
+ return;
+
+ spi = malloc(sizeof(struct spi_info));
+ if (!spi)
+ return;
+
+ spi->regs = dev->regs;
+
+ /* Reset */
+ spi_reset(spi);
+
+ /* Master Mode */
+ spi_writel(spi, MR, SPI_BIT(MR_MSTR)
+ |SPI_MR_PCS_MASK
+ |(0<<SPI_MR_FDIV_OFFSET)
+ |(0<<SPI_MR_MODFDIS_OFFSET));
+
+ /* Selection mode:
+ * no variable peripheral select
+ * no peripheral chip select decode
+ * 0 delay cycles after a chip select
+ */
+ if (!spi_selection_mode(0, 0, 0))
+ return;
+
+ debug("spi: controller at 0x%08x\n", spi->regs);
+}
+
+int spi_selection_mode(unsigned char variable_ps,
+ unsigned char pcs_decode,
+ unsigned char delay)
+{
+ if (variable_ps > 1 || pcs_decode > 1) {
+ return SPI_ERROR_ARGUMENT;
+ }
+
+ /* Unset bitfields */
+ spi_writel(spi, MR, spi_readl(spi, MR) &
+ ~(SPI_MR_PS_MASK|SPI_MR_PCSDEC_MASK
+ |SPI_MR_DLYBCS_MASK));
+ /* Set selction bits */
+ spi_writel(spi, MR, spi_readl(spi, MR)
+ |SPI_MKBF(MR_PS, variable_ps)
+ |SPI_MKBF(MR_PCSDEC, pcs_decode)
+ |SPI_MKBF(MR_DLYBCS, delay));
+
+ return SPI_OK;
+}
+
+int spi_select_chip(unsigned char chip)
+{
+ /* Assert all lines; no peripheral is selected */
+ spi_writel(spi, MR_PCS, spi_readl(spi, MR)|SPI_MR_PCS_MASK);
+
+ if (spi_readl(spi, MR) & SPI_MR_PCSDEC_MASK) {
+ ulong status;
+
+ /* The signal is decoded; allow up to 15 chips */
+ if (chip > 14) {
+ return SPI_ERROR_ARGUMENT;
+ }
+
+ status = spi_readl(spi, MR);
+ status &= ~SPI_MR_PCS_MASK;
+ status |= SPI_MKBF(MR_PCS, chip);
+ spi_writel(spi, MR, status);
+ } else {
+ if (chip > 3) {
+ return SPI_ERROR_ARGUMENT;
+ }
+
+ spi_writel(spi, MR, spi_readl(spi, MR) &
+ ~(1<<(SPI_MR_PCS_OFFSET + chip)));
+ }
+
+ debug("spi: chip select %d activated\n", chip);
+
+ return SPI_OK;
+}
+
+int spi_unselect_chip(unsigned char chip)
+{
+ /* Assert all lines; no peripheral is selected */
+ spi_writel(spi, MR, spi_readl(spi, MR)|SPI_MR_PCS_MASK);
+
+ /* Last transfer, so deassert the current NPCS if CSAAT is set */
+ spi_writel(spi, CR, spi_readl(spi, MR)|SPI_CR_LASTXFER_MASK);
+
+ debug("spi: chip select %d deactivated\n", chip);
+
+ return SPI_OK;
+}
+
+int spi_setup_chip_reg(struct spi_options_t *options,
+ unsigned int busHz)
+{
+ int baudDiv = -1;
+ unsigned long csr = 0;
+
+ if (options->bits > 16 || options->bits < 8 || options->stay_act > 1) {
+ return SPI_ERROR_ARGUMENT;
+ }
+
+ baudDiv = get_baud_div(options, busHz);
+
+ if (baudDiv < 0) {
+ return -baudDiv;
+ }
+
+ /* Will use CSR0 offsets; these are the same for CSR0 - CSR3 */
+ csr = ((options->bits - 8)<<SPI_CSR0_BITS_OFFSET)|
+ (baudDiv<<SPI_CSR0_SCBR_OFFSET)|
+ (options->spck_delay<<SPI_CSR0_DLYBS_OFFSET)|
+ (options->trans_delay<<SPI_CSR0_DLYBCT_OFFSET)|
+ (options->stay_act<<SPI_CSR0_CSAAT_OFFSET);
+
+ switch (options->spi_mode) {
+ case 0:
+ csr |= (1<<SPI_CSR0_NCPHA_OFFSET); /* pass through */
+ case 1:
+ break;
+ case 2:
+ csr |= (1<<SPI_CSR0_NCPHA_OFFSET); /* pass through */
+ case 3:
+ csr |= (1<<SPI_CSR0_CPOL_OFFSET);
+ break;
+ default: /* Not in legal range */
+ return SPI_ERROR_ARGUMENT;
+ }
+
+ switch (options->reg) {
+ case 0:
+ spi_writel(spi, CSR0, csr);
+ break;
+ case 1:
+ spi_writel(spi, CSR1, csr);
+ break;
+ case 2:
+ spi_writel(spi, CSR2, csr);
+ break;
+ case 3:
+ spi_writel(spi, CSR3, csr);
+ break;
+ default:
+ return SPI_ERROR_ARGUMENT;
+ }
+
+ debug("spi: chip select %d registered\n", options->reg);
+
+ return SPI_OK;
+}
+
+void spi_enable()
+{
+ spi_writel(spi, CR, SPI_BIT(CR_SPIEN));
+}
+
+void spi_disable()
+{
+ spi_writel(spi, CR, SPI_BIT(CR_SPIDIS));
+}
+
+int spi_write(uchar *addr, int alen, uchar *buffer, int len)
+{
+ int sent = 0;
+ uchar *addr_p = addr;
+ uchar *buffer_p = buffer;
+ unsigned int timeout = SPI_TIMEOUT;
+
+ if ((alen + len) <= 0)
+ return -SPI_ERROR_ARGUMENT;
+
+ do {
+ while (!(spi_readl(spi, SR) & SPI_BIT(SR_TXEMPTY)) && --timeout);
+ if (!timeout)
+ return -SPI_ERROR_TIMEOUT;
+ if (len > 0 || alen > 1)
+ spi_writel(spi, TDR, *addr_p++ & 0x0000FFFF);
+ else
+ spi_writel(spi, TDR, (*addr_p++ & 0x0000FFFF)
+ | SPI_BIT(TDR_LASTXFER));
+ sent++;
+ } while (--alen > 0);
+
+ timeout = SPI_TIMEOUT;
+
+ do {
+ while (!(spi_readl(spi, SR) & SPI_BIT(SR_TXEMPTY)) && --timeout);
+ if (!timeout)
+ return -SPI_ERROR_TIMEOUT;
+ if (len > 1)
+ spi_writel(spi, TDR, *buffer_p++ & 0x0000FFFF);
+ else
+ spi_writel(spi, TDR, (*buffer_p++ & 0x0000FFFF)
+ | SPI_BIT(TDR_LASTXFER));
+ sent++;
+ } while (--len > 0);
+
+ return sent;
+}
+
+int spi_read(uchar *addr, int alen, uchar *buffer, int len)
+{
+ int received = 0;
+ uchar *addr_p = addr;
+ uchar *buffer_p = buffer;
+ unsigned int timeout = SPI_TIMEOUT;
+
+ if ((alen + len) <= 0)
+ return SPI_ERROR_ARGUMENT;
+
+ do {
+ while (!(spi_readl(spi, SR) & SPI_BIT(SR_RDRF)) && --timeout);
+ if (!timeout)
+ return -SPI_ERROR_TIMEOUT;
+ *addr_p++ = spi_readl(spi, RDR) & 0x000000FF;
+ --alen;
+ received++;
+ } while (alen > 0);
+
+ timeout = SPI_TIMEOUT;
+
+ do {
+ while (!(spi_readl(spi, SR) & SPI_BIT(SR_RDRF)) && --timeout);
+ if (!timeout)
+ return -SPI_ERROR_TIMEOUT;
+ *buffer_p++ = spi_readl(spi, RDR) & 0x000000FF;
+ --len;
+ received++;
+ } while (len > 0);
+
+ return received;
+}
+
+int spi_xfer(spi_chipsel_type chipsel, int bitlen, uchar *dout, uchar *din)
+{
+ int len = 0;
+ uchar *dout_p = dout;
+ uchar *din_p = din;
+
+ while (--bitlen) {
+ if (spi_write(dout_p++, 1, 0, 0) != 1)
+ break;
+ if (spi_read(din_p++, 1, 0, 0) != 1)
+ break;
+ len++;
+ }
+
+ return len;
+}
+
+int get_baud_div(struct spi_options_t *options, int busHz) {
+ int baudDiv = 0;
+
+ baudDiv = busHz / options->baudrate;
+
+ if (baudDiv > (SPI_CSR0_SCBR_MASK<<SPI_CSR0_SCBR_OFFSET)
+ || baudDiv <= 0) {
+ return -SPI_ERROR_ARGUMENT;
+ }
+
+ return baudDiv;
+}
+
+#endif /* CONFIG_ATMEL_SPI */
diff -uprN u-boot-orig/drivers/Makefile u-boot/drivers/Makefile
--- u-boot-orig/drivers/Makefile 2007-01-01 19:26:46.000000000 +0100
+++ u-boot/drivers/Makefile 2007-01-01 16:10:49.000000000 +0100
@@ -28,7 +28,7 @@ include $(TOPDIR)/config.mk
LIB = libdrivers.a
OBJS = 3c589.o 5701rls.o ali512x.o \
- atmel_usart.o atmel_lcdc.o \
+ atmel_usart.o atmel_lcdc.o atmel_spi.o \
bcm570x.o bcm570x_autoneg.o cfb_console.o cfi_flash.o \
cs8900.o ct69000.o dataflash.o dc2114x.o dm9000x.o \
e1000.o eepro100.o \
|