Lines Matching +full:ptp +full:- +full:timer

1 // SPDX-License-Identifier: GPL-2.0+
2 /* PTP 1588 clock using the Renesas Ethernet AVB
4 * Copyright (C) 2013-2015 Renesas Electronics Corporation
6 * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com>
13 struct net_device *ndev = priv->ndev; in ravb_ptp_tcr_request()
27 struct net_device *ndev = priv->ndev; in ravb_ptp_time_read()
34 ts->tv_nsec = ravb_read(ndev, GCT0); in ravb_ptp_time_read()
35 ts->tv_sec = ravb_read(ndev, GCT1) | in ravb_ptp_time_read()
45 struct net_device *ndev = priv->ndev; in ravb_ptp_time_write()
55 return -EBUSY; in ravb_ptp_time_write()
56 ravb_write(ndev, ts->tv_nsec, GTO0); in ravb_ptp_time_write()
57 ravb_write(ndev, ts->tv_sec, GTO1); in ravb_ptp_time_write()
58 ravb_write(ndev, (ts->tv_sec >> 32) & 0xffff, GTO2); in ravb_ptp_time_write()
67 struct net_device *ndev = priv->ndev; in ravb_ptp_update_compare()
69 * [x-1 to x+1] (x is the configured increment value in in ravb_ptp_update_compare()
71 * not detected when the timer wraps around. in ravb_ptp_update_compare()
73 u32 gti_ns_plus_1 = (priv->ptp.current_addend >> 20) + 1; in ravb_ptp_update_compare()
78 else if (ns > 0 - gti_ns_plus_1) in ravb_ptp_update_compare()
79 ns = 0 - gti_ns_plus_1; in ravb_ptp_update_compare()
83 return -EBUSY; in ravb_ptp_update_compare()
90 /* PTP clock operations */
91 static int ravb_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) in ravb_ptp_adjfine() argument
93 struct ravb_private *priv = container_of(ptp, struct ravb_private, in ravb_ptp_adjfine()
94 ptp.info); in ravb_ptp_adjfine()
95 struct net_device *ndev = priv->ndev; in ravb_ptp_adjfine()
100 addend = (u32)adjust_by_scaled_ppm(priv->ptp.default_addend, in ravb_ptp_adjfine()
103 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_adjfine()
105 priv->ptp.current_addend = addend; in ravb_ptp_adjfine()
109 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_adjfine()
110 return -EBUSY; in ravb_ptp_adjfine()
115 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_adjfine()
120 static int ravb_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) in ravb_ptp_adjtime() argument
122 struct ravb_private *priv = container_of(ptp, struct ravb_private, in ravb_ptp_adjtime()
123 ptp.info); in ravb_ptp_adjtime()
128 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_adjtime()
136 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_adjtime()
141 static int ravb_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts) in ravb_ptp_gettime64() argument
143 struct ravb_private *priv = container_of(ptp, struct ravb_private, in ravb_ptp_gettime64()
144 ptp.info); in ravb_ptp_gettime64()
148 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_gettime64()
150 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_gettime64()
155 static int ravb_ptp_settime64(struct ptp_clock_info *ptp, in ravb_ptp_settime64() argument
158 struct ravb_private *priv = container_of(ptp, struct ravb_private, in ravb_ptp_settime64()
159 ptp.info); in ravb_ptp_settime64()
163 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_settime64()
165 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_settime64()
170 static int ravb_ptp_extts(struct ptp_clock_info *ptp, in ravb_ptp_extts() argument
173 struct ravb_private *priv = container_of(ptp, struct ravb_private, in ravb_ptp_extts()
174 ptp.info); in ravb_ptp_extts()
175 const struct ravb_hw_info *info = priv->info; in ravb_ptp_extts()
176 struct net_device *ndev = priv->ndev; in ravb_ptp_extts()
180 if (req->flags & ~(PTP_ENABLE_FEATURE | in ravb_ptp_extts()
184 return -EOPNOTSUPP; in ravb_ptp_extts()
186 if (req->index) in ravb_ptp_extts()
187 return -EINVAL; in ravb_ptp_extts()
189 if (priv->ptp.extts[req->index] == on) in ravb_ptp_extts()
191 priv->ptp.extts[req->index] = on; in ravb_ptp_extts()
193 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_extts()
194 if (!info->irq_en_dis) in ravb_ptp_extts()
200 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_extts()
205 static int ravb_ptp_perout(struct ptp_clock_info *ptp, in ravb_ptp_perout() argument
208 struct ravb_private *priv = container_of(ptp, struct ravb_private, in ravb_ptp_perout()
209 ptp.info); in ravb_ptp_perout()
210 const struct ravb_hw_info *info = priv->info; in ravb_ptp_perout()
211 struct net_device *ndev = priv->ndev; in ravb_ptp_perout()
217 if (req->flags) in ravb_ptp_perout()
218 return -EOPNOTSUPP; in ravb_ptp_perout()
220 if (req->index) in ravb_ptp_perout()
221 return -EINVAL; in ravb_ptp_perout()
227 start_ns = req->start.sec * NSEC_PER_SEC + req->start.nsec; in ravb_ptp_perout()
228 period_ns = req->period.sec * NSEC_PER_SEC + req->period.nsec; in ravb_ptp_perout()
232 "ptp: start value (nsec) is over limit. Maximum size of start is only 32 bits\n"); in ravb_ptp_perout()
233 return -ERANGE; in ravb_ptp_perout()
238 "ptp: period value (nsec) is over limit. Maximum size of period is only 32 bits\n"); in ravb_ptp_perout()
239 return -ERANGE; in ravb_ptp_perout()
242 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_perout()
244 perout = &priv->ptp.perout[req->index]; in ravb_ptp_perout()
245 perout->target = (u32)start_ns; in ravb_ptp_perout()
246 perout->period = (u32)period_ns; in ravb_ptp_perout()
250 if (!info->irq_en_dis) in ravb_ptp_perout()
256 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_perout()
258 perout = &priv->ptp.perout[req->index]; in ravb_ptp_perout()
259 perout->period = 0; in ravb_ptp_perout()
262 if (!info->irq_en_dis) in ravb_ptp_perout()
267 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_perout()
272 static int ravb_ptp_enable(struct ptp_clock_info *ptp, in ravb_ptp_enable() argument
275 switch (req->type) { in ravb_ptp_enable()
277 return ravb_ptp_extts(ptp, &req->extts, on); in ravb_ptp_enable()
279 return ravb_ptp_perout(ptp, &req->perout, on); in ravb_ptp_enable()
281 return -EOPNOTSUPP; in ravb_ptp_enable()
311 ptp_clock_event(priv->ptp.clock, &event); in ravb_ptp_interrupt()
314 struct ravb_ptp_perout *perout = priv->ptp.perout; in ravb_ptp_interrupt()
316 if (perout->period) { in ravb_ptp_interrupt()
317 perout->target += perout->period; in ravb_ptp_interrupt()
318 ravb_ptp_update_compare(priv, perout->target); in ravb_ptp_interrupt()
330 priv->ptp.info = ravb_ptp_info; in ravb_ptp_init()
332 priv->ptp.default_addend = ravb_read(ndev, GTI); in ravb_ptp_init()
333 priv->ptp.current_addend = priv->ptp.default_addend; in ravb_ptp_init()
335 spin_lock_irqsave(&priv->lock, flags); in ravb_ptp_init()
338 spin_unlock_irqrestore(&priv->lock, flags); in ravb_ptp_init()
340 priv->ptp.clock = ptp_clock_register(&priv->ptp.info, &pdev->dev); in ravb_ptp_init()
350 ptp_clock_unregister(priv->ptp.clock); in ravb_ptp_stop()