From patchwork Tue Nov 21 10:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp520766vqb; Tue, 21 Nov 2023 02:18:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEb5Zx9E5sj9iMWXqWHP2udD488XIkwKBDJM8sthR9+gUiZmHsmCva6O1fjp35gDT08RZMl X-Received: by 2002:a05:6870:7022:b0:1f9:6971:12da with SMTP id u34-20020a056870702200b001f9697112damr1697033oae.0.1700561913492; Tue, 21 Nov 2023 02:18:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561913; cv=none; d=google.com; s=arc-20160816; b=BJP5A15IXLpmAlWswREwKHQThDeJUO/lZXYN9fDs78TuTUkkF8WfmznIrEmOFGTJmU g/G4Od/Dvd2RNJ21vK6gXkyH6zWRw5xBtjtUnT7NGDrMlJbKtvG1qvA8RBlIxDl9Q3ck tBqIqCmxVe4x9PveV3dkwEfw1xZgMaE4FC7aMv+T3ZUAkvY9iy1yeTUUkoR4i7O4jOTs 5aGHCeBGXS8W1jaUkvsPHZ7N4qT0C2CblXIHRVa+9skNHteETRfYQr4UDkEVx3kW/MdQ DBwaNNqmr1Hzy/BMP9nnuID3YaCAmBDSBHkb7hazZskD4m+16my0mW4QNd9+vuJHZB8C YfPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=QohbLY7dW7q8BFzzSmrXneV14IW6RxwyVViKdDgmhCE=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=0X/RKJhr/KU8QSWsB7piqGPVRAFtrceM0rSWjkNrSA73/JDQeOePpIIqPyqVePg5BZ E6MVNhTxkVkQNLsBIxmsDAAJ+xAmnbQHyKAMMkt4zXRJ6OAmfyen13k2Zu0jkw4cJK7b KX7HGbxrjR6gusv6eEYxffaENG3V0wRnaYE0aM5LI4dSBcy71uFjzwkj9r0Inv7H7exy L3pGUZ6oolcd208KTuYMB2AL+OpRvBEAPae1ZNG1RWwR7brLuOBHGzAepsjTpqSVu7hg RXZ9CvebFrRpFFLmZINxwlu39+p+tfye8p/YAIJB8/JcKgrzVa5JDYVOYv0x0gG5dg42 fjOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oib2XK8e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id cm11-20020a056a020a0b00b005aaefc07ccfsi10340102pgb.36.2023.11.21.02.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:18:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oib2XK8e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7808D8068942; Tue, 21 Nov 2023 02:17:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233228AbjKUKR1 (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbjKUKRX (ORCPT ); Tue, 21 Nov 2023 05:17:23 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAC3111C for ; Tue, 21 Nov 2023 02:17:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 36C59C43391; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=xcCsv1YPXfjaIvVA0RXUQOLchG7pC7TZTbb7h2QT8FQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=oib2XK8eT+qBW/Nr472d/IyFjTfOHjRVg/9rYs7HMIkW6pLg/cMh1Mms2cGzbeyBm 3XwDVwIpdyYzPypAuS8/xiVeIDZA2KuJdGCU3vmoTvScbRvA1DEAtASwslpoW2HM0J 8k3dkcr0Vfl3SpneSmJg2avw0/cCj3BOSf0+55vLCfwvKO+sz+syiKp/gXFdtYob7S HsMmMdq2yS7GUtPdjdIfNXlxQSkzB008yQHlPcf12GKFSE6KHPEa5VYs6I5fncph7D DeHBHF+f1wTRjMq3/QxweB/k/8rAoHKdv/zrfCBMN+7s7/xaHqwvuUUwQ8dXiLxNDy TUDoQuRHZ1IZw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EFB9C61D88; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:14 +0100 Subject: [PATCH 01/12] driver: core: allow modifying device_links flags MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-1-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=1762; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=E5lJx+ba9aYfbW1751Y9ldC8MoJ9UmaBt8xD72NDIH4=; b=26RR5dmwuMuNTNSHOSrKzhJ9h6kRHuIupD5eZcLuJVFt7ycciyqPzBZYIEC4VKVNAvVs81nSY 9h5AiMe0tyIBb/3LpfBAVNjBvpsPsIPVhI3Nrk+IXGAEEGFn+7cKzt7 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:17:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168409199143841 X-GMAIL-MSGID: 1783168409199143841 From: Nuno Sa If a device_link is previously created (eg: via fw_devlink_create_devlink()) before the supplier + consumer are both present and bound to their respective drivers, there's no way to set DL_FLAG_AUTOREMOVE_CONSUMER anymore while one can still set DL_FLAG_AUTOREMOVE_SUPPLIER. Hence, rework the flags checks to allow for DL_FLAG_AUTOREMOVE_CONSUMER in the same way DL_FLAG_AUTOREMOVE_SUPPLIER is done. While at it, make sure that we are never left with DL_FLAG_AUTOPROBE_CONSUMER set together with one of DL_FLAG_AUTOREMOVE_CONSUMER or DL_FLAG_AUTOREMOVE_SUPPLIER. Signed-off-by: Nuno Sa --- drivers/base/core.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 4d8b315c48a1..b6aac55c361d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -806,11 +806,15 @@ struct device_link *device_link_add(struct device *consumer, * update the existing link to stay around longer. */ if (flags & DL_FLAG_AUTOREMOVE_SUPPLIER) { - if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) { - link->flags &= ~DL_FLAG_AUTOREMOVE_CONSUMER; - link->flags |= DL_FLAG_AUTOREMOVE_SUPPLIER; - } - } else if (!(flags & DL_FLAG_AUTOREMOVE_CONSUMER)) { + link->flags &= ~DL_FLAG_AUTOREMOVE_CONSUMER; + link->flags &= ~DL_FLAG_AUTOPROBE_CONSUMER; + link->flags |= DL_FLAG_AUTOREMOVE_SUPPLIER; + + } else if (flags & DL_FLAG_AUTOREMOVE_CONSUMER) { + link->flags &= ~DL_FLAG_AUTOREMOVE_SUPPLIER; + link->flags &= ~DL_FLAG_AUTOPROBE_CONSUMER; + link->flags |= DL_FLAG_AUTOREMOVE_CONSUMER; + } else { link->flags &= ~(DL_FLAG_AUTOREMOVE_CONSUMER | DL_FLAG_AUTOREMOVE_SUPPLIER); } From patchwork Tue Nov 21 10:20:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp520941vqb; Tue, 21 Nov 2023 02:19:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGa3CU9zzEYRMqXoMRSEVqhA0YZMElHuPKUFMLgzVO2fHPsB0k0TV66kYCVHHvoy9az1Na+ X-Received: by 2002:a05:6830:3d17:b0:6d6:4be1:4426 with SMTP id eu23-20020a0568303d1700b006d64be14426mr10003581otb.29.1700561942303; Tue, 21 Nov 2023 02:19:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561942; cv=none; d=google.com; s=arc-20160816; b=ot5MVhq5UhnjUKh0enEkLqXzK2ffpjJYs9JxG8RM4wDVL4dJvCrxSvOkxrTJe0BIqZ jtZG14Fn6QoD+4JT4k49imGmxOcG59YEKo2gzslRziKy/Yc5JB7HviBZVWSI3xv8zAJr Gq20N/A6m7BGDSNs3s8078Y2ikTikn3BhPWjSV2NfXWLrRA30O7at2vByDuqdgqUG2LJ Q2DwjnxEmpG95sclW/zbW7D+p4iinw84jgTOHItoFQxINCTMPStfSGIXFJFNo9gxx4Ot SJRAEy5ahwXLhqcA+Pdwc7CS10WyU+k3gaR2YHprI1whmBIPc7sf6Yl/DJcIjJcnnfpA o4bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=5lJ4WIYjn2gWU9I7inOQ1GTF8JDems8+efFeUsjoNSE=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=w+sIz6524yi/I20hWLqE4BgVYNKTTU5eRPRyXjKtMr9W/CGkHZCVrfYJl26A2ONAkU A+oAolQcOApNZJNPlFa9wAb7bNHnwNnQdAfvfNIyfMHbHq62VdQeZtQ+MsBg1lD330oj +xLEJBn/rh0wh3wfRZzOVvgObA2uEEJlQaJ5wc78DXjGllCIUQWiRjRfdULOctQ4cb+q gQhgGLjJx7yr0ETFz8wdwUDoFOoPy8FrPnraOnPdrRN/7N4AKF3uXjBmLtNSCSKR8KlH drpwy8oKguqklfv27iKNSijYnFLmS41V2fCNQX0wetuHhWby0AtaUMJVxUL96wr+XNCP JthQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LcArfob0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k38-20020a63ff26000000b005acd3068202si9986083pgi.552.2023.11.21.02.19.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LcArfob0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EA6FB80321ED; Tue, 21 Nov 2023 02:18:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233058AbjKUKRd (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232508AbjKUKRX (ORCPT ); Tue, 21 Nov 2023 05:17:23 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8AA5123 for ; Tue, 21 Nov 2023 02:17:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 414DEC4339A; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=SyiDg0M4bb96LkjdIXpGxEjy33+pSC9OiqWaYVm2mbo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=LcArfob0KPyzjlWHHA7Xr1L5mLN3cLO33jBh7/yw64RYsHJuq1o0UTd5a8hOKXfNW RjdQmprbhkoHvphiPQm9T4XDdALMw5Scjzk9vLQvxrwr59UVcW4a2VhJxZWdRNUQf3 7xJkyURy9qSSO1qWz8fMe6zOOaPYTVlugo2YhCyYCu+zY5YPME8UoZJzJhm+/3brJc Es0S44UbwF2Sq8zCOsHQ7QuqQpREmY4LDmoe5ZNBoNCUq0Z86bWFexB12WDQOKdgPu 5tCOMFd9i85F0JuJGFdtkdHxNzxFpOQLHSmdFv6Pgphp8f7n6SKzZqies7oV1ZUMzb YmiLpG3bHYx/A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B584C54FB9; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:15 +0100 Subject: [PATCH 02/12] of: property: add device link support for io-backends MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-2-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=1344; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=FN56N4bRgP7DSXQFw9VBSMu8KBn7uhCOtdkMxYwRVGo=; b=9P9DkFOjJlA87bAEaTzYVCxeiFrFxsqhruoD2Cj8TfiXTVFRdTcYH3Qw5P/Tq1x7Qczfi2yKB skhzbrDMdbjChTfL1jAZx0G/TbOKrbAh7dRl/k6Nc7QO6ooTB6aRZy9 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:18:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168439011425098 X-GMAIL-MSGID: 1783168439011425098 From: Olivier Moysan Add support for creating device links out of more DT properties. Signed-off-by: Olivier Moysan Signed-off-by: Nuno Sa --- drivers/of/property.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/of/property.c b/drivers/of/property.c index cf8dacf3e3b8..40a157daf08f 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1244,6 +1244,7 @@ DEFINE_SIMPLE_PROP(interconnects, "interconnects", "#interconnect-cells") DEFINE_SIMPLE_PROP(iommus, "iommus", "#iommu-cells") DEFINE_SIMPLE_PROP(mboxes, "mboxes", "#mbox-cells") DEFINE_SIMPLE_PROP(io_channels, "io-channel", "#io-channel-cells") +DEFINE_SIMPLE_PROP(io_backends, "io-backends", NULL) DEFINE_SIMPLE_PROP(interrupt_parent, "interrupt-parent", NULL) DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells") DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells") @@ -1333,6 +1334,7 @@ static const struct supplier_bindings of_supplier_bindings[] = { { .parse_prop = parse_iommu_maps, .optional = true, }, { .parse_prop = parse_mboxes, }, { .parse_prop = parse_io_channels, }, + { .parse_prop = parse_io_backends, }, { .parse_prop = parse_interrupt_parent, }, { .parse_prop = parse_dmas, .optional = true, }, { .parse_prop = parse_power_domains, }, From patchwork Tue Nov 21 10:20:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp521138vqb; Tue, 21 Nov 2023 02:19:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9+xPecR0AT/IPdqvelCjiCfPsWU4U+xzUSkWkUrR7PD3uDUhd4IFAnU23OEhQFeO+e7rx X-Received: by 2002:a17:90a:e7c1:b0:283:2805:7c7a with SMTP id kb1-20020a17090ae7c100b0028328057c7amr7663457pjb.43.1700561971765; Tue, 21 Nov 2023 02:19:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561971; cv=none; d=google.com; s=arc-20160816; b=F5JC80C0lBPKJ2OZhrU5eEgzqhVoLopueI0fHnCk9kqh5AXT+KHSMHDu1KHlgZ5MmG UcouU/61c98fio4PxRZrtEhNpUUK//8M8/YgfuZqtgGD0uvKYPK3Xk5DyjlyoneyZfms pyxr/RP6BvUrpN3YOhzCJVA68r9D0cIQf2ANwLKHntYeajiPPVrUdnfvpxBWWjhrWAtT Rc5zP1nZmVLTxJHq8+f6PwM1OHkLWMj9CffHCq8bOVHMNm4RVhf4ptpgAzBzdxrmQ46q 9aDdHyaMvVtDwbYmJE2Dtqf1tTmLjAkAS8LOi5KClnLHmm3DzyrYrg6IHQa57fWE96YS SxIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=piPVuH0NW5+eFErJPFSDddvHHE/iKQs0YU3DjtBoZJg=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=DOh/WwI7N5ebBBJGxtkKJo4Dxjhh59zyCFfg8YoRpgnUFh1VloM0fPPfEzcXlhef4T JfWZe6IPvjVTEw4U/tgJX0sciovgelELt6A+1iBBtGe9KWYYYg0U3Ms1euXQko1imoyS qKTCeY+H4cefJp+m+uAVUHTYU2D+S0wFctjZA+rH3zjJLTVvMMmEMvYmi+7ybQbe2rXJ CW7Gm0WoyAgmD4fbXaLacI0NkTLsHbjPCqcYk9XTdnVfZK6nqb6tzQDYRCVVadaPzoVd K0YAlBXtUA5s3Ky27sKu4LRkrhxi9CgL+jIOAGJ8qFyhWysq7tWEdI5y5JRabRDvgy5v EKSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rmMxqQQu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id be9-20020a170902aa0900b001ca93040adbsi9110691plb.653.2023.11.21.02.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rmMxqQQu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4106881043B1; Tue, 21 Nov 2023 02:17:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233604AbjKUKRw (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232960AbjKUKRY (ORCPT ); Tue, 21 Nov 2023 05:17:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF367125 for ; Tue, 21 Nov 2023 02:17:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 4F7AAC433BF; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=/oSYl9flhPg0YBaXCGjLnSwfN1N7d5GTC2/31nLbnZE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rmMxqQQubXghz6KJ7UnbtmlZySgbJ1w0ygmmUytVsASIMB89jnssl6O+KmcbiqySU i+ekLSuRo8zlV/ggc61WG1asB/6IiC/kZKJ6z5+mBxOcKKd8iztX5gsJrjnrMDNmh2 ZqGhKgKRqP4R7BFwQ0Vo9xicXLfMzDW52Ot09jCSeeLWH9UF1iAoS49tBLOGDpMZba SXIxCblEK5VKfpb6XEE0c5VDzYt3fGbTmXGCTh6P7ubGImPPhK5yagYRyUQJPiXZ3i +mv1XoRQv8zNFAazzwHaq0c2EPqXLxYfPzcTYM5qEu0gBu/O+1QIPzV6oGJ7P88c1r 864m0EfOwyz4A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38BD2C61D93; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:16 +0100 Subject: [PATCH 03/12] iio: add the IIO backend framework MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-3-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=13626; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=HcGNaoT+k8sdTWJ8i/Vb681dJIK2Fw5tfRlbp57sJyg=; b=iKnQgFUEOnzPYrctZAN21MreJUgdK98FQxaKQavEdeJkp1K7N3sRIuRaNn7XzGflQIiK5LN5D Oh4LJ2Hy+2YCoHBqoqjaHpWqDOQS1oIxJm+MZXr7FwH+Be4MxUI0jz1 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:17:56 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168470335468265 X-GMAIL-MSGID: 1783168470335468265 From: Nuno Sa This is a Framework to handle complex IIO aggregate devices. The typical architecture is to have one device as the frontend device which can be "linked" against one or multiple backend devices. All the IIO and userspace interface is expected to be registers/managed by the frontend device which will callback into the backends when needed (to get/set some configuration that it does not directly control). The basic framework interface is pretty simple: - Backends should register themselves with @devm_iio_backend_register() - Frontend devices should get backends with @devm_iio_backend_get() Signed-off-by: Nuno Sa --- MAINTAINERS | 7 + drivers/iio/Kconfig | 5 + drivers/iio/Makefile | 1 + drivers/iio/industrialio-backend.c | 302 +++++++++++++++++++++++++++++++++++++ include/linux/iio/backend.h | 58 +++++++ 5 files changed, 373 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c885d784dcb1..c20e288f23f0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10163,6 +10163,13 @@ L: linux-media@vger.kernel.org S: Maintained F: drivers/media/rc/iguanair.c +IIO BACKEND FRAMEWORK +M: Nuno Sa +L: linux-iio@vger.kernel.org +S: Maintained +F: drivers/iio/industrialio-backend.c +F: include/linux/iio/backend.h + IIO DIGITAL POTENTIOMETER DAC M: Peter Rosin L: linux-iio@vger.kernel.org diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index 52eb46ef84c1..451671112f73 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -71,6 +71,11 @@ config IIO_TRIGGERED_EVENT help Provides helper functions for setting up triggered events. +config IIO_BACKEND + tristate + help + Framework to handle complex IIO aggregate devices. + source "drivers/iio/accel/Kconfig" source "drivers/iio/adc/Kconfig" source "drivers/iio/addac/Kconfig" diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index 9622347a1c1b..0ba0e1521ba4 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_IIO_GTS_HELPER) += industrialio-gts-helper.o obj-$(CONFIG_IIO_SW_DEVICE) += industrialio-sw-device.o obj-$(CONFIG_IIO_SW_TRIGGER) += industrialio-sw-trigger.o obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o +obj-$(CONFIG_IIO_BACKEND) += industrialio-backend.o obj-y += accel/ obj-y += adc/ diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c new file mode 100644 index 000000000000..b11fcb2195c5 --- /dev/null +++ b/drivers/iio/industrialio-backend.c @@ -0,0 +1,302 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Framework to handle complex IIO aggregate devices. + * + * The typical architecture is to have one device as the frontend device which + * can be "linked" against one or multiple backend devices. All the IIO and + * userspace interface is expected to be registers/managed by the frontend + * device which will callback into the backends when needed (to get/set some + * configuration that it does not directly control). + * + * The framework interface is pretty simple: + * - Backends should register themselves with @devm_iio_backend_register() + * - Frontend devices should get backends with @devm_iio_backend_get() + * + * Also to note that the primary target for this framework are converters like + * ADC/DACs so @iio_backend_ops will have some operations typical of converter + * devices. On top of that, this is "generic" for all IIO which means any kind + * of device can make use of the framework. That said, If the @iio_backend_ops + * struct begins to grow out of control, we can always refactor things so that + * the industrialio-backend.c is only left with the really generic stuff. Then, + * we can build on top of it depending on the needs. + * + * Copyright (C) 2023 Analog Devices Inc. + */ +#define pr_fmt(fmt) "iio-backend: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct iio_backend { + struct list_head entry; + const struct iio_backend_ops *ops; + struct device *dev; + struct module *owner; + void *priv; + /* + * mutex used to synchronize backend callback access with concurrent + * calls to @iio_backend_unregister. The lock makes sure a device is + * not unregistered while a callback is being run. + */ + struct mutex lock; + struct kref ref; +}; + +static LIST_HEAD(iio_back_list); +static DEFINE_MUTEX(iio_back_lock); + +/* + * Helper macros to properly call backend ops. The main point for these macros + * is to properly lock the backend mutex on every call plus checking if the + * backend device is still around (by looking at the *ops pointer). + */ +#define iio_backend_op_call(back, op, args...) ({ \ + struct iio_backend *__back = back; \ + int __ret; \ + \ + guard(mutex)(&__back->lock); \ + if (WARN_ON_ONCE(!__back->ops)) \ + __ret = -ENODEV; \ + else if (!__back->ops->op) \ + __ret = -EOPNOTSUPP; \ + else \ + __ret = __back->ops->op(__back, ##args); \ + \ + __ret; \ +}) + +#define iio_backend_void_op_call(back, op, args...) { \ + struct iio_backend *__back = back; \ + \ + guard(mutex)(&__back->lock); \ + WARN_ON_ONCE(!__back->ops); \ + \ + if (__back->ops && __back->ops->op) \ + __back->ops->op(__back, ##args); \ + \ +} + +/** + * iio_backend_chan_enable - Enable a backend channel. + * @back: Backend device. + * @chan: Channel number. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan) +{ + return iio_backend_op_call(back, chan_enable, chan); +} +EXPORT_SYMBOL_GPL(iio_backend_chan_enable); + +/** + * iio_backend_chan_disable - Disable a backend channel. + * @back: Backend device. + * @chan: Channel number. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan) +{ + return iio_backend_op_call(back, chan_disable, chan); +} +EXPORT_SYMBOL_GPL(iio_backend_chan_disable); + +/** + * iio_backend_chan_enable - Enable the backend. + * @back: Backend device + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int iio_backend_enable(struct iio_backend *back) +{ + return iio_backend_op_call(back, enable); +} +EXPORT_SYMBOL_GPL(iio_backend_enable); + +/** + * iio_backend_disable - Disable the backend. + * @back: Backend device + */ +void iio_backend_disable(struct iio_backend *back) +{ + iio_backend_void_op_call(back, disable); +} +EXPORT_SYMBOL_GPL(iio_backend_disable); + +/** + * iio_backend_data_format_set - Configure the channel data format + * @back: Backend device + * @chan: Channel number. + * @data: Data format. + * + * Properly configure a channel with respect to the expected data format. A + * @struct iio_backend_data_fmt must be passed with the settings. + * + * RETURNS: + * 0 on success, negative error number on failure + */ +int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan, + const struct iio_backend_data_fmt *data) +{ + if (!data || data->type >= IIO_BACKEND_DATA_TYPE_MAX) + return -EINVAL; + + return iio_backend_op_call(back, data_format_set, chan, data); +} +EXPORT_SYMBOL_GPL(iio_backend_data_format_set); + +static void iio_backend_free(struct kref *ref) +{ + struct iio_backend *back = container_of(ref, struct iio_backend, ref); + + kfree(back); +} + +static void iio_backend_release(void *arg) +{ + struct iio_backend *back = arg; + + module_put(back->owner); + kref_put(&back->ref, iio_backend_free); +} + +/** + * devm_iio_backend_get - Get a backend device + * @dev: Device where to look for the backend. + * @name: Backend name. + * + * Get's the backend associated with @dev. + * + * RETURNS: + * A backend pointer, negative error pointer otherwise. + */ +struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) +{ + struct fwnode_handle *fwnode; + struct iio_backend *back; + int index = 0, ret; + + if (name) { + index = device_property_match_string(dev, "io-backends-names", + name); + if (index < 0) + return ERR_PTR(index); + } + + fwnode = fwnode_find_reference(dev_fwnode(dev), "io-backends", index); + if (IS_ERR(fwnode)) { + dev_err(dev, "Cannot get Firmware reference\n"); + return ERR_CAST(fwnode); + } + + guard(mutex)(&iio_back_lock); + list_for_each_entry(back, &iio_back_list, entry) { + struct device_link *link; + + if (!device_match_fwnode(back->dev, fwnode)) + continue; + + fwnode_handle_put(fwnode); + kref_get(&back->ref); + if (!try_module_get(back->owner)) { + dev_err(dev, "Cannot get module reference\n"); + return ERR_PTR(-ENODEV); + } + + ret = devm_add_action_or_reset(dev, iio_backend_release, back); + if (ret) + return ERR_PTR(ret); + + link = device_link_add(dev, back->dev, + DL_FLAG_AUTOREMOVE_CONSUMER); + if (!link) + dev_warn(dev, "Could not link to supplier(%s)\n", + dev_name(back->dev)); + + dev_dbg(dev, "Found backend(%s) device\n", dev_name(back->dev)); + return back; + } + + fwnode_handle_put(fwnode); + return ERR_PTR(-EPROBE_DEFER); +} +EXPORT_SYMBOL_GPL(devm_iio_backend_get); + +/** + * iio_backend_get_priv - Get driver private data + * @back Backend device + */ +void *iio_backend_get_priv(const struct iio_backend *back) +{ + return back->priv; +} +EXPORT_SYMBOL_GPL(iio_backend_get_priv); + +static void iio_backend_unregister(void *arg) +{ + struct iio_backend *back = arg; + + mutex_lock(&iio_back_lock); + list_del(&back->entry); + mutex_unlock(&iio_back_lock); + + mutex_lock(&back->lock); + back->ops = NULL; + mutex_unlock(&back->lock); + kref_put(&back->ref, iio_backend_free); +} + +/** + * devm_iio_backend_register - Register a new backend device + * @dev Backend device being registered. + * @ops Backend ops + * @priv Device private data. + * + * @ops and @priv are both mandatory. Not providing them results in -EINVAL. + * + * RETURNS: + * 0 on success, negative error number on failure. + */ +int devm_iio_backend_register(struct device *dev, + const struct iio_backend_ops *ops, void *priv) +{ + struct iio_backend *back; + + if (!ops || !priv) { + dev_err(dev, "No backend ops or private data given\n"); + return -EINVAL; + } + + back = kzalloc(sizeof(*back), GFP_KERNEL); + if (!back) + return -ENOMEM; + + kref_init(&back->ref); + mutex_init(&back->lock); + back->ops = ops; + back->owner = dev->driver->owner; + back->dev = dev; + back->priv = priv; + mutex_lock(&iio_back_lock); + list_add(&back->entry, &iio_back_list); + mutex_unlock(&iio_back_lock); + + return devm_add_action_or_reset(dev, iio_backend_unregister, back); +} +EXPORT_SYMBOL_GPL(devm_iio_backend_register); + +MODULE_AUTHOR("Nuno Sa "); +MODULE_DESCRIPTION("Framework to handle complex IIO aggregate devices"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h new file mode 100644 index 000000000000..8ae6549b8246 --- /dev/null +++ b/include/linux/iio/backend.h @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _IIO_BACKEND_H_ +#define _IIO_BACKEND_H_ + +#include + +struct iio_backend; +struct device; + +enum iio_backend_data_type { + IIO_BACKEND_TWOS_COMPLEMENT, + IIO_BACKEND_OFFSET_BINARY, + IIO_BACKEND_DATA_TYPE_MAX +}; + +/** + * struct iio_backend_data_fmt - Backend data format + * @type: Data type. + * @sign_extend: Bool to tell if the data is sign extended. + * @enable: Enable/Disable the data format module. If disabled, + * not formatting will happen. + */ +struct iio_backend_data_fmt { + enum iio_backend_data_type type; + bool sign_extend; + bool enable; +}; + +/** + * struct iio_backend_ops - operations structure for an iio_backend + * @enable: Enable backend. + * @disable: Disable backend. + * @chan_enable: Enable one channel. + * @chan_disable: Disable one channel. + * @data_format_set: Configure the data format for a specific channel. + **/ +struct iio_backend_ops { + int (*enable)(struct iio_backend *back); + void (*disable)(struct iio_backend *back); + int (*chan_enable)(struct iio_backend *back, unsigned int chan); + int (*chan_disable)(struct iio_backend *back, unsigned int chan); + int (*data_format_set)(struct iio_backend *conv, unsigned int chan, + const struct iio_backend_data_fmt *data); +}; + +int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan); +int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan); +void iio_backend_disable(struct iio_backend *back); +int iio_backend_enable(struct iio_backend *back); +int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan, + const struct iio_backend_data_fmt *data); + +void *iio_backend_get_priv(const struct iio_backend *conv); +struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name); +int devm_iio_backend_register(struct device *dev, + const struct iio_backend_ops *ops, void *priv); + +#endif From patchwork Tue Nov 21 10:20:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167615 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp520929vqb; Tue, 21 Nov 2023 02:19:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiXAlG0jWSW4Z5wJcLPoOlsKbE8o+qmAhHinKePrN7EjOBsqIbZHrHdkUCw09BjRwWNkYM X-Received: by 2002:a17:90a:3f87:b0:27f:bd9e:5a15 with SMTP id m7-20020a17090a3f8700b0027fbd9e5a15mr9071503pjc.28.1700561941272; Tue, 21 Nov 2023 02:19:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561941; cv=none; d=google.com; s=arc-20160816; b=cjEH6iIxvTVo+jhK+/VsMCjn0fzOe041qOwA/M/FyrYe/7TMFk7AA5pG1jnOWrgYm3 nncRMUggaWBl3li9vSDuebMzI+ZvpK/8ZpL/wfu9Ppmegr26zWXtzDCYDe2bzNON/0aY cq/BS7FpWzMhq10wwmTXQIVnA5J8S24fueVg3iB83RPNg1fo1ttZybKSRvu/O60/gdjC jJmWhHGyuPzRtGmw4vpVFNuHkP8pW9EVTMsZ06+Owp1+BI5+lWnXGE0GNrl5r2NUaIdS 1jDFdic00IMWv87FWEH84bHpmhppNkSnhY35zMJSUF8mcFkumaFT5mqKVR9ZLB0BFxXP dNvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=8JgsAoU3Rt2OVF5NQG/Ml9OxQMUNF6H72pTKb3a7DCg=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=VBxJaRuj4bmt+evKVVR6kgSRlX/i/nE/xu/H62H4VjoCzN/70Nr3j2YMibSaqwoKKx kv7w2ZNbkbByIv0KsAAceaJUz8mAUa+J4OKsFa5EBEcthv+deE8cmtLi4SFbaQGh1cE7 7aWsPKMLkRx05At0Xtz8k4JLSFPAFSZn2EKIrZTnZC0IHXKnhZSswQ/ltrsn6PCjZCXR jzWW47SpGvFv4+zyE1mH8Xxpf3ErYVUw9YeN7uRL3ehrGClA6CTBdJJ4m2aORvfO5B6c NcENVtJSl864RlVYnJ+hwmgAtf3QYr1HP+100LSniFIuhP8x1phWjPtt/67W0KgSSHN+ pPVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vBOT88LO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id pi16-20020a17090b1e5000b0027766994586si13293620pjb.71.2023.11.21.02.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vBOT88LO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9E18B8061406; Tue, 21 Nov 2023 02:17:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230256AbjKUKR3 (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232572AbjKUKRX (ORCPT ); Tue, 21 Nov 2023 05:17:23 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E1812A for ; Tue, 21 Nov 2023 02:17:19 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 5818BC433AB; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=kR1P1qDaKkBJqKHxLcftCCQPOWdMTfwi8zlle0jyKqw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=vBOT88LOE9Hs6UmC0GZ+CrcV2x6FG/SzD+X2lONoB3JvL2tlNzl3MHT8mw/pDFRT0 lh1dLjA+OWD6POGvUMs7WJ2D42DbnNDq3r3I4QMJlgCh9qf3knMAZVFQ4T/uLwxC5x TrmLPYloHLqJm29RRfg6hQTtscFYPBS6BJil/qawV7Nn2VYbAgd2W2ES3nOG1Bxf7y 03xIs0RPogPghut6UUi37ZmcJw//Km2lM9xesngRIKyagRWdSvXb5Ep14q4t74YJZ5 SH89jBFFCUSLXwfUQWPvtg2gNv3xNHYQXH+VexP+48HP0cZ8aNewkEiGrs08OGDClX eJ59TbPZu538w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 469B0C5ACB3; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:17 +0100 Subject: [PATCH 04/12] iio: adc: ad9467: fix reset gpio handling MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-4-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=2235; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=FvM763XbCHeFm7zY4qdHtyTPDglD207l1cPfXL+Oe8g=; b=P0PYKwMAq5iL7cSwivnC4VVCg/v4uxIFKKFnAFSJextBIv6XHP6HMK5EgXWqu3AOEsvidK4k8 XV1C7/S/fs3AY8OC0AcvsmPzFVQheDspuKVpvkfZ3R5cLdaYu3EndBB X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:17:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168438192374227 X-GMAIL-MSGID: 1783168438192374227 From: Nuno Sa The reset gpio was being requested with GPIOD_OUT_LOW which means, not asserted. Then it was being asserted but never de-asserted which means the devices was left in reset. Fix it by de-asserting the gpio. While at it, moved the handling to it's own function and dropped 'reset_gpio' from the 'struct ad9467_state' as we only need it during probe. On top of that, refactored things so that we now request the gpio asserted (i.e in reset) and then de-assert it. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 39eccc28debe..368ea57be117 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -121,7 +121,6 @@ struct ad9467_state { unsigned int output_mode; struct gpio_desc *pwrdown_gpio; - struct gpio_desc *reset_gpio; }; static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) @@ -378,6 +377,23 @@ static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) return ad9467_outputmode_set(st->spi, st->output_mode); } +static int ad9467_reset(struct device *dev) +{ + struct gpio_desc *gpio; + + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(gpio)) + return PTR_ERR(gpio); + if (!gpio) + return 0; + + fsleep(1); + gpiod_direction_output(gpio, 0); + fsleep(10); + + return 0; +} + static int ad9467_probe(struct spi_device *spi) { const struct ad9467_chip_info *info; @@ -408,18 +424,9 @@ static int ad9467_probe(struct spi_device *spi) if (IS_ERR(st->pwrdown_gpio)) return PTR_ERR(st->pwrdown_gpio); - st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", - GPIOD_OUT_LOW); - if (IS_ERR(st->reset_gpio)) - return PTR_ERR(st->reset_gpio); - - if (st->reset_gpio) { - udelay(1); - ret = gpiod_direction_output(st->reset_gpio, 1); - if (ret) - return ret; - mdelay(10); - } + ret = ad9467_reset(&spi->dev); + if (ret) + return ret; conv->chip_info = &info->axi_adc_info; From patchwork Tue Nov 21 10:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp521115vqb; Tue, 21 Nov 2023 02:19:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGS4ORNifg5IgvYWUdoa/OkhTF3TGKsc0AZN9qamku/NWlsNpTrVcZ+KwPuO5j7bzy7UTyn X-Received: by 2002:a17:903:22c7:b0:1cf:5c99:75f8 with SMTP id y7-20020a17090322c700b001cf5c9975f8mr7678630plg.65.1700561967401; Tue, 21 Nov 2023 02:19:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561967; cv=none; d=google.com; s=arc-20160816; b=LCr+PAbJuLhaU8BXtOFUfCBtvuvIvYbqv7kTaZ+SQ1sBm+UXSM7wt4jRZ/MipwxLc+ RapoRzHIxGEGLjn9O14F2o29TYezvAtpN9Y+chiW74fmAIFcQrMl8wlc1SC1s8C6/HwF gq/C5EefYw7bow7NihYApsiPnBz9ZmbvFs46FyI/rrGtMr+DieaNTj9M0BmFA0wHR6wY 0PLPVG3x9ZnaMUrz5DQCnfAksQXUSCfFnw/4iyu8jxA/K045vjLw6sfvovLbACdc+f/x 0Ldp+igGN6izmPUFJdkycJ9W9ACY6T8sY7+oixGP2DrNRgseA7GaSpJBlv0jAkt3CFQa jYPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=DAZY5AJ+GBHEyNx/dy9x+RErJZiZi/jB6WP5lrFGW7Y=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=p7uz+VMbeht5c0nrtZ7eG+9sAnju6KrGrpQLOiRwym4yC1k8y2G5JtE/JK9JycimKZ B6xvjUYTAfMUm0uRbkH++QASf+4UXGXdJhoVY3cqKUCVKA5PztqVQV9K8Z0D5to65ghf dNwH6GJtPNc62yv83gnbYck5cFJcsrVsm0BBmHz56+z3gcPd+CsowXxCzAlAbCGXFfkJ hcVntWZe3rxkWWlCCbBRFF65lhSry72qSnIYhIq6SrjjCySZiHXM61004sCZ9m/957sY VKnLL6FlRXQBnnrUte/CHIpv7X1GTXEf86+USdY4LYxHYqonvC1oxTw2qZKR6ABtjEFc SVIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qWgIDHcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p7-20020a170902a40700b001ca30930778si9429046plq.71.2023.11.21.02.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qWgIDHcj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A6086810438D; Tue, 21 Nov 2023 02:17:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232493AbjKUKRs (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232964AbjKUKRY (ORCPT ); Tue, 21 Nov 2023 05:17:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10031113 for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 65C59C43215; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=qSUa7Hi/hUvGOoV6T8t+VfM63v3j7nIpVAXf0Nwefts=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qWgIDHcjtrnHnJCZozZC23X8yKhhvdi6PscYnSnqGN/hur4B5WMyBBAgV9hbRKEHl Q5X15wT0LX9tPbiAun3N0ifbMEt+pKH+ztuPEdUESZGPk0WrwNsJ39eCLaFq4lJFpO gcBVv/nXhkcEQJt7RxSUJcIKJH0dwXazuVsqWMnqCoOP4YRJzE5Mx7oTAiRBL1Q14e mOECvk9dPv1Iy41EndovdhNow/5t8UDqGwDHmwY7PkkmgjIxc42OShjd7AVvcO97Zp 5gfPdvexpN36clBpRCL9MZb8fE90mzGe8xrqjmhw1qXxQqhEqrAZuEAKIvhYBdB+TR gh6/HQUOz5aEQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 554F2C61D88; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:18 +0100 Subject: [PATCH 05/12] iio: adc: ad9467: don't ignore error codes MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-5-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=2285; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=p+reK//8NVmJckTKVuZ5PeMlMhxvLT/SuRjMD0wgKfo=; b=R49EuewoiHYxiFgzjwcP3nIvMmY3PaNku9HMivMl6qBa1cAQ4vL1PO2YimCWCUzwwgQil7p41 rK7JWGwGhYhAXTFw/8uQ5/zSJbi1frMDouMhKua7NwtA37UYKhmdp5O X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:17:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168465503530568 X-GMAIL-MSGID: 1783168465503530568 From: Nuno Sa Make sure functions that return errors are not ignored. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 368ea57be117..04474dbfa631 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -160,11 +161,12 @@ static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, struct spi_device *spi = st->spi; int ret; - if (readval == NULL) { + if (!readval) { ret = ad9467_spi_write(spi, reg, writeval); - ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, - AN877_ADC_TRANSFER_SYNC); - return ret; + if (ret) + return ret; + return ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, + AN877_ADC_TRANSFER_SYNC); } ret = ad9467_spi_read(spi, reg); @@ -274,6 +276,8 @@ static int ad9467_get_scale(struct adi_axi_adc_conv *conv, int *val, int *val2) unsigned int i, vref_val; vref_val = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF); + if (vref_val < 0) + return vref_val; vref_val &= info1->vref_mask; @@ -296,6 +300,7 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) struct ad9467_state *st = adi_axi_adc_conv_priv(conv); unsigned int scale_val[2]; unsigned int i; + int ret; if (val != 0) return -EINVAL; @@ -305,11 +310,13 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) if (scale_val[0] != val || scale_val[1] != val2) continue; - ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, - info->scale_table[i][1]); - ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, - AN877_ADC_TRANSFER_SYNC); - return 0; + ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, + info->scale_table[i][1]); + if (ret < 0) + return ret; + + return ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, + AN877_ADC_TRANSFER_SYNC); } return -EINVAL; From patchwork Tue Nov 21 10:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp521027vqb; Tue, 21 Nov 2023 02:19:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IERY1oPO1fEiK9FveU5wFPa9/+KUo2Or7AeFcDZ78kDmqeTJAX/sVA//0c5KSKQj4FYTHvY X-Received: by 2002:a05:6a00:10c1:b0:6cb:bfc1:d3cb with SMTP id d1-20020a056a0010c100b006cbbfc1d3cbmr1076506pfu.16.1700561955183; Tue, 21 Nov 2023 02:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561955; cv=none; d=google.com; s=arc-20160816; b=YDDNWizvbEsDqgjJduYQvU7PeBuRlb9dxV1OPSg/NRLUSu/VA/LMJQS7z44oC/N+ih r4UJG1qCMQ9XZaBLEeNrQzYLC/+WW7mNclNkygGHZ2lHa4KGpAHv4G9SNrp9XPqMUaj+ aHpJTlqwXT1Ku+Vq2KvsRqM3GjJ6YbNO833x3aydM/b5D0sy5h85hG71aEcsg+RPlXWc XvM7PkIZqS3IgqhxPqnwJoQ8OvPLs+xcHtLNGzAGr2zdJMIUG0tdpqCZN2Ew0EpmPRJd ww++pm93wSir8cKI2CWvhctXQaW4qBRCaTGb8omUke904AOHslL6JohzcSsMsiaSFqUf Gqhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=mPCkF8r2gjDEwjA2exXfcObrLZoc5dRWaBYNS8IwX7w=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=D5q+nraKMVA3MqYsHIDJfmRx+L+VW93s0Yx7hxVvcOu3iUeRi3WpbWztsn46ApOPuz 5bJ8zozjXm+DfWHQp/3LxLv/AIE/qO0iCoJGqR9uPcF4jD2sg3cPiu9wscI58uDECr0d dPX11p3kg8nLstmfjSIoWvbm7o9cjEewy/Pag/COK2hC202cLPYTLWzgrhc7wk6cIiql 6LcVR9zheIjSwXLl5HKAew4otP3AejSdTK1iL9604qTbEaWZ7SAwSy8ZYaQCUVWM8KVC LnU+Z991Ew+Y3pbn4F1qjBTO5L9615wxUX1dxQ2NKgVnC9tCAanoMlKW4MTHQ9XtxFTI eDeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eM9cxBHG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h2-20020a056a00230200b006cbbd597aa1si1245203pfh.242.2023.11.21.02.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eM9cxBHG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EC47F810438F; Tue, 21 Nov 2023 02:17:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233680AbjKUKRn (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232875AbjKUKRY (ORCPT ); Tue, 21 Nov 2023 05:17:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1250011C for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 756A9C433CD; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=0BvXHNAq6MxvTFFypFKVLfm202ysR+MbTta68aDgcfw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=eM9cxBHG3fTojuudhsxbw1lZ7Gau0JELf/VvK07u5vpOTcme0gJ4xu+Itj8nCrBSS pQ69EQgUShyyhjHqyvtNK2fVLPjWzmn3347UIdDPX5pmrsJ9BNyBTiTtY5sWz3020C 1pF2EKHPSBIM7uYjXbgTbtpIiVU8tqs+yJIhruao5qJns1oBXNxyzQgSuqsAuc5rj5 j/4tC4i/BSgLYG/bNh5GL4Lb/bNJZgxQBh9frk9hEv1o+hRZ74LtQrT9pUsmM0NKwJ Mddy82xhpqFXPLV5KIcEOMEJ6uUrRPtQ/JJQjqjP0EiQQXm3lH0T31LaKT20IKzTiv Rj83/7XWraOOw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63334C61D92; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:19 +0100 Subject: [PATCH 06/12] iio: adc: ad9467: add mutex to struct ad9467_state MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-6-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=1622; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=g3tcVMAWnAaNpfd4zR0L8lXR29z5KekLRZe6sxMF/hk=; b=c73pLlPBK+gRvwbzpMIaQzg2/RJK0F0Puv/XvfzcIUdIwAgeIeOujPcKeq6HBext2kU07mya6 y+9u9e194XEB1j4VRHh9o3JjEgyQO25ay/PCBtt95QyHrc9TUVacvKt X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:17:45 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168452415838918 X-GMAIL-MSGID: 1783168452415838918 From: Nuno Sa When calling ad9467_set_scale(), multiple calls to ad9467_spi_write() are done which means we need to properly protect the whole operation so we are sure we will be in a sane state if two concurrent calls occur. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 04474dbfa631..91821dee03b7 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -4,7 +4,7 @@ * * Copyright 2012-2020 Analog Devices Inc. */ - +#include #include #include #include @@ -122,6 +122,8 @@ struct ad9467_state { unsigned int output_mode; struct gpio_desc *pwrdown_gpio; + /* protect against concurrent accesses to the device */ + struct mutex lock; }; static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) @@ -162,6 +164,7 @@ static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, int ret; if (!readval) { + guard(mutex)(&st->lock); ret = ad9467_spi_write(spi, reg, writeval); if (ret) return ret; @@ -310,6 +313,7 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) if (scale_val[0] != val || scale_val[1] != val2) continue; + guard(mutex)(&st->lock); ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, info->scale_table[i][1]); if (ret < 0) From patchwork Tue Nov 21 10:20:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp520721vqb; Tue, 21 Nov 2023 02:18:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEY63euT1p24OnAmysq2eIbbr3eJ9f59/OwGgMFKB5zkBaMSU5YiyU+iczF7yTzOknlOP44 X-Received: by 2002:a05:6e02:c84:b0:359:4f85:b230 with SMTP id b4-20020a056e020c8400b003594f85b230mr11424567ile.18.1700561907607; Tue, 21 Nov 2023 02:18:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561907; cv=none; d=google.com; s=arc-20160816; b=E3StSbRwWJr2OA+3xzC94Uq/8CBThvGPdtUzx01LytR+e1PeTe3/21c9L159LVcZ6S xX2wTVitWADO6TLRTojCTufDGQTQgtfW59MUaQmO5DhVNDfeQGr5zgOyujhaBkIDZ0vI wDZlvV0zWrbdjPRweVkuySN75EOYv0SiLeqIoLf8F1nkgo9edc2HLrDvCRZDGvJ/Vq/u kR8yNksIAf/tm6UYiL9ppuOWw4dtTzalwjulIZw+lIY9fuUbMWDZXkqFRO7Tk47q6wee VpeYFUqlJp+Lrqr3XRhRSQfVBE++75elah8p6q1he4oIXQvqy3Wnu91Mq3bwGGl9fafS 2IAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=BBnsZD75SUflJ1mE92Xkg1WUtCkdV/6j0nHuJI93Wa4=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=HMWiN5t4skH67uBqtX9l89wFJIGuIelrrySbK8jM7n+PHENP7Z0w4++7lR2P7+F1qG kXRzo7aYxzjLKe/mBXXnltBIgYdOXC5oMm4SScKwNrRmWRwRcXjJE4YB7Ay4TNe4qm+3 1PEm8N6vbWbgDxmCceVSzl0mJVRAIldK7W0Yg23eBcE/wzPxb81tPIz5CcJ1wxATPvnO VqTMUqeXpQaHCErd8Od180+e33WkjBsEe8hhZHmJajvRFa8fbeVsoIRHtvfUGa00VQtA a9Op24hIcF5sxqldaMYkHKoSGJ/f6t+aMeEOTRWCBZ5snyqfstMpv7tyOc5Wwxx/9ROv FGrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=j+KXFBmO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id 195-20020a6300cc000000b005b8f61fcb98si9989021pga.629.2023.11.21.02.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:18:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=j+KXFBmO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1BF9F8031D4E; Tue, 21 Nov 2023 02:18:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233752AbjKUKSA (ORCPT + 99 others); Tue, 21 Nov 2023 05:18:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233230AbjKUKRZ (ORCPT ); Tue, 21 Nov 2023 05:17:25 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DAC1123 for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id 89361C433C9; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=aNABuSX/iu/FZhYqcM7nGl46V+DTa8I77sLNnNUUCbM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=j+KXFBmO0VLW/kk+YkqR74u1RvNjaYcbY30YaQTpU7OitaBTQU5F+iyZR7vLFbdek ZiqZ8kyMEHKkjJxeTYQr5i6o2wql53rRHBziJwLHJiKAsQPcOJaqnSPjZesXe9ujlx aFFHHCUgzqQTiZwQBToBmJneVvQimCOvy/TDEwNEl8ceKDE7yQQArh5WcToNF/+JeC G9PA2b5Mr5u0wNorE1zWPm2pl0YSYBgBMx4fpOZ2AQ38bHVCW/pR01FMh9N2MAVszy khKa7ZdMmAny34bXlOQyWCYkoNN49MNbV5wC/+fV8/xJCCXbCNq96HciUKZYlv9VfT FKpdzv/p5gnzQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76438C61D93; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:20 +0100 Subject: [PATCH 07/12] iio: adc: ad9467: fix scale setting MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-7-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=8213; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=5RjYNT6FmhQuBx41nfBmHPCdi4pZgV0vQHZroLMTopw=; b=oVQFvVd9qVYjXGGsy9vaJzyQsWgsY6P5EpBdM7AlD7XfsL8GrcP587ImNrjSzhEGZHL9JtUEJ ed+R8jlUjXXCZ2IFQOYQs9Cv6bWGIrsd88hj5kuqyDRXIoHBuOnCt/d X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:18:09 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168402713897574 X-GMAIL-MSGID: 1783168402713897574 From: Nuno Sa When reading in_voltage_scale we can get something like: root@analog:/sys/bus/iio/devices/iio:device2# cat in_voltage_scale 0.038146 However, when reading the available options: root@analog:/sys/bus/iio/devices/iio:device2# cat in_voltage_scale_available 2000.000000 2100.000006 2200.000007 2300.000008 2400.000009 2500.000010 which does not make sense. Moreover, when trying to set a new scale we get an error because there's no call to __ad9467_get_scale() to give us values as given when reading in_voltage_scale. Fix it by computing the available scales during probe and properly pass the list when .read_available() is called. While at it, change to use .read_available() from iio_info. Also note that to properly fix this, adi-axi-adc.c has to be changed accordingly. Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC") Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 47 +++++++++++++++++++++++ drivers/iio/adc/adi-axi-adc.c | 74 ++++++++----------------------------- include/linux/iio/adc/adi-axi-adc.h | 4 ++ 3 files changed, 66 insertions(+), 59 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 91821dee03b7..df4c21248226 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -120,6 +120,7 @@ struct ad9467_state { struct spi_device *spi; struct clk *clk; unsigned int output_mode; + unsigned int (*scales)[2]; struct gpio_desc *pwrdown_gpio; /* protect against concurrent accesses to the device */ @@ -216,6 +217,7 @@ static void __ad9467_get_scale(struct adi_axi_adc_conv *conv, int index, .channel = _chan, \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE), \ .scan_index = _si, \ .scan_type = { \ .sign = _sign, \ @@ -369,6 +371,26 @@ static int ad9467_write_raw(struct adi_axi_adc_conv *conv, } } +static int ad9467_read_avail(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + *vals = (const int *)st->scales; + *type = IIO_VAL_INT_PLUS_MICRO; + /* Values are stored in a 2D matrix */ + *length = info->num_scales * 2; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) { int ret; @@ -381,6 +403,26 @@ static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) AN877_ADC_TRANSFER_SYNC); } +static int ad9467_scale_fill(struct adi_axi_adc_conv *conv) +{ + const struct adi_axi_adc_chip_info *info = conv->chip_info; + struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + unsigned int i, val1, val2; + + st->scales = devm_kcalloc(&st->spi->dev, ARRAY_SIZE(*st->scales), + info->num_scales, GFP_KERNEL); + if (!st->scales) + return -ENOMEM; + + for (i = 0; i < info->num_scales * 2; i++) { + __ad9467_get_scale(conv, i, &val1, &val2); + st->scales[i][0] = val1; + st->scales[i][1] = val2; + } + + return 0; +} + static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) { struct ad9467_state *st = adi_axi_adc_conv_priv(conv); @@ -441,6 +483,10 @@ static int ad9467_probe(struct spi_device *spi) conv->chip_info = &info->axi_adc_info; + ret = ad9467_scale_fill(conv); + if (ret) + return ret; + id = ad9467_spi_read(spi, AN877_ADC_REG_CHIP_ID); if (id != conv->chip_info->id) { dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", @@ -451,6 +497,7 @@ static int ad9467_probe(struct spi_device *spi) conv->reg_access = ad9467_reg_access; conv->write_raw = ad9467_write_raw; conv->read_raw = ad9467_read_raw; + conv->read_avail = ad9467_read_avail; conv->preenable_setup = ad9467_preenable_setup; st->output_mode = info->default_output_mode | diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index aff0532a974a..ae83ada7f9f2 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -144,6 +144,20 @@ static int adi_axi_adc_write_raw(struct iio_dev *indio_dev, return conv->write_raw(conv, chan, val, val2, mask); } +static int adi_axi_adc_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct adi_axi_adc_state *st = iio_priv(indio_dev); + struct adi_axi_adc_conv *conv = &st->client->conv; + + if (!conv->read_avail) + return -EOPNOTSUPP; + + return conv->read_avail(conv, chan, vals, type, length, mask); +} + static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) { @@ -228,69 +242,11 @@ struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, } EXPORT_SYMBOL_NS_GPL(devm_adi_axi_adc_conv_register, IIO_ADI_AXI); -static ssize_t in_voltage_scale_available_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - size_t len = 0; - int i; - - for (i = 0; i < conv->chip_info->num_scales; i++) { - const unsigned int *s = conv->chip_info->scale_table[i]; - - len += scnprintf(buf + len, PAGE_SIZE - len, - "%u.%06u ", s[0], s[1]); - } - buf[len - 1] = '\n'; - - return len; -} - -static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); - -enum { - ADI_AXI_ATTR_SCALE_AVAIL, -}; - -#define ADI_AXI_ATTR(_en_, _file_) \ - [ADI_AXI_ATTR_##_en_] = &iio_dev_attr_##_file_.dev_attr.attr - -static struct attribute *adi_axi_adc_attributes[] = { - ADI_AXI_ATTR(SCALE_AVAIL, in_voltage_scale_available), - NULL -}; - -static umode_t axi_adc_attr_is_visible(struct kobject *kobj, - struct attribute *attr, int n) -{ - struct device *dev = kobj_to_dev(kobj); - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - - switch (n) { - case ADI_AXI_ATTR_SCALE_AVAIL: - if (!conv->chip_info->num_scales) - return 0; - return attr->mode; - default: - return attr->mode; - } -} - -static const struct attribute_group adi_axi_adc_attribute_group = { - .attrs = adi_axi_adc_attributes, - .is_visible = axi_adc_attr_is_visible, -}; - static const struct iio_info adi_axi_adc_info = { .read_raw = &adi_axi_adc_read_raw, .write_raw = &adi_axi_adc_write_raw, - .attrs = &adi_axi_adc_attribute_group, .update_scan_mode = &adi_axi_adc_update_scan_mode, + .read_avail = &adi_axi_adc_read_avail, }; static const struct adi_axi_adc_core_info adi_axi_adc_10_0_a_info = { diff --git a/include/linux/iio/adc/adi-axi-adc.h b/include/linux/iio/adc/adi-axi-adc.h index 52620e5b8052..b7904992d561 100644 --- a/include/linux/iio/adc/adi-axi-adc.h +++ b/include/linux/iio/adc/adi-axi-adc.h @@ -41,6 +41,7 @@ struct adi_axi_adc_chip_info { * @reg_access IIO debugfs_reg_access hook for the client ADC * @read_raw IIO read_raw hook for the client ADC * @write_raw IIO write_raw hook for the client ADC + * @read_avail IIO read_avail hook for the client ADC */ struct adi_axi_adc_conv { const struct adi_axi_adc_chip_info *chip_info; @@ -54,6 +55,9 @@ struct adi_axi_adc_conv { int (*write_raw)(struct adi_axi_adc_conv *conv, struct iio_chan_spec const *chan, int val, int val2, long mask); + int (*read_avail)(struct adi_axi_adc_conv *conv, + struct iio_chan_spec const *chan, + const int **val, int *type, int *length, long mask); }; struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, From patchwork Tue Nov 21 10:20:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp521152vqb; Tue, 21 Nov 2023 02:19:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IH07pYz+1juujc4pUsOv92h5LR/aI+0bkOSvBwBDlePXknK7JEhd61HTZVq8Z1pSzaWR2I/ X-Received: by 2002:a92:320d:0:b0:359:30b1:4265 with SMTP id z13-20020a92320d000000b0035930b14265mr10574013ile.4.1700561975612; Tue, 21 Nov 2023 02:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561975; cv=none; d=google.com; s=arc-20160816; b=kIjkB3niQhlzjDF56k+0QVa6UnI33zJPJNhoO1maTHt4CbztrBtLyrn8PxzT92V43U t12D2gqKFmXTfDbA8GQN3A/loS13gwXTb3+Ggc91e+EOKvntQNqF/n5T5j87iEZcUs2M QkqO40VRq2EGM2b+UGxpteiLSl2mVjUBdlPb9XpcXpcbkv4uf39OuaCE5iuMs+yscOJX tofpzrJ/S1lUZIbzE8coTAd5AwMMOUwXTLPDnffHd718l5eL1YjRF8KtJikUWjqlnnfb 0Y1fruIEhw95TVd67hIiWt/rw0rWUkUhzFF5CH6ouZHvLd4cIZnYl15iYJvIjis9ElVx GLjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=R64GEZuVzY1nB4Hgmz27LP49LNsOHOLztywFKyvtJXM=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=Xj2K6l5m5chdQGKH2QCxS8oChT+aHOnsrjAGWsSj25C2+hdFqUqt51j+Ud/6r9HCqK 6/luE1aqivUgpfdPkNvCS1tQWZVyLfKHXTTAlo69OwG/N/VjPCqI0SbCYmSIUCZbBf8c jvoq8h2xlvWLCEQO4REco82QWcoKAB05vPIglssC25znim6zwkQl/VD5x7eEuenigKPu pYPHM9ZVillWJYwse5N0ZhzWmt1y0n3cZV/dQP32aZG5fb6QduKgW/z2+997/DceP3hv BxrMyKHKC4udvZITgJZK0/iqr9Du3FjqhqHv3SPYM9P77w8odORPspHYJV01B3sSut/Y FQxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lntgOrf9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id w10-20020a63d74a000000b005b884a11fdcsi9795411pgi.28.2023.11.21.02.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lntgOrf9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1A48D8104519; Tue, 21 Nov 2023 02:18:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232600AbjKUKRy (ORCPT + 99 others); Tue, 21 Nov 2023 05:17:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232841AbjKUKRY (ORCPT ); Tue, 21 Nov 2023 05:17:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E51012A for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id AE8A5C433B6; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=9VrRKn1T4nW7pywpPWHeJW9v+K02u4HC9bddai2LGIs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=lntgOrf9pEnmt1kBeSd1mEuOCJN9paZeKsT3jK8wRZVPLhqIbSMwiTYMe/U9HOPwc zNnmJjyDvY5mOpZ92z2Kkx40eIPuks4mwBGpdIBqLAOrOyBuHk5+80mqR3TB2QtKsi Vf5Fkke9TC2tqJYeJSgXO4+2jh8HxjWc+Vs2AZo769nsEf6Py80lcz95hZJ/nWiLVY b7PV4+JxiEBNaYak7HM8YEBK+KWQqbF17mx9tWFEmU2B5a/4H/z0hfe2GJ86uhbqtq z/D0wuyH26STC4e0nOa42Jt7GzGCvNg9zEmjlVcjLQse2/wzB781+XOu6MV0BgqV9C 1EpPBux/E12Qg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ED7DC54FB9; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:21 +0100 Subject: [PATCH 08/12] iio: adc: ad9467: use spi_get_device_match_data() MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-8-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=686; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=zYitHUb6TMLk+FkB4cL0ig740y1mLs+DvRMVWPrSNF0=; b=bXWJ7iE5iGJrgtGP5xd739Rr7ggBJOq8O9gdmWl6WbsvAQnU0yaRoF4iISJY3EzpfGMuAUAIN 4AltcqL8Q1WDNvkTtIpIqq0oGoY4BjwJS5R5b8uMYVJRnq0B/qzJQbm X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:18:01 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168473839732341 X-GMAIL-MSGID: 1783168473839732341 From: Nuno Sa Make use of spi_get_device_match_data() to simplify things. Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index df4c21248226..f0342c8942ee 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -455,9 +455,7 @@ static int ad9467_probe(struct spi_device *spi) unsigned int id; int ret; - info = of_device_get_match_data(&spi->dev); - if (!info) - info = (void *)spi_get_device_id(spi)->driver_data; + info = spi_get_device_match_data(spi); if (!info) return -ENODEV; From patchwork Tue Nov 21 10:20:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167614 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp520810vqb; Tue, 21 Nov 2023 02:18:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IG51tr0zE75E1VaholQV9wjIMrDCdADZpFhugOQFlqszEmcP8h+F2Nh8u3ILe/5k+nAPdHz X-Received: by 2002:a05:6a21:6d8a:b0:187:d380:fd98 with SMTP id wl10-20020a056a216d8a00b00187d380fd98mr8835722pzb.44.1700561921382; Tue, 21 Nov 2023 02:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561921; cv=none; d=google.com; s=arc-20160816; b=gZBIGeW+QfwVNmPRpqzD1necxPj3kREbS10oAWP1Ed8lbX1DYVexFOe7RPvMFpA7MC 1cuiz3NDKa+wE3FmNQIp4vBcgQ5CYPBIXLsaIxXVql5SpdXm+0zZd6Gnb2ENdD863i6f FXxQz0Q5QUZkGRkMMQco+ppJWxbzPQM5f1gChm752bdjgvzN0eFTN2rn9Ne7m0B9+5Pv k9SnqXJF9tujqU88gcluLMwVnc4wXQhCWaG4mvQ2bVXbywubYwwKR3bepQkkfYlMC01m jN50k3/1eyf1xM9mA8deebNh//Z5aatrNLeZi/I/QS9ZlQIttFgF5Ddv0oJxMg6xNvtb MwQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ih77yxA4BbrR9sb3xfi7YLBXZFMWFiOsJlTc1SChrMI=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=Awp3CKWuor2njPBWPRGf0smBIPUaVhDtvCGEWHIIAHLOyAjierq8E6g2WFARVxkKRc Jkw5OFZe0NI6L8MeN+z0Q6aJIApPYepOYzjtY7jr4mfxiD3tIdscl77cCJAUP0EdRe59 7V7swpTL6aTeolDfbY3l3pqAv+Y2UsP1kPsvTrkf1S8uqGTuVpvSC7O4CcP9hIB+agMN nYYBi01/yo9p8vgmlpInGFUGvYwAPN7dyKn5BlziuZ9ypLDEWUF3rjLFUyQnP33NO8/R vfXUUQ3v38Amuf2Bis2uUfiiK0pURPqT3ooUEdzmShJUvE12zmh4psv4XCRqKHO+UfvJ aSBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="MG22fP/8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id fy1-20020a17090b020100b0028511adb1acsi6463753pjb.67.2023.11.21.02.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:18:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="MG22fP/8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B35F98048D8E; Tue, 21 Nov 2023 02:18:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233787AbjKUKSE (ORCPT + 99 others); Tue, 21 Nov 2023 05:18:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233176AbjKUKRZ (ORCPT ); Tue, 21 Nov 2023 05:17:25 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3309B134 for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id BCEAAC433B7; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=3jqcpmMVgRdlV0OZKCqw9abAHNIj6Mrrp0uhYEWv1Tw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=MG22fP/8IbSk4s4y1vLdBrnoBg+zYmS0SAke44UgfmDz21OKuqfGt4MAF3OK+JWLl HSfavn7vxUR1o6bUUTQVNrOujw41oh/yjAV7vmM2OOqtgVHLW+QuM3rayrrUhd5SaX kNB3U5tO65hb5BNIoB0fE6BxIcwtI5y1Q8w7dWwuWM6S+gBGUcrB/Rm+UuClPVPTOX 5aG04NOEmjBYdniXWXzx3pQxCM6H9/ofZFt8cyacAMQYYlsWPVUKKkuwDkN8s8bp0B Wcgehwn7348Unz8ppoiDBevUFpnbzAxM/LCQBLHRPoZRtIQ5kf+40sfvnAuGPVT42n ZdIoBP6JzXmEg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A924DC5ACB3; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:22 +0100 Subject: [PATCH 09/12] iio: adc: ad9467: use chip_info variables instead of array MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-9-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=4457; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=vkbr36xjXuQW5nYydBocFuU8wGwlSsFvoY57jHRaH1w=; b=He0UNjSCXL2IIli4eBSKtEN63uAMX1iX8sAVvjSjiwnMjnttPr8caWXTQQjkZG7/HQauGJe4v gsLvTYTUJw8AkRva2t7rNxuOc9TIj9MRnodf6mbaPiFcZGIUmpJ591x X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:18:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168417298027053 X-GMAIL-MSGID: 1783168417298027053 From: Nuno Sa Instead of having an array and keeping IDs for each entry of the array, just have a chip_info struct per device. Signed-off-by: Nuno Sa --- drivers/iio/adc/ad9467.c | 89 +++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index f0342c8942ee..5db5690ccee8 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -101,12 +101,6 @@ #define AD9467_DEF_OUTPUT_MODE 0x08 #define AD9467_REG_VREF_MASK 0x0F -enum { - ID_AD9265, - ID_AD9434, - ID_AD9467, -}; - struct ad9467_chip_info { struct adi_axi_adc_chip_info axi_adc_info; unsigned int default_output_mode; @@ -234,43 +228,46 @@ static const struct iio_chan_spec ad9467_channels[] = { AD9467_CHAN(0, 0, 16, 'S'), }; -static const struct ad9467_chip_info ad9467_chip_tbl[] = { - [ID_AD9265] = { - .axi_adc_info = { - .id = CHIPID_AD9265, - .max_rate = 125000000UL, - .scale_table = ad9265_scale_table, - .num_scales = ARRAY_SIZE(ad9265_scale_table), - .channels = ad9467_channels, - .num_channels = ARRAY_SIZE(ad9467_channels), - }, - .default_output_mode = AD9265_DEF_OUTPUT_MODE, - .vref_mask = AD9265_REG_VREF_MASK, +static const struct ad9467_chip_info ad9467_chip_tbl = { + .axi_adc_info = { + .name = "ad9467", + .id = CHIPID_AD9467, + .max_rate = 250000000UL, + .scale_table = ad9467_scale_table, + .num_scales = ARRAY_SIZE(ad9467_scale_table), + .channels = ad9467_channels, + .num_channels = ARRAY_SIZE(ad9467_channels), }, - [ID_AD9434] = { - .axi_adc_info = { - .id = CHIPID_AD9434, - .max_rate = 500000000UL, - .scale_table = ad9434_scale_table, - .num_scales = ARRAY_SIZE(ad9434_scale_table), - .channels = ad9434_channels, - .num_channels = ARRAY_SIZE(ad9434_channels), - }, - .default_output_mode = AD9434_DEF_OUTPUT_MODE, - .vref_mask = AD9434_REG_VREF_MASK, + .default_output_mode = AD9467_DEF_OUTPUT_MODE, + .vref_mask = AD9467_REG_VREF_MASK, +}; + +static const struct ad9467_chip_info ad9434_chip_tbl = { + .axi_adc_info = { + .name = "ad9434", + .id = CHIPID_AD9434, + .max_rate = 500000000UL, + .scale_table = ad9434_scale_table, + .num_scales = ARRAY_SIZE(ad9434_scale_table), + .channels = ad9434_channels, + .num_channels = ARRAY_SIZE(ad9434_channels), }, - [ID_AD9467] = { - .axi_adc_info = { - .id = CHIPID_AD9467, - .max_rate = 250000000UL, - .scale_table = ad9467_scale_table, - .num_scales = ARRAY_SIZE(ad9467_scale_table), - .channels = ad9467_channels, - .num_channels = ARRAY_SIZE(ad9467_channels), - }, - .default_output_mode = AD9467_DEF_OUTPUT_MODE, - .vref_mask = AD9467_REG_VREF_MASK, + .default_output_mode = AD9434_DEF_OUTPUT_MODE, + .vref_mask = AD9434_REG_VREF_MASK, +}; + +static const struct ad9467_chip_info ad9265_chip_tbl = { + .axi_adc_info = { + .name = "ad9265", + .id = CHIPID_AD9265, + .max_rate = 125000000UL, + .scale_table = ad9265_scale_table, + .num_scales = ARRAY_SIZE(ad9265_scale_table), + .channels = ad9467_channels, + .num_channels = ARRAY_SIZE(ad9467_channels), }, + .default_output_mode = AD9265_DEF_OUTPUT_MODE, + .vref_mask = AD9265_REG_VREF_MASK, }; static int ad9467_get_scale(struct adi_axi_adc_conv *conv, int *val, int *val2) @@ -505,17 +502,17 @@ static int ad9467_probe(struct spi_device *spi) } static const struct of_device_id ad9467_of_match[] = { - { .compatible = "adi,ad9265", .data = &ad9467_chip_tbl[ID_AD9265], }, - { .compatible = "adi,ad9434", .data = &ad9467_chip_tbl[ID_AD9434], }, - { .compatible = "adi,ad9467", .data = &ad9467_chip_tbl[ID_AD9467], }, + { .compatible = "adi,ad9265", .data = &ad9265_chip_tbl, }, + { .compatible = "adi,ad9434", .data = &ad9434_chip_tbl, }, + { .compatible = "adi,ad9467", .data = &ad9467_chip_tbl, }, {} }; MODULE_DEVICE_TABLE(of, ad9467_of_match); static const struct spi_device_id ad9467_ids[] = { - { "ad9265", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9265] }, - { "ad9434", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9434] }, - { "ad9467", (kernel_ulong_t)&ad9467_chip_tbl[ID_AD9467] }, + { "ad9265", (kernel_ulong_t)&ad9265_chip_tbl }, + { "ad9434", (kernel_ulong_t)&ad9434_chip_tbl }, + { "ad9467", (kernel_ulong_t)&ad9467_chip_tbl }, {} }; MODULE_DEVICE_TABLE(spi, ad9467_ids); From patchwork Tue Nov 21 10:20:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167623 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp521257vqb; Tue, 21 Nov 2023 02:19:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIW08DmGq9RHpIJ70hCbvAYCd2d7RNBvA+obA+XU+VIg8ltkQkqWWFr+7dBe/TsptBrFem X-Received: by 2002:a17:903:2350:b0:1cf:595b:eaf4 with SMTP id c16-20020a170903235000b001cf595beaf4mr3513242plh.23.1700561991841; Tue, 21 Nov 2023 02:19:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561991; cv=none; d=google.com; s=arc-20160816; b=BkwnYaBnkK+ttpiF3Fjf7t9WPflHqDR9yfqhub9pbliIH4/N7a0SYvzMKcsW2i+DDw u7m8eSAW1CcOtgaJr07Az0HQaw9Lt0AaFP2yS1nyyko+iBjTSjn34hoCc5yDo+bSkv7k vhvFb/N09Ji4KdW8K3PwGgseZ5yZvuJcPwf9gXn5D6IIM9ANlYfW4COI7xxyr0p+fD8i AUcNA6C60A9ydu963yngigjjbuatFTwAWjBBE/+5oZ3eS0nBw6RyfJeZBgCbq4rcGJVt 95hn/4JR7/ZIIUk9NY/FrVXzxYlNO9IMS917h8OyzPeWYiwb5Djkx2YQnfHYhMVSdEOa qxWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=7cerog8OWsAoV8cX62kLTQsv75PTnK+n3zNUlAie42Q=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=jSIZBnBQYZlCXo05VLffIcXZNbZwAcmzJAp6Q26Q1yeVDaCSKGm4gu4sFphZW6PWxS mOmttDLfBH9H1KX0bq8KbNtyUXC8rbST1MPXrThlsuK72KL1nUSB23TmEwEAQThCWdDR q91aoublJa0bJV/ZmPu3g+F4k0N7JCgeUs/GJTesCuZVp6pzfGTB4So47eh2oJXJhlk+ CDlJ2mwCbwdyAXbqnBKMM1ZaxwS3ESY3hRqlg9SmXUcmxmK7wy8U6gkU8bR0jmwbNEJD hQmWeavQDoBk3j3SinSfhhmSLLSeSkkxJixrJD/HMrba17NRFceqiMan8e47R9fd1tUW v6aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dC9GOjZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id j9-20020a170903024900b001bda57935fasi10392710plh.64.2023.11.21.02.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dC9GOjZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9B177805DC01; Tue, 21 Nov 2023 02:18:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233817AbjKUKSP (ORCPT + 99 others); Tue, 21 Nov 2023 05:18:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233336AbjKUKR1 (ORCPT ); Tue, 21 Nov 2023 05:17:27 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344C1136 for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id C762CC433BB; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=2UVrdcO0muwBEBrUxXZmYaeSEgZfw994WYRynIcJKVA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dC9GOjZcnEOitFG2oxzXOYWAs34uU6YPt7hanAx+69J4nBuZGB45EwXJfsrmsVjyB G/gDppEvQD3ZSH+eNjEf0RTcxiuocf8eJ/qBjKnnykD7EtBZL64vqM1Ge7R7Up88k4 RZfohnHCcGK0aybTjbbcktxeUXiRupiHhbZgVCph/IgOVqXkPMZguklxAdHU2qY/XD WiCHdmbiojGwcnxpVgR76wXl6ka3LpmgpKbcp9x2OBsjh241DnXQ6QwNx8EphSuytx lTVf4A6rbmreKNQm9R1j95PrTHTGTNB6An2DGF3smQlw3eA93kgXPKQHzSbOSjxl70 4tdr34hqceI/Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B643CC61D88; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:23 +0100 Subject: [PATCH 10/12] iio: adc: ad9467: convert to backend framework MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-10-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=15166; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=Eq7e4pir873ISYA9fOUXbCVYvPsa2GwjrUl9ExaZa3g=; b=/ATgHhaFYBUX/e6U/yJCqqx2Y46Bt36VCEJ0Hp+q+myPbWd5wM37f0pT0DzNowkcEwh1Tkabb a8IIXDj2ULAAnvo3IV3Ydra8RsCAKjs8xfi2Oo0Zv5ABFf+vGBVAVVR X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:18:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168491376804180 X-GMAIL-MSGID: 1783168491376804180 From: Nuno Sa Convert the driver to use the new IIO backend framework. The device functionality is expected to be the same (meaning no added or removed features). Also note this patch effectively breaks ABI and that's needed so we can properly support this device and add needed features making use of the new IIO framework. Signed-off-by: Nuno Sa --- drivers/iio/adc/Kconfig | 2 +- drivers/iio/adc/ad9467.c | 256 +++++++++++++++++++++++++++++------------------ 2 files changed, 157 insertions(+), 101 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 1e2b7a2c67c6..af56df63beff 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -275,7 +275,7 @@ config AD799X config AD9467 tristate "Analog Devices AD9467 High Speed ADC driver" depends on SPI - depends on ADI_AXI_ADC + select IIO_BACKEND help Say yes here to build support for Analog Devices: * AD9467 16-Bit, 200 MSPS/250 MSPS Analog-to-Digital Converter diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c index 5db5690ccee8..8b0402e73ace 100644 --- a/drivers/iio/adc/ad9467.c +++ b/drivers/iio/adc/ad9467.c @@ -16,13 +16,13 @@ #include #include - +#include #include #include #include -#include +#include /* * ADI High-Speed ADC common spi interface registers @@ -102,15 +102,20 @@ #define AD9467_REG_VREF_MASK 0x0F struct ad9467_chip_info { - struct adi_axi_adc_chip_info axi_adc_info; - unsigned int default_output_mode; - unsigned int vref_mask; + const char *name; + unsigned int id; + const struct iio_chan_spec *channels; + unsigned int num_channels; + const unsigned int (*scale_table)[2]; + int num_scales; + unsigned long max_rate; + unsigned int default_output_mode; + unsigned int vref_mask; }; -#define to_ad9467_chip_info(_info) \ - container_of(_info, struct ad9467_chip_info, axi_adc_info) - struct ad9467_state { + const struct ad9467_chip_info *info; + struct iio_backend *back; struct spi_device *spi; struct clk *clk; unsigned int output_mode; @@ -151,10 +156,10 @@ static int ad9467_spi_write(struct spi_device *spi, unsigned int reg, return spi_write(spi, buf, ARRAY_SIZE(buf)); } -static int ad9467_reg_access(struct adi_axi_adc_conv *conv, unsigned int reg, +static int ad9467_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, unsigned int *readval) { - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + struct ad9467_state *st = iio_priv(indio_dev); struct spi_device *spi = st->spi; int ret; @@ -191,14 +196,13 @@ static const unsigned int ad9467_scale_table[][2] = { {2300, 8}, {2400, 9}, {2500, 10}, }; -static void __ad9467_get_scale(struct adi_axi_adc_conv *conv, int index, +static void __ad9467_get_scale(struct ad9467_state *st, int index, unsigned int *val, unsigned int *val2) { - const struct adi_axi_adc_chip_info *info = conv->chip_info; - const struct iio_chan_spec *chan = &info->channels[0]; + const struct iio_chan_spec *chan = &st->info->channels[0]; unsigned int tmp; - tmp = (info->scale_table[index][0] * 1000000ULL) >> + tmp = (st->info->scale_table[index][0] * 1000000ULL) >> chan->scan_type.realbits; *val = tmp / 1000000; *val2 = tmp % 1000000; @@ -229,77 +233,66 @@ static const struct iio_chan_spec ad9467_channels[] = { }; static const struct ad9467_chip_info ad9467_chip_tbl = { - .axi_adc_info = { - .name = "ad9467", - .id = CHIPID_AD9467, - .max_rate = 250000000UL, - .scale_table = ad9467_scale_table, - .num_scales = ARRAY_SIZE(ad9467_scale_table), - .channels = ad9467_channels, - .num_channels = ARRAY_SIZE(ad9467_channels), - }, + .name = "ad9467", + .id = CHIPID_AD9467, + .max_rate = 250000000UL, + .scale_table = ad9467_scale_table, + .num_scales = ARRAY_SIZE(ad9467_scale_table), + .channels = ad9467_channels, + .num_channels = ARRAY_SIZE(ad9467_channels), .default_output_mode = AD9467_DEF_OUTPUT_MODE, .vref_mask = AD9467_REG_VREF_MASK, }; static const struct ad9467_chip_info ad9434_chip_tbl = { - .axi_adc_info = { - .name = "ad9434", - .id = CHIPID_AD9434, - .max_rate = 500000000UL, - .scale_table = ad9434_scale_table, - .num_scales = ARRAY_SIZE(ad9434_scale_table), - .channels = ad9434_channels, - .num_channels = ARRAY_SIZE(ad9434_channels), - }, + .name = "ad9434", + .id = CHIPID_AD9434, + .max_rate = 500000000UL, + .scale_table = ad9434_scale_table, + .num_scales = ARRAY_SIZE(ad9434_scale_table), + .channels = ad9434_channels, + .num_channels = ARRAY_SIZE(ad9434_channels), .default_output_mode = AD9434_DEF_OUTPUT_MODE, .vref_mask = AD9434_REG_VREF_MASK, }; static const struct ad9467_chip_info ad9265_chip_tbl = { - .axi_adc_info = { - .name = "ad9265", - .id = CHIPID_AD9265, - .max_rate = 125000000UL, - .scale_table = ad9265_scale_table, - .num_scales = ARRAY_SIZE(ad9265_scale_table), - .channels = ad9467_channels, - .num_channels = ARRAY_SIZE(ad9467_channels), - }, + .name = "ad9265", + .id = CHIPID_AD9265, + .max_rate = 125000000UL, + .scale_table = ad9265_scale_table, + .num_scales = ARRAY_SIZE(ad9265_scale_table), + .channels = ad9467_channels, + .num_channels = ARRAY_SIZE(ad9467_channels), .default_output_mode = AD9265_DEF_OUTPUT_MODE, .vref_mask = AD9265_REG_VREF_MASK, }; -static int ad9467_get_scale(struct adi_axi_adc_conv *conv, int *val, int *val2) +static int ad9467_get_scale(struct ad9467_state *st, int *val, int *val2) { - const struct adi_axi_adc_chip_info *info = conv->chip_info; - const struct ad9467_chip_info *info1 = to_ad9467_chip_info(info); - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); unsigned int i, vref_val; vref_val = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF); if (vref_val < 0) return vref_val; - vref_val &= info1->vref_mask; + vref_val &= st->info->vref_mask; - for (i = 0; i < info->num_scales; i++) { - if (vref_val == info->scale_table[i][1]) + for (i = 0; i < st->info->num_scales; i++) { + if (vref_val == st->info->scale_table[i][1]) break; } - if (i == info->num_scales) + if (i == st->info->num_scales) return -ERANGE; - __ad9467_get_scale(conv, i, val, val2); + __ad9467_get_scale(st, i, val, val2); return IIO_VAL_INT_PLUS_MICRO; } -static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) +static int ad9467_set_scale(struct ad9467_state *st, int val, int val2) { - const struct adi_axi_adc_chip_info *info = conv->chip_info; - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); unsigned int scale_val[2]; unsigned int i; int ret; @@ -307,14 +300,14 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) if (val != 0) return -EINVAL; - for (i = 0; i < info->num_scales; i++) { - __ad9467_get_scale(conv, i, &scale_val[0], &scale_val[1]); + for (i = 0; i < st->info->num_scales; i++) { + __ad9467_get_scale(st, i, &scale_val[0], &scale_val[1]); if (scale_val[0] != val || scale_val[1] != val2) continue; guard(mutex)(&st->lock); ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, - info->scale_table[i][1]); + st->info->scale_table[i][1]); if (ret < 0) return ret; @@ -325,15 +318,15 @@ static int ad9467_set_scale(struct adi_axi_adc_conv *conv, int val, int val2) return -EINVAL; } -static int ad9467_read_raw(struct adi_axi_adc_conv *conv, +static int ad9467_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long m) { - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + struct ad9467_state *st = iio_priv(indio_dev); switch (m) { case IIO_CHAN_INFO_SCALE: - return ad9467_get_scale(conv, val, val2); + return ad9467_get_scale(st, val, val2); case IIO_CHAN_INFO_SAMP_FREQ: *val = clk_get_rate(st->clk); @@ -343,20 +336,19 @@ static int ad9467_read_raw(struct adi_axi_adc_conv *conv, } } -static int ad9467_write_raw(struct adi_axi_adc_conv *conv, +static int ad9467_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - const struct adi_axi_adc_chip_info *info = conv->chip_info; - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + struct ad9467_state *st = iio_priv(indio_dev); long r_clk; switch (mask) { case IIO_CHAN_INFO_SCALE: - return ad9467_set_scale(conv, val, val2); + return ad9467_set_scale(st, val, val2); case IIO_CHAN_INFO_SAMP_FREQ: r_clk = clk_round_rate(st->clk, val); - if (r_clk < 0 || r_clk > info->max_rate) { + if (r_clk < 0 || r_clk > st->info->max_rate) { dev_warn(&st->spi->dev, "Error setting ADC sample rate %ld", r_clk); return -EINVAL; @@ -368,26 +360,53 @@ static int ad9467_write_raw(struct adi_axi_adc_conv *conv, } } -static int ad9467_read_avail(struct adi_axi_adc_conv *conv, +static int ad9467_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, const int **vals, int *type, int *length, long mask) { - const struct adi_axi_adc_chip_info *info = conv->chip_info; - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + struct ad9467_state *st = iio_priv(indio_dev); switch (mask) { case IIO_CHAN_INFO_SCALE: *vals = (const int *)st->scales; *type = IIO_VAL_INT_PLUS_MICRO; /* Values are stored in a 2D matrix */ - *length = info->num_scales * 2; + *length = st->info->num_scales * 2; return IIO_AVAIL_LIST; default: return -EINVAL; } } +static int ad9467_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *scan_mask) +{ + struct ad9467_state *st = iio_priv(indio_dev); + unsigned int c; + int ret; + + for (c = 0; c < st->info->num_channels; c++) { + if (test_bit(c, scan_mask)) + ret = iio_backend_chan_enable(st->back, c); + else + ret = iio_backend_chan_disable(st->back, c); + + if (ret) + return ret; + } + + return 0; +} + +static const struct iio_info ad9467_info = { + .read_raw = ad9467_read_raw, + .write_raw = ad9467_write_raw, + .update_scan_mode = ad9467_update_scan_mode, + .debugfs_reg_access = ad9467_reg_access, + .read_avail = ad9467_read_avail, +}; + static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) { int ret; @@ -400,19 +419,17 @@ static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) AN877_ADC_TRANSFER_SYNC); } -static int ad9467_scale_fill(struct adi_axi_adc_conv *conv) +static int ad9467_scale_fill(struct ad9467_state *st) { - const struct adi_axi_adc_chip_info *info = conv->chip_info; - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); unsigned int i, val1, val2; st->scales = devm_kcalloc(&st->spi->dev, ARRAY_SIZE(*st->scales), - info->num_scales, GFP_KERNEL); + st->info->num_scales, GFP_KERNEL); if (!st->scales) return -ENOMEM; - for (i = 0; i < info->num_scales * 2; i++) { - __ad9467_get_scale(conv, i, &val1, &val2); + for (i = 0; i < st->info->num_scales * 2; i++) { + __ad9467_get_scale(st, i, &val1, &val2); st->scales[i][0] = val1; st->scales[i][1] = val2; } @@ -420,11 +437,27 @@ static int ad9467_scale_fill(struct adi_axi_adc_conv *conv) return 0; } -static int ad9467_preenable_setup(struct adi_axi_adc_conv *conv) +static int ad9467_setup(struct ad9467_state *st) { - struct ad9467_state *st = adi_axi_adc_conv_priv(conv); + struct iio_backend_data_fmt data = { + .sign_extend = true, + .enable = true, + }; + unsigned int c, mode; + int ret; - return ad9467_outputmode_set(st->spi, st->output_mode); + mode = st->info->default_output_mode | AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT; + ret = ad9467_outputmode_set(st->spi, mode); + if (ret) + return ret; + + for (c = 0; c < st->info->num_channels; c++) { + ret = iio_backend_data_format_set(st->back, c, &data); + if (ret) + return ret; + } + + return 0; } static int ad9467_reset(struct device *dev) @@ -444,25 +477,38 @@ static int ad9467_reset(struct device *dev) return 0; } +static int ad9467_buffer_get(struct iio_dev *indio_dev) +{ + struct device *dev = indio_dev->dev.parent; + const char *dma_name; + + if (!device_property_present(dev, "dmas")) + return 0; + + if (device_property_read_string(dev, "dma-names", &dma_name)) + dma_name = "rx"; + + return devm_iio_dmaengine_buffer_setup(dev, indio_dev, dma_name); +} + static int ad9467_probe(struct spi_device *spi) { - const struct ad9467_chip_info *info; - struct adi_axi_adc_conv *conv; + struct iio_dev *indio_dev; struct ad9467_state *st; unsigned int id; int ret; - info = spi_get_device_match_data(spi); - if (!info) - return -ENODEV; - - conv = devm_adi_axi_adc_conv_register(&spi->dev, sizeof(*st)); - if (IS_ERR(conv)) - return PTR_ERR(conv); + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); + if (!indio_dev) + return -ENOMEM; - st = adi_axi_adc_conv_priv(conv); + st = iio_priv(indio_dev); st->spi = spi; + st->info = spi_get_device_match_data(spi); + if (!st->info) + return -ENODEV; + st->clk = devm_clk_get_enabled(&spi->dev, "adc-clk"); if (IS_ERR(st->clk)) return PTR_ERR(st->clk); @@ -476,29 +522,39 @@ static int ad9467_probe(struct spi_device *spi) if (ret) return ret; - conv->chip_info = &info->axi_adc_info; - - ret = ad9467_scale_fill(conv); + ret = ad9467_scale_fill(st); if (ret) return ret; id = ad9467_spi_read(spi, AN877_ADC_REG_CHIP_ID); - if (id != conv->chip_info->id) { + if (id != st->info->id) { dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", - id, conv->chip_info->id); + id, st->info->id); return -ENODEV; } - conv->reg_access = ad9467_reg_access; - conv->write_raw = ad9467_write_raw; - conv->read_raw = ad9467_read_raw; - conv->read_avail = ad9467_read_avail; - conv->preenable_setup = ad9467_preenable_setup; + indio_dev->name = st->info->name; + indio_dev->channels = st->info->channels; + indio_dev->num_channels = st->info->num_channels; + indio_dev->info = &ad9467_info; + + ret = ad9467_buffer_get(indio_dev); + if (ret) + return ret; - st->output_mode = info->default_output_mode | - AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT; + st->back = devm_iio_backend_get(&spi->dev, NULL); + if (IS_ERR(st->back)) + return PTR_ERR(st->back); - return 0; + ret = iio_backend_enable(st->back); + if (ret) + return ret; + + ret = ad9467_setup(st); + if (ret) + return ret; + + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct of_device_id ad9467_of_match[] = { From patchwork Tue Nov 21 10:20:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp521225vqb; Tue, 21 Nov 2023 02:19:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQoMs43Tb0cMVD6e7VrMK/J4oBWyw8Cu9W06T/miw8nTZefhoV8BLhCzMERFjkmASYOP1C X-Received: by 2002:a17:902:ab93:b0:1c1:e7b2:27ad with SMTP id f19-20020a170902ab9300b001c1e7b227admr7122335plr.60.1700561986003; Tue, 21 Nov 2023 02:19:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561985; cv=none; d=google.com; s=arc-20160816; b=jfW1IGsWJa7jWycdO8xfNp3zg4nV8tAfPztA2s1gxwog8Ny0XyYigFgzDSkxUW8JFa dN08ORVkyzGwhEVgU8M4MJt8orH6BLFp7BXC6luoh/xxkLc3XyX9rmFL0XAt5PWiULWv A8FcF56SrTtfa1f5LdRfXpxuMxbOFsUF3zcmArBxsA+OXc1/EqDJbwTmMFHI9KGrHeOj jhZIJAbNRRs3jekLh/uiLqnkes5muxHTY9xalYAjqEnlsVKK7xHbGf4M5MMuzdc4zp0h fbT0JqxI4MLPLBrnsYtDQ4rp3lhXIrrfUU+AC3ep16X6Jf+6Lr8UmW1creF0E2y20FjH H6Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=U3P4aiRVJ9NohViwWTRinPt+sIiuatZWXEcQMdzW4S8=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=Ob9Qrukb+h5PCZ/bvdBoxrTtJiYxxiDUK5FsHz0ohrrrUmZmbeLgufeWaX5Ls/RYMA oSrqBG/bLTcvoyKfO6KZOeFZ35mlntwpVIBn6TaPA007arqc1u9UDWK/2L1gyB1Ugo2g AzN+D6R287Dtkv0r8OiuCdLTFt7tVt6Dn3nNmTVOO8g3gaNRnr18NDBuEuTUejwXRrsT lk3h1bHhjCuSjwrhH4+ZUxC29z6NXvGhQpwgFwjoOM4k1hIJT0/ma9sW3zg3w60V3XvI MNsKWMT1dtpkYDQO27XqRp0Te0uAAqnwNeVtS8vfx6snt29j7Ac4sD/xdptkxlTxkDay NNMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GWHlDPZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t6-20020a1709027fc600b001cc23d2bb92si9530376plb.650.2023.11.21.02.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GWHlDPZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 004E98104F10; Tue, 21 Nov 2023 02:18:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233563AbjKUKSI (ORCPT + 99 others); Tue, 21 Nov 2023 05:18:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230126AbjKUKR0 (ORCPT ); Tue, 21 Nov 2023 05:17:26 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B178C1 for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id D646CC4AF6B; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=w6aQ9dJ5B6A8WMrSgkXahhVY43m64ehi3h3s9hglcJk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=GWHlDPZSag9moXGZ2SzcH0A/BFpBnGgI49r6aKEecwtiepRerBvLc2WjxE+bsRuPx EmMLfyWDFv3usmQmBiEV8+jFvVnCVYEr8iy/I+y0WK1ZrhlBKaOduK/OxR+k34lvic c3iEsL4ph7wQKoBy5x49VtBd2ZGKaW92LIsZS2VfMKR+Kp8i1OUdCgX9PG5EPnuPZ5 A2FPPRPY6sJhGBJQ7oW0+7Nb2Plv0blQ7RrJSgBNTTqsKpOcD+wqAN1RVtjByvXZlZ QmZCMicD1P1L3WZX+U8ZaueS9brtIQMBnSSSLJFcXfDn9VIY7byl3OG8WVZ809coGE Pd/vlxJJEheDw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3C2AC61D93; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:24 +0100 Subject: [PATCH 11/12] iio: adc: adi-axi-adc: convert to regmap MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-11-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=4779; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=witdRDz1cNzA31LTYx4ngUVPfznr1OJ+tr958N00ncU=; b=DJEjy0HuPOzh+OG74+/E+esscrYisc3cu17cYfi2HXQltkRL+4tqKlxaxtoX6hKj2Abj5vCGY 64h0BLWKAdfD/RVpiMXPd7GlHi7hWwnHbrahjFBLOZEPwz/nOSOCS2s X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:18:24 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168484972479029 X-GMAIL-MSGID: 1783168484972479029 From: Nuno Sa Use MMIO regmap interface. It makes things easier for manipulating bits. Signed-off-by: Nuno Sa --- drivers/iio/adc/adi-axi-adc.c | 85 ++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index ae83ada7f9f2..c247ff1541d2 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -62,7 +63,7 @@ struct adi_axi_adc_state { struct mutex lock; struct adi_axi_adc_client *client; - void __iomem *regs; + struct regmap *regmap; }; struct adi_axi_adc_client { @@ -90,19 +91,6 @@ void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv) } EXPORT_SYMBOL_NS_GPL(adi_axi_adc_conv_priv, IIO_ADI_AXI); -static void adi_axi_adc_write(struct adi_axi_adc_state *st, - unsigned int reg, - unsigned int val) -{ - iowrite32(val, st->regs + reg); -} - -static unsigned int adi_axi_adc_read(struct adi_axi_adc_state *st, - unsigned int reg) -{ - return ioread32(st->regs + reg); -} - static int adi_axi_adc_config_dma_buffer(struct device *dev, struct iio_dev *indio_dev) { @@ -163,17 +151,20 @@ static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev, { struct adi_axi_adc_state *st = iio_priv(indio_dev); struct adi_axi_adc_conv *conv = &st->client->conv; - unsigned int i, ctrl; + unsigned int i; + int ret; for (i = 0; i < conv->chip_info->num_channels; i++) { - ctrl = adi_axi_adc_read(st, ADI_AXI_REG_CHAN_CTRL(i)); - if (test_bit(i, scan_mask)) - ctrl |= ADI_AXI_REG_CHAN_CTRL_ENABLE; + ret = regmap_set_bits(st->regmap, + ADI_AXI_REG_CHAN_CTRL(i), + ADI_AXI_REG_CHAN_CTRL_ENABLE); else - ctrl &= ~ADI_AXI_REG_CHAN_CTRL_ENABLE; - - adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), ctrl); + ret = regmap_clear_bits(st->regmap, + ADI_AXI_REG_CHAN_CTRL(i), + ADI_AXI_REG_CHAN_CTRL_ENABLE); + if (ret) + return ret; } return 0; @@ -310,21 +301,32 @@ static int adi_axi_adc_setup_channels(struct device *dev, } for (i = 0; i < conv->chip_info->num_channels; i++) { - adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), - ADI_AXI_REG_CHAN_CTRL_DEFAULTS); + ret = regmap_write(st->regmap, ADI_AXI_REG_CHAN_CTRL(i), + ADI_AXI_REG_CHAN_CTRL_DEFAULTS); + if (ret) + return ret; } return 0; } -static void axi_adc_reset(struct adi_axi_adc_state *st) +static int axi_adc_reset(struct adi_axi_adc_state *st) { - adi_axi_adc_write(st, ADI_AXI_REG_RSTN, 0); + int ret; + + ret = regmap_write(st->regmap, ADI_AXI_REG_RSTN, 0); + if (ret) + return ret; + mdelay(10); - adi_axi_adc_write(st, ADI_AXI_REG_RSTN, ADI_AXI_REG_RSTN_MMCM_RSTN); + ret = regmap_write(st->regmap, ADI_AXI_REG_RSTN, + ADI_AXI_REG_RSTN_MMCM_RSTN); + if (ret) + return ret; + mdelay(10); - adi_axi_adc_write(st, ADI_AXI_REG_RSTN, - ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN); + return regmap_write(st->regmap, ADI_AXI_REG_RSTN, + ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN); } static void adi_axi_adc_cleanup(void *data) @@ -335,12 +337,20 @@ static void adi_axi_adc_cleanup(void *data) module_put(cl->dev->driver->owner); } +static const struct regmap_config axi_adc_regmap_config = { + .val_bits = 32, + .reg_bits = 32, + .reg_stride = 4, + .max_register = 0x0800, +}; + static int adi_axi_adc_probe(struct platform_device *pdev) { struct adi_axi_adc_conv *conv; struct iio_dev *indio_dev; struct adi_axi_adc_client *cl; struct adi_axi_adc_state *st; + void __iomem *base; unsigned int ver; int ret; @@ -361,15 +371,24 @@ static int adi_axi_adc_probe(struct platform_device *pdev) cl->state = st; mutex_init(&st->lock); - st->regs = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(st->regs)) - return PTR_ERR(st->regs); + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + st->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &axi_adc_regmap_config); + if (IS_ERR(st->regmap)) + return PTR_ERR(st->regmap); conv = &st->client->conv; - axi_adc_reset(st); + ret = axi_adc_reset(st); + if (ret) + return ret; - ver = adi_axi_adc_read(st, ADI_AXI_REG_VERSION); + ret = regmap_read(st->regmap, ADI_AXI_REG_VERSION, &ver); + if (ret) + return ret; if (cl->info->version > ver) { dev_err(&pdev->dev, From patchwork Tue Nov 21 10:20:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 167622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp521238vqb; Tue, 21 Nov 2023 02:19:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgC+CGqqlED8/DThhJBAiDXA/fI5Zd7UHe507eJBmKEy2hoxIW4J0MpgXBvec+viYI5ZmH X-Received: by 2002:a05:6a00:8e03:b0:6be:1f19:e5f0 with SMTP id io3-20020a056a008e0300b006be1f19e5f0mr12127950pfb.25.1700561989626; Tue, 21 Nov 2023 02:19:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700561989; cv=none; d=google.com; s=arc-20160816; b=Mg1Iq80HxBBnJtHaaa5Gw1AVRAKoYBdbwqIYgyPLU1qGl5YhGqYHh+8hfMieKv/9qv e+BUz8BXFG4wiIknkZTJZfDlCPd2eMZuz8AOlRp25U0ZYTigzpR15TiTmtkdfq5WC54x DasHQGwPDpJmOCupezupRytD/9Ure7FYe/7l9UZI5VcX0tLskl/+Qn2yo84t8snqprZk dAtssyZuazGcZFwSumbsXXaJt0YxnmqR+pr52EdyeQBk2iCLGnfKQV/O9m07T0gkq19N boZlYYC04vjRpDvmG+2OqgWaI9klb9hzphmiIBmh0E6r8PVtuLOmvU67kJraJEqF2uqd FeoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=cHHXfxumnUe3RrG2KWkqOsYugvSXemZAGg5kr0v7mkQ=; fh=phDggtdq/mZScnogaJFJfeRDE2XPpZpUuxL35p15uks=; b=OdboXy7sVAT7kzToc+uVJMHqOXAgJQ6V6RvBGHEerbCixaHu7r6LmgGQG5ut1X9flE sxmnhW9dFzdKNeDvFp+9JJCrLNkm+CAUDvZwnLgXInaAb8i9W8KnEN+chpCBL7jTn+1U JunnfmdaF1vguZu5IYWuLCA9qgGG1PXA/s7+8SniZW2WvkxAOEasRg9ghMeSlZemZOtf B1CqhjI8D7PXmHjekFVpSArYsTBl3r0fEgVbphaFAcZfx8usHKJgcJU2AphUuAMEfoSK Lz0XIbgfRoR33g97Ao+vP2Fzc8jgeexHWfmnoFfXGax7pvQHEbjomJgdR2xmLPmjsCqp qFMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fwe9uYhz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cm11-20020a056a020a0b00b005be30c35ef7si10945102pgb.162.2023.11.21.02.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 02:19:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fwe9uYhz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4EBED8104F28; Tue, 21 Nov 2023 02:18:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233677AbjKUKSK (ORCPT + 99 others); Tue, 21 Nov 2023 05:18:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233476AbjKUKR1 (ORCPT ); Tue, 21 Nov 2023 05:17:27 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FFE8116 for ; Tue, 21 Nov 2023 02:17:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPS id E4672C4166B; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700561839; bh=KodMV26ca7GEsuJL/H7lYOP+04Qx83r0peydFy3c6MQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fwe9uYhzIqmrRqK9wt18UCOBkVNVij2q0PungQuybNWZZIZzyhYyoAf7TMLMrNJi/ xm4gSEKxCPXrBZKIjzRpEov0/BGtCJnrq7IhqS1EraucS5kM8z2cetrnMnPwTHC1iE xwKUzQFF+w3khqGOewdieatwP0nKQEf4XcKoUoA5Gi5nIU1cvW7V3d1nYbm/7eaMej +pH9ESw63UqUKd0DCAWm+jbX8Bk6Z4QNCaVAr/bvqZ/88ZXOadGta/AlHJXCBl6Wx0 2dKWXUUJKVB2I+UvJjoqmlS0vo2h66StZhQY9600j1R2iJMVQrY/iMIZbgdkHge5Xr b8mFo+8JLdMxw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D34AFC54FB9; Tue, 21 Nov 2023 10:17:19 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Tue, 21 Nov 2023 11:20:25 +0100 Subject: [PATCH 12/12] iio: adc: adi-axi-adc: move to backend framework MIME-Version: 1.0 Message-Id: <20231121-dev-iio-backend-v1-12-6a3d542eba35@analog.com> References: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> In-Reply-To: <20231121-dev-iio-backend-v1-0-6a3d542eba35@analog.com> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: Olivier MOYSAN , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Nuno Sa X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1700562016; l=14337; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=+u9HWUghl/248aJnsS8FrYOYG77gZgAnQv1PFeCSO1s=; b=tbqLWeExJMbjJ/4v6zWrjsAg+GNKLGrbhle82T3llI4pz3kYW9UZcgrhxLSENOUaDU8Pte51H VjmpMCFmNUGCrZPHQUSqQiiq8POYbUf5lsNEjVz6alFQaRrCxEgcStS X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 02:18:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783168488683988835 X-GMAIL-MSGID: 1783168488683988835 From: Nuno Sa Move to the IIO backend framework. Devices supported by adi-axi-adc now register themselves as backend devices. Signed-off-by: Nuno Sa --- drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/adi-axi-adc.c | 364 ++++++++---------------------------------- 2 files changed, 65 insertions(+), 300 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index af56df63beff..cc42a3399c63 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -292,6 +292,7 @@ config ADI_AXI_ADC select IIO_BUFFER select IIO_BUFFER_HW_CONSUMER select IIO_BUFFER_DMAENGINE + select IIO_BACKEND depends on HAS_IOMEM depends on OF help diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index c247ff1541d2..b2ab2c119efa 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -17,13 +17,9 @@ #include #include -#include -#include -#include -#include - #include -#include +#include + /* * Register definitions: @@ -44,6 +40,7 @@ #define ADI_AXI_REG_CHAN_CTRL_PN_SEL_OWR BIT(10) #define ADI_AXI_REG_CHAN_CTRL_IQCOR_EN BIT(9) #define ADI_AXI_REG_CHAN_CTRL_DCFILT_EN BIT(8) +#define ADI_AXI_REG_CHAN_CTRL_FMT_MASK GENMASK(6, 4) #define ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT BIT(6) #define ADI_AXI_REG_CHAN_CTRL_FMT_TYPE BIT(5) #define ADI_AXI_REG_CHAN_CTRL_FMT_EN BIT(4) @@ -55,286 +52,67 @@ ADI_AXI_REG_CHAN_CTRL_FMT_EN | \ ADI_AXI_REG_CHAN_CTRL_ENABLE) -struct adi_axi_adc_core_info { - unsigned int version; -}; - struct adi_axi_adc_state { - struct mutex lock; - - struct adi_axi_adc_client *client; struct regmap *regmap; }; -struct adi_axi_adc_client { - struct list_head entry; - struct adi_axi_adc_conv conv; - struct adi_axi_adc_state *state; - struct device *dev; - const struct adi_axi_adc_core_info *info; -}; - -static LIST_HEAD(registered_clients); -static DEFINE_MUTEX(registered_clients_lock); - -static struct adi_axi_adc_client *conv_to_client(struct adi_axi_adc_conv *conv) -{ - return container_of(conv, struct adi_axi_adc_client, conv); -} - -void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv) -{ - struct adi_axi_adc_client *cl = conv_to_client(conv); - - return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client), - IIO_DMA_MINALIGN); -} -EXPORT_SYMBOL_NS_GPL(adi_axi_adc_conv_priv, IIO_ADI_AXI); - -static int adi_axi_adc_config_dma_buffer(struct device *dev, - struct iio_dev *indio_dev) -{ - const char *dma_name; - - if (!device_property_present(dev, "dmas")) - return 0; - - if (device_property_read_string(dev, "dma-names", &dma_name)) - dma_name = "rx"; - - return devm_iio_dmaengine_buffer_setup(indio_dev->dev.parent, - indio_dev, dma_name); -} - -static int adi_axi_adc_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) -{ - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - - if (!conv->read_raw) - return -EOPNOTSUPP; - - return conv->read_raw(conv, chan, val, val2, mask); -} - -static int adi_axi_adc_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) -{ - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - - if (!conv->write_raw) - return -EOPNOTSUPP; - - return conv->write_raw(conv, chan, val, val2, mask); -} - -static int adi_axi_adc_read_avail(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - const int **vals, int *type, int *length, - long mask) -{ - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - - if (!conv->read_avail) - return -EOPNOTSUPP; - - return conv->read_avail(conv, chan, vals, type, length, mask); -} - -static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *scan_mask) -{ - struct adi_axi_adc_state *st = iio_priv(indio_dev); - struct adi_axi_adc_conv *conv = &st->client->conv; - unsigned int i; - int ret; - - for (i = 0; i < conv->chip_info->num_channels; i++) { - if (test_bit(i, scan_mask)) - ret = regmap_set_bits(st->regmap, - ADI_AXI_REG_CHAN_CTRL(i), - ADI_AXI_REG_CHAN_CTRL_ENABLE); - else - ret = regmap_clear_bits(st->regmap, - ADI_AXI_REG_CHAN_CTRL(i), - ADI_AXI_REG_CHAN_CTRL_ENABLE); - if (ret) - return ret; - } - - return 0; -} - -static struct adi_axi_adc_conv *adi_axi_adc_conv_register(struct device *dev, - size_t sizeof_priv) -{ - struct adi_axi_adc_client *cl; - size_t alloc_size; - - alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_DMA_MINALIGN); - if (sizeof_priv) - alloc_size += ALIGN(sizeof_priv, IIO_DMA_MINALIGN); - - cl = kzalloc(alloc_size, GFP_KERNEL); - if (!cl) - return ERR_PTR(-ENOMEM); - - mutex_lock(®istered_clients_lock); - - cl->dev = get_device(dev); - - list_add_tail(&cl->entry, ®istered_clients); - - mutex_unlock(®istered_clients_lock); - - return &cl->conv; -} - -static void adi_axi_adc_conv_unregister(struct adi_axi_adc_conv *conv) -{ - struct adi_axi_adc_client *cl = conv_to_client(conv); - - mutex_lock(®istered_clients_lock); - - list_del(&cl->entry); - put_device(cl->dev); - - mutex_unlock(®istered_clients_lock); - - kfree(cl); -} - -static void devm_adi_axi_adc_conv_release(void *conv) -{ - adi_axi_adc_conv_unregister(conv); -} - -struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev, - size_t sizeof_priv) +static int axi_adc_enable(struct iio_backend *back) { - struct adi_axi_adc_conv *conv; + struct adi_axi_adc_state *st = iio_backend_get_priv(back); int ret; - conv = adi_axi_adc_conv_register(dev, sizeof_priv); - if (IS_ERR(conv)) - return conv; - - ret = devm_add_action_or_reset(dev, devm_adi_axi_adc_conv_release, - conv); + ret = regmap_set_bits(st->regmap, ADI_AXI_REG_RSTN, + ADI_AXI_REG_RSTN_MMCM_RSTN); if (ret) - return ERR_PTR(ret); + return ret; - return conv; + fsleep(10); + return regmap_set_bits(st->regmap, ADI_AXI_REG_RSTN, + ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN); } -EXPORT_SYMBOL_NS_GPL(devm_adi_axi_adc_conv_register, IIO_ADI_AXI); -static const struct iio_info adi_axi_adc_info = { - .read_raw = &adi_axi_adc_read_raw, - .write_raw = &adi_axi_adc_write_raw, - .update_scan_mode = &adi_axi_adc_update_scan_mode, - .read_avail = &adi_axi_adc_read_avail, -}; - -static const struct adi_axi_adc_core_info adi_axi_adc_10_0_a_info = { - .version = ADI_AXI_PCORE_VER(10, 0, 'a'), -}; - -static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev) +static void axi_adc_disable(struct iio_backend *back) { - const struct adi_axi_adc_core_info *info; - struct adi_axi_adc_client *cl; - struct device_node *cln; - - info = of_device_get_match_data(dev); - if (!info) - return ERR_PTR(-ENODEV); - - cln = of_parse_phandle(dev->of_node, "adi,adc-dev", 0); - if (!cln) { - dev_err(dev, "No 'adi,adc-dev' node defined\n"); - return ERR_PTR(-ENODEV); - } - - mutex_lock(®istered_clients_lock); - - list_for_each_entry(cl, ®istered_clients, entry) { - if (!cl->dev) - continue; - - if (cl->dev->of_node != cln) - continue; + struct adi_axi_adc_state *st = iio_backend_get_priv(back); - if (!try_module_get(cl->dev->driver->owner)) { - mutex_unlock(®istered_clients_lock); - of_node_put(cln); - return ERR_PTR(-ENODEV); - } - - get_device(cl->dev); - cl->info = info; - mutex_unlock(®istered_clients_lock); - of_node_put(cln); - return cl; - } - - mutex_unlock(®istered_clients_lock); - of_node_put(cln); - - return ERR_PTR(-EPROBE_DEFER); + regmap_write(st->regmap, ADI_AXI_REG_RSTN, 0); } -static int adi_axi_adc_setup_channels(struct device *dev, - struct adi_axi_adc_state *st) +static int axi_adc_data_format_set(struct iio_backend *back, unsigned int chan, + const struct iio_backend_data_fmt *data) { - struct adi_axi_adc_conv *conv = &st->client->conv; - int i, ret; + struct adi_axi_adc_state *st = iio_backend_get_priv(back); + u32 val; - if (conv->preenable_setup) { - ret = conv->preenable_setup(conv); - if (ret) - return ret; - } + if (!data->enable) + return regmap_clear_bits(st->regmap, + ADI_AXI_REG_CHAN_CTRL(chan), + ADI_AXI_REG_CHAN_CTRL_FMT_EN); - for (i = 0; i < conv->chip_info->num_channels; i++) { - ret = regmap_write(st->regmap, ADI_AXI_REG_CHAN_CTRL(i), - ADI_AXI_REG_CHAN_CTRL_DEFAULTS); - if (ret) - return ret; - } + val = FIELD_PREP(ADI_AXI_REG_CHAN_CTRL_FMT_EN, true); + if (data->sign_extend) + val |= FIELD_PREP(ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT, true); + if (data->type == IIO_BACKEND_OFFSET_BINARY) + val |= FIELD_PREP(ADI_AXI_REG_CHAN_CTRL_FMT_TYPE, true); - return 0; + return regmap_update_bits(st->regmap, ADI_AXI_REG_CHAN_CTRL(chan), + ADI_AXI_REG_CHAN_CTRL_FMT_MASK, val); } -static int axi_adc_reset(struct adi_axi_adc_state *st) +static int axi_adc_chan_enable(struct iio_backend *back, unsigned int chan) { - int ret; + struct adi_axi_adc_state *st = iio_backend_get_priv(back); - ret = regmap_write(st->regmap, ADI_AXI_REG_RSTN, 0); - if (ret) - return ret; - - mdelay(10); - ret = regmap_write(st->regmap, ADI_AXI_REG_RSTN, - ADI_AXI_REG_RSTN_MMCM_RSTN); - if (ret) - return ret; - - mdelay(10); - return regmap_write(st->regmap, ADI_AXI_REG_RSTN, - ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN); + return regmap_set_bits(st->regmap, ADI_AXI_REG_CHAN_CTRL(chan), + ADI_AXI_REG_CHAN_CTRL_ENABLE); } -static void adi_axi_adc_cleanup(void *data) +static int axi_adc_chan_disable(struct iio_backend *back, unsigned int chan) { - struct adi_axi_adc_client *cl = data; + struct adi_axi_adc_state *st = iio_backend_get_priv(back); - put_device(cl->dev); - module_put(cl->dev->driver->owner); + return regmap_clear_bits(st->regmap, ADI_AXI_REG_CHAN_CTRL(chan), + ADI_AXI_REG_CHAN_CTRL_ENABLE); } static const struct regmap_config axi_adc_regmap_config = { @@ -344,33 +122,25 @@ static const struct regmap_config axi_adc_regmap_config = { .max_register = 0x0800, }; +static const struct iio_backend_ops adi_axi_adc_generic = { + .enable = axi_adc_enable, + .disable = axi_adc_disable, + .data_format_set = axi_adc_data_format_set, + .chan_enable = axi_adc_chan_enable, + .chan_disable = axi_adc_chan_disable, +}; + static int adi_axi_adc_probe(struct platform_device *pdev) { - struct adi_axi_adc_conv *conv; - struct iio_dev *indio_dev; - struct adi_axi_adc_client *cl; struct adi_axi_adc_state *st; void __iomem *base; - unsigned int ver; + unsigned int ver, *expected_ver; int ret; - cl = adi_axi_adc_attach_client(&pdev->dev); - if (IS_ERR(cl)) - return PTR_ERR(cl); - - ret = devm_add_action_or_reset(&pdev->dev, adi_axi_adc_cleanup, cl); - if (ret) - return ret; - - indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st)); - if (indio_dev == NULL) + st = devm_kzalloc(&pdev->dev, sizeof(*st), GFP_KERNEL); + if (!st) return -ENOMEM; - st = iio_priv(indio_dev); - st->client = cl; - cl->state = st; - mutex_init(&st->lock); - base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(base)) return PTR_ERR(base); @@ -380,9 +150,15 @@ static int adi_axi_adc_probe(struct platform_device *pdev) if (IS_ERR(st->regmap)) return PTR_ERR(st->regmap); - conv = &st->client->conv; + expected_ver = (unsigned int *)device_get_match_data(&pdev->dev); + if (!expected_ver) + return -ENODEV; - ret = axi_adc_reset(st); + /* + * Force disable the core. Up to the frontend to enable us. And we can + * still read/write registers... + */ + ret = regmap_write(st->regmap, ADI_AXI_REG_RSTN, 0); if (ret) return ret; @@ -390,37 +166,23 @@ static int adi_axi_adc_probe(struct platform_device *pdev) if (ret) return ret; - if (cl->info->version > ver) { + if (*expected_ver > ver) { dev_err(&pdev->dev, "IP core version is too old. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n", - ADI_AXI_PCORE_VER_MAJOR(cl->info->version), - ADI_AXI_PCORE_VER_MINOR(cl->info->version), - ADI_AXI_PCORE_VER_PATCH(cl->info->version), + ADI_AXI_PCORE_VER_MAJOR(*expected_ver), + ADI_AXI_PCORE_VER_MINOR(*expected_ver), + ADI_AXI_PCORE_VER_PATCH(*expected_ver), ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), ADI_AXI_PCORE_VER_PATCH(ver)); return -ENODEV; } - indio_dev->info = &adi_axi_adc_info; - indio_dev->name = "adi-axi-adc"; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->num_channels = conv->chip_info->num_channels; - indio_dev->channels = conv->chip_info->channels; - - ret = adi_axi_adc_config_dma_buffer(&pdev->dev, indio_dev); + ret = devm_iio_backend_register(&pdev->dev, &adi_axi_adc_generic, st); if (ret) return ret; - ret = adi_axi_adc_setup_channels(&pdev->dev, st); - if (ret) - return ret; - - ret = devm_iio_device_register(&pdev->dev, indio_dev); - if (ret) - return ret; - - dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%c) probed\n", + dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%d) probed\n", ADI_AXI_PCORE_VER_MAJOR(ver), ADI_AXI_PCORE_VER_MINOR(ver), ADI_AXI_PCORE_VER_PATCH(ver)); @@ -428,6 +190,8 @@ static int adi_axi_adc_probe(struct platform_device *pdev) return 0; } +static unsigned int adi_axi_adc_10_0_a_info = ADI_AXI_PCORE_VER(10, 0, 'a'); + /* Match table for of_platform binding */ static const struct of_device_id adi_axi_adc_of_match[] = { { .compatible = "adi,axi-adc-10.0.a", .data = &adi_axi_adc_10_0_a_info },