1 From: Anton Vorontsov <avorontsov@ru.mvista.com>
2 Date: Mon, 28 Apr 2008 09:14:47 +0000 (-0700)
3 Subject: gpiochip_reserve()
4 X-Git-Tag: v2.6.26-rc1~847
5 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=169b6a7a6e91e1ea32136681b475cbaf2074bf35
9 Add a new function gpiochip_reserve() to reserve ranges of gpios that platform
10 code has pre-allocated. That is, this marks gpio numbers which will be
11 claimed by drivers that haven't yet been loaded, and thus are not available
12 for dynamic gpio number allocation.
14 [akpm@linux-foundation.org: remove unneeded __must_check]
15 [david-b@pacbell.net: don't export gpiochip_reserve (section fix)]
16 Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
17 Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
18 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
19 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
22 --- a/drivers/gpio/gpiolib.c
23 +++ b/drivers/gpio/gpiolib.c
25 /* flag symbols are bit numbers */
26 #define FLAG_REQUESTED 0
28 +#define FLAG_RESERVED 2
30 #ifdef CONFIG_DEBUG_FS
35 for (i = ARCH_NR_GPIOS - 1; i >= 0 ; i--) {
36 - struct gpio_chip *chip = gpio_desc[i].chip;
37 + struct gpio_desc *desc = &gpio_desc[i];
38 + struct gpio_chip *chip = desc->chip;
41 + if (!chip && !test_bit(FLAG_RESERVED, &desc->flags)) {
49 - i -= chip->ngpio - 1;
51 + i -= chip->ngpio - 1;
59 + * gpiochip_reserve() - reserve range of gpios to use with platform code only
60 + * @start: starting gpio number
61 + * @ngpio: number of gpios to reserve
62 + * Context: platform init, potentially before irqs or kmalloc will work
64 + * Returns a negative errno if any gpio within the range is already reserved
65 + * or registered, else returns zero as a success code. Use this function
66 + * to mark a range of gpios as unavailable for dynamic gpio number allocation,
67 + * for example because its driver support is not yet loaded.
69 +int __init gpiochip_reserve(int start, int ngpio)
72 + unsigned long flags;
75 + if (!gpio_is_valid(start) || !gpio_is_valid(start + ngpio))
78 + spin_lock_irqsave(&gpio_lock, flags);
80 + for (i = start; i < start + ngpio; i++) {
81 + struct gpio_desc *desc = &gpio_desc[i];
83 + if (desc->chip || test_bit(FLAG_RESERVED, &desc->flags)) {
88 + set_bit(FLAG_RESERVED, &desc->flags);
91 + pr_debug("%s: reserved gpios from %d to %d\n",
92 + __func__, start, start + ngpio - 1);
94 + spin_unlock_irqrestore(&gpio_lock, flags);
100 * gpiochip_add() - register a gpio_chip
101 * @chip: the chip to register, with chip->base initialized
102 * Context: potentially before irqs or kmalloc will work
103 --- a/include/asm-generic/gpio.h
104 +++ b/include/asm-generic/gpio.h
107 extern const char *gpiochip_is_requested(struct gpio_chip *chip,
109 +extern int __init __must_check gpiochip_reserve(int start, int ngpio);
111 /* add/remove chips */
112 extern int gpiochip_add(struct gpio_chip *chip);