Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 |
Mario Six | b489358 | 2018-03-06 08:04:58 +0100 | [diff] [blame] | 4 | * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
| 9 | #include <asm/processor.h> |
| 10 | #include <asm/io.h> |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 11 | #include <asm/global_data.h> |
| 12 | |
| 13 | #include "mpc8308.h" |
| 14 | #include <gdsys_fpga.h> |
| 15 | |
| 16 | #define REFLECTION_TESTPATTERN 0xdede |
| 17 | #define REFLECTION_TESTPATTERN_INV (~REFLECTION_TESTPATTERN & 0xffff) |
| 18 | |
| 19 | #ifdef CONFIG_SYS_FPGA_NO_RFL_HI |
| 20 | #define REFLECTION_TESTREG reflection_low |
| 21 | #else |
| 22 | #define REFLECTION_TESTREG reflection_high |
| 23 | #endif |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
Mario Six | 7851021 | 2019-03-29 10:18:10 +0100 | [diff] [blame] | 27 | #ifdef CONFIG_GDSYS_LEGACY_DRIVERS |
Mario Six | ae0feaa | 2019-03-29 10:18:07 +0100 | [diff] [blame] | 28 | /* as gpio output status cannot be read back, we have to buffer it locally */ |
| 29 | u32 gpio0_out; |
| 30 | |
| 31 | void setbits_gpio0_out(u32 mask) |
| 32 | { |
| 33 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
| 34 | |
| 35 | gpio0_out |= mask; |
| 36 | out_be32(&immr->gpio[0].dat, gpio0_out); |
| 37 | } |
| 38 | |
| 39 | void clrbits_gpio0_out(u32 mask) |
| 40 | { |
| 41 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
| 42 | |
| 43 | gpio0_out &= ~mask; |
| 44 | out_be32(&immr->gpio[0].dat, gpio0_out); |
| 45 | } |
| 46 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 47 | int get_fpga_state(uint dev) |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 48 | { |
| 49 | return gd->arch.fpga_state[dev]; |
| 50 | } |
| 51 | |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 52 | int board_early_init_f(void) |
| 53 | { |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 54 | uint k; |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 55 | |
| 56 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
| 57 | gd->arch.fpga_state[k] = 0; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | int board_early_init_r(void) |
| 63 | { |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 64 | uint k; |
| 65 | uint ctr; |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 66 | |
| 67 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) |
| 68 | gd->arch.fpga_state[k] = 0; |
| 69 | |
| 70 | /* |
| 71 | * reset FPGA |
| 72 | */ |
| 73 | mpc8308_init(); |
| 74 | |
| 75 | mpc8308_set_fpga_reset(1); |
| 76 | |
| 77 | mpc8308_setup_hw(); |
| 78 | |
| 79 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) { |
| 80 | ctr = 0; |
| 81 | while (!mpc8308_get_fpga_done(k)) { |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 82 | mdelay(100); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 83 | if (ctr++ > 5) { |
| 84 | gd->arch.fpga_state[k] |= |
| 85 | FPGA_STATE_DONE_FAILED; |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | udelay(10); |
| 92 | |
| 93 | mpc8308_set_fpga_reset(0); |
| 94 | |
| 95 | for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) { |
| 96 | /* |
| 97 | * wait for fpga out of reset |
| 98 | */ |
| 99 | ctr = 0; |
| 100 | while (1) { |
| 101 | u16 val; |
| 102 | |
| 103 | FPGA_SET_REG(k, reflection_low, REFLECTION_TESTPATTERN); |
| 104 | |
| 105 | FPGA_GET_REG(k, REFLECTION_TESTREG, &val); |
| 106 | if (val == REFLECTION_TESTPATTERN_INV) |
| 107 | break; |
| 108 | |
Mario Six | 3809c47 | 2019-03-29 10:18:06 +0100 | [diff] [blame] | 109 | mdelay(100); |
Dirk Eibach | f74a027 | 2014-11-13 19:21:18 +0100 | [diff] [blame] | 110 | if (ctr++ > 5) { |
| 111 | gd->arch.fpga_state[k] |= |
| 112 | FPGA_STATE_REFLECTION_FAILED; |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return 0; |
| 119 | } |
Mario Six | 7851021 | 2019-03-29 10:18:10 +0100 | [diff] [blame] | 120 | #endif |