From nobody Tue Nov 26 06:30:01 2024 Received: from fhigh-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (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 701CF18C936; Sun, 20 Oct 2024 22:01:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461682; cv=none; b=rfneUY6AtVqbYcPLpwOHjTHPvZ3kc1+B8Ts416PYQ22qc/YiiuXzYUH9tlGh9OOnpHGPbrnTYTy3pZjmxkZ8ERbIPbxSuRG/BGJk2jAf6H3ZnbtRVI9bZHS4ZH/KbkfjL6XmXG9QK4ataUGjYXt43r6yEBLhhhPBsx0HmLW4v0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461682; c=relaxed/simple; bh=qdw5MFMRgYhe+aVYPJBeXeKc1wATpB/PgzF8oG7E8mQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n31JJHDNyeyYclSnkoLCmy12/9BfkifXSqYEKaJ5G2pzc6qm/gy6Sl9dwr6goK/jjZQqDUsV85w4+3uGoHJDLzhDZMNwXMep6Jbw0KFUKmCvu0DsCa5qC+oLXERB9ueAoH5dLNe97ZSwexG4CtgPZhXkh0lJAV34783nphBf7b4= 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=JWF91zCd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lDr8om9h; arc=none smtp.client-ip=202.12.124.154 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="JWF91zCd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lDr8om9h" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 307E12540090; Sun, 20 Oct 2024 18:01:19 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Sun, 20 Oct 2024 18:01:19 -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=1729461679; x= 1729548079; bh=Mj+psUKkmik1WyC08oA/zlwOnP61AyJE1/Yu7zehAGg=; b=J WF91zCdA/933hY/YBMwjqE3371Ux+NYk57RTVbE35bT3KqmZIe4hGycP5s9q4ykw LINzBR/RtZNOwJcg5QdAWcsdWRKunA/TG5gtTvDlzsIoB0YFfcv58H33659sdMN/ 9VKadxnLiRR1UKRjUcPSaY+gN+dDg+YoeV4tJ4vb8s3Su6MCrsN9LURkOEj3ri48 6i8Hg7ofNC5ftLA/Pyr9u2idOQ8MdECkCWK/9EqzDoJWADtrv+84SKD+KoiLcnSw AqG3Wke7IUTcWxGQLGskDpqCBxmf+v2XSAj+90VgxpGuNf8QzuX7M1pH1Ta9R4FY 8tl1REZ53BIPGnODH7o0Q== 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=1729461679; x= 1729548079; bh=Mj+psUKkmik1WyC08oA/zlwOnP61AyJE1/Yu7zehAGg=; b=l Dr8om9hPMfxIzlFu8Z25t6dgAqca16aeFyL9znQaGOdTWLrWfK9FNH22PdxUO5T1 0kuk1cn8EoGfOjFmfqGmBL9PF6IQLt+AZ8q8IaBHG+AbmIQoavJje+bFdxZB6whT 3Ca/ilJkOVqOkQQfngaDhfhaKfF1a1H92KDH3yoH2fl9cAud4xcsHgCqkxZrB/yO ViA1ZKgybXGynL5Yufv+3JVRVZVWsepoO4lPxXgV42sjYJhsvt+6ekXdTbifbmz3 hpmjxaJI2fkFKIO4L167THA53U/K5N+aQ0UqtNBiTxW/9HjzUmWHkjlrFPHyh0ql +/W5dt6WPDn5/lH9UCSew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehkedgtdeiucetufdoteggodetrfdotf 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; Sun, 20 Oct 2024 18:01:17 -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 1/6] iio: imu: bmi270: Remove unused FREQUENCY / SCALE attributes Date: Sun, 20 Oct 2024 15:00:05 -0700 Message-ID: <20241020220011.212395-2-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" These attributes are not currently wired up, and will always return EINVAL. 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, 4 deletions(-) diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/= bmi270_core.c index aeda7c4228df..e598c642178f 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -121,8 +121,6 @@ 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_FREQUENCY), \ } =20 #define BMI270_ANG_VEL_CHANNEL(_axis) { \ @@ -130,8 +128,6 @@ 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_FREQUENCY), \ } =20 static const struct iio_chan_spec bmi270_channels[] =3D { --=20 2.47.0 From nobody Tue Nov 26 06:30:01 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 978FA198A22; Sun, 20 Oct 2024 22:01:22 +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=1729461684; cv=none; b=tiN1N8CcaYY0xECuNb9SPXJ8JJLeT6DhunN9UPCkifBSbpR5Mi0UfmDaAI4Lpg51f1aA+5QVSuZ8StW2bATYHWPvUv9kG3vOePZLJxfYY70zhK4N1NUf80kEtf7VXZVWwlGvDj058nDwO5qXdmOHepPbnk5ZUvAg6AqrR7+V7OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461684; c=relaxed/simple; bh=ZlwpZiCAJw5Iw6r9ePBt0CKhMBO9B6wzTj3Q1YlBAY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KU45ZNR4q2uHxQea4AhMms2r4hqDKqH4e4t7gI6HLV7IAXklfYBrF8h+vzCNftju1QosQirC6KLbIXj1ulenze3Nms/uLnt/VWdPDIhe3CGNO/PRP3ftfMsLaMcibHJB18sJ/97ZMLzVjJDCUn5VN5Isxzrl3ZHcECCZKmahXq0= 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=ESiEWVKg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Hf3f9vEB; 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="ESiEWVKg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Hf3f9vEB" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id 5FD5C1140094; Sun, 20 Oct 2024 18:01:21 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Sun, 20 Oct 2024 18:01:21 -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=1729461681; x= 1729548081; bh=ZdNJ9xpyp21teAdPDPuiOkx1UKnmhOQ6+MEcMCqD6n4=; b=E SiEWVKg63KQZMLsUYRbP1TLVALj2jSTOOTXjqWvt4kwiHHxi0DShJdzOoNzjZRqj hL21uxvnAO07p060/7DhrQMaZF14xrMnFVjqNARmBA/3UtvLWRrzMRVXCQbhZsRE P3LW9JiKC7D9n86QcCBwcLro6yHrlXjq80Ueob3OzQmMStrHlOQOMj52r31pbwA8 Q6+UdT+/Z7XNSPTAOTscvsqxdcG6+4Hr2Nuyrvkb0qxMn+zlX3Yo23ccdVavrZ29 8H90FptSeftRC9GEbcX7tSMQhckmsjQCbcROFvJdHFdwlja6RVVsRuoH5sia4fRR Iq4Ki8w3bqn5NqmwnC06A== 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=1729461681; x= 1729548081; bh=ZdNJ9xpyp21teAdPDPuiOkx1UKnmhOQ6+MEcMCqD6n4=; b=H f3f9vEBPomiOcQbC45d86U7jnNEGJIUn1SI+MRRFV9Xpd1iBVhPu0jiFEFMYQ46w HEi02uUQQU74HnDwFI8wcW4MPLndaUW30OthWAXrr5WZSo9gUOG5t9Oe6HQRJZRE bEd1374lIq0RWPKH0m2lWfxBOf7Y7KllD/Ljy6jQv8vTBJpFsVJquqbRa3pjSPzS Oxb8XD7JF7z1gR0iSHZtQugpsZPd9KiAW/X1gzGn4U9MBZbeGSgPDcTgX0LIT9gp 90QugDhtGZD8u4vtBv5kklTXM8Kley7SOL/jhqIK9QGj0Ws7K1Cy+JKUPB0TBuai JET7SGZgyT22S/12UHmRA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehkedgtdeiucetufdoteggodetrfdotf 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; Sun, 20 Oct 2024 18:01:19 -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 2/6] iio: imu: bmi270: Provide chip info as configuration structure Date: Sun, 20 Oct 2024 15:00:06 -0700 Message-ID: <20241020220011.212395-3-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" Prepare the bmi270 driver to support similar devices like the bmi260. Signed-off-by: Justin Weiss --- drivers/iio/imu/bmi270/bmi270.h | 11 ++++++++++- 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, 40 insertions(+), 11 deletions(-) diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi27= 0.h index 8ac20ad7ee94..93e5f387607b 100644 --- a/drivers/iio/imu/bmi270/bmi270.h +++ b/drivers/iio/imu/bmi270/bmi270.h @@ -10,10 +10,19 @@ struct device; struct bmi270_data { struct device *dev; struct regmap *regmap; + const struct bmi270_chip_info *chip_info; +}; + +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 e598c642178f..5f08d786fa21 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -66,6 +66,13 @@ enum bmi270_scan { BMI270_SCAN_GYRO_Z, }; =20 +const struct bmi270_chip_info bmi270_chip_info =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) { @@ -150,7 +157,7 @@ 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) + if (chip_id !=3D bmi270_device->chip_info->chip_id) dev_info(dev, "Unknown chip id 0x%x", chip_id); =20 return 0; @@ -183,7 +190,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 @@ -270,7 +278,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; @@ -283,6 +292,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) @@ -290,7 +300,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 d59161f23f9a..394f27996059 100644 --- a/drivers/iio/imu/bmi270/bmi270_i2c.c +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c @@ -17,22 +17,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 }, { } }; =20 static const struct of_device_id bmi270_of_match[] =3D { - { .compatible =3D "bosch,bmi270" }, + { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info }, { } }; =20 diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/b= mi270_spi.c index b53784d4a1f4..7c2062c660d9 100644 --- a/drivers/iio/imu/bmi270/bmi270_spi.c +++ b/drivers/iio/imu/bmi270/bmi270_spi.c @@ -49,6 +49,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); @@ -56,16 +61,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 }, { } }; =20 static const struct of_device_id bmi270_of_match[] =3D { - { .compatible =3D "bosch,bmi270" }, + { .compatible =3D "bosch,bmi270", .data =3D &bmi270_chip_info }, { } }; =20 --=20 2.47.0 From nobody Tue Nov 26 06:30:01 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 0DAED1991B4; Sun, 20 Oct 2024 22:01:24 +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=1729461687; cv=none; b=EWa9Xhx0kCNNPlJ0prJ+UbBERmfvhp6PU92TRjVQn3P07OD7sp0XhWYjuLiqxYW/p+utvsTnxVi7KZ65XrLDP8YmjvOrK5l0nbu5FUscmXDVoaW/X3oHxiRrw06llwBuFvs8JZzdkEshQ9UrPLk/7c1qtlWxEd443erMQnE3iwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461687; c=relaxed/simple; bh=D/mLWFaivoTEaaqHLS6D9+BJQdYAQkXFI5nP6YYK7qE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WUEAQksAi4dMVNypZ5wVAO0nRt/89faXq2sJwI/ct2bMVA801V7MPwyahTf5E4tQtePrWK5u1hbvdgQBv2EpXYBkbukJqxR17589lLxoJnTzJXC3j0Q+GXHowmzuutWfGCRc4SZ4Od4Zh9FsRMBKcwoRx9vJEhhWdVKWziDkWeo= 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=OvNeu+IR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ELxUaHRI; 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="OvNeu+IR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ELxUaHRI" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.stl.internal (Postfix) with ESMTP id DB60C1140095; Sun, 20 Oct 2024 18:01:23 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Sun, 20 Oct 2024 18:01:24 -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=1729461683; x= 1729548083; bh=YMbbini+gX5z84v+iufpqhX1D/K7N7C3mTtmdziwyzw=; b=O vNeu+IR89ep0l/rR/wIg+gFluXmBjEkPiK4KTCEGXG7IpnJeMZ5fMx25lmFUGjLY RrVBaQEmHqKWBAAsUHD6Q6LdHG9wG3bbKj/bDVoLNOqpW9ZhuGySTRCk8CIbFvhm +ZqVR8m7a2TEdK5BhT/MsoGLjaMBt/gRevi32ynE6OIisCwFRov4B56uixqCQ6pK 4lMeT9IEbDFbnTY6QdUs5hOIcO/ImLahING/v1TyeciqbbdYj9XYj26R2gDZxtZI HfE8cBsTURAouV9bKlWh0GrnPP7ckR8SjAZEc16lg1cpQ+Aqo/QvFsJqu1Eh/TKg Gwq5rgdVSFbua1wRxGTXA== 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=1729461683; x= 1729548083; bh=YMbbini+gX5z84v+iufpqhX1D/K7N7C3mTtmdziwyzw=; b=E LxUaHRISayj9Lu9iHQoD8XwJTjrdfS1IgrmK+l3Xmykdh3c+9p6tZQ4wPgEnyooX c2DV4XuibUB1L1ilicyHak4jeecVk3KnZ8sUb9zcFfE9Pf43B6hZ4JWu8o+IaSHl /aK2BRQ/c35zfwRnOdAVi5XThDdMr7HWKioqE0gdr/Z5+3afp/JyK6I7B47nQ1DV foftmOJFfAz8pazUZKR6CNa/5nS71bigFYK3BaHg9lR6sxX/K90/lszT+CZOtw5A 7ciOtStW3CoYTfur8tXn9licRaOrqd6Mb5Ovnyb+jFKqtFkfYNGgZF7oohyb/6HT dRL7IEEBDrL29tz5s4xZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehkedgtdeiucetufdoteggodetrfdotf 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; Sun, 20 Oct 2024 18:01:22 -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 3/6] dt-bindings: iio: imu: bmi270: Add Bosch BMI260 Date: Sun, 20 Oct 2024 15:00:07 -0700 Message-ID: <20241020220011.212395-4-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" Add compatible ID for Bosch BMI260 to BMI270 documentation. Signed-off-by: Justin Weiss --- 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 Tue Nov 26 06:30:01 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 3D09E19923A; Sun, 20 Oct 2024 22:01:27 +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=1729461689; cv=none; b=DTO9G5IEtL4/ReEnaPBXmO6hptrUAujFCWSTlyHDxduzufoKJ/Z4hsRNsUqGoN4A3DrsPTqRgr3OD91arXXmKeefoXcwcyzkVD7+w+J3ilYU22jjDb/vdGyamnijgUf2tARVu2izEvkyYPCqdJce1WcKVUXh/8r8Y7QbULKcCKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461689; c=relaxed/simple; bh=DZ2bx7zJ032LMc6mL9mqFRpePhr64LSdUHo6or2i7tY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RuvMs1g6g9+h25mbMdX7OcqYXllqBnZ5tWzzKcwaHoYNMVB5Q5F3mThYZj3exQLgwUtK9zhX6hAmGF03+TI9e6zGMm2S73M4D06x0VEcCv9sZbQiKWnHF/Trfkgs+0CQFHzxvJTY5Cxe6LXWiMaFf6bbbFD2uJAIlm3XqBT1QD0= 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=dv+yqjL4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oIg+pGtk; 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="dv+yqjL4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oIg+pGtk" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 2D84111400A6; Sun, 20 Oct 2024 18:01:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Sun, 20 Oct 2024 18:01:26 -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=1729461686; x= 1729548086; bh=iVqj9XZD2JsvGg/ibY285jQCG1X6rPsjya8e6dV1l68=; b=d v+yqjL4Gq4Y/o1fYSKAWz5PWmkA+paZaoFJgCB2P4HHuHIx3szZIR84dZ4HNbdYO O4pMoL03mOTni+MUUqGWPGb9kfJ897ZBuAhCwu3zEoLRho7vjUwuCyrlt/pYluOX +ABVj8JMs/y+R+LA8rPjj9aiHHSNhwQ7rENFkyJoVt3tNl3gzCTNI9/CEMRZAea8 gOtDsx6AtgYdQZd/s97YVmmLJyxovxQ/VHbgdhuCY2FmmQzIpnsx2QyNYe/dXq/4 mlZ6ue/iYclw6wqawCGTaK5cJw1y25zxZkjjhkrm7Zqc0G5IBXxEg3skfZK8VdAl qqHXQY4J1EWtFaEkA6BXw== 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=1729461686; x= 1729548086; bh=iVqj9XZD2JsvGg/ibY285jQCG1X6rPsjya8e6dV1l68=; b=o Ig+pGtkiSRKFutg+2JSLNyD4gacmI8A3XY31Ph7iw4cA8bPWJs+6YaxvR7ADr2GB 2lzV0pU8ZnsOtKFWBxBvaJqCaLJKDD88YRn7WcLcYY2ab2vpFtIE4GojMkC7bnpj g2s4xIY+UuUmFs4eqqM1Uqg/I/g8XQLB395McpkP+0J0sv3417MeevmpYohB8/f5 MY86vRQ9d+Gl+XizSt94d8fa+QO8hOyPKmR3lrDIjKx11JFRv3WHzdhdAPoJtN70 xRKDPQv3ydihyLNd38urNoDjcQCabxMm42+uBSk6+sJmVJtNOuCnxYhGfhPFllIN QQifNSRUp1MtETN7w+qBA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehkedgtdeiucetufdoteggodetrfdotf 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; Sun, 20 Oct 2024 18:01:24 -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 4/6] iio: imu: bmi270: Add support for BMI260 Date: Sun, 20 Oct 2024 15:00:08 -0700 Message-ID: <20241020220011.212395-5-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" 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 | 28 +++++++++++++++++++++++++++- drivers/iio/imu/bmi270/bmi270_i2c.c | 13 +++++++++++++ drivers/iio/imu/bmi270/bmi270_spi.c | 8 ++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi27= 0.h index 93e5f387607b..d8f6d7cf47fc 100644 --- a/drivers/iio/imu/bmi270/bmi270.h +++ b/drivers/iio/imu/bmi270/bmi270.h @@ -20,6 +20,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 5f08d786fa21..24e45d6f0706 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -11,6 +11,11 @@ #include "bmi270.h" =20 #define BMI270_CHIP_ID_REG 0x00 + +/* Used 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 @@ -55,6 +60,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 { @@ -66,6 +72,13 @@ enum bmi270_scan { BMI270_SCAN_GYRO_Z, }; =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, @@ -157,8 +170,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..3d0d8f3e8b63 100644 --- a/drivers/iio/imu/bmi270/bmi270_i2c.c +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c @@ -32,11 +32,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)&bmi260_chip_info }, { "bmi270", (kernel_ulong_t)&bmi270_chip_info }, { } }; =20 +static const struct acpi_device_id bmi270_acpi_match[] =3D { + /* OrangePi NEO */ + { "BMI0260", (kernel_ulong_t)&bmi260_chip_info }, + /* GPD Win Mini, Aya Neo AIR Pro, OXP Mini Pro, etc. */ + { "BMI0160", (kernel_ulong_t)&bmi260_chip_info }, + /* GPD Win Max 2 */ + { "10EC5280", (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 +56,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..7f42ed74023b 100644 --- a/drivers/iio/imu/bmi270/bmi270_spi.c +++ b/drivers/iio/imu/bmi270/bmi270_spi.c @@ -65,11 +65,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)&bmi260_chip_info}, { "bmi270", (kernel_ulong_t)&bmi270_chip_info }, { } }; =20 +static const struct acpi_device_id bmi270_acpi_match[] =3D { + { "BOSC0260", (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 }, { } }; @@ -77,6 +84,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 06:30:01 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 From nobody Tue Nov 26 06:30:01 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 D317E199E93; Sun, 20 Oct 2024 22:01:31 +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=1729461694; cv=none; b=rJWr7HjgjQ/reqZcniVqJyurENHKRpsd2jKdSxJmRBdPBarMP9/cny/ZTQbhevgyEIOVScL77WT4HCTqRfwXuztjYn7FcrP+6lREvzgvBWehl3DinsndpLw6pmxFGfxH47NyITX6UKplTpu61mGjapva08fDFH8C//H7YjQEbes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729461694; c=relaxed/simple; bh=vF8PoZLcemoW7ocQiITA/5LyeyPnNKnsKzS6bvQdmFY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U6yDxtOp/rXV1GULMoC0eRdVOgEF9z5K/9puoNk8BpgW+qlrPnBlhA2XtOI8NvucbuEF+bdFA/QDKLlSdafdxQaRkUO1F45XGRrfl8IsaXGZg/cUsHp1lL8vWBPpjsyDAgy2EaiC5ixSzJRJwcwYibuFPBol1x520vqeJnYDhI0= 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=DGdEmU5T; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=J6+OP/Rt; 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="DGdEmU5T"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="J6+OP/Rt" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.stl.internal (Postfix) with ESMTP id E4B3311400A8; Sun, 20 Oct 2024 18:01:30 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Sun, 20 Oct 2024 18:01: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=fm2; t=1729461690; x= 1729548090; bh=p4bxuKiyW+ioXAqeVJXHXrTilmJtksg0SLU1JDE3quM=; b=D GdEmU5Tj0RjUAmXvcX3BVjQG58R53p3LDGkT/jD1XLehUSQo2d2W6jSbMRYJjhmN aPXIegFFyzpEG+QJQLJFK8Niw+LamE7XXR18K2RZVp+ZINURQZMwaScCQ9cnDUxN 8YbZOE3Q/CZcXjaJifhxhZXCjZ30aH3jkXt22uE+vrh8puHHWaCggk/MLmP0DaW0 gGV8/CGAKlDJJO0kDNaqf5PeZIWic4HWluxf08CKaifI0xNXeKFWzdkm8Y2bAXh/ Wr96+Yafm3kbafK7EywXjsMmBz3y8QMuOTU7WQarvv3/FeqHIp/3mGM3H5c5qxup y8RV+geNmDBSO8oISYX4Q== 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=1729461690; x= 1729548090; bh=p4bxuKiyW+ioXAqeVJXHXrTilmJtksg0SLU1JDE3quM=; b=J 6+OP/RtPXYvhM3CZ1oUeOSXEptqoZpS9TznVbzwTti4lCfJYGVdz5pMf7cEgi6W8 vODq2gYau+sg3msTgjh68OVOf9Zj/tz6Hp2SyXddnznPnewzMZGJU68HAcCdSQsx 7Udq6zgyqzVR00qy7YaXJDDrEJht4ncjbvKD/tCcwBqGe+Fv1Cc2/ynp6SVwGPIy XOyY+5hBJq1fGf6+X86WSgcWAvvCvgK4pgYSnOSPm0GzDHc2NXi2J5VqS+DTcxB1 IP+sktGh9IP+Kn61qqs/MTBHhBFoLuxKlhmGC0TpVk5uDq5cYFH3G4Srpyufcg9C 7fwsTZJsBrhUO0A0jl23w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehkedgtdeiucetufdoteggodetrfdotf 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; Sun, 20 Oct 2024 18:01: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 v3 6/6] iio: imu: bmi270: Add scale and sampling frequency to BMI270 IMU Date: Sun, 20 Oct 2024 15:00:10 -0700 Message-ID: <20241020220011.212395-7-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" 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 5b643afae9f7..3e1e698c4af0 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 @@ -38,6 +39,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 @@ -46,6 +50,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 @@ -99,6 +106,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; @@ -161,6 +427,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; } @@ -168,6 +496,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) { \ @@ -175,6 +505,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', \ @@ -189,6 +524,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