From patchwork Wed Aug 1 15:13:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10552451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 926AA14E2 for ; Wed, 1 Aug 2018 15:16:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 816EE2B5AF for ; Wed, 1 Aug 2018 15:16:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74D652B703; Wed, 1 Aug 2018 15:16:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31A062B5AF for ; Wed, 1 Aug 2018 15:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389624AbeHARCg (ORCPT ); Wed, 1 Aug 2018 13:02:36 -0400 Received: from mail-eopbgr720075.outbound.protection.outlook.com ([40.107.72.75]:7534 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389611AbeHARCg (ORCPT ); Wed, 1 Aug 2018 13:02:36 -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=b0gOs1M+jaMcwdqRG66aDm8PULJNXXCDus60/EOExHc=; b=R62HRvKcN3mM4vCTIeDRdxsrOks8I0kUx3W9xfvfjfcfAa4Kex/an3zMaxzJewHrChagvVStfRtCcIJhqC7aTg/P4ZdOqzuqvYaMdl+VKkn6BlsT4oVYPfwnPJywAmEDvWrVwaA4RiayyydchItHglfEt3mNTt0ynClKb/hMxcg= Received: from BLUPR0301CA0018.namprd03.prod.outlook.com (2a01:111:e400:5259::28) by DM2PR03MB557.namprd03.prod.outlook.com (2a01:111:e400:241b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.21; Wed, 1 Aug 2018 15:14:16 +0000 Received: from BY2FFO11FD014.protection.gbl (2a01:111:f400:7c0c::122) by BLUPR0301CA0018.outlook.office365.com (2a01:111:e400:5259::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:14:16 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) 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.57 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.57; helo=nwd2mta4.analog.com; Received: from nwd2mta4.analog.com (137.71.25.57) by BY2FFO11FD014.mail.protection.outlook.com (10.1.14.76) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:14:15 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta4.analog.com (8.13.8/8.13.8) with ESMTP id w71FEEe0013762 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 1 Aug 2018 08:14:14 -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; Wed, 1 Aug 2018 11:14:12 -0400 From: Stefan Popa To: CC: , , , , , , , , , , Subject: [PATCH v2 1/6] iio: adxl372: New driver for Analog Devices ADXL372 Accelerometer Date: Wed, 1 Aug 2018 18:13:09 +0300 Message-ID: <1533136389-31600-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39850400004)(346002)(376002)(136003)(396003)(2980300002)(438002)(189003)(199004)(316002)(16586007)(50226002)(106466001)(106002)(47776003)(53416004)(2351001)(54906003)(1720100001)(4326008)(7696005)(8936002)(2906002)(126002)(44832011)(426003)(486006)(8676002)(356003)(14444005)(476003)(478600001)(305945005)(966005)(7636002)(72206003)(246002)(51416003)(107886003)(50466002)(26005)(6916009)(6666003)(77096007)(36756003)(186003)(6306002)(7416002)(5660300001)(2616005)(336012)(48376002)(575784001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR03MB557;H:nwd2mta4.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD014;1:KDU1mYw//bDTZ9f4ZVC8ihwoCYPcgbNbV70z7Zeq3BVNZ5v2KzUO11/wbimzmE2kMYCx27bWtXDdvcKFHk4a/8BmnJbt/XnlEeMOkzeFgJVUtRL51Cka0iAOmzVx/iKg X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0fcc70fd-ea4c-4f70-b2a1-08d5f7c17213 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4608076)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060);SRVR:DM2PR03MB557; X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB557;3:8jqK6mIMceH6Z/BbspDl87SZo5xXnLFVls2ujh3dbOEiFzH0J+4tVelLvR9vld4c/KK9DCYXNpyRIbC1nZbTmrYcJjpOthOe7S0VH1pBT32p40bQVmL04s5I5Ui+kWsZqsglfhkYtj0KYi3VoaRKBQmHZqXhi2w/rDwclJNECWWOgvDfBYJVyLKI6uAe5ygKOSJdqx2TVQ9A2JTHwZ6EicgIrZgTQeqLycR1W/9nKMbyR44FG0fMBW1IIjFE61JW0+wvNKmkJ8dZMtKez+DYCBHS+k4uL/cTpkiWjFzGty8ZEKimtRYF4iHHghY1dxc09A1vuUk5muXFB8jnSrv5oElcPoLR6CXx6VX8/ixo1bA=;25:kqhTzaz6cH9Qo2NMWRSzf5x7ce/EHXMYrCebn/Ys8oB5tpdOFqFK851rsnJCzv5zE2FOTjl3j8LwNhrOLSBs4leVAYea75rJVlF5LfQ6a+nBb94enQZrCjl38WWc148NBYuk3hx98sp80j9lvIha5bjtgue3Qj8J4Zr2Sq2H/PZejKbwncZBOr3ty8Kmd8H4OsCd1rdk468NZT55126K6RHNybR4OLDQHjamNkZLIfjK8F/Jxa1zmFM+J5QkOy4gCjZJFQ/IHTd+DlFPwSzxXGBzIl6eDmQ5itiJj27ESFQta/wFf2Rt96uXHXn/KY6sPe6AjSC5zw5IfXkFVW4E5Q== X-MS-TrafficTypeDiagnostic: DM2PR03MB557: X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB557;31:vGTboGwdDerDWTukgURJYuGkUj5QwSKjk2ir/MmwWCHjE3v1RdKcS2xeVyrvDRfpQwXDaGtjvmFnNFHkScTCZxdLcfRU5UWjyoMAVmJIgzF7HmM7FT7SZzuZLXaI6BfYRqUpnrcWWeZemmNBSHtpcY7T2Pau9JTDe8GJWXvO9pVsCC71GI5z2Yh9XLzHhMPZmnEg1eL0FjGn9IFsWFqgbGDFEh9ILF/aiJZVkrBVlpU=;20:LY7cXxhfm6V7pPxots8FNXYlyfovfCTkhHOjA9ss6Z3PzAe6Og4KTysJ65vIOhPWReH09c72Ya4ePtzOet/6vbIqKyw0Q5Xuz+I3ClKmq3sEEzpGpl245Cv7CIJncMh7InGlpDx/8BLihcfw9c1y4AyYs9NycwO7v83YX737SsEeVYzcEXbtno7GN8XdtD87WrJ+Nt19ImcxHHSTf/cKFtRh3Jr46MJ948vbzR3zkWERuo5NgqJzQxUN09naC4G2bsrPwarl0AgEar7b8yM4tE9l2yhv0kuFeEGfsNIk5LlTuZbln5HYUJdhJFi85lN2krQENAO7GZkCFIqfAPGxya9JZoqB/g5bOCfnY6dEanlz35VBj0b/sH2of3VM9OASNt4s5QHb7gOgoZ1VchU3Uwdniig4vYaMUb+YN86qBTHum3jjukzP0FtfDel30fL8CPLVa2/rTvbsmb3X9rrDYUAFOwvO19zCZsBlxKG6wMRusOuEhbeSl9vx7G3KLy+g 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)(8121501046)(5005006)(3002001)(93006095)(93004095)(3231311)(944501410)(52105095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:DM2PR03MB557;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB557; X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB557;4:djLCbVJkQsNSui39TLhwsomoxf4vAWdgUb+48XTb9IdjJE28IPmboFR/cw+3LWgGFQokY213PkpHN1vqz4qDH+kdQ98HjEXrDfcBzzCozQtqOEIx54kfSq3QFJar4PTrhTMHmnN3okmrTDcpuL8wP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RCFjkQFBzccOWceNB6G3f0mPoim+/Iw92YCdzcWH49vfK6wdp8nJadllZw1bV5Xzuv4HNuD/m9uhZw1uvdhXFn/7II53NmvqpQ3IV2RniRz1Jwt+fKpwvTT5urs6TTLOsHc1dPX6gXUnH792n9+01D+TfSIBX3mvG1JW6XgNGesewd8xb3LcH05DRZToKWGEw0nsjXjXSbCzDX5U/LkNSgkXUJiYflmA==;5:+0q3nmXClNXkqmfvU7cTdt4A8E+P9VmlJl/VvGCa9t++lC20JTDel8Zg9cSCeF85rtjDBILxs6lfbuXZxPq6vmudFNMIGWZnZKfrTfzpLAi7AwyYaOJP53dW9aE9vbUjjZKQCStJrrAzg17nP+n2XcsZA7S7j3H4JvoDe85inKE=;7:J8l1O/2KD69pmvD0GZHxzQd/V7KxolUGqbthdSG0IinmnHPvSf6z6+oZEb26F1zg4THj/5qpn2sn4AKwVPrFSwAjGrKyyGuv4qyWFm66VyCfjgSXdQ9zaJSNZhCqpWmZ4c6802zKOplLHF8BgVtFp/dnICH8UdLTAPrBloE4DZ5vjgDxOOL5nD72yf2+PKI0+uxxxvnGrqQCtFhuld1rG0ptIFySXL4WqR+vendNsc9xhczGJ/rJVSWxPrhpAKzW SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 15:14:15.4514 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0fcc70fd-ea4c-4f70-b2a1-08d5f7c17213 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.57];Helo=[nwd2mta4.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB557 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Changes in v2: - removed ADXL372_RD_FLAG_MSK and ADXL372_WR_FLAG_MSK macros. - handled regmap read/write by setting reg_bits and pad_bits fields in regmap_config struct. - removed the buffer specifications when defining the channels. - changed the activity and inactivity thresholds. - added two new functions for setting the activity and inactivity timers: adxl372_set_inactivity_time_ms() and adxl372_set_activity_time_ms(). 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"); From patchwork Wed Aug 1 15:16:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10552453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 369B914E2 for ; Wed, 1 Aug 2018 15:17:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2697B2B6FC for ; Wed, 1 Aug 2018 15:17:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19F832B708; Wed, 1 Aug 2018 15:17:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D45E2B6FC for ; Wed, 1 Aug 2018 15:17:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389728AbeHARDF (ORCPT ); Wed, 1 Aug 2018 13:03:05 -0400 Received: from mail-eopbgr690075.outbound.protection.outlook.com ([40.107.69.75]:35941 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389452AbeHARDF (ORCPT ); Wed, 1 Aug 2018 13:03:05 -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=4ADO+wGmqtpTyoSSLEgGSM4alBR7rWDCkLI0UX7UU1s=; b=cAKHj6c2mDyyrsE1ETYsN6iRtR5Os0N30bQrCktXM7pM/KlklxqDR0ViHfS5hpMbdGtZO2U/N8Wdw0MZwwiowonp8Jq0fR9fKTg+TlPRcm5s6V5M7Vw5Cjl2ncWbW01iYD9g+xIxImI9MMfOkdkrKxJXzq7z8+EXBH532i6Rr7A= Received: from BN3PR03CA0069.namprd03.prod.outlook.com (2a01:111:e400:7a4d::29) by DM2PR03MB560.namprd03.prod.outlook.com (2a01:111:e400:241c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.19; Wed, 1 Aug 2018 15:16:51 +0000 Received: from BN1BFFO11FD014.protection.gbl (2a01:111:f400:7c10::1:165) by BN3PR03CA0069.outlook.office365.com (2a01:111:e400:7a4d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:16:50 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; pmeerw.net; dkim=none (message not signed) header.d=none;pmeerw.net; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.57 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.57; helo=nwd2mta4.analog.com; Received: from nwd2mta4.analog.com (137.71.25.57) by BN1BFFO11FD014.mail.protection.outlook.com (10.58.144.77) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:16:50 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta4.analog.com (8.13.8/8.13.8) with ESMTP id w71FGniT015023 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 1 Aug 2018 08:16:49 -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; Wed, 1 Aug 2018 11:16:49 -0400 From: Stefan Popa To: CC: , , , , , , , , , , , , , Subject: [PATCH v2 2/6] dt-bindings: iio: accel: Add docs for ADXL372 Date: Wed, 1 Aug 2018 18:16:39 +0300 Message-ID: <1533136599-31714-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(136003)(396003)(346002)(39850400004)(376002)(2980300002)(438002)(199004)(189003)(7636002)(44832011)(54906003)(47776003)(2351001)(7416002)(356003)(106002)(106466001)(53416004)(426003)(316002)(8676002)(305945005)(186003)(2906002)(478600001)(966005)(6306002)(5660300001)(16586007)(72206003)(6916009)(126002)(51416003)(4326008)(486006)(48376002)(8936002)(2616005)(246002)(36756003)(26005)(476003)(50466002)(50226002)(77096007)(336012)(7696005)(6666003)(1720100001)(107886003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR03MB560;H:nwd2mta4.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD014;1:bwPoI0mQPieGqx9XJ0CsSRnFqFW5P7N2dKVjL1UF2iuzd7PYV2Pcj46cTMUJqyKjnEr9GVgh3y8QtLxjyvgcJfu2JxrY6zDfcwNIzNs86cDEw4keDCPICnM2csg6FwPx X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72bb7cc1-6a00-4ceb-61b4-08d5f7c1ce45 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:DM2PR03MB560; X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB560;3:sYt3M0DD6BtjY9xdoFrdkHRP81y0I84kfNVnW0f1fpSgkyTonq94GP9Rr6varVLq25iigRpG4mwv9TixppiscIt0De8zQi8v6JuFJNN6UzajQpzf/izAX7MfninoXIWNAjGJLRivNve1Tr7piFYfGM+WqplAjQhWSBW8BtkR5bhMyWMwGB3R2uo46fZYnGbGcUuYp2yNkO/6u473Qg2lQIQHJb32ianH3qNXwELcqOnJgs3cyYgYE5N5iAnnyyuTbDRGZsFe0AKfSEpu8hy5OykjfYPECKy215A3jvS+EzN0kn/fjtDTM9VxyYcjFy/OFYQVOF3055oDHTmaahtPI/W4gaew0hfnw2ws/byPXtU=;25:HOjffC1etOz09Pfi+9w5MccFkofIJdvPzsr+gbBSTucBFOO/50wwiLkGPvDHHGY5Dq2z8t+Juzwq3sukT1eEOijtnpgaG43frWFp39eIPlMTH4LTcH720yYIL4R7i4LJiioNejyX26AubIJ4kcy6Ezkute/kt7Cb2Yj266seI+FRUYlPyqKW9pTnTqDhdU7tPEo8Awxc9UidYN8S0ZJ8Bws1B/L3HO2qr1mdDJrhwaZLsSJTrHVYUa9GyKglo4wwBaZl5xLKWpKEyQkM0hzWXYcKfF0IRLkkKClw6HaoyYTCLYwV09AeAs26YkHw/fLO13U/MovoT3Jbqg76gogwmQ== X-MS-TrafficTypeDiagnostic: DM2PR03MB560: X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB560;31:uETkFTa2SiMw5Vo3qEgeE6zerYzfuv43jbwo9pFFZ3D74JBhPzcKpxY0Xt0GD5yJjkzTKLKsvr3a8+Px3eCCq1RCbvqaXZWI7h2NLFQgADzxJZ9DmBsIO4m6jogTfAgVaLvR2H4PXCaQ6YJ4pu2TaBdgkfBzVEF/PugTV2UY4M0hJs9VPKu5hmtHfaIAGg7a80QUTwTjA/RbKC50GjeK/Zp4YbN6S+DO9DRs7MVldjs=;20:ykfROR0oKJKwhTHYcQC35B9KOcT219lSmyDmuboE+J7haGfzFSYZPIABKRB4H9iLukmzO3o2GhDpJQ3dsZPSIjyXjkplZRttFC+adyXSfBhLEhHT9zrvAZewHtvvpAm4Cr0LFbw3s+i9Ry7dhdWE0tNTXGyOTJ2odI7xwVwGyRnqxw3PPuXQTwiLjzI/Q24FsiTNw+LFDMs+O3WwlWYYeDx8rHci0p554FvVa4QvS70KsJmRJa2s5RwqczoDWIgTRCuJ9PpCKErVQBWiSTLSesKGJ1agE4SZMkVGlykoZCf32zQ2HGAD8XcZQM9Tawawo39hLsSMC6soSnNkg62aQg6xsgRw4VmJMxE6rRNyqX6V3TXstzI+hMzkH3zZxjlQcjk/gTXg3Tjr/j0OjwLkNg/gAIITyvg48vNweShRspwLJQrv6Ago5/U3p98tIcXJWdjvQiF7HArDZAyEta3OAhBNlcQ5q3jlU9ZSDO+rKxsxrjVPtxnbgV7N0kB/W/5M X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(270121546159015)(232431446821674)(170811661138872); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231311)(944501410)(52105095)(3002001)(93006095)(93004095)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:DM2PR03MB560;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB560; X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB560;4:d82JMuDzmhmNkivEACMtXQAw+ZPSduVcbT9AqSRT8GtPQLSzAA1DHJuW0KdlsaPQxSr0sAbVYbEuQ5BhE/J5UPRTOUoC6sJUMtsxEo3VK0G5HInL5vRLXIJrujEzljUPe1GpKKMHoqXDqnHyIRXxsG9HgKWG1fUfQsOIVhcAJrvzGtHvD32ki+s5g/9yQ+iKsQ35MWs+b39zo7LBhSwf5cCVHvPZ0HGfMBSvHEOt95tXtElpCuF8/NpurDvr4Ztzvvt/k4ZbOIOmnc/8pRHGizLQn9CZ/0OMXiHU2wnh0keIjHSNm3UhuQAe+mhhh79uOafbegnokxg//pW0kEvBXptHx7L0b1MxGDq8CzWisV80YuTyWFEFl73eTG3CF5ye X-Forefront-PRVS: 0751474A44 X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB560;23:c9kzRdNU1yqWevP9iOh6H0+Z/dRhl7Zm+6FuhfhHvSku323s8DwJTetO1f/JyuB8puMb8g4a8oYosusCSEfq95+Ey9eUqI2fyBJ3halfi7EQ8MtXDTEgmFqgZWrqFVVnyq2FG+efUehAFMWrxo+sz5PjOmtgWhQsUpb9uC9+QJ+qzaKNus27zIr0Q2hRbibDY2ZOuAuJaL4XLMZ7UFGIwsiaoBcMJseLxA/OY3gEclfWHXzWm1h40HXiF8RmvleXZsyk3+a6f7E/6qOS1WhLjwxx5UG8K6HJr+NhQccvaHXhTuhmYuP3hARV0ZCGVNNxCe6JpsOhEeNLy0LGe0hAP86gAN9qbQRIWi/jcA7UrT62utkgyrM7FdxbvK/2D1FNYtdUWIRJIbznhi8KLtCLRUp9xTor5qq+C5oW1AliygVcVJQakVUyOMe8KFZLJQS2b1GO17Zen5CU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;6:Qnrk0vAtEudfNOv20Q5795QcRcMA1RWPOZuSp1eaclNcsSxYhDBLfl/FV1SDhlzA4txBxCO5T75N1Nxpvp3CFd7XIgI/OV6+X2MODTnl5LMlQdij0rWcOWvc3/0tFQu+vFGdqea1NdWXUzfJyJJ3qXyJwyBBEBVR5lrPfCj6h4c0cIEne6KF9uAn68T/btRkgD75Ih5k0LZYtFmQgXouoRp3o4xyk5Ylkofo880OvOAFYBIWlsR36oYclXeVWe2JCTCzr4c1Qm9Z0Lxql8ejjn//e0IdbAvDHBi7I3b8uY+RbvDhafowYPz6EPfqmxJWnv+bYE1cLGgcvEbTxeGpbHBI9+UtE603f91O0j+3fytH/3Dk3w/JLUH7EarzwAfJSdDWTQz9LwkuiB7TWyphAShNdQ/5OctdKGnSE7aWK/j29CO8gaBzqbKT7YdKmQhrhZCG3oic97S9dneNEQcajw==;5:i7ngaXF2ppTV8iyCg/DgYyLbpEoL/2S8wZ6JC7AoSYKuP8srLgaFwzLkaiG1Sl3Ci6y/qZFwkuDUBgu4usWe9j6zrc1LR6Vc1iptFCkMXFGrOUJw6igOMbWosHaVPkc70BPEg9EX1E/BRrIn1xV33qv+w8gbyoHRGBJz+2cFU/U=;7:vcvd3ugPAqoLCnE6TKjiOwe3DTa2rTgdPdqt3zpxH+Ci58305tpX6TtxhAlkaG+isbUPX7iwS8RbCHNs5wSeInuDV/jwt+4MDxn0s0vvif2iA4ftfS9tbz8az4WN4/yErPl7wmW6dXHCaVDthD2O1ukPfr6Yl2tly5E82IxUk1HhTfQb2dx5RT3TrSGAfsrKeMr8m2wcrli/eqcvfm65huEVyBBk2/ZNYj3hwRDmvNcO3yoGul6HnHvjLOjKm33g SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 15:16:50.2476 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72bb7cc1-6a00-4ceb-61b4-08d5f7c1ce45 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.57];Helo=[nwd2mta4.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB560 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the device tree binding documentation for the ADXL372 3-axis digital accelerometer. Signed-off-by: Stefan Popa --- Changes in v2: - introduced all the DT bindings in a single patch. .../devicetree/bindings/iio/accel/adxl372.txt | 24 ++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/accel/adxl372.txt diff --git a/Documentation/devicetree/bindings/iio/accel/adxl372.txt b/Documentation/devicetree/bindings/iio/accel/adxl372.txt new file mode 100644 index 0000000..41493d9 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/accel/adxl372.txt @@ -0,0 +1,24 @@ +Analog Devices ADXL372 3-Axis, +/-(200g) Digital Accelerometer + +http://www.analog.com/media/en/technical-documentation/data-sheets/adxl372.pdf + +Required properties: + - compatible : should be "adi,adxl372" + - reg: SPI chip select number for the device + - spi-max-frequency: Max SPI frequency to use + +Optional properties: + - interrupt-parent : phandle to the parent interrupt controller as documented + in Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + - interrupts: interrupt mapping for IRQ as documented in + Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + +Example: + + accelerometer@0 { + compatible = "adi,adxl372"; + reg = <0>; + spi-max-frequency = <1000000>; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_EDGE_FALLING>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 2ba47bb..c8dd09c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -548,6 +548,7 @@ M: Stefan Popa W: http://ez.analog.com/community/linux-device-drivers S: Supported F: drivers/iio/accel/adxl372.c +F: Documentation/devicetree/bindings/iio/accel/adxl372.txt AF9013 MEDIA DRIVER M: Antti Palosaari From patchwork Wed Aug 1 15:17:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10552475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12D4714E2 for ; Wed, 1 Aug 2018 15:18:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1C8B2B5BE for ; Wed, 1 Aug 2018 15:18:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2CF72B5D2; Wed, 1 Aug 2018 15:18:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B2702B5BE for ; Wed, 1 Aug 2018 15:18:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389673AbeHAREY (ORCPT ); Wed, 1 Aug 2018 13:04:24 -0400 Received: from mail-eopbgr730075.outbound.protection.outlook.com ([40.107.73.75]:62784 "EHLO NAM05-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389656AbeHAREY (ORCPT ); Wed, 1 Aug 2018 13:04:24 -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=QCPYu6/JS4dQKY7tRxohA7+LD5h0U2GXJW9boTFGuGY=; b=KiKS0WIa3bvEBqehZb+X9HZ/EC9NZYkKCts8QXMqlYhgVcpENIWS4+VjgtN9l3x79+J+VJG4qk62y0rAzHFE2vZ0KHsxk7OJyVtiTtJz0GewU/S3DWoUsP5DfRYJuUbOCJHxCc+EMkKW7gt3w4Gh/1oAuOE0E9RPp9Ii4dHKD4A= Received: from BYAPR03CA0007.namprd03.prod.outlook.com (2603:10b6:a02:a8::20) by BLUPR03MB552.namprd03.prod.outlook.com (2a01:111:e400:883::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.19; Wed, 1 Aug 2018 15:18:07 +0000 Received: from BL2FFO11FD005.protection.gbl (2a01:111:f400:7c09::191) by BYAPR03CA0007.outlook.office365.com (2603:10b6:a02:a8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1017.14 via Frontend Transport; Wed, 1 Aug 2018 15:18:06 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.57 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.57; helo=nwd2mta4.analog.com; Received: from nwd2mta4.analog.com (137.71.25.57) by BL2FFO11FD005.mail.protection.outlook.com (10.173.161.1) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:18:05 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta4.analog.com (8.13.8/8.13.8) with ESMTP id w71FI561015489 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 1 Aug 2018 08:18:05 -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; Wed, 1 Aug 2018 11:18:05 -0400 From: Stefan Popa To: , CC: , , , , Crestez Dan Leonard Subject: [PATCH v2 3/6] regmap: Add regmap_pipe_read API Date: Wed, 1 Aug 2018 18:17:47 +0300 Message-ID: <1533136667-31828-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(376002)(396003)(39860400002)(136003)(346002)(2980300002)(438002)(199004)(189003)(50226002)(7636002)(305945005)(47776003)(77096007)(26005)(186003)(2906002)(476003)(16586007)(6666003)(316002)(246002)(5660300001)(7696005)(336012)(36756003)(14444005)(106002)(8936002)(51416003)(48376002)(478600001)(50466002)(72206003)(4326008)(126002)(106466001)(8676002)(2616005)(44832011)(426003)(486006)(356003)(54906003)(53416004)(110136005);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR03MB552;H:nwd2mta4.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD005;1:M1d54sCzRsRsk2fVszrqpiNo+SVpGZSTHcS3qeTHBo7IaA1zw6eQ6XaHzvj/v/TK06hiWX6t6q4xEHDGOMhztH5+m273CPAwyOajGjp/scpFzLFACHZ+10ee81M4YkTN X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2abd53a7-9196-47e9-3a4f-08d5f7c1fb4c X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:BLUPR03MB552; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB552;3:xdm4EbzV7Qy30oKO5WQSTTfKeUGODV5wi7FvwvSmH/EToBg1XTQsdQujgId/E/Fd5ZaxGjv5dzFu/zMpJRC+2/604/zW9sgqYtvLbS3LRqrxHPMal/+2H5WPWHuemrvO7eU1ckOLTJNxpU+lUsMFo9EIVpEFToQ6omOjbVOYo3D4rVJQoBeXifkHpUdPhUtks4Mpu0kBwFtD4A7e67aNGQ3XXxUfIQHzK+XpEVzhLpOhZvpwGsg5E5WqOLVE2kczf+fo/dfq46McNPW9aFbJ48u8IF4ZT71vrPPHeUgTfXyTPM8MY6imJKkXkcCjCLemykX11RfjeBMcjC03KMY8Bej/Um9h3sCjuW+sOJLWCzg=;25:LMgaiiH1RNisz/83MGDSXKPipGHyqUUSqnKb99Fgjy9GZBjOCwIGEqUkykzoC3bskYqqFf4I8xNwzAhTYCTUva0dhXpHEOj/6mKMQ2JcKyBZmvSIRse2M8qpnSaWBo6NCe27NQ5EJ94BXLVTowaXabaxkB9dgDBNn+AgmxbKaq8TqoKdc1AZMtESZuSEw0Jrtj1kl5z98Il0cWpVa1rNq0bvlqWtb6rnAi+jgaAvB+Vrr1ggSfX3qplSNSSIh2MpzJlhV9OuzLODuhwJwXBkqBkoye97P9rCu60GjrL7LSBe3VWD6ijsvNaKHh7V8gVPXJV/jEZdjFgJPM4dy5Gyzw== X-MS-TrafficTypeDiagnostic: BLUPR03MB552: X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB552;31:i7EKTL2c5t/86vR0aT48IkVREB4wss7KR59fJpGfd89hv/8kgcCH6IZs+sPiEJ1PEwHE81hBdG5XKbjm7cTddV6nvEK6JwicpTE+aeXrVj+vn12smOO5dWNYHb9p5g+As+0ToHabXtxNramo1mt1+D6+guoyTCT2Me3jJVwvyWkZvcXWrDaUYfK6V6iYVMCieT06PybmI9qLdLTqLuXHasSvBwb5XfH+O+HP3XaXZsc=;20:7w+dEgWui15qcCgNhSODtLM2n2L0m/qXlKMYM7dB3sB9eqKxKltbuEzyZtFZ+OaILWj1yrxsLIDVk+V/05cSwWOEtWGLqysmxRalobRKzbkBrIlWYsfrUBYaVaiqqI/BvsmfOY0fAxGgxodEuOsXEzEglIs0ztv9nyJPx7f0cvehZD3qyIXSoI9AkzSYdkrwrbQHFnyjH34mEN+0xt9Snhops78l2Apew5Eg5jIc4Rn6Oh/vRUImqepY2MExVIJ/nlzTV9tb9qELLr9oYIZc14pOnBhDvPMc5VRp8jkb6aYtQ7OGXaukftyrCJ/loX+IWlEzliel//ffEnmoRZU3T5PFCYsbI8RLW7ROTZiu0HfVhG9HK31Sl1Cl4UZkc1S5AEvCqEldJROj+sJTCN4joKiyegEL8KpwJ6rG3MH/GHtirFkFY0D9KVwxISyS0CPSEKMbtlbjK7nc7f7nD9qj9wxyOXXwcAQVyR7rWJMiif2TObHN9/uBdbzV7CRMXJVq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674)(228905959029699); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93004095)(10201501046)(3231311)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011)(7699016);SRVR:BLUPR03MB552;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB552; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB552;4:O4UCRKO66ICldPD0/fuwXpAt2GdZBA249ziUAIRbQn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Zwat+tMs+fJFpkaaNHMVgzxZx+S7HdSxkAVQ3mAn3CbBicAT1H4M2qmut6jnyWTqDMjXCNedklZvz8kulmqEdjo6arvsraDmAdoxNBEOFJx3DXDXz5HSxmy49ZFFeFg==;5:T34bqhz2iHfwaBq9kjuCi/1tJfUScdkB1E2VD/BvOZoRFmyQA7Uo2rbSOD2pKuTr2VJflhhr+7WiwrStVhFQgnjvtLgsgWQD/3gxFNAhAPKnoVri5vwUhut2zZHb3Wn1WF3c0VpN/DZHmDjuT9+sFB94RdPgRKiYiOsx5cggH0I=;7:UJAlPKHvDjy6R7TGkWtCrP3BnNkuyBtML8B/RwJ6Z/pt3GYrSIwDvvVvxpAt6vzjIv9vm5i3fMV1qmf7Lrkr9UHqVSuPaO5GBAQX2fh+MS1M+Uas4t2SduCiTBG9Q3iV+pBeZIiKIWxAHjB8HLWltRTyTxyW1puHWB9HS0xiVE5s9SgV9/uIyswlRigd4tFJu7j+Qep9e24ozEeSJe6EiXAZjr8+LZXTU2BnSGBPUFSj9TGYP3Vv/cNi5mtfw+4V SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 15:18:05.8525 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2abd53a7-9196-47e9-3a4f-08d5f7c1fb4c 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.57];Helo=[nwd2mta4.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB552 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Crestez Dan Leonard The regmap API usually assumes that bulk read operations will read a range of registers but some I2C/SPI devices have certain registers for which a such a read operation will return data from an internal FIFO instead. Add an explicit API to support bulk read with pipe rather than range semantics. Some linux drivers use regmap_bulk_read or regmap_raw_read for such registers, for example mpu6050 or bmi150 from IIO. This only happens to work because when caching is disabled a single regmap read op will map to a single bus read op (as desired). This breaks if caching is enabled and reg+1 happens to be a cacheable register. Without regmap support refactoring a driver to enable regmap caching requires separate I2C and SPI paths. This is exactly what regmap is supposed to help avoid. Suggested-by: Jonathan Cameron Signed-off-by: Crestez Dan Leonard Signed-off-by: Stefan Popa --- Changes in v2: Included as part of this patch series as the regmap_pipe_read() API will be used to read the data from the FIFO. drivers/base/regmap/regmap.c | 64 +++++++++++++++++++++++++++++++++++++++++++- include/linux/regmap.h | 9 +++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 3bc8488..73bacbd 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2564,7 +2564,69 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, EXPORT_SYMBOL_GPL(regmap_raw_read); /** - * regmap_field_read() - Read a value to a single register field + * regmap_pipe_read(): Read data from a register with pipe semantics + * + * @map: Register map to read from + * @reg: Register to read from + * @val: Pointer to data buffer + * @val_len: Length of output buffer in bytes. + * + * The regmap API usually assumes that bulk bus read operations will read a + * range of registers. Some devices have certain registers for which a read + * operation read will read from an internal FIFO. + * + * The target register must be volatile but registers after it can be + * completely unrelated cacheable registers. + * + * This will attempt multiple reads as required to read val_len bytes. + * + * A value of zero will be returned on success, a negative errno will be + * returned in error cases. + */ +int regmap_pipe_read(struct regmap *map, unsigned int reg, + void *val, size_t val_len) +{ + size_t read_len; + int ret; + + if (!map->bus) + return -EINVAL; + if (!map->bus->read) + return -ENOTSUPP; + if (val_len % map->format.val_bytes) + return -EINVAL; + if (!IS_ALIGNED(reg, map->reg_stride)) + return -EINVAL; + if (val_len == 0) + return -EINVAL; + + map->lock(map->lock_arg); + + if (!regmap_volatile(map, reg)) { + ret = -EINVAL; + goto out_unlock; + } + + while (val_len) { + if (map->max_raw_read && map->max_raw_read < val_len) + read_len = map->max_raw_read; + else + read_len = val_len; + ret = _regmap_raw_read(map, reg, val, read_len); + if (ret) + goto out_unlock; + val = ((u8 *)val) + read_len; + val_len -= read_len; + } + +out_unlock: + map->unlock(map->lock_arg); + return ret; +} +EXPORT_SYMBOL_GPL(regmap_pipe_read); + +/** + * regmap_field_read(): Read a value to a single register field * * @field: Register field to read from * @val: Pointer to store read value diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 4f38068..91c5cb6 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -946,6 +946,8 @@ int regmap_raw_write_async(struct regmap *map, unsigned int reg, int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, size_t val_len); +int regmap_pipe_read(struct regmap *map, unsigned int reg, + void *val, size_t val_len); int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, size_t val_count); int regmap_update_bits_base(struct regmap *map, unsigned int reg, @@ -1196,6 +1198,13 @@ static inline int regmap_raw_read(struct regmap *map, unsigned int reg, return -EINVAL; } +static inline int regmap_pipe_read(struct regmap *map, unsigned int reg, + void *val, size_t val_len) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + static inline int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, size_t val_count) { From patchwork Wed Aug 1 15:18:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10552477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4758114E2 for ; Wed, 1 Aug 2018 15:18:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34CBF2B7A7 for ; Wed, 1 Aug 2018 15:18:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 289EE2B7AC; Wed, 1 Aug 2018 15:18:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18DEC2B7A7 for ; Wed, 1 Aug 2018 15:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389701AbeHARE5 (ORCPT ); Wed, 1 Aug 2018 13:04:57 -0400 Received: from mail-cys01nam02on0049.outbound.protection.outlook.com ([104.47.37.49]:30402 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389656AbeHARE4 (ORCPT ); Wed, 1 Aug 2018 13:04:56 -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=ZtIMqf2td3NL077TAinUxlTufFvgz44gLQ2PR+qTjmQ=; b=DDoGPh1TehbjKPh7yZCL5GL29JTUotrc2AdXNn6KFr/IcAiFfYjDbxNg+VNw76DP7TEuvVJ7WW+YsBlaaQIhUeLuVwWvf2XzyUMMVX2wZFVf3xKxfMbwg9OLqO8JWm761Pf+eLwX2YZQxCTBVQk3vZ5iWebRtl4J3Tj16CvZAiQ= Received: from BN3PR03CA0104.namprd03.prod.outlook.com (2603:10b6:400:4::22) by BY2PR03MB555.namprd03.prod.outlook.com (2a01:111:e400:2c37::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.15; Wed, 1 Aug 2018 15:18:26 +0000 Received: from BL2FFO11FD013.protection.gbl (2a01:111:f400:7c09::193) by BN3PR03CA0104.outlook.office365.com (2603:10b6:400:4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1017.14 via Frontend Transport; Wed, 1 Aug 2018 15:18:25 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.57) smtp.mailfrom=analog.com; metafoo.de; dkim=none (message not signed) header.d=none;metafoo.de; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.57 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.57; helo=nwd2mta4.analog.com; Received: from nwd2mta4.analog.com (137.71.25.57) by BL2FFO11FD013.mail.protection.outlook.com (10.173.160.221) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:18:24 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta4.analog.com (8.13.8/8.13.8) with ESMTP id w71FIOIO015639 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK); Wed, 1 Aug 2018 08:18:24 -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; Wed, 1 Aug 2018 11:18:23 -0400 From: Stefan Popa To: CC: , , , , , , Subject: [PATCH v2 4/6] iio:adxl372: Add FIFO and interrupts support Date: Wed, 1 Aug 2018 18:18:12 +0300 Message-ID: <1533136692-31935-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.57;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39860400002)(396003)(346002)(376002)(136003)(2980300002)(438002)(199004)(189003)(316002)(7636002)(44832011)(16586007)(48376002)(426003)(336012)(246002)(50466002)(305945005)(486006)(2616005)(476003)(126002)(53416004)(8936002)(72206003)(5660300001)(478600001)(6916009)(50226002)(6666003)(8676002)(2351001)(77096007)(26005)(106466001)(47776003)(2906002)(186003)(36756003)(54906003)(14444005)(4326008)(107886003)(106002)(7696005)(51416003)(356003)(334744003);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR03MB555;H:nwd2mta4.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail11.analog.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD013;1:MSAsmGfC6pqACY7lKGurCf4lkXrRmHOV3cY2R2jWCRfz6xoJqcVOTQRhCiWppJ+1Ulh7+WkaZcFr4rDEhuxdsGU3pPnTAfn1MJ4OatdwOxbjDgq6NL8gvTqYAeZs78+D X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6a8506dc-0429-4641-ac44-08d5f7c206b2 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:BY2PR03MB555; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB555;3:8kiH/pvUxLwXvFtWAlr03nzyETEEhVsCE7EqiuoLORTdpfZrV8MATmEzXe1bVfdQgA0/RAA8cHOzXBCdhbnOC0QRzNFcXtf0499iq1GEcLH4C43i4BF0fw+K6ksT5GwwVNVRBH9V8aydOP4HB5nlIa/S7wU/CBHtnnFfYmrGsh/xZe8K9SrpE/s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/JS7/7wIG2fCJdPY9+bFtx5CX7NihtD2GtzvQtRxifCxMaHusIekuvl3I2FmFEo56lgw9ktYliQRSM7sQkQ1yRHSH3BPBqorQhNYBMPa2XZp0mrsuf1Civ8JESN30qAt+WNA4IgpMuCqg4+GGMvxHLiRxUSK2yRGvC6j5lnHN67+XSkeaF7FwyFWU9y8HfQ7VFoWT8/iD3NPQ3FeznAnQszs53n5p+/n9NtmYy/hg0j7rZO4goPTLX8zTOQEqEq+eD76s6mWC X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(131327999870524)(232431446821674)(17755550239193); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231311)(944501410)(52105095)(93006095)(93004095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:BY2PR03MB555;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB555; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB555;4:xcuQpOMl9zjnQEqqpoAH8cJrYbgj8rMw1KAmfzoJE3BQhsgYw5aSorIc4S60gSFFMyus34LC/PS0AwobyFuoRUsh2jqTRXeNyK5tTCSQ1Rq/3OzavpSJwyFjmCOmKrmVsiI5IjcHcHobP5e7/ca1Tlfk8lOXqYWK5tmJgQs7B1XOBWlvrAmINx3MLX+IZjAICBl37xw07i2/8XnKi0bwk49TPUXyt+rdU/UD5fwenmJWqfZtdT1atvOp2RL4ejTfGmHGG7j+bvuE58TIlOljIYuY0ECzHO+oNQQ29GribxU2rAyNJhTuf/Yj1sHFuoH4aFT62TwQ5/cSNrDI/bolmTismktzJfEMYClW8JbmKV/UHVMceVNEXfdf0GaongqK X-Forefront-PRVS: 0751474A44 X-Microsoft-Exchange-Diagnostics: 1;B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dUKbi4=;7:bq+E1PKZGnUzZcfBVieyvnB/psLoJ3ezeRNte+UWZRj8jOwpv+9nrBz7riaV7ZB6oRFl2yEtNu41eC+pEfawezLmeYZ7F1ZJm1y73dS9N+Utz/LDXss/Kkny82nG2+uW1AeX2v6+jRQpB16K41uAqyj9VuzyTBtcb5hBN8uy/e5sixWhm04TSXoPyTy50hPhscMCLPqururUnLo7ZAIMWkf6VCt1nMpBhudb6KOu696ia5eAutbjgUGS5Lbo/W54 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 15:18:24.9788 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a8506dc-0429-4641-ac44-08d5f7c206b2 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.57];Helo=[nwd2mta4.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB555 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for the adxl372 FIFO. In order to accomplish this, triggered buffers were used. The number of FIFO samples which trigger the watermark interrupt can be configured by using the buffer watermark. The FIFO format is determined by configuring the scan elements for each axis. Moreover, the FIFO can also be configured in the XYZ peak mode. The FIFO data is pushed to the IIO device's buffer. Signed-off-by: Stefan Popa --- Changes in v2: - removed DT bindings changes from this patch. - removed the linux/gpio/consumer.h header. - used regmap_pipe_read() instead of regmap_bulk_read() when reading data from the FIFO. - used multiple regmap_write() calls instead of a single regmap_bulk_write() if there is no fast path. - used be32_to_cpu() inside the adxl372_get_status() function. - added a new in_accel_x&y&z_peak scan element which allows the user to set the FIFO into XYZ peak mode. - used a adxl372_axis_lookup_table() to determine the fifo format from the active_scan_mask. - made IRQ optional. drivers/iio/accel/adxl372.c | 362 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 361 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c index 7d5092d..68862bf 100644 --- a/drivers/iio/accel/adxl372.c +++ b/drivers/iio/accel/adxl372.c @@ -6,12 +6,19 @@ */ #include +#include +#include #include #include #include #include #include +#include +#include +#include +#include +#include /* ADXL372 registers definition */ #define ADXL372_DEVID 0x00 @@ -123,6 +130,8 @@ #define ADXL372_INT1_MAP_LOW_MSK BIT(7) #define ADXL372_INT1_MAP_LOW_MODE(x) (((x) & 0x1) << 7) +#define ADXL372_FIFO_SIZE 512 + /* * At +/- 200g with 12-bit resolution, scale is computed as: * (200 + 200) * 9.81 / (2^12 - 1) = 0.958241 @@ -164,6 +173,44 @@ enum adxl372_bandwidth { ADXL372_BW_3200HZ, }; +enum adxl372_fifo_format { + ADXL372_XYZ_FIFO, + ADXL372_X_FIFO, + ADXL372_Y_FIFO, + ADXL372_XY_FIFO, + ADXL372_Z_FIFO, + ADXL372_XZ_FIFO, + ADXL372_YZ_FIFO, + ADXL372_XYZ_PEAK_FIFO, +}; + +enum adxl372_fifo_mode { + ADXL372_FIFO_BYPASSED, + ADXL372_FIFO_STREAMED, + ADXL372_FIFO_TRIGGERED, + ADXL372_FIFO_OLD_SAVED +}; + +static const int adxl372_samp_freq_tbl[5] = { + 400, 800, 1600, 3200, 6400, +}; + +struct adxl372_axis_lookup { + unsigned int bits; + enum adxl372_fifo_format fifo_format; +}; + +static const struct adxl372_axis_lookup adxl372_axis_lookup_table[] = { + { BIT(0), ADXL372_X_FIFO }, + { BIT(1), ADXL372_Y_FIFO }, + { BIT(2), ADXL372_Z_FIFO }, + { BIT(0) | BIT(1), ADXL372_XY_FIFO }, + { BIT(0) | BIT(2), ADXL372_XZ_FIFO }, + { BIT(1) | BIT(2), ADXL372_YZ_FIFO }, + { BIT(0) | BIT(1) | BIT(2), ADXL372_XYZ_FIFO }, + { BIT(3), ADXL372_XYZ_PEAK_FIFO } +}; + #define ADXL372_ACCEL_CHANNEL(index, reg, axis) { \ .type = IIO_ACCEL, \ .address = reg, \ @@ -171,25 +218,69 @@ enum adxl372_bandwidth { .channel2 = IIO_MOD_##axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 12, \ + .storagebits = 16, \ + .shift = 4, \ + }, \ } 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), + { + .type = IIO_ACCEL, + .modified = 1, + .channel2 = IIO_MOD_X_AND_Y_AND_Z, + .extend_name = "peak", + .scan_index = 3, + .scan_type = { + .sign = 's', + .realbits = 12, + .storagebits = 16, + .shift = 4, + } + } }; struct adxl372_state { struct spi_device *spi; struct regmap *regmap; + struct iio_trigger *dready_trig; + enum adxl372_fifo_mode fifo_mode; + enum adxl372_fifo_format fifo_format; 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; + u8 fifo_set_size; + u8 int1_bitmask; + u8 int2_bitmask; + u16 watermark; + __be16 fifo_buf[512]; +}; + +static const unsigned long adxl372_channel_masks[] = { + BIT(0), BIT(1), BIT(2), + BIT(0) | BIT(1), + BIT(0) | BIT(2), + BIT(1) | BIT(2), + BIT(0) | BIT(1) | BIT(2), + BIT(3), + 0 }; +static int adxl372_read_fifo(struct adxl372_state *st, u16 fifo_entries) +{ + return regmap_pipe_read(st->regmap, ADXL372_FIFO_DATA, + st->fifo_buf, fifo_entries * 2); +} + static int adxl372_read_axis(struct adxl372_state *st, u8 addr) { __be16 regval; @@ -364,6 +455,107 @@ static int adxl372_set_inactivity_time_ms(struct adxl372_state *st, return ret; } +static int adxl372_set_interrupts(struct adxl372_state *st, + unsigned char int1_bitmask, + unsigned char int2_bitmask) +{ + int ret; + + ret = regmap_write(st->regmap, ADXL372_INT1_MAP, int1_bitmask); + if (ret < 0) + return ret; + + return regmap_write(st->regmap, ADXL372_INT2_MAP, int2_bitmask); +} + +static int adxl372_configure_fifo(struct adxl372_state *st) +{ + unsigned int fifo_samples, fifo_ctl; + int ret; + + /* FIFO must be configured while in standby mode */ + ret = adxl372_set_op_mode(st, ADXL372_STANDBY); + if (ret < 0) + return ret; + + fifo_samples = st->watermark & 0xFF; + fifo_ctl = ADXL372_FIFO_CTL_FORMAT_MODE(st->fifo_format) | + ADXL372_FIFO_CTL_MODE_MODE(st->fifo_mode) | + ADXL372_FIFO_CTL_SAMPLES_MODE(st->watermark); + + ret = regmap_write(st->regmap, ADXL372_FIFO_SAMPLES, fifo_samples); + if (ret < 0) + return ret; + + ret = regmap_write(st->regmap, ADXL372_FIFO_CTL, fifo_ctl); + if (ret < 0) + return ret; + + return adxl372_set_op_mode(st, ADXL372_FULL_BW_MEASUREMENT); +} + +static int adxl372_get_status(struct adxl372_state *st, + u8 *status1, u8 *status2, + u16 *fifo_entries) +{ + __be32 buf; + u32 val; + int ret; + + /* STATUS, STATUS2, FIFO_ENTRIES2 and FIFO_ENTRIES are adjacent regs */ + ret = regmap_bulk_read(st->regmap, ADXL372_STATUS_1, + &buf, sizeof(buf)); + if (ret < 0) + return ret; + + val = be32_to_cpu(buf); + + *status1 = val >> 24; + *status2 = val >> 16; + /* + * FIFO_ENTRIES contains the least significant byte, and FIFO_ENTRIES2 + * contains the two most significant bits + */ + *fifo_entries = val & 0x3FF; + + return ret; +} + +static irqreturn_t adxl372_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct adxl372_state *st = iio_priv(indio_dev); + u8 status1, status2; + u16 fifo_entries, i; + int ret; + + ret = adxl372_get_status(st, &status1, &status2, &fifo_entries); + if (ret < 0) + goto err; + + if ((st->fifo_mode != ADXL372_FIFO_BYPASSED) && + (ADXL372_STATUS_1_FIFO_FULL(status1))) { + /* + * When reading data from multiple axes from the FIFO, + * to ensure that data is not overwritten and stored out + * of order at least one sample set must be left in the + * FIFO after every read. + */ + fifo_entries -= st->fifo_set_size; + + ret = adxl372_read_fifo(st, fifo_entries); + if (ret < 0) + goto err; + + for (i = 0; i < fifo_entries * 2; i += st->fifo_set_size * 2) + iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); + } +err: + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} + static int adxl372_setup(struct adxl372_state *st) { unsigned int regval; @@ -443,7 +635,12 @@ static int adxl372_read_raw(struct iio_dev *indio_dev, switch (info) { case IIO_CHAN_INFO_RAW: + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + ret = adxl372_read_axis(st, chan->address); + iio_device_release_direct_mode(indio_dev); if (ret < 0) return ret; @@ -459,9 +656,136 @@ static int adxl372_read_raw(struct iio_dev *indio_dev, } } +static ssize_t adxl372_get_fifo_enabled(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl372_state *st = iio_priv(indio_dev); + + return sprintf(buf, "%d\n", st->fifo_mode); +} + +static ssize_t adxl372_get_fifo_watermark(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl372_state *st = iio_priv(indio_dev); + + return sprintf(buf, "%d\n", st->watermark); +} + +static IIO_CONST_ATTR(hwfifo_watermark_min, "1"); +static IIO_CONST_ATTR(hwfifo_watermark_max, + __stringify(ADXL372_FIFO_SIZE)); +static IIO_DEVICE_ATTR(hwfifo_watermark, 0444, + adxl372_get_fifo_watermark, NULL, 0); +static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, + adxl372_get_fifo_enabled, NULL, 0); + +static const struct attribute *adxl372_fifo_attributes[] = { + &iio_const_attr_hwfifo_watermark_min.dev_attr.attr, + &iio_const_attr_hwfifo_watermark_max.dev_attr.attr, + &iio_dev_attr_hwfifo_watermark.dev_attr.attr, + &iio_dev_attr_hwfifo_enabled.dev_attr.attr, + NULL, +}; + +static int adxl372_set_watermark(struct iio_dev *indio_dev, unsigned int val) +{ + struct adxl372_state *st = iio_priv(indio_dev); + + if (val > ADXL372_FIFO_SIZE) + val = ADXL372_FIFO_SIZE; + + st->watermark = val; + + return 0; +} + +static int adxl372_buffer_postenable(struct iio_dev *indio_dev) +{ + struct adxl372_state *st = iio_priv(indio_dev); + unsigned int mask; + int i, ret; + + ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0); + if (ret < 0) + return ret; + + mask = *indio_dev->active_scan_mask; + + for (i = 0; i < ARRAY_SIZE(adxl372_axis_lookup_table); i++) { + if (mask == adxl372_axis_lookup_table[i].bits) + break; + } + + st->fifo_format = adxl372_axis_lookup_table[i].fifo_format; + + if (st->fifo_format == ADXL372_XYZ_PEAK_FIFO) + st->fifo_set_size = 3; + else + st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask, + indio_dev->masklength); + /* + * The 512 FIFO samples can be allotted in several ways, such as: + * 170 sample sets of concurrent 3-axis data + * 256 sample sets of concurrent 2-axis data (user selectable) + * 512 sample sets of single-axis data + */ + if ((st->watermark * st->fifo_set_size) > ADXL372_FIFO_SIZE) + st->watermark = (ADXL372_FIFO_SIZE / st->fifo_set_size); + + st->fifo_mode = ADXL372_FIFO_STREAMED; + + ret = adxl372_configure_fifo(st); + if (ret < 0) { + st->fifo_mode = ADXL372_FIFO_BYPASSED; + adxl372_set_interrupts(st, 0, 0); + return ret; + } + + return iio_triggered_buffer_postenable(indio_dev); +} + +static int adxl372_buffer_predisable(struct iio_dev *indio_dev) +{ + struct adxl372_state *st = iio_priv(indio_dev); + + adxl372_set_interrupts(st, 0, 0); + st->fifo_mode = ADXL372_FIFO_BYPASSED; + adxl372_configure_fifo(st); + + return iio_triggered_buffer_predisable(indio_dev); +} + +static const struct iio_buffer_setup_ops adxl372_buffer_ops = { + .postenable = adxl372_buffer_postenable, + .predisable = adxl372_buffer_predisable, +}; + +static int adxl372_dready_trig_set_state(struct iio_trigger *trig, + bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct adxl372_state *st = iio_priv(indio_dev); + unsigned long int mask = 0; + + if (state) + mask = ADXL372_INT1_MAP_FIFO_FULL_MSK; + + return adxl372_set_interrupts(st, mask, 0); +} + +static const struct iio_trigger_ops adxl372_trigger_ops = { + .set_trigger_state = adxl372_dready_trig_set_state, +}; + static const struct iio_info adxl372_info = { .read_raw = adxl372_read_raw, .debugfs_reg_access = &adxl372_reg_access, + .hwfifo_set_watermark = adxl372_set_watermark, }; static const struct regmap_config adxl372_spi_regmap_config = { @@ -495,10 +819,11 @@ static int adxl372_probe(struct spi_device *spi) indio_dev->channels = adxl372_channels; indio_dev->num_channels = ARRAY_SIZE(adxl372_channels); + indio_dev->available_scan_masks = adxl372_channel_masks; 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; + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; ret = adxl372_setup(st); if (ret < 0) { @@ -506,6 +831,41 @@ static int adxl372_probe(struct spi_device *spi) return ret; } + ret = devm_iio_triggered_buffer_setup(&st->spi->dev, + indio_dev, NULL, + adxl372_trigger_handler, + &adxl372_buffer_ops); + if (ret < 0) + return ret; + + iio_buffer_set_attrs(indio_dev->buffer, adxl372_fifo_attributes); + + if (st->spi->irq) { + st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, + "%s-dev%d", + indio_dev->name, + indio_dev->id); + if (st->dready_trig == NULL) + return -ENOMEM; + + st->dready_trig->ops = &adxl372_trigger_ops; + st->dready_trig->dev.parent = &st->spi->dev; + iio_trigger_set_drvdata(st->dready_trig, indio_dev); + ret = devm_iio_trigger_register(&st->spi->dev, st->dready_trig); + if (ret < 0) + return ret; + + indio_dev->trig = iio_trigger_get(st->dready_trig); + + ret = devm_request_threaded_irq(&st->spi->dev, st->spi->irq, + iio_trigger_generic_data_rdy_poll, + NULL, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + indio_dev->name, st->dready_trig); + if (ret < 0) + return ret; + } + return devm_iio_device_register(&st->spi->dev, indio_dev); } From patchwork Wed Aug 1 15:18:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10552479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E6F714E2 for ; Wed, 1 Aug 2018 15:19:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DD732B7AC for ; Wed, 1 Aug 2018 15:19:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41F832B7B2; Wed, 1 Aug 2018 15:19:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8F5C2B7AC for ; Wed, 1 Aug 2018 15:19:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389909AbeHARFC (ORCPT ); Wed, 1 Aug 2018 13:05:02 -0400 Received: from mail-cys01nam02on0087.outbound.protection.outlook.com ([104.47.37.87]:31703 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389645AbeHARFB (ORCPT ); Wed, 1 Aug 2018 13:05:01 -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=N3lRvDqyEMjKu5pz2Bn9ixFm9fNYM/q8NI1ytsx3TXs=; b=BNgZnlWvskeVVTdh2SFfpSXaz344asa8kcn3Oix6LfhOEey7/1Fls/Yn7dF4AGOAy/VBLIMdwirCiNEYKqGRkRgi7v9ZHJEHHKDymb0bHWaLppLt6RJGdH/Bk6S6HmwAuKfCYufV7gYyt2FfvD+2Cgr4JOw+sPLF66+eytrOp9I= Received: from DM6PR03CA0029.namprd03.prod.outlook.com (2603:10b6:5:40::42) by MWHPR03MB3136.namprd03.prod.outlook.com (2603:10b6:301:3c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.19; Wed, 1 Aug 2018 15:18:43 +0000 Received: from BL2FFO11FD019.protection.gbl (2a01:111:f400:7c09::185) by DM6PR03CA0029.outlook.office365.com (2603:10b6:5:40::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:18:43 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; metafoo.de; dkim=none (message not signed) header.d=none;metafoo.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 BL2FFO11FD019.mail.protection.outlook.com (10.173.161.37) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:18:42 +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 w71FIgZ6027813 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 1 Aug 2018 08:18:42 -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; Wed, 1 Aug 2018 11:18:41 -0400 From: Stefan Popa To: CC: , , , , , , Subject: [PATCH v2 5/6] iio:adxl372: Add sampling frequency support Date: Wed, 1 Aug 2018 18:18:36 +0300 Message-ID: <1533136716-32041-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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)(346002)(376002)(396003)(39860400002)(136003)(2980300002)(438002)(189003)(199004)(246002)(2616005)(2351001)(107886003)(5660300001)(305945005)(14444005)(36756003)(8936002)(336012)(7636002)(8676002)(316002)(16586007)(486006)(426003)(2906002)(476003)(72206003)(126002)(106466001)(26005)(47776003)(53416004)(186003)(51416003)(4326008)(50226002)(6916009)(106002)(6666003)(77096007)(7696005)(44832011)(54906003)(478600001)(50466002)(356003)(48376002);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR03MB3136;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD019;1:myqns1SU76M0UwS3N/s1xCFdf4oRQ0FUh3rRLr4+hhd5+wfGCiybuwTn9cpie1K9sbzLFTW8/GnH4iHZ6XISowXNYU73n/P3FqaGJUAFR2PcyhQTt36c8PuvGtlMEcE+ X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7ebed9ce-2636-4e4f-3b3a-08d5f7c2113d X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4608076)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060);SRVR:MWHPR03MB3136; X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB3136;3:WXtsXhQCQDUJvEhT0qATLaE9q2ptkBYwJ5cDU6E4d5aDX6aSG66o5QVIumk41/Rv7U1IUGH4zKUih2j6IaXw5e+iBEhnuTxCN/kUUtCZ23YQ2mBi8SwY8y3x+xIfSMUUO9OBAJz4g4zpx+ShjWjL0Erf3ID/sUFcFiH8GKpuO8uZP+o/eycL83ddHbLo8OO/vsavaWHidnXcMd0AKmEEPlxNhoTP8ag46aKTva+LKW5qz78Z994+UeMWRwJP6XQRtWxIVeeHeWQQGWFp4DDb2yjyvBGKyozvuUzpmcotMI2wyeBdLiCvIDRQcX+Ncrzl5/O7UmQ7Hd3jsuCAxuObuJV6EJY//wIMJwjd/ADwWBA=;25:TrhVqnVCj/QLAuYl6w4vZTWsSnxn0J4aTsXBzQcLo3H6Veh2WvAEmQnYTBTmDYSXBZMDZxCArz4wj6XexHzUxTY+pIlVZxUBCgTbyFWw3KwjgwJd/O0Ex8JB2YG0O0v6irl+rns82Uqy5BDmjp86UMzknx5PKVfI3JzaktIXUrCYiFDXvsa3i48zP/KZLCD4D/iC+7uuhwchWNxCs4QboM6IrztJkC7WFW1n2jYRW5HfYXtVqwA5n0Tldba+nh+JDQlqRje28Q3xc6cqIxvwsubJKPAFsRbCsRxMHJ2fRgBCNNeh3cTCIF+LF64dhUCVhih9+V230A4LYZFF0BSBqQ== X-MS-TrafficTypeDiagnostic: MWHPR03MB3136: X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB3136;31:1oWimv1yMebvhXPKmla+/aSpSWoWVxfONIXPUm+5Ah5b51SBjFv+/81Dqy9N6kqw3sGM/EQHGuX0LUeg/RXyuyI648OHBtaExBJN+j+EL0/8YXkxdFpPLYCs8WIIqMhDriJ7H0XvD+KwysVr3T5lxO33WHRvoFghHfl6PBQMhtt91uv9qFBdSAoK0qDF5DcVjU8MSSOnxCV4OH/j8RIEETqDv+NN+qlccNQrRlkrFbA=;20:I2KtJkC+wgB25x/U5o+OL1rjZWJYqlAB6vqbq0NfGiJKMaxHgAz0i+F792FjK4okqHlJk3POJimbzfBPWqxvDWZCzVIODKJkVTWnltPRdd2gyNZCHE/eNJlSuQaTRPumz8X41xkH3TFWEwIvDxVQ3DbVL9PWVe5JwgzUiKMQgZl5toJ7t4FOpOE6tu5Ahp3HhoVzYxbnukIPVqIrpM/sSDK9KYeJubljdYsv7Pycsa3zh2fR9/+uFKiZYQcHBBokqCZWLjI6OKbDP+iQluhBLSpM5OjvDwCIQoixt9zhaC4tzW9WIia8QvuyjzGIFXcan1DmUgow2iuNNU9EAz88XcZfSryjTN7EDxap6r02pBkzYjQDr26b6LAN7uT3wG506kXfooWdf4Sg8Qx2ZjhZ0hAzDdvtlz8gMCLLFTS97XTrw3lKi51Yvxar13/9wfcBBs73/kWRBc0+YJXy6o+ovFVm97JfdclzAGohvpauicq6Op5lm7qP32qsE7eBxtXf X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231311)(944501410)(52105095)(3002001)(93006095)(93004095)(6055026)(149027)(150027)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011)(7699016);SRVR:MWHPR03MB3136;BCL:0;PCL:0;RULEID:;SRVR:MWHPR03MB3136; X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB3136;4:3sPSje6yZ1LrkGPMXNVfoApjoeBoHP/zO4WBXVcxo0W69+lWK43Bm9LOFJ4varaeETAdH2Pv7SHpbJoKixQPATHh/qq6di14mALGVw6MG545HaALRFradQHBctwTZuJ3OLSdjj/ZEdxgjAKnOPQfXRBzU0nOx5+XKXSCU/8pm7t2EJOmQzagHNDy2c/uyQ6jNBeQARdxLRRD9QHVz2rNwNsBjrS3hBveb5wh1PpOogK/GgvXqqb5utGX4mjV+JlfepePANnaVcWpCz6/TbKYMjW4x32xQtaZ9qtJ3IepFl9CModmkLu28SvO7DaRN+TD X-Forefront-PRVS: 0751474A44 X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB3136;23:3fpukLVypUY++zRYrYBUSg667hCwWyHl7QfDjep1oTVDhf062fRXMFw05MCVvXFjj8l85S2X1K8sTKr6VPJC12axtCU/Wf6ZV2tDW0UkvgsDcjsCmi/7nrP18oHyRmEShQBOrbX5RPhJ0QWZS3fas38cVUAr+HUCt60F/VavW1M4n7jSEA4a+ZoDGOexasT4ghnbt7URkX3/4KXn38GbyyxjuY4LDz2oe+XRy3mK100NhhoQ7t0ElmbxVhmhSA94FSY9vRqfVtym6TM4FfddnTTHk9vPKWTE0rRgvFGVehyufnUUJtF1PMk1idUibQg1CLymrf4bxfTLGLNfjat8PPgzr8ePCU+o4B/pPBLTiBzOltNk4Pjtx31W/LIwheLM+MV4/RBH2BTRlgoAjDWnHHGEErhPqkZL8Wy61XQGm42s5S30jaiRZTWmYPdNnpA8l2FQ6URfHpEJdACE5EV0a0JXFg8lGJ+h6kudTH8hzmPj+KKj9WszD7LY3Nsz3TLZlfpZjQ1D7oo/Z7p8hNo/4vFs5MkcxWhynwW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WhIcHC5cZg1CeMN/aOpmlSTTnznRBrnjwQ+tUKyGSrQLJWKpkaBLMzG+rUizBAYUYAhEWmW8r9xs73gUHgE27s5ErZt3qbdgQp2+dGc1iZ1dgiL7EsxqUKXrNOYdsAoysOTCRKnVS9hCKYgjOddlWVNdbRYVVHhl+2pv4VtO7zku6iLgSJbe63nTOvpTz5CA0ZnFx+w1HjmRPWiZzKvPc7UQ3DLpTg6VATrqsBusFNMVEn7pM5DysRWxZYeTpPSouT72kJxSCoRESA0oFSFBPoRfwuKWLmRS7AxCeZmWWtxezoauRrZ9TZlormBwihjOXpHpGIbErB52EFAmFz6Hcd3oglDw==;5:1FYqs96Tg5o0t+JW4ZCodHfi5OEFimUL5zBOS3Rf110x7GjA0agIb2ZKAOhny0H7HWyllu8gT/44SknTJR7Rj83f06qDsB+YWRxHzOinei1oXqIjM7xC2d4mD5L2o/PRC3T2ofrQxsK3MuuhfKr2CiQobH2JHN0N9xqO7n9w6J0=;7:/I/TI9ogvfy5Bjg6MaXluQanlhe8AkKs5mCZwnnEgRfA989QOwbq9AyEcJ/T6jFc4v9VPgk7G3rRbEeS/TUJ6f0ehyTUQK7VKQrjiYdIp/Iy7QSdBgBvJs18iykpELZFI8sbiWJJ7bkw7MzIyYvUVII/2XDHJ7SL0CzGadL0qYKQfeYeSotBHyVesXzQIVJxYpaT8oGQWJ3Sy0wsJXIxhkOec+PpDnGNG42+X5nvVid4XcqBYo5PTFB1jOSRfJO8 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 15:18:42.6640 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ebed9ce-2636-4e4f-3b3a-08d5f7c2113d 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: MWHPR03MB3136 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the option for the user to select the sampling frequency. Also, the user can read the available frequencies and read the currently set frequency via the read_raw function. The frequency can be set via the write_raw function. When the frequency is set, the bandwidth is also checked and ensured that it is constrained to at most half of the sampling frequency. Also, the activity and inactivity timers have to be updated because they depend on the selected ODR. Signed-off-by: Stefan Popa --- Changes in v2: - nothing changed. drivers/iio/accel/adxl372.c | 74 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c index 68862bf..d9e4826 100644 --- a/drivers/iio/accel/adxl372.c +++ b/drivers/iio/accel/adxl372.c @@ -217,7 +217,8 @@ static const struct adxl372_axis_lookup adxl372_axis_lookup_table[] = { .modified = 1, \ .channel2 = IIO_MOD_##axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ .scan_index = index, \ .scan_type = { \ .sign = 's', \ @@ -325,6 +326,19 @@ static int adxl372_set_odr(struct adxl372_state *st, return ret; } +static int adxl372_find_closest_match(const int *array, + unsigned int size, int val) +{ + int i; + + for (i = 0; i < size; i++) { + if (val <= array[i]) + return i; + } + + return size - 1; +} + static int adxl372_set_bandwidth(struct adxl372_state *st, enum adxl372_bandwidth bw) { @@ -651,6 +665,51 @@ static int adxl372_read_raw(struct iio_dev *indio_dev, *val = 0; *val2 = ADXL372_USCALE; return IIO_VAL_INT_PLUS_MICRO; + case IIO_CHAN_INFO_SAMP_FREQ: + *val = adxl372_samp_freq_tbl[st->odr]; + return IIO_VAL_INT; + } + + return -EINVAL; +} + +static int adxl372_write_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 odr_index, ret; + + switch (info) { + case IIO_CHAN_INFO_SAMP_FREQ: + odr_index = adxl372_find_closest_match(adxl372_samp_freq_tbl, + ARRAY_SIZE(adxl372_samp_freq_tbl), + val); + ret = adxl372_set_odr(st, odr_index); + if (ret < 0) + return ret; + /* + * The timer period depends on the ODR selected. + * At 3200 Hz and below, it is 6.6 ms; at 6400 Hz, it is 3.3 ms + */ + ret = adxl372_set_activity_time_ms(st, st->act_time_ms); + if (ret < 0) + return ret; + /* + * The timer period depends on the ODR selected. + * At 3200 Hz and below, it is 26 ms; at 6400 Hz, it is 13 ms + */ + ret = adxl372_set_inactivity_time_ms(st, st->inact_time_ms); + if (ret < 0) + return ret; + /* + * The maximum bandwidth is constrained to at most half of + * the ODR to ensure that the Nyquist criteria is not violated + */ + if (st->bw > odr_index) + ret = adxl372_set_bandwidth(st, odr_index); + + return ret; default: return -EINVAL; } @@ -782,8 +841,21 @@ static const struct iio_trigger_ops adxl372_trigger_ops = { .set_trigger_state = adxl372_dready_trig_set_state, }; +static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400"); + +static struct attribute *adxl372_attributes[] = { + &iio_const_attr_sampling_frequency_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group adxl372_attrs_group = { + .attrs = adxl372_attributes, +}; + static const struct iio_info adxl372_info = { + .attrs = &adxl372_attrs_group, .read_raw = adxl372_read_raw, + .write_raw = adxl372_write_raw, .debugfs_reg_access = &adxl372_reg_access, .hwfifo_set_watermark = adxl372_set_watermark, }; From patchwork Wed Aug 1 15:18:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10552481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 047FD15E9 for ; Wed, 1 Aug 2018 15:19:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E92E92B7AC for ; Wed, 1 Aug 2018 15:19:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD8322B7B2; Wed, 1 Aug 2018 15:19:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 535222B7AC for ; Wed, 1 Aug 2018 15:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389776AbeHARFP (ORCPT ); Wed, 1 Aug 2018 13:05:15 -0400 Received: from mail-bn3nam01on0053.outbound.protection.outlook.com ([104.47.33.53]:56176 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389694AbeHARFO (ORCPT ); Wed, 1 Aug 2018 13:05:14 -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=Olx/U+THbusnFfv0YlLXsFkj5Ph+ZE2KnQqD1XwgYhs=; b=X2WfeW9kwvzTUfT5XRF6y1J4fZSLZ0FtT100EGH1YJH2ccPE2dLKrZqYtvLXWGtVC9V4CbqMhHThYriE7D6rAYcEjt1tFvD9MkNmph0eJJKFqQyyHuInmp0JcZs1QsuwKwc1wfuMyctIDsdz55XNVn2wNVn4XUHBH9nE5T33vzc= Received: from CY4PR03CA0018.namprd03.prod.outlook.com (2603:10b6:903:33::28) by BL2PR03MB548.namprd03.prod.outlook.com (2a01:111:e400:c26::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.15; Wed, 1 Aug 2018 15:19:00 +0000 Received: from BL2FFO11FD027.protection.gbl (2a01:111:f400:7c09::195) by CY4PR03CA0018.outlook.office365.com (2603:10b6:903:33::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:19:00 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; metafoo.de; dkim=none (message not signed) header.d=none;metafoo.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 BL2FFO11FD027.mail.protection.outlook.com (10.173.161.106) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1017.15 via Frontend Transport; Wed, 1 Aug 2018 15:18:59 +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 w71FIx0Q027981 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 1 Aug 2018 08:18:59 -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; Wed, 1 Aug 2018 11:18:58 -0400 From: Stefan Popa To: CC: , , , , , , Subject: [PATCH v2 6/6] iio:adxl372: Add filter bandwidth support Date: Wed, 1 Aug 2018 18:18:50 +0300 Message-ID: <1533136730-32149-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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)(396003)(346002)(39860400002)(136003)(376002)(2980300002)(438002)(189003)(199004)(50466002)(5660300001)(8676002)(246002)(4326008)(6666003)(72206003)(478600001)(7636002)(305945005)(6916009)(356003)(50226002)(8936002)(48376002)(53416004)(107886003)(2616005)(476003)(126002)(2351001)(54906003)(336012)(106002)(316002)(426003)(486006)(16586007)(106466001)(26005)(77096007)(186003)(2906002)(36756003)(47776003)(7696005)(44832011)(51416003);DIR:OUT;SFP:1101;SCL:1;SRVR:BL2PR03MB548;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD027;1:pgcM0iR2KBs4Rij5sxGqFIr63crpax4V6VYbDjSVtS2BdwNWNhJF6foIPDzX0aU/OBD3qxSaYZNLpy/OT+W76seQTUJCa3kAp+mBgXU0/jiAV8AZTudCjy0qJ0BT7bX4 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 26b306dc-28c7-4765-3194-08d5f7c21b7b X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:BL2PR03MB548; X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB548;3:Ww8PK4P+fs7/U4s9gaiL7fJid4znZ2o0O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Sj0PbzGqwfBSjsLFkdizH91fNO/DK6w3Qsm/jqqJeEGt5iUT3E12WW0/IBwMz0BVsIH49riIUze13/KErtBedb7bQm2HshFCEtIhcJJRBMm5dC0MNawwXFeNiUP8L0O+0oLorpeGkfny16wRJKg9hoMaxu9wfnZzzSDuHn2ZzV5Oulb5rKOu9Do3Yo50u2vgYEb+XGCOQTm0EKbMdnG70uWD1QD2g/hVUkjPsF1IYg/HqR5e3kvTAWW+tDH7wVB9Cw/qhU4Md3RDak9vdyAje0hDNIpnGEGkHQ4WJ5g2iEm7D4tGJWtg7i/d2CpZrhm6tTE+BI3YgsiVHllvJ+CXwq4csVvV+ZyDO1xDGOB9gym4jNSyARGwakW6oapQcm5sHeUs3nWYhhOJIL23CRV7ptT/qLyPoXvZFu X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93004095)(10201501046)(3002001)(3231311)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:BL2PR03MB548;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB548; X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB548;4:lH5198J6Lk9Wf6pWWTawplTb6Q3XjTlqcznq8XahW5fTLxT7D0DTJuJEbf5lVh4zw1FxKmrbaZSiLYUnzYDiVSvv+3+SKA/7S3plTbydD8MspxBYZP7ocoFEreaNghc8vCf/r5URQpA6/MaAISKxt5ogfBfcMDNTKEtY4KlD829149ZM169z9vxKl4SRyWRv9qYAuUJP8f+PIy9c137Vm4WWp0jB+aQnySiHKg3pHqLruLUx2cAt+E8pY3Kg8+T3uR4VXmSyjXaoksVPEcIFBJRg4J/bnmwq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cGDLqKuzpwzMgXB46QdGRlHkEZyuI=;7:zlK4kTldZU8KIGFfgB/51Ow1Y52FxRZ3QV7eYgAybtY6QNmhluh8Donku1N8V0F1YvwYBZCbADs6gjkNuadDfI0qIwEXQDwWC6v235ybJO02A+BcrkaXZ1AhS4Rx51pmeuU0U0CPnxebreWpT8chN+HYcLAOhwgcZQITYMeGa0H1xoLuV59fd6tRMcacJk9SY1/vYh6x2HKFkmvpQ7BpxrJqk0U86V5FUqNJtiLuHQMkbs+cqYyNLphL9WwfS1sd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 15:18:59.8473 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26b306dc-28c7-4765-3194-08d5f7c21b7b 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: BL2PR03MB548 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the option for the user to select the filter bandwidth. The user can also read the available bandwidths which are always adjusted to be at most half of the sampling frequency. Furthermore, the currently selected bandwidth can be read via the read_raw function, while the write_raw sets a new bandwidth value. Signed-off-by: Stefan Popa --- Changes in v2: - nothing changed. drivers/iio/accel/adxl372.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c index d9e4826..5c55bed 100644 --- a/drivers/iio/accel/adxl372.c +++ b/drivers/iio/accel/adxl372.c @@ -195,6 +195,10 @@ static const int adxl372_samp_freq_tbl[5] = { 400, 800, 1600, 3200, 6400, }; +static const int adxl372_bw_freq_tbl[5] = { + 200, 400, 800, 1600, 3200, +}; + struct adxl372_axis_lookup { unsigned int bits; enum adxl372_fifo_format fifo_format; @@ -218,7 +222,8 @@ static const struct adxl372_axis_lookup adxl372_axis_lookup_table[] = { .channel2 = IIO_MOD_##axis, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ - BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ .scan_index = index, \ .scan_type = { \ .sign = 's', \ @@ -668,6 +673,9 @@ static int adxl372_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SAMP_FREQ: *val = adxl372_samp_freq_tbl[st->odr]; return IIO_VAL_INT; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + *val = adxl372_bw_freq_tbl[st->bw]; + return IIO_VAL_INT; } return -EINVAL; @@ -678,7 +686,7 @@ static int adxl372_write_raw(struct iio_dev *indio_dev, int val, int val2, long info) { struct adxl372_state *st = iio_priv(indio_dev); - int odr_index, ret; + int odr_index, bw_index, ret; switch (info) { case IIO_CHAN_INFO_SAMP_FREQ: @@ -710,11 +718,34 @@ static int adxl372_write_raw(struct iio_dev *indio_dev, ret = adxl372_set_bandwidth(st, odr_index); return ret; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + bw_index = adxl372_find_closest_match(adxl372_bw_freq_tbl, + ARRAY_SIZE(adxl372_bw_freq_tbl), + val); + return adxl372_set_bandwidth(st, bw_index); default: return -EINVAL; } } +static ssize_t adxl372_show_filter_freq_avail(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct adxl372_state *st = iio_priv(indio_dev); + int i; + size_t len = 0; + + for (i = 0; i <= st->odr; i++) + len += scnprintf(buf + len, PAGE_SIZE - len, + "%d ", adxl372_bw_freq_tbl[i]); + + buf[len - 1] = '\n'; + + return len; +} + static ssize_t adxl372_get_fifo_enabled(struct device *dev, struct device_attribute *attr, char *buf) @@ -842,9 +873,12 @@ static const struct iio_trigger_ops adxl372_trigger_ops = { }; static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400"); +static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available, + 0444, adxl372_show_filter_freq_avail, NULL, 0); static struct attribute *adxl372_attributes[] = { &iio_const_attr_sampling_frequency_available.dev_attr.attr, + &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, NULL, };