blob: 2d878fdde6d98ed79505837302f047c2807d7111 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +02001/*
2 * (C) Copyright 2007-2008
3 * Stelian Pop <stelian.pop@leadtechdesign.com>
4 * Lead Tech Design <www.leadtechdesign.com>
5 *
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +02006 * (C) Copyright 2009
7 * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
8 * esd electronic system design gmbh <www.esd.eu>
9 *
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020010 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
29#include <common.h>
30#include <asm/arch/at91_common.h>
31#include <asm/arch/at91_pmc.h>
32#include <asm/arch/gpio.h>
33#include <asm/arch/io.h>
34
35void at91_serial0_hw_init(void)
36{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010037 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
38
Jens Scharsigb49d15c2010-02-03 22:46:46 +010039 at91_set_a_periph(AT91_PIO_PORTA, 22, 1); /* TXD0 */
40 at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* RXD0 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010041 writel(1 << AT91CAP9_ID_US0, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020042}
43
44void at91_serial1_hw_init(void)
45{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010046 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
47
Jens Scharsigb49d15c2010-02-03 22:46:46 +010048 at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */
49 at91_set_a_periph(AT91_PIO_PORTD, 1, 0); /* RXD1 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010050 writel(1 << AT91CAP9_ID_US1, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020051}
52
53void at91_serial2_hw_init(void)
54{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010055 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
56
Jens Scharsigb49d15c2010-02-03 22:46:46 +010057 at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */
58 at91_set_a_periph(AT91_PIO_PORTD, 3, 0); /* RXD2 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010059 writel(1 << AT91CAP9_ID_US2, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020060}
61
62void at91_serial3_hw_init(void)
63{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010064 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
65
Jens Scharsigb49d15c2010-02-03 22:46:46 +010066 at91_set_a_periph(AT91_PIO_PORTC, 30, 0); /* DRXD */
67 at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010068 writel(1 << AT91_ID_SYS, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020069}
70
71void at91_serial_hw_init(void)
72{
73#ifdef CONFIG_USART0
74 at91_serial0_hw_init();
75#endif
76
77#ifdef CONFIG_USART1
78 at91_serial1_hw_init();
79#endif
80
81#ifdef CONFIG_USART2
82 at91_serial2_hw_init();
83#endif
84
85#ifdef CONFIG_USART3 /* DBGU */
86 at91_serial3_hw_init();
87#endif
88}
89
90#ifdef CONFIG_HAS_DATAFLASH
91void at91_spi0_hw_init(unsigned long cs_mask)
92{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010093 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
94
Jens Scharsigb49d15c2010-02-03 22:46:46 +010095 at91_set_b_periph(AT91_PIO_PORTA, 0, 0); /* SPI0_MISO */
96 at91_set_b_periph(AT91_PIO_PORTA, 1, 0); /* SPI0_MOSI */
97 at91_set_b_periph(AT91_PIO_PORTA, 2, 0); /* SPI0_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020098
99 /* Enable clock */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100100 writel(1 << AT91CAP9_ID_SPI0, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200101
102 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100103 at91_set_b_periph(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200104 }
105 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100106 at91_set_b_periph(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200107 }
108 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100109 at91_set_b_periph(AT91_PIO_PORTD, 0, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200110 }
111 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100112 at91_set_b_periph(AT91_PIO_PORTD, 1, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200113 }
114 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100115 at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200116 }
117 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100118 at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200119 }
120 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100121 at91_set_pio_output(AT91_PIO_PORTD, 0, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200122 }
123 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100124 at91_set_pio_output(AT91_PIO_PORTD, 1, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200125 }
126}
127
128void at91_spi1_hw_init(unsigned long cs_mask)
129{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100130 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
131
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100132 at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* SPI1_MISO */
133 at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* SPI1_MOSI */
134 at91_set_a_periph(AT91_PIO_PORTB, 14, 0); /* SPI1_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200135
136 /* Enable clock */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100137 writel(1 << AT91CAP9_ID_SPI1, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200138
139 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100140 at91_set_a_periph(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200141 }
142 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100143 at91_set_a_periph(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200144 }
145 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100146 at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200147 }
148 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100149 at91_set_a_periph(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200150 }
151 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100152 at91_set_pio_output(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200153 }
154 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100155 at91_set_pio_output(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200156 }
157 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100158 at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200159 }
160 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100161 at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200162 }
163
164}
165#endif
166
167#ifdef CONFIG_MACB
168void at91_macb_hw_init(void)
169{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100170 at91_set_a_periph(AT91_PIO_PORTB, 21, 0); /* ETXCK_EREFCK */
171 at91_set_a_periph(AT91_PIO_PORTB, 22, 0); /* ERXDV */
172 at91_set_a_periph(AT91_PIO_PORTB, 25, 0); /* ERX0 */
173 at91_set_a_periph(AT91_PIO_PORTB, 26, 0); /* ERX1 */
174 at91_set_a_periph(AT91_PIO_PORTB, 27, 0); /* ERXER */
175 at91_set_a_periph(AT91_PIO_PORTB, 28, 0); /* ETXEN */
176 at91_set_a_periph(AT91_PIO_PORTB, 23, 0); /* ETX0 */
177 at91_set_a_periph(AT91_PIO_PORTB, 24, 0); /* ETX1 */
178 at91_set_a_periph(AT91_PIO_PORTB, 30, 0); /* EMDIO */
179 at91_set_a_periph(AT91_PIO_PORTB, 29, 0); /* EMDC */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200180
181#ifndef CONFIG_RMII
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100182 at91_set_b_periph(AT91_PIO_PORTC, 25, 0); /* ECRS */
183 at91_set_b_periph(AT91_PIO_PORTC, 26, 0); /* ECOL */
184 at91_set_b_periph(AT91_PIO_PORTC, 22, 0); /* ERX2 */
185 at91_set_b_periph(AT91_PIO_PORTC, 23, 0); /* ERX3 */
186 at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ERXCK */
187 at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ETX2 */
188 at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ETX3 */
189 at91_set_b_periph(AT91_PIO_PORTC, 24, 0); /* ETXER */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200190#endif
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200191}
192#endif
193
194#ifdef CONFIG_AT91_CAN
195void at91_can_hw_init(void)
196{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100197 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
198
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100199 at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* CAN_TX */
200 at91_set_a_periph(AT91_PIO_PORTA, 13, 1); /* CAN_RX */
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200201
202 /* Enable clock */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100203 writel(1 << AT91CAP9_ID_CAN, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200204}
205#endif