public inbox for intel-gfx@lists.freedesktop.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 2/2] drm/i915: abstract i2c bit banging fallback in gmbus xfer
Date: Tue, 1 Dec 2015 16:57:20 +0200	[thread overview]
Message-ID: <20151201145720.GE4437@intel.com> (raw)
In-Reply-To: <1448980166-23055-2-git-send-email-jani.nikula@intel.com>

On Tue, Dec 01, 2015 at 04:29:26PM +0200, Jani Nikula wrote:
> Choose between i2c bit banging and gmbus in a new higher level function,
> and let the i2c core retry the first time we fall back to bit banging.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_i2c.c | 39 +++++++++++++++++++++++++--------------
>  1 file changed, 25 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
> index ccb522c176bd..e26e22a72e3b 100644
> --- a/drivers/gpu/drm/i915/intel_i2c.c
> +++ b/drivers/gpu/drm/i915/intel_i2c.c
> @@ -472,9 +472,7 @@ gmbus_xfer_index_read(struct drm_i915_private *dev_priv, struct i2c_msg *msgs)
>  }
>  
>  static int
> -gmbus_xfer(struct i2c_adapter *adapter,
> -	   struct i2c_msg *msgs,
> -	   int num)
> +do_gmbus_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
>  {
>  	struct intel_gmbus *bus = container_of(adapter,
>  					       struct intel_gmbus,
> @@ -483,14 +481,6 @@ gmbus_xfer(struct i2c_adapter *adapter,
>  	int i = 0, inc, try = 0;
>  	int ret = 0;
>  
> -	intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
> -	mutex_lock(&dev_priv->gmbus_mutex);
> -
> -	if (bus->force_bit) {
> -		ret = i2c_bit_algo.master_xfer(adapter, msgs, num);
> -		goto out;
> -	}
> -
>  retry:
>  	I915_WRITE(GMBUS0, bus->reg0);
>  
> @@ -585,13 +575,34 @@ timeout:
>  		 bus->adapter.name, bus->reg0 & 0xff);
>  	I915_WRITE(GMBUS0, 0);
>  
> -	/* Hardware may not support GMBUS over these pins? Try GPIO bitbanging instead. */
> +	/*
> +	 * Hardware may not support GMBUS over these pins? Try GPIO bitbanging
> +	 * instead. Use EAGAIN to have i2c core retry.
> +	 */
>  	bus->force_bit = 1;
> -	ret = i2c_bit_algo.master_xfer(adapter, msgs, num);
> +	ret = -EAGAIN;

This does mean we're left to the mercy of the timeout handling in the
i2c core. That is if our gmbus attempt takes too long, we may never
get a chance to retry with bit banging. Not sure if that's a real
concern or not.

Otherwise lgtm.

>  
>  out:
> -	mutex_unlock(&dev_priv->gmbus_mutex);
> +	return ret;
> +}
> +
> +static int
> +gmbus_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
> +{
> +	struct intel_gmbus *bus = container_of(adapter, struct intel_gmbus,
> +					       adapter);
> +	struct drm_i915_private *dev_priv = bus->dev_priv;
> +	int ret;
> +
> +	intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
> +	mutex_lock(&dev_priv->gmbus_mutex);
> +
> +	if (bus->force_bit)
> +		ret = i2c_bit_algo.master_xfer(adapter, msgs, num);
> +	else
> +		ret = do_gmbus_xfer(adapter, msgs, num);
>  
> +	mutex_unlock(&dev_priv->gmbus_mutex);
>  	intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
>  
>  	return ret;
> -- 
> 2.1.4
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

  reply	other threads:[~2015-12-01 14:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-01 14:29 [PATCH 1/2] drm/i915: simplify gmbus xfer error checks Jani Nikula
2015-12-01 14:29 ` [PATCH 2/2] drm/i915: abstract i2c bit banging fallback in gmbus xfer Jani Nikula
2015-12-01 14:57   ` Ville Syrjälä [this message]
2015-12-01 15:38     ` Jani Nikula
2015-12-01 15:52       ` Ville Syrjälä
2015-12-02 11:35         ` Jani Nikula
2015-12-01 14:45 ` [PATCH 1/2] drm/i915: simplify gmbus xfer error checks Ville Syrjälä

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=20151201145720.GE4437@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