]> Git Repo - J-linux.git/blobdiff - drivers/fpga/fpga-bridge.c
Merge branch 'linus' into x86/urgent
[J-linux.git] / drivers / fpga / fpga-bridge.c
index 31bd2c59c305940fd77bbf81712f50f198743698..24b8f98b73ec69019a5421258c57123d8034cadf 100644 (file)
@@ -1,20 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * FPGA Bridge Framework Driver
  *
  *  Copyright (C) 2013-2016 Altera Corporation, All Rights Reserved.
  *  Copyright (C) 2017 Intel Corporation
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include <linux/fpga/fpga-bridge.h>
 #include <linux/idr.h>
@@ -132,6 +121,7 @@ static int fpga_bridge_dev_match(struct device *dev, const void *data)
 /**
  * fpga_bridge_get - get an exclusive reference to a fpga bridge
  * @dev:       parent device that fpga bridge was registered with
+ * @info:      fpga manager info
  *
  * Given a device, get an exclusive reference to a fpga bridge.
  *
@@ -328,28 +318,29 @@ static struct attribute *fpga_bridge_attrs[] = {
 ATTRIBUTE_GROUPS(fpga_bridge);
 
 /**
- * fpga_bridge_register - register a fpga bridge driver
+ * fpga_bridge_create - create and initialize a struct fpga_bridge
  * @dev:       FPGA bridge device from pdev
  * @name:      FPGA bridge name
  * @br_ops:    pointer to structure of fpga bridge ops
  * @priv:      FPGA bridge private data
  *
- * Return: 0 for success, error code otherwise.
+ * Return: struct fpga_bridge or NULL
  */
-int fpga_bridge_register(struct device *dev, const char *name,
-                        const struct fpga_bridge_ops *br_ops, void *priv)
+struct fpga_bridge *fpga_bridge_create(struct device *dev, const char *name,
+                                      const struct fpga_bridge_ops *br_ops,
+                                      void *priv)
 {
        struct fpga_bridge *bridge;
        int id, ret = 0;
 
        if (!name || !strlen(name)) {
                dev_err(dev, "Attempt to register with no name!\n");
-               return -EINVAL;
+               return NULL;
        }
 
        bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
        if (!bridge)
-               return -ENOMEM;
+               return NULL;
 
        id = ida_simple_get(&fpga_bridge_ida, 0, 0, GFP_KERNEL);
        if (id < 0) {
@@ -370,40 +361,62 @@ int fpga_bridge_register(struct device *dev, const char *name,
        bridge->dev.parent = dev;
        bridge->dev.of_node = dev->of_node;
        bridge->dev.id = id;
-       dev_set_drvdata(dev, bridge);
 
        ret = dev_set_name(&bridge->dev, "br%d", id);
        if (ret)
                goto error_device;
 
-       ret = device_add(&bridge->dev);
-       if (ret)
-               goto error_device;
-
-       of_platform_populate(dev->of_node, NULL, NULL, dev);
-
-       dev_info(bridge->dev.parent, "fpga bridge [%s] registered\n",
-                bridge->name);
-
-       return 0;
+       return bridge;
 
 error_device:
        ida_simple_remove(&fpga_bridge_ida, id);
 error_kfree:
        kfree(bridge);
 
-       return ret;
+       return NULL;
 }
-EXPORT_SYMBOL_GPL(fpga_bridge_register);
+EXPORT_SYMBOL_GPL(fpga_bridge_create);
 
 /**
- * fpga_bridge_unregister - unregister a fpga bridge driver
- * @dev: FPGA bridge device from pdev
+ * fpga_bridge_free - free a fpga bridge and its id
+ * @bridge:    FPGA bridge struct created by fpga_bridge_create
  */
-void fpga_bridge_unregister(struct device *dev)
+void fpga_bridge_free(struct fpga_bridge *bridge)
 {
-       struct fpga_bridge *bridge = dev_get_drvdata(dev);
+       ida_simple_remove(&fpga_bridge_ida, bridge->dev.id);
+       kfree(bridge);
+}
+EXPORT_SYMBOL_GPL(fpga_bridge_free);
 
+/**
+ * fpga_bridge_register - register a fpga bridge
+ * @bridge:    FPGA bridge struct created by fpga_bridge_create
+ *
+ * Return: 0 for success, error code otherwise.
+ */
+int fpga_bridge_register(struct fpga_bridge *bridge)
+{
+       struct device *dev = &bridge->dev;
+       int ret;
+
+       ret = device_add(dev);
+       if (ret)
+               return ret;
+
+       of_platform_populate(dev->of_node, NULL, NULL, dev);
+
+       dev_info(dev->parent, "fpga bridge [%s] registered\n", bridge->name);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(fpga_bridge_register);
+
+/**
+ * fpga_bridge_unregister - unregister and free a fpga bridge
+ * @bridge:    FPGA bridge struct created by fpga_bridge_create
+ */
+void fpga_bridge_unregister(struct fpga_bridge *bridge)
+{
        /*
         * If the low level driver provides a method for putting bridge into
         * a desired state upon unregister, do it.
@@ -419,8 +432,7 @@ static void fpga_bridge_dev_release(struct device *dev)
 {
        struct fpga_bridge *bridge = to_fpga_bridge(dev);
 
-       ida_simple_remove(&fpga_bridge_ida, bridge->dev.id);
-       kfree(bridge);
+       fpga_bridge_free(bridge);
 }
 
 static int __init fpga_bridge_dev_init(void)
This page took 0.03351 seconds and 4 git commands to generate.