From patchwork Wed Nov 30 14:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 13060000 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 041DCC4708A for ; Wed, 30 Nov 2022 14:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229720AbiK3OyS (ORCPT ); Wed, 30 Nov 2022 09:54:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbiK3OyR (ORCPT ); Wed, 30 Nov 2022 09:54:17 -0500 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2076.outbound.protection.outlook.com [40.107.21.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 522332AC60; Wed, 30 Nov 2022 06:54:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQv4pCh4Q0m1K2sLHHRMdDvRu00gaOxphMp4tZ3mhXFn6wfkPs3UEppB8ciaXVRSAvQS67vKA9g4Pta1oXKVlaT0fzHbnMRe8n6w8a4galaLuJxoUfJQ042zj9I55qW4URyrD99+UPRrEmDoE4/xiJFgZDf/iFeK212Gv10zCYEWkhJX+tcspfxlXY3XD+npJj2LBEE+cp6E0t+E770AIHNxJNfUf9WaxAS0qdiDHWjOfCI8kqkfeMjyIID01PEHNk/cxBHEnm6D4Loe9tr2864Q3/VJXNWCVOa2TXkAE2j1aXvW3YWALOs+vknuj+hfqwUcgOMgswa9XJzKz3TloA== 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=6KGfj0a4nDe53WaQ65o+byEaBR3heOWkJau4frimBEo=; b=iw78QA9eU2zlHOu1jLo2CHm0HdZ0FB8r/X8IlsuaK0zwTmGpiej4tQBX+BnNjg55IpspQu2xVhQjdSKjVRiOrRg846QdcHfBmpOpbnW4wCscnpmuL/egca7Rr8jbDR3CyQHElFJ5gpVEmHspf/pKOFRa+MgsbrnpBXdd4uhn9SlTeGJxbTjpC/MnoPpm1ojTLkXSenE7j5Et4uzjHPop/HKQL5/AsQ7Hx6b/qAaxjf6X5adOMIiqXQZ/W7wMkqQ0NEmnY+14piuTlKHB/A6ry48B2hZC043OyCVU8+wZa/aGp+AmbOT5E1DXktbKVOd1LIZfx3o0t4nZbc8oU0Is4w== 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=6KGfj0a4nDe53WaQ65o+byEaBR3heOWkJau4frimBEo=; b=iPyZXysfYuXK35UXIGcsjsMt3DTbDff6GGIVMU0KAtQEhPdy/qJpp7X0K2W6KwQgp3wGlOu4zIr+psJwbgJ5q2GaHPMhjhhLMGnVUBGiwoMefYPIomPap2UPvihEELr/qPOyeaG2Ebxnh3hKjqIv/5ejfbTzTyimhsYH5sfSwgM= 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 DBBPR08MB5977.eurprd08.prod.outlook.com (2603:10a6:10:209::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Wed, 30 Nov 2022 14:54:13 +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.5880.008; Wed, 30 Nov 2022 14:54:13 +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 v5 1/3] iio: add struct declaration for iio types Date: Wed, 30 Nov 2022 15:53:54 +0100 Message-Id: <20221130145356.1129901-2-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221130145356.1129901-1-gerald.loacker@wolfvision.net> References: <20221130145356.1129901-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0102CA0084.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::25) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|DBBPR08MB5977:EE_ X-MS-Office365-Filtering-Correlation-Id: 37d13749-aa9d-4a39-4cc1-08dad2e2beb9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tY9HgM4JCPOR1N0nXWt1WR+XJ+PA4tZzXQvhve+S1FqGf7mTSINE3B6hxaDRRuB5b25bRHudw0HgCufNihtTj5A+i9usJ2kbXFmHshj/PkCSpqeKdm2Tf5RXm5ADgnA8TE2lXFXqnH8z2zzeY+Ikthrmr6hz/g3RiBFbOmfW3SY50r4Hmin48VRLRsupll08bz04ByE3BGrjmsJWsELAapVzH/L3uNSNAn6DYPiPjyemJ8BU2IZaxmyYa2Niq0rWTy5CBIbIFR4zYgeDsn0IheifNq8QaWLD3i36zFj3+5UNwoY7nbHCIiaSH9MPmG7TR+HzFlhrXIPsGd7L6jEYxAGVnipWhq1EIfyWPDHxiqC8Si1X9bt/T+gEVmxqTZtJFScCLuPwuYDnrEDHxPbQaPnS0ZPwjw495ZFUrCefZu3452grrNjmduQXl5DZNyDr1Y3sI8feV0kqnNEqJh8FlxKJn5ykKxTTpVJEJ+zYkMMVn95WqKBkq+vT7/I9r6mr8yra26OPH5h2cDtrq/t4g7g9xrlYEvf61u71AeaQbfq3mY4RcRaPQkvjwQWrX61RA+a52cBCNGxm+/bgqRc8VSRvNUajlSlubnYtGciHGN6g+nlfacgZPHejHDXKpDTN84SPX1FQOd16X7PlwsTN+L60IRlYctstNIE2coiAyBiB6o6C22PgRJ9EoMzb9vFO 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)(39840400004)(346002)(136003)(396003)(376002)(366004)(451199015)(52116002)(478600001)(66556008)(36756003)(6486002)(26005)(38100700002)(38350700002)(6666004)(6506007)(66476007)(41300700001)(8676002)(66946007)(86362001)(4326008)(316002)(44832011)(4744005)(54906003)(7416002)(5660300002)(8936002)(6512007)(2616005)(186003)(1076003)(107886003)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gez6u7kgTqk4Vy8cAJ36oieZNWiyqFHw2LLKNmsg/RS73nXkzlGVUrGSRMnmFNc2QViwv14SrxzCVeYsoDIJSxjHMx5h1yaSzV/NsMk3OLHROnA8hja1b9wPDQ+Y9cnYnEG55sTBfUCT0U1JJTsmTElrz+dQFQsE8kO6Cm2yh2FVxF9GuLxC6aLQBW3TdntOPIvoHj5xj4j7kgVoKhJGdOk+hOdRfEH3oYWZXSdlxzeDF78jlGG+49vvOv/iYKoQX8Sc4Sjkp54sxyLhjpGDplJuOUylaPBhIJ4/xBt+YaXgqsIK9tH3dyvUesWiGqJM/nOgq/PGqbwWXuZIxC0qV/hNgoPvAGdAdmuWwltKvIZgqjGlQPONPT6NeJsCqaIK9FFzGxbxWUeAtzylBKU5ON/xfZ/pBAxQ8HghkA5GB1uCDiFj4Ht9P4fOZ+LLgp1ikfKKE/Pcwvyt0xcTNOrTzDHeD6RETU1wpfucBWn4fRKo4bmdHOJvsoeejGdc4FB6qUB0tKxKpDHXSyTHeLVNQbWPThKgb9QU/sJ3UT3Y+rI3HF9Dm3eXQ9IZu9n91/1bkhzhgxbz5aAYYl5TdC/gEIoei8gJATHzgVL6Bqp/Li9e/bUblrNfaD+nUsbc+jys5iUQ/WvKrHmRlsF5PtcWPNAa5bIdjxs9QI6K/tBiSdwPvrlMwaQ3sy0+YYBkJRFNN/8b9NAjO5LET4gmAdsbNSbEnPIZ8QWzjz4raHskDds709bEqMGy39DKZVg8eTGiGjRfuJ72i0XOgE3Ff3LD7L0jolO8dBxlWImPRB7aXGwomuLeyHqka61r9qp6FTnlPNA9WYs8Tl+OUgoQ4FToU+NmxunqJAIhWqQ0AYn9cdilP/8TpDIw8A4DLyt9afLgnJOOOqzbFQ9lHaRV41SwVBJIepmo14Q3T0NKb0YojQn2OOr3ihqBAYx1W96UjgfJPzoeIpFivLswrp76QbImjDB1CN4TQPQasJsQevL5K9m8/ocxWMmB55MAGeR6O4sOOKiKjYYtrHqYEUG/YJNIOWMKPFoT6nFjfiWaFPhbOmnS9UGi7ys9LuK3qedGMN1/igRD8cRRLUP33NpxAOCWTgo+MkWQxHCu0s9VjvKc0N1Yr3wZ01NW/lPy8IEMq9BfBb2lhQnb9B7yQt3WGPq9yBMy/a9PqWvXECqRX5jHhE31wnAqjNl6muhCknhQbIjcS8s7+3bYe4LUMbxVgMdPUk1gXA5I2ieqauMC/ko/XSxyDL43FGBxIchgiGOYLUqXMXM7UWDCbT7gZkoBpUOFKGlzv+KgWzPSMwz4jHPrnrW/YhJg2vLxmh+hksnlpEGkXoZekLMjS/cbScqd2ZXzs0ggKwcP+xwO8SWhWUBcPySt15SiX6r+vUHqBbksRgibzFke4oJE/N9LVTMO5MSj8+lDLTtZ6mmmPPO82AIeql1GuM3ZLV5RXg/+bros5BDz72RBuI9xW1HsxGjb35MbX0LX/cW39pwHZnrSvK/JRrz+i2t9Fr4spEyfwYHBf7b+bwVseIYiGSyJyE2taCKANDpDyLf7++smdg+F0LUGYRcInFdDv4km8rjiGlS3hJiFempFPmcYknhT3YraHLw8tQ== X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 37d13749-aa9d-4a39-4cc1-08dad2e2beb9 X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2022 14:54:13.3884 (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: hM0nUcQpI7z/Tl/h7Lwmw6tCWfLX5ngCx9I51CRP5q9+6yCIpWNJwbWUsH6zYu3mRpJt1BwubkT2HlMDD2BTdE57OShaG7oDvtBSQ4Kk2E4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5977 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add struct 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 --- Changes in v5: - no changes Changes in v4: - Add only struct for IIO_VAL_INT_PLUS_MICRO iio type. include/linux/iio/iio.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index f0ec8a5e5a7a..e5101bef50c5 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -381,6 +381,11 @@ s64 iio_get_time_ns(const struct iio_dev *indio_dev); #define INDIO_MAX_RAW_ELEMENTS 4 +struct iio_val_int_plus_micro { + int integer; + int micro; +}; + struct iio_trigger; /* forward declaration */ /** From patchwork Wed Nov 30 14:53:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 13060001 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 06337C352A1 for ; Wed, 30 Nov 2022 14:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbiK3OyT (ORCPT ); Wed, 30 Nov 2022 09:54:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbiK3OyS (ORCPT ); Wed, 30 Nov 2022 09:54:18 -0500 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2076.outbound.protection.outlook.com [40.107.21.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D3B7209B5; Wed, 30 Nov 2022 06:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZWnV1h/+HPlL6K8jSUdt2BZvhcHO+BIZyGGyw7of4eymO6QZYAXLc8rmKsxvlSY9rx2tHyh3pFdfWwN6HCtmXUnvrDP/gYRo9TV6OrZzUaMcQYXXK4UdcllznySqlxvZX2nmaDeQNlPZU5N4gsD05TT0Dc8ZEp8XW/OoZl/wWgzjG0UCqPVXynzANgDAAnms6GLYoIes2TbiBC/tI7xacyESGXW4ohMpNb0ZRp1u1KJeXXb1B3EYleI//fwpXmFCmmRaUkzkj8XAFpNbgA6Gsol6gcOzY0Bnmof1fiLuuakyL15+A07BjkLAVvnge6A+ThGGt+6i13HkeaWS4fJ1Ow== 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=EgJFone7l8oqZfqhQiTfHhuxlAO7drpTi8/2adeKPDA=; b=mnM62A1SaBrLvYxy2N5KC3AzqWyd2lCC17b+BLyhC/NXqQturHNpoKJB2sd9YeRoDouF1eps0u6XgvzM6zsereDa5BwrpSSykxnGoXv9ZcMioIB1mQgbbN9FBHfoDiXIEf1hRf+L2tOofZUUR1tq0OlFjpBMVsRHAdwcKe6BNo1KtNhAUHoJTi94MGJaX35Qf+7Bt8zIM2zgaFsI3tAVO7lsBOV4nsDMMEc2MUZAHqn8kKF2HUD9RlF68bTG8UeSeK466VaMhh/4j5rqL8fG30G+jvg5OZLdpPTKlE5GLJwkCERCpGeqEqxsCsBVEaNzdmK3njrDxHDiAZsBhKA6rw== 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=EgJFone7l8oqZfqhQiTfHhuxlAO7drpTi8/2adeKPDA=; b=2Dq+6nl/k5xJ6IlVIyFkDS/8eMLqWl9yUWtAG0y2TJsA6mGi7Y6KQM3kdY2kjCihPKjC6R5dKPIpzTdxyWKnjlqMSkZZPkEClRQCMEIxekColc8CoHKu3BgJMzM7y+DRfDVqaMvQVY+rQdxOzS7hPl51D9rgAC1TDuSjkRPBsQY= 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 DBBPR08MB5977.eurprd08.prod.outlook.com (2603:10a6:10:209::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Wed, 30 Nov 2022 14:54:14 +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.5880.008; Wed, 30 Nov 2022 14:54:14 +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 v5 2/3] dt-bindings: iio: magnetometer: add ti tmag5273 documentation file Date: Wed, 30 Nov 2022 15:53:55 +0100 Message-Id: <20221130145356.1129901-3-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221130145356.1129901-1-gerald.loacker@wolfvision.net> References: <20221130145356.1129901-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0102CA0084.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::25) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|DBBPR08MB5977:EE_ X-MS-Office365-Filtering-Correlation-Id: fe167261-f51d-428f-90d6-08dad2e2bf62 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0eMo8f0RJ2lZ/v0gSxOheu+dkmhmTIsjRcQdWipvIFYM6EzQH2sjZDYiL/GXtVgnI2cEr6hEADVEabi1L4sK+fuIOdST3hMGGdW0WLEkpwqOWO/j1NIHFQmL7OKconXgSDbd32i/9fkT5G7NMjZGOe/MPWqxLnigFaad/rXqa33Llb4ZjoBncdh5xITSU++VbixSft6y6ZtTj0qlV9dcE1lK0RWCB3tYKZ1h9UZYBsXb/JJn7ncQVV46Lgq79HugbyQPy4g2KdxQ4C0RJYL6SriBYBTJP9jg2YoACT5937himSLL96dDVjPQ35DENQ03ayCLF1GTbxSJdKG7r/ZsDlA4i7VYWhCIIkQcIEAbrJ1jzSsyRVvKGIML/iMQB0rrbcOIjD4b2XqfpMfhHSCbj6SwaXoJjo9NjD2hyt1KNs8/VL3In9ASkP+139shT1k8elvo2ISHhl44atdll+1biPjtEguHoA5/nXFEKrMYm5PlDkGWLUDMa2ZykwqcMpNOFcB0SY3rOR/wrBrePuGugppETDlvu8IjBLzw/IMjX/SSWmD4mXiCxLSHy69cgYWOUcNFGiNRYpgBN6Y5iRtIx6WhSnkaiZBqN3ock6ZBpyZVe8BZmvjJ94Ai2E6Eylg88GrpOcQzcaEvjswcAXDJnsqrLII5QPNExICuCX5PzXUWbW4mVbhHP535Cxhmkr4s9aIju4yY1bdUjfGOX1oKmG11Q33Fq+ZbF7TSrNkzjnx1z3d5P3vHrX2MWoxvSCkB 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)(39840400004)(346002)(136003)(396003)(376002)(366004)(451199015)(52116002)(478600001)(66556008)(36756003)(6486002)(26005)(38100700002)(38350700002)(6666004)(6506007)(66476007)(41300700001)(8676002)(66946007)(86362001)(4326008)(316002)(44832011)(54906003)(7416002)(5660300002)(8936002)(6512007)(2616005)(966005)(186003)(1076003)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Tam5OtU6jeqeFOWmwyqmhVIUqFdJ?= =?utf-8?q?NNhOm7+Tl7LvV5CGrZzn/5xsa0R94KpPs/Y70SoSf6dsz/6i5gqhVRZS47ZgliK6a?= =?utf-8?q?h2VwSNiSjbuvs6kECp4UFL1qRmoEkZQ3mMJseoeKjBk9kcTP34D90NOjJg4IzpzZQ?= =?utf-8?q?4tL59kQEq+fYDTYkTAJetq9QMBjqufEvBGnsraFhJFfkTQL/0nxS/bi3NJ/734ra0?= =?utf-8?q?fX49E89N9043bzpq1rv/kXdy/rOCZRnjqiualBQQ4eMFV7XB1kioMDn9bcvUv5vPF?= =?utf-8?q?n5YLwQJTvRpWULWt+psKFzKucQxY8QGG5vgP/qEVN6zd75Foj4Lhjp++lEKKfNlmx?= =?utf-8?q?xuoRuyL2gxNNaQPmchbMatSDt/FTiBnLzuONZWMSgpJqPN/cX7SEGljt0GQr3GRde?= =?utf-8?q?0MVLd1d17Sfzh5zTzqxts0BWuEr9EI5HkhfPq2QLwnLf57EHSPXPtcD30scunGC9I?= =?utf-8?q?hVOwyj2O+ZwWCmvd6NZrA6Ko74JE6VBX3wtujkTfAnHOsZAZ0aU2/A8X7TgXajYS2?= =?utf-8?q?glZZ9Pmalw0eKRiDlAMTd59oQERcS74G1D4TfYp1/djJAwX2em3GJuRDrL3j8J012?= =?utf-8?q?LgTanikk/OncMwR51UFAN6yQ9lij662wpcOhsEh2I+rsajRfq43yD2Q4oKHQC79T7?= =?utf-8?q?V3viJOZ+mzwKkAyO6S+G0qHskpi9jAtkASE/ZC8PCWomze632iqSL2SlKSMK1SNgJ?= =?utf-8?q?Dg8uhsBaqnl3hmXq0ELygcJwdeCERid9IJN1KlWjtKIAWctGOqfdUfrbznN3KIfzi?= =?utf-8?q?a6ypr88k7v/+d61gufLwmWTFVaTtU5nagDpqNPHDY5Cafsv8vUfKzqc6en2TjF9Qp?= =?utf-8?q?xQOkwkaDdEDivr251Euc02k3eavsxONq5tk4ZkC0cBGsBMpY3oK6hbxnKkWrEtepU?= =?utf-8?q?R0Teie2mTG2GdrOGTdUZgq1U/uauP+mwcMVirHD+5wvfb54Q5u0js3VGGcRBedKd4?= =?utf-8?q?ApPgYhbSnxkqJ3P70ovRA6fON+JE8vuboRwj49C9Jh7urbULrGvaiGucmXZsEP0Rj?= =?utf-8?q?XdwKge9MwPYgTgORzBnh7lN2Tz+DvRmLHyT+ma67zy7EJDbLO0pfo4T+9a4vZxjSs?= =?utf-8?q?CN+z/9//5hemrU5BdjnP4FDzZNdIZC6afIOtEY1BK5ocRAN2mweaU3cfJmjI7l3ie?= =?utf-8?q?yRVBaEL4ZQFD2VH9a88E1Ud2Ms4qXmLvz2zUkEVqDzRBoDtPuAR5gE4jyM8F190h4?= =?utf-8?q?LZjiUOCg6llYp4KdgEJ82sKXNxHcRP8tEGQbao7IeOaALwga/I427xLGv5owfJBUA?= =?utf-8?q?j9GcRoq3hekg9k07kx/ut+uWLGZF12/yAQ7Xolf7pAhWsgN3DDjVYKVRz9rIQY/R7?= =?utf-8?q?LcHSLVgqp/67aKXbDaDgSJZGs+B1CNJjScTjJ3bbu2C5j5aflZkIbx/kBemCHgmgo?= =?utf-8?q?GpC+xvWYkDDlhS6sywg5803Mdfk5q7IgBvgJqKoHx4+nwVwGc0lp9frQIfU1OtI9P?= =?utf-8?q?TiR7BAjaqjRk5Bnua4Ay/rPk29NUpDZD//KJYLfxmBpluV5Eq4Wh+OKg3itSh0td1?= =?utf-8?q?raBDbvUSGMeBOk76Ndzz4gA96aRb/3qtfw=3D=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: fe167261-f51d-428f-90d6-08dad2e2bf62 X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2022 14:54:14.2789 (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: k2IcgH9aByAKfbf1EcmcjLuFZRAq00mZzQaLecPi/SG7DRKBP5whPk3BDUVR1frttrmVAhBQn7gzL+U4qvTo3DObXPJ9lgIuk+RcMNZDrTU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5977 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 v5: - no changes Changes in v4: - no changes 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 Wed Nov 30 14:53:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 13060002 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 C6F6CC4332F for ; Wed, 30 Nov 2022 14:54:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbiK3OyZ (ORCPT ); Wed, 30 Nov 2022 09:54:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbiK3OyU (ORCPT ); Wed, 30 Nov 2022 09:54:20 -0500 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2076.outbound.protection.outlook.com [40.107.21.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC4830562; Wed, 30 Nov 2022 06:54:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G1UQCTnpfh3M0qHuwdXr7KV3EYRqVFs5XWEA3gLwqoRLUXfhNb8p1/QWW+l+hEKsFrqnC+Yo5LOxITIEOeRpcoRTlbQ0sPt8ZNIWL+vfcJje0cwF8vOYzRQ54eF2q+srQpHbQPiCyQE9yy+4J5FmJEthAgfAUQoqmI+KH/gqjDzdlIku1Y0oRyZpu+TT0HxhYBpQZH8o+BOEMqPT/1m42UEq+AmhdGnSCdL+s6RTkYDRy50UxIf44x3m60pgJ/IjzcU99mANWnlyUK4ghWXCLbTyxfiF6URLUlbBxA24UdHbHy2Q1PeqbnO2fMnrhPQ3dcCwa3HLKuy5iGZIRMfk+g== 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=kYJBL61NeW9NugbAjHaTgl9zvmtDgQXLX+kSVqGhLVY=; b=A8dwErGcsH9acgKqHssSjN9CrCM8QwyghGdv+h1m7uQ48uYM1QsbGLPJLSVbfT+VqlKiOJysxPohBdJhZcdppfljm2xW56Yznw0s7Mflh4FlMYaqLJgwBJ/RQi72IwsSL1fUQTFh+u+8xMcVYVov41FuZwgwtlcRT00fGdLPtX2vDIyGZyCKhyCQhqCxImVFREU4RkZulCABTfyOpdzD1kaWC9gJRhiqQrM7TSzvOWxxN99P6fNjaK88gTvUaPp0JfOSE8eJBhP8E6vYjCBdpBVNMykZ/7rxZ3x5TZvJPtk8pEkQD/I0jCqyneuSkQstpSdSSF7T9YcIdCAke1DbRg== 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=kYJBL61NeW9NugbAjHaTgl9zvmtDgQXLX+kSVqGhLVY=; b=If9cIeY7LDuz2nBv5FcnFpL8t8Xo1KILiESYbJvd/mk0hcD7HbWSOTqUo7B6sTF9VCMic84rZ1YjG5uev5Xd6d9GOdU1sl0GvTwD4POju/iNs+TtORYoIQCtfL/CvM40v98Z4orVuYgzWjjnI2GHILK/TGCYcRk/EmQhYQUBWVM= 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 DBBPR08MB5977.eurprd08.prod.outlook.com (2603:10a6:10:209::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Wed, 30 Nov 2022 14:54:15 +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.5880.008; Wed, 30 Nov 2022 14:54:15 +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 v5 3/3] iio: magnetometer: add ti tmag5273 driver Date: Wed, 30 Nov 2022 15:53:56 +0100 Message-Id: <20221130145356.1129901-4-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221130145356.1129901-1-gerald.loacker@wolfvision.net> References: <20221130145356.1129901-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0102CA0084.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::25) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|DBBPR08MB5977:EE_ X-MS-Office365-Filtering-Correlation-Id: b7bfa1cf-8be2-4db1-86f9-08dad2e2bffd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rXP3sqlY0ODqHLlJ5hxw4TVHg1vYWMffXM0Djtce42Sb2NLbhjMKqquggl5ld27VucAlSMm47dTJBqnLvPiULCq/2gmXYNhr9Yp+tcZrssw1oWKH+EtrF53VnF9M8lADFmF3/doDH2wTmKeeLAB1nhw/Y3MIIhWd9EBM2z3JPsX8fJMW32gtL5gT5/8MiHKoiuQmdSuI/dSDTqmvixVGEy8AoGceMxijztTK1wsazLe3P+sKjo8YX3zIyEKjJ5g3blJU/wP5xndk62P2Tqjo4GodVayn2MacApDvlwQQp++hiRQmNsUho2gGHx6lSlb2hhejgwSwbqxLdvTpmv/GNs/SU9JEbhlLppvTJmsxNpP8bJ3S+pVnB0MAWxC0TKefVOzYcIgxSUc2oJ7qKKXAPIkMqQtalWI/TR5kuGfhYQX7QWhcRfU563eIHE3fFWkzW9/CH/A/oREufRKsOS/El6CF3LrrLO4slxYn62a5U3RtyT4CCqu252WVrhfL8bmiUGaE2qyj8B1icGNhfOt3fEKVG0eZ2F2i6/BI+rfI3bzaqSMXcYV/fEod7CYBxgXKIJt6rq87DjNrMLlrb+YClddCVxSh87SE1R3Ro+tllLE/KPICUQePtGsfyNm/KIbBXns0Jh9M3axhN1JhAD9KFKp4KxhrKZQ0L0/z5tniX8JO84dpiFnzQK9FBOZ3+iLgHaQuQvd5zgvqivJlofqhfHV/ZvLoLjbcs5hox7KNBBE= 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)(39840400004)(346002)(136003)(396003)(376002)(366004)(451199015)(52116002)(478600001)(66556008)(36756003)(6486002)(26005)(38100700002)(38350700002)(6666004)(6506007)(66476007)(41300700001)(8676002)(66946007)(86362001)(4326008)(316002)(44832011)(54906003)(30864003)(7416002)(5660300002)(8936002)(6512007)(2616005)(966005)(186003)(1076003)(107886003)(83380400001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hlcGegswF9jNzfNeoW5fNBpsKmKzUE+vmJnVMTjBoeAl8AJmX9DJY78SYNY8uapzd+hkAKMjOJ3RfWE5cDSIo9nS4KlI2x/1nXi9HlG+8xlSWrbJ/1Pqme80FoBM/xQSSOkC+5v9ZPUx6cU7dNJOPqTxuBVX7UqgVjPgWcb3UW5MzYsx3CFvSvjiFPOyD2fN60CSSy3eMsG4yOJhoqflyYt810Y0bvNaO6Yu7LEvtyzl8/cH0kxUFYXRlaO8EbkXupeyqGemm/WANyttffGbg/L5QYsyxGWH7J8lsbldITAVMYmAzgkuleI4xfeqbmXq6iq28AXsGAT7n/vwS117yUfukZNeA8acbgXXgcGjhQkv3f/6II1A7urxHbGJ40YaZblkCBo2Gpwx8xdOzSknX+ru25ZOZOv1P3J4QXa0VSwtZ8jy0EYBjA68j5Gwd/ANn//65ciLm/muwLjKEP0Sb/7TOdlPzlOLRii1Y2Vm+m5jvFHdKYUKHTJvQtq74LgSMYiI48Le2C/GaGVGQDp4LH0ydR1JmhI7HteEiqhEaFIOiScMoZXel2qdUCL7OYn8o+UESyQ3IdI2H4+Zc3DRJGt/G07/MIue5WP7XBZkK2Hvbx3w35Rij/ao/4P03D5jhNL+RKhv81da90JlUSeyYKrcPxu7FMa8mTWQNxb2DedLHhEao8AryCLCVIHdn1YHzUuIGH+4JDBxBtxhkqD2HIXq+NUWZzcwPH+o7pI7oQDLZFSH3Ut6XODt9OMd/FJteCQCSZKxPY359+PAgiGumbAWM8BPaIoWnXaCvvyaNenwn2btITDeUjHzuPJbrPbPCHB7qTDtsw0sA3Ojw16NJfFehvjzqurm5Vsnud6NIr1hMSE5EWGEbkebjXd3JFM5JGojG5dWzek43WW+YwLojx1/zrbinKFZt+TQDJM2/jNJLdKcc/enZug2jU4q9BIpfMcRZsDIZlLytzLQ/L1Kg1oer58MNNSh3aQqjtZJOnDEbCxhSlSxsoAPPlpj5SlVID0aeg+19BZYyuFQGIT82KjQD20F/bsM8oIbWlTJUevMZZ1owGz9uruTcp+u9CjfKJmfVLnSZmozTAB0HLMbB4fqKKt/v4gU5ZYZ66lLrstUBR/Qo0dusAWpZBcSmJCAWIu8i7R/wRlXik8slNXPZNgbEUfXI3qflPP+a3WkC0+CkvZgp7eWDY5FslKlydownrlqIItqHDJovdZ9tE96q4GnxA81QC/Sz4CFaQHFLpF9DobmC4PKckgE4ygM7VGJimf6rAw+uP53O9n/822ePGL+/WZzkLlQ27eOI8Klou61wKPDIUvosccqJ7B4mBzPo3xQYkmDnOmwyL0YpKOq+rr0WRZY+RDqr5k47+8m8VVDs9MtvoBHpJ5zCa22ZGjek5v6JgNqj5OmqLjNT0HUQPDENcxboiYAqKbHUqbzVyijtZu2WGyCj9/ZEW3gW8aMxJHE6jcG5JVacInozpj6+xOcPMIh0g84Lh2NenPCE9DVa/S6d6eRi8LpvMjlW+RiuHaHiPHfRAfVkoIjV4uiQnp3KBR7USZkcbJKQ3D2IuuB/8//b4IX6GYJTluJbQ1+QmUspq1XRLJVrJhhHE8MLA== X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: b7bfa1cf-8be2-4db1-86f9-08dad2e2bffd X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2022 14:54:15.3414 (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: 5T8LTfpQVBhtNKHQeqhI18rcSoSkTs4fV2OMPqln+w1zgd3ePDBq51cQRXsh7MplJvnJ6vWPPMqUlMqC3W9TEXer6+9LNFpzizcfuWW9y/Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5977 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 Reviewed-by: Andy Shevchenko --- Changes in v5: - Fixed dev_err_probe - Removed unnecessary '&' for function pointers - Removed warning for device tree reading failure as Linux should not validate device tree. - Added comment for device name - Added tmag5273_wake_up() and improved comments - Reformatted pm_ops Changes in v4: - Renamed struct iio_val_int_plus_micro members - Simplified tmag5273_write_scale() - Removed unnecessary != 0 - Fixed regmap max_register - Simplified tmag5273_read_device_property() - Fixed some line breaks 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 | 738 ++++++++++++++++++++++++++++ 4 files changed, 753 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..8c1038618948 --- /dev/null +++ b/drivers/iio/magnetometer/tmag5273.c @@ -0,0 +1,738 @@ +// 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(data->dev, "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) +{ + u32 value; + int i; + + for (i = 0; i < ARRAY_SIZE(tmag5273_scale[0]); i++) { + if (tmag5273_scale[data->version][i].micro == scale_micro) + break; + } + if (i == ARRAY_SIZE(tmag5273_scale[0])) + return -EINVAL; + data->scale_index = i; + + if (data->scale_index == MAGN_RANGE_LOW) + value = 0; + else + value = TMAG5273_Z_RANGE_MASK | TMAG5273_X_Y_RANGE_MASK; + + return regmap_update_bits(data->map, TMAG5273_SENSOR_CONFIG_2, + TMAG5273_Z_RANGE_MASK | TMAG5273_X_Y_RANGE_MASK, value); +} + +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].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) + 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 = TMAG5273_DEVICE_STATUS, + .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) +{ + struct device *dev = data->dev; + const char *str; + int ret; + + data->angle_measurement = TMAG5273_ANGLE_EN_X_Y; + + ret = device_property_read_string(dev, "ti,angle-measurement", &str); + if (ret) + return; + + ret = match_string(tmag5273_angle_names, + ARRAY_SIZE(tmag5273_angle_names), str); + if (ret >= 0) + data->angle_measurement = ret; +} + +static void tmag5273_wake_up(struct tmag5273_data *data) +{ + int val; + + /* Wake up the chip by sending a dummy I2C command */ + regmap_read(data->map, TMAG5273_DEVICE_ID, &val); + /* + * Time to go to stand-by mode from sleep mode is 50us + * typically, during this time no I2C access is possible. + */ + usleep_range(80, 200); +} + +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_check_device_id(struct tmag5273_data *data) +{ + __le16 devid; + int val, ret; + + 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: + /* + * The device name matches the orderable part number. 'x' stands + * for A, B, C or D devices, which have different I2C addresses. + * Versions 1 or 2 (0 and 3 is reserved) stands for different + * magnetic strengths. + */ + 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); + return 0; + default: + dev_warn(data->dev, "Unknown device ID 0x%x\n", data->devid); + 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 -ENOMEM; + + 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"); + + tmag5273_wake_up(data); + + ret = tmag5273_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; + + tmag5273_wake_up(data); + + 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");