blob: e2620e3c0484bbe6823dd1dd888557a38475bd68 [file] [log] [blame]
Asen Dimovddd0bda2010-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 Pop5ee0c7f2011-11-01 00:00:39 +01008 * Stelian Pop <stelian@popies.net>
Asen Dimovddd0bda2010-04-20 22:49:04 +03009 * Lead Tech Design <www.leadtechdesign.com>
10 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Asen Dimovddd0bda2010-04-20 22:49:04 +030012 */
13
14#include <common.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040015#include <linux/sizes.h>
Asen Dimova1e4e2b2011-06-08 22:01:37 +000016#include <asm/io.h>
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010017#include <asm/gpio.h>
Asen Dimovddd0bda2010-04-20 22:49:04 +030018#include <asm/arch/at91sam9_smc.h>
19#include <asm/arch/at91_common.h>
Asen Dimovddd0bda2010-04-20 22:49:04 +030020#include <asm/arch/at91_rstc.h>
21#include <asm/arch/at91_matrix.h>
Asen Dimova1e4e2b2011-06-08 22:01:37 +000022#include <asm/arch/gpio.h>
Asen Dimovddd0bda2010-04-20 22:49:04 +030023#include <asm/arch/clk.h>
Asen Dimovddd0bda2010-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>
Simon Glass0ffb9d62017-05-31 19:47:48 -060028#include <asm/mach-types.h>
Asen Dimovddd0bda2010-04-20 22:49:04 +030029
30DECLARE_GLOBAL_DATA_PTR;
31
32/*
33 * Miscelaneous platform dependent initialisations
34 */
35
36#ifdef CONFIG_CMD_NAND
37static void pm9g45_nand_hw_init(void)
38{
39 unsigned long csa;
Asen Dimova1e4e2b2011-06-08 22:01:37 +000040 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
41 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Asen Dimovddd0bda2010-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
Wenyou Yang78f89762016-02-03 10:16:50 +080065 at91_periph_clk_enable(ATMEL_ID_PIOC);
Asen Dimovddd0bda2010-04-20 22:49:04 +030066
67#ifdef CONFIG_SYS_NAND_READY_PIN
68 /* Configure RDY/BSY */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010069 gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
Asen Dimovddd0bda2010-04-20 22:49:04 +030070#endif
71
72 /* Enable NandFlash */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010073 gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Asen Dimovddd0bda2010-04-20 22:49:04 +030074}
75#endif
76
77#ifdef CONFIG_MACB
78static void pm9g45_macb_hw_init(void)
79{
Asen Dimovddd0bda2010-04-20 22:49:04 +030080 /*
81 * PD2 enables the 50MHz oscillator for Ethernet PHY
82 * 1 - enable
83 * 0 - disable
84 */
85 at91_set_pio_output(AT91_PIO_PORTD, 2, 1);
86 at91_set_pio_value(AT91_PIO_PORTD, 2, 1); /* 1- enable, 0 - disable */
87
Wenyou Yang78f89762016-02-03 10:16:50 +080088 at91_periph_clk_enable(ATMEL_ID_EMAC);
Asen Dimovddd0bda2010-04-20 22:49:04 +030089
90 /*
91 * Disable pull-up on:
92 * RXDV (PA15) => PHY normal mode (not Test mode)
93 * ERX0 (PA12) => PHY ADDR0
94 * ERX1 (PA13) => PHY ADDR1 => PHYADDR = 0x0
95 *
96 * PHY has internal pull-down
97 */
98 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 0);
99 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 0);
100 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 0);
101
102 /* Re-enable pull-up */
103 at91_set_pio_pullup(AT91_PIO_PORTA, 15, 1);
104 at91_set_pio_pullup(AT91_PIO_PORTA, 12, 1);
105 at91_set_pio_pullup(AT91_PIO_PORTA, 13, 1);
106
107 at91_macb_hw_init();
108}
109#endif
110
Asen Dimova04fad92011-12-09 11:00:07 +0000111int board_early_init_f(void)
Asen Dimovddd0bda2010-04-20 22:49:04 +0300112{
Wenyou Yang78f89762016-02-03 10:16:50 +0800113 at91_periph_clk_enable(ATMEL_ID_PIOA);
114 at91_periph_clk_enable(ATMEL_ID_PIOB);
115 at91_periph_clk_enable(ATMEL_ID_PIOC);
116 at91_periph_clk_enable(ATMEL_ID_PIODE);
Asen Dimovddd0bda2010-04-20 22:49:04 +0300117
Asen Dimova04fad92011-12-09 11:00:07 +0000118 at91_seriald_hw_init();
119
120 return 0;
121}
122
123int board_init(void)
124{
125 /* arch number of AT91SAM9M10G45EK-Board */
126 gd->bd->bi_arch_number = MACH_TYPE_PM9G45;
Asen Dimovddd0bda2010-04-20 22:49:04 +0300127 /* adress of boot parameters */
128 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
129
Asen Dimovddd0bda2010-04-20 22:49:04 +0300130#ifdef CONFIG_CMD_NAND
131 pm9g45_nand_hw_init();
132#endif
133
134#ifdef CONFIG_MACB
135 pm9g45_macb_hw_init();
136#endif
137 return 0;
138}
139
140int dram_init(void)
141{
Asen Dimov8322d4e2010-12-12 00:42:28 +0000142 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +0000143 gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
Asen Dimov8322d4e2010-12-12 00:42:28 +0000144 PHYS_SDRAM_SIZE);
145 return 0;
146}
147
Simon Glass2f949c32017-03-31 08:40:32 -0600148int dram_init_banksize(void)
Asen Dimov8322d4e2010-12-12 00:42:28 +0000149{
Asen Dimovddd0bda2010-04-20 22:49:04 +0300150 gd->bd->bi_dram[0].start = PHYS_SDRAM;
151 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -0600152
153 return 0;
Asen Dimovddd0bda2010-04-20 22:49:04 +0300154}
155
156#ifdef CONFIG_RESET_PHY_R
157void reset_phy(void)
158{
159#ifdef CONFIG_MACB
160 /*
161 * Initialize ethernet HW addr prior to starting Linux,
162 * needed for nfsroot
163 */
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500164 eth_init();
Asen Dimovddd0bda2010-04-20 22:49:04 +0300165#endif
166}
167#endif
168
169int board_eth_init(bd_t *bis)
170{
171 int rc = 0;
172#ifdef CONFIG_MACB
Asen Dimova1e4e2b2011-06-08 22:01:37 +0000173 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_EMAC, 0x01);
Asen Dimovddd0bda2010-04-20 22:49:04 +0300174#endif
175 return rc;
176}