From patchwork Fri Apr 20 16:54:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10353253 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 A5F37600CC for ; Fri, 20 Apr 2018 16:54:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3560E287EA for ; Fri, 20 Apr 2018 16:54:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27507287F3; Fri, 20 Apr 2018 16:54:32 +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 DEB80287EA for ; Fri, 20 Apr 2018 16:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752332AbeDTQy3 (ORCPT ); Fri, 20 Apr 2018 12:54:29 -0400 Received: from mail-dm3nam03on0088.outbound.protection.outlook.com ([104.47.41.88]:65311 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750989AbeDTQy2 (ORCPT ); Fri, 20 Apr 2018 12:54:28 -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=qsriqiMesb8N/0xTfXAXIYK9ImsLgWbSJStrgND3bVo=; b=oVBENoS0ZQ70DSRXAumb5pKmEj5wYqRAKvY25gWUowdP0el6sk1lRcV3jO7AjcTFb/fjeUPgj4sGKlJinbd2nBLrKCCMJkfjuWP/Ms8RdPdGSZvA9dMQfxHwYVkaTogna6cilTs+vt+F+LTjXGZA+wraMcV8yDZY9td2enDkZQU= Received: from columbia.corp.xevo.com (65.122.179.226) by MW2PR0102MB3417.prod.exchangelabs.com (2603:10b6:302:3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Fri, 20 Apr 2018 16:54:25 +0000 From: Martin Kelly To: linux-iio@vger.kernel.org Cc: devicetree@vger.kernel.org, Jonathan Cameron , Jean-Baptiste Maneyrol , Martin Kelly Subject: [PATCH v7 1/2] iio:imu: inv_mpu6050: support more interrupt types Date: Fri, 20 Apr 2018 09:54:00 -0700 Message-Id: <20180420165401.13076-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: MWHPR13CA0048.namprd13.prod.outlook.com (2603:10b6:300:95::34) To MW2PR0102MB3417.prod.exchangelabs.com (2603:10b6:302:3::10) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:MW2PR0102MB3417; X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3417; 3:wVkXxFGyk+Myj6zEZGmHmLOPlZ4566f7PSuikn/fr79/qAIYx6lkDtiBCWefO7o5dU5dznxPS/r9aW6Jh3JIfFN6GV9j52v6e5c7oxWQHvJ7pdILBWv7n2AwXErjwS1smkpbffvk6nk+OJoEmZQ0ZP8SttqbfUEYiiHaDigZz+hKT0XuXlC4pmFS+F2DLZ8O6Yz35gdv6QTEDP9GXQDIAXNOGy8+KtWA6vD6qFn3ofsSfnovQxXamPNhV3f5taqm; 25:RD35UpgdbbicufgVIhvsXI3OJGo5AbQuPMeEhzCniiRvNiLZde+VsWYipbQN1BEClyUZJwkSJbNN5fNe89ZeuWsaocBFWhcEPsRIGRJFt0UiCL0zufisPtCGCOiBqOo/N26lwx9r7NuiIxrHrn52E58DU3ub2CVbIAV4Ub3Dg3HHAeOip7VdioWNAa9yfmKBKcMcJpC8dMdoI4E0Z+84e8y/BranVacumiiFgbYl8+3QDb6j+daNaOLkLYZLqBfMY1Pf4afBOHaHSiyozIlMUqLOmNcXz8I21PMmuOuqpzK1YaBKw1w64DS5yFoI2ZpQ2/R2zZUz/xjArLXb0q7gMA==; 31:hlTlklcWtHe3KIbyj/S28Hp3Kzdw5xai2gOVcLtqXBWouKHR7sfnI4VqPZ/swnesYKW/SX64p/spXulLi1dxjtGyY9AVEu414qv8nd0vTK0phttov3ZrQVuadXaV0z8+4q345JljK+kUuBUN86OpYtWbytjhWgupzXKEdj8Hfq6+nd6iORwU0G4g66sBQNn9/dsTDbaGFRm7A5ZuvYGrrZ80UpLhI6xUyzconJzX5xc= X-MS-TrafficTypeDiagnostic: MW2PR0102MB3417: Authentication-Results: outbound.protection.outlook.com; spf=skipped (originating message); dkim=none (message not signed) header.d=none; dmarc=none action=none header.from=xevo.com; X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3417; 20:Q/xykzEmopXhj4BjZY5NogGEFdrrpzuLd5xI1nRI978vvhSFKPPikZ9Nj+uokjVl4oo5NFs7OiaMIioKO80vo1d16I3EByazBM97jkh2SObazjgyWjltr6v5iFgY8x2XnXsJsqD8sA7knU7KwLtqPYkd9tTWDm2UXeFetNwjHucsmDKQd16K7KTuHdewdtzf5zG/GpCx6D5SjK7li2vP854d3fyQOIRF84Ta7Qp9toqILaE6C67dIB4RHmMu5W+OvjSSD0o/CCwaRECGaNJaDphl6Z9ffAH/paYcojtFEKzwJjWqaIi7EH+AA6PHyVocD7NOGPhAqSl1xVgj1ZTJLYITRKVx0qMLANNk/yDqGHfWmwZUviPpNiSihFrAjeOpfKcbPXBde468u8RUdGoYDJgLsF1THuSYyw53ZXWkpHsMz2rNsup/KPFVc+5buhxTlUNWYsY8VMW98Z422tx/s8nAgmSIUZ2Pv8+i0ZxW4pNJXaixUcMkGw1+8QEb2GhQ; 4:6TS5BdZfDz/X2BkCIJRYJSS7oZH/vaB72WIkbxW++CO0dGP1tXMl6YKVCagEeI5dSoOqrjxDIKE23TGChbsUaQs8ROaXHPYw3lneE4Jf0LLYUXJNfSw9rNf2iAL1OgPjOLYNBgHyx1PDthaBk8DdLIJ4ICESxnl28+QF0L+CKQk4kAwh4h9LHFOn3DBlPfgPAn1lNdAbSfg3c8iw+91RhM03kpzkYTemQCMcGYJAFyCn8ullE7FspOwmEnF+BVgMOHhjsbVNCnHRSSK0zvMyq2cxMM5hssMUZro58qiLQqfMvv226wULNf85lgc82FqA 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)(3002001)(10201501046)(93006095)(93001095)(3231232)(944501396)(52105095)(6041310)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:MW2PR0102MB3417; BCL:0; PCL:0; RULEID:; SRVR:MW2PR0102MB3417; X-Forefront-PRVS: 0648FCFFA8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(346002)(366004)(376002)(39380400002)(39850400004)(86362001)(6486002)(66066001)(47776003)(50226002)(36756003)(2351001)(48376002)(107886003)(186003)(16526019)(8676002)(8936002)(2616005)(26005)(956004)(81166006)(25786009)(478600001)(4326008)(2361001)(476003)(5660300001)(6916009)(2906002)(6666003)(316002)(386003)(305945005)(7736002)(59450400001)(1076002)(50466002)(3846002)(6116002)(53936002)(54906003)(16586007)(52116002)(7696005); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR0102MB3417; H:columbia.corp.xevo.com; FPR:; SPF:None; LANG:en; MLV:sfv; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MW2PR0102MB3417; 23:FvC0KIMs4YKCOptXTJxXRNpS+AHg1DLBANyjvFo?= =?us-ascii?Q?STpQsyQEALnRFgcmEHzEW3/NU8aXyDAShL6USadIUc4lLAogPDTBKCKpoAwR?= =?us-ascii?Q?Jgf5+NhHWAMD1GmplkuKchuQ6tiyayeGbnglCadIPtvX9es9PHKsIPvgBJ2o?= =?us-ascii?Q?+5AiCTFhFnPaezSlCk6w1MZ2frrOQsjDyoIiiNz9LyHUpZhoNDb+QAyfhHKO?= =?us-ascii?Q?qfDnYogH+YLf5OoXNkBfyIisGccjA1FLSqg1H4cmeV4dpw8jLMNX6xJY5VFP?= =?us-ascii?Q?WSL0LGh/Lw/re0T8r3eJjtUgj5lCdEUdTw+lA0lH3Rpmu7gXdNE4jOdRtn1Z?= =?us-ascii?Q?41LXPPB6VtzUNiSQ124USuuRFhxOXnGAYJRVyCckMiF5PEtdTGtU62MVZN1y?= =?us-ascii?Q?cGhF2OFjdDDjzwvNOBoC5uWAL4vc/NCe/mTW24Po/8FMgPw/QPKvZgBpBIp1?= =?us-ascii?Q?2t+0zHKB1z4YQYglr4vGc9EdJOTZKUvgxheqcCgr3D4ovxukv74is4KSxnzK?= =?us-ascii?Q?UND38n0CBy5yP4ZlwO6Udgy/PsKNExyOYXpdvc+FSYDaswpkv1H6GdPgZUHH?= =?us-ascii?Q?OGPFDLZ+/Cw/iMDiYp2LO420IbthC40I0Hj+LBSe8yVLiq7yonAe5+tEUDvt?= =?us-ascii?Q?neZ+MDIaY8gXO6Q+mK+yatO2LpWPu1ZZb+6/0o3gZzs1yOEbgagmYZVYWSlR?= =?us-ascii?Q?8tHH4O/PQ08iCi4Fv7iOxlmFNNv3Fo45lIQXPWfmjbRg7EkiPdrFh0bBmYLb?= =?us-ascii?Q?OU1r/amvDD6WM1KROXTGqQvKoATufPIqkbyGDg/AeixTkJz3Vwd7vduTthYj?= =?us-ascii?Q?7gtt5RZw+egjiwmDibG2aFx4eMbRoKyAk3s8a1BoZ6pVHGmAexJgbAeneGlk?= =?us-ascii?Q?6Hd/yUfYp6lDpbP5zK2/3VurglntaJm6fkuXLIimQxy+mGb7fMe+mIIh9hBY?= =?us-ascii?Q?o+a7IcvRvbcvup3rfNZNN534H8egWFCsocX8R9D+DQmWx0eP2ndxQKrTZ/3m?= =?us-ascii?Q?ykkqCaPklmnVT8bdehviPyc60MzTyJNSPjxEJv/GhZoSlwGsoV3AgUY3/A2q?= =?us-ascii?Q?NLNt/rJ4=3D?= X-Microsoft-Antispam-Message-Info: 2F9KluCGnQBUnlfu1b/kRVz7r2MaJKVjXGy/RV0vBbxFxFHG4MLmyai2VFgandxHQuCATJygyj188Gj2DRB1NvP71Lr5N9HfGWB7WONbs84yi2znxuSI19AYYSjz+rdtvgQ9YqKkyrFHmudvKq0aGuQW01Egf7oTUZHwl0JsEFCPQIu+AHibTUQmk1vFKcUr X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3417; 6:XkIq1lqatLzrGQmoeIhjOwf0LSc4xnYwyZiSCup7lg0YhYoAyMoUBOHtuc6b7Tcc6rqNV5ZZI08CNzH8/2MhVD+ZXgdo68vZDS4lBfdedKImaJLkyn/D4hBy6/G6mp7aEfs28ZWeldGnqbLICY6AhI6aKEOPoe70iO9Otr/WgyFEnhebU0StSV/Ry7AcFOvdaqWO6tK/EP7BSrC1WRpCm7fKiRCdxgNcb+lRzfTvgbBXg+NgOaFDJtzfWq1muS86z9NlyCG+/4ny7F3L/HwoeOhBuGUWdn/yo2a6h4+DggwxYohzxdi0jS446QsS8B8yD4F3Z8W64Ip9xpyzFbfRlzP+2mp+DsLrX/pm06YWdiGZzwN6SbhoCRNSwVTIbIBxATTrfccVp0gK5e+A4SKM2IH9N4JjqeqT9eBqkSnvDbuKSlk/SyefCDwsw504wVofXqKSauEnkq0YA0yIL0tPzw==; 5:KRXsx2iBfcdjXkijORUs9FKCJxVfELI5c25ywiUlRkPy0uOwMOBCXlD5okmJCXZqg6OTajv9x95ScLfTF9AiGZPt2ySl7AREdc6Rhkd0VpaNinfKgkkg+rGmQBqawVNPcpXpJuYYMPEZI8i8/fRZmXT1/1KA1AnsoNa/Twdqav8=; 24:X+eC+FYD6SYuEBz7zJcGGJCFB27py8QIKLcTJfp2RZv3h5gA3x1M0uPE+FOojFwM4Wy27m1dws+tQ0A49YQp4Qnxkx+qx64sEh9+YTaf7zE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3417; 7:0jISpVIeF3OunvaD2qb/KZsAzjkf0y1KgSQf/rapqn672HICVa3u8uiuNzbxPFZmSo5c44pDfm+IeoH+Dx6gBVamCA4PC+FLgZ1qQ9WDvaV8xWjoYJIp+DJv3EMEFPwdK5kutM0oD0kIv5PqX1NwIS8RUbrKUvv41bSZ9PQ1YuAmPmD5xNjo0gnPnPZ9CRlaMpcvRZoixpU9a9bKt1/KZLQHiQTjKIiwT3e4trB088WgazsDas9XfmJo3LIrNn3L X-MS-Office365-Filtering-Correlation-Id: 6beb7bb5-6e23-485d-2171-08d5a6df5f6d X-OriginatorOrg: xevo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2018 16:54:25.1229 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6beb7bb5-6e23-485d-2171-08d5a6df5f6d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e0a7ca1f-2458-4cd6-a7c7-d733c07495ab X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR0102MB3417 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. 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 Acked-by: Jean-Baptiste Maneyrol --- v7: - Actually flush the FIFO when we fail to ACK the interrupt, and end the session when we get a spurious interrupt. v6: - Use -EINVAL if devicetree interrupt configuration is missing. - Use u8 for irq_mask. - Stop mixing register and bit defines, and group them separately. - If we fail to ACK the interrupt, flush the FIFO. v5: - Check interrupt status in all cases rather than only in the level triggered case, and warn if we get spurious interrupts. - Rename INV_MPU6050_LEVEL_TRIGGERED to INV_MPU6050_LATCH_INT_EN to match datasheet naming. - Write st->irq_mask prior to device power off to make sure it is fully set. - Write st->irq_mask instead of 0 in inv_mpu6050_deselect_bypass. - Make irq_type local instead of part of the driver state, as we use it only at probe time and never again. - Remove the comment about bus lockups, as I have determined them to be unrelated. - Add missing documentation for irq_type and irq_mask. v4: - Moved the ACK inside the mutex. v3: - Sent version 2 too quickly. Now that the ACK is moved to the top of the function, the "goto out" logic is unnecessary, so we can clean it up. 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. drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 33 ++++++++++++++++++++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 5 ++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 15 ++++++++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 15 ++++++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 4 ++-- 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 7d64be353403..c2cec7508451 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, @@ -278,6 +280,10 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) if (result) return result; + result = regmap_write(st->map, st->reg->int_pin_cfg, st->irq_mask); + if (result) + return result; + memcpy(&st->chip_config, hw_info[st->chip_type].config, sizeof(struct inv_mpu6050_chip_config)); result = inv_mpu6050_set_power_itg(st, false); @@ -882,6 +888,8 @@ 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; + int irq_type; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); if (!indio_dev) @@ -913,6 +921,29 @@ 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 -EINVAL; + } + + irq_type = irqd_get_trigger_type(desc); + if (irq_type == IRQF_TRIGGER_RISING) + st->irq_mask = INV_MPU6050_ACTIVE_HIGH; + else if (irq_type == IRQF_TRIGGER_FALLING) + st->irq_mask = INV_MPU6050_ACTIVE_LOW; + else if (irq_type == IRQF_TRIGGER_HIGH) + st->irq_mask = INV_MPU6050_ACTIVE_HIGH | + INV_MPU6050_LATCH_INT_EN; + else if (irq_type == IRQF_TRIGGER_LOW) + st->irq_mask = INV_MPU6050_ACTIVE_LOW | + INV_MPU6050_LATCH_INT_EN; + else { + dev_err(dev, "Invalid interrupt type 0x%x specified\n", + irq_type); + return -EINVAL; + } + /* power is turned on inside check chip type*/ result = inv_check_and_setup_chip(st); if (result) @@ -948,7 +979,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, dev_err(dev, "configure buffer fail %d\n", result); return result; } - result = inv_mpu6050_probe_trigger(indio_dev); + result = inv_mpu6050_probe_trigger(indio_dev, irq_type); if (result) { dev_err(dev, "trigger probe fail %d\n", result); goto out_unreg_ring; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index fcd7a92b6cf8..1b02d2b69174 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, st->irq_mask); 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..eaa9158ac753 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; @@ -125,6 +127,7 @@ struct inv_mpu6050_hw { * @timestamps: kfifo queue to store time stamp. * @map regmap pointer. * @irq interrupt number. + * @irq_mask the int_pin_cfg mask to configure interrupt type. */ struct inv_mpu6050_state { #define TIMESTAMP_FIFO_SIZE 16 @@ -143,6 +146,7 @@ struct inv_mpu6050_state { DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE); struct regmap *map; int irq; + u8 irq_mask; }; /*register and associated bit definition*/ @@ -166,6 +170,9 @@ struct inv_mpu6050_state { #define INV_MPU6050_REG_TEMPERATURE 0x41 #define INV_MPU6050_REG_RAW_GYRO 0x43 +#define INV_MPU6050_REG_INT_STATUS 0x3A +#define INV_MPU6050_BIT_RAW_DATA_RDY_INT 0x01 + #define INV_MPU6050_REG_USER_CTRL 0x6A #define INV_MPU6050_BIT_FIFO_RST 0x04 #define INV_MPU6050_BIT_DMP_RST 0x08 @@ -215,8 +222,12 @@ struct inv_mpu6050_state { #define INV_MPU6050_OUTPUT_DATA_SIZE 24 #define INV_MPU6050_REG_INT_PIN_CFG 0x37 +#define INV_MPU6050_ACTIVE_HIGH 0x00 +#define INV_MPU6050_ACTIVE_LOW 0x80 +/* enable level triggering */ +#define INV_MPU6050_LATCH_INT_EN 0x20 #define INV_MPU6050_BIT_BYPASS_EN 0x2 -#define INV_MPU6050_INT_PIN_CFG 0 + /* init parameters */ #define INV_MPU6050_INIT_FIFO_RATE 50 @@ -287,7 +298,7 @@ enum inv_mpu6050_clock_sel_e { irqreturn_t inv_mpu6050_irq_handler(int irq, void *p); irqreturn_t inv_mpu6050_read_fifo(int irq, void *p); -int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev); +int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type); void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st); int inv_reset_fifo(struct iio_dev *indio_dev); int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index ff81c6aa009d..672c3df2d1d1 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -127,8 +127,23 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) u8 data[INV_MPU6050_OUTPUT_DATA_SIZE]; u16 fifo_count; s64 timestamp; + int int_status; mutex_lock(&st->lock); + + /* ack interrupt and check status */ + result = regmap_read(st->map, st->reg->int_status, &int_status); + if (result) { + dev_err(regmap_get_device(st->map), + "failed to ack interrupt\n"); + goto flush_fifo; + } + if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT)) { + dev_warn(regmap_get_device(st->map), + "spurious interrupt with status 0x%x\n", int_status); + goto end_session; + } + if (!(st->chip_config.accl_fifo_enable | st->chip_config.gyro_fifo_enable)) goto end_session; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index f963f9fc98c0..b8c5584e4252 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -117,7 +117,7 @@ static const struct iio_trigger_ops inv_mpu_trigger_ops = { .set_trigger_state = &inv_mpu_data_rdy_trigger_set_state, }; -int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev) +int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type) { int ret; struct inv_mpu6050_state *st = iio_priv(indio_dev); @@ -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, + irq_type, "inv_mpu", st->trig); if (ret)