From patchwork Mon Apr 30 10:14:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 10371341 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 4780A6032A for ; Mon, 30 Apr 2018 10:15:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 371512896F for ; Mon, 30 Apr 2018 10:15:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A00428A0C; Mon, 30 Apr 2018 10:15: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 9FDF22896F for ; Mon, 30 Apr 2018 10:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751446AbeD3KPB (ORCPT ); Mon, 30 Apr 2018 06:15:01 -0400 Received: from mail-sn1nam01on0056.outbound.protection.outlook.com ([104.47.32.56]:18131 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752473AbeD3KPA (ORCPT ); Mon, 30 Apr 2018 06:15:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=C+NTKz7fSzDqS1qijWl5HZoVsE7iNJCFm4sYtr7QEmU=; b=h1J6btK1PFfzETDhLc2uB5CAB/+RCRx44rD0QYiO9k1i2yzcQgqYnwQshFalRBHrsrh3ikI6byZA4ArZN7G/lJIQMnzpo2qpbMvs7NpWqCAHgmhguI2A6AB8m55P92Xbb3R0UoUh3G66ICkWDmfKwlDeG5fMx9xJ48jdNKnXHKU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=JManeyrol@invensense.com; Received: from frgnb-l-34296kv.invcorp.invensense.com (2a01:e35:87fd:c140:3da3:d062:883a:d6cf) by CY4PR1201MB0183.namprd12.prod.outlook.com (2603:10b6:910:1d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Mon, 30 Apr 2018 10:14:57 +0000 From: Jean-Baptiste Maneyrol To: linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH 3/4] iio: imu: inv_mpu6050: skip first sample when gyro is on Date: Mon, 30 Apr 2018 12:14:10 +0200 Message-Id: <1525083251-8368-3-git-send-email-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525083251-8368-1-git-send-email-jmaneyrol@invensense.com> References: <1525083251-8368-1-git-send-email-jmaneyrol@invensense.com> MIME-Version: 1.0 X-Originating-IP: [2a01:e35:87fd:c140:3da3:d062:883a:d6cf] X-ClientProxiedBy: LO2P265CA0031.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::19) To CY4PR1201MB0183.namprd12.prod.outlook.com (2603:10b6:910:1d::12) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CY4PR1201MB0183; X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0183; 3:p0hDdPOpWvS+HwDBY8tOCIf9/zUWRa7UGXw97MuMWDCMUh3Ud3WVeur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jDSjJLjLwNtcX2wb0NNW2xXWJENsrXiSpbR0G5pIDCwZ+54WLpqu9FNr+F+I8fq1oVpqQ+n0VLEfbvxr5VvomCjhV7Hqnek2DWxZXFGXK4pLZfitBJvPg5A5GzVTF2HAJTXl2LQ1wXgLshjUJC/h84q9JRNPosF4a9DgjNHyxKKW/EFp6mY88vm18688iFnPdJEz/WihGryissyXve8A+kbaZQt9+mS8QyaVe36A8hRflLov6MCq4vdzozEJUWETuOxAjIU4BIqzIGIoa6rJOpFn4m; 4:opWibHC0CNSuMFCUb8UzKDOUfGYzCvGJAOxsHiBgZUDrHem/x9TZywEoCmRV6+V3jpGzpXQh8iV2UuG9CreCc9i+h6g9rk0ONXhqRzzQo46+tbLV26pM7UM52XeoRrhaJZ6k9qwPL21hqIjY+8ooEmyMeCzVIce2YLg02Fo/6VFLkppoiTupkn6Bv6KLLvTVpAjtHZe++mMNmDhbzb64VApo5FDwxKCQgRLw+MTVBwqetFtwVy4ntOaE8sHdq5ay3ZnU5c+GM35zhKvniJMehHQx62ElpTijFMthRWuLE8BO4ftUudX2D8XVunkhThR6 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(257004950022427); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(6041310)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:CY4PR1201MB0183; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB0183; X-Forefront-PRVS: 0658BAF71F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(39380400002)(396003)(366004)(39850400004)(346002)(189003)(199004)(5660300001)(6486002)(7736002)(305945005)(478600001)(47776003)(2351001)(2361001)(72206003)(4326008)(106356001)(105586002)(316002)(107886003)(53936002)(2906002)(50466002)(81166006)(50226002)(486006)(80792005)(7696005)(46003)(6666003)(386003)(86362001)(36756003)(16586007)(476003)(97736004)(52116002)(8936002)(16526019)(6116002)(81156014)(51416003)(186003)(11346002)(8676002)(446003)(48376002)(6916009)(68736007)(52396003)(25786009)(76176011)(2616005)(59450400001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0183; H:frgnb-l-34296kv.invcorp.invensense.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: invensense.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR1201MB0183; 23:KRrSjA2KY+KvVIiJdIEqqA+ehJIbOV4h53+T5rf?= =?us-ascii?Q?MafrTv1PFEtJY/SDJDNCCTG9ANPC4BXoebYmwsQOM/H/V83d0kUENhA9qWiU?= =?us-ascii?Q?rdSJtMskzKxD+mcO82js6VNR+DLWRsZ3yLqbgTAOffRrw3iyrgK0cGtsdl2n?= =?us-ascii?Q?LWOzUqxgD8VXEPIgtxSj0TYO6CJ113PLjgo/Eqk0r8ojApY1ZdCBKyzLTiBH?= =?us-ascii?Q?QquYwSrJlEejKk3GN45rdfmxQBMupNYhWF8q3Jh4ym2ArRQ27tz6Cy50LP9n?= =?us-ascii?Q?vI8r8EA0oD3VadgQs/S+zYotbXZuCmYKR7XF5953Yf647nqlfzUYTMSTjwZm?= =?us-ascii?Q?KZayq7T519/Oz3jRnWqqzcmlBywU5SwFq+ZUvr8oZxRbdASnW5cdT+Qkzesc?= =?us-ascii?Q?txJa+KesF7O1Wp4BAGZalp8Z1T9nsF4eWEjfUoMRdbcw4bCmepiKKh3BfBu2?= =?us-ascii?Q?7lBsc2BkhXrszd6rItQ9FF3W5HvprugX/WtGQ69or5Uj28xFwDQj7MbdtIeu?= =?us-ascii?Q?OKWo5Dh3PXMiE9Vc08uaavSsB8/SEosznDvHXy7ZLnOvjQhGGnfuKfciqHXS?= =?us-ascii?Q?+99ZPXQ8/lDh8EtG7xLr/BYKG7ztKUTh6Im6X+SQwmrve2VwmK5rumeukLPj?= =?us-ascii?Q?8PqQ4r3w4DEF2ZpT1LrdEakbAgkCUfEtsPZv6ptJKSF8o+NByk39qKC7pUZT?= =?us-ascii?Q?kaiBW9G0L9e5qhIeB80bxKlI4nBAzSpt6dy4lidr+EnztMm8GF2mn8XA4F/Y?= =?us-ascii?Q?cPG7ldHX1UBBLvz4UW0kepspasbUnQrP3BHZ0hL9csg5zIVlT4yI5i/dFngT?= =?us-ascii?Q?Z8YvZjYdueJ5UJNcg6rk+NMxXG9Gc6nj13oYAb15dFuSXqtCOQDlqjHGd36b?= =?us-ascii?Q?SXxYRMlnvVXED7PNVv/1XR9nZoLyEDjfToBgpru4rTYRV8JMLDNXkAQvwptg?= =?us-ascii?Q?zqyfkcWSaJRzwkgmEcDZT6v0JRtVBpoBDk1SZZ6U8foC9kYEffGCkzq8hLOx?= =?us-ascii?Q?jxTgD66aEb+RbTSJpkYkqNKpk4Z85tikh87gWJmx+QK5QNZarVMSXfg2/kH1?= =?us-ascii?Q?zqz2/ZJWbQmVVk+25+S9QUHjcmIcaPv0KEKi93EA0UsH2UdFlHAMPg/d4tvd?= =?us-ascii?Q?uI0tcGP+HZdMNsoxMmnX332eGso8zKbupAZ1i2oBNYZIUp8wb0okiSDETsty?= =?us-ascii?Q?UtaYbeY2vxOtlcSMhJYgTiOb72y6u8bl32K1vq1bYOv/A8wgsWkyDp/NS7ON?= =?us-ascii?Q?UvU4cOMEkScJt07WT6C8=3D?= X-Microsoft-Antispam-Message-Info: 0tRx8dWgwUmiNbmXHN6TFHQc5+iGNf/dykOPVK8ZOlyjWdtGgoZxvOK46gFXzwooFvyuHeOwmri93WAi0Sh0lUBOeLjgB3NjVRZhYnB4Ti+uOoOK4Q0lfSrCfUalRNl6K28J3KTyqnS5pp+25s+XiTV675ef9YMBDx3XbvP5IGwf/5oXPYzWDkz0Ks4shwUX X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0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Mx3p+QZh7ogQaq X-MS-Office365-Filtering-Correlation-Id: 8d728cc3-9984-4230-e0eb-08d5ae833a8c X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2018 10:14:57.9521 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8d728cc3-9984-4230-e0eb-08d5ae833a8c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0183 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 Implement generic skip first samples mechanism and use it to filter out first sample when gyro is on. The problem for these chips is that the first sample of the gyro is out of specs, because gyro is not completely stabilized. To ensure all data are within sensor specs, we just skip the first sample when turning gyro on. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 1 + drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 7 ++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 142a835..dfb9e4e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -148,6 +148,7 @@ struct inv_mpu6050_state { struct regmap *map; int irq; u8 irq_mask; + unsigned skip_samples; }; /*register and associated bit definition*/ diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index e51404f..1b57354 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -185,7 +185,12 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) if (result == 0) timestamp = 0; - iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp); + /* skip first samples if needed */ + if (st->skip_samples) + st->skip_samples--; + else + iio_push_to_buffers_with_timestamp(indio_dev, data, + timestamp); fifo_count -= bytes_per_datum; } diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index 8a9f869..0d7db27 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -49,11 +49,14 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) if (result) return result; inv_scan_query(indio_dev); + st->skip_samples = 0; if (st->chip_config.gyro_fifo_enable) { result = inv_mpu6050_switch_engine(st, true, INV_MPU6050_BIT_PWR_GYRO_STBY); if (result) goto error_power_off; + /* gyro first sample is out of specs, skip it */ + st->skip_samples = 1; } if (st->chip_config.accl_fifo_enable) { result = inv_mpu6050_switch_engine(st, true,