Merge tag 'io_uring-5.19-2022-07-01' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / drivers / gpio / gpiolib.c
index 9fff4f4..9535f48 100644 (file)
@@ -2453,6 +2453,64 @@ set_output_flag:
 }
 EXPORT_SYMBOL_GPL(gpiod_direction_output);
 
+/**
+ * gpiod_enable_hw_timestamp_ns - Enable hardware timestamp in nanoseconds.
+ *
+ * @desc: GPIO to enable.
+ * @flags: Flags related to GPIO edge.
+ *
+ * Return 0 in case of success, else negative error code.
+ */
+int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags)
+{
+       int ret = 0;
+       struct gpio_chip *gc;
+
+       VALIDATE_DESC(desc);
+
+       gc = desc->gdev->chip;
+       if (!gc->en_hw_timestamp) {
+               gpiod_warn(desc, "%s: hw ts not supported\n", __func__);
+               return -ENOTSUPP;
+       }
+
+       ret = gc->en_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags);
+       if (ret)
+               gpiod_warn(desc, "%s: hw ts request failed\n", __func__);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(gpiod_enable_hw_timestamp_ns);
+
+/**
+ * gpiod_disable_hw_timestamp_ns - Disable hardware timestamp.
+ *
+ * @desc: GPIO to disable.
+ * @flags: Flags related to GPIO edge, same value as used during enable call.
+ *
+ * Return 0 in case of success, else negative error code.
+ */
+int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags)
+{
+       int ret = 0;
+       struct gpio_chip *gc;
+
+       VALIDATE_DESC(desc);
+
+       gc = desc->gdev->chip;
+       if (!gc->dis_hw_timestamp) {
+               gpiod_warn(desc, "%s: hw ts not supported\n", __func__);
+               return -ENOTSUPP;
+       }
+
+       ret = gc->dis_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags);
+       if (ret)
+               gpiod_warn(desc, "%s: hw ts release failed\n", __func__);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(gpiod_disable_hw_timestamp_ns);
+
 /**
  * gpiod_set_config - sets @config for a GPIO
  * @desc: descriptor of the GPIO for which to set the configuration