lib: decompress_bunzip2: delete duplicated words
[linux-2.6-microblaze.git] / drivers / gpio / gpiolib.c
index 80137c1..3cdf9ef 100644 (file)
@@ -340,9 +340,6 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
        struct gpio_device *gdev = gc->gpiodev;
        int i;
 
-       if (!gc->names)
-               return 0;
-
        /* First check all names if they are unique */
        for (i = 0; i != gc->ngpio; ++i) {
                struct gpio_desc *gpio;
@@ -361,6 +358,57 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
        return 0;
 }
 
+/*
+ * devprop_gpiochip_set_names - Set GPIO line names using device properties
+ * @chip: GPIO chip whose lines should be named, if possible
+ *
+ * Looks for device property "gpio-line-names" and if it exists assigns
+ * GPIO line names for the chip. The memory allocated for the assigned
+ * names belong to the underlying software node and should not be released
+ * by the caller.
+ */
+static int devprop_gpiochip_set_names(struct gpio_chip *chip)
+{
+       struct gpio_device *gdev = chip->gpiodev;
+       struct device *dev = chip->parent;
+       const char **names;
+       int ret, i;
+       int count;
+
+       /* GPIO chip may not have a parent device whose properties we inspect. */
+       if (!dev)
+               return 0;
+
+       count = device_property_string_array_count(dev, "gpio-line-names");
+       if (count < 0)
+               return 0;
+
+       if (count > gdev->ngpio) {
+               dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d",
+                        count, gdev->ngpio);
+               count = gdev->ngpio;
+       }
+
+       names = kcalloc(count, sizeof(*names), GFP_KERNEL);
+       if (!names)
+               return -ENOMEM;
+
+       ret = device_property_read_string_array(dev, "gpio-line-names",
+                                               names, count);
+       if (ret < 0) {
+               dev_warn(&gdev->dev, "failed to read GPIO line names\n");
+               kfree(names);
+               return ret;
+       }
+
+       for (i = 0; i < count; i++)
+               gdev->descs[i].name = names[i];
+
+       kfree(names);
+
+       return 0;
+}
+
 static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc)
 {
        unsigned long *p;
@@ -426,7 +474,7 @@ static void gpiodevice_release(struct device *dev)
        struct gpio_device *gdev = dev_get_drvdata(dev);
 
        list_del(&gdev->list);
-       ida_simple_remove(&gpio_ida, gdev->id);
+       ida_free(&gpio_ida, gdev->id);
        kfree_const(gdev->label);
        kfree(gdev->descs);
        kfree(gdev);
@@ -537,7 +585,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
                gc->of_node = gdev->dev.of_node;
 #endif
 
-       gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL);
+       gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL);
        if (gdev->id < 0) {
                ret = gdev->id;
                goto err_free_gdev;
@@ -621,7 +669,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
        INIT_LIST_HEAD(&gdev->pin_ranges);
 #endif
 
-       ret = gpiochip_set_desc_names(gc);
+       if (gc->names)
+               ret = gpiochip_set_desc_names(gc);
+       else
+               ret = devprop_gpiochip_set_names(gc);
        if (ret)
                goto err_remove_from_list;
 
@@ -705,7 +756,7 @@ err_free_label:
 err_free_descs:
        kfree(gdev->descs);
 err_free_ida:
-       ida_simple_remove(&gpio_ida, gdev->id);
+       ida_free(&gpio_ida, gdev->id);
 err_free_gdev:
        /* failures here can mean systems won't boot... */
        pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__,
@@ -2041,9 +2092,14 @@ static bool gpiod_free_commit(struct gpio_desc *desc)
                clear_bit(FLAG_PULL_UP, &desc->flags);
                clear_bit(FLAG_PULL_DOWN, &desc->flags);
                clear_bit(FLAG_BIAS_DISABLE, &desc->flags);
+               clear_bit(FLAG_EDGE_RISING, &desc->flags);
+               clear_bit(FLAG_EDGE_FALLING, &desc->flags);
                clear_bit(FLAG_IS_HOGGED, &desc->flags);
 #ifdef CONFIG_OF_DYNAMIC
                desc->hog = NULL;
+#endif
+#ifdef CONFIG_GPIO_CDEV
+               WRITE_ONCE(desc->debounce_period_us, 0);
 #endif
                ret = true;
        }
@@ -4402,31 +4458,18 @@ static int gpiolib_seq_show(struct seq_file *s, void *v)
        return 0;
 }
 
-static const struct seq_operations gpiolib_seq_ops = {
+static const struct seq_operations gpiolib_sops = {
        .start = gpiolib_seq_start,
        .next = gpiolib_seq_next,
        .stop = gpiolib_seq_stop,
        .show = gpiolib_seq_show,
 };
-
-static int gpiolib_open(struct inode *inode, struct file *file)
-{
-       return seq_open(file, &gpiolib_seq_ops);
-}
-
-static const struct file_operations gpiolib_operations = {
-       .owner          = THIS_MODULE,
-       .open           = gpiolib_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = seq_release,
-};
+DEFINE_SEQ_ATTRIBUTE(gpiolib);
 
 static int __init gpiolib_debugfs_init(void)
 {
        /* /sys/kernel/debug/gpio */
-       debugfs_create_file("gpio", S_IFREG | S_IRUGO, NULL, NULL,
-                           &gpiolib_operations);
+       debugfs_create_file("gpio", 0444, NULL, NULL, &gpiolib_fops);
        return 0;
 }
 subsys_initcall(gpiolib_debugfs_init);