dpll: add SiTime SiT9531x DPLL clock driver
Subsystems (6)
v17 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]/
v16: https://lore.kernel.org/netdev/[email protected]/
The changes in v17 answer the netdev AI review and the Sashiko review of v16. Each finding of the netdev AI review has a reply on its patch:
a fix folded into the patch that introduces the code, or a reason it does not hold. The two items left for patches after this series is merged are listed at the end of this letter.
Jiri, Ivan, Vadim, Arkadiusz: each AI review of this series raises new findings. Which open items would you want resolved before the series is merged, and would you rather review the driver as a smaller series first?
Ivan Vecera's Reviewed-by on patch 1 and Rob Herring's on patch 3 are carried. Patch 1 gained documentation of the -ENODATA return and no code; the schema in patch 3 gained one sentence in a description.
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 its selected input CONNECTED and 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. A table write latches the active selection again and restarts acquisition. The driver writes the table of a PLL in holdover once when it loses its reference, once when the best source with signal changes, and once on the first sample after probe or resume. A PLL that stays frozen with the best source unchanged is re-selected after 10 s, then at doubling intervals up to 640 s: a PLL that locks and loses its source between two samples is never seen to track. 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. The handler and the poll acknowledge each documented notification latch by writing back only the bits found set.
Clocks and supplies. Probe enables vdd, vddin and each VDDO supply the board names, then waits the 10 ms start-up time of the datasheet before the first access, with or without a reset line; resume waits the same time and reads the select modes, priority tables and output routing again. 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.
Clock ID. The clock_id is built from the 9-byte die ID at page 0 0x41-0x49: the last eight bytes, with the first XORed into the most significant one. A die ID of all zeros or all ones, or one another bound part holds, gives the clock_id from the SiTime OUI, the I2C bus number and the address instead.
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, reads as 0 Hz 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 an output by forcing its 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. Probe records the force the loaded configuration sets on each pad, and an unmute writes that record back. 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 NVM bank update, an output realignment, open output loops, a receiver to power down, 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 bank update, receiver power-down 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 v17:
- Patch 1: dpll.rst, the two callbacks in struct dpll_pin_ops and the netlink spec document the -ENODATA return.
- Patch 3: the description of supported-frequencies-hz says a rate is one 32-bit cell.
- Patch 4: probe enables the supplies and waits the start-up time before the first access.
- Patch 5: an output without supported-frequencies-hz advertises the datasheet rates, 1 Hz to 800 MHz and 61.44 MHz times 15, 20, 24, 30, 32, 40 and 48. A 0 Hz entry is refused as malformed.
- Patch 6: the clock_id comes from the die ID. The INTRB handler and the poll acknowledge every documented notification latch; an interrupt with no latch set is not handled. Resume waits the start-up time and reads the configuration again.
- Patch 7: a PLL that stays frozen is re-selected, as described above. On manual input select the selected input is CONNECTED and a state request is refused with a message. A failed receiver power-down and a failed close of the PLL debug key are retried.
- Patch 8: the XO pin of an automatic PLL reports its priority, read-only. A state request that succeeds is notified once.
- Patch 9: the setter accepts up to 2949.12 MHz, and 250 MHz on an LVCMOS output; the getter rounds to the nearest hertz. A failed NVM bank update is retried. The flush trigger falls before the trigger select is put back.
- Patch 10: an unmute writes back the force the loaded configuration set on each pad.
- Patch 11: the delay getter has no value while a delay waits for its re-time or update, or while the Fvco is outside the band. A request equal to the programmed delay writes nothing. A flush after a rate change waits for a pending bank update and stays pending until its trigger falls.
- Patch 12: no phase offset while the Fvco is outside the band.
- Patch 13: the getters answer from the kept record when a read fails. A failed close of an EXT page debug key is retried. A disconnect whose write fails writes the register back, so a PLL that still drives the line stays its source.
- Macros, helpers and struct fields move to the patch that first uses them.
Left for patches on top of this series once it is merged:
- reporting a loss of lock shorter than one poll period from the notification latches
- deriving the VCO rate of a PLL fed from another PLL
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 | 215 + .../devicetree/bindings/vendor-prefixes.yaml | 2 + Documentation/driver-api/dpll.rst | 11 +- Documentation/netlink/specs/dpll.yaml | 6 + 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 | 5816 +++++++++++++++++ drivers/dpll/sit9531x/core.h | 496 ++ drivers/dpll/sit9531x/dpll.c | 1632 +++++ drivers/dpll/sit9531x/dpll.h | 64 + drivers/dpll/sit9531x/prop.c | 406 ++ drivers/dpll/sit9531x/prop.h | 37 + drivers/dpll/sit9531x/regs.h | 353 + include/linux/dpll.h | 2 + 18 files changed, 9079 insertions(+), 6 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 v17 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.
Document the -ENODATA return in dpll.rst, at the two callbacks in struct dpll_pin_ops and in the netlink spec.
--- Documentation/driver-api/dpll.rst | 11 +++++++++-- Documentation/netlink/specs/dpll.yaml | 6 ++++++ drivers/dpll/dpll_netlink.c | 14 ++++++++++---- include/linux/dpll.h | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-)
Documentation/driver-api/dpll.rst +9 -2
@@ -195,7 +195,9 @@ Phase offset measurement and adjustment Device may provide ability to measure a phase difference between signals on a pin and its parent dpll device. If pin-dpll phase offset measurement is supported, it shall be provided with ``DPLL_A_PIN_PHASE_OFFSET`` -attribute for each parent dpll device. The reported phase offset may be +attribute for each parent dpll device. A driver that has no measurement +for a pin returns ``-ENODATA`` from ``phase_offset_get`` and the attribute +is left out of that parent device nest. The reported phase offset may be computed as the average of prior values and the current measurement, using the following formula:
@@ -221,6 +223,10 @@ granularity that pin handle shall be provided to the user on attributes. Configured phase adjust value is provided with ``DPLL_A_PIN_PHASE_ADJUST`` attribute of a pin, and value change can be requested with the same attribute with ``DPLL_CMD_PIN_SET`` command. +A driver that has no value for a pin returns ``-ENODATA`` from +``phase_adjust_get``; the attribute is then left out, while the minimum, +maximum and granularity are still provided, and a requested value is +passed to the driver without a comparison against the old one. ================================ ========================================== ``DPLL_A_PIN_ID`` configured pin id
@@ -260,7 +266,8 @@ In such cases, users can also control the feature using the ``DPLL_CMD_DEVICE_SET`` command by setting the ``enum dpll_feature_state`` values for the attribute. Once enabled the phase offset measurements for the input shall be returned -in the ``DPLL_A_PIN_PHASE_OFFSET`` attribute. +in the ``DPLL_A_PIN_PHASE_OFFSET`` attribute, except for an input the driver +has no measurement for (see above). =============================== ======================== ``DPLL_A_PHASE_OFFSET_MONITOR`` attr state of a feature
Documentation/netlink/specs/dpll.yaml +6 -0
@@ -456,9 +456,15 @@ attribute-sets: - name: phase-adjust type: s32 + doc: | + Configured phase adjustment of the pin, in picoseconds. + Left out when the driver has no value for the pin. - name: phase-offset type: s64 + doc: | + Measured phase difference between the pin and the parent dpll + device. Left out when the driver has no measurement for the pin. - name: fractional-frequency-offset type: sint
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),
include/linux/dpll.h +2 -0
@@ -121,10 +121,12 @@ struct dpll_pin_ops {int (*prio_set)(const struct dpll_pin *pin,void *pin_priv,const struct dpll_device *dpll,void *dpll_priv,const u32 prio,struct netlink_ext_ack *extack); +/* -ENODATA: no value, DPLL_A_PIN_PHASE_OFFSET is left out */ int (*phase_offset_get)(const struct dpll_pin *pin,void *pin_priv,const struct dpll_device *dpll,void *dpll_priv,s64 *phase_offset,struct netlink_ext_ack *extack); +/* -ENODATA: no value, DPLL_A_PIN_PHASE_ADJUST is left out */ int (*phase_adjust_get)(const struct dpll_pin *pin, void *pin_priv, const struct dpll_device *dpll, void *dpll_priv, s32 *phase_adjust,
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v17 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 v17 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 enables the supplies a board describes and waits the start-up time of the datasheet before its first access.
--- .../bindings/dpll/sitime,sit95316.yaml | 215 ++++++++++++++++++ MAINTAINERS | 6 + 2 files changed, 221 insertions(+) create mode 100644 Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml
Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml new file +215 -0
@@ -0,0 +1,215 @@ +# 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. The rate is one 32-bit cell, as is each + rate an output pin lists. + +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)
PATCH v17 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 twelve outputs, configured from efuse or 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 would read the selector back on each access, doubling the bus traffic. A debugfs dump of the map reads the page the driver selected last.
Probe requests the optional reset line before it enables the supplies and the XO, so a deferred probe does not gate the clock of a running part. It enables the described supplies, reads the XO rate and releases reset without pulsing it, keeping the configuration the part holds. It waits the 10 ms power-up to I2C-ready time of the datasheet (TSTART), then identifies the variant from the ID register. Devres releases the XO clock and supplies on a probe failure and at unbind; a clock or rail the part needs with no driver bound is marked always-on by its provider.
--- 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 | 291 +++++++++++++++++++++++++++++++++ drivers/dpll/sit9531x/core.h | 74 +++++++++ drivers/dpll/sit9531x/regs.h | 29 ++++ 8 files changed, 415 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 +291 -0
291 lines not on this page · raw message
drivers/dpll/sit9531x/core.h new file +74 -0
74 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h new file +29 -0
@@ -0,0 +1,29 @@ +/* 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_REG (_page, _offset) (((_page) << 8) | (_offset)) +#define SIT9531X_REG_PAGE (_reg) ((_reg) >> 8) +#define SIT9531X_REG_OFFSET (_reg) ((_reg) & 0xFF) + +/* 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)
PATCH v17 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 caller gives the direction, which 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 with the output rates of the datasheet, since the core refuses every frequency request on a pin with
none: every rate from 1 Hz to 800 MHz, and 61.44 MHz times 15, 20, 24, 30, 32, 40 and 48 above it.
--- drivers/dpll/sit9531x/Makefile | 2 +- drivers/dpll/sit9531x/core.h | 53 +++++ drivers/dpll/sit9531x/prop.c | 350 +++++++++++++++++++++++++++++++++ drivers/dpll/sit9531x/prop.h | 37 ++++ 4 files changed, 441 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 +53 -0
82 lines not on this page · raw message
drivers/dpll/sit9531x/prop.c new file +350 -0
350 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)
PATCH v17 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.
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, acknowledges the notification latches and notifies the core of what changed; a transition that begins and ends inside one period is not reported. INTRB, where wired, acknowledges them and schedules a tick early.
The sleep PM operations stop and restart the poll. As the part may lose power over suspend, resume waits the start-up time, reads the input pair modes, the select mode of each PLL and the output routing again, and notifies what changed.
A PLL that arbitrates by priority is reported AUTOMATIC, one on manual input select MANUAL. The clock_id is the nine-byte die ID folded to 64 bits; a blank or duplicate ID gives one from the SiTime OUI, the I2C bus number and the 7-bit address.
--- drivers/dpll/sit9531x/Kconfig | 4 + drivers/dpll/sit9531x/Makefile | 2 +- drivers/dpll/sit9531x/core.c | 1596 +++++++++++++++++++++++++++++++- drivers/dpll/sit9531x/core.h | 137 ++- drivers/dpll/sit9531x/dpll.c | 279 ++++++ drivers/dpll/sit9531x/dpll.h | 60 ++ drivers/dpll/sit9531x/regs.h | 173 ++++ 7 files changed, 2199 insertions(+), 52 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 +1548 -48
1,681 lines not on this page · raw message
drivers/dpll/sit9531x/core.h +134 -3
199 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.c new file +279 -0
279 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.h new file +60 -0
60 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h +173 -0
182 lines not on this page · raw message
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v17 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. CONNECTED is refused: the PLL selects by priority. On manual input select the selected input is CONNECTED and requests are refused.
A table write uses the documented procedure: force holdover, write the slots and the active selection, latch with a small update, release. A PLL whose table is emptied stays in forced holdover.
A receiver, shared by the PLLs and by both lanes of a pair, is powered down while no PLL may select its input; SELECTABLE gives it back to the loaded configuration, and one it keeps off stays off.
The poll re-selects a PLL in holdover while a listed source has signal:
after probe and resume, when it finds frozen a PLL that tracked a reference, and after 10 s frozen. It backs off to eight periods while the part gives no answer and rate-limits warnings. Probe warns of a pin node naming no pin. The debug status register is marked precious: each read advances its latch.
--- drivers/dpll/sit9531x/core.c | 1325 ++++++++++++++++++++++++++++++++-- drivers/dpll/sit9531x/core.h | 121 +++- drivers/dpll/sit9531x/dpll.c | 301 +++++++- drivers/dpll/sit9531x/dpll.h | 2 + drivers/dpll/sit9531x/prop.c | 20 +- drivers/dpll/sit9531x/regs.h | 59 +- 6 files changed, 1750 insertions(+), 78 deletions(-)
drivers/dpll/sit9531x/core.c +1265 -60
@@ -62,10 +62,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 , };
@@ -175,6 +186,66 @@ int sit9531x_read_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,return sit9531x_read_u8 (sitdev,SIT9531X_REG (page, offset), val); } +int sit9531x_write_pll_u8 (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 offset,u8 val) +{ +u8 page =sit9531x_pll_page (pll_idx); + +return sit9531x_write_u8 (sitdev,SIT9531X_REG (page, offset), val); +} + +int sit9531x_update_pll_u8 (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 offset,u8 mask,u8 val) +{ +u8 page =sit9531x_pll_page (pll_idx); +unsigned int reg =SIT9531X_REG (page, offset); +unsigned int orig, tmp; +int rc; + +mutex_lock (&sitdev->page_lock); + rc =sit9531x_read_locked (sitdev, reg, &orig); +if (!rc) { + tmp = (orig & ~mask) | (val & mask); +if (tmp != orig) + rc =sit9531x_write_locked (sitdev, reg, tmp); + } +mutex_unlock (&sitdev->page_lock); +if (rc) +dev_err_ratelimited (sitdev->dev, +"Failed to update page 0x%02x reg 0x%02x: %d\n" , + page, offset, rc); + +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,
@@ -192,6 +263,75 @@ 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; + +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); + +/* +* STATE before FORCE: the override applies the STATE bit as it is, so +* FORCE is written only once STATE is clear. +*/ + rc =sit9531x_read_u8 (sitdev, state_reg, &val); +if (!rc) + rc =sit9531x_write_u8 (sitdev, state_reg, val & ~BIT (pair)); +if (!rc) + rc =sit9531x_read_u8 (sitdev, force_reg, &val); +if (!rc) + rc =sit9531x_write_u8 (sitdev, force_reg, val |BIT (pair)); + + ref->enabled = false; + ref->off_pending = rc !=0 ; + +return rc; +} + +/* +* Release the force so the lane uses the loaded configuration, as the +* input_enable() of input_dsable_control.py does; a receiver the configuration +* keeps off stays off. 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
@@ -323,6 +463,16 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,return 0 ; } +/* +* Procedure: +* 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, unless something other than this driver forced it +* +* Caller must hold sitdev->multiop_lock. +*/ +static u16 sit9531x_prio_reg (u8 pll_idx,u8 slot) { return SIT9531X_REG(SIT9531X_PAGE_PRIOSYS,
@@ -340,39 +490,607 @@ 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; + } + +/* A source keeps the lane code the table last listed it by. */ +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) { +if (i >= n) + srcs[i] =SIT9531X_PRIO_SRC_NONE ; +else if (chan->lane_known &BIT (order[i])) + srcs[i] = chan->lane_code[order[i]]; +else + srcs[i] = order[i]; + } +} + +/* +* 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 ; + chan->lane_code[src_canon] = src; + chan->lane_known |=BIT (src_canon); + } + } + +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 ; +} + +/* +* Return the code by which a table lists a canonical source, or +* SIT9531X_PRIO_SRC_NONE. A differential pair may be listed by its N-lane code. +*/ +static u8 sit9531x_prio_table_code (const struct sit9531x_dev *sitdev, +const u8 *srcs,u8 canon) +{ +u8 i, src; + +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) { + src = srcs[i] &SIT9531X_PRIO_NIBBLE_MASK ; +if (sit9531x_prio_src_usable (src) && +sit9531x_prio_src_canon (sitdev, src) == canon) +return src; + } -if (sit9531x_prio_src_usable (src)) - mask |=BIT (src); +return SIT9531X_PRIO_SRC_NONE ; +} + +/* +* Pick the active selection to latch. The PLL keeps the selected source +* unless the best live source changed; an @idle PLL, found without a +* reference by the poll, takes the best live source. The pick is the code +* the table lists the source by. +*/ +static u8 sit9531x_prio_activesel_pick (struct sit9531x_dev *sitdev, +const u8 *old,const u8 *srcs,u8 cur, +bool idle) +{ +u8 top, code, i; + + top =sit9531x_prio_top_live (sitdev, srcs); +if (top !=SIT9531X_PRIO_SRC_NONE && + (idle || top !=sit9531x_prio_top_live (sitdev, old))) +return sit9531x_prio_table_code (sitdev, srcs, top); + + cur =sit9531x_prio_src_canon (sitdev, cur &SIT9531X_PRIO_NIBBLE_MASK ); + +if (sit9531x_prio_src_usable (cur) && +sit9531x_prio_src_live (sitdev, cur)) { + code =sit9531x_prio_table_code (sitdev, srcs, cur); +if (code !=SIT9531X_PRIO_SRC_NONE ) +return code; + } + +if (top !=SIT9531X_PRIO_SRC_NONE ) +return sit9531x_prio_table_code (sitdev, srcs, top); + +for (i =0 ; i <SIT9531X_PRIO_MAX_SLOTS ; i++) +if (sit9531x_prio_src_usable (srcs[i])) +return srcs[i]; + +return srcs[0 ]; +} + +static int sit9531x_prio_table_commit (struct sit9531x_dev *sitdev,u8 pll_idx, +const u8 *srcs,bool reselect) +{ +u8 now[SIT9531X_PRIO_MAX_SLOTS ], back[SIT9531X_PRIO_MAX_SLOTS ]; +u8 val, last_old, slot, attempt, top, written =0 , restored =0 ; +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +bool pending_before = chan->table_pending; +bool empty, ho_foreign, ho_undo = false, pending = false; +int rc =0 , prg_rc, ho_rc =0 ; +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, when the driver kept it for an empty table, or when 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; + +if (!(val &BIT (SIT9531X_PLL_HO_FORCE_BIT ))) + chan->ho_kept = false; + ho_foreign = (val &BIT (SIT9531X_PLL_HO_FORCE_BIT )) && + chan->prio_mask && !chan->ho_kept && + !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) { +/* +* The write may have reached the part; the release decides the +* bit as after a table write, from its value before this write. +*/ + ho_undo = !(val &BIT (SIT9531X_PLL_HO_FORCE_BIT )); + 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 ); +bool idle; + + rc =sit9531x_input_mon_fetch (sitdev); +if (rc) + goto rollback; + idle = reselect && (!chan->locked || chan->inner_lol || + chan->mode || chan->ho_freeze); + sel =sit9531x_prio_activesel_pick (sitdev, chan->prio_srcs, + srcs, sel, idle); + 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; + } +/* A latch starts a new acquisition; see sit9531x_reselect(). */ +if (!prg_rc) { + chan->tracked = false; + chan->stall_polls =0 ; + } + +if (!rc) { +sit9531x_prio_mask_build (sitdev, pll_idx, srcs); +/* Re-select compares against this table's best live source */ + top =sit9531x_prio_top_live (sitdev, srcs); +if (top != chan->live_top) + chan->stall_shift =0 ; + chan->live_top = top; +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 && !ho_undo) { +dev_dbg (sitdev->dev, +"PLL%c: no source listed, holdover kept\n" , +'A' + pll_idx); + chan->ho_release_pending = false; + chan->ho_kept = true; + 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; +if (!ho_rc) + chan->ho_kept = false; + +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. */ +static int sit9531x_prio_table_read (struct sit9531x_dev *sitdev,u8 pll_idx, +u8 *srcs) +{ +u8 val, slot; +int rc; + +for (slot =0 ; slot <SIT9531X_PRIO_MAX_SLOTS ; slot++) { + rc =sit9531x_read_u8 (sitdev, +sit9531x_prio_reg (pll_idx, slot), &val); +if (rc) +return rc; + + srcs[slot] =sit9531x_prio_slot_get (val, slot); + } + +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, false); +} + +/* +* 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)); } -/* Caller must hold sitdev->multiop_lock. */ -static int sit9531x_prio_table_read (struct sit9531x_dev *sitdev,u8 pll_idx, -u8 *srcs) +/* +* 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) { -u8 val, slot; -int rc; +struct sit9531x_chan *chan; -for (slot =0 ; slot <SIT9531X_PRIO_MAX_SLOTS ; slot++) { - rc =sit9531x_read_u8 (sitdev, -sit9531x_prio_reg (pll_idx, slot), &val); -if (rc) -return rc; +lockdep_assert_held (&sitdev->multiop_lock); - srcs[slot] =sit9531x_prio_slot_get (val, slot); - } +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 ; -return 0 ; + 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)); }/* The latches INTRB reports, each with its sticky bits */
@@ -508,7 +1226,8 @@ static int sit9531x_pll_is_active(struct sit9531x_dev *sitdev, u8 pll_idx,static int sit9531x_chan_select_fetch (struct sit9531x_dev *sitdev,u8 pll_idx) {struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; -bool manual_input = false; +bool manual_input = false, manual_any = false; +u8 manual_ref =SIT9531X_REF_INVALID ;u8 cfg, misc, sel;int rc;
@@ -534,8 +1253,13 @@ static int sit9531x_chan_select_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)if (rc)return rc; manual_input = true; + manual_any = !(sel &SIT9531X_MAN_IN_SEL_FROM_REG ) || + (sel &SIT9531X_MAN_IN_SEL_INDIRECT );if (sel &SIT9531X_MAN_IN_SEL_FROM_REG ) { sel =FIELD_GET (SIT9531X_MAN_IN_SEL_MASK , sel); + manual_ref = +sit9531x_hw_src_input (sit9531x_prio_src_canon (sitdev, + sel));dev_dbg (sitdev->dev,"PLL%c: the profile selects its reference from the register, input code %u; reported as manual\n" ,'A' + pll_idx, sel);
@@ -544,24 +1268,81 @@ static int sit9531x_chan_select_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)"PLL%c: the profile selects its reference from the input-select pins; reported as manual\n" , 'A' + pll_idx); } +/* +* The select pins and the indirect choice are not read here: a PLL +* found on them again keeps the input it last tracked. +*/ +if (manual_any && chan->manual_input && chan->manual_any) + manual_ref = chan->manual_ref; record: chan->manual_input = manual_input; + chan->manual_any = manual_any; + chan->manual_ref = manual_ref;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 ); + sitdev->chan[pll_idx].key_pending = !!lock_rc; + +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;/*
@@ -582,21 +1363,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)
@@ -607,23 +1373,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 );
@@ -739,11 +1530,53 @@ static int sit9531x_ref_pll_mask_fetch(struct sit9531x_dev *sitdev)return 0 ; } +/* +* Mark the input each manual-select PLL uses, or every input when the driver +* does not read which; 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, i; + +for (pll_idx =0 ; pll_idx <SIT9531X_NUM_PLLS ; pll_idx++) { + chan = &sitdev->chan[pll_idx]; +if (!chan->manual_input) +continue ; +/* +* The select pins can move such a PLL to any input at any +* time, so no receiver is turned off under it. +*/ +if (chan->manual_any) { +for (i =0 ; i < sitdev->info->num_inputs; i++) + sitdev->ref[i].pll_mask |=BIT (pll_idx); +continue ; + } +if (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; + sitdev->chan[i].stall_polls =0 ; + sitdev->chan[i].stall_shift =0 ; + } +} +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);
@@ -763,6 +1596,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; + } +for (i =0 ; i < sitdev->info->num_outputs; i++) {mutex_lock (&sitdev->multiop_lock); rc =sit9531x_out_state_fetch (sitdev, i);
@@ -798,34 +1638,279 @@ 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 of the PLLs that select by +* priority and from 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; + +/* A PLL on manual input select does not use its table */ +if (sitdev->chan[pll_idx].manual_input) +continue ; + +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; + chan->ho_kept = 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, false)) +return ; + +dev_info (sitdev->dev,"PLL%c: priority table written back\n" , +'A' + pll_idx); +} + +/* Lock the PLL debug key again. Caller must hold sitdev->multiop_lock. */ +static void sit9531x_debug_back_retry (struct sit9531x_dev *sitdev,u8 pll_idx) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; + +if (!chan->key_pending) +return ; + + chan->key_pending = !!sit9531x_write_pll_close (sitdev, pll_idx, +SIT9531X_PLL_REG_DEBUG , +SIT9531X_PLL_DEBUG_LOCK ); +} + +/* +* Frozen polls after which a stalled PLL is re-selected: 20, 10 s, doubled +* after each such re-select up to 1280, 640 s. +*/ +#define SIT9531X_RESELECT_STALL_POLLS 20 +#define SIT9531X_RESELECT_STALL_SHIFT_MAX 6 + +/* +* Rewrite the table of a PLL without a reference while a listed source has +* signal; the write latches the active selection again. A latch restarts +* acquisition: write once on a loss of the reference, on a change of the best +* live source and after each stall. 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]; +bool repeat = false; +u16 stall; +u8 top; +int rc; + +/* +* A PLL on manual input select uses no priority table, and an unused +* PLL, which never goes active, has no acquisition to restart. +*/ +if (chan->manual_input || !chan->active || !chan->prio_mask || + chan->mode || chan->ho_release_pending || chan->table_pending) +return ; + +/* +* A PLL that tracked a reference since its last latch and is frozen now +* has lost it. The monitors may not show it: after a dropout shorter +* than the poll period the best live source is the one it was. +*/ +if (sit9531x_chan_tracking (chan)) { + chan->tracked = true; + chan->stall_polls =0 ; + chan->stall_shift =0 ; + }else if (chan->tracked && chan->ho_freeze) { + chan->tracked = false; + chan->reselect_armed = true; + } + + top =sit9531x_prio_top_live (sitdev, chan->prio_srcs); +/* +* A PLL that locks and loses its source between two polls is not seen +* to track. It stalls when it stays frozen with the best live source +* unchanged since the last latch; each re-select for a stall doubles +* the count for the next one. +*/ + stall =SIT9531X_RESELECT_STALL_POLLS << chan->stall_shift; +if (top != chan->live_top) { + chan->stall_polls =0 ; + chan->stall_shift =0 ; + }else if (chan->ho_freeze && top !=SIT9531X_PRIO_SRC_NONE && + chan->stall_polls < stall && ++chan->stall_polls == stall) { + chan->reselect_armed = true; + repeat = chan->stall_shift >0 ; +if (chan->stall_shift <SIT9531X_RESELECT_STALL_SHIFT_MAX ) + chan->stall_shift++; + } + +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, true); +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; +if (repeat) +dev_dbg (sitdev->dev,"PLL%c: re-selecting, still frozen\n" , +'A' + pll_idx); +else +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); +sit9531x_debug_back_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)
@@ -834,6 +1919,7 @@ static void sit9531x_dev_periodic_work(struct kthread_work *work) work.work);struct sit9531x_dpll *sitdpll;bool latched; +bool answered;int rc;/*
@@ -841,8 +1927,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)
@@ -860,8 +1946,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. */
@@ -1000,6 +2092,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;
@@ -1014,6 +2163,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) {
@@ -1038,6 +2189,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);
@@ -1045,6 +2197,44 @@ 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); +sit9531x_debug_back_retry (sitdev, i); +if (sitdev->chan[i].key_pending) +dev_warn (sitdev->dev, +"PLL%c left with its debug window open\n" , +'A' + i); + } + +/* After the table write-back: the tables give the receiver claims */ +sit9531x_ref_pll_mask_rebuild (sitdev); +sit9531x_input_off_retry (sitdev); +for (i =0 ; i < sitdev->info->num_inputs; i++) +if (sitdev->ref[i].off_pending) +dev_warn (sitdev->dev, +"input %u: receiver gate-off not applied at removal\n" , + i); +mutex_unlock (&sitdev->multiop_lock); } static struct sit9531x_dpll_pin *
@@ -1088,8 +2278,11 @@ static int sit9531x_dpll_pin_register(struct sit9531x_dpll_pin *pin, }dpll_pin_fwnode_set (pin->dpll_pin, props->fwnode); - rc =dpll_pin_register (sitdpll->dpll_dev, pin->dpll_pin, -sit9531x_dpll_pin_ops_get (pin), pin); +/* Kept for the unregister: resume reads the select mode again */ + pin->ops =sit9531x_dpll_pin_ops_get (pin); + + rc =dpll_pin_register (sitdpll->dpll_dev, pin->dpll_pin, pin->ops, + pin);if (rc) goto err_register;
@@ -1119,8 +2312,7 @@ static void sit9531x_dpll_pin_unregister(struct sit9531x_dpll_pin *pin)*/ pin->dpll_pin =NULL ; -dpll_pin_unregister (sitdpll->dpll_dev, dpll_pin, -sit9531x_dpll_pin_ops_get (pin), pin); +dpll_pin_unregister (sitdpll->dpll_dev, dpll_pin, pin->ops, pin);dpll_pin_put (dpll_pin, &pin->tracker);fwnode_handle_put (pin->fwnode);
@@ -1159,10 +2351,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)
@@ -1709,6 +2906,9 @@ static int sit9531x_resume(struct device *dev)sit9531x_page_cache_drop (sitdev);mutex_lock (&sitdev->multiop_lock); +/* One re-select for a source lost and restored between samples */ +sit9531x_reselect_arm (sitdev); +/* Read again the configuration probe read */ for (i =0 ; i < sitdev->info->num_inputs /2 ; i++) {enum sit9531x_signal_mode mode = sitdev->ref[i *2 ].sig_mode;
@@ -1720,7 +2920,7 @@ static int sit9531x_resume(struct device *dev) i, rc); else if (sitdev->ref[i * 2].sig_mode != mode) dev_warn(sitdev->dev, -"CLKIN%u: signal mode changed over suspend\n" , +"CLKIN%u: signal mode changed over suspend; its pins stay as they were registered\n" , i); }for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {
@@ -1730,7 +2930,7 @@ static int sit9531x_resume(struct device *dev) rc =sit9531x_chan_select_fetch (sitdev, i);if (!rc && chan->manual_input != manual) {dev_warn (sitdev->dev, -"PLL%c: select mode changed over suspend\n" , +"PLL%c: select mode changed over suspend; its pins keep the callbacks of the mode they were registered for; rebind the driver to manage its inputs\n" ,'A' + i); modes_moved |=BIT (i); }
@@ -1741,8 +2941,13 @@ static int sit9531x_resume(struct device *dev)"PLL%c: state not read on resume: %d\n" , 'A' + i, rc); chan->stale = true; +continue ; } +/* A forced holdover over a listed table is the profile's */ +if (!chan->table_pending && chan->prio_mask) + chan->ho_kept = false; } +sit9531x_ref_pll_mask_rebuild (sitdev);for (i =0 ; i < sitdev->info->num_outputs; i++) {struct sit9531x_out *out = &sitdev->out[i];bool routed = out->routed;
drivers/dpll/sit9531x/core.h +116 -5
200 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.c +294 -7
363 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.h +2 -0
@@ -23,12 +23,14 @@ struct sit9531x_dpll_pin {struct list_head list;struct sit9531x_dpll *dpll;struct dpll_pin *dpll_pin; +const struct dpll_pin_ops *ops;/* as registered */ dpll_tracker tracker;struct fwnode_handle *fwnode;char label[8 ];/* "IN0", "OUT3" */ enum dpll_pin_direction dir;u8 id;/* hardware index */ enum dpll_pin_state pin_state; +enum dpll_pin_operstate operstate;bool seen;/* baseline taken by the poll */ };
drivers/dpll/sit9531x/prop.c +18 -2
@@ -24,6 +24,22 @@/* Multiples of SIT9531X_OUT_FREQ_STEP_HZ an output runs above 800 MHz */ static const u8 sit9531x_out_freq_mult[] = {15 ,20 ,24 ,30 ,32 ,40 ,48 }; +/* +* An input pin is registered with all four PLLs and takes a state request +* on those found on automatic input selection at probe. +*/ +static u32 sit9531x_prop_input_caps (const struct sit9531x_dev *sitdev) +{ +u8 i; + +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +if (!sit9531x_chan_state_get (sitdev, i)->manual_input) +return DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; + } + +return 0 ; +} +static void sit9531x_input_pin_label (struct sit9531x_dev *sitdev,struct sit9531x_pin_props *props,u8 id) {
@@ -149,7 +165,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_STATE_CAN_CHANGE ; +sit9531x_prop_input_caps (sitdev); curr_freq =0 ; }else if (sync_out) {/* INTSYNC source: driving it is not a reference selection */
@@ -164,7 +180,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_STATE_CAN_CHANGE ; +sit9531x_prop_input_caps (sitdev); curr_freq = sitdev->ref[index].freq; }else { props->dpll_props.type =DPLL_PIN_TYPE_EXT ;
drivers/dpll/sit9531x/regs.h +55 -4
92 lines not on this page · raw message
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v17 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 once the input is made selectable. The range is 0 to 255 over eleven slots; inputs of equal priority keep their table order.
A table write that leaves the best live source unchanged keeps as the active selection the source the PLL tracks, read at the write, or the selected one it acquires, so the PLL does not restart acquisition for it. The XO pin of an automatic PLL reports, read-only, the priority the table is built with for the oscillator.
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 record taken at registration and after a state request that succeeds, which the core notifies, and notifies a changed operational state or priority; a notification that fails is sent again on a later tick.
--- drivers/dpll/sit9531x/core.c | 181 +++++++++++++++++++++++---- drivers/dpll/sit9531x/core.h | 8 +- drivers/dpll/sit9531x/dpll.c | 232 ++++++++++++++++++++++++++++++----- drivers/dpll/sit9531x/dpll.h | 4 +- drivers/dpll/sit9531x/prop.c | 7 +- 5 files changed, 371 insertions(+), 61 deletions(-)
drivers/dpll/sit9531x/core.c +158 -23
@@ -609,6 +609,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.
@@ -726,6 +753,7 @@ static void sit9531x_prio_mask_build(struct sit9531x_dev *sitdev, u8 pll_idx,static int sit9531x_prio_table_read (struct sit9531x_dev *sitdev,u8 pll_idx,u8 *srcs); +static int sit9531x_chan_lock_fetch (struct sit9531x_dev *sitdev,u8 pll_idx);static int sit9531x_chan_state_fetch (struct sit9531x_dev *sitdev,u8 pll_idx); static u8 sit9531x_prio_top_live(const struct sit9531x_dev *sitdev,
@@ -764,14 +792,14 @@ static u8 sit9531x_prio_table_code(const struct sit9531x_dev *sitdev, }/* -* Pick the active selection to latch. The PLL keeps the selected source -* unless the best live source changed; an @idle PLL, found without a -* reference by the poll, takes the best live source. The pick is the code -* the table lists the source by. +* Pick the active selection to latch. The PLL keeps the source it tracks, or +* the selected one it acquires, unless the best live source changed; an @idle +* PLL, found without a reference by the poll, takes the best live source. The +* pick is the code by which the table lists the source. */ static u8 sit9531x_prio_activesel_pick (struct sit9531x_dev *sitdev,const u8 *old,const u8 *srcs,u8 cur, -bool idle) +u8 routed,bool idle) {u8 top, code, i;
@@ -780,6 +808,13 @@ static u8 sit9531x_prio_activesel_pick(struct sit9531x_dev *sitdev, (idle || top != sit9531x_prio_top_live(sitdev, old)))return sit9531x_prio_table_code (sitdev, srcs, top); +if (sit9531x_prio_src_usable (routed) && +sit9531x_prio_src_live (sitdev, routed)) { + code =sit9531x_prio_table_code (sitdev, srcs, routed); +if (code !=SIT9531X_PRIO_SRC_NONE ) +return code; + } + cur =sit9531x_prio_src_canon (sitdev, cur &SIT9531X_PRIO_NIBBLE_MASK ); if (sit9531x_prio_src_usable(cur) &&
@@ -818,6 +853,16 @@ static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_idx,memcpy (back, chan->table_pending ? chan->table_back : chan->prio_srcs,sizeof (back)); +/* +* Sample the lock state and the routed source for the pick before the +* forced holdover changes them. +*/ +if (!empty) { + rc =sit9531x_chan_lock_fetch (sitdev, pll_idx); +if (rc) +return rc; + } +/* * Treat a forced holdover as set by this driver only when the table is * empty, when the driver kept it for an empty table, or when a release
@@ -873,15 +918,23 @@ 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 ;bool idle; +/* +* The pick needs the signal state now, not as of the last poll; +* the routed source and the lock state were sampled before this +* write forced holdover. +*/ rc =sit9531x_input_mon_fetch (sitdev);if (rc) goto rollback; +if (chan->routed_ref !=SIT9531X_REF_INVALID ) + routed =sit9531x_input_hw_src (chan->routed_ref); idle = reselect && (!chan->locked || chan->inner_lol || chan->mode || chan->ho_freeze); sel =sit9531x_prio_activesel_pick (sitdev, chan->prio_srcs, - srcs, sel, idle); + srcs, sel, routed, idle); val =sit9531x_prio_slot_set (val, slot +1 , sel); }
@@ -1043,6 +1096,59 @@ static int sit9531x_prio_table_apply(struct sit9531x_dev *sitdev, u8 pll_idx,return sit9531x_prio_table_commit (sitdev, pll_idx, srcs, false); } +/* +* 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.
@@ -1333,14 +1439,13 @@ static int sit9531x_chan_routed_ref_read(struct sit9531x_dev *sitdev, }/* -* Read the PLL's run, lock and holdover state, mode, selection and priority -* table. +* Read the PLL's run, lock and holdover-freeze state and, while it tracks a +* reference, the routed source. Caller must hold sitdev->multiop_lock. */ -static int sit9531x_chan_state_fetch (struct sit9531x_dev *sitdev,u8 pll_idx) +static int sit9531x_chan_lock_fetch (struct sit9531x_dev *sitdev,u8 pll_idx) { -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 status, outer_lol, inner_lol, ho_freeze;u8 routed =SIT9531X_REF_INVALID ;bool active, tracking;int rc;
@@ -1386,6 +1491,34 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)return rc; } +/* 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->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)); + +return 0 ; +} + +/* +* 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) +{ +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +u8 srcs[SIT9531X_PRIO_MAX_SLOTS ]; +u8 pll_status_1; +int rc; + + rc =sit9531x_chan_lock_fetch (sitdev, pll_idx); +if (rc) +return rc; + rc =sit9531x_read_pll_u8 (sitdev, pll_idx,SIT9531X_PLL_REG_STATUS_1 , &pll_status_1);if (rc)
@@ -1408,15 +1541,6 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)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->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 ); chan->stale = false;
@@ -2333,8 +2457,8 @@ static void sit9531x_dpll_pins_unregister(struct sit9531x_dpll *sitdpll)sit9531x_dpll_pin_unregister (pin);/* -* Detached under multiop_lock, as every list change is; the poll is -* already canceled or not yet queued. +* Detached under multiop_lock, which callbacks walking the list hold; +* the poll is already canceled or not yet queued. */ mutex_lock (&sitdev->multiop_lock);list_splice_init (&sitdpll->pins, &dead);
@@ -2387,13 +2511,24 @@ 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); goto error; } -/* List changes are made under multiop_lock */ +/* +* Earlier pins are already reachable from netlink, and the +* walks over this list run under multiop_lock. +*/ mutex_lock (&sitdpll->dev->multiop_lock);list_add (&pin->list, &sitdpll->pins);mutex_unlock (&sitdpll->dev->multiop_lock);
drivers/dpll/sit9531x/core.h +6 -2
@@ -130,8 +130,8 @@ struct sit9531x_out {* @active: PLL reached its active state; an unused PLL never does and its * loss-of-lock bit stays clear * @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 +* @stale: last state read failed; the fields hold an earlier sample, or +* part of a new one, and are not reported * @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
@@ -287,6 +287,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 +200 -32
302 lines not on this page · raw message
drivers/dpll/sit9531x/dpll.h +3 -1
@@ -29,9 +29,10 @@ struct sit9531x_dpll_pin {char label[8 ];/* "IN0", "OUT3" */ enum dpll_pin_direction dir;u8 id;/* hardware index */ +u8 prio;enum dpll_pin_state pin_state;enum dpll_pin_operstate operstate; -bool seen;/* baseline taken by the poll */ +bool ntf_pending; };struct sit9531x_dpll {
@@ -57,6 +58,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 +4 -3
@@ -25,8 +25,8 @@static const u8 sit9531x_out_freq_mult[] = {15 ,20 ,24 ,30 ,32 ,40 ,48 };/* -* An input pin is registered with all four PLLs and takes a state request -* on those found on automatic input selection at probe. +* An input pin is registered with all four PLLs and takes a state or +* priority request on those found on automatic input selection at probe. */ static u32 sit9531x_prop_input_caps (const struct sit9531x_dev *sitdev) {
@@ -34,7 +34,8 @@ static u32 sit9531x_prop_input_caps(const struct sit9531x_dev *sitdev)for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {if (!sit9531x_chan_state_get (sitdev, i)->manual_input) -return DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; +return DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE | +DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; }return 0 ;
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v17 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 it 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, and on an LVCMOS output up to 250 MHz. An output whose divider chain does not resolve, or whose Fref * DIVN is outside the PLL's VCO band, reports 0 Hz and takes no rate.
A divider write takes effect only inside the programming state, and the documented 100 ms settling time after the loop-lock command is waited under the device lock. The poll and removal retry a failed bank update. 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 | 688 ++++++++++++++++++++++++++++++++++- drivers/dpll/sit9531x/core.h | 16 + drivers/dpll/sit9531x/dpll.c | 124 +++++++ drivers/dpll/sit9531x/prop.c | 43 ++- drivers/dpll/sit9531x/regs.h | 44 +++ 5 files changed, 904 insertions(+), 11 deletions(-)
drivers/dpll/sit9531x/core.c +687 -1
@@ -463,6 +463,153 @@ 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); + + sitdev->loops_open = !!rc; +sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); +} + +/* +* 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 =0 , close_rc; +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 programming: %d\n" , + rc); + + sitdev->loops_open = !!rc; + +msleep (100 ); + +/* +* The debug key register unlocks every debug register while it holds +* the unlock value. +*/ + close_rc =sit9531x_write_close (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); +if (close_rc) +dev_warn (sitdev->dev, +"output debug block left unlocked after programming: %d\n" , + close_rc); + +return rc; +} + +/* Retry a failed loop re-lock with the debug window open, as the first try */ +static int sit9531x_prg_relock_retry (struct sit9531x_dev *sitdev) +{ +int rc, lock_rc; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_UNLOCK_VAL ); +if (rc) { + lock_rc =sit9531x_write_close (sitdev, +SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); +if (lock_rc) +dev_warn (sitdev->dev, +"output debug block left unlocked: %d\n" , + lock_rc); +return rc; + } + +return sit9531x_prg_relock (sitdev); +} + +/* Update the NVM bank and leave PRG_CMD */ +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_BANK ); + sitdev->bank_pending = !!rc; + rc2 =sit9531x_prg_relock (sitdev); + +return rc ? rc : rc2; +} + +/* +* 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, lock_rc; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_UNLOCK_VAL ); +if (rc) { + lock_rc =sit9531x_write_close (sitdev, +SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); +if (lock_rc) +dev_warn (sitdev->dev, +"output debug block left unlocked: %d\n" , + lock_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 ; +} + +/* +* Retry a pending bank update or loop re-lock. The bank update is issued in +* PRG_CMD, as Out_Freq_CHange_v2.py does. +*/ +static int sit9531x_prg_retry (struct sit9531x_dev *sitdev) +{ +int rc; + +if (!sitdev->bank_pending) +return sit9531x_prg_relock_retry (sitdev); + + rc =sit9531x_prg_enter (sitdev); +if (rc) +return rc; + +return sit9531x_prg_commit (sitdev); +} +/* * Procedure: * 1. Force PLL into holdover (PLL page reg 0x6F bit 4)
@@ -1199,6 +1346,525 @@ 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 */ + +/* VCO frequency bands (Hz) */ +#define SIT9531X_FVCO_LOWBAND_MIN 4915200000ULL +#define SIT9531X_FVCO_LOWBAND_MAX 5898240000ULL +#define SIT9531X_FVCO_HIGHBAND_MIN 6875000000ULL +#define SIT9531X_FVCO_HIGHBAND_MAX 7812500000ULL + +#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 ; + +/* +* The VCO runs inside its band; Fref * DIVN outside it is not the +* PLL's rate, as for a PLL fed from another PLL. +*/ +if (!sit9531x_fvco_in_band (pll_idx, *fvco)) { +if (!(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 -ENODATA ; + } + +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 ); +if (rc) + goto restore; + +/* +* Clear the trigger with the register trigger still selected, as +* Dely_program_output.py does; the select goes back after it. +*/ + rc =sit9531x_write_close (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl); + +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 >SIT9531X_OUT_FREQ_MAX_HZ ) +return -EINVAL ; + + rc =sit9531x_get_fvco (sitdev, pll_idx, &fvco); +if (rc) +return rc == -ENODATA ? -ENODEV : rc; + + 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; + } + +/* Nearest hertz; truncation can take a listed rate out of its range */ + *frequency =div64_u64 (fvco + divo /2 , divo); + sitdev->out[out_idx].freq = *frequency; + +return 0 ; +} +/* The latches INTRB reports, each with its sticky bits */ static const struct { unsigned int reg;
@@ -2012,9 +2678,17 @@ static void sit9531x_reselect(struct sit9531x_dev *sitdev, u8 pll_idx)static bool sit9531x_dev_chan_states_update (struct sit9531x_dev *sitdev) { -bool answered = false; +bool answered = false, bank;int i, rc; +/* Retry pending writes first so the reads below see their result */ +if (sitdev->bank_pending || sitdev->loops_open) { + bank = sitdev->bank_pending; +sit9531x_prg_retry (sitdev); +if (bank && !sitdev->bank_pending) +dev_info (sitdev->dev,"output divider bank updated\n" ); + } +sit9531x_input_off_retry (sitdev);for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {sit9531x_table_back_retry (sitdev, i);
@@ -2359,6 +3033,18 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev)"input %u: receiver gate-off not applied at removal\n" , i);mutex_unlock (&sitdev->multiop_lock); + +mutex_lock (&sitdev->multiop_lock); +if (sitdev->bank_pending || sitdev->loops_open) { +sit9531x_prg_retry (sitdev); +if (sitdev->bank_pending) +dev_warn (sitdev->dev, +"output divider bank update not issued at removal\n" ); +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 +16 -0
@@ -33,6 +33,9 @@*/ #define SIT9531X_OUT_FREQ_CONT_MAX_HZ 800000000ULL#define SIT9531X_OUT_FREQ_STEP_HZ 61440000ULL +#define SIT9531X_OUT_FREQ_MAX_HZ (SIT9531X_OUT_FREQ_STEP_HZ * 48) +/* Datasheet Table 6: a single-ended (LVCMOS) output runs up to 250 MHz */ +#define SIT9531X_OUT_FREQ_CMOS_MAX_HZ 250000000ULL/* * 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
@@ -240,6 +243,10 @@ struct sit9531x_chan {* @reset_gpio: optional reset line, NULL if absent * @irq: optional INTRB IRQ, 0 if not wired * @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 +* @bank_pending: output divider bank update still to be issued */ struct sit9531x_dev {struct device *dev;
@@ -253,6 +260,7 @@ struct sit9531x_dev {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 ];
@@ -269,6 +277,9 @@ struct sit9531x_dev {struct gpio_desc *reset_gpio;int irq; + +bool loops_open; +bool bank_pending; }; int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
@@ -296,6 +307,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 +124 -0
168 lines not on this page · raw message
drivers/dpll/sit9531x/prop.c +33 -10
61 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h +44 -0
62 lines not on this page · raw message
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v17 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 running. 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. Probe records the override the loaded configuration sets on each pair, and an unmute writes that record back, so a pad the configuration forces stays forced. An output is reported muted only when both pads are forced off. A rebind takes the force registers as found: a pair forced on an output found muted is taken as the mute, also one an earlier binding set, so an unmute drives every pad.
The programming state of the previous patch now has one exit, which locks the output loops and closes the output-system debug key. A lock or a close that did not take effect is retried by the poll and at removal.
--- drivers/dpll/sit9531x/core.c | 369 ++++++++++++++++++++++++++++------- drivers/dpll/sit9531x/core.h | 25 ++- drivers/dpll/sit9531x/dpll.c | 153 ++++++++++++++- 3 files changed, 467 insertions(+), 80 deletions(-)
drivers/dpll/sit9531x/core.c +299 -70
@@ -335,8 +335,9 @@ int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index)/* * 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 -* buffers sit after the output driver, independent of the pad selection. -* ODRn_MISC0 bits 3:2 distinguish a CMOS output from a differential one. +* buffers sit after the output driver, independent of the pad selection, and +* a mute writes all three. ODRn_MISC0 bits 3:2 distinguish a CMOS output from +* a differential one. * * slot 0-7 : * DIFF 0xF2/0xF3 CMOS OutP 0xF8/0xF9 CMOS OutN 0xF6/0xF7
@@ -439,14 +440,16 @@ static int sit9531x_hiz_pair_forced(struct sit9531x_dev *sitdev,static int sit9531x_output_forced_hiz (struct sit9531x_dev *sitdev,u8 out_idx,bool *muted,bool *part) { +const struct sit9531x_out *out = &sitdev->out[out_idx];struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS ];bool pad_p, pad_n; +u8 keep;int rc;sit9531x_output_get_hiz_regs (sitdev->info->clkout_map[out_idx], p); *part = false; -if (!sitdev->out[out_idx].cmos) +if (!out->cmos)return sit9531x_hiz_pair_forced (sitdev, &p[SIT9531X_HIZ_DIFF ], muted);
@@ -457,44 +460,91 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,if (rc)return rc; +/* A pad the loaded configuration forces is not a part mute */ + keep = out->hiz_mask & ~out->hiz_state; *muted = pad_p && pad_n; - *part = pad_p != pad_n; + *part = pad_p != pad_n && + !(keep &BIT (pad_p ?SIT9531X_HIZ_CMOS_P : +SIT9531X_HIZ_CMOS_N ));return 0 ; } -#define SIT9531X_LOOP_LOCK_TRIES 3 +/* 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 ; +} -/* Close the loops and lock the debug block without committing */ -static void sit9531x_prg_abort (struct sit9531x_dev *sitdev) +static int sit9531x_hiz_set_bit (struct sit9531x_dev *sitdev, +unsigned int reg,u8 bit,bool set) { -int rc = -EIO ; -u8 attempt; +u8 cur, new_val; +int rc; -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 ); - } + rc =sit9531x_read_u8 (sitdev, reg, &cur);if (rc) -dev_err (sitdev->dev, -"output loops left unlocked after a failed entry: %d\n" , - rc); +return rc; - sitdev->loops_open = !!rc; -sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_LOCK_VAL ); + 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, lock_rc; + + rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_UNLOCK_VAL ); +if (rc) { + lock_rc =sit9531x_write_close (sitdev, +SIT9531X_REG_OUTSYS_DEBUG , +SIT9531X_DEBUG_LOCK_VAL ); + sitdev->outsys_key_pending = !!lock_rc; + } + +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 +/* * 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 =0 , close_rc; +int rc =0 ;u8 attempt;for (attempt =0 ; attempt <SIT9531X_LOOP_LOCK_TRIES ; attempt++) {
@@ -513,16 +563,7 @@ static int sit9531x_prg_relock(struct sit9531x_dev *sitdev)msleep (100 ); -/* -* The debug key register unlocks every debug register while it holds -* the unlock value. -*/ - close_rc =sit9531x_write_close (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_LOCK_VAL ); -if (close_rc) -dev_warn (sitdev->dev, -"output debug block left unlocked after programming: %d\n" , - close_rc); +sit9531x_outsys_debug_close (sitdev);return rc; }
@@ -530,20 +571,11 @@ static int sit9531x_prg_relock(struct sit9531x_dev *sitdev)/* Retry a failed loop re-lock with the debug window open, as the first try */ static int sit9531x_prg_relock_retry (struct sit9531x_dev *sitdev) { -int rc, lock_rc; +int rc; - rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_UNLOCK_VAL ); -if (rc) { - lock_rc =sit9531x_write_close (sitdev, -SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_LOCK_VAL ); -if (lock_rc) -dev_warn (sitdev->dev, -"output debug block left unlocked: %d\n" , - lock_rc); + rc =sit9531x_outsys_debug_open (sitdev); +if (rc)return rc; - }return sit9531x_prg_relock (sitdev); }
@@ -562,30 +594,21 @@ static int sit9531x_prg_commit(struct sit9531x_dev *sitdev) }/* -* Unlock the Page 3 debug registers and enter PRG_CMD; output-system writes -* take effect only in this state. +* 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, lock_rc; +int rc; - rc =sit9531x_write_u8 (sitdev,SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_UNLOCK_VAL ); -if (rc) { - lock_rc =sit9531x_write_close (sitdev, -SIT9531X_REG_OUTSYS_DEBUG , -SIT9531X_DEBUG_LOCK_VAL ); -if (lock_rc) -dev_warn (sitdev->dev, -"output debug block left unlocked: %d\n" , - lock_rc); + 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; }
@@ -610,6 +633,159 @@ static int sit9531x_prg_retry(struct sit9531x_dev *sitdev)return sit9531x_prg_commit (sitdev); } +/* +* Set one Hi-Z pair to @mask/@state from @cur_mask/@cur_state, writing only the +* bits that differ. STATE goes first while the override stays on and last when +* it goes off, so the pad holds no other value for one I2C transfer. +*/ +static int sit9531x_hiz_pair_put (struct sit9531x_dev *sitdev, +const struct sit9531x_hiz_pair *p,bool mask, +bool state,bool cur_mask,bool cur_state) +{ +int rc =0 ; + +if (mask && state != cur_state) + rc =sit9531x_hiz_set_bit (sitdev, p->state, p->bit, state); +if (!rc && mask != cur_mask) + rc =sit9531x_hiz_set_bit (sitdev, p->mask, p->bit, mask); +if (!rc && !mask && state != cur_state) + rc =sit9531x_hiz_set_bit (sitdev, p->state, p->bit, state); + +return rc; +} + +/* +* Mute every Hi-Z pair of a slot, or unmute it: put back on each pair the +* MASK and STATE bits in @out->hiz_mask and @out->hiz_state. 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_output_hiz_write (struct sit9531x_dev *sitdev,u8 slot, +bool mute,const struct sit9531x_out *out) +{ +u8 mask[SIT9531X_HIZ_PAIRS ], state[SIT9531X_HIZ_PAIRS ]; +struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS ]; +int i, rc, undo_rc; + +sit9531x_output_get_hiz_regs (slot, p); + +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; + } + +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { +bool cur_mask = mask[i] &BIT (p[i].bit); +bool cur_state = state[i] &BIT (p[i].bit); + +/* A mute writes both bits, whatever they hold */ +if (mute) + rc =sit9531x_hiz_pair_put (sitdev, &p[i], true, false, + false, true); +else + rc =sit9531x_hiz_pair_put (sitdev, &p[i], + out->hiz_mask &BIT (i), + out->hiz_state &BIT (i), + cur_mask, cur_state); +if (rc) +break ; + } +if (!rc) +return 0 ; + +/* Put back what the pairs held, both bits of each */ +for (; i >=0 ; i--) { +bool old_mask = mask[i] &BIT (p[i].bit); +bool old_state = state[i] &BIT (p[i].bit); + + undo_rc =sit9531x_hiz_pair_put (sitdev, &p[i], old_mask, + old_state, !old_mask, + !old_state); +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; + + rc =sit9531x_output_hiz_write (sitdev, slot, true, &sitdev->out[index]); +sit9531x_outsys_debug_close (sitdev); + +/* 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]); +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; +} +/* * Procedure: * 1. Force PLL into holdover (PLL page reg 0x6F bit 4)
@@ -2220,9 +2396,10 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)static int sit9531x_out_state_fetch (struct sit9531x_dev *sitdev,u8 index) {struct sit9531x_out *out = &sitdev->out[index]; +struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS ];u8 map_lo, map_hi, slot, bit, claimed;bool muted, part; -int pll_idx; +int pll_idx, i;u16 mask;int rc;
@@ -2232,11 +2409,37 @@ static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index)if (rc)return rc; + out->hiz_mask =0 ; + out->hiz_state =0 ; rc =sit9531x_output_forced_hiz (sitdev, index, &muted, &part);if (rc)return rc; - sitdev->out[index].part_muted = part; +/* +* Record what an unmute puts back on each Hi-Z pair: the MASK and STATE +* bits found here. A pair forced to Hi-Z stays forced on a driven +* output and is released on a muted one, so that the unmute drives it. +* The pad forced on a part-muted output is then the configuration's. +*/ +sit9531x_output_get_hiz_regs (slot, p); +for (i =0 ; i <SIT9531X_HIZ_PAIRS ; i++) { +u8 mask_val, state_val; + + rc =sit9531x_read_u8 (sitdev, p[i].mask, &mask_val); +if (!rc) + rc =sit9531x_read_u8 (sitdev, p[i].state, &state_val); +if (rc) +return rc; +if (state_val &BIT (p[i].bit)) + out->hiz_state |=BIT (i); +else if (muted) +continue ; +if (mask_val &BIT (p[i].bit)) + out->hiz_mask |=BIT (i); + } + + sitdev->out[index].part_muted = false; + sitdev->out[index].state_stale = false;/* * Each PLL page holds a 12-bit output-enable mask: OUT_MAP_LO bits 0-7
@@ -2687,6 +2890,8 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)sit9531x_prg_retry (sitdev);if (bank && !sitdev->bank_pending)dev_info (sitdev->dev,"output divider bank updated\n" ); + }else if (sitdev->outsys_key_pending) { +sit9531x_outsys_debug_close (sitdev); }sit9531x_input_off_retry (sitdev);
@@ -3043,6 +3248,8 @@ static void sit9531x_dev_stop(struct sit9531x_dev *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); }
@@ -3120,7 +3327,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, pin->ops, pin);dpll_pin_put (dpll_pin, &pin->tracker);
@@ -3156,20 +3363,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)
@@ -3771,17 +3991,26 @@ static int sit9531x_resume(struct device *dev)sit9531x_ref_pll_mask_rebuild (sitdev);for (i =0 ; i < sitdev->info->num_outputs; i++) {struct sit9531x_out *out = &sitdev->out[i]; +u8 hiz_mask = out->hiz_mask, hiz_state = out->hiz_state; +bool enabled = out->enabled;bool routed = out->routed;u8 pll_idx = out->pll_idx; rc =sit9531x_out_state_fetch (sitdev, i); -if (rc) +/* A muted output keeps the Hi-Z record taken before the mute */ +if (rc || (!enabled && !out->enabled)) { + out->hiz_mask = hiz_mask; + out->hiz_state = hiz_state; + } +if (rc) {dev_warn (sitdev->dev,"out%u: state not read on resume: %d\n" , i, rc); + out->state_stale = true; + }if (out->routed != routed || out->pll_idx != pll_idx)dev_warn (sitdev->dev, -"out%u: routing changed over suspend\n" , +"out%u: routing changed over suspend; its pin stays on the DPLL it was registered on\n" , i); }mutex_unlock (&sitdev->multiop_lock);
drivers/dpll/sit9531x/core.h +23 -2
@@ -113,8 +113,18 @@ 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 -* @part_muted: single-ended with one pad forced and the other not; reported -* as driven +* @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, where +* @hiz_mask and @hiz_state do not keep the forced pad forced; reported as +* driven. The driver's mute forces both pads. +* @hiz_mask: bit per Hi-Z pair, the MASK bit an unmute writes back; read at +* probe and on resume, unless the output is muted both before and after +* the resume. On an output muted at that read, a pair forced to Hi-Z is +* taken as the mute, also one an earlier binding set, and its bit is +* cleared, so that an unmute drives the pair +* @hiz_state: bit per Hi-Z pair, the STATE bit an unmute writes back * @routed: mapped to @pll_idx by the loaded configuration; an output * unrouted at probe has no pin * @pll_idx: PLL driving this output (0-3)
@@ -123,7 +133,11 @@ struct sit9531x_out {u64 freq;bool enabled;bool cmos; +bool state_stale; +bool ntf_pending;bool part_muted; +u8 hiz_mask; +u8 hiz_state;bool routed;u8 pll_idx; };
@@ -247,6 +261,7 @@ struct sit9531x_chan {* band; written under @multiop_lock * @loops_open: output loops not yet re-locked * @bank_pending: output divider bank update still to be issued +* @outsys_key_pending: output-system debug key not closed */ struct sit9531x_dev {struct device *dev;
@@ -280,6 +295,7 @@ struct sit9531x_dev {bool loops_open;bool bank_pending; +bool outsys_key_pending; }; int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
@@ -307,6 +323,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 +145 -8
190 lines not on this page · raw message
Signature · 1 line
2.39.2 (Apple Git-143)
PATCH v17 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, +/-1 ms at 1 ps granularity, bounds a request, not the delay the registers hold. An advance is held as the complementary positive 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 and 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 the PLL's outputs. A rate change encodes the delay again for the new period, in the divider's programming window.
The poll and removal apply a delay waiting for its re-time or update and finish a flush left partly done. A waiting delay, or Fref * DIVN outside the PLL's VCO band, has no value and the core leaves the attribute out; a delay whose flush is pending is reported.
--- drivers/dpll/sit9531x/core.c | 862 ++++++++++++++++++++++++++++++++--- drivers/dpll/sit9531x/core.h | 35 ++ drivers/dpll/sit9531x/dpll.c | 130 +++++- drivers/dpll/sit9531x/prop.c | 16 + drivers/dpll/sit9531x/regs.h | 29 ++ 5 files changed, 1009 insertions(+), 63 deletions(-)
drivers/dpll/sit9531x/core.c +800 -62
@@ -246,6 +246,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,
@@ -1683,6 +1700,72 @@ 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; +/* Re-arm after the select is back; the trigger may stay set */ +if (rc) { + sitdev->flush_arm_pending |= plls; + sitdev->flush_armed &= ~plls; + sitdev->flush_armed |= armed & plls; +return rc; + } + } + +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
@@ -1691,24 +1774,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); }
@@ -1721,18 +1816,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
@@ -1740,21 +1836,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
@@ -1763,47 +1857,26 @@ 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 );if (rc) - goto restore; + goto undo;/* * Clear the trigger with the register trigger still selected, as -* Dely_program_output.py does; the select goes back after it. +* Dely_program_output.py does; the select goes back in the undo. */ rc =sit9531x_write_close (sitdev,SIT9531X_REG_GPIO_FUNC_CTRL1 , ctrl); - -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; }
@@ -1877,7 +1950,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];
@@ -1904,6 +1977,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),
@@ -1962,12 +2036,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 ]; +bool divo_back = false, divo_in, back, landed, encoded = false; +bool retime = false, bytes_in = false, bytes_back = false; +struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; +struct sit9531x_out *out = &sitdev->out[out_idx]; +u64 fvco, divo, coarse, old_divo =0 ; +s32 phase_adj =0 , held =0 ; +bool beyond;int rc, ret; -bool back; +u8 fine;lockdep_assert_held (&sitdev->multiop_lock);
@@ -1976,28 +2399,120 @@ int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,if (rc)return rc; +/* The rate resolved, so a record of no delay value is out of date */ +if ((out->phase_stale || out->phase_none) && !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; + out->phase_none = false; + } + +/* +* The reset delay counts VCO cycles: encode the pending delay, or +* out->phase_adj in its form nearer to zero (an advance for a delay +* above half the old period), again for the new period. Write it in the +* divider's programming window; a second flush restarts the 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 ; }
@@ -2041,6 +2556,137 @@ int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,return 0 ; } +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; +u64 fvco, divo, coarse, old_coarse; +bool bytes_back, bytes_in, same; +u8 pll_idx, fine, old_fine; +struct sit9531x_chan *chan; +struct sit9531x_out *out; +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; + +/* 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 delay is unchanged; a rewrite +* restarts the divider phase of every output on the PLL. Every coarse +* value up to the settling cycles decodes as no delay. +*/ +sit9531x_output_phase_bytes_decode (old_bytes, &old_coarse, &old_fine); + same = old_coarse == coarse && old_fine == fine && !out->phase_stale; +if (same && !chan->flush_pending) { + rc =0 ; + goto cache; + } + +if (!same) { +/* +* Order of Dely_program_output.py: the bytes on page 3 or 4 +* under the Page 3 debug key, the small-change update on page 3 +* for either page, then the flush with no wait. 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, and a +* bank update after it changes the dividers again. +*/ +if (sitdev->bank_pending || sitdev->loops_open) { + rc =sit9531x_prg_retry (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->phase_none = 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 ; +} +/* The latches INTRB reports, each with its sticky bits */ static const struct { unsigned int reg;
@@ -2597,6 +3243,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);
@@ -2605,6 +3254,24 @@ 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); + sitdev->out[i].phase_none = rc == -ENODATA ; +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);
@@ -2743,6 +3410,25 @@ static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx) 'A' + pll_idx); } +/* +* Apply a delay that waits for its re-time after a rate change or for its +* small-change update. 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]; + +if (!out->retime_pending) +return ; + +if (!sit9531x_output_phase_adjust_set (sitdev, out_idx, out->retime_ps)) +dev_info (sitdev->dev,"out%u: pending delay applied\n" , + out_idx); +/* The delay getter reports a value again */ +if (!out->retime_pending) + out->ntf_pending = true; +} +/* * Write back the priority table after a failed write. Caller must hold * sitdev->multiop_lock.
@@ -2874,6 +3560,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.
@@ -2893,12 +3591,21 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *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);sit9531x_debug_back_retry (sitdev, i); +/* +* A flush pulse sent into open loops may be lost when they +* re-lock; a bank update after it changes the dividers again. +*/ +if (!sitdev->loops_open && !sitdev->bank_pending) +sit9531x_flush_retry (sitdev, i); rc =sit9531x_chan_state_fetch (sitdev, i);if (rc) { sitdev->chan[i].stale = true;
@@ -3239,6 +3946,10 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev) 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->bank_pending || sitdev->loops_open) {sit9531x_prg_retry (sitdev);
@@ -3248,8 +3959,35 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev)if (sitdev->loops_open)dev_warn (sitdev->dev,"output loops left unlocked at removal\n" ); - }else if (sitdev->outsys_key_pending) { + } +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: pending delay not applied at removal\n" , + i); + } +/* Last: a re-time opens the debug key again */ +if (sitdev->outsys_key_pending)sit9531x_outsys_debug_close (sitdev); +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +if (!sitdev->loops_open && !sitdev->bank_pending) +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 +35 -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/* * Output rates of the datasheet, Table 6: continuous up to 800 MHz, above it * 61.44 MHz times 15, 20, 24, 30, 32, 40 or 48.
@@ -128,6 +130,17 @@ struct sit9531x_ref {* @routed: mapped to @pll_idx by the loaded configuration; an output * unrouted at probe has no pin * @pll_idx: PLL driving this output (0-3) +* @phase_stale: programmed delay may differ from @phase_adj +* @phase_none: the last delay read found no valid Fvco on the PLL, so the +* output has no delay value and the getter leaves the attribute out; a +* delay or rate request that finds an Fvco clears it +* @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: delay not yet applied, after a rate change or with its +* small-change update still to be issued; the poll applies @retime_ps +* @retime_ps: delay to apply while @retime_pending */ struct sit9531x_out {u64 freq;
@@ -140,6 +153,12 @@ struct sit9531x_out {u8 hiz_state;bool routed;u8 pll_idx; +s64 phase_adj; +bool phase_armed; +bool phase_stale; +bool phase_none; +bool retime_pending; +s32 retime_ps; };/*
@@ -181,6 +200,8 @@ struct sit9531x_out {* @stall_shift: doublings of the stall count, one per re-select it arms, up * to SIT9531X_RESELECT_STALL_SHIFT_MAX; cleared when a poll sees the PLL * track, when @live_top changes, at probe and on resume +* @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
@@ -219,6 +240,7 @@ struct sit9531x_chan {bool tracked;u16 stall_polls;u8 stall_shift; +bool flush_pending;bool table_pending;u8 table_back[SIT9531X_PRIO_MAX_SLOTS ];bool key_pending;
@@ -262,6 +284,10 @@ struct sit9531x_chan {* @loops_open: output loops not yet re-locked * @bank_pending: output divider bank update still to be issued * @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;
@@ -296,6 +322,10 @@ struct sit9531x_dev {bool loops_open;bool bank_pending;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,
@@ -333,6 +363,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 +129 -1
169 lines not on this page · raw message
drivers/dpll/sit9531x/prop.c +16 -0
@@ -188,6 +188,22 @@ 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 delay grid is whole VCO cycles of the output's PLL plus +* 30 ps steps, so it depends on the PLL; a request in 1 ps +* units is programmed as the nearest grid point within the +* range, which is reported. +*/ + props->dpll_props.phase_gran =1 ; }sit9531x_prop_pin_package_label_set (sitdev, props, dir, index);
drivers/dpll/sit9531x/regs.h +29 -0
@@ -151,6 +151,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)
PATCH v17 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 the core builds a pin message, including the poll's change notifications, not on every tick: 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.
Only the input the part feeds the PLL has an offset. Any other pin, a PLL without a reference, a PLL that drives no enabled output or whose Fref * DIVN is outside its VCO band returns -ENODATA and the core leaves the attribute out. The XO pin has none: it is the frequency base of every PLL.
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 | 353 +++++++++++++++++++++++++++++------ drivers/dpll/sit9531x/core.h | 12 ++ drivers/dpll/sit9531x/dpll.c | 110 +++++++++++ drivers/dpll/sit9531x/regs.h | 19 ++ 4 files changed, 436 insertions(+), 58 deletions(-)
drivers/dpll/sit9531x/core.c +295 -58
@@ -263,6 +263,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,
@@ -860,12 +882,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 ,
@@ -2734,6 +2760,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) {
@@ -2877,13 +3073,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;
@@ -3448,14 +3652,22 @@ static void sit9531x_table_back_retry(struct sit9531x_dev *sitdev, u8 pll_idx) 'A' + pll_idx); } -/* Lock the PLL debug key again. Caller must hold sitdev->multiop_lock. */ +/* +* Restore the debug taps and lock the PLL debug key again. Caller must hold +* sitdev->multiop_lock. +*/ static void sit9531x_debug_back_retry (struct sit9531x_dev *sitdev,u8 pll_idx) {struct sit9531x_chan *chan = &sitdev->chan[pll_idx]; -if (!chan->key_pending) +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 );
@@ -3859,55 +4071,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) { - 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_debug_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.
@@ -3929,11 +4116,6 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev) !sitdev->chan[i].table_pending)dev_warn (sitdev->dev,"PLL%c left in forced holdover\n" ,'A' + i); -sit9531x_debug_back_retry (sitdev, i); -if (sitdev->chan[i].key_pending) -dev_warn (sitdev->dev, -"PLL%c left with its debug window open\n" , -'A' + i); }/* After the table write-back: the tables give the receiver claims */
@@ -3990,6 +4172,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) { + 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 +12 -0
@@ -206,6 +206,9 @@ struct sit9531x_out {* stays in forced holdover * @table_back: table reported and to be rewritten while @table_pending * @key_pending: debug key of the PLL page not locked again +* @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 * @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
@@ -244,6 +247,9 @@ struct sit9531x_chan {bool table_pending;u8 table_back[SIT9531X_PRIO_MAX_SLOTS ];bool key_pending; +bool tap_pending; +u8 tap_write_code; +u8 tap_read_code;u8 prio_srcs[SIT9531X_PRIO_MAX_SLOTS ];u8 prio_last[SIT9531X_PRIO_NUM_SRC ];u16 prio_mask;
@@ -368,6 +374,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
@@ -222,6 +222,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)
PATCH v17 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 on every DPLL, whose state says whether that PLL drives the line, and an input pin on each destination, with no signal while undriven. Both are INT_OSCILLATOR, the uAPI type for a clock made inside the device other than an NCO.
Taking the line writes the reference sequence's source pattern 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 getters answer from the owner read back from the four EXT pages. A page left with part of the pattern refuses a connect on another PLL until its source pin is disconnected.
Resume reads the line owner and output delays again, notifies pins whose mute, delay or source changed, drops a pending write to registers a reloaded configuration sets, and keeps the undo of a state the driver set and a pending delay still in its registers.
--- drivers/dpll/sit9531x/core.c | 817 ++++++++++++++++++++++++++++++++++- drivers/dpll/sit9531x/core.h | 39 ++ drivers/dpll/sit9531x/dpll.c | 451 +++++++++++++++++-- drivers/dpll/sit9531x/regs.h | 8 + 4 files changed, 1278 insertions(+), 37 deletions(-)
drivers/dpll/sit9531x/core.c +806 -11
@@ -932,6 +932,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;
@@ -1200,6 +1202,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,bool reselect) {
@@ -1216,6 +1230,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));
@@ -2760,6 +2779,596 @@ 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 pll) +{ +int rc; + + rc =sit9531x_write_close (sitdev, +SIT9531X_REG (SIT9531X_PLL_EXT_PAGE (pll), +SIT9531X_PLL_REG_DEBUG ), +SIT9531X_PLL_DEBUG_LOCK ); +if (rc) + sitdev->intsync_key_pending |=BIT (pll); +else + sitdev->intsync_key_pending &= ~BIT (pll); + +return rc; +} + +/* +* The bytes Intsync_enable_disable.py writes, each register whole, to the EXT +* page of the PLL that drives the line: en_val to drive it, dis_val to stop. +*/ +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, pll); +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, pll); +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, src_pll_idx); +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, src_pll_idx); + +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) { +int ret =0 ; + +/* +* The write may have reached the register, where the next +* page-0 small update would apply it; put back the value read. +*/ +if (restore) + ret =sit9531x_write_close (sitdev, +SIT9531X_REG_INTSYNC_GLOBAL , + val); +if (ret) +dev_warn (sitdev->dev, +"PLL%c: INTSYNC enable register not written back: %d\n" , +'A' + src_pll_idx, ret); +return rc; + } +/* 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, src_pll_idx); +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
@@ -3235,6 +3844,7 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx) chan->ho_valid = !!(pll_status_1 &SIT9531X_PLL_STATUS_1_HO_VALID ); chan->stale = false; + chan->intsync_dropped = false;return 0 ; }
@@ -3446,6 +4056,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;
@@ -3803,6 +4422,9 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev) }else if (sitdev->outsys_key_pending) {sit9531x_outsys_debug_close (sitdev); } +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) +if (sitdev->intsync_key_pending &BIT (i)) +sit9531x_intsync_debug_lock (sitdev, i);sit9531x_phase_flush_undo_retry (sitdev);for (i =0 ; i < sitdev->info->num_outputs; i++)sit9531x_retime_retry (sitdev, i);
@@ -3840,7 +4462,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 latched; +bool src_moved, latched;bool answered;int rc;
@@ -3850,16 +4472,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, &latched);mutex_unlock (&sitdev->multiop_lock);
@@ -4152,6 +4774,12 @@ static void sit9531x_dev_pending_retry(struct sit9531x_dev *sitdev)/* Last: a re-time opens the debug key again */ if (sitdev->outsys_key_pending)sit9531x_outsys_debug_close (sitdev); +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) +if ((sitdev->intsync_key_pending &BIT (i)) && +sit9531x_intsync_debug_lock (sitdev, i)) +dev_warn (sitdev->dev, +"PLL%c: EXT page debug key left open at removal\n" , +'A' + i);for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) {if (!sitdev->loops_open && !sitdev->bank_pending)sit9531x_flush_retry (sitdev, i);
@@ -4352,13 +4980,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;
@@ -4824,6 +5452,8 @@ static int sit9531x_dev_probe(struct sit9531x_dev *sitdev)if (rc)return rc; + sitdev->intsync_src =-1 ; + rc =devm_mutex_init (sitdev->dev, &sitdev->multiop_lock);if (rc) return dev_err_probe(sitdev->dev, rc,
@@ -4891,6 +5521,41 @@ static const struct of_device_id sit9531x_of_match[] = { };MODULE_DEVICE_TABLE (of, sit9531x_of_match); +/* +* Compare the delay bytes of an output with its pending re-time, decoded as the +* delay setter does: 1 if they hold the request, 0 if not or if the request has +* no encoding for the divider, <0 if a read failed. Caller must hold +* sitdev->multiop_lock. +*/ +static int sit9531x_retime_kept (struct sit9531x_dev *sitdev,u8 out_idx) +{ +struct sit9531x_out *out = &sitdev->out[out_idx]; +u8 bytes[SIT9531X_OUT_PRG_BYTES ], fine, old_fine; +u64 fvco, divo, coarse, old_coarse; +s32 phase_adj; +int rc; + +if (!out->routed) +return 0 ; + + rc =sit9531x_get_fvco (sitdev, out->pll_idx, &fvco); +if (!rc) + rc =sit9531x_output_divo_read (sitdev, out_idx, &divo); +if (rc) +return rc == -ENODATA ?0 : rc; + +if (sit9531x_output_phase_encode (fvco, divo, out->retime_ps, &coarse, + &fine, &phase_adj)) +return 0 ; + + rc =sit9531x_output_phase_bytes_read (sitdev, out_idx, bytes); +if (rc) +return rc; +sit9531x_output_phase_bytes_decode (bytes, &old_coarse, &old_fine); + +return old_coarse == coarse && old_fine == fine; +} +/* * Stop the poll and the IRQ across suspend so no paged I2C sequence reaches a * suspended adapter; the poll worker is not freezable.
@@ -4908,9 +5573,12 @@ static int sit9531x_suspend(struct device *dev)static int sit9531x_resume (struct device *dev) { +u16 outs_was =0 , outs_now =0 , outs_unread =0 , outs_moved =0 ;struct sit9531x_dev *sitdev =dev_get_drvdata (dev);struct sit9531x_dpll *sitdpll; -u8 modes_moved =0 ; +u8 modes_moved =0 , kept =0 ; +bool src_moved; +s8 owner;int rc;u8 i;
@@ -4924,6 +5592,81 @@ static int sit9531x_resume(struct device *dev)mutex_lock (&sitdev->multiop_lock);/* One re-select for a source lost and restored between samples */ sit9531x_reselect_arm (sitdev); +/* +* Drop and report the pending writes to registers a reloaded profile +* sets. Keep a delay re-time whose bytes still hold the request, and +* the undo of a state the driver set: loops or a debug key left open, +* debug taps left selected, a table write-back under forced holdover. +*/ +for (i =0 ; i <SIT9531X_NUM_PLLS ; i++) { +struct sit9531x_chan *chan = &sitdev->chan[i]; +bool retime = false, flush, arm; +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 ; +if (sit9531x_retime_kept (sitdev, j)) { + kept |=BIT (i); +continue ; + } + sitdev->out[j].retime_pending = false; + retime = true; + } +/* +* A re-time left pending ends in a flush, which first restores +* the trigger select and the flush enable: keep them pending. +*/ + flush = !(kept &BIT (i)) && chan->flush_pending; + arm = !(kept &BIT (i)) && (sitdev->flush_arm_pending &BIT (i)); +if (!retime && !flush && !arm) +continue ; +dev_warn (sitdev->dev, +"PLL%c: pending before suspend, dropped:%s%s%s\n" , +'A' + i, retime ?" output delay" :"" , + flush ?" output realignment" :"" , + arm ?" on-demand flush enable" :"" ); +if (kept &BIT (i)) +continue ; + chan->flush_pending = false; + sitdev->flush_arm_pending &= ~BIT (i); + } +if (sitdev->flush_ctrl_pending && !kept) { +dev_warn (sitdev->dev, +"flush trigger source select pending before suspend, dropped\n" ); + sitdev->flush_ctrl_pending = false; + } +if (sitdev->bank_pending) { +dev_warn (sitdev->dev, +"output divider bank update pending before suspend, dropped\n" ); + sitdev->bank_pending = false; + } +for (i =0 ; i < sitdev->info->num_inputs; i++) { +if (!sitdev->ref[i].off_pending) +continue ; +dev_warn (sitdev->dev, +"input %u: receiver gate-off pending before suspend, dropped\n" , + i); + sitdev->ref[i].off_pending = false; + } + owner =sit9531x_intsync_owner (sitdev);/* Read again the configuration probe read */ for (i =0 ; i < sitdev->info->num_inputs /2 ; i++) {
@@ -4967,13 +5710,17 @@ static int sit9531x_resume(struct device *dev)for (i =0 ; i < sitdev->info->num_outputs; i++) {struct sit9531x_out *out = &sitdev->out[i];u8 hiz_mask = out->hiz_mask, hiz_state = out->hiz_state; -bool enabled = out->enabled;bool routed = out->routed;u8 pll_idx = out->pll_idx; +if (out->enabled) + outs_was |=BIT (i); +/* The mute state of a request left unconfirmed is unknown */ +if (out->state_stale) + outs_unread |=BIT (i); rc =sit9531x_out_state_fetch (sitdev, i);/* A muted output keeps the Hi-Z record taken before the mute */ -if (rc || (!enabled && !out->enabled)) { +if (rc || (!(outs_was &BIT (i)) && !out->enabled)) { out->hiz_mask = hiz_mask; out->hiz_state = hiz_state; }
@@ -4982,14 +5729,62 @@ static int sit9531x_resume(struct device *dev)"out%u: state not read on resume: %d\n" , i, rc); out->state_stale = true; + outs_unread |=BIT (i); } -if (out->routed != routed || out->pll_idx != pll_idx) +if (out->routed != routed || out->pll_idx != pll_idx) {dev_warn (sitdev->dev,"out%u: routing changed over suspend; its pin stays on the DPLL it was registered on\n" , i); + outs_moved |=BIT (i); + } +if (out->enabled) + outs_now |=BIT (i); } +for (i =0 ; i < sitdev->info->num_outputs; i++) { +struct sit9531x_out *out = &sitdev->out[i]; +bool beyond, none; +s64 phase_ps; + +/* Bytes of a pending re-time are not a delay the part runs */ +if (out->retime_pending) +continue ; + + rc =sit9531x_output_phase_read (sitdev, i, &phase_ps, + &beyond); +/* Unrouted or with no valid Fvco, no delay, as at probe */ + none = rc == -ENODATA ; +if (none) { + phase_ps =0 ; + beyond = false; + rc =0 ; + } +if (rc) { +dev_warn (sitdev->dev, +"out%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 || + out->phase_none != none) + outs_moved |=BIT (i); + out->phase_none = none; + 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);mutex_unlock (&sitdev->multiop_lock); +sit9531x_drive_pins_ntf (sitdev, + (outs_was ^ outs_now) | outs_unread | + outs_moved, src_moved);/* The poll notifies a device whose mode changed */ list_for_each_entry (sitdpll, &sitdev->dplls, list)if (modes_moved &BIT (sitdpll->id))
drivers/dpll/sit9531x/core.h +39 -0
@@ -168,6 +168,8 @@ struct sit9531x_out {* @locked: PLL is active and its outer loop reports lock * @stale: last state read failed; the fields hold an earlier sample, or * part of a new one, 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
@@ -228,6 +230,7 @@ struct sit9531x_chan {bool active;bool locked;bool stale; +bool intsync_dropped;u8 mode;u8 routed_ref;bool inner_lol;
@@ -284,12 +287,22 @@ struct sit9531x_chan {* @clock_id_node: entry in the list of the clock ids of the bound parts * @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. A +* readback keeps it over a scan that finds the whole pattern enabled on the +* same PLL, as the page reads the same whether the pattern was latched or not +* @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 * @loops_open: output loops not yet re-locked * @bank_pending: output divider bank update still to be issued * @outsys_key_pending: output-system debug key not closed +* @intsync_key_pending: bit per PLL whose EXT page debug key is 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
@@ -325,9 +338,17 @@ struct sit9531x_dev {struct gpio_desc *reset_gpio;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 bank_pending;bool outsys_key_pending; +u8 intsync_key_pending;bool flush_ctrl_pending;u8 flush_ctrl;u8 flush_arm_pending;
@@ -374,6 +395,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 +425 -26
513 lines not on this page · raw message
drivers/dpll/sit9531x/regs.h +8 -0
@@ -23,6 +23,7 @@#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)
@@ -46,6 +47,10 @@#define SIT9531X_REG_HO_FREEZE_STATUS SIT9531X_REG(0x00, 0x0A)#define SIT9531X_REG_HO_FREEZE_NOTIF SIT9531X_REG(0x00, 0x0B) +/* INTSYNC (inter-PLL synchronization) global enable */ +#define SIT9531X_REG_INTSYNC_GLOBAL SIT9531X_REG(0x00, 0x40) +#define SIT9531X_INTSYNC_EN_BIT 6 +/* * Priority table: six registers per PLL from 0x16 + 6 * PLL, holding slots * 0-10 and the active-reference nibble; slot 2n in [7:4], 2n+1 in [3:0].
@@ -247,6 +252,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)