1d94ba80eSRichard Cochran /* 2d94ba80eSRichard Cochran * PTP 1588 clock support 3d94ba80eSRichard Cochran * 4d94ba80eSRichard Cochran * Copyright (C) 2010 OMICRON electronics GmbH 5d94ba80eSRichard Cochran * 6d94ba80eSRichard Cochran * This program is free software; you can redistribute it and/or modify 7d94ba80eSRichard Cochran * it under the terms of the GNU General Public License as published by 8d94ba80eSRichard Cochran * the Free Software Foundation; either version 2 of the License, or 9d94ba80eSRichard Cochran * (at your option) any later version. 10d94ba80eSRichard Cochran * 11d94ba80eSRichard Cochran * This program is distributed in the hope that it will be useful, 12d94ba80eSRichard Cochran * but WITHOUT ANY WARRANTY; without even the implied warranty of 13d94ba80eSRichard Cochran * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14d94ba80eSRichard Cochran * GNU General Public License for more details. 15d94ba80eSRichard Cochran * 16d94ba80eSRichard Cochran * You should have received a copy of the GNU General Public License 17d94ba80eSRichard Cochran * along with this program; if not, write to the Free Software 18d94ba80eSRichard Cochran * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19d94ba80eSRichard Cochran */ 20d94ba80eSRichard Cochran 21d94ba80eSRichard Cochran #ifndef _PTP_CLOCK_KERNEL_H_ 22d94ba80eSRichard Cochran #define _PTP_CLOCK_KERNEL_H_ 23d94ba80eSRichard Cochran 241ef76158SRichard Cochran #include <linux/device.h> 25220a60a4SBen Hutchings #include <linux/pps_kernel.h> 26d94ba80eSRichard Cochran #include <linux/ptp_clock.h> 27d94ba80eSRichard Cochran 28d94ba80eSRichard Cochran 29d94ba80eSRichard Cochran struct ptp_clock_request { 30d94ba80eSRichard Cochran enum { 31d94ba80eSRichard Cochran PTP_CLK_REQ_EXTTS, 32d94ba80eSRichard Cochran PTP_CLK_REQ_PEROUT, 33d94ba80eSRichard Cochran PTP_CLK_REQ_PPS, 34d94ba80eSRichard Cochran } type; 35d94ba80eSRichard Cochran union { 36d94ba80eSRichard Cochran struct ptp_extts_request extts; 37d94ba80eSRichard Cochran struct ptp_perout_request perout; 38d94ba80eSRichard Cochran }; 39d94ba80eSRichard Cochran }; 40d94ba80eSRichard Cochran 41d94ba80eSRichard Cochran /** 42d94ba80eSRichard Cochran * struct ptp_clock_info - decribes a PTP hardware clock 43d94ba80eSRichard Cochran * 44d94ba80eSRichard Cochran * @owner: The clock driver should set to THIS_MODULE. 45de465846SRichard Cochran * @name: A short "friendly name" to identify the clock and to 46de465846SRichard Cochran * help distinguish PHY based devices from MAC based ones. 47de465846SRichard Cochran * The string is not meant to be a unique id. 48d94ba80eSRichard Cochran * @max_adj: The maximum possible frequency adjustment, in parts per billon. 49d94ba80eSRichard Cochran * @n_alarm: The number of programmable alarms. 50d94ba80eSRichard Cochran * @n_ext_ts: The number of external time stamp channels. 51d94ba80eSRichard Cochran * @n_per_out: The number of programmable periodic signals. 52d94ba80eSRichard Cochran * @pps: Indicates whether the clock supports a PPS callback. 53d94ba80eSRichard Cochran * 54d94ba80eSRichard Cochran * clock operations 55d94ba80eSRichard Cochran * 56d94ba80eSRichard Cochran * @adjfreq: Adjusts the frequency of the hardware clock. 57*87f4d7c1SJacob Keller * parameter delta: Desired frequency offset from nominal frequency 58*87f4d7c1SJacob Keller * in parts per billion 59d94ba80eSRichard Cochran * 60d94ba80eSRichard Cochran * @adjtime: Shifts the time of the hardware clock. 61d94ba80eSRichard Cochran * parameter delta: Desired change in nanoseconds. 62d94ba80eSRichard Cochran * 63d94ba80eSRichard Cochran * @gettime: Reads the current time from the hardware clock. 64d94ba80eSRichard Cochran * parameter ts: Holds the result. 65d94ba80eSRichard Cochran * 66d94ba80eSRichard Cochran * @settime: Set the current time on the hardware clock. 67d94ba80eSRichard Cochran * parameter ts: Time value to set. 68d94ba80eSRichard Cochran * 69d94ba80eSRichard Cochran * @enable: Request driver to enable or disable an ancillary feature. 70d94ba80eSRichard Cochran * parameter request: Desired resource to enable or disable. 71d94ba80eSRichard Cochran * parameter on: Caller passes one to enable or zero to disable. 72d94ba80eSRichard Cochran * 73d94ba80eSRichard Cochran * Drivers should embed their ptp_clock_info within a private 74d94ba80eSRichard Cochran * structure, obtaining a reference to it using container_of(). 75d94ba80eSRichard Cochran * 76d94ba80eSRichard Cochran * The callbacks must all return zero on success, non-zero otherwise. 77d94ba80eSRichard Cochran */ 78d94ba80eSRichard Cochran 79d94ba80eSRichard Cochran struct ptp_clock_info { 80d94ba80eSRichard Cochran struct module *owner; 81d94ba80eSRichard Cochran char name[16]; 82d94ba80eSRichard Cochran s32 max_adj; 83d94ba80eSRichard Cochran int n_alarm; 84d94ba80eSRichard Cochran int n_ext_ts; 85d94ba80eSRichard Cochran int n_per_out; 86d94ba80eSRichard Cochran int pps; 87d94ba80eSRichard Cochran int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta); 88d94ba80eSRichard Cochran int (*adjtime)(struct ptp_clock_info *ptp, s64 delta); 89d94ba80eSRichard Cochran int (*gettime)(struct ptp_clock_info *ptp, struct timespec *ts); 90d94ba80eSRichard Cochran int (*settime)(struct ptp_clock_info *ptp, const struct timespec *ts); 91d94ba80eSRichard Cochran int (*enable)(struct ptp_clock_info *ptp, 92d94ba80eSRichard Cochran struct ptp_clock_request *request, int on); 93d94ba80eSRichard Cochran }; 94d94ba80eSRichard Cochran 95d94ba80eSRichard Cochran struct ptp_clock; 96d94ba80eSRichard Cochran 97d94ba80eSRichard Cochran /** 98d94ba80eSRichard Cochran * ptp_clock_register() - register a PTP hardware clock driver 99d94ba80eSRichard Cochran * 100d94ba80eSRichard Cochran * @info: Structure describing the new clock. 1011ef76158SRichard Cochran * @parent: Pointer to the parent device of the new clock. 102d94ba80eSRichard Cochran */ 103d94ba80eSRichard Cochran 1041ef76158SRichard Cochran extern struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, 1051ef76158SRichard Cochran struct device *parent); 106d94ba80eSRichard Cochran 107d94ba80eSRichard Cochran /** 108d94ba80eSRichard Cochran * ptp_clock_unregister() - unregister a PTP hardware clock driver 109d94ba80eSRichard Cochran * 110d94ba80eSRichard Cochran * @ptp: The clock to remove from service. 111d94ba80eSRichard Cochran */ 112d94ba80eSRichard Cochran 113d94ba80eSRichard Cochran extern int ptp_clock_unregister(struct ptp_clock *ptp); 114d94ba80eSRichard Cochran 115d94ba80eSRichard Cochran 116d94ba80eSRichard Cochran enum ptp_clock_events { 117d94ba80eSRichard Cochran PTP_CLOCK_ALARM, 118d94ba80eSRichard Cochran PTP_CLOCK_EXTTS, 119d94ba80eSRichard Cochran PTP_CLOCK_PPS, 120220a60a4SBen Hutchings PTP_CLOCK_PPSUSR, 121d94ba80eSRichard Cochran }; 122d94ba80eSRichard Cochran 123d94ba80eSRichard Cochran /** 124d94ba80eSRichard Cochran * struct ptp_clock_event - decribes a PTP hardware clock event 125d94ba80eSRichard Cochran * 126d94ba80eSRichard Cochran * @type: One of the ptp_clock_events enumeration values. 127d94ba80eSRichard Cochran * @index: Identifies the source of the event. 128220a60a4SBen Hutchings * @timestamp: When the event occurred (%PTP_CLOCK_EXTTS only). 129220a60a4SBen Hutchings * @pps_times: When the event occurred (%PTP_CLOCK_PPSUSR only). 130d94ba80eSRichard Cochran */ 131d94ba80eSRichard Cochran 132d94ba80eSRichard Cochran struct ptp_clock_event { 133d94ba80eSRichard Cochran int type; 134d94ba80eSRichard Cochran int index; 135220a60a4SBen Hutchings union { 136d94ba80eSRichard Cochran u64 timestamp; 137220a60a4SBen Hutchings struct pps_event_time pps_times; 138220a60a4SBen Hutchings }; 139d94ba80eSRichard Cochran }; 140d94ba80eSRichard Cochran 141d94ba80eSRichard Cochran /** 142d94ba80eSRichard Cochran * ptp_clock_event() - notify the PTP layer about an event 143d94ba80eSRichard Cochran * 144d94ba80eSRichard Cochran * @ptp: The clock obtained from ptp_clock_register(). 145d94ba80eSRichard Cochran * @event: Message structure describing the event. 146d94ba80eSRichard Cochran */ 147d94ba80eSRichard Cochran 148d94ba80eSRichard Cochran extern void ptp_clock_event(struct ptp_clock *ptp, 149d94ba80eSRichard Cochran struct ptp_clock_event *event); 150d94ba80eSRichard Cochran 151995a9090SRichard Cochran /** 152995a9090SRichard Cochran * ptp_clock_index() - obtain the device index of a PTP clock 153995a9090SRichard Cochran * 154995a9090SRichard Cochran * @ptp: The clock obtained from ptp_clock_register(). 155995a9090SRichard Cochran */ 156995a9090SRichard Cochran 157995a9090SRichard Cochran extern int ptp_clock_index(struct ptp_clock *ptp); 158995a9090SRichard Cochran 159d94ba80eSRichard Cochran #endif 160