| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | #include <linux/idr.h> |
|---|
| 2 | 3 | #include <linux/mutex.h> |
|---|
| 3 | 4 | #include <linux/device.h> |
|---|
| 4 | 5 | #include <linux/sysfs.h> |
|---|
| 5 | | -#include <linux/gpio.h> |
|---|
| 6 | 6 | #include <linux/gpio/consumer.h> |
|---|
| 7 | 7 | #include <linux/gpio/driver.h> |
|---|
| 8 | 8 | #include <linux/interrupt.h> |
|---|
| .. | .. |
|---|
| 11 | 11 | #include <linux/ctype.h> |
|---|
| 12 | 12 | |
|---|
| 13 | 13 | #include "gpiolib.h" |
|---|
| 14 | +#include "gpiolib-sysfs.h" |
|---|
| 14 | 15 | |
|---|
| 15 | 16 | #define GPIO_IRQF_TRIGGER_FALLING BIT(0) |
|---|
| 16 | 17 | #define GPIO_IRQF_TRIGGER_RISING BIT(1) |
|---|
| .. | .. |
|---|
| 80 | 81 | struct gpiod_data *data = dev_get_drvdata(dev); |
|---|
| 81 | 82 | struct gpio_desc *desc = data->desc; |
|---|
| 82 | 83 | ssize_t status; |
|---|
| 83 | | - int offset; |
|---|
| 84 | 84 | |
|---|
| 85 | 85 | mutex_lock(&data->mutex); |
|---|
| 86 | 86 | |
|---|
| 87 | | - offset = gpio_chip_hwgpio(desc); |
|---|
| 88 | 87 | if (sysfs_streq(buf, "high")) |
|---|
| 89 | 88 | status = gpiod_direction_output_raw(desc, 1); |
|---|
| 90 | 89 | else if (sysfs_streq(buf, "out") || sysfs_streq(buf, "low")) |
|---|
| 91 | | - if (( offset == 26 ) || ( offset == 25 ) || ( offset == 27 )) |
|---|
| 92 | | - status = gpiod_direction_output_raw(desc, 1); |
|---|
| 93 | | - else |
|---|
| 94 | | - status = gpiod_direction_output_raw(desc, 0); |
|---|
| 90 | + status = gpiod_direction_output_raw(desc, 0); |
|---|
| 95 | 91 | else if (sysfs_streq(buf, "in")) |
|---|
| 96 | 92 | status = gpiod_direction_input(desc); |
|---|
| 97 | 93 | else |
|---|
| .. | .. |
|---|
| 370 | 366 | static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr, |
|---|
| 371 | 367 | int n) |
|---|
| 372 | 368 | { |
|---|
| 373 | | - struct device *dev = container_of(kobj, struct device, kobj); |
|---|
| 369 | + struct device *dev = kobj_to_dev(kobj); |
|---|
| 374 | 370 | struct gpiod_data *data = dev_get_drvdata(dev); |
|---|
| 375 | 371 | struct gpio_desc *desc = data->desc; |
|---|
| 376 | 372 | umode_t mode = attr->mode; |
|---|
| .. | .. |
|---|
| 449 | 445 | }; |
|---|
| 450 | 446 | ATTRIBUTE_GROUPS(gpiochip); |
|---|
| 451 | 447 | |
|---|
| 452 | | -static struct gpio_desc *gpio_to_valid_desc(int gpio) |
|---|
| 453 | | -{ |
|---|
| 454 | | - return gpio_is_valid(gpio) ? gpio_to_desc(gpio) : NULL; |
|---|
| 455 | | -} |
|---|
| 456 | | - |
|---|
| 457 | 448 | /* |
|---|
| 458 | 449 | * /sys/class/gpio/export ... write-only |
|---|
| 459 | 450 | * integer N ... number of GPIO to export (full access) |
|---|
| .. | .. |
|---|
| 474 | 465 | if (status < 0) |
|---|
| 475 | 466 | goto done; |
|---|
| 476 | 467 | |
|---|
| 477 | | - desc = gpio_to_valid_desc(gpio); |
|---|
| 468 | + desc = gpio_to_desc(gpio); |
|---|
| 478 | 469 | /* reject invalid GPIOs */ |
|---|
| 479 | 470 | if (!desc) { |
|---|
| 480 | 471 | pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); |
|---|
| .. | .. |
|---|
| 527 | 518 | if (status < 0) |
|---|
| 528 | 519 | goto done; |
|---|
| 529 | 520 | |
|---|
| 530 | | - desc = gpio_to_valid_desc(gpio); |
|---|
| 521 | + desc = gpio_to_desc(gpio); |
|---|
| 531 | 522 | /* reject bogus commands (gpio_unexport ignores them) */ |
|---|
| 532 | 523 | if (!desc) { |
|---|
| 533 | 524 | pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); |
|---|
| .. | .. |
|---|
| 780 | 771 | parent = &gdev->dev; |
|---|
| 781 | 772 | |
|---|
| 782 | 773 | /* use chip->base for the ID; it's already known to be unique */ |
|---|
| 783 | | - dev = device_create_with_groups(&gpio_class, parent, |
|---|
| 784 | | - MKDEV(0, 0), |
|---|
| 785 | | - chip, gpiochip_groups, |
|---|
| 786 | | - "gpiochip%d", chip->base); |
|---|
| 774 | + dev = device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), chip, |
|---|
| 775 | + gpiochip_groups, GPIOCHIP_NAME "%d", |
|---|
| 776 | + chip->base); |
|---|
| 787 | 777 | if (IS_ERR(dev)) |
|---|
| 788 | 778 | return PTR_ERR(dev); |
|---|
| 789 | 779 | |
|---|