blob: 40c8a58b5635489a7e9e1f8072c81279f165eb11 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bo Shen42aafb32012-07-05 17:21:46 +00002/*
3 * Copyright (C) 2012 Atmel Corporation
Bo Shen42aafb32012-07-05 17:21:46 +00004 */
5
Bo Shen42aafb32012-07-05 17:21:46 +00006#include <asm/arch/at91_common.h>
Wenyou Yang57b7f292016-02-03 10:16:49 +08007#include <asm/arch/clk.h>
Bo Shen42aafb32012-07-05 17:21:46 +00008#include <asm/arch/gpio.h>
9#include <asm/io.h>
10
11unsigned int get_chip_id(void)
12{
13 /* The 0x40 is the offset of cidr in DBGU */
14 return readl(ATMEL_BASE_DBGU + 0x40) & ~ARCH_ID_VERSION_MASK;
15}
16
17unsigned int get_extension_chip_id(void)
18{
19 /* The 0x44 is the offset of exid in DBGU */
20 return readl(ATMEL_BASE_DBGU + 0x44);
21}
22
23unsigned int has_emac1()
24{
25 return cpu_is_at91sam9x25();
26}
27
28unsigned int has_emac0()
29{
30 return !(cpu_is_at91sam9g15());
31}
32
33unsigned int has_lcdc()
34{
35 return cpu_is_at91sam9g15() || cpu_is_at91sam9g35()
36 || cpu_is_at91sam9x35();
37}
38
39char *get_cpu_name()
40{
41 unsigned int extension_id = get_extension_chip_id();
42
43 if (cpu_is_at91sam9x5()) {
44 switch (extension_id) {
45 case ARCH_EXID_AT91SAM9G15:
Bo Shenc3575b32013-03-07 21:23:22 +000046 return "AT91SAM9G15";
Bo Shen42aafb32012-07-05 17:21:46 +000047 case ARCH_EXID_AT91SAM9G25:
Bo Shenc3575b32013-03-07 21:23:22 +000048 return "AT91SAM9G25";
Bo Shen42aafb32012-07-05 17:21:46 +000049 case ARCH_EXID_AT91SAM9G35:
Bo Shenc3575b32013-03-07 21:23:22 +000050 return "AT91SAM9G35";
Bo Shen42aafb32012-07-05 17:21:46 +000051 case ARCH_EXID_AT91SAM9X25:
Bo Shenc3575b32013-03-07 21:23:22 +000052 return "AT91SAM9X25";
Bo Shen42aafb32012-07-05 17:21:46 +000053 case ARCH_EXID_AT91SAM9X35:
Bo Shenc3575b32013-03-07 21:23:22 +000054 return "AT91SAM9X35";
Bo Shen42aafb32012-07-05 17:21:46 +000055 default:
Bo Shenc3575b32013-03-07 21:23:22 +000056 return "Unknown CPU type";
Bo Shen42aafb32012-07-05 17:21:46 +000057 }
58 } else {
Bo Shenc3575b32013-03-07 21:23:22 +000059 return "Unknown CPU type";
Bo Shen42aafb32012-07-05 17:21:46 +000060 }
61}
62
63void at91_seriald_hw_init(void)
64{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080065 at91_pio3_set_a_periph(AT91_PIO_PORTA, 9, 0); /* DRXD */
66 at91_pio3_set_a_periph(AT91_PIO_PORTA, 10, 1); /* DTXD */
Bo Shen42aafb32012-07-05 17:21:46 +000067
Wenyou Yang57b7f292016-02-03 10:16:49 +080068 at91_periph_clk_enable(ATMEL_ID_SYS);
Bo Shen42aafb32012-07-05 17:21:46 +000069}
70
71void at91_serial0_hw_init(void)
72{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080073 at91_pio3_set_a_periph(AT91_PIO_PORTA, 0, 1); /* TXD */
74 at91_pio3_set_a_periph(AT91_PIO_PORTA, 1, 0); /* RXD */
Bo Shen42aafb32012-07-05 17:21:46 +000075
Wenyou Yang57b7f292016-02-03 10:16:49 +080076 at91_periph_clk_enable(ATMEL_ID_USART0);
Bo Shen42aafb32012-07-05 17:21:46 +000077}
78
79void at91_serial1_hw_init(void)
80{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080081 at91_pio3_set_a_periph(AT91_PIO_PORTA, 5, 1); /* TXD */
82 at91_pio3_set_a_periph(AT91_PIO_PORTA, 6, 0); /* RXD */
Bo Shen42aafb32012-07-05 17:21:46 +000083
Wenyou Yang57b7f292016-02-03 10:16:49 +080084 at91_periph_clk_enable(ATMEL_ID_USART1);
Bo Shen42aafb32012-07-05 17:21:46 +000085}
86
87void at91_serial2_hw_init(void)
88{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080089 at91_pio3_set_a_periph(AT91_PIO_PORTA, 7, 1); /* TXD */
90 at91_pio3_set_a_periph(AT91_PIO_PORTA, 8, 0); /* RXD */
Bo Shen42aafb32012-07-05 17:21:46 +000091
Wenyou Yang57b7f292016-02-03 10:16:49 +080092 at91_periph_clk_enable(ATMEL_ID_USART2);
Bo Shen42aafb32012-07-05 17:21:46 +000093}
94
Wu, Joshe32c6612012-09-13 22:22:05 +000095void at91_mci_hw_init(void)
96{
97 /* Initialize the MCI0 */
Wenyou Yang4a92a3e2017-03-23 12:44:36 +080098 at91_pio3_set_a_periph(AT91_PIO_PORTA, 17, 1); /* MCCK */
99 at91_pio3_set_a_periph(AT91_PIO_PORTA, 16, 1); /* MCCDA */
100 at91_pio3_set_a_periph(AT91_PIO_PORTA, 15, 1); /* MCDA0 */
101 at91_pio3_set_a_periph(AT91_PIO_PORTA, 18, 1); /* MCDA1 */
102 at91_pio3_set_a_periph(AT91_PIO_PORTA, 19, 1); /* MCDA2 */
103 at91_pio3_set_a_periph(AT91_PIO_PORTA, 20, 1); /* MCDA3 */
Wu, Joshe32c6612012-09-13 22:22:05 +0000104
Wenyou Yang57b7f292016-02-03 10:16:49 +0800105 at91_periph_clk_enable(ATMEL_ID_HSMCI0);
Wu, Joshe32c6612012-09-13 22:22:05 +0000106}
107
Bo Shen42aafb32012-07-05 17:21:46 +0000108#ifdef CONFIG_ATMEL_SPI
109void at91_spi0_hw_init(unsigned long cs_mask)
110{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800111 at91_pio3_set_a_periph(AT91_PIO_PORTA, 11, 0); /* SPI0_MISO */
112 at91_pio3_set_a_periph(AT91_PIO_PORTA, 12, 0); /* SPI0_MOSI */
113 at91_pio3_set_a_periph(AT91_PIO_PORTA, 13, 0); /* SPI0_SPCK */
Bo Shen42aafb32012-07-05 17:21:46 +0000114
Wenyou Yang57b7f292016-02-03 10:16:49 +0800115 at91_periph_clk_enable(ATMEL_ID_SPI0);
Bo Shen42aafb32012-07-05 17:21:46 +0000116
117 if (cs_mask & (1 << 0))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800118 at91_pio3_set_a_periph(AT91_PIO_PORTA, 14, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000119 if (cs_mask & (1 << 1))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800120 at91_pio3_set_b_periph(AT91_PIO_PORTA, 7, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000121 if (cs_mask & (1 << 2))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800122 at91_pio3_set_b_periph(AT91_PIO_PORTA, 1, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000123 if (cs_mask & (1 << 3))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800124 at91_pio3_set_b_periph(AT91_PIO_PORTB, 3, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000125 if (cs_mask & (1 << 4))
126 at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
127 if (cs_mask & (1 << 5))
128 at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
129 if (cs_mask & (1 << 6))
130 at91_set_pio_output(AT91_PIO_PORTA, 1, 0);
131 if (cs_mask & (1 << 7))
132 at91_set_pio_output(AT91_PIO_PORTB, 3, 0);
133}
134
135void at91_spi1_hw_init(unsigned long cs_mask)
136{
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800137 at91_pio3_set_b_periph(AT91_PIO_PORTA, 21, 0); /* SPI1_MISO */
138 at91_pio3_set_b_periph(AT91_PIO_PORTA, 22, 0); /* SPI1_MOSI */
139 at91_pio3_set_b_periph(AT91_PIO_PORTA, 23, 0); /* SPI1_SPCK */
Bo Shen42aafb32012-07-05 17:21:46 +0000140
Wenyou Yang57b7f292016-02-03 10:16:49 +0800141 at91_periph_clk_enable(ATMEL_ID_SPI1);
Bo Shen42aafb32012-07-05 17:21:46 +0000142
143 if (cs_mask & (1 << 0))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800144 at91_pio3_set_b_periph(AT91_PIO_PORTA, 8, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000145 if (cs_mask & (1 << 1))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800146 at91_pio3_set_b_periph(AT91_PIO_PORTA, 0, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000147 if (cs_mask & (1 << 2))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800148 at91_pio3_set_b_periph(AT91_PIO_PORTA, 31, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000149 if (cs_mask & (1 << 3))
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800150 at91_pio3_set_b_periph(AT91_PIO_PORTA, 30, 0);
Bo Shen42aafb32012-07-05 17:21:46 +0000151 if (cs_mask & (1 << 4))
152 at91_set_pio_output(AT91_PIO_PORTA, 8, 0);
153 if (cs_mask & (1 << 5))
154 at91_set_pio_output(AT91_PIO_PORTA, 0, 0);
155 if (cs_mask & (1 << 6))
156 at91_set_pio_output(AT91_PIO_PORTA, 31, 0);
157 if (cs_mask & (1 << 7))
158 at91_set_pio_output(AT91_PIO_PORTA, 30, 0);
159}
160#endif
161
Tom Riniceed5d22017-05-12 22:33:27 -0400162#if defined(CONFIG_USB_OHCI_NEW) || defined(CONFIG_USB_EHCI_HCD)
Richard Genoudb762a9c2012-11-29 23:18:32 +0000163void at91_uhp_hw_init(void)
164{
165 /* Enable VBus on UHP ports */
166 at91_set_pio_output(AT91_PIO_PORTD, 18, 0); /* port A */
167 at91_set_pio_output(AT91_PIO_PORTD, 19, 0); /* port B */
168#if defined(CONFIG_USB_OHCI_NEW)
169 /* port C is OHCI only */
170 at91_set_pio_output(AT91_PIO_PORTD, 20, 0); /* port C */
171#endif
172}
173#endif
174
Bo Shen42aafb32012-07-05 17:21:46 +0000175#ifdef CONFIG_MACB
176void at91_macb_hw_init(void)
177{
Bo Shen42aafb32012-07-05 17:21:46 +0000178 if (has_emac0()) {
179 /* Enable EMAC0 clock */
Wenyou Yang57b7f292016-02-03 10:16:49 +0800180 at91_periph_clk_enable(ATMEL_ID_EMAC0);
Bo Shen42aafb32012-07-05 17:21:46 +0000181 /* EMAC0 pins setup */
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800182 at91_pio3_set_a_periph(AT91_PIO_PORTB, 4, 0); /* ETXCK */
183 at91_pio3_set_a_periph(AT91_PIO_PORTB, 3, 0); /* ERXDV */
184 at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ERX0 */
185 at91_pio3_set_a_periph(AT91_PIO_PORTB, 1, 0); /* ERX1 */
186 at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ERXER */
187 at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ETXEN */
188 at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ETX0 */
189 at91_pio3_set_a_periph(AT91_PIO_PORTB, 10, 0); /* ETX1 */
190 at91_pio3_set_a_periph(AT91_PIO_PORTB, 5, 0); /* EMDIO */
191 at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* EMDC */
Bo Shen42aafb32012-07-05 17:21:46 +0000192 }
193
194 if (has_emac1()) {
195 /* Enable EMAC1 clock */
Wenyou Yang57b7f292016-02-03 10:16:49 +0800196 at91_periph_clk_enable(ATMEL_ID_EMAC1);
Bo Shen42aafb32012-07-05 17:21:46 +0000197 /* EMAC1 pins setup */
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800198 at91_pio3_set_b_periph(AT91_PIO_PORTC, 29, 0); /* ETXCK */
199 at91_pio3_set_b_periph(AT91_PIO_PORTC, 28, 0); /* ECRSDV */
200 at91_pio3_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ERXO */
201 at91_pio3_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ERX1 */
202 at91_pio3_set_b_periph(AT91_PIO_PORTC, 16, 0); /* ERXER */
203 at91_pio3_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ETXEN */
204 at91_pio3_set_b_periph(AT91_PIO_PORTC, 18, 0); /* ETX0 */
205 at91_pio3_set_b_periph(AT91_PIO_PORTC, 19, 0); /* ETX1 */
206 at91_pio3_set_b_periph(AT91_PIO_PORTC, 31, 0); /* EMDIO */
207 at91_pio3_set_b_periph(AT91_PIO_PORTC, 30, 0); /* EMDC */
Bo Shen42aafb32012-07-05 17:21:46 +0000208 }
209
210#ifndef CONFIG_RMII
211 /* Only emac0 support MII */
212 if (has_emac0()) {
Wenyou Yang4a92a3e2017-03-23 12:44:36 +0800213 at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* ECRS */
214 at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* ECOL */
215 at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ERX2 */
216 at91_pio3_set_a_periph(AT91_PIO_PORTB, 14, 0); /* ERX3 */
217 at91_pio3_set_a_periph(AT91_PIO_PORTB, 15, 0); /* ERXCK */
218 at91_pio3_set_a_periph(AT91_PIO_PORTB, 11, 0); /* ETX2 */
219 at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX3 */
220 at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ETXER */
Bo Shen42aafb32012-07-05 17:21:46 +0000221 }
222#endif
223}
224#endif