Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 2 | * (C) Copyright 2007-2013 |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 18 | * MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <common.h> |
Stefan Roese | c25dd8f | 2007-08-23 11:02:37 +0200 | [diff] [blame] | 22 | #include <command.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 23 | #include <asm/ppc440.h> |
Stefan Roese | 04e6c38 | 2007-07-04 10:06:30 +0200 | [diff] [blame] | 24 | #include <asm/processor.h> |
Stefan Roese | 0988776 | 2010-09-16 14:30:37 +0200 | [diff] [blame] | 25 | #include <asm/ppc4xx-gpio.h> |
Stefan Roese | 04e6c38 | 2007-07-04 10:06:30 +0200 | [diff] [blame] | 26 | #include <asm/io.h> |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 27 | #include <post.h> |
| 28 | #include <flash.h> |
| 29 | #include <mtd/cfi_flash.h> |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 33 | static phys_addr_t lwmon5_cfi_flash_bank_addr[2] = CONFIG_SYS_FLASH_BANKS_LIST; |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 34 | |
Stefan Roese | 3ad6387 | 2007-08-21 16:27:57 +0200 | [diff] [blame] | 35 | ulong flash_get_size(ulong base, int banknum); |
| 36 | int misc_init_r_kbd(void); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 37 | |
| 38 | int board_early_init_f(void) |
| 39 | { |
| 40 | u32 sdr0_pfc1, sdr0_pfc2; |
| 41 | u32 reg; |
| 42 | |
Wolfgang Denk | 83b4cfa | 2007-06-20 18:14:24 +0200 | [diff] [blame] | 43 | /* PLB Write pipelining disabled. Denali Core workaround */ |
Stefan Roese | 5e7abce | 2010-09-11 09:31:43 +0200 | [diff] [blame] | 44 | mtdcr(PLB4A0_ACR, 0xDE000000); |
| 45 | mtdcr(PLB4A1_ACR, 0xDE000000); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 46 | |
| 47 | /*-------------------------------------------------------------------- |
| 48 | * Setup the interrupt controller polarities, triggers, etc. |
| 49 | *-------------------------------------------------------------------*/ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 50 | mtdcr(UIC0SR, 0xffffffff); /* clear all. if write with 1 then the status is cleared */ |
| 51 | mtdcr(UIC0ER, 0x00000000); /* disable all */ |
| 52 | mtdcr(UIC0CR, 0x00000000); /* we have not critical interrupts at the moment */ |
| 53 | mtdcr(UIC0PR, 0xFFBFF1EF); /* Adjustment of the polarity */ |
| 54 | mtdcr(UIC0TR, 0x00000900); /* per ref-board manual */ |
| 55 | mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */ |
| 56 | mtdcr(UIC0SR, 0xffffffff); /* clear all */ |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 57 | |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 58 | mtdcr(UIC1SR, 0xffffffff); /* clear all */ |
| 59 | mtdcr(UIC1ER, 0x00000000); /* disable all */ |
| 60 | mtdcr(UIC1CR, 0x00000000); /* all non-critical */ |
| 61 | mtdcr(UIC1PR, 0xFFFFC6A5); /* Adjustment of the polarity */ |
| 62 | mtdcr(UIC1TR, 0x60000040); /* per ref-board manual */ |
| 63 | mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */ |
| 64 | mtdcr(UIC1SR, 0xffffffff); /* clear all */ |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 65 | |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 66 | mtdcr(UIC2SR, 0xffffffff); /* clear all */ |
| 67 | mtdcr(UIC2ER, 0x00000000); /* disable all */ |
| 68 | mtdcr(UIC2CR, 0x00000000); /* all non-critical */ |
| 69 | mtdcr(UIC2PR, 0x27C00000); /* Adjustment of the polarity */ |
| 70 | mtdcr(UIC2TR, 0x3C000000); /* per ref-board manual */ |
| 71 | mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */ |
| 72 | mtdcr(UIC2SR, 0xffffffff); /* clear all */ |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 73 | |
| 74 | /* Trace Pins are disabled. SDR0_PFC0 Register */ |
| 75 | mtsdr(SDR0_PFC0, 0x0); |
| 76 | |
| 77 | /* select Ethernet pins */ |
| 78 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 79 | /* SMII via ZMII */ |
| 80 | sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) | |
| 81 | SDR0_PFC1_SELECT_CONFIG_6; |
| 82 | mfsdr(SDR0_PFC2, sdr0_pfc2); |
| 83 | sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) | |
| 84 | SDR0_PFC2_SELECT_CONFIG_6; |
| 85 | |
| 86 | /* enable SPI (SCP) */ |
| 87 | sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_SCP_SEL; |
| 88 | |
| 89 | mtsdr(SDR0_PFC2, sdr0_pfc2); |
| 90 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 91 | |
| 92 | mtsdr(SDR0_PFC4, 0x80000000); |
| 93 | |
| 94 | /* PCI arbiter disabled */ |
Wolfgang Denk | 83b4cfa | 2007-06-20 18:14:24 +0200 | [diff] [blame] | 95 | /* PCI Host Configuration disbaled */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 96 | mfsdr(SDR0_PCI0, reg); |
Wolfgang Denk | 83b4cfa | 2007-06-20 18:14:24 +0200 | [diff] [blame] | 97 | reg = 0; |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 98 | mtsdr(SDR0_PCI0, 0x00000000 | reg); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 99 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | gpio_write_bit(CONFIG_SYS_GPIO_FLASH_WP, 1); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 101 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | #if CONFIG_POST & CONFIG_SYS_POST_BSPEC1 |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 103 | /* enable the LSB transmitter */ |
| 104 | gpio_write_bit(CONFIG_SYS_GPIO_LSB_ENABLE, 1); |
| 105 | /* enable the CAN transmitter */ |
| 106 | gpio_write_bit(CONFIG_SYS_GPIO_CAN_ENABLE, 1); |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 107 | |
| 108 | reg = 0; /* reuse as counter */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 109 | out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR, |
| 110 | in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) |
| 111 | & ~CONFIG_SYS_DSPIC_TEST_MASK); |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 112 | while (gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY) && reg++ < 1000) { |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 113 | udelay(1000); |
| 114 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 115 | if (gpio_read_in_bit(CONFIG_SYS_GPIO_DSPIC_READY)) { |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 116 | /* set "boot error" flag */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 117 | out_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR, |
| 118 | in_be32((void *)CONFIG_SYS_DSPIC_TEST_ADDR) | |
| 119 | CONFIG_SYS_DSPIC_TEST_MASK); |
Yuri Tikhonov | 65b20dc | 2008-02-04 14:10:42 +0100 | [diff] [blame] | 120 | } |
| 121 | #endif |
| 122 | |
Stefan Roese | 54fd6c9 | 2007-11-13 08:18:20 +0100 | [diff] [blame] | 123 | /* |
| 124 | * Reset PHY's: |
| 125 | * The PHY's need a 2nd reset pulse, since the MDIO address is latched |
| 126 | * upon reset, and with the first reset upon powerup, the addresses are |
| 127 | * not latched reliable, since the IRQ line is multiplexed with an |
| 128 | * MDIO address. A 2nd reset at this time will make sure, that the |
| 129 | * correct address is latched. |
| 130 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 131 | gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1); |
| 132 | gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1); |
Stefan Roese | 54fd6c9 | 2007-11-13 08:18:20 +0100 | [diff] [blame] | 133 | udelay(1000); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 0); |
| 135 | gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 0); |
Stefan Roese | 54fd6c9 | 2007-11-13 08:18:20 +0100 | [diff] [blame] | 136 | udelay(1000); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 137 | gpio_write_bit(CONFIG_SYS_GPIO_PHY0_RST, 1); |
| 138 | gpio_write_bit(CONFIG_SYS_GPIO_PHY1_RST, 1); |
Stefan Roese | 54fd6c9 | 2007-11-13 08:18:20 +0100 | [diff] [blame] | 139 | |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 143 | /* |
| 144 | * Override weak default with board specific version |
| 145 | */ |
| 146 | phys_addr_t cfi_flash_bank_addr(int bank) |
| 147 | { |
| 148 | return lwmon5_cfi_flash_bank_addr[bank]; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Override the weak default mapping function with a board specific one |
| 153 | */ |
| 154 | u32 flash_get_bank_size(int cs, int idx) |
| 155 | { |
| 156 | return flash_info[idx].size; |
| 157 | } |
| 158 | |
| 159 | int board_early_init_r(void) |
| 160 | { |
| 161 | u32 val0, val1; |
| 162 | |
| 163 | /* |
| 164 | * lwmon5 is manufactured in 2 different board versions: |
| 165 | * The lwmon5a board has 64MiB NOR flash instead of the |
| 166 | * 128MiB of the original lwmon5. Unfortunately the CFI driver |
| 167 | * will report 2 banks of 64MiB even for the smaller flash |
| 168 | * chip, since the bank is mirrored. To fix this, we bring |
| 169 | * one bank into CFI query mode and read its response. This |
| 170 | * enables us to detect the real number of flash devices/ |
| 171 | * banks which will be used later on by the common CFI driver. |
| 172 | */ |
| 173 | |
| 174 | /* Put bank 0 into CFI command mode and read */ |
| 175 | out_be32((void *)CONFIG_SYS_FLASH0, 0x00980098); |
| 176 | val0 = in_be32((void *)CONFIG_SYS_FLASH0 + FLASH_OFFSET_CFI_RESP); |
| 177 | val1 = in_be32((void *)CONFIG_SYS_FLASH1 + FLASH_OFFSET_CFI_RESP); |
| 178 | |
| 179 | /* Reset flash again out of query mode */ |
| 180 | out_be32((void *)CONFIG_SYS_FLASH0, 0x00f000f0); |
| 181 | |
| 182 | /* When not identical, we have 2 different flash devices/banks */ |
| 183 | if (val0 != val1) |
| 184 | return 0; |
| 185 | |
| 186 | /* |
| 187 | * Now we're sure that we're running on a LWMON5a board with |
| 188 | * only 64MiB NOR flash in one bank: |
| 189 | * |
| 190 | * Set flash base address and bank count for CFI driver probing. |
| 191 | */ |
| 192 | cfi_flash_num_flash_banks = 1; |
| 193 | lwmon5_cfi_flash_bank_addr[0] = CONFIG_SYS_FLASH0; |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 198 | int misc_init_r(void) |
| 199 | { |
| 200 | u32 pbcr; |
| 201 | int size_val = 0; |
| 202 | u32 reg; |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 203 | #ifndef CONFIG_LCD4_LWMON5 |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 204 | unsigned long usb2d0cr = 0; |
| 205 | unsigned long usb2phy0cr, usb2h0cr = 0; |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 206 | unsigned long sdr0_pfc1, sdr0_srst; |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 207 | #endif |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 208 | |
| 209 | /* |
| 210 | * FLASH stuff... |
| 211 | */ |
| 212 | |
| 213 | /* Re-do sizing to get full correct info */ |
| 214 | |
| 215 | /* adjust flash start and offset */ |
| 216 | gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; |
| 217 | gd->bd->bi_flashoffset = 0; |
| 218 | |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 219 | mfebc(PB0CR, pbcr); |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 220 | size_val = ffs(gd->bd->bi_flashsize) - 21; |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 221 | pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17); |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 222 | mtebc(PB0CR, pbcr); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * Re-check to get correct base address |
| 226 | */ |
| 227 | flash_get_size(gd->bd->bi_flashstart, 0); |
| 228 | |
| 229 | /* Monitor protection ON by default */ |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 230 | flash_protect(FLAG_PROTECT_SET, -CONFIG_SYS_MONITOR_LEN, 0xffffffff, |
| 231 | &flash_info[cfi_flash_num_flash_banks - 1]); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 232 | |
| 233 | /* Env protection ON by default */ |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 234 | flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND, |
| 235 | CONFIG_ENV_ADDR_REDUND + 2 * CONFIG_ENV_SECT_SIZE - 1, |
| 236 | &flash_info[cfi_flash_num_flash_banks - 1]); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 237 | |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 238 | #ifndef CONFIG_LCD4_LWMON5 |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 239 | /* |
| 240 | * USB suff... |
| 241 | */ |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 242 | |
| 243 | /* Reset USB */ |
| 244 | /* Reset of USB2PHY0 must be active at least 10 us */ |
| 245 | mtsdr(SDR0_SRST0, SDR0_SRST0_USB2H | SDR0_SRST0_USB2D); |
| 246 | udelay(2000); |
| 247 | |
| 248 | mtsdr(SDR0_SRST1, SDR0_SRST1_USB20PHY | SDR0_SRST1_USB2HUTMI | |
| 249 | SDR0_SRST1_USB2HPHY | SDR0_SRST1_OPBA2 | |
| 250 | SDR0_SRST1_PLB42OPB1 | SDR0_SRST1_OPB2PLB40); |
| 251 | udelay(2000); |
| 252 | |
| 253 | /* Errata CHIP_6 */ |
| 254 | |
| 255 | /* 1. Set internal PHY configuration */ |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 256 | /* SDR Setting */ |
| 257 | mfsdr(SDR0_PFC1, sdr0_pfc1); |
| 258 | mfsdr(SDR0_USB0, usb2d0cr); |
| 259 | mfsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 260 | mfsdr(SDR0_USB2H0CR, usb2h0cr); |
| 261 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 262 | usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_XOCLK_MASK; |
| 263 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0*/ |
| 264 | usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_WDINT_MASK; |
| 265 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; /*1*/ |
| 266 | usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DVBUS_MASK; |
| 267 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PUREN; /*1*/ |
| 268 | usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_DWNSTR_MASK; |
| 269 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1*/ |
| 270 | usb2phy0cr = usb2phy0cr & ~SDR0_USB2PHY0CR_UTMICN_MASK; |
| 271 | usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1*/ |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 272 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 273 | /* |
| 274 | * An 8-bit/60MHz interface is the only possible alternative |
| 275 | * when connecting the Device to the PHY |
| 276 | */ |
| 277 | usb2h0cr = usb2h0cr & ~SDR0_USB2H0CR_WDINT_MASK; |
| 278 | usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; /*1*/ |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 279 | |
| 280 | mtsdr(SDR0_PFC1, sdr0_pfc1); |
| 281 | mtsdr(SDR0_USB0, usb2d0cr); |
| 282 | mtsdr(SDR0_USB2PHY0CR, usb2phy0cr); |
| 283 | mtsdr(SDR0_USB2H0CR, usb2h0cr); |
| 284 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 285 | /* 2. De-assert internal PHY reset */ |
| 286 | mfsdr(SDR0_SRST1, sdr0_srst); |
| 287 | sdr0_srst = sdr0_srst & ~SDR0_SRST1_USB20PHY; |
| 288 | mtsdr(SDR0_SRST1, sdr0_srst); |
| 289 | |
| 290 | /* 3. Wait for more than 1 ms */ |
| 291 | udelay(2000); |
| 292 | |
| 293 | /* 4. De-assert USB 2.0 Host main reset */ |
| 294 | mfsdr(SDR0_SRST0, sdr0_srst); |
| 295 | sdr0_srst = sdr0_srst &~ SDR0_SRST0_USB2H; |
| 296 | mtsdr(SDR0_SRST0, sdr0_srst); |
| 297 | udelay(1000); |
| 298 | |
| 299 | /* 5. De-assert reset of OPB2 cores */ |
| 300 | mfsdr(SDR0_SRST1, sdr0_srst); |
| 301 | sdr0_srst = sdr0_srst &~ SDR0_SRST1_PLB42OPB1; |
| 302 | sdr0_srst = sdr0_srst &~ SDR0_SRST1_OPB2PLB40; |
| 303 | sdr0_srst = sdr0_srst &~ SDR0_SRST1_OPBA2; |
| 304 | mtsdr(SDR0_SRST1, sdr0_srst); |
| 305 | udelay(1000); |
| 306 | |
| 307 | /* 6. Set EHCI Configure FLAG */ |
| 308 | |
| 309 | /* 7. Reassert internal PHY reset: */ |
| 310 | mtsdr(SDR0_SRST1, SDR0_SRST1_USB20PHY); |
| 311 | udelay(1000); |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 312 | #endif |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 313 | |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 314 | /* |
| 315 | * Clear resets |
| 316 | */ |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 317 | mtsdr(SDR0_SRST1, 0x00000000); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 318 | mtsdr(SDR0_SRST0, 0x00000000); |
| 319 | |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 320 | #ifndef CONFIG_LCD4_LWMON5 |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 321 | printf("USB: Host(int phy) Device(ext phy)\n"); |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 322 | #endif |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * Clear PLB4A0_ACR[WRP] |
| 326 | * This fix will make the MAL burst disabling patch for the Linux |
| 327 | * EMAC driver obsolete. |
| 328 | */ |
Stefan Roese | 5e7abce | 2010-09-11 09:31:43 +0200 | [diff] [blame] | 329 | reg = mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_WRP_MASK; |
| 330 | mtdcr(PLB4A0_ACR, reg); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 331 | |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 332 | #ifndef CONFIG_LCD4_LWMON5 |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 333 | /* |
Stefan Roese | 3ad6387 | 2007-08-21 16:27:57 +0200 | [diff] [blame] | 334 | * Init matrix keyboard |
| 335 | */ |
| 336 | misc_init_r_kbd(); |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 337 | #endif |
Stefan Roese | 3ad6387 | 2007-08-21 16:27:57 +0200 | [diff] [blame] | 338 | |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | int checkboard(void) |
| 343 | { |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 344 | char buf[64]; |
| 345 | int i = getenv_f("serial#", buf, sizeof(buf)); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 346 | |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 347 | printf("Board: %s", __stringify(CONFIG_HOSTNAME)); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 348 | |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 349 | if (i > 0) { |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 350 | puts(", serial# "); |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 351 | puts(buf); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 352 | } |
| 353 | putc('\n'); |
| 354 | |
| 355 | return (0); |
| 356 | } |
| 357 | |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 358 | void hw_watchdog_reset(void) |
| 359 | { |
| 360 | int val; |
Yuri Tikhonov | d32a874 | 2008-04-06 19:19:14 +0200 | [diff] [blame] | 361 | #if defined(CONFIG_WD_MAX_RATE) |
| 362 | unsigned long long ct = get_ticks(); |
| 363 | |
| 364 | /* |
| 365 | * Don't allow watch-dog triggering more frequently than |
| 366 | * the predefined value CONFIG_WD_MAX_RATE [ticks]. |
| 367 | */ |
Simon Glass | a0d3c82 | 2012-12-13 20:49:03 +0000 | [diff] [blame] | 368 | if (ct >= gd->arch.wdt_last) { |
| 369 | if ((ct - gd->arch.wdt_last) < CONFIG_WD_MAX_RATE) |
Yuri Tikhonov | d32a874 | 2008-04-06 19:19:14 +0200 | [diff] [blame] | 370 | return; |
| 371 | } else { |
| 372 | /* Time base counter had been reset */ |
Simon Glass | a0d3c82 | 2012-12-13 20:49:03 +0000 | [diff] [blame] | 373 | if (((unsigned long long)(-1) - gd->arch.wdt_last + ct) < |
Yuri Tikhonov | d32a874 | 2008-04-06 19:19:14 +0200 | [diff] [blame] | 374 | CONFIG_WD_MAX_RATE) |
| 375 | return; |
| 376 | } |
Simon Glass | a0d3c82 | 2012-12-13 20:49:03 +0000 | [diff] [blame] | 377 | gd->arch.wdt_last = get_ticks(); |
Yuri Tikhonov | d32a874 | 2008-04-06 19:19:14 +0200 | [diff] [blame] | 378 | #endif |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 379 | |
| 380 | /* |
| 381 | * Toggle watchdog output |
| 382 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 383 | val = gpio_read_out_bit(CONFIG_SYS_GPIO_WATCHDOG) == 0 ? 1 : 0; |
| 384 | gpio_write_bit(CONFIG_SYS_GPIO_WATCHDOG, val); |
Stefan Roese | b765ffb | 2007-06-15 08:18:01 +0200 | [diff] [blame] | 385 | } |
Stefan Roese | c25dd8f | 2007-08-23 11:02:37 +0200 | [diff] [blame] | 386 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 387 | int do_eeprom_wp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | c25dd8f | 2007-08-23 11:02:37 +0200 | [diff] [blame] | 388 | { |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 389 | if (argc < 2) |
| 390 | return cmd_usage(cmdtp); |
Stefan Roese | c25dd8f | 2007-08-23 11:02:37 +0200 | [diff] [blame] | 391 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 392 | if ((strcmp(argv[1], "on") == 0)) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 393 | gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 1); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 394 | else if ((strcmp(argv[1], "off") == 0)) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 395 | gpio_write_bit(CONFIG_SYS_GPIO_EEPROM_EXT_WP, 0); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 396 | else |
| 397 | return cmd_usage(cmdtp); |
Stefan Roese | c25dd8f | 2007-08-23 11:02:37 +0200 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | U_BOOT_CMD( |
| 403 | eepromwp, 2, 0, do_eeprom_wp, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 404 | "eeprom write protect off/on", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 405 | "<on|off> - enable (on) or disable (off) I2C EEPROM write protect" |
Stefan Roese | c25dd8f | 2007-08-23 11:02:37 +0200 | [diff] [blame] | 406 | ); |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 407 | |
| 408 | #if defined(CONFIG_VIDEO) |
| 409 | #include <video_fb.h> |
| 410 | #include <mb862xx.h> |
| 411 | |
| 412 | extern GraphicDevice mb862xx; |
| 413 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 414 | static const gdc_regs init_regs [] = { |
| 415 | { 0x0100, 0x00000f00 }, |
| 416 | { 0x0020, 0x801401df }, |
| 417 | { 0x0024, 0x00000000 }, |
| 418 | { 0x0028, 0x00000000 }, |
| 419 | { 0x002c, 0x00000000 }, |
| 420 | { 0x0110, 0x00000000 }, |
| 421 | { 0x0114, 0x00000000 }, |
| 422 | { 0x0118, 0x01df0280 }, |
| 423 | { 0x0004, 0x031f0000 }, |
| 424 | { 0x0008, 0x027f027f }, |
| 425 | { 0x000c, 0x015f028f }, |
| 426 | { 0x0010, 0x020c0000 }, |
| 427 | { 0x0014, 0x01df01ea }, |
| 428 | { 0x0018, 0x00000000 }, |
| 429 | { 0x001c, 0x01e00280 }, |
| 430 | { 0x0100, 0x80010f00 }, |
| 431 | { 0x0, 0x0 } |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 432 | }; |
| 433 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 434 | const gdc_regs *board_get_regs(void) |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 435 | { |
| 436 | return init_regs; |
| 437 | } |
| 438 | |
| 439 | /* Returns Lime base address */ |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 440 | unsigned int board_video_init(void) |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 441 | { |
| 442 | /* |
| 443 | * Reset Lime controller |
| 444 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 445 | gpio_write_bit(CONFIG_SYS_GPIO_LIME_S, 1); |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 446 | udelay(500); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 447 | gpio_write_bit(CONFIG_SYS_GPIO_LIME_RST, 1); |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 448 | |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 449 | mb862xx.winSizeX = 640; |
| 450 | mb862xx.winSizeY = 480; |
| 451 | mb862xx.gdfBytesPP = 2; |
| 452 | mb862xx.gdfIndex = GDF_15BIT_555RGB; |
| 453 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 454 | return CONFIG_SYS_LIME_BASE_0; |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 457 | #define DEFAULT_BRIGHTNESS 0x64 |
Yuri Tikhonov | 0f855a1 | 2008-03-18 13:27:57 +0100 | [diff] [blame] | 458 | |
| 459 | static void board_backlight_brightness(int brightness) |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 460 | { |
Yuri Tikhonov | 0f855a1 | 2008-03-18 13:27:57 +0100 | [diff] [blame] | 461 | if (brightness > 0) { |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 462 | /* pwm duty, lamp on */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 463 | out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), brightness); |
| 464 | out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x701); |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 465 | } else { |
| 466 | /* lamp off */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 467 | out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000024), 0x00); |
| 468 | out_be32((void *)(CONFIG_SYS_FPGA_BASE_0 + 0x00000020), 0x00); |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 472 | void board_backlight_switch(int flag) |
Yuri Tikhonov | 0f855a1 | 2008-03-18 13:27:57 +0100 | [diff] [blame] | 473 | { |
| 474 | char * param; |
| 475 | int rc; |
| 476 | |
| 477 | if (flag) { |
| 478 | param = getenv("brightness"); |
| 479 | rc = param ? simple_strtol(param, NULL, 10) : -1; |
| 480 | if (rc < 0) |
| 481 | rc = DEFAULT_BRIGHTNESS; |
| 482 | } else { |
| 483 | rc = 0; |
| 484 | } |
| 485 | board_backlight_brightness(rc); |
| 486 | } |
| 487 | |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 488 | #if defined(CONFIG_CONSOLE_EXTRA_INFO) |
| 489 | /* |
| 490 | * Return text to be printed besides the logo. |
| 491 | */ |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 492 | void video_get_info_str(int line_number, char *info) |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 493 | { |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 494 | if (line_number == 1) |
| 495 | strcpy(info, " Board: Lwmon5 (Liebherr Elektronik GmbH)"); |
| 496 | else |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 497 | info [0] = '\0'; |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 498 | } |
Sascha Laue | f14ae41 | 2010-08-19 09:38:56 +0200 | [diff] [blame] | 499 | #endif /* CONFIG_CONSOLE_EXTRA_INFO */ |
Anatolij Gustschin | d610a60 | 2008-01-11 15:31:09 +0100 | [diff] [blame] | 500 | #endif /* CONFIG_VIDEO */ |
Yuri Tikhonov | ff818b2 | 2008-02-04 17:11:53 +0100 | [diff] [blame] | 501 | |
| 502 | void board_reset(void) |
| 503 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 504 | gpio_write_bit(CONFIG_SYS_GPIO_BOARD_RESET, 1); |
Yuri Tikhonov | ff818b2 | 2008-02-04 17:11:53 +0100 | [diff] [blame] | 505 | } |
Stefan Roese | f47b048 | 2013-03-08 16:50:41 +0100 | [diff] [blame] | 506 | |
| 507 | #ifdef CONFIG_SPL_OS_BOOT |
| 508 | /* |
| 509 | * lwmon5 specific implementation of spl_start_uboot() |
| 510 | * |
| 511 | * RETURN |
| 512 | * 0 if booting into OS is selected (default) |
| 513 | * 1 if booting into U-Boot is selected |
| 514 | */ |
| 515 | int spl_start_uboot(void) |
| 516 | { |
| 517 | char s[8]; |
| 518 | |
| 519 | env_init(); |
| 520 | getenv_f("boot_os", s, sizeof(s)); |
| 521 | if ((s != NULL) && (strcmp(s, "yes") == 0)) |
| 522 | return 0; |
| 523 | |
| 524 | return 1; |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | * This function is called from the SPL U-Boot version for |
| 529 | * early init stuff, that needs to be done for OS (e.g. Linux) |
| 530 | * booting. Doing it later in the real U-Boot would not work |
| 531 | * in case that the SPL U-Boot boots Linux directly. |
| 532 | */ |
| 533 | void spl_board_init(void) |
| 534 | { |
| 535 | const gdc_regs *regs = board_get_regs(); |
| 536 | |
| 537 | /* |
| 538 | * Setup PFC registers, mainly for ethernet support |
| 539 | * later on in Linux |
| 540 | */ |
| 541 | board_early_init_f(); |
| 542 | |
| 543 | /* |
| 544 | * Clear resets |
| 545 | */ |
| 546 | mtsdr(SDR0_SRST1, 0x00000000); |
| 547 | mtsdr(SDR0_SRST0, 0x00000000); |
| 548 | |
| 549 | /* |
| 550 | * Reset Lime controller |
| 551 | */ |
| 552 | gpio_write_bit(CONFIG_SYS_GPIO_LIME_S, 1); |
| 553 | udelay(500); |
| 554 | gpio_write_bit(CONFIG_SYS_GPIO_LIME_RST, 1); |
| 555 | |
| 556 | out_be32((void *)CONFIG_SYS_LIME_SDRAM_CLOCK, CONFIG_SYS_MB862xx_CCF); |
| 557 | udelay(300); |
| 558 | out_be32((void *)CONFIG_SYS_LIME_MMR, CONFIG_SYS_MB862xx_MMR); |
| 559 | |
| 560 | while (regs->index) { |
| 561 | out_be32((void *)(CONFIG_SYS_LIME_BASE_0 + GC_DISP_BASE) + |
| 562 | regs->index, regs->value); |
| 563 | regs++; |
| 564 | } |
| 565 | |
| 566 | board_backlight_brightness(DEFAULT_BRIGHTNESS); |
| 567 | } |
| 568 | #endif |