Linux 4.19.133
[linux/fpc-iii.git] / drivers / fpga / dfl-fme-region.c
blob51a5ac2293a72c27e17bec80fa768986eb2751e4
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * FPGA Region Driver for FPGA Management Engine (FME)
5 * Copyright (C) 2017-2018 Intel Corporation, Inc.
7 * Authors:
8 * Wu Hao <hao.wu@intel.com>
9 * Joseph Grecco <joe.grecco@intel.com>
10 * Enno Luebbers <enno.luebbers@intel.com>
11 * Tim Whisonant <tim.whisonant@intel.com>
12 * Ananda Ravuri <ananda.ravuri@intel.com>
13 * Henry Mitchel <henry.mitchel@intel.com>
16 #include <linux/module.h>
17 #include <linux/fpga/fpga-mgr.h>
18 #include <linux/fpga/fpga-region.h>
20 #include "dfl-fme-pr.h"
22 static int fme_region_get_bridges(struct fpga_region *region)
24 struct dfl_fme_region_pdata *pdata = region->priv;
25 struct device *dev = &pdata->br->dev;
27 return fpga_bridge_get_to_list(dev, region->info, &region->bridge_list);
30 static int fme_region_probe(struct platform_device *pdev)
32 struct dfl_fme_region_pdata *pdata = dev_get_platdata(&pdev->dev);
33 struct device *dev = &pdev->dev;
34 struct fpga_region *region;
35 struct fpga_manager *mgr;
36 int ret;
38 mgr = fpga_mgr_get(&pdata->mgr->dev);
39 if (IS_ERR(mgr))
40 return -EPROBE_DEFER;
42 region = fpga_region_create(dev, mgr, fme_region_get_bridges);
43 if (!region) {
44 ret = -ENOMEM;
45 goto eprobe_mgr_put;
48 region->priv = pdata;
49 region->compat_id = mgr->compat_id;
50 platform_set_drvdata(pdev, region);
52 ret = fpga_region_register(region);
53 if (ret)
54 goto region_free;
56 dev_dbg(dev, "DFL FME FPGA Region probed\n");
58 return 0;
60 region_free:
61 fpga_region_free(region);
62 eprobe_mgr_put:
63 fpga_mgr_put(mgr);
64 return ret;
67 static int fme_region_remove(struct platform_device *pdev)
69 struct fpga_region *region = dev_get_drvdata(&pdev->dev);
70 struct fpga_manager *mgr = region->mgr;
72 fpga_region_unregister(region);
73 fpga_mgr_put(mgr);
75 return 0;
78 static struct platform_driver fme_region_driver = {
79 .driver = {
80 .name = DFL_FPGA_FME_REGION,
82 .probe = fme_region_probe,
83 .remove = fme_region_remove,
86 module_platform_driver(fme_region_driver);
88 MODULE_DESCRIPTION("FPGA Region for DFL FPGA Management Engine");
89 MODULE_AUTHOR("Intel Corporation");
90 MODULE_LICENSE("GPL v2");
91 MODULE_ALIAS("platform:dfl-fme-region");