2 * Copyright (C) 2012 Altera Corporation <www.altera.com>
5 * This file contains only support functions used also by the SoCFPGA
6 * platform code, the real meat is located in drivers/fpga/socfpga.c .
8 * SPDX-License-Identifier: BSD-3-Clause
13 #include <linux/errno.h>
14 #include <asm/arch/fpga_manager.h>
15 #include <asm/arch/reset_manager.h>
16 #include <asm/arch/system_manager.h>
19 #define FPGA_TIMEOUT_CNT 0x1000000
21 static struct socfpga_fpga_manager *fpgamgr_regs =
22 (struct socfpga_fpga_manager *)SOCFPGA_FPGAMGRREGS_ADDRESS;
24 /* Check whether FPGA Init_Done signal is high */
25 static int is_fpgamgr_initdone_high(void)
29 val = readl(&fpgamgr_regs->gpio_ext_porta);
30 return val & FPGAMGRREGS_MON_GPIO_EXT_PORTA_ID_MASK;
33 /* Get the FPGA mode */
34 int fpgamgr_get_mode(void)
38 val = readl(&fpgamgr_regs->stat);
39 return val & FPGAMGRREGS_STAT_MODE_MASK;
42 /* Check whether FPGA is ready to be accessed */
43 int fpgamgr_test_fpga_ready(void)
45 /* Check for init done signal */
46 if (!is_fpgamgr_initdone_high())
49 /* Check again to avoid false glitches */
50 if (!is_fpgamgr_initdone_high())
53 if (fpgamgr_get_mode() != FPGAMGRREGS_MODE_USERMODE)
59 /* Poll until FPGA is ready to be accessed or timeout occurred */
60 int fpgamgr_poll_fpga_ready(void)
64 /* If FPGA is blank, wait till WD invoke warm reset */
65 for (i = 0; i < FPGA_TIMEOUT_CNT; i++) {
66 /* check for init done signal */
67 if (!is_fpgamgr_initdone_high())
69 /* check again to avoid false glitches */
70 if (!is_fpgamgr_initdone_high())