From patchwork Mon Apr 23 10:33:32 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: 10356575 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 956FF60209 for ; Mon, 23 Apr 2018 10:34:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 856DD28464 for ; Mon, 23 Apr 2018 10:34:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79D9A28A3B; Mon, 23 Apr 2018 10:34:18 +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 EFAB928464 for ; Mon, 23 Apr 2018 10:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754652AbeDWKeR (ORCPT ); Mon, 23 Apr 2018 06:34:17 -0400 Received: from mail-bn3nam01on0084.outbound.protection.outlook.com ([104.47.33.84]:4272 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754442AbeDWKeQ (ORCPT ); Mon, 23 Apr 2018 06:34:16 -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=PWu7DZproXElv/SchGzjWEctdg2gucQeBtl5efPu3F4=; b=bE09xx/aYXRn1Ird2FdJLtMFBNrKL1jkX8inlPPTm21dh3bR+t3jLRhxPDh8TY/dK4RxY0D5vRYugc9AiH+Y7T4BANp2ymQbDtxtZ9jajh7QtdegISPQDR1mu+r4AVrs/p4AEFEsxs359fJ11mOS729/ZKD70aUvuxASX1K7ggY= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=invensense.com; Received: from frgnb-l-34296kv.invcorp.invensense.com (2a01:e35:87fd:c140:39a5:e592:8e24:6975) by BN6PR1201MB0178.namprd12.prod.outlook.com (2603:10b6:405:56::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.12; Mon, 23 Apr 2018 10:34:14 +0000 From: Jean-Baptiste Maneyrol To: linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v4 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data Date: Mon, 23 Apr 2018 12:33:32 +0200 Message-Id: <1524479613-23954-3-git-send-email-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524479613-23954-1-git-send-email-jmaneyrol@invensense.com> References: <1524479613-23954-1-git-send-email-jmaneyrol@invensense.com> MIME-Version: 1.0 X-Originating-IP: [2a01:e35:87fd:c140:39a5:e592:8e24:6975] X-ClientProxiedBy: DB6PR0601CA0023.eurprd06.prod.outlook.com (2603:10a6:4:7b::33) To BN6PR1201MB0178.namprd12.prod.outlook.com (2603:10b6:405:56::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:BN6PR1201MB0178; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0178; 3:CFqhkcNi96GZJouUw8Z6bNxf2MnQTd4T181k3w6gNZLoGl/hIy8bdXRM3O/FA070mWzVJRYPQsk84a8sQ1JHPld+gVKms2OfcQYj7hJMtpZLGpX/4iMcCnzDjifa9sZIjfPU2OiaNmFN3hV1+Fff3HaSF4ceKgZsiVHs2ST8SBdpQZuksbDZ0w2hIrcyf0GOP2yd79JkBaedm9oOPjM37AB7E/uGbx/MAEUXUqYITsJvPEJ0/etunBZBY+Wxn5mW; 25:Vg7B6yFs2HvoxhPFfWD91Kbk3+IYVHNguCfA0wwdjc8Csd400tXkQMSIquFIPYnVoc9syd7d2BPHfNegeImvCygNstZ7Ln1JeTCmxkep7k0+537sRShqSauCRaH4q0y1rfnEVH4rooAbHRxk+qStvhuPR8sb4vz1yO7jju2gnN9lyHIjJ0m0DANJKFQKUAeEhpOJfs4/HM82NfPfJnl+enKyb9rtlT8YjgexW6e0F89cMxbySLiAATF9ccCmnpUD5XDWLPeEsYsrCxY9LSGuXx54NB4pWadcZ6MqLgHkpUlyRYmQy8CIm2+wagmYr88cCa9w22PRjQPwMZAT3d76QQ==; 31:5THk8CCwt3l61/kBAx+VULTssAy6IZem0O9n5RMr8qjTWcRdvxpT/HD0JDsFIcqGKTSxRBHeM/8JCpVqeeXv9gO49nxGBuceuemDWDGnyG/mSIv005wjaH217wIGiHkLYKYJidxxXx6bu9b+Cx5vUmUbbhoUVSyfSp1Hr1JvVr5mdii0r4GM+/P7sg2Nd0DuDUNiROfHG3d/1187nFM8CgWmEN36uBCzX+1/DOsMirk= X-MS-TrafficTypeDiagnostic: BN6PR1201MB0178: X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0178; 20:7MXtFBbzNiIFmAjQRb+GQRfYzmZ3g/84TD+f73cXqZqTf54Ab7Zv+2N1ZMf/XdOw99px08p6PAs3PVXvYreQhtr7POrjowgfEuzF75hDj5Mb+KslmHyhZx7B06qBO3sut8S6X8trRNEitcLNNU0rWznRCBvJSJerZ7daqg62bsYiN5eO5WLw25wUtgCrU471BrN98BoEibowlB3jbXRJJoD+nlINlbZbTZgH9+CGCY5u/OY/Nfh2+DZiAL2DUm7UV9/OvERAJKBoEHbernI1sIJE0gGSnBrn2g/TnkGAgf1zCOmQDB7gkAqkQqHYx2eYm0yj+BnOKq5dpRc7qOLablMP/pFAc4LZsqgcUhBDnC33rziowq6hfEZMDYCJoAkh+xOWYdv306FtyWWDS8NgsA9A0xHQq1eBKkoAEIXuj8PjZJHZDg/NC+KMHccZkfrnV1b6jLF9xNypUuH7Q8b/hwnjoolJOoi9DHJTQ79LSUS1e9UeQE83soohx4cHbV6w; 4:ZFgLN4kgwxj/kkLi49FShc0a0XrHzK55d04Kg2mFdolLyDTt0XifsINJoJHcfmc1F0K/EnreNoWJ48czNJREQkDxq2ef5WrYeyS3pKWcPCaNdXQR5jxjD8pQGa8+4Sw7uICBmO4XQ3P4iI/EPF4cpBvLPzssSlrLOTQA21ykmrN7bMaywhWVLomscglqgVkfsqq+wzXTDADOBEdHBbMpgncic0LKxOoYDOfO3evOMM1KwPcxWlR1NZbco2N2Li3AQEu+SmoJQvrHZCEyDRr0ywyk70RpaXD80NTl6utpJCmK1ym01+/ABDmfxMAesDIh 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)(93006095)(93001095)(3002001)(3231232)(944501410)(52105095)(10201501046)(6041310)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011); SRVR:BN6PR1201MB0178; BCL:0; PCL:0; RULEID:; SRVR:BN6PR1201MB0178; X-Forefront-PRVS: 06515DA04B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39850400004)(376002)(396003)(346002)(39380400002)(366004)(36756003)(305945005)(5660300001)(6116002)(50466002)(48376002)(2906002)(80792005)(81166006)(8676002)(59450400001)(47776003)(86362001)(8936002)(50226002)(2351001)(72206003)(386003)(7736002)(25786009)(2616005)(11346002)(446003)(46003)(476003)(76176011)(16526019)(186003)(52116002)(478600001)(7696005)(6666003)(53936002)(52396003)(2361001)(16586007)(6486002)(4326008)(316002)(6916009)(107886003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0178; H:frgnb-l-34296kv.invcorp.invensense.com; FPR:; SPF:None; LANG:en; MLV:sfv; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR1201MB0178; 23:vNGfY5x+i+YQbH25XNOuLesr7JUtetr5yRTtWVd?= =?us-ascii?Q?b6/QxfRdHcOxSPkwz++aT8fFDzE/YK+at6UWtkf8MHvMbJe2RJa9A8BumLEA?= =?us-ascii?Q?ENpyT3hl+BrlF0XwGSdinCHMTxdX7cjgMymDTEq/1YW6RodyDtBR1WdnCbb1?= =?us-ascii?Q?WA2h3OuMs0Ec8bUjdDcZMosKSTbHxi22m07XBrK2bN8amRu8xQCJQZUjh+GB?= =?us-ascii?Q?GZPNIVKmJkZQGWRy1/UW3mWJKnEOoFP8vYo1xZUpvy61VXIzK41NhCC5PB4l?= =?us-ascii?Q?Te1EIDNVjlkt9cY/f1lHT01vWmjyIcCevj8KsQw3/x6RQM67yNMvSDj0nl60?= =?us-ascii?Q?42KOAPTGHixnmxb6bONDps3mdDgK83dDtcpIQQHScG3BPf+3mF7SjHw0SDOH?= =?us-ascii?Q?d2HXQoOuyGQcRe5Y19CK3eWee39pS4501X/IdkuxSNGbW/sg/DoFhM/eBkzL?= =?us-ascii?Q?z+Ri1zXxVcDZVWk47CkKBjihWbp1SSHS3fGC5lIT8mfG03zU9888q0MZ9TFS?= =?us-ascii?Q?Nh2WjVxQDZHFAEKoCDSDm2VZtPHnSQrMo82uOxkzNjPcYKKT/WNE1CNodnWO?= =?us-ascii?Q?MeSLZ3z1Ci3qpPHnTqXXcPV0HMB3f1PwEaUJZV5vTXa5UnOIlaKiZB/gDifD?= =?us-ascii?Q?tQqNk4aTQkgnVcUquLqveaqTMYEGL5bOQJtq1oyGthwyPNXy+teYkUbKivdU?= =?us-ascii?Q?cBHcUYcBYyoQZ8hWbsv2387vT7Ve3nf1TZtLliXme8onEnXmgjUurxNbjYj2?= =?us-ascii?Q?zwYEMcwWcmf5YWzjNi+GNeEwPvTtOtSESNRspRMBvoRtWOmZ5skPZN33jcyu?= =?us-ascii?Q?vcLJR/KsnlfRPuirYufWlsVpDVSrlAewmN6S2lxUBHczFIyuY0Yj6+D2CZ5A?= =?us-ascii?Q?YtsVk1/37wyusjvBO5sjnKz1We6s2QeWKYL3vu4lqDg8AgPvynod5aGIEJDa?= =?us-ascii?Q?njn23sPh9BTBDNWfH2ouWQcGRh3zxo52fk++T3e2Nuzg85o4FA8DjlZ5YJ/4?= =?us-ascii?Q?6sSRJRwhNzotgbJkxYYQGSxdtNYGprFkfUcCKnEDy0Cd8rliQi8dScfC0nsu?= =?us-ascii?Q?0N4QYf5Q49+b7eE5bDGRHsLc3tm++?= X-Microsoft-Antispam-Message-Info: wckR7oF4Tc+JYU+k4ngxIkr6VhnEBYNMwrrPeDAjr81KPNu7B7qs/aB9aN18oN0lZ4xigYEnRExK1cCbpYTWmBtuiSuouoCFmtlpg3VXj5YhY4wYwHaE1VTnKfuM37wBgrCb9AnTqJM1yZNO1/RvTIUSn2/t5F0ouQ+3saiELUAAwXM9zTkquI3pTgCOXKul X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0178; 6:k2XinicBm8hyY1fq6W5QHIaerpYA7FO3FdsUrRmo926Hknoldn3FNNOGbt1ypbtKCc025dEW3P9+pLAved9n051HL9XIHCi5w8wbqr6Z+eVIM1JVkYZAy7UltvKHwn/MCjSewBdigv/ksxP6F0hC8X66gtuLuhU5zoASvlU6DraQi343rfIlTMXekJl2XMU5IgC7S2iwZx3jUjpz2AfaGV7Pbsqb80F4rjvBePhUMfN4NDehnZtP0Q3aAgE8kWlcasKyLVKkh+n4YjTvOJDZRLLIRJXp+fiJi9Has99IVQCDhK8rCL2LreP7XwDTW0/NE36TBjRblT37lesCy3avhmbWFvZDNOeM8TrnRYtKQ4JYQGzy0Eyv50Ufq8UkV1TZZ7/I283LNPGU6dPo31ki1LByXVhfP1zacsT5KdklLSbxAmlpYmnx28dXb15zsWVpOeKExoHWJZ5ygKSUPLxxwA==; 5:4xtwKXGqRlIR139slK9XWRT9jD6wysPzEDOj0Vc07qmyUJbYlWEx827Uf4mV2hET82KutUwQiCoS5gOo750k54dnshSGee/G96ve0ijkJDQnBIvvAtj7G16YGtuiRHRXkbPvwa/YrBXzrwo5u2Xw1L9U1RMytiKxvZ2iUwZDVAE=; 24:NUmtK60dvSr/yWmnKpQn2KRF+pU8/9CvGYwd1aeS+/BlN9KGn8W1D7Gs2hOPlYDTaSHH0okFYP8Qxi/qG0VRW/V0i8Sq60Ycra8YUVx1Sto= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0178; 7:5iwI/fXPxJD3TLhAUrFjZSk5xvoH27JU7BChhj0t9nLBTvj852XVcTa3b3wwEjPP5KK+3E73gjhy/vUKnHiKKRF1tFBfwUyMAskcpz4S8ldhFUJNXgVAgc+GaAB6d0HXmBV+At0Bjn23kKlJsAKUrf60jZuDlbDiMAhBseNai9WqT4I3ctQe+Vn7Z4TL98iwg8SY/zMF37jlB06jmEF1jF8RA/GaBPG76eWsrTEy6To7+23K2kD6StT2d5r76c5O X-MS-Office365-Filtering-Correlation-Id: f694e11a-3c98-41e7-6256-08d5a905c2b4 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2018 10:34:14.3231 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f694e11a-3c98-41e7-6256-08d5a905c2b4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0178 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 Factorize reading channel data in its own function. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 116 +++++++++++++++-------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 45f57f7..79b44fd 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -332,6 +332,67 @@ static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg, return IIO_VAL_INT; } +static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + int result; + int ret = IIO_VAL_INT; + + result = iio_device_claim_direct_mode(indio_dev); + if (result) + return result; + result = inv_mpu6050_set_power_itg(st, true); + if (result) + goto error_release; + + switch (chan->type) { + case IIO_ANGL_VEL: + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_BIT_PWR_GYRO_STBY); + if (result) + goto error_power_off; + ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, + chan->channel2, val); + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_GYRO_STBY); + if (result) + goto error_power_off; + break; + case IIO_ACCEL: + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_BIT_PWR_ACCL_STBY); + if (result) + goto error_power_off; + ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl, + chan->channel2, val); + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_BIT_PWR_ACCL_STBY); + if (result) + goto error_power_off; + break; + case IIO_TEMP: + /* wait for stablization */ + msleep(INV_MPU6050_SENSOR_UP_TIME); + ret = inv_mpu6050_sensor_show(st, st->reg->temperature, + IIO_MOD_X, val); + break; + default: + ret = -EINVAL; + break; + } + +error_power_off: + result |= inv_mpu6050_set_power_itg(st, false); +error_release: + iio_device_release_direct_mode(indio_dev); + if (result) + return result; + + return ret; +} + static int inv_mpu6050_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, @@ -342,63 +403,10 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - { - int result; - - ret = IIO_VAL_INT; mutex_lock(&st->lock); - result = iio_device_claim_direct_mode(indio_dev); - if (result) - goto error_read_raw_unlock; - result = inv_mpu6050_set_power_itg(st, true); - if (result) - goto error_read_raw_release; - switch (chan->type) { - case IIO_ANGL_VEL: - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_BIT_PWR_GYRO_STBY); - if (result) - goto error_read_raw_power_off; - ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, - chan->channel2, val); - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_GYRO_STBY); - if (result) - goto error_read_raw_power_off; - break; - case IIO_ACCEL: - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_BIT_PWR_ACCL_STBY); - if (result) - goto error_read_raw_power_off; - ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl, - chan->channel2, val); - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_ACCL_STBY); - if (result) - goto error_read_raw_power_off; - break; - case IIO_TEMP: - /* wait for stablization */ - msleep(INV_MPU6050_SENSOR_UP_TIME); - ret = inv_mpu6050_sensor_show(st, st->reg->temperature, - IIO_MOD_X, val); - break; - default: - ret = -EINVAL; - break; - } -error_read_raw_power_off: - result |= inv_mpu6050_set_power_itg(st, false); -error_read_raw_release: - iio_device_release_direct_mode(indio_dev); -error_read_raw_unlock: + ret = inv_mpu6050_read_channel_data(indio_dev, chan, val); mutex_unlock(&st->lock); - if (result) - return result; - return ret; - } case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ANGL_VEL: