blob: 07febe69dc7c757c48a1630d6e90bf2e4e4da3fd [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 Glass8e16b1e2019-12-28 10:45:05 -070011#include <init.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070012#include <vsprintf.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040014#include <linux/sizes.h>
Asen Dimov6a595142011-07-26 04:48:41 +000015#include <asm/io.h>
Andreas Bießmanna4c24d32013-11-29 12:13:45 +010016#include <asm/gpio.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020017#include <asm/arch/at91sam9_smc.h>
18#include <asm/arch/at91_common.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020019#include <asm/arch/at91_rstc.h>
Asen Dimov9128acd2010-04-06 16:18:04 +030020#include <asm/arch/at91_matrix.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020021#include <asm/arch/clk.h>
Asen Dimov6a595142011-07-26 04:48:41 +000022#include <asm/arch/gpio.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060023#include <asm/mach-types.h>
Ilko Iliev61fdb732009-06-12 21:20:39 +020024
25DECLARE_GLOBAL_DATA_PTR;
26
27/* ------------------------------------------------------------------------- */
28/*
29 * Miscelaneous platform dependent initialisations
30 */
31
32#ifdef CONFIG_CMD_NAND
33static void pm9261_nand_hw_init(void)
34{
35 unsigned long csa;
Asen Dimov6a595142011-07-26 04:48:41 +000036 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
37 struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX;
Ilko Iliev61fdb732009-06-12 21:20:39 +020038
39 /* Enable CS3 */
Asen Dimov9128acd2010-04-06 16:18:04 +030040 csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A;
41 writel(csa, &matrix->csa);
Ilko Iliev61fdb732009-06-12 21:20:39 +020042
43 /* Configure SMC CS3 for NAND/SmartMedia */
Asen Dimov9128acd2010-04-06 16:18:04 +030044 writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) |
45 AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0),
46 &smc->cs[3].setup);
47
48 writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) |
49 AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3),
50 &smc->cs[3].pulse);
51
52 writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5),
53 &smc->cs[3].cycle);
54
55 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
56 AT91_SMC_MODE_EXNW_DISABLE |
Ilko Iliev61fdb732009-06-12 21:20:39 +020057#ifdef CONFIG_SYS_NAND_DBW_16
Asen Dimov9128acd2010-04-06 16:18:04 +030058 AT91_SMC_MODE_DBW_16 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020059#else /* CONFIG_SYS_NAND_DBW_8 */
Asen Dimov9128acd2010-04-06 16:18:04 +030060 AT91_SMC_MODE_DBW_8 |
Ilko Iliev61fdb732009-06-12 21:20:39 +020061#endif
Asen Dimov9128acd2010-04-06 16:18:04 +030062 AT91_SMC_MODE_TDF_CYCLE(2),
63 &smc->cs[3].mode);
64
Wenyou Yang78f89762016-02-03 10:16:50 +080065 at91_periph_clk_enable(ATMEL_ID_PIOA);
66 at91_periph_clk_enable(ATMEL_ID_PIOC);
Ilko Iliev61fdb732009-06-12 21:20:39 +020067
68 /* Configure RDY/BSY */
Tom Rinib4213492022-11-12 17:36:51 -050069 gpio_direction_input(CFG_SYS_NAND_READY_PIN);
Ilko Iliev61fdb732009-06-12 21:20:39 +020070
71 /* Enable NandFlash */
Tom Rinib4213492022-11-12 17:36:51 -050072 gpio_direction_output(CFG_SYS_NAND_ENABLE_PIN, 1);
Ilko Iliev61fdb732009-06-12 21:20:39 +020073
Asen Dimov9128acd2010-04-06 16:18:04 +030074 at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* NANDOE */
75 at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* NANDWE */
Ilko Iliev61fdb732009-06-12 21:20:39 +020076}
77#endif
78
Asen Dimov7aa4dc02011-12-09 10:59:07 +000079int board_early_init_f(void)
Ilko Iliev61fdb732009-06-12 21:20:39 +020080{
Asen Dimov7aa4dc02011-12-09 10:59:07 +000081 return 0;
82}
83
84int board_init(void)
85{
86 /* arch number of PM9261-Board */
87 gd->bd->bi_arch_number = MACH_TYPE_PM9261;
88
Ilko Iliev61fdb732009-06-12 21:20:39 +020089 /* adress of boot parameters */
90 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
91
Ilko Iliev61fdb732009-06-12 21:20:39 +020092#ifdef CONFIG_CMD_NAND
93 pm9261_nand_hw_init();
94#endif
Ilko Iliev61fdb732009-06-12 21:20:39 +020095#ifdef CONFIG_DRIVER_DM9000
96 pm9261_dm9000_hw_init();
97#endif
Ilko Iliev61fdb732009-06-12 21:20:39 +020098 return 0;
99}
100
Ilko Iliev61fdb732009-06-12 21:20:39 +0200101int dram_init(void)
102{
Asen Dimov5aae7462010-12-12 12:41:30 +0200103 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +0000104 gd->ram_size = get_ram_size((void *)PHYS_SDRAM,
Asen Dimov5aae7462010-12-12 12:41:30 +0200105 PHYS_SDRAM_SIZE);
106 return 0;
107}
108
Simon Glass2f949c32017-03-31 08:40:32 -0600109int dram_init_banksize(void)
Asen Dimov5aae7462010-12-12 12:41:30 +0200110{
Ilko Iliev61fdb732009-06-12 21:20:39 +0200111 gd->bd->bi_dram[0].start = PHYS_SDRAM;
112 gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -0600113
114 return 0;
Ilko Iliev61fdb732009-06-12 21:20:39 +0200115}
116
Ilko Iliev61fdb732009-06-12 21:20:39 +0200117#ifdef CONFIG_DISPLAY_BOARDINFO
118int checkboard (void)
119{
120 char buf[32];
121
122 printf ("Board : Ronetix PM9261\n");
123 printf ("Crystal frequency: %8s MHz\n",
124 strmhz(buf, get_main_clk_rate()));
125 printf ("CPU clock : %8s MHz\n",
126 strmhz(buf, get_cpu_clk_rate()));
127 printf ("Master clock : %8s MHz\n",
128 strmhz(buf, get_mck_clk_rate()));
129
130 return 0;
131}
132#endif