mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-09 06:14:34 +02:00
Replace the per-reference frequency offset measurement (which was redundant with measured-frequency) with a direct read of the DPLL's delta frequency offset vs its tracked input reference. The new implementation uses the dpll_df_offset_x register with ref_ofst=1 via the dpll_df_read_x semaphore mechanism. This provides 2^-48 resolution (~3.5 fE) and reports the actual frequency difference between the DPLL and its active input. Switch supported_ffo from DPLL_FFO_PORT_RXTX_RATE to DPLL_FFO_PIN_DEVICE so FFO is reported only in the per-parent context for the active input pin. Use atomic64_t for freq_offset to prevent torn reads on 32-bit architectures between the periodic worker and netlink callbacks. Rewrite ffo_check to compare the cached df_offset converted to PPT instead of using the old per-reference measurement. Remove the ref_ffo_update periodic measurement and the ref ffo field since they are no longer needed. Changes v3 -> v4: - Switch to DPLL_FFO_PIN_DEVICE, remove dpll=NULL guard - Use atomic64_t for freq_offset (torn read on 32-bit) Reviewed-by: Petr Oros <poros@redhat.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> Link: https://patch.msgid.link/20260511155816.99936-3-ivecera@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
192 lines
4.5 KiB
C
192 lines
4.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
#ifndef _ZL3073X_REF_H
|
|
#define _ZL3073X_REF_H
|
|
|
|
#include <linux/bitfield.h>
|
|
#include <linux/math64.h>
|
|
#include <linux/stddef.h>
|
|
#include <linux/types.h>
|
|
|
|
#include "regs.h"
|
|
|
|
struct zl3073x_dev;
|
|
|
|
/**
|
|
* struct zl3073x_ref - input reference state
|
|
* @phase_comp: phase compensation
|
|
* @esync_n_div: divisor for embedded sync or n-divided signal formats
|
|
* @freq_base: frequency base
|
|
* @freq_mult: frequnecy multiplier
|
|
* @freq_ratio_m: FEC mode multiplier
|
|
* @freq_ratio_n: FEC mode divisor
|
|
* @sync_ctrl: reference sync control
|
|
* @config: reference config
|
|
* @meas_freq: measured input frequency in Hz
|
|
* @mon_status: reference monitor status
|
|
*/
|
|
struct zl3073x_ref {
|
|
struct_group(cfg, /* Configuration */
|
|
u64 phase_comp;
|
|
u32 esync_n_div;
|
|
u16 freq_base;
|
|
u16 freq_mult;
|
|
u16 freq_ratio_m;
|
|
u16 freq_ratio_n;
|
|
u8 sync_ctrl;
|
|
);
|
|
struct_group(inv, /* Invariants */
|
|
u8 config;
|
|
);
|
|
struct_group(stat, /* Status */
|
|
u32 meas_freq;
|
|
u8 mon_status;
|
|
);
|
|
};
|
|
|
|
int zl3073x_ref_state_fetch(struct zl3073x_dev *zldev, u8 index);
|
|
|
|
const struct zl3073x_ref *zl3073x_ref_state_get(struct zl3073x_dev *zldev,
|
|
u8 index);
|
|
|
|
int zl3073x_ref_state_set(struct zl3073x_dev *zldev, u8 index,
|
|
const struct zl3073x_ref *ref);
|
|
|
|
int zl3073x_ref_state_update(struct zl3073x_dev *zldev, u8 index);
|
|
|
|
int zl3073x_ref_freq_factorize(u32 freq, u16 *base, u16 *mult);
|
|
|
|
/**
|
|
* zl3073x_ref_meas_freq_get - get measured input frequency
|
|
* @ref: pointer to ref state
|
|
*
|
|
* Return: measured input frequency in Hz
|
|
*/
|
|
static inline u32
|
|
zl3073x_ref_meas_freq_get(const struct zl3073x_ref *ref)
|
|
{
|
|
return ref->meas_freq;
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_freq_get - get given input reference frequency
|
|
* @ref: pointer to ref state
|
|
*
|
|
* Return: frequency of the given input reference
|
|
*/
|
|
static inline u32
|
|
zl3073x_ref_freq_get(const struct zl3073x_ref *ref)
|
|
{
|
|
return mul_u64_u32_div(ref->freq_base * ref->freq_mult,
|
|
ref->freq_ratio_m, ref->freq_ratio_n);
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_freq_set - set given input reference frequency
|
|
* @ref: pointer to ref state
|
|
* @freq: frequency to be set
|
|
*
|
|
* Return: 0 on success, <0 when frequency cannot be factorized
|
|
*/
|
|
static inline int
|
|
zl3073x_ref_freq_set(struct zl3073x_ref *ref, u32 freq)
|
|
{
|
|
u16 base, mult;
|
|
int rc;
|
|
|
|
rc = zl3073x_ref_freq_factorize(freq, &base, &mult);
|
|
if (rc)
|
|
return rc;
|
|
|
|
ref->freq_base = base;
|
|
ref->freq_mult = mult;
|
|
ref->freq_ratio_m = 1;
|
|
ref->freq_ratio_n = 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_sync_mode_get - get sync control mode
|
|
* @ref: pointer to ref state
|
|
*
|
|
* Return: sync control mode (ZL_REF_SYNC_CTRL_MODE_*)
|
|
*/
|
|
static inline u8
|
|
zl3073x_ref_sync_mode_get(const struct zl3073x_ref *ref)
|
|
{
|
|
return FIELD_GET(ZL_REF_SYNC_CTRL_MODE, ref->sync_ctrl);
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_sync_mode_set - set sync control mode
|
|
* @ref: pointer to ref state
|
|
* @mode: sync control mode (ZL_REF_SYNC_CTRL_MODE_*)
|
|
*/
|
|
static inline void
|
|
zl3073x_ref_sync_mode_set(struct zl3073x_ref *ref, u8 mode)
|
|
{
|
|
FIELD_MODIFY(ZL_REF_SYNC_CTRL_MODE, &ref->sync_ctrl, mode);
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_sync_pair_get - get sync pair reference index
|
|
* @ref: pointer to ref state
|
|
*
|
|
* Return: paired reference index
|
|
*/
|
|
static inline u8
|
|
zl3073x_ref_sync_pair_get(const struct zl3073x_ref *ref)
|
|
{
|
|
return FIELD_GET(ZL_REF_SYNC_CTRL_PAIR, ref->sync_ctrl);
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_sync_pair_set - set sync pair reference index
|
|
* @ref: pointer to ref state
|
|
* @pair: paired reference index
|
|
*/
|
|
static inline void
|
|
zl3073x_ref_sync_pair_set(struct zl3073x_ref *ref, u8 pair)
|
|
{
|
|
FIELD_MODIFY(ZL_REF_SYNC_CTRL_PAIR, &ref->sync_ctrl, pair);
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_is_diff - check if the given input reference is differential
|
|
* @ref: pointer to ref state
|
|
*
|
|
* Return: true if reference is differential, false if reference is single-ended
|
|
*/
|
|
static inline bool
|
|
zl3073x_ref_is_diff(const struct zl3073x_ref *ref)
|
|
{
|
|
return !!FIELD_GET(ZL_REF_CONFIG_DIFF_EN, ref->config);
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_is_enabled - check if the given input reference is enabled
|
|
* @ref: pointer to ref state
|
|
*
|
|
* Return: true if input refernce is enabled, false otherwise
|
|
*/
|
|
static inline bool
|
|
zl3073x_ref_is_enabled(const struct zl3073x_ref *ref)
|
|
{
|
|
return !!FIELD_GET(ZL_REF_CONFIG_ENABLE, ref->config);
|
|
}
|
|
|
|
/**
|
|
* zl3073x_ref_is_status_ok - check the given input reference status
|
|
* @ref: pointer to ref state
|
|
*
|
|
* Return: true if the status is ok, false otherwise
|
|
*/
|
|
static inline bool
|
|
zl3073x_ref_is_status_ok(const struct zl3073x_ref *ref)
|
|
{
|
|
return ref->mon_status == ZL_REF_MON_STATUS_OK;
|
|
}
|
|
|
|
#endif /* _ZL3073X_REF_H */
|