From patchwork Thu Dec 1 07:22:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 28216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp121697wrr; Wed, 30 Nov 2022 23:25:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5i139djlsGi91sGoMrRNpDwE6bdGhiDxDEflYFMk30ZZf7CLxlcxnQbSIfZnWdmoFRPurn X-Received: by 2002:a63:2361:0:b0:45f:f8df:108e with SMTP id u33-20020a632361000000b0045ff8df108emr38751592pgm.127.1669879514825; Wed, 30 Nov 2022 23:25:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669879514; cv=pass; d=google.com; s=arc-20160816; b=rcUgOOkwwqDSvGjmH36wJzkto4yUgWojt9GSsxphZvwUncg35p88gVp6fENH/QJJm2 HGUGPkL0HN+Na2uw3ahS0/5E4GFgtZxK2oUCv3QvAqehlbOlDldnY1RBH4v1mxxnk3KY PUF2NRLg9mkjHGgNm+5+Ee271alftOl4Wvwh8Bx1PnPG1qOuE2oQfro0V4hb/TgcSS/g 1opZLjKXwcLnwc4jOe0qHWtX7lIFljZZBq794ZYJFmub5+N8TpE9oIBmc07s7h1pNLlP ilN/O/vFOc8ER+GfIK4mR5QQ2tVng9pbSpd1IV/dR2LvoEuJc2iWlyOzqOHlkNpJPiMU KtAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NUqCJ82HPMnH6PSzidX/H0fdpuIVytwNRhSCJflFk+Y=; b=nmv7dpky+E5KkhQhd2sfSBiZvU+prKaBXs/yo+SZavZKIfLRK2A/GHBJTJteey8Luy EJb1w/JdPI4tgkf+FN3rJ2D5RQzzUvREb2vPvTlSDa8dBLcjJh64/WUcCFa8A1YbbyrQ ONPgm471MRjglFV5Sr2jYbJdPu9qRQYq27Atv76kijVibK/U4j2jdUk8uxA4mO7755XE HJxRl8L7E9cRc2dHz5x14LC+1pr8Oapsw6tzQVbcgsEAepn9ddEzl6yVmcSxNpyIOE0n 4hb1cW+eRUUbnB4o6fvVcFy0/RyDLoqxMtos4fPN7YzigHO2iopxY2sBWH8b1sQJzgPl 1+xg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=ihtCSpg+; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u64-20020a638543000000b00476c3ac7347si3671048pgd.443.2022.11.30.23.25.01; Wed, 30 Nov 2022 23:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=ihtCSpg+; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbiLAHXM (ORCPT + 99 others); Thu, 1 Dec 2022 02:23:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbiLAHXI (ORCPT ); Thu, 1 Dec 2022 02:23:08 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2073.outbound.protection.outlook.com [40.107.22.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC4982FFE9; Wed, 30 Nov 2022 23:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TyPR8xtI4BCL1DwN0TJLf7Qsgw6l3fiUW9Aigd6CBlVH2x0WoQQvCI1jUkF9M2O0BmQEDnbzJC7T0qy+u89Z5H+W/WumEE+sQU3oJG4yHN1/IWTH1kOVThyfkdjVdg2pY/aIBxJlsNx890ckcmyxc0ObkAjosc337ccQ84ZSPL2i4FXVmPB8t4gV8dBwRDsVtf/jnfw3OdA8VqYzXRS0yhg3LqNRUgH9PsnGx6DJJBVhqXmxw2d39Actogu4tHw8K42fOsezRxeFK7SrlWapNL3/8WAHN/VCsf7O3Wl9qGrHhGOH1nv5nXjxtN4xn878S0zZ9Js7gYc0FD/ZSu9KCw== 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=NUqCJ82HPMnH6PSzidX/H0fdpuIVytwNRhSCJflFk+Y=; b=iykMr2Iv32Q8mc4HC1VLlzTrr67HteUfZHI73az457pBPF6biOMGTj2m2VfJdtOklb7tw+mTSfdzw6MJJ/GR2kMarzTkdLako67FeY+POFSjDfYZIDMKcgRbnbL3lzZU3Kpo/DlkSB9id0LXI35xLnnGel93i7JsT4eKyNXZvRa9QuVM88SIAk1fPAT4jIdKeTPzXGPf5uZh7kP/HaVWkYhNe3HOrLfVkmT9FrsgyKcDwozVp18f/mDPDAI0u2xtDLlR6ZYUJhUdptskx6O54MQka8Trwn953cbly0sl4LgpQBqKSQ1LU7qBGVh/rHW4H20YpDVWspIjlTTP/aS6kA== 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=NUqCJ82HPMnH6PSzidX/H0fdpuIVytwNRhSCJflFk+Y=; b=ihtCSpg+YGcM+5eiWch33dKwlN+WrJBeM3sSC9IKJtIxbss8hGlFnDhtQ5ePX/cwJDMnziUf+HoHxrqOplTyvZUN+bLU3Lh9EKn3uijJwysQkE0721ztg9q1J/AfaZxLMaAEdOLnPSe9BtHiIY5voD3qxWFgEjNB6iUE/NpC6eI= 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 AS8PR08MB6023.eurprd08.prod.outlook.com (2603:10a6:20b:291::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Thu, 1 Dec 2022 07:23:05 +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; Thu, 1 Dec 2022 07:23:05 +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 v6 1/3] iio: add struct declaration for iio types Date: Thu, 1 Dec 2022 08:22:18 +0100 Message-Id: <20221201072220.402585-2-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221201072220.402585-1-gerald.loacker@wolfvision.net> References: <20221201072220.402585-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0501CA0024.eurprd05.prod.outlook.com (2603:10a6:800:92::34) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|AS8PR08MB6023:EE_ X-MS-Office365-Filtering-Correlation-Id: 4de252a6-bd8e-4da2-9f90-08dad36ce348 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b//2EXsq+M9HrwHnek3v9rVHYuWthPYNRASf+kZ92G1PypPlO+4n8zJaKrb1UUbD//kaUSyDW7kup2OShb2NKhY8P+FsjWsWisRwZRgR7+wiuZA/UuGS9iWf74V7w9Z1tUfOi4AW5KgCZWZpjBi2rDOPOQlznH8gBXqzKPyfdOaJG3flWCQWsz8BMqXkTJl/xX1/f5SqfVVtDbHkVA/g9qauEQKa/dHLx4CYrUTJeyM2lvqaPLoTOl5n2/qcI2SOipDGqqgdgJLavc3n4gQf0b4WCKf4E3iLZs2SdGNz6YA2nyVFIgzc2xKMbTtn7QKInzfXOjfyzfRMeQ0cutp5B/vFUAUA059nvfgxVvpCzxwkTkosnucXlnibk7Y2AHb8Hev0ODo8XwdeQqeOwrJktLhjnmJ9LYnqFO6tlF3gil5ix1e4FR9q9yO4Y64lmnMPX3uZ67zGN8tVhOMq9tqfHCwQW2RZOuq0WT/fD668QISmm0sIepJsWz9DsIKDZlXyoJ+Naft/L3XU1YFuzPgHpybjoSxYFff+uVHXjk4JhQQa/7zFzQFomSPxxsF02fwBcFiStCTCWAqbGFPI0PKDawYef9EHFTGCajcYcVh13qFF7CUYgGllnEpq4N+kVnTnX7riV92b5pneq7HpW8IJ2Kd6NSZ5qXuC+4dDYEYfzbnczDpoXMr/353ImLpxSDYE 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)(346002)(136003)(39850400004)(451199015)(8936002)(5660300002)(186003)(36756003)(66476007)(41300700001)(4326008)(66556008)(54906003)(316002)(8676002)(38100700002)(107886003)(86362001)(6486002)(6512007)(2616005)(66946007)(26005)(478600001)(7416002)(52116002)(1076003)(6666004)(38350700002)(6506007)(2906002)(44832011)(4744005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IVsfZcOrQQfvgf4urp/bmb5qnGZwjgV7rvRE/ZPPcK1i0YJwItAfSUFxg4Vl+QN0hJ5HsJT1jrfMHnI5+nKv2wBdQlKx4Q8tYeDhHeBIuw8FNgmxo9qXL2DydE+hZhLqg8FTARxMld758go0Z0jeMQHPQ8kR7DBKLAlT6qx9+8Dbb/ZFtvZgFU/8aak2RQ+6vQgjnOnk7ZDhLF14FIssAdmLB0u8mfo09OOvElOAegeBJZoEOPRGwfeOCneUOKfV1tNsqMAAe470LAFzK0J0as3+hurGQZF3/LEEX6RgqXgb1fcyRk/dOUc14mWhiqzazALnugzfFea+TiKTWgRnsfTCAUDtY7CJEirEJr8eqeQ3l5StMmFSk4Z2agSeJKJEaNAVpfvhr9NHdUfv6ci1QaubegaohrevmWkiyfA5NcJRYvourxmx+S7tBPNkHrJhO6UfTWLdN4Fg7xrA3ZlVGpRyOizSZfeWAcXKoQk5wDh+JGFmtdBX237Uo7oaUWcQGHpq2wXK+8S25gIM2prfb9x0A/Om26xLgNI4KlF4+PrzYs9oypgxJUVBnDLbNcpo2wQl9cdTTgq6zRiZTaCv0jnrwIfGnuZ9vio745iRJHDKQ+9eCTamSzfcX6KWG7vF04Cr+wZnRfRpLegGSLEqoiHYfH/498wb/BBPy/cgI72k00WgieDd6wyyxXvX8l4QYvd0g97xP/jcjT9NOMbXVZqrbyqH6t9N1YMi6iIK5qEkn4yxsa9+VHOk1QzaZcwWSSyQaJJ69HoeU1N10hkyBKM1cts8cQPaOJUdLXreW882Sw843R9ybtA5z1eK46EaJJ2k1bwKPtLnmug9aHlaKEjzGcsUI3AVwo7sVOqsUECaNRDF6LUrQH9JxiGkJSZGwONiyWqCUM1je1Ze9c42mSnxV/fVvVDMkZzpEiMnOGClvLPgD8YRmPqGD9Mf9TCrsQJUzT6eNdExnLCnUrlVOVlmCLHdWbD2yuzQ0F4Sq2ubbqtkiEzV8dAyrnZJjMrP6WM7lq7C+9eUaA3wDSIwiO4/LcbNxpcsLSzx8gId1jAEJ8K0YL371zK4Xraqfxd5bgjSKnve0Ivpv2U21++BKofWm43eLtBYbYblU2fT+l1ZvXQI8mXJrDIUo1oNnYF3YeLDQvjNTKq/o3xAHYxvd2rjIsKZ/fc5VZxD/aFmdwIQbemyHCOEMfi7Wq0l/3PEA5UrjrhvZIvywc/oqOa/SAPlZLVYnv2qIvuKzXDWQZQ4PSzCmTVYn0SGso8KpV2tzKr/iXb0Cy1u1uPPMyafoeMVVbsFJIir5UHIA0nVYG1/4XasY84xd/F6Hr2VvawQSlE0WpqRqzdXFuZPxzC9+MsgZaNa/34djbBb0aV2QKxwLMJLQDdFFUy+9lWFnxym2speOqbjoypcZQ3YzGs+IpTbt2U3IbBNTWU7nrv4IZPkq1Ie/ZIZdd1vZr8W47Tjj+1T9By4Za+eS/jqn4p2XhZoNVSxLy7JAGiRroYvHALyy5D4s75U1MCyh26le2kQEEzqTBa6gzcnz+O+R9lwCfH3pz3fSccT6X+hAVWt5hHgLUbW2irIQEVGeiMlCPLm0SFc0sBZjeSpOdc1hjxk3w== X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 4de252a6-bd8e-4da2-9f90-08dad36ce348 X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2022 07:23:05.0400 (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: qsNk91WBeYHKn6dbBri0qfHxN2Fg9/iBPqhKb+BXbwTbMMAEneAgnV9pBDi8fKDRemNjAFQmRZVVTClEWHTRQHBfUJQWGN6Uo5k3Z85QshA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6023 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750995582247273046?= X-GMAIL-MSGID: =?utf-8?q?1750995582247273046?= 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 v6: - no changes 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 Thu Dec 1 07:22:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 28218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp121934wrr; Wed, 30 Nov 2022 23:26:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ZArf01lKMDlXU9ZURc3sTZLgd0afUN7rm/WynVLmZitXhkGBQ3eaw17nNK5uFhhYBelVu X-Received: by 2002:a17:902:d58f:b0:189:a6bf:1b27 with SMTP id k15-20020a170902d58f00b00189a6bf1b27mr8168930plh.126.1669879561761; Wed, 30 Nov 2022 23:26:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669879561; cv=pass; d=google.com; s=arc-20160816; b=ithBrUZAiIZqN09PR+28i7JA21BhIDp02pPA96JBmyZEbzNI9dqImPlsghFOliuRkA +cZ8nGdKR+Jm+NbHDhXg2drRWg3DczVHAICh5y7ayu6kjHoAnr+5PbOCubQn0rT4yuQa flhxbuwMIIv3JcsWfUOpeyH/2pEQi9zHoBmKsaO4kp5sbCAaaNzoRdfGQnNTGD2w/mcp CgY+26zxPlrnY050FpjEof74WsmYJBFE2uB/OIt32U3w3vdi1zhKiYmXHGlT2Tr40kWo mjvCnZFybfsEu9Xn1B6GC9oGTnmth5zRGs9A5gw5AoPXnWhzPKyN8Mf5dU2neqR17TAB 2OLA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DcTrI2e03/n02a2qEVj5OqMq+C5Epm4gNCCaNxoObWE=; b=a5JdwDGolCupr5zwF4gLzFeOdU+yBVvifPPXAHCQOUjIMDV7qpaHdQeFVRlUjLF+ns C9oz8BD6pzc1LUPp30KcUbDdhTSXOAFK/mQPpLibuU15PC61Zru8WJYS4Je5+N7No3Np Zdx0fcen0sYI0wej/NeLvVxNTLKsc8gPTvWhdwfIOjUE7iwfiHzzVgfOnFy1Rpp+X4nT mI9s+6D+iHzRfTLsCytrhacHkrXJt7cvk7JrV52KpfBA25WW/afHRhEhD2YuCdqFz/WG UAnUuy8QmlM+FzvJ8p53mkFkDEdOLbvIXnpe2fGoPXSfbH13xq3wWm79bE/mZl0pjDBW 53/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=Bft+8wn1; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020a654643000000b0047831a85c77si3774528pgr.546.2022.11.30.23.25.48; Wed, 30 Nov 2022 23:26:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=Bft+8wn1; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbiLAHXj (ORCPT + 99 others); Thu, 1 Dec 2022 02:23:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbiLAHXT (ORCPT ); Thu, 1 Dec 2022 02:23:19 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2073.outbound.protection.outlook.com [40.107.22.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B730D45A37; Wed, 30 Nov 2022 23:23:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jo7Ilyv7Fusd6vk1hUPWTXxOsf6mE0IeN2d1g6jHQKHA0eOWlb5lZkSNcHKnXgPNpRcsRfy87kujjPrVzxRp65b2LMPIKNB49E7YTa5JKZZJw2YKwioUkkN+CLRRiESeR3GLqeR33xaaHLNIELFJ+KqCEOAJPMftHw3vQmpHC6cPPqyaMpZMvb9NJsUkMVurznC+PI77TT2w04kXvgeXHouNTxWs2KT4YWKUsIi9e36APRkwTMgV8FyWIaPvkl2iy3+8LpqUTl/2KEPgOh3ptg3XYZ1FXEkiB7aULUSgoZEORdHGncRPMWefuXAZ/e7LgVJ3Ghd/qmZpbLamY7ef5g== 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=DcTrI2e03/n02a2qEVj5OqMq+C5Epm4gNCCaNxoObWE=; b=k6HDFnJlug4r4qXUY2jp724D71/S4AB7WRjKzdpCoY6ENjz2DUq+ToorocieDUobVSTTZLH9LURtqy3rshuwZ2lwURSxOSAad04jGY0TCdg29zHFy7IHZ9CLVYbOaGDDNCqGJKaSssR42a1PhF2ZXeuHPY0Z6CLlbDXC8tu/gIFL1M/GoTamRuxGaVXKOsP1CSzE7ya+gMFo1LMGUNxcODR8tInffh0OnVj0BY+cVlrZ8jBOhFzHeottGmV18tJaVWaaoMcsfGlTZzl2Nr8BR+q6ANA3PqRxISkTvNx1ccAe41yLcV1G9cRZkcva0okecnYL94MxT0lwmpDbGqwJZA== 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=DcTrI2e03/n02a2qEVj5OqMq+C5Epm4gNCCaNxoObWE=; b=Bft+8wn1o8tTRnaspUVpz7vIQeTsRMHWMkmW8LMgup1y5zDLTqMQiG02XZkdrCvLNnEIF37lo35KQOcV8TJzSAWKYTK5tDTdMo/hLUzzOEwcvb6Sx2KEcXhPa2FnJd8B8+wDwqAk8NRqiiNehVN2poFGj2fnC9Ixbgk6AhKk4RQ= 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 AS8PR08MB6023.eurprd08.prod.outlook.com (2603:10a6:20b:291::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Thu, 1 Dec 2022 07:23:06 +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; Thu, 1 Dec 2022 07:23:06 +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 v6 2/3] dt-bindings: iio: magnetometer: add ti tmag5273 documentation file Date: Thu, 1 Dec 2022 08:22:19 +0100 Message-Id: <20221201072220.402585-3-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221201072220.402585-1-gerald.loacker@wolfvision.net> References: <20221201072220.402585-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0501CA0024.eurprd05.prod.outlook.com (2603:10a6:800:92::34) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|AS8PR08MB6023:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e2beabe-e4a2-46a0-f400-08dad36ce423 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O+hLmNdiImaZqAvZ7ze+KyuKZm304h1Q7XfyEE/IPhaLCW4LUeiPIkZrvln9Jf5zN+UzcMI6ApZKVH8d2z1J1zNdTvY3pSWP4BRxMbB5BxpDMA115lW0kyOQOCWlDVVz7w9xOXrU9dPKu98c3CpwU9SXvEu1tWrtEOt5TTLCRRqN1itvJhmJ67Mgem3tEgol7V2EFF7FvTSLGK0mRT+P3eACR+rDcQmHQ2phfdDAIdzu/UWbJUUWLgFDKIIOmENgQI0c8HldQZU/gRxdUS9LXWei1ADa008UkqzmmsPyyr8eiylo/RlAxeimnb9lVgFabqIgXnZKoIlWchULx7tSo9yGvCu3KThskaKYWh0u9HsbbqP1/rTepeevKx7ZZMLtvlEOr8o1FSAgBM/dO2zgLM/F5Ez0M0K3cYXnBQgUAV5VNBUESTJoxARFykTpFDYNo6t367UZ5osVjNJtjaE2fgAOyCmZ8Uu0iIIXHj5THJHoxfkNPms1RSXCdi3vivvEQGvE4kVWPYdiEMrS0LO6poRmY2VAqbNMZv6xSjJNw5DOR4FQGxFl+MiY52mcibnRPRORhRwTwK1JZxe2OSjQceN9ygEJscVoUlhq7JGOGCD2LCID6jIxaVyGAQ8M5J3/1of0pNsVFBkPNJJYuVYC2QsX4oQO4UhHoCNR/fiOl1TvXGRMubMbkaipc/UrJXcNhImLc9wH5bmfVfSWXYnjCnDB/6/GwOqX6fs5SyHEUzaYPFWJZm7x5MZyonGiPVEP 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)(346002)(136003)(39850400004)(451199015)(8936002)(5660300002)(186003)(36756003)(66476007)(41300700001)(4326008)(66556008)(54906003)(316002)(8676002)(38100700002)(86362001)(6486002)(6512007)(2616005)(66946007)(26005)(478600001)(7416002)(52116002)(1076003)(966005)(6666004)(38350700002)(6506007)(2906002)(44832011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/apuowKALf+Jet3lgkkcCGwegPd7?= =?utf-8?q?9qX9aJAmOKLOn4cAwsDJzDo4F0uJoV7Czehe6A+F4FMvQgjwtw6CzBg3IbQCJpsqT?= =?utf-8?q?6X/+pB3NsHoC5syHwXq0B5xr77L6x4NFeKSTNm+K5wFrtvvjSJAdmQoH0Iavnq+my?= =?utf-8?q?pM4SrHIr7QXBNUARZ9YISMZgvb+f7t5Itw3npQNurw8sjRvadcRA1qwZ6GguL5Fmd?= =?utf-8?q?3wG43z/zN60SmwfZF1Ip8COyYGbDqb/lK7EduLptWTW7Wn4Q1+sja0Qy8SB7WjuMW?= =?utf-8?q?DGKf/89M3p1t+dMg+0PTyhY93zBGlmqL1FGfzRA3F6LgENUmEh+L1/TIJFSB6LF/x?= =?utf-8?q?Cc1JCIWHWFU2PLWvmiu477MoDup6WarWxkOq1st3fMiFyU8tFNmPSx0HHV5tUWFhS?= =?utf-8?q?uDbpSDQPLkUwc6WzXNyuuutENOCWtcEEeCebE/QYW8VkKhnVAyaar1f1dP6E0Wyiw?= =?utf-8?q?nBog936oi2PgDM8BFLLYh0pJ3G6LuZnCH119nIxAuh1gIX7tT6JGRiiVblckts3HS?= =?utf-8?q?37Za/+Mv5pfX7+cMQ4jNyZmCFjyMt1Q8pj/1Oui6dlf+Z4lkC35hEf0fwsz5wZ2gb?= =?utf-8?q?hcSz6XL7trKX6CVNriI0RqE3iJryfR63Km6Bd7lR3vg96o8VkvtCa9QiNmXMc0Ur0?= =?utf-8?q?8qw6uKAf0IhhGW6sa8cljdi4Wf7ofExwjsa5RaT9Di5p9dWQ94HydAMzRgw/23868?= =?utf-8?q?lvT8mL17/+yclrfrE3Dg82rjUGI5XxqK31NkZbsqg+0nI8TNyouWndU2Q4NtseIHe?= =?utf-8?q?gR8W/uzjyLFsyDaXvO8KNsvGoCgtQQwujZAqYwB1jJd14zSKqJqSDumtG4gLYvBon?= =?utf-8?q?xPy6HBoA40KpBe9yFf+d/ib5FyMV2OjUej6jZgKwzy92rhJODGVFPYOEjKu93GXeZ?= =?utf-8?q?nliLMoyq+5/gKc+M/8le+sd4m9vdPQ7ZX1+LZ5XZVwxaibG/x2GTzphLDfWWRROOa?= =?utf-8?q?iiOTKl7uy0dmtS8RGABKzZJzaKJ0D2Hd5TCvXNE/rhAjDGcCgdsEzzUvbOvRQu2B9?= =?utf-8?q?N52uhfK/00ATTzGE8MYxK2fteD4JixoyPSWF/QlrwfL4w6v/Y2SgYtfmq//TS/JEj?= =?utf-8?q?krmRR7gBshVJIIe7B4izMliwztvbyFHQfmk+3ZqHofkM9yfOrwFGiHCgz4QmH31WA?= =?utf-8?q?mK080njxJ+YJ+DNOQlJlxydglYp7XsgXI+8BpJ2lSUoX58i5HXRvLqqrL+bbhKdAA?= =?utf-8?q?oNWnSG1Br+scIqkr6ojYKqUHM/XvZgCA508YU2Ocz7nU8f+PmLqTwFDYOXbCQgMxV?= =?utf-8?q?ngKPi4+/OpxN9+aeqv2g3KosGp67AFQbGQJZc7haR/ALq4tYfn/KqhdkswJiHw8qv?= =?utf-8?q?LbpuDjAPB5RKGiNQmMYiaPo4YLRN202j0VrSMGHO4pUHAzr2Zqh16VmMCAvi/iSTk?= =?utf-8?q?uu+p/4DQw7pm+5FzdoFsF2Idoe8azUGICyvSDd6DFwr1cM9rOnoePMfMSOkFKgyAw?= =?utf-8?q?zvrLlO/9ugJjuHjQeurKyOJZwaO/Pxx9xlfxsY+8/Fe7VXF42iyT7rhrG4rh9gmuV?= =?utf-8?q?3MtxOhWAdGFyAcOD6WBLAysQ3lwLvQ+IaA=3D=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 1e2beabe-e4a2-46a0-f400-08dad36ce423 X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2022 07:23:06.4774 (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: SrzPTDbNM77NpZ+eIhvq3NlYrCgl3DDKeAEnwggFIK319PB3KZ5Vr0aK3QimXQTrArmbdh99dGfbVA0g+kSFRi5VXXNSxSUd8B/c0Rm7OXM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6023 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750995631344379457?= X-GMAIL-MSGID: =?utf-8?q?1750995631344379457?= Add bindings for TI TMAG5273. Signed-off-by: Gerald Loacker Reviewed-by: Krzysztof Kozlowski --- Changes in v6: - no changes 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 Thu Dec 1 07:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Loacker X-Patchwork-Id: 28217 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp121767wrr; Wed, 30 Nov 2022 23:25:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf6P16bWZEaeSeBTajYOWlhw1JRtKxNh86tGSskJCqqRK7TLJ9B86lSfphKq+lSWfD+h974O X-Received: by 2002:a17:90a:4283:b0:218:4953:58aa with SMTP id p3-20020a17090a428300b00218495358aamr75090338pjg.219.1669879533141; Wed, 30 Nov 2022 23:25:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669879533; cv=pass; d=google.com; s=arc-20160816; b=IlzLOY1bGjvBjHdTDfLN+OTZLAMepsb6cdJhv+6LaKZGYmyKeqoFkd4xyQtteIu5T0 LZb/ToGzkJC0LY6HBKWBpSofMX5lMbdrX8QpSeEXU+Y8QSDUHgKJwBX/f+C8KtA4Aa6m 25UpxJEYyLf99p7Vtr62ZH6enEY0wBLJDhYfkEs8OKPajYKzW7MLT54vIkM/pmhe9PzE Or+i5b1mALHBaDc/4McAH6/mehPdRjCNzgg1QRCYa96ql94CZrsjc0V1ro3cR98zeTqR HEu8vSN/ui4uEnL02vUF2fSmrpKJ5ixkcVJA2dQS3+5tlh4ebh8ydTzNWZdTvS7S7sSz m/6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IKBtujhB9frL4G9x7/sZqqvYyb2RXrUdeln72NxSTeU=; b=ZghbHgj7iE5n/9Kp88UxuQRjaL7/g1X2hgxLs0HPOXVkcqAsnXU/TjAHPwzmPlnBjN 8GouwUtJgPN6fwNwlNTJQCfl5NFJ/mNeP26mTKRbTUjm7/8wr0dGrfVz9SclNLQyH/AF Ma/61IJp8aA+oBzs8ldO1oLFN2NcuctoWAJPDkokD6u1zoNFEbjP6PBmtobdBRNFg0kN 7UJ0jr81LewGc7YEJZ0sC50x6gPIv0ne1eHgSrWNZcVZDs96Z8lES58Vb3KQwqZeMyvs tC/DyFF2dJlJhrS6DD5pus5qF7QeeEtj3DD3Tm6MtgP426LPTYQATG+Prd3YcIqLq5st blAA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=y0QYhFMZ; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q33-20020a635c21000000b0043f06af782esi3747832pgb.304.2022.11.30.23.25.19; Wed, 30 Nov 2022 23:25:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=y0QYhFMZ; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbiLAHXV (ORCPT + 99 others); Thu, 1 Dec 2022 02:23:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbiLAHXO (ORCPT ); Thu, 1 Dec 2022 02:23:14 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2073.outbound.protection.outlook.com [40.107.22.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2201D31FBD; Wed, 30 Nov 2022 23:23:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jRImYTF5u3NsKda3Cnc/p9itpjg44s/zbQ4Fgi+SUKAcprnuvm6wwPfyK+jdNr9JI4Oo0hA6PLrDXrRD6f2Lk05lftTmUH3DwNfNzi2buWaSWEcoET0XD7cQM04IppP/05tkEnj7fqjC7Wojx7HhtYyYgjP/FKXGGYjOErFxAKKSatmDNtYaMxgEgwKjpC9qTWxQLoX0EYQmy+iilZLH6QG3EJoujcYmNuvIPzBeU05tIKrSBUfLpQV3pqCv5Um4sqoF2fA/7ctjKB7zHMmfzPPE09tfW8+1YMChDbn2NlAEpHcCMKQ532wmT+HAniUgB2LpkooZRtPXqgvRI6dI2g== 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=IKBtujhB9frL4G9x7/sZqqvYyb2RXrUdeln72NxSTeU=; b=Ci3SE8+4Vs8/TQa60xx3lerPmRJ5JirPKCKRelQYVsm16QGAlSAteIX9fEJtHnKJYYfqKFxT0yCy88vop/lxcTIcRiDgr4f6exR+pRC9dGFllmyZpVR+7Ps5A4vbnTJm0ctWIca9SYaIB6HYRxVI8Z2mQbrSTMQkZswwfa7UaChvfW1sdFraG6xZRKHu8t39JXuI+J6nNlD4+KO43ujKE9gJujpfeMfW6PQLzLt/iXDQYa1B6OQLTAC04rg4yWN6GIYHeosGJqlyv1aC2ISTZQyLTo7sFZfUWG0DqJ9MuKmU0ipp2whyh9SR2D7KzaKFMqZcPqaR9X+/KmMJfmp1IQ== 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=IKBtujhB9frL4G9x7/sZqqvYyb2RXrUdeln72NxSTeU=; b=y0QYhFMZFe2F17wQC1HOV66/2Zjgq74UFfbE6MHJu2Lhzjvq/GerPOJnPpCHEvh89AJKG2S9WmkgAbvgoZ1xmLVm02v3G5vkfH2nAuMfpvYUk7bpoFw2WBiAK3U9QeTvavYdANyrttRawazPd0GrEsAmlFaaw3uw6FeYGEZ/VJM= 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 AS8PR08MB6023.eurprd08.prod.outlook.com (2603:10a6:20b:291::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Thu, 1 Dec 2022 07:23:07 +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; Thu, 1 Dec 2022 07:23:07 +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 v6 3/3] iio: magnetometer: add ti tmag5273 driver Date: Thu, 1 Dec 2022 08:22:20 +0100 Message-Id: <20221201072220.402585-4-gerald.loacker@wolfvision.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221201072220.402585-1-gerald.loacker@wolfvision.net> References: <20221201072220.402585-1-gerald.loacker@wolfvision.net> X-ClientProxiedBy: VI1PR0501CA0024.eurprd05.prod.outlook.com (2603:10a6:800:92::34) To VI1PR08MB4544.eurprd08.prod.outlook.com (2603:10a6:803:100::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB4544:EE_|AS8PR08MB6023:EE_ X-MS-Office365-Filtering-Correlation-Id: b5c5f713-a56c-4127-c338-08dad36ce4b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0xr2GqqCIlFpMKxv5JH45MFHd7FPYue+8tJvt8VOOzgqMW+BLEZ6FOEntb6dQj3BB9Af/OR0XaUkw34gm2227HgkshTZ9j7TICxkYXxkFmTkn2miOrYPF1m7Svfz8otWUj1I30gHjaMNH1BSW49TxQZtS1kK35ICe9kqgTEDKwo6rCBA1fiBa82EQixdLZX8/bILpcDrMqxojM+d323Z54Z8GjvetrDIhDhLNmBihODyN01B/jZf+h1OUdbKGAvYFural4gXMnHeT+RHLcXO2KFJtaN+Qw9LrIKTNcrdJBnwd1YcqrcFsBGB4kdQbt3bwK0vbJvTutGzt2/+onBN34uK44frRRimMofos6oYYUYIC1xtd8Jk82o0IfVTAOfQ/zHQHYarxTKAzo9y5D6vjF6lK/TKYIjEGVrtVC5b4Ez/JPCnsmAUPTx9zk+VwYYfo4IUpNUQNgubkt6xOLhMimG400/26/ml6WF83kZdd7Nq5xDmORpewR/xLHD1M7sebQmg283CXvBHB+NwYezQjxaGgZSeTafa0kO1QftdUGaeW6mGsejFGbbfbGYTJ4/aCLIL8Ws83xVIYiVn+vVxUJOJ0+s06crtqWzcA+tlI0arzNYBUPZzZVwEomvNkKG0GF/M6DoqlAx7C9TMPRxQygkFO3FHzIjAO4AGoa7/eBP6UgZR+LbwROWIaM7rucqw1xyYfVm+YoQkbgpM9AnItLfqkGHGhKDp8X+aNhenD8g= 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)(346002)(136003)(39850400004)(451199015)(8936002)(5660300002)(186003)(36756003)(66476007)(41300700001)(4326008)(66556008)(54906003)(316002)(8676002)(38100700002)(107886003)(86362001)(83380400001)(6486002)(6512007)(2616005)(66946007)(26005)(478600001)(7416002)(52116002)(1076003)(966005)(6666004)(38350700002)(6506007)(2906002)(44832011)(30864003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3YS/MIqhhe9EbA1lxBEc1TwB2AnGsjaGNORHKrNGzh6l0YcinTE/MXpeNor7jFo8aeZnODoC6vnG4fvlmBKXqqTc5HpMUV8//wmZnzb7BIJsaWn8KMF0tvHct9uKAYGaTDBCFj+GjdA8kLFqA/XHe5Zv6eI5njBM6Bhr954TGaIGPjf+s/+4/gpZSyk14Dcx4KmwBLrLCJJn6+pjR+Zc5H+M05uWrlHRC9LPabs9/XM8nVsI3XmBFrzBAKE1ucJXPsm8oKmDzCZkrNBf1LigmSJm78uUujXrrduFNZs73HwAFoLhVt1QaeQLNdc1mh2kSzh5kt3EFySAdrJVGS2JWzCN3JYGA+M8OninjZ9bIx/ZRjWIgjTJxduX0TwdGtOWhKIQHsMzC0NZVg7BlmnoC1iqYBP11vtHDUcRsOgawGxoEY8vlDBEdY81XmctVdaHApzEkRsIm8WBnBtzYgLqXmep7EGhYsNHOvNLpjWfgBArPn3W/fmUdqVHLPAH4NKRAygH2wp8/7nvY8SEe3nIvEeGWWBAVFOdFg8Web/b1hPXexITk8ZPXgf2sIAV2isAzhdBPwZ9+Ed/5XpRPSDClSekgy0f7VLV9METjEnSWpQg5/5Yegfi5TRq2/eHquBmvwepMHudgVtdimU25ifJikb4s7dk0PE+xq3iKe4Rxrnz7HAHU7DqVK23wpjoiPuVXufDopEYAH2EA3hOh8vjHuVoao5Pc4DtuOFAueQrur9hQFiVwc9VSWgC5d9WgK8h7Ub2rrq6ViP97CwueU0za3uJwEBPl9LWLBq0fGalfhSGFZqI75qRP4R5VhIXDgKrFdb4QQ2LstoCjvJkMjiu2rYrSfjzdh/uNNb341j3srhHokYLdll+1M05UIFEL4FlSW5qJqfGMt6Awoe3s0cPg2amrDGgoqaQjiLwmyk+62EhApXUQB2RVxlUIrtHM/Gbx4MNHkmHqaeiCXXpXiJKdJ8lbgLEVK0jnzxI/JQ5JBPjPDnWjQu5COLS+8xOVeEve29Hz7S52vj3xF637FGZvjA/IffwDdATOINwks28G7UjLDojxQtOAFhU1vuqddBZx+Fo5uq45MyMxm2dderE7VRKYMAp01AvbSW7SnIAOT9qxweB7Hs0S4m0l53QUO02x6NpkG/D/TBwS1uk7wXxBBJJfhqyKVwoinO+nUAgOOH1hx1TJ6aFJ+QkfSAFTivJun75VQayyTVFYPajoum5hMmyJ2GsNBk1TXMjAltrbym1tBtjB7uv0iuPKueEs0qUDBnrs+oIt4wdky2DtmagZaj6WBdjI46GNWTF16jlo2qib0joxwi5xmG7EN2FnldkYkaIvanaUr/5A5BijmIPzVqwy6JmxKRbM/YjjMM3E7qp0SFIhUswr18QiYgcxNwXBObrh4jyvr1uVLiR/Qf8MnsTJ5pBh5eRHuDKgFLPwMbeHAoUHDSYdL1HH44WiCHGmSGIEbwqCTHjdl28N1OdeRYww86hlWMZvGOCZI4FieTz0/TGG1P6YVTxEDdwC/ryE0I5vQXfdm5butYR0OuunHFCHERtQ80vmp8aCfmXYswEI/g2dQO/gLSr8B7eXnkjfv/6Ee30PiSgXE555QlaIQ== X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: b5c5f713-a56c-4127-c338-08dad36ce4b7 X-MS-Exchange-CrossTenant-AuthSource: VI1PR08MB4544.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2022 07:23:07.4460 (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: 5ODBMs3TIFqHBCT4qsCFAQ7U4q+Rw0zGpIXV3wgggnMYufyRlPqa+AvS/AU9nfgVack/1CtqF/qfgs899db9C15/cJOakQRa0Sjn+sWjy2M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6023 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750995601387900040?= X-GMAIL-MSGID: =?utf-8?q?1750995601387900040?= 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 v6: - Defined TMAG5273_MAX_REG - Added comment for unknown device ID 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 | 743 ++++++++++++++++++++++++++++ 4 files changed, 758 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..0008138cbd63 --- /dev/null +++ b/drivers/iio/magnetometer/tmag5273.c @@ -0,0 +1,743 @@ +// 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_MAX_REG TMAG5273_DEVICE_STATUS + +#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_MAX_REG, + .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: + /* + * Only print warning in case of unknown device ID to allow + * fallback compatible in device tree. + */ + 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");