/* SPDX-License-Identifier: GPL-2.0-only */12#ifndef _ZL3073X_CHAN_H3#define _ZL3073X_CHAN_H45#include <linux/bitfield.h>6#include <linux/stddef.h>7#include <linux/types.h>89#include "regs.h"1011struct zl3073x_dev;1213/**14* struct zl3073x_chan - DPLL channel state15* @mode_refsel: mode and reference selection register value16* @ref_prio: reference priority registers (4 bits per ref, P/N packed)17* @mon_status: monitor status register value18* @refsel_status: reference selection status register value19*/20struct zl3073x_chan {21struct_group(cfg,22u8 mode_refsel;23u8 ref_prio[ZL3073X_NUM_REFS / 2];24);25struct_group(stat,26u8 mon_status;27u8 refsel_status;28);29};3031int zl3073x_chan_state_fetch(struct zl3073x_dev *zldev, u8 index);32const struct zl3073x_chan *zl3073x_chan_state_get(struct zl3073x_dev *zldev,33u8 index);34int zl3073x_chan_state_set(struct zl3073x_dev *zldev, u8 index,35const struct zl3073x_chan *chan);3637int zl3073x_chan_state_update(struct zl3073x_dev *zldev, u8 index);3839/**40* zl3073x_chan_mode_get - get DPLL channel operating mode41* @chan: pointer to channel state42*43* Return: reference selection mode of the given DPLL channel44*/45static inline u8 zl3073x_chan_mode_get(const struct zl3073x_chan *chan)46{47return FIELD_GET(ZL_DPLL_MODE_REFSEL_MODE, chan->mode_refsel);48}4950/**51* zl3073x_chan_ref_get - get manually selected reference52* @chan: pointer to channel state53*54* Return: reference selected in forced reference lock mode55*/56static inline u8 zl3073x_chan_ref_get(const struct zl3073x_chan *chan)57{58return FIELD_GET(ZL_DPLL_MODE_REFSEL_REF, chan->mode_refsel);59}6061/**62* zl3073x_chan_mode_set - set DPLL channel operating mode63* @chan: pointer to channel state64* @mode: mode to set65*/66static inline void zl3073x_chan_mode_set(struct zl3073x_chan *chan, u8 mode)67{68FIELD_MODIFY(ZL_DPLL_MODE_REFSEL_MODE, &chan->mode_refsel, mode);69}7071/**72* zl3073x_chan_ref_set - set manually selected reference73* @chan: pointer to channel state74* @ref: reference to set75*/76static inline void zl3073x_chan_ref_set(struct zl3073x_chan *chan, u8 ref)77{78FIELD_MODIFY(ZL_DPLL_MODE_REFSEL_REF, &chan->mode_refsel, ref);79}8081/**82* zl3073x_chan_ref_prio_get - get reference priority83* @chan: pointer to channel state84* @ref: input reference index85*86* Return: priority of the given reference <0, 15>87*/88static inline u889zl3073x_chan_ref_prio_get(const struct zl3073x_chan *chan, u8 ref)90{91u8 val = chan->ref_prio[ref / 2];9293if (!(ref & 1))94return FIELD_GET(ZL_DPLL_REF_PRIO_REF_P, val);95else96return FIELD_GET(ZL_DPLL_REF_PRIO_REF_N, val);97}9899/**100* zl3073x_chan_ref_prio_set - set reference priority101* @chan: pointer to channel state102* @ref: input reference index103* @prio: priority to set104*/105static inline void106zl3073x_chan_ref_prio_set(struct zl3073x_chan *chan, u8 ref, u8 prio)107{108u8 *val = &chan->ref_prio[ref / 2];109110if (!(ref & 1))111FIELD_MODIFY(ZL_DPLL_REF_PRIO_REF_P, val, prio);112else113FIELD_MODIFY(ZL_DPLL_REF_PRIO_REF_N, val, prio);114}115116/**117* zl3073x_chan_ref_is_selectable - check if reference is selectable118* @chan: pointer to channel state119* @ref: input reference index120*121* Return: true if the reference priority is not NONE, false otherwise122*/123static inline bool124zl3073x_chan_ref_is_selectable(const struct zl3073x_chan *chan, u8 ref)125{126return zl3073x_chan_ref_prio_get(chan, ref) != ZL_DPLL_REF_PRIO_NONE;127}128129/**130* zl3073x_chan_lock_state_get - get DPLL channel lock state131* @chan: pointer to channel state132*133* Return: lock state of the given DPLL channel134*/135static inline u8 zl3073x_chan_lock_state_get(const struct zl3073x_chan *chan)136{137return FIELD_GET(ZL_DPLL_MON_STATUS_STATE, chan->mon_status);138}139140/**141* zl3073x_chan_is_ho_ready - check if holdover is ready142* @chan: pointer to channel state143*144* Return: true if holdover is ready, false otherwise145*/146static inline bool zl3073x_chan_is_ho_ready(const struct zl3073x_chan *chan)147{148return !!FIELD_GET(ZL_DPLL_MON_STATUS_HO_READY, chan->mon_status);149}150151/**152* zl3073x_chan_refsel_state_get - get reference selection state153* @chan: pointer to channel state154*155* Return: reference selection state of the given DPLL channel156*/157static inline u8 zl3073x_chan_refsel_state_get(const struct zl3073x_chan *chan)158{159return FIELD_GET(ZL_DPLL_REFSEL_STATUS_STATE, chan->refsel_status);160}161162/**163* zl3073x_chan_refsel_ref_get - get currently selected reference in auto mode164* @chan: pointer to channel state165*166* Return: reference selected by the DPLL in automatic mode167*/168static inline u8 zl3073x_chan_refsel_ref_get(const struct zl3073x_chan *chan)169{170return FIELD_GET(ZL_DPLL_REFSEL_STATUS_REFSEL, chan->refsel_status);171}172173#endif /* _ZL3073X_CHAN_H */174175176