perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / media / platform / rcar-fcp.c
blob43c78620c9d8a3c04a12468a13124ea780a4b5db
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * rcar-fcp.c -- R-Car Frame Compression Processor Driver
5 * Copyright (C) 2016 Renesas Electronics Corporation
7 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 */
10 #include <linux/device.h>
11 #include <linux/list.h>
12 #include <linux/module.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/mutex.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/slab.h>
19 #include <media/rcar-fcp.h>
21 struct rcar_fcp_device {
22 struct list_head list;
23 struct device *dev;
26 static LIST_HEAD(fcp_devices);
27 static DEFINE_MUTEX(fcp_lock);
29 /* -----------------------------------------------------------------------------
30 * Public API
33 /**
34 * rcar_fcp_get - Find and acquire a reference to an FCP instance
35 * @np: Device node of the FCP instance
37 * Search the list of registered FCP instances for the instance corresponding to
38 * the given device node.
40 * Return a pointer to the FCP instance, or an ERR_PTR if the instance can't be
41 * found.
43 struct rcar_fcp_device *rcar_fcp_get(const struct device_node *np)
45 struct rcar_fcp_device *fcp;
47 mutex_lock(&fcp_lock);
49 list_for_each_entry(fcp, &fcp_devices, list) {
50 if (fcp->dev->of_node != np)
51 continue;
53 get_device(fcp->dev);
54 goto done;
57 fcp = ERR_PTR(-EPROBE_DEFER);
59 done:
60 mutex_unlock(&fcp_lock);
61 return fcp;
63 EXPORT_SYMBOL_GPL(rcar_fcp_get);
65 /**
66 * rcar_fcp_put - Release a reference to an FCP instance
67 * @fcp: The FCP instance
69 * Release the FCP instance acquired by a call to rcar_fcp_get().
71 void rcar_fcp_put(struct rcar_fcp_device *fcp)
73 if (fcp)
74 put_device(fcp->dev);
76 EXPORT_SYMBOL_GPL(rcar_fcp_put);
78 struct device *rcar_fcp_get_device(struct rcar_fcp_device *fcp)
80 return fcp->dev;
82 EXPORT_SYMBOL_GPL(rcar_fcp_get_device);
84 /**
85 * rcar_fcp_enable - Enable an FCP
86 * @fcp: The FCP instance
88 * Before any memory access through an FCP is performed by a module, the FCP
89 * must be enabled by a call to this function. The enable calls are reference
90 * counted, each successful call must be followed by one rcar_fcp_disable()
91 * call when no more memory transfer can occur through the FCP.
93 * Return 0 on success or a negative error code if an error occurs. The enable
94 * reference count isn't increased when this function returns an error.
96 int rcar_fcp_enable(struct rcar_fcp_device *fcp)
98 int ret;
100 if (!fcp)
101 return 0;
103 ret = pm_runtime_get_sync(fcp->dev);
104 if (ret < 0)
105 return ret;
107 return 0;
109 EXPORT_SYMBOL_GPL(rcar_fcp_enable);
112 * rcar_fcp_disable - Disable an FCP
113 * @fcp: The FCP instance
115 * This function is the counterpart of rcar_fcp_enable(). As enable calls are
116 * reference counted a disable call may not disable the FCP synchronously.
118 void rcar_fcp_disable(struct rcar_fcp_device *fcp)
120 if (fcp)
121 pm_runtime_put(fcp->dev);
123 EXPORT_SYMBOL_GPL(rcar_fcp_disable);
125 /* -----------------------------------------------------------------------------
126 * Platform Driver
129 static int rcar_fcp_probe(struct platform_device *pdev)
131 struct rcar_fcp_device *fcp;
133 fcp = devm_kzalloc(&pdev->dev, sizeof(*fcp), GFP_KERNEL);
134 if (fcp == NULL)
135 return -ENOMEM;
137 fcp->dev = &pdev->dev;
139 pm_runtime_enable(&pdev->dev);
141 mutex_lock(&fcp_lock);
142 list_add_tail(&fcp->list, &fcp_devices);
143 mutex_unlock(&fcp_lock);
145 platform_set_drvdata(pdev, fcp);
147 return 0;
150 static int rcar_fcp_remove(struct platform_device *pdev)
152 struct rcar_fcp_device *fcp = platform_get_drvdata(pdev);
154 mutex_lock(&fcp_lock);
155 list_del(&fcp->list);
156 mutex_unlock(&fcp_lock);
158 pm_runtime_disable(&pdev->dev);
160 return 0;
163 static const struct of_device_id rcar_fcp_of_match[] = {
164 { .compatible = "renesas,fcpf" },
165 { .compatible = "renesas,fcpv" },
166 { },
168 MODULE_DEVICE_TABLE(of, rcar_fcp_of_match);
170 static struct platform_driver rcar_fcp_platform_driver = {
171 .probe = rcar_fcp_probe,
172 .remove = rcar_fcp_remove,
173 .driver = {
174 .name = "rcar-fcp",
175 .of_match_table = rcar_fcp_of_match,
176 .suppress_bind_attrs = true,
180 module_platform_driver(rcar_fcp_platform_driver);
182 MODULE_ALIAS("rcar-fcp");
183 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
184 MODULE_DESCRIPTION("Renesas FCP Driver");
185 MODULE_LICENSE("GPL");