dpll: zl3073x: Refactor state management
Subsystems (4)
Ivan Vecera
maintainerv2 cover dpll: zl3073x: Refactor state management
This patch set is a refactoring of the zl3073x driver to clean up state management, improve modularity, and significantly reduce on-demand I/O.
The driver's dpll.c implementation previously performed on-demand register reads and writes (wrapped in mailbox operations) to get or set properties like frequency, phase, and embedded-sync settings. This cluttered the DPLL logic with low-level I/O, duplicated locking, and led to inefficient bus traffic.
This series addresses this by:
1. Splitting the monolithic 'core.c' into logical units ('ref.c', 'out.c', 'synth.c').
2. Implementing a full read/write-back cache for 'zl3073x_ref' and 'zl3073x_out' structures.
All state is now read once during '_state_fetch()' (and status updated periodically). DPLL get callbacks read from this cache. Set callbacks modify a copy of the state, which is then committed via a new '..._state_set()' function. These '_state_set' functions compare the new state to the cached state and write *only* the modified register values back to the hardware, all within a single mailbox sequence.
The result is a much cleaner 'dpll.c' that is almost entirely free of direct register I/O, and all state logic is properly encapsulated in its respective file.
The series is broken down as follows:
* Patch 1: Changes the state structs to store raw register values (e.g., 'config', 'ctrl') instead of parsed booleans, centralizing parsing logic into the helpers.
* Patch 2: Splits the logic from 'core.c' into new 'ref.c', 'out.c' and 'synth.c' files, creating a 'zl3073x_dev_...' abstraction layer.
* Patch 3: Introduces the caching concept by reading and caching the reference monitor status periodically, removing scattered reads from 'dpll.c'.
* Patch 4: Expands the 'zl3073x_ref' struct to cache *all* reference properties and adds 'zl3073x_ref_state_set()' to write back changes.
* Patch 5: Does the same for the 'zl3073x_out' struct, caching all output properties and adding 'zl3073x_out_state_set()'.
* Patch 6: A final cleanup that removes the 'zl3073x_dev_...' wrapper functions that became redundant after the refactoring.
Changes:
v2:
- addressed issues found by patchwork bot (details in each patch)
Ivan Vecera (6):
dpll: zl3073x: Store raw register values instead of parsed state
dpll: zl3073x: Split ref, out, and synth logic from core
dpll: zl3073x: Cache reference monitor status
dpll: zl3073x: Cache all reference properties in zl3073x_ref
dpll: zl3073x: Cache all output properties in zl3073x_out
dpll: zl3073x: Remove unused dev wrappers
drivers/dpll/zl3073x/Makefile | 3 +- drivers/dpll/zl3073x/core.c | 243 +---------- drivers/dpll/zl3073x/core.h | 184 +++----- drivers/dpll/zl3073x/dpll.c | 776 ++++++++-------------------------- drivers/dpll/zl3073x/out.c | 157 +++++++ drivers/dpll/zl3073x/out.h | 93 ++++ drivers/dpll/zl3073x/prop.c | 12 +- drivers/dpll/zl3073x/ref.c | 194 +++++++++ drivers/dpll/zl3073x/ref.h | 134 ++++++ drivers/dpll/zl3073x/synth.c | 87 ++++ drivers/dpll/zl3073x/synth.h | 72 ++++ 11 files changed, 1009 insertions(+), 946 deletions(-) create mode 100644 drivers/dpll/zl3073x/out.c create mode 100644 drivers/dpll/zl3073x/out.h create mode 100644 drivers/dpll/zl3073x/ref.c create mode 100644 drivers/dpll/zl3073x/ref.h create mode 100644 drivers/dpll/zl3073x/synth.c create mode 100644 drivers/dpll/zl3073x/synth.h
Signature · 1 line
2.51.0
Ivan Vecera
maintainerPATCH v2 1/6 dpll: zl3073x: Store raw register values instead of parsed state
The zl3073x_ref, zl3073x_out and zl3073x_synth structures previously stored state that was parsed from register reads. This included values like boolean 'enabled' flags, synthesizer selections, and pre-calculated frequencies.
This commit refactors the state management to store the raw register values directly in these structures. The various inline helper functions are updated to parse these raw values on-demand using FIELD_GET.
--- drivers/dpll/zl3073x/core.c | 81 ++++++++++++------------------------- drivers/dpll/zl3073x/core.h | 61 ++++++++++++++++------------ 2 files changed, 60 insertions(+), 82 deletions(-)
drivers/dpll/zl3073x/core.c +25 -56
@@ -598,25 +598,22 @@ int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev,* @zldev: pointer to zl3073x_dev structure * @index: input reference index to fetch state for * -* Function fetches information for the given input reference that are -* invariant and stores them for later use. +* Function fetches state for the given input reference and stores it for +* later user. * * Return: 0 on success, <0 on error */ static int zl3073x_ref_state_fetch (struct zl3073x_dev *zldev,u8 index) { -struct zl3073x_ref *input = &zldev->ref[index]; -u8 ref_config; +struct zl3073x_ref *ref = &zldev->ref[index];int rc;/* If the input is differential then the configuration for N-pin * reference is ignored and P-pin config is used for both. */ -if (zl3073x_is_n_pin (index) && -zl3073x_ref_is_diff (zldev, index -1 )) { - input->enabled =zl3073x_ref_is_enabled (zldev, index -1 ); - input->diff = true; +if (zl3073x_is_n_pin (index) &&zl3073x_ref_is_diff (zldev, index -1 )) { +memcpy (ref, &zldev->ref[index -1 ],sizeof (*ref));return 0 ; }
@@ -630,16 +627,14 @@ zl3073x_ref_state_fetch(struct zl3073x_dev *zldev, u8 index)return rc;/* Read ref_config register */ - rc =zl3073x_read_u8 (zldev,ZL_REG_REF_CONFIG , &ref_config); + rc =zl3073x_read_u8 (zldev,ZL_REG_REF_CONFIG , &ref->config);if (rc)return rc; - input->enabled =FIELD_GET (ZL_REF_CONFIG_ENABLE , ref_config); - input->diff =FIELD_GET (ZL_REF_CONFIG_DIFF_EN , ref_config); -dev_dbg (zldev->dev,"REF%u is %s and configured as %s\n" , index, -str_enabled_disabled (input->enabled), - input->diff ?"differential" :"single-ended" ); +str_enabled_disabled (zl3073x_ref_is_enabled (zldev, index)), +zl3073x_ref_is_diff (zldev, index) + ?"differential" :"single-ended" );return rc; }
@@ -649,8 +644,8 @@ zl3073x_ref_state_fetch(struct zl3073x_dev *zldev, u8 index)* @zldev: pointer to zl3073x_dev structure * @index: output index to fetch state for * -* Function fetches information for the given output (not output pin) -* that are invariant and stores them for later use. +* Function fetches state of the given output (not output pin) and stores it +* for later use. * * Return: 0 on success, <0 on error */
@@ -658,22 +653,16 @@ static int zl3073x_out_state_fetch(struct zl3073x_dev *zldev, u8 index) {struct zl3073x_out *out = &zldev->out[index]; -u8 output_ctrl, output_mode;int rc;/* Read output configuration */ - rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_CTRL (index), &output_ctrl); + rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_CTRL (index), &out->ctrl);if (rc)return rc; -/* Store info about output enablement and synthesizer the output -* is connected to. -*/ - out->enabled =FIELD_GET (ZL_OUTPUT_CTRL_EN , output_ctrl); - out->synth =FIELD_GET (ZL_OUTPUT_CTRL_SYNTH_SEL , output_ctrl); -dev_dbg (zldev->dev,"OUT%u is %s and connected to SYNTH%u\n" , index, -str_enabled_disabled (out->enabled), out->synth); +str_enabled_disabled (zl3073x_out_is_enabled (zldev, index)), +zl3073x_out_synth_get (zldev, index));guard (mutex)(&zldev->multiop_lock);
@@ -683,17 +672,13 @@ zl3073x_out_state_fetch(struct zl3073x_dev *zldev, u8 index)if (rc)return rc; -/* Read output_mode */ - rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_MODE , &output_mode); +/* Read output mode */ + rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_MODE , &out->mode);if (rc)return rc; -/* Extract and store output signal format */ - out->signal_format =FIELD_GET (ZL_OUTPUT_MODE_SIGNAL_FORMAT , - output_mode); -dev_dbg (zldev->dev,"OUT%u has signal format 0x%02x\n" , index, - out->signal_format); +zl3073x_out_signal_format_get (zldev, index));return rc; }
@@ -703,8 +688,7 @@ zl3073x_out_state_fetch(struct zl3073x_dev *zldev, u8 index)* @zldev: pointer to zl3073x_dev structure * @index: synth index to fetch state for * -* Function fetches information for the given synthesizer that are -* invariant and stores them for later use. +* Function fetches state of the given synthesizer and stores it for later use. * * Return: 0 on success, <0 on error */
@@ -712,25 +696,13 @@ static int zl3073x_synth_state_fetch(struct zl3073x_dev *zldev, u8 index) {struct zl3073x_synth *synth = &zldev->synth[index]; -u16 base, m, n; -u8 synth_ctrl; -u32 mult;int rc;/* Read synth control register */ - rc =zl3073x_read_u8 (zldev,ZL_REG_SYNTH_CTRL (index), &synth_ctrl); + rc =zl3073x_read_u8 (zldev,ZL_REG_SYNTH_CTRL (index), &synth->ctrl);if (rc)return rc; -/* Store info about synth enablement and DPLL channel the synth is -* driven by. -*/ - synth->enabled =FIELD_GET (ZL_SYNTH_CTRL_EN , synth_ctrl); - synth->dpll =FIELD_GET (ZL_SYNTH_CTRL_DPLL_SEL , synth_ctrl); - -dev_dbg (zldev->dev,"SYNTH%u is %s and driven by DPLL%u\n" , index, -str_enabled_disabled (synth->enabled), synth->dpll); -guard (mutex)(&zldev->multiop_lock);/* Read synth configuration */
@@ -744,35 +716,32 @@ zl3073x_synth_state_fetch(struct zl3073x_dev *zldev, u8 index)* * Read registers with these values */ - rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_BASE , &base); + rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_BASE , &synth->freq_base);if (rc)return rc; - rc =zl3073x_read_u32 (zldev,ZL_REG_SYNTH_FREQ_MULT , &mult); + rc =zl3073x_read_u32 (zldev,ZL_REG_SYNTH_FREQ_MULT , &synth->freq_mult);if (rc)return rc; - rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_M , &m); + rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_M , &synth->freq_m);if (rc)return rc; - rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_N , &n); + rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_N , &synth->freq_n);if (rc)return rc;/* Check denominator for zero to avoid div by 0 */ -if (!n) { +if (!synth->freq_n) {dev_err (zldev->dev,"Zero divisor for SYNTH%u retrieved from device\n" , index);return -EINVAL ; } -/* Compute and store synth frequency */ - zldev->synth[index].freq =div_u64 (mul_u32_u32 (base * m, mult), n); -dev_dbg (zldev->dev,"SYNTH%u frequency: %u Hz\n" , index, - zldev->synth[index].freq); +zl3073x_synth_freq_get (zldev, index));return rc; }
drivers/dpll/zl3073x/core.h +35 -26
132 lines not on this page · raw message
Signature · 1 line
2.51.0
Ivan Vecera
maintainerPATCH v2 2/6 dpll: zl3073x: Split ref, out, and synth logic from core
In reply to Ivan VeceraRefactor the zl3073x driver by splitting the logic for input references, outputs and synthesizers out of the monolithic core.[ch] files.
Move the logic for each functional block into its own dedicated files:
ref.[ch], out.[ch] and synth.[ch].
Specifically:
- Move state structures (zl3073x_ref, zl3073x_out, zl3073x_synth) from core.h into their respective new headers
- Move state-fetching functions (..._state_fetch) from core.c to their new .c files
- Move the zl3073x_ref_freq_factorize helper from core.c to ref.c
- Introduce a new helper layer to decouple the core device logic from the state-parsing logic:
1. Move the original inline helpers (e.g., zl3073x_ref_is_enabled) to the new headers (ref.h, etc.) and make them operate on a const struct ... * pointer.
2. Create new zl3073x_dev_... prefixed functions in core.h (e.g., zl3073x_dev_ref_is_enabled) and Implement these _dev_ functions to fetch state using a new ..._state_get() helper and then call the non-prefixed helper.
3. Update all driver-internal callers (in dpll.c, prop.c, etc.) to use
the new zl3073x_dev_... functions.
---
Changes:
v2 - removed unnecessary blank line
--- drivers/dpll/zl3073x/Makefile | 3 +- drivers/dpll/zl3073x/core.c | 194 ---------------------------------- drivers/dpll/zl3073x/core.h | 170 +++++++++++++---------------- drivers/dpll/zl3073x/dpll.c | 36 +++---- drivers/dpll/zl3073x/out.c | 67 ++++++++++++ drivers/dpll/zl3073x/out.h | 80 ++++++++++++++ drivers/dpll/zl3073x/prop.c | 12 +-- drivers/dpll/zl3073x/ref.c | 109 +++++++++++++++++++ drivers/dpll/zl3073x/ref.h | 66 ++++++++++++ drivers/dpll/zl3073x/synth.c | 87 +++++++++++++++ drivers/dpll/zl3073x/synth.h | 72 +++++++++++++ 11 files changed, 581 insertions(+), 315 deletions(-) create mode 100644 drivers/dpll/zl3073x/out.c create mode 100644 drivers/dpll/zl3073x/out.h create mode 100644 drivers/dpll/zl3073x/ref.c create mode 100644 drivers/dpll/zl3073x/ref.h create mode 100644 drivers/dpll/zl3073x/synth.c create mode 100644 drivers/dpll/zl3073x/synth.h
drivers/dpll/zl3073x/Makefile +2 -1
@@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ZL3073X) += zl3073x.o -zl3073x-objs := core.o devlink.o dpll.o flash.o fw.o prop.o +zl3073x-objs := core.o devlink.o dpll.o flash.o fw.o \ + out.o prop.o ref.o synth.o obj-$(CONFIG_ZL3073X_I2C) += zl3073x_i2c.o zl3073x_i2c-objs := i2c.o
drivers/dpll/zl3073x/core.c +0 -194
206 lines not on this page · raw message
drivers/dpll/zl3073x/core.h +74 -96
327 lines not on this page · raw message
drivers/dpll/zl3073x/dpll.c +18 -18
@@ -967,7 +967,7 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin,* for N-division is also used for the esync divider so both cannot * be used. */ -switch (zl3073x_out_signal_format_get (zldev, out)) { +switch (zl3073x_dev_out_signal_format_get (zldev, out)) {case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV :case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV :return -EOPNOTSUPP ;
@@ -1001,10 +1001,10 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin, }/* Get synth attached to output pin */ - synth =zl3073x_out_synth_get (zldev, out); + synth =zl3073x_dev_out_synth_get (zldev, out);/* Get synth frequency */ - synth_freq =zl3073x_synth_freq_get (zldev, synth); + synth_freq =zl3073x_dev_synth_freq_get (zldev, synth); clock_type =FIELD_GET (ZL_OUTPUT_MODE_CLOCK_TYPE , output_mode);if (clock_type !=ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ) {
@@ -1078,7 +1078,7 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,* for N-division is also used for the esync divider so both cannot * be used. */ -switch (zl3073x_out_signal_format_get (zldev, out)) { +switch (zl3073x_dev_out_signal_format_get (zldev, out)) {case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV :case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV :return -EOPNOTSUPP ;
@@ -1117,10 +1117,10 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin, goto write_mailbox;/* Get synth attached to output pin */ - synth =zl3073x_out_synth_get (zldev, out); + synth =zl3073x_dev_out_synth_get (zldev, out);/* Get synth frequency */ - synth_freq =zl3073x_synth_freq_get (zldev, synth); + synth_freq =zl3073x_dev_synth_freq_get (zldev, synth); rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_DIV , &output_div);if (rc)
@@ -1172,8 +1172,8 @@ zl3073x_dpll_output_pin_frequency_get(const struct dpll_pin *dpll_pin,int rc; out =zl3073x_output_pin_out_get (pin->id); - synth =zl3073x_out_synth_get (zldev, out); - synth_freq =zl3073x_synth_freq_get (zldev, synth); + synth =zl3073x_dev_out_synth_get (zldev, out); + synth_freq =zl3073x_dev_synth_freq_get (zldev, synth);guard (mutex)(&zldev->multiop_lock);
@@ -1195,7 +1195,7 @@ zl3073x_dpll_output_pin_frequency_get(const struct dpll_pin *dpll_pin, }/* Read used signal format for the given output */ - signal_format =zl3073x_out_signal_format_get (zldev, out); + signal_format =zl3073x_dev_out_signal_format_get (zldev, out);switch (signal_format) {case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV :
@@ -1263,12 +1263,12 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,int rc; out =zl3073x_output_pin_out_get (pin->id); - synth =zl3073x_out_synth_get (zldev, out); - synth_freq =zl3073x_synth_freq_get (zldev, synth); + synth =zl3073x_dev_out_synth_get (zldev, out); + synth_freq =zl3073x_dev_synth_freq_get (zldev, synth); new_div = synth_freq / (u32 )frequency;/* Get used signal format for the given output */ - signal_format =zl3073x_out_signal_format_get (zldev, out); + signal_format =zl3073x_dev_out_signal_format_get (zldev, out);guard (mutex)(&zldev->multiop_lock);
@@ -1856,8 +1856,8 @@ zl3073x_dpll_pin_is_registrable(struct zl3073x_dpll *zldpll,if (zldpll->refsel_mode ==ZL_DPLL_MODE_REFSEL_MODE_NCO )return false; - is_diff =zl3073x_ref_is_diff (zldev, ref); - is_enabled =zl3073x_ref_is_enabled (zldev, ref); + is_diff =zl3073x_dev_ref_is_diff (zldev, ref); + is_enabled =zl3073x_dev_ref_is_enabled (zldev, ref); }else {/* Output P&N pair shares single HW output */ u8 out =zl3073x_output_pin_out_get (index);
@@ -1865,7 +1865,7 @@ zl3073x_dpll_pin_is_registrable(struct zl3073x_dpll *zldpll, name ="OUT" ;/* Skip the pin if it is connected to different DPLL channel */ -if (zl3073x_out_dpll_get (zldev, out) != zldpll->id) { +if (zl3073x_dev_out_dpll_get (zldev, out) != zldpll->id) {dev_dbg (zldev->dev,"%s%u is driven by different DPLL\n" , name, out);
@@ -1873,8 +1873,8 @@ zl3073x_dpll_pin_is_registrable(struct zl3073x_dpll *zldpll,return false; } - is_diff =zl3073x_out_is_diff (zldev, out); - is_enabled =zl3073x_output_pin_is_enabled (zldev, index); + is_diff =zl3073x_dev_out_is_diff (zldev, out); + is_enabled =zl3073x_dev_output_pin_is_enabled (zldev, index); }/* Skip N-pin if the corresponding input/output is differential */
@@ -2124,7 +2124,7 @@ zl3073x_dpll_pin_ffo_check(struct zl3073x_dpll_pin *pin)return false;/* Get the latest measured ref's ffo */ - ffo =zl3073x_ref_ffo_get (zldev, ref); + ffo =zl3073x_dev_ref_ffo_get (zldev, ref);/* Compare with previous value */ if (pin->freq_offset != ffo) {
drivers/dpll/zl3073x/out.c new file +67 -0
67 lines not on this page · raw message
drivers/dpll/zl3073x/out.h new file +80 -0
80 lines not on this page · raw message
drivers/dpll/zl3073x/prop.c +6 -6
@@ -46,10 +46,10 @@ zl3073x_pin_check_freq(struct zl3073x_dev *zldev, enum dpll_pin_direction dir,/* Get output pin synthesizer */ out =zl3073x_output_pin_out_get (id); - synth =zl3073x_out_synth_get (zldev, out); + synth =zl3073x_dev_out_synth_get (zldev, out);/* Get synth frequency */ - synth_freq =zl3073x_synth_freq_get (zldev, synth); + synth_freq =zl3073x_dev_synth_freq_get (zldev, synth);/* Check the frequency divides synth frequency */ if (synth_freq % (u32 )freq)
@@ -93,13 +93,13 @@ zl3073x_prop_pin_package_label_set(struct zl3073x_dev *zldev, prefix ="REF" ; ref =zl3073x_input_pin_ref_get (id); - is_diff =zl3073x_ref_is_diff (zldev, ref); + is_diff =zl3073x_dev_ref_is_diff (zldev, ref); }else {u8 out; prefix ="OUT" ; out =zl3073x_output_pin_out_get (id); - is_diff =zl3073x_out_is_diff (zldev, out); + is_diff =zl3073x_dev_out_is_diff (zldev, out); }if (!is_diff)
@@ -217,8 +217,8 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev,* the synth frequency count. */ out =zl3073x_output_pin_out_get (index); - synth =zl3073x_out_synth_get (zldev, out); - f =2 *zl3073x_synth_freq_get (zldev, synth); + synth =zl3073x_dev_out_synth_get (zldev, out); + f =2 *zl3073x_dev_synth_freq_get (zldev, synth); props->dpll_props.phase_gran = f ?div_u64 (PSEC_PER_SEC , f) :1 ; }
drivers/dpll/zl3073x/ref.c new file +109 -0
109 lines not on this page · raw message
drivers/dpll/zl3073x/ref.h new file +66 -0
66 lines not on this page · raw message
drivers/dpll/zl3073x/synth.c new file +87 -0
87 lines not on this page · raw message
drivers/dpll/zl3073x/synth.h new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.51.0
Ivan Vecera
maintainerPATCH v2 3/6 dpll: zl3073x: Cache reference monitor status
In reply to Ivan VeceraInstead of reading the ZL_REG_REF_MON_STATUS register every time the reference status is needed, cache this value in the zl3073x_ref struct.
This is achieved by:
* Adding a mon_status field to struct zl3073x_ref
* Introducing zl3073x_dev_ref_status_update() to read the status for all references into this new cache field
* Calling this update function from the periodic work handler
* Adding zl3073x_ref_is_status_ok() and zl3073x_dev_ref_is_status_ok() helpers to check the cached value
* Refactoring all callers in dpll.c to use the new zl3073x_dev_ref_is_status_ok() helper, removing direct register reads
This change consolidates all status register reads into a single periodic function and reduces I/O bus traffic in dpll callbacks.
---
Changes:
v2:
- added .mon_status field description
--- drivers/dpll/zl3073x/core.c | 18 +++++++ drivers/dpll/zl3073x/core.h | 15 ++++++ drivers/dpll/zl3073x/dpll.c | 96 ++++++++----------------------------- drivers/dpll/zl3073x/ref.h | 14 ++++++ 4 files changed, 68 insertions(+), 75 deletions(-)
drivers/dpll/zl3073x/core.c +18 -0
@@ -591,6 +591,21 @@ zl3073x_dev_state_fetch(struct zl3073x_dev *zldev)return rc; } +static void +zl3073x_dev_ref_status_update (struct zl3073x_dev *zldev) +{ +int i, rc; + +for (i =0 ; i <ZL3073X_NUM_REFS ; i++) { + rc =zl3073x_read_u8 (zldev,ZL_REG_REF_MON_STATUS (i), + &zldev->ref[i].mon_status); +if (rc) +dev_warn (zldev->dev, +"Failed to get REF%u status: %pe\n" , i, +ERR_PTR (rc)); + } +} +/** * zl3073x_ref_phase_offsets_update - update reference phase offsets * @zldev: pointer to zl3073x_dev structure
@@ -710,6 +725,9 @@ zl3073x_dev_periodic_work(struct kthread_work *work)struct zl3073x_dpll *zldpll;int rc; +/* Update input references status */ +zl3073x_dev_ref_status_update (zldev); +/* Update DPLL-to-connected-ref phase offsets registers */ rc =zl3073x_ref_phase_offsets_update (zldev,-1 );if (rc)
drivers/dpll/zl3073x/core.h +15 -0
@@ -227,6 +227,21 @@ zl3073x_dev_ref_is_enabled(struct zl3073x_dev *zldev, u8 index)return zl3073x_ref_is_enabled (ref); } +/* +* zl3073x_dev_ref_is_status_ok - check the given input reference status +* @zldev: pointer to zl3073x device +* @index: input reference index +* +* Return: true if the status is ok, false otherwise +*/ +static inline bool +zl3073x_dev_ref_is_status_ok (struct zl3073x_dev *zldev,u8 index) +{ +const struct zl3073x_ref *ref =zl3073x_ref_state_get (zldev, index); + +return zl3073x_ref_is_status_ok (ref); +} +/** * zl3073x_dev_synth_dpll_get - get DPLL ID the synth is driven by * @zldev: pointer to zl3073x device
drivers/dpll/zl3073x/dpll.c +21 -75
154 lines not on this page · raw message
drivers/dpll/zl3073x/ref.h +14 -0
@@ -14,10 +14,12 @@ struct zl3073x_dev;* struct zl3073x_ref - input reference state * @ffo: current fractional frequency offset * @config: reference config +* @mon_status: reference monitor status */ struct zl3073x_ref {s64 ffo;u8 config; +u8 mon_status; };int zl3073x_ref_state_fetch (struct zl3073x_dev *zldev,u8 index);
@@ -63,4 +65,16 @@ zl3073x_ref_is_enabled(const struct zl3073x_ref *ref) return !!FIELD_GET(ZL_REF_CONFIG_ENABLE, ref->config); } +/** +* zl3073x_ref_is_status_ok - check the given input reference status +* @ref: pointer to ref state +* +* Return: true if the status is ok, false otherwise +*/ +static inline bool +zl3073x_ref_is_status_ok (const struct zl3073x_ref *ref) +{ +return ref->mon_status ==ZL_REF_MON_STATUS_OK ; +} +#endif /* _ZL3073X_REF_H */
Signature · 1 line
2.51.0
Ivan Vecera
maintainerPATCH v2 4/6 dpll: zl3073x: Cache all reference properties in zl3073x_ref
In reply to Ivan VeceraExpand the zl3073x_ref structure to cache all reference-related hardware registers, including frequency components, embedded-sync settings and phase compensation. Previously, these registers were read on-demand from various functions in dpll.c leading to frequent mailbox operations.
Modify zl3073x_ref_state_fetch() to read and populate all these new fields at once. Refactor all "getter" functions in dpll.c to read from this new cached state instead of performing direct register access.
Remove the standalone zl3073x_dpll_input_ref_frequency_get() helper, as its functionality is now replaced by zl3073x_ref_freq_get() which operates on the cached state and add a corresponding zl3073x_dev_... wrapper.
Introduce a new function, zl3073x_ref_state_set(), to handle writing changes back to the hardware. This function compares the provided state with the current cached state and writes *only* the modified register values to the device via a single mailbox sequence before updating the local cache.
Refactor all dpll "setter" functions to modify a local copy of the ref state and then call zl3073x_ref_state_set() to commit the changes.
As a cleanup, update callers in dpll.c that already have a struct zl3073x_ref * to use the direct helpers instead of the zl3073x_dev_... wrappers.
This change centralizes all reference-related register I/O into ref.c, significantly reduces bus traffic, and simplifies the logic in dpll.c.
---
Changes:
v2
- removed one set-but-not-used variable
- added new fields' description in zl3073x_ref
- dropped usage of ZL3073X_REF_SYNC_ONE
--- drivers/dpll/zl3073x/core.h | 15 ++ drivers/dpll/zl3073x/dpll.c | 308 +++++++++--------------------------- drivers/dpll/zl3073x/ref.c | 85 ++++++++++ drivers/dpll/zl3073x/ref.h | 54 +++++++ 4 files changed, 231 insertions(+), 231 deletions(-)
drivers/dpll/zl3073x/core.h +15 -0
@@ -197,6 +197,21 @@ zl3073x_dev_ref_ffo_get(struct zl3073x_dev *zldev, u8 index)return zl3073x_ref_ffo_get (ref); } +/** +* zl3073x_dev_ref_freq_get - get input reference frequency +* @zldev: pointer to zl3073x device +* @index: input reference index +* +* Return: frequency of given input reference +*/ +static inline u32 +zl3073x_dev_ref_freq_get (struct zl3073x_dev *zldev,u8 index) +{ +const struct zl3073x_ref *ref =zl3073x_ref_state_get (zldev, index); + +return zl3073x_ref_freq_get (ref); +} +/** * zl3073x_dev_ref_is_diff - check if the given input reference is differential * @zldev: pointer to zl3073x device
drivers/dpll/zl3073x/dpll.c +77 -231
461 lines not on this page · raw message
drivers/dpll/zl3073x/ref.c +85 -0
94 lines not on this page · raw message
drivers/dpll/zl3073x/ref.h +54 -0
84 lines not on this page · raw message
Signature · 1 line
2.51.0
Ivan Vecera
maintainerPATCH v2 5/6 dpll: zl3073x: Cache all output properties in zl3073x_out
In reply to Ivan VeceraExpand the zl3073x_out structure to cache all output-related hardware registers, including divisors, widths, embedded-sync parameters and phase compensation.
Modify zl3073x_out_state_fetch() to read and populate all these new fields at once, including zero-divisor checks. Refactor all dpll "getter" functions in dpll.c to read from this new cached state instead of performing direct register access.
Introduce a new function, zl3073x_out_state_set(), to handle writing changes back to the hardware. This function compares the provided state with the current cached state and writes *only* the modified register values via a single mailbox sequence before updating the local cache.
Refactor all dpll "setter" functions to modify a local copy of the output state and then call zl3073x_out_state_set() to commit the changes.
This change centralizes all output-related register I/O into out.c, significantly reduces bus traffic, and simplifies the logic in dpll.c.
---
Changes:
v2:
- added new fields' description in zl3073x_out
- fixed uninitialized variable warning
- dropped usage of ZL3073X_OUT_SYNC_ONE
--- drivers/dpll/zl3073x/dpll.c | 380 +++++++++--------------------------- drivers/dpll/zl3073x/out.c | 90 +++++++++ drivers/dpll/zl3073x/out.h | 13 ++ 3 files changed, 193 insertions(+), 290 deletions(-)
drivers/dpll/zl3073x/dpll.c +90 -290
@@ -770,21 +770,19 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; -struct device *dev = zldev->dev; -u32 esync_period, esync_width; -u8 clock_type, synth; -u8 out, output_mode; -u32 output_div; +const struct zl3073x_synth *synth; +const struct zl3073x_out *out; +u8 clock_type, out_id;u32 synth_freq; -int rc; - out =zl3073x_output_pin_out_get (pin->id); + out_id =zl3073x_output_pin_out_get (pin->id); + out =zl3073x_out_state_get (zldev, out_id);/* If N-division is enabled, esync is not supported. The register used * for N-division is also used for the esync divider so both cannot * be used. */ -switch (zl3073x_dev_out_signal_format_get (zldev, out)) { +switch (zl3073x_out_signal_format_get (out)) {case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV :case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV :return -EOPNOTSUPP ;
@@ -792,38 +790,11 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin,break ; } -guard (mutex)(&zldev->multiop_lock); - -/* Read output configuration into mailbox */ - rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); -if (rc) -return rc; - -/* Read output mode */ - rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_MODE , &output_mode); -if (rc) -return rc; - -/* Read output divisor */ - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_DIV , &output_div); -if (rc) -return rc; - -/* Check output divisor for zero */ -if (!output_div) { -dev_err (dev,"Zero divisor for OUTPUT%u got from device\n" , - out); -return -EINVAL ; - } - -/* Get synth attached to output pin */ - synth =zl3073x_dev_out_synth_get (zldev, out); - -/* Get synth frequency */ - synth_freq =zl3073x_dev_synth_freq_get (zldev, synth); +/* Get attached synth frequency */ + synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (out)); + synth_freq =zl3073x_synth_freq_get (synth); - clock_type =FIELD_GET (ZL_OUTPUT_MODE_CLOCK_TYPE , output_mode); + clock_type =FIELD_GET (ZL_OUTPUT_MODE_CLOCK_TYPE , out->mode);if (clock_type !=ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ) {/* No need to read esync data if it is not enabled */ esync->freq =0 ;
@@ -832,38 +803,21 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin, goto finish; } -/* Read esync period */ - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , &esync_period); -if (rc) -return rc; - -/* Check esync divisor for zero */ -if (!esync_period) { -dev_err (dev,"Zero esync divisor for OUTPUT%u got from device\n" , - out); -return -EINVAL ; - } - -/* Get esync pulse width in units of half synth cycles */ - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_ESYNC_WIDTH , &esync_width); -if (rc) -return rc; -/* Compute esync frequency */ - esync->freq = synth_freq / output_div / esync_period; + esync->freq = synth_freq / out->div / out->esync_n_period;/* By comparing the esync_pulse_width to the half of the pulse width * the esync pulse percentage can be determined. * Note that half pulse width is in units of half synth cycles, which * is why it reduces down to be output_div. */ - esync->pulse = (50 * esync_width) / output_div; + esync->pulse = (50 * out->esync_n_width) / out->div; finish:/* Set supported esync ranges if the pin supports esync control and * if the output frequency is > 1 Hz. */ -if (pin->esync_control && (synth_freq / output_div) >1 ) { +if (pin->esync_control && (synth_freq / out->div) >1 ) { esync->range = esync_freq_ranges; esync->range_num =ARRAY_SIZE (esync_freq_ranges); }else {
@@ -881,21 +835,22 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin, void *dpll_priv, u64 freq, struct netlink_ext_ack *extack) { - u32 esync_period, esync_width, output_div; struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; -u8 clock_type, out, output_mode, synth; +const struct zl3073x_synth *synth; +struct zl3073x_out out; +u8 clock_type, out_id;u32 synth_freq; -int rc; - out =zl3073x_output_pin_out_get (pin->id); + out_id =zl3073x_output_pin_out_get (pin->id); + out = *zl3073x_out_state_get (zldev, out_id);/* If N-division is enabled, esync is not supported. The register used * for N-division is also used for the esync divider so both cannot * be used. */ -switch (zl3073x_dev_out_signal_format_get (zldev, out)) { +switch (zl3073x_out_signal_format_get (&out)) {case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV :case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV :return -EOPNOTSUPP ;
@@ -903,19 +858,6 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,break ; } -guard (mutex)(&zldev->multiop_lock); - -/* Read output configuration into mailbox */ - rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); -if (rc) -return rc; - -/* Read output mode */ - rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_MODE , &output_mode); -if (rc) -return rc; -/* Select clock type */ if (freq) clock_type =ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ;
@@ -923,38 +865,19 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin, clock_type =ZL_OUTPUT_MODE_CLOCK_TYPE_NORMAL ;/* Update clock type in output mode */ - output_mode &= ~ZL_OUTPUT_MODE_CLOCK_TYPE ; - output_mode |=FIELD_PREP (ZL_OUTPUT_MODE_CLOCK_TYPE , clock_type); - rc =zl3073x_write_u8 (zldev,ZL_REG_OUTPUT_MODE , output_mode); -if (rc) -return rc; + out.mode &= ~ZL_OUTPUT_MODE_CLOCK_TYPE ; + out.mode |=FIELD_PREP (ZL_OUTPUT_MODE_CLOCK_TYPE , clock_type);/* If esync is being disabled just write mailbox and finish */ if (!freq) goto write_mailbox; -/* Get synth attached to output pin */ - synth =zl3073x_dev_out_synth_get (zldev, out); - -/* Get synth frequency */ - synth_freq =zl3073x_dev_synth_freq_get (zldev, synth); - - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_DIV , &output_div); -if (rc) -return rc; - -/* Check output divisor for zero */ -if (!output_div) { -dev_err (zldev->dev, -"Zero divisor for OUTPUT%u got from device\n" , out); -return -EINVAL ; - } +/* Get attached synth frequency */ + synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (&out)); + synth_freq =zl3073x_synth_freq_get (synth);/* Compute and update esync period */ - esync_period = synth_freq / (u32 )freq / output_div; - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , esync_period); -if (rc) -return rc; + out.esync_n_period = synth_freq / (u32 )freq / out.div;/* Half of the period in units of 1/2 synth cycle can be represented by * the output_div. To get the supported esync pulse width of 25% of the
@@ -962,15 +885,11 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,* assumes that output_div is even, otherwise some resolution will be * lost. */ - esync_width = output_div /2 ; - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_ESYNC_WIDTH , esync_width); -if (rc) -return rc; + out.esync_n_width = out.div /2 ; write_mailbox:/* Commit output configuration */ -return zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_WR , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); +return zl3073x_out_state_set (zldev, out_id, &out); } static int
@@ -983,83 +902,46 @@ zl3073x_dpll_output_pin_frequency_get(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; -struct device *dev = zldev->dev; -u8 out, signal_format, synth; -u32 output_div, synth_freq; -int rc; - - out =zl3073x_output_pin_out_get (pin->id); - synth =zl3073x_dev_out_synth_get (zldev, out); - synth_freq =zl3073x_dev_synth_freq_get (zldev, synth); - -guard (mutex)(&zldev->multiop_lock); - -/* Read output configuration into mailbox */ - rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); -if (rc) -return rc; - - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_DIV , &output_div); -if (rc) -return rc; +const struct zl3073x_synth *synth; +const struct zl3073x_out *out; +u32 synth_freq; +u8 out_id; -/* Check output divisor for zero */ -if (!output_div) { -dev_err (dev,"Zero divisor for output %u got from device\n" , - out); -return -EINVAL ; - } + out_id =zl3073x_output_pin_out_get (pin->id); + out =zl3073x_out_state_get (zldev, out_id); -/* Read used signal format for the given output */ - signal_format =zl3073x_dev_out_signal_format_get (zldev, out); +/* Get attached synth frequency */ + synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (out)); + synth_freq =zl3073x_synth_freq_get (synth); -switch (signal_format) { +switch (zl3073x_out_signal_format_get (out)) {case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV :case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV :/* In case of divided format we have to distiguish between * given output pin type. +* +* For P-pin the resulting frequency is computed as simple +* division of synth frequency and output divisor. +* +* For N-pin we have to divide additionally by divisor stored +* in esync_n_period output mailbox register that is used as +* N-pin divisor for these modes. */ -if (zl3073x_dpll_is_p_pin (pin)) { -/* For P-pin the resulting frequency is computed as -* simple division of synth frequency and output -* divisor. -*/ - *frequency = synth_freq / output_div; - }else { -/* For N-pin we have to divide additionally by -* divisor stored in esync_period output mailbox -* register that is used as N-pin divisor for these -* modes. -*/ -u32 ndiv; - - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , - &ndiv); -if (rc) -return rc; + *frequency = synth_freq / out->div; -/* Check N-pin divisor for zero */ -if (!ndiv) { -dev_err (dev, -"Zero N-pin divisor for output %u got from device\n" , - out); -return -EINVAL ; - } +if (!zl3073x_dpll_is_p_pin (pin)) + *frequency = (u32)*frequency / out->esync_n_period; -/* Compute final divisor for N-pin */ - *frequency = synth_freq / output_div / ndiv; - }break ;default :/* In other modes the resulting frequency is computed as * division of synth frequency and output divisor. */ - *frequency = synth_freq / output_div; + *frequency = synth_freq / out->div;break ; } -return rc; +return 0 ; } static int
@@ -1072,28 +954,21 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; -struct device *dev = zldev->dev; -u32 output_n_freq, output_p_freq; -u8 out, signal_format, synth; -u32 cur_div, new_div, ndiv; -u32 synth_freq; -int rc; +const struct zl3073x_synth *synth; +u8 out_id, signal_format; +u32 new_div, synth_freq; +struct zl3073x_out out; - out =zl3073x_output_pin_out_get (pin->id); - synth =zl3073x_dev_out_synth_get (zldev, out); - synth_freq =zl3073x_dev_synth_freq_get (zldev, synth); + out_id =zl3073x_output_pin_out_get (pin->id); + out = *zl3073x_out_state_get (zldev, out_id); + +/* Get attached synth frequency and compute new divisor */ + synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (&out)); + synth_freq =zl3073x_synth_freq_get (synth); new_div = synth_freq / (u32 )frequency;/* Get used signal format for the given output */ - signal_format =zl3073x_dev_out_signal_format_get (zldev, out); - -guard (mutex)(&zldev->multiop_lock); - -/* Load output configuration */ - rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); -if (rc) -return rc; + signal_format =zl3073x_out_signal_format_get (&out);/* Check signal format */ if (signal_format != ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV &&
@@ -1101,99 +976,50 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,/* For non N-divided signal formats the frequency is computed * as division of synth frequency and output divisor. */ - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_DIV , new_div); -if (rc) -return rc; + out.div = new_div;/* For 50/50 duty cycle the divisor is equal to width */ - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_WIDTH , new_div); -if (rc) -return rc; + out.width = new_div;/* Commit output configuration */ -return zl3073x_mb_op (zldev, -ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_WR , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); +return zl3073x_out_state_set (zldev, out_id, &out); } -/* For N-divided signal format get current divisor */ - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_DIV , &cur_div); -if (rc) -return rc; - -/* Check output divisor for zero */ -if (!cur_div) { -dev_err (dev,"Zero divisor for output %u got from device\n" , - out); -return -EINVAL ; - } - -/* Get N-pin divisor (shares the same register with esync */ - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , &ndiv); -if (rc) -return rc; - -/* Check N-pin divisor for zero */ -if (!ndiv) { -dev_err (dev, -"Zero N-pin divisor for output %u got from device\n" , - out); -return -EINVAL ; - } - -/* Compute current output frequency for P-pin */ - output_p_freq = synth_freq / cur_div; - -/* Compute current N-pin frequency */ - output_n_freq = output_p_freq / ndiv; -if (zl3073x_dpll_is_p_pin (pin)) {/* We are going to change output frequency for P-pin but * if the requested frequency is less than current N-pin * frequency then indicate a failure as we are not able * to compute N-pin divisor to keep its frequency unchanged. +* +* Update divisor for N-pin to keep N-pin frequency. */ -if (frequency <= output_n_freq) + out.esync_n_period = (out.esync_n_period * out.div) / new_div; +if (!out.esync_n_period)return -EINVAL ;/* Update the output divisor */ - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_DIV , new_div); -if (rc) -return rc; + out.div = new_div;/* For 50/50 duty cycle the divisor is equal to width */ - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_WIDTH , new_div); -if (rc) -return rc; - -/* Compute new divisor for N-pin */ - ndiv = (u32 )frequency / output_n_freq; + out.width = out.div; }else {/* We are going to change frequency of N-pin but if * the requested freq is greater or equal than freq of P-pin * in the output pair we cannot compute divisor for the N-pin. * In this case indicate a failure. +* +* Update divisor for N-pin */ -if (output_p_freq <= frequency) + out.esync_n_period =div64_u64 (synth_freq, frequency * out.div); +if (!out.esync_n_period)return -EINVAL ; - -/* Compute new divisor for N-pin */ - ndiv = output_p_freq / (u32 )frequency; } -/* Update divisor for the N-pin */ - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , ndiv); -if (rc) -return rc; -/* For 50/50 duty cycle the divisor is equal to width */ - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_ESYNC_WIDTH , ndiv); -if (rc) -return rc; + out.esync_n_width = out.esync_n_period;/* Commit output configuration */ -return zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_WR , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); +return zl3073x_out_state_set (zldev, out_id, &out); } static int
@@ -1207,30 +1033,18 @@ zl3073x_dpll_output_pin_phase_adjust_get(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; -s32 phase_comp; -u8 out; -int rc; - -guard (mutex)(&zldev->multiop_lock); +const struct zl3073x_out *out; +u8 out_id; -/* Read output configuration */ - out =zl3073x_output_pin_out_get (pin->id); - rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); -if (rc) -return rc; - -/* Read current output phase compensation */ - rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_PHASE_COMP , &phase_comp); -if (rc) -return rc; + out_id =zl3073x_output_pin_out_get (pin->id); + out =zl3073x_out_state_get (zldev, out_id);/* Convert value to ps and reverse two's complement negation applied * during 'set' */ - *phase_adjust = -phase_comp * pin->phase_gran; + *phase_adjust = -out->phase_comp * pin->phase_gran; -return rc; +return 0 ; } static int
@@ -1244,31 +1058,19 @@ zl3073x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; -u8 out; -int rc; +struct zl3073x_out out; +u8 out_id; + + out_id =zl3073x_output_pin_out_get (pin->id); + out = *zl3073x_out_state_get (zldev, out_id);/* The value in the register is stored as two's complement negation * of requested value and expressed in half synth clock cycles. */ - phase_adjust = -phase_adjust / pin->phase_gran; - -guard (mutex)(&zldev->multiop_lock); - -/* Read output configuration */ - out =zl3073x_output_pin_out_get (pin->id); - rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); -if (rc) -return rc; - -/* Write the requested value into the compensation register */ - rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_PHASE_COMP , phase_adjust); -if (rc) -return rc; + out.phase_comp = -phase_adjust / pin->phase_gran;/* Update output configuration from mailbox */ -return zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_WR , -ZL_REG_OUTPUT_MB_MASK ,BIT (out)); +return zl3073x_out_state_set (zldev, out_id, &out); } static int
@@ -1680,17 +1482,15 @@ zl3073x_dpll_pin_is_registrable(struct zl3073x_dpll *zldpll,/* Output P&N pair shares single HW output */ u8 out =zl3073x_output_pin_out_get (index); - name ="OUT" ; -/* Skip the pin if it is connected to different DPLL channel */ if (zl3073x_dev_out_dpll_get (zldev, out) != zldpll->id) {dev_dbg (zldev->dev, -"%s%u is driven by different DPLL\n" , name, - out); +"OUT%u is driven by different DPLL\n" , out);return false; } + name ="OUT" ; is_diff =zl3073x_dev_out_is_diff (zldev, out); is_enabled =zl3073x_dev_output_pin_is_enabled (zldev, index); }
drivers/dpll/zl3073x/out.c +90 -0
99 lines not on this page · raw message
drivers/dpll/zl3073x/out.h +13 -0
@@ -12,10 +12,20 @@ struct zl3073x_dev;/** * struct zl3073x_out - output state +* @div: output divisor +* @width: output pulse width +* @esync_n_period: embedded sync or n-pin period (for n-div formats) +* @esync_n_width: embedded sync or n-pin pulse width +* @phase_comp: phase compensation * @ctrl: output control * @mode: output mode */ struct zl3073x_out { +u32 div; +u32 width; +u32 esync_n_period; +u32 esync_n_width; +s32 phase_comp;u8 ctrl;u8 mode; };
@@ -24,6 +34,9 @@ int zl3073x_out_state_fetch(struct zl3073x_dev *zldev, u8 index);const struct zl3073x_out *zl3073x_out_state_get (struct zl3073x_dev *zldev,u8 index); +int zl3073x_out_state_set (struct zl3073x_dev *zldev,u8 index, +const struct zl3073x_out *out); +/** * zl3073x_out_signal_format_get - get output signal format * @out: pointer to out state
Signature · 1 line
2.51.0
Ivan Vecera
maintainerPATCH v2 6/6 dpll: zl3073x: Remove unused dev wrappers
In reply to Ivan VeceraRemove several zl3073x_dev_... inline wrapper functions from core.h as they are no longer used by any callers.
Removed functions:
* zl3073x_dev_ref_ffo_get
* zl3073x_dev_ref_is_enabled
* zl3073x_dev_synth_dpll_get
* zl3073x_dev_synth_is_enabled
* zl3073x_dev_out_signal_format_get
This is a cleanup after recent refactoring, as the remaining callers now fetch the state object and use the base helpers directly.
--- drivers/dpll/zl3073x/core.h | 77 ------------------------------------- 1 file changed, 77 deletions(-)
drivers/dpll/zl3073x/core.h +0 -77
@@ -182,21 +182,6 @@ zl3073x_output_pin_out_get(u8 id)return id /2 ; } -/** -* zl3073x_dev_ref_ffo_get - get current fractional frequency offset -* @zldev: pointer to zl3073x device -* @index: input reference index -* -* Return: the latest measured fractional frequency offset -*/ -static inline s64 -zl3073x_dev_ref_ffo_get (struct zl3073x_dev *zldev,u8 index) -{ -const struct zl3073x_ref *ref =zl3073x_ref_state_get (zldev, index); - -return zl3073x_ref_ffo_get (ref); -} -/** * zl3073x_dev_ref_freq_get - get input reference frequency * @zldev: pointer to zl3073x device
@@ -227,21 +212,6 @@ zl3073x_dev_ref_is_diff(struct zl3073x_dev *zldev, u8 index)return zl3073x_ref_is_diff (ref); } -/** -* zl3073x_dev_ref_is_enabled - check if the given input reference is enabled -* @zldev: pointer to zl3073x device -* @index: input reference index -* -* Return: true if input refernce is enabled, false otherwise -*/ -static inline bool -zl3073x_dev_ref_is_enabled (struct zl3073x_dev *zldev,u8 index) -{ -const struct zl3073x_ref *ref =zl3073x_ref_state_get (zldev, index); - -return zl3073x_ref_is_enabled (ref); -} -/* * zl3073x_dev_ref_is_status_ok - check the given input reference status * @zldev: pointer to zl3073x device
@@ -257,22 +227,6 @@ zl3073x_dev_ref_is_status_ok(struct zl3073x_dev *zldev, u8 index)return zl3073x_ref_is_status_ok (ref); } -/** -* zl3073x_dev_synth_dpll_get - get DPLL ID the synth is driven by -* @zldev: pointer to zl3073x device -* @index: synth index -* -* Return: ID of DPLL the given synthetizer is driven by -*/ -static inline u8 -zl3073x_dev_synth_dpll_get (struct zl3073x_dev *zldev,u8 index) -{ -const struct zl3073x_synth *synth; - - synth =zl3073x_synth_state_get (zldev, index); -return zl3073x_synth_dpll_get (synth); -} -/** * zl3073x_dev_synth_freq_get - get synth current freq * @zldev: pointer to zl3073x device
@@ -289,22 +243,6 @@ zl3073x_dev_synth_freq_get(struct zl3073x_dev *zldev, u8 index)return zl3073x_synth_freq_get (synth); } -/** -* zl3073x_dev_synth_is_enabled - check if the given synth is enabled -* @zldev: pointer to zl3073x device -* @index: synth index -* -* Return: true if synth is enabled, false otherwise -*/ -static inline bool -zl3073x_dev_synth_is_enabled (struct zl3073x_dev *zldev,u8 index) -{ -const struct zl3073x_synth *synth; - - synth =zl3073x_synth_state_get (zldev, index); -return zl3073x_synth_is_enabled (synth); -} -/** * zl3073x_dev_out_synth_get - get synth connected to given output * @zldev: pointer to zl3073x device
@@ -341,21 +279,6 @@ zl3073x_dev_out_is_enabled(struct zl3073x_dev *zldev, u8 index)return zl3073x_synth_is_enabled (synth) &&zl3073x_out_is_enabled (out); } -/** -* zl3073x_dev_out_signal_format_get - get output signal format -* @zldev: pointer to zl3073x device -* @index: output index -* -* Return: signal format of given output -*/ -static inline u8 -zl3073x_dev_out_signal_format_get (struct zl3073x_dev *zldev,u8 index) -{ -const struct zl3073x_out *out =zl3073x_out_state_get (zldev, index); - -return zl3073x_out_signal_format_get (out); -} -/** * zl3073x_dev_out_dpll_get - get DPLL ID the output is driven by * @zldev: pointer to zl3073x device
Signature · 1 line
2.51.0
Vadim Fedorenko
maintainerRe: [PATCH net-next v2 1/6] dpll: zl3073x: Store raw register values instead of parsed state
In reply to Ivan VeceraQuoted 39 lines · Ivan Vecera
The
zl3073x_ref,zl3073x_outandzl3073x_synthstructures previously stored state that was parsed from register reads. This included values like boolean 'enabled' flags, synthesizer selections, and pre-calculated frequencies.This commit refactors the state management to store the raw register values directly in these structures. The various inline helper functions are updated to parse these raw values on-demand using
FIELD_GET.Reviewed-by Petr Oros <[email protected]>Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>--- drivers/dpll/zl3073x/core.c | 81 ++++++++++++------------------------- drivers/dpll/zl3073x/core.h | 61 ++++++++++++++++------------ 2 files changed, 60 insertions(+), 82 deletions(-)drivers/dpll/zl3073x/core.c +3
-4@@ -598,25 +598,22 @@ int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev,* @zldev: pointer to zl3073x_dev structure * @index: input reference index to fetch state for * -* Function fetches information for the given input reference that are -* invariant and stores them for later use. +* Function fetches state for the given input reference and stores it for +* later user. * * Return: 0 on success, <0 on error */ static int zl3073x_ref_state_fetch (struct zl3073x_dev *zldev,u8 index) { -struct zl3073x_ref *input = &zldev->ref[index]; -u8 ref_config; +struct zl3073x_ref *ref = &zldev->ref[index];int rc;
drivers/dpll/zl3073x/core.c int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev, · line 616
Quoted 10 lines
drivers/dpll/zl3073x/core.c +2
-4/* If the input is differential then the configuration for N-pin * reference is ignored and P-pin config is used for both. */ -if (zl3073x_is_n_pin (index) && -zl3073x_ref_is_diff (zldev, index -1 )) { - input->enabled =zl3073x_ref_is_enabled (zldev, index -1 ); - input->diff = true; +if (zl3073x_is_n_pin (index) &&zl3073x_ref_is_diff (zldev, index -1 )) { +memcpy (ref, &zldev->ref[index -1 ],sizeof (*ref));
Oh, it's not obvious from the code that it's actually safe, unless reviewer remembers that N-pins have only even indexes. Have you thought of adding an abstraction for differential pair pins?
Quoted 3 lines
drivers/dpll/zl3073x/core.c +0
-0return 0 ; }
Ivan Vecera
maintainerRe: [PATCH net-next v2 1/6] dpll: zl3073x: Store raw register values instead of parsed state
Quoted 47 lines · Vadim Fedorenko
Quoted 46 lines · Ivan Vecera
The
zl3073x_ref,zl3073x_outandzl3073x_synthstructures previously stored state that was parsed from register reads. This included values like boolean 'enabled' flags, synthesizer selections, and pre-calculated frequencies.This commit refactors the state management to store the raw register values directly in these structures. The various inline helper functions are updated to parse these raw values on-demand using
FIELD_GET.Reviewed-by Petr Oros <[email protected]>Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>---
drivers/dpll/zl3073x/core.c| 81 ++++++++++++-------------------------drivers/dpll/zl3073x/core.h| 61 ++++++++++++++++------------2 files changed, 60 insertions(+), 82 deletions(-)drivers/dpll/zl3073x/core.c +1
-2@@ -598,25 +598,22 @@ int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev, * @zldev: pointer to zl3073x_dev structure * @index: input reference index to fetch state for * - * Function fetches information for the given input reference that are - * invariant and stores them for later use. + * Function fetches state for the given input reference and stores itfor
+ * later user.
*
* Return: 0 on success, <0 on error
*/
static int
zl3073x_ref_state_fetch(struct zl3073x_dev *zldev, u8 index){
- structzl3073x_ref*input = &zldev->ref[index];
- u8ref_config;
+ structzl3073x_ref*ref = &zldev->ref[index];
int rc;
/* If the input is differential then the configuration for N-pin
* reference is ignored and P-pin config is used for both. */
- if (zl3073x_is_n_pin(index)&&
-zl3073x_ref_is_diff(zldev, index - 1)) {
Quoted 8 lines
Quoted 5 lines
-
input->enabled=zl3073x_ref_is_enabled(zldev, index - 1); -input->diff= true;
+ if (zl3073x_is_n_pin(index)&&zl3073x_ref_is_diff(zldev, index - 1)) {
+memcpy(ref, &zldev->ref[index - 1], sizeof(*ref));Oh, it's not obvious from the code that it's actually safe, unless reviewer remembers that N-pins have only even indexes.
Would it be helpful to add here the comment describing that is safe and why?
Quoted 1 line
Have you thought of adding an abstraction for differential pair pins?
No, zl3073x_ref represents mailbox for HW reference... Here, I’m just following the datasheet, which states: "If the P-pin is marked as differential then some content of the mailbox for N-pin is ignored and is inherited from the P-pin".
For now, the content of zl3073x_ref is the inherited one, but this may change in the future.
The abstraction for differential pin pairs is actually handled in dpll.c, where only a single dpll_pin is registered for each such pair.
Ivan
Vadim Fedorenko
maintainerRe: [PATCH net-next v2 1/6] dpll: zl3073x: Store raw register values instead of parsed state
Quoted 57 lines · Ivan Vecera
Quoted 47 lines · Vadim Fedorenko
Quoted 46 lines · Ivan Vecera
The
zl3073x_ref,zl3073x_outandzl3073x_synthstructures previously stored state that was parsed from register reads. This included values like boolean 'enabled' flags, synthesizer selections, and pre-calculated frequencies.This commit refactors the state management to store the raw register values directly in these structures. The various inline helper functions are updated to parse these raw values on-demand using
FIELD_GET.Reviewed-by Petr Oros <[email protected]>Tested-by Prathosh Satish <[email protected]>Signed-off-by Ivan Vecera <[email protected]>---
drivers/dpll/zl3073x/core.c| 81 ++++++++++++-------------------------drivers/dpll/zl3073x/core.h| 61 ++++++++++++++++------------2 files changed, 60 insertions(+), 82 deletions(-)drivers/dpll/zl3073x/core.c +1
-2@@ -598,25 +598,22 @@ int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev, * @zldev: pointer to zl3073x_dev structure * @index: input reference index to fetch state for * - * Function fetches information for the given input reference that are - * invariant and stores them for later use. + * Function fetches state for the given input reference and storesit for
+ * later user.
*
* Return: 0 on success, <0 on error
*/
static int
zl3073x_ref_state_fetch(struct zl3073x_dev *zldev, u8 index){
- structzl3073x_ref*input = &zldev->ref[index];
- u8ref_config;
+ structzl3073x_ref*ref = &zldev->ref[index];
int rc;
/* If the input is differential then the configuration for N-pin
* reference is ignored and P-pin config is used for both. */
- if (zl3073x_is_n_pin(index)&&
-zl3073x_ref_is_diff(zldev, index - 1)) {Quoted 8 lines
Quoted 5 lines
-
input->enabled=zl3073x_ref_is_enabled(zldev, index - 1); -input->diff= true;
+ if (zl3073x_is_n_pin(index)&& zl3073x_ref_is_diff(zldev, index
- 1)) {
+memcpy(ref, &zldev->ref[index - 1], sizeof(*ref));Oh, it's not obvious from the code that it's actually safe, unless reviewer remembers that N-pins have only even indexes.
Quoted 2 lines
Would it be helpful to add here the comment describing that is safe and why?
Yes, comment would be great to have.
Quoted 15 lines
Quoted 2 lines
Have you thought of adding an abstraction for differential pair pins?
No,
zl3073x_refrepresents mailbox for HW reference... Here, I’m just following the datasheet, which states: "If the P-pin is marked as differential then some content of the mailbox for N-pin is ignored and is inherited from the P-pin".
For now, the content ofzl3073x_refis the inherited one, but this may change in the future.The abstraction for differential pin pairs is actually handled in
dpll.c, where only a singledpll_pinis registered for each such pair.Ivan