From nobody Sat Nov 30 00:39:21 2024 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2087.outbound.protection.outlook.com [40.107.247.87]) (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 9529B1D7E35; Fri, 13 Sep 2024 10:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726221695; cv=fail; b=Qx/kWS+ASvnFq9Fk56aYw8LkfxD19gmeZQE1WAyuYVJBODkGucZSxP8NBJDWf9J7LtlZ0zvEiEWhVvE8rJ81jQcGsamHdTo1p395QIQcLsFlRsg7viE0qeuYog6mGQ4+3Qx62hPzx/fqwcz5eEP5guRWn9vmkm7JtP755aFgQ68= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726221695; c=relaxed/simple; bh=Ssd/8UAGu7KN3UPkq4A0vpHmzXq9pQBl/b8vBAU57uQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fFUktNGqyhdP93ST7u1EO57BUoKcvtWFSA82VzLqBGdqrEou862GzugmCyNweDHrSV0gOtMskrqdTP0fcvxg6Lf9TDOJW9lEQmYrbrRzUlLzQbpkJHWCGQ133Lcnvspg2A6/Yj00bmcCuJkhycZYrLtyfOvZ5FmoqIbHTxWOTtc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=de.bosch.com; spf=pass smtp.mailfrom=de.bosch.com; dkim=pass (2048-bit key) header.d=de.bosch.com header.i=@de.bosch.com header.b=extuTXXq; arc=fail smtp.client-ip=40.107.247.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=de.bosch.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=de.bosch.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=de.bosch.com header.i=@de.bosch.com header.b="extuTXXq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cb2JbsWbuJe1bUvXFsNq34u5Z/ZXk9hjQ+26SLHvpueuzBa/bugE3G6F4Nc8k0KUp5MlQBvJau8lRl/H2XFC8xu39uNSjP9oABZvhLX3UrF88wM8RKVTiWE67ro1f/y18B2I116Re07tbd5scO1KIogNpAZ7ujzfoF4QWwusc3W/7wKriKaNE3g1yxEJBAupZwTycEE0R82MoIhFyWV5qUbVByrzoW12pMIfngiZmL7350kYSazBL6zw8LsGCgIYQijbXBtNIZp3sbRmeEw5anbTUWOUO5V1YZLEiIgP7b7A2zD74tlG8cYbR9kQcl+LWwwuRk6/V3veFfz5I6jlTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1WEXVP/5HzeyB1dvLgThCvPsnkBRL1Wtx1l62Qj1A0c=; b=fUYZ/wNArZw5sF7bJWBeEh9IwziMDE+LPY7bvlDLd1/ZvHiW4uZQ4p9YicOEZlKYCq616Twx6qe93+iGLIdPMT+r//8e+cb63bn56sZLSoGzPdFK2CTxcEJyiRMmjIOAgzjcy2sVpBQz64oILg0hb+FwzX38qt0ImAVVkE4M0N78DRABZiD5dp+vEvuo0eYvsjHs5Cs4gzy13/HHjWdK2chWuipRboSzJozFEEasJZn2baQuYiWZy0yDUV7K9AJDcBty6bwV7/MHZB7Tx0jZXc9VBY1nqdIOjNUJbjXvn0deVtBdj6bUdti+FbxHCSJDRnc+keDDMFrgeXVXkRXxqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 139.15.153.205) smtp.rcpttodomain=kernel.org smtp.mailfrom=de.bosch.com; dmarc=pass (p=reject sp=none pct=100) action=none header.from=de.bosch.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=de.bosch.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1WEXVP/5HzeyB1dvLgThCvPsnkBRL1Wtx1l62Qj1A0c=; b=extuTXXqHeAI1VEAgpJlTKPCvIBYsxN2SwI4kcDJiI43JdMGJ5imWHeFaNJo3UN5OOuSZ761r3qlX+aFZMPCjdoB8UEODUHoOaTsnYrJ5HE80bEGBkJLgYtLmwzAwd03vD3U6gNKVOMi+80z8kxbVCCHIIURVE7EjbdSGagd7xJfjC9s3ho60ZeDYJjAUdMfvjrA7t3o6JQBKudBvg3IdN32008vFfDQt5901utEfhwcMeqGJg9tH4XW/hWQ7ckJT3kdHUrYjfipA15kMIMlrDVpeDIGGxzF4JD2OQYWs2HYiJ9urcm+eEkC1j75EGDLMpSE9HxpwGFIicB3Wz2kdw== Received: from DU7PR01CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:10:50f::8) by AM7PR10MB3272.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:105::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.17; Fri, 13 Sep 2024 10:01:28 +0000 Received: from DB1PEPF00050A00.eurprd03.prod.outlook.com (2603:10a6:10:50f:cafe::31) by DU7PR01CA0013.outlook.office365.com (2603:10a6:10:50f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.27 via Frontend Transport; Fri, 13 Sep 2024 10:01:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 139.15.153.205) smtp.mailfrom=de.bosch.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=de.bosch.com; Received-SPF: Pass (protection.outlook.com: domain of de.bosch.com designates 139.15.153.205 as permitted sender) receiver=protection.outlook.com; client-ip=139.15.153.205; helo=eop.bosch-org.com; pr=C Received: from eop.bosch-org.com (139.15.153.205) by DB1PEPF00050A00.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 13 Sep 2024 10:01:27 +0000 Received: from FE-EXCAS2000.de.bosch.com (10.139.217.199) by eop.bosch-org.com (139.15.153.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 13 Sep 2024 12:01:11 +0200 Received: from LR-C-0008DVM.rt.de.bosch.com (10.139.217.196) by FE-EXCAS2000.de.bosch.com (10.139.217.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 13 Sep 2024 12:01:04 +0200 From: To: , , , , , , , , , , , , , Subject: [PATCH v7 1/2] dt-bindings: iio: imu: smi240: add Bosch smi240 Date: Fri, 13 Sep 2024 12:00:10 +0200 Message-ID: <20240913100011.4618-2-Jianping.Shen@de.bosch.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240913100011.4618-1-Jianping.Shen@de.bosch.com> References: <20240913100011.4618-1-Jianping.Shen@de.bosch.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF00050A00:EE_|AM7PR10MB3272:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a39a836-cce0-4eff-24f5-08dcd3db08ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026|7416014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?B?UEltK2hjUFFaOVU4elBhUmE3OEs2WWJsMXVRdUFnZmVpZjNMSGducFpURlNi?= =?utf-8?B?Z1l4TFBnVEZjQWhMNm9ERFNQc2pnbllxM2NlV0U3UlhZdFpCQWluUU1XZnRN?= =?utf-8?B?Vis3dWpaVmcrSzM5emVwSExXdUtXNEYxWmluNmgvVXJwNWdtWGlyV1ZnRFNl?= =?utf-8?B?Y2taTlZ0L3NtZ3BRTm1hdWNSRzFFeGpPT1c2OHQwYWxHekV3K0JlQzA0T1BP?= =?utf-8?B?anpwVzZhK2paM0VRdjZDSFZ1bW9YSUk2SThpMXh4M2tXcGM1VldQbzRlS0dh?= =?utf-8?B?WXBOenk2MVp1Wk9qcDRsUUYzSGloaThiN2xyVmxaSnNtbFphRkNycFdXa09S?= =?utf-8?B?aEIxdlZkTndScjlobm53bGpGRjF6dWNET0JhTmNHdFlIQlM0UkNLYnErT3g0?= =?utf-8?B?eVgxTnpuWkFFQ28vcmlydnNHdnBSRWlvSTVMalVMSlBPVW5hLzlBVEtuamlz?= =?utf-8?B?K1djVjdTVVBYNWtwVFh0NXNqb0JsQ2xWbzRmOGUrQ3hCU1Z1U1BEZnVSSjI1?= =?utf-8?B?UGtINUsxckJnUDBWUGpRWjJwYTg2TjJ0TmoyZWtjNDNqUnZpb2NQWmY0RTZX?= =?utf-8?B?OGduNFE5RmlyeDJFNXZOUzJjSFFibjhka2o2WXpxbFkyenY1SDVBMlY2NjBh?= =?utf-8?B?bnBWYmNuUkx5eEROWGhhb1BqZTF6QStGUkR6OWRSb0Q0b2V1U25aVEZGS3Vp?= =?utf-8?B?TUlRQ241NmZCZzB3V1BKeGhub3R5UUlNMFRJZmJLS0JFNlgxZkZvdkhHYVFr?= =?utf-8?B?Q3hqUmdCd3o2Q0UrQzRE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dzZzBOSlN6VWZyaXJIczdGTDU0VlVjRmdFRUIxWEtDODRnYmVTQnVjZGps?= =?utf-8?B?Z3p1cTcrMDVCU2ZDZTVZNTRhUlJEWmZkMlNVRzNjVTVtSnF2QXZiMFJhcmE0?= =?utf-8?B?bWNULzVGendXb0lDOHZKNy9vS2NlRGVTejV3cG40SkgyRVBpVzlHZ3pkUDln?= =?utf-8?B?TGloMW9QaFhvRnNINTE4WWpsWXZsRnFIc3hjSmtsbHBjQWc9PQ==?= X-Forefront-Antispam-Report: CIP:139.15.153.205;CTRY:DE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:eop.bosch-org.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: de.bosch.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2024 10:01:27.9953 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a39a836-cce0-4eff-24f5-08dcd3db08ee X-MS-Exchange-CrossTenant-Id: 0ae51e19-07c8-4e4b-bb6d-648ee58410f4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0ae51e19-07c8-4e4b-bb6d-648ee58410f4;Ip=[139.15.153.205];Helo=[eop.bosch-org.com] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF00050A00.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR10MB3272 From: Shen Jianping add devicetree binding for Bosch imu smi240. The smi240 is a combined three axis angular rate and three axis acceleration sensor module. * The smi240 requires VDD and VDDIO * Provides only spi interface. Reviewed-by: Rob Herring (Arm) Reviewed-by: Krzysztof Kozlowski Reviewed-by: Conor Dooley Signed-off-by: Shen Jianping --- .../bindings/iio/imu/bosch,smi240.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,smi240.= yaml diff --git a/Documentation/devicetree/bindings/iio/imu/bosch,smi240.yaml b/= Documentation/devicetree/bindings/iio/imu/bosch,smi240.yaml new file mode 100644 index 00000000000..58f1411728f --- /dev/null +++ b/Documentation/devicetree/bindings/iio/imu/bosch,smi240.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/bosch,smi240.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bosch smi240 imu + +maintainers: + - Jianping Shen + +description: + Inertial Measurement Unit with Accelerometer and Gyroscope + with a measurement range of +/-300=C2=B0/s and up to 16g. + https://www.bosch-semiconductors.com/mems-sensors/highly-automated-drivi= ng/smi240/ + +properties: + compatible: + const: bosch,smi240 + + reg: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + +required: + - compatible + - reg + - vdd-supply + - vddio-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + imu@0 { + compatible =3D "bosch,smi240"; + reg =3D <0>; + vdd-supply =3D <&vdd>; + vddio-supply =3D <&vddio>; + spi-max-frequency =3D <10000000>; + }; + }; --=20 2.34.1 From nobody Sat Nov 30 00:39:21 2024 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2077.outbound.protection.outlook.com [40.107.247.77]) (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 94AE01BD4FF; Fri, 13 Sep 2024 10:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726221695; cv=fail; b=gq412iKIjuv9VQpJkhb73oRCzJx4dpR/n9KZ1xulrGA13z4RuevQg9RUVqFOQ3bNxXZfj6WaUhmvwmoHNoSn2BR2EXw4+E4pucfXWp/A7wlMZThXqTY3fY5kacOeS+pR3/vEUjw3C7liEHVcxn0kD/PjrBl5THRm+U+RTUIX1BI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726221695; c=relaxed/simple; bh=d3noflPkTWV+URHtL3yu7fQvUHTtVzFcG+IahwEneMk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vARijJN78ZlkQ4BiD/dCbRH6FnMYhZazIqV4DT2OkJjw1ZuC/YPB5+uHumi86CWK322u20aC7c4A9sagMHoLRK+1MI9rp0P3ZqQZl/xeBaCsm9p6NdV9zhv5uHs6Ca66tcd3akwDcuPxi5+bKdKlUfGMvdBEamieoeEsW8a/bds= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=de.bosch.com; spf=pass smtp.mailfrom=de.bosch.com; dkim=pass (2048-bit key) header.d=de.bosch.com header.i=@de.bosch.com header.b=lH4NSKqe; arc=fail smtp.client-ip=40.107.247.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=de.bosch.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=de.bosch.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=de.bosch.com header.i=@de.bosch.com header.b="lH4NSKqe" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZkDGQbsHJL8UNTzCr0fAc3POlshjv45tCLeRzn9WTY4w8OKcf+kea4zCb2NwSgwTJ+DodxtbBokMdQL4yEx39wqK/Wr8zaAR3DUuPBX/NCu0FZEBy4f/4gn2XdVahfR1jXkfMD0rskr+wQOx1SOSnPuhp5tbFyZtZ0vHVuzCjpGbPwYzkypNUEM6g2VuCKdJYJQGwvS6CTYb79gRgikqpAlvPbYn4uxZyP0HEZ6vkK7xc7GE4uR4niQXbiGFdV1CVjZCE20zcOM2X7vnkFKxSvtdKdQzUEtC+oSCmZpDcY+hUHG4ah2YGF8V2g2vc2R8tQWhc7c1HqQ64yP03Tz06A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Y7kFngeJpom63BQj3ZrM9PKPSI4j2J8ATuYEcTeRWY8=; b=rAvFra3e97/vJ2ate4+g7952l3fMFkGk77xFWbvVv/lP81wldY99lKdjnWDNIeRaP2wy3GNc8uZ3cBiPuj49lcBShczKpSWtzZG1U97k5F6LGJy6BtiPUED0y45kZFeztmoel6ds+1lMYMXj04iUpDD9LTvgF0Zom4+/vlABJlgeNrNN5A6JqiquuLbU+icz22qFXKYdV3DCflL5aMc6SW64VXcWSbtnMAnLNqhyOosMJZ2/bLcwmZBoaMw7bvHLX9c7koDA/uJ4WMgZb8aIdisjoJlvJNdFHQKWG9HugRl7wfs4FSBgp8EtY/SBsxUCTYauq4FWwJUw47a7UAjRAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 139.15.153.205) smtp.rcpttodomain=kernel.org smtp.mailfrom=de.bosch.com; dmarc=pass (p=reject sp=none pct=100) action=none header.from=de.bosch.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=de.bosch.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Y7kFngeJpom63BQj3ZrM9PKPSI4j2J8ATuYEcTeRWY8=; b=lH4NSKqeMbOGIxEN+Q/JPOtNEVJenanrRRJcwb9czUDpjYY9hOnOM9Nr7AHK0uj6/aI1o9RbtL6GYmND/DHXB1sjdfH5HlypSBDZ8G52fmfagMY9gRd0ZvTkHXpxr4mTqHY3uetU/ulzg4ZJjtTB/2yqGrXjmXLDJNHBuM5JzICDh8R0griENLztjonBafSRfnsrSkT/KYUndX5pv+kX5QUnWleso5Oc5M/tRyO0ulyiDJVlmPPshcyJuMxJpv3BL2LqlnheBRSHeZhOjxWMAW0lnRdXyH7a0w8Qd0/ZnjtJsz8W4hBv3kmjem+LZL6u/MKOlW97DVuAGCjtgFNg9A== Received: from DU7PR01CA0021.eurprd01.prod.exchangelabs.com (2603:10a6:10:50f::9) by DU0PR10MB6226.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:3ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.19; Fri, 13 Sep 2024 10:01:26 +0000 Received: from DB1PEPF00050A00.eurprd03.prod.outlook.com (2603:10a6:10:50f:cafe::21) by DU7PR01CA0021.outlook.office365.com (2603:10a6:10:50f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.27 via Frontend Transport; Fri, 13 Sep 2024 10:01:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 139.15.153.205) smtp.mailfrom=de.bosch.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=de.bosch.com; Received-SPF: Pass (protection.outlook.com: domain of de.bosch.com designates 139.15.153.205 as permitted sender) receiver=protection.outlook.com; client-ip=139.15.153.205; helo=eop.bosch-org.com; pr=C Received: from eop.bosch-org.com (139.15.153.205) by DB1PEPF00050A00.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 13 Sep 2024 10:01:25 +0000 Received: from FE-EXCAS2000.de.bosch.com (10.139.217.199) by eop.bosch-org.com (139.15.153.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 13 Sep 2024 12:01:10 +0200 Received: from LR-C-0008DVM.rt.de.bosch.com (10.139.217.196) by FE-EXCAS2000.de.bosch.com (10.139.217.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 13 Sep 2024 12:01:04 +0200 From: To: , , , , , , , , , , , , , Subject: [PATCH v7 2/2] iio: imu: smi240: add driver Date: Fri, 13 Sep 2024 12:00:11 +0200 Message-ID: <20240913100011.4618-3-Jianping.Shen@de.bosch.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240913100011.4618-1-Jianping.Shen@de.bosch.com> References: <20240913100011.4618-1-Jianping.Shen@de.bosch.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF00050A00:EE_|DU0PR10MB6226:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c48342a-5691-43a5-a992-08dcd3db07ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|36860700013|82310400026|376014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?B?WkhJL29Nd1d3bjJhb3gzcERvYkJER0JMcVhoeEJBM0lLTUliV2xmWkxrc2NC?= =?utf-8?B?SzFPbWNMeFV6eWRRRnMyMVNnbnFGV3BjV2R6TlkrYmR1ZFlMdzJQQWJxRm55?= =?utf-8?B?SG1pRkdicENwem1DczlGYlBTRkFkS0FwbkRDR2pKOFF2QzlVUmZiOTlHMTdh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Q0Z5L1I0Z0VsRVZpTDRxWkNVS2g5VzNtbUNTWktY?= =?utf-8?B?K3hmVmlOWG9BPT0=?= X-Forefront-Antispam-Report: CIP:139.15.153.205;CTRY:DE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:eop.bosch-org.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(36860700013)(82310400026)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: de.bosch.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2024 10:01:25.9016 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4c48342a-5691-43a5-a992-08dcd3db07ae X-MS-Exchange-CrossTenant-Id: 0ae51e19-07c8-4e4b-bb6d-648ee58410f4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0ae51e19-07c8-4e4b-bb6d-648ee58410f4;Ip=[139.15.153.205];Helo=[eop.bosch-org.com] X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF00050A00.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR10MB6226 From: Shen Jianping add the iio driver for bosch imu smi240. The smi240 is a combined three axis angular rate and three axis acceleration sensor module with a measurement range of +/-300=C2=B0/s and up to 16g. A synchronous acc and gyro sampling can be triggered by setting the capture bit in spi read command. Implemented features: * raw data access for each axis through sysfs * tiggered buffer for continuous sampling * synchronous acc and gyro data from tiggered buffer Signed-off-by: Shen Jianping --- drivers/iio/imu/Kconfig | 14 + drivers/iio/imu/Makefile | 2 + drivers/iio/imu/smi240.c | 611 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 627 insertions(+) create mode 100644 drivers/iio/imu/smi240.c diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig index 52a155ff325..59d7f3cf8f0 100644 --- a/drivers/iio/imu/Kconfig +++ b/drivers/iio/imu/Kconfig @@ -96,6 +96,20 @@ config KMX61 =20 source "drivers/iio/imu/inv_icm42600/Kconfig" source "drivers/iio/imu/inv_mpu6050/Kconfig" + +config SMI240 + tristate "Bosch Sensor SMI240 Inertial Measurement Unit" + depends on SPI + select REGMAP_SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + If you say yes here you get support for SMI240 IMU on SPI with + accelerometer and gyroscope. + + This driver can also be built as a module. If so, the module will be + called smi240. + source "drivers/iio/imu/st_lsm6dsx/Kconfig" source "drivers/iio/imu/st_lsm9ds0/Kconfig" =20 diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile index 7e2d7d5c3b7..ca9c4db7725 100644 --- a/drivers/iio/imu/Makefile +++ b/drivers/iio/imu/Makefile @@ -27,5 +27,7 @@ obj-y +=3D inv_mpu6050/ =20 obj-$(CONFIG_KMX61) +=3D kmx61.o =20 +obj-$(CONFIG_SMI240) +=3D smi240.o + obj-y +=3D st_lsm6dsx/ obj-y +=3D st_lsm9ds0/ diff --git a/drivers/iio/imu/smi240.c b/drivers/iio/imu/smi240.c new file mode 100644 index 00000000000..892e14f3f60 --- /dev/null +++ b/drivers/iio/imu/smi240.c @@ -0,0 +1,611 @@ +// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 +/* + * Copyright (c) 2024 Robert Bosch GmbH. + */ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define SMI240_CHIP_ID 0x0024 + +#define SMI240_SOFT_CONFIG_EOC_MASK BIT_MASK(0) +#define SMI240_SOFT_CONFIG_GYR_BW_MASK BIT_MASK(1) +#define SMI240_SOFT_CONFIG_ACC_BW_MASK BIT_MASK(2) +#define SMI240_SOFT_CONFIG_BITE_AUTO_MASK BIT_MASK(3) +#define SMI240_SOFT_CONFIG_BITE_REP_MASK GENMASK(6, 4) + +#define SMI240_CHIP_ID_REG 0x00 +#define SMI240_SOFT_CONFIG_REG 0x0A +#define SMI240_TEMP_CUR_REG 0x10 +#define SMI240_ACCEL_X_CUR_REG 0x11 +#define SMI240_GYRO_X_CUR_REG 0x14 +#define SMI240_DATA_CAP_FIRST_REG 0x17 +#define SMI240_CMD_REG 0x2F + +#define SMI240_SOFT_RESET_CMD 0xB6 + +#define SMI240_BITE_SEQUENCE_DELAY_US 140000 +#define SMI240_FILTER_FLUSH_DELAY_US 60000 +#define SMI240_DIGITAL_STARTUP_DELAY_US 120000 +#define SMI240_MECH_STARTUP_DELAY_US 100000 + +#define SMI240_CRC_INIT 0x05 +#define SMI240_CRC_POLY 0x0B +#define SMI240_BUS_ID 0x00 + +#define SMI240_SD_BIT_MASK 0x80000000 +#define SMI240_CS_BIT_MASK 0x00000008 + +#define SMI240_BUS_ID_MASK GENMASK(31, 30) +#define SMI240_WRITE_ADDR_MASK GENMASK(29, 22) +#define SMI240_WRITE_BIT_MASK 0x00200000 +#define SMI240_WRITE_DATA_MASK GENMASK(18, 3) +#define SMI240_CAP_BIT_MASK 0x00100000 +#define SMI240_READ_DATA_MASK GENMASK(19, 4) + +/* T=C2=B0C =3D (temp / 256) + 25 */ +#define SMI240_TEMP_OFFSET 6400 // 25 * 256 +#define SMI240_TEMP_SCALE 3906250 // (1 / 256) * 1e9 + +#define SMI240_ACCEL_SCALE 500 // (1 / 2000) * 1e6 +#define SMI240_GYRO_SCALE 10000 // (1 / 100) * 1e6 + +#define SMI240_LOW_BANDWIDTH_HZ 50 +#define SMI240_HIGH_BANDWIDTH_HZ 400 + +#define SMI240_BUILT_IN_SELF_TEST_COUNT 3 + +#define SMI240_DATA_CHANNEL(_type, _axis, _index) { \ + .type =3D _type, \ + .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_LOW_PASS_FILTER_3DB_FREQUENCY), \ + .info_mask_shared_by_type_available =3D \ + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ + .scan_index =3D _index, \ + .scan_type =3D { \ + .sign =3D 's', \ + .realbits =3D 16, \ + .storagebits =3D 16, \ + .endianness =3D IIO_CPU, \ + }, \ +} + +#define SMI240_TEMP_CHANNEL(_index) { \ + .type =3D IIO_TEMP, \ + .modified =3D 1, \ + .channel2 =3D IIO_MOD_TEMP_OBJECT, \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index =3D _index, \ + .scan_type =3D { \ + .sign =3D 's', \ + .realbits =3D 16, \ + .storagebits =3D 16, \ + .endianness =3D IIO_CPU, \ + }, \ +} + +enum capture_mode { SMI240_CAPTURE_OFF =3D 0, SMI240_CAPTURE_ON =3D 1 }; + +struct smi240_data { + struct regmap *regmap; + u16 accel_filter_freq; + u16 anglvel_filter_freq; + u8 built_in_self_test_count; + enum capture_mode capture; + /* + * Ensure natural alignment for timestamp if present. + * Channel size: 2 bytes. + * Max length needed: 2 * 3 channels + temp channel + 2 bytes padding + 8= byte ts. + * If fewer channels are enabled, less space may be needed, as + * long as the timestamp is still aligned to 8 bytes. + */ + s16 buf[12] __aligned(8); + + __be32 spi_buf __aligned(IIO_DMA_MINALIGN); +}; + +enum { + SMI240_TEMP_OBJECT, + SMI240_SCAN_ACCEL_X, + SMI240_SCAN_ACCEL_Y, + SMI240_SCAN_ACCEL_Z, + SMI240_SCAN_GYRO_X, + SMI240_SCAN_GYRO_Y, + SMI240_SCAN_GYRO_Z, + SMI240_SCAN_TIMESTAMP, +}; + +static const struct iio_chan_spec smi240_channels[] =3D { + SMI240_TEMP_CHANNEL(SMI240_TEMP_OBJECT), + SMI240_DATA_CHANNEL(IIO_ACCEL, X, SMI240_SCAN_ACCEL_X), + SMI240_DATA_CHANNEL(IIO_ACCEL, Y, SMI240_SCAN_ACCEL_Y), + SMI240_DATA_CHANNEL(IIO_ACCEL, Z, SMI240_SCAN_ACCEL_Z), + SMI240_DATA_CHANNEL(IIO_ANGL_VEL, X, SMI240_SCAN_GYRO_X), + SMI240_DATA_CHANNEL(IIO_ANGL_VEL, Y, SMI240_SCAN_GYRO_Y), + SMI240_DATA_CHANNEL(IIO_ANGL_VEL, Z, SMI240_SCAN_GYRO_Z), + IIO_CHAN_SOFT_TIMESTAMP(SMI240_SCAN_TIMESTAMP), +}; + +static const int smi240_low_pass_freqs[] =3D { SMI240_LOW_BANDWIDTH_HZ, + SMI240_HIGH_BANDWIDTH_HZ }; + +static u8 smi240_crc3(u32 data, u8 init, u8 poly) +{ + u8 crc =3D init; + u8 do_xor; + s8 i =3D 31; + + do { + do_xor =3D crc & 0x04; + crc <<=3D 1; + crc |=3D 0x01 & (data >> i); + if (do_xor) + crc ^=3D poly; + + crc &=3D 0x07; + } while (--i >=3D 0); + + return crc; +} + +static bool smi240_sensor_data_is_valid(u32 data) +{ + if (smi240_crc3(data, SMI240_CRC_INIT, SMI240_CRC_POLY) !=3D 0) + return false; + + if (FIELD_GET(SMI240_SD_BIT_MASK, data) & + FIELD_GET(SMI240_CS_BIT_MASK, data)) + return false; + + return true; +} + +static int smi240_regmap_spi_read(void *context, const void *reg_buf, + size_t reg_size, void *val_buf, + size_t val_size) +{ + int ret; + u32 request, response; + u16 *val =3D val_buf; + struct spi_device *spi =3D context; + struct iio_dev *indio_dev =3D dev_get_drvdata(&spi->dev); + struct smi240_data *iio_priv_data =3D iio_priv(indio_dev); + + request =3D FIELD_PREP(SMI240_BUS_ID_MASK, SMI240_BUS_ID); + request |=3D FIELD_PREP(SMI240_CAP_BIT_MASK, iio_priv_data->capture); + request |=3D FIELD_PREP(SMI240_WRITE_ADDR_MASK, *(u8 *)reg_buf); + request |=3D smi240_crc3(request, SMI240_CRC_INIT, SMI240_CRC_POLY); + + iio_priv_data->spi_buf =3D cpu_to_be32(request); + + /* + * SMI240 module consists of a 32Bit Out Of Frame (OOF) + * SPI protocol, where the slave interface responds to + * the Master request in the next frame. + * CS signal must toggle (> 700 ns) between the frames. + */ + ret =3D spi_write(spi, &iio_priv_data->spi_buf, sizeof(request)); + if (ret) + return ret; + + ret =3D spi_read(spi, &iio_priv_data->spi_buf, sizeof(response)); + if (ret) + return ret; + + response =3D be32_to_cpu(iio_priv_data->spi_buf); + + if (!smi240_sensor_data_is_valid(response)) + return -EIO; + + *val =3D FIELD_GET(SMI240_READ_DATA_MASK, response); + + return 0; +} + +static int smi240_regmap_spi_write(void *context, const void *data, + size_t count) +{ + u8 reg_addr; + u16 reg_data; + u32 request; + struct spi_device *spi =3D context; + struct iio_dev *indio_dev =3D dev_get_drvdata(&spi->dev); + struct smi240_data *iio_priv_data =3D iio_priv(indio_dev); + + if (count < 2) + return -EINVAL; + + reg_addr =3D ((u8 *)data)[0]; + reg_data =3D get_unaligned_le16(&((u8 *)data)[1]); + + request =3D FIELD_PREP(SMI240_BUS_ID_MASK, SMI240_BUS_ID); + request |=3D FIELD_PREP(SMI240_WRITE_BIT_MASK, 1); + request |=3D FIELD_PREP(SMI240_WRITE_ADDR_MASK, reg_addr); + request |=3D FIELD_PREP(SMI240_WRITE_DATA_MASK, reg_data); + request |=3D smi240_crc3(request, SMI240_CRC_INIT, SMI240_CRC_POLY); + + iio_priv_data->spi_buf =3D cpu_to_be32(request); + + return spi_write(spi, &iio_priv_data->spi_buf, sizeof(request)); +} + +static const struct regmap_bus smi240_regmap_bus =3D { + .read =3D smi240_regmap_spi_read, + .write =3D smi240_regmap_spi_write, +}; + +static const struct regmap_config smi240_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 16, + .val_format_endian =3D REGMAP_ENDIAN_LITTLE, +}; + +static int smi240_soft_reset(struct smi240_data *data) +{ + int ret; + + ret =3D regmap_write(data->regmap, SMI240_CMD_REG, SMI240_SOFT_RESET_CMD); + if (ret) + return ret; + fsleep(SMI240_DIGITAL_STARTUP_DELAY_US); + + return 0; +} + +static int smi240_soft_config(struct smi240_data *data) +{ + int ret; + u8 acc_bw, gyr_bw; + u16 request; + + switch (data->accel_filter_freq) { + case SMI240_LOW_BANDWIDTH_HZ: + acc_bw =3D 0x1; + break; + case SMI240_HIGH_BANDWIDTH_HZ: + acc_bw =3D 0x0; + break; + default: + return -EINVAL; + } + + switch (data->anglvel_filter_freq) { + case SMI240_LOW_BANDWIDTH_HZ: + gyr_bw =3D 0x1; + break; + case SMI240_HIGH_BANDWIDTH_HZ: + gyr_bw =3D 0x0; + break; + default: + return -EINVAL; + } + + request =3D FIELD_PREP(SMI240_SOFT_CONFIG_EOC_MASK, 1); + request |=3D FIELD_PREP(SMI240_SOFT_CONFIG_GYR_BW_MASK, gyr_bw); + request |=3D FIELD_PREP(SMI240_SOFT_CONFIG_ACC_BW_MASK, acc_bw); + request |=3D FIELD_PREP(SMI240_SOFT_CONFIG_BITE_AUTO_MASK, 1); + request |=3D FIELD_PREP(SMI240_SOFT_CONFIG_BITE_REP_MASK, + data->built_in_self_test_count - 1); + + ret =3D regmap_write(data->regmap, SMI240_SOFT_CONFIG_REG, request); + if (ret) + return ret; + + fsleep(SMI240_MECH_STARTUP_DELAY_US + + data->built_in_self_test_count * SMI240_BITE_SEQUENCE_DELAY_US + + SMI240_FILTER_FLUSH_DELAY_US); + + return 0; +} + +static int smi240_get_low_pass_filter_freq(struct smi240_data *data, + int chan_type, int *val) +{ + switch (chan_type) { + case IIO_ACCEL: + *val =3D data->accel_filter_freq; + return 0; + case IIO_ANGL_VEL: + *val =3D data->anglvel_filter_freq; + return 0; + default: + return -EINVAL; + } +} + +static int smi240_get_data(struct smi240_data *data, int chan_type, int ax= is, + int *val) +{ + u8 reg; + int ret, sample; + + switch (chan_type) { + case IIO_TEMP: + reg =3D SMI240_TEMP_CUR_REG; + break; + case IIO_ACCEL: + reg =3D SMI240_ACCEL_X_CUR_REG + (axis - IIO_MOD_X); + break; + case IIO_ANGL_VEL: + reg =3D SMI240_GYRO_X_CUR_REG + (axis - IIO_MOD_X); + break; + default: + return -EINVAL; + } + + ret =3D regmap_read(data->regmap, reg, &sample); + if (ret) + return ret; + + *val =3D sign_extend32(sample, 15); + + return 0; +} + +static irqreturn_t smi240_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf =3D p; + struct iio_dev *indio_dev =3D pf->indio_dev; + struct smi240_data *data =3D iio_priv(indio_dev); + int base =3D SMI240_DATA_CAP_FIRST_REG, i =3D 0; + int ret, chan, sample; + + data->capture =3D SMI240_CAPTURE_ON; + + iio_for_each_active_channel(indio_dev, chan) { + ret =3D regmap_read(data->regmap, base + chan, &sample); + data->capture =3D SMI240_CAPTURE_OFF; + if (ret) + goto out; + data->buf[i++] =3D sample; + } + + iio_push_to_buffers_with_timestamp(indio_dev, data->buf, pf->timestamp); + +out: + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} + +static int smi240_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_LOW_PASS_FILTER_3DB_FREQUENCY: + *vals =3D smi240_low_pass_freqs; + *length =3D ARRAY_SIZE(smi240_low_pass_freqs); + *type =3D IIO_VAL_INT; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + +static int smi240_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + int ret; + struct smi240_data *data =3D iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret =3D iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + ret =3D smi240_get_data(data, chan->type, chan->channel2, val); + iio_device_release_direct_mode(indio_dev); + if (ret) + return ret; + return IIO_VAL_INT; + + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + ret =3D smi240_get_low_pass_filter_freq(data, chan->type, val); + if (ret) + return ret; + return IIO_VAL_INT; + + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_TEMP: + *val =3D SMI240_TEMP_SCALE / GIGA; + *val2 =3D SMI240_TEMP_SCALE % GIGA; + return IIO_VAL_INT_PLUS_NANO; + case IIO_ACCEL: + *val =3D 0; + *val2 =3D SMI240_ACCEL_SCALE; + return IIO_VAL_INT_PLUS_MICRO; + case IIO_ANGL_VEL: + *val =3D 0; + *val2 =3D SMI240_GYRO_SCALE; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + + case IIO_CHAN_INFO_OFFSET: + if (chan->type =3D=3D IIO_TEMP) { + *val =3D SMI240_TEMP_OFFSET; + return IIO_VAL_INT; + } else { + return -EINVAL; + } + + default: + return -EINVAL; + } +} + +static int smi240_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, + long mask) +{ + int ret, i; + struct smi240_data *data =3D iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + for (i =3D 0; i < ARRAY_SIZE(smi240_low_pass_freqs); i++) { + if (val =3D=3D smi240_low_pass_freqs[i]) + break; + } + + if (i =3D=3D ARRAY_SIZE(smi240_low_pass_freqs)) + return -EINVAL; + + switch (chan->type) { + case IIO_ACCEL: + data->accel_filter_freq =3D val; + break; + case IIO_ANGL_VEL: + data->anglvel_filter_freq =3D val; + break; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + /* Write access to soft config is locked until hard/soft reset */ + ret =3D smi240_soft_reset(data); + if (ret) + return ret; + + return smi240_soft_config(data); +} + +static int smi240_write_raw_get_fmt(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, long info) +{ + switch (info) { + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_TEMP: + return IIO_VAL_INT_PLUS_NANO; + default: + return IIO_VAL_INT_PLUS_MICRO; + } + default: + return IIO_VAL_INT_PLUS_MICRO; + } +} + +static int smi240_init(struct smi240_data *data) +{ + data->accel_filter_freq =3D SMI240_HIGH_BANDWIDTH_HZ; + data->anglvel_filter_freq =3D SMI240_HIGH_BANDWIDTH_HZ; + data->built_in_self_test_count =3D SMI240_BUILT_IN_SELF_TEST_COUNT; + + return smi240_soft_config(data); +} + +static const struct iio_info smi240_info =3D { + .read_avail =3D smi240_read_avail, + .read_raw =3D smi240_read_raw, + .write_raw =3D smi240_write_raw, + .write_raw_get_fmt =3D smi240_write_raw_get_fmt, +}; + +static int smi240_probe(struct spi_device *spi) +{ + struct device *dev =3D &spi->dev; + struct iio_dev *indio_dev; + struct regmap *regmap; + struct smi240_data *data; + int ret, response; + + indio_dev =3D devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + regmap =3D devm_regmap_init(dev, &smi240_regmap_bus, dev, + &smi240_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), + "Failed to initialize SPI Regmap\n"); + + data =3D iio_priv(indio_dev); + dev_set_drvdata(dev, indio_dev); + data->regmap =3D regmap; + data->capture =3D SMI240_CAPTURE_OFF; + + ret =3D regmap_read(data->regmap, SMI240_CHIP_ID_REG, &response); + if (ret) + return dev_err_probe(dev, ret, "Read chip id failed\n"); + + if (response !=3D SMI240_CHIP_ID) + dev_info(dev, "Unknown chip id: 0x%04x\n", response); + + ret =3D smi240_init(data); + if (ret) + return dev_err_probe(dev, ret, + "Device initialization failed\n"); + + indio_dev->channels =3D smi240_channels; + indio_dev->num_channels =3D ARRAY_SIZE(smi240_channels); + indio_dev->name =3D "smi240"; + indio_dev->modes =3D INDIO_DIRECT_MODE; + indio_dev->info =3D &smi240_info; + + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + smi240_trigger_handler, NULL); + if (ret) + return dev_err_probe(dev, ret, + "Setup triggered buffer failed\n"); + + ret =3D devm_iio_device_register(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "Register IIO device failed\n"); + + return 0; +} + +static const struct spi_device_id smi240_spi_id[] =3D { + { "smi240" }, + { } +}; +MODULE_DEVICE_TABLE(spi, smi240_spi_id); + +static const struct of_device_id smi240_of_match[] =3D { + { .compatible =3D "bosch,smi240" }, + { } +}; +MODULE_DEVICE_TABLE(of, smi240_of_match); + +static struct spi_driver smi240_spi_driver =3D { + .probe =3D smi240_probe, + .id_table =3D smi240_spi_id, + .driver =3D { + .of_match_table =3D smi240_of_match, + .name =3D "smi240", + }, +}; +module_spi_driver(smi240_spi_driver); + +MODULE_AUTHOR("Markus Lochmann "); +MODULE_AUTHOR("Stefan Gutmann "); +MODULE_DESCRIPTION("Bosch SMI240 SPI driver"); +MODULE_LICENSE("Dual BSD/GPL"); --=20 2.34.1