blob: 92185460a1ace1a5dd0a1ef7b0230c775585c0d0 [file] [log] [blame]
Bo Shen42aafb32012-07-05 17:21:46 +00001/*
2 * Copyright (C) 2012 Atmel Corporation
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <asm/arch/at91_common.h>
25#include <asm/arch/at91_pmc.h>
26#include <asm/arch/gpio.h>
27#include <asm/io.h>
28
29unsigned int get_chip_id(void)
30{
31 /* The 0x40 is the offset of cidr in DBGU */
32 return readl(ATMEL_BASE_DBGU + 0x40) & ~ARCH_ID_VERSION_MASK;
33}
34
35unsigned int get_extension_chip_id(void)
36{
37 /* The 0x44 is the offset of exid in DBGU */
38 return readl(ATMEL_BASE_DBGU + 0x44);
39}
40
41unsigned int has_emac1()
42{
43 return cpu_is_at91sam9x25();
44}
45
46unsigned int has_emac0()
47{
48 return !(cpu_is_at91sam9g15());
49}
50
51unsigned int has_lcdc()
52{
53 return cpu_is_at91sam9g15() || cpu_is_at91sam9g35()
54 || cpu_is_at91sam9x35();
55}
56
57char *get_cpu_name()
58{
59 unsigned int extension_id = get_extension_chip_id();
60
61 if (cpu_is_at91sam9x5()) {
62 switch (extension_id) {
63 case ARCH_EXID_AT91SAM9G15:
Bo Shenc3575b32013-03-07 21:23:22 +000064 return "AT91SAM9G15";
Bo Shen42aafb32012-07-05 17:21:46 +000065 case ARCH_EXID_AT91SAM9G25:
Bo Shenc3575b32013-03-07 21:23:22 +000066 return "AT91SAM9G25";
Bo Shen42aafb32012-07-05 17:21:46 +000067 case ARCH_EXID_AT91SAM9G35:
Bo Shenc3575b32013-03-07 21:23:22 +000068 return "AT91SAM9G35";
Bo Shen42aafb32012-07-05 17:21:46 +000069 case ARCH_EXID_AT91SAM9X25:
Bo Shenc3575b32013-03-07 21:23:22 +000070 return "AT91SAM9X25";
Bo Shen42aafb32012-07-05 17:21:46 +000071 case ARCH_EXID_AT91SAM9X35:
Bo Shenc3575b32013-03-07 21:23:22 +000072 return "AT91SAM9X35";
Bo Shen42aafb32012-07-05 17:21:46 +000073 default:
Bo Shenc3575b32013-03-07 21:23:22 +000074 return "Unknown CPU type";
Bo Shen42aafb32012-07-05 17:21:46 +000075 }
76 } else {
Bo Shenc3575b32013-03-07 21:23:22 +000077 return "Unknown CPU type";
Bo Shen42aafb32012-07-05 17:21:46 +000078 }
79}
80
81void at91_seriald_hw_init(void)
82{
83 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
84
85 at91_set_a_periph(AT91_PIO_PORTA, 9, 0); /* DRXD */
86 at91_set_a_periph(AT91_PIO_PORTA, 10, 1); /* DTXD */
87
88 writel(1 << ATMEL_ID_SYS, &pmc->pcer);
89}
90
91void at91_serial0_hw_init(void)
92{
93 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
94
95 at91_set_a_periph(AT91_PIO_PORTA, 0, 1); /* TXD */
96 at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* RXD */
97
98 writel(1 << ATMEL_ID_USART0, &pmc->pcer);
99}
100
101void at91_serial1_hw_init(void)
102{
103 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
104
105 at91_set_a_periph(AT91_PIO_PORTA, 5, 1); /* TXD */
106 at91_set_a_periph(AT91_PIO_PORTA, 6, 0); /* RXD */
107
108 writel(1 << ATMEL_ID_USART1, &pmc->pcer);
109}
110
111void at91_serial2_hw_init(void)
112{
113 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
114
115 at91_set_a_periph(AT91_PIO_PORTA, 7, 1); /* TXD */
116 at91_set_a_periph(AT91_PIO_PORTA, 8, 0); /* RXD */
117
118 writel(1 << ATMEL_ID_USART2, &pmc->pcer);
119}
120
Wu, Joshe32c6612012-09-13 22:22:05 +0000121void at91_mci_hw_init(void)
122{
123 /* Initialize the MCI0 */
124 at91_set_a_periph(AT91_PIO_PORTA, 17, 1); /* MCCK */
125 at91_set_a_periph(AT91_PIO_PORTA, 16, 1); /* MCCDA */
126 at91_set_a_periph(AT91_PIO_PORTA, 15, 1); /* MCDA0 */
127 at91_set_a_periph(AT91_PIO_PORTA, 18, 1); /* MCDA1 */
128 at91_set_a_periph(AT91_PIO_PORTA, 19, 1); /* MCDA2 */
129 at91_set_a_periph(AT91_PIO_PORTA, 20, 1); /* MCDA3 */
130
131 /* Enable clock for MCI0 */
132 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
133 writel(1 << ATMEL_ID_HSMCI0, &pmc->pcer);
134}
135
Bo Shen42aafb32012-07-05 17:21:46 +0000136#ifdef CONFIG_ATMEL_SPI
137void at91_spi0_hw_init(unsigned long cs_mask)
138{
Bo Shen2e383ad2012-08-19 20:32:23 +0000139 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Bo Shen42aafb32012-07-05 17:21:46 +0000140
141 at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* SPI0_MISO */
142 at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* SPI0_MOSI */
143 at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* SPI0_SPCK */
144
145 /* Enable clock */
146 writel(1 << ATMEL_ID_SPI0, &pmc->pcer);
147
148 if (cs_mask & (1 << 0))
149 at91_set_a_periph(AT91_PIO_PORTA, 14, 0);
150 if (cs_mask & (1 << 1))
151 at91_set_b_periph(AT91_PIO_PORTA, 7, 0);
152 if (cs_mask & (1 << 2))
153 at91_set_b_periph(AT91_PIO_PORTA, 1, 0);
154 if (cs_mask & (1 << 3))
155 at91_set_b_periph(AT91_PIO_PORTB, 3, 0);
156 if (cs_mask & (1 << 4))
157 at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
158 if (cs_mask & (1 << 5))
159 at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
160 if (cs_mask & (1 << 6))
161 at91_set_pio_output(AT91_PIO_PORTA, 1, 0);
162 if (cs_mask & (1 << 7))
163 at91_set_pio_output(AT91_PIO_PORTB, 3, 0);
164}
165
166void at91_spi1_hw_init(unsigned long cs_mask)
167{
Bo Shen2e383ad2012-08-19 20:32:23 +0000168 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Bo Shen42aafb32012-07-05 17:21:46 +0000169
170 at91_set_b_periph(AT91_PIO_PORTA, 21, 0); /* SPI1_MISO */
171 at91_set_b_periph(AT91_PIO_PORTA, 22, 0); /* SPI1_MOSI */
172 at91_set_b_periph(AT91_PIO_PORTA, 23, 0); /* SPI1_SPCK */
173
174 /* Enable clock */
175 writel(1 << ATMEL_ID_SPI1, &pmc->pcer);
176
177 if (cs_mask & (1 << 0))
178 at91_set_b_periph(AT91_PIO_PORTA, 8, 0);
179 if (cs_mask & (1 << 1))
180 at91_set_b_periph(AT91_PIO_PORTA, 0, 0);
181 if (cs_mask & (1 << 2))
182 at91_set_b_periph(AT91_PIO_PORTA, 31, 0);
183 if (cs_mask & (1 << 3))
184 at91_set_b_periph(AT91_PIO_PORTA, 30, 0);
185 if (cs_mask & (1 << 4))
186 at91_set_pio_output(AT91_PIO_PORTA, 8, 0);
187 if (cs_mask & (1 << 5))
188 at91_set_pio_output(AT91_PIO_PORTA, 0, 0);
189 if (cs_mask & (1 << 6))
190 at91_set_pio_output(AT91_PIO_PORTA, 31, 0);
191 if (cs_mask & (1 << 7))
192 at91_set_pio_output(AT91_PIO_PORTA, 30, 0);
193}
194#endif
195
Richard Genoudb762a9c2012-11-29 23:18:32 +0000196#if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI)
197void at91_uhp_hw_init(void)
198{
199 /* Enable VBus on UHP ports */
200 at91_set_pio_output(AT91_PIO_PORTD, 18, 0); /* port A */
201 at91_set_pio_output(AT91_PIO_PORTD, 19, 0); /* port B */
202#if defined(CONFIG_USB_OHCI_NEW)
203 /* port C is OHCI only */
204 at91_set_pio_output(AT91_PIO_PORTD, 20, 0); /* port C */
205#endif
206}
207#endif
208
Bo Shen42aafb32012-07-05 17:21:46 +0000209#ifdef CONFIG_MACB
210void at91_macb_hw_init(void)
211{
212 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
213
214 if (has_emac0()) {
215 /* Enable EMAC0 clock */
216 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
217 /* EMAC0 pins setup */
218 at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* ETXCK */
219 at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* ERXDV */
220 at91_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ERX0 */
221 at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* ERX1 */
222 at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ERXER */
223 at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ETXEN */
224 at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ETX0 */
225 at91_set_a_periph(AT91_PIO_PORTB, 10, 0); /* ETX1 */
226 at91_set_a_periph(AT91_PIO_PORTB, 5, 0); /* EMDIO */
227 at91_set_a_periph(AT91_PIO_PORTB, 6, 0); /* EMDC */
228 }
229
230 if (has_emac1()) {
231 /* Enable EMAC1 clock */
232 writel(1 << ATMEL_ID_EMAC1, &pmc->pcer);
233 /* EMAC1 pins setup */
234 at91_set_b_periph(AT91_PIO_PORTC, 29, 0); /* ETXCK */
235 at91_set_b_periph(AT91_PIO_PORTC, 28, 0); /* ECRSDV */
236 at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ERXO */
237 at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ERX1 */
238 at91_set_b_periph(AT91_PIO_PORTC, 16, 0); /* ERXER */
239 at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ETXEN */
240 at91_set_b_periph(AT91_PIO_PORTC, 18, 0); /* ETX0 */
241 at91_set_b_periph(AT91_PIO_PORTC, 19, 0); /* ETX1 */
242 at91_set_b_periph(AT91_PIO_PORTC, 31, 0); /* EMDIO */
243 at91_set_b_periph(AT91_PIO_PORTC, 30, 0); /* EMDC */
244 }
245
246#ifndef CONFIG_RMII
247 /* Only emac0 support MII */
248 if (has_emac0()) {
Jesse Gilles6ad5ac72013-02-27 23:42:49 +0000249 at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* ECRS */
250 at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* ECOL */
251 at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ERX2 */
252 at91_set_a_periph(AT91_PIO_PORTB, 14, 0); /* ERX3 */
253 at91_set_a_periph(AT91_PIO_PORTB, 15, 0); /* ERXCK */
254 at91_set_a_periph(AT91_PIO_PORTB, 11, 0); /* ETX2 */
255 at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX3 */
256 at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ETXER */
Bo Shen42aafb32012-07-05 17:21:46 +0000257 }
258#endif
259}
260#endif