Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007-2008 |
Stelian Pop | 5ee0c7f | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 3 | * Stelian Pop <stelian@popies.net> |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
| 5 | * Copyright (C) 2008 Ronetix Ilko Iliev (www.ronetix.at) |
| 6 | * Copyright (C) 2009 Jean-Christopher PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Alexey Brodkin | 267d8e2 | 2014-02-26 17:47:58 +0400 | [diff] [blame] | 12 | #include <linux/sizes.h> |
Asen Dimov | 6a59514 | 2011-07-26 04:48:41 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
Andreas Bießmann | a4c24d3 | 2013-11-29 12:13:45 +0100 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 15 | #include <asm/arch/at91sam9_smc.h> |
| 16 | #include <asm/arch/at91_common.h> |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 17 | #include <asm/arch/at91_rstc.h> |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 18 | #include <asm/arch/at91_matrix.h> |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 19 | #include <asm/arch/clk.h> |
Asen Dimov | 6a59514 | 2011-07-26 04:48:41 +0000 | [diff] [blame] | 20 | #include <asm/arch/gpio.h> |
| 21 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 22 | #include <lcd.h> |
| 23 | #include <atmel_lcdc.h> |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 24 | #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000) |
| 25 | #include <net.h> |
| 26 | #endif |
| 27 | #include <netdev.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | /* ------------------------------------------------------------------------- */ |
| 33 | /* |
| 34 | * Miscelaneous platform dependent initialisations |
| 35 | */ |
| 36 | |
| 37 | #ifdef CONFIG_CMD_NAND |
| 38 | static void pm9261_nand_hw_init(void) |
| 39 | { |
| 40 | unsigned long csa; |
Asen Dimov | 6a59514 | 2011-07-26 04:48:41 +0000 | [diff] [blame] | 41 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
| 42 | struct at91_matrix *matrix = (struct at91_matrix *)ATMEL_BASE_MATRIX; |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 43 | |
| 44 | /* Enable CS3 */ |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 45 | csa = readl(&matrix->csa) | AT91_MATRIX_CSA_EBI_CS3A; |
| 46 | writel(csa, &matrix->csa); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 47 | |
| 48 | /* Configure SMC CS3 for NAND/SmartMedia */ |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 49 | writel(AT91_SMC_SETUP_NWE(1) | AT91_SMC_SETUP_NCS_WR(0) | |
| 50 | AT91_SMC_SETUP_NRD(1) | AT91_SMC_SETUP_NCS_RD(0), |
| 51 | &smc->cs[3].setup); |
| 52 | |
| 53 | writel(AT91_SMC_PULSE_NWE(3) | AT91_SMC_PULSE_NCS_WR(3) | |
| 54 | AT91_SMC_PULSE_NRD(3) | AT91_SMC_PULSE_NCS_RD(3), |
| 55 | &smc->cs[3].pulse); |
| 56 | |
| 57 | writel(AT91_SMC_CYCLE_NWE(5) | AT91_SMC_CYCLE_NRD(5), |
| 58 | &smc->cs[3].cycle); |
| 59 | |
| 60 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 61 | AT91_SMC_MODE_EXNW_DISABLE | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 62 | #ifdef CONFIG_SYS_NAND_DBW_16 |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 63 | AT91_SMC_MODE_DBW_16 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 64 | #else /* CONFIG_SYS_NAND_DBW_8 */ |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 65 | AT91_SMC_MODE_DBW_8 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 66 | #endif |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 67 | AT91_SMC_MODE_TDF_CYCLE(2), |
| 68 | &smc->cs[3].mode); |
| 69 | |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 70 | at91_periph_clk_enable(ATMEL_ID_PIOA); |
| 71 | at91_periph_clk_enable(ATMEL_ID_PIOC); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 72 | |
| 73 | /* Configure RDY/BSY */ |
Andreas Bießmann | a4c24d3 | 2013-11-29 12:13:45 +0100 | [diff] [blame] | 74 | gpio_direction_input(CONFIG_SYS_NAND_READY_PIN); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 75 | |
| 76 | /* Enable NandFlash */ |
Andreas Bießmann | a4c24d3 | 2013-11-29 12:13:45 +0100 | [diff] [blame] | 77 | gpio_direction_output(CONFIG_SYS_NAND_ENABLE_PIN, 1); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 78 | |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 79 | at91_set_a_periph(AT91_PIO_PORTC, 0, 0); /* NANDOE */ |
| 80 | at91_set_a_periph(AT91_PIO_PORTC, 1, 0); /* NANDWE */ |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 81 | } |
| 82 | #endif |
| 83 | |
| 84 | |
| 85 | #ifdef CONFIG_DRIVER_DM9000 |
| 86 | static void pm9261_dm9000_hw_init(void) |
| 87 | { |
Asen Dimov | 6a59514 | 2011-07-26 04:48:41 +0000 | [diff] [blame] | 88 | struct at91_smc *smc = (struct at91_smc *)ATMEL_BASE_SMC; |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 89 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 90 | /* Configure SMC CS2 for DM9000 */ |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 91 | writel(AT91_SMC_SETUP_NWE(2) | AT91_SMC_SETUP_NCS_WR(0) | |
| 92 | AT91_SMC_SETUP_NRD(2) | AT91_SMC_SETUP_NCS_RD(0), |
| 93 | &smc->cs[2].setup); |
| 94 | |
| 95 | writel(AT91_SMC_PULSE_NWE(4) | AT91_SMC_PULSE_NCS_WR(8) | |
| 96 | AT91_SMC_PULSE_NRD(4) | AT91_SMC_PULSE_NCS_RD(8), |
| 97 | &smc->cs[2].pulse); |
| 98 | |
| 99 | writel(AT91_SMC_CYCLE_NWE(16) | AT91_SMC_CYCLE_NRD(16), |
| 100 | &smc->cs[2].cycle); |
| 101 | |
| 102 | writel(AT91_SMC_MODE_RM_NRD | AT91_SMC_MODE_WM_NWE | |
| 103 | AT91_SMC_MODE_EXNW_DISABLE | |
| 104 | AT91_SMC_MODE_BAT | AT91_SMC_MODE_DBW_16 | |
| 105 | AT91_SMC_MODE_TDF_CYCLE(1), |
| 106 | &smc->cs[2].mode); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 107 | |
| 108 | /* Configure Interrupt pin as input, no pull-up */ |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 109 | at91_periph_clk_enable(ATMEL_ID_PIOA); |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 110 | at91_set_pio_input(AT91_PIO_PORTA, 24, 0); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 111 | } |
| 112 | #endif |
| 113 | |
| 114 | #ifdef CONFIG_LCD |
| 115 | vidinfo_t panel_info = { |
Jeroen Hofstee | e887b72 | 2014-06-10 00:16:23 +0200 | [diff] [blame] | 116 | .vl_col = 240, |
| 117 | .vl_row = 320, |
| 118 | .vl_clk = 4965000, |
| 119 | .vl_sync = ATMEL_LCDC_INVLINE_INVERTED | |
| 120 | ATMEL_LCDC_INVFRAME_INVERTED, |
| 121 | .vl_bpix = 3, |
| 122 | .vl_tft = 1, |
| 123 | .vl_hsync_len = 5, |
| 124 | .vl_left_margin = 1, |
| 125 | .vl_right_margin = 33, |
| 126 | .vl_vsync_len = 1, |
| 127 | .vl_upper_margin = 1, |
| 128 | .vl_lower_margin = 0, |
| 129 | .mmio = ATMEL_BASE_LCDC, |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | void lcd_enable(void) |
| 133 | { |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 134 | at91_set_pio_value(AT91_PIO_PORTA, 22, 0); /* power up */ |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void lcd_disable(void) |
| 138 | { |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 139 | at91_set_pio_value(AT91_PIO_PORTA, 22, 1); /* power down */ |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void pm9261_lcd_hw_init(void) |
| 143 | { |
Asen Dimov | 9128acd | 2010-04-06 16:18:04 +0300 | [diff] [blame] | 144 | at91_set_a_periph(AT91_PIO_PORTB, 1, 0); /* LCDHSYNC */ |
| 145 | at91_set_a_periph(AT91_PIO_PORTB, 2, 0); /* LCDDOTCK */ |
| 146 | at91_set_a_periph(AT91_PIO_PORTB, 3, 0); /* LCDDEN */ |
| 147 | at91_set_a_periph(AT91_PIO_PORTB, 4, 0); /* LCDCC */ |
| 148 | at91_set_a_periph(AT91_PIO_PORTB, 7, 0); /* LCDD2 */ |
| 149 | at91_set_a_periph(AT91_PIO_PORTB, 8, 0); /* LCDD3 */ |
| 150 | at91_set_a_periph(AT91_PIO_PORTB, 9, 0); /* LCDD4 */ |
| 151 | at91_set_a_periph(AT91_PIO_PORTB, 10, 0); /* LCDD5 */ |
| 152 | at91_set_a_periph(AT91_PIO_PORTB, 11, 0); /* LCDD6 */ |
| 153 | at91_set_a_periph(AT91_PIO_PORTB, 12, 0); /* LCDD7 */ |
| 154 | at91_set_a_periph(AT91_PIO_PORTB, 15, 0); /* LCDD10 */ |
| 155 | at91_set_a_periph(AT91_PIO_PORTB, 16, 0); /* LCDD11 */ |
| 156 | at91_set_a_periph(AT91_PIO_PORTB, 17, 0); /* LCDD12 */ |
| 157 | at91_set_a_periph(AT91_PIO_PORTB, 18, 0); /* LCDD13 */ |
| 158 | at91_set_a_periph(AT91_PIO_PORTB, 19, 0); /* LCDD14 */ |
| 159 | at91_set_a_periph(AT91_PIO_PORTB, 20, 0); /* LCDD15 */ |
| 160 | at91_set_b_periph(AT91_PIO_PORTB, 23, 0); /* LCDD18 */ |
| 161 | at91_set_b_periph(AT91_PIO_PORTB, 24, 0); /* LCDD19 */ |
| 162 | at91_set_b_periph(AT91_PIO_PORTB, 25, 0); /* LCDD20 */ |
| 163 | at91_set_b_periph(AT91_PIO_PORTB, 26, 0); /* LCDD21 */ |
| 164 | at91_set_b_periph(AT91_PIO_PORTB, 27, 0); /* LCDD22 */ |
| 165 | at91_set_b_periph(AT91_PIO_PORTB, 28, 0); /* LCDD23 */ |
| 166 | |
Wenyou Yang | 78f8976 | 2016-02-03 10:16:50 +0800 | [diff] [blame] | 167 | at91_system_clk_enable(AT91_PMC_HCK1); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 168 | |
Asen Dimov | 6a59514 | 2011-07-26 04:48:41 +0000 | [diff] [blame] | 169 | gd->fb_base = ATMEL_BASE_SRAM; |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | #ifdef CONFIG_LCD_INFO |
| 173 | #include <nand.h> |
| 174 | #include <version.h> |
| 175 | |
| 176 | extern flash_info_t flash_info[]; |
| 177 | |
| 178 | void lcd_show_board_info(void) |
| 179 | { |
Wenyou.Yang@microchip.com | 8f2bbde | 2017-07-21 17:04:56 +0800 | [diff] [blame^] | 180 | ulong dram_size, nand_size, flash_size; |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 181 | int i; |
| 182 | char temp[32]; |
| 183 | |
| 184 | lcd_printf ("%s\n", U_BOOT_VERSION); |
| 185 | lcd_printf ("(C) 2009 Ronetix GmbH\n"); |
| 186 | lcd_printf ("support@ronetix.at\n"); |
| 187 | lcd_printf ("%s CPU at %s MHz", |
Achim Ehrlich | 443873d | 2010-02-24 10:29:16 +0100 | [diff] [blame] | 188 | CONFIG_SYS_AT91_CPU_NAME, |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 189 | strmhz(temp, get_cpu_clk_rate())); |
| 190 | |
| 191 | dram_size = 0; |
| 192 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) |
| 193 | dram_size += gd->bd->bi_dram[i].size; |
| 194 | |
| 195 | nand_size = 0; |
| 196 | for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) |
Grygorii Strashko | a2973c6 | 2017-06-26 19:13:04 -0500 | [diff] [blame] | 197 | nand_size += get_nand_dev_by_index(i)->size; |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 198 | |
| 199 | flash_size = 0; |
| 200 | for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) |
| 201 | flash_size += flash_info[i].size; |
| 202 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 203 | lcd_printf ("%ld MB SDRAM, %ld MB NAND\n%ld MB NOR Flash\n" |
| 204 | "%ld MB DataFlash\n", |
| 205 | dram_size >> 20, |
| 206 | nand_size >> 20, |
Wenyou.Yang@microchip.com | 8f2bbde | 2017-07-21 17:04:56 +0800 | [diff] [blame^] | 207 | flash_size >> 20); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 208 | } |
| 209 | #endif /* CONFIG_LCD_INFO */ |
| 210 | |
| 211 | #endif /* CONFIG_LCD */ |
| 212 | |
Asen Dimov | 7aa4dc0 | 2011-12-09 10:59:07 +0000 | [diff] [blame] | 213 | int board_early_init_f(void) |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 214 | { |
Asen Dimov | 7aa4dc0 | 2011-12-09 10:59:07 +0000 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | int board_init(void) |
| 219 | { |
| 220 | /* arch number of PM9261-Board */ |
| 221 | gd->bd->bi_arch_number = MACH_TYPE_PM9261; |
| 222 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 223 | /* adress of boot parameters */ |
| 224 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 225 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 226 | #ifdef CONFIG_CMD_NAND |
| 227 | pm9261_nand_hw_init(); |
| 228 | #endif |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 229 | #ifdef CONFIG_DRIVER_DM9000 |
| 230 | pm9261_dm9000_hw_init(); |
| 231 | #endif |
| 232 | #ifdef CONFIG_LCD |
| 233 | pm9261_lcd_hw_init(); |
| 234 | #endif |
| 235 | return 0; |
| 236 | } |
| 237 | |
Ilko Iliev | c120e9e | 2009-09-05 02:51:34 +0200 | [diff] [blame] | 238 | #ifdef CONFIG_DRIVER_DM9000 |
| 239 | int board_eth_init(bd_t *bis) |
| 240 | { |
| 241 | return dm9000_initialize(bis); |
| 242 | } |
| 243 | #endif |
| 244 | |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 245 | int dram_init(void) |
| 246 | { |
Asen Dimov | 5aae746 | 2010-12-12 12:41:30 +0200 | [diff] [blame] | 247 | /* dram_init must store complete ramsize in gd->ram_size */ |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 248 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM, |
Asen Dimov | 5aae746 | 2010-12-12 12:41:30 +0200 | [diff] [blame] | 249 | PHYS_SDRAM_SIZE); |
| 250 | return 0; |
| 251 | } |
| 252 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 253 | int dram_init_banksize(void) |
Asen Dimov | 5aae746 | 2010-12-12 12:41:30 +0200 | [diff] [blame] | 254 | { |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 255 | gd->bd->bi_dram[0].start = PHYS_SDRAM; |
| 256 | gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE; |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 257 | |
| 258 | return 0; |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | #ifdef CONFIG_RESET_PHY_R |
| 262 | void reset_phy(void) |
| 263 | { |
| 264 | #ifdef CONFIG_DRIVER_DM9000 |
| 265 | /* |
| 266 | * Initialize ethernet HW addr prior to starting Linux, |
| 267 | * needed for nfsroot |
| 268 | */ |
Joe Hershberger | 3dbe17e | 2015-03-22 17:09:06 -0500 | [diff] [blame] | 269 | eth_init(); |
Ilko Iliev | 61fdb73 | 2009-06-12 21:20:39 +0200 | [diff] [blame] | 270 | #endif |
| 271 | } |
| 272 | #endif |
| 273 | |
| 274 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 275 | int checkboard (void) |
| 276 | { |
| 277 | char buf[32]; |
| 278 | |
| 279 | printf ("Board : Ronetix PM9261\n"); |
| 280 | printf ("Crystal frequency: %8s MHz\n", |
| 281 | strmhz(buf, get_main_clk_rate())); |
| 282 | printf ("CPU clock : %8s MHz\n", |
| 283 | strmhz(buf, get_cpu_clk_rate())); |
| 284 | printf ("Master clock : %8s MHz\n", |
| 285 | strmhz(buf, get_mck_clk_rate())); |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | #endif |