diff options
author | Eric Miao <eric.y.miao@gmail.com> | 2010-03-05 16:44:35 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-03-06 14:26:48 -0500 |
commit | 3e45f1d1155894e6f4291f5536b224874d52d8e2 (patch) | |
tree | d7b44dd5248bdb053c0cd6632e82ce8893833519 /drivers/gpio/gpiolib.c | |
parent | 62fecb70cfaa9b4c6aa1981acd53b18f4ad925f0 (diff) |
gpio: introduce gpio_request_one() and friends
gpio_request() without initial configuration of the GPIO is normally
useless, introduce gpio_request_one() together with GPIOF_ flags for
input/output direction and initial output level.
gpio_{request,free}_array() for multiple GPIOs.
Signed-off-by: Eric Miao <eric.y.miao@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Ben Nizette <bn@niasdigital.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 350842ad3632..9006fdb26fea 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -1237,6 +1237,64 @@ void gpio_free(unsigned gpio) | |||
1237 | } | 1237 | } |
1238 | EXPORT_SYMBOL_GPL(gpio_free); | 1238 | EXPORT_SYMBOL_GPL(gpio_free); |
1239 | 1239 | ||
1240 | /** | ||
1241 | * gpio_request_one - request a single GPIO with initial configuration | ||
1242 | * @gpio: the GPIO number | ||
1243 | * @flags: GPIO configuration as specified by GPIOF_* | ||
1244 | * @label: a literal description string of this GPIO | ||
1245 | */ | ||
1246 | int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) | ||
1247 | { | ||
1248 | int err; | ||
1249 | |||
1250 | err = gpio_request(gpio, label); | ||
1251 | if (err) | ||
1252 | return err; | ||
1253 | |||
1254 | if (flags & GPIOF_DIR_IN) | ||
1255 | err = gpio_direction_input(gpio); | ||
1256 | else | ||
1257 | err = gpio_direction_output(gpio, | ||
1258 | (flags & GPIOF_INIT_HIGH) ? 1 : 0); | ||
1259 | |||
1260 | return err; | ||
1261 | } | ||
1262 | EXPORT_SYMBOL_GPL(gpio_request_one); | ||
1263 | |||
1264 | /** | ||
1265 | * gpio_request_array - request multiple GPIOs in a single call | ||
1266 | * @array: array of the 'struct gpio' | ||
1267 | * @num: how many GPIOs in the array | ||
1268 | */ | ||
1269 | int gpio_request_array(struct gpio *array, size_t num) | ||
1270 | { | ||
1271 | int i, err; | ||
1272 | |||
1273 | for (i = 0; i < num; i++, array++) { | ||
1274 | err = gpio_request_one(array->gpio, array->flags, array->label); | ||
1275 | if (err) | ||
1276 | goto err_free; | ||
1277 | } | ||
1278 | return 0; | ||
1279 | |||
1280 | err_free: | ||
1281 | while (i--) | ||
1282 | gpio_free((--array)->gpio); | ||
1283 | return err; | ||
1284 | } | ||
1285 | EXPORT_SYMBOL_GPL(gpio_request_array); | ||
1286 | |||
1287 | /** | ||
1288 | * gpio_free_array - release multiple GPIOs in a single call | ||
1289 | * @array: array of the 'struct gpio' | ||
1290 | * @num: how many GPIOs in the array | ||
1291 | */ | ||
1292 | void gpio_free_array(struct gpio *array, size_t num) | ||
1293 | { | ||
1294 | while (num--) | ||
1295 | gpio_free((array++)->gpio); | ||
1296 | } | ||
1297 | EXPORT_SYMBOL_GPL(gpio_free_array); | ||
1240 | 1298 | ||
1241 | /** | 1299 | /** |
1242 | * gpiochip_is_requested - return string iff signal was requested | 1300 | * gpiochip_is_requested - return string iff signal was requested |