aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Colberg <[email protected]>2024-11-20 01:10:25 +0000
committerXu Yilun <[email protected]>2024-12-18 14:28:48 +0000
commit0783f41b00502d29fd70c31e727671d4a94e92f6 (patch)
tree9cf6c79896ee6a3652ab1831f4da81099486f70a
parentfpga: dfl: refactor internal DFL APIs to take/return feature device data (diff)
downloadkernel-0783f41b00502d29fd70c31e727671d4a94e92f6.tar.gz
kernel-0783f41b00502d29fd70c31e727671d4a94e92f6.zip
fpga: dfl: factor out feature device registration
Add separate functions, feature_dev_{register,unregister}(), that wrap platform_device_add() and platform_device_unregister(), respectively. These are invoked once per feature device in this commit but will be reused in a subsequent commit to destroy and recreate the platform device when the corresponding port is released and reassigned. The function feature_dev_register() will be extended in subsequent commits to allocate the platform device, add resources and platform data, and finally add the platform device to the device hierarchy. Signed-off-by: Peter Colberg <[email protected]> Reviewed-by: Matthew Gerlach <[email protected]> Reviewed-by: Basheer Ahmed Muddebihal <[email protected]> Acked-by: Xu Yilun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Xu Yilun <[email protected]>
-rw-r--r--drivers/fpga/dfl.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 0462fe9edb10..081b55d22973 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -872,12 +872,34 @@ build_info_create_dev(struct build_feature_devs_info *binfo)
if (fdev->id < 0)
return fdev->id;
- fdev->dev.parent = &binfo->cdev->region->dev;
- fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);
+ return 0;
+}
+
+/*
+ * register current feature device, it is called when we need to switch to
+ * another feature parsing or we have parsed all features on given device
+ * feature list.
+ */
+static int feature_dev_register(struct dfl_feature_dev_data *fdata)
+{
+ struct platform_device *fdev = fdata->dev;
+ int ret;
+
+ fdev->dev.parent = &fdata->dfl_cdev->region->dev;
+ fdev->dev.devt = dfl_get_devt(dfl_devs[fdata->type].devt_type, fdev->id);
+
+ ret = platform_device_add(fdev);
+ if (ret)
+ return ret;
return 0;
}
+static void feature_dev_unregister(struct dfl_feature_dev_data *fdata)
+{
+ platform_device_unregister(fdata->dev);
+}
+
static int build_info_commit_dev(struct build_feature_devs_info *binfo)
{
struct dfl_feature_dev_data *fdata;
@@ -887,7 +909,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)
if (IS_ERR(fdata))
return PTR_ERR(fdata);
- ret = platform_device_add(binfo->feature_dev);
+ ret = feature_dev_register(fdata);
if (ret)
return ret;
@@ -1519,7 +1541,7 @@ static int remove_feature_dev(struct device *dev, void *data)
struct platform_device *pdev = to_platform_device(dev);
int id = pdev->id;
- platform_device_unregister(pdev);
+ feature_dev_unregister(fdata);
dfl_id_free(fdata->type, id);