174ba9207SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2d94ba80eSRichard Cochran /* 3d94ba80eSRichard Cochran * PTP 1588 clock support 4d94ba80eSRichard Cochran * 5d94ba80eSRichard Cochran * Copyright (C) 2010 OMICRON electronics GmbH 6d94ba80eSRichard Cochran */ 7d94ba80eSRichard Cochran 8d94ba80eSRichard Cochran #ifndef _PTP_CLOCK_KERNEL_H_ 9d94ba80eSRichard Cochran #define _PTP_CLOCK_KERNEL_H_ 10d94ba80eSRichard Cochran 111ef76158SRichard Cochran #include <linux/device.h> 12220a60a4SBen Hutchings #include <linux/pps_kernel.h> 13d94ba80eSRichard Cochran #include <linux/ptp_clock.h> 145d43f951SYangbo Lu #include <linux/timecounter.h> 15895487a3SYangbo Lu #include <linux/skbuff.h> 16d94ba80eSRichard Cochran 175d43f951SYangbo Lu #define PTP_CLOCK_NAME_LEN 32 18d04a53b1SAhmad Fatoum /** 19d04a53b1SAhmad Fatoum * struct ptp_clock_request - request PTP clock event 20d04a53b1SAhmad Fatoum * 21d04a53b1SAhmad Fatoum * @type: The type of the request. 22d04a53b1SAhmad Fatoum * EXTTS: Configure external trigger timestamping 23d04a53b1SAhmad Fatoum * PEROUT: Configure periodic output signal (e.g. PPS) 24d04a53b1SAhmad Fatoum * PPS: trigger internal PPS event for input 25d04a53b1SAhmad Fatoum * into kernel PPS subsystem 26d04a53b1SAhmad Fatoum * @extts: describes configuration for external trigger timestamping. 27d04a53b1SAhmad Fatoum * This is only valid when event == PTP_CLK_REQ_EXTTS. 28d04a53b1SAhmad Fatoum * @perout: describes configuration for periodic output. 29d04a53b1SAhmad Fatoum * This is only valid when event == PTP_CLK_REQ_PEROUT. 30d04a53b1SAhmad Fatoum */ 31d94ba80eSRichard Cochran 32d94ba80eSRichard Cochran struct ptp_clock_request { 33d94ba80eSRichard Cochran enum { 34d94ba80eSRichard Cochran PTP_CLK_REQ_EXTTS, 35d94ba80eSRichard Cochran PTP_CLK_REQ_PEROUT, 36d94ba80eSRichard Cochran PTP_CLK_REQ_PPS, 37d94ba80eSRichard Cochran } type; 38d94ba80eSRichard Cochran union { 39d94ba80eSRichard Cochran struct ptp_extts_request extts; 40d94ba80eSRichard Cochran struct ptp_perout_request perout; 41d94ba80eSRichard Cochran }; 42d94ba80eSRichard Cochran }; 43d94ba80eSRichard Cochran 44719f1aa4SChristopher S. Hall struct system_device_crosststamp; 4536180087SMiroslav Lichvar 4636180087SMiroslav Lichvar /** 4736180087SMiroslav Lichvar * struct ptp_system_timestamp - system time corresponding to a PHC timestamp 4836180087SMiroslav Lichvar */ 4936180087SMiroslav Lichvar struct ptp_system_timestamp { 5036180087SMiroslav Lichvar struct timespec64 pre_ts; 5136180087SMiroslav Lichvar struct timespec64 post_ts; 5236180087SMiroslav Lichvar }; 5336180087SMiroslav Lichvar 54d94ba80eSRichard Cochran /** 55184ecc9eSVincent Cheng * struct ptp_clock_info - describes a PTP hardware clock 56d94ba80eSRichard Cochran * 57d94ba80eSRichard Cochran * @owner: The clock driver should set to THIS_MODULE. 58de465846SRichard Cochran * @name: A short "friendly name" to identify the clock and to 59de465846SRichard Cochran * help distinguish PHY based devices from MAC based ones. 60de465846SRichard Cochran * The string is not meant to be a unique id. 61d94ba80eSRichard Cochran * @max_adj: The maximum possible frequency adjustment, in parts per billon. 62d94ba80eSRichard Cochran * @n_alarm: The number of programmable alarms. 63d94ba80eSRichard Cochran * @n_ext_ts: The number of external time stamp channels. 64d94ba80eSRichard Cochran * @n_per_out: The number of programmable periodic signals. 656092315dSRichard Cochran * @n_pins: The number of programmable pins. 66d94ba80eSRichard Cochran * @pps: Indicates whether the clock supports a PPS callback. 676092315dSRichard Cochran * @pin_config: Array of length 'n_pins'. If the number of 686092315dSRichard Cochran * programmable pins is nonzero, then drivers must 696092315dSRichard Cochran * allocate and initialize this array. 70d94ba80eSRichard Cochran * 71d94ba80eSRichard Cochran * clock operations 72d94ba80eSRichard Cochran * 73d8d26354SRichard Cochran * @adjfine: Adjusts the frequency of the hardware clock. 74d8d26354SRichard Cochran * parameter scaled_ppm: Desired frequency offset from 75d8d26354SRichard Cochran * nominal frequency in parts per million, but with a 76d8d26354SRichard Cochran * 16 bit binary fractional field. 77d8d26354SRichard Cochran * 78d94ba80eSRichard Cochran * @adjfreq: Adjusts the frequency of the hardware clock. 79d8d26354SRichard Cochran * This method is deprecated. New drivers should implement 80d8d26354SRichard Cochran * the @adjfine method instead. 8187f4d7c1SJacob Keller * parameter delta: Desired frequency offset from nominal frequency 8287f4d7c1SJacob Keller * in parts per billion 83d94ba80eSRichard Cochran * 84184ecc9eSVincent Cheng * @adjphase: Adjusts the phase offset of the hardware clock. 85184ecc9eSVincent Cheng * parameter delta: Desired change in nanoseconds. 86184ecc9eSVincent Cheng * 87d94ba80eSRichard Cochran * @adjtime: Shifts the time of the hardware clock. 88d94ba80eSRichard Cochran * parameter delta: Desired change in nanoseconds. 89d94ba80eSRichard Cochran * 9092f17194SRichard Cochran * @gettime64: Reads the current time from the hardware clock. 91916444dfSMiroslav Lichvar * This method is deprecated. New drivers should implement 92916444dfSMiroslav Lichvar * the @gettimex64 method instead. 9392f17194SRichard Cochran * parameter ts: Holds the result. 9492f17194SRichard Cochran * 9536180087SMiroslav Lichvar * @gettimex64: Reads the current time from the hardware clock and optionally 9636180087SMiroslav Lichvar * also the system clock. 9736180087SMiroslav Lichvar * parameter ts: Holds the PHC timestamp. 9836180087SMiroslav Lichvar * parameter sts: If not NULL, it holds a pair of timestamps from 9936180087SMiroslav Lichvar * the system clock. The first reading is made right before 10036180087SMiroslav Lichvar * reading the lowest bits of the PHC timestamp and the second 10136180087SMiroslav Lichvar * reading immediately follows that. 10236180087SMiroslav Lichvar * 103719f1aa4SChristopher S. Hall * @getcrosststamp: Reads the current time from the hardware clock and 104719f1aa4SChristopher S. Hall * system clock simultaneously. 105719f1aa4SChristopher S. Hall * parameter cts: Contains timestamp (device,system) pair, 106719f1aa4SChristopher S. Hall * where system time is realtime and monotonic. 107719f1aa4SChristopher S. Hall * 10892f17194SRichard Cochran * @settime64: Set the current time on the hardware clock. 109d94ba80eSRichard Cochran * parameter ts: Time value to set. 110d94ba80eSRichard Cochran * 11142704b26SGerhard Engleder * @getcycles64: Reads the current free running cycle counter from the hardware 11242704b26SGerhard Engleder * clock. 11342704b26SGerhard Engleder * If @getcycles64 and @getcyclesx64 are not supported, then 11442704b26SGerhard Engleder * @gettime64 or @gettimex64 will be used as default 11542704b26SGerhard Engleder * implementation. 11642704b26SGerhard Engleder * parameter ts: Holds the result. 11742704b26SGerhard Engleder * 11842704b26SGerhard Engleder * @getcyclesx64: Reads the current free running cycle counter from the 11942704b26SGerhard Engleder * hardware clock and optionally also the system clock. 12042704b26SGerhard Engleder * If @getcycles64 and @getcyclesx64 are not supported, then 12142704b26SGerhard Engleder * @gettimex64 will be used as default implementation if 12242704b26SGerhard Engleder * available. 12342704b26SGerhard Engleder * parameter ts: Holds the PHC timestamp. 12442704b26SGerhard Engleder * parameter sts: If not NULL, it holds a pair of timestamps 12542704b26SGerhard Engleder * from the system clock. The first reading is made right before 12642704b26SGerhard Engleder * reading the lowest bits of the PHC timestamp and the second 12742704b26SGerhard Engleder * reading immediately follows that. 12842704b26SGerhard Engleder * 12942704b26SGerhard Engleder * @getcrosscycles: Reads the current free running cycle counter from the 13042704b26SGerhard Engleder * hardware clock and system clock simultaneously. 13142704b26SGerhard Engleder * If @getcycles64 and @getcyclesx64 are not supported, then 13242704b26SGerhard Engleder * @getcrosststamp will be used as default implementation if 13342704b26SGerhard Engleder * available. 13442704b26SGerhard Engleder * parameter cts: Contains timestamp (device,system) pair, 13542704b26SGerhard Engleder * where system time is realtime and monotonic. 13642704b26SGerhard Engleder * 137d94ba80eSRichard Cochran * @enable: Request driver to enable or disable an ancillary feature. 138d94ba80eSRichard Cochran * parameter request: Desired resource to enable or disable. 139d94ba80eSRichard Cochran * parameter on: Caller passes one to enable or zero to disable. 140d94ba80eSRichard Cochran * 1416092315dSRichard Cochran * @verify: Confirm that a pin can perform a given function. The PTP 1426092315dSRichard Cochran * Hardware Clock subsystem maintains the 'pin_config' 1436092315dSRichard Cochran * array on behalf of the drivers, but the PHC subsystem 1446092315dSRichard Cochran * assumes that every pin can perform every function. This 1456092315dSRichard Cochran * hook gives drivers a way of telling the core about 1466092315dSRichard Cochran * limitations on specific pins. This function must return 1476092315dSRichard Cochran * zero if the function can be assigned to this pin, and 1486092315dSRichard Cochran * nonzero otherwise. 1496092315dSRichard Cochran * parameter pin: index of the pin in question. 1506092315dSRichard Cochran * parameter func: the desired function to use. 1516092315dSRichard Cochran * parameter chan: the function channel index to use. 1526092315dSRichard Cochran * 1532c864c78SJacob Keller * @do_aux_work: Request driver to perform auxiliary (periodic) operations 1542c864c78SJacob Keller * Driver should return delay of the next auxiliary work 1552c864c78SJacob Keller * scheduling time (>=0) or negative value in case further 1562c864c78SJacob Keller * scheduling is not required. 157d9535cb7SGrygorii Strashko * 158d94ba80eSRichard Cochran * Drivers should embed their ptp_clock_info within a private 159d94ba80eSRichard Cochran * structure, obtaining a reference to it using container_of(). 160d94ba80eSRichard Cochran * 161d94ba80eSRichard Cochran * The callbacks must all return zero on success, non-zero otherwise. 162d94ba80eSRichard Cochran */ 163d94ba80eSRichard Cochran 164d94ba80eSRichard Cochran struct ptp_clock_info { 165d94ba80eSRichard Cochran struct module *owner; 1665d43f951SYangbo Lu char name[PTP_CLOCK_NAME_LEN]; 167d94ba80eSRichard Cochran s32 max_adj; 168d94ba80eSRichard Cochran int n_alarm; 169d94ba80eSRichard Cochran int n_ext_ts; 170d94ba80eSRichard Cochran int n_per_out; 1716092315dSRichard Cochran int n_pins; 172d94ba80eSRichard Cochran int pps; 1736092315dSRichard Cochran struct ptp_pin_desc *pin_config; 174d8d26354SRichard Cochran int (*adjfine)(struct ptp_clock_info *ptp, long scaled_ppm); 175d94ba80eSRichard Cochran int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta); 176184ecc9eSVincent Cheng int (*adjphase)(struct ptp_clock_info *ptp, s32 phase); 177d94ba80eSRichard Cochran int (*adjtime)(struct ptp_clock_info *ptp, s64 delta); 17892f17194SRichard Cochran int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts); 17936180087SMiroslav Lichvar int (*gettimex64)(struct ptp_clock_info *ptp, struct timespec64 *ts, 18036180087SMiroslav Lichvar struct ptp_system_timestamp *sts); 181719f1aa4SChristopher S. Hall int (*getcrosststamp)(struct ptp_clock_info *ptp, 182719f1aa4SChristopher S. Hall struct system_device_crosststamp *cts); 18392f17194SRichard Cochran int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts); 18442704b26SGerhard Engleder int (*getcycles64)(struct ptp_clock_info *ptp, struct timespec64 *ts); 18542704b26SGerhard Engleder int (*getcyclesx64)(struct ptp_clock_info *ptp, struct timespec64 *ts, 18642704b26SGerhard Engleder struct ptp_system_timestamp *sts); 18742704b26SGerhard Engleder int (*getcrosscycles)(struct ptp_clock_info *ptp, 18842704b26SGerhard Engleder struct system_device_crosststamp *cts); 189d94ba80eSRichard Cochran int (*enable)(struct ptp_clock_info *ptp, 190d94ba80eSRichard Cochran struct ptp_clock_request *request, int on); 1916092315dSRichard Cochran int (*verify)(struct ptp_clock_info *ptp, unsigned int pin, 1926092315dSRichard Cochran enum ptp_pin_function func, unsigned int chan); 193d9535cb7SGrygorii Strashko long (*do_aux_work)(struct ptp_clock_info *ptp); 194d94ba80eSRichard Cochran }; 195d94ba80eSRichard Cochran 196d94ba80eSRichard Cochran struct ptp_clock; 197d94ba80eSRichard Cochran 198d94ba80eSRichard Cochran enum ptp_clock_events { 199d94ba80eSRichard Cochran PTP_CLOCK_ALARM, 200d94ba80eSRichard Cochran PTP_CLOCK_EXTTS, 201d94ba80eSRichard Cochran PTP_CLOCK_PPS, 202220a60a4SBen Hutchings PTP_CLOCK_PPSUSR, 203d94ba80eSRichard Cochran }; 204d94ba80eSRichard Cochran 205d94ba80eSRichard Cochran /** 206d94ba80eSRichard Cochran * struct ptp_clock_event - decribes a PTP hardware clock event 207d94ba80eSRichard Cochran * 208d94ba80eSRichard Cochran * @type: One of the ptp_clock_events enumeration values. 209d94ba80eSRichard Cochran * @index: Identifies the source of the event. 210220a60a4SBen Hutchings * @timestamp: When the event occurred (%PTP_CLOCK_EXTTS only). 211220a60a4SBen Hutchings * @pps_times: When the event occurred (%PTP_CLOCK_PPSUSR only). 212d94ba80eSRichard Cochran */ 213d94ba80eSRichard Cochran 214d94ba80eSRichard Cochran struct ptp_clock_event { 215d94ba80eSRichard Cochran int type; 216d94ba80eSRichard Cochran int index; 217220a60a4SBen Hutchings union { 218d94ba80eSRichard Cochran u64 timestamp; 219220a60a4SBen Hutchings struct pps_event_time pps_times; 220220a60a4SBen Hutchings }; 221d94ba80eSRichard Cochran }; 222d94ba80eSRichard Cochran 2239d9d415fSRadu Pirea (NXP OSS) /** 2249d9d415fSRadu Pirea (NXP OSS) * scaled_ppm_to_ppb() - convert scaled ppm to ppb 2259d9d415fSRadu Pirea (NXP OSS) * 2269d9d415fSRadu Pirea (NXP OSS) * @ppm: Parts per million, but with a 16 bit binary fractional field 2279d9d415fSRadu Pirea (NXP OSS) */ 228adc2e56eSJakub Kicinski static inline long scaled_ppm_to_ppb(long ppm) 2299d9d415fSRadu Pirea (NXP OSS) { 2309d9d415fSRadu Pirea (NXP OSS) /* 2319d9d415fSRadu Pirea (NXP OSS) * The 'freq' field in the 'struct timex' is in parts per 2329d9d415fSRadu Pirea (NXP OSS) * million, but with a 16 bit binary fractional field. 2339d9d415fSRadu Pirea (NXP OSS) * 2349d9d415fSRadu Pirea (NXP OSS) * We want to calculate 2359d9d415fSRadu Pirea (NXP OSS) * 2369d9d415fSRadu Pirea (NXP OSS) * ppb = scaled_ppm * 1000 / 2^16 2379d9d415fSRadu Pirea (NXP OSS) * 2389d9d415fSRadu Pirea (NXP OSS) * which simplifies to 2399d9d415fSRadu Pirea (NXP OSS) * 2409d9d415fSRadu Pirea (NXP OSS) * ppb = scaled_ppm * 125 / 2^13 2419d9d415fSRadu Pirea (NXP OSS) */ 2429d9d415fSRadu Pirea (NXP OSS) s64 ppb = 1 + ppm; 2439d9d415fSRadu Pirea (NXP OSS) 2449d9d415fSRadu Pirea (NXP OSS) ppb *= 125; 2459d9d415fSRadu Pirea (NXP OSS) ppb >>= 13; 246adc2e56eSJakub Kicinski return (long)ppb; 2479d9d415fSRadu Pirea (NXP OSS) } 2489d9d415fSRadu Pirea (NXP OSS) 249e5f31552SArnd Bergmann #if IS_ENABLED(CONFIG_PTP_1588_CLOCK) 250d1cbfd77SNicolas Pitre 251d1cbfd77SNicolas Pitre /** 252d1cbfd77SNicolas Pitre * ptp_clock_register() - register a PTP hardware clock driver 253d1cbfd77SNicolas Pitre * 254d1cbfd77SNicolas Pitre * @info: Structure describing the new clock. 255d1cbfd77SNicolas Pitre * @parent: Pointer to the parent device of the new clock. 256d1cbfd77SNicolas Pitre * 257d1cbfd77SNicolas Pitre * Returns a valid pointer on success or PTR_ERR on failure. If PHC 258d1cbfd77SNicolas Pitre * support is missing at the configuration level, this function 259d1cbfd77SNicolas Pitre * returns NULL, and drivers are expected to gracefully handle that 260d1cbfd77SNicolas Pitre * case separately. 261d1cbfd77SNicolas Pitre */ 262d1cbfd77SNicolas Pitre 263d1cbfd77SNicolas Pitre extern struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, 264d1cbfd77SNicolas Pitre struct device *parent); 265d1cbfd77SNicolas Pitre 266d1cbfd77SNicolas Pitre /** 267d1cbfd77SNicolas Pitre * ptp_clock_unregister() - unregister a PTP hardware clock driver 268d1cbfd77SNicolas Pitre * 269d1cbfd77SNicolas Pitre * @ptp: The clock to remove from service. 270d1cbfd77SNicolas Pitre */ 271d1cbfd77SNicolas Pitre 272d1cbfd77SNicolas Pitre extern int ptp_clock_unregister(struct ptp_clock *ptp); 273d1cbfd77SNicolas Pitre 274d94ba80eSRichard Cochran /** 275d94ba80eSRichard Cochran * ptp_clock_event() - notify the PTP layer about an event 276d94ba80eSRichard Cochran * 277d94ba80eSRichard Cochran * @ptp: The clock obtained from ptp_clock_register(). 278d94ba80eSRichard Cochran * @event: Message structure describing the event. 279d94ba80eSRichard Cochran */ 280d94ba80eSRichard Cochran 281d94ba80eSRichard Cochran extern void ptp_clock_event(struct ptp_clock *ptp, 282d94ba80eSRichard Cochran struct ptp_clock_event *event); 283d94ba80eSRichard Cochran 284995a9090SRichard Cochran /** 285995a9090SRichard Cochran * ptp_clock_index() - obtain the device index of a PTP clock 286995a9090SRichard Cochran * 287995a9090SRichard Cochran * @ptp: The clock obtained from ptp_clock_register(). 288995a9090SRichard Cochran */ 289995a9090SRichard Cochran 290995a9090SRichard Cochran extern int ptp_clock_index(struct ptp_clock *ptp); 291995a9090SRichard Cochran 2926092315dSRichard Cochran /** 2936092315dSRichard Cochran * ptp_find_pin() - obtain the pin index of a given auxiliary function 2946092315dSRichard Cochran * 29562582a7eSRichard Cochran * The caller must hold ptp_clock::pincfg_mux. Drivers do not have 29662582a7eSRichard Cochran * access to that mutex as ptp_clock is an opaque type. However, the 29762582a7eSRichard Cochran * core code acquires the mutex before invoking the driver's 29862582a7eSRichard Cochran * ptp_clock_info::enable() callback, and so drivers may call this 29962582a7eSRichard Cochran * function from that context. 30062582a7eSRichard Cochran * 3016092315dSRichard Cochran * @ptp: The clock obtained from ptp_clock_register(). 3026092315dSRichard Cochran * @func: One of the ptp_pin_function enumerated values. 3036092315dSRichard Cochran * @chan: The particular functional channel to find. 3046092315dSRichard Cochran * Return: Pin index in the range of zero to ptp_clock_caps.n_pins - 1, 3056092315dSRichard Cochran * or -1 if the auxiliary function cannot be found. 3066092315dSRichard Cochran */ 3076092315dSRichard Cochran 3086092315dSRichard Cochran int ptp_find_pin(struct ptp_clock *ptp, 3096092315dSRichard Cochran enum ptp_pin_function func, unsigned int chan); 3106092315dSRichard Cochran 311d9535cb7SGrygorii Strashko /** 31262582a7eSRichard Cochran * ptp_find_pin_unlocked() - wrapper for ptp_find_pin() 31362582a7eSRichard Cochran * 31462582a7eSRichard Cochran * This function acquires the ptp_clock::pincfg_mux mutex before 31562582a7eSRichard Cochran * invoking ptp_find_pin(). Instead of using this function, drivers 31662582a7eSRichard Cochran * should most likely call ptp_find_pin() directly from their 31762582a7eSRichard Cochran * ptp_clock_info::enable() method. 31862582a7eSRichard Cochran * 31962582a7eSRichard Cochran */ 32062582a7eSRichard Cochran 32162582a7eSRichard Cochran int ptp_find_pin_unlocked(struct ptp_clock *ptp, 32262582a7eSRichard Cochran enum ptp_pin_function func, unsigned int chan); 32362582a7eSRichard Cochran 32462582a7eSRichard Cochran /** 325d9535cb7SGrygorii Strashko * ptp_schedule_worker() - schedule ptp auxiliary work 326d9535cb7SGrygorii Strashko * 327d9535cb7SGrygorii Strashko * @ptp: The clock obtained from ptp_clock_register(). 328d9535cb7SGrygorii Strashko * @delay: number of jiffies to wait before queuing 329d9535cb7SGrygorii Strashko * See kthread_queue_delayed_work() for more info. 330d9535cb7SGrygorii Strashko */ 331d9535cb7SGrygorii Strashko 332d9535cb7SGrygorii Strashko int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay); 333d9535cb7SGrygorii Strashko 334544fed47SVladimir Oltean /** 335544fed47SVladimir Oltean * ptp_cancel_worker_sync() - cancel ptp auxiliary clock 336544fed47SVladimir Oltean * 337544fed47SVladimir Oltean * @ptp: The clock obtained from ptp_clock_register(). 338544fed47SVladimir Oltean */ 339544fed47SVladimir Oltean void ptp_cancel_worker_sync(struct ptp_clock *ptp); 340544fed47SVladimir Oltean 341e5f31552SArnd Bergmann #else 342e5f31552SArnd Bergmann static inline struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, 343e5f31552SArnd Bergmann struct device *parent) 344e5f31552SArnd Bergmann { return NULL; } 345e5f31552SArnd Bergmann static inline int ptp_clock_unregister(struct ptp_clock *ptp) 346e5f31552SArnd Bergmann { return 0; } 347e5f31552SArnd Bergmann static inline void ptp_clock_event(struct ptp_clock *ptp, 348e5f31552SArnd Bergmann struct ptp_clock_event *event) 349e5f31552SArnd Bergmann { } 350e5f31552SArnd Bergmann static inline int ptp_clock_index(struct ptp_clock *ptp) 351e5f31552SArnd Bergmann { return -1; } 352e5f31552SArnd Bergmann static inline int ptp_find_pin(struct ptp_clock *ptp, 353e5f31552SArnd Bergmann enum ptp_pin_function func, unsigned int chan) 354e5f31552SArnd Bergmann { return -1; } 35548cec73aSHoratiu Vultur static inline int ptp_find_pin_unlocked(struct ptp_clock *ptp, 35648cec73aSHoratiu Vultur enum ptp_pin_function func, 35748cec73aSHoratiu Vultur unsigned int chan) 35848cec73aSHoratiu Vultur { return -1; } 359e5f31552SArnd Bergmann static inline int ptp_schedule_worker(struct ptp_clock *ptp, 360e5f31552SArnd Bergmann unsigned long delay) 361e5f31552SArnd Bergmann { return -EOPNOTSUPP; } 362e5f31552SArnd Bergmann static inline void ptp_cancel_worker_sync(struct ptp_clock *ptp) 363e5f31552SArnd Bergmann { } 364e5f31552SArnd Bergmann #endif 365e5f31552SArnd Bergmann 366e5f31552SArnd Bergmann #if IS_BUILTIN(CONFIG_PTP_1588_CLOCK) 367e5f31552SArnd Bergmann /* 368e5f31552SArnd Bergmann * These are called by the network core, and don't work if PTP is in 369e5f31552SArnd Bergmann * a loadable module. 370e5f31552SArnd Bergmann */ 371e5f31552SArnd Bergmann 372acb288e8SYangbo Lu /** 373acb288e8SYangbo Lu * ptp_get_vclocks_index() - get all vclocks index on pclock, and 374acb288e8SYangbo Lu * caller is responsible to free memory 375acb288e8SYangbo Lu * of vclock_index 376acb288e8SYangbo Lu * 377acb288e8SYangbo Lu * @pclock_index: phc index of ptp pclock. 378acb288e8SYangbo Lu * @vclock_index: pointer to pointer of vclock index. 379acb288e8SYangbo Lu * 380acb288e8SYangbo Lu * return number of vclocks. 381acb288e8SYangbo Lu */ 382acb288e8SYangbo Lu int ptp_get_vclocks_index(int pclock_index, int **vclock_index); 383acb288e8SYangbo Lu 384895487a3SYangbo Lu /** 385895487a3SYangbo Lu * ptp_convert_timestamp() - convert timestamp to a ptp vclock time 386895487a3SYangbo Lu * 387*d58809d8SGerhard Engleder * @hwtstamp: timestamp 388895487a3SYangbo Lu * @vclock_index: phc index of ptp vclock. 389007747a9SMiroslav Lichvar * 390007747a9SMiroslav Lichvar * Returns converted timestamp, or 0 on error. 391895487a3SYangbo Lu */ 392*d58809d8SGerhard Engleder ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, int vclock_index); 393d1cbfd77SNicolas Pitre #else 394acb288e8SYangbo Lu static inline int ptp_get_vclocks_index(int pclock_index, int **vclock_index) 395acb288e8SYangbo Lu { return 0; } 396*d58809d8SGerhard Engleder static inline ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, 397895487a3SYangbo Lu int vclock_index) 398007747a9SMiroslav Lichvar { return 0; } 399d9535cb7SGrygorii Strashko 400d1cbfd77SNicolas Pitre #endif 401d1cbfd77SNicolas Pitre 40236180087SMiroslav Lichvar static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts) 40336180087SMiroslav Lichvar { 40436180087SMiroslav Lichvar if (sts) 40536180087SMiroslav Lichvar ktime_get_real_ts64(&sts->pre_ts); 40636180087SMiroslav Lichvar } 40736180087SMiroslav Lichvar 40836180087SMiroslav Lichvar static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts) 40936180087SMiroslav Lichvar { 41036180087SMiroslav Lichvar if (sts) 41136180087SMiroslav Lichvar ktime_get_real_ts64(&sts->post_ts); 41236180087SMiroslav Lichvar } 41336180087SMiroslav Lichvar 414d94ba80eSRichard Cochran #endif 415