1
0
Fork 0

fpga: manager: change api, don't use drvdata

Change fpga_mgr_register to not set or use drvdata.  This supports
the case where a PCIe device has more than one manager.

Add fpga_mgr_create/free functions.  Change fpga_mgr_register and
fpga_mgr_unregister functions to take the mgr struct as their only
parameter.

  struct fpga_manager *fpga_mgr_create(struct device *dev,
                const char *name,
                const struct fpga_manager_ops *mops,
                void *priv);
  void fpga_mgr_free(struct fpga_manager *mgr);
  int fpga_mgr_register(struct fpga_manager *mgr);
  void fpga_mgr_unregister(struct fpga_manager *mgr);

Update the drivers that call fpga_mgr_register with the new API.

Signed-off-by: Alan Tull <atull@kernel.org>
[Moritz: Fixup whitespace issue]
Reported-by: Jiuyue Ma <majiuyue@huawei.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
hifive-unleashed-5.1
Alan Tull 2018-05-16 18:49:55 -05:00 committed by Greg Kroah-Hartman
parent bbaa9cd3a6
commit 7085e2a94f
13 changed files with 237 additions and 71 deletions

View File

@ -63,17 +63,23 @@ The user should call fpga_mgr_lock and verify that it returns 0 before
attempting to program the FPGA. Likewise, the user should call attempting to program the FPGA. Likewise, the user should call
fpga_mgr_unlock when done programming the FPGA. fpga_mgr_unlock when done programming the FPGA.
To alloc/free a FPGA manager struct:
------------------------------------
struct fpga_manager *fpga_mgr_create(struct device *dev,
const char *name,
const struct fpga_manager_ops *mops,
void *priv);
void fpga_mgr_free(struct fpga_manager *mgr);
To register or unregister the low level FPGA-specific driver: To register or unregister the low level FPGA-specific driver:
------------------------------------------------------------- -------------------------------------------------------------
int fpga_mgr_register(struct device *dev, const char *name, int fpga_mgr_register(struct fpga_manager *mgr);
const struct fpga_manager_ops *mops,
void *priv);
void fpga_mgr_unregister(struct device *dev); void fpga_mgr_unregister(struct fpga_manager *mgr);
Use of these two functions is described below in "How To Support a new FPGA Use of these functions is described below in "How To Support a new FPGA
device." device."
@ -148,6 +154,7 @@ static int socfpga_fpga_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct socfpga_fpga_priv *priv; struct socfpga_fpga_priv *priv;
struct fpga_manager *mgr;
int ret; int ret;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@ -157,13 +164,25 @@ static int socfpga_fpga_probe(struct platform_device *pdev)
/* ... do ioremaps, get interrupts, etc. and save /* ... do ioremaps, get interrupts, etc. and save
them in priv... */ them in priv... */
return fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager", mgr = fpga_mgr_create(dev, "Altera SOCFPGA FPGA Manager",
&socfpga_fpga_ops, priv); &socfpga_fpga_ops, priv);
if (!mgr)
return -ENOMEM;
platform_set_drvdata(pdev, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
static int socfpga_fpga_remove(struct platform_device *pdev) static int socfpga_fpga_remove(struct platform_device *pdev)
{ {
fpga_mgr_unregister(&pdev->dev); struct fpga_manager *mgr = platform_get_drvdata(pdev);
fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -401,6 +401,7 @@ static int altera_cvp_probe(struct pci_dev *pdev,
const struct pci_device_id *dev_id) const struct pci_device_id *dev_id)
{ {
struct altera_cvp_conf *conf; struct altera_cvp_conf *conf;
struct fpga_manager *mgr;
u16 cmd, val; u16 cmd, val;
int ret; int ret;
@ -452,16 +453,24 @@ static int altera_cvp_probe(struct pci_dev *pdev,
snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s @%s", snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s @%s",
ALTERA_CVP_MGR_NAME, pci_name(pdev)); ALTERA_CVP_MGR_NAME, pci_name(pdev));
ret = fpga_mgr_register(&pdev->dev, conf->mgr_name, mgr = fpga_mgr_create(&pdev->dev, conf->mgr_name,
&altera_cvp_ops, conf); &altera_cvp_ops, conf);
if (ret) if (!mgr)
return -ENOMEM;
pci_set_drvdata(pdev, mgr);
ret = fpga_mgr_register(mgr);
if (ret) {
fpga_mgr_free(mgr);
goto err_unmap; goto err_unmap;
}
ret = driver_create_file(&altera_cvp_driver.driver, ret = driver_create_file(&altera_cvp_driver.driver,
&driver_attr_chkcfg); &driver_attr_chkcfg);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Can't create sysfs chkcfg file\n"); dev_err(&pdev->dev, "Can't create sysfs chkcfg file\n");
fpga_mgr_unregister(&pdev->dev); fpga_mgr_unregister(mgr);
goto err_unmap; goto err_unmap;
} }
@ -483,7 +492,7 @@ static void altera_cvp_remove(struct pci_dev *pdev)
u16 cmd; u16 cmd;
driver_remove_file(&altera_cvp_driver.driver, &driver_attr_chkcfg); driver_remove_file(&altera_cvp_driver.driver, &driver_attr_chkcfg);
fpga_mgr_unregister(&pdev->dev); fpga_mgr_unregister(mgr);
pci_iounmap(pdev, conf->map); pci_iounmap(pdev, conf->map);
pci_release_region(pdev, CVP_BAR); pci_release_region(pdev, CVP_BAR);
pci_read_config_word(pdev, PCI_COMMAND, &cmd); pci_read_config_word(pdev, PCI_COMMAND, &cmd);

View File

@ -187,6 +187,8 @@ static const struct fpga_manager_ops alt_pr_ops = {
int alt_pr_register(struct device *dev, void __iomem *reg_base) int alt_pr_register(struct device *dev, void __iomem *reg_base)
{ {
struct alt_pr_priv *priv; struct alt_pr_priv *priv;
struct fpga_manager *mgr;
int ret;
u32 val; u32 val;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@ -201,15 +203,27 @@ int alt_pr_register(struct device *dev, void __iomem *reg_base)
(val & ALT_PR_CSR_STATUS_MSK) >> ALT_PR_CSR_STATUS_SFT, (val & ALT_PR_CSR_STATUS_MSK) >> ALT_PR_CSR_STATUS_SFT,
(int)(val & ALT_PR_CSR_PR_START)); (int)(val & ALT_PR_CSR_PR_START));
return fpga_mgr_register(dev, dev_name(dev), &alt_pr_ops, priv); mgr = fpga_mgr_create(dev, dev_name(dev), &alt_pr_ops, priv);
if (!mgr)
return -ENOMEM;
dev_set_drvdata(dev, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
EXPORT_SYMBOL_GPL(alt_pr_register); EXPORT_SYMBOL_GPL(alt_pr_register);
int alt_pr_unregister(struct device *dev) int alt_pr_unregister(struct device *dev)
{ {
struct fpga_manager *mgr = dev_get_drvdata(dev);
dev_dbg(dev, "%s\n", __func__); dev_dbg(dev, "%s\n", __func__);
fpga_mgr_unregister(dev); fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -238,6 +238,8 @@ static int altera_ps_probe(struct spi_device *spi)
{ {
struct altera_ps_conf *conf; struct altera_ps_conf *conf;
const struct of_device_id *of_id; const struct of_device_id *of_id;
struct fpga_manager *mgr;
int ret;
conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL); conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL);
if (!conf) if (!conf)
@ -273,13 +275,25 @@ static int altera_ps_probe(struct spi_device *spi)
snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s %s", snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s %s",
dev_driver_string(&spi->dev), dev_name(&spi->dev)); dev_driver_string(&spi->dev), dev_name(&spi->dev));
return fpga_mgr_register(&spi->dev, conf->mgr_name, mgr = fpga_mgr_create(&spi->dev, conf->mgr_name,
&altera_ps_ops, conf); &altera_ps_ops, conf);
if (!mgr)
return -ENOMEM;
spi_set_drvdata(spi, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
static int altera_ps_remove(struct spi_device *spi) static int altera_ps_remove(struct spi_device *spi)
{ {
fpga_mgr_unregister(&spi->dev); struct fpga_manager *mgr = spi_get_drvdata(spi);
fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -515,17 +515,17 @@ void fpga_mgr_unlock(struct fpga_manager *mgr)
EXPORT_SYMBOL_GPL(fpga_mgr_unlock); EXPORT_SYMBOL_GPL(fpga_mgr_unlock);
/** /**
* fpga_mgr_register - register a low level fpga manager driver * fpga_mgr_create - create and initialize a FPGA manager struct
* @dev: fpga manager device from pdev * @dev: fpga manager device from pdev
* @name: fpga manager name * @name: fpga manager name
* @mops: pointer to structure of fpga manager ops * @mops: pointer to structure of fpga manager ops
* @priv: fpga manager private data * @priv: fpga manager private data
* *
* Return: 0 on success, negative error code otherwise. * Return: pointer to struct fpga_manager or NULL
*/ */
int fpga_mgr_register(struct device *dev, const char *name, struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,
const struct fpga_manager_ops *mops, const struct fpga_manager_ops *mops,
void *priv) void *priv)
{ {
struct fpga_manager *mgr; struct fpga_manager *mgr;
int id, ret; int id, ret;
@ -534,17 +534,17 @@ int fpga_mgr_register(struct device *dev, const char *name,
!mops->write_init || (!mops->write && !mops->write_sg) || !mops->write_init || (!mops->write && !mops->write_sg) ||
(mops->write && mops->write_sg)) { (mops->write && mops->write_sg)) {
dev_err(dev, "Attempt to register without fpga_manager_ops\n"); dev_err(dev, "Attempt to register without fpga_manager_ops\n");
return -EINVAL; return NULL;
} }
if (!name || !strlen(name)) { if (!name || !strlen(name)) {
dev_err(dev, "Attempt to register with no name!\n"); dev_err(dev, "Attempt to register with no name!\n");
return -EINVAL; return NULL;
} }
mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
if (!mgr) if (!mgr)
return -ENOMEM; return NULL;
id = ida_simple_get(&fpga_mgr_ida, 0, 0, GFP_KERNEL); id = ida_simple_get(&fpga_mgr_ida, 0, 0, GFP_KERNEL);
if (id < 0) { if (id < 0) {
@ -558,25 +558,56 @@ int fpga_mgr_register(struct device *dev, const char *name,
mgr->mops = mops; mgr->mops = mops;
mgr->priv = priv; mgr->priv = priv;
/*
* Initialize framework state by requesting low level driver read state
* from device. FPGA may be in reset mode or may have been programmed
* by bootloader or EEPROM.
*/
mgr->state = mgr->mops->state(mgr);
device_initialize(&mgr->dev); device_initialize(&mgr->dev);
mgr->dev.class = fpga_mgr_class; mgr->dev.class = fpga_mgr_class;
mgr->dev.groups = mops->groups; mgr->dev.groups = mops->groups;
mgr->dev.parent = dev; mgr->dev.parent = dev;
mgr->dev.of_node = dev->of_node; mgr->dev.of_node = dev->of_node;
mgr->dev.id = id; mgr->dev.id = id;
dev_set_drvdata(dev, mgr);
ret = dev_set_name(&mgr->dev, "fpga%d", id); ret = dev_set_name(&mgr->dev, "fpga%d", id);
if (ret) if (ret)
goto error_device; goto error_device;
return mgr;
error_device:
ida_simple_remove(&fpga_mgr_ida, id);
error_kfree:
kfree(mgr);
return NULL;
}
EXPORT_SYMBOL_GPL(fpga_mgr_create);
/**
* fpga_mgr_free - deallocate a FPGA manager
* @mgr: fpga manager struct created by fpga_mgr_create
*/
void fpga_mgr_free(struct fpga_manager *mgr)
{
ida_simple_remove(&fpga_mgr_ida, mgr->dev.id);
kfree(mgr);
}
EXPORT_SYMBOL_GPL(fpga_mgr_free);
/**
* fpga_mgr_register - register a FPGA manager
* @mgr: fpga manager struct created by fpga_mgr_create
*
* Return: 0 on success, negative error code otherwise.
*/
int fpga_mgr_register(struct fpga_manager *mgr)
{
int ret;
/*
* Initialize framework state by requesting low level driver read state
* from device. FPGA may be in reset mode or may have been programmed
* by bootloader or EEPROM.
*/
mgr->state = mgr->mops->state(mgr);
ret = device_add(&mgr->dev); ret = device_add(&mgr->dev);
if (ret) if (ret)
goto error_device; goto error_device;
@ -586,22 +617,18 @@ int fpga_mgr_register(struct device *dev, const char *name,
return 0; return 0;
error_device: error_device:
ida_simple_remove(&fpga_mgr_ida, id); ida_simple_remove(&fpga_mgr_ida, mgr->dev.id);
error_kfree:
kfree(mgr);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(fpga_mgr_register); EXPORT_SYMBOL_GPL(fpga_mgr_register);
/** /**
* fpga_mgr_unregister - unregister a low level fpga manager driver * fpga_mgr_unregister - unregister a FPGA manager
* @dev: fpga manager device from pdev * @mgr: fpga manager struct
*/ */
void fpga_mgr_unregister(struct device *dev) void fpga_mgr_unregister(struct fpga_manager *mgr)
{ {
struct fpga_manager *mgr = dev_get_drvdata(dev);
dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name); dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name);
/* /*
@ -619,8 +646,7 @@ static void fpga_mgr_dev_release(struct device *dev)
{ {
struct fpga_manager *mgr = to_fpga_manager(dev); struct fpga_manager *mgr = to_fpga_manager(dev);
ida_simple_remove(&fpga_mgr_ida, mgr->dev.id); fpga_mgr_free(mgr);
kfree(mgr);
} }
static int __init fpga_mgr_class_init(void) static int __init fpga_mgr_class_init(void)

View File

@ -133,6 +133,7 @@ static int ice40_fpga_probe(struct spi_device *spi)
{ {
struct device *dev = &spi->dev; struct device *dev = &spi->dev;
struct ice40_fpga_priv *priv; struct ice40_fpga_priv *priv;
struct fpga_manager *mgr;
int ret; int ret;
priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL);
@ -174,14 +175,26 @@ static int ice40_fpga_probe(struct spi_device *spi)
return ret; return ret;
} }
/* Register with the FPGA manager */ mgr = fpga_mgr_create(dev, "Lattice iCE40 FPGA Manager",
return fpga_mgr_register(dev, "Lattice iCE40 FPGA Manager", &ice40_fpga_ops, priv);
&ice40_fpga_ops, priv); if (!mgr)
return -ENOMEM;
spi_set_drvdata(spi, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
static int ice40_fpga_remove(struct spi_device *spi) static int ice40_fpga_remove(struct spi_device *spi)
{ {
fpga_mgr_unregister(&spi->dev); struct fpga_manager *mgr = spi_get_drvdata(spi);
fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -355,21 +355,33 @@ static const struct fpga_manager_ops machxo2_ops = {
static int machxo2_spi_probe(struct spi_device *spi) static int machxo2_spi_probe(struct spi_device *spi)
{ {
struct device *dev = &spi->dev; struct device *dev = &spi->dev;
struct fpga_manager *mgr;
int ret;
if (spi->max_speed_hz > MACHXO2_MAX_SPEED) { if (spi->max_speed_hz > MACHXO2_MAX_SPEED) {
dev_err(dev, "Speed is too high\n"); dev_err(dev, "Speed is too high\n");
return -EINVAL; return -EINVAL;
} }
return fpga_mgr_register(dev, "Lattice MachXO2 SPI FPGA Manager", mgr = fpga_mgr_create(dev, "Lattice MachXO2 SPI FPGA Manager",
&machxo2_ops, spi); &machxo2_ops, spi);
if (!mgr)
return -ENOMEM;
spi_set_drvdata(spi, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
static int machxo2_spi_remove(struct spi_device *spi) static int machxo2_spi_remove(struct spi_device *spi)
{ {
struct device *dev = &spi->dev; struct fpga_manager *mgr = spi_get_drvdata(spi);
fpga_mgr_unregister(dev); fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -482,6 +482,7 @@ static int socfpga_a10_fpga_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct a10_fpga_priv *priv; struct a10_fpga_priv *priv;
void __iomem *reg_base; void __iomem *reg_base;
struct fpga_manager *mgr;
struct resource *res; struct resource *res;
int ret; int ret;
@ -519,9 +520,16 @@ static int socfpga_a10_fpga_probe(struct platform_device *pdev)
return -EBUSY; return -EBUSY;
} }
ret = fpga_mgr_register(dev, "SoCFPGA Arria10 FPGA Manager", mgr = fpga_mgr_create(dev, "SoCFPGA Arria10 FPGA Manager",
&socfpga_a10_fpga_mgr_ops, priv); &socfpga_a10_fpga_mgr_ops, priv);
if (!mgr)
return -ENOMEM;
platform_set_drvdata(pdev, mgr);
ret = fpga_mgr_register(mgr);
if (ret) { if (ret) {
fpga_mgr_free(mgr);
clk_disable_unprepare(priv->clk); clk_disable_unprepare(priv->clk);
return ret; return ret;
} }
@ -534,7 +542,7 @@ static int socfpga_a10_fpga_remove(struct platform_device *pdev)
struct fpga_manager *mgr = platform_get_drvdata(pdev); struct fpga_manager *mgr = platform_get_drvdata(pdev);
struct a10_fpga_priv *priv = mgr->priv; struct a10_fpga_priv *priv = mgr->priv;
fpga_mgr_unregister(&pdev->dev); fpga_mgr_unregister(mgr);
clk_disable_unprepare(priv->clk); clk_disable_unprepare(priv->clk);
return 0; return 0;

View File

@ -555,6 +555,7 @@ static int socfpga_fpga_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct socfpga_fpga_priv *priv; struct socfpga_fpga_priv *priv;
struct fpga_manager *mgr;
struct resource *res; struct resource *res;
int ret; int ret;
@ -581,13 +582,25 @@ static int socfpga_fpga_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
return fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager", mgr = fpga_mgr_create(dev, "Altera SOCFPGA FPGA Manager",
&socfpga_fpga_ops, priv); &socfpga_fpga_ops, priv);
if (!mgr)
return -ENOMEM;
platform_set_drvdata(pdev, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
static int socfpga_fpga_remove(struct platform_device *pdev) static int socfpga_fpga_remove(struct platform_device *pdev)
{ {
fpga_mgr_unregister(&pdev->dev); struct fpga_manager *mgr = platform_get_drvdata(pdev);
fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -116,7 +116,9 @@ static int ts73xx_fpga_probe(struct platform_device *pdev)
{ {
struct device *kdev = &pdev->dev; struct device *kdev = &pdev->dev;
struct ts73xx_fpga_priv *priv; struct ts73xx_fpga_priv *priv;
struct fpga_manager *mgr;
struct resource *res; struct resource *res;
int ret;
priv = devm_kzalloc(kdev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(kdev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
@ -131,13 +133,25 @@ static int ts73xx_fpga_probe(struct platform_device *pdev)
return PTR_ERR(priv->io_base); return PTR_ERR(priv->io_base);
} }
return fpga_mgr_register(kdev, "TS-73xx FPGA Manager", mgr = fpga_mgr_create(kdev, "TS-73xx FPGA Manager",
&ts73xx_fpga_ops, priv); &ts73xx_fpga_ops, priv);
if (!mgr)
return -ENOMEM;
platform_set_drvdata(pdev, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
static int ts73xx_fpga_remove(struct platform_device *pdev) static int ts73xx_fpga_remove(struct platform_device *pdev)
{ {
fpga_mgr_unregister(&pdev->dev); struct fpga_manager *mgr = platform_get_drvdata(pdev);
fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -143,6 +143,8 @@ static const struct fpga_manager_ops xilinx_spi_ops = {
static int xilinx_spi_probe(struct spi_device *spi) static int xilinx_spi_probe(struct spi_device *spi)
{ {
struct xilinx_spi_conf *conf; struct xilinx_spi_conf *conf;
struct fpga_manager *mgr;
int ret;
conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL); conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL);
if (!conf) if (!conf)
@ -165,13 +167,25 @@ static int xilinx_spi_probe(struct spi_device *spi)
return PTR_ERR(conf->done); return PTR_ERR(conf->done);
} }
return fpga_mgr_register(&spi->dev, "Xilinx Slave Serial FPGA Manager", mgr = fpga_mgr_create(&spi->dev, "Xilinx Slave Serial FPGA Manager",
&xilinx_spi_ops, conf); &xilinx_spi_ops, conf);
if (!mgr)
return -ENOMEM;
spi_set_drvdata(spi, mgr);
ret = fpga_mgr_register(mgr);
if (ret)
fpga_mgr_free(mgr);
return ret;
} }
static int xilinx_spi_remove(struct spi_device *spi) static int xilinx_spi_remove(struct spi_device *spi)
{ {
fpga_mgr_unregister(&spi->dev); struct fpga_manager *mgr = spi_get_drvdata(spi);
fpga_mgr_unregister(mgr);
return 0; return 0;
} }

View File

@ -558,6 +558,7 @@ static int zynq_fpga_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct zynq_fpga_priv *priv; struct zynq_fpga_priv *priv;
struct fpga_manager *mgr;
struct resource *res; struct resource *res;
int err; int err;
@ -613,10 +614,17 @@ static int zynq_fpga_probe(struct platform_device *pdev)
clk_disable(priv->clk); clk_disable(priv->clk);
err = fpga_mgr_register(dev, "Xilinx Zynq FPGA Manager", mgr = fpga_mgr_create(dev, "Xilinx Zynq FPGA Manager",
&zynq_fpga_ops, priv); &zynq_fpga_ops, priv);
if (!mgr)
return -ENOMEM;
platform_set_drvdata(pdev, mgr);
err = fpga_mgr_register(mgr);
if (err) { if (err) {
dev_err(dev, "unable to register FPGA manager\n"); dev_err(dev, "unable to register FPGA manager\n");
fpga_mgr_free(mgr);
clk_unprepare(priv->clk); clk_unprepare(priv->clk);
return err; return err;
} }
@ -632,7 +640,7 @@ static int zynq_fpga_remove(struct platform_device *pdev)
mgr = platform_get_drvdata(pdev); mgr = platform_get_drvdata(pdev);
priv = mgr->priv; priv = mgr->priv;
fpga_mgr_unregister(&pdev->dev); fpga_mgr_unregister(mgr);
clk_unprepare(priv->clk); clk_unprepare(priv->clk);

View File

@ -170,9 +170,11 @@ struct fpga_manager *fpga_mgr_get(struct device *dev);
void fpga_mgr_put(struct fpga_manager *mgr); void fpga_mgr_put(struct fpga_manager *mgr);
int fpga_mgr_register(struct device *dev, const char *name, struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,
const struct fpga_manager_ops *mops, void *priv); const struct fpga_manager_ops *mops,
void *priv);
void fpga_mgr_unregister(struct device *dev); void fpga_mgr_free(struct fpga_manager *mgr);
int fpga_mgr_register(struct fpga_manager *mgr);
void fpga_mgr_unregister(struct fpga_manager *mgr);
#endif /*_LINUX_FPGA_MGR_H */ #endif /*_LINUX_FPGA_MGR_H */