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.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 3ee99d070608..cca749010cd0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -956,9 +956,11 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
956 } 956 }
957 957
958 if (eflags & GPIOEVENT_REQUEST_RISING_EDGE) 958 if (eflags & GPIOEVENT_REQUEST_RISING_EDGE)
959 irqflags |= IRQF_TRIGGER_RISING; 959 irqflags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
960 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
960 if (eflags & GPIOEVENT_REQUEST_FALLING_EDGE) 961 if (eflags & GPIOEVENT_REQUEST_FALLING_EDGE)
961 irqflags |= IRQF_TRIGGER_FALLING; 962 irqflags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
963 IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
962 irqflags |= IRQF_ONESHOT; 964 irqflags |= IRQF_ONESHOT;
963 965
964 INIT_KFIFO(le->events); 966 INIT_KFIFO(le->events);
@@ -1089,9 +1091,11 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1089 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 1091 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
1090 lineinfo.flags |= GPIOLINE_FLAG_ACTIVE_LOW; 1092 lineinfo.flags |= GPIOLINE_FLAG_ACTIVE_LOW;
1091 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) 1093 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
1092 lineinfo.flags |= GPIOLINE_FLAG_OPEN_DRAIN; 1094 lineinfo.flags |= (GPIOLINE_FLAG_OPEN_DRAIN |
1095 GPIOLINE_FLAG_IS_OUT);
1093 if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) 1096 if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
1094 lineinfo.flags |= GPIOLINE_FLAG_OPEN_SOURCE; 1097 lineinfo.flags |= (GPIOLINE_FLAG_OPEN_SOURCE |
1098 GPIOLINE_FLAG_IS_OUT);
1095 1099
1096 if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) 1100 if (copy_to_user(ip, &lineinfo, sizeof(lineinfo)))
1097 return -EFAULT; 1101 return -EFAULT;
@@ -1369,21 +1373,13 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
1369 if (status) 1373 if (status)
1370 goto err_remove_from_list; 1374 goto err_remove_from_list;
1371 1375
1372 status = gpiochip_irqchip_init_valid_mask(chip);
1373 if (status)
1374 goto err_remove_from_list;
1375
1376 status = gpiochip_alloc_valid_mask(chip); 1376 status = gpiochip_alloc_valid_mask(chip);
1377 if (status) 1377 if (status)
1378 goto err_remove_irqchip_mask; 1378 goto err_remove_from_list;
1379
1380 status = gpiochip_add_irqchip(chip, lock_key, request_key);
1381 if (status)
1382 goto err_free_gpiochip_mask;
1383 1379
1384 status = of_gpiochip_add(chip); 1380 status = of_gpiochip_add(chip);
1385 if (status) 1381 if (status)
1386 goto err_remove_chip; 1382 goto err_free_gpiochip_mask;
1387 1383
1388 status = gpiochip_init_valid_mask(chip); 1384 status = gpiochip_init_valid_mask(chip);
1389 if (status) 1385 if (status)
@@ -1392,18 +1388,31 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
1392 for (i = 0; i < chip->ngpio; i++) { 1388 for (i = 0; i < chip->ngpio; i++) {
1393 struct gpio_desc *desc = &gdev->descs[i]; 1389 struct gpio_desc *desc = &gdev->descs[i];
1394 1390
1395 if (chip->get_direction && gpiochip_line_is_valid(chip, i)) 1391 if (chip->get_direction && gpiochip_line_is_valid(chip, i)) {
1396 desc->flags = !chip->get_direction(chip, i) ? 1392 if (!chip->get_direction(chip, i))
1397 (1 << FLAG_IS_OUT) : 0; 1393 set_bit(FLAG_IS_OUT, &desc->flags);
1398 else 1394 else
1399 desc->flags = !chip->direction_input ? 1395 clear_bit(FLAG_IS_OUT, &desc->flags);
1400 (1 << FLAG_IS_OUT) : 0; 1396 } else {
1397 if (!chip->direction_input)
1398 set_bit(FLAG_IS_OUT, &desc->flags);
1399 else
1400 clear_bit(FLAG_IS_OUT, &desc->flags);
1401 }
1401 } 1402 }
1402 1403
1403 acpi_gpiochip_add(chip); 1404 acpi_gpiochip_add(chip);
1404 1405
1405 machine_gpiochip_add(chip); 1406 machine_gpiochip_add(chip);
1406 1407
1408 status = gpiochip_irqchip_init_valid_mask(chip);
1409 if (status)
1410 goto err_remove_acpi_chip;
1411
1412 status = gpiochip_add_irqchip(chip, lock_key, request_key);
1413 if (status)
1414 goto err_remove_irqchip_mask;
1415
1407 /* 1416 /*
1408 * By first adding the chardev, and then adding the device, 1417 * By first adding the chardev, and then adding the device,
1409 * we get a device node entry in sysfs under 1418 * we get a device node entry in sysfs under
@@ -1415,21 +1424,21 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
1415 if (gpiolib_initialized) { 1424 if (gpiolib_initialized) {
1416 status = gpiochip_setup_dev(gdev); 1425 status = gpiochip_setup_dev(gdev);
1417 if (status) 1426 if (status)
1418 goto err_remove_acpi_chip; 1427 goto err_remove_irqchip;
1419 } 1428 }
1420 return 0; 1429 return 0;
1421 1430
1431err_remove_irqchip:
1432 gpiochip_irqchip_remove(chip);
1433err_remove_irqchip_mask:
1434 gpiochip_irqchip_free_valid_mask(chip);
1422err_remove_acpi_chip: 1435err_remove_acpi_chip:
1423 acpi_gpiochip_remove(chip); 1436 acpi_gpiochip_remove(chip);
1424err_remove_of_chip: 1437err_remove_of_chip:
1425 gpiochip_free_hogs(chip); 1438 gpiochip_free_hogs(chip);
1426 of_gpiochip_remove(chip); 1439 of_gpiochip_remove(chip);
1427err_remove_chip:
1428 gpiochip_irqchip_remove(chip);
1429err_free_gpiochip_mask: 1440err_free_gpiochip_mask:
1430 gpiochip_free_valid_mask(chip); 1441 gpiochip_free_valid_mask(chip);
1431err_remove_irqchip_mask:
1432 gpiochip_irqchip_free_valid_mask(chip);
1433err_remove_from_list: 1442err_remove_from_list:
1434 spin_lock_irqsave(&gpio_lock, flags); 1443 spin_lock_irqsave(&gpio_lock, flags);
1435 list_del(&gdev->list); 1444 list_del(&gdev->list);