.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * drivers/uio/uio_dmem_genirq.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * Copyright (C) 2012 Damian Hobson-Garcia |
---|
7 | 8 | * |
---|
8 | 9 | * Based on uio_pdrv_genirq.c by Magnus Damm |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or modify it |
---|
11 | | - * under the terms of the GNU General Public License version 2 as published by |
---|
12 | | - * the Free Software Foundation. |
---|
13 | 10 | */ |
---|
14 | 11 | |
---|
15 | 12 | #include <linux/platform_device.h> |
---|
.. | .. |
---|
23 | 20 | #include <linux/pm_runtime.h> |
---|
24 | 21 | #include <linux/dma-mapping.h> |
---|
25 | 22 | #include <linux/slab.h> |
---|
| 23 | +#include <linux/irq.h> |
---|
26 | 24 | |
---|
27 | 25 | #include <linux/of.h> |
---|
28 | 26 | #include <linux/of_platform.h> |
---|
.. | .. |
---|
47 | 45 | { |
---|
48 | 46 | struct uio_dmem_genirq_platdata *priv = info->priv; |
---|
49 | 47 | struct uio_mem *uiomem; |
---|
50 | | - int ret = 0; |
---|
51 | 48 | int dmem_region = priv->dmem_region_start; |
---|
52 | 49 | |
---|
53 | 50 | uiomem = &priv->uioinfo->mem[priv->dmem_region_start]; |
---|
.. | .. |
---|
71 | 68 | mutex_unlock(&priv->alloc_lock); |
---|
72 | 69 | /* Wait until the Runtime PM code has woken up the device */ |
---|
73 | 70 | pm_runtime_get_sync(&priv->pdev->dev); |
---|
74 | | - return ret; |
---|
| 71 | + return 0; |
---|
75 | 72 | } |
---|
76 | 73 | |
---|
77 | 74 | static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode) |
---|
.. | .. |
---|
156 | 153 | int i; |
---|
157 | 154 | |
---|
158 | 155 | if (pdev->dev.of_node) { |
---|
159 | | - int irq; |
---|
160 | | - |
---|
161 | 156 | /* alloc uioinfo for one device */ |
---|
162 | 157 | uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL); |
---|
163 | 158 | if (!uioinfo) { |
---|
.. | .. |
---|
165 | 160 | dev_err(&pdev->dev, "unable to kmalloc\n"); |
---|
166 | 161 | goto bad2; |
---|
167 | 162 | } |
---|
168 | | - uioinfo->name = pdev->dev.of_node->name; |
---|
| 163 | + uioinfo->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn", |
---|
| 164 | + pdev->dev.of_node); |
---|
169 | 165 | uioinfo->version = "devicetree"; |
---|
170 | | - |
---|
171 | | - /* Multiple IRQs are not supported */ |
---|
172 | | - irq = platform_get_irq(pdev, 0); |
---|
173 | | - if (irq == -ENXIO) |
---|
174 | | - uioinfo->irq = UIO_IRQ_NONE; |
---|
175 | | - else |
---|
176 | | - uioinfo->irq = irq; |
---|
177 | 166 | } |
---|
178 | 167 | |
---|
179 | 168 | if (!uioinfo || !uioinfo->name || !uioinfo->version) { |
---|
.. | .. |
---|
203 | 192 | mutex_init(&priv->alloc_lock); |
---|
204 | 193 | |
---|
205 | 194 | if (!uioinfo->irq) { |
---|
| 195 | + /* Multiple IRQs are not supported */ |
---|
206 | 196 | ret = platform_get_irq(pdev, 0); |
---|
207 | | - if (ret < 0) { |
---|
208 | | - dev_err(&pdev->dev, "failed to get IRQ\n"); |
---|
| 197 | + if (ret == -ENXIO && pdev->dev.of_node) |
---|
| 198 | + ret = UIO_IRQ_NONE; |
---|
| 199 | + else if (ret < 0) |
---|
209 | 200 | goto bad1; |
---|
210 | | - } |
---|
211 | 201 | uioinfo->irq = ret; |
---|
212 | 202 | } |
---|
| 203 | + |
---|
| 204 | + if (uioinfo->irq) { |
---|
| 205 | + struct irq_data *irq_data = irq_get_irq_data(uioinfo->irq); |
---|
| 206 | + |
---|
| 207 | + /* |
---|
| 208 | + * If a level interrupt, dont do lazy disable. Otherwise the |
---|
| 209 | + * irq will fire again since clearing of the actual cause, on |
---|
| 210 | + * device level, is done in userspace |
---|
| 211 | + * irqd_is_level_type() isn't used since isn't valid until |
---|
| 212 | + * irq is configured. |
---|
| 213 | + */ |
---|
| 214 | + if (irq_data && |
---|
| 215 | + irqd_get_trigger_type(irq_data) & IRQ_TYPE_LEVEL_MASK) { |
---|
| 216 | + dev_dbg(&pdev->dev, "disable lazy unmask\n"); |
---|
| 217 | + irq_set_status_flags(uioinfo->irq, IRQ_DISABLE_UNLAZY); |
---|
| 218 | + } |
---|
| 219 | + } |
---|
| 220 | + |
---|
213 | 221 | uiomem = &uioinfo->mem[0]; |
---|
214 | 222 | |
---|
215 | 223 | for (i = 0; i < pdev->num_resources; ++i) { |
---|