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