hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpiolib-sysfs.c
....@@ -1,8 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 #include <linux/idr.h>
23 #include <linux/mutex.h>
34 #include <linux/device.h>
45 #include <linux/sysfs.h>
5
-#include <linux/gpio.h>
66 #include <linux/gpio/consumer.h>
77 #include <linux/gpio/driver.h>
88 #include <linux/interrupt.h>
....@@ -11,6 +11,7 @@
1111 #include <linux/ctype.h>
1212
1313 #include "gpiolib.h"
14
+#include "gpiolib-sysfs.h"
1415
1516 #define GPIO_IRQF_TRIGGER_FALLING BIT(0)
1617 #define GPIO_IRQF_TRIGGER_RISING BIT(1)
....@@ -80,18 +81,13 @@
8081 struct gpiod_data *data = dev_get_drvdata(dev);
8182 struct gpio_desc *desc = data->desc;
8283 ssize_t status;
83
- int offset;
8484
8585 mutex_lock(&data->mutex);
8686
87
- offset = gpio_chip_hwgpio(desc);
8887 if (sysfs_streq(buf, "high"))
8988 status = gpiod_direction_output_raw(desc, 1);
9089 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);
9591 else if (sysfs_streq(buf, "in"))
9692 status = gpiod_direction_input(desc);
9793 else
....@@ -370,7 +366,7 @@
370366 static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr,
371367 int n)
372368 {
373
- struct device *dev = container_of(kobj, struct device, kobj);
369
+ struct device *dev = kobj_to_dev(kobj);
374370 struct gpiod_data *data = dev_get_drvdata(dev);
375371 struct gpio_desc *desc = data->desc;
376372 umode_t mode = attr->mode;
....@@ -449,11 +445,6 @@
449445 };
450446 ATTRIBUTE_GROUPS(gpiochip);
451447
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
-
457448 /*
458449 * /sys/class/gpio/export ... write-only
459450 * integer N ... number of GPIO to export (full access)
....@@ -474,7 +465,7 @@
474465 if (status < 0)
475466 goto done;
476467
477
- desc = gpio_to_valid_desc(gpio);
468
+ desc = gpio_to_desc(gpio);
478469 /* reject invalid GPIOs */
479470 if (!desc) {
480471 pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
....@@ -527,7 +518,7 @@
527518 if (status < 0)
528519 goto done;
529520
530
- desc = gpio_to_valid_desc(gpio);
521
+ desc = gpio_to_desc(gpio);
531522 /* reject bogus commands (gpio_unexport ignores them) */
532523 if (!desc) {
533524 pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
....@@ -780,10 +771,9 @@
780771 parent = &gdev->dev;
781772
782773 /* 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);
787777 if (IS_ERR(dev))
788778 return PTR_ERR(dev);
789779