3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 * Keith Outwater, keith_outwater@mvis.com.
7 * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
8 * Michael Jones, Matrix Vision GmbH, michael.jones@matrix-vision.de
10 * SPDX-License-Identifier: GPL-2.0+
17 #include <linux/byteorder/generic.h>
21 #define fpga_debug(fmt, args...) printf("%s: "fmt, __func__, ##args)
23 #define fpga_debug(fmt, args...)
26 Altera_CYC2_Passive_Serial_fns altera_fns = {
27 fpga_null_fn, /* Altera_pre_fn */
36 Altera_desc cyclone2 = {
38 fast_passive_parallel,
47 #define GPIO_nSTATUS 157
48 #define GPIO_CONF_DONE 158
49 #define GPIO_nCONFIG 159
59 DECLARE_GLOBAL_DATA_PTR;
61 /* return FPGA_SUCCESS on success, else FPGA_FAIL
63 int mvblx_init_fpga(void)
65 fpga_debug("Initializing FPGA interface\n");
67 fpga_add(fpga_altera, &cyclone2);
69 if (gpio_request(GPIO_DCLK, "dclk") ||
70 gpio_request(GPIO_nSTATUS, "nStatus") ||
71 #ifndef CONFIG_SYS_FPGA_DONT_USE_CONF_DONE
72 gpio_request(GPIO_CONF_DONE, "conf_done") ||
74 gpio_request(GPIO_nCONFIG, "nConfig") ||
75 gpio_request(GPIO_DATA0, "data0") ||
76 gpio_request(GPIO_DATA1, "data1") ||
77 gpio_request(GPIO_DATA2, "data2") ||
78 gpio_request(GPIO_DATA3, "data3") ||
79 gpio_request(GPIO_DATA4, "data4") ||
80 gpio_request(GPIO_DATA5, "data5") ||
81 gpio_request(GPIO_DATA6, "data6") ||
82 gpio_request(GPIO_DATA7, "data7")) {
83 printf("%s: error requesting GPIOs.", __func__);
88 gpio_direction_output(GPIO_DCLK, 0);
89 gpio_direction_output(GPIO_nCONFIG, 0);
90 gpio_direction_output(GPIO_DATA0, 0);
91 gpio_direction_output(GPIO_DATA1, 0);
92 gpio_direction_output(GPIO_DATA2, 0);
93 gpio_direction_output(GPIO_DATA3, 0);
94 gpio_direction_output(GPIO_DATA4, 0);
95 gpio_direction_output(GPIO_DATA5, 0);
96 gpio_direction_output(GPIO_DATA6, 0);
97 gpio_direction_output(GPIO_DATA7, 0);
99 /* NB omap_free_gpio() resets to an input, so we can't
100 * free ie. nCONFIG, or else the FPGA would reset
101 * Q: presumably gpio_free() has the same effect?
105 gpio_direction_input(GPIO_nSTATUS);
106 #ifndef CONFIG_SYS_FPGA_DONT_USE_CONF_DONE
107 gpio_direction_input(GPIO_CONF_DONE);
110 fpga_config_fn(0, 1, 0);
116 int fpga_null_fn(int cookie)
121 int fpga_config_fn(int assert, int flush, int cookie)
123 fpga_debug("SET config : %s=%d\n", assert ? "low" : "high", assert);
125 gpio_set_value(GPIO_nCONFIG, !assert);
127 gpio_set_value(GPIO_nCONFIG, assert);
133 int fpga_done_fn(int cookie)
137 /* since revA of BLX, we will not get this signal. */
139 #ifdef CONFIG_SYS_FPGA_DONT_USE_CONF_DONE
140 fpga_debug("not waiting for CONF_DONE.");
143 fpga_debug("CONF_DONE check ... ");
144 if (gpio_get_value(GPIO_CONF_DONE)) {
145 fpga_debug("high\n");
149 gpio_free(GPIO_CONF_DONE);
155 int fpga_status_fn(int cookie)
158 fpga_debug("STATUS check ... ");
160 result = gpio_get_value(GPIO_nSTATUS);
163 fpga_debug("error\n");
165 fpga_debug("high\n");
172 static inline int _write_fpga(u8 byte)
174 gpio_set_value(GPIO_DATA0, byte & 0x01);
175 gpio_set_value(GPIO_DATA1, (byte >> 1) & 0x01);
176 gpio_set_value(GPIO_DATA2, (byte >> 2) & 0x01);
177 gpio_set_value(GPIO_DATA3, (byte >> 3) & 0x01);
178 gpio_set_value(GPIO_DATA4, (byte >> 4) & 0x01);
179 gpio_set_value(GPIO_DATA5, (byte >> 5) & 0x01);
180 gpio_set_value(GPIO_DATA6, (byte >> 6) & 0x01);
181 gpio_set_value(GPIO_DATA7, (byte >> 7) & 0x01);
184 gpio_set_value(GPIO_DCLK, 1);
186 gpio_set_value(GPIO_DCLK, 0);
192 int fpga_wr_fn(const void *buf, size_t len, int flush, int cookie)
194 unsigned char *data = (unsigned char *) buf;
196 int headerlen = len - cyclone2.size;
200 else if (headerlen == sizeof(uint32_t)) {
201 const unsigned int fpgavers_len = 11; /* '0x' + 8 hex digits + \0 */
202 char fpgavers_str[fpgavers_len];
203 snprintf(fpgavers_str, fpgavers_len, "0x%08x",
204 be32_to_cpup((uint32_t*)data));
205 setenv("fpgavers", fpgavers_str);
208 fpga_debug("fpga_wr: buf %p / size %d\n", buf, len);
209 for (i = headerlen; i < len; i++)
210 _write_fpga(data[i]);
211 fpga_debug("-%s\n", __func__);