dpll: add SiTime SiT9531x DPLL clock driver
Subsystems (4)
v16 cover dpll: add SiTime SiT9531x DPLL clock driver
This series adds a DPLL subsystem driver for the SiTime SiT95316 and SiT95317 I2C clock generators. Each device integrates four PLLs with automatic reference selection and on-chip TDC phase-offset measurement, and is used for synchronization in telecom, networking, and data-center timing.
Patch 1 changes the DPLL core: phase_offset_get and phase_adjust_get may return -ENODATA, and the core then leaves the attribute out of the pin message instead of failing the dump. Patches 11 and 12 use it. The rest is the device-tree binding, the driver under drivers/dpll/sit9531x/, and the MAINTAINERS entry.
v1: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v3: https://lore.kernel.org/netdev/[email protected]/
v4: https://lore.kernel.org/netdev/[email protected]/
v5: https://lore.kernel.org/netdev/[email protected]/
v6: https://lore.kernel.org/netdev/[email protected]/
v7: https://lore.kernel.org/netdev/[email protected]/
v8: https://lore.kernel.org/netdev/[email protected]/
v9: https://lore.kernel.org/netdev/[email protected]/
v10: https://lore.kernel.org/netdev/[email protected]/
v11: https://lore.kernel.org/netdev/[email protected]/
v12: https://lore.kernel.org/netdev/[email protected]/
v13: https://lore.kernel.org/netdev/[email protected]/
v14: https://lore.kernel.org/netdev/[email protected]/
v15: https://lore.kernel.org/netdev/[email protected]/
The changes in v16 answer the netdev AI review of v15. Each finding has a reply on its patch: a fix folded into the patch that introduces the code, a reason it does not hold, or a reason it is left for a patch after this series is merged. Those are listed at the end of this letter.
Ivan Vecera's Reviewed-by on patch 1 and Rob Herring's on patch 3 are carried; the schema in patch 3 is unchanged since v15.
Oleg and I used LLM coding assistants to write parts of the driver code and of the commit messages, and reviewed and revised what they produced.
1 dpll core: omit phase attributes a driver has no value for 2 bindings: vendor prefix 3 bindings: the device schema 4 basic support: paged regmap, variant detection, probe 5 DPLL types and pin properties from system firmware 6 register the DPLL devices and pins, and keep their state 7 input pin state and operational state on a DPLL 8 input pin priority 9 pin frequency, both directions 10 output pin state (mute) 11 output phase adjust 12 phase offset through the TDC 13 the inter-PLL sync line as a pair of pins
The two bindings patches come before the driver, so the driver never matches on a compatible string before the schema that describes it is in the tree.
Every patch builds with only the earlier patches applied: no patch calls something a later patch introduces. This was re-checked for this posting patch by patch with W=1 and with sparse, and kernel-doc -Wall is clean on every driver patch. checkpatch --strict at 80 columns is clean except for the "does MAINTAINERS need updating?" hint on patches 5 and 6, which add files under drivers/dpll/sit9531x/; patch 4 already covers that directory with an F: entry.
Design decisions and hardware assumptions
=========================================
Configuration ownership. The part runs a configuration it loaded before the driver binds, from efuse or from a blob the board applies. The driver reads that configuration and never resets the part, rewrites loop-filter coefficients or touches a register the configurator sets. What it changes at runtime is what the DPLL API asks it to change:
input selection and priorities, output enables, rates and delays, the inter-PLL sync source. Where the loaded configuration puts a PLL outside what the API can express, the driver reports what the part does and withholds the control rather than reconfiguring the part:
a PLL in manual input select is reported in MANUAL mode with no selection or priority setters; a half-armed fast lock registers without the attribute.
Automatic selection. A PLL whose profile arbitrates by priority is reported AUTOMATIC: the part picks among the listed inputs by the priorities it is given, and the driver keeps the table and the active selection register in step with the priorities it was asked for. When a PLL that lost every input sits in holdover and an input returns, the driver doesn't wait for the part: it re-selects the PLL when an input edge is sampled, and once on the first sample after probe or resume, where no edge could have been seen. Whether a PLL returns to a higher-priority input that recovers is the profile's REVERT_EN; the DPLL API has no attribute for revertive selection and no driver exposes its setting.
Qualification. The driver selects on loss of signal and reports ACTIVE from it. The frequency-drift monitors are reported as a qualification failure on an input the PLL is not on; an input the part keeps tracking while its drift flag is set is reported as the part reports it.
Register access. The part shows one 256-byte page at a time, selected through the register at offset 0xFF of every page and latched on the STOP of that write. The regmap is that flat window; the driver selects the page itself under its own lock, remembers the page it selected, forgets it on any failed transfer and on resume, and re-selects on the next access. No other regmap user, debugfs included, can move the page. The I2C_SLAVE_FORCE path of i2c-dev is the
documented debugging override and is not defended against.
Status. The poll reads the status registers twice a second and reports what it samples; a loss of lock that begins and ends between two samples is not reported. INTRB, where wired, brings the next sample forward.
Clocks and supplies. The XO is taken through devm_clk_get_optional_enabled() for its rate and to hold a reference, so clk_disable_unused() cannot gate an XO the loaded configuration runs from; the enable is not what starts the XO, and the reference goes back to the provider on unbind or a failed probe. A clock or a rail the part must keep without a driver bound is the provider's property (CLK_IS_CRITICAL, regulator-always-on), as for any part that is configured before Linux runs. The binding names the supplies; the driver does not enable them yet, so a board with switchable rails marks them always-on.
The XO pin. The XO is the reference of the inner loop of every PLL, so the XO pin is CONNECTED on every DPLL, next to the input the outer loop tracks, with no capabilities and no state setter. CONNECTED is the state the uAPI has for an input in use that the user cannot change. The XO pin has no phase offset.
VCO rate. The VCO rate is derived as Fref * DIVN, the XO rate (with the doubler) times the PLL page's static divider, which is how the register map defines the inner loop; the binding describes the XO and no other reference. The estimate is bounded: a product outside the PLL's VCO band is reported once and refuses every frequency and delay request, and inside the band a rate is programmed only when the estimated Fvco is a whole multiple of it. The read paths report the value computed from the product.
Output pads. The driver reads the pad-enable bits only to tell a CMOS output from a differential one, and mutes a CMOS output by forcing both pads off. It reports an output muted when both pads are forced off, the only state its own mute produces; a profile that forces one pad is reported as driven, and an unmute leaves that pad forced. The force registers act when written, under the output system's debug key and without a programming sequence.
Phase offset. The measurement compares the selected input against a physical output the PLL drives, as the documented procedure does, so a PLL with no routed, enabled output reports no phase offset (the attribute is omitted). The offset is negative when the input edge comes first. A sample that cannot be taken, including one taken while the input disappears, leaves the attribute out rather than failing the dump.
Notifications. The driver sends again a change notification it could not build for a change it made itself (a failed request that moved hardware, a read-through that moved a value, the sync-line source). It does not retry the notifications the core sends after a successful
request: dpll_pin_prio_set() and dpll_pin_state_set() discard that result for every driver, and a retry in the driver would notify the change twice.
Recovery after a failed write. A sequence that fails part-way leaves the part in a state the driver records as pending: a priority table not latched, a forced holdover to release, a delay to re-time, an output realignment, open output loops, a debug window to close, a sync-line page half written. The poll retries each until the write succeeds; unbind retries once more and warns about what is left; resume drops the pending delay and realignment, since the registers it re-reads describe the part after a suspend that may have reloaded it, and keeps the sync-line ownership records until a retry resolves them.
Changes in v16:
- Patch 1: Ivan Vecera's Reviewed-by.
- Patch 4: the reset line is requested before the XO is enabled, so a deferred probe does not gate the clock of a running part.
- Patch 8: a priority change while a PLL is in holdover no longer writes the table a second time on the next poll. A pin on a PLL in manual input select reports no priority in its notifications.
- Patch 9: the NVM bank update is written only by a frequency change whose divider was written; a failed entry into the programming sequence only re-locks the loops.
- Patch 10: a mute or unmute writes the Hi-Z force bits and nothing else; it no longer runs the output programming sequence or opens the output loops. An unmute leaves forced a pad the loaded configuration forces.
- Patch 11: a delay alone is applied with a small-change update instead of the programming sequence. The setter and the getter both report a stored delay in the form nearer to zero, so a request of -1000 ps reads back as -1000 ps. Output loops left open by a failed sequence are re-locked before a flush.
- Patch 12: the sign of the phase offset was inverted and is fixed. The attribute is left out while a failed sequence leaves the output loops open, and when a read fails, instead of failing the dump.
- Patch 13: the source pattern is written before the global enable, and a failed disable restores the enable only over a page that still holds the whole pattern. A PLL that is routed from the sync line, or whose manual select names it, cannot drive it. A global enable set with no page holding the pattern refuses the connect. A refusal caused by a partial source says that a disconnect of the source pin clears it.
- Struct fields move to the patch that first uses them. ODRn_MISC0 bits 2 and 3 are named for the pads they enable.
- Commit messages describe what each patch does, including the retries and the bus load of a poll tick.
Left for patches on top of this series once it is merged:
- claiming the supplies, with the power-up delay, and handling a part that loses power over suspend
- reporting a loss of lock shorter than one poll period from the notification latches
- guarding INTRB against a latch, routed there by the configuration, that the handler does not clear
- retrying an NVM bank update that failed while the loops re-locked
- deriving the VCO rate of a PLL fed from another PLL
- holding the phase flush pending until the trigger is written low
- tracking a failed close of the sync line's debug window
Ali Rouhi (2):
dt-bindings: vendor-prefixes: add SiTime Corporation
dt-bindings: dpll: add SiTime SiT95316 clock generator
Oleg Zadorozhnyi (11):
dpll: omit pin phase attributes the driver has no value for
dpll: add basic SiTime SiT9531x support
dpll: sit9531x: read DPLL types and pin properties from system
firmware
dpll: sit9531x: register DPLL devices and pins
dpll: sit9531x: implement input pin state on a DPLL
dpll: sit9531x: add support to get and set priority on input pins
dpll: sit9531x: add support to get and set frequency on pins
dpll: sit9531x: implement output pin state on a DPLL
dpll: sit9531x: add support to adjust output phase
dpll: sit9531x: add support to get phase offset on the connected input
dpll: sit9531x: model the inter-PLL sync line as a pair of pins
.../bindings/dpll/sitime,sit95316.yaml | 214 + .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 7 + drivers/dpll/Kconfig | 2 + drivers/dpll/Makefile | 1 + drivers/dpll/dpll_netlink.c | 14 +- drivers/dpll/sit9531x/Kconfig | 17 + drivers/dpll/sit9531x/Makefile | 4 + drivers/dpll/sit9531x/core.c | 5237 +++++++++++++++++ drivers/dpll/sit9531x/core.h | 438 ++ drivers/dpll/sit9531x/dpll.c | 1520 +++++ drivers/dpll/sit9531x/dpll.h | 63 + drivers/dpll/sit9531x/prop.c | 366 ++ drivers/dpll/sit9531x/prop.h | 37 + drivers/dpll/sit9531x/regs.h | 351 ++ 15 files changed, 8269 insertions(+), 4 deletions(-) create mode 100644 Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml create mode 100644 drivers/dpll/sit9531x/Kconfig create mode 100644 drivers/dpll/sit9531x/Makefile create mode 100644 drivers/dpll/sit9531x/core.c create mode 100644 drivers/dpll/sit9531x/core.h create mode 100644 drivers/dpll/sit9531x/dpll.c create mode 100644 drivers/dpll/sit9531x/dpll.h create mode 100644 drivers/dpll/sit9531x/prop.c create mode 100644 drivers/dpll/sit9531x/prop.h create mode 100644 drivers/dpll/sit9531x/regs.h
base-commit: fa5196392691051963726787944db872420dfa75
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v16 1/13 dpll: omit pin phase attributes the driver has no value for
From: Oleg Zadorozhnyi <[email protected]>
Let phase_offset_get and phase_adjust_get return -ENODATA for a pin the driver has no value for, and leave DPLL_A_PIN_PHASE_OFFSET and DPLL_A_PIN_PHASE_ADJUST out of the message in that case, as dpll_msg_add_ffo() already does for the fractional frequency offset. Today any error from either callback fails the whole pin dump.
A driver that measures the phase offset only on the input its PLL tracks, or whose part holds a delay larger than the s32 the adjust attribute carries, has no value to report for the pin, and a zero cannot be told from a measurement. A phase adjust request on such a pin is passed to the driver without the comparison against the old value, so the delay can still be set or cleared.
--- drivers/dpll/dpll_netlink.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/dpll/dpll_netlink.c +10 -4
@@ -388,8 +388,11 @@ dpll_msg_add_pin_phase_adjust(struct sk_buff *msg, struct dpll_pin *pin, ret = ops->phase_adjust_get (pin,dpll_pin_on_dpll_priv (dpll, pin), dpll,dpll_priv (dpll), &phase_adjust, extack); -if (ret) +if (ret) { +if (ret == -ENODATA ) +return 0 ;return ret; + }if (nla_put_s32 (msg,DPLL_A_PIN_PHASE_ADJUST , phase_adjust))return -EMSGSIZE ;
@@ -411,8 +414,11 @@ dpll_msg_add_phase_offset(struct sk_buff *msg, struct dpll_pin *pin, ret = ops->phase_offset_get (pin,dpll_pin_on_dpll_priv (dpll, pin), dpll,dpll_priv (dpll), &phase_offset, extack); -if (ret) +if (ret) { +if (ret == -ENODATA ) +return 0 ;return ret; + }if (nla_put_64bit (msg,DPLL_A_PIN_PHASE_OFFSET ,sizeof (phase_offset), &phase_offset,DPLL_A_PIN_PAD ))return -EMSGSIZE ;
@@ -1452,11 +1458,11 @@ dpll_pin_phase_adj_set(struct dpll_pin *pin, struct nlattr *phase_adj_attr, ret = ops->phase_adjust_get (pin,dpll_pin_on_dpll_priv (dpll, pin), dpll,dpll_priv (dpll), &old_phase_adj, extack); -if (ret) { +if (ret && ret != -ENODATA ) {NL_SET_ERR_MSG (extack,"unable to get old phase adjust value" );return ret; } -if (phase_adj == old_phase_adj) +if (!ret && phase_adj == old_phase_adj)return 0 ; ret = ops->phase_adjust_set(pin, dpll_pin_on_dpll_priv(dpll, pin),
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 01/13] dpll: omit pin phase attributes the driver has no value for
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] This patch makes the core leave DPLL_A_PIN_PHASE_OFFSET out of a pin's parent-device nest, and DPLL_A_PIN_PHASE_ADJUST out of a pin…
--
dpll: omit pin phase attributes the driver has no value for
With this patch, the phase_offset_get and phase_adjust_get callbacks can return -ENODATA. The core then leaves DPLL_A_PIN_PHASE_OFFSET or DPLL_A_PIN_PHASE_ADJUST out of the message instead of failing the whole pin dump. When the old value is not available, dpll_pin_phase_adj_set() skips the comparison against it and passes the request on to the driver.
Quoted 20 lines
drivers/dpll/dpll_netlink.c +4
-1@@ -388,8 +388,11 @@ dpll_msg_add_pin_phase_adjust(struct sk_buff *msg, struct dpll_pin *pin, ret = ops->phase_adjust_get (pin,dpll_pin_on_dpll_priv (dpll, pin), dpll,dpll_priv (dpll), &phase_adjust, extack); -if (ret) +if (ret) { +if (ret == -ENODATA ) +return 0 ;return ret; + }if (nla_put_s32 (msg,DPLL_A_PIN_PHASE_ADJUST , phase_adjust))return -EMSGSIZE ;@@ -411,8 +414,11 @@ dpll_msg_add_phase_offset(struct sk_buff *msg, struct dpll_pin *pin, ret = ops->phase_offset_get(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, dpll_priv(dpll), &phase_offset,
drivers/dpll/dpll_netlink.c dpll_msg_add_phase_offset(struct sk_buff *msg, struct dpll_pin *pin, · line 424
Quoted 10 lines
drivers/dpll/dpll_netlink.c +4
-1extack); -if (ret) +if (ret) { +if (ret == -ENODATA ) +return 0 ;return ret; + }if (nla_put_64bit (msg,DPLL_A_PIN_PHASE_OFFSET ,sizeof (phase_offset), &phase_offset,DPLL_A_PIN_PAD ))return -EMSGSIZE ;
[Severity: Low]
Should Documentation/driver-api/dpll.rst be updated along with these two -ENODATA paths? Right now it still promises that both attributes are always present.
The "Phase offset measurement and adjustment" section says:
If pin-dpll phase offset measurement is supported, it shall be provided with DPLL_A_PIN_PHASE_OFFSET attribute for each parent dpll device.
and:
Configured phase adjust value is provided with
DPLL_A_PIN_PHASE_ADJUST attribute of a pin
The "Phase offset monitor" section says:
Once enabled the phase offset measurements for the input shall be returned in the DPLL_A_PIN_PHASE_OFFSET attribute.
After this change, dpll_cmd_pin_get_one() can still send DPLL_A_PIN_PHASE_ADJUST_MIN/MAX/GRAN from pin->prop without DPLL_A_PIN_PHASE_ADJUST. It can also send a DPLL_A_PIN_PARENT_DEVICE nest without DPLL_A_PIN_PHASE_OFFSET, even though ops->phase_offset_get is implemented.
The new driver-facing rule, that -ENODATA from these callbacks means "no value, omit the attribute", also isn't written down anywhere. The phase_offset_get and phase_adjust_get members of struct dpll_pin_ops in include/linux/dpll.h have no comment describing it. The netlink spec in Documentation/netlink/specs/dpll.yaml doesn't say these attributes may be absent.
None of the later patches in the series, up to and including "dpll:
sit9531x: model the inter-PLL sync line as a pair of pins", touches dpll.rst, include/linux/dpll.h or dpll.yaml. The sit9531x driver added later in the series returns -ENODATA from phase_offset_get, and from phase_adjust_get when the delay is above S32_MAX. Once the series lands, the documented guarantee no longer holds for an in-tree driver.
Could the documentation and the callback descriptions be updated to cover the -ENODATA case?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 2/13 dt-bindings: vendor-prefixes: add SiTime Corporation
In reply to Ali RouhiAdd vendor prefix for SiTime Corporation, manufacturer of programmable clock generators and MEMS oscillators.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1581,6 +1581,8 @@ patternProperties: description: SiRF Technology, Inc. "^sis,.*": description: Silicon Integrated Systems Corp. + "^sitime,.*": + description: SiTime Corporation "^sitronix,.*": description: Sitronix Technology Corporation "^skov,.*":
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v16 3/13 dt-bindings: dpll: add SiTime SiT95316 clock generator
In reply to Ali RouhiAdd a binding for the SiTime SiT9531x family of clock generators: an I2C-controlled device with four independent PLLs, up to eight input clocks and up to twelve outputs, described as a DPLL provider.
The XO is given either as a clock or, for firmware that describes the oscillator as a property rather than as a clock provider, such as ACPI, as clock-frequency.
The supplies are described by their pin names: the core and input rails, the GPIO rail the SiT95317 has, and one per output-driver pin: VDDO0 to VDDO7 on the SiT95317, VDDO0_1, VDDO2 to VDDO9 and VDDO10_11 on the SiT95316. The driver does not enable them; describing them gives a board with switchable rails a way to say so.
--- .../bindings/dpll/sitime,sit95316.yaml | 214 ++++++++++++++++++ MAINTAINERS | 6 + 2 files changed, 220 insertions(+) create mode 100644 Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml
Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml new file +214 -0
@@ -0,0 +1,214 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/dpll/sitime,sit95316.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SiTime SiT95316/SiT95317 DPLL Clock Generator + +maintainers: + - Ali Rouhi <[email protected]> + +description: | + SiTime SiT95316 and SiT95317 are I2C-controlled programmable clock + generators with integrated DPLL for synchronization applications. Both + variants contain four PLLs with automatic/manual reference selection, + DCO frequency adjustment, and phase offset measurement via an on-chip + TDC (Time-to-Digital Converter). + + Both parts have 4 differential input pairs whose lanes can also be + driven independently as single-ended references, so 8 inputs are + individually selectable. SiT95317 drives 8 outputs, SiT95316 + drives 12. + + Pin numbering. An input pin's reg is its lane: 2k is INkP and 2k + 1 + is INkN, 0 to 7. A pair the loaded configuration runs differential is + one input, described at 2k. An output pin's reg is its physical output + OUTn, 0 to 11; the SiT95317 bonds out the die's outputs 0, 3, 4, 5, 7, 8, + 9 and 11, which its datasheet names OUT0 to OUT7 in that order. + +properties: + compatible: + enum: + - sitime,sit95316 + - sitime,sit95317 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: xtal + + clock-frequency: + description: + XO rate in Hz feeding XIN/XO_CLK, for firmware that describes the + oscillator as a property rather than as a clock provider, such as + ACPI. Use either this or "clocks", not both. + + reset-gpios: + maxItems: 1 + description: + GPIO connected to the chip's active-low reset pin (RESETB). + + interrupts: + maxItems: 1 + description: + Interrupt from the chip's active-low INTRB output. Asserted when + the device detects a status change such as lock acquisition or loss. + + dpll-types: + maxItems: 4 + + vdd-supply: + description: Core supply of the PLLs, 1.8 V (the VDD pins). + + vddin-supply: + description: + Supply of the input receivers and dividers, 3.3 V (VDDIN). + + vdds-supply: + description: + Supply of the two GPIO pins that have their own rail (VDDS). The + SiT95316 has no such pin. + + input-pins: + type: object + patternProperties: + "^pin@[0-9a-f]+$": + type: object + properties: + reg: + maximum: 7 + + supported-frequencies-hz: + maxItems: 1 + description: + The rate wired to the input, in Hz, as a single entry. An + input runs at the rate the board feeds it and has no + frequency to select, so that entry is what the pin reports + as its frequency. + +patternProperties: + "^vddo([0-9]|1[01]|0_1|10_11)-supply$": + description: | + Supply of an output driver, named after its VDDO pin. The SiT95317 + has one per output, VDDO0 to VDDO7, numbered as that part's + datasheet numbers its outputs; in the pin numbering of this binding + those are outputs 0, 3, 4, 5, 7, 8, 9 and 11, in that order. The + SiT95316 has VDDO0_1, VDDO2 to VDDO9 and VDDO10_11, the two shared + pins each powering the pair of outputs they are named after. + +required: + - compatible + - reg + +dependencies: + clocks: [ clock-names ] + +oneOf: + - required: + - clocks + - required: + - clock-frequency + +allOf: + - $ref: /schemas/dpll/dpll-device.yaml# + - if: + properties: + compatible: + const: sitime,sit95317 + then: + properties: + output-pins: + patternProperties: + "^pin@[0-9a-f]+$": + properties: + reg: + enum: [0, 3, 4, 5, 7, 8, 9, 11] + patternProperties: + "^vddo(8|9|1[01]|0_1|10_11)-supply$": false + else: + properties: + vdds-supply: false + output-pins: + patternProperties: + "^pin@[0-9a-f]+$": + properties: + reg: + maximum: 11 + patternProperties: + "^vddo(1[01]|[01])-supply$": false + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + dpll@68 { + compatible = "sitime,sit95316"; + reg = <0x68>; + clocks = <&xo2>; + clock-names = "xtal"; + reset-gpios = <&gpio 78 GPIO_ACTIVE_LOW>; + interrupts = <12 IRQ_TYPE_LEVEL_LOW>; + vdd-supply = <®_1v8>; + vddin-supply = <®_3v3>; + vddo0_1-supply = <®_3v3>; + vddo10_11-supply = <®_1v8>; + dpll-types = "eec", "eec", "eec", "eec"; + + input-pins { + #address-cells = <1>; + #size-cells = <0>; + + /* IN0P and IN0N: pair 0 runs single-ended */ + pin@0 { + reg = <0>; + label = "clkin0"; + connection-type = "ext"; + supported-frequencies-hz = <10000000>; + }; + + pin@1 { + reg = <1>; + label = "clkin1"; + connection-type = "synce"; + supported-frequencies-hz = <156250000>; + }; + }; + + output-pins { + #address-cells = <1>; + #size-cells = <0>; + + pin@0 { + reg = <0>; + label = "clkout0"; + supported-frequencies-hz = <156250000>; + }; + + pin@1 { + reg = <1>; + label = "clkout1"; + supported-frequencies-hz = <25000000>; + }; + + pin@a { + reg = <10>; + label = "clkout10"; + supported-frequencies-hz = <10000000>; + }; + }; + }; + }; +...
MAINTAINERS +6 -0
@@ -25870,6 +25870,12 @@ S: Maintained W: http://www.winischhofer.at/linuxsisusbvga.shtml F: drivers/usb/misc/sisusbvga/ +SITIME SIT9531X DPLL DRIVER +M: Ali Rouhi <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml + SL28 CPLD MFD DRIVER M: Michael Walle <[email protected]> S: Maintained
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 03/13] dt-bindings: dpll: add SiTime SiT95316 clock generator
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new binding uses the shared dpll-pin.yaml property supported-frequencies-hz with 32-bit cells, and nothing states the…
--
dt-bindings: dpll: add SiTime SiT95316 clock generator
This adds a DT binding for the SiTime SiT95316/SiT95317 DPLL clock generators. It describes the XO, reset, interrupt, supplies and the input/output pins on top of dpll-device.yaml, and it adds a MAINTAINERS entry for the binding.
Quoted 5 lines
Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml new file +0
-0
[ ... ]
Quoted 6 lines
Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml new file +6
-0+ input-pins: + type: object + patternProperties: + "^pin@[0-9a-f]+$": + type: object + properties:
Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml line 93
Quoted 10 lines
Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml new file +10
-0+ reg: + maximum: 7 + + supported-frequencies-hz: + maxItems: 1 + description: + The rate wired to the input, in Hz, as a single entry. An + input runs at the rate the board feeds it and has no + frequency to select, so that entry is what the pin reports + as its frequency.
[Severity: Low]
Should this binding state the cell width of supported-frequencies-hz?
The shared definition in dpll-pin.yaml has no type:
supported-frequencies-hz:
description: List of supported frequencies for this pin, expressed in Hz.
The only other binding that uses it, microchip,zl30731.yaml, writes it as 64-bit:
supported-frequencies-hz = /bits/ 64 <1>;
zl3073x_pin_props_get() in drivers/dpll/zl3073x/prop.c reads it with fwnode_property_count_u64().
The example in this binding uses 32-bit cells. The sit9531x driver added later in this series reads the property with fwnode_property_count_u32() and fwnode_property_read_u32_array().
A DTB does not record cell width. So a sitime node written the zl30731 way, for example:
supported-frequencies-hz = /bits/ 64 <10000000>;
would be read by the sit9531x driver as two u32 entries, [0, 10000000].
For an input pin, the driver takes the pin rate from freqs[0], so the pin would report 0 Hz. For an output pin, an extra 0 Hz entry would be advertised. Output pins have no maxItems limit, so validation would not catch that case.
Could the encoding be stated here, for example with a uint32-array $ref or a note in the per-pin description? Or could the type be fixed once in dpll-pin.yaml, so the two DPLL bindings don't use different encodings without saying so?
[ ... ]
Quoted 6 lines
Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml new file +6
-0+ pin@0 { + reg = <0>; + label = "clkin0"; + connection-type = "ext"; + supported-frequencies-hz = <10000000>; + };
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 4/13 dpll: add basic SiTime SiT9531x support
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Add the I2C probe for the SiTime SiT9531x family: four PLLs, up to eight inputs and up to twelve outputs, configured from efuse or from a blob applied before the driver binds. Later patches register the PLLs with the DPLL subsystem.
The register space is 32 pages of 256 registers, selected through offset 0xFF of any page. The regmap is the flat 256-byte window, and the accessors select the page under a lock. A regmap paged range is not
used: it reads the selector back on each access, which doubles the bus traffic, and a debugfs access would move the page under the driver.
Probe requests the optional reset line before it enables the XO, so a deferred probe does not gate the clock of a running part, reads the XO rate, waits the boot time with reset deasserted so the configuration the part holds is kept, and identifies the variant from the ID register.
--- MAINTAINERS | 1 + drivers/dpll/Kconfig | 2 + drivers/dpll/Makefile | 1 + drivers/dpll/sit9531x/Kconfig | 13 ++ drivers/dpll/sit9531x/Makefile | 4 + drivers/dpll/sit9531x/core.c | 318 +++++++++++++++++++++++++++++++++ drivers/dpll/sit9531x/core.h | 88 +++++++++ drivers/dpll/sit9531x/regs.h | 36 ++++ 8 files changed, 463 insertions(+) create mode 100644 drivers/dpll/sit9531x/Kconfig create mode 100644 drivers/dpll/sit9531x/Makefile create mode 100644 drivers/dpll/sit9531x/core.c create mode 100644 drivers/dpll/sit9531x/core.h create mode 100644 drivers/dpll/sit9531x/regs.h
MAINTAINERS +1 -0
@@ -25875,6 +25875,7 @@ M: Ali Rouhi <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml +F: drivers/dpll/sit9531x/ SL28 CPLD MFD DRIVER M: Michael Walle <[email protected]>
drivers/dpll/Kconfig +2 -0
@@ -23,6 +23,8 @@ config DPLL_REFCNT_TRACKER If unsure, say N. +source "drivers/dpll/sit9531x/Kconfig" + source "drivers/dpll/zl3073x/Kconfig" endmenu
drivers/dpll/Makefile +1 -0
@@ -8,4 +8,5 @@ dpll-y += dpll_core.o dpll-y += dpll_netlink.o dpll-y += dpll_nl.o +obj-$(CONFIG_SIT9531X_DPLL) += sit9531x/ obj-$(CONFIG_ZL3073X) += zl3073x/
drivers/dpll/sit9531x/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config SIT9531X_DPLL + tristate "SiTime SiT9531x DPLL driver" + depends on I2C && NET + select DPLL + select REGMAP_I2C + help + Driver for SiTime SiT9531x family clock generators + (SiT95317, SiT95316). + + To compile this driver as a module, choose M here: the + module will be called sit9531x.
drivers/dpll/sit9531x/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_SIT9531X_DPLL) += sit9531x.o +sit9531x-y := core.o
drivers/dpll/sit9531x/core.c new file +318 -0
318 lines not on this page · raw message
drivers/dpll/sit9531x/core.h new file +88 -0
88 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* SiTime SiT9531x register definitions +* +* Copyright (C) 2026 SiTime Corp. +* Author: Ali Rouhi <[email protected]> +* Author: Oleg Zadorozhnyi <[email protected]> +*/ + +#ifndef _SIT9531X_REGS_H +#define _SIT9531X_REGS_H + +/* +* The page select is at offset 0xFF in every page; some pages are paired, e.g. +* 0x0A/0x1A for PLLA. +*/ +#define SIT9531X_PAGE_SEL 0xFF +#define SIT9531X_PAGE_SIZE 0x100 +#define SIT9531X_NUM_PAGES 32 + +#define SIT9531X_REG (_page, _offset) (((_page) << 8) | (_offset)) +#define SIT9531X_REG_PAGE (_reg) ((_reg) >> 8) +#define SIT9531X_REG_OFFSET (_reg) ((_reg) & 0xFF) + +#define SIT9531X_PAGE_OUTSYS0 0x03 +#define SIT9531X_PAGE_OUTSYS1 0x04 +#define SIT9531X_PAGE_PLLA 0x0A +#define SIT9531X_PAGE_PLLA_EXT 0x1A + +/* Reg 0x03 holds an unrelated revision byte, not part of the variant ID */ +#define SIT9531X_REG_VARIANT_ID SIT9531X_REG(0x00, 0x02) + +#define SIT9531X_VARIANT_ID_95317 0x17 +#define SIT9531X_VARIANT_ID_95316 0x31 + +#endif /* _SIT9531X_REGS_H */
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 04/13] dpll: add basic SiTime SiT9531x support
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] dpll: sit9531x: missing regulator enable in sit9531x_dev_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] dpll: sit9531x: missing regulator enable in sit9531x_dev_probe()
--
commit 7413ebc82cba0bf0979b71e1af2d94d59391bd01
Author: Oleg Zadorozhnyi <[email protected]>
dpll: add basic SiTime SiT9531x support
This commit adds the core I2C driver, probe handling, and paged register accessors for the SiTime SiT9531x DPLL family.
Quoted 5 lines
drivers/dpll/sit9531x/core.c new file +0
-0
[ ... ]
Quoted 40 lines
drivers/dpll/sit9531x/core.c new file +40
-0+static int sit9531x_dev_probe (struct sit9531x_dev *sitdev) +{ +struct clk *xtal_clk; +u8 variant_id; +int rc; + +/* +* Request before enabling the XO: a probe deferral would gate the XO +* and remove the reference of a running part. +*/ + sitdev->reset_gpio =devm_gpiod_get_optional (sitdev->dev,"reset" , +GPIOD_ASIS ); +if (IS_ERR (sitdev->reset_gpio)) +return dev_err_probe (sitdev->dev,PTR_ERR (sitdev->reset_gpio), +"Failed to request reset gpio\n" ); + +/* +* Fvco = Fref * (DIVN + frac/2^32); Fref is the rate of the XO feeding +* XIN/XO_CLK. +*/ + xtal_clk =devm_clk_get_optional_enabled (sitdev->dev,"xtal" ); +if (IS_ERR (xtal_clk)) +return dev_err_probe (sitdev->dev,PTR_ERR (xtal_clk), +"Failed to get xtal clock\n" ); + sitdev->xtal_freq =clk_get_rate (xtal_clk); +if (!sitdev->xtal_freq) { +u32 freq; + +if (!device_property_read_u32 (sitdev->dev,"clock-frequency" , + &freq)) + sitdev->xtal_freq = freq; + } +if (!sitdev->xtal_freq) +return dev_err_probe (sitdev->dev, -EINVAL , +"no xtal rate: provide clocks=<&xo> + clock-names=\"xtal\", or a clock-frequency property\n" ); + +/* +* Keep reset deasserted, never pulse it: a reset discards the +* configuration from efuse or a pre-probe NVM blob. Release it before +* the first I2C access.
drivers/dpll/sit9531x/core.c line 250
Quoted 10 lines
drivers/dpll/sit9531x/core.c new file +10
-0+*/ +if (sitdev->reset_gpio) { + rc =gpiod_direction_output (sitdev->reset_gpio,0 ); +if (rc) +return dev_err_probe (sitdev->dev, rc, +"Failed to release the reset line\n" ); +fsleep (10000 );/* internal boot after release */ + } + + rc =sit9531x_read_variant_id (sitdev, &variant_id);
[Severity: Medium]
As reported by Jakub Kicinski on v15 [1], should sit9531x_dev_probe() request and enable the device power supplies before releasing reset_gpio and performing the first I2C read?
The sitime,sit95316.yaml DT binding defines vdd-supply, vddin-supply, vdds-supply, and the vddoN-supply rails, but the driver never claims or enables any regulators. On boards with switchable rails that are off at boot, sit9531x_read_variant_id() will fail against an unpowered chip; if the bootloader left a non-always-on regulator enabled, regulator_late_cleanup() will turn it off at late_initcall time while the driver is bound, powering down the device and losing its configuration.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH net-next v16 04/13] dpll: add basic SiTime SiT9531x support
In reply to Ali RouhiThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] sit9531x_dev_probe() (drivers/dpll/sit9531x/core.c) never gets or enables any supply that the series' binding defines: vdd-supply…
- [Medium] sit9531x_dev_probe() enables the XO with devm_clk_get_optional_enabled().
- [Low] The commit message rejects a regmap paged range partly because 'a debugfs access would move the page under the driver'.
- [Low] All three new files (core.c, core.h, regs.h) name Ali Rouhi as Author in their headers, listed first, and MODULE_AUTHOR lists him…
--
dpll: add basic SiTime SiT9531x support
This adds the I2C probe for the SiTime SiT9531x DPLL family. It uses a flat 256-byte regmap window, and the driver selects the page under a lock. Probe requests the optional reset line, enables the XO, releases reset and identifies the variant from the ID register.
Quoted 5 lines
The register space is 32 pages of 256 registers, selected through offset
0xFFof any page. The regmap is the flat 256-byte window, and the accessors select the page under a lock. A regmap paged range is not
used: it reads the selector back on each access, which doubles the bus traffic, and a debugfs access would move the page under the driver.
[Severity: Low]
Does the debugfs part of this rationale hold for regmap ranges?
As far as I can tell, _regmap_select_page() in drivers/base/regmap/regmap.c selects the page again on every access through the range, under the regmap lock:
ret = _regmap_update_bits(map, range->selector_reg,
range->selector_mask,
win_page << range->selector_shift,
NULL, false);So a debugfs access should not leave a range-based driver with a stale page.
The flat window chosen here looks like the design that has the page-tracking hazard. sit9531x_page_select() trusts the cached value and skips the selector write:
if (sitdev->page == page)
return 0;The regmap debugfs registers file for sit9531x_regmap_config dumps offsets 0x00-0xFF of whatever page the driver last selected. It does this without taking page_lock, and the dump does not say which page it shows.
Debugfs writes to 0xFF are compiled out by default (REGMAP_ALLOW_WRITE_DEBUGFS is undefined), so hitting the stale cache case needs a source change.
Could the commit message describe this tradeoff more precisely?
Quoted 3 lines
Suggested-by Ivan Vecera <[email protected]>Signed-off-by Oleg Zadorozhnyi <[email protected]>Signed-off-by Ali Rouhi <[email protected]>
[Severity: Low]
This isn't a bug, but core.c, core.h and regs.h all name Ali Rouhi first as Author in their headers, and MODULE_AUTHOR() lists him first too. If he co-developed the patch, should there be a Co-developed-by: tag right before his Signed-off-by:, as Documentation/process/submitting-patches.rst describes?
Quoted 6 lines
drivers/dpll/sit9531x/core.c new file +0
-0@@ -0,0 +1,318 @@
[ ... ]
Quoted 11 lines
drivers/dpll/sit9531x/core.c new file +11
-0+static int sit9531x_dev_probe (struct sit9531x_dev *sitdev) +{ +struct clk *xtal_clk; +u8 variant_id; +int rc; + +/* +* Request before enabling the XO: a probe deferral would gate the XO +* and remove the reference of a running part. +*/ + sitdev->reset_gpio = devm_gpiod_get_optional(sitdev->dev, "reset",
drivers/dpll/sit9531x/core.c line 221
Quoted 10 lines
drivers/dpll/sit9531x/core.c new file +10
-0+ GPIOD_ASIS); +if (IS_ERR (sitdev->reset_gpio)) +return dev_err_probe (sitdev->dev,PTR_ERR (sitdev->reset_gpio), +"Failed to request reset gpio\n" ); + +/* +* Fvco = Fref * (DIVN + frac/2^32); Fref is the rate of the XO feeding +* XIN/XO_CLK. +*/ + xtal_clk =devm_clk_get_optional_enabled (sitdev->dev,"xtal" );
[Severity: Medium]
The comment above says the goal is to avoid gating the XO of a running part. Doesn't devm_clk_get_optional_enabled() still gate it on every failure path after this point?
drivers/clk/clk-devres.c implements it as:
return __devm_clk_get(dev, id, clk_get_optional,
clk_prepare_enable, clk_disable_unprepare);
So devres calls clk_disable_unprepare() on any probe failure after this point, while the part stays out of reset and configured. That includes:
- the "no xtal rate" -EINVAL return
- a gpiod_direction_output() failure
- a transient I2C error from sit9531x_read_variant_id()
- the "Unknown variant ID" -ENODEV return
- a devm_mutex_init() failure
The driver has no .remove and is fully devm-managed, so a sysfs unbind or rmmod gates the XO as well.
Later patches in the series add more failure points after the XO enable (sit9531x_devm_dpll_init(), devm_request_threaded_irq()), and the XO is still devm-enabled.
If the XO is gateable and this driver is its only consumer, won't this stop the reference of a chip running from its efuse/NVM configuration?
Quoted 3 lines
drivers/dpll/sit9531x/core.c new file +3
-0+if (IS_ERR (xtal_clk)) +return dev_err_probe (sitdev->dev,PTR_ERR (xtal_clk), +"Failed to get xtal clock\n" );
[ ... ]
drivers/dpll/sit9531x/core.c line 250
Quoted 9 lines
drivers/dpll/sit9531x/core.c new file +9
-0+if (sitdev->reset_gpio) { + rc =gpiod_direction_output (sitdev->reset_gpio,0 ); +if (rc) +return dev_err_probe (sitdev->dev, rc, +"Failed to release the reset line\n" ); +fsleep (10000 );/* internal boot after release */ + } + + rc =sit9531x_read_variant_id (sitdev, &variant_id);
[Severity: Medium]
Should probe get and enable the supplies defined in the binding before this first I2C access?
The binding in this series (sitime,sit95316.yaml) documents vdd-supply, vddin-supply, vdds-supply and the vddoN-supply rails. It says they are there so that "a board with switchable rails" can describe them, and its example points vdd-supply/vddin-supply at ®_1v8/®_3v3.
The binding commit does note "The driver does not enable them", and sit9531x_dev_probe() makes no regulator call.
If the rail is off at probe on such a board, this read goes to an unpowered part. Probe then fails with an I2C error or a misleading "Unknown variant ID", and nothing points at the missing supply.
If the bootloader left the rail on, no consumer claims it. Wouldn't regulator_late_cleanup() then turn it off? It only skips regulators that are always_on or have a nonzero use_count. That would cut power to a running DPLL and drop the efuse/NVM configuration this patch tries to keep.
A separate point: when reset-gpios is absent, nothing waits before this read, because the fsleep() only runs when the reset GPIO exists. Does the part need time after the XO is enabled before it answers on I2C?
At the end of the series, drivers/dpll/sit9531x/ still has no regulator handling.
Quoted 8 lines
drivers/dpll/sit9531x/core.c new file +8
-0+if (rc) +return rc; + + sitdev->info =sit9531x_match_variant (variant_id); +if (!sitdev->info) +return dev_err_probe (sitdev->dev, -ENODEV , +"Unknown variant ID: 0x%02x\n" , + variant_id);
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 5/13 dpll: sit9531x: read DPLL types and pin properties from system firmware
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Read the DPLL type from the firmware node and, for each pin, its label, connection type and supported frequencies. The direction is the caller's and selects the sub-node; the capabilities are fixed per pin class. A node that gives none of these gets defaults.
Inputs are the P and N lanes of four pairs: a pair run single-ended gives two inputs, a differential pair one. Outputs are labeled OUTn by the driver's index, while reg stays the die slot the binding defines, so one binding serves both variants.
The first listed rate is used as an input's rate. An output with no supported-frequencies-hz is advertised as a continuous range, since the core refuses every frequency request on a pin with none.
--- drivers/dpll/sit9531x/Makefile | 2 +- drivers/dpll/sit9531x/core.h | 56 ++++++ drivers/dpll/sit9531x/prop.c | 327 +++++++++++++++++++++++++++++++++ drivers/dpll/sit9531x/prop.h | 37 ++++ 4 files changed, 421 insertions(+), 1 deletion(-) create mode 100644 drivers/dpll/sit9531x/prop.c create mode 100644 drivers/dpll/sit9531x/prop.h
drivers/dpll/sit9531x/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_SIT9531X_DPLL) += sit9531x.o -sit9531x-y := core.o +sit9531x-y := core.o prop.o
drivers/dpll/sit9531x/core.h +56 -0
86 lines not on this page · raw message
drivers/dpll/sit9531x/prop.c new file +327 -0
327 lines not on this page · raw message
drivers/dpll/sit9531x/prop.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* SiTime SiT9531x firmware node property parsing +* +* Copyright (C) 2026 SiTime Corp. +* Author: Ali Rouhi <[email protected]> +* Author: Oleg Zadorozhnyi <[email protected]> +*/ + +#ifndef _SIT9531X_PROP_H +#define _SIT9531X_PROP_H + +#include <linux/dpll.h> +#include <linux/fwnode.h> + +struct sit9531x_dev ; + +/* +* struct sit9531x_pin_props - pin properties from firmware +* @fwnode: firmware node handle, NULL if no DT node +* @dpll_props: DPLL core pin properties +* @package_label: pin package label (e.g. "IN0", "OUT3") +*/ +struct sit9531x_pin_props { +struct fwnode_handle *fwnode; +struct dpll_pin_properties dpll_props; +char package_label[8 ]; +}; + +enum dpll_type sit9531x_prop_dpll_type_get (struct sit9531x_dev *sitdev, +u8 index); +struct sit9531x_pin_props *sit9531x_pin_props_get (struct sit9531x_dev *sitdev, +enum dpll_pin_direction dir, +u8 index); +void sit9531x_pin_props_put (struct sit9531x_pin_props *props); + +#endif /* _SIT9531X_PROP_H */
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 05/13] dpll: sit9531x: read DPLL types and pin properties from system firmware
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] At this commit nothing writes ref[].sig_mode, so it stays SIT9531X_MODE_SE from devm_kzalloc().
- [Low] When an output has no supported-frequencies-hz, sit9531x_pin_props_get() advertises a hard-coded continuous range,…
--
dpll: sit9531x: read DPLL types and pin properties from system firmware
This adds prop.c. It reads the DPLL type from the firmware node, plus each pin's label, connection type and supported frequencies, and uses defaults when the node doesn't provide them. An output with no supported-frequencies-hz is advertised as one continuous frequency range.
Quoted 4 lines
drivers/dpll/sit9531x/core.h +0
-0
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.h +0
-0@@ -41,6 +49,35 @@ struct sit9531x_chip_info {const u8 *clkout_map; };
[ ... ]
drivers/dpll/sit9531x/core.h struct sit9531x_chip_info { · line 71
Quoted 10 lines
drivers/dpll/sit9531x/core.h +10
-0+/* +* struct sit9531x_ref - input reference state +* @freq: configured frequency in Hz +* @sig_mode: signal mode of the input pair, read from CLKINx_INPUT_MODE at +* probe +*/ +struct sit9531x_ref { +u64 freq; +enum sit9531x_signal_mode sig_mode; +};
[Severity: Low]
This isn't a bug, but is this kernel-doc accurate at this point in the series?
Nothing in this commit writes ref[].sig_mode, so it stays at SIT9531X_MODE_SE from the zeroed allocation. That means the differential branch in sit9531x_input_pin_label() can't run yet:
if (sitdev->ref[id].sig_mode == SIT9531X_MODE_DE)
snprintf(props->package_label,
sizeof(props->package_label), "IN%u", pair);The binding's pin numbering text ("A pair the loaded configuration runs differential is one input, described at 2k") also has no effect until then.
A later patch in the series fixes this. In "dpll: sit9531x: register DPLL devices and pins", sit9531x_input_mode_fetch() reads CLKINx_INPUT_MODE for every pair at probe and sets both lanes:
sitdev->ref[pair * 2].sig_mode = sig_mode;
sitdev->ref[pair * 2 + 1].sig_mode = sig_mode;So the per-lane ref[id] lookup here gets the right value. Also, nothing calls sit9531x_pin_props_get() at this commit, so no wrong label can be registered in the meantime.
Would it be clearer to add this kernel-doc text in the same patch as sit9531x_input_mode_fetch()?
Quoted 6 lines
drivers/dpll/sit9531x/prop.c new file +0
-0@@ -0,0 +1,327 @@
[ ... ]
Quoted 9 lines
drivers/dpll/sit9531x/prop.c new file +9
-0+skip_fwnode_props: +if (sync_in || sync_out) +return props; + +/* +* An output with no listed rates gets one wide range, as the setter +* checks Fvco/N; the XO gets its one rate. +*/ + ranges =kcalloc (num_freqs +1 ,sizeof (*ranges),GFP_KERNEL );
[ ... ]
drivers/dpll/sit9531x/prop.c line 267
Quoted 4 lines
drivers/dpll/sit9531x/prop.c new file +4
-0+if (!num_freqs && dir ==DPLL_PIN_DIRECTION_OUTPUT ) { + ranges[j].min =1 ; + ranges[j].max =1000000000ULL ;/* 1 GHz */ + j++;
[Severity: Low]
Where does the 1 GHz upper bound in sit9531x_pin_props_get() come from? It isn't derived from the part's limits, and it doesn't match the setter added later in the series.
In "dpll: sit9531x: add support to get and set frequency on pins", sit9531x_output_freq_set() accepts any exact Fvco/N up to U32_MAX:
if (frequency > U32_MAX)
return -EINVAL;
...
if (divo > SIT9531X_DIVO_MAX)
return -EINVAL;Fvco is at least 4.9152 GHz, so dividers from 2 to 7 give about 1.1 to 3.9 GHz across the VCO bands. However, dpll_pin_freq_set() in drivers/dpll/dpll_netlink.c checks the advertised ranges before it calls the driver:
if (!dpll_pin_is_freq_supported(pin, freq)) {
NL_SET_ERR_MSG_ATTR(extack, a, "frequency is not supported by the device");
return -EINVAL;
}On a board with no supported-frequencies-hz in DT, can a DPLL_CMD_PIN_SET above 1 GHz ever reach sit9531x_output_freq_set()? It looks like the core would always return -EINVAL for those divider values. The uAPI would then report a ceiling that doesn't come from the hardware. I couldn't confirm from the tree whether the output buffers can actually drive more than 1 GHz.
The 1 Hz lower bound is fine. SIT9531X_DIVO_MAX is GENMASK_ULL(33, 0), so 1 Hz is an exact Fvco/N.
Also, the comment says "as the setter checks Fvco/N", but that setter only arrives in the later commit mentioned above.
Could the upper bound come from the VCO and divider limits, or from a documented output maximum, so the advertised range and the setter agree?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 6/13 dpll: sit9531x: register DPLL devices and pins
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Register each PLL as a DPLL device with its lock status and mode callbacks, and the XO as a pin on each. Inputs and outputs are registered by the patches that add their state callbacks. Probe also reports the EEPROM profile and its CRC and clears the notification registers; the sleep PM operations stop and restart the poll.
A kthread worker polls the status registers twice a second into a cache the callbacks answer from, so a netlink call does not become a burst of I2C transfers. A tick is about a hundred transfers and notifies the core of what changed; a transition that begins and ends inside one period is not reported. INTRB, where wired, schedules a tick early.
A PLL that arbitrates by priority is reported AUTOMATIC, one on manual input select MANUAL. The clock_id is built from the SiTime OUI, the I2C bus number and the address; an i2c alias in the firmware description keeps it the same across boots.
--- drivers/dpll/sit9531x/Kconfig | 4 + drivers/dpll/sit9531x/Makefile | 2 +- drivers/dpll/sit9531x/core.c | 1478 ++++++++++++++++++++++++++++++-- drivers/dpll/sit9531x/core.h | 157 +++- drivers/dpll/sit9531x/dpll.c | 295 +++++++ drivers/dpll/sit9531x/dpll.h | 61 ++ drivers/dpll/sit9531x/regs.h | 205 +++++ 7 files changed, 2106 insertions(+), 96 deletions(-) create mode 100644 drivers/dpll/sit9531x/dpll.c create mode 100644 drivers/dpll/sit9531x/dpll.h
drivers/dpll/sit9531x/Kconfig +4 -0
@@ -9,5 +9,9 @@ config SIT9531X_DPLL Driver for SiTime SiT9531x family clock generators (SiT95317, SiT95316). + This driver registers each on-chip PLL as a DPLL device + and exposes input/output clocks as DPLL pins, providing + runtime configuration via Generic Netlink. + To compile this driver as a module, choose M here: the module will be called sit9531x.
drivers/dpll/sit9531x/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_SIT9531X_DPLL) += sit9531x.o -sit9531x-y := core.o prop.o +sit9531x-y := core.o dpll.o prop.o
drivers/dpll/sit9531x/core.c +1395 -83
1,556 lines not on this page · raw message
drivers/dpll/sit9531x/core.h +145 -12
225 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.c new file +295 -0
295 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.h new file +61 -0
61 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h +205 -0
211 lines not on this page · raw message
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 06/13] dpll: sit9531x: register DPLL devices and pins
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] dpll: sit9531x: lock error reported on inactive PLL in sit9531x_dpll_lock_status_get() - [Medium]…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] dpll: sit9531x: lock error reported on inactive PLL in sit9531x_dpll_lock_status_get()
- [Medium] dpll: sit9531x: unmasked INTRB latches cause storm in sit9531x_irq_thread_fn()
--
commit f2688535e3fdf8a8e4a4d89421da6aae6f0f4bb8
Author: Oleg Zadorozhnyi <[email protected]>
dpll: sit9531x: register DPLL devices and pins
This commit registers each PLL on the SiT9531x as a DPLL device with its XO pin, adds a periodic kthread worker and optional INTRB threaded IRQ handler to poll hardware status into a cache, and wires up system sleep PM operations.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -181,132 +206,1419 @@ int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,
[ ... ]
Quoted 22 lines
drivers/dpll/sit9531x/core.c +22
-0+/* Queue an immediate poll tick; polling continues as a fallback. */ +static irqreturn_t sit9531x_irq_thread_fn (int irq,void *data) +{ +struct sit9531x_dev *sitdev = data; +int rc; + +/* +* Acknowledge here: IRQF_ONESHOT unmasks the line on return, and a +* still-asserted INTRB would fire again at once. +*/ +mutex_lock (&sitdev->multiop_lock); + rc =sit9531x_clear_notifications (sitdev); +mutex_unlock (&sitdev->multiop_lock); +if (rc) { +dev_warn_ratelimited (sitdev->dev, +"IRQ: failed to clear notifications: %d\n" , + rc); +if (++sitdev->irq_ack_fails <SIT9531X_IRQ_ACK_TRIES ) +return IRQ_NONE ; + + dev_err(sitdev->dev, + "IRQ %d disabled: notifications cannot be cleared, polling only\n",
drivers/dpll/sit9531x/core.c int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx, · line 951
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ irq); +disable_irq_nosync (irq); +return IRQ_NONE ; + } + + sitdev->irq_ack_fails =0 ; + +kthread_mod_delayed_work (sitdev->kworker, &sitdev->work,0 ); +return IRQ_HANDLED ; +}
[Severity: Medium]
As reported by Jakub Kicinski on v15 [1], can sit9531x_irq_thread_fn() trigger a level-triggered interrupt storm if the device profile routes a sticky latch outside the eight registers cleared by sit9531x_clear_notifications() to INTRB?
The driver does not program the INTRB mask registers, and sit9531x_eeprom_state_report() reads the sticky SIT9531X_REG_EEPROM_NOTIF register at probe and leaves its bits set. If an unmonitored latch like SIT9531X_REG_EEPROM_NOTIF drives INTRB low, sit9531x_clear_notifications() succeeds without deasserting the line and sit9531x_irq_thread_fn() returns IRQ_HANDLED on every pass, preventing the spurious-IRQ detector from steping in while firing continuous I2C transactions.
Quoted 6 lines
drivers/dpll/sit9531x/dpll.c new file +0
-0@@ -0,0 +1,295 @@
[ ... ]
Quoted 47 lines
drivers/dpll/sit9531x/dpll.c new file +47
-0+static int +sit9531x_dpll_lock_status_get (const struct dpll_device *dpll,void *dpll_priv, +enum dpll_lock_status *status, +enum dpll_lock_status_error *status_error, +struct netlink_ext_ack *extack) +{ +struct sit9531x_dpll *sitdpll = dpll_priv; +struct sit9531x_dev *sitdev = sitdpll->dev; +const struct sit9531x_chan *chan; + +if (status_error) + *status_error =DPLL_LOCK_STATUS_ERROR_NONE ; + + chan =sit9531x_chan_state_get (sitdev, sitdpll->id); + +mutex_lock (&sitdev->multiop_lock); + +if (chan->stale) { + *status =DPLL_LOCK_STATUS_UNLOCKED ; +if (status_error) + *status_error =DPLL_LOCK_STATUS_ERROR_UNDEFINED ; + }else if (!chan->active) { +/* +* An unused PLL never goes active and its loss-of-lock bit is +* not driven. +*/ + *status =DPLL_LOCK_STATUS_UNLOCKED ; + }else if (chan->inner_lol) { +/* +* The core reports the error detail only with an unlocked or +* holdover status. +*/ + *status = chan->ho_freeze ?DPLL_LOCK_STATUS_HOLDOVER : +DPLL_LOCK_STATUS_UNLOCKED ; + }else if (chan->mode) { +/* +* In free-run the outer loop is disabled and its loss-of-lock +* bit is meaningless. +*/ + *status =DPLL_LOCK_STATUS_UNLOCKED ; + }else if (chan->ho_freeze) { +/* +* Test freeze before lock: a frozen PLL tracks no reference +* whatever its outer loss-of-lock bit reads. +*/ + *status =DPLL_LOCK_STATUS_HOLDOVER ; + }else if (chan->locked) {
drivers/dpll/sit9531x/dpll.c line 98
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c new file +10
-0+if (chan->ho_valid) + *status =DPLL_LOCK_STATUS_LOCKED_HO_ACQ ; +else + *status =DPLL_LOCK_STATUS_LOCKED ; + }else { + *status =DPLL_LOCK_STATUS_UNLOCKED ; + } + +if (status_error && chan->inner_lol) + *status_error =DPLL_LOCK_STATUS_ERROR_UNDEFINED ;
[Severity: Medium]
Should setting *status_error = DPLL_LOCK_STATUS_ERROR_UNDEFINED for chan->inner_lol move inside the else if (chan->inner_lol) branch?
Because it sits after the if/else-if chain, an unused PLL (!chan->active) whose inner_lol bit is set still reports DPLL_LOCK_STATUS_ERROR_UNDEFINED alongside DPLL_LOCK_STATUS_UNLOCKED, and sit9531x_dpll_changes_check() will emit change notifications if inner_lol toggles on an inactive PLL.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH net-next v16 06/13] dpll: sit9531x: register DPLL devices and pins
In reply to Ali RouhiThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] sit9531x_derive_clock_id() (drivers/dpll/sit9531x/core.c) computes clock_id = SIT9531X_OUI << 24 | (u64)adap << 8 | client->addr.
- [Medium] sit9531x_irq_thread_fn() (drivers/dpll/sit9531x/core.c) writes 0xFF to a fixed set of eight W1C notification registers in…
- [Medium] sit9531x_resume() (drivers/dpll/sit9531x/core.c) assumes the part may have lost power ('After power loss the part is on page 0')…
- [Medium] dpll: sit9531x: lock error reported on inactive PLL in sit9531x_dpll_lock_status_get()
- [Low] Two statements do not match the code.
- [Low] sit9531x_out_state_fetch() prints 'OUT%u is in the output-enable mask of more than one PLL ...' using the die slot (slot =…
--
dpll: sit9531x: register DPLL devices and pins
This commit registers each SiT9531x PLL as a DPLL device with lock status and mode callbacks, and registers the XO as a pin on each. A kthread worker polls the status registers twice a second into a cache, and INTRB (where wired) schedules an early tick. The clock_id is built from the SiTime OUI, the I2C bus number and the I2C address.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -181,132 +206,1419 @@ int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,
[ ... ]
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+static int sit9531x_out_state_fetch (struct sit9531x_dev *sitdev,u8 index) +{ +struct sit9531x_out *out = &sitdev->out[index]; +u8 map_lo, map_hi, slot, bit, claimed; +int pll_idx; +bool muted, part; +u16 mask; +int rc; + + slot = sitdev->info->clkout_map[index];
[ ... ]
drivers/dpll/sit9531x/core.c int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx, · line 756
Quoted 4 lines
drivers/dpll/sit9531x/core.c +4
-0+if (claimed & (claimed -1 )) +dev_warn (sitdev->dev, +"OUT%u is in the output-enable mask of more than one PLL (0x%x); taking PLL%c\n" , + slot, claimed,'A' + out->pll_idx);
[Severity: Low]
This warning names the output by its die slot. In prop.c, sit9531x_prop_pin_package_label_set() labels output pins "OUT%u" by the package index, and its own comment says the two numbers differ on the SiT95317.
On the SiT95317, clkout_map is {0, 3, 4, 5, 7, 8, 9, 11}. So the pin that userspace sees as "OUT1" shows up here as "OUT3".
Should this print the package index (or both numbers), so one output has one name? This looks the same later in the series.
[ ... ]
Quoted 14 lines
drivers/dpll/sit9531x/core.c +14
-0+/* Queue an immediate poll tick; polling continues as a fallback. */ +static irqreturn_t sit9531x_irq_thread_fn (int irq,void *data) +{ +struct sit9531x_dev *sitdev = data; +int rc; + +/* +* Acknowledge here: IRQF_ONESHOT unmasks the line on return, and a +* still-asserted INTRB would fire again at once. +*/ +mutex_lock (&sitdev->multiop_lock); + rc =sit9531x_clear_notifications (sitdev); +mutex_unlock (&sitdev->multiop_lock); +if (rc) {
[ ... ]
drivers/dpll/sit9531x/core.c int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx, · line 951
Quoted 5 lines
drivers/dpll/sit9531x/core.c +5
-0+ sitdev->irq_ack_fails =0 ; + +kthread_mod_delayed_work (sitdev->kworker, &sitdev->work,0 ); +return IRQ_HANDLED ; +}
[Severity: Medium]
What happens if INTRB is still asserted after this handler returns?
sit9531x_clear_notifications() writes 0xFF to a fixed list of eight
latches: OUTER_LOL, HO_FREEZE, INNER_LOL and CMON on page 0, plus four clock-monitor latches on page 6. The driver does not program or check the INTRB source mask, so it relies on whatever the EEPROM/efuse profile set up.
One example is NOTIFY_4 (SIT9531X_REG_EEPROM_NOTIF, page 0 reg 0x97). regs.h describes it as sticky, with READ_DONE set on every good load. sit9531x_eeprom_state_report() reads it, but nothing clears it.
If the profile routes such a latch to INTRB, IRQF_ONESHOT unmasks a line that is still asserted. The thread then runs again at once, and every pass calls kthread_mod_delayed_work(..., 0).
IRQ_HANDLED is returned every time, so the core's spurious interrupt detection never disables the line. irq_ack_fails only counts I2C write errors.
Can this loop forever, with back-to-back poll ticks of about a hundred paged I2C transfers each? Would it help to read which source asserted INTRB and return IRQ_NONE when no source the driver handles is pending? This looks the same later in the series.
[ ... ]
Quoted 2 lines
drivers/dpll/sit9531x/core.c +2
-0+static int sit9531x_dev_start (struct sit9531x_dev *sitdev) +{
[ ... ]
drivers/dpll/sit9531x/core.c int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx, · line 1076
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+kthread_queue_delayed_work (sitdev->kworker, &sitdev->work,0 ); + +return 0 ;
[Severity: Low]
The commit message says:
"Probe also reports the EEPROM profile and its CRC and clears the notification registers"
The only callers of sit9531x_clear_notifications() are sit9531x_dev_periodic_work() and sit9531x_irq_thread_fn(). Probe just queues the poll here, so the latches are cleared asynchronously, after probe has returned and the IRQ has been requested.
Could the commit message be reworded to match?
On a similar note, the dpll.c file header says:
" * DPLL device ops, pin ops (separate input/output), pin registration,"
The device and pin registration code (sit9531x_dpll_pin_register(), sit9531x_dpll_pins_register(), sit9531x_dpll_register() and so on) lives in core.c, and it is still there later in the series.
[ ... ]
Quoted 8 lines
drivers/dpll/sit9531x/core.c +8
-0+static int sit9531x_derive_clock_id (struct sit9531x_dev *sitdev) +{ +int adap =i2c_adapter_id (sitdev->client->adapter); + +/* +* The OUI with its EUI-64 filler takes the top 40 bits; the bus gets 16 +* bits. +*/
drivers/dpll/sit9531x/core.c int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx, · line 1452
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+if (adap >U16_MAX ) +return dev_err_probe (sitdev->dev, -EINVAL , +"I2C adapter number %d does not fit the clock id\n" , + adap); + + sitdev->clock_id =SIT9531X_OUI <<24 | (u64 )adap <<8 | + sitdev->client->addr; + +return 0 ; +}
[Severity: Medium]
The adapter number is range-checked here. client->addr is not masked to 8 bits, though, and I2C_CLIENT_TEN is not rejected.
With a 10-bit address (up to 0x3FF), bits 8-9 overlap the adapter field. For example, adapter 0 at 10-bit address 0x150 and adapter 1 at address 0x50 both produce:
SIT9531X_OUI << 24 | 0x150
dpll_device_get() matches on (clock_id, device_idx, module). The second chip would therefore get the first chip's struct dpll_device for every PLL index, and the first chip's XO pin through dpll_pin_get().
dpll_device_register() returns -EEXIST only for an identical (ops, priv) pair. Each instance has its own ops copy and priv, so the second registration is accepted without any error.
If the part can be addressed with 10-bit addresses, can two chips end up merged into one DPLL device, with callbacks answered from the first registration's priv? Would rejecting I2C_CLIENT_TEN, or masking the address, be enough to avoid this?
The commit message also says:
"an i2c alias in the firmware description keeps it the same across boots."
That only applies to DT. On ACPI, or with dynamically numbered adapters, the id can change between boots. Could the message say so?
This code looks the same later in the series.
[ ... ]
Quoted 5 lines
drivers/dpll/sit9531x/core.c +5
-0+static int sit9531x_resume (struct device *dev) +{ +struct sit9531x_dev *sitdev =dev_get_drvdata (dev); + +/*
drivers/dpll/sit9531x/core.c int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx, · line 1612
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+* After power loss the part is on page 0, not the cached page. The +* configuration read at probe is not read again. +*/ +sit9531x_page_cache_drop (sitdev); +if (sitdev->irq >0 ) +enable_irq (sitdev->irq); +kthread_queue_delayed_work (sitdev->kworker, &sitdev->work,0 ); + +return 0 ; +}
[Severity: Medium]
This comment assumes the part may have lost power. Probe waits for the internal boot:
fsleep(10000); /* internal boot after release */
Resume, though, enables the IRQ and queues the poll at delay 0 straight away. Can the first I2C transfers from the IRQ thread or the poll reach the part before it has finished booting?
After a power loss the part also reloads its EEPROM/efuse profile. Any configuration pushed over I2C before probe would be gone; sit9531x_eeprom_state_report() even detects that case. The driver still uses state cached at probe time by sit9531x_dev_state_fetch():
ref[].sig_mode selects the DE or SE registers in sit9531x_input_get_regs()
out[].cmos selects the Hi-Z pairs in sit9531x_output_forced_hiz()
the output routing, ref[].pll_mask, and chan[].manual_input, which sit9531x_dpll_mode_get() and sit9531x_dpll_supported_modes_get() return
Could resume then read the wrong register pairs and report wrong lock, pin and mode state, with no warning?
Later in the series, resume re-reads the INTSYNC owner, the output mutes and the delays. It still applies no boot delay, and it still does not re-read sig_mode, cmos, routing or manual_input. The output mute refresh also depends on the stale out[].cmos.
[ ... ]
Quoted 289 lines
drivers/dpll/sit9531x/dpll.c new file +285
-0@@ -0,0 +1,295 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* SiTime SiT9531x DPLL subsystem callbacks and registration +* +* Copyright (C) 2026 SiTime Corp. +* Author: Ali Rouhi <[email protected]> +* Author: Oleg Zadorozhnyi <[email protected]> +* +* DPLL device ops, pin ops (separate input/output), pin registration, +* and periodic change detection. +*/ + +#include <linux/dpll.h> +#include <linux/err.h> +#include <linux/kthread.h> +#include <linux/list.h> +#include <linux/netlink.h> +#include <linux/slab.h> + +#include "core.h" +#include "dpll.h" +#include "prop.h" +#include "regs.h" + +static bool sit9531x_dpll_is_input_pin (const struct sit9531x_dpll_pin *pin) +{ +return pin->dir ==DPLL_PIN_DIRECTION_INPUT ; +} + +static bool +sit9531x_dpll_is_xo_pin (const struct sit9531x_dpll_pin *pin) +{ +return sit9531x_dpll_is_input_pin (pin) && + pin->id ==SIT9531X_MAX_INPUTS ; +} + +/* +* Report the lock status from the last poll: outer LOL (page 0 reg 0x06), PLL +* mode (PLL page reg 0x31), inner LOL (reg 0x92), holdover freeze (reg 0x0A) +* and holdover-valid (PLL page reg 0x06). +*/ +static int +sit9531x_dpll_lock_status_get (const struct dpll_device *dpll,void *dpll_priv, +enum dpll_lock_status *status, +enum dpll_lock_status_error *status_error, +struct netlink_ext_ack *extack) +{ +struct sit9531x_dpll *sitdpll = dpll_priv; +struct sit9531x_dev *sitdev = sitdpll->dev; +const struct sit9531x_chan *chan; + +if (status_error) + *status_error =DPLL_LOCK_STATUS_ERROR_NONE ; + + chan =sit9531x_chan_state_get (sitdev, sitdpll->id); + +mutex_lock (&sitdev->multiop_lock); + +if (chan->stale) { + *status =DPLL_LOCK_STATUS_UNLOCKED ; +if (status_error) + *status_error =DPLL_LOCK_STATUS_ERROR_UNDEFINED ; + }else if (!chan->active) { +/* +* An unused PLL never goes active and its loss-of-lock bit is +* not driven. +*/ + *status =DPLL_LOCK_STATUS_UNLOCKED ; + }else if (chan->inner_lol) { +/* +* The core reports the error detail only with an unlocked or +* holdover status. +*/ + *status = chan->ho_freeze ?DPLL_LOCK_STATUS_HOLDOVER : +DPLL_LOCK_STATUS_UNLOCKED ; + }else if (chan->mode) { +/* +* In free-run the outer loop is disabled and its loss-of-lock +* bit is meaningless. +*/ + *status =DPLL_LOCK_STATUS_UNLOCKED ; + }else if (chan->ho_freeze) { +/* +* Test freeze before lock: a frozen PLL tracks no reference +* whatever its outer loss-of-lock bit reads. +*/ + *status =DPLL_LOCK_STATUS_HOLDOVER ; + }else if (chan->locked) { +if (chan->ho_valid) + *status =DPLL_LOCK_STATUS_LOCKED_HO_ACQ ; +else + *status =DPLL_LOCK_STATUS_LOCKED ; + }else { + *status =DPLL_LOCK_STATUS_UNLOCKED ; + } + +if (status_error && chan->inner_lol) + *status_error =DPLL_LOCK_STATUS_ERROR_UNDEFINED ; + +mutex_unlock (&sitdev->multiop_lock); + +return 0 ; +} + +/* +* Record the lock status the create notification carried as the poll baseline. +* Call once the device is registered. +*/ +void sit9531x_dpll_lock_status_baseline (struct sit9531x_dpll *sitdpll) +{ +sit9531x_dpll_lock_status_get (sitdpll->dpll_dev, sitdpll, + &sitdpll->lock_status, + &sitdpll->lock_status_error,NULL ); +} + +/* +* Report AUTOMATIC for a PLL on its priority table, also on manual active +* select, which uses the same nibble, and MANUAL on manual input select +* (MISCINNER_PLL bit 5), where the select pins or GPIO_INPUT_FUNC_CTRL5..8 +* choose the input. Free-run (PLL page reg 0x31[5]) shows in the lock status. +*/ +static int +sit9531x_dpll_mode_get (const struct dpll_device *dpll,void *dpll_priv, +enum dpll_mode *mode,struct netlink_ext_ack *extack) +{ +struct sit9531x_dpll *sitdpll = dpll_priv; + +/* Read once at probe, before the device is registered. */ +if (sit9531x_chan_state_get (sitdpll->dev, sitdpll->id)->manual_input) + *mode =DPLL_MODE_MANUAL ; +else + *mode =DPLL_MODE_AUTOMATIC ; + +return 0 ; +} + +static int +sit9531x_dpll_supported_modes_get (const struct dpll_device *dpll, +void *dpll_priv,unsigned long *modes, +struct netlink_ext_ack *extack) +{ +struct sit9531x_dpll *sitdpll = dpll_priv; + +if (sit9531x_chan_state_get (sitdpll->dev, sitdpll->id)->manual_input) +__set_bit (DPLL_MODE_MANUAL , modes); +else +__set_bit (DPLL_MODE_AUTOMATIC , modes); + +return 0 ; +} + +const struct dpll_device_ops sit9531x_dpll_device_ops = { + .lock_status_get = sit9531x_dpll_lock_status_get, + .mode_get = sit9531x_dpll_mode_get, + .supported_modes_get = sit9531x_dpll_supported_modes_get, +}; + +static int +sit9531x_dpll_input_pin_direction_get (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ + *direction =DPLL_PIN_DIRECTION_INPUT ; +return 0 ; +} + +static const struct dpll_pin_ops sit9531x_dpll_input_pin_ops = { + .direction_get = sit9531x_dpll_input_pin_direction_get, +}; + +/* +* INTSYNC is the inter-PLL sync line: one PLL drives it and other PLLs may lock +* to it. Each DPLL registers a source pin to drive the line and a destination +* pin to lock to it. +*/ + +static int +sit9531x_dpll_output_pin_direction_get (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack); + +/* The XO feeds every PLL and is always connected. */ + +static int +sit9531x_dpll_xo_pin_state_on_dpll_get (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack) +{ + *state =DPLL_PIN_STATE_CONNECTED ; +return 0 ; +} + +static const struct dpll_pin_ops sit9531x_dpll_xo_pin_ops = { + .direction_get = sit9531x_dpll_input_pin_direction_get, + .state_on_dpll_get = sit9531x_dpll_xo_pin_state_on_dpll_get, +}; + +static int +sit9531x_dpll_output_pin_direction_get (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_direction *direction, +struct netlink_ext_ack *extack) +{ + *direction =DPLL_PIN_DIRECTION_OUTPUT ; +return 0 ; +} + +static const struct dpll_pin_ops sit9531x_dpll_output_pin_ops = { + .direction_get = sit9531x_dpll_output_pin_direction_get, +}; + +const struct dpll_pin_ops * +sit9531x_dpll_pin_ops_get (const struct sit9531x_dpll_pin *pin) +{ +if (!sit9531x_dpll_is_input_pin (pin)) +return &sit9531x_dpll_output_pin_ops; +if (sit9531x_dpll_is_xo_pin (pin)) +return &sit9531x_dpll_xo_pin_ops; +return &sit9531x_dpll_input_pin_ops; +} + +/* +* Send notifications for changed lock status and pin state; called from +* sit9531x_dev_periodic_work(). +*/ +void sit9531x_dpll_changes_check (struct sit9531x_dpll *sitdpll) +{ +enum dpll_lock_status_error status_error =DPLL_LOCK_STATUS_ERROR_NONE ; +struct sit9531x_dev *sitdev = sitdpll->dev; +enum dpll_lock_status lock_status; +struct sit9531x_dpll_pin *pin; +int rc; + + rc =sit9531x_dpll_lock_status_get (sitdpll->dpll_dev, sitdpll, + &lock_status, &status_error,NULL ); +if (rc) { +dev_err (sitdev->dev,"Failed to get DPLL%u lock status: %d\n" , + sitdpll->id, rc); +return ; + } + +/* +* The core publishes the error detail with the status, so a change in +* either is notified. +*/ +if (sitdpll->lock_status != lock_status || + sitdpll->lock_status_error != status_error) { + sitdpll->lock_status = lock_status; + sitdpll->lock_status_error = status_error; + sitdpll->ntf_pending = true; + } + +if (sitdpll->ntf_pending && !dpll_device_change_ntf (sitdpll->dpll_dev)) + sitdpll->ntf_pending = false; + +list_for_each_entry (pin, &sitdpll->pins, list) { +const struct dpll_pin_ops *ops; +enum dpll_pin_state state; +bool changed; + +/* +* Only references and the INTSYNC destination change state +* without a request. +*/ +if (!sit9531x_dpll_is_input_pin (pin) || +sit9531x_dpll_is_xo_pin (pin)) +continue ; + + ops =sit9531x_dpll_pin_ops_get (pin); + rc = ops->state_on_dpll_get (pin->dpll_pin, pin, + sitdpll->dpll_dev, sitdpll, + &state,NULL ); +if (rc) +continue ;
drivers/dpll/sit9531x/dpll.c line 295
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c new file +10
-0+ + changed = pin->seen && state != pin->pin_state; + pin->pin_state = state; + pin->seen = true; +if (changed) { +dev_dbg (sitdev->dev,"%s state changed\n" , pin->label); +dpll_pin_change_ntf (pin->dpll_pin); + } + } +}
[Severity: Medium]
The !chan->active branch is ordered ahead of inner_lol so that an unused PLL reports a plain DPLL_LOCK_STATUS_UNLOCKED. Its comment says the loss-of-lock bit is not driven there.
This check runs after the whole chain, though. On an inactive PLL with its bit set in SIT9531X_REG_PLL_INNER_LOL_STATUS, status_error is still overwritten with DPLL_LOCK_STATUS_ERROR_UNDEFINED.
The DPLL core puts DPLL_A_LOCK_STATUS_ERROR in the message whenever the status is unlocked and the error is not NONE. Userspace would then be told that a PLL the loaded configuration does not use has an undefined lock error.
sit9531x_dpll_changes_check() also compares lock_status_error. Each time that bit toggles on an unused PLL, it sends a dpll_device_change_ntf() as well.
Every branch after the inner_lol one only runs with inner_lol clear, and the stale branch sets the error on its own. Could the assignment move into the inner_lol branch, so an inactive PLL keeps DPLL_LOCK_STATUS_ERROR_NONE? Or is the inner loss-of-lock bit meaningful on a PLL that never reached its active state?
This looks the same later in the series.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 7/13 dpll: sit9531x: implement input pin state on a DPLL
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Report and set whether an input takes part in a PLL's reference selection. The PLL picks its reference from a priority table: an input in the table is SELECTABLE, one absent is DISCONNECTED, and setting the state adds or removes it. The table is kept ordered by a priority per source, seeded from the table the part loaded; the next patch lets userspace change it. CONNECTED is refused, as the driver does not program manual input select.
A table write uses the documented procedure: force holdover, write the slots, latch with a small update, release. The pin reported active is the one the part feeds the PLL while the PLL tracks it and the lane has signal.
A PLL in holdover after losing its reference is re-selected when a listed source returns.
--- drivers/dpll/sit9531x/core.c | 1071 ++++++++++++++++++++++++++++++++-- drivers/dpll/sit9531x/core.h | 65 ++- drivers/dpll/sit9531x/dpll.c | 257 +++++++- drivers/dpll/sit9531x/regs.h | 38 ++ 4 files changed, 1381 insertions(+), 50 deletions(-)
drivers/dpll/sit9531x/core.c +1030 -41
@@ -61,10 +61,21 @@ static const struct sit9531x_chip_info sit9531x_chip_ids[] = {* One 256-register page is visible at a time, selected by offset 0xFF on every * page. The map covers that window, uncached; the accessors select the page. */ +/* +* Each read of the debug status data register advances the status bus latch; +* marking it precious stops a debugfs dump from reading it. +*/ +static bool sit9531x_precious_reg (struct device *dev__maybe_unused , +unsigned int reg) +{ +return reg ==SIT9531X_PLL_REG_DBG_STATUS_DATA ; +} +static const struct regmap_config sit9531x_regmap_config = { .reg_bits =8 , .val_bits =8 , .max_register =SIT9531X_PAGE_SEL , + .precious_reg = sit9531x_precious_reg, .cache_type =REGCACHE_NONE , };
@@ -206,6 +217,34 @@ int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,return rc; } +#define SIT9531X_CLOSE_TRIES 3 + +/* Write a register, retrying on failure */ +static int sit9531x_write_close (struct sit9531x_dev *sitdev,unsigned int reg, +u8 val) +{ +u8 attempt; +int rc; + +for (attempt =0 ; attempt <SIT9531X_CLOSE_TRIES ; attempt++) { +if (attempt) +usleep_range (1000 ,2000 ); + rc =sit9531x_write_u8 (sitdev, reg, val); +if (!rc) +break ; + } + +return rc; +} + +static int sit9531x_write_pll_close (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 offset,u8 val) +{ +return sit9531x_write_close (sitdev, +SIT9531X_REG (sit9531x_pll_page (pll_idx), + offset), val); +} + static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev, u8 index, unsigned int *force_reg,
@@ -223,6 +262,72 @@ static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev, } } +/* Caller must hold sitdev->multiop_lock. */ +int sit9531x_input_disable (struct sit9531x_dev *sitdev,u8 index) +{ +unsigned int force_reg, state_reg; +struct sit9531x_ref *ref; +u8 pair, val; +int rc, ret; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (index >=SIT9531X_MAX_INPUTS ) +return -EINVAL ; + + ref = &sitdev->ref[index]; + pair =sit9531x_input_pair (index); +sit9531x_input_get_regs (sitdev, index, &force_reg, &state_reg); + + rc =sit9531x_read_u8 (sitdev, force_reg, &val); +if (!rc) + rc =sit9531x_write_u8 (sitdev, force_reg, val |BIT (pair)); + + ret =sit9531x_read_u8 (sitdev, state_reg, &val); +if (!ret) + ret =sit9531x_write_u8 (sitdev, state_reg, val & ~BIT (pair)); +if (ret && !rc) + rc = ret; + + ref->enabled = false; + ref->off_pending = rc !=0 ; + +return rc; +} + +/* +* Release the force so the lane uses the loaded configuration. Caller must hold +* sitdev->multiop_lock. +*/ +int sit9531x_input_enable (struct sit9531x_dev *sitdev,u8 index) +{ +unsigned int force_reg, state_reg; +struct sit9531x_ref *ref; +u8 pair, val; +int rc; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (index >=SIT9531X_MAX_INPUTS ) +return -EINVAL ; + + ref = &sitdev->ref[index]; + pair =sit9531x_input_pair (index); +sit9531x_input_get_regs (sitdev, index, &force_reg, &state_reg); + + rc =sit9531x_read_u8 (sitdev, force_reg, &val); +if (rc) +return rc; + rc =sit9531x_write_u8 (sitdev, force_reg, val & ~BIT (pair)); +if (rc) +return rc; + + ref->enabled = true; + ref->off_pending = false; + +return 0 ; +} +/* * Output Hi-Z control: each slot has three force/state pairs on Page 0x03, * for the differential path and the CMOS OutP and OutN pads. The tri-state
@@ -360,7 +465,7 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,* 1. Force PLL into holdover (PLL page reg 0x6F bit 4) * 2. Write priority slots on Page 1 * 3. Small change update (Page 0 reg 0x0F bit 1) -* 4. Release holdover +* 4. Release holdover, unless something other than this driver forced it * * Caller must hold sitdev->multiop_lock. */
@@ -382,20 +487,462 @@ static u8 sit9531x_prio_slot_get(u8 val, u8 slot)return val >>SIT9531X_PRIO_HI_SHIFT ; } +static u8 sit9531x_prio_slot_set (u8 val,u8 slot,u8 src) +{ +if (slot &1 ) +return (val & (SIT9531X_PRIO_NIBBLE_MASK << +SIT9531X_PRIO_HI_SHIFT )) | + (src &SIT9531X_PRIO_NIBBLE_MASK ); + +return (val &SIT9531X_PRIO_NIBBLE_MASK ) | + ((src &SIT9531X_PRIO_NIBBLE_MASK ) << +SIT9531X_PRIO_HI_SHIFT ); +} + +/* +* Latch a priority table with a small change update, as in the documented +* input_priority_sel() procedure. +*/ +static int sit9531x_prio_prg_commit (struct sit9531x_dev *sitdev) +{ +int rc; + + rc =sit9531x_write_close (sitdev,SIT9531X_REG_GLOBAL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +if (rc) +return rc; + +usleep_range (1000 ,2000 ); + +return 0 ; +} + +/* +* Four registers carry a nibble per lane: loss of signal and the fine and +* coarse frequency-drift flags. Caller must hold sitdev->multiop_lock, or run +* before registration. +*/ +static int sit9531x_input_mon_fetch (struct sit9531x_dev *sitdev) +{ +static const unsigned int regs[] = { +SIT9531X_CLKMON_P_STATUS_01 ,SIT9531X_CLKMON_P_STATUS_23 , +SIT9531X_CLKMON_N_STATUS_01 ,SIT9531X_CLKMON_N_STATUS_23 , + }; +u8 val[ARRAY_SIZE (regs)], i, pair, nib; +int rc; + +for (i =0 ; i <ARRAY_SIZE (regs); i++) { + rc =sit9531x_read_u8 (sitdev, regs[i], &val[i]); +if (rc) +return rc; + } + +for (i =0 ; i < sitdev->info->num_inputs && i <SIT9531X_MAX_INPUTS ; + i++) { +struct sit9531x_ref *ref = &sitdev->ref[i]; + +/* Lane 2k is INkP, 2k + 1 INkN; a register holds two pairs. */ + pair =sit9531x_input_pair (i); + nib = val[(sit9531x_input_is_n (i) ?2 :0 ) + pair /2 ]; + nib = (pair &1 ) ? nib >>4 : nib &0x0F ; + + ref->los = !!(nib &SIT9531X_CLKMON_LOSS ); + ref->qual_fail = !ref->los && + !!(nib & (SIT9531X_CLKMON_FINE_DRIFT | +SIT9531X_CLKMON_COARSE_DRIFT )); + } + +return 0 ; +} + +/* +* Check if the device can lock to @src now; a differential pair is watched +* through its P lane. +*/ +static bool sit9531x_prio_src_live (const struct sit9531x_dev *sitdev,u8 src) +{ +u8 index =sit9531x_hw_src_input (src); + +if (index >= sitdev->info->num_inputs) +return true; + +return !sitdev->ref[index].los; +} + +/* +* Map an N-lane source of a differential pair to its P lane, the lane its DPLL +* pin represents. +*/ +static u8 sit9531x_prio_src_canon (const struct sit9531x_dev *sitdev,u8 src) +{ +u8 index =sit9531x_hw_src_input (src); + +if (index >= sitdev->info->num_inputs) +return src; + +if (sit9531x_input_is_n (index) && + sitdev->ref[index].sig_mode ==SIT9531X_MODE_DE ) +return sit9531x_input_hw_src (index -1 ); + +return src; +} + +/* +* @input_idx is in hardware encoding (see sit9531x_input_hw_src()). Caller must +* hold sitdev->multiop_lock. +*/ +bool sit9531x_input_prio_present (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx) +{ +lockdep_assert_held (&sitdev->multiop_lock); + +if (pll_idx >=SIT9531X_NUM_PLLS ) +return false; + + input_idx =sit9531x_prio_src_canon (sitdev, input_idx); +if (input_idx >=SIT9531X_PRIO_NUM_SRC ) +return false; + +return !!(sitdev->chan[pll_idx].prio_mask &BIT (input_idx)); +} + +/* +* Take the configured priorities from the hardware table: a listed source gets +* the first slot it occupies. +*/ +static void sit9531x_prio_cfg_seed (struct sit9531x_dev *sitdev,u8 pll_idx, +const u8 *srcs) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +u16 seeded =0 ; +u8 slot, src; + +for (slot =0 ; slot <SIT9531X_PRIO_MAX_SLOTS ; slot++) { + src = srcs[slot] &SIT9531X_PRIO_NIBBLE_MASK ; +if (!sit9531x_prio_src_usable (src)) +continue ; + src =sit9531x_prio_src_canon (sitdev, src); +if (seeded &BIT (src)) +continue ; + seeded |=BIT (src); + chan->cfg_prio[src] = slot; + chan->cfg_known |=BIT (src); + } + +for (src =0 ; src <SIT9531X_PRIO_NUM_SRC ; src++) { +if (chan->cfg_known &BIT (src)) +continue ; + chan->cfg_prio[src] =SIT9531X_PRIO_MAX_SLOTS -1 ; + chan->cfg_known |=BIT (src); + } + +memcpy (chan->seen_srcs, srcs,sizeof (chan->seen_srcs)); + chan->seen_valid = true; +} + +/* Order the members by configured priority */ +static void sit9531x_prio_table_build (struct sit9531x_dev *sitdev,u8 pll_idx, +u16 members,u8 *srcs) +{ +const struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +u8 order[SIT9531X_PRIO_NUM_SRC ], n =0 , i, j, src; + +for (src =0 ; src <SIT9531X_PRIO_NUM_SRC ; src++) +if (members &BIT (src)) + order[n++] = src; + +for (i =1 ; i < n; i++) { +u8 cur = order[i]; + +for (j = i; j >0 ; j--) { +u8 prev = order[j -1 ]; +u16 kc, kp; + + kc = (chan->cfg_known &BIT (cur)) ? + chan->cfg_prio[cur] :U8_MAX ; + kp = (chan->cfg_known &BIT (prev)) ? + chan->cfg_prio[prev] :U8_MAX ; +if (kc == kp) { +/* Keep the hardware order among equals. */ + kc = chan->prio_last[cur] ?:U8_MAX ; + kp = chan->prio_last[prev] ?:U8_MAX ; + } +if (kp <= kc) +break ; + order[j] = prev; + } + order[j] = cur; + } + +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) + srcs[i] = i < n ? order[i] :SIT9531X_PRIO_SRC_NONE ; +} + +/* +* Refresh the cached membership mask, per-slot copy and first-slot array of a +* PLL's priority table. +*/ static void sit9531x_prio_mask_build (struct sit9531x_dev *sitdev,u8 pll_idx,const u8 *srcs) { +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +u8 first[SIT9531X_PRIO_NUM_SRC ] = {0 }; +u8 slot, src, src_canon;u16 mask =0 ; -u8 slot;for (slot =0 ; slot <SIT9531X_PRIO_MAX_SLOTS ; slot++) { -u8 src = srcs[slot] &SIT9531X_PRIO_NIBBLE_MASK ; + src = srcs[slot]; + src &=SIT9531X_PRIO_NIBBLE_MASK ; + chan->prio_srcs[slot] = src; + src_canon =sit9531x_prio_src_canon (sitdev, src); +if (!sit9531x_prio_src_usable (src)) +continue ; + + mask |=BIT (src_canon); +if (!first[src_canon]) + first[src_canon] = slot +1 ; + } + +for (src =0 ; src <SIT9531X_PRIO_NUM_SRC ; src++) + chan->prio_last[src] = first[src]; + + chan->prio_mask = mask; +} + +#define SIT9531X_HO_CLEAR_TRIES 3 + +static int sit9531x_prio_table_read (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 *srcs); +static int sit9531x_chan_state_fetch (struct sit9531x_dev *sitdev,u8 pll_idx); + +static u8 sit9531x_prio_top_live (const struct sit9531x_dev *sitdev, +const u8 *srcs) +{ +u8 i, src; + +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) { + src = srcs[i] &SIT9531X_PRIO_NIBBLE_MASK ; + src =sit9531x_prio_src_canon (sitdev, src); +if (sit9531x_prio_src_usable (src) && +sit9531x_prio_src_live (sitdev, src)) +return src; + } + +return SIT9531X_PRIO_SRC_NONE ; +} + +/* +* Pick the active selection to latch; after a latch the PLL uses that source +* until it loses signal. +*/ +static u8 sit9531x_prio_activesel_pick (struct sit9531x_dev *sitdev, +const u8 *old,const u8 *srcs,u8 cur) +{ +u8 top, i; + + top =sit9531x_prio_top_live (sitdev, srcs); +if (top !=SIT9531X_PRIO_SRC_NONE && + top !=sit9531x_prio_top_live (sitdev, old)) +return top; + + cur =sit9531x_prio_src_canon (sitdev, cur &SIT9531X_PRIO_NIBBLE_MASK ); + +if (sit9531x_prio_src_usable (cur) && +sit9531x_prio_src_live (sitdev, cur)) +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (srcs[i] == cur) +return cur; + +if (top !=SIT9531X_PRIO_SRC_NONE ) +return top; + +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (sit9531x_prio_src_usable (srcs[i])) +return srcs[i]; + +return srcs[0 ]; +} -if (sit9531x_prio_src_usable (src)) - mask |=BIT (src); +static int sit9531x_prio_table_commit (struct sit9531x_dev *sitdev,u8 pll_idx, +const u8 *srcs) +{ +u8 val, last_old, slot, attempt, written =0 , restored =0 ; +u8 now[SIT9531X_PRIO_MAX_SLOTS ], back[SIT9531X_PRIO_MAX_SLOTS ]; +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +int rc =0 , prg_rc, ho_rc =0 ; +bool empty, ho_foreign, pending = false; +bool pending_before = chan->table_pending; +u16 reg; + + empty = true; +for (slot =0 ; slot <SIT9531X_PRIO_MAX_SLOTS ; slot++) +if (sit9531x_prio_src_usable (srcs[slot])) + empty = false; + +memcpy (back, chan->table_pending ? chan->table_back : chan->prio_srcs, +sizeof (back)); + +/* +* Treat a forced holdover as set by this driver only when the table is +* empty or a release is pending; leave any other in place. +*/ + rc =sit9531x_read_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_HO_CTRL , + &val); +if (rc) +return rc; + + ho_foreign = (val &BIT (SIT9531X_PLL_HO_FORCE_BIT )) && + chan->prio_mask && !chan->ho_release_pending; + + rc =sit9531x_write_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_HO_CTRL , + val |BIT (SIT9531X_PLL_HO_FORCE_BIT )); +if (rc) + goto release; + +usleep_range (10000 ,12000 ); + +for (slot =0 ; slot +1 <SIT9531X_PRIO_MAX_SLOTS ; slot +=2 ) { + reg =sit9531x_prio_reg (pll_idx, slot); + + val =sit9531x_prio_slot_set (0 , slot, srcs[slot]); + val =sit9531x_prio_slot_set (val, slot +1 , srcs[slot +1 ]); + + written = slot +2 ; + rc =sit9531x_write_u8 (sitdev, reg, val); +if (rc) + goto rollback; } - sitdev->chan[pll_idx].prio_mask = mask; +/* +* The last register holds slot 10 in [7:4] and the device's active +* selection in [3:0], addressed as the slot past the last. +*/ + reg =sit9531x_prio_reg (pll_idx, slot); + + rc =sit9531x_read_u8 (sitdev, reg, &last_old); +if (rc) + goto rollback; + + val =sit9531x_prio_slot_set (last_old, slot, srcs[slot]); + +if (!empty) { +u8 sel =sit9531x_prio_slot_get (val, slot +1 ); + + rc =sit9531x_input_mon_fetch (sitdev); +if (rc) + goto rollback; + sel =sit9531x_prio_activesel_pick (sitdev, chan->prio_srcs, + srcs, sel); + val =sit9531x_prio_slot_set (val, slot +1 , sel); + } + + written =SIT9531X_PRIO_MAX_SLOTS ; + rc =sit9531x_write_u8 (sitdev, reg, val); +if (rc) + goto rollback; + +rollback: +if (rc && written) { +for (slot =0 ; slot < written; slot +=2 ) { +const u8 *prev = &chan->prio_srcs[slot]; +u8 old; + +if (slot +1 <SIT9531X_PRIO_MAX_SLOTS ) { + old =sit9531x_prio_slot_set (0 , slot, prev[0 ]); + old =sit9531x_prio_slot_set (old, slot +1 , + prev[1 ]); + }else { + old = last_old; + } +if (sit9531x_write_u8 (sitdev, +sit9531x_prio_reg (pll_idx, slot), + old)) +break ; + + restored = slot +2 ; + } + pending = restored < written; + written = restored; + } + +/* +* Latch unconditionally: the PLL uses the register contents only after +* a latch. +*/ + prg_rc =sit9531x_prio_prg_commit (sitdev); +if (prg_rc && !rc) { + pending = true; + rc = prg_rc; + } + +if (!rc) { +sit9531x_prio_mask_build (sitdev, pll_idx, srcs); +/* Re-select compares against this table's best live source */ + chan->live_top =sit9531x_prio_top_live (sitdev, srcs); +memcpy (chan->seen_srcs, srcs,sizeof (chan->seen_srcs)); + chan->seen_valid = true; + chan->table_pending = false; + }else if (pending || pending_before) { +sit9531x_prio_mask_build (sitdev, pll_idx, back); +memcpy (chan->table_back, back,sizeof (chan->table_back)); + chan->table_pending = true; + }else if (!sit9531x_prio_table_read (sitdev, pll_idx, now)) { +sit9531x_prio_mask_build (sitdev, pll_idx, now); +memcpy (chan->seen_srcs, now,sizeof (chan->seen_srcs)); + chan->seen_valid = true; + } + +release: +/* +* An empty table keeps the forced holdover; the PLL uses the source in +* the selection nibble, which still names the old one. +*/ +if (!chan->prio_mask) { +dev_dbg (sitdev->dev, +"PLL%c: no source listed, holdover kept\n" , +'A' + pll_idx); + chan->ho_release_pending = false; + goto out; + } + +if (ho_foreign) { +dev_dbg (sitdev->dev, +"PLL%c: holdover was forced before the write, left in place\n" , +'A' + pll_idx); + goto out; + } + +if (chan->table_pending) { +dev_dbg (sitdev->dev, +"PLL%c: priority table restore pending, holdover kept\n" , +'A' + pll_idx); + chan->ho_release_pending = true; + goto out; + } + +for (attempt =0 ; attempt <SIT9531X_HO_CLEAR_TRIES ; attempt++) { + ho_rc =sit9531x_update_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_HO_CTRL , +BIT (SIT9531X_PLL_HO_FORCE_BIT ), +0 ); +if (!ho_rc) +break ; +usleep_range (1000 ,2000 ); + } +if (ho_rc) { +dev_err (sitdev->dev,"PLL%c left in forced holdover: %d\n" , +'A' + pll_idx, ho_rc); +if (!rc) + rc = ho_rc; + } + chan->ho_release_pending = !!ho_rc; + +out: +/* The core reads the pin getters as soon as the setter returns. */ +if (sit9531x_chan_state_fetch (sitdev, pll_idx)) + chan->stale = true; + +return rc; }/* Caller must hold sitdev->multiop_lock. */
@@ -417,6 +964,75 @@ static int sit9531x_prio_table_read(struct sit9531x_dev *sitdev, u8 pll_idx,return 0 ; } +/* +* Rewrite a PLL's table for a new member set; skip an unchanged table, since +* each write forces holdover. +*/ +static int sit9531x_prio_table_apply (struct sit9531x_dev *sitdev,u8 pll_idx, +u16 members) +{ +u8 srcs[SIT9531X_PRIO_MAX_SLOTS ]; + +if (hweight16 (members) >SIT9531X_PRIO_MAX_SLOTS ) +return -ENOSPC ; + +sit9531x_prio_table_build (sitdev, pll_idx, members, srcs); +if (!memcmp (srcs, sitdev->chan[pll_idx].prio_srcs,sizeof (srcs))) +return 0 ; + +return sit9531x_prio_table_commit (sitdev, pll_idx, srcs); +} + +/* +* Removing the last source leaves an empty table, which keeps the PLL in +* holdover. Caller must hold sitdev->multiop_lock. +*/ +int sit9531x_input_prio_remove (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx) +{ +struct sit9531x_chan *chan; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + input_idx =sit9531x_prio_src_canon (sitdev, input_idx); +if (input_idx >=SIT9531X_PRIO_NUM_SRC ) +return -EINVAL ; + + chan = &sitdev->chan[pll_idx]; +if (!(chan->prio_mask &BIT (input_idx))) +return 0 ; + +return sit9531x_prio_table_apply (sitdev, pll_idx, + chan->prio_mask & ~BIT (input_idx)); +} + +/* +* A source the PLL never listed gets the priority of the last slot. Caller must +* hold sitdev->multiop_lock. +*/ +int sit9531x_input_prio_add (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx) +{ +struct sit9531x_chan *chan; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + input_idx =sit9531x_prio_src_canon (sitdev, input_idx); +if (input_idx >=SIT9531X_PRIO_NUM_SRC ) +return -EINVAL ; + + chan = &sitdev->chan[pll_idx]; +if (chan->prio_mask &BIT (input_idx)) +return 0 ; + +return sit9531x_prio_table_apply (sitdev, pll_idx, + chan->prio_mask |BIT (input_idx)); +} +/* XO doubler register */ #define SIT9531X_REG_XO2_GENERIC SIT9531X_REG(0x00, 0x2D)#define SIT9531X_XO_DOUBLER_ENB_BIT 7/* inverted: 0 = enabled */
@@ -578,6 +1194,7 @@ static int sit9531x_chan_select_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)if (rc)return rc; chan->manual_input = false; + chan->manual_ref =SIT9531X_REF_INVALID ;if (!(cfg &SIT9531X_PLL_CONFIG1F_MANUAL_SEL ))return 0 ;
@@ -598,6 +1215,9 @@ static int sit9531x_chan_select_fetch(struct sit9531x_dev *sitdev, u8 pll_idx) chan->manual_input = true;if (sel &SIT9531X_MAN_IN_SEL_FROM_REG ) { sel =FIELD_GET (SIT9531X_MAN_IN_SEL_MASK , sel); + chan->manual_ref = +sit9531x_hw_src_input (sit9531x_prio_src_canon (sitdev, + sel));dev_info (sitdev->dev,"PLL%c: the profile selects its reference from the register, input code %u; reported as manual\n" ,'A' + pll_idx, sel);
@@ -610,17 +1230,65 @@ static int sit9531x_chan_select_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)return 0 ; } +/* +* Read the reference the device feeds a PLL from the debug status bus; the +* active selection does not change on a fallback. The caller rules out free-run +* first and must hold sitdev->multiop_lock. +*/ +static int sit9531x_chan_routed_ref_read (struct sit9531x_dev *sitdev, +u8 pll_idx,u8 *ref) +{ +int rc, lock_rc; +u8 v, i; + +lockdep_assert_held (&sitdev->multiop_lock); + + rc =sit9531x_write_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_DEBUG , +SIT9531X_PLL_DEBUG_UNLOCK ); +if (rc) + goto relock; + + rc =sit9531x_write_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_STATUS_ADDR , +SIT9531X_DBG_STATUS_ROUTED_SRC ); +if (rc) + goto relock; + +/* The first reads return earlier latches; the last is current. */ +for (i =0 ; i <SIT9531X_DBG_STATUS_READS ; i++) { + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_STATUS_DATA , + &v); +if (rc) + goto relock; + } + +/* +* Canonicalize like the table entries: a differential pair fed through +* its N-lane code is the P-lane pin. +*/ + v =sit9531x_prio_src_canon (sitdev, v &SIT9531X_DBG_ROUTED_SRC_MASK ); + *ref =sit9531x_hw_src_input (v); + +relock: + lock_rc =sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_DEBUG , +SIT9531X_PLL_DEBUG_LOCK ); + +return rc ? rc : lock_rc; +} +/* * Read the PLL's run, lock and holdover state, mode, selection and priority * table. */ static int sit9531x_chan_state_fetch (struct sit9531x_dev *sitdev,u8 pll_idx) { -u8 status, outer_lol, input_sel, inner_lol, ho_freeze, activesel_reg; +u8 status, outer_lol, inner_lol, ho_freeze, pll_status_1;struct sit9531x_chan *chan = &sitdev->chan[pll_idx];u8 srcs[SIT9531X_PRIO_MAX_SLOTS ]; -u8 pll_status_1; -bool active; +u8 routed =SIT9531X_REF_INVALID ; +bool active, tracking;int rc;/*
@@ -641,21 +1309,6 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)if (rc)return rc; -/* -* The active selection is CLK_ACTIVESEL_PLL, the low nibble of the last -* register of the PLL's Page 1 priority block. PLL-page 0x29 is a -* config register. -*/ - activesel_reg =SIT9531X_PRIO_BASE_REG + -SIT9531X_PRIO_REGS_PER_PLL * pll_idx + -SIT9531X_PRIO_ACTIVESEL_OFF ; - rc =sit9531x_read_u8 (sitdev, -SIT9531X_REG (SIT9531X_PAGE_PRIOSYS , - activesel_reg), - &input_sel); -if (rc) -return rc; - rc =sit9531x_read_u8 (sitdev,SIT9531X_REG_PLL_INNER_LOL_STATUS , &inner_lol);if (rc)
@@ -666,23 +1319,48 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)if (rc)return rc; +/* +* Read the routed reference only while the PLL tracks one; in free-run +* it has none. +*/ + tracking = active && !(outer_lol &BIT (pll_idx)) && + !(status &SIT9531X_PLL_STATUS_OUTER_DIS ) && + !(ho_freeze &BIT (pll_idx)); +if (tracking) { + rc =sit9531x_chan_routed_ref_read (sitdev, pll_idx, &routed); +if (rc) +return rc; + } + rc =sit9531x_read_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_STATUS_1 , &pll_status_1);if (rc)return rc; - rc =sit9531x_prio_table_read (sitdev, pll_idx, srcs); -if (rc) -return rc; +/* Keep the cached table while its write-back is pending */ +if (!chan->table_pending) { + rc =sit9531x_prio_table_read (sitdev, pll_idx, srcs); +if (rc) +return rc; + +sit9531x_prio_mask_build (sitdev, pll_idx, srcs); -sit9531x_prio_mask_build (sitdev, pll_idx, srcs); +/* +* A table that differs from the last one written was changed +* outside the driver; take it as the configuration. +*/ +if (!chan->seen_valid || +memcmp (srcs, chan->seen_srcs,sizeof (chan->seen_srcs))) +sit9531x_prio_cfg_seed (sitdev, pll_idx, srcs); + }/* STATUS_1_GENERIC reports loss of lock, so invert it. */ chan->active = active; chan->locked = active && !(outer_lol &BIT (pll_idx)); chan->mode = !!(status &SIT9531X_PLL_STATUS_OUTER_DIS ); - chan->selected_ref = -sit9531x_hw_src_input (input_sel &SIT9531X_PRIO_NIBBLE_MASK ); + chan->routed_ref = routed; +if (chan->manual_input && routed !=SIT9531X_REF_INVALID ) + chan->manual_ref = routed; chan->inner_lol = !!(inner_lol &BIT (pll_idx)); chan->ho_freeze = !!(ho_freeze &BIT (pll_idx)); chan->ho_valid = !!(pll_status_1 &SIT9531X_PLL_STATUS_1_HO_VALID );
@@ -793,11 +1471,39 @@ static int sit9531x_ref_pll_mask_fetch(struct sit9531x_dev *sitdev)return 0 ; } +/* +* Mark the input each manual-select PLL uses; its table need not list it. +* Caller must hold sitdev->multiop_lock. +*/ +static void sit9531x_manual_claims_add (struct sit9531x_dev *sitdev) +{ +const struct sit9531x_chan *chan; +u8 pll_idx; + +for (pll_idx =0 ; pll_idx <SIT9531X_NUM_PLLS ; pll_idx++) { + chan = &sitdev->chan[pll_idx]; +if (chan->manual_input && + chan->manual_ref < sitdev->info->num_inputs) + sitdev->ref[chan->manual_ref].pll_mask |=BIT (pll_idx); + } +} + +/* Arm the one-shot re-select of every PLL; see sit9531x_reselect(). */ +static void sit9531x_reselect_arm (struct sit9531x_dev *sitdev) +{ +u8 i; + +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) + sitdev->chan[i].reselect_armed = true; +} +static int sit9531x_dev_state_fetch (struct sit9531x_dev *sitdev) {int rc;u8 i; +sit9531x_reselect_arm (sitdev); +/* Detect SE/DE configuration before any per-lane access */ for (i =0 ; i < sitdev->info->num_inputs /2 ; i++) { rc =sit9531x_input_mode_fetch (sitdev, i);
@@ -817,6 +1523,13 @@ static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev) } } + rc =sit9531x_input_mon_fetch (sitdev); +if (rc) { +dev_err (sitdev->dev, +"Failed to read the input clock monitors: %d\n" , rc); +return rc; + } +mutex_lock (&sitdev->multiop_lock); rc =sit9531x_ref_pll_mask_fetch (sitdev);mutex_unlock (&sitdev->multiop_lock);
@@ -852,34 +1565,211 @@ static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev)return rc; } +/* Needs the select registers and samples read above */ +mutex_lock (&sitdev->multiop_lock); +sit9531x_manual_claims_add (sitdev); +mutex_unlock (&sitdev->multiop_lock); +return 0 ; } -static void sit9531x_dev_ref_states_update (struct sit9531x_dev *sitdev) +/* +* Read each receiver's enable and every lane's clock monitor; return true if +* any read succeeds. +*/ +static bool +sit9531x_dev_ref_states_update (struct sit9531x_dev *sitdev) { +bool answered = false;int i, rc;for (i =0 ; i < sitdev->info->num_inputs; i++) { rc =sit9531x_ref_state_fetch (sitdev, i);if (rc) -dev_warn (sitdev->dev, -"Failed to get REF%u status: %d\n" , i, rc); +dev_warn_ratelimited (sitdev->dev, +"Failed to get REF%u status: %d\n" , + i, rc); +else + answered = true; + } + + rc =sit9531x_input_mon_fetch (sitdev); +if (rc) +dev_warn_ratelimited (sitdev->dev, +"Failed to read the input clock monitors: %d\n" , + rc); +else + answered = true; + +return answered; +} + +/* +* Retry turning off a receiver unless a PLL has claimed the input since. Caller +* must hold sitdev->multiop_lock. +*/ +static void sit9531x_input_off_retry (struct sit9531x_dev *sitdev) +{ +u8 i; + +for (i =0 ; i < sitdev->info->num_inputs; i++) { +struct sit9531x_ref *ref = &sitdev->ref[i]; + +if (!ref->off_pending) +continue ; +if (ref->pll_mask) + ref->off_pending = false; +else +sit9531x_input_disable (sitdev, i); + } +} + +/* +* Rebuild pll_mask from the cached priority tables and the manual-select +* inputs. Caller must hold sitdev->multiop_lock. +*/ +static void sit9531x_ref_pll_mask_rebuild (struct sit9531x_dev *sitdev) +{ +u8 pll_idx, src, index; + +for (index =0 ; index < sitdev->info->num_inputs; index++) + sitdev->ref[index].pll_mask =0 ; + +for (pll_idx =0 ; pll_idx <SIT9531X_NUM_PLLS ; pll_idx++) { +u16 mask = sitdev->chan[pll_idx].prio_mask; + +for (src =0 ; src <SIT9531X_PRIO_NUM_SRC ; src++) { +if (!(mask &BIT (src))) +continue ; + + index =sit9531x_hw_src_input (src); +if (index < sitdev->info->num_inputs) + sitdev->ref[index].pll_mask |=BIT (pll_idx); + } + } + +sit9531x_manual_claims_add (sitdev); +} + +/* +* Retry a pending forced-holdover release; a pending table write-back releases +* it instead. Caller must hold sitdev->multiop_lock. +*/ +static void sit9531x_ho_release_retry (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; + +if (!chan->ho_release_pending || chan->table_pending) +return ; + +if (sit9531x_update_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_HO_CTRL , +BIT (SIT9531X_PLL_HO_FORCE_BIT ),0 )) +return ; + + chan->ho_release_pending = false; +dev_info (sitdev->dev,"PLL%c: forced holdover released\n" , +'A' + pll_idx); +} + +/* +* Write back the priority table after a failed write. Caller must hold +* sitdev->multiop_lock. +*/ +static void sit9531x_table_back_retry (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +u8 back[SIT9531X_PRIO_MAX_SLOTS ]; + +if (!sitdev->chan[pll_idx].table_pending) +return ; + +memcpy (back, sitdev->chan[pll_idx].table_back,sizeof (back)); +if (sit9531x_prio_table_commit (sitdev, pll_idx, back)) +return ; + +dev_info (sitdev->dev,"PLL%c: priority table written back\n" , +'A' + pll_idx); +} + +/* +* Rewrite the priority table when a listed source returns to a PLL without a +* reference; the write latches the active selection again. Each latch restarts +* acquisition, so the table is written once per change of the best live source. +* Caller must hold sitdev->multiop_lock. +*/ +static void sit9531x_reselect (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +u8 top; +int rc; + +/* A PLL on manual input select uses no priority table */ +if (chan->manual_input || !chan->prio_mask || chan->mode || + chan->ho_release_pending || chan->table_pending) +return ; + + top =sit9531x_prio_top_live (sitdev, chan->prio_srcs); +if (chan->reselect_armed) { +if (top ==SIT9531X_PRIO_SRC_NONE || !chan->ho_freeze) { + chan->reselect_armed = false; + chan->live_top = top; +return ; + } + }else { +if (top == chan->live_top) +return ; +/* +* Tracking is locked and not frozen; the two bits are read +* independently. +*/ +if (top ==SIT9531X_PRIO_SRC_NONE || + (chan->locked && !chan->ho_freeze)) { + chan->live_top = top; +return ; + } + } + + rc =sit9531x_prio_table_commit (sitdev, pll_idx, chan->prio_srcs); +if (rc) { +dev_warn_ratelimited (sitdev->dev, +"PLL%c: failed to re-select a returned source: %d\n" , +'A' + pll_idx, rc); +return ; } + + chan->reselect_armed = false; +dev_info (sitdev->dev,"PLL%c: re-selecting, a source is back\n" , +'A' + pll_idx); } -static void sit9531x_dev_chan_states_update (struct sit9531x_dev *sitdev) +/* +* Retry pending writes, then read each PLL's state; return true if any state +* read succeeds. +*/ +static bool +sit9531x_dev_chan_states_update (struct sit9531x_dev *sitdev) { +bool answered = false;int i, rc; +sit9531x_input_off_retry (sitdev);for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +sit9531x_table_back_retry (sitdev, i); +sit9531x_ho_release_retry (sitdev, i); rc =sit9531x_chan_state_fetch (sitdev, i);if (rc) { sitdev->chan[i].stale = true; -dev_warn (sitdev->dev, -"Failed to get PLL%c state: %d\n" , -'A' + i, rc); +dev_warn_ratelimited (sitdev->dev, +"Failed to get PLL%c state: %d\n" , +'A' + i, rc); +continue ; } + answered = true; +sit9531x_reselect (sitdev, i); } + +sit9531x_ref_pll_mask_rebuild (sitdev); + +return answered; }static void sit9531x_dev_periodic_work (struct kthread_work *work)
@@ -887,6 +1777,7 @@ static void sit9531x_dev_periodic_work(struct kthread_work *work) struct sit9531x_dev *sitdev = container_of(work, struct sit9531x_dev, work.work);struct sit9531x_dpll *sitdpll; +bool answered;int rc;/*
@@ -894,8 +1785,8 @@ static void sit9531x_dev_periodic_work(struct kthread_work *work)* take DPLL-subsystem locks, which nest outside it. */ mutex_lock (&sitdev->multiop_lock); -sit9531x_dev_ref_states_update (sitdev); -sit9531x_dev_chan_states_update (sitdev); + answered =sit9531x_dev_ref_states_update (sitdev); + answered |=sit9531x_dev_chan_states_update (sitdev);mutex_unlock (&sitdev->multiop_lock);list_for_each_entry (sitdpll, &sitdev->dplls, list)
@@ -913,8 +1804,14 @@ static void sit9531x_dev_periodic_work(struct kthread_work *work)"Failed to clear notifications: %d\n" , rc); +if (answered || !rc) + sitdev->poll_fails =0 ; +else if (sitdev->poll_fails <SIT9531X_POLL_STRETCH_MAX ) + sitdev->poll_fails++; +kthread_queue_delayed_work (sitdev->kworker, &sitdev->work, -msecs_to_jiffies (SIT9531X_STATUS_POLL_MS )); +msecs_to_jiffies (SIT9531X_STATUS_POLL_MS << + sitdev->poll_fails)); }/* Queue an immediate poll tick; polling continues as a fallback. */
@@ -1047,6 +1944,63 @@ static void sit9531x_pll_states_report(struct sit9531x_dev *sitdev) } } +static bool sit9531x_input_pin_is_registrable (struct sit9531x_dev *sitdev, +u8 index) +{ +if (index >= sitdev->info->num_inputs) +return false; + +/* The N lane of a differential pair is not a standalone input. */ +if (sit9531x_input_is_n (index) && + sitdev->ref[index].sig_mode ==SIT9531X_MODE_DE ) +return false; + +return true; +} + +/* Warn about a pin node whose reg names no registrable pin */ +static void sit9531x_pin_nodes_check (struct sit9531x_dev *sitdev) +{ +struct fwnode_handle *pins, *node; +bool found; +u32 reg; +u8 i; + + pins =device_get_named_child_node (sitdev->dev,"input-pins" ); +fwnode_for_each_child_node (pins, node) { +if (fwnode_property_read_u32 (node,"reg" , ®)) +continue ; +if (reg < sitdev->info->num_inputs && +sit9531x_input_pin_is_registrable (sitdev, reg)) +continue ; +dev_warn (sitdev->dev, +"input-pins/%pfwP: reg %u is %s, node ignored\n" , + node, reg, + reg < sitdev->info->num_inputs ? +"the N lane of a differential pair" : +"not an input lane" ); + } +fwnode_handle_put (pins); + + pins =device_get_named_child_node (sitdev->dev,"output-pins" ); +fwnode_for_each_child_node (pins, node) { +if (fwnode_property_read_u32 (node,"reg" , ®)) +continue ; + found = false; +for (i =0 ; i < sitdev->info->num_outputs; i++) { +if (sitdev->info->clkout_map[i] == reg) { + found = true; +break ; + } + } +if (!found) +dev_warn (sitdev->dev, +"output-pins/%pfwP: reg %u is not an output of %s, node ignored\n" , + node, reg, sitdev->info->name); + } +fwnode_handle_put (pins); +} +static int sit9531x_dev_start (struct sit9531x_dev *sitdev) {struct sit9531x_dpll *sitdpll;
@@ -1061,6 +2015,8 @@ static int sit9531x_dev_start(struct sit9531x_dev *sitdev)sit9531x_pll_states_report (sitdev);mutex_unlock (&sitdev->multiop_lock); +sit9531x_pin_nodes_check (sitdev); +list_for_each_entry (sitdpll, &sitdev->dplls, list) { rc =sit9531x_dpll_register (sitdpll);if (rc) {
@@ -1085,6 +2041,7 @@ static int sit9531x_dev_start(struct sit9531x_dev *sitdev)static void sit9531x_dev_stop (struct sit9531x_dev *sitdev) {struct sit9531x_dpll *sitdpll; +u8 i;kthread_cancel_delayed_work_sync (&sitdev->work);
@@ -1092,6 +2049,30 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev)if (sitdpll->dpll_dev)sit9531x_dpll_unregister (sitdpll); } + +/* +* Write back tables first: forced holdover stays set while a table +* write-back is pending. +*/ +mutex_lock (&sitdev->multiop_lock); +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +sit9531x_table_back_retry (sitdev, i); +if (sitdev->chan[i].table_pending) +dev_warn (sitdev->dev, +"PLL%c priority table left as written, holdover kept\n" , +'A' + i); + } +mutex_unlock (&sitdev->multiop_lock); + +mutex_lock (&sitdev->multiop_lock); +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +sit9531x_ho_release_retry (sitdev, i); +if (sitdev->chan[i].ho_release_pending && + !sitdev->chan[i].table_pending) +dev_warn (sitdev->dev, +"PLL%c left in forced holdover\n" ,'A' + i); + } +mutex_unlock (&sitdev->multiop_lock); } static struct sit9531x_dpll_pin *
@@ -1210,10 +2191,15 @@ static bool sit9531x_dpll_pin_is_registrable(struct sit9531x_dpll *sitdpll, enum dpll_pin_direction dir, u8 index) { +struct sit9531x_dev *sitdev = sitdpll->dev; +if (dir !=DPLL_PIN_DIRECTION_INPUT )return false; -return index ==SIT9531X_MAX_INPUTS ; +if (index ==SIT9531X_MAX_INPUTS ) +return true; + +return sit9531x_input_pin_is_registrable (sitdev, index); }static int sit9531x_dpll_pins_register (struct sit9531x_dpll *sitdpll)
@@ -1604,6 +2590,9 @@ static int sit9531x_resume(struct device *dev)* configuration read at probe is not read again. */ sit9531x_page_cache_drop (sitdev); +mutex_lock (&sitdev->multiop_lock); +sit9531x_reselect_arm (sitdev); +mutex_unlock (&sitdev->multiop_lock);if (sitdev->irq >0 )enable_irq (sitdev->irq);kthread_queue_delayed_work (sitdev->kworker, &sitdev->work,0 );
drivers/dpll/sit9531x/core.h +61 -4
138 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.c +252 -5
301 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h +38 -0
@@ -96,6 +96,10 @@#define SIT9531X_REG_GLOBAL_UPDATE SIT9531X_REG(0x00, 0x0F)#define SIT9531X_SMALL_UPDATE_CMD 0x02 +/* PLL holdover control (PLL page offset) */ +#define SIT9531X_PLL_REG_HO_CTRL 0x6F +#define SIT9531X_PLL_HO_FORCE_BIT 4 +/* One bit per input PAIR (bit 0 = CLKIN0, ..., bit 3 = CLKIN3) */ #define SIT9531X_REG_IN_DE_FORCE SIT9531X_REG(0x02, 0xE8)#define SIT9531X_REG_IN_DE_STATE SIT9531X_REG(0x02, 0xE9)
@@ -183,6 +187,29 @@#define SIT9531X_PLL_STATUS_OUTER_DIS BIT(5) +/* +* Writing the key unlocks the page's debug registers; writing zero locks them. +*/ +#define SIT9531X_PLL_REG_DEBUG 0xBD +#define SIT9531X_PLL_DEBUG_UNLOCK 0xC3 +#define SIT9531X_PLL_DEBUG_LOCK 0x00 + +/* +* The address register selects the block the data register reports. A data read +* returns what the previous read latched; the documented procedures read it +* three times. +*/ +#define SIT9531X_PLL_REG_DBG_STATUS_ADDR 0xD1 +#define SIT9531X_PLL_REG_DBG_STATUS_DATA 0xD0 +#define SIT9531X_DBG_STATUS_READS 3 + +/* +* Low nibble: the source the input subsystem routes to the PLL, in the +* priority-table encoding. +*/ +#define SIT9531X_DBG_STATUS_ROUTED_SRC 0xB0 +#define SIT9531X_DBG_ROUTED_SRC_MASK GENMASK(3, 0) +/* * PLL_CONFIG1F_PLL bit 6: manual active select, no priority arbitration. The * register is GUI generated; the driver only reads it.
@@ -213,6 +240,17 @@#define SIT9531X_PLL_REG_STATUS_1 0x06#define SIT9531X_PLL_STATUS_1_HO_VALID BIT(2) +/* +* Clock monitor status, one nibble per input lane; the lower-numbered input of +* each register is in the low nibble. +*/ +#define SIT9531X_CLKMON_P_STATUS_01 SIT9531X_REG(0x06, 0x02) +#define SIT9531X_CLKMON_P_STATUS_23 SIT9531X_REG(0x06, 0x06) +#define SIT9531X_CLKMON_N_STATUS_01 SIT9531X_REG(0x06, 0x92) +#define SIT9531X_CLKMON_N_STATUS_23 SIT9531X_REG(0x06, 0x96) +#define SIT9531X_CLKMON_FINE_DRIFT BIT(0) +#define SIT9531X_CLKMON_COARSE_DRIFT BIT(1) +#define SIT9531X_CLKMON_LOSS BIT(2)#define SIT9531X_CLKMON_P_NOTIF_01 SIT9531X_REG(0x06, 0x03)#define SIT9531X_CLKMON_P_NOTIF_23 SIT9531X_REG(0x06, 0x07)
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 07/13] dpll: sit9531x: implement input pin state on a DPLL
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] dpll: sit9531x: sit9531x_prio_activesel_pick() latches lower-priority source - [Medium] dpll…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] dpll: sit9531x: sit9531x_prio_activesel_pick() latches lower-priority source
- [Medium] dpll: sit9531x: sit9531x_prio_table_commit() releases unforced holdover on error
- [Medium] dpll: sit9531x: sit9531x_reselect() leaves PLL stuck in holdover
- [Medium] dpll: sit9531x: manual PLL priority table entries prevent disabling inputs
--
commit 2d816e6713729c64ab6242d9d6911d753a230377
Author: Oleg Zadorozhnyi <[email protected]>
dpll: sit9531x: implement input pin state on a DPLL
This commit implements DPLL input pin state and operstate reporting and configuration by managing per-PLL priority tables, input receiver gating, and holdover reference re-selection.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -382,20 +487,462 @@ static u8 sit9531x_prio_slot_get(u8 val, u8 slot)
[ ... ]
Quoted 21 lines
drivers/dpll/sit9531x/core.c +21
-0+/* +* Pick the active selection to latch; after a latch the PLL uses that source +* until it loses signal. +*/ +static u8 sit9531x_prio_activesel_pick (struct sit9531x_dev *sitdev, +const u8 *old,const u8 *srcs,u8 cur) +{ +u8 top, i; + + top =sit9531x_prio_top_live (sitdev, srcs); +if (top !=SIT9531X_PRIO_SRC_NONE && + top !=sit9531x_prio_top_live (sitdev, old)) +return top; + + cur =sit9531x_prio_src_canon (sitdev, cur &SIT9531X_PRIO_NIBBLE_MASK ); + +if (sit9531x_prio_src_usable (cur) && +sit9531x_prio_src_live (sitdev, cur)) +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (srcs[i] == cur) +return cur;
drivers/dpll/sit9531x/core.c static u8 sit9531x_prio_slot_get(u8 val, u8 slot) · line 764
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ +if (top !=SIT9531X_PRIO_SRC_NONE ) +return top; + +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (sit9531x_prio_src_usable (srcs[i])) +return srcs[i]; + +return srcs[0 ]; +}
[Severity: Medium]
Can sit9531x_prio_activesel_pick() re-latch a lower-priority cur source instead of top when sit9531x_reselect() runs?
sit9531x_reselect() calls sit9531x_prio_table_commit() with
srcs == chan->prio_srcs, so old and srcs point to the same array and top != sit9531x_prio_top_live(sitdev, old) is always false (and during sit9531x_prio_table_apply(), sit9531x_prio_top_live(sitdev, old) also evaluates old against the newly fetched sitdev->ref[].los state rather than chan->live_top). If the previous active-selection nibble cur names a lower-priority source in srcs[] whose loss-of-signal bit is clear (such as OCXO or an input with qual_fail), sit9531x_prio_activesel_pick() returns cur without checking whether the PLL is tracking it, and sit9531x_prio_table_commit() updates chan->live_top to top so subsequent polls never re-select top.
In addition, cur is canonicalized with sit9531x_prio_src_canon(), whereas chan->prio_srcs[] holds uncanonicalized hardware nibbles from sit9531x_prio_mask_build(), so srcs[i] == cur and the fallback return of srcs[i] do not match or canonicalize differential N-lane codes.
Quoted 26 lines
drivers/dpll/sit9531x/core.c +26
-0+ +static int sit9531x_prio_table_commit (struct sit9531x_dev *sitdev,u8 pll_idx, +const u8 *srcs) +{ +u8 val, last_old, slot, attempt, written =0 , restored =0 ; +u8 now[SIT9531X_PRIO_MAX_SLOTS ], back[SIT9531X_PRIO_MAX_SLOTS ]; +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +int rc =0 , prg_rc, ho_rc =0 ; +bool empty, ho_foreign, pending = false; +bool pending_before = chan->table_pending; +u16 reg; + + empty = true; +for (slot =0 ; slot <SIT9531X_PRIO_MAX_SLOTS ; slot++) +if (sit9531x_prio_src_usable (srcs[slot])) + empty = false; + +memcpy (back, chan->table_pending ? chan->table_back : chan->prio_srcs, +sizeof (back)); + +/* +* Treat a forced holdover as set by this driver only when the table is +* empty or a release is pending; leave any other in place. +*/ + rc =sit9531x_read_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_HO_CTRL , + &val);
drivers/dpll/sit9531x/core.c static u8 sit9531x_prio_slot_get(u8 val, u8 slot) · line 800
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+if (rc) +return rc; + + ho_foreign = (val &BIT (SIT9531X_PLL_HO_FORCE_BIT )) && + chan->prio_mask && !chan->ho_release_pending; + + rc =sit9531x_write_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_HO_CTRL , + val |BIT (SIT9531X_PLL_HO_FORCE_BIT )); +if (rc) + goto release;
[Severity: Medium]
Should this return rc directly instead of jumping to release when forcing holdover fails?
When sit9531x_write_pll_u8() fails here, holdover was never forced by this call, yet jumping to release tries to clear SIT9531X_PLL_HO_FORCE_BIT and sets chan->ho_release_pending = true if that update also fails (which causes later calls to treat an externally forced holdover bit as driver-owned and clear it).
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -852,34 +1565,211 @@ static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev)
[ ... ]
Quoted 16 lines
drivers/dpll/sit9531x/core.c +16
-0+/* +* Rebuild pll_mask from the cached priority tables and the manual-select +* inputs. Caller must hold sitdev->multiop_lock. +*/ +static void sit9531x_ref_pll_mask_rebuild (struct sit9531x_dev *sitdev) +{ +u8 pll_idx, src, index; + +for (index =0 ; index < sitdev->info->num_inputs; index++) + sitdev->ref[index].pll_mask =0 ; + +for (pll_idx =0 ; pll_idx <SIT9531X_NUM_PLLS ; pll_idx++) { +u16 mask = sitdev->chan[pll_idx].prio_mask; + +for (src =0 ; src <SIT9531X_PRIO_NUM_SRC ; src++) { +if (!(mask &BIT (src)))
drivers/dpll/sit9531x/core.c static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev) · line 1652
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+continue ; + + index =sit9531x_hw_src_input (src); +if (index < sitdev->info->num_inputs) + sitdev->ref[index].pll_mask |=BIT (pll_idx); + } + } + +sit9531x_manual_claims_add (sitdev); +}
[Severity: Medium]
Should sit9531x_ref_pll_mask_rebuild() and sit9531x_ref_pll_mask_fetch() skip PLLs with chan->manual_input set?
A manual-select PLL ignores its priority table and exposes no state_on_dpll_set callback to remove entries from it, so folding its prio_mask into ref->pll_mask keeps those inputs claimed forever and prevents sit9531x_input_disable() from powering down their receivers when they are disconnected from all automatic PLLs. Note that sit9531x_dev_state_fetch() also calls sit9531x_ref_pll_mask_fetch() before sit9531x_chan_select_fetch() has populated chan->manual_input.
[ ... ]
Quoted 23 lines
drivers/dpll/sit9531x/core.c +23
-0+static void sit9531x_reselect (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +u8 top; +int rc; + +/* A PLL on manual input select uses no priority table */ +if (chan->manual_input || !chan->prio_mask || chan->mode || + chan->ho_release_pending || chan->table_pending) +return ; + + top =sit9531x_prio_top_live (sitdev, chan->prio_srcs); +if (chan->reselect_armed) { +if (top ==SIT9531X_PRIO_SRC_NONE || !chan->ho_freeze) { + chan->reselect_armed = false; + chan->live_top = top; +return ; + } + }else { +if (top == chan->live_top) +return ; +/* +* Tracking is locked and not frozen; the two bits are read
drivers/dpll/sit9531x/core.c static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev) · line 1731
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+* independently. +*/ +if (top ==SIT9531X_PRIO_SRC_NONE || + (chan->locked && !chan->ho_freeze)) { + chan->live_top = top; +return ; + } + } + + rc =sit9531x_prio_table_commit (sitdev, pll_idx, chan->prio_srcs);
[Severity: Medium]
Can returning whenever top == chan->live_top leave the PLL stuck in holdover when a live source is available?
If a higher-priority source IN0 recovers while the PLL is locked to a fallback source IN1, sit9531x_reselect() sees chan->locked && !chan->ho_freeze, updates chan->live_top to IN0, and returns. If IN1 later fails and puts the PLL into holdover while IN0 is still live, top == chan->live_top is true, so sit9531x_reselect() returns early and never re-latches the table to acquire IN0 (the same happens if the active top source drops into holdover and recovers between two polls).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH net-next v16 07/13] dpll: sit9531x: implement input pin state on a DPLL
In reply to Ali RouhiThank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 13 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 9 · Low: 4
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message does not say that setting an input pin to DISCONNECTED can power down the input receiver for the whole device.
- [Medium] The commit message describes the table write as 'the documented procedure: force holdover, write the slots, latch with a…
- [Medium] The driver can lose track of a forced holdover it set itself.
- [Medium] For a PLL on manual input select, sit9531x_dpll_selection_state_get() returns CONNECTED only when…
- [Medium] Receiver gating does not protect the input of a PLL whose manual input select comes from the select pins.
- [Medium] sit9531x_prio_activesel_pick() (core.c:738) tries to keep the current source, but in this patch it reads that source from the…
- [Medium] sit9531x_reselect() (core.c:1699) returns early for manual, empty-table, free-run and pending-write PLLs, but not for an inactive…
- [Medium] For a differential pair, the driver writes the P-lane code where the profile used the N-lane code.
- [Medium] dpll: sit9531x: sit9531x_reselect() leaves PLL stuck in holdover
- [Low] The patch includes changes unrelated to input pin state that the commit message does not mention: (a) exponential back-off of the poll…
- [Low] Every external input pin is registered with DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE (prop.c:164-166), and one…
- [Low] sit9531x_input_enable() (core.c:302) only clears the lane-pair FORCE bit so the lane 'uses the loaded configuration', then sets…
- [Low] sit9531x_input_disable() (core.c:266) read-modify-writes the FORCE bit first (core.c:284) and clears the STATE bit afterwards.
--
dpll: sit9531x: implement input pin state on a DPLL
This patch adds state_on_dpll_get/set and operstate_on_dpll_get for the sit9531x input pins. SELECTABLE and DISCONNECTED map to whether the input is listed in each PLL's priority table. Table writes force holdover, rewrite the slots, latch with a small update and release holdover, and the poll worker re-selects a PLL in holdover when a listed source returns.
Quoted 4 lines
Report and set whether an input takes part in a PLL's reference selection. The PLL picks its reference from a priority table: an input in the table is SELECTABLE, one absent is DISCONNECTED, and setting the state adds or removes it.
[Severity: Medium]
Should the commit message say that DISCONNECTED can also power down the input receiver for the whole device?
In sit9531x_dpll_input_pin_state_on_dpll_set(), once ref->pll_mask drops to zero, the driver calls sit9531x_input_disable(). That sets the page 0x02 receiver FORCE bit and clears STATE for the whole lane pair.
SELECTABLE calls sit9531x_input_enable(), which clears FORCE. That also releases any force-off the loaded profile had set. The poll worker also retries a failed power-down on its own through sit9531x_input_off_retry().
The receiver is shared by all four PLLs and by both lanes of a pair. A per-(pin, DPLL) operation therefore has a device-wide side effect.
Quoted 7 lines
A table write uses the documented procedure: force holdover, write the slots, latch with a small update, release. The pin reported active is the one the part feeds the PLL while the PLL tracks it and the lane has signal.
A PLL in holdover after losing its reference is re-selected when a listed source returns.
[Severity: Medium]
Does this match what sit9531x_prio_table_commit() does?
On every non-empty write it does one more thing than the four steps. It reads the last priority register and replaces the CLK_ACTIVESEL nibble with a source chosen by sit9531x_prio_activesel_pick(). So the driver does decide which source the PLL latches. Yet the message justifies refusing CONNECTED with "the driver does not program manual input select".
The re-select also covers more than "a PLL in holdover after losing its reference". sit9531x_reselect_arm() runs from sit9531x_dev_state_fetch() at probe and from sit9531x_resume(). On the first poll, sit9531x_reselect() then commits for any PLL with ho_freeze set while a listed source has no LOS:
if (chan->reselect_armed) {
if (top == SIT9531X_PRIO_SRC_NONE || !chan->ho_freeze) {
...Nothing checks why the PLL is in holdover; it could be a profile-forced holdover. If FORCE was already set, ho_foreign leaves the HO_CTRL force in place. The table, the selection nibble and the global small update are still written, and each commit forces holdover for at least 10 ms.
Could the message describe the active selection write and the re-select at probe and resume?
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 7 lines
drivers/dpll/sit9531x/core.c +3
-0@@ -223,6 +262,72 @@ static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev, } } +/* Caller must hold sitdev->multiop_lock. */ +int sit9531x_input_disable (struct sit9531x_dev *sitdev,u8 index) +{
[ ... ]
drivers/dpll/sit9531x/core.c static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev, · line 288
Quoted 7 lines
drivers/dpll/sit9531x/core.c +7
-0+ rc =sit9531x_read_u8 (sitdev, force_reg, &val); +if (!rc) + rc =sit9531x_write_u8 (sitdev, force_reg, val |BIT (pair)); + + ret =sit9531x_read_u8 (sitdev, state_reg, &val); +if (!ret) + ret =sit9531x_write_u8 (sitdev, state_reg, val & ~BIT (pair));
[Severity: Low]
Can setting FORCE first turn the receiver on for one I2C transfer?
Suppose STATE still holds 1 for this pair while the profile keeps the receiver off. Writing FORCE first applies STATE=1 until the second write clears it. sit9531x_output_hiz_write() orders its writes the other way for this reason:
/* * STATE before MASK: enabling the override first can drive the pad for * one I2C transfer. */
Would clearing STATE before setting FORCE avoid the transient?
[ ... ]
Quoted 6 lines
drivers/dpll/sit9531x/core.c +6
-0+/* +* Release the force so the lane uses the loaded configuration. Caller must hold +* sitdev->multiop_lock. +*/ +int sit9531x_input_enable (struct sit9531x_dev *sitdev,u8 index) +{
[ ... ]
drivers/dpll/sit9531x/core.c static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev, · line 326
Quoted 9 lines
drivers/dpll/sit9531x/core.c +9
-0+ rc =sit9531x_read_u8 (sitdev, force_reg, &val); +if (rc) +return rc; + rc =sit9531x_write_u8 (sitdev, force_reg, val & ~BIT (pair)); +if (rc) +return rc; + + ref->enabled = true; + ref->off_pending = false;
[Severity: Low]
What happens here if the loaded profile itself keeps this receiver off?
Clearing FORCE hands the lane back to the profile, but ref->enabled is set to true either way. sit9531x_ref_state_fetch() computes:
ref->enabled = !((force & BIT(pair)) && !(state & BIT(pair)));
so the mismatch is never noticed.
A SELECTABLE request then succeeds and adds the source to the table, forcing holdover and re-latching, while the receiver stays off. The pin only shows NO_SIGNAL. Is it intended that the driver can never turn on a receiver the profile disabled?
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -382,20 +487,462 @@ static u8 sit9531x_prio_slot_get(u8 val, u8 slot)
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +4
-0+/* Order the members by configured priority */ +static void sit9531x_prio_table_build (struct sit9531x_dev *sitdev,u8 pll_idx, +u16 members,u8 *srcs) +{
[ ... ]
drivers/dpll/sit9531x/core.c static u8 sit9531x_prio_slot_get(u8 val, u8 slot) · line 679
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) + srcs[i] = i < n ? order[i] :SIT9531X_PRIO_SRC_NONE ; +}
[Severity: Medium]
Does the device treat codes k and SIT9531X_PRIO_SRC_N_BASE + k as the same differential receiver output?
A profile may list a differential pair by its N-lane code. members comes from prio_mask, which only holds canonical P-lane bits. Any table change therefore rewrites that entry as k.
The memcmp() against the raw chan->prio_srcs in sit9531x_prio_table_apply() then sees a change and forces holdover, even when the members are the same.
In the re-select path, sit9531x_reselect() passes the raw chan->prio_srcs. sit9531x_prio_activesel_pick() misses the N-coded entry when it compares the canonical cur, and returns top instead. sit9531x_prio_top_live() always returns a canonical code. The CLK_ACTIVESEL nibble then gets a P-lane code that the latched table does not contain.
The comment in sit9531x_chan_routed_ref_read() about "a differential pair fed through its N-lane code" suggests the device does tell the two codes apart.
[ ... ]
Quoted 7 lines
drivers/dpll/sit9531x/core.c +7
-0+static u8 sit9531x_prio_activesel_pick (struct sit9531x_dev *sitdev, +const u8 *old,const u8 *srcs,u8 cur) +{ +u8 top, i; + + top =sit9531x_prio_top_live (sitdev, srcs); + if (top != SIT9531X_PRIO_SRC_NONE &&
drivers/dpll/sit9531x/core.c static u8 sit9531x_prio_slot_get(u8 val, u8 slot) · line 754
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ top != sit9531x_prio_top_live(sitdev, old)) +return top; + + cur =sit9531x_prio_src_canon (sitdev, cur &SIT9531X_PRIO_NIBBLE_MASK ); + +if (sit9531x_prio_src_usable (cur) && +sit9531x_prio_src_live (sitdev, cur)) +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (srcs[i] == cur) +return cur;
[Severity: Medium]
Is cur the right source to keep here? It comes from the CLK_ACTIVESEL nibble. The driver's own comments say this nibble does not change when the device falls back to another listed source.
Take table [A, B], with the nibble naming B and the device fallen back to A. A user write that adds C re-latches B. That moves the PLL off the higher-priority A it is tracking.
The next patch, "dpll: sit9531x: add support to get and set priority on input pins", checks the routed source first, which fixes this tracking case. Two problems remain at the end of the series.
First, when called from sit9531x_reselect(), the PLL is in holdover or unlocked, so routed_ref is invalid. sit9531x_reselect() also passes the same array as both old and srcs:
rc = sit9531x_prio_table_commit(sitdev, pll_idx, chan->prio_srcs);
so the "top changed" branch above can never fire. If A and B both come back in the same poll after a full outage, the pick latches B. live_top is then set to A, and nothing corrects it afterwards.
Can the PLL stay on the lower-priority source indefinitely?
Second, srcs[i] == cur compares a canonical code against raw table codes. If the table lists a differential pair by its N-lane code, the match fails. The function then falls through to top, a canonical P code that is not in the table.
[ ... ]
Quoted 2 lines
drivers/dpll/sit9531x/core.c +2
-0+ ho_foreign = (val &BIT (SIT9531X_PLL_HO_FORCE_BIT )) && + chan->prio_mask && !chan->ho_release_pending;
[ ... ]
Quoted 9 lines
drivers/dpll/sit9531x/core.c +9
-0+release: +/* +* An empty table keeps the forced holdover; the PLL uses the source in +* the selection nibble, which still names the old one. +*/ +if (!chan->prio_mask) { +dev_dbg (sitdev->dev, +"PLL%c: no source listed, holdover kept\n" , +'A' + pll_idx);
drivers/dpll/sit9531x/core.c static u8 sit9531x_prio_slot_get(u8 val, u8 slot) · line 913
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ chan->ho_release_pending = false; + goto out; + } + +if (ho_foreign) { +dev_dbg (sitdev->dev, +"PLL%c: holdover was forced before the write, left in place\n" , +'A' + pll_idx); + goto out; + }
[Severity: Medium]
Does the empty-table branch lose the record that the driver owns the forced holdover?
It keeps HO_CTRL FORCE set but clears ho_release_pending. A normal re-add is fine, because prio_mask is still 0 when ho_foreign is computed.
The table can also become non-empty without a driver write, for example from an I2C tool. sit9531x_chan_state_fetch() accepts such a table and re-seeds it through sit9531x_prio_cfg_seed(). Then:
sit9531x_dev_chan_states_update()
sit9531x_chan_state_fetch() /* prio_mask now non-zero */
sit9531x_reselect() /* top != live_top, ho_freeze set */
sit9531x_prio_table_commit()
ho_foreign == true /* "left in place" */live_top is updated after that, so the poll never retries. Later user commits keep seeing ho_foreign as well.
Can the PLL then stay in forced holdover permanently while its table lists live sources?
Teardown does not undo this either. sit9531x_dev_stop(), and sit9531x_dev_pending_retry() at the end of the series, only call sit9531x_ho_release_retry(). That does nothing unless ho_release_pending is set, and no warning is printed for this case. Receivers forced off by sit9531x_input_disable() are also never released on unbind.
The commit message also does not mention the new rule in sit9531x_dpll_frozen_status(). A frozen PLL with an empty table and invalid holdover memory is now reported as UNLOCKED.
[ ... ]
Quoted 10 lines
drivers/dpll/sit9531x/core.c +6
-0@@ -793,11 +1471,39 @@ static int sit9531x_ref_pll_mask_fetch(struct sit9531x_dev *sitdev)return 0 ; } +/* +* Mark the input each manual-select PLL uses; its table need not list it. +* Caller must hold sitdev->multiop_lock. +*/ +static void sit9531x_manual_claims_add (struct sit9531x_dev *sitdev) +{
drivers/dpll/sit9531x/core.c static int sit9531x_ref_pll_mask_fetch(struct sit9531x_dev *sitdev) · line 1489
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+const struct sit9531x_chan *chan; +u8 pll_idx; + +for (pll_idx =0 ; pll_idx <SIT9531X_NUM_PLLS ; pll_idx++) { + chan = &sitdev->chan[pll_idx]; +if (chan->manual_input && + chan->manual_ref < sitdev->info->num_inputs) + sitdev->ref[chan->manual_ref].pll_mask |=BIT (pll_idx); + } +}
[Severity: Medium]
What keeps the receiver on for a PLL that takes its manual select from the select pins?
sit9531x_chan_select_fetch() sets manual_ref to SIT9531X_REF_INVALID and leaves it there in the pin-select branch. The only later update is in sit9531x_chan_state_fetch(), and it happens only while the PLL is tracking and the debug-bus read succeeds. A PLL that is not tracking at probe or resume claims nothing here.
Now take an automatic PLL that lists the same input:
sit9531x_dpll_input_pin_state_on_dpll_set(DISCONNECTED)
sit9531x_input_prio_remove()
ref->pll_mask &= ~pll_bit; /* now 0 */
sit9531x_input_disable() /* shared receiver forced off */
The manual PLL can then never track that input, so it never learns manual_ref. Its pins use sit9531x_dpll_input_pin_manual_ops, which has no setter.
Can a request on one DPLL silently cut the reference of another, manual one?
In the register-select branch, the low nibble of GPIO_INPUT_FUNC_CTRL5..8 is decoded as a plain source code. regs.h notes that bit 6 (indirect choice) and bit 5 (active/spare) are not decoded. With bit 6 set, could manual_ref protect the wrong receiver?
This code is unchanged at the end of the series.
[ ... ]
Quoted 23 lines
drivers/dpll/sit9531x/core.c +23
-0+static void sit9531x_reselect (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +u8 top; +int rc; + +/* A PLL on manual input select uses no priority table */ +if (chan->manual_input || !chan->prio_mask || chan->mode || + chan->ho_release_pending || chan->table_pending) +return ; + + top =sit9531x_prio_top_live (sitdev, chan->prio_srcs); +if (chan->reselect_armed) { +if (top ==SIT9531X_PRIO_SRC_NONE || !chan->ho_freeze) { + chan->reselect_armed = false; + chan->live_top = top; +return ; + } + }else { +if (top == chan->live_top) +return ; +/* +* Tracking is locked and not frozen; the two bits are read
drivers/dpll/sit9531x/core.c static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev) · line 1731
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+* independently. +*/ +if (top ==SIT9531X_PRIO_SRC_NONE || + (chan->locked && !chan->ho_freeze)) { + chan->live_top = top; +return ; + } + } + + rc =sit9531x_prio_table_commit (sitdev, pll_idx, chan->prio_srcs);
[Severity: Medium]
Can this early return leave a PLL in holdover while a listed source has signal?
The top == chan->live_top test runs before anything looks at chan->ho_freeze or chan->locked. live_top is also updated on the "locked and not frozen" path without a commit. Two sequences seem to end with no re-select.
First case: take table [IN0, IN1] with the PLL on IN1 after IN0 lost signal. IN0 comes back while IN1 is still good. top becomes IN0, but the PLL is locked and not frozen, so live_top is set to IN0 and nothing is written.
If IN1 then loses signal and the PLL enters holdover while IN0 is still live, the next poll computes top == IN0 == live_top and returns here. sit9531x_prio_table_commit() is never called, so the active selection is never re-latched to IN0.
Second case: the top source drops long enough for the PLL to enter holdover, then recovers before the next poll samples the clock monitors in sit9531x_input_mon_fetch(). From the poll's point of view top never changed, so it still matches live_top and the frozen PLL is left alone.
The comment above sit9531x_prio_activesel_pick() says the PLL uses the latched source until it loses signal. The commit message says a PLL in holdover after losing its reference is re-selected when a listed source returns.
Does the device leave holdover by itself in either case? Or does the PLL stay frozen until something else rewrites the table?
If it stays frozen, should the re-select be driven by the PLL being frozen with a live listed source, with live_top only limiting how often a commit is repeated while a fresh latch is still acquiring?
[Severity: Medium]
Should an inactive PLL be excluded from the early return above?
sit9531x_chan_state_fetch() sets:
chan->locked = active && !(outer_lol & BIT(pll_idx));
so an unused PLL always reads as not locked, and the locked guard never stops the commit.
On an unused PLL with a non-empty table, every change of the top live source runs sit9531x_prio_table_commit() from the poll worker. Each run forces holdover and sleeps 10-12 ms under multiop_lock. It rewrites the table and the active selection, and issues the page 0 global small-change update. It also logs "re-selecting, a source is back".
sit9531x_dpll_lock_status_get() already treats !chan->active as a separate state. This code is unchanged at the end of the series.
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0@@ -913,8 +1804,14 @@ static void sit9531x_dev_periodic_work(struct kthread_work *work)"Failed to clear notifications: %d\n" , rc);
drivers/dpll/sit9531x/core.c static void sit9531x_dev_periodic_work(struct kthread_work *work) · line 1815
Quoted 10 lines
drivers/dpll/sit9531x/core.c +7
-1+if (answered || !rc) + sitdev->poll_fails =0 ; +else if (sitdev->poll_fails <SIT9531X_POLL_STRETCH_MAX ) + sitdev->poll_fails++; +kthread_queue_delayed_work (sitdev->kworker, &sitdev->work, -msecs_to_jiffies (SIT9531X_STATUS_POLL_MS )); +msecs_to_jiffies (SIT9531X_STATUS_POLL_MS << + sitdev->poll_fails)); }
[Severity: Low]
This isn't a bug, but some changes in this patch look unrelated to input pin state, and the commit message does not mention them:
the exponential poll back-off here, up to 8x the period dev_warn() turned into dev_warn_ratelimited() in the poll paths the new sit9531x_pin_nodes_check() pass over input-pins and output-pins the regmap precious_reg callback
SIT9531X_POLL_STRETCH_MAX was added unused in "dpll: sit9531x: register DPLL devices and pins". That patch's message says the worker "polls the status registers twice a second", and the first user only shows up here. Could these changes be split out, or at least described?
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/dpll.c +0
-0
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/dpll.c +0
-0@@ -155,6 +168,120 @@ const struct dpll_device_ops sit9531x_dpll_device_ops = {
[ ... ]
Quoted 9 lines
drivers/dpll/sit9531x/dpll.c +9
-0+/* Caller must hold sitdev->multiop_lock. */ +static void +sit9531x_dpll_selection_state_get (struct sit9531x_dev *sitdev, +const struct sit9531x_dpll *sitdpll, +u8 pin_id,enum dpll_pin_state *state) +{ +const struct sit9531x_chan *chan; + +lockdep_assert_held (&sitdev->multiop_lock);
drivers/dpll/sit9531x/dpll.c const struct dpll_device_ops sit9531x_dpll_device_ops = { · line 201
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c +10
-0+ + chan =sit9531x_chan_state_get (sitdev, sitdpll->id); + +if (chan->manual_input) { +if (chan->routed_ref == pin_id && !chan->stale) + *state =DPLL_PIN_STATE_CONNECTED ; +else + *state =DPLL_PIN_STATE_DISCONNECTED ; +return ; + }
[Severity: Medium]
Should the state of a pin on a manual PLL depend on routed_ref?
sit9531x_chan_state_fetch() fills routed_ref only while the PLL is
tracking: active, outer loop locked, not free-run and not frozen. In every other case it is SIT9531X_REF_INVALID. So every input of a manual PLL reads DISCONNECTED while the PLL is acquiring, in holdover after losing its reference, or stale.
Documentation/driver-api/dpll.rst says the pin state "reflects the administrative intent set by the user". In manual mode, CONNECTED means the pin is selected to drive the dpll device. Hardware status belongs in the operstate, which already reports NO_SIGNAL.
chan->manual_ref already holds the selected input. Could it be used here instead? This code is unchanged at the end of the series.
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/dpll.c +0
-0@@ -167,8 +294,123 @@ sit9531x_dpll_input_pin_direction_get(const struct dpll_pin *pin,
[ ... ]
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_input_pin_direction_get(const struct dpll_pin *pin, · line 414
Quoted 9 lines
drivers/dpll/sit9531x/dpll.c +8
-0+/* +* For a PLL on manual input select: the select pins or register choose the +* reference, so the pin has no state setter and no priority. +*/ +static const struct dpll_pin_ops sit9531x_dpll_input_pin_manual_ops = { + .direction_get = sit9531x_dpll_input_pin_direction_get, + .state_on_dpll_get = sit9531x_dpll_input_pin_state_on_dpll_get, + .operstate_on_dpll_get = sit9531x_dpll_input_pin_operstate_on_dpll_get, };
[Severity: Low]sit9531x_pin_props_get() registers every external input pin with DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE, and the same dpll_pin is shared by all four PLLs. On a manual PLL this ops table has no state_on_dpll_set, so dpll_pin_state_set() returns early:
if (!ops->state_on_dpll_set) return -EOPNOTSUPP;
Userspace gets no extack message with that. Would a setter that refuses the request and explains why through NL_SET_ERR_MSG() be clearer?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 8/13 dpll: sit9531x: add support to get and set priority on input pins
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Let userspace read and set the priority kept per input and PLL; a set rebuilds the table from it. Priority and state are separate: a priority set on a disconnected input applies when it is connected. The range is 0 to 255 over eleven slots; inputs of equal priority keep their table order.
A commit that leaves the best live source unchanged keeps the routed source as the active selection, so the PLL does not restart acquisition for it.
A table rewritten outside the driver, by a profile reload or an I2C tool, becomes the new configuration. The poll compares each pin with a baseline taken at registration and notifies a changed operational state or priority; a notification that fails is sent again on a later tick.
--- drivers/dpll/sit9531x/core.c | 106 +++++++++++++++++++++- drivers/dpll/sit9531x/core.h | 4 + drivers/dpll/sit9531x/dpll.c | 167 ++++++++++++++++++++++++++++++----- drivers/dpll/sit9531x/dpll.h | 4 +- drivers/dpll/sit9531x/prop.c | 2 + 5 files changed, 260 insertions(+), 23 deletions(-)
drivers/dpll/sit9531x/core.c +104 -2
@@ -606,6 +606,33 @@ bool sit9531x_input_prio_present(struct sit9531x_dev *sitdev, u8 pll_idx,return !!(sitdev->chan[pll_idx].prio_mask &BIT (input_idx)); } +/* +* @input_idx is in hardware encoding (see sit9531x_input_hw_src()). A source +* the PLL has never listed reports the last slot index, 10. Caller must hold +* sitdev->multiop_lock. +*/ +int sit9531x_input_prio_get (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx,u8 *prio) +{ +const struct sit9531x_chan *chan; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + input_idx =sit9531x_prio_src_canon (sitdev, input_idx); +if (input_idx >=SIT9531X_PRIO_NUM_SRC ) +return -EINVAL ; + + chan = &sitdev->chan[pll_idx]; +if (chan->cfg_known &BIT (input_idx)) + *prio = chan->cfg_prio[input_idx]; +else + *prio =SIT9531X_PRIO_MAX_SLOTS -1 ; + +return 0 ; +} +/* * Take the configured priorities from the hardware table: a listed source gets * the first slot it occupies.
@@ -736,7 +763,8 @@ static u8 sit9531x_prio_top_live(const struct sit9531x_dev *sitdev,* until it loses signal. */ static u8 sit9531x_prio_activesel_pick (struct sit9531x_dev *sitdev, -const u8 *old,const u8 *srcs,u8 cur) +const u8 *old,const u8 *srcs,u8 cur, +u8 routed) {u8 top, i;
@@ -745,6 +773,12 @@ static u8 sit9531x_prio_activesel_pick(struct sit9531x_dev *sitdev, top != sit9531x_prio_top_live(sitdev, old))return top; +if (sit9531x_prio_src_usable (routed) && +sit9531x_prio_src_live (sitdev, routed)) +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (srcs[i] == routed) +return routed; + cur =sit9531x_prio_src_canon (sitdev, cur &SIT9531X_PRIO_NIBBLE_MASK ); if (sit9531x_prio_src_usable(cur) &&
@@ -827,12 +861,19 @@ static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_idx,if (!empty) {u8 sel =sit9531x_prio_slot_get (val, slot +1 ); +u8 routed =SIT9531X_PRIO_SRC_NONE ; +/* +* The pick needs the signal state now, not as of the last poll; +* the routed source is the last poll's sample. +*/ rc =sit9531x_input_mon_fetch (sitdev);if (rc) goto rollback; +if (!chan->stale && chan->routed_ref !=SIT9531X_REF_INVALID ) + routed =sit9531x_input_hw_src (chan->routed_ref); sel =sit9531x_prio_activesel_pick (sitdev, chan->prio_srcs, - srcs, sel); + srcs, sel, routed); val =sit9531x_prio_slot_set (val, slot +1 , sel); }
@@ -983,6 +1024,59 @@ static int sit9531x_prio_table_apply(struct sit9531x_dev *sitdev, u8 pll_idx,return sit9531x_prio_table_commit (sitdev, pll_idx, srcs); } +/* +* Check if the device holds the table the configured priorities give for +* @members. +*/ +static bool sit9531x_prio_table_held (struct sit9531x_dev *sitdev,u8 pll_idx, +u16 members) +{ +u8 srcs[SIT9531X_PRIO_MAX_SLOTS ]; + +sit9531x_prio_table_build (sitdev, pll_idx, members, srcs); + +return !memcmp (srcs, sitdev->chan[pll_idx].prio_srcs,sizeof (srcs)); +} + +/* +* @input_idx is in hardware encoding (0-11, see sit9531x_input_hw_src()). A +* source not in the table keeps the priority for when it is connected. Caller +* must hold sitdev->multiop_lock. +*/ +int sit9531x_input_prio_set (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx,u8 prio) +{ +struct sit9531x_chan *chan; +u16 old_known; +u8 old_prio; +int rc; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + input_idx =sit9531x_prio_src_canon (sitdev, input_idx); +if (input_idx >=SIT9531X_PRIO_NUM_SRC ) +return -EINVAL ; + + chan = &sitdev->chan[pll_idx]; + old_prio = chan->cfg_prio[input_idx]; + old_known = chan->cfg_known; + chan->cfg_prio[input_idx] = prio; + chan->cfg_known |=BIT (input_idx); + +if (!(chan->prio_mask &BIT (input_idx))) +return 0 ; + + rc =sit9531x_prio_table_apply (sitdev, pll_idx, chan->prio_mask); +if (rc && !sit9531x_prio_table_held (sitdev, pll_idx, chan->prio_mask)) { + chan->cfg_prio[input_idx] = old_prio; + chan->cfg_known = old_known; + } + +return rc; +} +/* * Removing the last source leaves an empty table, which keeps the PLL in * holdover. Caller must hold sitdev->multiop_lock.
@@ -2227,6 +2321,14 @@ static int sit9531x_dpll_pins_register(struct sit9531x_dpll *sitdpll) goto error; } +/* +* Taken before the pin is published; see +* sit9531x_dpll_pin_baseline(). +*/ +mutex_lock (&sitdpll->dev->multiop_lock); +sit9531x_dpll_pin_baseline (pin); +mutex_unlock (&sitdpll->dev->multiop_lock); + rc =sit9531x_dpll_pin_register (pin, index);if (rc) {kfree (pin);
drivers/dpll/sit9531x/core.h +4 -0
@@ -252,6 +252,10 @@ int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index);bool sit9531x_input_prio_present (struct sit9531x_dev *sitdev,u8 pll_idx,u8 input_idx); +int sit9531x_input_prio_set (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx,u8 prio); +int sit9531x_input_prio_get (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx,u8 *prio);int sit9531x_input_prio_remove (struct sit9531x_dev *sitdev,u8 pll_idx,u8 input_idx); int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,
drivers/dpll/sit9531x/dpll.c +147 -20
204 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.h +3 -1
@@ -30,7 +30,8 @@ struct sit9531x_dpll_pin {u8 id;/* hardware index */ u8 prio;enum dpll_pin_state pin_state; -bool seen;/* baseline taken by the poll */ +enum dpll_pin_operstate operstate; +bool ntf_pending; };struct sit9531x_dpll {
@@ -56,6 +57,7 @@ int sit9531x_dpll_register(struct sit9531x_dpll *sitdpll);void sit9531x_dpll_unregister (struct sit9531x_dpll *sitdpll);void sit9531x_dpll_lock_status_baseline (struct sit9531x_dpll *sitdpll); +void sit9531x_dpll_pin_baseline (struct sit9531x_dpll_pin *pin);void sit9531x_dpll_changes_check (struct sit9531x_dpll *sitdpll);#endif /* _SIT9531X_DPLL_H */
drivers/dpll/sit9531x/prop.c +2 -0
@@ -146,6 +146,7 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev,/* INTSYNC destination: a reference the PLL can lock to. */ props->dpll_props.type =DPLL_PIN_TYPE_INT_OSCILLATOR ; props->dpll_props.capabilities = +DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; curr_freq =0 ; }else if (sync_out) {
@@ -161,6 +162,7 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev, }else if (dir ==DPLL_PIN_DIRECTION_INPUT ) { props->dpll_props.type =DPLL_PIN_TYPE_EXT ; props->dpll_props.capabilities = +DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; curr_freq = sitdev->ref[index].freq; }else {
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 08/13] dpll: sit9531x: add support to get and set priority on input pins
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The OCXO is ordered in the priority table, but its priority cannot be seen or changed, and it lives on a different scale from user…
- [Medium] sit9531x_prio_table_commit() now passes routed = sit9531x_input_hw_src(chan->routed_ref) to…
- [Low] prop.c now advertises DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE on every reference input pin and on the INTSYNC destination pin,…
--
dpll: sit9531x: add support to get and set priority on input pins
This patch adds prio_get and prio_set callbacks for sit9531x input pins. Each input keeps a priority from 0 to 255 per PLL, and a set rebuilds the hardware priority table from those values. When the best live source does not change, a table commit now latches the routed source as the active selection. The poll also compares each pin's state, operstate and priority with a baseline taken at registration and sends a notification when one changes.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 18 lines
drivers/dpll/sit9531x/core.c +7
-0@@ -745,6 +773,12 @@ static u8 sit9531x_prio_activesel_pick(struct sit9531x_dev *sitdev, top != sit9531x_prio_top_live(sitdev, old))return top; +if (sit9531x_prio_src_usable (routed) && +sit9531x_prio_src_live (sitdev, routed)) +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (srcs[i] == routed) +return routed; + cur =sit9531x_prio_src_canon (sitdev, cur &SIT9531X_PRIO_NIBBLE_MASK ); if (sit9531x_prio_src_usable(cur) &&@@ -827,12 +861,19 @@ static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_idx,if (!empty) {u8 sel =sit9531x_prio_slot_get (val, slot +1 ); +u8 routed =SIT9531X_PRIO_SRC_NONE ;
drivers/dpll/sit9531x/core.c static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_idx, · line 874
Quoted 10 lines
drivers/dpll/sit9531x/core.c +6
-0+/* +* The pick needs the signal state now, not as of the last poll; +* the routed source is the last poll's sample. +*/ rc =sit9531x_input_mon_fetch (sitdev);if (rc) goto rollback; +if (!chan->stale && chan->routed_ref !=SIT9531X_REF_INVALID ) + routed =sit9531x_input_hw_src (chan->routed_ref);
[Severity: Medium]
Is chan->routed_ref recent enough to latch here? It is only set in sit9531x_chan_state_fetch(), once per poll or after an earlier commit, and the comment above says it is the last poll's sample. Before the pick, sit9531x_input_mon_fetch() refreshes only the LOS monitors.
Take this sequence within one poll period:
poll: chan->routed_ref = B
B has a brief LOS, the device falls back to C (and does not revert) B recovers before the next pollprio_set or state_set on an unrelated input
sit9531x_prio_table_commit()
sit9531x_prio_top_live() is unchanged sit9531x_prio_activesel_pick() returns routed (B): live and listed
Would the commit then write B into CLK_ACTIVESEL and move the PLL off C, the reference it is actually tracking? That looks like the acquisition restart the commit message says this change avoids:
"A commit that leaves the best live source unchanged keeps the routed source as the active selection, so the PLL does not restart acquisition for it."
Could the routed source be sampled with sit9531x_chan_routed_ref_read() before HO_FORCE is written, and that value latched instead? sit9531x_chan_state_fetch() only reads it while the PLL is tracking and not frozen, so the cached copy can't be refreshed through that path here.
Quoted 6 lines
drivers/dpll/sit9531x/core.c +1
-1sel =sit9531x_prio_activesel_pick (sitdev, chan->prio_srcs, - srcs, sel); + srcs, sel, routed); val =sit9531x_prio_slot_set (val, slot +1 , sel); }
[ ... ]
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+int sit9531x_input_prio_set (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 input_idx,u8 prio) +{
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_prio_table_apply(struct sit9531x_dev *sitdev, u8 pll_idx, · line 1066
Quoted 5 lines
drivers/dpll/sit9531x/core.c +5
-0+ chan = &sitdev->chan[pll_idx]; + old_prio = chan->cfg_prio[input_idx]; + old_known = chan->cfg_known; + chan->cfg_prio[input_idx] = prio; + chan->cfg_known |=BIT (input_idx);
[Severity: Medium]
How does a user priority compare with the OCXO's place in the table?
sit9531x_prio_cfg_seed() sets the OCXO's configured priority from its slot index in the profile table:
drivers/dpll/sit9531x/core.c:sit9531x_prio_cfg_seed() {
...
chan->cfg_prio[src] = slot;
chan->cfg_known |= BIT(src);
...
}That value is in 0..10, but this function accepts 0..255 for the other inputs. sit9531x_prio_table_build() then sorts every member by cfg_prio, the OCXO included:
sit9531x_dpll_input_pin_prio_set()
sit9531x_input_prio_set()
sit9531x_prio_table_apply()
sit9531x_prio_table_build()Suppose a profile, or an external table rewrite that the poll accepts as configuration, lists the OCXO at slot k. Any input given a priority above k (20, 50 or 100, all normal-looking DPLL priorities) is then sorted behind the OCXO.
sit9531x_prio_src_live() always treats the OCXO as live:
if (index >= sitdev->info->num_inputs) return true;
The device also falls back down the table without reverting. Can that input ever be selected while the OCXO is listed?
Userspace also has no way to see or change the OCXO's priority, or to drop it from the table:
static const struct dpll_pin_ops sit9531x_dpll_xo_pin_ops = {
.direction_get = sit9531x_dpll_input_pin_direction_get,
.state_on_dpll_get = sit9531x_dpll_xo_pin_state_on_dpll_get,
};The xo branch in sit9531x_pin_props_get() also leaves capabilities at 0. On this point the commit message only says "The range is 0 to 255 over eleven slots".
Should the OCXO's priority be exposed, or should user priorities be mapped relative to its position?
[ ... ]
Quoted 13 lines
drivers/dpll/sit9531x/prop.c +1
-0@@ -146,6 +146,7 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev,/* INTSYNC destination: a reference the PLL can lock to. */ props->dpll_props.type =DPLL_PIN_TYPE_INT_OSCILLATOR ; props->dpll_props.capabilities = +DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; curr_freq =0 ; }else if (sync_out) {
drivers/dpll/sit9531x/prop.c sit9531x_pin_props_get(struct sit9531x_dev *sitdev, · line 168
Quoted 7 lines
drivers/dpll/sit9531x/prop.c +1
-0@@ -161,6 +162,7 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev, }else if (dir ==DPLL_PIN_DIRECTION_INPUT ) { props->dpll_props.type =DPLL_PIN_TYPE_EXT ; props->dpll_props.capabilities = +DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; curr_freq = sitdev->ref[index].freq; }else {
[Severity: Low]
Is PRIORITY_CAN_CHANGE accurate when every PLL uses manual input select?
For a manual PLL, sit9531x_dpll_pin_ops_get() returns sit9531x_dpll_input_pin_manual_ops, which has neither prio_get nor prio_set:
if (sit9531x_chan_state_get(sitdev, pin->dpll->id)->manual_input) return &sit9531x_dpll_input_pin_manual_ops;
All four PLLs share one dpll_pin per index, and capabilities are per pin. So with mixed modes the bit has to be advertised, and the DPLL core's per-ref ops checks handle the manual PLLs.
The driver reads manual_input at probe, before any pin is registered, so it knows when all four PLLs are manual. In that case the reference pins and the INTSYNC destination pin still advertise PRIORITY_CAN_CHANGE. They report no priority, and every set fails in dpll_pin_prio_set() with a bare -EOPNOTSUPP and no extack message.
Could the bit be left off when no PLL can take a priority?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 9/13 dpll: sit9531x: add support to get and set frequency on pins
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Report an input's frequency from the firmware description and an output's as the VCO rate over its output divider; set an output's frequency by writing a new divider. The VCO rate is Fref * DIVN, and a rate is accepted only when the VCO rate is a whole multiple of it. An output whose divider chain does not resolve reports 0 Hz.
A divider write takes effect only inside the programming state, and the documented settling time after the loop-lock command, about 100 ms, is waited under the device lock. The phase flush after it is enabled per PLL, so it realigns every output the PLL drives. The on-demand enable of the other PLLs is cleared for the pulse and written back after it, so only this PLL is armed when the trigger fires. A PLL whose configuration has the flush off is restarted to realign its dividers, as the reference sequence does.
Output pins are registered by the next patch, which adds the state callback the core requires.
--- drivers/dpll/sit9531x/core.c | 611 +++++++++++++++++++++++++++++++++++ drivers/dpll/sit9531x/core.h | 12 +- drivers/dpll/sit9531x/dpll.c | 120 ++++++- drivers/dpll/sit9531x/prop.c | 29 +- drivers/dpll/sit9531x/regs.h | 21 ++ 5 files changed, 785 insertions(+), 8 deletions(-)
drivers/dpll/sit9531x/core.c +611 -0
@@ -460,6 +460,101 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,return 0 ; } +#define SIT9531X_LOOP_LOCK_TRIES 3 + +/* Close the loops and lock the debug block without committing */ +static void sit9531x_prg_abort (struct sit9531x_dev *sitdev) +{ +int rc = -EIO ; +u8 attempt; + +for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) { + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_LOOP_LOCK ); +if (!rc) +break ; +usleep_range (1000 ,2000 ); + } +if (rc) +dev_err (sitdev->dev, +"output loops left unlocked after a failed entry: %d\n" , + rc); + +sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); +} + +/* +* Unlock the Page 3 debug registers and enter PRG_CMD; output-system writes +* take effect only in this state. +*/ +static int sit9531x_prg_enter (struct sit9531x_dev *sitdev) +{ +int rc; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_UNLOCK_VAL ); +if (rc) +return rc; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_PRG_CMD_STATE ); +if (rc) { +sit9531x_prg_abort (sitdev); +return rc; + } + +return 0 ; +} + +/* +* Update the NVM shadow and re-lock the loops after sit9531x_prg_enter(). The +* sleep is the settling time after loop lock. +*/ +static int sit9531x_prg_commit (struct sit9531x_dev *sitdev) +{ +int rc, rc2 =0 , rc3; +u8 attempt; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_UPDATE_NVM ); + +for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) { + rc2 =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_LOOP_LOCK ); +if (!rc2) +break ; +usleep_range (1000 ,2000 ); + } +if (rc2) +dev_err (sitdev->dev, +"output loops left unlocked after programming: %d\n" , + rc2); + + sitdev->loops_open = !!rc2; + +msleep (100 ); + +/* +* The debug key register unlocks every debug register while it holds +* the unlock value. +*/ + rc3 =sit9531x_write_close (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); + +if (rc) +return rc; +if (rc2) +return rc2; + +if (rc3) +dev_warn (sitdev->dev, +"output debug block left unlocked after programming: %d\n" , + rc3); + +return 0 ; +} +/* * Procedure: * 1. Force PLL into holdover (PLL page reg 0x6F bit 4)
@@ -1127,6 +1222,11 @@ int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx, chan->prio_mask | BIT(input_idx)); } +/* Per-slot DIVO base register offsets (6 slots per page) */ +static const u8 clkout_odr_divn_base[] = { +0x14 ,0x24 ,0x34 ,0x44 ,0x54 ,0x64 +}; +/* XO doubler register */ #define SIT9531X_REG_XO2_GENERIC SIT9531X_REG(0x00, 0x2D)#define SIT9531X_XO_DOUBLER_ENB_BIT 7/* inverted: 0 = enabled */
@@ -1139,6 +1239,504 @@ int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,#define SIT9531X_DIVO_MAX GENMASK_ULL(33, 0) +/* Register 0x2D bit 7 is active-low: 0 = doubler enabled. */ +static int sit9531x_is_xo_doubler_enabled (struct sit9531x_dev *sitdev) +{ +u8 val; +int rc; + + rc =sit9531x_read_u8 (sitdev,SIT9531X_REG_XO2_GENERIC , &val); +if (rc) +return rc; + +return (~val >>SIT9531X_XO_DOUBLER_ENB_BIT ) &1u ; +} + +/* +* DIVN in fixed point: int_part + fracn/fracd, SIT9531X_DIVN_SCALE steps per +* unit. +*/ +static s64 sit9531x_divn_fixed (u32 int_part,s64 fracn,u64 fracd) +{ +s64 whole = (s64 )int_part *SIT9531X_DIVN_SCALE ; +u64 frac; + +if (!fracd) +return whole; + + frac =mul_u64_u64_div_u64 (abs (fracn),SIT9531X_DIVN_SCALE , fracd); + +return fracn <0 ? whole - (s64 )frac : whole + (s64 )frac; +} + +/* +* Read a PLL's configured DIVN, fixed point as per sit9531x_divn_fixed(). +* Fractions are stored LSB first; the numerator is two's complement 32-bit and +* the denominator register holds the divisor minus one. +*/ +static int sit9531x_divn_static (struct sit9531x_dev *sitdev,u8 pll_idx, +s64 *divn) +{ +u32 int_part, fracn_raw =0 , fracd_raw =0 ; +u64 fracd; +s64 fracn; +int rc, i; +u8 v; + + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DIVN_INT , &v); +if (rc) +return rc; + int_part = v; + +for (i =3 ; i >=0 ; i--) { + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DIVN_NUM + i, &v); +if (rc) +return rc; + fracn_raw = (fracn_raw <<8 ) | v; + } + +for (i =3 ; i >=0 ; i--) { + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DIVN_DEN + i, &v); +if (rc) +return rc; + fracd_raw = (fracd_raw <<8 ) | v; + } + + fracn = (s32 )fracn_raw; + fracd = (u64 )fracd_raw +1 ; +if ((u64 )abs (fracn) >= fracd) +return -ENODATA ; + + *divn =sit9531x_divn_fixed (int_part, fracn, fracd); + +return 0 ; +} + +/* PLLB and PLLD run their VCO in the high band, PLLA and PLLC in the low. */ +static bool sit9531x_fvco_in_band (u8 pll_idx,u64 fvco) +{ +if (pll_idx ==1 || pll_idx ==3 ) +return fvco >=SIT9531X_FVCO_HIGHBAND_MIN && + fvco <=SIT9531X_FVCO_HIGHBAND_MAX ; +return fvco >=SIT9531X_FVCO_LOWBAND_MIN && + fvco <=SIT9531X_FVCO_LOWBAND_MAX ; +} + +/* +* Fvco = Fref * DIVN with Fref = xtal_freq << doubler; DIVN is the profile's +* steady-state value in free-run and sync modes alike. +*/ +static int sit9531x_get_fvco (struct sit9531x_dev *sitdev,u8 pll_idx, +u64 *fvco) +{ +int doubler, rc; +u64 fref; +s64 divn; + + rc =sit9531x_divn_static (sitdev, pll_idx, &divn); +if (rc) +return rc; +if (divn <=0 ) +return -ENODATA ; + + doubler =sit9531x_is_xo_doubler_enabled (sitdev); +if (doubler <0 ) +return doubler; + + fref = (u64 )sitdev->xtal_freq << doubler; + +/* +* Round to the nearest hertz; the fixed-point DIVN is already floored +* once. +*/ + *fvco =mul_u64_u64_div_u64 (2 * fref, (u64 )divn,SIT9531X_DIVN_SCALE ); + *fvco = (*fvco +1 ) /2 ; + +/* Below the low VCO band the divider is not programmed */ +if (*fvco <SIT9531X_FVCO_LOWBAND_MIN ) +return -ENODATA ; + +/* +* Outside the PLL's VCO band, Fref * DIVN is usually not the rate the +* PLL runs at, as for a PLL fed from another PLL. +*/ +if (!sit9531x_fvco_in_band (pll_idx, *fvco) && + !(sitdev->fvco_band_warned &BIT (pll_idx))) { + sitdev->fvco_band_warned |=BIT (pll_idx); +dev_warn (sitdev->dev, +"PLL%c: Fref * DIVN = %llu Hz is outside its VCO band\n" , +'A' + pll_idx, *fvco); + } + +return 0 ; +} + +static int sit9531x_pll_small_update (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +return sit9531x_write_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_SMALL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +} + +/* +* Realign the PLL's output dividers with the on-demand phase flush (PHFL), or +* restart the PLL when its profile has PHFL off (PLL page 0x47 bit 7 clear), as +* Dely_program_output.py does. Without either, a rewritten DIVO keeps a fixed +* edge offset. Caller must hold sitdev->multiop_lock. +*/ +static int sit9531x_output_phase_flush (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +u8 ctrl, orig, phfl, armed_mask =0 , parked =0 , i; +int rc, ret; + + rc =sit9531x_read_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_CONFIG47 , + &phfl); +if (rc) +return rc; +if (!(phfl &SIT9531X_PLL_CONFIG47_PHFL_EN )) +return sit9531x_write_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DIRECTIVES , +SIT9531X_PLL_DIRECTIVE_RESTART ); + +/* Only the target PLL keeps on-demand flush enabled for the pulse. */ +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { + rc =sit9531x_read_pll_u8 (sitdev, i,SIT9531X_PLL_REG_PHFL_CTRL , + &phfl); +if (rc) +return rc; +if (phfl &SIT9531X_PLL_PHFL_ON_DEMAND_EN ) + armed_mask |=BIT (i); + } + +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +if (i == pll_idx || !(armed_mask &BIT (i))) +continue ; + parked |=BIT (i); + rc =sit9531x_update_pll_u8 (sitdev, i, +SIT9531X_PLL_REG_PHFL_CTRL , +SIT9531X_PLL_PHFL_ON_DEMAND_EN ,0 ); +if (rc) + goto unpark; + rc =sit9531x_pll_small_update (sitdev, i); +if (rc) + goto unpark; + } + + rc =sit9531x_update_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_PHFL_CTRL , +SIT9531X_PLL_PHFL_ON_DEMAND_EN , +SIT9531X_PLL_PHFL_ON_DEMAND_EN ); +if (rc) + goto disarm; + +/* +* Write the update register whole; a read-modify-write skips the write +* while the bit still reads set from the previous command. +*/ + rc =sit9531x_pll_small_update (sitdev, pll_idx); +if (rc) + goto disarm; + +/* +* Select the in-register phase trigger; the register also holds the OEb +* bits. +*/ + rc =sit9531x_read_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , &ctrl); +if (rc) + goto disarm; + + orig = ctrl & ~SIT9531X_DIVO_PHASE_TRIG ; + ctrl = orig |SIT9531X_DIVO_PHASE_SEL_REG ; + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl); +if (rc) + goto restore; + +/* +* No delay between set and clear; one I2C transfer is longer than the +* minimum pulse width. +*/ + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , + ctrl |SIT9531X_DIVO_PHASE_TRIG ); + +restore: + ret =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , orig); +if (ret && !rc) + rc = ret; + +disarm: +/* +* Restore the profile's flush enable; an armed flush re-flushes every +* output divider of this PLL on the next trigger. +*/ +if (!(armed_mask &BIT (pll_idx))) { + ret =sit9531x_update_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_PHFL_CTRL , +SIT9531X_PLL_PHFL_ON_DEMAND_EN ,0 ); +if (!ret) + ret =sit9531x_pll_small_update (sitdev, pll_idx); +if (ret && !rc) + rc = ret; + } + +unpark: +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +if (!(parked &BIT (i))) +continue ; + ret =sit9531x_update_pll_u8 (sitdev, i, +SIT9531X_PLL_REG_PHFL_CTRL , +SIT9531X_PLL_PHFL_ON_DEMAND_EN , +SIT9531X_PLL_PHFL_ON_DEMAND_EN ); +if (!ret) + ret =sit9531x_pll_small_update (sitdev, i); +if (ret && !rc) + rc = ret; + } + +return rc; +} + +/* +* Compute an output's divider and VCO rate; call before entering the +* programming state. +*/ +static int sit9531x_output_divo_calc (struct sit9531x_dev *sitdev,u8 out_idx, +u8 pll_idx,u64 frequency,u64 *fvco_out, +u64 *divo_out) +{ +const struct sit9531x_chip_info *info = sitdev->info; +u64 fvco, divo, nearest, rem; +int rc; + +if (out_idx >= info->num_outputs || pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + +/* An unrouted output has a placeholder in pll_idx. */ +if (!sitdev->out[out_idx].routed) +return -ENODEV ; + +if (!frequency) +return -EINVAL ; + +if (frequency >U32_MAX ) +return -EINVAL ; + + rc =sit9531x_get_fvco (sitdev, pll_idx, &fvco); +if (rc) +return rc == -ENODATA ? -ENODEV : rc; + +if (!sit9531x_fvco_in_band (pll_idx, fvco)) { +dev_dbg (sitdev->dev, +"out%u: PLL%c Fvco %llu Hz is outside its VCO band, rate not settable\n" , + out_idx,'A' + pll_idx, fvco); +return -EINVAL ; + } + + divo =div64_u64 (fvco + frequency /2 , frequency); +if (!divo) +return -EINVAL ; + +if (divo >SIT9531X_DIVO_MAX ) +return -EINVAL ; + +/* +* Refuse a rate that is not exactly Fvco/N; the quotient truncates to +* the request whenever the remainder is below N. +*/ + nearest =div64_u64_rem (fvco, divo, &rem); +if (nearest != frequency || rem) { +dev_dbg (sitdev->dev, +"out%u: %llu Hz is not Fvco/N (Fvco=%llu, nearest %llu Hz)\n" , + out_idx, frequency, fvco, nearest); +return -EINVAL ; + } + +dev_dbg (sitdev->dev,"out%u: Fvco=%llu freq=%llu DIVO=%llu\n" , + out_idx, fvco, frequency, divo); + + *fvco_out = fvco; + *divo_out = divo; + +return 0 ; +} + +/* +* Caller must be in the programming state; @back reports whether the divider +* holds its old value. +*/ +static int sit9531x_output_divo_write (struct sit9531x_dev *sitdev,u8 out_idx, +u64 divo,bool *back) +{ +u8 slot, page, base_reg, divo_bytes[5 ], old_bytes[5 ], msb_old; +const struct sit9531x_chip_info *info = sitdev->info; +int rc, j, rb_rc; +u8 written =0 ; + + *back = false; + + slot = info->clkout_map[out_idx]; + +if (slot >SIT9531X_PAGE_OUTSYS0_SLOT_MAX ) + page =SIT9531X_PAGE_OUTSYS1 ; +else + page =SIT9531X_PAGE_OUTSYS0 ; + base_reg = clkout_odr_divn_base[slot %6 ]; + + divo_bytes[0 ] = (divo >>0 ) &0xFF ; + divo_bytes[1 ] = (divo >>8 ) &0xFF ; + divo_bytes[2 ] = (divo >>16 ) &0xFF ; + divo_bytes[3 ] = (divo >>24 ) &0xFF ; + divo_bytes[4 ] = (divo >>32 ) &0x03 ;/* only bits [1:0] */ + +for (j =0 ; j <5 ; j++) { + rc =sit9531x_read_u8 (sitdev, +SIT9531X_REG (page, base_reg - j), + &old_bytes[j]); +if (rc) +return rc; + } + + msb_old = old_bytes[4 ]; + divo_bytes[4 ] |= msb_old &0xFC ; + +for (j =0 ; j <5 ; j++) { + rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (page, base_reg - j), + divo_bytes[j]); +if (rc) + goto rollback; + written++; + } + +return 0 ; + +rollback: +/* The byte whose write failed may have reached the part */ + *back = true; +for (j =0 ; j <= written && j <5 ; j++) { + rb_rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (page, base_reg - j), + old_bytes[j]); +if (rb_rc) { + *back = false; +dev_err (sitdev->dev, +"out%u: DIVO rollback failed (%d), the divider is part old and part new\n" , + out_idx, rb_rc); +if (!rc) + rc = rb_rc; + } + } + +return rc; +} + +static int sit9531x_output_divo_read (struct sit9531x_dev *sitdev,u8 out_idx, +u64 *divo) +{ +u8 slot, page, base_reg, v; +int rc, j; + + slot = sitdev->info->clkout_map[out_idx]; +if (slot >SIT9531X_PAGE_OUTSYS0_SLOT_MAX ) + page =SIT9531X_PAGE_OUTSYS1 ; +else + page =SIT9531X_PAGE_OUTSYS0 ; + base_reg = clkout_odr_divn_base[slot %6 ]; + + *divo =0 ; +for (j =4 ; j >=0 ; j--) { + rc =sit9531x_read_u8 (sitdev, +SIT9531X_REG (page, base_reg - j), &v); +if (rc) +return rc; +if (j ==4 ) + v &=0x03 ; + *divo = (*divo <<8 ) | v; + } + +return *divo ?0 : -ENODATA ; +} + +int sit9531x_output_freq_set (struct sit9531x_dev *sitdev,u8 out_idx, +u8 pll_idx,u64 frequency) +{ +u64 fvco, divo; +int rc, ret; +bool back; + +lockdep_assert_held (&sitdev->multiop_lock); + + rc =sit9531x_output_divo_calc (sitdev, out_idx, pll_idx, frequency, + &fvco, &divo); +if (rc) +return rc; + + rc =sit9531x_prg_enter (sitdev); +if (rc) +return rc; + + rc =sit9531x_output_divo_write (sitdev, out_idx, divo, &back); +/* NVM update and loop lock */ + ret =sit9531x_prg_commit (sitdev); +if (ret && !rc) + rc = ret; +if (rc) +return rc; + +/* Flush the output phase so the new DIVO starts aligned */ + rc =sit9531x_output_phase_flush (sitdev, pll_idx); +if (rc) { +dev_warn (sitdev->dev, +"out%u: rate changed but the divider phase was not realigned (%d)\n" , + out_idx, rc); + rc =0 ; + } + + sitdev->out[out_idx].freq =div64_u64 (fvco, divo); + +return 0 ; +} + +/* +* Read the output rate back as Fvco / DIVO and refresh the cached rate. Caller +* must hold sitdev->multiop_lock. +*/ +int sit9531x_output_freq_get (struct sit9531x_dev *sitdev,u8 out_idx, +u64 *frequency) +{ +const struct sit9531x_chip_info *info = sitdev->info; +u64 fvco, divo; +u8 pll_idx; +int rc; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (out_idx >= info->num_outputs) +return -EINVAL ; + + pll_idx = sitdev->out[out_idx].pll_idx; +if (pll_idx >=SIT9531X_NUM_PLLS || !sitdev->out[out_idx].routed) { + sitdev->out[out_idx].freq =0 ; +return -ENODATA ; + } + + rc =sit9531x_get_fvco (sitdev, pll_idx, &fvco); +if (!rc) + rc =sit9531x_output_divo_read (sitdev, out_idx, &divo); +if (rc) { +if (rc == -ENODATA ) + sitdev->out[out_idx].freq =0 ; +return rc; + } + + *frequency =div64_u64 (fvco, divo); + sitdev->out[out_idx].freq = *frequency; + +return 0 ; +} +/* * Phase adjust: per-output 34-bit coarse delay in VCO periods plus a 3-bit * fine delay in 30 ps steps, in PROG6..PROG2:
@@ -1845,6 +2443,10 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)bool answered = false;int i, rc; +/* Retry pending writes first so the reads below see their result */ +if (sitdev->loops_open) +sit9531x_prg_commit (sitdev); +sit9531x_input_off_retry (sitdev);for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {sit9531x_table_back_retry (sitdev, i);
@@ -2167,6 +2769,15 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev) "PLL%c left in forced holdover\n", 'A' + i); }mutex_unlock (&sitdev->multiop_lock); + +mutex_lock (&sitdev->multiop_lock); +if (sitdev->loops_open) { +sit9531x_prg_commit (sitdev); +if (sitdev->loops_open) +dev_warn (sitdev->dev, +"output loops left unlocked at removal\n" ); + } +mutex_unlock (&sitdev->multiop_lock); } static struct sit9531x_dpll_pin *
drivers/dpll/sit9531x/core.h +10 -2
@@ -203,19 +203,21 @@ struct sit9531x_chan {* @irq: optional INTRB IRQ, 0 if not wired * @intsync_src: PLL sourcing INTSYNC, or -1 * @irq_ack_fails: consecutive failed INTRB acknowledgements +* @fvco_band_warned: bit per PLL warned for Fref * DIVN outside its VCO +* band; written under @multiop_lock +* @loops_open: output loops not yet re-locked */ struct sit9531x_dev {struct device *dev;struct i2c_client *client;struct regmap *regmap;const struct sit9531x_chip_info *info; -/* Serializes multi-step register sequences */ struct mutex multiop_lock; -/* Serializes a page select and the transfer it is for */ struct mutex page_lock;int page;u8 irq_ack_fails; +u8 fvco_band_warned;struct sit9531x_ref ref[SIT9531X_MAX_INPUTS +1 ];/* +1 for xtal */ struct sit9531x_out out[SIT9531X_MAX_OUTPUTS ];struct sit9531x_chan chan[SIT9531X_NUM_PLLS ];
@@ -234,6 +236,7 @@ struct sit9531x_dev {s8 intsync_src; +bool loops_open; }; int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
@@ -261,6 +264,11 @@ int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,int sit9531x_input_prio_add (struct sit9531x_dev *sitdev,u8 pll_idx,u8 input_idx); +int sit9531x_output_freq_set (struct sit9531x_dev *sitdev,u8 out_idx, +u8 pll_idx,u64 frequency); +int sit9531x_output_freq_get (struct sit9531x_dev *sitdev,u8 out_idx, +u64 *frequency); +static inline u8 sit9531x_pll_page (u8 pll_idx) {return SIT9531X_PAGE_PLLA + pll_idx;
drivers/dpll/sit9531x/dpll.c +117 -3
164 lines not on this page · raw message
drivers/dpll/sit9531x/prop.c +26 -3
@@ -233,7 +233,10 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev, goto err_alloc_ranges; } -/* The first listed rate seeds the input's rate */ +/* +* The driver does not read an input's rate; the first listed rate seeds +* it. +*/ if (num_freqs >0 && dir ==DPLL_PIN_DIRECTION_INPUT && !xo) curr_freq = freqs[0 ];
@@ -241,6 +244,22 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev,if (sync_in || sync_out)return props; +/* +* Read the divider once so a bus fault fails the probe and the cached +* rate starts at the running one; -ENODATA is an unprogrammed divider +* or unknown VCO rate. +*/ +if (dir ==DPLL_PIN_DIRECTION_OUTPUT && + index < sitdev->info->num_outputs) { +u64 hw_freq; + +mutex_lock (&sitdev->multiop_lock); + rc =sit9531x_output_freq_get (sitdev, index, &hw_freq); +mutex_unlock (&sitdev->multiop_lock); +if (rc && rc != -ENODATA ) + goto err_alloc_ranges; + } +/* * An output with no listed rates gets one wide range, as the setter * checks Fvco/N; the XO gets its one rate.
@@ -251,8 +270,12 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev, goto err_alloc_ranges; } -/* Set after the last allocation that can fail */ -if (curr_freq && dir ==DPLL_PIN_DIRECTION_INPUT ) +/* +* Set after the last allocation that can fail, and only once, as pins +* of other DPLLs on this input may already be published. +*/ +if (curr_freq && dir ==DPLL_PIN_DIRECTION_INPUT && + !sitdev->ref[index].freq) sitdev->ref[index].freq = curr_freq; j =0 ;
drivers/dpll/sit9531x/regs.h +21 -0
@@ -156,6 +156,7 @@/* Debug register (same offset, per-page) */ #define SIT9531X_REG_OUTSYS_DEBUG SIT9531X_REG(0x03, 0xBD)#define SIT9531X_DEBUG_UNLOCK_VAL 0xC3 +#define SIT9531X_DEBUG_LOCK_VAL 0x00/* * Register-triggered phase flush: DIVO_PHASE_SEL_REG selects the register
@@ -169,6 +170,18 @@/* PLL page register offsets, pages 0x0A-0x0D */ #define SIT9531X_PLL_REG_SMALL_UPDATE 0x0F +/* On-demand phase-flush enable (PLL page reg 0x3D bit 7) */ +#define SIT9531X_PLL_REG_PHFL_CTRL 0x3D +#define SIT9531X_PLL_PHFL_ON_DEMAND_EN BIT(7) + +/* Whether the PLL has the phase-flush feature (PLL page reg 0x47 bit 7) */ +#define SIT9531X_PLL_REG_CONFIG47 0x47 +#define SIT9531X_PLL_CONFIG47_PHFL_EN BIT(7) + +/* Directives_GENERIC_PLL: the restart bit restarts the PLL, self-clearing */ +#define SIT9531X_PLL_REG_DIRECTIVES 0x05 +#define SIT9531X_PLL_DIRECTIVE_RESTART BIT(0) +/* * PLL page regs 0x10-0x15 hold the loop-filter coefficients (3 normal, 3 * fast-lock); they are GUI generated and must not be changed at runtime.
@@ -182,6 +195,14 @@#define SIT9531X_PLL_REG_OUT_MAP_LO 0x28#define SIT9531X_PLL_REG_STATUS 0x31 +/* DIVN registers (free-run divider readback) */ +#define SIT9531X_PLL_REG_DIVN_INT 0x30 +#define SIT9531X_PLL_REG_DIVN_NUM 0x32/* 4 bytes (0x32-0x35) */ +#define SIT9531X_PLL_REG_DIVN_DEN 0x38/* 4 bytes (0x38-0x3B) */ + +/* DIVN is carried as fixed point, in steps of 1e-12 of a whole divider */ +#define SIT9531X_DIVN_SCALE 1000000000000ULL +#define SIT9531X_PLL_REG_ACTIVE 0x02#define SIT9531X_PLL_ACTIVE_BIT BIT(0)/* PLL reached active state */
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 09/13] dpll: sit9531x: add support to get and set frequency on pins
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] dpll: sit9531x: unretried NVM update in sit9531x_prg_commit() on error --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] dpll: sit9531x: unretried NVM update in sit9531x_prg_commit() on error
--
commit 94b9cfbb99f072a3656d39c3238bca0469693ed3
Author: Oleg Zadorozhnyi <[email protected]>
dpll: sit9531x: add support to get and set frequency on pins
This commit adds DPLL pin frequency get and set callbacks for the SiT9531x driver, reporting input rates from firmware properties and reading or programming output rates through the VCO and output divider registers.
Quoted 8 lines
drivers/dpll/sit9531x/core.c +0
-0@@ -460,6 +460,101 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,return 0 ; }
[ ... ]
Quoted 15 lines
drivers/dpll/sit9531x/core.c +15
-0+/* +* Update the NVM shadow and re-lock the loops after sit9531x_prg_enter(). The +* sleep is the settling time after loop lock. +*/ +static int sit9531x_prg_commit (struct sit9531x_dev *sitdev) +{ +int rc, rc2 =0 , rc3; +u8 attempt; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_UPDATE_NVM ); + +for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) { + rc2 =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_LOOP_LOCK );
drivers/dpll/sit9531x/core.c static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev, · line 534
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+if (!rc2) +break ; +usleep_range (1000 ,2000 ); + } +if (rc2) +dev_err (sitdev->dev, +"output loops left unlocked after programming: %d\n" , + rc2); + + sitdev->loops_open = !!rc2;
[Severity: Medium]
As reported by Jakub Kicinski on v15 [1], what happens when sit9531x_output_divo_write() writes the new divider bytes, but the SIT9531X_UPDATE_NVM write in sit9531x_prg_commit() fails while SIT9531X_LOOP_LOCK succeeds?
In that case sitdev->loops_open is set to false, so the background poll never retries sit9531x_prg_commit(), and the new DIVO register values are neither rolled back nor committed to the NVM shadow. On the error path in sit9531x_dpll_output_pin_frequency_set(), sit9531x_output_freq_get() then reads back those uncommitted DIVO register bytes, updates sitdev->out[out_idx].freq, and sends a pin change notification for a frequency that was never committed in hardware.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
[email protected]
AI reviewRe: [PATCH net-next v16 09/13] dpll: sit9531x: add support to get and set frequency on pins
In reply to Ali RouhiThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 5 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The output frequency getter reports Fvco/DIVO even when the driver itself says that Fvco is not the PLL's real rate.
- [Medium] The loops_open retry sends the loop-lock command with the Page 3 debug key locked.
- [Medium] The reported output frequency can fall outside the frequency range the pin advertises.
- [Medium] In sit9531x_output_phase_flush(), the register-triggered phase flush is documented in regs.h as 'DIVO_PHASE_SEL_REG selects the…
- [Medium] dpll: sit9531x: unretried NVM update in sit9531x_prg_commit() on error
- [Low] The patch deletes the inline comments on struct sit9531x_dev's two mutexes ('/* Serializes multi-step register sequences */' above…
--
dpll: sit9531x: add support to get and set frequency on pins
This patch reports an input pin's frequency from the firmware description and an output pin's frequency as Fvco / DIVO. It sets an output's frequency by writing a new DIVO inside the programming state. The write is followed by a loop lock, a settling delay and a per-PLL phase flush.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0@@ -1139,6 +1239,504 @@ int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,#define SIT9531X_DIVO_MAX GENMASK_ULL(33, 0)
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +4
-0+/* +* Outside the PLL's VCO band, Fref * DIVN is usually not the rate the +* PLL runs at, as for a PLL fed from another PLL. +*/
drivers/dpll/sit9531x/core.c int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx, · line 1375
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+if (!sit9531x_fvco_in_band (pll_idx, *fvco) && + !(sitdev->fvco_band_warned &BIT (pll_idx))) { + sitdev->fvco_band_warned |=BIT (pll_idx); +dev_warn (sitdev->dev, +"PLL%c: Fref * DIVN = %llu Hz is outside its VCO band\n" , +'A' + pll_idx, *fvco); + } + +return 0 ; +}
[Severity: Medium]
If Fref * DIVN is above the low-band minimum but outside this PLL's own band, sit9531x_get_fvco() warns once and still returns 0. The comment above says such a value is usually not the rate the PLL runs at.
For that PLL, sit9531x_output_freq_get() then reports and caches div64_u64(fvco, divo). sit9531x_output_divo_calc() rejects the same Fvco:
if (!sit9531x_fvco_in_band(pll_idx, fvco)) {
dev_dbg(sitdev->dev,
"out%u: PLL%c Fvco %llu Hz is outside its VCO band, rate not settable\n",
...
return -EINVAL;
}So would a cascaded PLL report a nonzero DPLL_A_PIN_FREQUENCY that the driver itself treats as wrong?
The commit message says "An output whose divider chain does not resolve reports 0 Hz". Should sit9531x_output_freq_get() apply the same band check and return -ENODATA?
The later patch "dpll: sit9531x: add support to adjust output phase" adds the comment "Fref * DIVN outside the VCO band is not the rate the PLL runs at" in sit9531x_output_phase_adjust_set(). Even so, sit9531x_output_freq_get() still has no band check at the end of the series.
[ ... ]
Quoted 7 lines
drivers/dpll/sit9531x/core.c +7
-0+ orig = ctrl & ~SIT9531X_DIVO_PHASE_TRIG ; + ctrl = orig |SIT9531X_DIVO_PHASE_SEL_REG ; + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl); +if (rc) + goto restore; + +/*
drivers/dpll/sit9531x/core.c int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx, · line 1467
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+* No delay between set and clear; one I2C transfer is longer than the +* minimum pulse width. +*/ + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , + ctrl |SIT9531X_DIVO_PHASE_TRIG ); + +restore: + ret =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , orig); +if (ret && !rc) + rc = ret;
[Severity: Medium]regs.h describes the flush as "DIVO_PHASE_SEL_REG selects the register trigger; pulsing DIVO_PHASE_TRIG high then low flushes".
Here, the final write of orig clears DIVO_PHASE_TRIG and restores DIVO_PHASE_SEL_REG in the same transfer. Suppose the profile had the pin trigger selected, so SEL_REG is clear in orig. Then the register trigger's high-to-low transition happens at the same moment the mux switches back to the external pin.
If the flush acts on the falling edge, can the flush be missed while sit9531x_output_freq_set() still reports success? Would it help to write ctrl (SEL_REG set, TRIG clear) before restoring orig?
The same ordering is still there at the end of the series in sit9531x_phase_flush_undo(), which writes the original ctrl straight after the TRIG-high write.
[ ... ]
drivers/dpll/sit9531x/core.c int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx, · line 1735
Quoted 11 lines
drivers/dpll/sit9531x/core.c +11
-0+ rc =sit9531x_get_fvco (sitdev, pll_idx, &fvco); +if (!rc) + rc =sit9531x_output_divo_read (sitdev, out_idx, &divo); +if (rc) { +if (rc == -ENODATA ) + sitdev->out[out_idx].freq =0 ; +return rc; + } + + *frequency =div64_u64 (fvco, divo); + sitdev->out[out_idx].freq = *frequency;
[Severity: Medium]
Suppose the UPDATE_NVM write fails here but one of the LOOP_LOCK attempts that follow succeeds. sitdev->loops_open then ends up false, and nothing records that the bank update was never issued. Neither the retry in sit9531x_dev_chan_states_update() nor the one in sit9531x_dev_stop() will run, since both key on loops_open.
sit9531x_output_freq_set() returns the error, but the five DIVO bytes from sit9531x_output_divo_write() stay in the registers. The back flag that sit9531x_output_divo_write() fills in is never checked.
On that error, sit9531x_dpll_output_pin_frequency_set() calls sit9531x_output_freq_get(). That reads the new DIVO bytes back through sit9531x_output_divo_read() and caches Fvco / DIVO in sitdev->out[].freq. If the result differs from the old value, the setter then sends __dpll_pin_change_ntf().
If the divider only takes effect once UPDATE_NVM is written, user space gets an error together with a notification for a rate the part is not running. The cached freq follows the uncommitted register contents rather than the hardware.
Should a failed UPDATE_NVM be tracked as pending and retried by the poll worker? Or should sit9531x_output_freq_set() restore the old DIVO bytes before it closes the programming state?
At the end of the series the retry path is sit9531x_prg_relock(), which does not repeat the bank update either.
[Severity: Medium]
Can this value fall outside the range the pin advertises? For an output without supported-frequencies-hz, sit9531x_pin_props_get() advertises:
ranges[j].min = 1; ranges[j].max = 1000000000ULL; /* 1 GHz */
Fvco is at least SIT9531X_FVCO_LOWBAND_MIN (4.9152 GHz). A profile with DIVO of 4 or less therefore gives a reported frequency above 1 GHz. When there is a DT list, the truncated Fvco / DIVO also need not match any listed value.
dpll_pin_freq_set() in the core calls dpll_pin_is_freq_supported() before its freq == old_freq shortcut. Writing back the value just read would then fail with "frequency is not supported by the device". Is that intended?
The 1 GHz cap is unchanged at the end of the series.
[ ... ]
drivers/dpll/sit9531x/core.c sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev) · line 2450
Quoted 9 lines
drivers/dpll/sit9531x/core.c +4
-0@@ -1845,6 +2443,10 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)bool answered = false;int i, rc; +/* Retry pending writes first so the reads below see their result */ +if (sitdev->loops_open) +sit9531x_prg_commit (sitdev); +sit9531x_input_off_retry (sitdev);
[Severity: Medium]
Does this retry run with the Page 3 debug key locked?
When every LOOP_LOCK attempt fails, sit9531x_prg_commit() sets loops_open but still relocks the key at the end:
sitdev->loops_open = !!rc2; msleep(100); ... rc3 = sit9531x_write_close(sitdev, SIT9531X_REG_OUTSYS_DEBUG, SIT9531X_DEBUG_LOCK_VAL);
This retry calls sit9531x_prg_commit() directly, and so does the one in sit9531x_dev_stop(). Neither does the unlock that sit9531x_prg_enter() performs before every other PRG_DIR_GEN write:
rc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG, SIT9531X_DEBUG_UNLOCK_VAL);
If PRG_DIR_GEN commands only take effect while the key is unlocked, the LOOP_LOCK write would be ACKed but have no effect, and loops_open would be cleared anyway. sit9531x_dev_stop() would then skip its "output loops left unlocked at removal" warning, and later readers of loops_open would treat the loops as closed.
This retry also sends UPDATE_NVM again, outside the PRG_CMD sequence.
The later patch "dpll: sit9531x: implement output pin state on a DPLL" changes the retry to sit9531x_prg_relock(), which drops the UPDATE_NVM. It still writes LOOP_LOCK without opening the debug window, though.
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.h +0
-0
[ ... ]
drivers/dpll/sit9531x/core.h struct sit9531x_chan { · line 216
Quoted 9 lines
struct
sit9531x_dev{drivers/dpll/sit9531x/core.h +0
-2struct device *dev;struct i2c_client *client;struct regmap *regmap;const struct sit9531x_chip_info *info; -/* Serializes multi-step register sequences */ struct mutex multiop_lock; -/* Serializes a page select and the transfer it is for */ struct mutex page_lock;
[Severity: Low]
This isn't a bug, but removing these two comments looks unrelated to frequency get/set, and the commit message doesn't mention it.
The block comment above the struct is not kernel-doc, so checkpatch --strict will report "struct mutex definition without comment" for both locks. The comments are still missing at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 10/13 dpll: sit9531x: implement output pin state on a DPLL
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
An output's state says whether it carries a signal: CONNECTED while it drives, DISCONNECTED while muted. Setting it forces the output's pads to Hi-Z, which leaves the divider alone. Output pins are registered from this patch on.
A mute forces the slot's three Hi-Z pairs, differential, CMOS OutP and CMOS OutN, with the Page 3 debug window open; the force registers are outside the NVM, so no programming directive is written. An un-mute releases the force and the pads return to the loaded configuration. An output is reported muted only when both pads are forced off.
--- drivers/dpll/sit9531x/core.c | 313 +++++++++++++++++++++++++++++------ drivers/dpll/sit9531x/core.h | 15 ++ drivers/dpll/sit9531x/dpll.c | 142 +++++++++++++++- 3 files changed, 415 insertions(+), 55 deletions(-)
drivers/dpll/sit9531x/core.c +263 -50
@@ -460,12 +460,78 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,return 0 ; } +/* Re-read an output's mute state. Caller must hold sitdev->multiop_lock. */ +int sit9531x_output_state_refresh (struct sit9531x_dev *sitdev,u8 out_idx) +{ +bool muted, part; +int rc; + +lockdep_assert_held (&sitdev->multiop_lock); + + rc =sit9531x_output_forced_hiz (sitdev, out_idx, &muted, &part); +if (rc) +return rc; + + sitdev->out[out_idx].enabled = !muted; + sitdev->out[out_idx].part_muted = part; + sitdev->out[out_idx].state_stale = false; + +return 0 ; +} + +static int sit9531x_hiz_set_bit (struct sit9531x_dev *sitdev, +unsigned int reg,u8 bit,bool set) +{ +u8 cur, new_val; +int rc; + + rc =sit9531x_read_u8 (sitdev, reg, &cur); +if (rc) +return rc; + + new_val = set ? (cur |BIT (bit)) : (cur & ~BIT (bit)); + +return sit9531x_write_u8 (sitdev, reg, new_val); +} + +/* +* The Page 3 debug key opens every debug register of the output system while +* it holds the unlock value. +*/ +static int sit9531x_outsys_debug_open (struct sit9531x_dev *sitdev) +{ +int rc; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_UNLOCK_VAL ); +if (rc) +sit9531x_write_close (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); + +return rc; +} + +static void sit9531x_outsys_debug_close (struct sit9531x_dev *sitdev) +{ +int rc; + + rc =sit9531x_write_close (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); + sitdev->outsys_key_pending = !!rc; +if (rc) +dev_warn (sitdev->dev,"output debug block left unlocked: %d\n" , + rc); +} +#define SIT9531X_LOOP_LOCK_TRIES 3 -/* Close the loops and lock the debug block without committing */ -static void sit9531x_prg_abort (struct sit9531x_dev *sitdev) +/* +* Leave PRG_CMD: re-lock the loops and close the debug window. The sleep is +* the settling time after loop lock. +*/ +static int sit9531x_prg_relock (struct sit9531x_dev *sitdev) { -int rc = -EIO ; +int rc =0 ;u8 attempt;for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) {
@@ -477,30 +543,49 @@ static void sit9531x_prg_abort(struct sit9531x_dev *sitdev) }if (rc)dev_err (sitdev->dev, -"output loops left unlocked after a failed entry: %d\n" , +"output loops left unlocked after programming: %d\n" , rc); -sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_LOCK_VAL ); + sitdev->loops_open = !!rc; + +msleep (100 ); + +sit9531x_outsys_debug_close (sitdev); + +return rc; }/* -* Unlock the Page 3 debug registers and enter PRG_CMD; output-system writes -* take effect only in this state. +* Update the NVM bank and leave PRG_CMD. The bank update is issued once per +* programming sequence; a loop re-lock retried later does not repeat it. +*/ +static int sit9531x_prg_commit (struct sit9531x_dev *sitdev) +{ +int rc, rc2; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_UPDATE_NVM ); + rc2 =sit9531x_prg_relock (sitdev); + +return rc ? rc : rc2; +} + +/* +* Open the Page 3 debug window and enter PRG_CMD; the output divider takes +* effect only in this state. */ static int sit9531x_prg_enter (struct sit9531x_dev *sitdev) {int rc; - rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_UNLOCK_VAL ); + rc =sit9531x_outsys_debug_open (sitdev);if (rc)return rc; rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN ,SIT9531X_PRG_CMD_STATE );if (rc) { -sit9531x_prg_abort (sitdev); +sit9531x_prg_relock (sitdev);return rc; }
@@ -508,51 +593,144 @@ static int sit9531x_prg_enter(struct sit9531x_dev *sitdev) }/* -* Update the NVM shadow and re-lock the loops after sit9531x_prg_enter(). The -* sleep is the settling time after loop lock. +* Mute or unmute every Hi-Z pair of a slot. The force registers are outside +* the NVM, so no directive is written, as in Output_Disable_Control_HiZ.py. +* Caller must hold the debug window open. */ -static int sit9531x_prg_commit (struct sit9531x_dev *sitdev) +static int sit9531x_output_hiz_write (struct sit9531x_dev *sitdev,u8 slot, +bool mute,u8 keep) { -int rc, rc2 =0 , rc3; -u8 attempt; +u8 mask[SIT9531X_HIZ_PAIRS ], state[SIT9531X_HIZ_PAIRS ]; +struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS ]; +int i, rc, undo_rc; - rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , -SIT9531X_UPDATE_NVM ); +sit9531x_output_get_hiz_regs (slot, p); -for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) { - rc2 =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , -SIT9531X_LOOP_LOCK ); -if (!rc2) -break ; -usleep_range (1000 ,2000 ); +if (!mute) { +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { +/* A pad the loaded configuration forces stays forced */ +if (keep &BIT (i)) +continue ; + rc =sit9531x_hiz_set_bit (sitdev, p[i].mask, p[i].bit, + false); +if (rc) +return rc; + } +return 0 ; } -if (rc2) -dev_err (sitdev->dev, -"output loops left unlocked after programming: %d\n" , - rc2); - sitdev->loops_open = !!rc2; - -msleep (100 ); +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { + rc =sit9531x_read_u8 (sitdev, p[i].state, &state[i]); +if (rc) +return rc; + rc =sit9531x_read_u8 (sitdev, p[i].mask, &mask[i]); +if (rc) +return rc; + }/* -* The debug key register unlocks every debug register while it holds -* the unlock value. +* STATE before MASK: enabling the override first can drive the pad for +* one I2C transfer. */ - rc3 =sit9531x_write_close (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_LOCK_VAL ); +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { + rc =sit9531x_hiz_set_bit (sitdev, p[i].state, p[i].bit, false); +if (!rc) + rc =sit9531x_hiz_set_bit (sitdev, p[i].mask, p[i].bit, + true); +if (rc) +break ; + } +if (!rc) +return 0 ; +for (; i >=0 ; i--) { +u8 bit =BIT (p[i].bit); + + undo_rc =sit9531x_hiz_set_bit (sitdev, p[i].mask, p[i].bit, + mask[i] & bit); +if (!undo_rc) + undo_rc =sit9531x_hiz_set_bit (sitdev, p[i].state, + p[i].bit, + state[i] & bit); +if (undo_rc) +dev_err (sitdev->dev, +"slot%u: Hi-Z override left part applied (%d)\n" , + slot, undo_rc); + } + +return rc; +} + +/* Caller must hold sitdev->multiop_lock. */ +int sit9531x_output_disable (struct sit9531x_dev *sitdev,u8 index) +{ +const struct sit9531x_chip_info *info = sitdev->info; +int rc, state_rc; +bool muted, part; +u8 slot; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (index >= info->num_outputs) +return -EINVAL ; + + slot = info->clkout_map[index]; + rc =sit9531x_outsys_debug_open (sitdev);if (rc)return rc; -if (rc2) -return rc2; -if (rc3) -dev_warn (sitdev->dev, -"output debug block left unlocked after programming: %d\n" , - rc3); + rc =sit9531x_output_hiz_write (sitdev, slot, true,0 ); +sit9531x_outsys_debug_close (sitdev); -return 0 ; +/* Read back the Hi-Z state */ + state_rc =sit9531x_output_forced_hiz (sitdev, index, &muted, &part); +if (!state_rc) { + sitdev->out[index].enabled = !muted; + sitdev->out[index].part_muted = part; + sitdev->out[index].state_stale = false; + }else { + sitdev->out[index].state_stale = true; +if (!rc) + rc = state_rc; + } + +return rc; +} + +/* Caller must hold sitdev->multiop_lock. */ +int sit9531x_output_enable (struct sit9531x_dev *sitdev,u8 index) +{ +const struct sit9531x_chip_info *info = sitdev->info; +int rc, state_rc; +bool muted, part; +u8 slot; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (index >= info->num_outputs) +return -EINVAL ; + + slot = info->clkout_map[index]; + rc =sit9531x_outsys_debug_open (sitdev); +if (rc) +return rc; + + rc =sit9531x_output_hiz_write (sitdev, slot, false, + sitdev->out[index].hiz_keep); +sit9531x_outsys_debug_close (sitdev); + + state_rc =sit9531x_output_forced_hiz (sitdev, index, &muted, &part); +if (!state_rc) { + sitdev->out[index].enabled = !muted; + sitdev->out[index].part_muted = part; + sitdev->out[index].state_stale = false; + }else { + sitdev->out[index].state_stale = true; +if (!rc) + rc = state_rc; + } + +return rc; }/*
@@ -2085,6 +2263,24 @@ static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index)return rc; sitdev->out[index].part_muted = part; + sitdev->out[index].state_stale = false; + +/* Record the pads the loaded configuration forces on a driven output */ + out->hiz_keep =0 ; +if (part) { +struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS ]; +bool forced; +int i; + +sit9531x_output_get_hiz_regs (slot, p); +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { + rc =sit9531x_hiz_pair_forced (sitdev, &p[i], &forced); +if (rc) +return rc; +if (forced) + out->hiz_keep |=BIT (i); + } + }/* * Each PLL page holds a 12-bit output-enable mask: OUT_MAP_LO bits 0-7
@@ -2445,7 +2641,9 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)/* Retry pending writes first so the reads below see their result */ if (sitdev->loops_open) -sit9531x_prg_commit (sitdev); +sit9531x_prg_relock (sitdev); +else if (sitdev->outsys_key_pending) +sit9531x_outsys_debug_close (sitdev);sit9531x_input_off_retry (sitdev);for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {
@@ -2772,10 +2970,12 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev)mutex_lock (&sitdev->multiop_lock);if (sitdev->loops_open) { -sit9531x_prg_commit (sitdev); +sit9531x_prg_relock (sitdev);if (sitdev->loops_open)dev_warn (sitdev->dev,"output loops left unlocked at removal\n" ); + }else if (sitdev->outsys_key_pending) { +sit9531x_outsys_debug_close (sitdev); }mutex_unlock (&sitdev->multiop_lock); }
@@ -2855,7 +3055,7 @@ static void sit9531x_dpll_pin_unregister(struct sit9531x_dpll_pin *pin)* Clear before unregistering: callbacks test it under the DPLL device * lock, which dpll_pin_unregister() also takes. */ - pin->dpll_pin =NULL ; +WRITE_ONCE (pin->dpll_pin,NULL );dpll_pin_unregister (sitdpll->dpll_dev, dpll_pin, ops, pin);dpll_pin_put (dpll_pin, &pin->tracker);
@@ -2891,20 +3091,33 @@ static void sit9531x_dpll_pins_unregister(struct sit9531x_dpll *sitdpll) } } -/* Check if the pin class has a state callback, which the DPLL core requires */ +/* +* An output is registered when routed to this DPLL, whether or not it is +* driving. +*/ static bool sit9531x_dpll_pin_is_registrable (struct sit9531x_dpll *sitdpll,enum dpll_pin_direction dir,u8 index) {struct sit9531x_dev *sitdev = sitdpll->dev; -if (dir !=DPLL_PIN_DIRECTION_INPUT ) +if (dir ==DPLL_PIN_DIRECTION_INPUT ) { +if (index ==SIT9531X_MAX_INPUTS ) +return true; +if (index ==SIT9531X_INTSYNC_PIN_ID ) +return false; + +return sit9531x_input_pin_is_registrable (sitdev, index); + } + +if (index ==SIT9531X_INTSYNC_OUT_PIN_ID )return false; -if (index ==SIT9531X_MAX_INPUTS ) -return true; +if (index >= sitdev->info->num_outputs) +return false; -return sit9531x_input_pin_is_registrable (sitdev, index); +return sitdev->out[index].pll_idx == sitdpll->id && + sitdev->out[index].routed; }static int sit9531x_dpll_pins_register (struct sit9531x_dpll *sitdpll)
drivers/dpll/sit9531x/core.h +15 -0
@@ -101,8 +101,13 @@ struct sit9531x_ref {* @freq: output frequency in Hz * @enabled: output is driving, not forced into Hi-Z * @cmos: single-ended; the CMOS pad Hi-Z pairs apply, not the differential one +* @state_stale: cached mute state must be read back before it is reported +* @ntf_pending: pin change not yet notified; the poll notifies once the state +* is read * @part_muted: single-ended with one pad forced and the other not; reported * as driven. The driver's mute forces both pads. +* @hiz_keep: bit per Hi-Z pair the loaded configuration forces on an output +* found part muted at probe; an unmute leaves those pairs forced * @routed: mapped to @pll_idx by the initial configuration; an unrouted * output has no pin * @pll_idx: PLL driving this output (0-3)
@@ -111,7 +116,10 @@ struct sit9531x_out {u64 freq;bool enabled;bool cmos; +bool state_stale; +bool ntf_pending;bool part_muted; +u8 hiz_keep;bool routed;u8 pll_idx; };
@@ -206,6 +214,7 @@ struct sit9531x_chan {* @fvco_band_warned: bit per PLL warned for Fref * DIVN outside its VCO * band; written under @multiop_lock * @loops_open: output loops not yet re-locked +* @outsys_key_pending: output-system debug key not closed */ struct sit9531x_dev {struct device *dev;
@@ -237,6 +246,7 @@ struct sit9531x_dev {s8 intsync_src;bool loops_open; +bool outsys_key_pending; }; int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
@@ -264,6 +274,11 @@ int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,int sit9531x_input_prio_add (struct sit9531x_dev *sitdev,u8 pll_idx,u8 input_idx); +int sit9531x_output_disable (struct sit9531x_dev *sitdev,u8 index); +int sit9531x_output_enable (struct sit9531x_dev *sitdev,u8 index); +int sit9531x_output_state_refresh (struct sit9531x_dev *sitdev, +u8 out_idx); +int sit9531x_output_freq_set (struct sit9531x_dev *sitdev,u8 out_idx,u8 pll_idx,u64 frequency); int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,
drivers/dpll/sit9531x/dpll.c +137 -5
171 lines not on this page · raw message
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 10/13] dpll: sit9531x: implement output pin state on a DPLL
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] dpll: sit9531x: missing unmute rollback in sit9531x_output_hiz_write() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] dpll: sit9531x: missing unmute rollback in sit9531x_output_hiz_write()
--
commit 0e3fab69e8ec41357c5e926188ccf70841ddc72f
Author: Oleg Zadorozhnyi <[email protected]>
dpll: sit9531x: implement output pin state on a DPLL
This commit implements the DPLL state get and set callbacks for SiT9531x output pins by forcing or releasing the slot's Hi-Z pad overrides, and enables output pin registration.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 21 lines
drivers/dpll/sit9531x/core.c +8
-10+static int sit9531x_output_hiz_write (struct sit9531x_dev *sitdev,u8 slot, +bool mute,u8 keep) { -int rc, rc2 =0 , rc3; -u8 attempt; +u8 mask[SIT9531X_HIZ_PAIRS ], state[SIT9531X_HIZ_PAIRS ]; +struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS ]; +int i, rc, undo_rc; - rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , -SIT9531X_UPDATE_NVM ); +sit9531x_output_get_hiz_regs (slot, p); -for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) { - rc2 =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , -SIT9531X_LOOP_LOCK ); -if (!rc2) -break ; -usleep_range (1000 ,2000 ); +if (!mute) { +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) {
drivers/dpll/sit9531x/core.c static int sit9531x_prg_enter(struct sit9531x_dev *sitdev) · line 620
Quoted 10 lines
drivers/dpll/sit9531x/core.c +9
-0+/* A pad the loaded configuration forces stays forced */ +if (keep &BIT (i)) +continue ; + rc =sit9531x_hiz_set_bit (sitdev, p[i].mask, p[i].bit, + false); +if (rc) +return rc; + } +return 0 ; }
[Severity: Medium]
Should the !mute branch roll back the mask bits cleared in earlier iterations when sit9531x_hiz_set_bit() fails, just as the mute branch does?
On a muted CMOS output where clearing SIT9531X_HIZ_CMOS_P succeeds and clearing SIT9531X_HIZ_CMOS_N fails, the hardware is left partially unmuted with OutP driving and OutN still forced to Hi-Z. The subsequent readback in sit9531x_output_forced_hiz() computes muted = pad_p && pad_n as false, so sit9531x_output_enable() sets out->enabled = true and sit9531x_dpll_output_pin_state_on_dpll_set() fails the request while sending a notification that reports the pin as DPLL_PIN_STATE_CONNECTED.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
[email protected]
AI reviewRe: [PATCH net-next v16 10/13] dpll: sit9531x: implement output pin state on a DPLL
In reply to Ali RouhiThank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 4
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Unmuting does not put back the Hi-Z override that was there before the mute.
- [Medium] The driver keeps the record of which pads the loaded configuration forces (out->hiz_keep) only in driver memory, and…
- [Medium] The programming sequence opens the Page 3 debug key (0x03:0xBD) before it writes PRG_DIR_GEN (0x03:0x0F) with…
- [Low] The commit message describes only the output mute through the Hi-Z force registers.
- [Low] The get side and the set side disagree on what a part-muted output is.
- [Low] When the write of SIT9531X_DEBUG_UNLOCK_VAL to SIT9531X_REG_OUTSYS_DEBUG fails, sit9531x_outsys_debug_open() tries to…
- [Low] The unmute branch of sit9531x_output_hiz_write() releases MASK bits in order (DIFF, CMOS_P, CMOS_N) and returns on the first failed…
--
dpll: sit9531x: implement output pin state on a DPLL
This patch adds state_on_dpll_get/set for output pins and registers the output pins routed to each DPLL. An output is muted by forcing its differential and CMOS Hi-Z override pairs while the Page 3 debug window is open. The patch also folds the PRG_CMD helpers into sit9531x_prg_relock() and adds outsys_key_pending tracking for the output-system debug key.
Quoted 5 lines
drivers/dpll/sit9531x/core.c +0
-0@@ -460,12 +460,78 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev, · line 512
Quoted 12 lines
drivers/dpll/sit9531x/core.c +12
-0+static int sit9531x_outsys_debug_open (struct sit9531x_dev *sitdev) +{ +int rc; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_UNLOCK_VAL ); +if (rc) +sit9531x_write_close (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); + +return rc; +}
[Severity: Low]
When the unlock write fails here, the result of sit9531x_write_close() is dropped and outsys_key_pending is never set. Is that intended?
The only place that updates the flag is sit9531x_outsys_debug_close():
sitdev->outsys_key_pending = !!rc;
sit9531x_dev_chan_states_update() and sit9531x_dev_stop() retry the close only when that flag is set.
A failed I2C write can still latch the unlock byte, for example when the error comes after the data phase. If all SIT9531X_CLOSE_TRIES lock attempts then fail as well, could the Page 3 debug window stay unlocked with nothing ever retrying the close?
sit9531x_output_disable(), sit9531x_output_enable() and sit9531x_prg_enter() all reach this path. Would it work to call sit9531x_outsys_debug_close() in the failure branch, or to set outsys_key_pending from the sit9531x_write_close() result?
[ ... ]
Quoted 19 lines
drivers/dpll/sit9531x/core.c +7
-2+/* +* Leave PRG_CMD: re-lock the loops and close the debug window. The sleep is +* the settling time after loop lock. +*/ +static int sit9531x_prg_relock (struct sit9531x_dev *sitdev) { -int rc = -EIO ; +int rc =0 ;u8 attempt;for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) {@@ -477,30 +543,49 @@ static void sit9531x_prg_abort(struct sit9531x_dev *sitdev) }if (rc)dev_err (sitdev->dev, -"output loops left unlocked after a failed entry: %d\n" , +"output loops left unlocked after programming: %d\n" , rc);
drivers/dpll/sit9531x/core.c static void sit9531x_prg_abort(struct sit9531x_dev *sitdev) · line 556
Quoted 10 lines
drivers/dpll/sit9531x/core.c +7
-2-sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_LOCK_VAL ); + sitdev->loops_open = !!rc; + +msleep (100 ); + +sit9531x_outsys_debug_close (sitdev); + +return rc; }
[Severity: Medium]sit9531x_prg_relock() always closes the debug key, even when every LOOP_LOCK attempt failed and loops_open was set. The later retries call sit9531x_prg_relock() directly. In sit9531x_dev_chan_states_update() and sit9531x_dev_stop():
if (sitdev->loops_open)
sit9531x_prg_relock(sitdev);These retries write LOOP_LOCK to SIT9531X_REG_PRG_DIR_GEN while the key at 0x03:0xBD is locked, and nothing reopens it first.
Everywhere else, the driver opens the debug key before it writes PRG_DIR_GEN. Suppose the device ignores PRG_DIR_GEN writes while the key is locked. The retry would still be ACKed, loops_open would be cleared, and the output loops would stay in PRG_CMD. Can that happen?
loops_open = !!rc reflects only the I2C status, and nothing reads the loop state back. Later in the series, the phase offset code also gates on loops_open.
This patch also adds a new way into this state. A failed PRG_CMD_STATE write in sit9531x_prg_enter() now goes through sit9531x_prg_relock() and can set loops_open. The removed sit9531x_prg_abort() never queued a retry.
The out-of-window retry first appeared earlier in this series, in "dpll:
sit9531x: add support to get and set frequency on pins" (through sit9531x_prg_commit()). This patch rewrites it into sit9531x_prg_relock(). Whether the debug key gates 0x03:0x0F depends on the datasheet.
Should the retry path reopen the debug window before it writes LOOP_LOCK?
[ ... ]
Quoted 7 lines
drivers/dpll/sit9531x/core.c +1
-2static int sit9531x_prg_enter (struct sit9531x_dev *sitdev) {int rc; - rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_UNLOCK_VAL ); + rc =sit9531x_outsys_debug_open (sitdev);
drivers/dpll/sit9531x/core.c static void sit9531x_prg_abort(struct sit9531x_dev *sitdev) · line 590
Quoted 10 lines
drivers/dpll/sit9531x/core.c +1
-1if (rc)return rc; rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN ,SIT9531X_PRG_CMD_STATE );if (rc) { -sit9531x_prg_abort (sitdev); +sit9531x_prg_relock (sitdev);return rc; }
[Severity: Low]
This isn't a bug, but the commit message only describes the output mute through the Hi-Z force registers. The patch also reworks the PRG_CMD helpers that "dpll: sit9531x: add support to get and set frequency on pins" added for the output divider write.
sit9531x_prg_abort() is removed. A failed PRG_CMD_STATE write here now goes through sit9531x_prg_relock(), which sets loops_open, sleeps for 100 ms and records the result of the key close in outsys_key_pending. Before this patch, a failed loop lock on this path was never retried.
The poll retry in sit9531x_dev_chan_states_update() and the removal path in sit9531x_dev_stop() now call sit9531x_prg_relock() instead of sit9531x_prg_commit(). A retry therefore no longer re-issues SIT9531X_UPDATE_NVM, and only a code comment explains that.
There is also a new background retry that closes the output-system debug key after a failed close:
else if (sitdev->outsys_key_pending)
sit9531x_outsys_debug_close(sitdev);Together these change how sit9531x_output_freq_set() behaves on failure. Could these changes go into the frequency-set patch, or at least be described in this commit message?
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -508,51 +593,144 @@ static int sit9531x_prg_enter(struct sit9531x_dev *sitdev)
[ ... ]
Quoted 3 lines
drivers/dpll/sit9531x/core.c +2
-0+static int sit9531x_output_hiz_write (struct sit9531x_dev *sitdev,u8 slot, +bool mute,u8 keep) {
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_prg_enter(struct sit9531x_dev *sitdev) · line 617
Quoted 9 lines
drivers/dpll/sit9531x/core.c +9
-0+if (!mute) { +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { +/* A pad the loaded configuration forces stays forced */ +if (keep &BIT (i)) +continue ; + rc =sit9531x_hiz_set_bit (sitdev, p[i].mask, p[i].bit, + false); +if (rc) +return rc;
[Severity: Low]
If a read-modify-write fails partway through this loop, the pairs already released stay released. Is that intended?
Take a CMOS output where CMOS_P was released and the CMOS_N pair then fails. OutP is left driving and OutN is still forced to Hi-Z. Neither the user nor the loaded configuration asked for that state. sit9531x_output_enable() then reads back part_muted = true and enabled = true and returns the error. The pin reports CONNECTED while the request fails.
The mute branch below takes a snapshot of mask[] and state[] and rolls back on failure. Should the unmute branch do the same?
drivers/dpll/sit9531x/core.c static int sit9531x_prg_enter(struct sit9531x_dev *sitdev) · line 620
Quoted 3 lines
drivers/dpll/sit9531x/core.c +2
-0+ } +return 0 ; }
[Severity: Medium]
The commit message says:
An un-mute releases the force and the pads return to the loaded configuration.
Does this branch restore the loaded configuration? It only clears the MASK bit of each pair not in keep, and STATE stays at the 0 the mute wrote.
The mask[] and state[] snapshot in the mute branch is used only to roll back a failed mute. sit9531x_out_state_fetch() fills hiz_keep only for outputs found part-muted at probe, and only for pairs forced to Hi-Z (MASK set, STATE clear).
Consider a pair the profile had under a drive override (MASK=1, STATE=1), or any override on a differential or fully driven output. After a DISCONNECTED then CONNECTED cycle it comes back as MASK=0, STATE=0. Is losing that override expected?
sit9531x_dpll_output_pin_state_on_dpll_set() never skips a CONNECTED request while part_muted is set. So on an output that was part-muted at probe, every CONNECTED request clears MASK on non-keep pairs the driver never touched. The readback only checks mask && !state, so nothing reports the lost override.
Whether MASK=0 behaves differently from MASK=1/STATE=1 depends on the device's non-override output control. Could the unmute put back the saved MASK/STATE values instead?
[ ... ]
Quoted 12 lines
drivers/dpll/sit9531x/core.c +8
-0@@ -2085,6 +2263,24 @@ static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index)return rc; sitdev->out[index].part_muted = part; + sitdev->out[index].state_stale = false; + +/* Record the pads the loaded configuration forces on a driven output */ + out->hiz_keep =0 ; +if (part) { +struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS ]; +bool forced; +int i;
drivers/dpll/sit9531x/core.c static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index) · line 2283
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ +sit9531x_output_get_hiz_regs (slot, p); +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { + rc =sit9531x_hiz_pair_forced (sitdev, &p[i], &forced); +if (rc) +return rc; +if (forced) + out->hiz_keep |=BIT (i); + } + }
[Severity: Medium]
Does hiz_keep survive an unbind/rebind or a module reload?
It is rebuilt only for outputs found part-muted. The driver's own mute, sit9531x_output_disable()->sit9531x_output_hiz_write(..., true, 0), forces all three pairs. sit9531x_dev_stop() does not undo those forces, and the force registers are outside the NVM, so they stay set while the part has power.
After a rebind without a power cycle, this function sees muted = true and part = false, and sets hiz_keep = 0. A later CONNECTED request then calls sit9531x_output_hiz_write(slot, false, 0). That clears MASK on all three pairs, including the pad the loaded configuration had forced to Hi-Z.
For example, a CMOS output whose profile drives only OutP would end up with both OutP and OutN driving. Wouldn't that contradict "the pads return to the loaded configuration"?
Resume, added later in the series, re-reads the mute state but does not recompute hiz_keep. The gap is still there at the end of the series.
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/dpll.c +0
-0
[ ... ]
Quoted 8 lines
drivers/dpll/sit9531x/dpll.c +8
-0+static int +sit9531x_dpll_output_pin_state_on_dpll_set (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_state state, +struct netlink_ext_ack *extack) +{
[ ... ]
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_frequency_set(const struct dpll_pin *pin, · line 709
Quoted 12 lines
drivers/dpll/sit9531x/dpll.c +12
-0+mutex_lock (&sitdev->multiop_lock); + +/* +* Skip a request for the current state. One CMOS pad forced and the +* other not is neither state. +*/ +if (!sit9531x_output_state_refresh (sitdev, dpin->id) && + sitdev->out[dpin->id].enabled == enable && + !sitdev->out[dpin->id].part_muted) { +mutex_unlock (&sitdev->multiop_lock); +return 0 ; + }
[Severity: Low]
This comment seems to disagree with the get side. The @part_muted kernel-doc in core.h says such an output is "reported as driven", and sit9531x_dpll_output_pin_state_on_dpll_get() reports it as CONNECTED.
The skip test requires !part_muted, so a CONNECTED request on a pin that already reports CONNECTED always runs sit9531x_output_enable(). On an output part-muted at probe, the hiz_keep pads stay forced, the readback is part-muted and enabled again, and the reported state does not change.
Each such request still does a read-modify-write of every non-keep Hi-Z MASK bit. That can clear profile-set mask bits the driver never changed, such as the DIFF pair of a CMOS output.
The exclusion also lets a retry finish an unmute that failed partway when hiz_keep is 0. Could the skip treat the hiz_keep-only case as already satisfied for CONNECTED, or could the comment match the @part_muted documentation?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 11/13 dpll: sit9531x: add support to adjust output phase
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Shift an output in time against the other outputs of its PLL. A delay is a coarse count of VCO cycles plus a 3-bit fine field in 30 ps steps, so the grid depends on the PLL's rate; the driver programs the nearest point and the getter reports what the registers hold.
The range advertised to the core is +/-1 ms at 1 ps granularity. The driver writes only positive delays, so an advance is held as the complementary delay within the output period, and a stored delay is reported in the form nearer to zero. A delay alone takes a small-change update, without the programming state. It is applied by the PLL's phase flush, or by a PLL restart where the configuration has the flush off; both restart the divider phase of every output the PLL drives. A rate change re-times a programmed delay in the same programming window as the divider.
A write that fails part way is recorded and retried by the poll and at
removal: a flush that did not fire, the flush registers not put back, and a delay still to be re-timed after a rate change.
--- drivers/dpll/sit9531x/core.c | 861 ++++++++++++++++++++++++++++++++--- drivers/dpll/sit9531x/core.h | 30 ++ drivers/dpll/sit9531x/dpll.c | 119 ++++- drivers/dpll/sit9531x/prop.c | 14 + drivers/dpll/sit9531x/regs.h | 29 ++ 5 files changed, 977 insertions(+), 76 deletions(-)
drivers/dpll/sit9531x/core.c +788 -73
@@ -245,6 +245,23 @@ static int sit9531x_write_pll_close(struct sit9531x_dev *sitdev, u8 pll_idx, offset), val); } +static int sit9531x_update_pll_close (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 offset,u8 mask,u8 val) +{ +u8 attempt; +int rc; + +for (attempt =0 ; attempt <SIT9531X_CLOSE_TRIES ; attempt++) { +if (attempt) +usleep_range (1000 ,2000 ); + rc =sit9531x_update_pll_u8 (sitdev, pll_idx, offset, mask, val); +if (!rc) +break ; + } + +return rc; +} + static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev, u8 index, unsigned int *force_reg,
@@ -1559,6 +1576,65 @@ static int sit9531x_pll_small_update(struct sit9531x_dev *sitdev, u8 pll_idx) SIT9531X_SMALL_UPDATE_CMD); } +static int sit9531x_pll_small_update_close (struct sit9531x_dev *sitdev, +u8 pll_idx) +{ +return sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_SMALL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +} + +/* +* Undo a phase flush: restore the trigger select and the flush enable of @plls +* from @armed. +*/ +static int sit9531x_phase_flush_undo (struct sit9531x_dev *sitdev, +bool ctrl_back,u8 ctrl,u8 plls,u8 armed) +{ +const u8 en =SIT9531X_PLL_PHFL_ON_DEMAND_EN ; +int rc =0 , ret; +u8 i; + +if (ctrl_back) { + rc =sit9531x_write_close (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , + ctrl); + sitdev->flush_ctrl_pending = !!rc; + sitdev->flush_ctrl = ctrl; + } + +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +if (!(plls &BIT (i))) +continue ; + ret =sit9531x_update_pll_close (sitdev, i, +SIT9531X_PLL_REG_PHFL_CTRL , en, + (armed &BIT (i)) ? en :0 ); +if (!ret) + ret =sit9531x_pll_small_update_close (sitdev, i); +if (ret) { + sitdev->flush_arm_pending |=BIT (i); + sitdev->flush_armed &= ~BIT (i); + sitdev->flush_armed |= armed &BIT (i); +if (!rc) + rc = ret; + }else { + sitdev->flush_arm_pending &= ~BIT (i); + } + } + +return rc; +} + +static int sit9531x_phase_flush_undo_retry (struct sit9531x_dev *sitdev) +{ +if (!sitdev->flush_ctrl_pending && !sitdev->flush_arm_pending) +return 0 ; + +return sit9531x_phase_flush_undo (sitdev, sitdev->flush_ctrl_pending, + sitdev->flush_ctrl, + sitdev->flush_arm_pending, + sitdev->flush_armed); +} +/* * Realign the PLL's output dividers with the on-demand phase flush (PHFL), or * restart the PLL when its profile has PHFL off (PLL page 0x47 bit 7 clear), as
@@ -1567,24 +1643,36 @@ static int sit9531x_pll_small_update(struct sit9531x_dev *sitdev, u8 pll_idx)*/ static int sit9531x_output_phase_flush (struct sit9531x_dev *sitdev,u8 pll_idx) { -u8 ctrl, orig, phfl, armed_mask =0 , parked =0 , i; +u8 ctrl, orig =0 , phfl, armed_mask =0 , parked =0 , touched, i; +bool ctrl_back = false, armed_here = false, fired = false;int rc, ret; +/* +* Retry a pending undo first so the reads below see the profile's +* settings. +*/ + rc =sit9531x_phase_flush_undo_retry (sitdev); +if (rc) + goto out; + rc =sit9531x_read_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_CONFIG47 , &phfl);if (rc) -return rc; -if (!(phfl &SIT9531X_PLL_CONFIG47_PHFL_EN )) -return sit9531x_write_pll_u8 (sitdev, pll_idx, -SIT9531X_PLL_REG_DIRECTIVES , -SIT9531X_PLL_DIRECTIVE_RESTART ); + goto out; +if (!(phfl &SIT9531X_PLL_CONFIG47_PHFL_EN )) { + rc =sit9531x_write_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DIRECTIVES , +SIT9531X_PLL_DIRECTIVE_RESTART ); + fired = !rc; + goto out; + }/* Only the target PLL keeps on-demand flush enabled for the pulse. */ for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { rc =sit9531x_read_pll_u8 (sitdev, i,SIT9531X_PLL_REG_PHFL_CTRL , &phfl);if (rc) -return rc; + goto out;if (phfl &SIT9531X_PLL_PHFL_ON_DEMAND_EN ) armed_mask |=BIT (i); }
@@ -1597,18 +1685,19 @@ static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)SIT9531X_PLL_REG_PHFL_CTRL , SIT9531X_PLL_PHFL_ON_DEMAND_EN, 0);if (rc) - goto unpark; + goto undo; rc =sit9531x_pll_small_update (sitdev, i);if (rc) - goto unpark; + goto undo; } + armed_here = true; rc =sit9531x_update_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_PHFL_CTRL ,SIT9531X_PLL_PHFL_ON_DEMAND_EN ,SIT9531X_PLL_PHFL_ON_DEMAND_EN );if (rc) - goto disarm; + goto undo;/* * Write the update register whole; a read-modify-write skips the write
@@ -1616,21 +1705,19 @@ static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)*/ rc =sit9531x_pll_small_update (sitdev, pll_idx);if (rc) - goto disarm; + goto undo; -/* -* Select the in-register phase trigger; the register also holds the OEb -* bits. -*/ +/* Select the in-register phase trigger, preserving the OEb bits. */ rc =sit9531x_read_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , &ctrl);if (rc) - goto disarm; + goto undo; orig = ctrl & ~SIT9531X_DIVO_PHASE_TRIG ; ctrl = orig |SIT9531X_DIVO_PHASE_SEL_REG ; + ctrl_back = true; rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl);if (rc) - goto restore; + goto undo;/* * No delay between set and clear; one I2C transfer is longer than the
@@ -1638,40 +1725,19 @@ static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)*/ rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl |SIT9531X_DIVO_PHASE_TRIG ); - -restore: - ret =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , orig); + fired = !rc; + +undo: + touched = parked; +if (armed_here && !(armed_mask &BIT (pll_idx))) + touched |=BIT (pll_idx); + ret =sit9531x_phase_flush_undo (sitdev, ctrl_back, orig, touched, + armed_mask);if (ret && !rc) rc = ret; -disarm: -/* -* Restore the profile's flush enable; an armed flush re-flushes every -* output divider of this PLL on the next trigger. -*/ -if (!(armed_mask &BIT (pll_idx))) { - ret =sit9531x_update_pll_u8 (sitdev, pll_idx, -SIT9531X_PLL_REG_PHFL_CTRL , -SIT9531X_PLL_PHFL_ON_DEMAND_EN ,0 ); -if (!ret) - ret =sit9531x_pll_small_update (sitdev, pll_idx); -if (ret && !rc) - rc = ret; - } - -unpark: -for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { -if (!(parked &BIT (i))) -continue ; - ret =sit9531x_update_pll_u8 (sitdev, i, -SIT9531X_PLL_REG_PHFL_CTRL , -SIT9531X_PLL_PHFL_ON_DEMAND_EN , -SIT9531X_PLL_PHFL_ON_DEMAND_EN ); -if (!ret) - ret =sit9531x_pll_small_update (sitdev, i); -if (ret && !rc) - rc = ret; - } +out: + sitdev->chan[pll_idx].flush_pending = !fired;return rc; }
@@ -1752,7 +1818,7 @@ static int sit9531x_output_divo_write(struct sit9531x_dev *sitdev, u8 out_idx,int rc, j, rb_rc;u8 written =0 ; - *back = false; + *back = true; slot = info->clkout_map[out_idx];
@@ -1779,6 +1845,7 @@ static int sit9531x_output_divo_write(struct sit9531x_dev *sitdev, u8 out_idx, msb_old = old_bytes[4 ]; divo_bytes[4 ] |= msb_old &0xFC ; + *back = false;for (j =0 ; j <5 ; j++) { rc = sit9531x_write_u8(sitdev, SIT9531X_REG(page, base_reg - j),
@@ -1837,12 +1904,361 @@ static int sit9531x_output_divo_read(struct sit9531x_dev *sitdev, u8 out_idx,return *divo ?0 : -ENODATA ; } +/* +* Phase adjust is a 34-bit coarse delay in VCO cycles plus a 3-bit fine delay +* in 30 ps steps, in bytes PROG6..PROG2. PRG_RST_DELAY is unsigned, so an +* advance is written as T_out - |phase|. +*/ + +/* Register of byte @i (PROG6 first) of an output's PRG_RST_DELAY block. */ +static unsigned int sit9531x_output_prg_reg (struct sit9531x_dev *sitdev, +u8 out_idx,u8 i) +{ +u8 slot = sitdev->info->clkout_map[out_idx]; +u8 page = (slot >SIT9531X_PAGE_OUTSYS0_SLOT_MAX ) ? +SIT9531X_PAGE_OUTSYS1 :SIT9531X_PAGE_OUTSYS0 ; +u8 base =SIT9531X_OUT_PRG_DELAY_BASE + +SIT9531X_OUT_PRG_SLOT_STRIDE * (slot %6 ); + +return SIT9531X_REG (page, base + i); +} + +static int sit9531x_output_phase_bytes_read (struct sit9531x_dev *sitdev, +u8 out_idx,u8 *bytes) +{ +unsigned int reg; +int rc; +u8 i; + +for (i =0 ; i <SIT9531X_OUT_PRG_BYTES ; i++) { + reg =sit9531x_output_prg_reg (sitdev, out_idx, i); + rc =sit9531x_read_u8 (sitdev, reg, &bytes[i]); +if (rc) +return rc; + } + +return 0 ; +} + +/* +* The register value includes the divider's settling cycles; a value below them +* means no delay. +*/ +static void sit9531x_output_phase_bytes_decode (const u8 *bytes,u64 *coarse, +u8 *fine) +{ +u64 prg_coarse; + + *fine = (bytes[0 ] &SIT9531X_OUT_PRG_FINE_MASK ) >> +SIT9531X_OUT_PRG_FINE_SHIFT ; + prg_coarse = (u64)(bytes[0 ] &SIT9531X_OUT_PRG_COARSE_HI_MASK ) <<32 ; + prg_coarse |= (u64 )bytes[1 ] <<24 ; + prg_coarse |= (u64 )bytes[2 ] <<16 ; + prg_coarse |= (u64 )bytes[3 ] <<8 ; + prg_coarse |= bytes[4 ]; + *coarse = (prg_coarse >SIT9531X_OUT_PRG_DIVO_CYCLES ) ? + prg_coarse -SIT9531X_OUT_PRG_DIVO_CYCLES :0 ; +} + +/* +* @coarse excludes the divider's two settling cycles; the register value +* includes them. +*/ +static void sit9531x_output_phase_bytes_build (const u8 *old_bytes,u64 coarse, +u8 fine,u8 *new_bytes) +{ +u64 prg_coarse = coarse +SIT9531X_OUT_PRG_DIVO_CYCLES ; + +/* PROG6 RMW: preserve OPSTG_VCASC_BUMP in [7:5] */ + new_bytes[0 ] = old_bytes[0 ] &SIT9531X_OUT_PRG_OPSTG_MASK ; + new_bytes[0 ] |= (fine <<SIT9531X_OUT_PRG_FINE_SHIFT ) & +SIT9531X_OUT_PRG_FINE_MASK ; + new_bytes[0 ] |= (u8)((prg_coarse >>32 ) & +SIT9531X_OUT_PRG_COARSE_HI_MASK ); + new_bytes[1 ] = (u8)((prg_coarse >>24 ) &0xFF ); + new_bytes[2 ] = (u8)((prg_coarse >>16 ) &0xFF ); + new_bytes[3 ] = (u8)((prg_coarse >>8 ) &0xFF ); + new_bytes[4 ] = (u8)(prg_coarse &0xFF ); +} + +/* +* Caller must hold the debug window open; @back reports whether every byte +* holds its old value. +*/ +static int sit9531x_output_phase_bytes_write (struct sit9531x_dev *sitdev, +u8 out_idx,const u8 *new_bytes, +const u8 *old_bytes,bool *back) +{ +int rc, ret, rb_rc =0 ; +unsigned int reg; +u8 i; + + *back = false; + +for (i =0 ; i <SIT9531X_OUT_PRG_BYTES ; i++) { + reg =sit9531x_output_prg_reg (sitdev, out_idx, i); + rc =sit9531x_write_u8 (sitdev, reg, new_bytes[i]); +if (rc) + goto rollback; + } + +return 0 ; + +rollback: +for (i =0 ; i <SIT9531X_OUT_PRG_BYTES ; i++) { + reg =sit9531x_output_prg_reg (sitdev, out_idx, i); + ret =sit9531x_write_u8 (sitdev, reg, old_bytes[i]); +if (ret && !rb_rc) + rb_rc = ret; + } + *back = !rb_rc; +if (rb_rc) { +dev_err (sitdev->dev, +"out%u: phase-adjust rollback failed (%d), the delay registers are part old and part new\n" , + out_idx, rb_rc); +if (!rc) + rc = rb_rc; + } + +return rc; +} + +/* +* Return the error of @cycles VCO cycles plus the nearest fine steps (in @fine) +* against @abs_ps. +*/ +static u64 sit9531x_output_phase_quant_err (u64 abs_ps,u64 fvco,u64 cycles, +u8 *fine) +{ +u64 cycles_ps, steps =0 ; + + cycles_ps =mul_u64_u64_div_u64 (cycles,1000000000000ULL , fvco); +if (abs_ps > cycles_ps) + steps =div64_u64 (abs_ps - cycles_ps + +SIT9531X_OUT_PRG_FINE_STEP_PS /2 , +SIT9531X_OUT_PRG_FINE_STEP_PS ); + *fine =min_t (u64, steps,SIT9531X_OUT_PRG_FINE_MAX ); + +return abs_diff (abs_ps, cycles_ps + + (u64)*fine *SIT9531X_OUT_PRG_FINE_STEP_PS ); +} + +/* +* Fold @phase_ps into one output period and split it into VCO cycles and fine +* steps; @phase_adj gets the realized delay as the readback reports it. Pure +* arithmetic, so call it before entering the programming state. +*/ +static int sit9531x_output_phase_encode (u64 fvco,u64 divo,s32 phase_ps, +u64 *coarse_out,u8 *fine_out, +s32 *phase_adj) +{ +u64 abs_ps, cycles, frac_ps, coarse =0 , coarse_ps, t_out_ps; +s64 phase_norm_ps =0 ; +u8 fine =0 ; + + t_out_ps =mul_u64_u64_div_u64 (divo,1000000000000ULL , fvco); +if (!t_out_ps) +return -EINVAL ; + +if (!phase_ps) { + *coarse_out =0 ; + *fine_out =0 ; + *phase_adj =0 ; +return 0 ; + } + +/* +* The period is DIVO VCO cycles but often fractional in ps (7812.5 ps +* at 128 MHz from 5.12 GHz), so fold whole cycles modulo DIVO and carry +* the sub-cycle part. The DPLL core limits the request to +/-1 ms. +*/ + abs_ps =abs (phase_ps); + cycles =mul_u64_u64_div_u64 (abs_ps, fvco,1000000000000ULL ); + frac_ps = abs_ps -mul_u64_u64_div_u64 (cycles,1000000000000ULL , fvco); +div64_u64_rem (cycles, divo, &cycles); + abs_ps =mul_u64_u64_div_u64 (cycles,1000000000000ULL , fvco) + frac_ps; +/* +* Truncation can leave a request within 1 ps of a whole period, which +* is the same edge as no delay. +*/ +if (abs_ps >= t_out_ps) + abs_ps =0 ; + phase_norm_ps = phase_ps <0 ? -(s64 )abs_ps : (s64 )abs_ps; + abs_ps = (phase_ps <0 && abs_ps) ? t_out_ps - abs_ps : abs_ps; + +if (abs_ps) { +u64 floor_cycles, err, alt_err, realized; +u8 alt_fine; + +/* mul_u64_u64_div_u64(): abs_ps * fvco would overflow. */ + floor_cycles =mul_u64_u64_div_u64 (abs_ps, fvco, +1000000000000ULL ); + +/* +* The fine field spans 210 ps, more than one VCO cycle in every +* band, so take the nearest of floor, floor + 1, and floor - 1 +* with a larger fine code; the floor on a tie. +*/ + coarse = floor_cycles; + err =sit9531x_output_phase_quant_err (abs_ps, fvco, coarse, + &fine); + alt_err =sit9531x_output_phase_quant_err (abs_ps, fvco, + floor_cycles +1 , + &alt_fine); +if (alt_err < err) { + coarse = floor_cycles +1 ; + fine = alt_fine; + err = alt_err; + } +if (floor_cycles) { +u64 fewer = floor_cycles -1 ; + + alt_err =sit9531x_output_phase_quant_err (abs_ps, fvco, + fewer, + &alt_fine); +if (alt_err < err) { + coarse = fewer; + fine = alt_fine; + } + } + +/* +* Program a delay that quantizes to a whole period or more as +* none, and round one past the advertised range toward the +* request's side. +*/ + coarse_ps =mul_u64_u64_div_u64 (coarse,1000000000000ULL , fvco); + realized = coarse_ps + + (u64 )fine *SIT9531X_OUT_PRG_FINE_STEP_PS ; +if (realized >= t_out_ps) { + coarse =0 ; + fine =0 ; + }else if (phase_norm_ps <0 ? + t_out_ps - realized >SIT9531X_OUT_PHASE_ADJ_MAX_PS : + realized >SIT9531X_OUT_PHASE_ADJ_MAX_PS ) { +u64 rem; + + coarse = floor_cycles; + coarse_ps =mul_u64_u64_div_u64 (coarse, +1000000000000ULL , fvco); + rem = abs_ps - coarse_ps; +if (phase_norm_ps <0 ) + rem +=SIT9531X_OUT_PRG_FINE_STEP_PS -1 ; + fine =div_u64 (rem,SIT9531X_OUT_PRG_FINE_STEP_PS ); + } + +if (coarse +SIT9531X_OUT_PRG_DIVO_CYCLES >= + (1ULL <<SIT9531X_OUT_PRG_COARSE_BITS )) +return -ERANGE ; + } + + coarse_ps =mul_u64_u64_div_u64 (coarse,1000000000000ULL , fvco); + abs_ps = coarse_ps + (u64 )fine *SIT9531X_OUT_PRG_FINE_STEP_PS ; +/* +* Report the form nearer to zero, as the readback does; it is within +* the range, so it fits the s32 the ABI carries. +*/ +if (abs_ps > t_out_ps - abs_ps) + *phase_adj = -(s32)(t_out_ps - abs_ps); +else + *phase_adj = (s32 )abs_ps; + + *coarse_out = coarse; + *fine_out = fine; + +return 0 ; +} + +/** +* sit9531x_output_phase_read - read an output's programmed delay back +* @sitdev: device pointer +* @out_idx: logical output index +* @phase_ps: result in picoseconds +* @beyond: set when @phase_ps is outside the advertised range +* +* An advance is stored as the period minus the advance; the stored delay reads +* back in the form nearer to zero, as an advance when it is more than half the +* period. Caller must hold sitdev->multiop_lock. +* +* Return: 0 on success, -ENODATA for an output no PLL drives or whose Fvco +* is unknown, <0 on other errors +*/ +int sit9531x_output_phase_read (struct sit9531x_dev *sitdev,u8 out_idx, +s64 *phase_ps,bool *beyond) +{ +const struct sit9531x_chip_info *info = sitdev->info; +u8 bytes[SIT9531X_OUT_PRG_BYTES ], fine; +u64 coarse =0 , fvco, ps, divo; +int rc; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (out_idx >= info->num_outputs) +return -EINVAL ; + + *beyond = false; + +if (!sitdev->out[out_idx].routed) +return -ENODATA ; + + rc =sit9531x_get_fvco (sitdev, sitdev->out[out_idx].pll_idx, &fvco); +if (rc) +return rc; + + rc =sit9531x_output_phase_bytes_read (sitdev, out_idx, bytes); +if (rc) +return rc; +sit9531x_output_phase_bytes_decode (bytes, &coarse, &fine); + +/* +* Take the period from the divider; the cached rate is unset at probe +* and whole hertz at best. +*/ + rc =sit9531x_output_divo_read (sitdev, out_idx, &divo); +if (rc && rc != -ENODATA ) +return rc; + +/* +* Fold the cycle count, not the picoseconds; the fine steps can carry +* the sum a fraction of a cycle past the period. +*/ +if (!rc) +div64_u64_rem (coarse, divo, &coarse); + + ps =mul_u64_u64_div_u64 (coarse,1000000000000ULL , fvco); + ps += (u64 )fine *SIT9531X_OUT_PRG_FINE_STEP_PS ; + +if (!rc) { +u64 t_out_ps =mul_u64_u64_div_u64 (divo,1000000000000ULL , + fvco); + +if (ps >= t_out_ps) + ps -= t_out_ps; +if (ps > t_out_ps - ps && + t_out_ps - ps <=SIT9531X_OUT_PHASE_ADJ_MAX_PS ) { + *phase_ps = -(s64)(t_out_ps - ps); +return 0 ; + } + } + *beyond = ps >SIT9531X_OUT_PHASE_ADJ_MAX_PS ; + *phase_ps = ps; + +return 0 ; +} +int sit9531x_output_freq_set (struct sit9531x_dev *sitdev,u8 out_idx,u8 pll_idx,u64 frequency) { -u64 fvco, divo; +u8 old_bytes[SIT9531X_OUT_PRG_BYTES ], new_bytes[SIT9531X_OUT_PRG_BYTES ]; +u64 fvco, divo, coarse, old_divo =0 ; +bool retime = false, bytes_in = false, bytes_back = false; +bool divo_back = false, divo_in, back, landed, encoded = false; +bool beyond; +struct sit9531x_out *out = &sitdev->out[out_idx]; +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +s32 phase_adj =0 , held =0 ;int rc, ret; -bool back; +u8 fine;lockdep_assert_held (&sitdev->multiop_lock);
@@ -1851,28 +2267,118 @@ int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,if (rc)return rc; +if (out->phase_stale && !out->retime_pending) { +s64 phase_ps; + + rc =sit9531x_output_phase_read (sitdev, out_idx, &phase_ps, + &beyond); +if (rc) +return rc; + out->phase_adj = phase_ps; + out->phase_armed = !beyond && phase_ps; + out->phase_stale = false; + } + +/* +* The reset delay counts VCO cycles; an advance is stored as T_out - +* |advance| and must be re-encoded for the new period. Write it in the +* divider's programming window; a second flush would restart the PLL's +* dividers. +*/ + rc =sit9531x_output_phase_bytes_read (sitdev, out_idx, old_bytes); +if (rc) +return rc; +sit9531x_output_phase_bytes_decode (old_bytes, &coarse, &fine); + beyond = !out->retime_pending && !out->phase_armed && out->phase_adj; +if (out->retime_pending || out->phase_armed || + ((coarse || fine) && !beyond)) { + held = out->retime_pending ? out->retime_ps : out->phase_adj; + + rc =sit9531x_output_phase_encode (fvco, divo, held, &coarse, + &fine, &phase_adj); +if (rc) +return rc; + encoded = true; +sit9531x_output_phase_bytes_build (old_bytes, coarse, fine, + new_bytes); + retime =memcmp (old_bytes, new_bytes,sizeof (new_bytes)) !=0 ; + } + +if (retime) { + rc =sit9531x_output_divo_read (sitdev, out_idx, &old_divo); +if (rc && rc != -ENODATA ) +return rc; + } + rc =sit9531x_prg_enter (sitdev);if (rc)return rc; rc =sit9531x_output_divo_write (sitdev, out_idx, divo, &back); -/* NVM update and loop lock */ - ret =sit9531x_prg_commit (sitdev); + landed = !back; + divo_in = !rc; +if (!rc && retime) { + rc =sit9531x_output_phase_bytes_write (sitdev, out_idx, + new_bytes, old_bytes, + &bytes_back); +if (rc) { + divo_back = bytes_back && + !sit9531x_output_divo_write (sitdev, out_idx, + old_divo, &back); + landed = !divo_back; + }else { + bytes_in = true; + } + } +/* Leave PRG_CMD; the bank update only for a divider that changed */ + ret = landed ?sit9531x_prg_commit (sitdev) : +sit9531x_prg_relock (sitdev);if (ret && !rc) rc = ret; -if (rc) +if (rc) { +if (bytes_in || (encoded && !retime && divo_in)) { + out->phase_adj = phase_adj; + out->phase_armed = phase_adj !=0 ; + out->phase_stale = false; + out->retime_pending = false; + }else if (retime && landed) { + out->retime_ps = held; + out->retime_pending = true; + out->phase_stale = true; + }else if (encoded && landed) { + out->phase_stale = true; + }else if (beyond && landed) { + out->phase_stale = true; + } +if (landed) + chan->flush_pending = true;return rc; + } -/* Flush the output phase so the new DIVO starts aligned */ rc =sit9531x_output_phase_flush (sitdev, pll_idx); -if (rc) { +if (chan->flush_pending)dev_warn (sitdev->dev, -"out%u: rate changed but the divider phase was not realigned (%d)\n" , +"out%u: rate changed but the divider phase was not realigned (%d), the poll retries it\n" , out_idx, rc); - rc =0 ; +else if (rc) +dev_warn (sitdev->dev, +"out%u: rate changed, the flush left something to put back (%d)\n" , + out_idx, rc); +if (encoded) { + out->phase_adj = phase_adj; + out->phase_armed = phase_adj !=0 ; + out->phase_stale = false; } - sitdev->out[out_idx].freq =div64_u64 (fvco, divo); +/* +* A delay beyond the range was not re-timed and now decodes against the +* new divider. +*/ +if (beyond) + out->phase_stale = true; + + out->freq =div64_u64 (fvco, divo); + out->retime_pending = false;return 0 ; }
@@ -1915,20 +2421,138 @@ int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,return 0 ; } -/* -* Phase adjust: per-output 34-bit coarse delay in VCO periods plus a 3-bit -* fine delay in 30 ps steps, in PROG6..PROG2: -* base + 0 PROG6 [7:5] OPSTG_VCASC_BUMP (preserved) -* [4:2] PRG_RST_FINE_DELAY -* [1:0] PRG_RST_DELAY[33:32] -* base + 1 PROG5 PRG_RST_DELAY[31:24] -* base + 2 PROG4 PRG_RST_DELAY[23:16] -* base + 3 PROG3 PRG_RST_DELAY[15:8] -* base + 4 PROG2 PRG_RST_DELAY[7:0] -* Outputs 0-5 are on Page 3, 6-11 on Page 4; base = 0x15 + 16 * (out_idx % 6). -* PRG_RST_DELAY is unsigned; a negative adjustment is wrapped to -* (T_out - |phase|) modulo one output period. -*/ +int sit9531x_output_phase_adjust_set (struct sit9531x_dev *sitdev, +u8 out_idx,s32 phase_ps) +{ +u8 old_bytes[SIT9531X_OUT_PRG_BYTES ], new_bytes[SIT9531X_OUT_PRG_BYTES ]; +const struct sit9531x_chip_info *info = sitdev->info; +bool bytes_back, bytes_in, same; +struct sit9531x_chan *chan; +struct sit9531x_out *out; +u64 fvco, divo, coarse; +u8 pll_idx, fine; +s32 phase_adj; +int rc; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (out_idx >= info->num_outputs) +return -EINVAL ; + +/* An unrouted output has only a placeholder in pll_idx. */ +if (!sitdev->out[out_idx].routed) +return -ENODEV ; + + out = &sitdev->out[out_idx]; + pll_idx = out->pll_idx; +if (pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + chan = &sitdev->chan[pll_idx]; + + rc =sit9531x_get_fvco (sitdev, pll_idx, &fvco); +if (rc) +return rc == -ENODATA ? -ENODEV : rc; + +/* Fref * DIVN outside the VCO band is not the rate the PLL runs at. */ +if (!sit9531x_fvco_in_band (pll_idx, fvco)) { +dev_dbg (sitdev->dev, +"out%u: PLL%c Fvco %llu Hz is outside its VCO band, delay not settable\n" , + out_idx,'A' + pll_idx, fvco); +return -EINVAL ; + } + +/* Take the period from the divider; the cached rate is whole hertz. */ + rc =sit9531x_output_divo_read (sitdev, out_idx, &divo); +if (rc) +return rc == -ENODATA ? -ENODEV : rc; + + rc =sit9531x_output_phase_encode (fvco, divo, phase_ps, &coarse, &fine, + &phase_adj); +if (rc) +return rc; + + rc =sit9531x_output_phase_bytes_read (sitdev, out_idx, old_bytes); +if (rc) +return rc; +sit9531x_output_phase_bytes_build (old_bytes, coarse, fine, new_bytes); + +/* +* Skip the write if the quantized bytes are unchanged; a rewrite +* restarts the divider phase of every output on the PLL. +*/ + same = !memcmp (old_bytes, new_bytes,sizeof (new_bytes)) && + !out->phase_stale; +if (same && !chan->flush_pending) { + rc =0 ; + goto cache; + } + +if (!same) { +/* +* The delay bytes take effect on a small-change update, as in +* Dely_program_output.py; only a divider rewrite needs the +* programming state. +*/ + rc =sit9531x_outsys_debug_open (sitdev); +if (rc) +return rc; + + rc =sit9531x_output_phase_bytes_write (sitdev, out_idx, + new_bytes, old_bytes, + &bytes_back); + bytes_in = !rc; +if (!rc) + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_SMALL_UPDATE_CMD ); +sit9531x_outsys_debug_close (sitdev); +if (rc) { +if (bytes_in) { + out->phase_stale = true; + out->retime_ps = phase_ps; + out->retime_pending = true; + }else if (!bytes_back) { + out->phase_stale = true; + chan->flush_pending = true; + } +return rc; + } + } + +/* A flush pulse into open loops can be lost when they re-lock */ +if (sitdev->loops_open) { + rc =sit9531x_prg_relock (sitdev); +if (rc) { + chan->flush_pending = true; + goto cache; + } + } + +/* +* Restart the divider phase so the delay applies against a known edge. +*/ + rc =sit9531x_output_phase_flush (sitdev, pll_idx); + +cache: +/* Cache what the registers hold */ + out->phase_adj = phase_adj; + out->phase_stale = false; + out->retime_pending = false; + +/* +* A delay that quantized to zero needs no re-time: the quantum is the +* VCO cycle, not the output period. +*/ + out->phase_armed = phase_adj !=0 ; + +if (chan->flush_pending) +return rc; +if (rc) +dev_warn (sitdev->dev, +"out%u: delay applied, the flush left something to put back (%d)\n" , + out_idx, rc); + +return 0 ; +}/* * Clear the write-1-to-clear notification registers on page 0 and the clock
@@ -2428,6 +3052,9 @@ static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev) }for (i =0 ; i < sitdev->info->num_outputs; i++) { +bool beyond; +s64 phase_ps; +mutex_lock (&sitdev->multiop_lock); rc =sit9531x_out_state_fetch (sitdev, i);mutex_unlock (&sitdev->multiop_lock);
@@ -2436,6 +3063,23 @@ static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev) "Failed to fetch output %u state: %d\n", i, rc);return rc; } + +/* +* The profile can set a delay; read it so a request of 0 ps can +* clear it. +*/ +mutex_lock (&sitdev->multiop_lock); + rc =sit9531x_output_phase_read (sitdev, i, &phase_ps, &beyond); +mutex_unlock (&sitdev->multiop_lock); +if (!rc) { + sitdev->out[i].phase_adj = phase_ps; + sitdev->out[i].phase_armed = !beyond && phase_ps; + }else if (rc != -ENODATA ) { +dev_err (sitdev->dev, +"Failed to read output %u delay: %d\n" , + i, rc); +return rc; + } }mutex_lock (&sitdev->multiop_lock);
@@ -2559,6 +3203,25 @@ static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx) 'A' + pll_idx); } +/* +* Re-time the output delay after a failed rate change. Caller must hold +* sitdev->multiop_lock. +*/ +static void sit9531x_retime_retry (struct sit9531x_dev *sitdev,u8 out_idx) +{ +struct sit9531x_out *out = &sitdev->out[out_idx]; +s64 was; + +if (!out->retime_pending) +return ; + + was = out->phase_adj; +if (!sit9531x_output_phase_adjust_set (sitdev, out_idx, out->retime_ps)) +dev_info (sitdev->dev,"out%u: delay re-timed\n" , out_idx); +if (out->phase_adj != was || out->phase_stale) + out->ntf_pending = true; +} +/* * Write back the priority table after a failed write. Caller must hold * sitdev->multiop_lock.
@@ -2629,6 +3292,18 @@ static void sit9531x_reselect(struct sit9531x_dev *sitdev, u8 pll_idx) 'A' + pll_idx); } +/* Run a pending output-divider flush. Caller must hold sitdev->multiop_lock. */ +static void sit9531x_flush_retry (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +if (!sitdev->chan[pll_idx].flush_pending) +return ; + +sit9531x_output_phase_flush (sitdev, pll_idx); +if (!sitdev->chan[pll_idx].flush_pending) +dev_info (sitdev->dev,"PLL%c: output dividers realigned\n" , +'A' + pll_idx); +} +/* * Retry pending writes, then read each PLL's state; return true if any state * read succeeds.
@@ -2644,11 +3319,20 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)sit9531x_prg_relock (sitdev); else if (sitdev->outsys_key_pending) sit9531x_outsys_debug_close(sitdev); +sit9531x_phase_flush_undo_retry (sitdev ); +for (i =0 ; i < sitdev->info->num_outputs; i++) +sit9531x_retime_retry (sitdev, i);sit9531x_input_off_retry (sitdev);for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {sit9531x_table_back_retry (sitdev, i);sit9531x_ho_release_retry (sitdev, i); +/* +* A flush pulse sent into open loops may be lost when they +* re-lock. +*/ +if (!sitdev->loops_open) +sit9531x_flush_retry (sitdev, i); rc =sit9531x_chan_state_fetch (sitdev, i);if (rc) { sitdev->chan[i].stale = true;
@@ -2966,8 +3650,13 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev)dev_warn (sitdev->dev,"PLL%c left in forced holdover\n" ,'A' + i); } +mutex_unlock (&sitdev->multiop_lock); +/* +* Lock the loops first: a re-time ends in a flush, and a flush pulse +* into open loops can be lost. The undo runs after every flush. +*/ mutex_lock (&sitdev->multiop_lock);if (sitdev->loops_open) {sit9531x_prg_relock (sitdev);
@@ -2977,6 +3666,32 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev) }else if (sitdev->outsys_key_pending) {sit9531x_outsys_debug_close (sitdev); } +for (i =0 ; i < sitdev->info->num_outputs; i++) { +sit9531x_retime_retry (sitdev, i); +if (sitdev->out[i].retime_pending) +dev_warn (sitdev->dev, +"out%u: delay left not re-timed to its rate\n" , + i); + } +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +if (!sitdev->loops_open) +sit9531x_flush_retry (sitdev, i); +if (sitdev->chan[i].flush_pending) +dev_warn (sitdev->dev, +"PLL%c: output dividers left unaligned\n" , +'A' + i); + } +sit9531x_phase_flush_undo_retry (sitdev); +if (sitdev->flush_ctrl_pending) +dev_warn (sitdev->dev, +"phase flush trigger source select not put back\n" ); +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +if (!(sitdev->flush_arm_pending &BIT (i))) +continue ; +dev_warn (sitdev->dev,"PLL%c: on-demand phase flush left %s\n" , +'A' + i, + (sitdev->flush_armed &BIT (i)) ?"parked" :"armed" ); + }mutex_unlock (&sitdev->multiop_lock); }
drivers/dpll/sit9531x/core.h +30 -0
@@ -27,6 +27,8 @@#define SIT9531X_MAX_INPUTS 8#define SIT9531X_NUM_INPUT_PAIRS (SIT9531X_MAX_INPUTS / 2)#define SIT9531X_MAX_OUTPUTS 12 +/* Output phase-adjust range advertised to the core, +/-1 ms in ps */ +#define SIT9531X_OUT_PHASE_ADJ_MAX_PS 1000000000/* * INTSYNC, the inter-PLL sync line, is two pins: an input pin on the PLL that * locks to it, numbered after the inputs and the xtal, and an output pin on the
@@ -111,6 +113,13 @@ struct sit9531x_ref {* @routed: mapped to @pll_idx by the initial configuration; an unrouted * output has no pin * @pll_idx: PLL driving this output (0-3) +* @phase_stale: programmed delay may differ from @phase_adj +* @phase_armed: non-zero in-range delay programmed; a rate change re-times it +* @phase_adj: realized delay in whole VCO cycles plus 30 ps steps, in the +* form nearer to zero; an out-of-range profile delay is held as the +* positive decode +* @retime_pending: re-timed delay not yet applied; the poll applies @retime_ps +* @retime_ps: delay to apply while @retime_pending */ struct sit9531x_out {u64 freq;
@@ -122,6 +131,11 @@ struct sit9531x_out {u8 hiz_keep;bool routed;u8 pll_idx; +s64 phase_adj; +bool phase_armed; +bool phase_stale; +bool retime_pending; +s32 retime_ps; };/*
@@ -148,6 +162,8 @@ struct sit9531x_out {* rewrites the table * @reselect_armed: no poll since probe or resume; the first poll rewrites * the table of a PLL in holdover while a listed source has signal +* @flush_pending: output divider realignment flush not yet triggered after +* a rate or delay commit * @table_pending: priority table partly written or not latched; the PLL * stays in forced holdover * @table_back: table reported and to be rewritten while @table_pending
@@ -176,6 +192,7 @@ struct sit9531x_chan {bool ho_release_pending;u8 live_top;bool reselect_armed; +bool flush_pending;bool table_pending;u8 table_back[SIT9531X_PRIO_MAX_SLOTS ];u8 prio_srcs[SIT9531X_PRIO_MAX_SLOTS ];
@@ -215,6 +232,10 @@ struct sit9531x_chan {* band; written under @multiop_lock * @loops_open: output loops not yet re-locked * @outsys_key_pending: output-system debug key not closed +* @flush_ctrl_pending: @flush_ctrl still to be written back +* @flush_ctrl: trigger register value to restore +* @flush_arm_pending: bit per PLL whose flush enable is still to be restored +* @flush_armed: of those, the PLLs the profile arms */ struct sit9531x_dev {struct device *dev;
@@ -247,6 +268,10 @@ struct sit9531x_dev {bool loops_open;bool outsys_key_pending; +bool flush_ctrl_pending; +u8 flush_ctrl; +u8 flush_arm_pending; +u8 flush_armed; }; int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
@@ -284,6 +309,11 @@ int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,int sit9531x_output_freq_get (struct sit9531x_dev *sitdev,u8 out_idx,u64 *frequency); +int sit9531x_output_phase_read (struct sit9531x_dev *sitdev,u8 out_idx, +s64 *phase_ps,bool *beyond); +int sit9531x_output_phase_adjust_set (struct sit9531x_dev *sitdev, +u8 out_idx,s32 phase_ps); +static inline u8 sit9531x_pll_page (u8 pll_idx) {return SIT9531X_PAGE_PLLA + pll_idx;
drivers/dpll/sit9531x/dpll.c +116 -3
158 lines not on this page · raw message
drivers/dpll/sit9531x/prop.c +14 -0
@@ -170,6 +170,20 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev, props->dpll_props.capabilities =DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; curr_freq =0 ; + +/* +* The part takes a delay anywhere within the output period; +* +/-1 ms is a round figure within the s32 ps attribute. +*/ + props->dpll_props.phase_range.min = + -SIT9531X_OUT_PHASE_ADJ_MAX_PS ; + props->dpll_props.phase_range.max = +SIT9531X_OUT_PHASE_ADJ_MAX_PS ; +/* +* The 30 ps fine step is not advertised; requests are rounded +* to the nearest achievable delay. +*/ + props->dpll_props.phase_gran =1 ; }sit9531x_prop_pin_package_label_set (sitdev, props, dir, index);
drivers/dpll/sit9531x/regs.h +29 -0
@@ -158,6 +158,35 @@#define SIT9531X_DEBUG_UNLOCK_VAL 0xC3#define SIT9531X_DEBUG_LOCK_VAL 0x00 +/* +* Per-output phase delay: 34-bit coarse in VCO cycles plus a 3-bit fine +* field in 30 ps steps, in a five-byte block PROG6..PROG2: +* +* base + 0 PROG6 [7:5] OPSTG_VCASC_BUMP (preserve) +* [4:2] PRG_RST_FINE_DELAY[2:0] +* [1:0] PRG_RST_DELAY[33:32] +* base + 1..4 PROG5..PROG2 PRG_RST_DELAY[31:0], MSB first +* +* Block base is 0x15 + 16 * (slot % 6), slot from clkout_map[]; slots 0-5 +* on page 3, 6-11 on page 4. +*/ +#define SIT9531X_OUT_PRG_DELAY_BASE 0x15 +#define SIT9531X_OUT_PRG_SLOT_STRIDE 0x10 +#define SIT9531X_OUT_PRG_BYTES 5 +#define SIT9531X_OUT_PRG_OPSTG_MASK 0xE0 +#define SIT9531X_OUT_PRG_FINE_SHIFT 2 +#define SIT9531X_OUT_PRG_FINE_MASK 0x1C/* bits [4:2] */ +#define SIT9531X_OUT_PRG_COARSE_HI_MASK 0x03/* bits [1:0] */ +/* +* The divider takes two VCO cycles to act on a programmed delay; the encoded +* value includes them, as in the reference flow. +*/ +#define SIT9531X_OUT_PRG_DIVO_CYCLES 2 + +#define SIT9531X_OUT_PRG_FINE_STEP_PS 30 +#define SIT9531X_OUT_PRG_FINE_MAX 7/* 3-bit field */ +#define SIT9531X_OUT_PRG_COARSE_BITS 34 +/* * Register-triggered phase flush: DIVO_PHASE_SEL_REG selects the register * trigger; pulsing DIVO_PHASE_TRIG high then low flushes. Preserve the OEb
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 11/13] dpll: sit9531x: add support to adjust output phase
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] dpll: sit9531x: stale phase_adj cached when retime_pending is set on error - [Medium] dpll…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] dpll: sit9531x: stale phase_adj cached when retime_pending is set on error
- [Medium] dpll: sit9531x: spurious pin notifications while retime_pending is set
- [Medium] dpll: sit9531x: phase flush marked fired before trigger is cleared low
- [Low] dpll: sit9531x: unsigned underflow in sit9531x_output_phase_read()
--
commit 143a1b7f99e490d4972a0786a10e854c727940fb
Author: Oleg Zadorozhnyi <[email protected]>
dpll: sit9531x: add support to adjust output phase
This commit adds output phase-adjust support to the sit9531x DPLL driver, including register encoding/decoding, re-timing on output frequency changes, and deferred retries for failed phase flushes and re-time writes.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 29 lines
drivers/dpll/sit9531x/core.c +25
-0@@ -1559,6 +1576,65 @@ static int sit9531x_pll_small_update(struct sit9531x_dev *sitdev, u8 pll_idx) SIT9531X_SMALL_UPDATE_CMD); } +static int sit9531x_pll_small_update_close (struct sit9531x_dev *sitdev, +u8 pll_idx) +{ +return sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_SMALL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +} + +/* +* Undo a phase flush: restore the trigger select and the flush enable of @plls +* from @armed. +*/ +static int sit9531x_phase_flush_undo (struct sit9531x_dev *sitdev, +bool ctrl_back,u8 ctrl,u8 plls,u8 armed) +{ +const u8 en =SIT9531X_PLL_PHFL_ON_DEMAND_EN ; +int rc =0 , ret; +u8 i; + +if (ctrl_back) { + rc =sit9531x_write_close (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , + ctrl); + sitdev->flush_ctrl_pending = !!rc; + sitdev->flush_ctrl = ctrl; + }
[ ... ]
Quoted 19 lines
drivers/dpll/sit9531x/core.c +8
-4@@ -1638,40 +1725,19 @@ static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)*/ rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl |SIT9531X_DIVO_PHASE_TRIG ); - -restore: - ret =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , orig); + fired = !rc; + +undo: + touched = parked; +if (armed_here && !(armed_mask &BIT (pll_idx))) + touched |=BIT (pll_idx); + ret =sit9531x_phase_flush_undo (sitdev, ctrl_back, orig, touched, + armed_mask);if (ret && !rc) rc = ret; -disarm:
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx) · line 1743
Quoted 5 lines
drivers/dpll/sit9531x/core.c +2
-0+out: + sitdev->chan[pll_idx].flush_pending = !fired;return rc; }
[Severity: Medium]
As reported by Jakub Kicinski on v15 [1], if the write in sit9531x_phase_flush_undo() to restore SIT9531X_REG_GPIO_FUNC_CTRL1 fails, does sit9531x_phase_flush_undo() disarm the target PLL and re-arm the parked sibling PLLs while SIT9531X_DIVO_PHASE_TRIG is still asserted high?
Because fired is already true, sitdev->chan[pll_idx].flush_pending is also cleared, so when sit9531x_phase_flush_undo_retry() later writes SIT9531X_REG_GPIO_FUNC_CTRL1 low, the pulse can complete with the sibling PLLs armed instead of the target PLL and the target PLL's flush is not retried.
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -1837,12 +1904,361 @@ static int sit9531x_output_divo_read(struct sit9531x_dev *sitdev, u8 out_idx,
[ ... ]
Quoted 21 lines
drivers/dpll/sit9531x/core.c +21
-0+int sit9531x_output_phase_read (struct sit9531x_dev *sitdev,u8 out_idx, +s64 *phase_ps,bool *beyond) +{ +const struct sit9531x_chip_info *info = sitdev->info; +u8 bytes[SIT9531X_OUT_PRG_BYTES ], fine; +u64 coarse =0 , fvco, ps, divo; +int rc; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (out_idx >= info->num_outputs) +return -EINVAL ; + + *beyond = false; + +if (!sitdev->out[out_idx].routed) +return -ENODATA ; + + rc =sit9531x_get_fvco (sitdev, sitdev->out[out_idx].pll_idx, &fvco); +if (rc) +return rc;
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_output_divo_read(struct sit9531x_dev *sitdev, u8 out_idx, · line 2242
Quoted 12 lines
drivers/dpll/sit9531x/core.c +12
-0+if (!rc) { +u64 t_out_ps =mul_u64_u64_div_u64 (divo,1000000000000ULL , + fvco); + +if (ps >= t_out_ps) + ps -= t_out_ps; +if (ps > t_out_ps - ps && + t_out_ps - ps <=SIT9531X_OUT_PHASE_ADJ_MAX_PS ) { + *phase_ps = -(s64)(t_out_ps - ps); +return 0 ; + } + }
[Severity: Low]
Can t_out_ps - ps underflow when sit9531x_get_fvco() returns an out-of-band VCO frequency above SIT9531X_FVCO_HIGHBAND_MAX?
sit9531x_get_fvco() only rejects fvco < SIT9531X_FVCO_LOWBAND_MIN and warns without returning an error when fvco is above the PLL's VCO band. If fvco is high enough that t_out_ps is less than half of the 210 ps maximum fine delay (for example, divo == 1 and fine == 7 with fvco > 9.53 GHz), a single ps -= t_out_ps leaves ps > t_out_ps, wrapping the unsigned subtraction t_out_ps - ps and returning an unfolded *phase_ps larger than the output period.
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -1915,20 +2421,138 @@ int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,
[ ... ]
Quoted 20 lines
drivers/dpll/sit9531x/core.c +20
-0+if (!same) { +/* +* The delay bytes take effect on a small-change update, as in +* Dely_program_output.py; only a divider rewrite needs the +* programming state. +*/ + rc =sit9531x_outsys_debug_open (sitdev); +if (rc) +return rc; + + rc =sit9531x_output_phase_bytes_write (sitdev, out_idx, + new_bytes, old_bytes, + &bytes_back); + bytes_in = !rc; +if (!rc) + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_SMALL_UPDATE_CMD ); +sit9531x_outsys_debug_close (sitdev); +if (rc) { +if (bytes_in) {
drivers/dpll/sit9531x/core.c int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx, · line 2519
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ out->phase_stale = true; + out->retime_ps = phase_ps; + out->retime_pending = true; + }else if (!bytes_back) { + out->phase_stale = true; + chan->flush_pending = true; + } +return rc; + } + }
[Severity: Medium]
As reported by Jakub Kicinski on v15 [2], when arming out->retime_pending on error here (and in the retime && landed error branch of sit9531x_output_freq_set()), does leaving out->phase_adj at its previous value cause sit9531x_dpll_output_pin_phase_adjust_get() to report the old delay while a re-time to out->retime_ps is queued?
Because sit9531x_dpll_output_pin_phase_adjust_get() skips sit9531x_output_phase_read() while out->retime_pending is set, userspace reads the old out->phase_adj; if userspace then requests that reported value before the next poll, dpll_pin_phase_adj_set() treats the request as a no-op and sit9531x_retime_retry() overwrites the pin delay with out->retime_ps on the next poll tick.
[ ... ]
Quoted 12 lines
drivers/dpll/sit9531x/core.c +8
-0@@ -2559,6 +3203,25 @@ static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx) 'A' + pll_idx); } +/* +* Re-time the output delay after a failed rate change. Caller must hold +* sitdev->multiop_lock. +*/ +static void sit9531x_retime_retry (struct sit9531x_dev *sitdev,u8 out_idx) +{ +struct sit9531x_out *out = &sitdev->out[out_idx]; +s64 was;
drivers/dpll/sit9531x/core.c static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx) · line 3223
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ +if (!out->retime_pending) +return ; + + was = out->phase_adj; +if (!sit9531x_output_phase_adjust_set (sitdev, out_idx, out->retime_ps)) +dev_info (sitdev->dev,"out%u: delay re-timed\n" , out_idx); +if (out->phase_adj != was || out->phase_stale) + out->ntf_pending = true; +}
[Severity: Medium]
Does checking out->phase_stale without !out->retime_pending here (and in sit9531x_dpll_output_pin_phase_adjust_set() and sit9531x_dpll_output_pin_frequency_set()) emit a pin change notification on every failed retry while a re-time is pending?
Whenever out->retime_pending is set, out->phase_stale is also true. If sit9531x_output_phase_adjust_set() fails during sit9531x_retime_retry(), out->phase_stale sets out->ntf_pending = true, and sit9531x_dpll_output_ntf_pending() skips hardware readback because out->retime_pending is true and returns true, sending a notification with unchanged attributes on every failed poll tick.
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
[email protected]
AI reviewRe: [PATCH net-next v16 11/13] dpll: sit9531x: add support to adjust output phase
In reply to Ali RouhiThank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 6 · Low: 6
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] A user request to restore the old delay can be dropped, and the poll then applies the earlier request that failed.
- [Medium] Output pins advertise DPLL_A_PIN_PHASE_ADJUST_MIN/MAX = -/+SIT9531X_OUT_PHASE_ADJUST_MAX_PS (1e9 ps).
- [Medium] While a pending re-time keeps failing, every poll sends a spurious DPLL pin-change notification.
- [Medium] sit9531x_output_phase_flush() sets fired = !rc as soon as DIVO_PHASE_TRIG has been written high, and that clears…
- [Medium] sit9531x_output_phase_adjust_set() decides whether to skip the write by comparing raw bytes ('same = !memcmp(old_bytes, new_bytes,…
- [Medium] After writing the PRG_RST_DELAY bytes, sit9531x_output_phase_adjust_set() issues the small-change update only…
- [Low] On a rate change, sit9531x_output_freq_set() re-encodes the cached out->phase_adj.
- [Low] Output pins advertise DPLL_A_PIN_PHASE_ADJUST_GRAN = 1 ps (prop.c), but the hardware grid is whole VCO cycles (about 128-203 ps)…
- [Low] The comment on sit9531x_retime_retry() ('Re-time the output delay after a failed rate change') and the core.h kernel-doc for…
- [Low] sit9531x_dpll_output_ntf_pending() returns false on any sit9531x_output_phase_read() error when 'out->phase_stale &&…
- [Low] In the teardown retry path the last retry of the output-system debug-key close runs before the new per-output sit9531x_retime_retry()…
- [Low] sit9531x_output_phase_read() converts the PRG_RST_DELAY cycle count to picoseconds, and folds it by the output period, using the…
--
dpll: sit9531x: add support to adjust output phase
This adds phase_adjust_get/set callbacks for sit9531x output pins. A delay is programmed as whole VCO cycles plus 30 ps fine steps, and an advance is stored as the complementary delay within the output period. A rate change re-times a programmed delay, and partly failed writes (flush, flush restore, re-time) are recorded and retried from the poll and at removal.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 5 lines
drivers/dpll/sit9531x/core.c +0
-1@@ -1638,40 +1725,19 @@ static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)*/ rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl |SIT9531X_DIVO_PHASE_TRIG ); -
drivers/dpll/sit9531x/core.c static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx) · line 1735
Quoted 10 lines
drivers/dpll/sit9531x/core.c +8
-2-restore: - ret =sit9531x_write_u8 (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , orig); + fired = !rc; + +undo: + touched = parked; +if (armed_here && !(armed_mask &BIT (pll_idx))) + touched |=BIT (pll_idx); + ret =sit9531x_phase_flush_undo (sitdev, ctrl_back, orig, touched, + armed_mask);
[Severity: Medium]
Is it safe to mark the flush as fired here, before the falling edge of the pulse? regs.h describes the flush as pulsing DIVO_PHASE_TRIG high then low. The low write now happens in sit9531x_phase_flush_undo(), through sit9531x_write_close().
If every attempt of that write fails, flush_ctrl_pending is set and TRIG stays high. sit9531x_phase_flush_undo() still goes on to re-arm every parked PLL:
if (ctrl_back) {
rc = sit9531x_write_close(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1,
ctrl);
sitdev->flush_ctrl_pending = !!rc;
sitdev->flush_ctrl = ctrl;
}
for (i = 0; i < SIT9531X_NUM_PLLS; i++) {
...
ret = sit9531x_update_pll_close(sitdev, i,
SIT9531X_PLL_REG_PHFL_CTRL, en,
(armed & BIT(i)) ? en : 0);The deferred write of orig then runs from the poll, or at the start of the next sit9531x_output_phase_flush() before any parking. At that point every PLL the profile arms is armed.
If the hardware acts on the falling edge, could this restart the dividers of PLLs that nobody asked to flush? The target PLL's chan->flush_pending would also already be cleared.
Before this patch, a failed restore was completed by the next flush's "orig | SIT9531X_DIVO_PHASE_SEL_REG" write, which runs after parking.
Quoted 2 lines
drivers/dpll/sit9531x/core.c +0
-0if (ret && !rc) rc = ret;
[ ... ]
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+int sit9531x_output_phase_read (struct sit9531x_dev *sitdev,u8 out_idx, +s64 *phase_ps,bool *beyond) +{
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_output_divo_read(struct sit9531x_dev *sitdev, u8 out_idx, · line 2206
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+ rc =sit9531x_get_fvco (sitdev, sitdev->out[out_idx].pll_idx, &fvco); +if (rc) +return rc;
[Severity: Low]
Should this readback apply the same sit9531x_fvco_in_band() check that sit9531x_output_phase_adjust_set() does?
When the PLL is out of band, sit9531x_get_fvco() only warns. Its comment says Fref * DIVN is then usually not the rate the PLL runs at, but it still returns 0.
As written, sit9531x_dev_state_fetch(), the getter, the notification path and sit9531x_output_freq_set() all cache and report a delay converted with that rate. They also set phase_armed from it.
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -1851,28 +2267,118 @@ int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +4
-0+/* +* The reset delay counts VCO cycles; an advance is stored as T_out - +* |advance| and must be re-encoded for the new period. Write it in the +* divider's programming window; a second flush would restart the PLL's
drivers/dpll/sit9531x/core.c int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx, · line 2295
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+* dividers. +*/ + rc =sit9531x_output_phase_bytes_read (sitdev, out_idx, old_bytes); +if (rc) +return rc; +sit9531x_output_phase_bytes_decode (old_bytes, &coarse, &fine); + beyond = !out->retime_pending && !out->phase_armed && out->phase_adj; +if (out->retime_pending || out->phase_armed || + ((coarse || fine) && !beyond)) { + held = out->retime_pending ? out->retime_ps : out->phase_adj;
[Severity: Low]
The comment above says only an advance needs re-encoding. However, out->phase_adj holds the nearer-to-zero form from sit9531x_output_phase_encode():
if (abs_ps > t_out_ps - abs_ps) *phase_adj = -(s32)(t_out_ps - abs_ps);
Take T_out = 10 ns and a request of +7000 ps. About 7 ns of cycles is programmed, and phase_adj is cached as -3000 with phase_armed set.
If the rate is then halved (T_out = 20 ns), held = -3000 is re-encoded as an advance: abs_ps = 20000 - 3000 = 17000 ps. Leaving the cycle count alone would have kept the 7 ns.
Is it intended that any positive delay above half the period becomes an advance on the next rate change? If so, could the comment be updated? The code re-encodes delays and advances the same way.
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+ + rc =sit9531x_output_phase_encode (fvco, divo, held, &coarse, + &fine, &phase_adj);
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -1915,20 +2421,138 @@ int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,
[ ... ]
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+int sit9531x_output_phase_adjust_set (struct sit9531x_dev *sitdev, +u8 out_idx,s32 phase_ps) +{
[ ... ]
drivers/dpll/sit9531x/core.c int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx, · line 2488
Quoted 6 lines
drivers/dpll/sit9531x/core.c +6
-0+ same = !memcmp (old_bytes, new_bytes,sizeof (new_bytes)) && + !out->phase_stale; +if (same && !chan->flush_pending) { + rc =0 ; + goto cache; + }
[Severity: Medium]
Does this raw-byte comparison match the decoder? sit9531x_output_phase_bytes_decode() treats register values from 0 up to SIT9531X_OUT_PRG_DIVO_CYCLES as no delay:
*coarse = (prg_coarse > SIT9531X_OUT_PRG_DIVO_CYCLES) ? prg_coarse - SIT9531X_OUT_PRG_DIVO_CYCLES : 0;
sit9531x_output_phase_bytes_build(), however, always writes coarse + 2.
Suppose the profile left PRG_RST_DELAY at 0, which is reported as 0 ps. A request that quantizes to zero, such as 10 ps, builds PROG2 = 2 and fails the memcmp.
Would this then rewrite the bytes and call sit9531x_output_phase_flush()? That restarts the divider phase of every output on the PLL, or issues SIT9531X_PLL_DIRECTIVE_RESTART when PHFL is off. The realized delay does not change.
dpll_pin_phase_adj_set() short-circuits an exact 0 ps request, because the getter reports 0. Small non-zero requests still reach the driver.
Would comparing the decoded coarse and fine values avoid this?
Quoted 2 lines
drivers/dpll/sit9531x/core.c +2
-0+ +if (!same) {
[ ... ]
drivers/dpll/sit9531x/core.c int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx, · line 2507
Quoted 8 lines
drivers/dpll/sit9531x/core.c +8
-0+ rc =sit9531x_output_phase_bytes_write (sitdev, out_idx, + new_bytes, old_bytes, + &bytes_back); + bytes_in = !rc; +if (!rc) + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_PRG_DIR_GEN , +SIT9531X_SMALL_UPDATE_CMD ); +sit9531x_outsys_debug_close (sitdev);
[Severity: Medium]
The small-change update goes only to page 3's copy of PRG_Directives (SIT9531X_REG_PRG_DIR_GEN). This includes slots 6-11, whose delay bytes are on page 4, and regs.h notes that every page has a copy at offset 0x0F.
Does the page 3 update cover the page 4 delay registers?
The flush also follows right after the key is closed, with no wait. The INTSYNC paths sleep 1-2 ms after a small update.
If the flush lands before the update latches, would the dividers restart against the old delay? phase_adj would still be cached as the new value, with neither phase_stale nor flush_pending set.
This depends on hardware behaviour that the source doesn't show, so it may be fine if Dely_program_output.py does the same.
drivers/dpll/sit9531x/core.c int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx, · line 2512
Quoted 5 lines
drivers/dpll/sit9531x/core.c +5
-0+if (rc) { +if (bytes_in) { + out->phase_stale = true; + out->retime_ps = phase_ps; + out->retime_pending = true;
[Severity: Medium]
In this branch the bytes landed but the small update failed. retime_ps now holds the new request and retime_pending is set, while out->phase_adj keeps the old value.
sit9531x_dpll_output_pin_phase_adjust_get() skips the readback while retime_pending is set, so it returns the old value.
If userspace then asks for that old value, for example to revert, dpll_pin_phase_adj_set() returns before calling the driver:
if (!ret && phase_adj == old_phase_adj) return 0;
retime_pending and retime_ps are never cleared, so the next poll runs:
sit9531x_dev_chan_states_update()
sit9531x_retime_retry()
sit9531x_output_phase_adjust_set(sitdev, out_idx, out->retime_ps)
Can this program the request the user had just replaced, even though the replacing request returned success?
The getter comment "Bytes waiting for a re-time are for the old rate" fits the freq_set path. Here the bytes are already for the current rate.
[ ... ]
drivers/dpll/sit9531x/core.c static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx) · line 3209
Quoted 8 lines
drivers/dpll/sit9531x/core.c +4
-0@@ -2559,6 +3203,25 @@ static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx) 'A' + pll_idx); } +/* +* Re-time the output delay after a failed rate change. Caller must hold +* sitdev->multiop_lock. +*/
[Severity: Low]
This isn't a bug, but this comment and the @retime_pending kernel-doc in core.h ("re-timed delay not yet applied") only cover the failed rate change case.
sit9531x_output_phase_adjust_set() also sets retime_pending and retime_ps when the small update fails after a plain delay write. In that case the poll applies a new user request rather than re-timing an existing delay.
Could the comments cover that case too?
Quoted 2 lines
drivers/dpll/sit9531x/core.c +2
-0+static void sit9531x_retime_retry (struct sit9531x_dev *sitdev,u8 out_idx) +{
[ ... ]
drivers/dpll/sit9531x/core.c static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx) · line 3222
Quoted 5 lines
drivers/dpll/sit9531x/core.c +5
-0+ was = out->phase_adj; +if (!sit9531x_output_phase_adjust_set (sitdev, out_idx, out->retime_ps)) +dev_info (sitdev->dev,"out%u: delay re-timed\n" , out_idx); +if (out->phase_adj != was || out->phase_stale) + out->ntf_pending = true;
[Severity: Medium]retime_pending is only ever set together with phase_stale = true.
sit9531x_output_phase_adjust_set() can fail before it reaches the cache label. Examples are -ENODEV from get_fvco or divo_read, -ERANGE from the encode, a bus error, or the bytes_in branch, which sets phase_stale again. In each case phase_stale stays true, so this condition is always true.
sit9531x_dpll_output_ntf_pending() skips the re-read while retime_pending is set, clears ntf_pending and returns true. sit9531x_dpll_changes_check() then calls dpll_pin_change_ntf().
Does this send a pin-change notification on every poll for as long as the retry keeps failing, even though nothing on the pin changed?
[ ... ]
drivers/dpll/sit9531x/core.c static void sit9531x_dev_stop(struct sit9531x_dev *sitdev) · line 3670
Quoted 6 lines
drivers/dpll/sit9531x/core.c +2
-0@@ -2977,6 +3666,32 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev) }else if (sitdev->outsys_key_pending) {sit9531x_outsys_debug_close (sitdev); } +for (i =0 ; i < sitdev->info->num_outputs; i++) { +sit9531x_retime_retry (sitdev, i);
[Severity: Low]
The last retry of the output-system debug key close runs before this loop.
Each sit9531x_retime_retry() can call sit9531x_output_phase_adjust_set(). That opens the key again with sit9531x_outsys_debug_open() and closes it with sit9531x_outsys_debug_close().
If that close fails, only outsys_key_pending is set. Nothing later in sit9531x_dev_stop() closes the key again.
Can the device be left at removal with the output-system debug registers unlocked? The same ordering seems to carry over to sit9531x_dev_pending_retry() later in the series, which the probe failure path also uses.
Quoted 5 lines
drivers/dpll/sit9531x/core.c +5
-0+if (sitdev->out[i].retime_pending) +dev_warn (sitdev->dev, +"out%u: delay left not re-timed to its rate\n" , + i); + }
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/dpll.c +0
-0
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/dpll.c +0
-0@@ -740,12 +749,105 @@ sit9531x_dpll_output_pin_state_on_dpll_set(const struct dpll_pin *pin,
[ ... ]
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_state_on_dpll_set(const struct dpll_pin *pin, · line 798
Quoted 7 lines
drivers/dpll/sit9531x/dpll.c +7
-0+/* +* A profile delay on a slow output can exceed the s32 attribute; leave +* it out. +*/ +if (phase_adj >S32_MAX ) +return -ENODATA ; + *phase_adjust = phase_adj;
[Severity: Medium]sit9531x_pin_props_get() advertises a phase_range of +/-SIT9531X_OUT_PHASE_ADJ_MAX_PS (1e9 ps), but this check only drops values above S32_MAX.
sit9531x_output_phase_read() flags a decode above 1e9 ps in *beyond but still returns it. Take a profile delay between 1 ms and about 2.147 ms on a slow output, such as 1.5 ms on a 1 PPS output. It would be reported above the DPLL_A_PIN_PHASE_ADJUST_MAX sent in the same message.
Writing that value back then fails in dpll_pin_phase_adj_set():
if (phase_adj > pin->prop.phase_range.max ||
phase_adj < pin->prop.phase_range.min) {Should the getter filter on the advertised range, or on the beyond flag, instead of S32_MAX?
[ ... ]
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_ntf_pending(struct sit9531x_dev *sitdev, · line 939
Quoted 11 lines
drivers/dpll/sit9531x/dpll.c +7
-0@@ -828,6 +930,17 @@ sit9531x_dpll_output_ntf_pending(struct sit9531x_dev *sitdev,return false;if (out->state_stale &&sit9531x_output_state_refresh (sitdev, pin->id))return false; +if (out->phase_stale && !out->retime_pending) { +bool beyond; +s64 phase_ps; + +if (sit9531x_output_phase_read (sitdev, pin->id, &phase_ps, + &beyond)) +return false;
[Severity: Low]
On any sit9531x_output_phase_read() error, this returns false before out->ntf_pending is cleared.
phase_read returns -ENODATA when the output is not routed, or when sit9531x_get_fvco() returns -ENODATA. Both can last indefinitely: a state refresh can clear routed, and an outside reconfiguration can change DIVN. In that state phase_stale is never cleared.
Would a pending pin-change notification for this output then never be sent, even one for an unrelated state change? Elsewhere the patch treats -ENODATA as an absent value.
[ ... ]
Quoted 5 lines
drivers/dpll/sit9531x/prop.c +0
-0@@ -170,6 +170,20 @@ sit9531x_pin_props_get(struct sit9531x_dev *sitdev,
[ ... ]
drivers/dpll/sit9531x/prop.c sit9531x_pin_props_get(struct sit9531x_dev *sitdev, · line 186
Quoted 5 lines
drivers/dpll/sit9531x/prop.c +5
-0+/* +* The 30 ps fine step is not advertised; requests are rounded +* to the nearest achievable delay. +*/ + props->dpll_props.phase_gran =1 ;
[Severity: Low]
Is 1 ps the right value for DPLL_A_PIN_PHASE_ADJUST_GRAN?
The hardware grid is whole VCO cycles plus 30 ps steps, folded modulo the output period. sit9531x_output_phase_encode() rounds every request to that grid, so a request the core accepts as a multiple of 1 ps reads back as a different value.
dpll.rst describes the attribute as the granularity the pin handles, and zl3073x advertises its real step (half the synth period). The grid here is not uniform, so there may be no single exact value. Userspace could still assume 1 ps resolution from this.
Quoted 1 line
}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 12/13 dpll: sit9531x: add support to get phase offset on the connected input
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
Report the phase difference between a PLL's reference and the PLL, read from the on-chip time-to-digital converter through the debug window as the documented procedure does. A read latches a sample and returns the previous one, so each sample is read three times. The sign bit is set when the reference edge comes first: a negative offset.
The offset is sampled when asked for, not by the poll: a sample is several dozen transfers per PLL. A sample that cannot be taken, on a bus error or with the output loops open, is an absent attribute, so one failed read does not end a pin dump.
Only the input the part feeds the PLL has an offset. Any other pin, a PLL without a reference, or a PLL that drives no enabled output returns -ENODATA and the core leaves the attribute out. The XO pin has none: it is the frequency base of every PLL, not an input the loop is steered to.
The debug taps moved for a sample are put back after it; a restore that fails is retried by the poll, at removal and on the probe failure path, which now runs the same retries as removal.
--- drivers/dpll/sit9531x/core.c | 359 ++++++++++++++++++++++++++++++----- drivers/dpll/sit9531x/core.h | 15 ++ drivers/dpll/sit9531x/dpll.c | 110 +++++++++++ drivers/dpll/sit9531x/regs.h | 19 ++ 4 files changed, 452 insertions(+), 51 deletions(-)
drivers/dpll/sit9531x/core.c +308 -51
@@ -262,6 +262,28 @@ static int sit9531x_update_pll_close(struct sit9531x_dev *sitdev, u8 pll_idx,return rc; } +/* +* Restore the debug taps a phase-offset read changed. The PLL page's debug +* window must already be open. +*/ +static int sit9531x_tap_restore (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +int rc; + + rc =sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_READ_CODE , + chan->tap_read_code); +if (!rc) + rc =sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_WRITE_CODE , + chan->tap_write_code); +if (!rc) + chan->tap_pending = false; + +return rc; +} + static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev, u8 index, unsigned int *force_reg,
@@ -807,12 +829,16 @@ static int sit9531x_prio_prg_commit(struct sit9531x_dev *sitdev)return 0 ; } -/* -* Four registers carry a nibble per lane: loss of signal and the fine and -* coarse frequency-drift flags. Caller must hold sitdev->multiop_lock, or run -* before registration. +/** +* sit9531x_input_mon_fetch - read the clock monitor status of every lane +* @sitdev: device pointer +* +* One nibble per lane: loss of signal, fine and coarse frequency drift. +* Caller must hold sitdev->multiop_lock, or run before registration. +* +* Return: 0 on success, <0 on error */ -static int sit9531x_input_mon_fetch (struct sit9531x_dev *sitdev) +int sit9531x_input_mon_fetch (struct sit9531x_dev *sitdev) {static const unsigned int regs[] = {SIT9531X_CLKMON_P_STATUS_01 ,SIT9531X_CLKMON_P_STATUS_23 ,
@@ -2594,6 +2620,176 @@ static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev)return 0 ; } +/** +* sit9531x_phase_offset_read - read phase difference via TDC +* @sitdev: device pointer +* @pll_idx: PLL index (0-3) +* @phase_offset: phase difference in 1/DPLL_PHASE_OFFSET_DIVIDER ps +* +* The TDC code is a 35-bit magnitude with a separate sign bit; +* phase_diff = tdc_code / fvco. The result is negative when the reference +* edge is the earlier one. Caller must hold sitdev->multiop_lock. +* +* Return: 0 on success, -ENODATA if Fvco is unknown, <0 on other errors +*/ +int sit9531x_phase_offset_read (struct sit9531x_dev *sitdev,u8 pll_idx, +s64 *phase_offset) +{ +u8 v, old_write_code, old_read_code; +struct sit9531x_chan *chan; +bool have_old = false; +int rc, ret, i; +s64 tdc_signed; +u64 fvco, mag; +u64 tdc_raw; +bool sign; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + chan = &sitdev->chan[pll_idx]; + +/* +* Read Fvco first; without it there is no reason to open the debug +* window. +*/ + rc =sit9531x_get_fvco (sitdev, pll_idx, &fvco); +if (rc) { +if (rc == -ENODATA ) +dev_dbg (sitdev->dev, +"PLL%c: Fvco unknown, skip TDC\n" , +'A' + pll_idx); +return rc; + } + + rc =sit9531x_write_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DEBUG , +SIT9531X_PLL_DEBUG_UNLOCK ); +if (rc) + goto relock; + +/* Restore pending taps before saving the selection */ +if (chan->tap_pending) { + rc =sit9531x_tap_restore (sitdev, pll_idx); +if (rc) + goto relock; + } + +/* Save the tap selection; the debug key does not cover the mux. */ + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_WRITE_CODE , + &old_write_code); +if (!rc) + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_READ_CODE , + &old_read_code); +if (rc) + goto relock; + + have_old = true; + +/* +* Enable the debug clock for taps below 200 kHz, then select the TDC +* tap. The modifier register also holds fields of other taps. +*/ + rc =sit9531x_update_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_WRITE_CODE , +SIT9531X_DBG_LOW_FREQ_CLK_BIT , +SIT9531X_DBG_LOW_FREQ_CLK_BIT ); +if (rc) + goto relock; + rc =sit9531x_write_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_READ_CODE , +SIT9531X_DBG_READ_CODE_TDC ); +if (rc) + goto relock; + +/* +* A status data read latches a sample and returns the previous one; +* read three times as the documented procedure does. The procedure +* leaves the status address unwritten. +*/ +for (i =0 ; i <SIT9531X_DBG_STATUS_READS ; i++) { + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_STATUS_DATA , + &v); +if (rc) + goto relock; + } + + tdc_raw =0 ; + + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_DATA_4 , &v); +if (rc) + goto relock; + sign = !!(v &BIT (SIT9531X_TDC_SIGN_BIT )); + tdc_raw = (u64)(v &SIT9531X_TDC_MAG_HI_MASK ) <<32 ; + + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_DATA_3 , &v); +if (rc) + goto relock; + tdc_raw |= (u64 )v <<24 ; + + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_DATA_2 , &v); +if (rc) + goto relock; + tdc_raw |= (u64 )v <<16 ; + + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_DATA_1 , &v); +if (rc) + goto relock; + tdc_raw |= (u64 )v <<8 ; + + rc =sit9531x_read_pll_u8 (sitdev, pll_idx, +SIT9531X_PLL_REG_DBG_DATA_0 , &v); +if (rc) + goto relock; + tdc_raw |= v; + +/* +* The sign bit is set when the reference edge comes first; the +* subsystem reports a pin that is earlier than the DPLL as negative. +*/ + tdc_signed = sign ? -(s64 )tdc_raw : (s64 )tdc_raw; + +/* +* phase_diff (ps) = tdc_code * 1e12 / fvco. Scale by the subsystem's +* divider before dividing to keep the fractional digits; one code is +* 203.45 ps at 4.9152 GHz. +*/ + mag =mul_u64_u64_div_u64 (tdc_signed <0 ? -tdc_signed : tdc_signed, +1000000000000ULL *DPLL_PHASE_OFFSET_DIVIDER , + fvco); + *phase_offset = tdc_signed <0 ? -(s64 )mag : (s64 )mag; + + rc =0 ; + +relock: +if (have_old) { + chan->tap_read_code = old_read_code; + chan->tap_write_code = old_write_code; + ret =sit9531x_tap_restore (sitdev, pll_idx); +if (ret) + chan->tap_pending = true; +if (ret && !rc) + rc = ret; + } + + ret =sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_DEBUG , +SIT9531X_PLL_DEBUG_LOCK ); + chan->key_pending = !!ret; +if (ret && !rc) + rc = ret; + +return rc; +} +/* Read the lane's receiver state from the Page 0x02 force and state bits */ static int sit9531x_ref_state_fetch (struct sit9531x_dev *sitdev,u8 index) {
@@ -2724,13 +2920,21 @@ static int sit9531x_chan_select_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)return 0 ; } -/* -* Read the reference the device feeds a PLL from the debug status bus; the -* active selection does not change on a fallback. The caller rules out free-run -* first and must hold sitdev->multiop_lock. +/** +* sit9531x_chan_routed_ref_read - read the reference the device feeds a PLL +* @sitdev: device pointer +* @pll_idx: PLL index (0-3) +* @ref: logical input index, SIT9531X_MAX_INPUTS for the XO, +* SIT9531X_INTSYNC_PIN_ID, or SIT9531X_REF_INVALID +* +* The device falls back between listed sources without changing the active +* selection, so read the source from the debug status bus. The caller rules +* out free-run first and must hold multiop_lock. +* +* Return: 0 on success, <0 on error */ -static int sit9531x_chan_routed_ref_read (struct sit9531x_dev *sitdev, -u8 pll_idx,u8 *ref) +int sit9531x_chan_routed_ref_read (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 *ref) {int rc, lock_rc;u8 v, i;
@@ -2768,6 +2972,7 @@ static int sit9531x_chan_routed_ref_read(struct sit9531x_dev *sitdev, lock_rc =sit9531x_write_pll_close (sitdev, pll_idx,SIT9531X_PLL_REG_DEBUG ,SIT9531X_PLL_DEBUG_LOCK ); + sitdev->chan[pll_idx].key_pending = !!lock_rc;return rc ? rc : lock_rc; }
@@ -3241,6 +3446,27 @@ static void sit9531x_table_back_retry(struct sit9531x_dev *sitdev, u8 pll_idx) 'A' + pll_idx); } +/* +* Restore the debug taps and close the debug window after a failed phase-offset +* read. Caller must hold sitdev->multiop_lock. +*/ +static void sit9531x_tap_back_retry (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; + +if (!chan->tap_pending && !chan->key_pending) +return ; + +if (chan->tap_pending && + !sit9531x_write_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_DEBUG , +SIT9531X_PLL_DEBUG_UNLOCK )) +sit9531x_tap_restore (sitdev, pll_idx); + + chan->key_pending = !!sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_DEBUG , +SIT9531X_PLL_DEBUG_LOCK ); +} +/* * Rewrite the priority table when a listed source returns to a PLL without a * reference; the write latches the active selection again. Each latch restarts
@@ -3327,6 +3553,7 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {sit9531x_table_back_retry (sitdev, i);sit9531x_ho_release_retry (sitdev, i); +sit9531x_tap_back_retry (sitdev, i);/* * A flush pulse sent into open loops may be lost when they * re-lock.
@@ -3579,55 +3806,30 @@ static void sit9531x_pin_nodes_check(struct sit9531x_dev *sitdev)fwnode_handle_put (pins); } -static int sit9531x_dev_start (struct sit9531x_dev *sitdev) +/* Retry the pending debug tap restore and debug window close */ +static void sit9531x_tap_pending_retry (struct sit9531x_dev *sitdev) { -struct sit9531x_dpll *sitdpll; -int rc; - - rc =sit9531x_dev_state_fetch (sitdev); -if (rc) -return rc; +u8 i;mutex_lock (&sitdev->multiop_lock); -sit9531x_eeprom_state_report (sitdev); -sit9531x_pll_states_report (sitdev); -mutex_unlock (&sitdev->multiop_lock); - -sit9531x_pin_nodes_check (sitdev); - -list_for_each_entry (sitdpll, &sitdev->dplls, list) { - rc =sit9531x_dpll_register (sitdpll); -if (rc) { -dev_err_probe (sitdev->dev, rc, -"Failed to register DPLL%u\n" , - sitdpll->id); - goto err_unregister; - } +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +sit9531x_tap_back_retry (sitdev, i); +if (sitdev->chan[i].tap_pending || sitdev->chan[i].key_pending) +dev_warn (sitdev->dev, +"PLL%c left with its debug taps moved or window open\n" , +'A' + i); } - -kthread_queue_delayed_work (sitdev->kworker, &sitdev->work,0 ); - -return 0 ; - -err_unregister: -list_for_each_entry_continue_reverse (sitdpll, &sitdev->dplls, list) -sit9531x_dpll_unregister (sitdpll); - -return rc; +mutex_unlock (&sitdev->multiop_lock); } -static void sit9531x_dev_stop (struct sit9531x_dev *sitdev) +/* +* Retry every pending write once more and report what is still pending. Call +* with the DPLLs unregistered. +*/ +static void sit9531x_dev_pending_retry (struct sit9531x_dev *sitdev) { -struct sit9531x_dpll *sitdpll;u8 i; -kthread_cancel_delayed_work_sync (&sitdev->work); - -list_for_each_entry (sitdpll, &sitdev->dplls, list) { -if (sitdpll->dpll_dev) -sit9531x_dpll_unregister (sitdpll); - } -/* * Write back tables first: forced holdover stays set while a table * write-back is pending.
@@ -3693,6 +3895,61 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev) (sitdev->flush_armed & BIT(i)) ? "parked" : "armed"); }mutex_unlock (&sitdev->multiop_lock); + +sit9531x_tap_pending_retry (sitdev); +} + +static int sit9531x_dev_start (struct sit9531x_dev *sitdev) +{ +struct sit9531x_dpll *sitdpll; +int rc; + + rc =sit9531x_dev_state_fetch (sitdev); +if (rc) +return rc; + +mutex_lock (&sitdev->multiop_lock); +sit9531x_eeprom_state_report (sitdev); +sit9531x_pll_states_report (sitdev); +mutex_unlock (&sitdev->multiop_lock); + +sit9531x_pin_nodes_check (sitdev); + +list_for_each_entry (sitdpll, &sitdev->dplls, list) { + rc =sit9531x_dpll_register (sitdpll); +if (rc) { +dev_err_probe (sitdev->dev, rc, +"Failed to register DPLL%u\n" , + sitdpll->id); + goto err_unregister; + } + } + +kthread_queue_delayed_work (sitdev->kworker, &sitdev->work,0 ); + +return 0 ; + +err_unregister: +list_for_each_entry_continue_reverse (sitdpll, &sitdev->dplls, list) +sit9531x_dpll_unregister (sitdpll); + +sit9531x_dev_pending_retry (sitdev); + +return rc; +} + +static void sit9531x_dev_stop (struct sit9531x_dev *sitdev) +{ +struct sit9531x_dpll *sitdpll; + +kthread_cancel_delayed_work_sync (&sitdev->work); + +list_for_each_entry (sitdpll, &sitdev->dplls, list) { +if (sitdpll->dpll_dev) +sit9531x_dpll_unregister (sitdpll); + } + +sit9531x_dev_pending_retry (sitdev); } static struct sit9531x_dpll_pin *
drivers/dpll/sit9531x/core.h +15 -0
@@ -167,6 +167,11 @@ struct sit9531x_out {* @table_pending: priority table partly written or not latched; the PLL * stays in forced holdover * @table_back: table reported and to be rewritten while @table_pending +* @tap_pending: debug taps not restored after a phase-offset read +* @tap_write_code: tap selection to restore while @tap_pending +* @tap_read_code: readback selection to restore while @tap_pending +* @key_pending: debug key not locked again after a phase-offset read or tap +* retry * @prio_srcs: cached priority table, a source code per slot * @prio_last: first slot of each source plus one, 0 if absent * @prio_mask: bit per canonical source in the priority table read back
@@ -195,6 +200,10 @@ struct sit9531x_chan {bool flush_pending;bool table_pending;u8 table_back[SIT9531X_PRIO_MAX_SLOTS ]; +bool tap_pending; +u8 tap_write_code; +u8 tap_read_code; +bool key_pending;u8 prio_srcs[SIT9531X_PRIO_MAX_SLOTS ];u8 prio_last[SIT9531X_PRIO_NUM_SRC ];u16 prio_mask;
@@ -314,6 +323,12 @@ int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,int sit9531x_output_phase_adjust_set (struct sit9531x_dev *sitdev,u8 out_idx,s32 phase_ps); +int sit9531x_chan_routed_ref_read (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 *ref); +int sit9531x_input_mon_fetch (struct sit9531x_dev *sitdev); +int sit9531x_phase_offset_read (struct sit9531x_dev *sitdev,u8 pll_idx, +s64 *phase_offset); +static inline u8 sit9531x_pll_page (u8 pll_idx) {return SIT9531X_PAGE_PLLA + pll_idx;
drivers/dpll/sit9531x/dpll.c +110 -0
140 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h +19 -0
@@ -229,6 +229,25 @@#define SIT9531X_PLL_REG_DIVN_NUM 0x32/* 4 bytes (0x32-0x35) */ #define SIT9531X_PLL_REG_DIVN_DEN 0x38/* 4 bytes (0x38-0x3B) */ +/* +* Signal pathway debug readback: Dig_Sys_ReadCode selects the tap, +* Dig_Sys_WriteCode its modifiers; a read of the debug status data register +* latches a sample into Dig_Sys_read7..read0. +*/ +#define SIT9531X_PLL_REG_DBG_READ_CODE 0xB3 +#define SIT9531X_PLL_REG_DBG_WRITE_CODE 0xB4 +#define SIT9531X_DBG_LOW_FREQ_CLK_BIT BIT(7) +#define SIT9531X_PLL_REG_DBG_DATA_0 0xB5/* [7:0] */ +#define SIT9531X_PLL_REG_DBG_DATA_1 0xB6/* [15:8] */ +#define SIT9531X_PLL_REG_DBG_DATA_2 0xB7/* [23:16] */ +#define SIT9531X_PLL_REG_DBG_DATA_3 0xB8/* [31:24] */ +#define SIT9531X_PLL_REG_DBG_DATA_4 0xB9/* [34:32] + sign */ + +/* Read code of the TDC phase tap, and the sign bit of its sample */ +#define SIT9531X_DBG_READ_CODE_TDC 69 +#define SIT9531X_TDC_SIGN_BIT 3 +#define SIT9531X_TDC_MAG_HI_MASK GENMASK(2, 0) +/* DIVN is carried as fixed point, in steps of 1e-12 of a whole divider */ #define SIT9531X_DIVN_SCALE 1000000000000ULL
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 12/13] dpll: sit9531x: add support to get phase offset on the connected input
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] sit9531x_phase_offset_read() (drivers/dpll/sit9531x/core.c) turns the TDC code into picoseconds by dividing by the Fvco that…
- [Low] The commit message says "The offset is sampled when asked for, not by the poll: a sample is several dozen transfers per PLL." That is…
- [Low] The patch adds sitdev->chan[pll_idx].key_pending = !!lock_rc; to the existing helper sit9531x_chan_routed_ref_read()…
--
dpll: sit9531x: add support to get phase offset on the connected input
This adds a phase_offset_get callback to the sit9531x input pins. It reads the PLL's on-chip TDC through the debug window and converts the code to picoseconds using the PLL's Fvco. The debug taps are saved and restored around each sample, and a failed restore or relock is retried by the poll, at removal and on the probe failure path.
Quoted 2 lines
The offset is sampled when asked for, not by the poll: a sample is several dozen transfers per PLL.
[Severity: Low]
Is this accurate for notifications?
The poll worker calls sit9531x_dpll_changes_check(). That function calls dpll_pin_change_ntf() for every selection pin whose state, operstate or prio changed. The core then builds the full pin message for that notification:
sit9531x_dpll_changes_check()
dpll_pin_change_ntf()
dpll_pin_event_send()
dpll_cmd_pin_get_one()
dpll_msg_add_phase_offset()
sit9531x_dpll_input_pin_phase_offset_get()So when the poll notifies the active input of a PLL (for example, the new reference after a switch), the poll worker does two input monitor fetches, two routed reference reads and a full TDC sample. A failure there can also set tap_pending or key_pending from the poll.
This only happens on change notifications, not on every poll tick. The callback also maps errors to -ENODATA, so the notification still goes out. Could the commit message be reworded to say this?
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 6 lines
drivers/dpll/sit9531x/core.c +2
-0@@ -2594,6 +2620,176 @@ static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev)return 0 ; } +/** +* sit9531x_phase_offset_read - read phase difference via TDC
[ ... ]
Quoted 3 lines
drivers/dpll/sit9531x/core.c +3
-0+int sit9531x_phase_offset_read (struct sit9531x_dev *sitdev,u8 pll_idx, +s64 *phase_offset) +{
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev) · line 2664
Quoted 12 lines
drivers/dpll/sit9531x/core.c +12
-0+/* +* Read Fvco first; without it there is no reason to open the debug +* window. +*/ + rc =sit9531x_get_fvco (sitdev, pll_idx, &fvco); +if (rc) { +if (rc == -ENODATA ) +dev_dbg (sitdev->dev, +"PLL%c: Fvco unknown, skip TDC\n" , +'A' + pll_idx); +return rc; + }
[Severity: Medium]
Is an out-of-band Fvco safe to use here?
sit9531x_get_fvco() returns 0 even when Fref * DIVN falls outside the PLL's VCO band. It only warns once:
drivers/dpll/sit9531x/core.c:sit9531x_get_fvco() {
...
/*
* Outside the PLL's VCO band, Fref * DIVN is usually not the rate the
* PLL runs at, as for a PLL fed from another PLL.
*/
if (!sit9531x_fvco_in_band(pll_idx, *fvco) &&
!(sitdev->fvco_band_warned & BIT(pll_idx))) {
...
return 0;
}This value has two other users, sit9531x_output_divo_calc() and sit9531x_output_phase_adjust_set(). Both return -EINVAL when sit9531x_fvco_in_band() fails ("rate not settable" and "delay not settable").
This function only checks rc, and then divides the TDC code by that Fvco:
mag = mul_u64_u64_div_u64(tdc_signed < 0 ? -tdc_signed : tdc_signed, 1000000000000ULL * DPLL_PHASE_OFFSET_DIVIDER, fvco);
The "one code is 203.45 ps at 4.9152 GHz" comment suggests one TDC code is one period of the real VCO. If so, wouldn't the reported phase offset be off by the ratio of the computed VCO rate to the real one? sit9531x_dpll_input_pin_phase_offset_get() would then return 0, and user space would receive the wrong value as a valid attribute.
Should this return -ENODATA when sit9531x_fvco_in_band() fails, so the attribute is left out?
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_chan_routed_ref_read(struct sit9531x_dev *sitdev, · line 2978
Quoted 8 lines
drivers/dpll/sit9531x/core.c +1
-0@@ -2768,6 +2972,7 @@ static int sit9531x_chan_routed_ref_read(struct sit9531x_dev *sitdev, lock_rc =sit9531x_write_pll_close (sitdev, pll_idx,SIT9531X_PLL_REG_DEBUG ,SIT9531X_PLL_DEBUG_LOCK ); + sitdev->chan[pll_idx].key_pending = !!lock_rc;return rc ? rc : lock_rc; }
[Severity: Low]
This line also changes the existing poll path. sit9531x_chan_routed_ref_read() runs from sit9531x_chan_state_fetch() on every poll and at probe, so a failed relock there now sets key_pending.
The next poll's sit9531x_tap_back_retry() then retries it. At removal, sit9531x_tap_pending_retry() warns "left with its debug taps moved or window open". Before this patch, that relock failure was never retried.
The retry itself looks reasonable, but the documentation only describes the phase-offset path. The kernel-doc in core.h says:
* @key_pending: debug key not locked again after a phase-offset read or tap
* retry
The comment above sit9531x_tap_back_retry() says "after a failed phase-offset read", and the commit message only mentions the taps moved for a sample.
Could the kernel-doc, the sit9531x_tap_back_retry() comment and the commit message also mention the routed reference read?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com
PATCH v16 13/13 dpll: sit9531x: model the inter-PLL sync line as a pair of pins
In reply to Ali RouhiFrom: Oleg Zadorozhnyi <[email protected]>
The part has an internal line by which one PLL drives the others as a reference. Model it as two pins: a source pin, one pin registered on every DPLL, whose state on a DPLL says whether that PLL drives the line, and an input pin on each destination, selectable like any input, reporting no signal while the line is not driven.
Taking the line writes the source pattern, the values of the reference sequence, to the source's EXT page under its debug key, then sets the global enable; the enable is set last because over a page holding part of the pattern it may drive the line from that page.
Giving the line up clears the enable and writes the disable pattern. The owner is read back from the four EXT pages. A page left with part of the pattern refuses a connect on any other PLL until its source pin is disconnected; an enable the driver does not recognize, or the pattern on two pages, refuses every connect.
Resume re-reads the line owner, the output mutes and the output delays, which a configuration reload may have changed, and drops the writes left pending from before suspend, logging each.
--- drivers/dpll/sit9531x/core.c | 732 ++++++++++++++++++++++++++++++++++- drivers/dpll/sit9531x/core.h | 32 ++ drivers/dpll/sit9531x/dpll.c | 428 ++++++++++++++++++-- drivers/dpll/sit9531x/regs.h | 3 + 4 files changed, 1166 insertions(+), 29 deletions(-)
drivers/dpll/sit9531x/core.c +726 -6
@@ -879,6 +879,8 @@ static bool sit9531x_prio_src_live(const struct sit9531x_dev *sitdev, u8 src) {u8 index =sit9531x_hw_src_input (src); +if (index ==SIT9531X_INTSYNC_PIN_ID ) +return sit9531x_intsync_driven (sitdev);if (index >= sitdev->info->num_inputs)return true;
@@ -1113,6 +1115,18 @@ static u8 sit9531x_prio_activesel_pick(struct sit9531x_dev *sitdev,return srcs[0 ]; } +static bool sit9531x_prio_table_lists_intsync (const u8 *srcs) +{ +u8 slot; + +for (slot =0 ; slot <SIT9531X_PRIO_MAX_SLOTS ; slot++) +if ((srcs[slot] &SIT9531X_PRIO_NIBBLE_MASK ) == +SIT9531X_PRIO_SRC_INTSYNC ) +return true; + +return false; +} +static int sit9531x_prio_table_commit (struct sit9531x_dev *sitdev,u8 pll_idx,const u8 *srcs) {
@@ -1129,6 +1143,11 @@ static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_idx,if (sit9531x_prio_src_usable (srcs[slot])) empty = false; +if (sitdev->intsync_stale && + (sit9531x_prio_table_lists_intsync (srcs) || +sit9531x_prio_table_lists_intsync (chan->prio_srcs))) +sit9531x_intsync_refresh (sitdev); +memcpy (back, chan->table_pending ? chan->table_back : chan->prio_srcs,sizeof (back));
@@ -2620,6 +2639,574 @@ static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev)return 0 ; } +/* +* Close the debug window on a PLL's EXT page; the key opens every debug +* register on the page while it holds the unlock value. +*/ +static int sit9531x_intsync_debug_lock (struct sit9531x_dev *sitdev,u8 ext_page) +{ +return sit9531x_write_close (sitdev, +SIT9531X_REG (ext_page, +SIT9531X_PLL_REG_DEBUG ), +SIT9531X_PLL_DEBUG_LOCK ); +} + +/* +* Values written to the source PLL's EXT page to enable or disable INTSYNC, +* which locks the frequency PLL to the phase PLL; they are the values of +* Intsync_enable_disable.py. +*/ +struct sit9531x_intsync_reg { +u8 offset; +u8 en_val; +u8 dis_val; +}; + +static const struct sit9531x_intsync_reg intsync_config[] = { + {0x2D ,0x02 ,0x00 }, + {0x50 ,0x08 ,0x00 }, + {0x51 ,0x04 ,0x00 }, + {0x54 ,0x02 ,0x00 }, + {0x55 ,0x28 ,0x20 }, + {0x5C ,0x0F ,0x00 }, + {0x5D ,0xFF ,0x00 }, + {0x6C ,0xDD ,0x00 }, +}; + +/* +* Find the PLL whose EXT page holds the INTSYNC enable pattern, whole or in +* part. Caller must hold sitdev->multiop_lock. +*/ +int sit9531x_intsync_src_detect (struct sit9531x_dev *sitdev) +{ +s8 src =-1 , partial =-1 ; +int rc, ret, n_en, n_dis; +u8 pll, ext_page; +u8 n_pages =0 ; +unsigned int i; +bool enabled; +u8 global; + +lockdep_assert_held (&sitdev->multiop_lock); + + rc =sit9531x_read_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , &global); +if (rc) +return rc; + enabled = global &BIT (SIT9531X_INTSYNC_EN_BIT ); + +/* +* Read the EXT pages even with the global enable clear; a page can hold +* the enable pattern under a clear bit. +*/ +for (pll =0 ; pll <SIT9531X_NUM_PLLS ; pll++) { + ext_page =SIT9531X_PLL_EXT_PAGE (pll); + +/* +* Open the EXT page's debug window to read the INTSYNC +* registers. +*/ + rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, +SIT9531X_PLL_REG_DEBUG ), +SIT9531X_PLL_DEBUG_UNLOCK ); +if (rc) { +sit9531x_intsync_debug_lock (sitdev, ext_page); +return rc; + } + + n_en =0 ; + n_dis =0 ; +for (i =0 ; i <ARRAY_SIZE (intsync_config); i++) { +u16 reg; +u8 val; + + reg =SIT9531X_REG (ext_page, intsync_config[i].offset); + + rc =sit9531x_read_u8 (sitdev, reg, &val); +if (rc) +break ; +if (val == intsync_config[i].en_val) + n_en++; +else if (val == intsync_config[i].dis_val) + n_dis++; + } + + ret =sit9531x_intsync_debug_lock (sitdev, ext_page); +if (!rc) + rc = ret; +if (rc) +return rc; + +/* +* A page with the disable pattern or with other values is not a +* source. +*/ +if (!n_en || n_en + n_dis !=ARRAY_SIZE (intsync_config)) +continue ; + n_pages++; + +if (n_dis || !enabled) { +/* +* The whole pattern under a clear global enable does +* not drive the line; a page holding both patterns +* under the enable may drive it in an undefined state. +* Neither is reported as the source. +*/ +if (partial <0 ) + partial = pll; +continue ; + } + +if (src <0 ) + src = pll; + } + +/* +* Record a PLL with a partial or unenabled pattern so that no other +* PLL is enabled alongside it. +*/ + sitdev->intsync_partial = src <0 && partial >=0 ; +if (sitdev->intsync_partial) { +dev_warn (sitdev->dev, +"PLL%c holds an INTSYNC source configuration that is not a defined source\n" , +'A' + partial); + src = partial; + } + +/* +* With more than one page holding the pattern, refuse every connect; an +* enable on one would also set the global enable over the other. +*/ + sitdev->intsync_conflict = n_pages >1 ; +if (sitdev->intsync_conflict) +dev_warn (sitdev->dev, +"%u PLLs hold the INTSYNC source pattern; recording PLL%c\n" , + n_pages,'A' + src); + + sitdev->intsync_src = src; + sitdev->intsync_foreign = enabled && src <0 ; + +return 0 ; +} + +/** +* sit9531x_intsync_readback - re-read the sync source record from the part +* @sitdev: device pointer +* +* A page reads the same latched or not, so a recorded partial source is kept +* when the scan finds no source or the same PLL, and dropped when it finds +* another PLL or the global enable set with no page holding the pattern. +* Caller must hold sitdev->multiop_lock. +* +* Return: 0 on success, <0 on a read error +*/ +int sit9531x_intsync_readback (struct sit9531x_dev *sitdev) +{ +bool partial = sitdev->intsync_partial; +s8 src = sitdev->intsync_src; +int rc; + + rc =sit9531x_intsync_src_detect (sitdev); +if (rc) +return rc; + +if (partial && !sitdev->intsync_foreign && + (sitdev->intsync_src <0 || + (sitdev->intsync_src == src && !sitdev->intsync_partial))) { + sitdev->intsync_src = src; + sitdev->intsync_partial = true; + sitdev->intsync_foreign = false; + } + +return 0 ; +} + +/** +* sit9531x_intsync_refresh - re-read a stale sync source record +* @sitdev: device pointer +* +* Caller must hold sitdev->multiop_lock. +* +* Return: 0 when the record is current, <0 when the scan fails +*/ +int sit9531x_intsync_refresh (struct sit9531x_dev *sitdev) +{ +s8 owner; +int rc; + +if (!sitdev->intsync_stale) +return 0 ; + + owner =sit9531x_intsync_owner (sitdev); + rc =sit9531x_intsync_readback (sitdev); +if (rc) +return rc; + sitdev->intsync_stale = false; +if (owner !=sit9531x_intsync_owner (sitdev)) + sitdev->intsync_ntf_pending = true; + +return 0 ; +} + +/* +* Check if the inter-PLL sync line carries a signal, from the recorded source +* or a PLL locked to the line. Caller must hold sitdev->multiop_lock. +*/ +bool sit9531x_intsync_driven (const struct sit9531x_dev *sitdev) +{ +const struct sit9531x_chan *chan; +u8 pll; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (sitdev->intsync_src >=0 && !sitdev->intsync_partial && + !sitdev->intsync_stale) +return true; + +for (pll =0 ; pll <SIT9531X_NUM_PLLS ; pll++) { + chan =sit9531x_chan_state_get (sitdev, pll); +if (chan->routed_ref ==SIT9531X_INTSYNC_PIN_ID && + chan->locked && !chan->ho_freeze && + !chan->stale && !chan->intsync_dropped) +return true; + } + +return false; +} + +static int __sit9531x_intsync_disable (struct sit9531x_dev *sitdev, +u8 src_pll_idx,bool restore, +bool *owner_kept,bool *touched); + +/* +* Latch the INTSYNC source pattern into the PLL's EXT page, then set the global +* enable. The enable comes last: set over a page holding part of the pattern, +* it may drive the line from that page. Caller must hold sitdev->multiop_lock. +*/ +int sit9531x_intsync_enable (struct sit9531x_dev *sitdev,u8 src_pll_idx, +bool *rollback_failed,bool *touched) +{ +u8 ext_page, val; +int rc, lock_rc; +unsigned int i; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (rollback_failed) + *rollback_failed = false; +if (touched) + *touched = false; +if (src_pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + + ext_page =SIT9531X_PLL_EXT_PAGE (src_pll_idx); + + rc =sit9531x_read_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , &val); +if (rc) +return rc; + +if (touched) + *touched = true; + rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, +SIT9531X_PLL_REG_DEBUG ), +SIT9531X_PLL_DEBUG_UNLOCK ); +if (rc) + goto relock_err; + +for (i =0 ; i <ARRAY_SIZE (intsync_config); i++) { + rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, + intsync_config[i].offset), + intsync_config[i].en_val); +if (rc) + goto relock_err; + } + + rc =sit9531x_pll_small_update (sitdev, src_pll_idx); +if (rc) + goto relock_err; + + lock_rc =sit9531x_intsync_debug_lock (sitdev, ext_page); +if (lock_rc) +dev_warn (sitdev->dev, +"PLL%c: INTSYNC pattern written but the debug window was left open: %d\n" , +'A' + src_pll_idx, lock_rc); + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , + val |BIT (SIT9531X_INTSYNC_EN_BIT )); +if (rc) + goto err_disable; + +/* The page-0 small update applies the global enable */ + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GLOBAL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +usleep_range (1000 ,2000 ); +if (rc) + goto err_disable; + +return 0 ; + +relock_err: +sit9531x_intsync_debug_lock (sitdev, ext_page); + +err_disable: + { +int rollback_rc; + + rollback_rc =__sit9531x_intsync_disable (sitdev, src_pll_idx, + false,NULL ,NULL ); +if (rollback_rc) { +dev_warn (sitdev->dev, +"INTSYNC rollback failed after enable error: %d (original %d)\n" , + rollback_rc, rc); +if (rollback_failed) + *rollback_failed = true; + } + } + +return rc; +} + +/* +* Read whether every INTSYNC register of an EXT page holds its disable value +* (@off) or its enable value (@on). The page's debug window must be open. +*/ +static int sit9531x_intsync_page_state (struct sit9531x_dev *sitdev, +u8 ext_page,bool *off,bool *on) +{ +unsigned int i; +u8 val; +int rc; + + *off = true; + *on = true; +for (i =0 ; i <ARRAY_SIZE (intsync_config); i++) { + rc =sit9531x_read_u8 (sitdev, +SIT9531X_REG (ext_page, + intsync_config[i].offset), + &val); +if (rc) +return rc; +if (val != intsync_config[i].dis_val) + *off = false; +if (val != intsync_config[i].en_val) + *on = false; + } + +return 0 ; +} + +static int __sit9531x_intsync_disable (struct sit9531x_dev *sitdev, +u8 src_pll_idx,bool restore, +bool *owner_kept,bool *touched) +{ +bool in_window = false, was_enabled; +u8 ext_page, val; +int rc, lock_rc; +unsigned int i; + +lockdep_assert_held (&sitdev->multiop_lock); + +if (owner_kept) + *owner_kept = false; +if (touched) + *touched = false; +if (src_pll_idx >=SIT9531X_NUM_PLLS ) +return -EINVAL ; + + ext_page =SIT9531X_PLL_EXT_PAGE (src_pll_idx); + + rc =sit9531x_read_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , &val); +if (rc) +return rc; + was_enabled = val &BIT (SIT9531X_INTSYNC_EN_BIT ); +if (touched) + *touched = true; + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , + val & ~BIT (SIT9531X_INTSYNC_EN_BIT )); +if (rc) + goto restore_global; +/* A sample taken before this write can still show a lock. */ +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) +if (sitdev->chan[i].routed_ref ==SIT9531X_INTSYNC_PIN_ID ) + sitdev->chan[i].intsync_dropped = true; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GLOBAL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +usleep_range (1000 ,2000 ); +if (rc) + goto restore_global; + + rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, +SIT9531X_PLL_REG_DEBUG ), +SIT9531X_PLL_DEBUG_UNLOCK ); +if (rc) + goto restore_global; + in_window = true; + +for (i =0 ; i <ARRAY_SIZE (intsync_config); i++) { + rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, + intsync_config[i].offset), + intsync_config[i].dis_val); +if (rc) + goto restore_global; + } + + rc =sit9531x_pll_small_update (sitdev, src_pll_idx); +if (rc && owner_kept) + *owner_kept = true; + + goto relock; + +restore_global: +/* +* Finish the disable if the page holds the disable pattern; restore +* the global enable only if it still holds the enable pattern. Set +* over part of the pattern, the enable may drive the line, so it stays +* clear. +*/ +if (restore) { +bool off, on; + +if (!in_window && +sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, +SIT9531X_PLL_REG_DEBUG ), +SIT9531X_PLL_DEBUG_UNLOCK )) { +if (owner_kept) + *owner_kept = true; + goto relock; + } +if (sit9531x_intsync_page_state (sitdev, ext_page, &off, &on) || + (!off && !on)) { +if (owner_kept) + *owner_kept = true; + goto relock; + } +if (off) { + rc =sit9531x_pll_small_update (sitdev, src_pll_idx); +if (rc && owner_kept) + *owner_kept = true; + goto relock; + } + } + +if (restore && was_enabled) { +int ret; + + ret =sit9531x_read_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , + &val); +if (!ret) + ret =sit9531x_write_u8 (sitdev, +SIT9531X_REG_INTSYNC_GLOBAL , + val | +BIT (SIT9531X_INTSYNC_EN_BIT )); +if (!ret) { +/* The page-0 small update applies the global enable */ + ret =sit9531x_write_close (sitdev, +SIT9531X_REG_GLOBAL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +usleep_range (1000 ,2000 ); + } +if (ret) { +dev_warn (sitdev->dev, +"PLL%c: INTSYNC enable not put back after a failed disable: %d\n" , +'A' + src_pll_idx, ret); +if (owner_kept) + *owner_kept = true; + } + } + +relock: + lock_rc =sit9531x_intsync_debug_lock (sitdev, ext_page); +if (lock_rc) { +if (rc) +dev_warn (sitdev->dev, +"PLL%c: debug window left open: %d\n" , +'A' + src_pll_idx, lock_rc); +else +dev_warn (sitdev->dev, +"PLL%c: INTSYNC disabled but the debug window was left open: %d\n" , +'A' + src_pll_idx, lock_rc); + } + +return rc; +} + +/* +* Clear the global enable and latch the INTSYNC disable pattern into the PLL's +* EXT page. Caller must hold sitdev->multiop_lock. +*/ +int sit9531x_intsync_disable (struct sit9531x_dev *sitdev,u8 src_pll_idx, +bool *owner_kept,bool *touched) +{ +return __sit9531x_intsync_disable (sitdev, src_pll_idx, true, + owner_kept, touched); +} + +/* +* Notify the output pins in @outs and, when @src, the INTSYNC source pin. Call +* without multiop_lock: the notification takes the subsystem locks, which are +* taken before multiop_lock. +*/ +static void sit9531x_drive_pins_ntf (struct sit9531x_dev *sitdev,u16 outs, +bool src) +{ +struct sit9531x_dpll *sitdpll; +struct sit9531x_dpll_pin *pin; +struct dpll_pin *dpll_pin; +int rc; + +if (!outs && !src) +return ; + +list_for_each_entry (sitdpll, &sitdev->dplls, list) { +list_for_each_entry (pin, &sitdpll->pins, list) { +if (pin->dir !=DPLL_PIN_DIRECTION_OUTPUT ) +continue ; +if (pin->id ==SIT9531X_INTSYNC_OUT_PIN_ID ? + !src : !(outs &BIT (pin->id))) +continue ; + dpll_pin =READ_ONCE (pin->dpll_pin); +if (!dpll_pin) +continue ; + rc =dpll_pin_change_ntf (dpll_pin); +/* +* The source pin is one pin registered on every DPLL. +*/ +if (pin->id ==SIT9531X_INTSYNC_OUT_PIN_ID ) + src = false; +if (!rc) +continue ; +mutex_lock (&sitdev->multiop_lock); +if (pin->id ==SIT9531X_INTSYNC_OUT_PIN_ID ) + sitdev->intsync_ntf_pending = true; +else + sitdev->out[pin->id].ntf_pending = true; +mutex_unlock (&sitdev->multiop_lock); + } + } +} + +/* +* Re-read a stale sync source record; return true when a source pin +* notification is pending. Caller must hold sitdev->multiop_lock. +*/ +static bool sit9531x_intsync_stale_retry (struct sit9531x_dev *sitdev) +{ +if (sit9531x_intsync_refresh (sitdev)) +return false; + +if (!sitdev->intsync_ntf_pending) +return false; + sitdev->intsync_ntf_pending = false; + +return true; +} +/** * sit9531x_phase_offset_read - read phase difference via TDC * @sitdev: device pointer
@@ -3064,6 +3651,7 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx) chan->ho_freeze = !!(ho_freeze &BIT (pll_idx)); chan->ho_valid = !!(pll_status_1 &SIT9531X_PLL_STATUS_1_HO_VALID ); chan->stale = false; + chan->intsync_dropped = false;return 0 ; }
@@ -3256,6 +3844,15 @@ static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev)return rc; } +mutex_lock (&sitdev->multiop_lock); + rc =sit9531x_intsync_src_detect (sitdev); +mutex_unlock (&sitdev->multiop_lock); +if (rc) { +dev_err (sitdev->dev, +"Failed to detect INTSYNC source: %d\n" , rc); +return rc; + } +for (i =0 ; i < sitdev->info->num_outputs; i++) {bool beyond;s64 phase_ps;
@@ -3582,6 +4179,7 @@ static void sit9531x_dev_periodic_work(struct kthread_work *work) struct sit9531x_dev *sitdev = container_of(work, struct sit9531x_dev, work.work);struct sit9531x_dpll *sitdpll; +bool src_moved;bool answered;int rc;
@@ -3591,16 +4189,16 @@ static void sit9531x_dev_periodic_work(struct kthread_work *work)*/ mutex_lock (&sitdev->multiop_lock); answered =sit9531x_dev_ref_states_update (sitdev); + src_moved =sit9531x_intsync_stale_retry (sitdev); answered |=sit9531x_dev_chan_states_update (sitdev);mutex_unlock (&sitdev->multiop_lock);list_for_each_entry (sitdpll, &sitdev->dplls, list)sit9531x_dpll_changes_check (sitdpll); +/* The source pin is not a selection pin; the walk above skips it. */ +sit9531x_drive_pins_ntf (sitdev,0 , src_moved); -/* -* Clear the W1C notification latches on pages 0 and 6 after acting on -* them; while set they keep INTRB asserted. -*/ +/* The latches are W1C; left set, they keep INTRB asserted. */ mutex_lock (&sitdev->multiop_lock); rc =sit9531x_clear_notifications (sitdev);mutex_unlock (&sitdev->multiop_lock);
@@ -4077,13 +4675,13 @@ static bool sit9531x_dpll_pin_is_registrable(struct sit9531x_dpll *sitdpll,if (index ==SIT9531X_MAX_INPUTS )return true;if (index ==SIT9531X_INTSYNC_PIN_ID ) -return false; +return true;return sit9531x_input_pin_is_registrable (sitdev, index); }if (index ==SIT9531X_INTSYNC_OUT_PIN_ID ) -return false; +return true;if (index >= sitdev->info->num_outputs)return false;
@@ -4482,15 +5080,137 @@ static int sit9531x_suspend(struct device *dev)static int sit9531x_resume (struct device *dev) {struct sit9531x_dev *sitdev =dev_get_drvdata (dev); +u16 outs_was =0 , outs_now =0 , outs_unread =0 , outs_moved =0 ; +bool src_moved; +s8 owner; +int rc; +u8 i;/* * After power loss the part is on page 0, not the cached page. The * configuration read at probe is not read again. */ sit9531x_page_cache_drop (sitdev); + +/* +* A part that lost power returns with its profile's INTSYNC routing and +* output mutes, which the poll does not read; read them back. Arm one +* re-select for a source lost and restored between samples. +*/ mutex_lock (&sitdev->multiop_lock);sit9531x_reselect_arm (sitdev); +/* +* Drop and report writes pending from before suspend: a reloaded +* profile may have replaced their registers. +*/ +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +struct sit9531x_chan *chan = &sitdev->chan[i]; +bool retime = false; +u8 j, ho; + +/* +* A table write-back is pending only under forced holdover; +* once that is cleared, the next poll reads the table from the +* registers. +*/ +if ((chan->table_pending || chan->ho_release_pending) && + !sit9531x_read_pll_u8 (sitdev, i,SIT9531X_PLL_REG_HO_CTRL , + &ho) && + !(ho &BIT (SIT9531X_PLL_HO_FORCE_BIT ))) { +dev_warn (sitdev->dev, +"PLL%c: forced holdover cleared over suspend, priority table restore dropped\n" , +'A' + i); + chan->table_pending = false; + chan->ho_release_pending = false; + } + +for (j =0 ; j < sitdev->info->num_outputs; j++) { +if (!sitdev->out[j].retime_pending || + sitdev->out[j].pll_idx != i) +continue ; + sitdev->out[j].retime_pending = false; + retime = true; + } +if (!retime && !chan->flush_pending && + !(sitdev->flush_arm_pending &BIT (i))) +continue ; +dev_warn (sitdev->dev, +"PLL%c: pending before suspend, dropped:%s%s%s\n" , +'A' + i, retime ?" delay re-time" :"" , + chan->flush_pending ?" output realignment" :"" , + (sitdev->flush_arm_pending &BIT (i)) ? +" on-demand flush enable" :"" ); + chan->flush_pending = false; + sitdev->flush_arm_pending &= ~BIT (i); + } +if (sitdev->flush_ctrl_pending) { +dev_warn (sitdev->dev, +"flush trigger source select pending before suspend, dropped\n" ); + sitdev->flush_ctrl_pending = false; + } + owner =sit9531x_intsync_owner (sitdev); +/* +* The delay registers are reloaded with the profile too; read them back +* as probe does. +*/ +for (i =0 ; i < sitdev->info->num_outputs; i++) { +struct sit9531x_out *out = &sitdev->out[i]; +bool beyond; +s64 phase_ps; + +if (!out->routed) +continue ; + rc =sit9531x_output_phase_read (sitdev, i, &phase_ps, + &beyond); +/* An output with no divider has no delay, as at probe */ +if (rc == -ENODATA ) { + phase_ps =0 ; + beyond = false; + rc =0 ; + } +if (rc) { +dev_warn (sitdev->dev, +"Output %u delay not read on resume: %d\n" , + i, rc); + out->phase_stale = true; + outs_unread |=BIT (i); +continue ; + } +if (out->phase_adj != phase_ps || out->phase_stale) + outs_moved |=BIT (i); + out->phase_adj = phase_ps; + out->phase_armed = !beyond && phase_ps; + out->phase_stale = false; + } + rc =sit9531x_intsync_readback (sitdev); +if (rc) +dev_warn (sitdev->dev, +"INTSYNC source not re-detected on resume: %d\n" , rc); + sitdev->intsync_stale = rc !=0 ; + src_moved = rc || owner !=sit9531x_intsync_owner (sitdev); +for (i =0 ; i < sitdev->info->num_outputs; i++) { +if (sitdev->out[i].enabled) + outs_was |=BIT (i); +/* The mute state of a request left unconfirmed is unknown */ +if (sitdev->out[i].state_stale) + outs_unread |=BIT (i); + rc =sit9531x_output_state_refresh (sitdev, i); +if (rc) { +dev_warn (sitdev->dev, +"Output %u mute state not read on resume: %d\n" , + i, rc); + sitdev->out[i].state_stale = true; + outs_unread |=BIT (i); + } +if (sitdev->out[i].enabled) + outs_now |=BIT (i); + }mutex_unlock (&sitdev->multiop_lock); + +sit9531x_drive_pins_ntf (sitdev, + (outs_was ^ outs_now) | outs_unread | + outs_moved, src_moved); +if (sitdev->irq >0 )enable_irq (sitdev->irq);kthread_queue_delayed_work (sitdev->kworker, &sitdev->work,0 );
drivers/dpll/sit9531x/core.h +32 -0
@@ -145,6 +145,8 @@ struct sit9531x_out {* @locked: PLL is active and its outer loop reports lock * @stale: last state read failed; the fields hold the previous sample and * are not reported +* @intsync_dropped: driver turned INTSYNC off after this sample; a lock to +* INTSYNC in it is not trusted * @mode: 0 = sync (outer loop enabled), 1 = free-run * @routed_ref: input the device routes to the PLL, as a logical index * (INTSYNC: SIT9531X_INTSYNC_PIN_ID); SIT9531X_REF_INVALID if none
@@ -187,6 +189,7 @@ struct sit9531x_chan {bool active;bool locked;bool stale; +bool intsync_dropped;u8 mode;u8 routed_ref;bool inner_lol;
@@ -236,6 +239,12 @@ struct sit9531x_chan {* @reset_gpio: optional reset line, NULL if absent * @irq: optional INTRB IRQ, 0 if not wired * @intsync_src: PLL sourcing INTSYNC, or -1 +* @intsync_partial: @intsync_src holds part of the source pattern, or the whole +* pattern under a clear global enable; not reported as the source +* @intsync_conflict: more than one PLL page holds the source pattern +* @intsync_foreign: global enable set with no page holding the pattern +* @intsync_stale: @intsync_src must be read back before use +* @intsync_ntf_pending: the poll must send a source pin notification * @irq_ack_fails: consecutive failed INTRB acknowledgements * @fvco_band_warned: bit per PLL warned for Fref * DIVN outside its VCO * band; written under @multiop_lock
@@ -274,6 +283,11 @@ struct sit9531x_dev {int irq;s8 intsync_src; +bool intsync_partial; +bool intsync_conflict; +bool intsync_foreign; +bool intsync_stale; +bool intsync_ntf_pending;bool loops_open;bool outsys_key_pending;
@@ -323,6 +337,24 @@ int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,int sit9531x_output_phase_adjust_set (struct sit9531x_dev *sitdev,u8 out_idx,s32 phase_ps); +/* +* Return the PLL driving INTSYNC with a complete source configuration, or -1. +* Caller must hold sitdev->multiop_lock. +*/ +static inline s8 sit9531x_intsync_owner (const struct sit9531x_dev *sitdev) +{ +return sitdev->intsync_partial ?-1 : sitdev->intsync_src; +} + +int sit9531x_intsync_enable (struct sit9531x_dev *sitdev,u8 src_pll_idx, +bool *rollback_failed,bool *touched); +int sit9531x_intsync_disable (struct sit9531x_dev *sitdev,u8 src_pll_idx, +bool *owner_kept,bool *touched); +int sit9531x_intsync_src_detect (struct sit9531x_dev *sitdev); +int sit9531x_intsync_readback (struct sit9531x_dev *sitdev); +int sit9531x_intsync_refresh (struct sit9531x_dev *sitdev); +bool sit9531x_intsync_driven (const struct sit9531x_dev *sitdev); +int sit9531x_chan_routed_ref_read (struct sit9531x_dev *sitdev,u8 pll_idx,u8 *ref);int sit9531x_input_mon_fetch (struct sit9531x_dev *sitdev);
drivers/dpll/sit9531x/dpll.c +405 -23
483 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h +3 -0
@@ -254,6 +254,9 @@#define SIT9531X_PLL_REG_ACTIVE 0x02#define SIT9531X_PLL_ACTIVE_BIT BIT(0)/* PLL reached active state */ +/* PLL EXT page INTSYNC configuration registers */ +#define SIT9531X_PLL_EXT_PAGE (_idx) (SIT9531X_PAGE_PLLA_EXT + (_idx)) +#define SIT9531X_PLL_STATUS_OUTER_DIS BIT(5)/*
Signature · 1 line
2.39.2 (Apple Git-143)
[email protected]
AI reviewRe: [PATCH net-next v16 13/13] dpll: sit9531x: model the inter-PLL sync line as a pair of pins
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] dpll: sit9531x: lost global disable error in __sit9531x_intsync_disable() - [Medium] dpll…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] dpll: sit9531x: lost global disable error in __sit9531x_intsync_disable()
- [Medium] dpll: sit9531x: sticky intsync_partial in sit9531x_intsync_readback()
- [Medium] dpll: sit9531x: stale partial state on INTSYNC source set failure
- [Medium] dpll: sit9531x: hidden INTSYNC selection in sit9531x_dpll_pin_snapshot()
--
commit cfe63c19d5fe92b45accc9dad92f48789a062ff1
Author: Oleg Zadorozhnyi <[email protected]>
dpll: sit9531x: model the inter-PLL sync line as a pair of pins
This commit models the internal inter-PLL sync line (INTSYNC) as a source pin and a destination input pin on each DPLL, adding hardware detection, enable/disable sequences, and resume state recovery.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0@@ -2620,6 +2639,574 @@ static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev)return 0 ; }
[ ... ]
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+int sit9531x_intsync_readback (struct sit9531x_dev *sitdev) +{ +bool partial = sitdev->intsync_partial; +s8 src = sitdev->intsync_src; +int rc; + + rc =sit9531x_intsync_src_detect (sitdev); +if (rc) +return rc; +
drivers/dpll/sit9531x/core.c static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev) · line 2822
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+if (partial && !sitdev->intsync_foreign && + (sitdev->intsync_src <0 || + (sitdev->intsync_src == src && !sitdev->intsync_partial))) { + sitdev->intsync_src = src; + sitdev->intsync_partial = true; + sitdev->intsync_foreign = false; + } + +return 0 ; +}
[Severity: Medium]
As reported by Jakub Kicinski on v15 [1], does sit9531x_intsync_readback() clobber the freshly scanned hardware profile on resume whenever sitdev->intsync_partial was set before suspend?
sit9531x_resume() calls sit9531x_intsync_readback() without clearing sitdev->intsync_partial first. If the reloaded hardware profile has no INTSYNC source, sit9531x_intsync_readback() restores the stale pre-suspend partial record, blocking other PLLs from connecting INTSYNC (-EBUSY). If the reloaded profile has the same PLL actively driving INTSYNC, it forces sitdev->intsync_partial back to true, causing sit9531x_intsync_owner() to return -1 and the source pin to report DPLL_PIN_STATE_DISCONNECTED.
Also, if INTSYNC was driven before suspend with a destination PLL locked to it and the reloaded profile disables INTSYNC, sit9531x_resume() does not set chan->intsync_dropped, so sit9531x_intsync_driven() continues returning true from the pre-suspend sample until the periodic poll runs.
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +4
-0+static int __sit9531x_intsync_disable (struct sit9531x_dev *sitdev, +u8 src_pll_idx,bool restore, +bool *owner_kept,bool *touched) +{
[ ... ]
Quoted 14 lines
drivers/dpll/sit9531x/core.c +14
-0+ rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , + val & ~BIT (SIT9531X_INTSYNC_EN_BIT )); +if (rc) + goto restore_global; +/* A sample taken before this write can still show a lock. */ +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) +if (sitdev->chan[i].routed_ref ==SIT9531X_INTSYNC_PIN_ID ) + sitdev->chan[i].intsync_dropped = true; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_GLOBAL_UPDATE , +SIT9531X_SMALL_UPDATE_CMD ); +usleep_range (1000 ,2000 ); +if (rc) + goto restore_global;
[ ... ]
Quoted 22 lines
drivers/dpll/sit9531x/core.c +22
-0+restore_global: +/* +* Finish the disable if the page holds the disable pattern; restore +* the global enable only if it still holds the enable pattern. Set +* over part of the pattern, the enable may drive the line, so it stays +* clear. +*/ +if (restore) { +bool off, on; + +if (!in_window && +sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, +SIT9531X_PLL_REG_DEBUG ), +SIT9531X_PLL_DEBUG_UNLOCK )) { +if (owner_kept) + *owner_kept = true; + goto relock; + } +if (sit9531x_intsync_page_state (sitdev, ext_page, &off, &on) || + (!off && !on)) { +if (owner_kept)
drivers/dpll/sit9531x/core.c static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev) · line 3095
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ *owner_kept = true; + goto relock; + } +if (off) { + rc =sit9531x_pll_small_update (sitdev, src_pll_idx); +if (rc && owner_kept) + *owner_kept = true; + goto relock; + } + }
[Severity: Medium]
If clearing SIT9531X_REG_INTSYNC_GLOBAL or latching SIT9531X_REG_GLOBAL_UPDATE fails when the EXT page already holds the disable pattern (off == true, for example after an earlier partial disable or failed enable rollback), does the "if (off)" branch overwrite rc with 0 when sit9531x_pll_small_update() succeeds?
__sit9531x_intsync_disable() then returns 0 even though the global enable bit was never cleared or latched. In sit9531x_dpll_intsync_src_state_on_dpll_set(), rc == 0 clears sitdev->intsync_partial before calling sit9531x_intsync_readback(); with the global enable bit still set and no EXT page holding the enable pattern, sit9531x_intsync_src_detect() sets sitdev->intsync_foreign = true and locks out all future INTSYNC connects.
Quoted 4 lines
drivers/dpll/sit9531x/dpll.c +0
-0
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/dpll.c +0
-0@@ -652,6 +679,355 @@ sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin,
[ ... ]
Quoted 8 lines
drivers/dpll/sit9531x/dpll.c +8
-0+static int +sit9531x_dpll_intsync_src_state_on_dpll_set (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_state state, +struct netlink_ext_ack *extack) +{
[ ... ]
Quoted 9 lines
drivers/dpll/sit9531x/dpll.c +9
-0+/* A disconnect reads back through the partial record */ +if (changed) + detect_rc = state ==DPLL_PIN_STATE_DISCONNECTED ? +sit9531x_intsync_readback (sitdev) : +sit9531x_intsync_src_detect (sitdev); +if (changed && rc) { +if (owner_kept || + (state ==DPLL_PIN_STATE_CONNECTED && + (detect_rc || sitdev->intsync_src == sitdpll->id))) {
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin, · line 857
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c +10
-0+ sitdev->intsync_src = sitdpll->id; + sitdev->intsync_partial = true; + sitdev->intsync_foreign = false; + }else if (detect_rc) { + sitdev->intsync_stale = true; + } + }else if (changed && detect_rc && sitdev->intsync_conflict) { + sitdev->intsync_stale = true; + sitdev->intsync_ntf_pending = true; + }
[Severity: Medium]
When sit9531x_intsync_enable() or sit9531x_intsync_disable() fails, can this error recovery leave a false partial record wedged or falsely report an active source as disconnected?
Because setting sitdev->intsync_stale = true is in an "else if (detect_rc)" branch, if sit9531x_intsync_enable() fails (even after a clean rollback) and sit9531x_intsync_src_detect() also hits a transient bus error (detect_rc != 0), the first branch sets sitdev->intsync_src = sitdpll->id and sitdev->intsync_partial = true while leaving sitdev->intsync_stale false, so sit9531x_intsync_refresh() never re-reads the hardware.
Conversely, on DPLL_PIN_STATE_DISCONNECTED, if the very first write to SIT9531X_REG_INTSYNC_GLOBAL in __sit9531x_intsync_disable() fails before any register is changed and unlocking the debug window in restore_global also fails, *owner_kept is set to true; even when sit9531x_intsync_readback() then succeeds and sees that the PLL is still a complete, active source, "if (owner_kept || ...)" forces sitdev->intsync_partial = true and emits a notification reporting the source pin as disconnected while the PLL is still driving the line.
[ ... ]
Quoted 18 lines
drivers/dpll/sit9531x/dpll.c +18
-0+static int +sit9531x_dpll_intsync_dst_state_on_dpll_get (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack) +{ +struct sit9531x_dpll *sitdpll = dpll_priv; +struct sit9531x_dev *sitdev = sitdpll->dev; +int rc; + +mutex_lock (&sitdev->multiop_lock); + rc =sit9531x_dpll_intsync_refresh (sitdev, extack); +if (rc) { +mutex_unlock (&sitdev->multiop_lock); +return rc; + }
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin, · line 923
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c +10
-0+if (sitdev->intsync_src == sitdpll->id) + *state =DPLL_PIN_STATE_DISCONNECTED ; +else +sit9531x_dpll_selection_state_get (sitdev, sitdpll, +SIT9531X_INTSYNC_PIN_ID , + state); +mutex_unlock (&sitdev->multiop_lock); + +return 0 ; +}
[Severity: Medium]
As reported by Jakub Kicinski on v15 [2], should sit9531x_dpll_intsync_dst_state_on_dpll_get() (and sit9531x_dpll_pin_snapshot()) force *state = DPLL_PIN_STATE_DISCONNECTED when sitdev->intsync_src == sitdpll->id?
When sitdev->intsync_partial is true on a PLL whose priority table or manual selection also lists INTSYNC, both the source pin and the destination pin on that PLL report DPLL_PIN_STATE_DISCONNECTED. Connecting the source pin on that PLL then fails in sit9531x_dpll_intsync_src_state_on_dpll_set() via sit9531x_dpll_intsync_selected() with -EBUSY ("PLL selects INTSYNC as a reference; it cannot drive it"), while hiding that the destination pin is actually selectable (or connected in manual mode).
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
[email protected]
AI reviewRe: [PATCH net-next v16 13/13] dpll: sit9531x: model the inter-PLL sync line as a pair of pins
In reply to Ali RouhiThank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 5 · Low: 7
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] sit9531x_intsync_readback() keeps an earlier partial record even when the new scan finds the same PLL with the whole pattern and…
- [Medium] This patch makes sit9531x_dpll_pin_is_registrable() return true for SIT9531X_INTSYNC_PIN_ID and SIT9531X_INTSYNC_OUT_PIN_ID,…
- [Medium] sit9531x_dpll_intsync_src_state_on_dpll_get(), sit9531x_dpll_intsync_dst_state_on_dpll_get() and…
- [Medium] sit9531x_resume() is written for a part that lost power and reloaded its profile ('A part that lost power returns with its…
- [Medium] sit9531x_intsync_enable() and __sit9531x_intsync_disable() write whole bytes from intsync_config[] into eight EXT-page registers,…
- [Low] Most of the sit9531x_resume() changes have nothing to do with the INTSYNC line.
- [Low] In sit9531x_resume() the old comment still says 'After power loss the part is on page 0, not the cached page.
- [Low] intsync_config[] is eight raw byte values for undocumented EXT- page debug registers (0x2D, 0x50, 0x51, 0x54, 0x55, 0x5C, 0x5D, 0x6C).
- [Low] When PLLx's EXT page holds a partial pattern, sit9531x_dpll_intsync_src_state_on_dpll_set() refuses a CONNECT on any…
- [Low] sit9531x_dpll_intsync_src_state_on_dpll_set() refuses SELECTABLE, and any other state that is not CONNECTED or DISCONNECTED, in its…
- [Low] The dpll.c pin-state contract says the INTSYNC destination is 'SELECTABLE while listed in this PLL's priority table and DISCONNECTED…
- [Low] The INTSYNC code unlocks the debug key (0xBD = 0xC3) on each PLL EXT page (0x1A + n).
--
dpll: sit9531x: model the inter-PLL sync line as a pair of pins
This commit registers two pins for the internal inter-PLL sync (INTSYNC) line. One is a source pin shared by every DPLL, whose state says whether that PLL drives the line. The other is a selectable destination input on each PLL. Connecting the source writes an enable pattern into the PLL's EXT page under its debug key and then sets the global enable. Resume now re-reads the line owner, output mutes and output delays, and drops some writes that were pending from before suspend.
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0
[ ... ]
Quoted 1 line
drivers/dpll/sit9531x/core.c +0
-0@@ -2620,6 +2639,574 @@ static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev)
[ ... ]
Quoted 11 lines
drivers/dpll/sit9531x/core.c +11
-0+/* +* Values written to the source PLL's EXT page to enable or disable INTSYNC, +* which locks the frequency PLL to the phase PLL; they are the values of +* Intsync_enable_disable.py. +*/ +struct sit9531x_intsync_reg { +u8 offset; +u8 en_val; +u8 dis_val; +}; +
drivers/dpll/sit9531x/core.c static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev) · line 2674
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+static const struct sit9531x_intsync_reg intsync_config[] = { + {0x2D ,0x02 ,0x00 }, + {0x50 ,0x08 ,0x00 }, + {0x51 ,0x04 ,0x00 }, + {0x54 ,0x02 ,0x00 }, + {0x55 ,0x28 ,0x20 }, + {0x5C ,0x0F ,0x00 }, + {0x5D ,0xFF ,0x00 }, + {0x6C ,0xDD ,0x00 }, +};
[Severity: Low]
Could each of these eight registers get a short description? The only reference is Intsync_enable_disable.py, which isn't public. sit9531x_intsync_src_detect() decides source, partial and conflict only by counting matches against these bytes.
The comment says the pattern "locks the frequency PLL to the phase PLL". The commit message says "one PLL drives the others as a reference". Which one describes the hardware? The second is the model this patch exposes to user space, as a source pin plus a destination input.
[ ... ]
Quoted 7 lines
drivers/dpll/sit9531x/core.c +7
-0+int sit9531x_intsync_readback (struct sit9531x_dev *sitdev) +{ +bool partial = sitdev->intsync_partial; +s8 src = sitdev->intsync_src; +int rc; + + rc =sit9531x_intsync_src_detect (sitdev);
drivers/dpll/sit9531x/core.c static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev) · line 2819
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+if (rc) +return rc; + +if (partial && !sitdev->intsync_foreign && + (sitdev->intsync_src <0 || + (sitdev->intsync_src == src && !sitdev->intsync_partial))) { + sitdev->intsync_src = src; + sitdev->intsync_partial = true; + sitdev->intsync_foreign = false; + }
[Severity: Medium]
Does this mark a source that is fully driving the line as partial again? Suppose an earlier partial record exists for PLLx. If the new scan finds the whole pattern on PLLx with the global enable set, the second half of the condition is true and intsync_partial goes back to true.
That isn't one of the meanings core.h lists:
* @intsync_partial: @intsync_src holds part of the source pattern, or the whole
* pattern under a clear global enable; not reported as the source
Both sit9531x_dpll_intsync_src_connected() and sit9531x_intsync_driven() ignore partial records. So the PLL driving the line would show a DISCONNECTED source pin. The other PLLs' INTSYNC inputs would show NO_SIGNAL unless one of them is locked.
sit9531x_resume() uses this same readback for the power-loss case ("A part that lost power returns with its profile's INTSYNC routing ... read them back"). The partial record may be left by a failed connect or disconnect (the owner_kept or rollback_failed paths). If the reloaded profile then sources INTSYNC from that same PLL, would connects on other PLLs be refused with "PLL%c holds a partial INTSYNC source"? The only recovery would be a DISCONNECT, which turns off the profile's source.
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev) · line 2937
Quoted 12 lines
drivers/dpll/sit9531x/core.c +12
-0+ rc =sit9531x_pll_small_update (sitdev, src_pll_idx); +if (rc) + goto relock_err; + + lock_rc =sit9531x_intsync_debug_lock (sitdev, ext_page); +if (lock_rc) +dev_warn (sitdev->dev, +"PLL%c: INTSYNC pattern written but the debug window was left open: %d\n" , +'A' + src_pll_idx, lock_rc); + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_INTSYNC_GLOBAL , + val |BIT (SIT9531X_INTSYNC_EN_BIT ));
[Severity: Low]
What closes the EXT page debug window if this lock fails? The other debug windows have a pending flag that gets retried:
- PLL page: chan->key_pending, retried by sit9531x_tap_back_retry()
- OUTSYS page: outsys_key_pending, retried by the poll
The EXT page has no such flag.
Two other places have the same problem:
- The relock label in __sit9531x_intsync_disable() only warns, and the function can still return 0.
- sit9531x_intsync_src_detect() returns early on a failed lock and leaves that page open.
The setter's follow-up detect or readback re-locks each page. Some failure cases don't set intsync_stale, for example:
changed && !rc && detect_rc && !intsync_conflict
If that follow-up scan fails in one of those cases, nothing seems to retry the lock. The EXT page INTSYNC registers would stay writable, and the driver would have no record of it.
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +4
-0+static int __sit9531x_intsync_disable (struct sit9531x_dev *sitdev, +u8 src_pll_idx,bool restore, +bool *owner_kept,bool *touched) +{
[ ... ]
drivers/dpll/sit9531x/core.c static int sit9531x_clear_notifications(struct sit9531x_dev *sitdev) · line 3056
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ in_window = true; + +for (i =0 ; i <ARRAY_SIZE (intsync_config); i++) { + rc =sit9531x_write_u8 (sitdev, +SIT9531X_REG (ext_page, + intsync_config[i].offset), + intsync_config[i].dis_val); +if (rc) + goto restore_global; + }
[Severity: Medium]
Can this overwrite profile settings that are not part of the INTSYNC switch? Enable and disable both write whole bytes from intsync_config[]. There is no read-modify-write, and the old contents are not saved.
sit9531x_intsync_src_detect() allows pages that hold "other values", and a connect on such a PLL is not refused. The page then ends up with the fixed dis_val bytes instead of the profile's values. This happens after a connect followed by a disconnect. It also happens on the enable-failure rollback, which goes through __sit9531x_intsync_disable() with restore == false.
Offset 0x55 has bit 5 set in both en_val (0x28) and dis_val (0x20). That suggests the register holds at least one other field, and this code forces it to 1. Would it be better to save and restore the original bytes, or to change only the INTSYNC bits?
[ ... ]
drivers/dpll/sit9531x/core.c static bool sit9531x_dpll_pin_is_registrable(struct sit9531x_dpll *sitdpll, · line 4684
Quoted 13 lines
drivers/dpll/sit9531x/core.c +2
-2@@ -4077,13 +4675,13 @@ static bool sit9531x_dpll_pin_is_registrable(struct sit9531x_dpll *sitdpll,if (index ==SIT9531X_MAX_INPUTS )return true;if (index ==SIT9531X_INTSYNC_PIN_ID ) -return false; +return true;return sit9531x_input_pin_is_registrable (sitdev, index); }if (index ==SIT9531X_INTSYNC_OUT_PIN_ID ) -return false; +return true;
[Severity: Medium]
Once these pins are registered, user space can see their type. sit9531x_pin_props_get() in prop.c gives both of them the same type as the XO:
drivers/dpll/sit9531x/prop.c:sit9531x_pin_props_get() {
if (sync_in) {
/* INTSYNC destination: a reference the PLL can lock to. */
props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;
...
} else if (sync_out) {
/* INTSYNC source: driving it is not a reference selection */
props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;
...
} else if (xo) {
props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;
...
}Is INT_OSCILLATOR the right type for a line driven by another PLL? User space that finds the free-running oscillator by pin type would see three INT_OSCILLATOR pins per DPLL, and two of them are not oscillators. Pin type is uAPI and is hard to change after release.
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +0
-0@@ -4482,15 +5080,137 @@ static int sit9531x_suspend(struct device *dev)static int sit9531x_resume (struct device *dev) {struct sit9531x_dev *sitdev =dev_get_drvdata (dev);
drivers/dpll/sit9531x/core.c static int sit9531x_suspend(struct device *dev) · line 5092
Quoted 10 lines
drivers/dpll/sit9531x/core.c +5
-0+u16 outs_was =0 , outs_now =0 , outs_unread =0 , outs_moved =0 ; +bool src_moved; +s8 owner; +int rc; +u8 i;/* * After power loss the part is on page 0, not the cached page. The * configuration read at probe is not read again. */
[Severity: Low]
This isn't a bug, but this comment now contradicts the code below. That code re-reads probe-time configuration through sit9531x_intsync_readback(), sit9531x_output_phase_read() ("read them back as probe does") and sit9531x_output_state_refresh().
drivers/dpll/sit9531x/core.c static int sit9531x_suspend(struct device *dev) · line 5101
Quoted 9 lines
drivers/dpll/sit9531x/core.c +6
-0sit9531x_page_cache_drop (sitdev); + +/* +* A part that lost power returns with its profile's INTSYNC routing and +* output mutes, which the poll does not read; read them back. Arm one +* re-select for a source lost and restored between samples. +*/ mutex_lock (&sitdev->multiop_lock);sit9531x_reselect_arm (sitdev);
[Severity: Medium]
Is the part guaranteed to be ready here? This code assumes the part lost power and reloaded its profile. It then immediately reads and caches HO_CTRL, the output delay registers, all four EXT pages and the output mute state.
Probe waits for internal boot after releasing reset:
sit9531x_dev_probe() {
...
fsleep(10000); /* internal boot after release */
...
}Suspend and resume don't touch the reset GPIO or power, so nothing here knows when the part came back. If this runs while the profile is still loading, these fields could be cached from transient values:
- intsync_src, intsync_partial and intsync_foreign
- out->phase_adj and out->phase_armed
- out->enabled
The poll does not re-read any of them. table_pending and ho_release_pending could also be dropped based on a transient HO_CTRL read.
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/core.c +4
-0+for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +struct sit9531x_chan *chan = &sitdev->chan[i]; +bool retime = false; +u8 j, ho;
[ ... ]
Quoted 7 lines
drivers/dpll/sit9531x/core.c +7
-0+if (!retime && !chan->flush_pending && + !(sitdev->flush_arm_pending &BIT (i))) +continue ; + dev_warn(sitdev->dev, + "PLL%c: pending before suspend, dropped:%s%s%s\n", + 'A' + i, retime ? " delay re-time" : "", + chan->flush_pending ? " output realignment" : "",
drivers/dpll/sit9531x/core.c static int sit9531x_suspend(struct device *dev) · line 5150
Quoted 10 lines
drivers/dpll/sit9531x/core.c +10
-0+ (sitdev->flush_arm_pending &BIT (i)) ? + " on-demand flush enable" : ""); + chan->flush_pending = false; + sitdev->flush_arm_pending &= ~BIT (i); + } +if (sitdev->flush_ctrl_pending) { +dev_warn (sitdev->dev, +"flush trigger source select pending before suspend, dropped\n" ); + sitdev->flush_ctrl_pending = false; + }
[Severity: Low]
The commit message says resume "drops the writes left pending from before suspend, logging each". This loop drops retime_pending, flush_pending, flush_arm_pending and flush_ctrl_pending. It drops table_pending and ho_release_pending only when HO_FORCE reads clear.
Several retries are left in place:
- tap restore (tap_pending, key_pending)
- input-off
- the loops_open relock
- the outsys_key_pending close
The poll queued at the end of resume then runs them from sit9531x_dev_chan_states_update(), against a configuration that may have been reloaded:
if (sitdev->loops_open) sit9531x_prg_relock(sitdev); else if (sitdev->outsys_key_pending) sit9531x_outsys_debug_close(sitdev); ... sit9531x_input_off_retry(sitdev); ... sit9531x_tap_back_retry(sitdev, i);
Is that intended?
Separately, most of the resume work belongs to the output phase, output state, flush and priority table code rather than to the INTSYNC line. That includes the delay and mute read-back and the dropped flush, retime and table writes. Could it go in its own patch?
[ ... ]
Quoted 4 lines
drivers/dpll/sit9531x/dpll.c +0
-0
[ ... ]
Quoted 8 lines
drivers/dpll/sit9531x/dpll.c +8
-0+static int +sit9531x_dpll_intsync_src_state_on_dpll_get (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack) +{
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin, · line 720
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c +10
-0+struct sit9531x_dpll *sitdpll = dpll_priv; +struct sit9531x_dev *sitdev = sitdpll->dev; +int rc; + +mutex_lock (&sitdev->multiop_lock); + rc =sit9531x_dpll_intsync_refresh (sitdev, extack); +if (rc) { +mutex_unlock (&sitdev->multiop_lock); +return rc; + }
[Severity: Medium]
Can a failed refresh here end the pin dump for the whole system? While intsync_stale is set, sit9531x_dpll_intsync_refresh() rescans all four EXT pages over I2C. If that fails, the error (for example -EIO) goes back to the DPLL core, and dpll_nl_pin_get_dumpit() only skips -ENODEV:
ret = dpll_cmd_pin_get_one(skb, pin, cb->extack);
if (ret) {
genlmsg_cancel(skb, hdr);
if (ret == -ENODEV) {
ret = 0;
continue;
}
break;
}The dump then stops, so the pins after this one are never listed, including pins of other DPLL drivers. The same pattern is in sit9531x_dpll_intsync_dst_state_on_dpll_get() and sit9531x_dpll_intsync_dst_operstate_on_dpll_get().
Each INTSYNC pin is one dpll_pin shared by all four DPLLs. PIN_GET and change notifications for it would fail too, and sit9531x_drive_pins_ntf() would keep setting intsync_ntf_pending.
intsync_stale is set right after an EXT-page read has already failed, in sit9531x_resume() or in the source setter. So this path runs when the bus is already known to be failing. sit9531x_dpll_input_pin_phase_offset_get() maps such errors to -ENODATA for this reason.
sit9531x_intsync_driven() already treats a stale record as not driven. Could these getters answer from the cached record instead?
[ ... ]
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin, · line 786
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c +10
-0+switch (state) { +case DPLL_PIN_STATE_CONNECTED : +if (was_connected) +break ; +if (sitdev->intsync_src >=0 && + sitdev->intsync_src != sitdpll->id) { +if (sitdev->intsync_partial) +NL_SET_ERR_MSG_FMT (extack, +"PLL%c holds a partial INTSYNC source; disconnect its source pin first" , +'A' + sitdev->intsync_src);
[Severity: Low]
How would user space tell which pin needs disconnecting? sit9531x_dpll_intsync_src_connected() returns false when intsync_partial is set, so the partial owner's source pin already reports DISCONNECTED.
A redundant DISCONNECTED write does reach sit9531x_intsync_disable(), because the core doesn't short-circuit same-state requests. Nothing in the reported state shows that the pin needs it, though, and tools that skip no-op state writes would never send it.
[ ... ]
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin, · line 831
Quoted 10 lines
drivers/dpll/sit9531x/dpll.c +10
-0+case DPLL_PIN_STATE_DISCONNECTED : +if (sitdev->intsync_src != sitdpll->id) +break ; + rc =sit9531x_intsync_disable (sitdev, sitdpll->id, + &owner_kept, &changed); +break ; +default : + rc = -EINVAL ; +break ; + }
[Severity: Low]
Should this default case set an extack message? SELECTABLE ends up here with a bare -EINVAL. The end of the function skips the generic "Failed to set INTSYNC source state" message for -EINVAL, so user space gets no explanation. The destination pin's CONNECTED refusal does set one ("Device selects its reference by priority; use selectable").
[ ... ]
Quoted 8 lines
drivers/dpll/sit9531x/dpll.c +8
-0+static int +sit9531x_dpll_intsync_dst_state_on_dpll_get (const struct dpll_pin *pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_state *state, +struct netlink_ext_ack *extack) +{
[ ... ]
drivers/dpll/sit9531x/dpll.c sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin, · line 919
Quoted 6 lines
drivers/dpll/sit9531x/dpll.c +6
-0+if (sitdev->intsync_src == sitdpll->id) + *state =DPLL_PIN_STATE_DISCONNECTED ; +else +sit9531x_dpll_selection_state_get (sitdev, sitdpll, +SIT9531X_INTSYNC_PIN_ID , + state);
[Severity: Low]
The pin-state contract comment doesn't cover this case. It says the INTSYNC destination is "SELECTABLE while listed in this PLL's priority table and DISCONNECTED otherwise".
Here, and in sit9531x_dpll_pin_snapshot(), the pin is forced to DISCONNECTED whenever intsync_src matches this PLL. That includes partial records and owners detected at probe or resume.
A profile can list INTSYNC in the source PLL's own table. sit9531x_dpll_intsync_selected() only refuses that combination for the driver's own connect requests. In that case sit9531x_dpll_input_pin_prio_get() still returns the live slot, so the pin shows DISCONNECTED with a valid priority. Could the contract comment and the reported state be made to agree?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119225752.41846-1-arouhi%40sitime.com