From patchwork Fri Apr 6 18:19:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10327413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B76A56053F for ; Fri, 6 Apr 2018 18:20:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A729C295DF for ; Fri, 6 Apr 2018 18:20:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A145295E0; Fri, 6 Apr 2018 18:20:02 +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 9DBCB295E4 for ; Fri, 6 Apr 2018 18:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbeDFSUB (ORCPT ); Fri, 6 Apr 2018 14:20:01 -0400 Received: from mail-by2nam03on0058.outbound.protection.outlook.com ([104.47.42.58]:43075 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750807AbeDFST7 (ORCPT ); Fri, 6 Apr 2018 14:19:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uievolution.onmicrosoft.com; s=selector1-xevo-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=UdOV2vpbtXmtGprax/IOvxAd38fTVHSnOwB0HQ+pZ10=; b=MjgviYt3TEsQ0zSyoZbX7XnxPEIvACj3oGLjgh7XqvEttO3tE4UT4R6zTbYYu3gN6Kew/8JC4jOc7sa5DTUxrAFupgT3Q+2Ftpuafscfp8tFDtF5ZhLxQ8Zi9Y9gSO8uHB4OYm1IrqZ+JDWdGZjIbjmOGge/62/xdNTgeJGWbkM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=mkelly@xevo.com; Received: from columbia.corp.xevo.com (65.122.179.226) by SN6PR0102MB3422.prod.exchangelabs.com (2603:10b6:805:3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Fri, 6 Apr 2018 18:19:56 +0000 From: Martin Kelly To: linux-iio@vger.kernel.org Cc: devicetree@vger.kernel.org, Jonathan Cameron , Jean-Baptiste Maneyrol , Martin Kelly Subject: [PATCH v2 1/2] iio:imu: inv_mpu6050: support more interrupt types Date: Fri, 6 Apr 2018 11:19:41 -0700 Message-Id: <20180406181942.1365-1-mkelly@xevo.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [65.122.179.226] X-ClientProxiedBy: MWHPR17CA0067.namprd17.prod.outlook.com (2603:10b6:300:93::29) To SN6PR0102MB3422.prod.exchangelabs.com (2603:10b6:805:3::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3acb8d2-e686-4600-428e-08d59beb002a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:SN6PR0102MB3422; X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3422; 3:XNpJ8kbXCC00b2hAazhMwhOuQSMM9r7Zj1BOyQ15d5OFgGaKR3/9IqTP5AvoLJWdHiFdklNgWOXSsb1ZmPq01qNZpbA86wxz9bYUp9Kio9kEFfn/eJ31RZeNbJ/UZSX8rlBKeHfmd65PyHOEb2LbhNgX/sOKMOnmkd8k99fD2AgGhIHJNsAWBSaXNUKeXWbptRFahPNLUWNG/genLCB2aIKaCAuNDGuPcE6L+UJlTl/KeG+xCot55vTV4gKLNkRb; 25:rQMMkbiYPay1zcKbs1/UE+2JijZeLaFMj6eJTAWON+r0Qln99qsftnXMidcEyJ6qP29xw4DMFgCyczwMCqc1rt0YWoSGT9Pw9toZbSXsWIf4pDxU4+G2vbJT19gvFAvcJf9x3PxFbnJVQ3iV7a82eUtHKnHyy9kpMypRVpJ0uAG6H27KGRejhkVE+v3BOaPU6enfW5+2ZjfP/WRlKgleHBeqjN31BIkvLE+0V3EZLH7z6flrvQKZb0eww27gu9o86LgG5nrXw1BXJpsMiOsAv3NH3GyTyWmqvO3vv4oaxijFTvPnfhniifvZ2ZhSv2TMuoAo4wX5NiwAOD0SJl/Lfg==; 31:uc/snU46kyu86hXt4rg/s+hTCEZPCY9K4lt4aSSFSJHzB+ko0qN5Nn9yW+sbV4RyGloQ3Gx31DE2qH1U9BggfBoJhfiHVuELfp3/nz9E8uZPdkcQy/zgWTF1eyXivxnISp1RLZdInhP/R15FWRp92zcYO/Iw52xY95+uIekjTLR6eU+o+3q/2DonHrOEqFt9JTcYwHZH72C8/bs/0l41M959lYDq9P7PK/XbYvR8sO4= X-MS-TrafficTypeDiagnostic: SN6PR0102MB3422: X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3422; 20:omLi90VEkxSjXfs/U/g8uYwZ4QcCEJAXrET0uTHl3VChEWWeX6bKLGU13ySQOySnwc1BxsWcG3P2sKi5NlrwEfU87JkupfRrYdbRAczaX1zi/O8LMcfLD+A3GrJQ1IKfiEN2ZTTe5S1mtLnfO6vUqJil010D0jHRzC7y0mlr9zq0FVx9ckZ+g6zyqWIic9Gq8bm7sKK+9Sv70K5bwhg5agGHmjrJJdZGuJ0Aigog8/RER36zEYUwFAMINu19l28hcj4oyROT2sNHYYU29tEbroI5KHiN+6Cd5hlawECBpQmFDwVi+TvdiRYz+7C2Gxm/HW7ZxTHgi7K8Bkb5LY4hWCSVXO7sabv8GFxDJCEcNEfRJt6pnIc3W2lIKRlbG4N5oD8H9NntzEdRehy1zkIpNsTJiZnF+M45ZYRX9LbdxflyIDzR2woDavEZAGAoc96Bp5RzoKe9Sy2lBOOjwcWa00KrWSm99acPKkoXFvHU1JXKIOovLEIBrDfP5NmZMd0O; 4:RAb/bJefVETWna1Erj+VPHnzPJwyz0K92OeH8IQwu01ee1e4+dp+xn/qZmmZWMJwRpT7CLdN6/Qp2NHw7TuNpxOlUmc8IJpz1hRJ6R5xSq3VMBgISaOkigSMqvB0b9VN1cs0hRt+wxdlqT6k03lZ81pya23rCG4DTxxE1yQZiw+rZuCrWQpldTGRVHkrws2EFpIL0k2HrfRXW2y/8+6Aw7xXEjcFKchQ+ztzTTOgCD3ehLusqXuSFoGKwjsIHi/dR8+5i/IigFvK/01bEQooylzPyx8jnTv24ywgCWbB4k70SQTrlR7ysV5kJUnK2z7/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231221)(944501327)(52105095)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:SN6PR0102MB3422; BCL:0; PCL:0; RULEID:; SRVR:SN6PR0102MB3422; X-Forefront-PRVS: 0634F37BFF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(396003)(39840400004)(376002)(366004)(39380400002)(189003)(199004)(36756003)(6486002)(16586007)(386003)(316002)(50466002)(106356001)(48376002)(186003)(956004)(2361001)(50226002)(97736004)(105586002)(2616005)(2351001)(26005)(305945005)(7736002)(16526019)(54906003)(107886003)(66066001)(5660300001)(8676002)(1076002)(47776003)(6666003)(59450400001)(476003)(4326008)(51416003)(7696005)(8936002)(25786009)(86362001)(2906002)(81156014)(52116002)(486006)(68736007)(3846002)(6916009)(478600001)(53936002)(6116002)(81166006); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR0102MB3422; H:columbia.corp.xevo.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: xevo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN6PR0102MB3422; 23:xXr7wHxv9Ey/xHPf2f+pKASM/469WuA1GOwZ4fT?= =?us-ascii?Q?SL0a0HvC9m8QlcPjwNBmzcv+HaeNibuR0Z8zh86oY1EtTrwWld8XX2nVCjYg?= =?us-ascii?Q?eL/OZVXR7pTUkXCKx+pV2936fT365kFAhUMgOW9TQYTTGph9xkChyUDvrTrz?= =?us-ascii?Q?0mfBdtYV89TAjVgwxTt2AR233BTHEldAzpgIiGllR3G3PYPnnWHOffBqYoy6?= =?us-ascii?Q?YexlJJJu2ryug5Bn7KAlgLycGAiHogh/AI5KJ6nKbtlVGCQYJ7uocEh8yul4?= =?us-ascii?Q?ycU9v2OiC7tCTDCT17L5XFB+7yZJd3wnQk4EQ9g/bkXQGLXSflaMEoRF4lNq?= =?us-ascii?Q?fxEZ5E+AHsC8z84O/+jsHSYZ3SBL2LKqTr+iLoPdt9wrNbw/8YaV5WTJdH9H?= =?us-ascii?Q?NXrXgxVfbe9dV0fvZWwz6aMqROkyKOcKNJ/am+qbeEIJQ8kzi2EzPBFG6OZe?= =?us-ascii?Q?BgQGsJl9G7fqJRj/5J8ujRPFL06X+1qSORMRkVVYoOA2WtDvTCRIVogYx0cA?= =?us-ascii?Q?1aNAeaNHg6eDhFJXbcCpxXIkMs+aYjNTgYrz7yaHISXsPX5mfuZkCFTWX93T?= =?us-ascii?Q?WxIbpeZDI3/hlh1b3+QNTiT776gZOCc8IpaO55k8qpjtkoz3GOl1RqVV1b/p?= =?us-ascii?Q?cTHxI0iujaVGlYFFMcskeyQ/YWe7O5hjdzaykgurU2e0vnXfdB09p+407ngl?= =?us-ascii?Q?e1+ZSEi3iKYfvx7QHzAjZXKMAXEt7UGMobwItRzokujnkelHwe6jnntZAf8Y?= =?us-ascii?Q?Z4FdfgAwgbl1HeiFHSACiFOdRzH7WPijrevf3891UPMpXz7TEHhmFl5xuRiY?= =?us-ascii?Q?l3ySr6TeAIzGm5e1sJwAxQgQFlfl1x8uArl/5g1hhLjsTVRS/V8A4fzG8xL3?= =?us-ascii?Q?Mljevl8NnA06lLkWl7l66Z59OPJ7KwaPYf4FzJnf7dFxa4hFYpw/RcAw8tX1?= =?us-ascii?Q?XDAYcN9Hy+CeFFypGiTN8c67j/iBNzOkMIBo3ozfDQF2H2/s15cJI0ra5+HL?= =?us-ascii?Q?L5gaXJpxT7OZrXPCH3GPJE6aToV0L/MOrTmCwsXixBkh1G1J6tHyTYwt8ojQ?= =?us-ascii?Q?FRas3pieU7F33PTDoM0/eZ5euqpCa/WOuz6TrLB7KCuQgr6jCUb5ZqQXCiAJ?= =?us-ascii?Q?5m373e28qZtAl0JEGBFLB3AzXqSURjJeRookwHsFGYFr7QK1b7BP11U6OmXW?= =?us-ascii?Q?wuVNj/M59RWhfNbQ3aou+XJcSy1GlowP4Hgo5bI5wl20m/4F1UFkdezhajw?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Antispam-Message-Info: Qbo79tnnVILPS6p4IjI8zq1YBwF+WUmIKXoiDn0nb2QG/CiAMmtQi/D59sZ9BGEI4485g6QaFVu6qzQRSgnT+AI5sudm4O/zsTSMK5zn5NRR1jFnFIIAHBNIi30fFJFtN7gFvRfVRoyvPgcSzX7ornPDtNDx0kQ30HNBhfs4RZ9DsNfas0eWuH/dEhnF4Ay+ X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3422; 6:UvJ7usQn0/Gq41KrzbbaOVXInwG7ctLDZu4PAvNgcmJnmpYwTimcXI4Is3sYQP5Kxuv1pNl41hjCE71UdxaH3LZqcaU4eKC6jFpVfL8VM/dAflRrvl4eeHE++UJQ7onnH+tYQTunZ9ASVVh7X/vj2BK0Bp8D2rAvOT1F3JEfp7cfGa4xN736U+Ji7/JXdv9uaK8spuPshRRxh0qhPwAH5GrtMB2cD/dAwoz+xG+K/rKV/iN4e8zMbC+VcA/HbDsr82D72FQ5WP1yUDI3P4MslFc0IQQ/JpIG+ZtVtideXS8yJd9/90JeyEKN4QeHFG5m0cu3w1396zH6YVxftYXZkUcRbki7Wy3U2kRenlyMZVKvmMvJWiXxITo+LGzE8u4j/h3GoI91a6Mxq4/3EfJ8BVM4HLCUvBeTcc5LpPa2Er4+zsZn589hfphb4PqPo6eBcwDccJBUMp+sL2x1P/YMQQ==; 5:CvPCnN3MX5CT+h5Yd8iP5hOeYaw0SAO0tuudh5LfBH3x2I49crOY+jzIxjyrQ4VlMI8IXEY9wxf1a8BtBYYDFhpW97wnSN8USAqiu5U2qz7zRuhxlgvFsVbWwtdERF3syIcIQt0aLekcgdddTnxc1aVOPEqodMb6NX88HHaWJq4=; 24:vcNGEILUPlxH3AuDKA1uotrLuq7QctDKXBTXSMrvWTtpWgavNOOphqJX15aNXBJVFu9iE8QmffEIbTVxxBGRVjBxK4fjqY6Y8n1QE08vuu4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3422; 7:ePyoHyYu6TTNZg8V/7dKzR8PORebDdggpdW9e1VXqaUuSQZfOFPWD7vFu6CGg0mSxzwPM0jOEYgI1hODgVXvVuZrr3d8V28ISgzA7e89n8Eu+9Z64KHxhpabozQy/6pyh6mNwvp8Ym1PxpS8tDE5eBgwrqC1sKqrH/Az2q8XwRxq9RByttG6RPCvoYKa1M/z4tm09uLjmCgdsFVsg2Tsbd4EjiKhdmvCL0ZOK1EMeLAr1dErtGjZ+DeGuykJj3Oj X-OriginatorOrg: xevo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2018 18:19:56.1588 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3acb8d2-e686-4600-428e-08d59beb002a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e0a7ca1f-2458-4cd6-a7c7-d733c07495ab X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR0102MB3422 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 Currently, we support only rising edge interrupts, and in fact we assume that the interrupt we're given is rising edge (and things won't work if it's not). However, the device supports rising edge, falling edge, level low, and level high interrupts. Empirically, on my system, switching to level interrupts has fixed a problem I had with significant (~40%) interrupt loss with edge interrupts, as well as bus errors at high frequencies (possibly a concurrency issue, which I will look into separately). This issue is likely related to the SoC I'm using (Allwinner H3), but being able to switch the interrupt type is still a very useful workaround. I tested this with each interrupt type and verified correct behavior in a logic analyzer. Add support for these interrupt types while also eliminating the error case of the device tree and driver using different interrupt types. Signed-off-by: Martin Kelly --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 +++++++++++++++++++++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 5 ++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 12 ++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 14 ++++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- 5 files changed, 63 insertions(+), 6 deletions(-) v2: - Changed to ACK level interrupts at the start of the bottom half thread instead of at the end of it. Without this, the sample timestamps get distorted because the time to handle the bottom half thread delays future interrupts. With this change, the timestamps appear evenly distributed at the right frequency. diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 7d64be353403..869768d08802 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "inv_mpu_iio.h" /* @@ -52,6 +53,7 @@ static const struct inv_mpu6050_reg_map reg_set_6500 = { .raw_accl = INV_MPU6050_REG_RAW_ACCEL, .temperature = INV_MPU6050_REG_TEMPERATURE, .int_enable = INV_MPU6050_REG_INT_ENABLE, + .int_status = INV_MPU6050_REG_INT_STATUS, .pwr_mgmt_1 = INV_MPU6050_REG_PWR_MGMT_1, .pwr_mgmt_2 = INV_MPU6050_REG_PWR_MGMT_2, .int_pin_cfg = INV_MPU6050_REG_INT_PIN_CFG, @@ -281,6 +283,10 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) memcpy(&st->chip_config, hw_info[st->chip_type].config, sizeof(struct inv_mpu6050_chip_config)); result = inv_mpu6050_set_power_itg(st, false); + if (result) + return result; + + result = regmap_write(st->map, st->reg->int_pin_cfg, st->irq_mask); return result; } @@ -882,6 +888,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, struct inv_mpu6050_platform_data *pdata; struct device *dev = regmap_get_device(regmap); int result; + struct irq_data *desc; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); if (!indio_dev) @@ -913,6 +920,35 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, st->plat_data = *pdata; } + desc = irq_get_irq_data(irq); + if (!desc) { + dev_err(dev, "Could not find IRQ %d\n", irq); + return -EBUSY; + } + + st->irq_type = irqd_get_trigger_type(desc); + if (st->irq_type == IRQF_TRIGGER_RISING) { + st->irq_mask = INV_MPU6050_ACTIVE_HIGH | + INV_MPU6050_EDGE_TRIGGERED; + st->irq_level_triggered = false; + } else if (st->irq_type == IRQF_TRIGGER_FALLING) { + st->irq_mask = INV_MPU6050_ACTIVE_LOW | + INV_MPU6050_EDGE_TRIGGERED; + st->irq_level_triggered = false; + } else if (st->irq_type == IRQF_TRIGGER_HIGH) { + st->irq_mask = INV_MPU6050_ACTIVE_HIGH | + INV_MPU6050_LEVEL_TRIGGERED; + st->irq_level_triggered = true; + } else if (st->irq_type == IRQF_TRIGGER_LOW) { + st->irq_mask = INV_MPU6050_ACTIVE_LOW | + INV_MPU6050_LEVEL_TRIGGERED; + st->irq_level_triggered = true; + } else { + dev_err(dev, "Invalid interrupt type 0x%x specified\n", + st->irq_type); + return -EBUSY; + } + /* power is turned on inside check chip type*/ result = inv_check_and_setup_chip(st); if (result) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index fcd7a92b6cf8..bb3064537943 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c @@ -44,8 +44,7 @@ static int inv_mpu6050_select_bypass(struct i2c_mux_core *muxc, u32 chan_id) if (!ret) { st->powerup_count++; ret = regmap_write(st->map, st->reg->int_pin_cfg, - INV_MPU6050_INT_PIN_CFG | - INV_MPU6050_BIT_BYPASS_EN); + st->irq_mask | INV_MPU6050_BIT_BYPASS_EN); } write_error: mutex_unlock(&st->lock); @@ -60,7 +59,7 @@ static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id) mutex_lock(&st->lock); /* It doesn't really mattter, if any of the calls fails */ - regmap_write(st->map, st->reg->int_pin_cfg, INV_MPU6050_INT_PIN_CFG); + regmap_write(st->map, st->reg->int_pin_cfg, 0); st->powerup_count--; if (!st->powerup_count) regmap_write(st->map, st->reg->pwr_mgmt_1, diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 065794162d65..2822b638804f 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -40,6 +40,7 @@ * @raw_accl: Address of first accel register. * @temperature: temperature register * @int_enable: Interrupt enable register. + * @int_status: Interrupt status register. * @pwr_mgmt_1: Controls chip's power state and clock source. * @pwr_mgmt_2: Controls power state of individual sensors. * @int_pin_cfg; Controls interrupt pin configuration. @@ -60,6 +61,7 @@ struct inv_mpu6050_reg_map { u8 raw_accl; u8 temperature; u8 int_enable; + u8 int_status; u8 pwr_mgmt_1; u8 pwr_mgmt_2; u8 int_pin_cfg; @@ -143,6 +145,9 @@ struct inv_mpu6050_state { DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE); struct regmap *map; int irq; + int irq_type; + u16 irq_mask; + bool irq_level_triggered; }; /*register and associated bit definition*/ @@ -159,6 +164,7 @@ struct inv_mpu6050_state { #define INV_MPU6050_BITS_GYRO_OUT 0x70 #define INV_MPU6050_REG_INT_ENABLE 0x38 +#define INV_MPU6050_REG_INT_STATUS 0x3a #define INV_MPU6050_BIT_DATA_RDY_EN 0x01 #define INV_MPU6050_BIT_DMP_INT_EN 0x02 @@ -190,6 +196,11 @@ struct inv_mpu6050_state { #define INV_MPU6050_FIFO_COUNT_BYTE 2 #define INV_MPU6050_FIFO_THRESHOLD 500 +#define INV_MPU6050_ACTIVE_HIGH 0x00 +#define INV_MPU6050_ACTIVE_LOW 0x80 +#define INV_MPU6050_EDGE_TRIGGERED 0x00 +#define INV_MPU6050_LEVEL_TRIGGERED 0x20 + /* mpu6500 registers */ #define INV_MPU6500_REG_ACCEL_CONFIG_2 0x1D #define INV_MPU6500_REG_ACCEL_OFFSET 0x77 @@ -216,7 +227,6 @@ struct inv_mpu6050_state { #define INV_MPU6050_REG_INT_PIN_CFG 0x37 #define INV_MPU6050_BIT_BYPASS_EN 0x2 -#define INV_MPU6050_INT_PIN_CFG 0 /* init parameters */ #define INV_MPU6050_INIT_FIFO_RATE 50 diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index ff81c6aa009d..15bd36385f1d 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -128,6 +128,14 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) u16 fifo_count; s64 timestamp; + if (st->irq_level_triggered) { + result = regmap_read(st->map, st->reg->int_status, + (int *) data); + if (result) + dev_err(regmap_get_device(st->map), + "failed to ack interrupt\n"); + } + mutex_lock(&st->lock); if (!(st->chip_config.accl_fifo_enable | st->chip_config.gyro_fifo_enable)) @@ -181,7 +189,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) mutex_unlock(&st->lock); iio_trigger_notify_done(indio_dev->trig); - return IRQ_HANDLED; + goto out; flush_fifo: /* Flush HW and SW FIFOs. */ @@ -189,5 +197,9 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) mutex_unlock(&st->lock); iio_trigger_notify_done(indio_dev->trig); + /* Fall through */ + return IRQ_HANDLED; + +out: return IRQ_HANDLED; } diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index f963f9fc98c0..1e7201a43e34 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -131,7 +131,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev) ret = devm_request_irq(&indio_dev->dev, st->irq, &iio_trigger_generic_data_rdy_poll, - IRQF_TRIGGER_RISING, + st->irq_type, "inv_mpu", st->trig); if (ret)