7a44a7cc6535acfa1d8a913773e111d8a47f0673
[openwrt/openwrt.git] / target / linux / brcm63xx / patches-4.4 / 000-4.5-30-gpio-add-a-data-pointer-to-gpio_chip.patch
1 From b08ea35a3296ee25c4cb53a977b752266dafa2c2 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Thu, 3 Dec 2015 15:14:13 +0100
4 Subject: [PATCH] gpio: add a data pointer to gpio_chip
5
6 This adds a void * pointer to gpio_chip so that driver can
7 assign and retrieve some states. This is done to get rid of
8 container_of() calls for gpio_chips embedded inside state
9 containers, so we can remove the need to have the gpio_chip
10 or later (planned) struct gpio_device be dynamically allocated
11 at registration time, so that its struct device can be properly
12 reference counted and not bound to its parent device (e.g.
13 a platform_device) but instead live on after unregistration
14 if it is opened by e.g. a char device or sysfs.
15
16 The data is added with the new function gpiochip_add_data()
17 and for compatibility we add static inline wrapper function
18 gpiochip_add() that will call gpiochip_add_data() with
19 NULL as argument. The latter will be removed once we have
20 exorcised gpiochip_add() from the kernel.
21
22 gpiochip_get_data() is added as a static inline accessor
23 for drivers to quickly get their data out.
24
25 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
26 ---
27 drivers/gpio/gpiolib.c | 10 ++++++----
28 include/linux/gpio/driver.h | 14 +++++++++++++-
29 2 files changed, 19 insertions(+), 5 deletions(-)
30
31 --- a/drivers/gpio/gpiolib.c
32 +++ b/drivers/gpio/gpiolib.c
33 @@ -280,7 +280,7 @@ static int gpiochip_set_desc_names(struc
34 }
35
36 /**
37 - * gpiochip_add() - register a gpio_chip
38 + * gpiochip_add_data() - register a gpio_chip
39 * @chip: the chip to register, with chip->base initialized
40 * Context: potentially before irqs will work
41 *
42 @@ -288,7 +288,7 @@ static int gpiochip_set_desc_names(struc
43 * because the chip->base is invalid or already associated with a
44 * different chip. Otherwise it returns zero as a success code.
45 *
46 - * When gpiochip_add() is called very early during boot, so that GPIOs
47 + * When gpiochip_add_data() is called very early during boot, so that GPIOs
48 * can be freely used, the chip->dev device must be registered before
49 * the gpio framework's arch_initcall(). Otherwise sysfs initialization
50 * for GPIOs will fail rudely.
51 @@ -296,7 +296,7 @@ static int gpiochip_set_desc_names(struc
52 * If chip->base is negative, this requests dynamic assignment of
53 * a range of valid GPIOs.
54 */
55 -int gpiochip_add(struct gpio_chip *chip)
56 +int gpiochip_add_data(struct gpio_chip *chip, void *data)
57 {
58 unsigned long flags;
59 int status = 0;
60 @@ -308,6 +308,8 @@ int gpiochip_add(struct gpio_chip *chip)
61 if (!descs)
62 return -ENOMEM;
63
64 + chip->data = data;
65 +
66 spin_lock_irqsave(&gpio_lock, flags);
67
68 if (base < 0) {
69 @@ -389,7 +391,7 @@ err_free_descs:
70 chip->label ? : "generic");
71 return status;
72 }
73 -EXPORT_SYMBOL_GPL(gpiochip_add);
74 +EXPORT_SYMBOL_GPL(gpiochip_add_data);
75
76 /**
77 * gpiochip_remove() - unregister a gpio_chip
78 --- a/include/linux/gpio/driver.h
79 +++ b/include/linux/gpio/driver.h
80 @@ -23,6 +23,7 @@ struct seq_file;
81 * @dev: optional device providing the GPIOs
82 * @cdev: class device used by sysfs interface (may be NULL)
83 * @owner: helps prevent removal of modules exporting active GPIOs
84 + * @data: per-instance data assigned by the driver
85 * @list: links gpio_chips together for traversal
86 * @request: optional hook for chip-specific activation, such as
87 * enabling module power and clock; may sleep
88 @@ -92,6 +93,7 @@ struct gpio_chip {
89 struct device *dev;
90 struct device *cdev;
91 struct module *owner;
92 + void *data;
93 struct list_head list;
94
95 int (*request)(struct gpio_chip *chip,
96 @@ -166,7 +168,11 @@ extern const char *gpiochip_is_requested
97 unsigned offset);
98
99 /* add/remove chips */
100 -extern int gpiochip_add(struct gpio_chip *chip);
101 +extern int gpiochip_add_data(struct gpio_chip *chip, void *data);
102 +static inline int gpiochip_add(struct gpio_chip *chip)
103 +{
104 + return gpiochip_add_data(chip, NULL);
105 +}
106 extern void gpiochip_remove(struct gpio_chip *chip);
107 extern struct gpio_chip *gpiochip_find(void *data,
108 int (*match)(struct gpio_chip *chip, void *data));
109 @@ -175,6 +181,12 @@ extern struct gpio_chip *gpiochip_find(v
110 int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset);
111 void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
112
113 +/* get driver data */
114 +static inline void *gpiochip_get_data(struct gpio_chip *chip)
115 +{
116 + return chip->data;
117 +}
118 +
119 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
120
121 #ifdef CONFIG_GPIOLIB_IRQCHIP