/* 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;93ref->freq_ratio_m = 1;94ref->freq_ratio_n = 1;9596return 0;97}9899/**100* zl3073x_ref_is_diff - check if the given input reference is differential101* @ref: pointer to ref state102*103* Return: true if reference is differential, false if reference is single-ended104*/105static inline bool106zl3073x_ref_is_diff(const struct zl3073x_ref *ref)107{108return !!FIELD_GET(ZL_REF_CONFIG_DIFF_EN, ref->config);109}110111/**112* zl3073x_ref_is_enabled - check if the given input reference is enabled113* @ref: pointer to ref state114*115* Return: true if input refernce is enabled, false otherwise116*/117static inline bool118zl3073x_ref_is_enabled(const struct zl3073x_ref *ref)119{120return !!FIELD_GET(ZL_REF_CONFIG_ENABLE, ref->config);121}122123/**124* zl3073x_ref_is_status_ok - check the given input reference status125* @ref: pointer to ref state126*127* Return: true if the status is ok, false otherwise128*/129static inline bool130zl3073x_ref_is_status_ok(const struct zl3073x_ref *ref)131{132return ref->mon_status == ZL_REF_MON_STATUS_OK;133}134135#endif /* _ZL3073X_REF_H */136137138