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>
962011840SMasahiro Yamada #include <asm/io.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
1462011840SMasahiro Yamada /*
1562011840SMasahiro Yamada * if CONFIG_AT91_GPIO_PULLUP ist set, keep pullups on on all
1662011840SMasahiro Yamada * peripheral pins. Good to have if hardware is soldered optionally
1762011840SMasahiro Yamada * or in case of SPI no slave is selected. Avoid lines to float
1862011840SMasahiro Yamada * needlessly. Use a short local PUP define.
1962011840SMasahiro Yamada *
2062011840SMasahiro Yamada * Due to errata "TXD floats when CTS is inactive" pullups are always
2162011840SMasahiro Yamada * on for TXD pins.
2262011840SMasahiro Yamada */
2362011840SMasahiro Yamada #ifdef CONFIG_AT91_GPIO_PULLUP
2462011840SMasahiro Yamada # define PUP CONFIG_AT91_GPIO_PULLUP
2562011840SMasahiro Yamada #else
2662011840SMasahiro Yamada # define PUP 0
2762011840SMasahiro Yamada #endif
2862011840SMasahiro Yamada
at91_serial0_hw_init(void)2962011840SMasahiro Yamada void at91_serial0_hw_init(void)
3062011840SMasahiro Yamada {
3162011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 6, 1); /* TXD0 */
3262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 7, PUP); /* RXD0 */
33eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_USART0);
3462011840SMasahiro Yamada }
3562011840SMasahiro Yamada
at91_serial1_hw_init(void)3662011840SMasahiro Yamada void at91_serial1_hw_init(void)
3762011840SMasahiro Yamada {
3862011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 11, 1); /* TXD1 */
3962011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 12, PUP); /* RXD1 */
40eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_USART1);
4162011840SMasahiro Yamada }
4262011840SMasahiro Yamada
at91_serial2_hw_init(void)4362011840SMasahiro Yamada void at91_serial2_hw_init(void)
4462011840SMasahiro Yamada {
4562011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 13, 1); /* TXD2 */
4662011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 14, PUP); /* RXD2 */
47eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_USART2);
4862011840SMasahiro Yamada }
4962011840SMasahiro Yamada
at91_seriald_hw_init(void)5062011840SMasahiro Yamada void at91_seriald_hw_init(void)
5162011840SMasahiro Yamada {
5262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 21, PUP); /* DRXD */
5362011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 22, 1); /* DTXD */
54eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_SYS);
5562011840SMasahiro Yamada }
5662011840SMasahiro Yamada
57c68c03f5STuomas Tynkkynen #ifdef CONFIG_ATMEL_SPI
at91_spi0_hw_init(unsigned long cs_mask)5862011840SMasahiro Yamada void at91_spi0_hw_init(unsigned long cs_mask)
5962011840SMasahiro Yamada {
6062011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 25, PUP); /* SPI0_MISO */
6162011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 26, PUP); /* SPI0_MOSI */
6262011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 27, PUP); /* SPI0_SPCK */
6362011840SMasahiro Yamada
64eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_SPI);
6562011840SMasahiro Yamada
6662011840SMasahiro Yamada if (cs_mask & (1 << 0)) {
6762011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTA, 28, 1);
6862011840SMasahiro Yamada }
6962011840SMasahiro Yamada if (cs_mask & (1 << 1)) {
7062011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTB, 7, 1);
7162011840SMasahiro Yamada }
7262011840SMasahiro Yamada if (cs_mask & (1 << 2)) {
7362011840SMasahiro Yamada at91_set_a_periph(AT91_PIO_PORTD, 8, 1);
7462011840SMasahiro Yamada }
7562011840SMasahiro Yamada if (cs_mask & (1 << 3)) {
7662011840SMasahiro Yamada at91_set_b_periph(AT91_PIO_PORTD, 9, 1);
7762011840SMasahiro Yamada }
7862011840SMasahiro Yamada if (cs_mask & (1 << 4)) {
7962011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTA, 28, 1);
8062011840SMasahiro Yamada }
8162011840SMasahiro Yamada if (cs_mask & (1 << 5)) {
8262011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTB, 7, 1);
8362011840SMasahiro Yamada }
8462011840SMasahiro Yamada if (cs_mask & (1 << 6)) {
8562011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTD, 8, 1);
8662011840SMasahiro Yamada }
8762011840SMasahiro Yamada if (cs_mask & (1 << 7)) {
8862011840SMasahiro Yamada at91_set_pio_output(AT91_PIO_PORTD, 9, 1);
8962011840SMasahiro Yamada }
9062011840SMasahiro Yamada }
9162011840SMasahiro Yamada #endif
92111ec4c6SWu, Josh
93111ec4c6SWu, Josh #ifdef CONFIG_GENERIC_ATMEL_MCI
at91_mci_hw_init(void)94111ec4c6SWu, Josh void at91_mci_hw_init(void)
95111ec4c6SWu, Josh {
96111ec4c6SWu, Josh at91_set_a_periph(AT91_PIO_PORTA, 2, 0); /* MCI CLK */
97111ec4c6SWu, Josh at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* MCI CDA */
98111ec4c6SWu, Josh at91_set_a_periph(AT91_PIO_PORTA, 0, 0); /* MCI DA0 */
99111ec4c6SWu, Josh at91_set_a_periph(AT91_PIO_PORTA, 3, 0); /* MCI DA1 */
100111ec4c6SWu, Josh at91_set_a_periph(AT91_PIO_PORTA, 4, 0); /* MCI DA2 */
101111ec4c6SWu, Josh at91_set_a_periph(AT91_PIO_PORTA, 5, 0); /* MCI DA3 */
102111ec4c6SWu, Josh
103eced5a7eSWenyou Yang at91_periph_clk_enable(ATMEL_ID_MCI);
104111ec4c6SWu, Josh }
105111ec4c6SWu, Josh #endif
106