blob: 3b8a4623866cb88aec23245561f49b2986da5c08 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +02002/*
3 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01004 * Stelian Pop <stelian@popies.net>
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +02005 * Lead Tech Design <www.leadtechdesign.com>
6 *
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +00007 * (C) Copyright 2009-2011
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +02008 * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
9 * esd electronic system design gmbh <www.esd.eu>
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020010 */
11
12#include <common.h>
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000013#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020014#include <asm/arch/at91_common.h>
Wenyou Yang57b7f292016-02-03 10:16:49 +080015#include <asm/arch/clk.h>
Xu, Hong4fae89c2011-06-10 21:31:25 +000016#include <asm/arch/gpio.h>
17
18/*
19 * if CONFIG_AT91_GPIO_PULLUP ist set, keep pullups on on all
20 * peripheral pins. Good to have if hardware is soldered optionally
21 * or in case of SPI no slave is selected. Avoid lines to float
22 * needlessly. Use a short local PUP define.
23 *
24 * Due to errata "TXD floats when CTS is inactive" pullups are always
25 * on for TXD pins.
26 */
27#ifdef CONFIG_AT91_GPIO_PULLUP
28# define PUP CONFIG_AT91_GPIO_PULLUP
29#else
30# define PUP 0
31#endif
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020032
33void at91_serial0_hw_init(void)
34{
Jens Scharsigb49d15c2010-02-03 22:46:46 +010035 at91_set_a_periph(AT91_PIO_PORTA, 26, 1); /* TXD0 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000036 at91_set_a_periph(AT91_PIO_PORTA, 27, PUP); /* RXD0 */
Wenyou Yang57b7f292016-02-03 10:16:49 +080037 at91_periph_clk_enable(ATMEL_ID_USART0);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020038}
39
40void at91_serial1_hw_init(void)
41{
Jens Scharsigb49d15c2010-02-03 22:46:46 +010042 at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000043 at91_set_a_periph(AT91_PIO_PORTD, 1, PUP); /* RXD1 */
Wenyou Yang57b7f292016-02-03 10:16:49 +080044 at91_periph_clk_enable(ATMEL_ID_USART1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020045}
46
47void at91_serial2_hw_init(void)
48{
Jens Scharsigb49d15c2010-02-03 22:46:46 +010049 at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000050 at91_set_a_periph(AT91_PIO_PORTD, 3, PUP); /* RXD2 */
Wenyou Yang57b7f292016-02-03 10:16:49 +080051 at91_periph_clk_enable(ATMEL_ID_USART2);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020052}
53
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000054void at91_seriald_hw_init(void)
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020055{
Xu, Hong4fae89c2011-06-10 21:31:25 +000056 at91_set_a_periph(AT91_PIO_PORTC, 30, PUP); /* DRXD */
Jens Scharsigb49d15c2010-02-03 22:46:46 +010057 at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */
Wenyou Yang57b7f292016-02-03 10:16:49 +080058 at91_periph_clk_enable(ATMEL_ID_SYS);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020059}
60
Tuomas Tynkkynen1b725202017-10-10 21:59:42 +030061#ifdef CONFIG_ATMEL_SPI
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020062void at91_spi0_hw_init(unsigned long cs_mask)
63{
Xu, Hong4fae89c2011-06-10 21:31:25 +000064 at91_set_b_periph(AT91_PIO_PORTA, 0, PUP); /* SPI0_MISO */
65 at91_set_b_periph(AT91_PIO_PORTA, 1, PUP); /* SPI0_MOSI */
66 at91_set_b_periph(AT91_PIO_PORTA, 2, PUP); /* SPI0_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020067
Wenyou Yang57b7f292016-02-03 10:16:49 +080068 at91_periph_clk_enable(ATMEL_ID_SPI0);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020069
70 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010071 at91_set_b_periph(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020072 }
73 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010074 at91_set_b_periph(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020075 }
76 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010077 at91_set_b_periph(AT91_PIO_PORTA, 4, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020078 }
79 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010080 at91_set_b_periph(AT91_PIO_PORTB, 11, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020081 }
82 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010083 at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020084 }
85 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010086 at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020087 }
88 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010089 at91_set_pio_output(AT91_PIO_PORTA, 4, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020090 }
91 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010092 at91_set_pio_output(AT91_PIO_PORTB, 11, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020093 }
94}
95
96void at91_spi1_hw_init(unsigned long cs_mask)
97{
Xu, Hong4fae89c2011-06-10 21:31:25 +000098 at91_set_a_periph(AT91_PIO_PORTB, 12, PUP); /* SPI1_MISO */
99 at91_set_a_periph(AT91_PIO_PORTB, 13, PUP); /* SPI1_MOSI */
100 at91_set_a_periph(AT91_PIO_PORTB, 14, PUP); /* SPI1_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200101
Wenyou Yang57b7f292016-02-03 10:16:49 +0800102 at91_periph_clk_enable(ATMEL_ID_SPI1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200103
104 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100105 at91_set_a_periph(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200106 }
107 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100108 at91_set_a_periph(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200109 }
110 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100111 at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200112 }
113 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100114 at91_set_a_periph(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200115 }
116 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100117 at91_set_pio_output(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200118 }
119 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100120 at91_set_pio_output(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200121 }
122 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100123 at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200124 }
125 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100126 at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200127 }
128}
129#endif
130
Andreas Henrikssond70d42f2014-01-27 19:18:59 +0100131#if defined(CONFIG_GENERIC_ATMEL_MCI)
132void at91_mci_hw_init(void)
133{
Wenyou Yang57b7f292016-02-03 10:16:49 +0800134 at91_periph_clk_enable(ATMEL_ID_MCI1);
Andreas Henrikssond70d42f2014-01-27 19:18:59 +0100135
136 at91_set_a_periph(AT91_PIO_PORTA, 6, PUP); /* MCI1_CK */
137
138#if defined(CONFIG_ATMEL_MCI_PORTB)
139 at91_set_a_periph(AT91_PIO_PORTA, 21, PUP); /* MCI1_CDB */
140 at91_set_a_periph(AT91_PIO_PORTA, 22, PUP); /* MCI1_DB0 */
141 at91_set_a_periph(AT91_PIO_PORTA, 23, PUP); /* MCI1_DB1 */
142 at91_set_a_periph(AT91_PIO_PORTA, 24, PUP); /* MCI1_DB2 */
143 at91_set_a_periph(AT91_PIO_PORTA, 25, PUP); /* MCI1_DB3 */
144#else
145 at91_set_a_periph(AT91_PIO_PORTA, 7, PUP); /* MCI1_CDA */
146 at91_set_a_periph(AT91_PIO_PORTA, 8, PUP); /* MCI1_DA0 */
147 at91_set_a_periph(AT91_PIO_PORTA, 9, PUP); /* MCI1_DA1 */
148 at91_set_a_periph(AT91_PIO_PORTA, 10, PUP); /* MCI1_DA2 */
149 at91_set_a_periph(AT91_PIO_PORTA, 11, PUP); /* MCI1_DA3 */
150#endif
151}
152#endif
153
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200154#ifdef CONFIG_MACB
155void at91_macb_hw_init(void)
156{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100157 at91_set_a_periph(AT91_PIO_PORTE, 21, 0); /* ETXCK_EREFCK */
158 at91_set_b_periph(AT91_PIO_PORTC, 25, 0); /* ERXDV */
159 at91_set_a_periph(AT91_PIO_PORTE, 25, 0); /* ERX0 */
160 at91_set_a_periph(AT91_PIO_PORTE, 26, 0); /* ERX1 */
161 at91_set_a_periph(AT91_PIO_PORTE, 27, 0); /* ERXER */
162 at91_set_a_periph(AT91_PIO_PORTE, 28, 0); /* ETXEN */
163 at91_set_a_periph(AT91_PIO_PORTE, 23, 0); /* ETX0 */
164 at91_set_a_periph(AT91_PIO_PORTE, 24, 0); /* ETX1 */
165 at91_set_a_periph(AT91_PIO_PORTE, 30, 0); /* EMDIO */
166 at91_set_a_periph(AT91_PIO_PORTE, 29, 0); /* EMDC */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200167
168#ifndef CONFIG_RMII
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100169 at91_set_a_periph(AT91_PIO_PORTE, 22, 0); /* ECRS */
170 at91_set_b_periph(AT91_PIO_PORTC, 26, 0); /* ECOL */
171 at91_set_b_periph(AT91_PIO_PORTC, 22, 0); /* ERX2 */
172 at91_set_b_periph(AT91_PIO_PORTC, 23, 0); /* ERX3 */
173 at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ERXCK */
174 at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ETX2 */
175 at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ETX3 */
176 at91_set_b_periph(AT91_PIO_PORTC, 24, 0); /* ETXER */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200177#endif
178}
179#endif
180
181#ifdef CONFIG_USB_OHCI_NEW
182void at91_uhp_hw_init(void)
183{
184 /* Enable VBus on UHP ports */
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100185 at91_set_pio_output(AT91_PIO_PORTA, 21, 0);
186 at91_set_pio_output(AT91_PIO_PORTA, 24, 0);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200187}
188#endif
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200189
190#ifdef CONFIG_AT91_CAN
191void at91_can_hw_init(void)
192{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100193 at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* CAN_TX */
194 at91_set_a_periph(AT91_PIO_PORTA, 14, 1); /* CAN_RX */
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200195
Wenyou Yang57b7f292016-02-03 10:16:49 +0800196 at91_periph_clk_enable(ATMEL_ID_CAN);
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200197}
198#endif