initial commit
[freebsd-arm:freebsd-arm.git] / boot / arm / at91 / boot2 / bwct_board.c
1 #include <sys/cdefs.h>
2 __FBSDID("$FreeBSD$");
3
4 #include <sys/param.h>
5
6 #include "at91rm9200_lowlevel.h"
7 #include "at91rm9200.h"
8 #include "emac.h"
9 #include "lib.h"
10 #include "ee.h"
11 #include "board.h"
12 #include "sd-card.h"
13
14 unsigned char mac[6] = { 0x00, 0x0e, 0x42, 0x02, 0x00, 0x28 };
15
16 static void USART0_Init();
17 static void USART1_Init();
18 static void USART2_Init();
19 static void USART3_Init();
20 static void DS1672_Init();
21
22 static void
23 DS1672_Init() {
24         uint8_t buf[] = {0x00, 0xa9};
25
26         EEWrite(0xd0, buf, sizeof(buf));
27 }
28
29 static void
30 USART0_Init() {
31
32         AT91PS_PIO pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
33         AT91PS_PMC pPMC = (AT91PS_PMC)AT91C_BASE_PMC;
34
35         // setup GPIO
36         pPio->PIO_ASR = AT91C_PA17_TXD0 | AT91C_PA18_RXD0;
37         pPio->PIO_PDR = AT91C_PA17_TXD0 | AT91C_PA18_RXD0;
38
39         // enable power
40         pPMC->PMC_PCER = 1u << AT91C_ID_US0;
41 }
42
43 static void
44 USART1_Init() {
45
46         AT91PS_PIO pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
47         AT91PS_PMC pPMC = (AT91PS_PMC)AT91C_BASE_PMC;
48
49         // setup GPIO
50         pPio->PIO_ASR = AT91C_PB20_TXD1 | AT91C_PB21_RXD1;
51         pPio->PIO_PDR = AT91C_PB20_TXD1 | AT91C_PB21_RXD1;
52
53         // enable power
54         pPMC->PMC_PCER = 1u << AT91C_ID_US1;
55 }
56
57 static void
58 USART2_Init() {
59
60         AT91PS_PIO pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
61         AT91PS_PMC pPMC = (AT91PS_PMC)AT91C_BASE_PMC;
62
63         // setup GPIO
64         pPio->PIO_ASR = AT91C_PA23_TXD2 | AT91C_PA22_RXD2;
65         pPio->PIO_PDR = AT91C_PA23_TXD2 | AT91C_PA22_RXD2;
66
67         // enable power
68         pPMC->PMC_PCER = 1u << AT91C_ID_US2;
69 }
70
71 static void
72 USART3_Init() {
73
74         AT91PS_PIO pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
75         AT91PS_PMC pPMC = (AT91PS_PMC)AT91C_BASE_PMC;
76
77         // setup GPIO
78         pPio->PIO_BSR = AT91C_PA5_TXD3 | AT91C_PA6_RXD3;
79         pPio->PIO_PDR = AT91C_PA5_TXD3 | AT91C_PA6_RXD3;
80
81         // enable power
82         pPMC->PMC_PCER = 1u << AT91C_ID_US3;
83 }
84
85 void
86 board_init(void)
87 {
88
89         printf("\n\n");
90         printf("BWCT FSB-A920-1\n");
91         printf("http://www.bwct.de\n");
92         printf("\n");
93         printf("AT92RM9200 180MHz\n");
94         printf("Initialising USART0\n");
95         USART0_Init();
96         printf("Initialising USART1\n");
97         USART1_Init();
98         printf("Initialising USART2\n");
99         USART2_Init();
100         printf("Initialising USART3\n");
101         USART3_Init();
102         printf("Initialising TWI\n");
103         EEInit();
104         printf("Initialising DS1672\n");
105         DS1672_Init();
106         printf("Initialising Ethernet\n");
107         printf("MAC %x:%x:%x:%x:%x:%x\n", mac[0],
108             mac[1], mac[2], mac[3], mac[4], mac[5]);
109         EMAC_Init();
110         EMAC_SetMACAddress(mac);
111         printf("Initialising SD-card\n");
112         sdcard_init();
113 }
114
115 #include "../bootspi/ee.c"
116
117 int
118 drvread(void *buf, unsigned lba, unsigned nblk)
119 {
120     return (MCI_read((char *)buf, lba << 9, nblk << 9));
121 }