blob: ecf261c1aec654a3f68128c69e491b0aad7f7818 [file] [log] [blame]
Albin Tonnerre94539672009-08-24 18:03:26 +02001/*
2 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Albin Tonnerre94539672009-08-24 18:03:26 +02004 * Lead Tech Design <www.leadtechdesign.com>
5 *
6 * Copyright (C) 2009
7 * Albin Tonnerre, Free-Electrons <albin.tonnerre@free-electrons.com>
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Albin Tonnerre94539672009-08-24 18:03:26 +020010 */
11
12#include <common.h>
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000013#include <asm/io.h>
Albin Tonnerre94539672009-08-24 18:03:26 +020014#include <asm/arch/at91sam9260_matrix.h>
15#include <asm/arch/at91sam9_smc.h>
16#include <asm/arch/at91_common.h>
17#include <asm/arch/at91_pmc.h>
18#include <asm/arch/at91_rstc.h>
19#include <asm/arch/gpio.h>
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000020
Albin Tonnerre94539672009-08-24 18:03:26 +020021#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
22#include <net.h>
23#endif
24#include <netdev.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
28/* ------------------------------------------------------------------------- */
29/*
30 * Miscelaneous platform dependent initialisations
31 */
32
33#ifdef CONFIG_CMD_NAND
34static void sbc35_a9g20_nand_hw_init(void)
35{
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000036 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
37 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
38 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Albin Tonnerre94539672009-08-24 18:03:26 +020039 unsigned long csa;
40
41 /* Enable CS3 */
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000042 csa = readl(&matrix->ebicsa);
43 csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA;
44 writel(csa, &matrix->ebicsa);
Albin Tonnerre94539672009-08-24 18:03:26 +020045
46 /* Configure SMC CS3 for NAND/SmartMedia */
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000047 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
48 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
49 &smc->cs[3].setup);
50 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
51 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
52 &smc->cs[3].pulse);
53 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
54 &smc->cs[3].cycle);
55 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
56 AT91_SMC_MODE_EXNW_DISABLE |
Albin Tonnerre94539672009-08-24 18:03:26 +020057#ifdef CONFIG_SYS_NAND_DBW_16
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000058 AT91_SMC_MODE_DBW_16 |
Albin Tonnerre94539672009-08-24 18:03:26 +020059#else /* CONFIG_SYS_NAND_DBW_8 */
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000060 AT91_SMC_MODE_DBW_8 |
Albin Tonnerre94539672009-08-24 18:03:26 +020061#endif
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000062 AT91_SMC_MODE_TDF_CYCLE(2),
63 &smc->cs[3].mode);
Albin Tonnerre94539672009-08-24 18:03:26 +020064
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000065 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Albin Tonnerre94539672009-08-24 18:03:26 +020066
67 /* Configure RDY/BSY */
68 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
69
70 /* Enable NandFlash */
71 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
72}
73#endif
74
75#ifdef CONFIG_MACB
76static void sbc35_a9g20_macb_hw_init(void)
77{
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000078 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
79 struct at91_port *pioa = (struct at91_port *)ATMEL_BASE_PIOA;
80 struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
81 unsigned long erstl;
Albin Tonnerre94539672009-08-24 18:03:26 +020082
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +000083 /* Enable EMAC clock */
84 writel(1 << ATMEL_ID_EMAC0, &pmc->pcer);
Albin Tonnerre94539672009-08-24 18:03:26 +020085
86 /*
87 * Disable pull-up on:
88 * RXDV (PA17) => PHY normal mode (not Test mode)
89 * ERX0 (PA14) => PHY ADDR0
90 * ERX1 (PA15) => PHY ADDR1
91 * ERX2 (PA25) => PHY ADDR2
92 * ERX3 (PA26) => PHY ADDR3
93 * ECRS (PA28) => PHY ADDR4 => PHYADDR = 0x0
94 *
95 * PHY has internal pull-down
96 */
97 writel(pin_to_mask(AT91_PIN_PA14) |
98 pin_to_mask(AT91_PIN_PA15) |
99 pin_to_mask(AT91_PIN_PA17) |
100 pin_to_mask(AT91_PIN_PA25) |
101 pin_to_mask(AT91_PIN_PA26) |
102 pin_to_mask(AT91_PIN_PA28),
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000103 &pioa->pudr);
Albin Tonnerre94539672009-08-24 18:03:26 +0200104
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000105 erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
Albin Tonnerre94539672009-08-24 18:03:26 +0200106
107 /* Need to reset PHY -> 500ms reset */
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000108 writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
109 AT91_RSTC_MR_URSTEN, &rstc->mr);
Albin Tonnerre94539672009-08-24 18:03:26 +0200110
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000111 writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
Albin Tonnerre94539672009-08-24 18:03:26 +0200112
113 /* Wait for end hardware reset */
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000114 while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL))
115 ;
Albin Tonnerre94539672009-08-24 18:03:26 +0200116
117 /* Restore NRST value */
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000118 writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
119 &rstc->mr);
Albin Tonnerre94539672009-08-24 18:03:26 +0200120
121 /* Re-enable pull-up */
122 writel(pin_to_mask(AT91_PIN_PA14) |
123 pin_to_mask(AT91_PIN_PA15) |
124 pin_to_mask(AT91_PIN_PA17) |
125 pin_to_mask(AT91_PIN_PA25) |
126 pin_to_mask(AT91_PIN_PA26) |
127 pin_to_mask(AT91_PIN_PA28),
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000128 &pioa->puer);
Albin Tonnerre94539672009-08-24 18:03:26 +0200129
130 at91_macb_hw_init();
131}
132#endif
133
134int board_init(void)
135{
Albin Tonnerre94539672009-08-24 18:03:26 +0200136 /* adress of boot parameters */
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000137 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Albin Tonnerre94539672009-08-24 18:03:26 +0200138
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000139 at91_seriald_hw_init();
Albin Tonnerre94539672009-08-24 18:03:26 +0200140 sbc35_a9g20_nand_hw_init();
141#ifdef CONFIG_ATMEL_SPI
142 at91_spi0_hw_init(1 << 4 | 1 << 5);
143#endif
144#ifdef CONFIG_MACB
145 sbc35_a9g20_macb_hw_init();
146#endif
147
148 return 0;
149}
150
151int dram_init(void)
152{
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000153 gd->ram_size = get_ram_size(
154 (void *)CONFIG_SYS_SDRAM_BASE,
155 CONFIG_SYS_SDRAM_SIZE);
Albin Tonnerre94539672009-08-24 18:03:26 +0200156 return 0;
157}
158
159#ifdef CONFIG_RESET_PHY_R
160void reset_phy(void)
161{
Albin Tonnerre94539672009-08-24 18:03:26 +0200162}
163#endif
164
165int board_eth_init(bd_t *bis)
166{
167 int rc = 0;
168#ifdef CONFIG_MACB
Thomas Petazzoni6785c7c2011-08-04 02:22:20 +0000169 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC0, 0x00);
Albin Tonnerre94539672009-08-24 18:03:26 +0200170#endif
171 return rc;
172}