Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpiolib: Add HTE support

Some GPIO chip can provide hardware timestamp support on its GPIO lines
, in order to support that, additional API needs to be added which
can talk to both GPIO chip and HTE (hardware timestamping engine)
providers if there is any dependencies. This patch introduces optional
hooks to enable and disable hardware timestamping related features
in the GPIO controller chip.

Signed-off-by: Dipen Patel <dipenp@nvidia.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>

authored by

Dipen Patel and committed by
Thierry Reding
42112dd7 e6a3a65b

+83 -2
+58
drivers/gpio/gpiolib.c
··· 2435 2435 EXPORT_SYMBOL_GPL(gpiod_direction_output); 2436 2436 2437 2437 /** 2438 + * gpiod_enable_hw_timestamp_ns - Enable hardware timestamp in nanoseconds. 2439 + * 2440 + * @desc: GPIO to enable. 2441 + * @flags: Flags related to GPIO edge. 2442 + * 2443 + * Return 0 in case of success, else negative error code. 2444 + */ 2445 + int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags) 2446 + { 2447 + int ret = 0; 2448 + struct gpio_chip *gc; 2449 + 2450 + VALIDATE_DESC(desc); 2451 + 2452 + gc = desc->gdev->chip; 2453 + if (!gc->en_hw_timestamp) { 2454 + gpiod_warn(desc, "%s: hw ts not supported\n", __func__); 2455 + return -ENOTSUPP; 2456 + } 2457 + 2458 + ret = gc->en_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags); 2459 + if (ret) 2460 + gpiod_warn(desc, "%s: hw ts request failed\n", __func__); 2461 + 2462 + return ret; 2463 + } 2464 + EXPORT_SYMBOL_GPL(gpiod_enable_hw_timestamp_ns); 2465 + 2466 + /** 2467 + * gpiod_disable_hw_timestamp_ns - Disable hardware timestamp. 2468 + * 2469 + * @desc: GPIO to disable. 2470 + * @flags: Flags related to GPIO edge, same value as used during enable call. 2471 + * 2472 + * Return 0 in case of success, else negative error code. 2473 + */ 2474 + int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags) 2475 + { 2476 + int ret = 0; 2477 + struct gpio_chip *gc; 2478 + 2479 + VALIDATE_DESC(desc); 2480 + 2481 + gc = desc->gdev->chip; 2482 + if (!gc->dis_hw_timestamp) { 2483 + gpiod_warn(desc, "%s: hw ts not supported\n", __func__); 2484 + return -ENOTSUPP; 2485 + } 2486 + 2487 + ret = gc->dis_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags); 2488 + if (ret) 2489 + gpiod_warn(desc, "%s: hw ts release failed\n", __func__); 2490 + 2491 + return ret; 2492 + } 2493 + EXPORT_SYMBOL_GPL(gpiod_disable_hw_timestamp_ns); 2494 + 2495 + /** 2438 2496 * gpiod_set_config - sets @config for a GPIO 2439 2497 * @desc: descriptor of the GPIO for which to set the configuration 2440 2498 * @config: Same packed config format as generic pinconf
+1
drivers/gpio/gpiolib.h
··· 158 158 #define FLAG_EDGE_RISING 16 /* GPIO CDEV detects rising edge events */ 159 159 #define FLAG_EDGE_FALLING 17 /* GPIO CDEV detects falling edge events */ 160 160 #define FLAG_EVENT_CLOCK_REALTIME 18 /* GPIO CDEV reports REALTIME timestamps in events */ 161 + #define FLAG_EVENT_CLOCK_HTE 19 /* GPIO CDEV reports hardware timestamps in events */ 161 162 162 163 /* Connection label */ 163 164 const char *label;
+14 -2
include/linux/gpio/consumer.h
··· 109 109 int gpiod_direction_input(struct gpio_desc *desc); 110 110 int gpiod_direction_output(struct gpio_desc *desc, int value); 111 111 int gpiod_direction_output_raw(struct gpio_desc *desc, int value); 112 + int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags); 113 + int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags); 112 114 113 115 /* Value get/set from non-sleeping context */ 114 116 int gpiod_get_value(const struct gpio_desc *desc); ··· 352 350 WARN_ON(desc); 353 351 return -ENOSYS; 354 352 } 355 - 356 - 353 + static inline int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, 354 + unsigned long flags) 355 + { 356 + WARN_ON(desc); 357 + return -ENOSYS; 358 + } 359 + static inline int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, 360 + unsigned long flags) 361 + { 362 + WARN_ON(desc); 363 + return -ENOSYS; 364 + } 357 365 static inline int gpiod_get_value(const struct gpio_desc *desc) 358 366 { 359 367 /* GPIO can never have been requested */
+10
include/linux/gpio/driver.h
··· 323 323 * @add_pin_ranges: optional routine to initialize pin ranges, to be used when 324 324 * requires special mapping of the pins that provides GPIO functionality. 325 325 * It is called after adding GPIO chip and before adding IRQ chip. 326 + * @en_hw_timestamp: Dependent on GPIO chip, an optional routine to 327 + * enable hardware timestamp. 328 + * @dis_hw_timestamp: Dependent on GPIO chip, an optional routine to 329 + * disable hardware timestamp. 326 330 * @base: identifies the first GPIO number handled by this chip; 327 331 * or, if negative during registration, requests dynamic ID allocation. 328 332 * DEPRECATION: providing anything non-negative and nailing the base ··· 423 419 424 420 int (*add_pin_ranges)(struct gpio_chip *gc); 425 421 422 + int (*en_hw_timestamp)(struct gpio_chip *gc, 423 + u32 offset, 424 + unsigned long flags); 425 + int (*dis_hw_timestamp)(struct gpio_chip *gc, 426 + u32 offset, 427 + unsigned long flags); 426 428 int base; 427 429 u16 ngpio; 428 430 u16 offset;