From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 23FCB2EA48F for ; Fri, 23 Jan 2026 11:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769166217; cv=none; b=nRon9RTEd8yd5rQg+VXLP100E0LwwfhT5NIsDYrLnlZq7XZNHXiWFFlDEQ7DU4To8+hh7yza92ZhsSxRPR1cDkLMqGI42/1nFgUo0r3fGPkC5b0EF8wKgi/Yt5pkm1WXHQ7ywYo9f6FJ5mhMbJdUQnKUL/KS5pbd51n3feXZPlE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769166217; c=relaxed/simple; bh=O4Nih27iosbIpR9tjlrFXWsPJSLSROkSTpB4yV9z8V8=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=uAYOwgb0VeOQsDrpO88GyOx1sKBmfpGon6kpWwQYxytZW4x/RM/Dut3H97gNZbSHlo/RI4wc5I2KBXTA4lzEBvpq+hjfhFNCHuxSL64o9jh8mZao2TBekNt3A6QX+GwzBIUdPoJo6YGz9wlfB2Rpog2Fc6y8xD+Oi1MdTv9P3Ck= 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=hV3gmEmZ; arc=none smtp.client-ip=209.85.218.45 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="hV3gmEmZ" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-b86ed375d37so245325766b.3 for ; Fri, 23 Jan 2026 03:03:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1769166213; x=1769771013; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:organization :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to; bh=O4Nih27iosbIpR9tjlrFXWsPJSLSROkSTpB4yV9z8V8=; b=hV3gmEmZyjq84jsLETSBnHVno6wWBBQaMdR7u8msuFS4Z0JWdm8rNNCSKepAdDYZ++ 3zcAWPdi6KOabctKWcECXUhbjxCS6IO6WeNnWWPf805mAv9RZohOTQiuMOMfPZOjDLha r0Oo8IhbmV0l/gUVvM8c90Gu+fphybAGmtD7tWt0W1CFo8N9DKAIJjxvRHoEin9buI+b mqyQM+MVssQ0yhKF+FC73xXVfCNltmfOJHGKQRCuShIJx7RQDq7X16m8n/lb0XNTG917 r8BnXQGWbKjuwcDC84pr7GwYJlhqZxWuJY++qpEnU1/r52zpzUZI6R54sAWUIsG89UmC BpLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769166213; x=1769771013; h=mime-version:user-agent:content-transfer-encoding:organization :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O4Nih27iosbIpR9tjlrFXWsPJSLSROkSTpB4yV9z8V8=; b=K7r0v9y6cpne+CqL8hx3zrNfQ89caqcxcWEAqMhdASu0uzbXYav/SOhFrxwRD+tIhU Ejf37BrE2N8Iif9+H1mBKMOla05VrV3ABbl4BhLJHvA3HI2HUuks0Z9Fz2O15oOAjlhY DStGic5b8ehlZ5lKMWEZtrIhAgfQ0Hu9AMwgE2J0V8CmTOmzud0UqVElSa1Rm90qJsmh NA5HIP6HjRL+dy5sAKPpfNKHrSSoABttuQCMGLpHS9zGgjIIRmBFZxJKBd8CTw6Nt8JK s5CJ3g2dnylhLQRpZNuRGmhernn81EocBarmQMoJ6/mI7fZd68ZOk3WiY+nu5ONZx4On YioQ== X-Forwarded-Encrypted: i=1; AJvYcCVwW5zrc99Us8ciAKR8qsfu087t+MZP32qZTXGHp7G7arFKirF3GC29/KzllmJ+qciA0VEWjj0B0EfP2ew=@vger.kernel.org X-Gm-Message-State: AOJu0YzVsoSoz2kQkuQTBLEoO7+oIcNLH+v3QrMw8QIXv6iHGEZfFpIF QL3b6VpzpgH3YC+2Sjw6WNNsR1tB+L6GuU9tTryLFx/UpfAWKXLXQbG8DNB2cw8/7DM= X-Gm-Gg: AZuq6aKQ9rNIgGEEyYNYYjdcTKG/puqqgFiHvYxRF8TDQ3N5EB3ECpCifAjhDSfMUAJ pNfchJ6h/T0IpcbQ1d+i3thtgHGdcE+KcpmR2YuBU1QUE07cb6Wpy3a42Efj5HO/EXb5RslIijQ xjG5ZEXky4I3MjXsfhaaykBvLoKLJgHzGC0b6ESHFBT10DlMEj7OB1OVmdui713rhn6jw4Q5Rvn 90dACT2g/PHG5Z/I3bfWm1DMR/xnqJaaUq5cthU8UAOIAN094XDEOjNovs5TqS1CwP7QunE3Y7V z5YXwAx1BBeB0JnznQW481+vIVwVRT4jLlnvl4/DaK/L4AkZGg7U2kslcTPnh4XNmeJKiwULGJF pC6zUV0dZfXHYyxrkDWtP/+30pCS62pophNMgN66CJJ6dqSJVky+YEJfT1qlPOe8dIfdG8LnXQP C59ic= X-Received: by 2002:a17:907:da6:b0:b87:d3af:de68 with SMTP id a640c23a62f3a-b885ac0fad0mr156808266b.7.1769166213265; Fri, 23 Jan 2026 03:03:33 -0800 (PST) Received: from [10.203.83.237] ([151.19.16.90]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6584b3eb9f2sm807038a12.14.2026.01.23.03.03.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jan 2026 03:03:32 -0800 (PST) Message-ID: Subject: Re: [PATCH v5 4/4] iio: imu: st_lsm6dsx: Add support for rotation sensor From: Francesco Lavra To: Jonathan Cameron Cc: Lorenzo Bianconi , David Lechner , Nuno =?ISO-8859-1?Q?S=E1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 23 Jan 2026 12:03:29 +0100 In-Reply-To: <20260122202943.344e7311@jic23-huawei> References: <20260122162335.2020006-1-flavra@baylibre.com> <20260122162335.2020006-5-flavra@baylibre.com> <20260122202943.344e7311@jic23-huawei> Organization: BayLibre Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2026-01-22 at 20:29 +0000, Jonathan Cameron wrote: > On Thu, 22 Jan 2026 17:23:35 +0100 > Francesco Lavra wrote: >=20 > > Some IMU chips in the LSM6DSX family have sensor fusion features that > > combine data from the accelerometer and gyroscope. One of these > > features > > generates rotation vector data and makes it available in the hardware > > FIFO as a quaternion (more specifically, the X, Y and Z components of > > the > > quaternion vector, expressed as 16-bit half-precision floating-point > > numbers). > >=20 > > Add support for a new sensor instance that allows receiving sensor > > fusion > > data, by defining a new struct st_lsm6dsx_sf_settings (which contains > > chip-specific details for the sensor fusion functionality), and adding > > this > > struct as a new field in struct st_lsm6dsx_settings. In > > st_lsm6dsx_core.c, > > populate this new struct for the LSM6DSV and LSM6DSV16X chips, and add > > the > > logic to initialize an additional IIO device if this struct is > > populated > > for the hardware type being probed. > > Note: a new IIO device is being defined (as opposed to adding channels > > to > > an existing device) because the rate at which sensor fusion data is > > generated may not match the data rate from any of the existing devices. > >=20 > > Tested on LSMDSV16X. > >=20 > > Signed-off-by: Francesco Lavra > > Acked-by: Lorenzo Bianconi >=20 > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > > b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > > index ded9a96076e6..3b4fa57bf461 100644 > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c >=20 > > @@ -580,6 +584,16 @@ st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw > > *hw, u8 tag, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0case ST_LSM6DSX_EXT2_TA= G: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0iio_dev =3D hw->iio_devs[ST_LSM6DSX_ID_EXT2]; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0break; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0case ST_LSM6DSX_ROT_TAG: > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0/* > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * The sensor reports only the {X, Y, Z} elements of > > the > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * quaternion vector; set the W value to 0 (it can be > > derived > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * from the {X, Y, Z} values due to the property that > > the vector > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * is normalized). >=20 > I'd missed this before.=C2=A0 This is going to really confuse user space. > I don't think we can just return it with a 0 in that last entry. > At the very least we need an ABI doc update to reflect this oddity. >=20 > I don't think that is enough though. This isn't a quaternion, but > rather something we can derive one from. Annoying though it is, > we can't realistically fix it up in kernel, so we are probably talking > a new MOD_TYPE. Quaternion data read from the sensor is expressed in floating-point format, and as such needs to be interpreted by userspace in a "non-standard" way (note there is no scale in the channel info, and this is intentional because we are not dealing with integers) regardless of whether the W value is present or must be derived. Isn't the absence of the scale info enough to let userspace know that this data is non-standard? Only applications that know how to deal specifically with this sensor device can make sense of the data (and these applications know that the quaternion vector is normalized and the W value must be derived from X, Y, Z). > Also it's been a long time since I did much with quaternions, > but isn't the sign of w ambiguous if we are relying on only X, Y and Z? > A bit of googling + AI suggests flipping it inverts the direction of > rotation around a given axis. Feels like there is a constraint missing > in this description. Flipping the sign of W doesn't just invert the direction of rotation, it basically applies an offset of -360 degrees; if a value w0 indicates a rotation by an angle theta0, the value -w0 indicates a rotation by (theta0 - 360), which is basically the same as rotating by theta0. So knowing the {X, Y, Z} values is enough to have a non-ambiguous orientation.