Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007-2008 |
Stelian Pop | 5ee0c7f | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 4 | * Stelian Pop <stelian@popies.net> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 5 | * Lead Tech Design <www.leadtechdesign.com> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Wenyou Yang | de56d37 | 2017-04-18 15:18:49 +0800 | [diff] [blame] | 9 | #include <debug_uart.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 0c36441 | 2019-12-28 10:44:48 -0700 | [diff] [blame] | 11 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 14 | #include <asm/arch/at91sam9260_matrix.h> |
Stelian Pop | d57846e | 2008-05-08 22:52:10 +0200 | [diff] [blame] | 15 | #include <asm/arch/at91sam9_smc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6b0b3db | 2009-03-21 21:07:59 +0100 | [diff] [blame] | 16 | #include <asm/arch/at91_common.h> |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 17 | #include <asm/arch/clk.h> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 18 | #include <asm/arch/gpio.h> |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | /* ------------------------------------------------------------------------- */ |
| 23 | /* |
| 24 | * Miscelaneous platform dependent initialisations |
| 25 | */ |
| 26 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 27 | #ifdef CONFIG_CMD_NAND |
| 28 | static void at91sam9260ek_nand_hw_init(void) |
| 29 | { |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 30 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 31 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 32 | unsigned long csa; |
| 33 | |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 34 | /* Assign CS3 to NAND/SmartMedia Interface */ |
| 35 | csa = readl(&matrix->ebicsa); |
| 36 | csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; |
| 37 | writel(csa, &matrix->ebicsa); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 38 | |
| 39 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 40 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 41 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 42 | &smc->cs[3].setup); |
| 43 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) | |
| 44 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3), |
| 45 | &smc->cs[3].pulse); |
| 46 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5), |
| 47 | &smc->cs[3].cycle); |
| 48 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 49 | AT91_SMC_MODE_EXNW_DISABLE | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_SYS_NAND_DBW_16 |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 51 | AT91_SMC_MODE_DBW_16 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 53 | AT91_SMC_MODE_DBW_8 | |
Stelian Pop | a35a4f8 | 2008-05-08 20:52:18 +0200 | [diff] [blame] | 54 | #endif |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 55 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 56 | &smc->cs[3].mode); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 57 | |
| 58 | /* Configure RDY/BSY */ |
Jean-Christophe PLAGNIOL-VILLARD | c9539ba | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 59 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 60 | |
| 61 | /* Enable NandFlash */ |
Jean-Christophe PLAGNIOL-VILLARD | c9539ba | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 62 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 63 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 64 | } |
| 65 | #endif |
| 66 | |
Wenyou Yang | de56d37 | 2017-04-18 15:18:49 +0800 | [diff] [blame] | 67 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 68 | void board_debug_uart_init(void) |
| 69 | { |
| 70 | at91_seriald_hw_init(); |
| 71 | } |
| 72 | #endif |
| 73 | |
| 74 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 75 | int board_early_init_f(void) |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 76 | { |
Wenyou Yang | de56d37 | 2017-04-18 15:18:49 +0800 | [diff] [blame] | 77 | #ifdef CONFIG_DEBUG_UART |
| 78 | debug_uart_init(); |
| 79 | #endif |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 80 | return 0; |
| 81 | } |
Wenyou Yang | de56d37 | 2017-04-18 15:18:49 +0800 | [diff] [blame] | 82 | #endif |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 83 | |
| 84 | int board_init(void) |
| 85 | { |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 86 | /* adress of boot parameters */ |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 87 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 88 | |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 89 | #ifdef CONFIG_CMD_NAND |
| 90 | at91sam9260ek_nand_hw_init(); |
| 91 | #endif |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | int dram_init(void) |
| 96 | { |
Reinhard Meyer | 0bda5f2 | 2011-06-06 00:13:10 +0000 | [diff] [blame] | 97 | gd->ram_size = get_ram_size( |
| 98 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 99 | CONFIG_SYS_SDRAM_SIZE); |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | #ifdef CONFIG_RESET_PHY_R |
| 104 | void reset_phy(void) |
| 105 | { |
Stelian Pop | 7837993 | 2008-03-26 18:52:33 +0100 | [diff] [blame] | 106 | } |
| 107 | #endif |