From patchwork Fri Mar 8 15:10:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: inv.git-commit@tdk.com X-Patchwork-Id: 13586934 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B49A1D54D for ; Fri, 8 Mar 2024 15:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.178.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910691; cv=fail; b=gPKSutZMRK27SF0AN2KJgd3KMLrEFh77/kC1rlJHfgCo3pjM4oEeGSONCs37SfheYC+YgLMHsIBEsTfnQd0GroODDyif4n7KM1nNrEIZeRoN6sWrtYIR240eV9kEkKDQ93609+Ms1GvXwBy/yYLsl9H9eCb6GiAhUigXJIGqz5c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910691; c=relaxed/simple; bh=2E3FK8MSgoRmvoufRurz5pgMZvDdeY5yCV94vkIP5F0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=IXqnKzRZDgahPc5Jtcs/ioZtT6JP0Kv7p+k7nXrMKEZSo3RUZHkX7Hv1pyZVw0UG9lE1W1tYLoLQb14TXu06c4WxzoOHPTJWSpjgP+QvH5ghgehc4Ny0BxHgGrj0ORHQyzq0Iz6/35JJmsgQZZSbfL/uSjE49Bja6XYfZndaoSc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com; spf=pass smtp.mailfrom=tdk.com; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b=GDObxaUK; arc=fail smtp.client-ip=205.220.178.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tdk.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b="GDObxaUK" Received: from pps.filterd (m0233779.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 428A25tM016412; Fri, 8 Mar 2024 15:11:03 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2105.outbound.protection.outlook.com [104.47.23.105]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wkwfjmyah-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:11:03 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cTSob9QNLJkbuIpXBFnzMbV2HXp7zn95sUo5l8yqKHwpkYyhVNNraRETi8DhSQ/XxhflGVjCMMxk2/VJQ962VmdTfMSt+DqH/j5/cfjOuQjYWwQUuS+nvZ0Ho52X6gTmNAsIi8yAVBOpQ88yvHAF6cg7Upn9CTzwaCBWjbjkccc5wLOjV1yZhRxEKagoP0Vl4Ua4OG7/I8BUgXuvGb3QvYriMTqsKOrVaroO6USurIfE3zolg4ugWLs1zrbQqIz4HsqkNOHX2JzbcOwuMpr2tlSQJCvE/Zk34psqjlnvrubxD3StAfgkyeylA8T+zxOVgi5iJe120cEn+hzcCnDkUw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=P3rwcKSGlDA1fJFaKs1sV2oBRRsupJlhcydMxPp81RQ=; b=Dtga4/V4YYuxuG7nZ8MFYyCTfGSQ3619w/PR8HtimD3VW0swAiZmYWJWfzt7lmUXnKVO+gl/7yMlK7t19082xNMzJVsyHtIHk62QnM7noxKjrcJHiiid53fJKrJBtcC5ibeblpeXw7hkNd0oEoUA3yL91A5Kd2R3alb4fqnt1/OQtW3YTXuzQacFy1plcABWNltnTn/pxTFbUlIE5p4Pb+8ZPOoLuNbPaWTHFUJ7IulFH5pb8m+HAMSRbojjIis/6M5SHMI32jjWSPNWuUPxLDwaNWmtIu6CYW+aKJ6L18agSOBeUOblcStZu8c2T1f1H+czkUb1Y0H9jXvvtqfe0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=tdk.com; dmarc=pass action=none header.from=tdk.com; dkim=pass header.d=tdk.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tdk.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P3rwcKSGlDA1fJFaKs1sV2oBRRsupJlhcydMxPp81RQ=; b=GDObxaUK67T0FB5VQRNN2/c1Nl9qt/Gyr4qYfDqF3yy2+eRdcyocnmjSM4NsfwYWAcT4LN7xeamdmUes1UAkLzce+9a/7PjaBSnLUDeEM/nv4hV/nLcbyNrF+CO4qKg6xeRTD0YJ0kCEJfMKrTQoPuFZa9PXa2AQUgSLsESNL/LjyPuu6Q2aGgcBHIrq9JZHnyY7u5S7pm/nZp2AHRjNdQ3C3ZfuvD026VpG3GfJ0noOMgadD7eHkJd2pcoiTdPWqRQTSemMYm6y7haJLtbmsfEYl6+w6sephOLDi9s9KqYY1LTk052kdYMrphY7Cn+WiKtdN76kCf0KL0mWDQ20Ww== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TY3P286MB2564.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:22c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 15:10:38 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2%5]) with mapi id 15.20.7362.024; Fri, 8 Mar 2024 15:10:38 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org Cc: lars@metafoo.de, linux-iio@vger.kernel.org, Jean-Baptiste Maneyrol Subject: [PATCH v2 1/4] iio: imu: inv_mpu6050: add WoM (Wake-on-Motion) sensor Date: Fri, 8 Mar 2024 15:10:20 +0000 Message-Id: <20240308151023.379705-2-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240308151023.379705-1-inv.git-commit@tdk.com> References: <20240308151023.379705-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO4P265CA0230.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:315::6) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TY3P286MB2564:EE_ X-MS-Office365-Filtering-Correlation-Id: 65e94755-9b03-4bcb-72e6-08dc3f81e942 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bQTpWlt08hMcRbUh6G0ECdNWgtXtEwPVCW9nGIbty3b+emPS40BSIJWHOixpfT8ogNE6bA/vcr9+mSISYAWKIOjJipXPhDyzaLnvSSW84Z2/U72GGo88Px91CpX/gH0dxjNLbFbgswUYFtygOJCPJuXje/N3Ba8buhALwMgi0bMNuCDMEMkL5m3oiU86lWAFwUfm8heAQUiFQmqt9vdFx+2n0enFFxlXD20342mY0nhHyrIGr+RyfJqWt5r0PokRf+75TuzdLyBrDti4SzfWWuhQqH3UK+U8nZU2e6H2Pl7d/jOnrcY3uYuz0CWd3XrVapVz3tcFnNhspG/Favw7zSyh+8U7b8XcC48TjHmWq6NzhPtUU2b6l+SKmagPZoJJL0NJQQ3h1u75GXvLOwYMkwH7wO5NJJ+9CIzkCjDjxcl+UVD2uDqfPaYLihPNzAMuFyQ633mPmEyvo201euu5IRJ+XMWxMHLnoRMc2J5vUhAcgLFrbkJtLxnvrS0+kE7R38SiM3N+vcm+86Am73Bz4xdWo1tpAeWeHhMcwozrSlXXotuhT5wXmPaO9kZlOiGXlpbeS05DxDV9xM8dYyUjOSEbrSSN6EwR4j0W06GlwN95G2S8ejZxEryUqhszxhvNOPCUwzabjb5B1UdwQiRrgnzsPDr+dyF0uohJej5lgzbuWDGyn9kDXOkQ9uw4sLpT8cdr+qBB+cVULIahh7spAbgAIMguNipvF2mjW5kAb0l4z6RANIKe8vd6q3CxZW0g X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(52116005)(376005)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AUYnwwo19OU/zlKa4WhrjLhkUdYm?= =?utf-8?q?F5js/ZRjSF0XwcnZQBJQ4a8VOxwMSbRlqLnNWIWM4v76LeNTSZvETsxgMNmAd8Fux?= =?utf-8?q?rmO3tyzjH1lyQM9sgEQc3WxfOXCUio+6bnTFvDNlX0+JpC3L0XMOsiZFJlFDjEp0C?= =?utf-8?q?pi6K11/gpxLiqQ7Pb/pnedeHCSiDV38YmTM0hANSVYnW5SBhA/nUH54EA6h8O4ahr?= =?utf-8?q?+AtTA5ybvasBdEufeSZKhAbQ4/uPs0/T5RsLA+k595kJ3WfjiOJ5tkYmoGRW+bH5P?= =?utf-8?q?trEA0vQAXPll7BVkAAotzUysqMziMrl9cFpsJvKwO51vn4ZwWn3O3MORgQxrS4qr7?= =?utf-8?q?9Eq0nkWX8Odv2F8CCf3RLFxha7B4CNTHsvf0nlGRBiJM+Amf6Cj+6AwX2rSPexAY7?= =?utf-8?q?4IY5VhBe9nkslO44TeKFik3ClO7nRYcyeh8KBXQxe745amB/0/F03JzyXtDjEORQh?= =?utf-8?q?UzZqswbRnQKtkZaHPLcMG2it9XPWjrkepNkTlGlczPoQzHOyu+HpNn2mWV3E8sDdP?= =?utf-8?q?KHt7jhIYHcF2fHb7+7Hof+T1dDo6o+hDjY0SMzpRhe/BF+oUy0bnPGN+BAGKoxDG7?= =?utf-8?q?CLaeFoy+bQMd8QW7+GB5dQoRTCfWlnZzaGN4zJbumZPB6+rrRGea/WhcAcNb9bi/p?= =?utf-8?q?P6DzwXu0jL53FdMuhPy8rmuABU/mEFh3Eq2nZlDhr5gpe/RaEX+9CHxGeoIt1bIs/?= =?utf-8?q?2eQP/eFx60Ixgeoz9Bg065fuBMqo19a0LJFzLD9QKJoNCqMtYPxxFJiEmEnYQim+j?= =?utf-8?q?s4glmLVkfq4gnLDOFI3klI3AaxNMUVz23xB6zT5r7lu3A7LbRoF9kSh4L4GC7qROk?= =?utf-8?q?loWEjgyJvfCR7xgMdutmcS9TrLdDRAdQsHnwm8UrrnEz7zzvV4OmJPYFcz5p5ed3E?= =?utf-8?q?OvyHm7Voi0RxOjlP5zvq8BsHRVAC3nJ7qgIO1Na8OrXCUuOUpTGPx8b1V8g8jNLcz?= =?utf-8?q?kqRvM9f3LU0xnuXKHI9QgBshSmsnEUPk5CoLu+TwIZnggXu4PAj0WJAJmrovD4Cr+?= =?utf-8?q?QkRff5f/Pgqei1zTGvgdmwTVtAyH3zbScdiVg64cpWEvHUep9Ws+F7GO4mFV42xyV?= =?utf-8?q?ZOnpa//1+O5X95Lm9cmCXoF96lSpqqpv0kLCDWZlVdpZOaKuyRax/B0Hbfq+AfGtl?= =?utf-8?q?3Tgn36ke2zNwz4k2jc+z9oygNJqNKe+kjIhm+gOETJhE7GmYmNNfV40ZQ9jJ2dCGA?= =?utf-8?q?DH1UuRNvdA+rSFtDPRqSeySdOs7se3VlD2+3hHwGTyjsbNBPTR4Hernt+Bvl2uox+?= =?utf-8?q?4kUx6Up+6ydxls4o1rgIJa1IshNz2C+DCVJNC5aXc8jXbgRolnTF/tEA/Uo5TSy5E?= =?utf-8?q?0KvivP4fJzPIHjDQHmSVstby6/xRNcNs+nG60Uhh5m5i9icHOYJvJh+PcMSJCSlvF?= =?utf-8?q?5lz7LFqS6yyL3Jgv9oVtcP0kJWV2bZUbKIEVVUlukJbm1Z/ObiooRXq+0yO79FKBT?= =?utf-8?q?Kju7E1nKnQspmYzGePG/5v8SIO7KKEWBcXJNjO1HDt58AnA5ZiYFvbPRwskj+Gf3A?= =?utf-8?q?FzdUyJL2Ndqv?= X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65e94755-9b03-4bcb-72e6-08dc3f81e942 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:10:38.0113 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7e452255-946f-4f17-800a-a0fb6835dc6c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r3hC6Kn2j3vk96BqICvjCymTOzrOHo/KYUJ3HX34oYYYMYZMMMoXzev0ItgmndRnSFKfkq5U9VAooIFVgf6IVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB2564 X-Proofpoint-GUID: AS-DT9_a4Wx4pb_adOEGsESofOY6yRxX X-Proofpoint-ORIG-GUID: AS-DT9_a4Wx4pb_adOEGsESofOY6yRxX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-08_08,2024-03-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 impostorscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403080122 From: Jean-Baptiste Maneyrol WoM is a threshold test on accel value comparing actual sample with previous one. It maps best to roc rising event. Add support of a new WOM sensor and functions for handling the corresponding roc_rising event. The event value is in SI units. Ensure WOM is stopped and restarted at suspend-resume, handle usage with buffer data ready interrupt, and handle change in sampling rate impacting already set roc value. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 293 +++++++++++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 19 +- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 6 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 14 +- 4 files changed, 319 insertions(+), 13 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 0e94e5335e93..ad42be809f09 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -332,7 +333,7 @@ static int inv_mpu6050_clock_switch(struct inv_mpu6050_state *st, int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, unsigned int mask) { - unsigned int sleep; + unsigned int sleep, val; u8 pwr_mgmt2, user_ctrl; int ret; @@ -345,6 +346,14 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, mask &= ~INV_MPU6050_SENSOR_TEMP; if (mask & INV_MPU6050_SENSOR_MAGN && en == st->chip_config.magn_en) mask &= ~INV_MPU6050_SENSOR_MAGN; + if (mask & INV_MPU6050_SENSOR_WOM && en == st->chip_config.wom_en) + mask &= ~INV_MPU6050_SENSOR_WOM; + + /* force accel on if WoM is on and not going off */ + if (!en && (mask & INV_MPU6050_SENSOR_ACCL) && st->chip_config.wom_en && + !(mask & INV_MPU6050_SENSOR_WOM)) + mask &= ~INV_MPU6050_SENSOR_ACCL; + if (mask == 0) return 0; @@ -439,6 +448,16 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, } } + /* enable/disable accel intelligence control */ + if (mask & INV_MPU6050_SENSOR_WOM) { + val = en ? INV_MPU6500_BIT_ACCEL_INTEL_EN | + INV_MPU6500_BIT_ACCEL_INTEL_MODE : 0; + ret = regmap_write(st->map, INV_MPU6500_REG_ACCEL_INTEL_CTRL, val); + if (ret) + return ret; + st->chip_config.wom_en = en; + } + return 0; } @@ -893,6 +912,251 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, return result; } +static u64 inv_mpu6050_convert_wom_to_roc(unsigned int threshold, unsigned int freq_div) +{ + /* 4mg per LSB converted in m/s² in micro (1000000) */ + const unsigned int convert = 4U * 9807U; + u64 value; + + value = threshold * convert; + /* compute the differential by multiplying by the frequency */ + value = div_u64(value * INV_MPU6050_INTERNAL_FREQ_HZ, freq_div); + + return value; +} + +static unsigned int inv_mpu6050_convert_roc_to_wom(u64 roc, unsigned int freq_div) +{ + /* 4mg per LSB converted in m/s² in micro (1000000) */ + const unsigned int convert = 4U * 9807U; + u64 value; + unsigned int threshold; + + /* return 0 only if roc is 0 */ + if (roc == 0) + return 0; + + value = div_u64(roc * freq_div, convert * INV_MPU6050_INTERNAL_FREQ_HZ); + /* limit value to 8 bits and prevent 0*/ + if (value == 0) + threshold = 1; + else if (value > 255) + threshold = 255; + else + threshold = value; + + return threshold; +} + +static int inv_mpu6050_set_wom_int(struct inv_mpu6050_state *st, bool on) +{ + unsigned int reg_val, val; + + switch (st->chip_type) { + case INV_MPU6050: + case INV_MPU6500: + case INV_MPU6515: + case INV_MPU6880: + case INV_MPU6000: + case INV_MPU9150: + case INV_MPU9250: + case INV_MPU9255: + reg_val = INV_MPU6500_BIT_WOM_INT_EN; + break; + default: + reg_val = INV_ICM20608_BIT_WOM_INT_EN; + break; + } + + val = on ? reg_val : 0; + + return regmap_update_bits(st->map, st->reg->int_enable, reg_val, val); +} + +static int inv_mpu6050_set_wom_threshold(struct inv_mpu6050_state *st, u64 value, + unsigned int freq_div) +{ + unsigned int threshold; + int result; + + /* convert roc to wom threshold and convert back to handle clipping */ + threshold = inv_mpu6050_convert_roc_to_wom(value, freq_div); + value = inv_mpu6050_convert_wom_to_roc(threshold, freq_div); + + dev_dbg(regmap_get_device(st->map), "wom_threshold: 0x%x\n", threshold); + + switch (st->chip_type) { + case INV_ICM20609: + case INV_ICM20689: + case INV_ICM20600: + case INV_ICM20602: + case INV_ICM20690: + st->data[0] = threshold; + st->data[1] = threshold; + st->data[2] = threshold; + result = regmap_bulk_write(st->map, INV_ICM20609_REG_ACCEL_WOM_X_THR, + st->data, 3); + break; + default: + result = regmap_write(st->map, INV_MPU6500_REG_WOM_THRESHOLD, threshold); + break; + } + if (!result) + st->chip_config.roc_threshold = value; + + return result; +} + +static int inv_mpu6050_enable_wom(struct inv_mpu6050_state *st, bool en) +{ + struct device *pdev = regmap_get_device(st->map); + unsigned int mask; + int result; + + if (en) { + result = pm_runtime_resume_and_get(pdev); + if (result) + return result; + + mask = INV_MPU6050_SENSOR_ACCL | INV_MPU6050_SENSOR_WOM; + result = inv_mpu6050_switch_engine(st, true, mask); + if (result) + goto error_suspend; + + result = inv_mpu6050_set_wom_int(st, true); + if (result) + goto error_suspend; + } else { + result = inv_mpu6050_set_wom_int(st, false); + if (result) + dev_err(pdev, "error %d disabling WoM interrupt bit", result); + + /* disable only WoM and let accel be disabled by autosuspend */ + result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_SENSOR_WOM); + if (result) { + dev_err(pdev, "error %d disabling WoM force off", result); + /* force WoM off */ + st->chip_config.wom_en = false; + } + + pm_runtime_mark_last_busy(pdev); + pm_runtime_put_autosuspend(pdev); + } + + return result; + +error_suspend: + pm_runtime_mark_last_busy(pdev); + pm_runtime_put_autosuspend(pdev); + return result; +} + +static int inv_mpu6050_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + int result; + + /* support only WoM (accel roc rising) event */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_ROC || dir != IIO_EV_DIR_RISING) + return -EINVAL; + + mutex_lock(&st->lock); + result = st->chip_config.wom_en ? 1 : 0; + mutex_unlock(&st->lock); + + return result; +} + +static int inv_mpu6050_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + int state) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + int enable; + int result; + + /* support only WoM (accel roc rising) event */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_ROC || dir != IIO_EV_DIR_RISING) + return -EINVAL; + + enable = !!state; + + mutex_lock(&st->lock); + + if (st->chip_config.wom_en == enable) { + result = 0; + goto exit_unlock; + } + + result = inv_mpu6050_enable_wom(st, enable); + +exit_unlock: + mutex_unlock(&st->lock); + return result; +} + +static int inv_mpu6050_read_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, int *val, int *val2) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + u32 rem; + + /* support only WoM (accel roc rising) event value */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_ROC || + dir != IIO_EV_DIR_RISING || info != IIO_EV_INFO_VALUE) + return -EINVAL; + + /* return value in micro */ + *val = div_u64_rem(st->chip_config.roc_threshold, 1000000U, &rem); + *val2 = rem; + + return IIO_VAL_INT_PLUS_MICRO; +} + +static int inv_mpu6050_write_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, int val, int val2) +{ + struct inv_mpu6050_state *st = iio_priv(indio_dev); + struct device *pdev = regmap_get_device(st->map); + u64 value; + int result; + + /* support only WoM (accel roc rising) event value */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_ROC || + dir != IIO_EV_DIR_RISING || info != IIO_EV_INFO_VALUE) + return -EINVAL; + + if (val < 0 || val2 < 0) + return -EINVAL; + + mutex_lock(&st->lock); + + result = pm_runtime_resume_and_get(pdev); + if (result) + goto exit_unlock; + + value = (u64)val * 1000000ULL + (u64)val2; + result = inv_mpu6050_set_wom_threshold(st, value, INV_MPU6050_FREQ_DIVIDER(st)); + + pm_runtime_mark_last_busy(pdev); + pm_runtime_put_autosuspend(pdev); + +exit_unlock: + mutex_unlock(&st->lock); + return result; +} + /* * inv_mpu6050_set_lpf() - set low pass filer based on fifo rate. * @@ -989,6 +1253,12 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, if (result) goto fifo_rate_fail_power_off; + /* update wom threshold since roc is dependent on sampling frequency */ + result = inv_mpu6050_set_wom_threshold(st, st->chip_config.roc_threshold, + INV_MPU6050_FREQ_DIVIDER(st)); + if (result) + goto fifo_rate_fail_power_off; + pm_runtime_mark_last_busy(pdev); fifo_rate_fail_power_off: pm_runtime_put_autosuspend(pdev); @@ -1326,6 +1596,10 @@ static const struct iio_info mpu_info = { .write_raw = &inv_mpu6050_write_raw, .write_raw_get_fmt = &inv_write_raw_get_fmt, .attrs = &inv_attribute_group, + .read_event_config = inv_mpu6050_read_event_config, + .write_event_config = inv_mpu6050_write_event_config, + .read_event_value = inv_mpu6050_read_event_value, + .write_event_value = inv_mpu6050_write_event_value, .validate_trigger = inv_mpu6050_validate_trigger, .debugfs_reg_access = &inv_mpu6050_reg_access, }; @@ -1706,6 +1980,12 @@ static int inv_mpu_resume(struct device *dev) if (result) goto out_unlock; + if (st->chip_config.wom_en) { + result = inv_mpu6050_set_wom_int(st, true); + if (result) + goto out_unlock; + } + if (iio_buffer_enabled(indio_dev)) result = inv_mpu6050_prepare_fifo(st, true); @@ -1735,6 +2015,12 @@ static int inv_mpu_suspend(struct device *dev) goto out_unlock; } + if (st->chip_config.wom_en) { + result = inv_mpu6050_set_wom_int(st, false); + if (result) + goto out_unlock; + } + if (st->chip_config.accl_en) st->suspended_sensors |= INV_MPU6050_SENSOR_ACCL; if (st->chip_config.gyro_en) @@ -1743,6 +2029,8 @@ static int inv_mpu_suspend(struct device *dev) st->suspended_sensors |= INV_MPU6050_SENSOR_TEMP; if (st->chip_config.magn_en) st->suspended_sensors |= INV_MPU6050_SENSOR_MAGN; + if (st->chip_config.wom_en) + st->suspended_sensors |= INV_MPU6050_SENSOR_WOM; result = inv_mpu6050_switch_engine(st, false, st->suspended_sensors); if (result) goto out_unlock; @@ -1767,7 +2055,8 @@ static int inv_mpu_runtime_suspend(struct device *dev) mutex_lock(&st->lock); sensors = INV_MPU6050_SENSOR_ACCL | INV_MPU6050_SENSOR_GYRO | - INV_MPU6050_SENSOR_TEMP | INV_MPU6050_SENSOR_MAGN; + INV_MPU6050_SENSOR_TEMP | INV_MPU6050_SENSOR_MAGN | + INV_MPU6050_SENSOR_WOM; ret = inv_mpu6050_switch_engine(st, false, sensors); if (ret) goto out_unlock; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 5950e2419ebb..19adccf388cf 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -88,11 +88,12 @@ enum inv_devices { INV_NUM_PARTS }; -/* chip sensors mask: accelerometer, gyroscope, temperature, magnetometer */ +/* chip sensors mask: accelerometer, gyroscope, temperature, magnetometer, WoM */ #define INV_MPU6050_SENSOR_ACCL BIT(0) #define INV_MPU6050_SENSOR_GYRO BIT(1) #define INV_MPU6050_SENSOR_TEMP BIT(2) #define INV_MPU6050_SENSOR_MAGN BIT(3) +#define INV_MPU6050_SENSOR_WOM BIT(4) /** * struct inv_mpu6050_chip_config - Cached chip configuration data. @@ -104,6 +105,7 @@ enum inv_devices { * @gyro_en: gyro engine enabled * @temp_en: temperature sensor enabled * @magn_en: magn engine (i2c master) enabled + * @wom_en: Wake-on-Motion enabled * @accl_fifo_enable: enable accel data output * @gyro_fifo_enable: enable gyro data output * @temp_fifo_enable: enable temp data output @@ -119,12 +121,14 @@ struct inv_mpu6050_chip_config { unsigned int gyro_en:1; unsigned int temp_en:1; unsigned int magn_en:1; + unsigned int wom_en:1; unsigned int accl_fifo_enable:1; unsigned int gyro_fifo_enable:1; unsigned int temp_fifo_enable:1; unsigned int magn_fifo_enable:1; u8 divider; u8 user_ctrl; + u64 roc_threshold; }; /* @@ -256,12 +260,16 @@ struct inv_mpu6050_state { #define INV_MPU6050_REG_INT_ENABLE 0x38 #define INV_MPU6050_BIT_DATA_RDY_EN 0x01 #define INV_MPU6050_BIT_DMP_INT_EN 0x02 +#define INV_MPU6500_BIT_WOM_INT_EN BIT(6) +#define INV_ICM20608_BIT_WOM_INT_EN GENMASK(7, 5) #define INV_MPU6050_REG_RAW_ACCEL 0x3B #define INV_MPU6050_REG_TEMPERATURE 0x41 #define INV_MPU6050_REG_RAW_GYRO 0x43 #define INV_MPU6050_REG_INT_STATUS 0x3A +#define INV_MPU6500_BIT_WOM_INT BIT(6) +#define INV_ICM20608_BIT_WOM_INT GENMASK(7, 5) #define INV_MPU6050_BIT_FIFO_OVERFLOW_INT 0x10 #define INV_MPU6050_BIT_RAW_DATA_RDY_INT 0x01 @@ -301,6 +309,11 @@ struct inv_mpu6050_state { #define INV_MPU6050_BIT_PWR_ACCL_STBY 0x38 #define INV_MPU6050_BIT_PWR_GYRO_STBY 0x07 +/* ICM20609 registers */ +#define INV_ICM20609_REG_ACCEL_WOM_X_THR 0x20 +#define INV_ICM20609_REG_ACCEL_WOM_Y_THR 0x21 +#define INV_ICM20609_REG_ACCEL_WOM_Z_THR 0x22 + /* ICM20602 register */ #define INV_ICM20602_REG_I2C_IF 0x70 #define INV_ICM20602_BIT_I2C_IF_DIS 0x40 @@ -320,6 +333,10 @@ struct inv_mpu6050_state { /* mpu6500 registers */ #define INV_MPU6500_REG_ACCEL_CONFIG_2 0x1D #define INV_ICM20689_BITS_FIFO_SIZE_MAX 0xC0 +#define INV_MPU6500_REG_WOM_THRESHOLD 0x1F +#define INV_MPU6500_REG_ACCEL_INTEL_CTRL 0x69 +#define INV_MPU6500_BIT_ACCEL_INTEL_EN BIT(7) +#define INV_MPU6500_BIT_ACCEL_INTEL_MODE BIT(6) #define INV_MPU6500_REG_ACCEL_OFFSET 0x77 /* delay time in milliseconds */ diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index 66d4ba088e70..13da6f523ca2 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -33,10 +33,8 @@ static int inv_reset_fifo(struct iio_dev *indio_dev) reset_fifo_fail: dev_err(regmap_get_device(st->map), "reset fifo failed %d\n", result); - result = regmap_write(st->map, st->reg->int_enable, - INV_MPU6050_BIT_DATA_RDY_EN); - - return result; + return regmap_update_bits(st->map, st->reg->int_enable, + INV_MPU6050_BIT_DATA_RDY_EN, INV_MPU6050_BIT_DATA_RDY_EN); } /* diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index 676704f9151f..ec2398a87f45 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -134,11 +134,13 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable) ret = regmap_write(st->map, st->reg->user_ctrl, d); if (ret) return ret; - /* enable interrupt */ - ret = regmap_write(st->map, st->reg->int_enable, - INV_MPU6050_BIT_DATA_RDY_EN); + /* enable data interrupt */ + ret = regmap_update_bits(st->map, st->reg->int_enable, + INV_MPU6050_BIT_DATA_RDY_EN, INV_MPU6050_BIT_DATA_RDY_EN); } else { - ret = regmap_write(st->map, st->reg->int_enable, 0); + /* disable data interrupt */ + ret = regmap_update_bits(st->map, st->reg->int_enable, + INV_MPU6050_BIT_DATA_RDY_EN, 0); if (ret) return ret; ret = regmap_write(st->map, st->reg->fifo_en, 0); @@ -171,9 +173,9 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) return result; /* * In case autosuspend didn't trigger, turn off first not - * required sensors. + * required sensors excepted WoM */ - result = inv_mpu6050_switch_engine(st, false, ~scan); + result = inv_mpu6050_switch_engine(st, false, ~scan & ~INV_MPU6050_SENSOR_WOM); if (result) goto error_power_off; result = inv_mpu6050_switch_engine(st, true, scan); From patchwork Fri Mar 8 15:10:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: inv.git-commit@tdk.com X-Patchwork-Id: 13586931 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 409444405 for ; Fri, 8 Mar 2024 15:11:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.178.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910689; cv=fail; b=Ng9llBoFbavU1I7Ns5NSNI3ACuBsP6wc3A40WIy30Ey5Wc1nVjdioU1Mu3rvtUU2Gl/inbAilZQjTS9sMxtJNYzCRHe/cCOxlQsIoMGsT962DetZRYPImCoBx//OG8kKzpxM6UXrijo1HUMLQignEz6YHcZQcdqFZxOCk/SmMsg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910689; c=relaxed/simple; bh=3T01nf4DhB5Xp/sWd3kAfW4unryf76NDdhsyHhuRFFY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Szym6T9Hvben2xdsdVXPerQPCKLwSxkbym9ThoQzzZNVEuOPkVGMlt5F0j9XOx6RzB920KC742jgBREWmEZl4t/44Zkl4IGcS2a6T1lXNC4sX2Ehmrjt/7478QYjLdb3yN5VfgbActGCu1Hx+a7p0kjCPRSKIrzdfprPuBzi8wU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com; spf=pass smtp.mailfrom=tdk.com; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b=CSGvAxL5; arc=fail smtp.client-ip=205.220.178.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tdk.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b="CSGvAxL5" Received: from pps.filterd (m0233779.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 428A25tJ016412; Fri, 8 Mar 2024 15:11:00 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2105.outbound.protection.outlook.com [104.47.23.105]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wkwfjmyah-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:11:00 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F32bXs8505F56Ya4zDsDBUtEmWnupuPUphB1vnye9JeI0WHsrg/PD1zLPp84EPTq36fxnQUPyeng0DJRL139hoquqctJxcFVIqQ7IICOEHjLr9TnxUZcurmhs8+wqNYrACeFz2nPHgzH/whGpk/+9P7+9hwU6uJKTupXH6OwTiv9vGy3LiQEZA32uFUdPrNlgMlR/kwmm8Es1yHCv8M+ek/hSOFZFbp0Ksg3RuW6L+dBeXUlYdlKxXJp7jAanCYedRpxKOzP+mqITVwFu0fcHrgHSIc37eIFSRMHh/n+1GKt6HUDetqoUWVzx0dcv4OoE+xYojPfMb9VJejHPZ7ESw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LaZ91oJMcjbJ4ADy3556eyzAFidkeJjUcPc7ClNEihI=; b=UWSByVTWOgOZp86J6b4643hdsgeOIaOZ3R/9dO8gLll8HZgPzuaHQ94ozMP3Qhym6nR18Bes2gFfn+79f5usxJbwDZC+JFiZCT/HX/SCB/eJyG6e+LZxjLF+/KKw1tDKq4ADAp2txkcqi+vuRsZm7xZQMyaIosz64oRYFVspcY2u8zx8BwuhYNpvJaypbN5fEnsrp1BU3BP9JWV0J8xQvlexbm/5Q6e5z1/dTQ7lVbIInc3De4InWcEZCvjFAZ5zdkQ9aDX6HOef9OjOkRV/NE3jhLWg7XzQe9ElIXK3Urh2m5++1kejalVTLeI/uEJ7P3+dBvf/dZFBClNo2Gi5SA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=tdk.com; dmarc=pass action=none header.from=tdk.com; dkim=pass header.d=tdk.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tdk.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LaZ91oJMcjbJ4ADy3556eyzAFidkeJjUcPc7ClNEihI=; b=CSGvAxL5ityavsWYfGG78OQettDbNYzp1OyaB43vvUR7ddQSkT4/3DiF84DP6CtFCm1+6oJLHkdQcBQF0oUu3a6BOUx+8d0o4YwRSOpjqK2Nm+gxKM2hjDqoBo2FEJIuIIHxSDB4K96CrRNalqmFt3T2A/pPhKICZymvJexNG3bNOncxTs394F6bEwLHCix8hzh48jf/vBz43TS8DAUofkblVuUjnWCOmnkq07/EWtqB8l6mhNwJGrXl+7X5p6ePprSqEXNGhz1YgtETOxzU2KVnMq91MG2OI98vzPHpYR3+1PZT2+zAaEwry2bLELQF2rB1qq57dNDEJ6aGJ82fZw== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TY3P286MB2564.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:22c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 15:10:40 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2%5]) with mapi id 15.20.7362.024; Fri, 8 Mar 2024 15:10:39 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org Cc: lars@metafoo.de, linux-iio@vger.kernel.org, Jean-Baptiste Maneyrol Subject: [PATCH v2 2/4] iio: imu: inv_mpu6050: add WoM event as accel event Date: Fri, 8 Mar 2024 15:10:21 +0000 Message-Id: <20240308151023.379705-3-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240308151023.379705-1-inv.git-commit@tdk.com> References: <20240308151023.379705-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO4P265CA0230.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:315::6) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TY3P286MB2564:EE_ X-MS-Office365-Filtering-Correlation-Id: 1293c556-1af7-42e3-5f9f-08dc3f81ea81 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +yzsy9U4gJ+Z/IjlN6n6gyCeSIBWjD6ub7tO+kS8Q2ANUtt5jjf81opMK+vsVU2IYQAo66zmQiTKjejpTa9+q2tqeovEwoW9a/s75Jld88I1wqIbQ70m63xzRHCBHF+RYkhZ/jxArIRmr8azfUkYKyh5bSECvJZpCcKAfcY4eJ8Zp88qmUSzYMl8oy71QGSnlkgwvu1k4EpqFdVgC3JZnvToWRsc7d+lgapncoqQOLYW7xXoBl+n2pBc4P78EiciAicxJQ02lIaAQ5oHkPW7ARcUf401D56CzWEdE4o8gGelIERl2K6qPhf91lqgbTt6A/X2Ab1groMG3uq8BkmkpUbGm7Q21eloHUTvAWFEozKBZ+Om0XljOlMATFvAdzgJsB5+QQoKLa08UVw3ZfPN6OlzRULdqppZZvwlPMJcai5eXi2pf8zUEah8CUMy98y4cYla5Y33mhXsJ7WrLOX1tomhWnrm7B5gwWr+8cigOPKYv07NMzfU/xu5a7pv8QAVDq9aA8+pYVidEGHPjjXgTT6mhBCosxVdTYUYddtgCebUVaAL+Kf7/4xQVAt2IX3UetNJGJMZFxeKi96e7r2a0UNQUxzMKgXdWEjGdkf7XojF8o0SGJGTOF58fxSbf855plzCXOy06VCoMhxIG869r54KTEvbWhoiyzuC5qXySW/HtXTjpreekZIXBEwRMEfC1iQMCjlFkD6s/2xD+insGMiAWM/Nn65DuE5agNYY8p+xdVoeGzS4kqL1kBrwRN1a X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(52116005)(376005)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: f2hVReJ83sp7TLcDj+GDBojHVx+XBymmmkZyDAKY7VO8KbkiHJ2JKJGTbDQfTFZA/vrz4KYs2+cA5XmaiHGANfWcElfJOZfRaE14yg0RbgVpPvm9tJfZch+PUkK2ytsnB12cvzwWrpLwkZ2M/zAfanLMEFuKztPqmGNQyL1q/ttBkYt8EUet3f5TmY7v2LI1im0qYAwEw24LzgaYCaIGfDhlBbu0gtIqSgv9hbzJB8RJn7ohE3jMWKeEQgoN33NCwyJLq2tTm8//fpuCkzNK1df4j3HDniYLHR9rXVIiOG+CDJtziiBEjekfQ/jOCxQtCn9DjCzhWsV/AUANShorl6HXBX7QsSlNLg7f07fQensdfyAiObzms6142vU37syHIp1VuI0Hb588W3bryJezbuO4ZnDIpFDmUilNVfTj047HX4AAse24jHkPhKm0+ZorOh44pZE3ycZP+gl1JK9hwy3KCe47DvPySWYpxkK0ghZYCgLqfGsrzUQadtMIQa06BiyLPvj2hdRpFiJyFCEfm48uq4LxDMXz5Dz2GkveGUo3wQRzMxgRRw5aVoC4Vw0ue6PN1qk0sAySF8TK7jmQ3D+OWrhipiBwCU3HO0NkxZ6YUZSIR5FLBai+GXQcN2MUsPd5WwW1EICwoDOmG79A+hHgQW9u1ON8yG5H4t9dGsiFWogCxD2fx2YPwnl/EK4HLjDKfbOii9AyHki4yGaffaCBpVG6nZr4ZySYUwlca7MXjVVxlpNf0r2XdHf4n2fwrlJksiVfef3TU0RD61+F/HOYX4MIwwYCHX08zCUE93a39wuN48FAt6chpQWp3A5E+xRL2dXudQWw+6LLeOOOm9EntF/SgHv1p1zV6Qu+7jHaXzCkg/vlBP+AzSWzYrZ7OxhEw1SA5qoFNponWj4Ifce7TsKruv7aMABaXzvMn5epeIX0+ANRJJRcn0n9DCGTbLSvdKuQ0ib5wTSxrr0Be76zyxz/PtyL0Qc9I7FGkdH3SNzovqvw36x34RA/VL1M35if7g65SLdmAlekYWQCeORPeSCMS3/osca4Q/cT9siAN3vA/GGUU20SpPGrsVsVr8hgSaDOgktdQj6kpmnDtFXwPs11z66gSBfkWodafv7P7XYMHH0ANhoXfKYmXntiz2DSN/DLUI4sAtG4Sf4FuULrRUbjxsayT9bRQHjf+wcK2Ie/kdHUrmSnGD2AYdsCyApSGlzT7ygfbqrrL/ov9ONeCxPqUal6vpSO9DvMFRwQzleeuqfZnDKwabVjqMOrkfw+cE3TUSCikcCJZalh3bbsl423loz7hzT+thQpXnYJ4XpWl/FPd5R9K+AXlx2t0wIsa8dgDLQnfSvnpOyAmJm6fXWFQq5h/zwWQm2h1h5+cYuomOY5oqdQShTH8Hagd0tjn+Ycalbvqpse3Ldsp3A/KEQWrpwaKTywyne0gmermyG54cunosSFnjhHCK0O6mPOYCjcZ69d04Jx/ek3PAKT2rjaIx3xia/kXN16R1lqyA6FccPdv67CBijGk7/NXnHDLlzKpSo14eD+AP2VGlku8tMT2JCkV3f1UHVfIfP42PlGKhksTIhI36gHgYp1 X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1293c556-1af7-42e3-5f9f-08dc3f81ea81 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:10:39.8803 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7e452255-946f-4f17-800a-a0fb6835dc6c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4iz/PIFz1k1NNmmPjmKqzh3QFeWSk8J0wyGqEIGNAWDsk/VRMmOfrWDav+yeyzZAipS/CvIzohETpd12a5TSEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB2564 X-Proofpoint-GUID: UVxOVr4LBWA8DNzdRazAervhJYssCc7M X-Proofpoint-ORIG-GUID: UVxOVr4LBWA8DNzdRazAervhJYssCc7M X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-08_08,2024-03-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 impostorscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403080122 From: Jean-Baptiste Maneyrol Add WoM (roc rising) event as accel x_or_y_or_z event for all chips >= MPU-6500. This requires to create new MPU-6500 channels as default and MPU-6050 channels for older chips. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 67 +++++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index ad42be809f09..ddc905bb74d6 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -1359,6 +1359,15 @@ static const struct iio_chan_spec_ext_info inv_ext_info[] = { { } }; +static const struct iio_event_spec inv_wom_events[] = { + { + .type = IIO_EV_TYPE_ROC, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_VALUE), + }, +}; + #define INV_MPU6050_CHAN(_type, _channel2, _index) \ { \ .type = _type, \ @@ -1394,7 +1403,17 @@ static const struct iio_chan_spec_ext_info inv_ext_info[] = { }, \ } -static const struct iio_chan_spec inv_mpu_channels[] = { +#define INV_MPU6050_EVENT_CHAN(_type, _channel2, _events, _events_nb) \ +{ \ + .type = _type, \ + .modified = 1, \ + .channel2 = _channel2, \ + .event_spec = _events, \ + .num_event_specs = _events_nb, \ + .scan_index = -1, \ +} + +static const struct iio_chan_spec inv_mpu6050_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP), INV_MPU6050_TEMP_CHAN(INV_MPU6050_SCAN_TEMP), @@ -1408,6 +1427,23 @@ static const struct iio_chan_spec inv_mpu_channels[] = { INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z), }; +static const struct iio_chan_spec inv_mpu6500_channels[] = { + IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP), + + INV_MPU6050_TEMP_CHAN(INV_MPU6050_SCAN_TEMP), + + 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), + + INV_MPU6050_EVENT_CHAN(IIO_ACCEL, IIO_MOD_X_OR_Y_OR_Z, + inv_wom_events, ARRAY_SIZE(inv_wom_events)), +}; + #define INV_MPU6050_SCAN_MASK_3AXIS_ACCEL \ (BIT(INV_MPU6050_SCAN_ACCL_X) \ | BIT(INV_MPU6050_SCAN_ACCL_Y) \ @@ -1887,6 +1923,12 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, return result; switch (chip_type) { + case INV_MPU6000: + case INV_MPU6050: + indio_dev->channels = inv_mpu6050_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu6050_channels); + indio_dev->available_scan_masks = inv_mpu_scan_masks; + break; case INV_MPU9150: indio_dev->channels = inv_mpu9150_channels; indio_dev->num_channels = ARRAY_SIZE(inv_mpu9150_channels); @@ -1900,13 +1942,13 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, break; case INV_ICM20600: case INV_ICM20602: - indio_dev->channels = inv_mpu_channels; - indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels); + indio_dev->channels = inv_mpu6500_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu6500_channels); indio_dev->available_scan_masks = inv_icm20602_scan_masks; break; default: - indio_dev->channels = inv_mpu_channels; - indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels); + indio_dev->channels = inv_mpu6500_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu6500_channels); indio_dev->available_scan_masks = inv_mpu_scan_masks; break; } @@ -1915,9 +1957,18 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, * auxiliary device in use. Otherwise Going back to 6-axis only. */ if (st->magn_disabled) { - indio_dev->channels = inv_mpu_channels; - indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels); - indio_dev->available_scan_masks = inv_mpu_scan_masks; + switch (chip_type) { + case INV_MPU9150: + indio_dev->channels = inv_mpu6050_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu6050_channels); + indio_dev->available_scan_masks = inv_mpu_scan_masks; + break; + default: + indio_dev->channels = inv_mpu6500_channels; + indio_dev->num_channels = ARRAY_SIZE(inv_mpu6500_channels); + indio_dev->available_scan_masks = inv_mpu_scan_masks; + break; + } } indio_dev->info = &mpu_info; From patchwork Fri Mar 8 15:10:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: inv.git-commit@tdk.com X-Patchwork-Id: 13586932 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4DE0568A for ; Fri, 8 Mar 2024 15:11:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.178.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910689; cv=fail; b=B6ieIA9GjvQRK8SaiDK/MxDaWKJ3RkTWoSXr/KslWccaAi9/DArGaCHqOIVytsdJn6qEsRJszreBKc47eJF6BcvGlLy2zqcMaIYXAwL6Htie+nhjnVwg1IfXphTJjy+FjL3d5NHYqCbutCFU1Z1F7XKytTlce6HhCYs/gAJhMtk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910689; c=relaxed/simple; bh=nxluuw1XuA2Tq2N3+mXlfkNGKQPDhtxnpvWw+cRM+3A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Tdap7kEAEuQvY/PQ80EYF0nGsbvG5Dil2F6whb7A6qfmB+dNULy7lh2Cvvt9YoCJHT1RObZmH0cmX6r9lLXOtsLxiSEeYD694vtNz9rivIGY69UbDGNkebq4S11/eruVWiLLjoBP6MlCESGrRBiA7i+V+hS7bkPOjF/Xz/q3kJY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com; spf=pass smtp.mailfrom=tdk.com; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b=fuG8qp/m; arc=fail smtp.client-ip=205.220.178.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tdk.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b="fuG8qp/m" Received: from pps.filterd (m0233779.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 428A25tK016412; Fri, 8 Mar 2024 15:11:01 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2105.outbound.protection.outlook.com [104.47.23.105]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wkwfjmyah-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:11:01 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b0BO76ed0mokNK39y9+F3eEbnDMSboQxEJ0Lm+4nTJkELE+otJPYon6tiqMFiqSdF9ixaP/ZqxmSogq4hhX6xEpgKtiDeggzKC91N7qYyCrhHud1Nmui/ZIlM+8u/aj+//8jhf2hYiYc5v1MP/lmc8q9XQBnkze68ftzH0HiYS7yipzpkGKUMfrLCwyoj3M+c/PkmYYriDudzQKKsaQDBNTmcTr0TGg0jsMpYBvDzBBpVrWTwMwZC8k+rukMxFVMHZb9V5kl3RTOLFzyM0ezfCPwAwyI2nsLIJ9i+YQ0UiNh2MirQwO3MgCHW1nyByd7/jauwTMkLX0azdlYLJNFvw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ItSEIXqKBH5LvC1064SnsO/FTPVBjZUYgm/Fx44o018=; b=eEfIJWsO0ZmLJP/Y90HczMTrgtK++jwC9bGb99WkAeZ7npau1JV/ZZwp02KxsBoHfcGRt8trkP1PPAX26H5NlBA1FVS7nSkH7L78vN6SGNqXTsfQjB7F9RpXslStGV+5M7mfs69FrkDriXx+8u/uwVj7n59a1SjLOufSU81HpJetYdRiedk9xtYvYmK4C8gibU1SNO/wLsQ714ihsDR6BeEakNkfMN6sDa0eqD3ABTOsALPhBXaVxmZRazH8dTnJGtdHkzYv4QcpkiMcNswouY2a3CQvmwbVgSzFDoSmjGU4n33X8Li9MFIfFgQQtB2aMe4IJ1lv+EPePtt58SL7dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=tdk.com; dmarc=pass action=none header.from=tdk.com; dkim=pass header.d=tdk.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tdk.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ItSEIXqKBH5LvC1064SnsO/FTPVBjZUYgm/Fx44o018=; b=fuG8qp/mgbZGDWfJI6xBG25hLfPQNbVYkbqf19WjzlxENPBbs6bS4HGOD3zbldT5z95ogxKHVt20My4WAyQXiFJeZGDHXdp/ozO6/VawtuoYdMNQheAbX5ubKIPtT9cu3oG5NKPmQD4zAWIKHYiBNaxbA1YewASax/+5VnY1KNLjQ9pnk68kyHVA4iT5IrC7YbSD8BlYVlfVNayK2LKtPeen7+d3t/yg5iOSeiA0lZww2XqxDcy24TGrnzpeZ/M8WAlV6jOPJAolrir6Jct6HG7UBPL8RN4myKm67ObpkQ13P2Hmqiu+wroEJyngXZXi2QWiFdCQACI9s2Ef5WImQw== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TY3P286MB2564.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:22c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 15:10:41 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2%5]) with mapi id 15.20.7362.024; Fri, 8 Mar 2024 15:10:41 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org Cc: lars@metafoo.de, linux-iio@vger.kernel.org, Jean-Baptiste Maneyrol Subject: [PATCH v2 3/4] iio: imu: inv_mpu6050: add new interrupt handler for WoM events Date: Fri, 8 Mar 2024 15:10:22 +0000 Message-Id: <20240308151023.379705-4-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240308151023.379705-1-inv.git-commit@tdk.com> References: <20240308151023.379705-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO4P265CA0230.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:315::6) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TY3P286MB2564:EE_ X-MS-Office365-Filtering-Correlation-Id: d39df35b-635a-42e9-0273-08dc3f81eb9f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oazcSchiMKfoRnWgoDJDvgsiEAXBLj+orn8U77+56X2l+dY10hw2ieckjBKsw42Sn3ZYSztN4cPEhMFi0jUfmrY6IgCsZTdGSdKBLCBTnXNpcL1jiO3UYy65aaMf9H/zUQOCUNMXfN32FU9r5R1k/oYdbPdWfoqh5EtpVP2ELjs3gjGd8EKTw1iLHpjCu07BlYEDidUxyo/ptgLOf9Y53sT+/8Tcu2U+euxSopVtfubJT3MdZUO2d13arhten9ktlelJblU51tRJRFKLhDKb9WONpUPboTCF2DDWW321Wn+yoVIgd+NRwKpNhQoBPc/U9DUdFz+ziUCvL6PNOOgaTJQGyxOjK1YljUDIJ4jB4fRE00lqK8oIhGJNUAnvCZLbY8WSeOS4NLMl7n+TNH23675NOCACzel+psasUZA9lZpbAaen3BjifBZpOGwNpOcK4ySlpuwlxT8VKdTBvtvJ1+caieAciOa+/fhWsKxW0MBRbw8J/Bih5jIeMkPoUMQMcnM9H8+JUopNU0+jDfmKhKUE69pmsfK8sHIOc/H8pVVRXnpq7jkhMjI2ZZj6NE36snrmvZ1QClkTSkpbXX4xlrbwSoHNAWEmFCXbPU+IDkTULGmNN4k7wiYeW0VPxhvuS/Y1Tu5SJTxarVOnYCXfvpBnmT3l8cU0g8rB8tgEYuksMJquwgGJUoQDTE18R857Y/6IQ2QAn+8fTRNlpBzcgGXKjR4K9VEQ6/VwYpcGYVYPc2o1bGKJo9+W9D2pl3OR X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(52116005)(376005)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0GaPY02Dx1enCy3ryXubi31FUBaIEFjXm8RhJT5ihmBuEeJ1icGuJpqDS+mNnDTLBjMYGnJNewddX/GGb9PYnZPjttYbKj0BLX0PGadJ7lCDH1PvVVtBQDtMp/HTn71WugVXubT7WBpDzmSdTTUxDTMnGNrFKLMlcIhkwN/kgdO2lRj185N3tdhw5kAHYQn1PfcFm+LYU2G44ycX2k0cC/lI1ijY+ChwN02fA32sqQ1snk0RP916ZW2fEqoOZkWrRUgK8ri/MwhBFQIbng03k1Do8It+6nFOITzsubYDaCKwL6fNiHbkckfGzZSfVzBcggb2BXWIDDZs0FSBZRVFs0E4RI4q+ZUZ/iuVoP4sb81ErvYoNQE4R9+aAvo4PpaWT3jYjucOgIKol1fbm6F3IJYMh+8IfpmsXdA0G0cLDbrbt3NNCmWGzYIa16Z2/L36bHCANXRIMRB9tZfo1u8WpjUF7JBRnCTpaUYhqL9kYhu1gH4k/Ioyi6+kG7/FHErWYg6jB6VkpERuhAToiAeHnmrj7T7iRyfsIcmaqzqOyw6zYqmEppL751SpV90YERhTMRuCX+sJk77ayZ+cJ5Ss3wbGD7kVzFXEWRLNOEyfFLW/A5UlO8e9xIineExYkfeP44j0F7AkTGVzcSt2T950PKThGAkL8XO7zw5I0vJEtMgGCyeDe1CewXnT15fdseU2m90+Alct4gwNRxmmk8N7RPfCm9P4J+TdkRqRNjAinJ06DiSlznkqbGiZ5mv55pie9m6JUtbKXxJyDLtLn5sNVfegOaZQIQJfTOP06R+zPSZvtZ5cFsrGrF32La7q+YTRlPzalglr8n6QMKMuHVOyTECigo6qnooTBs8qASDYL43Ym6AToRKX13Adb28lZWfGTkwXQCkMRyzI3ZRgMraPLmcUrrcQFu6+TqUzHSaqkxlZ5HAgtzhIOqXCesP+iShQMuVmJo8rcgNQVLR05uNz6Q6dKiYfu3OLTDNlCcNBjSmiKU27iCHk48eZRw9Y5+Atww4oAW2dtsYIsDLAI2WONiRBO+RTbUHPelmMUYej+lJI+xJNnpFTGVHZGJ+xHdOAG8GVPUb7YErVeF7tq5pOUUs4HBLk2AZ5V+Qj3AGj0vdDTefu2wTc/Y2Tf81bHZkXvLCwkUviQF8Iv/yqyU1o8iiUb1LEqnfUrXGTqXUa24jrmISjUduGKfbiJfFnLD5Yrwd/DYEah0VgdImg+vimxuBnx08knkXsbLuph2PVxlE7Lh6lO4nZ1d5cSF67rTz7mCRQTSMLZptpuLr+/RZeOYHzrxc9+JR78xdLKK8u5DUGXAkHzEnBZLYZy3nzMmXORCG2eiOpaN0VQMbi/+eASdrj0HchDXp0ahFmhNMTAFVZs6YF9Xad0Brk869qQ4b6BKrVmJHfjxlmQ4i1WNjCSZhz2xaHRZHGSN5h8SCGuPas1wGj/9TSmli6P8lufM5QG3G/Z6begEyyxlvgzKwwf8BaC11QB2OjSee+O4Rtu1SpRHlX/oDVKgmDNNY0ICGxVNWHmUdtIv23nQc8i+NypG21QRnoKVq3PBDaxzWp68O7nzM9HkdTBlC8vtYvPR+z X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: d39df35b-635a-42e9-0273-08dc3f81eb9f X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:10:41.7644 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7e452255-946f-4f17-800a-a0fb6835dc6c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 39eODOqzbqnDRdSqUPbR/L9VjGm+g21ifJo070S1yMvXKiJUBUzwExXlWiiwFV4XUkMnKl4q28HqmbHnUoWnfw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB2564 X-Proofpoint-GUID: yC9NNv4CopOat13Yqu4h3JAIKd--upK0 X-Proofpoint-ORIG-GUID: yC9NNv4CopOat13Yqu4h3JAIKd--upK0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-08_08,2024-03-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 impostorscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403080122 From: Jean-Baptiste Maneyrol Add new interrupt handler for generating WoM event from int status register bits. Launch from interrupt the trigger poll function for data buffer. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 2 + drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 11 --- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 72 +++++++++++++++++-- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index 19adccf388cf..e97a63ad2c31 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -184,6 +184,7 @@ struct inv_mpu6050_hw { * @magn_orient: magnetometer sensor chip orientation if available. * @suspended_sensors: sensors mask of sensors turned off for suspend * @data: read buffer used for bulk reads. + * @it_timestamp: interrupt timestamp. */ struct inv_mpu6050_state { struct mutex lock; @@ -209,6 +210,7 @@ struct inv_mpu6050_state { unsigned int suspended_sensors; bool level_shifter; u8 *data; + s64 it_timestamp; }; /*register and associated bit definition*/ diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index 13da6f523ca2..e282378ee2ca 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -51,21 +51,10 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) u32 fifo_period; s64 timestamp; u8 data[INV_MPU6050_OUTPUT_DATA_SIZE]; - int int_status; size_t i, nb; mutex_lock(&st->lock); - /* ack interrupt and check status */ - result = regmap_read(st->map, st->reg->int_status, &int_status); - if (result) { - dev_err(regmap_get_device(st->map), - "failed to ack interrupt\n"); - goto flush_fifo; - } - if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT)) - goto end_session; - if (!(st->chip_config.accl_fifo_enable | st->chip_config.gyro_fifo_enable | st->chip_config.magn_fifo_enable)) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index ec2398a87f45..585e5112f7a5 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -6,6 +6,7 @@ #include #include +#include #include "inv_mpu_iio.h" @@ -223,6 +224,68 @@ static const struct iio_trigger_ops inv_mpu_trigger_ops = { .set_trigger_state = &inv_mpu_data_rdy_trigger_set_state, }; +static irqreturn_t inv_mpu6050_interrupt_timestamp(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct inv_mpu6050_state *st = iio_priv(indio_dev); + + st->it_timestamp = iio_get_time_ns(indio_dev); + + return IRQ_WAKE_THREAD; +} + +static irqreturn_t inv_mpu6050_interrupt_handle(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct inv_mpu6050_state *st = iio_priv(indio_dev); + unsigned int int_status, wom_bits; + int result; + + switch (st->chip_type) { + case INV_MPU6050: + case INV_MPU6500: + case INV_MPU6515: + case INV_MPU6880: + case INV_MPU6000: + case INV_MPU9150: + case INV_MPU9250: + case INV_MPU9255: + wom_bits = INV_MPU6500_BIT_WOM_INT; + break; + default: + wom_bits = INV_ICM20608_BIT_WOM_INT; + break; + } + + mutex_lock(&st->lock); + + /* ack interrupt and check status */ + result = regmap_read(st->map, st->reg->int_status, &int_status); + if (result) { + dev_err(regmap_get_device(st->map), "failed to ack interrupt\n"); + int_status = 0; + goto exit_unlock; + } + + /* handle WoM event */ + if (st->chip_config.wom_en && (int_status & wom_bits)) + iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z, + IIO_EV_TYPE_ROC, IIO_EV_DIR_RISING), + st->it_timestamp); + +exit_unlock: + mutex_unlock(&st->lock); + + /* handle raw data interrupt */ + if (int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT) { + indio_dev->pollfunc->timestamp = st->it_timestamp; + iio_trigger_poll_nested(st->trig); + } + + return IRQ_HANDLED; +} + int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type) { int ret; @@ -235,11 +298,10 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type) if (!st->trig) return -ENOMEM; - ret = devm_request_irq(&indio_dev->dev, st->irq, - &iio_trigger_generic_data_rdy_poll, - irq_type, - "inv_mpu", - st->trig); + ret = devm_request_threaded_irq(&indio_dev->dev, st->irq, + &inv_mpu6050_interrupt_timestamp, + &inv_mpu6050_interrupt_handle, + irq_type, "inv_mpu", indio_dev); if (ret) return ret; From patchwork Fri Mar 8 15:10:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: inv.git-commit@tdk.com X-Patchwork-Id: 13586933 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4E1F1BF37 for ; Fri, 8 Mar 2024 15:11:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.178.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910690; cv=fail; b=M74MS8ICtedcFpgG0LWb6cMvQfrhs5xlyWux6GhDlI25AlvgnbB3qQbpevXPoW+dLHRWY2NWjatsQMFXLqfrmt6n5csymBPuS5h3RfpguugA5YKHP28JbR2xGcfKLFMoqo49GL1C7XvO1sZyahtqzXONMEJ8QpF8+97Bxc2fbcg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709910690; c=relaxed/simple; bh=+Z5F/SjboyJrxyP1NEEYTr9bzrq7oY0jYwSaK43n8g4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=t7yX5pMPtaE2tHpkfgyDu74JWH61bMJu2Uqf1PjSmVuyQoY4S+8nx9YPWZ8oTjLDr7rZTtPbHGPtyIsosiLUWjByvWDfMpzVjn2wYif0B6fG4qoPwTDnejKTJQU1XKl9a8LQMIIzgnykuMRmU/Rgekp6DNhYQPz6eQnwB5/ZGcI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com; spf=pass smtp.mailfrom=tdk.com; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b=BWpdWFZC; arc=fail smtp.client-ip=205.220.178.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tdk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tdk.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tdk.com header.i=@tdk.com header.b="BWpdWFZC" Received: from pps.filterd (m0233779.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 428A25tL016412; Fri, 8 Mar 2024 15:11:02 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2105.outbound.protection.outlook.com [104.47.23.105]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wkwfjmyah-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Mar 2024 15:11:02 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IcTfJNwaMwH0GDR0oF+CvVcDAA9jMhQSAnk0HcnmiwCaURyB1yRHO8L/5Aode/YfuDShxFFtIOicIy4PAXxzcaE8wcDWD8VoQHAyGx0e6B9tnU/vVHEQmjEl1H3Ke9orforZIfTztFjpaTvJmj/MZLn01xvTjuull4yQT2UQOrsHAM9A6XBsyPXRAmxu1J2qHHlWzvDOgTnVm+5Ky6+w+kQ44XHSRTH4f74ewogyiUketMy4fRtaPwdMhyAPi36XTJc0iwO7Fdf3CaYyDEuIoUWu/7pNLRzFHH6n0P9ExOO0NGNe1oU5MmqTf2WzRWtlRAAvMne+6jScBFi5ajlnww== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JgEMkt8fd8fYHvKq5/rf0xlR2f/FIPqdnQJBSPMulfc=; b=FHvRq954DQ1T/iwjLHUscoIS1UwuJHbz0/fD3/exHr8szLf/2hc+y2hYybYZI8jmmOgB6IL5dNQwSMMT5BbC6uMxvCQWBvB8E/gnG+4gxLKattvxCbO3cLPgUyZoL2JE11VHrtY+kYcJNFnEIgUvDBSWSsBOwRm4CzsQojAFN27p+d5CxC0PaLE5QQM6umQ+U9mfzE4ygQ8LCk1x5TDZbC5n+MBdzuJ0WQnofvujqc13dORoJ/zb2sgxQ2ad3V1yDICbiT3GLz8WAVKECem8ayZdukku10QJEe+BdX2KpZS+o6pUrO3t5PEkg8ZVnc4uQK+zCdSOFV7kO2YF9NWUoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=tdk.com; dmarc=pass action=none header.from=tdk.com; dkim=pass header.d=tdk.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tdk.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JgEMkt8fd8fYHvKq5/rf0xlR2f/FIPqdnQJBSPMulfc=; b=BWpdWFZCAQznlnyizR7p61g3ZCK88ZXn3hOubl0pleQj9sMS/OZ04nrHVLfdpziiI/G4EtfGD3Uvph7HBaLSjmTivpj9UweN4ICGE9g+OkNtSWX+h8k0AKCnE9Buwj+D4+FybI01jgBzvlRBk7yDc1sK54wFmFlu/3gKw/v5YHDRQbLUY7eGo5AK3G5Lt+gvLqPOGMqXAskHqCLQXPLvnuZ3uhZbQl+xQsRtaDdXAvhIW82PdMg9SX6cL1PHELCYk3na1TYzv9GJF1XQ6Vy57TAEKdNA5/nDR1ViKpPQug/OzE5VC+IXBMcZ6gTe6FkHv/Qi7OPjaOTOI7bQx/fJBQ== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TY3P286MB2564.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:22c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 15:10:43 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::9119:3ad4:c68d:9da2%5]) with mapi id 15.20.7362.024; Fri, 8 Mar 2024 15:10:43 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org Cc: lars@metafoo.de, linux-iio@vger.kernel.org, Jean-Baptiste Maneyrol Subject: [PATCH v2 4/4] iio: imu: inv_mpu6050: add WoM suspend wakeup with low-power mode Date: Fri, 8 Mar 2024 15:10:23 +0000 Message-Id: <20240308151023.379705-5-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240308151023.379705-1-inv.git-commit@tdk.com> References: <20240308151023.379705-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO4P265CA0230.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:315::6) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TY3P286MB2564:EE_ X-MS-Office365-Filtering-Correlation-Id: c527ef31-4222-42c4-22c7-08dc3f81ecc0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FjQfz2VdvcQj9P6TSzdQFDFl4evfNFclmG59238zgfpXySmaxKV3uB10eAIkx99r9uBsMTBjrVnrjGk1h6QhjG0TLoApWysfs5ndH8+QW/Yc7uSDOvO+Vhh+G9sHX783tUwTN1j0V0EemGFCpAgrwtjKd0mkrEgyHo1skQZE+PeNgJArpgFs1kslwNaLuzw4EW3yJ20FUnPLW7DD5GEbO6n4xPT3D6e2o1EOUfbifycjoy7RV82hDkHD/tBAQKE2UeZxgVsLRHALmMsa+X0+co8v1wJw9r2psOc69SnYcTbHLWq7FMvL/FAhdYUCc4Trt8uI2LOl1/hDxrrqdE1ZmjDW2Rtk6Mk6bjONfcdHwUqBMbXHFpRLVYxAucErmgVLmtYcsXh+Cqt8pl/NiPk0VQ6qO0ygJFUU4Z5wlJCAbJkjVHQvlscl6+EAR7L+0LYe+XP11KSuuGX3NYHNatLLzgQ5GsZo2en1l4zDP989WBt25vhTSN9sa2qFzhGL35H0P7o8BURh2uWyBY9GX0OK5NdcwXAJsKMSJSpCjgFgws0eckGsJKN5gcGQney3BxnmGVr1su53wYTYteh1uNeEiDTCyEnTsHlDEiu6L97RvmIZ/eZQ/QkfD9SpVhhXCHvdkmjsoe5om4U3pbc3n2z/yBX6Ll4RX6SGkf4zBwzV00whPXA9+5lndqbL7H/WHS5OUiQGORiDInXVSGfAATTEkGeF94LRLukpz/yNyQNLhliM3gebXahKivYGYA0Nq4m4 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(52116005)(376005)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 67zLWmXx2V0GEEd1HbsS6RuGqh+74qg7kovAHBrVdFq1yeic3OqazulL1UkKPtHZevLuS/oEXFm4zpG7u3errhckTa4Pc23xX+lVEXnHZI/dzlZP6PNfGFZU6BY+a+SmCcqKiZxlsWSxq88OhlaxIEhxEpcJs0cD9MhT+fjnN08ot9U/e1u+XfaZAosMpGffRJnslsAXi9qEtBeAPi47+R4OeGjRqGE3cF+xX21tQhYxrGU407OCKhaKkFJ9aUjWXt4uRqySfDyiEltVjK4eColTVEAVGPLASpCLY+rQRrP35BLurNngo6GQ8iR27NNfILkP3N5mIOxdX5sFM2XB4QnIY8XLLICL1ARjuuP+3By7CGNyLWFE9YrNWjKhsFGt3oEeIVf3JNH2we098yM5+wR8a6AdWqVuVbhWUZqTfolpoxHCQ2g+wT15YFMYsT4Q5DvwfRtY6Z5ktdW3BgqdYyuN+8uHPSmjzM2NSb0tMBNW17kTbqUwlhNZi9Bpi7x1Kidl8bDWvzhtQLbB6UA7odL6logErCsrsYg9V5AmCaZAGMje9p8Av7CMgvURND3JRMFYbQ/VjC7UrwLpuj4B6KRt1TjmmI369CUAeMg/l2/xoUsBeLcdvBKx4KrVs1H/9xmP5EzeOQVe0aj1ZuS4htKx5931aGVyVuZ4Y7WEZDGBAmYXTsxQjsQPc7mp3Jil4R3KQrhcmh7WcVJ+E6HQrLiNVvgOmTHF8licrsVKzhxrBaKKM80hgfK/779850GGimU5VLB8f/tMP+m9RQvn2cvNI7sLjvRl8XaRY5+mkErfKEglw9OsTIzDbvn7AYNB1VRLtQ6cTgkg5X/kPQ8aY39kO5uo2pSIhQVak4BwAWW5uJiCPqZha2ykkZJau4utG0vZTNOS7lqZXjUAvmP8qaNa6XzTZ9L93xSu2DZz9QzOpMKzYZjx1unIcwPvT2H1IP5pYOnvk6WqPmZtYoN1aVNnW1750SHiZ4GhAcgQ741q5mIc0c8OSCxc6RJHYNG+QZKuxqUbS12VcViVoOTMT4vYHJ/QnlQFHLeSDwYe0IbkM8b5x2dpEb97HW+XhgHE2MSP/RpaVI1UpZHoYJaMNrr5bTJtXnopmY1v4cGA7KYJpUGmcU700wRdU1hrD+QRcWcnb0aVbSnIeHbggPk5ChEOhff6S4qyk/J/bYgVD99hNqrfcH+sxGt95L0fSs7Plq2tHgio4hdRci3P2bqSL2NYf2pUZwmxV3exptgZ5wZm/Nz5PhukPiZS7vmvvw6B/SDzk5g6IIcisIfl1v/2DQvmmv+eFbu2j0SAUdFBr6VytQ1uRqp/dpmg0PSo5uLuqtrHgA5Z7XpjiCCAAo9zW5ganwRL+XlbHIQ1dGAHyIiproNg6YJBomXsn9GxyX5q1ndZIMCxw9CMmZ3S4LUdJ3xHJ3Jl+NYMm4ZNvBI0knjiaa0qle6RZ1NRfn5IPVG2gBVaRPABhqrtLhg+IYX6UA0xu95F5hrJiPt1pbhhs61sLU0OnMgiaAenn7gHBcbKN7v5NZs6eWjuaI89EA+ON/GjNp516FVVGAnWuUK8Q8Gkkf/RiPWJogom8eEItw3v X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: c527ef31-4222-42c4-22c7-08dc3f81ecc0 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:10:43.6478 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 7e452255-946f-4f17-800a-a0fb6835dc6c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Sz2J0NGvYlMJw8uVZWTGkXF5GKz3i4GFupX9X5uAb79E8HyUd3iOgvc74pgnqufM4XltdHC9a70m5UY551LAgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB2564 X-Proofpoint-GUID: vb4MS-_oSLgxh46uZJcDhmbifuszo92I X-Proofpoint-ORIG-GUID: vb4MS-_oSLgxh46uZJcDhmbifuszo92I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-08_08,2024-03-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 impostorscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403080122 From: Jean-Baptiste Maneyrol Add wakeup from suspend for WoM when enabled and put accel in low-power mode when suspended. Requires rewriting pwr_mgmt_1 register handling and factorize out accel LPF settings. Use a low-power rate similar to the chip sampling rate but always lower for a best match of the sampling rate while saving power and adjust threshold to follow the required roc value. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 175 +++++++++++++++++---- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 14 ++ 2 files changed, 156 insertions(+), 33 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index ddc905bb74d6..17844390b786 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -288,7 +288,7 @@ static const struct inv_mpu6050_hw hw_info[] = { }; static int inv_mpu6050_pwr_mgmt_1_write(struct inv_mpu6050_state *st, bool sleep, - int clock, int temp_dis) + bool cycle, int clock, int temp_dis) { u8 val; @@ -302,6 +302,8 @@ static int inv_mpu6050_pwr_mgmt_1_write(struct inv_mpu6050_state *st, bool sleep val |= INV_MPU6050_BIT_TEMP_DIS; if (sleep) val |= INV_MPU6050_BIT_SLEEP; + if (cycle) + val |= INV_MPU6050_BIT_CYCLE; dev_dbg(regmap_get_device(st->map), "pwr_mgmt_1: 0x%x\n", val); return regmap_write(st->map, st->reg->pwr_mgmt_1, val); @@ -317,7 +319,7 @@ static int inv_mpu6050_clock_switch(struct inv_mpu6050_state *st, case INV_MPU6000: case INV_MPU9150: /* old chips: switch clock manually */ - ret = inv_mpu6050_pwr_mgmt_1_write(st, false, clock, -1); + ret = inv_mpu6050_pwr_mgmt_1_write(st, false, false, clock, -1); if (ret) return ret; st->chip_config.clk = clock; @@ -359,7 +361,7 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, /* turn on/off temperature sensor */ if (mask & INV_MPU6050_SENSOR_TEMP) { - ret = inv_mpu6050_pwr_mgmt_1_write(st, false, -1, !en); + ret = inv_mpu6050_pwr_mgmt_1_write(st, false, false, -1, !en); if (ret) return ret; st->chip_config.temp_en = en; @@ -466,7 +468,7 @@ static int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, { int result; - result = inv_mpu6050_pwr_mgmt_1_write(st, !power_on, -1, -1); + result = inv_mpu6050_pwr_mgmt_1_write(st, !power_on, false, -1, -1); if (result) return result; @@ -496,22 +498,9 @@ static int inv_mpu6050_set_gyro_fsr(struct inv_mpu6050_state *st, return regmap_write(st->map, st->reg->gyro_config, data); } -/* - * inv_mpu6050_set_lpf_regs() - set low pass filter registers, chip dependent - * - * MPU60xx/MPU9150 use only 1 register for accelerometer + gyroscope - * MPU6500 and above have a dedicated register for accelerometer - */ -static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st, - enum inv_mpu6050_filter_e val) +static int inv_mpu6050_set_accel_lpf_regs(struct inv_mpu6050_state *st, + enum inv_mpu6050_filter_e val) { - int result; - - result = regmap_write(st->map, st->reg->lpf, val); - if (result) - return result; - - /* set accel lpf */ switch (st->chip_type) { case INV_MPU6050: case INV_MPU6000: @@ -530,6 +519,25 @@ static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st, return regmap_write(st->map, st->reg->accel_lpf, val); } +/* + * inv_mpu6050_set_lpf_regs() - set low pass filter registers, chip dependent + * + * MPU60xx/MPU9150 use only 1 register for accelerometer + gyroscope + * MPU6500 and above have a dedicated register for accelerometer + */ +static int inv_mpu6050_set_lpf_regs(struct inv_mpu6050_state *st, + enum inv_mpu6050_filter_e val) +{ + int result; + + result = regmap_write(st->map, st->reg->lpf, val); + if (result) + return result; + + /* set accel lpf */ + return inv_mpu6050_set_accel_lpf_regs(st, val); +} + /* * inv_mpu6050_init_config() - Initialize hardware, disable FIFO. * @@ -1007,6 +1015,84 @@ static int inv_mpu6050_set_wom_threshold(struct inv_mpu6050_state *st, u64 value return result; } +static int inv_mpu6050_set_lp_odr(struct inv_mpu6050_state *st, unsigned int freq_div, + unsigned int *lp_div) +{ + static const unsigned int freq_dividers[] = {2, 4, 8, 16, 32, 64, 128, 256}; + static const unsigned int reg_values[] = { + INV_MPU6050_LPOSC_500HZ, INV_MPU6050_LPOSC_250HZ, + INV_MPU6050_LPOSC_125HZ, INV_MPU6050_LPOSC_62HZ, + INV_MPU6050_LPOSC_31HZ, INV_MPU6050_LPOSC_16HZ, + INV_MPU6050_LPOSC_8HZ, INV_MPU6050_LPOSC_4HZ, + }; + unsigned int val, i; + + switch (st->chip_type) { + case INV_ICM20609: + case INV_ICM20689: + case INV_ICM20600: + case INV_ICM20602: + case INV_ICM20690: + /* nothing to do */ + *lp_div = INV_MPU6050_FREQ_DIVIDER(st); + return 0; + default: + break; + } + + /* found the nearest superior frequency divider */ + i = ARRAY_SIZE(reg_values) - 1; + val = reg_values[i]; + *lp_div = freq_dividers[i]; + for (i = 0; i < ARRAY_SIZE(freq_dividers); ++i) { + if (freq_div <= freq_dividers[i]) { + val = reg_values[i]; + *lp_div = freq_dividers[i]; + break; + } + } + + dev_dbg(regmap_get_device(st->map), "lp_odr: 0x%x\n", val); + return regmap_write(st->map, INV_MPU6500_REG_LP_ODR, val); +} + +static int inv_mpu6050_set_wom_lp(struct inv_mpu6050_state *st, bool on) +{ + unsigned int lp_div; + int result; + + if (on) { + /* set low power ODR */ + result = inv_mpu6050_set_lp_odr(st, INV_MPU6050_FREQ_DIVIDER(st), &lp_div); + if (result) + return result; + /* disable accel low pass filter */ + result = inv_mpu6050_set_accel_lpf_regs(st, INV_MPU6050_FILTER_NOLPF); + if (result) + return result; + /* update wom threshold with new low-power frequency divider */ + result = inv_mpu6050_set_wom_threshold(st, st->chip_config.roc_threshold, lp_div); + if (result) + return result; + /* set cycle mode */ + result = inv_mpu6050_pwr_mgmt_1_write(st, false, true, -1, -1); + } else { + /* disable cycle mode */ + result = inv_mpu6050_pwr_mgmt_1_write(st, false, false, -1, -1); + if (result) + return result; + /* restore wom threshold */ + result = inv_mpu6050_set_wom_threshold(st, st->chip_config.roc_threshold, + INV_MPU6050_FREQ_DIVIDER(st)); + if (result) + return result; + /* restore accel low pass filter */ + result = inv_mpu6050_set_accel_lpf_regs(st, st->chip_config.lpf); + } + + return result; +} + static int inv_mpu6050_enable_wom(struct inv_mpu6050_state *st, bool en) { struct device *pdev = regmap_get_device(st->map); @@ -1847,6 +1933,7 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, irq_type); return -EINVAL; } + device_set_wakeup_capable(dev, true); st->vdd_supply = devm_regulator_get(dev, "vdd"); if (IS_ERR(st->vdd_supply)) @@ -2012,16 +2099,27 @@ static int inv_mpu_resume(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct inv_mpu6050_state *st = iio_priv(indio_dev); + bool wakeup; int result; mutex_lock(&st->lock); - result = inv_mpu_core_enable_regulator_vddio(st); - if (result) - goto out_unlock; - result = inv_mpu6050_set_power_itg(st, true); - if (result) - goto out_unlock; + wakeup = device_may_wakeup(dev) && st->chip_config.wom_en; + + if (wakeup) { + enable_irq(st->irq); + disable_irq_wake(st->irq); + result = inv_mpu6050_set_wom_lp(st, false); + if (result) + goto out_unlock; + } else { + result = inv_mpu_core_enable_regulator_vddio(st); + if (result) + goto out_unlock; + result = inv_mpu6050_set_power_itg(st, true); + if (result) + goto out_unlock; + } pm_runtime_disable(dev); pm_runtime_set_active(dev); @@ -2031,7 +2129,7 @@ static int inv_mpu_resume(struct device *dev) if (result) goto out_unlock; - if (st->chip_config.wom_en) { + if (st->chip_config.wom_en && !wakeup) { result = inv_mpu6050_set_wom_int(st, true); if (result) goto out_unlock; @@ -2050,6 +2148,7 @@ static int inv_mpu_suspend(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct inv_mpu6050_state *st = iio_priv(indio_dev); + bool wakeup; int result; mutex_lock(&st->lock); @@ -2066,13 +2165,15 @@ static int inv_mpu_suspend(struct device *dev) goto out_unlock; } - if (st->chip_config.wom_en) { + wakeup = device_may_wakeup(dev) && st->chip_config.wom_en; + + if (st->chip_config.wom_en && !wakeup) { result = inv_mpu6050_set_wom_int(st, false); if (result) goto out_unlock; } - if (st->chip_config.accl_en) + if (st->chip_config.accl_en && !wakeup) st->suspended_sensors |= INV_MPU6050_SENSOR_ACCL; if (st->chip_config.gyro_en) st->suspended_sensors |= INV_MPU6050_SENSOR_GYRO; @@ -2080,17 +2181,25 @@ static int inv_mpu_suspend(struct device *dev) st->suspended_sensors |= INV_MPU6050_SENSOR_TEMP; if (st->chip_config.magn_en) st->suspended_sensors |= INV_MPU6050_SENSOR_MAGN; - if (st->chip_config.wom_en) + if (st->chip_config.wom_en && !wakeup) st->suspended_sensors |= INV_MPU6050_SENSOR_WOM; result = inv_mpu6050_switch_engine(st, false, st->suspended_sensors); if (result) goto out_unlock; - result = inv_mpu6050_set_power_itg(st, false); - if (result) - goto out_unlock; + if (wakeup) { + result = inv_mpu6050_set_wom_lp(st, true); + if (result) + goto out_unlock; + enable_irq_wake(st->irq); + disable_irq(st->irq); + } else { + result = inv_mpu6050_set_power_itg(st, false); + if (result) + goto out_unlock; + inv_mpu_core_disable_regulator_vddio(st); + } - inv_mpu_core_disable_regulator_vddio(st); out_unlock: mutex_unlock(&st->lock); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index e97a63ad2c31..6ba9d42b2537 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -304,6 +304,7 @@ struct inv_mpu6050_state { #define INV_MPU6050_REG_PWR_MGMT_1 0x6B #define INV_MPU6050_BIT_H_RESET 0x80 #define INV_MPU6050_BIT_SLEEP 0x40 +#define INV_MPU6050_BIT_CYCLE 0x20 #define INV_MPU6050_BIT_TEMP_DIS 0x08 #define INV_MPU6050_BIT_CLK_MASK 0x7 @@ -335,6 +336,7 @@ struct inv_mpu6050_state { /* mpu6500 registers */ #define INV_MPU6500_REG_ACCEL_CONFIG_2 0x1D #define INV_ICM20689_BITS_FIFO_SIZE_MAX 0xC0 +#define INV_MPU6500_REG_LP_ODR 0x1E #define INV_MPU6500_REG_WOM_THRESHOLD 0x1F #define INV_MPU6500_REG_ACCEL_INTEL_CTRL 0x69 #define INV_MPU6500_BIT_ACCEL_INTEL_EN BIT(7) @@ -451,6 +453,18 @@ enum inv_mpu6050_filter_e { NUM_MPU6050_FILTER }; +enum inv_mpu6050_lposc_e { + INV_MPU6050_LPOSC_4HZ = 4, + INV_MPU6050_LPOSC_8HZ, + INV_MPU6050_LPOSC_16HZ, + INV_MPU6050_LPOSC_31HZ, + INV_MPU6050_LPOSC_62HZ, + INV_MPU6050_LPOSC_125HZ, + INV_MPU6050_LPOSC_250HZ, + INV_MPU6050_LPOSC_500HZ, + NUM_MPU6050_LPOSC, +}; + /* IIO attribute address */ enum INV_MPU6050_IIO_ATTR_ADDR { ATTR_GYRO_MATRIX,