kernel: update 3.18 to 3.18.1
[openwrt.git] / target / linux / generic / patches-3.3 / 070-gpio-add-flags-to-export-GPIOs-when-requesting.patch
1 From fc3a1f04f5040255cbc086c419e4237f29f89f88 Mon Sep 17 00:00:00 2001
2 From: Wolfram Sang <w.sang@pengutronix.de>
3 Date: Tue, 13 Dec 2011 18:34:01 +0100
4 Subject: [PATCH] gpio: add flags to export GPIOs when requesting
5
6 commit fc3a1f04f5040255cbc086c419e4237f29f89f88 upstream.
7
8 Introduce new flags to automatically export GPIOs when using the convenience
9 functions gpio_request_one() or gpio_request_array(). This eases support for
10 custom boards where lots of GPIOs need to be exported for customer
11 applications.
12
13 Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
14 Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
15 ---
16  Documentation/gpio.txt |    3 +++
17  drivers/gpio/gpiolib.c |   12 +++++++++++-
18  include/linux/gpio.h   |    5 +++++
19  3 files changed, 19 insertions(+), 1 deletion(-)
20
21 --- a/Documentation/gpio.txt
22 +++ b/Documentation/gpio.txt
23 @@ -303,6 +303,9 @@ where 'flags' is currently defined to sp
24         * GPIOF_INIT_LOW        - as output, set initial level to LOW
25         * GPIOF_INIT_HIGH       - as output, set initial level to HIGH
26  
27 +       * GPIOF_EXPORT_DIR_FIXED        - export gpio to sysfs, keep direction
28 +       * GPIOF_EXPORT_DIR_CHANGEABLE   - also export, allow changing direction
29 +
30  since GPIOF_INIT_* are only valid when configured as output, so group valid
31  combinations as:
32  
33 --- a/drivers/gpio/gpiolib.c
34 +++ b/drivers/gpio/gpiolib.c
35 @@ -1289,8 +1289,18 @@ int gpio_request_one(unsigned gpio, unsi
36                                 (flags & GPIOF_INIT_HIGH) ? 1 : 0);
37  
38         if (err)
39 -               gpio_free(gpio);
40 +               goto free_gpio;
41  
42 +       if (flags & GPIOF_EXPORT) {
43 +               err = gpio_export(gpio, flags & GPIOF_EXPORT_CHANGEABLE);
44 +               if (err)
45 +                       goto free_gpio;
46 +       }
47 +
48 +       return 0;
49 +
50 + free_gpio:
51 +       gpio_free(gpio);
52         return err;
53  }
54  EXPORT_SYMBOL_GPL(gpio_request_one);
55 --- a/include/linux/gpio.h
56 +++ b/include/linux/gpio.h
57 @@ -14,6 +14,11 @@
58  #define GPIOF_OUT_INIT_LOW     (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
59  #define GPIOF_OUT_INIT_HIGH    (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
60  
61 +#define GPIOF_EXPORT           (1 << 2)
62 +#define GPIOF_EXPORT_CHANGEABLE        (1 << 3)
63 +#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
64 +#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
65 +
66  /**
67   * struct gpio - a structure describing a GPIO with configuration
68   * @gpio:      the GPIO number