Merge branch 'next'
[u-boot/qq2440-u-boot.git] / board / matrix_vision / mvbc_p / fpga.c
blobb88f43f3e398249684f5622047f25ebcecdeacff
1 /*
2 * (C) Copyright 2002
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 * Keith Outwater, keith_outwater@mvis.com.
6 * (C) Copyright 2008
7 * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
9 * SPDX-License-Identifier: GPL-2.0+
12 #include <common.h>
13 #include <ACEX1K.h>
14 #include <command.h>
15 #include "fpga.h"
16 #include "mvbc_p.h"
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
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,
34 Altera_desc cyclone2 = {
35 Altera_CYC2,
36 passive_serial,
37 Altera_EP2C8_SIZE,
38 (void *) &altera_fns,
39 NULL,
42 DECLARE_GLOBAL_DATA_PTR;
44 int mvbc_p_init_fpga(void)
46 fpga_debug("Initialize FPGA interface\n");
47 fpga_init();
48 fpga_add(fpga_altera, &cyclone2);
49 fpga_config_fn(0, 1, 0);
50 udelay(60);
52 return 1;
55 int fpga_null_fn(int cookie)
57 return 0;
60 int fpga_config_fn(int assert, int flush, int cookie)
62 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
63 u32 dvo = gpio->simple_dvo;
65 fpga_debug("SET config : %s\n", assert ? "low" : "high");
66 if (assert)
67 dvo |= FPGA_CONFIG;
68 else
69 dvo &= ~FPGA_CONFIG;
71 if (flush)
72 gpio->simple_dvo = dvo;
74 return assert;
77 int fpga_done_fn(int cookie)
79 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
80 int result = 0;
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");
90 return result;
93 int fpga_status_fn(int cookie)
95 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
96 int result = 0;
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");
105 return result;
108 int fpga_clk_fn(int assert_clk, int flush, int cookie)
110 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
111 u32 dvo = gpio->simple_dvo;
113 fpga_debug("CLOCK %s\n", assert_clk ? "high" : "low");
114 if (assert_clk)
115 dvo |= FPGA_CCLK;
116 else
117 dvo &= ~FPGA_CCLK;
119 if (flush)
120 gpio->simple_dvo = dvo;
122 return assert_clk;
125 static inline int _write_fpga(u8 val)
127 int i;
128 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
129 u32 dvo = gpio->simple_dvo;
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;
143 return 0;
146 int fpga_wr_fn(const void *buf, size_t len, int flush, int cookie)
148 unsigned char *data = (unsigned char *) buf;
149 int i;
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");
156 return FPGA_SUCCESS;