| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/23 20:44 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch adds a new device driver for the SiTime SiT95316 and SiT95317 I2C-controlled DPLL clock generator chips (drivers/dpll/sit9531x/). This hardware requires physical discrete ASICs communicating over I2C with specific clock inputs, which are not emulated in standard QEMU or GCE virtualized fuzzing environments. As such, the driver cannot successfully probe or execute in standard syzkaller environments, making the modified code structurally unreachable.",
"WorthFuzzing": false
} |
| 1/1 | 2026/09/23 20:44 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 780781b91d8cfecf2ab75310256bf8247b8ed953\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Sep 23 20:44:14 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml b/Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml\nnew file mode 100644\nindex 0000000000000..6f4c60ba1cb92\n--- /dev/null\n+++ b/Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml\n@@ -0,0 +1,183 @@\n+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)\n+%YAML 1.2\n+---\n+$id: http://devicetree.org/schemas/dpll/sitime,sit95316.yaml#\n+$schema: http://devicetree.org/meta-schemas/core.yaml#\n+\n+title: SiTime SiT95316/SiT95317 DPLL Clock Generator\n+\n+maintainers:\n+ - Ali Rouhi \u003carouhi@sitime.com\u003e\n+\n+description: |\n+ SiTime SiT95316 and SiT95317 are I2C-controlled programmable clock\n+ generators with integrated DPLL for synchronization applications. Both\n+ variants contain four PLLs with automatic/manual reference selection,\n+ DCO frequency adjustment, and phase offset measurement via an on-chip\n+ TDC (Time-to-Digital Converter).\n+\n+ Both parts have 4 differential input pairs whose lanes can also be\n+ driven independently as single-ended references, so 8 inputs are\n+ individually selectable. SiT95317 drives 8 outputs, SiT95316\n+ drives 12.\n+\n+properties:\n+ compatible:\n+ enum:\n+ - sitime,sit95316\n+ - sitime,sit95317\n+\n+ reg:\n+ maxItems: 1\n+\n+ clocks:\n+ maxItems: 1\n+\n+ clock-names:\n+ items:\n+ - const: xtal\n+\n+ clock-frequency:\n+ description:\n+ XO rate in Hz feeding XIN/XO_CLK. Alternative to the \"clocks\"\n+ phandle for platforms where the firmware does not expose the\n+ oscillator through the clock framework.\n+\n+ reset-gpios:\n+ maxItems: 1\n+ description:\n+ GPIO connected to the chip's active-low reset pin (RESETB).\n+\n+ interrupts:\n+ maxItems: 1\n+ description:\n+ Interrupt from the chip's active-low INTRB output. Asserted when\n+ the device detects a status change such as lock acquisition or loss.\n+\n+ dpll-types:\n+ maxItems: 4\n+\n+ sitime,pll-fvco:\n+ $ref: /schemas/types.yaml#/definitions/uint64-array\n+ minItems: 4\n+ maxItems: 4\n+ description:\n+ Per-PLL VCO frequency in Hz for PLLA, PLLB, PLLC, PLLD. The\n+ values exceed 32 bits, which requires an explicit uint64-array\n+ type; the dtschema meta-schema does not permit a type $ref on a\n+ \"-hz\" unit-suffix property (only opp-hz is defined as 64-bit),\n+ hence no unit suffix. Override where the standard\n+ Fvco = Fref * DIVN derivation does not match the running VCO --\n+ for example a PLL operating in INTSYNC mode. A value of 0 keeps\n+ the register-derived computation for that PLL.\n+\n+ sitime,output-pll-map:\n+ $ref: /schemas/types.yaml#/definitions/uint32-array\n+ minItems: 8\n+ maxItems: 12\n+ items:\n+ enum: [0, 1, 2, 3, 255]\n+ description:\n+ Source PLL index (0=PLLA .. 3=PLLD) for each output 0..11. The\n+ value 255 (0xff) marks an output as unmapped and prevents the\n+ driver from registering it as a DPLL pin. Override for\n+ configurations where the chip's per-PLL OUTPUT_ENABLE bitmaps do\n+ not unambiguously describe output-to-PLL routing.\n+\n+required:\n+ - compatible\n+ - reg\n+\n+oneOf:\n+ - required:\n+ - clocks\n+ - clock-names\n+ - required:\n+ - clock-frequency\n+\n+allOf:\n+ - $ref: /schemas/dpll/dpll-device.yaml#\n+ # SiT95317 exposes 8 outputs, SiT95316 exposes 12. Bound the\n+ # output-pll-map length to the variant so a SiT95317 node cannot\n+ # describe more outputs than the part has.\n+ - if:\n+ properties:\n+ compatible:\n+ contains:\n+ const: sitime,sit95317\n+ then:\n+ properties:\n+ sitime,output-pll-map:\n+ maxItems: 8\n+ # SiT95316 has 12 outputs. When the map is supplied it must describe\n+ # all of them, otherwise the trailing outputs are left ambiguous.\n+ - if:\n+ properties:\n+ compatible:\n+ contains:\n+ const: sitime,sit95316\n+ then:\n+ properties:\n+ sitime,output-pll-map:\n+ minItems: 12\n+\n+unevaluatedProperties: false\n+\n+examples:\n+ - |\n+ #include \u003cdt-bindings/gpio/gpio.h\u003e\n+ #include \u003cdt-bindings/interrupt-controller/irq.h\u003e\n+\n+ i2c {\n+ #address-cells = \u003c1\u003e;\n+ #size-cells = \u003c0\u003e;\n+\n+ dpll@68 {\n+ compatible = \"sitime,sit95316\";\n+ reg = \u003c0x68\u003e;\n+ clocks = \u003c\u0026xo2\u003e;\n+ clock-names = \"xtal\";\n+ reset-gpios = \u003c\u0026gpio 78 GPIO_ACTIVE_LOW\u003e;\n+ interrupts = \u003c12 IRQ_TYPE_LEVEL_LOW\u003e;\n+ dpll-types = \"eec\", \"eec\", \"eec\", \"eec\";\n+ sitime,pll-fvco = /bits/ 64 \u003c0 6875000000 0 0\u003e;\n+ sitime,output-pll-map = \u003c0 0 0 0 0 0 0 0 0 0 0 0\u003e;\n+\n+ input-pins {\n+ #address-cells = \u003c1\u003e;\n+ #size-cells = \u003c0\u003e;\n+\n+ pin@0 {\n+ reg = \u003c0\u003e;\n+ label = \"clkin0\";\n+ connection-type = \"ext\";\n+ supported-frequencies-hz = /bits/ 64 \u003c10000000\u003e;\n+ };\n+\n+ pin@1 {\n+ reg = \u003c1\u003e;\n+ label = \"clkin1\";\n+ connection-type = \"synce\";\n+ supported-frequencies-hz = /bits/ 64 \u003c156250000\u003e;\n+ };\n+ };\n+\n+ output-pins {\n+ #address-cells = \u003c1\u003e;\n+ #size-cells = \u003c0\u003e;\n+\n+ pin@0 {\n+ reg = \u003c0\u003e;\n+ label = \"clkout0\";\n+ supported-frequencies-hz = /bits/ 64 \u003c156250000\u003e;\n+ };\n+\n+ pin@1 {\n+ reg = \u003c1\u003e;\n+ label = \"clkout1\";\n+ supported-frequencies-hz = /bits/ 64 \u003c25000000\u003e;\n+ };\n+ };\n+ };\n+ };\n+...\ndiff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml\nindex ba20029693734..65da27d6e84d8 100644\n--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml\n+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml\n@@ -1563,6 +1563,8 @@ patternProperties:\n description: SiRF Technology, Inc.\n \"^sis,.*\":\n description: Silicon Integrated Systems Corp.\n+ \"^sitime,.*\":\n+ description: SiTime Corporation\n \"^sitronix,.*\":\n description: Sitronix Technology Corporation\n \"^skov,.*\":\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex cae5962045dd6..b500dbb67c4e9 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -25151,6 +25151,13 @@ S:\tMaintained\n W:\thttp://www.winischhofer.at/linuxsisusbvga.shtml\n F:\tdrivers/usb/misc/sisusbvga/\n \n+SITIME SIT9531X DPLL DRIVER\n+M:\tAli Rouhi \u003carouhi@sitime.com\u003e\n+L:\tnetdev@vger.kernel.org\n+S:\tMaintained\n+F:\tDocumentation/devicetree/bindings/dpll/sitime,sit95316.yaml\n+F:\tdrivers/dpll/sit9531x/\n+\n SL28 CPLD MFD DRIVER\n M:\tMichael Walle \u003cmwalle@kernel.org\u003e\n S:\tMaintained\ndiff --git a/drivers/dpll/Kconfig b/drivers/dpll/Kconfig\nindex be98969f040ab..f8f7ca121b932 100644\n--- a/drivers/dpll/Kconfig\n+++ b/drivers/dpll/Kconfig\n@@ -23,6 +23,8 @@ config DPLL_REFCNT_TRACKER\n \n \t If unsure, say N.\n \n+source \"drivers/dpll/sit9531x/Kconfig\"\n+\n source \"drivers/dpll/zl3073x/Kconfig\"\n \n endmenu\ndiff --git a/drivers/dpll/Makefile b/drivers/dpll/Makefile\nindex 9e7a3a3e592e8..4adc50d748d4d 100644\n--- a/drivers/dpll/Makefile\n+++ b/drivers/dpll/Makefile\n@@ -8,4 +8,5 @@ dpll-y += dpll_core.o\n dpll-y += dpll_netlink.o\n dpll-y += dpll_nl.o\n \n+obj-$(CONFIG_SIT9531X_DPLL)\t+= sit9531x/\n obj-$(CONFIG_ZL3073X)\t+= zl3073x/\ndiff --git a/drivers/dpll/sit9531x/Kconfig b/drivers/dpll/sit9531x/Kconfig\nnew file mode 100644\nindex 0000000000000..47aea8674327c\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/Kconfig\n@@ -0,0 +1,17 @@\n+# SPDX-License-Identifier: GPL-2.0-only\n+\n+config SIT9531X_DPLL\n+\ttristate \"SiTime SiT9531x DPLL driver\"\n+\tdepends on I2C \u0026\u0026 NET\n+\tselect DPLL\n+\tselect REGMAP_I2C\n+\thelp\n+\t Driver for SiTime SiT9531x family clock generators\n+\t (SiT95317, SiT95316).\n+\n+\t This driver registers each on-chip PLL as a DPLL device\n+\t and exposes input/output clocks as DPLL pins, providing\n+\t runtime configuration via Generic Netlink.\n+\n+\t To compile this driver as a module, choose M here: the\n+\t module will be called sit9531x.\ndiff --git a/drivers/dpll/sit9531x/Makefile b/drivers/dpll/sit9531x/Makefile\nnew file mode 100644\nindex 0000000000000..b97d2656a4603\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/Makefile\n@@ -0,0 +1,4 @@\n+# SPDX-License-Identifier: GPL-2.0-only\n+\n+obj-$(CONFIG_SIT9531X_DPLL) += sit9531x.o\n+sit9531x-y := core.o dpll.o prop.o\ndiff --git a/drivers/dpll/sit9531x/core.c b/drivers/dpll/sit9531x/core.c\nnew file mode 100644\nindex 0000000000000..5316e6bcb338c\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/core.c\n@@ -0,0 +1,4553 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * SiTime SiT9531x DPLL core driver\n+ *\n+ * Copyright (C) 2026 SiTime Corp.\n+ * Author: Ali Rouhi \u003carouhi@sitime.com\u003e\n+ * Author: Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\n+ *\n+ * Core I2C probe, regmap configuration, hardware state management,\n+ * and periodic work thread.\n+ */\n+\n+#include \u003clinux/bitfield.h\u003e\n+#include \u003clinux/bits.h\u003e\n+#include \u003clinux/clk.h\u003e\n+#include \u003clinux/delay.h\u003e\n+#include \u003clinux/dev_printk.h\u003e\n+#include \u003clinux/device.h\u003e\n+#include \u003clinux/gpio/consumer.h\u003e\n+#include \u003clinux/i2c.h\u003e\n+#include \u003clinux/interrupt.h\u003e\n+#include \u003clinux/kernel.h\u003e\n+#include \u003clinux/kthread.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/pm.h\u003e\n+#include \u003clinux/property.h\u003e\n+#include \u003clinux/regmap.h\u003e\n+#include \u003clinux/slab.h\u003e\n+#include \u003clinux/string.h\u003e\n+\n+#include \"core.h\"\n+#include \"dpll.h\"\n+#include \"prop.h\"\n+#include \"regs.h\"\n+\n+/*\n+ * Number of input + output pin positions for pin index allocation. The two\n+ * extra input positions are the crystal and the INTSYNC destination, the\n+ * extra output position is the INTSYNC source.\n+ */\n+#define SIT9531X_NUM_INPUT_PINS\t\t(SIT9531X_MAX_INPUTS + 2)\n+#define SIT9531X_NUM_OUTPUT_PINS\t(SIT9531X_MAX_OUTPUTS + 1)\n+#define SIT9531X_NUM_PINS_TOTAL\t\t(SIT9531X_NUM_INPUT_PINS + \\\n+\t\t\t\t\t SIT9531X_NUM_OUTPUT_PINS)\n+\n+#define SIT9531X_CHIP(_id, _nin, _nout, _name, _map) \\\n+\t{ .id = (_id), .num_inputs = (_nin), .num_outputs = (_nout), \\\n+\t .name = (_name), .clkout_map = (_map) }\n+\n+/* Per-variant output index -\u003e physical slot mapping */\n+static const u8 clkout_map_95317[] = {0, 3, 4, 5, 7, 8, 9, 11};\n+static const u8 clkout_map_95316[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};\n+\n+static const struct sit9531x_chip_info sit9531x_chip_ids[] = {\n+\tSIT9531X_CHIP(SIT9531X_VARIANT_ID_95317, 8, 8, \"SiT95317\",\n+\t\t clkout_map_95317),\n+\tSIT9531X_CHIP(SIT9531X_VARIANT_ID_95316, 8, 12, \"SiT95316\",\n+\t\t clkout_map_95316),\n+};\n+\n+#define SIT9531X_RANGE_OFFSET\tSIT9531X_PAGE_SIZE\n+\n+/*\n+ * Everything the device holds can change without the driver writing it,\n+ * so nothing here is cacheable -- except the page selector, which only\n+ * this driver moves. Caching that one spares a read of it before every\n+ * access: the range code selects the page through a read-modify-write,\n+ * and with no cache that read goes to the bus each time.\n+ */\n+static bool sit9531x_volatile_reg(struct device *dev __maybe_unused,\n+\t\t\t\t unsigned int reg)\n+{\n+\treturn reg != SIT9531X_PAGE_SEL;\n+}\n+\n+static const struct regmap_range_cfg sit9531x_regmap_range = {\n+\t.range_min\t= SIT9531X_RANGE_OFFSET,\n+\t.range_max\t= SIT9531X_RANGE_OFFSET +\n+\t\t\t (SIT9531X_NUM_PAGES * SIT9531X_PAGE_SIZE) - 1,\n+\t.selector_reg\t= SIT9531X_PAGE_SEL,\n+\t.selector_mask\t= GENMASK(7, 0),\n+\t.selector_shift\t= 0,\n+\t.window_start\t= 0,\n+\t.window_len\t= SIT9531X_PAGE_SIZE,\n+};\n+\n+const struct regmap_config sit9531x_regmap_config = {\n+\t.reg_bits\t= 8,\n+\t.val_bits\t= 8,\n+\t.max_register\t= SIT9531X_RANGE_OFFSET +\n+\t\t\t (SIT9531X_NUM_PAGES * SIT9531X_PAGE_SIZE) - 1,\n+\t.ranges\t\t= \u0026sit9531x_regmap_range,\n+\t.num_ranges\t= 1,\n+\t.volatile_reg\t= sit9531x_volatile_reg,\n+\t.cache_type\t= REGCACHE_MAPLE,\n+};\n+\n+/*\n+ * sit9531x_read_u8 - read an 8-bit register\n+ * @reg:\tregister in SIT9531X_REG(page, offset) form\n+ * @val:\toutput value\n+ */\n+int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,\n+\t\t u8 *val)\n+{\n+\tunsigned int tmp;\n+\tint rc;\n+\n+\treg = (SIT9531X_REG_PAGE(reg) * SIT9531X_PAGE_SIZE) +\n+\t SIT9531X_REG_OFFSET(reg) + SIT9531X_RANGE_OFFSET;\n+\n+\trc = regmap_read(sitdev-\u003eregmap, reg, \u0026tmp);\n+\tif (rc)\n+\t\tdev_err(sitdev-\u003edev, \"Failed to read reg 0x%04x: %d\\n\",\n+\t\t\treg, rc);\n+\telse\n+\t\t*val = (u8)tmp;\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_write_u8 - write an 8-bit register\n+ * @reg:\tregister in SIT9531X_REG(page, offset) form\n+ * @val:\tvalue to write\n+ */\n+int sit9531x_write_u8(struct sit9531x_dev *sitdev, unsigned int reg,\n+\t\t u8 val)\n+{\n+\tint rc;\n+\n+\treg = (SIT9531X_REG_PAGE(reg) * SIT9531X_PAGE_SIZE) +\n+\t SIT9531X_REG_OFFSET(reg) + SIT9531X_RANGE_OFFSET;\n+\n+\trc = regmap_write(sitdev-\u003eregmap, reg, val);\n+\tif (rc)\n+\t\tdev_err(sitdev-\u003edev, \"Failed to write reg 0x%04x: %d\\n\",\n+\t\t\treg, rc);\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_read_pll_u8 - read a register on a PLL page\n+ * @val:\toutput value\n+ */\n+int sit9531x_read_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 offset, u8 *val)\n+{\n+\tu8 page = sit9531x_pll_page(pll_idx);\n+\n+\treturn sit9531x_read_u8(sitdev, SIT9531X_REG(page, offset), val);\n+}\n+\n+/*\n+ * sit9531x_write_pll_u8 - write a register on a PLL page\n+ * @val:\tvalue to write\n+ */\n+int sit9531x_write_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 offset, u8 val)\n+{\n+\tu8 page = sit9531x_pll_page(pll_idx);\n+\n+\treturn sit9531x_write_u8(sitdev, SIT9531X_REG(page, offset), val);\n+}\n+\n+/*\n+ * sit9531x_update_pll_u8 - read-modify-write a register on a PLL page\n+ * @mask:\tbits to modify\n+ * @val:\tnew value for masked bits\n+ */\n+int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 offset, u8 mask, u8 val)\n+{\n+\tunsigned int reg;\n+\n+\treg = (sit9531x_pll_page(pll_idx) * SIT9531X_PAGE_SIZE) +\n+\t offset + SIT9531X_RANGE_OFFSET;\n+\n+\treturn regmap_update_bits(sitdev-\u003eregmap, reg, mask, val);\n+}\n+\n+/*\n+ * sit9531x_input_get_regs - get force mask and state register addresses\n+ * @index:\tlogical input index\n+ * @force_reg:\toutput force mask register address\n+ * @state_reg:\toutput state register address\n+ *\n+ * Selects the correct Page 0x02 register pair based on the pair's\n+ * signal mode and the lane (P/N) the index refers to.\n+ */\n+static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev,\n+\t\t\t\t u8 index,\n+\t\t\t\t unsigned int *force_reg,\n+\t\t\t\t unsigned int *state_reg)\n+{\n+\tif (sitdev-\u003eref[index].sig_mode == SIT9531X_MODE_DE) {\n+\t\t*force_reg = SIT9531X_REG_IN_DE_FORCE;\n+\t\t*state_reg = SIT9531X_REG_IN_DE_STATE;\n+\t} else if (sit9531x_input_is_n(index)) {\n+\t\t*force_reg = SIT9531X_REG_IN_SEN_FORCE;\n+\t\t*state_reg = SIT9531X_REG_IN_SEN_STATE;\n+\t} else {\n+\t\t*force_reg = SIT9531X_REG_IN_SEP_FORCE;\n+\t\t*state_reg = SIT9531X_REG_IN_SEP_STATE;\n+\t}\n+}\n+\n+/*\n+ * sit9531x_input_disable - disable an input reference\n+ * @index:\tlogical input index (0-N)\n+ *\n+ * Sets the force mask bit and clears the state bit for the given\n+ * input, effectively disabling it. Register selection depends on\n+ * the pair's signal mode (SE/DE) and the lane (P/N); the bit within\n+ * each register addresses the input pair.\n+ *\n+ * Both writes are attempted even when the first fails, and the first\n+ * error is returned. Neither is rolled back: the force and state bits\n+ * only mean something together, so a transient bus error can leave the\n+ * force bit asserted over a state bit that was never programmed, and the\n+ * error is what says the override is not to be trusted.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_input_disable(struct sit9531x_dev *sitdev, u8 index)\n+{\n+\tunsigned int force_reg, state_reg;\n+\tstruct sit9531x_ref *ref;\n+\tu8 pair, val;\n+\tint rc, ret;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (index \u003e= SIT9531X_MAX_INPUTS)\n+\t\treturn -EINVAL;\n+\n+\tref = \u0026sitdev-\u003eref[index];\n+\tpair = sit9531x_input_pair(index);\n+\tsit9531x_input_get_regs(sitdev, index, \u0026force_reg, \u0026state_reg);\n+\n+\trc = sit9531x_read_u8(sitdev, force_reg, \u0026val);\n+\tif (!rc)\n+\t\trc = sit9531x_write_u8(sitdev, force_reg, val | BIT(pair));\n+\n+\tret = sit9531x_read_u8(sitdev, state_reg, \u0026val);\n+\tif (!ret)\n+\t\tret = sit9531x_write_u8(sitdev, state_reg, val \u0026 ~BIT(pair));\n+\tif (ret \u0026\u0026 !rc)\n+\t\trc = ret;\n+\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tref-\u003eenabled = false;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_input_enable - enable an input reference\n+ * @index:\tlogical input index (0-N)\n+ *\n+ * Clears the force mask bit for the given input, returning it to\n+ * hardware default (enabled).\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index)\n+{\n+\tunsigned int force_reg, state_reg;\n+\tstruct sit9531x_ref *ref;\n+\tu8 pair, val;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (index \u003e= SIT9531X_MAX_INPUTS)\n+\t\treturn -EINVAL;\n+\n+\tref = \u0026sitdev-\u003eref[index];\n+\tpair = sit9531x_input_pair(index);\n+\tsit9531x_input_get_regs(sitdev, index, \u0026force_reg, \u0026state_reg);\n+\n+\trc = sit9531x_read_u8(sitdev, force_reg, \u0026val);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, force_reg, val \u0026 ~BIT(pair));\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tref-\u003eenabled = true;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Output enable / disable (Hi-Z control)\n+ *\n+ * SiT9531x outputs can be configured as differential (DIFF) or\n+ * single-ended (SE) depending on the factory blob. Each output slot\n+ * has TWO Hi-Z force/state register pairs on Page 0x03 -- one for the\n+ * DIFF path, one for the SE path.\n+ *\n+ * We write to BOTH pairs so the function mutes the output regardless\n+ * of whether it's been configured DIFF or SE on this board.\n+ *\n+ * slot 0-7 :\n+ * DIFF mask=0xF2 state=0xF3 SE mask=0xF8 state=0xF9\n+ * slot 8-11:\n+ * DIFF mask=0xF4 state=0xF5 SE mask=0xFA state=0xFB\n+ *\n+ * MASK bit = 1 -\u003e driver takes control of that output's Hi-Z state\n+ * STATE bit = 0 -\u003e output is forced to Hi-Z (muted)\n+ * STATE bit = 1 -\u003e output is driven (active)\n+ *\n+ * The output \"index\" in the driver is logical; the physical slot comes\n+ * from info-\u003eclkout_map[].\n+ */\n+\n+struct sit9531x_hiz_regs {\n+\tunsigned int diff_mask;\n+\tunsigned int diff_state;\n+\tunsigned int se_mask;\n+\tunsigned int se_state;\n+\tu8 bit;\n+};\n+\n+static void sit9531x_output_get_hiz_regs(u8 slot,\n+\t\t\t\t\t struct sit9531x_hiz_regs *r)\n+{\n+\tif (slot \u003c= 7) {\n+\t\tr-\u003ediff_mask = SIT9531X_REG_HIZ_DIFF_07_MASK;\n+\t\tr-\u003ediff_state = SIT9531X_REG_HIZ_DIFF_07_STATE;\n+\t\tr-\u003ese_mask = SIT9531X_REG_HIZ_SE_07_MASK;\n+\t\tr-\u003ese_state = SIT9531X_REG_HIZ_SE_07_STATE;\n+\t\tr-\u003ebit = slot;\n+\t} else {\n+\t\tr-\u003ediff_mask = SIT9531X_REG_HIZ_DIFF_811_MASK;\n+\t\tr-\u003ediff_state = SIT9531X_REG_HIZ_DIFF_811_STATE;\n+\t\tr-\u003ese_mask = SIT9531X_REG_HIZ_SE_811_MASK;\n+\t\tr-\u003ese_state = SIT9531X_REG_HIZ_SE_811_STATE;\n+\t\tr-\u003ebit = slot - 8;\n+\t}\n+}\n+\n+/*\n+ * sit9531x_output_mode_fetch - read how an output is wired\n+ *\n+ * The Hi-Z force is a separate register pair for the differential and the\n+ * single-ended path, and only the pair belonging to the way the output is\n+ * actually wired says anything about whether it is quiet. The other pair\n+ * holds whatever the loaded configuration left in it.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static int sit9531x_output_mode_fetch(struct sit9531x_dev *sitdev, u8 out_idx)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tu8 slot, page, reg, val;\n+\tint rc;\n+\n+\tslot = info-\u003eclkout_map[out_idx];\n+\tpage = (slot \u003e SIT9531X_PAGE_OUTSYS0_SLOT_MAX) ?\n+\t\tSIT9531X_PAGE_OUTSYS1 : SIT9531X_PAGE_OUTSYS0;\n+\treg = SIT9531X_OUT_MISC0_BASE +\n+\t SIT9531X_OUT_MISC0_STRIDE * (slot % 6);\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG(page, reg), \u0026val);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tsitdev-\u003eout[out_idx].cmos = !!(val \u0026 (SIT9531X_OUT_CMOS_ENP |\n+\t\t\t\t\t SIT9531X_OUT_CMOS_ENN));\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Report whether a slot is currently forced into Hi-Z, i.e. the driver\n+ * (or the blob) took control of the Hi-Z state (MASK bit set) and drives\n+ * it low (STATE bit clear). Either register pair muting the slot counts,\n+ * mirroring what sit9531x_output_disable() programs.\n+ */\n+static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,\n+\t\t\t\t u8 out_idx, bool *muted)\n+{\n+\tstruct sit9531x_hiz_regs r;\n+\tunsigned int mask_reg, state_reg;\n+\tu8 mask, state;\n+\tint rc;\n+\n+\tsit9531x_output_get_hiz_regs(sitdev-\u003einfo-\u003eclkout_map[out_idx], \u0026r);\n+\n+\t/*\n+\t * Read the pair that belongs to the way this output is wired.\n+\t * Testing both and taking either as proof of a mute answers\n+\t * from a register nothing drives, and disagrees with itself\n+\t * when a mute lands on one pair and fails on the other.\n+\t */\n+\tif (sitdev-\u003eout[out_idx].cmos) {\n+\t\tmask_reg = r.se_mask;\n+\t\tstate_reg = r.se_state;\n+\t} else {\n+\t\tmask_reg = r.diff_mask;\n+\t\tstate_reg = r.diff_state;\n+\t}\n+\n+\trc = sit9531x_read_u8(sitdev, mask_reg, \u0026mask);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_read_u8(sitdev, state_reg, \u0026state);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t*muted = (mask \u0026 BIT(r.bit)) \u0026\u0026 !(state \u0026 BIT(r.bit));\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_output_state_refresh - read an output's mute state back\n+ *\n+ * Used when a mute could not be confirmed at the time it was written. The\n+ * driver does not poll output state, so without this the cached value would\n+ * stand until something else happened to write it.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_output_state_refresh(struct sit9531x_dev *sitdev, u8 out_idx)\n+{\n+\tbool muted;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\trc = sit9531x_output_forced_hiz(sitdev, out_idx, \u0026muted);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tsitdev-\u003eout[out_idx].enabled = !muted;\n+\tsitdev-\u003eout[out_idx].state_stale = false;\n+\n+\treturn 0;\n+}\n+\n+static int sit9531x_hiz_set_bit(struct sit9531x_dev *sitdev,\n+\t\t\t\tunsigned int reg, u8 bit, bool set)\n+{\n+\tu8 cur, new_val;\n+\tint rc;\n+\n+\trc = sit9531x_read_u8(sitdev, reg, \u0026cur);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tnew_val = set ? (cur | BIT(bit)) : (cur \u0026 ~BIT(bit));\n+\n+\treturn sit9531x_write_u8(sitdev, reg, new_val);\n+}\n+\n+/* Attempts to re-lock the output loops before reporting them open. */\n+#define SIT9531X_LOOP_LOCK_TRIES\t3\n+\n+/*\n+ * sit9531x_prg_abort - leave the programming state without committing\n+ *\n+ * Entering the state is two writes, and the second can fail with the debug\n+ * block already unlocked and the part possibly already in PRG_CMD. There\n+ * is nothing to commit in that case, but the loops still have to be closed\n+ * and the debug key put back, which is otherwise only done by\n+ * sit9531x_prg_commit().\n+ */\n+static void sit9531x_prg_abort(struct sit9531x_dev *sitdev)\n+{\n+\tu8 attempt;\n+\tint rc = -EIO;\n+\n+\tfor (attempt = 0; attempt \u003c SIT9531X_LOOP_LOCK_TRIES; attempt++) {\n+\t\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,\n+\t\t\t\t SIT9531X_LOOP_LOCK);\n+\t\tif (!rc)\n+\t\t\tbreak;\n+\t\tusleep_range(1000, 2000);\n+\t}\n+\tif (rc)\n+\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\"output loops left unlocked after a failed entry: %d\\n\",\n+\t\t\trc);\n+\n+\tsit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,\n+\t\t\t SIT9531X_DEBUG_LOCK_VAL);\n+}\n+\n+/*\n+ * Enter the output-system programming state: unlock the debug\n+ * registers on Page 3 and issue the PRG_CMD state command. Register\n+ * writes that reconfigure the output system only take effect when\n+ * they are made inside this state.\n+ */\n+static int sit9531x_prg_enter(struct sit9531x_dev *sitdev)\n+{\n+\tint rc;\n+\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,\n+\t\t\t SIT9531X_DEBUG_UNLOCK_VAL);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,\n+\t\t\t SIT9531X_PRG_CMD_STATE);\n+\tif (rc) {\n+\t\t/*\n+\t\t * The debug block is unlocked at this point, and a transfer\n+\t\t * that reported an error may still have reached the part --\n+\t\t * which would leave the device in PRG_CMD with its output\n+\t\t * loops open. Callers skip the commit when the entry\n+\t\t * fails, so close both here.\n+\t\t */\n+\t\tsit9531x_prg_abort(sitdev);\n+\t\treturn rc;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Commit a programming sequence started by sit9531x_prg_enter():\n+ * update the NVM shadow and re-lock the loops. The sleep gives the\n+ * hardware its required settling time after the loop-lock command;\n+ * it is intentional despite the caller holding multiop_lock, as the\n+ * whole NVM + lock sequence must be atomic.\n+ */\n+static int sit9531x_prg_commit(struct sit9531x_dev *sitdev)\n+{\n+\tint rc, rc2 = 0, rc3;\n+\tu8 attempt;\n+\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,\n+\t\t\t SIT9531X_UPDATE_NVM);\n+\n+\t/*\n+\t * Issue the loop lock even if the update failed. Callers reach\n+\t * this function through a goto so that the chip never stays in\n+\t * the PRG_CMD state with its loops open; returning early here\n+\t * would defeat that and leave the outputs unlocked until the\n+\t * next successful commit.\n+\t */\n+\t/*\n+\t * Re-lock the loops. Leaving them open is worse than any other\n+\t * failure this function can report, and nothing else closes them,\n+\t * so retry as the priority table does with its own latch.\n+\t */\n+\tfor (attempt = 0; attempt \u003c SIT9531X_LOOP_LOCK_TRIES; attempt++) {\n+\t\trc2 = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,\n+\t\t\t\t\tSIT9531X_LOOP_LOCK);\n+\t\tif (!rc2)\n+\t\t\tbreak;\n+\t\tusleep_range(1000, 2000);\n+\t}\n+\tif (rc2)\n+\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\"output loops left unlocked after programming: %d\\n\",\n+\t\t\trc2);\n+\n+\tmsleep(100);\n+\n+\t/*\n+\t * Put the output-system debug block back the way the device powers\n+\t * up. Its key register unlocks every debug register while it holds\n+\t * the unlock value, and each programming sequence writes that value\n+\t * itself, so nothing needs it left unlocked in between.\n+\t */\n+\trc3 = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,\n+\t\t\t\tSIT9531X_DEBUG_LOCK_VAL);\n+\n+\tif (rc)\n+\t\treturn rc;\n+\n+\treturn rc2 ? rc2 : rc3;\n+}\n+\n+/*\n+ * sit9531x_output_hiz_write - mute or unmute an output\n+ *\n+ * Muting takes control of the pin (MASK=1) and drives it low (STATE=0) on\n+ * both the differential and the single-ended register pair, because the\n+ * output must go quiet whichever way it is wired; unmuting hands it back\n+ * to the device's own state machine. The caller must already be in the\n+ * programming state.\n+ */\n+static int sit9531x_output_hiz_write(struct sit9531x_dev *sitdev, u8 slot,\n+\t\t\t\t bool mute)\n+{\n+\tstruct sit9531x_hiz_regs r;\n+\tint rc, undo_rc;\n+\n+\tsit9531x_output_get_hiz_regs(slot, \u0026r);\n+\n+\tif (!mute) {\n+\t\trc = sit9531x_hiz_set_bit(sitdev, r.diff_mask, r.bit, false);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\n+\t\treturn sit9531x_hiz_set_bit(sitdev, r.se_mask, r.bit, false);\n+\t}\n+\n+\t/*\n+\t * Forced value first, override enable second. Muted is decoded as\n+\t * MASK set with STATE clear, so enabling the override while STATE\n+\t * still holds whatever the loaded configuration left there can pin\n+\t * the pad driven for the width of an I2C transfer.\n+\t */\n+\trc = sit9531x_hiz_set_bit(sitdev, r.diff_state, r.bit, false);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_hiz_set_bit(sitdev, r.diff_mask, r.bit, true);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_hiz_set_bit(sitdev, r.se_state, r.bit, false);\n+\tif (rc)\n+\t\tgoto undo_diff;\n+\trc = sit9531x_hiz_set_bit(sitdev, r.se_mask, r.bit, true);\n+\tif (rc)\n+\t\tgoto undo_diff;\n+\n+\treturn 0;\n+\n+undo_diff:\n+\t/*\n+\t * Only one half of the pair reached the device. Release the\n+\t * override that did: that leaves the pad on the state the loaded\n+\t * configuration gave it, which is where the request started, rather\n+\t * than driven by half a mute that nothing afterwards clears.\n+\t */\n+\tundo_rc = sit9531x_hiz_set_bit(sitdev, r.diff_mask, r.bit, false);\n+\tif (undo_rc)\n+\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\"slot%u: Hi-Z override left half applied (%d)\\n\",\n+\t\t\tslot, undo_rc);\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_output_disable - mute an output (force Hi-Z)\n+ * @index:\tlogical output index (0..info-\u003enum_outputs-1)\n+ *\n+ * Sets MASK and clears STATE on BOTH the DIFF and SE register pairs so that the\n+ * output is muted regardless of its electrical configuration. The\n+ * writes are wrapped in the PRG_CMD / NVM update / loop lock sequence\n+ * so the new state is applied by the hardware.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_output_disable(struct sit9531x_dev *sitdev, u8 index)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tbool muted;\n+\tu8 slot;\n+\tint rc, ret, state_rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (index \u003e= info-\u003enum_outputs)\n+\t\treturn -EINVAL;\n+\n+\tslot = info-\u003eclkout_map[index];\n+\trc = sit9531x_prg_enter(sitdev);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_output_hiz_write(sitdev, slot, true);\n+\n+\t/*\n+\t * Always leave the PRG_CMD programming state, even on a mid-sequence\n+\t * write failure: prg_enter() unlocked the output loops, so returning\n+\t * without prg_commit() would strand the chip in the programming state\n+\t * with the loops unlocked. Best effort -- keep the first error.\n+\t */\n+\tret = sit9531x_prg_commit(sitdev);\n+\tif (ret \u0026\u0026 !rc)\n+\t\trc = ret;\n+\n+\t/*\n+\t * Keep the software state aligned to what hardware now drives even\n+\t * when one write in the sequence failed. The commit above may have\n+\t * applied a partial mask/state combination.\n+\t */\n+\tstate_rc = sit9531x_output_forced_hiz(sitdev, index, \u0026muted);\n+\tif (!state_rc) {\n+\t\tsitdev-\u003eout[index].enabled = !muted;\n+\t\tsitdev-\u003eout[index].state_stale = false;\n+\t} else {\n+\t\t/*\n+\t\t * The writes may well have landed; what failed is the proof.\n+\t\t * Mark the cached state for a read-through rather than\n+\t\t * reporting the value it had before this call.\n+\t\t */\n+\t\tsitdev-\u003eout[index].state_stale = true;\n+\t\tif (!rc)\n+\t\t\trc = state_rc;\n+\t}\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_output_enable - un-mute an output (active state)\n+ * @index:\tlogical output index (0..info-\u003enum_outputs-1)\n+ *\n+ * Releases MASK on BOTH register pairs so the output returns to\n+ * whatever the initial_config blob programmed. The writes are wrapped\n+ * in the PRG_CMD / NVM update / loop lock sequence so the new state is\n+ * applied by the hardware.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_output_enable(struct sit9531x_dev *sitdev, u8 index)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tbool muted;\n+\tu8 slot;\n+\tint rc, ret, state_rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (index \u003e= info-\u003enum_outputs)\n+\t\treturn -EINVAL;\n+\n+\tslot = info-\u003eclkout_map[index];\n+\trc = sit9531x_prg_enter(sitdev);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_output_hiz_write(sitdev, slot, false);\n+\n+\t/*\n+\t * Always leave the PRG_CMD programming state, even on a mid-sequence\n+\t * write failure: prg_enter() unlocked the output loops, so returning\n+\t * without prg_commit() would strand the chip in the programming state\n+\t * with the loops unlocked. Best effort -- keep the first error.\n+\t */\n+\tret = sit9531x_prg_commit(sitdev);\n+\tif (ret \u0026\u0026 !rc)\n+\t\trc = ret;\n+\n+\t/* See sit9531x_output_disable(): commit can apply part of it. */\n+\tstate_rc = sit9531x_output_forced_hiz(sitdev, index, \u0026muted);\n+\tif (!state_rc) {\n+\t\tsitdev-\u003eout[index].enabled = !muted;\n+\t\tsitdev-\u003eout[index].state_stale = false;\n+\t} else {\n+\t\t/*\n+\t\t * The writes may well have landed; what failed is the proof.\n+\t\t * Mark the cached state for a read-through rather than\n+\t\t * reporting the value it had before this call.\n+\t\t */\n+\t\tsitdev-\u003eout[index].state_stale = true;\n+\t\tif (!rc)\n+\t\t\trc = state_rc;\n+\t}\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * Input priority selection\n+ *\n+ * The SiT9531x has an 11-slot priority table per PLL on Page 1. Each\n+ * register holds two slots nibble-packed: the earlier (even, 2n) slot\n+ * in [7:4] and the later (odd, 2n+1) slot in [3:0].\n+ *\n+ * The procedure:\n+ * 1. Force PLL into holdover (PLL page reg 0x6F bit 4)\n+ * 2. Write priority slots on Page 1\n+ * 3. Small change update (Page 0 reg 0x0F bit 1)\n+ * 4. Release holdover\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+\n+/* Page-1 register holding priority slot @slot of @pll_idx. */\n+static u16 sit9531x_prio_reg(u8 pll_idx, u8 slot)\n+{\n+\treturn SIT9531X_REG(SIT9531X_PAGE_PRIOSYS,\n+\t\t\t SIT9531X_PRIO_BASE_REG +\n+\t\t\t SIT9531X_PRIO_REGS_PER_PLL * pll_idx +\n+\t\t\t slot / SIT9531X_PRIO_SLOTS_PER_REG);\n+}\n+\n+/*\n+ * Extract priority slot @slot from its register value. The register\n+ * holding slots 2n and 2n+1 keeps the earlier slot in the high nibble\n+ * (CLK_SPARE\u003c2n\u003eSEL) and the later one in the low nibble.\n+ */\n+static u8 sit9531x_prio_slot_get(u8 val, u8 slot)\n+{\n+\tif (slot \u0026 1)\n+\t\treturn val \u0026 SIT9531X_PRIO_NIBBLE_MASK;\n+\n+\treturn val \u003e\u003e SIT9531X_PRIO_HI_SHIFT;\n+}\n+\n+/* Place source @src in priority slot @slot of a register value. */\n+static u8 sit9531x_prio_slot_set(u8 val, u8 slot, u8 src)\n+{\n+\tif (slot \u0026 1)\n+\t\treturn (val \u0026 (SIT9531X_PRIO_NIBBLE_MASK \u003c\u003c\n+\t\t\t SIT9531X_PRIO_HI_SHIFT)) |\n+\t\t (src \u0026 SIT9531X_PRIO_NIBBLE_MASK);\n+\n+\treturn (val \u0026 SIT9531X_PRIO_NIBBLE_MASK) |\n+\t ((src \u0026 SIT9531X_PRIO_NIBBLE_MASK) \u003c\u003c\n+\t\tSIT9531X_PRIO_HI_SHIFT);\n+}\n+\n+/*\n+ * Commit a priority-table programming sequence through the Page-0\n+ * programming directive register.\n+ *\n+ * A small change update is all the table needs. The NVM-bank and\n+ * loop-lock directives that the output system issues do not belong\n+ * here: the former programs non-volatile storage from the efuse and\n+ * the latter only means anything after an escape to the PRG_CMD\n+ * state. This matches the documented input_priority_sel() procedure.\n+ */\n+static int sit9531x_prio_prg_commit(struct sit9531x_dev *sitdev)\n+{\n+\tint rc;\n+\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_GLOBAL_UPDATE,\n+\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tusleep_range(1000, 2000);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Fold a source code to the lane a DPLL pin actually represents.\n+ *\n+ * Differential input pairs expose only the P lane as a DPLL pin. A\n+ * priority table entry encoded as an N lane for such a pair must map to\n+ * the P-lane source for pin-facing operations (membership, priority slots,\n+ * add/remove/set lookups), matching sit9531x_ref_pll_mask_fetch().\n+ */\n+static u8 sit9531x_prio_src_canon(const struct sit9531x_dev *sitdev, u8 src)\n+{\n+\tu8 index = sit9531x_hw_src_input(src);\n+\n+\tif (index \u003e= sitdev-\u003einfo-\u003enum_inputs)\n+\t\treturn src;\n+\n+\tif (sit9531x_input_is_n(index) \u0026\u0026\n+\t sitdev-\u003eref[index].sig_mode == SIT9531X_MODE_DE)\n+\t\treturn sit9531x_input_hw_src(index - 1);\n+\n+\treturn src;\n+}\n+\n+/*\n+ * sit9531x_input_prio_present - is a source listed in a PLL's priority table\n+ * @input_idx:\tinput source in hardware encoding (see\n+ *\t\tsit9531x_input_hw_src())\n+ *\n+ * Answers from the membership mask that every table write and every poll\n+ * refreshes, which is what the pin state getters test. The priority slot\n+ * cannot answer this: a source that is not in the table reports the lowest\n+ * slot, so the slot value alone does not separate absent from last.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+bool sit9531x_input_prio_present(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t u8 input_idx)\n+{\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn false;\n+\n+\tinput_idx = sit9531x_prio_src_canon(sitdev, input_idx);\n+\tif (input_idx \u003e= SIT9531X_PRIO_NUM_SRC)\n+\t\treturn false;\n+\n+\treturn !!(sitdev-\u003echan[pll_idx].prio_mask \u0026 BIT(input_idx));\n+}\n+\n+/*\n+ * sit9531x_input_prio_get - read an input's priority slot for a PLL\n+ * @input_idx:\tinput source in hardware encoding (see\n+ *\t\tsit9531x_input_hw_src())\n+ * @prio:\toutput slot position (0 = highest)\n+ *\n+ * Reports the last slot this source occupied on this PLL. The value is\n+ * cached from the hardware table read at startup and refreshed after every\n+ * table write and poll read-back, so pin-get reflects hardware state without\n+ * issuing synchronous register reads per pin. A source with no known slot\n+ * falls back to the lowest-priority valid slot.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_input_prio_get(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx, u8 *prio)\n+{\n+\tconst struct sit9531x_chan *chan;\n+\tu8 slot;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\tinput_idx = sit9531x_prio_src_canon(sitdev, input_idx);\n+\tif (input_idx \u003e= SIT9531X_PRIO_NUM_SRC)\n+\t\treturn -EINVAL;\n+\n+\tchan = \u0026sitdev-\u003echan[pll_idx];\n+\tslot = chan-\u003eprio_last[input_idx];\n+\tif (!slot)\n+\t\tslot = SIT9531X_PRIO_MAX_SLOTS;\n+\n+\t*prio = slot - 1;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Refresh a PLL's cached view of its priority table from the source codes\n+ * the table holds -- here after a write, and once per poll from the\n+ * read-back in sit9531x_chan_state_fetch().\n+ *\n+ * The membership mask is what the pin state getters test; the per-slot\n+ * copy and the last-slot-seen array are what priority get answers from,\n+ * so neither costs a register read per pin.\n+ */\n+static void sit9531x_prio_mask_build(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t const u8 *srcs, u8 written)\n+{\n+\tstruct sit9531x_chan *chan = \u0026sitdev-\u003echan[pll_idx];\n+\tu8 first[SIT9531X_PRIO_NUM_SRC] = { 0 };\n+\tu16 mask = 0;\n+\tu8 slot, src, src_canon;\n+\n+\tfor (slot = 0; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++) {\n+\t\t/*\n+\t\t * A slot the caller could not write still holds what it\n+\t\t * held before, so take that rather than the value the\n+\t\t * request wanted to put there.\n+\t\t */\n+\t\tsrc = slot \u003c written ? srcs[slot] : chan-\u003eprio_srcs[slot];\n+\t\tsrc \u0026= SIT9531X_PRIO_NIBBLE_MASK;\n+\t\tchan-\u003eprio_srcs[slot] = src;\n+\t\tsrc_canon = sit9531x_prio_src_canon(sitdev, src);\n+\t\tif (!sit9531x_prio_src_usable(src))\n+\t\t\tcontinue;\n+\n+\t\tmask |= BIT(src_canon);\n+\t\tif (!first[src_canon])\n+\t\t\tfirst[src_canon] = slot + 1;\n+\t}\n+\n+\t/*\n+\t * Assign unconditionally: a source that has left the table has no\n+\t * slot, and leaving its old one behind would keep reporting it as\n+\t * listed for as long as the device runs.\n+\t */\n+\tfor (src = 0; src \u003c SIT9531X_PRIO_NUM_SRC; src++)\n+\t\tchan-\u003eprio_last[src] = first[src];\n+\n+\tchan-\u003eprio_mask = mask;\n+}\n+\n+/* Attempts to release a forced holdover before reporting it stuck. */\n+#define SIT9531X_HO_CLEAR_TRIES\t\t3\n+\n+static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t const u8 *srcs)\n+{\n+\tstruct sit9531x_chan *chan = \u0026sitdev-\u003echan[pll_idx];\n+\tu8 val, slot, attempt, written = 0, restored = 0;\n+\tint rc = 0, prg_rc, ho_rc = 0;\n+\tu16 reg;\n+\n+\trc = sit9531x_update_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_HO_CTRL,\n+\t\t\t\t BIT(SIT9531X_PLL_HO_FORCE_BIT),\n+\t\t\t\t BIT(SIT9531X_PLL_HO_FORCE_BIT));\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tusleep_range(10000, 12000);\n+\n+\t/*\n+\t * Two slots share a register, and this writes every slot, so both\n+\t * nibbles are known for every register but the last -- build those\n+\t * bytes outright. Reading first would raise the question of what a\n+\t * read returns between the write and the latch, and the answer does\n+\t * not matter if nothing is read.\n+\t */\n+\tfor (slot = 0; slot + 1 \u003c SIT9531X_PRIO_MAX_SLOTS; slot += 2) {\n+\t\treg = sit9531x_prio_reg(pll_idx, slot);\n+\n+\t\tval = sit9531x_prio_slot_set(0, slot, srcs[slot]);\n+\t\tval = sit9531x_prio_slot_set(val, slot + 1, srcs[slot + 1]);\n+\n+\t\trc = sit9531x_write_u8(sitdev, reg, val);\n+\t\tif (rc)\n+\t\t\tgoto commit;\n+\n+\t\twritten = slot + 2;\n+\t}\n+\n+\t/*\n+\t * The last slot shares its register with a nibble this table does\n+\t * not use, so that one is read first to leave it as it was.\n+\t */\n+\treg = sit9531x_prio_reg(pll_idx, slot);\n+\n+\trc = sit9531x_read_u8(sitdev, reg, \u0026val);\n+\tif (rc)\n+\t\tgoto commit;\n+\n+\tval = sit9531x_prio_slot_set(val, slot, srcs[slot]);\n+\n+\trc = sit9531x_write_u8(sitdev, reg, val);\n+\tif (rc)\n+\t\tgoto commit;\n+\n+\twritten = SIT9531X_PRIO_MAX_SLOTS;\n+\n+\tif (rc \u0026\u0026 written) {\n+\t\t/*\n+\t\t * Put the slots that did reach the device back the way they\n+\t\t * were. Latching a table that is neither the previous order\n+\t\t * nor the requested one hands the reference selection loop\n+\t\t * a priority list nobody asked for. The cache is the table\n+\t\t * as last read, which is what those slots held.\n+\t\t */\n+\t\tfor (slot = 0; slot \u003c written; slot += 2) {\n+\t\t\tu8 old;\n+\n+\t\t\told = sit9531x_prio_slot_set(0, slot,\n+\t\t\t\t\t\t chan-\u003eprio_srcs[slot]);\n+\t\t\told = sit9531x_prio_slot_set(old, slot + 1,\n+\t\t\t\t\t\t chan-\u003eprio_srcs[slot + 1]);\n+\t\t\tif (sit9531x_write_u8(sitdev,\n+\t\t\t\t\t sit9531x_prio_reg(pll_idx, slot),\n+\t\t\t\t\t old))\n+\t\t\t\tbreak;\n+\n+\t\t\trestored = slot + 2;\n+\t\t}\n+\t\twritten = restored;\n+\t}\n+\n+commit:\n+\t/*\n+\t * Latch unconditionally: the slots that reached the device are in\n+\t * the table regardless, so the latch keeps hardware and the cache\n+\t * refresh below consistent with what was actually written.\n+\t */\n+\tprg_rc = sit9531x_prio_prg_commit(sitdev);\n+\tif (prg_rc \u0026\u0026 !rc)\n+\t\trc = prg_rc;\n+\n+\t/*\n+\t * Refresh the cache from the table just written, so a get that\n+\t * follows a set does not have to wait for the next poll -- but only\n+\t * for the slots that reached the device. Describing a table that\n+\t * does not exist would make the membership test answer for writes\n+\t * that failed, and that test is what decides whether a failed\n+\t * request gets rolled back.\n+\t */\n+\tsit9531x_prio_mask_build(sitdev, pll_idx, srcs, written);\n+\n+\t/*\n+\t * Release the forced holdover. Nothing else in the driver clears\n+\t * this bit, so a PLL left with it set reports holdover until the\n+\t * next table write on the same PLL happens to clear it, which may\n+\t * never come. Retry before giving up, and say so if it stays set.\n+\t */\n+\tfor (attempt = 0; attempt \u003c SIT9531X_HO_CLEAR_TRIES; attempt++) {\n+\t\tho_rc = sit9531x_update_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_HO_CTRL,\n+\t\t\t\t\t BIT(SIT9531X_PLL_HO_FORCE_BIT),\n+\t\t\t\t\t 0);\n+\t\tif (!ho_rc)\n+\t\t\tbreak;\n+\t\tusleep_range(1000, 2000);\n+\t}\n+\tif (ho_rc) {\n+\t\tdev_err(sitdev-\u003edev, \"PLL%c left in forced holdover: %d\\n\",\n+\t\t\t'A' + pll_idx, ho_rc);\n+\t\tif (!rc)\n+\t\t\trc = ho_rc;\n+\t}\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_prio_table_read - read a PLL's priority-table source codes\n+ * @srcs:\toutput array of SIT9531X_PRIO_MAX_SLOTS source codes\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static int sit9531x_prio_table_read(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t u8 *srcs)\n+{\n+\tu8 val, slot;\n+\tint rc;\n+\n+\tfor (slot = 0; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++) {\n+\t\trc = sit9531x_read_u8(sitdev,\n+\t\t\t\t sit9531x_prio_reg(pll_idx, slot), \u0026val);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\n+\t\tsrcs[slot] = sit9531x_prio_slot_get(val, slot);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_input_prio_set - move an input to a priority slot\n+ * @input_idx:\tinput source in hardware encoding (0-11, see\n+ *\t\tsit9531x_input_hw_src())\n+ * @prio:\tpriority slot position (0 = highest)\n+ *\n+ * Reads the PLL's table, takes the source out of wherever it sits and\n+ * reinserts it at @prio, shifting the entries in between. The rest keep\n+ * their relative order: a priority change asks about one input, so the\n+ * fallbacks configured behind it have to survive it.\n+ *\n+ * The table is what makes a source eligible for this PLL, so this only\n+ * ever reorders sources already in it. A source that is absent is\n+ * disconnected on this PLL, and inserting it here would make it a\n+ * selection candidate again behind the caller's back; that is a connect,\n+ * and it belongs to the pin's state setter.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ *\n+ * Return: 0 on success, -EINVAL if the source is not in the table,\n+ * \u003c0 on error\n+ */\n+int sit9531x_input_prio_set(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx, u8 prio)\n+{\n+\tu8 orig_srcs[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 rest[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 srcs[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 slot, n = 0;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\tinput_idx = sit9531x_prio_src_canon(sitdev, input_idx);\n+\tif (input_idx \u003e= SIT9531X_PRIO_NUM_SRC)\n+\t\treturn -EINVAL;\n+\tif (prio \u003e= SIT9531X_PRIO_MAX_SLOTS)\n+\t\treturn -EINVAL;\n+\n+\trc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tmemcpy(orig_srcs, srcs, sizeof(srcs));\n+\n+\t/*\n+\t * Take every copy of the source out first. A disconnect backfills\n+\t * the slots it frees with the lowest-priority source still listed,\n+\t * so the same source appearing more than once is an ordinary state\n+\t * of the table, and shifting from its first copy alone can leave\n+\t * another copy ahead of the slot the request named -- a priority\n+\t * the request did not ask for and the getter would then report.\n+\t */\n+\tfor (slot = 0; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++)\n+\t\tif (sit9531x_prio_src_canon(sitdev, srcs[slot]) != input_idx)\n+\t\t\trest[n++] = srcs[slot];\n+\n+\tif (n == SIT9531X_PRIO_MAX_SLOTS)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * Once the copies are collapsed the source can only sit behind the\n+\t * other sources the table lists, because the slots past the last of\n+\t * them repeat it. A slot beyond that is a priority the table cannot\n+\t * express, and placing the source at the nearest one it can would\n+\t * report success for a priority nobody asked for.\n+\t */\n+\tif (prio \u003e n)\n+\t\treturn -ERANGE;\n+\n+\tfor (slot = 0; slot \u003c prio; slot++)\n+\t\tsrcs[slot] = rest[slot];\n+\n+\tsrcs[prio] = input_idx;\n+\n+\tfor (slot = prio + 1; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++)\n+\t\tsrcs[slot] = (slot - 1 \u003c n) ? rest[slot - 1] : srcs[slot - 1];\n+\tif (!memcmp(srcs, orig_srcs, sizeof(srcs)))\n+\t\treturn 0;\n+\n+\treturn sit9531x_prio_table_commit(sitdev, pll_idx, srcs);\n+}\n+\n+/*\n+ * sit9531x_input_prio_remove - drop an input from a PLL's priority table\n+ * @input_idx:\tinput source in hardware encoding\n+ *\n+ * Rewrites the priority table with the source removed: the remaining\n+ * sources are compacted toward the highest-priority slots and the freed\n+ * tail slots are backfilled with the lowest-priority remaining source.\n+ * This makes a disconnected input ineligible for automatic reference\n+ * selection, not just gated at the input buffer.\n+ *\n+ * Removing a source that is absent is what the caller asked for already,\n+ * so it succeeds without touching the table. Removing the last one fills\n+ * every slot with the code for the pair this part does not have, which\n+ * leaves the device with nothing to select and no reference to fall back\n+ * on -- which is what a request to disconnect the last input means.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ *\n+ * Return: 0 on success, \u003c0 on error\n+ */\n+int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx)\n+{\n+\tu8 srcs[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 kept[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 slot, count = 0;\n+\tbool found = false;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\tinput_idx = sit9531x_prio_src_canon(sitdev, input_idx);\n+\n+\trc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tfor (slot = 0; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++) {\n+\t\tif (sit9531x_prio_src_canon(sitdev, srcs[slot]) == input_idx)\n+\t\t\tfound = true;\n+\t\telse\n+\t\t\tkept[count++] = srcs[slot];\n+\t}\n+\n+\tif (!found)\n+\t\treturn 0;\n+\n+\tif (count == 0) {\n+\t\t/*\n+\t\t * Nothing is left to compact toward, so every slot gets the\n+\t\t * code that names no reference. The device is then left\n+\t\t * with no source to select, which is what disconnecting the\n+\t\t * last input asks for; lock status follows the loop on its\n+\t\t * own from there.\n+\t\t */\n+\t\tmemset(kept, SIT9531X_PRIO_SRC_NONE, sizeof(kept));\n+\t} else {\n+\t\t/* Backfill freed tail slots with the lowest-priority src */\n+\t\twhile (count \u003c SIT9531X_PRIO_MAX_SLOTS) {\n+\t\t\tkept[count] = kept[count - 1];\n+\t\t\tcount++;\n+\t\t}\n+\t}\n+\n+\treturn sit9531x_prio_table_commit(sitdev, pll_idx, kept);\n+}\n+\n+/*\n+ * sit9531x_input_prio_add - make an input eligible in a PLL's table\n+ * @input_idx:\tinput source in hardware encoding\n+ *\n+ * Ensures the source appears in the priority table so it can be picked\n+ * by automatic reference selection again after a disconnect. If the\n+ * source is already listed the table is left untouched; otherwise it\n+ * replaces a duplicate at the tail. A table that contains only unique\n+ * sources cannot accept a new one without evicting another, so that\n+ * case fails with -ENOSPC.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx)\n+{\n+\tu8 srcs[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 seen[SIT9531X_PRIO_NUM_SRC] = { 0 };\n+\tu8 replace = SIT9531X_PRIO_MAX_SLOTS;\n+\tu8 slot, src, src_canon;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\tinput_idx = sit9531x_prio_src_canon(sitdev, input_idx);\n+\tif (input_idx \u003e= SIT9531X_PRIO_NUM_SRC)\n+\t\treturn -EINVAL;\n+\n+\trc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tfor (slot = 0; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++)\n+\t\tif (sit9531x_prio_src_canon(sitdev, srcs[slot]) == input_idx)\n+\t\t\treturn 0;\n+\n+\tfor (slot = 0; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++) {\n+\t\tsrc = srcs[slot] \u0026 SIT9531X_PRIO_NIBBLE_MASK;\n+\t\tsrc_canon = sit9531x_prio_src_canon(sitdev, src);\n+\t\tif (!sit9531x_prio_src_usable(src))\n+\t\t\tcontinue;\n+\n+\t\tseen[src_canon]++;\n+\t}\n+\n+\t/*\n+\t * A slot whose code names no usable source -- a reserved value, or\n+\t * one past the inputs this variant has -- is free space, and taking\n+\t * it costs nothing. Prefer it over displacing a real reference.\n+\t */\n+\tfor (slot = SIT9531X_PRIO_MAX_SLOTS; slot-- \u003e 0;) {\n+\t\tsrc = srcs[slot] \u0026 SIT9531X_PRIO_NIBBLE_MASK;\n+\t\tif (!sit9531x_prio_src_usable(src)) {\n+\t\t\treplace = slot;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/* Otherwise take the last slot holding a source listed twice. */\n+\tfor (slot = SIT9531X_PRIO_MAX_SLOTS;\n+\t replace == SIT9531X_PRIO_MAX_SLOTS \u0026\u0026 slot-- \u003e 0;) {\n+\t\tsrc = srcs[slot] \u0026 SIT9531X_PRIO_NIBBLE_MASK;\n+\t\tsrc_canon = sit9531x_prio_src_canon(sitdev, src);\n+\t\tif (!sit9531x_prio_src_usable(src))\n+\t\t\tcontinue;\n+\n+\t\tif (seen[src_canon] \u003e 1) {\n+\t\t\treplace = slot;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (replace == SIT9531X_PRIO_MAX_SLOTS)\n+\t\treturn -ENOSPC;\n+\n+\tsrcs[replace] = input_idx;\n+\n+\treturn sit9531x_prio_table_commit(sitdev, pll_idx, srcs);\n+}\n+\n+/* Per-slot DIVO base register offsets (6 slots per page) */\n+static const u8 clkout_odr_divn_base[] = {\n+\t0x14, 0x24, 0x34, 0x44, 0x54, 0x64\n+};\n+\n+/* XO doubler register */\n+#define SIT9531X_REG_XO2_GENERIC\t\tSIT9531X_REG(0x00, 0x2D)\n+#define SIT9531X_XO_DOUBLER_ENB_BIT\t\t7 /* inverted: 0 = enabled */\n+\n+/* VCO frequency bands (Hz) */\n+#define SIT9531X_FVCO_LOWBAND_MIN\t\t4915200000ULL\n+#define SIT9531X_FVCO_LOWBAND_MAX\t\t5898240000ULL\n+#define SIT9531X_FVCO_HIGHBAND_MIN\t\t6875000000ULL\n+#define SIT9531X_FVCO_HIGHBAND_MAX\t\t7812500000ULL\n+\n+/* The output divider is a 34-bit field */\n+#define SIT9531X_DIVO_MAX\t\t\tGENMASK_ULL(33, 0)\n+\n+/*\n+ * sit9531x_is_xo_doubler_enabled - check if Fref doubler is active\n+ *\n+ * Register 0x2D bit 7 is active-low: 0 = doubler enabled, 1 = disabled.\n+ *\n+ * Return: 1 if enabled, 0 if disabled, \u003c0 on error\n+ */\n+static int sit9531x_is_xo_doubler_enabled(struct sit9531x_dev *sitdev)\n+{\n+\tu8 val;\n+\tint rc;\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_XO2_GENERIC, \u0026val);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\treturn (~val \u003e\u003e SIT9531X_XO_DOUBLER_ENB_BIT) \u0026 1u;\n+}\n+\n+/*\n+ * sit9531x_dbg_sample - latch and read a signal pathway debug sample\n+ * @sitdev:\tdevice pointer\n+ * @pll_idx:\tPLL index (0-3)\n+ * @read_code:\twhich tap of the pathway to sample\n+ * @low_freq_clk: sample with the slow debug clock, which taps below\n+ *\t\t200 kHz need\n+ * @buf:\tresult, least significant byte first\n+ * @len:\tbytes to read, at most SIT9531X_DBG_DATA_BYTES\n+ *\n+ * Return: 0 on success, \u003c0 on error\n+ */\n+static int sit9531x_dbg_sample(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 read_code, bool low_freq_clk,\n+\t\t\t u8 *buf, unsigned int len)\n+{\n+\tunsigned int i;\n+\tint rc, lock_rc;\n+\tu8 v;\n+\n+\tif (len \u003e SIT9531X_DBG_DATA_BYTES)\n+\t\treturn -EINVAL;\n+\n+\trc = sit9531x_write_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_DEBUG,\n+\t\t\t\t SIT9531X_PLL_DEBUG_UNLOCK);\n+\tif (rc)\n+\t\tgoto relock;\n+\n+\t/*\n+\t * Select the debug clock this tap needs. The device never clears\n+\t * the bit, so a read that left it to whatever the previous one set\n+\t * would depend on the order the taps happened to be read in. Taps\n+\t * below 200 kHz need the slow clock; the divider taps do not.\n+\t */\n+\trc = sit9531x_update_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_WRITE_CODE,\n+\t\t\t\t SIT9531X_DBG_LOW_FREQ_CLK_BIT,\n+\t\t\t\t low_freq_clk ?\n+\t\t\t\t SIT9531X_DBG_LOW_FREQ_CLK_BIT : 0);\n+\tif (rc)\n+\t\tgoto relock;\n+\n+\trc = sit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_READ_CODE, read_code);\n+\tif (rc)\n+\t\tgoto relock;\n+\n+\t/*\n+\t * Reading the trigger latches a sample of the selected tap. Read it\n+\t * three times, as the documented phase-difference procedure does and as\n+\t * sit9531x_phase_offset_read() already did: a single read returns\n+\t * the previous latch, so a caller sampling repeatedly gets the same\n+\t * value back however much the tap has moved.\n+\t */\n+\tfor (i = 0; i \u003c SIT9531X_DBG_LATCH_READS; i++) {\n+\t\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_DBG_TRIGGER, \u0026v);\n+\t\tif (rc)\n+\t\t\tgoto relock;\n+\t}\n+\n+\tfor (i = 0; i \u003c len; i++) {\n+\t\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_DBG_DATA_0 + i,\n+\t\t\t\t\t \u0026buf[i]);\n+\t\tif (rc)\n+\t\t\tgoto relock;\n+\t}\n+\n+\trc = 0;\n+\n+relock:\n+\t/*\n+\t * Close the debug window again. The key register opens every debug\n+\t * register on this PLL while it holds the unlock value, and these\n+\t * samples run on ordinary monitoring paths, so leaving it open would\n+\t * unlock the block for as long as the device runs.\n+\t */\n+\tlock_rc = sit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\tSIT9531X_PLL_REG_DEBUG,\n+\t\t\t\t\tSIT9531X_PLL_DEBUG_LOCK);\n+\tif (lock_rc \u0026\u0026 !rc)\n+\t\trc = lock_rc;\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * DIVN as a fixed-point value: int_part plus fracn/fracd, carried with\n+ * SIT9531X_DIVN_SCALE steps per unit. The scale keeps a whole DIVN\n+ * well inside s64 while resolving far below the parts-per-trillion the\n+ * frequency offset is reported in.\n+ */\n+static s64 sit9531x_divn_fixed(u32 int_part, s64 fracn, u64 fracd)\n+{\n+\ts64 whole = (s64)int_part * SIT9531X_DIVN_SCALE;\n+\tu64 frac;\n+\n+\tif (!fracd)\n+\t\treturn whole;\n+\n+\tfrac = mul_u64_u64_div_u64(abs(fracn), SIT9531X_DIVN_SCALE, fracd);\n+\n+\treturn fracn \u003c 0 ? whole - (s64)frac : whole + (s64)frac;\n+}\n+\n+/*\n+ * sit9531x_divn_static - read the configured DIVN of a PLL\n+ * @sitdev:\tdevice pointer\n+ * @pll_idx:\tPLL index (0-3)\n+ * @divn:\tresult, fixed point as per sit9531x_divn_fixed()\n+ *\n+ * Reads PLL page regs 0x30 (integer part), 0x32-0x35 (numerator) and\n+ * 0x38-0x3B (denominator). The numerator is a two's complement 32-bit\n+ * value, so DIVN can sit below the integer part, and the denominator\n+ * register holds the divisor minus one.\n+ *\n+ * Return: 0 on success, \u003c0 on error\n+ */\n+static int sit9531x_divn_static(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\ts64 *divn)\n+{\n+\tu32 int_part, fracn_raw = 0, fracd_raw = 0;\n+\tu64 fracd;\n+\ts64 fracn;\n+\tint rc, i;\n+\tu8 v;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DIVN_INT, \u0026v);\n+\tif (rc)\n+\t\treturn rc;\n+\tint_part = v;\n+\n+\tfor (i = 3; i \u003e= 0; i--) {\n+\t\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_DIVN_NUM + i, \u0026v);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\t\tfracn_raw = (fracn_raw \u003c\u003c 8) | v;\n+\t}\n+\n+\tfor (i = 3; i \u003e= 0; i--) {\n+\t\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_DIVN_DEN + i, \u0026v);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\t\tfracd_raw = (fracd_raw \u003c\u003c 8) | v;\n+\t}\n+\n+\t/*\n+\t * NUM/DEN is the fractional part of DIVN, so |NUM| is below DEN by\n+\t * construction. A pair that says otherwise did not come from a\n+\t * programmed divider, and handing it on would divide by a\n+\t * denominator small enough for the quotient to leave u64 -- which\n+\t * is a divide-error exception on x86, not a value a caller could\n+\t * reject.\n+\t */\n+\tfracn = (s32)fracn_raw;\n+\tfracd = (u64)fracd_raw + 1;\n+\tif ((u64)abs(fracn) \u003e= fracd)\n+\t\treturn -ENODATA;\n+\n+\t*divn = sit9531x_divn_fixed(int_part, fracn, fracd);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_divn_runtime - read the DIVN the digital loop is commanding\n+ * @sitdev:\tdevice pointer\n+ * @pll_idx:\tPLL index (0-3)\n+ * @divn:\tresult, fixed point as per sit9531x_divn_fixed()\n+ *\n+ * Same quantity as sit9531x_divn_static(), but sampled from the running\n+ * loop rather than from the configuration registers, and carried at a\n+ * wider precision: the numerator is 48 bits, two's complement, the\n+ * denominator 49. The integer part shares its tap with the numerator.\n+ *\n+ * The denominator is taken as it reads. The configuration register holds\n+ * the divisor minus one, and correcting for that reproduces a profile's\n+ * stated VCO exactly, to the last bit of the fraction; this tap is a wider\n+ * field sampled from the loop itself and the documented readback uses it as it\n+ * comes, so the bias is not applied here.\n+ *\n+ * The numerator and the denominator come from two separate latches:\n+ * the debug window exposes one tap at a time, so the pair can be torn\n+ * by a loop that moves between them. The divider changes by parts per\n+ * trillion between samples on a locked loop, which is below what this\n+ * measurement resolves.\n+ *\n+ * Return: 0 on success, \u003c0 on error\n+ */\n+static int sit9531x_divn_runtime(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t s64 *divn)\n+{\n+\tu8 buf[SIT9531X_DBG_DATA_BYTES];\n+\tu64 fracn_raw = 0, fracd = 0;\n+\tu32 int_part;\n+\ts64 fracn;\n+\tint rc, i;\n+\n+\trc = sit9531x_dbg_sample(sitdev, pll_idx, SIT9531X_DBG_READ_CODE_DIVN,\n+\t\t\t\t false, buf, SIT9531X_DBG_DATA_BYTES);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tfor (i = 5; i \u003e= 0; i--)\n+\t\tfracn_raw = (fracn_raw \u003c\u003c 8) | buf[i];\n+\n+\tint_part = buf[6] | ((u32)(buf[7] \u0026 SIT9531X_DIVN_RT_INT_HI_BIT) \u003c\u003c 8);\n+\n+\trc = sit9531x_dbg_sample(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_DBG_READ_CODE_DIVN_DEN, false, buf,\n+\t\t\t\t SIT9531X_DBG_DATA_BYTES);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tfor (i = 5; i \u003e= 0; i--)\n+\t\tfracd = (fracd \u003c\u003c 8) | buf[i];\n+\n+\tfracd |= (u64)(buf[6] \u0026 SIT9531X_DIVN_RT_DEN_HI_BIT) \u003c\u003c 48;\n+\n+\tfracn = sign_extend64(fracn_raw, SIT9531X_DIVN_RT_NUM_BITS - 1);\n+\n+\t/*\n+\t * sit9531x_divn_fixed() drops the fractional part when the\n+\t * denominator is zero. That is right for a configuration register\n+\t * that was never programmed, but a running loop reading zero means\n+\t * the sample is unusable, and returning the whole part alone would\n+\t * put a wrong DIVN into the frequency offset without saying so.\n+\t *\n+\t * A numerator at or above the denominator is not a fraction either,\n+\t * and would divide by a denominator small enough for the quotient\n+\t * to leave u64 -- a divide-error exception on x86 rather than a\n+\t * value sit9531x_get_fvco() could reject.\n+\t */\n+\tif (!fracd || (u64)abs(fracn) \u003e= fracd)\n+\t\treturn -ENODATA;\n+\t*divn = sit9531x_divn_fixed(int_part, fracn, fracd);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * sit9531x_pll_ffo_ppt - fractional frequency offset of a PLL's reference\n+ * @sitdev:\tdevice pointer\n+ * @pll_idx:\tPLL index (0-3)\n+ * @ffo:\tresult in parts per trillion\n+ *\n+ * A locked PLL commands whatever DIVN keeps its VCO tracking the\n+ * reference. How far that sits from the configured DIVN is how far the\n+ * reference sits from the local oscillator, which is the fractional\n+ * frequency offset the DPLL ABI reports for the pin feeding the device.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ *\n+ * Return: 0 on success, \u003c0 on error. -ENODATA covers every reason the\n+ * ratio cannot be formed: a DIVN that was never programmed, a runtime\n+ * sample that is not a running loop, and a configured divider below one\n+ * whole unit.\n+ */\n+int sit9531x_pll_ffo_ppt(struct sit9531x_dev *sitdev, u8 pll_idx, s64 *ffo)\n+{\n+\ts64 configured, running, delta;\n+\tu64 magnitude;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\n+\trc = sit9531x_divn_static(sitdev, pll_idx, \u0026configured);\n+\tif (rc)\n+\t\treturn rc;\n+\t/*\n+\t * Scaling by a divider far below one whole cycle overflows the\n+\t * 64-bit product and comes back as ~0, which would be reported\n+\t * as a plausible offset. A DIVN that small is not a running\n+\t * loop, so treat it as no measurement.\n+\t */\n+\tif (configured \u003c SIT9531X_DIVN_SCALE)\n+\t\treturn -ENODATA;\n+\n+\trc = sit9531x_divn_runtime(sitdev, pll_idx, \u0026running);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tdelta = running - configured;\n+\tmagnitude = mul_u64_u64_div_u64(abs(delta), SIT9531X_PPT_PER_UNIT,\n+\t\t\t\t\t(u64)configured);\n+\n+\t*ffo = delta \u003c 0 ? -(s64)magnitude : (s64)magnitude;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_get_fvco - the VCO frequency the driver works from\n+ *\n+ * A board that describes the VCO through \"sitime,pll-fvco\" is taken at\n+ * its word and nothing is read. Otherwise Fvco = Fref * DIVN, where\n+ * DIVN comes from sit9531x_divn_static() and Fref = xtal_freq \u003c\u003c\n+ * doubler. DIVN is the steady-state Fvco/Fref target programmed by the\n+ * NVM blob and is authoritative in both free-run and sync modes; the\n+ * result is clamped to the band the PLL runs in, so every caller divides\n+ * the same number.\n+ *\n+ * Return: 0 with *fvco set on success, -ENODATA when DIVN is not\n+ * programmed (dormant PLL), or the register access error. A bus\n+ * failure is never folded into the -ENODATA case, so callers can fail\n+ * a request instead of acting on a guessed rate.\n+ */\n+static int sit9531x_get_fvco(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u64 *fvco)\n+{\n+\tu64 fref, fvco_min, fvco_max;\n+\tint doubler, rc;\n+\ts64 divn;\n+\n+\t/*\n+\t * DT board-config override: some configs (e.g. an INTSYNC PLL)\n+\t * run a VCO that Fref*DIVN does not reproduce. When the board\n+\t * supplies the measured VCO, use it verbatim.\n+\t */\n+\tif (pll_idx \u003c SIT9531X_NUM_PLLS \u0026\u0026 sitdev-\u003epll_fvco[pll_idx]) {\n+\t\t*fvco = sitdev-\u003epll_fvco[pll_idx];\n+\t\treturn 0;\n+\t}\n+\n+\tif (pll_idx == 1 || pll_idx == 3) {\n+\t\t/* PLLB, PLLD: high band */\n+\t\tfvco_min = SIT9531X_FVCO_HIGHBAND_MIN;\n+\t\tfvco_max = SIT9531X_FVCO_HIGHBAND_MAX;\n+\t} else {\n+\t\t/* PLLA, PLLC: low band */\n+\t\tfvco_min = SIT9531X_FVCO_LOWBAND_MIN;\n+\t\tfvco_max = SIT9531X_FVCO_LOWBAND_MAX;\n+\t}\n+\n+\trc = sit9531x_divn_static(sitdev, pll_idx, \u0026divn);\n+\tif (rc)\n+\t\treturn rc;\n+\tif (divn \u003c= 0)\n+\t\treturn -ENODATA;\n+\n+\tdoubler = sit9531x_is_xo_doubler_enabled(sitdev);\n+\tif (doubler \u003c 0)\n+\t\treturn doubler;\n+\n+\tfref = (u64)sitdev-\u003extal_freq \u003c\u003c doubler;\n+\n+\t*fvco = mul_u64_u64_div_u64(fref, (u64)divn, SIT9531X_DIVN_SCALE);\n+\n+\t/*\n+\t * A DIVN of less than one whole cycle passes the check above and\n+\t * still truncates the product to zero. Callers divide by this, so\n+\t * report the unprogrammed divider it describes rather than handing\n+\t * back a zero denominator.\n+\t */\n+\tif (!*fvco)\n+\t\treturn -ENODATA;\n+\n+\t/*\n+\t * The bands bound what the VCO can physically run at, and a rate\n+\t * derived from registers the loaded configuration may never have\n+\t * programmed can fall outside them. Clamp rather than refuse:\n+\t * the readback is the only estimate available, and refusing would\n+\t * make every output unprogrammable on such a part. Clamping here\n+\t * rather than in the divider calculation keeps the rate a frequency\n+\t * get reports and the rate a frequency set divides the same one.\n+\t */\n+\tif (*fvco \u003c fvco_min)\n+\t\t*fvco = fvco_min;\n+\telse if (*fvco \u003e fvco_max)\n+\t\t*fvco = fvco_max;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_output_phase_flush - flush the output phase of a PLL\n+ *\n+ * Fires the chip's on-demand phase-flush (PHFL) so every output divider\n+ * of @pll_idx restarts aligned to the PLL phase. Without it a rewritten\n+ * DIVO keeps counting from an arbitrary point and the output edge lands\n+ * with a persistent offset against the tracked reference (only a power\n+ * cycle realigned it).\n+ *\n+ * The sequence mirrors the documented procedure: arm the on-demand PHFL and\n+ * latch it with the PLL-page small-change update, then select the\n+ * in-register phase trigger on Page 0 and pulse it. The Page 0 trigger\n+ * register is touched read-modify-write so the unrelated OEb bits are\n+ * preserved.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)\n+{\n+\tu8 ctrl, orig;\n+\tint rc, ret;\n+\n+\t/* Arm the on-demand phase-flush on the PLL page. */\n+\trc = sit9531x_update_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_PHFL_CTRL,\n+\t\t\t\t SIT9531X_PLL_PHFL_ON_DEMAND_EN,\n+\t\t\t\t SIT9531X_PLL_PHFL_ON_DEMAND_EN);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/*\n+\t * Latch it with the PLL small-change update. Written whole, like\n+\t * every other issue of this directive: the register is a command\n+\t * register, and a read-modify-write skips the write entirely when\n+\t * the bit still reads back set from the previous command.\n+\t */\n+\trc = sit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_SMALL_UPDATE,\n+\t\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tif (rc)\n+\t\tgoto disarm;\n+\n+\t/*\n+\t * Select the in-register phase trigger, preserving the OEb bits.\n+\t * Remember the original register value (with the trigger de-asserted)\n+\t * so the trigger-source select can be restored once the pulse has\n+\t * fired.\n+\t */\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, \u0026ctrl);\n+\tif (rc)\n+\t\tgoto disarm;\n+\n+\torig = ctrl \u0026 ~SIT9531X_DIVO_PHASE_TRIG;\n+\tctrl = orig | SIT9531X_DIVO_PHASE_SEL_REG;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, ctrl);\n+\tif (rc)\n+\t\tgoto disarm;\n+\n+\t/*\n+\t * Pulse the phase trigger. No explicit delay is needed between the\n+\t * set and clear writes: each I2C transaction takes far longer than\n+\t * any minimum pulse width.\n+\t */\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1,\n+\t\t\t ctrl | SIT9531X_DIVO_PHASE_TRIG);\n+\n+\t/*\n+\t * Restore the original trigger-source select. The pulse above has\n+\t * already latched the flush, so a one-shot flush must not leave the\n+\t * phase trigger permanently pinned to the in-register source. This\n+\t * runs even when the pulse write failed, otherwise a failed flush\n+\t * would keep a hardware trigger source hijacked; the restore error\n+\t * is only surfaced when it would not mask the pulse failure.\n+\t */\n+\tret = sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, orig);\n+\tif (ret \u0026\u0026 !rc)\n+\t\trc = ret;\n+\n+disarm:\n+\t/*\n+\t * Disarm the on-demand flush enable armed above. Leaving it set\n+\t * would let a later assertion of the restored trigger source\n+\t * re-flush every output divider of this PLL, which is exactly the\n+\t * persistent side effect the one-shot sequence must not have.\n+\t */\n+\tret = sit9531x_update_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_PHFL_CTRL,\n+\t\t\t\t SIT9531X_PLL_PHFL_ON_DEMAND_EN, 0);\n+\tif (!ret)\n+\t\tret = sit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_SMALL_UPDATE,\n+\t\t\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tif (ret \u0026\u0026 !rc)\n+\t\trc = ret;\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_output_divo_calc - work out an output's divider and its VCO\n+ *\n+ * Separated from the write so a caller that programs more than the\n+ * divider in one sequence can compute the value before it enters the\n+ * programming state.\n+ */\n+static int sit9531x_output_divo_calc(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t\t u8 pll_idx, u64 frequency, u64 *fvco_out,\n+\t\t\t\t u64 *divo_out)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tu64 fvco, divo;\n+\tint rc;\n+\n+\tif (out_idx \u003e= info-\u003enum_outputs || pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\n+\tif (!frequency)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * The core validates the request against the supported ranges with\n+\t * the value narrowed to u32 but hands the full u64 down, so a value\n+\t * like U32_MAX + 1 Hz validates as 1 Hz. Reject anything that does\n+\t * not fit the narrowed width the validation actually covered.\n+\t */\n+\tif (frequency \u003e U32_MAX)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * sit9531x_get_fvco() returns the board override verbatim and a\n+\t * register-derived rate clamped to the PLL's band, so a frequency\n+\t * get and a frequency set divide the same number. A VCO that\n+\t * cannot be read fails the request: programming a divider from a\n+\t * guessed rate would put the output far from what was asked for\n+\t * while reporting success.\n+\t */\n+\trc = sit9531x_get_fvco(sitdev, pll_idx, \u0026fvco);\n+\tif (rc)\n+\t\treturn rc == -ENODATA ? -ENODEV : rc;\n+\n+\t/*\n+\t * Round to nearest rather than down: flooring picks the worse of the\n+\t * two adjacent dividers whenever the remainder is above half the\n+\t * request.\n+\t */\n+\tdivo = div64_u64(fvco + frequency / 2, frequency);\n+\tif (!divo)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * DIVO is a 34-bit field. With a band-clamped Fvco this cannot\n+\t * overflow, but a DT Fvco override is taken verbatim, so guard the\n+\t * field width rather than silently truncating the divider.\n+\t */\n+\tif (divo \u003e SIT9531X_DIVO_MAX)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * The output divider is an integer divider of the VCO, so the only\n+\t * rates the part can make are Fvco/N. An output pin that lists no\n+\t * supported frequencies advertises a continuous range, because the\n+\t * divisors cannot be enumerated ahead of a known Fvco, so a request\n+\t * for a rate between two of them arrives here. Refuse it: running\n+\t * the output at the nearest divider instead and reporting success\n+\t * would leave the pin several percent off what was asked for with\n+\t * nothing saying so.\n+\t */\n+\tif (div64_u64(fvco, divo) != frequency) {\n+\t\tdev_dbg(sitdev-\u003edev,\n+\t\t\t\"out%u: %llu Hz is not Fvco/N (Fvco=%llu, nearest %llu Hz)\\n\",\n+\t\t\tout_idx, frequency, fvco, div64_u64(fvco, divo));\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tdev_dbg(sitdev-\u003edev,\n+\t\t\"out%u: Fvco=%llu freq=%llu DIVO=%llu (effective %llu Hz)\\n\",\n+\t\tout_idx, fvco, frequency, divo, div64_u64(fvco, divo));\n+\n+\t*fvco_out = fvco;\n+\t*divo_out = divo;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_output_divo_write - write the five DIVO bytes of an output\n+ *\n+ * The caller must already be in the programming state. Bytes written\n+ * before a failure are put back, so the output keeps the divider it had\n+ * rather than a mixture of the two.\n+ */\n+static int sit9531x_output_divo_write(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t\t u64 divo)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tu8 slot, page, base_reg, divo_bytes[5], old_bytes[5], msb_old;\n+\tint rc, j, rb_rc;\n+\tu8 written = 0;\n+\n+\t/* Map output index to physical slot */\n+\tslot = info-\u003eclkout_map[out_idx];\n+\n+\t/* Determine page and per-page slot register */\n+\tif (slot \u003e SIT9531X_PAGE_OUTSYS0_SLOT_MAX)\n+\t\tpage = SIT9531X_PAGE_OUTSYS1;\n+\telse\n+\t\tpage = SIT9531X_PAGE_OUTSYS0;\n+\tbase_reg = clkout_odr_divn_base[slot % 6];\n+\n+\tdivo_bytes[0] = (divo \u003e\u003e 0) \u0026 0xFF;\n+\tdivo_bytes[1] = (divo \u003e\u003e 8) \u0026 0xFF;\n+\tdivo_bytes[2] = (divo \u003e\u003e 16) \u0026 0xFF;\n+\tdivo_bytes[3] = (divo \u003e\u003e 24) \u0026 0xFF;\n+\tdivo_bytes[4] = (divo \u003e\u003e 32) \u0026 0x03; /* only bits [1:0] */\n+\n+\tfor (j = 0; j \u003c 5; j++) {\n+\t\trc = sit9531x_read_u8(sitdev,\n+\t\t\t\t SIT9531X_REG(page, base_reg - j),\n+\t\t\t\t \u0026old_bytes[j]);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\t}\n+\n+\tmsb_old = old_bytes[4];\n+\tdivo_bytes[4] |= msb_old \u0026 0xFC;\n+\n+\tfor (j = 0; j \u003c 5; j++) {\n+\t\trc = sit9531x_write_u8(sitdev,\n+\t\t\t\t SIT9531X_REG(page, base_reg - j),\n+\t\t\t\t divo_bytes[j]);\n+\t\tif (rc)\n+\t\t\tgoto rollback;\n+\t\twritten++;\n+\t}\n+\n+\treturn 0;\n+\n+rollback:\n+\tfor (j = 0; j \u003c written; j++) {\n+\t\trb_rc = sit9531x_write_u8(sitdev,\n+\t\t\t\t\t SIT9531X_REG(page, base_reg - j),\n+\t\t\t\t\t old_bytes[j]);\n+\t\tif (rb_rc) {\n+\t\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\t\"out%u: DIVO rollback failed (%d), the divider is part old and part new\\n\",\n+\t\t\t\tout_idx, rb_rc);\n+\t\t\tif (!rc)\n+\t\t\t\trc = rb_rc;\n+\t\t}\n+\t}\n+\n+\treturn rc;\n+}\n+\n+/**\n+ * sit9531x_output_phase_read - read an output's programmed delay back\n+ * @sitdev:\tdevice pointer\n+ * @out_idx:\tlogical output index\n+ * @phase_ps:\tresult in picoseconds, always a delay (never an advance)\n+ *\n+ * The delay the chip holds is part of the profile it loads before probe,\n+ * and a rate or phase request that failed after its writes reached the\n+ * device leaves the cache describing something else. Decoding the five\n+ * PRG_RST_DELAY bytes is the only way to say what the output is really\n+ * doing. The registers carry an unsigned delay, so a request that was\n+ * made as an advance reads back as the equivalent delay.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ *\n+ * Return: 0 on success, \u003c0 on error\n+ */\n+int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t s32 *phase_ps)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tu8 bytes[5], page, base, slot, fine, i;\n+\tu64 coarse = 0, fvco, ps;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (out_idx \u003e= info-\u003enum_outputs)\n+\t\treturn -EINVAL;\n+\n+\trc = sit9531x_get_fvco(sitdev, sitdev-\u003eout[out_idx].pll_idx, \u0026fvco);\n+\tif (rc)\n+\t\treturn rc == -ENODATA ? -ENODEV : rc;\n+\n+\tslot = info-\u003eclkout_map[out_idx];\n+\tpage = (slot \u003e SIT9531X_PAGE_OUTSYS0_SLOT_MAX) ?\n+\t SIT9531X_PAGE_OUTSYS1 : SIT9531X_PAGE_OUTSYS0;\n+\tbase = SIT9531X_OUT_PRG_DELAY_BASE +\n+\t SIT9531X_OUT_PRG_SLOT_STRIDE * (slot % 6);\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(bytes); i++) {\n+\t\trc = sit9531x_read_u8(sitdev, SIT9531X_REG(page, base + i),\n+\t\t\t\t \u0026bytes[i]);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\t}\n+\n+\tfine = (bytes[0] \u0026 SIT9531X_OUT_PRG_FINE_MASK) \u003e\u003e\n+\t SIT9531X_OUT_PRG_FINE_SHIFT;\n+\tcoarse = (u64)(bytes[0] \u0026 SIT9531X_OUT_PRG_COARSE_HI_MASK) \u003c\u003c 32;\n+\tcoarse |= (u64)bytes[1] \u003c\u003c 24;\n+\tcoarse |= (u64)bytes[2] \u003c\u003c 16;\n+\tcoarse |= (u64)bytes[3] \u003c\u003c 8;\n+\tcoarse |= bytes[4];\n+\n+\tps = mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);\n+\tps += (u64)fine * SIT9531X_OUT_PRG_FINE_STEP_PS;\n+\n+\t*phase_ps = (s32)min_t(u64, ps, S32_MAX);\n+\n+\treturn 0;\n+}\n+\n+int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t u8 pll_idx, u64 frequency)\n+{\n+\tu64 fvco, divo;\n+\tint rc, ret;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\trc = sit9531x_output_divo_calc(sitdev, out_idx, pll_idx, frequency,\n+\t\t\t\t \u0026fvco, \u0026divo);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_prg_enter(sitdev);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_output_divo_write(sitdev, out_idx, divo);\n+\t/*\n+\t * Step 4: NVM update + loop lock. Always run prg_commit() so the chip\n+\t * leaves the PRG_CMD state with the output loops re-locked, even when a\n+\t * write above failed; keep the first error to return. It also carries\n+\t * the required post-lock settling sleep.\n+\t */\n+\tret = sit9531x_prg_commit(sitdev);\n+\tif (ret \u0026\u0026 !rc)\n+\t\trc = ret;\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/*\n+\t * Step 5: flush the PLL's output phase so the new DIVO starts\n+\t * aligned instead of keeping the arbitrary phase the divider\n+\t * happened to be at.\n+\t */\n+\t/*\n+\t * The divider is committed by this point, so the part is already\n+\t * running at the new rate. A flush that fails leaves the output\n+\t * divider on its old phase, which is a realignment that did not\n+\t * happen rather than a rate that did not change -- and reporting a\n+\t * failure would be doubly wrong, because the core asks for the\n+\t * current rate first and would drop an identical retry.\n+\t */\n+\trc = sit9531x_output_phase_flush(sitdev, pll_idx);\n+\tif (rc) {\n+\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t \"out%u: rate changed but the divider phase was not realigned (%d)\\n\",\n+\t\t\t out_idx, rc);\n+\t\trc = 0;\n+\t}\n+\n+\tsitdev-\u003eout[out_idx].freq = div64_u64(fvco, divo);\n+\n+\t/*\n+\t * The programmed reset delay counts VCO cycles against the output\n+\t * period in force when it was written, so a rate change silently\n+\t * re-times a previously requested phase adjust. Re-encode the\n+\t * cached picosecond request against the new rate.\n+\t *\n+\t * Keyed off whether a delay was ever programmed rather than off the\n+\t * cached value: quantization can leave a whole period in the\n+\t * registers, which is the same phase and caches as zero, and that\n+\t * still has to be re-timed when the period changes.\n+\t */\n+\tif (sitdev-\u003eout[out_idx].phase_armed) {\n+\t\ts32 phase_ps = sitdev-\u003eout[out_idx].phase_adj;\n+\t\tint ph_rc;\n+\n+\t\t/*\n+\t\t * The rate is already programmed and latched at this point.\n+\t\t * Failing the request for a re-timing that did not take\n+\t\t * would report a frequency set that did not happen, and the\n+\t\t * core drops an identical retry because it asks the driver\n+\t\t * for the current rate first -- which is the new one. Say\n+\t\t * what went wrong and mark the delay for a read-back\n+\t\t * instead.\n+\t\t */\n+\t\tph_rc = sit9531x_output_phase_adjust_set(sitdev, out_idx,\n+\t\t\t\t\t\t\t phase_ps);\n+\t\tif (ph_rc) {\n+\t\t\tsitdev-\u003eout[out_idx].phase_stale = true;\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"out%u: rate changed but the phase adjust was not re-timed (%d)\\n\",\n+\t\t\t\t out_idx, ph_rc);\n+\t\t}\n+\t}\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_output_freq_get - read output clock frequency from hardware\n+ * @out_idx:\toutput index (0-N for this chip variant)\n+ * @frequency:\toutput frequency in Hz\n+ *\n+ * Reads the 34-bit DIVO divider back from the output system registers\n+ * and computes the live output frequency as Fvco / DIVO. This stays\n+ * correct even when the divider was reprogrammed behind the driver's\n+ * back (e.g. by a direct-I2C userspace tool), where the cached value\n+ * would be stale.\n+ *\n+ * The cached output state is refreshed with the computed value.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ *\n+ * Return: 0 on success, -ENODEV when the output divider or VCO rate\n+ *\t is not resolvable, \u003c0 on register access error\n+ */\n+int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t u64 *frequency)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tu8 slot, page, base_reg, pll_idx, v;\n+\tu64 fvco, divo = 0;\n+\tint rc, j;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (out_idx \u003e= info-\u003enum_outputs)\n+\t\treturn -EINVAL;\n+\n+\tpll_idx = sitdev-\u003eout[out_idx].pll_idx;\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -ENODEV;\n+\n+\trc = sit9531x_get_fvco(sitdev, pll_idx, \u0026fvco);\n+\tif (rc)\n+\t\treturn rc == -ENODATA ? -ENODEV : rc;\n+\n+\tslot = info-\u003eclkout_map[out_idx];\n+\tif (slot \u003e SIT9531X_PAGE_OUTSYS0_SLOT_MAX)\n+\t\tpage = SIT9531X_PAGE_OUTSYS1;\n+\telse\n+\t\tpage = SIT9531X_PAGE_OUTSYS0;\n+\tbase_reg = clkout_odr_divn_base[slot % 6];\n+\n+\tfor (j = 4; j \u003e= 0; j--) {\n+\t\trc = sit9531x_read_u8(sitdev,\n+\t\t\t\t SIT9531X_REG(page, base_reg - j), \u0026v);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\t\tif (j == 4)\n+\t\t\tv \u0026= 0x03;\n+\t\tdivo = (divo \u003c\u003c 8) | v;\n+\t}\n+\n+\tif (!divo)\n+\t\treturn -ENODEV;\n+\n+\t*frequency = div64_u64(fvco, divo);\n+\tsitdev-\u003eout[out_idx].freq = *frequency;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Phase adjust (PRG_RST_DELAY register-based).\n+ *\n+ * The chip exposes a per-output 34-bit coarse delay measured in VCO\n+ * clock periods plus a 3-bit fine delay in fixed 30 ps steps. The\n+ * five bytes PROG6..PROG2 hold the field across registers:\n+ * base + 0 PROG6 [7:5] OPSTG_VCASC_BUMP (preserved via RMW)\n+ * [4:2] PRG_RST_FINE_DELAY\n+ * [1:0] PRG_RST_DELAY[33:32]\n+ * base + 1 PROG5 PRG_RST_DELAY[31:24]\n+ * base + 2 PROG4 PRG_RST_DELAY[23:16]\n+ * base + 3 PROG3 PRG_RST_DELAY[15:8]\n+ * base + 4 PROG2 PRG_RST_DELAY[7:0]\n+ *\n+ * Slots 0-5 live on Page 3, slots 6-11 on Page 4, with each slot's\n+ * block at base = 0x15 + 16 * (slot % 6); the slot is the physical\n+ * output position from clkout_map[], not the logical output index.\n+ *\n+ * The chip only supports unsigned positive delay. Requests are folded\n+ * modulo one output period: positive delays wrap naturally and a negative\n+ * phase adjustment (advance) is rendered as (T_out - |phase|).\n+ */\n+\n+int sit9531x_output_phase_adjust_set(struct sit9531x_dev *sitdev,\n+\t\t\t\t u8 out_idx, s32 phase_ps)\n+{\n+\tconst struct sit9531x_chip_info *info = sitdev-\u003einfo;\n+\tu64 abs_ps, fvco, coarse = 0, coarse_ps, t_out_ps;\n+\ts64 phase_norm_ps = 0;\n+\tu8 page, base, prog6_val, fine = 0;\n+\tu8 old_bytes[5], new_bytes[5], i;\n+\tu8 pll_idx, slot;\n+\tu64 freq;\n+\tint rc, ret, rb_rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (out_idx \u003e= info-\u003enum_outputs)\n+\t\treturn -EINVAL;\n+\n+\tpll_idx = sitdev-\u003eout[out_idx].pll_idx;\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\n+\tfreq = sitdev-\u003eout[out_idx].freq;\n+\tif (!freq) {\n+\t\t/*\n+\t\t * The cache is only seeded by a DT frequency list or an\n+\t\t * earlier get/set; a board without supported-frequencies-hz\n+\t\t * would otherwise get -EINVAL on every phase request forever.\n+\t\t * Read the effective rate back from the divider chain.\n+\t\t */\n+\t\trc = sit9531x_output_freq_get(sitdev, out_idx, \u0026freq);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\t\tif (!freq)\n+\t\t\treturn -EINVAL;\n+\t}\n+\n+\trc = sit9531x_get_fvco(sitdev, pll_idx, \u0026fvco);\n+\tif (rc)\n+\t\treturn rc == -ENODATA ? -ENODEV : rc;\n+\n+\tt_out_ps = div64_u64(1000000000000ULL, freq);\n+\tif (!t_out_ps)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * Convert to unsigned absolute delay. Both signs are folded\n+\t * modulo one period: positive delays wrap naturally, negative\n+\t * delays are rendered as T_out - |phase|. abs() is safe here\n+\t * because the core rejects anything outside the advertised phase\n+\t * range, which is +/-1 ms. div64_u64_rem() rather than the %\n+\t * operator: a 64-bit modulo has no compiler helper on 32-bit\n+\t * targets and leaves the module with an undefined __umoddi3.\n+\t */\n+\tabs_ps = abs(phase_ps);\n+\tdiv64_u64_rem(abs_ps, t_out_ps, \u0026abs_ps);\n+\tphase_norm_ps = phase_ps \u003c 0 ? -(s64)abs_ps : (s64)abs_ps;\n+\tabs_ps = (phase_ps \u003c 0 \u0026\u0026 abs_ps) ? t_out_ps - abs_ps : abs_ps;\n+\n+\tif (abs_ps) {\n+\t\tu64 rem_ps;\n+\n+\t\t/*\n+\t\t * coarse_cycles = abs_ps * Fvco / 1e12 ps/s.\n+\t\t * mul_u64_u64_div_u64() avoids overflow when abs_ps approaches\n+\t\t * one second of 1 PPS wrap-around.\n+\t\t */\n+\t\tcoarse = mul_u64_u64_div_u64(abs_ps, fvco, 1000000000000ULL);\n+\t\tif (coarse \u003e= (1ULL \u003c\u003c SIT9531X_OUT_PRG_COARSE_BITS))\n+\t\t\treturn -ERANGE;\n+\n+\t\t/*\n+\t\t * Fine delay = round((abs_ps - coarse * vco_period_ps) / 30 ps)\n+\t\t */\n+\t\tcoarse_ps = mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);\n+\t\trem_ps = (abs_ps \u003e coarse_ps) ? (abs_ps - coarse_ps) : 0;\n+\t\tif (rem_ps) {\n+\t\t\tu64 steps;\n+\n+\t\t\tsteps = div64_u64(rem_ps +\n+\t\t\t\t\t SIT9531X_OUT_PRG_FINE_STEP_PS / 2,\n+\t\t\t\t\t SIT9531X_OUT_PRG_FINE_STEP_PS);\n+\t\t\tif (steps \u003e SIT9531X_OUT_PRG_FINE_MAX)\n+\t\t\t\tsteps = SIT9531X_OUT_PRG_FINE_MAX;\n+\t\t\tfine = (u8)steps;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Map logical output index to the chip's physical output slot.\n+\t * On SiT95317 the eight logical outputs land on chip slots\n+\t * {0, 3, 4, 5, 7, 8, 9, 11}; on SiT95316 the map is identity.\n+\t * Page/base must address the slot, not the logical index.\n+\t */\n+\tslot = info-\u003eclkout_map[out_idx];\n+\tpage = (slot \u003e SIT9531X_PAGE_OUTSYS0_SLOT_MAX) ?\n+\t SIT9531X_PAGE_OUTSYS1 : SIT9531X_PAGE_OUTSYS0;\n+\tbase = SIT9531X_OUT_PRG_DELAY_BASE +\n+\t SIT9531X_OUT_PRG_SLOT_STRIDE * (slot % 6);\n+\n+\t/*\n+\t * The PRG_RST_DELAY bytes live in the output system, so the writes\n+\t * only take effect when made inside the PRG_CMD programming state and\n+\t * committed to the NVM shadow, exactly like sit9531x_output_freq_set().\n+\t */\n+\trc = sit9531x_prg_enter(sitdev);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(old_bytes); i++) {\n+\t\trc = sit9531x_read_u8(sitdev, SIT9531X_REG(page, base + i),\n+\t\t\t\t \u0026old_bytes[i]);\n+\t\tif (rc)\n+\t\t\tgoto commit;\n+\t}\n+\n+\t/* PROG6 RMW: preserve OPSTG_VCASC_BUMP in [7:5] */\n+\tprog6_val = old_bytes[0] \u0026 SIT9531X_OUT_PRG_OPSTG_MASK;\n+\tprog6_val |= (fine \u003c\u003c SIT9531X_OUT_PRG_FINE_SHIFT) \u0026\n+\t\t SIT9531X_OUT_PRG_FINE_MASK;\n+\tprog6_val |= (u8)((coarse \u003e\u003e 32) \u0026 SIT9531X_OUT_PRG_COARSE_HI_MASK);\n+\n+\tnew_bytes[0] = prog6_val;\n+\tnew_bytes[1] = (u8)((coarse \u003e\u003e 24) \u0026 0xFF);\n+\tnew_bytes[2] = (u8)((coarse \u003e\u003e 16) \u0026 0xFF);\n+\tnew_bytes[3] = (u8)((coarse \u003e\u003e 8) \u0026 0xFF);\n+\tnew_bytes[4] = (u8)(coarse \u0026 0xFF);\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(new_bytes); i++) {\n+\t\trc = sit9531x_write_u8(sitdev,\n+\t\t\t\t SIT9531X_REG(page, base + i),\n+\t\t\t\t new_bytes[i]);\n+\t\tif (rc)\n+\t\t\tgoto rollback;\n+\t}\n+\n+\tgoto commit;\n+\n+rollback:\n+\trb_rc = 0;\n+\tfor (i = 0; i \u003c ARRAY_SIZE(old_bytes); i++) {\n+\t\tret = sit9531x_write_u8(sitdev,\n+\t\t\t\t\tSIT9531X_REG(page, base + i),\n+\t\t\t\t\told_bytes[i]);\n+\t\tif (ret \u0026\u0026 !rb_rc)\n+\t\t\trb_rc = ret;\n+\t}\n+\tif (rb_rc) {\n+\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\"out%u: phase-adjust rollback failed (%d), the delay registers are part old and part new\\n\",\n+\t\t\tout_idx, rb_rc);\n+\t\tif (!rc)\n+\t\t\trc = rb_rc;\n+\t}\n+\n+commit:\n+\t/*\n+\t * Always leave the PRG_CMD state via prg_commit(), even on a\n+\t * mid-sequence write failure, so the output loops are re-locked rather\n+\t * than stranded unlocked; keep the first error.\n+\t */\n+\tret = sit9531x_prg_commit(sitdev);\n+\tif (ret \u0026\u0026 !rc)\n+\t\trc = ret;\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/*\n+\t * Restart the output divider phase so the freshly programmed delay is\n+\t * applied against a known edge instead of the divider's arbitrary\n+\t * running phase.\n+\t */\n+\trc = sit9531x_output_phase_flush(sitdev, pll_idx);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/*\n+\t * Cache what the registers realize, and only once every step has\n+\t * succeeded: the core drops a repeated request with the same value,\n+\t * so a cache updated by a failed call would make the retry a no-op.\n+\t *\n+\t * Quantizing to whole VCO cycles plus 30 ps steps can land a few\n+\t * picoseconds past the end of the period, which would wrap the\n+\t * subtraction below; one period is the most a delay can be.\n+\t */\n+\tcoarse_ps = mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);\n+\tabs_ps = coarse_ps + (u64)fine * SIT9531X_OUT_PRG_FINE_STEP_PS;\n+\tif (abs_ps \u003e t_out_ps)\n+\t\tabs_ps = t_out_ps;\n+\tif (phase_norm_ps \u003c 0)\n+\t\tsitdev-\u003eout[out_idx].phase_adj =\n+\t\t\tabs_ps ? -(s32)(t_out_ps - abs_ps) : 0;\n+\telse\n+\t\t/*\n+\t\t * The cache is an s32 because that is what the ABI carries.\n+\t\t * A delay is bounded by the output period, which on a slow\n+\t\t * output is wider than that, so bound the cast. The negative\n+\t\t * branch above needs no bound: what it stores is the advance\n+\t\t * that was asked for, and that came in as an s32.\n+\t\t */\n+\t\tsitdev-\u003eout[out_idx].phase_adj = (s32)min(abs_ps,\n+\t\t\t\t\t\t\t (u64)S32_MAX);\n+\n+\t/*\n+\t * Record that a delay is programmed whatever it quantized to. A\n+\t * request that lands on a whole period caches as zero, and the rate\n+\t * change that follows still has to re-time what the registers hold.\n+\t */\n+\tsitdev-\u003eout[out_idx].phase_armed = true;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_clear_notifications - clear all notification registers\n+ *\n+ * Clears all write-1-to-clear notification registers:\n+ * - PLL outer LOL notification (Page 0, reg 0x07)\n+ * - PLL holdover freeze notification (Page 0, reg 0x0B)\n+ * - PLL inner LOL notification (Page 0, reg 0x93)\n+ * - Clock monitor XO/PLL notification (Page 0, reg 0x9E)\n+ * - Clock input notifications (Page 6, regs 0x03/0x07/0x93/0x97)\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_clear_notifications(struct sit9531x_dev *sitdev)\n+{\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\t/* Page 0x00 W1C notification registers */\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTER_LOL_NOTIF, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_HO_FREEZE_NOTIF, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_PLL_INNER_LOL_NOTIF, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_CMON_NOTIF, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/* Page 0x06 clock input monitor notifications */\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_P_NOTIF_01, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_P_NOTIF_23, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_N_NOTIF_01, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_N_NOTIF_23, 0xFF);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tdev_dbg(sitdev-\u003edev, \"All notification registers cleared\\n\");\n+\treturn 0;\n+}\n+\n+/*\n+ * INTSYNC configuration register values.\n+ * These are written to the source PLL's EXT page to enable/disable\n+ * inter-PLL synchronization (lock frequency PLL to phase PLL).\n+ */\n+struct sit9531x_intsync_reg {\n+\tu8 offset;\n+\tu8 en_val;\n+\tu8 dis_val;\n+};\n+\n+static const struct sit9531x_intsync_reg intsync_config[] = {\n+\t{ 0x2D, 0x02, 0x00 },\n+\t{ 0x50, 0x08, 0x00 },\n+\t{ 0x51, 0x04, 0x00 },\n+\t{ 0x54, 0x02, 0x00 },\n+\t{ 0x55, 0x28, 0x20 },\n+\t{ 0x5C, 0x0F, 0x00 },\n+\t{ 0x5D, 0xFF, 0x00 },\n+\t{ 0x6C, 0xDD, 0x00 },\n+};\n+\n+int sit9531x_intsync_src_detect(struct sit9531x_dev *sitdev)\n+{\n+\ts8 src = -1;\n+\tu8 global;\n+\tu8 pll, ext_page;\n+\tint rc, i;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL, \u0026global);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tif (!(global \u0026 BIT(SIT9531X_INTSYNC_EN_BIT))) {\n+\t\tsitdev-\u003eintsync_src = -1;\n+\t\treturn 0;\n+\t}\n+\n+\tfor (pll = 0; pll \u003c SIT9531X_NUM_PLLS; pll++) {\n+\t\text_page = SIT9531X_PLL_EXT_PAGE(pll);\n+\n+\t\tfor (i = 0; i \u003c ARRAY_SIZE(intsync_config); i++) {\n+\t\t\tu16 reg;\n+\t\t\tu8 val;\n+\n+\t\t\treg = SIT9531X_REG(ext_page, intsync_config[i].offset);\n+\n+\t\t\trc = sit9531x_read_u8(sitdev, reg, \u0026val);\n+\t\t\tif (rc)\n+\t\t\t\treturn rc;\n+\t\t\tif (val != intsync_config[i].en_val)\n+\t\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (i == ARRAY_SIZE(intsync_config)) {\n+\t\t\t/*\n+\t\t\t * Only one PLL can drive the net. If a second\n+\t\t\t * one matches, the registers are not describing\n+\t\t\t * a state this driver put the device in, so say\n+\t\t\t * so rather than pick silently.\n+\t\t\t */\n+\t\t\tif (src \u003c 0)\n+\t\t\t\tsrc = pll;\n+\t\t\telse\n+\t\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t\t \"PLL%c also matches the INTSYNC source pattern; keeping PLL%c\\n\",\n+\t\t\t\t\t 'A' + pll, 'A' + src);\n+\t\t}\n+\t}\n+\n+\tsitdev-\u003eintsync_src = src;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Close the debug window on a PLL's EXT page. The key register opens\n+ * every debug register on that page while it holds the unlock value.\n+ */\n+static int sit9531x_intsync_debug_lock(struct sit9531x_dev *sitdev, u8 ext_page)\n+{\n+\treturn sit9531x_write_u8(sitdev,\n+\t\t\t\t SIT9531X_REG(ext_page, SIT9531X_PLL_REG_DEBUG),\n+\t\t\t\t SIT9531X_PLL_DEBUG_LOCK);\n+}\n+\n+/*\n+ * sit9531x_intsync_enable - enable inter-PLL synchronization\n+ * @src_pll_idx: source (frequency) PLL index (0-3)\n+ *\n+ * Enables INTSYNC global bit, unlocks the source PLL's EXT page\n+ * debug registers, writes configuration, and triggers a small\n+ * update on the source PLL.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_intsync_enable(struct sit9531x_dev *sitdev, u8 src_pll_idx)\n+{\n+\tu8 ext_page, val;\n+\tint rc, lock_rc, i;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (src_pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\n+\text_page = SIT9531X_PLL_EXT_PAGE(src_pll_idx);\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL, \u0026val);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL,\n+\t\t\t val | BIT(SIT9531X_INTSYNC_EN_BIT));\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/* Small update on Page 0 */\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_GLOBAL_UPDATE,\n+\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tusleep_range(1000, 2000);\n+\tif (rc)\n+\t\tgoto relock_err;\n+\n+\t/* Unlock debug on EXT page */\n+\trc = sit9531x_write_u8(sitdev,\n+\t\t\t SIT9531X_REG(ext_page,\n+\t\t\t\t\t SIT9531X_PLL_REG_DEBUG),\n+\t\t\t SIT9531X_PLL_DEBUG_UNLOCK);\n+\tif (rc)\n+\t\tgoto relock_err;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(intsync_config); i++) {\n+\t\trc = sit9531x_write_u8(sitdev,\n+\t\t\t\t SIT9531X_REG(ext_page,\n+\t\t\t\t\t\t intsync_config[i].offset),\n+\t\t\t\t intsync_config[i].en_val);\n+\t\tif (rc)\n+\t\t\tgoto relock_err;\n+\t}\n+\n+\t/* Small update on source PLL */\n+\trc = sit9531x_write_pll_u8(sitdev, src_pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_SMALL_UPDATE,\n+\t\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tif (rc)\n+\t\tgoto relock_err;\n+\n+\trc = 0;\n+\tgoto relock;\n+\n+relock_err:\n+\tsit9531x_intsync_debug_lock(sitdev, ext_page);\n+\tgoto err_disable;\n+\n+relock:\n+\t/*\n+\t * Close the EXT page debug window the sequence opened. Nothing\n+\t * else writes the key back, so leaving it open would keep the block\n+\t * unlocked for as long as the device runs.\n+\t */\n+\tlock_rc = sit9531x_intsync_debug_lock(sitdev, ext_page);\n+\tif (lock_rc \u0026\u0026 !rc)\n+\t\trc = lock_rc;\n+\n+\treturn rc;\n+\n+err_disable:\n+\t/*\n+\t * The global enable is already set at this point. The caller only\n+\t * records the source PLL when this function succeeds, so nothing\n+\t * else will ever clear the bit: undo it here rather than leave the\n+\t * net asserted with a half-written EXT page.\n+\t */\n+\t{\n+\t\tint rollback_rc;\n+\n+\t\trollback_rc = sit9531x_intsync_disable(sitdev, src_pll_idx);\n+\t\tif (rollback_rc)\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"INTSYNC rollback failed after enable error: %d (original %d)\\n\",\n+\t\t\t\t rollback_rc, rc);\n+\t}\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_intsync_disable - disable inter-PLL synchronization\n+ * @src_pll_idx: source (frequency) PLL index (0-3)\n+ *\n+ * Clears INTSYNC global bit, writes disable values to the source\n+ * PLL's EXT page, and triggers a small update.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_intsync_disable(struct sit9531x_dev *sitdev, u8 src_pll_idx)\n+{\n+\tu8 ext_page, val;\n+\tint rc, lock_rc, i;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (src_pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\n+\text_page = SIT9531X_PLL_EXT_PAGE(src_pll_idx);\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL, \u0026val);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL,\n+\t\t\t val \u0026 ~BIT(SIT9531X_INTSYNC_EN_BIT));\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/* Small update on Page 0 */\n+\trc = sit9531x_write_u8(sitdev, SIT9531X_REG_GLOBAL_UPDATE,\n+\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tusleep_range(1000, 2000);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/* Unlock debug on EXT page */\n+\trc = sit9531x_write_u8(sitdev,\n+\t\t\t SIT9531X_REG(ext_page,\n+\t\t\t\t\t SIT9531X_PLL_REG_DEBUG),\n+\t\t\t SIT9531X_PLL_DEBUG_UNLOCK);\n+\tif (rc)\n+\t\tgoto relock;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(intsync_config); i++) {\n+\t\trc = sit9531x_write_u8(sitdev,\n+\t\t\t\t SIT9531X_REG(ext_page,\n+\t\t\t\t\t\t intsync_config[i].offset),\n+\t\t\t\t intsync_config[i].dis_val);\n+\t\tif (rc)\n+\t\t\tgoto restore_global;\n+\t}\n+\n+\t/* Small update on source PLL */\n+\trc = sit9531x_write_pll_u8(sitdev, src_pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_SMALL_UPDATE,\n+\t\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tif (rc)\n+\t\tgoto relock;\n+\n+\trc = 0;\n+\n+restore_global:\n+\t/*\n+\t * The global enable was cleared first, so a failure here leaves the\n+\t * EXT page still holding the enable pattern with nothing pointing\n+\t * at it: the source detector keys on the global bit, would report\n+\t * the net as unowned, and a retry of the disable would then\n+\t * short-circuit. Put the bit back so the state stays one the\n+\t * driver can describe and the request can be repeated.\n+\t */\n+\tif (!sit9531x_read_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL, \u0026val))\n+\t\tsit9531x_write_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL,\n+\t\t\t\t val | BIT(SIT9531X_INTSYNC_EN_BIT));\n+\n+relock:\n+\t/* Close the EXT page debug window the sequence opened. */\n+\tlock_rc = sit9531x_intsync_debug_lock(sitdev, ext_page);\n+\tif (lock_rc \u0026\u0026 !rc)\n+\t\trc = lock_rc;\n+\n+\treturn rc;\n+}\n+\n+/**\n+ * sit9531x_chan_selected_ref_read - read a PLL's active reference now\n+ * @sitdev:\tdevice pointer\n+ * @pll_idx:\tPLL index (0-3)\n+ * @ref:\tresult, logical input index of the selected reference\n+ *\n+ * chan-\u003eselected_ref is refreshed by the monitor twice a second, which is\n+ * close enough for reporting pin state but not for attributing a\n+ * measurement: the device picks its own reference, so a sample taken now\n+ * can belong to a pin the cache has not caught up with.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ *\n+ * Return: 0 on success, \u003c0 on error\n+ */\n+int sit9531x_chan_selected_ref_read(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t u8 *ref)\n+{\n+\tu8 activesel_reg, input_sel;\n+\tint rc;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\n+\tactivesel_reg = SIT9531X_PRIO_BASE_REG +\n+\t\t\tSIT9531X_PRIO_REGS_PER_PLL * pll_idx +\n+\t\t\tSIT9531X_PRIO_ACTIVESEL_OFF;\n+\trc = sit9531x_read_u8(sitdev,\n+\t\t\t SIT9531X_REG(SIT9531X_PAGE_PRIOSYS,\n+\t\t\t\t\t activesel_reg),\n+\t\t\t \u0026input_sel);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t*ref = sit9531x_hw_src_input(input_sel \u0026 SIT9531X_PRIO_NIBBLE_MASK);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_phase_offset_read - read phase difference via TDC\n+ * @phase_ps:\toutput phase difference in picoseconds\n+ *\n+ * Reads the Time-to-Digital Converter (TDC) signed 35-bit code from the\n+ * PLL page registers, then converts to picoseconds using the VCO\n+ * frequency: phase_diff = tdc_code / fvco.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+int sit9531x_phase_offset_read(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t s64 *phase_ps)\n+{\n+\tu8 v, old_write_code, old_read_code;\n+\tbool have_old = false;\n+\tint rc, lock_rc, i;\n+\tu64 fvco, mag_ps;\n+\ts64 tdc_signed;\n+\tu64 tdc_raw;\n+\tbool sign;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (pll_idx \u003e= SIT9531X_NUM_PLLS)\n+\t\treturn -EINVAL;\n+\n+\t/* Unlock the debug page so the TDC registers are accessible. */\n+\trc = sit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DEBUG,\n+\t\t\t\t SIT9531X_PLL_DEBUG_UNLOCK);\n+\tif (rc)\n+\t\tgoto relock;\n+\n+\t/*\n+\t * Remember the tap selection so it can be put back. The key\n+\t * register is re-locked below, but the mux is not part of the key:\n+\t * leaving it parked on the TDC with a slow sampling clock selected\n+\t * is a state change the caller did not ask for, and the next reader\n+\t * of a different tap would have to know to undo it.\n+\t */\n+\tif (!sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_WRITE_CODE,\n+\t\t\t\t \u0026old_write_code) \u0026\u0026\n+\t !sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_READ_CODE,\n+\t\t\t\t \u0026old_read_code))\n+\t\thave_old = true;\n+\n+\t/*\n+\t * Select the debug clock for taps below 200 kHz, then point the\n+\t * readback at the TDC. Only the one bit is touched: writing the\n+\t * modifier register whole would clear the fields belonging to\n+\t * other taps.\n+\t */\n+\trc = sit9531x_update_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_WRITE_CODE,\n+\t\t\t\t SIT9531X_DBG_LOW_FREQ_CLK_BIT,\n+\t\t\t\t SIT9531X_DBG_LOW_FREQ_CLK_BIT);\n+\tif (rc)\n+\t\tgoto relock;\n+\trc = sit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_READ_CODE,\n+\t\t\t\t SIT9531X_DBG_READ_CODE_TDC);\n+\tif (rc)\n+\t\tgoto relock;\n+\n+\t/*\n+\t * Latch a sample by reading the trigger register. A single\n+\t * read returns the previous latch, so read it three times as\n+\t * the documented phase-difference procedure does.\n+\t */\n+\tfor (i = 0; i \u003c SIT9531X_DBG_LATCH_READS; i++) {\n+\t\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_DBG_TRIGGER, \u0026v);\n+\t\tif (rc)\n+\t\t\tgoto relock;\n+\t}\n+\n+\ttdc_raw = 0;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_DATA_4, \u0026v);\n+\tif (rc)\n+\t\tgoto relock;\n+\tsign = !!(v \u0026 BIT(SIT9531X_TDC_SIGN_BIT));\n+\ttdc_raw = (u64)(v \u0026 SIT9531X_TDC_MAG_HI_MASK) \u003c\u003c 32;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_DATA_3, \u0026v);\n+\tif (rc)\n+\t\tgoto relock;\n+\ttdc_raw |= (u64)v \u003c\u003c 24;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_DATA_2, \u0026v);\n+\tif (rc)\n+\t\tgoto relock;\n+\ttdc_raw |= (u64)v \u003c\u003c 16;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_DATA_1, \u0026v);\n+\tif (rc)\n+\t\tgoto relock;\n+\ttdc_raw |= (u64)v \u003c\u003c 8;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_DATA_0, \u0026v);\n+\tif (rc)\n+\t\tgoto relock;\n+\ttdc_raw |= v;\n+\n+\t/*\n+\t * Apply sign. Per the register map the sign bit is active-high\n+\t * for a positive offset: bit set -\u003e +code, bit clear -\u003e -code.\n+\t */\n+\ttdc_signed = sign ? (s64)tdc_raw : -(s64)tdc_raw;\n+\n+\t/*\n+\t * Get VCO frequency for conversion. -ENODATA means DIVN is not\n+\t * programmed (PLL unused on this board) -- skip silently rather\n+\t * than spamming the log on every poll cycle. It is passed up as\n+\t * itself rather than as -ENODEV, which the I2C layer produces for\n+\t * an adapter that has gone away: the caller turns the dormant-PLL\n+\t * case into a zero reading, and a bus failure must not take that\n+\t * path.\n+\t */\n+\trc = sit9531x_get_fvco(sitdev, pll_idx, \u0026fvco);\n+\tif (rc) {\n+\t\tif (rc == -ENODATA)\n+\t\t\tdev_dbg(sitdev-\u003edev,\n+\t\t\t\t\"PLL%c: Fvco unknown, skip TDC\\n\",\n+\t\t\t\t'A' + pll_idx);\n+\t\tgoto relock;\n+\t}\n+\n+\t/*\n+\t * phase_diff (seconds) = tdc_code / fvco\n+\t * phase_diff (ps) = tdc_code * 1e12 / fvco\n+\t *\n+\t * mul_u64_u64_div_u64() keeps the exact Hz denominator; dividing\n+\t * by whole MHz instead would lose up to ~40 ppm of scale on a\n+\t * fractional-DIVN Fvco.\n+\t */\n+\tmag_ps = mul_u64_u64_div_u64(tdc_signed \u003c 0 ? -tdc_signed : tdc_signed,\n+\t\t\t\t 1000000000000ULL, fvco);\n+\t*phase_ps = tdc_signed \u003c 0 ? -(s64)mag_ps : (s64)mag_ps;\n+\n+\trc = 0;\n+\n+relock:\n+\tif (have_old) {\n+\t\tsit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_READ_CODE,\n+\t\t\t\t old_read_code);\n+\t\tsit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_DBG_WRITE_CODE,\n+\t\t\t\t old_write_code);\n+\t}\n+\n+\t/*\n+\t * Close the debug window again. The key register opens every debug\n+\t * register on this PLL while it holds the unlock value, and this read\n+\t * runs on every pin-get of a connected input, so leaving it open\n+\t * would mean normal monitoring permanently unlocks the block.\n+\t */\n+\tlock_rc = sit9531x_write_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\tSIT9531X_PLL_REG_DEBUG,\n+\t\t\t\t\tSIT9531X_PLL_DEBUG_LOCK);\n+\tif (lock_rc \u0026\u0026 !rc)\n+\t\trc = lock_rc;\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_ref_state_fetch - read input reference status from hardware\n+ * @index:\tlogical input index\n+ *\n+ * Reads LOS and OOF status for the given input lane from the Page 0x06\n+ * clock monitor registers. P and N lanes have separate register banks;\n+ * each register carries two input pairs nibble-packed (even pair in\n+ * bits [3:0], odd pair in [7:4]).\n+ */\n+static int sit9531x_ref_state_fetch(struct sit9531x_dev *sitdev, u8 index)\n+{\n+\tunsigned int force_reg, state_reg;\n+\tu8 pair, force, state;\n+\tstruct sit9531x_ref *ref;\n+\tint rc;\n+\n+\t/*\n+\t * The XTAL/XO reference (index SIT9531X_MAX_INPUTS) is the on-chip\n+\t * oscillator that feeds every PLL. It cannot be routed or deselected,\n+\t * so its pin is modeled as permanently connected (see\n+\t * sit9531x_dpll_xo_pin_ops) and has no receiver to gate. Only the\n+\t * routable per-lane inputs (0..num_inputs-1) are polled here.\n+\t */\n+\tif (index \u003e= SIT9531X_MAX_INPUTS)\n+\t\treturn -EINVAL;\n+\n+\tref = \u0026sitdev-\u003eref[index];\n+\tpair = sit9531x_input_pair(index);\n+\n+\t/*\n+\t * Whether the receiver is on. This has to come from the chip: it\n+\t * is the loaded configuration that decides, and without reading it\n+\t * back every input would look disabled until something called\n+\t * sit9531x_input_enable(). A lane counts as disabled only while\n+\t * the force bit overrides it to the off state; with the force bit\n+\t * clear it follows the configuration, which is the enabled case.\n+\t */\n+\tsit9531x_input_get_regs(sitdev, index, \u0026force_reg, \u0026state_reg);\n+\n+\trc = sit9531x_read_u8(sitdev, force_reg, \u0026force);\n+\tif (rc)\n+\t\treturn rc;\n+\trc = sit9531x_read_u8(sitdev, state_reg, \u0026state);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tref-\u003eenabled = !((force \u0026 BIT(pair)) \u0026\u0026 !(state \u0026 BIT(pair)));\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_input_mode_fetch - detect SE/DE configuration of an input pair\n+ * @pair:\tinput pair number (0-3)\n+ *\n+ * Reads CLKINx_INPUT_MODE and stores the detected signal mode on both\n+ * lanes of the pair. A pair with neither SE lane enabled is running\n+ * differential.\n+ */\n+static int sit9531x_input_mode_fetch(struct sit9531x_dev *sitdev, u8 pair)\n+{\n+\tenum sit9531x_signal_mode sig_mode;\n+\tu8 mode;\n+\tint rc;\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_IN_MODE(pair), \u0026mode);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tif (mode \u0026 (SIT9531X_IN_MODE_SE_P_EN | SIT9531X_IN_MODE_SE_N_EN))\n+\t\tsig_mode = SIT9531X_MODE_SE;\n+\telse\n+\t\tsig_mode = SIT9531X_MODE_DE;\n+\n+\tsitdev-\u003eref[pair * 2].sig_mode = sig_mode;\n+\tsitdev-\u003eref[pair * 2 + 1].sig_mode = sig_mode;\n+\n+\tdev_dbg(sitdev-\u003edev, \"CLKIN%u mode reg 0x%02x -\u003e %s\\n\", pair, mode,\n+\t\tsig_mode == SIT9531X_MODE_DE ? \"differential\" : \"single-ended\");\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_chan_state_fetch - read PLL channel status from hardware\n+ *\n+ * Reads lock status and mode from the PLL status register.\n+ */\n+/* Read the PLL active-state bit (PLL page reg 0x02 bit 0). */\n+static int sit9531x_pll_is_active(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t bool *active)\n+{\n+\tu8 v;\n+\tint rc;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_ACTIVE, \u0026v);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t*active = !!(v \u0026 SIT9531X_PLL_ACTIVE_BIT);\n+\n+\treturn 0;\n+}\n+\n+static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)\n+{\n+\tu8 status, outer_lol, input_sel, inner_lol, ho_freeze, activesel_reg;\n+\tstruct sit9531x_chan *chan = \u0026sitdev-\u003echan[pll_idx];\n+\tu8 srcs[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 pll_status_1;\n+\tbool active;\n+\tint rc;\n+\n+\t/*\n+\t * Whether the PLL is running at all. The loss-of-lock bit read\n+\t * below is driven by the PLL itself, so on one the loaded\n+\t * configuration leaves unused it simply stays clear and would\n+\t * otherwise read as a lock.\n+\t */\n+\trc = sit9531x_pll_is_active(sitdev, pll_idx, \u0026active);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t SIT9531X_PLL_REG_STATUS, \u0026status);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_OUTER_LOL_STATUS,\n+\t\t\t \u0026outer_lol);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/*\n+\t * Read the input source the PLL has currently selected as its\n+\t * active reference. This lives in the low nibble of the last\n+\t * register of the PLL's page-1 priority block (CLK_ACTIVESEL_PLL),\n+\t * not on the PLL page -- PLL-page 0x29 is a config register.\n+\t */\n+\tactivesel_reg = SIT9531X_PRIO_BASE_REG +\n+\t\t\tSIT9531X_PRIO_REGS_PER_PLL * pll_idx +\n+\t\t\tSIT9531X_PRIO_ACTIVESEL_OFF;\n+\trc = sit9531x_read_u8(sitdev,\n+\t\t\t SIT9531X_REG(SIT9531X_PAGE_PRIOSYS,\n+\t\t\t\t\t activesel_reg),\n+\t\t\t \u0026input_sel);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_PLL_INNER_LOL_STATUS,\n+\t\t\t \u0026inner_lol);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_HO_FREEZE_STATUS,\n+\t\t\t \u0026ho_freeze);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_read_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_STATUS_1,\n+\t\t\t\t \u0026pll_status_1);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/*\n+\t * Which sources this PLL may select. The table is configuration and\n+\t * changes only through the driver, but reading it back keeps the\n+\t * membership the pin state getters report tied to the hardware\n+\t * instead of to a value the driver maintains on the side.\n+\t */\n+\trc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tsit9531x_prio_mask_build(sitdev, pll_idx, srcs,\n+\t\t\t\t SIT9531X_PRIO_MAX_SLOTS);\n+\n+\t/* STATUS_1_GENERIC reports loss of lock, so invert it. */\n+\tchan-\u003eactive = active;\n+\tchan-\u003elocked = active \u0026\u0026 !(outer_lol \u0026 BIT(pll_idx));\n+\tchan-\u003emode = !!(status \u0026 SIT9531X_PLL_STATUS_OUTER_DIS);\n+\tchan-\u003eselected_ref =\n+\t\tsit9531x_hw_src_input(input_sel \u0026 SIT9531X_PRIO_NIBBLE_MASK);\n+\tchan-\u003einner_lol = !!(inner_lol \u0026 BIT(pll_idx));\n+\tchan-\u003eho_freeze = !!(ho_freeze \u0026 BIT(pll_idx));\n+\tchan-\u003eho_valid = !!(pll_status_1 \u0026 SIT9531X_PLL_STATUS_1_HO_VALID);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_out_state_fetch - read output status from hardware\n+ *\n+ * Reads the output PLL association from the PLL page output map\n+ * registers into out-\u003erouted / out-\u003epll_idx, and the current drive\n+ * state from the Hi-Z force bits into out-\u003eenabled. The two are\n+ * separate: routing decides whether the output gets a DPLL pin at all,\n+ * while a muted but routed output keeps its pin and reports\n+ * DPLL_PIN_STATE_DISCONNECTED until it is un-muted.\n+ */\n+static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index)\n+{\n+\tstruct sit9531x_out *out = \u0026sitdev-\u003eout[index];\n+\tu8 map_lo, map_hi, slot;\n+\tint pll_idx;\n+\tbool muted;\n+\tint rc;\n+\n+\tslot = sitdev-\u003einfo-\u003eclkout_map[index];\n+\n+\trc = sit9531x_output_mode_fetch(sitdev, index);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_output_forced_hiz(sitdev, index, \u0026muted);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tsitdev-\u003eout[index].state_stale = false;\n+\n+\t/*\n+\t * DT board-config override: the per-PLL OUTPUT_ENABLE bitmaps\n+\t * (0x27/0x28) do not unambiguously express output-\u003ePLL routing on\n+\t * every config (overlaps, and some outputs routed outside that\n+\t * path). When the board supplies an explicit map, trust it.\n+\t */\n+\tif (sitdev-\u003eout_pll_map_valid) {\n+\t\tu8 m = sitdev-\u003eout_pll_map[index];\n+\n+\t\tif (m \u003c SIT9531X_NUM_PLLS) {\n+\t\t\tout-\u003epll_idx = m;\n+\t\t\tout-\u003erouted = true;\n+\t\t\tout-\u003eenabled = !muted;\n+\t\t} else {\n+\t\t\tout-\u003epll_idx = 0;\n+\t\t\tout-\u003erouted = false;\n+\t\t\tout-\u003eenabled = false;\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\n+\t/*\n+\t * The OUT_MAP_LO/HI bitmaps are indexed by the physical slot the\n+\t * output occupies on the chip, not by the driver's logical output\n+\t * index (translated above via the chip-info clkout_map[]: identity\n+\t * on SiT95316, non-contiguous on SiT95317).\n+\t *\n+\t * Determine which PLL drives this output by checking each PLL's\n+\t * output map registers (0x27 = slots 8-11, 0x28 = slots 0-7).\n+\t */\n+\tfor (pll_idx = 0; pll_idx \u003c SIT9531X_NUM_PLLS; pll_idx++) {\n+\t\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_OUT_MAP_LO, \u0026map_lo);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\n+\t\trc = sit9531x_read_pll_u8(sitdev, pll_idx,\n+\t\t\t\t\t SIT9531X_PLL_REG_OUT_MAP_HI, \u0026map_hi);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\n+\t\tif (slot \u003c 8) {\n+\t\t\tif (map_lo \u0026 BIT(slot)) {\n+\t\t\t\tout-\u003epll_idx = pll_idx;\n+\t\t\t\tout-\u003erouted = true;\n+\t\t\t\tout-\u003eenabled = !muted;\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tif (map_hi \u0026 BIT(slot - 8)) {\n+\t\t\t\tout-\u003epll_idx = pll_idx;\n+\t\t\t\tout-\u003erouted = true;\n+\t\t\t\tout-\u003eenabled = !muted;\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/* Output not mapped to any PLL */\n+\tout-\u003epll_idx = 0;\n+\tout-\u003erouted = false;\n+\tout-\u003eenabled = false;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_ref_pll_mask_fetch - seed the input-to-PLL usage masks\n+ *\n+ * ref-\u003epll_mask is the refcount the disconnect path uses to decide when\n+ * an input receiver may be powered down: the physical input is only\n+ * disabled once the last DPLL has released it. It therefore has to\n+ * start out matching the hardware. Without this pass every mask starts\n+ * at zero, and disconnecting an input from one DPLL drops the mask to\n+ * zero and disables a receiver the other DPLLs are still locked to.\n+ *\n+ * An input is counted for a PLL when it appears in that PLL's Page-1\n+ * priority table, which is exactly the condition the connect and\n+ * disconnect callbacks maintain. Sources that are not physical inputs\n+ * (OCXO, INTSYNC) and reserved codes are skipped.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static int sit9531x_ref_pll_mask_fetch(struct sit9531x_dev *sitdev)\n+{\n+\tu8 srcs[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8 pll_idx, slot, index;\n+\tint rc;\n+\n+\tfor (pll_idx = 0; pll_idx \u003c SIT9531X_NUM_PLLS; pll_idx++) {\n+\t\trc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);\n+\t\tif (rc)\n+\t\t\treturn rc;\n+\n+\t\tfor (slot = 0; slot \u003c SIT9531X_PRIO_MAX_SLOTS; slot++) {\n+\t\t\tindex = sit9531x_hw_src_input(srcs[slot]);\n+\t\t\tif (index \u003e= sitdev-\u003einfo-\u003enum_inputs)\n+\t\t\t\tcontinue;\n+\n+\t\t\t/*\n+\t\t\t * On a differentially configured pair only the P lane\n+\t\t\t * has a DPLL pin, so that is the lane the connect and\n+\t\t\t * disconnect callbacks account for. Fold an N-lane\n+\t\t\t * table entry onto its P lane, otherwise the count\n+\t\t\t * would land on a lane nothing ever releases. The\n+\t\t\t * signaling mode is already known here:\n+\t\t\t * sit9531x_input_mode_fetch() runs first.\n+\t\t\t */\n+\t\t\tif (sit9531x_input_is_n(index) \u0026\u0026\n+\t\t\t sitdev-\u003eref[index].sig_mode == SIT9531X_MODE_DE)\n+\t\t\t\tindex--;\n+\n+\t\t\tsitdev-\u003eref[index].pll_mask |= BIT(pll_idx);\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dev_state_fetch - read all hardware state at startup\n+ *\n+ * Called once during probe to populate the initial state cache.\n+ */\n+static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev)\n+{\n+\tint rc;\n+\tu8 i;\n+\n+\t/* Detect SE/DE configuration before any per-lane access */\n+\tfor (i = 0; i \u003c sitdev-\u003einfo-\u003enum_inputs / 2; i++) {\n+\t\trc = sit9531x_input_mode_fetch(sitdev, i);\n+\t\tif (rc) {\n+\t\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\t\"Failed to fetch CLKIN%u mode: %d\\n\", i, rc);\n+\t\t\treturn rc;\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i \u003c sitdev-\u003einfo-\u003enum_inputs; i++) {\n+\t\trc = sit9531x_ref_state_fetch(sitdev, i);\n+\t\tif (rc) {\n+\t\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\t\"Failed to fetch input %u state: %d\\n\", i, rc);\n+\t\t\treturn rc;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * The priority-table read walks the Page-1 registers, so it runs\n+\t * with multiop_lock held like every other multi-register sequence.\n+\t * Nothing can race with it here -- the DPLLs are not registered and\n+\t * the monitor is not running yet -- but the page handling stays\n+\t * serialized the same way as at runtime.\n+\t */\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_ref_pll_mask_fetch(sitdev);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\tif (rc) {\n+\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\"Failed to fetch input priority tables: %d\\n\", rc);\n+\t\treturn rc;\n+\t}\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_intsync_src_detect(sitdev);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\tif (rc) {\n+\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\"Failed to detect INTSYNC source: %d\\n\", rc);\n+\t\treturn rc;\n+\t}\n+\n+\tfor (i = 0; i \u003c sitdev-\u003einfo-\u003enum_outputs; i++) {\n+\t\ts32 phase_ps;\n+\n+\t\trc = sit9531x_out_state_fetch(sitdev, i);\n+\t\tif (rc) {\n+\t\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\t\"Failed to fetch output %u state: %d\\n\", i, rc);\n+\t\t\treturn rc;\n+\t\t}\n+\n+\t\t/*\n+\t\t * The delay registers are part of the profile the chip loads\n+\t\t * before probe, so an output can already carry one. Seeding\n+\t\t * the cache from the device is what lets a request of 0 ps\n+\t\t * clear it: the core drops a request equal to what the\n+\t\t * getter reports, and a cache that started at zero would\n+\t\t * make clearing a programmed delay impossible. An output\n+\t\t * the configuration does not route has no Fvco to decode\n+\t\t * against, which is not an error here.\n+\t\t */\n+\t\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\t\trc = sit9531x_output_phase_read(sitdev, i, \u0026phase_ps);\n+\t\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\t\tif (!rc) {\n+\t\t\tsitdev-\u003eout[i].phase_adj = phase_ps;\n+\t\t\tsitdev-\u003eout[i].phase_armed = !!phase_ps;\n+\t\t} else if (rc != -ENODEV) {\n+\t\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\t\"Failed to read output %u delay: %d\\n\",\n+\t\t\t\ti, rc);\n+\t\t\treturn rc;\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i \u003c SIT9531X_NUM_PLLS; i++) {\n+\t\trc = sit9531x_chan_state_fetch(sitdev, i);\n+\t\tif (rc) {\n+\t\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\t\"Failed to fetch PLL%c state: %d\\n\",\n+\t\t\t\t'A' + i, rc);\n+\t\t\treturn rc;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void sit9531x_dev_ref_states_update(struct sit9531x_dev *sitdev)\n+{\n+\tint i, rc;\n+\n+\tfor (i = 0; i \u003c sitdev-\u003einfo-\u003enum_inputs; i++) {\n+\t\trc = sit9531x_ref_state_fetch(sitdev, i);\n+\t\tif (rc)\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"Failed to get REF%u status: %d\\n\", i, rc);\n+\t}\n+}\n+\n+/*\n+ * sit9531x_ref_pll_mask_rebuild - re-derive the input receiver refcounts\n+ *\n+ * ref-\u003epll_mask decides when an input receiver may be powered down, and\n+ * the connect and disconnect paths maintain it by hand. A request that\n+ * failed part way through leaves it describing a table the device does\n+ * not hold, and nothing else corrected it: a later disconnect could then\n+ * drop the count to zero and gate an input another PLL is still locked\n+ * to. Re-derive every mask from the tables the poll has just read. No\n+ * extra bus traffic -- sit9531x_chan_state_fetch() refreshed the masks\n+ * this reads immediately before.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static void sit9531x_ref_pll_mask_rebuild(struct sit9531x_dev *sitdev)\n+{\n+\tu8 pll_idx, src, index;\n+\n+\tfor (index = 0; index \u003c sitdev-\u003einfo-\u003enum_inputs; index++)\n+\t\tsitdev-\u003eref[index].pll_mask = 0;\n+\n+\tfor (pll_idx = 0; pll_idx \u003c SIT9531X_NUM_PLLS; pll_idx++) {\n+\t\tu16 mask = sitdev-\u003echan[pll_idx].prio_mask;\n+\n+\t\tfor (src = 0; src \u003c SIT9531X_PRIO_NUM_SRC; src++) {\n+\t\t\tif (!(mask \u0026 BIT(src)))\n+\t\t\t\tcontinue;\n+\n+\t\t\tindex = sit9531x_hw_src_input(src);\n+\t\t\tif (index \u003c sitdev-\u003einfo-\u003enum_inputs)\n+\t\t\t\tsitdev-\u003eref[index].pll_mask |= BIT(pll_idx);\n+\t\t}\n+\t}\n+}\n+\n+static void sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)\n+{\n+\tint i, rc;\n+\n+\tfor (i = 0; i \u003c SIT9531X_NUM_PLLS; i++) {\n+\t\trc = sit9531x_chan_state_fetch(sitdev, i);\n+\t\tif (rc)\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"Failed to get PLL%c state: %d\\n\",\n+\t\t\t\t 'A' + i, rc);\n+\t}\n+\n+\tsit9531x_ref_pll_mask_rebuild(sitdev);\n+}\n+\n+/*\n+ * sit9531x_dev_periodic_work - periodic hardware state polling\n+ * @work:\tkthread_work pointer\n+ *\n+ * Polls hardware state at SIT9531X_STATUS_POLL_MS intervals.\n+ * Updates reference and channel states, then delegates change\n+ * detection to sit9531x_dpll_changes_check() for each registered DPLL.\n+ */\n+static void sit9531x_dev_periodic_work(struct kthread_work *work)\n+{\n+\tstruct sit9531x_dev *sitdev = container_of(work, struct sit9531x_dev,\n+\t\t\t\t\t\t work.work);\n+\tstruct sit9531x_dpll *sitdpll;\n+\tint rc;\n+\n+\t/*\n+\t * Update the cached ref[]/chan[] arrays under multiop_lock so the\n+\t * fetches are serialized against the DPLL callbacks that read\n+\t * these fields and against the chip's page selector.\n+\t *\n+\t * The lock is then dropped before sit9531x_dpll_changes_check(),\n+\t * which calls dpll_pin_change_ntf() / dpll_device_change_ntf().\n+\t * Those notification helpers take DPLL-subsystem locks that are\n+\t * already held when our callbacks are invoked from netlink\n+\t * context, and nesting multiop_lock around them would invert the\n+\t * lock order. changes_check() reads the cache published above,\n+\t * which is already consistent.\n+\t */\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\tsit9531x_dev_ref_states_update(sitdev);\n+\tsit9531x_dev_chan_states_update(sitdev);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tlist_for_each_entry(sitdpll, \u0026sitdev-\u003edplls, list)\n+\t\tsit9531x_dpll_changes_check(sitdpll);\n+\n+\t/*\n+\t * Acknowledge the chip's notification latches after the tick has\n+\t * read and acted on them. Without this, the W1C bits remain set\n+\t * and -- on boards that wire INTRB -- the line stays asserted,\n+\t * re-firing the threaded handler back to back. The helper writes\n+\t * W1C bits across page 0 and page 6 and must run under\n+\t * multiop_lock to serialize the page selector against userspace\n+\t * dpll ops. Failure is non-fatal: status was already consumed\n+\t * for this tick and the next tick re-processes whatever stayed\n+\t * latched.\n+\t */\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_clear_notifications(sitdev);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\tif (rc)\n+\t\tdev_warn_ratelimited(sitdev-\u003edev,\n+\t\t\t\t \"Failed to clear notifications: %d\\n\",\n+\t\t\t\t rc);\n+\n+\t/* Run twice a second */\n+\tkthread_queue_delayed_work(sitdev-\u003ekworker, \u0026sitdev-\u003ework,\n+\t\t\t\t msecs_to_jiffies(SIT9531X_STATUS_POLL_MS));\n+}\n+\n+/*\n+ * sit9531x_irq_thread_fn - threaded IRQ handler for the chip's INTRB line\n+ *\n+ * Triggered when the chip asserts INTRB (and only when DT wires up the\n+ * client interrupt; absent property == handler never installed). The\n+ * action mirrors a periodic-work tick: queue an immediate run so status\n+ * registers are read and DPLL changes_check fires without waiting for\n+ * the next poll deadline. Polling continues to run as a fallback.\n+ */\n+static irqreturn_t sit9531x_irq_thread_fn(int irq, void *data)\n+{\n+\tstruct sit9531x_dev *sitdev = data;\n+\tint rc;\n+\n+\t/*\n+\t * Acknowledge the chip's notification latches from the threaded\n+\t * handler itself. With IRQF_ONESHOT the line is unmasked on\n+\t * return, so deferring the W1C clear to the async kworker would\n+\t * let a still-asserted INTRB re-fire immediately (interrupt storm).\n+\t * Clear here, then kick the poll worker to read state and run\n+\t * changes_check.\n+\t */\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_clear_notifications(sitdev);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\tif (rc) {\n+\t\tdev_warn_ratelimited(sitdev-\u003edev,\n+\t\t\t\t \"IRQ: failed to clear notifications: %d\\n\",\n+\t\t\t\t rc);\n+\t\t/*\n+\t\t * The latch was not acknowledged, so with IRQF_ONESHOT the\n+\t\t * still-asserted line re-enters this handler as soon as it\n+\t\t * returns. Returning IRQ_NONE leaves that to the spurious\n+\t\t * detector, which needs roughly 100000 interrupts and resets\n+\t\t * its count every tenth of a second -- unreachable when each\n+\t\t * pass costs an I2C timeout. Give up on the line instead:\n+\t\t * the periodic poll reads the same state without it, so the\n+\t\t * driver keeps working on a board whose INTRB cannot be\n+\t\t * acknowledged.\n+\t\t */\n+\t\tif (++sitdev-\u003eirq_ack_fails \u003c SIT9531X_IRQ_ACK_TRIES)\n+\t\t\treturn IRQ_NONE;\n+\n+\t\tdev_err(sitdev-\u003edev,\n+\t\t\t\"IRQ %d disabled: notifications cannot be cleared, polling only\\n\",\n+\t\t\tirq);\n+\t\tdisable_irq_nosync(irq);\n+\t\treturn IRQ_NONE;\n+\t}\n+\n+\tsitdev-\u003eirq_ack_fails = 0;\n+\n+\tkthread_mod_delayed_work(sitdev-\u003ekworker, \u0026sitdev-\u003ework, 0);\n+\treturn IRQ_HANDLED;\n+}\n+\n+/*\n+ * sit9531x_dev_start - start normal operation\n+ *\n+ * Fetches initial hardware state, registers all DPLL devices and\n+ * their pins, and starts the periodic monitoring thread.\n+ */\n+/*\n+ * Report what the device loaded from its EEPROM, and warn if it does not\n+ * look like a healthy load.\n+ *\n+ * A profile that failed to load leaves the part running something other\n+ * than what the board was designed around -- dividers, output routing\n+ * and priority tables all differ -- while every register still reads\n+ * back a plausible value. Naming the profile and saying whether the\n+ * load was clean turns that into something visible at startup instead of\n+ * something inferred from measurements later.\n+ *\n+ * This only reports. Boards in this family may have their\n+ * configuration pushed over I2C rather than held in an EEPROM, and there\n+ * the CRC pair means nothing, so a mismatch is not grounds for refusing\n+ * to drive the device.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static void sit9531x_eeprom_state_report(struct sit9531x_dev *sitdev)\n+{\n+\tu32 rec_crc = 0, cal_crc = 0, prof_id = 0;\n+\tu8 notif, v;\n+\tint rc, i;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\t/* Profile id: three bytes, least significant first. */\n+\tfor (i = 2; i \u003e= 0; i--) {\n+\t\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_PROFILE_ID + i, \u0026v);\n+\t\tif (rc)\n+\t\t\treturn;\n+\t\tprof_id = prof_id \u003c\u003c 8 | v;\n+\t}\n+\n+\tdev_info(sitdev-\u003edev, \"profile id %u\\n\", prof_id);\n+\n+\t/* Both CRCs: four bytes, most significant first. */\n+\tfor (i = 0; i \u003c 4; i++) {\n+\t\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_REC_CRC + i, \u0026v);\n+\t\tif (rc)\n+\t\t\treturn;\n+\t\trec_crc = rec_crc \u003c\u003c 8 | v;\n+\n+\t\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_CAL_CRC + i, \u0026v);\n+\t\tif (rc)\n+\t\t\treturn;\n+\t\tcal_crc = cal_crc \u003c\u003c 8 | v;\n+\t}\n+\n+\trc = sit9531x_read_u8(sitdev, SIT9531X_REG_EEPROM_NOTIF, \u0026notif);\n+\tif (rc)\n+\t\treturn;\n+\n+\t/*\n+\t * A clean load leaves the read-done bit set and every defect bit\n+\t * clear. Both CRCs zero means no EEPROM read happened at all:\n+\t * boards in this family may take their configuration over I2C\n+\t * instead of an EEPROM, and there the CRC pair means nothing, so\n+\t * that case is not a mismatch worth warning about.\n+\t */\n+\tif (!rec_crc \u0026\u0026 !cal_crc)\n+\t\tdev_dbg(sitdev-\u003edev,\n+\t\t\t\"no EEPROM profile (configuration pushed over I2C)\\n\");\n+\telse if (rec_crc != cal_crc)\n+\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t \"EEPROM CRC mismatch: stored %08x, computed %08x\\n\",\n+\t\t\t rec_crc, cal_crc);\n+\telse if (notif != SIT9531X_EEPROM_READ_DONE)\n+\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t \"EEPROM read reported defects (notify %02x)\\n\",\n+\t\t\t notif);\n+\telse\n+\t\tdev_dbg(sitdev-\u003edev, \"EEPROM profile loaded, CRC %08x\\n\",\n+\t\t\tcal_crc);\n+}\n+\n+/*\n+ * Report which PLLs came up, and flag the one case that is a real\n+ * inconsistency rather than a configuration choice.\n+ *\n+ * A PLL the loaded configuration leaves unused never reaches its active\n+ * state, which is normal and not worth a warning. A PLL that has\n+ * outputs routed to it and is still not active is different: something\n+ * that is meant to be generating clocks is not running, and every value\n+ * read from it -- lock state, phase, frequency offset -- describes a\n+ * stopped loop. Say so once at startup rather than leaving it to be\n+ * discovered through measurements that quietly read as zero.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static void sit9531x_pll_states_report(struct sit9531x_dev *sitdev)\n+{\n+\tunsigned int idx, i;\n+\tbool routed;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tfor (i = 0; i \u003c SIT9531X_NUM_PLLS; i++) {\n+\t\tif (sitdev-\u003echan[i].active) {\n+\t\t\tdev_dbg(sitdev-\u003edev, \"PLL%c active\\n\", 'A' + i);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\trouted = false;\n+\t\tfor (idx = 0; idx \u003c sitdev-\u003einfo-\u003enum_outputs; idx++) {\n+\t\t\tconst struct sit9531x_out *out;\n+\n+\t\t\tout = sit9531x_out_state_get(sitdev, idx);\n+\t\t\tif (out-\u003erouted \u0026\u0026 out-\u003epll_idx == i) {\n+\t\t\t\trouted = true;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (routed)\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"PLL%c drives outputs but is not in its active state\\n\",\n+\t\t\t\t 'A' + i);\n+\t\telse\n+\t\t\tdev_dbg(sitdev-\u003edev, \"PLL%c unused by the loaded configuration\\n\",\n+\t\t\t\t'A' + i);\n+\t}\n+}\n+\n+int sit9531x_dev_start(struct sit9531x_dev *sitdev)\n+{\n+\tstruct sit9531x_dpll *sitdpll;\n+\tint rc;\n+\n+\t/* Fetch device state */\n+\trc = sit9531x_dev_state_fetch(sitdev);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\tsit9531x_eeprom_state_report(sitdev);\n+\tsit9531x_pll_states_report(sitdev);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tlist_for_each_entry(sitdpll, \u0026sitdev-\u003edplls, list) {\n+\t\trc = sit9531x_dpll_register(sitdpll);\n+\t\tif (rc) {\n+\t\t\tdev_err_probe(sitdev-\u003edev, rc,\n+\t\t\t\t \"Failed to register DPLL%u\\n\",\n+\t\t\t\t sitdpll-\u003eid);\n+\t\t\tgoto err_unregister;\n+\t\t}\n+\t}\n+\n+\tkthread_queue_delayed_work(sitdev-\u003ekworker, \u0026sitdev-\u003ework, 0);\n+\n+\treturn 0;\n+\n+err_unregister:\n+\t/*\n+\t * Unregister what did register. The caller frees the list on this\n+\t * path, so leaving a DPLL registered would hand the subsystem a\n+\t * pointer to freed memory.\n+\t */\n+\tlist_for_each_entry_continue_reverse(sitdpll, \u0026sitdev-\u003edplls, list)\n+\t\tsit9531x_dpll_unregister(sitdpll);\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_dev_stop - stop normal operation\n+ *\n+ * Cancels the monitoring thread and unregisters all DPLL devices\n+ * and their pins.\n+ */\n+void sit9531x_dev_stop(struct sit9531x_dev *sitdev)\n+{\n+\tstruct sit9531x_dpll *sitdpll;\n+\n+\tkthread_cancel_delayed_work_sync(\u0026sitdev-\u003ework);\n+\n+\tlist_for_each_entry(sitdpll, \u0026sitdev-\u003edplls, list) {\n+\t\tif (sitdpll-\u003edpll_dev)\n+\t\t\tsit9531x_dpll_unregister(sitdpll);\n+\t}\n+}\n+\n+static struct sit9531x_dpll_pin *\n+sit9531x_dpll_pin_alloc(struct sit9531x_dpll *sitdpll,\n+\t\t\tenum dpll_pin_direction dir, u8 id)\n+{\n+\tstruct sit9531x_dpll_pin *pin;\n+\n+\tpin = kzalloc_obj(*pin, GFP_KERNEL);\n+\tif (!pin)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tpin-\u003edpll = sitdpll;\n+\tpin-\u003edir = dir;\n+\tpin-\u003eid = id;\n+\n+\treturn pin;\n+}\n+\n+/*\n+ * sit9531x_dpll_pin_register - register a DPLL pin with the subsystem\n+ * @index:\tabsolute pin index for clock_id namespace\n+ *\n+ * Gets pin properties from firmware, creates or gets a dpll_pin,\n+ * and registers it with the parent DPLL device.\n+ */\n+static int sit9531x_dpll_pin_register(struct sit9531x_dpll_pin *pin,\n+\t\t\t\t u32 index)\n+{\n+\tstruct sit9531x_dpll *sitdpll = pin-\u003edpll;\n+\tstruct sit9531x_pin_props *props;\n+\tconst struct dpll_pin_ops *ops;\n+\tint rc;\n+\n+\tprops = sit9531x_pin_props_get(sitdpll-\u003edev, pin-\u003edir, pin-\u003eid);\n+\tif (IS_ERR(props))\n+\t\treturn PTR_ERR(props);\n+\n+\tstrscpy(pin-\u003elabel, props-\u003epackage_label, sizeof(pin-\u003elabel));\n+\tpin-\u003efwnode = fwnode_handle_get(props-\u003efwnode);\n+\n+\tpin-\u003edpll_pin = dpll_pin_get(sitdpll-\u003edev-\u003eclock_id, index,\n+\t\t\t\t THIS_MODULE, \u0026props-\u003edpll_props,\n+\t\t\t\t \u0026pin-\u003etracker);\n+\tif (IS_ERR(pin-\u003edpll_pin)) {\n+\t\trc = PTR_ERR(pin-\u003edpll_pin);\n+\t\tgoto err_pin_get;\n+\t}\n+\tdpll_pin_fwnode_set(pin-\u003edpll_pin, props-\u003efwnode);\n+\n+\tops = sit9531x_dpll_pin_ops_get(pin);\n+\n+\trc = dpll_pin_register(sitdpll-\u003edpll_dev, pin-\u003edpll_pin, ops, pin);\n+\tif (rc)\n+\t\tgoto err_register;\n+\n+\tsit9531x_pin_props_put(props);\n+\n+\treturn 0;\n+\n+err_register:\n+\tdpll_pin_put(pin-\u003edpll_pin, \u0026pin-\u003etracker);\n+err_pin_get:\n+\t/* dpll_pin_get() left an ERR_PTR here. */\n+\tpin-\u003edpll_pin = NULL;\n+\tfwnode_handle_put(pin-\u003efwnode);\n+\tpin-\u003efwnode = NULL;\n+\tsit9531x_pin_props_put(props);\n+\n+\treturn rc;\n+}\n+\n+static void sit9531x_dpll_pin_unregister(struct sit9531x_dpll_pin *pin)\n+{\n+\tstruct sit9531x_dpll *sitdpll = pin-\u003edpll;\n+\tconst struct dpll_pin_ops *ops;\n+\n+\tops = sit9531x_dpll_pin_ops_get(pin);\n+\n+\tdpll_pin_unregister(sitdpll-\u003edpll_dev, pin-\u003edpll_pin, ops, pin);\n+\tdpll_pin_put(pin-\u003edpll_pin, \u0026pin-\u003etracker);\n+\tpin-\u003edpll_pin = NULL;\n+\n+\tfwnode_handle_put(pin-\u003efwnode);\n+\tpin-\u003efwnode = NULL;\n+}\n+\n+static void sit9531x_dpll_pins_unregister(struct sit9531x_dpll *sitdpll)\n+{\n+\tstruct sit9531x_dpll_pin *pin, *next;\n+\n+\tlist_for_each_entry_safe(pin, next, \u0026sitdpll-\u003epins, list) {\n+\t\tsit9531x_dpll_pin_unregister(pin);\n+\t\tlist_del(\u0026pin-\u003elist);\n+\t\tkfree(pin);\n+\t}\n+}\n+\n+/*\n+ * sit9531x_input_pin_is_registrable - check if an input pin is registrable\n+ *\n+ * Split out so input-model changes stay local to this helper.\n+ *\n+ * Return: true if the input pin should be registered, false otherwise\n+ */\n+static bool sit9531x_input_pin_is_registrable(struct sit9531x_dev *sitdev,\n+\t\t\t\t\t u8 index)\n+{\n+\tif (index \u003e= sitdev-\u003einfo-\u003enum_inputs)\n+\t\treturn false;\n+\n+\t/*\n+\t * The N lane of a differentially-configured pair is not a\n+\t * standalone input and is skipped (zl3073x model).\n+\t */\n+\tif (sit9531x_input_is_n(index) \u0026\u0026\n+\t sitdev-\u003eref[index].sig_mode == SIT9531X_MODE_DE)\n+\t\treturn false;\n+\n+\treturn true;\n+}\n+\n+/*\n+ * sit9531x_dpll_pin_is_registrable - check if a pin should be registered\n+ * @dir:\tpin direction\n+ * @index:\tpin hardware index\n+ *\n+ * For input pins: delegate to sit9531x_input_pin_is_registrable().\n+ * For output pins: the pin is registrable if this DPLL is routed to it,\n+ * whether or not it is currently driving.\n+ *\n+ * Return: true if pin should be registered, false otherwise\n+ */\n+static bool sit9531x_dpll_pin_is_registrable(struct sit9531x_dpll *sitdpll,\n+\t\t\t\t\t enum dpll_pin_direction dir,\n+\t\t\t\t\t u8 index)\n+{\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT) {\n+\t\tif (index == SIT9531X_MAX_INPUTS)\n+\t\t\treturn true;\n+\t\tif (index == SIT9531X_INTSYNC_PIN_ID)\n+\t\t\treturn true;\n+\n+\t\treturn sit9531x_input_pin_is_registrable(sitdev, index);\n+\t}\n+\n+\tif (index == SIT9531X_INTSYNC_OUT_PIN_ID)\n+\t\treturn true;\n+\n+\tif (index \u003e= sitdev-\u003einfo-\u003enum_outputs)\n+\t\treturn false;\n+\n+\treturn sitdev-\u003eout[index].pll_idx == sitdpll-\u003eid \u0026\u0026\n+\t sitdev-\u003eout[index].routed;\n+}\n+\n+/*\n+ * sit9531x_dpll_pins_register - register all registrable pins\n+ *\n+ * Enumerates all possible input and output pins, checks registrability,\n+ * and registers each one. Input pins come first, then output pins,\n+ * with input pins first, then output pins.\n+ */\n+static int sit9531x_dpll_pins_register(struct sit9531x_dpll *sitdpll)\n+{\n+\tstruct sit9531x_dpll_pin *pin;\n+\tenum dpll_pin_direction dir;\n+\tu8 id, index;\n+\tint rc;\n+\n+\tfor (index = 0; index \u003c SIT9531X_NUM_PINS_TOTAL; index++) {\n+\t\tif (index \u003c SIT9531X_NUM_INPUT_PINS) {\n+\t\t\tid = index;\n+\t\t\tdir = DPLL_PIN_DIRECTION_INPUT;\n+\t\t} else {\n+\t\t\tid = index - SIT9531X_NUM_INPUT_PINS;\n+\t\t\tdir = DPLL_PIN_DIRECTION_OUTPUT;\n+\t\t}\n+\n+\t\tif (!sit9531x_dpll_pin_is_registrable(sitdpll, dir, id))\n+\t\t\tcontinue;\n+\n+\t\tpin = sit9531x_dpll_pin_alloc(sitdpll, dir, id);\n+\t\tif (IS_ERR(pin)) {\n+\t\t\trc = PTR_ERR(pin);\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\trc = sit9531x_dpll_pin_register(pin, index);\n+\t\tif (rc) {\n+\t\t\tkfree(pin);\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tlist_add(\u0026pin-\u003elist, \u0026sitdpll-\u003epins);\n+\t}\n+\n+\treturn 0;\n+\n+error:\n+\tsit9531x_dpll_pins_unregister(sitdpll);\n+\treturn rc;\n+}\n+\n+static int sit9531x_dpll_device_register(struct sit9531x_dpll *sitdpll)\n+{\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tint rc;\n+\n+\tsitdpll-\u003eops = sit9531x_dpll_device_ops;\n+\n+\tsitdpll-\u003edpll_dev = dpll_device_get(sitdev-\u003eclock_id, sitdpll-\u003eid,\n+\t\t\t\t\t THIS_MODULE, \u0026sitdpll-\u003etracker);\n+\tif (IS_ERR(sitdpll-\u003edpll_dev)) {\n+\t\trc = PTR_ERR(sitdpll-\u003edpll_dev);\n+\t\tsitdpll-\u003edpll_dev = NULL;\n+\t\treturn rc;\n+\t}\n+\n+\trc = dpll_device_register(sitdpll-\u003edpll_dev,\n+\t\t\t\t sit9531x_prop_dpll_type_get(sitdev,\n+\t\t\t\t\t\t\t sitdpll-\u003eid),\n+\t\t\t\t \u0026sitdpll-\u003eops, sitdpll);\n+\tif (rc) {\n+\t\tdpll_device_put(sitdpll-\u003edpll_dev, \u0026sitdpll-\u003etracker);\n+\t\tsitdpll-\u003edpll_dev = NULL;\n+\t}\n+\n+\treturn rc;\n+}\n+\n+static void sit9531x_dpll_device_unregister(struct sit9531x_dpll *sitdpll)\n+{\n+\tdpll_device_unregister(sitdpll-\u003edpll_dev, \u0026sitdpll-\u003eops, sitdpll);\n+\tdpll_device_put(sitdpll-\u003edpll_dev, \u0026sitdpll-\u003etracker);\n+\tsitdpll-\u003edpll_dev = NULL;\n+}\n+\n+/*\n+ * sit9531x_dpll_alloc - allocate a DPLL device structure\n+ * @sitdev:\tparent device\n+ * @ch:\t\tPLL channel number (0-3)\n+ *\n+ * Return: pointer to allocated DPLL on success, error pointer on error\n+ */\n+struct sit9531x_dpll *sit9531x_dpll_alloc(struct sit9531x_dev *sitdev, u8 ch)\n+{\n+\tstruct sit9531x_dpll *sitdpll;\n+\n+\tsitdpll = kzalloc_obj(*sitdpll, GFP_KERNEL);\n+\tif (!sitdpll)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tsitdpll-\u003edev = sitdev;\n+\tsitdpll-\u003eid = ch;\n+\tsitdpll-\u003elock_status = DPLL_LOCK_STATUS_UNLOCKED;\n+\tINIT_LIST_HEAD(\u0026sitdpll-\u003epins);\n+\n+\treturn sitdpll;\n+}\n+\n+/*\n+ * sit9531x_dpll_free - deallocate a DPLL device structure\n+ * @sitdpll:\tDPLL to free\n+ */\n+void sit9531x_dpll_free(struct sit9531x_dpll *sitdpll)\n+{\n+\tkfree(sitdpll);\n+}\n+\n+/*\n+ * sit9531x_dpll_register - register DPLL device and all its pins\n+ *\n+ * Registers the DPLL device with the subsystem and then registers\n+ * all input and output pins that are connected to this PLL.\n+ */\n+int sit9531x_dpll_register(struct sit9531x_dpll *sitdpll)\n+{\n+\tint rc;\n+\n+\trc = sit9531x_dpll_device_register(sitdpll);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\trc = sit9531x_dpll_pins_register(sitdpll);\n+\tif (rc) {\n+\t\tsit9531x_dpll_device_unregister(sitdpll);\n+\t\treturn rc;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/* sit9531x_dpll_unregister - unregister DPLL device and its pins */\n+void sit9531x_dpll_unregister(struct sit9531x_dpll *sitdpll)\n+{\n+\tsit9531x_dpll_pins_unregister(sitdpll);\n+\tsit9531x_dpll_device_unregister(sitdpll);\n+}\n+\n+static void sit9531x_dpll_list_free(struct sit9531x_dev *sitdev)\n+{\n+\tstruct sit9531x_dpll *sitdpll, *next;\n+\n+\tlist_for_each_entry_safe(sitdpll, next, \u0026sitdev-\u003edplls, list) {\n+\t\tlist_del(\u0026sitdpll-\u003elist);\n+\t\tsit9531x_dpll_free(sitdpll);\n+\t}\n+}\n+\n+/* Runs only once the device is fully started, see the caller. */\n+static void sit9531x_dev_dpll_fini(void *ptr)\n+{\n+\tstruct sit9531x_dev *sitdev = ptr;\n+\n+\tsit9531x_dev_stop(sitdev);\n+\tkthread_destroy_worker(sitdev-\u003ekworker);\n+\tsit9531x_dpll_list_free(sitdev);\n+}\n+\n+static int sit9531x_devm_dpll_init(struct sit9531x_dev *sitdev)\n+{\n+\tstruct kthread_worker *kworker;\n+\tstruct sit9531x_dpll *sitdpll;\n+\tunsigned int i;\n+\tint rc;\n+\n+\tINIT_LIST_HEAD(\u0026sitdev-\u003edplls);\n+\tkthread_init_delayed_work(\u0026sitdev-\u003ework, sit9531x_dev_periodic_work);\n+\n+\tfor (i = 0; i \u003c SIT9531X_NUM_PLLS; i++) {\n+\t\tsitdpll = sit9531x_dpll_alloc(sitdev, i);\n+\t\tif (IS_ERR(sitdpll)) {\n+\t\t\trc = dev_err_probe(sitdev-\u003edev, PTR_ERR(sitdpll),\n+\t\t\t\t\t \"Failed to alloc DPLL%u\\n\", i);\n+\t\t\tgoto err_free_dplls;\n+\t\t}\n+\n+\t\tlist_add_tail(\u0026sitdpll-\u003elist, \u0026sitdev-\u003edplls);\n+\t}\n+\n+\tkworker = kthread_run_worker(0, \"sit9531x-%s\", dev_name(sitdev-\u003edev));\n+\tif (IS_ERR(kworker)) {\n+\t\trc = PTR_ERR(kworker);\n+\t\tgoto err_free_dplls;\n+\t}\n+\tsitdev-\u003ekworker = kworker;\n+\n+\trc = sit9531x_dev_start(sitdev);\n+\tif (rc) {\n+\t\trc = dev_err_probe(sitdev-\u003edev, rc, \"Failed to start device\\n\");\n+\t\tgoto err_destroy_worker;\n+\t}\n+\n+\t/*\n+\t * Only now is every field the cleanup touches valid, so this is the\n+\t * first point at which the action may be registered. On failure it\n+\t * runs the action itself, which is correct here and only here.\n+\t */\n+\treturn devm_add_action_or_reset(sitdev-\u003edev, sit9531x_dev_dpll_fini,\n+\t\t\t\t\tsitdev);\n+\n+err_destroy_worker:\n+\tkthread_destroy_worker(sitdev-\u003ekworker);\n+err_free_dplls:\n+\tsit9531x_dpll_list_free(sitdev);\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_read_variant_id - read chip variant ID byte from hardware\n+ * @id:\t\toutput variant ID byte\n+ *\n+ * Reads the single-byte variant identification register from Page 0\n+ * reg 0x02 (95317 = 0x17, 95316 = 0x31). Reg 0x03 holds a separate\n+ * revision byte and is intentionally not consumed here.\n+ */\n+static int sit9531x_read_variant_id(struct sit9531x_dev *sitdev, u8 *id)\n+{\n+\treturn sit9531x_read_u8(sitdev, SIT9531X_REG_VARIANT_ID, id);\n+}\n+\n+static const struct sit9531x_chip_info *sit9531x_match_variant(u8 id)\n+{\n+\tunsigned int i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(sit9531x_chip_ids); i++) {\n+\t\tif (sit9531x_chip_ids[i].id == id)\n+\t\t\treturn \u0026sit9531x_chip_ids[i];\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+/*\n+ * sit9531x_derive_clock_id - build EUI-64 clock identifier\n+ *\n+ * Generates a deterministic 64-bit identifier from the SiTime OUI,\n+ * the chip ID, the I2C bus number and the I2C address. The bus number\n+ * disambiguates two same-variant parts at the same address on\n+ * different adapters (or behind a mux), which the DPLL core would\n+ * otherwise fold onto one set of objects; DT bus aliases keep the\n+ * numbering, and with it the clock_id, stable across reboots.\n+ *\n+ * Return: 64-bit clock identifier\n+ */\n+static u64 sit9531x_derive_clock_id(struct sit9531x_dev *sitdev)\n+{\n+\tu64 clkid;\n+\n+\tclkid = SIT9531X_OUI \u003c\u003c 24;\n+\tclkid |= (u64)(i2c_adapter_id(sitdev-\u003eclient-\u003eadapter) \u0026 0xff) \u003c\u003c 16;\n+\tclkid |= (u64)sitdev-\u003einfo-\u003eid \u003c\u003c 8;\n+\tclkid |= (u64)sitdev-\u003eclient-\u003eaddr;\n+\n+\treturn clkid;\n+}\n+\n+/*\n+ * Does an Fvco fall in the band the given PLL runs in?\n+ *\n+ * The two bands are disjoint, and which one applies is fixed per PLL, so a\n+ * single envelope from the bottom of the low band to the top of the high\n+ * one would accept both the ~1 GHz gap between them and a rate belonging to\n+ * the other PLL's band.\n+ */\n+static bool sit9531x_fvco_in_band(u8 pll_idx, u64 fvco)\n+{\n+\tif (pll_idx == 1 || pll_idx == 3)\n+\t\treturn fvco \u003e= SIT9531X_FVCO_HIGHBAND_MIN \u0026\u0026\n+\t\t fvco \u003c= SIT9531X_FVCO_HIGHBAND_MAX;\n+\n+\treturn fvco \u003e= SIT9531X_FVCO_LOWBAND_MIN \u0026\u0026\n+\t fvco \u003c= SIT9531X_FVCO_LOWBAND_MAX;\n+}\n+\n+/*\n+ * Board-config overrides for fixed efuse/blob routing the chip registers do\n+ * not describe unambiguously. Absent properties leave pll_fvco[] zeroed\n+ * (derive from DIVN) and out_pll_map_valid false (use the OUT_MAP registers).\n+ */\n+static void sit9531x_parse_board_config(struct sit9531x_dev *sitdev)\n+{\n+\tu32 map[SIT9531X_MAX_OUTPUTS];\n+\tint n, i, rc;\n+\n+\tif (device_property_present(sitdev-\u003edev, \"sitime,pll-fvco\")) {\n+\t\t/*\n+\t\t * A fixed-count read rejects a short array but accepts a\n+\t\t * long one and drops the surplus, so the count is checked\n+\t\t * here: the property describes four PLLs and an array of\n+\t\t * any other length describes something else.\n+\t\t */\n+\t\trc = device_property_count_u64(sitdev-\u003edev,\n+\t\t\t\t\t \"sitime,pll-fvco\");\n+\t\tif (rc != SIT9531X_NUM_PLLS) {\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"sitime,pll-fvco needs %d entries, ignoring\\n\",\n+\t\t\t\t SIT9531X_NUM_PLLS);\n+\t\t\tmemset(sitdev-\u003epll_fvco, 0, sizeof(sitdev-\u003epll_fvco));\n+\t\t\tgoto out_map;\n+\t\t}\n+\n+\t\trc = device_property_read_u64_array(sitdev-\u003edev,\n+\t\t\t\t\t\t \"sitime,pll-fvco\",\n+\t\t\t\t\t\t sitdev-\u003epll_fvco,\n+\t\t\t\t\t\t SIT9531X_NUM_PLLS);\n+\t\tif (rc) {\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"invalid sitime,pll-fvco (%d), ignoring\\n\",\n+\t\t\t\t rc);\n+\t\t\tmemset(sitdev-\u003epll_fvco, 0, sizeof(sitdev-\u003epll_fvco));\n+\t\t}\n+\n+\t\t/*\n+\t\t * The override is used verbatim by the divider math, so an\n+\t\t * implausible value (units typo, wrong cell count worked\n+\t\t * around with zeros) must not silently misprogram DIVO.\n+\t\t * Anything outside both VCO bands is dropped with a warning\n+\t\t * rather than trusted.\n+\t\t */\n+\t\tfor (i = 0; i \u003c SIT9531X_NUM_PLLS; i++) {\n+\t\t\tu64 f = sitdev-\u003epll_fvco[i];\n+\n+\t\t\tif (f \u0026\u0026 !sit9531x_fvco_in_band(i, f)) {\n+\t\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t\t \"PLL%c Fvco override %llu Hz is outside the band that PLL runs in, ignoring\\n\",\n+\t\t\t\t\t 'A' + i, f);\n+\t\t\t\tsitdev-\u003epll_fvco[i] = 0;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+out_map:\n+\tif (!device_property_present(sitdev-\u003edev, \"sitime,output-pll-map\"))\n+\t\treturn;\n+\n+\t/*\n+\t * Any 1..MAX_OUTPUTS length is accepted so the 8-output SiT95317 need\n+\t * not pad to 12; variant detection has not run yet and entries past\n+\t * the detected num_outputs are never indexed. Trailing entries of a\n+\t * short map must read as unmapped rather than 0 (== PLLA), which\n+\t * would mark unrouted outputs active in sit9531x_out_state_fetch().\n+\t */\n+\tmemset(sitdev-\u003eout_pll_map, SIT9531X_OUT_PLL_UNMAPPED,\n+\t sizeof(sitdev-\u003eout_pll_map));\n+\n+\tn = device_property_count_u32(sitdev-\u003edev, \"sitime,output-pll-map\");\n+\tsitdev-\u003eout_pll_map_count = (n \u003e 0) ? n : 0;\n+\tif (n \u003c= 0 || n \u003e SIT9531X_MAX_OUTPUTS ||\n+\t device_property_read_u32_array(sitdev-\u003edev, \"sitime,output-pll-map\",\n+\t\t\t\t\t map, n)) {\n+\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t \"invalid sitime,output-pll-map, ignoring\\n\");\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * The binding allows only 0-3 and 255 per entry. A stray value\n+\t * would silently unroute an output (m \u003e= SIT9531X_NUM_PLLS reads\n+\t * as unmapped in sit9531x_out_state_fetch()), so reject the whole\n+\t * property loudly instead.\n+\t */\n+\tfor (i = 0; i \u003c n; i++) {\n+\t\tif (map[i] \u003e= SIT9531X_NUM_PLLS \u0026\u0026\n+\t\t map[i] != SIT9531X_OUT_PLL_UNMAPPED) {\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"sitime,output-pll-map entry %d is %u (must be 0-3 or 255), ignoring map\\n\",\n+\t\t\t\t i, map[i]);\n+\t\t\treturn;\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i \u003c n; i++)\n+\t\tsitdev-\u003eout_pll_map[i] = map[i];\n+\tsitdev-\u003eout_pll_map_valid = true;\n+}\n+\n+int sit9531x_dev_probe(struct sit9531x_dev *sitdev)\n+{\n+\tstruct clk *xtal_clk;\n+\tu8 variant_id;\n+\tint rc;\n+\n+\t/*\n+\t * Fvco = Fref * (DIVN + frac/2^32) with Fref = xtal_freq \u003c\u003c doubler,\n+\t * so every freq_set and phase_adjust path divides by a rate derived\n+\t * from the XO feeding XIN/XO_CLK. The rate normally comes from a\n+\t * \"clocks\" phandle (clock-names = \"xtal\"). On platforms where the\n+\t * firmware does not expose the XO through the clock framework, fall\n+\t * back to a \"clock-frequency\" device property.\n+\t */\n+\txtal_clk = devm_clk_get_optional_enabled(sitdev-\u003edev, \"xtal\");\n+\tif (IS_ERR(xtal_clk))\n+\t\treturn dev_err_probe(sitdev-\u003edev, PTR_ERR(xtal_clk),\n+\t\t\t\t \"Failed to get xtal clock\\n\");\n+\tsitdev-\u003extal_freq = clk_get_rate(xtal_clk);\n+\tif (!sitdev-\u003extal_freq) {\n+\t\tu32 freq;\n+\n+\t\tif (!device_property_read_u32(sitdev-\u003edev, \"clock-frequency\",\n+\t\t\t\t\t \u0026freq))\n+\t\t\tsitdev-\u003extal_freq = freq;\n+\t}\n+\tif (!sitdev-\u003extal_freq)\n+\t\treturn dev_err_probe(sitdev-\u003edev, -EINVAL,\n+\t\t\t\t \"no xtal rate: provide clocks=\u003c\u0026xo\u003e + clock-names=\\\"xtal\\\", or a clock-frequency property\\n\");\n+\n+\t/*\n+\t * Held deasserted, never pulsed: the chip configuration comes from\n+\t * efuse or an NVM blob applied before probe, and a reset would\n+\t * discard it. Must precede the first I2C access, as a board that\n+\t * powers up asserted keeps the chip unreachable until released.\n+\t */\n+\tsitdev-\u003ereset_gpio = devm_gpiod_get_optional(sitdev-\u003edev, \"reset\",\n+\t\t\t\t\t\t GPIOD_OUT_LOW);\n+\tif (IS_ERR(sitdev-\u003ereset_gpio))\n+\t\treturn dev_err_probe(sitdev-\u003edev, PTR_ERR(sitdev-\u003ereset_gpio),\n+\t\t\t\t \"Failed to request reset gpio\\n\");\n+\tif (sitdev-\u003ereset_gpio)\n+\t\tfsleep(10000);\t/* internal boot after release */\n+\n+\tsit9531x_parse_board_config(sitdev);\n+\n+\trc = sit9531x_read_variant_id(sitdev, \u0026variant_id);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tsitdev-\u003einfo = sit9531x_match_variant(variant_id);\n+\tif (!sitdev-\u003einfo)\n+\t\treturn dev_err_probe(sitdev-\u003edev, -ENODEV,\n+\t\t\t\t \"Unknown variant ID: 0x%02x\\n\",\n+\t\t\t\t variant_id);\n+\n+\t/*\n+\t * The map is parsed before the variant is known, so its length can\n+\t * only be checked against the part here. A map that stops short of\n+\t * the outputs this variant has leaves the rest reading as unmapped,\n+\t * which would drop real output pins; fall back to the routing the\n+\t * registers describe instead.\n+\t */\n+\tif (sitdev-\u003eout_pll_map_valid \u0026\u0026\n+\t sitdev-\u003eout_pll_map_count \u003c sitdev-\u003einfo-\u003enum_outputs) {\n+\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t \"sitime,output-pll-map has %u of %u outputs, ignoring map\\n\",\n+\t\t\t sitdev-\u003eout_pll_map_count, sitdev-\u003einfo-\u003enum_outputs);\n+\t\tsitdev-\u003eout_pll_map_valid = false;\n+\t}\n+\n+\tsitdev-\u003eclock_id = sit9531x_derive_clock_id(sitdev);\n+\tsitdev-\u003eintsync_src = -1;\n+\n+\trc = devm_mutex_init(sitdev-\u003edev, \u0026sitdev-\u003emultiop_lock);\n+\tif (rc)\n+\t\treturn dev_err_probe(sitdev-\u003edev, rc,\n+\t\t\t\t \"Failed to initialize mutex\\n\");\n+\n+\tdev_info(sitdev-\u003edev, \"%s detected, %u inputs, %u outputs\\n\",\n+\t\t sitdev-\u003einfo-\u003ename, sitdev-\u003einfo-\u003enum_inputs,\n+\t\t sitdev-\u003einfo-\u003enum_outputs);\n+\n+\t/*\n+\t * Before the IRQ: the handler reaches sitdev-\u003ekworker through\n+\t * kthread_mod_delayed_work(), so the worker has to exist before an\n+\t * INTRB assertion can land.\n+\t */\n+\trc = sit9531x_devm_dpll_init(sitdev);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\t/* Absent \"interrupts\" leaves client-\u003eirq 0 and the poll in charge. */\n+\tsitdev-\u003eirq = sitdev-\u003eclient ? sitdev-\u003eclient-\u003eirq : 0;\n+\tif (sitdev-\u003eirq \u003e 0) {\n+\t\trc = devm_request_threaded_irq(sitdev-\u003edev, sitdev-\u003eirq,\n+\t\t\t\t\t NULL, sit9531x_irq_thread_fn,\n+\t\t\t\t\t IRQF_ONESHOT,\n+\t\t\t\t\t dev_name(sitdev-\u003edev), sitdev);\n+\t\tif (rc)\n+\t\t\treturn dev_err_probe(sitdev-\u003edev, rc,\n+\t\t\t\t\t \"Failed to request IRQ %d\\n\",\n+\t\t\t\t\t sitdev-\u003eirq);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int sit9531x_i2c_probe(struct i2c_client *client)\n+{\n+\tstruct sit9531x_dev *sitdev;\n+\tstruct regmap *regmap;\n+\n+\tregmap = devm_regmap_init_i2c(client, \u0026sit9531x_regmap_config);\n+\tif (IS_ERR(regmap))\n+\t\treturn dev_err_probe(\u0026client-\u003edev, PTR_ERR(regmap),\n+\t\t\t\t \"Failed to initialize regmap\\n\");\n+\n+\tsitdev = devm_kzalloc(\u0026client-\u003edev, sizeof(*sitdev), GFP_KERNEL);\n+\tif (!sitdev)\n+\t\treturn -ENOMEM;\n+\n+\tsitdev-\u003edev = \u0026client-\u003edev;\n+\tsitdev-\u003eclient = client;\n+\tsitdev-\u003eregmap = regmap;\n+\ti2c_set_clientdata(client, sitdev);\n+\n+\treturn sit9531x_dev_probe(sitdev);\n+}\n+\n+static const struct of_device_id sit9531x_of_match[] = {\n+\t{ .compatible = \"sitime,sit95316\" },\n+\t{ .compatible = \"sitime,sit95317\" },\n+\t{ }\n+};\n+MODULE_DEVICE_TABLE(of, sit9531x_of_match);\n+\n+/*\n+ * The poll worker is not freezable and would keep issuing paged I2C\n+ * transfers into a suspended adapter, where i2c_transfer() fails and a\n+ * tick landing mid-suspend could tear a paged sequence between the\n+ * page-selector write and the register access. Park the worker (and\n+ * the IRQ that kicks it) across suspend and take a fresh sample on\n+ * resume.\n+ */\n+static int sit9531x_suspend(struct device *dev)\n+{\n+\tstruct sit9531x_dev *sitdev = dev_get_drvdata(dev);\n+\n+\tif (sitdev-\u003eirq \u003e 0)\n+\t\tdisable_irq(sitdev-\u003eirq);\n+\tkthread_cancel_delayed_work_sync(\u0026sitdev-\u003ework);\n+\n+\treturn 0;\n+}\n+\n+static int sit9531x_resume(struct device *dev)\n+{\n+\tstruct sit9531x_dev *sitdev = dev_get_drvdata(dev);\n+\n+\tif (sitdev-\u003eirq \u003e 0)\n+\t\tenable_irq(sitdev-\u003eirq);\n+\tkthread_queue_delayed_work(sitdev-\u003ekworker, \u0026sitdev-\u003ework, 0);\n+\n+\treturn 0;\n+}\n+\n+static DEFINE_SIMPLE_DEV_PM_OPS(sit9531x_pm_ops,\n+\t\t\t\tsit9531x_suspend, sit9531x_resume);\n+\n+static struct i2c_driver sit9531x_i2c_driver = {\n+\t.driver\t\t\t= {\n+\t\t.name\t\t= \"sit9531x\",\n+\t\t.of_match_table\t= sit9531x_of_match,\n+\t\t.pm\t\t= pm_sleep_ptr(\u0026sit9531x_pm_ops),\n+\t},\n+\t.probe\t\t= sit9531x_i2c_probe,\n+};\n+module_i2c_driver(sit9531x_i2c_driver);\n+\n+MODULE_AUTHOR(\"Ali Rouhi \u003carouhi@sitime.com\u003e\");\n+MODULE_AUTHOR(\"Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\");\n+MODULE_DESCRIPTION(\"SiTime SiT9531x DPLL subsystem driver\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/drivers/dpll/sit9531x/core.h b/drivers/dpll/sit9531x/core.h\nnew file mode 100644\nindex 0000000000000..31a5f49c02531\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/core.h\n@@ -0,0 +1,429 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * SiTime SiT9531x DPLL core driver\n+ *\n+ * Copyright (C) 2026 SiTime Corp.\n+ * Author: Ali Rouhi \u003carouhi@sitime.com\u003e\n+ * Author: Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\n+ *\n+ * Device structure, register access helpers, and core function\n+ * declarations.\n+ */\n+\n+#ifndef _SIT9531X_CORE_H\n+#define _SIT9531X_CORE_H\n+\n+#include \u003clinux/gpio/consumer.h\u003e\n+#include \u003clinux/i2c.h\u003e\n+#include \u003clinux/kthread.h\u003e\n+#include \u003clinux/list.h\u003e\n+#include \u003clinux/mutex.h\u003e\n+#include \u003clinux/regmap.h\u003e\n+#include \u003clinux/types.h\u003e\n+\n+#include \"regs.h\"\n+\n+#define SIT9531X_NUM_PLLS\t\t4\n+#define SIT9531X_MAX_INPUTS\t\t8\n+#define SIT9531X_NUM_INPUT_PAIRS\t(SIT9531X_MAX_INPUTS / 2)\n+#define SIT9531X_MAX_OUTPUTS\t\t12\n+/* out_pll_map[] entry meaning \"this output is not routed to any PLL\" */\n+#define SIT9531X_OUT_PLL_UNMAPPED\t0xFF\n+/*\n+ * INTSYNC (the inter-PLL sync net) is modeled as two pins. The\n+ * destination PLL that locks to INTSYNC sees an input pin\n+ * (SIT9531X_INTSYNC_PIN_ID, in the input id namespace after the physical\n+ * inputs and the xtal); the source PLL that drives INTSYNC sees an output\n+ * pin (SIT9531X_INTSYNC_OUT_PIN_ID, appended after the physical outputs).\n+ */\n+#define SIT9531X_INTSYNC_PIN_ID\t\t(SIT9531X_MAX_INPUTS + 1)\n+#define SIT9531X_INTSYNC_OUT_PIN_ID\tSIT9531X_MAX_OUTPUTS\n+#define SIT9531X_STATUS_POLL_MS\t\t500\n+\n+/* selected_ref value when the active source is not a registered input */\n+#define SIT9531X_REF_INVALID\t\t0xFF\n+\n+/* SiTime IEEE OUI for EUI-64 generation */\n+#define SIT9531X_OUI\t\t\t0x0090C2FFFEULL\n+\n+struct sit9531x_dpll;\n+\n+/*\n+ * struct sit9531x_chip_info - chip variant identification\n+ * @id:\t\tvariant ID byte read from register\n+ * @num_inputs:\tnumber of input clock pins\n+ * @num_outputs: number of output clock pins\n+ * @name:\thuman-readable variant name\n+ * @clkout_map:\tper-output slot mapping (output index -\u003e physical slot)\n+ */\n+struct sit9531x_chip_info {\n+\tu8\t\tid;\n+\tu8\t\tnum_inputs;\n+\tu8\t\tnum_outputs;\n+\tconst char\t*name;\n+\tconst u8\t*clkout_map;\n+};\n+\n+/*\n+ * enum sit9531x_signal_mode - input signal electrical mode\n+ * @SIT9531X_MODE_SE: single-ended\n+ * @SIT9531X_MODE_DE: differential\n+ */\n+enum sit9531x_signal_mode {\n+\tSIT9531X_MODE_SE = 0,\n+\tSIT9531X_MODE_DE,\n+};\n+\n+/*\n+ * struct sit9531x_ref - input reference state\n+ * @freq:\t\tconfigured frequency in Hz\n+ * @enabled:\t\tthe lane's receiver is on\n+ * @pll_mask:\t\tbitmask of PLLs this input feeds (bit 0 = PLLA)\n+ * @label:\t\tboard label from DT or default\n+ * @sig_mode:\t\tsignal mode of the pair this lane belongs to\n+ *\t\t\t(detected from CLKINx_INPUT_MODE at probe)\n+ */\n+struct sit9531x_ref {\n+\tu64\t\tfreq;\n+\tbool\t\tenabled;\n+\tu8\t\tpll_mask;\n+\tconst char\t*label;\n+\tenum sit9531x_signal_mode\tsig_mode;\n+};\n+\n+/*\n+ * struct sit9531x_out - output state\n+ * @freq:\t\trate the output is running at, in Hz\n+ * @enabled:\t\toutput is driving, i.e. not forced into Hi-Z\n+ * @cmos:\t\toutput is wired single-ended; the Hi-Z pair that\n+ *\t\t\tspeaks for it is the SE one, not the differential\n+ * @state_stale:\tthe cached mute state could not be confirmed against\n+ *\t\t\thardware and has to be read back before it is reported\n+ * @routed:\t\toutput is mapped to @pll_idx by the initial\n+ *\t\t\tconfiguration; an unrouted output has no DPLL pin\n+ * @pll_idx:\t\tPLL driving this output (0-3)\n+ * @phase_stale:\tthe programmed delay may differ from @phase_adj\n+ * @phase_armed:\ta phase adjust has been programmed, so a rate\n+ *\t\t\tchange has to re-time it even when it quantized\n+ *\t\t\tto zero\n+ * @phase_adj:\t\tphase adjust the delay registers actually realize,\n+ *\t\t\ti.e. the last request quantized to whole VCO cycles\n+ *\t\t\tplus 30 ps fine steps, in the request's sign\n+ * @label:\t\tboard label from DT or default\n+ */\n+struct sit9531x_out {\n+\tu64\t\tfreq;\n+\tbool\t\tenabled;\n+\tbool\t\tcmos;\n+\tbool\t\tstate_stale;\n+\tbool\t\trouted;\n+\tu8\t\tpll_idx;\n+\ts32\t\tphase_adj;\n+\tbool\t\tphase_armed;\n+\tbool\t\tphase_stale;\n+\tconst char\t*label;\n+};\n+\n+/*\n+ * struct sit9531x_chan - per-PLL channel state\n+ * @active:\t\tPLL has reached its active state; a PLL the loaded\n+ *\t\t\tconfiguration leaves unused never does, and its\n+ *\t\t\tloss-of-lock bit stays clear because nothing drives it\n+ * @locked:\t\tPLL is locked (raw status register bit)\n+ * @mode:\t\t0 = sync (outer loop enabled), 1 = free-run\n+ * @selected_ref:\tlogical input index of the currently selected\n+ *\t\t\treference (the INTSYNC net maps to\n+ *\t\t\tSIT9531X_INTSYNC_PIN_ID), or SIT9531X_REF_INVALID\n+ *\t\t\twhen the hardware source encoding is reserved\n+ * @inner_lol:\t\tPLL inner loop loss-of-lock detected\n+ * @ho_freeze:\t\tholdover freeze active\n+ * @ho_valid:\t\tholdover memory acquired, i.e. the holdover window\n+ *\t\t\tholds a valid estimate to fall back on\n+ * @prio_srcs:\t\tcached copy of the priority table, one source code\n+ *\t\t\tper slot; refreshed together with @prio_mask, so\n+ *\t\t\tpriority reads generate no register traffic\n+ * @prio_last:\t\tslot each source occupies, plus one (0 = the source\n+ *\t\t\tis not in the table); refreshed from the same scan\n+ *\t\t\tas @prio_mask, so the two never disagree\n+ * @prio_mask:\t\tbit per hardware source code present in this PLL's\n+ *\t\t\tpriority table, i.e. the sources it may select. Read\n+ *\t\t\tback from the table by the periodic worker and\n+ *\t\t\trefreshed by every table write, so it tracks the\n+ *\t\t\thardware rather than the driver's intent\n+ */\n+struct sit9531x_chan {\n+\tbool\t\tactive;\n+\tbool\t\tlocked;\n+\tu8\t\tmode;\n+\tu8\t\tselected_ref;\n+\tbool\t\tinner_lol;\n+\tbool\t\tho_freeze;\n+\tbool\t\tho_valid;\n+\tu8\t\tprio_srcs[SIT9531X_PRIO_MAX_SLOTS];\n+\tu8\t\tprio_last[SIT9531X_PRIO_NUM_SRC];\n+\tu16\t\tprio_mask;\n+};\n+\n+/*\n+ * struct sit9531x_dev - SiT9531x device instance\n+ * @info:\t\tdetected chip variant info\n+ * @dev:\t\tparent device\n+ * @client:\t\tI2C client backing @regmap\n+ * @regmap:\t\tpaged register map of the device\n+ * @dplls:\t\tDPLL devices registered for this chip\n+ * @multiop_lock:\tmutex for multi-register atomic operations\n+ * @ref:\t\tarray of input reference states\n+ * @out:\t\tarray of output states\n+ * @chan:\t\tarray of per-PLL channel states\n+ * @xtal_freq:\t\tcrystal oscillator frequency in Hz\n+ * @kworker:\t\tkthread worker for periodic polling\n+ * @work:\t\tdelayed work for periodic state checks\n+ * @clock_id:\t\tIEEE 1588 EUI-64 clock identifier\n+ * @reset_gpio:\t\toptional reset line (DT \"reset-gpios\"), NULL if absent\n+ * @irq:\t\toptional INTRB IRQ number (from DT \"interrupts\" via the\n+ *\t\t\tI2C client), 0 if no IRQ is wired\n+ * @pll_fvco:\t\toptional per-PLL VCO in Hz from DT\n+ *\t\t\t\"sitime,pll-fvco\"; 0 means derive from DIVN\n+ * @out_pll_map:\toptional per-output source PLL (0-3, 0xff =\n+ *\t\t\tunmapped) from DT \"sitime,output-pll-map\"\n+ * @out_pll_map_valid:\ttrue when out_pll_map[] was populated from DT;\n+ *\t\t\tfalse means use the chip's OUT_MAP registers\n+ * @intsync_src:\tPLL index currently sourcing inter-PLL\n+ *\t\t\tsynchronization (INTSYNC), or -1 when disabled\n+ */\n+struct sit9531x_dev {\n+\tstruct device\t\t\t*dev;\n+\tstruct i2c_client\t\t*client;\n+\tstruct regmap\t\t\t*regmap;\n+\tconst struct sit9531x_chip_info\t*info;\n+\t/* Serializes multi-step register sequences */\n+\tstruct mutex\t\t\tmultiop_lock;\n+\n+\t/* Hardware state */\n+\tu8\t\t\tirq_ack_fails;\n+\tstruct sit9531x_ref\tref[SIT9531X_MAX_INPUTS + 1]; /* +1 for xtal */\n+\tstruct sit9531x_out\tout[SIT9531X_MAX_OUTPUTS];\n+\tstruct sit9531x_chan\tchan[SIT9531X_NUM_PLLS];\n+\tu32\t\t\txtal_freq;\n+\n+\t/* DPLL channels */\n+\tstruct list_head\tdplls;\n+\n+\t/* Monitor */\n+\tstruct kthread_worker\t\t*kworker;\n+\tstruct kthread_delayed_work\twork;\n+\n+\t/* Device identity */\n+\tu64\t\t\tclock_id;\n+\n+\t/* Optional DT-described GPIO / IRQ lines */\n+\tstruct gpio_desc\t*reset_gpio;\n+\tint\t\t\tirq;\n+\n+\t/* Optional DT board-config overrides */\n+\tu64\t\t\tpll_fvco[SIT9531X_NUM_PLLS];\n+\tu8\t\t\tout_pll_map[SIT9531X_MAX_OUTPUTS];\n+\tbool\t\t\tout_pll_map_valid;\n+\tu8\t\t\tout_pll_map_count;\n+\n+\t/* Inter-PLL synchronization state */\n+\ts8\t\t\tintsync_src;\n+\n+};\n+\n+extern const struct regmap_config sit9531x_regmap_config;\n+\n+/* ---- Core lifecycle ---- */\n+int sit9531x_dev_probe(struct sit9531x_dev *sitdev);\n+int sit9531x_dev_start(struct sit9531x_dev *sitdev);\n+void sit9531x_dev_stop(struct sit9531x_dev *sitdev);\n+\n+/* ---- Register access ---- */\n+int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,\n+\t\t u8 *val);\n+int sit9531x_write_u8(struct sit9531x_dev *sitdev, unsigned int reg,\n+\t\t u8 val);\n+int sit9531x_read_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 offset, u8 *val);\n+int sit9531x_write_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 offset, u8 val);\n+int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 offset, u8 mask, u8 val);\n+\n+/* ---- Input enable/disable ---- */\n+int sit9531x_input_disable(struct sit9531x_dev *sitdev, u8 index);\n+int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index);\n+\n+/* ---- Input priority ---- */\n+bool sit9531x_input_prio_present(struct sit9531x_dev *sitdev,\n+\t\t\t\t u8 pll_idx, u8 input_idx);\n+int sit9531x_input_prio_set(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx, u8 prio);\n+int sit9531x_input_prio_get(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx, u8 *prio);\n+int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx);\n+int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t u8 input_idx);\n+\n+/* ---- Output enable/disable (Hi-Z control) ---- */\n+int sit9531x_output_disable(struct sit9531x_dev *sitdev, u8 index);\n+int sit9531x_output_enable(struct sit9531x_dev *sitdev, u8 index);\n+int sit9531x_output_state_refresh(struct sit9531x_dev *sitdev,\n+\t\t\t\t u8 out_idx);\n+\n+/* ---- Output frequency ---- */\n+int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t u8 pll_idx, u64 frequency);\n+int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t u64 *frequency);\n+\n+/* ---- Output phase adjust (PRG_RST_DELAY register-based) ---- */\n+int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,\n+\t\t\t s32 *phase_ps);\n+int sit9531x_output_phase_adjust_set(struct sit9531x_dev *sitdev,\n+\t\t\t\t u8 out_idx, s32 phase_ps);\n+\n+/* ---- Notification clear ---- */\n+int sit9531x_clear_notifications(struct sit9531x_dev *sitdev);\n+\n+/* ---- INTSYNC (inter-PLL synchronization) ---- */\n+int sit9531x_intsync_enable(struct sit9531x_dev *sitdev, u8 src_pll_idx);\n+int sit9531x_intsync_disable(struct sit9531x_dev *sitdev, u8 src_pll_idx);\n+int sit9531x_intsync_src_detect(struct sit9531x_dev *sitdev);\n+\n+/* ---- Phase offset (TDC readback) ---- */\n+int sit9531x_pll_ffo_ppt(struct sit9531x_dev *sitdev, u8 pll_idx, s64 *ffo);\n+int sit9531x_chan_selected_ref_read(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t\t u8 *ref);\n+int sit9531x_phase_offset_read(struct sit9531x_dev *sitdev, u8 pll_idx,\n+\t\t\t s64 *phase_ps);\n+\n+/* ---- State helpers ---- */\n+\n+/*\n+ * sit9531x_pll_page - get register page for PLL index\n+ * @pll_idx: PLL index (0 = PLLA, 3 = PLLD)\n+ */\n+static inline u8 sit9531x_pll_page(u8 pll_idx)\n+{\n+\treturn SIT9531X_PAGE_PLLA + pll_idx;\n+}\n+\n+/*\n+ * Logical input pins are interleaved: even index = P lane, odd\n+ * index = N lane of pair index/2 (IN0P, IN0N, IN1P, IN1N, ...).\n+ * Index SIT9531X_MAX_INPUTS is the XO input.\n+ */\n+\n+/*\n+ * sit9531x_input_pair - get input pair number for a logical input index\n+ * @index: logical input pin index\n+ */\n+static inline u8 sit9531x_input_pair(u8 index)\n+{\n+\treturn index \u003e\u003e 1;\n+}\n+\n+/*\n+ * sit9531x_input_is_n - check if a logical input index is an N lane\n+ * @index: logical input pin index\n+ */\n+static inline bool sit9531x_input_is_n(u8 index)\n+{\n+\treturn index \u0026 1;\n+}\n+\n+/*\n+ * sit9531x_input_hw_src - translate logical input index to source encoding\n+ * @index: logical input pin index\n+ *\n+ * The priority table and CLK_ACTIVESEL registers use a non-contiguous\n+ * source encoding: 0-3 = CLK0P..CLK3P, 5 = OCXO, 6 = INTSYNC,\n+ * 7-10 = CLK0N..CLK3N.\n+ */\n+static inline u8 sit9531x_input_hw_src(u8 index)\n+{\n+\tif (index == SIT9531X_MAX_INPUTS)\n+\t\treturn SIT9531X_PRIO_SRC_OCXO;\n+\tif (index == SIT9531X_INTSYNC_PIN_ID)\n+\t\treturn SIT9531X_PRIO_SRC_INTSYNC;\n+\tif (sit9531x_input_is_n(index))\n+\t\treturn SIT9531X_PRIO_SRC_N_BASE + sit9531x_input_pair(index);\n+\treturn sit9531x_input_pair(index);\n+}\n+\n+/*\n+ * sit9531x_hw_src_input - translate source encoding to logical input index\n+ * @src: 4-bit hardware source encoding\n+ *\n+ * Return: logical input index (INTSYNC maps to SIT9531X_INTSYNC_PIN_ID),\n+ * or SIT9531X_REF_INVALID if @src is a reserved value\n+ */\n+static inline u8 sit9531x_hw_src_input(u8 src)\n+{\n+\tif (src \u003c SIT9531X_NUM_INPUT_PAIRS)\n+\t\treturn src * 2;\n+\tif (src == SIT9531X_PRIO_SRC_OCXO)\n+\t\treturn SIT9531X_MAX_INPUTS;\n+\tif (src == SIT9531X_PRIO_SRC_INTSYNC)\n+\t\treturn SIT9531X_INTSYNC_PIN_ID;\n+\tif (src \u003e= SIT9531X_PRIO_SRC_N_BASE \u0026\u0026\n+\t src \u003c SIT9531X_PRIO_SRC_N_BASE + SIT9531X_NUM_INPUT_PAIRS)\n+\t\treturn (src - SIT9531X_PRIO_SRC_N_BASE) * 2 + 1;\n+\treturn SIT9531X_REF_INVALID;\n+}\n+\n+/*\n+ * sit9531x_prio_src_usable - does a priority slot name a reference?\n+ * @src: 4-bit hardware source encoding held in a table slot\n+ *\n+ * Codes 4 and 11 address a fifth input pair this part does not have, and\n+ * a value outside the encoding is not a source either, so a slot holding\n+ * one of them names nothing the device can select. Canonicalizing an N\n+ * lane to its pair first would not change the answer -- both lanes are\n+ * references -- so this needs no device state.\n+ *\n+ * Return: true when the code resolves to a reference the device can use\n+ */\n+static inline bool sit9531x_prio_src_usable(u8 src)\n+{\n+\treturn sit9531x_hw_src_input(src) != SIT9531X_REF_INVALID;\n+}\n+\n+/*\n+ * sit9531x_ref_state_get - get reference state by index\n+ * @index:\tlogical input index\n+ *\n+ * Return: pointer to the cached input reference state\n+ */\n+static inline const struct sit9531x_ref *\n+sit9531x_ref_state_get(const struct sit9531x_dev *sitdev, u8 index)\n+{\n+\treturn \u0026sitdev-\u003eref[index];\n+}\n+\n+/*\n+ * sit9531x_out_state_get - get output state by index\n+ * @index:\tlogical output index\n+ *\n+ * Return: pointer to the cached output state\n+ */\n+static inline const struct sit9531x_out *\n+sit9531x_out_state_get(const struct sit9531x_dev *sitdev, u8 index)\n+{\n+\treturn \u0026sitdev-\u003eout[index];\n+}\n+\n+/*\n+ * sit9531x_chan_state_get - get channel state by PLL index\n+ *\n+ * Return: pointer to the cached per-PLL channel state\n+ */\n+static inline const struct sit9531x_chan *\n+sit9531x_chan_state_get(const struct sit9531x_dev *sitdev, u8 pll_idx)\n+{\n+\treturn \u0026sitdev-\u003echan[pll_idx];\n+}\n+\n+#endif /* _SIT9531X_CORE_H */\ndiff --git a/drivers/dpll/sit9531x/dpll.c b/drivers/dpll/sit9531x/dpll.c\nnew file mode 100644\nindex 0000000000000..856c9bdf33d45\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/dpll.c\n@@ -0,0 +1,1445 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * SiTime SiT9531x DPLL subsystem callbacks and registration\n+ *\n+ * Copyright (C) 2026 SiTime Corp.\n+ * Author: Ali Rouhi \u003carouhi@sitime.com\u003e\n+ * Author: Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\n+ *\n+ * DPLL device ops, pin ops (separate input/output), pin registration,\n+ * and periodic change detection.\n+ */\n+\n+#include \u003clinux/dpll.h\u003e\n+#include \u003clinux/err.h\u003e\n+#include \u003clinux/kthread.h\u003e\n+#include \u003clinux/list.h\u003e\n+#include \u003clinux/netlink.h\u003e\n+#include \u003clinux/slab.h\u003e\n+\n+#include \"core.h\"\n+#include \"dpll.h\"\n+#include \"prop.h\"\n+#include \"regs.h\"\n+\n+static bool sit9531x_dpll_is_input_pin(const struct sit9531x_dpll_pin *pin)\n+{\n+\treturn pin-\u003edir == DPLL_PIN_DIRECTION_INPUT;\n+}\n+\n+static bool\n+sit9531x_dpll_is_intsync_pin(const struct sit9531x_dpll_pin *pin)\n+{\n+\treturn sit9531x_dpll_is_input_pin(pin) \u0026\u0026\n+\t pin-\u003eid == SIT9531X_INTSYNC_PIN_ID;\n+}\n+\n+static bool\n+sit9531x_dpll_is_intsync_src_pin(const struct sit9531x_dpll_pin *pin)\n+{\n+\treturn !sit9531x_dpll_is_input_pin(pin) \u0026\u0026\n+\t pin-\u003eid == SIT9531X_INTSYNC_OUT_PIN_ID;\n+}\n+\n+static bool\n+sit9531x_dpll_is_xo_pin(const struct sit9531x_dpll_pin *pin)\n+{\n+\treturn sit9531x_dpll_is_input_pin(pin) \u0026\u0026\n+\t pin-\u003eid == SIT9531X_MAX_INPUTS;\n+}\n+\n+/*\n+ * The cached state this reports comes from the outer loss-of-lock byte\n+ * (page 0, reg 0x06), the PLL mode bit (PLL page, reg 0x31), inner LOL\n+ * (reg 0x92), the holdover freeze byte (reg 0x0A) and the per-PLL\n+ * holdover-valid bit (PLL page, reg 0x06).\n+ */\n+static int\n+sit9531x_dpll_lock_status_get(const struct dpll_device *dpll, void *dpll_priv,\n+\t\t\t enum dpll_lock_status *status,\n+\t\t\t enum dpll_lock_status_error *status_error,\n+\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tconst struct sit9531x_chan *chan;\n+\n+\tif (status_error)\n+\t\t*status_error = DPLL_LOCK_STATUS_ERROR_NONE;\n+\n+\tchan = sit9531x_chan_state_get(sitdev, sitdpll-\u003eid);\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (!chan-\u003eactive) {\n+\t\t/*\n+\t\t * A PLL the loaded configuration leaves unused never reaches\n+\t\t * its active state. Nothing drives its loss-of-lock bit, so\n+\t\t * without this it would report a lock it does not have.\n+\t\t */\n+\t\t*status = DPLL_LOCK_STATUS_UNLOCKED;\n+\t} else if (chan-\u003emode) {\n+\t\t/*\n+\t\t * Free-run: the outer loop is disabled, so the PLL tracks no\n+\t\t * reference at all and its loss-of-lock bit means nothing.\n+\t\t * That is what UNLOCKED describes -- \"not yet locked to any\n+\t\t * valid input (or was forced by user)\".\n+\t\t */\n+\t\t*status = DPLL_LOCK_STATUS_UNLOCKED;\n+\t} else if (chan-\u003elocked) {\n+\t\t/*\n+\t\t * HO_ACQ is locked *and* holdover memory acquired, so it needs\n+\t\t * the holdover-valid bit rather than following from the lock.\n+\t\t */\n+\t\tif (chan-\u003eho_valid)\n+\t\t\t*status = DPLL_LOCK_STATUS_LOCKED_HO_ACQ;\n+\t\telse\n+\t\t\t*status = DPLL_LOCK_STATUS_LOCKED;\n+\t} else if (chan-\u003eho_freeze) {\n+\t\t*status = DPLL_LOCK_STATUS_HOLDOVER;\n+\t} else {\n+\t\t*status = DPLL_LOCK_STATUS_UNLOCKED;\n+\t}\n+\n+\t/* Report inner LOL as an error condition */\n+\tif (status_error \u0026\u0026 chan-\u003einner_lol)\n+\t\t*status_error = DPLL_LOCK_STATUS_ERROR_UNDEFINED;\n+\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Mode\n+ * ====\n+ * enum dpll_mode differentiates how a DPLL selects an input: AUTOMATIC\n+ * has the device pick the highest-priority one, MANUAL has userspace\n+ * request one. The device only implements the former through this\n+ * driver, so AUTOMATIC is the only mode advertised.\n+ *\n+ * Free-run -- the outer loop disabled through PLL page reg 0x31[5] -- is\n+ * not a mode in those terms, because no input is selected either way. It\n+ * is reported through lock status instead, and reached through the\n+ * chip-specific tool rather than over netlink.\n+ *\n+ * The device could implement real MANUAL: MISCINNER_PLL (PLL page reg\n+ * 0x18) bit 5 switches a PLL from priority-based to manual active select,\n+ * and GPIO_INPUT_FUNC_CTRL5..8 (page 0, regs 0xE8-0xEB) bit 4 makes the\n+ * choice come from the register's own low nibble instead of the GPIO\n+ * pins, which pins one reference while the loop keeps running. Wiring\n+ * that up would let .state_on_dpll_set() accept CONNECTED; it needs bench\n+ * validation first, and reg 0x18 carries GUI-generated configuration in\n+ * its other bits, so it is left out until then. Advertising MANUAL and\n+ * then refusing the one request MANUAL exists for is the worse of the two\n+ * incomplete answers, and after merge it would be ABI.\n+ */\n+static int\n+sit9531x_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,\n+\t\t enum dpll_mode *mode, struct netlink_ext_ack *extack)\n+{\n+\t*mode = DPLL_MODE_AUTOMATIC;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_mode_set - put the PLL in automatic selection mode\n+ *\n+ * Clears the outer loop disable bit (PLL page reg 0x31[5]) and triggers a\n+ * small update via reg 0x0F, so a PLL left free-running by the loaded\n+ * configuration or by the chip-specific tool returns to selecting its\n+ * reference from the priority table. Any other mode is refused.\n+ */\n+static int\n+sit9531x_dpll_mode_set(const struct dpll_device *dpll, void *dpll_priv,\n+\t\t enum dpll_mode mode, struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tint rc, restore_rc;\n+\tu8 status;\n+\n+\tif (mode != DPLL_MODE_AUTOMATIC) {\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Device selects its reference by priority; only automatic mode is supported\");\n+\t\treturn -EOPNOTSUPP;\n+\t}\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\t/*\n+\t * Read before writing. Automatic is the only mode this driver\n+\t * advertises, so userspace setting it again is a no-op the device\n+\t * must not feel: without this, a redundant set followed by one\n+\t * failed latch would restore an outer-loop disable the PLL never\n+\t * had and put a running loop into free-run.\n+\t */\n+\trc = sit9531x_read_pll_u8(sitdev, sitdpll-\u003eid,\n+\t\t\t\t SIT9531X_PLL_REG_STATUS, \u0026status);\n+\tif (rc) {\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to read PLL mode register\");\n+\t\tgoto unlock;\n+\t}\n+\tif (!(status \u0026 SIT9531X_PLL_STATUS_OUTER_DIS)) {\n+\t\tsitdev-\u003echan[sitdpll-\u003eid].mode = 0;\n+\t\tgoto unlock;\n+\t}\n+\n+\trc = sit9531x_update_pll_u8(sitdev, sitdpll-\u003eid,\n+\t\t\t\t SIT9531X_PLL_REG_STATUS,\n+\t\t\t\t SIT9531X_PLL_STATUS_OUTER_DIS, 0);\n+\tif (rc) {\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to write PLL mode register\");\n+\t\tgoto unlock;\n+\t}\n+\n+\t/* Trigger small update to apply without full NVM cycle */\n+\trc = sit9531x_write_pll_u8(sitdev, sitdpll-\u003eid,\n+\t\t\t\t SIT9531X_PLL_REG_SMALL_UPDATE,\n+\t\t\t\t SIT9531X_SMALL_UPDATE_CMD);\n+\tif (rc) {\n+\t\tu8 dis = SIT9531X_PLL_STATUS_OUTER_DIS;\n+\n+\t\t/*\n+\t\t * The cleared disable bit was never latched. Put it back so\n+\t\t * the register does not read \"outer loop enabled\" for a loop\n+\t\t * that is still free-running, which the poll would then hand\n+\t\t * to the lock-status getter as a live mode.\n+\t\t */\n+\t\trestore_rc = sit9531x_update_pll_u8(sitdev, sitdpll-\u003eid,\n+\t\t\t\t\t\t SIT9531X_PLL_REG_STATUS,\n+\t\t\t\t\t\t dis, dis);\n+\t\tif (restore_rc)\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"PLL%c outer loop left enabled without a latch: %d\\n\",\n+\t\t\t\t 'A' + sitdpll-\u003eid, restore_rc);\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to trigger small update\");\n+\t\tgoto unlock;\n+\t}\n+\n+\t/*\n+\t * Keep the cached mode in step with the register. The periodic\n+\t * monitor refreshes it too, but the pin state getters and lock status\n+\t * read this cache and would otherwise keep reporting free-run until\n+\t * the next poll.\n+\t */\n+\tsitdev-\u003echan[sitdpll-\u003eid].mode = 0;\n+\n+unlock:\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\treturn rc;\n+}\n+\n+static int\n+sit9531x_dpll_supported_modes_get(const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv, unsigned long *modes,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\t__set_bit(DPLL_MODE_AUTOMATIC, modes);\n+\n+\treturn 0;\n+}\n+\n+const struct dpll_device_ops sit9531x_dpll_device_ops = {\n+\t.lock_status_get\t= sit9531x_dpll_lock_status_get,\n+\t.mode_get\t\t= sit9531x_dpll_mode_get,\n+\t.mode_set\t\t= sit9531x_dpll_mode_set,\n+\t.supported_modes_get\t= sit9531x_dpll_supported_modes_get,\n+\t/* temp_get not available -- SiT9531x has no on-die temp sensor */\n+};\n+\n+/*\n+ * Pin-state contract\n+ * ==================\n+ * The five pin ops tables below fall into three roles, and only the first\n+ * has a selection state machine. Each state_on_dpll callback implements\n+ * the rules for its role and nothing else, so the tables cannot drift\n+ * apart the way five independent encodings of this did.\n+ *\n+ * SELECTION role -- physical input pins, INTSYNC destination pin.\n+ * Where does this reference sit in this DPLL's selection process?\n+ * Predicates, all evaluated under multiop_lock:\n+ * M source is present in THIS PLL's hardware priority table\n+ * A chan-\u003emode == 0 (outer loop running)\n+ * L chan-\u003elocked \u0026\u0026 !chan-\u003einner_lol (only meaningful when A)\n+ * S chan-\u003eselected_ref == this pin's id\n+ * get:\n+ * CONNECTED A \u0026\u0026 L \u0026\u0026 S \u0026\u0026 M\n+ * SELECTABLE M \u0026\u0026 !(A \u0026\u0026 L \u0026\u0026 S)\n+ * DISCONNECTED !M\n+ * set:\n+ * DISCONNECTED remove from this PLL's table; a physical input also\n+ * releases this DPLL's claim and powers the shared\n+ * receiver down on the last release\n+ * SELECTABLE add to this PLL's table; a physical input powers the\n+ * receiver up and takes the claim, in that order\n+ * CONNECTED -EOPNOTSUPP -- the device selects by priority and has\n+ * no mode that pins one reference (see mode_set())\n+ * other -EINVAL\n+ *\n+ * A is what separates CONNECTED from SELECTABLE: chan-\u003elocked is derived\n+ * from the outer loss-of-lock bit, which can read clear while the outer\n+ * loop is disabled, so a free-running PLL would otherwise claim its\n+ * reference as the active input of a loop that is ignoring it.\n+ *\n+ * M is read from the hardware priority table, not from ref-\u003epll_mask.\n+ * pll_mask is only the shared-receiver refcount and says nothing about\n+ * one DPLL's eligibility; it also drifts, because .prio_set writes the\n+ * table without touching it. Signal quality is reported through the\n+ * pin's own attributes rather than by demoting the state, so a source\n+ * that is momentarily in LOS stays selectable.\n+ *\n+ * DRIVE role -- output pins, INTSYNC source pin.\n+ * Is this pin or net being driven? Nothing is selected here, so:\n+ * CONNECTED pin or net is driven\n+ * DISCONNECTED pin is muted (Hi-Z), or this PLL does not drive it\n+ * SELECTABLE -EINVAL on set, never reported by get\n+ *\n+ * FIXED role -- XO pin. Always CONNECTED; it cannot be routed.\n+ */\n+\n+/*\n+ * Report a selection-role pin's state on this DPLL. @pin_id is a logical\n+ * input index, SIT9531X_INTSYNC_PIN_ID for the INTSYNC destination.\n+ *\n+ * CONNECTED means the device has selected this pin, not that the loop\n+ * has settled on it: how well it is tracking is what lock status answers,\n+ * and a PLL following a reference it has not locked to yet is still\n+ * following that reference and no other.\n+ *\n+ * Membership comes from chan-\u003eprio_mask, which is the priority table read\n+ * back from the chip -- not a record of what the driver asked for. The\n+ * getter runs on every poll for every input pin of every DPLL, so it takes\n+ * the mask the worker refreshed rather than rescanning the table over I2C\n+ * each time; table writes refresh it too, so a get right after a set does\n+ * not report the old membership.\n+ *\n+ * Caller must hold sitdev-\u003emultiop_lock.\n+ */\n+static void\n+sit9531x_dpll_selection_state_get(struct sit9531x_dev *sitdev,\n+\t\t\t\t const struct sit9531x_dpll *sitdpll,\n+\t\t\t\t u8 pin_id, enum dpll_pin_state *state)\n+{\n+\tconst struct sit9531x_chan *chan;\n+\tbool active_input;\n+\n+\tlockdep_assert_held(\u0026sitdev-\u003emultiop_lock);\n+\n+\tchan = sit9531x_chan_state_get(sitdev, sitdpll-\u003eid);\n+\tactive_input = !chan-\u003emode \u0026\u0026 chan-\u003eselected_ref == pin_id;\n+\n+\tif (!(chan-\u003eprio_mask \u0026 BIT(sit9531x_input_hw_src(pin_id))))\n+\t\t*state = DPLL_PIN_STATE_DISCONNECTED;\n+\telse if (active_input)\n+\t\t*state = DPLL_PIN_STATE_CONNECTED;\n+\telse\n+\t\t*state = DPLL_PIN_STATE_SELECTABLE;\n+}\n+\n+static int\n+sit9531x_dpll_input_pin_direction_get(const struct dpll_pin *pin,\n+\t\t\t\t void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv,\n+\t\t\t\t enum dpll_pin_direction *direction,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\t*direction = DPLL_PIN_DIRECTION_INPUT;\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_input_pin_frequency_get - read input pin frequency\n+ *\n+ * returns cached frequency from DT or last set.\n+ */\n+static int\n+sit9531x_dpll_input_pin_frequency_get(const struct dpll_pin *pin,\n+\t\t\t\t void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv, u64 *frequency,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tconst struct sit9531x_ref *ref;\n+\n+\tref = sit9531x_ref_state_get(sitdpll-\u003edev, dpin-\u003eid);\n+\t*frequency = ref-\u003efreq;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_input_pin_state_on_dpll_get - get input pin DPLL state\n+ *\n+ * Selection role; see the pin-state contract above.\n+ */\n+static int\n+sit9531x_dpll_input_pin_state_on_dpll_get(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state *state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\tsit9531x_dpll_selection_state_get(sitdev, sitdpll, dpin-\u003eid, state);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_input_pin_state_on_dpll_set - set input pin DPLL state\n+ *\n+ * Enables or disables the physical input receiver via Page 0x02\n+ * force/state registers (sit9531x_input_disable/enable()) and updates\n+ * this DPLL's Page 1 priority table so the state is honoured by the\n+ * PLL's automatic reference selection, not just at the input buffer.\n+ * Selection role; see the pin-state contract above for the states.\n+ *\n+ * The priority table is per PLL, so it is always updated for this DPLL.\n+ * A single physical input feeds every DPLL, so the hardware receiver is\n+ * only cut off once the last DPLL has released it: ref-\u003epll_mask tracks\n+ * which DPLLs currently claim the input, and the physical disable\n+ * happens on the transition to an empty mask.\n+ */\n+static int\n+sit9531x_dpll_input_pin_state_on_dpll_set(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tstruct sit9531x_ref *ref = \u0026sitdev-\u003eref[dpin-\u003eid];\n+\tu8 hw_src = sit9531x_input_hw_src(dpin-\u003eid);\n+\tu8 pll_bit = BIT(sitdpll-\u003eid);\n+\tbool enabled_here = false;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tswitch (state) {\n+\tcase DPLL_PIN_STATE_DISCONNECTED:\n+\t\trc = sit9531x_input_prio_remove(sitdev, sitdpll-\u003eid, hw_src);\n+\t\t/*\n+\t\t * The table write, the latch and the holdover release are\n+\t\t * three steps behind one return code, so ask the table what\n+\t\t * actually happened rather than reading the errno as \"no\n+\t\t * change\". A source that is gone from the table has been\n+\t\t * released whatever else failed.\n+\t\t */\n+\t\tif (rc \u0026\u0026 sit9531x_input_prio_present(sitdev, sitdpll-\u003eid,\n+\t\t\t\t\t\t hw_src))\n+\t\t\tbreak;\n+\t\tref-\u003epll_mask \u0026= ~pll_bit;\n+\t\t/*\n+\t\t * The receiver is shared, so the last DPLL to let go turns it\n+\t\t * off. That has to happen even when the table rewrite\n+\t\t * reported an error, or the input stays powered with nothing\n+\t\t * tracking it; the first error is the one returned.\n+\t\t */\n+\t\tif (!ref-\u003epll_mask) {\n+\t\t\tint off_rc = sit9531x_input_disable(sitdev, dpin-\u003eid);\n+\n+\t\t\tif (off_rc \u0026\u0026 !rc)\n+\t\t\t\trc = off_rc;\n+\t\t}\n+\t\tbreak;\n+\tcase DPLL_PIN_STATE_CONNECTED:\n+\t\t/*\n+\t\t * CONNECTED asks for this input and no other, which the\n+\t\t * device cannot be told to do: it selects by priority and the\n+\t\t * manual-active-select path is not wired up (see mode_set()).\n+\t\t * Refuse instead of quietly behaving like SELECTABLE.\n+\t\t */\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Device selects its reference by priority; use selectable\");\n+\t\trc = -EOPNOTSUPP;\n+\t\tbreak;\n+\tcase DPLL_PIN_STATE_SELECTABLE:\n+\t\t/*\n+\t\t * Gate the receiver on whenever it is off, not only when this\n+\t\t * DPLL holds no claim yet. The two are tracked separately --\n+\t\t * the claim comes from the priority table, the receiver from\n+\t\t * the force bits -- so a PLL that already lists the input can\n+\t\t * still find it powered down, and skipping the enable would\n+\t\t * report success for a reference that cannot reach the loop.\n+\t\t */\n+\t\tif (!ref-\u003eenabled) {\n+\t\t\trc = sit9531x_input_enable(sitdev, dpin-\u003eid);\n+\t\t\tif (rc)\n+\t\t\t\tbreak;\n+\t\t\tenabled_here = true;\n+\t\t}\n+\t\trc = sit9531x_input_prio_add(sitdev, sitdpll-\u003eid, hw_src);\n+\t\tif (rc \u0026\u0026 !sit9531x_input_prio_present(sitdev, sitdpll-\u003eid,\n+\t\t\t\t\t\t hw_src)) {\n+\t\t\t/*\n+\t\t\t * Undo only what this request did. A receiver the\n+\t\t\t * loaded configuration had already turned on is not\n+\t\t\t * this request's to turn off.\n+\t\t\t */\n+\t\t\tif (enabled_here)\n+\t\t\t\tsit9531x_input_disable(sitdev, dpin-\u003eid);\n+\t\t\tbreak;\n+\t\t}\n+\t\t/*\n+\t\t * Claim the input for this DPLL only once it is both enabled\n+\t\t * and present in the priority table. Setting the mask before\n+\t\t * prio_add would leak the claim if prio_add failed, keeping the\n+\t\t * shared input receiver powered even after every DPLL released\n+\t\t * it.\n+\t\t */\n+\t\tref-\u003epll_mask |= pll_bit;\n+\t\tbreak;\n+\tdefault:\n+\t\trc = -EINVAL;\n+\t\tbreak;\n+\t}\n+\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\t/*\n+\t * Leave the messages the switch already set in place; only a failure\n+\t * that came from the hardware path still needs one.\n+\t */\n+\tif (rc == -ENOSPC)\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Priority table is full of unique sources on this PLL\");\n+\telse if (rc \u0026\u0026 rc != -EOPNOTSUPP \u0026\u0026 rc != -EINVAL)\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to set input pin state\");\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_dpll_input_pin_prio_get - read input pin priority\n+ *\n+ * Reports the cached slot from sit9531x_input_prio_get(). The cache is\n+ * refreshed from hardware at startup and by periodic read-back, so pin-get\n+ * reports hardware priority without synchronous per-pin I2C reads.\n+ */\n+static int\n+sit9531x_dpll_input_pin_prio_get(const struct dpll_pin *pin, void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv, u32 *prio,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tu8 slot;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_input_prio_get(sitdev, sitdpll-\u003eid,\n+\t\t\t\t sit9531x_input_hw_src(dpin-\u003eid), \u0026slot);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tdpin-\u003eprio = slot;\n+\t*prio = slot;\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_input_pin_prio_set - set input pin priority\n+ *\n+ * writes input priority table on Page 1 via\n+ * core.c sit9531x_input_prio_set(). Forces holdover during update.\n+ */\n+static int\n+sit9531x_dpll_input_pin_prio_set(const struct dpll_pin *pin, void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv, u32 prio,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct dpll_pin *changed[SIT9531X_MAX_INPUTS + 1];\n+\tstruct sit9531x_dpll_pin *sibling;\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tu8 changed_cnt = 0, hw_src, slot;\n+\tint get_rc, rc;\n+\n+\tif (dpin-\u003edir != DPLL_PIN_DIRECTION_INPUT) {\n+\t\tNL_SET_ERR_MSG(extack, \"Priority applies only to input pins\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (prio \u003e= SIT9531X_PRIO_MAX_SLOTS) {\n+\t\tNL_SET_ERR_MSG(extack, \"Priority out of range (0-10)\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_input_prio_set(sitdev, sitdpll-\u003eid,\n+\t\t\t\t sit9531x_input_hw_src(dpin-\u003eid),\n+\t\t\t\t (u8)prio);\n+\tif (!rc) {\n+\t\tlist_for_each_entry(sibling, \u0026sitdpll-\u003epins, list) {\n+\t\t\tif (!sit9531x_dpll_is_input_pin(sibling) ||\n+\t\t\t sit9531x_dpll_is_xo_pin(sibling))\n+\t\t\t\tcontinue;\n+\n+\t\t\thw_src = sit9531x_input_hw_src(sibling-\u003eid);\n+\t\t\tget_rc = sit9531x_input_prio_get(sitdev, sitdpll-\u003eid,\n+\t\t\t\t\t\t\t hw_src, \u0026slot);\n+\t\t\tif (get_rc)\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (sibling-\u003eprio == slot)\n+\t\t\t\tcontinue;\n+\n+\t\t\tsibling-\u003eprio = slot;\n+\n+\t\t\t/*\n+\t\t\t * The core notifies the pin the request named, so\n+\t\t\t * only the others are collected here. A pin whose\n+\t\t\t * dpll_pin is already NULL is mid-unregister: that\n+\t\t\t * runs with the device lock dropped between the\n+\t\t\t * unregister and the free, so it can be seen from\n+\t\t\t * here, and notifying through it would follow a\n+\t\t\t * pointer that is on its way out.\n+\t\t\t */\n+\t\t\tif (sibling == dpin || !sibling-\u003edpll_pin)\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (changed_cnt \u003c ARRAY_SIZE(changed))\n+\t\t\t\tchanged[changed_cnt++] = sibling-\u003edpll_pin;\n+\t\t}\n+\t}\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (rc == -EINVAL) {\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Pin is not a reference of this DPLL; connect it first\");\n+\t\treturn rc;\n+\t}\n+\tif (rc == -ERANGE) {\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Priority is past the last reference this DPLL lists\");\n+\t\treturn rc;\n+\t}\n+\tif (rc) {\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to set input priority\");\n+\t\treturn rc;\n+\t}\n+\n+\t/*\n+\t * The core notifies only the pin the request named, so the ones whose\n+\t * slots moved are notified here. This runs inside a pin op, where\n+\t * the core already holds the lock the notification needs, so it is\n+\t * the underscore helper rather than the wrapper that takes it.\n+\t */\n+\twhile (changed_cnt--)\n+\t\t__dpll_pin_change_ntf(changed[changed_cnt]);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_input_pin_ffo_get - read the input's frequency offset\n+ *\n+ * The offset is derived from how far the PLL's running DIVN sits from\n+ * its configured one, which only says something about the reference the\n+ * PLL is actually tracking. For every other input there is no\n+ * measurement, and -ENODATA leaves the attribute out rather than\n+ * reporting the active reference's figure against the wrong pin.\n+ */\n+static int\n+sit9531x_dpll_input_pin_ffo_get(const struct dpll_pin *pin, void *pin_priv,\n+\t\t\t\tconst struct dpll_device *dpll, void *dpll_priv,\n+\t\t\t\tstruct dpll_ffo_param *ffo,\n+\t\t\t\tstruct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tenum dpll_pin_state state;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\t/*\n+\t * Publish FFO only for the input the DPLL is actively tracking.\n+\t * selected_ref alone is not enough (free-run, LOL, holdover), so use\n+\t * the same CONNECTED criterion as the generic selection-state logic.\n+\t */\n+\tsit9531x_dpll_selection_state_get(sitdev, sitdpll, dpin-\u003eid, \u0026state);\n+\tif (state != DPLL_PIN_STATE_CONNECTED) {\n+\t\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\t\treturn -ENODATA;\n+\t}\n+\n+\trc = sit9531x_pll_ffo_ppt(sitdev, sitdpll-\u003eid, \u0026ffo-\u003effo);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (rc \u0026\u0026 rc != -ENODATA)\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Failed to measure the frequency offset of the selected reference\");\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_dpll_input_pin_phase_offset_get - phase offset of a reference\n+ *\n+ * What this reports, and what it deliberately does not:\n+ *\n+ * The ABI defines the attribute as the phase difference between the signal\n+ * on a pin and its parent DPLL device, so this is the loop's own residual\n+ * error, sampled with the loop closed. On a locked DPLL it therefore\n+ * trends small -- that is the measurement, not an artefact of it. The\n+ * documentation describes the reported value as one that may be averaged\n+ * over prior measurements, which suits a closed-loop residual and not a\n+ * one-shot open-loop capture; the core publishes whatever this callback\n+ * returns, so the averaging, if any, would be this driver's to do.\n+ *\n+ * The chip can also measure the reference against the local oscillator\n+ * with the outer loop's correction frozen, which is a different quantity\n+ * and the one the documented phase-difference procedure produces. That\n+ * needs the digital loop filter held (and, on the 1PPS PLL, the automatic\n+ * phase- and frequency-lock helpers held off), which leaves the PLL\n+ * undisciplined until it is released. A netlink read must not do that,\n+ * so that measurement is not offered here at all; it belongs to a caller\n+ * that can own the freeze and restore it.\n+ *\n+ * Precondition, which this callback cannot create: the TDC compares\n+ * against a signal the PLL drives, so a PLL driving no output with its\n+ * zero-delay buffer off has nothing to measure. SiTime confirms this is\n+ * a property of the hardware rather than of their measurement script.\n+ * The script satisfies it by mapping a spare output and restarting the\n+ * PLL -- side effects that do not belong in a getter, so a reading taken\n+ * in that state is simply not meaningful.\n+ *\n+ * Non-selected pins and a PLL with no programmed divider report zero\n+ * rather than an error: the DPLL core propagates any error from this\n+ * callback and fails the whole pin dump with it, unlike the frequency\n+ * offset getter, where -ENODATA makes the core omit the attribute. There\n+ * is no per-pin \"no data\" for phase offset, so it is a value or no\n+ * callback at all.\n+ */\n+static int\n+sit9531x_dpll_input_pin_phase_offset_get(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv, s64 *phase_offset,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tenum dpll_pin_state state;\n+\ts64 offset;\n+\tu8 selected;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\t/*\n+\t * The on-chip TDC is a per-PLL resource that always measures the\n+\t * phase difference between the VCO and the PLL's currently\n+\t * selected reference; it cannot be pointed at an arbitrary input.\n+\t * For any input that is not the active reference there is no\n+\t * meaningful per-pin phase offset, so report 0 instead of the\n+\t * active reference's value.\n+\t */\n+\t/*\n+\t * Which pin the sample belongs to is read from the device rather\n+\t * than taken from the monitor's cache: the device selects its own\n+\t * reference, so a cache up to a poll period old could attribute a\n+\t * live measurement to the pin that used to be selected.\n+\t */\n+\trc = sit9531x_chan_selected_ref_read(sitdev, sitdpll-\u003eid,\n+\t\t\t\t\t \u0026selected);\n+\tif (rc) {\n+\t\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Selected reference could not be read back\");\n+\t\treturn rc;\n+\t}\n+\n+\tsit9531x_dpll_selection_state_get(sitdev, sitdpll, dpin-\u003eid, \u0026state);\n+\tif (state != DPLL_PIN_STATE_CONNECTED || selected != dpin-\u003eid) {\n+\t\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\t\t*phase_offset = 0;\n+\t\treturn 0;\n+\t}\n+\n+\trc = sit9531x_phase_offset_read(sitdev, sitdpll-\u003eid, \u0026offset);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\t/*\n+\t * -ENODATA means the PLL has no programmed DIVN (unused on this\n+\t * board); report phase_offset = 0 so a full pin-get dump does not\n+\t * fail just because one DPLL is dormant. Every other errno,\n+\t * -ENODEV from a vanished adapter included, is a failure.\n+\t */\n+\tif (rc == -ENODATA) {\n+\t\t*phase_offset = 0;\n+\t\treturn 0;\n+\t}\n+\tif (rc) {\n+\t\tNL_SET_ERR_MSG(extack, \"TDC phase readback failed\");\n+\t\treturn rc;\n+\t}\n+\n+\t/*\n+\t * The ABI reports phase offset in units of 1/DPLL_PHASE_OFFSET_DIVIDER\n+\t * picoseconds: the integer part of the attribute is the value divided\n+\t * by the divider, the remainder is the fraction. The TDC resolves one\n+\t * VCO period (hundreds of picoseconds), so the fractional digits are\n+\t * always zero here, but the magnitude still has to be scaled or every\n+\t * reading would be reported a thousand times too small.\n+\t */\n+\toffset *= DPLL_PHASE_OFFSET_DIVIDER;\n+\n+\t*phase_offset = offset;\n+\treturn 0;\n+}\n+\n+static const struct dpll_pin_ops sit9531x_dpll_input_pin_ops = {\n+\t.direction_get\t\t= sit9531x_dpll_input_pin_direction_get,\n+\t.frequency_get\t\t= sit9531x_dpll_input_pin_frequency_get,\n+\t.state_on_dpll_get\t= sit9531x_dpll_input_pin_state_on_dpll_get,\n+\t.state_on_dpll_set\t= sit9531x_dpll_input_pin_state_on_dpll_set,\n+\t.prio_get\t\t= sit9531x_dpll_input_pin_prio_get,\n+\t.prio_set\t\t= sit9531x_dpll_input_pin_prio_set,\n+\t.phase_offset_get\t= sit9531x_dpll_input_pin_phase_offset_get,\n+\t/*\n+\t * The measurement compares the PLL's running feedback divider with\n+\t * its configured one, so it describes the device's own reference\n+\t * rather than a port rate.\n+\t */\n+\t.supported_ffo\t\t= BIT(DPLL_FFO_PIN_DEVICE),\n+\t.ffo_get\t\t= sit9531x_dpll_input_pin_ffo_get,\n+};\n+\n+/*\n+ * INTSYNC pin ops\n+ *\n+ * INTSYNC is the chip's inter-PLL sync net: one PLL drives it and other\n+ * PLLs may lock to it instead of to an external reference. The two\n+ * roles are exposed as two separate pins so neither overloads the other:\n+ *\n+ * - a source (output) pin registered on every DPLL. Connecting it on a\n+ * DPLL makes that DPLL drive INTSYNC; only one DPLL may drive it at a\n+ * time. It has no priority ops -- driving the net is not a reference\n+ * selection.\n+ * - a destination (input) pin registered on every DPLL. Connecting it\n+ * on a DPLL makes that DPLL eligible to lock to INTSYNC as a\n+ * reference, so it carries the priority ops.\n+ */\n+\n+/* ---- INTSYNC source (output) pin ---- */\n+\n+/* The INTSYNC source pin is an output; its direction_get is defined below. */\n+static int\n+sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin,\n+\t\t\t\t void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv,\n+\t\t\t\t enum dpll_pin_direction *direction,\n+\t\t\t\t struct netlink_ext_ack *extack);\n+\n+static int\n+sit9531x_dpll_intsync_src_state_on_dpll_get(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state *state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\tif (sitdev-\u003eintsync_src == sitdpll-\u003eid)\n+\t\t*state = DPLL_PIN_STATE_CONNECTED;\n+\telse\n+\t\t*state = DPLL_PIN_STATE_DISCONNECTED;\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_intsync_src_state_on_dpll_set - drive INTSYNC from a PLL\n+ *\n+ * CONNECTED -\u003e this PLL drives the INTSYNC net\n+ * DISCONNECTED -\u003e stop driving INTSYNC if this PLL drives it\n+ *\n+ * SELECTABLE is rejected: driving the net is an explicit output routing,\n+ * not an automatic-selection candidate, matching the regular output pin.\n+ */\n+static int\n+sit9531x_dpll_intsync_src_state_on_dpll_set(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tint rc = 0, detect_rc = 0;\n+\tu8 hw_src;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tswitch (state) {\n+\tcase DPLL_PIN_STATE_CONNECTED:\n+\t\tif (sitdev-\u003eintsync_src == sitdpll-\u003eid)\n+\t\t\tbreak;\n+\t\tif (sitdev-\u003eintsync_src \u003e= 0) {\n+\t\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t\t \"INTSYNC is already sourced by another PLL\");\n+\t\t\trc = -EBUSY;\n+\t\t\tbreak;\n+\t\t}\n+\t\t/*\n+\t\t * A PLL that already lists INTSYNC among its references must\n+\t\t * not also drive it: the destination side refuses the mirror\n+\t\t * of this, and without the check here the net could be routed\n+\t\t * back into the PLL feeding it.\n+\t\t */\n+\t\thw_src = sit9531x_input_hw_src(SIT9531X_INTSYNC_PIN_ID);\n+\t\tif (sit9531x_input_prio_present(sitdev, sitdpll-\u003eid, hw_src)) {\n+\t\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t\t \"PLL selects INTSYNC as a reference; it cannot drive it\");\n+\t\t\trc = -EBUSY;\n+\t\t\tbreak;\n+\t\t}\n+\t\trc = sit9531x_intsync_enable(sitdev, sitdpll-\u003eid);\n+\t\tbreak;\n+\tcase DPLL_PIN_STATE_DISCONNECTED:\n+\t\tif (sitdev-\u003eintsync_src != sitdpll-\u003eid)\n+\t\t\tbreak;\n+\t\trc = sit9531x_intsync_disable(sitdev, sitdpll-\u003eid);\n+\t\tbreak;\n+\tdefault:\n+\t\trc = -EINVAL;\n+\t\tbreak;\n+\t}\n+\n+\t/*\n+\t * Re-scan hardware after source state transitions so cache follows\n+\t * partially failed enable/disable paths as closely as possible.\n+\t */\n+\t/*\n+\t * Record what was asked for before confirming it. The refresh below\n+\t * leaves the cache untouched when a read fails, and a cache that\n+\t * still says nobody drives the net would let a second PLL be\n+\t * configured to drive it as well.\n+\t */\n+\tif (!rc \u0026\u0026 state == DPLL_PIN_STATE_CONNECTED)\n+\t\tsitdev-\u003eintsync_src = sitdpll-\u003eid;\n+\telse if (!rc \u0026\u0026 state == DPLL_PIN_STATE_DISCONNECTED)\n+\t\tsitdev-\u003eintsync_src = -1;\n+\n+\tif (state == DPLL_PIN_STATE_CONNECTED ||\n+\t state == DPLL_PIN_STATE_DISCONNECTED)\n+\t\tdetect_rc = sit9531x_intsync_src_detect(sitdev);\n+\t/*\n+\t * The refresh only re-reads what the device now shows. Failing\n+\t * the request because that read hit a bus error would tell\n+\t * userspace the enable did not happen when it did.\n+\t */\n+\tif (detect_rc)\n+\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t \"INTSYNC source cache not refreshed: %d\\n\",\n+\t\t\t detect_rc);\n+\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (rc \u0026\u0026 rc != -EBUSY \u0026\u0026 rc != -EINVAL \u0026\u0026 rc != -EOPNOTSUPP)\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to set INTSYNC source state\");\n+\n+\treturn rc;\n+}\n+\n+static const struct dpll_pin_ops sit9531x_dpll_intsync_src_pin_ops = {\n+\t.direction_get\t\t= sit9531x_dpll_output_pin_direction_get,\n+\t.state_on_dpll_get\t= sit9531x_dpll_intsync_src_state_on_dpll_get,\n+\t.state_on_dpll_set\t= sit9531x_dpll_intsync_src_state_on_dpll_set,\n+};\n+\n+/* ---- INTSYNC destination (input) pin ---- */\n+\n+/*\n+ * sit9531x_dpll_intsync_dst_state_on_dpll_get - INTSYNC reference state\n+ *\n+ * Selection role, so the contract above decides this exactly as it does\n+ * for a physical input: the priority table is the eligibility record, and\n+ * whether a source PLL happens to be driving the net right now is no more\n+ * a state than a momentary LOS is on an external reference. The one\n+ * addition is that the PLL driving INTSYNC is never its own destination.\n+ */\n+static int\n+sit9531x_dpll_intsync_dst_state_on_dpll_get(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state *state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\tif (sitdev-\u003eintsync_src == sitdpll-\u003eid)\n+\t\t*state = DPLL_PIN_STATE_DISCONNECTED;\n+\telse\n+\t\tsit9531x_dpll_selection_state_get(sitdev, sitdpll,\n+\t\t\t\t\t\t SIT9531X_INTSYNC_PIN_ID,\n+\t\t\t\t\t\t state);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_intsync_dst_state_on_dpll_set - lock a PLL to INTSYNC\n+ *\n+ * Selection role, so this accepts and refuses what a physical input does,\n+ * CONNECTED included: the device pins no reference on request whichever\n+ * source is asked for. INTSYNC is an internal net with no physical\n+ * receiver, so only the per-PLL priority table is touched; the source pin\n+ * controls generation.\n+ */\n+static int\n+sit9531x_dpll_intsync_dst_state_on_dpll_set(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tu8 hw_src = sit9531x_input_hw_src(SIT9531X_INTSYNC_PIN_ID);\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tswitch (state) {\n+\tcase DPLL_PIN_STATE_DISCONNECTED:\n+\t\trc = sit9531x_input_prio_remove(sitdev, sitdpll-\u003eid, hw_src);\n+\t\tbreak;\n+\tcase DPLL_PIN_STATE_CONNECTED:\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Device selects its reference by priority; use selectable\");\n+\t\trc = -EOPNOTSUPP;\n+\t\tbreak;\n+\tcase DPLL_PIN_STATE_SELECTABLE:\n+\t\tif (sitdev-\u003eintsync_src == sitdpll-\u003eid) {\n+\t\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t\t \"PLL cannot lock to the INTSYNC it drives\");\n+\t\t\trc = -EINVAL;\n+\t\t\tbreak;\n+\t\t}\n+\t\trc = sit9531x_input_prio_add(sitdev, sitdpll-\u003eid, hw_src);\n+\t\tbreak;\n+\tdefault:\n+\t\trc = -EINVAL;\n+\t\tbreak;\n+\t}\n+\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (rc == -ENOSPC)\n+\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t \"Priority table is full of unique sources on this PLL\");\n+\telse if (rc \u0026\u0026 rc != -EINVAL \u0026\u0026 rc != -EOPNOTSUPP)\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to set INTSYNC input state\");\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * Do not add .frequency_get / the generic input state getter here: the\n+ * destination pin id is SIT9531X_INTSYNC_PIN_ID, one past the end of the\n+ * ref[] array (INTSYNC is an internal net with no ref[] entry). The ops\n+ * below only ever key on chan[] and the priority table, never ref[id].\n+ */\n+static const struct dpll_pin_ops sit9531x_dpll_intsync_dst_pin_ops = {\n+\t.direction_get\t\t= sit9531x_dpll_input_pin_direction_get,\n+\t.state_on_dpll_get\t= sit9531x_dpll_intsync_dst_state_on_dpll_get,\n+\t.state_on_dpll_set\t= sit9531x_dpll_intsync_dst_state_on_dpll_set,\n+\t.prio_get\t\t= sit9531x_dpll_input_pin_prio_get,\n+\t.prio_set\t\t= sit9531x_dpll_input_pin_prio_set,\n+};\n+\n+/*\n+ * XO (crystal oscillator) pin ops\n+ *\n+ * The XO is the chip's internal reference oscillator that feeds every\n+ * PLL. It is exposed so userspace can see the on-chip reference, but it\n+ * cannot be routed or disconnected, so it is reported permanently\n+ * connected and offers no state_on_dpll_set / prio ops.\n+ */\n+\n+static int\n+sit9531x_dpll_xo_pin_state_on_dpll_get(const struct dpll_pin *pin,\n+\t\t\t\t void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv,\n+\t\t\t\t enum dpll_pin_state *state,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\t*state = DPLL_PIN_STATE_CONNECTED;\n+\treturn 0;\n+}\n+\n+static const struct dpll_pin_ops sit9531x_dpll_xo_pin_ops = {\n+\t.direction_get\t\t= sit9531x_dpll_input_pin_direction_get,\n+\t.frequency_get\t\t= sit9531x_dpll_input_pin_frequency_get,\n+\t.state_on_dpll_get\t= sit9531x_dpll_xo_pin_state_on_dpll_get,\n+};\n+\n+static int\n+sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin,\n+\t\t\t\t void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv,\n+\t\t\t\t enum dpll_pin_direction *direction,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\t*direction = DPLL_PIN_DIRECTION_OUTPUT;\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_output_pin_frequency_get - read output pin frequency\n+ *\n+ * Reads the DIVO divider back from the chip and computes the live\n+ * frequency as Fvco / DIVO. Falls back to the cached value only when\n+ * the output is not resolvable through the divider chain (e.g. not\n+ * mapped to a PLL), so transport/register errors still surface.\n+ */\n+static int\n+sit9531x_dpll_output_pin_frequency_get(const struct dpll_pin *pin,\n+\t\t\t\t void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv, u64 *frequency,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_output_freq_get(sitdev, dpin-\u003eid, frequency);\n+\tif (rc == -ENODEV)\n+\t\t*frequency = sit9531x_out_state_get(sitdev, dpin-\u003eid)-\u003efreq;\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\treturn rc == -ENODEV ? 0 : rc;\n+}\n+\n+/*\n+ * sit9531x_dpll_output_pin_frequency_set - set output pin frequency\n+ *\n+ * computes DIVO = Fvco / frequency and writes the\n+ * 34-bit output divider to the output system registers via\n+ * sit9531x_output_freq_set().\n+ */\n+static int\n+sit9531x_dpll_output_pin_frequency_set(const struct dpll_pin *pin,\n+\t\t\t\t void *pin_priv,\n+\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t void *dpll_priv, u64 frequency,\n+\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tu8 actual_pll;\n+\tint rc;\n+\n+\t/*\n+\t * Read the PLL that drives this output from its OUT_MAP state\n+\t * (populated by out_state_fetch from the chip's OUT_MAP registers).\n+\t * That is the index the output register programming below is keyed\n+\t * by; the output is registered under the DPLL matching this PLL.\n+\t */\n+\tactual_pll = sitdev-\u003eout[dpin-\u003eid].pll_idx;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_output_freq_set(sitdev, dpin-\u003eid, actual_pll,\n+\t\t\t\t frequency);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (rc)\n+\t\tNL_SET_ERR_MSG(extack, \"Output frequency set failed\");\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_dpll_output_pin_state_on_dpll_get - get output pin state\n+ *\n+ * reports CONNECTED when the output is driven and\n+ * DISCONNECTED when it has been muted via sit9531x_output_disable().\n+ */\n+static int\n+sit9531x_dpll_output_pin_state_on_dpll_get(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state *state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tconst struct sit9531x_out *out;\n+\tint rc;\n+\n+\t/*\n+\t * A mute whose read-back failed left the cache unconfirmed; there is\n+\t * no poll of output state to correct it, so read it here rather than\n+\t * report a value that may predate the request.\n+\t */\n+\tif (sitdev-\u003eout[dpin-\u003eid].state_stale) {\n+\t\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\t\trc = sit9531x_output_state_refresh(sitdev, dpin-\u003eid);\n+\t\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\t\tif (rc) {\n+\t\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t\t \"Output mute state could not be read back\");\n+\t\t\treturn rc;\n+\t\t}\n+\t}\n+\n+\tout = sit9531x_out_state_get(sitdev, dpin-\u003eid);\n+\t*state = out-\u003eenabled ? DPLL_PIN_STATE_CONNECTED\n+\t\t\t : DPLL_PIN_STATE_DISCONNECTED;\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_output_pin_state_on_dpll_set - mute/un-mute an output\n+ *\n+ * forces Hi-Z on the output pin via the Page 0x03\n+ * force/state register pair.\n+ * CONNECTED -\u003e enable (release force, back to factory default)\n+ * DISCONNECTED -\u003e disable (force Hi-Z)\n+ */\n+static int\n+sit9531x_dpll_output_pin_state_on_dpll_set(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv,\n+\t\t\t\t\t enum dpll_pin_state state,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tswitch (state) {\n+\tcase DPLL_PIN_STATE_CONNECTED:\n+\t\trc = sit9531x_output_enable(sitdev, dpin-\u003eid);\n+\t\tbreak;\n+\tcase DPLL_PIN_STATE_DISCONNECTED:\n+\t\trc = sit9531x_output_disable(sitdev, dpin-\u003eid);\n+\t\tbreak;\n+\tdefault:\n+\t\trc = -EINVAL;\n+\t\tbreak;\n+\t}\n+\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (rc)\n+\t\tNL_SET_ERR_MSG(extack, \"Failed to set output pin state\");\n+\n+\treturn rc;\n+}\n+\n+/*\n+ * sit9531x_dpll_output_pin_phase_adjust_get - read output phase adjustment\n+ *\n+ * Returns what the delay registers hold, i.e. the value\n+ * sit9531x_output_phase_adjust_set() programmed after quantization, read\n+ * from the cache unless a failed request left it unconfirmed.\n+ */\n+static int\n+sit9531x_dpll_output_pin_phase_adjust_get(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv, s32 *phase_adjust,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\t/*\n+\t * A request whose writes reached the device but whose commit or\n+\t * phase flush failed left the cache describing the delay before it.\n+\t * There is no poll of the delay registers to correct that, so read\n+\t * them here rather than report a value the output is not using.\n+\t */\n+\tif (sitdev-\u003eout[dpin-\u003eid].phase_stale) {\n+\t\ts32 phase_ps;\n+\n+\t\trc = sit9531x_output_phase_read(sitdev, dpin-\u003eid, \u0026phase_ps);\n+\t\tif (rc) {\n+\t\t\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\t\t\tNL_SET_ERR_MSG(extack,\n+\t\t\t\t \"Output delay could not be read back\");\n+\t\t\treturn rc;\n+\t\t}\n+\t\tsitdev-\u003eout[dpin-\u003eid].phase_adj = phase_ps;\n+\t\tsitdev-\u003eout[dpin-\u003eid].phase_armed = !!phase_ps;\n+\t\tsitdev-\u003eout[dpin-\u003eid].phase_stale = false;\n+\t}\n+\t*phase_adjust = sit9531x_out_state_get(sitdev, dpin-\u003eid)-\u003ephase_adj;\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * sit9531x_dpll_output_pin_phase_adjust_set - set output phase adjustment\n+ *\n+ * Programs the per-output PRG_RST_DELAY registers for deterministic\n+ * phase offset; see sit9531x_output_phase_adjust_set() in core.c.\n+ */\n+static int\n+sit9531x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *pin,\n+\t\t\t\t\t void *pin_priv,\n+\t\t\t\t\t const struct dpll_device *dpll,\n+\t\t\t\t\t void *dpll_priv, s32 phase_adjust,\n+\t\t\t\t\t struct netlink_ext_ack *extack)\n+{\n+\tstruct sit9531x_dpll_pin *dpin = pin_priv;\n+\tstruct sit9531x_dpll *sitdpll = dpll_priv;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tint rc;\n+\n+\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\trc = sit9531x_output_phase_adjust_set(sitdev, dpin-\u003eid, phase_adjust);\n+\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\n+\tif (rc) {\n+\t\tNL_SET_ERR_MSG(extack, \"Phase adjust failed\");\n+\t\treturn rc;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static const struct dpll_pin_ops sit9531x_dpll_output_pin_ops = {\n+\t.direction_get\t\t= sit9531x_dpll_output_pin_direction_get,\n+\t.frequency_get\t\t= sit9531x_dpll_output_pin_frequency_get,\n+\t.frequency_set\t\t= sit9531x_dpll_output_pin_frequency_set,\n+\t.state_on_dpll_get\t= sit9531x_dpll_output_pin_state_on_dpll_get,\n+\t.state_on_dpll_set\t= sit9531x_dpll_output_pin_state_on_dpll_set,\n+\t.phase_adjust_get\t= sit9531x_dpll_output_pin_phase_adjust_get,\n+\t.phase_adjust_set\t= sit9531x_dpll_output_pin_phase_adjust_set,\n+};\n+\n+const struct dpll_pin_ops *\n+sit9531x_dpll_pin_ops_get(const struct sit9531x_dpll_pin *pin)\n+{\n+\tif (!sit9531x_dpll_is_input_pin(pin)) {\n+\t\tif (sit9531x_dpll_is_intsync_src_pin(pin))\n+\t\t\treturn \u0026sit9531x_dpll_intsync_src_pin_ops;\n+\t\treturn \u0026sit9531x_dpll_output_pin_ops;\n+\t}\n+\tif (sit9531x_dpll_is_intsync_pin(pin))\n+\t\treturn \u0026sit9531x_dpll_intsync_dst_pin_ops;\n+\tif (sit9531x_dpll_is_xo_pin(pin))\n+\t\treturn \u0026sit9531x_dpll_xo_pin_ops;\n+\treturn \u0026sit9531x_dpll_input_pin_ops;\n+}\n+\n+/*\n+ * sit9531x_dpll_changes_check - check for state changes and notify\n+ *\n+ * Called from sit9531x_dev_periodic_work(). Compares current hardware\n+ * state against cached values and sends netlink notifications on changes.\n+ */\n+void sit9531x_dpll_changes_check(struct sit9531x_dpll *sitdpll)\n+{\n+\tenum dpll_lock_status_error status_error = DPLL_LOCK_STATUS_ERROR_NONE;\n+\tstruct sit9531x_dev *sitdev = sitdpll-\u003edev;\n+\tenum dpll_lock_status lock_status;\n+\tstruct sit9531x_dpll_pin *pin;\n+\tint rc;\n+\n+\trc = sit9531x_dpll_lock_status_get(sitdpll-\u003edpll_dev, sitdpll,\n+\t\t\t\t\t \u0026lock_status, \u0026status_error, NULL);\n+\tif (rc) {\n+\t\tdev_err(sitdev-\u003edev, \"Failed to get DPLL%u lock status: %d\\n\",\n+\t\t\tsitdpll-\u003eid, rc);\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * The core publishes the error detail alongside the status, so a\n+\t * change in either is a change subscribers have to be told about:\n+\t * an inner loss of lock appearing or clearing while the status\n+\t * stays UNLOCKED would otherwise be visible only to a later GET.\n+\t */\n+\tif (sitdpll-\u003elock_status != lock_status ||\n+\t sitdpll-\u003elock_status_error != status_error) {\n+\t\tsitdpll-\u003elock_status = lock_status;\n+\t\tsitdpll-\u003elock_status_error = status_error;\n+\t\tdpll_device_change_ntf(sitdpll-\u003edpll_dev);\n+\t}\n+\n+\tlist_for_each_entry(pin, \u0026sitdpll-\u003epins, list) {\n+\t\tconst struct dpll_pin_ops *ops;\n+\t\tenum dpll_pin_state state;\n+\n+\t\t/*\n+\t\t * Poll input pins whose state can change autonomously: regular\n+\t\t * references and the INTSYNC destination pin. Outputs (incl.\n+\t\t * the INTSYNC source) change only through their own set\n+\t\t * callback and the XO is permanently connected, so skip those.\n+\t\t * Each pin's state_on_dpll_get resolves to the right getter.\n+\t\t */\n+\t\tif (!sit9531x_dpll_is_input_pin(pin) ||\n+\t\t sit9531x_dpll_is_xo_pin(pin))\n+\t\t\tcontinue;\n+\n+\t\tops = sit9531x_dpll_pin_ops_get(pin);\n+\t\trc = ops-\u003estate_on_dpll_get(pin-\u003edpll_pin, pin,\n+\t\t\t\t\t sitdpll-\u003edpll_dev, sitdpll,\n+\t\t\t\t\t \u0026state, NULL);\n+\t\tif (rc)\n+\t\t\tcontinue;\n+\n+\t\tif (state != pin-\u003epin_state) {\n+\t\t\tdev_dbg(sitdev-\u003edev, \"%s state changed: %u-\u003e%u\\n\",\n+\t\t\t\tpin-\u003elabel, pin-\u003epin_state, state);\n+\t\t\tpin-\u003epin_state = state;\n+\t\t\tdpll_pin_change_ntf(pin-\u003edpll_pin);\n+\t\t}\n+\t}\n+}\ndiff --git a/drivers/dpll/sit9531x/dpll.h b/drivers/dpll/sit9531x/dpll.h\nnew file mode 100644\nindex 0000000000000..d6ef799d52c2f\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/dpll.h\n@@ -0,0 +1,66 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * SiTime SiT9531x DPLL subsystem interface\n+ *\n+ * Copyright (C) 2026 SiTime Corp.\n+ * Author: Ali Rouhi \u003carouhi@sitime.com\u003e\n+ * Author: Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\n+ *\n+ * DPLL device and pin structures, and function declarations for\n+ * the DPLL registration and callback layer.\n+ */\n+\n+#ifndef _SIT9531X_DPLL_H\n+#define _SIT9531X_DPLL_H\n+\n+#include \u003clinux/dpll.h\u003e\n+#include \u003clinux/list.h\u003e\n+#include \u003clinux/types.h\u003e\n+\n+struct sit9531x_dev;\n+\n+/* Per-pin DPLL state. */\n+struct sit9531x_dpll_pin {\n+\tstruct list_head\t\tlist;\n+\tstruct sit9531x_dpll\t\t*dpll;\n+\tstruct dpll_pin\t\t\t*dpll_pin;\n+\tdpll_tracker\t\t\ttracker;\n+\tstruct fwnode_handle\t\t*fwnode;\n+\tchar\t\t\t\tlabel[8];\t/* \"IN0\", \"OUT3\" */\n+\tenum dpll_pin_direction\t\tdir;\n+\tu8\t\t\t\tid;\t\t/* hardware index */\n+\tu8\t\t\t\tprio;\n+\tenum dpll_pin_state\t\tpin_state;\n+};\n+\n+/* Per-PLL DPLL device state. */\n+struct sit9531x_dpll {\n+\tstruct list_head\t\tlist;\n+\tstruct sit9531x_dev\t\t*dev;\n+\tstruct dpll_device\t\t*dpll_dev;\n+\tdpll_tracker\t\t\ttracker;\n+\tstruct dpll_device_ops\t\tops;\t/* per-instance copy */\n+\tstruct list_head\t\tpins;\n+\tu8\t\t\t\tid;\t/* 0 = PLLA .. 3 = PLLD */\n+\tenum dpll_lock_status\t\tlock_status;\n+\tenum dpll_lock_status_error\tlock_status_error;\n+};\n+\n+/* ---- DPLL allocation and registration ---- */\n+/*\n+ * The callback tables stay with the callbacks; the registration code that\n+ * hands them to the subsystem lives next to probe() in core.c.\n+ */\n+extern const struct dpll_device_ops sit9531x_dpll_device_ops;\n+const struct dpll_pin_ops *\n+sit9531x_dpll_pin_ops_get(const struct sit9531x_dpll_pin *pin);\n+\n+struct sit9531x_dpll *sit9531x_dpll_alloc(struct sit9531x_dev *sitdev, u8 ch);\n+void sit9531x_dpll_free(struct sit9531x_dpll *sitdpll);\n+int sit9531x_dpll_register(struct sit9531x_dpll *sitdpll);\n+void sit9531x_dpll_unregister(struct sit9531x_dpll *sitdpll);\n+\n+/* ---- Periodic change detection ---- */\n+void sit9531x_dpll_changes_check(struct sit9531x_dpll *sitdpll);\n+\n+#endif /* _SIT9531X_DPLL_H */\ndiff --git a/drivers/dpll/sit9531x/prop.c b/drivers/dpll/sit9531x/prop.c\nnew file mode 100644\nindex 0000000000000..82e8cd2266f5a\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/prop.c\n@@ -0,0 +1,469 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * SiTime SiT9531x firmware node property parsing\n+ *\n+ * Copyright (C) 2026 SiTime Corp.\n+ * Author: Ali Rouhi \u003carouhi@sitime.com\u003e\n+ * Author: Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\n+ *\n+ * Retrieves pin properties from Device Tree firmware nodes (or\n+ * applies defaults when no firmware node exists).\n+ */\n+\n+#include \u003clinux/dev_printk.h\u003e\n+#include \u003clinux/dpll.h\u003e\n+#include \u003clinux/err.h\u003e\n+#include \u003clinux/fwnode.h\u003e\n+#include \u003clinux/property.h\u003e\n+#include \u003clinux/slab.h\u003e\n+#include \u003clinux/string.h\u003e\n+\n+#include \"core.h\"\n+#include \"prop.h\"\n+\n+/*\n+ * sit9531x_input_pin_label - fill the package label for an input pin\n+ *\n+ * Split out so input-naming changes stay local to this helper.\n+ */\n+static void sit9531x_input_pin_label(struct sit9531x_dev *sitdev,\n+\t\t\t\t struct sit9531x_pin_props *props, u8 id)\n+{\n+\tu8 pair = sit9531x_input_pair(id);\n+\n+\tif (sitdev-\u003eref[id].sig_mode == SIT9531X_MODE_DE)\n+\t\tsnprintf(props-\u003epackage_label,\n+\t\t\t sizeof(props-\u003epackage_label), \"IN%u\", pair);\n+\telse\n+\t\tsnprintf(props-\u003epackage_label,\n+\t\t\t sizeof(props-\u003epackage_label), \"IN%u%c\", pair,\n+\t\t\t sit9531x_input_is_n(id) ? 'N' : 'P');\n+}\n+\n+/*\n+ * sit9531x_prop_pin_package_label_set - generate package label\n+ * @dir:\tpin direction\n+ * @id:\t\tpin index\n+ *\n+ * Generates a package label string. Output pins are named \"OUT0\",\n+ * \"OUT1\", ... Input pins are named after the physical pair and lane:\n+ * \"IN0P\", \"IN0N\", \"IN1P\", ... for single-ended lanes, or \"IN0\",\n+ * \"IN1\", ... when the pair is configured differential (the N lane is\n+ * not registered in that case).\n+ */\n+static void\n+sit9531x_prop_pin_package_label_set(struct sit9531x_dev *sitdev,\n+\t\t\t\t struct sit9531x_pin_props *props,\n+\t\t\t\t enum dpll_pin_direction dir, u8 id)\n+{\n+\t/* The internal INTSYNC pin has a fixed label */\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT \u0026\u0026\n+\t id == SIT9531X_INTSYNC_PIN_ID) {\n+\t\tstrscpy(props-\u003epackage_label, \"INTSYNC\",\n+\t\t\tsizeof(props-\u003epackage_label));\n+\t\tprops-\u003edpll_props.package_label = props-\u003epackage_label;\n+\t\treturn;\n+\t}\n+\n+\t/* The internal XO reference has a fixed label */\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT \u0026\u0026 id == SIT9531X_MAX_INPUTS) {\n+\t\tstrscpy(props-\u003epackage_label, \"XO\",\n+\t\t\tsizeof(props-\u003epackage_label));\n+\t\tprops-\u003edpll_props.package_label = props-\u003epackage_label;\n+\t\treturn;\n+\t}\n+\n+\t/* The internal INTSYNC source (output) pin has a fixed label */\n+\tif (dir == DPLL_PIN_DIRECTION_OUTPUT \u0026\u0026\n+\t id == SIT9531X_INTSYNC_OUT_PIN_ID) {\n+\t\tstrscpy(props-\u003epackage_label, \"SYNCOUT\",\n+\t\t\tsizeof(props-\u003epackage_label));\n+\t\tprops-\u003edpll_props.package_label = props-\u003epackage_label;\n+\t\treturn;\n+\t}\n+\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT)\n+\t\tsit9531x_input_pin_label(sitdev, props, id);\n+\telse\n+\t\t/*\n+\t\t * Name the chip pin, not the driver's index for it. The\n+\t\t * two differ on the variant whose outputs are bonded out\n+\t\t * from a subset of the twelve slots, and a package label\n+\t\t * that named the index would point at a pin that is not\n+\t\t * the one being driven.\n+\t\t */\n+\t\tsnprintf(props-\u003epackage_label, sizeof(props-\u003epackage_label),\n+\t\t\t \"OUT%u\", sitdev-\u003einfo-\u003eclkout_map[id]);\n+\n+\tprops-\u003edpll_props.package_label = props-\u003epackage_label;\n+}\n+\n+/*\n+ * sit9531x_prop_pin_fwnode_get - find firmware node for a pin\n+ * @dir:\tpin direction\n+ * @id:\t\tpin index\n+ *\n+ * Searches for input-pins/output-pins child nodes in DT, looking for a\n+ * child whose \"reg\" property matches the pin. The binding describes reg\n+ * as the hardware index, so an output is matched by the chip slot it\n+ * drives rather than by the driver's index for it: on the variant where\n+ * the two differ, a board describing the pin it wired would otherwise\n+ * have its properties applied to a different one.\n+ *\n+ * Return: 0 on success, -ENOENT if no firmware node exists\n+ */\n+static int\n+sit9531x_prop_pin_fwnode_get(struct sit9531x_dev *sitdev,\n+\t\t\t struct sit9531x_pin_props *props,\n+\t\t\t enum dpll_pin_direction dir, u8 id)\n+{\n+\tstruct fwnode_handle *pins_node, *pin_node;\n+\tconst char *node_name;\n+\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT) {\n+\t\tnode_name = \"input-pins\";\n+\t} else {\n+\t\tnode_name = \"output-pins\";\n+\t\tif (id \u003c sitdev-\u003einfo-\u003enum_outputs)\n+\t\t\tid = sitdev-\u003einfo-\u003eclkout_map[id];\n+\t}\n+\n+\tpins_node = device_get_named_child_node(sitdev-\u003edev, node_name);\n+\tif (!pins_node) {\n+\t\tdev_dbg(sitdev-\u003edev, \"'%s' sub-node is missing\\n\", node_name);\n+\t\treturn -ENOENT;\n+\t}\n+\n+\t/* Enumerate child pin nodes and find the requested one */\n+\tfwnode_for_each_child_node(pins_node, pin_node) {\n+\t\tu32 reg;\n+\n+\t\tif (fwnode_property_read_u32(pin_node, \"reg\", \u0026reg))\n+\t\t\tcontinue;\n+\n+\t\tif (id == reg)\n+\t\t\tbreak;\n+\t}\n+\n+\tfwnode_handle_put(pins_node);\n+\n+\tprops-\u003efwnode = pin_node;\n+\n+\tdev_dbg(sitdev-\u003edev, \"Firmware node for %s %sfound\\n\",\n+\t\tprops-\u003epackage_label, pin_node ? \"\" : \"NOT \");\n+\n+\treturn pin_node ? 0 : -ENOENT;\n+}\n+\n+/*\n+ * sit9531x_pin_props_get - get pin properties for a given pin\n+ * @dir:\tpin direction (INPUT or OUTPUT)\n+ * @index:\tpin index\n+ *\n+ * Allocates a pin properties structure, generates a package label,\n+ * looks up the firmware node if available, and reads optional\n+ * properties (label, connection-type, supported-frequencies-hz).\n+ *\n+ * Call sit9531x_pin_props_put() to free the returned structure.\n+ *\n+ * Return: pointer to pin properties on success, error pointer on error\n+ */\n+struct sit9531x_pin_props *\n+sit9531x_pin_props_get(struct sit9531x_dev *sitdev,\n+\t\t enum dpll_pin_direction dir, u8 index)\n+{\n+\tstruct dpll_pin_frequency *ranges;\n+\tstruct sit9531x_pin_props *props;\n+\tint i, j, num_freqs = 0, rc;\n+\tu64 *freqs = NULL;\n+\tconst char *type;\n+\tu64 curr_freq;\n+\n+\tprops = kzalloc_obj(*props, GFP_KERNEL);\n+\tif (!props)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT \u0026\u0026\n+\t index == SIT9531X_INTSYNC_PIN_ID) {\n+\t\t/*\n+\t\t * INTSYNC destination pin: a PLL locks to the INTSYNC net as a\n+\t\t * reference, so it can be connected and re-prioritised.\n+\t\t */\n+\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;\n+\t\tprops-\u003edpll_props.capabilities =\n+\t\t\tDPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |\n+\t\t\tDPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;\n+\t\tcurr_freq = 0;\n+\t} else if (dir == DPLL_PIN_DIRECTION_OUTPUT \u0026\u0026\n+\t\t index == SIT9531X_INTSYNC_OUT_PIN_ID) {\n+\t\t/*\n+\t\t * INTSYNC source pin: a PLL drives the INTSYNC net. It can be\n+\t\t * connected/disconnected but carries no priority (driving the\n+\t\t * net is not a reference selection) and no frequency.\n+\t\t */\n+\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;\n+\t\tprops-\u003edpll_props.capabilities =\n+\t\t\tDPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;\n+\t\tcurr_freq = 0;\n+\t} else if (dir == DPLL_PIN_DIRECTION_INPUT \u0026\u0026\n+\t\t index == SIT9531X_MAX_INPUTS) {\n+\t\t/* The XO reference is fixed: no state or priority control. */\n+\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;\n+\t\tprops-\u003edpll_props.capabilities = 0;\n+\t\tsitdev-\u003eref[index].freq = sitdev-\u003extal_freq;\n+\t\tcurr_freq = sitdev-\u003extal_freq;\n+\t} else if (dir == DPLL_PIN_DIRECTION_INPUT) {\n+\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_EXT;\n+\t\tprops-\u003edpll_props.capabilities =\n+\t\t\tDPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |\n+\t\t\tDPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;\n+\t\tcurr_freq = sitdev-\u003eref[index].freq;\n+\t} else {\n+\t\t/*\n+\t\t * A synthesized clock output is an external connection with\n+\t\t * no more specific meaning; a board that knows better says\n+\t\t * so through the pin's connection-type property below.\n+\t\t */\n+\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_EXT;\n+\t\tprops-\u003edpll_props.capabilities =\n+\t\t\tDPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;\n+\t\tcurr_freq = sitdev-\u003eout[index].freq;\n+\n+\t\t/*\n+\t\t * Allow phase-adjust over a +/-1 ms window. The subsystem\n+\t\t * rejects pin_set(phase-adjust, X) when X falls outside\n+\t\t * [min, max], so leaving these at 0 silently blocks every\n+\t\t * netlink call. 1 ms is well beyond the DCO dynamic range\n+\t\t * but costs nothing. Only outputs get a range: input pins\n+\t\t * have no .phase_adjust_set, and advertising one there would\n+\t\t * promise userspace something every set would refuse.\n+\t\t */\n+\t\t/* +/-1 ms, in ps */\n+\t\tprops-\u003edpll_props.phase_range.min = -1000000000;\n+\t\tprops-\u003edpll_props.phase_range.max = 1000000000;\n+\t\t/*\n+\t\t * The fine step is 30 ps, but requests are accepted at 1 ps\n+\t\t * resolution and rounded to the nearest achievable delay, so\n+\t\t * advertise the request granularity, not the hardware step.\n+\t\t */\n+\t\tprops-\u003edpll_props.phase_gran = 1;\n+\t}\n+\n+\t/* Generate package label */\n+\tsit9531x_prop_pin_package_label_set(sitdev, props, dir, index);\n+\n+\t/*\n+\t * Both INTSYNC pins are internal to the chip and have no board-level\n+\t * wiring, so they take no properties from the firmware node.\n+\t */\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT \u0026\u0026\n+\t (index == SIT9531X_INTSYNC_PIN_ID ||\n+\t index == SIT9531X_MAX_INPUTS))\n+\t\tgoto skip_fwnode_props;\n+\tif (dir == DPLL_PIN_DIRECTION_OUTPUT \u0026\u0026\n+\t index == SIT9531X_INTSYNC_OUT_PIN_ID)\n+\t\tgoto skip_fwnode_props;\n+\n+\trc = sit9531x_prop_pin_fwnode_get(sitdev, props, dir, index);\n+\tif (rc)\n+\t\tgoto skip_fwnode_props;\n+\n+\t/* Look for \"label\" property -\u003e board label */\n+\tfwnode_property_read_string(props-\u003efwnode, \"label\",\n+\t\t\t\t \u0026props-\u003edpll_props.board_label);\n+\n+\t/* Look for \"connection-type\" property -\u003e pin type enum */\n+\tif (!fwnode_property_read_string(props-\u003efwnode, \"connection-type\",\n+\t\t\t\t\t \u0026type)) {\n+\t\tif (!strcmp(type, \"ext\"))\n+\t\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_EXT;\n+\t\telse if (!strcmp(type, \"gnss\"))\n+\t\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_GNSS;\n+\t\telse if (!strcmp(type, \"int\"))\n+\t\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;\n+\t\telse if (!strcmp(type, \"synce\"))\n+\t\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT;\n+\t\telse if (!strcmp(type, \"mux\"))\n+\t\t\tprops-\u003edpll_props.type = DPLL_PIN_TYPE_MUX;\n+\t\telse\n+\t\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t\t \"Unknown pin type '%s'\\n\", type);\n+\t}\n+\n+\tnum_freqs = fwnode_property_count_u64(props-\u003efwnode,\n+\t\t\t\t\t \"supported-frequencies-hz\");\n+\tif (num_freqs \u003c= 0) {\n+\t\tnum_freqs = 0;\n+\t\tgoto skip_fwnode_props;\n+\t}\n+\n+\tfreqs = kcalloc(num_freqs, sizeof(*freqs), GFP_KERNEL);\n+\tif (!freqs) {\n+\t\trc = -ENOMEM;\n+\t\tgoto err_alloc_freqs;\n+\t}\n+\n+\trc = fwnode_property_read_u64_array(props-\u003efwnode,\n+\t\t\t\t\t \"supported-frequencies-hz\",\n+\t\t\t\t\t freqs, num_freqs);\n+\tif (rc) {\n+\t\tdev_warn(sitdev-\u003edev,\n+\t\t\t \"failed to parse supported-frequencies-hz for %s: %d\\n\",\n+\t\t\t props-\u003epackage_label, rc);\n+\t\tgoto err_alloc_ranges;\n+\t}\n+\n+\t/*\n+\t * Seed the runtime ref-\u003efreq with the first DT-listed supported\n+\t * frequency: an input's rate is a board fact the device cannot be\n+\t * asked for, so firmware is the only source. An output is left to\n+\t * the read-back below, which knows what the divider is actually\n+\t * doing.\n+\t */\n+\tif (num_freqs \u003e 0 \u0026\u0026 dir == DPLL_PIN_DIRECTION_INPUT \u0026\u0026\n+\t index != SIT9531X_MAX_INPUTS)\n+\t\tcurr_freq = freqs[0];\n+\n+\t/*\n+\t * An output's current rate is the one its divider produces, so read\n+\t * it rather than assume the first entry of a list of the rates the\n+\t * board supports is the one in force. A rate taken from firmware\n+\t * that the part is not running would be reported as current and,\n+\t * worse, used as the output period the phase adjust quantizes\n+\t * against. An output the configuration does not route has no rate\n+\t * to read, which is not an error.\n+\t */\n+\tif (dir == DPLL_PIN_DIRECTION_OUTPUT \u0026\u0026\n+\t index \u003c sitdev-\u003einfo-\u003enum_outputs) {\n+\t\tu64 hw_freq;\n+\n+\t\tmutex_lock(\u0026sitdev-\u003emultiop_lock);\n+\t\trc = sit9531x_output_freq_get(sitdev, index, \u0026hw_freq);\n+\t\tmutex_unlock(\u0026sitdev-\u003emultiop_lock);\n+\t\tif (!rc)\n+\t\t\tcurr_freq = hw_freq;\n+\t}\n+\n+skip_fwnode_props:\n+\t/* Neither INTSYNC pin carries a frequency attribute */\n+\tif (dir == DPLL_PIN_DIRECTION_INPUT \u0026\u0026\n+\t index == SIT9531X_INTSYNC_PIN_ID)\n+\t\treturn props;\n+\tif (dir == DPLL_PIN_DIRECTION_OUTPUT \u0026\u0026\n+\t index == SIT9531X_INTSYNC_OUT_PIN_ID)\n+\t\treturn props;\n+\n+\t/*\n+\t * Advertise only concrete values from firmware plus current runtime\n+\t * value. For outputs without a firmware list, publish one wide range as\n+\t * an explicit fallback because those pins do support frequency_set.\n+\t */\n+\tranges = kcalloc(num_freqs + 2, sizeof(*ranges), GFP_KERNEL);\n+\tif (!ranges) {\n+\t\trc = -ENOMEM;\n+\t\tgoto err_alloc_ranges;\n+\t}\n+\n+\t/*\n+\t * Publish the seeded rate only once the pin is certain to be built.\n+\t * The allocation above is the last thing that can fail, and a call\n+\t * that reports failure must not leave the device's cached rate\n+\t * changed behind it.\n+\t */\n+\tif (curr_freq) {\n+\t\tif (dir == DPLL_PIN_DIRECTION_INPUT)\n+\t\t\tsitdev-\u003eref[index].freq = curr_freq;\n+\t\telse\n+\t\t\tsitdev-\u003eout[index].freq = curr_freq;\n+\t}\n+\n+\tj = 0;\n+\n+\t/* Current frequency first, when known. */\n+\tif (curr_freq) {\n+\t\tstruct dpll_pin_frequency f = DPLL_PIN_FREQUENCY(curr_freq);\n+\n+\t\tranges[j++] = f;\n+\t}\n+\n+\tfor (i = 0; i \u003c num_freqs; i++) {\n+\t\tstruct dpll_pin_frequency freq = DPLL_PIN_FREQUENCY(freqs[i]);\n+\n+\t\tif (freqs[i] == curr_freq)\n+\t\t\tcontinue;\n+\t\tranges[j++] = freq;\n+\t}\n+\n+\tif (dir == DPLL_PIN_DIRECTION_OUTPUT \u0026\u0026 num_freqs == 0) {\n+\t\tranges[j].min = 1;\n+\t\tranges[j].max = 1000000000ULL; /* 1 GHz */\n+\t\tj++;\n+\t}\n+\n+\tif (j \u003e 0) {\n+\t\tprops-\u003edpll_props.freq_supported = ranges;\n+\t\tprops-\u003edpll_props.freq_supported_num = j;\n+\t} else {\n+\t\tkfree(ranges);\n+\t\tprops-\u003edpll_props.freq_supported = NULL;\n+\t\tprops-\u003edpll_props.freq_supported_num = 0;\n+\t}\n+\n+\tkfree(freqs);\n+\n+\treturn props;\n+\n+err_alloc_ranges:\n+\tkfree(freqs);\n+err_alloc_freqs:\n+\tfwnode_handle_put(props-\u003efwnode);\n+\tkfree(props);\n+\n+\treturn ERR_PTR(rc);\n+}\n+\n+/*\n+ * sit9531x_pin_props_put - release pin properties\n+ * @props:\tpin properties to free\n+ */\n+void sit9531x_pin_props_put(struct sit9531x_pin_props *props)\n+{\n+\tkfree(props-\u003edpll_props.freq_supported);\n+\n+\tif (props-\u003efwnode)\n+\t\tfwnode_handle_put(props-\u003efwnode);\n+\n+\tkfree(props);\n+}\n+\n+/*\n+ * sit9531x_prop_dpll_type_get - get DPLL channel type from firmware\n+ * @index:\tDPLL channel index (0-3)\n+ *\n+ * Reads the \"dpll-types\" string array property from the firmware node\n+ * and returns the corresponding DPLL type enum.\n+ *\n+ * Return: DPLL type for the given channel (default: DPLL_TYPE_PPS)\n+ */\n+enum dpll_type\n+sit9531x_prop_dpll_type_get(struct sit9531x_dev *sitdev, u8 index)\n+{\n+\tconst char *types[SIT9531X_NUM_PLLS];\n+\tint count;\n+\n+\tcount = device_property_read_string_array(sitdev-\u003edev, \"dpll-types\",\n+\t\t\t\t\t\t types, ARRAY_SIZE(types));\n+\n+\tif (index \u003e= count)\n+\t\treturn DPLL_TYPE_PPS;\n+\n+\tif (!strcmp(types[index], \"pps\"))\n+\t\treturn DPLL_TYPE_PPS;\n+\telse if (!strcmp(types[index], \"eec\"))\n+\t\treturn DPLL_TYPE_EEC;\n+\n+\tdev_warn(sitdev-\u003edev, \"Unknown DPLL type '%s', using default\\n\",\n+\t\t types[index]);\n+\n+\treturn DPLL_TYPE_PPS;\n+}\ndiff --git a/drivers/dpll/sit9531x/prop.h b/drivers/dpll/sit9531x/prop.h\nnew file mode 100644\nindex 0000000000000..a65efdfd9ef8a\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/prop.h\n@@ -0,0 +1,37 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * SiTime SiT9531x firmware node property parsing\n+ *\n+ * Copyright (C) 2026 SiTime Corp.\n+ * Author: Ali Rouhi \u003carouhi@sitime.com\u003e\n+ * Author: Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\n+ */\n+\n+#ifndef _SIT9531X_PROP_H\n+#define _SIT9531X_PROP_H\n+\n+#include \u003clinux/dpll.h\u003e\n+#include \u003clinux/fwnode.h\u003e\n+\n+struct sit9531x_dev;\n+\n+/*\n+ * struct sit9531x_pin_props - pin properties from firmware\n+ * @fwnode:\t\tfirmware node handle (NULL if no DT node)\n+ * @dpll_props:\t\tDPLL core pin properties\n+ * @package_label:\tpin package label (e.g. \"IN0\", \"OUT3\")\n+ */\n+struct sit9531x_pin_props {\n+\tstruct fwnode_handle\t\t*fwnode;\n+\tstruct dpll_pin_properties\tdpll_props;\n+\tchar\t\t\t\tpackage_label[8];\n+};\n+\n+enum dpll_type sit9531x_prop_dpll_type_get(struct sit9531x_dev *sitdev,\n+\t\t\t\t\t u8 index);\n+struct sit9531x_pin_props *sit9531x_pin_props_get(struct sit9531x_dev *sitdev,\n+\t\t\t\t\t\t enum dpll_pin_direction dir,\n+\t\t\t\t\t\t u8 index);\n+void sit9531x_pin_props_put(struct sit9531x_pin_props *props);\n+\n+#endif /* _SIT9531X_PROP_H */\ndiff --git a/drivers/dpll/sit9531x/regs.h b/drivers/dpll/sit9531x/regs.h\nnew file mode 100644\nindex 0000000000000..09a2032f7bf02\n--- /dev/null\n+++ b/drivers/dpll/sit9531x/regs.h\n@@ -0,0 +1,364 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * SiTime SiT9531x register definitions\n+ *\n+ * Copyright (C) 2026 SiTime Corp.\n+ * Author: Ali Rouhi \u003carouhi@sitime.com\u003e\n+ * Author: Oleg Zadorozhnyi \u003cOleg.Zadorozhnyi@devoxsoftware.com\u003e\n+ */\n+\n+#ifndef _SIT9531X_REGS_H\n+#define _SIT9531X_REGS_H\n+\n+/*\n+ * I2C register model:\n+ * - Page select register at offset 0xFF, present in every page\n+ * - Each page has 256 registers (0x00-0xFF)\n+ * - Some pages are paired (e.g. 0x0A/0x1A for PLLA)\n+ */\n+#define SIT9531X_PAGE_SEL\t\t0xFF\n+#define SIT9531X_PAGE_SIZE\t\t0x100\n+#define SIT9531X_NUM_PAGES\t\t32\n+\n+/* Helper macros for page:offset addressing */\n+#define SIT9531X_REG(_page, _offset)\t\t(((_page) \u003c\u003c 8) | (_offset))\n+#define SIT9531X_REG_PAGE(_reg)\t\t((_reg) \u003e\u003e 8)\n+#define SIT9531X_REG_OFFSET(_reg)\t\t((_reg) \u0026 0xFF)\n+\n+#define SIT9531X_PAGE_OUTSYS0\t\t0x03\n+#define SIT9531X_PAGE_OUTSYS1\t\t0x04\n+#define SIT9531X_PAGE_PLLA\t\t\t0x0A\n+#define SIT9531X_PAGE_PLLA_EXT\t\t0x1A\n+\n+/*\n+ * VARIANT_ID is a single byte at page 0 reg 0x02 (95317 = 0x17, 95316 = 0x31).\n+ * Reg 0x03 carries an unrelated revision byte and must not be combined into\n+ * the variant identifier.\n+ */\n+#define SIT9531X_REG_VARIANT_ID\t\tSIT9531X_REG(0x00, 0x02)\n+\n+/* DCO trigger pulse timing: minimum 6 ns required by hardware */\n+\n+/* Page 0 -- PLL inner loop loss-of-lock */\n+#define SIT9531X_REG_PLL_INNER_LOL_STATUS\tSIT9531X_REG(0x00, 0x92)\n+#define SIT9531X_REG_PLL_INNER_LOL_NOTIF\tSIT9531X_REG(0x00, 0x93)\n+\n+/* Page 0 -- Clock monitor PLL / XO status */\n+#define SIT9531X_REG_CMON_NOTIF\t\tSIT9531X_REG(0x00, 0x9E)\n+\n+/* Page 0 -- PLL outer-loop loss-of-lock */\n+#define SIT9531X_REG_OUTER_LOL_STATUS\tSIT9531X_REG(0x00, 0x06)\n+#define SIT9531X_REG_OUTER_LOL_NOTIF\t\tSIT9531X_REG(0x00, 0x07)\n+\n+/* Page 0 -- PLL holdover freeze status */\n+#define SIT9531X_REG_HO_FREEZE_STATUS\tSIT9531X_REG(0x00, 0x0A)\n+#define SIT9531X_REG_HO_FREEZE_NOTIF\tSIT9531X_REG(0x00, 0x0B)\n+\n+/* Page 0 -- INTSYNC (inter-PLL synchronization) global enable */\n+#define SIT9531X_REG_INTSYNC_GLOBAL\t\tSIT9531X_REG(0x00, 0x40)\n+#define SIT9531X_INTSYNC_EN_BIT\t\t6\n+\n+/*\n+ * Priority table: 6 registers per PLL, each holds two priority slots\n+ * nibble-packed. The register holding slots 2n and 2n+1 keeps the\n+ * earlier slot (CLK_SPARE\u003c2n\u003eSEL_PLL) in [7:4] and the later one in\n+ * [3:0].\n+ *\n+ * Base registers for PLLA: 0x16-0x1B (slots 0-10 plus the\n+ * active-reference nibble).\n+ * For PLL N: base + 6 * N (e.g. PLLB starts at 0x1C).\n+ *\n+ * Input source encoding (4-bit value):\n+ * 0=IN0P, 1=IN1P, 2=IN2P, 3=IN3P,\n+ * 5=OCXO, 6=INTSYNC,\n+ * 7=IN0N, 8=IN1N, 9=IN2N, 10=IN3N\n+ *\n+ * Codes 4 and 11 address a fifth input pair that this part does\n+ * not have. They read back as no valid reference.\n+ */\n+#define SIT9531X_PAGE_PRIOSYS\t\t0x01\n+#define SIT9531X_PRIO_BASE_REG\t\t0x16\n+#define SIT9531X_PRIO_REGS_PER_PLL\t\t6\n+#define SIT9531X_PRIO_SLOTS_PER_REG\t\t2\n+/*\n+ * 11 priority slots, CLK_SPARE0SEL_PLL through CLK_SPARE10SEL_PLL.\n+ * The twelfth nibble of the block is not a slot: it is\n+ * CLK_ACTIVESEL_PLL, see SIT9531X_PRIO_ACTIVESEL_OFF below.\n+ */\n+#define SIT9531X_PRIO_MAX_SLOTS\t\t11\n+/* Number of source encodings (0-11), unrelated to the slot count */\n+#define SIT9531X_PRIO_NUM_SRC\t\t12\n+#define SIT9531X_PRIO_NIBBLE_MASK\t\t0x0F\n+#define SIT9531X_PRIO_HI_SHIFT\t\t4\n+/* Input source encoding values (see table above) */\n+/*\n+ * Either of the two codes for the absent fifth pair works as \"no source\";\n+ * the driver writes this one when it empties a slot.\n+ */\n+#define SIT9531X_PRIO_SRC_NONE\t\t\t4\n+#define SIT9531X_PRIO_SRC_OCXO\t\t5\n+#define SIT9531X_PRIO_SRC_INTSYNC\t\t6\n+#define SIT9531X_PRIO_SRC_N_BASE\t\t7\n+/*\n+ * The last register of each PLL's priority block holds, in its low\n+ * nibble, the input source the PLL has currently selected as its\n+ * active reference (CLK_ACTIVESEL_PLL, same 4-bit encoding as above).\n+ */\n+#define SIT9531X_PRIO_ACTIVESEL_OFF\t\t5\n+\n+/*\n+ * Page 0 -- PRG_Directives_GENERIC_0, the main system's programming\n+ * directive register. Every page carries its own copy of this\n+ * register at offset 0x0F with the same bit layout:\n+ *\n+ * bit 6 proceed to loop lock / active state from the PRG_CMD state\n+ * bit 4 update the NVM bank from the efuse contents\n+ * bit 3 read the efuse into the volatile registers\n+ * bit 2 program the efuse\n+ * bit 1 small change update (SIT9531X_SMALL_UPDATE_CMD)\n+ * bit 0 escape to the PRG_CMD state\n+ *\n+ * The NVM bank is a volatile shadow, so bits 4 and 1 are both fine in\n+ * a runtime path: bit 1 for a change made in the active state, bit 4\n+ * to close a PRG_CMD sequence. Only bit 2 writes non-volatile\n+ * storage, and the driver never issues it.\n+ */\n+#define SIT9531X_REG_GLOBAL_UPDATE\t\tSIT9531X_REG(0x00, 0x0F)\n+#define SIT9531X_SMALL_UPDATE_CMD\t\t0x02\n+\n+/* PLL holdover control (PLL page offset) */\n+#define SIT9531X_PLL_REG_HO_CTRL\t\t0x6F\n+#define SIT9531X_PLL_HO_FORCE_BIT\t\t4\n+\n+/* One bit per input PAIR (bit 0 = CLKIN0, ..., bit 3 = CLKIN3) */\n+#define SIT9531X_REG_IN_DE_FORCE\t\tSIT9531X_REG(0x02, 0xE8)\n+#define SIT9531X_REG_IN_DE_STATE\t\tSIT9531X_REG(0x02, 0xE9)\n+#define SIT9531X_REG_IN_SEP_FORCE\t\tSIT9531X_REG(0x02, 0xEA)\n+#define SIT9531X_REG_IN_SEP_STATE\t\tSIT9531X_REG(0x02, 0xEB)\n+#define SIT9531X_REG_IN_SEN_FORCE\t\tSIT9531X_REG(0x02, 0xF2)\n+#define SIT9531X_REG_IN_SEN_STATE\t\tSIT9531X_REG(0x02, 0xF3)\n+\n+/*\n+ * One register per input pair at 0x1B + 0x10 * pair\n+ * (CLKIN0 = 0x1B, CLKIN1 = 0x2B, CLKIN2 = 0x3B, CLKIN3 = 0x4B).\n+ * SE_P_EN/SE_N_EN set means the corresponding lane is configured\n+ * single-ended; both clear means the pair runs differential.\n+ */\n+#define SIT9531X_REG_IN_MODE(_pair)\t\t\\\n+\tSIT9531X_REG(0x02, 0x1B + 0x10 * (_pair))\n+#define SIT9531X_IN_MODE_SE_P_EN\t\tBIT(0)\n+#define SIT9531X_IN_MODE_SE_N_EN\t\tBIT(1)\n+\n+/* ---- Page 0x03 (Output System) registers -- Hi-Z control ---- */\n+#define SIT9531X_REG_HIZ_DIFF_07_MASK\tSIT9531X_REG(0x03, 0xF2)\n+#define SIT9531X_REG_HIZ_DIFF_07_STATE\tSIT9531X_REG(0x03, 0xF3)\n+#define SIT9531X_REG_HIZ_DIFF_811_MASK\tSIT9531X_REG(0x03, 0xF4)\n+#define SIT9531X_REG_HIZ_DIFF_811_STATE\tSIT9531X_REG(0x03, 0xF5)\n+#define SIT9531X_REG_HIZ_SE_07_MASK\t\tSIT9531X_REG(0x03, 0xF8)\n+#define SIT9531X_REG_HIZ_SE_07_STATE\t\tSIT9531X_REG(0x03, 0xF9)\n+#define SIT9531X_REG_HIZ_SE_811_MASK\t\tSIT9531X_REG(0x03, 0xFA)\n+#define SIT9531X_REG_HIZ_SE_811_STATE\tSIT9531X_REG(0x03, 0xFB)\n+\n+/*\n+ * Output driver configuration. Either CMOS enable means the output\n+ * is wired single-ended -- one lane, or both driven as CMOS; with\n+ * neither set it is a differential pair.\n+ */\n+#define SIT9531X_OUT_MISC0_BASE\t\t0x1E\n+#define SIT9531X_OUT_MISC0_STRIDE\t\t0x10\n+#define SIT9531X_OUT_CMOS_ENP\t\tBIT(3)\n+#define SIT9531X_OUT_CMOS_ENN\t\tBIT(2)\n+\n+/*\n+ * Output divider registers in Pages 3/4. Each output has a 34-bit\n+ * integer divider mapped to 5 bytes (LSB at base reg, MSB at base-4).\n+ * Outputs 0-5 are on Page 3, outputs 6-11 are on Page 4.\n+ *\n+ * The base register for slot N within a page is:\n+ * clkout_odr_divn_base[slot] = { 0x14, 0x24, 0x34, 0x44, 0x54, 0x64 }\n+ *\n+ * Layout: base=LSB, base-1, base-2, base-3, base-4[1:0]=MSB.\n+ *\n+ * Per-chip clkout_map[] translates output index to slot position.\n+ */\n+#define SIT9531X_PAGE_OUTSYS0_SLOT_MAX\t5 /* slots 0-5 on Page 0x03 */\n+\n+/* Misc output system registers */\n+#define SIT9531X_REG_PRG_DIR_GEN\t\tSIT9531X_REG(0x03, 0x0F)\n+#define SIT9531X_PRG_CMD_STATE\t\t0x01\n+#define SIT9531X_UPDATE_NVM\t\t\t0x10\n+#define SIT9531X_LOOP_LOCK\t\t\t0x40\n+\n+/* Debug register (same offset, per-page) */\n+#define SIT9531X_REG_OUTSYS_DEBUG\t\tSIT9531X_REG(0x03, 0xBD)\n+#define SIT9531X_DEBUG_UNLOCK_VAL\t\t0xC3\n+#define SIT9531X_DEBUG_LOCK_VAL\t\t\t0x00\n+\n+/*\n+ * Per-output programmable phase delay: 34-bit coarse (in VCO clock\n+ * cycles) plus a 3-bit fine field with fixed 30 ps steps. Each output\n+ * has a five-byte block PROG6..PROG2:\n+ *\n+ * base + 0 PROG6 [7:5] OPSTG_VCASC_BUMP (preserve via RMW)\n+ * [4:2] PRG_RST_FINE_DELAY[2:0]\n+ * [1:0] PRG_RST_DELAY[33:32]\n+ * base + 1 PROG5 [7:0] PRG_RST_DELAY[31:24]\n+ * base + 2 PROG4 [7:0] PRG_RST_DELAY[23:16]\n+ * base + 3 PROG3 [7:0] PRG_RST_DELAY[15:8]\n+ * base + 4 PROG2 [7:0] PRG_RST_DELAY[7:0]\n+ *\n+ * Slots 0-5 are on Page 3, slots 6-11 on Page 4. The block base\n+ * within a page is 0x15 + 16 * (slot % 6), where slot is the physical\n+ * output slot from clkout_map[], not the logical output index.\n+ */\n+#define SIT9531X_OUT_PRG_DELAY_BASE\t\t0x15\n+#define SIT9531X_OUT_PRG_SLOT_STRIDE\t\t0x10\n+/* bits [7:5], preserve */\n+#define SIT9531X_OUT_PRG_OPSTG_MASK\t\t0xE0\n+#define SIT9531X_OUT_PRG_FINE_SHIFT\t\t2\n+#define SIT9531X_OUT_PRG_FINE_MASK\t\t0x1C\t/* bits [4:2] */\n+#define SIT9531X_OUT_PRG_COARSE_HI_MASK\t\t0x03\t/* bits [1:0] */\n+#define SIT9531X_OUT_PRG_FINE_STEP_PS\t\t30\n+#define SIT9531X_OUT_PRG_FINE_MAX\t\t7\t/* 3-bit field */\n+#define SIT9531X_OUT_PRG_COARSE_BITS\t\t34\n+\n+/*\n+ * On-demand phase-flush fired from a register rather than a GPIO pin.\n+ * DIVO_PHASE_SEL_REG selects the in-register trigger source and\n+ * DIVO_PHASE_TRIG flushes the output phase when pulsed high then low.\n+ * The unrelated OEb trigger pair in bits [7:6] must be preserved.\n+ */\n+#define SIT9531X_REG_GPIO_FUNC_CTRL1\tSIT9531X_REG(0x00, 0x65)\n+#define SIT9531X_DIVO_PHASE_SEL_REG\tBIT(5)\n+#define SIT9531X_DIVO_PHASE_TRIG\tBIT(4)\n+\n+/* ---- PLL page registers (apply to pages 0x0A-0x0D) ---- */\n+#define SIT9531X_PLL_REG_SMALL_UPDATE\t0x0F\n+\n+/* On-demand phase-flush enable (PLL page reg 0x3D bit 7) */\n+#define SIT9531X_PLL_REG_PHFL_CTRL\t0x3D\n+#define SIT9531X_PLL_PHFL_ON_DEMAND_EN\tBIT(7)\n+\n+/*\n+ * Loop-filter coefficients on PLL_PAGE regs 0x10-0x15 (3 normal +\n+ * 3 fast-lock) are GUI/NVM-generated by the timing configurator and must not be\n+ * reprogrammed at runtime; the register map flags them as\n+ * \"GUI generated configuration should not change manually\".\n+ */\n+\n+#define SIT9531X_PLL_REG_OUT_MAP_HI\t\t0x27\n+#define SIT9531X_PLL_REG_OUT_MAP_LO\t\t0x28\n+#define SIT9531X_PLL_REG_STATUS\t\t0x31\n+\n+/* DIVN registers (free-run divider readback) */\n+#define SIT9531X_PLL_REG_DIVN_INT\t\t0x30\n+#define SIT9531X_PLL_REG_DIVN_NUM\t\t0x32 /* 4 bytes (0x32-0x35) */\n+#define SIT9531X_PLL_REG_DIVN_DEN\t\t0x38 /* 4 bytes (0x38-0x3B) */\n+\n+/* Debug register unlock */\n+#define SIT9531X_PLL_REG_DEBUG\t\t0xBD\n+#define SIT9531X_PLL_DEBUG_UNLOCK\t\t0xC3\n+#define SIT9531X_PLL_DEBUG_LOCK\t\t\t0x00\n+\n+/*\n+ * Signal pathway debug readback -- PLL page. Dig_Sys_ReadCode selects\n+ * which point of the pathway is tapped, Dig_Sys_WriteCode carries the\n+ * modifiers for that read, Dig_Sys_read7..read0 hold the sampled bytes\n+ * and the trigger register latches a sample. The TDC phase\n+ * measurement is one tap among several, reached through read code 69.\n+ */\n+#define SIT9531X_PLL_REG_DBG_READ_CODE\t0xB3\n+#define SIT9531X_PLL_REG_DBG_WRITE_CODE\t0xB4\n+#define SIT9531X_DBG_LOW_FREQ_CLK_BIT\tBIT(7)\n+#define SIT9531X_PLL_REG_DBG_DATA_0\t\t0xB5 /* [7:0] */\n+#define SIT9531X_PLL_REG_DBG_DATA_1\t\t0xB6 /* [15:8] */\n+#define SIT9531X_PLL_REG_DBG_DATA_2\t\t0xB7 /* [23:16] */\n+#define SIT9531X_PLL_REG_DBG_DATA_3\t\t0xB8 /* [31:24] */\n+#define SIT9531X_PLL_REG_DBG_DATA_4\t\t0xB9 /* [34:32] + sign */\n+/* read to latch a sample */\n+#define SIT9531X_PLL_REG_DBG_TRIGGER\t\t0xD0\n+\n+/*\n+ * Reads of the trigger needed to latch a fresh sample. One returns the\n+ * previous latch, which the documented procedures work around by reading it\n+ * three times.\n+ */\n+#define SIT9531X_DBG_LATCH_READS\t\t3\n+#define SIT9531X_DBG_DATA_BYTES\t\t8\n+\n+/* Read code of the TDC phase tap, and the sign bit of its sample */\n+#define SIT9531X_DBG_READ_CODE_TDC\t\t69\n+#define SIT9531X_TDC_SIGN_BIT\t\t3\n+#define SIT9531X_TDC_MAG_HI_MASK\tGENMASK(2, 0)\n+\n+/*\n+ * Read codes of the running DIVN taps. Unlike the configuration\n+ * registers these report what the digital loop currently commands, so\n+ * they carry the correction the loop applies to track its reference.\n+ * The integer part and the numerator share one tap, the denominator\n+ * has its own.\n+ */\n+#define SIT9531X_DBG_READ_CODE_DIVN\t\t0x57\n+#define SIT9531X_DBG_READ_CODE_DIVN_DEN\t0x56\n+#define SIT9531X_DIVN_RT_NUM_BITS\t\t48\n+#define SIT9531X_DIVN_RT_INT_HI_BIT\t\tBIT(0)\n+/* Bit 48 of the denominator tap, which lands in the same byte position */\n+#define SIT9531X_DIVN_RT_DEN_HI_BIT\t\tBIT(0)\n+\n+/*\n+ * DIVN carried as fixed point, and the unit the DPLL ABI wants the\n+ * fractional frequency offset in. Equal in value, distinct in meaning.\n+ */\n+#define SIT9531X_DIVN_SCALE\t\t1000000000000ULL\n+#define SIT9531X_PPT_PER_UNIT\t\t1000000000000ULL\n+\n+#define SIT9531X_PLL_REG_ACTIVE\t\t0x02\n+#define SIT9531X_PLL_ACTIVE_BIT\t\tBIT(0) /* PLL reached active state */\n+\n+/* PLL EXT page INTSYNC configuration registers */\n+#define SIT9531X_PLL_EXT_PAGE(_idx)\t(SIT9531X_PAGE_PLLA_EXT + (_idx))\n+\n+#define SIT9531X_PLL_STATUS_OUTER_DIS\tBIT(5)\n+\n+/*\n+ * Per-PLL status register. HO_VALID says the holdover window holds a\n+ * valid frequency estimate, i.e. holdover memory has been acquired; it is\n+ * not the same as HO_FREEZE (page 0, reg 0x0A), which says the PLL has\n+ * already switched over to holdover.\n+ */\n+#define SIT9531X_PLL_REG_STATUS_1\t\t0x06\n+#define SIT9531X_PLL_STATUS_1_HO_VALID\tBIT(2)\n+\n+#define SIT9531X_CLKMON_P_NOTIF_01\t\tSIT9531X_REG(0x06, 0x03)\n+#define SIT9531X_CLKMON_P_NOTIF_23\t\tSIT9531X_REG(0x06, 0x07)\n+\n+#define SIT9531X_CLKMON_N_NOTIF_01\t\tSIT9531X_REG(0x06, 0x93)\n+#define SIT9531X_CLKMON_N_NOTIF_23\t\tSIT9531X_REG(0x06, 0x97)\n+\n+/* Per-input bit offsets within clock monitor nibble */\n+\n+/*\n+ * EEPROM profile load, page 0. The device compares the CRC stored in the\n+ * EEPROM against the one it computes from what it read; a mismatch means\n+ * the profile on the part is not the profile the board expects.\n+ * NOTIFY_4 collects the read-done bit and the defect bits, all sticky, so\n+ * a healthy load leaves exactly the read-done bit set.\n+ */\n+/* 4 bytes each, MSB first */\n+#define SIT9531X_REG_REC_CRC\t\tSIT9531X_REG(0x00, 0x8A)\n+#define SIT9531X_REG_CAL_CRC\t\tSIT9531X_REG(0x00, 0x8E)\n+#define SIT9531X_REG_EEPROM_NOTIF\t\tSIT9531X_REG(0x00, 0x97)\n+#define SIT9531X_EEPROM_READ_DONE\t\tBIT(0)\n+\n+/* Profile identifier the loaded configuration carries, page 1, 24 bits */\n+/* 3 bytes, LSB first */\n+#define SIT9531X_REG_PROFILE_ID\t\tSIT9531X_REG(0x01, 0x44)\n+\n+/* Consecutive failed INTRB acknowledgements before the line is given up */\n+#define SIT9531X_IRQ_ACK_TRIES\t\t\t8\n+\n+/* ---- Variant ID values (one byte at SIT9531X_REG_VARIANT_ID) ---- */\n+#define SIT9531X_VARIANT_ID_95317\t0x17\n+#define SIT9531X_VARIANT_ID_95316\t0x31\n+\n+#endif /* _SIT9531X_REGS_H */\n"
} |
| 2/1 | 2026/09/23 20:44 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch adds a new device driver for the SiTime SiT95316 and SiT95317 I2C-controlled DPLL clock generator chips (drivers/dpll/sit9531x/). This hardware requires physical discrete ASICs communicating over I2C with specific clock inputs, which are not emulated in standard QEMU or GCE virtualized fuzzing environments. As such, the driver cannot successfully probe or execute in standard syzkaller environments, making the modified code structurally unreachable.",
"WorthFuzzing": false
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 780781b91d8cfecf2ab75310256bf8247b8ed953
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Sep 23 20:44:14 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml b/Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml
new file mode 100644
index 0000000000000..6f4c60ba1cb92
--- /dev/null
+++ b/Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml
@@ -0,0 +1,183 @@
+# 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 <arouhi@sitime.com>
+
+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.
+
+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. Alternative to the "clocks"
+ phandle for platforms where the firmware does not expose the
+ oscillator through the clock framework.
+
+ 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
+
+ sitime,pll-fvco:
+ $ref: /schemas/types.yaml#/definitions/uint64-array
+ minItems: 4
+ maxItems: 4
+ description:
+ Per-PLL VCO frequency in Hz for PLLA, PLLB, PLLC, PLLD. The
+ values exceed 32 bits, which requires an explicit uint64-array
+ type; the dtschema meta-schema does not permit a type $ref on a
+ "-hz" unit-suffix property (only opp-hz is defined as 64-bit),
+ hence no unit suffix. Override where the standard
+ Fvco = Fref * DIVN derivation does not match the running VCO --
+ for example a PLL operating in INTSYNC mode. A value of 0 keeps
+ the register-derived computation for that PLL.
+
+ sitime,output-pll-map:
+ $ref: /schemas/types.yaml#/definitions/uint32-array
+ minItems: 8
+ maxItems: 12
+ items:
+ enum: [0, 1, 2, 3, 255]
+ description:
+ Source PLL index (0=PLLA .. 3=PLLD) for each output 0..11. The
+ value 255 (0xff) marks an output as unmapped and prevents the
+ driver from registering it as a DPLL pin. Override for
+ configurations where the chip's per-PLL OUTPUT_ENABLE bitmaps do
+ not unambiguously describe output-to-PLL routing.
+
+required:
+ - compatible
+ - reg
+
+oneOf:
+ - required:
+ - clocks
+ - clock-names
+ - required:
+ - clock-frequency
+
+allOf:
+ - $ref: /schemas/dpll/dpll-device.yaml#
+ # SiT95317 exposes 8 outputs, SiT95316 exposes 12. Bound the
+ # output-pll-map length to the variant so a SiT95317 node cannot
+ # describe more outputs than the part has.
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: sitime,sit95317
+ then:
+ properties:
+ sitime,output-pll-map:
+ maxItems: 8
+ # SiT95316 has 12 outputs. When the map is supplied it must describe
+ # all of them, otherwise the trailing outputs are left ambiguous.
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: sitime,sit95316
+ then:
+ properties:
+ sitime,output-pll-map:
+ minItems: 12
+
+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>;
+ dpll-types = "eec", "eec", "eec", "eec";
+ sitime,pll-fvco = /bits/ 64 <0 6875000000 0 0>;
+ sitime,output-pll-map = <0 0 0 0 0 0 0 0 0 0 0 0>;
+
+ input-pins {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ pin@0 {
+ reg = <0>;
+ label = "clkin0";
+ connection-type = "ext";
+ supported-frequencies-hz = /bits/ 64 <10000000>;
+ };
+
+ pin@1 {
+ reg = <1>;
+ label = "clkin1";
+ connection-type = "synce";
+ supported-frequencies-hz = /bits/ 64 <156250000>;
+ };
+ };
+
+ output-pins {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ pin@0 {
+ reg = <0>;
+ label = "clkout0";
+ supported-frequencies-hz = /bits/ 64 <156250000>;
+ };
+
+ pin@1 {
+ reg = <1>;
+ label = "clkout1";
+ supported-frequencies-hz = /bits/ 64 <25000000>;
+ };
+ };
+ };
+ };
+...
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index ba20029693734..65da27d6e84d8 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -1563,6 +1563,8 @@ patternProperties:
description: SiRF Technology, Inc.
"^sis,.*":
description: Silicon Integrated Systems Corp.
+ "^sitime,.*":
+ description: SiTime Corporation
"^sitronix,.*":
description: Sitronix Technology Corporation
"^skov,.*":
diff --git a/MAINTAINERS b/MAINTAINERS
index cae5962045dd6..b500dbb67c4e9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25151,6 +25151,13 @@ S: Maintained
W: http://www.winischhofer.at/linuxsisusbvga.shtml
F: drivers/usb/misc/sisusbvga/
+SITIME SIT9531X DPLL DRIVER
+M: Ali Rouhi <arouhi@sitime.com>
+L: netdev@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/dpll/sitime,sit95316.yaml
+F: drivers/dpll/sit9531x/
+
SL28 CPLD MFD DRIVER
M: Michael Walle <mwalle@kernel.org>
S: Maintained
diff --git a/drivers/dpll/Kconfig b/drivers/dpll/Kconfig
index be98969f040ab..f8f7ca121b932 100644
--- a/drivers/dpll/Kconfig
+++ b/drivers/dpll/Kconfig
@@ -23,6 +23,8 @@ config DPLL_REFCNT_TRACKER
If unsure, say N.
+source "drivers/dpll/sit9531x/Kconfig"
+
source "drivers/dpll/zl3073x/Kconfig"
endmenu
diff --git a/drivers/dpll/Makefile b/drivers/dpll/Makefile
index 9e7a3a3e592e8..4adc50d748d4d 100644
--- a/drivers/dpll/Makefile
+++ b/drivers/dpll/Makefile
@@ -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/
diff --git a/drivers/dpll/sit9531x/Kconfig b/drivers/dpll/sit9531x/Kconfig
new file mode 100644
index 0000000000000..47aea8674327c
--- /dev/null
+++ b/drivers/dpll/sit9531x/Kconfig
@@ -0,0 +1,17 @@
+# 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).
+
+ 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.
diff --git a/drivers/dpll/sit9531x/Makefile b/drivers/dpll/sit9531x/Makefile
new file mode 100644
index 0000000000000..b97d2656a4603
--- /dev/null
+++ b/drivers/dpll/sit9531x/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_SIT9531X_DPLL) += sit9531x.o
+sit9531x-y := core.o dpll.o prop.o
diff --git a/drivers/dpll/sit9531x/core.c b/drivers/dpll/sit9531x/core.c
new file mode 100644
index 0000000000000..5316e6bcb338c
--- /dev/null
+++ b/drivers/dpll/sit9531x/core.c
@@ -0,0 +1,4553 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SiTime SiT9531x DPLL core driver
+ *
+ * Copyright (C) 2026 SiTime Corp.
+ * Author: Ali Rouhi <arouhi@sitime.com>
+ * Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
+ *
+ * Core I2C probe, regmap configuration, hardware state management,
+ * and periodic work thread.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/kthread.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "core.h"
+#include "dpll.h"
+#include "prop.h"
+#include "regs.h"
+
+/*
+ * Number of input + output pin positions for pin index allocation. The two
+ * extra input positions are the crystal and the INTSYNC destination, the
+ * extra output position is the INTSYNC source.
+ */
+#define SIT9531X_NUM_INPUT_PINS (SIT9531X_MAX_INPUTS + 2)
+#define SIT9531X_NUM_OUTPUT_PINS (SIT9531X_MAX_OUTPUTS + 1)
+#define SIT9531X_NUM_PINS_TOTAL (SIT9531X_NUM_INPUT_PINS + \
+ SIT9531X_NUM_OUTPUT_PINS)
+
+#define SIT9531X_CHIP(_id, _nin, _nout, _name, _map) \
+ { .id = (_id), .num_inputs = (_nin), .num_outputs = (_nout), \
+ .name = (_name), .clkout_map = (_map) }
+
+/* Per-variant output index -> physical slot mapping */
+static const u8 clkout_map_95317[] = {0, 3, 4, 5, 7, 8, 9, 11};
+static const u8 clkout_map_95316[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+
+static const struct sit9531x_chip_info sit9531x_chip_ids[] = {
+ SIT9531X_CHIP(SIT9531X_VARIANT_ID_95317, 8, 8, "SiT95317",
+ clkout_map_95317),
+ SIT9531X_CHIP(SIT9531X_VARIANT_ID_95316, 8, 12, "SiT95316",
+ clkout_map_95316),
+};
+
+#define SIT9531X_RANGE_OFFSET SIT9531X_PAGE_SIZE
+
+/*
+ * Everything the device holds can change without the driver writing it,
+ * so nothing here is cacheable -- except the page selector, which only
+ * this driver moves. Caching that one spares a read of it before every
+ * access: the range code selects the page through a read-modify-write,
+ * and with no cache that read goes to the bus each time.
+ */
+static bool sit9531x_volatile_reg(struct device *dev __maybe_unused,
+ unsigned int reg)
+{
+ return reg != SIT9531X_PAGE_SEL;
+}
+
+static const struct regmap_range_cfg sit9531x_regmap_range = {
+ .range_min = SIT9531X_RANGE_OFFSET,
+ .range_max = SIT9531X_RANGE_OFFSET +
+ (SIT9531X_NUM_PAGES * SIT9531X_PAGE_SIZE) - 1,
+ .selector_reg = SIT9531X_PAGE_SEL,
+ .selector_mask = GENMASK(7, 0),
+ .selector_shift = 0,
+ .window_start = 0,
+ .window_len = SIT9531X_PAGE_SIZE,
+};
+
+const struct regmap_config sit9531x_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = SIT9531X_RANGE_OFFSET +
+ (SIT9531X_NUM_PAGES * SIT9531X_PAGE_SIZE) - 1,
+ .ranges = &sit9531x_regmap_range,
+ .num_ranges = 1,
+ .volatile_reg = sit9531x_volatile_reg,
+ .cache_type = REGCACHE_MAPLE,
+};
+
+/*
+ * sit9531x_read_u8 - read an 8-bit register
+ * @reg: register in SIT9531X_REG(page, offset) form
+ * @val: output value
+ */
+int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
+ u8 *val)
+{
+ unsigned int tmp;
+ int rc;
+
+ reg = (SIT9531X_REG_PAGE(reg) * SIT9531X_PAGE_SIZE) +
+ SIT9531X_REG_OFFSET(reg) + SIT9531X_RANGE_OFFSET;
+
+ rc = regmap_read(sitdev->regmap, reg, &tmp);
+ if (rc)
+ dev_err(sitdev->dev, "Failed to read reg 0x%04x: %d\n",
+ reg, rc);
+ else
+ *val = (u8)tmp;
+
+ return rc;
+}
+
+/*
+ * sit9531x_write_u8 - write an 8-bit register
+ * @reg: register in SIT9531X_REG(page, offset) form
+ * @val: value to write
+ */
+int sit9531x_write_u8(struct sit9531x_dev *sitdev, unsigned int reg,
+ u8 val)
+{
+ int rc;
+
+ reg = (SIT9531X_REG_PAGE(reg) * SIT9531X_PAGE_SIZE) +
+ SIT9531X_REG_OFFSET(reg) + SIT9531X_RANGE_OFFSET;
+
+ rc = regmap_write(sitdev->regmap, reg, val);
+ if (rc)
+ dev_err(sitdev->dev, "Failed to write reg 0x%04x: %d\n",
+ reg, rc);
+
+ return rc;
+}
+
+/*
+ * sit9531x_read_pll_u8 - read a register on a PLL page
+ * @val: output value
+ */
+int sit9531x_read_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 offset, u8 *val)
+{
+ u8 page = sit9531x_pll_page(pll_idx);
+
+ return sit9531x_read_u8(sitdev, SIT9531X_REG(page, offset), val);
+}
+
+/*
+ * sit9531x_write_pll_u8 - write a register on a PLL page
+ * @val: value to write
+ */
+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);
+}
+
+/*
+ * sit9531x_update_pll_u8 - read-modify-write a register on a PLL page
+ * @mask: bits to modify
+ * @val: new value for masked bits
+ */
+int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 offset, u8 mask, u8 val)
+{
+ unsigned int reg;
+
+ reg = (sit9531x_pll_page(pll_idx) * SIT9531X_PAGE_SIZE) +
+ offset + SIT9531X_RANGE_OFFSET;
+
+ return regmap_update_bits(sitdev->regmap, reg, mask, val);
+}
+
+/*
+ * sit9531x_input_get_regs - get force mask and state register addresses
+ * @index: logical input index
+ * @force_reg: output force mask register address
+ * @state_reg: output state register address
+ *
+ * Selects the correct Page 0x02 register pair based on the pair's
+ * signal mode and the lane (P/N) the index refers to.
+ */
+static void sit9531x_input_get_regs(const struct sit9531x_dev *sitdev,
+ u8 index,
+ unsigned int *force_reg,
+ unsigned int *state_reg)
+{
+ if (sitdev->ref[index].sig_mode == SIT9531X_MODE_DE) {
+ *force_reg = SIT9531X_REG_IN_DE_FORCE;
+ *state_reg = SIT9531X_REG_IN_DE_STATE;
+ } else if (sit9531x_input_is_n(index)) {
+ *force_reg = SIT9531X_REG_IN_SEN_FORCE;
+ *state_reg = SIT9531X_REG_IN_SEN_STATE;
+ } else {
+ *force_reg = SIT9531X_REG_IN_SEP_FORCE;
+ *state_reg = SIT9531X_REG_IN_SEP_STATE;
+ }
+}
+
+/*
+ * sit9531x_input_disable - disable an input reference
+ * @index: logical input index (0-N)
+ *
+ * Sets the force mask bit and clears the state bit for the given
+ * input, effectively disabling it. Register selection depends on
+ * the pair's signal mode (SE/DE) and the lane (P/N); the bit within
+ * each register addresses the input pair.
+ *
+ * Both writes are attempted even when the first fails, and the first
+ * error is returned. Neither is rolled back: the force and state bits
+ * only mean something together, so a transient bus error can leave the
+ * force bit asserted over a state bit that was never programmed, and the
+ * error is what says the override is not to be trusted.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_input_disable(struct sit9531x_dev *sitdev, u8 index)
+{
+ unsigned int force_reg, state_reg;
+ struct sit9531x_ref *ref;
+ u8 pair, val;
+ int rc, ret;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ if (index >= SIT9531X_MAX_INPUTS)
+ return -EINVAL;
+
+ ref = &sitdev->ref[index];
+ pair = sit9531x_input_pair(index);
+ sit9531x_input_get_regs(sitdev, index, &force_reg, &state_reg);
+
+ rc = sit9531x_read_u8(sitdev, force_reg, &val);
+ if (!rc)
+ rc = sit9531x_write_u8(sitdev, force_reg, val | BIT(pair));
+
+ ret = sit9531x_read_u8(sitdev, state_reg, &val);
+ if (!ret)
+ ret = sit9531x_write_u8(sitdev, state_reg, val & ~BIT(pair));
+ if (ret && !rc)
+ rc = ret;
+
+ if (rc)
+ return rc;
+
+ ref->enabled = false;
+
+ return 0;
+}
+
+/*
+ * sit9531x_input_enable - enable an input reference
+ * @index: logical input index (0-N)
+ *
+ * Clears the force mask bit for the given input, returning it to
+ * hardware default (enabled).
+ *
+ * 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;
+
+ return 0;
+}
+
+/*
+ * Output enable / disable (Hi-Z control)
+ *
+ * SiT9531x outputs can be configured as differential (DIFF) or
+ * single-ended (SE) depending on the factory blob. Each output slot
+ * has TWO Hi-Z force/state register pairs on Page 0x03 -- one for the
+ * DIFF path, one for the SE path.
+ *
+ * We write to BOTH pairs so the function mutes the output regardless
+ * of whether it's been configured DIFF or SE on this board.
+ *
+ * slot 0-7 :
+ * DIFF mask=0xF2 state=0xF3 SE mask=0xF8 state=0xF9
+ * slot 8-11:
+ * DIFF mask=0xF4 state=0xF5 SE mask=0xFA state=0xFB
+ *
+ * MASK bit = 1 -> driver takes control of that output's Hi-Z state
+ * STATE bit = 0 -> output is forced to Hi-Z (muted)
+ * STATE bit = 1 -> output is driven (active)
+ *
+ * The output "index" in the driver is logical; the physical slot comes
+ * from info->clkout_map[].
+ */
+
+struct sit9531x_hiz_regs {
+ unsigned int diff_mask;
+ unsigned int diff_state;
+ unsigned int se_mask;
+ unsigned int se_state;
+ u8 bit;
+};
+
+static void sit9531x_output_get_hiz_regs(u8 slot,
+ struct sit9531x_hiz_regs *r)
+{
+ if (slot <= 7) {
+ r->diff_mask = SIT9531X_REG_HIZ_DIFF_07_MASK;
+ r->diff_state = SIT9531X_REG_HIZ_DIFF_07_STATE;
+ r->se_mask = SIT9531X_REG_HIZ_SE_07_MASK;
+ r->se_state = SIT9531X_REG_HIZ_SE_07_STATE;
+ r->bit = slot;
+ } else {
+ r->diff_mask = SIT9531X_REG_HIZ_DIFF_811_MASK;
+ r->diff_state = SIT9531X_REG_HIZ_DIFF_811_STATE;
+ r->se_mask = SIT9531X_REG_HIZ_SE_811_MASK;
+ r->se_state = SIT9531X_REG_HIZ_SE_811_STATE;
+ r->bit = slot - 8;
+ }
+}
+
+/*
+ * sit9531x_output_mode_fetch - read how an output is wired
+ *
+ * The Hi-Z force is a separate register pair for the differential and the
+ * single-ended path, and only the pair belonging to the way the output is
+ * actually wired says anything about whether it is quiet. The other pair
+ * holds whatever the loaded configuration left in it.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+static int sit9531x_output_mode_fetch(struct sit9531x_dev *sitdev, u8 out_idx)
+{
+ const struct sit9531x_chip_info *info = sitdev->info;
+ u8 slot, page, reg, val;
+ int rc;
+
+ slot = info->clkout_map[out_idx];
+ page = (slot > SIT9531X_PAGE_OUTSYS0_SLOT_MAX) ?
+ SIT9531X_PAGE_OUTSYS1 : SIT9531X_PAGE_OUTSYS0;
+ reg = SIT9531X_OUT_MISC0_BASE +
+ SIT9531X_OUT_MISC0_STRIDE * (slot % 6);
+
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG(page, reg), &val);
+ if (rc)
+ return rc;
+
+ sitdev->out[out_idx].cmos = !!(val & (SIT9531X_OUT_CMOS_ENP |
+ SIT9531X_OUT_CMOS_ENN));
+
+ return 0;
+}
+
+/*
+ * Report whether a slot is currently forced into Hi-Z, i.e. the driver
+ * (or the blob) took control of the Hi-Z state (MASK bit set) and drives
+ * it low (STATE bit clear). Either register pair muting the slot counts,
+ * mirroring what sit9531x_output_disable() programs.
+ */
+static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,
+ u8 out_idx, bool *muted)
+{
+ struct sit9531x_hiz_regs r;
+ unsigned int mask_reg, state_reg;
+ u8 mask, state;
+ int rc;
+
+ sit9531x_output_get_hiz_regs(sitdev->info->clkout_map[out_idx], &r);
+
+ /*
+ * Read the pair that belongs to the way this output is wired.
+ * Testing both and taking either as proof of a mute answers
+ * from a register nothing drives, and disagrees with itself
+ * when a mute lands on one pair and fails on the other.
+ */
+ if (sitdev->out[out_idx].cmos) {
+ mask_reg = r.se_mask;
+ state_reg = r.se_state;
+ } else {
+ mask_reg = r.diff_mask;
+ state_reg = r.diff_state;
+ }
+
+ rc = sit9531x_read_u8(sitdev, mask_reg, &mask);
+ if (rc)
+ return rc;
+ rc = sit9531x_read_u8(sitdev, state_reg, &state);
+ if (rc)
+ return rc;
+
+ *muted = (mask & BIT(r.bit)) && !(state & BIT(r.bit));
+
+ return 0;
+}
+
+/*
+ * sit9531x_output_state_refresh - read an output's mute state back
+ *
+ * Used when a mute could not be confirmed at the time it was written. The
+ * driver does not poll output state, so without this the cached value would
+ * stand until something else happened to write it.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_output_state_refresh(struct sit9531x_dev *sitdev, u8 out_idx)
+{
+ bool muted;
+ int rc;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ rc = sit9531x_output_forced_hiz(sitdev, out_idx, &muted);
+ if (rc)
+ return rc;
+
+ sitdev->out[out_idx].enabled = !muted;
+ sitdev->out[out_idx].state_stale = false;
+
+ return 0;
+}
+
+static int sit9531x_hiz_set_bit(struct sit9531x_dev *sitdev,
+ unsigned int reg, u8 bit, bool set)
+{
+ u8 cur, new_val;
+ int rc;
+
+ rc = sit9531x_read_u8(sitdev, reg, &cur);
+ if (rc)
+ return rc;
+
+ new_val = set ? (cur | BIT(bit)) : (cur & ~BIT(bit));
+
+ return sit9531x_write_u8(sitdev, reg, new_val);
+}
+
+/* Attempts to re-lock the output loops before reporting them open. */
+#define SIT9531X_LOOP_LOCK_TRIES 3
+
+/*
+ * sit9531x_prg_abort - leave the programming state without committing
+ *
+ * Entering the state is two writes, and the second can fail with the debug
+ * block already unlocked and the part possibly already in PRG_CMD. There
+ * is nothing to commit in that case, but the loops still have to be closed
+ * and the debug key put back, which is otherwise only done by
+ * sit9531x_prg_commit().
+ */
+static void sit9531x_prg_abort(struct sit9531x_dev *sitdev)
+{
+ u8 attempt;
+ int rc = -EIO;
+
+ for (attempt = 0; attempt < SIT9531X_LOOP_LOCK_TRIES; attempt++) {
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
+ SIT9531X_LOOP_LOCK);
+ if (!rc)
+ break;
+ usleep_range(1000, 2000);
+ }
+ if (rc)
+ dev_err(sitdev->dev,
+ "output loops left unlocked after a failed entry: %d\n",
+ rc);
+
+ sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
+ SIT9531X_DEBUG_LOCK_VAL);
+}
+
+/*
+ * Enter the output-system programming state: unlock the debug
+ * registers on Page 3 and issue the PRG_CMD state command. Register
+ * writes that reconfigure the output system only take effect when
+ * they are made inside this state.
+ */
+static int sit9531x_prg_enter(struct sit9531x_dev *sitdev)
+{
+ int rc;
+
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
+ SIT9531X_DEBUG_UNLOCK_VAL);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
+ SIT9531X_PRG_CMD_STATE);
+ if (rc) {
+ /*
+ * The debug block is unlocked at this point, and a transfer
+ * that reported an error may still have reached the part --
+ * which would leave the device in PRG_CMD with its output
+ * loops open. Callers skip the commit when the entry
+ * fails, so close both here.
+ */
+ sit9531x_prg_abort(sitdev);
+ return rc;
+ }
+
+ return 0;
+}
+
+/*
+ * Commit a programming sequence started by sit9531x_prg_enter():
+ * update the NVM shadow and re-lock the loops. The sleep gives the
+ * hardware its required settling time after the loop-lock command;
+ * it is intentional despite the caller holding multiop_lock, as the
+ * whole NVM + lock sequence must be atomic.
+ */
+static int sit9531x_prg_commit(struct sit9531x_dev *sitdev)
+{
+ int rc, rc2 = 0, rc3;
+ u8 attempt;
+
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
+ SIT9531X_UPDATE_NVM);
+
+ /*
+ * Issue the loop lock even if the update failed. Callers reach
+ * this function through a goto so that the chip never stays in
+ * the PRG_CMD state with its loops open; returning early here
+ * would defeat that and leave the outputs unlocked until the
+ * next successful commit.
+ */
+ /*
+ * Re-lock the loops. Leaving them open is worse than any other
+ * failure this function can report, and nothing else closes them,
+ * so retry as the priority table does with its own latch.
+ */
+ for (attempt = 0; attempt < SIT9531X_LOOP_LOCK_TRIES; attempt++) {
+ rc2 = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
+ SIT9531X_LOOP_LOCK);
+ if (!rc2)
+ break;
+ usleep_range(1000, 2000);
+ }
+ if (rc2)
+ dev_err(sitdev->dev,
+ "output loops left unlocked after programming: %d\n",
+ rc2);
+
+ msleep(100);
+
+ /*
+ * Put the output-system debug block back the way the device powers
+ * up. Its key register unlocks every debug register while it holds
+ * the unlock value, and each programming sequence writes that value
+ * itself, so nothing needs it left unlocked in between.
+ */
+ rc3 = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
+ SIT9531X_DEBUG_LOCK_VAL);
+
+ if (rc)
+ return rc;
+
+ return rc2 ? rc2 : rc3;
+}
+
+/*
+ * sit9531x_output_hiz_write - mute or unmute an output
+ *
+ * Muting takes control of the pin (MASK=1) and drives it low (STATE=0) on
+ * both the differential and the single-ended register pair, because the
+ * output must go quiet whichever way it is wired; unmuting hands it back
+ * to the device's own state machine. The caller must already be in the
+ * programming state.
+ */
+static int sit9531x_output_hiz_write(struct sit9531x_dev *sitdev, u8 slot,
+ bool mute)
+{
+ struct sit9531x_hiz_regs r;
+ int rc, undo_rc;
+
+ sit9531x_output_get_hiz_regs(slot, &r);
+
+ if (!mute) {
+ rc = sit9531x_hiz_set_bit(sitdev, r.diff_mask, r.bit, false);
+ if (rc)
+ return rc;
+
+ return sit9531x_hiz_set_bit(sitdev, r.se_mask, r.bit, false);
+ }
+
+ /*
+ * Forced value first, override enable second. Muted is decoded as
+ * MASK set with STATE clear, so enabling the override while STATE
+ * still holds whatever the loaded configuration left there can pin
+ * the pad driven for the width of an I2C transfer.
+ */
+ rc = sit9531x_hiz_set_bit(sitdev, r.diff_state, r.bit, false);
+ if (rc)
+ return rc;
+ rc = sit9531x_hiz_set_bit(sitdev, r.diff_mask, r.bit, true);
+ if (rc)
+ return rc;
+ rc = sit9531x_hiz_set_bit(sitdev, r.se_state, r.bit, false);
+ if (rc)
+ goto undo_diff;
+ rc = sit9531x_hiz_set_bit(sitdev, r.se_mask, r.bit, true);
+ if (rc)
+ goto undo_diff;
+
+ return 0;
+
+undo_diff:
+ /*
+ * Only one half of the pair reached the device. Release the
+ * override that did: that leaves the pad on the state the loaded
+ * configuration gave it, which is where the request started, rather
+ * than driven by half a mute that nothing afterwards clears.
+ */
+ undo_rc = sit9531x_hiz_set_bit(sitdev, r.diff_mask, r.bit, false);
+ if (undo_rc)
+ dev_err(sitdev->dev,
+ "slot%u: Hi-Z override left half applied (%d)\n",
+ slot, undo_rc);
+
+ return rc;
+}
+
+/*
+ * sit9531x_output_disable - mute an output (force Hi-Z)
+ * @index: logical output index (0..info->num_outputs-1)
+ *
+ * Sets MASK and clears STATE on BOTH the DIFF and SE register pairs so that the
+ * output is muted regardless of its electrical configuration. The
+ * writes are wrapped in the PRG_CMD / NVM update / loop lock sequence
+ * so the new state is applied by the hardware.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_output_disable(struct sit9531x_dev *sitdev, u8 index)
+{
+ const struct sit9531x_chip_info *info = sitdev->info;
+ bool muted;
+ u8 slot;
+ int rc, ret, state_rc;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ if (index >= info->num_outputs)
+ return -EINVAL;
+
+ slot = info->clkout_map[index];
+ rc = sit9531x_prg_enter(sitdev);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_output_hiz_write(sitdev, slot, true);
+
+ /*
+ * Always leave the PRG_CMD programming state, even on a mid-sequence
+ * write failure: prg_enter() unlocked the output loops, so returning
+ * without prg_commit() would strand the chip in the programming state
+ * with the loops unlocked. Best effort -- keep the first error.
+ */
+ ret = sit9531x_prg_commit(sitdev);
+ if (ret && !rc)
+ rc = ret;
+
+ /*
+ * Keep the software state aligned to what hardware now drives even
+ * when one write in the sequence failed. The commit above may have
+ * applied a partial mask/state combination.
+ */
+ state_rc = sit9531x_output_forced_hiz(sitdev, index, &muted);
+ if (!state_rc) {
+ sitdev->out[index].enabled = !muted;
+ sitdev->out[index].state_stale = false;
+ } else {
+ /*
+ * The writes may well have landed; what failed is the proof.
+ * Mark the cached state for a read-through rather than
+ * reporting the value it had before this call.
+ */
+ sitdev->out[index].state_stale = true;
+ if (!rc)
+ rc = state_rc;
+ }
+
+ return rc;
+}
+
+/*
+ * sit9531x_output_enable - un-mute an output (active state)
+ * @index: logical output index (0..info->num_outputs-1)
+ *
+ * Releases MASK on BOTH register pairs so the output returns to
+ * whatever the initial_config blob programmed. The writes are wrapped
+ * in the PRG_CMD / NVM update / loop lock sequence so the new state is
+ * applied by the hardware.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_output_enable(struct sit9531x_dev *sitdev, u8 index)
+{
+ const struct sit9531x_chip_info *info = sitdev->info;
+ bool muted;
+ u8 slot;
+ int rc, ret, state_rc;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ if (index >= info->num_outputs)
+ return -EINVAL;
+
+ slot = info->clkout_map[index];
+ rc = sit9531x_prg_enter(sitdev);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_output_hiz_write(sitdev, slot, false);
+
+ /*
+ * Always leave the PRG_CMD programming state, even on a mid-sequence
+ * write failure: prg_enter() unlocked the output loops, so returning
+ * without prg_commit() would strand the chip in the programming state
+ * with the loops unlocked. Best effort -- keep the first error.
+ */
+ ret = sit9531x_prg_commit(sitdev);
+ if (ret && !rc)
+ rc = ret;
+
+ /* See sit9531x_output_disable(): commit can apply part of it. */
+ state_rc = sit9531x_output_forced_hiz(sitdev, index, &muted);
+ if (!state_rc) {
+ sitdev->out[index].enabled = !muted;
+ sitdev->out[index].state_stale = false;
+ } else {
+ /*
+ * The writes may well have landed; what failed is the proof.
+ * Mark the cached state for a read-through rather than
+ * reporting the value it had before this call.
+ */
+ sitdev->out[index].state_stale = true;
+ if (!rc)
+ rc = state_rc;
+ }
+
+ return rc;
+}
+
+/*
+ * Input priority selection
+ *
+ * The SiT9531x has an 11-slot priority table per PLL on Page 1. Each
+ * register holds two slots nibble-packed: the earlier (even, 2n) slot
+ * in [7:4] and the later (odd, 2n+1) slot in [3:0].
+ *
+ * The 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
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+
+/* Page-1 register holding priority slot @slot of @pll_idx. */
+static u16 sit9531x_prio_reg(u8 pll_idx, u8 slot)
+{
+ return SIT9531X_REG(SIT9531X_PAGE_PRIOSYS,
+ SIT9531X_PRIO_BASE_REG +
+ SIT9531X_PRIO_REGS_PER_PLL * pll_idx +
+ slot / SIT9531X_PRIO_SLOTS_PER_REG);
+}
+
+/*
+ * Extract priority slot @slot from its register value. The register
+ * holding slots 2n and 2n+1 keeps the earlier slot in the high nibble
+ * (CLK_SPARE<2n>SEL) and the later one in the low nibble.
+ */
+static u8 sit9531x_prio_slot_get(u8 val, u8 slot)
+{
+ if (slot & 1)
+ return val & SIT9531X_PRIO_NIBBLE_MASK;
+
+ return val >> SIT9531X_PRIO_HI_SHIFT;
+}
+
+/* Place source @src in priority slot @slot of a register value. */
+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);
+}
+
+/*
+ * Commit a priority-table programming sequence through the Page-0
+ * programming directive register.
+ *
+ * A small change update is all the table needs. The NVM-bank and
+ * loop-lock directives that the output system issues do not belong
+ * here: the former programs non-volatile storage from the efuse and
+ * the latter only means anything after an escape to the PRG_CMD
+ * state. This matches the documented input_priority_sel() procedure.
+ */
+static int sit9531x_prio_prg_commit(struct sit9531x_dev *sitdev)
+{
+ int rc;
+
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_GLOBAL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ if (rc)
+ return rc;
+
+ usleep_range(1000, 2000);
+
+ return 0;
+}
+
+/*
+ * Fold a source code to the lane a DPLL pin actually represents.
+ *
+ * Differential input pairs expose only the P lane as a DPLL pin. A
+ * priority table entry encoded as an N lane for such a pair must map to
+ * the P-lane source for pin-facing operations (membership, priority slots,
+ * add/remove/set lookups), matching sit9531x_ref_pll_mask_fetch().
+ */
+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;
+}
+
+/*
+ * sit9531x_input_prio_present - is a source listed in a PLL's priority table
+ * @input_idx: input source in hardware encoding (see
+ * sit9531x_input_hw_src())
+ *
+ * Answers from the membership mask that every table write and every poll
+ * refreshes, which is what the pin state getters test. The priority slot
+ * cannot answer this: a source that is not in the table reports the lowest
+ * slot, so the slot value alone does not separate absent from last.
+ *
+ * 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));
+}
+
+/*
+ * sit9531x_input_prio_get - read an input's priority slot for a PLL
+ * @input_idx: input source in hardware encoding (see
+ * sit9531x_input_hw_src())
+ * @prio: output slot position (0 = highest)
+ *
+ * Reports the last slot this source occupied on this PLL. The value is
+ * cached from the hardware table read at startup and refreshed after every
+ * table write and poll read-back, so pin-get reflects hardware state without
+ * issuing synchronous register reads per pin. A source with no known slot
+ * falls back to the lowest-priority valid slot.
+ *
+ * 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;
+ u8 slot;
+
+ 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];
+ slot = chan->prio_last[input_idx];
+ if (!slot)
+ slot = SIT9531X_PRIO_MAX_SLOTS;
+
+ *prio = slot - 1;
+
+ return 0;
+}
+
+/*
+ * Refresh a PLL's cached view of its priority table from the source codes
+ * the table holds -- here after a write, and once per poll from the
+ * read-back in sit9531x_chan_state_fetch().
+ *
+ * The membership mask is what the pin state getters test; the per-slot
+ * copy and the last-slot-seen array are what priority get answers from,
+ * so neither costs a register read per pin.
+ */
+static void sit9531x_prio_mask_build(struct sit9531x_dev *sitdev, u8 pll_idx,
+ const u8 *srcs, u8 written)
+{
+ struct sit9531x_chan *chan = &sitdev->chan[pll_idx];
+ u8 first[SIT9531X_PRIO_NUM_SRC] = { 0 };
+ u16 mask = 0;
+ u8 slot, src, src_canon;
+
+ for (slot = 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {
+ /*
+ * A slot the caller could not write still holds what it
+ * held before, so take that rather than the value the
+ * request wanted to put there.
+ */
+ src = slot < written ? srcs[slot] : chan->prio_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;
+ }
+
+ /*
+ * Assign unconditionally: a source that has left the table has no
+ * slot, and leaving its old one behind would keep reporting it as
+ * listed for as long as the device runs.
+ */
+ for (src = 0; src < SIT9531X_PRIO_NUM_SRC; src++)
+ chan->prio_last[src] = first[src];
+
+ chan->prio_mask = mask;
+}
+
+/* Attempts to release a forced holdover before reporting it stuck. */
+#define SIT9531X_HO_CLEAR_TRIES 3
+
+static int sit9531x_prio_table_commit(struct sit9531x_dev *sitdev, u8 pll_idx,
+ const u8 *srcs)
+{
+ struct sit9531x_chan *chan = &sitdev->chan[pll_idx];
+ u8 val, slot, attempt, written = 0, restored = 0;
+ int rc = 0, prg_rc, ho_rc = 0;
+ u16 reg;
+
+ rc = sit9531x_update_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_HO_CTRL,
+ BIT(SIT9531X_PLL_HO_FORCE_BIT),
+ BIT(SIT9531X_PLL_HO_FORCE_BIT));
+ if (rc)
+ return rc;
+
+ usleep_range(10000, 12000);
+
+ /*
+ * Two slots share a register, and this writes every slot, so both
+ * nibbles are known for every register but the last -- build those
+ * bytes outright. Reading first would raise the question of what a
+ * read returns between the write and the latch, and the answer does
+ * not matter if nothing is read.
+ */
+ 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]);
+
+ rc = sit9531x_write_u8(sitdev, reg, val);
+ if (rc)
+ goto commit;
+
+ written = slot + 2;
+ }
+
+ /*
+ * The last slot shares its register with a nibble this table does
+ * not use, so that one is read first to leave it as it was.
+ */
+ reg = sit9531x_prio_reg(pll_idx, slot);
+
+ rc = sit9531x_read_u8(sitdev, reg, &val);
+ if (rc)
+ goto commit;
+
+ val = sit9531x_prio_slot_set(val, slot, srcs[slot]);
+
+ rc = sit9531x_write_u8(sitdev, reg, val);
+ if (rc)
+ goto commit;
+
+ written = SIT9531X_PRIO_MAX_SLOTS;
+
+ if (rc && written) {
+ /*
+ * Put the slots that did reach the device back the way they
+ * were. Latching a table that is neither the previous order
+ * nor the requested one hands the reference selection loop
+ * a priority list nobody asked for. The cache is the table
+ * as last read, which is what those slots held.
+ */
+ for (slot = 0; slot < written; slot += 2) {
+ u8 old;
+
+ old = sit9531x_prio_slot_set(0, slot,
+ chan->prio_srcs[slot]);
+ old = sit9531x_prio_slot_set(old, slot + 1,
+ chan->prio_srcs[slot + 1]);
+ if (sit9531x_write_u8(sitdev,
+ sit9531x_prio_reg(pll_idx, slot),
+ old))
+ break;
+
+ restored = slot + 2;
+ }
+ written = restored;
+ }
+
+commit:
+ /*
+ * Latch unconditionally: the slots that reached the device are in
+ * the table regardless, so the latch keeps hardware and the cache
+ * refresh below consistent with what was actually written.
+ */
+ prg_rc = sit9531x_prio_prg_commit(sitdev);
+ if (prg_rc && !rc)
+ rc = prg_rc;
+
+ /*
+ * Refresh the cache from the table just written, so a get that
+ * follows a set does not have to wait for the next poll -- but only
+ * for the slots that reached the device. Describing a table that
+ * does not exist would make the membership test answer for writes
+ * that failed, and that test is what decides whether a failed
+ * request gets rolled back.
+ */
+ sit9531x_prio_mask_build(sitdev, pll_idx, srcs, written);
+
+ /*
+ * Release the forced holdover. Nothing else in the driver clears
+ * this bit, so a PLL left with it set reports holdover until the
+ * next table write on the same PLL happens to clear it, which may
+ * never come. Retry before giving up, and say so if it stays set.
+ */
+ 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;
+ }
+
+ return rc;
+}
+
+/*
+ * sit9531x_prio_table_read - read a PLL's priority-table source codes
+ * @srcs: output array of SIT9531X_PRIO_MAX_SLOTS source codes
+ *
+ * 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;
+}
+
+/*
+ * sit9531x_input_prio_set - move an input to a priority slot
+ * @input_idx: input source in hardware encoding (0-11, see
+ * sit9531x_input_hw_src())
+ * @prio: priority slot position (0 = highest)
+ *
+ * Reads the PLL's table, takes the source out of wherever it sits and
+ * reinserts it at @prio, shifting the entries in between. The rest keep
+ * their relative order: a priority change asks about one input, so the
+ * fallbacks configured behind it have to survive it.
+ *
+ * The table is what makes a source eligible for this PLL, so this only
+ * ever reorders sources already in it. A source that is absent is
+ * disconnected on this PLL, and inserting it here would make it a
+ * selection candidate again behind the caller's back; that is a connect,
+ * and it belongs to the pin's state setter.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ *
+ * Return: 0 on success, -EINVAL if the source is not in the table,
+ * <0 on error
+ */
+int sit9531x_input_prio_set(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 input_idx, u8 prio)
+{
+ u8 orig_srcs[SIT9531X_PRIO_MAX_SLOTS];
+ u8 rest[SIT9531X_PRIO_MAX_SLOTS];
+ u8 srcs[SIT9531X_PRIO_MAX_SLOTS];
+ u8 slot, n = 0;
+ 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;
+ if (prio >= SIT9531X_PRIO_MAX_SLOTS)
+ return -EINVAL;
+
+ rc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);
+ if (rc)
+ return rc;
+
+ memcpy(orig_srcs, srcs, sizeof(srcs));
+
+ /*
+ * Take every copy of the source out first. A disconnect backfills
+ * the slots it frees with the lowest-priority source still listed,
+ * so the same source appearing more than once is an ordinary state
+ * of the table, and shifting from its first copy alone can leave
+ * another copy ahead of the slot the request named -- a priority
+ * the request did not ask for and the getter would then report.
+ */
+ for (slot = 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++)
+ if (sit9531x_prio_src_canon(sitdev, srcs[slot]) != input_idx)
+ rest[n++] = srcs[slot];
+
+ if (n == SIT9531X_PRIO_MAX_SLOTS)
+ return -EINVAL;
+
+ /*
+ * Once the copies are collapsed the source can only sit behind the
+ * other sources the table lists, because the slots past the last of
+ * them repeat it. A slot beyond that is a priority the table cannot
+ * express, and placing the source at the nearest one it can would
+ * report success for a priority nobody asked for.
+ */
+ if (prio > n)
+ return -ERANGE;
+
+ for (slot = 0; slot < prio; slot++)
+ srcs[slot] = rest[slot];
+
+ srcs[prio] = input_idx;
+
+ for (slot = prio + 1; slot < SIT9531X_PRIO_MAX_SLOTS; slot++)
+ srcs[slot] = (slot - 1 < n) ? rest[slot - 1] : srcs[slot - 1];
+ if (!memcmp(srcs, orig_srcs, sizeof(srcs)))
+ return 0;
+
+ return sit9531x_prio_table_commit(sitdev, pll_idx, srcs);
+}
+
+/*
+ * sit9531x_input_prio_remove - drop an input from a PLL's priority table
+ * @input_idx: input source in hardware encoding
+ *
+ * Rewrites the priority table with the source removed: the remaining
+ * sources are compacted toward the highest-priority slots and the freed
+ * tail slots are backfilled with the lowest-priority remaining source.
+ * This makes a disconnected input ineligible for automatic reference
+ * selection, not just gated at the input buffer.
+ *
+ * Removing a source that is absent is what the caller asked for already,
+ * so it succeeds without touching the table. Removing the last one fills
+ * every slot with the code for the pair this part does not have, which
+ * leaves the device with nothing to select and no reference to fall back
+ * on -- which is what a request to disconnect the last input means.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ *
+ * Return: 0 on success, <0 on error
+ */
+int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 input_idx)
+{
+ u8 srcs[SIT9531X_PRIO_MAX_SLOTS];
+ u8 kept[SIT9531X_PRIO_MAX_SLOTS];
+ u8 slot, count = 0;
+ bool found = false;
+ 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);
+
+ rc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);
+ if (rc)
+ return rc;
+
+ for (slot = 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {
+ if (sit9531x_prio_src_canon(sitdev, srcs[slot]) == input_idx)
+ found = true;
+ else
+ kept[count++] = srcs[slot];
+ }
+
+ if (!found)
+ return 0;
+
+ if (count == 0) {
+ /*
+ * Nothing is left to compact toward, so every slot gets the
+ * code that names no reference. The device is then left
+ * with no source to select, which is what disconnecting the
+ * last input asks for; lock status follows the loop on its
+ * own from there.
+ */
+ memset(kept, SIT9531X_PRIO_SRC_NONE, sizeof(kept));
+ } else {
+ /* Backfill freed tail slots with the lowest-priority src */
+ while (count < SIT9531X_PRIO_MAX_SLOTS) {
+ kept[count] = kept[count - 1];
+ count++;
+ }
+ }
+
+ return sit9531x_prio_table_commit(sitdev, pll_idx, kept);
+}
+
+/*
+ * sit9531x_input_prio_add - make an input eligible in a PLL's table
+ * @input_idx: input source in hardware encoding
+ *
+ * Ensures the source appears in the priority table so it can be picked
+ * by automatic reference selection again after a disconnect. If the
+ * source is already listed the table is left untouched; otherwise it
+ * replaces a duplicate at the tail. A table that contains only unique
+ * sources cannot accept a new one without evicting another, so that
+ * case fails with -ENOSPC.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 input_idx)
+{
+ u8 srcs[SIT9531X_PRIO_MAX_SLOTS];
+ u8 seen[SIT9531X_PRIO_NUM_SRC] = { 0 };
+ u8 replace = SIT9531X_PRIO_MAX_SLOTS;
+ u8 slot, src, src_canon;
+ 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;
+
+ rc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);
+ if (rc)
+ return rc;
+
+ for (slot = 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++)
+ if (sit9531x_prio_src_canon(sitdev, srcs[slot]) == input_idx)
+ return 0;
+
+ for (slot = 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {
+ src = srcs[slot] & SIT9531X_PRIO_NIBBLE_MASK;
+ src_canon = sit9531x_prio_src_canon(sitdev, src);
+ if (!sit9531x_prio_src_usable(src))
+ continue;
+
+ seen[src_canon]++;
+ }
+
+ /*
+ * A slot whose code names no usable source -- a reserved value, or
+ * one past the inputs this variant has -- is free space, and taking
+ * it costs nothing. Prefer it over displacing a real reference.
+ */
+ for (slot = SIT9531X_PRIO_MAX_SLOTS; slot-- > 0;) {
+ src = srcs[slot] & SIT9531X_PRIO_NIBBLE_MASK;
+ if (!sit9531x_prio_src_usable(src)) {
+ replace = slot;
+ break;
+ }
+ }
+
+ /* Otherwise take the last slot holding a source listed twice. */
+ for (slot = SIT9531X_PRIO_MAX_SLOTS;
+ replace == SIT9531X_PRIO_MAX_SLOTS && slot-- > 0;) {
+ src = srcs[slot] & SIT9531X_PRIO_NIBBLE_MASK;
+ src_canon = sit9531x_prio_src_canon(sitdev, src);
+ if (!sit9531x_prio_src_usable(src))
+ continue;
+
+ if (seen[src_canon] > 1) {
+ replace = slot;
+ break;
+ }
+ }
+
+ if (replace == SIT9531X_PRIO_MAX_SLOTS)
+ return -ENOSPC;
+
+ srcs[replace] = input_idx;
+
+ return sit9531x_prio_table_commit(sitdev, pll_idx, srcs);
+}
+
+/* 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
+
+/* The output divider is a 34-bit field */
+#define SIT9531X_DIVO_MAX GENMASK_ULL(33, 0)
+
+/*
+ * sit9531x_is_xo_doubler_enabled - check if Fref doubler is active
+ *
+ * Register 0x2D bit 7 is active-low: 0 = doubler enabled, 1 = disabled.
+ *
+ * Return: 1 if enabled, 0 if disabled, <0 on error
+ */
+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;
+}
+
+/*
+ * sit9531x_dbg_sample - latch and read a signal pathway debug sample
+ * @sitdev: device pointer
+ * @pll_idx: PLL index (0-3)
+ * @read_code: which tap of the pathway to sample
+ * @low_freq_clk: sample with the slow debug clock, which taps below
+ * 200 kHz need
+ * @buf: result, least significant byte first
+ * @len: bytes to read, at most SIT9531X_DBG_DATA_BYTES
+ *
+ * Return: 0 on success, <0 on error
+ */
+static int sit9531x_dbg_sample(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 read_code, bool low_freq_clk,
+ u8 *buf, unsigned int len)
+{
+ unsigned int i;
+ int rc, lock_rc;
+ u8 v;
+
+ if (len > SIT9531X_DBG_DATA_BYTES)
+ return -EINVAL;
+
+ rc = sit9531x_write_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_DEBUG,
+ SIT9531X_PLL_DEBUG_UNLOCK);
+ if (rc)
+ goto relock;
+
+ /*
+ * Select the debug clock this tap needs. The device never clears
+ * the bit, so a read that left it to whatever the previous one set
+ * would depend on the order the taps happened to be read in. Taps
+ * below 200 kHz need the slow clock; the divider taps do not.
+ */
+ rc = sit9531x_update_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_WRITE_CODE,
+ SIT9531X_DBG_LOW_FREQ_CLK_BIT,
+ low_freq_clk ?
+ SIT9531X_DBG_LOW_FREQ_CLK_BIT : 0);
+ if (rc)
+ goto relock;
+
+ rc = sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_READ_CODE, read_code);
+ if (rc)
+ goto relock;
+
+ /*
+ * Reading the trigger latches a sample of the selected tap. Read it
+ * three times, as the documented phase-difference procedure does and as
+ * sit9531x_phase_offset_read() already did: a single read returns
+ * the previous latch, so a caller sampling repeatedly gets the same
+ * value back however much the tap has moved.
+ */
+ for (i = 0; i < SIT9531X_DBG_LATCH_READS; i++) {
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_TRIGGER, &v);
+ if (rc)
+ goto relock;
+ }
+
+ for (i = 0; i < len; i++) {
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_DATA_0 + i,
+ &buf[i]);
+ if (rc)
+ goto relock;
+ }
+
+ rc = 0;
+
+relock:
+ /*
+ * Close the debug window again. The key register opens every debug
+ * register on this PLL while it holds the unlock value, and these
+ * samples run on ordinary monitoring paths, so leaving it open would
+ * unlock the block for as long as the device runs.
+ */
+ lock_rc = sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DEBUG,
+ SIT9531X_PLL_DEBUG_LOCK);
+ if (lock_rc && !rc)
+ rc = lock_rc;
+
+ return rc;
+}
+
+/*
+ * DIVN as a fixed-point value: int_part plus fracn/fracd, carried with
+ * SIT9531X_DIVN_SCALE steps per unit. The scale keeps a whole DIVN
+ * well inside s64 while resolving far below the parts-per-trillion the
+ * frequency offset is reported in.
+ */
+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;
+}
+
+/*
+ * sit9531x_divn_static - read the configured DIVN of a PLL
+ * @sitdev: device pointer
+ * @pll_idx: PLL index (0-3)
+ * @divn: result, fixed point as per sit9531x_divn_fixed()
+ *
+ * Reads PLL page regs 0x30 (integer part), 0x32-0x35 (numerator) and
+ * 0x38-0x3B (denominator). The numerator is a two's complement 32-bit
+ * value, so DIVN can sit below the integer part, and the denominator
+ * register holds the divisor minus one.
+ *
+ * Return: 0 on success, <0 on error
+ */
+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;
+ }
+
+ /*
+ * NUM/DEN is the fractional part of DIVN, so |NUM| is below DEN by
+ * construction. A pair that says otherwise did not come from a
+ * programmed divider, and handing it on would divide by a
+ * denominator small enough for the quotient to leave u64 -- which
+ * is a divide-error exception on x86, not a value a caller could
+ * reject.
+ */
+ 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;
+}
+
+/*
+ * sit9531x_divn_runtime - read the DIVN the digital loop is commanding
+ * @sitdev: device pointer
+ * @pll_idx: PLL index (0-3)
+ * @divn: result, fixed point as per sit9531x_divn_fixed()
+ *
+ * Same quantity as sit9531x_divn_static(), but sampled from the running
+ * loop rather than from the configuration registers, and carried at a
+ * wider precision: the numerator is 48 bits, two's complement, the
+ * denominator 49. The integer part shares its tap with the numerator.
+ *
+ * The denominator is taken as it reads. The configuration register holds
+ * the divisor minus one, and correcting for that reproduces a profile's
+ * stated VCO exactly, to the last bit of the fraction; this tap is a wider
+ * field sampled from the loop itself and the documented readback uses it as it
+ * comes, so the bias is not applied here.
+ *
+ * The numerator and the denominator come from two separate latches:
+ * the debug window exposes one tap at a time, so the pair can be torn
+ * by a loop that moves between them. The divider changes by parts per
+ * trillion between samples on a locked loop, which is below what this
+ * measurement resolves.
+ *
+ * Return: 0 on success, <0 on error
+ */
+static int sit9531x_divn_runtime(struct sit9531x_dev *sitdev, u8 pll_idx,
+ s64 *divn)
+{
+ u8 buf[SIT9531X_DBG_DATA_BYTES];
+ u64 fracn_raw = 0, fracd = 0;
+ u32 int_part;
+ s64 fracn;
+ int rc, i;
+
+ rc = sit9531x_dbg_sample(sitdev, pll_idx, SIT9531X_DBG_READ_CODE_DIVN,
+ false, buf, SIT9531X_DBG_DATA_BYTES);
+ if (rc)
+ return rc;
+
+ for (i = 5; i >= 0; i--)
+ fracn_raw = (fracn_raw << 8) | buf[i];
+
+ int_part = buf[6] | ((u32)(buf[7] & SIT9531X_DIVN_RT_INT_HI_BIT) << 8);
+
+ rc = sit9531x_dbg_sample(sitdev, pll_idx,
+ SIT9531X_DBG_READ_CODE_DIVN_DEN, false, buf,
+ SIT9531X_DBG_DATA_BYTES);
+ if (rc)
+ return rc;
+
+ for (i = 5; i >= 0; i--)
+ fracd = (fracd << 8) | buf[i];
+
+ fracd |= (u64)(buf[6] & SIT9531X_DIVN_RT_DEN_HI_BIT) << 48;
+
+ fracn = sign_extend64(fracn_raw, SIT9531X_DIVN_RT_NUM_BITS - 1);
+
+ /*
+ * sit9531x_divn_fixed() drops the fractional part when the
+ * denominator is zero. That is right for a configuration register
+ * that was never programmed, but a running loop reading zero means
+ * the sample is unusable, and returning the whole part alone would
+ * put a wrong DIVN into the frequency offset without saying so.
+ *
+ * A numerator at or above the denominator is not a fraction either,
+ * and would divide by a denominator small enough for the quotient
+ * to leave u64 -- a divide-error exception on x86 rather than a
+ * value sit9531x_get_fvco() could reject.
+ */
+ if (!fracd || (u64)abs(fracn) >= fracd)
+ return -ENODATA;
+ *divn = sit9531x_divn_fixed(int_part, fracn, fracd);
+
+ return 0;
+}
+
+/**
+ * sit9531x_pll_ffo_ppt - fractional frequency offset of a PLL's reference
+ * @sitdev: device pointer
+ * @pll_idx: PLL index (0-3)
+ * @ffo: result in parts per trillion
+ *
+ * A locked PLL commands whatever DIVN keeps its VCO tracking the
+ * reference. How far that sits from the configured DIVN is how far the
+ * reference sits from the local oscillator, which is the fractional
+ * frequency offset the DPLL ABI reports for the pin feeding the device.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ *
+ * Return: 0 on success, <0 on error. -ENODATA covers every reason the
+ * ratio cannot be formed: a DIVN that was never programmed, a runtime
+ * sample that is not a running loop, and a configured divider below one
+ * whole unit.
+ */
+int sit9531x_pll_ffo_ppt(struct sit9531x_dev *sitdev, u8 pll_idx, s64 *ffo)
+{
+ s64 configured, running, delta;
+ u64 magnitude;
+ int rc;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ if (pll_idx >= SIT9531X_NUM_PLLS)
+ return -EINVAL;
+
+ rc = sit9531x_divn_static(sitdev, pll_idx, &configured);
+ if (rc)
+ return rc;
+ /*
+ * Scaling by a divider far below one whole cycle overflows the
+ * 64-bit product and comes back as ~0, which would be reported
+ * as a plausible offset. A DIVN that small is not a running
+ * loop, so treat it as no measurement.
+ */
+ if (configured < SIT9531X_DIVN_SCALE)
+ return -ENODATA;
+
+ rc = sit9531x_divn_runtime(sitdev, pll_idx, &running);
+ if (rc)
+ return rc;
+
+ delta = running - configured;
+ magnitude = mul_u64_u64_div_u64(abs(delta), SIT9531X_PPT_PER_UNIT,
+ (u64)configured);
+
+ *ffo = delta < 0 ? -(s64)magnitude : (s64)magnitude;
+
+ return 0;
+}
+
+/*
+ * sit9531x_get_fvco - the VCO frequency the driver works from
+ *
+ * A board that describes the VCO through "sitime,pll-fvco" is taken at
+ * its word and nothing is read. Otherwise Fvco = Fref * DIVN, where
+ * DIVN comes from sit9531x_divn_static() and Fref = xtal_freq <<
+ * doubler. DIVN is the steady-state Fvco/Fref target programmed by the
+ * NVM blob and is authoritative in both free-run and sync modes; the
+ * result is clamped to the band the PLL runs in, so every caller divides
+ * the same number.
+ *
+ * Return: 0 with *fvco set on success, -ENODATA when DIVN is not
+ * programmed (dormant PLL), or the register access error. A bus
+ * failure is never folded into the -ENODATA case, so callers can fail
+ * a request instead of acting on a guessed rate.
+ */
+static int sit9531x_get_fvco(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u64 *fvco)
+{
+ u64 fref, fvco_min, fvco_max;
+ int doubler, rc;
+ s64 divn;
+
+ /*
+ * DT board-config override: some configs (e.g. an INTSYNC PLL)
+ * run a VCO that Fref*DIVN does not reproduce. When the board
+ * supplies the measured VCO, use it verbatim.
+ */
+ if (pll_idx < SIT9531X_NUM_PLLS && sitdev->pll_fvco[pll_idx]) {
+ *fvco = sitdev->pll_fvco[pll_idx];
+ return 0;
+ }
+
+ if (pll_idx == 1 || pll_idx == 3) {
+ /* PLLB, PLLD: high band */
+ fvco_min = SIT9531X_FVCO_HIGHBAND_MIN;
+ fvco_max = SIT9531X_FVCO_HIGHBAND_MAX;
+ } else {
+ /* PLLA, PLLC: low band */
+ fvco_min = SIT9531X_FVCO_LOWBAND_MIN;
+ fvco_max = SIT9531X_FVCO_LOWBAND_MAX;
+ }
+
+ 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;
+
+ *fvco = mul_u64_u64_div_u64(fref, (u64)divn, SIT9531X_DIVN_SCALE);
+
+ /*
+ * A DIVN of less than one whole cycle passes the check above and
+ * still truncates the product to zero. Callers divide by this, so
+ * report the unprogrammed divider it describes rather than handing
+ * back a zero denominator.
+ */
+ if (!*fvco)
+ return -ENODATA;
+
+ /*
+ * The bands bound what the VCO can physically run at, and a rate
+ * derived from registers the loaded configuration may never have
+ * programmed can fall outside them. Clamp rather than refuse:
+ * the readback is the only estimate available, and refusing would
+ * make every output unprogrammable on such a part. Clamping here
+ * rather than in the divider calculation keeps the rate a frequency
+ * get reports and the rate a frequency set divides the same one.
+ */
+ if (*fvco < fvco_min)
+ *fvco = fvco_min;
+ else if (*fvco > fvco_max)
+ *fvco = fvco_max;
+
+ return 0;
+}
+
+/*
+ * sit9531x_output_phase_flush - flush the output phase of a PLL
+ *
+ * Fires the chip's on-demand phase-flush (PHFL) so every output divider
+ * of @pll_idx restarts aligned to the PLL phase. Without it a rewritten
+ * DIVO keeps counting from an arbitrary point and the output edge lands
+ * with a persistent offset against the tracked reference (only a power
+ * cycle realigned it).
+ *
+ * The sequence mirrors the documented procedure: arm the on-demand PHFL and
+ * latch it with the PLL-page small-change update, then select the
+ * in-register phase trigger on Page 0 and pulse it. The Page 0 trigger
+ * register is touched read-modify-write so the unrelated OEb bits are
+ * preserved.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)
+{
+ u8 ctrl, orig;
+ int rc, ret;
+
+ /* Arm the on-demand phase-flush on the PLL page. */
+ 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)
+ return rc;
+
+ /*
+ * Latch it with the PLL small-change update. Written whole, like
+ * every other issue of this directive: the register is a command
+ * register, and a read-modify-write skips the write entirely when
+ * the bit still reads back set from the previous command.
+ */
+ rc = sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_SMALL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ if (rc)
+ goto disarm;
+
+ /*
+ * Select the in-register phase trigger, preserving the OEb bits.
+ * Remember the original register value (with the trigger de-asserted)
+ * so the trigger-source select can be restored once the pulse has
+ * fired.
+ */
+ 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 disarm;
+
+ /*
+ * Pulse the phase trigger. No explicit delay is needed between the
+ * set and clear writes: each I2C transaction takes far longer than
+ * any minimum pulse width.
+ */
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1,
+ ctrl | SIT9531X_DIVO_PHASE_TRIG);
+
+ /*
+ * Restore the original trigger-source select. The pulse above has
+ * already latched the flush, so a one-shot flush must not leave the
+ * phase trigger permanently pinned to the in-register source. This
+ * runs even when the pulse write failed, otherwise a failed flush
+ * would keep a hardware trigger source hijacked; the restore error
+ * is only surfaced when it would not mask the pulse failure.
+ */
+ ret = sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, orig);
+ if (ret && !rc)
+ rc = ret;
+
+disarm:
+ /*
+ * Disarm the on-demand flush enable armed above. Leaving it set
+ * would let a later assertion of the restored trigger source
+ * re-flush every output divider of this PLL, which is exactly the
+ * persistent side effect the one-shot sequence must not have.
+ */
+ ret = sit9531x_update_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_PHFL_CTRL,
+ SIT9531X_PLL_PHFL_ON_DEMAND_EN, 0);
+ if (!ret)
+ ret = sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_SMALL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ if (ret && !rc)
+ rc = ret;
+
+ return rc;
+}
+
+/*
+ * sit9531x_output_divo_calc - work out an output's divider and its VCO
+ *
+ * Separated from the write so a caller that programs more than the
+ * divider in one sequence can compute the value before it enters 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;
+ int rc;
+
+ if (out_idx >= info->num_outputs || pll_idx >= SIT9531X_NUM_PLLS)
+ return -EINVAL;
+
+ if (!frequency)
+ return -EINVAL;
+
+ /*
+ * The core validates the request against the supported ranges with
+ * the value narrowed to u32 but hands the full u64 down, so a value
+ * like U32_MAX + 1 Hz validates as 1 Hz. Reject anything that does
+ * not fit the narrowed width the validation actually covered.
+ */
+ if (frequency > U32_MAX)
+ return -EINVAL;
+
+ /*
+ * sit9531x_get_fvco() returns the board override verbatim and a
+ * register-derived rate clamped to the PLL's band, so a frequency
+ * get and a frequency set divide the same number. A VCO that
+ * cannot be read fails the request: programming a divider from a
+ * guessed rate would put the output far from what was asked for
+ * while reporting success.
+ */
+ rc = sit9531x_get_fvco(sitdev, pll_idx, &fvco);
+ if (rc)
+ return rc == -ENODATA ? -ENODEV : rc;
+
+ /*
+ * Round to nearest rather than down: flooring picks the worse of the
+ * two adjacent dividers whenever the remainder is above half the
+ * request.
+ */
+ divo = div64_u64(fvco + frequency / 2, frequency);
+ if (!divo)
+ return -EINVAL;
+
+ /*
+ * DIVO is a 34-bit field. With a band-clamped Fvco this cannot
+ * overflow, but a DT Fvco override is taken verbatim, so guard the
+ * field width rather than silently truncating the divider.
+ */
+ if (divo > SIT9531X_DIVO_MAX)
+ return -EINVAL;
+
+ /*
+ * The output divider is an integer divider of the VCO, so the only
+ * rates the part can make are Fvco/N. An output pin that lists no
+ * supported frequencies advertises a continuous range, because the
+ * divisors cannot be enumerated ahead of a known Fvco, so a request
+ * for a rate between two of them arrives here. Refuse it: running
+ * the output at the nearest divider instead and reporting success
+ * would leave the pin several percent off what was asked for with
+ * nothing saying so.
+ */
+ if (div64_u64(fvco, divo) != frequency) {
+ dev_dbg(sitdev->dev,
+ "out%u: %llu Hz is not Fvco/N (Fvco=%llu, nearest %llu Hz)\n",
+ out_idx, frequency, fvco, div64_u64(fvco, divo));
+ return -EINVAL;
+ }
+
+ dev_dbg(sitdev->dev,
+ "out%u: Fvco=%llu freq=%llu DIVO=%llu (effective %llu Hz)\n",
+ out_idx, fvco, frequency, divo, div64_u64(fvco, divo));
+
+ *fvco_out = fvco;
+ *divo_out = divo;
+
+ return 0;
+}
+
+/*
+ * sit9531x_output_divo_write - write the five DIVO bytes of an output
+ *
+ * The caller must already be in the programming state. Bytes written
+ * before a failure are put back, so the output keeps the divider it had
+ * rather than a mixture of the two.
+ */
+static int sit9531x_output_divo_write(struct sit9531x_dev *sitdev, u8 out_idx,
+ u64 divo)
+{
+ const struct sit9531x_chip_info *info = sitdev->info;
+ u8 slot, page, base_reg, divo_bytes[5], old_bytes[5], msb_old;
+ int rc, j, rb_rc;
+ u8 written = 0;
+
+ /* Map output index to physical slot */
+ slot = info->clkout_map[out_idx];
+
+ /* Determine page and per-page slot register */
+ 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:
+ for (j = 0; j < written; j++) {
+ rb_rc = sit9531x_write_u8(sitdev,
+ SIT9531X_REG(page, base_reg - j),
+ old_bytes[j]);
+ if (rb_rc) {
+ 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;
+}
+
+/**
+ * sit9531x_output_phase_read - read an output's programmed delay back
+ * @sitdev: device pointer
+ * @out_idx: logical output index
+ * @phase_ps: result in picoseconds, always a delay (never an advance)
+ *
+ * The delay the chip holds is part of the profile it loads before probe,
+ * and a rate or phase request that failed after its writes reached the
+ * device leaves the cache describing something else. Decoding the five
+ * PRG_RST_DELAY bytes is the only way to say what the output is really
+ * doing. The registers carry an unsigned delay, so a request that was
+ * made as an advance reads back as the equivalent delay.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ *
+ * Return: 0 on success, <0 on error
+ */
+int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,
+ s32 *phase_ps)
+{
+ const struct sit9531x_chip_info *info = sitdev->info;
+ u8 bytes[5], page, base, slot, fine, i;
+ u64 coarse = 0, fvco, ps;
+ int rc;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ if (out_idx >= info->num_outputs)
+ return -EINVAL;
+
+ rc = sit9531x_get_fvco(sitdev, sitdev->out[out_idx].pll_idx, &fvco);
+ if (rc)
+ return rc == -ENODATA ? -ENODEV : rc;
+
+ slot = info->clkout_map[out_idx];
+ page = (slot > SIT9531X_PAGE_OUTSYS0_SLOT_MAX) ?
+ SIT9531X_PAGE_OUTSYS1 : SIT9531X_PAGE_OUTSYS0;
+ base = SIT9531X_OUT_PRG_DELAY_BASE +
+ SIT9531X_OUT_PRG_SLOT_STRIDE * (slot % 6);
+
+ for (i = 0; i < ARRAY_SIZE(bytes); i++) {
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG(page, base + i),
+ &bytes[i]);
+ if (rc)
+ return rc;
+ }
+
+ fine = (bytes[0] & SIT9531X_OUT_PRG_FINE_MASK) >>
+ SIT9531X_OUT_PRG_FINE_SHIFT;
+ coarse = (u64)(bytes[0] & SIT9531X_OUT_PRG_COARSE_HI_MASK) << 32;
+ coarse |= (u64)bytes[1] << 24;
+ coarse |= (u64)bytes[2] << 16;
+ coarse |= (u64)bytes[3] << 8;
+ coarse |= bytes[4];
+
+ ps = mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);
+ ps += (u64)fine * SIT9531X_OUT_PRG_FINE_STEP_PS;
+
+ *phase_ps = (s32)min_t(u64, ps, S32_MAX);
+
+ return 0;
+}
+
+int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,
+ u8 pll_idx, u64 frequency)
+{
+ u64 fvco, divo;
+ int rc, ret;
+
+ 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);
+ /*
+ * Step 4: NVM update + loop lock. Always run prg_commit() so the chip
+ * leaves the PRG_CMD state with the output loops re-locked, even when a
+ * write above failed; keep the first error to return. It also carries
+ * the required post-lock settling sleep.
+ */
+ ret = sit9531x_prg_commit(sitdev);
+ if (ret && !rc)
+ rc = ret;
+ if (rc)
+ return rc;
+
+ /*
+ * Step 5: flush the PLL's output phase so the new DIVO starts
+ * aligned instead of keeping the arbitrary phase the divider
+ * happened to be at.
+ */
+ /*
+ * The divider is committed by this point, so the part is already
+ * running at the new rate. A flush that fails leaves the output
+ * divider on its old phase, which is a realignment that did not
+ * happen rather than a rate that did not change -- and reporting a
+ * failure would be doubly wrong, because the core asks for the
+ * current rate first and would drop an identical retry.
+ */
+ 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);
+
+ /*
+ * The programmed reset delay counts VCO cycles against the output
+ * period in force when it was written, so a rate change silently
+ * re-times a previously requested phase adjust. Re-encode the
+ * cached picosecond request against the new rate.
+ *
+ * Keyed off whether a delay was ever programmed rather than off the
+ * cached value: quantization can leave a whole period in the
+ * registers, which is the same phase and caches as zero, and that
+ * still has to be re-timed when the period changes.
+ */
+ if (sitdev->out[out_idx].phase_armed) {
+ s32 phase_ps = sitdev->out[out_idx].phase_adj;
+ int ph_rc;
+
+ /*
+ * The rate is already programmed and latched at this point.
+ * Failing the request for a re-timing that did not take
+ * would report a frequency set that did not happen, and the
+ * core drops an identical retry because it asks the driver
+ * for the current rate first -- which is the new one. Say
+ * what went wrong and mark the delay for a read-back
+ * instead.
+ */
+ ph_rc = sit9531x_output_phase_adjust_set(sitdev, out_idx,
+ phase_ps);
+ if (ph_rc) {
+ sitdev->out[out_idx].phase_stale = true;
+ dev_warn(sitdev->dev,
+ "out%u: rate changed but the phase adjust was not re-timed (%d)\n",
+ out_idx, ph_rc);
+ }
+ }
+
+ return rc;
+}
+
+/*
+ * sit9531x_output_freq_get - read output clock frequency from hardware
+ * @out_idx: output index (0-N for this chip variant)
+ * @frequency: output frequency in Hz
+ *
+ * Reads the 34-bit DIVO divider back from the output system registers
+ * and computes the live output frequency as Fvco / DIVO. This stays
+ * correct even when the divider was reprogrammed behind the driver's
+ * back (e.g. by a direct-I2C userspace tool), where the cached value
+ * would be stale.
+ *
+ * The cached output state is refreshed with the computed value.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ *
+ * Return: 0 on success, -ENODEV when the output divider or VCO rate
+ * is not resolvable, <0 on register access error
+ */
+int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,
+ u64 *frequency)
+{
+ const struct sit9531x_chip_info *info = sitdev->info;
+ u8 slot, page, base_reg, pll_idx, v;
+ u64 fvco, divo = 0;
+ int rc, j;
+
+ 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)
+ return -ENODEV;
+
+ rc = sit9531x_get_fvco(sitdev, pll_idx, &fvco);
+ if (rc)
+ return rc == -ENODATA ? -ENODEV : rc;
+
+ 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];
+
+ 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;
+ }
+
+ if (!divo)
+ return -ENODEV;
+
+ *frequency = div64_u64(fvco, divo);
+ sitdev->out[out_idx].freq = *frequency;
+
+ return 0;
+}
+
+/*
+ * Phase adjust (PRG_RST_DELAY register-based).
+ *
+ * The chip exposes a per-output 34-bit coarse delay measured in VCO
+ * clock periods plus a 3-bit fine delay in fixed 30 ps steps. The
+ * five bytes PROG6..PROG2 hold the field across registers:
+ * base + 0 PROG6 [7:5] OPSTG_VCASC_BUMP (preserved via RMW)
+ * [4:2] PRG_RST_FINE_DELAY
+ * [1:0] PRG_RST_DELAY[33:32]
+ * base + 1 PROG5 PRG_RST_DELAY[31:24]
+ * base + 2 PROG4 PRG_RST_DELAY[23:16]
+ * base + 3 PROG3 PRG_RST_DELAY[15:8]
+ * base + 4 PROG2 PRG_RST_DELAY[7:0]
+ *
+ * Slots 0-5 live on Page 3, slots 6-11 on Page 4, with each slot's
+ * block at base = 0x15 + 16 * (slot % 6); the slot is the physical
+ * output position from clkout_map[], not the logical output index.
+ *
+ * The chip only supports unsigned positive delay. Requests are folded
+ * modulo one output period: positive delays wrap naturally and a negative
+ * phase adjustment (advance) is rendered as (T_out - |phase|).
+ */
+
+int sit9531x_output_phase_adjust_set(struct sit9531x_dev *sitdev,
+ u8 out_idx, s32 phase_ps)
+{
+ const struct sit9531x_chip_info *info = sitdev->info;
+ u64 abs_ps, fvco, coarse = 0, coarse_ps, t_out_ps;
+ s64 phase_norm_ps = 0;
+ u8 page, base, prog6_val, fine = 0;
+ u8 old_bytes[5], new_bytes[5], i;
+ u8 pll_idx, slot;
+ u64 freq;
+ int rc, ret, rb_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)
+ return -EINVAL;
+
+ freq = sitdev->out[out_idx].freq;
+ if (!freq) {
+ /*
+ * The cache is only seeded by a DT frequency list or an
+ * earlier get/set; a board without supported-frequencies-hz
+ * would otherwise get -EINVAL on every phase request forever.
+ * Read the effective rate back from the divider chain.
+ */
+ rc = sit9531x_output_freq_get(sitdev, out_idx, &freq);
+ if (rc)
+ return rc;
+ if (!freq)
+ return -EINVAL;
+ }
+
+ rc = sit9531x_get_fvco(sitdev, pll_idx, &fvco);
+ if (rc)
+ return rc == -ENODATA ? -ENODEV : rc;
+
+ t_out_ps = div64_u64(1000000000000ULL, freq);
+ if (!t_out_ps)
+ return -EINVAL;
+
+ /*
+ * Convert to unsigned absolute delay. Both signs are folded
+ * modulo one period: positive delays wrap naturally, negative
+ * delays are rendered as T_out - |phase|. abs() is safe here
+ * because the core rejects anything outside the advertised phase
+ * range, which is +/-1 ms. div64_u64_rem() rather than the %
+ * operator: a 64-bit modulo has no compiler helper on 32-bit
+ * targets and leaves the module with an undefined __umoddi3.
+ */
+ abs_ps = abs(phase_ps);
+ div64_u64_rem(abs_ps, t_out_ps, &abs_ps);
+ 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 rem_ps;
+
+ /*
+ * coarse_cycles = abs_ps * Fvco / 1e12 ps/s.
+ * mul_u64_u64_div_u64() avoids overflow when abs_ps approaches
+ * one second of 1 PPS wrap-around.
+ */
+ coarse = mul_u64_u64_div_u64(abs_ps, fvco, 1000000000000ULL);
+ if (coarse >= (1ULL << SIT9531X_OUT_PRG_COARSE_BITS))
+ return -ERANGE;
+
+ /*
+ * Fine delay = round((abs_ps - coarse * vco_period_ps) / 30 ps)
+ */
+ coarse_ps = mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);
+ rem_ps = (abs_ps > coarse_ps) ? (abs_ps - coarse_ps) : 0;
+ if (rem_ps) {
+ u64 steps;
+
+ steps = div64_u64(rem_ps +
+ SIT9531X_OUT_PRG_FINE_STEP_PS / 2,
+ SIT9531X_OUT_PRG_FINE_STEP_PS);
+ if (steps > SIT9531X_OUT_PRG_FINE_MAX)
+ steps = SIT9531X_OUT_PRG_FINE_MAX;
+ fine = (u8)steps;
+ }
+ }
+
+ /*
+ * Map logical output index to the chip's physical output slot.
+ * On SiT95317 the eight logical outputs land on chip slots
+ * {0, 3, 4, 5, 7, 8, 9, 11}; on SiT95316 the map is identity.
+ * Page/base must address the slot, not the logical index.
+ */
+ slot = info->clkout_map[out_idx];
+ page = (slot > SIT9531X_PAGE_OUTSYS0_SLOT_MAX) ?
+ SIT9531X_PAGE_OUTSYS1 : SIT9531X_PAGE_OUTSYS0;
+ base = SIT9531X_OUT_PRG_DELAY_BASE +
+ SIT9531X_OUT_PRG_SLOT_STRIDE * (slot % 6);
+
+ /*
+ * The PRG_RST_DELAY bytes live in the output system, so the writes
+ * only take effect when made inside the PRG_CMD programming state and
+ * committed to the NVM shadow, exactly like sit9531x_output_freq_set().
+ */
+ rc = sit9531x_prg_enter(sitdev);
+ if (rc)
+ return rc;
+
+ for (i = 0; i < ARRAY_SIZE(old_bytes); i++) {
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG(page, base + i),
+ &old_bytes[i]);
+ if (rc)
+ goto commit;
+ }
+
+ /* PROG6 RMW: preserve OPSTG_VCASC_BUMP in [7:5] */
+ prog6_val = old_bytes[0] & SIT9531X_OUT_PRG_OPSTG_MASK;
+ prog6_val |= (fine << SIT9531X_OUT_PRG_FINE_SHIFT) &
+ SIT9531X_OUT_PRG_FINE_MASK;
+ prog6_val |= (u8)((coarse >> 32) & SIT9531X_OUT_PRG_COARSE_HI_MASK);
+
+ new_bytes[0] = prog6_val;
+ new_bytes[1] = (u8)((coarse >> 24) & 0xFF);
+ new_bytes[2] = (u8)((coarse >> 16) & 0xFF);
+ new_bytes[3] = (u8)((coarse >> 8) & 0xFF);
+ new_bytes[4] = (u8)(coarse & 0xFF);
+
+ for (i = 0; i < ARRAY_SIZE(new_bytes); i++) {
+ rc = sit9531x_write_u8(sitdev,
+ SIT9531X_REG(page, base + i),
+ new_bytes[i]);
+ if (rc)
+ goto rollback;
+ }
+
+ goto commit;
+
+rollback:
+ rb_rc = 0;
+ for (i = 0; i < ARRAY_SIZE(old_bytes); i++) {
+ ret = sit9531x_write_u8(sitdev,
+ SIT9531X_REG(page, base + i),
+ old_bytes[i]);
+ if (ret && !rb_rc)
+ rb_rc = ret;
+ }
+ 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;
+ }
+
+commit:
+ /*
+ * Always leave the PRG_CMD state via prg_commit(), even on a
+ * mid-sequence write failure, so the output loops are re-locked rather
+ * than stranded unlocked; keep the first error.
+ */
+ ret = sit9531x_prg_commit(sitdev);
+ if (ret && !rc)
+ rc = ret;
+ if (rc)
+ return rc;
+
+ /*
+ * Restart the output divider phase so the freshly programmed delay is
+ * applied against a known edge instead of the divider's arbitrary
+ * running phase.
+ */
+ rc = sit9531x_output_phase_flush(sitdev, pll_idx);
+ if (rc)
+ return rc;
+
+ /*
+ * Cache what the registers realize, and only once every step has
+ * succeeded: the core drops a repeated request with the same value,
+ * so a cache updated by a failed call would make the retry a no-op.
+ *
+ * Quantizing to whole VCO cycles plus 30 ps steps can land a few
+ * picoseconds past the end of the period, which would wrap the
+ * subtraction below; one period is the most a delay can be.
+ */
+ coarse_ps = mul_u64_u64_div_u64(coarse, 1000000000000ULL, fvco);
+ abs_ps = coarse_ps + (u64)fine * SIT9531X_OUT_PRG_FINE_STEP_PS;
+ if (abs_ps > t_out_ps)
+ abs_ps = t_out_ps;
+ if (phase_norm_ps < 0)
+ sitdev->out[out_idx].phase_adj =
+ abs_ps ? -(s32)(t_out_ps - abs_ps) : 0;
+ else
+ /*
+ * The cache is an s32 because that is what the ABI carries.
+ * A delay is bounded by the output period, which on a slow
+ * output is wider than that, so bound the cast. The negative
+ * branch above needs no bound: what it stores is the advance
+ * that was asked for, and that came in as an s32.
+ */
+ sitdev->out[out_idx].phase_adj = (s32)min(abs_ps,
+ (u64)S32_MAX);
+
+ /*
+ * Record that a delay is programmed whatever it quantized to. A
+ * request that lands on a whole period caches as zero, and the rate
+ * change that follows still has to re-time what the registers hold.
+ */
+ sitdev->out[out_idx].phase_armed = true;
+
+ return 0;
+}
+
+/*
+ * sit9531x_clear_notifications - clear all notification registers
+ *
+ * Clears all write-1-to-clear notification registers:
+ * - PLL outer LOL notification (Page 0, reg 0x07)
+ * - PLL holdover freeze notification (Page 0, reg 0x0B)
+ * - PLL inner LOL notification (Page 0, reg 0x93)
+ * - Clock monitor XO/PLL notification (Page 0, reg 0x9E)
+ * - Clock input notifications (Page 6, regs 0x03/0x07/0x93/0x97)
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_clear_notifications(struct sit9531x_dev *sitdev)
+{
+ int rc;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ /* Page 0x00 W1C notification registers */
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTER_LOL_NOTIF, 0xFF);
+ if (rc)
+ return rc;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_HO_FREEZE_NOTIF, 0xFF);
+ if (rc)
+ return rc;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PLL_INNER_LOL_NOTIF, 0xFF);
+ if (rc)
+ return rc;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_CMON_NOTIF, 0xFF);
+ if (rc)
+ return rc;
+
+ /* Page 0x06 clock input monitor notifications */
+ rc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_P_NOTIF_01, 0xFF);
+ if (rc)
+ return rc;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_P_NOTIF_23, 0xFF);
+ if (rc)
+ return rc;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_N_NOTIF_01, 0xFF);
+ if (rc)
+ return rc;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_CLKMON_N_NOTIF_23, 0xFF);
+ if (rc)
+ return rc;
+
+ dev_dbg(sitdev->dev, "All notification registers cleared\n");
+ return 0;
+}
+
+/*
+ * INTSYNC configuration register values.
+ * These are written to the source PLL's EXT page to enable/disable
+ * inter-PLL synchronization (lock frequency PLL to phase PLL).
+ */
+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 },
+};
+
+int sit9531x_intsync_src_detect(struct sit9531x_dev *sitdev)
+{
+ s8 src = -1;
+ u8 global;
+ u8 pll, ext_page;
+ int rc, i;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL, &global);
+ if (rc)
+ return rc;
+
+ if (!(global & BIT(SIT9531X_INTSYNC_EN_BIT))) {
+ sitdev->intsync_src = -1;
+ return 0;
+ }
+
+ for (pll = 0; pll < SIT9531X_NUM_PLLS; pll++) {
+ ext_page = SIT9531X_PLL_EXT_PAGE(pll);
+
+ 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)
+ return rc;
+ if (val != intsync_config[i].en_val)
+ break;
+ }
+
+ if (i == ARRAY_SIZE(intsync_config)) {
+ /*
+ * Only one PLL can drive the net. If a second
+ * one matches, the registers are not describing
+ * a state this driver put the device in, so say
+ * so rather than pick silently.
+ */
+ if (src < 0)
+ src = pll;
+ else
+ dev_warn(sitdev->dev,
+ "PLL%c also matches the INTSYNC source pattern; keeping PLL%c\n",
+ 'A' + pll, 'A' + src);
+ }
+ }
+
+ sitdev->intsync_src = src;
+
+ return 0;
+}
+
+/*
+ * Close the debug window on a PLL's EXT page. The key register opens
+ * every debug register on that page while it holds the unlock value.
+ */
+static int sit9531x_intsync_debug_lock(struct sit9531x_dev *sitdev, u8 ext_page)
+{
+ return sit9531x_write_u8(sitdev,
+ SIT9531X_REG(ext_page, SIT9531X_PLL_REG_DEBUG),
+ SIT9531X_PLL_DEBUG_LOCK);
+}
+
+/*
+ * sit9531x_intsync_enable - enable inter-PLL synchronization
+ * @src_pll_idx: source (frequency) PLL index (0-3)
+ *
+ * Enables INTSYNC global bit, unlocks the source PLL's EXT page
+ * debug registers, writes configuration, and triggers a small
+ * update on the source PLL.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_intsync_enable(struct sit9531x_dev *sitdev, u8 src_pll_idx)
+{
+ u8 ext_page, val;
+ int rc, lock_rc, i;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ 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;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL,
+ val | BIT(SIT9531X_INTSYNC_EN_BIT));
+ if (rc)
+ return rc;
+
+ /* Small update on Page 0 */
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_GLOBAL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ usleep_range(1000, 2000);
+ if (rc)
+ goto relock_err;
+
+ /* Unlock debug on EXT page */
+ 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;
+ }
+
+ /* Small update on source PLL */
+ rc = sit9531x_write_pll_u8(sitdev, src_pll_idx,
+ SIT9531X_PLL_REG_SMALL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ if (rc)
+ goto relock_err;
+
+ rc = 0;
+ goto relock;
+
+relock_err:
+ sit9531x_intsync_debug_lock(sitdev, ext_page);
+ goto err_disable;
+
+relock:
+ /*
+ * Close the EXT page debug window the sequence opened. Nothing
+ * else writes the key back, so leaving it open would keep the block
+ * unlocked for as long as the device runs.
+ */
+ lock_rc = sit9531x_intsync_debug_lock(sitdev, ext_page);
+ if (lock_rc && !rc)
+ rc = lock_rc;
+
+ return rc;
+
+err_disable:
+ /*
+ * The global enable is already set at this point. The caller only
+ * records the source PLL when this function succeeds, so nothing
+ * else will ever clear the bit: undo it here rather than leave the
+ * net asserted with a half-written EXT page.
+ */
+ {
+ int rollback_rc;
+
+ rollback_rc = sit9531x_intsync_disable(sitdev, src_pll_idx);
+ if (rollback_rc)
+ dev_warn(sitdev->dev,
+ "INTSYNC rollback failed after enable error: %d (original %d)\n",
+ rollback_rc, rc);
+ }
+
+ return rc;
+}
+
+/*
+ * sit9531x_intsync_disable - disable inter-PLL synchronization
+ * @src_pll_idx: source (frequency) PLL index (0-3)
+ *
+ * Clears INTSYNC global bit, writes disable values to the source
+ * PLL's EXT page, and triggers a small update.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_intsync_disable(struct sit9531x_dev *sitdev, u8 src_pll_idx)
+{
+ u8 ext_page, val;
+ int rc, lock_rc, i;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ 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;
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL,
+ val & ~BIT(SIT9531X_INTSYNC_EN_BIT));
+ if (rc)
+ return rc;
+
+ /* Small update on Page 0 */
+ rc = sit9531x_write_u8(sitdev, SIT9531X_REG_GLOBAL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ usleep_range(1000, 2000);
+ if (rc)
+ return rc;
+
+ /* Unlock debug on EXT page */
+ rc = sit9531x_write_u8(sitdev,
+ SIT9531X_REG(ext_page,
+ SIT9531X_PLL_REG_DEBUG),
+ SIT9531X_PLL_DEBUG_UNLOCK);
+ if (rc)
+ goto relock;
+
+ 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;
+ }
+
+ /* Small update on source PLL */
+ rc = sit9531x_write_pll_u8(sitdev, src_pll_idx,
+ SIT9531X_PLL_REG_SMALL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ if (rc)
+ goto relock;
+
+ rc = 0;
+
+restore_global:
+ /*
+ * The global enable was cleared first, so a failure here leaves the
+ * EXT page still holding the enable pattern with nothing pointing
+ * at it: the source detector keys on the global bit, would report
+ * the net as unowned, and a retry of the disable would then
+ * short-circuit. Put the bit back so the state stays one the
+ * driver can describe and the request can be repeated.
+ */
+ if (!sit9531x_read_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL, &val))
+ sit9531x_write_u8(sitdev, SIT9531X_REG_INTSYNC_GLOBAL,
+ val | BIT(SIT9531X_INTSYNC_EN_BIT));
+
+relock:
+ /* Close the EXT page debug window the sequence opened. */
+ lock_rc = sit9531x_intsync_debug_lock(sitdev, ext_page);
+ if (lock_rc && !rc)
+ rc = lock_rc;
+
+ return rc;
+}
+
+/**
+ * sit9531x_chan_selected_ref_read - read a PLL's active reference now
+ * @sitdev: device pointer
+ * @pll_idx: PLL index (0-3)
+ * @ref: result, logical input index of the selected reference
+ *
+ * chan->selected_ref is refreshed by the monitor twice a second, which is
+ * close enough for reporting pin state but not for attributing a
+ * measurement: the device picks its own reference, so a sample taken now
+ * can belong to a pin the cache has not caught up with.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ *
+ * Return: 0 on success, <0 on error
+ */
+int sit9531x_chan_selected_ref_read(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 *ref)
+{
+ u8 activesel_reg, input_sel;
+ int rc;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ if (pll_idx >= SIT9531X_NUM_PLLS)
+ return -EINVAL;
+
+ 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;
+
+ *ref = sit9531x_hw_src_input(input_sel & SIT9531X_PRIO_NIBBLE_MASK);
+
+ return 0;
+}
+
+/*
+ * sit9531x_phase_offset_read - read phase difference via TDC
+ * @phase_ps: output phase difference in picoseconds
+ *
+ * Reads the Time-to-Digital Converter (TDC) signed 35-bit code from the
+ * PLL page registers, then converts to picoseconds using the VCO
+ * frequency: phase_diff = tdc_code / fvco.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+int sit9531x_phase_offset_read(struct sit9531x_dev *sitdev, u8 pll_idx,
+ s64 *phase_ps)
+{
+ u8 v, old_write_code, old_read_code;
+ bool have_old = false;
+ int rc, lock_rc, i;
+ u64 fvco, mag_ps;
+ s64 tdc_signed;
+ u64 tdc_raw;
+ bool sign;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ if (pll_idx >= SIT9531X_NUM_PLLS)
+ return -EINVAL;
+
+ /* Unlock the debug page so the TDC registers are accessible. */
+ rc = sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DEBUG,
+ SIT9531X_PLL_DEBUG_UNLOCK);
+ if (rc)
+ goto relock;
+
+ /*
+ * Remember the tap selection so it can be put back. The key
+ * register is re-locked below, but the mux is not part of the key:
+ * leaving it parked on the TDC with a slow sampling clock selected
+ * is a state change the caller did not ask for, and the next reader
+ * of a different tap would have to know to undo it.
+ */
+ if (!sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_WRITE_CODE,
+ &old_write_code) &&
+ !sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_READ_CODE,
+ &old_read_code))
+ have_old = true;
+
+ /*
+ * Select the debug clock for taps below 200 kHz, then point the
+ * readback at the TDC. Only the one bit is touched: writing the
+ * modifier register whole would clear the fields belonging to
+ * 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;
+
+ /*
+ * Latch a sample by reading the trigger register. A single
+ * read returns the previous latch, so read it three times as
+ * the documented phase-difference procedure does.
+ */
+ for (i = 0; i < SIT9531X_DBG_LATCH_READS; i++) {
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_TRIGGER, &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;
+
+ /*
+ * Apply sign. Per the register map the sign bit is active-high
+ * for a positive offset: bit set -> +code, bit clear -> -code.
+ */
+ tdc_signed = sign ? (s64)tdc_raw : -(s64)tdc_raw;
+
+ /*
+ * Get VCO frequency for conversion. -ENODATA means DIVN is not
+ * programmed (PLL unused on this board) -- skip silently rather
+ * than spamming the log on every poll cycle. It is passed up as
+ * itself rather than as -ENODEV, which the I2C layer produces for
+ * an adapter that has gone away: the caller turns the dormant-PLL
+ * case into a zero reading, and a bus failure must not take that
+ * path.
+ */
+ 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);
+ goto relock;
+ }
+
+ /*
+ * phase_diff (seconds) = tdc_code / fvco
+ * phase_diff (ps) = tdc_code * 1e12 / fvco
+ *
+ * mul_u64_u64_div_u64() keeps the exact Hz denominator; dividing
+ * by whole MHz instead would lose up to ~40 ppm of scale on a
+ * fractional-DIVN Fvco.
+ */
+ mag_ps = mul_u64_u64_div_u64(tdc_signed < 0 ? -tdc_signed : tdc_signed,
+ 1000000000000ULL, fvco);
+ *phase_ps = tdc_signed < 0 ? -(s64)mag_ps : (s64)mag_ps;
+
+ rc = 0;
+
+relock:
+ if (have_old) {
+ sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_READ_CODE,
+ old_read_code);
+ sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DBG_WRITE_CODE,
+ old_write_code);
+ }
+
+ /*
+ * Close the debug window again. The key register opens every debug
+ * register on this PLL while it holds the unlock value, and this read
+ * runs on every pin-get of a connected input, so leaving it open
+ * would mean normal monitoring permanently unlocks the block.
+ */
+ lock_rc = sit9531x_write_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_DEBUG,
+ SIT9531X_PLL_DEBUG_LOCK);
+ if (lock_rc && !rc)
+ rc = lock_rc;
+
+ return rc;
+}
+
+/*
+ * sit9531x_ref_state_fetch - read input reference status from hardware
+ * @index: logical input index
+ *
+ * Reads LOS and OOF status for the given input lane from the Page 0x06
+ * clock monitor registers. P and N lanes have separate register banks;
+ * each register carries two input pairs nibble-packed (even pair in
+ * bits [3:0], odd pair in [7:4]).
+ */
+static int sit9531x_ref_state_fetch(struct sit9531x_dev *sitdev, u8 index)
+{
+ unsigned int force_reg, state_reg;
+ u8 pair, force, state;
+ struct sit9531x_ref *ref;
+ int rc;
+
+ /*
+ * The XTAL/XO reference (index SIT9531X_MAX_INPUTS) is the on-chip
+ * oscillator that feeds every PLL. It cannot be routed or deselected,
+ * so its pin is modeled as permanently connected (see
+ * sit9531x_dpll_xo_pin_ops) and has no receiver to gate. Only the
+ * routable per-lane inputs (0..num_inputs-1) are polled here.
+ */
+ if (index >= SIT9531X_MAX_INPUTS)
+ return -EINVAL;
+
+ ref = &sitdev->ref[index];
+ pair = sit9531x_input_pair(index);
+
+ /*
+ * Whether the receiver is on. This has to come from the chip: it
+ * is the loaded configuration that decides, and without reading it
+ * back every input would look disabled until something called
+ * sit9531x_input_enable(). A lane counts as disabled only while
+ * the force bit overrides it to the off state; with the force bit
+ * clear it follows the configuration, which is the enabled case.
+ */
+ sit9531x_input_get_regs(sitdev, index, &force_reg, &state_reg);
+
+ rc = sit9531x_read_u8(sitdev, force_reg, &force);
+ if (rc)
+ return rc;
+ rc = sit9531x_read_u8(sitdev, state_reg, &state);
+ if (rc)
+ return rc;
+
+ ref->enabled = !((force & BIT(pair)) && !(state & BIT(pair)));
+
+ return 0;
+}
+
+/*
+ * sit9531x_input_mode_fetch - detect SE/DE configuration of an input pair
+ * @pair: input pair number (0-3)
+ *
+ * Reads CLKINx_INPUT_MODE and stores the detected signal mode on both
+ * lanes of the pair. A pair with neither SE lane enabled is running
+ * differential.
+ */
+static int sit9531x_input_mode_fetch(struct sit9531x_dev *sitdev, u8 pair)
+{
+ enum sit9531x_signal_mode sig_mode;
+ u8 mode;
+ int rc;
+
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_IN_MODE(pair), &mode);
+ if (rc)
+ return rc;
+
+ if (mode & (SIT9531X_IN_MODE_SE_P_EN | SIT9531X_IN_MODE_SE_N_EN))
+ sig_mode = SIT9531X_MODE_SE;
+ else
+ sig_mode = SIT9531X_MODE_DE;
+
+ sitdev->ref[pair * 2].sig_mode = sig_mode;
+ sitdev->ref[pair * 2 + 1].sig_mode = sig_mode;
+
+ dev_dbg(sitdev->dev, "CLKIN%u mode reg 0x%02x -> %s\n", pair, mode,
+ sig_mode == SIT9531X_MODE_DE ? "differential" : "single-ended");
+
+ return 0;
+}
+
+/*
+ * sit9531x_chan_state_fetch - read PLL channel status from hardware
+ *
+ * Reads lock status and mode from the PLL status register.
+ */
+/* Read the PLL active-state bit (PLL page reg 0x02 bit 0). */
+static int sit9531x_pll_is_active(struct sit9531x_dev *sitdev, u8 pll_idx,
+ bool *active)
+{
+ u8 v;
+ int rc;
+
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_ACTIVE, &v);
+ if (rc)
+ return rc;
+
+ *active = !!(v & SIT9531X_PLL_ACTIVE_BIT);
+
+ return 0;
+}
+
+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;
+ struct sit9531x_chan *chan = &sitdev->chan[pll_idx];
+ u8 srcs[SIT9531X_PRIO_MAX_SLOTS];
+ u8 pll_status_1;
+ bool active;
+ int rc;
+
+ /*
+ * Whether the PLL is running at all. The loss-of-lock bit read
+ * below is driven by the PLL itself, so on one the loaded
+ * configuration leaves unused it simply stays clear and would
+ * otherwise read as a lock.
+ */
+ rc = sit9531x_pll_is_active(sitdev, pll_idx, &active);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_STATUS, &status);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_OUTER_LOL_STATUS,
+ &outer_lol);
+ if (rc)
+ return rc;
+
+ /*
+ * Read the input source the PLL has currently selected as its
+ * active reference. This lives in the low nibble of the last
+ * register of the PLL's page-1 priority block (CLK_ACTIVESEL_PLL),
+ * not on the PLL page -- 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)
+ return rc;
+
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_HO_FREEZE_STATUS,
+ &ho_freeze);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx, SIT9531X_PLL_REG_STATUS_1,
+ &pll_status_1);
+ if (rc)
+ return rc;
+
+ /*
+ * Which sources this PLL may select. The table is configuration and
+ * changes only through the driver, but reading it back keeps the
+ * membership the pin state getters report tied to the hardware
+ * instead of to a value the driver maintains on the side.
+ */
+ rc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);
+ if (rc)
+ return rc;
+
+ sit9531x_prio_mask_build(sitdev, pll_idx, srcs,
+ SIT9531X_PRIO_MAX_SLOTS);
+
+ /* 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->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);
+
+ return 0;
+}
+
+/*
+ * sit9531x_out_state_fetch - read output status from hardware
+ *
+ * Reads the output PLL association from the PLL page output map
+ * registers into out->routed / out->pll_idx, and the current drive
+ * state from the Hi-Z force bits into out->enabled. The two are
+ * separate: routing decides whether the output gets a DPLL pin at all,
+ * while a muted but routed output keeps its pin and reports
+ * DPLL_PIN_STATE_DISCONNECTED until it is un-muted.
+ */
+static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index)
+{
+ struct sit9531x_out *out = &sitdev->out[index];
+ u8 map_lo, map_hi, slot;
+ int pll_idx;
+ bool muted;
+ int rc;
+
+ slot = sitdev->info->clkout_map[index];
+
+ rc = sit9531x_output_mode_fetch(sitdev, index);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_output_forced_hiz(sitdev, index, &muted);
+ if (rc)
+ return rc;
+
+ sitdev->out[index].state_stale = false;
+
+ /*
+ * DT board-config override: the per-PLL OUTPUT_ENABLE bitmaps
+ * (0x27/0x28) do not unambiguously express output->PLL routing on
+ * every config (overlaps, and some outputs routed outside that
+ * path). When the board supplies an explicit map, trust it.
+ */
+ if (sitdev->out_pll_map_valid) {
+ u8 m = sitdev->out_pll_map[index];
+
+ if (m < SIT9531X_NUM_PLLS) {
+ out->pll_idx = m;
+ out->routed = true;
+ out->enabled = !muted;
+ } else {
+ out->pll_idx = 0;
+ out->routed = false;
+ out->enabled = false;
+ }
+ return 0;
+ }
+
+ /*
+ * The OUT_MAP_LO/HI bitmaps are indexed by the physical slot the
+ * output occupies on the chip, not by the driver's logical output
+ * index (translated above via the chip-info clkout_map[]: identity
+ * on SiT95316, non-contiguous on SiT95317).
+ *
+ * Determine which PLL drives this output by checking each PLL's
+ * output map registers (0x27 = slots 8-11, 0x28 = slots 0-7).
+ */
+ for (pll_idx = 0; pll_idx < SIT9531X_NUM_PLLS; pll_idx++) {
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_OUT_MAP_LO, &map_lo);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_read_pll_u8(sitdev, pll_idx,
+ SIT9531X_PLL_REG_OUT_MAP_HI, &map_hi);
+ if (rc)
+ return rc;
+
+ if (slot < 8) {
+ if (map_lo & BIT(slot)) {
+ out->pll_idx = pll_idx;
+ out->routed = true;
+ out->enabled = !muted;
+ return 0;
+ }
+ } else {
+ if (map_hi & BIT(slot - 8)) {
+ out->pll_idx = pll_idx;
+ out->routed = true;
+ out->enabled = !muted;
+ return 0;
+ }
+ }
+ }
+
+ /* Output not mapped to any PLL */
+ out->pll_idx = 0;
+ out->routed = false;
+ out->enabled = false;
+
+ return 0;
+}
+
+/*
+ * sit9531x_ref_pll_mask_fetch - seed the input-to-PLL usage masks
+ *
+ * ref->pll_mask is the refcount the disconnect path uses to decide when
+ * an input receiver may be powered down: the physical input is only
+ * disabled once the last DPLL has released it. It therefore has to
+ * start out matching the hardware. Without this pass every mask starts
+ * at zero, and disconnecting an input from one DPLL drops the mask to
+ * zero and disables a receiver the other DPLLs are still locked to.
+ *
+ * An input is counted for a PLL when it appears in that PLL's Page-1
+ * priority table, which is exactly the condition the connect and
+ * disconnect callbacks maintain. Sources that are not physical inputs
+ * (OCXO, INTSYNC) and reserved codes are skipped.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+static int sit9531x_ref_pll_mask_fetch(struct sit9531x_dev *sitdev)
+{
+ u8 srcs[SIT9531X_PRIO_MAX_SLOTS];
+ u8 pll_idx, slot, index;
+ int rc;
+
+ for (pll_idx = 0; pll_idx < SIT9531X_NUM_PLLS; pll_idx++) {
+ rc = sit9531x_prio_table_read(sitdev, pll_idx, srcs);
+ if (rc)
+ return rc;
+
+ for (slot = 0; slot < SIT9531X_PRIO_MAX_SLOTS; slot++) {
+ index = sit9531x_hw_src_input(srcs[slot]);
+ if (index >= sitdev->info->num_inputs)
+ continue;
+
+ /*
+ * On a differentially configured pair only the P lane
+ * has a DPLL pin, so that is the lane the connect and
+ * disconnect callbacks account for. Fold an N-lane
+ * table entry onto its P lane, otherwise the count
+ * would land on a lane nothing ever releases. The
+ * signaling mode is already known here:
+ * sit9531x_input_mode_fetch() runs first.
+ */
+ if (sit9531x_input_is_n(index) &&
+ sitdev->ref[index].sig_mode == SIT9531X_MODE_DE)
+ index--;
+
+ sitdev->ref[index].pll_mask |= BIT(pll_idx);
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * sit9531x_dev_state_fetch - read all hardware state at startup
+ *
+ * Called once during probe to populate the initial state cache.
+ */
+static int sit9531x_dev_state_fetch(struct sit9531x_dev *sitdev)
+{
+ int rc;
+ u8 i;
+
+ /* 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);
+ if (rc) {
+ dev_err(sitdev->dev,
+ "Failed to fetch CLKIN%u mode: %d\n", i, rc);
+ return rc;
+ }
+ }
+
+ for (i = 0; i < sitdev->info->num_inputs; i++) {
+ rc = sit9531x_ref_state_fetch(sitdev, i);
+ if (rc) {
+ dev_err(sitdev->dev,
+ "Failed to fetch input %u state: %d\n", i, rc);
+ return rc;
+ }
+ }
+
+ /*
+ * The priority-table read walks the Page-1 registers, so it runs
+ * with multiop_lock held like every other multi-register sequence.
+ * Nothing can race with it here -- the DPLLs are not registered and
+ * the monitor is not running yet -- but the page handling stays
+ * serialized the same way as at runtime.
+ */
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_ref_pll_mask_fetch(sitdev);
+ mutex_unlock(&sitdev->multiop_lock);
+ if (rc) {
+ dev_err(sitdev->dev,
+ "Failed to fetch input priority tables: %d\n", rc);
+ 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++) {
+ s32 phase_ps;
+
+ rc = sit9531x_out_state_fetch(sitdev, i);
+ if (rc) {
+ dev_err(sitdev->dev,
+ "Failed to fetch output %u state: %d\n", i, rc);
+ return rc;
+ }
+
+ /*
+ * The delay registers are part of the profile the chip loads
+ * before probe, so an output can already carry one. Seeding
+ * the cache from the device is what lets a request of 0 ps
+ * clear it: the core drops a request equal to what the
+ * getter reports, and a cache that started at zero would
+ * make clearing a programmed delay impossible. An output
+ * the configuration does not route has no Fvco to decode
+ * against, which is not an error here.
+ */
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_output_phase_read(sitdev, i, &phase_ps);
+ mutex_unlock(&sitdev->multiop_lock);
+ if (!rc) {
+ sitdev->out[i].phase_adj = phase_ps;
+ sitdev->out[i].phase_armed = !!phase_ps;
+ } else if (rc != -ENODEV) {
+ dev_err(sitdev->dev,
+ "Failed to read output %u delay: %d\n",
+ i, rc);
+ return rc;
+ }
+ }
+
+ for (i = 0; i < SIT9531X_NUM_PLLS; i++) {
+ rc = sit9531x_chan_state_fetch(sitdev, i);
+ if (rc) {
+ dev_err(sitdev->dev,
+ "Failed to fetch PLL%c state: %d\n",
+ 'A' + i, rc);
+ return rc;
+ }
+ }
+
+ return 0;
+}
+
+static void sit9531x_dev_ref_states_update(struct sit9531x_dev *sitdev)
+{
+ 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);
+ }
+}
+
+/*
+ * sit9531x_ref_pll_mask_rebuild - re-derive the input receiver refcounts
+ *
+ * ref->pll_mask decides when an input receiver may be powered down, and
+ * the connect and disconnect paths maintain it by hand. A request that
+ * failed part way through leaves it describing a table the device does
+ * not hold, and nothing else corrected it: a later disconnect could then
+ * drop the count to zero and gate an input another PLL is still locked
+ * to. Re-derive every mask from the tables the poll has just read. No
+ * extra bus traffic -- sit9531x_chan_state_fetch() refreshed the masks
+ * this reads immediately before.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+static void sit9531x_ref_pll_mask_rebuild(struct sit9531x_dev *sitdev)
+{
+ u8 pll_idx, src, index;
+
+ for (index = 0; index < sitdev->info->num_inputs; index++)
+ sitdev->ref[index].pll_mask = 0;
+
+ for (pll_idx = 0; pll_idx < SIT9531X_NUM_PLLS; pll_idx++) {
+ u16 mask = sitdev->chan[pll_idx].prio_mask;
+
+ for (src = 0; src < SIT9531X_PRIO_NUM_SRC; src++) {
+ if (!(mask & BIT(src)))
+ continue;
+
+ index = sit9531x_hw_src_input(src);
+ if (index < sitdev->info->num_inputs)
+ sitdev->ref[index].pll_mask |= BIT(pll_idx);
+ }
+ }
+}
+
+static void sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)
+{
+ int i, rc;
+
+ for (i = 0; i < SIT9531X_NUM_PLLS; i++) {
+ rc = sit9531x_chan_state_fetch(sitdev, i);
+ if (rc)
+ dev_warn(sitdev->dev,
+ "Failed to get PLL%c state: %d\n",
+ 'A' + i, rc);
+ }
+
+ sit9531x_ref_pll_mask_rebuild(sitdev);
+}
+
+/*
+ * sit9531x_dev_periodic_work - periodic hardware state polling
+ * @work: kthread_work pointer
+ *
+ * Polls hardware state at SIT9531X_STATUS_POLL_MS intervals.
+ * Updates reference and channel states, then delegates change
+ * detection to sit9531x_dpll_changes_check() for each registered DPLL.
+ */
+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;
+ int rc;
+
+ /*
+ * Update the cached ref[]/chan[] arrays under multiop_lock so the
+ * fetches are serialized against the DPLL callbacks that read
+ * these fields and against the chip's page selector.
+ *
+ * The lock is then dropped before sit9531x_dpll_changes_check(),
+ * which calls dpll_pin_change_ntf() / dpll_device_change_ntf().
+ * Those notification helpers take DPLL-subsystem locks that are
+ * already held when our callbacks are invoked from netlink
+ * context, and nesting multiop_lock around them would invert the
+ * lock order. changes_check() reads the cache published above,
+ * which is already consistent.
+ */
+ mutex_lock(&sitdev->multiop_lock);
+ sit9531x_dev_ref_states_update(sitdev);
+ sit9531x_dev_chan_states_update(sitdev);
+ mutex_unlock(&sitdev->multiop_lock);
+
+ list_for_each_entry(sitdpll, &sitdev->dplls, list)
+ sit9531x_dpll_changes_check(sitdpll);
+
+ /*
+ * Acknowledge the chip's notification latches after the tick has
+ * read and acted on them. Without this, the W1C bits remain set
+ * and -- on boards that wire INTRB -- the line stays asserted,
+ * re-firing the threaded handler back to back. The helper writes
+ * W1C bits across page 0 and page 6 and must run under
+ * multiop_lock to serialize the page selector against userspace
+ * dpll ops. Failure is non-fatal: status was already consumed
+ * for this tick and the next tick re-processes whatever stayed
+ * latched.
+ */
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_clear_notifications(sitdev);
+ mutex_unlock(&sitdev->multiop_lock);
+ if (rc)
+ dev_warn_ratelimited(sitdev->dev,
+ "Failed to clear notifications: %d\n",
+ rc);
+
+ /* Run twice a second */
+ kthread_queue_delayed_work(sitdev->kworker, &sitdev->work,
+ msecs_to_jiffies(SIT9531X_STATUS_POLL_MS));
+}
+
+/*
+ * sit9531x_irq_thread_fn - threaded IRQ handler for the chip's INTRB line
+ *
+ * Triggered when the chip asserts INTRB (and only when DT wires up the
+ * client interrupt; absent property == handler never installed). The
+ * action mirrors a periodic-work tick: queue an immediate run so status
+ * registers are read and DPLL changes_check fires without waiting for
+ * the next poll deadline. Polling continues to run as a fallback.
+ */
+static irqreturn_t sit9531x_irq_thread_fn(int irq, void *data)
+{
+ struct sit9531x_dev *sitdev = data;
+ int rc;
+
+ /*
+ * Acknowledge the chip's notification latches from the threaded
+ * handler itself. With IRQF_ONESHOT the line is unmasked on
+ * return, so deferring the W1C clear to the async kworker would
+ * let a still-asserted INTRB re-fire immediately (interrupt storm).
+ * Clear here, then kick the poll worker to read state and run
+ * changes_check.
+ */
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_clear_notifications(sitdev);
+ mutex_unlock(&sitdev->multiop_lock);
+ if (rc) {
+ dev_warn_ratelimited(sitdev->dev,
+ "IRQ: failed to clear notifications: %d\n",
+ rc);
+ /*
+ * The latch was not acknowledged, so with IRQF_ONESHOT the
+ * still-asserted line re-enters this handler as soon as it
+ * returns. Returning IRQ_NONE leaves that to the spurious
+ * detector, which needs roughly 100000 interrupts and resets
+ * its count every tenth of a second -- unreachable when each
+ * pass costs an I2C timeout. Give up on the line instead:
+ * the periodic poll reads the same state without it, so the
+ * driver keeps working on a board whose INTRB cannot be
+ * acknowledged.
+ */
+ if (++sitdev->irq_ack_fails < SIT9531X_IRQ_ACK_TRIES)
+ return IRQ_NONE;
+
+ dev_err(sitdev->dev,
+ "IRQ %d disabled: notifications cannot be cleared, polling only\n",
+ irq);
+ disable_irq_nosync(irq);
+ return IRQ_NONE;
+ }
+
+ sitdev->irq_ack_fails = 0;
+
+ kthread_mod_delayed_work(sitdev->kworker, &sitdev->work, 0);
+ return IRQ_HANDLED;
+}
+
+/*
+ * sit9531x_dev_start - start normal operation
+ *
+ * Fetches initial hardware state, registers all DPLL devices and
+ * their pins, and starts the periodic monitoring thread.
+ */
+/*
+ * Report what the device loaded from its EEPROM, and warn if it does not
+ * look like a healthy load.
+ *
+ * A profile that failed to load leaves the part running something other
+ * than what the board was designed around -- dividers, output routing
+ * and priority tables all differ -- while every register still reads
+ * back a plausible value. Naming the profile and saying whether the
+ * load was clean turns that into something visible at startup instead of
+ * something inferred from measurements later.
+ *
+ * This only reports. Boards in this family may have their
+ * configuration pushed over I2C rather than held in an EEPROM, and there
+ * the CRC pair means nothing, so a mismatch is not grounds for refusing
+ * to drive the device.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+static void sit9531x_eeprom_state_report(struct sit9531x_dev *sitdev)
+{
+ u32 rec_crc = 0, cal_crc = 0, prof_id = 0;
+ u8 notif, v;
+ int rc, i;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ /* Profile id: three bytes, least significant first. */
+ for (i = 2; i >= 0; i--) {
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_PROFILE_ID + i, &v);
+ if (rc)
+ return;
+ prof_id = prof_id << 8 | v;
+ }
+
+ dev_info(sitdev->dev, "profile id %u\n", prof_id);
+
+ /* Both CRCs: four bytes, most significant first. */
+ for (i = 0; i < 4; i++) {
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_REC_CRC + i, &v);
+ if (rc)
+ return;
+ rec_crc = rec_crc << 8 | v;
+
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_CAL_CRC + i, &v);
+ if (rc)
+ return;
+ cal_crc = cal_crc << 8 | v;
+ }
+
+ rc = sit9531x_read_u8(sitdev, SIT9531X_REG_EEPROM_NOTIF, ¬if);
+ if (rc)
+ return;
+
+ /*
+ * A clean load leaves the read-done bit set and every defect bit
+ * clear. Both CRCs zero means no EEPROM read happened at all:
+ * boards in this family may take their configuration over I2C
+ * instead of an EEPROM, and there the CRC pair means nothing, so
+ * that case is not a mismatch worth warning about.
+ */
+ if (!rec_crc && !cal_crc)
+ dev_dbg(sitdev->dev,
+ "no EEPROM profile (configuration pushed over I2C)\n");
+ else if (rec_crc != cal_crc)
+ dev_warn(sitdev->dev,
+ "EEPROM CRC mismatch: stored %08x, computed %08x\n",
+ rec_crc, cal_crc);
+ else if (notif != SIT9531X_EEPROM_READ_DONE)
+ dev_warn(sitdev->dev,
+ "EEPROM read reported defects (notify %02x)\n",
+ notif);
+ else
+ dev_dbg(sitdev->dev, "EEPROM profile loaded, CRC %08x\n",
+ cal_crc);
+}
+
+/*
+ * Report which PLLs came up, and flag the one case that is a real
+ * inconsistency rather than a configuration choice.
+ *
+ * A PLL the loaded configuration leaves unused never reaches its active
+ * state, which is normal and not worth a warning. A PLL that has
+ * outputs routed to it and is still not active is different: something
+ * that is meant to be generating clocks is not running, and every value
+ * read from it -- lock state, phase, frequency offset -- describes a
+ * stopped loop. Say so once at startup rather than leaving it to be
+ * discovered through measurements that quietly read as zero.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+static void sit9531x_pll_states_report(struct sit9531x_dev *sitdev)
+{
+ unsigned int idx, i;
+ bool routed;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ for (i = 0; i < SIT9531X_NUM_PLLS; i++) {
+ if (sitdev->chan[i].active) {
+ dev_dbg(sitdev->dev, "PLL%c active\n", 'A' + i);
+ continue;
+ }
+
+ routed = false;
+ for (idx = 0; idx < sitdev->info->num_outputs; idx++) {
+ const struct sit9531x_out *out;
+
+ out = sit9531x_out_state_get(sitdev, idx);
+ if (out->routed && out->pll_idx == i) {
+ routed = true;
+ break;
+ }
+ }
+
+ if (routed)
+ dev_warn(sitdev->dev,
+ "PLL%c drives outputs but is not in its active state\n",
+ 'A' + i);
+ else
+ dev_dbg(sitdev->dev, "PLL%c unused by the loaded configuration\n",
+ 'A' + i);
+ }
+}
+
+int sit9531x_dev_start(struct sit9531x_dev *sitdev)
+{
+ struct sit9531x_dpll *sitdpll;
+ int rc;
+
+ /* Fetch device state */
+ 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);
+
+ list_for_each_entry(sitdpll, &sitdev->dplls, list) {
+ rc = sit9531x_dpll_register(sitdpll);
+ if (rc) {
+ dev_err_probe(sitdev->dev, rc,
+ "Failed to register DPLL%u\n",
+ sitdpll->id);
+ goto err_unregister;
+ }
+ }
+
+ kthread_queue_delayed_work(sitdev->kworker, &sitdev->work, 0);
+
+ return 0;
+
+err_unregister:
+ /*
+ * Unregister what did register. The caller frees the list on this
+ * path, so leaving a DPLL registered would hand the subsystem a
+ * pointer to freed memory.
+ */
+ list_for_each_entry_continue_reverse(sitdpll, &sitdev->dplls, list)
+ sit9531x_dpll_unregister(sitdpll);
+
+ return rc;
+}
+
+/*
+ * sit9531x_dev_stop - stop normal operation
+ *
+ * Cancels the monitoring thread and unregisters all DPLL devices
+ * and their pins.
+ */
+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);
+ }
+}
+
+static struct sit9531x_dpll_pin *
+sit9531x_dpll_pin_alloc(struct sit9531x_dpll *sitdpll,
+ enum dpll_pin_direction dir, u8 id)
+{
+ struct sit9531x_dpll_pin *pin;
+
+ pin = kzalloc_obj(*pin, GFP_KERNEL);
+ if (!pin)
+ return ERR_PTR(-ENOMEM);
+
+ pin->dpll = sitdpll;
+ pin->dir = dir;
+ pin->id = id;
+
+ return pin;
+}
+
+/*
+ * sit9531x_dpll_pin_register - register a DPLL pin with the subsystem
+ * @index: absolute pin index for clock_id namespace
+ *
+ * Gets pin properties from firmware, creates or gets a dpll_pin,
+ * and registers it with the parent DPLL device.
+ */
+static int sit9531x_dpll_pin_register(struct sit9531x_dpll_pin *pin,
+ u32 index)
+{
+ struct sit9531x_dpll *sitdpll = pin->dpll;
+ struct sit9531x_pin_props *props;
+ const struct dpll_pin_ops *ops;
+ int rc;
+
+ props = sit9531x_pin_props_get(sitdpll->dev, pin->dir, pin->id);
+ if (IS_ERR(props))
+ return PTR_ERR(props);
+
+ strscpy(pin->label, props->package_label, sizeof(pin->label));
+ pin->fwnode = fwnode_handle_get(props->fwnode);
+
+ pin->dpll_pin = dpll_pin_get(sitdpll->dev->clock_id, index,
+ THIS_MODULE, &props->dpll_props,
+ &pin->tracker);
+ if (IS_ERR(pin->dpll_pin)) {
+ rc = PTR_ERR(pin->dpll_pin);
+ goto err_pin_get;
+ }
+ dpll_pin_fwnode_set(pin->dpll_pin, props->fwnode);
+
+ ops = sit9531x_dpll_pin_ops_get(pin);
+
+ rc = dpll_pin_register(sitdpll->dpll_dev, pin->dpll_pin, ops, pin);
+ if (rc)
+ goto err_register;
+
+ sit9531x_pin_props_put(props);
+
+ return 0;
+
+err_register:
+ dpll_pin_put(pin->dpll_pin, &pin->tracker);
+err_pin_get:
+ /* dpll_pin_get() left an ERR_PTR here. */
+ pin->dpll_pin = NULL;
+ fwnode_handle_put(pin->fwnode);
+ pin->fwnode = NULL;
+ sit9531x_pin_props_put(props);
+
+ return rc;
+}
+
+static void sit9531x_dpll_pin_unregister(struct sit9531x_dpll_pin *pin)
+{
+ struct sit9531x_dpll *sitdpll = pin->dpll;
+ const struct dpll_pin_ops *ops;
+
+ ops = sit9531x_dpll_pin_ops_get(pin);
+
+ dpll_pin_unregister(sitdpll->dpll_dev, pin->dpll_pin, ops, pin);
+ dpll_pin_put(pin->dpll_pin, &pin->tracker);
+ pin->dpll_pin = NULL;
+
+ fwnode_handle_put(pin->fwnode);
+ pin->fwnode = NULL;
+}
+
+static void sit9531x_dpll_pins_unregister(struct sit9531x_dpll *sitdpll)
+{
+ struct sit9531x_dpll_pin *pin, *next;
+
+ list_for_each_entry_safe(pin, next, &sitdpll->pins, list) {
+ sit9531x_dpll_pin_unregister(pin);
+ list_del(&pin->list);
+ kfree(pin);
+ }
+}
+
+/*
+ * sit9531x_input_pin_is_registrable - check if an input pin is registrable
+ *
+ * Split out so input-model changes stay local to this helper.
+ *
+ * Return: true if the input pin should be registered, false otherwise
+ */
+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 differentially-configured pair is not a
+ * standalone input and is skipped (zl3073x model).
+ */
+ if (sit9531x_input_is_n(index) &&
+ sitdev->ref[index].sig_mode == SIT9531X_MODE_DE)
+ return false;
+
+ return true;
+}
+
+/*
+ * sit9531x_dpll_pin_is_registrable - check if a pin should be registered
+ * @dir: pin direction
+ * @index: pin hardware index
+ *
+ * For input pins: delegate to sit9531x_input_pin_is_registrable().
+ * For output pins: the pin is registrable if this DPLL is routed to it,
+ * whether or not it is currently driving.
+ *
+ * Return: true if pin should be registered, false otherwise
+ */
+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 (index == SIT9531X_MAX_INPUTS)
+ return true;
+ if (index == SIT9531X_INTSYNC_PIN_ID)
+ return true;
+
+ return sit9531x_input_pin_is_registrable(sitdev, index);
+ }
+
+ if (index == SIT9531X_INTSYNC_OUT_PIN_ID)
+ return true;
+
+ if (index >= sitdev->info->num_outputs)
+ return false;
+
+ return sitdev->out[index].pll_idx == sitdpll->id &&
+ sitdev->out[index].routed;
+}
+
+/*
+ * sit9531x_dpll_pins_register - register all registrable pins
+ *
+ * Enumerates all possible input and output pins, checks registrability,
+ * and registers each one. Input pins come first, then output pins,
+ * with input pins first, then output pins.
+ */
+static int sit9531x_dpll_pins_register(struct sit9531x_dpll *sitdpll)
+{
+ struct sit9531x_dpll_pin *pin;
+ enum dpll_pin_direction dir;
+ u8 id, index;
+ int rc;
+
+ for (index = 0; index < SIT9531X_NUM_PINS_TOTAL; index++) {
+ if (index < SIT9531X_NUM_INPUT_PINS) {
+ id = index;
+ dir = DPLL_PIN_DIRECTION_INPUT;
+ } else {
+ id = index - SIT9531X_NUM_INPUT_PINS;
+ dir = DPLL_PIN_DIRECTION_OUTPUT;
+ }
+
+ if (!sit9531x_dpll_pin_is_registrable(sitdpll, dir, id))
+ continue;
+
+ pin = sit9531x_dpll_pin_alloc(sitdpll, dir, id);
+ if (IS_ERR(pin)) {
+ rc = PTR_ERR(pin);
+ goto error;
+ }
+
+ rc = sit9531x_dpll_pin_register(pin, index);
+ if (rc) {
+ kfree(pin);
+ goto error;
+ }
+
+ list_add(&pin->list, &sitdpll->pins);
+ }
+
+ return 0;
+
+error:
+ sit9531x_dpll_pins_unregister(sitdpll);
+ return rc;
+}
+
+static int sit9531x_dpll_device_register(struct sit9531x_dpll *sitdpll)
+{
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ int rc;
+
+ sitdpll->ops = sit9531x_dpll_device_ops;
+
+ sitdpll->dpll_dev = dpll_device_get(sitdev->clock_id, sitdpll->id,
+ THIS_MODULE, &sitdpll->tracker);
+ if (IS_ERR(sitdpll->dpll_dev)) {
+ rc = PTR_ERR(sitdpll->dpll_dev);
+ sitdpll->dpll_dev = NULL;
+ return rc;
+ }
+
+ rc = dpll_device_register(sitdpll->dpll_dev,
+ sit9531x_prop_dpll_type_get(sitdev,
+ sitdpll->id),
+ &sitdpll->ops, sitdpll);
+ if (rc) {
+ dpll_device_put(sitdpll->dpll_dev, &sitdpll->tracker);
+ sitdpll->dpll_dev = NULL;
+ }
+
+ return rc;
+}
+
+static void sit9531x_dpll_device_unregister(struct sit9531x_dpll *sitdpll)
+{
+ dpll_device_unregister(sitdpll->dpll_dev, &sitdpll->ops, sitdpll);
+ dpll_device_put(sitdpll->dpll_dev, &sitdpll->tracker);
+ sitdpll->dpll_dev = NULL;
+}
+
+/*
+ * sit9531x_dpll_alloc - allocate a DPLL device structure
+ * @sitdev: parent device
+ * @ch: PLL channel number (0-3)
+ *
+ * Return: pointer to allocated DPLL on success, error pointer on error
+ */
+struct sit9531x_dpll *sit9531x_dpll_alloc(struct sit9531x_dev *sitdev, u8 ch)
+{
+ struct sit9531x_dpll *sitdpll;
+
+ sitdpll = kzalloc_obj(*sitdpll, GFP_KERNEL);
+ if (!sitdpll)
+ return ERR_PTR(-ENOMEM);
+
+ sitdpll->dev = sitdev;
+ sitdpll->id = ch;
+ sitdpll->lock_status = DPLL_LOCK_STATUS_UNLOCKED;
+ INIT_LIST_HEAD(&sitdpll->pins);
+
+ return sitdpll;
+}
+
+/*
+ * sit9531x_dpll_free - deallocate a DPLL device structure
+ * @sitdpll: DPLL to free
+ */
+void sit9531x_dpll_free(struct sit9531x_dpll *sitdpll)
+{
+ kfree(sitdpll);
+}
+
+/*
+ * sit9531x_dpll_register - register DPLL device and all its pins
+ *
+ * Registers the DPLL device with the subsystem and then registers
+ * all input and output pins that are connected to this PLL.
+ */
+int sit9531x_dpll_register(struct sit9531x_dpll *sitdpll)
+{
+ int rc;
+
+ rc = sit9531x_dpll_device_register(sitdpll);
+ if (rc)
+ return rc;
+
+ rc = sit9531x_dpll_pins_register(sitdpll);
+ if (rc) {
+ sit9531x_dpll_device_unregister(sitdpll);
+ return rc;
+ }
+
+ return 0;
+}
+
+/* sit9531x_dpll_unregister - unregister DPLL device and its pins */
+void sit9531x_dpll_unregister(struct sit9531x_dpll *sitdpll)
+{
+ sit9531x_dpll_pins_unregister(sitdpll);
+ sit9531x_dpll_device_unregister(sitdpll);
+}
+
+static void sit9531x_dpll_list_free(struct sit9531x_dev *sitdev)
+{
+ struct sit9531x_dpll *sitdpll, *next;
+
+ list_for_each_entry_safe(sitdpll, next, &sitdev->dplls, list) {
+ list_del(&sitdpll->list);
+ sit9531x_dpll_free(sitdpll);
+ }
+}
+
+/* Runs only once the device is fully started, see the caller. */
+static void sit9531x_dev_dpll_fini(void *ptr)
+{
+ struct sit9531x_dev *sitdev = ptr;
+
+ sit9531x_dev_stop(sitdev);
+ kthread_destroy_worker(sitdev->kworker);
+ sit9531x_dpll_list_free(sitdev);
+}
+
+static int sit9531x_devm_dpll_init(struct sit9531x_dev *sitdev)
+{
+ struct kthread_worker *kworker;
+ struct sit9531x_dpll *sitdpll;
+ unsigned int i;
+ int rc;
+
+ INIT_LIST_HEAD(&sitdev->dplls);
+ kthread_init_delayed_work(&sitdev->work, sit9531x_dev_periodic_work);
+
+ for (i = 0; i < SIT9531X_NUM_PLLS; i++) {
+ sitdpll = sit9531x_dpll_alloc(sitdev, i);
+ if (IS_ERR(sitdpll)) {
+ rc = dev_err_probe(sitdev->dev, PTR_ERR(sitdpll),
+ "Failed to alloc DPLL%u\n", i);
+ goto err_free_dplls;
+ }
+
+ list_add_tail(&sitdpll->list, &sitdev->dplls);
+ }
+
+ kworker = kthread_run_worker(0, "sit9531x-%s", dev_name(sitdev->dev));
+ if (IS_ERR(kworker)) {
+ rc = PTR_ERR(kworker);
+ goto err_free_dplls;
+ }
+ sitdev->kworker = kworker;
+
+ rc = sit9531x_dev_start(sitdev);
+ if (rc) {
+ rc = dev_err_probe(sitdev->dev, rc, "Failed to start device\n");
+ goto err_destroy_worker;
+ }
+
+ /*
+ * Only now is every field the cleanup touches valid, so this is the
+ * first point at which the action may be registered. On failure it
+ * runs the action itself, which is correct here and only here.
+ */
+ return devm_add_action_or_reset(sitdev->dev, sit9531x_dev_dpll_fini,
+ sitdev);
+
+err_destroy_worker:
+ kthread_destroy_worker(sitdev->kworker);
+err_free_dplls:
+ sit9531x_dpll_list_free(sitdev);
+
+ return rc;
+}
+
+/*
+ * sit9531x_read_variant_id - read chip variant ID byte from hardware
+ * @id: output variant ID byte
+ *
+ * Reads the single-byte variant identification register from Page 0
+ * reg 0x02 (95317 = 0x17, 95316 = 0x31). Reg 0x03 holds a separate
+ * revision byte and is intentionally not consumed here.
+ */
+static int sit9531x_read_variant_id(struct sit9531x_dev *sitdev, u8 *id)
+{
+ return sit9531x_read_u8(sitdev, SIT9531X_REG_VARIANT_ID, id);
+}
+
+static const struct sit9531x_chip_info *sit9531x_match_variant(u8 id)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(sit9531x_chip_ids); i++) {
+ if (sit9531x_chip_ids[i].id == id)
+ return &sit9531x_chip_ids[i];
+ }
+
+ return NULL;
+}
+
+/*
+ * sit9531x_derive_clock_id - build EUI-64 clock identifier
+ *
+ * Generates a deterministic 64-bit identifier from the SiTime OUI,
+ * the chip ID, the I2C bus number and the I2C address. The bus number
+ * disambiguates two same-variant parts at the same address on
+ * different adapters (or behind a mux), which the DPLL core would
+ * otherwise fold onto one set of objects; DT bus aliases keep the
+ * numbering, and with it the clock_id, stable across reboots.
+ *
+ * Return: 64-bit clock identifier
+ */
+static u64 sit9531x_derive_clock_id(struct sit9531x_dev *sitdev)
+{
+ u64 clkid;
+
+ clkid = SIT9531X_OUI << 24;
+ clkid |= (u64)(i2c_adapter_id(sitdev->client->adapter) & 0xff) << 16;
+ clkid |= (u64)sitdev->info->id << 8;
+ clkid |= (u64)sitdev->client->addr;
+
+ return clkid;
+}
+
+/*
+ * Does an Fvco fall in the band the given PLL runs in?
+ *
+ * The two bands are disjoint, and which one applies is fixed per PLL, so a
+ * single envelope from the bottom of the low band to the top of the high
+ * one would accept both the ~1 GHz gap between them and a rate belonging to
+ * the other PLL's band.
+ */
+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;
+}
+
+/*
+ * Board-config overrides for fixed efuse/blob routing the chip registers do
+ * not describe unambiguously. Absent properties leave pll_fvco[] zeroed
+ * (derive from DIVN) and out_pll_map_valid false (use the OUT_MAP registers).
+ */
+static void sit9531x_parse_board_config(struct sit9531x_dev *sitdev)
+{
+ u32 map[SIT9531X_MAX_OUTPUTS];
+ int n, i, rc;
+
+ if (device_property_present(sitdev->dev, "sitime,pll-fvco")) {
+ /*
+ * A fixed-count read rejects a short array but accepts a
+ * long one and drops the surplus, so the count is checked
+ * here: the property describes four PLLs and an array of
+ * any other length describes something else.
+ */
+ rc = device_property_count_u64(sitdev->dev,
+ "sitime,pll-fvco");
+ if (rc != SIT9531X_NUM_PLLS) {
+ dev_warn(sitdev->dev,
+ "sitime,pll-fvco needs %d entries, ignoring\n",
+ SIT9531X_NUM_PLLS);
+ memset(sitdev->pll_fvco, 0, sizeof(sitdev->pll_fvco));
+ goto out_map;
+ }
+
+ rc = device_property_read_u64_array(sitdev->dev,
+ "sitime,pll-fvco",
+ sitdev->pll_fvco,
+ SIT9531X_NUM_PLLS);
+ if (rc) {
+ dev_warn(sitdev->dev,
+ "invalid sitime,pll-fvco (%d), ignoring\n",
+ rc);
+ memset(sitdev->pll_fvco, 0, sizeof(sitdev->pll_fvco));
+ }
+
+ /*
+ * The override is used verbatim by the divider math, so an
+ * implausible value (units typo, wrong cell count worked
+ * around with zeros) must not silently misprogram DIVO.
+ * Anything outside both VCO bands is dropped with a warning
+ * rather than trusted.
+ */
+ for (i = 0; i < SIT9531X_NUM_PLLS; i++) {
+ u64 f = sitdev->pll_fvco[i];
+
+ if (f && !sit9531x_fvco_in_band(i, f)) {
+ dev_warn(sitdev->dev,
+ "PLL%c Fvco override %llu Hz is outside the band that PLL runs in, ignoring\n",
+ 'A' + i, f);
+ sitdev->pll_fvco[i] = 0;
+ }
+ }
+ }
+
+out_map:
+ if (!device_property_present(sitdev->dev, "sitime,output-pll-map"))
+ return;
+
+ /*
+ * Any 1..MAX_OUTPUTS length is accepted so the 8-output SiT95317 need
+ * not pad to 12; variant detection has not run yet and entries past
+ * the detected num_outputs are never indexed. Trailing entries of a
+ * short map must read as unmapped rather than 0 (== PLLA), which
+ * would mark unrouted outputs active in sit9531x_out_state_fetch().
+ */
+ memset(sitdev->out_pll_map, SIT9531X_OUT_PLL_UNMAPPED,
+ sizeof(sitdev->out_pll_map));
+
+ n = device_property_count_u32(sitdev->dev, "sitime,output-pll-map");
+ sitdev->out_pll_map_count = (n > 0) ? n : 0;
+ if (n <= 0 || n > SIT9531X_MAX_OUTPUTS ||
+ device_property_read_u32_array(sitdev->dev, "sitime,output-pll-map",
+ map, n)) {
+ dev_warn(sitdev->dev,
+ "invalid sitime,output-pll-map, ignoring\n");
+ return;
+ }
+
+ /*
+ * The binding allows only 0-3 and 255 per entry. A stray value
+ * would silently unroute an output (m >= SIT9531X_NUM_PLLS reads
+ * as unmapped in sit9531x_out_state_fetch()), so reject the whole
+ * property loudly instead.
+ */
+ for (i = 0; i < n; i++) {
+ if (map[i] >= SIT9531X_NUM_PLLS &&
+ map[i] != SIT9531X_OUT_PLL_UNMAPPED) {
+ dev_warn(sitdev->dev,
+ "sitime,output-pll-map entry %d is %u (must be 0-3 or 255), ignoring map\n",
+ i, map[i]);
+ return;
+ }
+ }
+
+ for (i = 0; i < n; i++)
+ sitdev->out_pll_map[i] = map[i];
+ sitdev->out_pll_map_valid = true;
+}
+
+int sit9531x_dev_probe(struct sit9531x_dev *sitdev)
+{
+ struct clk *xtal_clk;
+ u8 variant_id;
+ int rc;
+
+ /*
+ * Fvco = Fref * (DIVN + frac/2^32) with Fref = xtal_freq << doubler,
+ * so every freq_set and phase_adjust path divides by a rate derived
+ * from the XO feeding XIN/XO_CLK. The rate normally comes from a
+ * "clocks" phandle (clock-names = "xtal"). On platforms where the
+ * firmware does not expose the XO through the clock framework, fall
+ * back to a "clock-frequency" device property.
+ */
+ xtal_clk = devm_clk_get_optional_enabled(sitdev->dev, "xtal");
+ if (IS_ERR(xtal_clk))
+ return dev_err_probe(sitdev->dev, PTR_ERR(xtal_clk),
+ "Failed to get xtal clock\n");
+ sitdev->xtal_freq = clk_get_rate(xtal_clk);
+ if (!sitdev->xtal_freq) {
+ u32 freq;
+
+ if (!device_property_read_u32(sitdev->dev, "clock-frequency",
+ &freq))
+ sitdev->xtal_freq = freq;
+ }
+ if (!sitdev->xtal_freq)
+ return dev_err_probe(sitdev->dev, -EINVAL,
+ "no xtal rate: provide clocks=<&xo> + clock-names=\"xtal\", or a clock-frequency property\n");
+
+ /*
+ * Held deasserted, never pulsed: the chip configuration comes from
+ * efuse or an NVM blob applied before probe, and a reset would
+ * discard it. Must precede the first I2C access, as a board that
+ * powers up asserted keeps the chip unreachable until released.
+ */
+ sitdev->reset_gpio = devm_gpiod_get_optional(sitdev->dev, "reset",
+ GPIOD_OUT_LOW);
+ if (IS_ERR(sitdev->reset_gpio))
+ return dev_err_probe(sitdev->dev, PTR_ERR(sitdev->reset_gpio),
+ "Failed to request reset gpio\n");
+ if (sitdev->reset_gpio)
+ fsleep(10000); /* internal boot after release */
+
+ sit9531x_parse_board_config(sitdev);
+
+ rc = sit9531x_read_variant_id(sitdev, &variant_id);
+ if (rc)
+ return rc;
+
+ sitdev->info = sit9531x_match_variant(variant_id);
+ if (!sitdev->info)
+ return dev_err_probe(sitdev->dev, -ENODEV,
+ "Unknown variant ID: 0x%02x\n",
+ variant_id);
+
+ /*
+ * The map is parsed before the variant is known, so its length can
+ * only be checked against the part here. A map that stops short of
+ * the outputs this variant has leaves the rest reading as unmapped,
+ * which would drop real output pins; fall back to the routing the
+ * registers describe instead.
+ */
+ if (sitdev->out_pll_map_valid &&
+ sitdev->out_pll_map_count < sitdev->info->num_outputs) {
+ dev_warn(sitdev->dev,
+ "sitime,output-pll-map has %u of %u outputs, ignoring map\n",
+ sitdev->out_pll_map_count, sitdev->info->num_outputs);
+ sitdev->out_pll_map_valid = false;
+ }
+
+ sitdev->clock_id = sit9531x_derive_clock_id(sitdev);
+ sitdev->intsync_src = -1;
+
+ rc = devm_mutex_init(sitdev->dev, &sitdev->multiop_lock);
+ if (rc)
+ return dev_err_probe(sitdev->dev, rc,
+ "Failed to initialize mutex\n");
+
+ dev_info(sitdev->dev, "%s detected, %u inputs, %u outputs\n",
+ sitdev->info->name, sitdev->info->num_inputs,
+ sitdev->info->num_outputs);
+
+ /*
+ * Before the IRQ: the handler reaches sitdev->kworker through
+ * kthread_mod_delayed_work(), so the worker has to exist before an
+ * INTRB assertion can land.
+ */
+ rc = sit9531x_devm_dpll_init(sitdev);
+ if (rc)
+ return rc;
+
+ /* Absent "interrupts" leaves client->irq 0 and the poll in charge. */
+ sitdev->irq = sitdev->client ? sitdev->client->irq : 0;
+ if (sitdev->irq > 0) {
+ rc = devm_request_threaded_irq(sitdev->dev, sitdev->irq,
+ NULL, sit9531x_irq_thread_fn,
+ IRQF_ONESHOT,
+ dev_name(sitdev->dev), sitdev);
+ if (rc)
+ return dev_err_probe(sitdev->dev, rc,
+ "Failed to request IRQ %d\n",
+ sitdev->irq);
+ }
+
+ return 0;
+}
+
+static int sit9531x_i2c_probe(struct i2c_client *client)
+{
+ struct sit9531x_dev *sitdev;
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_i2c(client, &sit9531x_regmap_config);
+ if (IS_ERR(regmap))
+ return dev_err_probe(&client->dev, PTR_ERR(regmap),
+ "Failed to initialize regmap\n");
+
+ sitdev = devm_kzalloc(&client->dev, sizeof(*sitdev), GFP_KERNEL);
+ if (!sitdev)
+ return -ENOMEM;
+
+ sitdev->dev = &client->dev;
+ sitdev->client = client;
+ sitdev->regmap = regmap;
+ i2c_set_clientdata(client, sitdev);
+
+ return sit9531x_dev_probe(sitdev);
+}
+
+static const struct of_device_id sit9531x_of_match[] = {
+ { .compatible = "sitime,sit95316" },
+ { .compatible = "sitime,sit95317" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, sit9531x_of_match);
+
+/*
+ * The poll worker is not freezable and would keep issuing paged I2C
+ * transfers into a suspended adapter, where i2c_transfer() fails and a
+ * tick landing mid-suspend could tear a paged sequence between the
+ * page-selector write and the register access. Park the worker (and
+ * the IRQ that kicks it) across suspend and take a fresh sample on
+ * resume.
+ */
+static int sit9531x_suspend(struct device *dev)
+{
+ struct sit9531x_dev *sitdev = dev_get_drvdata(dev);
+
+ if (sitdev->irq > 0)
+ disable_irq(sitdev->irq);
+ kthread_cancel_delayed_work_sync(&sitdev->work);
+
+ return 0;
+}
+
+static int sit9531x_resume(struct device *dev)
+{
+ struct sit9531x_dev *sitdev = dev_get_drvdata(dev);
+
+ if (sitdev->irq > 0)
+ enable_irq(sitdev->irq);
+ kthread_queue_delayed_work(sitdev->kworker, &sitdev->work, 0);
+
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(sit9531x_pm_ops,
+ sit9531x_suspend, sit9531x_resume);
+
+static struct i2c_driver sit9531x_i2c_driver = {
+ .driver = {
+ .name = "sit9531x",
+ .of_match_table = sit9531x_of_match,
+ .pm = pm_sleep_ptr(&sit9531x_pm_ops),
+ },
+ .probe = sit9531x_i2c_probe,
+};
+module_i2c_driver(sit9531x_i2c_driver);
+
+MODULE_AUTHOR("Ali Rouhi <arouhi@sitime.com>");
+MODULE_AUTHOR("Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>");
+MODULE_DESCRIPTION("SiTime SiT9531x DPLL subsystem driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/dpll/sit9531x/core.h b/drivers/dpll/sit9531x/core.h
new file mode 100644
index 0000000000000..31a5f49c02531
--- /dev/null
+++ b/drivers/dpll/sit9531x/core.h
@@ -0,0 +1,429 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SiTime SiT9531x DPLL core driver
+ *
+ * Copyright (C) 2026 SiTime Corp.
+ * Author: Ali Rouhi <arouhi@sitime.com>
+ * Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
+ *
+ * Device structure, register access helpers, and core function
+ * declarations.
+ */
+
+#ifndef _SIT9531X_CORE_H
+#define _SIT9531X_CORE_H
+
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/kthread.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/types.h>
+
+#include "regs.h"
+
+#define SIT9531X_NUM_PLLS 4
+#define SIT9531X_MAX_INPUTS 8
+#define SIT9531X_NUM_INPUT_PAIRS (SIT9531X_MAX_INPUTS / 2)
+#define SIT9531X_MAX_OUTPUTS 12
+/* out_pll_map[] entry meaning "this output is not routed to any PLL" */
+#define SIT9531X_OUT_PLL_UNMAPPED 0xFF
+/*
+ * INTSYNC (the inter-PLL sync net) is modeled as two pins. The
+ * destination PLL that locks to INTSYNC sees an input pin
+ * (SIT9531X_INTSYNC_PIN_ID, in the input id namespace after the physical
+ * inputs and the xtal); the source PLL that drives INTSYNC sees an output
+ * pin (SIT9531X_INTSYNC_OUT_PIN_ID, appended after the physical outputs).
+ */
+#define SIT9531X_INTSYNC_PIN_ID (SIT9531X_MAX_INPUTS + 1)
+#define SIT9531X_INTSYNC_OUT_PIN_ID SIT9531X_MAX_OUTPUTS
+#define SIT9531X_STATUS_POLL_MS 500
+
+/* selected_ref value when the active source is not a registered input */
+#define SIT9531X_REF_INVALID 0xFF
+
+/* SiTime IEEE OUI for EUI-64 generation */
+#define SIT9531X_OUI 0x0090C2FFFEULL
+
+struct sit9531x_dpll;
+
+/*
+ * struct sit9531x_chip_info - chip variant identification
+ * @id: variant ID byte read from register
+ * @num_inputs: number of input clock pins
+ * @num_outputs: number of output clock pins
+ * @name: human-readable variant name
+ * @clkout_map: per-output slot mapping (output index -> physical slot)
+ */
+struct sit9531x_chip_info {
+ u8 id;
+ u8 num_inputs;
+ u8 num_outputs;
+ const char *name;
+ const u8 *clkout_map;
+};
+
+/*
+ * enum sit9531x_signal_mode - input signal electrical mode
+ * @SIT9531X_MODE_SE: single-ended
+ * @SIT9531X_MODE_DE: differential
+ */
+enum sit9531x_signal_mode {
+ SIT9531X_MODE_SE = 0,
+ SIT9531X_MODE_DE,
+};
+
+/*
+ * struct sit9531x_ref - input reference state
+ * @freq: configured frequency in Hz
+ * @enabled: the lane's receiver is on
+ * @pll_mask: bitmask of PLLs this input feeds (bit 0 = PLLA)
+ * @label: board label from DT or default
+ * @sig_mode: signal mode of the pair this lane belongs to
+ * (detected from CLKINx_INPUT_MODE at probe)
+ */
+struct sit9531x_ref {
+ u64 freq;
+ bool enabled;
+ u8 pll_mask;
+ const char *label;
+ enum sit9531x_signal_mode sig_mode;
+};
+
+/*
+ * struct sit9531x_out - output state
+ * @freq: rate the output is running at, in Hz
+ * @enabled: output is driving, i.e. not forced into Hi-Z
+ * @cmos: output is wired single-ended; the Hi-Z pair that
+ * speaks for it is the SE one, not the differential
+ * @state_stale: the cached mute state could not be confirmed against
+ * hardware and has to be read back before it is reported
+ * @routed: output is mapped to @pll_idx by the initial
+ * configuration; an unrouted output has no DPLL pin
+ * @pll_idx: PLL driving this output (0-3)
+ * @phase_stale: the programmed delay may differ from @phase_adj
+ * @phase_armed: a phase adjust has been programmed, so a rate
+ * change has to re-time it even when it quantized
+ * to zero
+ * @phase_adj: phase adjust the delay registers actually realize,
+ * i.e. the last request quantized to whole VCO cycles
+ * plus 30 ps fine steps, in the request's sign
+ * @label: board label from DT or default
+ */
+struct sit9531x_out {
+ u64 freq;
+ bool enabled;
+ bool cmos;
+ bool state_stale;
+ bool routed;
+ u8 pll_idx;
+ s32 phase_adj;
+ bool phase_armed;
+ bool phase_stale;
+ const char *label;
+};
+
+/*
+ * struct sit9531x_chan - per-PLL channel state
+ * @active: PLL has reached its active state; a PLL the loaded
+ * configuration leaves unused never does, and its
+ * loss-of-lock bit stays clear because nothing drives it
+ * @locked: PLL is locked (raw status register bit)
+ * @mode: 0 = sync (outer loop enabled), 1 = free-run
+ * @selected_ref: logical input index of the currently selected
+ * reference (the INTSYNC net maps to
+ * SIT9531X_INTSYNC_PIN_ID), or SIT9531X_REF_INVALID
+ * when the hardware source encoding is reserved
+ * @inner_lol: PLL inner loop loss-of-lock detected
+ * @ho_freeze: holdover freeze active
+ * @ho_valid: holdover memory acquired, i.e. the holdover window
+ * holds a valid estimate to fall back on
+ * @prio_srcs: cached copy of the priority table, one source code
+ * per slot; refreshed together with @prio_mask, so
+ * priority reads generate no register traffic
+ * @prio_last: slot each source occupies, plus one (0 = the source
+ * is not in the table); refreshed from the same scan
+ * as @prio_mask, so the two never disagree
+ * @prio_mask: bit per hardware source code present in this PLL's
+ * priority table, i.e. the sources it may select. Read
+ * back from the table by the periodic worker and
+ * refreshed by every table write, so it tracks the
+ * hardware rather than the driver's intent
+ */
+struct sit9531x_chan {
+ bool active;
+ bool locked;
+ u8 mode;
+ u8 selected_ref;
+ bool inner_lol;
+ bool ho_freeze;
+ bool ho_valid;
+ u8 prio_srcs[SIT9531X_PRIO_MAX_SLOTS];
+ u8 prio_last[SIT9531X_PRIO_NUM_SRC];
+ u16 prio_mask;
+};
+
+/*
+ * struct sit9531x_dev - SiT9531x device instance
+ * @info: detected chip variant info
+ * @dev: parent device
+ * @client: I2C client backing @regmap
+ * @regmap: paged register map of the device
+ * @dplls: DPLL devices registered for this chip
+ * @multiop_lock: mutex for multi-register atomic operations
+ * @ref: array of input reference states
+ * @out: array of output states
+ * @chan: array of per-PLL channel states
+ * @xtal_freq: crystal oscillator frequency in Hz
+ * @kworker: kthread worker for periodic polling
+ * @work: delayed work for periodic state checks
+ * @clock_id: IEEE 1588 EUI-64 clock identifier
+ * @reset_gpio: optional reset line (DT "reset-gpios"), NULL if absent
+ * @irq: optional INTRB IRQ number (from DT "interrupts" via the
+ * I2C client), 0 if no IRQ is wired
+ * @pll_fvco: optional per-PLL VCO in Hz from DT
+ * "sitime,pll-fvco"; 0 means derive from DIVN
+ * @out_pll_map: optional per-output source PLL (0-3, 0xff =
+ * unmapped) from DT "sitime,output-pll-map"
+ * @out_pll_map_valid: true when out_pll_map[] was populated from DT;
+ * false means use the chip's OUT_MAP registers
+ * @intsync_src: PLL index currently sourcing inter-PLL
+ * synchronization (INTSYNC), or -1 when disabled
+ */
+struct sit9531x_dev {
+ struct device *dev;
+ struct i2c_client *client;
+ struct regmap *regmap;
+ const struct sit9531x_chip_info *info;
+ /* Serializes multi-step register sequences */
+ struct mutex multiop_lock;
+
+ /* Hardware state */
+ u8 irq_ack_fails;
+ 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];
+ u32 xtal_freq;
+
+ /* DPLL channels */
+ struct list_head dplls;
+
+ /* Monitor */
+ struct kthread_worker *kworker;
+ struct kthread_delayed_work work;
+
+ /* Device identity */
+ u64 clock_id;
+
+ /* Optional DT-described GPIO / IRQ lines */
+ struct gpio_desc *reset_gpio;
+ int irq;
+
+ /* Optional DT board-config overrides */
+ u64 pll_fvco[SIT9531X_NUM_PLLS];
+ u8 out_pll_map[SIT9531X_MAX_OUTPUTS];
+ bool out_pll_map_valid;
+ u8 out_pll_map_count;
+
+ /* Inter-PLL synchronization state */
+ s8 intsync_src;
+
+};
+
+extern const struct regmap_config sit9531x_regmap_config;
+
+/* ---- Core lifecycle ---- */
+int sit9531x_dev_probe(struct sit9531x_dev *sitdev);
+int sit9531x_dev_start(struct sit9531x_dev *sitdev);
+void sit9531x_dev_stop(struct sit9531x_dev *sitdev);
+
+/* ---- Register access ---- */
+int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
+ u8 *val);
+int sit9531x_write_u8(struct sit9531x_dev *sitdev, unsigned int reg,
+ u8 val);
+int sit9531x_read_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 offset, u8 *val);
+int sit9531x_write_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 offset, u8 val);
+int sit9531x_update_pll_u8(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 offset, u8 mask, u8 val);
+
+/* ---- Input enable/disable ---- */
+int sit9531x_input_disable(struct sit9531x_dev *sitdev, u8 index);
+int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index);
+
+/* ---- Input priority ---- */
+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,
+ u8 input_idx);
+
+/* ---- Output enable/disable (Hi-Z control) ---- */
+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);
+
+/* ---- Output frequency ---- */
+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);
+
+/* ---- Output phase adjust (PRG_RST_DELAY register-based) ---- */
+int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,
+ s32 *phase_ps);
+int sit9531x_output_phase_adjust_set(struct sit9531x_dev *sitdev,
+ u8 out_idx, s32 phase_ps);
+
+/* ---- Notification clear ---- */
+int sit9531x_clear_notifications(struct sit9531x_dev *sitdev);
+
+/* ---- INTSYNC (inter-PLL synchronization) ---- */
+int sit9531x_intsync_enable(struct sit9531x_dev *sitdev, u8 src_pll_idx);
+int sit9531x_intsync_disable(struct sit9531x_dev *sitdev, u8 src_pll_idx);
+int sit9531x_intsync_src_detect(struct sit9531x_dev *sitdev);
+
+/* ---- Phase offset (TDC readback) ---- */
+int sit9531x_pll_ffo_ppt(struct sit9531x_dev *sitdev, u8 pll_idx, s64 *ffo);
+int sit9531x_chan_selected_ref_read(struct sit9531x_dev *sitdev, u8 pll_idx,
+ u8 *ref);
+int sit9531x_phase_offset_read(struct sit9531x_dev *sitdev, u8 pll_idx,
+ s64 *phase_ps);
+
+/* ---- State helpers ---- */
+
+/*
+ * sit9531x_pll_page - get register page for PLL index
+ * @pll_idx: PLL index (0 = PLLA, 3 = PLLD)
+ */
+static inline u8 sit9531x_pll_page(u8 pll_idx)
+{
+ return SIT9531X_PAGE_PLLA + pll_idx;
+}
+
+/*
+ * Logical input pins are interleaved: even index = P lane, odd
+ * index = N lane of pair index/2 (IN0P, IN0N, IN1P, IN1N, ...).
+ * Index SIT9531X_MAX_INPUTS is the XO input.
+ */
+
+/*
+ * sit9531x_input_pair - get input pair number for a logical input index
+ * @index: logical input pin index
+ */
+static inline u8 sit9531x_input_pair(u8 index)
+{
+ return index >> 1;
+}
+
+/*
+ * sit9531x_input_is_n - check if a logical input index is an N lane
+ * @index: logical input pin index
+ */
+static inline bool sit9531x_input_is_n(u8 index)
+{
+ return index & 1;
+}
+
+/*
+ * sit9531x_input_hw_src - translate logical input index to source encoding
+ * @index: logical input pin index
+ *
+ * The priority table and CLK_ACTIVESEL registers use a non-contiguous
+ * source encoding: 0-3 = CLK0P..CLK3P, 5 = OCXO, 6 = INTSYNC,
+ * 7-10 = CLK0N..CLK3N.
+ */
+static inline u8 sit9531x_input_hw_src(u8 index)
+{
+ if (index == SIT9531X_MAX_INPUTS)
+ return SIT9531X_PRIO_SRC_OCXO;
+ if (index == SIT9531X_INTSYNC_PIN_ID)
+ return SIT9531X_PRIO_SRC_INTSYNC;
+ if (sit9531x_input_is_n(index))
+ return SIT9531X_PRIO_SRC_N_BASE + sit9531x_input_pair(index);
+ return sit9531x_input_pair(index);
+}
+
+/*
+ * sit9531x_hw_src_input - translate source encoding to logical input index
+ * @src: 4-bit hardware source encoding
+ *
+ * Return: logical input index (INTSYNC maps to SIT9531X_INTSYNC_PIN_ID),
+ * or SIT9531X_REF_INVALID if @src is a reserved value
+ */
+static inline u8 sit9531x_hw_src_input(u8 src)
+{
+ if (src < SIT9531X_NUM_INPUT_PAIRS)
+ return src * 2;
+ if (src == SIT9531X_PRIO_SRC_OCXO)
+ return SIT9531X_MAX_INPUTS;
+ if (src == SIT9531X_PRIO_SRC_INTSYNC)
+ return SIT9531X_INTSYNC_PIN_ID;
+ if (src >= SIT9531X_PRIO_SRC_N_BASE &&
+ src < SIT9531X_PRIO_SRC_N_BASE + SIT9531X_NUM_INPUT_PAIRS)
+ return (src - SIT9531X_PRIO_SRC_N_BASE) * 2 + 1;
+ return SIT9531X_REF_INVALID;
+}
+
+/*
+ * sit9531x_prio_src_usable - does a priority slot name a reference?
+ * @src: 4-bit hardware source encoding held in a table slot
+ *
+ * Codes 4 and 11 address a fifth input pair this part does not have, and
+ * a value outside the encoding is not a source either, so a slot holding
+ * one of them names nothing the device can select. Canonicalizing an N
+ * lane to its pair first would not change the answer -- both lanes are
+ * references -- so this needs no device state.
+ *
+ * Return: true when the code resolves to a reference the device can use
+ */
+static inline bool sit9531x_prio_src_usable(u8 src)
+{
+ return sit9531x_hw_src_input(src) != SIT9531X_REF_INVALID;
+}
+
+/*
+ * sit9531x_ref_state_get - get reference state by index
+ * @index: logical input index
+ *
+ * Return: pointer to the cached input reference state
+ */
+static inline const struct sit9531x_ref *
+sit9531x_ref_state_get(const struct sit9531x_dev *sitdev, u8 index)
+{
+ return &sitdev->ref[index];
+}
+
+/*
+ * sit9531x_out_state_get - get output state by index
+ * @index: logical output index
+ *
+ * Return: pointer to the cached output state
+ */
+static inline const struct sit9531x_out *
+sit9531x_out_state_get(const struct sit9531x_dev *sitdev, u8 index)
+{
+ return &sitdev->out[index];
+}
+
+/*
+ * sit9531x_chan_state_get - get channel state by PLL index
+ *
+ * Return: pointer to the cached per-PLL channel state
+ */
+static inline const struct sit9531x_chan *
+sit9531x_chan_state_get(const struct sit9531x_dev *sitdev, u8 pll_idx)
+{
+ return &sitdev->chan[pll_idx];
+}
+
+#endif /* _SIT9531X_CORE_H */
diff --git a/drivers/dpll/sit9531x/dpll.c b/drivers/dpll/sit9531x/dpll.c
new file mode 100644
index 0000000000000..856c9bdf33d45
--- /dev/null
+++ b/drivers/dpll/sit9531x/dpll.c
@@ -0,0 +1,1445 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SiTime SiT9531x DPLL subsystem callbacks and registration
+ *
+ * Copyright (C) 2026 SiTime Corp.
+ * Author: Ali Rouhi <arouhi@sitime.com>
+ * Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
+ *
+ * DPLL device ops, pin ops (separate input/output), pin registration,
+ * and periodic change detection.
+ */
+
+#include <linux/dpll.h>
+#include <linux/err.h>
+#include <linux/kthread.h>
+#include <linux/list.h>
+#include <linux/netlink.h>
+#include <linux/slab.h>
+
+#include "core.h"
+#include "dpll.h"
+#include "prop.h"
+#include "regs.h"
+
+static bool sit9531x_dpll_is_input_pin(const struct sit9531x_dpll_pin *pin)
+{
+ return pin->dir == DPLL_PIN_DIRECTION_INPUT;
+}
+
+static bool
+sit9531x_dpll_is_intsync_pin(const struct sit9531x_dpll_pin *pin)
+{
+ return sit9531x_dpll_is_input_pin(pin) &&
+ pin->id == SIT9531X_INTSYNC_PIN_ID;
+}
+
+static bool
+sit9531x_dpll_is_intsync_src_pin(const struct sit9531x_dpll_pin *pin)
+{
+ return !sit9531x_dpll_is_input_pin(pin) &&
+ pin->id == SIT9531X_INTSYNC_OUT_PIN_ID;
+}
+
+static bool
+sit9531x_dpll_is_xo_pin(const struct sit9531x_dpll_pin *pin)
+{
+ return sit9531x_dpll_is_input_pin(pin) &&
+ pin->id == SIT9531X_MAX_INPUTS;
+}
+
+/*
+ * The cached state this reports comes from the outer loss-of-lock byte
+ * (page 0, reg 0x06), the PLL mode bit (PLL page, reg 0x31), inner LOL
+ * (reg 0x92), the holdover freeze byte (reg 0x0A) and the per-PLL
+ * holdover-valid bit (PLL page, reg 0x06).
+ */
+static int
+sit9531x_dpll_lock_status_get(const struct dpll_device *dpll, void *dpll_priv,
+ enum dpll_lock_status *status,
+ enum dpll_lock_status_error *status_error,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ const struct sit9531x_chan *chan;
+
+ if (status_error)
+ *status_error = DPLL_LOCK_STATUS_ERROR_NONE;
+
+ chan = sit9531x_chan_state_get(sitdev, sitdpll->id);
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ if (!chan->active) {
+ /*
+ * A PLL the loaded configuration leaves unused never reaches
+ * its active state. Nothing drives its loss-of-lock bit, so
+ * without this it would report a lock it does not have.
+ */
+ *status = DPLL_LOCK_STATUS_UNLOCKED;
+ } else if (chan->mode) {
+ /*
+ * Free-run: the outer loop is disabled, so the PLL tracks no
+ * reference at all and its loss-of-lock bit means nothing.
+ * That is what UNLOCKED describes -- "not yet locked to any
+ * valid input (or was forced by user)".
+ */
+ *status = DPLL_LOCK_STATUS_UNLOCKED;
+ } else if (chan->locked) {
+ /*
+ * HO_ACQ is locked *and* holdover memory acquired, so it needs
+ * the holdover-valid bit rather than following from the lock.
+ */
+ if (chan->ho_valid)
+ *status = DPLL_LOCK_STATUS_LOCKED_HO_ACQ;
+ else
+ *status = DPLL_LOCK_STATUS_LOCKED;
+ } else if (chan->ho_freeze) {
+ *status = DPLL_LOCK_STATUS_HOLDOVER;
+ } else {
+ *status = DPLL_LOCK_STATUS_UNLOCKED;
+ }
+
+ /* Report inner LOL as an error condition */
+ if (status_error && chan->inner_lol)
+ *status_error = DPLL_LOCK_STATUS_ERROR_UNDEFINED;
+
+ mutex_unlock(&sitdev->multiop_lock);
+
+ return 0;
+}
+
+/*
+ * Mode
+ * ====
+ * enum dpll_mode differentiates how a DPLL selects an input: AUTOMATIC
+ * has the device pick the highest-priority one, MANUAL has userspace
+ * request one. The device only implements the former through this
+ * driver, so AUTOMATIC is the only mode advertised.
+ *
+ * Free-run -- the outer loop disabled through PLL page reg 0x31[5] -- is
+ * not a mode in those terms, because no input is selected either way. It
+ * is reported through lock status instead, and reached through the
+ * chip-specific tool rather than over netlink.
+ *
+ * The device could implement real MANUAL: MISCINNER_PLL (PLL page reg
+ * 0x18) bit 5 switches a PLL from priority-based to manual active select,
+ * and GPIO_INPUT_FUNC_CTRL5..8 (page 0, regs 0xE8-0xEB) bit 4 makes the
+ * choice come from the register's own low nibble instead of the GPIO
+ * pins, which pins one reference while the loop keeps running. Wiring
+ * that up would let .state_on_dpll_set() accept CONNECTED; it needs bench
+ * validation first, and reg 0x18 carries GUI-generated configuration in
+ * its other bits, so it is left out until then. Advertising MANUAL and
+ * then refusing the one request MANUAL exists for is the worse of the two
+ * incomplete answers, and after merge it would be ABI.
+ */
+static int
+sit9531x_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,
+ enum dpll_mode *mode, struct netlink_ext_ack *extack)
+{
+ *mode = DPLL_MODE_AUTOMATIC;
+
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_mode_set - put the PLL in automatic selection mode
+ *
+ * Clears the outer loop disable bit (PLL page reg 0x31[5]) and triggers a
+ * small update via reg 0x0F, so a PLL left free-running by the loaded
+ * configuration or by the chip-specific tool returns to selecting its
+ * reference from the priority table. Any other mode is refused.
+ */
+static int
+sit9531x_dpll_mode_set(const struct dpll_device *dpll, void *dpll_priv,
+ enum dpll_mode mode, struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ int rc, restore_rc;
+ u8 status;
+
+ if (mode != DPLL_MODE_AUTOMATIC) {
+ NL_SET_ERR_MSG(extack,
+ "Device selects its reference by priority; only automatic mode is supported");
+ return -EOPNOTSUPP;
+ }
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ /*
+ * Read before writing. Automatic is the only mode this driver
+ * advertises, so userspace setting it again is a no-op the device
+ * must not feel: without this, a redundant set followed by one
+ * failed latch would restore an outer-loop disable the PLL never
+ * had and put a running loop into free-run.
+ */
+ rc = sit9531x_read_pll_u8(sitdev, sitdpll->id,
+ SIT9531X_PLL_REG_STATUS, &status);
+ if (rc) {
+ NL_SET_ERR_MSG(extack, "Failed to read PLL mode register");
+ goto unlock;
+ }
+ if (!(status & SIT9531X_PLL_STATUS_OUTER_DIS)) {
+ sitdev->chan[sitdpll->id].mode = 0;
+ goto unlock;
+ }
+
+ rc = sit9531x_update_pll_u8(sitdev, sitdpll->id,
+ SIT9531X_PLL_REG_STATUS,
+ SIT9531X_PLL_STATUS_OUTER_DIS, 0);
+ if (rc) {
+ NL_SET_ERR_MSG(extack, "Failed to write PLL mode register");
+ goto unlock;
+ }
+
+ /* Trigger small update to apply without full NVM cycle */
+ rc = sit9531x_write_pll_u8(sitdev, sitdpll->id,
+ SIT9531X_PLL_REG_SMALL_UPDATE,
+ SIT9531X_SMALL_UPDATE_CMD);
+ if (rc) {
+ u8 dis = SIT9531X_PLL_STATUS_OUTER_DIS;
+
+ /*
+ * The cleared disable bit was never latched. Put it back so
+ * the register does not read "outer loop enabled" for a loop
+ * that is still free-running, which the poll would then hand
+ * to the lock-status getter as a live mode.
+ */
+ restore_rc = sit9531x_update_pll_u8(sitdev, sitdpll->id,
+ SIT9531X_PLL_REG_STATUS,
+ dis, dis);
+ if (restore_rc)
+ dev_warn(sitdev->dev,
+ "PLL%c outer loop left enabled without a latch: %d\n",
+ 'A' + sitdpll->id, restore_rc);
+ NL_SET_ERR_MSG(extack, "Failed to trigger small update");
+ goto unlock;
+ }
+
+ /*
+ * Keep the cached mode in step with the register. The periodic
+ * monitor refreshes it too, but the pin state getters and lock status
+ * read this cache and would otherwise keep reporting free-run until
+ * the next poll.
+ */
+ sitdev->chan[sitdpll->id].mode = 0;
+
+unlock:
+ mutex_unlock(&sitdev->multiop_lock);
+
+ return rc;
+}
+
+static int
+sit9531x_dpll_supported_modes_get(const struct dpll_device *dpll,
+ void *dpll_priv, unsigned long *modes,
+ struct netlink_ext_ack *extack)
+{
+ __set_bit(DPLL_MODE_AUTOMATIC, modes);
+
+ return 0;
+}
+
+const struct dpll_device_ops sit9531x_dpll_device_ops = {
+ .lock_status_get = sit9531x_dpll_lock_status_get,
+ .mode_get = sit9531x_dpll_mode_get,
+ .mode_set = sit9531x_dpll_mode_set,
+ .supported_modes_get = sit9531x_dpll_supported_modes_get,
+ /* temp_get not available -- SiT9531x has no on-die temp sensor */
+};
+
+/*
+ * Pin-state contract
+ * ==================
+ * The five pin ops tables below fall into three roles, and only the first
+ * has a selection state machine. Each state_on_dpll callback implements
+ * the rules for its role and nothing else, so the tables cannot drift
+ * apart the way five independent encodings of this did.
+ *
+ * SELECTION role -- physical input pins, INTSYNC destination pin.
+ * Where does this reference sit in this DPLL's selection process?
+ * Predicates, all evaluated under multiop_lock:
+ * M source is present in THIS PLL's hardware priority table
+ * A chan->mode == 0 (outer loop running)
+ * L chan->locked && !chan->inner_lol (only meaningful when A)
+ * S chan->selected_ref == this pin's id
+ * get:
+ * CONNECTED A && L && S && M
+ * SELECTABLE M && !(A && L && S)
+ * DISCONNECTED !M
+ * set:
+ * DISCONNECTED remove from this PLL's table; a physical input also
+ * releases this DPLL's claim and powers the shared
+ * receiver down on the last release
+ * SELECTABLE add to this PLL's table; a physical input powers the
+ * receiver up and takes the claim, in that order
+ * CONNECTED -EOPNOTSUPP -- the device selects by priority and has
+ * no mode that pins one reference (see mode_set())
+ * other -EINVAL
+ *
+ * A is what separates CONNECTED from SELECTABLE: chan->locked is derived
+ * from the outer loss-of-lock bit, which can read clear while the outer
+ * loop is disabled, so a free-running PLL would otherwise claim its
+ * reference as the active input of a loop that is ignoring it.
+ *
+ * M is read from the hardware priority table, not from ref->pll_mask.
+ * pll_mask is only the shared-receiver refcount and says nothing about
+ * one DPLL's eligibility; it also drifts, because .prio_set writes the
+ * table without touching it. Signal quality is reported through the
+ * pin's own attributes rather than by demoting the state, so a source
+ * that is momentarily in LOS stays selectable.
+ *
+ * DRIVE role -- output pins, INTSYNC source pin.
+ * Is this pin or net being driven? Nothing is selected here, so:
+ * CONNECTED pin or net is driven
+ * DISCONNECTED pin is muted (Hi-Z), or this PLL does not drive it
+ * SELECTABLE -EINVAL on set, never reported by get
+ *
+ * FIXED role -- XO pin. Always CONNECTED; it cannot be routed.
+ */
+
+/*
+ * Report a selection-role pin's state on this DPLL. @pin_id is a logical
+ * input index, SIT9531X_INTSYNC_PIN_ID for the INTSYNC destination.
+ *
+ * CONNECTED means the device has selected this pin, not that the loop
+ * has settled on it: how well it is tracking is what lock status answers,
+ * and a PLL following a reference it has not locked to yet is still
+ * following that reference and no other.
+ *
+ * Membership comes from chan->prio_mask, which is the priority table read
+ * back from the chip -- not a record of what the driver asked for. The
+ * getter runs on every poll for every input pin of every DPLL, so it takes
+ * the mask the worker refreshed rather than rescanning the table over I2C
+ * each time; table writes refresh it too, so a get right after a set does
+ * not report the old membership.
+ *
+ * Caller must hold sitdev->multiop_lock.
+ */
+static void
+sit9531x_dpll_selection_state_get(struct sit9531x_dev *sitdev,
+ const struct sit9531x_dpll *sitdpll,
+ u8 pin_id, enum dpll_pin_state *state)
+{
+ const struct sit9531x_chan *chan;
+ bool active_input;
+
+ lockdep_assert_held(&sitdev->multiop_lock);
+
+ chan = sit9531x_chan_state_get(sitdev, sitdpll->id);
+ active_input = !chan->mode && chan->selected_ref == pin_id;
+
+ if (!(chan->prio_mask & BIT(sit9531x_input_hw_src(pin_id))))
+ *state = DPLL_PIN_STATE_DISCONNECTED;
+ else if (active_input)
+ *state = DPLL_PIN_STATE_CONNECTED;
+ else
+ *state = DPLL_PIN_STATE_SELECTABLE;
+}
+
+static int
+sit9531x_dpll_input_pin_direction_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_direction *direction,
+ struct netlink_ext_ack *extack)
+{
+ *direction = DPLL_PIN_DIRECTION_INPUT;
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_input_pin_frequency_get - read input pin frequency
+ *
+ * returns cached frequency from DT or last set.
+ */
+static int
+sit9531x_dpll_input_pin_frequency_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv, u64 *frequency,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ const struct sit9531x_ref *ref;
+
+ ref = sit9531x_ref_state_get(sitdpll->dev, dpin->id);
+ *frequency = ref->freq;
+
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_input_pin_state_on_dpll_get - get input pin DPLL state
+ *
+ * Selection role; see the pin-state contract above.
+ */
+static int
+sit9531x_dpll_input_pin_state_on_dpll_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state *state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+
+ mutex_lock(&sitdev->multiop_lock);
+ sit9531x_dpll_selection_state_get(sitdev, sitdpll, dpin->id, state);
+ mutex_unlock(&sitdev->multiop_lock);
+
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_input_pin_state_on_dpll_set - set input pin DPLL state
+ *
+ * Enables or disables the physical input receiver via Page 0x02
+ * force/state registers (sit9531x_input_disable/enable()) and updates
+ * this DPLL's Page 1 priority table so the state is honoured by the
+ * PLL's automatic reference selection, not just at the input buffer.
+ * Selection role; see the pin-state contract above for the states.
+ *
+ * The priority table is per PLL, so it is always updated for this DPLL.
+ * A single physical input feeds every DPLL, so the hardware receiver is
+ * only cut off once the last DPLL has released it: ref->pll_mask tracks
+ * which DPLLs currently claim the input, and the physical disable
+ * happens on the transition to an empty mask.
+ */
+static int
+sit9531x_dpll_input_pin_state_on_dpll_set(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ struct sit9531x_ref *ref = &sitdev->ref[dpin->id];
+ u8 hw_src = sit9531x_input_hw_src(dpin->id);
+ u8 pll_bit = BIT(sitdpll->id);
+ bool enabled_here = false;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ switch (state) {
+ case DPLL_PIN_STATE_DISCONNECTED:
+ rc = sit9531x_input_prio_remove(sitdev, sitdpll->id, hw_src);
+ /*
+ * The table write, the latch and the holdover release are
+ * three steps behind one return code, so ask the table what
+ * actually happened rather than reading the errno as "no
+ * change". A source that is gone from the table has been
+ * released whatever else failed.
+ */
+ if (rc && sit9531x_input_prio_present(sitdev, sitdpll->id,
+ hw_src))
+ break;
+ ref->pll_mask &= ~pll_bit;
+ /*
+ * The receiver is shared, so the last DPLL to let go turns it
+ * off. That has to happen even when the table rewrite
+ * reported an error, or the input stays powered with nothing
+ * tracking it; the first error is the one returned.
+ */
+ if (!ref->pll_mask) {
+ int off_rc = sit9531x_input_disable(sitdev, dpin->id);
+
+ if (off_rc && !rc)
+ rc = off_rc;
+ }
+ break;
+ case DPLL_PIN_STATE_CONNECTED:
+ /*
+ * CONNECTED asks for this input and no other, which the
+ * device cannot be told to do: it selects by priority and the
+ * manual-active-select path is not wired up (see mode_set()).
+ * Refuse instead of quietly behaving like SELECTABLE.
+ */
+ NL_SET_ERR_MSG(extack,
+ "Device selects its reference by priority; use selectable");
+ rc = -EOPNOTSUPP;
+ break;
+ case DPLL_PIN_STATE_SELECTABLE:
+ /*
+ * Gate the receiver on whenever it is off, not only when this
+ * DPLL holds no claim yet. The two are tracked separately --
+ * the claim comes from the priority table, the receiver from
+ * the force bits -- so a PLL that already lists the input can
+ * still find it powered down, and skipping the enable would
+ * report success for a reference that cannot reach the loop.
+ */
+ if (!ref->enabled) {
+ rc = sit9531x_input_enable(sitdev, dpin->id);
+ if (rc)
+ break;
+ enabled_here = true;
+ }
+ rc = sit9531x_input_prio_add(sitdev, sitdpll->id, hw_src);
+ if (rc && !sit9531x_input_prio_present(sitdev, sitdpll->id,
+ hw_src)) {
+ /*
+ * Undo only what this request did. A receiver the
+ * loaded configuration had already turned on is not
+ * this request's to turn off.
+ */
+ if (enabled_here)
+ sit9531x_input_disable(sitdev, dpin->id);
+ break;
+ }
+ /*
+ * Claim the input for this DPLL only once it is both enabled
+ * and present in the priority table. Setting the mask before
+ * prio_add would leak the claim if prio_add failed, keeping the
+ * shared input receiver powered even after every DPLL released
+ * it.
+ */
+ ref->pll_mask |= pll_bit;
+ break;
+ default:
+ rc = -EINVAL;
+ break;
+ }
+
+ mutex_unlock(&sitdev->multiop_lock);
+
+ /*
+ * Leave the messages the switch already set in place; only a failure
+ * that came from the hardware path still needs one.
+ */
+ if (rc == -ENOSPC)
+ NL_SET_ERR_MSG(extack,
+ "Priority table is full of unique sources on this PLL");
+ else if (rc && rc != -EOPNOTSUPP && rc != -EINVAL)
+ NL_SET_ERR_MSG(extack, "Failed to set input pin state");
+
+ return rc;
+}
+
+/*
+ * sit9531x_dpll_input_pin_prio_get - read input pin priority
+ *
+ * Reports the cached slot from sit9531x_input_prio_get(). The cache is
+ * refreshed from hardware at startup and by periodic read-back, so pin-get
+ * reports hardware priority without synchronous per-pin I2C reads.
+ */
+static int
+sit9531x_dpll_input_pin_prio_get(const struct dpll_pin *pin, void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv, u32 *prio,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ u8 slot;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_input_prio_get(sitdev, sitdpll->id,
+ sit9531x_input_hw_src(dpin->id), &slot);
+ mutex_unlock(&sitdev->multiop_lock);
+ if (rc)
+ return rc;
+
+ dpin->prio = slot;
+ *prio = slot;
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_input_pin_prio_set - set input pin priority
+ *
+ * writes input priority table on Page 1 via
+ * core.c sit9531x_input_prio_set(). Forces holdover during update.
+ */
+static int
+sit9531x_dpll_input_pin_prio_set(const struct dpll_pin *pin, void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv, u32 prio,
+ struct netlink_ext_ack *extack)
+{
+ struct dpll_pin *changed[SIT9531X_MAX_INPUTS + 1];
+ struct sit9531x_dpll_pin *sibling;
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ u8 changed_cnt = 0, hw_src, slot;
+ int get_rc, rc;
+
+ if (dpin->dir != DPLL_PIN_DIRECTION_INPUT) {
+ NL_SET_ERR_MSG(extack, "Priority applies only to input pins");
+ return -EINVAL;
+ }
+
+ if (prio >= SIT9531X_PRIO_MAX_SLOTS) {
+ NL_SET_ERR_MSG(extack, "Priority out of range (0-10)");
+ return -EINVAL;
+ }
+
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_input_prio_set(sitdev, sitdpll->id,
+ sit9531x_input_hw_src(dpin->id),
+ (u8)prio);
+ if (!rc) {
+ list_for_each_entry(sibling, &sitdpll->pins, list) {
+ if (!sit9531x_dpll_is_input_pin(sibling) ||
+ sit9531x_dpll_is_xo_pin(sibling))
+ continue;
+
+ hw_src = sit9531x_input_hw_src(sibling->id);
+ get_rc = sit9531x_input_prio_get(sitdev, sitdpll->id,
+ hw_src, &slot);
+ if (get_rc)
+ continue;
+
+ if (sibling->prio == slot)
+ continue;
+
+ sibling->prio = slot;
+
+ /*
+ * The core notifies the pin the request named, so
+ * only the others are collected here. A pin whose
+ * dpll_pin is already NULL is mid-unregister: that
+ * runs with the device lock dropped between the
+ * unregister and the free, so it can be seen from
+ * here, and notifying through it would follow a
+ * pointer that is on its way out.
+ */
+ if (sibling == dpin || !sibling->dpll_pin)
+ continue;
+
+ if (changed_cnt < ARRAY_SIZE(changed))
+ changed[changed_cnt++] = sibling->dpll_pin;
+ }
+ }
+ mutex_unlock(&sitdev->multiop_lock);
+
+ if (rc == -EINVAL) {
+ NL_SET_ERR_MSG(extack,
+ "Pin is not a reference of this DPLL; connect it first");
+ return rc;
+ }
+ if (rc == -ERANGE) {
+ NL_SET_ERR_MSG(extack,
+ "Priority is past the last reference this DPLL lists");
+ return rc;
+ }
+ if (rc) {
+ NL_SET_ERR_MSG(extack, "Failed to set input priority");
+ return rc;
+ }
+
+ /*
+ * The core notifies only the pin the request named, so the ones whose
+ * slots moved are notified here. This runs inside a pin op, where
+ * the core already holds the lock the notification needs, so it is
+ * the underscore helper rather than the wrapper that takes it.
+ */
+ while (changed_cnt--)
+ __dpll_pin_change_ntf(changed[changed_cnt]);
+
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_input_pin_ffo_get - read the input's frequency offset
+ *
+ * The offset is derived from how far the PLL's running DIVN sits from
+ * its configured one, which only says something about the reference the
+ * PLL is actually tracking. For every other input there is no
+ * measurement, and -ENODATA leaves the attribute out rather than
+ * reporting the active reference's figure against the wrong pin.
+ */
+static int
+sit9531x_dpll_input_pin_ffo_get(const struct dpll_pin *pin, void *pin_priv,
+ const struct dpll_device *dpll, void *dpll_priv,
+ struct dpll_ffo_param *ffo,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ enum dpll_pin_state state;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ /*
+ * Publish FFO only for the input the DPLL is actively tracking.
+ * selected_ref alone is not enough (free-run, LOL, holdover), so use
+ * the same CONNECTED criterion as the generic selection-state logic.
+ */
+ sit9531x_dpll_selection_state_get(sitdev, sitdpll, dpin->id, &state);
+ if (state != DPLL_PIN_STATE_CONNECTED) {
+ mutex_unlock(&sitdev->multiop_lock);
+ return -ENODATA;
+ }
+
+ rc = sit9531x_pll_ffo_ppt(sitdev, sitdpll->id, &ffo->ffo);
+ mutex_unlock(&sitdev->multiop_lock);
+
+ if (rc && rc != -ENODATA)
+ NL_SET_ERR_MSG(extack,
+ "Failed to measure the frequency offset of the selected reference");
+
+ return rc;
+}
+
+/*
+ * sit9531x_dpll_input_pin_phase_offset_get - phase offset of a reference
+ *
+ * What this reports, and what it deliberately does not:
+ *
+ * The ABI defines the attribute as the phase difference between the signal
+ * on a pin and its parent DPLL device, so this is the loop's own residual
+ * error, sampled with the loop closed. On a locked DPLL it therefore
+ * trends small -- that is the measurement, not an artefact of it. The
+ * documentation describes the reported value as one that may be averaged
+ * over prior measurements, which suits a closed-loop residual and not a
+ * one-shot open-loop capture; the core publishes whatever this callback
+ * returns, so the averaging, if any, would be this driver's to do.
+ *
+ * The chip can also measure the reference against the local oscillator
+ * with the outer loop's correction frozen, which is a different quantity
+ * and the one the documented phase-difference procedure produces. That
+ * needs the digital loop filter held (and, on the 1PPS PLL, the automatic
+ * phase- and frequency-lock helpers held off), which leaves the PLL
+ * undisciplined until it is released. A netlink read must not do that,
+ * so that measurement is not offered here at all; it belongs to a caller
+ * that can own the freeze and restore it.
+ *
+ * Precondition, which this callback cannot create: the TDC compares
+ * against a signal the PLL drives, so a PLL driving no output with its
+ * zero-delay buffer off has nothing to measure. SiTime confirms this is
+ * a property of the hardware rather than of their measurement script.
+ * The script satisfies it by mapping a spare output and restarting the
+ * PLL -- side effects that do not belong in a getter, so a reading taken
+ * in that state is simply not meaningful.
+ *
+ * Non-selected pins and a PLL with no programmed divider report zero
+ * rather than an error: the DPLL core propagates any error from this
+ * callback and fails the whole pin dump with it, unlike the frequency
+ * offset getter, where -ENODATA makes the core omit the attribute. There
+ * is no per-pin "no data" for phase offset, so it is a value or no
+ * callback at all.
+ */
+static int
+sit9531x_dpll_input_pin_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)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ enum dpll_pin_state state;
+ s64 offset;
+ u8 selected;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ /*
+ * The on-chip TDC is a per-PLL resource that always measures the
+ * phase difference between the VCO and the PLL's currently
+ * selected reference; it cannot be pointed at an arbitrary input.
+ * For any input that is not the active reference there is no
+ * meaningful per-pin phase offset, so report 0 instead of the
+ * active reference's value.
+ */
+ /*
+ * Which pin the sample belongs to is read from the device rather
+ * than taken from the monitor's cache: the device selects its own
+ * reference, so a cache up to a poll period old could attribute a
+ * live measurement to the pin that used to be selected.
+ */
+ rc = sit9531x_chan_selected_ref_read(sitdev, sitdpll->id,
+ &selected);
+ if (rc) {
+ mutex_unlock(&sitdev->multiop_lock);
+ NL_SET_ERR_MSG(extack,
+ "Selected reference could not be read back");
+ return rc;
+ }
+
+ sit9531x_dpll_selection_state_get(sitdev, sitdpll, dpin->id, &state);
+ if (state != DPLL_PIN_STATE_CONNECTED || selected != dpin->id) {
+ mutex_unlock(&sitdev->multiop_lock);
+ *phase_offset = 0;
+ return 0;
+ }
+
+ rc = sit9531x_phase_offset_read(sitdev, sitdpll->id, &offset);
+ mutex_unlock(&sitdev->multiop_lock);
+
+ /*
+ * -ENODATA means the PLL has no programmed DIVN (unused on this
+ * board); report phase_offset = 0 so a full pin-get dump does not
+ * fail just because one DPLL is dormant. Every other errno,
+ * -ENODEV from a vanished adapter included, is a failure.
+ */
+ if (rc == -ENODATA) {
+ *phase_offset = 0;
+ return 0;
+ }
+ if (rc) {
+ NL_SET_ERR_MSG(extack, "TDC phase readback failed");
+ return rc;
+ }
+
+ /*
+ * The ABI reports phase offset in units of 1/DPLL_PHASE_OFFSET_DIVIDER
+ * picoseconds: the integer part of the attribute is the value divided
+ * by the divider, the remainder is the fraction. The TDC resolves one
+ * VCO period (hundreds of picoseconds), so the fractional digits are
+ * always zero here, but the magnitude still has to be scaled or every
+ * reading would be reported a thousand times too small.
+ */
+ offset *= DPLL_PHASE_OFFSET_DIVIDER;
+
+ *phase_offset = offset;
+ return 0;
+}
+
+static const struct dpll_pin_ops sit9531x_dpll_input_pin_ops = {
+ .direction_get = sit9531x_dpll_input_pin_direction_get,
+ .frequency_get = sit9531x_dpll_input_pin_frequency_get,
+ .state_on_dpll_get = sit9531x_dpll_input_pin_state_on_dpll_get,
+ .state_on_dpll_set = sit9531x_dpll_input_pin_state_on_dpll_set,
+ .prio_get = sit9531x_dpll_input_pin_prio_get,
+ .prio_set = sit9531x_dpll_input_pin_prio_set,
+ .phase_offset_get = sit9531x_dpll_input_pin_phase_offset_get,
+ /*
+ * The measurement compares the PLL's running feedback divider with
+ * its configured one, so it describes the device's own reference
+ * rather than a port rate.
+ */
+ .supported_ffo = BIT(DPLL_FFO_PIN_DEVICE),
+ .ffo_get = sit9531x_dpll_input_pin_ffo_get,
+};
+
+/*
+ * INTSYNC pin ops
+ *
+ * INTSYNC is the chip's inter-PLL sync net: one PLL drives it and other
+ * PLLs may lock to it instead of to an external reference. The two
+ * roles are exposed as two separate pins so neither overloads the other:
+ *
+ * - a source (output) pin registered on every DPLL. Connecting it on a
+ * DPLL makes that DPLL drive INTSYNC; only one DPLL may drive it at a
+ * time. It has no priority ops -- driving the net is not a reference
+ * selection.
+ * - a destination (input) pin registered on every DPLL. Connecting it
+ * on a DPLL makes that DPLL eligible to lock to INTSYNC as a
+ * reference, so it carries the priority ops.
+ */
+
+/* ---- INTSYNC source (output) pin ---- */
+
+/* The INTSYNC source pin is an output; its direction_get is defined below. */
+static int
+sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_direction *direction,
+ struct netlink_ext_ack *extack);
+
+static int
+sit9531x_dpll_intsync_src_state_on_dpll_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state *state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+
+ mutex_lock(&sitdev->multiop_lock);
+ if (sitdev->intsync_src == sitdpll->id)
+ *state = DPLL_PIN_STATE_CONNECTED;
+ else
+ *state = DPLL_PIN_STATE_DISCONNECTED;
+ mutex_unlock(&sitdev->multiop_lock);
+
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_intsync_src_state_on_dpll_set - drive INTSYNC from a PLL
+ *
+ * CONNECTED -> this PLL drives the INTSYNC net
+ * DISCONNECTED -> stop driving INTSYNC if this PLL drives it
+ *
+ * SELECTABLE is rejected: driving the net is an explicit output routing,
+ * not an automatic-selection candidate, matching the regular output pin.
+ */
+static int
+sit9531x_dpll_intsync_src_state_on_dpll_set(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ int rc = 0, detect_rc = 0;
+ u8 hw_src;
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ switch (state) {
+ case DPLL_PIN_STATE_CONNECTED:
+ if (sitdev->intsync_src == sitdpll->id)
+ break;
+ if (sitdev->intsync_src >= 0) {
+ NL_SET_ERR_MSG(extack,
+ "INTSYNC is already sourced by another PLL");
+ rc = -EBUSY;
+ break;
+ }
+ /*
+ * A PLL that already lists INTSYNC among its references must
+ * not also drive it: the destination side refuses the mirror
+ * of this, and without the check here the net could be routed
+ * back into the PLL feeding it.
+ */
+ hw_src = sit9531x_input_hw_src(SIT9531X_INTSYNC_PIN_ID);
+ if (sit9531x_input_prio_present(sitdev, sitdpll->id, hw_src)) {
+ NL_SET_ERR_MSG(extack,
+ "PLL selects INTSYNC as a reference; it cannot drive it");
+ rc = -EBUSY;
+ break;
+ }
+ rc = sit9531x_intsync_enable(sitdev, sitdpll->id);
+ break;
+ case DPLL_PIN_STATE_DISCONNECTED:
+ if (sitdev->intsync_src != sitdpll->id)
+ break;
+ rc = sit9531x_intsync_disable(sitdev, sitdpll->id);
+ break;
+ default:
+ rc = -EINVAL;
+ break;
+ }
+
+ /*
+ * Re-scan hardware after source state transitions so cache follows
+ * partially failed enable/disable paths as closely as possible.
+ */
+ /*
+ * Record what was asked for before confirming it. The refresh below
+ * leaves the cache untouched when a read fails, and a cache that
+ * still says nobody drives the net would let a second PLL be
+ * configured to drive it as well.
+ */
+ if (!rc && state == DPLL_PIN_STATE_CONNECTED)
+ sitdev->intsync_src = sitdpll->id;
+ else if (!rc && state == DPLL_PIN_STATE_DISCONNECTED)
+ sitdev->intsync_src = -1;
+
+ if (state == DPLL_PIN_STATE_CONNECTED ||
+ state == DPLL_PIN_STATE_DISCONNECTED)
+ detect_rc = sit9531x_intsync_src_detect(sitdev);
+ /*
+ * The refresh only re-reads what the device now shows. Failing
+ * the request because that read hit a bus error would tell
+ * userspace the enable did not happen when it did.
+ */
+ if (detect_rc)
+ dev_warn(sitdev->dev,
+ "INTSYNC source cache not refreshed: %d\n",
+ detect_rc);
+
+ mutex_unlock(&sitdev->multiop_lock);
+
+ if (rc && rc != -EBUSY && rc != -EINVAL && rc != -EOPNOTSUPP)
+ NL_SET_ERR_MSG(extack, "Failed to set INTSYNC source state");
+
+ return rc;
+}
+
+static const struct dpll_pin_ops sit9531x_dpll_intsync_src_pin_ops = {
+ .direction_get = sit9531x_dpll_output_pin_direction_get,
+ .state_on_dpll_get = sit9531x_dpll_intsync_src_state_on_dpll_get,
+ .state_on_dpll_set = sit9531x_dpll_intsync_src_state_on_dpll_set,
+};
+
+/* ---- INTSYNC destination (input) pin ---- */
+
+/*
+ * sit9531x_dpll_intsync_dst_state_on_dpll_get - INTSYNC reference state
+ *
+ * Selection role, so the contract above decides this exactly as it does
+ * for a physical input: the priority table is the eligibility record, and
+ * whether a source PLL happens to be driving the net right now is no more
+ * a state than a momentary LOS is on an external reference. The one
+ * addition is that the PLL driving INTSYNC is never its own destination.
+ */
+static int
+sit9531x_dpll_intsync_dst_state_on_dpll_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state *state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+
+ mutex_lock(&sitdev->multiop_lock);
+ if (sitdev->intsync_src == sitdpll->id)
+ *state = DPLL_PIN_STATE_DISCONNECTED;
+ else
+ sit9531x_dpll_selection_state_get(sitdev, sitdpll,
+ SIT9531X_INTSYNC_PIN_ID,
+ state);
+ mutex_unlock(&sitdev->multiop_lock);
+
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_intsync_dst_state_on_dpll_set - lock a PLL to INTSYNC
+ *
+ * Selection role, so this accepts and refuses what a physical input does,
+ * CONNECTED included: the device pins no reference on request whichever
+ * source is asked for. INTSYNC is an internal net with no physical
+ * receiver, so only the per-PLL priority table is touched; the source pin
+ * controls generation.
+ */
+static int
+sit9531x_dpll_intsync_dst_state_on_dpll_set(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ u8 hw_src = sit9531x_input_hw_src(SIT9531X_INTSYNC_PIN_ID);
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ switch (state) {
+ case DPLL_PIN_STATE_DISCONNECTED:
+ rc = sit9531x_input_prio_remove(sitdev, sitdpll->id, hw_src);
+ break;
+ case DPLL_PIN_STATE_CONNECTED:
+ NL_SET_ERR_MSG(extack,
+ "Device selects its reference by priority; use selectable");
+ rc = -EOPNOTSUPP;
+ break;
+ case DPLL_PIN_STATE_SELECTABLE:
+ if (sitdev->intsync_src == sitdpll->id) {
+ NL_SET_ERR_MSG(extack,
+ "PLL cannot lock to the INTSYNC it drives");
+ rc = -EINVAL;
+ break;
+ }
+ rc = sit9531x_input_prio_add(sitdev, sitdpll->id, hw_src);
+ break;
+ default:
+ rc = -EINVAL;
+ break;
+ }
+
+ mutex_unlock(&sitdev->multiop_lock);
+
+ if (rc == -ENOSPC)
+ NL_SET_ERR_MSG(extack,
+ "Priority table is full of unique sources on this PLL");
+ else if (rc && rc != -EINVAL && rc != -EOPNOTSUPP)
+ NL_SET_ERR_MSG(extack, "Failed to set INTSYNC input state");
+
+ return rc;
+}
+
+/*
+ * Do not add .frequency_get / the generic input state getter here: the
+ * destination pin id is SIT9531X_INTSYNC_PIN_ID, one past the end of the
+ * ref[] array (INTSYNC is an internal net with no ref[] entry). The ops
+ * below only ever key on chan[] and the priority table, never ref[id].
+ */
+static const struct dpll_pin_ops sit9531x_dpll_intsync_dst_pin_ops = {
+ .direction_get = sit9531x_dpll_input_pin_direction_get,
+ .state_on_dpll_get = sit9531x_dpll_intsync_dst_state_on_dpll_get,
+ .state_on_dpll_set = sit9531x_dpll_intsync_dst_state_on_dpll_set,
+ .prio_get = sit9531x_dpll_input_pin_prio_get,
+ .prio_set = sit9531x_dpll_input_pin_prio_set,
+};
+
+/*
+ * XO (crystal oscillator) pin ops
+ *
+ * The XO is the chip's internal reference oscillator that feeds every
+ * PLL. It is exposed so userspace can see the on-chip reference, but it
+ * cannot be routed or disconnected, so it is reported permanently
+ * connected and offers no state_on_dpll_set / prio ops.
+ */
+
+static int
+sit9531x_dpll_xo_pin_state_on_dpll_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state *state,
+ struct netlink_ext_ack *extack)
+{
+ *state = DPLL_PIN_STATE_CONNECTED;
+ return 0;
+}
+
+static const struct dpll_pin_ops sit9531x_dpll_xo_pin_ops = {
+ .direction_get = sit9531x_dpll_input_pin_direction_get,
+ .frequency_get = sit9531x_dpll_input_pin_frequency_get,
+ .state_on_dpll_get = sit9531x_dpll_xo_pin_state_on_dpll_get,
+};
+
+static int
+sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_direction *direction,
+ struct netlink_ext_ack *extack)
+{
+ *direction = DPLL_PIN_DIRECTION_OUTPUT;
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_output_pin_frequency_get - read output pin frequency
+ *
+ * Reads the DIVO divider back from the chip and computes the live
+ * frequency as Fvco / DIVO. Falls back to the cached value only when
+ * the output is not resolvable through the divider chain (e.g. not
+ * mapped to a PLL), so transport/register errors still surface.
+ */
+static int
+sit9531x_dpll_output_pin_frequency_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv, u64 *frequency,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_output_freq_get(sitdev, dpin->id, frequency);
+ if (rc == -ENODEV)
+ *frequency = sit9531x_out_state_get(sitdev, dpin->id)->freq;
+ mutex_unlock(&sitdev->multiop_lock);
+
+ return rc == -ENODEV ? 0 : rc;
+}
+
+/*
+ * sit9531x_dpll_output_pin_frequency_set - set output pin frequency
+ *
+ * computes DIVO = Fvco / frequency and writes the
+ * 34-bit output divider to the output system registers via
+ * sit9531x_output_freq_set().
+ */
+static int
+sit9531x_dpll_output_pin_frequency_set(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv, u64 frequency,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ u8 actual_pll;
+ int rc;
+
+ /*
+ * Read the PLL that drives this output from its OUT_MAP state
+ * (populated by out_state_fetch from the chip's OUT_MAP registers).
+ * That is the index the output register programming below is keyed
+ * by; the output is registered under the DPLL matching this PLL.
+ */
+ actual_pll = sitdev->out[dpin->id].pll_idx;
+
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_output_freq_set(sitdev, dpin->id, actual_pll,
+ frequency);
+ mutex_unlock(&sitdev->multiop_lock);
+
+ if (rc)
+ NL_SET_ERR_MSG(extack, "Output frequency set failed");
+
+ return rc;
+}
+
+/*
+ * sit9531x_dpll_output_pin_state_on_dpll_get - get output pin state
+ *
+ * reports CONNECTED when the output is driven and
+ * DISCONNECTED when it has been muted via sit9531x_output_disable().
+ */
+static int
+sit9531x_dpll_output_pin_state_on_dpll_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state *state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ const struct sit9531x_out *out;
+ int rc;
+
+ /*
+ * A mute whose read-back failed left the cache unconfirmed; there is
+ * no poll of output state to correct it, so read it here rather than
+ * report a value that may predate the request.
+ */
+ if (sitdev->out[dpin->id].state_stale) {
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_output_state_refresh(sitdev, dpin->id);
+ mutex_unlock(&sitdev->multiop_lock);
+ if (rc) {
+ NL_SET_ERR_MSG(extack,
+ "Output mute state could not be read back");
+ return rc;
+ }
+ }
+
+ out = sit9531x_out_state_get(sitdev, dpin->id);
+ *state = out->enabled ? DPLL_PIN_STATE_CONNECTED
+ : DPLL_PIN_STATE_DISCONNECTED;
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_output_pin_state_on_dpll_set - mute/un-mute an output
+ *
+ * forces Hi-Z on the output pin via the Page 0x03
+ * force/state register pair.
+ * CONNECTED -> enable (release force, back to factory default)
+ * DISCONNECTED -> disable (force Hi-Z)
+ */
+static int
+sit9531x_dpll_output_pin_state_on_dpll_set(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv,
+ enum dpll_pin_state state,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+
+ switch (state) {
+ case DPLL_PIN_STATE_CONNECTED:
+ rc = sit9531x_output_enable(sitdev, dpin->id);
+ break;
+ case DPLL_PIN_STATE_DISCONNECTED:
+ rc = sit9531x_output_disable(sitdev, dpin->id);
+ break;
+ default:
+ rc = -EINVAL;
+ break;
+ }
+
+ mutex_unlock(&sitdev->multiop_lock);
+
+ if (rc)
+ NL_SET_ERR_MSG(extack, "Failed to set output pin state");
+
+ return rc;
+}
+
+/*
+ * sit9531x_dpll_output_pin_phase_adjust_get - read output phase adjustment
+ *
+ * Returns what the delay registers hold, i.e. the value
+ * sit9531x_output_phase_adjust_set() programmed after quantization, read
+ * from the cache unless a failed request left it unconfirmed.
+ */
+static int
+sit9531x_dpll_output_pin_phase_adjust_get(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv, s32 *phase_adjust,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+ /*
+ * A request whose writes reached the device but whose commit or
+ * phase flush failed left the cache describing the delay before it.
+ * There is no poll of the delay registers to correct that, so read
+ * them here rather than report a value the output is not using.
+ */
+ if (sitdev->out[dpin->id].phase_stale) {
+ s32 phase_ps;
+
+ rc = sit9531x_output_phase_read(sitdev, dpin->id, &phase_ps);
+ if (rc) {
+ mutex_unlock(&sitdev->multiop_lock);
+ NL_SET_ERR_MSG(extack,
+ "Output delay could not be read back");
+ return rc;
+ }
+ sitdev->out[dpin->id].phase_adj = phase_ps;
+ sitdev->out[dpin->id].phase_armed = !!phase_ps;
+ sitdev->out[dpin->id].phase_stale = false;
+ }
+ *phase_adjust = sit9531x_out_state_get(sitdev, dpin->id)->phase_adj;
+ mutex_unlock(&sitdev->multiop_lock);
+
+ return 0;
+}
+
+/*
+ * sit9531x_dpll_output_pin_phase_adjust_set - set output phase adjustment
+ *
+ * Programs the per-output PRG_RST_DELAY registers for deterministic
+ * phase offset; see sit9531x_output_phase_adjust_set() in core.c.
+ */
+static int
+sit9531x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *pin,
+ void *pin_priv,
+ const struct dpll_device *dpll,
+ void *dpll_priv, s32 phase_adjust,
+ struct netlink_ext_ack *extack)
+{
+ struct sit9531x_dpll_pin *dpin = pin_priv;
+ struct sit9531x_dpll *sitdpll = dpll_priv;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ int rc;
+
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_output_phase_adjust_set(sitdev, dpin->id, phase_adjust);
+ mutex_unlock(&sitdev->multiop_lock);
+
+ if (rc) {
+ NL_SET_ERR_MSG(extack, "Phase adjust failed");
+ return rc;
+ }
+
+ return 0;
+}
+
+static const struct dpll_pin_ops sit9531x_dpll_output_pin_ops = {
+ .direction_get = sit9531x_dpll_output_pin_direction_get,
+ .frequency_get = sit9531x_dpll_output_pin_frequency_get,
+ .frequency_set = sit9531x_dpll_output_pin_frequency_set,
+ .state_on_dpll_get = sit9531x_dpll_output_pin_state_on_dpll_get,
+ .state_on_dpll_set = sit9531x_dpll_output_pin_state_on_dpll_set,
+ .phase_adjust_get = sit9531x_dpll_output_pin_phase_adjust_get,
+ .phase_adjust_set = sit9531x_dpll_output_pin_phase_adjust_set,
+};
+
+const struct dpll_pin_ops *
+sit9531x_dpll_pin_ops_get(const struct sit9531x_dpll_pin *pin)
+{
+ if (!sit9531x_dpll_is_input_pin(pin)) {
+ if (sit9531x_dpll_is_intsync_src_pin(pin))
+ return &sit9531x_dpll_intsync_src_pin_ops;
+ return &sit9531x_dpll_output_pin_ops;
+ }
+ if (sit9531x_dpll_is_intsync_pin(pin))
+ return &sit9531x_dpll_intsync_dst_pin_ops;
+ if (sit9531x_dpll_is_xo_pin(pin))
+ return &sit9531x_dpll_xo_pin_ops;
+ return &sit9531x_dpll_input_pin_ops;
+}
+
+/*
+ * sit9531x_dpll_changes_check - check for state changes and notify
+ *
+ * Called from sit9531x_dev_periodic_work(). Compares current hardware
+ * state against cached values and sends netlink notifications on changes.
+ */
+void sit9531x_dpll_changes_check(struct sit9531x_dpll *sitdpll)
+{
+ enum dpll_lock_status_error status_error = DPLL_LOCK_STATUS_ERROR_NONE;
+ struct sit9531x_dev *sitdev = sitdpll->dev;
+ enum dpll_lock_status lock_status;
+ struct sit9531x_dpll_pin *pin;
+ int rc;
+
+ rc = sit9531x_dpll_lock_status_get(sitdpll->dpll_dev, sitdpll,
+ &lock_status, &status_error, NULL);
+ if (rc) {
+ dev_err(sitdev->dev, "Failed to get DPLL%u lock status: %d\n",
+ sitdpll->id, rc);
+ return;
+ }
+
+ /*
+ * The core publishes the error detail alongside the status, so a
+ * change in either is a change subscribers have to be told about:
+ * an inner loss of lock appearing or clearing while the status
+ * stays UNLOCKED would otherwise be visible only to a later GET.
+ */
+ if (sitdpll->lock_status != lock_status ||
+ sitdpll->lock_status_error != status_error) {
+ sitdpll->lock_status = lock_status;
+ sitdpll->lock_status_error = status_error;
+ dpll_device_change_ntf(sitdpll->dpll_dev);
+ }
+
+ list_for_each_entry(pin, &sitdpll->pins, list) {
+ const struct dpll_pin_ops *ops;
+ enum dpll_pin_state state;
+
+ /*
+ * Poll input pins whose state can change autonomously: regular
+ * references and the INTSYNC destination pin. Outputs (incl.
+ * the INTSYNC source) change only through their own set
+ * callback and the XO is permanently connected, so skip those.
+ * Each pin's state_on_dpll_get resolves to the right getter.
+ */
+ if (!sit9531x_dpll_is_input_pin(pin) ||
+ sit9531x_dpll_is_xo_pin(pin))
+ continue;
+
+ ops = sit9531x_dpll_pin_ops_get(pin);
+ rc = ops->state_on_dpll_get(pin->dpll_pin, pin,
+ sitdpll->dpll_dev, sitdpll,
+ &state, NULL);
+ if (rc)
+ continue;
+
+ if (state != pin->pin_state) {
+ dev_dbg(sitdev->dev, "%s state changed: %u->%u\n",
+ pin->label, pin->pin_state, state);
+ pin->pin_state = state;
+ dpll_pin_change_ntf(pin->dpll_pin);
+ }
+ }
+}
diff --git a/drivers/dpll/sit9531x/dpll.h b/drivers/dpll/sit9531x/dpll.h
new file mode 100644
index 0000000000000..d6ef799d52c2f
--- /dev/null
+++ b/drivers/dpll/sit9531x/dpll.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SiTime SiT9531x DPLL subsystem interface
+ *
+ * Copyright (C) 2026 SiTime Corp.
+ * Author: Ali Rouhi <arouhi@sitime.com>
+ * Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
+ *
+ * DPLL device and pin structures, and function declarations for
+ * the DPLL registration and callback layer.
+ */
+
+#ifndef _SIT9531X_DPLL_H
+#define _SIT9531X_DPLL_H
+
+#include <linux/dpll.h>
+#include <linux/list.h>
+#include <linux/types.h>
+
+struct sit9531x_dev;
+
+/* Per-pin DPLL state. */
+struct sit9531x_dpll_pin {
+ struct list_head list;
+ struct sit9531x_dpll *dpll;
+ struct dpll_pin *dpll_pin;
+ dpll_tracker tracker;
+ struct fwnode_handle *fwnode;
+ char label[8]; /* "IN0", "OUT3" */
+ enum dpll_pin_direction dir;
+ u8 id; /* hardware index */
+ u8 prio;
+ enum dpll_pin_state pin_state;
+};
+
+/* Per-PLL DPLL device state. */
+struct sit9531x_dpll {
+ struct list_head list;
+ struct sit9531x_dev *dev;
+ struct dpll_device *dpll_dev;
+ dpll_tracker tracker;
+ struct dpll_device_ops ops; /* per-instance copy */
+ struct list_head pins;
+ u8 id; /* 0 = PLLA .. 3 = PLLD */
+ enum dpll_lock_status lock_status;
+ enum dpll_lock_status_error lock_status_error;
+};
+
+/* ---- DPLL allocation and registration ---- */
+/*
+ * The callback tables stay with the callbacks; the registration code that
+ * hands them to the subsystem lives next to probe() in core.c.
+ */
+extern const struct dpll_device_ops sit9531x_dpll_device_ops;
+const struct dpll_pin_ops *
+sit9531x_dpll_pin_ops_get(const struct sit9531x_dpll_pin *pin);
+
+struct sit9531x_dpll *sit9531x_dpll_alloc(struct sit9531x_dev *sitdev, u8 ch);
+void sit9531x_dpll_free(struct sit9531x_dpll *sitdpll);
+int sit9531x_dpll_register(struct sit9531x_dpll *sitdpll);
+void sit9531x_dpll_unregister(struct sit9531x_dpll *sitdpll);
+
+/* ---- Periodic change detection ---- */
+void sit9531x_dpll_changes_check(struct sit9531x_dpll *sitdpll);
+
+#endif /* _SIT9531X_DPLL_H */
diff --git a/drivers/dpll/sit9531x/prop.c b/drivers/dpll/sit9531x/prop.c
new file mode 100644
index 0000000000000..82e8cd2266f5a
--- /dev/null
+++ b/drivers/dpll/sit9531x/prop.c
@@ -0,0 +1,469 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SiTime SiT9531x firmware node property parsing
+ *
+ * Copyright (C) 2026 SiTime Corp.
+ * Author: Ali Rouhi <arouhi@sitime.com>
+ * Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
+ *
+ * Retrieves pin properties from Device Tree firmware nodes (or
+ * applies defaults when no firmware node exists).
+ */
+
+#include <linux/dev_printk.h>
+#include <linux/dpll.h>
+#include <linux/err.h>
+#include <linux/fwnode.h>
+#include <linux/property.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "core.h"
+#include "prop.h"
+
+/*
+ * sit9531x_input_pin_label - fill the package label for an input pin
+ *
+ * Split out so input-naming changes stay local to this helper.
+ */
+static void sit9531x_input_pin_label(struct sit9531x_dev *sitdev,
+ struct sit9531x_pin_props *props, u8 id)
+{
+ u8 pair = sit9531x_input_pair(id);
+
+ if (sitdev->ref[id].sig_mode == SIT9531X_MODE_DE)
+ snprintf(props->package_label,
+ sizeof(props->package_label), "IN%u", pair);
+ else
+ snprintf(props->package_label,
+ sizeof(props->package_label), "IN%u%c", pair,
+ sit9531x_input_is_n(id) ? 'N' : 'P');
+}
+
+/*
+ * sit9531x_prop_pin_package_label_set - generate package label
+ * @dir: pin direction
+ * @id: pin index
+ *
+ * Generates a package label string. Output pins are named "OUT0",
+ * "OUT1", ... Input pins are named after the physical pair and lane:
+ * "IN0P", "IN0N", "IN1P", ... for single-ended lanes, or "IN0",
+ * "IN1", ... when the pair is configured differential (the N lane is
+ * not registered in that case).
+ */
+static void
+sit9531x_prop_pin_package_label_set(struct sit9531x_dev *sitdev,
+ struct sit9531x_pin_props *props,
+ enum dpll_pin_direction dir, u8 id)
+{
+ /* The internal INTSYNC pin has a fixed label */
+ if (dir == DPLL_PIN_DIRECTION_INPUT &&
+ id == SIT9531X_INTSYNC_PIN_ID) {
+ strscpy(props->package_label, "INTSYNC",
+ sizeof(props->package_label));
+ props->dpll_props.package_label = props->package_label;
+ return;
+ }
+
+ /* The internal XO reference has a fixed label */
+ if (dir == DPLL_PIN_DIRECTION_INPUT && id == SIT9531X_MAX_INPUTS) {
+ strscpy(props->package_label, "XO",
+ sizeof(props->package_label));
+ props->dpll_props.package_label = props->package_label;
+ return;
+ }
+
+ /* The internal INTSYNC source (output) pin has a fixed label */
+ if (dir == DPLL_PIN_DIRECTION_OUTPUT &&
+ id == SIT9531X_INTSYNC_OUT_PIN_ID) {
+ strscpy(props->package_label, "SYNCOUT",
+ sizeof(props->package_label));
+ props->dpll_props.package_label = props->package_label;
+ return;
+ }
+
+ if (dir == DPLL_PIN_DIRECTION_INPUT)
+ sit9531x_input_pin_label(sitdev, props, id);
+ else
+ /*
+ * Name the chip pin, not the driver's index for it. The
+ * two differ on the variant whose outputs are bonded out
+ * from a subset of the twelve slots, and a package label
+ * that named the index would point at a pin that is not
+ * the one being driven.
+ */
+ snprintf(props->package_label, sizeof(props->package_label),
+ "OUT%u", sitdev->info->clkout_map[id]);
+
+ props->dpll_props.package_label = props->package_label;
+}
+
+/*
+ * sit9531x_prop_pin_fwnode_get - find firmware node for a pin
+ * @dir: pin direction
+ * @id: pin index
+ *
+ * Searches for input-pins/output-pins child nodes in DT, looking for a
+ * child whose "reg" property matches the pin. The binding describes reg
+ * as the hardware index, so an output is matched by the chip slot it
+ * drives rather than by the driver's index for it: on the variant where
+ * the two differ, a board describing the pin it wired would otherwise
+ * have its properties applied to a different one.
+ *
+ * Return: 0 on success, -ENOENT if no firmware node exists
+ */
+static int
+sit9531x_prop_pin_fwnode_get(struct sit9531x_dev *sitdev,
+ struct sit9531x_pin_props *props,
+ enum dpll_pin_direction dir, u8 id)
+{
+ struct fwnode_handle *pins_node, *pin_node;
+ const char *node_name;
+
+ if (dir == DPLL_PIN_DIRECTION_INPUT) {
+ node_name = "input-pins";
+ } else {
+ node_name = "output-pins";
+ if (id < sitdev->info->num_outputs)
+ id = sitdev->info->clkout_map[id];
+ }
+
+ pins_node = device_get_named_child_node(sitdev->dev, node_name);
+ if (!pins_node) {
+ dev_dbg(sitdev->dev, "'%s' sub-node is missing\n", node_name);
+ return -ENOENT;
+ }
+
+ /* Enumerate child pin nodes and find the requested one */
+ fwnode_for_each_child_node(pins_node, pin_node) {
+ u32 reg;
+
+ if (fwnode_property_read_u32(pin_node, "reg", ®))
+ continue;
+
+ if (id == reg)
+ break;
+ }
+
+ fwnode_handle_put(pins_node);
+
+ props->fwnode = pin_node;
+
+ dev_dbg(sitdev->dev, "Firmware node for %s %sfound\n",
+ props->package_label, pin_node ? "" : "NOT ");
+
+ return pin_node ? 0 : -ENOENT;
+}
+
+/*
+ * sit9531x_pin_props_get - get pin properties for a given pin
+ * @dir: pin direction (INPUT or OUTPUT)
+ * @index: pin index
+ *
+ * Allocates a pin properties structure, generates a package label,
+ * looks up the firmware node if available, and reads optional
+ * properties (label, connection-type, supported-frequencies-hz).
+ *
+ * Call sit9531x_pin_props_put() to free the returned structure.
+ *
+ * Return: pointer to pin properties on success, error pointer on error
+ */
+struct sit9531x_pin_props *
+sit9531x_pin_props_get(struct sit9531x_dev *sitdev,
+ enum dpll_pin_direction dir, u8 index)
+{
+ struct dpll_pin_frequency *ranges;
+ struct sit9531x_pin_props *props;
+ int i, j, num_freqs = 0, rc;
+ u64 *freqs = NULL;
+ const char *type;
+ u64 curr_freq;
+
+ props = kzalloc_obj(*props, GFP_KERNEL);
+ if (!props)
+ return ERR_PTR(-ENOMEM);
+
+ if (dir == DPLL_PIN_DIRECTION_INPUT &&
+ index == SIT9531X_INTSYNC_PIN_ID) {
+ /*
+ * INTSYNC destination pin: a PLL locks to the INTSYNC net as a
+ * reference, so it can be connected and re-prioritised.
+ */
+ props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;
+ props->dpll_props.capabilities =
+ DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |
+ DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
+ curr_freq = 0;
+ } else if (dir == DPLL_PIN_DIRECTION_OUTPUT &&
+ index == SIT9531X_INTSYNC_OUT_PIN_ID) {
+ /*
+ * INTSYNC source pin: a PLL drives the INTSYNC net. It can be
+ * connected/disconnected but carries no priority (driving the
+ * net is not a reference selection) and no frequency.
+ */
+ props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;
+ props->dpll_props.capabilities =
+ DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
+ curr_freq = 0;
+ } else if (dir == DPLL_PIN_DIRECTION_INPUT &&
+ index == SIT9531X_MAX_INPUTS) {
+ /* The XO reference is fixed: no state or priority control. */
+ props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;
+ props->dpll_props.capabilities = 0;
+ sitdev->ref[index].freq = sitdev->xtal_freq;
+ curr_freq = sitdev->xtal_freq;
+ } else if (dir == DPLL_PIN_DIRECTION_INPUT) {
+ props->dpll_props.type = DPLL_PIN_TYPE_EXT;
+ props->dpll_props.capabilities =
+ DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |
+ DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
+ curr_freq = sitdev->ref[index].freq;
+ } else {
+ /*
+ * A synthesized clock output is an external connection with
+ * no more specific meaning; a board that knows better says
+ * so through the pin's connection-type property below.
+ */
+ props->dpll_props.type = DPLL_PIN_TYPE_EXT;
+ props->dpll_props.capabilities =
+ DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
+ curr_freq = sitdev->out[index].freq;
+
+ /*
+ * Allow phase-adjust over a +/-1 ms window. The subsystem
+ * rejects pin_set(phase-adjust, X) when X falls outside
+ * [min, max], so leaving these at 0 silently blocks every
+ * netlink call. 1 ms is well beyond the DCO dynamic range
+ * but costs nothing. Only outputs get a range: input pins
+ * have no .phase_adjust_set, and advertising one there would
+ * promise userspace something every set would refuse.
+ */
+ /* +/-1 ms, in ps */
+ props->dpll_props.phase_range.min = -1000000000;
+ props->dpll_props.phase_range.max = 1000000000;
+ /*
+ * The fine step is 30 ps, but requests are accepted at 1 ps
+ * resolution and rounded to the nearest achievable delay, so
+ * advertise the request granularity, not the hardware step.
+ */
+ props->dpll_props.phase_gran = 1;
+ }
+
+ /* Generate package label */
+ sit9531x_prop_pin_package_label_set(sitdev, props, dir, index);
+
+ /*
+ * Both INTSYNC pins are internal to the chip and have no board-level
+ * wiring, so they take no properties from the firmware node.
+ */
+ if (dir == DPLL_PIN_DIRECTION_INPUT &&
+ (index == SIT9531X_INTSYNC_PIN_ID ||
+ index == SIT9531X_MAX_INPUTS))
+ goto skip_fwnode_props;
+ if (dir == DPLL_PIN_DIRECTION_OUTPUT &&
+ index == SIT9531X_INTSYNC_OUT_PIN_ID)
+ goto skip_fwnode_props;
+
+ rc = sit9531x_prop_pin_fwnode_get(sitdev, props, dir, index);
+ if (rc)
+ goto skip_fwnode_props;
+
+ /* Look for "label" property -> board label */
+ fwnode_property_read_string(props->fwnode, "label",
+ &props->dpll_props.board_label);
+
+ /* Look for "connection-type" property -> pin type enum */
+ if (!fwnode_property_read_string(props->fwnode, "connection-type",
+ &type)) {
+ if (!strcmp(type, "ext"))
+ props->dpll_props.type = DPLL_PIN_TYPE_EXT;
+ else if (!strcmp(type, "gnss"))
+ props->dpll_props.type = DPLL_PIN_TYPE_GNSS;
+ else if (!strcmp(type, "int"))
+ props->dpll_props.type = DPLL_PIN_TYPE_INT_OSCILLATOR;
+ else if (!strcmp(type, "synce"))
+ props->dpll_props.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT;
+ else if (!strcmp(type, "mux"))
+ props->dpll_props.type = DPLL_PIN_TYPE_MUX;
+ else
+ dev_warn(sitdev->dev,
+ "Unknown pin type '%s'\n", type);
+ }
+
+ num_freqs = fwnode_property_count_u64(props->fwnode,
+ "supported-frequencies-hz");
+ if (num_freqs <= 0) {
+ num_freqs = 0;
+ goto skip_fwnode_props;
+ }
+
+ freqs = kcalloc(num_freqs, sizeof(*freqs), GFP_KERNEL);
+ if (!freqs) {
+ rc = -ENOMEM;
+ goto err_alloc_freqs;
+ }
+
+ rc = fwnode_property_read_u64_array(props->fwnode,
+ "supported-frequencies-hz",
+ freqs, num_freqs);
+ if (rc) {
+ dev_warn(sitdev->dev,
+ "failed to parse supported-frequencies-hz for %s: %d\n",
+ props->package_label, rc);
+ goto err_alloc_ranges;
+ }
+
+ /*
+ * Seed the runtime ref->freq with the first DT-listed supported
+ * frequency: an input's rate is a board fact the device cannot be
+ * asked for, so firmware is the only source. An output is left to
+ * the read-back below, which knows what the divider is actually
+ * doing.
+ */
+ if (num_freqs > 0 && dir == DPLL_PIN_DIRECTION_INPUT &&
+ index != SIT9531X_MAX_INPUTS)
+ curr_freq = freqs[0];
+
+ /*
+ * An output's current rate is the one its divider produces, so read
+ * it rather than assume the first entry of a list of the rates the
+ * board supports is the one in force. A rate taken from firmware
+ * that the part is not running would be reported as current and,
+ * worse, used as the output period the phase adjust quantizes
+ * against. An output the configuration does not route has no rate
+ * to read, which is not an error.
+ */
+ if (dir == DPLL_PIN_DIRECTION_OUTPUT &&
+ index < sitdev->info->num_outputs) {
+ u64 hw_freq;
+
+ mutex_lock(&sitdev->multiop_lock);
+ rc = sit9531x_output_freq_get(sitdev, index, &hw_freq);
+ mutex_unlock(&sitdev->multiop_lock);
+ if (!rc)
+ curr_freq = hw_freq;
+ }
+
+skip_fwnode_props:
+ /* Neither INTSYNC pin carries a frequency attribute */
+ if (dir == DPLL_PIN_DIRECTION_INPUT &&
+ index == SIT9531X_INTSYNC_PIN_ID)
+ return props;
+ if (dir == DPLL_PIN_DIRECTION_OUTPUT &&
+ index == SIT9531X_INTSYNC_OUT_PIN_ID)
+ return props;
+
+ /*
+ * Advertise only concrete values from firmware plus current runtime
+ * value. For outputs without a firmware list, publish one wide range as
+ * an explicit fallback because those pins do support frequency_set.
+ */
+ ranges = kcalloc(num_freqs + 2, sizeof(*ranges), GFP_KERNEL);
+ if (!ranges) {
+ rc = -ENOMEM;
+ goto err_alloc_ranges;
+ }
+
+ /*
+ * Publish the seeded rate only once the pin is certain to be built.
+ * The allocation above is the last thing that can fail, and a call
+ * that reports failure must not leave the device's cached rate
+ * changed behind it.
+ */
+ if (curr_freq) {
+ if (dir == DPLL_PIN_DIRECTION_INPUT)
+ sitdev->ref[index].freq = curr_freq;
+ else
+ sitdev->out[index].freq = curr_freq;
+ }
+
+ j = 0;
+
+ /* Current frequency first, when known. */
+ if (curr_freq) {
+ struct dpll_pin_frequency f = DPLL_PIN_FREQUENCY(curr_freq);
+
+ ranges[j++] = f;
+ }
+
+ for (i = 0; i < num_freqs; i++) {
+ struct dpll_pin_frequency freq = DPLL_PIN_FREQUENCY(freqs[i]);
+
+ if (freqs[i] == curr_freq)
+ continue;
+ ranges[j++] = freq;
+ }
+
+ if (dir == DPLL_PIN_DIRECTION_OUTPUT && num_freqs == 0) {
+ ranges[j].min = 1;
+ ranges[j].max = 1000000000ULL; /* 1 GHz */
+ j++;
+ }
+
+ if (j > 0) {
+ props->dpll_props.freq_supported = ranges;
+ props->dpll_props.freq_supported_num = j;
+ } else {
+ kfree(ranges);
+ props->dpll_props.freq_supported = NULL;
+ props->dpll_props.freq_supported_num = 0;
+ }
+
+ kfree(freqs);
+
+ return props;
+
+err_alloc_ranges:
+ kfree(freqs);
+err_alloc_freqs:
+ fwnode_handle_put(props->fwnode);
+ kfree(props);
+
+ return ERR_PTR(rc);
+}
+
+/*
+ * sit9531x_pin_props_put - release pin properties
+ * @props: pin properties to free
+ */
+void sit9531x_pin_props_put(struct sit9531x_pin_props *props)
+{
+ kfree(props->dpll_props.freq_supported);
+
+ if (props->fwnode)
+ fwnode_handle_put(props->fwnode);
+
+ kfree(props);
+}
+
+/*
+ * sit9531x_prop_dpll_type_get - get DPLL channel type from firmware
+ * @index: DPLL channel index (0-3)
+ *
+ * Reads the "dpll-types" string array property from the firmware node
+ * and returns the corresponding DPLL type enum.
+ *
+ * Return: DPLL type for the given channel (default: DPLL_TYPE_PPS)
+ */
+enum dpll_type
+sit9531x_prop_dpll_type_get(struct sit9531x_dev *sitdev, u8 index)
+{
+ const char *types[SIT9531X_NUM_PLLS];
+ int count;
+
+ count = device_property_read_string_array(sitdev->dev, "dpll-types",
+ types, ARRAY_SIZE(types));
+
+ if (index >= count)
+ return DPLL_TYPE_PPS;
+
+ if (!strcmp(types[index], "pps"))
+ return DPLL_TYPE_PPS;
+ else if (!strcmp(types[index], "eec"))
+ return DPLL_TYPE_EEC;
+
+ dev_warn(sitdev->dev, "Unknown DPLL type '%s', using default\n",
+ types[index]);
+
+ return DPLL_TYPE_PPS;
+}
diff --git a/drivers/dpll/sit9531x/prop.h b/drivers/dpll/sit9531x/prop.h
new file mode 100644
index 0000000000000..a65efdfd9ef8a
--- /dev/null
+++ b/drivers/dpll/sit9531x/prop.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SiTime SiT9531x firmware node property parsing
+ *
+ * Copyright (C) 2026 SiTime Corp.
+ * Author: Ali Rouhi <arouhi@sitime.com>
+ * Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
+ */
+
+#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 */
diff --git a/drivers/dpll/sit9531x/regs.h b/drivers/dpll/sit9531x/regs.h
new file mode 100644
index 0000000000000..09a2032f7bf02
--- /dev/null
+++ b/drivers/dpll/sit9531x/regs.h
@@ -0,0 +1,364 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SiTime SiT9531x register definitions
+ *
+ * Copyright (C) 2026 SiTime Corp.
+ * Author: Ali Rouhi <arouhi@sitime.com>
+ * Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
+ */
+
+#ifndef _SIT9531X_REGS_H
+#define _SIT9531X_REGS_H
+
+/*
+ * I2C register model:
+ * - Page select register at offset 0xFF, present in every page
+ * - Each page has 256 registers (0x00-0xFF)
+ * - Some pages are paired (e.g. 0x0A/0x1A for PLLA)
+ */
+#define SIT9531X_PAGE_SEL 0xFF
+#define SIT9531X_PAGE_SIZE 0x100
+#define SIT9531X_NUM_PAGES 32
+
+/* Helper macros for page:offset addressing */
+#define SIT9531X_REG(_page, _offset) (((_page) << 8) | (_offset))
+#define SIT9531X_REG_PAGE(_reg) ((_reg) >> 8)
+#define SIT9531X_REG_OFFSET(_reg) ((_reg) & 0xFF)
+
+#define SIT9531X_PAGE_OUTSYS0 0x03
+#define SIT9531X_PAGE_OUTSYS1 0x04
+#define SIT9531X_PAGE_PLLA 0x0A
+#define SIT9531X_PAGE_PLLA_EXT 0x1A
+
+/*
+ * VARIANT_ID is a single byte at page 0 reg 0x02 (95317 = 0x17, 95316 = 0x31).
+ * Reg 0x03 carries an unrelated revision byte and must not be combined into
+ * the variant identifier.
+ */
+#define SIT9531X_REG_VARIANT_ID SIT9531X_REG(0x00, 0x02)
+
+/* DCO trigger pulse timing: minimum 6 ns required by hardware */
+
+/* Page 0 -- PLL inner loop loss-of-lock */
+#define SIT9531X_REG_PLL_INNER_LOL_STATUS SIT9531X_REG(0x00, 0x92)
+#define SIT9531X_REG_PLL_INNER_LOL_NOTIF SIT9531X_REG(0x00, 0x93)
+
+/* Page 0 -- Clock monitor PLL / XO status */
+#define SIT9531X_REG_CMON_NOTIF SIT9531X_REG(0x00, 0x9E)
+
+/* Page 0 -- PLL outer-loop loss-of-lock */
+#define SIT9531X_REG_OUTER_LOL_STATUS SIT9531X_REG(0x00, 0x06)
+#define SIT9531X_REG_OUTER_LOL_NOTIF SIT9531X_REG(0x00, 0x07)
+
+/* Page 0 -- PLL holdover freeze status */
+#define SIT9531X_REG_HO_FREEZE_STATUS SIT9531X_REG(0x00, 0x0A)
+#define SIT9531X_REG_HO_FREEZE_NOTIF SIT9531X_REG(0x00, 0x0B)
+
+/* Page 0 -- INTSYNC (inter-PLL synchronization) global enable */
+#define SIT9531X_REG_INTSYNC_GLOBAL SIT9531X_REG(0x00, 0x40)
+#define SIT9531X_INTSYNC_EN_BIT 6
+
+/*
+ * Priority table: 6 registers per PLL, each holds two priority slots
+ * nibble-packed. The register holding slots 2n and 2n+1 keeps the
+ * earlier slot (CLK_SPARE<2n>SEL_PLL) in [7:4] and the later one in
+ * [3:0].
+ *
+ * Base registers for PLLA: 0x16-0x1B (slots 0-10 plus the
+ * active-reference nibble).
+ * For PLL N: base + 6 * N (e.g. PLLB starts at 0x1C).
+ *
+ * Input source encoding (4-bit value):
+ * 0=IN0P, 1=IN1P, 2=IN2P, 3=IN3P,
+ * 5=OCXO, 6=INTSYNC,
+ * 7=IN0N, 8=IN1N, 9=IN2N, 10=IN3N
+ *
+ * Codes 4 and 11 address a fifth input pair that this part does
+ * not have. They read back as no valid reference.
+ */
+#define SIT9531X_PAGE_PRIOSYS 0x01
+#define SIT9531X_PRIO_BASE_REG 0x16
+#define SIT9531X_PRIO_REGS_PER_PLL 6
+#define SIT9531X_PRIO_SLOTS_PER_REG 2
+/*
+ * 11 priority slots, CLK_SPARE0SEL_PLL through CLK_SPARE10SEL_PLL.
+ * The twelfth nibble of the block is not a slot: it is
+ * CLK_ACTIVESEL_PLL, see SIT9531X_PRIO_ACTIVESEL_OFF below.
+ */
+#define SIT9531X_PRIO_MAX_SLOTS 11
+/* Number of source encodings (0-11), unrelated to the slot count */
+#define SIT9531X_PRIO_NUM_SRC 12
+#define SIT9531X_PRIO_NIBBLE_MASK 0x0F
+#define SIT9531X_PRIO_HI_SHIFT 4
+/* Input source encoding values (see table above) */
+/*
+ * Either of the two codes for the absent fifth pair works as "no source";
+ * the driver writes this one when it empties a slot.
+ */
+#define SIT9531X_PRIO_SRC_NONE 4
+#define SIT9531X_PRIO_SRC_OCXO 5
+#define SIT9531X_PRIO_SRC_INTSYNC 6
+#define SIT9531X_PRIO_SRC_N_BASE 7
+/*
+ * The last register of each PLL's priority block holds, in its low
+ * nibble, the input source the PLL has currently selected as its
+ * active reference (CLK_ACTIVESEL_PLL, same 4-bit encoding as above).
+ */
+#define SIT9531X_PRIO_ACTIVESEL_OFF 5
+
+/*
+ * Page 0 -- PRG_Directives_GENERIC_0, the main system's programming
+ * directive register. Every page carries its own copy of this
+ * register at offset 0x0F with the same bit layout:
+ *
+ * bit 6 proceed to loop lock / active state from the PRG_CMD state
+ * bit 4 update the NVM bank from the efuse contents
+ * bit 3 read the efuse into the volatile registers
+ * bit 2 program the efuse
+ * bit 1 small change update (SIT9531X_SMALL_UPDATE_CMD)
+ * bit 0 escape to the PRG_CMD state
+ *
+ * The NVM bank is a volatile shadow, so bits 4 and 1 are both fine in
+ * a runtime path: bit 1 for a change made in the active state, bit 4
+ * to close a PRG_CMD sequence. Only bit 2 writes non-volatile
+ * storage, and the driver never issues it.
+ */
+#define SIT9531X_REG_GLOBAL_UPDATE SIT9531X_REG(0x00, 0x0F)
+#define SIT9531X_SMALL_UPDATE_CMD 0x02
+
+/* PLL holdover control (PLL page offset) */
+#define SIT9531X_PLL_REG_HO_CTRL 0x6F
+#define SIT9531X_PLL_HO_FORCE_BIT 4
+
+/* One bit per input PAIR (bit 0 = CLKIN0, ..., bit 3 = CLKIN3) */
+#define SIT9531X_REG_IN_DE_FORCE SIT9531X_REG(0x02, 0xE8)
+#define SIT9531X_REG_IN_DE_STATE SIT9531X_REG(0x02, 0xE9)
+#define SIT9531X_REG_IN_SEP_FORCE SIT9531X_REG(0x02, 0xEA)
+#define SIT9531X_REG_IN_SEP_STATE SIT9531X_REG(0x02, 0xEB)
+#define SIT9531X_REG_IN_SEN_FORCE SIT9531X_REG(0x02, 0xF2)
+#define SIT9531X_REG_IN_SEN_STATE SIT9531X_REG(0x02, 0xF3)
+
+/*
+ * One register per input pair at 0x1B + 0x10 * pair
+ * (CLKIN0 = 0x1B, CLKIN1 = 0x2B, CLKIN2 = 0x3B, CLKIN3 = 0x4B).
+ * SE_P_EN/SE_N_EN set means the corresponding lane is configured
+ * single-ended; both clear means the pair runs differential.
+ */
+#define SIT9531X_REG_IN_MODE(_pair) \
+ SIT9531X_REG(0x02, 0x1B + 0x10 * (_pair))
+#define SIT9531X_IN_MODE_SE_P_EN BIT(0)
+#define SIT9531X_IN_MODE_SE_N_EN BIT(1)
+
+/* ---- Page 0x03 (Output System) registers -- Hi-Z control ---- */
+#define SIT9531X_REG_HIZ_DIFF_07_MASK SIT9531X_REG(0x03, 0xF2)
+#define SIT9531X_REG_HIZ_DIFF_07_STATE SIT9531X_REG(0x03, 0xF3)
+#define SIT9531X_REG_HIZ_DIFF_811_MASK SIT9531X_REG(0x03, 0xF4)
+#define SIT9531X_REG_HIZ_DIFF_811_STATE SIT9531X_REG(0x03, 0xF5)
+#define SIT9531X_REG_HIZ_SE_07_MASK SIT9531X_REG(0x03, 0xF8)
+#define SIT9531X_REG_HIZ_SE_07_STATE SIT9531X_REG(0x03, 0xF9)
+#define SIT9531X_REG_HIZ_SE_811_MASK SIT9531X_REG(0x03, 0xFA)
+#define SIT9531X_REG_HIZ_SE_811_STATE SIT9531X_REG(0x03, 0xFB)
+
+/*
+ * Output driver configuration. Either CMOS enable means the output
+ * is wired single-ended -- one lane, or both driven as CMOS; with
+ * neither set it is a differential pair.
+ */
+#define SIT9531X_OUT_MISC0_BASE 0x1E
+#define SIT9531X_OUT_MISC0_STRIDE 0x10
+#define SIT9531X_OUT_CMOS_ENP BIT(3)
+#define SIT9531X_OUT_CMOS_ENN BIT(2)
+
+/*
+ * Output divider registers in Pages 3/4. Each output has a 34-bit
+ * integer divider mapped to 5 bytes (LSB at base reg, MSB at base-4).
+ * Outputs 0-5 are on Page 3, outputs 6-11 are on Page 4.
+ *
+ * The base register for slot N within a page is:
+ * clkout_odr_divn_base[slot] = { 0x14, 0x24, 0x34, 0x44, 0x54, 0x64 }
+ *
+ * Layout: base=LSB, base-1, base-2, base-3, base-4[1:0]=MSB.
+ *
+ * Per-chip clkout_map[] translates output index to slot position.
+ */
+#define SIT9531X_PAGE_OUTSYS0_SLOT_MAX 5 /* slots 0-5 on Page 0x03 */
+
+/* Misc output system registers */
+#define SIT9531X_REG_PRG_DIR_GEN SIT9531X_REG(0x03, 0x0F)
+#define SIT9531X_PRG_CMD_STATE 0x01
+#define SIT9531X_UPDATE_NVM 0x10
+#define SIT9531X_LOOP_LOCK 0x40
+
+/* Debug register (same offset, per-page) */
+#define SIT9531X_REG_OUTSYS_DEBUG SIT9531X_REG(0x03, 0xBD)
+#define SIT9531X_DEBUG_UNLOCK_VAL 0xC3
+#define SIT9531X_DEBUG_LOCK_VAL 0x00
+
+/*
+ * Per-output programmable phase delay: 34-bit coarse (in VCO clock
+ * cycles) plus a 3-bit fine field with fixed 30 ps steps. Each output
+ * has a five-byte block PROG6..PROG2:
+ *
+ * base + 0 PROG6 [7:5] OPSTG_VCASC_BUMP (preserve via RMW)
+ * [4:2] PRG_RST_FINE_DELAY[2:0]
+ * [1:0] PRG_RST_DELAY[33:32]
+ * base + 1 PROG5 [7:0] PRG_RST_DELAY[31:24]
+ * base + 2 PROG4 [7:0] PRG_RST_DELAY[23:16]
+ * base + 3 PROG3 [7:0] PRG_RST_DELAY[15:8]
+ * base + 4 PROG2 [7:0] PRG_RST_DELAY[7:0]
+ *
+ * Slots 0-5 are on Page 3, slots 6-11 on Page 4. The block base
+ * within a page is 0x15 + 16 * (slot % 6), where slot is the physical
+ * output slot from clkout_map[], not the logical output index.
+ */
+#define SIT9531X_OUT_PRG_DELAY_BASE 0x15
+#define SIT9531X_OUT_PRG_SLOT_STRIDE 0x10
+/* bits [7:5], preserve */
+#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] */
+#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
+
+/*
+ * On-demand phase-flush fired from a register rather than a GPIO pin.
+ * DIVO_PHASE_SEL_REG selects the in-register trigger source and
+ * DIVO_PHASE_TRIG flushes the output phase when pulsed high then low.
+ * The unrelated OEb trigger pair in bits [7:6] must be preserved.
+ */
+#define SIT9531X_REG_GPIO_FUNC_CTRL1 SIT9531X_REG(0x00, 0x65)
+#define SIT9531X_DIVO_PHASE_SEL_REG BIT(5)
+#define SIT9531X_DIVO_PHASE_TRIG BIT(4)
+
+/* ---- PLL page registers (apply to pages 0x0A-0x0D) ---- */
+#define SIT9531X_PLL_REG_SMALL_UPDATE 0x0F
+
+/* On-demand phase-flush enable (PLL page reg 0x3D bit 7) */
+#define SIT9531X_PLL_REG_PHFL_CTRL 0x3D
+#define SIT9531X_PLL_PHFL_ON_DEMAND_EN BIT(7)
+
+/*
+ * Loop-filter coefficients on PLL_PAGE regs 0x10-0x15 (3 normal +
+ * 3 fast-lock) are GUI/NVM-generated by the timing configurator and must not be
+ * reprogrammed at runtime; the register map flags them as
+ * "GUI generated configuration should not change manually".
+ */
+
+#define SIT9531X_PLL_REG_OUT_MAP_HI 0x27
+#define SIT9531X_PLL_REG_OUT_MAP_LO 0x28
+#define SIT9531X_PLL_REG_STATUS 0x31
+
+/* DIVN registers (free-run divider readback) */
+#define SIT9531X_PLL_REG_DIVN_INT 0x30
+#define SIT9531X_PLL_REG_DIVN_NUM 0x32 /* 4 bytes (0x32-0x35) */
+#define SIT9531X_PLL_REG_DIVN_DEN 0x38 /* 4 bytes (0x38-0x3B) */
+
+/* Debug register unlock */
+#define SIT9531X_PLL_REG_DEBUG 0xBD
+#define SIT9531X_PLL_DEBUG_UNLOCK 0xC3
+#define SIT9531X_PLL_DEBUG_LOCK 0x00
+
+/*
+ * Signal pathway debug readback -- PLL page. Dig_Sys_ReadCode selects
+ * which point of the pathway is tapped, Dig_Sys_WriteCode carries the
+ * modifiers for that read, Dig_Sys_read7..read0 hold the sampled bytes
+ * and the trigger register latches a sample. The TDC phase
+ * measurement is one tap among several, reached through read code 69.
+ */
+#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 to latch a sample */
+#define SIT9531X_PLL_REG_DBG_TRIGGER 0xD0
+
+/*
+ * Reads of the trigger needed to latch a fresh sample. One returns the
+ * previous latch, which the documented procedures work around by reading it
+ * three times.
+ */
+#define SIT9531X_DBG_LATCH_READS 3
+#define SIT9531X_DBG_DATA_BYTES 8
+
+/* 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)
+
+/*
+ * Read codes of the running DIVN taps. Unlike the configuration
+ * registers these report what the digital loop currently commands, so
+ * they carry the correction the loop applies to track its reference.
+ * The integer part and the numerator share one tap, the denominator
+ * has its own.
+ */
+#define SIT9531X_DBG_READ_CODE_DIVN 0x57
+#define SIT9531X_DBG_READ_CODE_DIVN_DEN 0x56
+#define SIT9531X_DIVN_RT_NUM_BITS 48
+#define SIT9531X_DIVN_RT_INT_HI_BIT BIT(0)
+/* Bit 48 of the denominator tap, which lands in the same byte position */
+#define SIT9531X_DIVN_RT_DEN_HI_BIT BIT(0)
+
+/*
+ * DIVN carried as fixed point, and the unit the DPLL ABI wants the
+ * fractional frequency offset in. Equal in value, distinct in meaning.
+ */
+#define SIT9531X_DIVN_SCALE 1000000000000ULL
+#define SIT9531X_PPT_PER_UNIT 1000000000000ULL
+
+#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)
+
+/*
+ * Per-PLL status register. HO_VALID says the holdover window holds a
+ * valid frequency estimate, i.e. holdover memory has been acquired; it is
+ * not the same as HO_FREEZE (page 0, reg 0x0A), which says the PLL has
+ * already switched over to holdover.
+ */
+#define SIT9531X_PLL_REG_STATUS_1 0x06
+#define SIT9531X_PLL_STATUS_1_HO_VALID BIT(2)
+
+#define SIT9531X_CLKMON_P_NOTIF_01 SIT9531X_REG(0x06, 0x03)
+#define SIT9531X_CLKMON_P_NOTIF_23 SIT9531X_REG(0x06, 0x07)
+
+#define SIT9531X_CLKMON_N_NOTIF_01 SIT9531X_REG(0x06, 0x93)
+#define SIT9531X_CLKMON_N_NOTIF_23 SIT9531X_REG(0x06, 0x97)
+
+/* Per-input bit offsets within clock monitor nibble */
+
+/*
+ * EEPROM profile load, page 0. The device compares the CRC stored in the
+ * EEPROM against the one it computes from what it read; a mismatch means
+ * the profile on the part is not the profile the board expects.
+ * NOTIFY_4 collects the read-done bit and the defect bits, all sticky, so
+ * a healthy load leaves exactly the read-done bit set.
+ */
+/* 4 bytes each, MSB first */
+#define SIT9531X_REG_REC_CRC SIT9531X_REG(0x00, 0x8A)
+#define SIT9531X_REG_CAL_CRC SIT9531X_REG(0x00, 0x8E)
+#define SIT9531X_REG_EEPROM_NOTIF SIT9531X_REG(0x00, 0x97)
+#define SIT9531X_EEPROM_READ_DONE BIT(0)
+
+/* Profile identifier the loaded configuration carries, page 1, 24 bits */
+/* 3 bytes, LSB first */
+#define SIT9531X_REG_PROFILE_ID SIT9531X_REG(0x01, 0x44)
+
+/* Consecutive failed INTRB acknowledgements before the line is given up */
+#define SIT9531X_IRQ_ACK_TRIES 8
+
+/* ---- Variant ID values (one byte at SIT9531X_REG_VARIANT_ID) ---- */
+#define SIT9531X_VARIANT_ID_95317 0x17
+#define SIT9531X_VARIANT_ID_95316 0x31
+
+#endif /* _SIT9531X_REGS_H */
|
| 3/2 | 2026/09/23 20:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 103292 output: 28 thoughts: 767 Thoughts: **Analyzing the SiTime SiT9531x DPLL Driver Patch Series** Okay, so I've got a patch series here, and the user wants my expert evaluation. Let's dive in. First, I'll need to understand what this thing *does*. Looks like it's a new driver for the SiTime SiT9531x DPLL, a programmable clock generator controlled via I2C. The files point to documentation, Kconfig, Makefiles, and the core driver code, all neatly organized within a `drivers/dpll/sit9531x` directory. Standard stuff. But wait a minute... I2C, eh? My immediate thought is, "Reachability!" Can this I2C device actually be instantiated and tested in a standard QEMU environment, or is this going to require special hardware that's not easily accessible for fuzzing? This is key. I've got to follow the core triage philosophy here - reachability is *the* primary gate. Remember those reachability rules? We can't fuzz code that's structurally unreachable. Section 2 of that document is the go-to: vendor-specific PCIe stuff, SmartNICs, GPU drivers – those are a no-go if they need physical hardware. But what about I2C? Does Linux have a way to create I2C devices from userspace or virtual buses? The `/dev/i2c-X` interface with `I2C_SLAVE` and `I2C_SMBUS` ioctls... and what about the `/sys/bus/i2c/devices/i2c-*/new_device`? Can syzkaller, the primary fuzzing tool, even instantiate I2C devices using `/sys/bus/i2c/devices/i2c-*/new_device`? I need to check syzkaller's documentation, or better yet, do a quick grep in the kernel source code. Is I2C considered reachable or unreachable in the context of the fuzzing environment? This could be the determining factor. I'll need to check the tools and resources available to figure this out. |
| 4/2 | 2026/09/23 20:44 | tool | grepper |
0mArgs:{
"Expression": "new_device",
"PathPrefix": "drivers/i2c"
}Results: {
"Output": "drivers/i2c/i2c-core-acpi.c=522=struct notifier_block i2c_acpi_notifier = {\n--\ndrivers/i2c/i2c-core-acpi.c-526-/**\ndrivers/i2c/i2c-core-acpi.c:527: * i2c_acpi_new_device_by_fwnode - Create i2c-client for the Nth I2cSerialBus resource\ndrivers/i2c/i2c-core-acpi.c-528- * @fwnode: fwnode with the ACPI resources to get the client from\n--\ndrivers/i2c/i2c-core-acpi.c-543- */\ndrivers/i2c/i2c-core-acpi.c:544:struct i2c_client *i2c_acpi_new_device_by_fwnode(struct fwnode_handle *fwnode,\ndrivers/i2c/i2c-core-acpi.c-545-\t\t\t\t\t\t int index,\n--\ndrivers/i2c/i2c-core-acpi.c-578-}\ndrivers/i2c/i2c-core-acpi.c:579:EXPORT_SYMBOL_GPL(i2c_acpi_new_device_by_fwnode);\ndrivers/i2c/i2c-core-acpi.c-580-\n--\ndrivers/i2c/i2c-core-base.c=1264=static ssize_t\ndrivers/i2c/i2c-core-base.c:1265:new_device_store(struct device *dev, struct device_attribute *attr,\ndrivers/i2c/i2c-core-base.c-1266-\t\t const char *buf, size_t count)\n--\ndrivers/i2c/i2c-core-base.c-1277-\tif (!blank) {\ndrivers/i2c/i2c-core-base.c:1278:\t\tdev_err(dev, \"%s: Missing parameters\\n\", \"new_device\");\ndrivers/i2c/i2c-core-base.c-1279-\t\treturn -EINVAL;\n--\ndrivers/i2c/i2c-core-base.c-1281-\tif (blank - buf \u003e I2C_NAME_SIZE - 1) {\ndrivers/i2c/i2c-core-base.c:1282:\t\tdev_err(dev, \"%s: Invalid device name\\n\", \"new_device\");\ndrivers/i2c/i2c-core-base.c-1283-\t\treturn -EINVAL;\n--\ndrivers/i2c/i2c-core-base.c-1289-\tif (res \u003c 1) {\ndrivers/i2c/i2c-core-base.c:1290:\t\tdev_err(dev, \"%s: Can't parse I2C address\\n\", \"new_device\");\ndrivers/i2c/i2c-core-base.c-1291-\t\treturn -EINVAL;\n--\ndrivers/i2c/i2c-core-base.c-1293-\tif (res \u003e 1 \u0026\u0026 end != '\\n') {\ndrivers/i2c/i2c-core-base.c:1294:\t\tdev_err(dev, \"%s: Extra parameters\\n\", \"new_device\");\ndrivers/i2c/i2c-core-base.c-1295-\t\treturn -EINVAL;\n--\ndrivers/i2c/i2c-core-base.c-1315-\tmutex_unlock(\u0026adap-\u003euserspace_clients_lock);\ndrivers/i2c/i2c-core-base.c:1316:\tdev_info(dev, \"%s: Instantiated device %s at 0x%02hx\\n\", \"new_device\",\ndrivers/i2c/i2c-core-base.c-1317-\t\t info.type, info.addr);\n--\ndrivers/i2c/i2c-core-base.c-1320-}\ndrivers/i2c/i2c-core-base.c:1321:static DEVICE_ATTR_WO(new_device);\ndrivers/i2c/i2c-core-base.c-1322-\n--\ndrivers/i2c/i2c-core-base.c-1325- * they got it wrong. This interface can only be used to delete devices\ndrivers/i2c/i2c-core-base.c:1326: * instantiated by i2c_sysfs_new_device above. This guarantees that we\ndrivers/i2c/i2c-core-base.c-1327- * don't delete devices to which some kernel code still has references.\n--\ndrivers/i2c/i2c-core-base.c=1379=static struct attribute *i2c_adapter_attrs[] = {\ndrivers/i2c/i2c-core-base.c-1380-\t\u0026dev_attr_name.attr,\ndrivers/i2c/i2c-core-base.c:1381:\t\u0026dev_attr_new_device.attr,\ndrivers/i2c/i2c-core-base.c-1382-\t\u0026dev_attr_delete_device.attr,\n--\ndrivers/i2c/i2c-core-base.c=1804=void i2c_del_adapter(struct i2c_adapter *adap)\n--\ndrivers/i2c/i2c-core-base.c-1822-\t */\ndrivers/i2c/i2c-core-base.c:1823:\tdevice_remove_file(\u0026adap-\u003edev, \u0026dev_attr_new_device);\ndrivers/i2c/i2c-core-base.c-1824-\n"
} |
| 5/2 | 2026/09/23 20:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 106038 output: 44 thoughts: 360 Thoughts: **Analyzing the Device Driver Matching**
Okay, let's see how this `sit9531x_i2c_driver` is actually matched and instantiated. Time to dig into the driver code itself. Looking at the definition, it seems pretty straightforward:
```c
static const struct of_device_id sit9531x_of_match[] = {
{ .compatible = "sitime,sit95316" },
{ .compatible = "sitime,sit95317" },
{ }
};
MODULE_DEVICE_TABLE(of, sit9531x_of_match);
static struct i2c_driver sit9531x_i2c_driver = {
.driver = {
.name = "sit9531x",
.of_match_table = sit9531x_of_match,
.pm = pm_sleep_ptr(&sit9531x_pm_ops),
},
.probe = sit9531x_i2c_probe,
};
```
Aha! The driver is using an `of_match_table`. This tells us that the device matching relies on the device tree's "compatible" strings. It looks for either "sitime,sit95316" or "sitime,sit95317". Makes sense, so far.
Wait a second, does this driver define an `id_table`? That would be similar to `static const struct i2c_device_id sit9531x_id[]`. Nope, it doesn't. So the driver *only* uses the device tree for matching. Good to know.
Okay, let's get back to what values we can write to `new_device`. I will check `i2c-core-base.c` and specifically `new_device_store`.
|
| 6/2 | 2026/09/23 20:44 | tool | read-file |
0mArgs:{
"File": "drivers/i2c/i2c-core-base.c",
"FirstLine": 1260,
"LineCount": 60
}Results: {
"Contents": "1260:\t *\n1261:\t * Parameter checking may look overzealous, but we really don't want\n1262:\t * the user to provide incorrect parameters.\n1263:\t */\n1264:\tstatic ssize_t\n1265:\tnew_device_store(struct device *dev, struct device_attribute *attr,\n1266:\t\t\t const char *buf, size_t count)\n1267:\t{\n1268:\t\tstruct i2c_adapter *adap = to_i2c_adapter(dev);\n1269:\t\tstruct i2c_board_info info;\n1270:\t\tstruct i2c_client *client;\n1271:\t\tchar *blank, end;\n1272:\t\tint res;\n1273:\t\n1274:\t\tmemset(\u0026info, 0, sizeof(struct i2c_board_info));\n1275:\t\n1276:\t\tblank = strchr(buf, ' ');\n1277:\t\tif (!blank) {\n1278:\t\t\tdev_err(dev, \"%s: Missing parameters\\n\", \"new_device\");\n1279:\t\t\treturn -EINVAL;\n1280:\t\t}\n1281:\t\tif (blank - buf \u003e I2C_NAME_SIZE - 1) {\n1282:\t\t\tdev_err(dev, \"%s: Invalid device name\\n\", \"new_device\");\n1283:\t\t\treturn -EINVAL;\n1284:\t\t}\n1285:\t\tmemcpy(info.type, buf, blank - buf);\n1286:\t\n1287:\t\t/* Parse remaining parameters, reject extra parameters */\n1288:\t\tres = sscanf(++blank, \"%hi%c\", \u0026info.addr, \u0026end);\n1289:\t\tif (res \u003c 1) {\n1290:\t\t\tdev_err(dev, \"%s: Can't parse I2C address\\n\", \"new_device\");\n1291:\t\t\treturn -EINVAL;\n1292:\t\t}\n1293:\t\tif (res \u003e 1 \u0026\u0026 end != '\\n') {\n1294:\t\t\tdev_err(dev, \"%s: Extra parameters\\n\", \"new_device\");\n1295:\t\t\treturn -EINVAL;\n1296:\t\t}\n1297:\t\n1298:\t\tif ((info.addr \u0026 I2C_ADDR_OFFSET_TEN_BIT) == I2C_ADDR_OFFSET_TEN_BIT) {\n1299:\t\t\tinfo.addr \u0026= ~I2C_ADDR_OFFSET_TEN_BIT;\n1300:\t\t\tinfo.flags |= I2C_CLIENT_TEN;\n1301:\t\t}\n1302:\t\n1303:\t\tif (info.addr \u0026 I2C_ADDR_OFFSET_SLAVE) {\n1304:\t\t\tinfo.addr \u0026= ~I2C_ADDR_OFFSET_SLAVE;\n1305:\t\t\tinfo.flags |= I2C_CLIENT_SLAVE;\n1306:\t\t}\n1307:\t\n1308:\t\tclient = i2c_new_client_device(adap, \u0026info);\n1309:\t\tif (IS_ERR(client))\n1310:\t\t\treturn PTR_ERR(client);\n1311:\t\n1312:\t\t/* Keep track of the added device */\n1313:\t\tmutex_lock(\u0026adap-\u003euserspace_clients_lock);\n1314:\t\tlist_add_tail(\u0026client-\u003edetected, \u0026adap-\u003euserspace_clients);\n1315:\t\tmutex_unlock(\u0026adap-\u003euserspace_clients_lock);\n1316:\t\tdev_info(dev, \"%s: Instantiated device %s at 0x%02hx\\n\", \"new_device\",\n1317:\t\t\t info.type, info.addr);\n1318:\t\n1319:\t\treturn count;\n"
} |
| 7/2 | 2026/09/23 20:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 107870 output: 32 thoughts: 49 Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person: **Decoding I2C Driver Matching Without the ID Table** Right, let's take a look at this `info.type` and understand exactly what's going on. My immediate question is: how does `i2c_match_id` handle the identification of an `i2c_client` when there *isn't* a traditional `id_table` involved? We often rely on those tables, but I know there are alternative matching mechanisms. It's time to dive into the core of how I2C driver matching really functions. I want to trace the code path and understand the logic that's executed when we're *not* using an explicit ID table. There's got to be some other criteria the system is using to determine if a driver is a good fit for this client. Let's dig in and figure out the exact matching process being used in this situation! |
| 8/2 | 2026/09/23 20:44 | tool | grepper |
0mArgs:{
"Expression": "i2c_device_match",
"PathPrefix": "drivers/i2c"
}Results: {
"Output": "drivers/i2c/i2c-core-base.c=138=EXPORT_SYMBOL(i2c_get_match_data);\ndrivers/i2c/i2c-core-base.c-139-\ndrivers/i2c/i2c-core-base.c:140:static int i2c_device_match(struct device *dev, const struct device_driver *drv)\ndrivers/i2c/i2c-core-base.c-141-{\n--\ndrivers/i2c/i2c-core-base.c=700=const struct bus_type i2c_bus_type = {\ndrivers/i2c/i2c-core-base.c-701-\t.name\t\t= \"i2c\",\ndrivers/i2c/i2c-core-base.c:702:\t.match\t\t= i2c_device_match,\ndrivers/i2c/i2c-core-base.c-703-\t.probe\t\t= i2c_device_probe,\n"
} |
| 9/2 | 2026/09/23 20:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 108434 output: 43 thoughts: 13 Thoughts: Okay, let's dive into this `i2c_device_match` function. I see it's important for identifying devices on the I2C bus, a pretty fundamental part of embedded systems design. I'm going to quickly skim the function's structure. Understanding how it determines whether a driver can claim a device is critical for writing robust and conflict-free drivers. This is where the core of device probing often lives, so I'm keen to dissect its logic. I need to see how it handles different device IDs, how it interacts with the driver's ID table, and if there are any vendor-specific nuances I should note. Let's get to it. |
| 10/2 | 2026/09/23 20:44 | tool | read-file |
0mArgs:{
"File": "drivers/i2c/i2c-core-base.c",
"FirstLine": 140,
"LineCount": 40
}Results: {
"Contents": " 140:\tstatic int i2c_device_match(struct device *dev, const struct device_driver *drv)\n 141:\t{\n 142:\t\tstruct i2c_client\t*client = i2c_verify_client(dev);\n 143:\t\tconst struct i2c_driver\t*driver;\n 144:\t\n 145:\t\n 146:\t\t/* Attempt an OF style match */\n 147:\t\tif (i2c_of_match_device(drv-\u003eof_match_table, client))\n 148:\t\t\treturn 1;\n 149:\t\n 150:\t\t/* Then ACPI style match */\n 151:\t\tif (acpi_driver_match_device(dev, drv))\n 152:\t\t\treturn 1;\n 153:\t\n 154:\t\tdriver = to_i2c_driver(drv);\n 155:\t\n 156:\t\t/* Finally an I2C match */\n 157:\t\tif (i2c_match_id(driver-\u003eid_table, client))\n 158:\t\t\treturn 1;\n 159:\t\n 160:\t\treturn 0;\n 161:\t}\n 162:\t\n 163:\tstatic int i2c_device_uevent(const struct device *dev, struct kobj_uevent_env *env)\n 164:\t{\n 165:\t\tconst struct i2c_client *client = to_i2c_client(dev);\n 166:\t\tint rc;\n 167:\t\n 168:\t\trc = of_device_uevent_modalias(dev, env);\n 169:\t\tif (rc != -ENODEV)\n 170:\t\t\treturn rc;\n 171:\t\n 172:\t\trc = acpi_device_uevent_modalias(dev, env);\n 173:\t\tif (rc != -ENODEV)\n 174:\t\t\treturn rc;\n 175:\t\n 176:\t\treturn add_uevent_var(env, \"MODALIAS=%s%s\", I2C_MODULE_PREFIX, client-\u003ename);\n 177:\t}\n 178:\t\n 179:\t/* i2c bus recovery routines */\n"
} |
| 11/2 | 2026/09/23 20:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 109236 output: 34 thoughts: 28 Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, geared toward an expert audience, and in the first person: **Diving into i2c_of_match_device** Alright, let's dissect `i2c_of_match_device`. I want to understand exactly how the I2C bus interacts with the device tree. I need to make sure I am fully comprehending the interaction between the device and the bus, and ensure my own work is following standard methodology. This likely involves how the driver binds to a specific I2C device described in the device tree. I'm especially interested in the matching process itself. What criteria are being used? Is it based on compatible strings, reg properties, or something else entirely? What happens if multiple matches are found, or if no match is found? I need to review the code to ensure I haven't missed any edge cases and that I have addressed any potential issues that may occur. This inspection needs to give me confidence in my analysis. |
| 12/2 | 2026/09/23 20:44 | tool | grepper |
0mArgs:{
"Expression": "i2c_of_match_device",
"PathPrefix": "drivers/i2c"
}Results: {
"Output": "drivers/i2c/i2c-core-base.c=140=static int i2c_device_match(struct device *dev, const struct device_driver *drv)\n--\ndrivers/i2c/i2c-core-base.c-146-\t/* Attempt an OF style match */\ndrivers/i2c/i2c-core-base.c:147:\tif (i2c_of_match_device(drv-\u003eof_match_table, client))\ndrivers/i2c/i2c-core-base.c-148-\t\treturn 1;\n--\ndrivers/i2c/i2c-core-base.c=492=static int i2c_device_probe(struct device *dev)\n--\ndrivers/i2c/i2c-core-base.c-542-\t !acpi_driver_match_device(dev, dev-\u003edriver) \u0026\u0026\ndrivers/i2c/i2c-core-base.c:543:\t !i2c_of_match_device(dev-\u003edriver-\u003eof_match_table, client)) {\ndrivers/i2c/i2c-core-base.c-544-\t\tstatus = -ENODEV;\n--\ndrivers/i2c/i2c-core-of.c=115=static const struct of_device_id*\ndrivers/i2c/i2c-core-of.c:116:i2c_of_match_device_sysfs(const struct of_device_id *matches,\ndrivers/i2c/i2c-core-of.c-117-\t\t\t\t struct i2c_client *client)\n--\ndrivers/i2c/i2c-core-of.c=144=const struct of_device_id\ndrivers/i2c/i2c-core-of.c:145:*i2c_of_match_device(const struct of_device_id *matches,\ndrivers/i2c/i2c-core-of.c-146-\t\t struct i2c_client *client)\n--\ndrivers/i2c/i2c-core-of.c-156-\ndrivers/i2c/i2c-core-of.c:157:\treturn i2c_of_match_device_sysfs(matches, client);\ndrivers/i2c/i2c-core-of.c-158-}\n--\ndrivers/i2c/i2c-core.h=87=void of_i2c_register_devices(struct i2c_adapter *adap);\ndrivers/i2c/i2c-core.h:88:const struct of_device_id *i2c_of_match_device(const struct of_device_id *matches,\ndrivers/i2c/i2c-core.h-89-\t\t\t\t\t struct i2c_client *client);\n--\ndrivers/i2c/i2c-core.h=93=static inline\ndrivers/i2c/i2c-core.h:94:const struct of_device_id *i2c_of_match_device(const struct of_device_id *matches,\ndrivers/i2c/i2c-core.h-95-\t\t\t\t\t struct i2c_client *client)\n"
} |
| 13/2 | 2026/09/23 20:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 110332 output: 43 thoughts: 40 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Diving into the Device Matching Logic** Right, so the trace of the problem has led me to `i2c-core-of.c` and, more specifically, line 115: `i2c_of_match_device_sysfs`. I'm going to pull up that function. I *know* this area; OF matching is fundamental for I2C device instantiation on these systems. My spidey-sense is telling me the issue is probably in the device matching or driver binding phase given the context, let's see where the system is failing. I need to understand exactly how the system is correlating the device tree information with the driver probe. Let's start with the code. I expect I will see the usual suspects: properties being compared, maybe some quirk handling, and hopefully a clear path through the match table. No surprises yet, let's keep digging and start to develop a hypothesis. |
| 14/2 | 2026/09/23 20:44 | tool | read-file |
0mArgs:{
"File": "drivers/i2c/i2c-core-of.c",
"FirstLine": 115,
"LineCount": 45
}Results: {
"Contents": " 115:\tstatic const struct of_device_id*\n 116:\ti2c_of_match_device_sysfs(const struct of_device_id *matches,\n 117:\t\t\t\t\t struct i2c_client *client)\n 118:\t{\n 119:\t\tconst char *name;\n 120:\t\n 121:\t\tfor (; matches-\u003ecompatible[0]; matches++) {\n 122:\t\t\t/*\n 123:\t\t\t * Adding devices through the i2c sysfs interface provides us\n 124:\t\t\t * a string to match which may be compatible with the device\n 125:\t\t\t * tree compatible strings, however with no actual of_node the\n 126:\t\t\t * of_match_device() will not match\n 127:\t\t\t */\n 128:\t\t\tif (sysfs_streq(client-\u003ename, matches-\u003ecompatible))\n 129:\t\t\t\treturn matches;\n 130:\t\n 131:\t\t\tname = strchr(matches-\u003ecompatible, ',');\n 132:\t\t\tif (!name)\n 133:\t\t\t\tname = matches-\u003ecompatible;\n 134:\t\t\telse\n 135:\t\t\t\tname++;\n 136:\t\n 137:\t\t\tif (sysfs_streq(client-\u003ename, name))\n 138:\t\t\t\treturn matches;\n 139:\t\t}\n 140:\t\n 141:\t\treturn NULL;\n 142:\t}\n 143:\t\n 144:\tconst struct of_device_id\n 145:\t*i2c_of_match_device(const struct of_device_id *matches,\n 146:\t\t\t struct i2c_client *client)\n 147:\t{\n 148:\t\tconst struct of_device_id *match;\n 149:\t\n 150:\t\tif (!(client \u0026\u0026 matches))\n 151:\t\t\treturn NULL;\n 152:\t\n 153:\t\tmatch = of_match_device(matches, \u0026client-\u003edev);\n 154:\t\tif (match)\n 155:\t\t\treturn match;\n 156:\t\n 157:\t\treturn i2c_of_match_device_sysfs(matches, client);\n 158:\t}\n 159:\t\n"
} |
| 15/2 | 2026/09/23 20:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 111236 output: 23 thoughts: 2547 Thoughts: **Analysis of the SiTime SiT9531x Driver and Fuzzing Potential** Okay, so here's the deal. I'm looking at this new `sit9531x` driver, and I need to figure out if it's fuzzable in our standard environments. First, the `i2c_of_match_device_sysfs` function seems to be how the driver gets loaded, meaning I can potentially create the device with `/sys/bus/i2c/devices/i2c-X/new_device`. But can syzkaller or QEMU actually trigger this? Let's dig into `sit9531x_dev_probe` in `drivers/dpll/sit9531x/core.c`. Right away, the probe function is looking for an "xtal" clock or a "clock-frequency" property. Specifically, it's getting the crystal frequency which is crucial to the chip's operation, it tries to get this using `devm_clk_get_optional_enabled(sitdev->dev, "xtal")` or failing that, reads the "clock-frequency" device property. If this fails, then it calls `dev_err_probe` with an error. If instantiated via sysfs `new_device`, `sitdev->dev` has NO device properties or clock named "xtal"! This means that the attempt to get the crystal frequency will fail! Okay, so I understand the problem. The chip needs a crystal clock rate, and that's usually provided via the device tree or a property. With a sysfs-created I2C client, *there's no device tree!* The driver's going to fail right there, returning `-EINVAL`. The failure is immediate, because the probe immediately fails if the device doesn't have the `xtal` clock or `clock-frequency`. Even *before* we get to the crystal frequency, the driver tries to read a `variant_id`. However, that read uses `regmap_read`, which implies an actual I2C transaction. On an emulated I2C bus (like the one in QEMU), there's no physical SiTime chip at I2C address 0x68 to respond, therefore, it will fail. This probe will then fail with an error! And even if we somehow get past that, it's still going to fail because the driver is expecting a *specific* `variant_id`. It has to be either 0x17 or 0x31 to match. So, the probe is doomed from the start. Can QEMU even *emulate* the SiT95316? No, it doesn't. And even on ARM with a device tree, the standard QEMU "virt" machine doesn't include this chip. And even with ACPI or DT overlays or sysfs: even if you could add it, syzkaller *probably* doesn't create device tree overlays or sysfs I2C devices automatically. I'd have to check syzkaller's documentation on this. But I don't see anything obvious using our tools. Let's quickly review the triage philosophy, specifically, it says: "REACHABILITY IS THE PRIMARY GATE. If the modified code is structurally unreachable, it MUST NOT be fuzzed." The triage then describes scenarios when a piece of code is reachable, and when it is not. According to the triage, this driver isn't reachable because it's a "structurally unreachable hardware". Now, let's look at the patch itself. It's just adding a new driver in `drivers/dpll/sit9531x/`. The *core* DPLL subsystem hasn't been touched. This driver is for a *physical* I2C chip (SiTime SiT95316 or SiT95317). It needs real hardware to work. And because the target architecture is amd64, there is no emulation for this device in QEMU. In summary, the driver is going to fail to probe, *immediately*. It requires a physical chip that's not emulated, and it expects a crystal frequency through device tree properties, or the probe will fail. There is no such physical device, and in a standard virtualized environment, it's simply unreachable and it is not fuzzable. Time to categorize it as `WorthFuzzing=false`. Let's check other DPLL drivers or I2C clock chips in the kernel to see how they are categorized. |
| 16/2 | 2026/09/23 20:44 | tool | codesearch-dir-index |
0mArgs:{
"Dir": "drivers/dpll"
}Results: {
"Files": [
"dpll_core.c",
"dpll_core.h",
"dpll_netlink.c",
"dpll_netlink.h",
"dpll_nl.c",
"dpll_nl.h"
],
"Subdirs": [
"sit9531x",
"zl3073x"
]
} |
| 17/2 | 2026/09/23 20:44 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 114886 output: 41 thoughts: 78 Thoughts: Here's my thought process, as requested: **Navigating the Digital Landscape of Clock Generation** Okay, let's dive into this `drivers/dpll/zl3073x/` directory. What's the context here? Ah, it's about the ZL3073x! Right, that's a Microchip DPLL driver, dealing with SPI or I2C clock generation and synchronization. Good, good. That clarifies the hardware interaction. Now, the next logical step is to understand the configuration options, so let's examine the `drivers/dpll/zl3073x/Kconfig` file. I need to see what knobs and dials are available for configuring this specific DPLL implementation within the broader system. |
| 18/2 | 2026/09/23 20:45 | tool | read-file |
0mArgs:{
"File": "drivers/dpll/zl3073x/Kconfig",
"FirstLine": 1,
"LineCount": 20
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t\n 3:\tconfig ZL3073X\n 4:\t\ttristate \"Microchip Azurite DPLL/PTP/SyncE devices\" if COMPILE_TEST\n 5:\t\tdepends on NET \u0026\u0026 PTP_1588_CLOCK\n 6:\t\tselect DPLL\n 7:\t\tselect NET_DEVLINK\n 8:\t\tselect REGMAP\n 9:\t\thelp\n 10:\t\t This driver supports Microchip Azurite family DPLL/PTP/SyncE\n 11:\t\t devices that support up to 5 independent DPLL channels,\n 12:\t\t 10 input pins and up to 20 output pins.\n 13:\t\n 14:\t\t To compile this driver as a module, choose M here. The module\n 15:\t\t will be called zl3073x.\n 16:\t\n 17:\tconfig ZL3073X_I2C\n 18:\t\ttristate \"I2C bus implementation for Microchip Azurite devices\"\n 19:\t\tdepends on I2C \u0026\u0026 NET \u0026\u0026 PTP_1588_CLOCK\n 20:\t\tselect REGMAP_I2C\n"
} |
| 19/2 | 2026/09/23 20:45 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 115492 output: 141 thoughts: 554 Thoughts: **Fuzzing Triage: Negative Evaluation** Okay, so I've taken a look at this patch. It concerns the `ZL3073X` and `SIT9531X_DPLL` drivers, both of which are for discrete, external DPLL/clock hardware chips that communicate over I2C/SPI buses. The crucial point here is that neither of these chips are emulated within standard QEMU or GCE virtualized environments – the very environments we use for fuzzing. I've re-read the triage rules, and I'm focusing on two key sections: "Reachability is the Primary Gate" and "When to Return WorthFuzzing=false." The rules are clear: if the code we're evaluating is *structurally unreachable* in the standard fuzzing environment, we *must not* attempt to fuzz it. This holds regardless of whether the code includes assertions or complicated logic. Considering this, I've broken down the patch. The modifications are: 1. Documentation and MAINTAINERS updates, which are non-kernel and documentation. 2. Kconfig and Makefile additions. 3. The most important part: the new `drivers/dpll/sit9531x/*` driver for the SiTime SiT95316 and SiT95317 I2C-controlled DPLL clock generator chips. My analysis is that the `sit9531x` driver, critically, *requires* the physical hardware. The driver's probe function needs to directly interact with hardware registers (like `sit9531x_read_variant_id`) and read device-tree or firmware clock properties (such as `xtal` clock or `clock-frequency`). This simply cannot succeed in a virtualized environment without that physical hardware present. Therefore, the entirety of the modified code is, for the purposes of fuzzing, structurally unreachable. My conclusion is that `WorthFuzzing` should be `false`. Accordingly, `EnableConfigs` and `FocusSymbols` will be an empty array (or null). I'll provide a concise reasoning explaining the patch introduces a driver for the SiTime SiT95316/SiT95317 I2C DPLL clock generators requiring physical ASIC hardware not emulated in standard QEMU/GCE environments, rendering the code structurally unreachable for syzkaller fuzzing. Time to call `set-results` with these values. |
| 20/2 | 2026/09/23 20:46 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch adds a new device driver for the SiTime SiT95316 and SiT95317 I2C-controlled DPLL clock generator chips (drivers/dpll/sit9531x/). This hardware requires physical discrete ASICs communicating over I2C with specific clock inputs, which are not emulated in standard QEMU or GCE virtualized fuzzing environments. As such, the driver cannot successfully probe or execute in standard syzkaller environments, making the modified code structurally unreachable.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch adds a new device driver for the SiTime SiT95316 and SiT95317 I2C-controlled DPLL clock generator chips (drivers/dpll/sit9531x/). This hardware requires physical discrete ASICs communicating over I2C with specific clock inputs, which are not emulated in standard QEMU or GCE virtualized fuzzing environments. As such, the driver cannot successfully probe or execute in standard syzkaller environments, making the modified code structurally unreachable.",
"WorthFuzzing": false
} |
| 21/1 | 2026/09/23 20:46 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|