linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: srinivas pandruvada <srinivas.pandruvada@linux.intel.com>
To: Philipp Jungkamp <p.jungkamp@gmx.net>,
	Jiri Kosina <jikos@kernel.org>,
	Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v3 4/4] IIO: hid-sensor-prox: Use generic usage
Date: Fri, 18 Nov 2022 12:26:39 -0800	[thread overview]
Message-ID: <960a1f37f63fc56364b5e3e5cf83c67fd7a06730.camel@linux.intel.com> (raw)
In-Reply-To: <20221117234824.6227-4-p.jungkamp@gmx.net>

On Fri, 2022-11-18 at 00:48 +0100, Philipp Jungkamp wrote:
> Use a generic 'hsdev->usage' instead of the HID_USAGE_SENSOR_PROX to
> allow this driver to drive the Lenvo custom proximity sensor, which
> is
> registered under a 'custom' usage and not HID_USAGE_SENSOR_PROX.
> 
> Add the Lenovo Intelligent Sensing Solution (LISS) human presence
> sensor
> to the platform device ids.
> 
> Signed-off-by: Philipp Jungkamp <p.jungkamp@gmx.net>
> ---
> Lines are shorter and the switch statement for raw_len is cleaner.
Didn't understand why this change is required.

Thanks,
Srinivas

> 
>  drivers/iio/light/hid-sensor-prox.c | 37 ++++++++++++++++++---------
> --
>  1 file changed, 23 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/light/hid-sensor-prox.c
> b/drivers/iio/light/hid-sensor-prox.c
> index f10fa2abfe72..a47591e1bad9 100644
> --- a/drivers/iio/light/hid-sensor-prox.c
> +++ b/drivers/iio/light/hid-sensor-prox.c
> @@ -61,6 +61,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
>                               long mask)
>  {
>         struct prox_state *prox_state = iio_priv(indio_dev);
> +       struct hid_sensor_hub_device *hsdev;
>         int report_id = -1;
>         u32 address;
>         int ret_type;
> @@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
>                         report_id = prox_state->prox_attr.report_id;
>                         min = prox_state->prox_attr.logical_minimum;
>                         address = HID_USAGE_SENSOR_HUMAN_PRESENCE;
> +                       hsdev = prox_state->common_attributes.hsdev;
>                         break;
>                 default:
>                         report_id = -1;
> @@ -84,11 +86,8 @@ static int prox_read_raw(struct iio_dev
> *indio_dev,
>                         hid_sensor_power_state(&prox_state-
> >common_attributes,
>                                                 true);
>                         *val = sensor_hub_input_attr_get_raw_value(
> -                               prox_state->common_attributes.hsdev,
> -                               HID_USAGE_SENSOR_PROX, address,
> -                               report_id,
> -                               SENSOR_HUB_SYNC,
> -                               min < 0);
> +                               hsdev, hsdev->usage, address,
> report_id,
> +                               SENSOR_HUB_SYNC, min < 0);
>                         hid_sensor_power_state(&prox_state-
> >common_attributes,
>                                                 false);
>                 } else {
> @@ -191,10 +190,16 @@ static int prox_capture_sample(struct
> hid_sensor_hub_device *hsdev,
> 
>         switch (usage_id) {
>         case HID_USAGE_SENSOR_HUMAN_PRESENCE:
> -               prox_state->human_presence = *(u32 *)raw_data;
> -               ret = 0;
> -               break;
> -       default:
> +               switch (raw_len) {
> +               case 1:
> +                       prox_state->human_presence = *(u8 *)raw_data;
> +                       return 0;
> +               case 4:
> +                       prox_state->human_presence = *(u32
> *)raw_data;
> +                       return 0;
> +               default:
> +                       break;
> +               }
>                 break;
>         }
> 
> @@ -244,7 +249,7 @@ static int hid_prox_probe(struct platform_device
> *pdev)
>         prox_state->common_attributes.hsdev = hsdev;
>         prox_state->common_attributes.pdev = pdev;
> 
> -       ret = hid_sensor_parse_common_attributes(hsdev,
> HID_USAGE_SENSOR_PROX,
> +       ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
>                                         &prox_state-
> >common_attributes,
>                                         prox_sensitivity_addresses,
>                                         ARRAY_SIZE(prox_sensitivity_a
> ddresses));
> @@ -262,7 +267,7 @@ static int hid_prox_probe(struct platform_device
> *pdev)
> 
>         ret = prox_parse_report(pdev, hsdev,
>                                 (struct iio_chan_spec *)indio_dev-
> >channels,
> -                               HID_USAGE_SENSOR_PROX, prox_state);
> +                               hsdev->usage, prox_state);
>         if (ret) {
>                 dev_err(&pdev->dev, "failed to setup attributes\n");
>                 return ret;
> @@ -291,8 +296,8 @@ static int hid_prox_probe(struct platform_device
> *pdev)
>         prox_state->callbacks.send_event = prox_proc_event;
>         prox_state->callbacks.capture_sample = prox_capture_sample;
>         prox_state->callbacks.pdev = pdev;
> -       ret = sensor_hub_register_callback(hsdev,
> HID_USAGE_SENSOR_PROX,
> -                                       &prox_state->callbacks);
> +       ret = sensor_hub_register_callback(hsdev, hsdev->usage,
> +                                          &prox_state->callbacks);
>         if (ret < 0) {
>                 dev_err(&pdev->dev, "callback reg failed\n");
>                 goto error_iio_unreg;
> @@ -314,7 +319,7 @@ static int hid_prox_remove(struct platform_device
> *pdev)
>         struct iio_dev *indio_dev = platform_get_drvdata(pdev);
>         struct prox_state *prox_state = iio_priv(indio_dev);
> 
> -       sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PROX);
> +       sensor_hub_remove_callback(hsdev, hsdev->usage);
>         iio_device_unregister(indio_dev);
>         hid_sensor_remove_trigger(indio_dev, &prox_state-
> >common_attributes);
> 
> @@ -326,6 +331,10 @@ static const struct platform_device_id
> hid_prox_ids[] = {
>                 /* Format: HID-SENSOR-usage_id_in_hex_lowercase */
>                 .name = "HID-SENSOR-200011",
>         },
> +       {
> +               /* Format: HID-SENSOR-tag-usage_id_in_hex_lowercase
> */
> +               .name = "HID-SENSOR-LISS-0226",
> +       },
>         { /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(platform, hid_prox_ids);
> --
> 2.38.1
> 



  reply	other threads:[~2022-11-18 20:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 12:11 PROBLEM: Lenovo ALS sensor disguised under custom usage Philipp Jungkamp
2022-11-16 23:19 ` [PATCH 1/3] HID: hid-sensor-custom: More custom iio sensors Philipp Jungkamp
2022-11-16 23:19   ` [PATCH 2/3] IIO: hid-sensor-als: Use generic usage Philipp Jungkamp
2022-11-17 15:09     ` Jonathan Cameron
2022-11-16 23:19   ` [PATCH 3/3] IIO: hid-sensor-prox: " Philipp Jungkamp
2022-11-17 15:14     ` Jonathan Cameron
2022-11-17 15:05   ` [PATCH 1/3] HID: hid-sensor-custom: More custom iio sensors Jonathan Cameron
2022-11-17 23:42     ` [PATCH v2 1/4] HID: hid-sensor-custom: Allow more " Philipp Jungkamp
2022-11-17 23:43       ` [PATCH v2 2/4] HID: hid-sensor-custom: Add LISS custom sensors Philipp Jungkamp
2022-11-18 20:16         ` srinivas pandruvada
2022-11-17 23:43       ` [PATCH v2 3/4] IIO: hid-sensor-als: Use generic usage Philipp Jungkamp
2022-11-17 23:43       ` [PATCH v2 4/4] IIO: hid-sensor-prox: " Philipp Jungkamp
2022-11-18 20:11       ` [PATCH v2 1/4] HID: hid-sensor-custom: Allow more custom iio sensors srinivas pandruvada
2022-11-17 23:48     ` [PATCH v3 " Philipp Jungkamp
2022-11-17 23:48       ` [PATCH v3 2/4] HID: hid-sensor-custom: Add LISS custom sensors Philipp Jungkamp
2022-11-17 23:48       ` [PATCH v3 3/4] IIO: hid-sensor-als: Use generic usage Philipp Jungkamp
2022-11-18 20:23         ` srinivas pandruvada
2022-11-21 17:59           ` Jiri Kosina
2022-11-21 19:55             ` srinivas pandruvada
2022-11-23 17:16         ` Jonathan Cameron
2022-11-17 23:48       ` [PATCH v3 4/4] IIO: hid-sensor-prox: " Philipp Jungkamp
2022-11-18 20:26         ` srinivas pandruvada [this message]
2022-11-23 17:17         ` Jonathan Cameron
2022-11-23 17:08       ` [PATCH v3 1/4] HID: hid-sensor-custom: Allow more custom iio sensors Jonathan Cameron
2022-11-23 17:10       ` Jonathan Cameron

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=960a1f37f63fc56364b5e3e5cf83c67fd7a06730.camel@linux.intel.com \
    --to=srinivas.pandruvada@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=p.jungkamp@gmx.net \
    /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;
as well as URLs for NNTP newsgroup(s).