From patchwork Fri Mar 30 14:26:51 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: 10317789 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 0864F60212 for ; Fri, 30 Mar 2018 14:26:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBB8A2A50D for ; Fri, 30 Mar 2018 14:26:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEF002A516; Fri, 30 Mar 2018 14:26:55 +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 5FC402A50D for ; Fri, 30 Mar 2018 14:26:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751258AbeC3O0y (ORCPT ); Fri, 30 Mar 2018 10:26:54 -0400 Received: from mail-by2nam03on0048.outbound.protection.outlook.com ([104.47.42.48]:18592 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751163AbeC3O0x (ORCPT ); Fri, 30 Mar 2018 10:26: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=o/M55EIcb36KeNd5mUXeqX4uJC9l8p4vAf6KDuvZKZs=; b=nCJMi1yfHlWqLrTEhA/XL35eU2wSp12ZCcxD602o2p1O+f/vxR3usZAWJaGdLRM6fftWtH9QdXpGRs2MaYm9laUOa9++JM3EeBHyxsHTRL22hbOdBr1ZG51WclLnvSgbK52ZsmASdFdQOFzlxBCAUHpsFT7d/A6rRztKQNrLcJ8= Received: from CY4PR1201MB0184.namprd12.prod.outlook.com (10.172.78.141) by CY4PR1201MB0230.namprd12.prod.outlook.com (10.172.79.7) 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:26:51 +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:26:51 +0000 From: Jean-Baptiste Maneyrol To: linux-iio Subject: [PATCH 2/2] iio: imu: inv_mpu6050: use set_power_itg function in i2c mux Thread-Topic: [PATCH 2/2] iio: imu: inv_mpu6050: use set_power_itg function in i2c mux Thread-Index: AQHTyDMHHN4E79ugREyqOCES+z1fZg== Date: Fri, 30 Mar 2018 14:26:51 +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; CY4PR1201MB0230; 7:8XC3XXjc6fHUUIiWfPrO1hIdIp539wraH5xgc4U+bqn1MwBi5ZRWAxxfNwdZXwfH8YojXRKVwwvji4vbPDInMN5NQ4f6dqqM8qErTIa7SeywnDTKeoLd12vymZGasoJXzDDsgUF+bC2t+xfTpMlzaHBu7GSroAxwfFsd3aQUY2Y19zs3VI5LNnj+P3MDMCglNqUhg0hYR/UOVoQKEQLyBmR9xVwSwtEvqdXtb28T+QVzih0PFm51kfE9qfaoYcyk x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: bdc18ec0-b6fb-4bda-ab91-08d5964a478e x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CY4PR1201MB0230; x-ms-traffictypediagnostic: CY4PR1201MB0230: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(257004950022427)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(10201501046)(93006095)(93001095)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR1201MB0230; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB0230; x-forefront-prvs: 06274D1C43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39380400002)(376002)(39850400004)(396003)(366004)(346002)(199004)(189003)(68736007)(72206003)(7696005)(99286004)(5250100002)(9686003)(53936002)(102836004)(6116002)(6506007)(6436002)(81166006)(59450400001)(105586002)(55016002)(33656002)(81156014)(74316002)(305945005)(8676002)(25786009)(7736002)(8936002)(486005)(486005)(476003)(46003)(5660300001)(2900100001)(6916009)(478600001)(2906002)(3280700002)(86362001)(106356001)(316002)(14454004)(186003)(3660700001)(97736004)(80792005); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0230; H:CY4PR1201MB0184.namprd12.prod.outlook.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-antispam-message-info: WZ8+fPzqrr84X+7m6c5U35F6ZtpScvLwHcVQTlyJbVgVkR2W5EXj54KBDl2NgEcFNqREjV8dYd2djbU9z/tiX21sYyLEaxQSiqku2eOQffqnSuAeUsxm7flUeI9gboY8yu7LEzm8B/NrxEpyU5YssE48tNNdtSqZbX2Acvl3yuTp6AAfdF+3qXVB18Sq2Mwwdg99Fg4X8f3/38ew2XoE2zPsy0yJkCGPwWIH/Hl/ipy+ss1b5IXtaRVVWQWY5vVFXUzbZh0vfydXi2VQr9lKMpxIr9naMFl1gFwx0xiFBJzvCIbGa46vvdVgpG9F+VyPhcsl8uZ5/OfQrbU5kXLRSu+u6ZBlLZW/0suNcUOhlBxpq5XCbzcQ5kPAD5GU3X/vIR67E1VNVwNrUjukX0DHtcnrng3xns010urIcGGeZ7c= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: bdc18ec0-b6fb-4bda-ab91-08d5964a478e X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Mar 2018 14:26:51.4603 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0230 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 Set power function is rewritten manually inside i2c mux select. Better use the already identical existing function. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 33 ++++++++++++------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index fcd7a92..8a8a5bd 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c @@ -29,25 +29,19 @@ static int inv_mpu6050_select_bypass(struct i2c_mux_core *muxc, u32 chan_id) { struct iio_dev *indio_dev = i2c_mux_priv(muxc); struct inv_mpu6050_state *st = iio_priv(indio_dev); - int ret = 0; + int ret; - /* Use the same mutex which was used everywhere to protect power-op */ mutex_lock(&st->lock); - if (!st->powerup_count) { - ret = regmap_write(st->map, st->reg->pwr_mgmt_1, 0); - if (ret) - goto write_error; - usleep_range(INV_MPU6050_REG_UP_TIME_MIN, - INV_MPU6050_REG_UP_TIME_MAX); - } - 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); - } -write_error: + ret = inv_mpu6050_set_power_itg(st, true); + if (ret) + goto error_unlock; + + ret = regmap_write(st->map, st->reg->int_pin_cfg, + INV_MPU6050_INT_PIN_CFG | + INV_MPU6050_BIT_BYPASS_EN); + +error_unlock: mutex_unlock(&st->lock); return ret; @@ -59,12 +53,11 @@ static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id) struct inv_mpu6050_state *st = iio_priv(indio_dev); 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); - st->powerup_count--; - if (!st->powerup_count) - regmap_write(st->map, st->reg->pwr_mgmt_1, - INV_MPU6050_BIT_SLEEP); + inv_mpu6050_set_power_itg(st, false); + mutex_unlock(&st->lock); return 0;