drm/i915: simplify gmbus xfer error checks
Subsystems (2)
PATCH 1/2 drm/i915: simplify gmbus xfer error checks
Shorter, easier to follow code with no functional changes. In all cases, the return value ultimately comes from gmbus_wait_hw_status() anyway.
--- drivers/gpu/drm/i915/intel_i2c.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/intel_i2c.c +4 -8
@@ -505,17 +505,13 @@ retry: ret =gmbus_xfer_write (dev_priv, &msgs[i]); } +if (!ret) + ret =gmbus_wait_hw_status (dev_priv,GMBUS_HW_WAIT_PHASE , +GMBUS_HW_WAIT_EN );if (ret == -ETIMEDOUT ) goto timeout; -if (ret == -ENXIO ) +else if (ret) goto clear_err; - - ret =gmbus_wait_hw_status (dev_priv,GMBUS_HW_WAIT_PHASE , -GMBUS_HW_WAIT_EN ); -if (ret == -ENXIO ) - goto clear_err; -if (ret) - goto timeout; }/* Generate a STOP condition on the bus. Note that gmbus can't generata
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/2 drm/i915: abstract i2c bit banging fallback in gmbus xfer
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.
--- drivers/gpu/drm/i915/intel_i2c.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/intel_i2c.c +25 -14
@@ -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 ; 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;
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: abstract i2c bit banging fallback in gmbus xfer
Quoted 40 lines · Jani Nikula
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 <[email protected]>--- drivers/gpu/drm/i915/intel_i2c.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)drivers/gpu/drm/i915/intel_i2c.c +1
-11@@ -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);
drivers/gpu/drm/i915/intel_i2c.c timeout: · line 583
Quoted 10 lines
drivers/gpu/drm/i915/intel_i2c.c +5
-2I915_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.
Quoted 33 lines
drivers/gpu/drm/i915/intel_i2c.c +19
-1out: -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;Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: abstract i2c bit banging fallback in gmbus xfer
Quoted 43 lines · Ville Syrjälä
Quoted 42 lines · Jani Nikula
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 <[email protected]>--- drivers/gpu/drm/i915/intel_i2c.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)drivers/gpu/drm/i915/intel_i2c.c +1
-11@@ -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 );
Quoted 13 lines
drivers/gpu/drm/i915/intel_i2c.c timeout: · line 583
Quoted 8 lines
drivers/gpu/drm/i915/intel_i2c.c +5
-2-/* 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.
IIUC the longest it can take to transfer 4 bytes without timing out is just under 50 ms. The i2c core use a default timeout of 1000 ms. So if we first succesfully, but slowly manage to transfer quite a bit (well, at least 80 bytes, almost but not quite timing out), and then time out, i2c core won't try again.
I do not think this is a real concern, but if it is, we can increase the adapter->timeout in our gmbus setup code.
BR,
Jani.
Quoted 36 lines
Otherwise lgtm.
Quoted 33 lines
drivers/gpu/drm/i915/intel_i2c.c +19
-1out: -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;Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Ville Syrjälä
Reviewed-byRe: [PATCH 2/2] drm/i915: abstract i2c bit banging fallback in gmbus xfer
Quoted 58 lines · Jani Nikula
Quoted 43 lines · Ville Syrjälä
Quoted 42 lines · Jani Nikula
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 <[email protected]>--- drivers/gpu/drm/i915/intel_i2c.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)drivers/gpu/drm/i915/intel_i2c.c +1
-11@@ -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 );Quoted 13 lines
drivers/gpu/drm/i915/intel_i2c.c timeout: · line 583
Quoted 8 lines
drivers/gpu/drm/i915/intel_i2c.c +5
-2-/* 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.
Quoted 8 lines
IIUC the longest it can take to transfer 4 bytes without timing out is just under 50 ms. The i2c core use a default timeout of 1000 ms. So if we first succesfully, but slowly manage to transfer quite a bit (well, at least 80 bytes, almost but not quite timing out), and then time out, i2c core won't try again.
I do not think this is a real concern, but if it is, we can increase the
adapter->timeoutin our gmbus setup code.
Hmm. I was thinking it's shorter than that, but I guess I was mixing it up with the i2c-bit-algo timeout which is 2.2ms (per some DDC spec IIRC).
1 second seems plenty enough to me.
Quoted 45 lines
BR,
Jani.Quoted 36 lines
Otherwise lgtm.
Quoted 33 lines
drivers/gpu/drm/i915/intel_i2c.c +19
-1out: -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;Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfxSignature · 1 line
Jani Nikula, Intel Open Source Technology Center
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: abstract i2c bit banging fallback in gmbus xfer
Quoted 68 lines · Ville Syrjälä
Quoted 58 lines · Jani Nikula
Quoted 43 lines · Ville Syrjälä
Quoted 42 lines · Jani Nikula
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 <[email protected]>--- drivers/gpu/drm/i915/intel_i2c.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)drivers/gpu/drm/i915/intel_i2c.c +1
-11@@ -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 );Quoted 13 lines
drivers/gpu/drm/i915/intel_i2c.c timeout: · line 583
Quoted 8 lines
drivers/gpu/drm/i915/intel_i2c.c +5
-2-/* 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.
Quoted 8 lines
IIUC the longest it can take to transfer 4 bytes without timing out is just under 50 ms. The i2c core use a default timeout of 1000 ms. So if we first succesfully, but slowly manage to transfer quite a bit (well, at least 80 bytes, almost but not quite timing out), and then time out, i2c core won't try again.
I do not think this is a real concern, but if it is, we can increase the
adapter->timeoutin our gmbus setup code.
Quoted 7 lines
Hmm. I was thinking it's shorter than that, but I guess I was mixing it up with the i2c-bit-algo timeout which is 2.2ms (per some DDC spec IIRC).
1 second seems plenty enough to me.
Reviewed-by Ville Syrjälä <[email protected]>
Both pushed to drm-intel-next-queued, thanks for the review.
BR,
Jani.
Quoted 46 lines
Quoted 46 lines
BR,
Jani.Quoted 36 lines
Otherwise lgtm.
Quoted 33 lines
drivers/gpu/drm/i915/intel_i2c.c +19
-1out: -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;Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfxSignature · 1 line
Jani Nikula, Intel Open Source Technology Center
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 21 lines · Jani Nikula
Shorter, easier to follow code with no functional changes. In all cases, the return value ultimately comes from
gmbus_wait_hw_status()anyway.Signed-off-by Jani Nikula <[email protected]>--- drivers/gpu/drm/i915/intel_i2c.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)drivers/gpu/drm/i915/intel_i2c.c +3
-0@@ -505,17 +505,13 @@ retry: ret =gmbus_xfer_write (dev_priv, &msgs[i]); } +if (!ret) + ret =gmbus_wait_hw_status (dev_priv,GMBUS_HW_WAIT_PHASE , +GMBUS_HW_WAIT_EN );if (ret == -ETIMEDOUT ) goto timeout;
drivers/gpu/drm/i915/intel_i2c.c retry: · line 518
Quoted 10 lines
drivers/gpu/drm/i915/intel_i2c.c +1
-8-if (ret == -ENXIO ) +else if (ret) goto clear_err; - - ret =gmbus_wait_hw_status (dev_priv,GMBUS_HW_WAIT_PHASE , -GMBUS_HW_WAIT_EN ); -if (ret == -ENXIO ) - goto clear_err; -if (ret) - goto timeout;
Hmm. So gmbus_waut_hw_status() only ever returns -ENXIO,-ETIMEDOUT,0. And since the xfer functions return value also comes from gmbus_wait_hw_status() the same holds for them.
For -ENXIO we want to go to clear_err, for -ETIMEDOUT we want to go to timeout. Other error values can't happen so the old 'if (ret)' case actually checks for timeouts. So even if you sort of reversed the checks there, it actually still checks for the same thing.
Quoted 10 lines
drivers/gpu/drm/i915/intel_i2c.c +0
-0}/* Generate a STOP condition on the bus. Note that gmbus can't generata Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx