Commit 8ebab40f authored by Tom Rix's avatar Tom Rix Committed by Moritz Fischer

fpga: fpga-mgr: wrap the write() op

An FPGA manager should not be required to provide a
write function. Move the op check to the wrapper.
Default to -EOPNOTSUP so its users will fail
gracefully.

[mdf@kernel.org: Reworded message]
Signed-off-by: default avatarTom Rix <trix@redhat.com>
Signed-off-by: default avatarMoritz Fischer <mdf@kernel.org>
parent 72d93502
...@@ -25,6 +25,13 @@ struct fpga_mgr_devres { ...@@ -25,6 +25,13 @@ struct fpga_mgr_devres {
struct fpga_manager *mgr; struct fpga_manager *mgr;
}; };
static inline int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size_t count)
{
if (mgr->mops->write)
return mgr->mops->write(mgr, buf, count);
return -EOPNOTSUPP;
}
/* /*
* After all the FPGA image has been written, do the device specific steps to * After all the FPGA image has been written, do the device specific steps to
* finish and set the FPGA into operating mode. * finish and set the FPGA into operating mode.
...@@ -204,7 +211,7 @@ static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr, ...@@ -204,7 +211,7 @@ static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr,
sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG); sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG);
while (sg_miter_next(&miter)) { while (sg_miter_next(&miter)) {
ret = mgr->mops->write(mgr, miter.addr, miter.length); ret = fpga_mgr_write(mgr, miter.addr, miter.length);
if (ret) if (ret)
break; break;
} }
...@@ -234,7 +241,7 @@ static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr, ...@@ -234,7 +241,7 @@ static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr,
* Write the FPGA image to the FPGA. * Write the FPGA image to the FPGA.
*/ */
mgr->state = FPGA_MGR_STATE_WRITE; mgr->state = FPGA_MGR_STATE_WRITE;
ret = mgr->mops->write(mgr, buf, count); ret = fpga_mgr_write(mgr, buf, count);
if (ret) { if (ret) {
dev_err(&mgr->dev, "Error while writing image data to FPGA\n"); dev_err(&mgr->dev, "Error while writing image data to FPGA\n");
mgr->state = FPGA_MGR_STATE_WRITE_ERR; mgr->state = FPGA_MGR_STATE_WRITE_ERR;
...@@ -578,9 +585,7 @@ struct fpga_manager *fpga_mgr_create(struct device *parent, const char *name, ...@@ -578,9 +585,7 @@ struct fpga_manager *fpga_mgr_create(struct device *parent, const char *name,
struct fpga_manager *mgr; struct fpga_manager *mgr;
int id, ret; int id, ret;
if (!mops || !mops->state || if (!mops || !mops->state) {
(!mops->write && !mops->write_sg) ||
(mops->write && mops->write_sg)) {
dev_err(parent, "Attempt to register without fpga_manager_ops\n"); dev_err(parent, "Attempt to register without fpga_manager_ops\n");
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment