diff options
-rw-r--r-- | drivers/net/ethernet/freescale/Makefile | 1 | ||||
-rw-r--r-- | drivers/ptp/Kconfig | 14 | ||||
-rw-r--r-- | drivers/ptp/Makefile | 1 | ||||
-rw-r--r-- | drivers/ptp/ptp_qoriq.c (renamed from drivers/net/ethernet/freescale/gianfar_ptp.c) | 320 |
4 files changed, 174 insertions, 162 deletions
diff --git a/drivers/net/ethernet/freescale/Makefile b/drivers/net/ethernet/freescale/Makefile index ed8ad0fefbda..0914a3ea4405 100644 --- a/drivers/net/ethernet/freescale/Makefile +++ b/drivers/net/ethernet/freescale/Makefile | |||
@@ -14,7 +14,6 @@ obj-$(CONFIG_FS_ENET) += fs_enet/ | |||
14 | obj-$(CONFIG_FSL_PQ_MDIO) += fsl_pq_mdio.o | 14 | obj-$(CONFIG_FSL_PQ_MDIO) += fsl_pq_mdio.o |
15 | obj-$(CONFIG_FSL_XGMAC_MDIO) += xgmac_mdio.o | 15 | obj-$(CONFIG_FSL_XGMAC_MDIO) += xgmac_mdio.o |
16 | obj-$(CONFIG_GIANFAR) += gianfar_driver.o | 16 | obj-$(CONFIG_GIANFAR) += gianfar_driver.o |
17 | obj-$(CONFIG_PTP_1588_CLOCK_GIANFAR) += gianfar_ptp.o | ||
18 | gianfar_driver-objs := gianfar.o \ | 17 | gianfar_driver-objs := gianfar.o \ |
19 | gianfar_ethtool.o | 18 | gianfar_ethtool.o |
20 | obj-$(CONFIG_UCC_GETH) += ucc_geth_driver.o | 19 | obj-$(CONFIG_UCC_GETH) += ucc_geth_driver.o |
diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig index a21ad10d613c..474c988d2e95 100644 --- a/drivers/ptp/Kconfig +++ b/drivers/ptp/Kconfig | |||
@@ -41,19 +41,19 @@ config PTP_1588_CLOCK_DTE | |||
41 | To compile this driver as a module, choose M here: the module | 41 | To compile this driver as a module, choose M here: the module |
42 | will be called ptp_dte. | 42 | will be called ptp_dte. |
43 | 43 | ||
44 | config PTP_1588_CLOCK_GIANFAR | 44 | config PTP_1588_CLOCK_QORIQ |
45 | tristate "Freescale eTSEC as PTP clock" | 45 | tristate "Freescale QorIQ 1588 timer as PTP clock" |
46 | depends on GIANFAR | 46 | depends on GIANFAR |
47 | depends on PTP_1588_CLOCK | 47 | depends on PTP_1588_CLOCK |
48 | default y | 48 | default y |
49 | help | 49 | help |
50 | This driver adds support for using the eTSEC as a PTP | 50 | This driver adds support for using the Freescale QorIQ 1588 |
51 | clock. This clock is only useful if your PTP programs are | 51 | timer as a PTP clock. This clock is only useful if your PTP |
52 | getting hardware time stamps on the PTP Ethernet packets | 52 | programs are getting hardware time stamps on the PTP Ethernet |
53 | using the SO_TIMESTAMPING API. | 53 | packets using the SO_TIMESTAMPING API. |
54 | 54 | ||
55 | To compile this driver as a module, choose M here: the module | 55 | To compile this driver as a module, choose M here: the module |
56 | will be called gianfar_ptp. | 56 | will be called ptp_qoriq. |
57 | 57 | ||
58 | config PTP_1588_CLOCK_IXP46X | 58 | config PTP_1588_CLOCK_IXP46X |
59 | tristate "Intel IXP46x as PTP clock" | 59 | tristate "Intel IXP46x as PTP clock" |
diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile index fd28207f5379..19efa9cfa950 100644 --- a/drivers/ptp/Makefile +++ b/drivers/ptp/Makefile | |||
@@ -9,3 +9,4 @@ obj-$(CONFIG_PTP_1588_CLOCK_DTE) += ptp_dte.o | |||
9 | obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o | 9 | obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o |
10 | obj-$(CONFIG_PTP_1588_CLOCK_PCH) += ptp_pch.o | 10 | obj-$(CONFIG_PTP_1588_CLOCK_PCH) += ptp_pch.o |
11 | obj-$(CONFIG_PTP_1588_CLOCK_KVM) += ptp_kvm.o | 11 | obj-$(CONFIG_PTP_1588_CLOCK_KVM) += ptp_kvm.o |
12 | obj-$(CONFIG_PTP_1588_CLOCK_QORIQ) += ptp_qoriq.o | ||
diff --git a/drivers/net/ethernet/freescale/gianfar_ptp.c b/drivers/ptp/ptp_qoriq.c index 9f8d4f8e57e3..5110cce78fb5 100644 --- a/drivers/net/ethernet/freescale/gianfar_ptp.c +++ b/drivers/ptp/ptp_qoriq.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * PTP 1588 clock using the eTSEC | 2 | * PTP 1588 clock for Freescale QorIQ 1588 timer |
3 | * | 3 | * |
4 | * Copyright (C) 2010 OMICRON electronics GmbH | 4 | * Copyright (C) 2010 OMICRON electronics GmbH |
5 | * | 5 | * |
@@ -29,16 +29,15 @@ | |||
29 | #include <linux/of_platform.h> | 29 | #include <linux/of_platform.h> |
30 | #include <linux/timex.h> | 30 | #include <linux/timex.h> |
31 | #include <linux/io.h> | 31 | #include <linux/io.h> |
32 | #include <linux/slab.h> | ||
32 | 33 | ||
33 | #include <linux/ptp_clock_kernel.h> | 34 | #include <linux/ptp_clock_kernel.h> |
34 | 35 | ||
35 | #include "gianfar.h" | ||
36 | |||
37 | /* | 36 | /* |
38 | * gianfar ptp registers | 37 | * qoriq ptp registers |
39 | * Generated by regen.tcl on Thu May 13 01:38:57 PM CEST 2010 | 38 | * Generated by regen.tcl on Thu May 13 01:38:57 PM CEST 2010 |
40 | */ | 39 | */ |
41 | struct gianfar_ptp_registers { | 40 | struct qoriq_ptp_registers { |
42 | u32 tmr_ctrl; /* Timer control register */ | 41 | u32 tmr_ctrl; /* Timer control register */ |
43 | u32 tmr_tevent; /* Timestamp event register */ | 42 | u32 tmr_tevent; /* Timestamp event register */ |
44 | u32 tmr_temask; /* Timer event mask register */ | 43 | u32 tmr_temask; /* Timer event mask register */ |
@@ -127,18 +126,19 @@ struct gianfar_ptp_registers { | |||
127 | #define PRSC_OCK_MASK (0xffff) | 126 | #define PRSC_OCK_MASK (0xffff) |
128 | 127 | ||
129 | 128 | ||
130 | #define DRIVER "gianfar_ptp" | 129 | #define DRIVER "ptp_qoriq" |
131 | #define DEFAULT_CKSEL 1 | 130 | #define DEFAULT_CKSEL 1 |
132 | #define N_EXT_TS 2 | 131 | #define N_EXT_TS 2 |
133 | #define REG_SIZE sizeof(struct gianfar_ptp_registers) | 132 | #define REG_SIZE sizeof(struct qoriq_ptp_registers) |
134 | 133 | ||
135 | struct etsects { | 134 | struct qoriq_ptp { |
136 | struct gianfar_ptp_registers __iomem *regs; | 135 | struct qoriq_ptp_registers __iomem *regs; |
137 | spinlock_t lock; /* protects regs */ | 136 | spinlock_t lock; /* protects regs */ |
138 | struct ptp_clock *clock; | 137 | struct ptp_clock *clock; |
139 | struct ptp_clock_info caps; | 138 | struct ptp_clock_info caps; |
140 | struct resource *rsrc; | 139 | struct resource *rsrc; |
141 | int irq; | 140 | int irq; |
141 | int phc_index; | ||
142 | u64 alarm_interval; /* for periodic alarm */ | 142 | u64 alarm_interval; /* for periodic alarm */ |
143 | u64 alarm_value; | 143 | u64 alarm_value; |
144 | u32 tclk_period; /* nanoseconds */ | 144 | u32 tclk_period; /* nanoseconds */ |
@@ -149,54 +149,67 @@ struct etsects { | |||
149 | u32 tmr_fiper2; | 149 | u32 tmr_fiper2; |
150 | }; | 150 | }; |
151 | 151 | ||
152 | static inline u32 qoriq_read(unsigned __iomem *addr) | ||
153 | { | ||
154 | u32 val; | ||
155 | |||
156 | val = ioread32be(addr); | ||
157 | return val; | ||
158 | } | ||
159 | |||
160 | static inline void qoriq_write(unsigned __iomem *addr, u32 val) | ||
161 | { | ||
162 | iowrite32be(val, addr); | ||
163 | } | ||
164 | |||
152 | /* | 165 | /* |
153 | * Register access functions | 166 | * Register access functions |
154 | */ | 167 | */ |
155 | 168 | ||
156 | /* Caller must hold etsects->lock. */ | 169 | /* Caller must hold qoriq_ptp->lock. */ |
157 | static u64 tmr_cnt_read(struct etsects *etsects) | 170 | static u64 tmr_cnt_read(struct qoriq_ptp *qoriq_ptp) |
158 | { | 171 | { |
159 | u64 ns; | 172 | u64 ns; |
160 | u32 lo, hi; | 173 | u32 lo, hi; |
161 | 174 | ||
162 | lo = gfar_read(&etsects->regs->tmr_cnt_l); | 175 | lo = qoriq_read(&qoriq_ptp->regs->tmr_cnt_l); |
163 | hi = gfar_read(&etsects->regs->tmr_cnt_h); | 176 | hi = qoriq_read(&qoriq_ptp->regs->tmr_cnt_h); |
164 | ns = ((u64) hi) << 32; | 177 | ns = ((u64) hi) << 32; |
165 | ns |= lo; | 178 | ns |= lo; |
166 | return ns; | 179 | return ns; |
167 | } | 180 | } |
168 | 181 | ||
169 | /* Caller must hold etsects->lock. */ | 182 | /* Caller must hold qoriq_ptp->lock. */ |
170 | static void tmr_cnt_write(struct etsects *etsects, u64 ns) | 183 | static void tmr_cnt_write(struct qoriq_ptp *qoriq_ptp, u64 ns) |
171 | { | 184 | { |
172 | u32 hi = ns >> 32; | 185 | u32 hi = ns >> 32; |
173 | u32 lo = ns & 0xffffffff; | 186 | u32 lo = ns & 0xffffffff; |
174 | 187 | ||
175 | gfar_write(&etsects->regs->tmr_cnt_l, lo); | 188 | qoriq_write(&qoriq_ptp->regs->tmr_cnt_l, lo); |
176 | gfar_write(&etsects->regs->tmr_cnt_h, hi); | 189 | qoriq_write(&qoriq_ptp->regs->tmr_cnt_h, hi); |
177 | } | 190 | } |
178 | 191 | ||
179 | /* Caller must hold etsects->lock. */ | 192 | /* Caller must hold qoriq_ptp->lock. */ |
180 | static void set_alarm(struct etsects *etsects) | 193 | static void set_alarm(struct qoriq_ptp *qoriq_ptp) |
181 | { | 194 | { |
182 | u64 ns; | 195 | u64 ns; |
183 | u32 lo, hi; | 196 | u32 lo, hi; |
184 | 197 | ||
185 | ns = tmr_cnt_read(etsects) + 1500000000ULL; | 198 | ns = tmr_cnt_read(qoriq_ptp) + 1500000000ULL; |
186 | ns = div_u64(ns, 1000000000UL) * 1000000000ULL; | 199 | ns = div_u64(ns, 1000000000UL) * 1000000000ULL; |
187 | ns -= etsects->tclk_period; | 200 | ns -= qoriq_ptp->tclk_period; |
188 | hi = ns >> 32; | 201 | hi = ns >> 32; |
189 | lo = ns & 0xffffffff; | 202 | lo = ns & 0xffffffff; |
190 | gfar_write(&etsects->regs->tmr_alarm1_l, lo); | 203 | qoriq_write(&qoriq_ptp->regs->tmr_alarm1_l, lo); |
191 | gfar_write(&etsects->regs->tmr_alarm1_h, hi); | 204 | qoriq_write(&qoriq_ptp->regs->tmr_alarm1_h, hi); |
192 | } | 205 | } |
193 | 206 | ||
194 | /* Caller must hold etsects->lock. */ | 207 | /* Caller must hold qoriq_ptp->lock. */ |
195 | static void set_fipers(struct etsects *etsects) | 208 | static void set_fipers(struct qoriq_ptp *qoriq_ptp) |
196 | { | 209 | { |
197 | set_alarm(etsects); | 210 | set_alarm(qoriq_ptp); |
198 | gfar_write(&etsects->regs->tmr_fiper1, etsects->tmr_fiper1); | 211 | qoriq_write(&qoriq_ptp->regs->tmr_fiper1, qoriq_ptp->tmr_fiper1); |
199 | gfar_write(&etsects->regs->tmr_fiper2, etsects->tmr_fiper2); | 212 | qoriq_write(&qoriq_ptp->regs->tmr_fiper2, qoriq_ptp->tmr_fiper2); |
200 | } | 213 | } |
201 | 214 | ||
202 | /* | 215 | /* |
@@ -205,72 +218,72 @@ static void set_fipers(struct etsects *etsects) | |||
205 | 218 | ||
206 | static irqreturn_t isr(int irq, void *priv) | 219 | static irqreturn_t isr(int irq, void *priv) |
207 | { | 220 | { |
208 | struct etsects *etsects = priv; | 221 | struct qoriq_ptp *qoriq_ptp = priv; |
209 | struct ptp_clock_event event; | 222 | struct ptp_clock_event event; |
210 | u64 ns; | 223 | u64 ns; |
211 | u32 ack = 0, lo, hi, mask, val; | 224 | u32 ack = 0, lo, hi, mask, val; |
212 | 225 | ||
213 | val = gfar_read(&etsects->regs->tmr_tevent); | 226 | val = qoriq_read(&qoriq_ptp->regs->tmr_tevent); |
214 | 227 | ||
215 | if (val & ETS1) { | 228 | if (val & ETS1) { |
216 | ack |= ETS1; | 229 | ack |= ETS1; |
217 | hi = gfar_read(&etsects->regs->tmr_etts1_h); | 230 | hi = qoriq_read(&qoriq_ptp->regs->tmr_etts1_h); |
218 | lo = gfar_read(&etsects->regs->tmr_etts1_l); | 231 | lo = qoriq_read(&qoriq_ptp->regs->tmr_etts1_l); |
219 | event.type = PTP_CLOCK_EXTTS; | 232 | event.type = PTP_CLOCK_EXTTS; |
220 | event.index = 0; | 233 | event.index = 0; |
221 | event.timestamp = ((u64) hi) << 32; | 234 | event.timestamp = ((u64) hi) << 32; |
222 | event.timestamp |= lo; | 235 | event.timestamp |= lo; |
223 | ptp_clock_event(etsects->clock, &event); | 236 | ptp_clock_event(qoriq_ptp->clock, &event); |
224 | } | 237 | } |
225 | 238 | ||
226 | if (val & ETS2) { | 239 | if (val & ETS2) { |
227 | ack |= ETS2; | 240 | ack |= ETS2; |
228 | hi = gfar_read(&etsects->regs->tmr_etts2_h); | 241 | hi = qoriq_read(&qoriq_ptp->regs->tmr_etts2_h); |
229 | lo = gfar_read(&etsects->regs->tmr_etts2_l); | 242 | lo = qoriq_read(&qoriq_ptp->regs->tmr_etts2_l); |
230 | event.type = PTP_CLOCK_EXTTS; | 243 | event.type = PTP_CLOCK_EXTTS; |
231 | event.index = 1; | 244 | event.index = 1; |
232 | event.timestamp = ((u64) hi) << 32; | 245 | event.timestamp = ((u64) hi) << 32; |
233 | event.timestamp |= lo; | 246 | event.timestamp |= lo; |
234 | ptp_clock_event(etsects->clock, &event); | 247 | ptp_clock_event(qoriq_ptp->clock, &event); |
235 | } | 248 | } |
236 | 249 | ||
237 | if (val & ALM2) { | 250 | if (val & ALM2) { |
238 | ack |= ALM2; | 251 | ack |= ALM2; |
239 | if (etsects->alarm_value) { | 252 | if (qoriq_ptp->alarm_value) { |
240 | event.type = PTP_CLOCK_ALARM; | 253 | event.type = PTP_CLOCK_ALARM; |
241 | event.index = 0; | 254 | event.index = 0; |
242 | event.timestamp = etsects->alarm_value; | 255 | event.timestamp = qoriq_ptp->alarm_value; |
243 | ptp_clock_event(etsects->clock, &event); | 256 | ptp_clock_event(qoriq_ptp->clock, &event); |
244 | } | 257 | } |
245 | if (etsects->alarm_interval) { | 258 | if (qoriq_ptp->alarm_interval) { |
246 | ns = etsects->alarm_value + etsects->alarm_interval; | 259 | ns = qoriq_ptp->alarm_value + qoriq_ptp->alarm_interval; |
247 | hi = ns >> 32; | 260 | hi = ns >> 32; |
248 | lo = ns & 0xffffffff; | 261 | lo = ns & 0xffffffff; |
249 | spin_lock(&etsects->lock); | 262 | spin_lock(&qoriq_ptp->lock); |
250 | gfar_write(&etsects->regs->tmr_alarm2_l, lo); | 263 | qoriq_write(&qoriq_ptp->regs->tmr_alarm2_l, lo); |
251 | gfar_write(&etsects->regs->tmr_alarm2_h, hi); | 264 | qoriq_write(&qoriq_ptp->regs->tmr_alarm2_h, hi); |
252 | spin_unlock(&etsects->lock); | 265 | spin_unlock(&qoriq_ptp->lock); |
253 | etsects->alarm_value = ns; | 266 | qoriq_ptp->alarm_value = ns; |
254 | } else { | 267 | } else { |
255 | gfar_write(&etsects->regs->tmr_tevent, ALM2); | 268 | qoriq_write(&qoriq_ptp->regs->tmr_tevent, ALM2); |
256 | spin_lock(&etsects->lock); | 269 | spin_lock(&qoriq_ptp->lock); |
257 | mask = gfar_read(&etsects->regs->tmr_temask); | 270 | mask = qoriq_read(&qoriq_ptp->regs->tmr_temask); |
258 | mask &= ~ALM2EN; | 271 | mask &= ~ALM2EN; |
259 | gfar_write(&etsects->regs->tmr_temask, mask); | 272 | qoriq_write(&qoriq_ptp->regs->tmr_temask, mask); |
260 | spin_unlock(&etsects->lock); | 273 | spin_unlock(&qoriq_ptp->lock); |
261 | etsects->alarm_value = 0; | 274 | qoriq_ptp->alarm_value = 0; |
262 | etsects->alarm_interval = 0; | 275 | qoriq_ptp->alarm_interval = 0; |
263 | } | 276 | } |
264 | } | 277 | } |
265 | 278 | ||
266 | if (val & PP1) { | 279 | if (val & PP1) { |
267 | ack |= PP1; | 280 | ack |= PP1; |
268 | event.type = PTP_CLOCK_PPS; | 281 | event.type = PTP_CLOCK_PPS; |
269 | ptp_clock_event(etsects->clock, &event); | 282 | ptp_clock_event(qoriq_ptp->clock, &event); |
270 | } | 283 | } |
271 | 284 | ||
272 | if (ack) { | 285 | if (ack) { |
273 | gfar_write(&etsects->regs->tmr_tevent, ack); | 286 | qoriq_write(&qoriq_ptp->regs->tmr_tevent, ack); |
274 | return IRQ_HANDLED; | 287 | return IRQ_HANDLED; |
275 | } else | 288 | } else |
276 | return IRQ_NONE; | 289 | return IRQ_NONE; |
@@ -280,18 +293,18 @@ static irqreturn_t isr(int irq, void *priv) | |||
280 | * PTP clock operations | 293 | * PTP clock operations |
281 | */ | 294 | */ |
282 | 295 | ||
283 | static int ptp_gianfar_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) | 296 | static int ptp_qoriq_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) |
284 | { | 297 | { |
285 | u64 adj, diff; | 298 | u64 adj, diff; |
286 | u32 tmr_add; | 299 | u32 tmr_add; |
287 | int neg_adj = 0; | 300 | int neg_adj = 0; |
288 | struct etsects *etsects = container_of(ptp, struct etsects, caps); | 301 | struct qoriq_ptp *qoriq_ptp = container_of(ptp, struct qoriq_ptp, caps); |
289 | 302 | ||
290 | if (scaled_ppm < 0) { | 303 | if (scaled_ppm < 0) { |
291 | neg_adj = 1; | 304 | neg_adj = 1; |
292 | scaled_ppm = -scaled_ppm; | 305 | scaled_ppm = -scaled_ppm; |
293 | } | 306 | } |
294 | tmr_add = etsects->tmr_add; | 307 | tmr_add = qoriq_ptp->tmr_add; |
295 | adj = tmr_add; | 308 | adj = tmr_add; |
296 | 309 | ||
297 | /* calculate diff as adj*(scaled_ppm/65536)/1000000 | 310 | /* calculate diff as adj*(scaled_ppm/65536)/1000000 |
@@ -303,70 +316,70 @@ static int ptp_gianfar_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) | |||
303 | 316 | ||
304 | tmr_add = neg_adj ? tmr_add - diff : tmr_add + diff; | 317 | tmr_add = neg_adj ? tmr_add - diff : tmr_add + diff; |
305 | 318 | ||
306 | gfar_write(&etsects->regs->tmr_add, tmr_add); | 319 | qoriq_write(&qoriq_ptp->regs->tmr_add, tmr_add); |
307 | 320 | ||
308 | return 0; | 321 | return 0; |
309 | } | 322 | } |
310 | 323 | ||
311 | static int ptp_gianfar_adjtime(struct ptp_clock_info *ptp, s64 delta) | 324 | static int ptp_qoriq_adjtime(struct ptp_clock_info *ptp, s64 delta) |
312 | { | 325 | { |
313 | s64 now; | 326 | s64 now; |
314 | unsigned long flags; | 327 | unsigned long flags; |
315 | struct etsects *etsects = container_of(ptp, struct etsects, caps); | 328 | struct qoriq_ptp *qoriq_ptp = container_of(ptp, struct qoriq_ptp, caps); |
316 | 329 | ||
317 | spin_lock_irqsave(&etsects->lock, flags); | 330 | spin_lock_irqsave(&qoriq_ptp->lock, flags); |
318 | 331 | ||
319 | now = tmr_cnt_read(etsects); | 332 | now = tmr_cnt_read(qoriq_ptp); |
320 | now += delta; | 333 | now += delta; |
321 | tmr_cnt_write(etsects, now); | 334 | tmr_cnt_write(qoriq_ptp, now); |
322 | set_fipers(etsects); | 335 | set_fipers(qoriq_ptp); |
323 | 336 | ||
324 | spin_unlock_irqrestore(&etsects->lock, flags); | 337 | spin_unlock_irqrestore(&qoriq_ptp->lock, flags); |
325 | 338 | ||
326 | return 0; | 339 | return 0; |
327 | } | 340 | } |
328 | 341 | ||
329 | static int ptp_gianfar_gettime(struct ptp_clock_info *ptp, | 342 | static int ptp_qoriq_gettime(struct ptp_clock_info *ptp, |
330 | struct timespec64 *ts) | 343 | struct timespec64 *ts) |
331 | { | 344 | { |
332 | u64 ns; | 345 | u64 ns; |
333 | unsigned long flags; | 346 | unsigned long flags; |
334 | struct etsects *etsects = container_of(ptp, struct etsects, caps); | 347 | struct qoriq_ptp *qoriq_ptp = container_of(ptp, struct qoriq_ptp, caps); |
335 | 348 | ||
336 | spin_lock_irqsave(&etsects->lock, flags); | 349 | spin_lock_irqsave(&qoriq_ptp->lock, flags); |
337 | 350 | ||
338 | ns = tmr_cnt_read(etsects); | 351 | ns = tmr_cnt_read(qoriq_ptp); |
339 | 352 | ||
340 | spin_unlock_irqrestore(&etsects->lock, flags); | 353 | spin_unlock_irqrestore(&qoriq_ptp->lock, flags); |
341 | 354 | ||
342 | *ts = ns_to_timespec64(ns); | 355 | *ts = ns_to_timespec64(ns); |
343 | 356 | ||
344 | return 0; | 357 | return 0; |
345 | } | 358 | } |
346 | 359 | ||
347 | static int ptp_gianfar_settime(struct ptp_clock_info *ptp, | 360 | static int ptp_qoriq_settime(struct ptp_clock_info *ptp, |
348 | const struct timespec64 *ts) | 361 | const struct timespec64 *ts) |
349 | { | 362 | { |
350 | u64 ns; | 363 | u64 ns; |
351 | unsigned long flags; | 364 | unsigned long flags; |
352 | struct etsects *etsects = container_of(ptp, struct etsects, caps); | 365 | struct qoriq_ptp *qoriq_ptp = container_of(ptp, struct qoriq_ptp, caps); |
353 | 366 | ||
354 | ns = timespec64_to_ns(ts); | 367 | ns = timespec64_to_ns(ts); |
355 | 368 | ||
356 | spin_lock_irqsave(&etsects->lock, flags); | 369 | spin_lock_irqsave(&qoriq_ptp->lock, flags); |
357 | 370 | ||
358 | tmr_cnt_write(etsects, ns); | 371 | tmr_cnt_write(qoriq_ptp, ns); |
359 | set_fipers(etsects); | 372 | set_fipers(qoriq_ptp); |
360 | 373 | ||
361 | spin_unlock_irqrestore(&etsects->lock, flags); | 374 | spin_unlock_irqrestore(&qoriq_ptp->lock, flags); |
362 | 375 | ||
363 | return 0; | 376 | return 0; |
364 | } | 377 | } |
365 | 378 | ||
366 | static int ptp_gianfar_enable(struct ptp_clock_info *ptp, | 379 | static int ptp_qoriq_enable(struct ptp_clock_info *ptp, |
367 | struct ptp_clock_request *rq, int on) | 380 | struct ptp_clock_request *rq, int on) |
368 | { | 381 | { |
369 | struct etsects *etsects = container_of(ptp, struct etsects, caps); | 382 | struct qoriq_ptp *qoriq_ptp = container_of(ptp, struct qoriq_ptp, caps); |
370 | unsigned long flags; | 383 | unsigned long flags; |
371 | u32 bit, mask; | 384 | u32 bit, mask; |
372 | 385 | ||
@@ -382,25 +395,25 @@ static int ptp_gianfar_enable(struct ptp_clock_info *ptp, | |||
382 | default: | 395 | default: |
383 | return -EINVAL; | 396 | return -EINVAL; |
384 | } | 397 | } |
385 | spin_lock_irqsave(&etsects->lock, flags); | 398 | spin_lock_irqsave(&qoriq_ptp->lock, flags); |
386 | mask = gfar_read(&etsects->regs->tmr_temask); | 399 | mask = qoriq_read(&qoriq_ptp->regs->tmr_temask); |
387 | if (on) | 400 | if (on) |
388 | mask |= bit; | 401 | mask |= bit; |
389 | else | 402 | else |
390 | mask &= ~bit; | 403 | mask &= ~bit; |
391 | gfar_write(&etsects->regs->tmr_temask, mask); | 404 | qoriq_write(&qoriq_ptp->regs->tmr_temask, mask); |
392 | spin_unlock_irqrestore(&etsects->lock, flags); | 405 | spin_unlock_irqrestore(&qoriq_ptp->lock, flags); |
393 | return 0; | 406 | return 0; |
394 | 407 | ||
395 | case PTP_CLK_REQ_PPS: | 408 | case PTP_CLK_REQ_PPS: |
396 | spin_lock_irqsave(&etsects->lock, flags); | 409 | spin_lock_irqsave(&qoriq_ptp->lock, flags); |
397 | mask = gfar_read(&etsects->regs->tmr_temask); | 410 | mask = qoriq_read(&qoriq_ptp->regs->tmr_temask); |
398 | if (on) | 411 | if (on) |
399 | mask |= PP1EN; | 412 | mask |= PP1EN; |
400 | else | 413 | else |
401 | mask &= ~PP1EN; | 414 | mask &= ~PP1EN; |
402 | gfar_write(&etsects->regs->tmr_temask, mask); | 415 | qoriq_write(&qoriq_ptp->regs->tmr_temask, mask); |
403 | spin_unlock_irqrestore(&etsects->lock, flags); | 416 | spin_unlock_irqrestore(&qoriq_ptp->lock, flags); |
404 | return 0; | 417 | return 0; |
405 | 418 | ||
406 | default: | 419 | default: |
@@ -410,142 +423,141 @@ static int ptp_gianfar_enable(struct ptp_clock_info *ptp, | |||
410 | return -EOPNOTSUPP; | 423 | return -EOPNOTSUPP; |
411 | } | 424 | } |
412 | 425 | ||
413 | static const struct ptp_clock_info ptp_gianfar_caps = { | 426 | static const struct ptp_clock_info ptp_qoriq_caps = { |
414 | .owner = THIS_MODULE, | 427 | .owner = THIS_MODULE, |
415 | .name = "gianfar clock", | 428 | .name = "qoriq ptp clock", |
416 | .max_adj = 512000, | 429 | .max_adj = 512000, |
417 | .n_alarm = 0, | 430 | .n_alarm = 0, |
418 | .n_ext_ts = N_EXT_TS, | 431 | .n_ext_ts = N_EXT_TS, |
419 | .n_per_out = 0, | 432 | .n_per_out = 0, |
420 | .n_pins = 0, | 433 | .n_pins = 0, |
421 | .pps = 1, | 434 | .pps = 1, |
422 | .adjfine = ptp_gianfar_adjfine, | 435 | .adjfine = ptp_qoriq_adjfine, |
423 | .adjtime = ptp_gianfar_adjtime, | 436 | .adjtime = ptp_qoriq_adjtime, |
424 | .gettime64 = ptp_gianfar_gettime, | 437 | .gettime64 = ptp_qoriq_gettime, |
425 | .settime64 = ptp_gianfar_settime, | 438 | .settime64 = ptp_qoriq_settime, |
426 | .enable = ptp_gianfar_enable, | 439 | .enable = ptp_qoriq_enable, |
427 | }; | 440 | }; |
428 | 441 | ||
429 | static int gianfar_ptp_probe(struct platform_device *dev) | 442 | static int qoriq_ptp_probe(struct platform_device *dev) |
430 | { | 443 | { |
431 | struct device_node *node = dev->dev.of_node; | 444 | struct device_node *node = dev->dev.of_node; |
432 | struct etsects *etsects; | 445 | struct qoriq_ptp *qoriq_ptp; |
433 | struct timespec64 now; | 446 | struct timespec64 now; |
434 | int err = -ENOMEM; | 447 | int err = -ENOMEM; |
435 | u32 tmr_ctrl; | 448 | u32 tmr_ctrl; |
436 | unsigned long flags; | 449 | unsigned long flags; |
437 | 450 | ||
438 | etsects = kzalloc(sizeof(*etsects), GFP_KERNEL); | 451 | qoriq_ptp = kzalloc(sizeof(*qoriq_ptp), GFP_KERNEL); |
439 | if (!etsects) | 452 | if (!qoriq_ptp) |
440 | goto no_memory; | 453 | goto no_memory; |
441 | 454 | ||
442 | err = -ENODEV; | 455 | err = -ENODEV; |
443 | 456 | ||
444 | etsects->caps = ptp_gianfar_caps; | 457 | qoriq_ptp->caps = ptp_qoriq_caps; |
445 | 458 | ||
446 | if (of_property_read_u32(node, "fsl,cksel", &etsects->cksel)) | 459 | if (of_property_read_u32(node, "fsl,cksel", &qoriq_ptp->cksel)) |
447 | etsects->cksel = DEFAULT_CKSEL; | 460 | qoriq_ptp->cksel = DEFAULT_CKSEL; |
448 | 461 | ||
449 | if (of_property_read_u32(node, | 462 | if (of_property_read_u32(node, |
450 | "fsl,tclk-period", &etsects->tclk_period) || | 463 | "fsl,tclk-period", &qoriq_ptp->tclk_period) || |
451 | of_property_read_u32(node, | 464 | of_property_read_u32(node, |
452 | "fsl,tmr-prsc", &etsects->tmr_prsc) || | 465 | "fsl,tmr-prsc", &qoriq_ptp->tmr_prsc) || |
453 | of_property_read_u32(node, | 466 | of_property_read_u32(node, |
454 | "fsl,tmr-add", &etsects->tmr_add) || | 467 | "fsl,tmr-add", &qoriq_ptp->tmr_add) || |
455 | of_property_read_u32(node, | 468 | of_property_read_u32(node, |
456 | "fsl,tmr-fiper1", &etsects->tmr_fiper1) || | 469 | "fsl,tmr-fiper1", &qoriq_ptp->tmr_fiper1) || |
457 | of_property_read_u32(node, | 470 | of_property_read_u32(node, |
458 | "fsl,tmr-fiper2", &etsects->tmr_fiper2) || | 471 | "fsl,tmr-fiper2", &qoriq_ptp->tmr_fiper2) || |
459 | of_property_read_u32(node, | 472 | of_property_read_u32(node, |
460 | "fsl,max-adj", &etsects->caps.max_adj)) { | 473 | "fsl,max-adj", &qoriq_ptp->caps.max_adj)) { |
461 | pr_err("device tree node missing required elements\n"); | 474 | pr_err("device tree node missing required elements\n"); |
462 | goto no_node; | 475 | goto no_node; |
463 | } | 476 | } |
464 | 477 | ||
465 | etsects->irq = platform_get_irq(dev, 0); | 478 | qoriq_ptp->irq = platform_get_irq(dev, 0); |
466 | 479 | ||
467 | if (etsects->irq < 0) { | 480 | if (qoriq_ptp->irq < 0) { |
468 | pr_err("irq not in device tree\n"); | 481 | pr_err("irq not in device tree\n"); |
469 | goto no_node; | 482 | goto no_node; |
470 | } | 483 | } |
471 | if (request_irq(etsects->irq, isr, 0, DRIVER, etsects)) { | 484 | if (request_irq(qoriq_ptp->irq, isr, 0, DRIVER, qoriq_ptp)) { |
472 | pr_err("request_irq failed\n"); | 485 | pr_err("request_irq failed\n"); |
473 | goto no_node; | 486 | goto no_node; |
474 | } | 487 | } |
475 | 488 | ||
476 | etsects->rsrc = platform_get_resource(dev, IORESOURCE_MEM, 0); | 489 | qoriq_ptp->rsrc = platform_get_resource(dev, IORESOURCE_MEM, 0); |
477 | if (!etsects->rsrc) { | 490 | if (!qoriq_ptp->rsrc) { |
478 | pr_err("no resource\n"); | 491 | pr_err("no resource\n"); |
479 | goto no_resource; | 492 | goto no_resource; |
480 | } | 493 | } |
481 | if (request_resource(&iomem_resource, etsects->rsrc)) { | 494 | if (request_resource(&iomem_resource, qoriq_ptp->rsrc)) { |
482 | pr_err("resource busy\n"); | 495 | pr_err("resource busy\n"); |
483 | goto no_resource; | 496 | goto no_resource; |
484 | } | 497 | } |
485 | 498 | ||
486 | spin_lock_init(&etsects->lock); | 499 | spin_lock_init(&qoriq_ptp->lock); |
487 | 500 | ||
488 | etsects->regs = ioremap(etsects->rsrc->start, | 501 | qoriq_ptp->regs = ioremap(qoriq_ptp->rsrc->start, |
489 | resource_size(etsects->rsrc)); | 502 | resource_size(qoriq_ptp->rsrc)); |
490 | if (!etsects->regs) { | 503 | if (!qoriq_ptp->regs) { |
491 | pr_err("ioremap ptp registers failed\n"); | 504 | pr_err("ioremap ptp registers failed\n"); |
492 | goto no_ioremap; | 505 | goto no_ioremap; |
493 | } | 506 | } |
494 | getnstimeofday64(&now); | 507 | getnstimeofday64(&now); |
495 | ptp_gianfar_settime(&etsects->caps, &now); | 508 | ptp_qoriq_settime(&qoriq_ptp->caps, &now); |
496 | 509 | ||
497 | tmr_ctrl = | 510 | tmr_ctrl = |
498 | (etsects->tclk_period & TCLK_PERIOD_MASK) << TCLK_PERIOD_SHIFT | | 511 | (qoriq_ptp->tclk_period & TCLK_PERIOD_MASK) << TCLK_PERIOD_SHIFT | |
499 | (etsects->cksel & CKSEL_MASK) << CKSEL_SHIFT; | 512 | (qoriq_ptp->cksel & CKSEL_MASK) << CKSEL_SHIFT; |
500 | 513 | ||
501 | spin_lock_irqsave(&etsects->lock, flags); | 514 | spin_lock_irqsave(&qoriq_ptp->lock, flags); |
502 | 515 | ||
503 | gfar_write(&etsects->regs->tmr_ctrl, tmr_ctrl); | 516 | qoriq_write(&qoriq_ptp->regs->tmr_ctrl, tmr_ctrl); |
504 | gfar_write(&etsects->regs->tmr_add, etsects->tmr_add); | 517 | qoriq_write(&qoriq_ptp->regs->tmr_add, qoriq_ptp->tmr_add); |
505 | gfar_write(&etsects->regs->tmr_prsc, etsects->tmr_prsc); | 518 | qoriq_write(&qoriq_ptp->regs->tmr_prsc, qoriq_ptp->tmr_prsc); |
506 | gfar_write(&etsects->regs->tmr_fiper1, etsects->tmr_fiper1); | 519 | qoriq_write(&qoriq_ptp->regs->tmr_fiper1, qoriq_ptp->tmr_fiper1); |
507 | gfar_write(&etsects->regs->tmr_fiper2, etsects->tmr_fiper2); | 520 | qoriq_write(&qoriq_ptp->regs->tmr_fiper2, qoriq_ptp->tmr_fiper2); |
508 | set_alarm(etsects); | 521 | set_alarm(qoriq_ptp); |
509 | gfar_write(&etsects->regs->tmr_ctrl, tmr_ctrl|FIPERST|RTPE|TE|FRD); | 522 | qoriq_write(&qoriq_ptp->regs->tmr_ctrl, tmr_ctrl|FIPERST|RTPE|TE|FRD); |
510 | 523 | ||
511 | spin_unlock_irqrestore(&etsects->lock, flags); | 524 | spin_unlock_irqrestore(&qoriq_ptp->lock, flags); |
512 | 525 | ||
513 | etsects->clock = ptp_clock_register(&etsects->caps, &dev->dev); | 526 | qoriq_ptp->clock = ptp_clock_register(&qoriq_ptp->caps, &dev->dev); |
514 | if (IS_ERR(etsects->clock)) { | 527 | if (IS_ERR(qoriq_ptp->clock)) { |
515 | err = PTR_ERR(etsects->clock); | 528 | err = PTR_ERR(qoriq_ptp->clock); |
516 | goto no_clock; | 529 | goto no_clock; |
517 | } | 530 | } |
518 | gfar_phc_index = ptp_clock_index(etsects->clock); | 531 | qoriq_ptp->phc_index = ptp_clock_index(qoriq_ptp->clock); |
519 | 532 | ||
520 | platform_set_drvdata(dev, etsects); | 533 | platform_set_drvdata(dev, qoriq_ptp); |
521 | 534 | ||
522 | return 0; | 535 | return 0; |
523 | 536 | ||
524 | no_clock: | 537 | no_clock: |
525 | iounmap(etsects->regs); | 538 | iounmap(qoriq_ptp->regs); |
526 | no_ioremap: | 539 | no_ioremap: |
527 | release_resource(etsects->rsrc); | 540 | release_resource(qoriq_ptp->rsrc); |
528 | no_resource: | 541 | no_resource: |
529 | free_irq(etsects->irq, etsects); | 542 | free_irq(qoriq_ptp->irq, qoriq_ptp); |
530 | no_node: | 543 | no_node: |
531 | kfree(etsects); | 544 | kfree(qoriq_ptp); |
532 | no_memory: | 545 | no_memory: |
533 | return err; | 546 | return err; |
534 | } | 547 | } |
535 | 548 | ||
536 | static int gianfar_ptp_remove(struct platform_device *dev) | 549 | static int qoriq_ptp_remove(struct platform_device *dev) |
537 | { | 550 | { |
538 | struct etsects *etsects = platform_get_drvdata(dev); | 551 | struct qoriq_ptp *qoriq_ptp = platform_get_drvdata(dev); |
539 | 552 | ||
540 | gfar_write(&etsects->regs->tmr_temask, 0); | 553 | qoriq_write(&qoriq_ptp->regs->tmr_temask, 0); |
541 | gfar_write(&etsects->regs->tmr_ctrl, 0); | 554 | qoriq_write(&qoriq_ptp->regs->tmr_ctrl, 0); |
542 | 555 | ||
543 | gfar_phc_index = -1; | 556 | ptp_clock_unregister(qoriq_ptp->clock); |
544 | ptp_clock_unregister(etsects->clock); | 557 | iounmap(qoriq_ptp->regs); |
545 | iounmap(etsects->regs); | 558 | release_resource(qoriq_ptp->rsrc); |
546 | release_resource(etsects->rsrc); | 559 | free_irq(qoriq_ptp->irq, qoriq_ptp); |
547 | free_irq(etsects->irq, etsects); | 560 | kfree(qoriq_ptp); |
548 | kfree(etsects); | ||
549 | 561 | ||
550 | return 0; | 562 | return 0; |
551 | } | 563 | } |
@@ -556,17 +568,17 @@ static const struct of_device_id match_table[] = { | |||
556 | }; | 568 | }; |
557 | MODULE_DEVICE_TABLE(of, match_table); | 569 | MODULE_DEVICE_TABLE(of, match_table); |
558 | 570 | ||
559 | static struct platform_driver gianfar_ptp_driver = { | 571 | static struct platform_driver qoriq_ptp_driver = { |
560 | .driver = { | 572 | .driver = { |
561 | .name = "gianfar_ptp", | 573 | .name = "ptp_qoriq", |
562 | .of_match_table = match_table, | 574 | .of_match_table = match_table, |
563 | }, | 575 | }, |
564 | .probe = gianfar_ptp_probe, | 576 | .probe = qoriq_ptp_probe, |
565 | .remove = gianfar_ptp_remove, | 577 | .remove = qoriq_ptp_remove, |
566 | }; | 578 | }; |
567 | 579 | ||
568 | module_platform_driver(gianfar_ptp_driver); | 580 | module_platform_driver(qoriq_ptp_driver); |
569 | 581 | ||
570 | MODULE_AUTHOR("Richard Cochran <richardcochran@gmail.com>"); | 582 | MODULE_AUTHOR("Richard Cochran <richardcochran@gmail.com>"); |
571 | MODULE_DESCRIPTION("PTP clock using the eTSEC"); | 583 | MODULE_DESCRIPTION("PTP clock for Freescale QorIQ 1588 timer"); |
572 | MODULE_LICENSE("GPL"); | 584 | MODULE_LICENSE("GPL"); |