Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Atmel Corporation |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
Ben Warren | 89973f8 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 7 | #include <netdev.h> |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 8 | |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/sdram.h> |
| 11 | #include <asm/arch/clk.h> |
| 12 | #include <asm/arch/gpio.h> |
| 13 | #include <asm/arch/hmatrix.h> |
Haavard Skinnemoen | 1f36f73 | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 14 | #include <asm/arch/mmu.h> |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 15 | #include <asm/arch/portmux.h> |
Mark Jackson | f68378d | 2009-07-21 11:35:22 +0100 | [diff] [blame] | 16 | #include <atmel_lcdc.h> |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 17 | #include <lcd.h> |
| 18 | |
Peter Tyser | 8a15c2d | 2010-04-12 22:28:15 -0500 | [diff] [blame] | 19 | #include "../../../arch/avr32/cpu/hsmc3.h" |
Mark Jackson | 58a518c | 2009-02-13 15:48:18 +0000 | [diff] [blame] | 20 | |
Haavard Skinnemoen | 1f36f73 | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 21 | struct mmu_vm_range mmu_vmr_table[CONFIG_SYS_NR_VM_REGIONS] = { |
| 22 | { |
Andreas Bießmann | e9ed41c | 2015-02-06 23:06:42 +0100 | [diff] [blame] | 23 | .virt_pgno = CONFIG_SYS_FLASH_BASE >> MMU_PAGE_SHIFT, |
| 24 | .nr_pages = CONFIG_SYS_FLASH_SIZE >> MMU_PAGE_SHIFT, |
| 25 | .phys = (CONFIG_SYS_FLASH_BASE >> MMU_PAGE_SHIFT) |
Haavard Skinnemoen | 1f36f73 | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 26 | | MMU_VMR_CACHE_NONE, |
| 27 | }, { |
Andreas Bießmann | e9ed41c | 2015-02-06 23:06:42 +0100 | [diff] [blame] | 28 | .virt_pgno = EBI_SRAM_CS2_BASE >> MMU_PAGE_SHIFT, |
| 29 | .nr_pages = EBI_SRAM_CS2_SIZE >> MMU_PAGE_SHIFT, |
| 30 | .phys = (EBI_SRAM_CS2_BASE >> MMU_PAGE_SHIFT) |
Haavard Skinnemoen | 1f36f73 | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 31 | | MMU_VMR_CACHE_NONE, |
| 32 | }, { |
Andreas Bießmann | e9ed41c | 2015-02-06 23:06:42 +0100 | [diff] [blame] | 33 | .virt_pgno = CONFIG_SYS_SDRAM_BASE >> MMU_PAGE_SHIFT, |
| 34 | .nr_pages = EBI_SDRAM_SIZE >> MMU_PAGE_SHIFT, |
| 35 | .phys = (CONFIG_SYS_SDRAM_BASE >> MMU_PAGE_SHIFT) |
Haavard Skinnemoen | 1f36f73 | 2010-08-12 13:52:54 +0700 | [diff] [blame] | 36 | | MMU_VMR_CACHE_WRBACK, |
| 37 | }, |
| 38 | }; |
| 39 | |
Mark Jackson | f68378d | 2009-07-21 11:35:22 +0100 | [diff] [blame] | 40 | #if defined(CONFIG_LCD) |
| 41 | /* 480x272x16 @ 72 Hz */ |
| 42 | vidinfo_t panel_info = { |
Anatolij Gustschin | bcf0b52 | 2009-07-26 11:04:59 +0200 | [diff] [blame] | 43 | .vl_col = 480, /* Number of columns */ |
| 44 | .vl_row = 272, /* Number of rows */ |
Mark Jackson | 54e399f | 2009-08-11 11:33:47 +0100 | [diff] [blame] | 45 | .vl_clk = 5000000, /* pixel clock in ps */ |
Mark Jackson | f68378d | 2009-07-21 11:35:22 +0100 | [diff] [blame] | 46 | .vl_sync = ATMEL_LCDC_INVCLK_INVERTED | |
| 47 | ATMEL_LCDC_INVLINE_INVERTED | |
| 48 | ATMEL_LCDC_INVFRAME_INVERTED, |
Anatolij Gustschin | bcf0b52 | 2009-07-26 11:04:59 +0200 | [diff] [blame] | 49 | .vl_bpix = LCD_COLOR16, /* Bits per pixel, BPP = 2^n */ |
| 50 | .vl_tft = 1, /* 0 = passive, 1 = TFT */ |
| 51 | .vl_hsync_len = 42, /* Length of horizontal sync */ |
| 52 | .vl_left_margin = 1, /* Time from sync to picture */ |
| 53 | .vl_right_margin = 1, /* Time from picture to sync */ |
| 54 | .vl_vsync_len = 1, /* Length of vertical sync */ |
| 55 | .vl_upper_margin = 12, /* Time from sync to picture */ |
| 56 | .vl_lower_margin = 1, /* Time from picture to sync */ |
| 57 | .mmio = LCDC_BASE, /* Memory mapped registers */ |
Mark Jackson | f68378d | 2009-07-21 11:35:22 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | void lcd_enable(void) |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | void lcd_disable(void) |
| 65 | { |
| 66 | } |
| 67 | #endif |
| 68 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 69 | DECLARE_GLOBAL_DATA_PTR; |
| 70 | |
| 71 | static const struct sdram_config sdram_config = { |
| 72 | .data_bits = SDRAM_DATA_16BIT, |
| 73 | .row_bits = 13, |
| 74 | .col_bits = 9, |
| 75 | .bank_bits = 2, |
| 76 | .cas = 3, |
| 77 | .twr = 2, |
| 78 | .trc = 6, |
| 79 | .trp = 2, |
| 80 | .trcd = 2, |
| 81 | .tras = 6, |
| 82 | .txsr = 6, |
| 83 | /* 15.6 us */ |
| 84 | .refresh_period = (156 * (SDRAMC_BUS_HZ / 1000)) / 10000, |
| 85 | }; |
| 86 | |
| 87 | int board_early_init_f(void) |
| 88 | { |
| 89 | /* Enable SDRAM in the EBI mux */ |
| 90 | hmatrix_slave_write(EBI, SFR, HMATRIX_BIT(EBI_SDRAM_ENABLE)); |
| 91 | |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 92 | /* Enable 26 address bits and NCS2 */ |
| 93 | portmux_enable_ebi(16, 26, PORTMUX_EBI_CS(2), PORTMUX_DRIVE_HIGH); |
Andreas Bießmann | 1866786 | 2015-02-06 23:06:43 +0100 | [diff] [blame] | 94 | sdram_init(uncached(EBI_SDRAM_BASE), &sdram_config); |
| 95 | |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 96 | portmux_enable_usart1(PORTMUX_DRIVE_MIN); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 97 | |
| 98 | /* de-assert "force sys reset" pin */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 99 | portmux_select_gpio(PORTMUX_PORT_D, 1 << 15, |
| 100 | PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 101 | |
| 102 | /* init custom i/o */ |
| 103 | /* cpu type inputs */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 104 | portmux_select_gpio(PORTMUX_PORT_E, (1 << 19) | (1 << 20) | (1 << 23), |
| 105 | PORTMUX_DIR_INPUT); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 106 | /* main board type inputs */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 107 | portmux_select_gpio(PORTMUX_PORT_B, (1 << 19) | (1 << 29), |
| 108 | PORTMUX_DIR_INPUT); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 109 | /* DEBUG input (use weak pullup) */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 110 | portmux_select_gpio(PORTMUX_PORT_E, 1 << 21, |
| 111 | PORTMUX_DIR_INPUT | PORTMUX_PULL_UP); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 112 | |
| 113 | /* are we suppressing the console ? */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 114 | if (gpio_get_value(GPIO_PIN_PE(21)) == 1) |
Mark Jackson | a69a423 | 2008-10-03 11:48:57 +0100 | [diff] [blame] | 115 | gd->flags |= (GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 116 | |
| 117 | /* reset phys */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 118 | portmux_select_gpio(PORTMUX_PORT_E, 1 << 24, PORTMUX_DIR_INPUT); |
| 119 | portmux_select_gpio(PORTMUX_PORT_C, 1 << 18, |
| 120 | PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 121 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 122 | udelay(5000); |
| 123 | |
| 124 | /* release phys reset */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 125 | gpio_set_value(GPIO_PIN_PC(18), 0); /* PHY RESET (Release) */ |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 126 | |
Mark Jackson | 58a518c | 2009-02-13 15:48:18 +0000 | [diff] [blame] | 127 | /* setup Data Flash chip select (NCS2) */ |
| 128 | hsmc3_writel(MODE2, 0x20121003); |
| 129 | hsmc3_writel(CYCLE2, 0x000a0009); |
| 130 | hsmc3_writel(PULSE2, 0x0a060806); |
| 131 | hsmc3_writel(SETUP2, 0x00030102); |
| 132 | |
| 133 | /* setup FRAM chip select (NCS3) */ |
| 134 | hsmc3_writel(MODE3, 0x10120001); |
| 135 | hsmc3_writel(CYCLE3, 0x001e001d); |
| 136 | hsmc3_writel(PULSE3, 0x08040704); |
| 137 | hsmc3_writel(SETUP3, 0x02050204); |
| 138 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 139 | #if defined(CONFIG_MACB) |
| 140 | /* init macb0 pins */ |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 141 | portmux_enable_macb0(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); |
| 142 | portmux_enable_macb1(PORTMUX_MACB_MII, PORTMUX_DRIVE_HIGH); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 143 | #endif |
| 144 | |
| 145 | #if defined(CONFIG_MMC) |
Haavard Skinnemoen | ab0df36 | 2008-08-29 21:09:49 +0200 | [diff] [blame] | 146 | portmux_enable_mmci(0, PORTMUX_MMCI_4BIT, PORTMUX_DRIVE_LOW); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 147 | #endif |
| 148 | |
Mark Jackson | f68378d | 2009-07-21 11:35:22 +0100 | [diff] [blame] | 149 | #if defined(CONFIG_LCD) |
| 150 | portmux_enable_lcdc(1); |
| 151 | #endif |
| 152 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
Haavard Skinnemoen | 25e6854 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 156 | int board_early_init_r(void) |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 157 | { |
| 158 | gd->bd->bi_phy_id[0] = 0x01; |
| 159 | gd->bd->bi_phy_id[1] = 0x03; |
Haavard Skinnemoen | 25e6854 | 2008-08-31 18:46:35 +0200 | [diff] [blame] | 160 | return 0; |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Mark Jackson | 8053488 | 2008-11-24 12:10:56 +0000 | [diff] [blame] | 163 | int board_postclk_init(void) |
| 164 | { |
| 165 | /* Use GCLK0 as 10MHz output */ |
| 166 | gclk_enable_output(0, PORTMUX_DRIVE_LOW); |
| 167 | gclk_set_rate(0, GCLK_PARENT_OSC0, 10000000); |
| 168 | return 0; |
| 169 | } |
| 170 | |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 171 | /* SPI chip select control */ |
| 172 | #ifdef CONFIG_ATMEL_SPI |
| 173 | #include <spi.h> |
| 174 | |
| 175 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 176 | { |
| 177 | return (bus == 0) && (cs == 0); |
| 178 | } |
| 179 | |
| 180 | void spi_cs_activate(struct spi_slave *slave) |
| 181 | { |
| 182 | } |
| 183 | |
| 184 | void spi_cs_deactivate(struct spi_slave *slave) |
| 185 | { |
| 186 | } |
| 187 | #endif /* CONFIG_ATMEL_SPI */ |
| 188 | |
| 189 | #ifdef CONFIG_CMD_NET |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 190 | int board_eth_init(bd_t *bi) |
| 191 | { |
Andreas Bießmann | f4278b7 | 2010-11-04 23:15:31 +0000 | [diff] [blame] | 192 | macb_eth_initialize(0, (void *)ATMEL_BASE_MACB0, bi->bi_phy_id[0]); |
| 193 | macb_eth_initialize(1, (void *)ATMEL_BASE_MACB1, bi->bi_phy_id[1]); |
Mark Jackson | 13b50fe | 2008-07-30 13:07:27 +0100 | [diff] [blame] | 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | #endif |