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_DONE 0x20
101 int trigger_fpga_config(void)
106 /* we have a BOCO2, this has to be triggered here */
108 /* make sure the FPGA_can access the EEPROM */
109 ret = boco_clear_bits(SPI_REG, CFG_EEPROM);
113 /* trigger the config start */
114 ret = boco_clear_bits(SPI_REG, FPGA_PROG);
118 /* small delay for the pulse */
121 /* up signal for pulse end */
122 ret = boco_set_bits(SPI_REG, FPGA_PROG);
127 /* we do it the old way, with the gpio pin */
128 kw_gpio_set_valid(KM_XLX_PROGRAM_B_PIN, 1);
129 kw_gpio_direction_output(KM_XLX_PROGRAM_B_PIN, 0);
130 /* small delay for the pulse */
132 kw_gpio_direction_input(KM_XLX_PROGRAM_B_PIN);
138 int wait_for_fpga_config(void)
144 if (!check_boco2()) {
145 /* we do not have BOCO2, this is not really used */
149 printf("PCIe FPGA config:");
151 ret = i2c_read(BOCO_ADDR, SPI_REG, 1, &spictrl, 1);
153 printf("%s: error reading the BOCO spictrl !!\n",
157 if (timeout-- == 0) {
158 printf(" FPGA_DONE timeout\n");
162 } while (!(spictrl & FPGA_DONE));
170 #define BRIDGE_RST 0x4
176 if (!check_boco2()) {
177 /* we do not have BOCO2, this is not really used */
181 ret = boco_clear_bits(PRST1, BRIDGE_RST);
185 /* small delay for the pulse */
188 ret = boco_set_bits(PRST1, BRIDGE_RST);
195 /* the FPGA was configured, we configure the BOCO2 so that the EEPROM
196 * is available from the Bobcat SPI bus */
197 int toggle_eeprom_spi_bus(void)
201 if (!check_boco2()) {
202 /* we do not have BOCO2, this is not really used */
206 ret = boco_set_bits(SPI_REG, CFG_EEPROM);