/* SPDX-License-Identifier: GPL-2.0-only */12#ifndef _ZL3073X_REF_H3#define _ZL3073X_REF_H45#include <linux/bitfield.h>6#include <linux/math64.h>7#include <linux/types.h>89#include "regs.h"1011struct zl3073x_dev;1213/**14* struct zl3073x_ref - input reference state15* @ffo: current fractional frequency offset16* @phase_comp: phase compensation17* @esync_n_div: divisor for embedded sync or n-divided signal formats18* @freq_base: frequency base19* @freq_mult: frequnecy multiplier20* @freq_ratio_m: FEC mode multiplier21* @freq_ratio_n: FEC mode divisor22* @config: reference config23* @sync_ctrl: reference sync control24* @mon_status: reference monitor status25*/26struct zl3073x_ref {27s64 ffo;28u64 phase_comp;29u32 esync_n_div;30u16 freq_base;31u16 freq_mult;32u16 freq_ratio_m;33u16 freq_ratio_n;34u8 config;35u8 sync_ctrl;36u8 mon_status;37};3839int zl3073x_ref_state_fetch(struct zl3073x_dev *zldev, u8 index);4041const struct zl3073x_ref *zl3073x_ref_state_get(struct zl3073x_dev *zldev,42u8 index);4344int zl3073x_ref_state_set(struct zl3073x_dev *zldev, u8 index,45const struct zl3073x_ref *ref);4647int zl3073x_ref_freq_factorize(u32 freq, u16 *base, u16 *mult);4849/**50* zl3073x_ref_ffo_get - get current fractional frequency offset51* @ref: pointer to ref state52*53* Return: the latest measured fractional frequency offset54*/55static inline s6456zl3073x_ref_ffo_get(const struct zl3073x_ref *ref)57{58return ref->ffo;59}6061/**62* zl3073x_ref_freq_get - get given input reference frequency63* @ref: pointer to ref state64*65* Return: frequency of the given input reference66*/67static inline u3268zl3073x_ref_freq_get(const struct zl3073x_ref *ref)69{70return mul_u64_u32_div(ref->freq_base * ref->freq_mult,71ref->freq_ratio_m, ref->freq_ratio_n);72}7374/**75* zl3073x_ref_freq_set - set given input reference frequency76* @ref: pointer to ref state77* @freq: frequency to be set78*79* Return: 0 on success, <0 when frequency cannot be factorized80*/81static inline int82zl3073x_ref_freq_set(struct zl3073x_ref *ref, u32 freq)83{84u16 base, mult;85int rc;8687rc = zl3073x_ref_freq_factorize(freq, &base, &mult);88if (rc)89return rc;9091ref->freq_base = base;92ref->freq_mult = mult;9394return 0;95}9697/**98* zl3073x_ref_is_diff - check if the given input reference is differential99* @ref: pointer to ref state100*101* Return: true if reference is differential, false if reference is single-ended102*/103static inline bool104zl3073x_ref_is_diff(const struct zl3073x_ref *ref)105{106return !!FIELD_GET(ZL_REF_CONFIG_DIFF_EN, ref->config);107}108109/**110* zl3073x_ref_is_enabled - check if the given input reference is enabled111* @ref: pointer to ref state112*113* Return: true if input refernce is enabled, false otherwise114*/115static inline bool116zl3073x_ref_is_enabled(const struct zl3073x_ref *ref)117{118return !!FIELD_GET(ZL_REF_CONFIG_ENABLE, ref->config);119}120121/**122* zl3073x_ref_is_status_ok - check the given input reference status123* @ref: pointer to ref state124*125* Return: true if the status is ok, false otherwise126*/127static inline bool128zl3073x_ref_is_status_ok(const struct zl3073x_ref *ref)129{130return ref->mon_status == ZL_REF_MON_STATUS_OK;131}132133#endif /* _ZL3073X_REF_H */134135136