blob: fbd05c78a94859a98db4499713efb6b6a651c508 [file] [log] [blame]
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Microchip Technology Inc. and its subsidiaries
4 *
5 * Author: Sandeep Sheriker M <sandeep.sheriker@microchip.com>
6 */
7
8#include <common.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -07009#include <init.h>
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +000010#include <asm/io.h>
Tudor Ambaruse76c66a2019-09-27 13:09:07 +000011#include <asm/arch/at91sam9_smc.h>
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +000012#include <asm/arch/at91_common.h>
13#include <asm/arch/at91_rstc.h>
Tudor Ambaruse76c66a2019-09-27 13:09:07 +000014#include <asm/arch/at91_sfr.h>
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +000015#include <asm/arch/clk.h>
16#include <asm/arch/gpio.h>
17#include <debug_uart.h>
18#include <asm/mach-types.h>
19
Eugen Hristevf9990dc2019-09-30 07:29:01 +000020extern void at91_pda_detect(void);
21
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +000022DECLARE_GLOBAL_DATA_PTR;
23
24void at91_prepare_cpu_var(void);
25
Tudor Ambaruse76c66a2019-09-27 13:09:07 +000026#ifdef CONFIG_CMD_NAND
27static void sam9x60ek_nand_hw_init(void)
28{
29 struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC;
30 struct atmel_sfr *sfr = (struct atmel_sfr *)ATMEL_BASE_SFR;
31 unsigned int csa;
32
33 at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */
34 at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */
35 at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 0); /* NAND ALE */
36 at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 0); /* NAND CLE */
37 /* Enable NandFlash */
38 at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);
39 /* Configure RDY/BSY */
40 at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1);
41 at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1);
42 at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1);
43 at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1);
44 at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1);
45 at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1);
46 at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1);
47 at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1);
48 at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1);
49
50 at91_periph_clk_enable(ATMEL_ID_PIOD);
51
52 /* Enable CS3 */
53 csa = readl(&sfr->ebicsa);
54 csa |= AT91_SFR_CCFG_EBI_CSA(3, 1) | AT91_SFR_CCFG_NFD0_ON_D16;
55
56 /* Configure IO drive */
57 csa &= ~AT91_SFR_CCFG_EBI_DRIVE_SAM9X60;
58
59 writel(csa, &sfr->ebicsa);
60
61 /* Configure SMC CS3 for NAND/SmartMedia */
62 writel(AT91_SMC_SETUP_NWE(4), &smc->cs[3].setup);
63
64 writel(AT91_SMC_PULSE_NWE(10) | AT91_SMC_PULSE_NCS_WR(20) |
65 AT91_SMC_PULSE_NRD(10) | AT91_SMC_PULSE_NCS_RD(20),
66 &smc->cs[3].pulse);
67
68 writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20),
69 &smc->cs[3].cycle);
70
71 writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE |
72#ifdef CONFIG_SYS_NAND_DBW_16
73 AT91_SMC_MODE_DBW_16 |
74#else /* CONFIG_SYS_NAND_DBW_8 */
75 AT91_SMC_MODE_DBW_8 |
76#endif
77 AT91_SMC_MODE_TDF | AT91_SMC_MODE_TDF_CYCLE(15),
78 &smc->cs[3].mode);
79}
80#endif
81
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +000082#ifdef CONFIG_BOARD_LATE_INIT
83int board_late_init(void)
84{
85 at91_prepare_cpu_var();
Eugen Hristevf9990dc2019-09-30 07:29:01 +000086
87 at91_pda_detect();
88
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +000089 return 0;
90}
91#endif
92
93#ifdef CONFIG_DEBUG_UART_BOARD_INIT
94void board_debug_uart_init(void)
95{
96 at91_seriald_hw_init();
97}
98#endif
99
100#ifdef CONFIG_BOARD_EARLY_INIT_F
101int board_early_init_f(void)
102{
103#ifdef CONFIG_DEBUG_UART
104 debug_uart_init();
105#endif
106 return 0;
107}
108#endif
109
Eugen Hristeva4f51ce2019-10-09 09:23:43 +0000110#define MAC24AA_MAC_OFFSET 0xfa
111
112#ifdef CONFIG_MISC_INIT_R
113int misc_init_r(void)
114{
115#ifdef CONFIG_I2C_EEPROM
116 at91_set_ethaddr(MAC24AA_MAC_OFFSET);
117#endif
118 return 0;
119}
120#endif
121
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +0000122int board_init(void)
123{
124 /* address of boot parameters */
125 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
126
Tudor Ambaruse76c66a2019-09-27 13:09:07 +0000127#ifdef CONFIG_CMD_NAND
128 sam9x60ek_nand_hw_init();
129#endif
Sandeep Sheriker Mallikarjun641b3352019-09-27 13:08:52 +0000130 return 0;
131}
132
133int dram_init(void)
134{
135 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
136 CONFIG_SYS_SDRAM_SIZE);
137 return 0;
138}