Skip to content

Commit 42112dd

Browse files
pateldipen1984-nvthierryreding
authored andcommitted
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 <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reported-by: kernel test robot <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent e6a3a65 commit 42112dd

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

drivers/gpio/gpiolib.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,6 +2434,64 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
24342434
}
24352435
EXPORT_SYMBOL_GPL(gpiod_direction_output);
24362436

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+
24372495
/**
24382496
* gpiod_set_config - sets @config for a GPIO
24392497
* @desc: descriptor of the GPIO for which to set the configuration

drivers/gpio/gpiolib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct gpio_desc {
158158
#define FLAG_EDGE_RISING 16 /* GPIO CDEV detects rising edge events */
159159
#define FLAG_EDGE_FALLING 17 /* GPIO CDEV detects falling edge events */
160160
#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 */
161162

162163
/* Connection label */
163164
const char *label;

include/linux/gpio/consumer.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ int gpiod_get_direction(struct gpio_desc *desc);
109109
int gpiod_direction_input(struct gpio_desc *desc);
110110
int gpiod_direction_output(struct gpio_desc *desc, int value);
111111
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);
112114

113115
/* Value get/set from non-sleeping context */
114116
int gpiod_get_value(const struct gpio_desc *desc);
@@ -350,8 +352,18 @@ static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
350352
WARN_ON(desc);
351353
return -ENOSYS;
352354
}
353-
354-
355+
static inline int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc,
356+
unsigned long flags)
357+
{
358+
WARN_ON(desc);
359+
return -ENOSYS;
360+
}
361+
static inline int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc,
362+
unsigned long flags)
363+
{
364+
WARN_ON(desc);
365+
return -ENOSYS;
366+
}
355367
static inline int gpiod_get_value(const struct gpio_desc *desc)
356368
{
357369
/* GPIO can never have been requested */

include/linux/gpio/driver.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ struct gpio_irq_chip {
323323
* @add_pin_ranges: optional routine to initialize pin ranges, to be used when
324324
* requires special mapping of the pins that provides GPIO functionality.
325325
* 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.
326330
* @base: identifies the first GPIO number handled by this chip;
327331
* or, if negative during registration, requests dynamic ID allocation.
328332
* DEPRECATION: providing anything non-negative and nailing the base
@@ -419,6 +423,12 @@ struct gpio_chip {
419423

420424
int (*add_pin_ranges)(struct gpio_chip *gc);
421425

426+
int (*en_hw_timestamp)(struct gpio_chip *gc,
427+
u32 offset,
428+
unsigned long flags);
429+
int (*dis_hw_timestamp)(struct gpio_chip *gc,
430+
u32 offset,
431+
unsigned long flags);
422432
int base;
423433
u16 ngpio;
424434
u16 offset;

0 commit comments

Comments
 (0)