.. | .. |
---|
| 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) |
---|
.. | .. |
---|
365 | 366 | static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr, |
---|
366 | 367 | int n) |
---|
367 | 368 | { |
---|
368 | | - struct device *dev = container_of(kobj, struct device, kobj); |
---|
| 369 | + struct device *dev = kobj_to_dev(kobj); |
---|
369 | 370 | struct gpiod_data *data = dev_get_drvdata(dev); |
---|
370 | 371 | struct gpio_desc *desc = data->desc; |
---|
371 | 372 | umode_t mode = attr->mode; |
---|
.. | .. |
---|
444 | 445 | }; |
---|
445 | 446 | ATTRIBUTE_GROUPS(gpiochip); |
---|
446 | 447 | |
---|
447 | | -static struct gpio_desc *gpio_to_valid_desc(int gpio) |
---|
448 | | -{ |
---|
449 | | - return gpio_is_valid(gpio) ? gpio_to_desc(gpio) : NULL; |
---|
450 | | -} |
---|
451 | | - |
---|
452 | 448 | /* |
---|
453 | 449 | * /sys/class/gpio/export ... write-only |
---|
454 | 450 | * integer N ... number of GPIO to export (full access) |
---|
.. | .. |
---|
469 | 465 | if (status < 0) |
---|
470 | 466 | goto done; |
---|
471 | 467 | |
---|
472 | | - desc = gpio_to_valid_desc(gpio); |
---|
| 468 | + desc = gpio_to_desc(gpio); |
---|
473 | 469 | /* reject invalid GPIOs */ |
---|
474 | 470 | if (!desc) { |
---|
475 | 471 | pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); |
---|
.. | .. |
---|
522 | 518 | if (status < 0) |
---|
523 | 519 | goto done; |
---|
524 | 520 | |
---|
525 | | - desc = gpio_to_valid_desc(gpio); |
---|
| 521 | + desc = gpio_to_desc(gpio); |
---|
526 | 522 | /* reject bogus commands (gpio_unexport ignores them) */ |
---|
527 | 523 | if (!desc) { |
---|
528 | 524 | pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); |
---|
.. | .. |
---|
775 | 771 | parent = &gdev->dev; |
---|
776 | 772 | |
---|
777 | 773 | /* use chip->base for the ID; it's already known to be unique */ |
---|
778 | | - dev = device_create_with_groups(&gpio_class, parent, |
---|
779 | | - MKDEV(0, 0), |
---|
780 | | - chip, gpiochip_groups, |
---|
781 | | - "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); |
---|
782 | 777 | if (IS_ERR(dev)) |
---|
783 | 778 | return PTR_ERR(dev); |
---|
784 | 779 | |
---|