diff mbox

[3/4,resend,#2] fb_ddc: Allow I2C adapters without SCL read capability

Message ID 1440445048-24694-3-git-send-email-linux@rainbow-software.org (mailing list archive)
State New, archived
Headers show

Commit Message

Ondrej Zary Aug. 24, 2015, 7:37 p.m. UTC
i2c-algo-bit allows I2C adapters without SCL read capability to work but
fb_ddc_read fails to work on them.

Fix fb_ddc_read to work with I2C adapters not capable of reading SCL.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Acked-by: Krzysztof Helt <krzysztof.h1@wp.pl>
---
 drivers/video/fbdev/core/fb_ddc.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Tomi Valkeinen Sept. 2, 2015, 11:33 a.m. UTC | #1
On 24/08/15 22:37, Ondrej Zary wrote:
> i2c-algo-bit allows I2C adapters without SCL read capability to work but
> fb_ddc_read fails to work on them.
> 
> Fix fb_ddc_read to work with I2C adapters not capable of reading SCL.
> 
> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> Acked-by: Krzysztof Helt <krzysztof.h1@wp.pl>
> ---
>  drivers/video/fbdev/core/fb_ddc.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/fbdev/core/fb_ddc.c b/drivers/video/fbdev/core/fb_ddc.c
> index 94322cc..22c694a 100644
> --- a/drivers/video/fbdev/core/fb_ddc.c
> +++ b/drivers/video/fbdev/core/fb_ddc.c
> @@ -69,10 +69,11 @@ unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
>  		algo_data->setscl(algo_data->data, 1);
>  		for (j = 0; j < 5; j++) {
>  			msleep(10);
> -			if (algo_data->getscl(algo_data->data))
> +			if (algo_data->getscl &&
> +			    algo_data->getscl(algo_data->data))
>  				break;
>  		}
> -		if (j == 5)
> +		if (algo_data->getscl && j == 5)
>  			continue;
>  
>  		algo_data->setsda(algo_data->data, 0);
> @@ -91,7 +92,8 @@ unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
>  		algo_data->setscl(algo_data->data, 1);
>  		for (j = 0; j < 10; j++) {
>  			msleep(10);
> -			if (algo_data->getscl(algo_data->data))
> +			if (algo_data->getscl &&
> +			    algo_data->getscl(algo_data->data))
>  				break;
>  		}

Aren't both of those loops pointless if there's no getscl?

 Tomi
Ondrej Zary Sept. 2, 2015, 12:04 p.m. UTC | #2
On Wednesday 02 September 2015, Tomi Valkeinen wrote:
> On 24/08/15 22:37, Ondrej Zary wrote:
> > i2c-algo-bit allows I2C adapters without SCL read capability to work but
> > fb_ddc_read fails to work on them.
> >
> > Fix fb_ddc_read to work with I2C adapters not capable of reading SCL.
> >
> > Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> > Acked-by: Krzysztof Helt <krzysztof.h1@wp.pl>
> > ---
> >  drivers/video/fbdev/core/fb_ddc.c |    8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/video/fbdev/core/fb_ddc.c
> > b/drivers/video/fbdev/core/fb_ddc.c index 94322cc..22c694a 100644
> > --- a/drivers/video/fbdev/core/fb_ddc.c
> > +++ b/drivers/video/fbdev/core/fb_ddc.c
> > @@ -69,10 +69,11 @@ unsigned char *fb_ddc_read(struct i2c_adapter
> > *adapter) algo_data->setscl(algo_data->data, 1);
> >  		for (j = 0; j < 5; j++) {
> >  			msleep(10);
> > -			if (algo_data->getscl(algo_data->data))
> > +			if (algo_data->getscl &&
> > +			    algo_data->getscl(algo_data->data))
> >  				break;
> >  		}
> > -		if (j == 5)
> > +		if (algo_data->getscl && j == 5)
> >  			continue;
> >
> >  		algo_data->setsda(algo_data->data, 0);
> > @@ -91,7 +92,8 @@ unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
> >  		algo_data->setscl(algo_data->data, 1);
> >  		for (j = 0; j < 10; j++) {
> >  			msleep(10);
> > -			if (algo_data->getscl(algo_data->data))
> > +			if (algo_data->getscl &&
> > +			    algo_data->getscl(algo_data->data))
> >  				break;
> >  		}
>
> Aren't both of those loops pointless if there's no getscl?

They're reduced to delays - don't know how much critical they are.
Tomi Valkeinen Sept. 24, 2015, 11:04 a.m. UTC | #3
On 02/09/15 15:04, Ondrej Zary wrote:
> On Wednesday 02 September 2015, Tomi Valkeinen wrote:
>> On 24/08/15 22:37, Ondrej Zary wrote:
>>> i2c-algo-bit allows I2C adapters without SCL read capability to work but
>>> fb_ddc_read fails to work on them.
>>>
>>> Fix fb_ddc_read to work with I2C adapters not capable of reading SCL.
>>>
>>> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
>>> Acked-by: Krzysztof Helt <krzysztof.h1@wp.pl>
>>> ---
>>>  drivers/video/fbdev/core/fb_ddc.c |    8 +++++---
>>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/video/fbdev/core/fb_ddc.c
>>> b/drivers/video/fbdev/core/fb_ddc.c index 94322cc..22c694a 100644
>>> --- a/drivers/video/fbdev/core/fb_ddc.c
>>> +++ b/drivers/video/fbdev/core/fb_ddc.c
>>> @@ -69,10 +69,11 @@ unsigned char *fb_ddc_read(struct i2c_adapter
>>> *adapter) algo_data->setscl(algo_data->data, 1);
>>>  		for (j = 0; j < 5; j++) {
>>>  			msleep(10);
>>> -			if (algo_data->getscl(algo_data->data))
>>> +			if (algo_data->getscl &&
>>> +			    algo_data->getscl(algo_data->data))
>>>  				break;
>>>  		}
>>> -		if (j == 5)
>>> +		if (algo_data->getscl && j == 5)
>>>  			continue;
>>>
>>>  		algo_data->setsda(algo_data->data, 0);
>>> @@ -91,7 +92,8 @@ unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
>>>  		algo_data->setscl(algo_data->data, 1);
>>>  		for (j = 0; j < 10; j++) {
>>>  			msleep(10);
>>> -			if (algo_data->getscl(algo_data->data))
>>> +			if (algo_data->getscl &&
>>> +			    algo_data->getscl(algo_data->data))
>>>  				break;
>>>  		}
>>
>> Aren't both of those loops pointless if there's no getscl?
> 
> They're reduced to delays - don't know how much critical they are.

I think the code gets somewhat confusing the way you did it.

Maybe instead something like:

if (algo_data->getscl) {
	the current loop & delays here;
} else {
	msleep(25); // 25 was just a guess...
}

 Tomi
diff mbox

Patch

diff --git a/drivers/video/fbdev/core/fb_ddc.c b/drivers/video/fbdev/core/fb_ddc.c
index 94322cc..22c694a 100644
--- a/drivers/video/fbdev/core/fb_ddc.c
+++ b/drivers/video/fbdev/core/fb_ddc.c
@@ -69,10 +69,11 @@  unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
 		algo_data->setscl(algo_data->data, 1);
 		for (j = 0; j < 5; j++) {
 			msleep(10);
-			if (algo_data->getscl(algo_data->data))
+			if (algo_data->getscl &&
+			    algo_data->getscl(algo_data->data))
 				break;
 		}
-		if (j == 5)
+		if (algo_data->getscl && j == 5)
 			continue;
 
 		algo_data->setsda(algo_data->data, 0);
@@ -91,7 +92,8 @@  unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
 		algo_data->setscl(algo_data->data, 1);
 		for (j = 0; j < 10; j++) {
 			msleep(10);
-			if (algo_data->getscl(algo_data->data))
+			if (algo_data->getscl &&
+			    algo_data->getscl(algo_data->data))
 				break;
 		}