Lines Matching +full:ptp +full:- +full:timer
1 // SPDX-License-Identifier: GPL-2.0
2 /* Renesas R-Car Gen4 gPTP device driver
15 #define ptp_to_priv(ptp) container_of(ptp, struct rcar_gen4_ptp_private, info) argument
29 static int rcar_gen4_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) in rcar_gen4_ptp_adjfine() argument
31 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); in rcar_gen4_ptp_adjfine()
33 s64 addend = ptp_priv->default_addend; in rcar_gen4_ptp_adjfine()
37 scaled_ppm = -scaled_ppm; in rcar_gen4_ptp_adjfine()
39 addend = neg_adj ? addend - diff : addend + diff; in rcar_gen4_ptp_adjfine()
41 iowrite32(addend, ptp_priv->addr + ptp_priv->offs->increment); in rcar_gen4_ptp_adjfine()
47 static void _rcar_gen4_ptp_gettime(struct ptp_clock_info *ptp, in _rcar_gen4_ptp_gettime() argument
50 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); in _rcar_gen4_ptp_gettime()
52 ts->tv_nsec = ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t0); in _rcar_gen4_ptp_gettime()
53 ts->tv_sec = ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t1) | in _rcar_gen4_ptp_gettime()
54 ((s64)ioread32(ptp_priv->addr + ptp_priv->offs->monitor_t2) << 32); in _rcar_gen4_ptp_gettime()
57 static int rcar_gen4_ptp_gettime(struct ptp_clock_info *ptp, in rcar_gen4_ptp_gettime() argument
60 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); in rcar_gen4_ptp_gettime()
63 spin_lock_irqsave(&ptp_priv->lock, flags); in rcar_gen4_ptp_gettime()
64 _rcar_gen4_ptp_gettime(ptp, ts); in rcar_gen4_ptp_gettime()
65 spin_unlock_irqrestore(&ptp_priv->lock, flags); in rcar_gen4_ptp_gettime()
71 static void _rcar_gen4_ptp_settime(struct ptp_clock_info *ptp, in _rcar_gen4_ptp_settime() argument
74 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); in _rcar_gen4_ptp_settime()
76 iowrite32(1, ptp_priv->addr + ptp_priv->offs->disable); in _rcar_gen4_ptp_settime()
77 iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t2); in _rcar_gen4_ptp_settime()
78 iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t1); in _rcar_gen4_ptp_settime()
79 iowrite32(0, ptp_priv->addr + ptp_priv->offs->config_t0); in _rcar_gen4_ptp_settime()
80 iowrite32(1, ptp_priv->addr + ptp_priv->offs->enable); in _rcar_gen4_ptp_settime()
81 iowrite32(ts->tv_sec >> 32, ptp_priv->addr + ptp_priv->offs->config_t2); in _rcar_gen4_ptp_settime()
82 iowrite32(ts->tv_sec, ptp_priv->addr + ptp_priv->offs->config_t1); in _rcar_gen4_ptp_settime()
83 iowrite32(ts->tv_nsec, ptp_priv->addr + ptp_priv->offs->config_t0); in _rcar_gen4_ptp_settime()
86 static int rcar_gen4_ptp_settime(struct ptp_clock_info *ptp, in rcar_gen4_ptp_settime() argument
89 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); in rcar_gen4_ptp_settime()
92 spin_lock_irqsave(&ptp_priv->lock, flags); in rcar_gen4_ptp_settime()
93 _rcar_gen4_ptp_settime(ptp, ts); in rcar_gen4_ptp_settime()
94 spin_unlock_irqrestore(&ptp_priv->lock, flags); in rcar_gen4_ptp_settime()
99 static int rcar_gen4_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) in rcar_gen4_ptp_adjtime() argument
101 struct rcar_gen4_ptp_private *ptp_priv = ptp_to_priv(ptp); in rcar_gen4_ptp_adjtime()
106 spin_lock_irqsave(&ptp_priv->lock, flags); in rcar_gen4_ptp_adjtime()
107 _rcar_gen4_ptp_gettime(ptp, &ts); in rcar_gen4_ptp_adjtime()
110 _rcar_gen4_ptp_settime(ptp, &ts); in rcar_gen4_ptp_adjtime()
111 spin_unlock_irqrestore(&ptp_priv->lock, flags); in rcar_gen4_ptp_adjtime()
116 static int rcar_gen4_ptp_enable(struct ptp_clock_info *ptp, in rcar_gen4_ptp_enable() argument
119 return -EOPNOTSUPP; in rcar_gen4_ptp_enable()
137 return -EINVAL; in rcar_gen4_ptp_set_offs()
139 ptp_priv->offs = &gen4_offs; in rcar_gen4_ptp_set_offs()
146 /* Timer increment in ns. in rcar_gen4_ptp_rate_to_increment()
147 * bit[31:27] - integer in rcar_gen4_ptp_rate_to_increment()
148 * bit[26:0] - decimal in rcar_gen4_ptp_rate_to_increment()
159 if (ptp_priv->initialized) in rcar_gen4_ptp_register()
162 spin_lock_init(&ptp_priv->lock); in rcar_gen4_ptp_register()
168 ptp_priv->default_addend = rcar_gen4_ptp_rate_to_increment(rate); in rcar_gen4_ptp_register()
169 iowrite32(ptp_priv->default_addend, ptp_priv->addr + ptp_priv->offs->increment); in rcar_gen4_ptp_register()
170 ptp_priv->clock = ptp_clock_register(&ptp_priv->info, NULL); in rcar_gen4_ptp_register()
171 if (IS_ERR(ptp_priv->clock)) in rcar_gen4_ptp_register()
172 return PTR_ERR(ptp_priv->clock); in rcar_gen4_ptp_register()
174 iowrite32(0x01, ptp_priv->addr + ptp_priv->offs->enable); in rcar_gen4_ptp_register()
175 ptp_priv->initialized = true; in rcar_gen4_ptp_register()
183 iowrite32(1, ptp_priv->addr + ptp_priv->offs->disable); in rcar_gen4_ptp_unregister()
185 return ptp_clock_unregister(ptp_priv->clock); in rcar_gen4_ptp_unregister()
191 struct rcar_gen4_ptp_private *ptp; in rcar_gen4_ptp_alloc() local
193 ptp = devm_kzalloc(&pdev->dev, sizeof(*ptp), GFP_KERNEL); in rcar_gen4_ptp_alloc()
194 if (!ptp) in rcar_gen4_ptp_alloc()
197 ptp->info = rcar_gen4_ptp_info; in rcar_gen4_ptp_alloc()
199 return ptp; in rcar_gen4_ptp_alloc()
204 MODULE_DESCRIPTION("Renesas R-Car Gen4 gPTP driver");