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