2022-12-17 08:28:06

by Aditya Garg

[permalink] [raw]
Subject: [PATCH] HID: Recognize sensors with application collections too.

From: Ronald Tschalär <[email protected]>

According to HUTRR39 logical sensor devices may be nested inside
physical collections or may be specified in multiple top-level
application collections (see page 59, strategies 1 and 2). However,
the current code was only recognizing those with physical collections.

This issue turned up in recent MacBook Pro's which define the ALS in
a top-level application collection.

Signed-off-by: Ronald Tschalär <[email protected]>
Signed-off-by: Aditya Garg <[email protected]>
---
drivers/hid/hid-core.c | 3 ++-
drivers/hid/hid-sensor-hub.c | 6 ++++--
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b7f5566e338d..8fcd663b10e2 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -804,7 +804,8 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
int i;

if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
- type == HID_COLLECTION_PHYSICAL)
+ (type == HID_COLLECTION_PHYSICAL ||
+ type == HID_COLLECTION_APPLICATION))
hid->group = HID_GROUP_SENSOR_HUB;

if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 6abd3e2a9094..d03dc4ca095f 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -397,7 +397,8 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
for (i = 0; i < report->maxfield; ++i) {
field = report->field[i];
if (field->maxusage) {
- if (field->physical == usage_id &&
+ if ((field->physical == usage_id ||
+ field->application == usage_id) &&
(field->logical == attr_usage_id ||
field->usage[0].hid ==
attr_usage_id) &&
@@ -506,7 +507,8 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
collection->usage);

callback = sensor_hub_get_callback(hdev,
- report->field[i]->physical,
+ report->field[i]->physical ?:
+ report->field[i]->application,
report->field[i]->usage[0].collection_index,
&hsdev, &priv);
if (!callback) {
--
2.38.1


2023-01-10 09:52:25

by Aditya Garg

[permalink] [raw]
Subject: [PATCH RESEND] HID: Recognize sensors with application collections too.

From: Ronald Tschalär <[email protected]>

According to HUTRR39 logical sensor devices may be nested inside
physical collections or may be specified in multiple top-level
application collections (see page 59, strategies 1 and 2). However,
the current code was only recognizing those with physical collections.

This issue turned up in the T2 MacBook Pro's which define the ALS in
a top-level application collection.

Signed-off-by: Ronald Tschalär <[email protected]>
---
drivers/hid/hid-core.c | 3 ++-
drivers/hid/hid-sensor-hub.c | 6 ++++--
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b7f5566e338d..8fcd663b10e2 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -804,7 +804,8 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
int i;

if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
- type == HID_COLLECTION_PHYSICAL)
+ (type == HID_COLLECTION_PHYSICAL ||
+ type == HID_COLLECTION_APPLICATION))
hid->group = HID_GROUP_SENSOR_HUB;

if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 6abd3e2a9094..d03dc4ca095f 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -397,7 +397,8 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
for (i = 0; i < report->maxfield; ++i) {
field = report->field[i];
if (field->maxusage) {
- if (field->physical == usage_id &&
+ if ((field->physical == usage_id ||
+ field->application == usage_id) &&
(field->logical == attr_usage_id ||
field->usage[0].hid ==
attr_usage_id) &&
@@ -506,7 +507,8 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
collection->usage);

callback = sensor_hub_get_callback(hdev,
- report->field[i]->physical,
+ report->field[i]->physical ?:
+ report->field[i]->application,
report->field[i]->usage[0].collection_index,
&hsdev, &priv);
if (!callback) {
--
2.38.1

2023-01-10 10:02:55

by Aditya Garg

[permalink] [raw]
Subject: [PATCH v2] HID: Recognize sensors with application collections too.

From: Ronald Tschalär <[email protected]>

According to HUTRR39 logical sensor devices may be nested inside
physical collections or may be specified in multiple top-level
application collections (see page 59, strategies 1 and 2). However,
the current code was only recognizing those with physical collections.

This issue turned up in the T2 MacBook Pro's which define the ALS in
a top-level application collection.

Signed-off-by: Ronald Tschalär <[email protected]>
Signed-off-by: Aditya Garg <[email protected]>

V2 :- Add missing signed-off-by
drivers/hid/hid-core.c | 3 ++-
drivers/hid/hid-sensor-hub.c | 6 ++++--
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b7f5566e338d..8fcd663b10e2 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -804,7 +804,8 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
int i;

if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
- type == HID_COLLECTION_PHYSICAL)
+ (type == HID_COLLECTION_PHYSICAL ||
+ type == HID_COLLECTION_APPLICATION))
hid->group = HID_GROUP_SENSOR_HUB;

if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 6abd3e2a9094..d03dc4ca095f 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -397,7 +397,8 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
for (i = 0; i < report->maxfield; ++i) {
field = report->field[i];
if (field->maxusage) {
- if (field->physical == usage_id &&
+ if ((field->physical == usage_id ||
+ field->application == usage_id) &&
(field->logical == attr_usage_id ||
field->usage[0].hid ==
attr_usage_id) &&
@@ -506,7 +507,8 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
collection->usage);

callback = sensor_hub_get_callback(hdev,
- report->field[i]->physical,
+ report->field[i]->physical ?:
+ report->field[i]->application,
report->field[i]->usage[0].collection_index,
&hsdev, &priv);
if (!callback) {
--
2.38.1

2023-01-10 22:25:28

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v2] HID: Recognize sensors with application collections too.


Don't add full stop at the end.

HID: Recognize sensors with application collection

On Tue, 2023-01-10 at 08:57 +0000, Aditya Garg wrote:
> From: Ronald Tschalär <[email protected]>
>
> According to HUTRR39 logical sensor devices may be nested inside
> physical collections or may be specified in multiple top-level
> application collections (see page 59, strategies 1 and 2). However,
> the current code was only recognizing those with physical
> collections.
>
> This issue turned up in the T2 MacBook Pro's which define the ALS in
> a top-level application collection.
>
> Signed-off-by: Ronald Tschalär <[email protected]>
> Signed-off-by: Aditya Garg <[email protected]>
> —
> V2 :- Add missing signed-off-by
>  drivers/hid/hid-core.c       | 3 ++-
>  drivers/hid/hid-sensor-hub.c | 6 ++++--
>  2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index b7f5566e338d..8fcd663b10e2 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -804,7 +804,8 @@ static void hid_scan_collection(struct hid_parser
> *parser, unsigned type)
>         int i;
>  
>         if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
> -           type == HID_COLLECTION_PHYSICAL)
> +           (type == HID_COLLECTION_PHYSICAL ||
> +            type == HID_COLLECTION_APPLICATION))
>                 hid->group = HID_GROUP_SENSOR_HUB;
>  
>         if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-
> hub.c
> index 6abd3e2a9094..d03dc4ca095f 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -397,7 +397,8 @@ int sensor_hub_input_get_attribute_info(struct
> hid_sensor_hub_device *hsdev,
>                 for (i = 0; i < report->maxfield; ++i) {
>                         field = report->field[i];
>                         if (field->maxusage) {
> -                               if (field->physical == usage_id &&
> +                               if ((field->physical == usage_id ||
> +                                    field->application == usage_id)
> &&
>                                         (field->logical ==
> attr_usage_id ||
>                                         field->usage[0].hid ==
>                                                         attr_usage_id
> ) &&
> @@ -506,7 +507,8 @@ static int sensor_hub_raw_event(struct hid_device
> *hdev,
>                                         collection->usage);
>  
>                 callback = sensor_hub_get_callback(hdev,
> -                               report->field[i]->physical,
> +                               report->field[i]->physical ?:
> +                                       report->field[i]->application
Better not use language extensions. Simple to use

report->field[i]->physical ? report->field[i]->physical : report-
>field[i]->application

Otherwise patch is fine.

Thanks,
Srinivas

> ,
>                                 report->field[i]-
> >usage[0].collection_index,
>                                 &hsdev, &priv);
>                 if (!callback) {
> --
> 2.38.1
>

2023-01-11 10:31:07

by Aditya Garg

[permalink] [raw]
Subject: Re: [PATCH v2] HID: Recognize sensors with application collections too.



> On 11-Jan-2023, at 3:46 AM, srinivas pandruvada <[email protected]> wrote:
>
>
> Don't add full stop at the end.
>
> HID: Recognize sensors with application collection
>
> Better not use language extensions. Simple to use
>
> report->field[i]->physical ? report->field[i]->physical : report-
>> field[i]->application
>
>

Sending a v3 with the changes.


2023-01-11 10:52:49

by Aditya Garg

[permalink] [raw]
Subject: [PATCH v3] HID: Recognize sensors with application collections

From: Ronald Tschalär <[email protected]>

According to HUTRR39 logical sensor devices may be nested inside
physical collections or may be specified in multiple top-level
application collections (see page 59, strategies 1 and 2). However,
the current code was only recognizing those with physical collections.

This issue turned up in the T2 MacBook Pros which define the ALS in
a top-level application collection.

Signed-off-by: Ronald Tschalär <[email protected]>
Signed-off-by: Aditya Garg <[email protected]>
---
V2 :- Add missing signed-off-by
V3 :- Avoid using language extensions
drivers/hid/hid-core.c | 3 ++-
drivers/hid/hid-sensor-hub.c | 6 ++++--
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index bd47628da..8ff08e6c2 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -804,7 +804,8 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
int i;

if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
- type == HID_COLLECTION_PHYSICAL)
+ (type == HID_COLLECTION_PHYSICAL ||
+ type == HID_COLLECTION_APPLICATION))
hid->group = HID_GROUP_SENSOR_HUB;

if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 6abd3e2a9..83237b86c 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -397,7 +397,8 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
for (i = 0; i < report->maxfield; ++i) {
field = report->field[i];
if (field->maxusage) {
- if (field->physical == usage_id &&
+ if ((field->physical == usage_id ||
+ field->application == usage_id) &&
(field->logical == attr_usage_id ||
field->usage[0].hid ==
attr_usage_id) &&
@@ -506,7 +507,8 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
collection->usage);

callback = sensor_hub_get_callback(hdev,
- report->field[i]->physical,
+ report->field[i]->physical ? report->field[i]->physical :
+ report->field[i]->application,
report->field[i]->usage[0].collection_index,
&hsdev, &priv);
if (!callback) {
--
2.34.1

2023-01-11 17:09:38

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v3] HID: Recognize sensors with application collections

On Wed, 2023-01-11 at 10:07 +0000, Aditya Garg wrote:
> From: Ronald Tschalär <[email protected]>
>
> According to HUTRR39 logical sensor devices may be nested inside
> physical collections or may be specified in multiple top-level
> application collections (see page 59, strategies 1 and 2). However,
> the current code was only recognizing those with physical
> collections.
>
> This issue turned up in the T2 MacBook Pros which define the ALS in
> a top-level application collection.
>
> Signed-off-by: Ronald Tschalär <[email protected]>
> Signed-off-by: Aditya Garg <[email protected]>

Since there are some hid core change, Jiri needs to check. If Jiri is
fine with hid core changes:
Acked-by: Srinivas Pandruvada <[email protected]>



> ---
> V2 :- Add missing signed-off-by
> V3 :- Avoid using language extensions
>  drivers/hid/hid-core.c       | 3 ++-
>  drivers/hid/hid-sensor-hub.c | 6 ++++--
>  2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index bd47628da..8ff08e6c2 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -804,7 +804,8 @@ static void hid_scan_collection(struct hid_parser
> *parser, unsigned type)
>         int i;
>  
>         if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
> -           type == HID_COLLECTION_PHYSICAL)
> +           (type == HID_COLLECTION_PHYSICAL ||
> +            type == HID_COLLECTION_APPLICATION))
>                 hid->group = HID_GROUP_SENSOR_HUB;
>  
>         if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-
> hub.c
> index 6abd3e2a9..83237b86c 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -397,7 +397,8 @@ int sensor_hub_input_get_attribute_info(struct
> hid_sensor_hub_device *hsdev,
>                 for (i = 0; i < report->maxfield; ++i) {
>                         field = report->field[i];
>                         if (field->maxusage) {
> -                               if (field->physical == usage_id &&
> +                               if ((field->physical == usage_id ||
> +                                    field->application == usage_id) &&
>                                         (field->logical ==
> attr_usage_id ||
>                                         field->usage[0].hid ==
>                                                         attr_usage_id)
> &&
> @@ -506,7 +507,8 @@ static int sensor_hub_raw_event(struct hid_device
> *hdev,
>                                         collection->usage);
>  
>                 callback = sensor_hub_get_callback(hdev,
> -                               report->field[i]->physical,
> +                               report->field[i]->physical ? report-
> >field[i]->physical :
> +                                                            report-
> >field[i]->application,
>                                 report->field[i]-
> >usage[0].collection_index,
>                                 &hsdev, &priv);
>                 if (!callback) {
> --
> 2.34.1
>


2023-01-18 10:29:14

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH v3] HID: Recognize sensors with application collections

On Wed, 11 Jan 2023, Aditya Garg wrote:

> From: Ronald Tschalär <[email protected]>
>
> According to HUTRR39 logical sensor devices may be nested inside
> physical collections or may be specified in multiple top-level
> application collections (see page 59, strategies 1 and 2). However,
> the current code was only recognizing those with physical collections.
>
> This issue turned up in the T2 MacBook Pros which define the ALS in
> a top-level application collection.
>
> Signed-off-by: Ronald Tschalär <[email protected]>
> Signed-off-by: Aditya Garg <[email protected]>

Makes sense. Queued in for-6.3/hid-core. Thanks,

--
Jiri Kosina
SUSE Labs