blob: 5bb5a3c102da20a53e2667145f1e13d3584dc9cc [file] [log] [blame]
Asen Dimovb5d289f2010-04-20 22:49:04 +03001/*
2 * (C) Copyright 2010
3 * Ilko Iliev <iliev@ronetix.at>
4 * Asen Dimov <dimov@ronetix.at>
5 * Ronetix GmbH <www.ronetix.at>
6 *
7 * (C) Copyright 2007-2008
Stelian Popc9e798d2011-11-01 00:00:39 +01008 * Stelian Pop <stelian@popies.net>
Asen Dimovb5d289f2010-04-20 22:49:04 +03009 * Lead Tech Design <www.leadtechdesign.com>
10 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Asen Dimovb5d289f2010-04-20 22:49:04 +030012 */
13
14#include <common.h>
15#include <asm/sizes.h>
Asen Dimoveb6e6082011-06-08 22:01:37 +000016#include <asm/io.h>
Asen Dimovb5d289f2010-04-20 22:49:04 +030017#include <asm/arch/at91sam9_smc.h>
18#include <asm/arch/at91_common.h>
19#include <asm/arch/at91_pmc.h>
20#include <asm/arch/at91_rstc.h>
21#include <asm/arch/at91_matrix.h>
Asen Dimoveb6e6082011-06-08 22:01:37 +000022#include <asm/arch/gpio.h>
Asen Dimovb5d289f2010-04-20 22:49:04 +030023#include <asm/arch/clk.h>
Asen Dimovb5d289f2010-04-20 22:49:04 +030024#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
25#include <net.h>
26#endif
27#include <netdev.h>
28
29DECLARE_GLOBAL_DATA_PTR;
30
31/*
32 * Miscelaneous platform dependent initialisations
33 */
34
35#ifdef CONFIG_CMD_NAND
36static void pm9g45_nand_hw_init(void)
37{
38 unsigned long csa;
Asen Dimoveb6e6082011-06-08 22:01:37 +000039 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
40 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
41 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Asen Dimovb5d289f2010-04-20 22:49:04 +030042
43 /* Enable CS3 */
44 csa = readl(&matrix->ccr[6]) | AT91_MATRIX_CSA_EBI_CS3A;
45 writel(csa, &matrix->ccr[6]);
46
47 /* Configure SMC CS3 for NAND/SmartMedia */
48 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
49 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
50 &smc->cs[3].setup);
51
52 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(3) |
53 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(2),
54 &smc->cs[3].pulse);
55
56 writel(AT91_SMC_CYCLE_NWE(7) | AT91_SMC_CYCLE_NRD(4),
57 &smc->cs[3].cycle);
58
59 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
60 AT91_SMC_MODE_EXNW_DISABLE |
61 AT91_SMC_MODE_DBW_8 |
62 AT91_SMC_MODE_TDF_CYCLE(3),
63 &smc->cs[3].mode);
64
Asen Dimoveb6e6082011-06-08 22:01:37 +000065 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Asen Dimovb5d289f2010-04-20 22:49:04 +030066
67#ifdef CONFIG_SYS_NAND_READY_PIN
68 /* Configure RDY/BSY */
69 at91_set_pio_input(CONFIG_SYS_NAND_READY_PIN, 1);
70#endif
71
72 /* Enable NandFlash */
73 at91_set_pio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
74}
75#endif
76
77#ifdef CONFIG_MACB
78static void pm9g45_macb_hw_init(void)
79{
Asen Dimoveb6e6082011-06-08 22:01:37 +000080 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Asen Dimovb5d289f2010-04-20 22:49:04 +030081
82 /*
83 * PD2 enables the 50MHz oscillator for Ethernet PHY
84 * 1 - enable
85 * 0 - disable
86 */
87 at91_set_pio_output(AT91_PIO_PORTD, 2, 1);
88 at91_set_pio_value(AT91_PIO_PORTD, 2, 1); /* 1- enable, 0 - disable */
89
90 /* Enable clock */
Asen Dimoveb6e6082011-06-08 22:01:37 +000091 writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
Asen Dimovb5d289f2010-04-20 22:49:04 +030092
93 /*
94 * Disable pull-up on:
95 * RXDV (PA15) => PHY normal mode (not Test mode)
96 * ERX0 (PA12) => PHY ADDR0
97 * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
98 *
99 * PHY has internal pull-down
100 */
101 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
102 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 0);
103 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 0);
104
105 /* Re-enable pull-up */
106 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
107 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
108 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
109
110 at91_macb_hw_init();
111}
112#endif
113
Asen Dimovc4df2142011-12-09 11:00:07 +0000114int board_early_init_f(void)
Asen Dimovb5d289f2010-04-20 22:49:04 +0300115{
Asen Dimoveb6e6082011-06-08 22:01:37 +0000116 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
Asen Dimovb5d289f2010-04-20 22:49:04 +0300117
Asen Dimovc4df2142011-12-09 11:00:07 +0000118 /* Enable clocks for all PIOs */
Asen Dimoveb6e6082011-06-08 22:01:37 +0000119 writel((1 << ATMEL_ID_PIOA) |
120 (1 << ATMEL_ID_PIOB) |
121 (1 << ATMEL_ID_PIOC) |
122 (1 << ATMEL_ID_PIODE), &pmc->pcer);
Asen Dimovb5d289f2010-04-20 22:49:04 +0300123
Asen Dimovc4df2142011-12-09 11:00:07 +0000124 at91_seriald_hw_init();
125
126 return 0;
127}
128
129int board_init(void)
130{
131 /* arch number of AT91SAM9M10G45EK-Board */
132 gd->bd->bi_arch_number = MACH_TYPE_PM9G45;
Asen Dimovb5d289f2010-04-20 22:49:04 +0300133 /* adress of boot parameters */
134 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
135
Asen Dimovb5d289f2010-04-20 22:49:04 +0300136#ifdef CONFIG_CMD_NAND
137 pm9g45_nand_hw_init();
138#endif
139
140#ifdef CONFIG_MACB
141 pm9g45_macb_hw_init();
142#endif
143 return 0;
144}
145
146int dram_init(void)
147{
Asen Dimov510f7942010-12-12 00:42:28 +0000148 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa55d23c2011-07-03 05:55:33 +0000149 gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
Asen Dimov510f7942010-12-12 00:42:28 +0000150 PHYS_SDRAM_SIZE);
151 return 0;
152}
153
154void dram_init_banksize(void)
155{
Asen Dimovb5d289f2010-04-20 22:49:04 +0300156 gd->bd->bi_dram[0].start = PHYS_SDRAM;
157 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
Asen Dimovb5d289f2010-04-20 22:49:04 +0300158}
159
160#ifdef CONFIG_RESET_PHY_R
161void reset_phy(void)
162{
163#ifdef CONFIG_MACB
164 /*
165 * Initialize ethernet HW addr prior to starting Linux,
166 * needed for nfsroot
167 */
168 eth_init(gd->bd);
169#endif
170}
171#endif
172
173int board_eth_init(bd_t *bis)
174{
175 int rc = 0;
176#ifdef CONFIG_MACB
Asen Dimoveb6e6082011-06-08 22:01:37 +0000177 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x01);
Asen Dimovb5d289f2010-04-20 22:49:04 +0300178#endif
179 return rc;
180}