Devicetree
 help / color / mirror / Atom feed
From: Ali Rouhi <arouhi@sitime.com>
To: "jiri@resnulli.us" <jiri@resnulli.us>
Cc: "ivecera@redhat.com" <ivecera@redhat.com>,
	"vadim.fedorenko@linux.dev" <vadim.fedorenko@linux.dev>,
	"arkadiusz.kubalewski@intel.com" <arkadiusz.kubalewski@intel.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"robh@kernel.org" <robh@kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"prabhakar.mahadev-lad.rj@bp.renesas.com"
	<prabhakar.mahadev-lad.rj@bp.renesas.com>,
	"cjubran@nvidia.com" <cjubran@nvidia.com>,
	"Oleg.Zadorozhnyi@devoxsoftware.com"
	<Oleg.Zadorozhnyi@devoxsoftware.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH net-next v17 10/13] dpll: sit9531x: implement output pin state on a DPLL
Date: Tue, 1 Dec 2026 23:52:07 +0000	[thread overview]
Message-ID: <20261201235202.97645-11-arouhi@sitime.com> (raw)
In-Reply-To: <20261201235202.97645-1-arouhi@sitime.com>

From: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>

An output's state says whether it carries a signal: CONNECTED while it
drives, DISCONNECTED while muted. Setting it forces the output's pads to
Hi-Z, which leaves the divider running. Output pins are registered from
this patch on.

A mute forces the slot's three Hi-Z pairs, differential, CMOS OutP and
CMOS OutN, with the Page 3 debug window open; the force registers are
outside the NVM, so no programming directive is written. Probe records
the override the loaded configuration sets on each pair, and an unmute
writes that record back, so a pad the configuration forces stays forced.
An output is reported muted only when both pads are forced off. A rebind
takes the force registers as found: a pair forced on an output found
muted is taken as the mute, also one an earlier binding set, so an
unmute drives every pad.

The programming state of the previous patch now has one exit, which
locks the output loops and closes the output-system debug key. A lock or
a close that did not take effect is retried by the poll and at removal.

Signed-off-by: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
Co-developed-by: Ali Rouhi <arouhi@sitime.com>
Signed-off-by: Ali Rouhi <arouhi@sitime.com>
---
 drivers/dpll/sit9531x/core.c | 369 ++++++++++++++++++++++++++++-------
 drivers/dpll/sit9531x/core.h |  25 ++-
 drivers/dpll/sit9531x/dpll.c | 153 ++++++++++++++-
 3 files changed, 467 insertions(+), 80 deletions(-)

diff --git a/drivers/dpll/sit9531x/core.c b/drivers/dpll/sit9531x/core.c
index bce58b337113..3316e3761e16 100644
--- a/drivers/dpll/sit9531x/core.c
+++ b/drivers/dpll/sit9531x/core.c
@@ -335,8 +335,9 @@ int sit9531x_input_enable(struct sit9531x_dev *sitdev, u8 index)
 /*
  * Output Hi-Z control: each slot has three force/state pairs on Page 0x03,
  * for the differential path and the CMOS OutP and OutN pads. The tri-state
- * buffers sit after the output driver, independent of the pad selection.
- * ODRn_MISC0 bits 3:2 distinguish a CMOS output from a differential one.
+ * buffers sit after the output driver, independent of the pad selection, and
+ * a mute writes all three. ODRn_MISC0 bits 3:2 distinguish a CMOS output from
+ * a differential one.
  *
  *   slot 0-7 :
  *     DIFF 0xF2/0xF3   CMOS OutP 0xF8/0xF9   CMOS OutN 0xF6/0xF7
@@ -439,14 +440,16 @@ static int sit9531x_hiz_pair_forced(struct sit9531x_dev *sitdev,
 static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,
 				      u8 out_idx, bool *muted, bool *part)
 {
+	const struct sit9531x_out *out = &sitdev->out[out_idx];
 	struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS];
 	bool pad_p, pad_n;
+	u8 keep;
 	int rc;
 
 	sit9531x_output_get_hiz_regs(sitdev->info->clkout_map[out_idx], p);
 
 	*part = false;
-	if (!sitdev->out[out_idx].cmos)
+	if (!out->cmos)
 		return sit9531x_hiz_pair_forced(sitdev,
 						&p[SIT9531X_HIZ_DIFF], muted);
 
@@ -457,44 +460,91 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,
 	if (rc)
 		return rc;
 
+	/* A pad the loaded configuration forces is not a part mute */
+	keep = out->hiz_mask & ~out->hiz_state;
 	*muted = pad_p && pad_n;
-	*part = pad_p != pad_n;
+	*part = pad_p != pad_n &&
+		!(keep & BIT(pad_p ? SIT9531X_HIZ_CMOS_P :
+				     SIT9531X_HIZ_CMOS_N));
 
 	return 0;
 }
 
-#define SIT9531X_LOOP_LOCK_TRIES	3
+/* Re-read an output's mute state. Caller must hold sitdev->multiop_lock. */
+int sit9531x_output_state_refresh(struct sit9531x_dev *sitdev, u8 out_idx)
+{
+	bool muted, part;
+	int rc;
+
+	lockdep_assert_held(&sitdev->multiop_lock);
+
+	rc = sit9531x_output_forced_hiz(sitdev, out_idx, &muted, &part);
+	if (rc)
+		return rc;
+
+	sitdev->out[out_idx].enabled = !muted;
+	sitdev->out[out_idx].part_muted = part;
+	sitdev->out[out_idx].state_stale = false;
+
+	return 0;
+}
 
-/* Close the loops and lock the debug block without committing */
-static void sit9531x_prg_abort(struct sit9531x_dev *sitdev)
+static int sit9531x_hiz_set_bit(struct sit9531x_dev *sitdev,
+				unsigned int reg, u8 bit, bool set)
 {
-	int rc = -EIO;
-	u8 attempt;
+	u8 cur, new_val;
+	int rc;
 
-	for (attempt = 0; attempt < SIT9531X_LOOP_LOCK_TRIES; attempt++) {
-		rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
-				       SIT9531X_LOOP_LOCK);
-		if (!rc)
-			break;
-		usleep_range(1000, 2000);
-	}
+	rc = sit9531x_read_u8(sitdev, reg, &cur);
 	if (rc)
-		dev_err(sitdev->dev,
-			"output loops left unlocked after a failed entry: %d\n",
-			rc);
+		return rc;
 
-	sitdev->loops_open = !!rc;
-	sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
-			  SIT9531X_DEBUG_LOCK_VAL);
+	new_val = set ? (cur | BIT(bit)) : (cur & ~BIT(bit));
+
+	return sit9531x_write_u8(sitdev, reg, new_val);
+}
+
+/*
+ * The Page 3 debug key opens every debug register of the output system while
+ * it holds the unlock value.
+ */
+static int sit9531x_outsys_debug_open(struct sit9531x_dev *sitdev)
+{
+	int rc, lock_rc;
+
+	rc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
+			       SIT9531X_DEBUG_UNLOCK_VAL);
+	if (rc) {
+		lock_rc = sit9531x_write_close(sitdev,
+					       SIT9531X_REG_OUTSYS_DEBUG,
+					       SIT9531X_DEBUG_LOCK_VAL);
+		sitdev->outsys_key_pending = !!lock_rc;
+	}
+
+	return rc;
+}
+
+static void sit9531x_outsys_debug_close(struct sit9531x_dev *sitdev)
+{
+	int rc;
+
+	rc = sit9531x_write_close(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
+				  SIT9531X_DEBUG_LOCK_VAL);
+	sitdev->outsys_key_pending = !!rc;
+	if (rc)
+		dev_warn(sitdev->dev, "output debug block left unlocked: %d\n",
+			 rc);
 }
 
+#define SIT9531X_LOOP_LOCK_TRIES	3
+
 /*
  * Leave PRG_CMD: re-lock the loops and close the debug window. The sleep is
  * the settling time after loop lock.
  */
 static int sit9531x_prg_relock(struct sit9531x_dev *sitdev)
 {
-	int rc = 0, close_rc;
+	int rc = 0;
 	u8 attempt;
 
 	for (attempt = 0; attempt < SIT9531X_LOOP_LOCK_TRIES; attempt++) {
@@ -513,16 +563,7 @@ static int sit9531x_prg_relock(struct sit9531x_dev *sitdev)
 
 	msleep(100);
 
-	/*
-	 * The debug key register unlocks every debug register while it holds
-	 * the unlock value.
-	 */
-	close_rc = sit9531x_write_close(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
-					SIT9531X_DEBUG_LOCK_VAL);
-	if (close_rc)
-		dev_warn(sitdev->dev,
-			 "output debug block left unlocked after programming: %d\n",
-			 close_rc);
+	sit9531x_outsys_debug_close(sitdev);
 
 	return rc;
 }
@@ -530,20 +571,11 @@ static int sit9531x_prg_relock(struct sit9531x_dev *sitdev)
 /* Retry a failed loop re-lock with the debug window open, as the first try */
 static int sit9531x_prg_relock_retry(struct sit9531x_dev *sitdev)
 {
-	int rc, lock_rc;
+	int rc;
 
-	rc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
-			       SIT9531X_DEBUG_UNLOCK_VAL);
-	if (rc) {
-		lock_rc = sit9531x_write_close(sitdev,
-					       SIT9531X_REG_OUTSYS_DEBUG,
-					       SIT9531X_DEBUG_LOCK_VAL);
-		if (lock_rc)
-			dev_warn(sitdev->dev,
-				 "output debug block left unlocked: %d\n",
-				 lock_rc);
+	rc = sit9531x_outsys_debug_open(sitdev);
+	if (rc)
 		return rc;
-	}
 
 	return sit9531x_prg_relock(sitdev);
 }
@@ -562,30 +594,21 @@ static int sit9531x_prg_commit(struct sit9531x_dev *sitdev)
 }
 
 /*
- * Unlock the Page 3 debug registers and enter PRG_CMD; output-system writes
- * take effect only in this state.
+ * Open the Page 3 debug window and enter PRG_CMD; the output divider takes
+ * effect only in this state.
  */
 static int sit9531x_prg_enter(struct sit9531x_dev *sitdev)
 {
-	int rc, lock_rc;
+	int rc;
 
-	rc = sit9531x_write_u8(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
-			       SIT9531X_DEBUG_UNLOCK_VAL);
-	if (rc) {
-		lock_rc = sit9531x_write_close(sitdev,
-					       SIT9531X_REG_OUTSYS_DEBUG,
-					       SIT9531X_DEBUG_LOCK_VAL);
-		if (lock_rc)
-			dev_warn(sitdev->dev,
-				 "output debug block left unlocked: %d\n",
-				 lock_rc);
+	rc = sit9531x_outsys_debug_open(sitdev);
+	if (rc)
 		return rc;
-	}
 
 	rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
 			       SIT9531X_PRG_CMD_STATE);
 	if (rc) {
-		sit9531x_prg_abort(sitdev);
+		sit9531x_prg_relock(sitdev);
 		return rc;
 	}
 
@@ -610,6 +633,159 @@ static int sit9531x_prg_retry(struct sit9531x_dev *sitdev)
 	return sit9531x_prg_commit(sitdev);
 }
 
+/*
+ * Set one Hi-Z pair to @mask/@state from @cur_mask/@cur_state, writing only the
+ * bits that differ. STATE goes first while the override stays on and last when
+ * it goes off, so the pad holds no other value for one I2C transfer.
+ */
+static int sit9531x_hiz_pair_put(struct sit9531x_dev *sitdev,
+				 const struct sit9531x_hiz_pair *p, bool mask,
+				 bool state, bool cur_mask, bool cur_state)
+{
+	int rc = 0;
+
+	if (mask && state != cur_state)
+		rc = sit9531x_hiz_set_bit(sitdev, p->state, p->bit, state);
+	if (!rc && mask != cur_mask)
+		rc = sit9531x_hiz_set_bit(sitdev, p->mask, p->bit, mask);
+	if (!rc && !mask && state != cur_state)
+		rc = sit9531x_hiz_set_bit(sitdev, p->state, p->bit, state);
+
+	return rc;
+}
+
+/*
+ * Mute every Hi-Z pair of a slot, or unmute it: put back on each pair the
+ * MASK and STATE bits in @out->hiz_mask and @out->hiz_state. The force
+ * registers are outside the NVM, so no directive is written, as in
+ * Output_Disable_Control_HiZ.py. Caller must hold the debug window open.
+ */
+static int sit9531x_output_hiz_write(struct sit9531x_dev *sitdev, u8 slot,
+				     bool mute, const struct sit9531x_out *out)
+{
+	u8 mask[SIT9531X_HIZ_PAIRS], state[SIT9531X_HIZ_PAIRS];
+	struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS];
+	int i, rc, undo_rc;
+
+	sit9531x_output_get_hiz_regs(slot, p);
+
+	for (i = 0; i < SIT9531X_HIZ_PAIRS; i++) {
+		rc = sit9531x_read_u8(sitdev, p[i].state, &state[i]);
+		if (rc)
+			return rc;
+		rc = sit9531x_read_u8(sitdev, p[i].mask, &mask[i]);
+		if (rc)
+			return rc;
+	}
+
+	for (i = 0; i < SIT9531X_HIZ_PAIRS; i++) {
+		bool cur_mask = mask[i] & BIT(p[i].bit);
+		bool cur_state = state[i] & BIT(p[i].bit);
+
+		/* A mute writes both bits, whatever they hold */
+		if (mute)
+			rc = sit9531x_hiz_pair_put(sitdev, &p[i], true, false,
+						   false, true);
+		else
+			rc = sit9531x_hiz_pair_put(sitdev, &p[i],
+						   out->hiz_mask & BIT(i),
+						   out->hiz_state & BIT(i),
+						   cur_mask, cur_state);
+		if (rc)
+			break;
+	}
+	if (!rc)
+		return 0;
+
+	/* Put back what the pairs held, both bits of each */
+	for (; i >= 0; i--) {
+		bool old_mask = mask[i] & BIT(p[i].bit);
+		bool old_state = state[i] & BIT(p[i].bit);
+
+		undo_rc = sit9531x_hiz_pair_put(sitdev, &p[i], old_mask,
+						old_state, !old_mask,
+						!old_state);
+		if (undo_rc)
+			dev_err(sitdev->dev,
+				"slot%u: Hi-Z override left part applied (%d)\n",
+				slot, undo_rc);
+	}
+
+	return rc;
+}
+
+/* Caller must hold sitdev->multiop_lock. */
+int sit9531x_output_disable(struct sit9531x_dev *sitdev, u8 index)
+{
+	const struct sit9531x_chip_info *info = sitdev->info;
+	int rc, state_rc;
+	bool muted, part;
+	u8 slot;
+
+	lockdep_assert_held(&sitdev->multiop_lock);
+
+	if (index >= info->num_outputs)
+		return -EINVAL;
+
+	slot = info->clkout_map[index];
+	rc = sit9531x_outsys_debug_open(sitdev);
+	if (rc)
+		return rc;
+
+	rc = sit9531x_output_hiz_write(sitdev, slot, true, &sitdev->out[index]);
+	sit9531x_outsys_debug_close(sitdev);
+
+	/* Read back the Hi-Z state */
+	state_rc = sit9531x_output_forced_hiz(sitdev, index, &muted, &part);
+	if (!state_rc) {
+		sitdev->out[index].enabled = !muted;
+		sitdev->out[index].part_muted = part;
+		sitdev->out[index].state_stale = false;
+	} else {
+		sitdev->out[index].state_stale = true;
+		if (!rc)
+			rc = state_rc;
+	}
+
+	return rc;
+}
+
+/* Caller must hold sitdev->multiop_lock. */
+int sit9531x_output_enable(struct sit9531x_dev *sitdev, u8 index)
+{
+	const struct sit9531x_chip_info *info = sitdev->info;
+	int rc, state_rc;
+	bool muted, part;
+	u8 slot;
+
+	lockdep_assert_held(&sitdev->multiop_lock);
+
+	if (index >= info->num_outputs)
+		return -EINVAL;
+
+	slot = info->clkout_map[index];
+	rc = sit9531x_outsys_debug_open(sitdev);
+	if (rc)
+		return rc;
+
+	rc = sit9531x_output_hiz_write(sitdev, slot, false,
+				       &sitdev->out[index]);
+	sit9531x_outsys_debug_close(sitdev);
+
+	state_rc = sit9531x_output_forced_hiz(sitdev, index, &muted, &part);
+	if (!state_rc) {
+		sitdev->out[index].enabled = !muted;
+		sitdev->out[index].part_muted = part;
+		sitdev->out[index].state_stale = false;
+	} else {
+		sitdev->out[index].state_stale = true;
+		if (!rc)
+			rc = state_rc;
+	}
+
+	return rc;
+}
+
 /*
  * Procedure:
  *   1. Force PLL into holdover (PLL page reg 0x6F bit 4)
@@ -2220,9 +2396,10 @@ static int sit9531x_chan_state_fetch(struct sit9531x_dev *sitdev, u8 pll_idx)
 static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index)
 {
 	struct sit9531x_out *out = &sitdev->out[index];
+	struct sit9531x_hiz_pair p[SIT9531X_HIZ_PAIRS];
 	u8 map_lo, map_hi, slot, bit, claimed;
 	bool muted, part;
-	int pll_idx;
+	int pll_idx, i;
 	u16 mask;
 	int rc;
 
@@ -2232,11 +2409,37 @@ static int sit9531x_out_state_fetch(struct sit9531x_dev *sitdev, u8 index)
 	if (rc)
 		return rc;
 
+	out->hiz_mask = 0;
+	out->hiz_state = 0;
 	rc = sit9531x_output_forced_hiz(sitdev, index, &muted, &part);
 	if (rc)
 		return rc;
 
-	sitdev->out[index].part_muted = part;
+	/*
+	 * Record what an unmute puts back on each Hi-Z pair: the MASK and STATE
+	 * bits found here. A pair forced to Hi-Z stays forced on a driven
+	 * output and is released on a muted one, so that the unmute drives it.
+	 * The pad forced on a part-muted output is then the configuration's.
+	 */
+	sit9531x_output_get_hiz_regs(slot, p);
+	for (i = 0; i < SIT9531X_HIZ_PAIRS; i++) {
+		u8 mask_val, state_val;
+
+		rc = sit9531x_read_u8(sitdev, p[i].mask, &mask_val);
+		if (!rc)
+			rc = sit9531x_read_u8(sitdev, p[i].state, &state_val);
+		if (rc)
+			return rc;
+		if (state_val & BIT(p[i].bit))
+			out->hiz_state |= BIT(i);
+		else if (muted)
+			continue;
+		if (mask_val & BIT(p[i].bit))
+			out->hiz_mask |= BIT(i);
+	}
+
+	sitdev->out[index].part_muted = false;
+	sitdev->out[index].state_stale = false;
 
 	/*
 	 * Each PLL page holds a 12-bit output-enable mask: OUT_MAP_LO bits 0-7
@@ -2687,6 +2890,8 @@ sit9531x_dev_chan_states_update(struct sit9531x_dev *sitdev)
 		sit9531x_prg_retry(sitdev);
 		if (bank && !sitdev->bank_pending)
 			dev_info(sitdev->dev, "output divider bank updated\n");
+	} else if (sitdev->outsys_key_pending) {
+		sit9531x_outsys_debug_close(sitdev);
 	}
 
 	sit9531x_input_off_retry(sitdev);
@@ -3043,6 +3248,8 @@ static void sit9531x_dev_stop(struct sit9531x_dev *sitdev)
 		if (sitdev->loops_open)
 			dev_warn(sitdev->dev,
 				 "output loops left unlocked at removal\n");
+	} else if (sitdev->outsys_key_pending) {
+		sit9531x_outsys_debug_close(sitdev);
 	}
 	mutex_unlock(&sitdev->multiop_lock);
 }
@@ -3120,7 +3327,7 @@ static void sit9531x_dpll_pin_unregister(struct sit9531x_dpll_pin *pin)
 	 * Clear before unregistering: callbacks test it under the DPLL device
 	 * lock, which dpll_pin_unregister() also takes.
 	 */
-	pin->dpll_pin = NULL;
+	WRITE_ONCE(pin->dpll_pin, NULL);
 
 	dpll_pin_unregister(sitdpll->dpll_dev, dpll_pin, pin->ops, pin);
 	dpll_pin_put(dpll_pin, &pin->tracker);
@@ -3156,20 +3363,33 @@ static void sit9531x_dpll_pins_unregister(struct sit9531x_dpll *sitdpll)
 	}
 }
 
-/* Check if the pin class has a state callback, which the DPLL core requires */
+/*
+ * An output is registered when routed to this DPLL, whether or not it is
+ * driving.
+ */
 static bool sit9531x_dpll_pin_is_registrable(struct sit9531x_dpll *sitdpll,
 					     enum dpll_pin_direction dir,
 					     u8 index)
 {
 	struct sit9531x_dev *sitdev = sitdpll->dev;
 
-	if (dir != DPLL_PIN_DIRECTION_INPUT)
+	if (dir == DPLL_PIN_DIRECTION_INPUT) {
+		if (index == SIT9531X_MAX_INPUTS)
+			return true;
+		if (index == SIT9531X_INTSYNC_PIN_ID)
+			return false;
+
+		return sit9531x_input_pin_is_registrable(sitdev, index);
+	}
+
+	if (index == SIT9531X_INTSYNC_OUT_PIN_ID)
 		return false;
 
-	if (index == SIT9531X_MAX_INPUTS)
-		return true;
+	if (index >= sitdev->info->num_outputs)
+		return false;
 
-	return sit9531x_input_pin_is_registrable(sitdev, index);
+	return sitdev->out[index].pll_idx == sitdpll->id &&
+	       sitdev->out[index].routed;
 }
 
 static int sit9531x_dpll_pins_register(struct sit9531x_dpll *sitdpll)
@@ -3771,17 +3991,26 @@ static int sit9531x_resume(struct device *dev)
 	sit9531x_ref_pll_mask_rebuild(sitdev);
 	for (i = 0; i < sitdev->info->num_outputs; i++) {
 		struct sit9531x_out *out = &sitdev->out[i];
+		u8 hiz_mask = out->hiz_mask, hiz_state = out->hiz_state;
+		bool enabled = out->enabled;
 		bool routed = out->routed;
 		u8 pll_idx = out->pll_idx;
 
 		rc = sit9531x_out_state_fetch(sitdev, i);
-		if (rc)
+		/* A muted output keeps the Hi-Z record taken before the mute */
+		if (rc || (!enabled && !out->enabled)) {
+			out->hiz_mask = hiz_mask;
+			out->hiz_state = hiz_state;
+		}
+		if (rc) {
 			dev_warn(sitdev->dev,
 				 "out%u: state not read on resume: %d\n",
 				 i, rc);
+			out->state_stale = true;
+		}
 		if (out->routed != routed || out->pll_idx != pll_idx)
 			dev_warn(sitdev->dev,
-				 "out%u: routing changed over suspend\n",
+				 "out%u: routing changed over suspend; its pin stays on the DPLL it was registered on\n",
 				 i);
 	}
 	mutex_unlock(&sitdev->multiop_lock);
diff --git a/drivers/dpll/sit9531x/core.h b/drivers/dpll/sit9531x/core.h
index e664a3d247e1..3c2a312f392c 100644
--- a/drivers/dpll/sit9531x/core.h
+++ b/drivers/dpll/sit9531x/core.h
@@ -113,8 +113,18 @@ struct sit9531x_ref {
  * @freq: output frequency in Hz
  * @enabled: output is driving, not forced into Hi-Z
  * @cmos: single-ended; the CMOS pad Hi-Z pairs apply, not the differential one
- * @part_muted: single-ended with one pad forced and the other not; reported
- *   as driven
+ * @state_stale: cached mute state must be read back before it is reported
+ * @ntf_pending: pin change not yet notified; the poll notifies once the state
+ *   is read
+ * @part_muted: single-ended with one pad forced and the other not, where
+ *   @hiz_mask and @hiz_state do not keep the forced pad forced; reported as
+ *   driven. The driver's mute forces both pads.
+ * @hiz_mask: bit per Hi-Z pair, the MASK bit an unmute writes back; read at
+ *   probe and on resume, unless the output is muted both before and after
+ *   the resume. On an output muted at that read, a pair forced to Hi-Z is
+ *   taken as the mute, also one an earlier binding set, and its bit is
+ *   cleared, so that an unmute drives the pair
+ * @hiz_state: bit per Hi-Z pair, the STATE bit an unmute writes back
  * @routed: mapped to @pll_idx by the loaded configuration; an output
  *   unrouted at probe has no pin
  * @pll_idx: PLL driving this output (0-3)
@@ -123,7 +133,11 @@ struct sit9531x_out {
 	u64		freq;
 	bool		enabled;
 	bool		cmos;
+	bool		state_stale;
+	bool		ntf_pending;
 	bool		part_muted;
+	u8		hiz_mask;
+	u8		hiz_state;
 	bool		routed;
 	u8		pll_idx;
 };
@@ -247,6 +261,7 @@ struct sit9531x_chan {
  *   band; written under @multiop_lock
  * @loops_open: output loops not yet re-locked
  * @bank_pending: output divider bank update still to be issued
+ * @outsys_key_pending: output-system debug key not closed
  */
 struct sit9531x_dev {
 	struct device			*dev;
@@ -280,6 +295,7 @@ struct sit9531x_dev {
 
 	bool			loops_open;
 	bool			bank_pending;
+	bool			outsys_key_pending;
 };
 
 int sit9531x_read_u8(struct sit9531x_dev *sitdev, unsigned int reg,
@@ -307,6 +323,11 @@ int sit9531x_input_prio_remove(struct sit9531x_dev *sitdev, u8 pll_idx,
 int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,
 			    u8 input_idx);
 
+int sit9531x_output_disable(struct sit9531x_dev *sitdev, u8 index);
+int sit9531x_output_enable(struct sit9531x_dev *sitdev, u8 index);
+int sit9531x_output_state_refresh(struct sit9531x_dev *sitdev,
+				  u8 out_idx);
+
 int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,
 			     u8 pll_idx, u64 frequency);
 int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,
diff --git a/drivers/dpll/sit9531x/dpll.c b/drivers/dpll/sit9531x/dpll.c
index 25bee483bb5a..b0403c0bc132 100644
--- a/drivers/dpll/sit9531x/dpll.c
+++ b/drivers/dpll/sit9531x/dpll.c
@@ -187,8 +187,9 @@ const struct dpll_device_ops sit9531x_dpll_device_ops = {
  * falls back to another listed source and leaves the selection naming the lost
  * one. On manual input select, the selected input is CONNECTED: the one the
  * select register names, or the one the PLL last tracked when the select pins
- * or the indirect choice pick it; a state request is refused. The XO pin is
- * always CONNECTED and reports its priority read-only.
+ * or the indirect choice pick it; a state request is refused. An output is
+ * CONNECTED while driven and DISCONNECTED while muted; SELECTABLE is refused.
+ * The XO pin is always CONNECTED and reports its priority read-only.
  */
 
 /* Caller must hold sitdev->multiop_lock. */
@@ -665,7 +666,9 @@ sit9531x_dpll_output_pin_frequency_set(const struct dpll_pin *pin,
 	rc = sit9531x_output_freq_set(sitdev, dpin->id, actual_pll,
 				      frequency);
 	if (rc) {
-		if (!sit9531x_output_freq_get(sitdev, dpin->id, &hz))
+		if (sit9531x_output_freq_get(sitdev, dpin->id, &hz))
+			moved = true;
+		else
 			moved |= hz != was;
 	}
 	mutex_unlock(&sitdev->multiop_lock);
@@ -676,8 +679,112 @@ sit9531x_dpll_output_pin_frequency_set(const struct dpll_pin *pin,
 		NL_SET_ERR_MSG(extack, "Output frequency set failed");
 		/* The core notifies only a request that succeeded */
 		dpll_pin = READ_ONCE(dpin->dpll_pin);
-		if (moved && dpll_pin)
-			__dpll_pin_change_ntf(dpll_pin);
+		if (moved && dpll_pin && __dpll_pin_change_ntf(dpll_pin)) {
+			mutex_lock(&sitdev->multiop_lock);
+			sitdev->out[dpin->id].ntf_pending = true;
+			mutex_unlock(&sitdev->multiop_lock);
+		}
+	}
+
+	return rc;
+}
+
+/*
+ * DISCONNECTED while the output is forced to Hi-Z, by a mute request or by the
+ * loaded profile.
+ */
+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 = 0;
+
+	mutex_lock(&sitdev->multiop_lock);
+	out = sit9531x_out_state_get(sitdev, dpin->id);
+	if (out->state_stale)
+		rc = sit9531x_output_state_refresh(sitdev, dpin->id);
+	if (!rc)
+		*state = out->enabled ? DPLL_PIN_STATE_CONNECTED
+				      : DPLL_PIN_STATE_DISCONNECTED;
+	mutex_unlock(&sitdev->multiop_lock);
+	if (rc)
+		NL_SET_ERR_MSG(extack,
+			       "Output mute state could not be read back");
+
+	return rc;
+}
+
+/*
+ * Force Hi-Z through the slot's Hi-Z force/state register pairs: differential,
+ * CMOS OutP and CMOS OutN.
+ */
+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)
+{
+	bool enable = state == DPLL_PIN_STATE_CONNECTED;
+	struct sit9531x_dpll_pin *dpin = pin_priv;
+	struct sit9531x_dpll *sitdpll = dpll_priv;
+	struct sit9531x_dev *sitdev = sitdpll->dev;
+	bool was_enabled, changed;
+	int rc;
+
+	/* An output is routed explicitly, not a selection candidate */
+	if (!enable && state != DPLL_PIN_STATE_DISCONNECTED)
+		return -EINVAL;
+
+	mutex_lock(&sitdev->multiop_lock);
+
+	/*
+	 * Skip a request for the current state. One CMOS pad forced and the
+	 * other not is neither state, unless the configuration forces that pad.
+	 */
+	if (!sit9531x_output_state_refresh(sitdev, dpin->id) &&
+	    sitdev->out[dpin->id].enabled == enable &&
+	    !sitdev->out[dpin->id].part_muted) {
+		mutex_unlock(&sitdev->multiop_lock);
+		return 0;
+	}
+
+	was_enabled = sitdev->out[dpin->id].enabled;
+
+	if (enable)
+		rc = sit9531x_output_enable(sitdev, dpin->id);
+	else
+		rc = sit9531x_output_disable(sitdev, dpin->id);
+
+	changed = sitdev->out[dpin->id].enabled != was_enabled ||
+		  sitdev->out[dpin->id].state_stale;
+
+	mutex_unlock(&sitdev->multiop_lock);
+
+	if (rc) {
+		struct dpll_pin *dpll_pin;
+
+		NL_SET_ERR_MSG(extack, "Failed to set output pin state");
+		/*
+		 * The core notifies only a request that succeeded. Teardown
+		 * clears dpll_pin without the core's lock, which is held here;
+		 * read it once, as a set handle stays valid until this returns.
+		 */
+		dpll_pin = READ_ONCE(dpin->dpll_pin);
+		if (changed && dpll_pin && __dpll_pin_change_ntf(dpll_pin)) {
+			mutex_lock(&sitdev->multiop_lock);
+			sitdev->out[dpin->id].ntf_pending = true;
+			mutex_unlock(&sitdev->multiop_lock);
+		}
 	}
 
 	return rc;
@@ -687,6 +794,8 @@ 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,
 };
 
 const struct dpll_pin_ops *
@@ -774,8 +883,33 @@ void sit9531x_dpll_pin_baseline(struct sit9531x_dpll_pin *pin)
 }
 
 /*
- * Notify a changed lock status, pin state or priority; called from
- * sit9531x_dev_periodic_work().
+ * Re-read an output with a pending change notification; return true once the
+ * read succeeds. Caller must hold sitdev->multiop_lock.
+ */
+static bool
+sit9531x_dpll_output_ntf_pending(struct sit9531x_dev *sitdev,
+				 const struct sit9531x_dpll_pin *pin)
+{
+	struct sit9531x_out *out;
+
+	if (sit9531x_dpll_is_input_pin(pin) ||
+	    pin->id >= sitdev->info->num_outputs)
+		return false;
+
+	out = &sitdev->out[pin->id];
+	if (!out->ntf_pending)
+		return false;
+	if (out->state_stale && sit9531x_output_state_refresh(sitdev, pin->id))
+		return false;
+
+	out->ntf_pending = false;
+
+	return true;
+}
+
+/*
+ * Notify a changed lock status, pin state, operational state or priority and
+ * retry a notification that failed; called from sit9531x_dev_periodic_work().
  */
 void sit9531x_dpll_changes_check(struct sit9531x_dpll *sitdpll)
 {
@@ -821,8 +955,11 @@ void sit9531x_dpll_changes_check(struct sit9531x_dpll *sitdpll)
 			continue;
 		}
 
-		if (!sit9531x_dpll_is_selection_pin(pin))
+		if (!sit9531x_dpll_is_selection_pin(pin)) {
+			pin->ntf_pending |=
+				sit9531x_dpll_output_ntf_pending(sitdev, pin);
 			continue;
+		}
 
 		sit9531x_dpll_pin_snapshot(sitdpll, pin, &state, &operstate,
 					   &prio);
-- 
2.39.2 (Apple Git-143)


  parent reply	other threads:[~2026-12-01 23:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 23:52 [PATCH net-next v17 00/13] dpll: add SiTime SiT9531x DPLL clock driver Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 01/13] dpll: omit pin phase attributes the driver has no value for Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 02/13] dt-bindings: vendor-prefixes: add SiTime Corporation Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 03/13] dt-bindings: dpll: add SiTime SiT95316 clock generator Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 04/13] dpll: add basic SiTime SiT9531x support Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 05/13] dpll: sit9531x: read DPLL types and pin properties from system firmware Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 06/13] dpll: sit9531x: register DPLL devices and pins Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 08/13] dpll: sit9531x: add support to get and set priority on input pins Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 07/13] dpll: sit9531x: implement input pin state on a DPLL Ali Rouhi
2026-12-01 23:52 ` Ali Rouhi [this message]
2026-12-01 23:52 ` [PATCH net-next v17 09/13] dpll: sit9531x: add support to get and set frequency on pins Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 12/13] dpll: sit9531x: add support to get phase offset on the connected input Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 11/13] dpll: sit9531x: add support to adjust output phase Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 13/13] dpll: sit9531x: model the inter-PLL sync line as a pair of pins Ali Rouhi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201235202.97645-11-arouhi@sitime.com \
    --to=arouhi@sitime.com \
    --cc=Oleg.Zadorozhnyi@devoxsoftware.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=cjubran@nvidia.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ivecera@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=robh@kernel.org \
    --cc=vadim.fedorenko@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox