aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c58
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}
1238EXPORT_SYMBOL_GPL(gpio_free); 1238EXPORT_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 */
1246int 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}
1262EXPORT_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 */
1269int 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
1280err_free:
1281 while (i--)
1282 gpio_free((--array)->gpio);
1283 return err;
1284}
1285EXPORT_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 */
1292void gpio_free_array(struct gpio *array, size_t num)
1293{
1294 while (num--)
1295 gpio_free((array++)->gpio);
1296}
1297EXPORT_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