From patchwork Fri Mar 30 14:25:50 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: 10317787 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 6740960467 for ; Fri, 30 Mar 2018 14:25:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46F9F2A50D for ; Fri, 30 Mar 2018 14:25:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B1C02A516; Fri, 30 Mar 2018 14:25:58 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 98D142A50D for ; Fri, 30 Mar 2018 14:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751203AbeC3OZx (ORCPT ); Fri, 30 Mar 2018 10:25:53 -0400 Received: from mail-bl2nam02on0063.outbound.protection.outlook.com ([104.47.38.63]:42684 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751163AbeC3OZx (ORCPT ); Fri, 30 Mar 2018 10:25:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector1-invensense-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=h0wwvT1gDF9mz+kO/GhLpRLapRqOc+ZdsBM+bKtOlGA=; b=MSJozTF7PgrXCcW5DwIf8zLFaTraUabCcR6weT0IOAWYjd/hmx+f7S7nYrvw5WRBrvq1FcOupZzQBq5XmLze3tDEb0S3uvNBClv8os+voJbHrX1RGI5WqOmmP6VqjxChwrsZPkcTY8PFSxyDjEdIXIP0fkTCUZyMAOPdIJvqG44= Received: from CY4PR1201MB0184.namprd12.prod.outlook.com (10.172.78.141) by CY4PR1201MB0087.namprd12.prod.outlook.com (10.172.77.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Fri, 30 Mar 2018 14:25:50 +0000 Received: from CY4PR1201MB0184.namprd12.prod.outlook.com ([fe80::6cd9:f753:b84b:7f85]) by CY4PR1201MB0184.namprd12.prod.outlook.com ([fe80::6cd9:f753:b84b:7f85%13]) with mapi id 15.20.0631.012; Fri, 30 Mar 2018 14:25:50 +0000 From: Jean-Baptiste Maneyrol To: linux-iio Subject: [PATCH 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage Thread-Topic: [PATCH 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage Thread-Index: AQHTyDLTnkXoerZ5DEaGEcYMJ09lRQ== Date: Fri, 30 Mar 2018 14:25:50 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=JManeyrol@invensense.com; x-originating-ip: [2a01:e35:87fd:c140:8c11:73a5:8e6d:5a4] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY4PR1201MB0087; 7:HxoxxyZo5/1VUBRLb9JyZK5H44XAiHetmDRPpMICPvAM2bDfvGInZs1un5UULHwwQTja85O9ixQGCHQfk7PJvGJqfkM67T2S5nqgjUBufyhCyfok3vClxXWfzbAycubMhsrJ6crraBoR3XDtancoecirBV7NgFrb4IHOPB/dMzwK38JDYgLWdZHOhu6Tkv2EDAvEU0yE9sHYahsv0zu9lJqpD3UGHsrlDlbRSRMdwS6K5/24em/i9J/THAjKtrys x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: a48d36d7-f539-46b8-bec8-08d5964a2332 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CY4PR1201MB0087; x-ms-traffictypediagnostic: CY4PR1201MB0087: 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)(3231221)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR1201MB0087; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB0087; x-forefront-prvs: 06274D1C43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(39380400002)(366004)(396003)(346002)(39850400004)(189003)(199004)(7736002)(486005)(305945005)(74316002)(80792005)(3660700001)(97736004)(7696005)(3280700002)(486005)(2906002)(105586002)(106356001)(6116002)(5660300001)(86362001)(476003)(14454004)(6506007)(316002)(102836004)(81156014)(81166006)(5250100002)(186003)(72206003)(8936002)(6916009)(8676002)(2900100001)(46003)(99286004)(68736007)(53936002)(25786009)(6436002)(9686003)(478600001)(55016002)(33656002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0087; H:CY4PR1201MB0184.namprd12.prod.outlook.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-antispam-message-info: EqCddagAwmYQLAebO4XMVHMJhLxSCFCaH3lN4EFmUoxz0sjzM/hk4Q3sl6ObH7Nu6e/FDQXTqx5JT6ohkPF31uPL/BWx1AQHPeUon02YmbLdwKm9xhzcDkgQYWprJCtEFRs8QAFBxZUf7nz/KizR3feI+sqAK95N9nOtGefrhJ+gLpZxcqTF9fmPqT5sF5s6N3Mwf0lfvkVK6pKvAnPuytWHAqnNweiAnAzg4MQMO4mlgmyUztYcQfGUpCD9NqzEET3SqZwEMLqLUtKb7zVfkVc2+TNplIosdqaUzB4rukJKUfamiCfw7iV+LoOxXRymhiPRkXlY3tUY9x24D0iMeZyeimR+r99vid16xCCVbqymiaavm2fvtmdehcYeEkF+77aZgmF3BpcUUIGq+NLeQiS8bqePtwRXDUHfp6x1Aqs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: a48d36d7-f539-46b8-bec8-08d5964a2332 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Mar 2018 14:25:50.4442 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0087 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 7d64be3..f17fbfa 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -185,26 +185,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; } @@ -850,14 +853,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; @@ -865,13 +865,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,