From nobody Tue Nov 26 08:28:04 2024 Received: from fout-b8-smtp.messagingengine.com (fout-b8-smtp.messagingengine.com [202.12.124.151]) (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 886D81993BA; Sun, 20 Oct 2024 22:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461691; cv=none; b=NXBvGhjiHrfkcu51SmQWZAohMRGMOJF6/Jt6z6yQWMslEPSpJEW3fSPcpQvuDXMpiEih1JKSCgACku84L0tLO7fSZ8l1QnUMC2cZQgu0vZgAgOxeKQ8L86sm8PmHuIGDLqw/Z75vlYGMELeqlJpfPIKIhIhm0yVPtfLeD77X+zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461691; c=relaxed/simple; bh=CxNCSF8NoJCOEhg4BM8L5ZjwqS4AkGsSGeH5dxRmZvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RDy2hdqYLjTflhSLKjoxZjks5A1IWie7ERNGbSE1aJ15/ow2DzsHijco8kPZzV/KSBgwyqiW4tuof2XQT1tQ+YHaAFw3bzqp8kYEzoJAmcab+HYgxCbVATMonc/XkO7CLY3hBq7YZ8xYDA24h2NBbRxmARZYKT4iK8hpmpg3mDM= 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=p1LYkbyp; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZIkPC6Kx; arc=none smtp.client-ip=202.12.124.151 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="p1LYkbyp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZIkPC6Kx" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id 5DD6D114008E; Sun, 20 Oct 2024 18:01:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Sun, 20 Oct 2024 18:01:28 -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=1729461688; x= 1729548088; bh=v7JdK+EfV4NU1+GpmRFSjPS2tNauAbxiLGo8QCU/BU0=; b=p 1LYkbyprI8+dTsKrO6SlUlPdRY/HJvY4lZtCIiqWP9TCeir5HcQzwyE+ABrYDk4f j+Gjxi6Z7IoAZpMVHbL5Xyxe1ybG1REa3swQ68rNYWdjXBL84eGNIhDI0OWKAUXJ pePIFUW1k0pQvI/Ytq/ONvYtie9Rb0pH+eN16ewUDrnFuQjIREgS4YBt8X48VLxe zTLzvdenBWjYngUBpF93HkM8edhCx/XphQ5L9Vfy2FSoHbefPl+MKXqKYKTDsg8/ OYHqfBQ35vhsPIA6c/2K89+q6b9Q5RRJDmPlOe4tIUodJyKu5r1ck54+0E98tyDa dl1sBOXpV+t4Lv294yauA== 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=1729461688; x= 1729548088; bh=v7JdK+EfV4NU1+GpmRFSjPS2tNauAbxiLGo8QCU/BU0=; b=Z IkPC6Kxf7o3hFYGTE/SKMKvh/fgpbiFf0eJxaAn3T6L2Pa0rVuEl0u+UrXbYZTst QEnKnv6VL2gXc05BRc5h4Ic7D50sVE1sn21YlhEqUHULfCTJdU3WKKqg6AXsHjzG YR2oaRZercwUmAizbzW7U5Zdd+f590xs6qLWaGRzb/yNrobz/ouphpjMKE/ZZJec CW0VEef6EpmYdsr8nFhDCPsD5cCgJp7ao9DXE6zCRizY4uBtnKEir4c/kYalCZPL Ew9zirUlSLrWLrXd0YzP9JlhaEzqEKl1RdJNZ1msjyKgV1k0wcOE3paa8UTbSIHQ l4Ix1UdRjw2fRZv5v6CiA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehkedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheplfhushhtihhnucghvghishhsuceojhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmqeenucggtffrrghtthgvrhhnpeeiffdtvdfgtddvieetffduhfejtdef teelkefgteekgeegffduiefhudeiveejkeenucevlhhushhtvghrufhiiigvpedunecurf grrhgrmhepmhgrihhlfhhrohhmpehjuhhsthhinhesjhhushhtihhnfigvihhsshdrtgho mhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hlrghniigrnhhordgrlhgvgiesghhmrghilhdrtghomhdprhgtphhtthhopehjihgtvdef sehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlrghrshesmhgvthgrfhhoohdruggvpd hrtghpthhtoheprhhosghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdo ughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgtohhm pdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopeguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 20 Oct 2024 18:01:26 -0400 (EDT) From: Justin Weiss To: Alex Lanzano , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley 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 v3 5/6] iio: imu: bmi270: Add triggered buffer for Bosch BMI270 IMU Date: Sun, 20 Oct 2024 15:00:09 -0700 Message-ID: <20241020220011.212395-6-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241020220011.212395-1-justin@justinweiss.com> References: <20241020220011.212395-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 d8f6d7cf47fc..fdfad5784cc5 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 24e45d6f0706..5b643afae9f7 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 @@ -70,6 +72,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 bmi260_chip_info =3D { @@ -86,6 +99,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) { @@ -141,6 +175,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) { \ @@ -148,6 +189,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 { @@ -157,6 +205,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) @@ -327,9 +376,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