blob: f1e7aab6296ae5abca33b697f722b7ca94f54dfc [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>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040011#include <linux/sizes.h>
Asen Dimov6a595142011-07-26 04:48:41 +000012#include <asm/io.h>
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010013#include <asm/gpio.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020014#include <asm/arch/at91sam9_smc.h>
15#include <asm/arch/at91_common.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020016#include <asm/arch/at91_rstc.h>
Asen Dimov9128acd2010-04-06 16:18:04 +030017#include <asm/arch/at91_matrix.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020018#include <asm/arch/clk.h>
Asen Dimov6a595142011-07-26 04:48:41 +000019#include <asm/arch/gpio.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020020#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
21#include <net.h>
22#endif
23#include <netdev.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060024#include <asm/mach-types.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020025
26DECLARE_GLOBAL_DATA_PTR;
27
28/* ------------------------------------------------------------------------- */
29/*
30 * Miscelaneous platform dependent initialisations
31 */
32
33#ifdef CONFIG_CMD_NAND
34static void pm9261_nand_hw_init(void)
35{
36 unsigned long csa;
Asen Dimov6a595142011-07-26 04:48:41 +000037 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
38 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Ilko Iliev61fdb732009-06-12 21:20:39 +020039
40 /* Enable CS3 */
Asen Dimov9128acd2010-04-06 16:18:04 +030041 csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A;
42 writel(csa, &matrix->csa);
Ilko Iliev61fdb732009-06-12 21:20:39 +020043
44 /* Configure SMC CS3 for NAND/SmartMedia */
Asen Dimov9128acd2010-04-06 16:18:04 +030045 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
46 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
47 &smc->cs[3].setup);
48
49 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
50 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
51 &smc->cs[3].pulse);
52
53 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
54 &smc->cs[3].cycle);
55
56 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
57 AT91_SMC_MODE_EXNW_DISABLE |
Ilko Iliev61fdb732009-06-12 21:20:39 +020058#ifdef CONFIG_SYS_NAND_DBW_16
Asen Dimov9128acd2010-04-06 16:18:04 +030059 AT91_SMC_MODE_DBW_16 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020060#else /* CONFIG_SYS_NAND_DBW_8 */
Asen Dimov9128acd2010-04-06 16:18:04 +030061 AT91_SMC_MODE_DBW_8 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020062#endif
Asen Dimov9128acd2010-04-06 16:18:04 +030063 AT91_SMC_MODE_TDF_CYCLE(2),
64 &smc->cs[3].mode);
65
Wenyou Yang78f89762016-02-03 10:16:50 +080066 at91_periph_clk_enable(ATMEL_ID_PIOA);
67 at91_periph_clk_enable(ATMEL_ID_PIOC);
Ilko Iliev61fdb732009-06-12 21:20:39 +020068
69 /* Configure RDY/BSY */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010070 gpio_direction_input(CONFIG_SYS_NAND_READY_PIN);
Ilko Iliev61fdb732009-06-12 21:20:39 +020071
72 /* Enable NandFlash */
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010073 gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
Ilko Iliev61fdb732009-06-12 21:20:39 +020074
Asen Dimov9128acd2010-04-06 16:18:04 +030075 at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* NANDOE */
76 at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* NANDWE */
Ilko Iliev61fdb732009-06-12 21:20:39 +020077}
78#endif
79
80
81#ifdef CONFIG_DRIVER_DM9000
82static void pm9261_dm9000_hw_init(void)
83{
Asen Dimov6a595142011-07-26 04:48:41 +000084 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
Asen Dimov9128acd2010-04-06 16:18:04 +030085
Ilko Iliev61fdb732009-06-12 21:20:39 +020086 /* Configure SMC CS2 for DM9000 */
Asen Dimov9128acd2010-04-06 16:18:04 +030087 writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) |
88 AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0),
89 &smc->cs[2].setup);
90
91 writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) |
92 AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8),
93 &smc->cs[2].pulse);
94
95 writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16),
96 &smc->cs[2].cycle);
97
98 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
99 AT91_SMC_MODE_EXNW_DISABLE |
100 AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 |
101 AT91_SMC_MODE_TDF_CYCLE(1),
102 &smc->cs[2].mode);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200103
104 /* Configure Interrupt pin as input, no pull-up */
Wenyou Yang78f89762016-02-03 10:16:50 +0800105 at91_periph_clk_enable(ATMEL_ID_PIOA);
Asen Dimov9128acd2010-04-06 16:18:04 +0300106 at91_set_pio_input(AT91_PIO_PORTA, 24, 0);
Ilko Iliev61fdb732009-06-12 21:20:39 +0200107}
108#endif
109
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000110int board_early_init_f(void)
Ilko Iliev61fdb732009-06-12 21:20:39 +0200111{
Asen Dimov7aa4dc02011-12-09 10:59:07 +0000112 return 0;
113}
114
115int board_init(void)
116{
117 /* arch number of PM9261-Board */
118 gd->bd->bi_arch_number = MACH_TYPE_PM9261;
119
Ilko Iliev61fdb732009-06-12 21:20:39 +0200120 /* adress of boot parameters */
121 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
122
Ilko Iliev61fdb732009-06-12 21:20:39 +0200123#ifdef CONFIG_CMD_NAND
124 pm9261_nand_hw_init();
125#endif
Ilko Iliev61fdb732009-06-12 21:20:39 +0200126#ifdef CONFIG_DRIVER_DM9000
127 pm9261_dm9000_hw_init();
128#endif
Ilko Iliev61fdb732009-06-12 21:20:39 +0200129 return 0;
130}
131
Ilko Ilievc120e9e2009-09-05 02:51:34 +0200132#ifdef CONFIG_DRIVER_DM9000
133int board_eth_init(bd_t *bis)
134{
135 return dm9000_initialize(bis);
136}
137#endif
138
Ilko Iliev61fdb732009-06-12 21:20:39 +0200139int dram_init(void)
140{
Asen Dimov5aae7462010-12-12 12:41:30 +0200141 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +0000142 gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
Asen Dimov5aae7462010-12-12 12:41:30 +0200143 PHYS_SDRAM_SIZE);
144 return 0;
145}
146
Simon Glass2f949c32017-03-31 08:40:32 -0600147int dram_init_banksize(void)
Asen Dimov5aae7462010-12-12 12:41:30 +0200148{
Ilko Iliev61fdb732009-06-12 21:20:39 +0200149 gd->bd->bi_dram[0].start = PHYS_SDRAM;
150 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -0600151
152 return 0;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200153}
154
155#ifdef CONFIG_RESET_PHY_R
156void reset_phy(void)
157{
158#ifdef CONFIG_DRIVER_DM9000
159 /*
160 * Initialize ethernet HW addr prior to starting Linux,
161 * needed for nfsroot
162 */
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500163 eth_init();
Ilko Iliev61fdb732009-06-12 21:20:39 +0200164#endif
165}
166#endif
167
168#ifdef CONFIG_DISPLAY_BOARDINFO
169int checkboard (void)
170{
171 char buf[32];
172
173 printf ("Board : Ronetix PM9261\n");
174 printf ("Crystal frequency: %8s MHz\n",
175 strmhz(buf, get_main_clk_rate()));
176 printf ("CPU clock : %8s MHz\n",
177 strmhz(buf, get_cpu_clk_rate()));
178 printf ("Master clock : %8s MHz\n",
179 strmhz(buf, get_mck_clk_rate()));
180
181 return 0;
182}
183#endif