Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/sbi: add and use intel_sbi_rmw()
Date: Tue, 24 Nov 2026 22:40:10 +0200	[thread overview]
Message-ID: <awX2Kv_A7kZs92fU@intel.com> (raw)
In-Reply-To: <20261124170441.1600907-1-jani.nikula@intel.com>

On Tue, Nov 24, 2026 at 07:04:41PM +0200, Jani Nikula wrote:
> Almost all of SBI access is read-modify-write with separate reads and
> writes. Add intel_sbi_rmw() modeled after intel_de_rwm(), and use it to
> make the code more concise and easier to read.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  .../gpu/drm/i915/display/intel_pch_refclk.c   | 144 +++++-------------
>  drivers/gpu/drm/i915/display/intel_sbi.c      |  12 ++
>  drivers/gpu/drm/i915/display/intel_sbi.h      |   2 +
>  3 files changed, 49 insertions(+), 109 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_pch_refclk.c b/drivers/gpu/drm/i915/display/intel_pch_refclk.c
> index 5f88663ef5e8..fe9dbc2b21ee 100644
> --- a/drivers/gpu/drm/i915/display/intel_pch_refclk.c
> +++ b/drivers/gpu/drm/i915/display/intel_pch_refclk.c
> @@ -36,91 +36,32 @@ static void lpt_fdi_reset_mphy(struct intel_display *display)
>  /* WaMPhyProgramming:hsw */
>  static void lpt_fdi_program_mphy(struct intel_display *display)
>  {
> -	u32 tmp;
> -
>  	lpt_fdi_reset_mphy(display);
>  
> -	tmp = intel_sbi_read(display, 0x8008, SBI_MPHY);
> -	tmp &= ~(0xFF << 24);
> -	tmp |= (0x12 << 24);
> -	intel_sbi_write(display, 0x8008, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x2008, SBI_MPHY);
> -	tmp |= (1 << 11);
> -	intel_sbi_write(display, 0x2008, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x2108, SBI_MPHY);
> -	tmp |= (1 << 11);
> -	intel_sbi_write(display, 0x2108, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x206C, SBI_MPHY);
> -	tmp |= (1 << 24) | (1 << 21) | (1 << 18);
> -	intel_sbi_write(display, 0x206C, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x216C, SBI_MPHY);
> -	tmp |= (1 << 24) | (1 << 21) | (1 << 18);
> -	intel_sbi_write(display, 0x216C, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x2080, SBI_MPHY);
> -	tmp &= ~(7 << 13);
> -	tmp |= (5 << 13);
> -	intel_sbi_write(display, 0x2080, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x2180, SBI_MPHY);
> -	tmp &= ~(7 << 13);
> -	tmp |= (5 << 13);
> -	intel_sbi_write(display, 0x2180, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x208C, SBI_MPHY);
> -	tmp &= ~0xFF;
> -	tmp |= 0x1C;
> -	intel_sbi_write(display, 0x208C, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x218C, SBI_MPHY);
> -	tmp &= ~0xFF;
> -	tmp |= 0x1C;
> -	intel_sbi_write(display, 0x218C, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x2098, SBI_MPHY);
> -	tmp &= ~(0xFF << 16);
> -	tmp |= (0x1C << 16);
> -	intel_sbi_write(display, 0x2098, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x2198, SBI_MPHY);
> -	tmp &= ~(0xFF << 16);
> -	tmp |= (0x1C << 16);
> -	intel_sbi_write(display, 0x2198, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x20C4, SBI_MPHY);
> -	tmp |= (1 << 27);
> -	intel_sbi_write(display, 0x20C4, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x21C4, SBI_MPHY);
> -	tmp |= (1 << 27);
> -	intel_sbi_write(display, 0x21C4, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x20EC, SBI_MPHY);
> -	tmp &= ~(0xF << 28);
> -	tmp |= (4 << 28);
> -	intel_sbi_write(display, 0x20EC, tmp, SBI_MPHY);
> -
> -	tmp = intel_sbi_read(display, 0x21EC, SBI_MPHY);
> -	tmp &= ~(0xF << 28);
> -	tmp |= (4 << 28);
> -	intel_sbi_write(display, 0x21EC, tmp, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x8008, 0xFF << 24, 0x12 << 24, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x2008, 0, 1 << 11, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x2108, 0, 1 << 11, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x206C, 0, (1 << 24) | (1 << 21) | (1 << 18), SBI_MPHY);
> +	intel_sbi_rmw(display, 0x216C, 0, (1 << 24) | (1 << 21) | (1 << 18), SBI_MPHY);
> +	intel_sbi_rmw(display, 0x2080, 7 << 13, 5 << 13, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x2180, 7 << 13, 5 << 13, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x208C, 0xFF, 0x1C, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x218C, 0xFF, 0x1C, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x2098, 0xFF << 16, 0x1C << 16, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x2198, 0xFF << 16, 0x1C << 16, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x20C4, 0, 1 << 27, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x21C4, 0, 1 << 27, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x20EC, 0xF << 28, 4 << 28, SBI_MPHY);
> +	intel_sbi_rmw(display, 0x21EC, 0xF << 28, 4 << 28, SBI_MPHY);

If only the diff would group these in a sane way :/

Went a bit cross-eyed looking at this, but it looks correct to me.
Asked Claude to double check it and it didn't spot any unintended
changes either.

Claude did spot a "rmw" vs. "rwm" typo in the commit message,
and...

>  }
>  
>  void lpt_disable_iclkip(struct intel_display *display)
>  {
> -	u32 temp;
> -
>  	intel_de_write(display, PIXCLK_GATE, PIXCLK_GATE_GATE);
>  
>  	intel_sbi_lock(display);
>  
> -	temp = intel_sbi_read(display, SBI_SSCCTL6, SBI_ICLK);
> -	temp |= SBI_SSCCTL_DISABLE;
> -	intel_sbi_write(display, SBI_SSCCTL6, temp, SBI_ICLK);
> +	intel_sbi_rmw(display, SBI_SSCCTL6, 0, SBI_SSCCTL_DISABLE, SBI_ICLK);
>  
>  	intel_sbi_unlock(display);
>  }
> @@ -185,7 +126,6 @@ void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
>  	struct intel_display *display = to_intel_display(crtc_state);
>  	int clock = crtc_state->hw.adjusted_mode.crtc_clock;
>  	struct iclkip_params p;
> -	u32 temp;
>  
>  	lpt_disable_iclkip(display);
>  
> @@ -205,25 +145,23 @@ void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
>  	intel_sbi_lock(display);
>  
>  	/* Program SSCDIVINTPHASE6 */
> -	temp = intel_sbi_read(display, SBI_SSCDIVINTPHASE6, SBI_ICLK);
> -	temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
> -	temp |= SBI_SSCDIVINTPHASE_DIVSEL(p.divsel);
> -	temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
> -	temp |= SBI_SSCDIVINTPHASE_INCVAL(p.phaseinc);
> -	temp |= SBI_SSCDIVINTPHASE_DIR(p.phasedir);
> -	temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
> -	intel_sbi_write(display, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
> +	intel_sbi_rmw(display, SBI_SSCDIVINTPHASE6,
> +		      SBI_SSCDIVINTPHASE_DIVSEL_MASK |
> +		      SBI_SSCDIVINTPHASE_INCVAL_MASK,

... we both noticed that we don't clear the DIR bit here,
which means if it was set previously it'll remain set
when p.phasedir==0 (which it always is).

But according to the spec we shouldn't even be touching
that bit (its specific meaning isn't even documented).
So the code actually matches the spec by accident. This
bit is probably some prehistoric leftover that we should
just completely nuke.

Anyways, this patch is
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> +		      SBI_SSCDIVINTPHASE_DIVSEL(p.divsel) |
> +		      SBI_SSCDIVINTPHASE_INCVAL(p.phaseinc) |
> +		      SBI_SSCDIVINTPHASE_DIR(p.phasedir) |
> +		      SBI_SSCDIVINTPHASE_PROPAGATE,
> +		      SBI_ICLK);
>  
>  	/* Program SSCAUXDIV */
> -	temp = intel_sbi_read(display, SBI_SSCAUXDIV6, SBI_ICLK);
> -	temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
> -	temp |= SBI_SSCAUXDIV_FINALDIV2SEL(p.auxdiv);
> -	intel_sbi_write(display, SBI_SSCAUXDIV6, temp, SBI_ICLK);
> +	intel_sbi_rmw(display, SBI_SSCAUXDIV6,
> +		      SBI_SSCAUXDIV_FINALDIV2SEL(1),
> +		      SBI_SSCAUXDIV_FINALDIV2SEL(p.auxdiv),
> +		      SBI_ICLK);
>  
>  	/* Enable modulator and associated divider */
> -	temp = intel_sbi_read(display, SBI_SSCCTL6, SBI_ICLK);
> -	temp &= ~SBI_SSCCTL_DISABLE;
> -	intel_sbi_write(display, SBI_SSCCTL6, temp, SBI_ICLK);
> +	intel_sbi_rmw(display, SBI_SSCCTL6, SBI_SSCCTL_DISABLE, 0, SBI_ICLK);
>  
>  	intel_sbi_unlock(display);
>  
> @@ -277,7 +215,7 @@ int lpt_get_iclkip(struct intel_display *display)
>  static void lpt_enable_clkout_dp(struct intel_display *display,
>  				 bool with_spread, bool with_fdi)
>  {
> -	u32 reg, tmp;
> +	u32 reg;
>  
>  	if (drm_WARN(display->drm, with_fdi && !with_spread,
>  		     "FDI requires downspread\n"))
> @@ -288,26 +226,19 @@ static void lpt_enable_clkout_dp(struct intel_display *display,
>  
>  	intel_sbi_lock(display);
>  
> -	tmp = intel_sbi_read(display, SBI_SSCCTL, SBI_ICLK);
> -	tmp &= ~SBI_SSCCTL_DISABLE;
> -	tmp |= SBI_SSCCTL_PATHALT;
> -	intel_sbi_write(display, SBI_SSCCTL, tmp, SBI_ICLK);
> +	intel_sbi_rmw(display, SBI_SSCCTL, SBI_SSCCTL_DISABLE, SBI_SSCCTL_PATHALT, SBI_ICLK);
>  
>  	udelay(24);
>  
>  	if (with_spread) {
> -		tmp = intel_sbi_read(display, SBI_SSCCTL, SBI_ICLK);
> -		tmp &= ~SBI_SSCCTL_PATHALT;
> -		intel_sbi_write(display, SBI_SSCCTL, tmp, SBI_ICLK);
> +		intel_sbi_rmw(display, SBI_SSCCTL, SBI_SSCCTL_PATHALT, 0, SBI_ICLK);
>  
>  		if (with_fdi)
>  			lpt_fdi_program_mphy(display);
>  	}
>  
>  	reg = HAS_PCH_LPT_LP(display) ? SBI_GEN0 : SBI_DBUFF0;
> -	tmp = intel_sbi_read(display, reg, SBI_ICLK);
> -	tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
> -	intel_sbi_write(display, reg, tmp, SBI_ICLK);
> +	intel_sbi_rmw(display, reg, 0, SBI_GEN0_CFG_BUFFENABLE_DISABLE, SBI_ICLK);
>  
>  	intel_sbi_unlock(display);
>  }
> @@ -320,9 +251,7 @@ void lpt_disable_clkout_dp(struct intel_display *display)
>  	intel_sbi_lock(display);
>  
>  	reg = HAS_PCH_LPT_LP(display) ? SBI_GEN0 : SBI_DBUFF0;
> -	tmp = intel_sbi_read(display, reg, SBI_ICLK);
> -	tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
> -	intel_sbi_write(display, reg, tmp, SBI_ICLK);
> +	intel_sbi_rmw(display, reg, SBI_GEN0_CFG_BUFFENABLE_DISABLE, 0, SBI_ICLK);
>  
>  	tmp = intel_sbi_read(display, SBI_SSCCTL, SBI_ICLK);
>  	if (!(tmp & SBI_SSCCTL_DISABLE)) {
> @@ -389,10 +318,7 @@ static void lpt_bend_clkout_dp(struct intel_display *display, int steps)
>  		tmp = 0x00000000;
>  	intel_sbi_write(display, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
>  
> -	tmp = intel_sbi_read(display, SBI_SSCDIVINTPHASE, SBI_ICLK);
> -	tmp &= 0xffff0000;
> -	tmp |= sscdivintphase[idx];
> -	intel_sbi_write(display, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
> +	intel_sbi_rmw(display, SBI_SSCDIVINTPHASE, 0x0000ffff, sscdivintphase[idx], SBI_ICLK);
>  
>  	intel_sbi_unlock(display);
>  }
> diff --git a/drivers/gpu/drm/i915/display/intel_sbi.c b/drivers/gpu/drm/i915/display/intel_sbi.c
> index b636a0060d39..e671a8b5f3be 100644
> --- a/drivers/gpu/drm/i915/display/intel_sbi.c
> +++ b/drivers/gpu/drm/i915/display/intel_sbi.c
> @@ -81,6 +81,18 @@ void intel_sbi_write(struct intel_display *display, u16 reg, u32 value,
>  	intel_sbi_rw(display, reg, destination, &value, false);
>  }
>  
> +u32 intel_sbi_rmw(struct intel_display *display, u16 reg, u32 clear, u32 set,
> +		  enum intel_sbi_destination destination)
> +{
> +	u32 old, val;
> +
> +	old = intel_sbi_read(display, reg, destination);
> +	val = (old & ~clear) | set;
> +	intel_sbi_write(display, reg, val, destination);
> +
> +	return old;
> +}
> +
>  void intel_sbi_init(struct intel_display *display)
>  {
>  	mutex_init(&display->sbi.lock);
> diff --git a/drivers/gpu/drm/i915/display/intel_sbi.h b/drivers/gpu/drm/i915/display/intel_sbi.h
> index 841f77a142a1..5e4afbbf25a6 100644
> --- a/drivers/gpu/drm/i915/display/intel_sbi.h
> +++ b/drivers/gpu/drm/i915/display/intel_sbi.h
> @@ -23,5 +23,7 @@ u32 intel_sbi_read(struct intel_display *display, u16 reg,
>  		   enum intel_sbi_destination destination);
>  void intel_sbi_write(struct intel_display *display, u16 reg, u32 value,
>  		     enum intel_sbi_destination destination);
> +u32 intel_sbi_rmw(struct intel_display *display, u16 reg, u32 clear, u32 set,
> +		  enum intel_sbi_destination destination);
>  
>  #endif /* _INTEL_SBI_H_ */
> -- 
> 2.47.3

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2026-11-24 20:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 17:04 [PATCH] drm/i915/sbi: add and use intel_sbi_rmw() Jani Nikula
2026-11-24 20:40 ` Ville Syrjälä [this message]
2026-11-26  8:29   ` Jani Nikula
2026-11-25  3:59 ` ✓ i915.CI.BAT: success for " Patchwork
2026-11-25 22:57 ` ✓ i915.CI.Full: " Patchwork

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=awX2Kv_A7kZs92fU@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    /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