From patchwork Tue Apr 17 07:19:39 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: 10344449 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 E0E9260548 for ; Tue, 17 Apr 2018 07:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF35728A0B for ; Tue, 17 Apr 2018 07:20:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E3FF289FB; Tue, 17 Apr 2018 07:20:30 +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 D80E0289B8 for ; Tue, 17 Apr 2018 07:20:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751096AbeDQHUK (ORCPT ); Tue, 17 Apr 2018 03:20:10 -0400 Received: from mail-bl2nam02on0063.outbound.protection.outlook.com ([104.47.38.63]:8858 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751085AbeDQHUJ (ORCPT ); Tue, 17 Apr 2018 03:20:09 -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=A3LMGkretiYoMOl8Vy8CSfSUI2B18OcmYeIEe1QzER8=; b=AmYolgEin+4jwyBdN5ha0oOdiL5cvWwxK7idKPRnJ3K2TwZ1KelF/79iJ7LQPzTMJGqNolt9Li9vH1mNhFesBXCz8ShjM8/7zu6fX6Z5/8oKmqBZ8sVBwPH2tlf9PZFx7E+EXHn9ONotiBWwGZkSPY03bEAJ7MdxIjUNUwL02h0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=JManeyrol@invensense.com; Received: from frgnb-l-34296kv.invcorp.invensense.com (92.154.85.143) by CY4PR1201MB0181.namprd12.prod.outlook.com (2603:10b6:910:1d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.675.10; Tue, 17 Apr 2018 07:20:06 +0000 From: Jean-Baptiste Maneyrol To: linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v4 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage Date: Tue, 17 Apr 2018 09:19:39 +0200 Message-Id: <1523949580-18016-1-git-send-email-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [92.154.85.143] X-ClientProxiedBy: AM5PR0701CA0071.eurprd07.prod.outlook.com (2603:10a6:203:2::33) To CY4PR1201MB0181.namprd12.prod.outlook.com (2603:10b6:910:1d::10) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CY4PR1201MB0181; X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0181; 3:RQCC8uiBr9PB+3OPOkQIm1BAOx5XSQZ6jSyr2AnXkPFypKcBSX0DJYN89yAW/nSGy0VPJbuBbbxy5awH9tCIdFssvpqRHQIIQjLLQfnIe68xJvA98ykt6PpeKrHeuaDIOq/cRT0k6CQ5WbI+J3RlQW7vNxgxjYVsOgCXb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VM6QgI0/5vr0IjLWYmlNJZyysNhE5HTPwI8kibZwfvaiZwoY57rmuMsR6m8T2vr121mRueKb/RgPkxjH6JWtB8B+7dqe1YJMTVLpDUNflhTa3MfFe5VnB9tCU663XwHaJrPJS16Suf5njC9bpg7GZHKcwUijTisu8SAU1nKP5ix7yis9wZBafSnwbsHb; 4:FFW/SSJDFYi13MhfbAYubHUH08Nnkc9DLF9oaGWdHC/FepLPJWDY3xz7hjXbIRyT/21cOV4Jk7uU1wM8pUp6ePNcHZoTO8IlEQt3Z7nF3HppYxP5OpKuRC+W7M0tMCVOqwhavaP9e/QHLHSIP58i0f5gy62aJEZp+ErcFn75idU93J9uKtPd0OnZI1TY/noQpy4zU2BkP0c7Fs7oC3kwJAfZhVz9WAg33wpq5cZijmRwcalUdecvpO8tMUOfoJZwJ5OiAmdN9ElDzmeJUmz/oEhahdU0haY5J+0mb69XnFSAymev3kS82qqk9vudewle X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(257004950022427); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231232)(944501327)(52105095)(6041310)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR1201MB0181; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB0181; X-Forefront-PRVS: 0645BEB7AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39850400004)(396003)(376002)(346002)(39380400002)(366004)(199004)(189003)(50226002)(186003)(81156014)(8676002)(8936002)(2906002)(80792005)(81166006)(2351001)(97736004)(66066001)(72206003)(6916009)(47776003)(6666003)(2361001)(386003)(7696005)(36756003)(51416003)(48376002)(52116002)(478600001)(25786009)(68736007)(26005)(476003)(5660300001)(4326008)(105586002)(50466002)(106356001)(16586007)(86362001)(316002)(53936002)(486006)(7736002)(3846002)(305945005)(956004)(16526019)(2616005)(107886003)(6116002)(6486002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0181; H:frgnb-l-34296kv.invcorp.invensense.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: invensense.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR1201MB0181; 23:bk1qp3I+Ftb+et9M4NdC2UiB4tuojJxHecFmoeA?= =?us-ascii?Q?gzZfy/yLTVgtY1hkDGmGXTYPYB/nNPEdQtfjRfrRGyO+pe2qHjJGIf/KQRFQ?= =?us-ascii?Q?Z0vGheSZr5fg8CLoLEvyy9tni9XyRUodix4IqT0oIdtIcbannjdw/mVHuP6q?= =?us-ascii?Q?wXED9vHr+Wa8USUjfD3JzcmLTO9wDLSbJ1vSw9frvd677GzBM0ZtRpbLM8Ve?= =?us-ascii?Q?U5CzjFSyDqvPlx2m0XYEZD8qcfBSD9gQR3MjVYs0M/U0J4RZB7N39Y+nRiiM?= =?us-ascii?Q?+zO2W+aVjA3/4dhivup4mc+TdBGIkpeR6eB2vntjNUwByQj4xPKXH+L2Ssok?= =?us-ascii?Q?8VdTka+2KOtXS9kz15rQa8tw7+wH4uDnJCm/yDF0l1NxICXhMBeDOIKPJEJE?= =?us-ascii?Q?haJYz2fW82lZe9YaAYspB04DOU/39to0L9ajrE8XDoyixi8f9R8ji3jr62gn?= =?us-ascii?Q?AJbjABgYaUaLDP5RHikQ6a+qCnFzC58iDqFZRiq460MH7RFFPGEEE+HyjCJI?= =?us-ascii?Q?Vq2ikOcOC5Sc9BEns6hGKTSo3ZPIqqLQJtug8cmYH/RjmtLGgfxyRitJt/ck?= =?us-ascii?Q?XsDvP4iNtIK04/GjDzaWcIQxYPY6hup1ZMhqLAIBJ4jQ9IyvYNWKLY3eLFi/?= =?us-ascii?Q?CFcjMqTHXmhMrg8dhpDAEExYD7+fCshXuiQ8bqLgUJBRELxlMZAL2kRw4xZb?= =?us-ascii?Q?KeSgiS2zZ1XDFO5AFLCcVdnAN8OrLH55qyimtN6NnEn5VwmA9ToB1Q8uUNF5?= =?us-ascii?Q?i8eK+ZKGv8CWVXTH0PmredPYdgXeclUTb2VjojQinjAO7wd701HXLfgF8DGr?= =?us-ascii?Q?tF/rK+p9yo1j/LzqN8AKdsC1BGUzsraWdO3rj9Kutg1CDYrTFcxfJD4vfooI?= =?us-ascii?Q?Eel5jRH031XdOjRGfD/3O/Ioi3RatvzzKyD27g8xQa6gQ+815xAJJ2GXQNtN?= =?us-ascii?Q?BJxC2QV3YgOKPZ26506S46/Do1J5mW4g+jPLsvF0bLYpMpo+rGzfnqtnZj7l?= =?us-ascii?Q?WYbcGaA8IAsLeZrIuqqKEZ/icujpAXObU/AK3qhER+/m6T64ksXs9lHSZzf8?= =?us-ascii?Q?SY50VubPeQZ2IhSeCdSyMOTcGnXKjqavRMlLNdTT3KTk8E/0fPwv9THRkOlh?= =?us-ascii?Q?HsKjSf/rV+R9eIayLk55q+bxXBfhFKDarG523CMKvpQOzoSwTxgnWBMc/BBB?= =?us-ascii?Q?5kWMuv/Q3nF8VOs9Tsn8g34S+lAWLeg9Q/Wsv?= X-Microsoft-Antispam-Message-Info: nuJJefIg28KJ8+mom1vHPxeJ158HB6u2aKrccMAfxPDrTqU1QnL455QJ5UJ99WNYFHp+Rgj0YqqYLYCctuxEeLsBS2DZpaa89n/7vhlk8JFbD18RITp1pjV2z4NfbxtRHFOdJ10J96FTLTp/a9XX9x0QPvjViQywecHK81ypewx+/1H5yivyMiswsVkLN9+C X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0181; 6:HQ9uYmV7/DTIczVfzlM3UUI92dXmo1Si4uCz4klGkrPUxlxnoXtFBPHBAYtfHDrjgqaN19JMMEpgzBT3sE7BcN1LDm7E0Gu7r4p+4K14sBzgQqZ+w0dqAWFgRSxxpxj7xsljPa1+Eyd/Y5zNbbRscDHPrUWsGUtxWKOEtthcClYVQ/pSut6tvvgfB0DxB+Q2Kr2JyzhYvKpCe4uwTRzhFFhC37N6EgUkAitASAMfqnLkGw1lZFNEX5mVSBr1WrAGJqNwMxC+5mWL/LV++dvSxtT1/fmH3VHURuSmJ6ugbn5bo5NrezcMY6KEqWxktolPUqfuP3nKIvQ/l5X1CbjIaYlylM1b4CAUbGH+uTW+lJHn1LJwNevzcVxfwIdoEBmm62CHwfhfwK7U5OrEZYeLCiIVJVlXB0F4NkKIFPE797ZYw1OiKCa9zKd90QyeQQR/kfnyhKdQsVjqiCrMHP35aw==; 5:687IUW8eH1yK/duQqKUbGUrKNbWJv49MJkmXUWEVH5Mmnw6QlWSLGymafHOOdIDq87yP6XsVp82CtBlV1iM24hiO18UxYNoYJtWcnDAKKHC2s9FAfooIFGcLxnYH+Uqf20YrYfNmNKhViTRgXubq7zloIQOYM1fO2F4aFj24GC0=; 24:hxyhGd1cZwGR2pvOQDvrYgqxPXbhNhdckMbgnXEQpuZ91sR7A6EkIqUh8RDmNd1gF2hbr6xQawreYcqgWKekN1niRz3x/Nl89ctp/49sEJs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0181; 7:2WXxj/UrqPyFdiKwnGHuGlMTVABQ+tm7E5nnp5DVzvDiR1H2xDeww1c44wBRQ4P1mWkKF0V9ZrMPO9dJxavmj6ym/qKuY8OSz+k1MQJUUZTIaVWkPjCtqcDjiaGj+2+5sDD39sBhwmA/S0vuvYZfHPzGyRZZI2ezte0BUphH9TF6NciX91c4VBhEVLpiWJvJa8y2L8ihzh35Oupo7iVatbmhs97udPEAbSKyTjMBwd6ufJk62HTuvzQumvWb7G+V X-MS-Office365-Filtering-Correlation-Id: 89f1f84a-db4b-4051-c4e8-08d5a433a5bb X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2018 07:20:06.7533 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89f1f84a-db4b-4051-c4e8-08d5a433a5bb X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0181 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 Rewrite set_power_itg. Failing when turning power off is no more decreasing the counter now and sleeping only happens when effectively turning the chip on. Fix also usage in init function (setting power on one time is sufficient to ensure chip is effectively on). Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 44 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 20b94d9..f3cf327 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -191,26 +191,29 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask) int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on) { - int result = 0; + int result; if (power_on) { - if (!st->powerup_count) + if (!st->powerup_count) { result = regmap_write(st->map, st->reg->pwr_mgmt_1, 0); - if (!result) - st->powerup_count++; + if (result) + return result; + usleep_range(INV_MPU6050_REG_UP_TIME_MIN, + INV_MPU6050_REG_UP_TIME_MAX); + } + st->powerup_count++; } else { - st->powerup_count--; - if (!st->powerup_count) + if (st->powerup_count == 1) { result = regmap_write(st->map, st->reg->pwr_mgmt_1, INV_MPU6050_BIT_SLEEP); + if (result) + return result; + } + st->powerup_count--; } - if (result) - return result; - - if (power_on) - usleep_range(INV_MPU6050_REG_UP_TIME_MIN, - INV_MPU6050_REG_UP_TIME_MAX); + dev_dbg(regmap_get_device(st->map), "set power %d, count=%u\n", + power_on, st->powerup_count); return 0; } @@ -856,14 +859,11 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) msleep(INV_MPU6050_POWER_UP_TIME); /* - * toggle power state. After reset, the sleep bit could be on - * or off depending on the OTP settings. Toggling power would + * Turn power on. After reset, the sleep bit could be on + * or off depending on the OTP settings. Turning power on * make it in a definite state as well as making the hardware * state align with the software state */ - result = inv_mpu6050_set_power_itg(st, false); - if (result) - return result; result = inv_mpu6050_set_power_itg(st, true); if (result) return result; @@ -871,13 +871,17 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_ACCL_STBY); if (result) - return result; + goto error_power_off; result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_GYRO_STBY); if (result) - return result; + goto error_power_off; - return 0; + return inv_mpu6050_set_power_itg(st, false); + +error_power_off: + inv_mpu6050_set_power_itg(st, false); + return result; } int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,