From nobody Mon Nov 25 12:50:27 2024 Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE14838F82; Sun, 27 Oct 2024 17:21:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049709; cv=none; b=gnjr3DnY5nxK7ed60izbNArB5SdpPBz4X4I9jmkJ0QYoFbgEg1/Nwt36XbTjapcdnAFphzClTX+oSvfWKGel03p6BThgI5SsoXPkfwm4aTFapDM0O7vRe3cP+URNHdsslHaBMsiXfNhFBK+bsVitCiGAi8mHluuFT1DNfbvTYmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049709; c=relaxed/simple; bh=Nsxs3CXHgYFu8qUUqadgrTXp6c1kCCUvahwZ69uwwKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D3N1QkLthbtBEWdt8tXFlFoBc0iMZo0IHyWkC4d982+zmYlQV6+e+fSlGXm3Y0Hd8844AE/cADGhsam8giI9lFba5jIIOSIQ96GNq3cTYMAe9QtQl11+pRkKHHwqkjKiYO7Sq53ztV4Sqd2wfgxfzswikC9NaHcy87WHTEmfcjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com; spf=pass smtp.mailfrom=justinweiss.com; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b=k8aqnkw8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gUafitMw; arc=none smtp.client-ip=202.12.124.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b="k8aqnkw8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gUafitMw" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 3FB98254009C; Sun, 27 Oct 2024 13:21:45 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Sun, 27 Oct 2024 13:21:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=justinweiss.com; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730049705; x= 1730136105; bh=CwZceMBqTT2pEGup3sQN8Jo7JhDAcLQmyspij77zCCM=; b=k 8aqnkw8/Bfg8uBo+L7WgmnQ67P0axF6zZzmHcPbU3auBgIXBcASVYWHpk7rA71S5 TKn2s/h9+L2oeiphD6T1JcTlNRmR7SJmJcONBhSVtGtUeghMY7CIagLAPEpCHGhu tgr1G5R3hPjNt0Nk/49FizV2F6HCzo4meUNF2/HxrWSV3jFMNGwTJgsC+2AipdPw F21WY40AWp7Wtbs+8tzzcwneUckUlGoQsm8aiJi9ObcqzG/eR1FiDHsDkyhS4Nfk 2HGyIGCUewbhSXua+C64ubvC1tj+7H17oyi7wmIXp4iRjd1YGoYvWxG/LHfI9kHj VD7qu3xguP7wyV4u6vxRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1730049705; x= 1730136105; bh=CwZceMBqTT2pEGup3sQN8Jo7JhDAcLQmyspij77zCCM=; b=g UafitMw+DI0xQFzHP5y2lAVwsp0oLOHCY6BNWNgHsIBwjd3yByN+Y4XeC98kaSYS BjIreVog7eIsLJBlMqToNwUq/7YSa3xD7JjQGB5FC7IBPzFRky4BvMzw7hZzw5XX p+ogaWsnKiSea0HHV/Ylbil81mWe7BkaehrhBiQtELC/+WW+1FQJYTSthOkYFhel /bq/F91oaMg36ILOGgdWNVpu8d1kOFVNFl00L2Hzw2ANdEIhzUlBMOvaUKEdWX3E ayQnaB9ZC26xail4agUzaHK16VfLocp8U+gzHj53zb9QMASt+xIxbDNEsXZxbJg8 4RdwWAWbOIQLlCgUJwxbQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdejiedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddt necuhfhrohhmpefluhhsthhinhcuhggvihhsshcuoehjuhhsthhinhesjhhushhtihhnfi gvihhsshdrtghomheqnecuggftrfgrthhtvghrnhepiefftddvgfdtvdeiteffudfhjedt feetleekgfetkeeggeffudeihfduieevjeeknecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgt ohhmpdhnsggprhgtphhtthhopedufedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoh eplhgrnhiirghnohdrrghlvgigsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhhitgdv feeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhgrrhhssehmvghtrghfohhordguvg dprhgtphhtthhopehrohgshheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhhriihk odgutheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnh gvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehlihhn uhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmpdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgv lhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 27 Oct 2024 13:21:43 -0400 (EDT) From: Justin Weiss To: Alex Lanzano , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko Cc: Justin Weiss , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, "Derek J . Clark" , =?UTF-8?q?Philip=20M=C3=BCller?= Subject: [PATCH v4 1/4] iio: imu: bmi270: Add triggered buffer for Bosch BMI270 IMU Date: Sun, 27 Oct 2024 10:20:22 -0700 Message-ID: <20241027172029.160134-2-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241027172029.160134-1-justin@justinweiss.com> References: <20241027172029.160134-1-justin@justinweiss.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Set up a triggered buffer for the accel and angl_vel values. Signed-off-by: Justin Weiss --- drivers/iio/imu/bmi270/Kconfig | 1 + drivers/iio/imu/bmi270/bmi270.h | 9 +++++ drivers/iio/imu/bmi270/bmi270_core.c | 56 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/drivers/iio/imu/bmi270/Kconfig b/drivers/iio/imu/bmi270/Kconfig index 0ffd29794fda..6362acc706da 100644 --- a/drivers/iio/imu/bmi270/Kconfig +++ b/drivers/iio/imu/bmi270/Kconfig @@ -6,6 +6,7 @@ config BMI270 tristate select IIO_BUFFER + select IIO_TRIGGERED_BUFFER =20 config BMI270_I2C tristate "Bosch BMI270 I2C driver" diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi27= 0.h index 93e5f387607b..6173be929bac 100644 --- a/drivers/iio/imu/bmi270/bmi270.h +++ b/drivers/iio/imu/bmi270/bmi270.h @@ -11,6 +11,15 @@ struct bmi270_data { struct device *dev; struct regmap *regmap; const struct bmi270_chip_info *chip_info; + + /* + * Where IIO_DMA_MINALIGN may be larger than 8 bytes, align to + * that to ensure a DMA safe buffer. + */ + struct { + __le16 channels[6]; + aligned_s64 timestamp; + } data __aligned(IIO_DMA_MINALIGN); }; =20 struct bmi270_chip_info { diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index 5f08d786fa21..1608cb2c8fb5 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -7,6 +7,8 @@ #include =20 #include +#include +#include =20 #include "bmi270.h" =20 @@ -64,6 +66,17 @@ enum bmi270_scan { BMI270_SCAN_GYRO_X, BMI270_SCAN_GYRO_Y, BMI270_SCAN_GYRO_Z, + BMI270_SCAN_TIMESTAMP, +}; + +static const unsigned long bmi270_avail_scan_masks[] =3D { + (BIT(BMI270_SCAN_ACCEL_X) | + BIT(BMI270_SCAN_ACCEL_Y) | + BIT(BMI270_SCAN_ACCEL_Z) | + BIT(BMI270_SCAN_GYRO_X) | + BIT(BMI270_SCAN_GYRO_Y) | + BIT(BMI270_SCAN_GYRO_Z)), + 0 }; =20 const struct bmi270_chip_info bmi270_chip_info =3D { @@ -73,6 +86,27 @@ const struct bmi270_chip_info bmi270_chip_info =3D { }; EXPORT_SYMBOL_NS_GPL(bmi270_chip_info, IIO_BMI270); =20 +static irqreturn_t bmi270_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf =3D p; + struct iio_dev *indio_dev =3D pf->indio_dev; + struct bmi270_data *bmi270_device =3D iio_priv(indio_dev); + int ret; + + ret =3D regmap_bulk_read(bmi270_device->regmap, BMI270_ACCEL_X_REG, + &bmi270_device->data.channels, + sizeof(bmi270_device->data.channels)); + + if (ret) + goto done; + + iio_push_to_buffers_with_timestamp(indio_dev, &bmi270_device->data, + pf->timestamp); +done: + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} + static int bmi270_get_data(struct bmi270_data *bmi270_device, int chan_type, int axis, int *val) { @@ -128,6 +162,13 @@ static const struct iio_info bmi270_info =3D { .modified =3D 1, \ .channel2 =3D IIO_MOD_##_axis, \ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ + .scan_index =3D BMI270_SCAN_ACCEL_##_axis, \ + .scan_type =3D { \ + .sign =3D 's', \ + .realbits =3D 16, \ + .storagebits =3D 16, \ + .endianness =3D IIO_LE \ + }, \ } =20 #define BMI270_ANG_VEL_CHANNEL(_axis) { \ @@ -135,6 +176,13 @@ static const struct iio_info bmi270_info =3D { .modified =3D 1, \ .channel2 =3D IIO_MOD_##_axis, \ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ + .scan_index =3D BMI270_SCAN_GYRO_##_axis, \ + .scan_type =3D { \ + .sign =3D 's', \ + .realbits =3D 16, \ + .storagebits =3D 16, \ + .endianness =3D IIO_LE \ + }, \ } =20 static const struct iio_chan_spec bmi270_channels[] =3D { @@ -144,6 +192,7 @@ static const struct iio_chan_spec bmi270_channels[] =3D= { BMI270_ANG_VEL_CHANNEL(X), BMI270_ANG_VEL_CHANNEL(Y), BMI270_ANG_VEL_CHANNEL(Z), + IIO_CHAN_SOFT_TIMESTAMP(BMI270_SCAN_TIMESTAMP), }; =20 static int bmi270_validate_chip_id(struct bmi270_data *bmi270_device) @@ -301,9 +350,16 @@ int bmi270_core_probe(struct device *dev, struct regma= p *regmap, indio_dev->channels =3D bmi270_channels; indio_dev->num_channels =3D ARRAY_SIZE(bmi270_channels); indio_dev->name =3D chip_info->name; + indio_dev->available_scan_masks =3D bmi270_avail_scan_masks; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &bmi270_info; =20 + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + bmi270_trigger_handler, NULL); + if (ret) + return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(bmi270_core_probe, IIO_BMI270); --=20 2.47.0 From nobody Mon Nov 25 12:50:27 2024 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3178F175D4F; Sun, 27 Oct 2024 17:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049711; cv=none; b=PuTDzUDZa9YI6mTxokN4XYAiVTgAxdEOh2+s9qq1wbp90gFOZ5k3dVKAZtsN1tWqZU+bEnUmbaxkE/vFplDWJD0otna0pgb3KWYkcQzPmLcxMrk+Rdc3StwxqcYPTB0hW2sLv/JNPecYchc551WHxjZgkZEPF2THhgv1QZVy5ZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049711; c=relaxed/simple; bh=bp983poLAcKtxPrBrfKTRuNcMz1BqZz6VM2dc/JnW7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YHqtiGEIz/sZiOnCPiOzZpnKHYwIS5P970JlOOJsFI1GkBwWsoI52O05c1Gic1Tph9b9EtURk58AizL6MY8S5nx0ivLd9ecOMDnX/Wa+d/ZOnD5BN5En6CeXlcoavyvVODa3ekDPSVQbZ0F7HjIbGqGMiJgXw7Uxnw6EDsN3pHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com; spf=pass smtp.mailfrom=justinweiss.com; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b=Qx+WRquR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fqW2teji; arc=none smtp.client-ip=202.12.124.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b="Qx+WRquR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fqW2teji" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id E1DAA11400CF; Sun, 27 Oct 2024 13:21:47 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Sun, 27 Oct 2024 13:21:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=justinweiss.com; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730049707; x= 1730136107; bh=CH9W/hAloaYyEdc4LPF+ff9/zId9y0OyHWzDLblVZXQ=; b=Q x+WRquR8pNcb7qvdpRblrkxPWTyEisIm2yM4I2KWWXnWioddcyqx3gscCC5MXWLa MnL80lubQGuOme4jqVJN/5rcKRbHrXdngN2Bkm9hyGP9V+0j+N+4ASko5QcvgFcI mmwvUK/7OAE4hejhkcLq+EnTW+4Vn6mZ89xDolq5SsPQXxwa5Sey9l4Jv1ILOppB 6amTnsvNBwCgkjOZv9TyA5Cyz4cNxU9gRnDRiMutkwKmWQH55TsI7SZsBycQ8vo2 gLUdbNnxZ3XpFsJqb7MO7GdWint73tS8JvauUZuwBXAsbbCt6hbNrnJV+7mpuxl+ 423UJMzIOHLkAI7MoY14Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1730049707; x= 1730136107; bh=CH9W/hAloaYyEdc4LPF+ff9/zId9y0OyHWzDLblVZXQ=; b=f qW2teji5dcyfKKyXIl7Oi5TOeRwbNaP1n0y4qxYPBGop6rQGublM+8ShAmDnlRRG MMvZYYH4kV5YMRLTy4ovQ3vmIUwI9BloMf/0kOZuVOEH6kn1FD53CkL4/4FZov4z C/Ckkigh63yssau+Mc/aQu53VmTMOhGSR58JVJ5kvaJrPG5yzPjk6oOKsDoW2D+6 iX8HtF5RR/l+HlkkwSxrI1vlxp/7jYcyhEHeJS25sxFHQwnhthaHkfh8q6gYJgro 4Pbq+hDbpJfhROzBA2gk1nRMWMw3jRkiHOZsb/+pJRQnGU44PFhex0tgVdb0FLOp 5NBKhTnz6HvKliLnc7o3A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdejiedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddt necuhfhrohhmpefluhhsthhinhcuhggvihhsshcuoehjuhhsthhinhesjhhushhtihhnfi gvihhsshdrtghomheqnecuggftrfgrthhtvghrnhepiefftddvgfdtvdeiteffudfhjedt feetleekgfetkeeggeffudeihfduieevjeeknecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgt ohhmpdhnsggprhgtphhtthhopedufedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoh eplhgrnhiirghnohdrrghlvgigsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhhitgdv feeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhgrrhhssehmvghtrghfohhordguvg dprhgtphhtthhopehrohgshheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhhriihk odgutheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnh gvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehlihhn uhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmpdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgv lhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 27 Oct 2024 13:21:45 -0400 (EDT) From: Justin Weiss To: Alex Lanzano , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko Cc: Justin Weiss , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, "Derek J . Clark" , =?UTF-8?q?Philip=20M=C3=BCller?= Subject: [PATCH v4 2/4] iio: imu: bmi270: Add scale and sampling frequency to BMI270 IMU Date: Sun, 27 Oct 2024 10:20:23 -0700 Message-ID: <20241027172029.160134-3-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241027172029.160134-1-justin@justinweiss.com> References: <20241027172029.160134-1-justin@justinweiss.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add read and write functions and create _available entries. Signed-off-by: Justin Weiss --- drivers/iio/imu/bmi270/bmi270_core.c | 340 +++++++++++++++++++++++++++ 1 file changed, 340 insertions(+) diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index 1608cb2c8fb5..27e501a15095 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -7,6 +7,7 @@ #include =20 #include +#include #include #include =20 @@ -33,6 +34,9 @@ #define BMI270_ACC_CONF_BWP_NORMAL_MODE 0x02 #define BMI270_ACC_CONF_FILTER_PERF_MSK BIT(7) =20 +#define BMI270_ACC_CONF_RANGE_REG 0x41 +#define BMI270_ACC_CONF_RANGE_MSK GENMASK(1, 0) + #define BMI270_GYR_CONF_REG 0x42 #define BMI270_GYR_CONF_ODR_MSK GENMASK(3, 0) #define BMI270_GYR_CONF_ODR_200HZ 0x09 @@ -41,6 +45,9 @@ #define BMI270_GYR_CONF_NOISE_PERF_MSK BIT(6) #define BMI270_GYR_CONF_FILTER_PERF_MSK BIT(7) =20 +#define BMI270_GYR_CONF_RANGE_REG 0x43 +#define BMI270_GYR_CONF_RANGE_MSK GENMASK(2, 0) + #define BMI270_INIT_CTRL_REG 0x59 #define BMI270_INIT_CTRL_LOAD_DONE_MSK BIT(0) =20 @@ -86,6 +93,265 @@ const struct bmi270_chip_info bmi270_chip_info =3D { }; EXPORT_SYMBOL_NS_GPL(bmi270_chip_info, IIO_BMI270); =20 +enum bmi270_sensor_type { + BMI270_ACCEL =3D 0, + BMI270_GYRO, +}; + +struct bmi270_scale { + int scale; + int uscale; +}; + +struct bmi270_odr { + int odr; + int uodr; +}; + +static const struct bmi270_scale bmi270_accel_scale[] =3D { + { 0, 598 }, + { 0, 1197 }, + { 0, 2394 }, + { 0, 4788 }, +}; + +static const struct bmi270_scale bmi270_gyro_scale[] =3D { + { 0, 1065 }, + { 0, 532 }, + { 0, 266 }, + { 0, 133 }, + { 0, 66 }, +}; + +struct bmi270_scale_item { + const struct bmi270_scale *tbl; + int num; +}; + +static const struct bmi270_scale_item bmi270_scale_table[] =3D { + [BMI270_ACCEL] =3D { + .tbl =3D bmi270_accel_scale, + .num =3D ARRAY_SIZE(bmi270_accel_scale), + }, + [BMI270_GYRO] =3D { + .tbl =3D bmi270_gyro_scale, + .num =3D ARRAY_SIZE(bmi270_gyro_scale), + }, +}; + +static const struct bmi270_odr bmi270_accel_odr[] =3D { + { 0, 781250 }, + { 1, 562500 }, + { 3, 125000 }, + { 6, 250000 }, + { 12, 500000 }, + { 25, 0 }, + { 50, 0 }, + { 100, 0 }, + { 200, 0 }, + { 400, 0 }, + { 800, 0 }, + { 1600, 0 }, +}; + +static const u8 bmi270_accel_odr_vals[] =3D { + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x0A, + 0x0B, + 0x0C, +}; + +static const struct bmi270_odr bmi270_gyro_odr[] =3D { + { 25, 0 }, + { 50, 0 }, + { 100, 0 }, + { 200, 0 }, + { 400, 0 }, + { 800, 0 }, + { 1600, 0 }, + { 3200, 0 }, +}; + +static const u8 bmi270_gyro_odr_vals[] =3D { + 0x06, + 0x07, + 0x08, + 0x09, + 0x0A, + 0x0B, + 0x0C, + 0x0D, +}; + +struct bmi270_odr_item { + const struct bmi270_odr *tbl; + const u8 *vals; + int num; +}; + +static const struct bmi270_odr_item bmi270_odr_table[] =3D { + [BMI270_ACCEL] =3D { + .tbl =3D bmi270_accel_odr, + .vals =3D bmi270_accel_odr_vals, + .num =3D ARRAY_SIZE(bmi270_accel_odr), + }, + [BMI270_GYRO] =3D { + .tbl =3D bmi270_gyro_odr, + .vals =3D bmi270_gyro_odr_vals, + .num =3D ARRAY_SIZE(bmi270_gyro_odr), + }, +}; + +static int bmi270_set_scale(struct bmi270_data *data, + int chan_type, int uscale) +{ + int i; + int reg, mask; + struct bmi270_scale_item bmi270_scale_item; + + switch (chan_type) { + case IIO_ACCEL: + reg =3D BMI270_ACC_CONF_RANGE_REG; + mask =3D BMI270_ACC_CONF_RANGE_MSK; + bmi270_scale_item =3D bmi270_scale_table[BMI270_ACCEL]; + break; + case IIO_ANGL_VEL: + reg =3D BMI270_GYR_CONF_RANGE_REG; + mask =3D BMI270_GYR_CONF_RANGE_MSK; + bmi270_scale_item =3D bmi270_scale_table[BMI270_GYRO]; + break; + default: + return -EINVAL; + } + + for (i =3D 0; i < bmi270_scale_item.num; i++) { + if (bmi270_scale_item.tbl[i].uscale !=3D uscale) + continue; + + return regmap_update_bits(data->regmap, reg, mask, i); + } + + return -EINVAL; +} + +static int bmi270_get_scale(struct bmi270_data *bmi270_device, + int chan_type, int *uscale) +{ + int ret; + unsigned int val; + struct bmi270_scale_item bmi270_scale_item; + + switch (chan_type) { + case IIO_ACCEL: + ret =3D regmap_read(bmi270_device->regmap, + BMI270_ACC_CONF_RANGE_REG, &val); + if (ret) + return ret; + + val =3D FIELD_GET(BMI270_ACC_CONF_RANGE_MSK, val); + bmi270_scale_item =3D bmi270_scale_table[BMI270_ACCEL]; + break; + case IIO_ANGL_VEL: + ret =3D regmap_read(bmi270_device->regmap, + BMI270_GYR_CONF_RANGE_REG, &val); + if (ret) + return ret; + + val =3D FIELD_GET(BMI270_GYR_CONF_RANGE_MSK, val); + bmi270_scale_item =3D bmi270_scale_table[BMI270_GYRO]; + break; + default: + return -EINVAL; + } + + if (val >=3D bmi270_scale_item.num) + return -EINVAL; + + *uscale =3D bmi270_scale_item.tbl[val].uscale; + return 0; +} + +static int bmi270_set_odr(struct bmi270_data *data, int chan_type, + int odr, int uodr) +{ + int i; + int reg, mask; + struct bmi270_odr_item bmi270_odr_item; + + switch (chan_type) { + case IIO_ACCEL: + reg =3D BMI270_ACC_CONF_REG; + mask =3D BMI270_ACC_CONF_ODR_MSK; + bmi270_odr_item =3D bmi270_odr_table[BMI270_ACCEL]; + break; + case IIO_ANGL_VEL: + reg =3D BMI270_GYR_CONF_REG; + mask =3D BMI270_GYR_CONF_ODR_MSK; + bmi270_odr_item =3D bmi270_odr_table[BMI270_GYRO]; + break; + default: + return -EINVAL; + } + + for (i =3D 0; i < bmi270_odr_item.num; i++) { + if (bmi270_odr_item.tbl[i].odr !=3D odr || + bmi270_odr_item.tbl[i].uodr !=3D uodr) + continue; + + return regmap_update_bits(data->regmap, reg, mask, + bmi270_odr_item.vals[i]); + } + + return -EINVAL; +} + +static int bmi270_get_odr(struct bmi270_data *data, int chan_type, + int *odr, int *uodr) +{ + int i, val, ret; + struct bmi270_odr_item bmi270_odr_item; + + switch (chan_type) { + case IIO_ACCEL: + ret =3D regmap_read(data->regmap, BMI270_ACC_CONF_REG, &val); + if (ret) + return ret; + + val =3D FIELD_GET(BMI270_ACC_CONF_ODR_MSK, val); + bmi270_odr_item =3D bmi270_odr_table[BMI270_ACCEL]; + break; + case IIO_ANGL_VEL: + ret =3D regmap_read(data->regmap, BMI270_GYR_CONF_REG, &val); + if (ret) + return ret; + + val =3D FIELD_GET(BMI270_GYR_CONF_ODR_MSK, val); + bmi270_odr_item =3D bmi270_odr_table[BMI270_GYRO]; + break; + default: + return -EINVAL; + } + + for (i =3D 0; i < bmi270_odr_item.num; i++) { + if (val !=3D bmi270_odr_item.vals[i]) + continue; + + *odr =3D bmi270_odr_item.tbl[i].odr; + *uodr =3D bmi270_odr_item.tbl[i].uodr; + return 0; + } + + return -EINVAL; +} + static irqreturn_t bmi270_trigger_handler(int irq, void *p) { struct iio_poll_func *pf =3D p; @@ -148,6 +414,68 @@ static int bmi270_read_raw(struct iio_dev *indio_dev, return ret; =20 return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val =3D 0; + ret =3D bmi270_get_scale(bmi270_device, chan->type, val2); + return ret ? ret : IIO_VAL_INT_PLUS_MICRO; + case IIO_CHAN_INFO_SAMP_FREQ: + ret =3D bmi270_get_odr(bmi270_device, chan->type, val, val2); + return ret ? ret : IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static int bmi270_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct bmi270_data *data =3D iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + return bmi270_set_scale(data, chan->type, val2); + case IIO_CHAN_INFO_SAMP_FREQ: + return bmi270_set_odr(data, chan->type, val, val2); + default: + return -EINVAL; + } +} + +static int bmi270_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *type =3D IIO_VAL_INT_PLUS_MICRO; + switch (chan->type) { + case IIO_ANGL_VEL: + *vals =3D (const int *)bmi270_gyro_scale; + *length =3D ARRAY_SIZE(bmi270_gyro_scale) * 2; + return IIO_AVAIL_LIST; + case IIO_ACCEL: + *vals =3D (const int *)bmi270_accel_scale; + *length =3D ARRAY_SIZE(bmi270_accel_scale) * 2; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SAMP_FREQ: + *type =3D IIO_VAL_INT_PLUS_MICRO; + switch (chan->type) { + case IIO_ANGL_VEL: + *vals =3D (const int *)bmi270_gyro_odr; + *length =3D ARRAY_SIZE(bmi270_gyro_odr) * 2; + return IIO_AVAIL_LIST; + case IIO_ACCEL: + *vals =3D (const int *)bmi270_accel_odr; + *length =3D ARRAY_SIZE(bmi270_accel_odr) * 2; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } default: return -EINVAL; } @@ -155,6 +483,8 @@ static int bmi270_read_raw(struct iio_dev *indio_dev, =20 static const struct iio_info bmi270_info =3D { .read_raw =3D bmi270_read_raw, + .write_raw =3D bmi270_write_raw, + .read_avail =3D bmi270_read_avail, }; =20 #define BMI270_ACCEL_CHANNEL(_axis) { \ @@ -162,6 +492,11 @@ static const struct iio_info bmi270_info =3D { .modified =3D 1, \ .channel2 =3D IIO_MOD_##_axis, \ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_type_available =3D \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index =3D BMI270_SCAN_ACCEL_##_axis, \ .scan_type =3D { \ .sign =3D 's', \ @@ -176,6 +511,11 @@ static const struct iio_info bmi270_info =3D { .modified =3D 1, \ .channel2 =3D IIO_MOD_##_axis, \ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_type_available =3D \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index =3D BMI270_SCAN_GYRO_##_axis, \ .scan_type =3D { \ .sign =3D 's', \ --=20 2.47.0 From nobody Mon Nov 25 12:50:27 2024 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 691C917B506; Sun, 27 Oct 2024 17:21:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049713; cv=none; b=Ak38FxaAYvJXBGoH15GM6YKPCBMAPUYy8H/NFQNcVUm139mt60ewdN/QjlNp6iK7mb/dV9C0yQEHEDC5DxYYITDBV5/3R1bXARp1oOB2yMaDKTRyT0fN6+MrwBDhQD6QAdIQb3R9oS4zuMk3X3CNgJTM5xpCW4pF7K36QJaNJO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049713; c=relaxed/simple; bh=zNLifCw53RuEU9K56iB2kiI1QFNOASqO/+9c0/UVaLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YBKZYo6DrK0n3sd5UlkqAOcF8I/Xu6n9vdVfmHjmmw4PxNxCxXtOe1XJz7GDEWUiEf+hFgz5umYz8mALrNkIY4SPZMHubK1iTWPfVmPKFStD+jhhfTGVwlga7EOv4AEQi/3QaSjkEd6tnq744bBODKuFPZ1hUNiygIVqp6Kx/Vo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com; spf=pass smtp.mailfrom=justinweiss.com; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b=k5Aw02Lf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VWrkwj4Z; arc=none smtp.client-ip=202.12.124.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b="k5Aw02Lf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VWrkwj4Z" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 30F6D11400CE; Sun, 27 Oct 2024 13:21:50 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Sun, 27 Oct 2024 13:21:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=justinweiss.com; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730049710; x= 1730136110; bh=b3yx3pByZgnY+Ay2QUJg1Z3X5UQekehxLlhS8VzCxk4=; b=k 5Aw02LfPEWGwR3MNc2DUIjT3UT/cgdeVGidAYPR1vmAFjP2USyIYqJ1EtC0drpZa rHK1MsXIidf3zHEBAToYNiTUnnCq5HK5ou73fVHYDkmkTSytuF9I0loqaMedWYBn A+SMi6yvkljw94VPmzFCQsWxl0yXR/bunlwD9fw1O0LEKPCTof0BgTCG4U0bUztj m25VXxBnn/TPSq6inkjUsUClVeV43/NfwRp5AQOuKt9l/XXo9+Lsr0PmQ+VDFwer B8Kl01bIjcH0V7+SwTne+0GgeFA4Sg75SRy4wLdabkcMZLxwCD0Lw3Jad5UOUZAV c5XwxvTI0EDYfv16NHphQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1730049710; x= 1730136110; bh=b3yx3pByZgnY+Ay2QUJg1Z3X5UQekehxLlhS8VzCxk4=; b=V Wrkwj4ZqkCXQ2y3gi6B1XVGl5DmYgQDmnCrpCvQfU7mzODq0wtt8h76Wq6eeWbwv ymoaQbcWvwY6kQPC5bI4Kvikf4UJmbuY9lgWDA7SaKh/IUCOJxJOX3neZu/Sn1E5 f31d4ywKKyi4chntoKhYLQGHIDQhzFilFaSBCxQA49P6VFdwTRjJhFvC/77p49QR Iq455z2HXXVivvknJfNo7jK6HIJlcgdNCf3WcEJLd+wORaNk5xOLt23oj928XuCD DaHLlw9AzC9RmqdnT64/q0qLRwfn8Emx8U6TusMIB+4D1jfVYwqRfLjNgziH9us0 +vFrazwwWAOJM2JwPs5fw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdejiedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddt necuhfhrohhmpefluhhsthhinhcuhggvihhsshcuoehjuhhsthhinhesjhhushhtihhnfi gvihhsshdrtghomheqnecuggftrfgrthhtvghrnhepiefftddvgfdtvdeiteffudfhjedt feetleekgfetkeeggeffudeihfduieevjeeknecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgt ohhmpdhnsggprhgtphhtthhopedufedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoh eplhgrnhiirghnohdrrghlvgigsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhhitgdv feeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhgrrhhssehmvghtrghfohhordguvg dprhgtphhtthhopehrohgshheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhhriihk odgutheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnh gvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehlihhn uhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmpdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgv lhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 27 Oct 2024 13:21:48 -0400 (EDT) From: Justin Weiss To: Alex Lanzano , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko Cc: Justin Weiss , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, "Derek J . Clark" , =?UTF-8?q?Philip=20M=C3=BCller?= Subject: [PATCH v4 3/4] dt-bindings: iio: imu: bmi270: Add Bosch BMI260 Date: Sun, 27 Oct 2024 10:20:24 -0700 Message-ID: <20241027172029.160134-4-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241027172029.160134-1-justin@justinweiss.com> References: <20241027172029.160134-1-justin@justinweiss.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The BMI260's register map, configuration, and capabilities are nearly identical to the BMI270, but the devices have different chip IDs and require different initialization firmware. Signed-off-by: Justin Weiss Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml b/= Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml index 792d1483af3c..7b0cde1c9b0a 100644 --- a/Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml +++ b/Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml @@ -18,7 +18,9 @@ description: | =20 properties: compatible: - const: bosch,bmi270 + enum: + - bosch,bmi260 + - bosch,bmi270 =20 reg: maxItems: 1 --=20 2.47.0 From nobody Mon Nov 25 12:50:27 2024 Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3971417C9F8; Sun, 27 Oct 2024 17:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049716; cv=none; b=Kp37noRv80yZdZsZqhmYsBQuG5tAjBK/HlJQPCc/e7xf89CngY3QzaXls54DG1zS3czXEUEs+t40qV20P7fGmLm8+KmgPeO99ADAtKKiW7sxD52TxW2q0DXJDcU08DwhuFYyICFxQ7z3Mkzzn17gEUw6SJ3Fixs3Q7meBq0KLRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730049716; c=relaxed/simple; bh=mZli/58Bf8b2rVFGCQQ5z0QEq2d90jadrU+ROb/40TA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fppkjrTtz2UQ96YqZjz2OqHwnZxU5TSvBkc+UpXNTv/4dkO6kuQcMfKqPQAX7r/6nt8JNXZAZj9NCaOuN0FPrQM/GKtdpETRET/lSG+c2H4HQq/J9fVPSlGYrL1lkpnif1Uoi41jV0i74kqTq6N0yNgPX1EraHVzVOnNgxNWXKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com; spf=pass smtp.mailfrom=justinweiss.com; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b=baogTKWQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CKRVWrUy; arc=none smtp.client-ip=202.12.124.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=justinweiss.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=justinweiss.com header.i=@justinweiss.com header.b="baogTKWQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CKRVWrUy" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 0320325400A4; Sun, 27 Oct 2024 13:21:52 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Sun, 27 Oct 2024 13:21:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=justinweiss.com; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1730049712; x= 1730136112; bh=HZ0f4dodd217AkGZBJ4uwjooGTB/NPsDwvhotzR1ZOw=; b=b aogTKWQ9MqVrjOh/u0IijpEnBp/BT/RtM+EIFoSX7oaSHROmpWPPQL/ell9hp+Jv Up1HDCYeBvrjcPL5gD63ZFnDBxjCo/cyBYiVqj11GkV315yCEivX5IPWwZ/I85Yx YncMBYr6BcPimzd4xAf7eax090cy6iYFFjatqpGR4InBU0sAD899VD3tm4oUVM1S EWtI38ZGLTlX2mKL5IH6AFy9bPsWxuyWLINy9d9ZGESmR5IT3NKUu7vBma3PZn7r 98nf+gMY92YEMwiiMm8VstMmN+HYzz3ioDK12ltXeFjUdX0Utbxd9AkLfcjOpg5k 7rQdEKu4dl/D8q4dDUY8g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1730049712; x= 1730136112; bh=HZ0f4dodd217AkGZBJ4uwjooGTB/NPsDwvhotzR1ZOw=; b=C KRVWrUyYOk00Y4ZfyUBSkAQI6Rki9PC5X2v8NilCOFbIaXkypcbAT4VpaDznp52h Xp7PEyc+U2Rpj4GBE22fuvG9ri02T+UpeQhQz5M0qxzYrUtYGsTumkuYCnLbh5R6 PuX+ENbodQNLqrWHF+D33YSEuEpODKnBI011LJJ6skMmd8uy0n7FpfOVZtUDeRn9 Npeq+wedC9lmBeBoPm7C1nlJZyNTjKBkS8G6BQby3agszAS9zG2dIMAMFMwDx4+k ScNu/zO06coBtya4SuGUibdC6v8FJERgyeXQOWHrkt9ptVw1i2H1v7ISC01peTn6 sTL3sYKnvRekPjvDZqx6g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdejiedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddt necuhfhrohhmpefluhhsthhinhcuhggvihhsshcuoehjuhhsthhinhesjhhushhtihhnfi gvihhsshdrtghomheqnecuggftrfgrthhtvghrnhepfeeuvdehieefleeiiedugfefleei uedtveevkeeigeeiudfhleeluedvkeeiveelnecuffhomhgrihhnpegsmhhivddrpggtrh hsnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhu shhtihhnsehjuhhsthhinhifvghishhsrdgtohhmpdhnsggprhgtphhtthhopedufedpmh houggvpehsmhhtphhouhhtpdhrtghpthhtoheplhgrnhiirghnohdrrghlvgigsehgmhgr ihhlrdgtohhmpdhrtghpthhtohepjhhitgdvfeeskhgvrhhnvghlrdhorhhgpdhrtghpth htoheplhgrrhhssehmvghtrghfohhordguvgdprhgtphhtthhopehrohgshheskhgvrhhn vghlrdhorhhgpdhrtghpthhtohepkhhriihkodgutheskhgvrhhnvghlrdhorhhgpdhrtg hpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgu rhhihidrshhhvghvtghhvghnkhhosehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpth htohepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgtohhmpdhrtghpthhtoheplhhi nhhugidqihhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 27 Oct 2024 13:21:51 -0400 (EDT) From: Justin Weiss To: Alex Lanzano , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko Cc: Justin Weiss , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, "Derek J . Clark" , =?UTF-8?q?Philip=20M=C3=BCller?= Subject: [PATCH v4 4/4] iio: imu: bmi270: Add support for BMI260 Date: Sun, 27 Oct 2024 10:20:25 -0700 Message-ID: <20241027172029.160134-5-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241027172029.160134-1-justin@justinweiss.com> References: <20241027172029.160134-1-justin@justinweiss.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds support for the Bosch BMI260 6-axis IMU to the Bosch BMI270 driver. Setup and operation is nearly identical to the Bosch BMI270, but has a different chip ID and requires different firmware. Firmware is requested and loaded from userspace. Adds ACPI ID BMI0160, used by several devices including the GPD Win Mini, Aya Neo AIR Pro, and OXP Mini Pro. GPD Win Mini: Device (BMI2) { Name (_ADR, Zero) // _ADR: Address Name (_HID, "BMI0160") // _HID: Hardware ID Name (_CID, "BMI0160") // _CID: Compatible ID Name (_DDN, "Accelerometer") // _DDN: DOS Device Name Name (_UID, One) // _UID: Unique ID Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings { Name (RBUF, ResourceTemplate () { I2cSerialBusV2 (0x0068, ControllerInitiated, 0x00061A80, AddressingMode7Bit, "\\_SB.I2CB", 0x00, ResourceConsumer, , Exclusive, ) GpioInt (Edge, ActiveLow, Exclusive, PullDefault, 0x0000, "\\_SB.GPIO", 0x00, ResourceConsumer, , ) { // Pin list 0x008B } }) Return (RBUF) /* \_SB_.I2CB.BMI2._CRS.RBUF */ } ... } Signed-off-by: Justin Weiss Reviewed-by: Andy Shevchenko --- drivers/iio/imu/bmi270/bmi270.h | 1 + drivers/iio/imu/bmi270/bmi270_core.c | 28 +++++++++++++++++++++++++++- drivers/iio/imu/bmi270/bmi270_i2c.c | 9 +++++++++ drivers/iio/imu/bmi270/bmi270_spi.c | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi27= 0.h index 6173be929bac..fdfad5784cc5 100644 --- a/drivers/iio/imu/bmi270/bmi270.h +++ b/drivers/iio/imu/bmi270/bmi270.h @@ -29,6 +29,7 @@ struct bmi270_chip_info { }; =20 extern const struct regmap_config bmi270_regmap_config; +extern const struct bmi270_chip_info bmi260_chip_info; extern const struct bmi270_chip_info bmi270_chip_info; =20 int bmi270_core_probe(struct device *dev, struct regmap *regmap, diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index 27e501a15095..938cf14d46bd 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -14,6 +14,11 @@ #include "bmi270.h" =20 #define BMI270_CHIP_ID_REG 0x00 + +/* Checked to prevent sending incompatible firmware to BMI160 devices */ +#define BMI160_CHIP_ID_VAL 0xD1 + +#define BMI260_CHIP_ID_VAL 0x27 #define BMI270_CHIP_ID_VAL 0x24 #define BMI270_CHIP_ID_MSK GENMASK(7, 0) =20 @@ -64,6 +69,7 @@ #define BMI270_PWR_CTRL_ACCEL_EN_MSK BIT(2) #define BMI270_PWR_CTRL_TEMP_EN_MSK BIT(3) =20 +#define BMI260_INIT_DATA_FILE "bmi260-init-data.fw" #define BMI270_INIT_DATA_FILE "bmi270-init-data.fw" =20 enum bmi270_scan { @@ -86,6 +92,13 @@ static const unsigned long bmi270_avail_scan_masks[] =3D= { 0 }; =20 +const struct bmi270_chip_info bmi260_chip_info =3D { + .name =3D "bmi260", + .chip_id =3D BMI260_CHIP_ID_VAL, + .fw_name =3D BMI260_INIT_DATA_FILE, +}; +EXPORT_SYMBOL_NS_GPL(bmi260_chip_info, IIO_BMI270); + const struct bmi270_chip_info bmi270_chip_info =3D { .name =3D "bmi270", .chip_id =3D BMI270_CHIP_ID_VAL, @@ -546,8 +559,21 @@ static int bmi270_validate_chip_id(struct bmi270_data = *bmi270_device) if (ret) return dev_err_probe(dev, ret, "Failed to read chip id"); =20 + /* + * Some manufacturers use "BMI0160" for both the BMI160 and + * BMI260. If the device is actually a BMI160, the bmi160 + * driver should handle it and this driver should not. + */ + if (chip_id =3D=3D BMI160_CHIP_ID_VAL) + return -ENODEV; + if (chip_id !=3D bmi270_device->chip_info->chip_id) - dev_info(dev, "Unknown chip id 0x%x", chip_id); + dev_info(dev, "Unexpected chip id 0x%x", chip_id); + + if (chip_id =3D=3D bmi260_chip_info.chip_id) + bmi270_device->chip_info =3D &bmi260_chip_info; + else if (chip_id =3D=3D bmi270_chip_info.chip_id) + bmi270_device->chip_info =3D &bmi270_chip_info; =20 return 0; } diff --git a/drivers/iio/imu/bmi270/bmi270_i2c.c b/drivers/iio/imu/bmi270/b= mi270_i2c.c index 394f27996059..6bd82e4362ab 100644 --- a/drivers/iio/imu/bmi270/bmi270_i2c.c +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c @@ -32,11 +32,19 @@ static int bmi270_i2c_probe(struct i2c_client *client) } =20 static const struct i2c_device_id bmi270_i2c_id[] =3D { + { "bmi260", (kernel_ulong_t)&bmi260_chip_info }, { "bmi270", (kernel_ulong_t)&bmi270_chip_info }, { } }; =20 +static const struct acpi_device_id bmi270_acpi_match[] =3D { + /* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */ + { "BMI0160", (kernel_ulong_t)&bmi260_chip_info }, + { } +}; + static const struct of_device_id bmi270_of_match[] =3D { + { .compatible =3D "bosch,bmi260", .data =3D &bmi260_chip_info }, { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info }, { } }; @@ -44,6 +52,7 @@ static const struct of_device_id bmi270_of_match[] =3D { static struct i2c_driver bmi270_i2c_driver =3D { .driver =3D { .name =3D "bmi270_i2c", + .acpi_match_table =3D bmi270_acpi_match, .of_match_table =3D bmi270_of_match, }, .probe =3D bmi270_i2c_probe, diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/b= mi270_spi.c index 7c2062c660d9..b1fd9fc5dc98 100644 --- a/drivers/iio/imu/bmi270/bmi270_spi.c +++ b/drivers/iio/imu/bmi270/bmi270_spi.c @@ -65,11 +65,13 @@ static int bmi270_spi_probe(struct spi_device *spi) } =20 static const struct spi_device_id bmi270_spi_id[] =3D { + { "bmi260", (kernel_ulong_t)&bmi260_chip_info}, { "bmi270", (kernel_ulong_t)&bmi270_chip_info }, { } }; =20 static const struct of_device_id bmi270_of_match[] =3D { + { .compatible =3D "bosch,bmi260", .data =3D &bmi260_chip_info }, { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info }, { } }; --=20 2.47.0