2 * rcar-fcp.c -- R-Car Frame Compression Processor Driver
4 * Copyright (C) 2016 Renesas Electronics Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/device.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/list.h>
17 #include <linux/module.h>
18 #include <linux/mutex.h>
19 #include <linux/platform_device.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/slab.h>
23 #include <media/rcar-fcp.h>
25 struct rcar_fcp_device {
26 struct list_head list;
28 struct device_dma_parameters dma_parms;
31 static LIST_HEAD(fcp_devices);
32 static DEFINE_MUTEX(fcp_lock);
34 /* -----------------------------------------------------------------------------
39 * rcar_fcp_get - Find and acquire a reference to an FCP instance
40 * @np: Device node of the FCP instance
42 * Search the list of registered FCP instances for the instance corresponding to
43 * the given device node.
45 * Return a pointer to the FCP instance, or an ERR_PTR if the instance can't be
48 struct rcar_fcp_device *rcar_fcp_get(const struct device_node *np)
50 struct rcar_fcp_device *fcp;
52 mutex_lock(&fcp_lock);
54 list_for_each_entry(fcp, &fcp_devices, list) {
55 if (fcp->dev->of_node != np)
62 fcp = ERR_PTR(-EPROBE_DEFER);
65 mutex_unlock(&fcp_lock);
68 EXPORT_SYMBOL_GPL(rcar_fcp_get);
71 * rcar_fcp_put - Release a reference to an FCP instance
72 * @fcp: The FCP instance
74 * Release the FCP instance acquired by a call to rcar_fcp_get().
76 void rcar_fcp_put(struct rcar_fcp_device *fcp)
81 EXPORT_SYMBOL_GPL(rcar_fcp_put);
83 struct device *rcar_fcp_get_device(struct rcar_fcp_device *fcp)
87 EXPORT_SYMBOL_GPL(rcar_fcp_get_device);
90 * rcar_fcp_enable - Enable an FCP
91 * @fcp: The FCP instance
93 * Before any memory access through an FCP is performed by a module, the FCP
94 * must be enabled by a call to this function. The enable calls are reference
95 * counted, each successful call must be followed by one rcar_fcp_disable()
96 * call when no more memory transfer can occur through the FCP.
98 * Return 0 on success or a negative error code if an error occurs. The enable
99 * reference count isn't increased when this function returns an error.
101 int rcar_fcp_enable(struct rcar_fcp_device *fcp)
108 ret = pm_runtime_get_sync(fcp->dev);
110 pm_runtime_put_noidle(fcp->dev);
116 EXPORT_SYMBOL_GPL(rcar_fcp_enable);
119 * rcar_fcp_disable - Disable an FCP
120 * @fcp: The FCP instance
122 * This function is the counterpart of rcar_fcp_enable(). As enable calls are
123 * reference counted a disable call may not disable the FCP synchronously.
125 void rcar_fcp_disable(struct rcar_fcp_device *fcp)
128 pm_runtime_put(fcp->dev);
130 EXPORT_SYMBOL_GPL(rcar_fcp_disable);
132 /* -----------------------------------------------------------------------------
136 static int rcar_fcp_probe(struct platform_device *pdev)
138 struct rcar_fcp_device *fcp;
140 fcp = devm_kzalloc(&pdev->dev, sizeof(*fcp), GFP_KERNEL);
144 fcp->dev = &pdev->dev;
146 fcp->dev->dma_parms = &fcp->dma_parms;
147 dma_set_max_seg_size(fcp->dev, DMA_BIT_MASK(32));
149 pm_runtime_enable(&pdev->dev);
151 mutex_lock(&fcp_lock);
152 list_add_tail(&fcp->list, &fcp_devices);
153 mutex_unlock(&fcp_lock);
155 platform_set_drvdata(pdev, fcp);
160 static int rcar_fcp_remove(struct platform_device *pdev)
162 struct rcar_fcp_device *fcp = platform_get_drvdata(pdev);
164 mutex_lock(&fcp_lock);
165 list_del(&fcp->list);
166 mutex_unlock(&fcp_lock);
168 pm_runtime_disable(&pdev->dev);
173 static const struct of_device_id rcar_fcp_of_match[] = {
174 { .compatible = "renesas,fcpf" },
175 { .compatible = "renesas,fcpv" },
178 MODULE_DEVICE_TABLE(of, rcar_fcp_of_match);
180 static struct platform_driver rcar_fcp_platform_driver = {
181 .probe = rcar_fcp_probe,
182 .remove = rcar_fcp_remove,
185 .of_match_table = rcar_fcp_of_match,
186 .suppress_bind_attrs = true,
190 module_platform_driver(rcar_fcp_platform_driver);
192 MODULE_ALIAS("rcar-fcp");
193 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
194 MODULE_DESCRIPTION("Renesas FCP Driver");
195 MODULE_LICENSE("GPL");