bcm27xx: update 6.1 patches to latest version
[openwrt/staging/dangole.git] / target / linux / bcm27xx / patches-6.1 / 950-0909-drivers-char-delete-bcm2835-gpiomem.patch
1 From 27bda80061b46e18fe83be11228df5365363b377 Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Wed, 26 Apr 2023 13:44:15 +0100
4 Subject: [PATCH] drivers: char: delete bcm2835-gpiomem
5
6 This functionality is now provided by raspberrypi-gpiomem.
7
8 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
9 ---
10 drivers/char/broadcom/Kconfig | 8 -
11 drivers/char/broadcom/Makefile | 1 -
12 drivers/char/broadcom/bcm2835-gpiomem.c | 258 ------------------------
13 3 files changed, 267 deletions(-)
14 delete mode 100644 drivers/char/broadcom/bcm2835-gpiomem.c
15
16 --- a/drivers/char/broadcom/Kconfig
17 +++ b/drivers/char/broadcom/Kconfig
18 @@ -23,14 +23,6 @@ config BCM_VCIO
19
20 endif
21
22 -config BCM2835_DEVGPIOMEM
23 - tristate "/dev/gpiomem rootless GPIO access via mmap() on the BCM2835"
24 - default m
25 - help
26 - Provides users with root-free access to the GPIO registers
27 - on the 2835. Calling mmap(/dev/gpiomem) will map the GPIO
28 - register page to the user's pointer.
29 -
30 config BCM2835_SMI_DEV
31 tristate "Character device driver for BCM2835 Secondary Memory Interface"
32 depends on BCM2835_SMI
33 --- a/drivers/char/broadcom/Makefile
34 +++ b/drivers/char/broadcom/Makefile
35 @@ -1,5 +1,4 @@
36 obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
37 obj-$(CONFIG_BCM_VCIO) += vcio.o
38 -obj-$(CONFIG_BCM2835_DEVGPIOMEM)+= bcm2835-gpiomem.o
39 obj-$(CONFIG_BCM2835_SMI_DEV) += bcm2835_smi_dev.o
40 obj-$(CONFIG_RPIVID_MEM) += rpivid-mem.o
41 --- a/drivers/char/broadcom/bcm2835-gpiomem.c
42 +++ /dev/null
43 @@ -1,258 +0,0 @@
44 -/**
45 - * GPIO memory device driver
46 - *
47 - * Creates a chardev /dev/gpiomem which will provide user access to
48 - * the BCM2835's GPIO registers when it is mmap()'d.
49 - * No longer need root for user GPIO access, but without relaxing permissions
50 - * on /dev/mem.
51 - *
52 - * Written by Luke Wren <luke@raspberrypi.org>
53 - * Copyright (c) 2015, Raspberry Pi (Trading) Ltd.
54 - *
55 - * Redistribution and use in source and binary forms, with or without
56 - * modification, are permitted provided that the following conditions
57 - * are met:
58 - * 1. Redistributions of source code must retain the above copyright
59 - * notice, this list of conditions, and the following disclaimer,
60 - * without modification.
61 - * 2. Redistributions in binary form must reproduce the above copyright
62 - * notice, this list of conditions and the following disclaimer in the
63 - * documentation and/or other materials provided with the distribution.
64 - * 3. The names of the above-listed copyright holders may not be used
65 - * to endorse or promote products derived from this software without
66 - * specific prior written permission.
67 - *
68 - * ALTERNATIVELY, this software may be distributed under the terms of the
69 - * GNU General Public License ("GPL") version 2, as published by the Free
70 - * Software Foundation.
71 - *
72 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
73 - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
74 - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
75 - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
76 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
77 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
78 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
79 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
80 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
81 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
82 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 - */
84 -
85 -#include <linux/kernel.h>
86 -#include <linux/module.h>
87 -#include <linux/of.h>
88 -#include <linux/platform_device.h>
89 -#include <linux/mm.h>
90 -#include <linux/slab.h>
91 -#include <linux/cdev.h>
92 -#include <linux/pagemap.h>
93 -#include <linux/io.h>
94 -
95 -#define DEVICE_NAME "bcm2835-gpiomem"
96 -#define DRIVER_NAME "gpiomem-bcm2835"
97 -#define DEVICE_MINOR 0
98 -
99 -struct bcm2835_gpiomem_instance {
100 - unsigned long gpio_regs_phys;
101 - struct device *dev;
102 -};
103 -
104 -static struct cdev bcm2835_gpiomem_cdev;
105 -static dev_t bcm2835_gpiomem_devid;
106 -static struct class *bcm2835_gpiomem_class;
107 -static struct device *bcm2835_gpiomem_dev;
108 -static struct bcm2835_gpiomem_instance *inst;
109 -
110 -
111 -/****************************************************************************
112 -*
113 -* GPIO mem chardev file ops
114 -*
115 -***************************************************************************/
116 -
117 -static int bcm2835_gpiomem_open(struct inode *inode, struct file *file)
118 -{
119 - int dev = iminor(inode);
120 - int ret = 0;
121 -
122 - if (dev != DEVICE_MINOR) {
123 - dev_err(inst->dev, "Unknown minor device: %d", dev);
124 - ret = -ENXIO;
125 - }
126 - return ret;
127 -}
128 -
129 -static int bcm2835_gpiomem_release(struct inode *inode, struct file *file)
130 -{
131 - int dev = iminor(inode);
132 - int ret = 0;
133 -
134 - if (dev != DEVICE_MINOR) {
135 - dev_err(inst->dev, "Unknown minor device %d", dev);
136 - ret = -ENXIO;
137 - }
138 - return ret;
139 -}
140 -
141 -static const struct vm_operations_struct bcm2835_gpiomem_vm_ops = {
142 -#ifdef CONFIG_HAVE_IOREMAP_PROT
143 - .access = generic_access_phys
144 -#endif
145 -};
146 -
147 -static int bcm2835_gpiomem_mmap(struct file *file, struct vm_area_struct *vma)
148 -{
149 - /* Ignore what the user says - they're getting the GPIO regs
150 - whether they like it or not! */
151 - unsigned long gpio_page = inst->gpio_regs_phys >> PAGE_SHIFT;
152 -
153 - vma->vm_page_prot = phys_mem_access_prot(file, gpio_page,
154 - PAGE_SIZE,
155 - vma->vm_page_prot);
156 - vma->vm_ops = &bcm2835_gpiomem_vm_ops;
157 - if (remap_pfn_range(vma, vma->vm_start,
158 - gpio_page,
159 - PAGE_SIZE,
160 - vma->vm_page_prot)) {
161 - return -EAGAIN;
162 - }
163 - return 0;
164 -}
165 -
166 -static const struct file_operations
167 -bcm2835_gpiomem_fops = {
168 - .owner = THIS_MODULE,
169 - .open = bcm2835_gpiomem_open,
170 - .release = bcm2835_gpiomem_release,
171 - .mmap = bcm2835_gpiomem_mmap,
172 -};
173 -
174 -
175 - /****************************************************************************
176 -*
177 -* Probe and remove functions
178 -*
179 -***************************************************************************/
180 -
181 -
182 -static int bcm2835_gpiomem_probe(struct platform_device *pdev)
183 -{
184 - int err;
185 - void *ptr_err;
186 - struct device *dev = &pdev->dev;
187 - struct resource *ioresource;
188 -
189 - /* Allocate buffers and instance data */
190 -
191 - inst = kzalloc(sizeof(struct bcm2835_gpiomem_instance), GFP_KERNEL);
192 -
193 - if (!inst) {
194 - err = -ENOMEM;
195 - goto failed_inst_alloc;
196 - }
197 -
198 - inst->dev = dev;
199 -
200 - ioresource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
201 - if (ioresource) {
202 - inst->gpio_regs_phys = ioresource->start;
203 - } else {
204 - dev_err(inst->dev, "failed to get IO resource");
205 - err = -ENOENT;
206 - goto failed_get_resource;
207 - }
208 -
209 - /* Create character device entries */
210 -
211 - err = alloc_chrdev_region(&bcm2835_gpiomem_devid,
212 - DEVICE_MINOR, 1, DEVICE_NAME);
213 - if (err != 0) {
214 - dev_err(inst->dev, "unable to allocate device number");
215 - goto failed_alloc_chrdev;
216 - }
217 - cdev_init(&bcm2835_gpiomem_cdev, &bcm2835_gpiomem_fops);
218 - bcm2835_gpiomem_cdev.owner = THIS_MODULE;
219 - err = cdev_add(&bcm2835_gpiomem_cdev, bcm2835_gpiomem_devid, 1);
220 - if (err != 0) {
221 - dev_err(inst->dev, "unable to register device");
222 - goto failed_cdev_add;
223 - }
224 -
225 - /* Create sysfs entries */
226 -
227 - bcm2835_gpiomem_class = class_create(THIS_MODULE, DEVICE_NAME);
228 - ptr_err = bcm2835_gpiomem_class;
229 - if (IS_ERR(ptr_err))
230 - goto failed_class_create;
231 -
232 - bcm2835_gpiomem_dev = device_create(bcm2835_gpiomem_class, NULL,
233 - bcm2835_gpiomem_devid, NULL,
234 - "gpiomem");
235 - ptr_err = bcm2835_gpiomem_dev;
236 - if (IS_ERR(ptr_err))
237 - goto failed_device_create;
238 -
239 - dev_info(inst->dev, "Initialised: Registers at 0x%08lx",
240 - inst->gpio_regs_phys);
241 -
242 - return 0;
243 -
244 -failed_device_create:
245 - class_destroy(bcm2835_gpiomem_class);
246 -failed_class_create:
247 - cdev_del(&bcm2835_gpiomem_cdev);
248 - err = PTR_ERR(ptr_err);
249 -failed_cdev_add:
250 - unregister_chrdev_region(bcm2835_gpiomem_devid, 1);
251 -failed_alloc_chrdev:
252 -failed_get_resource:
253 - kfree(inst);
254 -failed_inst_alloc:
255 - dev_err(inst->dev, "could not load bcm2835_gpiomem");
256 - return err;
257 -}
258 -
259 -static int bcm2835_gpiomem_remove(struct platform_device *pdev)
260 -{
261 - struct device *dev = inst->dev;
262 -
263 - kfree(inst);
264 - device_destroy(bcm2835_gpiomem_class, bcm2835_gpiomem_devid);
265 - class_destroy(bcm2835_gpiomem_class);
266 - cdev_del(&bcm2835_gpiomem_cdev);
267 - unregister_chrdev_region(bcm2835_gpiomem_devid, 1);
268 -
269 - dev_info(dev, "GPIO mem driver removed - OK");
270 - return 0;
271 -}
272 -
273 - /****************************************************************************
274 -*
275 -* Register the driver with device tree
276 -*
277 -***************************************************************************/
278 -
279 -static const struct of_device_id bcm2835_gpiomem_of_match[] = {
280 - {.compatible = "brcm,bcm2835-gpiomem",},
281 - { /* sentinel */ },
282 -};
283 -
284 -MODULE_DEVICE_TABLE(of, bcm2835_gpiomem_of_match);
285 -
286 -static struct platform_driver bcm2835_gpiomem_driver = {
287 - .probe = bcm2835_gpiomem_probe,
288 - .remove = bcm2835_gpiomem_remove,
289 - .driver = {
290 - .name = DRIVER_NAME,
291 - .owner = THIS_MODULE,
292 - .of_match_table = bcm2835_gpiomem_of_match,
293 - },
294 -};
295 -
296 -module_platform_driver(bcm2835_gpiomem_driver);
297 -
298 -MODULE_ALIAS("platform:gpiomem-bcm2835");
299 -MODULE_LICENSE("GPL");
300 -MODULE_DESCRIPTION("gpiomem driver for accessing GPIO from userspace");
301 -MODULE_AUTHOR("Luke Wren <luke@raspberrypi.org>");