hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
....@@ -1,25 +1,16 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*******************************************************************************
23 Copyright (C) 2013 Vayavya Labs Pvt Ltd
34
45 This implements all the API for managing HW timestamp & PTP.
56
6
- This program is free software; you can redistribute it and/or modify it
7
- under the terms and conditions of the GNU General Public License,
8
- version 2, as published by the Free Software Foundation.
9
-
10
- This program is distributed in the hope it will be useful, but WITHOUT
11
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- more details.
14
-
15
- The full GNU General Public License is included in this distribution in
16
- the file called "COPYING".
177
188 Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
199 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
2010 *******************************************************************************/
2111
2212 #include <linux/io.h>
13
+#include <linux/iopoll.h>
2314 #include <linux/delay.h>
2415 #include "common.h"
2516 #include "stmmac_ptp.h"
....@@ -67,7 +58,6 @@
6758
6859 static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
6960 {
70
- int limit;
7161 u32 value;
7262
7363 writel(sec, ioaddr + PTP_STSUR);
....@@ -78,16 +68,9 @@
7868 writel(value, ioaddr + PTP_TCR);
7969
8070 /* wait for present system time initialize to complete */
81
- limit = 10;
82
- while (limit--) {
83
- if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSINIT))
84
- break;
85
- mdelay(10);
86
- }
87
- if (limit < 0)
88
- return -EBUSY;
89
-
90
- return 0;
71
+ return readl_poll_timeout_atomic(ioaddr + PTP_TCR, value,
72
+ !(value & PTP_TCR_TSINIT),
73
+ 10, 100000);
9174 }
9275
9376 static int config_addend(void __iomem *ioaddr, u32 addend)
....@@ -159,15 +142,20 @@
159142
160143 static void get_systime(void __iomem *ioaddr, u64 *systime)
161144 {
162
- u64 ns;
145
+ u64 ns, sec0, sec1;
163146
164
- /* Get the TSSS value */
165
- ns = readl(ioaddr + PTP_STNSR);
166
- /* Get the TSS and convert sec time value to nanosecond */
167
- ns += readl(ioaddr + PTP_STSR) * 1000000000ULL;
147
+ /* Get the TSS value */
148
+ sec1 = readl_relaxed(ioaddr + PTP_STSR);
149
+ do {
150
+ sec0 = sec1;
151
+ /* Get the TSSS value */
152
+ ns = readl_relaxed(ioaddr + PTP_STNSR);
153
+ /* Get the TSS value */
154
+ sec1 = readl_relaxed(ioaddr + PTP_STSR);
155
+ } while (sec0 != sec1);
168156
169157 if (systime)
170
- *systime = ns;
158
+ *systime = ns + (sec1 * 1000000000ULL);
171159 }
172160
173161 const struct stmmac_hwtimestamp stmmac_ptp = {