intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Sean Paul <seanpaul@chromium.org>
Cc: seanpaul@google.com, David Airlie <airlied@linux.ie>,
	intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	daniel.vetter@intel.com
Subject: Re: [PATCH v3 6/9] drm/i915: Make use of indexed write GMBUS feature
Date: Tue, 5 Dec 2017 19:33:14 +0200	[thread overview]
Message-ID: <20171205173313.GX10981@intel.com> (raw)
In-Reply-To: <20171205051513.8603-7-seanpaul@chromium.org>

On Tue, Dec 05, 2017 at 12:15:05AM -0500, Sean Paul wrote:
> This patch enables the indexed write feature of the GMBUS to concatenate
> 2 consecutive messages into one. The criteria for an indexed write is
> that both messages are writes, the first is length == 1, and the second
> is length > 0. The first message is sent out by the GMBUS as the slave
> command, and the second one is sent via the GMBUS FIFO as usual.
> 
> Changes in v3:
> - Added to series
> 
> Suggested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Sean Paul <seanpaul@chromium.org>
> ---
>  drivers/gpu/drm/i915/intel_i2c.c | 39 ++++++++++++++++++++++++++++++++++-----
>  1 file changed, 34 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
> index 49fdf09f9919..7399009aee0a 100644
> --- a/drivers/gpu/drm/i915/intel_i2c.c
> +++ b/drivers/gpu/drm/i915/intel_i2c.c
> @@ -373,7 +373,8 @@ gmbus_xfer_read(struct drm_i915_private *dev_priv, struct i2c_msg *msg,
>  
>  static int
>  gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv,
> -		       unsigned short addr, u8 *buf, unsigned int len)
> +		       unsigned short addr, u8 *buf, unsigned int len,
> +		       u32 gmbus1_index)
>  {
>  	unsigned int chunk_size = len;
>  	u32 val, loop;
> @@ -386,7 +387,7 @@ gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv,
>  
>  	I915_WRITE_FW(GMBUS3, val);
>  	I915_WRITE_FW(GMBUS1,
> -		      GMBUS_CYCLE_WAIT |
> +		      gmbus1_index | GMBUS_CYCLE_WAIT |
>  		      (chunk_size << GMBUS_BYTE_COUNT_SHIFT) |
>  		      (addr << GMBUS_SLAVE_ADDR_SHIFT) |
>  		      GMBUS_SLAVE_WRITE | GMBUS_SW_RDY);
> @@ -409,7 +410,8 @@ gmbus_xfer_write_chunk(struct drm_i915_private *dev_priv,
>  }
>  
>  static int
> -gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg)
> +gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg,
> +		 u32 gmbus1_index)
>  {
>  	u8 *buf = msg->buf;
>  	unsigned int tx_size = msg->len;
> @@ -419,7 +421,8 @@ gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg)
>  	do {
>  		len = min(tx_size, GMBUS_BYTE_COUNT_MAX);
>  
> -		ret = gmbus_xfer_write_chunk(dev_priv, msg->addr, buf, len);
> +		ret = gmbus_xfer_write_chunk(dev_priv, msg->addr, buf, len,
> +					     gmbus1_index);
>  		if (ret)
>  			return ret;
>  
> @@ -430,6 +433,14 @@ gmbus_xfer_write(struct drm_i915_private *dev_priv, struct i2c_msg *msg)
>  	return 0;
>  }
>  
> +static int
> +gmbus_xfer_index_write(struct drm_i915_private *dev_priv, u8 cmd,
> +		       struct i2c_msg *msg)
> +{
> +	u8 gmbus1_index = GMBUS_CYCLE_INDEX | (cmd << GMBUS_SLAVE_INDEX_SHIFT);
> +	return gmbus_xfer_write(dev_priv, msg, gmbus1_index);
> +}

Instead of a duplicating the entire thing I'd just

- gmbus_xfer_index_read
+ gmbus_xfer_index
  {
  ...
+ 	if (msgs[1].flags & I2C_M_RD)
		gmbus_xfer_read()
+ 	else
+ 		gmbus_xfer_write()
  ...
  }

Matches the current pattern better (no 'cmd' passed in), and
will give us the 2 byte index for free as well.

> +
>  /*
>   * The gmbus controller can combine a 1 or 2 byte write with a read that
>   * immediately follows it by using an "INDEX" cycle.
> @@ -444,6 +455,20 @@ gmbus_is_index_read(struct i2c_msg *msgs, int i, int num)
>  		(msgs[i + 1].flags & I2C_M_RD));
>  }
>  
> +/*
> + * The gmbus controller can combine a 2-msg write into a single write that
> + * immediately follows it by using an "INDEX" cycle.
> + */
> +static bool
> +gmbus_is_index_write(struct i2c_msg *msgs, int i, int num)
> +{
> +	return (i + 1 < num &&
> +		msgs[i].addr == msgs[i + 1].addr &&
> +		!(msgs[i].flags & I2C_M_RD) &&
> +		!(msgs[i + 1].flags & I2C_M_RD) &&
> +		(msgs[i].len == 1 || msgs[i + 1].len > 0));

Hmm. We don't have the len check for the second msg for reads. I wonder
if gmbus can actually do a zero length "read/write"?

> +}
> +
>  static int
>  gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs)
>  {
> @@ -489,10 +514,14 @@ do_gmbus_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
>  		if (gmbus_is_index_read(msgs, i, num)) {
>  			ret = gmbus_xfer_index_read(dev_priv, &msgs[i]);
>  			inc = 2; /* an index read is two msgs */
> +		} else if (gmbus_is_index_write(msgs, i, num)) {
> +			ret = gmbus_xfer_index_write(dev_priv, msgs[i].buf[0],
> +					&msgs[i + 1]);
> +			inc = 2; /* an index write is two msgs */
>  		} else if (msgs[i].flags & I2C_M_RD) {
>  			ret = gmbus_xfer_read(dev_priv, &msgs[i], 0);
>  		} else {
> -			ret = gmbus_xfer_write(dev_priv, &msgs[i]);
> +			ret = gmbus_xfer_write(dev_priv, &msgs[i], 0);
>  		}
>  
>  		if (!ret)
> -- 
> 2.15.0.531.g2ccb3012c9-goog
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2017-12-05 17:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-05  5:14 [PATCH v3 0/9] drm/i915: Implement HDCP Sean Paul
2017-12-05  5:15 ` [PATCH v3 1/9] drm: Fix link-status kerneldoc line lengths Sean Paul
2017-12-05  5:15 ` [PATCH v3 2/9] drm/i915: Add more control to wait_for routines Sean Paul
2017-12-05 17:13   ` Daniel Vetter
2017-12-05 23:09   ` [Intel-gfx] " Chris Wilson
2017-12-05  5:15 ` [PATCH v3 3/9] drm: Add Content Protection property Sean Paul
2017-12-05  8:07   ` Hans Verkuil
2017-12-05 15:27     ` Daniel Vetter
2017-12-05 15:34   ` Daniel Vetter
2017-12-05 15:40     ` [Intel-gfx] " Chris Wilson
2017-12-05  5:15 ` [PATCH v3 4/9] drm: Add some HDCP related #defines Sean Paul
2017-12-05 23:12   ` [Intel-gfx] " Chris Wilson
2017-12-06 15:01     ` Alex Deucher
2017-12-05  5:15 ` [PATCH v3 5/9] drm/i915: Add HDCP framework + base implementation Sean Paul
2017-12-05  9:06   ` Ramalingam C
2017-12-05 17:00   ` Daniel Vetter
2017-12-05  5:15 ` [PATCH v3 6/9] drm/i915: Make use of indexed write GMBUS feature Sean Paul
2017-12-05 17:01   ` [Intel-gfx] " Daniel Vetter
2017-12-05 17:33   ` Ville Syrjälä [this message]
2017-12-05  5:15 ` [PATCH v3 7/9] drm/i915: Add function to output Aksv over GMBUS Sean Paul
2017-12-05 17:02   ` Daniel Vetter
2017-12-05  5:15 ` [PATCH v3 8/9] drm/i915: Implement HDCP for HDMI Sean Paul
2017-12-05 17:06   ` Daniel Vetter
2017-12-05  5:15 ` [PATCH v3 9/9] drm/i915: Implement HDCP for DisplayPort Sean Paul
2017-12-05 14:30   ` Ramalingam C
2017-12-05 17:12   ` Daniel Vetter
2017-12-05  5:21 ` ✗ Fi.CI.BAT: failure for drm/i915: Implement HDCP (rev3) Patchwork
2017-12-05 15:30   ` Daniel Vetter

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=20171205173313.GX10981@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=seanpaul@chromium.org \
    --cc=seanpaul@google.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;
as well as URLs for NNTP newsgroup(s).