.. | .. |
---|
103 | 103 | u64 ns; |
---|
104 | 104 | val = 0; |
---|
105 | 105 | |
---|
106 | | - if (!(fep->hwts_tx_en || fep->hwts_rx_en)) { |
---|
107 | | - dev_err(&fep->pdev->dev, "No ptp stack is running\n"); |
---|
108 | | - return -EINVAL; |
---|
109 | | - } |
---|
110 | | - |
---|
111 | 106 | if (fep->pps_enable == enable) |
---|
112 | 107 | return 0; |
---|
113 | 108 | |
---|
.. | .. |
---|
141 | 136 | * NSEC_PER_SEC - ts.tv_nsec. Add the remaining nanoseconds |
---|
142 | 137 | * to current timer would be next second. |
---|
143 | 138 | */ |
---|
144 | | - tempval = readl(fep->hwp + FEC_ATIME_CTRL); |
---|
145 | | - tempval |= FEC_T_CTRL_CAPTURE; |
---|
146 | | - writel(tempval, fep->hwp + FEC_ATIME_CTRL); |
---|
147 | | - |
---|
148 | | - tempval = readl(fep->hwp + FEC_ATIME); |
---|
| 139 | + tempval = fep->cc.read(&fep->cc); |
---|
149 | 140 | /* Convert the ptp local counter to 1588 timestamp */ |
---|
150 | 141 | ns = timecounter_cyc2time(&fep->tc, tempval); |
---|
151 | 142 | ts = ns_to_timespec64(ns); |
---|
.. | .. |
---|
267 | 258 | fep->cc.mult = FEC_CC_MULT; |
---|
268 | 259 | |
---|
269 | 260 | /* reset the ns time counter */ |
---|
270 | | - timecounter_init(&fep->tc, &fep->cc, ktime_to_ns(ktime_get_real())); |
---|
| 261 | + timecounter_init(&fep->tc, &fep->cc, 0); |
---|
271 | 262 | |
---|
272 | 263 | spin_unlock_irqrestore(&fep->tmreg_lock, flags); |
---|
273 | 264 | } |
---|
.. | .. |
---|
457 | 448 | return -EOPNOTSUPP; |
---|
458 | 449 | } |
---|
459 | 450 | |
---|
| 451 | +/** |
---|
| 452 | + * fec_ptp_disable_hwts - disable hardware time stamping |
---|
| 453 | + * @ndev: pointer to net_device |
---|
| 454 | + */ |
---|
| 455 | +void fec_ptp_disable_hwts(struct net_device *ndev) |
---|
| 456 | +{ |
---|
| 457 | + struct fec_enet_private *fep = netdev_priv(ndev); |
---|
| 458 | + |
---|
| 459 | + fep->hwts_tx_en = 0; |
---|
| 460 | + fep->hwts_rx_en = 0; |
---|
| 461 | +} |
---|
| 462 | + |
---|
460 | 463 | int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr) |
---|
461 | 464 | { |
---|
462 | 465 | struct fec_enet_private *fep = netdev_priv(ndev); |
---|
.. | .. |
---|
483 | 486 | |
---|
484 | 487 | switch (config.rx_filter) { |
---|
485 | 488 | case HWTSTAMP_FILTER_NONE: |
---|
486 | | - if (fep->hwts_rx_en) |
---|
487 | | - fep->hwts_rx_en = 0; |
---|
488 | | - config.rx_filter = HWTSTAMP_FILTER_NONE; |
---|
| 489 | + fep->hwts_rx_en = 0; |
---|
489 | 490 | break; |
---|
490 | 491 | |
---|
491 | 492 | default: |
---|
.. | .. |
---|
512 | 513 | -EFAULT : 0; |
---|
513 | 514 | } |
---|
514 | 515 | |
---|
515 | | -/** |
---|
| 516 | +/* |
---|
516 | 517 | * fec_time_keep - call timecounter_read every second to avoid timer overrun |
---|
517 | 518 | * because ENET just support 32bit counter, will timeout in 4s |
---|
518 | 519 | */ |
---|
.. | .. |
---|
520 | 521 | { |
---|
521 | 522 | struct delayed_work *dwork = to_delayed_work(work); |
---|
522 | 523 | struct fec_enet_private *fep = container_of(dwork, struct fec_enet_private, time_keep); |
---|
523 | | - u64 ns; |
---|
524 | 524 | unsigned long flags; |
---|
525 | 525 | |
---|
526 | 526 | mutex_lock(&fep->ptp_clk_mutex); |
---|
527 | 527 | if (fep->ptp_clk_on) { |
---|
528 | 528 | spin_lock_irqsave(&fep->tmreg_lock, flags); |
---|
529 | | - ns = timecounter_read(&fep->tc); |
---|
| 529 | + timecounter_read(&fep->tc); |
---|
530 | 530 | spin_unlock_irqrestore(&fep->tmreg_lock, flags); |
---|
531 | 531 | } |
---|
532 | 532 | mutex_unlock(&fep->ptp_clk_mutex); |
---|
.. | .. |
---|
567 | 567 | |
---|
568 | 568 | /** |
---|
569 | 569 | * fec_ptp_init |
---|
570 | | - * @ndev: The FEC network adapter |
---|
| 570 | + * @pdev: The FEC network adapter |
---|
| 571 | + * @irq_idx: the interrupt index |
---|
571 | 572 | * |
---|
572 | 573 | * This function performs the required steps for enabling ptp |
---|
573 | 574 | * support. If ptp support has already been loaded it simply calls the |
---|
.. | .. |
---|
582 | 583 | int ret; |
---|
583 | 584 | |
---|
584 | 585 | fep->ptp_caps.owner = THIS_MODULE; |
---|
585 | | - snprintf(fep->ptp_caps.name, 16, "fec ptp"); |
---|
| 586 | + strlcpy(fep->ptp_caps.name, "fec ptp", sizeof(fep->ptp_caps.name)); |
---|
586 | 587 | |
---|
587 | 588 | fep->ptp_caps.max_adj = 250000000; |
---|
588 | 589 | fep->ptp_caps.n_alarm = 0; |
---|
.. | .. |
---|
609 | 610 | |
---|
610 | 611 | INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep); |
---|
611 | 612 | |
---|
612 | | - irq = platform_get_irq_byname(pdev, "pps"); |
---|
| 613 | + irq = platform_get_irq_byname_optional(pdev, "pps"); |
---|
613 | 614 | if (irq < 0) |
---|
614 | | - irq = platform_get_irq(pdev, irq_idx); |
---|
| 615 | + irq = platform_get_irq_optional(pdev, irq_idx); |
---|
615 | 616 | /* Failure to get an irq is not fatal, |
---|
616 | 617 | * only the PTP_CLOCK_PPS clock events should stop |
---|
617 | 618 | */ |
---|
.. | .. |
---|
626 | 627 | fep->ptp_clock = ptp_clock_register(&fep->ptp_caps, &pdev->dev); |
---|
627 | 628 | if (IS_ERR(fep->ptp_clock)) { |
---|
628 | 629 | fep->ptp_clock = NULL; |
---|
629 | | - pr_err("ptp_clock_register failed\n"); |
---|
| 630 | + dev_err(&pdev->dev, "ptp_clock_register failed\n"); |
---|
630 | 631 | } |
---|
631 | 632 | |
---|
632 | 633 | schedule_delayed_work(&fep->time_keep, HZ); |
---|