From patchwork Sun Feb 25 16:00:24 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: 13570931 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 F0EFD171AB for ; Sun, 25 Feb 2024 16:01:14 +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=1708876877; cv=fail; b=Z4kPZLF7r1KOJQUUPI9IyT9X6hHQgrnbOUoFxg5EJQkbo4h3LxK8ZDu0BWgYhDOijSlrv3ukLlAK45hSZuxavqXFVMjoLKl50ZRSOt/ZR5aq7FJFxM8jNxEWCvFP5Qku39mt1DW/pesQRlqccWI6+D3rXygSXaLEAqBan0uNIf4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708876877; c=relaxed/simple; bh=8mizCPmEZ5GR980dSpjVpQjLTfAepjOOXvM90ARZBAw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=JEQ0S4Vb8EX+9q/vrWOw1fv/e9SwaJnb8xZZhaJaXv89OMb53ajqCwc0OuU3cYTK+ADNdg9M/Ccnhs1iF9qRR0bjFOuYrx0UbsV6mG2BXkYdRXzxl1r4B4Cv7MScRVG9zXPd1g+L9G4AJxhSFO37PozW3+kBFJwFL+E+Pnp80/A= 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=AYMUHwA0; 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="AYMUHwA0" 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 41PFo2ci018247; Sun, 25 Feb 2024 16:00:58 GMT Received: from jpn01-tyc-obe.outbound.protection.outlook.com (mail-tycjpn01lp2169.outbound.protection.outlook.com [104.47.23.169]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wf9tjrf3v-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 25 Feb 2024 16:00:58 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YCXJI5u8AsQAQkVtHoXDPEAVHXy9bFeSlIfg/4VlZ+KeBu1u6iwmlIXCaYhcE7TaFuslBHOgPIX1GvIwAYM+9/5T/viS6ox1UTpq+uzekxLMOV8+TJF6uWJ5A6ekIxK0YGaMxWqggpE6zUduLTbaLbsBO0xbn2hG5aF4hM6dPg1sABsUGIMwt7ox+rB6Q1CcI0/0+PLcI162X00u8Ht3y2aNHk8qOuzxoFKWDdh2tF3HFrk93uCXGLU/DeP22CqOjPIMmL6LrNqg7hnCZHtWf1dnKze/YVXDbJRfDVVDo7nPkeC076r5RvV/7BFu8gd+bqd/1GocK6BR7wQjqd5jXw== 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=DWTvL4Q4/9g+MPSfDFKg4niRiaJAz0yjSeoXJ1Gv9iQ=; b=XPwN+baZZbvcTdPHsYT1+A30P8PyIl7tP69wXQ+MNnMOfqT9jEAKU8jDgOY2I/D0pekB931CU6RduMm+yAPxOO9x1EvnfWvpmNgkg3HVv0OGaqgcQiClm95YhEAr1hFsXfCK7p0oYGJ5rk+0hPKD2FwlpIv4RRFIBMmiRU5w7wVcNSBs+rVLJcwi2hoQ0laUN+gF2xqKjt+yOhBtEM/Skzt27D5ODH9aAR5424hhHtLkNxXnFVG1fNc66EvvAJKI9BtnkYOoA+919LYhBn8W4GJXkVmBLA8rb34sP/JbLsTD7OF+fPMPyWZokQ1Jk0A4LXvzrwIGkZBrNnoh/ReN5A== 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=DWTvL4Q4/9g+MPSfDFKg4niRiaJAz0yjSeoXJ1Gv9iQ=; b=AYMUHwA0duWHsPbZUBDjzhpnTX2SW3uvk4ow1TSBQiF1gQtELLpmEoqHm1xWDQE7wkD3wAdbE/J2b4QOhqstzZx1bZjnrM1XeszXygwziNnFYN5uTpFpNBCETlPXiACkff+DSYzWdOWxd3Wi4rMMeU2UXkbNwdSxxGGEvBIvq6OdSva6yGnLDLST1e4SF0bQXlicDDotmczshZaLDo0PvphvjXcJs8b38Jk9bjRyYm9hvKh6jb/J4WomeouMu22EdmxqMSCzRyxKrKGeplKpOHtLIQMoHMnLc8CVx/VHQvsV22xS2D+hBnHui88IefgiuaWVC1sSNuqOecrrJLSbkw== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYTP286MB3462.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:39b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Sun, 25 Feb 2024 16:00:50 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f%4]) with mapi id 15.20.7316.018; Sun, 25 Feb 2024 16:00:50 +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 1/4] iio: imu: inv_mpu6050: add WoM (Wake-on-Motion) sensor Date: Sun, 25 Feb 2024 16:00:24 +0000 Message-Id: <20240225160027.200092-2-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240225160027.200092-1-inv.git-commit@tdk.com> References: <20240225160027.200092-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LNXP265CA0028.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::16) 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_|TYTP286MB3462:EE_ X-MS-Office365-Filtering-Correlation-Id: 508d52e5-9795-4622-c64d-08dc361aefa8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mcha3AM5JahDduR8TX8bQIPMxV0WRKcc5Yw9YIZrvx6mlPSV2n4ozuRvWzXTrxelxnUNduBIS1QzmeEQS13WpOwXbrlF3j8NOPnwggJ/qzLDS3Bc3MlLnk3YPgruejuvYSNikemWAsx3I9xp9w9uO0LZEuJN+4rhbwtnhq8rDtNOXC4aahvKwN6uD7w8M6teQKX9Cw7ChbfEyInhIKYm60ywc6VhtDGylkiWupGn5g2oT1lpFC08bOptZlecm9ksXwA/0vuHCPoAPucBsMugmPHcs5kj4lqawNVcFDKW6ktjycpcOZHE/yEjM0dvhYPNsoQtBVGIwFgGm1dmSwoBkjPR5s/WkLG5BsmENgU9GSIU2uDghfB8vjAY4hvWlBxN+gy41uGliL97o7V7lIQ2TGblL9IUAh47YVOFOi+oDQJ4HxSl0nSzKle1QhbW7xjxOo4W5Vo+Sp3GWOzroMLb9bhg0V05DxxGvvxZJvhk9vnMO+vbR7wu71cFJ9//s/rAyZTmmLLYCU60TwORNG7gGHtZGvE0me0DCOe2B/5YVDz2jyjktF6xz8ltxicL1buZsGU8zQ69gM8JPojw0gy7vssq/vjPP4w36Ujxyeh9u55lsIAfPEZlhlcUXVoGEszBwNOZT+DmFAveA6EjDV3bfg== 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)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?aSpNF8FvcO8H6/QWDggVn1As2Hs6?= =?utf-8?q?qYST1+aFEBTS0gGGKAi2fuC0J6jUbcmpKi3zJSgukb+aiUAjhSe8x+it4Ohzjsgnr?= =?utf-8?q?enOUyLFhhqWr8dUtFvTfmkH/TQzDFoV0oIe9wrqmJ1cn/Z5uCthChzf9NprMRi7fy?= =?utf-8?q?Ay5aa5dlr60CbGy7tEoTSOu23xJkF6Q3h1g9w4N6nTbXoC6uk/NQOF4H2iDV/ppwE?= =?utf-8?q?VSmXG0rndHyFAj2Ybx0iGs1j7JB0O7HgMZHR8GH+tI+6OHnH/CYqsH3udZRrirLFL?= =?utf-8?q?MLaFVRxAMponbvpxe+1aLSHoskPpXVwVu2I6eA39EhsbujRfK6bbYFxPV0G8vtbMK?= =?utf-8?q?fwcauVZsfLbGnS/VYuCfqdV2cB6rxqxFVZI4zMnxctQctbvHLD+wc4SWZi4RUbApl?= =?utf-8?q?YncpUeW9y2LqEENnB6AHQWh/+6r1e8eXFHM/9pYR/OBAx86Uilcg+WOo1jA4Ek23o?= =?utf-8?q?YwQ/furxOmsGLRpXCRte4k9pnbQ/efdVGSstzLKUC+qN8OkzBcDshqbOvdrrDmd6e?= =?utf-8?q?MWxFMN5Gxqph+a1/brkOAAq55r0WoR63k334VRoWkq9ZYy7bsi4u1Yu+N3juisWtJ?= =?utf-8?q?DegoRA9JumrMtKBMTYtTr+aTuKeCN4tL65e1V+RJzV/6EnLYZZllVCDHWcygFnFdL?= =?utf-8?q?X8K3SvTTiTKgcPi4lDcIJfe9EsXF9YPSUyxUyRkAykSlzBKiRVxt42LFjSsv56IuX?= =?utf-8?q?cxCNofe/WhVtC3LFWhT+P/8LTcYlqFkWXCsEenHkkBROI0AkqYKH8f1m3diL9Y53b?= =?utf-8?q?ct9kL7jT/U2I3r5bsS6Qkw9U9g6ICGYDmR13BLbyK7qVgQHtHKBi9bx+H/ZwHDfgq?= =?utf-8?q?uN3pH1S4o4cLJ9WVq3im+fyDHcV/xfndnZixG8BdDQlPGCnyHXQps/NFLO4PHVsn4?= =?utf-8?q?vUM91fGsKd/MRv8hxnhpzXRRXIsocZf/XtF4tm9azn+cV+RaXIt7GBH0J0XhgnfBf?= =?utf-8?q?kMAKrblg8dS2P85qORQExsBxW+evwXOKdgv4SRqwfLsFr50VWLpxexO907ci3KTWi?= =?utf-8?q?zYrKDdtsFuNhsRfUa4yFUFfkYZOBEAmoY7LwI+OQbo+tVao8oyzvkTnrGdEztWbA0?= =?utf-8?q?BhRvUY4zoRVWrkx0JdOyf9im8L4ioxK2GClVIDTlCIE0dV30o2wxpGMBVfuVyhD/q?= =?utf-8?q?mhdiy86dSjDWkUe/VCyXNe6Uv8ao8JiQvssoDqJBjqfmyDAcfFJ3fQLl/52cuM3zU?= =?utf-8?q?Pkvd8+d8rdtL8Sl2hSsvIAOVt3dwfBAeDWQp7mki9L5YT2loBGqzo4mfxyy6F99A6?= =?utf-8?q?rAXpEYKX9JGddpzIrBisZVWwEnjUF+yJZobJcXXt8H3rRIso+NkeBxT88EKaQHtuP?= =?utf-8?q?ZtEdPtUtLpitx391DV6VS/USzF83lSykqFCy7ailahHyoeh14/AnHwBWQ+PgWIs6e?= =?utf-8?q?zNSICk11k33HBec6+/r+jX/7GDu/fk1ARQliwjoyXLb3C/7Cz9/+Etg/j1MmJWeK6?= =?utf-8?q?DXqUEqFVW1Cw9Dl9XTRqqRmPLkuY0/i4lOmABMAF6SNY0uZY7frCcwZpyGHySJEpi?= =?utf-8?q?oTP/HfqN6fZc?= X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 508d52e5-9795-4622-c64d-08dc361aefa8 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2024 16:00:50.0661 (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: pH12GynR6iLHD8bfKopYbsNw5v2B7706e17Ln4RGI4TcDchWLfu7jvOBy5Dp0sIUEZok30KEpwWd+rWXXSt32g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYTP286MB3462 X-Proofpoint-GUID: D6-NI9FV6mn0-hlb4r52xkp3OObMHTjv X-Proofpoint-ORIG-GUID: D6-NI9FV6mn0-hlb4r52xkp3OObMHTjv 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-02-25_18,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 priorityscore=1501 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402250127 From: Jean-Baptiste Maneyrol WoM is a threshold test on accel value comparing actual sample with previous one. It maps best to magnitude adaptive rising event. Add support of a new WOM sensor and functions for handling the corresponding mag_adaptive_rising event. The event value is in SI units. Ensure WOM is stopped and restarted at suspend-resume and handle usage with buffer data ready interrupt. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 237 +++++++++++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 17 +- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 6 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 14 +- 4 files changed, 261 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..fca7fc1ba4e2 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -332,7 +332,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 +345,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 +447,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 +911,202 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev, return result; } +static int inv_mpu6050_set_wom_int(struct inv_mpu6050_state *st, bool on) +{ + unsigned int val; + + val = on ? INV_MPU6500_BIT_WOM_INT_EN : 0; + + return regmap_update_bits(st->map, st->reg->int_enable, + INV_MPU6500_BIT_WOM_INT_EN, val); +} + +static int inv_mpu6050_set_wom_threshold(struct inv_mpu6050_state *st, unsigned int value) +{ + struct device *pdev = regmap_get_device(st->map); + int result; + + mutex_lock(&st->lock); + + result = pm_runtime_resume_and_get(pdev); + if (result) + goto exit_unlock; + + switch (st->chip_type) { + case INV_ICM20609: + case INV_ICM20689: + case INV_ICM20600: + case INV_ICM20602: + case INV_ICM20690: + st->data[0] = value; + st->data[1] = value; + st->data[2] = value; + 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, value); + break; + } + if (result) + goto exit_suspend; + + st->chip_config.wom_threshold = value; + +exit_suspend: + pm_runtime_mark_last_busy(pdev); + pm_runtime_put_autosuspend(pdev); +exit_unlock: + mutex_unlock(&st->lock); + 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 mag_adaptive rising) event */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_MAG_ADAPTIVE || + 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 mag_adaptive rising) event */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_MAG_ADAPTIVE || + 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); + unsigned int value; + + /* support only WoM (accel mag_adaptive rising) event threshold value */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_MAG_ADAPTIVE || + dir != IIO_EV_DIR_RISING || info != IIO_EV_INFO_VALUE) + return -EINVAL; + + /* 4mg per LSB converted in m/s² in micro (1000000) */ + value = (unsigned int)st->chip_config.wom_threshold * 4U * 9807U; + *val = value / 1000000; + *val2 = value % 1000000; + + 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); + const int max = 4 * 255 * 9807; + const int max_val = max / 1000000; + const int max_val2 = max % 1000000; + unsigned int value; + + /* support only WoM (accel mag_adaptive rising) event threshold value */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_MAG_ADAPTIVE || + dir != IIO_EV_DIR_RISING || info != IIO_EV_INFO_VALUE) + return -EINVAL; + + if (val < 0 || val2 < 0) + return -EINVAL; + if (val > max_val || (val == max_val && val2 > max_val2)) { + val = max_val; + val2 = max_val2; + } + value = val * 1000000U + val2; + value /= (4U * 9807U); + + return inv_mpu6050_set_wom_threshold(st, value); +} + /* * inv_mpu6050_set_lpf() - set low pass filer based on fifo rate. * @@ -1326,6 +1540,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 +1924,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 +1959,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 +1973,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 +1999,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..519c1eee96ad 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; + u8 wom_threshold; }; /* @@ -256,12 +260,14 @@ 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(7) | BIT(6) | BIT(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(7) | BIT(6) | BIT(5)) #define INV_MPU6050_BIT_FIFO_OVERFLOW_INT 0x10 #define INV_MPU6050_BIT_RAW_DATA_RDY_INT 0x01 @@ -301,6 +307,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 +331,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 Sun Feb 25 16:00:25 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: 13570929 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 09214168DD for ; Sun, 25 Feb 2024 16:01:13 +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=1708876876; cv=fail; b=ZjZrGmyx1QjhG84ypVgzonfTSIi9oyJmEwRs7Hw8CAY3tIgsRDaDKrq2gkeFsVDIXkccTNxUrWth0fUKXd1XmH63zb0FO8TVbpDIuwnX+LLSWMT+0aYeo48KAzLXnejQaCaCsKFhoAgP6SYE2tel+c4qdbwWwrPfd7EMiXOMMUw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708876876; c=relaxed/simple; bh=dk9+YV+9XAe5leDx5AFCAOQysZagOG2MCwHpBmNYxMY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=pYkxpeZ+JWJZno3zvx6mSmydddLTkqEarODJ6f/wwIpbYkn6DdtR/5CZP0AjB3HyawviUbak+Iz7l9TfOG0P9DHve87Fz3yu3sL8/hhuMLP/31Ct0UW2IwfzuCUgYz94ABtdqBzqNO8GOH99DP/ylhSL3rJHFa2u8FxipZlPor8= 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=kfbJaBwi; 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="kfbJaBwi" 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 41PFo2ch018247; Sun, 25 Feb 2024 16:00:58 GMT Received: from jpn01-tyc-obe.outbound.protection.outlook.com (mail-tycjpn01lp2169.outbound.protection.outlook.com [104.47.23.169]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wf9tjrf3v-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 25 Feb 2024 16:00:57 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lf9cfEBVJpeCglWpEsr+ehctH8dHFG9OjXvOpvYCT2UrWE/kovNZGp1PisXoaatStGpiBz9RwpJYDtwYIJzbkaU/V9Ws/nhViqmNhTzC+uOEHyGCt3YNSbJ1yDSYlXH2woLOKYygnTkGCMyKryiUWX7xMC9QrGumAA5hZMNMnxONRo9nCMtJiF4H7L2pPFnvFRzAX0/MnJyYHW9ogmTc1hUIEcI1DLUAMuDSdv5L7EdcISEYKHhiHs06TfoZfPP00CPdD3Wnn//lzQhDF9lGyz8OyxaOId/pxcVEvzaSqYCd1hhoprrxiN27m/BzzMKuGRD0VAks7ukOppI7Pkl+jQ== 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=KCNVN1XRGRiTNWcrvswYp0UGUrKEINVjMMaHnlVg9G8=; b=ZR7yRSdXbQNd51bzwLKHW87pHfi7oSraFyp85oKuPCwTQUZrdCH40bUjdmQEb0tSB9nbnJ/ZBzKz/WEdBnchcCfsnbZ85NIIjrdymGx02e4XnRq9WnIlditRo3hVnZCgvBOOv4na6FYdarkhxdescgIy7Ud8Cfv7v0B7I1375tOWEim1kBFpUClFgcfFjY50WAdp9ToR6LqhVhziUqRUIeUFtRMhN9gWHKwda77TvTlgkhGtMU2QPKTHSoPKG22q56CPLNjfNhdkny/NmupaGBbP0pdsPLCe5/S0spExzRA4poDYUn3gc7JFlhMN8+vL0fihiQxFeNgELWdp6/8+6w== 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=KCNVN1XRGRiTNWcrvswYp0UGUrKEINVjMMaHnlVg9G8=; b=kfbJaBwizogTIcFpPXIDPwXXZ4XbKX0lz8eOT8azxyl/47rDy7PrVq1mpAXWf609QbZvSH1OcfdozVvujUL228BN2Ps8zYNFXYkwhl4n5LR9ngsc6pYurGplhAf/7KqIxfvXlsf7Vy2SOgmvaiUmyruDnFxg4gRqupohr7cTCexm7DWnOpUTAvQ5pkGNVqvhR0dpcpU+66Jl3BO/kVBpPFzMzz8LvcIPhxgAzJSgiPlLrwHp2hRd1+x6i+CIEGr0d3+fZi4rgkWE1GZ5WtuaPzP+yZG4fWG471bNO547rZTUdNClt3/6eHyM45DCKufG5vC2qj96YMj7SZXVzfGemw== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYTP286MB3462.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:39b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Sun, 25 Feb 2024 16:00:52 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f%4]) with mapi id 15.20.7316.018; Sun, 25 Feb 2024 16:00:52 +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 2/4] iio: imu: inv_mpu6050: add WoM event inside accel channels Date: Sun, 25 Feb 2024 16:00:25 +0000 Message-Id: <20240225160027.200092-3-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240225160027.200092-1-inv.git-commit@tdk.com> References: <20240225160027.200092-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LNXP265CA0028.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::16) 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_|TYTP286MB3462:EE_ X-MS-Office365-Filtering-Correlation-Id: bf540368-3ae1-4a76-8840-08dc361af0e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CTRNF9IT5lf5Mt/4YSF8yTX08Oi4TmtNb+4mE/aJiJKjb7zfyTi+I64TOEr/6oal50GsEKCld6w4FjhacGPvH/uNnouUIYa66hvaphB/DEWx69QTEz64212KPgLx3vDXknaKJ0we+RkkbtrMRGoAvj1ZWrcogACzD3cBqbUSzx7JE/cNQdeIcky+eiV4ZSPyykXzWqYfq+/bc2s6B+Fp12z86Wtgf6GQ32KhMfHJBW1zeMPOe2bDQSRNPuTju55VJmvwrwUgqtjQOWBcB3bgvwlPZG/KnvGkt+zGFSmEc91jenWKCRD4dh6xyXlhYnc3cnfUdVOxM+08TkryXv/CUItNARHCsUOVPRjOMKkUB5A3AZ1DwU0zaF9Ll1WVaPOvs7OJspVroaQG8BiILDTZ2eQ4enFZwi9aAtSttWj5dG1xuOaLufeHlFEGCL2hgUDCFW9/ocl6jW7ALCctwHuB36QTOBBaswEp76NzEOnOjrNt4WGVCPvNZ2ucHT8w/gkPGN3Ov+f7CUOB9Dd6yTWx71++xHusdp1HzO8H/Vk1KCWAE0Hekbau8ExUOg+jgN6aotZ34X7OtyoBImY38Osy7p2IpWzsX1a9uYnGlLrtETIMqrVI2tzK0nSOEy29b7HEjtuAcZiV2LuJrLPll4Sd3Q== 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)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 043ZxxXDb6nD57CBlMflb1zDMAAV2XCPF6lUcHNOFlBYeqqI+biVVbLghcicbREOUsSU0I/O8Kn9KbWJcjvIzZxF9m8fn1mG8w7OCoepKxMd5w3h1umni0yp+8CEI490Nea1OK3c/pprZn67vd+1DaHG4gP195wueQ/L7M0ArEjvwOif5VOUoEAJo+H1US9OII+MTdJ69Aq96GfXIMqrSNuhNJSJbfpR9G7uQNAdxZ5dsH4mOdZFj+3R0nsFVbXja9gFWtmvOtOuiZjfwNi4PZwNyt6630HubglE746p/sRcrT0Gp8/KLOJPNiOP/660wc9cDnaiQwcetI9q7KiwxEAQAEP1QLnwN5tv5gzd+3tK5g3vodMxlRGFPzwsvDsVPh8d9Vw/AnLPGQ4xgIUGjb2b/fxFPdlbEqvUVXiinSpqs3Wn1FwuoXwqIw1ZQJlr47+nldXwzwGYkPbWwlKFq3wK8D9ujHwW7Ef31b2Jub0pE159BSj4laQG7sAI9ezC+Nan4vf/ZNo/rxTLLH5RUx5wN2vEillwrUD3K4wAEa6NRIecpZu2cBhecmPcHfBXVlLP0Gbb/rIPEhlVqmO57mleaHm/UpJimlkB2lhHN924vY6WhV8F2vv3He1ePk3lxSWnaxsO+G2IJdxdM4l0F0aVDTrPpuR+6IEvo+9MT38/huhJSRPzaMN/wRBZQeyde5RvQ3BuwKQmO7hMSvcyDcRLEx6VE6op+nWSRu7Uh+QwrnQHs2s6fBs+5yU/tQtxgW6CDTU12ruLiU1OZUFmWEdFS5qaprfMqIjxHN7lvv4tzR0MeiYXN1SBq3LRjEmlQjFdjYO1RCC1v9cti9E24ciQIV+tEmhOnX/iy7K7IK08CQKLL3aqY4yVgpC4ipcI0fBbfrYNVaThNyCIBi+v2mYXJ8bQJf18J20eG0G5ifmChFX4XJgTFVflpkj0hPCdg7LzSoyrsDbULUwBeJeWuz547SWn0O5ATvSRfnfAh+PB9kojMIOd3X3UEwoWaoZ+UzpVS4T9tv2nxs1mjurFr8CjP0F/XEOkw3whLwahjtaQxcihkQ62+UXkrAOovl+ErDdvhy73rQTiv2rKjstaR5/z1jNh2BbF5ZGZdiMtjK3H8MRxwrEnJRcN8pPHYtgXZ+jflr8RDZbmf0kD1iO736kAjpQGvaNq83stwE0F8iR2kBBF3CMqK0b5Xa1Drbpy6XV1ZGMNwIA6AlZOanLPyUAYerUGT9CEILXynYVpW1yt434XAQ4EVXmj/4eIY2TLqA41rG3nAVLHjqo2RBBJYizYBrW+YW1+1LmDoNSNT9fPqackyXM/pOUVGatvcMjjgheQU0EDROw90yV56Gx6ZOz2K+Q+hq1oQItftqi1gLeY8XSbSzPJzL7w0Q3XWGvBfvZrCv0fzTKpjV0cSJhW7brD8v/o7+vKcjMf1bA5h20r/qrtmaRNkhKOOnw1U5TcWw9X8kZ30+5zJueTy5I33bdbfZeN3S6VDta5bo/j16ZVFk3oL6Ekw5i1eeEBZQgA9c0BxJa7v3azjaJ7fPC0acwJcY1r8mSe7MthXq5YlCjO96AbWe9Spy+GwhIjwNQP X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf540368-3ae1-4a76-8840-08dc361af0e3 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2024 16:00:51.9057 (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: NaQ3P2aG1gGZEFHliawCvK50bU3nGVrKBC5d3S2DIOeEJxcb+JQiUf3neWFwg/B1C8UyENtqhTjziMtHKHD1NQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYTP286MB3462 X-Proofpoint-GUID: -6bCFtZen11USaL7E2UqxQ4WjrIXepFp X-Proofpoint-ORIG-GUID: -6bCFtZen11USaL7E2UqxQ4WjrIXepFp 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-02-25_18,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 priorityscore=1501 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402250127 From: Jean-Baptiste Maneyrol Add WoM (mag_adaptive rising) event in accel channels 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 | 132 ++++++++++++++------- 1 file changed, 89 insertions(+), 43 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index fca7fc1ba4e2..d2544c758815 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -1303,23 +1303,34 @@ static const struct iio_chan_spec_ext_info inv_ext_info[] = { { } }; -#define INV_MPU6050_CHAN(_type, _channel2, _index) \ - { \ - .type = _type, \ - .modified = 1, \ - .channel2 = _channel2, \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_CALIBBIAS), \ - .scan_index = _index, \ - .scan_type = { \ - .sign = 's', \ - .realbits = 16, \ - .storagebits = 16, \ - .shift = 0, \ - .endianness = IIO_BE, \ - }, \ - .ext_info = inv_ext_info, \ +static const struct iio_event_spec inv_accel_events[] = { + { + .type = IIO_EV_TYPE_MAG_ADAPTIVE, + .dir = IIO_EV_DIR_RISING, + .mask_shared_by_type = BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_VALUE), + }, +}; + +#define INV_MPU6050_CHAN(_type, _channel2, _index, _events, _events_nb) \ + { \ + .type = _type, \ + .modified = 1, \ + .channel2 = _channel2, \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_CALIBBIAS), \ + .event_spec = _events, \ + .num_event_specs = _events_nb, \ + .scan_index = _index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .shift = 0, \ + .endianness = IIO_BE, \ + }, \ + .ext_info = inv_ext_info, \ } #define INV_MPU6050_TEMP_CHAN(_index) \ @@ -1338,18 +1349,35 @@ static const struct iio_chan_spec_ext_info inv_ext_info[] = { }, \ } -static const struct iio_chan_spec inv_mpu_channels[] = { +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), + + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0), + + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X, NULL, 0), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y, NULL, 0), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z, NULL, 0), +}; + +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_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0), - 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_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X, + inv_accel_events, ARRAY_SIZE(inv_accel_events)), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y, + inv_accel_events, ARRAY_SIZE(inv_accel_events)), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z, + inv_accel_events, ARRAY_SIZE(inv_accel_events)), }; #define INV_MPU6050_SCAN_MASK_3AXIS_ACCEL \ @@ -1401,13 +1429,13 @@ static const struct iio_chan_spec inv_mpu9150_channels[] = { 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_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0), - 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_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X, NULL, 0), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y, NULL, 0), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z, NULL, 0), /* Magnetometer resolution is 13 bits */ INV_MPU9X50_MAGN_CHAN(IIO_MOD_X, 13, INV_MPU9X50_SCAN_MAGN_X), @@ -1420,13 +1448,16 @@ static const struct iio_chan_spec inv_mpu9250_channels[] = { 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_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y, NULL, 0), + INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z, NULL, 0), - 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_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X, + inv_accel_events, ARRAY_SIZE(inv_accel_events)), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y, + inv_accel_events, ARRAY_SIZE(inv_accel_events)), + INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z, + inv_accel_events, ARRAY_SIZE(inv_accel_events)), /* Magnetometer resolution is 16 bits */ INV_MPU9X50_MAGN_CHAN(IIO_MOD_X, 16, INV_MPU9X50_SCAN_MAGN_X), @@ -1831,6 +1862,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); @@ -1844,13 +1881,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; } @@ -1859,9 +1896,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 Sun Feb 25 16:00:26 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: 13570928 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 091D616427 for ; Sun, 25 Feb 2024 16:01:13 +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=1708876876; cv=fail; b=EVGQFLHG+9LA5nk+9Y3XHwTgjMdTtpTe9AnM+XwQ7AmcvvfKpnypBdSbzHVBhqRYmLUpxiFdULoESvc1xRE0y1dU1ySab0QKslSiNx8L3rw3jtIGD/OTDq05o7MpqbSH5qeomDz/sW0JB0bptIv/0maYOsv+3vNRF/xI4VS6f1Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708876876; c=relaxed/simple; bh=C+75DR0zcd0gip0+Ukf0w/K4XVI+FN2HC7bzTMnZKWE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=B5x8h3F4c+JG1KpHs/p/Q2+CQcYCIhySDK1P02nUnVtEW7O3fTZAyn2rCMiKPKAJQBA8ExBtROi7ETZFmZtubFj+MMWkwjBZGA9dBxfN09tOnOUEO4988rBvbNNIpr2SbAJKakoqTKg/O6AFCmIeFm5DoijgmwRmjdyTB89Ksv4= 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=qeP8DZe8; 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="qeP8DZe8" 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 41PFo2cj018247; Sun, 25 Feb 2024 16:00:59 GMT Received: from jpn01-tyc-obe.outbound.protection.outlook.com (mail-tycjpn01lp2169.outbound.protection.outlook.com [104.47.23.169]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wf9tjrf3v-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 25 Feb 2024 16:00:59 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AB9Jyp188umXrt9KLvgYCong2dIy2c4QyKTVgpx1ApMCMW4fjsto/oqd8yIvSGUwQCqhu4eDjT1B/uOzZoywlt56527fQCfX1244u9IqWvfKhNWfCYfIZk0Ue09kGihDjwBCBnwZyfyo781L6L9I1ZGzcVbkbR3+X6l3haIM3FSeo4dTvRjIJG0+SbE8Zyuw56d3rU/F6kJG+IEi7NsJS1FuntFYSVlSMATJLX4sfnz4yQrOdLUDmYxfsq8i1ZNurmZpziMCdh0sgvzZBw3lpEToztiEMHXtIY4bsUISXa0/Vc+o4GZcflXxPDwpGaS0qDlPWHDFfy1m6ZHz/Lz1/w== 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=Di+Z22lae+WiswI8QMc3LB6JuhyXGlF5VEy7sw2Mpt4=; b=OwlocDEH9fGfVYsvBAqbp3/+NHX7gqzXRbCmE9URoW9sOOUVYnZrk6c6aSq815DGNMv7T4TrtP27bvqx5u8C2q/jOfMWB0GApN89aWCcAOzcQwu2xmPDaYDoTfggxML25we7LfrpDPYU3ml6Tgq7lhElk/A71/DZOWrOQNLHQ5pp0xMI+LW2T/VNqIALRSLr5y8egOwEiwwKbuBSIeTHpUMTaN9M0kd1ierxA3cfpy6vTeCFqG3icGvmBJnCu3dmpPO01LiL6F1nb71AYbK8YkZQUFu8Kp/U/ei604yqwZtTPqzXYNvYIELHwJLDaoLL/i/MtOxJOYpjAaLCoTNLyQ== 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=Di+Z22lae+WiswI8QMc3LB6JuhyXGlF5VEy7sw2Mpt4=; b=qeP8DZe8ALFv8AB2wjJh/hNQdVxH5Fj0qYLBjBbYrcoIKrLoh5MR/t7hg3OFU4oj+islEXxjNuc24AC/QnZDWlZfeSvXCQuaEFxqDcDdpiNN4NzHdFsS+X5LSs+4S6Vv23sXVRM/Bjw+/HnD9EMlBBdPSPdVjLXm8ue2Il4G4+T2YT6d3hbMHewRzyAGCE6CVHJVCgMSQUqRvhH6kArwRDhxFKnZsS0I5gR32+VpTr4VRkOy3k9DVxk32C5ThscG0fbLw+/z5KoCXCkxST/0xvqvUZaFocRAkIfb7zqJ1tHBt34lczaTV46Rwx2MYrztTdjVZwPKWv8aiZPMRI37VQ== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYTP286MB3462.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:39b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Sun, 25 Feb 2024 16:00:53 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f%4]) with mapi id 15.20.7316.018; Sun, 25 Feb 2024 16:00:53 +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 3/4] iio: imu: inv_mpu6050: add new interrupt handler for WoM events Date: Sun, 25 Feb 2024 16:00:26 +0000 Message-Id: <20240225160027.200092-4-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240225160027.200092-1-inv.git-commit@tdk.com> References: <20240225160027.200092-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LNXP265CA0028.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::16) 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_|TYTP286MB3462:EE_ X-MS-Office365-Filtering-Correlation-Id: f056c358-bd1c-4f9a-6e6d-08dc361af1f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FtFUL23U+JTmqRoJo4jYZSJIolF/PwbYWC/U94LdFusxPw1Y3mD7AfmVKF8jgQj0GvwxYlTDoHD9Ze9bewK+g+vrD63Z13se5jKnlFE8sgI5s/KP3kaOZaIFUqtlASFJrNWccswo629BlUxnL+UzxPTRRcR6XJzJ6kG+7Eu549i2yC8RN//OO7X0SpftPt6LPNuCxLMUCDjdWZLK+wuSaqzUDYn3rzXhjEfHIEY3ebeMqTF9teBUsbOcqv/eu7pdUxAL569Diu8HKMTvfT7lFxd5bn1lUOadZutsFVIeGvco+ud65Kb+UDmtkly+w3SE0MXeAutYYR32RwZllvQi+N2sIwQeCRwWo3YR7IKmWSmsA1JM+smf4x7XPjmb3ZrSWopTKpmVhc3HS2zgRTtPHXIC4cuoOJUD64Uhh9uEo2Vz54MU2ZBN4XBayf968fjpMXdERnE7gd1gGsDSZ1w0OCOls2CZiCax7csWbbqdcNd2OrlKtzBDVZEtcpbo9/opm4jvulcl3mrMwj5EK6YOBl68/BM8IHpccG1qJBOYmXhlPogk6l6weD+pFoZXf4i4YZw84NuBxIcU3RNn8rLSe4wyJ7LPNRa6cA4BKiSBV3xM13MliWsBUrbUP4NCjmdWYTA+3U6oOwhtlMzTZGoLPA== 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)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6FSYY584DOPFNc77tEXPRtfIpPzVSQRORfsuLfyLINZlliq/eTzIUOgAGvvkIc5AKOlLSgTTH78nse13nPUBsPoKFqF5S57ubIyTfHZke1mxZ9U2E/QjPcp49xDRUk3qYGvaM2uKturb89MHxJDM4sbu1j59jphuhajhfDdwfJ/zVt3GQ7PbOCMkA+L0dEcMA4YLqaTzXTzHqkopuJCdfeFr7R9pOCoCucjP/Agxtcxj3cSAclXay5Q4ylzMAQbgAFbSwg+bbEF3nfquASZAXf4QhQFkgfmgcokE/tYU6k8/FFQYlWwilmdrFZY+SYw2x6GQ697IilBsR94kPEbsdKCcYNwiJvyJ8GSuGESOG/WS80D4eobB+AzULyUTyMTMZHEoFIkFVRkvNp5Vu9DyVafb+aCsSP/TFX6drBK97zyv2mbjkxPvMtwUoJnNxIolcMKPXNwmvn1h9E+nWlRc+z1IK2fx9M/iVt/ucp4qg+AqbFFIY/LlaaQZ167wM5iYo9sgpNhE3qMGEdGc/dJ1e+x3EbBiHQCUWezBvCb88A3JH3Bg4Y8jGleGVVWgqmLdS8ST8hCyYsOVbTWzP+Bx96zxNnbGdLJ4Kkes4WzA15Ryz+6Xph7qHpDleZD802RAbQ1/VuIf3JfOSU/E0Fu+yhX0xLHzosm3ftz4LMfanYKNGfIYc1pk0xVSVoNZTO/OVMujfmr+RJkqJ9JGyQHPPBBudTMWMwWTeenYTzsU++9S1LIwmOytTT1xgY5P4btojHQyzzNRcd8qBMUrIdWge5sJiEEOZJ5x9cxPQ2axWn5GFLNgfRA8zxuoLD/vfPsZa+rDSfXJjmE9RdnkVglkSQ3bLgxvi8Ie6FYfmOZYLeuiHUs5cEf/i4EfxMs9GQEbVD6dBh3MZ1j/U7prFxDNd+AL2vr9UckY2Y2C7qoU1nEn6zKPxG8trTrCTnuaObrlA+Haxrn1s8P8iKXVw9raErh1LYMHBA//MJmIsDOTYwwC0wtu7D8kXUXGP2+wnEuttOdLnb7z/O4V6eFweFS8z9nJONA+2FS+V3AraxGxX42Q/JTQm5wdD2KofYWjK0swQzX9FVGVm8nYbWsw+LDXFzXef//ziNNLsI0uC7yGZmIevzkPQa/c4T5/oHho8fyAlGix4Bp1iOdledqNcFt74WJbiqEmhfFPizRPhJcg6sRFIkDDSpuauRZQbZJ2rV8XaVM9VLKnEsasfUE0ppEx1lglGiatgvuw3OPaUfKY46O53FyYuwCWNUmtOTertnN62gEnP0iICF6qVPxW7KCNf5MQdcnYy11yb32Vs2rMuCldtVrsHKcp/m0XDqxPnMc4F5ouBJCBGh+IG0QHuGZSrhMItoYB7oaYMz2Xi3a+2sh5UkSWWnZuJG6YAGaccMwQf7Q/hG0LjsIkW9Xiyq9yTlIgdyawoKcDdJhm1gyP6z+ijlnszeKPf5E9nZ42wPj5Cy+dCUT/+rMRvDqXMooiQ0Nt/bBSnqI3KsmdXD/4cHDEa3Yaavk5iRZqQqb6c7pv8fEQT+viaxstwgGaoa3VeUayfSCbo88xXmAi7PIMLIRcLuMITzrnrRMS2EW3qAnU X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: f056c358-bd1c-4f9a-6e6d-08dc361af1f6 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2024 16:00:53.7072 (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: m+aRQghEgDFyfhCaNzEs+PELyRCKE8S8aDig9ym4Gj9wShGmhoKsAwOwxEh/dpseclkByUhQThg4hU66tlHKoA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYTP286MB3462 X-Proofpoint-GUID: uk93VNAGHrQt8q21wgjS3J4uO25UbRJv X-Proofpoint-ORIG-GUID: uk93VNAGHrQt8q21wgjS3J4uO25UbRJv 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-02-25_18,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 priorityscore=1501 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402250127 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 | 56 +++++++++++++++++-- 3 files changed, 53 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 519c1eee96ad..9be67cebbd49 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..7ffbb9e7c100 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,52 @@ 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 = 0; + int result; + + 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 exit_unlock; + } + + /* handle WoM event */ + if (st->chip_config.wom_en && (int_status & INV_MPU6500_BIT_WOM_INT)) + iio_push_event(indio_dev, + IIO_UNMOD_EVENT_CODE(IIO_ACCEL, 0, IIO_EV_TYPE_MAG_ADAPTIVE, + 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 +282,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 Sun Feb 25 16:00:27 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: 13570930 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 2AD90168DE for ; Sun, 25 Feb 2024 16:01:13 +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=1708876876; cv=fail; b=PnbDR4BsYevXAVLiYLD67KhqnEZNYYCKZ8JlcFWzVyQ50wN1eFhssSPp/DE15QFbhYRxPsJRR8osKyAD1piKKxhAtj9TCfp5CX2l7Is3nyizIu9StC28aO88FGrFj8PrWusTAaPGOiEdteqPomybOqjqNKkc92MAX6etq58hUAQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708876876; c=relaxed/simple; bh=/pxRqpfwrd6XdDoXdT3gRK59jXeynn0nEjHOEtL6p9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=SPHS0BFWeKWz+mIdmY0zZG4RNog7QLhY8PKrCCSdZYU21v5lEX8BaB0o3F8q5O7JzrMmuWCpWS2cK6r8KYY1HEVg2mSFSj6pZnCgc3cj1syXWzk1tK4l7SIJ1zTdE+DxeRs/Snwcjc9k/DFPKeJOHnx0xIZHirfMeLbqu7Mj8f8= 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=fIhDC3Rw; 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="fIhDC3Rw" 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 41PFo2ck018247; Sun, 25 Feb 2024 16:01:00 GMT Received: from jpn01-tyc-obe.outbound.protection.outlook.com (mail-tycjpn01lp2169.outbound.protection.outlook.com [104.47.23.169]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wf9tjrf3v-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 25 Feb 2024 16:00:59 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ENJysjdVXOhAO/Pe1xgT1ZDxHG45Y/DxSVGLbJq/D5yr7t/PZxeyrMOYJZqZrkYYZ1d6w/shj6YugqcGXazioats9Oz6u0J8yaqMxi00/8k8FazBcjeL5M/0EPnN2UM81bTMYjhnwEEcC5Ls5pHI0eGkKnvtf9f7VvTs79pkqv406odV1IUSxwvxS/uOwYK4bGt5/0n7pnMqAOXaH55mK5Ff3Rgujz7isTJi8tVhm0VdY9hP3dA8G+tou7sc7W9xLOudXs5S3EyCljZNjjlOKZ0EaRxj+wZ1S2+YbrtAjSXHb4qlmk0WGOGbNcQhY0+V7QGC0bsNDoMe0Pagmok2gg== 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=FuHFgPgENuPIPUANRte+Cpd+uIzsQCz0Qx/9LoNTWL4=; b=I3KQS4dG7JyryKlxhoy/T6pKjjQLtO9zg0SlrZsjEbSIAWDbySZOsOxgJWW0piZDR+xTXOHf/V0gB7Ft6gCGnJFflekJ6BSZ5rXYgTWoJI1Ko4OwFok7gHNry919JDJx/DNzNDnwxDXSGYT+IW8FnGyZH/ENJwZhsYBdQ8GKuRSDy1TtQ/2DQ6cxYzXacm1Jm74WD0bbINNOVK3Iz8LV6ttbKZSnSW2b1S7ABB64ybw4dzVYSWo759oDUW+7fnQAoAze8vjC+skXyEnoFxJuA0qiXguYQvOaahKhvSaelbCBieTMdIy0NdZ0/FkQB5OVAAk4P1ieI4eHz4Q0RbWxzg== 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=FuHFgPgENuPIPUANRte+Cpd+uIzsQCz0Qx/9LoNTWL4=; b=fIhDC3RwVftzFfkdGfiWEqPSLBA0FH8rRAxlrTAQ1F84dWynrRmH2l0DmsXsm1V4tIkyeBjE0djnLWO46zlQrzaznCGtTTYtGamWSBziPGb4a89ELSL0eUBeTzbnGMIRouWneubTHhzLuiJUtYtIoJCWqKvSvh9ur9mN8d+cxRjXnkpP1RSOym9BT6R4d1bND9g/LjEYLYni4VbI3BlVYuAz+FATUE+TNiIjf/8YeUpIHAjLOrBXvUKpp31Xg5IWxfN5PS5E/2lBKh5Zp4CE000vEZOnn5NUKo9zg7D0Y3jtNFAY+TPsRZfGSNUVfrCqk2AKBK/L1/enMciU6p3xYg== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYTP286MB3462.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:39b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Sun, 25 Feb 2024 16:00:55 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::cb8d:ccc6:f2:ff8f%4]) with mapi id 15.20.7316.018; Sun, 25 Feb 2024 16:00:55 +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 4/4] iio: imu: inv_mpu6050: add WoM suspend wakeup with low-power mode Date: Sun, 25 Feb 2024 16:00:27 +0000 Message-Id: <20240225160027.200092-5-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240225160027.200092-1-inv.git-commit@tdk.com> References: <20240225160027.200092-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LNXP265CA0028.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::16) 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_|TYTP286MB3462:EE_ X-MS-Office365-Filtering-Correlation-Id: 863062a4-2d22-49f4-ac76-08dc361af309 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lR+bOcTAAAnndV3JcISGh66Qrg3T7aUJPE8+B9AbJpJRN8FdY/euylKG6VL0AXr1kMVYeVXIiy5IUkdgzN6Cnbi1C5QQvx0j9QFN109Prb+bxTLMom2nrNeFNt342dP0iyyoi9DwgaOuTkqawDUG4SY3YHPoFY1DBUgHjs436EcT2MNSi8/ALH0eW7d8tLf54Eggm5V7ZSr7XJ/8AOv1nvgvZ9AjXfkk+40t0JYNGxGdeAEAt8bFgFs9ikr8A0P6/Y7ADowTr7Yy5ngocw34C+sD0InvutWydnM8P1elk3RM6Et5C9+b6t36r9PUexCDLfNQbu6reTwEUkPOB/ZxjEupjtbtIRIuJ1rc3tp0Na/3BxiyGRY1NcQApu+4HNzWt2JJZfGGdRYZMl/erdPe918EQM9BwkzU1ICjB3bUNcOVZCg8MAPzaZI4FN92XmVic2Sip0gXoV8UotiIKHXVtI0+GSHiOcgWcHY0q8SlmaiFElYZhbNStE9YfARsj0BOBAfuuHX39mesBhcTRDqmmgJNKHkQxU3scfr1SSsQcNsRCu0plqLyeye49MZwIS9zUvzqwB5XvbeoSmjbja+RlNg2Vk6EPXFcSyZbI+SBhNIp0qYFgF+8d0d66i8fZe9/yFKlE9ntM/oplw9Ad6/CDg== 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)(38350700005)(3613699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ShGDb01jrvLggmgMRiqxnQfubMn8vwdTeOCNcHRwE2L18+4o9uhwjQVTUl11lD9UpVLmiYUO0n/eMGm5xV5UIJ6jamgpF/fDoFgqJw/BXalqh3sk6S10zykLc3HSpVC7qDljQmuJ+Jm94RvYSoehUI/GdCV9ovAAvpvCNZ06UQ5fTppFJnKP2Xhh0cN/4OfI6sZfi0eD8mCgo4AZH4o6gDlS1aZsBhcr2Zjs5hL9KGeLpI+gKpus7q3KCZTRZA84X/g9os6e3FY/OBdBkQ0oJeftXpoOKvOyfU8+19mDEslPkLdA5tywE8zE8wi2NozA4gybCDB3SFJ3sfrnX8nIZYc/TMGquJVgsE1U9PFJx9ef9VFx+pX9vdwQdMueTScyX0Kcspka1R86sJv+1ZSj+XeieavhsJqAJtj9yWcp1NFh8ggPC5CihoOZ8PO0y6xgpvdeGWXKg5c8DCAPaPIYuRXRPdxTC7ObQ32UkE06eC/xqpjRQAbRIz/QgjBGDd8SA+r5rZGREm2Q4hhgWU/sDBOh9MrA6H7CqcmtYdJ/bv0H5dsvIUIwcpW3jCMVeeGqZMA5kOWEidPcWYar3JBTmRoL6QwYapamDAk6emLXZV30ZZNALTqGGebZyMGGdXg//4q5u9uGyB4mtXAmhq9CpJh+YiTvrVlR3SVWaFPQp8Ox90bRFRPigEJXzYORnNE4ywFxt851ZLGEkOl+xRGzcUkuL8qwIx61/3vJgHV3LBTfxr+k+XLq3olMbz8wyKqiu3erQQhdyJHQ9J5JxYP8wK29TiDWmQLDM8PQa+b9sOdNropFERjOtvrVtKyX8g31+ihPsuYJqhUQf77RkQWOSzdF0iH2Mzli9EOJwv+0t/JAluQGG7PfN2s0vdFZ66L9f10yNmY6VQRu0tcWvirzVhXDIzTF70s45UATF/fmYrc1IlsaU4y1yYb1wS94bSX8WscDgJ8dcgV9PLpX3NJOztIkctdpzoYs2bJAHz6Oox1Gq3jACaaogsO6MNcLcv6vpQ9sn0n1f2rKkWg3oG3XN8fGjRtHNKCfbXV43nfSxdqKR/HwYw7+3VPCVX3lgXYAIlt7P39E7Ct5tCMfr2rimN7nBwozP74Fd03I46g6TlH6Cbnj0w9712qMPaS5EcY1Jr90ebz0ul/AbDICHJiVL4dvjrR3GJE32p6gaCd6Vx8m5RhtllLh8IfKFhA/Crnuhmzt2T6xs/tS4VMAjLkOIGMQkDImPoOBCYypHTUIhWDxVuC4g0XB6aaoAS/att1YbgNzh4y99U3LZ9qfvMrd49ei+4iHE3bqx7X+q+hxTs8xgM1/9Br9/QgtxA6okMu8ELCPv6xo8O/KBSK9mrQJEDwKq3dL8rQTsJWcJPSQLhrkiW7NP3rEFDacJvSk5Q7xifcVGo2Y6Plx9QIjw6uXf/mJeN9plrGAGJy1lTqnRpNOM1aR0Paxo1Uj1tEyJPsYZvP0K4DBV9KoLCRAzBKMT/2iR34pPJns5IRiAZExi1DHnFMTosQh3xnypFYEKMEeaddpTGTg9deyqe9dNzIEsvNDufxPAZ2QgRghtpTa3k2hc7pNfDsR1TQDwVzTo5Ng X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 863062a4-2d22-49f4-ac76-08dc361af309 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2024 16:00:55.7317 (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: yG4ofCWWOaT2haK6caxOUD+hg9NNU2hPaYxejRxAhh0tE6xulp9RZi3kEEI+Smdu7/u7n1jDVyqagdvQIRVJKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYTP286MB3462 X-Proofpoint-GUID: 0-Weksogfa_jTm9hW0HH6_66QLL-hga3 X-Proofpoint-ORIG-GUID: 0-Weksogfa_jTm9hW0HH6_66QLL-hga3 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-02-25_18,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 priorityscore=1501 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402250127 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. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 160 ++++++++++++++++----- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 14 ++ 2 files changed, 141 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 d2544c758815..db02dd50c0bc 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -287,7 +287,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; @@ -301,6 +301,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); @@ -316,7 +318,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; @@ -358,7 +360,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; @@ -465,7 +467,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; @@ -495,22 +497,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: @@ -529,6 +518,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. * @@ -921,6 +929,69 @@ static int inv_mpu6050_set_wom_int(struct inv_mpu6050_state *st, bool on) INV_MPU6500_BIT_WOM_INT_EN, val); } +static int inv_mpu6050_set_wom_odr(struct inv_mpu6050_state *st, unsigned int rate) +{ + static const unsigned int hz[] = {500, 250, 125, 62, 31, 16, 8, 4}; + static const unsigned int d[] = { + 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 data, i; + + switch (st->chip_type) { + case INV_ICM20609: + case INV_ICM20689: + case INV_ICM20600: + case INV_ICM20602: + case INV_ICM20690: + /* nothing to do */ + return 0; + default: + break; + } + + data = INV_MPU6050_LPOSC_4HZ; + for (i = 0; i < ARRAY_SIZE(hz); ++i) { + if (rate >= hz[i]) { + data = d[i]; + break; + } + } + + dev_dbg(regmap_get_device(st->map), "lp_odr: 0x%x\n", data); + return regmap_write(st->map, INV_MPU6500_REG_LP_ODR, data); +} + +static int inv_mpu6050_set_wom_lp(struct inv_mpu6050_state *st, bool on) +{ + int result; + + if (on) { + /* set WoM low power ODR */ + result = inv_mpu6050_set_wom_odr(st, + INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider)); + 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; + /* 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 accel low pass filter */ + result = inv_mpu6050_set_accel_lpf_regs(st, st->chip_config.lpf); + } + + return result; +} + static int inv_mpu6050_set_wom_threshold(struct inv_mpu6050_state *st, unsigned int value) { struct device *pdev = regmap_get_device(st->map); @@ -1786,6 +1857,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)) @@ -1951,16 +2023,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); @@ -1970,7 +2053,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; @@ -1989,6 +2072,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); @@ -2005,13 +2089,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; @@ -2019,17 +2105,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 9be67cebbd49..751e2b72aebc 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -302,6 +302,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 @@ -333,6 +334,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) @@ -449,6 +451,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,