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 | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 21 | #ifdef CONFIG_SYS_FPGA_NO_RFL_HI |
| 22 | #define REFLECTION_TESTREG reflection_low |
| 23 | #else |
| 24 | #define REFLECTION_TESTREG reflection_high |
| 25 | #endif |
| 26 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
| 29 | int get_fpga_state(unsigned dev) |
| 30 | { |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 31 | return gd->arch.fpga_state[dev]; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 34 | int board_early_init_f(void) |
| 35 | { |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 36 | unsigned k; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 37 | |
| 38 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 39 | gd->arch.fpga_state[k] = 0; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 40 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 41 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 42 | mtdcr(UIC0ER, 0x00000000); /* disable all ints */ |
| 43 | mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical */ |
| 44 | mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */ |
| 45 | mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */ |
| 46 | mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest prio */ |
| 47 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 48 | |
| 49 | /* |
| 50 | * EBC Configuration Register: set ready timeout to 512 ebc-clks |
| 51 | * -> ca. 15 us |
| 52 | */ |
| 53 | mtebc(EBC0_CFG, 0xa8400000); /* ebc always driven */ |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int board_early_init_r(void) |
| 58 | { |
| 59 | unsigned k; |
| 60 | unsigned ctr; |
| 61 | |
| 62 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 63 | gd->arch.fpga_state[k] = 0; |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 64 | |
| 65 | /* |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 66 | * reset FPGA |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 67 | */ |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 68 | gd405ep_init(); |
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_set_fpga_reset(1); |
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_setup_hw(); |
| 73 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 74 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) { |
| 75 | ctr = 0; |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 76 | while (!gd405ep_get_fpga_done(k)) { |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 77 | udelay(100000); |
| 78 | if (ctr++ > 5) { |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 79 | gd->arch.fpga_state[k] |= |
| 80 | FPGA_STATE_DONE_FAILED; |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 85 | |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 86 | udelay(10); |
Dirk Eibach | 6e9e6c3 | 2012-04-26 03:54:22 +0000 | [diff] [blame] | 87 | |
| 88 | gd405ep_set_fpga_reset(0); |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 89 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 90 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) { |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 91 | /* |
| 92 | * wait for fpga out of reset |
| 93 | */ |
| 94 | ctr = 0; |
| 95 | while (1) { |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 96 | u16 val; |
Dirk Eibach | 5cb4100 | 2011-04-06 13:53:46 +0200 | [diff] [blame] | 97 | |
Dirk Eibach | aba27ac | 2013-06-26 16:04:26 +0200 | [diff] [blame] | 98 | FPGA_SET_REG(k, reflection_low, REFLECTION_TESTPATTERN); |
| 99 | |
| 100 | FPGA_GET_REG(k, REFLECTION_TESTREG, &val); |
| 101 | if (val == REFLECTION_TESTPATTERN_INV) |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 102 | break; |
Dirk Eibach | 5cb4100 | 2011-04-06 13:53:46 +0200 | [diff] [blame] | 103 | |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 104 | udelay(100000); |
| 105 | if (ctr++ > 5) { |
Simon Glass | 923a662 | 2012-12-13 20:49:02 +0000 | [diff] [blame] | 106 | gd->arch.fpga_state[k] |= |
Dirk Eibach | 2da0fc0 | 2011-01-21 09:31:21 +0100 | [diff] [blame] | 107 | FPGA_STATE_REFLECTION_FAILED; |
| 108 | break; |
| 109 | } |
| 110 | } |
Dirk Eibach | a605ea7 | 2010-10-21 10:50:05 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | return 0; |
| 114 | } |