Lines Matching +full:high +full:- +full:to +full:- +full:low

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021 Gerhard Engleder <gerhard@engleder-embedded.com> */
9 u32 low; in tsnep_get_system_time() local
10 u32 high; in tsnep_get_system_time() local
12 /* read high dword twice to detect overrun */ in tsnep_get_system_time()
13 high = ioread32(adapter->addr + ECM_SYSTEM_TIME_HIGH); in tsnep_get_system_time()
15 low = ioread32(adapter->addr + ECM_SYSTEM_TIME_LOW); in tsnep_get_system_time()
16 high_before = high; in tsnep_get_system_time()
17 high = ioread32(adapter->addr + ECM_SYSTEM_TIME_HIGH); in tsnep_get_system_time()
18 } while (high != high_before); in tsnep_get_system_time()
19 *time = (((u64)high) << 32) | ((u64)low); in tsnep_get_system_time()
28 return -EINVAL; in tsnep_ptp_ioctl()
31 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) in tsnep_ptp_ioctl()
32 return -EFAULT; in tsnep_ptp_ioctl()
39 return -ERANGE; in tsnep_ptp_ioctl()
62 return -ERANGE; in tsnep_ptp_ioctl()
65 memcpy(&adapter->hwtstamp_config, &config, in tsnep_ptp_ioctl()
66 sizeof(adapter->hwtstamp_config)); in tsnep_ptp_ioctl()
69 if (copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config, in tsnep_ptp_ioctl()
70 sizeof(adapter->hwtstamp_config))) in tsnep_ptp_ioctl()
71 return -EFAULT; in tsnep_ptp_ioctl()
84 scaled_ppm = -scaled_ppm; in tsnep_ptp_adjfine()
88 /* convert from 16 bit to 32 bit binary fractional, divide by 1000000 to in tsnep_ptp_adjfine()
89 * eliminate ppm, multiply with 8 to compensate 8ns clock cycle time, in tsnep_ptp_adjfine()
93 rate_offset <<= 16 - 3; in tsnep_ptp_adjfine()
99 iowrite32(rate_offset & 0xFFFFFFFF, adapter->addr + ECM_CLOCK_RATE); in tsnep_ptp_adjfine()
111 spin_lock_irqsave(&adapter->ptp_lock, flags); in tsnep_ptp_adjtime()
117 /* high dword is buffered in hardware and synchronously written to in tsnep_ptp_adjtime()
118 * system time when low dword is written in tsnep_ptp_adjtime()
120 iowrite32(system_time >> 32, adapter->addr + ECM_SYSTEM_TIME_HIGH); in tsnep_ptp_adjtime()
122 adapter->addr + ECM_SYSTEM_TIME_LOW); in tsnep_ptp_adjtime()
124 spin_unlock_irqrestore(&adapter->ptp_lock, flags); in tsnep_ptp_adjtime()
136 u32 low; in tsnep_ptp_gettimex64() local
137 u32 high; in tsnep_ptp_gettimex64() local
140 /* read high dword twice to detect overrun */ in tsnep_ptp_gettimex64()
141 high = ioread32(adapter->addr + ECM_SYSTEM_TIME_HIGH); in tsnep_ptp_gettimex64()
144 low = ioread32(adapter->addr + ECM_SYSTEM_TIME_LOW); in tsnep_ptp_gettimex64()
146 high_before = high; in tsnep_ptp_gettimex64()
147 high = ioread32(adapter->addr + ECM_SYSTEM_TIME_HIGH); in tsnep_ptp_gettimex64()
148 } while (high != high_before); in tsnep_ptp_gettimex64()
149 system_time = (((u64)high) << 32) | ((u64)low); in tsnep_ptp_gettimex64()
164 spin_lock_irqsave(&adapter->ptp_lock, flags); in tsnep_ptp_settime64()
166 /* high dword is buffered in hardware and synchronously written to in tsnep_ptp_settime64()
167 * system time when low dword is written in tsnep_ptp_settime64()
169 iowrite32(system_time >> 32, adapter->addr + ECM_SYSTEM_TIME_HIGH); in tsnep_ptp_settime64()
171 adapter->addr + ECM_SYSTEM_TIME_LOW); in tsnep_ptp_settime64()
173 spin_unlock_irqrestore(&adapter->ptp_lock, flags); in tsnep_ptp_settime64()
185 u32 low; in tsnep_ptp_getcyclesx64() local
186 u32 high; in tsnep_ptp_getcyclesx64() local
189 /* read high dword twice to detect overrun */ in tsnep_ptp_getcyclesx64()
190 high = ioread32(adapter->addr + ECM_COUNTER_HIGH); in tsnep_ptp_getcyclesx64()
193 low = ioread32(adapter->addr + ECM_COUNTER_LOW); in tsnep_ptp_getcyclesx64()
195 high_before = high; in tsnep_ptp_getcyclesx64()
196 high = ioread32(adapter->addr + ECM_COUNTER_HIGH); in tsnep_ptp_getcyclesx64()
197 } while (high != high_before); in tsnep_ptp_getcyclesx64()
198 counter = (((u64)high) << 32) | ((u64)low); in tsnep_ptp_getcyclesx64()
209 adapter->hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE; in tsnep_ptp_init()
210 adapter->hwtstamp_config.tx_type = HWTSTAMP_TX_OFF; in tsnep_ptp_init()
212 snprintf(adapter->ptp_clock_info.name, 16, "%s", TSNEP); in tsnep_ptp_init()
213 adapter->ptp_clock_info.owner = THIS_MODULE; in tsnep_ptp_init()
214 /* at most 2^-1ns adjustment every clock cycle for 8ns clock cycle time, in tsnep_ptp_init()
215 * stay slightly below because only bits below 2^-1ns are supported in tsnep_ptp_init()
217 adapter->ptp_clock_info.max_adj = (500000000 / 8 - 1); in tsnep_ptp_init()
218 adapter->ptp_clock_info.adjfine = tsnep_ptp_adjfine; in tsnep_ptp_init()
219 adapter->ptp_clock_info.adjtime = tsnep_ptp_adjtime; in tsnep_ptp_init()
220 adapter->ptp_clock_info.gettimex64 = tsnep_ptp_gettimex64; in tsnep_ptp_init()
221 adapter->ptp_clock_info.settime64 = tsnep_ptp_settime64; in tsnep_ptp_init()
222 adapter->ptp_clock_info.getcyclesx64 = tsnep_ptp_getcyclesx64; in tsnep_ptp_init()
224 spin_lock_init(&adapter->ptp_lock); in tsnep_ptp_init()
226 adapter->ptp_clock = ptp_clock_register(&adapter->ptp_clock_info, in tsnep_ptp_init()
227 &adapter->pdev->dev); in tsnep_ptp_init()
228 if (IS_ERR(adapter->ptp_clock)) { in tsnep_ptp_init()
229 netdev_err(adapter->netdev, "ptp_clock_register failed\n"); in tsnep_ptp_init()
231 retval = PTR_ERR(adapter->ptp_clock); in tsnep_ptp_init()
232 adapter->ptp_clock = NULL; in tsnep_ptp_init()
233 } else if (adapter->ptp_clock) { in tsnep_ptp_init()
234 netdev_info(adapter->netdev, "PHC added\n"); in tsnep_ptp_init()
242 if (adapter->ptp_clock) { in tsnep_ptp_cleanup()
243 ptp_clock_unregister(adapter->ptp_clock); in tsnep_ptp_cleanup()
244 netdev_info(adapter->netdev, "PHC removed\n"); in tsnep_ptp_cleanup()