From patchwork Thu Sep 12 10:58:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11142781 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 DE13B924 for ; Thu, 12 Sep 2019 10:58:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7F0C214AE for ; Thu, 12 Sep 2019 10:58:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="shami1dK"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="Zc/QYOcr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731232AbfILK6c (ORCPT ); Thu, 12 Sep 2019 06:58:32 -0400 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:14126 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730680AbfILK6c (ORCPT ); Thu, 12 Sep 2019 06:58:32 -0400 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 x8CAtDu6012941; Thu, 12 Sep 2019 03:58:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=pfpt1; bh=prb8IZ9lwHU14PLNCdQOHRz5berl0XmIoPzwvMU+hfI=; b=shami1dKNDR+NeMOGSTH6ygPa++SgG6MWvJDmg+DBiL1LGRhaErgRyDhnwHV+r497Yrk lpT5muUpGXZiZ20S2xb6en3742fD9Icqcwpgn7GyaHKICw7dMjx0Q9zharsbQhBa7eCg WOJZgMxHzhF9Nb3fVuYcBwFEW1s2SyZRRoC6goK9ZEJJgvfe4sUIeXdL1EMun9sOD4Ez N24l0JDZy0jFgVH/TEzbwmFSaDN4o0S7t58tzUQO1aYbeQ2TkB+nKS0/6o3CqQyeG3K9 85LENgf80wRozxgZRqflw1ZZD88WbsFS8BWpqJMiihCVlES3D6nYkJkdZJVJG7oJm8pi UQ== Received: from nam05-by2-obe.outbound.protection.outlook.com (mail-by2nam05lp2059.outbound.protection.outlook.com [104.47.50.59]) by mx0b-00328301.pphosted.com with ESMTP id 2uv8gn2s9m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2019 03:58:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TRHo04e4FSrj/e+OyFs9YvGb6JpYyW0ZoYJHznrG9pbP7HTLs4fgvUVGpqBy3MV/mKGtyWM73jq46f/6/tfGYFEIFPVjaoSGmtvC5YRkECNaJqGWyvpITtkynN4anF19HfP0LYSyNsf9fy2fqrtp7GMMZNBjWgPjDEeX5enaGEXB1vBityn/3BSZXbZDX+H9O3NQAqGsgjsoHPI8QmGbmShyJ180Gd0WDkoh+FIuyXiMqry6fpUVtgJsKUrT7857dEhzRKlweriIammEY8+AgHax+KwZpkp08rPGBkS/7HRbHUjpiEVfDgAlXUJY21paoUG9D9z7ukomPBGN6FqCrg== 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=prb8IZ9lwHU14PLNCdQOHRz5berl0XmIoPzwvMU+hfI=; b=ZxE0T//ICrZSF9xGVJy5ypi69AEwwew7gkgUc/O4tsyj1zlQo0qI8sF/bI3xUiYEQVMUWKOdrBeQOvcEUzx91hYXVdbZHA0eEjQvJ9kANYaPNDmCIRPJjvJIEa2c4v5qgAM/M2/tvnleW5aL/UbiLyi5K6J7yuuQ/8LuQO+MiRvDaugE3ZdIiYOAgTsYv4a5mq37VJ/i1j6cG+iZ0l9AfavIV8B9AlDyz0UDGptB07kD+xoWwxp+E8xgGCq+ioUXY5yA4uObm+QtfdJdsK9ngqcJoOSTQXtquxvU4HDE3wxQV4H+mssIVdv8yal8IGZyTVDLH3pYnFzHDGRTQ2cqdA== 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=prb8IZ9lwHU14PLNCdQOHRz5berl0XmIoPzwvMU+hfI=; b=Zc/QYOcrgfCfFqeYKprsEVLKTd2ayFhkJDz0rW/SMb3MXG4r7Jiez27Zzq8DTrrXxDGyetNw/HbJyvLoUN4UhozI9aj8xVoZB6If0U5nmVjvsriVkug9TH2Cl8Xt2ySLNJ6cxJ89Lg8AYGZduikMPpYKn3TQTnRZ9okC3moqIBQ= Received: from MN2PR12MB3373.namprd12.prod.outlook.com (20.178.242.33) by MN2PR12MB2973.namprd12.prod.outlook.com (20.178.243.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.15; Thu, 12 Sep 2019 10:58:25 +0000 Received: from MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166]) by MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166%5]) with mapi id 15.20.2241.018; Thu, 12 Sep 2019 10:58:24 +0000 From: Jean-Baptiste Maneyrol To: "jic23@kernel.org" CC: "linux-iio@vger.kernel.org" , Jean-Baptiste Maneyrol Subject: [PATCH v2 1/7] iio: imu: inv_mpu6050: disable i2c mux for MPU925x Thread-Topic: [PATCH v2 1/7] iio: imu: inv_mpu6050: disable i2c mux for MPU925x Thread-Index: AQHVaVj/37OHFQUMKUGuprUbhwJ5jw== Date: Thu, 12 Sep 2019 10:58:24 +0000 Message-ID: <20190912105804.15650-1-jmaneyrol@invensense.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) x-originating-ip: [77.157.193.39] x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 550ac9ef-60d7-407f-99f4-08d737702222 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MN2PR12MB2973; x-ms-traffictypediagnostic: MN2PR12MB2973: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(346002)(376002)(366004)(396003)(39840400004)(199004)(189003)(81166006)(80792005)(86362001)(386003)(102836004)(6436002)(50226002)(26005)(4326008)(14444005)(256004)(6506007)(186003)(2501003)(99286004)(53936002)(66446008)(64756008)(1076003)(54906003)(66476007)(66556008)(5660300002)(486006)(14454004)(52116002)(66946007)(476003)(2616005)(316002)(36756003)(2351001)(71190400001)(2906002)(478600001)(305945005)(107886003)(6512007)(25786009)(7736002)(81156014)(8676002)(5640700003)(71200400001)(66066001)(6486002)(6916009)(6116002)(3846002)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB2973;H:MN2PR12MB3373.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-message-info: FfWEDC7UV7Ay3vrXArnwKldqPg9WjF7CrAAvg2aoR4b4mSUQ2ZsL8bRiQNIVVEFuOaIDLWB7lbTJfUpRf39cG3yx4nNt4PEL/jgBde3M9YhZ7yeeXyYbuGbSqoXuK3B+C85v6zVkpcz3h0XF6WBnWuFSYZLqSUm3axKNd5lj4mb9hftq2VLlQoGP10F4F+Fk3yRYgTPDdGOyUY0TnJLvVkWM0KwMYnscCqEuxElBkp9gQ21Jn99kbVtnpst1eOmCh3X2ddQUTxd2Po7BfIhjVRpwgM/DyvuyJyK1Jnn0q925XgFFgrzUsBhVKFSyOp4KXGLYTPf5ka2lZO3WSvTHadMSPcuqWBhi3hwnJtmv3KjDPiN0t+Cd3Gf3fcQON1emQ8xtRlaZZN5H+Dge6hK2YJtjZJasgvu27d0YC5uAKGg= MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 550ac9ef-60d7-407f-99f4-08d737702222 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2019 10:58:24.8230 (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: 6YS05PqXgO8wGZpMNewCapXrbBgPyOADHPA88b1yjpBeobNnaunHDRU6qI9ppkMDK/WBDGzJS0M755SdUxDU+KsC9rX2Zda+b7Pl0DzIYHY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2973 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-12_05:2019-09-11,2019-09-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=944 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909120116 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Disable i2c mux for supported 9xxx chips. This is a pre-requesite for controling 9xxx magnetometer using the i2c master of the chip. Check in device-tree that there is no i2c-gate device declared for ensuring backward compatibility with existing setups. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 7 +-- drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 60 +++++++++++++++++++--- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 + 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index b17f060b52fc..7b2e4d81bbba 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -1156,9 +1156,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, return result; } - if (inv_mpu_bus_setup) - inv_mpu_bus_setup(indio_dev); - dev_set_drvdata(dev, indio_dev); indio_dev->dev.parent = dev; /* name will be NULL when enumerated via ACPI */ @@ -1167,6 +1164,10 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, else 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 (chip_type == INV_ICM20602) { indio_dev->channels = inv_icm20602_channels; indio_dev->num_channels = ARRAY_SIZE(inv_icm20602_channels); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c index 4b8b5a87398c..389cc8505e0e 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c @@ -68,6 +68,56 @@ static const char *inv_mpu_match_acpi_device(struct device *dev, return dev_name(dev); } +static bool inv_mpu_i2c_aux_bus(struct device *dev) +{ + struct inv_mpu6050_state *st = iio_priv(dev_get_drvdata(dev)); + + switch (st->chip_type) { + case INV_ICM20608: + case INV_ICM20602: + /* no i2c auxiliary bus on the chip */ + return false; + case INV_MPU9250: + case INV_MPU9255: + if (st->magn_disabled) + return true; + else + return false; + default: + return true; + } +} + +/* + * 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) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + struct device *dev = indio_dev->dev.parent; + struct device_node *mux_node; + + switch (st->chip_type) { + case INV_MPU9250: + case INV_MPU9255: + mux_node = of_get_child_by_name(dev->of_node, "i2c-gate"); + if (mux_node != NULL) { + st->magn_disabled = true; + dev_warn(dev, "disable internal use of magnetometer\n"); + } + of_node_put(mux_node); + break; + default: + break; + } + + return 0; +} + /** * inv_mpu_probe() - probe function. * @client: i2c client. @@ -112,17 +162,12 @@ static int inv_mpu_probe(struct i2c_client *client, } result = inv_mpu_core_probe(regmap, client->irq, name, - NULL, chip_type); + inv_mpu_magn_disable, chip_type); if (result < 0) return result; st = iio_priv(dev_get_drvdata(&client->dev)); - switch (st->chip_type) { - case INV_ICM20608: - case INV_ICM20602: - /* no i2c auxiliary bus on the chip */ - break; - default: + if (inv_mpu_i2c_aux_bus(&client->dev)) { /* declare i2c auxiliary bus */ st->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, I2C_MUX_LOCKED | I2C_MUX_GATE, @@ -137,7 +182,6 @@ static int inv_mpu_probe(struct i2c_client *client, result = inv_mpu_acpi_create_mux_client(client); if (result) goto out_del_mux; - break; } return 0; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index db1c6904388b..cbbb2fb8949a 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -125,6 +125,7 @@ struct inv_mpu6050_hw { * @it_timestamp: timestamp from previous interrupt. * @data_timestamp: timestamp for next data sample. * @vddio_supply voltage regulator for the chip. + * @magn_disabled: magnetometer disabled for backward compatibility reason. */ struct inv_mpu6050_state { struct mutex lock; @@ -146,6 +147,7 @@ struct inv_mpu6050_state { s64 it_timestamp; s64 data_timestamp; struct regulator *vddio_supply; + bool magn_disabled; }; /*register and associated bit definition*/ From patchwork Thu Sep 12 10:58:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11142783 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 06B3C1599 for ; Thu, 12 Sep 2019 10:58:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF93F208C2 for ; Thu, 12 Sep 2019 10:58:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="XDhjE8qL"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="KoehO4dQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730680AbfILK6d (ORCPT ); Thu, 12 Sep 2019 06:58:33 -0400 Received: from mx0a-00328301.pphosted.com ([148.163.145.46]:11170 "EHLO mx0a-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730811AbfILK6d (ORCPT ); Thu, 12 Sep 2019 06:58:33 -0400 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 x8CAuIFi020608; Thu, 12 Sep 2019 03:58:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt1; bh=H/HbullFhz+KLrFmGWvTfyVKjyDp6t8npS/tLvwO3Og=; b=XDhjE8qLj+rfEcpSpO5w+7qOeSLhQ5DX2YDNGd67Uo8ZmGZYhj33bSPMxgvAYxSFYcTI WiGkMkAowNEESbRLTKkAJroTrWX5HF7esKPlwVZ1VtnbwUOwqeGBNNOYML3cxqyca1mr hexmXYAXLermC22xPce+kIxscuFW2ozqQBe0x/A5YhneFGyThe4OLHbC1ZfH4c+5LE4X Fii3leRBjmQJfGvhs79pOEzRwXq+urOFdTueVFFTiLNVwaZ9aloLkxuqxKJJXfQZNVpl wjVJ4TUavae8o7TV1X/qaYyEI8Wy10Qrr6yP1Pjbkw/QhQAWn9hKGI4EOro91ImOXx/s fA== Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2059.outbound.protection.outlook.com [104.47.37.59]) by mx0a-00328301.pphosted.com with ESMTP id 2uwrvdhwky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2019 03:58:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cVxe8/QlPseXVGmSo9n8CB6VzWkgZNQGJB9V56WFPrzTrxZ+a4Zp+JB4evJkS6DqU4PJtQGr6H0pZpotwn2jnbJDVERW3XlvQm6DwT2FY88UYNc5b+rM7BakRwslWXZtnUr2gjyksDJg6BYSHf1N7otJDkDBZW5eh05U6umNSP0NaRuznDY5g65K8qk4EC1GRE9MdCBJV5IkbglGFIMmiR84BQrWR1D9YLPvPS65m61WcUokgpxavq7+IvKNtwQNZYvfCXNQXaK+T4OPFz0/UbewHAtsnOWEBAt+fhoBIIDw2k3vWC+VpfNTzJYLqZ11ysw5eeCF/E1HucWumRNHAA== 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=H/HbullFhz+KLrFmGWvTfyVKjyDp6t8npS/tLvwO3Og=; b=dqqEfS9mbTbDO6dglfZgDF1IELiKP060P4FUgsP5825IYNSFMvjjJmW+TqBQQhFHMEJ7doLZ/ICMGbz6EP76cDB5P6LoRFhK4fXHqwNZxJ0vYBw6MiUkCNkW8xPJlFt0MWhbaY9Sl/FiJuo95pwhuRjXUdYz+2Bm/iqkV1sUxqvY8UullD8jkLVBXkfA1filL/dlSbfNu/fI4Hj/6TDYsNv64F1ETwN7wDMX3wxuVynxmwAhAX0vZLe4WSDw1p7YMvrK5/SwAGTJG2Ihu5vviBc5EMhOoUyKyatz2t52FMUEWxMCkWPAuBZ6Zwp0ZwmJlkq+kilc+meJNqswLb3VOw== 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=H/HbullFhz+KLrFmGWvTfyVKjyDp6t8npS/tLvwO3Og=; b=KoehO4dQT8VxCCVZbExaFnT1lgybfNLRb1HEi4WwIUswNrwLucU9LZlsY8KsYN6wjITKKe7OgZtz9sAToXqyhPQzeFJOAWXWWYuSBVWlLQuqQ8FB/Wap8r4g5O0CqbbB1Ld9OrQEaTiiY3jQK58q70t7gZ6IUn/nuRoZlvCiXHQ= Received: from MN2PR12MB3373.namprd12.prod.outlook.com (20.178.242.33) by MN2PR12MB2973.namprd12.prod.outlook.com (20.178.243.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.15; Thu, 12 Sep 2019 10:58:30 +0000 Received: from MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166]) by MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166%5]) with mapi id 15.20.2241.018; Thu, 12 Sep 2019 10:58:29 +0000 From: Jean-Baptiste Maneyrol To: "jic23@kernel.org" CC: "linux-iio@vger.kernel.org" , Jean-Baptiste Maneyrol Subject: [PATCH v2 2/7] iio: imu: inv_mpu6050: add header include protection macro Thread-Topic: [PATCH v2 2/7] iio: imu: inv_mpu6050: add header include protection macro Thread-Index: AQHVaVkCmetzGvkag0CGnV9OrCVo6g== Date: Thu, 12 Sep 2019 10:58:29 +0000 Message-ID: <20190912105804.15650-2-jmaneyrol@invensense.com> References: <20190912105804.15650-1-jmaneyrol@invensense.com> In-Reply-To: <20190912105804.15650-1-jmaneyrol@invensense.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) x-originating-ip: [77.157.193.39] x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7f0c2ed4-5f06-4a12-f6eb-08d73770250a x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MN2PR12MB2973; x-ms-traffictypediagnostic: MN2PR12MB2973: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:296; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(346002)(376002)(366004)(396003)(39840400004)(199004)(189003)(81166006)(80792005)(86362001)(76176011)(386003)(102836004)(6436002)(50226002)(26005)(4326008)(14444005)(256004)(6506007)(186003)(2501003)(99286004)(53936002)(66446008)(64756008)(1076003)(54906003)(66476007)(4744005)(66556008)(5660300002)(486006)(14454004)(52116002)(66946007)(446003)(476003)(2616005)(316002)(11346002)(36756003)(2351001)(71190400001)(2906002)(478600001)(305945005)(107886003)(6512007)(25786009)(7736002)(81156014)(8676002)(5640700003)(71200400001)(66066001)(6486002)(6916009)(6116002)(3846002)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB2973;H:MN2PR12MB3373.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-message-info: mEv41thoEaBCrRVXjOLJBjJGjDhqdVe4vI5iQQsqyuaMpmedmSeyz8ZE5n6lZs3QJE74Qwm3ufVTUdSpWudvoOpeQebBzDnFLyubu5b//JGUZEzzOLZ+RYywgLavWheVnqTtvFyVOrYbCRQS9ZlU7iK45+/LST/I0oXQ0jnhB5z0ejWu7AiNBM1rK3muXSv2P7kAASkqh2ojIfr2lTflhosr/L081PCN1mEtft4o7HKgm53PMs9zZuzLvSF33wEDSjS0D0CDzlTFMrdRS3dc0HOmho9fpEi2Pp1JenOyjcQsAcJzuBQ0xqxIH9KDsndPQbH0+5p93MT81YDGJ82SAFRc0pQea2ekzRLMskq8BkLQh/p7WA5ecY3djSi5A5TluIYLOqfgU04gyK0zMD9llA6hwBn9wlm0WkZsrw5y9hA= MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f0c2ed4-5f06-4a12-f6eb-08d73770250a X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2019 10:58:29.7932 (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: xOF0dJ6u6L1SGTSx6ItxqCPPiMq//jYBMQcRIOVTuUGixuYK9pbnSjLL2YSPhJoBxlbRezHA22LzPUSnxkDdAQUH+VE/i9z3jTBi5y7Iscc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2973 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-12_05:2019-09-11,2019-09-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 spamscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909120116 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index cbbb2fb8949a..7cfd3a05c144 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -2,6 +2,10 @@ /* * Copyright (C) 2012 Invensense, Inc. */ + +#ifndef INV_MPU_IIO_H_ +#define INV_MPU_IIO_H_ + #include #include #include @@ -344,3 +348,5 @@ void inv_mpu_acpi_delete_mux_client(struct i2c_client *client); int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type); extern const struct dev_pm_ops inv_mpu_pmops; + +#endif From patchwork Thu Sep 12 10:58:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11142785 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 26D731599 for ; Thu, 12 Sep 2019 10:58:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4522214AE for ; Thu, 12 Sep 2019 10:58:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="il5JYNAG"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="ZOGIRY7T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731282AbfILK6g (ORCPT ); Thu, 12 Sep 2019 06:58:36 -0400 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:16930 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730811AbfILK6f (ORCPT ); Thu, 12 Sep 2019 06:58:35 -0400 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 x8CAtDEU012938; Thu, 12 Sep 2019 03:58:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt1; bh=qSrvncP8uZjIPGyIqTJfnOHst250avxl5ofrnHdGELs=; b=il5JYNAGTm2TLk3qkfEpkaiQFhHfEKWtoRUCegYTIHpIGPOPzVf0hD0ZRevJf9NMK0h3 mcfwWJ6OfbWyBhrjOeCoEVIf9ipWcFzhACRhVuV3/+fGaiI/tsUJrZh80YbXZSBwsHWf IQVVKxvHIiJaujaZf8O/NyuB1P9Sa8FWX9fxi91y5RhG0D1Cci3aZvha7OBFstoaGfXC Shn68SGNdJCGTVq8UOGjLJmqYZSWkLfebqQzpWzOWv83IenCMWHYzTt4qmNdUVfDRLEN KKS+OXH/V+H+SzvZou6LW9S0EqkAk9Di1SfOVx22YRg2CWs5AyxeGbB2ABUQb7YH4Au9 MQ== Received: from nam05-by2-obe.outbound.protection.outlook.com (mail-by2nam05lp2058.outbound.protection.outlook.com [104.47.50.58]) by mx0b-00328301.pphosted.com with ESMTP id 2uv8gn2s9p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2019 03:58:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TuT0vkQJei5XTEsWvjfy+lOcM+Da7d0LQKGAVqdApxAupq9bA2IjAuJpeRQcTNX3ZWVuj5ArbM06cnCqvVcI4TzgU+JVhKhqHYi6FeNUXHjaz5RFvbgFd4nVwvBu1dqTDh9a3SOUXnt6C/bFFWdp+RNUbppTDGgQIsRd9xd8PhtlsXA502MYGoJlJFdlfSNSHNTqiAAaZdWt4ywbYSAAo1qTUowVClrdphQoJKb5NFOX0G8+jJHqp88PdaL8XxXwaR1k3I9O1CV9RAe27SO45+LqctYDdRtQ3TI5OpUb8+Cdq8kiYXWbwRdGvlB1OsPLMpOvkS+e310Xl932X2XlHg== 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=qSrvncP8uZjIPGyIqTJfnOHst250avxl5ofrnHdGELs=; b=Jnj8mt20EATpjaaSBLCymXgAfTWGRYL2/ZWlHwOI60yNsEPCbfA7Lc6EM3M7IpJyTmCt/sBVPT4CFZ4jZViBDWBx+z/CSzx1RwTpXdsJy8UVSsBjbgryKX7HOp/qnMyj7z5qlOXh/4uWkYEvsgkoiAYDSwHjViMiFuhNq4/Dge0YMedAv64CMYrxe5tHcRgLjMagzyloxX+feUzV9thI85rDPSJevy0SDzkf+7C5qk6Sph+NDGhYlB7YZeyDyPKOb9QyrrvzXP6tW5QXAAXc/ub5SUynNBvAL1wE5KrUYT+AJIgdr5niLBLsA+swf9sEBAJLwkOUHjeL+dhvvG9nIw== 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=qSrvncP8uZjIPGyIqTJfnOHst250avxl5ofrnHdGELs=; b=ZOGIRY7TfZLPyxxFpqEr8AhGnqwS7cyMjbs0CM4bj4eF++hO3FNQxA5WwHsMLhcDozvUuK/UilZR2YF0JzXvqhGRFITfT2J0ccLMIX/pMdt7b2qJRonm2DYi8A2K9vzVW6ys5ZDZq2oy5MjT/L1ncsONcWCvtP2DO2WL3xhstG8= Received: from MN2PR12MB3373.namprd12.prod.outlook.com (20.178.242.33) by MN2PR12MB2973.namprd12.prod.outlook.com (20.178.243.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.15; Thu, 12 Sep 2019 10:58:31 +0000 Received: from MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166]) by MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166%5]) with mapi id 15.20.2241.018; Thu, 12 Sep 2019 10:58:31 +0000 From: Jean-Baptiste Maneyrol To: "jic23@kernel.org" CC: "linux-iio@vger.kernel.org" , Jean-Baptiste Maneyrol Subject: [PATCH v2 3/7] iio: imu: inv_mpu6050: add defines for supporting 9-axis chips Thread-Topic: [PATCH v2 3/7] iio: imu: inv_mpu6050: add defines for supporting 9-axis chips Thread-Index: AQHVaVkDkc1zIGVDD0yrFYCm7/9tXw== Date: Thu, 12 Sep 2019 10:58:31 +0000 Message-ID: <20190912105804.15650-3-jmaneyrol@invensense.com> References: <20190912105804.15650-1-jmaneyrol@invensense.com> In-Reply-To: <20190912105804.15650-1-jmaneyrol@invensense.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) x-originating-ip: [77.157.193.39] x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 224aeb75-3583-4e16-3606-08d737702629 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MN2PR12MB2973; x-ms-traffictypediagnostic: MN2PR12MB2973: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2276; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(979002)(136003)(346002)(376002)(366004)(396003)(39840400004)(199004)(189003)(81166006)(80792005)(86362001)(76176011)(386003)(102836004)(6436002)(50226002)(26005)(4326008)(14444005)(256004)(6506007)(186003)(2501003)(99286004)(53936002)(66446008)(64756008)(1076003)(54906003)(66476007)(66556008)(5660300002)(486006)(14454004)(52116002)(66946007)(446003)(476003)(2616005)(316002)(11346002)(36756003)(2351001)(71190400001)(2906002)(478600001)(305945005)(107886003)(6512007)(25786009)(7736002)(81156014)(8676002)(5640700003)(71200400001)(66066001)(6486002)(6916009)(6116002)(3846002)(8936002)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB2973;H:MN2PR12MB3373.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-message-info: 9SNb6m3LKbVJBVygQ0avfAC4QVED1fx6vnWTgxxVKemgO9aQlYf8TulZCsLjDD+Gh/h+ao33mDhXbrde7d/6Y91rPz5RwhaHAWzuSfcokH3sifBlfcDHhraeHi0RJb9Rb/ZdLP8RXojevyxm/daPF9E2/Dr0az3p8dtZYiMumwxWzNYym/GTQryqIA25kFo33ToPhI7Sn9CyFD33SRNn8nkr6OAggpluJtKro8EEsuletmgYJi0r53oGuMTf00QD9AanTdxofwwnTpGCyRzrafZsjOJmQRTB9436so3F5SrIQv/NV07xrHieLs63rnup2k/lnj+f3te9btJsWqbyk1814HRXney+TQV/PzD1yDSBpKubaumzNiCFa3i7my/GvwQfPlCfYgrs9yk1agyJLXMhTu+ubkh/uXtL68/9tDw= MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 224aeb75-3583-4e16-3606-08d737702629 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2019 10:58:31.5932 (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: cUN4/ur43zaPeFaSnGSwY2OkMYyqbAsn+eLEPvWvbVdCovFCzt1n0e5bTpbS4UJSBsi8dIj3G4zLRX4r0gjntSGbns/b5a4CQM1LTl/i4vc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2973 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-12_05:2019-09-11,2019-09-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909120116 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add registers defines required for driving chip i2c master ip. Add MPU9xxx magnetometer scan elements and update data bytes size. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 56 ++++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 7cfd3a05c144..04215bc6e8ab 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -164,9 +164,41 @@ struct inv_mpu6050_state { #define INV_MPU6050_REG_ACCEL_CONFIG 0x1C #define INV_MPU6050_REG_FIFO_EN 0x23 +#define INV_MPU6050_BIT_SLAVE_0 0x01 +#define INV_MPU6050_BIT_SLAVE_1 0x02 +#define INV_MPU6050_BIT_SLAVE_2 0x04 #define INV_MPU6050_BIT_ACCEL_OUT 0x08 #define INV_MPU6050_BITS_GYRO_OUT 0x70 +#define INV_MPU6050_REG_I2C_MST_CTRL 0x24 +#define INV_MPU6050_BITS_I2C_MST_CLK_400KHZ 0x0D +#define INV_MPU6050_BIT_I2C_MST_P_NSR 0x10 +#define INV_MPU6050_BIT_SLV3_FIFO_EN 0x20 +#define INV_MPU6050_BIT_WAIT_FOR_ES 0x40 +#define INV_MPU6050_BIT_MULT_MST_EN 0x80 + +/* control I2C slaves from 0 to 3 */ +#define INV_MPU6050_REG_I2C_SLV_ADDR(_x) (0x25 + 3 * (_x)) +#define INV_MPU6050_BIT_I2C_SLV_RNW 0x80 + +#define INV_MPU6050_REG_I2C_SLV_REG(_x) (0x26 + 3 * (_x)) + +#define INV_MPU6050_REG_I2C_SLV_CTRL(_x) (0x27 + 3 * (_x)) +#define INV_MPU6050_BIT_SLV_GRP 0x10 +#define INV_MPU6050_BIT_SLV_REG_DIS 0x20 +#define INV_MPU6050_BIT_SLV_BYTE_SW 0x40 +#define INV_MPU6050_BIT_SLV_EN 0x80 + +/* I2C master delay register */ +#define INV_MPU6050_REG_I2C_SLV4_CTRL 0x34 +#define INV_MPU6050_BITS_I2C_MST_DLY(_x) ((_x) & 0x1F) + +#define INV_MPU6050_REG_I2C_MST_STATUS 0x36 +#define INV_MPU6050_BIT_I2C_SLV0_NACK 0x01 +#define INV_MPU6050_BIT_I2C_SLV1_NACK 0x02 +#define INV_MPU6050_BIT_I2C_SLV2_NACK 0x04 +#define INV_MPU6050_BIT_I2C_SLV3_NACK 0x08 + #define INV_MPU6050_REG_INT_ENABLE 0x38 #define INV_MPU6050_BIT_DATA_RDY_EN 0x01 #define INV_MPU6050_BIT_DMP_INT_EN 0x02 @@ -179,6 +211,18 @@ struct inv_mpu6050_state { #define INV_MPU6050_BIT_FIFO_OVERFLOW_INT 0x10 #define INV_MPU6050_BIT_RAW_DATA_RDY_INT 0x01 +#define INV_MPU6050_REG_EXT_SENS_DATA 0x49 + +/* I2C slaves data output from 0 to 3 */ +#define INV_MPU6050_REG_I2C_SLV_DO(_x) (0x63 + (_x)) + +#define INV_MPU6050_REG_I2C_MST_DELAY_CTRL 0x67 +#define INV_MPU6050_BIT_I2C_SLV0_DLY_EN 0x01 +#define INV_MPU6050_BIT_I2C_SLV1_DLY_EN 0x02 +#define INV_MPU6050_BIT_I2C_SLV2_DLY_EN 0x04 +#define INV_MPU6050_BIT_I2C_SLV3_DLY_EN 0x08 +#define INV_MPU6050_BIT_DELAY_ES_SHADOW 0x80 + #define INV_MPU6050_REG_USER_CTRL 0x6A #define INV_MPU6050_BIT_FIFO_RST 0x04 #define INV_MPU6050_BIT_DMP_RST 0x08 @@ -206,6 +250,9 @@ struct inv_mpu6050_state { #define INV_MPU6050_BYTES_PER_3AXIS_SENSOR 6 #define INV_MPU6050_FIFO_COUNT_BYTE 2 +/* MPU9X50 9-axis magnetometer */ +#define INV_MPU9X50_BYTES_MAGN 7 + /* ICM20602 FIFO samples include temperature readings */ #define INV_ICM20602_BYTES_PER_TEMP_SENSOR 2 @@ -233,8 +280,8 @@ struct inv_mpu6050_state { #define INV_ICM20602_TEMP_OFFSET 8170 #define INV_ICM20602_TEMP_SCALE 3060 -/* 6 + 6 round up and plus 8 */ -#define INV_MPU6050_OUTPUT_DATA_SIZE 24 +/* 6 + 6 + 7 (for MPU9x50) = 19 round up to 24 and plus 8 */ +#define INV_MPU6050_OUTPUT_DATA_SIZE 32 #define INV_MPU6050_REG_INT_PIN_CFG 0x37 #define INV_MPU6050_ACTIVE_HIGH 0x00 @@ -283,6 +330,11 @@ enum inv_mpu6050_scan { INV_MPU6050_SCAN_GYRO_Y, INV_MPU6050_SCAN_GYRO_Z, INV_MPU6050_SCAN_TIMESTAMP, + + INV_MPU9X50_SCAN_MAGN_X = INV_MPU6050_SCAN_GYRO_Z + 1, + INV_MPU9X50_SCAN_MAGN_Y, + INV_MPU9X50_SCAN_MAGN_Z, + INV_MPU9X50_SCAN_TIMESTAMP, }; /* scan element definition for ICM20602, which includes temperature */ From patchwork Thu Sep 12 10:58:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11142787 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 34F2B1599 for ; Thu, 12 Sep 2019 10:58:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08B3B214AF for ; Thu, 12 Sep 2019 10:58:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="oQfYwO29"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="HpX9mFLB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731291AbfILK6i (ORCPT ); Thu, 12 Sep 2019 06:58:38 -0400 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:18766 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730811AbfILK6i (ORCPT ); Thu, 12 Sep 2019 06:58:38 -0400 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 x8CAtDPJ012944; Thu, 12 Sep 2019 03:58:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt1; bh=5mSFPzjXvF2DWpr+b2NK78N6s6olmW8sHyGEuxIcapE=; b=oQfYwO29BZo6mHzyskjRrG/fuYuQhuDNvZGmbg0YGHeS1gbKRkqbXaY+I1LLc04eY2YU QTv4uxAXv67HE9Ku8LmQIhKV+8aaDR2BS6hGE6nLroe0gebqiQGC2I+hpqyAV0EmqXXQ /AJhtFs0sJsbRDxYDlowfR81dWgNrrJQGzWNX2zzUaXAvvYnoiI6Ie9UcQDpzXcCFyyq tJQSNbWrvBI2cncHBDU4SlIpJ2MqhU9dUZTkmbgZfTej0ecW6V/zrszjRpWL0fhYweXF yndIKvztWFbdgE4M/b4iQCM/JPKWrN+/RV9zfbLc3aNLaYmO53YIRpiwFiUKhcuEeTtU HA== Received: from nam05-dm3-obe.outbound.protection.outlook.com (mail-dm3nam05lp2054.outbound.protection.outlook.com [104.47.49.54]) by mx0b-00328301.pphosted.com with ESMTP id 2uv8gn2s9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2019 03:58:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BoSibjYyxf+yUhJLdk7IosG58aXesdPuUo2LMM4lQhoyg33lM4Se+J/w34bbaJBjj+pfEXUWHqvgqWnphURFc+Im0KH8inHXxqqgRQETKgQqkBOwBmsL4s3UNtts4XyUaA8AnvEJSohWfXoxrJ9mAHBoOAWoSgNvJqGOYaC4jaS+qM88rm+WWIhLY8HBkg9vwFrMvcTEfmEjCSza2R3Ur5dUr6qe1trM/yQ6+TsvEwTwKZjFpvQXHvtbs0zFAfnCF3aFYcmRb3IeIq+wcSPPCO4/vHCvCASRczBrAHQj6RFSmwrTwUnNsdyQrERQVe1U+uO+cWaaHLvVO/p1/sw6Yw== 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=5mSFPzjXvF2DWpr+b2NK78N6s6olmW8sHyGEuxIcapE=; b=ApcDsRPk5KbshYkAmk6T//Ox8gAwf4K9l4usBphpjVpcQJstWcDVpxk0fFnN/n6FBxsPvBIJDWX1xTYxiTT8IrB3YIwUCiL+zvQzjSygtvxxO6CYc9BIY5knzPBfT++1xEf+zlG4shBhNYI47yyaEBOBYEYsUJb3Bhqa5kI023Vhs4zeg54Wv7EFJbw5vAhKOo1WcDIIWh61MBjtV5l96kfY6nKw+9WWa5zz35C11JRGIXYBJNev+5P7nccRpSyZJ8d2fgDWcsRpaSQsyzc/HdHot35WerlTl1LX2Aki7jPVxlfE+Npv5ETAaImqYYpKxd1iIFWHu1FqQY5PdAUm7g== 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=5mSFPzjXvF2DWpr+b2NK78N6s6olmW8sHyGEuxIcapE=; b=HpX9mFLBk+zm5aVUc2hmMMTzS1g82MOsVwFXTegXYiJmPkdwZDShsXDZxClf9YLTVC+dKiARo0PjOaJgcg3uuvOaJrLbfnBHHdXEd3PiKdGENUpx6j482Jz1fjHecIFqqkOMUiQ3yAtXL9/6mgSmc4F0A4oZln16XzhGl3oy4kw= Received: from MN2PR12MB3373.namprd12.prod.outlook.com (20.178.242.33) by MN2PR12MB2911.namprd12.prod.outlook.com (20.179.80.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.15; Thu, 12 Sep 2019 10:58:33 +0000 Received: from MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166]) by MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166%5]) with mapi id 15.20.2241.018; Thu, 12 Sep 2019 10:58:33 +0000 From: Jean-Baptiste Maneyrol To: "jic23@kernel.org" CC: "linux-iio@vger.kernel.org" , Jean-Baptiste Maneyrol Subject: [PATCH v2 4/7] iio: imu: inv_mpu6050: fix objects syntax in Makefile Thread-Topic: [PATCH v2 4/7] iio: imu: inv_mpu6050: fix objects syntax in Makefile Thread-Index: AQHVaVkEobZ2UimBLk688fmzqwhfpg== Date: Thu, 12 Sep 2019 10:58:33 +0000 Message-ID: <20190912105804.15650-4-jmaneyrol@invensense.com> References: <20190912105804.15650-1-jmaneyrol@invensense.com> In-Reply-To: <20190912105804.15650-1-jmaneyrol@invensense.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) x-originating-ip: [77.157.193.39] x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 841a6b37-51e1-400f-52f4-08d7377026ff x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MN2PR12MB2911; x-ms-traffictypediagnostic: MN2PR12MB2911: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2449; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39840400004)(366004)(396003)(376002)(136003)(346002)(199004)(189003)(86362001)(6116002)(4744005)(3846002)(99286004)(54906003)(2351001)(1076003)(81166006)(81156014)(8676002)(71190400001)(71200400001)(14454004)(476003)(446003)(36756003)(25786009)(80792005)(52116002)(11346002)(2616005)(256004)(486006)(6436002)(478600001)(76176011)(386003)(53936002)(305945005)(66066001)(6512007)(8936002)(6486002)(26005)(5640700003)(6916009)(102836004)(6506007)(2906002)(107886003)(50226002)(316002)(2501003)(5660300002)(66946007)(4326008)(66446008)(64756008)(66556008)(66476007)(7736002)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB2911;H:MN2PR12MB3373.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-message-info: JMctpO/LQj2SIaTbas4bS5q/g5VK+Eu6zmIK8TbHrAN4H3IhWmb58uWJc0JDqAasID0vThKrTKRrAG+8kdxjA+YkMizg9Vj6vR2abxsrfgKSnxyaLAXbjetUijgYZHEB5Vrpdjtv5nfZS9hBtHmwnxBxbOvjjSdIQlEI2uv6NA5+G5OuE4tvxhTXPBSgskGkg5CB/hO67Ukmd9aoacWYnOudA+cWk0kyyhnYFSablHFnQVuwUhX7mRZ33CO0qXgoQiY6YTM87Mv9QARmt41kAgy2Ur8/yEv2bTzMTiN+dGToBiufHy2Su/oA9QnTkqN2XpzsZD/ReZOScrItGsvFxayhyjMPo82VyPi1pLaqFVg7SqIKyqlvbmZcgRIKRcH5+vnvdI4lLaVuEgKZMNamDJ51BMHgyzhCJvuCHhvRVck= MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 841a6b37-51e1-400f-52f4-08d7377026ff X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2019 10:58:33.2493 (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: MjvKJEtQTserxjithNy8k1DZbixQif3F18EQCzkvF2cnzXW0b5ol9u/IblqwftGLc94L+0jKcFFv2cxbsfzh24tAYroAvwihRt8F6//CRSg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2911 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-12_05:2019-09-11,2019-09-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=937 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909120116 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use the correct syntax *-y for declaring object files. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/Makefile b/drivers/iio/imu/inv_mpu6050/Makefile index 70ffe0d13d8c..33bec09fee9b 100644 --- a/drivers/iio/imu/inv_mpu6050/Makefile +++ b/drivers/iio/imu/inv_mpu6050/Makefile @@ -4,10 +4,10 @@ # obj-$(CONFIG_INV_MPU6050_IIO) += inv-mpu6050.o -inv-mpu6050-objs := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o +inv-mpu6050-y := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o obj-$(CONFIG_INV_MPU6050_I2C) += inv-mpu6050-i2c.o -inv-mpu6050-i2c-objs := inv_mpu_i2c.o inv_mpu_acpi.o +inv-mpu6050-i2c-y := inv_mpu_i2c.o inv_mpu_acpi.o obj-$(CONFIG_INV_MPU6050_SPI) += inv-mpu6050-spi.o -inv-mpu6050-spi-objs := inv_mpu_spi.o +inv-mpu6050-spi-y := inv_mpu_spi.o From patchwork Thu Sep 12 10:58:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11142789 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 B83A6184E for ; Thu, 12 Sep 2019 10:58:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C168214AF for ; Thu, 12 Sep 2019 10:58:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="eWmred04"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="XTNdG4zp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731292AbfILK6j (ORCPT ); Thu, 12 Sep 2019 06:58:39 -0400 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:19204 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731284AbfILK6i (ORCPT ); Thu, 12 Sep 2019 06:58:38 -0400 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 x8CAtDPK012944; Thu, 12 Sep 2019 03:58:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt1; bh=EkrbfUdO/rrNl3ayqxA+zOH+OAKS1db9sjlwB9x4RHs=; b=eWmred045j2PuOemO9sKq1VWnhRgFoFDnDn8PEfojuFDZ+Mm3On5x0IVVb5JJoV6erqG PV7xXUzThtzjA5TGx7UorJtKyorgbHseZ9J7gCRqI/lCTIHN3Fngi9HeCz9JKRQvGZM/ fJeM3z2BK8TdHg00G9/K6jxN9+pEnWbs79WdwG9+lZw7c5L7DE9/zWBjgkQPyqxwHvWP VZ9EDZVYz00fKoRlzek9cUmbEtHojA1mL21yzJdGcMC6b893iOpezk0tq7N+IP6jwO4K PCYwvxRMun8ZOeDUsiJ/XqlOqD1vuoD2zIAmhUCwc3voEjSuygBw3tHlMV1LP7iHg3uV CA== Received: from nam05-dm3-obe.outbound.protection.outlook.com (mail-dm3nam05lp2054.outbound.protection.outlook.com [104.47.49.54]) by mx0b-00328301.pphosted.com with ESMTP id 2uv8gn2s9r-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2019 03:58:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JAEfspsUkWGD/wpN0belHsr8e6pd6zRdaj29YWxBz0Hsw0xV/FQHcgyaiG3mMbO12y4YpDLIyZYjbVK6obuSs112FSDnj7SGUjJlv/ZrUzRaLO6WRgMSTRxQOV0BTWOAkruX8HkYgPBSMzYrE67jZ0oqWizQJWQ52tCuAZPuLCHx+rhNB3SFoXjHnhMui3Sivjuh81CmMfEqw9MgitnYRlU5Bor5SryKXYKO5tWV2bXYcnvVVbzWVofj0PmcEK7G0PC2Bm/73s48o98KM2zci6YkZjlgWWdBuKhrlOMfqAahGnaOAWHFr4CnpxeU4umSAPQRvdp5HkA/jDR98iQ/Ig== 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=EkrbfUdO/rrNl3ayqxA+zOH+OAKS1db9sjlwB9x4RHs=; b=n3ksn8ZfebrCzOpTtyA2DDQpkLFeMnPKrvraXzaYx7tmnGoq/1SGxPd5AB0eUputAbc9VYBSlTns/6w/vH1LXiX75kcyjRhyTuBzyzx0ot3L5oF49CQGZCVOovpT038hwNWJ0WJVTlAEdDOwkKZ1bMiG8TfJRlpTQevNf++7yF10wvN6mvyg8CLvmCJBccSEugzTgRTT8TajZZ9R5VzSDAjIX4l2itb6/If/VyNPypBOoEoG8JPMAE0ZpKx5MjYeZl3BJQrXgN83I67MOOa1o1R5eIMWgDM6XTQh0XJcDhM0FfFAvwKIv6ugHyIeSgIv/7PHJ3KH1TzDh7nBTs2xxQ== 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=EkrbfUdO/rrNl3ayqxA+zOH+OAKS1db9sjlwB9x4RHs=; b=XTNdG4zp0fMNuEv+CXT1SzLPkS8PtOeboiInJAfT7Y+GGUv0/IVquVOdrdTwDTYC4y3aUaJu++vphvyMS3NDU7h1K68hdmET+g/gVcI6SE2simzd/8rbEauWEGdUBZV00m26VHIxc3ORAMb0/Vv4PN3kXuRdrCJrS67uBDLQhx8= Received: from MN2PR12MB3373.namprd12.prod.outlook.com (20.178.242.33) by MN2PR12MB2911.namprd12.prod.outlook.com (20.179.80.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.15; Thu, 12 Sep 2019 10:58:34 +0000 Received: from MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166]) by MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166%5]) with mapi id 15.20.2241.018; Thu, 12 Sep 2019 10:58:34 +0000 From: Jean-Baptiste Maneyrol To: "jic23@kernel.org" CC: "linux-iio@vger.kernel.org" , Jean-Baptiste Maneyrol Subject: [PATCH v2 5/7] iio: imu: inv_mpu6050: helpers for using i2c master on auxiliary bus Thread-Topic: [PATCH v2 5/7] iio: imu: inv_mpu6050: helpers for using i2c master on auxiliary bus Thread-Index: AQHVaVkFN2zI+sFPv0CoakMxw8BnLA== Date: Thu, 12 Sep 2019 10:58:34 +0000 Message-ID: <20190912105804.15650-5-jmaneyrol@invensense.com> References: <20190912105804.15650-1-jmaneyrol@invensense.com> In-Reply-To: <20190912105804.15650-1-jmaneyrol@invensense.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) x-originating-ip: [77.157.193.39] x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9fc387d2-b379-4bc2-2341-08d737702800 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MN2PR12MB2911; x-ms-traffictypediagnostic: MN2PR12MB2911: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39840400004)(366004)(396003)(376002)(136003)(346002)(199004)(189003)(86362001)(6116002)(3846002)(99286004)(54906003)(2351001)(1076003)(81166006)(81156014)(8676002)(71190400001)(71200400001)(14454004)(476003)(446003)(36756003)(25786009)(80792005)(52116002)(11346002)(2616005)(14444005)(256004)(486006)(6436002)(478600001)(76176011)(386003)(53936002)(305945005)(66066001)(6512007)(8936002)(6486002)(26005)(5640700003)(6916009)(102836004)(6506007)(2906002)(107886003)(50226002)(316002)(2501003)(5660300002)(66946007)(4326008)(66446008)(64756008)(66556008)(66476007)(7736002)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB2911;H:MN2PR12MB3373.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-message-info: +a4AXS5QfOwtBILhlT2rntp0qpmUumFelCdd8oBxxA/JPiuLQjOdf+Lm3PsYA940o163jt01oaZygjVenWpb+1icYrJRmU0YqzfGniJiJ95598pZS/TcoUBWTEMBm8esgUhrqzwli6OnOyGfqmrE434bQGDfj8HZAWMVqwcD0MHnVlQ90VPtoX0I76KezVfUybZM0KyqD69AxJC7i7xBsZHQb3u9OTL1OjwE4ztt+JYQA8VVAFmUjhNexl9HmYgrl6V6GRyldIdwY5JncoDfu6nPJ/rKk5km0zihMNeOMA4V9sin21fpKMfP246+ttQWMpBbmrylQ6VO6TC88McldvJ5U3oPiOjyvWl+u8B8JKOrIbJAT01FXVPN7sdCFHenAwogkrSMIsrRw80PPqfYg3tdBCGwSQ7ZouIXs4aaTLo= MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fc387d2-b379-4bc2-2341-08d737702800 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2019 10:58:34.6575 (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: NIRbVb1LkRwgq/S0/WiyfhADETy9bvHEIVuFFVaDFYWN/ohHalDkVAyEyqVzjrwwtjEcbqx9Csxr6vWU8RVXJM6n9xc8DhPOPhZ7zCjr12Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2911 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-12_05:2019-09-11,2019-09-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909120116 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add helper functions to use the i2c auxiliary bus with the MPU i2c master block. Support only register based chip, reading and 1 byte writing. These will be useful for initializing magnetometers inside MPU9x50 chips. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/Makefile | 3 +- drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c | 184 ++++++++++++++++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_aux.h | 46 ++++++ 3 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c create mode 100644 drivers/iio/imu/inv_mpu6050/inv_mpu_aux.h diff --git a/drivers/iio/imu/inv_mpu6050/Makefile b/drivers/iio/imu/inv_mpu6050/Makefile index 33bec09fee9b..2cfbd926522f 100644 --- a/drivers/iio/imu/inv_mpu6050/Makefile +++ b/drivers/iio/imu/inv_mpu6050/Makefile @@ -4,7 +4,8 @@ # obj-$(CONFIG_INV_MPU6050_IIO) += inv-mpu6050.o -inv-mpu6050-y := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o +inv-mpu6050-y := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o \ + inv_mpu_aux.o obj-$(CONFIG_INV_MPU6050_I2C) += inv-mpu6050-i2c.o inv-mpu6050-i2c-y := inv_mpu_i2c.o inv_mpu_acpi.o diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c new file mode 100644 index 000000000000..b4907c1a8bb6 --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.c @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 TDK-InvenSense, Inc. + */ + +#include +#include +#include +#include + +#include "inv_mpu_iio.h" + +/* + * i2c master auxiliary bus transfer function. + * Requires the i2c operations to be correctly setup before. + */ +static int inv_mpu_i2c_master_xfer(const struct inv_mpu6050_state *st) +{ + /* use 50hz frequency for xfer */ + const unsigned int freq = 50; + const unsigned int period_ms = 1000 / freq; + uint8_t d; + unsigned int user_ctrl; + int ret; + + /* set sample rate */ + d = INV_MPU6050_FIFO_RATE_TO_DIVIDER(freq); + ret = regmap_write(st->map, st->reg->sample_rate_div, d); + if (ret) + return ret; + + /* start i2c master */ + user_ctrl = st->chip_config.user_ctrl | INV_MPU6050_BIT_I2C_MST_EN; + ret = regmap_write(st->map, st->reg->user_ctrl, user_ctrl); + if (ret) + goto error_restore_rate; + + /* wait for xfer: 1 period + half-period margin */ + msleep(period_ms + period_ms / 2); + + /* stop i2c master */ + user_ctrl = st->chip_config.user_ctrl; + ret = regmap_write(st->map, st->reg->user_ctrl, user_ctrl); + if (ret) + goto error_stop_i2c; + + /* restore sample rate */ + d = st->chip_config.divider; + ret = regmap_write(st->map, st->reg->sample_rate_div, d); + if (ret) + goto error_restore_rate; + + return 0; + +error_stop_i2c: + regmap_write(st->map, st->reg->user_ctrl, st->chip_config.user_ctrl); +error_restore_rate: + regmap_write(st->map, st->reg->sample_rate_div, st->chip_config.divider); + return ret; +} + +int inv_mpu_aux_init(const struct inv_mpu6050_state *st) +{ + unsigned int val; + int ret; + + /* configure i2c master */ + val = INV_MPU6050_BITS_I2C_MST_CLK_400KHZ | + INV_MPU6050_BIT_WAIT_FOR_ES; + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_MST_CTRL, val); + if (ret) + return ret; + + /* configure i2c master delay */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV4_CTRL, 0); + if (ret) + return ret; + + val = INV_MPU6050_BIT_I2C_SLV0_DLY_EN | + INV_MPU6050_BIT_I2C_SLV1_DLY_EN | + INV_MPU6050_BIT_I2C_SLV2_DLY_EN | + INV_MPU6050_BIT_I2C_SLV3_DLY_EN | + INV_MPU6050_BIT_DELAY_ES_SHADOW; + return regmap_write(st->map, INV_MPU6050_REG_I2C_MST_DELAY_CTRL, val); +} + +/* + * i2c slave reading using SLV0 + */ +int inv_mpu_aux_read(const struct inv_mpu6050_state *st, uint8_t addr, + uint8_t reg, uint8_t *val, size_t size) +{ + unsigned int status; + int ret; + + if (size > 0x0F) + return -EINVAL; + + /* setup i2c SLV0 control: i2c addr, register, enable + size */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_ADDR(0), + INV_MPU6050_BIT_I2C_SLV_RNW | addr); + if (ret) + return ret; + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_REG(0), reg); + if (ret) + return ret; + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(0), + INV_MPU6050_BIT_SLV_EN | size); + if (ret) + return ret; + + /* do i2c xfer */ + ret = inv_mpu_i2c_master_xfer(st); + if (ret) + goto error_disable_i2c; + + /* disable i2c slave */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(0), 0); + if (ret) + goto error_disable_i2c; + + /* check i2c status */ + ret = regmap_read(st->map, INV_MPU6050_REG_I2C_MST_STATUS, &status); + if (ret) + return ret; + if (status & INV_MPU6050_BIT_I2C_SLV0_NACK) + return -EIO; + + /* read data in registers */ + return regmap_bulk_read(st->map, INV_MPU6050_REG_EXT_SENS_DATA, + val, size); + +error_disable_i2c: + regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(0), 0); + return ret; +} + +/* + * i2c slave writing 1 byte using SLV0 + */ +int inv_mpu_aux_write(const struct inv_mpu6050_state *st, uint8_t addr, + uint8_t reg, uint8_t val) +{ + unsigned int status; + int ret; + + /* setup i2c SLV0 control: i2c addr, register, value, enable + size */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_ADDR(0), addr); + if (ret) + return ret; + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_REG(0), reg); + if (ret) + return ret; + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_DO(0), val); + if (ret) + return ret; + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(0), + INV_MPU6050_BIT_SLV_EN | 1); + if (ret) + return ret; + + /* do i2c xfer */ + ret = inv_mpu_i2c_master_xfer(st); + if (ret) + goto error_disable_i2c; + + /* disable i2c slave */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(0), 0); + if (ret) + goto error_disable_i2c; + + /* check i2c status */ + ret = regmap_read(st->map, INV_MPU6050_REG_I2C_MST_STATUS, &status); + if (ret) + return ret; + if (status & INV_MPU6050_BIT_I2C_SLV0_NACK) + return -EIO; + + return 0; + +error_disable_i2c: + regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(0), 0); + return ret; +} diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.h new file mode 100644 index 000000000000..bae4eab58e6c --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_aux.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2019 TDK-InvenSense, Inc. + */ + +#ifndef INV_MPU_AUX_H_ +#define INV_MPU_AUX_H_ + +#include + +#include "inv_mpu_iio.h" + +/** + * inv_mpu_aux_init() - init i2c auxiliary bus + * @st: driver internal state + * + * Returns 0 on success, a negative error code otherwise. + */ +int inv_mpu_aux_init(const struct inv_mpu6050_state *st); + +/** + * inv_mpu_aux_read() - read register function for i2c auxiliary bus + * @st: driver internal state. + * @addr: chip i2c Address + * @reg: chip register address + * @val: buffer for storing read bytes + * @size: number of bytes to read + * + * Returns 0 on success, a negative error code otherwise. + */ +int inv_mpu_aux_read(const struct inv_mpu6050_state *st, uint8_t addr, + uint8_t reg, uint8_t *val, size_t size); + +/** + * inv_mpu_aux_write() - write register function for i2c auxiliary bus + * @st: driver internal state. + * @addr: chip i2c Address + * @reg: chip register address + * @val: 1 byte value to write + * + * Returns 0 on success, a negative error code otherwise. + */ +int inv_mpu_aux_write(const struct inv_mpu6050_state *st, uint8_t addr, + uint8_t reg, uint8_t val); + +#endif /* INV_MPU_AUX_H_ */ From patchwork Thu Sep 12 10:58:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11142793 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 2D4111599 for ; Thu, 12 Sep 2019 10:58:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E126721479 for ; Thu, 12 Sep 2019 10:58:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="kphYfYwA"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="UY8hsiIE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731324AbfILK6n (ORCPT ); Thu, 12 Sep 2019 06:58:43 -0400 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:20132 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731294AbfILK6m (ORCPT ); Thu, 12 Sep 2019 06:58:42 -0400 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 x8CAt1io012325; Thu, 12 Sep 2019 03:58:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt1; bh=8GWKfZDi3BOUIwnrimpfRqeOg+WJDaylDOMJs6xHCgU=; b=kphYfYwAUj6TfGpMfTEVk5k7PyWirovFcAkHucwGO2K/xEf8/U4YUfJRVp9lg44oaXF/ 7iyTRDn8bvk6xlGvUlP6yvQ9yyS3s/Tq+gPgqffulxpdUKPavNL9CIQ/rnIzVvYGinq2 HEa0YBZPaeOdN9ubT+HubUWlzWJonW1aUWfVfHGiN6UJeKHIMAy4QzSlSfogIu3Gnvh9 rYLsVaAz06tQmYHwZBELFha7xf+8/pPNhDCHcS464f+NZ/7icWUPKJ3WKoZnGk2XUxFe 6tacCN9eDoErweSrdObPv1qpRItNlMg6MTsff2udDeIlzg9XyBz9HI/DH2toVR9jxB3E KA== Received: from nam05-dm3-obe.outbound.protection.outlook.com (mail-dm3nam05lp2051.outbound.protection.outlook.com [104.47.49.51]) by mx0b-00328301.pphosted.com with ESMTP id 2uv8gn2s9u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2019 03:58:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L5orphf+KlbHB7N5jOzH+KK5dm/TDt9Dq+11dKU1r2iXh9ke8rX9EI16UpjqIccIm5KcwmvpVX7/zEkjwvLL7ym4OdqymwJ+gbjQ2ju7brVdgbMFnua+PDQHozbnhsQALRQRRLnEhRBwQIu0LTdlUgzC3fuufmkmFrzDtkBIeVhzlS6IIoJMj6RiBCeVr04nZUhJSZFM5c4BatoYUYTY3EfrTU4xE/zAYuYob3Q0u2NoZP4Qa77BDl5NMWB/yx36cecVvs/78oPd+3m8KZqKQ0vVS+IYZBiszKwpmcPLTEMx7inPqZdFMigvIbawv5SgJLbcVxoUzz4rIxvRk4YGJw== 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=8GWKfZDi3BOUIwnrimpfRqeOg+WJDaylDOMJs6xHCgU=; b=eT9Q6/nbWgMJe0YVuR8zo3iBA8+lpZBQisUqZksWlI4zeGjMokf+e8oSTOgsjSVyXTOr5PtlD+0X5eNHGbcZ94QYjCpkbh0TvERK4EDyPLP1PTuw/Xm58WI81w9dFJKPw6Wfe19qzAzyAV7Cg1qC7MyoRQc7g/sEaC5fPFeLc9YUzzw2NexhnlJZerWdNTZSWi8Ia9Q2VF0mXWKczq6dsqnSrM6h6AsqhctOJ8RBTR1bCEV4OXW+Wqd3isR0WkGpwweMOP55OCWPQMVNoKbUOPLpT6g2f0f5uLcvPLDYJvsPodxQly+JNDE5sZdYLwmWKDcDKr0NO0Nyq1CrC5mGgg== 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=8GWKfZDi3BOUIwnrimpfRqeOg+WJDaylDOMJs6xHCgU=; b=UY8hsiIEONB9wLzEKpxL/GhV+IWSiQDxkeUQsyM+IPobFrhlPok0pK9y3k5s/isvb+CfUly6ECJDRJErDz2H+misTRSizzSrJ8jcz8Brc+3IPqUSgHaHaiTu1ELzzKi9TKHPExisgj30b5ktNhfU0U9PtXG8pLHFwW82OXAUqAQ= Received: from MN2PR12MB3373.namprd12.prod.outlook.com (20.178.242.33) by MN2PR12MB2911.namprd12.prod.outlook.com (20.179.80.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.15; Thu, 12 Sep 2019 10:58:36 +0000 Received: from MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166]) by MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166%5]) with mapi id 15.20.2241.018; Thu, 12 Sep 2019 10:58:36 +0000 From: Jean-Baptiste Maneyrol To: "jic23@kernel.org" CC: "linux-iio@vger.kernel.org" , Jean-Baptiste Maneyrol Subject: [PATCH v2 6/7] iio: imu: inv_mpu6050: add MPU925x magnetometer support Thread-Topic: [PATCH v2 6/7] iio: imu: inv_mpu6050: add MPU925x magnetometer support Thread-Index: AQHVaVkG052q11dNIkq4KAkIiMgs1w== Date: Thu, 12 Sep 2019 10:58:36 +0000 Message-ID: <20190912105804.15650-6-jmaneyrol@invensense.com> References: <20190912105804.15650-1-jmaneyrol@invensense.com> In-Reply-To: <20190912105804.15650-1-jmaneyrol@invensense.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) x-originating-ip: [77.157.193.39] x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5b20a485-87d1-41a2-89c8-08d7377028d8 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MN2PR12MB2911; x-ms-traffictypediagnostic: MN2PR12MB2911: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39840400004)(366004)(396003)(376002)(136003)(346002)(199004)(189003)(86362001)(6116002)(30864003)(3846002)(99286004)(54906003)(2351001)(1076003)(81166006)(81156014)(8676002)(71190400001)(71200400001)(14454004)(476003)(446003)(36756003)(25786009)(80792005)(52116002)(11346002)(2616005)(14444005)(256004)(486006)(6436002)(478600001)(76176011)(386003)(53936002)(305945005)(66066001)(53946003)(6512007)(8936002)(6486002)(26005)(5640700003)(6916009)(102836004)(6506007)(2906002)(107886003)(50226002)(316002)(2501003)(5660300002)(66946007)(4326008)(66446008)(64756008)(66556008)(66476007)(7736002)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB2911;H:MN2PR12MB3373.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-message-info: nLykvjkTsHMgE0nhoc+ttG8i5S0NDZZFjpx7sGEURffkpfJHwaXE+sdGpi+cyL6yBATu8Wv8T9JKQcvhSAZ5fmHfZRq1aQQ+8xUm7CNGzxzZVRMQt+FFw52jDUY0luU1AeUv9UGphpltVTT/chHp6o5QW7OvGp4d+zuySL5969DVq3vrUoX8yPqRVt8LCbmHVrXqjJbj5jvzUs1Vpr+nrxKvb6w+Y1NqHFE7PdmGg8IonWLZ0Id7PmAhY3aChfa4rBSVKFj/2Sr7XGsQyn0y4M4YArS95elWxZTEP3MWVWgTZCr41Wh36FA84ihLYH3KPWBSXqffWi0hsbMpEGukpvhEHYJVAlBaWcQOXZ/Kh4+X7xfS5lkqChRHPPpBWYX5Yw2A+dskbFOQI3lYijaJnQfhVG2jFtQ1uX3jr4+FoMs= MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b20a485-87d1-41a2-89c8-08d7377028d8 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2019 10:58:36.0917 (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: NLQXJBiswxzaT+8Sz+UmJRTccPervkzkOF5s6KhrniPRIETKpaxxWyovvom8eARAzhcp3z6iaRUfwU6jdbnIOxtv9M02/YcArF03lKEVOHk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2911 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-12_05:2019-09-11,2019-09-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909120116 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support of driving MPU9250 magnetometer connected on i2c auxiliary bus using the MPU i2c master. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/Makefile | 2 +- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 144 ++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 + drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c | 355 +++++++++++++++++++++ drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h | 36 +++ 5 files changed, 537 insertions(+), 4 deletions(-) create mode 100644 drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c create mode 100644 drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h diff --git a/drivers/iio/imu/inv_mpu6050/Makefile b/drivers/iio/imu/inv_mpu6050/Makefile index 2cfbd926522f..c103441a906b 100644 --- a/drivers/iio/imu/inv_mpu6050/Makefile +++ b/drivers/iio/imu/inv_mpu6050/Makefile @@ -5,7 +5,7 @@ obj-$(CONFIG_INV_MPU6050_IIO) += inv-mpu6050.o inv-mpu6050-y := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o \ - inv_mpu_aux.o + inv_mpu_aux.o inv_mpu_magn.o obj-$(CONFIG_INV_MPU6050_I2C) += inv-mpu6050-i2c.o inv-mpu6050-i2c-y := inv_mpu_i2c.o inv_mpu_acpi.o diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 7b2e4d81bbba..f1c65e0dd1a5 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -17,6 +17,7 @@ #include #include #include "inv_mpu_iio.h" +#include "inv_mpu_magn.h" /* * this is the gyro scale translated from dynamic range plus/minus @@ -332,6 +333,11 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) */ st->chip_period = NSEC_PER_MSEC; + /* 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); error_power_off: @@ -411,6 +417,9 @@ static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev, ret = inv_mpu6050_sensor_show(st, st->reg->temperature, IIO_MOD_X, val); break; + case IIO_MAGN: + ret = inv_mpu_magn_read(st, chan->channel2, val); + break; default: ret = -EINVAL; break; @@ -469,6 +478,8 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev, *val2 = INV_MPU6050_TEMP_SCALE; return IIO_VAL_INT_PLUS_MICRO; + case IIO_MAGN: + return inv_mpu_magn_get_scale(st, chan, val, val2); default: return -EINVAL; } @@ -710,6 +721,11 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, if (result) goto fifo_rate_fail_power_off; + /* update rate for magn, noop if not present in chip */ + result = inv_mpu_magn_set_rate(st, fifo_rate); + if (result) + goto fifo_rate_fail_power_off; + fifo_rate_fail_power_off: result |= inv_mpu6050_set_power_itg(st, false); fifo_rate_fail_unlock: @@ -795,8 +811,14 @@ inv_get_mount_matrix(const struct iio_dev *indio_dev, const struct iio_chan_spec *chan) { struct inv_mpu6050_state *data = iio_priv(indio_dev); + const struct iio_mount_matrix *matrix; + + if (chan->type == IIO_MAGN) + matrix = &data->magn_orient; + else + matrix = &data->orientation; - return &data->orientation; + return matrix; } static const struct iio_chan_spec_ext_info inv_ext_info[] = { @@ -864,6 +886,98 @@ static const unsigned long inv_mpu_scan_masks[] = { 0, }; +#define INV_MPU9X50_MAGN_CHAN(_chan2, _bits, _index) \ + { \ + .type = IIO_MAGN, \ + .modified = 1, \ + .channel2 = _chan2, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_RAW), \ + .scan_index = _index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = _bits, \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ + .ext_info = inv_ext_info, \ + } + +static const struct iio_chan_spec inv_mpu9250_channels[] = { + IIO_CHAN_SOFT_TIMESTAMP(INV_MPU9X50_SCAN_TIMESTAMP), + /* + * Note that temperature should only be via polled reading only, + * not the final scan elements output. + */ + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) + | BIT(IIO_CHAN_INFO_OFFSET) + | BIT(IIO_CHAN_INFO_SCALE), + .scan_index = -1, + }, + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z), + + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z), + + /* Magnetometer resolution is 16 bits */ + INV_MPU9X50_MAGN_CHAN(IIO_MOD_X, 16, INV_MPU9X50_SCAN_MAGN_X), + INV_MPU9X50_MAGN_CHAN(IIO_MOD_Y, 16, INV_MPU9X50_SCAN_MAGN_Y), + INV_MPU9X50_MAGN_CHAN(IIO_MOD_Z, 16, INV_MPU9X50_SCAN_MAGN_Z), +}; + +static const unsigned long inv_mpu9x50_scan_masks[] = { + /* 3-axis accel */ + BIT(INV_MPU6050_SCAN_ACCL_X) + | BIT(INV_MPU6050_SCAN_ACCL_Y) + | BIT(INV_MPU6050_SCAN_ACCL_Z), + /* 3-axis gyro */ + BIT(INV_MPU6050_SCAN_GYRO_X) + | BIT(INV_MPU6050_SCAN_GYRO_Y) + | BIT(INV_MPU6050_SCAN_GYRO_Z), + /* 3-axis magn */ + BIT(INV_MPU9X50_SCAN_MAGN_X) + | BIT(INV_MPU9X50_SCAN_MAGN_Y) + | BIT(INV_MPU9X50_SCAN_MAGN_Z), + /* 6-axis accel + gyro */ + BIT(INV_MPU6050_SCAN_ACCL_X) + | BIT(INV_MPU6050_SCAN_ACCL_Y) + | BIT(INV_MPU6050_SCAN_ACCL_Z) + | BIT(INV_MPU6050_SCAN_GYRO_X) + | BIT(INV_MPU6050_SCAN_GYRO_Y) + | BIT(INV_MPU6050_SCAN_GYRO_Z), + /* 6-axis accel + magn */ + BIT(INV_MPU6050_SCAN_ACCL_X) + | BIT(INV_MPU6050_SCAN_ACCL_Y) + | BIT(INV_MPU6050_SCAN_ACCL_Z) + | BIT(INV_MPU9X50_SCAN_MAGN_X) + | BIT(INV_MPU9X50_SCAN_MAGN_Y) + | BIT(INV_MPU9X50_SCAN_MAGN_Z), + /* 6-axis gyro + magn */ + BIT(INV_MPU6050_SCAN_GYRO_X) + | BIT(INV_MPU6050_SCAN_GYRO_Y) + | BIT(INV_MPU6050_SCAN_GYRO_Z) + | BIT(INV_MPU9X50_SCAN_MAGN_X) + | BIT(INV_MPU9X50_SCAN_MAGN_Y) + | BIT(INV_MPU9X50_SCAN_MAGN_Z), + /* 9-axis accel + gyro + magn */ + BIT(INV_MPU6050_SCAN_ACCL_X) + | BIT(INV_MPU6050_SCAN_ACCL_Y) + | BIT(INV_MPU6050_SCAN_ACCL_Z) + | BIT(INV_MPU6050_SCAN_GYRO_X) + | BIT(INV_MPU6050_SCAN_GYRO_Y) + | BIT(INV_MPU6050_SCAN_GYRO_Z) + | BIT(INV_MPU9X50_SCAN_MAGN_X) + | BIT(INV_MPU9X50_SCAN_MAGN_Y) + | BIT(INV_MPU9X50_SCAN_MAGN_Z), + 0, +}; + static const struct iio_chan_spec inv_icm20602_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(INV_ICM20602_SCAN_TIMESTAMP), { @@ -1145,6 +1259,11 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, return result; } + /* fill magnetometer orientation */ + result = inv_mpu_magn_set_orient(st); + if (result) + return result; + /* power is turned on inside check chip type*/ result = inv_check_and_setup_chip(st); if (result) @@ -1168,14 +1287,33 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, if (inv_mpu_bus_setup) inv_mpu_bus_setup(indio_dev); - if (chip_type == INV_ICM20602) { + switch (chip_type) { + case INV_MPU9250: + case INV_MPU9255: + /* + * Use magnetometer inside the chip only if there is no i2c + * auxiliary device in use. + */ + if (!st->magn_disabled) { + indio_dev->channels = inv_mpu9250_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu9250_channels); + indio_dev->available_scan_masks = inv_mpu9x50_scan_masks; + } else { + indio_dev->channels = inv_mpu_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels); + indio_dev->available_scan_masks = inv_mpu_scan_masks; + } + break; + case INV_ICM20602: indio_dev->channels = inv_icm20602_channels; indio_dev->num_channels = ARRAY_SIZE(inv_icm20602_channels); indio_dev->available_scan_masks = inv_icm20602_scan_masks; - } else { + break; + default: indio_dev->channels = inv_mpu_channels; indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels); indio_dev->available_scan_masks = inv_mpu_scan_masks; + break; } indio_dev->info = &mpu_info; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 04215bc6e8ab..953f85618199 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -130,6 +130,8 @@ struct inv_mpu6050_hw { * @data_timestamp: timestamp for next data sample. * @vddio_supply voltage regulator for the chip. * @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. */ struct inv_mpu6050_state { struct mutex lock; @@ -152,6 +154,8 @@ struct inv_mpu6050_state { s64 data_timestamp; struct regulator *vddio_supply; bool magn_disabled; + s32 magn_raw_to_gauss[3]; + struct iio_mount_matrix magn_orient; }; /*register and associated bit definition*/ diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c new file mode 100644 index 000000000000..415d8acece54 --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.c @@ -0,0 +1,355 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 TDK-InvenSense, Inc. + */ + +#include +#include +#include + +#include "inv_mpu_iio.h" +#include "inv_mpu_aux.h" + +/* + * MPU9250 magnetometer is an AKM AK8963 chip on I2C aux bus + */ +#define INV_MPU_MAGN_I2C_ADDR 0x0C + +#define INV_MPU_MAGN_REG_WIA 0x00 +#define INV_MPU_MAGN_BITS_WIA 0x48 + +#define INV_MPU_MAGN_REG_ST1 0x02 +#define INV_MPU_MAGN_BIT_DRDY 0x01 +#define INV_MPU_MAGN_BIT_DOR 0x02 + +#define INV_MPU_MAGN_REG_DATA 0x03 + +#define INV_MPU_MAGN_REG_ST2 0x09 +#define INV_MPU_MAGN_BIT_HOFL 0x08 +#define INV_MPU_MAGN_BIT_BITM 0x10 + +#define INV_MPU_MAGN_REG_CNTL1 0x0A +#define INV_MPU_MAGN_BITS_MODE_PWDN 0x00 +#define INV_MPU_MAGN_BITS_MODE_SINGLE 0x01 +#define INV_MPU_MAGN_BITS_MODE_FUSE 0x0F +#define INV_MPU_MAGN_BIT_OUTPUT_BIT 0x10 + +#define INV_MPU_MAGN_REG_CNTL2 0x0B +#define INV_MPU_MAGN_BIT_SRST 0x01 + +#define INV_MPU_MAGN_REG_ASAX 0x10 +#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) { + case INV_MPU9250: + case INV_MPU9255: + return true; + default: + return false; + } +} + +/* init magnetometer chip */ +static int inv_magn_init(struct inv_mpu6050_state *st) +{ + uint8_t val; + uint8_t asa[3]; + int ret; + + /* check whoami */ + ret = inv_mpu_aux_read(st, INV_MPU_MAGN_I2C_ADDR, INV_MPU_MAGN_REG_WIA, + &val, sizeof(val)); + if (ret) + return ret; + if (val != INV_MPU_MAGN_BITS_WIA) + return -ENODEV; + + /* reset chip */ + ret = inv_mpu_aux_write(st, INV_MPU_MAGN_I2C_ADDR, + INV_MPU_MAGN_REG_CNTL2, + INV_MPU_MAGN_BIT_SRST); + if (ret) + return ret; + + /* read fuse ROM data */ + ret = inv_mpu_aux_write(st, INV_MPU_MAGN_I2C_ADDR, + INV_MPU_MAGN_REG_CNTL1, + INV_MPU_MAGN_BITS_MODE_FUSE); + if (ret) + return ret; + + ret = inv_mpu_aux_read(st, INV_MPU_MAGN_I2C_ADDR, INV_MPU_MAGN_REG_ASAX, + asa, sizeof(asa)); + if (ret) + return ret; + + /* switch back to power-down */ + ret = inv_mpu_aux_write(st, INV_MPU_MAGN_I2C_ADDR, + INV_MPU_MAGN_REG_CNTL1, + INV_MPU_MAGN_BITS_MODE_PWDN); + if (ret) + return ret; + + /* + * Sensitivity adjustement and scale to Gauss + * + * Hadj = H * (((ASA - 128) * 0.5 / 128) + 1) + * Factor simplification: + * Hadj = H * ((ASA + 128) / 256) + * + * Sensor sentivity + * 0.15 uT in 16 bits mode + * 1 uT = 0.01 G and value is in micron (1e6) + * sensitvity = 0.15 uT * 0.01 * 1e6 + * + * raw_to_gauss = Hadj * 1500 + */ + st->magn_raw_to_gauss[0] = (((int32_t)asa[0] + 128) * 1500) / 256; + st->magn_raw_to_gauss[1] = (((int32_t)asa[1] + 128) * 1500) / 256; + st->magn_raw_to_gauss[2] = (((int32_t)asa[2] + 128) * 1500) / 256; + + return 0; +} + +/** + * inv_mpu_magn_probe() - probe and setup magnetometer chip + * @st: driver internal state + * + * Returns 0 on success, a negative error code otherwise + * + * It is probing the chip and setting up all needed i2c transfers. + * Noop if there is no magnetometer in the chip. + */ +int inv_mpu_magn_probe(struct inv_mpu6050_state *st) +{ + int ret; + + /* quit if chip is not supported */ + if (!inv_magn_supported(st)) + return 0; + + /* configure i2c master aux port */ + ret = inv_mpu_aux_init(st); + if (ret) + return ret; + + /* check and init mag chip */ + ret = inv_magn_init(st); + if (ret) + return ret; + + /* + * configure mpu i2c master accesses + * i2c SLV0: read sensor data, 7 bytes data(6)-ST2 + * Byte swap data to store them in big-endian in impair address groups + */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_ADDR(0), + INV_MPU6050_BIT_I2C_SLV_RNW | INV_MPU_MAGN_I2C_ADDR); + if (ret) + return ret; + + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_REG(0), + INV_MPU_MAGN_REG_DATA); + if (ret) + return ret; + + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(0), + INV_MPU6050_BIT_SLV_EN | + INV_MPU6050_BIT_SLV_BYTE_SW | + INV_MPU6050_BIT_SLV_GRP | + INV_MPU9X50_BYTES_MAGN); + if (ret) + return ret; + + /* i2c SLV1: launch single measurement */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_ADDR(1), + INV_MPU_MAGN_I2C_ADDR); + if (ret) + return ret; + + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_REG(1), + INV_MPU_MAGN_REG_CNTL1); + if (ret) + return ret; + + /* add 16 bits mode */ + ret = regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_DO(1), + INV_MPU_MAGN_BITS_MODE_SINGLE | + INV_MPU_MAGN_BIT_OUTPUT_BIT); + if (ret) + return ret; + + return regmap_write(st->map, INV_MPU6050_REG_I2C_SLV_CTRL(1), + INV_MPU6050_BIT_SLV_EN | 1); +} + +/** + * inv_mpu_magn_set_rate() - set magnetometer sampling rate + * @st: driver internal state + * @fifo_rate: mpu set fifo rate + * + * Returns 0 on success, a negative error code otherwise + * + * Limit sampling frequency to the maximum value supported by the + * magnetometer chip. Resulting in duplicated data for higher frequencies. + * Noop if there is no magnetometer in the chip. + */ +int inv_mpu_magn_set_rate(const struct inv_mpu6050_state *st, int fifo_rate) +{ + uint8_t d; + + /* quit if chip is not supported */ + if (!inv_magn_supported(st)) + return 0; + + /* + * update i2c master delay to limit mag sampling to max frequency + * compute fifo_rate divider d: rate = fifo_rate / (d + 1) + */ + if (fifo_rate > INV_MPU_MAGN_FREQ_HZ_MAX) + d = fifo_rate / INV_MPU_MAGN_FREQ_HZ_MAX - 1; + else + d = 0; + + return regmap_write(st->map, INV_MPU6050_REG_I2C_SLV4_CTRL, d); +} + +/** + * inv_mpu_magn_set_orient() - fill magnetometer mounting matrix + * @st: driver internal state + * + * Returns 0 on success, a negative error code otherwise + * + * Fill magnetometer mounting matrix using the provided chip matrix. + */ +int inv_mpu_magn_set_orient(struct inv_mpu6050_state *st) +{ + const char *orient; + char *str; + int i; + + /* fill magnetometer orientation */ + switch (st->chip_type) { + case INV_MPU9250: + case INV_MPU9255: + /* x <- y */ + st->magn_orient.rotation[0] = st->orientation.rotation[3]; + st->magn_orient.rotation[1] = st->orientation.rotation[4]; + st->magn_orient.rotation[2] = st->orientation.rotation[5]; + /* y <- x */ + st->magn_orient.rotation[3] = st->orientation.rotation[0]; + st->magn_orient.rotation[4] = st->orientation.rotation[1]; + st->magn_orient.rotation[5] = st->orientation.rotation[2]; + /* z <- -z */ + for (i = 0; i < 3; ++i) { + orient = st->orientation.rotation[6 + i]; + /* use length + 2 for adding minus sign if needed */ + str = devm_kzalloc(regmap_get_device(st->map), + strlen(orient) + 2, GFP_KERNEL); + if (str == NULL) + return -ENOMEM; + if (strcmp(orient, "0") == 0) { + strcpy(str, orient); + } else if (orient[0] == '-') { + strcpy(str, &orient[1]); + } else { + str[0] = '-'; + strcpy(&str[1], orient); + } + st->magn_orient.rotation[6 + i] = str; + } + break; + default: + st->magn_orient = st->orientation; + break; + } + + return 0; +} + +/** + * inv_mpu_magn_read() - read magnetometer data + * @st: driver internal state + * @axis: IIO modifier axis value + * @val: store corresponding axis value + * + * Returns 0 on success, a negative error code otherwise + */ +int inv_mpu_magn_read(const struct inv_mpu6050_state *st, int axis, int *val) +{ + unsigned int user_ctrl, status; + __be16 data[3]; + uint8_t addr; + uint8_t d; + unsigned int period_ms; + int ret; + + /* quit if chip is not supported */ + if (!inv_magn_supported(st)) + return -ENODEV; + + /* Mag data: X - Y - Z */ + switch (axis) { + case IIO_MOD_X: + addr = 0; + break; + case IIO_MOD_Y: + addr = 1; + break; + case IIO_MOD_Z: + addr = 2; + break; + default: + return -EINVAL; + } + + /* 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; + + /* 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); + if (ret) + 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) + return ret; + + if (status & INV_MPU6050_BIT_I2C_SLV0_NACK || + status & INV_MPU6050_BIT_I2C_SLV1_NACK) + return -EIO; + + ret = regmap_bulk_read(st->map, INV_MPU6050_REG_EXT_SENS_DATA, + data, sizeof(data)); + if (ret) + return ret; + + *val = (int16_t)be16_to_cpu(data[addr]); + + return IIO_VAL_INT; +} diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h new file mode 100644 index 000000000000..b41bd0578478 --- /dev/null +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_magn.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2019 TDK-InvenSense, Inc. + */ + +#ifndef INV_MPU_MAGN_H_ +#define INV_MPU_MAGN_H_ + +#include + +#include "inv_mpu_iio.h" + +int inv_mpu_magn_probe(struct inv_mpu6050_state *st); + +/** + * inv_mpu_magn_get_scale() - get magnetometer scale value + * @st: driver internal state + * + * Returns IIO data format. + */ +static inline int inv_mpu_magn_get_scale(const struct inv_mpu6050_state *st, + const struct iio_chan_spec *chan, + int *val, int *val2) +{ + *val = 0; + *val2 = st->magn_raw_to_gauss[chan->address]; + return IIO_VAL_INT_PLUS_MICRO; +} + +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); + +#endif /* INV_MPU_MAGN_H_ */ From patchwork Thu Sep 12 10:58:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 11142791 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 E98E6924 for ; Thu, 12 Sep 2019 10:58:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B30C6214AE for ; Thu, 12 Sep 2019 10:58:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=invensense.com header.i=@invensense.com header.b="Ee3Yks7C"; dkim=pass (1024-bit key) header.d=invensense.onmicrosoft.com header.i=@invensense.onmicrosoft.com header.b="NFLqPwFx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730811AbfILK6l (ORCPT ); Thu, 12 Sep 2019 06:58:41 -0400 Received: from mx0b-00328301.pphosted.com ([148.163.141.47]:20824 "EHLO mx0b-00328301.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731298AbfILK6l (ORCPT ); Thu, 12 Sep 2019 06:58:41 -0400 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 x8CAtDEV012938; Thu, 12 Sep 2019 03:58:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt1; bh=1+eq/nwvj82vzfIJxXfs/PzE+8W3aPtP5X/lR1mbnGM=; b=Ee3Yks7Ch+L9sBCIhSdyPROFWxLop8lhVF5I0QNeJj8pSbIs5GForIjU3DprvWxKkgC0 Og9wtmQOWEmZFsVNakk0oIfrT3f9U4h0s9MWwnJVBWO0R7E8VqidStQU8ghS9dw+3J0D CPscem9+Ol5tcanZNo9Kmt1/jaLyMkJmsD/8rD+ImVh+OJiSqqmaID56q0K8KBnjS9lc RFIYkwYzvsHoiKMy6cjaM44I19Ly2EGiVNqczNywaNRkzC2R26OJ9325kLghh+e1ox/m SpC1HUTRedY4iwjM2b9iXR0goCnvmEYizOxcFBt7md6z+HkSVIm4TdjGo7qawq9ieL8w UQ== Received: from nam05-dm3-obe.outbound.protection.outlook.com (mail-dm3nam05lp2054.outbound.protection.outlook.com [104.47.49.54]) by mx0b-00328301.pphosted.com with ESMTP id 2uv8gn2s9v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2019 03:58:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZCG3XLWq2JJuc5DdomYBOP9b30sYV758zfEijK/1NttYrjzUWfSaknBYx1drNIHqZnJm5SQ/AXgI5h4k+gQbDJFlj+Hd/p9x23KG2lsLtVZvXFANvqrBGauOyrr2VALqjhU9lmvyfwp18ppjrve4jxX7zrNW1e1rbeb4BzPtA1mnWlqRxI8NDFbjiA95KcLgoOLw3+qUBScJ5Rcf9RXrMlq8/YHWldBUR0UW00Mm9JAqopAPJ+eeVuzYi8LB9VZX8LMUc82A9V35ZxF1eFE6qWymwYGFg5XRoVLuQbmDihDdywmqb70ijLoYLXe8/YvDyL3yFChdqkNS/KGDYp/HEg== 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=1+eq/nwvj82vzfIJxXfs/PzE+8W3aPtP5X/lR1mbnGM=; b=apSf/sVWoJ5aj7jKdqAcuZZc1eHG0Cf0+JR+awRFxbpXa5kCqyqrbU2qBC4OGXP01fEHCx/FZxueRPMlgzc7QHYGl5T/AYx1rg+R4hAqmPknxI2coI5XbuzwV+Pay/w1xLaOOHjuoSFSOd1/bZHrL3TL/lp0XKLm9LUkPrVnmGK3XUUXRhpAW6c3e1oEirKDvmc6F3KJUTl1PDeku8U7qWpT6Qj1VmbRdgWP4Yp2pQoyvPj7BqOP0WJ8GTuYjLjG7qfDboB60a6z3XUOZjR1l53QeJgTxNekRQMbMsnpMRQaboBpzZKpGVLfZT3xMBzy/jm67WXikYf9o8Dqn7m64w== 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=1+eq/nwvj82vzfIJxXfs/PzE+8W3aPtP5X/lR1mbnGM=; b=NFLqPwFxieS5V/LnLW6NO76VvarUS3GMJTXN9svjJnZLEdxOEzf6LwTSWev4LcSN7zLvGgK+sENptRyreihrk+pooT/tB1Fzy+YuJ2L1c4cP3BpHysXKuZ3KtTgTcHhogpqkOg31e7rY4PmtwhDgyVkXaqo0NEVk5Ra1nsBdMCo= Received: from MN2PR12MB3373.namprd12.prod.outlook.com (20.178.242.33) by MN2PR12MB2911.namprd12.prod.outlook.com (20.179.80.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.15; Thu, 12 Sep 2019 10:58:37 +0000 Received: from MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166]) by MN2PR12MB3373.namprd12.prod.outlook.com ([fe80::256d:7ef4:1570:a166%5]) with mapi id 15.20.2241.018; Thu, 12 Sep 2019 10:58:37 +0000 From: Jean-Baptiste Maneyrol To: "jic23@kernel.org" CC: "linux-iio@vger.kernel.org" , Jean-Baptiste Maneyrol Subject: [PATCH v2 7/7] iio: imu: inv_mpu6050: add fifo support for magnetometer data Thread-Topic: [PATCH v2 7/7] iio: imu: inv_mpu6050: add fifo support for magnetometer data Thread-Index: AQHVaVkHqrNnPr7fmkeG9N0Jt7k2aw== Date: Thu, 12 Sep 2019 10:58:37 +0000 Message-ID: <20190912105804.15650-7-jmaneyrol@invensense.com> References: <20190912105804.15650-1-jmaneyrol@invensense.com> In-Reply-To: <20190912105804.15650-1-jmaneyrol@invensense.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) x-originating-ip: [77.157.193.39] x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9604de88-a289-497f-aa8c-08d7377029b5 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:MN2PR12MB2911; x-ms-traffictypediagnostic: MN2PR12MB2911: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2331; x-forefront-prvs: 01583E185C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39840400004)(366004)(396003)(376002)(136003)(346002)(199004)(189003)(86362001)(6116002)(3846002)(99286004)(54906003)(2351001)(1076003)(81166006)(81156014)(8676002)(71190400001)(71200400001)(14454004)(476003)(446003)(36756003)(25786009)(80792005)(52116002)(11346002)(2616005)(14444005)(256004)(486006)(6436002)(478600001)(76176011)(386003)(53936002)(305945005)(66066001)(6512007)(8936002)(6486002)(26005)(5640700003)(6916009)(102836004)(6506007)(2906002)(107886003)(50226002)(316002)(2501003)(5660300002)(66946007)(4326008)(66446008)(64756008)(66556008)(66476007)(7736002)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR12MB2911;H:MN2PR12MB3373.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-message-info: /r4lh655nlP5Tn854M93BwPevX85mni/ygmJB8cpgSFuiiSpbjRVt72e4W+irloyizwwTwLKe+IkGA/GyspD9AHgNydHF9NsFJlO/zdfjj5V8Bk+Qfj/lof8LNw05azIFFxiiKOsOrRaZ+xTdgq5e3iYAgLW5IoBIJIvvwvxu91soNP1evQlB5mYdNUjSPyD7FiK3EStvAi2HxRzt/75VJ+Bj46JuNrUjQVcb1mZ0OSPcouZHfEVIDhAgtTuigXnH4egW2xJWQkPbTFUJKqJLUh5VwopTC44eJ0F+7UjgKE7RhknC9+KOQ0D6YfhAzL3uCsX48xpWgD4EwqCV58S5ICF5F/oSu1K7FHjCltDbsWiSFz8zIfJfa58EE3thtUhHZZVVCFfIM67Ylh+AIgR1v2exjFZP87gGdHakpmpwnk= MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9604de88-a289-497f-aa8c-08d7377029b5 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2019 10:58:37.6118 (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: 7puslD949PsjUBbXsAe/lza3ijCKaLkjvji+nOkpVgPt7RMF5MNpPPGOi6+AJWyWamujIss/OSC4tkREi1gZdhrSvcrWJHsUxvDMYGonkp0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2911 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.70,1.0.8 definitions=2019-09-12_05:2019-09-11,2019-09-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1906280000 definitions=main-1909120116 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Put read magnetometer data by mpu inside the fifo. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 1 + drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 + drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 11 ++- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 86 ++++++++++++++++--- 4 files changed, 88 insertions(+), 12 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index f1c65e0dd1a5..354030e9bed5 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -104,6 +104,7 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = { .divider = INV_MPU6050_FIFO_RATE_TO_DIVIDER(INV_MPU6050_INIT_FIFO_RATE), .gyro_fifo_enable = false, .accl_fifo_enable = false, + .magn_fifo_enable = false, .accl_fs = INV_MPU6050_FS_02G, .user_ctrl = 0, }; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 953f85618199..52fcf45050a5 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -86,6 +86,7 @@ enum inv_devices { * @accl_fs: accel full scale range. * @accl_fifo_enable: enable accel data output * @gyro_fifo_enable: enable gyro data output + * @magn_fifo_enable: enable magn data output * @divider: chip sample rate divider (sample rate divider - 1) */ struct inv_mpu6050_chip_config { @@ -94,6 +95,7 @@ struct inv_mpu6050_chip_config { unsigned int accl_fs:2; unsigned int accl_fifo_enable:1; unsigned int gyro_fifo_enable:1; + unsigned int magn_fifo_enable:1; u8 divider; u8 user_ctrl; }; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index 5f9a5de0bab4..bbf68b474556 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -124,7 +124,8 @@ int inv_reset_fifo(struct iio_dev *indio_dev) /* enable interrupt */ if (st->chip_config.accl_fifo_enable || - st->chip_config.gyro_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) @@ -141,6 +142,8 @@ int inv_reset_fifo(struct iio_dev *indio_dev) d |= INV_MPU6050_BITS_GYRO_OUT; if (st->chip_config.accl_fifo_enable) d |= INV_MPU6050_BIT_ACCEL_OUT; + if (st->chip_config.magn_fifo_enable) + d |= INV_MPU6050_BIT_SLAVE_0; result = regmap_write(st->map, st->reg->fifo_en, d); if (result) goto reset_fifo_fail; @@ -190,7 +193,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) } if (!(st->chip_config.accl_fifo_enable | - st->chip_config.gyro_fifo_enable)) + st->chip_config.gyro_fifo_enable | + st->chip_config.magn_fifo_enable)) goto end_session; bytes_per_datum = 0; if (st->chip_config.accl_fifo_enable) @@ -202,6 +206,9 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) if (st->chip_type == INV_ICM20602) bytes_per_datum += INV_ICM20602_BYTES_PER_TEMP_SENSOR; + if (st->chip_config.magn_fifo_enable) + bytes_per_datum += INV_MPU9X50_BYTES_MAGN; + /* * read fifo_count register to know how many bytes are inside the FIFO * right now diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index dd55e70b6f77..d7d951927a44 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -5,7 +5,7 @@ #include "inv_mpu_iio.h" -static void inv_scan_query(struct iio_dev *indio_dev) +static void inv_scan_query_mpu6050(struct iio_dev *indio_dev) { struct inv_mpu6050_state *st = iio_priv(indio_dev); @@ -26,6 +26,60 @@ static void inv_scan_query(struct iio_dev *indio_dev) indio_dev->active_scan_mask); } +static void inv_scan_query_mpu9x50(struct iio_dev *indio_dev) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + inv_scan_query_mpu6050(indio_dev); + + /* no magnetometer if i2c auxiliary bus is used */ + if (st->magn_disabled) + return; + + st->chip_config.magn_fifo_enable = + test_bit(INV_MPU9X50_SCAN_MAGN_X, + indio_dev->active_scan_mask) || + test_bit(INV_MPU9X50_SCAN_MAGN_Y, + indio_dev->active_scan_mask) || + test_bit(INV_MPU9X50_SCAN_MAGN_Z, + indio_dev->active_scan_mask); +} + +static void inv_scan_query(struct iio_dev *indio_dev) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + switch (st->chip_type) { + case INV_MPU9250: + case INV_MPU9255: + return inv_scan_query_mpu9x50(indio_dev); + default: + return inv_scan_query_mpu6050(indio_dev); + } +} + +static unsigned int inv_compute_skip_samples(const struct inv_mpu6050_state *st) +{ + unsigned int gyro_skip = 0; + unsigned int magn_skip = 0; + unsigned int skip_samples; + + /* gyro first sample is out of specs, skip it */ + if (st->chip_config.gyro_fifo_enable) + gyro_skip = 1; + + /* mag first sample is always not ready, skip it */ + if (st->chip_config.magn_fifo_enable) + magn_skip = 1; + + /* compute first samples to skip */ + skip_samples = gyro_skip; + if (magn_skip > skip_samples) + skip_samples = magn_skip; + + return skip_samples; +} + /** * inv_mpu6050_set_enable() - enable chip functions. * @indio_dev: Device driver instance. @@ -34,6 +88,7 @@ static void inv_scan_query(struct iio_dev *indio_dev) 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; int result; if (enable) { @@ -41,14 +96,11 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) if (result) return result; inv_scan_query(indio_dev); - st->skip_samples = 0; 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; - /* gyro first sample is out of specs, skip it */ - st->skip_samples = 1; } if (st->chip_config.accl_fifo_enable) { result = inv_mpu6050_switch_engine(st, true, @@ -56,22 +108,32 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) 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; + } + st->skip_samples = inv_compute_skip_samples(st); result = inv_reset_fifo(indio_dev); if (result) - goto error_accl_off; + goto error_magn_off; } else { result = regmap_write(st->map, st->reg->fifo_en, 0); if (result) - goto error_accl_off; + goto error_magn_off; result = regmap_write(st->map, st->reg->int_enable, 0); if (result) - goto error_accl_off; + goto error_magn_off; - result = regmap_write(st->map, st->reg->user_ctrl, - st->chip_config.user_ctrl); + 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; + goto error_magn_off; + st->chip_config.user_ctrl = d; result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_ACCL_STBY); @@ -90,6 +152,10 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) return 0; +error_magn_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,