Skip to contentSkip to conversation

iio: hid-sensor: Fix scale for magnetic north heading

PATCH Applied Maximilian Czirr 3 participants 5 messages Oct 7 – Nov 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: hid-sensor: Fix scale for magnetic north heading

hid_sensor_format_scale() applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].

Rotation-from-north support uses HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in the conversion table. As a result, the unit exponent is ignored and the heading can be exposed with a scale of 1 instead of the scale specified by the HID descriptor.

Add a unitless conversion entry so the HID unit exponent is applied to the magnetic north heading. A sensor reporting an exponent of -5 then correctly exposes a scale of 0.00001 instead of 1.

Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support for rotation from north")
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
index 9e7c26e37880..26f8554d18a5 100644
@@ -38,6 +38,8 @@ static const struct {
 	{HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000},
 	{HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
 
+	{HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0},
+
 	{HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293},
 	{HID_USAGE_SENSOR_INCLINOMETER_3D,
 		HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
Signature · 1 line
2.56.0
maintainer
#1 lore raw
Quoted 9 lines · On Wed, 7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:

hid_sensor_format_scale() applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].

Rotation-from-north support uses HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in the conversion table. As a result, the unit exponent is ignored and the heading can be exposed with a scale of 1 instead of the scale specified by the HID descriptor.

Quoted 7 lines

Add a unitless conversion entry so the HID unit exponent is applied to the magnetic north heading. A sensor reporting an exponent of -5 then correctly exposes a scale of 0.00001 instead of 1.

Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support for rotation from north")

+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.

Quoted 17 lines
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
index 9e7c26e37880..26f8554d18a5 100644
@@ -38,6 +38,8 @@ static const struct {
 	{HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000},
 	{HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
 
+	{HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0},
+
 	{HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293},
 	{HID_USAGE_SENSOR_INCLINOMETER_3D,
 		HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
maintainer
#2 lore raw
Quoted 16 lines · On Sun, 18 Oct 2026 20:36:59 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 13 lines · On Wed, 7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:

hid_sensor_format_scale() applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].

Rotation-from-north support uses HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in the conversion table. As a result, the unit exponent is ignored and the heading can be exposed with a scale of 1 instead of the scale specified by the HID descriptor.

Add a unitless conversion entry so the HID unit exponent is applied to the magnetic north heading. A sensor reporting an exponent of -5 then correctly exposes a scale of 0.00001 instead of 1.

Quoted 7 lines
Quoted 3 lines
Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support for rotation from north")

+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.

Srinivas, another one for you to check when you have a moment!

No huge rush - I'm just having a scan through what is outstanding in patchwork to make sure I didn't miss anything.

thanks

Jonathan

Quoted 19 lines
Quoted 17 lines
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
index 9e7c26e37880..26f8554d18a5 100644
@@ -38,6 +38,8 @@ static const struct {
 	{HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000},
 	{HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
 
+	{HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0},
+
 	{HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293},
 	{HID_USAGE_SENSOR_INCLINOMETER_3D,
 		HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},  
#3 lore raw
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 18 Oct 2026 20:36:59 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 18 lines · On Wed,  7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:

hid_sensor_format_scale() applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].

Rotation-from-north support uses HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in
the conversion table. As a result, the unit exponent is ignored and the
heading can be exposed with a scale of 1 instead of the scale specified
by the HID descriptor.

Add a unitless conversion entry so the HID unit exponent is applied to
the magnetic north heading. A sensor reporting an exponent of -5 then
correctly exposes a scale of 0.00001 instead of 1.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support for

rotation from north")

Quoted 33 lines
Quoted 3 lines

+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.

Srinivas, another one for you to check when you have a moment!

No huge rush - I'm just having a scan through what is outstanding in patchwork to make sure I didn't miss anything.

thanks

Jonathan

Quoted 22 lines
Quoted 20 lines

---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++

 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

attributes.c b/drivers/iio/common/hid-sensors/hid-sensor- attributes.c
index 9e7c26e37880..26f8554d18a5 100644

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
@@ -38,6 +38,8 @@ static const struct {
  	{HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000},
  	{HID_USAGE_SENSOR_COMPASS_3D,
 HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
+	{HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0},
+

  {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293}, {HID_USAGE_SENSOR_INCLINOMETER_3D, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},

maintainer Applied
#4 lore raw
Quoted 25 lines · On Mon, 02 Nov 2026 09:15:07 -0800 srinivas pandruvada…
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 18 Oct 2026 20:36:59 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 18 lines · On Wed,  7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:

hid_sensor_format_scale() applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].

Rotation-from-north support uses HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in
the conversion table. As a result, the unit exponent is ignored and the
heading can be exposed with a scale of 1 instead of the scale specified
by the HID descriptor.

Add a unitless conversion entry so the HID unit exponent is applied to
the magnetic north heading. A sensor reporting an exponent of -5 then
correctly exposes a scale of 0.00001 instead of 1.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support for

rotation from north")

Thanks.

Applied to the fixes-togreg branch of iio.git

Jonathan

Quoted 34 lines
Quoted 34 lines
Quoted 4 lines

+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.

Srinivas, another one for you to check when you have a moment!

No huge rush - I'm just having a scan through what is outstanding in patchwork to make sure I didn't miss anything.

thanks

Jonathan

Quoted 22 lines
Quoted 20 lines

---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++

 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

attributes.c b/drivers/iio/common/hid-sensors/hid-sensor- attributes.c
index 9e7c26e37880..26f8554d18a5 100644

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0 -0
@@ -38,6 +38,8 @@ static const struct {
  	{HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000},
  	{HID_USAGE_SENSOR_COMPASS_3D,
 HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},

drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
+	{HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0},
+

  {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293}, {HID_USAGE_SENSOR_INCLINOMETER_3D, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},