Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003-2007 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * modified for Promess PRO - by Andy Joseph, andy@promessdev.com |
| 6 | * modified for Promess PRO-Motion - by Robert McCullough, rob@promessdev.com |
| 7 | * modified by Chris M. Tumas 6/20/06 Change CAS latency to 2 from 3 |
Wolfgang Denk | af0501a | 2008-10-19 02:35:50 +0200 | [diff] [blame] | 8 | * Also changed the refresh for 100MHz operation |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 9 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <mpc5xxx.h> |
Bartlomiej Sieka | 26b4c4f | 2007-05-27 16:58:45 +0200 | [diff] [blame] | 15 | #include <miiphy.h> |
Grant Likely | 8d1e6e7 | 2007-09-06 09:46:23 -0600 | [diff] [blame] | 16 | #include <libfdt.h> |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 17 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 18 | #if defined(CONFIG_LED_STATUS) |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 19 | #include <status_led.h> |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 20 | #endif /* CONFIG_LED_STATUS */ |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 21 | |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 22 | /* Kollmorgen DPR initialization data */ |
| 23 | struct init_elem { |
| 24 | unsigned long addr; |
| 25 | unsigned len; |
| 26 | char *data; |
| 27 | } init_seq[] = { |
| 28 | {0x500003F2, 2, "\x86\x00"}, /* HW parameter */ |
| 29 | {0x500003F0, 2, "\x00\x00"}, |
| 30 | {0x500003EC, 4, "\x00\x80\xc1\x52"}, /* Magic word */ |
| 31 | }; |
| 32 | |
| 33 | /* |
| 34 | * Initialize Kollmorgen DPR |
| 35 | */ |
| 36 | static void kollmorgen_init(void) |
| 37 | { |
| 38 | unsigned i, j; |
| 39 | vu_char *p; |
| 40 | |
| 41 | for (i = 0; i < sizeof(init_seq) / sizeof(struct init_elem); ++i) { |
| 42 | p = (vu_char *)init_seq[i].addr; |
| 43 | for (j = 0; j < init_seq[i].len; ++j) |
| 44 | *(p + j) = *(init_seq[i].data + j); |
| 45 | } |
| 46 | |
| 47 | printf("DPR: Kollmorgen DPR initialized\n"); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /* |
| 52 | * Early board initalization. |
| 53 | */ |
| 54 | int board_early_init_r(void) |
| 55 | { |
| 56 | /* Now, when we are in RAM, disable Boot Chipselect and enable CS0 */ |
| 57 | *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); |
| 58 | *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); |
| 59 | |
| 60 | /* Initialize Kollmorgen DPR */ |
| 61 | kollmorgen_init(); |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
Bartlomiej Sieka | 26b4c4f | 2007-05-27 16:58:45 +0200 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Additional PHY intialization. After being reset in mpc5xxx_fec_init_phy(), |
| 69 | * PHY goes into FX mode. To take it out of the FX mode and switch into |
| 70 | * desired TX operation, one needs to clear the FX_SEL bit of Mode Control |
| 71 | * Register. |
| 72 | */ |
| 73 | void reset_phy(void) |
| 74 | { |
| 75 | unsigned short mode_control; |
| 76 | |
Heiko Schocher | c5e8405 | 2010-07-20 17:45:02 +0200 | [diff] [blame] | 77 | miiphy_read("FEC", CONFIG_PHY_ADDR, 0x15, &mode_control); |
| 78 | miiphy_write("FEC", CONFIG_PHY_ADDR, 0x15, |
Bartlomiej Sieka | 26b4c4f | 2007-05-27 16:58:45 +0200 | [diff] [blame] | 79 | mode_control & 0xfffe); |
| 80 | return; |
| 81 | } |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 82 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 83 | #ifndef CONFIG_SYS_RAMBOOT |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 84 | /* |
| 85 | * Helper function to initialize SDRAM controller. |
| 86 | */ |
Bartlomiej Sieka | 082da16 | 2007-05-27 17:26:46 +0200 | [diff] [blame] | 87 | static void sdram_start(int hi_addr) |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 88 | { |
| 89 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 90 | |
| 91 | /* unlock mode register */ |
| 92 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | |
| 93 | hi_addr_bit; |
| 94 | |
| 95 | /* precharge all banks */ |
| 96 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | |
| 97 | hi_addr_bit; |
| 98 | |
| 99 | /* auto refresh */ |
| 100 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | |
| 101 | hi_addr_bit; |
| 102 | |
| 103 | /* auto refresh, second time */ |
| 104 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | |
| 105 | hi_addr_bit; |
| 106 | |
| 107 | /* set mode register */ |
| 108 | *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE; |
| 109 | |
| 110 | /* normal operation */ |
| 111 | *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit; |
| 112 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | #endif /* !CONFIG_SYS_RAMBOOT */ |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 114 | |
| 115 | |
| 116 | /* |
| 117 | * Initalize SDRAM - configure SDRAM controller, detect memory size. |
| 118 | */ |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 119 | phys_size_t initdram(int board_type) |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 120 | { |
| 121 | ulong dramsize = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 122 | #ifndef CONFIG_SYS_RAMBOOT |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 123 | ulong test1, test2; |
| 124 | |
Bartlomiej Sieka | 3b8b527 | 2007-10-23 11:36:07 +0200 | [diff] [blame] | 125 | /* According to AN3221 (MPC5200B SDRAM Initialization and |
| 126 | * Configuration), the SDelay register must be written a value of |
| 127 | * 0x00000004 as the first step of the SDRAM contorller configuration. |
| 128 | */ |
| 129 | *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04; |
| 130 | |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 131 | /* configure SDRAM start/end for detection */ |
| 132 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */ |
| 133 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */ |
| 134 | |
| 135 | /* setup config registers */ |
| 136 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1; |
| 137 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2; |
| 138 | |
| 139 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 141 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 143 | if (test1 > test2) { |
| 144 | sdram_start(0); |
| 145 | dramsize = test1; |
| 146 | } else { |
| 147 | dramsize = test2; |
| 148 | } |
| 149 | |
| 150 | /* memory smaller than 1MB is impossible */ |
| 151 | if (dramsize < (1 << 20)) |
| 152 | dramsize = 0; |
| 153 | |
| 154 | /* set SDRAM CS0 size according to the amount of RAM found */ |
Wolfgang Denk | 52232fd | 2007-02-27 14:26:04 +0100 | [diff] [blame] | 155 | if (dramsize > 0) { |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 156 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + |
| 157 | __builtin_ffs(dramsize >> 20) - 1; |
Wolfgang Denk | 52232fd | 2007-02-27 14:26:04 +0100 | [diff] [blame] | 158 | } else { |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 159 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */ |
Wolfgang Denk | 52232fd | 2007-02-27 14:26:04 +0100 | [diff] [blame] | 160 | } |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 161 | |
| 162 | /* let SDRAM CS1 start right after CS0 and disable it */ |
| 163 | *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; |
| 164 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 165 | #else /* !CONFIG_SYS_RAMBOOT */ |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 166 | /* retrieve size of memory connected to SDRAM CS0 */ |
| 167 | dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF; |
| 168 | if (dramsize >= 0x13) |
| 169 | dramsize = (1 << (dramsize - 0x13)) << 20; |
| 170 | else |
| 171 | dramsize = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | #endif /* CONFIG_SYS_RAMBOOT */ |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 173 | |
| 174 | /* return total ram size */ |
| 175 | return dramsize; |
| 176 | } |
| 177 | |
| 178 | |
Bartlomiej Sieka | 082da16 | 2007-05-27 17:26:46 +0200 | [diff] [blame] | 179 | int checkboard(void) |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 180 | { |
Bartlomiej Sieka | 4ac54f9 | 2007-05-27 16:55:23 +0200 | [diff] [blame] | 181 | uchar rev = *(vu_char *)CPLD_REV_REGISTER; |
| 182 | printf("Board: Promess Motion-PRO board (CPLD rev. 0x%02x)\n", rev); |
Bartlomiej Sieka | c619a9f | 2007-02-09 10:45:42 +0100 | [diff] [blame] | 183 | return 0; |
| 184 | } |
Bartlomiej Sieka | 8daee21 | 2007-05-08 09:21:57 +0200 | [diff] [blame] | 185 | |
| 186 | |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 187 | #ifdef CONFIG_OF_BOARD_SETUP |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 188 | int ft_board_setup(void *blob, bd_t *bd) |
Bartlomiej Sieka | 8daee21 | 2007-05-08 09:21:57 +0200 | [diff] [blame] | 189 | { |
| 190 | ft_cpu_setup(blob, bd); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 191 | |
| 192 | return 0; |
Bartlomiej Sieka | 8daee21 | 2007-05-08 09:21:57 +0200 | [diff] [blame] | 193 | } |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 194 | #endif /* CONFIG_OF_BOARD_SETUP */ |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 195 | |
| 196 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 197 | #if defined(CONFIG_LED_STATUS) |
| 198 | vu_long *regcode_to_regaddr(led_id_t regcode) |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 199 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 200 | /* GPT Enable and Mode Select Register address */ |
| 201 | vu_long *reg_translate[] = { |
| 202 | (vu_long *)MPC5XXX_GPT6_ENABLE, |
| 203 | (vu_long *)MPC5XXX_GPT7_ENABLE, |
| 204 | }; |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 205 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 206 | if (ARRAY_SIZE(reg_translate) <= regcode) |
| 207 | return NULL; |
| 208 | return reg_translate[regcode]; |
| 209 | } |
| 210 | |
| 211 | void __led_init(led_id_t regcode, int state) |
| 212 | { |
| 213 | vu_long *regaddr = regcode_to_regaddr(regcode); |
| 214 | |
| 215 | *regaddr |= ENABLE_GPIO_OUT; |
| 216 | |
| 217 | if (state == CONFIG_LED_STATUS_ON) |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 218 | *((vu_long *) regaddr) |= LED_ON; |
| 219 | else |
| 220 | *((vu_long *) regaddr) &= ~LED_ON; |
| 221 | } |
| 222 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 223 | void __led_set(led_id_t regcode, int state) |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 224 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 225 | vu_long *regaddr = regcode_to_regaddr(regcode); |
| 226 | |
| 227 | if (state == CONFIG_LED_STATUS_ON) |
| 228 | *regaddr |= LED_ON; |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 229 | else |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 230 | *regaddr &= ~LED_ON; |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 233 | void __led_toggle(led_id_t regcode) |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 234 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 235 | vu_long *regaddr = regcode_to_regaddr(regcode); |
| 236 | |
| 237 | *regaddr ^= LED_ON; |
Bartlomiej Sieka | c9e6a1e | 2007-05-27 16:51:48 +0200 | [diff] [blame] | 238 | } |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 239 | #endif /* CONFIG_LED_STATUS */ |