/* Register bit defines */ /* SOCFPGA_FPGMGR_STAT register mode field values */ #define SOCFPGA_FPGMGR_STAT_POWER_UP 0x0 /*ramping*/ #define SOCFPGA_FPGMGR_STAT_RESET 0x1 #define SOCFPGA_FPGMGR_STAT_CFG 0x2 #define SOCFPGA_FPGMGR_STAT_INIT 0x3 #define SOCFPGA_FPGMGR_STAT_USER_MODE 0x4 #define SOCFPGA_FPGMGR_STAT_UNKNOWN 0x5 #define SOCFPGA_FPGMGR_STAT_STATE_MASK 0x7 /* This is a flag value that doesn't really happen in this register field */ #define SOCFPGA_FPGMGR_STAT_POWER_OFF 0x0
/* * Set the DCLKCNT, wait for DCLKSTAT to report the count completed, and clear * the complete status.
*/ staticint socfpga_fpga_dclk_set_and_wait_clear(struct socfpga_fpga_priv *priv,
u32 count)
{ int timeout = 2;
u32 done;
/* Clear any existing DONE status. */ if (socfpga_fpga_readl(priv, SOCFPGA_FPGMGR_DCLKSTAT_OFST))
socfpga_fpga_clear_done_status(priv);
/* Issue the DCLK count. */
socfpga_fpga_writel(priv, SOCFPGA_FPGMGR_DCLKCNT_OFST, count);
/* Poll DCLKSTAT to see if it completed in the timeout period. */ do {
done = socfpga_fpga_readl(priv, SOCFPGA_FPGMGR_DCLKSTAT_OFST); if (done == SOCFPGA_FPGMGR_DCLKSTAT_DCNTDONE_E_DONE) {
socfpga_fpga_clear_done_status(priv); return 0;
}
udelay(1);
} while (timeout--);
/* * HW doesn't support an interrupt for changes in state, so poll to see * if it matches the requested state within the timeout period.
*/ do { if ((socfpga_fpga_state_get(priv) & state) != 0) return 0;
msleep(20);
} while (timeout--);
return -ETIMEDOUT;
}
staticvoid socfpga_fpga_enable_irqs(struct socfpga_fpga_priv *priv, u32 irqs)
{ /* set irqs to level sensitive */
socfpga_fpga_writel(priv, SOCFPGA_FPGMGR_GPIO_INTTYPE_LEVEL_OFST, 0);
/* set interrupt polarity */
socfpga_fpga_writel(priv, SOCFPGA_FPGMGR_GPIO_INT_POL_OFST, irqs);
/* * Step 1: * - Set CTRL.CFGWDTH, CTRL.CDRATIO to match cfg mode * - Set CTRL.NCE to 0
*/
ret = socfpga_fpga_cfg_mode_set(priv); if (ret) return ret;
/* Step 2: Set CTRL.EN to 1 */
socfpga_fpga_set_bitsl(priv, SOCFPGA_FPGMGR_CTL_OFST,
SOCFPGA_FPGMGR_CTL_EN);
/* Step 3: Set CTRL.NCONFIGPULL to 1 to put FPGA in reset */
ctrl_reg = socfpga_fpga_readl(priv, SOCFPGA_FPGMGR_CTL_OFST);
ctrl_reg |= SOCFPGA_FPGMGR_CTL_NCFGPULL;
socfpga_fpga_writel(priv, SOCFPGA_FPGMGR_CTL_OFST, ctrl_reg);
/* Step 4: Wait for STATUS.MODE to report FPGA is in reset phase */
status = socfpga_fpga_wait_for_state(priv, SOCFPGA_FPGMGR_STAT_RESET);
/* Step 5: Set CONTROL.NCONFIGPULL to 0 to release FPGA from reset */
ctrl_reg &= ~SOCFPGA_FPGMGR_CTL_NCFGPULL;
socfpga_fpga_writel(priv, SOCFPGA_FPGMGR_CTL_OFST, ctrl_reg);
/* Timeout waiting for reset */ if (status) return -ETIMEDOUT;
return 0;
}
/* * Prepare the FPGA to receive the configuration data.
*/ staticint socfpga_fpga_ops_configure_init(struct fpga_manager *mgr, struct fpga_image_info *info, constchar *buf, size_t count)
{ struct socfpga_fpga_priv *priv = mgr->priv; int ret;
if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) {
dev_err(&mgr->dev, "Partial reconfiguration not supported.\n"); return -EINVAL;
} /* Steps 1 - 5: Reset the FPGA */
ret = socfpga_fpga_reset(mgr); if (ret) return ret;
/* Step 6: Wait for FPGA to enter configuration phase */ if (socfpga_fpga_wait_for_state(priv, SOCFPGA_FPGMGR_STAT_CFG)) return -ETIMEDOUT;
/* Step 8: Set CTRL.AXICFGEN to 1 to enable transfer of config data */
socfpga_fpga_set_bitsl(priv, SOCFPGA_FPGMGR_CTL_OFST,
SOCFPGA_FPGMGR_CTL_AXICFGEN);
return 0;
}
/* * Step 9: write data to the FPGA data register
*/ staticint socfpga_fpga_ops_configure_write(struct fpga_manager *mgr, constchar *buf, size_t count)
{ struct socfpga_fpga_priv *priv = mgr->priv;
u32 *buffer_32 = (u32 *)buf;
size_t i = 0;
if (count <= 0) return -EINVAL;
/* Write out the complete 32-bit chunks. */ while (count >= sizeof(u32)) {
socfpga_fpga_data_writel(priv, buffer_32[i++]);
count -= sizeof(u32);
}
/* Write out remaining non 32-bit chunks. */ switch (count) { case 3:
socfpga_fpga_data_writel(priv, buffer_32[i++] & 0x00ffffff); break; case 2:
socfpga_fpga_data_writel(priv, buffer_32[i++] & 0x0000ffff); break; case 1:
socfpga_fpga_data_writel(priv, buffer_32[i++] & 0x000000ff); break; case 0: break; default: /* This will never happen. */ return -EFAULT;
}
/* * Step 10: * - Observe CONF_DONE and nSTATUS (active low) * - if CONF_DONE = 1 and nSTATUS = 1, configuration was successful * - if CONF_DONE = 0 and nSTATUS = 0, configuration failed
*/
status = socfpga_fpga_wait_for_config_done(priv); if (status) return status;
/* Step 11: Clear CTRL.AXICFGEN to disable transfer of config data */
socfpga_fpga_clr_bitsl(priv, SOCFPGA_FPGMGR_CTL_OFST,
SOCFPGA_FPGMGR_CTL_AXICFGEN);
/* * Step 12: * - Write 4 to DCLKCNT * - Wait for STATUS.DCNTDONE = 1 * - Clear W1C bit in STATUS.DCNTDONE
*/ if (socfpga_fpga_dclk_set_and_wait_clear(priv, 4)) return -ETIMEDOUT;
/* Step 13: Wait for STATUS.MODE to report USER MODE */ if (socfpga_fpga_wait_for_state(priv, SOCFPGA_FPGMGR_STAT_USER_MODE)) return -ETIMEDOUT;
/* Step 14: Set CTRL.EN to 0 */
socfpga_fpga_clr_bitsl(priv, SOCFPGA_FPGMGR_CTL_OFST,
SOCFPGA_FPGMGR_CTL_EN);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.