From patchwork Wed Feb 19 14:39:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80B5E13A4 for ; Wed, 19 Feb 2020 14:40:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58D0624672 for ; Wed, 19 Feb 2020 14:40:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="WEM8fsuU"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="XFTopTSU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbgBSOkf (ORCPT ); Wed, 19 Feb 2020 09:40:35 -0500 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:10906 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOke (ORCPT ); Wed, 19 Feb 2020 09:40:34 -0500 Received: from pps.filterd (m0156136.ppops.net [127.0.0.1]) by mx0b-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEandV007777; Wed, 19 Feb 2020 06:40:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=hLl3QPIq8SlVoRBagJpbEy83IJ5j7nGjeIIwQjYLbv4=; b=WEM8fsuUM335Ua0AtDJ1BRz2fXlVP7wWUbH8EaxOysXtmK7hzoq5hFwl2wF47DOWbm7F l6uxobLtxSc8QtdQOQw0Scb1W4TZ4TzFFKRb1GHpPIqprOQqODHA8qqTg8cwDXYWZuYH fmdrKcBjYxO5irLx5gioTqo6yaHSUsPW2oFUXVfcg58WZWcl3S4OBJHwyWuOEwhFEyaa MTlbQGCpE8SwYHiujQEOUvDXzHIxbXBzgpbEG7OPXOXL4dOcxXGYMYCtnYw+PududtO4 6Km9NVYmSzLvDezheu5QDO4HlqDP3KPz0eLqcyxSZQmfsS/7x3GFr2JQHXFCYYtQXYTF cw== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by mx0b-00328301.pphosted.com with ESMTP id 2y8uc908h1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:40:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=URXycUyyzUbM74FR1MTBd44sb5f7sJFuEmjLXfAHJ6I3oSUtBn1QuiPCxGp5jZm6q0Sv8iVDEe4s+kTgUdbc39x6ORIoFz5TQCv+V7xam46gDg14FcX1rdIbaj/ZDqfnhlanDxr1t477ZJIfEg4TpYjo5YXAK4TIWPObvk8GCUvFQYR+mu6cF0lfWaG05w/TnaabnpQTjgHbu9BcxNbtUYe4VS+50kTcb2+1idEqnvcYWmo7vQ2wa5qoiQYK7joFTsr7bMDxKegAVEgnc6BoJUVj9nlWIjpBrzZ+k0fPdoPaiSjLNJQyszvFIxlM66cHjpxuBfUkSnaa1GWHyBQJUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hLl3QPIq8SlVoRBagJpbEy83IJ5j7nGjeIIwQjYLbv4=; b=jIeY+izFF4TZl0yQMIu0GR/SHa/dD6x7+dgBKOTkQrJUITOf9Q7srpy4UcddIYlPO4YaqTNhqaLHhuRJd1r6RnHGmW4RESX+dlU0ug09AGplCMWxnxzrpHo/+7nc3glqWStQJZ1cXU/zGa5SEYDNtQvMEiB1gakRzwfZMtF7EGR0F7ACQ7cn7IfzPLVcWXIB8JFlK5/Oy3k5WlAA41ih+qS1c+BaoB8IAoVfBLfOcWqLL35ZRTQxS4IU+1b6ZJ4pVYHbxzzNSR1dnnlcz6Qsh1x1rfHhYYJ9HpSu3nLABtox5IH7+gJNJoh9tdOuAhPg9J0v9tbaLLkHcPMuEBoGHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hLl3QPIq8SlVoRBagJpbEy83IJ5j7nGjeIIwQjYLbv4=; b=XFTopTSUoWrn2dK1s5Qbr+vqyMDZCLZEuL7bnX4W4Ox+u+0ySq7yB+jLefMjpgiEMFlvQyyCZQ9GrANrJV6+JgqsrinXgHDHxnnfp9Mv2VMAwgFRRaUzjzGauz/8m6AHROeZhtESH8QD451vVy+EbgNsiPPJRuFa/08JP1ukstc= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB3878.namprd12.prod.outlook.com (52.132.245.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17; Wed, 19 Feb 2020 14:40:29 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:29 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 01/13] iio: imu: inv_mpu6050: enable i2c aux mux bypass only once Date: Wed, 19 Feb 2020 15:39:46 +0100 Message-Id: <20200219143958.3548-2-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:28 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c732267-2607-4c6e-4859-08d7b549aa5c X-MS-TrafficTypeDiagnostic: CH2PR12MB3878: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(396003)(376002)(39850400004)(136003)(366004)(189003)(199004)(2906002)(5660300002)(7696005)(36756003)(16526019)(6666004)(81166006)(26005)(956004)(2616005)(52116002)(186003)(1076003)(81156014)(8936002)(86362001)(8676002)(4326008)(66946007)(66556008)(66476007)(316002)(107886003)(478600001)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB3878;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JdbXtPbWimmj+K+iRNrRV7496fFY+1eaghldQINSlCLFLoNxiwj6kNJeSJimbzXEbR34FgTDRO9WPr5tAswan8e2qtS5ycuwy1XL7Pz6Jto7TRGMQIeR1JkLvCvI7RtAZrCpMd3+pMkun+12kcYwVlRxkpMQnRlCTT32VHqeqQShFUp5kpxC50HKfSaC84Ife0i9D8c59U5NETKa7KbgDwxGarjiCNO88jq4LtxwNUTvF9fsKD81OPeRHvUqbrt0jvTz/neYKtwA/S2eR2hElpk/JpdVtmqx3V+q84UStWbzoAWHQD/vOQYwiDF1tLzE+blJZ5mwHAz4xcvcxe72bMgGQp1G3ls8W7cYmiRBQTFMrngsV1AwUH91MQK58Hut7HXvAzkFxTmb0puZGFzU+Pv0kRoxc+5qoqfAK3ZdAhwszZNda8OAoB7sruHzHGUP X-MS-Exchange-AntiSpam-MessageData: D/VJqPdRHKwZ9NXFXsX9IoIf0a2/zgxl7byLQvFz4B3od4iHnoD2ggyL0lcP4s4eTOObd27IXXHZgWI6eLkZC6URlycl71mKpcYlhGe65iEj+JREza1sFjXn2VfO7YahfhGC137hmqSVCJLos8+KRg== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c732267-2607-4c6e-4859-08d7b549aa5c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:29.5103 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YggF4C4wkJUjoAcqbJCh+BT8NTzLDBaHx1heuYWPRLejxPWNxJyoyVV8MsVqyMXPuTUAGUVlNel0p21oFyinqdYe6ax+Yx/1h9mpgBfDdhg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3878 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org i2c auxiliary mux is done by analog switches. You do not need to set them for every i2c transfer. Just set i2c bypass bit at init and do noting in i2c de/select. Signed-off-by: Jean-Baptiste Maneyrol Acked-by: Peter Rosin --- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 71 +++++++++-------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index 1363d3776523..24df880248f2 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c @@ -20,38 +20,6 @@ static const struct regmap_config inv_mpu_regmap_config = { 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; - - mutex_lock(&st->lock); - - ret = inv_mpu6050_set_power_itg(st, true); - if (ret) - goto error_unlock; - - ret = regmap_write(st->map, st->reg->int_pin_cfg, - st->irq_mask | INV_MPU6050_BIT_BYPASS_EN); - -error_unlock: - mutex_unlock(&st->lock); - - return ret; -} - -static int inv_mpu6050_deselect_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); - - mutex_lock(&st->lock); - - /* It doesn't really matter if any of the calls fail */ - regmap_write(st->map, st->reg->int_pin_cfg, st->irq_mask); - inv_mpu6050_set_power_itg(st, false); - - mutex_unlock(&st->lock); - return 0; } @@ -79,19 +47,20 @@ static bool inv_mpu_i2c_aux_bus(struct device *dev) } } -/* - * MPU9xxx magnetometer support requires to disable i2c auxiliary bus support. - * To ensure backward compatibility with existing setups, do not disable - * i2c auxiliary bus if it used. - * Check for i2c-gate node in devicetree and set magnetometer disabled. - * Only MPU6500 is supported by ACPI, no need to check. - */ -static int inv_mpu_magn_disable(struct iio_dev *indio_dev) +static int inv_mpu_i2c_aux_setup(struct iio_dev *indio_dev) { struct inv_mpu6050_state *st = iio_priv(indio_dev); struct device *dev = indio_dev->dev.parent; struct device_node *mux_node; + int ret; + /* + * MPU9xxx magnetometer support requires to disable i2c auxiliary bus. + * To ensure backward compatibility with existing setups, do not disable + * i2c auxiliary bus if it used. + * Check for i2c-gate node in devicetree and set magnetometer disabled. + * Only MPU6500 is supported by ACPI, no need to check. + */ switch (st->chip_type) { case INV_MPU9150: case INV_MPU9250: @@ -107,7 +76,24 @@ static int inv_mpu_magn_disable(struct iio_dev *indio_dev) break; } + /* enable i2c bypass when using i2c auxiliary bus */ + if (inv_mpu_i2c_aux_bus(dev)) { + ret = inv_mpu6050_set_power_itg(st, true); + if (ret) + return ret; + ret = regmap_write(st->map, st->reg->int_pin_cfg, + st->irq_mask | INV_MPU6050_BIT_BYPASS_EN); + if (ret) + goto error; + ret = inv_mpu6050_set_power_itg(st, false); + if (ret) + goto error; + } + return 0; +error: + inv_mpu6050_set_power_itg(st, false); + return ret; } /** @@ -151,7 +137,7 @@ static int inv_mpu_probe(struct i2c_client *client, } result = inv_mpu_core_probe(regmap, client->irq, name, - inv_mpu_magn_disable, chip_type); + inv_mpu_i2c_aux_setup, chip_type); if (result < 0) return result; @@ -160,8 +146,7 @@ static int inv_mpu_probe(struct i2c_client *client, /* declare i2c auxiliary bus */ st->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE, - inv_mpu6050_select_bypass, - inv_mpu6050_deselect_bypass); + inv_mpu6050_select_bypass, NULL); if (!st->muxc) return -ENOMEM; st->muxc->priv = dev_get_drvdata(&client->dev); From patchwork Wed Feb 19 14:39:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391633 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 56BF717EF for ; Wed, 19 Feb 2020 14:40:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F4ED24672 for ; Wed, 19 Feb 2020 14:40:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="OR2lXFLz"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="Y76h44GK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726677AbgBSOkh (ORCPT ); Wed, 19 Feb 2020 09:40:37 -0500 Received: from mx0a-00328301.pphosted.com ([148.163.145.46]:49324 "EHLO mx0a-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOkh (ORCPT ); Wed, 19 Feb 2020 09:40:37 -0500 Received: from pps.filterd (m0156134.ppops.net [127.0.0.1]) by mx0a-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEdZT5016941; Wed, 19 Feb 2020 06:40:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=uwM2Uo4f+8hMl3XDl9A1AOaH0DZAuv5Qo/R2efzX4uI=; b=OR2lXFLzpTNzCXy4hCMWpsZHZqF3/hwMH6My/sZcEH1CB5kGNdoWHb9YcKIE05zzt0Eo yfjdTa3HQuS9XFMDoGooJNtcsBEnJdncoEXzAZrCl1DDAYAXbOV/dY8Yjg2yXbo0lnMn gcKfGzyMTPma+jReBywUNUUJj1cVj8yTwVULRmD1pzicxX+7B6lvv6WE0g2zrUfCMGT8 IrqPJ4LQn0s4Pr7De48XU8n8c+4gLe8LmLoP3nXpT5HqesMzMZvlFY9JfT+mlw6gKShp zISYCihCcITQqZoCSXx81cQvwV1UV+Bw8FViLyS34y8PiO4fE8xsAFOLt+zxconwC+0Y eA== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by mx0a-00328301.pphosted.com with ESMTP id 2y8uem892d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:40:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvAnuo4TzaoKCFKEcnT5/asrYQr5T74hYg6k+lnKBEaUcDgJbw/g+WJdMxGeIPOk8uXq652s3xwCeF6wPpdSTE4V3y2WfVfuQLEL6rxRjsIyt8a0GiHKELiPmsNZ88hQEKMaR5Hk3Wrg/XQZ2MV111rvbbZKzPmV3RzkXw7lgtKztYSwzpFr4hSqkdl4elxPRgPW9DcrRLv+DSVWzZEJ01cX+lpA2Z6lP+2Yt/lIbSfa/KSWyDHOs6UhH39E3ew1jMWR0AkW5DAvVpY+znZnves1fnFkrpwB+14otO32/KthVeQi+spRnFCh8enYTcXQRDjusYvMitvrom8C2W7QVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uwM2Uo4f+8hMl3XDl9A1AOaH0DZAuv5Qo/R2efzX4uI=; b=POTh6l9nOs7zgKrvjv2s5wjSIV6NHhzf9fHCPUyWnY7aR1tnQ3xQxAnTLCGoG6luQlPv22fR1sFMKQKE9L1xnMariOfJaT1/oIBNUQCdp6AV1qI8vTyYHxgKP77/CfZg9yhgp1+9WUkVzGkUtxLXEnMoZ4RLe0qV/A9Nh1LYX+baiP25E5InW7jphHSjwU6dctgOoDZEN5CxfYPV4WKXDW8RqmmA/xNsUIxq2M3jRutPgdxleKNuBqmNSme2Rabklh/RGkHj/v0PrPW2nh1uM2RS45+JO1fpagTiGHmCf3nujINw89MKUzpXq3+tF+oFEbDrkYQPJtXkNWVkzEyQ1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uwM2Uo4f+8hMl3XDl9A1AOaH0DZAuv5Qo/R2efzX4uI=; b=Y76h44GKsCdRakza4h+pEzOWIEPQr+EOLFjDpATONS9jlZAO7ZMjVljp0hV4JyIdIvLKhj6YsqtOgMNSIqzFm+IOzc6ZduFgtnnw8+0xT056KHUrQFAdLVZzs1Qi+IPX3QdzyfW2Wly9ahiSCgZCgRxsb4qgBVdDtnAPvJNULiE= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB3878.namprd12.prod.outlook.com (52.132.245.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17; Wed, 19 Feb 2020 14:40:35 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:35 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 02/13] iio: imu: inv_mpu6050: delete useless check Date: Wed, 19 Feb 2020 15:39:47 +0100 Message-Id: <20200219143958.3548-3-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:33 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c7155a64-ebf2-4ca1-6d75-08d7b549adb5 X-MS-TrafficTypeDiagnostic: CH2PR12MB3878: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(396003)(376002)(39850400004)(136003)(366004)(189003)(199004)(2906002)(5660300002)(7696005)(36756003)(16526019)(6666004)(81166006)(26005)(956004)(2616005)(52116002)(186003)(1076003)(81156014)(8936002)(86362001)(8676002)(4326008)(66946007)(66556008)(66476007)(316002)(107886003)(478600001)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB3878;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OsEoDLr1QK1+saYwLkbC7QjRCAlUJKxq6sEyMROMgEgzn1j3C3YmmisfbLrpRVvtGuuf82eVQOP6Syyj7Q682bMHs4AIQzisTvoWWI1AuWUkHbmlJQF80cFz9xDm8qoMSAwkCHsH65kT8bSzCZCM33eT0dXlsBUI8OwjEAdSkzyWykubviUSweIOzvaYuJQ//h5j7A7aZiaaHzlUviacy+e6ksH3jOScoO6NszGwTQ3htmH4fnM5zzh2m3nh4g7aiZEIpZIElv9n4b/kdMKGGlyOY5uVvSH0kFMnT7VreYgEk6RxZoaCL2DgO+otIXnhVScNUmhtJtVkcrldkcn8aR66Yue/oS2WGHUGDJwl4x7QF4R0+m16Vz5GgAMZDyfjdvRxiGghyDgpLAdCc9wh8RLk5QAJaNirFLjLq7Nbm8v3R85GfXtPQwbVewxQfd/a X-MS-Exchange-AntiSpam-MessageData: Vk6ysr6Dz3YzHBpmgwk00nRSweFmKN/zAxNGt/Z9plEDGwPyd/Li1rML1WioyL8pK2F0f04hgq8P2SGK7ATJ8jhtoi0jGXWIRKoYqG1xm1rSkB+obH7V+TP9VgurwZ3p7n4JkgQIXW+u3PTEWKLRnQ== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7155a64-ebf2-4ca1-6d75-08d7b549adb5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:35.1178 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jQ3z1htIHqntjN/Lh9uofbAZJmEzA9fKPmRYLBpKjc5I562j6mDO8YK1r01yro2rBmj5p+of4PaJy9COCepyjT6AiaRay2AZ33OpdtSsk38= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3878 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=834 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org If we are here it means we have fifo enabled for 1 sensor at least. And interrupt is always required for using trigger. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index f9fdf4302a91..d7397705974e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -123,14 +123,11 @@ int inv_reset_fifo(struct iio_dev *indio_dev) goto reset_fifo_fail; /* enable interrupt */ - if (st->chip_config.accl_fifo_enable || - st->chip_config.gyro_fifo_enable || - st->chip_config.magn_fifo_enable) { - result = regmap_write(st->map, st->reg->int_enable, - INV_MPU6050_BIT_DATA_RDY_EN); - if (result) - return result; - } + result = regmap_write(st->map, st->reg->int_enable, + INV_MPU6050_BIT_DATA_RDY_EN); + if (result) + return result; + /* enable FIFO reading */ d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_EN; result = regmap_write(st->map, st->reg->user_ctrl, d); From patchwork Wed Feb 19 14:39:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391635 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E06DD13A4 for ; Wed, 19 Feb 2020 14:40:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AFF2224672 for ; Wed, 19 Feb 2020 14:40:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="leZ0PEh0"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="RERouhd4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726610AbgBSOko (ORCPT ); Wed, 19 Feb 2020 09:40:44 -0500 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:22564 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOko (ORCPT ); Wed, 19 Feb 2020 09:40:44 -0500 Received: from pps.filterd (m0156136.ppops.net [127.0.0.1]) by mx0b-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEc7kj009174; Wed, 19 Feb 2020 06:40:42 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=7FR7F8FgFtcmDyVSk+DOURDCQcMgO+uACeDc9tcm4rQ=; b=leZ0PEh0e05qknTlToFyVdmJf8ntyrou3r2qwUxtVIPwLIAPHMqfOH/0ceLPjnWrgmaY NCLinWTGVc57QMSj4EDhG+JWWiIIII4pYGAp8tYqxgnoK0V9zymDB8j2SV4m1ha6T1Sv Nd0Ke+Zakbse52URxv/gkbgXzTOAkcHwhtH+iW4MUmyqq5BcW2sXxfYlDRlCDvwblGTG hRX8dPQR+GL1tDsq7tQ30OoCSkbRjG7dS1AEoOJsxZGp8qj03GiHjZgXVTiVrxrZS/RN zG+v+0xDewWsUny3EsydgHV6CkyrJYU48wPn0HitXwA5rCTLyutkrD7i3KqEc3aqqDIS pQ== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2171.outbound.protection.outlook.com [104.47.59.171]) by mx0b-00328301.pphosted.com with ESMTP id 2y8uc908h4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:40:42 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bEQRzIhsLlUAkbBxO/iRkH/E1tOTb8oEJqnWC0W30ZMT0YY1LMrlnxAo2x7yJ7tC2raTIR5Ccwa1Ny2GY+/U8i9xyXJQcChkeHLvi+31E8iPjhZd7x0gwUEkNMDMw016KvWX0rji6SElYpnVtmkmpsyrcZdyRliRAuNJ34T2dWMmQWhl8XX2GeyWAQ8qP9qnv1zMkJvzXYDvvuzUQb7E+R/x228DldlEuNzPAuWtQ4DbO2gZqFIULJLHMBaTFB2QeZGFVBzQZtgMfXtPS09GW2qC7/HhX7UX/4zDOihdBVFkXihltQWu+ufNXhf792RvgOTuUq6MK1tqjvjtyIeJUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7FR7F8FgFtcmDyVSk+DOURDCQcMgO+uACeDc9tcm4rQ=; b=jkdTQINofAhnxMhrPWHUkMBdfLNg/ymf9wJq7xXOfn14A7xHmD3T03+UIpp0BiIf4r1R8kmvRPvedUWUtd6EJuSZclwplxrXjfl2d9ZRnlV/LO1y1xwWpKTEbSiro4QaH7spy5PEao/Qs3duZocm3SoUeS4Ph8uBElksGd4gVDC/8oVt8ErAO9W4Z0cw85FaPpD59eifbJ6IvNlibkHhkSXnKKVgofYGJT/YXJ4Od5izxA/LA7Q2PKk1MHQWyKvxr48T1y+3m7/A+UzKPtCbN7S3DOuj9i38olKlGtjaiV0faroyuNTXXKzc5zdCVsp6p8eAamf7MYPg1/lePJLlQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7FR7F8FgFtcmDyVSk+DOURDCQcMgO+uACeDc9tcm4rQ=; b=RERouhd4VUQFE3bkbMMGjhv6BI5K2LhZVC/UOJ5OVQIvrR+KyjLk5NoNEV6WDz9R9tygM6KdKj6hARqX2hS7kYAw/gSMmrhsIRcD3aHdJdvY80elUm5zIT8kQIF+xJgls5o7NbYt312LNWkTnYD0BSND+r2oHzwND2/zXrX1LJ0= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB3878.namprd12.prod.outlook.com (52.132.245.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17; Wed, 19 Feb 2020 14:40:39 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:39 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 03/13] iio: imu: inv_mpu6050: set power on/off only once during all init Date: Wed, 19 Feb 2020 15:39:48 +0100 Message-Id: <20200219143958.3548-4-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:38 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 54ebdd95-b0a9-4ab3-c962-08d7b549b065 X-MS-TrafficTypeDiagnostic: CH2PR12MB3878: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(396003)(376002)(39850400004)(136003)(366004)(189003)(199004)(2906002)(5660300002)(7696005)(36756003)(16526019)(6666004)(81166006)(26005)(956004)(2616005)(52116002)(186003)(1076003)(81156014)(8936002)(86362001)(8676002)(4326008)(66946007)(66556008)(66476007)(316002)(107886003)(478600001)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB3878;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CUhz6tjItsTU034MsgbaVHwETh/qI/iYeA8+zigVURFjX+I5uvw7Ce5EGLtBvbPcL3VxZh0z1Mc9nAFfZX2DGerhh1zzjIl5WNi+mtk9uT/c5UMOZsVjm2p61cwBBezNgu+3PYhL9c/T0JyuMJW/j2TGvY8fZynIDrwPLQmNy8wsc61GZuYh6IT8nG/uV4l+2j2HGQknuZ2CPYVr9MgcRue6o9Zp2COOwuJnYUWeqNVM9YG7SKeDT+ayxnby9FsQzFirXTmIeqkH9ucXr/cpjioW5hEkquqLfFUGTgKDMgmktTN795WdH2LiThp2R/PZBN4xSCsb8sTJlJ2NfPCvyOBaEco+5BtDMANLdrgHVy9oXoJ6HoYx3me3QaJ6dDrX1Xxgun+0TQrPeTfexNQf/vX9ELdoT1PHpvlgC0arVF3FUaP53mglmX9ZXG9ugb4V X-MS-Exchange-AntiSpam-MessageData: Hl1j1HYXwr8DqhIocQuSQhe68rEML9hKlsLH2J7aDBpoptf7CIDEOmsEZuWyG87FFkpsEjy3TIQkZWxU8MtvyU/swX+aNWNyIo15ikSNvAHTEh5CVZkw16R/vEinr+LFvWj9D2PW5CgQR86rdf9+Jg== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54ebdd95-b0a9-4ab3-c962-08d7b549b065 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:39.6350 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: p7nTfjQnOwncxQlJDQ7DR867TviaxKHGRIJHDC7ku3ffZVTrPztwIyveYuNVIUWVunFt14CIi+9HxKV7Jhc/E4EMnE3IBoNCtTKpObDxLMQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3878 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This way there is no need anymore to export the power function to i2c and spi modules. Bus setup is done inside init when power is on and the result is now checked. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 41 ++++++++++++---------- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 11 +----- drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 10 +----- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index c4db9086775c..0b06d6aa6469 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -301,7 +301,6 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on) return 0; } -EXPORT_SYMBOL_GPL(inv_mpu6050_set_power_itg); static int inv_mpu6050_set_gyro_fsr(struct inv_mpu6050_state *st, enum inv_mpu6050_fsr_e val) @@ -371,27 +370,23 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) u8 d; struct inv_mpu6050_state *st = iio_priv(indio_dev); - result = inv_mpu6050_set_power_itg(st, true); - if (result) - return result; - result = inv_mpu6050_set_gyro_fsr(st, INV_MPU6050_FSR_2000DPS); if (result) - goto error_power_off; + return result; result = inv_mpu6050_set_lpf_regs(st, INV_MPU6050_FILTER_20HZ); if (result) - goto error_power_off; + return result; d = INV_MPU6050_FIFO_RATE_TO_DIVIDER(INV_MPU6050_INIT_FIFO_RATE); result = regmap_write(st->map, st->reg->sample_rate_div, d); if (result) - goto error_power_off; + return result; d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); result = regmap_write(st->map, st->reg->accl_config, d); if (result) - goto error_power_off; + return result; result = regmap_write(st->map, st->reg->int_pin_cfg, st->irq_mask); if (result) @@ -410,13 +405,9 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) /* magn chip init, noop if not present in the chip */ result = inv_mpu_magn_probe(st); if (result) - goto error_power_off; - - return inv_mpu6050_set_power_itg(st, false); + return result; -error_power_off: - inv_mpu6050_set_power_itg(st, false); - return result; + return 0; } static int inv_mpu6050_sensor_set(struct inv_mpu6050_state *st, int reg, @@ -1176,7 +1167,7 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) if (result) goto error_power_off; - return inv_mpu6050_set_power_itg(st, false); + return 0; error_power_off: inv_mpu6050_set_power_itg(st, false); @@ -1341,7 +1332,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, result = inv_mpu6050_init_config(indio_dev); if (result) { dev_err(dev, "Could not initialize device.\n"); - return result; + goto error_power_off; } dev_set_drvdata(dev, indio_dev); @@ -1353,8 +1344,16 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, indio_dev->name = dev_name(dev); /* requires parent device set in indio_dev */ - if (inv_mpu_bus_setup) - inv_mpu_bus_setup(indio_dev); + if (inv_mpu_bus_setup) { + result = inv_mpu_bus_setup(indio_dev); + if (result) + goto error_power_off; + } + + /* chip init is done, turning off */ + result = inv_mpu6050_set_power_itg(st, false); + if (result) + return result; switch (chip_type) { case INV_MPU9150: @@ -1413,6 +1412,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, } return 0; + +error_power_off: + inv_mpu6050_set_power_itg(st, false); + return result; } EXPORT_SYMBOL_GPL(inv_mpu_core_probe); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index 24df880248f2..6993d3b87bb0 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c @@ -78,22 +78,13 @@ static int inv_mpu_i2c_aux_setup(struct iio_dev *indio_dev) /* enable i2c bypass when using i2c auxiliary bus */ if (inv_mpu_i2c_aux_bus(dev)) { - ret = inv_mpu6050_set_power_itg(st, true); - if (ret) - return ret; ret = regmap_write(st->map, st->reg->int_pin_cfg, st->irq_mask | INV_MPU6050_BIT_BYPASS_EN); if (ret) - goto error; - ret = inv_mpu6050_set_power_itg(st, false); - if (ret) - goto error; + return ret; } return 0; -error: - inv_mpu6050_set_power_itg(st, false); - return ret; } /** diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c index bc351dd58c53..673b198e6368 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c @@ -21,10 +21,6 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev) struct inv_mpu6050_state *st = iio_priv(indio_dev); int ret = 0; - ret = inv_mpu6050_set_power_itg(st, true); - if (ret) - return ret; - if (st->reg->i2c_if) { ret = regmap_write(st->map, st->reg->i2c_if, INV_ICM20602_BIT_I2C_IF_DIS); @@ -33,12 +29,8 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev) ret = regmap_write(st->map, st->reg->user_ctrl, st->chip_config.user_ctrl); } - if (ret) { - inv_mpu6050_set_power_itg(st, false); - return ret; - } - return inv_mpu6050_set_power_itg(st, false); + return ret; } static int inv_mpu_probe(struct spi_device *spi) From patchwork Wed Feb 19 14:39:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391637 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DD6B930 for ; Wed, 19 Feb 2020 14:40:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15FC524670 for ; Wed, 19 Feb 2020 14:40:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="l9SldotH"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="URkD6Xg3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726683AbgBSOkq (ORCPT ); Wed, 19 Feb 2020 09:40:46 -0500 Received: from mx0a-00328301.pphosted.com ([148.163.145.46]:59430 "EHLO mx0a-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOkq (ORCPT ); Wed, 19 Feb 2020 09:40:46 -0500 Received: from pps.filterd (m0156134.ppops.net [127.0.0.1]) by mx0a-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEdZsI016944; Wed, 19 Feb 2020 06:40:45 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=jFPSXbujM9lLcbXjIsL1hv1vTOO0fm/ny77cSG39Ok8=; b=l9SldotHg6vLQbzH9mQFSq9IiOLRYS8hozyzlaP7T4TOOUQJAcoiRM3Keh/0pHPG5hZO pcJjDiV9zPkFRpcQPFwAFo/21/l8dsRKpd4koctE1nmTAQZRLqLr9C/qrk6t5jToNukq 7TFbPfQOYL+bQdlFRej0tCuZe08F7Jsi6XpwmFC95djXEYC8BNms8CIZC7HW3wAoPrb1 P/VGfeRXt7sJgU5hvX8Uk1wd3x/qFlFgFIl/uDe4hE1e50AdwiF78Zam4fnwEra9nre2 x6/TnCe6gskNCyg5Nlmrf3x7furSPuKN1RuOP4VbP2khyPWcoS3+OgVzSR9ILAoDeaSD FA== Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2105.outbound.protection.outlook.com [104.47.55.105]) by mx0a-00328301.pphosted.com with ESMTP id 2y8uem892j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:40:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JFX9HtnIq6IlHIqGVImydeWlXZ0hf51oyHwJ9slIzgW0vlyJuLuO5toU4TA0AhG2dfdGx8EPkY9oSqUAAk/cPfItygfBYcMmO3JZDHdivamumOVh1bRtXWsLK8JiIPZMnivZ9Y+8AfBExqtC7OsRU8O8o0kWEAY693qI/cBmY8EUKNaRmvrUDc7+OqgwucnsWLSWTQQggyin1fPK8k/J61enPnTESB77ULiz9RCyBR7qiAonmXAkch4gT7sgZaFnumdU7gPV0BxhZUpcSZq5N6wNvgw+0AAb0DS/Dup08aOpRYPmBk7Ah76a0/PAOeN/w8AKNNBx1hTPp98vWYGt3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jFPSXbujM9lLcbXjIsL1hv1vTOO0fm/ny77cSG39Ok8=; b=jWvgK2gPwNkDajGC1AT1qE/unmG2qjfOSl/lZzYZRb0yXAI0KcORBPlmPcWknnQk8/z0138OQecyS8NE9Woi8qVuqhzM8O/KosEZfLEdO3qv88nDIZlA6WlRAHkuIxkwej/DxUoDB28twaJ4JuuoB9n6J2aZZRzkpLzTi0j1k7opsxQ+dhZSSbVGHxPRtYFrGvaAJG46NXqTw5laTKrZkkrnYK5DQ+bQgKhdbB+Eba+L+1jvNEDDI8zdb68uO23+zzKYH7DBAktPM3bHbuwHpyX5f5lt9BMeP4dnWBCSpMaLFq5rGBV02fFEAzYrlGH3UwcpJ1myWMiO+5kfvIvVIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jFPSXbujM9lLcbXjIsL1hv1vTOO0fm/ny77cSG39Ok8=; b=URkD6Xg3trTUwH77YpAPvtcCniNNdZvTxN8Lhj+r+/2W5bW6PZSbGkhx3U0XDmPuRR4ngXPStqSCdqEH3cEiNFkTRr8i4nfS3b1rbEqfL6JDj0kt+5fvTt3X1MuHSGhiPa5MwHsnwwUWoP8vPesrBbJ/OP/APhnpZtR/jpd2ZcM= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4213.namprd12.prod.outlook.com (20.180.5.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Wed, 19 Feb 2020 14:40:43 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:43 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 04/13] iio: imu: inv_mpu6050: simplify polling magnetometer Date: Wed, 19 Feb 2020 15:39:49 +0100 Message-Id: <20200219143958.3548-5-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:42 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 354fb49d-0e47-41dd-d723-08d7b549b2ba X-MS-TrafficTypeDiagnostic: CH2PR12MB4213: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(376002)(396003)(346002)(39850400004)(136003)(189003)(199004)(2906002)(36756003)(16526019)(26005)(86362001)(107886003)(2616005)(66556008)(66476007)(4326008)(5660300002)(66946007)(81166006)(186003)(478600001)(81156014)(7696005)(8936002)(1076003)(8676002)(6486002)(52116002)(316002)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4213;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 64ameCA4jGudLUQRKmyUcAnbIT5mjsfhZak4zK0A2a0nd4YensUeZEaWeRElvx64rrgWeKGpXj4dYNN4DXBjpKMeeOy6EIwYiW+xhR9APJBOhOiCMkbbbDPKpXIgCeMlpGBhgeKvS/bLvQSUU/0laxkHGKSbU5gtypiv40KUzsuKuXihkD7M6MigjV0/J1/nrnbZkFiGLQp0OQ/Ath2BUF79n1DKTHgnf1oBSb4ujoZXDEjczjE7dmaPuBX/QHZNzQhoyJgN6RIPjIyT+ahA5M24qRGtsK2xK1Nfll2iiCVwjFttguxFCGxGe5192Cdfch5YUfmB/EnxuKBdL32WQ6Kb5cLCUOKvw4vlvgaNbB1NZwI8ae9c3GWUSyNcSvWcvturayUWTpI/nH5YdnHP6bRbtURducbvWH4R1ifFVILtC1Jbd9SaYHTfcKCNf4n6 X-MS-Exchange-AntiSpam-MessageData: 7C3FFUzrTFsSRYx3/VDmGtg45NVv9GNYM8dx0BtzzPVJrgs0fKWkjOWK5vRXBiB9F8MrIOq0c6+fE2a8DDlGOYHAUAzYXAM07vS7ZIeYGdzSKinyXcc37ApF+KF0owfYuTt6BMU/V2Htimp+wBSx4g== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 354fb49d-0e47-41dd-d723-08d7b549b2ba X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:43.5438 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: O8+Xlq3CWBuFC9MEAhx1ME4Rn0hJTRk3uhzFL/16hnyXo3RFV4LJndPjEpgPdUa75L+NAuXIhkFnwN4kv6dx/8C9rwkbYz8QH9efMLYAkUw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4213 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Do not change the sampling rate value. Let userspace decide what is the sampling rate to use. Read only the requested axis. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c index 4f192352521e..607104a2631e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c @@ -319,36 +319,36 @@ int inv_mpu_magn_set_orient(struct inv_mpu6050_state *st) int inv_mpu_magn_read(const struct inv_mpu6050_state *st, int axis, int *val) { unsigned int user_ctrl, status; - __be16 data[3]; + __be16 data; uint8_t addr; - uint8_t d; - unsigned int period_ms; + unsigned int freq_hz, period_ms; int ret; /* quit if chip is not supported */ if (!inv_magn_supported(st)) return -ENODEV; - /* Mag data: X - Y - Z */ + /* Mag data: XH,XL,YH,YL,ZH,ZL */ switch (axis) { case IIO_MOD_X: addr = 0; break; case IIO_MOD_Y: - addr = 1; + addr = 2; break; case IIO_MOD_Z: - addr = 2; + addr = 4; break; default: return -EINVAL; } + addr += INV_MPU6050_REG_EXT_SENS_DATA; - /* set sample rate to max mag freq */ - d = INV_MPU6050_FIFO_RATE_TO_DIVIDER(INV_MPU_MAGN_FREQ_HZ_MAX); - ret = regmap_write(st->map, st->reg->sample_rate_div, d); - if (ret) - return ret; + /* compute period depending on current sampling rate */ + freq_hz = INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); + if (freq_hz > INV_MPU_MAGN_FREQ_HZ_MAX) + freq_hz = INV_MPU_MAGN_FREQ_HZ_MAX; + period_ms = 1000 / freq_hz; /* start i2c master, wait for xfer, stop */ user_ctrl = st->chip_config.user_ctrl | INV_MPU6050_BIT_I2C_MST_EN; @@ -357,19 +357,12 @@ int inv_mpu_magn_read(const struct inv_mpu6050_state *st, int axis, int *val) return ret; /* need to wait 2 periods + half-period margin */ - period_ms = 1000 / INV_MPU_MAGN_FREQ_HZ_MAX; msleep(period_ms * 2 + period_ms / 2); user_ctrl = st->chip_config.user_ctrl; ret = regmap_write(st->map, st->reg->user_ctrl, user_ctrl); if (ret) return ret; - /* restore sample rate */ - d = st->chip_config.divider; - ret = regmap_write(st->map, st->reg->sample_rate_div, d); - if (ret) - return ret; - /* check i2c status and read raw data */ ret = regmap_read(st->map, INV_MPU6050_REG_I2C_MST_STATUS, &status); if (ret) @@ -379,12 +372,11 @@ int inv_mpu_magn_read(const struct inv_mpu6050_state *st, int axis, int *val) status & INV_MPU6050_BIT_I2C_SLV1_NACK) return -EIO; - ret = regmap_bulk_read(st->map, INV_MPU6050_REG_EXT_SENS_DATA, - data, sizeof(data)); + ret = regmap_bulk_read(st->map, addr, &data, sizeof(data)); if (ret) return ret; - *val = (int16_t)be16_to_cpu(data[addr]); + *val = (int16_t)be16_to_cpu(data); return IIO_VAL_INT; } From patchwork Wed Feb 19 14:39:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391639 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ACFAD930 for ; Wed, 19 Feb 2020 14:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84E5124672 for ; Wed, 19 Feb 2020 14:40:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="v8JwbKYw"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="UXxrzl4G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbgBSOku (ORCPT ); Wed, 19 Feb 2020 09:40:50 -0500 Received: from mx0a-00328301.pphosted.com ([148.163.145.46]:63542 "EHLO mx0a-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOku (ORCPT ); Wed, 19 Feb 2020 09:40:50 -0500 Received: from pps.filterd (m0156134.ppops.net [127.0.0.1]) by mx0a-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEdVSN016934; Wed, 19 Feb 2020 06:40:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=MVVBtRXHr6LCuQTLaHsj3Nxg8sq2OgfadZ8gQWwmvQE=; b=v8JwbKYwEvof1hDCkN+q1mVjMJB6Q6lLi/jKcCT1o7WQZ7OtRnVkN5nFCElk532jdpop YNCNg6faf3NlEo5i3CsM0Bc6wZR1tyb13Sc2pFDsMh6VYzi36M18kPvfLXvRTsx7xmHq PcL0MQDGPi/heJB69053BPdlKxyYZOFgQC37HypUatlrpA8hTKUcYqnPcpgxek7ewGLJ VagF4mobFKdZM4Uh+iTkGieue4gpoT/zdVBhDhHxg0Idof6dOeiZK4qU0pRbSyZsJnrV hcYLaSOasrr5KmTnftHI6oF9TbUjCaS5h0FxX0lyHN8f8OCBtgWxIJH7weSNqSZh1vDY Rw== Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by mx0a-00328301.pphosted.com with ESMTP id 2y8uem892q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:40:48 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=njqeWHKf3kpq6EFMNsbsJTo2T88JZWubfJfNlKnyINwAdZFWHZ479UcDvX3AGOOCFrmkgBMpwZCELoeQbl+WO3mVlJq37snjbzRUjDbqPdl6B7eT3+5NxozNvpR10h3S9+oXJwWqx2zFYmeBgex9+2IxtMem8+Cx8sd/58X5sgdjbu3eCxBJcuxYAe+xJeVE9rJ5SjWpgy4e2KcTbovXA0TrvU3YC+SXnIGOD/fMKi4NsnAl/pGwVQGQDPHJIoRJ3uAHc+MaSNGn3VkUhxJdGH1qJIP2pqacgufOU8LWDRdvswWe2IEL1pYPPs2on2wFNkRnJLexM9+omJlx0vsfJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MVVBtRXHr6LCuQTLaHsj3Nxg8sq2OgfadZ8gQWwmvQE=; b=gAYUy/R8DOcV8MJxRS/8z3Bt35NpLN0wq/iDElf8AnYkfZZjjNhEqX6UfzsLgcfL/C9ppCdCVPzKKWP1Ar65EvZwJRIqgWeA1dAgliosaq7Jp/0e3u2Y03WQbpK2KTmQYW4qNiOLzYtCzqxIN+kJP3up6Oyha0O5699E3X0rst9+PekkxK8+H8S22bMxEjxRv1pZb1Ml/RjUpZrOwjKfhBb22bs+dkRZoF5ao5h2GqLzB6VLwnoCYxwsY9xeKdCm6LB1iW7KR0S43u4dP6AVuoJXTPAY/+hX9YKYOSXCmOUhplpEhOFi1MIB1UKq21wRn03xOwdXzh0iJjaoAz/wDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MVVBtRXHr6LCuQTLaHsj3Nxg8sq2OgfadZ8gQWwmvQE=; b=UXxrzl4GRKrcvT+vrhIreIHqwRkOAYTmLOUe20NT0deVoSurrbEaJchbo1qzTkB93OMVkKMBb9RMSdPCeblJo8hNax1KmS7tLaANzzfNAf9rKMqXJKaVgYQ4CWpm5gGDmeq9E/vlv6JoXhgIsVvXCmESQuVwkaCzSgxsTTFXEIo= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4213.namprd12.prod.outlook.com (20.180.5.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Wed, 19 Feb 2020 14:40:47 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:47 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 05/13] iio: imu: inv_mpu6050: early init of chip_config for use at setup Date: Wed, 19 Feb 2020 15:39:50 +0100 Message-Id: <20200219143958.3548-6-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:46 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9eba5d1-c89d-46d3-f21f-08d7b549b517 X-MS-TrafficTypeDiagnostic: CH2PR12MB4213: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(376002)(396003)(346002)(39850400004)(136003)(189003)(199004)(2906002)(36756003)(16526019)(6666004)(26005)(86362001)(107886003)(2616005)(66556008)(66476007)(4326008)(5660300002)(66946007)(81166006)(186003)(478600001)(81156014)(7696005)(8936002)(1076003)(8676002)(6486002)(52116002)(316002)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4213;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5G6vU1j9HO645ePdqzwfwSCHl2YM96A6aW46yfrmSfMqpxRfklhxjn/dLNrpplIzTHRIrjvFBuTLHV+FMfgJrisIQobPZ0W4p6cDoKocJP/q6IZfeuUx7dnV6ASKe1xzBiRNXSKUKOwIlvmuT5fQ7KId1HXY4P5fSBxpSFSN5HPq5dHSWDykMMmT7Gxh7CpR4gXo07asMMylQKU6dQyERyc28veI5aW3nOYmGPbvYm3OVyq5UBB1uNYSjD57ma0wERV5Z4xIC2ihJsBu66U49+pXKZyuRwMMcbdapeScr+1wL/ZO8h0H3zuxpeVdeXS9/GEutcfgEHqkIuDQE7a+2C5seJph2rq6lSQ8MEs7wV+keEQQaE57BfxOP7XiA1Rx0eN4gA2YPk2iq5dxNYQHTfNc9Om4EHQXRHaXEMSEEnFxoPbob8dVf1c/7TOZql1o X-MS-Exchange-AntiSpam-MessageData: zTw8uhMUpD3W1MS1ngNmBzVw05lT7snJjswo5VChfZRdu7b9dP5q9HSHce8O2wOkOzzGmIm9OQWWW1VrXOnB/eVQGSikKicLoP6Xj8g+uX+Fs6RAD2VVmjY86CCKXF02ICwZkRDwNme8HVFbfrkzMw== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9eba5d1-c89d-46d3-f21f-08d7b549b517 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:47.5264 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2h5HL6qIBM7oubFfUZw+6XyRzcWMcC4/kf5u2QU5s6jFjeHBIDPDc/b7RWVU9XzQpHnuu8xB6BT4jrRd9acwBDiNh1kMCq6yivA04r+Jbvk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4213 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=907 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Init chip_config early and use its values for initial setup. More coherent, prevent possible mistakes. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 15 +++++++-------- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 1 - 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 0b06d6aa6469..85872e55154f 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -101,7 +101,7 @@ static const struct inv_mpu6050_reg_map reg_set_6050 = { static const struct inv_mpu6050_chip_config chip_config_6050 = { .fsr = INV_MPU6050_FSR_2000DPS, .lpf = INV_MPU6050_FILTER_20HZ, - .divider = INV_MPU6050_FIFO_RATE_TO_DIVIDER(INV_MPU6050_INIT_FIFO_RATE), + .divider = INV_MPU6050_FIFO_RATE_TO_DIVIDER(50), .gyro_fifo_enable = false, .accl_fifo_enable = false, .temp_fifo_enable = false, @@ -370,20 +370,20 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) u8 d; struct inv_mpu6050_state *st = iio_priv(indio_dev); - result = inv_mpu6050_set_gyro_fsr(st, INV_MPU6050_FSR_2000DPS); + result = inv_mpu6050_set_gyro_fsr(st, st->chip_config.fsr); if (result) return result; - result = inv_mpu6050_set_lpf_regs(st, INV_MPU6050_FILTER_20HZ); + result = inv_mpu6050_set_lpf_regs(st, st->chip_config.lpf); if (result) return result; - d = INV_MPU6050_FIFO_RATE_TO_DIVIDER(INV_MPU6050_INIT_FIFO_RATE); + d = st->chip_config.divider; result = regmap_write(st->map, st->reg->sample_rate_div, d); if (result) return result; - d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); + d = (st->chip_config.accl_fs << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); result = regmap_write(st->map, st->reg->accl_config, d); if (result) return result; @@ -392,9 +392,6 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) if (result) return result; - memcpy(&st->chip_config, hw_info[st->chip_type].config, - sizeof(struct inv_mpu6050_chip_config)); - /* * Internal chip period is 1ms (1kHz). * Let's use at the beginning the theorical value before measuring @@ -1116,6 +1113,8 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) st->hw = &hw_info[st->chip_type]; st->reg = hw_info[st->chip_type].reg; + memcpy(&st->chip_config, hw_info[st->chip_type].config, + sizeof(st->chip_config)); /* check chip self-identification */ result = regmap_read(st->map, INV_MPU6050_REG_WHOAMI, ®val); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 9a81098a8b4d..d5edf903c076 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -321,7 +321,6 @@ struct inv_mpu6050_state { #define INV_MPU6050_TS_PERIOD_JITTER 4 /* init parameters */ -#define INV_MPU6050_INIT_FIFO_RATE 50 #define INV_MPU6050_MAX_FIFO_RATE 1000 #define INV_MPU6050_MIN_FIFO_RATE 4 From patchwork Wed Feb 19 14:39:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391641 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4134B930 for ; Wed, 19 Feb 2020 14:40:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1997C24672 for ; Wed, 19 Feb 2020 14:40:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="r4LcNwu8"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="YhpknAJs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726697AbgBSOky (ORCPT ); Wed, 19 Feb 2020 09:40:54 -0500 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:36028 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOky (ORCPT ); Wed, 19 Feb 2020 09:40:54 -0500 Received: from pps.filterd (m0156136.ppops.net [127.0.0.1]) by mx0b-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEandX007777; Wed, 19 Feb 2020 06:40:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=A2A/F5LZ0QhdPfyYutPKZ+T4auYI0oxbnMa0to7ZA0o=; b=r4LcNwu8R2QgaYFyJt99Tgz3Egc//UqxVI8a8EuLSlI9hHgo0py2YMNuel+Liq4kEtMh R4ZB8W/3M6SKs5jW/VFgwgaL21vaOlySenK6Xk3h+4X07EP5jFHTTj0RmxpHok+B4hkr 6wnoOcVhpIYesMhsxpgFLmHEtrRHBDTq5h2EyLtObosiLhaNCAS0xSc3IpVuzxutwDpT kDvJryCL/BbK+1CIignQ3uAZ21nBcSAoQTkTecllgIWl2iYqkTjyIZfK+R5AAsQjvKa+ xhYQHvcRDDGvD3INpVztA3GmK4Vae8Coq3v0Msjp+7qpX8rMxzyTkOLw8rhCCClzczwS Ew== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by mx0b-00328301.pphosted.com with ESMTP id 2y8uc908hc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:40:53 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ehAPG8H5TmBfzoAkTzhDqwt9+fcTEBAe7mlY6W93UmPheImjvD76NTGg0MI/r8fou3iDXzTK22pTn7X642U9wAFdx3yxRUOkdlxbAO8wlCfm818Xn/u9mxoZgeHkxHI/aMFkiDWlm7mqj+5Yj/quFdVFVGSpK9kPoRNs8cQ4FzaYOO5fN36dv9nj/WaIG8HTZ6vncyeRx89WQinvxHMrpPksgEzBBEj+FY7GHpxL1MfuOgf0wmijgA2xTfmOCOD4dcOGBesQK39zh2PrAMFeLSeANsr/7AnRs6matHSeN2HWjnLPGd1SxKjTMGBoRbK5nEE42hBxIvckeuQqS4+QEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A2A/F5LZ0QhdPfyYutPKZ+T4auYI0oxbnMa0to7ZA0o=; b=OtiFs6Rs8ErikJ2lzWFlJdGgC0LB6TRossLDRcMEjupHXbX/VXssJp6rAT9noVCnR2ziJWELUmleD+jlZ4sMxJjhSkrGM9jLhDP52EoBcfE8yudpWMtsyucpyudlE6p2dh7x1GmF321/T6Qfqp4CPy/vcASUknG+2GZxVfxVcOCeU+IV9SxYR7/nEL+zhuJ6pdFaade4SyQJ2n3OWHs5KQ8b8W3L7s/loScJi3XcQRZVtAQJybyFnpZVDq6XlQRMhg1dj03qLpesXjpAb0goGXyfzP1JFGpu0bXAwBCeiqg8aEAgnE2NpuDD1khhUMWtXu/EQaFtGqtzZ7mjd2crHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A2A/F5LZ0QhdPfyYutPKZ+T4auYI0oxbnMa0to7ZA0o=; b=YhpknAJse7KdG4+/p4WZY6aebkM/P/5llamgpDeT3WdeCP6RtsTQQtFjQeQuO8KR9hPGKERZnizfQyL74AqtmTPh2iSyERplkQYOk8lEItOaV6HYCA6/oKy5EmlGR/EAt1Vxjf4ET8XwROhl9V9y6VHlTXyoD53/w+mBIoTUBCs= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB3878.namprd12.prod.outlook.com (52.132.245.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17; Wed, 19 Feb 2020 14:40:51 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:51 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 06/13] iio: imu: inv_mpu6050: add all signal path resets at init Date: Wed, 19 Feb 2020 15:39:51 +0100 Message-Id: <20200219143958.3548-7-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:50 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 36a9af2f-df74-4425-54e7-08d7b549b783 X-MS-TrafficTypeDiagnostic: CH2PR12MB3878: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(396003)(376002)(39850400004)(136003)(366004)(189003)(199004)(2906002)(5660300002)(7696005)(36756003)(16526019)(81166006)(26005)(956004)(2616005)(52116002)(186003)(1076003)(81156014)(8936002)(86362001)(8676002)(4326008)(66946007)(66556008)(66476007)(316002)(107886003)(478600001)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB3878;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qhRtlE55lwWKzUADmEdqUQgNYj+Rt3cxpSUmWUdhHQKzb96I56EFzhceotbU3X2OLQHCnrwKmuWNF3ovn1SoCNWoUf2CZGYOdT9CIIpRO6Ch0+mMb/yHVS+M9LT/mWPb6t4d57oNVbe0E8JQQZ7kX6V970FxEZeZkxGqc8PyyVn5Xz8h/mzr2zxf1mWfKu5tVjis2bel/JGH49VfsEpWNEV3IcuzkyEc8Jr21xurQ+NhYsB6HUNAumoWRCWSmMpMAKiabjOyHx7stFR1txrFvYvmVDBEmnYVggX/xshT4rBjR/cHFfn/FxFkuZBXSShDG1M5klLNmT1YoAXrN2LmAb5bHxV6HegT+CaCJqiGcdR9gOBLhDZQak9oAVsWLbsnx2ab6vg8xzckTOmWPpoQQdHGslC/vb46axgd8//uojqAdpnKizmXCSkDPv34Ye8R X-MS-Exchange-AntiSpam-MessageData: cGOj6nm/FjDGsPG3xug6pOyT5O+D7jcMhbxLDi8TNfQD8s3ncJjMCSv1IAm+SMkdbxZL1MAC4F+PwkSXA9bbYVkf2E8gdsNs+nRA3IZBwnj5DqKTKpdQn7Eg2WNZG8NZBq7hRFiZ7kgMMeoxv1j70A== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36a9af2f-df74-4425-54e7-08d7b549b783 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:51.5956 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: g+qRQPYZFidds+fcJRNctJOtQt3YmPN9ivpGD+ZGl6rXvE0HENiaoQ8vOL1Aa+08y6wXXOqk8dLN0YmoPDQ/xAQp42CzI81vj98Puc6pdyU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3878 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Old chips using spi require for a full reset to manually reset all signal path. This does not harm when using i2c so do it inconditionally. Exclude i2c only chips. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 18 ++++++++++++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 85872e55154f..3502b996671c 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -1146,6 +1146,24 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) if (result) return result; msleep(INV_MPU6050_POWER_UP_TIME); + switch (st->chip_type) { + case INV_MPU6000: + case INV_MPU6500: + case INV_MPU6515: + case INV_MPU9250: + case INV_MPU9255: + /* reset signal path (required for spi connection) */ + regval = INV_MPU6050_BIT_TEMP_RST | INV_MPU6050_BIT_ACCEL_RST | + INV_MPU6050_BIT_GYRO_RST; + result = regmap_write(st->map, INV_MPU6050_REG_SIGNAL_PATH_RESET, + regval); + if (result) + return result; + msleep(INV_MPU6050_POWER_UP_TIME); + break; + default: + break; + } /* * Turn power on. After reset, the sleep bit could be on diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index d5edf903c076..17f1f6a15f95 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -245,7 +245,13 @@ struct inv_mpu6050_state { #define INV_MPU6050_BIT_I2C_SLV3_DLY_EN 0x08 #define INV_MPU6050_BIT_DELAY_ES_SHADOW 0x80 +#define INV_MPU6050_REG_SIGNAL_PATH_RESET 0x68 +#define INV_MPU6050_BIT_TEMP_RST BIT(0) +#define INV_MPU6050_BIT_ACCEL_RST BIT(1) +#define INV_MPU6050_BIT_GYRO_RST BIT(2) + #define INV_MPU6050_REG_USER_CTRL 0x6A +#define INV_MPU6050_BIT_SIG_COND_RST 0x01 #define INV_MPU6050_BIT_FIFO_RST 0x04 #define INV_MPU6050_BIT_DMP_RST 0x08 #define INV_MPU6050_BIT_I2C_MST_EN 0x20 From patchwork Wed Feb 19 14:39:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F40E2930 for ; Wed, 19 Feb 2020 14:40:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D4F6824672 for ; Wed, 19 Feb 2020 14:40:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="baUeUK7l"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="TxSm/Luq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726700AbgBSOk6 (ORCPT ); Wed, 19 Feb 2020 09:40:58 -0500 Received: from mx0a-00328301.pphosted.com ([148.163.145.46]:8006 "EHLO mx0a-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOk6 (ORCPT ); Wed, 19 Feb 2020 09:40:58 -0500 Received: from pps.filterd (m0156134.ppops.net [127.0.0.1]) by mx0a-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEdvML017413; Wed, 19 Feb 2020 06:40:57 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=qxUlRkH1AH40ywDEC6scD2Q7UYYGY/mICPPAw/oBUiA=; b=baUeUK7lxPR9cKvo8rP4LBMzQKQxseuV/wr+y82ICKBB3J1rTDCFjxp4R/anxB7jX6EJ 4ZiwtnwnIGm0YJw+bcEYfNLqKmemp4vPFFxsTg6nrdeGq0Dp/wJAHNvBr1LBEpKsEA6/ Zl5m7FUKqsiGN6LxbekbyUjQ48DXZEDM7BpGrZJJ3RTsT4lSaLK3LbMioCNiOu6fdB+F 2/TyJILXqjnvAoLBhg71nfLWFxfE4b/u+r+Vxixm7DbLqVZldzRsmtajzsDQ0pMqV5ou Ca2AeCVr8s8Bll40+y9Xy119JKe6JnGXtkIRtD1ardrXwoYhfv9zlWkgrChTUcbTRI9V iA== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by mx0a-00328301.pphosted.com with ESMTP id 2y8uem892x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:40:56 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h0YNrinrNFTYV8yGaGA4PmdONOhwZfcYx4VsAgXuFZfjmaQBmDB9amNtF9SNHTcK7LlxoPl4SxDNcOiwnaS4Omskq1l5+TfM8fCLedmUrpw3kSyCDp5bcjfLK9z9/YufV9kAyVDgpldkyQuzmmBxLkiecaApfx/l/ySG3atHp4WFbvsLOFswbN6/9oiwRx2RtsHmwVAO2mDbjRtH3yYa/ZCcqBQF62pQtxFqnhMvZiZA/tmR4BjW9ujBRk2nnPs4igQwLc0TZLPEXYDCry8JpJz86HvVeYGzqfnXsjcp/n5vQdx8DTHcJ5D9/zqq0Jet4zqvnGQImzMyUHcHu2d0Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qxUlRkH1AH40ywDEC6scD2Q7UYYGY/mICPPAw/oBUiA=; b=hIO0vWYahC33U120dqM3ftf+vFgDw8Dk0na2aS9lKopAngSirN1dHOZ/EXR2FQF1JWnSrbxF4ugcP7Fu90NlK4AAH7b03yTaw+NL5H7hjTcfmxNNAYC3GGrVVEjzU8pAZbKlk4R6Ntb3L+5fw2Sq+gQWqqllq7CvEfY3INgEJPlex+GiMACxL1nHbwz2SKLbOIBDWkyn27sbJUbFhroiZqvpB3bRc4GutEJBJjZDOieSqszw6nPFRf8RCSkGeWuc/So0B8RULUV0It3OitZsdE4Nnl3CyJxY2hoK7EabN+eKRTJ+Wd/tA5J7cEQGV2wRKJ1R/yWWbdWbktRpSCvjjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qxUlRkH1AH40ywDEC6scD2Q7UYYGY/mICPPAw/oBUiA=; b=TxSm/LuqT04cDcuGy8bLXbim3IuDhw2Z7fGHmpbrCScCIMPHeBT8/TkwOmXti7W10lN/UtIreEd6I3xOwpENUR1+Rvkqk4YbEdu9ZnyNrh+j5D4TTcZoornnIoQdKGnOodbyJ1MI1NK/qEc22aazjadGxP/jOWNN/L6hzWN6S4w= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4213.namprd12.prod.outlook.com (20.180.5.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Wed, 19 Feb 2020 14:40:55 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:55 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 07/13] iio: imu: inv_mpu6050: fix sleep time when turning regulators on Date: Wed, 19 Feb 2020 15:39:52 +0100 Message-Id: <20200219143958.3548-8-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:53 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 80fd47a1-10a2-47f4-211d-08d7b549b9c8 X-MS-TrafficTypeDiagnostic: CH2PR12MB4213: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(376002)(396003)(346002)(39850400004)(136003)(189003)(199004)(2906002)(36756003)(16526019)(26005)(86362001)(107886003)(2616005)(66556008)(66476007)(4326008)(5660300002)(66946007)(81166006)(186003)(478600001)(81156014)(7696005)(8936002)(1076003)(8676002)(6486002)(52116002)(316002)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4213;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: baYkajMIwKRSVIrW35YrEyIr+Xi3ZIu0IV85DXil2yujs50h5yGwikihAYMyX6hu9tyJI+GtYCYAdj/yl16UA2sFSLKYCgiSst/O91El+hBltopsYneD5s9xPAqE1eiLTmwwQZdnlFkg1y1fJHx1yFhSJPrgEbdQ8lr+fhZExdbSxZhB2fniACpf0AMLt0nyvBy2NdaLyNYeO1I5gzCq1rMZ9sLB0EkZSn5e4mhqy+3svt3KuZq+dve9gQWlJ3TJ7YUKJeSaCYC5WoGXmFLkUyGyatjs0JXbU+Ujc53sL8B7JcpmXKCLQTdyNPKiZE3uyxxedrfNcs9fKkW9R3F//a0euFwEn+qtZeKF6+DZKejQz+9xj2Of0dN3WBSsoQiKzqMgdNyY7oyv0UfO53e+UiszJM1HlYos2d/iIMTdAc4Tr9T3fDn8MB9g1kK1+yz7 X-MS-Exchange-AntiSpam-MessageData: nULEUKBaBQBge2dC9TReqQ9tm3ekYGRqzDTygRxii0SxKdmgmR4kUlKpbcCdMHoEUZTZy7aQBsromUWLCspnsVeFdgwIw51dFi1QlsiKshklz6A0c5uM0XyqiYDl3CpePohRe7Z0Vi8ojB/I1JXdbA== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80fd47a1-10a2-47f4-211d-08d7b549b9c8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:55.4118 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: P95NuD7AKTHGHDTeeXaO/ubBltq6pGJKhxi3CmJxQ2SzYlskGP11f8Zn8LiA7GdWujghec+4y9+Ay/FlDm/5GVrLiSeTFRKzgUf8ItwQDkA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4213 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=885 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Turning vdd regulator on requires a consequent sleep for the chip to power on correctly. Turning vddio regulator is much faster. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 3502b996671c..63cdde20df7e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -1201,7 +1201,7 @@ static int inv_mpu_core_enable_regulator_vddio(struct inv_mpu6050_state *st) "Failed to enable vddio regulator: %d\n", result); } else { /* Give the device a little bit of time to start up. */ - usleep_range(35000, 70000); + usleep_range(3000, 5000); } return result; @@ -1321,6 +1321,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, dev_err(dev, "Failed to enable vdd regulator: %d\n", result); return result; } + msleep(INV_MPU6050_POWER_UP_TIME); result = inv_mpu_core_enable_regulator_vddio(st); if (result) { From patchwork Wed Feb 19 14:39:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391645 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8AB72930 for ; Wed, 19 Feb 2020 14:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 494B224654 for ; Wed, 19 Feb 2020 14:41:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="pc+EgLRP"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="Y4JZ52Sf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726680AbgBSOlG (ORCPT ); Wed, 19 Feb 2020 09:41:06 -0500 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:47144 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgBSOlF (ORCPT ); Wed, 19 Feb 2020 09:41:05 -0500 Received: from pps.filterd (m0156136.ppops.net [127.0.0.1]) by mx0b-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEaRO7006599; Wed, 19 Feb 2020 06:41:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=lnXhuxj5D+S1un4NkVfCOqiyKVbQc4WVgU3FVFoSIoU=; b=pc+EgLRPvJj17mcw/8LrNfSKVbuJicPu6+nUAw7tIhMWC5KpwcXt6DAfhiNrUti5xz5X RBoYmhx/cYZJd9uwXgX4aENMwj5Zfwl2qjLI11KZKcJTwzaUWODCDvAMqwRVaIh2ysCV 7bzVTzaXWnkk/Xst3Vfp8uNAX+rI4iwQD7coac76GRFmEyWlGTqEPIz/v4sjWupXI7l+ M9tEIYxcgHrPkiJoym7h7k5cF/VDfIW3h5Mp2BAEklqefj8lGMkBXcX7jehgvuRnWHjT quEd3BTFdaFq8n7d0stlQRNT/AwiHRGCTWPjdPh66chyMALsN1M5r66+6p4NUxj6TxrD xA== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by mx0b-00328301.pphosted.com with ESMTP id 2y8uc908hj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:41:01 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E+SRQyFqeSBoBVsgTB01MHbrqDX1Vx5tJuCUeOFwzNU1E+9WZUW2FtHIrLp9s4zb/Yv6wymCxvMP8ocY5yqrXpuVDyNie8xweS+AZ0Gx3KDv7HWbLNbFy+AAqClIHHiFM6uTUl+TN1KXsUsKU3Gmjp7jVHHyhSvyBw6zhhh3uYzqwFCixWcnZN0SooNbtRC6stS6aK9OpiOoIprNx3UoVa2hpstUizxXYUgODyTMg+p6s/kOUdtCjyJhqMRrtQkBUpd0tzH6rIb5St7L+JaT/D09xg5X8jntqjtUre6JG8lStWY709HJDHc1O3uOqe5p4Cg6l2s+Nshot0fu+ArPSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lnXhuxj5D+S1un4NkVfCOqiyKVbQc4WVgU3FVFoSIoU=; b=gI/j6+iMH48d2W1lsJjwJaYJZA2zL54gTUaDQuCtqvSnxmq/CHiZQY8m61bslUhhRRCyTBU47iHdPsEOey97tzLBbBXe0OxrIlPkkJUWGsseZVViJBKC2qUL4o/t9NANoExtLIZaEmLkP6KWVswl8J4o3e4MiCQ0xyQ1mMZ0sUDxJUCWdtjCuJKfzUGYRJWU0eU4x3xcQxQnnfNAhZZTsw0DrRxfan0f94Dg62TvK1ftft2b/Pi/8fSpOIk9UHGlmfYuXprueDXgsRINYsqlncw+eIIC9IqASBXCOugo7ZI8FFQmi6gUheqY9vjip1+Xa+YWsEk0GrgxVRiiYchCbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lnXhuxj5D+S1un4NkVfCOqiyKVbQc4WVgU3FVFoSIoU=; b=Y4JZ52SfC8BZ6IVvjU6XOae2R52BoF7UIdXUMX6UtvuHGils+UeaSS0OUO6m3vWshZoqvMSyxbRNk0gAuqpcTN9xK3ZcVVBT9xpgy2QrNLzlHo7gfIb/L7RIGvN63qymaVDrWpbK+HEQhSP10qAnla6JkfK0K1QW/JKNSUEl5Cc= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB3878.namprd12.prod.outlook.com (52.132.245.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17; Wed, 19 Feb 2020 14:40:58 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:40:58 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 08/13] iio: imu: inv_mpu6050: rewrite power and engine management Date: Wed, 19 Feb 2020 15:39:53 +0100 Message-Id: <20200219143958.3548-9-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:40:57 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a13495d4-1b92-4042-d5d3-08d7b549bba6 X-MS-TrafficTypeDiagnostic: CH2PR12MB3878: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:50; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(396003)(376002)(39850400004)(136003)(366004)(189003)(199004)(2906002)(5660300002)(7696005)(36756003)(16526019)(6666004)(81166006)(26005)(956004)(2616005)(52116002)(186003)(1076003)(81156014)(8936002)(30864003)(86362001)(8676002)(4326008)(66946007)(66556008)(66476007)(316002)(107886003)(478600001)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB3878;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KC0br0rvwWYFIiiE4fYia+2KecCk0qR+X4Ltwnjgcg4JJpZAQgeMyMcDrmgYZQl0es8J2wWbMtbYWUErwgQnmJsg6ULwO5lu6zG6JMsnsLqFRrxIsaRcQAeezWIKa4VDDLXtkzHWgkV86/hTFsARexKxwwAwn1Lj44gGHpKfP2zEUBafIkchkaQpg3UZWybw0fLDyf0K+KoWJIlPejtjBlK3OSDBg64/fFmMVq9LG9RLwTz+6mDQOtx/u6oZoSQqSLTYzr7FtZsBFldybdXBiGXzzq9IEqqJ10e0sLgd2pmUrxe8t7VbmqKKupLIFjOvAtQha4U4bJqp5R+CCX5Qv8YEbJj5O4zUfkqmlw7P96EJ3qsI2vSLImiFIa2miukReGCxaSHg1xpu45+WBXHXibAUV4206brg171OQrJnt5LKdKEjNvtLjT0+x47HOOJe X-MS-Exchange-AntiSpam-MessageData: PM890Uh7C/T/5Buy/pSTKP2Ka2mtCvna+u3Uo0jgBzH24tVHE++ohQ8GM5p4q9D3nxo5tcjIVpvdgPnkS/RiQnjQfTCtDBEKdRR8YH3WxcuUHhdqmwI0uxHAzxNLAijMtGHO+i9VTE0PSvtm9waqKA== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: a13495d4-1b92-4042-d5d3-08d7b549bba6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:40:58.7044 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: whRFILeKKrDrO0tZuMmIGbccV11GWZPLjgn8ZvEl/wzbxslkYz7kXRarVKpus9jxJoJCRDamYo0EPQJETB4ibcDG0Bv6WZ4qmwhw5iXbcDg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3878 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Rewrite clock management to use automatic clock switching present since MPU6500. Sensors engine management can now turn on or off a batch of sensors which simplifies usage a lot. Temperature sensor is now turned on/off depending on usage. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 264 +++++++++++++----- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 24 +- drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c | 12 +- drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 91 +++--- 5 files changed, 262 insertions(+), 131 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 63cdde20df7e..a51efc4c941b 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -99,9 +99,31 @@ static const struct inv_mpu6050_reg_map reg_set_6050 = { }; static const struct inv_mpu6050_chip_config chip_config_6050 = { + .clk = INV_CLK_INTERNAL, .fsr = INV_MPU6050_FSR_2000DPS, .lpf = INV_MPU6050_FILTER_20HZ, .divider = INV_MPU6050_FIFO_RATE_TO_DIVIDER(50), + .gyro_en = true, + .accl_en = true, + .temp_en = true, + .magn_en = false, + .gyro_fifo_enable = false, + .accl_fifo_enable = false, + .temp_fifo_enable = false, + .magn_fifo_enable = false, + .accl_fs = INV_MPU6050_FS_02G, + .user_ctrl = 0, +}; + +static const struct inv_mpu6050_chip_config chip_config_6500 = { + .clk = INV_CLK_PLL, + .fsr = INV_MPU6050_FSR_2000DPS, + .lpf = INV_MPU6050_FILTER_20HZ, + .divider = INV_MPU6050_FIFO_RATE_TO_DIVIDER(50), + .gyro_en = true, + .accl_en = true, + .temp_en = true, + .magn_en = false, .gyro_fifo_enable = false, .accl_fifo_enable = false, .temp_fifo_enable = false, @@ -124,7 +146,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_MPU6500_WHOAMI_VALUE, .name = "MPU6500", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, }, @@ -132,7 +154,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_MPU6515_WHOAMI_VALUE, .name = "MPU6515", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, }, @@ -156,7 +178,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_MPU9250_WHOAMI_VALUE, .name = "MPU9250", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, }, @@ -164,7 +186,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_MPU9255_WHOAMI_VALUE, .name = "MPU9255", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE}, }, @@ -172,7 +194,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_ICM20608_WHOAMI_VALUE, .name = "ICM20608", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, }, @@ -180,7 +202,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_ICM20609_WHOAMI_VALUE, .name = "ICM20609", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 4 * 1024, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, }, @@ -188,7 +210,7 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_ICM20689_WHOAMI_VALUE, .name = "ICM20689", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 4 * 1024, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, }, @@ -196,15 +218,15 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_ICM20602_WHOAMI_VALUE, .name = "ICM20602", .reg = ®_set_icm20602, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 1008, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, }, { .whoami = INV_ICM20690_WHOAMI_VALUE, .name = "ICM20690", - .reg = ®_set_icm20602, - .config = &chip_config_6050, + .reg = ®_set_6500, + .config = &chip_config_6500, .fifo_size = 1024, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, }, @@ -212,61 +234,162 @@ static const struct inv_mpu6050_hw hw_info[] = { .whoami = INV_IAM20680_WHOAMI_VALUE, .name = "IAM20680", .reg = ®_set_6500, - .config = &chip_config_6050, + .config = &chip_config_6500, .fifo_size = 512, .temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE}, }, }; -int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask) +static int inv_mpu6050_pwr_mgmt_1_write(struct inv_mpu6050_state *st, bool sleep, + int clock, int temp_dis) { - unsigned int d, mgmt_1; - int result; - /* - * switch clock needs to be careful. Only when gyro is on, can - * clock source be switched to gyro. Otherwise, it must be set to - * internal clock - */ - if (mask == INV_MPU6050_BIT_PWR_GYRO_STBY) { - result = regmap_read(st->map, st->reg->pwr_mgmt_1, &mgmt_1); - if (result) - return result; + u8 val; + + if (clock < 0) + clock = st->chip_config.clk; + if (temp_dis < 0) + temp_dis = !st->chip_config.temp_en; + + val = clock & INV_MPU6050_BIT_CLK_MASK; + if (temp_dis) + val |= INV_MPU6050_BIT_TEMP_DIS; + if (sleep) + val |= INV_MPU6050_BIT_SLEEP; + + dev_dbg(regmap_get_device(st->map), "pwr_mgmt_1: 0x%x\n", val); + return regmap_write(st->map, st->reg->pwr_mgmt_1, val); +} + +static int inv_mpu6050_clock_switch(struct inv_mpu6050_state *st, + unsigned int clock) +{ + int ret; + + switch (st->chip_type) { + case INV_MPU6050: + case INV_MPU6000: + case INV_MPU9150: + /* old chips: switch clock manually */ + ret = inv_mpu6050_pwr_mgmt_1_write(st, false, clock, -1); + if (ret) + return ret; + st->chip_config.clk = clock; + break; + default: + /* automatic clock switching, nothing to do */ + break; + } + + return 0; +} - mgmt_1 &= ~INV_MPU6050_BIT_CLK_MASK; +int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, + unsigned int mask) +{ + unsigned int sleep; + u8 pwr_mgmt2, user_ctrl; + int ret; + + /* delete useless requests */ + if (mask & INV_MPU6050_SENSOR_ACCL && en == st->chip_config.accl_en) + mask &= ~INV_MPU6050_SENSOR_ACCL; + if (mask & INV_MPU6050_SENSOR_GYRO && en == st->chip_config.gyro_en) + mask &= ~INV_MPU6050_SENSOR_GYRO; + if (mask & INV_MPU6050_SENSOR_TEMP && en == st->chip_config.temp_en) + mask &= ~INV_MPU6050_SENSOR_TEMP; + if (mask & INV_MPU6050_SENSOR_MAGN && en == st->chip_config.magn_en) + mask &= ~INV_MPU6050_SENSOR_MAGN; + if (mask == 0) + return 0; + + /* turn on/off temperature sensor */ + if (mask & INV_MPU6050_SENSOR_TEMP) { + ret = inv_mpu6050_pwr_mgmt_1_write(st, false, -1, !en); + if (ret) + return ret; + st->chip_config.temp_en = en; } - if ((mask == INV_MPU6050_BIT_PWR_GYRO_STBY) && (!en)) { - /* - * turning off gyro requires switch to internal clock first. - * Then turn off gyro engine - */ - mgmt_1 |= INV_CLK_INTERNAL; - result = regmap_write(st->map, st->reg->pwr_mgmt_1, mgmt_1); - if (result) - return result; + /* update user_crtl for driving magnetometer */ + if (mask & INV_MPU6050_SENSOR_MAGN) { + user_ctrl = st->chip_config.user_ctrl; + if (en) + user_ctrl |= INV_MPU6050_BIT_I2C_MST_EN; + else + user_ctrl &= ~INV_MPU6050_BIT_I2C_MST_EN; + ret = regmap_write(st->map, st->reg->user_ctrl, user_ctrl); + if (ret) + return ret; + st->chip_config.user_ctrl = user_ctrl; + st->chip_config.magn_en = en; } - result = regmap_read(st->map, st->reg->pwr_mgmt_2, &d); - if (result) - return result; - if (en) - d &= ~mask; - else - d |= mask; - result = regmap_write(st->map, st->reg->pwr_mgmt_2, d); - if (result) - return result; + /* manage accel & gyro engines */ + if (mask & (INV_MPU6050_SENSOR_ACCL | INV_MPU6050_SENSOR_GYRO)) { + /* compute power management 2 current value */ + pwr_mgmt2 = 0; + if (!st->chip_config.accl_en) + pwr_mgmt2 |= INV_MPU6050_BIT_PWR_ACCL_STBY; + if (!st->chip_config.gyro_en) + pwr_mgmt2 |= INV_MPU6050_BIT_PWR_GYRO_STBY; + + /* update to new requested value */ + if (mask & INV_MPU6050_SENSOR_ACCL) { + if (en) + pwr_mgmt2 &= ~INV_MPU6050_BIT_PWR_ACCL_STBY; + else + pwr_mgmt2 |= INV_MPU6050_BIT_PWR_ACCL_STBY; + } + if (mask & INV_MPU6050_SENSOR_GYRO) { + if (en) + pwr_mgmt2 &= ~INV_MPU6050_BIT_PWR_GYRO_STBY; + else + pwr_mgmt2 |= INV_MPU6050_BIT_PWR_GYRO_STBY; + } - if (en) { - /* Wait for output to stabilize */ - msleep(INV_MPU6050_TEMP_UP_TIME); - if (mask == INV_MPU6050_BIT_PWR_GYRO_STBY) { - /* switch internal clock to PLL */ - mgmt_1 |= INV_CLK_PLL; - result = regmap_write(st->map, - st->reg->pwr_mgmt_1, mgmt_1); - if (result) - return result; + /* switch clock to internal when turning gyro off */ + if (mask & INV_MPU6050_SENSOR_GYRO && !en) { + ret = inv_mpu6050_clock_switch(st, INV_CLK_INTERNAL); + if (ret) + return ret; + } + + /* update sensors engine */ + dev_dbg(regmap_get_device(st->map), "pwr_mgmt_2: 0x%x\n", + pwr_mgmt2); + ret = regmap_write(st->map, st->reg->pwr_mgmt_2, pwr_mgmt2); + if (ret) + return ret; + if (mask & INV_MPU6050_SENSOR_ACCL) + st->chip_config.accl_en = en; + if (mask & INV_MPU6050_SENSOR_GYRO) + st->chip_config.gyro_en = en; + + /* compute required time to have sensors stabilized */ + sleep = 0; + if (en) { + if (mask & INV_MPU6050_SENSOR_ACCL) { + if (sleep < INV_MPU6050_ACCEL_UP_TIME) + sleep = INV_MPU6050_ACCEL_UP_TIME; + } + if (mask & INV_MPU6050_SENSOR_GYRO) { + if (sleep < INV_MPU6050_GYRO_UP_TIME) + sleep = INV_MPU6050_GYRO_UP_TIME; + } + } else { + if (mask & INV_MPU6050_SENSOR_GYRO) { + if (sleep < INV_MPU6050_GYRO_DOWN_TIME) + sleep = INV_MPU6050_GYRO_DOWN_TIME; + } + } + if (sleep) + msleep(sleep); + + /* switch clock to PLL when turning gyro on */ + if (mask & INV_MPU6050_SENSOR_GYRO && en) { + ret = inv_mpu6050_clock_switch(st, INV_CLK_PLL); + if (ret) + return ret; } } @@ -279,7 +402,7 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on) if (power_on) { if (!st->powerup_count) { - result = regmap_write(st->map, st->reg->pwr_mgmt_1, 0); + result = inv_mpu6050_pwr_mgmt_1_write(st, false, -1, -1); if (result) return result; usleep_range(INV_MPU6050_REG_UP_TIME_MIN, @@ -288,8 +411,7 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on) st->powerup_count++; } else { if (st->powerup_count == 1) { - result = regmap_write(st->map, st->reg->pwr_mgmt_1, - INV_MPU6050_BIT_SLEEP); + result = inv_mpu6050_pwr_mgmt_1_write(st, true, -1, -1); if (result) return result; } @@ -451,33 +573,41 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, switch (chan->type) { case IIO_ANGL_VEL: result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_BIT_PWR_GYRO_STBY); + INV_MPU6050_SENSOR_GYRO); 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); + INV_MPU6050_SENSOR_GYRO); if (result) goto error_power_off; break; case IIO_ACCEL: result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_BIT_PWR_ACCL_STBY); + INV_MPU6050_SENSOR_ACCL); 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); + INV_MPU6050_SENSOR_ACCL); if (result) goto error_power_off; break; case IIO_TEMP: + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_SENSOR_TEMP); + if (result) + goto error_power_off; /* wait for stablization */ - msleep(INV_MPU6050_SENSOR_UP_TIME); + msleep(INV_MPU6050_TEMP_UP_TIME); ret = inv_mpu6050_sensor_show(st, st->reg->temperature, IIO_MOD_X, val); + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_SENSOR_TEMP); + if (result) + goto error_power_off; break; case IIO_MAGN: ret = inv_mpu_magn_read(st, chan->channel2, val); @@ -1108,7 +1238,7 @@ static const struct iio_info mpu_info = { static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) { int result; - unsigned int regval; + unsigned int regval, mask; int i; st->hw = &hw_info[st->chip_type]; @@ -1174,13 +1304,9 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st) result = inv_mpu6050_set_power_itg(st, true); if (result) return result; - - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_ACCL_STBY); - if (result) - goto error_power_off; - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_GYRO_STBY); + mask = INV_MPU6050_SENSOR_ACCL | INV_MPU6050_SENSOR_GYRO | + INV_MPU6050_SENSOR_TEMP | INV_MPU6050_SENSOR_MAGN; + result = inv_mpu6050_switch_engine(st, false, mask); if (result) goto error_power_off; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 17f1f6a15f95..a578789c9210 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -83,11 +83,22 @@ enum inv_devices { INV_NUM_PARTS }; +/* chip sensors mask: accelerometer, gyroscope, temperature, magnetometer */ +#define INV_MPU6050_SENSOR_ACCL BIT(0) +#define INV_MPU6050_SENSOR_GYRO BIT(1) +#define INV_MPU6050_SENSOR_TEMP BIT(2) +#define INV_MPU6050_SENSOR_MAGN BIT(3) + /** * struct inv_mpu6050_chip_config - Cached chip configuration data. + * @clk: selected chip clock * @fsr: Full scale range. * @lpf: Digital low pass filter frequency. * @accl_fs: accel full scale range. + * @accl_en: accel engine enabled + * @gyro_en: gyro engine enabled + * @temp_en: temperature sensor enabled + * @magn_en: magn engine (i2c master) enabled * @accl_fifo_enable: enable accel data output * @gyro_fifo_enable: enable gyro data output * @temp_fifo_enable: enable temp data output @@ -95,9 +106,14 @@ enum inv_devices { * @divider: chip sample rate divider (sample rate divider - 1) */ struct inv_mpu6050_chip_config { + unsigned int clk:3; unsigned int fsr:2; unsigned int lpf:3; unsigned int accl_fs:2; + unsigned int accl_en:1; + unsigned int gyro_en:1; + unsigned int temp_en:1; + unsigned int magn_en:1; unsigned int accl_fifo_enable:1; unsigned int gyro_fifo_enable:1; unsigned int temp_fifo_enable:1; @@ -262,6 +278,7 @@ struct inv_mpu6050_state { #define INV_MPU6050_REG_PWR_MGMT_1 0x6B #define INV_MPU6050_BIT_H_RESET 0x80 #define INV_MPU6050_BIT_SLEEP 0x40 +#define INV_MPU6050_BIT_TEMP_DIS 0x08 #define INV_MPU6050_BIT_CLK_MASK 0x7 #define INV_MPU6050_REG_PWR_MGMT_2 0x6C @@ -292,7 +309,9 @@ struct inv_mpu6050_state { /* delay time in milliseconds */ #define INV_MPU6050_POWER_UP_TIME 100 #define INV_MPU6050_TEMP_UP_TIME 100 -#define INV_MPU6050_SENSOR_UP_TIME 30 +#define INV_MPU6050_ACCEL_UP_TIME 20 +#define INV_MPU6050_GYRO_UP_TIME 35 +#define INV_MPU6050_GYRO_DOWN_TIME 150 /* delay time in microseconds */ #define INV_MPU6050_REG_UP_TIME_MIN 5000 @@ -417,7 +436,8 @@ enum inv_mpu6050_clock_sel_e { irqreturn_t inv_mpu6050_read_fifo(int irq, void *p); int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type); int inv_reset_fifo(struct iio_dev *indio_dev); -int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask); +int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, + unsigned int mask); int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val); int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on); int inv_mpu_acpi_create_mux_client(struct i2c_client *client); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c index 607104a2631e..3f402fa56d95 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c @@ -316,9 +316,9 @@ int inv_mpu_magn_set_orient(struct inv_mpu6050_state *st) * * Returns 0 on success, a negative error code otherwise */ -int inv_mpu_magn_read(const struct inv_mpu6050_state *st, int axis, int *val) +int inv_mpu_magn_read(struct inv_mpu6050_state *st, int axis, int *val) { - unsigned int user_ctrl, status; + unsigned int status; __be16 data; uint8_t addr; unsigned int freq_hz, period_ms; @@ -350,16 +350,14 @@ int inv_mpu_magn_read(const struct inv_mpu6050_state *st, int axis, int *val) freq_hz = INV_MPU_MAGN_FREQ_HZ_MAX; period_ms = 1000 / freq_hz; - /* start i2c master, wait for xfer, stop */ - user_ctrl = st->chip_config.user_ctrl | INV_MPU6050_BIT_I2C_MST_EN; - ret = regmap_write(st->map, st->reg->user_ctrl, user_ctrl); + ret = inv_mpu6050_switch_engine(st, true, INV_MPU6050_SENSOR_MAGN); if (ret) return ret; /* need to wait 2 periods + half-period margin */ msleep(period_ms * 2 + period_ms / 2); - user_ctrl = st->chip_config.user_ctrl; - ret = regmap_write(st->map, st->reg->user_ctrl, user_ctrl); + + ret = inv_mpu6050_switch_engine(st, false, INV_MPU6050_SENSOR_MAGN); if (ret) return ret; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h index b41bd0578478..f7ad50ca6c1b 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h @@ -31,6 +31,6 @@ int inv_mpu_magn_set_rate(const struct inv_mpu6050_state *st, int fifo_rate); int inv_mpu_magn_set_orient(struct inv_mpu6050_state *st); -int inv_mpu_magn_read(const struct inv_mpu6050_state *st, int axis, int *val); +int inv_mpu_magn_read(struct inv_mpu6050_state *st, int axis, int *val); #endif /* INV_MPU_MAGN_H_ */ diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index 5199fe790c30..cfd7243159f6 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -5,9 +5,10 @@ #include "inv_mpu_iio.h" -static void inv_scan_query_mpu6050(struct iio_dev *indio_dev) +static unsigned int inv_scan_query_mpu6050(struct iio_dev *indio_dev) { struct inv_mpu6050_state *st = iio_priv(indio_dev); + unsigned int mask; st->chip_config.gyro_fifo_enable = test_bit(INV_MPU6050_SCAN_GYRO_X, @@ -27,17 +28,28 @@ static void inv_scan_query_mpu6050(struct iio_dev *indio_dev) st->chip_config.temp_fifo_enable = test_bit(INV_MPU6050_SCAN_TEMP, indio_dev->active_scan_mask); + + mask = 0; + if (st->chip_config.gyro_fifo_enable) + mask |= INV_MPU6050_SENSOR_GYRO; + if (st->chip_config.accl_fifo_enable) + mask |= INV_MPU6050_SENSOR_ACCL; + if (st->chip_config.temp_fifo_enable) + mask |= INV_MPU6050_SENSOR_TEMP; + + return mask; } -static void inv_scan_query_mpu9x50(struct iio_dev *indio_dev) +static unsigned int inv_scan_query_mpu9x50(struct iio_dev *indio_dev) { struct inv_mpu6050_state *st = iio_priv(indio_dev); + unsigned int mask; - inv_scan_query_mpu6050(indio_dev); + mask = inv_scan_query_mpu6050(indio_dev); /* no magnetometer if i2c auxiliary bus is used */ if (st->magn_disabled) - return; + return mask; st->chip_config.magn_fifo_enable = test_bit(INV_MPU9X50_SCAN_MAGN_X, @@ -46,9 +58,13 @@ static void inv_scan_query_mpu9x50(struct iio_dev *indio_dev) indio_dev->active_scan_mask) || test_bit(INV_MPU9X50_SCAN_MAGN_Z, indio_dev->active_scan_mask); + if (st->chip_config.magn_fifo_enable) + mask |= INV_MPU6050_SENSOR_MAGN; + + return mask; } -static void inv_scan_query(struct iio_dev *indio_dev) +static unsigned int inv_scan_query(struct iio_dev *indio_dev) { struct inv_mpu6050_state *st = iio_priv(indio_dev); @@ -92,62 +108,40 @@ static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st) static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) { struct inv_mpu6050_state *st = iio_priv(indio_dev); - uint8_t d; + unsigned int scan; int result; + scan = inv_scan_query(indio_dev); + if (enable) { result = inv_mpu6050_set_power_itg(st, true); if (result) return result; - inv_scan_query(indio_dev); - if (st->chip_config.gyro_fifo_enable) { - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_BIT_PWR_GYRO_STBY); - if (result) - goto error_power_off; - } - if (st->chip_config.accl_fifo_enable) { - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_BIT_PWR_ACCL_STBY); - if (result) - goto error_gyro_off; - } - if (st->chip_config.magn_fifo_enable) { - d = st->chip_config.user_ctrl | - INV_MPU6050_BIT_I2C_MST_EN; - result = regmap_write(st->map, st->reg->user_ctrl, d); - if (result) - goto error_accl_off; - st->chip_config.user_ctrl = d; - } + result = inv_mpu6050_switch_engine(st, true, scan); + if (result) + goto error_power_off; st->skip_samples = inv_compute_skip_samples(st); result = inv_reset_fifo(indio_dev); if (result) - goto error_magn_off; + goto error_sensors_off; } else { result = regmap_write(st->map, st->reg->fifo_en, 0); if (result) - goto error_magn_off; + goto error_fifo_off; result = regmap_write(st->map, st->reg->int_enable, 0); if (result) - goto error_magn_off; - - d = st->chip_config.user_ctrl & ~INV_MPU6050_BIT_I2C_MST_EN; - result = regmap_write(st->map, st->reg->user_ctrl, d); - if (result) - goto error_magn_off; - st->chip_config.user_ctrl = d; + goto error_fifo_off; - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_ACCL_STBY); + /* restore user_ctrl for disabling FIFO reading */ + result = regmap_write(st->map, st->reg->user_ctrl, + st->chip_config.user_ctrl); if (result) - goto error_accl_off; + goto error_sensors_off; - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_GYRO_STBY); + result = inv_mpu6050_switch_engine(st, false, scan); if (result) - goto error_gyro_off; + goto error_power_off; result = inv_mpu6050_set_power_itg(st, false); if (result) @@ -156,18 +150,11 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) return 0; -error_magn_off: +error_fifo_off: /* always restore user_ctrl to disable fifo properly */ - st->chip_config.user_ctrl &= ~INV_MPU6050_BIT_I2C_MST_EN; regmap_write(st->map, st->reg->user_ctrl, st->chip_config.user_ctrl); -error_accl_off: - if (st->chip_config.accl_fifo_enable) - inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_ACCL_STBY); -error_gyro_off: - if (st->chip_config.gyro_fifo_enable) - inv_mpu6050_switch_engine(st, false, - INV_MPU6050_BIT_PWR_GYRO_STBY); +error_sensors_off: + inv_mpu6050_switch_engine(st, false, scan); error_power_off: inv_mpu6050_set_power_itg(st, false); return result; From patchwork Wed Feb 19 14:39:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391647 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB6D5930 for ; Wed, 19 Feb 2020 14:41:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3D2124670 for ; Wed, 19 Feb 2020 14:41:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="EKgwcYCW"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="h1sEtP0q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbgBSOlH (ORCPT ); Wed, 19 Feb 2020 09:41:07 -0500 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:51780 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbgBSOlH (ORCPT ); Wed, 19 Feb 2020 09:41:07 -0500 Received: from pps.filterd (m0156136.ppops.net [127.0.0.1]) by mx0b-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEaS9q006602; Wed, 19 Feb 2020 06:41:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=yWo4zX/wrZ92Uov4BTPS0Fy4HARYP0oDxSIizGEtNcU=; b=EKgwcYCWNeMgCw9qCwid77RwHh0Ta9J/5tDSlh3PhOGt60/Gmu9Ym7RuRa99TraYsGLv GdkXJ/antbSgzieypRrGoxR6IVZfSiz4bI2e9j/oKUo8ULciTJ6XHNBhG3XugyGSKPDG T+uX4/Ty5Qb4RLZ2lJfD0m88lE24BcqTye7u6THVOgmspNPNC0Ym7fUiGaZSzYLJOscL l/Or3cZaUKJ46QQYZJ0OrtI0G1e7b0eX1UHEA5/lNFunpCggkPlaWEwgLR11g4QSsfX0 2oGPSvqrhHr/hOKTm6JeTlL65CcodqZlYTjrKU4wr72YxYUXNBT1ISTcP7LxoDg88jnQ dA== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2174.outbound.protection.outlook.com [104.47.55.174]) by mx0b-00328301.pphosted.com with ESMTP id 2y8uc908hn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:41:05 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hvMvYvxdoaGi5OayZVQQorn0XnPcSGYHd2f9a/pFxvkDdOBFy5NQZ+EvpR7SbkT0yhTstTmKCUeBvJcnasw/thjKnqWnojP847O6wY/yed8QQ2yjOELzqngr9nMq15wYkp468ocsS4HPXFDe6jfdBYtq5f0BeUiVN5Hy5lLeqodLOc0Nz4qj3BqlNxFjTo0KOxV8eUcjWS6miW/ADA2Y5aGrLEeiL3qJU7h4fI7XI6bOSj1KdfBZqjdWEigaiCzsr4B48fCL7rfMLNlluAemy6W127Ln0nxV6nXAp2xrvAWu7va3Who3K3R/1ea9Vr01gaAs7mZkrupa7P2b41Juhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yWo4zX/wrZ92Uov4BTPS0Fy4HARYP0oDxSIizGEtNcU=; b=cYDVNzFfNPvoQkZslSujaK01uy5UbfJiDVA38VJv2nUkjIxiAuHXvkOm2wwDXS4QGvNNkIi4nEilMVkY+hEwQs/hyKnAx6fRIlL/insgNGwlP88tYsZ8s1Zy7qi5jzpXlSjYUNekOFBolgQ3aCdw0MLvvEvHKk7Mf1FW95nXp+mzIR3gCXHPGhgOtm8VSs+iTrQPGDTFIhgItj8rz2f6K2PRpuxgm1SEM+G6uwxyUVg3osVScdFUfzNVl5FeHRab2fJYpoOS1kD21Ur5samFiKv+kRd/13N30H7drNaoCFFkoitWo+uSXcawzszBX2UjgBU3LADkwMQzP4UaCYTr5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yWo4zX/wrZ92Uov4BTPS0Fy4HARYP0oDxSIizGEtNcU=; b=h1sEtP0qLxn33DqTplgOa5UfABnlN8H6Zs4IU0kMnu7Z2KTIVXB3y4Tb8Jt7yzU+eSn2MQMb3bfbSK1Ts5bekz9A6d2Vxl1ecI5PYhmohZWLCMK7t2EFrXegQSU/kIJ6vjrcQw+DpcR2TZdpc7sr3UzEfKs5xkeeRePZafoBWVM= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4134.namprd12.prod.outlook.com (20.180.6.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.23; Wed, 19 Feb 2020 14:41:02 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:41:02 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 09/13] iio: imu: inv_mpu6050: fix data polling interface Date: Wed, 19 Feb 2020 15:39:54 +0100 Message-Id: <20200219143958.3548-10-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:41:00 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 50e0fb04-cef6-44e5-7e76-08d7b549bdf0 X-MS-TrafficTypeDiagnostic: CH2PR12MB4134: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(396003)(376002)(346002)(39850400004)(366004)(136003)(199004)(189003)(107886003)(2906002)(66946007)(4326008)(26005)(66476007)(66556008)(316002)(81166006)(8936002)(81156014)(6486002)(36756003)(1076003)(8676002)(86362001)(7696005)(5660300002)(478600001)(52116002)(6666004)(956004)(2616005)(16526019)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4134;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: poiVguOw2HHA+Ye+TQrXkaEy3931DaOsKBblRl8sfFpefvlzRx5NfozhlaD7UYFnxcshXA3JpMgD1gYzoCrmDm7IBeGTFJ4slb2T108HjVm+QXeWQpqyC5HlHouaWIRps5i+DvDbjsXo5hlOuwKGIHxD25CbZy8fHqEBNUVXYXV45oWw+dW1zFqTUuqCzR4131Mj2ZGH1Ng8dZDDo6sbsVeqftFWisuLL4OmpDwMU+He5h5DHyjIIulHswfiKMp1ldbmZ92VYgnGmiQ7A92cE1o5Tv0bObmSEaI8ekolffOh7rKmlG2TIkponJj1t5c88NAWL8cXLTSMv/5a128Yrxu9gfiL981U6m6Mebiut/a3z2wtN6o072XFxeebtD+L5dYzOzQAskuNrVQkfCP6SMhcLm8lyyiR99ic30ciz4hNKABtleZpHLOYiL04CEaT X-MS-Exchange-AntiSpam-MessageData: Ep/uPgR109RhbW+VEsJhRpwYSmkhtin249Xr4JWNWsYz8WImR/vv2w+btQSbhfZPE6S13IG5WFslHZLaLAvxlh6Yf9yQ5+jSeiokxKOglo01x63UWZyaqRa8odik77RlgO08zJyMfJ7pgH7Uj953eQ== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50e0fb04-cef6-44e5-7e76-08d7b549bdf0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:41:02.3614 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: a5hYZFlHxg4h55lciCbYDfXCN9V9SWDoAHWN9L9GVy8Uk4S5ft1zC3pxysONKOARCEjHsD0JyUylI2BrWZQNI01MpZxZSuNPSMmBKsDJ/S8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4134 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org When reading data with the polling interface, we need to wait at 1 sampling period to have a sample. For gyroscope and magnetometer, we need to wait for 2 periods before having a correct sample. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 36 ++++++++++++++++++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c | 21 ------------- drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h | 3 ++ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index a51efc4c941b..aeee39696d3a 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -563,9 +563,14 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, int *val) { struct inv_mpu6050_state *st = iio_priv(indio_dev); + unsigned int freq_hz, period_us, min_sleep_us, max_sleep_us; int result; int ret; + /* compute sample period */ + freq_hz = INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); + period_us = 1000000 / freq_hz; + result = inv_mpu6050_set_power_itg(st, true); if (result) return result; @@ -576,6 +581,10 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, INV_MPU6050_SENSOR_GYRO); if (result) goto error_power_off; + /* need to wait 2 periods to have first valid sample */ + min_sleep_us = 2 * period_us; + max_sleep_us = 2 * (period_us + period_us / 2); + usleep_range(min_sleep_us, max_sleep_us); ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, chan->channel2, val); result = inv_mpu6050_switch_engine(st, false, @@ -588,6 +597,10 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, INV_MPU6050_SENSOR_ACCL); if (result) goto error_power_off; + /* wait 1 period for first sample availability */ + min_sleep_us = period_us; + max_sleep_us = period_us + period_us / 2; + usleep_range(min_sleep_us, max_sleep_us); ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl, chan->channel2, val); result = inv_mpu6050_switch_engine(st, false, @@ -600,8 +613,10 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, INV_MPU6050_SENSOR_TEMP); if (result) goto error_power_off; - /* wait for stablization */ - msleep(INV_MPU6050_TEMP_UP_TIME); + /* wait 1 period for first sample availability */ + min_sleep_us = period_us; + max_sleep_us = period_us + period_us / 2; + usleep_range(min_sleep_us, max_sleep_us); ret = inv_mpu6050_sensor_show(st, st->reg->temperature, IIO_MOD_X, val); result = inv_mpu6050_switch_engine(st, false, @@ -610,7 +625,24 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, goto error_power_off; break; case IIO_MAGN: + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_SENSOR_MAGN); + if (result) + goto error_power_off; + /* frequency is limited for magnetometer */ + if (freq_hz > INV_MPU_MAGN_FREQ_HZ_MAX) { + freq_hz = INV_MPU_MAGN_FREQ_HZ_MAX; + period_us = 1000000 / freq_hz; + } + /* need to wait 2 periods to have first valid sample */ + min_sleep_us = 2 * period_us; + max_sleep_us = 2 * (period_us + period_us / 2); + usleep_range(min_sleep_us, max_sleep_us); ret = inv_mpu_magn_read(st, chan->channel2, val); + result = inv_mpu6050_switch_engine(st, false, + INV_MPU6050_SENSOR_MAGN); + if (result) + goto error_power_off; break; default: ret = -EINVAL; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c index 3f402fa56d95..f282e9cc34c5 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c @@ -44,9 +44,6 @@ #define INV_MPU_MAGN_REG_ASAY 0x11 #define INV_MPU_MAGN_REG_ASAZ 0x12 -/* Magnetometer maximum frequency */ -#define INV_MPU_MAGN_FREQ_HZ_MAX 50 - static bool inv_magn_supported(const struct inv_mpu6050_state *st) { switch (st->chip_type) { @@ -321,7 +318,6 @@ int inv_mpu_magn_read(struct inv_mpu6050_state *st, int axis, int *val) unsigned int status; __be16 data; uint8_t addr; - unsigned int freq_hz, period_ms; int ret; /* quit if chip is not supported */ @@ -344,23 +340,6 @@ int inv_mpu_magn_read(struct inv_mpu6050_state *st, int axis, int *val) } addr += INV_MPU6050_REG_EXT_SENS_DATA; - /* compute period depending on current sampling rate */ - freq_hz = INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); - if (freq_hz > INV_MPU_MAGN_FREQ_HZ_MAX) - freq_hz = INV_MPU_MAGN_FREQ_HZ_MAX; - period_ms = 1000 / freq_hz; - - ret = inv_mpu6050_switch_engine(st, true, INV_MPU6050_SENSOR_MAGN); - if (ret) - return ret; - - /* need to wait 2 periods + half-period margin */ - msleep(period_ms * 2 + period_ms / 2); - - ret = inv_mpu6050_switch_engine(st, false, INV_MPU6050_SENSOR_MAGN); - if (ret) - return ret; - /* check i2c status and read raw data */ ret = regmap_read(st->map, INV_MPU6050_REG_I2C_MST_STATUS, &status); if (ret) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h index f7ad50ca6c1b..185c000c697c 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h @@ -10,6 +10,9 @@ #include "inv_mpu_iio.h" +/* Magnetometer maximum frequency */ +#define INV_MPU_MAGN_FREQ_HZ_MAX 50 + int inv_mpu_magn_probe(struct inv_mpu6050_state *st); /** From patchwork Wed Feb 19 14:39:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 581A3930 for ; Wed, 19 Feb 2020 14:41:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30E0324672 for ; Wed, 19 Feb 2020 14:41:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="ijQzh9nc"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="kwSEMGJC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726609AbgBSOlL (ORCPT ); Wed, 19 Feb 2020 09:41:11 -0500 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:56426 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbgBSOlL (ORCPT ); Wed, 19 Feb 2020 09:41:11 -0500 Received: from pps.filterd (m0156136.ppops.net [127.0.0.1]) by mx0b-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEc7kq009174; Wed, 19 Feb 2020 06:41:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=R+WbWyYcaS/YkPN7jz7RMcx5sWf3sbBJwhfCEYBZKMk=; b=ijQzh9ncls7s/zvahpUlO9D8JdbsOrFlogtGHMwygurnBNOpMV/zWQ/BjFPLITHaPJPm WR2a/mP8dyHFeGgZA3l8Bkklz/Ts8isRZ9iscYmOWlMcrLMLimN+5wH0mJKsS7uhaqH8 iH5Y+973WYVrbp56UZ8FvtuMqazbNWgnt3VLWgJLxbOtlu3u1asz1hC1WN1vuqbhtX8j j+Gx5tQ/XuNPD/6gYOJVXAhIB2vSbtEyAlDJMgwdKAymyFs5Ddv7YLfn8wTi8ywmrVOl WrPTEEv93/haJMXEiQ6MuiA+bKMkMEjRH+D6UpcU7g8J/tSM/T6RLqKsCkjnv/1vOJx2 7Q== Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by mx0b-00328301.pphosted.com with ESMTP id 2y8uc908hs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:41:09 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jSExrUnUVClpsTlYGxPVxlfcAGmv+xJNHd+uCNsev9YRgZQMOxufnGJ/qKYMdgyfgxBKponPQB/mXiPBcDUf/wPPdL/w43z2EWyI4eKjNcK3rfv1vnPwV9Yg59qd7L6JtIAghhUETeyUE9IfUq5MwQ70gIIXzpvoYKgi1WNQD6+hpuxRUxkP7QmPuBLqFTGzWuy6GR9ngt9TO8ihqRhmjupfzclmcOjX4UPoj6gM+oSEDiRRWidxyGcR4ET0uVIrSq64gIIUoOBkcoFFJJUI7efzl2c0UjvwTpJUiJSQWVysVpKfzsZN1bncUM0beCMzDiw+IpauzjItZibDgHEL6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R+WbWyYcaS/YkPN7jz7RMcx5sWf3sbBJwhfCEYBZKMk=; b=dqzdDSGyF5Pzl8eS21GLGTWyNtUucs0+V+WxQ7Oisgc6PqWdvucx4i+jRZuqbHVj6QH8pRg+WInBa4AXdZKjJ+Y9i5087YrCk0ZHat9kera7sOPyFZmhQzHBwDuoB8mBMDMzHlwaL5lpO7I3tfnxDRLeE36ggrLHeOOaMAEIcVophAUc0QhGABiVjW3RisRg9aXCtoKA+ixFhWaS4+/OfGbjCzAzYrYLLrqURoK2O9BppTN5Qg4IlCIzmNloXDrlfEpbtsjPVPjG04CxmvVRis6XwdC/BRkJwzw9rsyb0fUjAOivxotu426dhcn4jC0R4c79dWUp8KAUPRPaZisrKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R+WbWyYcaS/YkPN7jz7RMcx5sWf3sbBJwhfCEYBZKMk=; b=kwSEMGJCF0G5Pv2ueqBfOUlLG161hBYWpz6ow9jGJD8ZgoEfr2wmksVDOwSsT9dqxUCey6xZKDc+hNQ4CyJwMixIoXiryxz/hdZjjICXNKhWLg/4T904Rd9r1tNi1FNLT7dOKRNsTRLcvmUFRz68nE1Ps1qlgmGW9Yqo7yMaUYU= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4213.namprd12.prod.outlook.com (20.180.5.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Wed, 19 Feb 2020 14:41:06 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:41:06 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 10/13] iio: imu: inv_mpu6050: factorize fifo enable/disable Date: Wed, 19 Feb 2020 15:39:55 +0100 Message-Id: <20200219143958.3548-11-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:41:05 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d641c44-2eb4-49d2-5733-08d7b549c080 X-MS-TrafficTypeDiagnostic: CH2PR12MB4213: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(376002)(396003)(346002)(39850400004)(136003)(189003)(199004)(2906002)(36756003)(16526019)(6666004)(26005)(86362001)(107886003)(2616005)(66556008)(66476007)(4326008)(5660300002)(66946007)(81166006)(186003)(478600001)(81156014)(7696005)(8936002)(1076003)(8676002)(6486002)(52116002)(316002)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4213;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vB4DeWrgNsfeiV0ERCtZIeuk63p/bnDwRNAeFRtcG6zjWKOM2Q+7C99Hl0KB/9X/0lb0/bTcoUyhWiSlX1PNpdtN/GXL74Xha9X1yYrQNMxpCG+ThrwLkMw4zb+yXKDU1OQdtjB5Dz6RC2f21nkWagbrS/71vVLC1DyN6IxZtIJkTN9vfqo9nCelkyrN8rCBfZu/SHOfY3icc5Zy+jtZc4+MdzIBjIPXKhMCtzxyLNjY5z0wzF5pGASaAkANU+TqCf20y/pbcuz8X9CR7FkrFwdSzOGrAMDyVz30BkY3zzQ39PyDJ6JO5EX3TaRPjKe5EeZ6u+Lps93MOGNQA+7uDp8A9iEEOMH3hwXM0m1KZzKHbCn9I/ogoIXDrj+9kOyMhRFe9UihcuJQMHmQfNkadKKZ4pp8EVJvgeUWeoTwK8h3nO41ehrD5uM48U2R1jF1 X-MS-Exchange-AntiSpam-MessageData: nVUuf8OSV+767vk6nw/aDCqN/zBPR45f6pHLZKHFXB+3Nm2NrD9BnyY9yJI2PAiztG5MdqdXTvW10FxzVwpN2kZ5l9jZNBH3pu2o1YSLGj4v2uCC3qbi1QQQcTgTwvUIiHKqYKrcccnRmCtLsQ8b6w== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d641c44-2eb4-49d2-5733-08d7b549c080 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:41:06.6635 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JHXr/v6yTwPiqdTz9nne9spgeDYTyLTfkgWz4J+w3oipjbaVbBfbxGp4bdwfzX8jjbinnwbwbmNb/SyOnmOBErUGqHjugLFB3IaCplGncNk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4213 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 mlxlogscore=936 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Rework fifo enable/disable in a separate function. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 54 ++------------- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 66 ++++++++++++++----- 3 files changed, 55 insertions(+), 67 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index a578789c9210..e328c98e362c 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -435,7 +435,7 @@ enum inv_mpu6050_clock_sel_e { irqreturn_t inv_mpu6050_read_fifo(int irq, void *p); int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type); -int inv_reset_fifo(struct iio_dev *indio_dev); +int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable); int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, unsigned int mask); int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index d7397705974e..9511e4715e2c 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -90,60 +90,14 @@ static s64 inv_mpu6050_get_timestamp(struct inv_mpu6050_state *st) return ts; } -int inv_reset_fifo(struct iio_dev *indio_dev) +static int inv_reset_fifo(struct iio_dev *indio_dev) { int result; - u8 d; struct inv_mpu6050_state *st = iio_priv(indio_dev); - /* reset it timestamp validation */ - st->it_timestamp = 0; - - /* disable interrupt */ - result = regmap_write(st->map, st->reg->int_enable, 0); - if (result) { - dev_err(regmap_get_device(st->map), "int_enable failed %d\n", - result); - return result; - } - /* disable the sensor output to FIFO */ - result = regmap_write(st->map, st->reg->fifo_en, 0); - if (result) - goto reset_fifo_fail; - /* disable fifo reading */ - result = regmap_write(st->map, st->reg->user_ctrl, - st->chip_config.user_ctrl); - if (result) - goto reset_fifo_fail; - - /* reset FIFO*/ - d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST; - result = regmap_write(st->map, st->reg->user_ctrl, d); - if (result) - goto reset_fifo_fail; - - /* enable interrupt */ - result = regmap_write(st->map, st->reg->int_enable, - INV_MPU6050_BIT_DATA_RDY_EN); - if (result) - return result; - - /* enable FIFO reading */ - d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_EN; - result = regmap_write(st->map, st->reg->user_ctrl, d); - if (result) - goto reset_fifo_fail; - /* enable sensor output to FIFO */ - d = 0; - if (st->chip_config.gyro_fifo_enable) - d |= INV_MPU6050_BITS_GYRO_OUT; - if (st->chip_config.accl_fifo_enable) - d |= INV_MPU6050_BIT_ACCEL_OUT; - if (st->chip_config.temp_fifo_enable) - d |= INV_MPU6050_BIT_TEMP_OUT; - if (st->chip_config.magn_fifo_enable) - d |= INV_MPU6050_BIT_SLAVE_0; - result = regmap_write(st->map, st->reg->fifo_en, d); + /* disable fifo and reenable it */ + inv_mpu6050_prepare_fifo(st, false); + result = inv_mpu6050_prepare_fifo(st, true); if (result) goto reset_fifo_fail; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index cfd7243159f6..f53f50d08b9e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -100,6 +100,54 @@ static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st) return skip_samples; } +int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable) +{ + uint8_t d; + int ret; + + if (enable) { + st->it_timestamp = 0; + /* reset FIFO */ + d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST; + ret = regmap_write(st->map, st->reg->user_ctrl, d); + if (ret) + return ret; + /* enable sensor output to FIFO */ + d = 0; + if (st->chip_config.gyro_fifo_enable) + d |= INV_MPU6050_BITS_GYRO_OUT; + if (st->chip_config.accl_fifo_enable) + d |= INV_MPU6050_BIT_ACCEL_OUT; + if (st->chip_config.temp_fifo_enable) + d |= INV_MPU6050_BIT_TEMP_OUT; + if (st->chip_config.magn_fifo_enable) + d |= INV_MPU6050_BIT_SLAVE_0; + ret = regmap_write(st->map, st->reg->fifo_en, d); + if (ret) + return ret; + /* enable FIFO reading */ + d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_EN; + ret = regmap_write(st->map, st->reg->user_ctrl, d); + if (ret) + return ret; + /* enable interrupt */ + ret = regmap_write(st->map, st->reg->int_enable, + INV_MPU6050_BIT_DATA_RDY_EN); + } else { + ret = regmap_write(st->map, st->reg->int_enable, 0); + if (ret) + return ret; + ret = regmap_write(st->map, st->reg->fifo_en, 0); + if (ret) + return ret; + /* restore user_ctrl for disabling FIFO reading */ + ret = regmap_write(st->map, st->reg->user_ctrl, + st->chip_config.user_ctrl); + } + + return ret; +} + /** * inv_mpu6050_set_enable() - enable chip functions. * @indio_dev: Device driver instance. @@ -121,24 +169,13 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) if (result) goto error_power_off; st->skip_samples = inv_compute_skip_samples(st); - result = inv_reset_fifo(indio_dev); + result = inv_mpu6050_prepare_fifo(st, true); if (result) goto error_sensors_off; } else { - result = regmap_write(st->map, st->reg->fifo_en, 0); - if (result) - goto error_fifo_off; - - result = regmap_write(st->map, st->reg->int_enable, 0); - if (result) - goto error_fifo_off; - - /* restore user_ctrl for disabling FIFO reading */ - result = regmap_write(st->map, st->reg->user_ctrl, - st->chip_config.user_ctrl); + result = inv_mpu6050_prepare_fifo(st, false); if (result) goto error_sensors_off; - result = inv_mpu6050_switch_engine(st, false, scan); if (result) goto error_power_off; @@ -150,9 +187,6 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) return 0; -error_fifo_off: - /* always restore user_ctrl to disable fifo properly */ - regmap_write(st->map, st->reg->user_ctrl, st->chip_config.user_ctrl); error_sensors_off: inv_mpu6050_switch_engine(st, false, scan); error_power_off: From patchwork Wed Feb 19 14:39:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391651 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63510138D for ; Wed, 19 Feb 2020 14:41:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B5D624654 for ; Wed, 19 Feb 2020 14:41:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="kQysE6sf"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="Au7n5QrE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726613AbgBSOlN (ORCPT ); Wed, 19 Feb 2020 09:41:13 -0500 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:60468 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbgBSOlN (ORCPT ); Wed, 19 Feb 2020 09:41:13 -0500 Received: from pps.filterd (m0156136.ppops.net [127.0.0.1]) by mx0b-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEaRO8006599; Wed, 19 Feb 2020 06:41:12 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=UoT0gkU3Vhd3X2T0qfT2Yuj0mPyPJsMzh1Tx6BIie/U=; b=kQysE6sfIKyNPieBjCxPn8Gp0AVK+atuYJmWnqoqd70X3fwSVS9FwsS0PmuBFWvsNvlm ADwetonygAk5hesuDnoHxZxu7SzMgQ8wn/Z2v3Cb4hcz2HI5n0pTxkb+5J7tOfjt6hH9 zeSucm94WIyz+xRbWnT5HYl8nn4VAaKwQP2ufaaYmfZ982kBJGVOZzTGUwhp0pAGjD9I 27oUbCk3uwLVyR6X3R8Xf7tEUg1Kcbq4fX1hWXP7sorzI4cS+NIZngfmz9yCTXm+7bew yNJBgJgVjkMKqEx+qyJIgoGJ/ybJ+tRRCCEl1Z4kzo+M+ZO6iopWStFvsYXZtObdweAC FQ== Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2106.outbound.protection.outlook.com [104.47.55.106]) by mx0b-00328301.pphosted.com with ESMTP id 2y8uc908ht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:41:12 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=chhez8tO9iT9jP3HTyMpieKKpRABwhlWvKot4Z3F+Hg6CKUYxNjxxSdh7fv1boI6B4gQfG3RzC2X53BMCh5I4xvluVXepnE3ynQk3hTdSdqu4ye5nM1IYbaQNKwihrI0y4jE+jnZ6AMakYMNyfqoAK776makP/Auyf0lrRU/VqxY/SwO2Pgyqmhcf+AY9pAh+6AwsGFTAAnTUsihwPJsCpB7BzZTzTlw5drhwox5MGW71wiMuUmeQI6M1enm/6Sg2OBd1jhtr+9cgvhyUCf/VqPaMJqGKkuiJ9nrchBVYXWw8gHJNYw7Q8OBIMpqYhPpjQSXqLvODGZ7i4NPR6FFXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UoT0gkU3Vhd3X2T0qfT2Yuj0mPyPJsMzh1Tx6BIie/U=; b=XJoJG0W6J/DmeJWZ4sZjgecW8rIErOEWxcJIDPgdw1wtAaInGXXwLmMCru/rIkVCPHLyVQhsoaqsl9w3Q+GRUsf5+mpxVnXCd8zQ5FWJVUH1umrihivMx4m64+o1UiBxiFB7Iu1MGQjBei4oVdUaHfMBSt4XGr1LnMq1ltyWR+9nIUD7XMEN3l+aDHo0+hsuo5WkOaDgrsQLNdpykgWjX+MB/5ocoTqHwEM+lGNU3dLHnm3SEM8k4uGV0MSaHWIVb6rOZG/soOEwm22kj4lZkW3cK1zEcfPlCZXFyfiPdBg8YZJDxyALxZfk/xK2IoFewW74lL/aAEr9MePhGuGZvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UoT0gkU3Vhd3X2T0qfT2Yuj0mPyPJsMzh1Tx6BIie/U=; b=Au7n5QrEpQlVm4yywkwHNjs3mmC2WR2b9iV5cfU23fOXfm8PsekKz7hcrGfASvpYwSTHzoMPCxl5YWA6K2yLDIoq6qaHZMWbZPtXl5yfE2lnmzasF17jrbWFetvx7XhT+foRQJZULeMvBkKbzwZ3KLAWEQxnUKnvBQG1qsb7ReI= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4213.namprd12.prod.outlook.com (20.180.5.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Wed, 19 Feb 2020 14:41:10 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:41:10 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 11/13] iio: imu: inv_mpu6050: dynamic sampling rate change Date: Wed, 19 Feb 2020 15:39:56 +0100 Message-Id: <20200219143958.3548-12-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:41:08 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d2680f0-25a6-4dcf-c0db-08d7b549c2a6 X-MS-TrafficTypeDiagnostic: CH2PR12MB4213: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(376002)(396003)(346002)(39850400004)(136003)(189003)(199004)(2906002)(36756003)(16526019)(6666004)(26005)(86362001)(107886003)(2616005)(66556008)(66476007)(4326008)(5660300002)(66946007)(81166006)(186003)(478600001)(81156014)(7696005)(8936002)(1076003)(8676002)(6486002)(52116002)(316002)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4213;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KnPfBDg0xX01PfuBB3ymNqzQGKvUKWIlmo9bm097mPwCyFXG57vdwduJgKcO0Chm0p2OcFNgetgMIovLNIpr+CBTXbK6Gt0oKC8E96NCvVT0S3FVSVXklejNVjgom/ksrddRKLI84JmC3FesBPX3u31z2ay2+01l/P9O6+yMzorqGp5+jHGRG1C8Vnw1LAbcWGRE/++InEPKeCIgsP1jYeYVMOfQb7Tey6poQBB/no6YoIe9DwAqKqsIJiJSrOAl1EWb5SRUNOI9Hra4JMoiXiltXbCiShjaZcQyR2/OE64ZwP4wP03nX+qb2HWz6qe9VZmLYDEkNHbIBZWPr1JjyzUKulmgpYshr3s2MX/itCzdvhdhvMI4qttR+f28E3A85O94ADqYn9/b5EnO5TEk7LqrgX4Y0fGSw6qoMmcp8xCrnhhUWVmxjVCO44RuYRq3 X-MS-Exchange-AntiSpam-MessageData: YPLkYaxmAJLlP3zdB16F9dK2zJoNi2XW6prz19U/jak29MvdNrQgydhEB97QnNL4mLvDq0ugaXkQh87prfs88s/OAT0ZEDbu9StROMNLfQjOKWpXfHovVV14SFj7usXNxGGwD6C4AJ86v+BBwUGhHg== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d2680f0-25a6-4dcf-c0db-08d7b549c2a6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:41:10.2577 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zUKJF2IvgFXOx3vavyl3DmykaQXdKH26b+KoIOC/xwQN5FL5PxcGFFsh3BmVqSmMvrY77uOd2x+5mAha9+A0t/HHHVE2icQOr74UIYv9X7w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4213 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 mlxlogscore=694 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Sampling rate can be changed while the chip is running. It can be useful thus do not prevent it. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index aeee39696d3a..9076b6bb099c 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -910,10 +910,6 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, fifo_rate > INV_MPU6050_MAX_FIFO_RATE) return -EINVAL; - result = iio_device_claim_direct_mode(indio_dev); - if (result) - return result; - /* compute the chip sample rate divider */ d = INV_MPU6050_FIFO_RATE_TO_DIVIDER(fifo_rate); /* compute back the fifo rate to handle truncation cases */ @@ -946,7 +942,6 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, result |= inv_mpu6050_set_power_itg(st, false); fifo_rate_fail_unlock: mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); if (result) return result; From patchwork Wed Feb 19 14:39:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391653 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDBCA138D for ; Wed, 19 Feb 2020 14:41:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A487824672 for ; Wed, 19 Feb 2020 14:41:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="PXi2qR7j"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="Yvqzi8nM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbgBSOlR (ORCPT ); Wed, 19 Feb 2020 09:41:17 -0500 Received: from mx0a-00328301.pphosted.com ([148.163.145.46]:31540 "EHLO mx0a-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbgBSOlR (ORCPT ); Wed, 19 Feb 2020 09:41:17 -0500 Received: from pps.filterd (m0156134.ppops.net [127.0.0.1]) by mx0a-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEdVSQ016934; Wed, 19 Feb 2020 06:41:15 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=NW5saCpbUxUMe4Y3+xbu4Q1BEzzxexbYO8RDJm+K+Wg=; b=PXi2qR7jMokc8yUAafmEL8K9IZb1k4sLbd3JTseZYmleeOq7r5Ssw9sM0eOfoLTNFzR4 Jgz6rLYeOLOweg6Tc/6MozkTrXka5a4b8UuuGPlIKDgGSsmvBmEEv7M+pMb3GelvmqzH 1cd9jCQZrUlLZfcwuKiSfh9SIeCxRpqauVQVix1fdo3Xg+1KJ6UOInA9IoARXYqnkX8Z cy6Gd+I7Ca2nfKv4ST/ZzjBM0W9p0Hj2mM/YbjK6s6H9peJgnQ+YpOl+OhrANWWXVaPX ETNdnF7mWo25Vqugc2wjfGlUM9wXp4spb/g7lpFeRUNiC8vCUfAhmS4PAo6qiWMREcTV BQ== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2172.outbound.protection.outlook.com [104.47.59.172]) by mx0a-00328301.pphosted.com with ESMTP id 2y8uem8936-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:41:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QcHEmjRmZKCdrKYGB7fhD/SoWJ26h8EooYpas0qx6tN62tfTKeCqSf9/U7pDLdNrQl78Ib14gd2ggcHBpmVxHL0reSn7eBUiW/sdsK896j42SzjGV1R4/f6+sEo2rvoFyIatz047Xwu4SrvusGxBLDvaqiguBirhUBMSL/JLuLnrxRIiWTQ+mAGEScHVsMieZeVlV4gegLdu9MuFtG0Kz8VEsOax1IZDUi++wOfNRivCI6ChajR6LeHa311TTxQYB1z1e9YLpvXxHQbvnHeUtXLZKFXrO4MIDMHm8YuXljRputx436iI0L+oSVrKVnNLooCxtSw2cfJsH48KHQbmSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NW5saCpbUxUMe4Y3+xbu4Q1BEzzxexbYO8RDJm+K+Wg=; b=Nd1OPL3+1loMbnyuLC+07rV8Id/7ZzTfXDTIuJGmbU0wFtTK6NgBZ9SYGMmNsNGxe4Sz6Dhj0MgjMZDCTfJqiHHjiHDE1vJ7q4qtCTW0RvzE1tLLc+DC2lcuIv8ex7+5uvqwZVPp8XVmQc2x/OA+KrcSnfQ7UBXRP2IPh/X3rIF6PMZPItlFSgsj9jhDbLXCjE3k5iay6A5CfvghihF8ieXFPfWMuG+hDM7s4gjNoe9Azck/5tqtiGBWoRYQVoJei84Ycr0itVD7FXhiMgxh1MlUW0t2aw0QtgRzu/phPvUa9ql2HnY5nsT5lBq4CgRNSJRwt3vr34eE1RJPv0Iiiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NW5saCpbUxUMe4Y3+xbu4Q1BEzzxexbYO8RDJm+K+Wg=; b=Yvqzi8nM5+teResY4lZriyXVGqM6qzw0y+2A5BvCupRDrp1hVkHm1MGXPJUQbq/Adb3zGVWp/TTFkh8tD8eFDxhSFmfWU9f5LQoKE9eAqJa0sqvKImdSC+P6VfTFpF8AEBtRLfiUgMfiQjfIYopLK6tt+bKTOsBq0V/n0dHIvnM= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4213.namprd12.prod.outlook.com (20.180.5.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Wed, 19 Feb 2020 14:41:13 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:41:13 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 12/13] iio: imu: inv_mpu6050: use runtime pm with autosuspend Date: Wed, 19 Feb 2020 15:39:57 +0100 Message-Id: <20200219143958.3548-13-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:41:12 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c47b625b-b44a-41b9-bac4-08d7b549c4a6 X-MS-TrafficTypeDiagnostic: CH2PR12MB4213: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:792; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(376002)(396003)(346002)(39850400004)(136003)(189003)(199004)(2906002)(36756003)(16526019)(6666004)(26005)(86362001)(107886003)(2616005)(66556008)(66476007)(4326008)(5660300002)(66946007)(81166006)(186003)(478600001)(81156014)(7696005)(8936002)(1076003)(8676002)(6486002)(30864003)(52116002)(316002)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4213;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z/fR1id76d7E8CrbGLfEDlc5ouCYKG3N1cGcmTXNOLg+JECJo8rSg75BVDyszL3oDN/zKVCgbODCevj8rAQGkvKyE1bY6JRhlvk4hJiP1Cpu9jDuQs1KSUe4xQ7bZC7xGzs3aBtBYecUPUQ8vLJSfuDYdSgXoKF9zuJ0gEhocjHbbsWdVBkjuar/60SuQKVzgUed3n1TurxCupphocirWHvxgbSiDFJo8Df48cNRb9USYO3QIyv9F57kfTCBOzBUSv9hcoh86XHm966M5XjpG6I69fA5mA81UVe7RF6TGu/mq4RqnbsQOyv5fF+MXA3Q5heIX+zoCVanSd3JN4gRULJTXGmOIyJK4kkaijzvoSAGDrus/yg+li5X0731t2jDJrTW4h8XxJdPmSn+vfag56DgF1G3A/i2AjT5NKHSG16ui+l/OrHo5MqhoDgcgzPI X-MS-Exchange-AntiSpam-MessageData: /tGriZEZQCpTrOhDEeJV7sklZh/Z5Fr0mlHISgy4QIkltQNiRwlnXmtZmpwZqXm8eK9SbPj9vxhAIRcKHnN6Tj2VWxK0HI+KlCa4UpdR5XX8rGowyGqVqQGLqnzRSKAH0WQ8XHa/ntPT17mhaEksKA== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: c47b625b-b44a-41b9-bac4-08d7b549c4a6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:41:13.6250 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pcrPwJeyaB/XdctlQlOg1+5eovzAADSZN8XqH4HfvvOTT/TXhKSRhIS5tejpy2EvhXFdw3Z/oyKbAeQo5IyyKQ0uc985eAnXJsSJOZYlSUM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4213 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use runtime power management for handling chip power and sensor engines on/off. Simplifies things a lot since pm runtime already has reference counter. Usage of autosuspend reduces the number of power on/off. This makes polling interface now usable to get data at low frequency. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 267 ++++++++++++------ drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 5 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 33 ++- 3 files changed, 194 insertions(+), 111 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 9076b6bb099c..750fbc2614f0 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "inv_mpu_iio.h" #include "inv_mpu_magn.h" @@ -400,26 +402,13 @@ int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on) { int result; - if (power_on) { - if (!st->powerup_count) { - result = inv_mpu6050_pwr_mgmt_1_write(st, false, -1, -1); - if (result) - return result; - usleep_range(INV_MPU6050_REG_UP_TIME_MIN, - INV_MPU6050_REG_UP_TIME_MAX); - } - st->powerup_count++; - } else { - if (st->powerup_count == 1) { - result = inv_mpu6050_pwr_mgmt_1_write(st, true, -1, -1); - if (result) - return result; - } - st->powerup_count--; - } + result = inv_mpu6050_pwr_mgmt_1_write(st, !power_on, -1, -1); + if (result) + return result; - dev_dbg(regmap_get_device(st->map), "set power %d, count=%u\n", - power_on, st->powerup_count); + if (power_on) + usleep_range(INV_MPU6050_REG_UP_TIME_MIN, + INV_MPU6050_REG_UP_TIME_MAX); return 0; } @@ -563,6 +552,7 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, int *val) { struct inv_mpu6050_state *st = iio_priv(indio_dev); + struct device *pdev = regmap_get_device(st->map); unsigned int freq_hz, period_us, min_sleep_us, max_sleep_us; int result; int ret; @@ -571,92 +561,85 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, freq_hz = INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); period_us = 1000000 / freq_hz; - result = inv_mpu6050_set_power_itg(st, true); - if (result) + result = pm_runtime_get_sync(pdev); + if (result < 0) { + pm_runtime_put_noidle(pdev); return result; + } switch (chan->type) { case IIO_ANGL_VEL: - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_SENSOR_GYRO); - if (result) - goto error_power_off; - /* need to wait 2 periods to have first valid sample */ - min_sleep_us = 2 * period_us; - max_sleep_us = 2 * (period_us + period_us / 2); - usleep_range(min_sleep_us, max_sleep_us); + if (!st->chip_config.gyro_en) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_SENSOR_GYRO); + if (result) + goto error_power_off; + /* need to wait 2 periods to have first valid sample */ + min_sleep_us = 2 * period_us; + max_sleep_us = 2 * (period_us + period_us / 2); + usleep_range(min_sleep_us, max_sleep_us); + } ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, chan->channel2, val); - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_SENSOR_GYRO); - if (result) - goto error_power_off; break; case IIO_ACCEL: - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_SENSOR_ACCL); - if (result) - goto error_power_off; - /* wait 1 period for first sample availability */ - min_sleep_us = period_us; - max_sleep_us = period_us + period_us / 2; - usleep_range(min_sleep_us, max_sleep_us); + if (!st->chip_config.accl_en) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_SENSOR_ACCL); + if (result) + goto error_power_off; + /* wait 1 period for first sample availability */ + min_sleep_us = period_us; + max_sleep_us = period_us + period_us / 2; + usleep_range(min_sleep_us, max_sleep_us); + } ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl, chan->channel2, val); - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_SENSOR_ACCL); - if (result) - goto error_power_off; break; case IIO_TEMP: - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_SENSOR_TEMP); - if (result) - goto error_power_off; - /* wait 1 period for first sample availability */ - min_sleep_us = period_us; - max_sleep_us = period_us + period_us / 2; - usleep_range(min_sleep_us, max_sleep_us); + if (!st->chip_config.temp_en) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_SENSOR_TEMP); + if (result) + goto error_power_off; + /* wait 1 period for first sample availability */ + min_sleep_us = period_us; + max_sleep_us = period_us + period_us / 2; + usleep_range(min_sleep_us, max_sleep_us); + } ret = inv_mpu6050_sensor_show(st, st->reg->temperature, IIO_MOD_X, val); - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_SENSOR_TEMP); - if (result) - goto error_power_off; break; case IIO_MAGN: - result = inv_mpu6050_switch_engine(st, true, - INV_MPU6050_SENSOR_MAGN); - if (result) - goto error_power_off; - /* frequency is limited for magnetometer */ - if (freq_hz > INV_MPU_MAGN_FREQ_HZ_MAX) { - freq_hz = INV_MPU_MAGN_FREQ_HZ_MAX; - period_us = 1000000 / freq_hz; + if (!st->chip_config.magn_en) { + result = inv_mpu6050_switch_engine(st, true, + INV_MPU6050_SENSOR_MAGN); + if (result) + goto error_power_off; + /* frequency is limited for magnetometer */ + if (freq_hz > INV_MPU_MAGN_FREQ_HZ_MAX) { + freq_hz = INV_MPU_MAGN_FREQ_HZ_MAX; + period_us = 1000000 / freq_hz; + } + /* need to wait 2 periods to have first valid sample */ + min_sleep_us = 2 * period_us; + max_sleep_us = 2 * (period_us + period_us / 2); + usleep_range(min_sleep_us, max_sleep_us); } - /* need to wait 2 periods to have first valid sample */ - min_sleep_us = 2 * period_us; - max_sleep_us = 2 * (period_us + period_us / 2); - usleep_range(min_sleep_us, max_sleep_us); ret = inv_mpu_magn_read(st, chan->channel2, val); - result = inv_mpu6050_switch_engine(st, false, - INV_MPU6050_SENSOR_MAGN); - if (result) - goto error_power_off; break; default: ret = -EINVAL; break; } - result = inv_mpu6050_set_power_itg(st, false); - if (result) - goto error_power_off; + pm_runtime_mark_last_busy(pdev); + pm_runtime_put_autosuspend(pdev); return ret; error_power_off: - inv_mpu6050_set_power_itg(st, false); + pm_runtime_put_autosuspend(pdev); return result; } @@ -795,6 +778,7 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { struct inv_mpu6050_state *st = iio_priv(indio_dev); + struct device *pdev = regmap_get_device(st->map); int result; /* @@ -806,9 +790,11 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, return result; mutex_lock(&st->lock); - result = inv_mpu6050_set_power_itg(st, true); - if (result) + result = pm_runtime_get_sync(pdev); + if (result < 0) { + pm_runtime_put_noidle(pdev); goto error_write_raw_unlock; + } switch (mask) { case IIO_CHAN_INFO_SCALE: @@ -846,7 +832,8 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, break; } - result |= inv_mpu6050_set_power_itg(st, false); + pm_runtime_mark_last_busy(pdev); + pm_runtime_put_autosuspend(pdev); error_write_raw_unlock: mutex_unlock(&st->lock); iio_device_release_direct_mode(indio_dev); @@ -903,6 +890,7 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, int result; struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct inv_mpu6050_state *st = iio_priv(indio_dev); + struct device *pdev = regmap_get_device(st->map); if (kstrtoint(buf, 10, &fifo_rate)) return -EINVAL; @@ -920,9 +908,11 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, result = 0; goto fifo_rate_fail_unlock; } - result = inv_mpu6050_set_power_itg(st, true); - if (result) + result = pm_runtime_get_sync(pdev); + if (result < 0) { + pm_runtime_put_noidle(pdev); goto fifo_rate_fail_unlock; + } result = regmap_write(st->map, st->reg->sample_rate_div, d); if (result) @@ -938,8 +928,9 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, if (result) goto fifo_rate_fail_power_off; + pm_runtime_mark_last_busy(pdev); fifo_rate_fail_power_off: - result |= inv_mpu6050_set_power_itg(st, false); + pm_runtime_put_autosuspend(pdev); fifo_rate_fail_unlock: mutex_unlock(&st->lock); if (result) @@ -1385,6 +1376,14 @@ static void inv_mpu_core_disable_regulator_action(void *_data) inv_mpu_core_disable_regulator_vddio(st); } +static void inv_mpu_pm_disable(void *data) +{ + struct device *dev = data; + + pm_runtime_put_sync_suspend(dev); + pm_runtime_disable(dev); +} + int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type) { @@ -1409,7 +1408,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, st = iio_priv(indio_dev); mutex_init(&st->lock); st->chip_type = chip_type; - st->powerup_count = 0; st->irq = irq; st->map = regmap; @@ -1521,8 +1519,16 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, goto error_power_off; } - /* chip init is done, turning off */ - result = inv_mpu6050_set_power_itg(st, false); + /* chip init is done, turning on runtime power management */ + result = pm_runtime_set_active(dev); + if (result) + goto error_power_off; + pm_runtime_get_noresume(dev); + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, INV_MPU6050_SUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(dev); + pm_runtime_put(dev); + result = devm_add_action_or_reset(dev, inv_mpu_pm_disable, dev); if (result) return result; @@ -1590,11 +1596,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, } EXPORT_SYMBOL_GPL(inv_mpu_core_probe); -#ifdef CONFIG_PM_SLEEP - -static int inv_mpu_resume(struct device *dev) +static int __maybe_unused inv_mpu_resume(struct device *dev) { - struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct inv_mpu6050_state *st = iio_priv(indio_dev); int result; mutex_lock(&st->lock); @@ -1603,27 +1608,101 @@ static int inv_mpu_resume(struct device *dev) goto out_unlock; result = inv_mpu6050_set_power_itg(st, true); + if (result) + goto out_unlock; + + result = inv_mpu6050_switch_engine(st, true, st->suspended_sensors); + if (result) + goto out_unlock; + + if (iio_buffer_enabled(indio_dev)) + result = inv_mpu6050_prepare_fifo(st, true); + out_unlock: mutex_unlock(&st->lock); return result; } -static int inv_mpu_suspend(struct device *dev) +static int __maybe_unused inv_mpu_suspend(struct device *dev) { - struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev)); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct inv_mpu6050_state *st = iio_priv(indio_dev); int result; mutex_lock(&st->lock); + + if (iio_buffer_enabled(indio_dev)) { + result = inv_mpu6050_prepare_fifo(st, false); + if (result) + goto out_unlock; + } + + st->suspended_sensors = 0; + if (st->chip_config.accl_en) + st->suspended_sensors |= INV_MPU6050_SENSOR_ACCL; + if (st->chip_config.gyro_en) + st->suspended_sensors |= INV_MPU6050_SENSOR_GYRO; + if (st->chip_config.temp_en) + st->suspended_sensors |= INV_MPU6050_SENSOR_TEMP; + if (st->chip_config.magn_en) + st->suspended_sensors |= INV_MPU6050_SENSOR_MAGN; + result = inv_mpu6050_switch_engine(st, false, st->suspended_sensors); + if (result) + goto out_unlock; + result = inv_mpu6050_set_power_itg(st, false); + if (result) + goto out_unlock; + inv_mpu_core_disable_regulator_vddio(st); +out_unlock: mutex_unlock(&st->lock); return result; } -#endif /* CONFIG_PM_SLEEP */ -SIMPLE_DEV_PM_OPS(inv_mpu_pmops, inv_mpu_suspend, inv_mpu_resume); +static int __maybe_unused inv_mpu_runtime_suspend(struct device *dev) +{ + struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev)); + unsigned int sensors; + int ret; + + mutex_lock(&st->lock); + + sensors = INV_MPU6050_SENSOR_ACCL | INV_MPU6050_SENSOR_GYRO | + INV_MPU6050_SENSOR_TEMP | INV_MPU6050_SENSOR_MAGN; + ret = inv_mpu6050_switch_engine(st, false, sensors); + if (ret) + goto out_unlock; + + ret = inv_mpu6050_set_power_itg(st, false); + if (ret) + goto out_unlock; + + inv_mpu_core_disable_regulator_vddio(st); + +out_unlock: + mutex_unlock(&st->lock); + return ret; +} + +static int __maybe_unused inv_mpu_runtime_resume(struct device *dev) +{ + struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev)); + int ret; + + ret = inv_mpu_core_enable_regulator_vddio(st); + if (ret) + return ret; + + return inv_mpu6050_set_power_itg(st, true); +} + +const struct dev_pm_ops inv_mpu_pmops = { + SET_SYSTEM_SLEEP_PM_OPS(inv_mpu_suspend, inv_mpu_resume) + SET_RUNTIME_PM_OPS(inv_mpu_runtime_suspend, inv_mpu_runtime_resume, NULL) +}; EXPORT_SYMBOL_GPL(inv_mpu_pmops); MODULE_AUTHOR("Invensense Corporation"); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index e328c98e362c..cd38b3fccc7b 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -164,6 +164,7 @@ struct inv_mpu6050_hw { * @magn_disabled: magnetometer disabled for backward compatibility reason. * @magn_raw_to_gauss: coefficient to convert mag raw value to Gauss. * @magn_orient: magnetometer sensor chip orientation if available. + * @suspended_sensors: sensors mask of sensors turned off for suspend */ struct inv_mpu6050_state { struct mutex lock; @@ -174,7 +175,6 @@ struct inv_mpu6050_state { enum inv_devices chip_type; struct i2c_mux_core *muxc; struct i2c_client *mux_client; - unsigned int powerup_count; struct inv_mpu6050_platform_data plat_data; struct iio_mount_matrix orientation; struct regmap *map; @@ -189,6 +189,7 @@ struct inv_mpu6050_state { bool magn_disabled; s32 magn_raw_to_gauss[3]; struct iio_mount_matrix magn_orient; + unsigned int suspended_sensors; }; /*register and associated bit definition*/ @@ -312,6 +313,7 @@ struct inv_mpu6050_state { #define INV_MPU6050_ACCEL_UP_TIME 20 #define INV_MPU6050_GYRO_UP_TIME 35 #define INV_MPU6050_GYRO_DOWN_TIME 150 +#define INV_MPU6050_SUSPEND_DELAY_MS 2000 /* delay time in microseconds */ #define INV_MPU6050_REG_UP_TIME_MIN 5000 @@ -439,7 +441,6 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable); int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, unsigned int mask); int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val); -int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on); int inv_mpu_acpi_create_mux_client(struct i2c_client *client); void inv_mpu_acpi_delete_mux_client(struct i2c_client *client); int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index f53f50d08b9e..f7b5a70be30f 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -3,6 +3,7 @@ * Copyright (C) 2012 Invensense, Inc. */ +#include #include "inv_mpu_iio.h" static unsigned int inv_scan_query_mpu6050(struct iio_dev *indio_dev) @@ -156,41 +157,43 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable) static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) { struct inv_mpu6050_state *st = iio_priv(indio_dev); + struct device *pdev = regmap_get_device(st->map); unsigned int scan; int result; - scan = inv_scan_query(indio_dev); - if (enable) { - result = inv_mpu6050_set_power_itg(st, true); - if (result) + scan = inv_scan_query(indio_dev); + result = pm_runtime_get_sync(pdev); + if (result < 0) { + pm_runtime_put_noidle(pdev); return result; + } + /* + * In case autosuspend didn't trigger, turn off first not + * required sensors. + */ + result = inv_mpu6050_switch_engine(st, false, ~scan); + if (result) + goto error_power_off; result = inv_mpu6050_switch_engine(st, true, scan); if (result) goto error_power_off; st->skip_samples = inv_compute_skip_samples(st); result = inv_mpu6050_prepare_fifo(st, true); if (result) - goto error_sensors_off; + goto error_power_off; } else { result = inv_mpu6050_prepare_fifo(st, false); - if (result) - goto error_sensors_off; - result = inv_mpu6050_switch_engine(st, false, scan); - if (result) - goto error_power_off; - - result = inv_mpu6050_set_power_itg(st, false); if (result) goto error_power_off; + pm_runtime_mark_last_busy(pdev); + pm_runtime_put_autosuspend(pdev); } return 0; -error_sensors_off: - inv_mpu6050_switch_engine(st, false, scan); error_power_off: - inv_mpu6050_set_power_itg(st, false); + pm_runtime_put_autosuspend(pdev); return result; } From patchwork Wed Feb 19 14:39:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11391655 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24936930 for ; Wed, 19 Feb 2020 14:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F027924654 for ; Wed, 19 Feb 2020 14:41:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="byeUyvJ7"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="Gtb2TLw8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726651AbgBSOlV (ORCPT ); Wed, 19 Feb 2020 09:41:21 -0500 Received: from mx0a-00328301.pphosted.com ([148.163.145.46]:36730 "EHLO mx0a-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbgBSOlU (ORCPT ); Wed, 19 Feb 2020 09:41:20 -0500 Received: from pps.filterd (m0156134.ppops.net [127.0.0.1]) by mx0a-00328301.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01JEdZTC016941; Wed, 19 Feb 2020 06:41:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=pfpt1; bh=QN9IlZdTIswfuX6DlTgo4hiDqK7JGVTkqXAy1bHxHgw=; b=byeUyvJ7lPDwhpmG1zCd7wPe9tIFnQzJnieExjV90S8tLN35J3E67nQOBYt3XSsZy3kk tMA5t1CDbJaXdacZl2bvhhL51j1tldRLZtghOMkc6aU+XbLz38sJuKq9sdDpIQ6XAzQv s1UPxeikyizD/9oJ66mARJpkOAjX46a3nNO5u6oEHd/KlMclc4KV//xK0Wf883r4+lSt uJ3LcvzHEZHD1bdJn0O26H4lXg40TYDLkrvIoLOEMLv0WaEOPqCPZ4mIaklNpuxaG10i V2c+Gwj/a9bs4B2W6Ym2ucpPzn9LLvGxq2VW/Asrjk8G9Ujb47Yiif4ywuwgrW0ZpN/K qw== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by mx0a-00328301.pphosted.com with ESMTP id 2y8uem893f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Feb 2020 06:41:19 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WA+QAmAUUmY8Wx9OgpELQ41dVxbVyhaXDoGwoPAbSOcOAuaVgnyUyGKhfKjS3z3aCQQxIGdjS10tb8XXNlpajImJ7+6Dp4sdcwe7vhz9dW+wdx4KYKl+UDvRI96SyXuRpEW90NZhWaV06C2bZ34oBCbC0v6g6zAu+dZ8Uma37moxpeU3Ox2+MG4kI93yB06zkqMQgY4ol42R6DWRBuyAirtsGOqakBO3A9Im+BJmt183WilS3jxzcZ6Wmf14QmkwJPumY1T5FZ10EsW4QBdgypgENhkxR6elcBJR2NBb8nrLtcpIM/nC4Nv5+PtgRugORDrZQaEFg9UW6KYEGlqMkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QN9IlZdTIswfuX6DlTgo4hiDqK7JGVTkqXAy1bHxHgw=; b=jy1Oetcm3x7FkXSSqT9FqWQWCLTx2tBx0cexkIHlPuiR4arbKyzIbQh/5W1NaqZDhQ07FRo2UJRf5mNQ53n2f6o0e+7wgzb/ziXcfwY/6uROVnBwAAEsf+jqHuUxyngBQajZoh468BjEOz2oxLDRF9LL6IENmfLv4STGJpsdEV5hbpyKpPmaR+USt5e5BwfMqKNSpmRu56qfKsbRsVu4usBG5OUotIA8QNw7z0Q/UvHjdNnqLJgUdWvmrDtwYgvwEXcL/MCvY0cE7v4CaS1IJBv78cNumbrENehnrBIStuTT4N2eRd1BDLvbXlU8IRVybuhe+ca0sYGVJ07yWugRvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=invensense.com; dmarc=pass action=none header.from=invensense.com; dkim=pass header.d=invensense.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector2-invensense-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QN9IlZdTIswfuX6DlTgo4hiDqK7JGVTkqXAy1bHxHgw=; b=Gtb2TLw8plPFJCn30qtvZPYPnaPMBYJKOD7uvqA/QNcSbzreqovjmXwSTckit1kWGmxddxhPVPCo84565CWc3EDcG48DKwJlEGLahc9Fdpy19DNNAaOtm1n2R0CXQCDWat/nGjnUFrb4krbywCcpTjV4uAfFdZgAzqKaWizG6fY= Received: from CH2PR12MB4181.namprd12.prod.outlook.com (20.180.6.144) by CH2PR12MB4213.namprd12.prod.outlook.com (20.180.5.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Wed, 19 Feb 2020 14:41:17 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c057:8a13:530a:4340%5]) with mapi id 15.20.2750.016; Wed, 19 Feb 2020 14:41:17 +0000 From: Jean-Baptiste Maneyrol To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: Jean-Baptiste Maneyrol Subject: [PATCH v2 13/13] iio: imu: inv_mpu6050: temperature only work with accel/gyro Date: Wed, 19 Feb 2020 15:39:58 +0100 Message-Id: <20200219143958.3548-14-jmaneyrol@invensense.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200219143958.3548-1-jmaneyrol@invensense.com> References: <20200219143958.3548-1-jmaneyrol@invensense.com> X-ClientProxiedBy: BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frgnb-12nlpn2.invcorp.invensense.com (77.157.193.39) by BYAPR01CA0043.prod.exchangelabs.com (2603:10b6:a03:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 14:41:15 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [77.157.193.39] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e729fb5-7e87-4f4f-1519-08d7b549c6e4 X-MS-TrafficTypeDiagnostic: CH2PR12MB4213: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:612; X-Forefront-PRVS: 0318501FAE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(376002)(396003)(346002)(39850400004)(136003)(189003)(199004)(4744005)(2906002)(36756003)(16526019)(6666004)(26005)(86362001)(107886003)(2616005)(66556008)(66476007)(4326008)(5660300002)(66946007)(81166006)(186003)(478600001)(81156014)(7696005)(8936002)(1076003)(8676002)(6486002)(52116002)(316002)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:CH2PR12MB4213;H:CH2PR12MB4181.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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SteKXXVxKOOc+niJboEKejo22z0eB4Sy2XSr4QKcnAMq+ZhsoqacA7HickP/9oYYNWEA0R1ZCfWxde2RtfC0hQaEIMmqxGNnIHgy8srWtCQQDxIXT94iHvREUWiYuEKlavZjg61knkZCymjDu7yrfQE50Hq+cFEXgdlJYeaI188chiyjZnIqW7XhE8wlS+msJDZfpZk1EbKuJnIrYWQ9WyWW32LNQTryNaChWCHxCiGCmWKooh6FdGWBUykPunx568h0JORn4CbtT9PzZ3ocEsLvDfyOcPThYgdSIDM4mXnGmczvktundxKyEmvuAw9n87MoHw0SmGXrY4JTO5Lr9Op+d4NHVeBw/d2wn2IDpoiFEv6T7DtBci9Eb4pAsNfz223EG/tf4bSxc0dOXBBQc16F2nt0I6JdReIvexopn5uVLLOY9oLMCh9vvuFkvT0R X-MS-Exchange-AntiSpam-MessageData: WRacVBU53HD+rmW4UDnMCmYv3N885iKRqU2HoWBNpwuZ1XHcdcshzu6utPT0l9Z7SvoaUqJ781z2lkxVJge1qX3GM0GSCdN2R8lzlwSSuxN8ViyuZODBREl3thge3PK5QjFxqtZ4B+swTXDHb5QsgA== X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e729fb5-7e87-4f4f-1519-08d7b549c6e4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2020 14:41:17.3666 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: z68FCYl1JPES5M4yJAwYxbRM+4BOL01nr8cjAkLK0C98rQScVgrTS2Cm90THkfZpODumfQpDPXnT2XH1GQ1jGaP3hWubsLXJqEIhxuKNMQg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4213 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-19_03:2020-02-19,2020-02-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190113 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Temperature sensor works correctly only when accel and/or gyro is turned on. Prevent polling value if they are not running. Anyway it doesn't make sense to use it without sensor engines on. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 750fbc2614f0..94a989368b94 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -597,6 +597,11 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, chan->channel2, val); break; case IIO_TEMP: + /* temperature sensor work only with accel and/or gyro */ + if (!st->chip_config.accl_en && !st->chip_config.gyro_en) { + result = -EBUSY; + goto error_power_off; + } if (!st->chip_config.temp_en) { result = inv_mpu6050_switch_engine(st, true, INV_MPU6050_SENSOR_TEMP);