Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp439791imm; Fri, 3 Aug 2018 06:04:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdqBEMrmg79sZQiVmhO34toChcuPJcnLxpmwKGsfSD2MKoibSz6Tfjv/CakXocfXdHYxnR4 X-Received: by 2002:a17:902:b81:: with SMTP id 1-v6mr3578042plr.164.1533301475037; Fri, 03 Aug 2018 06:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533301475; cv=none; d=google.com; s=arc-20160816; b=aKs1BLmusCEImyJryP6uqQkCsKJvrIA7DW132MRJtKtNDUBY4JrFDucR4JTQIFHhjh I2RwUNF59mSE3JB39Yx7tm8U3MSuzLqO7e1KpXJavCCsr63g5Fd9y5TUxrFkyYmIF/94 W/H7eeE90am4tBGs0wdY7ieQfGbtASh96AKwLAmBnXElWAaPnhN74kNFpksmJLZB4Gd4 1NSacB8iUzDeIWrzb7pWUCuT6x3WFcUrkk2CrReTZ5fNNRNdv6qb4iMzSAiQXr6/m8sk tSlSk4GYRgNRnMxHr9FPc7RzgophSwuuFo4oNsi3sI5h4bq9aZvQkszDDOMCpKnRFRY7 m79g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=afXxFnjRPn2FRM8qyaeZWi/8j9SOj52O8e/lPAoHDHo=; b=TxpU5mmH1mLwBwhPZQU1RpMn79nyeHRVTXsaaD+pj0JJBimN6Jqv/nek8E3JmlMN5P 4YU6FmUCiICcDFDGhIfOEbMKVEi2srICf73ZeaY1smCRPA3OC1w03XVd3iYSGXW2awL/ 8A+vjpeVS/cleRi0WXjBuOqbPz7yukTLI1GSqbYpe1/bH2VRyC17WQOnkQJoGgS1WXFE 022AsRUAA5Wn9gfQb26kdKvzhZCCdaZHv6NuY+4S23g/TbkZn6IRA/XG5mOV0ourmQIK oMvOvyqomhGzz8xKjq2lX3NbPbefvQUvi7fgRYfQ+q03VJurEhbMybLDRmJd67lH1qiT Emiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@analog.onmicrosoft.com header.s=selector1-analog-com header.b=dZ7m+QYx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l190-v6si4703227pgd.626.2018.08.03.06.04.20; Fri, 03 Aug 2018 06:04:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@analog.onmicrosoft.com header.s=selector1-analog-com header.b=dZ7m+QYx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732133AbeHCO73 (ORCPT + 99 others); Fri, 3 Aug 2018 10:59:29 -0400 Received: from mail-eopbgr730083.outbound.protection.outlook.com ([40.107.73.83]:32704 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729603AbeHCO73 (ORCPT ); Fri, 3 Aug 2018 10:59:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=afXxFnjRPn2FRM8qyaeZWi/8j9SOj52O8e/lPAoHDHo=; b=dZ7m+QYxKGd+ODKLOzLQ23lcoIyGnNZ3Hf4fEVwVPGvYx9WtH54RJ0nE2igejOMypD8wBBw/dokKI8A7Z52CAaYmWP7gVmh68s4e2XoLguk7i4BKL6Ft4Dd9+OV78kicGQ1INT03JEW/45E/Q1iD21cs6UtTd1eg142CmK56EhI= Received: from BN6PR03CA0014.namprd03.prod.outlook.com (2603:10b6:404:23::24) by DM5PR03MB3131.namprd03.prod.outlook.com (2603:10b6:4:3c::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.15; Fri, 3 Aug 2018 13:03:05 +0000 Received: from BN1BFFO11FD003.protection.gbl (2a01:111:f400:7c10::1:118) by BN6PR03CA0014.outlook.office365.com (2603:10b6:404:23::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1017.15 via Frontend Transport; Fri, 3 Aug 2018 13:03:05 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; gmx.de; dkim=none (message not signed) header.d=none;gmx.de; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by BN1BFFO11FD003.mail.protection.outlook.com (10.58.144.66) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1017.15 via Frontend Transport; Fri, 3 Aug 2018 13:03:05 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id w73D34If011786 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Fri, 3 Aug 2018 06:03:04 -0700 Received: from linux.analog.com (10.50.1.113) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.301.0; Fri, 3 Aug 2018 09:03:04 -0400 From: Stefan Popa To: , CC: Stefan Popa , , , , , , , , , , , , , Subject: [PATCH v3 1/6] iio: adxl372: New driver for Analog Devices ADXL372 Accelerometer Date: Fri, 3 Aug 2018 16:02:16 +0300 Message-ID: <1533301341-26560-2-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533301341-26560-1-git-send-email-stefan.popa@analog.com> References: <1533301341-26560-1-git-send-email-stefan.popa@analog.com> MIME-Version: 1.0 Content-Type: text/plain X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(7966004)(136003)(346002)(376002)(396003)(39860400002)(2980300002)(438002)(199004)(189003)(426003)(11346002)(486006)(6666003)(246002)(6306002)(47776003)(305945005)(1720100001)(575784001)(186003)(4326008)(446003)(336012)(76176011)(106002)(110136005)(316002)(16586007)(7696005)(51416003)(54906003)(77096007)(26005)(7416002)(106466001)(14444005)(72206003)(126002)(8936002)(5660300001)(356003)(50466002)(48376002)(966005)(44832011)(53416004)(508600001)(50226002)(2906002)(36756003)(7636002)(476003)(2616005)(8676002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR03MB3131;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD003;1:jnsKycLKHSS2y4iOJ5JV0oo1mi/uxvfyHDlBQIrhtT7WAC7NSqIaK6ahq+NOzA1AZnn3ZWPfgQmIj3idLfZNUodOO96muwIoBl8BEQswQmPqLz0RkCvkm4AnZ+jZ+pVU X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9c11c6b2-1b73-447d-02ed-08d5f94173b2 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4608076)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060);SRVR:DM5PR03MB3131; X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB3131;3:Y1A8rUx5Kt8OzUGRdsmCvfkng53f8JRcRuzQZ+fKCNA0E8H6Tq8+bHiprRPfee9k/l12DJAtUeXtNw4Kz7PhKXegCzzLrbat5xLczMQAzj3Xkyr+1NzTQX6f506EZMkISXEPZA0WZJrdcqOKmfmDK1evSLyWQBeWjR8C24jRIUHxxNFBlwqF5RBH97weogb8sRZUS7cmVodwAHhpRo/iwCROVMlagUAxX1RBUpwqfzUChYddSa3MzusKjF7oc0gcOQWKDP826S9cEbfw1M+YEMdd9OtvfC4ytGLuudYuS0TVw5ovlcTtcIOu8kICvzjlaqRKQCk/Oo5LKHamtavltYwPtLK7t3AGJS5JYIY1LOo=;25:Nn3l5qWCsXCu2wQwzOb6GVPcAQsJBd/LWusEq524WAjPuQ5IaFQOhiw9jJBkaLM+e9EnS4wyyCWilA9GxEXF/oZ6vA7FxrQXvRv3agkANHU5KDEmtB7VA/WeH4N5UlFHNGqvPb5lA1xxcZfR/mfDAO86bGxZCqiBr5F7HgZqjwikQR41GW9NEhOrm1RjzcU3Sp17lja43NJv9oqvtn3+yCaEADpF+Py7gbvWeWuALlD/p8MXLAGDOVfJmG1BVE2x0o3oRHjsSSj9GxJae/f/3R5kNP10RA6DgMw+QFd6zNRwuFJaPZwQgEUN+ir6a1tzDEBMW+QWr8AhklncwI1ylQ== X-MS-TrafficTypeDiagnostic: DM5PR03MB3131: X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB3131;31:bMX1OMEhnHRZa/lxEcaExYj1ZIaRjROxjtqtU2OGReiWouE7aAa6w4U448JV572E07/JN+NnW2r+nIloRUiTIeK6/n5I7FrKPdD4C5zExCPNkJPS8u7DRXjYX/aq9ho6v2sNg3G+NKw3VcXu9YBX61NSSFqNEaa7WjX1DEnoJSj2klUDlLftPT7PCIUbMcJxiuSKj8nsPVlasfHZDb3XgDnI0i/XO3qUSYY9XBslv4Q=;20:j4ivhqgzqfO5Sr1u6WE4Cdtwv3axGj9gTEJhws3Nw5dZQoHlV2kB3YWZYKDavRUR9zbXs9tpNzfRpc56q2WjVa4TWzVpLmJEYrWwUHKi4xxlVNGSa9jNHP0XlrMtj1mDPB+W8O4nbRkO5t4qqw6JMGoLMvbH0vvcGuawZ8NFBbKIO2du87RFxx2mTtC1LXU/FjkZYkTWGuk5C7fLA0Y1CEBl8Uw5Ek3HCbJG7yL182K7Wi69txylP8L7KAka+PW2VJtoMORY46Rpj3wa4yIaDiWi9x4k/cmE2Y8mbVzFvZm9ZXmZ5l3CUunjPKPSflWy2BNNapXsrb5DdwasYlxm43ITqzYmccpF2bUxuJrJpT9H4NmYHOMFXqdhljw6KRx5lgFV8m+C1wNXt1olTrGL04DXtxclwCLBSgrI0w4/rSk4dpTSPZj9dLnXEymVgtzFOaBZ41aQ8wX96+7cJesl8smepiN5etKp3lSlQ7NZl3GZRFlI3/6sB9aLit/dJwMs X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(270121546159015)(9452136761055)(232431446821674)(170811661138872); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93004095)(10201501046)(3231311)(944501410)(52105095)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201703011903075)(201702281528075)(20161123555045)(201703061421075)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:DM5PR03MB3131;BCL:0;PCL:0;RULEID:;SRVR:DM5PR03MB3131; X-Microsoft-Exchange-Diagnostics: 1;DM5PR03MB3131;4:1t3WA+2xfxHZroaiyiOH2/JmOyAm2qrBUSeIXkJ9g7koXk6YZW6d4slzQG7k88Z8OvjZ42umGI8/Xqmp33HGJkT8aadfNAxK2yg1stfPm1umLBdQz+BcrqGbDL2AkjmrlBlldOLfposwgH2SB2MvwK7kbRQTRhFSh90fy+4PjjYmE9Z2dPAwD/tauBKynHI3+ABLrdwvRlDC+I2v5ij/1oEeaTPyscXOOcxTtMnj5i1dwruilfxmTBlRjoWEIzOt/ADUNnrWFDKwW1IkdK3UERXhj286+AmoySiWGR1iRH9pMQx3eF5Jx+lyGlcshs79LkTOCnzH0uECFsl8uAkdOuIKHLE+GaxUZqw/dAst2x95pBFin+WQ4JfILfhBp/1mYICw2QQVjf2GBggg8w8ui92GIRFX+kb75IIRL2ftTHI= X-Forefront-PRVS: 0753EA505A X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM5PR03MB3131;23:bxbW/0XSgYo7tTDRSi3q3vyNWeRQLhdrWis8F6+Av?= =?us-ascii?Q?zcFbM+l6XX0m3aetQzo9x076rRcg2nBQOIU3UGzuaDbV3LiblVoy7EK6xi1B?= =?us-ascii?Q?h2pbylRdCNs1A5MaB0KuLa+d6fbTL5eoXjc2dkR4bVFaMnKTwrSiyD2Wk5Y5?= =?us-ascii?Q?DVCHMeIat5TOTAWmwdxaqc3MogLYjz7/VHoTKt2kAFniVkf8FYuS9CmhVjpa?= =?us-ascii?Q?MPaeZLgXN79v7ffxm64NdPAYLeUbsyy+yCy3jgIIJ+n5wR7FzICjyeyQ9fBZ?= =?us-ascii?Q?ELpZVwr0L+WKfEltE4+0THksQiSqmnIt9EFKX5lM1YbGVBIbh6iowtu7eFzd?= =?us-ascii?Q?KGnToxJFtRudgIroXczGh+P2BL3xy+PyYXJ1MegxUPPlGN184m8ikwneFb3Z?= =?us-ascii?Q?sXnZe3hHPnaWHTumrprE7WuE/d3mPBS4NzZKiAU40XEla3IllSf5V0Z58oyl?= =?us-ascii?Q?vASqW55x9LCOJEhpI4EMFj3qsHvKQNizyAWM29HLO3YiILQsLGa9Z2z4y8sQ?= =?us-ascii?Q?F23hAqmA6tHGcJldYZ+BJAeFtui1ti7VzsAJGT2h/uRZNNgpRBFNz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Metadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2018 13:03:05.0310 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c11c6b2-1b73-447d-02ed-08d5f94173b2 X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.55];Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB3131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds basic support for Analog Devices ADXL372 SPI-Bus Three-Axis Digital Accelerometer. The device is probed and configured the with some initial default values. With this basic driver, it is possible to read raw acceleration data. Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL372.pdf Signed-off-by: Stefan Popa --- MAINTAINERS | 6 + drivers/iio/accel/Kconfig | 11 + drivers/iio/accel/Makefile | 1 + drivers/iio/accel/adxl372.c | 530 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 548 insertions(+) create mode 100644 drivers/iio/accel/adxl372.c diff --git a/MAINTAINERS b/MAINTAINERS index 60b1028..2ba47bb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -543,6 +543,12 @@ W: http://ez.analog.com/community/linux-device-drivers S: Supported F: drivers/input/misc/adxl34x.c +ADXL372 THREE-AXIS DIGITAL ACCELEROMETER DRIVER +M: Stefan Popa +W: http://ez.analog.com/community/linux-device-drivers +S: Supported +F: drivers/iio/accel/adxl372.c + AF9013 MEDIA DRIVER M: Antti Palosaari L: linux-media@vger.kernel.org diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig index 62ae7e5..1b496ef 100644 --- a/drivers/iio/accel/Kconfig +++ b/drivers/iio/accel/Kconfig @@ -60,6 +60,17 @@ config ADXL345_SPI will be called adxl345_spi and you will also get adxl345_core for the core module. +config ADXL372 + tristate "Analog Devices ADXL372 3-Axis Accelerometer Driver" + depends on SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say yes here to add support for the Analog Devices ADXL372 triaxial + acceleration sensor. + To compile this driver as a module, choose M here: the + module will be called adxl372. + config BMA180 tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver" depends on I2C diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile index 636d4d1..5758ffc 100644 --- a/drivers/iio/accel/Makefile +++ b/drivers/iio/accel/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_ADIS16209) += adis16209.o obj-$(CONFIG_ADXL345) += adxl345_core.o obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o +obj-$(CONFIG_ADXL372) += adxl372.o obj-$(CONFIG_BMA180) += bma180.o obj-$(CONFIG_BMA220) += bma220_spi.o obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c new file mode 100644 index 0000000..7d5092d --- /dev/null +++ b/drivers/iio/accel/adxl372.c @@ -0,0 +1,530 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * ADXL372 3-Axis Digital Accelerometer SPI driver + * + * Copyright 2018 Analog Devices Inc. + */ + +#include +#include +#include +#include + +#include +#include + +/* ADXL372 registers definition */ +#define ADXL372_DEVID 0x00 +#define ADXL372_DEVID_MST 0x01 +#define ADXL372_PARTID 0x02 +#define ADXL372_REVID 0x03 +#define ADXL372_STATUS_1 0x04 +#define ADXL372_STATUS_2 0x05 +#define ADXL372_FIFO_ENTRIES_2 0x06 +#define ADXL372_FIFO_ENTRIES_1 0x07 +#define ADXL372_X_DATA_H 0x08 +#define ADXL372_X_DATA_L 0x09 +#define ADXL372_Y_DATA_H 0x0A +#define ADXL372_Y_DATA_L 0x0B +#define ADXL372_Z_DATA_H 0x0C +#define ADXL372_Z_DATA_L 0x0D +#define ADXL372_X_MAXPEAK_H 0x15 +#define ADXL372_X_MAXPEAK_L 0x16 +#define ADXL372_Y_MAXPEAK_H 0x17 +#define ADXL372_Y_MAXPEAK_L 0x18 +#define ADXL372_Z_MAXPEAK_H 0x19 +#define ADXL372_Z_MAXPEAK_L 0x1A +#define ADXL372_OFFSET_X 0x20 +#define ADXL372_OFFSET_Y 0x21 +#define ADXL372_OFFSET_Z 0x22 +#define ADXL372_X_THRESH_ACT_H 0x23 +#define ADXL372_X_THRESH_ACT_L 0x24 +#define ADXL372_Y_THRESH_ACT_H 0x25 +#define ADXL372_Y_THRESH_ACT_L 0x26 +#define ADXL372_Z_THRESH_ACT_H 0x27 +#define ADXL372_Z_THRESH_ACT_L 0x28 +#define ADXL372_TIME_ACT 0x29 +#define ADXL372_X_THRESH_INACT_H 0x2A +#define ADXL372_X_THRESH_INACT_L 0x2B +#define ADXL372_Y_THRESH_INACT_H 0x2C +#define ADXL372_Y_THRESH_INACT_L 0x2D +#define ADXL372_Z_THRESH_INACT_H 0x2E +#define ADXL372_Z_THRESH_INACT_L 0x2F +#define ADXL372_TIME_INACT_H 0x30 +#define ADXL372_TIME_INACT_L 0x31 +#define ADXL372_X_THRESH_ACT2_H 0x32 +#define ADXL372_X_THRESH_ACT2_L 0x33 +#define ADXL372_Y_THRESH_ACT2_H 0x34 +#define ADXL372_Y_THRESH_ACT2_L 0x35 +#define ADXL372_Z_THRESH_ACT2_H 0x36 +#define ADXL372_Z_THRESH_ACT2_L 0x37 +#define ADXL372_HPF 0x38 +#define ADXL372_FIFO_SAMPLES 0x39 +#define ADXL372_FIFO_CTL 0x3A +#define ADXL372_INT1_MAP 0x3B +#define ADXL372_INT2_MAP 0x3C +#define ADXL372_TIMING 0x3D +#define ADXL372_MEASURE 0x3E +#define ADXL372_POWER_CTL 0x3F +#define ADXL372_SELF_TEST 0x40 +#define ADXL372_RESET 0x41 +#define ADXL372_FIFO_DATA 0x42 + +#define ADXL372_DEVID_VAL 0xAD +#define ADXL372_PARTID_VAL 0xFA +#define ADXL372_RESET_CODE 0x52 + +/* ADXL372_POWER_CTL */ +#define ADXL372_POWER_CTL_MODE_MSK GENMASK_ULL(1, 0) +#define ADXL372_POWER_CTL_MODE(x) (((x) & 0x3) << 0) + +/* ADXL372_MEASURE */ +#define ADXL372_MEASURE_LINKLOOP_MSK GENMASK_ULL(5, 4) +#define ADXL372_MEASURE_LINKLOOP_MODE(x) (((x) & 0x3) << 4) +#define ADXL372_MEASURE_BANDWIDTH_MSK GENMASK_ULL(2, 0) +#define ADXL372_MEASURE_BANDWIDTH_MODE(x) (((x) & 0x7) << 0) + +/* ADXL372_TIMING */ +#define ADXL372_TIMING_ODR_MSK GENMASK_ULL(7, 5) +#define ADXL372_TIMING_ODR_MODE(x) (((x) & 0x7) << 5) + +/* ADXL372_FIFO_CTL */ +#define ADXL372_FIFO_CTL_FORMAT_MSK GENMASK(5, 3) +#define ADXL372_FIFO_CTL_FORMAT_MODE(x) (((x) & 0x7) << 3) +#define ADXL372_FIFO_CTL_MODE_MSK GENMASK(2, 1) +#define ADXL372_FIFO_CTL_MODE_MODE(x) (((x) & 0x3) << 1) +#define ADXL372_FIFO_CTL_SAMPLES_MSK BIT(1) +#define ADXL372_FIFO_CTL_SAMPLES_MODE(x) (((x) > 0xFF) ? 1 : 0) + +/* ADXL372_STATUS_1 */ +#define ADXL372_STATUS_1_DATA_RDY(x) (((x) >> 0) & 0x1) +#define ADXL372_STATUS_1_FIFO_RDY(x) (((x) >> 1) & 0x1) +#define ADXL372_STATUS_1_FIFO_FULL(x) (((x) >> 2) & 0x1) +#define ADXL372_STATUS_1_FIFO_OVR(x) (((x) >> 3) & 0x1) +#define ADXL372_STATUS_1_USR_NVM_BUSY(x) (((x) >> 5) & 0x1) +#define ADXL372_STATUS_1_AWAKE(x) (((x) >> 6) & 0x1) +#define ADXL372_STATUS_1_ERR_USR_REGS(x) (((x) >> 7) & 0x1) + +/* ADXL372_INT1_MAP */ +#define ADXL372_INT1_MAP_DATA_RDY_MSK BIT(0) +#define ADXL372_INT1_MAP_DATA_RDY_MODE(x) (((x) & 0x1) << 0) +#define ADXL372_INT1_MAP_FIFO_RDY_MSK BIT(1) +#define ADXL372_INT1_MAP_FIFO_RDY_MODE(x) (((x) & 0x1) << 1) +#define ADXL372_INT1_MAP_FIFO_FULL_MSK BIT(2) +#define ADXL372_INT1_MAP_FIFO_FULL_MODE(x) (((x) & 0x1) << 2) +#define ADXL372_INT1_MAP_FIFO_OVR_MSK BIT(3) +#define ADXL372_INT1_MAP_FIFO_OVR_MODE(x) (((x) & 0x1) << 3) +#define ADXL372_INT1_MAP_INACT_MSK BIT(4) +#define ADXL372_INT1_MAP_INACT_MODE(x) (((x) & 0x1) << 4) +#define ADXL372_INT1_MAP_ACT_MSK BIT(5) +#define ADXL372_INT1_MAP_ACT_MODE(x) (((x) & 0x1) << 5) +#define ADXL372_INT1_MAP_AWAKE_MSK BIT(6) +#define ADXL372_INT1_MAP_AWAKE_MODE(x) (((x) & 0x1) << 6) +#define ADXL372_INT1_MAP_LOW_MSK BIT(7) +#define ADXL372_INT1_MAP_LOW_MODE(x) (((x) & 0x1) << 7) + +/* + * At +/- 200g with 12-bit resolution, scale is computed as: + * (200 + 200) * 9.81 / (2^12 - 1) = 0.958241 + */ +#define ADXL372_USCALE 958241 + +enum adxl372_op_mode { + ADXL372_STANDBY, + ADXL372_WAKE_UP, + ADXL372_INSTANT_ON, + ADXL372_FULL_BW_MEASUREMENT, +}; + +enum adxl372_act_proc_mode { + ADXL372_DEFAULT, + ADXL372_LINKED, + ADXL372_LOOPED, +}; + +enum adxl372_th_activity { + ADXL372_ACTIVITY, + ADXL372_ACTIVITY2, + ADXL372_INACTIVITY, +}; + +enum adxl372_odr { + ADXL372_ODR_400HZ, + ADXL372_ODR_800HZ, + ADXL372_ODR_1600HZ, + ADXL372_ODR_3200HZ, + ADXL372_ODR_6400HZ, +}; + +enum adxl372_bandwidth { + ADXL372_BW_200HZ, + ADXL372_BW_400HZ, + ADXL372_BW_800HZ, + ADXL372_BW_1600HZ, + ADXL372_BW_3200HZ, +}; + +#define ADXL372_ACCEL_CHANNEL(index, reg, axis) { \ + .type = IIO_ACCEL, \ + .address = reg, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ +} + +static const struct iio_chan_spec adxl372_channels[] = { + ADXL372_ACCEL_CHANNEL(0, ADXL372_X_DATA_H, X), + ADXL372_ACCEL_CHANNEL(1, ADXL372_Y_DATA_H, Y), + ADXL372_ACCEL_CHANNEL(2, ADXL372_Z_DATA_H, Z), +}; + +struct adxl372_state { + struct spi_device *spi; + struct regmap *regmap; + enum adxl372_op_mode op_mode; + enum adxl372_act_proc_mode act_proc_mode; + enum adxl372_odr odr; + enum adxl372_bandwidth bw; + u32 act_time_ms; + u32 inact_time_ms; +}; + +static int adxl372_read_axis(struct adxl372_state *st, u8 addr) +{ + __be16 regval; + int ret; + + ret = regmap_bulk_read(st->regmap, addr, ®val, sizeof(regval)); + if (ret < 0) + return ret; + + return be16_to_cpu(regval); +} + +static int adxl372_set_op_mode(struct adxl372_state *st, + enum adxl372_op_mode op_mode) +{ + int ret; + + ret = regmap_update_bits(st->regmap, ADXL372_POWER_CTL, + ADXL372_POWER_CTL_MODE_MSK, + ADXL372_POWER_CTL_MODE(op_mode)); + if (ret < 0) + return ret; + + st->op_mode = op_mode; + + return ret; +} + +static int adxl372_set_odr(struct adxl372_state *st, + enum adxl372_odr odr) +{ + int ret; + + ret = regmap_update_bits(st->regmap, ADXL372_TIMING, + ADXL372_TIMING_ODR_MSK, + ADXL372_TIMING_ODR_MODE(odr)); + if (ret < 0) + return ret; + + st->odr = odr; + + return ret; +} + +static int adxl372_set_bandwidth(struct adxl372_state *st, + enum adxl372_bandwidth bw) +{ + int ret; + + ret = regmap_update_bits(st->regmap, ADXL372_MEASURE, + ADXL372_MEASURE_BANDWIDTH_MSK, + ADXL372_MEASURE_BANDWIDTH_MODE(bw)); + if (ret < 0) + return ret; + + st->bw = bw; + + return ret; +} + +static int adxl372_set_act_proc_mode(struct adxl372_state *st, + enum adxl372_act_proc_mode mode) +{ + int ret; + + ret = regmap_update_bits(st->regmap, + ADXL372_MEASURE, + ADXL372_MEASURE_LINKLOOP_MSK, + ADXL372_MEASURE_LINKLOOP_MODE(mode)); + if (ret < 0) + return ret; + + st->act_proc_mode = mode; + + return ret; +} + +static int adxl372_set_activity_threshold(struct adxl372_state *st, + enum adxl372_th_activity act, + bool ref_en, bool enable, + unsigned int threshold) +{ + unsigned char buf[6]; + unsigned char th_reg_high_val, th_reg_low_val, th_reg_high_addr; + + /* scale factor is 100 mg/code */ + th_reg_high_val = (threshold / 100) >> 3; + th_reg_low_val = ((threshold / 100) << 5) | (ref_en << 1) | enable; + + switch (act) { + case ADXL372_ACTIVITY: + th_reg_high_addr = ADXL372_X_THRESH_ACT_H; + break; + case ADXL372_ACTIVITY2: + th_reg_high_addr = ADXL372_X_THRESH_ACT2_H; + break; + case ADXL372_INACTIVITY: + th_reg_high_addr = ADXL372_X_THRESH_INACT_H; + break; + } + + buf[0] = th_reg_high_val; + buf[1] = th_reg_low_val; + buf[2] = th_reg_high_val; + buf[3] = th_reg_low_val; + buf[4] = th_reg_high_val; + buf[5] = th_reg_low_val; + + return regmap_bulk_write(st->regmap, th_reg_high_addr, + buf, ARRAY_SIZE(buf)); +} + +static int adxl372_set_activity_time_ms(struct adxl372_state *st, + unsigned int act_time_ms) +{ + unsigned int reg_val, scale_factor; + int ret; + + /* + * 3.3 ms per code is the scale factor of the TIME_ACT register for + * ODR = 6400 Hz. It is 6.6 ms per code for ODR = 3200 Hz and below. + */ + if (st->odr == ADXL372_ODR_6400HZ) + scale_factor = 3300; + else + scale_factor = 6600; + + reg_val = DIV_ROUND_CLOSEST(act_time_ms * 1000, scale_factor); + + /* TIME_ACT register is 8 bits wide */ + if (reg_val > 0xFF) + reg_val = 0xFF; + + ret = regmap_write(st->regmap, ADXL372_TIME_ACT, reg_val); + if (ret < 0) + return ret; + + st->act_time_ms = act_time_ms; + + return ret; +} + +static int adxl372_set_inactivity_time_ms(struct adxl372_state *st, + unsigned int inact_time_ms) +{ + unsigned int reg_val_h, reg_val_l, res, scale_factor; + int ret; + + /* + * 13 ms per code is the scale factor of the TIME_INACT register for + * ODR = 6400 Hz. It is 26 ms per code for ODR = 3200 Hz and below. + */ + if (st->odr == ADXL372_ODR_6400HZ) + scale_factor = 13; + else + scale_factor = 26; + + res = DIV_ROUND_CLOSEST(inact_time_ms, scale_factor); + reg_val_h = (res >> 8) & 0xFF; + reg_val_l = res & 0xFF; + + ret = regmap_write(st->regmap, ADXL372_TIME_INACT_H, reg_val_h); + if (ret < 0) + return ret; + + ret = regmap_write(st->regmap, ADXL372_TIME_INACT_L, reg_val_l); + if (ret < 0) + return ret; + + st->inact_time_ms = inact_time_ms; + + return ret; +} + +static int adxl372_setup(struct adxl372_state *st) +{ + unsigned int regval; + int ret; + + ret = regmap_read(st->regmap, ADXL372_DEVID, ®val); + if (ret < 0) + return ret; + + if (regval != ADXL372_DEVID_VAL) { + dev_err(&st->spi->dev, "Invalid chip id %x\n", regval); + return -ENODEV; + } + + ret = adxl372_set_op_mode(st, ADXL372_STANDBY); + if (ret < 0) + return ret; + + /* Set threshold for activity detection to 1g */ + ret = adxl372_set_activity_threshold(st, ADXL372_ACTIVITY, + true, true, 1000); + if (ret < 0) + return ret; + + /* Set threshold for inactivity detection to 100mg */ + ret = adxl372_set_activity_threshold(st, ADXL372_INACTIVITY, + true, true, 100); + if (ret < 0) + return ret; + + /* Set activity processing in Looped mode */ + ret = adxl372_set_act_proc_mode(st, ADXL372_LOOPED); + if (ret < 0) + return ret; + + ret = adxl372_set_odr(st, ADXL372_ODR_6400HZ); + if (ret < 0) + return ret; + + ret = adxl372_set_bandwidth(st, ADXL372_BW_3200HZ); + if (ret < 0) + return ret; + + /* Set activity timer to 1ms */ + ret = adxl372_set_activity_time_ms(st, 1); + if (ret < 0) + return ret; + + /* Set inactivity timer to 10s */ + ret = adxl372_set_inactivity_time_ms(st, 10000); + if (ret < 0) + return ret; + + /* Set the mode of operation to full bandwidth measurement mode */ + return adxl372_set_op_mode(st, ADXL372_FULL_BW_MEASUREMENT); +} + +static int adxl372_reg_access(struct iio_dev *indio_dev, + unsigned int reg, + unsigned int writeval, + unsigned int *readval) +{ + struct adxl372_state *st = iio_priv(indio_dev); + + if (readval) + return regmap_read(st->regmap, reg, readval); + else + return regmap_write(st->regmap, reg, writeval); +} + +static int adxl372_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long info) +{ + struct adxl372_state *st = iio_priv(indio_dev); + int ret; + + switch (info) { + case IIO_CHAN_INFO_RAW: + ret = adxl372_read_axis(st, chan->address); + if (ret < 0) + return ret; + + *val = sign_extend32(ret >> chan->scan_type.shift, + chan->scan_type.realbits - 1); + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 0; + *val2 = ADXL372_USCALE; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static const struct iio_info adxl372_info = { + .read_raw = adxl372_read_raw, + .debugfs_reg_access = &adxl372_reg_access, +}; + +static const struct regmap_config adxl372_spi_regmap_config = { + .reg_bits = 7, + .pad_bits = 1, + .val_bits = 8, + .read_flag_mask = BIT(0), +}; + +static int adxl372_probe(struct spi_device *spi) +{ + struct iio_dev *indio_dev; + struct adxl372_state *st; + struct regmap *regmap; + int ret; + + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); + if (!indio_dev) + return -ENOMEM; + + st = iio_priv(indio_dev); + spi_set_drvdata(spi, indio_dev); + + st->spi = spi; + + regmap = devm_regmap_init_spi(spi, &adxl372_spi_regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + st->regmap = regmap; + + indio_dev->channels = adxl372_channels; + indio_dev->num_channels = ARRAY_SIZE(adxl372_channels); + indio_dev->dev.parent = &spi->dev; + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->info = &adxl372_info; + indio_dev->modes = INDIO_DIRECT_MODE; + + ret = adxl372_setup(st); + if (ret < 0) { + dev_err(&st->spi->dev, "ADXL372 setup failed\n"); + return ret; + } + + return devm_iio_device_register(&st->spi->dev, indio_dev); +} + +static const struct spi_device_id adxl372_id[] = { + { "adxl372", 0 }, + {} +}; +MODULE_DEVICE_TABLE(spi, adxl372_id); + +static struct spi_driver adxl372_driver = { + .driver = { + .name = KBUILD_MODNAME, + }, + .probe = adxl372_probe, + .id_table = adxl372_id, +}; + +module_spi_driver(adxl372_driver); + +MODULE_AUTHOR("Stefan Popa "); +MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer driver"); +MODULE_LICENSE("GPL v2"); -- 2.7.4