Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
| 3 | * Stelian Pop <stelian.pop@leadtechdesign.com> |
| 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 6 | * (C) Copyright 2009 |
| 7 | * Daniel Gorsulowski <daniel.gorsulowski@esd.eu> |
| 8 | * esd electronic system design gmbh <www.esd.eu> |
| 9 | * |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 10 | * 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 | |
| 35 | void at91_serial0_hw_init(void) |
| 36 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 37 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 38 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 39 | at91_set_a_periph(AT91_PIO_PORTA, 22, 1); /* TXD0 */ |
| 40 | at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* RXD0 */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 41 | writel(1 << AT91CAP9_ID_US0, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void at91_serial1_hw_init(void) |
| 45 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 46 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 47 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 48 | at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */ |
| 49 | at91_set_a_periph(AT91_PIO_PORTD, 1, 0); /* RXD1 */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 50 | writel(1 << AT91CAP9_ID_US1, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void at91_serial2_hw_init(void) |
| 54 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 55 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 56 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 57 | at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */ |
| 58 | at91_set_a_periph(AT91_PIO_PORTD, 3, 0); /* RXD2 */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 59 | writel(1 << AT91CAP9_ID_US2, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void at91_serial3_hw_init(void) |
| 63 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 64 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 65 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 66 | at91_set_a_periph(AT91_PIO_PORTC, 30, 0); /* DRXD */ |
| 67 | at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 68 | writel(1 << AT91_ID_SYS, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void 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 |
| 91 | void at91_spi0_hw_init(unsigned long cs_mask) |
| 92 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 93 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 94 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 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 */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 98 | |
| 99 | /* Enable clock */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 100 | writel(1 << AT91CAP9_ID_SPI0, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 101 | |
| 102 | if (cs_mask & (1 << 0)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 103 | at91_set_b_periph(AT91_PIO_PORTA, 5, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 104 | } |
| 105 | if (cs_mask & (1 << 1)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 106 | at91_set_b_periph(AT91_PIO_PORTA, 3, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 107 | } |
| 108 | if (cs_mask & (1 << 2)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 109 | at91_set_b_periph(AT91_PIO_PORTD, 0, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 110 | } |
| 111 | if (cs_mask & (1 << 3)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 112 | at91_set_b_periph(AT91_PIO_PORTD, 1, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 113 | } |
| 114 | if (cs_mask & (1 << 4)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 115 | at91_set_pio_output(AT91_PIO_PORTA, 5, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 116 | } |
| 117 | if (cs_mask & (1 << 5)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 118 | at91_set_pio_output(AT91_PIO_PORTA, 3, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 119 | } |
| 120 | if (cs_mask & (1 << 6)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 121 | at91_set_pio_output(AT91_PIO_PORTD, 0, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 122 | } |
| 123 | if (cs_mask & (1 << 7)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 124 | at91_set_pio_output(AT91_PIO_PORTD, 1, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | void at91_spi1_hw_init(unsigned long cs_mask) |
| 129 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 130 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 131 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 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 */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 135 | |
| 136 | /* Enable clock */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 137 | writel(1 << AT91CAP9_ID_SPI1, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 138 | |
| 139 | if (cs_mask & (1 << 0)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 140 | at91_set_a_periph(AT91_PIO_PORTB, 15, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 141 | } |
| 142 | if (cs_mask & (1 << 1)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 143 | at91_set_a_periph(AT91_PIO_PORTB, 16, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 144 | } |
| 145 | if (cs_mask & (1 << 2)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 146 | at91_set_a_periph(AT91_PIO_PORTB, 17, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 147 | } |
| 148 | if (cs_mask & (1 << 3)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 149 | at91_set_a_periph(AT91_PIO_PORTB, 18, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 150 | } |
| 151 | if (cs_mask & (1 << 4)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 152 | at91_set_pio_output(AT91_PIO_PORTB, 15, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 153 | } |
| 154 | if (cs_mask & (1 << 5)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 155 | at91_set_pio_output(AT91_PIO_PORTB, 16, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 156 | } |
| 157 | if (cs_mask & (1 << 6)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 158 | at91_set_pio_output(AT91_PIO_PORTB, 17, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 159 | } |
| 160 | if (cs_mask & (1 << 7)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 161 | at91_set_pio_output(AT91_PIO_PORTB, 18, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | } |
| 165 | #endif |
| 166 | |
| 167 | #ifdef CONFIG_MACB |
| 168 | void at91_macb_hw_init(void) |
| 169 | { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 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 */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 180 | |
| 181 | #ifndef CONFIG_RMII |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 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 */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 190 | #endif |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 191 | } |
| 192 | #endif |
| 193 | |
| 194 | #ifdef CONFIG_AT91_CAN |
| 195 | void at91_can_hw_init(void) |
| 196 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 197 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 198 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 199 | at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* CAN_TX */ |
| 200 | at91_set_a_periph(AT91_PIO_PORTA, 13, 1); /* CAN_RX */ |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 201 | |
| 202 | /* Enable clock */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 203 | writel(1 << AT91CAP9_ID_CAN, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 204 | } |
| 205 | #endif |