Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] iio: cros_ec: Use default frequencies when EC returns invalid information
@ 2020-06-30  7:59 Gwendal Grignou
  2020-06-30 15:12 ` Enric Balletbo i Serra
  0 siblings, 1 reply; 4+ messages in thread
From: Gwendal Grignou @ 2020-06-30  7:59 UTC (permalink / raw)
  To: jic23, bleung, enric.balletbo; +Cc: lars, linux-iio, Gwendal Grignou

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>
---
 .../common/cros_ec_sensors/cros_ec_sensors_core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 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..8437ff659260b 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,8 +345,17 @@ 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;
+			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;
 		}
-- 
2.27.0.212.ge8ba1cc988-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: cros_ec: Use default frequencies when EC returns invalid information
  2020-06-30  7:59 [PATCH] iio: cros_ec: Use default frequencies when EC returns invalid information Gwendal Grignou
@ 2020-06-30 15:12 ` Enric Balletbo i Serra
  2020-06-30 15:31   ` Gwendal Grignou
  0 siblings, 1 reply; 4+ messages in thread
From: Enric Balletbo i Serra @ 2020-06-30 15:12 UTC (permalink / raw)
  To: Gwendal Grignou, jic23, bleung; +Cc: lars, linux-iio

Hi Gwendal,

Thank you for the patch.

On 30/6/20 9:59, 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>
> ---
>  .../common/cros_ec_sensors/cros_ec_sensors_core.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 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..8437ff659260b 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,8 +345,17 @@ 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;
> +			if (state->resp->info_3.max_frequency == 0) {

I might miss some use cases but I am wondering if this can be OR'ed with the
above if, so there is only one call to get_default_min_max_freq

> +				get_default_min_max_freq(state->resp->info.type,
> +							 &frequencies[1],
> +							 &frequencies[2],
> +							 &temp);

and use &state->fifo_max_event_count instead of temp, so you don't need to
create a new variable that is not used anymore. Or is in purpose?

> +			} else {
> +				frequencies[1] =
> +					state->resp->info_3.min_frequency;

nit: I think that you can take advantage of the new 100 character line length
limit, here.

> +				frequencies[2] =
> +					state->resp->info_3.max_frequency;

nit: ditto

> +			}
>  			state->fifo_max_event_count =
>  			    state->resp->info_3.fifo_max_event_count;
>  		}
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: cros_ec: Use default frequencies when EC returns invalid information
  2020-06-30 15:12 ` Enric Balletbo i Serra
@ 2020-06-30 15:31   ` Gwendal Grignou
  2020-06-30 15:49     ` Enric Balletbo i Serra
  0 siblings, 1 reply; 4+ messages in thread
From: Gwendal Grignou @ 2020-06-30 15:31 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Lars-Peter Clausen, linux-iio

On Tue, Jun 30, 2020 at 8:12 AM Enric Balletbo i Serra
<enric.balletbo@collabora.com> wrote:
>
> Hi Gwendal,
>
> Thank you for the patch.
>
> On 30/6/20 9:59, 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>
> > ---
> >  .../common/cros_ec_sensors/cros_ec_sensors_core.c | 15 ++++++++++++---
> >  1 file changed, 12 insertions(+), 3 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..8437ff659260b 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,8 +345,17 @@ 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;
> > +                     if (state->resp->info_3.max_frequency == 0) {
>
> I might miss some use cases but I am wondering if this can be OR'ed with the
> above if, so there is only one call to get_default_min_max_freq
>
> > +                             get_default_min_max_freq(state->resp->info.type,
> > +                                                      &frequencies[1],
> > +                                                      &frequencies[2],
> > +                                                      &temp);
>
> and use &state->fifo_max_event_count instead of temp, so you don't need to
> create a new variable that is not used anymore. Or is in purpose?
It is on purpose: on some machines, min_frequency and max_frequency
are both 0, but fifo_max_event_count is correct and should be used.
>
> > +                     } else {
> > +                             frequencies[1] =
> > +                                     state->resp->info_3.min_frequency;
>
> nit: I think that you can take advantage of the new 100 character line length
> limit, here.
Fixed in the next patch.
>
> > +                             frequencies[2] =
> > +                                     state->resp->info_3.max_frequency;
>
> nit: ditto
>
> > +                     }
> >                       state->fifo_max_event_count =
> >                           state->resp->info_3.fifo_max_event_count;
> >               }
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: cros_ec: Use default frequencies when EC returns invalid information
  2020-06-30 15:31   ` Gwendal Grignou
@ 2020-06-30 15:49     ` Enric Balletbo i Serra
  0 siblings, 0 replies; 4+ messages in thread
From: Enric Balletbo i Serra @ 2020-06-30 15:49 UTC (permalink / raw)
  To: Gwendal Grignou
  Cc: Jonathan Cameron, Benson Leung, Lars-Peter Clausen, linux-iio

Hi Gwendal,

On 30/6/20 17:31, Gwendal Grignou wrote:
> On Tue, Jun 30, 2020 at 8:12 AM Enric Balletbo i Serra
> <enric.balletbo@collabora.com> wrote:
>>
>> Hi Gwendal,
>>
>> Thank you for the patch.
>>
>> On 30/6/20 9:59, 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>
>>> ---
>>>  .../common/cros_ec_sensors/cros_ec_sensors_core.c | 15 ++++++++++++---
>>>  1 file changed, 12 insertions(+), 3 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..8437ff659260b 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,8 +345,17 @@ 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;
>>> +                     if (state->resp->info_3.max_frequency == 0) {
>>
>> I might miss some use cases but I am wondering if this can be OR'ed with the
>> above if, so there is only one call to get_default_min_max_freq
>>
>>> +                             get_default_min_max_freq(state->resp->info.type,
>>> +                                                      &frequencies[1],
>>> +                                                      &frequencies[2],
>>> +                                                      &temp);
>>
>> and use &state->fifo_max_event_count instead of temp, so you don't need to
>> create a new variable that is not used anymore. Or is in purpose?
> It is on purpose: on some machines, min_frequency and max_frequency
> are both 0, but fifo_max_event_count is correct and should be used.

Thanks for the explanation, good to know :-)

>>
>>> +                     } else {
>>> +                             frequencies[1] =
>>> +                                     state->resp->info_3.min_frequency;
>>
>> nit: I think that you can take advantage of the new 100 character line length
>> limit, here.
> Fixed in the next patch.
>>
>>> +                             frequencies[2] =
>>> +                                     state->resp->info_3.max_frequency;
>>
>> nit: ditto
>>
>>> +                     }
>>>                       state->fifo_max_event_count =
>>>                           state->resp->info_3.fifo_max_event_count;
>>>               }
>>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30  7:59 [PATCH] iio: cros_ec: Use default frequencies when EC returns invalid information Gwendal Grignou
2020-06-30 15:12 ` Enric Balletbo i Serra
2020-06-30 15:31   ` Gwendal Grignou
2020-06-30 15:49     ` Enric Balletbo i Serra

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git