Andre Schwarz | 2a29329 | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <ACEX1K.h> |
| 14 | #include <command.h> |
| 15 | #include "fpga.h" |
| 16 | #include "mvbc_p.h" |
| 17 | |
| 18 | #ifdef FPGA_DEBUG |
| 19 | #define fpga_debug(fmt, args...) printf("%s: "fmt, __func__, ##args) |
| 20 | #else |
| 21 | #define fpga_debug(fmt, args...) |
| 22 | #endif |
| 23 | |
| 24 | Altera_CYC2_Passive_Serial_fns altera_fns = { |
| 25 | fpga_null_fn, |
| 26 | fpga_config_fn, |
| 27 | fpga_status_fn, |
| 28 | fpga_done_fn, |
| 29 | fpga_wr_fn, |
| 30 | fpga_null_fn, |
| 31 | fpga_null_fn, |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | Altera_desc cyclone2 = { |
| 35 | Altera_CYC2, |
| 36 | passive_serial, |
| 37 | Altera_EP2C8_SIZE, |
| 38 | (void *) &altera_fns, |
| 39 | NULL, |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
| 44 | int mvbc_p_init_fpga(void) |
| 45 | { |
Peter Tyser | cf8582c | 2009-09-21 11:20:32 -0500 | [diff] [blame] | 46 | fpga_debug("Initialize FPGA interface\n"); |
| 47 | fpga_init(); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 48 | fpga_add(fpga_altera, &cyclone2); |
| 49 | fpga_config_fn(0, 1, 0); |
| 50 | udelay(60); |
| 51 | |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | int fpga_null_fn(int cookie) |
| 56 | { |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | int fpga_config_fn(int assert, int flush, int cookie) |
| 61 | { |
| 62 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 63 | u32 dvo = gpio->simple_dvo; |
| 64 | |
| 65 | fpga_debug("SET config : %s\n", assert ? "low" : "high"); |
| 66 | if (assert) |
| 67 | dvo |= FPGA_CONFIG; |
| 68 | else |
| 69 | dvo &= ~FPGA_CONFIG; |
| 70 | |
| 71 | if (flush) |
| 72 | gpio->simple_dvo = dvo; |
| 73 | |
| 74 | return assert; |
| 75 | } |
| 76 | |
| 77 | int fpga_done_fn(int cookie) |
| 78 | { |
| 79 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 80 | int result = 0; |
| 81 | |
| 82 | udelay(10); |
| 83 | fpga_debug("CONF_DONE check ... "); |
| 84 | if (gpio->simple_ival & FPGA_CONF_DONE) { |
| 85 | fpga_debug("high\n"); |
| 86 | result = 1; |
| 87 | } else |
| 88 | fpga_debug("low\n"); |
| 89 | |
| 90 | return result; |
| 91 | } |
| 92 | |
| 93 | int fpga_status_fn(int cookie) |
| 94 | { |
| 95 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 96 | int result = 0; |
| 97 | |
| 98 | fpga_debug("STATUS check ... "); |
| 99 | if (gpio->sint_ival & FPGA_STATUS) { |
| 100 | fpga_debug("high\n"); |
| 101 | result = 1; |
| 102 | } else |
| 103 | fpga_debug("low\n"); |
| 104 | |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | int fpga_clk_fn(int assert_clk, int flush, int cookie) |
| 109 | { |
| 110 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 111 | u32 dvo = gpio->simple_dvo; |
| 112 | |
| 113 | fpga_debug("CLOCK %s\n", assert_clk ? "high" : "low"); |
| 114 | if (assert_clk) |
| 115 | dvo |= FPGA_CCLK; |
| 116 | else |
| 117 | dvo &= ~FPGA_CCLK; |
| 118 | |
| 119 | if (flush) |
| 120 | gpio->simple_dvo = dvo; |
| 121 | |
| 122 | return assert_clk; |
| 123 | } |
| 124 | |
| 125 | static inline int _write_fpga(u8 val) |
| 126 | { |
| 127 | int i; |
| 128 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 129 | u32 dvo = gpio->simple_dvo; |
| 130 | |
| 131 | for (i=0; i<8; i++) { |
| 132 | dvo &= ~FPGA_CCLK; |
| 133 | gpio->simple_dvo = dvo; |
| 134 | dvo &= ~FPGA_DIN; |
| 135 | if (val & 1) |
| 136 | dvo |= FPGA_DIN; |
| 137 | gpio->simple_dvo = dvo; |
| 138 | dvo |= FPGA_CCLK; |
| 139 | gpio->simple_dvo = dvo; |
| 140 | val >>= 1; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Wolfgang Denk | 74f9b38 | 2011-07-30 13:33:49 +0000 | [diff] [blame] | 146 | int fpga_wr_fn(const void *buf, size_t len, int flush, int cookie) |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 147 | { |
| 148 | unsigned char *data = (unsigned char *) buf; |
| 149 | int i; |
| 150 | |
| 151 | fpga_debug("fpga_wr: buf %p / size %d\n", buf, len); |
| 152 | for (i = 0; i < len; i++) |
| 153 | _write_fpga(data[i]); |
| 154 | fpga_debug("\n"); |
| 155 | |
| 156 | return FPGA_SUCCESS; |
| 157 | } |