diff options
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpiolib.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 713ca0e37f23..73fd328f6fe4 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -1153,6 +1153,38 @@ int gpiochip_remove(struct gpio_chip *chip) | |||
1153 | } | 1153 | } |
1154 | EXPORT_SYMBOL_GPL(gpiochip_remove); | 1154 | EXPORT_SYMBOL_GPL(gpiochip_remove); |
1155 | 1155 | ||
1156 | /** | ||
1157 | * gpiochip_find() - iterator for locating a specific gpio_chip | ||
1158 | * @data: data to pass to match function | ||
1159 | * @callback: Callback function to check gpio_chip | ||
1160 | * | ||
1161 | * Similar to bus_find_device. It returns a reference to a gpio_chip as | ||
1162 | * determined by a user supplied @match callback. The callback should return | ||
1163 | * 0 if the device doesn't match and non-zero if it does. If the callback is | ||
1164 | * non-zero, this function will return to the caller and not iterate over any | ||
1165 | * more gpio_chips. | ||
1166 | */ | ||
1167 | struct gpio_chip *gpiochip_find(void *data, | ||
1168 | int (*match)(struct gpio_chip *chip, void *data)) | ||
1169 | { | ||
1170 | struct gpio_chip *chip = NULL; | ||
1171 | unsigned long flags; | ||
1172 | int i; | ||
1173 | |||
1174 | spin_lock_irqsave(&gpio_lock, flags); | ||
1175 | for (i = 0; i < ARCH_NR_GPIOS; i++) { | ||
1176 | if (!gpio_desc[i].chip) | ||
1177 | continue; | ||
1178 | |||
1179 | if (match(gpio_desc[i].chip, data)) { | ||
1180 | chip = gpio_desc[i].chip; | ||
1181 | break; | ||
1182 | } | ||
1183 | } | ||
1184 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
1185 | |||
1186 | return chip; | ||
1187 | } | ||
1156 | 1188 | ||
1157 | /* These "optional" allocation calls help prevent drivers from stomping | 1189 | /* These "optional" allocation calls help prevent drivers from stomping |
1158 | * on each other, and help provide better diagnostics in debugfs. | 1190 | * on each other, and help provide better diagnostics in debugfs. |