]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/keymile/km_arm/fpga_config.c
3 * Valentin Lontgchamp, Keymile AG, valentin.longchamp@keymile.com
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 #include <asm/errno.h>
28 /* GPIO Pin from kirkwood connected to PROGRAM_B pin of the xilinx FPGA */
29 #define KM_XLX_PROGRAM_B_PIN 39
31 #define BOCO_ADDR 0x10
36 static int check_boco2(void)
41 ret
= i2c_read(BOCO_ADDR
, ID_REG
, 1, &id
, 1);
43 printf("%s: error reading the BOCO id !!\n", __func__
);
47 return (id
== BOCO2_ID
);
50 static int boco_clear_bits(u8 reg
, u8 flags
)
55 /* give access to the EEPROM from FPGA */
56 ret
= i2c_read(BOCO_ADDR
, reg
, 1, ®val
, 1);
58 printf("%s: error reading the BOCO @%#x !!\n",
63 ret
= i2c_write(BOCO_ADDR
, reg
, 1, ®val
, 1);
65 printf("%s: error writing the BOCO @%#x !!\n",
73 static int boco_set_bits(u8 reg
, u8 flags
)
78 /* give access to the EEPROM from FPGA */
79 ret
= i2c_read(BOCO_ADDR
, reg
, 1, ®val
, 1);
81 printf("%s: error reading the BOCO @%#x !!\n",
86 ret
= i2c_write(BOCO_ADDR
, reg
, 1, ®val
, 1);
88 printf("%s: error writing the BOCO @%#x !!\n",
97 #define CFG_EEPROM 0x02
98 #define FPGA_PROG 0x04
99 #define FPGA_INIT_B 0x10
100 #define FPGA_DONE 0x20
102 static int fpga_done()
107 /* this is only supported with the boco2 design */
111 ret
= i2c_read(BOCO_ADDR
, SPI_REG
, 1, ®val
, 1);
113 printf("%s: error reading the BOCO @%#x !!\n",
118 return regval
& FPGA_DONE
? 1 : 0;
123 int trigger_fpga_config(void)
127 /* if the FPGA is already configured, we do not want to
131 printf("PCIe FPGA config: skipped\n");
137 /* we have a BOCO2, this has to be triggered here */
139 /* make sure the FPGA_can access the EEPROM */
140 ret
= boco_clear_bits(SPI_REG
, CFG_EEPROM
);
144 /* trigger the config start */
145 ret
= boco_clear_bits(SPI_REG
, FPGA_PROG
| FPGA_INIT_B
);
149 /* small delay for the pulse */
152 /* up signal for pulse end */
153 ret
= boco_set_bits(SPI_REG
, FPGA_PROG
);
157 /* finally, raise INIT_B to remove the config delay */
158 ret
= boco_set_bits(SPI_REG
, FPGA_INIT_B
);
163 /* we do it the old way, with the gpio pin */
164 kw_gpio_set_valid(KM_XLX_PROGRAM_B_PIN
, 1);
165 kw_gpio_direction_output(KM_XLX_PROGRAM_B_PIN
, 0);
166 /* small delay for the pulse */
168 kw_gpio_direction_input(KM_XLX_PROGRAM_B_PIN
);
174 int wait_for_fpga_config(void)
183 if (!check_boco2()) {
184 /* we do not have BOCO2, this is not really used */
188 printf("PCIe FPGA config:");
190 ret
= i2c_read(BOCO_ADDR
, SPI_REG
, 1, &spictrl
, 1);
192 printf("%s: error reading the BOCO spictrl !!\n",
196 if (timeout
-- == 0) {
197 printf(" FPGA_DONE timeout\n");
201 } while (!(spictrl
& FPGA_DONE
));
209 #define BRIDGE_RST 0x4
215 if (!check_boco2()) {
216 /* we do not have BOCO2, this is not really used */
220 ret
= boco_clear_bits(PRST1
, BRIDGE_RST
);
224 /* small delay for the pulse */
227 ret
= boco_set_bits(PRST1
, BRIDGE_RST
);
234 /* the FPGA was configured, we configure the BOCO2 so that the EEPROM
235 * is available from the Bobcat SPI bus */
236 int toggle_eeprom_spi_bus(void)
240 if (!check_boco2()) {
241 /* we do not have BOCO2, this is not really used */
245 ret
= boco_set_bits(SPI_REG
, CFG_EEPROM
);