blob: 0e6c0da1bdd4cfeefb2c7f3e20d207550b76c4c6 [file] [log] [blame]
Sedji Gaouaou538566d2009-07-09 10:16:29 +02001/*
2 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Sedji Gaouaou538566d2009-07-09 10:16:29 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Sedji Gaouaou538566d2009-07-09 10:16:29 +02007 */
8
9#include <common.h>
10#include <asm/arch/at91_common.h>
11#include <asm/arch/at91_pmc.h>
12#include <asm/arch/gpio.h>
Thomas Petazzonib0263c52011-08-04 08:53:29 +000013#include <asm/io.h>
14
15/*
16 * if CONFIG_AT91_GPIO_PULLUP ist set, keep pullups on on all
17 * peripheral pins. Good to have if hardware is soldered optionally
18 * or in case of SPI no slave is selected. Avoid lines to float
19 * needlessly. Use a short local PUP define.
20 *
21 * Due to errata "TXD floats when CTS is inactive" pullups are always
22 * on for TXD pins.
23 */
24#ifdef CONFIG_AT91_GPIO_PULLUP
25# define PUP CONFIG_AT91_GPIO_PULLUP
26#else
27# define PUP 0
28#endif
Sedji Gaouaou538566d2009-07-09 10:16:29 +020029
30void at91_serial0_hw_init(void)
31{
Thomas Petazzonib0263c52011-08-04 08:53:29 +000032 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010033
Jens Scharsigb49d15c2010-02-03 22:46:46 +010034 at91_set_a_periph(AT91_PIO_PORTB, 19, 1); /* TXD0 */
Thomas Petazzonib0263c52011-08-04 08:53:29 +000035 at91_set_a_periph(AT91_PIO_PORTB, 18, PUP); /* RXD0 */
36 writel(1 << ATMEL_ID_USART0, &pmc->pcer);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020037}
38
39void at91_serial1_hw_init(void)
40{
Thomas Petazzonib0263c52011-08-04 08:53:29 +000041 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010042
Jens Scharsigb49d15c2010-02-03 22:46:46 +010043 at91_set_a_periph(AT91_PIO_PORTB, 4, 1); /* TXD1 */
Thomas Petazzonib0263c52011-08-04 08:53:29 +000044 at91_set_a_periph(AT91_PIO_PORTB, 5, PUP); /* RXD1 */
45 writel(1 << ATMEL_ID_USART1, &pmc->pcer);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020046}
47
48void at91_serial2_hw_init(void)
49{
Thomas Petazzonib0263c52011-08-04 08:53:29 +000050 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010051
Jens Scharsigb49d15c2010-02-03 22:46:46 +010052 at91_set_a_periph(AT91_PIO_PORTD, 6, 1); /* TXD2 */
Thomas Petazzonib0263c52011-08-04 08:53:29 +000053 at91_set_a_periph(AT91_PIO_PORTD, 7, PUP); /* RXD2 */
54 writel(1 << ATMEL_ID_USART2, &pmc->pcer);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020055}
56
Thomas Petazzonib0263c52011-08-04 08:53:29 +000057void at91_seriald_hw_init(void)
Sedji Gaouaou538566d2009-07-09 10:16:29 +020058{
Thomas Petazzonib0263c52011-08-04 08:53:29 +000059 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010060
Jens Scharsigb49d15c2010-02-03 22:46:46 +010061 at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* DRXD */
62 at91_set_a_periph(AT91_PIO_PORTB, 13, 1); /* DTXD */
Thomas Petazzonib0263c52011-08-04 08:53:29 +000063 writel(1 << ATMEL_ID_SYS, &pmc->pcer);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020064}
65
Thomas Petazzonib0263c52011-08-04 08:53:29 +000066#if defined(CONFIG_HAS_DATAFLASH) || defined(CONFIG_ATMEL_SPI)
Sedji Gaouaou538566d2009-07-09 10:16:29 +020067void at91_spi0_hw_init(unsigned long cs_mask)
68{
Thomas Petazzonib0263c52011-08-04 08:53:29 +000069 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +010070
Thomas Petazzonib0263c52011-08-04 08:53:29 +000071 at91_set_a_periph(AT91_PIO_PORTB, 0, PUP); /* SPI0_MISO */
72 at91_set_a_periph(AT91_PIO_PORTB, 1, PUP); /* SPI0_MOSI */
73 at91_set_a_periph(AT91_PIO_PORTB, 2, PUP); /* SPI0_SPCK */
Sedji Gaouaou538566d2009-07-09 10:16:29 +020074
75 /* Enable clock */
Thomas Petazzonib0263c52011-08-04 08:53:29 +000076 writel(1 << ATMEL_ID_SPI0, &pmc->pcer);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020077
78 if (cs_mask & (1 << 0)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +000079 at91_set_a_periph(AT91_PIO_PORTB, 3, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020080 }
81 if (cs_mask & (1 << 1)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +000082 at91_set_b_periph(AT91_PIO_PORTB, 18, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020083 }
84 if (cs_mask & (1 << 2)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +000085 at91_set_b_periph(AT91_PIO_PORTB, 19, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020086 }
87 if (cs_mask & (1 << 3)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +000088 at91_set_b_periph(AT91_PIO_PORTD, 27, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020089 }
90 if (cs_mask & (1 << 4)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +000091 at91_set_pio_output(AT91_PIO_PORTB, 3, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020092 }
93 if (cs_mask & (1 << 5)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +000094 at91_set_pio_output(AT91_PIO_PORTB, 18, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020095 }
96 if (cs_mask & (1 << 6)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +000097 at91_set_pio_output(AT91_PIO_PORTB, 19, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +020098 }
99 if (cs_mask & (1 << 7)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000100 at91_set_pio_output(AT91_PIO_PORTD, 27, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200101 }
102}
103
104void at91_spi1_hw_init(unsigned long cs_mask)
105{
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000106 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Jens Scharsiga4db1ca2010-02-03 22:46:58 +0100107
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000108 at91_set_a_periph(AT91_PIO_PORTB, 14, PUP); /* SPI1_MISO */
109 at91_set_a_periph(AT91_PIO_PORTB, 15, PUP); /* SPI1_MOSI */
110 at91_set_a_periph(AT91_PIO_PORTB, 16, PUP); /* SPI1_SPCK */
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200111
112 /* Enable clock */
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000113 writel(1 << ATMEL_ID_SPI1, &pmc->pcer);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200114
115 if (cs_mask & (1 << 0)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000116 at91_set_a_periph(AT91_PIO_PORTB, 17, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200117 }
118 if (cs_mask & (1 << 1)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000119 at91_set_b_periph(AT91_PIO_PORTD, 28, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200120 }
121 if (cs_mask & (1 << 2)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000122 at91_set_a_periph(AT91_PIO_PORTD, 18, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200123 }
124 if (cs_mask & (1 << 3)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000125 at91_set_a_periph(AT91_PIO_PORTD, 19, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200126 }
127 if (cs_mask & (1 << 4)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000128 at91_set_pio_output(AT91_PIO_PORTB, 17, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200129 }
130 if (cs_mask & (1 << 5)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000131 at91_set_pio_output(AT91_PIO_PORTD, 28, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200132 }
133 if (cs_mask & (1 << 6)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000134 at91_set_pio_output(AT91_PIO_PORTD, 18, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200135 }
136 if (cs_mask & (1 << 7)) {
Thomas Petazzonib0263c52011-08-04 08:53:29 +0000137 at91_set_pio_output(AT91_PIO_PORTD, 19, 1);
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200138 }
139
140}
141#endif
142
143#ifdef CONFIG_MACB
144void at91_macb_hw_init(void)
145{
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100146 at91_set_a_periph(AT91_PIO_PORTA, 17, 0); /* ETXCK_EREFCK */
147 at91_set_a_periph(AT91_PIO_PORTA, 15, 0); /* ERXDV */
148 at91_set_a_periph(AT91_PIO_PORTA, 12, 0); /* ERX0 */
149 at91_set_a_periph(AT91_PIO_PORTA, 13, 0); /* ERX1 */
150 at91_set_a_periph(AT91_PIO_PORTA, 16, 0); /* ERXER */
151 at91_set_a_periph(AT91_PIO_PORTA, 14, 0); /* ETXEN */
152 at91_set_a_periph(AT91_PIO_PORTA, 10, 0); /* ETX0 */
153 at91_set_a_periph(AT91_PIO_PORTA, 11, 0); /* ETX1 */
154 at91_set_a_periph(AT91_PIO_PORTA, 19, 0); /* EMDIO */
155 at91_set_a_periph(AT91_PIO_PORTA, 18, 0); /* EMDC */
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200156#ifndef CONFIG_RMII
Jens Scharsigb49d15c2010-02-03 22:46:46 +0100157 at91_set_b_periph(AT91_PIO_PORTA, 29, 0); /* ECRS */
158 at91_set_b_periph(AT91_PIO_PORTA, 30, 0); /* ECOL */
159 at91_set_b_periph(AT91_PIO_PORTA, 8, 0); /* ERX2 */
160 at91_set_b_periph(AT91_PIO_PORTA, 9, 0); /* ERX3 */
161 at91_set_b_periph(AT91_PIO_PORTA, 28, 0); /* ERXCK */
162 at91_set_b_periph(AT91_PIO_PORTA, 6, 0); /* ETX2 */
163 at91_set_b_periph(AT91_PIO_PORTA, 7, 0); /* ETX3 */
164 at91_set_b_periph(AT91_PIO_PORTA, 27, 0); /* ETXER */
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200165#endif
166}
167#endif
Wu, Joshdff665a2014-05-21 10:42:15 +0800168
169#ifdef CONFIG_GENERIC_ATMEL_MCI
170void at91_mci_hw_init(void)
171{
172 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
173
174 at91_set_a_periph(AT91_PIO_PORTA, 0, 0); /* MCI0 CLK */
175 at91_set_a_periph(AT91_PIO_PORTA, 1, 0); /* MCI0 CDA */
176 at91_set_a_periph(AT91_PIO_PORTA, 2, 0); /* MCI0 DA0 */
177 at91_set_a_periph(AT91_PIO_PORTA, 3, 0); /* MCI0 DA1 */
178 at91_set_a_periph(AT91_PIO_PORTA, 4, 0); /* MCI0 DA2 */
179 at91_set_a_periph(AT91_PIO_PORTA, 5, 0); /* MCI0 DA3 */
180
181 /* Enable clock */
182 writel(1 << ATMEL_ID_MCI0, &pmc->pcer);
183}
184#endif