Andre Schwarz | 5e0de0e | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
| 4 | * Keith Outwater, keith_outwater@mvis.com. |
| 5 | * |
| 6 | * (C) Copyright 2008 |
| 7 | * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | #include <common.h> |
| 30 | #include <ACEX1K.h> |
| 31 | #include <command.h> |
| 32 | #include "fpga.h" |
| 33 | #include "mvbc_p.h" |
| 34 | |
| 35 | #ifdef FPGA_DEBUG |
| 36 | #define fpga_debug(fmt, args...) printf("%s: "fmt, __func__, ##args) |
| 37 | #else |
| 38 | #define fpga_debug(fmt, args...) |
| 39 | #endif |
| 40 | |
| 41 | Altera_CYC2_Passive_Serial_fns altera_fns = { |
| 42 | fpga_null_fn, |
| 43 | fpga_config_fn, |
| 44 | fpga_status_fn, |
| 45 | fpga_done_fn, |
| 46 | fpga_wr_fn, |
| 47 | fpga_null_fn, |
| 48 | fpga_null_fn, |
Andre Schwarz | 5e0de0e | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | Altera_desc cyclone2 = { |
| 52 | Altera_CYC2, |
| 53 | passive_serial, |
| 54 | Altera_EP2C8_SIZE, |
| 55 | (void *) &altera_fns, |
| 56 | NULL, |
Andre Schwarz | 5e0de0e | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | DECLARE_GLOBAL_DATA_PTR; |
| 60 | |
| 61 | int mvbc_p_init_fpga(void) |
| 62 | { |
Peter Tyser | 6385b28 | 2009-09-21 11:20:32 -0500 | [diff] [blame] | 63 | fpga_debug("Initialize FPGA interface\n"); |
| 64 | fpga_init(); |
Andre Schwarz | 5e0de0e | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 65 | fpga_add(fpga_altera, &cyclone2); |
| 66 | fpga_config_fn(0, 1, 0); |
| 67 | udelay(60); |
| 68 | |
| 69 | return 1; |
| 70 | } |
| 71 | |
| 72 | int fpga_null_fn(int cookie) |
| 73 | { |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int fpga_config_fn(int assert, int flush, int cookie) |
| 78 | { |
| 79 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 80 | u32 dvo = gpio->simple_dvo; |
| 81 | |
| 82 | fpga_debug("SET config : %s\n", assert ? "low" : "high"); |
| 83 | if (assert) |
| 84 | dvo |= FPGA_CONFIG; |
| 85 | else |
| 86 | dvo &= ~FPGA_CONFIG; |
| 87 | |
| 88 | if (flush) |
| 89 | gpio->simple_dvo = dvo; |
| 90 | |
| 91 | return assert; |
| 92 | } |
| 93 | |
| 94 | int fpga_done_fn(int cookie) |
| 95 | { |
| 96 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 97 | int result = 0; |
| 98 | |
| 99 | udelay(10); |
| 100 | fpga_debug("CONF_DONE check ... "); |
| 101 | if (gpio->simple_ival & FPGA_CONF_DONE) { |
| 102 | fpga_debug("high\n"); |
| 103 | result = 1; |
| 104 | } else |
| 105 | fpga_debug("low\n"); |
| 106 | |
| 107 | return result; |
| 108 | } |
| 109 | |
| 110 | int fpga_status_fn(int cookie) |
| 111 | { |
| 112 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 113 | int result = 0; |
| 114 | |
| 115 | fpga_debug("STATUS check ... "); |
| 116 | if (gpio->sint_ival & FPGA_STATUS) { |
| 117 | fpga_debug("high\n"); |
| 118 | result = 1; |
| 119 | } else |
| 120 | fpga_debug("low\n"); |
| 121 | |
| 122 | return result; |
| 123 | } |
| 124 | |
| 125 | int fpga_clk_fn(int assert_clk, int flush, int cookie) |
| 126 | { |
| 127 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 128 | u32 dvo = gpio->simple_dvo; |
| 129 | |
| 130 | fpga_debug("CLOCK %s\n", assert_clk ? "high" : "low"); |
| 131 | if (assert_clk) |
| 132 | dvo |= FPGA_CCLK; |
| 133 | else |
| 134 | dvo &= ~FPGA_CCLK; |
| 135 | |
| 136 | if (flush) |
| 137 | gpio->simple_dvo = dvo; |
| 138 | |
| 139 | return assert_clk; |
| 140 | } |
| 141 | |
| 142 | static inline int _write_fpga(u8 val) |
| 143 | { |
| 144 | int i; |
| 145 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 146 | u32 dvo = gpio->simple_dvo; |
| 147 | |
| 148 | for (i=0; i<8; i++) { |
| 149 | dvo &= ~FPGA_CCLK; |
| 150 | gpio->simple_dvo = dvo; |
| 151 | dvo &= ~FPGA_DIN; |
| 152 | if (val & 1) |
| 153 | dvo |= FPGA_DIN; |
| 154 | gpio->simple_dvo = dvo; |
| 155 | dvo |= FPGA_CCLK; |
| 156 | gpio->simple_dvo = dvo; |
| 157 | val >>= 1; |
| 158 | } |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
Wolfgang Denk | e6a857d | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 163 | int fpga_wr_fn(const void *buf, size_t len, int flush, int cookie) |
Andre Schwarz | 5e0de0e | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 164 | { |
| 165 | unsigned char *data = (unsigned char *) buf; |
| 166 | int i; |
| 167 | |
| 168 | fpga_debug("fpga_wr: buf %p / size %d\n", buf, len); |
| 169 | for (i = 0; i < len; i++) |
| 170 | _write_fpga(data[i]); |
| 171 | fpga_debug("\n"); |
| 172 | |
| 173 | return FPGA_SUCCESS; |
| 174 | } |