Lines Matching +full:fpga +full:- +full:mgr
1 // SPDX-License-Identifier: GPL-2.0
3 * FPGA Manager Driver for Altera SOCFPGA
5 * Copyright (C) 2013-2015 Altera Corporation
9 #include <linux/fpga/fpga-mgr.h>
96 /* In power-up order. Reverse for power-down. */
98 "FPGA-1.5V",
99 "FPGA-1.1V",
100 "FPGA-2.5V",
136 return readl(priv->fpga_base_addr + reg_offset); in socfpga_fpga_readl()
142 writel(value, priv->fpga_base_addr + reg_offset); in socfpga_fpga_writel()
148 return __raw_readl(priv->fpga_base_addr + reg_offset); in socfpga_fpga_raw_readl()
154 __raw_writel(value, priv->fpga_base_addr + reg_offset); in socfpga_fpga_raw_writel()
159 writel(value, priv->fpga_data_addr); in socfpga_fpga_data_writel()
230 } while (timeout--); in socfpga_fpga_dclk_set_and_wait_clear()
232 return -ETIMEDOUT; in socfpga_fpga_dclk_set_and_wait_clear()
248 } while (timeout--); in socfpga_fpga_wait_for_state()
250 return -ETIMEDOUT; in socfpga_fpga_wait_for_state()
296 complete(&priv->status_complete); in socfpga_fpga_isr()
308 init_completion(&priv->status_complete); in socfpga_fpga_wait_for_config_done()
312 &priv->status_complete, in socfpga_fpga_wait_for_config_done()
315 ret = -ETIMEDOUT; in socfpga_fpga_wait_for_config_done()
331 return -EINVAL; in socfpga_fpga_cfg_mode_get()
359 static int socfpga_fpga_reset(struct fpga_manager *mgr) in socfpga_fpga_reset() argument
361 struct socfpga_fpga_priv *priv = mgr->priv; in socfpga_fpga_reset()
367 * - Set CTRL.CFGWDTH, CTRL.CDRATIO to match cfg mode in socfpga_fpga_reset()
368 * - Set CTRL.NCE to 0 in socfpga_fpga_reset()
378 /* Step 3: Set CTRL.NCONFIGPULL to 1 to put FPGA in reset */ in socfpga_fpga_reset()
383 /* Step 4: Wait for STATUS.MODE to report FPGA is in reset phase */ in socfpga_fpga_reset()
386 /* Step 5: Set CONTROL.NCONFIGPULL to 0 to release FPGA from reset */ in socfpga_fpga_reset()
392 return -ETIMEDOUT; in socfpga_fpga_reset()
398 * Prepare the FPGA to receive the configuration data.
400 static int socfpga_fpga_ops_configure_init(struct fpga_manager *mgr, in socfpga_fpga_ops_configure_init() argument
404 struct socfpga_fpga_priv *priv = mgr->priv; in socfpga_fpga_ops_configure_init()
407 if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) { in socfpga_fpga_ops_configure_init()
408 dev_err(&mgr->dev, "Partial reconfiguration not supported.\n"); in socfpga_fpga_ops_configure_init()
409 return -EINVAL; in socfpga_fpga_ops_configure_init()
411 /* Steps 1 - 5: Reset the FPGA */ in socfpga_fpga_ops_configure_init()
412 ret = socfpga_fpga_reset(mgr); in socfpga_fpga_ops_configure_init()
416 /* Step 6: Wait for FPGA to enter configuration phase */ in socfpga_fpga_ops_configure_init()
418 return -ETIMEDOUT; in socfpga_fpga_ops_configure_init()
432 * Step 9: write data to the FPGA data register
434 static int socfpga_fpga_ops_configure_write(struct fpga_manager *mgr, in socfpga_fpga_ops_configure_write() argument
437 struct socfpga_fpga_priv *priv = mgr->priv; in socfpga_fpga_ops_configure_write()
442 return -EINVAL; in socfpga_fpga_ops_configure_write()
444 /* Write out the complete 32-bit chunks. */ in socfpga_fpga_ops_configure_write()
447 count -= sizeof(u32); in socfpga_fpga_ops_configure_write()
450 /* Write out remaining non 32-bit chunks. */ in socfpga_fpga_ops_configure_write()
465 return -EFAULT; in socfpga_fpga_ops_configure_write()
471 static int socfpga_fpga_ops_configure_complete(struct fpga_manager *mgr, in socfpga_fpga_ops_configure_complete() argument
474 struct socfpga_fpga_priv *priv = mgr->priv; in socfpga_fpga_ops_configure_complete()
479 * - Observe CONF_DONE and nSTATUS (active low) in socfpga_fpga_ops_configure_complete()
480 * - if CONF_DONE = 1 and nSTATUS = 1, configuration was successful in socfpga_fpga_ops_configure_complete()
481 * - if CONF_DONE = 0 and nSTATUS = 0, configuration failed in socfpga_fpga_ops_configure_complete()
493 * - Write 4 to DCLKCNT in socfpga_fpga_ops_configure_complete()
494 * - Wait for STATUS.DCNTDONE = 1 in socfpga_fpga_ops_configure_complete()
495 * - Clear W1C bit in STATUS.DCNTDONE in socfpga_fpga_ops_configure_complete()
498 return -ETIMEDOUT; in socfpga_fpga_ops_configure_complete()
502 return -ETIMEDOUT; in socfpga_fpga_ops_configure_complete()
511 /* Translate state register values to FPGA framework state */
521 static enum fpga_mgr_states socfpga_fpga_ops_state(struct fpga_manager *mgr) in socfpga_fpga_ops_state() argument
523 struct socfpga_fpga_priv *priv = mgr->priv; in socfpga_fpga_ops_state()
546 struct device *dev = &pdev->dev; in socfpga_fpga_probe()
548 struct fpga_manager *mgr; in socfpga_fpga_probe() local
553 return -ENOMEM; in socfpga_fpga_probe()
555 priv->fpga_base_addr = devm_platform_ioremap_resource(pdev, 0); in socfpga_fpga_probe()
556 if (IS_ERR(priv->fpga_base_addr)) in socfpga_fpga_probe()
557 return PTR_ERR(priv->fpga_base_addr); in socfpga_fpga_probe()
559 priv->fpga_data_addr = devm_platform_ioremap_resource(pdev, 1); in socfpga_fpga_probe()
560 if (IS_ERR(priv->fpga_data_addr)) in socfpga_fpga_probe()
561 return PTR_ERR(priv->fpga_data_addr); in socfpga_fpga_probe()
563 priv->irq = platform_get_irq(pdev, 0); in socfpga_fpga_probe()
564 if (priv->irq < 0) in socfpga_fpga_probe()
565 return priv->irq; in socfpga_fpga_probe()
567 ret = devm_request_irq(dev, priv->irq, socfpga_fpga_isr, 0, in socfpga_fpga_probe()
572 mgr = devm_fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager", in socfpga_fpga_probe()
574 return PTR_ERR_OR_ZERO(mgr); in socfpga_fpga_probe()
579 { .compatible = "altr,socfpga-fpga-mgr", },
597 MODULE_DESCRIPTION("Altera SOCFPGA FPGA Manager");