From patchwork Mon Mar 11 16:05:54 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: 13588991 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 DB18E44393 for ; Mon, 11 Mar 2024 16:06:42 +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=1710173205; cv=fail; b=ekv+10YQnlbavnwXrUzpm4EJoR67trIUyuzRtxK4XlK8YolF8GvtD6xMoVlC4lXyfveVu7a2/u4cFPbXKfEUTkf3MKg8WQUos0HA3T7aXC1dUxhjTKMZW3A3bsmGQu4eUUrj7TReA8z4Glyzr8GHevf6UwIgwfhaLnqIXzAMONo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710173205; c=relaxed/simple; bh=HufJo69z3Gd8MxXIIqo6Fr2nU3CWDDyoh1oHAutNQC4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=YffbU73KP9WhxaTTvSzd8J1sBpDALfHBtMnrglaNPIYnTS1tveYF/Zwl7h666u7DpduX+E/qZj+x79hDmiun3/PSgkd3txZgV6wglPqt3j9ccT43u362pYcV2YJZXcKxxxKhiU3iRfC+12S4IXpeqYUfqkR25TDGKp6Pz19sEpI= 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=dISzDTsx; 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="dISzDTsx" 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 42B9oV0j032277; Mon, 11 Mar 2024 16:06:16 GMT Received: from os0p286cu010.outbound.protection.outlook.com (mail-japanwestazlp17010000.outbound.protection.outlook.com [40.93.130.0]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wrh4j19vn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Mar 2024 16:06:15 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=acFFxFmD/49DoaUIJvaBv/LjM4jAVzTtBGOVI5dCTXn/g0NtwpvvDTvQtPYckF9HTMKNOHe3CBzkqka2LG7dUtFE04UYfkpGe23XiitKwVg1pZMZqSo2hmC7q9E5xpMktm/P1JtPg7ltQ9r0YCaECrLgYRCSrnNGhOXC80F2uSkGXfGKBQG6nebuL+NEW7CfUTtOJu8xSyYcTGchuHlNpPfbCkUfm/EvdcJH4NyB1sSYb7k3/4lh1xUJz4Z+1KDSgMGSd5MvL6JYLrNqnGiSO7/fYgEg+JuYDqBzXQJJuTcXVZByMifmI7lj0DWyVmraaYV3Xg9s1NdBhCHhB1dayA== 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=JaEpqtIKDkQji52A9iLbEEAVwnjKr3Ezo1vWr3/CiQY=; b=kggzU+5Hrskqg2q7LJZrC+35u5cMj8T+EmT6nb6tz1uoJI0jTLW6/pECSoVKaUBTAzrNEDThDDxsAMVqSi4UXKsNZM7cDv8m5veIIwEAf51f+ahxlAnDoirSVJNt8EqDGD+TUDXgMVivtiYbNk0FD/Ui0cktGRuXc/7RzhAUCQFjcirh1nDi1JLrdaHVwXHfsCGcay83Yjv00QHx2InuCyfOKPgMNt/xzXdHcyAvKPN0DTjK/EieOCaLSwnrED2FLF2/CPg/SNF/25R9pPwV2XvPyuElmDryHYvOyZiMgOZRSxnbf3NbcbxQFsGBXElNzF436jAaN5BBVln12dWeZw== 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=JaEpqtIKDkQji52A9iLbEEAVwnjKr3Ezo1vWr3/CiQY=; b=dISzDTsxDq6bxFDg1l/rOIPOLs+oSECuY26KQ7qvZuqsIMXhpQ+Tmg/9F9uilDU3vP5QkkFXXcj/z/z0567FjumYMV69J1DNFPt0UIoBNZjunFk4f8SzobDbRy++RobzPWc1NPi7nde0d2WO6HEL2Og0EQUAfEQkhZNCVEeRX1ATqqwlLLQeqLfWT+XeCiPTkqU9Bzjz1niihYgexRx1+KdEmzRf8JqqryDnpMMhB+gO5vYJ7KmrUXGCMyK3332xK2BeDR0pcPwec9/zZWsEjpzDEgaX8IIm5QK5zq7o0IVOnyhgGwGNhJhlpId4hbK9pu53iGvRff8Vd4Y1SxdSdw== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by OS3P286MB1961.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 16:06:12 +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.031; Mon, 11 Mar 2024 16:06:12 +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 v3 1/4] iio: imu: inv_mpu6050: add WoM (Wake-on-Motion) sensor Date: Mon, 11 Mar 2024 16:05:54 +0000 Message-Id: <20240311160557.437337-2-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240311160557.437337-1-inv.git-commit@tdk.com> References: <20240311160557.437337-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P123CA0074.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::7) 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_|OS3P286MB1961:EE_ X-MS-Office365-Filtering-Correlation-Id: 1209070c-029f-47e7-5dfd-08dc41e52c1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DCp7NgbiQid5H+T4FO2ohIB404NQ5uzy8OCzH9lwlcHfud6ChFFZmWYsRLBfXEGavCbSo3MXRid4No4dLFiv8HDhda6ZYbAGvuDSGPW8P3p9II8wxcPEmQcebzDXB18ED/hlK7SA4/KR5g8NHdaiDYBSj157aZaOBxrSw7RBu87tKCZGYOePgExS3ju8Rw/V8FP02VI0iCB932BEHLgKevaJuLwocEryPJb9j0zGYXS/zapIo2BDgAel/bO/TepSU71vm7+AELbP9IDHXhv+NFmaoS+S2kwm//jw0aeBQEeY46InAZH6ensb7UKUy0KBFGypDGYxdE7q9z5RcnFDmxbduL6/z8e7v7g2Xsi2xFMU1+0pYlNiblR8obFahFwqZQgQPdPYWYw74AadRxRhnHyZBWwqwJHv+2i9HErwcsyLPMIsOMoXMz8MgsNLh5ls5yv544qoB7clV04xF7y2bOUSngHtY1lBGrW5wvzXDVSEupFF7gJDFeC/+Up+scXJ7xzWpO4z++Ct2nDVSBbKCQpSUib+efrQFlG0b0vcxDNqem5QM8U3h8YWTcFioJZAtJo+0DqCVmHIhL+KKXuklKpS44n6QPw6bZCQ948nY+62FvPhMq4g8YKO0MwvCNg8Tgdbs1hWiuayp9Xo9n3ZYaqBSfkZHgdnpK7AvcoxDYi0+OKtGXVGQi97LMW2S7OD5jp9cd/j9ytRfcdF1lEDbouP7r4OfVuQr51LPE0OWf851VNn/v7yM8qNEikCWtaR 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)(376005)(52116005)(1800799015)(3613699003)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7FoIg/w/NKyAKOlazj3WQyahtSvC?= =?utf-8?q?BMRsT6F3llgqEC2N8q73FCZQoGg0ImRZPG80X2otC34sW+ql6tj7g4Mk7L2svFkhI?= =?utf-8?q?h7JIydp+rwFy3Nv1fffQAzrMCdwXpy6lGCHHFf9kJKk+DpWfd7grpn9m1NedbSoPm?= =?utf-8?q?Wqla7o2tT9b0EMAUJN3LE1Yo2d4h3/izcG4rc8TfyZhatTlYeOaTkjx1ZTC0mW8Ip?= =?utf-8?q?XmV3ECwBp81gN6IzDKV5vmL7sOAApno4/Sj4fv8hEBsroZf24Kb7Sjtx7XniZjqrE?= =?utf-8?q?ZcTKlu5eqJb15IoKzjRSHwPWnCWnQFFjrYJBSHtQ0B6VyEN1eqGIyupGHjnRr2o4D?= =?utf-8?q?CrHdj5KBmJoXugaeOz0no5BjmTG3Cj/ylTWPtxBofpWRMc9fOnUmq+ySs44omcWZE?= =?utf-8?q?O205A5S9a6D0R7EiKBqJseoztmDiFF4XK+iX2dl/hbdAvifzrg80tCZFjLDx3V7Y4?= =?utf-8?q?3lsfNyWwyasd01RpipO1bmjgwrmhIwbKNAaFGYd6AYSuCbzc2CVFvaaMcA0bH58ZQ?= =?utf-8?q?86VufL9ZXrQ1YCPp93Fo9uipZ8eLynoXeKJo8wQafkrWaGyzlYID3TYnltaC2xtXo?= =?utf-8?q?oxbjmaiPezjMQOpUbbsXS0gGGqGcA82T6eb+Y9y5Jvg3N1rYoAqMiZpNfx5Ff6Z+F?= =?utf-8?q?hOrT5dz6Q5N4gsNtd+uEhm77gZGftM9bPp0BdOBlxhvQnw89z3C1izw4qauqTWdEP?= =?utf-8?q?XWLW88Or3gcWCYikHd/k/oVtKa08yCRZmLvwQB+H/ZaR13TvBRp/T1HPQO7LqKw8e?= =?utf-8?q?2lCzVubaKAlDhodsBw8x7VpfjZU34Vo35FVjOQ+2hWbgniiwK9oCjyyYs46PYCd82?= =?utf-8?q?MZo/yZyTtRcvcs70x72hvL1Sl+11PtUYmMeBwnBystw1PIfabG75MdeKCpR6BS+p/?= =?utf-8?q?QcmrufzXQ5NiDym1bdNbDgW5NTZWyThHeUdR9byl6K1t4j2QYZIco0VFgK/LsouaF?= =?utf-8?q?VitPLEBcMG9NRS7gzUoan5yxsoIJZRYVKLDVMPBriMAFflLRckFhtNWRVzPFy2MKo?= =?utf-8?q?2kNm1MSwslBrj70k3PBLMihizz7eoXU+TQqgvUw0Wx04jAJU/BWcC0RdcwlKNIAfj?= =?utf-8?q?yKS63IiVZB/s/SBO8A3U2iFkYe4hGkhUn0QJCBjWjbJRha+npxJKTAlqHDwHv68nS?= =?utf-8?q?Iy3tn5Xhr33Ilje5cCU541eVlKn1AhJnxltYVzo7QwCkMO5zNP8btkZ9+JgiZt/sy?= =?utf-8?q?rVEdZEUfjsBMrP5yEmxoVT/NThXeXv2M55GrmlV6AC2uuS9eAP6pPendXyy20sTjv?= =?utf-8?q?fK/e5dCYRAj3OoIGWDw2UDBsgrb5N2+ChMBLzQB1MKCabY/itL634Q+uowUyMMeRr?= =?utf-8?q?Sog19F01EHcmMTtjmYEIRNaby22B8cg/6H0mjRNclZv1IOVIZxtckg9t8dwTZbJF/?= =?utf-8?q?R8uqKJ1vluvMIvgNvYSAg+j9ajo5XcytzanuKgmTDUgf+BAykCPzh8W0sS9ogUNGM?= =?utf-8?q?msCnjZ007cl3gELO0cJSJPYF17BZE3AGPBZu8+fECS0y1+P0FLEtvxhA5jCDHVDCh?= =?utf-8?q?UTkJOmCMfhrz?= X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1209070c-029f-47e7-5dfd-08dc41e52c1e X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:06:12.7199 (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: WoyC8o0lEWrXEK4lS0fnooPU9nMnJ+rBdQC09QhjY4/+6TMnUSH9VSACAm7s8qTjz2KHx/u5dmEll7xnk7GWMg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB1961 X-Proofpoint-ORIG-GUID: VRAaeq7EZzQFp6BfItzkPq0bPMvV0hLm X-Proofpoint-GUID: VRAaeq7EZzQFp6BfItzkPq0bPMvV0hLm 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-11_10,2024-03-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403110122 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 associated 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 | 282 +++++++++++++++++- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 20 +- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 6 +- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 14 +- 4 files changed, 309 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..d49c0ac91a59 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -332,7 +334,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 +347,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 +449,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 +913,239 @@ 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 */ + return div_u64(value * INV_MPU6050_INTERNAL_FREQ_HZ, freq_div); +} + +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; + + /* 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 */ + return min(255, max(1, value)); +} + +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) + return result; + + st->chip_config.roc_threshold = value; + + return 0; +} + +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); + + /* support only WoM (accel roc rising) event */ + if (chan->type != IIO_ACCEL || type != IIO_EV_TYPE_ROC || + dir != IIO_EV_DIR_RISING) + return -EINVAL; + + guard(mutex)(&st->lock); + + return st->chip_config.wom_en ? 1 : 0; +} + +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; + + /* 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; + + guard(mutex)(&st->lock); + + if (st->chip_config.wom_en == enable) + return 0; + + return inv_mpu6050_enable_wom(st, enable); +} + +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; + + guard(mutex)(&st->lock); + + /* 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; + + guard(mutex)(&st->lock); + + result = pm_runtime_resume_and_get(pdev); + if (result) + return result; + + 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); + + return result; +} + /* * inv_mpu6050_set_lpf() - set low pass filer based on fifo rate. * @@ -989,6 +1242,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 +1585,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 +1969,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 +2004,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 +2018,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 +2044,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..d5b0465d1f74 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,11 +105,13 @@ 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 * @magn_fifo_enable: enable magn data output * @divider: chip sample rate divider (sample rate divider - 1) + * @roc_threshold: save ROC threshold (WoM) set value */ struct inv_mpu6050_chip_config { unsigned int clk:3; @@ -119,12 +122,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 +261,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 +310,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 +334,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 Mon Mar 11 16:05:55 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: 13588990 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 DB1C944C8D for ; Mon, 11 Mar 2024 16:06:42 +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=1710173205; cv=fail; b=mMyKym6fQ9dFxZYXAlHqFgzWH5xFT5lPpCzuWUc+gYkKNeF7wb7r6eCRT3mZ/r8Ihj/aPGAetdds2Wz7nn+tJnZLdYZxeca3a4DT+bReBPjPz1LD+A9lnVB99Y4Ga3HAfi9jn389VLMvED6pPbjHhZVbuFRIUFfSSOMgYF5cNcg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710173205; c=relaxed/simple; bh=9mLo8US8o87b7jnsSKdCF2+Pvs53aaazeP2Xa/M59nM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=eRWHrKDQO2khKBOLdoqMZBgZA4vxKwrYhqc9eHOss5WBE43weFNyqqMcQofdpAZDfwRBTw77ZYhlLNMTu8aVrwOhO56LtlxvNzhURpYsI1A641vMiyGsnXXNiE4Mj7lqn6OJuGn+06Lh1aKzFiocouEJ2htjaSf5+0UWEqC2XTQ= 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=aKdFaTse; 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="aKdFaTse" 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 42B9oV0k032277; Mon, 11 Mar 2024 16:06:17 GMT Received: from os0p286cu010.outbound.protection.outlook.com (mail-japanwestazlp17010000.outbound.protection.outlook.com [40.93.130.0]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wrh4j19vn-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Mar 2024 16:06:16 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S8L/UOlE0TIn1DE8RbfeKLs+EQtJeSHJbLA456lm+ShR+HvYbnDRzlzneXJ/f2Ht7ssoN4jGptSi3NyNZQsZbatYvSS47Q7FPeo0FG1IKjan4AQB03oUrgLmxnGRNfULZrVjNSn2hv29iDt9uYkaS48p/SwI8Vz4Ks9n4O/BHmfs/OToXs9e9cNVCt4kEF8vjRrDdyPJyULRF+Iu3O7r5K/d1bLOgWlpeeU0fDTcEqNPW8u8qXA9DDHdhvmab6GmiBCqIseWY9qHhAywt1261Jmp8ovTqgDOoEGvxDNZCfsjBbKb2O5cvbe+y+IYXbULtubQOcxBCZkY6/KGqMpiFg== 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=WSJQ5WckAmyspTFv2g3Y8gpyEj82xt9jLcyK7W6GJtw=; b=kjTzw+xyC5Hzt0CRGkEJTUuBqqpB2aZ2g/crn6AF7qv5CtancSXuDTP5qnqRQuw5Jw1UxnMXL7TwpG/Kpe3RpqQVuP7zLa4mZ+oAQBS4lAK/I3dQ77aTLp/hydZ/ymuzRA5aQB8pT5XMkwsH0J0/Oa52gfgJ4VpLO4owmNa0SpspgVVv7x1ML9pzm+95RTQsUrCDUYDKoYKnRJfmFIf1NgR7rZhv9QZVNb7McctCvGayrXTtIZYiGOBDnxAovHYZ6HJebHxkMtZ9yt4kxxLjjcqTo582gVi0quFMLYghoVzngUW4+h8abC9wy05d9EXrKjS/ePj/FWNH/ULQmVtZig== 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=WSJQ5WckAmyspTFv2g3Y8gpyEj82xt9jLcyK7W6GJtw=; b=aKdFaTseGNDON1RBckWDvu1lg4ZlIhnilABmLAKDQjhybF8jLiFBC36eIrRS4woS7labvJIDcCrsZltmjxQrvYQKh0/Slru5/+mEqelopwVvpjWpeBN547HsxqMCoxZXgtuW5mgxUFoElKr3ZnP5vvqSyuyBdwGNYyzfPtiMxY7KWtxUwZ4zyLkR2wkwetlgRTtU2KjYwO84zOMlEllu3wnpj8iEbzD+ubYR7RJlCH3bOOTk4//YvGuk01UlAxBQe20ymtlnAd0WekUEI/JtT+kP4CnpZa91Q+AV5wFhjMv584lnXuWDf5Cs/A5UOdpZ0cL/In1EvH71HPoFkD4urg== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by OS3P286MB1961.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 16:06:14 +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.031; Mon, 11 Mar 2024 16:06:14 +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 v3 2/4] iio: imu: inv_mpu6050: add WoM event as accel event Date: Mon, 11 Mar 2024 16:05:55 +0000 Message-Id: <20240311160557.437337-3-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240311160557.437337-1-inv.git-commit@tdk.com> References: <20240311160557.437337-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P123CA0074.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::7) 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_|OS3P286MB1961:EE_ X-MS-Office365-Filtering-Correlation-Id: 2611c030-d768-4b4a-f9bc-08dc41e52d6d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /OmIGkZfSLsmL02+sxGoT7RThrjfXT3LaDQ45JjgBWScboSeW+IzcGv4Wad73hdV0M7MLfeC0IvqeThk1yv3ciuaEiNSDV1QYSa6eL2GMnRn62FpIH3P10iNhA+Ic4skQCpMB1RabHw3dfus8Uj7mQX6UjVF7kU+JXctt+YL6WFMmR71lMrT+OIIQ+CrCWECJMBR1kToZtEZJIuRe2hpDrqig6bteAZtiyZ+0fan0Pc6MXDzHQV0LGQGWg+VwBSPXVj7soCt0SFJdWHDLqe/kWniQJ2EzePA/8eBiQY2wTfo6kbIeIIxCISyOcW+0kZxbCfNOl3vviVeImZ5Ara2Gysie0K4K9sGkZyyRZm2Dt+O/C383Z6J07oD/v4WoGk8oN0x7w50lFVdzOqjhzEbtRnIj5nl+a6wzhT2GU0xid7jC9EOVSq7Baim9HvwPNYkAi1XIQU6eBL869QIeEFSdWPW6V7uIFAvWXZL4+rlS/PyBlvy2tIEwRYeDti3UYS6zIMeKzloooVAjEZRv70ZADFr7TOzm5OD19oaIIRP7OfJuCEFEXI+4vE3xCfhyTSnltv//uexXd3G1FBI6AgiKQbmVbhxCbH7aUd4MSWeg3bQZTHOweNlJ6lXETac1BNBvDKvxaUGEtQyj6xlXhApGHn+HvIo9+qxW7sXd5X9ZKuQDpGRvBgle3FJ275iYkob7jX19r9/s+KKP/EDB30YLghz7Oj3HqVbcu0r13ShkueBFPNyWOC321J+RhQ5iS4j 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)(376005)(52116005)(1800799015)(3613699003)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W8G+mWQuDK/xWEn+9dFyiRrwIkGRnYXqUOnzZDH5DwXHTGf3g0aM6t465RklG6XXDtVpOi6/fPDFSDVimvuPu8HLYHVnhUM4qsv/IEeJehLSxjfTr43QBu8wfpe2ojPQjOBFuPSPyRNcyPdrxbcgmdCSdMl4k31g0wn2KVfYBhI0LsGgDdwspUNtj7kEOgAwzOq2kGeNt+r3fgiIP/lQVzM4bRRrXNaTJMbRUAtGeKxfyyf027VkdlreP81TivarqOEpB6srStd2/CzPVYbxY10H5KKHfD59BhmiUg/MTm3fdGYN6+qxFxxXV+WC+SrRiE/vlmL2CovBJzCpLTrnynXVIKedxTPc7rrz5pbWsWux0iblJ4iAVq5BYou88UU/dVMjM+K5sM05/2l2TFdnx/AQ2jiZ7+54+eQdFxYko027x2NOpdzkwjmcpCfHBPx0/aS/DtZ6eq6Z70oCrvgRDWFIvcGugMItMU2/S8lj1rLeBD1yJ2yz1XF1tTDI0VrPiRCfSYuJeue4NT+cmN233LwUOeC7UJelJhGDguxATho9AgHGpfyq8iQDfFHMY4Ud/QWwXeCj253TLhV2C0zg75cCZp7wbS7zuBsfvPyBib5kyEHbxiHM2srFSkSjFvA6N8zmTgqNPDFLoPVilx4q0jxww2x3VNQSDOfMtwvkJF+UfKQ5Ri8qB+bdUfsf3dAN5FhW9sDG3pPeqNwuJNTle2z89+5J42LHXxXo8gfIYKvoduFGO0eWNvKtPv3YNxDNaFqWjbbinuJecoWyO9c+e3+YWnJOcnOj1Mjh7oPDWASyyrCYw+wTWTHlfNIfX21Os4VS4EVfcECri1ev//ODrCTOKuTrxnn947ERBh+GkNBT6aA1SD27qRhIdFbr8xp4qzxB+XsQnu9aaHAYOqsesU22BrzvHC5B0y9s05/8C2x2D29WeO30DgtMCTxnzNnbS56zfyqrwSWlQggYBDNd65rThsr3uQg7lPnCPeYv2srxLRq/6BZ9NnufO7YHYCFzYiiIYIfoYjrkQ2W4JjeAGEXWMQsyjdgGTt/ISMacUTZcYVBcpcGUJRH47ILIt9L/hxYahNa4Q27fUStgAb0HFPdiGNToXh9L7EE0qMTJhQu8ldNAmrvobnPJvPKQVF3towz+iZ+xreMHpc85BTCRNoQ60GX9HpCG5A0UYXgkdrpPGKRjJNmAStU1PfWit079qsRzIhTtLJ/kzYKyPVOJK8wvOhhdeBkTxzTUrkc8bmyaHHIUQu5GL2grn7Zwq30cVIGOKcyZ1ZvxdjX93iXIgE16VlD+g5b7Up+d0JpWx1DYBcSihYG//riggYG8iL7KSIxFk26jqDnwil2wuYnzwJWhOy2buRc864g+HUnL3Q1LEXyEf2A4JK+n47zVHrxI75SAtDwTametXM+jyERBs/y0H0a+cgx2NqRzpAX7bdTRrN7GJz+zxPbBrFi0pIZNeRbLxVsVGNMrNqfJipRGU6PoHzGSpxeZtVA7brrJeArcxgG/tZCLJ3IBgdek7KVn/lKqeofWjWDyKH9bxXVmeBbKZFnZpzKT4TIwTB6KNQRckIMXzGbHuFAyepEmR/gq X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2611c030-d768-4b4a-f9bc-08dc41e52d6d X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:06:14.7001 (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: Ta8R8lVAjnIkGuxjr6IFegOR4HGlsipVnhagAJBp7cd9FhVdk+QiQtrsMhzYDG5MOhauuku2q1DfRMqRFaaOBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB1961 X-Proofpoint-ORIG-GUID: pe-AGKD-eBD6zHrJHg_L14V3fON5oAHE X-Proofpoint-GUID: pe-AGKD-eBD6zHrJHg_L14V3fON5oAHE 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-11_10,2024-03-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403110122 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 d49c0ac91a59..281fbd8eb791 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -1348,6 +1348,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, \ @@ -1383,7 +1392,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), @@ -1397,6 +1416,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) \ @@ -1876,6 +1912,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); @@ -1889,13 +1931,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; } @@ -1904,9 +1946,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 Mon Mar 11 16:05:56 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: 13589146 Received: from mx0a-00549402.pphosted.com (mx0a-00549402.pphosted.com [205.220.166.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 15721482E9 for ; Mon, 11 Mar 2024 17:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.166.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710179599; cv=fail; b=OOspg03mhv1+p9Jr5YXx8EQVzXbuTX+RZ/6DxS7nBUW4G9LDEuMdrQZId4yAzAt9DH0o6lu0mTwdLAGqTIDrGZHD1ymkHumtDxw8BRDsl0UHAa2XVvz4lZ0uRlENj5vufkzA/5oCUtIhaee/wU50VIW+7vNJSkhAkb7wiFx4U0k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710179599; c=relaxed/simple; bh=sTSvgx0lEUwGnmLdqht12FFZlXs7HhXWcIjAr5BoWZI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=khG4/a4RlYXp2PaMCm4e/MBWl2lIMIY0cMKdJJ8Uva9qAX6uAjxUJrEHGYn4YshBG3gVuRqBDY7A+ctSpQPvDSDIaKHmooh3KgB0ky36hUZXYYTAfzmDgjGsVwLIeEjEDxC/DfR6a5Wu7UvLe1XEm5aZYl+Xej9twZkHq5PnuvQ= 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=XisjH5Fw; arc=fail smtp.client-ip=205.220.166.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="XisjH5Fw" Received: from pps.filterd (m0233778.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 42B9r7MB020821; Mon, 11 Mar 2024 16:06:19 GMT Received: from os0p286cu010.outbound.protection.outlook.com (mail-japanwestazlp17010003.outbound.protection.outlook.com [40.93.130.3]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wre4xsbjb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Mar 2024 16:06:18 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hNyg28CMJLFlgwNXCfYZy1QEzUWn5+A/RnUbBDdmp0QbDHGcuFCS6qhCfr2TGc+Bo4ptKbzvkX7ulvTMRQ/BYxX47fb4AEFxKFTLw68MOpS0B9mBA66pPZcRfTVL/NIHqj4PBl3QPN61ZNdgM4Ev35PgVYBai8WHtYLgo4Wijy9vFlQ34ZI6/3EuiQImg5nVfvSoQgMTD06XoETaRwJI1/zmeAiFAXTroxh7sTob9vDdkWhpsoZAJisMx7yT+DqfnFWMee8YQewlHmDLvSSnkKg4tZdLguxR8hQqlGQ4weTNV6A4bCksaWcrs1fCCd2J5DfY4bV99uMW02bt6Rwa6Q== 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=qC479+W/FizE/kP9UEdDEwdYfqkvs6R4i72UBgk++jw=; b=Pxg4B3GMuR9TJNtpM+btAMDEwWxsquBU0n4Uej8bkooGBTDf/2VWmIdFg7o4M5tfrmYpRH5uF6FZpdnESahFjiMHuoJTzG6A/P5nvnFXqMweI9AVkXzkEf+sPep6i0IlskIT488ec9OnNZB44Lj1Kt9OULyV8YkLkBnrsdBuzAZtupgj3qsL+sJGBY1fnVFCiddqSyOoRVKireyLOjun1qhoMOwV8S0EkDVTh5l0Qi/brsoTgIBwn5I3rtCrTCEMq1TRdG9CiLU7UNtlDEaLxdnIad+5l13hdDAjfAaVHTSuyK/ecGAyY6cf9HvzPS6qJW55/IViQsU8lSxlQBW+0g== 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=qC479+W/FizE/kP9UEdDEwdYfqkvs6R4i72UBgk++jw=; b=XisjH5FwMRfMu7GWJwobeLejjTt5q85tAB7BFUVxyidjoBHVDcyKNBvPUib9lj7DCYXW324trHaQDN2AY95FGJENW4PgepSK0dfHi1ME7HKRXs3ap9TEDoTwYnRQdqxY2W/1Dcnq+awIwyb8oUGvOeGC1417GISAqSCEm5Gdw28lCsvR2nctVelIsdNPkX5wHjbekzij6Z5HTJV8YWZA5E+W+rU4s+aklyMXyzMWx/xQC+HPuuWGGNx94FI/hNU+Ju0m/LSDRz4WOv2BsZEkITcJAd1F+xKT+J3SVD4+SCtK5ig4gH+uvbRDrR2fOSgubl2Ngwca6DuZ33UGd1Xy5A== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by OS3P286MB1961.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 16:06:16 +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.031; Mon, 11 Mar 2024 16:06:16 +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 v3 3/4] iio: imu: inv_mpu6050: add new interrupt handler for WoM events Date: Mon, 11 Mar 2024 16:05:56 +0000 Message-Id: <20240311160557.437337-4-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240311160557.437337-1-inv.git-commit@tdk.com> References: <20240311160557.437337-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P123CA0074.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::7) 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_|OS3P286MB1961:EE_ X-MS-Office365-Filtering-Correlation-Id: 281eab46-823f-4015-7361-08dc41e52e9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i/cO1yMZpUXtEtFySfQkCbmBqGdwokrRzT3exrEzGw+nAH6G02rKpOZM6f2Jw/tzO3u7m6040AtKuCkE6xDrxU9DSVDUXaUs6X07yd7I0pcDZQZeEKT7GnIAi1Nee+75Y0AZm7dk5FJO0PNo3IJ3aSNEwxGmonp8s0y5sm54lXk85oU1Yw1L98xFXDIw4lYgvNiFZcdy6bEQ2wC0kKUlriVSrmZVkOhpZqaApMOS8eO1v5qo+uPmSo2xkGXz/LWGiv5Z673Awq4WQd4fTfHrKqPogWX/tgF9GH3MrO74suXSP2UC8aoKxtCggAjtrKQPjWSLGioBkq49s0ZcReBl/SUY05yxZcEI9doLdJg/bcuc3xAT7A6H4m91T29Qu4+MHexYdTri2yU3UT0jhZhTP+JTj/wUU0i7gD6c379gEWuc+ajp6LHXuY6bQGAVCrNAuhOx95OM/ssC0fIZ1FcDnKG6lEgoBF/2TL0AxtHfxPxby1R8+gs/p1vKvu1UlSm1jvugvl2oRBIrADrT65cVsuCNWkO+fUpBTFG4hECa+BRs7RRM7JjHifBXF6+jwNZAer/7V4Az8VDjsWlqKZPv0dWHU9cc6W/v4po9EVlxzC4xmzIZnDQ2Yfgkf/qfpkurn86UMUG4B458fCCW6UvIRbaC4TH1sTZgHDQRW3UzKblba7YXtNpUakmU6cLUgX7grn/Rdu6+0cTvTgCXsMrbTNFoJASsXPIDo4PFnCl4OM4Fo02CpI+Fh9u17qNshewD 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)(376005)(52116005)(1800799015)(3613699003)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PCZXgXzNPmGj4dq5O36mmpO+D7e3zbJ6zOB36H9YDp+WQb7eaW2lu3WmDHL+kBJJxG/+AXl7xjOvpdhEJEcKZp6NrgK9ZrozQIK3yeU/C64wOxTHzhO1znX//22gGivav6kVUY0/dnZAH5XUvKYlpxgwsBfWFy5jaEdQ+OVoYcgVBhlUVlb5A9wW7MPlxmjU/Hrp1AKGyaGiqkW/4MmX536N/IkDscZOHvy/rZ8c1R83bfxFiMweUCb+lNVs5Hw/gMPqmKOgI4aUW4Rb6UiBa4kDtsSB50Nsh3G/OsFFqCmaxs0zCbh3YCwOguDenKKejCr59BaGzXB91MG277rBHEe5obHCdqBLUTH1+52i3oFwn9AFjF92/dJXQZ+fgv3HE1Xym2bgbd0A8ioaEwe+svKHwPfxUeWE4LaDkCBm0Aqzm/1tp3Ch9FLlGgu9o2vjH8OpezA+7A8WKE3SPdm1U0kPSbayKsK+rHrAEQ6fTaaL5CIMHf/fluEiQ2oVodfRWkuUMgqhwZpwrHLlyEDlbCwJavM/b7ArQIzGIgsVhLSRy+XqHmxlK+ZtluuRZc43WoLEd9BWDCet9Jd5PaAwnwP8zvlP/VAzFLQRVADBjBr4TgpBuZj8VB6WMJDUnH3U4UwC6ns2qLXu5NTHQLzXOxNRWtqXIlA33mRpcd3Rq//dUgzdCKYtgMYkOHkd8jBZzSuR/kd/lbj6OD/t8C8sYvGM5vWephpw5SlyAlwpTsOwk3rQ1LZlq1CiBt9kZ2uL6W89gmqo6CrgtEuGuilFnEFnW4Q7Jix3t0cZiaQZTfr140mjR7eIPzZFoz3JSo5ljEeI8JyxwPBX0D4Xf8O7S4x2eVqgyejWkH7m35+SxNXqfUIsiA4AQTyevwuCGbLmBB4Jhb7P/k5kyWilQ+6x6admxsPGgwIECnIUrhw0ZNGx1U7B8U4QQ6lrJTcuzXf12KxoqSXAYm/Y6D+xCYgBwSnJqaFCzRInQ6tE2XW9QAC4boSuWewzdYH+xo28s4sbUDzrU1L94zsmENCsfXt5o6KUqpWcCXSDzdMaw8+E5NSHVUcX74E1N/PnARSrPZrpDocB5j4PuPgD3gKwL4XjT8hwoZa/h9PEmkijui9bmfm4AHwbdU0Ib9bZnxE392AuBhtghMlrC4CJ0WMOdXU6jz7ExwNUQlhywy6tSczIGL2H7QycARLANW0riqxRsnxajGTD2PPJPnoeww6ngHQIumm9vV8HteDvCA6RtsHFeVoUZ/20uoSI5Oloc4IkfZmOeuFZIPhyq2rxnBiU71T50jy4pe1I4fNXIXxwKSsbTHe8wdtrJ2Svl56YLPzHF3x5jCE4pAx0VKyWcy2QatWCzLOWOJxvboFnROgppCQBPVQ1LFfCJCxn0Y8AQ3EiQHOzeA7Be/rKjrJq2wq4XL/0REqbi4VLhJaZWEwuLvnoaUh3QbwM+ggXhqsusf3FpylfCrF+nvNQSYCE4RqkUkxHGa2+QveEx0+6rPmfcz9zCkKt1VbF7fKlzITzfd+jiKajRtEKh4x/qcFPD88+7xEeoGBpsNryaNThz0GhMGjB/rLy6nzQ9OTwWgFeb7hZCTw4 X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 281eab46-823f-4015-7361-08dc41e52e9b X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:06:16.6605 (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: oXf67PXtOiilULLEA7sjT0vomhB6/gN6IhV4Y4To2/utItiDh9t16L1poW92EIDJHPm6Qt+S9iA8+ZyeGMoEog== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB1961 X-Proofpoint-GUID: u03V6lfqaQwEcJ9BxBvQ5mWPurcFKvAV X-Proofpoint-ORIG-GUID: u03V6lfqaQwEcJ9BxBvQ5mWPurcFKvAV 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-11_10,2024-03-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 bulkscore=0 clxscore=1015 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403110122 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 | 69 +++++++++++++++++-- 3 files changed, 66 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 d5b0465d1f74..ca5f7d45a6d4 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -185,6 +185,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; @@ -210,6 +211,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..2514966f6495 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,65 @@ 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; + u64 ev_code; + 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; + } + + scoped_guard(mutex, &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"); + return IRQ_HANDLED; + } + + /* handle WoM event */ + if (st->chip_config.wom_en && (int_status & wom_bits)) { + ev_code = IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X_OR_Y_OR_Z, + IIO_EV_TYPE_ROC, IIO_EV_DIR_RISING); + iio_push_event(indio_dev, ev_code, st->it_timestamp); + } + } + + /* 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 +295,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 Mon Mar 11 16:05:57 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: 13589070 Received: from mx0a-00549402.pphosted.com (mx0a-00549402.pphosted.com [205.220.166.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 A2A78405C1 for ; Mon, 11 Mar 2024 16:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.166.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710175259; cv=fail; b=bfrU9HfaqnHbjETEYn4PQQl05Lu1tsOOldhU+461Cje39rWPnKBVMNEqf9p+nWLkQ85lGflfmw7UlyXn87yLYaXwBnjy7Yl3DDETp1P0gVxFPe9jBXmlp42TNQxg2h1fKwhfqq8AZkuRCenZz47LSYvUoVuvo9DID5/1S9ED7gA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710175259; c=relaxed/simple; bh=l9Ls0+hh+ZteB0TOQ0TjYzPu0NP1anTE9Lqnm5Ha3Xk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=IiVhkKqpIq9DRlG6mrSEU0CNlMqK0GLaxGEHNtWbs7VvL2i/GgodGlJWEhDr4aw/OVlTmah2gwMw4IhhCsZwetwJ2Fy7N8T86xUbLVskqJU6s6dnRTyr+D2WCTV2eZzqsH0QO5kNXO8qgsywJvpINEKqfiwyHtoLkk9QtoEeV6Y= 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=tZp4znfI; arc=fail smtp.client-ip=205.220.166.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="tZp4znfI" Received: from pps.filterd (m0233778.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 42B9SP30018770; Mon, 11 Mar 2024 16:06:22 GMT Received: from os0p286cu010.outbound.protection.outlook.com (mail-japanwestazlp17010000.outbound.protection.outlook.com [40.93.130.0]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3wre4xsbjd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Mar 2024 16:06:21 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kTTMuvX0ecNdMcNwztOyZs7wieat1DHfpX1Vvv7DZ0l9jVNME46eVccQvL5q+229rr2skoBSlMsHDeC5ayOTTuKbbQA+/U2s7z/ExSD6ZAO5MohdBAa81AdJw0XlVQl+c9RZDqeZ3CjbDMwgWYPRnA+srTZvPR2sOI5AzBD+bxJ7KSILciL5HliqixDC1mM+qhJUInMoST7tgu6259ghs3HEdji9a7WelMnuJWnWMSwfAZIZ1O7p5zmfXj+QVwqd3VJUEAW7BOfV5g+ZfuECOHKiQvkP4C005vi9o5YzIiqJYab29J/OXtIR/uPeW39fXr9iH2au0R7aso0w14pSFQ== 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=eipdkPfj8YpXZ7eHh9U8768O/9LoZDWbP6GirwR8Z4A=; b=EQ06LBJA7lPs096A8QYA5u0LwCoye/LkOimuIwsn6qpu5zZ4Iknw5NO/9Yj9oiQpr+JxJ1M15LC6yGZSB+ypUyzrWe/thei50M2UdlXaQZ0RTK4q9o8VlpxEsp2bQdP01E9Owx/tJdMi9kgO19K5VlcUv/ZaVrhFSJaZwd+KNdxIFYxNBXRBqHrPIaSP0N6eqvkREZRYBFZdCKPp0/t5+t4XEAIzbV2UqENiBB4I2JezVkLforSGmv+IvU7V4CvYxyu9tgVfaWN3ZkF41lva1VBzILNtEJhJ5XgipgDfKdj/aTjlmkzqAd/v/3UawDc/WZxb6uvTCkmnUIkCeroEDg== 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=eipdkPfj8YpXZ7eHh9U8768O/9LoZDWbP6GirwR8Z4A=; b=tZp4znfIlhQhxOIJOSgYEdm7rlwDaLtwSFQpBf0EV/fpJ3LzwksXRe0f300FFdQFTgt2CDMFfINSEImW6jY03X2LSmRmbnE/uXWPWD5qtIu7U+DSpeFtYIVg2Qy2EOxz6JhohAZSlxG5fMwSS+YjXOfELoNpLL6+YW7DwpBmVpDX97iapuZmPk3Ulfr83MmgdXa+T0MP3f7QR3k0wW5I/t4LeKk4iOShJXoGom3P48FxzSmlcwQg7kOCjvYESh4N7pMPYH+HhckbDtWVcx9czcG5PcrMHjQThGJVHrHwMtj+QWHuvzPhw9UTO13SixbirF6oBTY+od1r2kQyAvLDjw== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by OS3P286MB1961.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36; Mon, 11 Mar 2024 16:06:19 +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.031; Mon, 11 Mar 2024 16:06:18 +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 v3 4/4] iio: imu: inv_mpu6050: add WoM suspend wakeup with low-power mode Date: Mon, 11 Mar 2024 16:05:57 +0000 Message-Id: <20240311160557.437337-5-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240311160557.437337-1-inv.git-commit@tdk.com> References: <20240311160557.437337-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P123CA0074.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::7) 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_|OS3P286MB1961:EE_ X-MS-Office365-Filtering-Correlation-Id: eab0e3f3-3016-4e7b-eeae-08dc41e52fc6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RQGOdZmKHFH2mQRmH6/Qkjg0ZfLHwf6veD18yiDFt0upZz8IXvq84zrIh1G1KiBYTlNgXJNIPb0Z4chq7FOaKs7sciknZZxcIXox04TPDAidaE1q8wRQ8LUWjzzVwTKytiJ3znnQJgx6w5Dr3ZjgGXbWbgRaI9TrntIYK1TJ+qWwTyEHbbhn8d+RRf6BhVoqOLdQz4oE29DeKn0mO6ca2Pt6dL2iDzITtabkp44nkSxWVO1G3hWRuPS64PxS1KiPbbRrzS3vZy4JBrHOdGs3g40IpoeHQTBASOudJS6kxNoEJJopqheOwYu/7AVS/UBH+wHUyq9ALYqEP0b6KdrHTcnx80HD0++YsS4C5qiQYSlYRJvEvEDks3sye90b7vpUA5HGlNpUwrEwq1YFj/9Qv9g4iA2kOKM4BXQ1aEOP8qkmG4m0/K9CvQJK4la3WEDOcBoZY3estnrIge/MkhwRj662wxuHPDfyBW+adYhu32Pnl1VzRQ7e/e815qp+GZexdHgD5eBZUaBbZ1rc53nwXUAqovBKCbo/SZ7YVvLTFxaYk/BlPw2KIDdN51S9zIdlLXUI5nPw9s+yEhFH7JNEB7Y609XASRHu/7vaatJcdUAmkBas2RZ+DN1jM5ISDVoBYJHbNq8TdgDY5POH0ohhJkFX6/GzWmQIhJau8rgIIFpip9Plc3lAqqZn9m4+CYF0Kq59VnMXWFUfm+RhdfntWJHeVDr5dLFhHHaaAgaZvlGDpEPXo7FOQMKNZ0KxAiCC 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)(376005)(52116005)(1800799015)(3613699003)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dLSTxX2U7SgpvSyxcxp47qF0zYBk3VDitV500pUomFkesbCSyOe5+cZyFsW38BXR7giq8M56NUQbZSvke2onGGPTAZ5UoxN1nIMf/Ksk8BBtqxklee9PWhgjJ25RaJxvjgy1ZKmtSMn14iiyR6ulUlFDkC0jKTl7plAYsJMV7cc8Tf/z8at/p6m7F1/AbNLJqpd3DF0EqQpwS8Lkqe3Z+Bm699A+f1JxHVpaaALTdSHljYalFSxtQlXOyjULChZOiDt4h+BFO8qKzZxCCgklIgofCRElXmS3Zsu72rPoFsqQ6k1F/rFpjg9l52CiYjfeh6Z0jic8Z+mo/EQDMYJudXpd8OlFkTNg1v85XE4U9/rvwzZLnmlEaR3cAZ7IFmAk/XG5Ah3YEwINFScANBqEU46JHhQQMd8ZcMEHK5qD8m8uZ1rY46FsS4x9clVVEGVUSYisMj5ECXsw8+vmBWIJsFcOAax6EWQmt9D/yaOokeKuvrE/C46eb6FUMIAnSAKIdzcE6S4laLpxeqVR5noUR+w1NttWLCBycaktRIwx4aXL6PswJNwEdjw7MxsdCDxCKV44U4MFem/DP3dvqSi0Wbid9mXiHB4fprs4WKUvaszI7s+ibBuZznJzKA6MmryqfH7WDdvtaC+zxYh/tfzGnciayCWvqdUGluMQvmoG+wUpWmd9UlrR+RRnRYBi8Vv/IFhFSmzCgJPGx3YCA2dU+17e1k31hvswmIOKHD2lahtjuaiTJAuJn8sDWpA1y7nCOR8GWFlL8lcq0Ztqpo9B5utLGD1wz2vYiLM0KnODErR/QmbatF+e0pmbEkwKKa7cW0+Kyo3lxQavxFc1dN6QAtPJfSkVzMOX/n9p3HSBwr9O8UPIvRlCxvHzBh1WtEdQGVk17SG0YK9CmlaLtMrj5pFyFthovTZSDD4wHmL41IvjTG7pxZejGW3QUWhS7EV/vxqGG8K7WfYIkiKk5m2vh6uUOwIlJkbu9sb9H0rdqjMQkeDPde6OS5TzMlnKeVUu80qk0WLsn0teMO0SxdJi+vJ1K063oUgRV6sWT69R/VUgrFHBPXAy/l0CSXyCguNcisjnfg/ahT61WLGKA4Iuu+HjgX8NhiUheN3Vyw+w/Cwk2zRGfaJyeKOXgc+lrBnkH39ENQXVsD0BqKXi/Fg6mIXgHeapORZAZVv72XWkhars+10W7O0E8aWQIOLJ8HbL1Qilgo08LYR4CkqD3LFuWXtqM7MY7Uer8sZlu8wFmxyUG3l2m7tPGmzaL6qt6j8OZ+iENth0RXk+UmGzvwhG/bSE7fMn3Uv8c/5CQnX1FOjFoD4vwTFU0XApoXI9BHBSrzxvRWuSTyUtXi+oc/hfBnFENH6y9R1VE+jPuDgHigznQ9tg7aqsjCmw8XnmHjH/0mjLiG1ThjFE+B8p8wobR4wUg/628MFRzjhLBwrexovi5DjVpXB3uD3a9eindlI2mZVexGkfcY2wCBaI2kKo/q0Moy/8IB7oLgUMfHGrsEImAjZ/L9n5uN9kp7bPU+3hVr1ABOn8R9Oa7+Qh0ShqJcbGsonExNj5ExZFPoiD18fMw8DNJzc7Jxoh8UmL/1f6 X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: eab0e3f3-3016-4e7b-eeae-08dc41e52fc6 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:06:18.8531 (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: lVUCY7zdBz38LDw8BEaN29vN957igw+RyXv5yO9raY86kSUaM5t7X+4nJT/VnbNUWYALeZtcLIku+s6f5dbOKw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB1961 X-Proofpoint-GUID: gY49OkwPSbWXmI0edhJCcKvhYq3gfPUM X-Proofpoint-ORIG-GUID: gY49OkwPSbWXmI0edhJCcKvhYq3gfPUM 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-11_10,2024-03-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 bulkscore=0 clxscore=1015 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403110122 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 | 203 +++++++++++++++------ drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 14 ++ 2 files changed, 166 insertions(+), 51 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 281fbd8eb791..caa486bbe865 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -289,7 +289,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; @@ -303,6 +303,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); @@ -318,7 +320,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; @@ -360,7 +362,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; @@ -467,7 +469,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; @@ -497,22 +499,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: @@ -531,6 +520,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. * @@ -1002,6 +1010,84 @@ static int inv_mpu6050_set_wom_threshold(struct inv_mpu6050_state *st, u64 value return 0; } +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); @@ -1836,6 +1922,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)) @@ -2001,16 +2088,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; + guard(mutex)(&st->lock); - 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) + return result; + } else { + result = inv_mpu_core_enable_regulator_vddio(st); + if (result) + return result; + result = inv_mpu6050_set_power_itg(st, true); + if (result) + return result; + } pm_runtime_disable(dev); pm_runtime_set_active(dev); @@ -2018,20 +2116,17 @@ static int inv_mpu_resume(struct device *dev) result = inv_mpu6050_switch_engine(st, true, st->suspended_sensors); if (result) - goto out_unlock; + return result; - 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; + return result; } if (iio_buffer_enabled(indio_dev)) result = inv_mpu6050_prepare_fifo(st, true); -out_unlock: - mutex_unlock(&st->lock); - return result; } @@ -2039,29 +2134,30 @@ 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); + guard(mutex)(&st->lock); st->suspended_sensors = 0; - if (pm_runtime_suspended(dev)) { - result = 0; - goto out_unlock; - } + if (pm_runtime_suspended(dev)) + return 0; if (iio_buffer_enabled(indio_dev)) { result = inv_mpu6050_prepare_fifo(st, false); if (result) - goto out_unlock; + return result; } - 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; + return result; } - 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; @@ -2069,21 +2165,26 @@ 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; + return result; - inv_mpu_core_disable_regulator_vddio(st); -out_unlock: - mutex_unlock(&st->lock); + if (wakeup) { + result = inv_mpu6050_set_wom_lp(st, true); + if (result) + return result; + enable_irq_wake(st->irq); + disable_irq(st->irq); + } else { + result = inv_mpu6050_set_power_itg(st, false); + if (result) + return result; + inv_mpu_core_disable_regulator_vddio(st); + } - return result; + return 0; } static int inv_mpu_runtime_suspend(struct device *dev) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index ca5f7d45a6d4..d65b8776004a 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -305,6 +305,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 @@ -336,6 +337,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) @@ -452,6 +454,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,