1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef _ZL3073X_OUT_H
4 #define _ZL3073X_OUT_H
5
6 #include <linux/bitfield.h>
7 #include <linux/types.h>
8
9 #include "regs.h"
10
11 struct zl3073x_dev;
12
13 /**
14 * struct zl3073x_out - output state
15 * @div: output divisor
16 * @width: output pulse width
17 * @esync_n_period: embedded sync or n-pin period (for n-div formats)
18 * @esync_n_width: embedded sync or n-pin pulse width
19 * @phase_comp: phase compensation
20 * @ctrl: output control
21 * @mode: output mode
22 */
23 struct zl3073x_out {
24 u32 div;
25 u32 width;
26 u32 esync_n_period;
27 u32 esync_n_width;
28 s32 phase_comp;
29 u8 ctrl;
30 u8 mode;
31 };
32
33 int zl3073x_out_state_fetch(struct zl3073x_dev *zldev, u8 index);
34 const struct zl3073x_out *zl3073x_out_state_get(struct zl3073x_dev *zldev,
35 u8 index);
36
37 int zl3073x_out_state_set(struct zl3073x_dev *zldev, u8 index,
38 const struct zl3073x_out *out);
39
40 /**
41 * zl3073x_out_signal_format_get - get output signal format
42 * @out: pointer to out state
43 *
44 * Return: signal format of given output
45 */
zl3073x_out_signal_format_get(const struct zl3073x_out * out)46 static inline u8 zl3073x_out_signal_format_get(const struct zl3073x_out *out)
47 {
48 return FIELD_GET(ZL_OUTPUT_MODE_SIGNAL_FORMAT, out->mode);
49 }
50
51 /**
52 * zl3073x_out_is_diff - check if the given output is differential
53 * @out: pointer to out state
54 *
55 * Return: true if output is differential, false if output is single-ended
56 */
zl3073x_out_is_diff(const struct zl3073x_out * out)57 static inline bool zl3073x_out_is_diff(const struct zl3073x_out *out)
58 {
59 switch (zl3073x_out_signal_format_get(out)) {
60 case ZL_OUTPUT_MODE_SIGNAL_FORMAT_LVDS:
61 case ZL_OUTPUT_MODE_SIGNAL_FORMAT_DIFF:
62 case ZL_OUTPUT_MODE_SIGNAL_FORMAT_LOWVCM:
63 return true;
64 default:
65 break;
66 }
67
68 return false;
69 }
70
71 /**
72 * zl3073x_out_is_enabled - check if the given output is enabled
73 * @out: pointer to out state
74 *
75 * Return: true if output is enabled, false if output is disabled
76 */
zl3073x_out_is_enabled(const struct zl3073x_out * out)77 static inline bool zl3073x_out_is_enabled(const struct zl3073x_out *out)
78 {
79 return !!FIELD_GET(ZL_OUTPUT_CTRL_EN, out->ctrl);
80 }
81
82 /**
83 * zl3073x_out_is_ndiv - check if the given output is in N-div mode
84 * @out: pointer to out state
85 *
86 * Return: true if output is in N-div mode, false otherwise
87 */
zl3073x_out_is_ndiv(const struct zl3073x_out * out)88 static inline bool zl3073x_out_is_ndiv(const struct zl3073x_out *out)
89 {
90 switch (zl3073x_out_signal_format_get(out)) {
91 case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV:
92 case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV:
93 return true;
94 default:
95 return false;
96 }
97 }
98
99 /**
100 * zl3073x_out_synth_get - get synth connected to given output
101 * @out: pointer to out state
102 *
103 * Return: index of synth connected to given output.
104 */
zl3073x_out_synth_get(const struct zl3073x_out * out)105 static inline u8 zl3073x_out_synth_get(const struct zl3073x_out *out)
106 {
107 return FIELD_GET(ZL_OUTPUT_CTRL_SYNTH_SEL, out->ctrl);
108 }
109
110 #endif /* _ZL3073X_OUT_H */
111