From patchwork Fri Nov 25 08:35:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 13055599 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 585FCC4321E for ; Fri, 25 Nov 2022 08:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbiKYIfs (ORCPT ); Fri, 25 Nov 2022 03:35:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbiKYIfr (ORCPT ); Fri, 25 Nov 2022 03:35:47 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70054.outbound.protection.outlook.com [40.107.7.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9544D31371; Fri, 25 Nov 2022 00:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gflwdJWoRH304oGhg05fr/G2/WIP0AkJVAUn+bBICNVLj574vnWuDNcxPj9mtq0enq2csiyhyznDBSHh0yI7FiR0c70z9LrOn48TEJJmykkixIPFjZRmyOPX0RLZwiLT5Cu5XP+38s/0ZfgBLvZ9XfZw6jDSBLem84q5mG+trIy7z7yzBzvHS9JIiP0Dx74PODVFwAYaQW6OO5gOKOI1Q+z9u6DvsbyCefB5ySS3g26nGGYggMrfe9+J1B3RosCHNR5bPwvlEW5Hfixqle58ViidNwHS68Asfwx3/uIGZ9pQ8di4TVYIffUA4sHSR6g3ZMIjZIR4xcC/enSBeW4Gng== 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=UHZrtVTVx7BdBWrx8k8G0wo6sQRpsya9kqz08AJ3VSM=; b=nTbb5NBih6tq1ybKZ32wRbSrqNmJzZh3DTLyNaqzfnUYeIbWe3LkuCUcqXiinkg7LEsrGLDTV2KN+Ra6SUJZQ2SpEf18wzX+nBJTQK0TlXjib9Mmc0sRXqc+tjuhOQFtMPg17VlV7eDfpIVSbQc9xkAGd57byv+aVFo9BitQROkq9rc9ROS35XSR+wXSeWlvQQKGid008baa7MGIh8cY+j/nrJ9ZOd4EYTHSJHKymFIAWpDeCEp1H7+Q2LJobC42pithXkwf8RaLhJpzvGUA6VYD7Z7RoHyFy655B9ISNb14gTKugWztAxgtFFn6W7VuaFg+qF7+qim5bpqjWGYgtA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wolfvision.net; dmarc=pass action=none header.from=wolfvision.net; dkim=pass header.d=wolfvision.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfvision.net; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UHZrtVTVx7BdBWrx8k8G0wo6sQRpsya9kqz08AJ3VSM=; b=csIRdBleuQn5ST8q8EGUQfHnH/8V9qc3WC+l4UNN+oUJtkXDDYlT9Ua0Af0siJDpdocWFAEhRc+zklq9FrTYICiBJ6fW1wSKzT3mLCG+fVBrVACt6FTXi+fiB5AF9DUyF6mJI/Xr4B/6a8jjNodDK3GiZ6M3ZuHKuFYciixPXLI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) by PAXPR08MB6751.eurprd08.prod.outlook.com (2603:10a6:102:136::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.5; Fri, 25 Nov 2022 08:35:43 +0000 Received: from VI1PR08MB4544.eurprd08.prod.outlook.com ([fe80::bcc7:bc51:bf44:1454]) by VI1PR08MB4544.eurprd08.prod.outlook.com ([fe80::bcc7:bc51:bf44:1454%6]) with mapi id 15.20.5857.019; Fri, 25 Nov 2022 08:35:43 +0000 From: Gerald Loacker To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Jakob Hauser , Linus Walleij , Nikita Yushchenko , Michael Riesch , Gerald Loacker Subject: [PATCH v3 1/3] iio: add struct declarations for iio types Date: Fri, 25 Nov 2022 09:35:24 +0100 Message-Id: <20221125083526.2422900-2-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221125083526.2422900-1-gerald.loacker@wolfvision.net> References: <20221125083526.2422900-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0501CA0011.eurprd05.prod.outlook.com (2603:10a6:800:92::21) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|PAXPR08MB6751:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a9d7e45-6df8-4d93-799a-08dacec00a6a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bhu+6pxahRRmp7YhQTKMJXuk0i4Qd7zwTsS09iYufI7lnTwQy3ZPJsuERcNQaEILiScSkBd58CQAC6nkixEOgg7Bh/vJlKGviWG79ciOQwbFIPPHLpdtHQEkUs/U3xFTsLXJyEXlfg9A08J/sUrwkXHCJEdOviQxLzBbmVwQeRGwmj5t4aDPsUq8HdWa+HT0fdyc7b1DaLJzPVHB/o348wnjJxv5iUpIxBT4wMtXgyT6iEHqHhUq3HyGily6nqo+fDSkXI6o9RU0d00kUzOLzygufLKk8BgsUnfcNL+uEMzVaWuC5Kh19HIdLOGgUEwf2i4zNdJrLdBN4FKyp3d5/4Ly1Lr0NysJ5H5XvaSYUHZrJkFWdixIxMfHFyoxg2lGfXZKhKGSCCOA8lwaHSaibeydqVrmDoHSjGGtTlsVCnf+UbOOFbyzmyakBCByUTew5r6BU8bFGEZveWRyBx4RPMdznb2yKXQsBIo1Uw/upAN6BubqiCe0tSGQMPOqDEuYdt1lJCWYI726C56oun8Fqc+hlbsc35wFtxOLTcRqz1P0VoKIA35Q2Je16tHcpw/0okVa46nSbFAMUO9+NRMlXbL/fmL/Wk1GYrh0+5WhQqBG1e6kAX7Vm7MINriddZFFWDGNSJuzBDDmEm5IOKYHKrQOQI26v1XYMEFTHf7OrWH4yISXmQnSEJbsGYTdJWRLMbE6zPGJPwIYvITBeWHy2w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB4544.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(346002)(376002)(136003)(396003)(39840400004)(451199015)(478600001)(6486002)(186003)(44832011)(4744005)(7416002)(41300700001)(2616005)(1076003)(316002)(54906003)(38100700002)(38350700002)(36756003)(6506007)(6666004)(107886003)(52116002)(26005)(6512007)(86362001)(4326008)(66946007)(66556008)(8676002)(66476007)(5660300002)(8936002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sOgAZSXJNO3hV/W4yGDjgfMPrO7H9ax+xipPaFxiJ2Vj8d2KaZXduUVX19B+kl+xSmfegejRTw95ck/fPi3YYSGZAsSfpSgrlmNQE5ekTqcPTfdAEYLSjIMhgQoowoEufLYpEp9PxhuIqIhZ7NNF4/M+NoB36U4VZZ/jVLnzAx+JOzPe6O4DGfHPp6kOkNQj/PJeRsmOG4dLtJ65HNjcQ5+HqYpRpITUkzLU1BjEyIDk8IWe6TkXu7aQNH1+5gLN+86qXTGjybykWHdatM/z1K5/x1MzREFQ/C64nDgMz6yw++bIv9cddxYdT7AAMhV6kObkYusrRaDqgSqTsTGe47DLeukp21AfL6eqGzw8FKg67YdUCw+x55MbuRjKKazMXdK2Tv8+IlG0sXJ7WObAbnKXteWxsJTyvOoKrM6ZWZheINfwKYiuqu+8DisL8Lzu0mttaegoWNCCLLtfbWwlREcbF0Ntwzshc2F1SRl6mWSiDaPf4rCEzuWkL3sAYiHraJMrQRmMINpc60R6xfsskvu7W8BGkCZunaeONdy+DE3Ka0iOdpFYmWP/DyvPzOakRYZKWb/l49eJoo9WBUAZjnROnn3DvgWUTCm2KYunaffmiv1+q1JdwBAHVavdIDHHmsgYV5u27IE5BH25c2Ny19iPyOrlXBWp8uqPvZF4oSZTq5jhmqy4GNwjf5LL7hK4bae0EJm0SMxdBo/oBMnu8QxK197xKp+KMy6YRhpkMiWJZXoJCVZ30F0dfIuaqi1bQzo0+spdPi5FpKfMeKPv1pHMTheQNmULeCCW8qpbXXuvGnUsBNBCOQ1WzrwpGR1idr9VaNJ43esWDyhwz+v5ExK2uMIA7R5ciID2+Yo3Bmhiys0MSwl/LrHfuifIOdPV2rwLdvuM2B6X9UXAQOVLTMm/sN+rNp28G9wLHmC+ogi2qeC6PU8eF9leuG2gyP40CMk+4ngonAHTRGjFS4B192tLgD8hBLa67gwKS3fHXJXejWYUC28C+VG4tur3jCxbvCJ4TLhGS5YFtZgIA6YgZR8lRge/EaKdU2vVvK75pn1veL9QDQKxFe0ZTbzSMMMkpG1uqBi10M4MVyEBiSdhvkOTWHMytBrN8fQ2HxZK8o3WlXEtlDDpf0g8gz1jxYBvixi73guMC1M1z+pU+bLTMSlil8uIV+Jb8bqljyKDMKrARXSW3OAvE15qIxmmCs7f3l3FEUwuVufYExLaL73KNAqWCoWEcC4RlKjg/dKAmegmOxVu752PiHWa+DPao4FIBVsdUxxpWMKZ0RThLmmh4JKwA45+j4Ik7/22KQdvA9qxvkBQy+MORVaDsNDoFYLsrOLt+++0J4eZlEapf/XybER2GT2FnEsSu5VG11vhtzIfV8iQxS2gCnQmBwRguRLGsvxFvpzScIir99L9v/ALyMt2OMUCcp2HuXLddtlf4gPln+SzqYEE4lmCmOE4C6tjZ3jvIPR5r06PeU5RSRlcjfKixu/WsOSjaVSYzhkZQ04ze3gZAuJRmbEe3liP4Z0AiRi540xchZ3QixBs9c7PRrkZUUAW1qgk5Y+zox+nWsqtmhgTSvpbP+kSy0neC0ks5p1dNffAy+vvjNwiycqsdg== X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 7a9d7e45-6df8-4d93-799a-08dacec00a6a X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2022 08:35:43.1545 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e94ec9da-9183-471e-83b3-51baa8eb804f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dakzInhTz8qaX0SHT/a2clmAV0hqVgMAvndML8q9jSSP0ocKNroDPp86KxQNF4Zm2y66O48HX0pWgZ94LB5EP5pNblhYksf5HT3jFSXRefM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6751 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add structs for iio type arrays such as IIO_AVAIL_LIST which can be used instead of int arrays. Signed-off-by: Gerald Loacker Reviewed-by: Andy Shevchenko --- include/linux/iio/iio.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index f0ec8a5e5a7a..eaf6727445a6 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -383,6 +383,21 @@ s64 iio_get_time_ns(const struct iio_dev *indio_dev); struct iio_trigger; /* forward declaration */ +struct iio_val_int_plus_micro { + int val_int; + int val_micro; +}; + +struct iio_val_int_plus_nano { + int val_int; + int val_nano; +}; + +struct iio_val_int_plus_micro_db { + int val_int; + int val_micro_db; +}; + /** * struct iio_info - constant information about device * @event_attrs: event control attributes From patchwork Fri Nov 25 08:35:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 13055600 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 E7326C4167D for ; Fri, 25 Nov 2022 08:35:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbiKYIft (ORCPT ); Fri, 25 Nov 2022 03:35:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiKYIfs (ORCPT ); Fri, 25 Nov 2022 03:35:48 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70054.outbound.protection.outlook.com [40.107.7.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8676B2D77C; Fri, 25 Nov 2022 00:35:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UJV30xGDWtj5C5lAYoxG7xUxxSZOA/ot9FUCNiCeIxRjrKVNFYhKTImtyK+M7Ljw2ICrDFm+U/MRLTOXjVxL3vEIcF/l/EUVRWuXuuc0SFtXI36mlZd9PBIftHzHVTjw/qF6gxJAYsIKvEeQNmqUVVmDJmvHpbfIB01iJswi4iMEWzxcZ0v5xu8hUkEqr2CArZ1G0yEpXn3oaIrisB8UwEndr0anYTAVqBUC7HBTrYtZqMy3tQoepRxGi3aVCBWKBZhgbxi/MKRz/zHQq7CdWjPJ5q6FK8Z1z5DE1K0VQmhIXllKJZQq/SBXl5FAnT8tS/HtD4Y6F1bC0YZXeB8E2g== 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=LxxbkWH4Ok5gqDUM9+y8AQPJClOqYYBnY5ZEuEZRr7k=; b=fjw99r0j1g9NSg2lkXIKiJ3ywG0vfe5kWLYcQCRTv/lY4dEo7rzKSv7uj8maHm2OxmbQKIi/WNn3VLqmm5AZLvIk3rPcFSmjNV3RklcpsjEju8A/sMz11dUeG1d90PG8rZeseJ41Apwf13TYqFJ+kVBbxfbm80osO1ayM9K2FnuBZ4JyXqwq2g0xHnvcASm8uZwmrUI1Sw4kFe5TAUje9OPa1hq3FeGTNyYugjcpixVUCbMFjfzB4JUkBEc7lgoINiXI4HHxVa0XVS/vIjE6CRE3+tB6V3edlulhIKmKFVTc16MzMgY5VVws3UbReDQPs7o+wF00DJW4z9PcP68DlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wolfvision.net; dmarc=pass action=none header.from=wolfvision.net; dkim=pass header.d=wolfvision.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfvision.net; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LxxbkWH4Ok5gqDUM9+y8AQPJClOqYYBnY5ZEuEZRr7k=; b=0ACDM9LwCJhrX9z0x0Jl3+hkrZPf8+6K3PiKv0WDYGatYtsP2ihfL5ZG6U+ZSwx5aWcM3uaaUKbTf24ckLf4kEf/knzGElJ4YX94xF91H5erh+dKdsOdtNUvQVLI5XEpLJoG6SoQApABA/nsyMZ2edlYfgum+mGqW8LK4ilhHvs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) by PAXPR08MB6751.eurprd08.prod.outlook.com (2603:10a6:102:136::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.5; Fri, 25 Nov 2022 08:35:44 +0000 Received: from VI1PR08MB4544.eurprd08.prod.outlook.com ([fe80::bcc7:bc51:bf44:1454]) by VI1PR08MB4544.eurprd08.prod.outlook.com ([fe80::bcc7:bc51:bf44:1454%6]) with mapi id 15.20.5857.019; Fri, 25 Nov 2022 08:35:44 +0000 From: Gerald Loacker To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Jakob Hauser , Linus Walleij , Nikita Yushchenko , Michael Riesch , Gerald Loacker , Krzysztof Kozlowski Subject: [PATCH v3 2/3] dt-bindings: iio: magnetometer: add ti tmag5273 documentation file Date: Fri, 25 Nov 2022 09:35:25 +0100 Message-Id: <20221125083526.2422900-3-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221125083526.2422900-1-gerald.loacker@wolfvision.net> References: <20221125083526.2422900-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0501CA0011.eurprd05.prod.outlook.com (2603:10a6:800:92::21) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|PAXPR08MB6751:EE_ X-MS-Office365-Filtering-Correlation-Id: 8cbdecfa-1922-4a2f-f902-08dacec00b0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H+O084nUOvlBqQ2JAfCmXSqb+sSC7il8/zCRDJkMHBq4QjTJSp6rLHZGpjqftVm3GoPNwyJJXxLAl/1E+ol15Z6s619gp646Oq46RaC504KlwLF4G4aapUtLL1Uo0Y5PM7CWK/rldCoudBO9caCmorVkbSBjSzELt+C0zX5kEQ9aztpIoP8MLmRM93AHR9klvmwEQF9+vI2Cpw8O8Juh6kAB5OP8tps2M54Lv5A7/1ik9jpNGgCFUz/Le5gSM8TzF0yLSC+GYxirRa8DyrBf1UFaWM5OjVWaPgb22q+MyL+gvTaW61I3P6Cs94IOzJk0nDd4BpWbXp75bArN2UIMXd9vBuR0HLzsmE4Cye1nrJ25K7NwZL3Bpy/pkYG7kytaM7KCGVl8RuHzp+MW34K8r9Y7OIy3v/alSHU4NeORKWGYkKh3R8qAQi5y+73FswW5VHwao/AJ3q+z4YbLFyEQbhxGchO9T1C90R5GwX5J9hKedO0zwBUOdKwTJK3ZZMxbMv7gNgKf9zBISdf/LaoAvWzZcRduigHaHTyxIF82vUo7/NDnNKw6yY/3rx7+kMmh21Bwnyd38qhMjaGrVlO5vSru6gDR4LrOHaJuNxtFkvI0oGUCEt0dBHZCMoetwqyvDs4b4VcQ8yfxg9tXUZay8wjWzrwMdjaxPEzcdmM5n+MDhKhJ7CjIZc6EXDPoshLKQ9LwYbyT+8ppPYK4bYBZjYMSUEPX/HqTR8nuh0vU1g5/9XyytOL/77RmQXTyNyeT/PHOcOhtvP62w7e+7l112A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB4544.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(346002)(376002)(136003)(396003)(39840400004)(451199015)(966005)(478600001)(6486002)(186003)(44832011)(7416002)(41300700001)(2616005)(1076003)(316002)(54906003)(38100700002)(38350700002)(36756003)(6506007)(6666004)(52116002)(26005)(6512007)(86362001)(4326008)(66946007)(66556008)(8676002)(66476007)(5660300002)(8936002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?8wjh+4elxedX+SQ+rhXLSF2HR4V1?= =?utf-8?q?KjqMlDCFHxKtermVUhB++Ab6m2VB590fFmadt2PNtM8G9Jw0jVW22aIsOg//uUimy?= =?utf-8?q?qm4uyZYZ1YrDXNu+LLzWjBWzXF/seJnbf0AG6AXNM8gpZh+cNycw+/ZNTow31bRPL?= =?utf-8?q?eKz11usaJ20sMbrimUzxLHbxc46f6lJWQm30Cy7SIbKTNZ63V2kFgIZCl2zPVAnc8?= =?utf-8?q?LPt1LsTBUvxfa92kNU3vWaBwpVnvqUlWyvdPEPPleEDyQ7yCAFjOTuF3siU8ZfCC5?= =?utf-8?q?FdiR56Eaa1QIx6MGMIOFjirfjIFuaPIJ0wvv3yCH1MrAJ6YUeEU+FIo3yPOxB++9H?= =?utf-8?q?rDItlgC16bOKFr46a/eQBFaL+wanYLmI58jJlHPG16WyM/mW7FzhfMr5snX9tPyg5?= =?utf-8?q?DQ10+C4Ui5ehyTaY+3tOPMKTXCCLFpntmXWlUcwAVbPwrLYUjqj28S4z/dqmDAmDZ?= =?utf-8?q?9JZKxhkIbCzMPeY/Sh2DheiKROGrYJ6Shau/z9KwJQTqT7Fm2UWYIO3QCP4+9iVpf?= =?utf-8?q?7qlhO1Q0ln7aG/CmCoRSwLdSOgNJS5XbXt0yTk8ksoGNqg3jNJ12mF28PsdOTzKrk?= =?utf-8?q?xuNsdEhs4b08CLLaByXQdcGuOjCkVP00bgIuHlky2iPQepiC204beJPZyHRxIUnev?= =?utf-8?q?bYXLscwFjH4xzTeHUXD1xjY3RIAUWoLVlKKdplij1C6/BZRpeh+hElsgw7O8f3efL?= =?utf-8?q?ACLHjbdFzCvJOgOq0IXy+9mbEr7+qKqHn7i1fRenxrhpJyoqwAMpOCS5tEUorju1Y?= =?utf-8?q?jh0ziTn29HxysMA5YfWvCTUol+D3twIQth/NJKY9kFlgjM4GAwGNQrvpKIelOa6Sf?= =?utf-8?q?UcLLQ8c6pzXPv4UJ6Uj0Q/XFMhfnQg8x/f27KHi08C4sCgPf0ImVpGOSUsL18BsmU?= =?utf-8?q?Mue7zLQYpFQMQiHSz0qIbSctOThcR+SSrM9Yj741mCS94Jhr71vzoqAnZ6HEgsnmH?= =?utf-8?q?1IUakozowFrI0Eg0Hl/cFqYuRmWomXmxy9ZtSxO6FOL3MY88wvpULTqHc65Y6Pj/q?= =?utf-8?q?plR9mrS8q1QHkG/Yu3oywoqUTPNIsXgizsEizw6c6QYwSCO0VfrPQKLWAjDHUMrWO?= =?utf-8?q?rCpjTBFKevPuJyEKrYhze4QEURje21PXQv7Z9ySlsr6oGxkQPlulBSAo6kVGKgWVh?= =?utf-8?q?h4nasGlvFVPEZxrG71STNuAOwXozbdKDtBqTypZm1g9FGp6X4xf0JJZDTNZC6TzDV?= =?utf-8?q?VKfV7kiRWpgnkwxHPP57FyouOzv5gLq9ZgXtLqQPoBNWriB2WAXlHldbrX6S6Owgp?= =?utf-8?q?whmr1+7litmR8UI7TYwfkZ943ZYNKAhewkmb6vETdElam1WkcdZ1BZMnlKurWn6Nt?= =?utf-8?q?KzPe2Uiku1XtWeUMqyMicbKP6RXE9YkFQ3WyKy4EoBT7qEP62MwoFNebAfD5ExJWY?= =?utf-8?q?Gwp8m90IYaUAToqouWrNVBvI0u9kw9hWGXP08QVJlTofQEUy2hfHtIc723f9nGpOU?= =?utf-8?q?9ae9atKk++rKR3zV0zumKxy2OLxKQDD+bT8QAn5Q2d0Rw4xGvqX9oTqsiHKc26qdl?= =?utf-8?q?YJDNM8l4aD2COKXH1dCj+PYdCeIcOc765A=3D=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 8cbdecfa-1922-4a2f-f902-08dacec00b0e X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2022 08:35:44.2169 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e94ec9da-9183-471e-83b3-51baa8eb804f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EHdo4Iui7mYRdyB0ULvSMwHdiHyqP8WgUDX7e4pe1V9FoGEIhtOqsUo/d0+nD9O1Cv1KP4cY8j1Zz64JePUTiE5w9DUd60P1yzqCw7JB0Jg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6751 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add bindings for TI TMAG5273. Signed-off-by: Gerald Loacker Reviewed-by: Krzysztof Kozlowski --- Changes in v3: - dropped quotes from strings Changes in v2: - Removed nodename - Changed angle-enable to angle-measurement and used strings - Added interrupts - Removed vcc-supply from required properties - Changed i2c-0 to i2c in examples .../iio/magnetometer/ti,tmag5273.yaml | 75 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 81 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/magnetometer/ti,tmag5273.yaml diff --git a/Documentation/devicetree/bindings/iio/magnetometer/ti,tmag5273.yaml b/Documentation/devicetree/bindings/iio/magnetometer/ti,tmag5273.yaml new file mode 100644 index 000000000000..121d540b7b6e --- /dev/null +++ b/Documentation/devicetree/bindings/iio/magnetometer/ti,tmag5273.yaml @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/magnetometer/ti,tmag5273.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor + +maintainers: + - Gerald Loacker + +description: + The TI TMAG5273 is a low-power linear 3D Hall-effect sensor. This device + integrates three independent Hall-effect sensors in the X, Y, and Z axes. + The device has an integrated temperature sensor available. The TMAG5273 + can be configured through the I2C interface to enable any combination of + magnetic axes and temperature measurements. An integrated angle calculation + engine (CORDIC) provides full 360° angular position information for both + on-axis and off-axis angle measurement topologies. The angle calculation is + performed using two user-selected magnetic axes. + +properties: + compatible: + const: ti,tmag5273 + + reg: + maxItems: 1 + + "#io-channel-cells": + const: 1 + + ti,angle-measurement: + $ref: /schemas/types.yaml#/definitions/string + description: + Enables angle measurement in the selected plane. + If not specified, "x-y" will be anables as default. + enum: + - off + - x-y + - y-z + - x-z + + vcc-supply: + description: + A regulator providing 1.7 V to 3.6 V supply voltage on the VCC pin, + typically 3.3 V. + + interrupts: + description: + The low active interrupt can be configured to be fixed width or latched. + Interrupt events can be configured to be generated from magnetic + thresholds or when a conversion is completed. + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + magnetometer@35 { + compatible = "ti,tmag5273"; + reg = <0x35>; + #io-channel-cells = <1>; + ti,angle-measurement = "x-z"; + vcc-supply = <&vcc3v3>; + }; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index cf0f18502372..ea7acec52f8b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20613,6 +20613,12 @@ L: alsa-devel@alsa-project.org (moderated for non-subscribers) S: Odd Fixes F: sound/soc/codecs/tas571x* +TI TMAG5273 MAGNETOMETER DRIVER +M: Gerald Loacker +L: linux-iio@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/iio/magnetometer/ti,tmag5273.yaml + TI TRF7970A NFC DRIVER M: Mark Greer L: linux-wireless@vger.kernel.org From patchwork Fri Nov 25 08:35:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 13055601 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 D97FAC4321E for ; Fri, 25 Nov 2022 08:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbiKYIgC (ORCPT ); Fri, 25 Nov 2022 03:36:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbiKYIfv (ORCPT ); Fri, 25 Nov 2022 03:35:51 -0500 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2057.outbound.protection.outlook.com [40.107.249.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 594103135E; Fri, 25 Nov 2022 00:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=en31NTi2d+Qj9GURTne/eagwTXlJ+CINdyPzupcLdUAOZ9HnvazTNO57w2nrZRbenqlrzJXSfJqeho5I/Vez0f7u3kTrOXCs57++3lK8BGxwlsOi67RL2SoMKOl5PB5LKYALu3odF6Y28Z2NuMRxk8mVqU9EK8a5RPpqIkqJWmrbMwBDTwJE2WNzJcaWBycxdjIyHxTZOu4x91cnLKBCF9JqSmZ2JUuOH7qnaxIRi7UbHJ8JMTie7P6GQ3+6vCqWiK4/4mQ9ZR4PggBgGL82ZQoIJ5hriE4opiVUGbOaIUYI69vA546DqfjUxeYMEHJlBbchR1mU0DUjAIq9ilWyTw== 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=xatLQdxlA4455hSPCOqhvadd0Vf6mgFNHgzW25s4WJk=; b=KPLsWFTz8J3VpUejCkOdmvqTbgNNtCXw2j6FSFV7P+E4Iaq/cSeOdZ6DI0SoewyK5dD+uumQzkR/X6y7RRbpvPUpGRmG31J326G1z7OXrqsVIz4kOtoAtsrwi9m0xH7jQxnbA7XK30N1SiKbWm+MYVToFT2QnTdgvUwLaQsjIhQHudcFK9kfHmtAhnUYRVATF1fML6+OKBZTbRcsOWzfxDKhxe1NI2CMLRl73m+MiXfHbWo0lZ6pdneIkKPgptdAyfnnNaoRoxWB0MXCjfV3PNlCibDxbQ1Okaagv/ErIaAUBmYCTZyjq92Zm/Fayxix8WSONSa5XXFi+EUCNQDynQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wolfvision.net; dmarc=pass action=none header.from=wolfvision.net; dkim=pass header.d=wolfvision.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfvision.net; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xatLQdxlA4455hSPCOqhvadd0Vf6mgFNHgzW25s4WJk=; b=Sw+1MY0Hf1SHo9tOryWo9p779RNsCMgs005cfDPiUctTFSvh3QFKQQv0AxRLCdjThmEih6WRTQfuqB4SPXJkD3RsCJB/QpDYq9pt+YCW4eO/FO3aNF8kqgKxRx96mvMfzKo9A4T826vbQ9038bO4fcfKO6t9pRbBBt2jwJa3k7k= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) by AS8PR08MB9527.eurprd08.prod.outlook.com (2603:10a6:20b:61d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.19; Fri, 25 Nov 2022 08:35:45 +0000 Received: from VI1PR08MB4544.eurprd08.prod.outlook.com ([fe80::bcc7:bc51:bf44:1454]) by VI1PR08MB4544.eurprd08.prod.outlook.com ([fe80::bcc7:bc51:bf44:1454%6]) with mapi id 15.20.5857.019; Fri, 25 Nov 2022 08:35:45 +0000 From: Gerald Loacker To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Jakob Hauser , Linus Walleij , Nikita Yushchenko , Michael Riesch , Gerald Loacker Subject: [PATCH v3 3/3] iio: magnetometer: add ti tmag5273 driver Date: Fri, 25 Nov 2022 09:35:26 +0100 Message-Id: <20221125083526.2422900-4-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221125083526.2422900-1-gerald.loacker@wolfvision.net> References: <20221125083526.2422900-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0501CA0011.eurprd05.prod.outlook.com (2603:10a6:800:92::21) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|AS8PR08MB9527:EE_ X-MS-Office365-Filtering-Correlation-Id: ebad9b95-fee8-4669-b3cb-08dacec00bae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3z5HyOqrO7eQvRQG+C+cJ/kQX3Y2PS62fIaFo8g3r/hlV6Q/pQRykzGXW2m1af2chKjaDTVJfcqtqifmspkO3pL5UUi8rY65kXJ5F8LWw/6K03vHUoKn8S8yPyCOUjWcFhbRzbyuucWwN06cAz1F3YrhFfZ7YNWwUgmteDVqt7Htx6XvfvVBADUS3E9afCXtALowPvi+52mpzLUxLDAW/gFcPdY+xuho+qcsKimv6K/4qdpmsR5c95aBkkV8MqE2BS28Fzhbu0hrnX5GuDYMfsZX0WShrzfNP5VWeTrIW4toUhZ6rji0OE9hl9de2bbRcYLAtGReBPE+evkz/puY2TWewSMB0k2abO/m2fEWDG33zgFgkrL2AMEEceeiP/p2xzylvdnvvCEO2UWsvrSroHJ8gtQdM6wxe0kzkOpeJJlcZLuNbJYNtvVUjxIfr8dd+k6eNsoWuJfdir0twIV2/MtiurhnOZITTmSrA2jakfKtyPlEtrF1o1h6s+8paRHgprT6uzRau+kjELDkns20SywLkB7LQC4JZ3SW5odE/tqkXnfBXKoLxW/gibwFECz6HhKtxzHBUTVdLojR4t/r6g53AX90Bz6SBYImbwBEl9aRCIqEdgFtCrPdB9Tde3tH6O2dNlPivO8ihWCpuL1nBruNdreeM/WVqpdMyPNFcTpGkXdgM4qt+8kRkqOa3c8iVk38XlLDCfel7GuzMVc941ECpnEO4NNEHDRUC564jss= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB4544.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(376002)(396003)(136003)(39840400004)(346002)(451199015)(86362001)(5660300002)(7416002)(66476007)(8676002)(66946007)(66556008)(36756003)(4326008)(8936002)(30864003)(44832011)(54906003)(478600001)(83380400001)(6512007)(107886003)(52116002)(6506007)(26005)(2616005)(966005)(1076003)(6666004)(186003)(6486002)(316002)(38100700002)(38350700002)(2906002)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DOHgW0QDlp2wr8J3kTSnmkE8ersmGAtTmhf9SaLZNzymwxX54LaL0zKAgQMB/bNaeANBP2xTL51YDglFNoWc4FCUJsMBZrtYCIg+rJkM8oX7n3Eg2T1pAkIiv0h/G7Y7SljNz6QqTbI+iFTFKqtVKEV5hVhlBUoRriq0VIE6hi5NCqNiDK3QoZFA1izb3WV7EXx0oKNdE0W42QgL1o8ELWHW5t2WSWiqIFtxEjqC1FcjEW+oAhXTQlcGp8SCfB439aqi6kboIVWpaj3uCykx8WcmGpnC6ylXQW2zkGELS0jmmWoZOJmdKlYRCv7wLyB+Vb5//59tXRoz0IDuHKor59QzeEM4SYNHeNPHXrnU+XBisiDEazrnhIf9PO5n5fZB0wKJIWXgh2rbStL8HQiTXbVFPrralx93VnuyBQN9w6ytBDm0I0OqYOU8XWyA5s6Y3ZGEmRIujZJPdK3dgHKolnMSEOIinxvDFYF6WtU9dTPNh9Qr9lJjM2xEPOKZxlaa4PQKaaTRt+huK/Of6DxPubLll2vdjs1Y1vUN4DTxxKGnKwgVUxom7++CXpOL9XwTviWTcXTJ+rAz9omy1qr/58vC8hTG83xPc0SE2ddB6uI5DealMnXV/ss7GM1dm3bA+KtejaUrj263cmuNebfxutrfq2BomTAKLYATTJwbWuGRi1+2dfB4KdyCsDLN50glH2F44L5KDAftLpYpY28G7yobT80p7h91GpbM/rtI5qCTnLKSPvievadpD4gv+AHX/gHxlV54983tgkLLjGxhUBWxB09ODkaymosIgGEWWoUUtlAA43+u/cPFCbfEIyn/kdbxaZH49MFJ3NFGL48VOCCks/9Ku18AVyB5dz3pW0gPuACVlJmDW1iOpMMxa00X2MdaTKmdjKu2w3WUDvS35RBxuqgob9hGikjKtHkvcrX7UbBCCSyJdZ7Dms40nFEmLbKTPdgSFEgj1JmGE4NKOjp9fHS40PGt0Qz0YZzVgNz4CTOdQSzUiIPLyyxA0Ivjp+FzscvnFv2kbHaDrevMfPR/4UQX3IfYSyMnsfVtdIu19/1vJxtLqCur6wPvOKiRwZMQRFNki8hBkNaZUtKlC9VrSmWdxcCxyq38es+T1GK2kxWPEn2QSIvmK4iKMbbL1RYgkVIpn0RSCwryQ8PL2IDGlT8IHg/Ft6TFQSHFP/FJTMm427aGWWzTdWlXgh1XRR1sNOxuYpQDCwnIj8351zUubL+EA9mSHcJDCEB6rRjrw8+zi5PwscKjdUX/MX6WkLjXtm9eJuPnrrjRM00Sc42S5+yg513Q5aLF4Pu+WFnVm9yjdIrjtlMnzt7txJ3ThV8ab4YvpWey4x91fTGJcKb3TJZOOAclV0QQ+eUgW6zd442Q7emBWhqyiNCYtvBaxw98vaApUeF2ScrKLEx9KpwP+aDHPyWuIC7pX96Ngn6OFBTolqLitjnweSQcecwcbRQYKujpZcpTmECV/M4tIX+Ch/g66M1KjKzPOzC0262QRl9UwDdov2O1SQIK7abADuMyPfpFSQ5HrNxzqAZiJ/EZAkGjwPfhzaVFsxtQ1O3W/NsnpF9AupPuCpmVJutTUdnID4siMOq0fsCqTXRg2w== X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: ebad9b95-fee8-4669-b3cb-08dacec00bae X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2022 08:35:45.2794 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e94ec9da-9183-471e-83b3-51baa8eb804f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1U20oz09tdtYw0tcisUTNjypheZcFosRyzHscHpi/REHxo0UQD2uqR2/yHRwWVyV0nxnEP+7n0HM5QjHwtGnm4oP65uQXtW/llz8Ms3p5dk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9527 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor. Additionally to temperature and magnetic X, Y and Z-axes the angle and magnitude are reported. The sensor is operating in continuous measurement mode and changes to sleep mode if not used for 5 seconds. Datasheet: https://www.ti.com/lit/gpn/tmag5273 Signed-off-by: Gerald Loacker --- Changes in v3: - Added include | Reported-by: kernel test robot - Added include - Removed - Added missing "static const" for tmag5273_avg_table - Documented Device ID - Fixed index of tmag5273_scale definition - Clarify TMAG5273_MAG_CH_EN_X_Y_Z as an index - Removed unnecessary print - Introduced tmag5273_write_scale() and tmag5273_write_osr() helper functions - Use of match_string() - Format Changes in v2: - Implemented suggestions from review and cleaned up probe function. This results in changes all over the tmag5273.c code. MAINTAINERS | 1 + drivers/iio/magnetometer/Kconfig | 12 + drivers/iio/magnetometer/Makefile | 2 + drivers/iio/magnetometer/tmag5273.c | 736 ++++++++++++++++++++++++++++ 4 files changed, 751 insertions(+) create mode 100644 drivers/iio/magnetometer/tmag5273.c diff --git a/MAINTAINERS b/MAINTAINERS index ea7acec52f8b..9d20b5780051 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20618,6 +20618,7 @@ M: Gerald Loacker L: linux-iio@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/iio/magnetometer/ti,tmag5273.yaml +F: drivers/iio/magnetometer/tmag5273.c TI TRF7970A NFC DRIVER M: Mark Greer diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index b91fc5e6a26e..467819335588 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig @@ -208,6 +208,18 @@ config SENSORS_RM3100_SPI To compile this driver as a module, choose M here: the module will be called rm3100-spi. +config TI_TMAG5273 + tristate "TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor" + depends on I2C + select REGMAP_I2C + help + Say Y here to add support for the TI TMAG5273 Low-Power + Linear 3D Hall-Effect Sensor. + + This driver can also be compiled as a module. + To compile this driver as a module, choose M here: the module + will be called tmag5273. + config YAMAHA_YAS530 tristate "Yamaha YAS530 family of 3-Axis Magnetometers (I2C)" depends on I2C diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile index b9f45b7fafc3..b1c784ea71c8 100644 --- a/drivers/iio/magnetometer/Makefile +++ b/drivers/iio/magnetometer/Makefile @@ -29,4 +29,6 @@ obj-$(CONFIG_SENSORS_RM3100) += rm3100-core.o obj-$(CONFIG_SENSORS_RM3100_I2C) += rm3100-i2c.o obj-$(CONFIG_SENSORS_RM3100_SPI) += rm3100-spi.o +obj-$(CONFIG_TI_TMAG5273) += tmag5273.o + obj-$(CONFIG_YAMAHA_YAS530) += yamaha-yas530.o diff --git a/drivers/iio/magnetometer/tmag5273.c b/drivers/iio/magnetometer/tmag5273.c new file mode 100644 index 000000000000..d61a99fea9fe --- /dev/null +++ b/drivers/iio/magnetometer/tmag5273.c @@ -0,0 +1,736 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for the TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor + * + * Copyright (C) 2022 WolfVision GmbH + * + * Author: Gerald Loacker + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define TMAG5273_DEVICE_CONFIG_1 0x00 +#define TMAG5273_DEVICE_CONFIG_2 0x01 +#define TMAG5273_SENSOR_CONFIG_1 0x02 +#define TMAG5273_SENSOR_CONFIG_2 0x03 +#define TMAG5273_X_THR_CONFIG 0x04 +#define TMAG5273_Y_THR_CONFIG 0x05 +#define TMAG5273_Z_THR_CONFIG 0x06 +#define TMAG5273_T_CONFIG 0x07 +#define TMAG5273_INT_CONFIG_1 0x08 +#define TMAG5273_MAG_GAIN_CONFIG 0x09 +#define TMAG5273_MAG_OFFSET_CONFIG_1 0x0A +#define TMAG5273_MAG_OFFSET_CONFIG_2 0x0B +#define TMAG5273_I2C_ADDRESS 0x0C +#define TMAG5273_DEVICE_ID 0x0D +#define TMAG5273_MANUFACTURER_ID_LSB 0x0E +#define TMAG5273_MANUFACTURER_ID_MSB 0x0F +#define TMAG5273_T_MSB_RESULT 0x10 +#define TMAG5273_T_LSB_RESULT 0x11 +#define TMAG5273_X_MSB_RESULT 0x12 +#define TMAG5273_X_LSB_RESULT 0x13 +#define TMAG5273_Y_MSB_RESULT 0x14 +#define TMAG5273_Y_LSB_RESULT 0x15 +#define TMAG5273_Z_MSB_RESULT 0x16 +#define TMAG5273_Z_LSB_RESULT 0x17 +#define TMAG5273_CONV_STATUS 0x18 +#define TMAG5273_ANGLE_RESULT_MSB 0x19 +#define TMAG5273_ANGLE_RESULT_LSB 0x1A +#define TMAG5273_MAGNITUDE_RESULT 0x1B +#define TMAG5273_DEVICE_STATUS 0x1C + +#define TMAG5273_AUTOSLEEP_DELAY_MS 5000 +#define TMAG5273_MAX_AVERAGE 32 + +/* + * bits in the TMAG5273_MANUFACTURER_ID_LSB / MSB register + * 16-bit unique manufacturer ID 0x49 / 0x54 = "TI" + */ +#define TMAG5273_MANUFACTURER_ID 0x5449 + +/* bits in the TMAG5273_DEVICE_CONFIG_1 register */ +#define TMAG5273_AVG_MODE_MASK GENMASK(4, 2) +#define TMAG5273_AVG_1_MODE FIELD_PREP(TMAG5273_AVG_MODE_MASK, 0) +#define TMAG5273_AVG_2_MODE FIELD_PREP(TMAG5273_AVG_MODE_MASK, 1) +#define TMAG5273_AVG_4_MODE FIELD_PREP(TMAG5273_AVG_MODE_MASK, 2) +#define TMAG5273_AVG_8_MODE FIELD_PREP(TMAG5273_AVG_MODE_MASK, 3) +#define TMAG5273_AVG_16_MODE FIELD_PREP(TMAG5273_AVG_MODE_MASK, 4) +#define TMAG5273_AVG_32_MODE FIELD_PREP(TMAG5273_AVG_MODE_MASK, 5) + +/* bits in the TMAG5273_DEVICE_CONFIG_2 register */ +#define TMAG5273_OP_MODE_MASK GENMASK(1, 0) +#define TMAG5273_OP_MODE_STANDBY FIELD_PREP(TMAG5273_OP_MODE_MASK, 0) +#define TMAG5273_OP_MODE_SLEEP FIELD_PREP(TMAG5273_OP_MODE_MASK, 1) +#define TMAG5273_OP_MODE_CONT FIELD_PREP(TMAG5273_OP_MODE_MASK, 2) +#define TMAG5273_OP_MODE_WAKEUP FIELD_PREP(TMAG5273_OP_MODE_MASK, 3) + +/* bits in the TMAG5273_SENSOR_CONFIG_1 register */ +#define TMAG5273_MAG_CH_EN_MASK GENMASK(7, 4) +#define TMAG5273_MAG_CH_EN_X_Y_Z 7 + +/* bits in the TMAG5273_SENSOR_CONFIG_2 register */ +#define TMAG5273_Z_RANGE_MASK BIT(0) +#define TMAG5273_X_Y_RANGE_MASK BIT(1) +#define TMAG5273_ANGLE_EN_MASK GENMASK(3, 2) +#define TMAG5273_ANGLE_EN_OFF 0 +#define TMAG5273_ANGLE_EN_X_Y 1 +#define TMAG5273_ANGLE_EN_Y_Z 2 +#define TMAG5273_ANGLE_EN_X_Z 3 + +/* bits in the TMAG5273_T_CONFIG register */ +#define TMAG5273_T_CH_EN BIT(0) + +/* bits in the TMAG5273_DEVICE_ID register */ +#define TMAG5273_VERSION_MASK GENMASK(1, 0) + +/* bits in the TMAG5273_CONV_STATUS register */ +#define TMAG5273_CONV_STATUS_COMPLETE BIT(0) + +enum tmag5273_channels { + TEMPERATURE = 0, + AXIS_X, + AXIS_Y, + AXIS_Z, + ANGLE, + MAGNITUDE, +}; + +enum tmag5273_scale_index { + MAGN_RANGE_LOW = 0, + MAGN_RANGE_HIGH, + MAGN_RANGE_NUM +}; + +/* state container for the TMAG5273 driver */ +struct tmag5273_data { + struct device *dev; + unsigned int devid; + unsigned int version; + char name[16]; + unsigned int conv_avg; + unsigned int scale; + enum tmag5273_scale_index scale_index; + unsigned int angle_measurement; + struct regmap *map; + struct regulator *vcc; + + /* + * Locks the sensor for exclusive use during a measurement (which + * involves several register transactions so the regmap lock is not + * enough) so that measurements get serialized in a + * first-come-first-serve manner. + */ + struct mutex lock; +}; + +static const char *const tmag5273_angle_names[] = { "off", "x-y", "y-z", "x-z" }; + +/* + * Averaging enables additional sampling of the sensor data to reduce the noise + * effect, but also increases conversion time. + */ +static const unsigned int tmag5273_avg_table[] = { + 1, 2, 4, 8, 16, 32, +}; + +/* + * Magnetic resolution in Gauss for different TMAG5273 versions. + * Scale[Gauss] = Range[mT] * 1000 / 2^15 * 10, (1 mT = 10 Gauss) + * Only version 1 and 2 are valid, version 0 and 3 are reserved. + */ +static const struct iio_val_int_plus_micro tmag5273_scale[][MAGN_RANGE_NUM] = { + { { 0, 0 }, { 0, 0 } }, + { { 0, 12200 }, { 0, 24400 } }, + { { 0, 40600 }, { 0, 81200 } }, + { { 0, 0 }, { 0, 0 } }, +}; + +static int tmag5273_get_measure(struct tmag5273_data *data, s16 *t, s16 *x, + s16 *y, s16 *z, u16 *angle, u16 *magnitude) +{ + unsigned int status, val; + __be16 reg_data[4]; + int ret; + + mutex_lock(&data->lock); + + /* + * Max. conversion time is 2425 us in 32x averaging mode for all three + * channels. Since we are in continuous measurement mode, a measurement + * may already be there, so poll for completed measurement with + * timeout. + */ + ret = regmap_read_poll_timeout(data->map, TMAG5273_CONV_STATUS, status, + status & TMAG5273_CONV_STATUS_COMPLETE, + 100, 10000); + if (ret) { + dev_err_probe(data->dev, ret, + "timeout waiting for measurement\n"); + goto out_unlock; + } + + ret = regmap_bulk_read(data->map, TMAG5273_T_MSB_RESULT, reg_data, + sizeof(reg_data)); + if (ret) + goto out_unlock; + *t = be16_to_cpu(reg_data[0]); + *x = be16_to_cpu(reg_data[1]); + *y = be16_to_cpu(reg_data[2]); + *z = be16_to_cpu(reg_data[3]); + + ret = regmap_bulk_read(data->map, TMAG5273_ANGLE_RESULT_MSB, + ®_data[0], sizeof(reg_data[0])); + if (ret) + goto out_unlock; + /* + * angle has 9 bits integer value and 4 bits fractional part + * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 + * 0 0 0 a a a a a a a a a f f f f + */ + *angle = be16_to_cpu(reg_data[0]); + + ret = regmap_read(data->map, TMAG5273_MAGNITUDE_RESULT, &val); + if (ret < 0) + goto out_unlock; + *magnitude = val; + +out_unlock: + mutex_unlock(&data->lock); + return ret; +} + +static int tmag5273_write_osr(struct tmag5273_data *data, int val) +{ + int i; + + if (val == data->conv_avg) + return 0; + + for (i = 0; i < ARRAY_SIZE(tmag5273_avg_table); i++) { + if (tmag5273_avg_table[i] == val) + break; + } + if (i == ARRAY_SIZE(tmag5273_avg_table)) + return -EINVAL; + data->conv_avg = val; + + return regmap_update_bits(data->map, TMAG5273_DEVICE_CONFIG_1, + TMAG5273_AVG_MODE_MASK, + FIELD_PREP(TMAG5273_AVG_MODE_MASK, i)); +} + +static int tmag5273_write_scale(struct tmag5273_data *data, int scale_micro) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(tmag5273_scale[0]); i++) { + if (tmag5273_scale[data->version][i].val_micro == scale_micro) + break; + } + if (i == ARRAY_SIZE(tmag5273_scale[0])) + return -EINVAL; + data->scale_index = i; + + return regmap_update_bits(data->map, + TMAG5273_SENSOR_CONFIG_2, + TMAG5273_Z_RANGE_MASK | TMAG5273_X_Y_RANGE_MASK, + data->scale_index == MAGN_RANGE_LOW ? 0 : + TMAG5273_Z_RANGE_MASK | + TMAG5273_X_Y_RANGE_MASK); +} + +static int tmag5273_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct tmag5273_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *vals = tmag5273_avg_table; + *type = IIO_VAL_INT; + *length = ARRAY_SIZE(tmag5273_avg_table); + return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_MAGN: + *type = IIO_VAL_INT_PLUS_MICRO; + *vals = (int *)tmag5273_scale[data->version]; + *length = ARRAY_SIZE(tmag5273_scale[data->version]) * + MAGN_RANGE_NUM; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +static int tmag5273_read_raw(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, int *val, + int *val2, long mask) +{ + struct tmag5273_data *data = iio_priv(indio_dev); + s16 t, x, y, z; + u16 angle, magnitude; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + case IIO_CHAN_INFO_RAW: + ret = pm_runtime_resume_and_get(data->dev); + if (ret < 0) + return ret; + + ret = tmag5273_get_measure(data, &t, &x, &y, &z, &angle, &magnitude); + if (ret) + return ret; + + pm_runtime_mark_last_busy(data->dev); + pm_runtime_put_autosuspend(data->dev); + + switch (chan->address) { + case TEMPERATURE: + *val = t; + return IIO_VAL_INT; + case AXIS_X: + *val = x; + return IIO_VAL_INT; + case AXIS_Y: + *val = y; + return IIO_VAL_INT; + case AXIS_Z: + *val = z; + return IIO_VAL_INT; + case ANGLE: + *val = angle; + return IIO_VAL_INT; + case MAGNITUDE: + *val = magnitude; + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_TEMP: + /* + * Convert device specific value to millicelsius. + * Resolution from the sensor is 60.1 LSB/celsius and + * the reference value at 25 celsius is 17508 LSBs. + */ + *val = 10000; + *val2 = 601; + return IIO_VAL_FRACTIONAL; + case IIO_MAGN: + /* Magnetic resolution in uT */ + *val = 0; + *val2 = tmag5273_scale[data->version] + [data->scale_index].val_micro; + return IIO_VAL_INT_PLUS_MICRO; + case IIO_ANGL: + /* + * Angle is in degrees and has four fractional bits, + * therefore use 1/16 * pi/180 to convert to radiants. + */ + *val = 1000; + *val2 = 916732; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OFFSET: + switch (chan->type) { + case IIO_TEMP: + *val = -266314; + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *val = data->conv_avg; + return IIO_VAL_INT; + + default: + return -EINVAL; + } +} + +static int tmag5273_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long mask) +{ + struct tmag5273_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + return tmag5273_write_osr(data, val); + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_MAGN: + if (val != 0) + return -EINVAL; + return tmag5273_write_scale(data, val2); + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +#define TMAG5273_AXIS_CHANNEL(axis, index) \ + { \ + .type = IIO_MAGN, \ + .modified = 1, \ + .channel2 = IIO_MOD_##axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_shared_by_all_available = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .address = index, \ + .scan_index = index, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ + } + +static const struct iio_chan_spec tmag5273_channels[] = { + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET), + .address = TEMPERATURE, + .scan_index = TEMPERATURE, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_CPU, + }, + }, + TMAG5273_AXIS_CHANNEL(X, AXIS_X), + TMAG5273_AXIS_CHANNEL(Y, AXIS_Y), + TMAG5273_AXIS_CHANNEL(Z, AXIS_Z), + { + .type = IIO_ANGL, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), + .info_mask_shared_by_all = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .address = ANGLE, + .scan_index = ANGLE, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_CPU, + }, + }, + { + .type = IIO_DISTANCE, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_all = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_shared_by_all_available = + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .address = MAGNITUDE, + .scan_index = MAGNITUDE, + .scan_type = { + .sign = 'u', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_CPU, + }, + }, + IIO_CHAN_SOFT_TIMESTAMP(6), +}; + +static const struct iio_info tmag5273_info = { + .read_avail = &tmag5273_read_avail, + .read_raw = &tmag5273_read_raw, + .write_raw = &tmag5273_write_raw, +}; + +static bool tmag5273_volatile_reg(struct device *dev, unsigned int reg) +{ + return reg >= TMAG5273_T_MSB_RESULT && reg <= TMAG5273_MAGNITUDE_RESULT; +} + +static const struct regmap_config tmag5273_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0xff, + .volatile_reg = tmag5273_volatile_reg, +}; + +static int tmag5273_set_operating_mode(struct tmag5273_data *data, + unsigned int val) +{ + return regmap_write(data->map, TMAG5273_DEVICE_CONFIG_2, val); +} + +static void tmag5273_read_device_property(struct tmag5273_data *data) +{ + const char *str; + int ret; + + data->angle_measurement = TMAG5273_ANGLE_EN_X_Y; + + if (!device_property_read_string(data->dev, "ti,angle-measurement", &str)) { + ret = match_string(tmag5273_angle_names, + ARRAY_SIZE(tmag5273_angle_names), str); + if (ret < 0) + dev_warn(data->dev, + "unexpected read angle-measurement property: %s\n", str); + else + data->angle_measurement = ret; + } +} + +static int tmag5273_chip_init(struct tmag5273_data *data) +{ + int ret; + + ret = regmap_write(data->map, TMAG5273_DEVICE_CONFIG_1, + TMAG5273_AVG_32_MODE); + if (ret) + return ret; + data->conv_avg = 32; + + ret = regmap_write(data->map, TMAG5273_DEVICE_CONFIG_2, + TMAG5273_OP_MODE_CONT); + if (ret) + return ret; + + ret = regmap_write(data->map, TMAG5273_SENSOR_CONFIG_1, + FIELD_PREP(TMAG5273_MAG_CH_EN_MASK, + TMAG5273_MAG_CH_EN_X_Y_Z)); + if (ret) + return ret; + + ret = regmap_write(data->map, TMAG5273_SENSOR_CONFIG_2, + FIELD_PREP(TMAG5273_ANGLE_EN_MASK, + data->angle_measurement)); + if (ret) + return ret; + data->scale_index = MAGN_RANGE_LOW; + + return regmap_write(data->map, TMAG5273_T_CONFIG, TMAG5273_T_CH_EN); +} + +static int tmag5273_wake_up_and_check_device_id(struct tmag5273_data *data) +{ + __le16 devid; + int val, ret; + + /* + * If we come from sleep with power already activated, the + * first I2C command wakes up the chip but will fail. + * Time to go to stand-by mode from sleep mode is 50us + * typically. During this time no I2C access is possible. + */ + regmap_read(data->map, TMAG5273_DEVICE_ID, &val); + usleep_range(80, 200); + ret = regmap_read(data->map, TMAG5273_DEVICE_ID, &val); + if (ret) + return dev_err_probe(data->dev, ret, + "failed to power on device\n"); + data->version = FIELD_PREP(TMAG5273_VERSION_MASK, val); + + ret = regmap_bulk_read(data->map, TMAG5273_MANUFACTURER_ID_LSB, &devid, + sizeof(devid)); + if (ret) + return dev_err_probe(data->dev, ret, + "failed to read device ID\n"); + data->devid = le16_to_cpu(devid); + + switch (data->devid) { + case TMAG5273_MANUFACTURER_ID: + snprintf(data->name, sizeof(data->name), "tmag5273x%1u", + data->version); + if (data->version < 1 || data->version > 2) + dev_warn(data->dev, "Unsupported device %s\n", + data->name); + break; + default: + dev_warn(data->dev, "Unknown device ID 0x%x\n", data->devid); + break; + } + + return 0; +} + +static void tmag5273_power_down(void *data) +{ + tmag5273_set_operating_mode(data, TMAG5273_OP_MODE_SLEEP); +} + +static int tmag5273_probe(struct i2c_client *i2c) +{ + struct device *dev = &i2c->dev; + struct tmag5273_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return dev_err_probe(dev, -ENOMEM, + "IIO device allocation failed\n"); + + data = iio_priv(indio_dev); + data->dev = dev; + i2c_set_clientdata(i2c, indio_dev); + + data->map = devm_regmap_init_i2c(i2c, &tmag5273_regmap_config); + if (IS_ERR(data->map)) + return dev_err_probe(dev, PTR_ERR(data->map), + "failed to allocate register map\n"); + + mutex_init(&data->lock); + + ret = devm_regulator_get_enable(dev, "vcc"); + if (ret) + return dev_err_probe(dev, ret, "failed to enable regulator\n"); + + ret = tmag5273_wake_up_and_check_device_id(data); + if (ret) + return ret; + + ret = tmag5273_set_operating_mode(data, TMAG5273_OP_MODE_CONT); + if (ret) + return dev_err_probe(dev, ret, "failed to power on device\n"); + + /* + * Register powerdown deferred callback which suspends the chip + * after module unloaded. + * + * TMAG5273 should be in SUSPEND mode in the two cases: + * 1) When driver is loaded, but we do not have any data or + * configuration requests to it (we are solving it using + * autosuspend feature). + * 2) When driver is unloaded and device is not used (devm action is + * used in this case). + */ + ret = devm_add_action_or_reset(dev, tmag5273_power_down, data); + if (ret) + return dev_err_probe(dev, ret, + "failed to add powerdown action\n"); + + ret = pm_runtime_set_active(dev); + if (ret < 0) + return ret; + + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + + pm_runtime_get_noresume(dev); + pm_runtime_set_autosuspend_delay(dev, TMAG5273_AUTOSLEEP_DELAY_MS); + pm_runtime_use_autosuspend(dev); + + tmag5273_read_device_property(data); + + ret = tmag5273_chip_init(data); + if (ret) + return dev_err_probe(dev, ret, "failed to init device\n"); + + indio_dev->info = &tmag5273_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = data->name; + indio_dev->channels = tmag5273_channels; + indio_dev->num_channels = ARRAY_SIZE(tmag5273_channels); + + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + ret = devm_iio_device_register(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "device register failed\n"); + + return 0; +} + +static int tmag5273_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct tmag5273_data *data = iio_priv(indio_dev); + int ret; + + ret = tmag5273_set_operating_mode(data, TMAG5273_OP_MODE_SLEEP); + if (ret) + dev_err(dev, "failed to power off device (%pe)\n", + ERR_PTR(ret)); + + return ret; +} + +static int tmag5273_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct tmag5273_data *data = iio_priv(indio_dev); + int ret; + + /* + * Time to go to stand-by mode from sleep mode is 50us + * typically. During this time no I2C access is possible. + */ + tmag5273_set_operating_mode(data, TMAG5273_OP_MODE_CONT); + usleep_range(80, 200); + ret = tmag5273_set_operating_mode(data, TMAG5273_OP_MODE_CONT); + if (ret) + dev_err(dev, "failed to power on device (%pe)\n", ERR_PTR(ret)); + + return ret; +} + +static DEFINE_RUNTIME_DEV_PM_OPS(tmag5273_pm_ops, tmag5273_runtime_suspend, + tmag5273_runtime_resume, NULL); + +static const struct i2c_device_id tmag5273_id[] = { + { "tmag5273" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(i2c, tmag5273_id); + +static const struct of_device_id tmag5273_of_match[] = { + { .compatible = "ti,tmag5273" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, tmag5273_of_match); + +static struct i2c_driver tmag5273_driver = { + .driver = { + .name = "tmag5273", + .of_match_table = tmag5273_of_match, + .pm = pm_ptr(&tmag5273_pm_ops), + }, + .probe_new = tmag5273_probe, + .id_table = tmag5273_id, +}; +module_i2c_driver(tmag5273_driver); + +MODULE_DESCRIPTION("TI TMAG5273 Low-Power Linear 3D Hall-Effect Sensor driver"); +MODULE_AUTHOR("Gerald Loacker "); +MODULE_LICENSE("GPL");