Skip to content

Commit 9dd4e02

Browse files
Furong Xukuba-moo
authored andcommitted
net: stmmac: Convert open-coded register polling to helper macro
Drop the open-coded register polling routines. Use readl_poll_timeout_atomic() in atomic state. Also adjust the delay time to 10us which seems more reasonable. Tested on NXP i.MX8MP and ROCKCHIP RK3588 boards, the break condition was met right after the first polling, no delay involved at all. So the 10us delay should be long enough for most cases. Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Furong Xu <0x1207@gmail.com> Link: https://patch.msgid.link/20250927081036.10611-1-0x1207@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 74f7c52 commit 9dd4e02

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
135135
static int config_addend(void __iomem *ioaddr, u32 addend)
136136
{
137137
u32 value;
138-
int limit;
139138

140139
writel(addend, ioaddr + PTP_TAR);
141140
/* issue command to update the addend value */
@@ -144,23 +143,15 @@ static int config_addend(void __iomem *ioaddr, u32 addend)
144143
writel(value, ioaddr + PTP_TCR);
145144

146145
/* wait for present addend update to complete */
147-
limit = 10;
148-
while (limit--) {
149-
if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSADDREG))
150-
break;
151-
mdelay(10);
152-
}
153-
if (limit < 0)
154-
return -EBUSY;
155-
156-
return 0;
146+
return readl_poll_timeout_atomic(ioaddr + PTP_TCR, value,
147+
!(value & PTP_TCR_TSADDREG),
148+
10, 100000);
157149
}
158150

159151
static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
160152
int add_sub, int gmac4)
161153
{
162154
u32 value;
163-
int limit;
164155

165156
if (add_sub) {
166157
/* If the new sec value needs to be subtracted with
@@ -187,16 +178,9 @@ static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
187178
writel(value, ioaddr + PTP_TCR);
188179

189180
/* wait for present system time adjust/update to complete */
190-
limit = 10;
191-
while (limit--) {
192-
if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSUPDT))
193-
break;
194-
mdelay(10);
195-
}
196-
if (limit < 0)
197-
return -EBUSY;
198-
199-
return 0;
181+
return readl_poll_timeout_atomic(ioaddr + PTP_TCR, value,
182+
!(value & PTP_TCR_TSUPDT),
183+
10, 100000);
200184
}
201185

202186
static void get_systime(void __iomem *ioaddr, u64 *systime)

0 commit comments

Comments
 (0)