Sandeep Sheriker Mallikarjun | 5142266 | 2019-09-27 13:08:52 +0000 | [diff] [blame] | 1 | // 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> |
| 9 | #include <asm/io.h> |
Tudor Ambarus | 8ed15e4 | 2019-09-27 13:09:07 +0000 | [diff] [blame] | 10 | #include <asm/arch/at91sam9_smc.h> |
Sandeep Sheriker Mallikarjun | 5142266 | 2019-09-27 13:08:52 +0000 | [diff] [blame] | 11 | #include <asm/arch/at91_common.h> |
| 12 | #include <asm/arch/at91_rstc.h> |
Tudor Ambarus | 8ed15e4 | 2019-09-27 13:09:07 +0000 | [diff] [blame] | 13 | #include <asm/arch/at91_sfr.h> |
Sandeep Sheriker Mallikarjun | 5142266 | 2019-09-27 13:08:52 +0000 | [diff] [blame] | 14 | #include <asm/arch/clk.h> |
| 15 | #include <asm/arch/gpio.h> |
| 16 | #include <debug_uart.h> |
| 17 | #include <asm/mach-types.h> |
| 18 | |
Eugen Hristev | 34c53a9 | 2019-09-30 07:29:01 +0000 | [diff] [blame^] | 19 | extern void at91_pda_detect(void); |
| 20 | |
Sandeep Sheriker Mallikarjun | 5142266 | 2019-09-27 13:08:52 +0000 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | void at91_prepare_cpu_var(void); |
| 24 | |
Tudor Ambarus | 8ed15e4 | 2019-09-27 13:09:07 +0000 | [diff] [blame] | 25 | #ifdef CONFIG_CMD_NAND |
| 26 | static void sam9x60ek_nand_hw_init(void) |
| 27 | { |
| 28 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 29 | struct atmel_sfr *sfr = (struct atmel_sfr *)ATMEL_BASE_SFR; |
| 30 | unsigned int csa; |
| 31 | |
| 32 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 0, 1); /* NAND OE */ |
| 33 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 1, 1); /* NAND WE */ |
| 34 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 2, 0); /* NAND ALE */ |
| 35 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 3, 0); /* NAND CLE */ |
| 36 | /* Enable NandFlash */ |
| 37 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
| 38 | /* Configure RDY/BSY */ |
| 39 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
| 40 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 6, 1); |
| 41 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 7, 1); |
| 42 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 8, 1); |
| 43 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 9, 1); |
| 44 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 1); |
| 45 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 1); |
| 46 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 1); |
| 47 | at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1); |
| 48 | |
| 49 | at91_periph_clk_enable(ATMEL_ID_PIOD); |
| 50 | |
| 51 | /* Enable CS3 */ |
| 52 | csa = readl(&sfr->ebicsa); |
| 53 | csa |= AT91_SFR_CCFG_EBI_CSA(3, 1) | AT91_SFR_CCFG_NFD0_ON_D16; |
| 54 | |
| 55 | /* Configure IO drive */ |
| 56 | csa &= ~AT91_SFR_CCFG_EBI_DRIVE_SAM9X60; |
| 57 | |
| 58 | writel(csa, &sfr->ebicsa); |
| 59 | |
| 60 | /* Configure SMC CS3 for NAND/SmartMedia */ |
| 61 | writel(AT91_SMC_SETUP_NWE(4), &smc->cs[3].setup); |
| 62 | |
| 63 | writel(AT91_SMC_PULSE_NWE(10) | AT91_SMC_PULSE_NCS_WR(20) | |
| 64 | AT91_SMC_PULSE_NRD(10) | AT91_SMC_PULSE_NCS_RD(20), |
| 65 | &smc->cs[3].pulse); |
| 66 | |
| 67 | writel(AT91_SMC_CYCLE_NWE(20) | AT91_SMC_CYCLE_NRD(20), |
| 68 | &smc->cs[3].cycle); |
| 69 | |
| 70 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 71 | #ifdef CONFIG_SYS_NAND_DBW_16 |
| 72 | AT91_SMC_MODE_DBW_16 | |
| 73 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
| 74 | AT91_SMC_MODE_DBW_8 | |
| 75 | #endif |
| 76 | AT91_SMC_MODE_TDF | AT91_SMC_MODE_TDF_CYCLE(15), |
| 77 | &smc->cs[3].mode); |
| 78 | } |
| 79 | #endif |
| 80 | |
Sandeep Sheriker Mallikarjun | 5142266 | 2019-09-27 13:08:52 +0000 | [diff] [blame] | 81 | #ifdef CONFIG_BOARD_LATE_INIT |
| 82 | int board_late_init(void) |
| 83 | { |
| 84 | at91_prepare_cpu_var(); |
Eugen Hristev | 34c53a9 | 2019-09-30 07:29:01 +0000 | [diff] [blame^] | 85 | |
| 86 | at91_pda_detect(); |
| 87 | |
Sandeep Sheriker Mallikarjun | 5142266 | 2019-09-27 13:08:52 +0000 | [diff] [blame] | 88 | return 0; |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 93 | void board_debug_uart_init(void) |
| 94 | { |
| 95 | at91_seriald_hw_init(); |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 100 | int board_early_init_f(void) |
| 101 | { |
| 102 | #ifdef CONFIG_DEBUG_UART |
| 103 | debug_uart_init(); |
| 104 | #endif |
| 105 | return 0; |
| 106 | } |
| 107 | #endif |
| 108 | |
| 109 | int board_init(void) |
| 110 | { |
| 111 | /* address of boot parameters */ |
| 112 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 113 | |
Tudor Ambarus | 8ed15e4 | 2019-09-27 13:09:07 +0000 | [diff] [blame] | 114 | #ifdef CONFIG_CMD_NAND |
| 115 | sam9x60ek_nand_hw_init(); |
| 116 | #endif |
Sandeep Sheriker Mallikarjun | 5142266 | 2019-09-27 13:08:52 +0000 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | int dram_init(void) |
| 121 | { |
| 122 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 123 | CONFIG_SYS_SDRAM_SIZE); |
| 124 | return 0; |
| 125 | } |