Skip to content

Commit 76b7bcc

Browse files
yangbolu1991MaureenHelm
authored andcommitted
drivers: eth_stm32_hal: adjust ptp clock rate based on nominal frequency
Adjusted ptp clock rate based on nominal frequency. Signed-off-by: Yangbo Lu <[email protected]>
1 parent 969e619 commit 76b7bcc

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

drivers/ethernet/eth_stm32_hal.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,25 +1503,15 @@ static int ptp_clock_stm32_rate_adjust(const struct device *dev, double ratio)
15031503
int key, ret;
15041504
uint32_t addend_val;
15051505

1506-
/* No change needed */
1507-
if (ratio == 1.0L) {
1508-
return 0;
1509-
}
1510-
15111506
key = irq_lock();
15121507

1513-
ratio *= (double)eth_dev_data->clk_ratio_adj;
1514-
15151508
/* Limit possible ratio */
15161509
if (ratio * 100 < CONFIG_ETH_STM32_HAL_PTP_CLOCK_ADJ_MIN_PCT ||
15171510
ratio * 100 > CONFIG_ETH_STM32_HAL_PTP_CLOCK_ADJ_MAX_PCT) {
15181511
ret = -EINVAL;
15191512
goto error;
15201513
}
15211514

1522-
/* Save new ratio */
1523-
eth_dev_data->clk_ratio_adj = ratio;
1524-
15251515
/* Update addend register */
15261516
addend_val = UINT32_MAX * (double)eth_dev_data->clk_ratio * ratio;
15271517

@@ -1619,12 +1609,10 @@ static int ptp_stm32_init(const struct device *port)
16191609
* clk_ratio is a ratio between desired PTP clock frequency and HCLK rate.
16201610
* Because HCLK is defined by a physical oscillator, it might drift due
16211611
* to manufacturing tolerances and environmental effects (e.g. temperature).
1622-
* clk_ratio_adj compensates for such inaccuracies. It starts off as 1.0
1623-
* and gets adjusted by calling ptp_clock_stm32_rate_adjust().
1612+
* It gets adjusted by calling ptp_clock_stm32_rate_adjust().
16241613
*/
1625-
eth_dev_data->clk_ratio_adj = 1.0f;
16261614
addend_val =
1627-
UINT32_MAX * eth_dev_data->clk_ratio * eth_dev_data->clk_ratio_adj;
1615+
UINT32_MAX * eth_dev_data->clk_ratio;
16281616
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_ethernet)
16291617
heth->Instance->MACTSAR = addend_val;
16301618
heth->Instance->MACTSCR |= ETH_MACTSCR_TSADDREG;

drivers/ethernet/eth_stm32_hal_priv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct eth_stm32_hal_dev_data {
6060
#if defined(CONFIG_PTP_CLOCK_STM32_HAL)
6161
const struct device *ptp_clock;
6262
float clk_ratio;
63-
float clk_ratio_adj;
6463
#endif /* CONFIG_PTP_CLOCK_STM32_HAL */
6564
#if defined(CONFIG_NET_STATISTICS_ETHERNET)
6665
struct net_stats_eth stats;

0 commit comments

Comments
 (0)