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