Lines Matching +full:period +full:- +full:scale

1 // SPDX-License-Identifier: GPL-2.0-only
3 * DFL device driver for Time-of-Day (ToD) private feature
77 * and TOD_ADJUST_COUNT register for in hardware. The dt->tod_lock spinlock must be
83 void __iomem *base = dt->tod_ctrl; in fine_adjust_tod_clock()
101 void __iomem *base = dt->tod_ctrl; in coarse_adjust_tod_clock()
130 void __iomem *base = dt->tod_ctrl; in dfl_tod_adjust_fine()
142 return -ERANGE; in dfl_tod_adjust_fine()
160 spin_lock_irqsave(&dt->tod_lock, flags); in dfl_tod_adjust_fine()
166 spin_unlock_irqrestore(&dt->tod_lock, flags); in dfl_tod_adjust_fine()
174 u32 period, diff, rem, rem_period, adj_period; in dfl_tod_adjust_time() local
175 void __iomem *base = dt->tod_ctrl; in dfl_tod_adjust_time()
183 delta = -delta; in dfl_tod_adjust_time()
185 spin_lock_irqsave(&dt->tod_lock, flags); in dfl_tod_adjust_time()
188 * Get the maximum possible value of the Period register offset in dfl_tod_adjust_time()
189 * adjustment in nanoseconds scale. This depends on the current in dfl_tod_adjust_time()
190 * Period register setting and the maximum and minimum possible in dfl_tod_adjust_time()
191 * values of the Period register. in dfl_tod_adjust_time()
193 period = readl(base + TOD_PERIOD); in dfl_tod_adjust_time()
196 diff = (period - TOD_PERIOD_MIN) >> PERIOD_FRAC_OFFSET; in dfl_tod_adjust_time()
197 adj_period = period - (diff << PERIOD_FRAC_OFFSET); in dfl_tod_adjust_time()
199 rem_period = period - (rem << PERIOD_FRAC_OFFSET); in dfl_tod_adjust_time()
201 diff = (TOD_PERIOD_MAX - period) >> PERIOD_FRAC_OFFSET; in dfl_tod_adjust_time()
202 adj_period = period + (diff << PERIOD_FRAC_OFFSET); in dfl_tod_adjust_time()
204 rem_period = period + (rem << PERIOD_FRAC_OFFSET); in dfl_tod_adjust_time()
212 /* Adjust the period by count cycles to adjust the time */ in dfl_tod_adjust_time()
216 /* If there is a remainder, adjust the period for an additional cycle */ in dfl_tod_adjust_time()
221 spin_unlock_irqrestore(&dt->tod_lock, flags); in dfl_tod_adjust_time()
231 void __iomem *base = dt->tod_ctrl; in dfl_tod_get_timex()
235 spin_lock_irqsave(&dt->tod_lock, flags); in dfl_tod_get_timex()
241 spin_unlock_irqrestore(&dt->tod_lock, flags); in dfl_tod_get_timex()
245 ts->tv_nsec = nanosec; in dfl_tod_get_timex()
246 ts->tv_sec = seconds; in dfl_tod_get_timex()
255 u32 seconds_msb = FIELD_GET(SECONDS_MSB, ts->tv_sec); in dfl_tod_set_time()
256 u32 seconds_lsb = FIELD_GET(SECONDS_LSB, ts->tv_sec); in dfl_tod_set_time()
257 u32 nanosec = FIELD_GET(SECONDS_LSB, ts->tv_nsec); in dfl_tod_set_time()
258 void __iomem *base = dt->tod_ctrl; in dfl_tod_set_time()
261 spin_lock_irqsave(&dt->tod_lock, flags); in dfl_tod_set_time()
265 spin_unlock_irqrestore(&dt->tod_lock, flags); in dfl_tod_set_time()
282 struct device *dev = &ddev->dev; in dfl_tod_probe()
287 return -ENOMEM; in dfl_tod_probe()
289 dt->tod_ctrl = devm_ioremap_resource(dev, &ddev->mmio_res); in dfl_tod_probe()
290 if (IS_ERR(dt->tod_ctrl)) in dfl_tod_probe()
291 return PTR_ERR(dt->tod_ctrl); in dfl_tod_probe()
293 dt->dev = dev; in dfl_tod_probe()
294 spin_lock_init(&dt->tod_lock); in dfl_tod_probe()
297 dt->ptp_clock_ops = dfl_tod_clock_ops; in dfl_tod_probe()
299 dt->ptp_clock = ptp_clock_register(&dt->ptp_clock_ops, dev); in dfl_tod_probe()
300 if (IS_ERR(dt->ptp_clock)) in dfl_tod_probe()
301 return dev_err_probe(dt->dev, PTR_ERR(dt->ptp_clock), in dfl_tod_probe()
309 struct dfl_tod *dt = dev_get_drvdata(&ddev->dev); in dfl_tod_remove()
311 ptp_clock_unregister(dt->ptp_clock); in dfl_tod_remove()
322 .name = "dfl-tod",