xref: /linux/drivers/dpll/zl3073x/synth.h (revision 53597deca0e38c30e6cd4ba2114fa42d2bcd85bb)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef _ZL3073X_SYNTH_H
4 #define _ZL3073X_SYNTH_H
5 
6 #include <linux/bitfield.h>
7 #include <linux/math64.h>
8 #include <linux/stddef.h>
9 #include <linux/types.h>
10 
11 #include "regs.h"
12 
13 struct zl3073x_dev;
14 
15 /**
16  * struct zl3073x_synth - synthesizer state
17  * @freq_mult: frequency multiplier
18  * @freq_base: frequency base
19  * @freq_m: frequency numerator
20  * @freq_n: frequency denominator
21  * @ctrl: synth control
22  */
23 struct zl3073x_synth {
24 	struct_group(inv, /* Invariants */
25 		u32	freq_mult;
26 		u16	freq_base;
27 		u16	freq_m;
28 		u16	freq_n;
29 		u8	ctrl;
30 	);
31 };
32 
33 int zl3073x_synth_state_fetch(struct zl3073x_dev *zldev, u8 synth_id);
34 
35 const struct zl3073x_synth *zl3073x_synth_state_get(struct zl3073x_dev *zldev,
36 						    u8 synth_id);
37 
38 /**
39  * zl3073x_synth_dpll_get - get DPLL ID the synth is driven by
40  * @synth: pointer to synth state
41  *
42  * Return: ID of DPLL the given synthetizer is driven by
43  */
44 static inline u8 zl3073x_synth_dpll_get(const struct zl3073x_synth *synth)
45 {
46 	return FIELD_GET(ZL_SYNTH_CTRL_DPLL_SEL, synth->ctrl);
47 }
48 
49 /**
50  * zl3073x_synth_freq_get - get synth current freq
51  * @synth: pointer to synth state
52  *
53  * Return: frequency of given synthetizer
54  */
55 static inline u32 zl3073x_synth_freq_get(const struct zl3073x_synth *synth)
56 {
57 	return mul_u64_u32_div(synth->freq_base * synth->freq_m,
58 			       synth->freq_mult, synth->freq_n);
59 }
60 
61 /**
62  * zl3073x_synth_is_enabled - check if the given synth is enabled
63  * @synth: pointer to synth state
64  *
65  * Return: true if synth is enabled, false otherwise
66  */
67 static inline bool zl3073x_synth_is_enabled(const struct zl3073x_synth *synth)
68 {
69 	return FIELD_GET(ZL_SYNTH_CTRL_EN, synth->ctrl);
70 }
71 
72 #endif /* _ZL3073X_SYNTH_H */
73