Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
Stelian Pop | 5ee0c7f | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 3 | * Stelian Pop <stelian@popies.net> |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 6 | * (C) Copyright 2009-2011 |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 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> |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 30 | #include <asm/io.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 31 | #include <asm/arch/at91_common.h> |
| 32 | #include <asm/arch/at91_pmc.h> |
Xu, Hong | 4fae89c | 2011-06-10 21:31:25 +0000 | [diff] [blame] | 33 | #include <asm/arch/gpio.h> |
| 34 | |
| 35 | /* |
| 36 | * if CONFIG_AT91_GPIO_PULLUP ist set, keep pullups on on all |
| 37 | * peripheral pins. Good to have if hardware is soldered optionally |
| 38 | * or in case of SPI no slave is selected. Avoid lines to float |
| 39 | * needlessly. Use a short local PUP define. |
| 40 | * |
| 41 | * Due to errata "TXD floats when CTS is inactive" pullups are always |
| 42 | * on for TXD pins. |
| 43 | */ |
| 44 | #ifdef CONFIG_AT91_GPIO_PULLUP |
| 45 | # define PUP CONFIG_AT91_GPIO_PULLUP |
| 46 | #else |
| 47 | # define PUP 0 |
| 48 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 49 | |
| 50 | void at91_serial0_hw_init(void) |
| 51 | { |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 52 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 53 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 54 | at91_set_a_periph(AT91_PIO_PORTA, 26, 1); /* TXD0 */ |
Xu, Hong | 4fae89c | 2011-06-10 21:31:25 +0000 | [diff] [blame] | 55 | at91_set_a_periph(AT91_PIO_PORTA, 27, PUP); /* RXD0 */ |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 56 | writel(1 << ATMEL_ID_USART0, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void at91_serial1_hw_init(void) |
| 60 | { |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 61 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 62 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 63 | at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */ |
Xu, Hong | 4fae89c | 2011-06-10 21:31:25 +0000 | [diff] [blame] | 64 | at91_set_a_periph(AT91_PIO_PORTD, 1, PUP); /* RXD1 */ |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 65 | writel(1 << ATMEL_ID_USART1, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void at91_serial2_hw_init(void) |
| 69 | { |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 70 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 71 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 72 | at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */ |
Xu, Hong | 4fae89c | 2011-06-10 21:31:25 +0000 | [diff] [blame] | 73 | at91_set_a_periph(AT91_PIO_PORTD, 3, PUP); /* RXD2 */ |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 74 | writel(1 << ATMEL_ID_USART2, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 77 | void at91_seriald_hw_init(void) |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 78 | { |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 79 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 80 | |
Xu, Hong | 4fae89c | 2011-06-10 21:31:25 +0000 | [diff] [blame] | 81 | at91_set_a_periph(AT91_PIO_PORTC, 30, PUP); /* DRXD */ |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 82 | at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */ |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 83 | writel(1 << ATMEL_ID_SYS, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 86 | #if defined(CONFIG_HAS_DATAFLASH) || defined(CONFIG_ATMEL_SPI) |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 87 | void at91_spi0_hw_init(unsigned long cs_mask) |
| 88 | { |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 89 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 90 | |
Xu, Hong | 4fae89c | 2011-06-10 21:31:25 +0000 | [diff] [blame] | 91 | at91_set_b_periph(AT91_PIO_PORTA, 0, PUP); /* SPI0_MISO */ |
| 92 | at91_set_b_periph(AT91_PIO_PORTA, 1, PUP); /* SPI0_MOSI */ |
| 93 | at91_set_b_periph(AT91_PIO_PORTA, 2, PUP); /* SPI0_SPCK */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 94 | |
| 95 | /* Enable clock */ |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 96 | writel(1 << ATMEL_ID_SPI0, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 97 | |
| 98 | if (cs_mask & (1 << 0)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 99 | at91_set_b_periph(AT91_PIO_PORTA, 5, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 100 | } |
| 101 | if (cs_mask & (1 << 1)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 102 | at91_set_b_periph(AT91_PIO_PORTA, 3, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 103 | } |
| 104 | if (cs_mask & (1 << 2)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 105 | at91_set_b_periph(AT91_PIO_PORTA, 4, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 106 | } |
| 107 | if (cs_mask & (1 << 3)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 108 | at91_set_b_periph(AT91_PIO_PORTB, 11, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 109 | } |
| 110 | if (cs_mask & (1 << 4)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 111 | at91_set_pio_output(AT91_PIO_PORTA, 5, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 112 | } |
| 113 | if (cs_mask & (1 << 5)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 114 | at91_set_pio_output(AT91_PIO_PORTA, 3, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 115 | } |
| 116 | if (cs_mask & (1 << 6)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 117 | at91_set_pio_output(AT91_PIO_PORTA, 4, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 118 | } |
| 119 | if (cs_mask & (1 << 7)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 120 | at91_set_pio_output(AT91_PIO_PORTB, 11, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | void at91_spi1_hw_init(unsigned long cs_mask) |
| 125 | { |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 126 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 127 | |
Xu, Hong | 4fae89c | 2011-06-10 21:31:25 +0000 | [diff] [blame] | 128 | at91_set_a_periph(AT91_PIO_PORTB, 12, PUP); /* SPI1_MISO */ |
| 129 | at91_set_a_periph(AT91_PIO_PORTB, 13, PUP); /* SPI1_MOSI */ |
| 130 | at91_set_a_periph(AT91_PIO_PORTB, 14, PUP); /* SPI1_SPCK */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 131 | |
| 132 | /* Enable clock */ |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 133 | writel(1 << ATMEL_ID_SPI1, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 134 | |
| 135 | if (cs_mask & (1 << 0)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 136 | at91_set_a_periph(AT91_PIO_PORTB, 15, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 137 | } |
| 138 | if (cs_mask & (1 << 1)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 139 | at91_set_a_periph(AT91_PIO_PORTB, 16, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 140 | } |
| 141 | if (cs_mask & (1 << 2)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 142 | at91_set_a_periph(AT91_PIO_PORTB, 17, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 143 | } |
| 144 | if (cs_mask & (1 << 3)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 145 | at91_set_a_periph(AT91_PIO_PORTB, 18, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 146 | } |
| 147 | if (cs_mask & (1 << 4)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 148 | at91_set_pio_output(AT91_PIO_PORTB, 15, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 149 | } |
| 150 | if (cs_mask & (1 << 5)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 151 | at91_set_pio_output(AT91_PIO_PORTB, 16, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 152 | } |
| 153 | if (cs_mask & (1 << 6)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 154 | at91_set_pio_output(AT91_PIO_PORTB, 17, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 155 | } |
| 156 | if (cs_mask & (1 << 7)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 157 | at91_set_pio_output(AT91_PIO_PORTB, 18, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | #ifdef CONFIG_MACB |
| 163 | void at91_macb_hw_init(void) |
| 164 | { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 165 | at91_set_a_periph(AT91_PIO_PORTE, 21, 0); /* ETXCK_EREFCK */ |
| 166 | at91_set_b_periph(AT91_PIO_PORTC, 25, 0); /* ERXDV */ |
| 167 | at91_set_a_periph(AT91_PIO_PORTE, 25, 0); /* ERX0 */ |
| 168 | at91_set_a_periph(AT91_PIO_PORTE, 26, 0); /* ERX1 */ |
| 169 | at91_set_a_periph(AT91_PIO_PORTE, 27, 0); /* ERXER */ |
| 170 | at91_set_a_periph(AT91_PIO_PORTE, 28, 0); /* ETXEN */ |
| 171 | at91_set_a_periph(AT91_PIO_PORTE, 23, 0); /* ETX0 */ |
| 172 | at91_set_a_periph(AT91_PIO_PORTE, 24, 0); /* ETX1 */ |
| 173 | at91_set_a_periph(AT91_PIO_PORTE, 30, 0); /* EMDIO */ |
| 174 | at91_set_a_periph(AT91_PIO_PORTE, 29, 0); /* EMDC */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 175 | |
| 176 | #ifndef CONFIG_RMII |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 177 | at91_set_a_periph(AT91_PIO_PORTE, 22, 0); /* ECRS */ |
| 178 | at91_set_b_periph(AT91_PIO_PORTC, 26, 0); /* ECOL */ |
| 179 | at91_set_b_periph(AT91_PIO_PORTC, 22, 0); /* ERX2 */ |
| 180 | at91_set_b_periph(AT91_PIO_PORTC, 23, 0); /* ERX3 */ |
| 181 | at91_set_b_periph(AT91_PIO_PORTC, 27, 0); /* ERXCK */ |
| 182 | at91_set_b_periph(AT91_PIO_PORTC, 20, 0); /* ETX2 */ |
| 183 | at91_set_b_periph(AT91_PIO_PORTC, 21, 0); /* ETX3 */ |
| 184 | at91_set_b_periph(AT91_PIO_PORTC, 24, 0); /* ETXER */ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 185 | #endif |
| 186 | } |
| 187 | #endif |
| 188 | |
| 189 | #ifdef CONFIG_USB_OHCI_NEW |
| 190 | void at91_uhp_hw_init(void) |
| 191 | { |
| 192 | /* Enable VBus on UHP ports */ |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 193 | at91_set_pio_output(AT91_PIO_PORTA, 21, 0); |
| 194 | at91_set_pio_output(AT91_PIO_PORTA, 24, 0); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 195 | } |
| 196 | #endif |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 197 | |
| 198 | #ifdef CONFIG_AT91_CAN |
| 199 | void at91_can_hw_init(void) |
| 200 | { |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 201 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 202 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 203 | at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* CAN_TX */ |
| 204 | at91_set_a_periph(AT91_PIO_PORTA, 14, 1); /* CAN_RX */ |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 205 | |
| 206 | /* Enable clock */ |
Daniel Gorsulowski | bbe1169 | 2011-01-20 23:12:15 +0000 | [diff] [blame] | 207 | writel(1 << ATMEL_ID_CAN, &pmc->pcer); |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 208 | } |
| 209 | #endif |