hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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,13 +81,17 @@
8081 struct gpiod_data *data = dev_get_drvdata(dev);
8182 struct gpio_desc *desc = data->desc;
8283 ssize_t status;
84
+ int offset;
8385
8486 mutex_lock(&data->mutex);
85
-
87
+ offset = gpio_chip_hwgpio(desc);
8688 if (sysfs_streq(buf, "high"))
8789 status = gpiod_direction_output_raw(desc, 1);
8890 else if (sysfs_streq(buf, "out") || sysfs_streq(buf, "low"))
89
- status = gpiod_direction_output_raw(desc, 0);
91
+ if (( offset == 8 ) || ( offset == 11 ) || ( offset == 12 ) || ( offset == 13 ) || ( offset == 14 ))
92
+ status = gpiod_direction_output_raw(desc, 1);
93
+ else
94
+ status = gpiod_direction_output_raw(desc, 0);
9095 else if (sysfs_streq(buf, "in"))
9196 status = gpiod_direction_input(desc);
9297 else
....@@ -365,7 +370,7 @@
365370 static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr,
366371 int n)
367372 {
368
- struct device *dev = container_of(kobj, struct device, kobj);
373
+ struct device *dev = kobj_to_dev(kobj);
369374 struct gpiod_data *data = dev_get_drvdata(dev);
370375 struct gpio_desc *desc = data->desc;
371376 umode_t mode = attr->mode;
....@@ -444,11 +449,6 @@
444449 };
445450 ATTRIBUTE_GROUPS(gpiochip);
446451
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
-
452452 /*
453453 * /sys/class/gpio/export ... write-only
454454 * integer N ... number of GPIO to export (full access)
....@@ -469,7 +469,7 @@
469469 if (status < 0)
470470 goto done;
471471
472
- desc = gpio_to_valid_desc(gpio);
472
+ desc = gpio_to_desc(gpio);
473473 /* reject invalid GPIOs */
474474 if (!desc) {
475475 pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
....@@ -522,7 +522,7 @@
522522 if (status < 0)
523523 goto done;
524524
525
- desc = gpio_to_valid_desc(gpio);
525
+ desc = gpio_to_desc(gpio);
526526 /* reject bogus commands (gpio_unexport ignores them) */
527527 if (!desc) {
528528 pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
....@@ -775,10 +775,9 @@
775775 parent = &gdev->dev;
776776
777777 /* 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);
778
+ dev = device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), chip,
779
+ gpiochip_groups, GPIOCHIP_NAME "%d",
780
+ chip->base);
782781 if (IS_ERR(dev))
783782 return PTR_ERR(dev);
784783