kernel: update linux 3.2 to 3.2.13 and refresh patches
[openwrt/svn-archive/archive.git] / target / linux / lantiq / patches-3.2 / 0001-GPIO-add-bindings-for-managed-devices.patch
1 From 282f1ca84b35f3be68abc4fd8b52e229f3cb6bb7 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 8 Mar 2012 13:23:53 +0100
4 Subject: [PATCH 01/70] GPIO: add bindings for managed devices
5
6 This patch adds 2 functions that allow managed devices to request GPIOs.
7 These GPIOs will then be managed by drivers/base/devres.c.
8
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
11 ---
12 drivers/gpio/Makefile | 2 +-
13 drivers/gpio/devres.c | 90 ++++++++++++++++++++++++++++++++++++++++++++
14 include/asm-generic/gpio.h | 4 ++
15 3 files changed, 95 insertions(+), 1 deletions(-)
16 create mode 100644 drivers/gpio/devres.c
17
18 --- a/drivers/gpio/Makefile
19 +++ b/drivers/gpio/Makefile
20 @@ -2,7 +2,7 @@
21
22 ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
23
24 -obj-$(CONFIG_GPIOLIB) += gpiolib.o
25 +obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o
26
27 # Device drivers. Generally keep list sorted alphabetically
28 obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o
29 --- /dev/null
30 +++ b/drivers/gpio/devres.c
31 @@ -0,0 +1,90 @@
32 +/*
33 + * drivers/gpio/devres.c - managed gpio resources
34 + *
35 + * This program is free software; you can redistribute it and/or modify
36 + * it under the terms of the GNU General Public License version 2
37 + * as published by the Free Software Foundation.
38 + *
39 + * You should have received a copy of the GNU General Public License
40 + * along with this program; if not, write to the Free Software
41 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 + *
43 + * This file is based on kernel/irq/devres.c
44 + *
45 + * Copyright (c) 2011 John Crispin <blogic@openwrt.org>
46 + */
47 +
48 +#include <linux/module.h>
49 +#include <linux/gpio.h>
50 +#include <linux/device.h>
51 +#include <linux/gfp.h>
52 +
53 +static void devm_gpio_release(struct device *dev, void *res)
54 +{
55 + unsigned *gpio = res;
56 +
57 + gpio_free(*gpio);
58 +}
59 +
60 +static int devm_gpio_match(struct device *dev, void *res, void *data)
61 +{
62 + unsigned *this = res, *gpio = data;
63 +
64 + return *this == *gpio;
65 +}
66 +
67 +/**
68 + * devm_gpio_request - request a gpio for a managed device
69 + * @dev: device to request the gpio for
70 + * @gpio: gpio to allocate
71 + * @label: the name of the requested gpio
72 + *
73 + * Except for the extra @dev argument, this function takes the
74 + * same arguments and performs the same function as
75 + * gpio_request(). GPIOs requested with this function will be
76 + * automatically freed on driver detach.
77 + *
78 + * If an GPIO allocated with this function needs to be freed
79 + * separately, devm_gpio_free() must be used.
80 + */
81 +
82 +int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)
83 +{
84 + unsigned *dr;
85 + int rc;
86 +
87 + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
88 + if (!dr)
89 + return -ENOMEM;
90 +
91 + rc = gpio_request(gpio, label);
92 + if (rc) {
93 + devres_free(dr);
94 + return rc;
95 + }
96 +
97 + *dr = gpio;
98 + devres_add(dev, dr);
99 +
100 + return 0;
101 +}
102 +EXPORT_SYMBOL(devm_gpio_request);
103 +
104 +/**
105 + * devm_gpio_free - free an interrupt
106 + * @dev: device to free gpio for
107 + * @gpio: gpio to free
108 + *
109 + * Except for the extra @dev argument, this function takes the
110 + * same arguments and performs the same function as gpio_free().
111 + * This function instead of gpio_free() should be used to manually
112 + * free GPIOs allocated with devm_gpio_request().
113 + */
114 +void devm_gpio_free(struct device *dev, unsigned int gpio)
115 +{
116 +
117 + WARN_ON(devres_destroy(dev, devm_gpio_release, devm_gpio_match,
118 + &gpio));
119 + gpio_free(gpio);
120 +}
121 +EXPORT_SYMBOL(devm_gpio_free);
122 --- a/include/asm-generic/gpio.h
123 +++ b/include/asm-generic/gpio.h
124 @@ -175,6 +175,10 @@ extern int gpio_request_one(unsigned gpi
125 extern int gpio_request_array(const struct gpio *array, size_t num);
126 extern void gpio_free_array(const struct gpio *array, size_t num);
127
128 +/* bindings for managed devices that want to request gpios */
129 +int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
130 +void devm_gpio_free(struct device *dev, unsigned int gpio);
131 +
132 #ifdef CONFIG_GPIO_SYSFS
133
134 /*