From patchwork Mon Apr 9 20:21:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10331979 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 832E76053B for ; Mon, 9 Apr 2018 20:21:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73D9828B86 for ; Mon, 9 Apr 2018 20:21:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67C4E28BAC; Mon, 9 Apr 2018 20:21:47 +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 629A628B86 for ; Mon, 9 Apr 2018 20:21:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754239AbeDIUVp (ORCPT ); Mon, 9 Apr 2018 16:21:45 -0400 Received: from mail-sn1nam01on0065.outbound.protection.outlook.com ([104.47.32.65]:52960 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754218AbeDIUVj (ORCPT ); Mon, 9 Apr 2018 16:21:39 -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=21S5C/dkYs6kwLQJFctsFb5AY97b2aXG8De1XRLInmE=; b=B1+OjFtrsDuMZWZSE+aWI7+z1L3F4BHAI6X74iKrgzDsK+Vd2vk/jJ+U3aknVFg29Zd2F83Lp/b1s5vbp2A6SwSsleUderGWY4jvapdWbjQUpWgdvwptvfs7umucriWBoDGfTZdU3yHuu9qYY/A/kuTv7MTpvGQa2FwXaV29RbE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=mkelly@xevo.com; Received: from localhost.localdomain (71.212.16.149) by SN6PR0102MB3421.prod.exchangelabs.com (2603:10b6:805:3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Mon, 9 Apr 2018 20:21:37 +0000 From: Martin Kelly To: linux-iio@vger.kernel.org Cc: devicetree@vger.kernel.org, Jonathan Cameron , Jean-Baptiste Maneyrol , Martin Kelly Subject: [PATCH v5 1/2] iio:imu: inv_mpu6050: support more interrupt types Date: Mon, 9 Apr 2018 13:21:27 -0700 Message-Id: <20180409202128.5031-1-mkelly@xevo.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [71.212.16.149] X-ClientProxiedBy: CO2PR05CA0092.namprd05.prod.outlook.com (2603:10b6:104:1::18) To SN6PR0102MB3421.prod.exchangelabs.com (2603:10b6:805:3::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d779cb5b-7b64-426a-f579-08d59e577f68 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603328)(7153060)(7193020); SRVR:SN6PR0102MB3421; X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3421; 3:yRJDLzLWbJB8kj8GaUcUtII9kArlQUTjuUWVgpaIR/NpRraAqglSKVsAEU5p2hkCnAOZ1sdJqa95MqKWHzEDIGGVkLXcgOABqG1t4AsLsBDfAT6IbpLtDyhzD0dsQy4TqlPCa++E8wbrt1Q8Mq5CkrMeGScGApLbhKwi2JpR39283DV0R8xIRSwdx6rDEJkyg9LubVSxL2AWaR4AUZrvKVMyCAUFWsf6fzeg95gVnd5PFWJn7UwRDcLXEG44OGIp; 25:Tizaw715zVANHybokJmREsBmA5FN/eDc6T88SjLl2wGmGbUnapcGb2hGiiVBIglSm2rQnpKKVNB/eejT9JjbFNnabr5FHLEtl3Rv8avm7cYVVcjkCcSi4pBLYGKXgEMpyt/dfAca3dqxdgRe9z1bshmHZ5WgB2l+n4Eeeig20lqh8x1gm0/vJ2wb6XJg2QcdzqIE6m6Rq3cLj2lllCK2MhVuY075PsfVtC7Hhh3zOGbhW+tirjWRpu8YPmIFjAolPHj86eT9w4rUKXcd8NJ4IWOa2Cdlrseq9cYefzQClvZxL4Ux6/DCBe0VVpONwe0fDSwCs4hfmm8jDiIOjIcJuw==; 31:gainAdzrbM1DoTSwvpiZhMZo8ghOdrckZ8NIc74COpcccNXK/UlPldi1PLVZy3FK+XEtwrboMZMrVqQUHB94bNxMJ4ak59tBdzyWSxFN8No1358HLQL0zvXHPhd9xph8vXBKpVQD0rpJCCk05FydeebqkAdVrTAIm3boa4/9+ewMA53S/8EhkJnEnGisG+mEn+4XpiU687BFz0QYnNA1jGUam6tMK8R5hDBHqycCW9s= X-MS-TrafficTypeDiagnostic: SN6PR0102MB3421: X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3421; 20:NR7YDPMFBYb/qXpBRsy5dwCW0nLTfRHX0K8cy+dcFhn8SQYgXSrwmnvGkPz8lV3ht0fyF7Bl01mZcMqFhoo3sSgW5tvsURBvsrkThMR4yiQA+zi1YjKO94sB5BYwDIBjldk/SXLWi0+T9E/svs0JVDMHWAygTRVIz8BwLHzCc5VLYGN5ul8WMvKRycNwDYV/0o8fnC4npygeYBP+3nFn6YqnZXHBVvZgg64/ggEzG/aa+UNISPg1i4y+KmzC0OQP28WanfR5g/bm+Q7jjSEtmJq9U5u8ZP5umrs68ZlbgOr4o3P6ibc6qYBq7BoHiKzUBQWVFCSL7uLblaj5FmU24R+vT4a8niEOL4AlRmP6VeLfnefAT4FPt6UTTzSnLR9CZhzgC/wk2gEaPjsEOsREiBEfgpwAiIeSObtgqczSIDKwVqiSfMQQVwmzXQokJg3ZdZA5vPkECjN4ZTM1zc1oQpA6kK7JOriTfeQoHbkOpNLtQADlqYEql0vpwAfRLJud; 4:qs88jJGdWs8QmJLZuZxwHw+4aFPxWBTQNvpOEIe+nUpqAWLI5r0J4dGgt8Ls1CW0nsEwq59YtMsA0Tbg71u05KktV+iaIp7UsrOdtrGE1ObhfiXrzv9TqNVyHH2Pi/+6PxjaYgS/tygvBBy/QVxObwfH3qEXAl9b07MVTmNnh1ayhXKZ6NuK4cOC1lKbJkzoyuF6lQAvqJVZW+mdqNFPmyAL5dIkujVQ6etx25gydRnpy/GlJOYzZBYG6TLabtXHm4LwAxxVakw9h9m4piy+OlrL9J+OXY3V5amX7j8yRCVXWaiZ/Hld49OvJ3yDZv9m X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(3231221)(944501327)(52105095)(10201501046)(6041310)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:SN6PR0102MB3421; BCL:0; PCL:0; RULEID:; SRVR:SN6PR0102MB3421; X-Forefront-PRVS: 0637FCE711 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(396003)(376002)(346002)(39840400004)(366004)(39380400002)(189003)(199004)(2351001)(1076002)(26005)(3846002)(59450400001)(6116002)(386003)(51416003)(6506007)(52116002)(486006)(106356001)(2361001)(2616005)(956004)(16526019)(476003)(186003)(6512007)(81166006)(8676002)(53936002)(105586002)(81156014)(4326008)(316002)(107886003)(25786009)(54906003)(16586007)(50226002)(8936002)(478600001)(5660300001)(6486002)(7736002)(66066001)(305945005)(47776003)(50466002)(2906002)(48376002)(97736004)(68736007)(86362001)(36756003)(6666003)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR0102MB3421; H:localhost.localdomain; 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; SN6PR0102MB3421; 23:5pDO+nIa2ZuJqzaZN6jjUsuHHdSTTG+SviHuKu2?= =?us-ascii?Q?qylMiUHTgmMJisECB0sbYRYnRkF2ptVGbI95AE5tygPcHwvLpG58/1WcKU7v?= =?us-ascii?Q?WNjLlYb5eDHM2hBmoLsEBy6cKSFF7bEDEyNMNnO+NdOGQjTI0eJZ03jcAK6+?= =?us-ascii?Q?4inzbmfBrApA+zy842AZ9MqvlR0OVMT0ySyQMOBpI2502FuuGIa1BtmSqkke?= =?us-ascii?Q?Q9JrrvkQKHao7x3Nu6/ymrgt/kJSfd6ACD/UPnWFzsEyK6+uglP1UphE6ssA?= =?us-ascii?Q?41qtzpZhKkzqgmnIHCGS7dlL5vwRZXRP3vRDBiboCEOmKKcDSIn3FnwK0Dbf?= =?us-ascii?Q?GJD4vQ1JB2Mb9sMx1d8LEIXEMMwlNXmeKZgru7IyF/rcB3do95oOGL8UsR6H?= =?us-ascii?Q?1+bXfnq0HSqYdMHg8o2ckvXYkIvIGwXskIJ4lMo32CD55buHywOBcC0p8Qt9?= =?us-ascii?Q?DJG57rwN4I5N09RGlwBzwVUWhfMEFYwUKvEWLhyZ9t4rLedw58dF7nVCAhQF?= =?us-ascii?Q?tityGcPODNQSieST9bhyaGUhmokmzv7ik6KYAB/mEuuf/btydpKN4uWWaFqK?= =?us-ascii?Q?5xE319IOOz7S7dCpirNBFECua/gA1NO50DpwLKOkNPIKKXerXGnfoXANrgui?= =?us-ascii?Q?J8DPWm0pfFBQ5heOBoezA4lRxIjQNLHP+eAF0aK92CwzAVzfJON4IQnesC0V?= =?us-ascii?Q?CpgC7EbL8SGnSMHa1eenA4m9bGGUOOzgUkg9+M4ftBnayCDYbrhqBrc2ypas?= =?us-ascii?Q?gFhbxyzDWF80SiL6XsHvIGNSK4u6+tw8PLBqvNEP4jvIv2j0L7WNDj1sF+uX?= =?us-ascii?Q?tinuUaCMDW8P4+ozPVj0lrC2hUJ3PWrgvIsYvruB9Fxj5XBA86jgy+Tq0muN?= =?us-ascii?Q?gK6S12TlRgYSQ94MaMk2xYSdkkKPzd56HnPw9IBK1AVB8au36tqn7cKwyu31?= =?us-ascii?Q?x4CTVWwCU3MK1W2lx+0PfvMXwCodb9WJj/zxgQO6k5N7T5tjx4jltDWdqoXd?= =?us-ascii?Q?YFNmyYFmeYdEFJdPcf43Jc1uE393VEtXhzgEhxYAtGB0Fob0rNuE8cA6ysSV?= =?us-ascii?Q?QeiovpFzTjxNcTVeeo6YilT1e6J3+kpYzSrievReeSsl9QhGixjpyAljEyQi?= =?us-ascii?Q?O0zK1f/qB4exUNfjB7YjZI492EgqGu9RgpsJtoNpcToI+PNAqqidL8yqZM5t?= =?us-ascii?Q?REx+HS0y6cr3L+Xu1A6Ss4v73SujeT+N5sLOSlT4Q0Ckhgo4CsKCQyRYoz0J?= =?us-ascii?Q?HkpnsheOAa1wI9cyQXecQ6f3ATfxN8luCAQvZrKsA?= X-Microsoft-Antispam-Message-Info: 8YW7yk54jhUvP7/Jd8cpZtJ3mqyME+MN2mIroLV29mHrBcOwctKFbBoEvl5jFf1/TvWVC233KDZiGUsosD/44unsX9WJu/GcTu6OHIfpUPZOyQKT41qStxHaQHeQqN1IgdfmRK2f5qbe/90QCbZXxmepZRfzvrGpGU/5ijSOFRW7F9t6jMY5n1W5cd4+EH5W X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3421; 6:A/EdS+6bMfSifSmizauaIdRNGmivEZ5wORhyheb60AH7qW23KA8cjnunYVceq1x5foaC2BLU1BKlpZizgUENC5sHymHl2KcOreOe0v6zTXQmwzQGa0AY2TpbpzEO+0gMY0N4afRswurx6eUyQ7DhZOtkKwKC3DqKi50BZGKNfTmDQC2NI2DDuxuzj5Pn+LfcOyq87hI2RceHVkQuvPPqLsKWQrmgkUDRDcTvIhDFGc3mo9ymLI8pMcgcPlqnik1UC63J6ETIayu0lu2uhhBITZR8X2JFa+XteQ50qGBGHAFsZogRga9Cc6l6UAQpRSduOSowHsIewHqDq9momwioHq33Mjiu3S9/zj1buf4hCqiC6HhWCa0FMihActSF/J6K1H19ONEGHYb9NF/gu6MPJG98oTRyU9I4vMk+IOqAkyEDklpCKY5eCCYFjq47KX/knDXZoQuaizaDqXypSm3TuA==; 5:e7q+KtBuZbS5M18DnSGzw7A0DymLkRo30eBej0+t66jalDrS79Kex2PgTalVF30zRAArlM63okLl6qDPaCwTSEU8F5obUOrT1K2zmQ494r5Vy/Krld7RmtaSwgOL2ogCbZ5MquXpVEEK79wukrq3hk/hZ0LKtckL8w77gaGQGeY=; 24:H+OHSm9IJDQAeQ3ydFGrvNKSvijZUDLIDh+gr+bCD9iZL1ygaGHMsmnKl6lqjfXZf2R0yCGgcLYSsseB6jYyL0/QkSMUhPPDFsYQFFptWE8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR0102MB3421; 7:yw7WqU1PPrwj+QsZ94jLj8hmkV3B0smOoxyOknCQCruvuMxmhPyY8rFqMfEl3OtXQYSm76sZLGotlAZvuxNcZh10PPBtBlaSmQ4oKfH9GPeesHiPOBxTFoUcpCA5li5F3ilHPbOD0iG8itNfeRYdI+/QMSIhlMXxw3bcVG/jSn/D72vWAR2eK97AAiInACbXVQ6N7jNWKcM33u/g5rlcZsRrQ9ZSoUsTFAoFT+6Dni3ZB7rlPwFWhT/iLZV+V0fg X-OriginatorOrg: xevo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2018 20:21:37.6127 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d779cb5b-7b64-426a-f579-08d59e577f68 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e0a7ca1f-2458-4cd6-a7c7-d733c07495ab X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR0102MB3421 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 --- 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 | 14 ++++++++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 13 +++++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 4 ++-- 5 files changed, 61 insertions(+), 8 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. 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. v4: - Moved the ACK inside the mutex. 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. -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 7d64be353403..b711e6260d9a 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 -EBUSY; + } + + 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 -EBUSY; + } + /* 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..064e3b28fdb0 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; + u16 irq_mask; }; /*register and associated bit definition*/ @@ -159,6 +163,8 @@ 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_RAW_DATA_RDY_INT 0x01 #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 +/* enable level triggering */ +#define INV_MPU6050_LATCH_INT_EN 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 @@ -287,7 +297,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..8f1f637fb972 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -127,8 +127,21 @@ 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"); + 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)