From patchwork Fri Apr 6 22:00:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10327619 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 8B0086038F for ; Fri, 6 Apr 2018 22:01:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74CFA2955A for ; Fri, 6 Apr 2018 22:01:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6981E29684; Fri, 6 Apr 2018 22:01: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 8703E2955A for ; Fri, 6 Apr 2018 22:01:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752170AbeDFWBM (ORCPT ); Fri, 6 Apr 2018 18:01:12 -0400 Received: from mail-dm3nam03on0071.outbound.protection.outlook.com ([104.47.41.71]:55028 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752114AbeDFWBF (ORCPT ); Fri, 6 Apr 2018 18:01:05 -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=4FNHQvrAKf3iwantqum8HaUmS+r+aTN3s2tNLCSjl0M=; b=dfSL7kSIIeSo75iV5xNLzI1iqhPhcbZn1t9O1I1HrTn2gzcQ7Y3cFi0ZQNk1qReGHmiBwDYmjSi7Bz9nA1tjJPbdlMfZFf2d++tfKIzSs4oIDJDZhZDf7DimOvWgVHpKpj5/T73LHwmwHVpOEjuDtA8GKls1x0rNnG9xPyAlmbU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=mkelly@xevo.com; Received: from columbia.corp.xevo.com (65.122.179.226) by MW2PR0102MB3420.prod.exchangelabs.com (2603:10b6:302:3::13) 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 22:01:00 +0000 From: Martin Kelly To: linux-iio@vger.kernel.org Cc: devicetree@vger.kernel.org, Jonathan Cameron , Jean-Baptiste Maneyrol , Martin Kelly Subject: [PATCH v4 1/2] iio:imu: inv_mpu6050: support more interrupt types Date: Fri, 6 Apr 2018 15:00:47 -0700 Message-Id: <20180406220048.29498-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: BN6PR10CA0021.namprd10.prod.outlook.com (2603:10b6:405:1::31) To MW2PR0102MB3420.prod.exchangelabs.com (2603:10b6:302:3::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c1d5e03d-0b59-46c3-f42a-08d59c09e2f1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MW2PR0102MB3420; X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3420; 3:Q7OURZYKJZPLQxS8SWqs+Zue9MceC4AdJgGQ8xPx7ZyXcqAOLNEeezNtfQimN3y3msvOgsADF0E/Bp2uNP9qLOqYOuJP5LmCOAP6pMb2dwVjoj+A5CzTExtjb+DtGNCtHl/l6QRXOm/KbFIpb7TJHup9USy9h4uvWVuS9F3Kk/d8McMCEB+w43fgOvk+WzoVWY1u/2PLMUcyVe24yvQLIeOs4/EQU5r6daXTq+uKmBZppbf3ibow2DGyKsGpkXvG; 25:ZnQNPQlaXr0RUS/yiHgN74A5b4Z3P2Jkot7SDuRDfuZWQByQVNd6VFSXK4Vg4gLrTBbSiw8/NxRumB+1cGULzrXdQEW0mCY34F7cU4J/YGXFmMKWbT/9kzZtICDpPWijI8Qovh9RUlKJ0Pp8kR8uILkeDMrwpz4pzJBp3XkDVXlDXK/v7G4uwEnmjwMa/2l7iSNFnENv1MK/ERmFAASz4xpXkpeDoJFbQXNRhNUMQW0XeP0uwUUSD+76ZbDmpPOe0fvij/KKsRi4OK3UxVxaGG5ShU4Lm8mvayg7FIkZZhWyH5c4IsAIWRgKAM4QZIGb5Og7L03FYVqboBxvqhz11w==; 31:k4QBviHrlwflGBvT1MyRwcDc1l1VD1tW18HtYZv+/jeTHEYeO+eTwWqF1b7SqrYuBGAWx6y11zrefKoWEcan0f0nw/sE8mWTk9aGfovcARZ4Gybbn2bZrMQOvltSCj0voBv5AtLf1sEwKqWL25FpNRdBqlSug++pEmKxZKGgh5dNVo09FRRyUBguerGV6R6b9jieb5vf/zuV2M+f5ec2PTDiXP6E6NpUD52p8b1rUvQ= X-MS-TrafficTypeDiagnostic: MW2PR0102MB3420: X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3420; 20:4o0EuwsCb46rD7ANC7wJuy+FMU/BDh9gubTRNbzG4TZAkdei8BF1P/i7oipAAhoKjIZ9NNbC5UDB6ReDD9n/clC3vuJzAs0knAvSRti1M6hgTHqGojJxk+OLUdGZale1eU65F1VPCklMSomzoO4la8Y8ATon6hkFMtdz3VXnEQjICYX0knrpv+0CjKvz3Dmtq/3fKIM3WyJo35SlOhyjRZ1Tu1sO7YVuQXC+zkBYFoKaZCoSxXGmk3iuICGvfXSskqlc08mw6SwT92SD35b7X02pMoLXbESfAHZRZaygR4b+edJc6DZXaoKfHEoZkeNFAXiLRPiQK4CXeUGzc7h6tM3o/wIml8qwcZHbg2rmmIZazAZxREaRq66i8kkmeVzJ5bCtaR8u8dzeEocGmNO1WBXFsWqMSDzLdD8BMHqlvVi2mvvCYJSF10aKzS2TFhWL6V1EE+/hVJ2Fv0GIy1ZIRVYVhej5ua7dNTGn8g+dIrc2TR6Pw6IcSfTav47aJS6o; 4:RJX+Q8aKkUhFI4IhdjgqWWxXqwouaz7Qxhbrd3JUNwWmIodlhpZYeOkWHm3SlSNnfSLjiwz9bVgJVa9LA04Lcd4G8qIUUaCCqSKw1eOii71GQugPBO7btR6yFElt6yjXjZ9jGZzmUeG4rEXJwIGrneuhaxYwSj7sAj4VGgLl9NEBuCBhqWwS9yFmY1PjYue5/apAqgQ72DkHgUcruqJk8qA3rsuRxaPox3ZWjzcdfwYfbSkJEv8VlOJLEkLE/XNdQUE6E8YvDxZOfdcl6x62BoI1CqB2xPOj15XRV5J51615HNBJ9/7xIIrNUdkDshze 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)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:MW2PR0102MB3420; BCL:0; PCL:0; RULEID:; SRVR:MW2PR0102MB3420; X-Forefront-PRVS: 0634F37BFF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(39840400004)(346002)(396003)(39380400002)(366004)(189003)(199004)(486006)(51416003)(106356001)(478600001)(59450400001)(2351001)(2361001)(186003)(16526019)(26005)(386003)(7736002)(305945005)(48376002)(47776003)(52116002)(86362001)(25786009)(2616005)(956004)(50466002)(6116002)(3846002)(476003)(5660300001)(316002)(16586007)(6916009)(6666003)(66066001)(6486002)(97736004)(4326008)(53936002)(1076002)(36756003)(8676002)(54906003)(68736007)(50226002)(105586002)(2906002)(8936002)(81156014)(107886003)(81166006)(7696005); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR0102MB3420; 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; MW2PR0102MB3420; 23:xQc5G3nVdK8bkUQ8ZRwtm9euLPIVQyEvcBlsHC1?= =?us-ascii?Q?1lOj9FIm+DnR7FLv0Pq66EYsiMnT02NB7O2+pESpvAOKlYrDf51H2GhnILWg?= =?us-ascii?Q?hqv+SAjgJeE9k/c70HE62ZLvQRmenP/yrseKBCwpASJLLNk3aK23gVSADfk7?= =?us-ascii?Q?btO9lbkYBP88DBuhRec5Dr67DCvzhbjhZDW2SN0FTOe9+tKeUf9EcwiOtGMC?= =?us-ascii?Q?PkLPba3cMRGnecf4Gal4xmHUQq1sRKALi5m2kxF/qItdUESCxvTqOOj1BHAW?= =?us-ascii?Q?vQAmTKoItlt4ednUBt2N/nDX+dUhyhKyX9R0VH6tKt8sPepo5X5L5BZtIJ1v?= =?us-ascii?Q?Narhn0UfYmjOI9cIYe8XKUKRgTqZfYFGVpl6Eq2/dNfbhDbnTa0PMOHxWFLn?= =?us-ascii?Q?o4QVS3mW5byaAeoAbmmbM9L6FYjJq0vX53XWQuy6OnMKhIDgwVE6qhrbOmu5?= =?us-ascii?Q?Ik1xE3ALKiE+IjdDvEWDoUq8CctAQR4SEmV3NClETWexDLYsM7zDk4BFtEP5?= =?us-ascii?Q?E2ytcne9AIEhgFhw26+RmqBkcqvkOzcRihpcd4Wb+viJM3eU5Ndlw5fn3I8+?= =?us-ascii?Q?pCNYtP6P0WOnCvnw6VVtOQ9TZG/Xao7lYv6P8DLU01u1g3FXsRfatUH9qjbn?= =?us-ascii?Q?6iSfIDIANwmc5ZNOOW2jQUue8p7zw7gJUeYt4tZFOxbkQe+nfMsotnniJP7x?= =?us-ascii?Q?/eqR5U0IlpNx1kJJWee+v6Q0w3/gp6VvzpBc4UjWOTVu9tS3PbVqJXpRRMPE?= =?us-ascii?Q?bv/hphkwiUykGb52RzDRwG3S+XJ27pcGk8lpK0+Fs91VDgESgjvrOCEj8Rml?= =?us-ascii?Q?GhCbEPExyUDVIQqNugqb3XNqazvbUiXoGHnTfXcLd2h1dH1FmkDSgnzBCeyt?= =?us-ascii?Q?F0EwUMpLtJpWszzlFbWXcBo0RfyJ0vndfUCXoNc2a1eQU/VFtlJFU+GcoJ95?= =?us-ascii?Q?mSSSD6AbIrHVBMsNAWpK7t4vkUUuI55jQ2y5VqHJtFn2cGqxWHv1lpBDj/jG?= =?us-ascii?Q?uq6Snuz5uK1v9/UWAVq5RgsmpJXNknVt9GIggFBwmg8j3J4VG+WMeafWHM9D?= =?us-ascii?Q?KCABS3AfvLi6SI+HGy0NgjVZ66FhJ/tca8mhB2BX+LX8UyJciZ4Be9eZPO02?= =?us-ascii?Q?fmYeUNTnit5Tzy59wtYEXXv5kD4SQp4Wu7xthIajKq3/GkmHYUjFyx0qfjYx?= =?us-ascii?Q?9k+xntTwkFRKobDoDsZNLO4o8rHn0A/kAKM9toXj7UakMmc0sendOccuaQw?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Antispam-Message-Info: DTY97cOtaCcObByPRkzt4anzo2INoT2iKMypBV7ToVbcw28TpGOIDNF4eDtVceTB/DKnWk23xMk1yUsKGBXg9BXWHZtCbJlPo1lxLuYRemv1lmC00XamSKXEHHnuijlAZHOZcSvVnZDLFNUWljl7CrzHgyCNQF85pe0PEjCCP14lt8fAkeBtuNNU1zmOQ7RD X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3420; 6:N4RNFkT2b/o0vr9FG54zBK1BcHi71UKEfSuVse5yN4xk7PTtW7jCM9cr51DEYsaDzRNyXTl1qh/FGvse9WAsYWQiEecMtN4wa6O8Mb1bwMvVg4bp4ZClDWyJGdHmRFCxlFoczuSYK7J0zIJxWL6y3cQlRzvVmXYQpzAwUzoZWSS4eS8htIvmBC+xKvb1fUK1IyTLwuBAtAkcJJbdb9nL3JJMFqlQMtN0mF5d3CF5l55Yy5pxXvxtCs0dtPbZFfukr9pCuwCgDCm+E3lH8TbiVZWnVuv/rQkIadz/4jatZV666mQ9GN9Q+XZRwtZS7o1fnefsTtnIrLKCUL/7wEUUcB7VNjqGwWBQ3/Z58PJPaKOKoBV52jvfaQ7oVPXp0Su4pFLwtww3TaHmygX14VeBg0JeEvJJ42Jdu8sfiOyE5qHcO8mi2nMh5XrEqc/AdaQHmFv+28XiWMP3AyxTj+50Zg==; 5:vXMw2xw126p9WkBbdQwM9g1M6c8f5NRauY7+IpSA2+x7bZqUEspQE9Z/ggPHeivHbtYCt6ZKIT0ZBY7uGsJVNRPoj1GdEc7VcSsp//WgHqjfybK1jV94rhuIHnX1JQPolBDQpxebfiOSAwoECPsC0XnWA7F3Ux6tiIfcOMsXjKw=; 24:PbMNVc+ImoA3278nzbCTLJLW/9fbi/2IGgT6V18Ago4ATu/X39xn+uH3p0p/40AS8ZfHVlXBmeX3AEvVAJ0L6Klo1GM56PayxTfUvkxHGd8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR0102MB3420; 7:4bjYXW7hWoeqidtDSRUT3r98h2OlDbGH8iSqP+ZKBfGA/928tgAee+OR7JYNvxCRAJlG4f6TjplNXUPmQLokI1mnNZ1TEtNwrYhsUx9BdKqkjwyjSWwrvmMOX3WkkAHrYmhYz45pAIb9hu87Bh/Oo0j1m+UcvAYg1nPaGj0n/Ap7TqzLu8fR/uJqeSL39OQuXT+AXBZfSylMiaiLB4WlUO5evIwd82NolM4lyniSQabMfZSftx5025KuE208INQX X-OriginatorOrg: xevo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2018 22:01:00.8783 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1d5e03d-0b59-46c3-f42a-08d59c09e2f1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e0a7ca1f-2458-4cd6-a7c7-d733c07495ab X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR0102MB3420 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 | 9 +++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 2 +- 5 files changed, 59 insertions(+), 5 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. 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..04dc4a11a9d0 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -129,6 +129,15 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) s64 timestamp; mutex_lock(&st->lock); + + 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"); + } + 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..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)