blob: bad673412a1f4d36e03192eb8015aa75fa4ef356 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilko Iliev61fdb732009-06-12 21:20:39 +02002/*
3 * (C) Copyright 2007-2008
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01004 * Stelian Pop <stelian@popies.net>
Ilko Iliev61fdb732009-06-12 21:20:39 +02005 * Lead Tech Design <www.leadtechdesign.com>
6 * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at)
7 * Copyright (C) 2009 Jean-Christopher PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Ilko Iliev61fdb732009-06-12 21:20:39 +02008 */
9
10#include <common.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070011#include <vsprintf.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040012#include <linux/sizes.h>
Asen Dimov6a595142011-07-26 04:48:41 +000013#include <asm/io.h>
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010014#include <asm/gpio.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020015#include <asm/arch/at91sam9_smc.h>
16#include <asm/arch/at91_common.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020017#include <asm/arch/at91_rstc.h>
Asen Dimov9128acd2010-04-06 16:18:04 +030018#include <asm/arch/at91_matrix.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020019#include <asm/arch/clk.h>
Asen Dimov6a595142011-07-26 04:48:41 +000020#include <asm/arch/gpio.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020021#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
22#include <net.h>
23#endif
24#include <netdev.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060025#include <asm/mach-types.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020026
27DECLARE_GLOBAL_DATA_PTR;
28
29/* ------------------------------------------------------------------------- */
30/*
31 * Miscelaneous platform dependent initialisations
32 */
33
34#ifdef CONFIG_CMD_NAND
35static void pm9261_nand_hw_init(void)
36{
37 unsigned long csa;
Asen Dimov6a595142011-07-26 04:48:41 +000038 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
39 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Ilko Iliev61fdb732009-06-12 21:20:39 +020040
41 /* Enable CS3 */
Asen Dimov9128acd2010-04-06 16:18:04 +030042 csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A;
43 writel(csa, &matrix->csa);
Ilko Iliev61fdb732009-06-12 21:20:39 +020044
45 /* Configure SMC CS3 for NAND/SmartMedia */
Asen Dimov9128acd2010-04-06 16:18:04 +030046 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
47 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
48 &smc->cs[3].setup);
49
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
54 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
55 &smc->cs[3].cycle);
56
57 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
58 AT91_SMC_MODE_EXNW_DISABLE |
Ilko Iliev61fdb732009-06-12 21:20:39 +020059#ifdef CONFIG_SYS_NAND_DBW_16
Asen Dimov9128acd2010-04-06 16:18:04 +030060 AT91_SMC_MODE_DBW_16 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020061#else /* CONFIG_SYS_NAND_DBW_8 */
Asen Dimov9128acd2010-04-06 16:18:04 +030062 AT91_SMC_MODE_DBW_8 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020063#endif
Asen Dimov9128acd2010-04-06 16:18:04 +030064 AT91_SMC_MODE_TDF_CYCLE(2),
65 &smc->cs[3].mode);
66
Wenyou Yang78f89762016-02-03 10:16:50 +080067 at91_periph_clk_enable(ATMEL_ID_PIOA);
68 at91_periph_clk_enable(ATMEL_ID_PIOC);
Ilko Iliev61fdb732009-06-12 21:20:39 +020069
70 /* Configure RDY/BSY */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010071 gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
Ilko Iliev61fdb732009-06-12 21:20:39 +020072
73 /* Enable NandFlash */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010074 gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Ilko Iliev61fdb732009-06-12 21:20:39 +020075
Asen Dimov9128acd2010-04-06 16:18:04 +030076 at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* NANDOE */
77 at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* NANDWE */
Ilko Iliev61fdb732009-06-12 21:20:39 +020078}
79#endif
80
81
82#ifdef CONFIG_DRIVER_DM9000
83static void pm9261_dm9000_hw_init(void)
84{
Asen Dimov6a595142011-07-26 04:48:41 +000085 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
Asen Dimov9128acd2010-04-06 16:18:04 +030086
Ilko Iliev61fdb732009-06-12 21:20:39 +020087 /* Configure SMC CS2 for DM9000 */
Asen Dimov9128acd2010-04-06 16:18:04 +030088 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
89 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
90 &smc->cs[2].setup);
91
92 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
93 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
94 &smc->cs[2].pulse);
95
96 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
97 &smc->cs[2].cycle);
98
99 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
100 AT91_SMC_MODE_EXNW_DISABLE |
101 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
102 AT91_SMC_MODE_TDF_CYCLE(1),
103 &smc->cs[2].mode);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200104
105 /* Configure Interrupt pin as input, no pull-up */
Wenyou Yang78f89762016-02-03 10:16:50 +0800106 at91_periph_clk_enable(ATMEL_ID_PIOA);
Asen Dimov9128acd2010-04-06 16:18:04 +0300107 at91_set_pio_input(AT91_PIO_PORTA, 24, 0);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200108}
109#endif
110
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000111int board_early_init_f(void)
Ilko Iliev61fdb732009-06-12 21:20:39 +0200112{
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000113 return 0;
114}
115
116int board_init(void)
117{
118 /* arch number of PM9261-Board */
119 gd->bd->bi_arch_number = MACH_TYPE_PM9261;
120
Ilko Iliev61fdb732009-06-12 21:20:39 +0200121 /* adress of boot parameters */
122 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
123
Ilko Iliev61fdb732009-06-12 21:20:39 +0200124#ifdef CONFIG_CMD_NAND
125 pm9261_nand_hw_init();
126#endif
Ilko Iliev61fdb732009-06-12 21:20:39 +0200127#ifdef CONFIG_DRIVER_DM9000
128 pm9261_dm9000_hw_init();
129#endif
Ilko Iliev61fdb732009-06-12 21:20:39 +0200130 return 0;
131}
132
Ilko Ilievc120e9e2009-09-05 02:51:34 +0200133#ifdef CONFIG_DRIVER_DM9000
134int board_eth_init(bd_t *bis)
135{
136 return dm9000_initialize(bis);
137}
138#endif
139
Ilko Iliev61fdb732009-06-12 21:20:39 +0200140int dram_init(void)
141{
Asen Dimov5aae7462010-12-12 12:41:30 +0200142 /* 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 Dimov5aae7462010-12-12 12:41:30 +0200144 PHYS_SDRAM_SIZE);
145 return 0;
146}
147
Simon Glass2f949c32017-03-31 08:40:32 -0600148int dram_init_banksize(void)
Asen Dimov5aae7462010-12-12 12:41:30 +0200149{
Ilko Iliev61fdb732009-06-12 21:20:39 +0200150 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;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200154}
155
156#ifdef CONFIG_RESET_PHY_R
157void reset_phy(void)
158{
159#ifdef CONFIG_DRIVER_DM9000
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();
Ilko Iliev61fdb732009-06-12 21:20:39 +0200165#endif
166}
167#endif
168
169#ifdef CONFIG_DISPLAY_BOARDINFO
170int checkboard (void)
171{
172 char buf[32];
173
174 printf ("Board : Ronetix PM9261\n");
175 printf ("Crystal frequency: %8s MHz\n",
176 strmhz(buf, get_main_clk_rate()));
177 printf ("CPU clock : %8s MHz\n",
178 strmhz(buf, get_cpu_clk_rate()));
179 printf ("Master clock : %8s MHz\n",
180 strmhz(buf, get_mck_clk_rate()));
181
182 return 0;
183}
184#endif