[lantiq] bump kernel to 3.2.12
[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 diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
19 index 4e018d6..76dbd3f 100644
20 --- a/drivers/gpio/Makefile
21 +++ b/drivers/gpio/Makefile
22 @@ -2,7 +2,7 @@
23
24 ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
25
26 -obj-$(CONFIG_GPIOLIB) += gpiolib.o
27 +obj-$(CONFIG_GPIOLIB) += gpiolib.o devres.o
28
29 # Device drivers. Generally keep list sorted alphabetically
30 obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o
31 diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
32 new file mode 100644
33 index 0000000..3dd2939
34 --- /dev/null
35 +++ b/drivers/gpio/devres.c
36 @@ -0,0 +1,90 @@
37 +/*
38 + * drivers/gpio/devres.c - managed gpio resources
39 + *
40 + * This program is free software; you can redistribute it and/or modify
41 + * it under the terms of the GNU General Public License version 2
42 + * as published by the Free Software Foundation.
43 + *
44 + * You should have received a copy of the GNU General Public License
45 + * along with this program; if not, write to the Free Software
46 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 + *
48 + * This file is based on kernel/irq/devres.c
49 + *
50 + * Copyright (c) 2011 John Crispin <blogic@openwrt.org>
51 + */
52 +
53 +#include <linux/module.h>
54 +#include <linux/gpio.h>
55 +#include <linux/device.h>
56 +#include <linux/gfp.h>
57 +
58 +static void devm_gpio_release(struct device *dev, void *res)
59 +{
60 + unsigned *gpio = res;
61 +
62 + gpio_free(*gpio);
63 +}
64 +
65 +static int devm_gpio_match(struct device *dev, void *res, void *data)
66 +{
67 + unsigned *this = res, *gpio = data;
68 +
69 + return *this == *gpio;
70 +}
71 +
72 +/**
73 + * devm_gpio_request - request a gpio for a managed device
74 + * @dev: device to request the gpio for
75 + * @gpio: gpio to allocate
76 + * @label: the name of the requested gpio
77 + *
78 + * Except for the extra @dev argument, this function takes the
79 + * same arguments and performs the same function as
80 + * gpio_request(). GPIOs requested with this function will be
81 + * automatically freed on driver detach.
82 + *
83 + * If an GPIO allocated with this function needs to be freed
84 + * separately, devm_gpio_free() must be used.
85 + */
86 +
87 +int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)
88 +{
89 + unsigned *dr;
90 + int rc;
91 +
92 + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL);
93 + if (!dr)
94 + return -ENOMEM;
95 +
96 + rc = gpio_request(gpio, label);
97 + if (rc) {
98 + devres_free(dr);
99 + return rc;
100 + }
101 +
102 + *dr = gpio;
103 + devres_add(dev, dr);
104 +
105 + return 0;
106 +}
107 +EXPORT_SYMBOL(devm_gpio_request);
108 +
109 +/**
110 + * devm_gpio_free - free an interrupt
111 + * @dev: device to free gpio for
112 + * @gpio: gpio to free
113 + *
114 + * Except for the extra @dev argument, this function takes the
115 + * same arguments and performs the same function as gpio_free().
116 + * This function instead of gpio_free() should be used to manually
117 + * free GPIOs allocated with devm_gpio_request().
118 + */
119 +void devm_gpio_free(struct device *dev, unsigned int gpio)
120 +{
121 +
122 + WARN_ON(devres_destroy(dev, devm_gpio_release, devm_gpio_match,
123 + &gpio));
124 + gpio_free(gpio);
125 +}
126 +EXPORT_SYMBOL(devm_gpio_free);
127 diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
128 index 8c86210..8601a02 100644
129 --- a/include/asm-generic/gpio.h
130 +++ b/include/asm-generic/gpio.h
131 @@ -175,6 +175,10 @@ extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *labe
132 extern int gpio_request_array(const struct gpio *array, size_t num);
133 extern void gpio_free_array(const struct gpio *array, size_t num);
134
135 +/* bindings for managed devices that want to request gpios */
136 +int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
137 +void devm_gpio_free(struct device *dev, unsigned int gpio);
138 +
139 #ifdef CONFIG_GPIO_SYSFS
140
141 /*
142 --
143 1.7.7.1
144