From nobody Thu Apr 2 23:56:16 2026 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EDA6175A9B for ; Sun, 1 Mar 2026 23:47:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772408828; cv=none; b=ni65pKzOcoAPBNJj5GQLM0IFPn6Ma1gt3VzKfpDaWW8D94xFDviDCM++pFTIrX9doHUtrmHK6dWOctzHvPPGWvi1as6bDHWr1zmvRkhvaZeDHz/tUi/jy3RBrHwBqwylJjXnhAaAar+tXhQC4y2YcizlRQucWwROHZlVH23yGRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772408828; c=relaxed/simple; bh=d2WnHgqmi2t0hFyj3qyly3wbZePdj7qu8dGp5arudvw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Kj8pw9f42lIZsAP1uDP+EVSYjytZKAeM01h1e1GVHiVJDuqBfNuHWaYnnJdewI8BWYyNUvHwaP2k6+x9p0fb3cGDuCd9/rFg4PvywVxTfiEX/mwrAQdcaq3cKeA/57X3bqGmEBcj0bk8BrW8IbhBklWpFj21m2keTQrBxAOMnKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=WiCU2SL3; arc=none smtp.client-ip=209.85.167.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="WiCU2SL3" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-463967f35d7so3203889b6e.1 for ; Sun, 01 Mar 2026 15:47:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1772408825; x=1773013625; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=5dwT1q+TqqHDCYMVcm5xwnQXT5XtGs/pb1m0k2p2HzY=; b=WiCU2SL3Bw8olojpjv9WWa2j7NbEtLY1OocRswNGH+ArPk/G+tlYY7oMKJQbxWjMFT YAK5KzuuJhhNGeBij8FTG0AeQSYZ1mLUoQrj+SL2v8XAi14POgTExnrolmSgIkQQ5JZ1 mP35Vm0egF3QjomlbwEQXhv4CwI0pSIvDzR464faNUUXemw7y+BhJorojxkRstegYanJ 5F+9Hyj41oDKnEORJbqIWxwG0plMiZI607dF+r92t+YqP17VxcYeV2eTGCsMfgDogZDl eX6nQMPMOEgWOGQXUXiHgb2DWChDRFQ1qExlNjutotzIbmiz+1VvS4WzJGpUbD3Q3W3V XbPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772408825; x=1773013625; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5dwT1q+TqqHDCYMVcm5xwnQXT5XtGs/pb1m0k2p2HzY=; b=tl5h0Y/qqusSXJrT0vZQgZVtsXno2YSMhAS1wMVJoV5KEYi9fNkODLEPLHDrDnu/up grvrzwGUFkrPJyXcLpKw7JrHcPGjF0fcibkCLBCrNwpx4t+QjmkBFw6YnQj0vVKqh+PR LkwHdq+rcSaZxIXzhOFtknpz9LxHoKqVZ/mK+pijZ3KWNShPodsYLliyyygKgHUHHirv o10fPaHaziVb0Bn25HwZ97C7HvzqR1C+AqQ45KLeHRmXi2OoGIkx2IeTyoirgI5YeSRO WSepBOYztntMbPuVWpSITHrQ56RkZHKWoQYlG9tlXKG3H5QEwoUavcbgFrKDGDXT1obe rpew== X-Forwarded-Encrypted: i=1; AJvYcCXEFWjG6nNwGXNBbo56WdXppurj2c/dP4HbqRssSBj300XcQ+f1ToI66LpCp+k2ijdft1SgEygtQV6XyXE=@vger.kernel.org X-Gm-Message-State: AOJu0YyXJSx7B4wpYhXyK9J6oEn4A2Zttuhne1kfBd1AFDculg6FqOlj pPKu/zZvEkit5QFt2Rqf1zMqvcNFHkHcQp4pPnQpTcnMo8ZR+AsuhMO26/VpxSf0rN4= X-Gm-Gg: ATEYQzx0IPc8ojTfoZkxzyTsFVMSpjpE4NhpC97BX8Gco2sXygfsXdfAHNG0xUGZY5p JEc0l8SWePzV27UVbOYJP/iDn2IDhXNmJlHCxGmdkEeCklBVEKvpaoS8dYDDstp4Y7IelnKIgyx NtS0G84m3dUQxio9dNnQ/uT9VjQGTgXOsSXzI198rl8hovzd0BpUGpC+WsNCqplOeETuv6Ww74x 6E5yrwl7sevPfJ0bNSOfZwnieTNOKk0L/XcQGdWP25/PdOHiv2Fr3QPdIWA9gdH4VtQeTUkMLe6 G+BCFdluVczVwAmH6Yrt4oxErYdKPdD6RqCrF8Sal2PXFyi/WGKNJoKJ+D8Kmuv4ff4KpIkZ6YA keVhw/rtYvBUJvXSiKd+LtkmESBi65gfj7ET/3ir8vP9SeLBvclOvdXiZD89qRwgNXOCd1Z2n73 f+JxRbsrDfdI8rIOR7oLUqQ0l6WoXZ X-Received: by 2002:a05:6820:4b18:b0:66f:2d14:32b7 with SMTP id 006d021491bc7-679fadb8aebmr5703003eaf.9.1772408825368; Sun, 01 Mar 2026 15:47:05 -0800 (PST) Received: from [127.0.1.1] ([2600:8803:e7e4:500:8b9c:d657:204d:5a5f]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-679f2da4390sm8152129eaf.14.2026.03.01.15.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2026 15:47:03 -0800 (PST) From: David Lechner Date: Sun, 01 Mar 2026 17:46:48 -0600 Subject: [PATCH v2] iio: orientation: hid-sensor-rotation: use ext_scan_type Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260301-iio-hid-sensor-rotation-cleanup-v2-1-245c6ad59afc@baylibre.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/42OwQ6CMBBEf8X07Jq2IAFP/ofhUMoim2CL20Ikh H+34sGrxzfJzJtVBGTCIC6HVTDOFMi7BPp4ELY37o5AbWKhpS6kVjkQeeiphYAueAb20cTUATu gcdMIZY5lrmSlC+xEWhkZO3rthlv9ZcbnlETxF/YUoudlfzGrT/q/cFagIDNoK3POMiu7a2OWg RrGk/UPUW/b9ga3eEgI5gAAAA== X-Change-ID: 20260214-iio-hid-sensor-rotation-cleanup-84e8410926ef To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5237; i=dlechner@baylibre.com; h=from:subject:message-id; bh=d2WnHgqmi2t0hFyj3qyly3wbZePdj7qu8dGp5arudvw=; b=owEBbQGS/pANAwAKAcLMIAH/AY/AAcsmYgBppM/vBv88UMkBlPn8dCHUBhk8jgkIzWqMtohA8 IT61NTktZ6JATMEAAEKAB0WIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCaaTP7wAKCRDCzCAB/wGP wBObB/9PCXzB6uVauf004a+Ojx96a7UBtPuXvJza727xxOJHSIrawHfQy86MBJ+CTssCw1y3ioz oM6qc9ml4JONrOamrF13ppfjgxULDiqj7gVPLq1ClDBMT5xcVyVpeOFUnvqnTojGzeTEThPDnM9 XmDqXE9okxfvcnlJD4neasvsXqp2g6V8yoBqpxjwaWQbd5eY4tXOAyi+7nkNfFLky3fnDN3WiH3 CHqQ8+8+A9lBoYrOo4xv32fOYmLqNhLcWGUh1QPXxXmcS4BnGfkkzGmIG0co1jcOPVVvHUl9Pa9 N6LhgxDZpb+zFM7m/gdCJz+LD40zv+oNgxyw7PgjbQrKB247 X-Developer-Key: i=dlechner@baylibre.com; a=openpgp; fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03 Make use of ext_scan_type to handle the dynamic realbits size of the quaternion data. This lets us implement it using static data rather than having to duplicate the channel info for each driver instance. Signed-off-by: David Lechner Reviewed-by: Andy Shevchenko --- This is something I noticed we could do while looking at an unrelated bug. I've tested this using the same script from [1] and confirmed that that the scan type didn't change. Before and after are both: $ cat in_rot_quaternion_type le:s16/32X4>>0 [1]: https://lore.kernel.org/linux-iio/20260301-iio-fix-timestamp-alignment= -v1-1-1a54980bfb90@baylibre.com/ --- Changes in v2: - Dropped DEV_ROT_SCAN_TYPE_8BIT. - Tested using /dev/uhid. - Link to v1: https://lore.kernel.org/r/20260214-iio-hid-sensor-rotation-cl= eanup-v1-1-3aec9a533c0f@baylibre.com --- drivers/iio/orientation/hid-sensor-rotation.c | 71 ++++++++++++++++-------= ---- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/or= ientation/hid-sensor-rotation.c index e759f91a710a..3cfd0b323514 100644 --- a/drivers/iio/orientation/hid-sensor-rotation.c +++ b/drivers/iio/orientation/hid-sensor-rotation.c @@ -34,6 +34,27 @@ static const u32 rotation_sensitivity_addresses[] =3D { HID_USAGE_SENSOR_ORIENT_QUATERNION, }; =20 +enum { + DEV_ROT_SCAN_TYPE_16BIT, + DEV_ROT_SCAN_TYPE_32BIT, +}; + +static const struct iio_scan_type dev_rot_scan_types[] =3D { + [DEV_ROT_SCAN_TYPE_16BIT] =3D { + .sign =3D 's', + .realbits =3D 16, + /* Storage bits has to stay 32 to not break userspace. */ + .storagebits =3D 32, + .repeat =3D 4, + }, + [DEV_ROT_SCAN_TYPE_32BIT] =3D { + .sign =3D 's', + .realbits =3D 32, + .storagebits =3D 32, + .repeat =3D 4, + }, +}; + /* Channel definitions */ static const struct iio_chan_spec dev_rot_channels[] =3D { { @@ -45,23 +66,14 @@ static const struct iio_chan_spec dev_rot_channels[] = =3D { BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_HYSTERESIS), - .scan_index =3D 0 + .scan_index =3D 0, + .has_ext_scan_type =3D 1, + .ext_scan_type =3D dev_rot_scan_types, + .num_ext_scan_type =3D ARRAY_SIZE(dev_rot_scan_types), }, IIO_CHAN_SOFT_TIMESTAMP(1) }; =20 -/* Adjust channel real bits based on report descriptor */ -static void dev_rot_adjust_channel_bit_mask(struct iio_chan_spec *chan, - int size) -{ - chan->scan_type.sign =3D 's'; - /* Real storage bits will change based on the report desc. */ - chan->scan_type.realbits =3D size * 8; - /* Maximum size of a sample to capture is u32 */ - chan->scan_type.storagebits =3D sizeof(u32) * 8; - chan->scan_type.repeat =3D 4; -} - /* Channel read_raw handler */ static int dev_rot_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, @@ -136,9 +148,25 @@ static int dev_rot_write_raw(struct iio_dev *indio_dev, return ret; } =20 +static int dev_rot_get_current_scan_type(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct dev_rot_state *rot_state =3D iio_priv(indio_dev); + + switch (rot_state->quaternion.size / 4) { + case sizeof(s16): + return DEV_ROT_SCAN_TYPE_16BIT; + case sizeof(s32): + return DEV_ROT_SCAN_TYPE_32BIT; + default: + return -EINVAL; + } +} + static const struct iio_info dev_rot_info =3D { .read_raw_multi =3D &dev_rot_read_raw, .write_raw =3D &dev_rot_write_raw, + .get_current_scan_type =3D &dev_rot_get_current_scan_type, }; =20 /* Callback handler to send event after all samples are received and captu= red */ @@ -196,7 +224,6 @@ static int dev_rot_capture_sample(struct hid_sensor_hub= _device *hsdev, /* Parse report which is specific to an usage id*/ static int dev_rot_parse_report(struct platform_device *pdev, struct hid_sensor_hub_device *hsdev, - struct iio_chan_spec *channels, unsigned usage_id, struct dev_rot_state *st) { @@ -210,9 +237,6 @@ static int dev_rot_parse_report(struct platform_device = *pdev, if (ret) return ret; =20 - dev_rot_adjust_channel_bit_mask(&channels[0], - st->quaternion.size / 4); - dev_dbg(&pdev->dev, "dev_rot %x:%x\n", st->quaternion.index, st->quaternion.report_id); =20 @@ -271,22 +295,13 @@ static int hid_dev_rot_probe(struct platform_device *= pdev) return ret; } =20 - indio_dev->channels =3D devm_kmemdup(&pdev->dev, dev_rot_channels, - sizeof(dev_rot_channels), - GFP_KERNEL); - if (!indio_dev->channels) { - dev_err(&pdev->dev, "failed to duplicate channels\n"); - return -ENOMEM; - } - - ret =3D dev_rot_parse_report(pdev, hsdev, - (struct iio_chan_spec *)indio_dev->channels, - hsdev->usage, rot_state); + ret =3D dev_rot_parse_report(pdev, hsdev, hsdev->usage, rot_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); return ret; } =20 + indio_dev->channels =3D dev_rot_channels; indio_dev->num_channels =3D ARRAY_SIZE(dev_rot_channels); indio_dev->info =3D &dev_rot_info; indio_dev->name =3D name; --- base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31 change-id: 20260214-iio-hid-sensor-rotation-cleanup-84e8410926ef Best regards, --=20 David Lechner