From patchwork Wed May 31 14:25:10 2023 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: 13262394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25BBBC77B73 for ; Wed, 31 May 2023 14:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236053AbjEaO03 (ORCPT ); Wed, 31 May 2023 10:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236414AbjEaO0Z (ORCPT ); Wed, 31 May 2023 10:26:25 -0400 Received: from mx0a-00549402.pphosted.com (mx0a-00549402.pphosted.com [205.220.166.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 519EB1A5 for ; Wed, 31 May 2023 07:26:09 -0700 (PDT) Received: from pps.filterd (m0233778.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34VD5Ck1030918; Wed, 31 May 2023 14:25:44 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2107.outbound.protection.outlook.com [104.47.23.107]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3quanmk3c3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 14:25:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QCotOcG1T4eGaAQs4wIRlhNOX2cqdE2U+zOXSSglXQqLHYlp2/HmezmT0IGN04uzgNmkcKYUfX9dPinl+lL3OdbhQAsMz+jjjwlWvVPXcAruGETUXwkXumq2rjCZf6fxZxsC4coaaSwS+ucrgq4AzNou5uwfwdnxL1zauIX9r/lk73kv+6AmYqU9nj/XEqKT8K98cTZBOlAqHu2cDkbDtxCWG0VFJO4THsfUjEVsRJU8Vspanp+YGBUmJra8b92b9zpw8jCPrRXcIWeZeXfrHZC9KIioLrWKR6WFo8fYV/HBs72FZsJ9TTCZt/ru4aPup5xpc2cbuQBZML6tXx9o1Q== 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=8sJYkZy138zblZgRLIUvmUQ0R8GXgRe85wfpyKVNOjA=; b=P9I23SGTLxI79z96F5h6OYEnzX+N/5tXNWmdde8QetoXehBxlUBBHES2lshoKILNtYHOHJYMBi2fQ3zYP+OWYwHVtoCn7B16RTxeAWpQqox2Izl8bYKhifO+ICBmyU3kb+kY0GVOq8J2RBjoMwJel3xlAehsw+WuejH23EiOgCKWuRGLOPNirUWrnguzwV/Cvg0OKt2cr6+1TubwpNaMXNIjZCpx6sUbm5K0nW7Ly7W4K5vyDouZQXoO46V8HuEro3XBnahbqaMVJBxykooGd16fDfzzaFUyNZ1DYN39dM3OMmnQiFfC8/g1IpP+T1ILSZSXfbmxfba8abxU1xP2EQ== 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=8sJYkZy138zblZgRLIUvmUQ0R8GXgRe85wfpyKVNOjA=; b=kdr5F5pTCPOt3rNzEzND1EAmJawy90auqjCTmDOtqgR6ZzfcDGFn9wWW1kBZmHoN6/kV5aDjYirXTpDpwBiEOvBLToCK34Hr55wkKsUJTf8/bUdogaEmV/grrCezBdGr368XhENlAVjpptEmwenaY9Mqak7OfkYPnpfrb3hZi+N7lppIVG4a3dkLnUIsnDh9tLm8PE6AZU3k6iWN1COxQ5dJCE4SKol/EQixoz0i6posNCjyiNCtNSGfsuEretl5JXkHjp451zyECJFdzBtkJr7DvK0pp3XPKEIObIGMBIH/55RX5dR/SZvje3XqAzRigjK3AYQHa6iWVXLPwme4GA== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TY3P286MB2785.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:250::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22; Wed, 31 May 2023 14:25:41 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1%7]) with mapi id 15.20.6455.020; Wed, 31 May 2023 14:25:41 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: lars@metafoo.de, Jean-Baptiste Maneyrol Subject: [PATCH 1/4] iio: imu: inv_icm42600: make timestamp module chip independant Date: Wed, 31 May 2023 14:25:10 +0000 Message-Id: <20230531142513.48507-2-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531142513.48507-1-inv.git-commit@tdk.com> References: <20230531142513.48507-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO0P265CA0007.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::18) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TY3P286MB2785:EE_ X-MS-Office365-Filtering-Correlation-Id: 95bd48f4-a3d7-41f8-cf2b-08db61e2e97c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qgj9RTCx/Uab3nFFt0P3yZoyutTAI59l/VlKznhXisqL0plskQEQi+JfKdWed9aR+7+eNHtfgXxHG0CX+ezXUrSl71dmiHteGJSG4WN6EbCBOF7G1uqBG75M59K6knxHgMlzBDmG8EcrBWzceqvFIfW6Qc7RXZXbY47aYCEd2VJVWNgpGuDR1C4rp5EYMult673vNYVLGkJt3AeZdNUYt2kOvhRfBuygLIvQox6wi/idtpuCffdUhDK3IBjdhFQC++NNzoJOLyd0K55vJpo0nwf75+JlOaNpLCyO1pcmRb6mc//Psse56E9r4q3QgBxKSstTNg7dF/GM1d9wnf0pq1OiQ0l5Fj7iYL9NHsW/W5vk8Wc7SsO9EXca1UaevNBTUSHpBDShtMeEtucjvJvZ7LDQXHLmrLPC/CNJm+iFwMRHatyK8EixMfOacFUwzqcOi1wQyZEMq+W2RwZVQTaix5rNwmLdEzzjHWDgM8zo6AwFOwKEZxQO9zFkCWlLUgXwnkUEX/anj7J3tsB76sqFSl4i0v3qxZIgrC00voiqM93wz9Il2RCKxTrymBCZnpWbG86VRuBH6CzoHxc6ae8tiQ9/OzW1maev7sYskfQUugSOcGwUqSRTnMEMA2p9/h9c 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:(13230028)(4636009)(136003)(396003)(39860400002)(366004)(376002)(346002)(451199021)(86362001)(36756003)(2906002)(186003)(5660300002)(6506007)(1076003)(26005)(9686003)(6512007)(6666004)(52116002)(6486002)(2616005)(478600001)(83380400001)(38350700002)(4326008)(66946007)(66476007)(66556008)(38100700002)(41300700001)(316002)(8936002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pDIcLp/6TDu2xtHiuz3BKFX6+qOZFNw96eqb0F5Ux4vhb34/Oan8Cn2Wiod7AWpcN+45PpzpoUQK/SPlAQjv5ptssD1fL34ZOAdjWN/W18RkjtcF6cbmDJw3/xhEslI6JFAs0B1LWCnHRZbnTLJQ+j8ALqJpXW+y8O3A29fqm4jEFoq9/bHVvPB290ZXTO3tzdBj6+tYJVyCR2lOpmKyR/fw8/UJz42Dy4F6j3lCFZ1SuCkJc3TBGi8Tu6pTE95C2DLeMil0pZanWSoriJZcECcye7wrVw1xxskclK5uoAj+JVHZ6FzD2rTJJgIOLwCY3/VcmEaehy7lZWekfScztii/ahtQPrBAeohaV2icym+6TCRKY4D/TWi6lHNEmv5RhBmtsHecIMGNitbHeuOGZfkmbSfU2kLURlLKywbOBIhmgUgRLTTiIzvNSUAkD1gHvywlSnp0Mr0XXumaB3VY+BwyvBzQ95Rvl4fUk575wPNMvWi/OZ8vp8V70frTCODXhcGiRs6J6QMvOTf5nfDGaTZFw8IIJFbYCEn/m/l7gG7ejjgT1Deivm1vr+TM7poCvkTYwRs5zayE69Vh/xzOw/llFdP3R81Jgh3/x0rH9xFvV+y0znTCzhkdclvpiHhkqh21tCyGB77Jt5VU3ZSRyZfUyH52Qk9GT5B99gYOojuvp1iEvZcQouBMyWRXcUrOLo0R7NxtI46/7Gi2E+MbkjKYfqIjX8F/6G0/n//qJOKbnKF69G5uvJr6EMcI3L4MeY4iM32aX/eHHZDZrA+9yUiXAjdeNiFFKn/ucMq7MK8jJe2aXxxLp97nEmPmWAoZWGQ9ElUyFyGAdYYbmMBy50RQPW9Cm+LAfqVM52Q7VvBGhPejzJ7PkyOLVpQxPduRyIpcsCwnZjVWBiYiEO/ekT7S05t1VOPLM+7EyQKtSpVdmhw79HPM2FnTy9yUgQJNYo0YomRh3jHglM47o7W0VS4fpGcL0PjF1KA8X7dPM6fbhiOqsnQwZd6HDE0FTfqTvdSHzSnilwE3YXcEPkQnAAveAo/uzh0LZFy6xiJUZs5e3eydX/rOF/2dxIMaadgRfou/EsxlwSEo/cYn7wzGIb31EVEyy7/bQAoZvIIABngf+kH2yeUuha2EL1SWA9pEJXDar0weMgRbL1sn6AHsDz6i2hqsf9RDrldzPdfGUfjHtezlmpsQH9tHMl0WIKvS82TLbbpi1Ru2zk09/n1Kt6dmRCRM9c33Gz5EildDYZLLbCaBNNQqA2e0sz9dHaW1N3IdfST6N5SeUcL0lc1bfAjvyp7o9FaKIwirHi7IM50Yb+KoqjnvrrjxkjZbfpSBDrdReLqGMsLMZXI7j/qqkXIj1upLlB5KUSHPBh6VuTevihOpzxTgpTUPT2JWX0ISsXaTSGYUyRpc0AxsUwQ4xVr4bIZ5J+SyyWUawcO3d5vPjOiKrRll8GZ6SlUsYiisME4/XQXzw/XdDag0oF+u5DoruO9d2y1sFoJ8iUzDzcBse0TCrnPczU5rkYeZkEx2A+5lfLIlFxY0lu5Ru8yERNkKcEn5BSDqReXqoFEN6eEkvl1Bu1wBahTF/1QKAsiD X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95bd48f4-a3d7-41f8-cf2b-08db61e2e97c X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2023 14:25:41.2646 (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: llTq71Drpq+7FsptqxPRlNs78ZRv6HA0QNsR31XXEpuLyBmQoUJeZm6kfmofoNCq1hS5qY0RgHS6767j0QaNxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB2785 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-31_08,2023-05-31_03,2023-05-22_02 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jean-Baptiste Maneyrol Move icm42600 dependent function inside the core module. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 11 +++++++++++ .../iio/imu/inv_icm42600/inv_icm42600_timestamp.c | 14 +------------- .../iio/imu/inv_icm42600/inv_icm42600_timestamp.h | 4 ---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c index 7b3a2a0dc2cb..c34735b05830 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -516,6 +516,17 @@ static int inv_icm42600_irq_init(struct inv_icm42600_state *st, int irq, "inv_icm42600", st); } +static int inv_icm42600_timestamp_setup(struct inv_icm42600_state *st) +{ + unsigned int val; + + /* enable timestamp register */ + val = INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN | + INV_ICM42600_TMST_CONFIG_TMST_EN; + return regmap_update_bits(st->map, INV_ICM42600_REG_TMST_CONFIG, + INV_ICM42600_TMST_CONFIG_MASK, val); +} + static int inv_icm42600_enable_regulator_vddio(struct inv_icm42600_state *st) { int ret; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c index 37cbf08acb3a..ceae8ccb1747 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c @@ -4,10 +4,9 @@ */ #include -#include #include +#include -#include "inv_icm42600.h" #include "inv_icm42600_timestamp.h" /* internal chip period is 32kHz, 31250ns */ @@ -56,17 +55,6 @@ void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts, inv_update_acc(&ts->chip_period, INV_ICM42600_TIMESTAMP_PERIOD); } -int inv_icm42600_timestamp_setup(struct inv_icm42600_state *st) -{ - unsigned int val; - - /* enable timestamp register */ - val = INV_ICM42600_TMST_CONFIG_TMST_TO_REGS_EN | - INV_ICM42600_TMST_CONFIG_TMST_EN; - return regmap_update_bits(st->map, INV_ICM42600_REG_TMST_CONFIG, - INV_ICM42600_TMST_CONFIG_MASK, val); -} - int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, uint32_t period, bool fifo) { diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h b/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h index 4e4f331d4fe4..00fd452632a3 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h @@ -8,8 +8,6 @@ #include -struct inv_icm42600_state; - /** * struct inv_icm42600_timestamp_interval - timestamps interval * @lo: interval lower bound @@ -53,8 +51,6 @@ struct inv_icm42600_timestamp { void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts, uint32_t period); -int inv_icm42600_timestamp_setup(struct inv_icm42600_state *st); - int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, uint32_t period, bool fifo); From patchwork Wed May 31 14:25:11 2023 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: 13262397 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72418C7EE2F for ; Wed, 31 May 2023 14:26:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236277AbjEaO0d (ORCPT ); Wed, 31 May 2023 10:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236350AbjEaO0a (ORCPT ); Wed, 31 May 2023 10:26:30 -0400 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 142BE139 for ; Wed, 31 May 2023 07:26:12 -0700 (PDT) Received: from pps.filterd (m0233779.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34V8wvYk008615; Wed, 31 May 2023 14:25:48 GMT Received: from jpn01-tyc-obe.outbound.protection.outlook.com (mail-tycjpn01lp2173.outbound.protection.outlook.com [104.47.23.173]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3qub7gu0yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 14:25:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J/NX9m0VVwFuG7AjTAITGs7nrFHWnOFAPiz6A9YH0KU/X7VB4A/VfBM1o8aXJ11DK9axUFbysOK+8nRKaVIeXs33X8vehp9U5+nyGPK3qYl2C3o4lhWUmARKkMiy9ZqszYiPd633PX0Vnls+bCL/Pe7ubCKC/g41hQ433GA74aNGlVc/rv80A5vjWXO4rSX1A3VBJgV3RZer63hT9Bh01+Yfh3m6oqD3A5WAeV/PaDwMIIiHL1FQGWhSi2yYoQ8yyOpJnjr94/qWD8+5PzxDGz8b1sRmPy7vFD5QB+rcYdzapyijH9aeyKDqM2Mtqsk1k/NlGTgXUk8K5MlE94jKNQ== 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=9ZJgRUBqPDhn9GbKgnyCMz6lpyTZyWctRscwKkZM4Bg=; b=Sqohvfp1Pg9YDqRN5N+iZvwGTiatE3JaiIKTYHsPrg2LdmFQDV6gOqEQOrndhCG1JlrGtZC+XkujtcrGDh2HmIVBwMqqkmYeV0mpCvZqOnCX30nHbOg1VvaRAlRhRc/hPlOg265R3+TvsuK78XRwkFEHQujq6TyI77B2dL8vXRCFybfkUFuh0nEKvj65Pi1Zw+FelhtzDA9hdgjBmVZzaBElzZpSSFbvQ0MxfJPPIA3lb0Gi5v2KkdDTWNsgf4zpfaD7INzLoofQtVY+TPSFEcQrx+JSl+rbHzMhvkAo3xn0+c6CcX+sW3JKIQZb3eTXiggavWgexkuDzyLMLKSmnA== 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=9ZJgRUBqPDhn9GbKgnyCMz6lpyTZyWctRscwKkZM4Bg=; b=VY4qlLzPdeZPYJMz1AjJKm4iVcd8sEyGfTi/cr9VVrbznUHZtHPo54KvjNE5n3Hhm050N0UhGv5iwfprNa4AfCmB90yEyFaoKcAeY0OswS7okIxyV07nRnYt/zaAP3v+TBYNJOHDioiNn3uhALPsnupDWAV4pojrp15BO1Lrp42NPP5LSKSadHLvVllBrUY4ZwJvxvIq32eQgwJWATpyHZgmpvsUiKO5SW6svf260KvTc8HUitG+HyGM+bXAI47/w09nn/lTyT8FnuIKPOg41QHnAXMJ6bZhUB+sn2RJBcf8EVyf8cVTWcYCsgLBasYs0u5KxisFu3sPaX2ZQXME7Q== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by OS3P286MB3226.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:20e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Wed, 31 May 2023 14:25:43 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1%7]) with mapi id 15.20.6455.020; Wed, 31 May 2023 14:25:43 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: lars@metafoo.de, Jean-Baptiste Maneyrol Subject: [PATCH 2/4] iio: move inv_icm42600 timestamp module in common Date: Wed, 31 May 2023 14:25:11 +0000 Message-Id: <20230531142513.48507-3-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531142513.48507-1-inv.git-commit@tdk.com> References: <20230531142513.48507-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO0P265CA0007.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::18) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|OS3P286MB3226:EE_ X-MS-Office365-Filtering-Correlation-Id: 64f8e0c0-ec84-4c16-ee0a-08db61e2eaad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EwWTgizyuT6A/jfF6U0VahbggFvE+LPNVCxnYy6ohG24ZvW4O1wKrk4MDJuPa1224bO6tplq0vJynXvChhdieOJHxdOXjfStMhXumSxdmk6s4I1/vATxZolz/vW0KjJLzTbaFm5SvphqubC6zwhFc+qwIxpvM/o3YirYj7U7hUV+H/UM3zUctD0Msl5NbYEX0ne8Mx2oPSiha8b8XRNFhn18m1+ZFChlrIY2EUxb1dWOnbgf9hUNIEmSNolpa3kZBYhByRLHzKIkf0FumnTBIlocQGAIj6grAeq7HRTMyJHdALi6hpCT9JoudUucLkhuEaqyok1tF9kndrBMatSrQ/iMbOGRXGR0PoplgMnr5V7g5BPm8RlLrrrmPNm/rkGEUoK5QQz/OPhvJEt+Ne94ur5eo5waR+7TBab6mazIvyjlQnDr+4iymg4f04sqpsdc64IVhfZyZkJYs7W+5Hl8y/3KMPSdRWNWTESUWXgF4XoNmNafDLRB1kzPUIzZjHZVL6o3kEUIKTW2/AxwCdibLPx0EAX3KmhYY4C8t+qbhKmCMClXJjoOTSPPTqRyIyQ0Pia7QaS3z0Bb7Fa7X4+5OwLa0Reil6F07JJDML4/f203nasQ20DzwfPVphkfZKXJ 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:(13230028)(4636009)(366004)(396003)(39860400002)(136003)(346002)(376002)(451199021)(2616005)(2906002)(186003)(83380400001)(36756003)(38100700002)(38350700002)(8936002)(8676002)(41300700001)(86362001)(478600001)(4326008)(66556008)(66476007)(66946007)(5660300002)(6486002)(52116002)(6666004)(316002)(6512007)(9686003)(6506007)(26005)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K73csZUFi5Xe9HRIh9uPZN9dpo2cBzD6YacfHky0OKHwRLV0JfkEVgMflTQf3ydueh3ZyQGnJ4eoW9Hc2EVOBOdCLtXHG8uefpBOuV5JFzAllN0WmC+2xGgvX+VegkxIGIEBYYBI73u5z8zHSnuDm8GdzJ0dt25BTYJfjD9Z0tRv3YVpT2IXFelAzrY0PWAcWKqzii7Jw/oO55vengH+w26P/Zos/Oej2RpCzWLpS6LF/a6e20KOnttYzxq0eKR6rQWwbdRPnwrCfonWQuREYwu+f7BydoZbfc+cv/ybXuOoRLXzDEKdNYhptw/w6uLW2YjjyOZvNiFeiEB3uZvFpjQ9c5vxbEhK8NBn+Mi5jaN1HJXTnUT4sk+bcpGvKDZzQTjksVdVZB2az5QofEeGffmpHSOO+zmjfa3FWN/4FrM9ExaMFIbWGCFcO/OLIgEkgqI6xe5WhZRleiT31lDaZtmNcYn76Bt3ebkOq1eoXNm4uy0ZK3lioNdTOejNZYT1DRLA1JLXJf1eLVpjh2Rq1o8g/8tdriM6xKWfwywNyBAamxnyOsx2LvacA0vxJOLQCBjW6JD8AYt0T4SRhbmdXMM4VU8E1AxNlsG8JQSiSoqt04hAYSk2exR/4RggR5xNS9RDblStgSWXEpdeOYoXxhDnapUFFZgNqRSUQHmOtj8QS+UBk8GoWtjbMEb6nOAV/4Lk7NN5yXFvtm+1JYzRHasCqSyyySym66PATwCPx8EBDTgnIHyBjq1qTGcYx8DDrVXk7UrDPQaXGQTbYkewQqBpj8M9AssCqyEwKe5vnhhLYAPE+q+7ylBUhoDNc0Vga5JLcbN1lx7kTFG0ByZxHG2ltxFoYWrWk99mKeQCDIF+n/3FFzHfmyeDxOlV162dll+DyXQCEMklQjOwzU9WiiyOvZjk85xjMVW4xNZrQAMqyIq80dPgwxXyW8ZFuL8kRfD27+8lt7dI48hnefB5KiG+y6NLDVmnDJQmm9aGWLYxwUTepUmlgOSxKR67YNtSAs4C7m6F8sZ0gJ4LLJVClId+tyVGC3vjMNagsb3rCQDYV22QVCwMvTEUDGbKWSeTYQVWTrzlyVZnXr44FBQzSAIcUNdd34UxDuMuedZixnp8LXYlBChZT+XfZ7OgJeqbhuDw7rXpt1kQ+QaIyjIHrHsONFol73I2BBnftMPZYkOgJYwldDv5Nui/XfjDIvba6i68uxZZsjZSvyWUrhVHhrg9bWro1UkNGhKlpREY9pCaxiuMTl1swTLmhYcaFro9WRlUUVICag99lyUM+ET5rWgXvmgzTNrZwBSGMusFriaOvpM57Yj+ZlEDCVT2LG09jEnZGvWTUJXOlCe6jCIvDVADbEQ5lqlwkvZMzqwZ/Ls8ER1/6hNF6mxZoDqhgc9VolkNTNktdu8TaDhF8kCKJ5ahDl/t6iirdTh2vMzPXR+prJSRepxCxuADQbJtDCyV78sgIwBxbiYYg+9mLCYNpbh3E8ZJcriAPKl7w6zAid/73L6TlGffw0LepGidpTTkFMFtbvSIFefqdQrG2EvOlWxORXCirW2P4BR5Z/jWck5bOIHWwMDSMXTBVyMcx3Kf X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64f8e0c0-ec84-4c16-ee0a-08db61e2eaad X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2023 14:25:43.2379 (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: sZPDvc4kdbZmeHGdvEbYfNCT89NwF8Q3r8cm6NvDbyIcxUG5BPvTY0du8v5l2+18D00pUboPflJkxaaHuthDzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB3226 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-31_09,2023-05-31_03,2023-05-22_02 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jean-Baptiste Maneyrol Create new inv_sensors common modules and move inv_icm42600 timestamp module inside. Modify inv_icm42600 driver to use timestamp module. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/common/Kconfig | 1 + drivers/iio/common/Makefile | 1 + drivers/iio/common/inv_sensors/Kconfig | 7 +++++++ drivers/iio/common/inv_sensors/Makefile | 6 ++++++ .../inv_sensors}/inv_icm42600_timestamp.c | 12 ++++++++++-- drivers/iio/imu/inv_icm42600/Kconfig | 1 + drivers/iio/imu/inv_icm42600/Makefile | 1 - drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 2 +- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 3 ++- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 2 +- .../linux/iio/common}/inv_icm42600_timestamp.h | 0 12 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 drivers/iio/common/inv_sensors/Kconfig create mode 100644 drivers/iio/common/inv_sensors/Makefile rename drivers/iio/{imu/inv_icm42600 => common/inv_sensors}/inv_icm42600_timestamp.c (91%) rename {drivers/iio/imu/inv_icm42600 => include/linux/iio/common}/inv_icm42600_timestamp.h (100%) diff --git a/drivers/iio/common/Kconfig b/drivers/iio/common/Kconfig index 0334b4954773..1ccb5ccf3706 100644 --- a/drivers/iio/common/Kconfig +++ b/drivers/iio/common/Kconfig @@ -5,6 +5,7 @@ source "drivers/iio/common/cros_ec_sensors/Kconfig" source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/inv_sensors/Kconfig" source "drivers/iio/common/ms_sensors/Kconfig" source "drivers/iio/common/scmi_sensors/Kconfig" source "drivers/iio/common/ssp_sensors/Kconfig" diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile index fad40e1e1718..d3e952239a62 100644 --- a/drivers/iio/common/Makefile +++ b/drivers/iio/common/Makefile @@ -10,6 +10,7 @@ # When adding new entries keep the list in alphabetical order obj-y += cros_ec_sensors/ obj-y += hid-sensors/ +obj-y += inv_sensors/ obj-y += ms_sensors/ obj-y += scmi_sensors/ obj-y += ssp_sensors/ diff --git a/drivers/iio/common/inv_sensors/Kconfig b/drivers/iio/common/inv_sensors/Kconfig new file mode 100644 index 000000000000..28815fb43157 --- /dev/null +++ b/drivers/iio/common/inv_sensors/Kconfig @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# TDK-InvenSense sensors common library +# + +config IIO_INV_SENSORS_TIMESTAMP + tristate diff --git a/drivers/iio/common/inv_sensors/Makefile b/drivers/iio/common/inv_sensors/Makefile new file mode 100644 index 000000000000..93bddb9356b8 --- /dev/null +++ b/drivers/iio/common/inv_sensors/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for TDK-InvenSense sensors module. +# + +obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_icm42600_timestamp.o diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c b/drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c similarity index 91% rename from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c rename to drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c index ceae8ccb1747..411f561e1a24 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +++ b/drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c @@ -5,9 +5,9 @@ #include #include +#include #include - -#include "inv_icm42600_timestamp.h" +#include /* internal chip period is 32kHz, 31250ns */ #define INV_ICM42600_TIMESTAMP_PERIOD 31250 @@ -54,6 +54,7 @@ void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts, /* use theoretical value for chip period */ inv_update_acc(&ts->chip_period, INV_ICM42600_TIMESTAMP_PERIOD); } +EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_init, IIO_INV_SENSORS_TIMESTAMP); int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, uint32_t period, bool fifo) @@ -66,6 +67,7 @@ int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, return 0; } +EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_update_odr, IIO_INV_SENSORS_TIMESTAMP); static bool inv_validate_period(uint32_t period, uint32_t mult) { @@ -153,6 +155,7 @@ void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts, if (valid) inv_align_timestamp_it(ts); } +EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_interrupt, IIO_INV_SENSORS_TIMESTAMP); void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, uint32_t fifo_period, size_t fifo_nb, @@ -184,3 +187,8 @@ void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, ts->timestamp = ts->it.up - interval; } } +EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_apply_odr, IIO_INV_SENSORS_TIMESTAMP); + +MODULE_AUTHOR("InvenSense, Inc."); +MODULE_DESCRIPTION("InvenSense sensors timestamp module"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/imu/inv_icm42600/Kconfig b/drivers/iio/imu/inv_icm42600/Kconfig index 50cbcfcb6cf1..f56b0816cc4d 100644 --- a/drivers/iio/imu/inv_icm42600/Kconfig +++ b/drivers/iio/imu/inv_icm42600/Kconfig @@ -3,6 +3,7 @@ config INV_ICM42600 tristate select IIO_BUFFER + select IIO_INV_SENSORS_TIMESTAMP config INV_ICM42600_I2C tristate "InvenSense ICM-426xx I2C driver" diff --git a/drivers/iio/imu/inv_icm42600/Makefile b/drivers/iio/imu/inv_icm42600/Makefile index 291714d9aa54..0f49f6df3647 100644 --- a/drivers/iio/imu/inv_icm42600/Makefile +++ b/drivers/iio/imu/inv_icm42600/Makefile @@ -6,7 +6,6 @@ inv-icm42600-y += inv_icm42600_gyro.o inv-icm42600-y += inv_icm42600_accel.o inv-icm42600-y += inv_icm42600_temp.o inv-icm42600-y += inv_icm42600_buffer.o -inv-icm42600-y += inv_icm42600_timestamp.o obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o inv-icm42600-i2c-y += inv_icm42600_i2c.o diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c index c3f433ad3af6..1015de636a94 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -12,12 +12,12 @@ #include #include #include +#include #include #include "inv_icm42600.h" #include "inv_icm42600_temp.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" #define INV_ICM42600_ACCEL_CHAN(_modifier, _index, _ext_info) \ { \ diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c index 32d7f8364230..4a39d31e911f 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -11,9 +11,9 @@ #include #include #include +#include #include "inv_icm42600.h" -#include "inv_icm42600_timestamp.h" #include "inv_icm42600_buffer.h" /* FIFO header: 1 byte */ diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c index c34735b05830..f3e379f9733d 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -16,10 +16,10 @@ #include #include #include +#include #include "inv_icm42600.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" static const struct regmap_range_cfg inv_icm42600_regmap_ranges[] = { { @@ -799,3 +799,4 @@ EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) = { MODULE_AUTHOR("InvenSense, Inc."); MODULE_DESCRIPTION("InvenSense ICM-426xx device driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IIO_INV_SENSORS_TIMESTAMP); diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c index 9d94a8518e3c..6caea7b8a344 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c @@ -12,12 +12,12 @@ #include #include #include +#include #include #include "inv_icm42600.h" #include "inv_icm42600_temp.h" #include "inv_icm42600_buffer.h" -#include "inv_icm42600_timestamp.h" #define INV_ICM42600_GYRO_CHAN(_modifier, _index, _ext_info) \ { \ diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h b/include/linux/iio/common/inv_icm42600_timestamp.h similarity index 100% rename from drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h rename to include/linux/iio/common/inv_icm42600_timestamp.h From patchwork Wed May 31 14:25:12 2023 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: 13262398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F284C7EE23 for ; Wed, 31 May 2023 14:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236343AbjEaO0e (ORCPT ); Wed, 31 May 2023 10:26:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236162AbjEaO0c (ORCPT ); Wed, 31 May 2023 10:26:32 -0400 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95E4413D for ; Wed, 31 May 2023 07:26:13 -0700 (PDT) Received: from pps.filterd (m0233779.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34V8wvYl008615; Wed, 31 May 2023 14:25:48 GMT Received: from jpn01-tyc-obe.outbound.protection.outlook.com (mail-tycjpn01lp2173.outbound.protection.outlook.com [104.47.23.173]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3qub7gu0yx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 14:25:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AbAvg63DU5sJEbLAj8MyuEuS4KEcY1NGFPP+3l0meUuSrfFde8T2UaxEyxlWP9OOugkUztOAj3fHNHaS8yOSXO9+SfOJL6hvuL5KKNCM45Sstn0VF47v4/N9uLHv47WySmxhagcldMGZVZ/LGkF9uc5k0bPgG0FsroVGicADSxpV3mymXbysFFcIwMi80Jif0EutbYNAxrnv/bua2q6NyOc+cj8PXUSDNCXD/DClexEWKaIuYXu0ccj1Sxs5WjdtVT3tq0i+PFr84kFK2gLprjxM+19rjWs0o+nF6DwzS7wdEUxky5xJpVCMST+XaED3akKfsRMSFSgH8Uy3XOVolw== 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=KIwkGJkdijBDxgTP4v0U5Ez/23aQ/ggz8AqymM3BWOQ=; b=h3lQ5NxA+Ty3D6p9agT8E52kzYAzk62Vwgu7cehXXYSRKCbxFmkY086de/hBI1l/ccnBI0044UbuhGkuE/5FcgW90qpgkQlmeAVYt2KkMA8CdS18msmvyFS5atIpiQd6aGcnEkncT6c3H4b+EeqZiZ2hIxApvs3g8w8AlRgxjpL6sqnYTeGksq6Goo0YkrwX6GTjUMdxVFHYxwqXCBxoxeQa4guTIzvkYVmKhra9VQ0qXsPyiwpHnhI3tUrAI7EL5i6jWLS4bL18NC5qTTrbfEr8YfsvxEoUkaHpTO74Fc3fMsJYvi0PT9sWEHbbOTrecPlbgfGWomAzMClNDh3OdA== 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=KIwkGJkdijBDxgTP4v0U5Ez/23aQ/ggz8AqymM3BWOQ=; b=UnLGr7BZXKdpKhuL8nBy6OOMI2GixARz16QOTO5qaJJgGAXcJzDbmncTmK+i6Toa+2pBMvbSdTPT0aTsUosPdRLKqLCszBYO7Ni7EP/qYqBaQ59ghSD4/VTKL7B4dgsc8JUDO7abzwRX2MAH14xV4gHsFO7S8vVzCW0mVPI6qEk5eSdHWSI3evI/NcpQ0avxK2uotlqyGHlGolDmxNHkoQDDtrvTMtSCWnHySeW+GB20+sUFykNJMNGk2PS/z0UudzBiEYxmdO0Q9czqnLw4VFT/EZto5a6M2t5wLcua53m6/Rgt5HM2Dci0AcLy9Dvh5CVFHRuZvs+RW0Cpsceq7w== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by OS3P286MB3226.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:20e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Wed, 31 May 2023 14:25:45 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1%7]) with mapi id 15.20.6455.020; Wed, 31 May 2023 14:25:45 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: lars@metafoo.de, Jean-Baptiste Maneyrol Subject: [PATCH 3/4] iio: make invensense timestamp module generic Date: Wed, 31 May 2023 14:25:12 +0000 Message-Id: <20230531142513.48507-4-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531142513.48507-1-inv.git-commit@tdk.com> References: <20230531142513.48507-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO0P265CA0007.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::18) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|OS3P286MB3226:EE_ X-MS-Office365-Filtering-Correlation-Id: e075caa7-782b-4c3d-0e8d-08db61e2ebdf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TXHosRKlfYSrIZZzGyMR1a94cgh+NWPTB7/UdU4WrAkyFVvtOGRaN6f0sONeDEPTyD45UXOzPR7qA1sWiOsx52lkaW6xNWyToSjnSNmy6FHpLz8+fAGTi3bhzd4CAyIA9PPcwh/a95cLfo/b13eAoEs1E6R3RKOf4FIVb6Tr2+KDjslDT8RpeMrfqsF2NjSWRa1u22WxH7odA4lwK7P41SAj4AVhzWqKOpWg8ukh6dq2cFk2EnoLvIGWaZlEFPElA8LLBgRhjsD3EBA6kVAkJi7VZxs84umKx0WlkftsbyQhs8w6bh4AubJ/hKpjU48dV2mKasNM5gOX+kQ5s95L/NmJyRvmJGnjCiDIzgOsAd1kVBwQ8Bg9ZCFqmLoUCvY9ZhzlU4RTEFx5TMw/B60WWHCQewXEVJFiBrVVYynCX40bOhI8HxN/aVP2oEnik0M4M4J2DrqKL11q6h+dq0TfKkVzbFRhDhEpHH0N5EiR7DfTFqp1qaHI/HpQQ/2Qnk3GnGSWEfZzgKWP7PMaMtxx6XERd4PXsNrvUo49KCOAPrLOGfotRiCNOL9DA/jhG9Ln1zWPVhYigdhIWElMOu4S2Gy1Z9O7tCgPz5cYBThK+qIunqdpVLDxSBaPKGGaCWhnNwGiAr2Pe3pyN7oiPs8/ew== 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:(13230028)(4636009)(366004)(396003)(39860400002)(136003)(346002)(376002)(451199021)(30864003)(2616005)(2906002)(186003)(83380400001)(36756003)(38100700002)(38350700002)(8936002)(8676002)(41300700001)(86362001)(478600001)(4326008)(66556008)(66476007)(66946007)(5660300002)(6486002)(52116002)(6666004)(316002)(6512007)(9686003)(6506007)(26005)(1076003)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pl8AfCt/nEnQqJltMQhypdX2oDTNKCYjVnX3JGEzpTzbjdV+8zhHSplPDoj/6qDNYeuimzGK3bw1ImJQgYF4+iWaw6YMjhMAndLyORF6si+VBNH6/CJOF30aswXqGOpuBz2CClfUQXs7PQYHGBg9ei37aNQryPBdW6dM9cTUoVHoJa+gXukuj4FYUbQxD/bRauqy/DMgA5snx+SPME5WhBvf3R3F0k23HbvWVBOV1lSh+ISDbHFmdTMTV3RPd5nfcwG4Wke10JfaoY/9eoHv7zSrJDhdpLHodAa/yeoE+yAFExpH0RtAb1CClds24GeCt4TnisRMXxpQjxNnDT8F+r3/bllioT9Wi8wVg/CGU0OrtV9d92aIPxepK1ZK4QdssqMwAE2PPDMD6CPOEg0+8XrYdhSYqfZ0Wa/Ql7GqElGSBOIfA3tPrQH8oBBFmGZNlRoXDGcraOjvAoWowllSX8jOmcHVGzHf/jjXio+psXSIrLPNqn8l/PGumL7PerDAzw4klv4zrdaQ2WgKkYhO+oGaL+apYzSnHnokDTryhmetsSTup8Hc+B3HuJacQntvGthQIInhI8qBhlTkrV2tLjv3BPkkUYqTiEYptrXDBPZIuJygB1NSvOU5aDu7a+s/5NKNuvcEbDqGHK0o01fZMxVcLcBZp2LXOmsy+HzK6nniSLo02eUi66e7FkT+4yCMFVpJJSuglfiZFoevDmjYD35BaNI9xn5tQYqWw6THul5kOGYKlFFxOzzvXgsF1u7a409el5iCLi6kgvx/AXCiR2JsBkfxpBuJvZJqxSbitTT7FuBfjc72UJ7Oiq7B80v0IJU2ii/kUlDBZ+11VgjfvBKtk88CXueD9vaJTojmu5nMPDw2ugNcwvy0GZe9ZNidEnJp+DB9LASCAnE2aXM9LOXqHv0/VoJVJ4NQvSfxMS2Ena7x7KCDICcTtYDAoHP9SUcyypJfQPP9yPvhPK57JRVgr3qr3Sus5Y54mE2o1norddyqHt4X5A6M3V+9wjfobYXtjJZitL0iNl/S577RlbNf8oB86d9SEZlip1mKNg3qtkuetwFyC3sNvercGmjfEHVGL7xzqmKPxIZ0IM7AWtYJQoFXTsQ+9Ce7GhvIJyyJKdUQsMVP60cakic2JSyF90uHS6Maps7kfSRJKsXWSNEbFYa5CAcTllT3ftdDjiFxu0clsFjOsmTkWpt9F1ngIEvvQUDyiynHWhSmSQjanML3IuGWMHpjUHgBfY2+fkCq4RdXx9dJXu66r5DfvOTLLH8fiFtC1dhT7Zif5lleJ5ZVYIiQS9lY/lFmMQDfnO+MkFwReyUfsmWI0VTvTvN6B5//hrHWVVEZBkSxgN+IHtHIH38bGCHKJhrNGUwknzMNUdlMiRYK3JZGn+YInS6kbg5Ca+VYc1R6U8gbkNNGby2mWr/3SWQcjsPw5ldNQtjD4Uq5hC4AhbQ9EzzTeiklsKYd5R5VIVKmopOq/D5Wa2KDpGY0N0tskWl6HeczR6RXdjoAwrrRKH9rhk7e/CWVdHSh/8Kgfl8xMUESyBzWU+wUU36Oa3ak7awtNixiWlHJ/S92PUePq3ZfhJzYxI88 X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: e075caa7-782b-4c3d-0e8d-08db61e2ebdf X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2023 14:25:45.4967 (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: NOZUpOjrhZEyfn4aMDA6FNOZqsUicQbz/NpzAKRSr6/PvUmawfHYOzdSJDv2VqV9FX4LR4c2dXkH+12f8hvfRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB3226 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-31_09,2023-05-31_03,2023-05-22_02 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jean-Baptiste Maneyrol Rename common module to inv_sensors_timestamp, add configuration at init (chip internal clock, acceptable jitter, ...) and update inv_icm42600 driver integration. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/common/inv_sensors/Makefile | 2 +- ...00_timestamp.c => inv_sensors_timestamp.c} | 89 +++++++++---------- .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 32 ++++--- .../imu/inv_icm42600/inv_icm42600_buffer.c | 30 +++---- .../iio/imu/inv_icm42600/inv_icm42600_core.c | 1 - .../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 32 ++++--- .../linux/iio/common/inv_icm42600_timestamp.h | 81 ----------------- .../linux/iio/common/inv_sensors_timestamp.h | 89 +++++++++++++++++++ 8 files changed, 189 insertions(+), 167 deletions(-) rename drivers/iio/common/inv_sensors/{inv_icm42600_timestamp.c => inv_sensors_timestamp.c} (57%) delete mode 100644 include/linux/iio/common/inv_icm42600_timestamp.h create mode 100644 include/linux/iio/common/inv_sensors_timestamp.h diff --git a/drivers/iio/common/inv_sensors/Makefile b/drivers/iio/common/inv_sensors/Makefile index 93bddb9356b8..dcf39f249112 100644 --- a/drivers/iio/common/inv_sensors/Makefile +++ b/drivers/iio/common/inv_sensors/Makefile @@ -3,4 +3,4 @@ # Makefile for TDK-InvenSense sensors module. # -obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_icm42600_timestamp.o +obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_sensors_timestamp.o diff --git a/drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c similarity index 57% rename from drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c rename to drivers/iio/common/inv_sensors/inv_sensors_timestamp.c index 411f561e1a24..060191ef3125 100644 --- a/drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c +++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c @@ -7,20 +7,18 @@ #include #include #include -#include - -/* internal chip period is 32kHz, 31250ns */ -#define INV_ICM42600_TIMESTAMP_PERIOD 31250 -/* allow a jitter of +/- 2% */ -#define INV_ICM42600_TIMESTAMP_JITTER 2 -/* compute min and max periods accepted */ -#define INV_ICM42600_TIMESTAMP_MIN_PERIOD(_p) \ - (((_p) * (100 - INV_ICM42600_TIMESTAMP_JITTER)) / 100) -#define INV_ICM42600_TIMESTAMP_MAX_PERIOD(_p) \ - (((_p) * (100 + INV_ICM42600_TIMESTAMP_JITTER)) / 100) +#include + +/* compute jitter, min and max following jitter in per mille */ +#define INV_SENSORS_TIMESTAMP_JITTER(_val, _jitter) \ + (div_s64((_val) * (_jitter), 1000)) +#define INV_SENSORS_TIMESTAMP_MIN(_val, _jitter) \ + (((_val) * (1000 - (_jitter))) / 1000) +#define INV_SENSORS_TIMESTAMP_MAX(_val, _jitter) \ + (((_val) * (1000 + (_jitter))) / 1000) /* Add a new value inside an accumulator and update the estimate value */ -static void inv_update_acc(struct inv_icm42600_timestamp_acc *acc, uint32_t val) +static void inv_update_acc(struct inv_sensors_timestamp_acc *acc, uint32_t val) { uint64_t sum = 0; size_t i; @@ -39,56 +37,57 @@ static void inv_update_acc(struct inv_icm42600_timestamp_acc *acc, uint32_t val) acc->val = div_u64(sum, i); } -void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts, - uint32_t period) +void inv_sensors_timestamp_init(struct inv_sensors_timestamp *ts, + const struct inv_sensors_timestamp_chip *chip) { - /* initial odr for sensor after reset is 1kHz */ - const uint32_t default_period = 1000000; + memset(ts, 0, sizeof(*ts)); + + /* save chip parameters and compute min and max clock period */ + ts->chip = *chip; + ts->min_period = INV_SENSORS_TIMESTAMP_MIN(chip->clock_period, chip->jitter); + ts->max_period = INV_SENSORS_TIMESTAMP_MAX(chip->clock_period, chip->jitter); /* current multiplier and period values after reset */ - ts->mult = default_period / INV_ICM42600_TIMESTAMP_PERIOD; - ts->period = default_period; - /* new set multiplier is the one from chip initialization */ - ts->new_mult = period / INV_ICM42600_TIMESTAMP_PERIOD; + ts->mult = chip->init_period / chip->clock_period; + ts->period = chip->init_period; /* use theoretical value for chip period */ - inv_update_acc(&ts->chip_period, INV_ICM42600_TIMESTAMP_PERIOD); + inv_update_acc(&ts->chip_period, chip->clock_period); } -EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_init, IIO_INV_SENSORS_TIMESTAMP); +EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_init, IIO_INV_SENSORS_TIMESTAMP); -int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, - uint32_t period, bool fifo) +int inv_sensors_timestamp_update_odr(struct inv_sensors_timestamp *ts, + uint32_t period, bool fifo) { /* when FIFO is on, prevent odr change if one is already pending */ if (fifo && ts->new_mult != 0) return -EAGAIN; - ts->new_mult = period / INV_ICM42600_TIMESTAMP_PERIOD; + ts->new_mult = period / ts->chip.clock_period; return 0; } -EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_update_odr, IIO_INV_SENSORS_TIMESTAMP); +EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_update_odr, IIO_INV_SENSORS_TIMESTAMP); -static bool inv_validate_period(uint32_t period, uint32_t mult) +static bool inv_validate_period(struct inv_sensors_timestamp *ts, uint32_t period, uint32_t mult) { - const uint32_t chip_period = INV_ICM42600_TIMESTAMP_PERIOD; uint32_t period_min, period_max; /* check that period is acceptable */ - period_min = INV_ICM42600_TIMESTAMP_MIN_PERIOD(chip_period) * mult; - period_max = INV_ICM42600_TIMESTAMP_MAX_PERIOD(chip_period) * mult; + period_min = ts->min_period * mult; + period_max = ts->max_period * mult; if (period > period_min && period < period_max) return true; else return false; } -static bool inv_update_chip_period(struct inv_icm42600_timestamp *ts, - uint32_t mult, uint32_t period) +static bool inv_update_chip_period(struct inv_sensors_timestamp *ts, + uint32_t mult, uint32_t period) { uint32_t new_chip_period; - if (!inv_validate_period(period, mult)) + if (!inv_validate_period(ts, period, mult)) return false; /* update chip internal period estimation */ @@ -99,7 +98,7 @@ static bool inv_update_chip_period(struct inv_icm42600_timestamp *ts, return true; } -static void inv_align_timestamp_it(struct inv_icm42600_timestamp *ts) +static void inv_align_timestamp_it(struct inv_sensors_timestamp *ts) { int64_t delta, jitter; int64_t adjust; @@ -108,7 +107,7 @@ static void inv_align_timestamp_it(struct inv_icm42600_timestamp *ts) delta = ts->it.lo - ts->timestamp; /* adjust timestamp while respecting jitter */ - jitter = div_s64((int64_t)ts->period * INV_ICM42600_TIMESTAMP_JITTER, 100); + jitter = INV_SENSORS_TIMESTAMP_JITTER((int64_t)ts->period, ts->chip.jitter); if (delta > jitter) adjust = jitter; else if (delta < -jitter) @@ -119,13 +118,13 @@ static void inv_align_timestamp_it(struct inv_icm42600_timestamp *ts) ts->timestamp += adjust; } -void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts, +void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, uint32_t fifo_period, size_t fifo_nb, size_t sensor_nb, int64_t timestamp) { - struct inv_icm42600_timestamp_interval *it; + struct inv_sensors_timestamp_interval *it; int64_t delta, interval; - const uint32_t fifo_mult = fifo_period / INV_ICM42600_TIMESTAMP_PERIOD; + const uint32_t fifo_mult = fifo_period / ts->chip.clock_period; uint32_t period = ts->period; bool valid = false; @@ -151,15 +150,15 @@ void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts, return; } - /* if interrupt interval is valid, sync with interrupt timestamp */ + /* if interrupt interval is valid, align with interrupt timestamp */ if (valid) inv_align_timestamp_it(ts); } -EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_interrupt, IIO_INV_SENSORS_TIMESTAMP); +EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_interrupt, IIO_INV_SENSORS_TIMESTAMP); -void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, - uint32_t fifo_period, size_t fifo_nb, - unsigned int fifo_no) +void inv_sensors_timestamp_apply_odr(struct inv_sensors_timestamp *ts, + uint32_t fifo_period, size_t fifo_nb, + unsigned int fifo_no) { int64_t interval; uint32_t fifo_mult; @@ -180,14 +179,14 @@ void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, */ if (ts->timestamp != 0) { /* compute measured fifo period */ - fifo_mult = fifo_period / INV_ICM42600_TIMESTAMP_PERIOD; + fifo_mult = fifo_period / ts->chip.clock_period; fifo_period = fifo_mult * ts->chip_period.val; /* computes time interval between interrupt and this sample */ interval = (int64_t)(fifo_nb - fifo_no) * (int64_t)fifo_period; ts->timestamp = ts->it.up - interval; } } -EXPORT_SYMBOL_NS_GPL(inv_icm42600_timestamp_apply_odr, IIO_INV_SENSORS_TIMESTAMP); +EXPORT_SYMBOL_NS_GPL(inv_sensors_timestamp_apply_odr, IIO_INV_SENSORS_TIMESTAMP); MODULE_AUTHOR("InvenSense, Inc."); MODULE_DESCRIPTION("InvenSense sensors timestamp module"); diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c index 1015de636a94..795f31b47318 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include "inv_icm42600.h" @@ -98,7 +98,7 @@ static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) { struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); - struct inv_icm42600_timestamp *ts = iio_priv(indio_dev); + struct inv_sensors_timestamp *ts = iio_priv(indio_dev); struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; unsigned int fifo_en = 0; unsigned int sleep_temp = 0; @@ -126,7 +126,7 @@ static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev, } /* update data FIFO write */ - inv_icm42600_timestamp_apply_odr(ts, 0, 0, 0); + inv_sensors_timestamp_apply_odr(ts, 0, 0, 0); ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en); if (ret) goto out_unlock; @@ -311,7 +311,7 @@ static int inv_icm42600_accel_write_odr(struct iio_dev *indio_dev, int val, int val2) { struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); - struct inv_icm42600_timestamp *ts = iio_priv(indio_dev); + struct inv_sensors_timestamp *ts = iio_priv(indio_dev); struct device *dev = regmap_get_device(st->map); unsigned int idx; struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; @@ -330,8 +330,8 @@ static int inv_icm42600_accel_write_odr(struct iio_dev *indio_dev, pm_runtime_get_sync(dev); mutex_lock(&st->lock); - ret = inv_icm42600_timestamp_update_odr(ts, inv_icm42600_odr_to_period(conf.odr), - iio_buffer_enabled(indio_dev)); + ret = inv_sensors_timestamp_update_odr(ts, inv_icm42600_odr_to_period(conf.odr), + iio_buffer_enabled(indio_dev)); if (ret) goto out_unlock; @@ -707,7 +707,8 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st) { struct device *dev = regmap_get_device(st->map); const char *name; - struct inv_icm42600_timestamp *ts; + struct inv_sensors_timestamp_chip ts_chip; + struct inv_sensors_timestamp *ts; struct iio_dev *indio_dev; int ret; @@ -719,8 +720,15 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st) if (!indio_dev) return ERR_PTR(-ENOMEM); + /* + * clock period is 32kHz (31250ns) + * jitter is +/- 2% (20 per mille) + */ + ts_chip.clock_period = 31250; + ts_chip.jitter = 20; + ts_chip.init_period = inv_icm42600_odr_to_period(st->conf.accel.odr); ts = iio_priv(indio_dev); - inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.accel.odr)); + inv_sensors_timestamp_init(ts, &ts_chip); iio_device_set_drvdata(indio_dev, st); indio_dev->name = name; @@ -745,7 +753,7 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st) int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev) { struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); - struct inv_icm42600_timestamp *ts = iio_priv(indio_dev); + struct inv_sensors_timestamp *ts = iio_priv(indio_dev); ssize_t i, size; unsigned int no; const void *accel, *gyro, *timestamp; @@ -768,15 +776,15 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev) /* update odr */ if (odr & INV_ICM42600_SENSOR_ACCEL) - inv_icm42600_timestamp_apply_odr(ts, st->fifo.period, - st->fifo.nb.total, no); + inv_sensors_timestamp_apply_odr(ts, st->fifo.period, + st->fifo.nb.total, no); /* buffer is copied to userspace, zeroing it to avoid any data leak */ memset(&buffer, 0, sizeof(buffer)); memcpy(&buffer.accel, accel, sizeof(buffer.accel)); /* convert 8 bits FIFO temperature in high resolution format */ buffer.temp = temp ? (*temp * 64) : 0; - ts_val = inv_icm42600_timestamp_pop(ts); + ts_val = inv_sensors_timestamp_pop(ts); iio_push_to_buffers_with_timestamp(indio_dev, &buffer, ts_val); } diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c index 4a39d31e911f..42a4a1a52d60 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include "inv_icm42600.h" #include "inv_icm42600_buffer.h" @@ -275,12 +275,12 @@ static int inv_icm42600_buffer_preenable(struct iio_dev *indio_dev) { struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); struct device *dev = regmap_get_device(st->map); - struct inv_icm42600_timestamp *ts = iio_priv(indio_dev); + struct inv_sensors_timestamp *ts = iio_priv(indio_dev); pm_runtime_get_sync(dev); mutex_lock(&st->lock); - inv_icm42600_timestamp_reset(ts); + inv_sensors_timestamp_reset(ts); mutex_unlock(&st->lock); return 0; @@ -504,7 +504,7 @@ int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st, int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st) { - struct inv_icm42600_timestamp *ts; + struct inv_sensors_timestamp *ts; int ret; if (st->fifo.nb.total == 0) @@ -512,8 +512,8 @@ int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st) /* handle gyroscope timestamp and FIFO data parsing */ ts = iio_priv(st->indio_gyro); - inv_icm42600_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, - st->fifo.nb.gyro, st->timestamp.gyro); + inv_sensors_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, + st->fifo.nb.gyro, st->timestamp.gyro); if (st->fifo.nb.gyro > 0) { ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro); if (ret) @@ -522,8 +522,8 @@ int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st) /* handle accelerometer timestamp and FIFO data parsing */ ts = iio_priv(st->indio_accel); - inv_icm42600_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, - st->fifo.nb.accel, st->timestamp.accel); + inv_sensors_timestamp_interrupt(ts, st->fifo.period, st->fifo.nb.total, + st->fifo.nb.accel, st->timestamp.accel); if (st->fifo.nb.accel > 0) { ret = inv_icm42600_accel_parse_fifo(st->indio_accel); if (ret) @@ -536,7 +536,7 @@ int inv_icm42600_buffer_fifo_parse(struct inv_icm42600_state *st) int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st, unsigned int count) { - struct inv_icm42600_timestamp *ts; + struct inv_sensors_timestamp *ts; int64_t gyro_ts, accel_ts; int ret; @@ -552,9 +552,9 @@ int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st, if (st->fifo.nb.gyro > 0) { ts = iio_priv(st->indio_gyro); - inv_icm42600_timestamp_interrupt(ts, st->fifo.period, - st->fifo.nb.total, st->fifo.nb.gyro, - gyro_ts); + inv_sensors_timestamp_interrupt(ts, st->fifo.period, + st->fifo.nb.total, st->fifo.nb.gyro, + gyro_ts); ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro); if (ret) return ret; @@ -562,9 +562,9 @@ int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st, if (st->fifo.nb.accel > 0) { ts = iio_priv(st->indio_accel); - inv_icm42600_timestamp_interrupt(ts, st->fifo.period, - st->fifo.nb.total, st->fifo.nb.accel, - accel_ts); + inv_sensors_timestamp_interrupt(ts, st->fifo.period, + st->fifo.nb.total, st->fifo.nb.accel, + accel_ts); ret = inv_icm42600_accel_parse_fifo(st->indio_accel); if (ret) return ret; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c index f3e379f9733d..0eb11911f786 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "inv_icm42600.h" #include "inv_icm42600_buffer.h" diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c index 6caea7b8a344..57dd7324e9e9 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include "inv_icm42600.h" @@ -98,7 +98,7 @@ static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) { struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); - struct inv_icm42600_timestamp *ts = iio_priv(indio_dev); + struct inv_sensors_timestamp *ts = iio_priv(indio_dev); struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; unsigned int fifo_en = 0; unsigned int sleep_gyro = 0; @@ -126,7 +126,7 @@ static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev, } /* update data FIFO write */ - inv_icm42600_timestamp_apply_odr(ts, 0, 0, 0); + inv_sensors_timestamp_apply_odr(ts, 0, 0, 0); ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en); if (ret) goto out_unlock; @@ -323,7 +323,7 @@ static int inv_icm42600_gyro_write_odr(struct iio_dev *indio_dev, int val, int val2) { struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); - struct inv_icm42600_timestamp *ts = iio_priv(indio_dev); + struct inv_sensors_timestamp *ts = iio_priv(indio_dev); struct device *dev = regmap_get_device(st->map); unsigned int idx; struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT; @@ -342,8 +342,8 @@ static int inv_icm42600_gyro_write_odr(struct iio_dev *indio_dev, pm_runtime_get_sync(dev); mutex_lock(&st->lock); - ret = inv_icm42600_timestamp_update_odr(ts, inv_icm42600_odr_to_period(conf.odr), - iio_buffer_enabled(indio_dev)); + ret = inv_sensors_timestamp_update_odr(ts, inv_icm42600_odr_to_period(conf.odr), + iio_buffer_enabled(indio_dev)); if (ret) goto out_unlock; @@ -718,7 +718,8 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st) { struct device *dev = regmap_get_device(st->map); const char *name; - struct inv_icm42600_timestamp *ts; + struct inv_sensors_timestamp_chip ts_chip; + struct inv_sensors_timestamp *ts; struct iio_dev *indio_dev; int ret; @@ -730,8 +731,15 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st) if (!indio_dev) return ERR_PTR(-ENOMEM); + /* + * clock period is 32kHz (31250ns) + * jitter is +/- 2% (20 per mille) + */ + ts_chip.clock_period = 31250; + ts_chip.jitter = 20; + ts_chip.init_period = inv_icm42600_odr_to_period(st->conf.accel.odr); ts = iio_priv(indio_dev); - inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.gyro.odr)); + inv_sensors_timestamp_init(ts, &ts_chip); iio_device_set_drvdata(indio_dev, st); indio_dev->name = name; @@ -757,7 +765,7 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st) int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev) { struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev); - struct inv_icm42600_timestamp *ts = iio_priv(indio_dev); + struct inv_sensors_timestamp *ts = iio_priv(indio_dev); ssize_t i, size; unsigned int no; const void *accel, *gyro, *timestamp; @@ -780,15 +788,15 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev) /* update odr */ if (odr & INV_ICM42600_SENSOR_GYRO) - inv_icm42600_timestamp_apply_odr(ts, st->fifo.period, - st->fifo.nb.total, no); + inv_sensors_timestamp_apply_odr(ts, st->fifo.period, + st->fifo.nb.total, no); /* buffer is copied to userspace, zeroing it to avoid any data leak */ memset(&buffer, 0, sizeof(buffer)); memcpy(&buffer.gyro, gyro, sizeof(buffer.gyro)); /* convert 8 bits FIFO temperature in high resolution format */ buffer.temp = temp ? (*temp * 64) : 0; - ts_val = inv_icm42600_timestamp_pop(ts); + ts_val = inv_sensors_timestamp_pop(ts); iio_push_to_buffers_with_timestamp(indio_dev, &buffer, ts_val); } diff --git a/include/linux/iio/common/inv_icm42600_timestamp.h b/include/linux/iio/common/inv_icm42600_timestamp.h deleted file mode 100644 index 00fd452632a3..000000000000 --- a/include/linux/iio/common/inv_icm42600_timestamp.h +++ /dev/null @@ -1,81 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2020 Invensense, Inc. - */ - -#ifndef INV_ICM42600_TIMESTAMP_H_ -#define INV_ICM42600_TIMESTAMP_H_ - -#include - -/** - * struct inv_icm42600_timestamp_interval - timestamps interval - * @lo: interval lower bound - * @up: interval upper bound - */ -struct inv_icm42600_timestamp_interval { - int64_t lo; - int64_t up; -}; - -/** - * struct inv_icm42600_timestamp_acc - accumulator for computing an estimation - * @val: current estimation of the value, the mean of all values - * @idx: current index of the next free place in values table - * @values: table of all measured values, use for computing the mean - */ -struct inv_icm42600_timestamp_acc { - uint32_t val; - size_t idx; - uint32_t values[32]; -}; - -/** - * struct inv_icm42600_timestamp - timestamp management states - * @it: interrupts interval timestamps - * @timestamp: store last timestamp for computing next data timestamp - * @mult: current internal period multiplier - * @new_mult: new set internal period multiplier (not yet effective) - * @period: measured current period of the sensor - * @chip_period: accumulator for computing internal chip period - */ -struct inv_icm42600_timestamp { - struct inv_icm42600_timestamp_interval it; - int64_t timestamp; - uint32_t mult; - uint32_t new_mult; - uint32_t period; - struct inv_icm42600_timestamp_acc chip_period; -}; - -void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts, - uint32_t period); - -int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts, - uint32_t period, bool fifo); - -void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts, - uint32_t fifo_period, size_t fifo_nb, - size_t sensor_nb, int64_t timestamp); - -static inline int64_t -inv_icm42600_timestamp_pop(struct inv_icm42600_timestamp *ts) -{ - ts->timestamp += ts->period; - return ts->timestamp; -} - -void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts, - uint32_t fifo_period, size_t fifo_nb, - unsigned int fifo_no); - -static inline void -inv_icm42600_timestamp_reset(struct inv_icm42600_timestamp *ts) -{ - const struct inv_icm42600_timestamp_interval interval_init = {0LL, 0LL}; - - ts->it = interval_init; - ts->timestamp = 0; -} - -#endif diff --git a/include/linux/iio/common/inv_sensors_timestamp.h b/include/linux/iio/common/inv_sensors_timestamp.h new file mode 100644 index 000000000000..23440bc7322c --- /dev/null +++ b/include/linux/iio/common/inv_sensors_timestamp.h @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020 Invensense, Inc. + */ + +#ifndef INV_SENSORS_TIMESTAMP_H_ +#define INV_SENSORS_TIMESTAMP_H_ + +#include + +struct inv_sensors_timestamp_chip { + uint32_t clock_period; + uint32_t jitter; + uint32_t init_period; +}; + +/** + * struct inv_sensors_timestamp_interval - timestamps interval + * @lo: interval lower bound + * @up: interval upper bound + */ +struct inv_sensors_timestamp_interval { + int64_t lo; + int64_t up; +}; + +/** + * struct inv_sensors_timestamp_acc - accumulator for computing an estimation + * @val: current estimation of the value, the mean of all values + * @idx: current index of the next free place in values table + * @values: table of all measured values, use for computing the mean + */ +struct inv_sensors_timestamp_acc { + uint32_t val; + size_t idx; + uint32_t values[32]; +}; + +/** + * struct inv_sensors_timestamp - timestamp management states + * @chip: chip internal characteristics + * @it: interrupts interval timestamps + * @timestamp: store last timestamp for computing next data timestamp + * @mult: current internal period multiplier + * @new_mult: new set internal period multiplier (not yet effective) + * @period: measured current period of the sensor + * @chip_period: accumulator for computing internal chip period + */ +struct inv_sensors_timestamp { + struct inv_sensors_timestamp_chip chip; + uint32_t min_period; + uint32_t max_period; + struct inv_sensors_timestamp_interval it; + int64_t timestamp; + uint32_t mult; + uint32_t new_mult; + uint32_t period; + struct inv_sensors_timestamp_acc chip_period; +}; + +void inv_sensors_timestamp_init(struct inv_sensors_timestamp *ts, + const struct inv_sensors_timestamp_chip *chip); + +int inv_sensors_timestamp_update_odr(struct inv_sensors_timestamp *ts, + uint32_t period, bool fifo); + +void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts, + uint32_t fifo_period, size_t fifo_nb, + size_t sensor_nb, int64_t timestamp); + +static inline int64_t inv_sensors_timestamp_pop(struct inv_sensors_timestamp *ts) +{ + ts->timestamp += ts->period; + return ts->timestamp; +} + +void inv_sensors_timestamp_apply_odr(struct inv_sensors_timestamp *ts, + uint32_t fifo_period, size_t fifo_nb, + unsigned int fifo_no); + +static inline void inv_sensors_timestamp_reset(struct inv_sensors_timestamp *ts) +{ + const struct inv_sensors_timestamp_interval interval_init = {0LL, 0LL}; + + ts->it = interval_init; + ts->timestamp = 0; +} + +#endif From patchwork Wed May 31 14:25:13 2023 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: 13262396 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB6FCC7EE2E for ; Wed, 31 May 2023 14:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236178AbjEaO0c (ORCPT ); Wed, 31 May 2023 10:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236256AbjEaO0a (ORCPT ); Wed, 31 May 2023 10:26:30 -0400 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AD11136 for ; Wed, 31 May 2023 07:26:12 -0700 (PDT) Received: from pps.filterd (m0233779.ppops.net [127.0.0.1]) by mx0b-00549402.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34V8wvYm008615; Wed, 31 May 2023 14:25:49 GMT Received: from jpn01-tyc-obe.outbound.protection.outlook.com (mail-tycjpn01lp2173.outbound.protection.outlook.com [104.47.23.173]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3qub7gu0yx-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 14:25:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ua2NAy1neA8IWP9sc68zMXw69C/XF5NcJb5bLOe0JIaFZOeam6ib0RXiDg84LGNsVaHgrRSnPhqjZoOolCOOMwGKqt7yuxkq8quec20NsSqWcLqaqCZg2Ic0A4h7S/gIlP5lYetBQp+axmhFPP7i4v4HAQLaoA8/uDNHbxxGVoTRvPESinokjyZQKMLS1KX57RXpR3L5AQqyTNWAZ/UVmLm0p49RhafexdCY4RCn8hr8c1pF69nOXnvyUOf4ilI2mGgQ+nvD6WrXZLqZHsuFl/tQoBuNBCSPYS7I3g6k8DPKmcNuxM0DFGBwNN/+Pfo0OM6o+zYgauuRUnEGfOyc1Q== 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=Au83NdEjf9ZHVl7L+rGDAyDho62J04fqx5rPo91TNnY=; b=FL8iD11ACRPHZytJZ/FuH+kJ+NGFBfZXFB7JM08TwPfRv8He4vL37cukLpYTFiyvPFn3f/Wn/AuqXravIx9l1gkR7KqbV6E/pSSXGftJqurS+L+x3W7Frbdir8E/33OVTiem89IusiI6Wiav7Lt86gAWagsvhbKb2P+l523tk+jrg0YgzXiGc7cl/OnCLVOLlDCACR+9fIs+2m8hvfeNTaJMzHD+c3vXGSk9gj2wle2e8QaYHGN/1pQpSQ2degFLbHevyZiCF7UlfQQjIX8Mob/kvNfoF4sIMVW8nSjzZoJSzWS/Tf05HzDXZoU37ULSLScRioHU4a7FAsF5mKwU3Q== 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=Au83NdEjf9ZHVl7L+rGDAyDho62J04fqx5rPo91TNnY=; b=GQccO2GUHyWs1qg7Pr21i5ML6jTMKAiNdi7KLedM9hryoF6eO2E5o3Yoka7DXP25eTiB+GVykDDXO8x/FYi9Qb4rM+Wigx/rQvS+UPYJrIzFJpF30+fQGeQ2kR3kySzdmp1wf9zIQiATOFZixFQzVLYrLgsGYIkMGZ7c/qvBbHr4ZKupga+Hq/6MQ5ptYfYGkKkBgKIEl8WQW/BnTgrwjaBthuD53PshgN9h0y4T2w9RchtiZWoCbRWSKKuTlmFpuChoXINbCPS7NarPU1TLtHky717zFkoOPizdKWiQ+WxPzBpM9NN2sUkWyfFsyUFzijpRxUbX9N7/EI5GomXjdQ== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by OS3P286MB3226.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:20e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Wed, 31 May 2023 14:25:47 +0000 Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1]) by OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM ([fe80::60df:b013:2731:f9c1%7]) with mapi id 15.20.6455.020; Wed, 31 May 2023 14:25:47 +0000 From: inv.git-commit@tdk.com To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: lars@metafoo.de, Jean-Baptiste Maneyrol Subject: [PATCH 4/4] iio: imu: inv_mpu6050: use the common inv_sensors timestamp module Date: Wed, 31 May 2023 14:25:13 +0000 Message-Id: <20230531142513.48507-5-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531142513.48507-1-inv.git-commit@tdk.com> References: <20230531142513.48507-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO0P265CA0007.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::18) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|OS3P286MB3226:EE_ X-MS-Office365-Filtering-Correlation-Id: 8dcc9a1b-c87f-4d26-8b06-08db61e2ed31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TX9hc7gpr7EC++z/cvQmY/qp4JzRq5MCxP12+9/Xct5BID7egYck6NI6vTqnfsLzOQ16XQtkAUqh4T6Pd7P0AN5f+m1/MkNuINiJMjPErxryFh9PivbRSps5/LQWMaHhKYevIlTvbPXIEq7zcJe9YJGDQfNmp0lvePXJ1/P47VyZGPpLKSVDIDnpRfhH55XEH7IHLmHB+ADub1SPaGBWT2IL/Y4SmJIat/DjwPM0rGHYUWIBQvl1U2Iry78wZy0jBZKk9N9GeNKLgHLEIbw/7L62PTeuB3WMLuKiHOYWtelFBLCDMC6Q7UhbWT1Fqmx8yIe37Wbqxmt0FvITNbPQViybttO3twXwMXWuB/fxOqh8EaFYXmH95L1tfroNC+v54VDDtoFABa277JSxw7drAAhWfdo9TxRpvxx6Ogs56t4O6OPHQpMMZtGAj3YQNZ5hlkPu/Po1L1hQSNuBdWUPq1ETK7xvFucxiG24Qoi2DOQVBobUzwXy7epj2JfziePKLCsUoMroEcYcv8LTuug6M3gHuGVhs337IhNWsXdnQEi5YIqOlPieibnWD/D0OqpIigN6DR0U6HjJsoOLltI1MH7OJeplK36EGPbo5u47DjJ3yJS29Kr3lFF3xtAN7ENW 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:(13230028)(4636009)(366004)(396003)(39860400002)(136003)(346002)(376002)(451199021)(2616005)(2906002)(186003)(83380400001)(36756003)(38100700002)(38350700002)(8936002)(8676002)(41300700001)(86362001)(478600001)(4326008)(66556008)(66476007)(66946007)(5660300002)(6486002)(52116002)(6666004)(316002)(6512007)(9686003)(6506007)(26005)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z8zdhlRqffR3NuYcp5ZUrLit/kjaUen0dwwKK1K6wk4HXnt2972SXVYA/IFTJHgKac4hmjm+QfdVuw9I0EZQoEqO3kHf1uvRvJ0v1QETrc3JtkF08ztd5IjNvRa+v6+6St8BuaHPJoyyfNtf8Rss39HJwc5PqYuawfg7bUaC0EsqatByRB+wxnkUsYDUcx+kwmucUHcnT2u+U9Y9Guy2B6MRtvbnhcAYEL6unUQNsTSYsgdJTiEUKL4V4nhH20/WmPeBzHok6AMDIaLIMLYhf3hoWMGKK086YC6pM4XDCy75ypNnbCsDq8xexZ7gT0+Lbj9KU2YUS17LAL6R7Onb2Ggn8GYqxmk2WT/IggwFGGRORRhz1G5EkxJWnIZUfkKd8gJpsvgvMtKqIm1y+ySYvhqzJFXDDTO8+5tNJHU9lauFCNJHUZgIipYmH6VSXOVuGzrHglt7EyZM56dr1sLAupKPkqbH+kk/YJp5/YRjHR0MzsJQ5Dx4/lbbLBXJci/n2YOoJDHabbEDingyaFjYXa9j3wj0IhrCU08e0nWVuV10ZWsaQHCayX3zr+a5ZMXveMf6y4MTJTC1mkUxDFPDJgF2ts3OqV9MqixotYmQblnPqg3gmbNt1/tsplM55i8safxy1VwGfuFVOHxo4trJTZ72TUyq2sQtt4QWe6IhXWb/UCeOLpZKReFWlasxudOc/bFNJ76+Y4JCUAf4QisrJECcn3Ks7jz2WcMhcv/Qj1bQY+JxaPzSfXc6JZZWg68QX9OzCrmfeUW+Ea8Z2BTtiQrEe9TASSmic7vUVNyTkjEDnNFT0BVbMBOEdD5zD0x6jqxmC/Fnu+ZsENWVQSbgsH5PmD8dOQj3X4gwDr2KWuKdxUA+qHKyT2fcGkHTJ6Ea9TXkPzOpXNlvA+Wk/Jl2lrTRt8V0m8es0k3AXS7VLx9rg/vh5ISVGTyq3T96iVX7XWKpUyMt2Z5eVeUasXg3RyBBzFJ4r3EeEGB3oo3BC0gt6AlmXQhjM4stXLxbjmZaY0QrXuFNxKYC+svwq3zve/0lxMPRhYo2mzyT7SGBcXCRrGiU/xMH3WQFGtfboWAaiFRfVG/psV/rGQEgwpDkjyUw5oWGuXJRICYzrcq5xpUNBsU3PFoD/puCm5q2ibxlAUJI6bIRG0KmwtbiNxROYjXtmk+6vAIgdbsFo7NDPohnj77n37oKOhb5DEjKNadclFS5otntwwBb5ai3jJwv2U7W1WwBoYlqxzvJeaF6KbtEhla1vDvH1CvDW/15pXE+XLm93mltDA3tCiqjQtReYOqzAvqumQ1EsVmi3EaNUE5WsrRbgZTzo5KqVeU7OeGHmDfHkgmd7UnVaok4PYwUh7V8zqILk0JrfhcUg7CNjYB+KP+gn7BtgVTonk4tZ1W0cay0OmPRh0/BUiAp2374GRbLsOW7ibXqFXsTzobrdtISKpFYOXXC1QcM3iWOoxSjnQfY41dLCw3efXgFyTsOfj2bHpD63+xpIqr6MPW3nbGqnkckwsnq4soqMYRwUaeNj341EQgQ1ZLHR3kAvrZXCyv7tlzn90NoDNofumZQi5QjtMhD4KvUmMrRlMplx4rW X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dcc9a1b-c87f-4d26-8b06-08db61e2ed31 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2023 14:25:47.4864 (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: k3nut+RVRkrccWc1T8jDBmfFtjTHa4wEU3ORYfoEQigsCDuutx0sv9WPhTxuKpBUmAEPRl/CJc3tjMyaCh7jEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3P286MB3226 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-31_09,2023-05-31_03,2023-05-22_02 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jean-Baptiste Maneyrol Replace timestamping by the new common inv_sensors timestamp module. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/Kconfig | 1 + drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 26 ++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 9 +- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 83 ++----------------- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 3 +- 5 files changed, 33 insertions(+), 89 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig index 64dd73dcc4ba..5f62e4fd475d 100644 --- a/drivers/iio/imu/inv_mpu6050/Kconfig +++ b/drivers/iio/imu/inv_mpu6050/Kconfig @@ -7,6 +7,7 @@ config INV_MPU6050_IIO tristate select IIO_BUFFER select IIO_TRIGGERED_BUFFER + select IIO_INV_SENSORS_TIMESTAMP config INV_MPU6050_I2C tristate "Invensense MPU6050 devices (I2C)" diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 592a6e60b413..022bc314f4a8 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -521,6 +522,7 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) int result; u8 d; struct inv_mpu6050_state *st = iio_priv(indio_dev); + struct inv_sensors_timestamp_chip timestamp; result = inv_mpu6050_set_gyro_fsr(st, st->chip_config.fsr); if (result) @@ -544,12 +546,12 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) if (result) return result; - /* - * Internal chip period is 1ms (1kHz). - * Let's use at the beginning the theorical value before measuring - * with interrupt timestamps. - */ - st->chip_period = NSEC_PER_MSEC; + /* clock jitter is +/- 2% */ + timestamp.clock_period = NSEC_PER_SEC / INV_MPU6050_INTERNAL_FREQ_HZ; + timestamp.jitter = 20; + timestamp.init_period = + NSEC_PER_SEC / INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); + inv_sensors_timestamp_init(&st->timestamp, ×tamp); /* magn chip init, noop if not present in the chip */ result = inv_mpu_magn_probe(st); @@ -936,6 +938,8 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int fifo_rate; + u32 fifo_period; + bool fifo_on; u8 d; int result; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -952,12 +956,21 @@ inv_mpu6050_fifo_rate_store(struct device *dev, struct device_attribute *attr, d = INV_MPU6050_FIFO_RATE_TO_DIVIDER(fifo_rate); /* compute back the fifo rate to handle truncation cases */ fifo_rate = INV_MPU6050_DIVIDER_TO_FIFO_RATE(d); + fifo_period = NSEC_PER_SEC / fifo_rate; mutex_lock(&st->lock); if (d == st->chip_config.divider) { result = 0; goto fifo_rate_fail_unlock; } + + fifo_on = st->chip_config.accl_fifo_enable || + st->chip_config.gyro_fifo_enable || + st->chip_config.magn_fifo_enable; + result = inv_sensors_timestamp_update_odr(&st->timestamp, fifo_period, fifo_on); + if (result) + goto fifo_rate_fail_unlock; + result = pm_runtime_resume_and_get(pdev); if (result) goto fifo_rate_fail_unlock; @@ -1785,3 +1798,4 @@ EXPORT_NS_GPL_DEV_PM_OPS(inv_mpu_pmops, IIO_MPU6050) = { MODULE_AUTHOR("Invensense Corporation"); MODULE_DESCRIPTION("Invensense device MPU6050 driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IIO_INV_SENSORS_TIMESTAMP); diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h index b4ab2c397d0f..1dc2d4e451a2 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -170,9 +171,7 @@ struct inv_mpu6050_hw { * @map regmap pointer. * @irq interrupt number. * @irq_mask the int_pin_cfg mask to configure interrupt type. - * @chip_period: chip internal period estimation (~1kHz). - * @it_timestamp: timestamp from previous interrupt. - * @data_timestamp: timestamp for next data sample. + * @timestamp: timestamping module * @vdd_supply: VDD voltage regulator for the chip. * @vddio_supply I/O voltage regulator for the chip. * @magn_disabled: magnetometer disabled for backward compatibility reason. @@ -196,9 +195,7 @@ struct inv_mpu6050_state { int irq; u8 irq_mask; unsigned skip_samples; - s64 chip_period; - s64 it_timestamp; - s64 data_timestamp; + struct inv_sensors_timestamp timestamp; struct regulator *vdd_supply; struct regulator *vddio_supply; bool magn_disabled; diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c index 45c37525c2f1..6a6cee0f535b 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -13,82 +13,9 @@ #include #include #include +#include #include "inv_mpu_iio.h" -/** - * inv_mpu6050_update_period() - Update chip internal period estimation - * - * @st: driver state - * @timestamp: the interrupt timestamp - * @nb: number of data set in the fifo - * - * This function uses interrupt timestamps to estimate the chip period and - * to choose the data timestamp to come. - */ -static void inv_mpu6050_update_period(struct inv_mpu6050_state *st, - s64 timestamp, size_t nb) -{ - /* Period boundaries for accepting timestamp */ - const s64 period_min = - (NSEC_PER_MSEC * (100 - INV_MPU6050_TS_PERIOD_JITTER)) / 100; - const s64 period_max = - (NSEC_PER_MSEC * (100 + INV_MPU6050_TS_PERIOD_JITTER)) / 100; - const s32 divider = INV_MPU6050_FREQ_DIVIDER(st); - s64 delta, interval; - bool use_it_timestamp = false; - - if (st->it_timestamp == 0) { - /* not initialized, forced to use it_timestamp */ - use_it_timestamp = true; - } else if (nb == 1) { - /* - * Validate the use of it timestamp by checking if interrupt - * has been delayed. - * nb > 1 means interrupt was delayed for more than 1 sample, - * so it's obviously not good. - * Compute the chip period between 2 interrupts for validating. - */ - delta = div_s64(timestamp - st->it_timestamp, divider); - if (delta > period_min && delta < period_max) { - /* update chip period and use it timestamp */ - st->chip_period = (st->chip_period + delta) / 2; - use_it_timestamp = true; - } - } - - if (use_it_timestamp) { - /* - * Manage case of multiple samples in the fifo (nb > 1): - * compute timestamp corresponding to the first sample using - * estimated chip period. - */ - interval = (nb - 1) * st->chip_period * divider; - st->data_timestamp = timestamp - interval; - } - - /* save it timestamp */ - st->it_timestamp = timestamp; -} - -/** - * inv_mpu6050_get_timestamp() - Return the current data timestamp - * - * @st: driver state - * @return: current data timestamp - * - * This function returns the current data timestamp and prepares for next one. - */ -static s64 inv_mpu6050_get_timestamp(struct inv_mpu6050_state *st) -{ - s64 ts; - - /* return current data timestamp and increment */ - ts = st->data_timestamp; - st->data_timestamp += st->chip_period * INV_MPU6050_FREQ_DIVIDER(st); - - return ts; -} - static int inv_reset_fifo(struct iio_dev *indio_dev) { int result; @@ -121,6 +48,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) size_t bytes_per_datum; int result; u16 fifo_count; + u32 fifo_period; s64 timestamp; int int_status; size_t i, nb; @@ -177,7 +105,10 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) /* compute and process all complete datum */ nb = fifo_count / bytes_per_datum; - inv_mpu6050_update_period(st, pf->timestamp, nb); + /* Each FIFO data contains all sensors, so same number for FIFO and sensor data */ + fifo_period = NSEC_PER_SEC / INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); + inv_sensors_timestamp_interrupt(&st->timestamp, fifo_period, nb, nb, pf->timestamp); + inv_sensors_timestamp_apply_odr(&st->timestamp, fifo_period, nb, 0); for (i = 0; i < nb; ++i) { result = regmap_noinc_read(st->map, st->reg->fifo_r_w, st->data, bytes_per_datum); @@ -188,7 +119,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) st->skip_samples--; continue; } - timestamp = inv_mpu6050_get_timestamp(st); + timestamp = inv_sensors_timestamp_pop(&st->timestamp); iio_push_to_buffers_with_timestamp(indio_dev, st->data, timestamp); } diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index 882546897255..c26bb9988d7a 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -106,7 +106,8 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable) int ret; if (enable) { - st->it_timestamp = 0; + /* reset timestamping */ + inv_sensors_timestamp_reset(&st->timestamp); /* reset FIFO */ d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST; ret = regmap_write(st->map, st->reg->user_ctrl, d);