From patchwork Tue Jun 6 16:21:44 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: 13269433 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 18B49C77B73 for ; Tue, 6 Jun 2023 16:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233354AbjFFQWp (ORCPT ); Tue, 6 Jun 2023 12:22:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231700AbjFFQWn (ORCPT ); Tue, 6 Jun 2023 12:22:43 -0400 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D29E60 for ; Tue, 6 Jun 2023 09:22:41 -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 3568m9s6005040; Tue, 6 Jun 2023 16:22:20 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2111.outbound.protection.outlook.com [104.47.23.111]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3qyxvgj55s-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Jun 2023 16:22:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fovD/I4KhYnmSz/s/9H8fsikofMGBFEVx+RZqkvzo1l7U8NnxvmN/O3WSidYySd0ksR9J/6LqkNS96AsMvOJmZqKdNkmYb49INDyXt3o2GrQt+LqD+CLbjFRyY8g42Uv1R+gCUSCN++0kc7a08QhJhO1u39AMnv+Bn2hlEBmRheIFFNoGCekJDYx94a8ZaviV8IcsQ+oKZvyfWdCIAPLPTXPrHKr821/cp4eG7TxfrfnEAXzkGM+rNEXR7apl3O17HFgipOw/ngMlCtniicMGqRANKvpAWVIRbw70WHRO3uBoHJ3Qp/jTNAqH1p9BG897kAvNOq1ZZkyWATTUKguJA== 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=i0/EgbE5etH7aZ6HkrXSYltUVpmY4rdEkYxLhXvCuJw=; b=RF6FkDi1MEygn1kdLWEphnJtYTrvHpD4AI+XGsZbRBchZqw4Nz93hI7W2HV/IZRp/YesQdeyoVnDObZzzIGp0wVHGHIy2DZ9EWJi52BID+VUkUc9KwAqqv40aGdAPM4pAqbzpvj1kIsENsmaX5ngSFt2HqSfalMcGXm2cGqAb8O0NKUFXXUbAvlFmPmMh1BzI3dffDlVD59sO7ij4AVRdbdYKSxlYIaukNghr7+uGoysfwvOnTux4YHgabsddMMyXdNAHujDDT6GYyyXMoPQOGt1ehNZNGTMfFr3F2UbzzgT9U3XgjrG4IjrIA6Csn46O2qtXbPf3J+y+4fpu699tg== 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=i0/EgbE5etH7aZ6HkrXSYltUVpmY4rdEkYxLhXvCuJw=; b=bAcjbylQ1GEQFFw+bF1mPjXNmu+aI2SnBlnKgR9I4HFy0msVvq1/UZPp79H/WkPOVqrd/Rtm8l6ZAje6DPTFH7DQ+oXrSSrdKWIV6seIlINkoP0KnYy1CBnsegD6dqi2wG70exYQtJN5jUJZ4KAMLkahhyJ+XIsOgZNkuNXcuo9Lu1WDLo5oe80poCHJfzT7Y8rhk2lsg9p4o8gEK6WpVZeXKK/jKYMchrMty86EqTd3uuDHW4cihqP3/r83pDvmfmA+LfGBOtgEXe/xk9Y+N2uqvztAMXkEe8b6vMRzbZUhoqBYcUSq+pAAcrtFpJMtsjZsSjCa1kglKsVeEnxqAA== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYCP286MB2179.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:15d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.19; Tue, 6 Jun 2023 16:22:16 +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.030; Tue, 6 Jun 2023 16:22:16 +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 v2 1/4] iio: imu: inv_icm42600: make timestamp module chip independent Date: Tue, 6 Jun 2023 16:21:44 +0000 Message-Id: <20230606162147.79667-2-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230606162147.79667-1-inv.git-commit@tdk.com> References: <20230606162147.79667-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P265CA0212.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::32) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TYCP286MB2179:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f55f20b-dbfc-4e62-535c-08db66aa2d6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DV3c3aXrqUaxFjGgFxwpUgMEw3js9jppaGBPmHFYsTa+sg1CHrFyzRzrtUIXAmObXw2JpnGZSESvYClBg6Z0/IPqhNL1m+XSvQfRe1mzp2fQDwerziBf0sDrtvw/XFOPxaDfKl9gnVx1xDoX+OJJrFoZPsPxLMnaoDrUH/dT2Dx9YmA5nT2xJLFO4N9ZOHuAaNYPT6pF2keCkjWT9oGABmqXydov/7czjI+IokQzOc5BQQlAUZ+jl5l1hNLeZSUsamO98jykvr6WoDPsa4gQ1qlux7+7JXteltKjYESkHmqap5c8KV1r8YflZ+fNwLmNXQZdxADjFacDKTPPuP+kjDL+jolYTmK/Vds0Q7wQq95KVjiat61ZZV3Nq4rvUtW8mbN5cWqb1YdNLMlHxJ5puPfddLLyb5D1AZTO5YjzgKaL31BOazC5j6Zjq8ZgpnzHnYJvp2q68pOb7r6yvfcC3Vci3LZzEbRTNtnfO0j0YMa0TXW5Z0N9YkELSM3ue2hJ0q3DnIjMO57nLj8GmbaFD+ZFIS9IMIO8jQQ/daEb+Y31A2odYHcBIKsXu+MQ60lNpd8JwhBpwgHuYzrEak7RQ1YqPypelpqDmamJRNqjtCbaow6Y2kGYfXjeQaP6CMQF 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)(346002)(376002)(39860400002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(5660300002)(6666004)(8936002)(8676002)(316002)(4326008)(66476007)(66556008)(66946007)(41300700001)(38350700002)(38100700002)(2906002)(1076003)(26005)(6506007)(6512007)(9686003)(86362001)(186003)(2616005)(83380400001)(52116002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CSVwCrXyK+JkTwWXn/0eI5bS0aNuPuKWWxK+A6eEytUTnYsJtMKI6Rqczbuui0x1ezDeYomflu4T5zdS6+UpMwo/tjQTEI1Wz+L/0DV2riPNC+9Q0Vaq1ltr2oBEnrf8KtIoYvLVule42NXB3fYMB1o/HIn6w747LrJJxRMkrqlKHO8V45tTUTXzvYf5UMhsHkwcpzQZ+rhtnGkPFCcoa+d4OXAZsnWWklHpsFnNn22Y4YrQ03wejUPSpjx4D+BWGOY69iw2hMA75OfzuRY4ejWVHAfJHZD59WA+P1ImMAt5hlYhibKTzI8SFjFEIdFNhKyaJu2vxJfNcvaYJ2W0EDgTGV88vwuKM06zomNqr3k9UxQcxyJSvbq8QDDSmiQYlsfOnYXROkVeModMWGzFdI6i3v+rwq91cjANLIfPO2SeKT+KgJVj7jg8pK/FA2uXZ01fqeKZJ7UWJ4SdlcqCgtcKUFIbjHh+4x9amdubXdwDZeGIYtCqsCq5wUzziTPsY+VyK2HPA4NAIAe3UGenmb1iVFsMSYZQoOkEHn7Jq+nA3X23TvTuqcTXWwxORmbyXHsKrBecov8IizeAfOJjuPt67yav36+K8fqpl89f296x3oUZR7MieJy6q0cw1ZyVkWmFdl05SRMYYlhjrDnXWei7taPiDapqDPhxqpJPWSOGOdIhYENaOm/C27FvnpaFe1Se7qmkvlpVL9fVg4Ga2nv26kRrEU5N26HD0VVjV0DfKRXffyV6lUpMobUvEM/kDJVtpHRYtma9vwE6H7dRTenWAyBmq92R8qyLASRTrgvqjOODSwnOXwgcjKco/sw0DvFzhOrhwsTG/lnP2IiGPkvIdjIYGxdnUl7w00tjY3BjhIywqnX62wYHdLxoQeIu0tq7KwF/WRHNWVCic+eXOYa7JoVqH7pFfZEe84ItIf6IuP40I+kNy93IAhkaKZpKMwXc/3lQg7kDFqLCj/ZHLOfElS2g+gkJKWbxVCzkOTPMYjYEgCPFqrFY9Uxkw4sjZth5guUon4L83IWlUuYVD5VnQeCB14QlLq7gSytIkPo9NdlOaUvDr0osQGBSt+dFOV3aDalcgBaX92cJApCuQtadlxuRz6u/JzEowrpYeK8iRWYiEkppQS8UTD3rwAqlkB02b8mdOui7BE6Etnxufm67OKVxiHD25MN/GHmKVqc0sqnVfc1eB8UHjx/qDM1din38k1Fyrqc9mpIbewis+haPrIxah4+HF1s9Swx4jjip6lXxy7zu5w19tZOhVK3s299tq1LPmz7zsDRV0R47MwtBds6im0wWIDRNBo/8MfTp7uw9aBVwN2P1aOW+2bD1hAdzqeac8uVv8zvgJDzoKxVbyHFUNBREbyx2JLL6ks0M9EvZ9L4kLygMlfaMQOAwHY8IdFqilfzPRt+z1fZkfEvoFu2+GrpVGb11Vq1uKI2fZW0Afs0/EJaRvf0Acl7yalKpa4djGMzrBeTWv+lVngn1nDyNqqcZ9UdhQw1P7mVsIUXleZFKQPYrTEvTYtdbDwwvNhlyEZvehnTG7lkzv5+fK3wlzjXYAylkT0JqfV1me3N03Z4pZJVrr5HX1C0M X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f55f20b-dbfc-4e62-535c-08db66aa2d6b X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 16:22:09.7920 (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: ZYW37TOdJTc5XT++cKU3aj0ONWdnhLVW00dyZlh94epU2nzKdcOyPeu2RpFBMqU+986bjaZLWXzLaBlwaYKIzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCP286MB2179 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-06-06_12,2023-06-06_02,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. Do some headers cleanup at the same time. 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 | 6 ------ 3 files changed, 12 insertions(+), 19 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..3e305e7e9887 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c @@ -3,11 +3,10 @@ * Copyright (C) 2020 Invensense, Inc. */ +#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..b808a6da15e5 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.h @@ -6,10 +6,6 @@ #ifndef INV_ICM42600_TIMESTAMP_H_ #define INV_ICM42600_TIMESTAMP_H_ -#include - -struct inv_icm42600_state; - /** * struct inv_icm42600_timestamp_interval - timestamps interval * @lo: interval lower bound @@ -53,8 +49,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 Tue Jun 6 16:21:45 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: 13269436 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 C3F96C7EE29 for ; Tue, 6 Jun 2023 16:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237638AbjFFQWq (ORCPT ); Tue, 6 Jun 2023 12:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237227AbjFFQWo (ORCPT ); Tue, 6 Jun 2023 12:22:44 -0400 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97957FB for ; Tue, 6 Jun 2023 09:22:42 -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 3568m9s7005040; Tue, 6 Jun 2023 16:22:20 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2111.outbound.protection.outlook.com [104.47.23.111]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3qyxvgj55s-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Jun 2023 16:22:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KEmIHD5N2lo32eZFS+LvQVofCu5lSTxwbjcH1KptH++zIrkA/1JIF2zg4fagSfnxi8SFj39C4qMfW9icNkRIoKzFdoteh6I7sOzoJ724uUIbdH3rvHMDBQza3XSsV0FE/0K96p2T9wE4btWVrDCKH/CFleffncZQrD4n5ISFaDoMvPSzdSsfwWRlFwTt38VogXBUAzuAbt9Ia3+TO6zM+66bGK7YvbuVDZwUSgT17ZBEMMj8NX2mpAQDipOwwR8U/ZdkBNvIkF6Fh5RCEHwAyH8kRMpa6pTa/eJVoGe1S/pxfnJhd/KUZGY0Y5NnJg1pNESVFnexeZx5EDGItFxiiw== 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=1e/6spIzRRlQvVAr7yIu1yBt3CG7RNFfhk/CWIIsZUA=; b=cGxv8vGnJo7Q8aaKuGzNz2iiHUnUb6K/rZio3SjZ6Hq5dZOZOCXqb7a5BESMHts5TJwal+UpLdSMsPimKHmOkaeAk8HsiyqsbJ1Li5M3K1NfLZK3QZptuCkbjHbeO+0L1FqjPVukRIb4uU/ahtmcZijucUUtDP2iTHOPJViDzPr5t7KTUCmSa7ALePXqAuNR1sETj7VBOAZs6bknvdH2ELR6xBukruiyf1yEIdfH7MUYZCKM5N1Ha2W7QSb6vzTENEl4q57cw7CQ8HoTCEhONmeCJn8xrDAvr3/feFTEYaZPfYar2Refg6nGfulDxpbnFJw6a74tAcW+ZJJbxtO1qg== 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=1e/6spIzRRlQvVAr7yIu1yBt3CG7RNFfhk/CWIIsZUA=; b=WV5DjI9i5p6YDl6/q8EA62Xy+ZG8us+yPPHOPSsQyQ9IYYNoSib9o3iLx0X5XbkgTAweKxj9I2vM82/AoSJB5UYf3B7qpMrqKFib2tGOUPgZZec++9tGshLz8DnS9FNSRSxVLe5dW9SAINpqkwNKUkslY58bxp+VOaCxfW/wXRJlxR2j5ZnLod5eIkeOOF+eOa6Wz6eEhJ0JWUUvOhUoiQ8QwWkbZoh324eBvUNbYA/onTQj6T1buJrE7r4BxRRP6+A1VyN21R1S+OxrYwO5sz/7u//qkK6Kt4Ruwc6fNmy9hNHULNCCPNt2hzb6CxDIiDf8SJ5/QYRx4YeBm311aQ== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYCP286MB2179.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:15d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.19; Tue, 6 Jun 2023 16:22:17 +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.030; Tue, 6 Jun 2023 16:22:17 +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 v2 2/4] iio: move inv_icm42600 timestamp module in common Date: Tue, 6 Jun 2023 16:21:45 +0000 Message-Id: <20230606162147.79667-3-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230606162147.79667-1-inv.git-commit@tdk.com> References: <20230606162147.79667-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P265CA0212.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::32) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TYCP286MB2179:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c839d1d-7eaf-4300-98cf-08db66aa2ea3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9+sZXctgSDySgORjip6rat8vAnaqZakf2ok4kU33FYWJ7j89M0Xg9hNB1c8XXLK2ZFRPS2ru7z6Yp4LM+44EGNdUDNXQwfCojTWFx4qM9W8Om/E2XJjcleP5K91EmW9F44tFfkUMChb8aLnvcOcHJGWwqVWPxlw6bga8RkWwiAJamTC8mXgPoE6Hao/S89wuVF2djRfIXoZFm2k3hjiqpaYg8OGSX7t3rxim+78CgpK6Krduc67mrxAA4AoZI+5ui8gCOrWdnHKlohkoFdf8moUEyBKt/WrSw2b1m1e+CxS7iT0jpJpoaIEPMoEnu3vEtbDCBTmPOsuCngMQD2keBVfojleFEDDaI9qZ4oXkMsqWgZVVu+D6UqbdrQywiFZCYMOdMzYtijuD70TxOVtdocLZuQ90VwzLvn1Zug28UXWDQD/MB0lj29KIhHKel1JpbceljmKg9jueiIaDI0k4RPLG332nLQJjJexUpgzuue6lJQXDeweXrVzP08NM/kBxm2ZFli+lic0uhlq23Ep8CK0xyXmEGD28FPoHt/G1Jvi2DyqNBHRXec6Ep1BjxgHWddwET/edNNN3fEJ40cN7WYiJJ0IlEwnY5N0gMmW0mqIk88trx+vSA9xrOJ8xZie9 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)(346002)(376002)(39860400002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(5660300002)(6666004)(8936002)(8676002)(316002)(4326008)(66476007)(66556008)(66946007)(41300700001)(38350700002)(38100700002)(2906002)(1076003)(26005)(6506007)(6512007)(9686003)(86362001)(186003)(2616005)(83380400001)(52116002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cIJg02m0LiGKYB0jkqpYG+UdaLcFO82Wm6fafV3IzaERQpStMChRzp6n29VnSzWJGfQ1fJ6fKCi3f3XBDdPNhNV2YMVn5NehJq0TiWzA5nGTFks39rUTdOhUJjKAhJldSSNCdXpJOPxcwrVsCSsRBbKaDMMRI0rarWn86ZdujANxqHm1OsJaJrYlDJOTgy3yEWkoXHPaDtNgnPs6K8Oe8UWEAeF6QAwT7uyDxNDXuzdi7DUv5dl4lT4HZqKfUJwVcA4VYzi6O8bzS3N+Dp06aACS5Fu2MwyKkp2vV4bbXWZfUJiiF3v80+/h6/Spq4B2HLyMI8BvaiH0t7LhtIu/y+YGpZpeMxaYHuqsQIA3Ip5+mBaSWyycAttI9lEqvUK5RAhvfADtFQzO8c3KbDXqvUcIQhN8Aj++lXmqtRxSJpJH68TvNcHFR54pclvLnGXeDqMwOIaML0/kg0Knoq+DVBg0G9+pHZmZaj7YQ/bQvw9FPVzq3gWfWbcdJlOBLCTW3Oh6shf/IaTIW9xnGGTa1z4OsK9Ftq+Eb7KQRlk56UsvA2wj7v9QsyXoUekPYuxFaJSSVNa9C2xhN5GP+GtFmzZOGnkusmTwjnYZp/XHMvQUiGp8FxyCx1Yb/sUMtbS+rNEbtZ6+mp6foDSCqdsWpzVRwTGDAw40qbxRAU3PYOztHZInJbadIzoaMZ8SDwYR/diK+Q1qZtX92rQkSsbBCDg4I8plvU2q0xXioLMVHOg6oWFHpXECbSw6cHqIjCnuq4L+sHse2PbzbHfQL8PVGIUUyiqtvxm9QAiM1erXb7VK8L8AFvDRxb2IyEOBwDU32Hg4M9vk/lLJza151r+AQqeHBpU8S8NywS+az/tKfj41OMX+Hfq9OSw72EDn+V8ztKxfONDa41fs3d2X95n18Xscm3KXJOjHAC7HNf8/BiTB1VxJ1wtaLGpLnMByioj0qkgsrRemk8p5y9jpqx2mWWYUDUlf5w9MytzHKw3tTT0SrBsgJk0gXeNpXakvgAx7XA4BHCCq+SzJRkZntTd400N767WHIgQTHiyLBvcXNhFyhMLVzTUDYQfRvo2GvUrnN+x+BHI6nSMH3mPvoFnl59M+zLAo+gCOmo7jQ4kS6rF/LhphexS/B8GUS0KXDZyq5bDd2UF5tsX7hFo/GC1fS0sYzA21yCMqrynI13BEQEVTwtvxwN1L9DorgRLNBLOpjy/7oXxR/Mdt/69YO/pUkbaAFNmOtfHnHE3jygsqOFXFEAs8sbx6vDyDAfMJP6I9TqlFO+kt+yyBFk3VRYIdjZGSmRKmKQnQv5+wiLA5pydmtMx7QhjIT9L7i1TbNRDF4lVUPpUmmHtwcCvwMCAxJDMwxXeCHdx7D+IJ+xc6Tmgc0tfsQjh9P4N6V3DNFLoDfwS+Ut9s4YjTqPcEGh7l04e+oldQ/TFa/P3RQbnbtJqBKBJeP0vY6RAMEiplYvpHDGb/WW4r+p4McCl7fyL9AOGgYYyWlR5kaBIRC/XeLRbTboNSfsEXBqOkie83W0ek0N7wTNLE8exQlE4/hN95RFTIJHxcboQaEr4/k0yNw+CwMlNjBm7Ys42Uf7RcD/EX X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c839d1d-7eaf-4300-98cf-08db66aa2ea3 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 16:22:11.7895 (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: t8M+KiuQyxgPW5PaWWFcJwIBtLuZrr/+6lrLcYsj5gyYOhTF4IxF3gayb2zziJRLCDeyLHBZG/zQcA7uacdKfA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCP286MB2179 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-06-06_12,2023-06-06_02,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. This module will be used by IMUs and also in the future by other chips. Modify inv_icm42600 driver to use timestamp module and do some headers cleanup. 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 | 11 ++++++++++- drivers/iio/imu/inv_icm42600/Kconfig | 1 + drivers/iio/imu/inv_icm42600/Makefile | 1 - drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 5 +++-- drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 5 +++-- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 4 +++- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 5 +++-- .../linux/iio/common}/inv_icm42600_timestamp.h | 0 12 files changed, 38 insertions(+), 9 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 3e305e7e9887..7cd80cdf0ee5 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_timestamp.c +++ b/drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c @@ -6,8 +6,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 +55,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 +68,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 +156,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 +188,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..c2591101645a 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -10,14 +10,15 @@ #include #include #include -#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..ba4bb389a9fc 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -9,11 +9,12 @@ #include #include #include -#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..9d227b4776eb 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -15,11 +15,12 @@ #include #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 +800,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..0ea3d8bf709d 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c @@ -10,14 +10,15 @@ #include #include #include -#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 Tue Jun 6 16:21:46 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: 13269437 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 CA46FC7EE24 for ; Tue, 6 Jun 2023 16:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237977AbjFFQWr (ORCPT ); Tue, 6 Jun 2023 12:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233485AbjFFQWp (ORCPT ); Tue, 6 Jun 2023 12:22:45 -0400 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05F71E40 for ; Tue, 6 Jun 2023 09:22:42 -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 3568m9s9005040; Tue, 6 Jun 2023 16:22:21 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2111.outbound.protection.outlook.com [104.47.23.111]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3qyxvgj55s-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Jun 2023 16:22:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dTgrqCJzYwgmte936OAZ5seeXwGVJoQbQaPtAxKHdUCMd3OXeD4gpq463wGySEjCbp6OGRknuNVMhosgKrnf0Pn7BdjfvtchMH4FFpqT/FhuypJ6b+1r9w+zv/pOcg2cET+PIzU375pI3pKPc4FmIEQM/qL396C28k936fTNHQemjH9rvo9Tav0wwGiUCUe9wNsfjhRAimUdnIV9ONyGU+JycIqPmdlwaddpbRH6OkP7kDzRRNAT9VVNhTUr9EFFc/mIjAF64iXuw4GtDCcaY9YXqrr/XDfH6nv4gBv1VLc9sMN3RBEfYnUOtWQ8ZFXktLgxRlIcaj9o5PS4+tTvYg== 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=91m4jX5cnpdJX6OlwIy0jlgHXkN2VA/WCnPhaG+53d8=; b=nMH0ZjdoI4z3hftPHp1SMTorgi1HccgSMDkzx9k0DM5X+fQzh6/U/UyZLeReqqWCkZuE5h81iuBUx6kqZ8EM6VXaEjfmfBgGVtnFxrXvJPV92l42iJLF9bsNKJQVY/glbx8wdXpVoW+RXIP3KaxRcEg8kDoCWP4EeQNUI1ZybZaZobVuVapJgBh+icgi58k2c7gIbYrxFxTHM104ZrIUZFV13Cd18K+kINSbHDXiVIrShJXrjK4zBdl8PbFwjouiIW/bItVxHOebFpvygmuviyuaCbHXwSK1huWNNndyqm1eP7uzpqEpD/ACC+X5ziNFDZFop0/EZZNjLemO4H6WPw== 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=91m4jX5cnpdJX6OlwIy0jlgHXkN2VA/WCnPhaG+53d8=; b=elsKr2Xgz84rzXwV+Iw4MjRFOXeH9ODkl/gKY0EAdDXk+tuGmey1UgOyHwt0KvApmG3nXV1OGYTZRB37MFzBzCIwFgHjdjX0eF7OEIawedKY0nyALzgGkdj9Y7NFLJMZZJ43hCEM8jvu9EwCUhoWPU6lCvRBVSXg2eO/CaZmeoPLHRfBwBLdz8H9dKcHKxY4kqhDOlVpGP9vVKfrs5KYM2uSVgl2UMrYkEkbeGmW3qu41toZ7GPbC6b+k8QFJH00tf6wbAIxpJZ0vi7VlQA1o9K+m1DP9PC8aOmFrfff0Uz4uYS1AW8nA05RocsasFK11/0rWSn9d+HghF2XOheiJA== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYCP286MB2179.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:15d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.19; Tue, 6 Jun 2023 16:22:17 +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.030; Tue, 6 Jun 2023 16:22:17 +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 v2 3/4] iio: make invensense timestamp module generic Date: Tue, 6 Jun 2023 16:21:46 +0000 Message-Id: <20230606162147.79667-4-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230606162147.79667-1-inv.git-commit@tdk.com> References: <20230606162147.79667-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P265CA0212.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::32) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TYCP286MB2179:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a07c113-865e-48be-b7af-08db66aa2fd4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: thUwgeyO8C328LRpQQSanufm3fPkoYzDkiYlkoX26Z8/BP4qlaYeJzqFnxiNc32oGSeDm4cSNGpUZ87LnLnkiLh0SVPdX2OfGvnMqhXrV+p/gkO1s7el8JUv0qhtYxWLaiZGucT8cYv3c7TLVqP3Hnv7X6/aHmElWoxcUFghLFtgHx/LKAQWO7CZa2NSW/5Ke9VbfLjGF8CjCDSlmABM8N6nECyCSZXm8NtknuLynbC9iq/sbNZ7309R3FemMUsdFWe16/YoXpGhFnPj6BuLWeQQXCgUJFmz5gXm2se6Ok13+u6qaGHZ/QBL1jr4/8O91yOm59ay4b/sGWl77fTYtaiVmaDRdGockQu55CTh4JL9PGbsR7WyLODzp71VwGaLU53DpnoEslRqU8+KU4xjp8ZSpB3fXm0OaxqZzHMKtxPpCmUh94i/DNrQ6QHs7emopZFTsRXCsL3I2BqMAeXfYowexM38IFQEw5LCZiox4XsqA1FTWcf/x/XbZCf4muHTfXg7GdS6KjXhwel6AQTzdvoBbM0fU2QJJds9CEj7yhngtpsRypXERT9yIyyzR8HRzh3e1W6+jqdZlKdJygOD5eqsofgcOtFhfAaY9Q8FdHXKgM2mpTUGF4UP8CAOYvglOb3sDTx7kWVAX6uncoDwlw== 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)(346002)(376002)(39860400002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(5660300002)(6666004)(8936002)(8676002)(316002)(4326008)(66476007)(66556008)(66946007)(41300700001)(38350700002)(38100700002)(2906002)(30864003)(1076003)(26005)(6506007)(6512007)(9686003)(86362001)(186003)(2616005)(83380400001)(52116002)(6486002)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mstw4D2ntX3HQMUksBKIRfpk+FC3W/7uF+CXcIObnattW2GClC/DODgItqtSSa0GrRUEPVSZerheaHborDSvMjBntZNVRo5ce6ZY/fD7q+TcjaJA6+AazdS4+HVlllKDOALBuCfapnLuz6G7IBZA1deTN1qBjckASfns6fYdOfaSLfthszTxGMwCIC3AdYqsJGxaz4hZ4WIQeyOiSs6VPGjCuBFurgNbsjRW0b3im/ijwci+KHFuz/oyLmf4dkqMPXblBbRLImevuia235VscLULy5/lC+fap1ANYiNkgCaGZp4pwtNj8u6WpNNrFeRV23ecDe+UcezQ7F2N0yWv/+R83ErmP1ASnq+Fl+HVYvAIe3hRDbjkPXTGgBUeQz9HTK4txMRjCd493VbaKfgbZzyN6xH+YtAjNn9b79jOy8pVMr3AxKncGU0roIDE5N6U4x6MM/jev3+EXYEYZPMxyz14O+RwcdZhbv9FRB3vlW1T8zzPU2LnUQzCTK+udeqpfljM9Sh6nnNG7yy2ESBddPXOEaWgJ3WA54iWhDSxI3nA58mAFdUZlbN+Fz+ItiBedy9CC7yMpmcIAI9RnxFs+Vt/J8RnNEdI1MmrtoQwwGYTcXopHAJXM2Gp54JxRfhI1mOXJOwlOHfo8q/lu7vZdIkeN5pKHcGqSAl+oBADpR4OXIzicPM2BStgcZksXhaQjbS74eKY/LPuNfwK6Muup8C5PLgSvi1xWq2fh2IT/9YbPKetg2muxZbc3M0Cm68pM02442RSUmSufMN6AHF1eIuzzY0Vq5uRoyQEtEw/PGA/9FAC4R4QE8A8EsuH6M003RuRJjVWHgwr1Gm9UpYrD2Qhd6CG5wOtJffjjJjmmj4l8Qgm9Bn3xR7nMmJHjJSiLIFYC/6yLnRgpWvpDxlbE5ibSpjJcSupu5/tAC+o3VxG3VhsElbCaRG5yddgbhPcIMNKSD9txFvjg3FBWVbYl+QQ+MfaS/pVT9hcI/o9ZkVnYHIzgJf5Y+dXm1nC4r6ltC4iYeL//j2yvsHgXe22+K32sACMc+YbWsnrwY00fyLy0/pSPPlwQxXtaS48HqBHb1iZ/mk1qE/gsvdJXzX91ye5jLpvmtmMiTRy9t9gbFYkR6d7AqRVWjTY5Ar21sIpZyuugXaDOXIkI6SBK5EmuRa4mUUPtUIgMaBk+mDOtpKsl18r9ezMb2mX79OhBDsoxUkVEG8ayqOt3FRPfzcknOynNFusCKEv+Zlek5cR6aRpGhfmwnusGTlnH2yCcvK5cNiJUH+eN3j6ftLvwA6I2rFuvRfVOzevnAOMB05CPpzIWz2Vrco+QWEMLH6UnUqip/L/oCzcyMNPJ60rsyrL2WZq563m2jQ3U7eLEX4TLLDFtF3PLWrztdvXqvYDJHLAaLPnm/YfGC/musxYTxzSD5jaJU0j4NlfhMQdHbTSy+U6sYjKfAKBYRyELxKGsQ9fkjy3KsmD0jkMCNkjMil4ch88OgBH4FlD/xm6vmvzFqvoHqOGGV8VVjPBgiwqrLwBOronZAFpCoqKq40iD03iuyyD7PXk/d2x4aENVIRbzWTzuinJuN+q0lX8R94Y41hK X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a07c113-865e-48be-b7af-08db66aa2fd4 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 16:22:14.0242 (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: TxSzS+pVSnqQRDKwsz/B2qDgfY6axBnIzxK8c8Hh7u9qRiQUmNx1hL4BMXrbHwg6ujR2Bvtas2ZOWGheRZKg1g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCP286MB2179 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-06-06_12,2023-06-06_02,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} | 87 +++++++++-------- .../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 | 79 --------------- .../linux/iio/common/inv_sensors_timestamp.h | 95 +++++++++++++++++++ 8 files changed, 194 insertions(+), 164 deletions(-) rename drivers/iio/common/inv_sensors/{inv_icm42600_timestamp.c => inv_sensors_timestamp.c} (58%) 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 58% rename from drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c rename to drivers/iio/common/inv_sensors/inv_sensors_timestamp.c index 7cd80cdf0ee5..03823ee57f59 100644 --- a/drivers/iio/common/inv_sensors/inv_icm42600_timestamp.c +++ b/drivers/iio/common/inv_sensors/inv_sensors_timestamp.c @@ -8,20 +8,18 @@ #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; @@ -40,56 +38,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 */ @@ -100,7 +99,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; @@ -109,7 +108,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) @@ -120,13 +119,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; @@ -156,11 +155,11 @@ 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); +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; @@ -181,14 +180,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 c2591101645a..b1e4fde27d25 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 @@ -99,7 +99,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; @@ -127,7 +127,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; @@ -312,7 +312,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; @@ -331,8 +331,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; @@ -708,7 +708,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; @@ -720,8 +721,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; @@ -746,7 +754,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; @@ -769,15 +777,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 ba4bb389a9fc..6ef1df9d60b7 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" @@ -276,12 +276,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; @@ -505,7 +505,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) @@ -513,8 +513,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) @@ -523,8 +523,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) @@ -537,7 +537,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; @@ -553,9 +553,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; @@ -563,9 +563,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 9d227b4776eb..a5e81906e37e 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" diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c index 0ea3d8bf709d..3bf946e56e1d 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 @@ -99,7 +99,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; @@ -127,7 +127,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; @@ -324,7 +324,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; @@ -343,8 +343,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; @@ -719,7 +719,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; @@ -731,8 +732,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; @@ -758,7 +766,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; @@ -781,15 +789,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 b808a6da15e5..000000000000 --- a/include/linux/iio/common/inv_icm42600_timestamp.h +++ /dev/null @@ -1,79 +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_ - -/** - * 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..a47d304d1ba7 --- /dev/null +++ b/include/linux/iio/common/inv_sensors_timestamp.h @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020 Invensense, Inc. + */ + +#ifndef INV_SENSORS_TIMESTAMP_H_ +#define INV_SENSORS_TIMESTAMP_H_ + +/** + * struct inv_sensors_timestamp_chip - chip internal properties + * @clock_period: internal clock period in ns + * @jitter: acceptable jitter in per-mille + * @init_period: chip initial period at reset in ns + */ +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 + * @min_period: minimal acceptable clock period + * @max_period: maximal acceptable clock period + * @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 Tue Jun 6 16:21:47 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: 13269435 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 88B8BC7EE31 for ; Tue, 6 Jun 2023 16:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237227AbjFFQWq (ORCPT ); Tue, 6 Jun 2023 12:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236500AbjFFQWo (ORCPT ); Tue, 6 Jun 2023 12:22:44 -0400 Received: from mx0b-00549402.pphosted.com (mx0b-00549402.pphosted.com [205.220.178.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CDD10D5 for ; Tue, 6 Jun 2023 09:22:41 -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 3568m9s8005040; Tue, 6 Jun 2023 16:22:21 GMT Received: from jpn01-os0-obe.outbound.protection.outlook.com (mail-os0jpn01lp2111.outbound.protection.outlook.com [104.47.23.111]) by mx0b-00549402.pphosted.com (PPS) with ESMTPS id 3qyxvgj55s-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Jun 2023 16:22:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OtKMVPAjO8fR5CaUowl7TYv/kG2p4zj3Rtidd5NzE51Q40UxQB0e9FXgt1Q1X2FSB1ZBNe7eCy5SCcBxumnQxVn+UCc20mgtX5kQURN54FrD3KYAH+74zDhhozxXSXYA3N49K6K3SPznIDkFgIdNkDH6ipODj7gjxAkg9ycUIQYz7TsJMGLrdRt7gZfP4nSpRyW4QLh8UmT2LPViSdsRmMsIU0ZiVoMkV4kfAcfmhrPVWE73DLQF0i5ikqBbXJwHlQw/pGNTcT2WmW/i2TEZP4Nn6wdP/e/kOCbP3i8jvBq2NtEgs6r/PeQKZA16Iogto2aULsJEIxe+Aq64btCONw== 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=e5jwordiGFcx8XvzL9GZTFz+sKLUqev6iQpGV3INcA8=; b=PLj7c2g17J3Jm+lwwx2qXI4WgsMQAkjOfXMsaTPBXnNwkwWjM1WLvO+CqRuf9KaIW/oU1aMCihDGoNGYRTJ4upokdvvsJ4phIf0+jMHg5pr3IO/sLjELwBDAmrYMZqh3RmC+RZgA3/R2LUkIcXLtLJGd62q2PneG6Y0JlpmbsJBSTK/cSBWhBeSsYITu79vLQBcJNzMgBZpiZX05NGnCSQW02+oWM8aqk5eK8PEteRzPbx40SXTW7GqR3qpJh9NYUM+G+k40j//mI0MMRLzphZhIKCkjLfDHpWrreeYPiBQ7fIi/PMIiXE2DFwyIaZuFW+2BwNyTewasLaohJDYWGw== 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=e5jwordiGFcx8XvzL9GZTFz+sKLUqev6iQpGV3INcA8=; b=dODLl3lCDvYLCNzvP8nJF+vEKaRWAHGuKTLppa5MSAPs/R2NB23Fvm5NlR3m4c7EpiD+Ejf3bsuiF85dAga3SZVjwCVhYmDHm2G3XERdB5ZhhaPdLaCHfajDIqHTPdtE+GQTp/bHLUR4li7/Lay0tPRwdBuffsmywM8CUxtGfs/KyO/Ve30yYYS8YiQwIsc6ZKrHi+VCNLMLYnYxv+TFULRFnAe/z6iHcmawak3xA5Uj1fJZmR4dXuxwQptBWKi4yLOzz6UWRQZXVjpyxj7ql1VAWINFDVKLp05Ms+gDUYEi8Ax4WKurPXn0ygezxY4NkJNuXWTi9nBainNIPgj9kw== Received: from OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) by TYCP286MB2179.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:15d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.19; Tue, 6 Jun 2023 16:22:18 +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.030; Tue, 6 Jun 2023 16:22:17 +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 v2 4/4] iio: imu: inv_mpu6050: use the common inv_sensors timestamp module Date: Tue, 6 Jun 2023 16:21:47 +0000 Message-Id: <20230606162147.79667-5-inv.git-commit@tdk.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230606162147.79667-1-inv.git-commit@tdk.com> References: <20230606162147.79667-1-inv.git-commit@tdk.com> X-ClientProxiedBy: LO2P265CA0212.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::32) To OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1a7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OSZP286MB1942:EE_|TYCP286MB2179:EE_ X-MS-Office365-Filtering-Correlation-Id: 637cf58f-59f7-41c9-9814-08db66aa3129 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8O/qO2iKfwlW74DMde4if3OZidYTm7XJo4JKPQQHVav3Sfx8ATTNCyXZ0F+UoB8hqpyw3iWZ7ST799UShC5EN7w0L7pl1Vftg7vKP7I5G4phj9e9GxY5rJyTeOkcvFSyCaZwLoiFSHDL2e3JfaeTIMx+VE5I4+PnX2CP4H+iNhERvI+ibVNQGsY+XiP2bOZfOb4AVuLjf86QPq85VhJMKXJqEuu3i+g66Cr0EFpW4qJndYz20v4GH30kFgVgIb1fwa2rcowILqZH8+YBbMn+QJp5J0mJZk0llq4IvXUO0/Wugo37NQr9Q1lVy0BLnu9ZQRZnS9p0E/K9EF23b+FnZjVNJP3gkANltaYCfYomDrU9EG9hasKKPQVGDufFKRz0CT1nHPy/l3/+yC/cb9aCBSj/Y5pYwIvld0Ln7MT3vnKnOfTv+FpyDWhqgO/nvEX1YWsfX09P9Nv1SGeF+7pslWyjKO0gEw/Rd/zuwwQS2Z8ne5rC256KA5BFhtOLyXSFf7c5Q14H5cJ0feTjfSgagplYm3U8EW2ywDafmNTg9wpxhj6TzctDXwGWlqDAgnwY4eFdaDzb1j1owc+JaGE/A9D8N63dNsAzNEOttytynfar0iNEpYodsgO0L8h+G49k 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)(346002)(376002)(39860400002)(136003)(396003)(366004)(451199021)(36756003)(478600001)(5660300002)(6666004)(8936002)(8676002)(316002)(4326008)(66476007)(66556008)(66946007)(41300700001)(38350700002)(38100700002)(2906002)(30864003)(1076003)(26005)(6506007)(6512007)(9686003)(86362001)(186003)(2616005)(83380400001)(52116002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qjGtuw32Ujx82h0ekUDvR7XJBEsIwlO/LMK0sqSTOhZY3RsjYtW0RgA168uMjv01x8Y8kS1cR9OkkcXAxBN2Zfq3m+FXFiDeEKpvIRVpKI8ilF4KNy/b4kycm4o5XCvIWp6b+08USkRT4TrwLw26ja1ACVNt+UJGGTYvS9fed22VBpt3Sp/uH+R0lWXENLV6Q18qr5lk6yDzhkvdFaJB/k/oWxl8Qkp0jsqcHVwYNsgJ+OP0qVHWQN8p9QId91MoQ2EE9tIsDSw/hzQjdZ6BQrig9TBiJYrA7w/1FbT/tOJ2Xcj1qIibQbkaoSM4rIzoI29QUnyd3wpczGEGgpP9dCEmHLWM0P8tkVYw/MFaD5lj7dPLskivgGQ0byPvIXfUIkeBEI114+jFHXpbUzzIusXWnJLPWaHssQ27yUF3BngVKNTOzuMoR+GG4VkH03BiCl5EYKpMoYT2399YBg1rgOnC1q+m1ZisIAF3XIE/NqRy3e+Y/tf1C6zE7cLHqCmZLgWyoqXC4xalfTUraJDg2nF2HGPyCvuCjOOPpBwFVXAP/1mAhgp7Pof0s0kfTgEaigKHAR5WHwiB37a6Rs6WaWuBWikm/WvpxfLtuR/AK+KFdbFxPXhNycKfijfenlYLZ+0vJXNQuIsUlMKRLywx40lqO3DnHEe8e0IW67WkrRbEFQwpodnKjQr98nk4J6HliwrPVXuXMRJujuji+34DZ9NVWtid6L2kont2JbxPwSqDqQPeQ6LranbEK7DxG2YhaK3CL1OGU/j2npJ9uJFbLMI7eFf1KyJ/TnCQK5LocK+HNof7oid4gyzVnYE5c0qWQShHOxM08ceMxQsuASc09wkhPE8iQg+lPdC01OlY8HPiONgsz5pjAO0j/45bgsysO3uzbfw1po36EXlYLHihUUBV3l72vLDfEJBgrDQKoTaPBX7gjaYaIqatMisdFuQblPMUbnUkAKyK3PWUhK+f+55J2WoD3WWs65xBH3Jd4w523Jhz/nWzYAXqH794lXNf1y8Pu8G2h+UqGzD8E88tvUQD+J0wOWzh/pBGD82yMuZFJomlSKPKL3jtVT9ObQX0kwms5PSmhp4csd5qPLg77XvpyTW8pCkRYAfl4uFZhgV+ioKUrZ+u+xEFQg1KP9HfeBamakLw95IaDjXwFGxZyMdghqJehiErqzOztfr6rGnHxJM3+h4V3zoQRvCRVUPMcX4r5jPpAnj8ppEyfEv2hk1VdU0pAyAssH5TzgUm2BaCWvoev2d/rDtK608woD/DplI7CoiPkH3LQ2YMLPILYYNTHSDZ9lVm+eIy24c7phlQBe6mgOerjPLG3+Uu54TNSeKB6cdaH23cFVTqX81nu1pd+RZ+fB0KXEGVc3RRcEh/FX2bqTpo+p0C52tSHctGNiEBlxQN0QzYKP3YnEP0C2poybRT2IbDCGOz5rxBvLuSWtmhg23QFClybK6rzyXwkU++VsXKk6J7Tgyt43LUNhZMza86VR2vPo6MZCPdkJJC/1wC0QcQuZn6EgyamG9322tWUGDy+6sv3Dk4h3vjV1ZNeItOJUvRLNtjmj3Oi8Gy3DVL8hK2wn/kUfIkcBHz X-OriginatorOrg: tdk.com X-MS-Exchange-CrossTenant-Network-Message-Id: 637cf58f-59f7-41c9-9814-08db66aa3129 X-MS-Exchange-CrossTenant-AuthSource: OSZP286MB1942.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 16:22:16.2534 (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: byc9zzBFcK5RK899gqLo0kWy/lDuzuUlqoqG0C4MSH2wo6fozsHAZAIPj8ga+ulas4Gm7MU8Sbdp/eWWaFTlFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCP286MB2179 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-06-06_12,2023-06-06_02,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. The principle behind is the same but the implementation in the new module is far better providing less jitter and a better estimation. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/Kconfig | 1 + drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 30 +++++-- drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 18 ++-- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 83 ++----------------- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 6 +- 5 files changed, 45 insertions(+), 93 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..13086b569b90 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -12,12 +12,15 @@ #include #include #include -#include #include #include #include #include #include + +#include +#include + #include "inv_mpu_iio.h" #include "inv_mpu_magn.h" @@ -521,6 +524,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 +548,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 +940,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 +958,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 +1800,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..a51d103a57ca 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h @@ -9,15 +9,17 @@ #include #include #include -#include -#include +#include #include -#include + +#include +#include +#include #include #include #include #include -#include +#include /** * struct inv_mpu6050_reg_map - Notable registers. @@ -170,9 +172,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 +196,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..d83f61a99504 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c @@ -13,81 +13,10 @@ #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; - } +#include - /* 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; -} +#include "inv_mpu_iio.h" static int inv_reset_fifo(struct iio_dev *indio_dev) { @@ -121,6 +50,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 +107,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 +121,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..676704f9151f 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -4,6 +4,9 @@ */ #include + +#include + #include "inv_mpu_iio.h" static unsigned int inv_scan_query_mpu6050(struct iio_dev *indio_dev) @@ -106,7 +109,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);