Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
Stelian Pop | c9e798d | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 3 | * Stelian Pop <stelian@popies.net> |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 10 | #include <asm/io.h> |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 11 | #include <asm/arch/at91sam9rl.h> |
| 12 | #include <asm/arch/at91sam9rl_matrix.h> |
| 13 | #include <asm/arch/at91sam9_smc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 1332a2a | 2009-03-21 21:07:59 +0100 | [diff] [blame] | 14 | #include <asm/arch/at91_common.h> |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 15 | #include <asm/arch/at91_rstc.h> |
Jean-Christophe PLAGNIOL-VILLARD | dc39ae9 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 16 | #include <asm/arch/clk.h> |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 17 | #include <asm/arch/gpio.h> |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 18 | |
Stelian Pop | 761c70b | 2008-05-08 14:52:32 +0200 | [diff] [blame] | 19 | #include <lcd.h> |
| 20 | #include <atmel_lcdc.h> |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | /* ------------------------------------------------------------------------- */ |
| 25 | /* |
| 26 | * Miscelaneous platform dependent initialisations |
| 27 | */ |
| 28 | |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 29 | #ifdef CONFIG_CMD_NAND |
| 30 | static void at91sam9rlek_nand_hw_init(void) |
| 31 | { |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 32 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 33 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 34 | unsigned long csa; |
| 35 | |
| 36 | /* Enable CS3 */ |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 37 | csa = readl(&matrix->ebicsa); |
| 38 | csa |= AT91_MATRIX_CS3A_SMC_SMARTMEDIA; |
| 39 | |
| 40 | writel(csa, &matrix->ebicsa); |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 41 | |
| 42 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 43 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 44 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 45 | &smc->cs[3].setup); |
| 46 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) | |
| 47 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3), |
| 48 | &smc->cs[3].pulse); |
| 49 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5), |
| 50 | &smc->cs[3].cycle); |
| 51 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 52 | AT91_SMC_MODE_EXNW_DISABLE | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | #ifdef CONFIG_SYS_NAND_DBW_16 |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 54 | AT91_SMC_MODE_DBW_16 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 56 | AT91_SMC_MODE_DBW_8 | |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 57 | #endif |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 58 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 59 | &smc->cs[3].mode); |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 60 | |
Wenyou Yang | 70341e2 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 61 | at91_periph_clk_enable(ATMEL_ID_PIOD); |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 62 | |
| 63 | /* Configure RDY/BSY */ |
Jean-Christophe PLAGNIOL-VILLARD | 74c076d | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 64 | at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 1); |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 65 | |
| 66 | /* Enable NandFlash */ |
Jean-Christophe PLAGNIOL-VILLARD | 74c076d | 2009-03-22 10:22:34 +0100 | [diff] [blame] | 67 | at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 68 | |
| 69 | at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */ |
| 70 | at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */ |
| 71 | } |
| 72 | #endif |
| 73 | |
Stelian Pop | 761c70b | 2008-05-08 14:52:32 +0200 | [diff] [blame] | 74 | #ifdef CONFIG_LCD |
| 75 | vidinfo_t panel_info = { |
Jeroen Hofstee | c346e46 | 2014-06-10 00:16:23 +0200 | [diff] [blame] | 76 | .vl_col = 240, |
| 77 | .vl_row = 320, |
| 78 | .vl_clk = 4965000, |
| 79 | .vl_sync = ATMEL_LCDC_INVLINE_INVERTED | |
| 80 | ATMEL_LCDC_INVFRAME_INVERTED, |
| 81 | .vl_bpix = 3, |
| 82 | .vl_tft = 1, |
| 83 | .vl_hsync_len = 5, |
| 84 | .vl_left_margin = 1, |
| 85 | .vl_right_margin = 33, |
| 86 | .vl_vsync_len = 1, |
| 87 | .vl_upper_margin = 1, |
| 88 | .vl_lower_margin = 0, |
| 89 | .mmio = ATMEL_BASE_LCDC, |
Stelian Pop | 761c70b | 2008-05-08 14:52:32 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | void lcd_enable(void) |
| 93 | { |
| 94 | at91_set_gpio_value(AT91_PIN_PA30, 0); /* power up */ |
| 95 | } |
| 96 | |
| 97 | void lcd_disable(void) |
| 98 | { |
| 99 | at91_set_gpio_value(AT91_PIN_PA30, 1); /* power down */ |
| 100 | } |
| 101 | static void at91sam9rlek_lcd_hw_init(void) |
| 102 | { |
| 103 | at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */ |
| 104 | at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */ |
| 105 | at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */ |
| 106 | at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */ |
| 107 | at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */ |
| 108 | at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */ |
| 109 | at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */ |
| 110 | at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */ |
| 111 | at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */ |
| 112 | at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */ |
| 113 | at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */ |
| 114 | at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */ |
| 115 | at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */ |
| 116 | at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */ |
| 117 | at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */ |
| 118 | at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */ |
| 119 | at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */ |
| 120 | at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */ |
| 121 | at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */ |
| 122 | at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */ |
| 123 | at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */ |
| 124 | |
Wenyou Yang | 70341e2 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 125 | at91_periph_clk_enable(ATMEL_ID_LCDC); |
Stelian Pop | 761c70b | 2008-05-08 14:52:32 +0200 | [diff] [blame] | 126 | } |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 127 | |
| 128 | #ifdef CONFIG_LCD_INFO |
| 129 | #include <nand.h> |
| 130 | #include <version.h> |
| 131 | |
| 132 | void lcd_show_board_info(void) |
| 133 | { |
| 134 | ulong dram_size, nand_size; |
| 135 | int i; |
| 136 | char temp[32]; |
| 137 | |
| 138 | lcd_printf ("%s\n", U_BOOT_VERSION); |
| 139 | lcd_printf ("(C) 2008 ATMEL Corp\n"); |
| 140 | lcd_printf ("at91support@atmel.com\n"); |
| 141 | lcd_printf ("%s CPU at %s MHz\n", |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 142 | ATMEL_CPU_NAME, |
Jean-Christophe PLAGNIOL-VILLARD | dc39ae9 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 143 | strmhz(temp, get_cpu_clk_rate())); |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 144 | |
| 145 | dram_size = 0; |
| 146 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) |
| 147 | dram_size += gd->bd->bi_dram[i].size; |
| 148 | nand_size = 0; |
| 149 | for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) |
Scott Wood | b616d9b | 2016-05-30 13:57:55 -0500 | [diff] [blame] | 150 | nand_size += nand_info[i]->size; |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 151 | lcd_printf (" %ld MB SDRAM, %ld MB NAND\n", |
| 152 | dram_size >> 20, |
| 153 | nand_size >> 20 ); |
| 154 | } |
| 155 | #endif /* CONFIG_LCD_INFO */ |
Stelian Pop | 761c70b | 2008-05-08 14:52:32 +0200 | [diff] [blame] | 156 | #endif |
| 157 | |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 158 | int board_early_init_f(void) |
| 159 | { |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 160 | return 0; |
| 161 | } |
Stelian Pop | 761c70b | 2008-05-08 14:52:32 +0200 | [diff] [blame] | 162 | |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 163 | int board_init(void) |
| 164 | { |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 165 | /* arch number of AT91SAM9RLEK-Board */ |
| 166 | gd->bd->bi_arch_number = MACH_TYPE_AT91SAM9RLEK; |
| 167 | /* adress of boot parameters */ |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 168 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 169 | |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 170 | #ifdef CONFIG_CMD_NAND |
| 171 | at91sam9rlek_nand_hw_init(); |
| 172 | #endif |
| 173 | #ifdef CONFIG_HAS_DATAFLASH |
Jean-Christophe PLAGNIOL-VILLARD | 7ebafb7 | 2009-03-21 21:07:59 +0100 | [diff] [blame] | 174 | at91_spi0_hw_init(1 << 0); |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 175 | #endif |
Stelian Pop | 761c70b | 2008-05-08 14:52:32 +0200 | [diff] [blame] | 176 | #ifdef CONFIG_LCD |
| 177 | at91sam9rlek_lcd_hw_init(); |
| 178 | #endif |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | int dram_init(void) |
| 183 | { |
Xu, Hong | 21d671d | 2011-08-01 03:56:53 +0000 | [diff] [blame] | 184 | gd->ram_size = get_ram_size( |
| 185 | (void *)CONFIG_SYS_SDRAM_BASE, |
| 186 | CONFIG_SYS_SDRAM_SIZE); |
Stelian Pop | 2118ebb | 2008-05-08 18:52:25 +0200 | [diff] [blame] | 187 | return 0; |
| 188 | } |