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 | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 11 | */ |
| 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 | |
| 19 | void at91_serial0_hw_init(void) |
| 20 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 21 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 22 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 23 | at91_set_a_periph(AT91_PIO_PORTA, 22, 1); /* TXD0 */ |
| 24 | at91_set_a_periph(AT91_PIO_PORTA, 23, 0); /* RXD0 */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 25 | writel(1 << AT91CAP9_ID_US0, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void at91_serial1_hw_init(void) |
| 29 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 30 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 31 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 32 | at91_set_a_periph(AT91_PIO_PORTD, 0, 1); /* TXD1 */ |
| 33 | at91_set_a_periph(AT91_PIO_PORTD, 1, 0); /* RXD1 */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 34 | writel(1 << AT91CAP9_ID_US1, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void at91_serial2_hw_init(void) |
| 38 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 39 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 40 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 41 | at91_set_a_periph(AT91_PIO_PORTD, 2, 1); /* TXD2 */ |
| 42 | at91_set_a_periph(AT91_PIO_PORTD, 3, 0); /* RXD2 */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 43 | writel(1 << AT91CAP9_ID_US2, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void at91_serial3_hw_init(void) |
| 47 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 48 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 49 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 50 | at91_set_a_periph(AT91_PIO_PORTC, 30, 0); /* DRXD */ |
| 51 | at91_set_a_periph(AT91_PIO_PORTC, 31, 1); /* DTXD */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 52 | writel(1 << AT91_ID_SYS, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void 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 |
| 75 | void at91_spi0_hw_init(unsigned long cs_mask) |
| 76 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 77 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 78 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 79 | 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-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 82 | |
| 83 | /* Enable clock */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 84 | writel(1 << AT91CAP9_ID_SPI0, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 85 | |
| 86 | if (cs_mask & (1 << 0)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 87 | at91_set_b_periph(AT91_PIO_PORTA, 5, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 88 | } |
| 89 | if (cs_mask & (1 << 1)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 90 | at91_set_b_periph(AT91_PIO_PORTA, 3, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 91 | } |
| 92 | if (cs_mask & (1 << 2)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 93 | at91_set_b_periph(AT91_PIO_PORTD, 0, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 94 | } |
| 95 | if (cs_mask & (1 << 3)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 96 | at91_set_b_periph(AT91_PIO_PORTD, 1, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 97 | } |
| 98 | if (cs_mask & (1 << 4)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 99 | at91_set_pio_output(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 << 5)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 102 | at91_set_pio_output(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 << 6)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 105 | at91_set_pio_output(AT91_PIO_PORTD, 0, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 106 | } |
| 107 | if (cs_mask & (1 << 7)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 108 | at91_set_pio_output(AT91_PIO_PORTD, 1, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | void at91_spi1_hw_init(unsigned long cs_mask) |
| 113 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 114 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 115 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 116 | 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-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 119 | |
| 120 | /* Enable clock */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 121 | writel(1 << AT91CAP9_ID_SPI1, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 122 | |
| 123 | if (cs_mask & (1 << 0)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 124 | at91_set_a_periph(AT91_PIO_PORTB, 15, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 125 | } |
| 126 | if (cs_mask & (1 << 1)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 127 | at91_set_a_periph(AT91_PIO_PORTB, 16, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 128 | } |
| 129 | if (cs_mask & (1 << 2)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 130 | at91_set_a_periph(AT91_PIO_PORTB, 17, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 131 | } |
| 132 | if (cs_mask & (1 << 3)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 133 | at91_set_a_periph(AT91_PIO_PORTB, 18, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 134 | } |
| 135 | if (cs_mask & (1 << 4)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 136 | at91_set_pio_output(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 << 5)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 139 | at91_set_pio_output(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 << 6)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 142 | at91_set_pio_output(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 << 7)) { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 145 | at91_set_pio_output(AT91_PIO_PORTB, 18, 1); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | } |
| 149 | #endif |
| 150 | |
| 151 | #ifdef CONFIG_MACB |
| 152 | void at91_macb_hw_init(void) |
| 153 | { |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 154 | 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-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 164 | |
| 165 | #ifndef CONFIG_RMII |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 166 | 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-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 174 | #endif |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 175 | } |
| 176 | #endif |
| 177 | |
| 178 | #ifdef CONFIG_AT91_CAN |
| 179 | void at91_can_hw_init(void) |
| 180 | { |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 181 | at91_pmc_t *pmc = (at91_pmc_t *) AT91_PMC_BASE; |
| 182 | |
Jens Scharsig | b49d15c | 2010-02-03 22:46:46 +0100 | [diff] [blame] | 183 | at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* CAN_TX */ |
| 184 | at91_set_a_periph(AT91_PIO_PORTA, 13, 1); /* CAN_RX */ |
Daniel Gorsulowski | 96d1b47 | 2009-06-30 23:03:33 +0200 | [diff] [blame] | 185 | |
| 186 | /* Enable clock */ |
Jens Scharsig | a4db1ca | 2010-02-03 22:46:58 +0100 | [diff] [blame] | 187 | writel(1 << AT91CAP9_ID_CAN, &pmc->pcer); |
Jean-Christophe PLAGNIOL-VILLARD | 2495b2d | 2009-05-13 21:01:13 +0200 | [diff] [blame] | 188 | } |
| 189 | #endif |