Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008-2013 Eric Jarrige <eric.jarrige@armadeus.org> |
| 4 | * |
| 5 | * based on the files by |
| 6 | * Sascha Hauer, Pengutronix |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 10 | #include <jffs2/jffs2.h> |
| 11 | #include <nand.h> |
| 12 | #include <netdev.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/imx-regs.h> |
| 15 | #include <asm/arch/gpio.h> |
| 16 | #include <asm/gpio.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 17 | #include <linux/errno.h> |
Philipp Tomsich | a740ee9 | 2018-11-25 19:22:18 +0100 | [diff] [blame] | 18 | #include <u-boot/crc.h> |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 19 | #include "apf27.h" |
trem | b5e7f1b | 2013-09-10 22:08:40 +0200 | [diff] [blame] | 20 | #include "fpga.h" |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | /* |
| 25 | * Fuse bank 1 row 8 is "reserved for future use" and therefore available for |
| 26 | * customer use. The APF27 board uses this fuse to store the board revision: |
| 27 | * 0: initial board revision |
| 28 | * 1: first revision - Presence of the second RAM chip on the board is blown in |
| 29 | * fuse bank 1 row 9 bit 0 - No hardware change |
| 30 | * N: to be defined |
| 31 | */ |
| 32 | static u32 get_board_rev(void) |
| 33 | { |
| 34 | struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE; |
| 35 | |
| 36 | return readl(&iim->bank[1].fuse_regs[8]); |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * Fuse bank 1 row 9 is "reserved for future use" and therefore available for |
| 41 | * customer use. The APF27 board revision 1 uses the bit 0 to permanently store |
| 42 | * the presence of the second RAM chip |
| 43 | * 0: AFP27 with 1 RAM of 64 MiB |
| 44 | * 1: AFP27 with 2 RAM chips of 64 MiB each (128MB) |
| 45 | */ |
| 46 | static int get_num_ram_bank(void) |
| 47 | { |
| 48 | struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE; |
| 49 | int nr_dram_banks = 1; |
| 50 | |
| 51 | if ((get_board_rev() > 0) && (CONFIG_NR_DRAM_BANKS > 1)) |
| 52 | nr_dram_banks += readl(&iim->bank[1].fuse_regs[9]) & 0x01; |
| 53 | else |
| 54 | nr_dram_banks = CONFIG_NR_DRAM_POPULATED; |
| 55 | |
| 56 | return nr_dram_banks; |
| 57 | } |
| 58 | |
| 59 | static void apf27_port_init(int port, u32 gpio_dr, u32 ocr1, u32 ocr2, |
| 60 | u32 iconfa1, u32 iconfa2, u32 iconfb1, u32 iconfb2, |
| 61 | u32 icr1, u32 icr2, u32 imr, u32 gpio_dir, u32 gpr, |
| 62 | u32 puen, u32 gius) |
| 63 | { |
| 64 | struct gpio_port_regs *regs = (struct gpio_port_regs *)IMX_GPIO_BASE; |
| 65 | |
| 66 | writel(gpio_dr, ®s->port[port].gpio_dr); |
| 67 | writel(ocr1, ®s->port[port].ocr1); |
| 68 | writel(ocr2, ®s->port[port].ocr2); |
| 69 | writel(iconfa1, ®s->port[port].iconfa1); |
| 70 | writel(iconfa2, ®s->port[port].iconfa2); |
| 71 | writel(iconfb1, ®s->port[port].iconfb1); |
| 72 | writel(iconfb2, ®s->port[port].iconfb2); |
| 73 | writel(icr1, ®s->port[port].icr1); |
| 74 | writel(icr2, ®s->port[port].icr2); |
| 75 | writel(imr, ®s->port[port].imr); |
| 76 | writel(gpio_dir, ®s->port[port].gpio_dir); |
| 77 | writel(gpr, ®s->port[port].gpr); |
| 78 | writel(puen, ®s->port[port].puen); |
| 79 | writel(gius, ®s->port[port].gius); |
| 80 | } |
| 81 | |
| 82 | #define APF27_PORT_INIT(n) apf27_port_init(PORT##n, ACFG_DR_##n##_VAL, \ |
| 83 | ACFG_OCR1_##n##_VAL, ACFG_OCR2_##n##_VAL, ACFG_ICFA1_##n##_VAL, \ |
| 84 | ACFG_ICFA2_##n##_VAL, ACFG_ICFB1_##n##_VAL, ACFG_ICFB2_##n##_VAL, \ |
| 85 | ACFG_ICR1_##n##_VAL, ACFG_ICR2_##n##_VAL, ACFG_IMR_##n##_VAL, \ |
| 86 | ACFG_DDIR_##n##_VAL, ACFG_GPR_##n##_VAL, ACFG_PUEN_##n##_VAL, \ |
| 87 | ACFG_GIUS_##n##_VAL) |
| 88 | |
| 89 | static void apf27_iomux_init(void) |
| 90 | { |
| 91 | APF27_PORT_INIT(A); |
| 92 | APF27_PORT_INIT(B); |
| 93 | APF27_PORT_INIT(C); |
| 94 | APF27_PORT_INIT(D); |
| 95 | APF27_PORT_INIT(E); |
| 96 | APF27_PORT_INIT(F); |
| 97 | } |
| 98 | |
| 99 | static int apf27_devices_init(void) |
| 100 | { |
| 101 | int i; |
| 102 | unsigned int mode[] = { |
| 103 | PC5_PF_I2C2_DATA, |
| 104 | PC6_PF_I2C2_CLK, |
| 105 | PD17_PF_I2C_DATA, |
| 106 | PD18_PF_I2C_CLK, |
| 107 | }; |
| 108 | |
| 109 | for (i = 0; i < ARRAY_SIZE(mode); i++) |
| 110 | imx_gpio_mode(mode[i]); |
| 111 | |
| 112 | #ifdef CONFIG_MXC_UART |
| 113 | mx27_uart1_init_pins(); |
| 114 | #endif |
| 115 | |
| 116 | #ifdef CONFIG_FEC_MXC |
| 117 | mx27_fec_init_pins(); |
| 118 | #endif |
| 119 | |
Masahiro Yamada | 1d2c050 | 2017-01-10 13:32:07 +0900 | [diff] [blame] | 120 | #ifdef CONFIG_MMC_MXC |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 121 | mx27_sd2_init_pins(); |
| 122 | imx_gpio_mode((GPIO_PORTF | GPIO_OUT | GPIO_PUEN | GPIO_GPIO | 16)); |
| 123 | gpio_request(PC_PWRON, "pc_pwron"); |
| 124 | gpio_set_value(PC_PWRON, 1); |
| 125 | #endif |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static void apf27_setup_csx(void) |
| 130 | { |
| 131 | struct weim_regs *weim = (struct weim_regs *)IMX_WEIM_BASE; |
| 132 | |
| 133 | writel(ACFG_CS0U_VAL, &weim->cs0u); |
| 134 | writel(ACFG_CS0L_VAL, &weim->cs0l); |
| 135 | writel(ACFG_CS0A_VAL, &weim->cs0a); |
| 136 | |
| 137 | writel(ACFG_CS1U_VAL, &weim->cs1u); |
| 138 | writel(ACFG_CS1L_VAL, &weim->cs1l); |
| 139 | writel(ACFG_CS1A_VAL, &weim->cs1a); |
| 140 | |
| 141 | writel(ACFG_CS2U_VAL, &weim->cs2u); |
| 142 | writel(ACFG_CS2L_VAL, &weim->cs2l); |
| 143 | writel(ACFG_CS2A_VAL, &weim->cs2a); |
| 144 | |
| 145 | writel(ACFG_CS3U_VAL, &weim->cs3u); |
| 146 | writel(ACFG_CS3L_VAL, &weim->cs3l); |
| 147 | writel(ACFG_CS3A_VAL, &weim->cs3a); |
| 148 | |
| 149 | writel(ACFG_CS4U_VAL, &weim->cs4u); |
| 150 | writel(ACFG_CS4L_VAL, &weim->cs4l); |
| 151 | writel(ACFG_CS4A_VAL, &weim->cs4a); |
| 152 | |
| 153 | writel(ACFG_CS5U_VAL, &weim->cs5u); |
| 154 | writel(ACFG_CS5L_VAL, &weim->cs5l); |
| 155 | writel(ACFG_CS5A_VAL, &weim->cs5a); |
| 156 | |
| 157 | writel(ACFG_EIM_VAL, &weim->eim); |
| 158 | } |
| 159 | |
| 160 | static void apf27_setup_port(void) |
| 161 | { |
| 162 | struct system_control_regs *system = |
| 163 | (struct system_control_regs *)IMX_SYSTEM_CTL_BASE; |
| 164 | |
| 165 | writel(ACFG_FMCR_VAL, &system->fmcr); |
| 166 | } |
| 167 | |
| 168 | int board_init(void) |
| 169 | { |
| 170 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 171 | |
| 172 | apf27_setup_csx(); |
| 173 | apf27_setup_port(); |
| 174 | apf27_iomux_init(); |
| 175 | apf27_devices_init(); |
trem | b5e7f1b | 2013-09-10 22:08:40 +0200 | [diff] [blame] | 176 | #if defined(CONFIG_FPGA) |
| 177 | APF27_init_fpga(); |
| 178 | #endif |
| 179 | |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int dram_init(void) |
| 185 | { |
| 186 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE); |
| 187 | if (get_num_ram_bank() > 1) |
| 188 | gd->ram_size += get_ram_size((void *)PHYS_SDRAM_2, |
| 189 | PHYS_SDRAM_2_SIZE); |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 194 | int dram_init_banksize(void) |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 195 | { |
| 196 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 197 | gd->bd->bi_dram[0].size = get_ram_size((void *)PHYS_SDRAM_1, |
| 198 | PHYS_SDRAM_1_SIZE); |
| 199 | gd->bd->bi_dram[1].start = PHYS_SDRAM_2; |
| 200 | if (get_num_ram_bank() > 1) |
| 201 | gd->bd->bi_dram[1].size = get_ram_size((void *)PHYS_SDRAM_2, |
| 202 | PHYS_SDRAM_2_SIZE); |
| 203 | else |
| 204 | gd->bd->bi_dram[1].size = 0; |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 205 | |
| 206 | return 0; |
trem | bcc05c7 | 2013-09-10 22:08:39 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | ulong board_get_usable_ram_top(ulong total_size) |
| 210 | { |
| 211 | ulong ramtop; |
| 212 | |
| 213 | if (get_num_ram_bank() > 1) |
| 214 | ramtop = PHYS_SDRAM_2 + get_ram_size((void *)PHYS_SDRAM_2, |
| 215 | PHYS_SDRAM_2_SIZE); |
| 216 | else |
| 217 | ramtop = PHYS_SDRAM_1 + get_ram_size((void *)PHYS_SDRAM_1, |
| 218 | PHYS_SDRAM_1_SIZE); |
| 219 | |
| 220 | return ramtop; |
| 221 | } |
| 222 | |
| 223 | int checkboard(void) |
| 224 | { |
| 225 | printf("Board: Armadeus APF27 revision %d\n", get_board_rev()); |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | #ifdef CONFIG_SPL_BUILD |
| 230 | inline void hang(void) |
| 231 | { |
| 232 | for (;;) |
| 233 | ; |
| 234 | } |
| 235 | |
| 236 | void board_init_f(ulong bootflag) |
| 237 | { |
| 238 | /* |
| 239 | * copy ourselves from where we are running to where we were |
| 240 | * linked at. Use ulong pointers as all addresses involved |
| 241 | * are 4-byte-aligned. |
| 242 | */ |
| 243 | ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst; |
| 244 | asm volatile ("ldr %0, =_start" : "=r"(start_ptr)); |
| 245 | asm volatile ("ldr %0, =_end" : "=r"(end_ptr)); |
| 246 | asm volatile ("ldr %0, =board_init_f" : "=r"(link_ptr)); |
| 247 | asm volatile ("adr %0, board_init_f" : "=r"(run_ptr)); |
| 248 | for (dst = start_ptr; dst < end_ptr; dst++) |
| 249 | *dst = *(dst+(run_ptr-link_ptr)); |
| 250 | |
| 251 | /* |
| 252 | * branch to nand_boot's link-time address. |
| 253 | */ |
| 254 | asm volatile("ldr pc, =nand_boot"); |
| 255 | } |
| 256 | #endif /* CONFIG_SPL_BUILD */ |