Skip to content

Commit

Permalink
fpga: mgr: Use standard dev_release for class driver
Browse files Browse the repository at this point in the history
The FPGA manager class driver data structure is being treated as a
managed resource instead of using the standard dev_release call-back
function to release the class data structure. This change removes
the managed resource code for the freeing of the class data structure
and combines the create() and register() functions into a single
register() or register_full() function.

The register_full() function accepts an info data structure to provide
flexibility in passing optional parameters. The register() function
supports the current parameter list for users that don't require the
use of optional parameters.

The devm_fpga_mgr_register() function is retained, and the
devm_fpga_mgr_register_full() function is added.

Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Reviewed-by: Xu Yilun <yilun.xu@intel.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
  • Loading branch information
Russ Weight authored and mfischer committed Nov 28, 2021
1 parent fa55b7d commit 4ba0b2c
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 261 deletions.
38 changes: 29 additions & 9 deletions Documentation/driver-api/fpga/fpga-mgr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ How to support a new FPGA device
--------------------------------

To add another FPGA manager, write a driver that implements a set of ops. The
probe function calls fpga_mgr_register(), such as::
probe function calls fpga_mgr_register() or fpga_mgr_register_full(), such as::

static const struct fpga_manager_ops socfpga_fpga_ops = {
.write_init = socfpga_fpga_ops_configure_init,
Expand All @@ -49,14 +49,14 @@ probe function calls fpga_mgr_register(), such as::
* them in priv
*/

mgr = devm_fpga_mgr_create(dev, "Altera SOCFPGA FPGA Manager",
&socfpga_fpga_ops, priv);
if (!mgr)
return -ENOMEM;
mgr = fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager",
&socfpga_fpga_ops, priv);
if (IS_ERR(mgr))
return PTR_ERR(mgr);

platform_set_drvdata(pdev, mgr);

return fpga_mgr_register(mgr);
return 0;
}

static int socfpga_fpga_remove(struct platform_device *pdev)
Expand All @@ -68,6 +68,11 @@ probe function calls fpga_mgr_register(), such as::
return 0;
}

Alternatively, the probe function could call one of the resource managed
register functions, devm_fpga_mgr_register() or devm_fpga_mgr_register_full().
When these functions are used, the parameter syntax is the same, but the call
to fpga_mgr_unregister() should be removed. In the above example, the
socfpga_fpga_remove() function would not be required.

The ops will implement whatever device specific register writes are needed to
do the programming sequence for this particular FPGA. These ops return 0 for
Expand Down Expand Up @@ -104,8 +109,14 @@ API for implementing a new FPGA Manager driver
* ``fpga_mgr_states`` - Values for :c:expr:`fpga_manager->state`.
* struct fpga_manager - the FPGA manager struct
* struct fpga_manager_ops - Low level FPGA manager driver ops
* devm_fpga_mgr_create() - Allocate and init a manager struct
* fpga_mgr_register() - Register an FPGA manager
* struct fpga_manager_info - Parameter structure for fpga_mgr_register_full()
* fpga_mgr_register_full() - Create and register an FPGA manager using the
fpga_mgr_info structure to provide the full flexibility of options
* fpga_mgr_register() - Create and register an FPGA manager using standard
arguments
* devm_fpga_mgr_register_full() - Resource managed version of
fpga_mgr_register_full()
* devm_fpga_mgr_register() - Resource managed version of fpga_mgr_register()
* fpga_mgr_unregister() - Unregister an FPGA manager

.. kernel-doc:: include/linux/fpga/fpga-mgr.h
Expand All @@ -117,11 +128,20 @@ API for implementing a new FPGA Manager driver
.. kernel-doc:: include/linux/fpga/fpga-mgr.h
:functions: fpga_manager_ops

.. kernel-doc:: include/linux/fpga/fpga-mgr.h
:functions: fpga_manager_info

.. kernel-doc:: drivers/fpga/fpga-mgr.c
:functions: devm_fpga_mgr_create
:functions: fpga_mgr_register_full

.. kernel-doc:: drivers/fpga/fpga-mgr.c
:functions: fpga_mgr_register

.. kernel-doc:: drivers/fpga/fpga-mgr.c
:functions: devm_fpga_mgr_register_full

.. kernel-doc:: drivers/fpga/fpga-mgr.c
:functions: devm_fpga_mgr_register

.. kernel-doc:: drivers/fpga/fpga-mgr.c
:functions: fpga_mgr_unregister
12 changes: 4 additions & 8 deletions drivers/fpga/altera-cvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,19 +652,15 @@ static int altera_cvp_probe(struct pci_dev *pdev,
snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s @%s",
ALTERA_CVP_MGR_NAME, pci_name(pdev));

mgr = devm_fpga_mgr_create(&pdev->dev, conf->mgr_name,
&altera_cvp_ops, conf);
if (!mgr) {
ret = -ENOMEM;
mgr = fpga_mgr_register(&pdev->dev, conf->mgr_name,
&altera_cvp_ops, conf);
if (IS_ERR(mgr)) {
ret = PTR_ERR(mgr);
goto err_unmap;
}

pci_set_drvdata(pdev, mgr);

ret = fpga_mgr_register(mgr);
if (ret)
goto err_unmap;

return 0;

err_unmap:
Expand Down
7 changes: 2 additions & 5 deletions drivers/fpga/altera-pr-ip-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,8 @@ int alt_pr_register(struct device *dev, void __iomem *reg_base)
(val & ALT_PR_CSR_STATUS_MSK) >> ALT_PR_CSR_STATUS_SFT,
(int)(val & ALT_PR_CSR_PR_START));

mgr = devm_fpga_mgr_create(dev, dev_name(dev), &alt_pr_ops, priv);
if (!mgr)
return -ENOMEM;

return devm_fpga_mgr_register(dev, mgr);
mgr = devm_fpga_mgr_register(dev, dev_name(dev), &alt_pr_ops, priv);
return PTR_ERR_OR_ZERO(mgr);
}
EXPORT_SYMBOL_GPL(alt_pr_register);

Expand Down
9 changes: 3 additions & 6 deletions drivers/fpga/altera-ps-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,9 @@ static int altera_ps_probe(struct spi_device *spi)
snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s %s",
dev_driver_string(&spi->dev), dev_name(&spi->dev));

mgr = devm_fpga_mgr_create(&spi->dev, conf->mgr_name,
&altera_ps_ops, conf);
if (!mgr)
return -ENOMEM;

return devm_fpga_mgr_register(&spi->dev, mgr);
mgr = devm_fpga_mgr_register(&spi->dev, conf->mgr_name,
&altera_ps_ops, conf);
return PTR_ERR_OR_ZERO(mgr);
}

static const struct spi_device_id altera_ps_spi_ids[] = {
Expand Down
22 changes: 9 additions & 13 deletions drivers/fpga/dfl-fme-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static void fme_mgr_get_compat_id(void __iomem *fme_pr,
static int fme_mgr_probe(struct platform_device *pdev)
{
struct dfl_fme_mgr_pdata *pdata = dev_get_platdata(&pdev->dev);
struct fpga_compat_id *compat_id;
struct fpga_manager_info info = { 0 };
struct device *dev = &pdev->dev;
struct fme_mgr_priv *priv;
struct fpga_manager *mgr;
Expand All @@ -296,20 +296,16 @@ static int fme_mgr_probe(struct platform_device *pdev)
return PTR_ERR(priv->ioaddr);
}

compat_id = devm_kzalloc(dev, sizeof(*compat_id), GFP_KERNEL);
if (!compat_id)
info.name = "DFL FME FPGA Manager";
info.mops = &fme_mgr_ops;
info.priv = priv;
info.compat_id = devm_kzalloc(dev, sizeof(*info.compat_id), GFP_KERNEL);
if (!info.compat_id)
return -ENOMEM;

fme_mgr_get_compat_id(priv->ioaddr, compat_id);

mgr = devm_fpga_mgr_create(dev, "DFL FME FPGA Manager",
&fme_mgr_ops, priv);
if (!mgr)
return -ENOMEM;

mgr->compat_id = compat_id;

return devm_fpga_mgr_register(dev, mgr);
fme_mgr_get_compat_id(priv->ioaddr, info.compat_id);
mgr = devm_fpga_mgr_register_full(dev, &info);
return PTR_ERR_OR_ZERO(mgr);
}

static struct platform_driver fme_mgr_driver = {
Expand Down
Loading

0 comments on commit 4ba0b2c

Please sign in to comment.