2 * (C) Copyright 2007-2008
3 * Stelian Pop <stelian@popies.net>
4 * Lead Tech Design <www.leadtechdesign.com>
7 * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
8 * esd electronic system design gmbh <www.esd.eu>
10 * See file CREDITS for list of people who contributed to this
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.
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.
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,
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>
35 void at91_serial0_hw_init(void)
37 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
39 at91_set_a_periph(AT91_PIO_PORTA, 22, 1); /* TXD0 */
40 at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* RXD0 */
41 writel(1 << AT91CAP9_ID_US0, &pmc->pcer);
44 void at91_serial1_hw_init(void)
46 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
48 at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */
49 at91_set_a_periph(AT91_PIO_PORTD, 1, 0); /* RXD1 */
50 writel(1 << AT91CAP9_ID_US1, &pmc->pcer);
53 void at91_serial2_hw_init(void)
55 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
57 at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */
58 at91_set_a_periph(AT91_PIO_PORTD, 3, 0); /* RXD2 */
59 writel(1 << AT91CAP9_ID_US2, &pmc->pcer);
62 void at91_serial3_hw_init(void)
64 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
66 at91_set_a_periph(AT91_PIO_PORTC, 30, 0); /* DRXD */
67 at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */
68 writel(1 << AT91_ID_SYS, &pmc->pcer);
71 void at91_serial_hw_init(void)
74 at91_serial0_hw_init();
78 at91_serial1_hw_init();
82 at91_serial2_hw_init();
85 #ifdef CONFIG_USART3 /* DBGU */
86 at91_serial3_hw_init();
90 #ifdef CONFIG_HAS_DATAFLASH
91 void at91_spi0_hw_init(unsigned long cs_mask)
93 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
95 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 */
100 writel(1 << AT91CAP9_ID_SPI0, &pmc->pcer);
102 if (cs_mask & (1 << 0)) {
103 at91_set_b_periph(AT91_PIO_PORTA, 5, 1);
105 if (cs_mask & (1 << 1)) {
106 at91_set_b_periph(AT91_PIO_PORTA, 3, 1);
108 if (cs_mask & (1 << 2)) {
109 at91_set_b_periph(AT91_PIO_PORTD, 0, 1);
111 if (cs_mask & (1 << 3)) {
112 at91_set_b_periph(AT91_PIO_PORTD, 1, 1);
114 if (cs_mask & (1 << 4)) {
115 at91_set_pio_output(AT91_PIO_PORTA, 5, 1);
117 if (cs_mask & (1 << 5)) {
118 at91_set_pio_output(AT91_PIO_PORTA, 3, 1);
120 if (cs_mask & (1 << 6)) {
121 at91_set_pio_output(AT91_PIO_PORTD, 0, 1);
123 if (cs_mask & (1 << 7)) {
124 at91_set_pio_output(AT91_PIO_PORTD, 1, 1);
128 void at91_spi1_hw_init(unsigned long cs_mask)
130 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
132 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 */
137 writel(1 << AT91CAP9_ID_SPI1, &pmc->pcer);
139 if (cs_mask & (1 << 0)) {
140 at91_set_a_periph(AT91_PIO_PORTB, 15, 1);
142 if (cs_mask & (1 << 1)) {
143 at91_set_a_periph(AT91_PIO_PORTB, 16, 1);
145 if (cs_mask & (1 << 2)) {
146 at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
148 if (cs_mask & (1 << 3)) {
149 at91_set_a_periph(AT91_PIO_PORTB, 18, 1);
151 if (cs_mask & (1 << 4)) {
152 at91_set_pio_output(AT91_PIO_PORTB, 15, 1);
154 if (cs_mask & (1 << 5)) {
155 at91_set_pio_output(AT91_PIO_PORTB, 16, 1);
157 if (cs_mask & (1 << 6)) {
158 at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
160 if (cs_mask & (1 << 7)) {
161 at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
168 void at91_macb_hw_init(void)
170 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 */
182 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 */
194 #ifdef CONFIG_AT91_CAN
195 void at91_can_hw_init(void)
197 at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE;
199 at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* CAN_TX */
200 at91_set_a_periph(AT91_PIO_PORTA, 13, 1); /* CAN_RX */
203 writel(1 << AT91CAP9_ID_CAN, &pmc->pcer);