blob: 16eeca7378983a16c48052b43b77e8ddb3af693d [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 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 *
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>
14#include <asm/arch/at91_common.h>
15#include <asm/arch/at91_pmc.h>
16#include <asm/arch/gpio.h>
17#include <asm/arch/io.h>
18
19void at91_serial0_hw_init(void)
20{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010021 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
22
Jens Scharsigb49d15c2010-02-03 22:46:46 +010023 at91_set_a_periph(AT91_PIO_PORTA, 22, 1); /* TXD0 */
24 at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* RXD0 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010025 writel(1 << AT91CAP9_ID_US0, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020026}
27
28void at91_serial1_hw_init(void)
29{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010030 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
31
Jens Scharsigb49d15c2010-02-03 22:46:46 +010032 at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */
33 at91_set_a_periph(AT91_PIO_PORTD, 1, 0); /* RXD1 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010034 writel(1 << AT91CAP9_ID_US1, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020035}
36
37void at91_serial2_hw_init(void)
38{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010039 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
40
Jens Scharsigb49d15c2010-02-03 22:46:46 +010041 at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */
42 at91_set_a_periph(AT91_PIO_PORTD, 3, 0); /* RXD2 */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010043 writel(1 << AT91CAP9_ID_US2, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020044}
45
46void at91_serial3_hw_init(void)
47{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010048 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
49
Jens Scharsigb49d15c2010-02-03 22:46:46 +010050 at91_set_a_periph(AT91_PIO_PORTC, 30, 0); /* DRXD */
51 at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010052 writel(1 << AT91_ID_SYS, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020053}
54
55void at91_serial_hw_init(void)
56{
57#ifdef CONFIG_USART0
58 at91_serial0_hw_init();
59#endif
60
61#ifdef CONFIG_USART1
62 at91_serial1_hw_init();
63#endif
64
65#ifdef CONFIG_USART2
66 at91_serial2_hw_init();
67#endif
68
69#ifdef CONFIG_USART3 /* DBGU */
70 at91_serial3_hw_init();
71#endif
72}
73
74#ifdef CONFIG_HAS_DATAFLASH
75void at91_spi0_hw_init(unsigned long cs_mask)
76{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010077 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
78
Jens Scharsigb49d15c2010-02-03 22:46:46 +010079 at91_set_b_periph(AT91_PIO_PORTA, 0, 0); /* SPI0_MISO */
80 at91_set_b_periph(AT91_PIO_PORTA, 1, 0); /* SPI0_MOSI */
81 at91_set_b_periph(AT91_PIO_PORTA, 2, 0); /* SPI0_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020082
83 /* Enable clock */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010084 writel(1 << AT91CAP9_ID_SPI0, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020085
86 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010087 at91_set_b_periph(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020088 }
89 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010090 at91_set_b_periph(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020091 }
92 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010093 at91_set_b_periph(AT91_PIO_PORTD, 0, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020094 }
95 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010096 at91_set_b_periph(AT91_PIO_PORTD, 1, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +020097 }
98 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +010099 at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200100 }
101 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100102 at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200103 }
104 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100105 at91_set_pio_output(AT91_PIO_PORTD, 0, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200106 }
107 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100108 at91_set_pio_output(AT91_PIO_PORTD, 1, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200109 }
110}
111
112void at91_spi1_hw_init(unsigned long cs_mask)
113{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100114 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
115
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100116 at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* SPI1_MISO */
117 at91_set_a_periph(AT91_PIO_PORTB, 13, 0); /* SPI1_MOSI */
118 at91_set_a_periph(AT91_PIO_PORTB, 14, 0); /* SPI1_SPCK */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200119
120 /* Enable clock */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100121 writel(1 << AT91CAP9_ID_SPI1, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200122
123 if (cs_mask & (1 << 0)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100124 at91_set_a_periph(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200125 }
126 if (cs_mask & (1 << 1)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100127 at91_set_a_periph(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200128 }
129 if (cs_mask & (1 << 2)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100130 at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200131 }
132 if (cs_mask & (1 << 3)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100133 at91_set_a_periph(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200134 }
135 if (cs_mask & (1 << 4)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100136 at91_set_pio_output(AT91_PIO_PORTB, 15, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200137 }
138 if (cs_mask & (1 << 5)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100139 at91_set_pio_output(AT91_PIO_PORTB, 16, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200140 }
141 if (cs_mask & (1 << 6)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100142 at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200143 }
144 if (cs_mask & (1 << 7)) {
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100145 at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200146 }
147
148}
149#endif
150
151#ifdef CONFIG_MACB
152void at91_macb_hw_init(void)
153{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100154 at91_set_a_periph(AT91_PIO_PORTB, 21, 0); /* ETXCK_EREFCK */
155 at91_set_a_periph(AT91_PIO_PORTB, 22, 0); /* ERXDV */
156 at91_set_a_periph(AT91_PIO_PORTB, 25, 0); /* ERX0 */
157 at91_set_a_periph(AT91_PIO_PORTB, 26, 0); /* ERX1 */
158 at91_set_a_periph(AT91_PIO_PORTB, 27, 0); /* ERXER */
159 at91_set_a_periph(AT91_PIO_PORTB, 28, 0); /* ETXEN */
160 at91_set_a_periph(AT91_PIO_PORTB, 23, 0); /* ETX0 */
161 at91_set_a_periph(AT91_PIO_PORTB, 24, 0); /* ETX1 */
162 at91_set_a_periph(AT91_PIO_PORTB, 30, 0); /* EMDIO */
163 at91_set_a_periph(AT91_PIO_PORTB, 29, 0); /* EMDC */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200164
165#ifndef CONFIG_RMII
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100166 at91_set_b_periph(AT91_PIO_PORTC, 25, 0); /* ECRS */
167 at91_set_b_periph(AT91_PIO_PORTC, 26, 0); /* ECOL */
168 at91_set_b_periph(AT91_PIO_PORTC, 22, 0); /* ERX2 */
169 at91_set_b_periph(AT91_PIO_PORTC, 23, 0); /* ERX3 */
170 at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ERXCK */
171 at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ETX2 */
172 at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ETX3 */
173 at91_set_b_periph(AT91_PIO_PORTC, 24, 0); /* ETXER */
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200174#endif
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200175}
176#endif
177
178#ifdef CONFIG_AT91_CAN
179void at91_can_hw_init(void)
180{
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100181 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
182
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100183 at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* CAN_TX */
184 at91_set_a_periph(AT91_PIO_PORTA, 13, 1); /* CAN_RX */
Daniel Gorsulowski96d1b472009-06-30 23:03:33 +0200185
186 /* Enable clock */
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100187 writel(1 << AT91CAP9_ID_CAN, &pmc->pcer);
Jean-Christophe PLAGNIOL-VILLARD2495b2d2009-05-13 21:01:13 +0200188}
189#endif