blob: 99a39134defaef6b4f3fbf55fa1993c4a0b07635 [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>
16#include <asm/arch/at91_pmc.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{
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000036 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010037
Jens Scharsigb49d15c2010-02-03 22:46:46 +010038 at91_set_a_periph(AT91_PIO_PORTA, 26, 1); /* TXD0 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000039 at91_set_a_periph(AT91_PIO_PORTA, 27, PUP); /* RXD0 */
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000040 writel(1 << ATMEL_ID_USART0, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020041}
42
43void at91_serial1_hw_init(void)
44{
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000045 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010046
Jens Scharsigb49d15c2010-02-03 22:46:46 +010047 at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000048 at91_set_a_periph(AT91_PIO_PORTD, 1, PUP); /* RXD1 */
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000049 writel(1 << ATMEL_ID_USART1, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020050}
51
52void at91_serial2_hw_init(void)
53{
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000054 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010055
Jens Scharsigb49d15c2010-02-03 22:46:46 +010056 at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */
Xu, Hong4fae89c2011-06-10 21:31:25 +000057 at91_set_a_periph(AT91_PIO_PORTD, 3, PUP); /* RXD2 */
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000058 writel(1 << ATMEL_ID_USART2, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020059}
60
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000061void at91_seriald_hw_init(void)
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020062{
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000063 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010064
Xu, Hong4fae89c2011-06-10 21:31:25 +000065 at91_set_a_periph(AT91_PIO_PORTC, 30, PUP); /* DRXD */
Jens Scharsigb49d15c2010-02-03 22:46:46 +010066 at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000067 writel(1 << ATMEL_ID_SYS, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020068}
69
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000070#if defined(CONFIG_HAS_DATAFLASH) || defined(CONFIG_ATMEL_SPI)
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020071void at91_spi0_hw_init(unsigned long cs_mask)
72{
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000073 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010074
Xu, Hong4fae89c2011-06-10 21:31:25 +000075 at91_set_b_periph(AT91_PIO_PORTA, 0, PUP); /* SPI0_MISO */
76 at91_set_b_periph(AT91_PIO_PORTA, 1, PUP); /* SPI0_MOSI */
77 at91_set_b_periph(AT91_PIO_PORTA, 2, PUP); /* SPI0_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020078
79 /* Enable clock */
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +000080 writel(1 << ATMEL_ID_SPI0, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020081
82 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010083 at91_set_b_periph(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020084 }
85 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010086 at91_set_b_periph(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020087 }
88 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010089 at91_set_b_periph(AT91_PIO_PORTA, 4, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020090 }
91 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010092 at91_set_b_periph(AT91_PIO_PORTB, 11, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020093 }
94 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010095 at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020096 }
97 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010098 at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020099 }
100 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100101 at91_set_pio_output(AT91_PIO_PORTA, 4, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200102 }
103 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100104 at91_set_pio_output(AT91_PIO_PORTB, 11, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200105 }
106}
107
108void at91_spi1_hw_init(unsigned long cs_mask)
109{
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +0000110 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100111
Xu, Hong4fae89c2011-06-10 21:31:25 +0000112 at91_set_a_periph(AT91_PIO_PORTB, 12, PUP); /* SPI1_MISO */
113 at91_set_a_periph(AT91_PIO_PORTB, 13, PUP); /* SPI1_MOSI */
114 at91_set_a_periph(AT91_PIO_PORTB, 14, PUP); /* SPI1_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200115
116 /* Enable clock */
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +0000117 writel(1 << ATMEL_ID_SPI1, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200118
119 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100120 at91_set_a_periph(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200121 }
122 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100123 at91_set_a_periph(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200124 }
125 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100126 at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200127 }
128 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100129 at91_set_a_periph(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200130 }
131 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100132 at91_set_pio_output(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200133 }
134 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100135 at91_set_pio_output(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200136 }
137 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100138 at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200139 }
140 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100141 at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200142 }
143}
144#endif
145
146#ifdef CONFIG_MACB
147void at91_macb_hw_init(void)
148{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100149 at91_set_a_periph(AT91_PIO_PORTE, 21, 0); /* ETXCK_EREFCK */
150 at91_set_b_periph(AT91_PIO_PORTC, 25, 0); /* ERXDV */
151 at91_set_a_periph(AT91_PIO_PORTE, 25, 0); /* ERX0 */
152 at91_set_a_periph(AT91_PIO_PORTE, 26, 0); /* ERX1 */
153 at91_set_a_periph(AT91_PIO_PORTE, 27, 0); /* ERXER */
154 at91_set_a_periph(AT91_PIO_PORTE, 28, 0); /* ETXEN */
155 at91_set_a_periph(AT91_PIO_PORTE, 23, 0); /* ETX0 */
156 at91_set_a_periph(AT91_PIO_PORTE, 24, 0); /* ETX1 */
157 at91_set_a_periph(AT91_PIO_PORTE, 30, 0); /* EMDIO */
158 at91_set_a_periph(AT91_PIO_PORTE, 29, 0); /* EMDC */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200159
160#ifndef CONFIG_RMII
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100161 at91_set_a_periph(AT91_PIO_PORTE, 22, 0); /* ECRS */
162 at91_set_b_periph(AT91_PIO_PORTC, 26, 0); /* ECOL */
163 at91_set_b_periph(AT91_PIO_PORTC, 22, 0); /* ERX2 */
164 at91_set_b_periph(AT91_PIO_PORTC, 23, 0); /* ERX3 */
165 at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ERXCK */
166 at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ETX2 */
167 at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ETX3 */
168 at91_set_b_periph(AT91_PIO_PORTC, 24, 0); /* ETXER */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200169#endif
170}
171#endif
172
173#ifdef CONFIG_USB_OHCI_NEW
174void at91_uhp_hw_init(void)
175{
176 /* Enable VBus on UHP ports */
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100177 at91_set_pio_output(AT91_PIO_PORTA, 21, 0);
178 at91_set_pio_output(AT91_PIO_PORTA, 24, 0);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200179}
180#endif
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200181
182#ifdef CONFIG_AT91_CAN
183void at91_can_hw_init(void)
184{
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +0000185 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100186
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100187 at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* CAN_TX */
188 at91_set_a_periph(AT91_PIO_PORTA, 14, 1); /* CAN_RX */
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200189
190 /* Enable clock */
Daniel Gorsulowskibbe11692011-01-20 23:12:15 +0000191 writel(1 << ATMEL_ID_CAN, &pmc->pcer);
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200192}
193#endif