From patchwork Tue Apr 17 08:07:21 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: 10344525 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 7F46F6039A for ; Tue, 17 Apr 2018 08:07:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74CB1287D4 for ; Tue, 17 Apr 2018 08:07:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69070289A3; Tue, 17 Apr 2018 08:07: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=-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 4969E287D4 for ; Tue, 17 Apr 2018 08:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751327AbeDQIH4 (ORCPT ); Tue, 17 Apr 2018 04:07:56 -0400 Received: from mail-co1nam03on0084.outbound.protection.outlook.com ([104.47.40.84]:38912 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751183AbeDQIHy (ORCPT ); Tue, 17 Apr 2018 04:07:54 -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=6vmwoyyNixojl4S1Y79hsutUvoHc7Q8r16/bXjbemyQ=; b=A8BPVjqwSdSSF3S+SrwMucUq1JMdZSkR+QguGiPJmOUnZAF9u6zKidOPW7baud1PzLasnZVQqWYRSp0LmZHNK1G4Yxo/hI7yteGZ3IDHy10irLvY78fPHZUH4Tuf5EkhQ0Tuh5BYCnX2KCMlkgMT+oFD2rY0HtKVDZ1wY6vCZz8= 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 08:07:52 +0000 From: Jean-Baptiste Maneyrol To: linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v3 3/4] iio: imu: inv_mpu6050: clean read raw by factorizing out raw data Date: Tue, 17 Apr 2018 10:07:21 +0200 Message-Id: <1523952442-20104-3-git-send-email-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523952442-20104-1-git-send-email-jmaneyrol@invensense.com> References: <1523952442-20104-1-git-send-email-jmaneyrol@invensense.com> MIME-Version: 1.0 X-Originating-IP: [92.154.85.143] X-ClientProxiedBy: HE1PR05CA0162.eurprd05.prod.outlook.com (2603:10a6:7:28::49) 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:SMFi14EHrEZEQr6BJwt6/KIvIA7oRu+EPE+2nRbVxWz3S9oZ3uxffxI6IXGLeDbGSOeha95dzZUjnPVOgwyWUr1Ggkotl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91zS6EYuip0pJAmKJEu8zH7ak1yDaxMI9H4khCRUxtzWYJAekYiby/5Egzn2iXhhTPqaD0kZ0u3q9fE+E9lp+nUEV1Qt5u0aLUFR8nBYs5i+GgY+kMHS9Fma/0V145jxYD8r73a8wGgj0GLz7lEYDX/FLj2NtrdU+Eti+Loe1T83ctrMmybbY1jDNupk/zWaYpTDvw6eDL+usVzDsOmbXK164OYwCGeHXybj2LnZtJKtwODEjZW/3TOHqDLD; 4:89yXiUOS1huu37wwKvgZJnag7/4oT5qITJYX4ZVXx8TQIj2HSHJwnFHk5itJ5BKGuCkKb+5OBbGNudo0qdl7LvsrqukO5ZOmnZFwPEIYwNO+LAYF+KBVRlU7barkd0DacSYQyuwIckLeyZmMT5GHCMt2PpY5ay+OyA3lf+rtX3Ib6ppNxH3hoaR7PpjoR6aQFxYU605WdFK7S7G0AM+1E/o6o5AWlNksi2cGrRQQiYsUinewUNd9SnFPFlUYEZ6YzTKHSAkRwtaJXe704f8EMg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231232)(944501327)(52105095)(93006095)(93001095)(3002001)(10201501046)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:CY4PR1201MB0181; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB0181; X-Forefront-PRVS: 0645BEB7AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39380400002)(376002)(396003)(39850400004)(346002)(189003)(199004)(105586002)(50466002)(4326008)(476003)(5660300001)(26005)(16526019)(956004)(305945005)(486006)(53936002)(3846002)(7736002)(107886003)(6486002)(6116002)(2616005)(11346002)(446003)(316002)(106356001)(16586007)(86362001)(575784001)(6916009)(72206003)(66066001)(97736004)(6666003)(2361001)(47776003)(81156014)(50226002)(186003)(81166006)(2351001)(2906002)(80792005)(8936002)(8676002)(25786009)(478600001)(68736007)(76176011)(51416003)(48376002)(36756003)(7696005)(386003)(59450400001)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0181; 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; CY4PR1201MB0181; 23:x034+sfaMjU8KHDR1/nnUuTZhefc/tlGXkOSZQS?= =?us-ascii?Q?fTu678UBYbLcj8bA1CdJnyEONpHqqdLtiobFhDG5XlzWKOv4UIN3MJOypap+?= =?us-ascii?Q?F7Y6HY3sj/6XFDEaQoVHpkCXn/ULZaqXMrehT3+JLHkn97dUq+6QsgNP5XS5?= =?us-ascii?Q?RsLZiSCuRTynsSYvSv67+xtQ1/hb2Za0cqjgI7NmaZ4eQiaHwxv2+AKXortF?= =?us-ascii?Q?cnUexE2TWMLWEgbHIPzxbLmKntDul+iItvzQGYUlsVwT+ckR8Xoj6IgP8BJJ?= =?us-ascii?Q?9/LUVqEtNij5QO4vNEMcHOt9J9uY68BvLsnElqWM4S+/uinEbkfUGw3fJ4I0?= =?us-ascii?Q?LL/X6ZPpoyQleY8lSpBiYuw+BVcc991Ckt+CkVWVQLOzQkkzscRIuv/8qrnL?= =?us-ascii?Q?TyeCxdxiIi/3TU0bwBoTf+yBZ5QbZLBl8EePe3fzcvCVlmWs0go6sPATVGjZ?= =?us-ascii?Q?cqf+hFaz/lywnEDjSJCVPo0ILzsYedqVsss2E7YHcNzUO1hPWjIbcTlC2Del?= =?us-ascii?Q?gYTcNf+d/BHjgQJF3dF9AZqvwhoHdnrfTgzdRmuk4rUGe6TDAp37S2QVaB+4?= =?us-ascii?Q?ZdGK2m3k0BawkExEbV70ZpB80PgDtJ/VzUyCKCRaywlfo8RktAiqxiMAQ8gW?= =?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/ENh0ZsfHG0bjz000T/3cNrx0ZeRR2wEoagVoaQKKbwco0kqeasojrU3JAmgzCy6YUen X-MS-Office365-Filtering-Correlation-Id: 1cbd3983-a672-4e56-9346-08d5a43a523a X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2018 08:07:52.9140 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1cbd3983-a672-4e56-9346-08d5a43a523a 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 Factorize reading channel data in its own function. --- 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 996e68e..a0cecd9 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -324,6 +324,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, @@ -334,63 +395,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: