diff mbox series

[v2] iio: cros_ec: Use default frequencies when EC returns invalid information

Message ID 20200630153730.3302889-1-gwendal@chromium.org (mailing list archive)
State New, archived
Headers show
Series [v2] iio: cros_ec: Use default frequencies when EC returns invalid information | expand

Commit Message

Gwendal Grignou June 30, 2020, 3:37 p.m. UTC
Minimal and maximal frequencies supported by a sensor is queried.
On some older machines, these frequencies are not returned properly and
the EC returns 0 instead.
When returned maximal frequency is 0, ignore the information and use
default frequencies instead.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
Changes since v1:
- improve visibility by using new 100 character line length limit.

 .../cros_ec_sensors/cros_ec_sensors_core.c       | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Enric Balletbo i Serra June 30, 2020, 3:50 p.m. UTC | #1
Hi Gwendal,

On 30/6/20 17:37, Gwendal Grignou wrote:
> Minimal and maximal frequencies supported by a sensor is queried.
> On some older machines, these frequencies are not returned properly and
> the EC returns 0 instead.
> When returned maximal frequency is 0, ignore the information and use
> default frequencies instead.
> 
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>

Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

> ---
> Changes since v1:
> - improve visibility by using new 100 character line length limit.
> 
>  .../cros_ec_sensors/cros_ec_sensors_core.c       | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> index 36e3f20891f05..b30fd6b56773f 100644
> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> @@ -289,7 +289,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>  	struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
>  	struct cros_ec_dev *ec = sensor_hub->ec;
>  	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
> -	u32 ver_mask;
> +	u32 ver_mask, temp;
>  	int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
>  	int ret, i;
>  
> @@ -345,10 +345,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>  						 &frequencies[2],
>  						 &state->fifo_max_event_count);
>  		} else {
> -			frequencies[1] = state->resp->info_3.min_frequency;
> -			frequencies[2] = state->resp->info_3.max_frequency;
> -			state->fifo_max_event_count =
> -			    state->resp->info_3.fifo_max_event_count;
> +			if (state->resp->info_3.max_frequency == 0) {
> +				get_default_min_max_freq(state->resp->info.type,
> +							 &frequencies[1],
> +							 &frequencies[2],
> +							 &temp);
> +			} else {
> +				frequencies[1] = state->resp->info_3.min_frequency;
> +				frequencies[2] = state->resp->info_3.max_frequency;
> +			}
> +			state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
>  		}
>  		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
>  			state->frequencies[2 * i] = frequencies[i] / 1000;
>
Jonathan Cameron July 4, 2020, 4:44 p.m. UTC | #2
On Tue, 30 Jun 2020 17:50:24 +0200
Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:

> Hi Gwendal,
> 
> On 30/6/20 17:37, Gwendal Grignou wrote:
> > Minimal and maximal frequencies supported by a sensor is queried.
> > On some older machines, these frequencies are not returned properly and
> > the EC returns 0 instead.
> > When returned maximal frequency is 0, ignore the information and use
> > default frequencies instead.
> > 
> > Signed-off-by: Gwendal Grignou <gwendal@chromium.org>  
> 
> Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

Fix or tidy up? I.e. does this want to go into stable?

Thanks,

Jonathan

> 
> > ---
> > Changes since v1:
> > - improve visibility by using new 100 character line length limit.
> > 
> >  .../cros_ec_sensors/cros_ec_sensors_core.c       | 16 +++++++++++-----
> >  1 file changed, 11 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > index 36e3f20891f05..b30fd6b56773f 100644
> > --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > @@ -289,7 +289,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> >  	struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
> >  	struct cros_ec_dev *ec = sensor_hub->ec;
> >  	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
> > -	u32 ver_mask;
> > +	u32 ver_mask, temp;
> >  	int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
> >  	int ret, i;
> >  
> > @@ -345,10 +345,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> >  						 &frequencies[2],
> >  						 &state->fifo_max_event_count);
> >  		} else {
> > -			frequencies[1] = state->resp->info_3.min_frequency;
> > -			frequencies[2] = state->resp->info_3.max_frequency;
> > -			state->fifo_max_event_count =
> > -			    state->resp->info_3.fifo_max_event_count;
> > +			if (state->resp->info_3.max_frequency == 0) {
> > +				get_default_min_max_freq(state->resp->info.type,
> > +							 &frequencies[1],
> > +							 &frequencies[2],
> > +							 &temp);
> > +			} else {
> > +				frequencies[1] = state->resp->info_3.min_frequency;
> > +				frequencies[2] = state->resp->info_3.max_frequency;
> > +			}
> > +			state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
> >  		}
> >  		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> >  			state->frequencies[2 * i] = frequencies[i] / 1000;
> >
Jonathan Cameron Sept. 26, 2020, 3:21 p.m. UTC | #3
On Sat, 4 Jul 2020 17:44:37 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Tue, 30 Jun 2020 17:50:24 +0200
> Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:
> 
> > Hi Gwendal,
> > 
> > On 30/6/20 17:37, Gwendal Grignou wrote:  
> > > Minimal and maximal frequencies supported by a sensor is queried.
> > > On some older machines, these frequencies are not returned properly and
> > > the EC returns 0 instead.
> > > When returned maximal frequency is 0, ignore the information and use
> > > default frequencies instead.
> > > 
> > > Signed-off-by: Gwendal Grignou <gwendal@chromium.org>    
> > 
> > Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>  
> 
> Fix or tidy up? I.e. does this want to go into stable?

I've still not applied this one due to the above question.

If I don't hear reasonably soon I'll guess tidy up and queue
it up.

Thanks,

Jonathan

> 
> Thanks,
> 
> Jonathan
> 
> >   
> > > ---
> > > Changes since v1:
> > > - improve visibility by using new 100 character line length limit.
> > > 
> > >  .../cros_ec_sensors/cros_ec_sensors_core.c       | 16 +++++++++++-----
> > >  1 file changed, 11 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > > index 36e3f20891f05..b30fd6b56773f 100644
> > > --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> > > @@ -289,7 +289,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> > >  	struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
> > >  	struct cros_ec_dev *ec = sensor_hub->ec;
> > >  	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
> > > -	u32 ver_mask;
> > > +	u32 ver_mask, temp;
> > >  	int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
> > >  	int ret, i;
> > >  
> > > @@ -345,10 +345,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> > >  						 &frequencies[2],
> > >  						 &state->fifo_max_event_count);
> > >  		} else {
> > > -			frequencies[1] = state->resp->info_3.min_frequency;
> > > -			frequencies[2] = state->resp->info_3.max_frequency;
> > > -			state->fifo_max_event_count =
> > > -			    state->resp->info_3.fifo_max_event_count;
> > > +			if (state->resp->info_3.max_frequency == 0) {
> > > +				get_default_min_max_freq(state->resp->info.type,
> > > +							 &frequencies[1],
> > > +							 &frequencies[2],
> > > +							 &temp);
> > > +			} else {
> > > +				frequencies[1] = state->resp->info_3.min_frequency;
> > > +				frequencies[2] = state->resp->info_3.max_frequency;
> > > +			}
> > > +			state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
> > >  		}
> > >  		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> > >  			state->frequencies[2 * i] = frequencies[i] / 1000;
> > >     
>
Enric Balletbo i Serra Oct. 1, 2020, 4:52 p.m. UTC | #4
Hi Jonathan,

Sorry for the late reply.

On 26/9/20 17:21, Jonathan Cameron wrote:
> On Sat, 4 Jul 2020 17:44:37 +0100
> Jonathan Cameron <jic23@kernel.org> wrote:
> 
>> On Tue, 30 Jun 2020 17:50:24 +0200
>> Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:
>>
>>> Hi Gwendal,
>>>
>>> On 30/6/20 17:37, Gwendal Grignou wrote:  
>>>> Minimal and maximal frequencies supported by a sensor is queried.
>>>> On some older machines, these frequencies are not returned properly and
>>>> the EC returns 0 instead.
>>>> When returned maximal frequency is 0, ignore the information and use
>>>> default frequencies instead.
>>>>
>>>> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>    
>>>
>>> Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>  
>>
>> Fix or tidy up? I.e. does this want to go into stable?
> 
> I've still not applied this one due to the above question.
> 
> If I don't hear reasonably soon I'll guess tidy up and queue
> it up.
> 

I think that should be a fix, although it might require some backport effort to
apply the patch cleanly on older stable versions as there were some changes
between the problem was introduced and the fix.

Fixes: ae7b02ad2f32 ("iio: common: cros_ec_sensors: Expose cros_ec_sensors
frequency range via iio sysfs")

Thanks,
 Enric

> Thanks,
> 
> Jonathan
> 
>>
>> Thanks,
>>
>> Jonathan
>>
>>>   
>>>> ---
>>>> Changes since v1:
>>>> - improve visibility by using new 100 character line length limit.
>>>>
>>>>  .../cros_ec_sensors/cros_ec_sensors_core.c       | 16 +++++++++++-----
>>>>  1 file changed, 11 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>>>> index 36e3f20891f05..b30fd6b56773f 100644
>>>> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>>>> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
>>>> @@ -289,7 +289,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>>>>  	struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
>>>>  	struct cros_ec_dev *ec = sensor_hub->ec;
>>>>  	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
>>>> -	u32 ver_mask;
>>>> +	u32 ver_mask, temp;
>>>>  	int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
>>>>  	int ret, i;
>>>>  
>>>> @@ -345,10 +345,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
>>>>  						 &frequencies[2],
>>>>  						 &state->fifo_max_event_count);
>>>>  		} else {
>>>> -			frequencies[1] = state->resp->info_3.min_frequency;
>>>> -			frequencies[2] = state->resp->info_3.max_frequency;
>>>> -			state->fifo_max_event_count =
>>>> -			    state->resp->info_3.fifo_max_event_count;
>>>> +			if (state->resp->info_3.max_frequency == 0) {
>>>> +				get_default_min_max_freq(state->resp->info.type,
>>>> +							 &frequencies[1],
>>>> +							 &frequencies[2],
>>>> +							 &temp);
>>>> +			} else {
>>>> +				frequencies[1] = state->resp->info_3.min_frequency;
>>>> +				frequencies[2] = state->resp->info_3.max_frequency;
>>>> +			}
>>>> +			state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
>>>>  		}
>>>>  		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
>>>>  			state->frequencies[2 * i] = frequencies[i] / 1000;
>>>>     
>>
>
Jonathan Cameron Oct. 10, 2020, 1:19 p.m. UTC | #5
On Thu, 1 Oct 2020 18:52:16 +0200
Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:

> Hi Jonathan,
> 
> Sorry for the late reply.
> 
> On 26/9/20 17:21, Jonathan Cameron wrote:
> > On Sat, 4 Jul 2020 17:44:37 +0100
> > Jonathan Cameron <jic23@kernel.org> wrote:
> >   
> >> On Tue, 30 Jun 2020 17:50:24 +0200
> >> Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote:
> >>  
> >>> Hi Gwendal,
> >>>
> >>> On 30/6/20 17:37, Gwendal Grignou wrote:    
> >>>> Minimal and maximal frequencies supported by a sensor is queried.
> >>>> On some older machines, these frequencies are not returned properly and
> >>>> the EC returns 0 instead.
> >>>> When returned maximal frequency is 0, ignore the information and use
> >>>> default frequencies instead.
> >>>>
> >>>> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>      
> >>>
> >>> Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>    
> >>
> >> Fix or tidy up? I.e. does this want to go into stable?  
> > 
> > I've still not applied this one due to the above question.
> > 
> > If I don't hear reasonably soon I'll guess tidy up and queue
> > it up.
> >   
> 
> I think that should be a fix, although it might require some backport effort to
> apply the patch cleanly on older stable versions as there were some changes
> between the problem was introduced and the fix.
> 
> Fixes: ae7b02ad2f32 ("iio: common: cros_ec_sensors: Expose cros_ec_sensors
> frequency range via iio sysfs")
Applied to the fixes-togreg branch of iio.git and marked for stable.
This won't go upstream until after the merge window though given timing.

Thanks,

Jonathan

> 
> Thanks,
>  Enric
> 
> > Thanks,
> > 
> > Jonathan
> >   
> >>
> >> Thanks,
> >>
> >> Jonathan
> >>  
> >>>     
> >>>> ---
> >>>> Changes since v1:
> >>>> - improve visibility by using new 100 character line length limit.
> >>>>
> >>>>  .../cros_ec_sensors/cros_ec_sensors_core.c       | 16 +++++++++++-----
> >>>>  1 file changed, 11 insertions(+), 5 deletions(-)
> >>>>
> >>>> diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> >>>> index 36e3f20891f05..b30fd6b56773f 100644
> >>>> --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> >>>> +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
> >>>> @@ -289,7 +289,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> >>>>  	struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
> >>>>  	struct cros_ec_dev *ec = sensor_hub->ec;
> >>>>  	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
> >>>> -	u32 ver_mask;
> >>>> +	u32 ver_mask, temp;
> >>>>  	int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
> >>>>  	int ret, i;
> >>>>  
> >>>> @@ -345,10 +345,16 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
> >>>>  						 &frequencies[2],
> >>>>  						 &state->fifo_max_event_count);
> >>>>  		} else {
> >>>> -			frequencies[1] = state->resp->info_3.min_frequency;
> >>>> -			frequencies[2] = state->resp->info_3.max_frequency;
> >>>> -			state->fifo_max_event_count =
> >>>> -			    state->resp->info_3.fifo_max_event_count;
> >>>> +			if (state->resp->info_3.max_frequency == 0) {
> >>>> +				get_default_min_max_freq(state->resp->info.type,
> >>>> +							 &frequencies[1],
> >>>> +							 &frequencies[2],
> >>>> +							 &temp);
> >>>> +			} else {
> >>>> +				frequencies[1] = state->resp->info_3.min_frequency;
> >>>> +				frequencies[2] = state->resp->info_3.max_frequency;
> >>>> +			}
> >>>> +			state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
> >>>>  		}
> >>>>  		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
> >>>>  			state->frequencies[2 * i] = frequencies[i] / 1000;
> >>>>       
> >>  
> >
diff mbox series

Patch

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index 36e3f20891f05..b30fd6b56773f 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -289,7 +289,7 @@  int cros_ec_sensors_core_init(struct platform_device *pdev,
 	struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
 	struct cros_ec_dev *ec = sensor_hub->ec;
 	struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
-	u32 ver_mask;
+	u32 ver_mask, temp;
 	int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
 	int ret, i;
 
@@ -345,10 +345,16 @@  int cros_ec_sensors_core_init(struct platform_device *pdev,
 						 &frequencies[2],
 						 &state->fifo_max_event_count);
 		} else {
-			frequencies[1] = state->resp->info_3.min_frequency;
-			frequencies[2] = state->resp->info_3.max_frequency;
-			state->fifo_max_event_count =
-			    state->resp->info_3.fifo_max_event_count;
+			if (state->resp->info_3.max_frequency == 0) {
+				get_default_min_max_freq(state->resp->info.type,
+							 &frequencies[1],
+							 &frequencies[2],
+							 &temp);
+			} else {
+				frequencies[1] = state->resp->info_3.min_frequency;
+				frequencies[2] = state->resp->info_3.max_frequency;
+			}
+			state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
 		}
 		for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
 			state->frequencies[2 * i] = frequencies[i] / 1000;