Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <asm/processor.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/ppc4xx-gpio.h> |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 14 | |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 15 | #include "405ep.h" |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 16 | #include <gdsys_fpga.h> |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 17 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 18 | #define REFLECTION_TESTPATTERN 0xdede |
| 19 | #define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff) |
| 20 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | int get_fpga_state(unsigned dev) |
| 24 | { |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 25 | return gd->arch.fpga_state[dev]; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void print_fpga_state(unsigned dev) |
| 29 | { |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 30 | if (gd->arch.fpga_state[dev] & FPGA_STATE_DONE_FAILED) |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 31 | puts(" Waiting for FPGA-DONE timed out.\n"); |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 32 | if (gd->arch.fpga_state[dev] & FPGA_STATE_REFLECTION_FAILED) |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 33 | puts(" FPGA reflection test failed.\n"); |
| 34 | } |
| 35 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 36 | int board_early_init_f(void) |
| 37 | { |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 38 | unsigned k; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 39 | |
| 40 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 41 | gd->arch.fpga_state[k] = 0; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 42 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 43 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 44 | mtdcr(UIC0ER, 0x00000000); /* disable all ints */ |
| 45 | mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical */ |
| 46 | mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */ |
| 47 | mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */ |
| 48 | mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest prio */ |
| 49 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 50 | |
| 51 | /* |
| 52 | * EBC Configuration Register: set ready timeout to 512 ebc-clks |
| 53 | * -> ca. 15 us |
| 54 | */ |
| 55 | mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */ |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | int board_early_init_r(void) |
| 60 | { |
| 61 | unsigned k; |
| 62 | unsigned ctr; |
| 63 | |
| 64 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 65 | gd->arch.fpga_state[k] = 0; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 66 | |
| 67 | /* |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 68 | * reset FPGA |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 69 | */ |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 70 | gd405ep_init(); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 71 | |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 72 | gd405ep_set_fpga_reset(1); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 73 | |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 74 | gd405ep_setup_hw(); |
| 75 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 76 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) { |
| 77 | ctr = 0; |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 78 | while (!gd405ep_get_fpga_done(k)) { |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 79 | udelay(100000); |
| 80 | if (ctr++ > 5) { |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 81 | gd->arch.fpga_state[k] |= |
| 82 | FPGA_STATE_DONE_FAILED; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 83 | break; |
| 84 | } |
| 85 | } |
| 86 | } |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 87 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 88 | udelay(10); |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 89 | |
| 90 | gd405ep_set_fpga_reset(0); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 91 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 92 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) { |
Dirk Eibach | 0e60aa8 | 2012-04-27 10:33:46 +0200 | [diff] [blame] | 93 | struct ihs_fpga *fpga = |
| 94 | (struct ihs_fpga *)CONFIG_SYS_FPGA_BASE(k); |
Dirk Eibach | 5cb4100 | 2011-04-06 13:53:46 +0200 | [diff] [blame] | 95 | #ifdef CONFIG_SYS_FPGA_NO_RFL_HI |
| 96 | u16 *reflection_target = &fpga->reflection_low; |
| 97 | #else |
| 98 | u16 *reflection_target = &fpga->reflection_high; |
| 99 | #endif |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 100 | /* |
| 101 | * wait for fpga out of reset |
| 102 | */ |
| 103 | ctr = 0; |
| 104 | while (1) { |
| 105 | out_le16(&fpga->reflection_low, |
| 106 | REFLECTION_TESTPATTERN); |
Dirk Eibach | 5cb4100 | 2011-04-06 13:53:46 +0200 | [diff] [blame] | 107 | |
| 108 | if (in_le16(reflection_target) == |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 109 | REFLECTION_TESTPATTERN_INV) |
| 110 | break; |
Dirk Eibach | 5cb4100 | 2011-04-06 13:53:46 +0200 | [diff] [blame] | 111 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 112 | udelay(100000); |
| 113 | if (ctr++ > 5) { |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 114 | gd->arch.fpga_state[k] |= |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 115 | FPGA_STATE_REFLECTION_FAILED; |
| 116 | break; |
| 117 | } |
| 118 | } |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return 0; |
| 122 | } |