Skip to content

Commit 24e4336

Browse files
ivecerakuba-moo
authored andcommitted
dpll: zl3073x: Add output pin frequency helper
Introduce zl3073x_dev_output_pin_freq_get() helper function to compute the output pin frequency based on synthesizer frequency, output divisor, and signal format. For N-div signal formats, the N-pin frequency is additionally divided by esync_n_period. Add zl3073x_out_is_ndiv() helper to check if an output is configured in N-div mode (2_NDIV or 2_NDIV_INV signal formats). Refactor zl3073x_dpll_output_pin_frequency_get() callback to use the new helper, reducing code duplication and enabling reuse of the frequency calculation logic in other contexts. This is a preparatory change for adding current frequency to the supported frequencies list in pin properties. Signed-off-by: Ivan Vecera <ivecera@redhat.com> Link: https://patch.msgid.link/20260205154350.3180465-2-ivecera@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a14d931 commit 24e4336

3 files changed

Lines changed: 48 additions & 38 deletions

File tree

drivers/dpll/zl3073x/core.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,36 @@ u8 zl3073x_dev_out_dpll_get(struct zl3073x_dev *zldev, u8 index)
301301
return zl3073x_synth_dpll_get(synth);
302302
}
303303

304+
/**
305+
* zl3073x_dev_output_pin_freq_get - get output pin frequency
306+
* @zldev: pointer to zl3073x device
307+
* @id: output pin id
308+
*
309+
* Computes the output pin frequency based on the synth frequency, output
310+
* divisor, and signal format. For N-div formats, N-pin frequency is
311+
* additionally divided by esync_n_period.
312+
*
313+
* Return: frequency of the given output pin in Hz
314+
*/
315+
static inline u32
316+
zl3073x_dev_output_pin_freq_get(struct zl3073x_dev *zldev, u8 id)
317+
{
318+
const struct zl3073x_synth *synth;
319+
const struct zl3073x_out *out;
320+
u8 out_id;
321+
u32 freq;
322+
323+
out_id = zl3073x_output_pin_out_get(id);
324+
out = zl3073x_out_state_get(zldev, out_id);
325+
synth = zl3073x_synth_state_get(zldev, zl3073x_out_synth_get(out));
326+
freq = zl3073x_synth_freq_get(synth) / out->div;
327+
328+
if (zl3073x_out_is_ndiv(out) && zl3073x_is_n_pin(id))
329+
freq /= out->esync_n_period;
330+
331+
return freq;
332+
}
333+
304334
/**
305335
* zl3073x_dev_out_is_diff - check if the given output is differential
306336
* @zldev: pointer to zl3073x device

drivers/dpll/zl3073x/dpll.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -916,46 +916,9 @@ zl3073x_dpll_output_pin_frequency_get(const struct dpll_pin *dpll_pin,
916916
struct netlink_ext_ack *extack)
917917
{
918918
struct zl3073x_dpll *zldpll = dpll_priv;
919-
struct zl3073x_dev *zldev = zldpll->dev;
920919
struct zl3073x_dpll_pin *pin = pin_priv;
921-
const struct zl3073x_synth *synth;
922-
const struct zl3073x_out *out;
923-
u32 synth_freq;
924-
u8 out_id;
925920

926-
out_id = zl3073x_output_pin_out_get(pin->id);
927-
out = zl3073x_out_state_get(zldev, out_id);
928-
929-
/* Get attached synth frequency */
930-
synth = zl3073x_synth_state_get(zldev, zl3073x_out_synth_get(out));
931-
synth_freq = zl3073x_synth_freq_get(synth);
932-
933-
switch (zl3073x_out_signal_format_get(out)) {
934-
case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV:
935-
case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV:
936-
/* In case of divided format we have to distiguish between
937-
* given output pin type.
938-
*
939-
* For P-pin the resulting frequency is computed as simple
940-
* division of synth frequency and output divisor.
941-
*
942-
* For N-pin we have to divide additionally by divisor stored
943-
* in esync_n_period output mailbox register that is used as
944-
* N-pin divisor for these modes.
945-
*/
946-
*frequency = synth_freq / out->div;
947-
948-
if (!zl3073x_dpll_is_p_pin(pin))
949-
*frequency = (u32)*frequency / out->esync_n_period;
950-
951-
break;
952-
default:
953-
/* In other modes the resulting frequency is computed as
954-
* division of synth frequency and output divisor.
955-
*/
956-
*frequency = synth_freq / out->div;
957-
break;
958-
}
921+
*frequency = zl3073x_dev_output_pin_freq_get(zldpll->dev, pin->id);
959922

960923
return 0;
961924
}

drivers/dpll/zl3073x/out.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ static inline bool zl3073x_out_is_enabled(const struct zl3073x_out *out)
7979
return !!FIELD_GET(ZL_OUTPUT_CTRL_EN, out->ctrl);
8080
}
8181

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+
*/
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+
8299
/**
83100
* zl3073x_out_synth_get - get synth connected to given output
84101
* @out: pointer to out state

0 commit comments

Comments
 (0)