From nobody Tue Nov 26 09:30:25 2024 Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (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 04B8E170A0C; Fri, 18 Oct 2024 23:38:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294714; cv=none; b=t44xYp9OcGR/wL0RoHoJOWawYDoYtoUCKM/+9Cu8wpjWLZOCagFXqBEYTVbqucBVP+iPWko7usi0QNnavrvj+0gebB1Mx2ml0f4Au98pOlwgJ5YKSXijYbY2IKzSPrT8eL2OwoiCUImFYflQuf82lHOzWZyQAmFgyViLT0fIJrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294714; c=relaxed/simple; bh=8Mzxjvr6pqmET2+vuwfGzxgc5CDTOOOVPkje8V5HPr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C5NhBcB3YS5S4g3BBIISWFPtuzo/FZaZC1zKbP1ymaAzS2GMGojb9eoKFINsQtaDVka3zBmy84L+UFUiIwYpatE2hxcQbRybZT2zK+8pQ6ipNhzqRDlCQg7MpReAHGd1g7+hstuAl9TmMX5zozQUxbxkU8ANImSuaYBSLEczeeo= 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=WO09xFSL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FtnUEmnd; arc=none smtp.client-ip=103.168.172.148 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="WO09xFSL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FtnUEmnd" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id 161E71380256; Fri, 18 Oct 2024 19:38:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 18 Oct 2024 19:38:31 -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=fm1; t=1729294711; x= 1729381111; bh=h0xnwWYrsLs+HCnDx67w6s2AQcXWhkdn4kqNreYvgwQ=; b=W O09xFSLpebu3frRG41QSf+D3O9i7AqLmONVsdSBJFYXVzRow1XJAAr96tMzqazfF CIBmz8uaWy0PaXl4KF1QaXodM6sSnmuvn2bYGIMLPIUw+IsgfRLhw3wxLYgvgydT hEfasEVaAMS0EqUXA3MwnKPuZ3I5f9Cipqvbuy9Kb5vNy6nWrL0Aw9GPUxz0sLGH 3qhFENk2+OWLGmvxTkvBNn77M8xUqfaSPAxBN4RLybFxPpTSQy3T+mQNljUBoXJ5 quXdfq1BD1aFsb0mtf2JySV5lcqg2f2/lyM5swtcCoqUO6A07e6QLIPsIvuO5KQs Ic3QiF3SMSotnbqapdAsA== 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=fm2; t=1729294711; x= 1729381111; bh=h0xnwWYrsLs+HCnDx67w6s2AQcXWhkdn4kqNreYvgwQ=; b=F tnUEmndnNUcAtAFBskfbmJSE+P1QGwupt9SLndDdaXyy7e+37vaL/NWOB4/njzJq QO6rgTmLju6fPNgP4OtexNQdKY6zeqKbR4Kw0SOQl5CQF1GYFuaHLlwc/9V5oP95 StLiiavGETpN4OTU9KoAYGDA0CoId+2ed7zGg8hCCT7kjD80/P6M9l6eOUUrb6qM Kr7Qp8g18U7FIgaeN4PTe/8GSkYLtX3qSfAvA3yoSiQBcXld98Ut0BDNNLM/FJCB Ax8JHWXHnE9OeIy7PFTwJLEzz5LlmHS1ZcxEEuMu6SeHhTGE0PRdlKNJIG4gP7l4 vXcfB0c7x+MJBWHBp3iMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehgedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheplfhushhtihhnucghvghishhsuceojhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmqeenucggtffrrghtthgvrhhnpeeiffdtvdfgtddvieetffduhfejtdef teelkefgteekgeegffduiefhudeiveejkeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehjuhhsthhinhesjhhushhtihhnfigvihhsshdrtgho mhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hlrghniigrnhhordgrlhgvgiesghhmrghilhdrtghomhdprhgtphhtthhopehjihgtvdef sehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlrghrshesmhgvthgrfhhoohdruggvpd hrtghpthhtoheprhhosghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdo ughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgtohhm pdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopeguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Oct 2024 19:38:29 -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 v2 1/6] iio: imu: bmi270: Use INFO_SAMP_FREQ instead of INFO_FREQUENCY Date: Fri, 18 Oct 2024 16:36:07 -0700 Message-ID: <20241018233723.28757-2-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241018233723.28757-1-justin@justinweiss.com> References: <20241018233723.28757-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" Use IIO_CHAN_INFO_SAMP_FREQ instead of IIO_CHAN_INFO_FREQUENCY to match the BMI160 / BMI323 drivers. Fixes: 3ea51548d6b2 ("iio: imu: Add i2c driver for bmi270 imu") Signed-off-by: Justin Weiss --- drivers/iio/imu/bmi270/bmi270_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index aeda7c4228df..87036f352698 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -122,7 +122,7 @@ static const struct iio_info bmi270_info =3D { .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_FREQUENCY), \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ } =20 #define BMI270_ANG_VEL_CHANNEL(_axis) { \ @@ -131,7 +131,7 @@ static const struct iio_info bmi270_info =3D { .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_FREQUENCY), \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ } =20 static const struct iio_chan_spec bmi270_channels[] =3D { --=20 2.47.0 From nobody Tue Nov 26 09:30:25 2024 Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (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 127D21917E8; Fri, 18 Oct 2024 23:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294716; cv=none; b=nIv5AQvRflRkNHjUunjrtvx4zZYrPJ6Fy4rwUifTYfKs2Rk2kNOeC+FhFykjfxKF+eISub4LdF+EgaCXRPqwkwH79L/fpS68b68CGfLs31/el0SbBkJIOk+OuYhA8F23UbBSzq0LIBxQWz8vEs/viHrXGYti8wJhmMAhBXnYhio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294716; c=relaxed/simple; bh=GDYZwPp3yvJIK3hOsOoF8vQ04kAvhZffTQjy6lXZLRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PWK192/vXbjh6XzivhbB+tHk2c3OobfEazzNWb+rfCaO8TOeLCioLg3GJfwRA3ZGGv5Z1r0rphXh2f0rsOi4VLazAu56DlHPLUGSohpYKSJHId0yTmz1QDyh4yQ8aZB2JwOfNd8NInF4LTYJkebUI9ZRGuQK1HxSJ5yuuHWd414= 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=jif7WHSY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eJAVyMxE; arc=none smtp.client-ip=103.168.172.148 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="jif7WHSY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eJAVyMxE" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 4001B138025E; Fri, 18 Oct 2024 19:38:33 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Fri, 18 Oct 2024 19:38:33 -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=fm1; t=1729294713; x= 1729381113; bh=6QboU7Q+vBowkys+BJ+Pi/7vS9E06Wbw+TGb24bDDNI=; b=j if7WHSYIU1uQqG8nWGMPFH7wU+TkpsQflejZRNr3VGdMhh5Ta1qwhqTGw0cF4Wau RecDDbaPGmx1NREW7rxdSgDZICWIr7D6hm7hvKYElGMCSMu7cD0KyzG9UCArxglk z2Ip4WdhozPQ9fPpDEZx69xSM820Br9kcMp5VgTa1GmIXxlztocx4hDU9UYSjJg1 W1eb74HSTi+Y/HoaWviRl0N0KTfwhmJb55jfwEo1D0SOD6zhwLVg/BPdGVJ0M0dE X2fqvOPPSx5v0OdDcFdPchgyiYEvxLJZUdL/ABBMlm7gST8YgIEQyzCXjU8Pfvn4 HUrhFGFkF+4a7NYGEiWiQ== 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=fm2; t=1729294713; x= 1729381113; bh=6QboU7Q+vBowkys+BJ+Pi/7vS9E06Wbw+TGb24bDDNI=; b=e JAVyMxE/Ke8m4tB+dYYVPZqxSioeUNWE5NpHZhYKPsZh1gO12foEQV/ic6Xq3ku/ SsOp6CuOCuYy1APp2iiLNzglcZMv2hv6iSQqkYBN/FR2CJ3ZeHxhtd3yqnOzLyZ+ nLPDDJXvEjoqI/vsjsKMYWtcMYA6EYvlfPqddFjnD631o69r+Is0vIakWJFXtiyd +dkbKCU+ptKFMR9rYqA7GvHaV7xyGlt9Qlj9bw53bB0Uplz/MEPyR+dYNh9FQUAS gYoVojGoLSsAsSjUeDQeHtndU1+VjnryY+WNSNNa0tmxNiUq0A5ay4WyykPPjnHJ zm37ErMfn56sHGRKoDfEw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehgedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheplfhushhtihhnucghvghishhsuceojhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmqeenucggtffrrghtthgvrhhnpeeiffdtvdfgtddvieetffduhfejtdef teelkefgteekgeegffduiefhudeiveejkeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehjuhhsthhinhesjhhushhtihhnfigvihhsshdrtgho mhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hlrghniigrnhhordgrlhgvgiesghhmrghilhdrtghomhdprhgtphhtthhopehjihgtvdef sehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlrghrshesmhgvthgrfhhoohdruggvpd hrtghpthhtoheprhhosghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdo ughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgtohhm pdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopeguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Oct 2024 19:38:31 -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 v2 2/6] iio: imu: bmi270: Provide chip info as configuration structure Date: Fri, 18 Oct 2024 16:36:08 -0700 Message-ID: <20241018233723.28757-3-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241018233723.28757-1-justin@justinweiss.com> References: <20241018233723.28757-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" Prepare the bmi270 driver to support similar devices like the bmi260. Signed-off-by: Justin Weiss --- drivers/iio/imu/bmi270/bmi270.h | 15 ++++++++++++++- drivers/iio/imu/bmi270/bmi270_core.c | 18 +++++++++++++++--- drivers/iio/imu/bmi270/bmi270_i2c.c | 11 ++++++++--- drivers/iio/imu/bmi270/bmi270_spi.c | 11 ++++++++--- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi27= 0.h index 8ac20ad7ee94..2e8d85a4e419 100644 --- a/drivers/iio/imu/bmi270/bmi270.h +++ b/drivers/iio/imu/bmi270/bmi270.h @@ -10,10 +10,23 @@ struct device; struct bmi270_data { struct device *dev; struct regmap *regmap; + const struct bmi270_chip_info *chip_info; +}; + +enum bmi270_device_type { + BMI270, +}; + +struct bmi270_chip_info { + const char *name; + int chip_id; + const char *fw_name; }; =20 extern const struct regmap_config bmi270_regmap_config; +extern const struct bmi270_chip_info bmi270_chip_info[]; =20 -int bmi270_core_probe(struct device *dev, struct regmap *regmap); +int bmi270_core_probe(struct device *dev, struct regmap *regmap, + const struct bmi270_chip_info *chip_info); =20 #endif /* BMI270_H_ */ diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index 87036f352698..799df78ec862 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -66,6 +66,15 @@ enum bmi270_scan { BMI270_SCAN_GYRO_Z, }; =20 +const struct bmi270_chip_info bmi270_chip_info[] =3D { + [BMI270] =3D { + .name =3D "bmi270", + .chip_id =3D BMI270_CHIP_ID_VAL, + .fw_name =3D BMI270_INIT_DATA_FILE, + } +}; +EXPORT_SYMBOL_NS_GPL(bmi270_chip_info, IIO_BMI270); + static int bmi270_get_data(struct bmi270_data *bmi270_device, int chan_type, int axis, int *val) { @@ -187,7 +196,8 @@ static int bmi270_write_calibration_data(struct bmi270_= data *bmi270_device) return dev_err_probe(dev, ret, "Failed to prepare device to load init data"); =20 - ret =3D request_firmware(&init_data, BMI270_INIT_DATA_FILE, dev); + ret =3D request_firmware(&init_data, + bmi270_device->chip_info->fw_name, dev); if (ret) return dev_err_probe(dev, ret, "Failed to load init data file"); =20 @@ -274,7 +284,8 @@ static int bmi270_chip_init(struct bmi270_data *bmi270_= device) return bmi270_configure_imu(bmi270_device); } =20 -int bmi270_core_probe(struct device *dev, struct regmap *regmap) +int bmi270_core_probe(struct device *dev, struct regmap *regmap, + const struct bmi270_chip_info *chip_info) { int ret; struct bmi270_data *bmi270_device; @@ -287,6 +298,7 @@ int bmi270_core_probe(struct device *dev, struct regmap= *regmap) bmi270_device =3D iio_priv(indio_dev); bmi270_device->dev =3D dev; bmi270_device->regmap =3D regmap; + bmi270_device->chip_info =3D chip_info; =20 ret =3D bmi270_chip_init(bmi270_device); if (ret) @@ -294,7 +306,7 @@ int bmi270_core_probe(struct device *dev, struct regmap= *regmap) =20 indio_dev->channels =3D bmi270_channels; indio_dev->num_channels =3D ARRAY_SIZE(bmi270_channels); - indio_dev->name =3D "bmi270"; + indio_dev->name =3D chip_info->name; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &bmi270_info; =20 diff --git a/drivers/iio/imu/bmi270/bmi270_i2c.c b/drivers/iio/imu/bmi270/b= mi270_i2c.c index e9025d22d5cc..742149701849 100644 --- a/drivers/iio/imu/bmi270/bmi270_i2c.c +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c @@ -18,22 +18,27 @@ static int bmi270_i2c_probe(struct i2c_client *client) { struct regmap *regmap; struct device *dev =3D &client->dev; + const struct bmi270_chip_info *chip_info; + + chip_info =3D i2c_get_match_data(client); + if (!chip_info) + return -ENODEV; =20 regmap =3D devm_regmap_init_i2c(client, &bmi270_i2c_regmap_config); if (IS_ERR(regmap)) return dev_err_probe(dev, PTR_ERR(regmap), "Failed to init i2c regmap"); =20 - return bmi270_core_probe(dev, regmap); + return bmi270_core_probe(dev, regmap, chip_info); } =20 static const struct i2c_device_id bmi270_i2c_id[] =3D { - { "bmi270", 0 }, + { "bmi270", (kernel_ulong_t)&bmi270_chip_info[BMI270] }, { } }; =20 static const struct of_device_id bmi270_of_match[] =3D { - { .compatible =3D "bosch,bmi270" }, + { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info[BMI270] }, { } }; =20 diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/b= mi270_spi.c index 34d5ba6273bb..3d240f9651bc 100644 --- a/drivers/iio/imu/bmi270/bmi270_spi.c +++ b/drivers/iio/imu/bmi270/bmi270_spi.c @@ -50,6 +50,11 @@ static int bmi270_spi_probe(struct spi_device *spi) { struct regmap *regmap; struct device *dev =3D &spi->dev; + const struct bmi270_chip_info *chip_info; + + chip_info =3D spi_get_device_match_data(spi); + if (!chip_info) + return -ENODEV; =20 regmap =3D devm_regmap_init(dev, &bmi270_regmap_bus, dev, &bmi270_spi_regmap_config); @@ -57,16 +62,16 @@ static int bmi270_spi_probe(struct spi_device *spi) return dev_err_probe(dev, PTR_ERR(regmap), "Failed to init i2c regmap"); =20 - return bmi270_core_probe(dev, regmap); + return bmi270_core_probe(dev, regmap, chip_info); } =20 static const struct spi_device_id bmi270_spi_id[] =3D { - { "bmi270" }, + { "bmi270", (kernel_ulong_t)&bmi270_chip_info[BMI270] }, { } }; =20 static const struct of_device_id bmi270_of_match[] =3D { - { .compatible =3D "bosch,bmi270" }, + { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info[BMI270] }, { } }; =20 --=20 2.47.0 From nobody Tue Nov 26 09:30:25 2024 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (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 014E8191F7A; Fri, 18 Oct 2024 23:38:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294718; cv=none; b=D7p9F9ZxWE6GrCFCLwLN6kjvoDpwuQCpYIDwa83VSPLppZPjp52pOis/NbMDwbEd6eOgMAQpGEttSllhWeDHEyCYqvIEzpow0IbnBpIB7ZrpwBT5+p2R6A2sbbIWXNIjciXnSN4Y7yg5UofxVBNzTvsmajbSFm5IIqqf0cUg4vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294718; c=relaxed/simple; bh=/W9FGWS2rn2hVxrPOJYydbV38Tzx81yvg95cOMZh0KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jdNs5diFzpdPUveAnIP4bDdV/U63mhlCZbj/jF1ZOT30HISBrNaD31Kbk4ZLrVkl2KAhdRMTPxHddmuBqiUJN/PHeA1EBqdUytdJNJM2kWPemasWQVR+j7Pfgw2TFMi+TXxbRPkxhEXk4Ze3K0G/BHJXfLUaTuOu9sHL9FS3vi0= 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=DjoInp1p; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U+/vzWEg; arc=none smtp.client-ip=103.168.172.153 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="DjoInp1p"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U+/vzWEg" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0ACB61140193; Fri, 18 Oct 2024 19:38:35 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Fri, 18 Oct 2024 19:38:35 -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=fm1; t=1729294715; x= 1729381115; bh=oa9cgVMycUuHRIX2mC52gb2eRMUx9qVL+xj6GNcI2Jw=; b=D joInp1pzYZxGFEPQ2Rlnwbm/i/6m8BhPM2der/Zd8QQV056YZ+zefJos2hye3VvG GEIokk8XN56/xzM5XqxKe8sUTsPFuOEDpcgLO2rg7BxJUlVhPvLOwmuunNNGqpEC 71rTC9ZVDnQEinRDNVgNs0rxQoBnFQvvealwOQXKNb4ImAXInWVQq9NHCWxM8Dse gj4BAx7NZo26Y6Z+k0RNioLw3Uw4SHvAxdTa9+KuusJUYJH9aKqgnkyrq49rDJ6S I8AqQ7GMjfN4wgTJ5Aih5f5cbwB5eP6L5VF/fdiQIgUpQbIKAkmbh3+VkzLBBvJ/ orinX3DtIfWrHQsOlEpKg== 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=fm2; t=1729294715; x= 1729381115; bh=oa9cgVMycUuHRIX2mC52gb2eRMUx9qVL+xj6GNcI2Jw=; b=U +/vzWEgGTxVIy+Gh/6iN/abYhdm1ucR4mPd2XYdvsy1dYCNF3K77ZsrYZMSrxS3I AS/5sVtjN6/2TVdr6+pbMI57Pd4KbrDTHYKJaa4mgE4ZpMaVwZ6JQkqMPCGOt55N /7nM6ihLDrZnszPdJamUm7LiZ39XX1IzjzAIcU6pf83buYdIM6e99dBnnIKrTz06 TzRISHSxWXWdR/gZJv/mFs6Qqa/yTOuSkoiWLdGrI6qHORyTbMhZIPu0nepGCltA ojzUY5Ow/wfjYByauOmNA3n7bKo3KOpbfNS6TV1RgVz6CubQ3LD4PDh9si/39ULr CoE19VIqkXB0H8sKB3eFg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehgedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheplfhushhtihhnucghvghishhsuceojhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmqeenucggtffrrghtthgvrhhnpeeltdelfefgleetjeeuteehudejledt gedujeeutdeuledtgeejvdehhfeileegtdenucffohhmrghinhepuggvvhhitggvthhrvg gvrdhorhhgpdgsohhstghhqdhsvghnshhorhhtvggtrdgtohhmnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhushhtihhnsehjuhhsthhinh ifvghishhsrdgtohhmpdhnsggprhgtphhtthhopeduvddpmhhouggvpehsmhhtphhouhht pdhrtghpthhtoheplhgrnhiirghnohdrrghlvgigsehgmhgrihhlrdgtohhmpdhrtghpth htohepjhhitgdvfeeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhgrrhhssehmvght rghfohhordguvgdprhgtphhtthhopehrohgshheskhgvrhhnvghlrdhorhhgpdhrtghpth htohepkhhriihkodgutheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdo ughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehjuhhsthhinhesjhhushhtihhnfi gvihhsshdrtghomhdprhgtphhtthhopehlihhnuhigqdhiihhosehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtohepuggvvhhitggvthhrvggvsehvghgvrhdrkhgvrhhnvg hlrdhorhhg X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Oct 2024 19:38:33 -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 v2 3/6] dt-bindings: iio: imu: Add Bosch BMI260 Date: Fri, 18 Oct 2024 16:36:09 -0700 Message-ID: <20241018233723.28757-4-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241018233723.28757-1-justin@justinweiss.com> References: <20241018233723.28757-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 devicetree description document for Bosch BMI260, a 6-Axis IMU. Signed-off-by: Justin Weiss --- .../bindings/iio/imu/bosch,bmi260.yaml | 77 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi260.= yaml diff --git a/Documentation/devicetree/bindings/iio/imu/bosch,bmi260.yaml b/= Documentation/devicetree/bindings/iio/imu/bosch,bmi260.yaml new file mode 100644 index 000000000000..6786b5e4d0fa --- /dev/null +++ b/Documentation/devicetree/bindings/iio/imu/bosch,bmi260.yaml @@ -0,0 +1,77 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/bosch,bmi260.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bosch BMI260 6-Axis IMU + +maintainers: + - Justin Weiss + +description: | + BMI260 is a 6-axis inertial measurement unit that can measure accelerati= on and + angular velocity. The sensor also supports configurable interrupt events= such + as motion detection and step counting. The sensor can communicate over + I2C or SPI. + https://www.bosch-sensortec.com/products/motion-sensors/imus/bmi260/ + +properties: + compatible: + const: bosch,bmi260 + + reg: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + + interrupts: + minItems: 1 + maxItems: 2 + + interrupt-names: + minItems: 1 + maxItems: 2 + items: + enum: + - INT1 + - INT2 + + drive-open-drain: + description: + set if the specified interrupt pins should be configured as + open drain. If not set, defaults to push-pull. + + mount-matrix: + description: + an optional 3x3 mounting rotation matrix. + +required: + - compatible + - reg + - vdd-supply + - vddio-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + imu@68 { + compatible =3D "bosch,bmi260"; + reg =3D <0x68>; + vdd-supply =3D <&vdd>; + vddio-supply =3D <&vddio>; + interrupt-parent =3D <&gpio1>; + interrupts =3D <16 IRQ_TYPE_EDGE_RISING>; + interrupt-names =3D "INT1"; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 6011af70c12e..73b6b7721dd8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4047,6 +4047,7 @@ BOSCH SENSORTEC BMI270 IMU IIO DRIVER M: Alex Lanzano L: linux-iio@vger.kernel.org S: Maintained +F: Documentation/devicetree/bindings/iio/imu/bosch,bmi260.yaml F: Documentation/devicetree/bindings/iio/imu/bosch,bmi270.yaml F: drivers/iio/imu/bmi270/ =20 --=20 2.47.0 From nobody Tue Nov 26 09:30:25 2024 Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (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 C655C1922D8; Fri, 18 Oct 2024 23:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294720; cv=none; b=DY1xoPzUEqaHXUidxvODqDcKmyJ/qyJqfZun/e/8fyXnx55356sbMGkYLQD/Eu4o/MlCUn0/ZArvcDxUTs3e0ZZAzZb0l9BErgA+snOt4Pn7FV7heY02MnWo3DyVBybyWbsfKBcvdh6oGpTEhZMSLbo436Z9FgkXkBPEkd+n+FM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294720; c=relaxed/simple; bh=efEEDDEcwsl9RrrRrmM9w38qZUfKeTJkwV2M+yOy4MY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vv8GEXC7eYq9SPssL4wG9UXjuMcf3hDx9RsEd6g9IfymFDH0w0+/QP06/9nPRJ4aSwI53TA1Aa7qGIAvbbNEvjwlvvWwQVunzUFxSBFbPH10hwYDperf0SnqPhefoyFlkV6vZ33E6dvzyuD2tm+sIQb9YB/7TwWnJN2MNcnng9c= 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=QwCnc2sD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ek89c0VS; arc=none smtp.client-ip=103.168.172.148 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="QwCnc2sD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ek89c0VS" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id F3A95138027C; Fri, 18 Oct 2024 19:38:36 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Fri, 18 Oct 2024 19:38:36 -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=fm1; t=1729294716; x= 1729381116; bh=Lwz5amVvIkTFXl6lGJDlLiSiyJHjLWdvDvVr3n66PJo=; b=Q wCnc2sDUOPdsDB7YBQFGfSR04Wl8af1bqNVFLf0IruzsX+AlYetm63GPXUZmxR9d gcMZqvuk18VK7G4Jm/dv3awiW7Hs7HzzzC9ZIhHu8V2fzzt3F3F5lgOdULNdwylE EGbj2aTbglOc71keEq+b8MB2LSmk4ZcyHQg2HTSjOq1vqSRJXCqH29Eq5gqz+kUr hhY/7thSbxvR8dAq6+AwKLtx71J+ui6aF87CRRY64pINuCCBcUMNsKjbkz9tPsTO 74zLR77emCIdBtNTIN+2qDHBWG9tgoCjasXN55CWgspLj5D+WHIvEeFqLkLfaeJ6 5MbK4jPrPJb+Yb626n17Q== 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=fm2; t=1729294716; x= 1729381116; bh=Lwz5amVvIkTFXl6lGJDlLiSiyJHjLWdvDvVr3n66PJo=; b=e k89c0VSXQsG5Ycx6dwPvEGZUTYIzBlhRzDwPknCOahYFjYL3QpZhgms9eZ3envYb vY9zBUxcjj/Lw4V4n6ckWrjVa9mWAJWqs+2oIHwBA+TrU+hCbBMKAAimpV2iJRht xixpBDY5u/cEs5JJNHQoZAIqRAT52tF5Nf3jX7eiGeBKv4Yg1BX5yn+MoXfkekOL klqMtFyecZMRVR7Tt2UEEI8tbOLm1K0iIFNlh527hMhev1QE94PffCP+tVPpUw+V NVIbnbcVPl8Sgt2NcRx8wCQCwkPpNkFW5gi05bJOQ799W2G2GsDRu2lk9ihhCVld 2qcvNTi8FRnIGGcSt7DyQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehgedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheplfhushhtihhnucghvghishhsuceojhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmqeenucggtffrrghtthgvrhhnpeeiffdtvdfgtddvieetffduhfejtdef teelkefgteekgeegffduiefhudeiveejkeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehjuhhsthhinhesjhhushhtihhnfigvihhsshdrtgho mhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hlrghniigrnhhordgrlhgvgiesghhmrghilhdrtghomhdprhgtphhtthhopehjihgtvdef sehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlrghrshesmhgvthgrfhhoohdruggvpd hrtghpthhtoheprhhosghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdo ughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgtohhm pdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopeguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Oct 2024 19:38:35 -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 v2 4/6] iio: imu: bmi270: Add support for BMI260 Date: Fri, 18 Oct 2024 16:36:10 -0700 Message-ID: <20241018233723.28757-5-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241018233723.28757-1-justin@justinweiss.com> References: <20241018233723.28757-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. Signed-off-by: Justin Weiss --- drivers/iio/imu/bmi270/bmi270.h | 1 + drivers/iio/imu/bmi270/bmi270_core.c | 25 +++++++++++++++++++++++-- drivers/iio/imu/bmi270/bmi270_i2c.c | 13 +++++++++++++ drivers/iio/imu/bmi270/bmi270_spi.c | 8 ++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi27= 0.h index 2e8d85a4e419..51e374fd4290 100644 --- a/drivers/iio/imu/bmi270/bmi270.h +++ b/drivers/iio/imu/bmi270/bmi270.h @@ -14,6 +14,7 @@ struct bmi270_data { }; =20 enum bmi270_device_type { + BMI260, BMI270, }; =20 diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index 799df78ec862..b30201dc4e22 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -11,6 +11,8 @@ #include "bmi270.h" =20 #define BMI270_CHIP_ID_REG 0x00 +#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 @@ -55,6 +57,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 { @@ -67,6 +70,11 @@ enum bmi270_scan { }; =20 const struct bmi270_chip_info bmi270_chip_info[] =3D { + [BMI260] =3D { + .name =3D "bmi260", + .chip_id =3D BMI260_CHIP_ID_VAL, + .fw_name =3D BMI260_INIT_DATA_FILE, + }, [BMI270] =3D { .name =3D "bmi270", .chip_id =3D BMI270_CHIP_ID_VAL, @@ -163,8 +171,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 - if (chip_id !=3D BMI270_CHIP_ID_VAL) - dev_info(dev, "Unknown chip id 0x%x", chip_id); + /* + * 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, "Unexpected chip id 0x%x", chip_id); + + if (chip_id =3D=3D BMI260_CHIP_ID_VAL) + bmi270_device->chip_info =3D &bmi270_chip_info[BMI260]; + else if (chip_id =3D=3D BMI270_CHIP_ID_VAL) + bmi270_device->chip_info =3D &bmi270_chip_info[BMI270]; =20 return 0; } diff --git a/drivers/iio/imu/bmi270/bmi270_i2c.c b/drivers/iio/imu/bmi270/b= mi270_i2c.c index 742149701849..d6417b7c799c 100644 --- a/drivers/iio/imu/bmi270/bmi270_i2c.c +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c @@ -33,11 +33,23 @@ static int bmi270_i2c_probe(struct i2c_client *client) } =20 static const struct i2c_device_id bmi270_i2c_id[] =3D { + { "bmi260", (kernel_ulong_t)&bmi270_chip_info[BMI260] }, { "bmi270", (kernel_ulong_t)&bmi270_chip_info[BMI270] }, { } }; =20 +static const struct acpi_device_id bmi270_acpi_match[] =3D { + /* OrangePi NEO */ + { "BMI0260", (kernel_ulong_t)&bmi270_chip_info[BMI260] }, + /* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */ + { "BMI0160", (kernel_ulong_t)&bmi270_chip_info[BMI260] }, + /* GPD Win Max 2 */ + { "10EC5280", (kernel_ulong_t)&bmi270_chip_info[BMI260] }, + { } +}; + static const struct of_device_id bmi270_of_match[] =3D { + { .compatible =3D "bosch,bmi260", .data =3D &bmi270_chip_info[BMI260] }, { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info[BMI270] }, { } }; @@ -45,6 +57,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 3d240f9651bc..88173e9a3529 100644 --- a/drivers/iio/imu/bmi270/bmi270_spi.c +++ b/drivers/iio/imu/bmi270/bmi270_spi.c @@ -66,11 +66,18 @@ static int bmi270_spi_probe(struct spi_device *spi) } =20 static const struct spi_device_id bmi270_spi_id[] =3D { + { "bmi260", (kernel_ulong_t)&bmi270_chip_info[BMI260] }, { "bmi270", (kernel_ulong_t)&bmi270_chip_info[BMI270] }, { } }; =20 +static const struct acpi_device_id bmi270_acpi_match[] =3D { + { "BOSC0260", (kernel_ulong_t)&bmi270_chip_info[BMI260] }, + { } +}; + static const struct of_device_id bmi270_of_match[] =3D { + { .compatible =3D "bosch,bmi260", .data =3D &bmi270_chip_info[BMI260] }, { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info[BMI270] }, { } }; @@ -78,6 +85,7 @@ static const struct of_device_id bmi270_of_match[] =3D { static struct spi_driver bmi270_spi_driver =3D { .driver =3D { .name =3D "bmi270", + .acpi_match_table =3D bmi270_acpi_match, .of_match_table =3D bmi270_of_match, }, .probe =3D bmi270_spi_probe, --=20 2.47.0 From nobody Tue Nov 26 09:30:25 2024 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (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 92008192593; Fri, 18 Oct 2024 23:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294721; cv=none; b=RiQOOqwv4LbwKzK8yfaDCSAlZDXGgYbCx5mYJBVIY1aGVC7MIwPSjSL5lMyfCc5kfMKsvtwUgfp/HRfpKOITFe4IJUqiyMDEECAZZcvz9DUzKNW5MjQEiNdChzeONLkogdSglhXK7JHs0nXFE2MSgWj/001g9qJk4mbnLqfI4Ng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294721; c=relaxed/simple; bh=Rb0+K9ekan0pIdjctjIWQU5HI8jwStHR65Uuq2wijnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KQiYbTNelGrunjTkjqW/G13EREWsF72NQOelpc0phAj52giL8Y0tNo2aghxKG1RmmD+U7W6keMpjSvKusRrnc5EJmk5IgGBfMPGQD7l4gQIZAQpIieEcRCF5nYKgJHfVruTDOZ7dvdGWuXS2+H7rm3kjIiTPPESuX8nPCx7i8kw= 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=O/bwy1Hh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=py5i+2C1; arc=none smtp.client-ip=103.168.172.153 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="O/bwy1Hh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="py5i+2C1" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id B60AC11400B5; Fri, 18 Oct 2024 19:38:38 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Fri, 18 Oct 2024 19:38:38 -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=fm1; t=1729294718; x= 1729381118; bh=jIzjZw+jZqRy27lPMRRLcFPQ1p9XahgRDxdC2JepzMY=; b=O /bwy1HhRLHD1IC+EXmZaUtn9rAhtn8qVt2Up5uBgF8rsCbXkG8z5bDKZ8xVoIr/q otRJaCTku/KJcL9IiblprZLd0hfsjOG3qgZt24HNXLNTg/aG98AR+Zq5Usu4LpVC tBZf/ZPz6EcjmYqeBruBi2q69mhehf3HQTJXq4pgQruWWV4obh0iHISAgPm2zTpF UNoHmD+oEJrQjSJfwnFEx3SxvcMY1Ewxo1K+5Xnaz+sgSip1YFvjH9a/4ZX5Kf6f CiIM5oehRDaPuoJTU5++E9qKwVnhWxBAE4FT3jXSL9dRZjN564wBBwstCrlhdTJH ZLyv3wwkPAXb0tW7Hltnw== 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=fm2; t=1729294718; x= 1729381118; bh=jIzjZw+jZqRy27lPMRRLcFPQ1p9XahgRDxdC2JepzMY=; b=p y5i+2C1ZV5BpdNbG7LjWgx+hPql7QEPJCesPcA+xXdJ8JpIvSn6NJX0TYqD+njG2 p8IM96Gqo9NSCCUVusaqgcVTvaIL0hhhsnYPwWZVN9+shi/u7tOJM3vzVSj/RRnY YXQza9qiI+jnB+pnPMosWHrHwdBV12iv8OKxpXvHTPk0rt32Pp5olsOwZgXfZTI6 ayUJnkUM16/2TAiTVAitcItG8wEhViJLVh3jA9SwbGjSaSFJlcf445glLo9gHlFD mHaZadtefBjc3rwS7vG+5FL6e6N/Vgr39mtnieHVD6bHqHHSdd811PL5fO0bqzg1 MvtBy1uRQzcBQPwxv2QTw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehgedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheplfhushhtihhnucghvghishhsuceojhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmqeenucggtffrrghtthgvrhhnpeeiffdtvdfgtddvieetffduhfejtdef teelkefgteekgeegffduiefhudeiveejkeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehjuhhsthhinhesjhhushhtihhnfigvihhsshdrtgho mhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hlrghniigrnhhordgrlhgvgiesghhmrghilhdrtghomhdprhgtphhtthhopehjihgtvdef sehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlrghrshesmhgvthgrfhhoohdruggvpd hrtghpthhtoheprhhosghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdo ughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgtohhm pdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopeguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Oct 2024 19:38:37 -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 v2 5/6] iio: imu: bmi270: Add triggered buffer for Bosch BMI270 IMU Date: Fri, 18 Oct 2024 16:36:11 -0700 Message-ID: <20241018233723.28757-6-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241018233723.28757-1-justin@justinweiss.com> References: <20241018233723.28757-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 51e374fd4290..844d70a7d32e 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 is 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 enum bmi270_device_type { diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index b30201dc4e22..69b011f97324 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 @@ -67,6 +69,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 { @@ -83,6 +96,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) { @@ -140,6 +174,13 @@ static const struct iio_info bmi270_info =3D { .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), \ + .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) { \ @@ -149,6 +190,13 @@ static const struct iio_info bmi270_info =3D { .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), \ + .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 { @@ -158,6 +206,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) @@ -328,9 +377,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 Tue Nov 26 09:30:25 2024 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (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 50BC118FC75; Fri, 18 Oct 2024 23:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294723; cv=none; b=VxxCu4a7atngLpjBxl7n7ghstoBuBFQC0TH3mdqyyYi8CvXMpwokpXH6agP20l0Y1LuT5LhwdaqZeSFTCWYHvH0NI91BbRoHYVfz9nahEcbZScja8h8CC9qnD+VvVjt30z1LteUxG4fmK91M5+U9Gs5Ur3CDEtyV5wcgyYDrxNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729294723; c=relaxed/simple; bh=H3o6ust5TtWf1YCVzQJ2oGdTQvq7q/eoAIiPmlCTtH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DJzi8/hXGD0xR5SjlJ3HzIvV+GsrefjPsmqm58WuVHieXBfYjLN6TvH14w1LXKwB7Y8VbDf2eViOwdZ+JTq+oLWnwTjvyYahvtHeEoIXmdFVz7t+tQM+C8qm0TcigbXBN5okSaLFyM70mAtCsmH4CPOol8mB9zQqQXtJbpi6r0g= 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=aGnroQid; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z9prkcC5; arc=none smtp.client-ip=103.168.172.153 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="aGnroQid"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z9prkcC5" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8626911401AA; Fri, 18 Oct 2024 19:38:40 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Fri, 18 Oct 2024 19:38:40 -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=fm1; t=1729294720; x= 1729381120; bh=kddeGIUsRBS+Tfy6+HMUhxC0WI/aqwj15PsI6K+5vZw=; b=a GnroQidNwmtlS8kQPWkj+y1Egu3mjbd2D11c2cjfELzbZ4F7SZhfs5hG9x6C4jUp 0Z08cw+SyGBd2eRTxhLL09MRbtAfcMmGB8gdKf/GdLXZkbyGWUTe9XQT3i+KVUwa qiC9js8dJOSUnMrWc+wpRc3IAbCjb6Ohl9w7EeszVr4mZR+0UdfaZuKsAKvea0In oBADi3uUmbRoQhmdLz8wUaM75v66A4BgJO+ZyKzza5tteNmSy4gP7QtSau3xAgDC Mdg4CwKpNxYi2tAO90hcAAweNyCN0jeGLSkbBBclk25jQ9pG6Z/uKb4vHN3hMex7 oNMNJzz89OG3AmF+ge27g== 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=fm2; t=1729294720; x= 1729381120; bh=kddeGIUsRBS+Tfy6+HMUhxC0WI/aqwj15PsI6K+5vZw=; b=Z 9prkcC5UmqbY1LQk1OVISIqOljLjWSpnxd1gNoe79skoGsoU8pQO9re/fHtt5jz1 jcG4sW3ztocmWjvLlm0dPBwOJjPTToliy5yTQxkixeggR68Y6BbAVzL/aX/GSchv eG77F3C4rKsmJ5CQcrz82Gx1vAsAmTVTiz8i+c9Tca+Wz0W+P2JV86dKK4Px6KmR zSwOYpiXCPFzzl1Gf8629Q05HWIfQatFuGWT3fpHuU44tTj5kY4TNXvSWARZ/iep 7Drz5cF2bgNy+me15oWl47CmzIGkpP/qrb3sWfu/yaxO2Aa4qfucXionjYh1t+cB paXU4s3I5/SMt2NglWfow== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehgedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomheplfhushhtihhnucghvghishhsuceojhhushhtihhnsehjuhhsthhinhifvg hishhsrdgtohhmqeenucggtffrrghtthgvrhhnpeeiffdtvdfgtddvieetffduhfejtdef teelkefgteekgeegffduiefhudeiveejkeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehjuhhsthhinhesjhhushhtihhnfigvihhsshdrtgho mhdpnhgspghrtghpthhtohepuddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hlrghniigrnhhordgrlhgvgiesghhmrghilhdrtghomhdprhgtphhtthhopehjihgtvdef sehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlrghrshesmhgvthgrfhhoohdruggvpd hrtghpthhtoheprhhosghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdo ughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepjhhushhtihhnsehjuhhsthhinhifvghishhsrdgtohhm pdhrtghpthhtoheplhhinhhugidqihhiohesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopeguvghvihgtvghtrhgvvgesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: icf614246:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Oct 2024 19:38:38 -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 v2 6/6] iio: imu: bmi270: Add scale and sampling frequency to BMI270 IMU Date: Fri, 18 Oct 2024 16:36:12 -0700 Message-ID: <20241018233723.28757-7-justin@justinweiss.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241018233723.28757-1-justin@justinweiss.com> References: <20241018233723.28757-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 | 338 +++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index 69b011f97324..bc3604e66f85 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 @@ -35,6 +36,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 @@ -43,6 +47,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 @@ -96,6 +103,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; @@ -158,6 +424,70 @@ 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; + } + + return 0; +} + +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; } @@ -165,6 +495,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) { \ @@ -174,6 +506,9 @@ static const struct iio_info bmi270_info =3D { .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', \ @@ -190,6 +525,9 @@ static const struct iio_info bmi270_info =3D { .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