blob: 3e4555a1a1222f99dc05067c7ded0d338b3d1e90 [file] [log] [blame]
Bo Shen42aafb32012-07-05 17:21:46 +00001/*
2 * Copyright (C) 2012 Atmel Corporation
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Bo Shen42aafb32012-07-05 17:21:46 +00005 */
6
7#include <common.h>
8#include <asm/arch/at91_common.h>
Wenyou Yang57b7f292016-02-03 10:16:49 +08009#include <asm/arch/clk.h>
Bo Shen42aafb32012-07-05 17:21:46 +000010#include <asm/arch/gpio.h>
11#include <asm/io.h>
12
13unsigned int get_chip_id(void)
14{
15 /* The 0x40 is the offset of cidr in DBGU */
16 return readl(ATMEL_BASE_DBGU + 0x40) & ~ARCH_ID_VERSION_MASK;
17}
18
19unsigned int get_extension_chip_id(void)
20{
21 /* The 0x44 is the offset of exid in DBGU */
22 return readl(ATMEL_BASE_DBGU + 0x44);
23}
24
25unsigned int has_emac1()
26{
27 return cpu_is_at91sam9x25();
28}
29
30unsigned int has_emac0()
31{
32 return !(cpu_is_at91sam9g15());
33}
34
35unsigned int has_lcdc()
36{
37 return cpu_is_at91sam9g15() || cpu_is_at91sam9g35()
38 || cpu_is_at91sam9x35();
39}
40
41char *get_cpu_name()
42{
43 unsigned int extension_id = get_extension_chip_id();
44
45 if (cpu_is_at91sam9x5()) {
46 switch (extension_id) {
47 case ARCH_EXID_AT91SAM9G15:
Bo Shenc3575b32013-03-07 21:23:22 +000048 return "AT91SAM9G15";
Bo Shen42aafb32012-07-05 17:21:46 +000049 case ARCH_EXID_AT91SAM9G25:
Bo Shenc3575b32013-03-07 21:23:22 +000050 return "AT91SAM9G25";
Bo Shen42aafb32012-07-05 17:21:46 +000051 case ARCH_EXID_AT91SAM9G35:
Bo Shenc3575b32013-03-07 21:23:22 +000052 return "AT91SAM9G35";
Bo Shen42aafb32012-07-05 17:21:46 +000053 case ARCH_EXID_AT91SAM9X25:
Bo Shenc3575b32013-03-07 21:23:22 +000054 return "AT91SAM9X25";
Bo Shen42aafb32012-07-05 17:21:46 +000055 case ARCH_EXID_AT91SAM9X35:
Bo Shenc3575b32013-03-07 21:23:22 +000056 return "AT91SAM9X35";
Bo Shen42aafb32012-07-05 17:21:46 +000057 default:
Bo Shenc3575b32013-03-07 21:23:22 +000058 return "Unknown CPU type";
Bo Shen42aafb32012-07-05 17:21:46 +000059 }
60 } else {
Bo Shenc3575b32013-03-07 21:23:22 +000061 return "Unknown CPU type";
Bo Shen42aafb32012-07-05 17:21:46 +000062 }
63}
64
65void at91_seriald_hw_init(void)
66{
Bo Shen42aafb32012-07-05 17:21:46 +000067 at91_set_a_periph(AT91_PIO_PORTA, 9, 0); /* DRXD */
68 at91_set_a_periph(AT91_PIO_PORTA, 10, 1); /* DTXD */
69
Wenyou Yang57b7f292016-02-03 10:16:49 +080070 at91_periph_clk_enable(ATMEL_ID_SYS);
Bo Shen42aafb32012-07-05 17:21:46 +000071}
72
73void at91_serial0_hw_init(void)
74{
Bo Shen42aafb32012-07-05 17:21:46 +000075 at91_set_a_periph(AT91_PIO_PORTA, 0, 1); /* TXD */
76 at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* RXD */
77
Wenyou Yang57b7f292016-02-03 10:16:49 +080078 at91_periph_clk_enable(ATMEL_ID_USART0);
Bo Shen42aafb32012-07-05 17:21:46 +000079}
80
81void at91_serial1_hw_init(void)
82{
Bo Shen42aafb32012-07-05 17:21:46 +000083 at91_set_a_periph(AT91_PIO_PORTA, 5, 1); /* TXD */
84 at91_set_a_periph(AT91_PIO_PORTA, 6, 0); /* RXD */
85
Wenyou Yang57b7f292016-02-03 10:16:49 +080086 at91_periph_clk_enable(ATMEL_ID_USART1);
Bo Shen42aafb32012-07-05 17:21:46 +000087}
88
89void at91_serial2_hw_init(void)
90{
Bo Shen42aafb32012-07-05 17:21:46 +000091 at91_set_a_periph(AT91_PIO_PORTA, 7, 1); /* TXD */
92 at91_set_a_periph(AT91_PIO_PORTA, 8, 0); /* RXD */
93
Wenyou Yang57b7f292016-02-03 10:16:49 +080094 at91_periph_clk_enable(ATMEL_ID_USART2);
Bo Shen42aafb32012-07-05 17:21:46 +000095}
96
Wu, Joshe32c6612012-09-13 22:22:05 +000097void at91_mci_hw_init(void)
98{
99 /* Initialize the MCI0 */
100 at91_set_a_periph(AT91_PIO_PORTA, 17, 1); /* MCCK */
101 at91_set_a_periph(AT91_PIO_PORTA, 16, 1); /* MCCDA */
102 at91_set_a_periph(AT91_PIO_PORTA, 15, 1); /* MCDA0 */
103 at91_set_a_periph(AT91_PIO_PORTA, 18, 1); /* MCDA1 */
104 at91_set_a_periph(AT91_PIO_PORTA, 19, 1); /* MCDA2 */
105 at91_set_a_periph(AT91_PIO_PORTA, 20, 1); /* MCDA3 */
106
Wenyou Yang57b7f292016-02-03 10:16:49 +0800107 at91_periph_clk_enable(ATMEL_ID_HSMCI0);
Wu, Joshe32c6612012-09-13 22:22:05 +0000108}
109
Bo Shen42aafb32012-07-05 17:21:46 +0000110#ifdef CONFIG_ATMEL_SPI
111void at91_spi0_hw_init(unsigned long cs_mask)
112{
Bo Shen42aafb32012-07-05 17:21:46 +0000113 at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* SPI0_MISO */
114 at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* SPI0_MOSI */
115 at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* SPI0_SPCK */
116
Wenyou Yang57b7f292016-02-03 10:16:49 +0800117 at91_periph_clk_enable(ATMEL_ID_SPI0);
Bo Shen42aafb32012-07-05 17:21:46 +0000118
119 if (cs_mask & (1 << 0))
120 at91_set_a_periph(AT91_PIO_PORTA, 14, 0);
121 if (cs_mask & (1 << 1))
122 at91_set_b_periph(AT91_PIO_PORTA, 7, 0);
123 if (cs_mask & (1 << 2))
124 at91_set_b_periph(AT91_PIO_PORTA, 1, 0);
125 if (cs_mask & (1 << 3))
126 at91_set_b_periph(AT91_PIO_PORTB, 3, 0);
127 if (cs_mask & (1 << 4))
128 at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
129 if (cs_mask & (1 << 5))
130 at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
131 if (cs_mask & (1 << 6))
132 at91_set_pio_output(AT91_PIO_PORTA, 1, 0);
133 if (cs_mask & (1 << 7))
134 at91_set_pio_output(AT91_PIO_PORTB, 3, 0);
135}
136
137void at91_spi1_hw_init(unsigned long cs_mask)
138{
Bo Shen42aafb32012-07-05 17:21:46 +0000139 at91_set_b_periph(AT91_PIO_PORTA, 21, 0); /* SPI1_MISO */
140 at91_set_b_periph(AT91_PIO_PORTA, 22, 0); /* SPI1_MOSI */
141 at91_set_b_periph(AT91_PIO_PORTA, 23, 0); /* SPI1_SPCK */
142
Wenyou Yang57b7f292016-02-03 10:16:49 +0800143 at91_periph_clk_enable(ATMEL_ID_SPI1);
Bo Shen42aafb32012-07-05 17:21:46 +0000144
145 if (cs_mask & (1 << 0))
146 at91_set_b_periph(AT91_PIO_PORTA, 8, 0);
147 if (cs_mask & (1 << 1))
148 at91_set_b_periph(AT91_PIO_PORTA, 0, 0);
149 if (cs_mask & (1 << 2))
150 at91_set_b_periph(AT91_PIO_PORTA, 31, 0);
151 if (cs_mask & (1 << 3))
152 at91_set_b_periph(AT91_PIO_PORTA, 30, 0);
153 if (cs_mask & (1 << 4))
154 at91_set_pio_output(AT91_PIO_PORTA, 8, 0);
155 if (cs_mask & (1 << 5))
156 at91_set_pio_output(AT91_PIO_PORTA, 0, 0);
157 if (cs_mask & (1 << 6))
158 at91_set_pio_output(AT91_PIO_PORTA, 31, 0);
159 if (cs_mask & (1 << 7))
160 at91_set_pio_output(AT91_PIO_PORTA, 30, 0);
161}
162#endif
163
Richard Genoudb762a9c2012-11-29 23:18:32 +0000164#if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI)
165void at91_uhp_hw_init(void)
166{
167 /* Enable VBus on UHP ports */
168 at91_set_pio_output(AT91_PIO_PORTD, 18, 0); /* port A */
169 at91_set_pio_output(AT91_PIO_PORTD, 19, 0); /* port B */
170#if defined(CONFIG_USB_OHCI_NEW)
171 /* port C is OHCI only */
172 at91_set_pio_output(AT91_PIO_PORTD, 20, 0); /* port C */
173#endif
174}
175#endif
176
Bo Shen42aafb32012-07-05 17:21:46 +0000177#ifdef CONFIG_MACB
178void at91_macb_hw_init(void)
179{
Bo Shen42aafb32012-07-05 17:21:46 +0000180 if (has_emac0()) {
181 /* Enable EMAC0 clock */
Wenyou Yang57b7f292016-02-03 10:16:49 +0800182 at91_periph_clk_enable(ATMEL_ID_EMAC0);
Bo Shen42aafb32012-07-05 17:21:46 +0000183 /* EMAC0 pins setup */
184 at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* ETXCK */
185 at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* ERXDV */
186 at91_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ERX0 */
187 at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* ERX1 */
188 at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ERXER */
189 at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ETXEN */
190 at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ETX0 */
191 at91_set_a_periph(AT91_PIO_PORTB, 10, 0); /* ETX1 */
192 at91_set_a_periph(AT91_PIO_PORTB, 5, 0); /* EMDIO */
193 at91_set_a_periph(AT91_PIO_PORTB, 6, 0); /* EMDC */
194 }
195
196 if (has_emac1()) {
197 /* Enable EMAC1 clock */
Wenyou Yang57b7f292016-02-03 10:16:49 +0800198 at91_periph_clk_enable(ATMEL_ID_EMAC1);
Bo Shen42aafb32012-07-05 17:21:46 +0000199 /* EMAC1 pins setup */
200 at91_set_b_periph(AT91_PIO_PORTC, 29, 0); /* ETXCK */
201 at91_set_b_periph(AT91_PIO_PORTC, 28, 0); /* ECRSDV */
202 at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ERXO */
203 at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ERX1 */
204 at91_set_b_periph(AT91_PIO_PORTC, 16, 0); /* ERXER */
205 at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ETXEN */
206 at91_set_b_periph(AT91_PIO_PORTC, 18, 0); /* ETX0 */
207 at91_set_b_periph(AT91_PIO_PORTC, 19, 0); /* ETX1 */
208 at91_set_b_periph(AT91_PIO_PORTC, 31, 0); /* EMDIO */
209 at91_set_b_periph(AT91_PIO_PORTC, 30, 0); /* EMDC */
210 }
211
212#ifndef CONFIG_RMII
213 /* Only emac0 support MII */
214 if (has_emac0()) {
Jesse Gilles6ad5ac72013-02-27 23:42:49 +0000215 at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* ECRS */
216 at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* ECOL */
217 at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ERX2 */
218 at91_set_a_periph(AT91_PIO_PORTB, 14, 0); /* ERX3 */
219 at91_set_a_periph(AT91_PIO_PORTB, 15, 0); /* ERXCK */
220 at91_set_a_periph(AT91_PIO_PORTB, 11, 0); /* ETX2 */
221 at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX3 */
222 at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ETXER */
Bo Shen42aafb32012-07-05 17:21:46 +0000223 }
224#endif
225}
226#endif