blob: 1e6a605672244e50c063b94d6cafcf439d15aaef [file] [log] [blame]
Timo Tuunainenea8d9892008-02-01 10:09:03 +00001/*
2 * (C) Copyright 2008
3 * Based on modifications by Alan Lu / Artila
4 * Author : Timo Tuunainen / Sysart
5 Kimmo Leppala / Sysart
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <at91rm9200_net.h>
28#include <dm9161.h>
29#include "m501sk.h"
30#include "net.h"
31
32#ifdef CONFIG_M501SK
33
34void m501sk_gpio_init(void)
35{
36 AT91C_BASE_PIOD->PIO_PER = 1 << (M501SK_DEBUG_LED1 - 96) |
37 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) |
38 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96);
39
40 AT91C_BASE_PIOD->PIO_OER = 1 << (M501SK_DEBUG_LED1 - 96) |
41 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) |
42 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96);
43
44 AT91C_BASE_PIOD->PIO_SODR = 1 << (M501SK_READY_LED - 96);
45 AT91C_BASE_PIOD->PIO_CODR = 1 << (M501SK_DEBUG_LED3 - 96);
46 AT91C_BASE_PIOB->PIO_PER = 1 << (M501SK_BUZZER - 32);
47 AT91C_BASE_PIOB->PIO_OER = 1 << (M501SK_BUZZER - 32);
48 AT91C_BASE_PIOC->PIO_PDR = (1 << 7) | (1 << 8);
49
50 /* Power OFF all USART's LEDs */
51 AT91C_BASE_PIOA->PIO_PER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
52 AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
53 AT91C_PA23_TXD2;
54
55 AT91C_BASE_PIOA->PIO_OER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
56 AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
57 AT91C_PA23_TXD2;
58
59 AT91C_BASE_PIOA->PIO_SODR = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 |
60 AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \
61 AT91C_PA23_TXD2;
62
63 AT91C_BASE_PIOB->PIO_PER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
64 AT91C_BASE_PIOB->PIO_OER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
65 AT91C_BASE_PIOB->PIO_SODR = AT91C_PB20_RXD1 | AT91C_PB21_TXD1;
66}
67
68uchar m501sk_gpio_set(M501SK_PIO io)
69{
70 uchar status = 0xff;
71 switch (io) {
72 case M501SK_DEBUG_LED1:
73 case M501SK_DEBUG_LED2:
74 case M501SK_DEBUG_LED3:
75 case M501SK_DEBUG_LED4:
76 case M501SK_READY_LED:
77 AT91C_BASE_PIOD->PIO_SODR = 1 << (io - 96);
78 status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96));
79 break;
80 case M501SK_BUZZER:
81 AT91C_BASE_PIOB->PIO_SODR = 1 << (io - 32);
82 status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32));
83 break;
84 }
85 return status;
86}
87
88uchar m501sk_gpio_clear(M501SK_PIO io)
89{
90 uchar status = 0xff;
91 switch (io) {
92 case M501SK_DEBUG_LED1:
93 case M501SK_DEBUG_LED2:
94 case M501SK_DEBUG_LED3:
95 case M501SK_DEBUG_LED4:
96 case M501SK_READY_LED:
97 AT91C_BASE_PIOD->PIO_CODR = 1 << (io - 96);
98 status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96));
99 break;
100 case M501SK_BUZZER:
101 AT91C_BASE_PIOB->PIO_CODR = 1 << (io - 32);
102 status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32));
103 break;
104 }
105 return status;
106}
107
Timo Tuunainenea8d9892008-02-01 10:09:03 +0000108/*
109 * Miscelaneous platform dependent initialisations
110 */
111DECLARE_GLOBAL_DATA_PTR;
112
113int board_init(void)
114{
115 /* Enable Ctrlc */
116 console_init_f();
117
118 /* Correct IRDA resistor problem */
119 /* Set PA23_TXD in Output */
120 ((AT91PS_PIO)AT91C_BASE_PIOA)->PIO_OER = AT91C_PA23_TXD2;
121
122 /* memory and cpu-speed are setup before relocation */
123 /* so we do _nothing_ here */
124 gd->bd->bi_arch_number = MACH_TYPE_M501;
125 /* adress of boot parameters */
126 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
127 m501sk_gpio_init();
128
129 /* Do interrupt init here, because flash needs timers */
Jean-Christophe PLAGNIOL-VILLARDb54384e2009-05-15 23:47:02 +0200130 timer_init();
Timo Tuunainenea8d9892008-02-01 10:09:03 +0000131 flash_init();
132
133 return 0;
134}
135
136int dram_init(void)
137{
138 int i = 0;
139 gd->bd->bi_dram[0].start = PHYS_SDRAM;
140 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
141
142 for (i = 0; i < 500; i++) {
143 m501sk_gpio_clear(M501SK_DEBUG_LED3);
144 m501sk_gpio_clear(M501SK_BUZZER);
145 udelay(250);
146 m501sk_gpio_set(M501SK_DEBUG_LED3);
147 m501sk_gpio_set(M501SK_BUZZER);
148 udelay(80);
149 }
150 m501sk_gpio_clear(M501SK_BUZZER);
151 m501sk_gpio_clear(M501SK_DEBUG_LED3);
152
153 return 0;
154}
155
156int board_late_init(void)
157{
158#if defined(CONFIG_CMD_NET)
159 eth_init(gd->bd);
160 eth_halt();
161#endif
162
163 /* Protect U-Boot, kernel & ramdisk memory addresses */
164 run_command("protect on 10000000 1041ffff", 0);
165 return 0;
166}
167
168#ifdef CONFIG_DRIVER_ETHER
169#if defined(CONFIG_CMD_NET)
170/*
171 * Name:
172 * at91rm9200_GetPhyInterface
173 * Description:
174 * Initialise the interface functions to the PHY
175 * Arguments:
176 * None
177 * Return value:
178 * None
179 */
180void at91rm9200_GetPhyInterface(AT91PS_PhyOps p_phyops)
181{
182 p_phyops->Init = dm9161_InitPhy;
183 p_phyops->IsPhyConnected = dm9161_IsPhyConnected;
184 p_phyops->GetLinkSpeed = dm9161_GetLinkSpeed;
185 p_phyops->AutoNegotiate = dm9161_AutoNegotiate;
186}
187#endif /* CONFIG_CMD_NET */
188#endif /* CONFIG_DRIVER_ETHER */
189#endif /* CONFIG_M501SK */