blob: f3f480010a4a1faea67ee067507e94617afd6608 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +02001/*
2 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 *
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +00006 * (C) Copyright 2009-2011
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +02007 * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
8 * esd electronic system design gmbh <www.esd.eu>
9 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020010 * SPDX-License-Identifier: GPL-2.0+
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020011 */
12
13#include <common.h>
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000014#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020015#include <asm/arch/at91_common.h>
Wenyou Yang57b7f292016-02-03 10:16:49 +080016#include <asm/arch/clk.h>
Xu, Hong4fae89c2011-06-10 21:31:25 +000017#include <asm/arch/gpio.h>
18
19/*
20 * if CONFIG_AT91_GPIO_PULLUP ist set, keep pullups on on all
21 * peripheral pins. Good to have if hardware is soldered optionally
22 * or in case of SPI no slave is selected. Avoid lines to float
23 * needlessly. Use a short local PUP define.
24 *
25 * Due to errata "TXD floats when CTS is inactive" pullups are always
26 * on for TXD pins.
27 */
28#ifdef CONFIG_AT91_GPIO_PULLUP
29# define PUP CONFIG_AT91_GPIO_PULLUP
30#else
31# define PUP 0
32#endif
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020033
34void at91_serial0_hw_init(void)
35{
Jens Scharsigb49d15c2010-02-03 22:46:46 +010036 at91_set_a_periph(AT91_PIO_PORTA, 26, 1); /* TXD0 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000037 at91_set_a_periph(AT91_PIO_PORTA, 27, PUP); /* RXD0 */
Wenyou Yang57b7f292016-02-03 10:16:49 +080038 at91_periph_clk_enable(ATMEL_ID_USART0);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020039}
40
41void at91_serial1_hw_init(void)
42{
Jens Scharsigb49d15c2010-02-03 22:46:46 +010043 at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000044 at91_set_a_periph(AT91_PIO_PORTD, 1, PUP); /* RXD1 */
Wenyou Yang57b7f292016-02-03 10:16:49 +080045 at91_periph_clk_enable(ATMEL_ID_USART1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020046}
47
48void at91_serial2_hw_init(void)
49{
Jens Scharsigb49d15c2010-02-03 22:46:46 +010050 at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000051 at91_set_a_periph(AT91_PIO_PORTD, 3, PUP); /* RXD2 */
Wenyou Yang57b7f292016-02-03 10:16:49 +080052 at91_periph_clk_enable(ATMEL_ID_USART2);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020053}
54
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000055void at91_seriald_hw_init(void)
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020056{
Xu, Hong4fae89c2011-06-10 21:31:25 +000057 at91_set_a_periph(AT91_PIO_PORTC, 30, PUP); /* DRXD */
Jens Scharsigb49d15c2010-02-03 22:46:46 +010058 at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */
Wenyou Yang57b7f292016-02-03 10:16:49 +080059 at91_periph_clk_enable(ATMEL_ID_SYS);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020060}
61
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000062#if defined(CONFIG_HAS_DATAFLASH) || defined(CONFIG_ATMEL_SPI)
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020063void at91_spi0_hw_init(unsigned long cs_mask)
64{
Xu, Hong4fae89c2011-06-10 21:31:25 +000065 at91_set_b_periph(AT91_PIO_PORTA, 0, PUP); /* SPI0_MISO */
66 at91_set_b_periph(AT91_PIO_PORTA, 1, PUP); /* SPI0_MOSI */
67 at91_set_b_periph(AT91_PIO_PORTA, 2, PUP); /* SPI0_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020068
Wenyou Yang57b7f292016-02-03 10:16:49 +080069 at91_periph_clk_enable(ATMEL_ID_SPI0);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020070
71 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010072 at91_set_b_periph(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020073 }
74 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010075 at91_set_b_periph(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020076 }
77 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010078 at91_set_b_periph(AT91_PIO_PORTA, 4, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020079 }
80 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010081 at91_set_b_periph(AT91_PIO_PORTB, 11, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020082 }
83 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010084 at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020085 }
86 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010087 at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020088 }
89 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010090 at91_set_pio_output(AT91_PIO_PORTA, 4, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020091 }
92 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010093 at91_set_pio_output(AT91_PIO_PORTB, 11, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020094 }
95}
96
97void at91_spi1_hw_init(unsigned long cs_mask)
98{
Xu, Hong4fae89c2011-06-10 21:31:25 +000099 at91_set_a_periph(AT91_PIO_PORTB, 12, PUP); /* SPI1_MISO */
100 at91_set_a_periph(AT91_PIO_PORTB, 13, PUP); /* SPI1_MOSI */
101 at91_set_a_periph(AT91_PIO_PORTB, 14, PUP); /* SPI1_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200102
Wenyou Yang57b7f292016-02-03 10:16:49 +0800103 at91_periph_clk_enable(ATMEL_ID_SPI1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200104
105 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100106 at91_set_a_periph(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200107 }
108 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100109 at91_set_a_periph(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200110 }
111 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100112 at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200113 }
114 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100115 at91_set_a_periph(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200116 }
117 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100118 at91_set_pio_output(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200119 }
120 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100121 at91_set_pio_output(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200122 }
123 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100124 at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200125 }
126 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100127 at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200128 }
129}
130#endif
131
Andreas Henrikssond70d42f2014-01-27 19:18:59 +0100132#if defined(CONFIG_GENERIC_ATMEL_MCI)
133void at91_mci_hw_init(void)
134{
Wenyou Yang57b7f292016-02-03 10:16:49 +0800135 at91_periph_clk_enable(ATMEL_ID_MCI1);
Andreas Henrikssond70d42f2014-01-27 19:18:59 +0100136
137 at91_set_a_periph(AT91_PIO_PORTA, 6, PUP); /* MCI1_CK */
138
139#if defined(CONFIG_ATMEL_MCI_PORTB)
140 at91_set_a_periph(AT91_PIO_PORTA, 21, PUP); /* MCI1_CDB */
141 at91_set_a_periph(AT91_PIO_PORTA, 22, PUP); /* MCI1_DB0 */
142 at91_set_a_periph(AT91_PIO_PORTA, 23, PUP); /* MCI1_DB1 */
143 at91_set_a_periph(AT91_PIO_PORTA, 24, PUP); /* MCI1_DB2 */
144 at91_set_a_periph(AT91_PIO_PORTA, 25, PUP); /* MCI1_DB3 */
145#else
146 at91_set_a_periph(AT91_PIO_PORTA, 7, PUP); /* MCI1_CDA */
147 at91_set_a_periph(AT91_PIO_PORTA, 8, PUP); /* MCI1_DA0 */
148 at91_set_a_periph(AT91_PIO_PORTA, 9, PUP); /* MCI1_DA1 */
149 at91_set_a_periph(AT91_PIO_PORTA, 10, PUP); /* MCI1_DA2 */
150 at91_set_a_periph(AT91_PIO_PORTA, 11, PUP); /* MCI1_DA3 */
151#endif
152}
153#endif
154
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200155#ifdef CONFIG_MACB
156void at91_macb_hw_init(void)
157{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100158 at91_set_a_periph(AT91_PIO_PORTE, 21, 0); /* ETXCK_EREFCK */
159 at91_set_b_periph(AT91_PIO_PORTC, 25, 0); /* ERXDV */
160 at91_set_a_periph(AT91_PIO_PORTE, 25, 0); /* ERX0 */
161 at91_set_a_periph(AT91_PIO_PORTE, 26, 0); /* ERX1 */
162 at91_set_a_periph(AT91_PIO_PORTE, 27, 0); /* ERXER */
163 at91_set_a_periph(AT91_PIO_PORTE, 28, 0); /* ETXEN */
164 at91_set_a_periph(AT91_PIO_PORTE, 23, 0); /* ETX0 */
165 at91_set_a_periph(AT91_PIO_PORTE, 24, 0); /* ETX1 */
166 at91_set_a_periph(AT91_PIO_PORTE, 30, 0); /* EMDIO */
167 at91_set_a_periph(AT91_PIO_PORTE, 29, 0); /* EMDC */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200168
169#ifndef CONFIG_RMII
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100170 at91_set_a_periph(AT91_PIO_PORTE, 22, 0); /* ECRS */
171 at91_set_b_periph(AT91_PIO_PORTC, 26, 0); /* ECOL */
172 at91_set_b_periph(AT91_PIO_PORTC, 22, 0); /* ERX2 */
173 at91_set_b_periph(AT91_PIO_PORTC, 23, 0); /* ERX3 */
174 at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ERXCK */
175 at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ETX2 */
176 at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ETX3 */
177 at91_set_b_periph(AT91_PIO_PORTC, 24, 0); /* ETXER */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200178#endif
179}
180#endif
181
182#ifdef CONFIG_USB_OHCI_NEW
183void at91_uhp_hw_init(void)
184{
185 /* Enable VBus on UHP ports */
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100186 at91_set_pio_output(AT91_PIO_PORTA, 21, 0);
187 at91_set_pio_output(AT91_PIO_PORTA, 24, 0);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200188}
189#endif
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200190
191#ifdef CONFIG_AT91_CAN
192void at91_can_hw_init(void)
193{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100194 at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* CAN_TX */
195 at91_set_a_periph(AT91_PIO_PORTA, 14, 1); /* CAN_RX */
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200196
Wenyou Yang57b7f292016-02-03 10:16:49 +0800197 at91_periph_clk_enable(ATMEL_ID_CAN);
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200198}
199#endif