1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
262011840SMasahiro Yamada /*
362011840SMasahiro Yamada * (C) Copyright 2007-2008
462011840SMasahiro Yamada * Stelian Pop <stelian@popies.net>
562011840SMasahiro Yamada * Lead Tech Design <www.leadtechdesign.com>
662011840SMasahiro Yamada */
762011840SMasahiro Yamada
862011840SMasahiro Yamada #include <common.h>
9b3ab0fc7SSimon Glass #include <dm.h>
1062011840SMasahiro Yamada #include <asm/arch/at91_common.h>
11eced5a7eSWenyou Yang #include <asm/arch/clk.h>
1262011840SMasahiro Yamada #include <asm/arch/gpio.h>
1362011840SMasahiro Yamada #include <asm/io.h>
1462011840SMasahiro Yamada
1562011840SMasahiro Yamada /*
1662011840SMasahiro Yamada * if CONFIG_AT91_GPIO_PULLUP ist set, keep pullups on on all
1762011840SMasahiro Yamada * peripheral pins. Good to have if hardware is soldered optionally
1862011840SMasahiro Yamada * or in case of SPI no slave is selected. Avoid lines to float
1962011840SMasahiro Yamada * needlessly. Use a short local PUP define.
2062011840SMasahiro Yamada *
2162011840SMasahiro Yamada * Due to errata "TXD floats when CTS is inactive" pullups are always
2262011840SMasahiro Yamada * on for TXD pins.
2362011840SMasahiro Yamada */
2462011840SMasahiro Yamada #ifdef CONFIG_AT91_GPIO_PULLUP
2562011840SMasahiro Yamada # define PUP CONFIG_AT91_GPIO_PULLUP
2662011840SMasahiro Yamada #else
2762011840SMasahiro Yamada # define PUP 0
2862011840SMasahiro Yamada #endif
2962011840SMasahiro Yamada
at91_serial0_hw_init(void)3062011840SMasahiro Yamada void at91_serial0_hw_init(void)
3162011840SMasahiro Yamada {
3262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 19, 1); /* TXD0 */
3362011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 18, PUP); /* RXD0 */
34eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_USART0);
3562011840SMasahiro Yamada }
3662011840SMasahiro Yamada
at91_serial1_hw_init(void)3762011840SMasahiro Yamada void at91_serial1_hw_init(void)
3862011840SMasahiro Yamada {
3962011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 4, 1); /* TXD1 */
4062011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 5, PUP); /* RXD1 */
41eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_USART1);
4262011840SMasahiro Yamada }
4362011840SMasahiro Yamada
at91_serial2_hw_init(void)4462011840SMasahiro Yamada void at91_serial2_hw_init(void)
4562011840SMasahiro Yamada {
4662011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTD, 6, 1); /* TXD2 */
4762011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTD, 7, PUP); /* RXD2 */
48eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_USART2);
4962011840SMasahiro Yamada }
5062011840SMasahiro Yamada
at91_seriald_hw_init(void)5162011840SMasahiro Yamada void at91_seriald_hw_init(void)
5262011840SMasahiro Yamada {
5362011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* DRXD */
5462011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 13, 1); /* DTXD */
55eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_SYS);
5662011840SMasahiro Yamada }
5762011840SMasahiro Yamada
58c68c03f5STuomas Tynkkynen #ifdef CONFIG_ATMEL_SPI
at91_spi0_hw_init(unsigned long cs_mask)5962011840SMasahiro Yamada void at91_spi0_hw_init(unsigned long cs_mask)
6062011840SMasahiro Yamada {
6162011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 0, PUP); /* SPI0_MISO */
6262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 1, PUP); /* SPI0_MOSI */
6362011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 2, PUP); /* SPI0_SPCK */
6462011840SMasahiro Yamada
65eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_SPI0);
6662011840SMasahiro Yamada
6762011840SMasahiro Yamada if (cs_mask & (1 << 0)) {
6862011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 3, 1);
6962011840SMasahiro Yamada }
7062011840SMasahiro Yamada if (cs_mask & (1 << 1)) {
7162011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTB, 18, 1);
7262011840SMasahiro Yamada }
7362011840SMasahiro Yamada if (cs_mask & (1 << 2)) {
7462011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTB, 19, 1);
7562011840SMasahiro Yamada }
7662011840SMasahiro Yamada if (cs_mask & (1 << 3)) {
7762011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTD, 27, 1);
7862011840SMasahiro Yamada }
7962011840SMasahiro Yamada if (cs_mask & (1 << 4)) {
8062011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTB, 3, 1);
8162011840SMasahiro Yamada }
8262011840SMasahiro Yamada if (cs_mask & (1 << 5)) {
8362011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
8462011840SMasahiro Yamada }
8562011840SMasahiro Yamada if (cs_mask & (1 << 6)) {
8662011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTB, 19, 1);
8762011840SMasahiro Yamada }
8862011840SMasahiro Yamada if (cs_mask & (1 << 7)) {
8962011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTD, 27, 1);
9062011840SMasahiro Yamada }
9162011840SMasahiro Yamada }
9262011840SMasahiro Yamada
at91_spi1_hw_init(unsigned long cs_mask)9362011840SMasahiro Yamada void at91_spi1_hw_init(unsigned long cs_mask)
9462011840SMasahiro Yamada {
9562011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 14, PUP); /* SPI1_MISO */
9662011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 15, PUP); /* SPI1_MOSI */
9762011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 16, PUP); /* SPI1_SPCK */
9862011840SMasahiro Yamada
99eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_SPI1);
10062011840SMasahiro Yamada
10162011840SMasahiro Yamada if (cs_mask & (1 << 0)) {
10262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
10362011840SMasahiro Yamada }
10462011840SMasahiro Yamada if (cs_mask & (1 << 1)) {
10562011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTD, 28, 1);
10662011840SMasahiro Yamada }
10762011840SMasahiro Yamada if (cs_mask & (1 << 2)) {
10862011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTD, 18, 1);
10962011840SMasahiro Yamada }
11062011840SMasahiro Yamada if (cs_mask & (1 << 3)) {
11162011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTD, 19, 1);
11262011840SMasahiro Yamada }
11362011840SMasahiro Yamada if (cs_mask & (1 << 4)) {
11462011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
11562011840SMasahiro Yamada }
11662011840SMasahiro Yamada if (cs_mask & (1 << 5)) {
11762011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTD, 28, 1);
11862011840SMasahiro Yamada }
11962011840SMasahiro Yamada if (cs_mask & (1 << 6)) {
12062011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTD, 18, 1);
12162011840SMasahiro Yamada }
12262011840SMasahiro Yamada if (cs_mask & (1 << 7)) {
12362011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTD, 19, 1);
12462011840SMasahiro Yamada }
12562011840SMasahiro Yamada
12662011840SMasahiro Yamada }
12762011840SMasahiro Yamada #endif
12862011840SMasahiro Yamada
12962011840SMasahiro Yamada #ifdef CONFIG_MACB
at91_macb_hw_init(void)13062011840SMasahiro Yamada void at91_macb_hw_init(void)
13162011840SMasahiro Yamada {
13262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 17, 0); /* ETXCK_EREFCK */
13362011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 15, 0); /* ERXDV */
13462011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* ERX0 */
13562011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* ERX1 */
13662011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 16, 0); /* ERXER */
13762011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 14, 0); /* ETXEN */
13862011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 10, 0); /* ETX0 */
13962011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* ETX1 */
14062011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 19, 0); /* EMDIO */
14162011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 18, 0); /* EMDC */
14262011840SMasahiro Yamada #ifndef CONFIG_RMII
14362011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 29, 0); /* ECRS */
14462011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 30, 0); /* ECOL */
14562011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 8, 0); /* ERX2 */
14662011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 9, 0); /* ERX3 */
14762011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 28, 0); /* ERXCK */
14862011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 6, 0); /* ETX2 */
14962011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 7, 0); /* ETX3 */
15062011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTA, 27, 0); /* ETXER */
15162011840SMasahiro Yamada #endif
15262011840SMasahiro Yamada }
15362011840SMasahiro Yamada #endif
15462011840SMasahiro Yamada
15562011840SMasahiro Yamada #ifdef CONFIG_GENERIC_ATMEL_MCI
at91_mci_hw_init(void)15662011840SMasahiro Yamada void at91_mci_hw_init(void)
15762011840SMasahiro Yamada {
15862011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 0, 0); /* MCI0 CLK */
15962011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* MCI0 CDA */
16062011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 2, 0); /* MCI0 DA0 */
16162011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 3, 0); /* MCI0 DA1 */
16262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 4, 0); /* MCI0 DA2 */
16362011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 5, 0); /* MCI0 DA3 */
16462011840SMasahiro Yamada
165eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_MCI0);
16662011840SMasahiro Yamada }
16762011840SMasahiro Yamada #endif
168b3ab0fc7SSimon Glass
169b3ab0fc7SSimon Glass /* Platform data for the GPIOs */
170b3ab0fc7SSimon Glass static const struct at91_port_platdata at91sam9260_plat[] = {
171b3ab0fc7SSimon Glass { ATMEL_BASE_PIOA, "PA" },
172b3ab0fc7SSimon Glass { ATMEL_BASE_PIOB, "PB" },
173b3ab0fc7SSimon Glass { ATMEL_BASE_PIOC, "PC" },
174b3ab0fc7SSimon Glass { ATMEL_BASE_PIOD, "PD" },
175b3ab0fc7SSimon Glass { ATMEL_BASE_PIOE, "PE" },
176b3ab0fc7SSimon Glass };
177b3ab0fc7SSimon Glass
178b3ab0fc7SSimon Glass U_BOOT_DEVICES(at91sam9260_gpios) = {
179b3ab0fc7SSimon Glass { "gpio_at91", &at91sam9260_plat[0] },
180b3ab0fc7SSimon Glass { "gpio_at91", &at91sam9260_plat[1] },
181b3ab0fc7SSimon Glass { "gpio_at91", &at91sam9260_plat[2] },
182b3ab0fc7SSimon Glass { "gpio_at91", &at91sam9260_plat[3] },
183b3ab0fc7SSimon Glass { "gpio_at91", &at91sam9260_plat[4] },
184b3ab0fc7SSimon Glass };
185