From patchwork Mon Mar 10 12:55:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 872527 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F407A3EA76; Mon, 10 Mar 2025 12:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611365; cv=none; b=Ez8u30hPSD3qrsb4ilpjNgrbzKyytj/Oq7C2oxmOqKdrk+75KUSKlHw/2GNAfM1zLu4+BUC3hfqxk9m0knQ4vt5znBiKFt688LNMwuu1rOgxvf7mFGg2ihZN/BaRGohUhAVwxanzxv9Pexjp+eMnpt/ntEeCLhtYZJ8UB1MmxOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611365; c=relaxed/simple; bh=W50C9myyD+f04dNjjlf3vCz4lf/WRKAWpjph/AEznqo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AtlIBXBifl2aU4+cE5A7VV24riJgFfIZmAz/tkFLSu+Pr7PESKMFaHUNofhQhcisT1oF5+CvRjSiNN42V2JMkirBTi2cebPh/FE1th1tIb3qtkBYldlKoIK3NNSvOeXnFM97mBC9nvY0rCGooAv7KWldDMfgk7gGYQZDKOrDk2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KTKkoM9E; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KTKkoM9E" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5499bd3084aso1860989e87.0; Mon, 10 Mar 2025 05:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741611362; x=1742216162; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=tqSie8Pu9UlkmTVB8KCTPHYG/3Uxc6sn89mUIbchqHc=; b=KTKkoM9Et51nyvxx4sHogZU+DMTla7Dv+5oNIhpdIOj9TmXYAFtKytwxzsL1GTUjcZ UtL+dv6n0k0wvUSakkuIDHdtWFR8kNHlVq7xhrFKtxyl4G+H6XXf6tq8dRPFNRKrq+SP HZtvXcVbB0kQXuXMEiJWyQgwsHOoEDCtYkhIs+Tty2rCsfRJWs0LvuqGZva2ilGXc7Lo x/B85THYWzWrnf6chu1Vj4IS8khoEMT2JrL/h9cf9mgL5kGqEXYMjLq/2pCxeIUqDMmU st+8NKJRO276RcmnOvd9z0kHJyasth8WSY3uKL4NeYNDnAnHWL/7ZytrtjmXgLATO71n x/7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741611362; x=1742216162; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tqSie8Pu9UlkmTVB8KCTPHYG/3Uxc6sn89mUIbchqHc=; b=CIctrukcSMpBfZIb57zjRb6uXDia0TNXGSEgbveRXqOzfgjxUQspGpdmJtfgac4Srp JB1KSCmeVptgOUfEBBT8OraVlJIwaO6ZA2OTvG2hEIuZeluvarqPGDXqcUngsv/GECdw uVqGEnaWEaFHoWw5Wc+ZfKiUp3MUDewuM/65IO0y2W2SiNTc7eXBwNgEe4OYtenINn2y PrwtoStKlvYGI04UTArlvtrUM8qTdHP7qZMUlIGpgE2FHrd07dYRsmzRZ9tAVSktJJJS aus1Afwt4vvNM0ApOSa/aiG93AGx/tvWD5/0FfIt80a2lmxGRFkUlDSWfaxi60zYwXxl OLGg== X-Forwarded-Encrypted: i=1; AJvYcCV0W9jHQrvZz8cQMxBHBpbSYDLv4M+GZGci5bsPQD+YSGvUosLrO7I4PItiRDXjhtV0U/3MUFdj@vger.kernel.org, AJvYcCVAKb1VCeHtYhms3+IvpqsJN1NXVGnR6y1kILWKZci8HChofvrZjhZlc1qypwCsB/kNwA3ocCSPN3ytBg==@vger.kernel.org, AJvYcCVAyIYVJnBgqH6jYAQjt1yM07ktp0QZjGVqFj0yzK0mrZxEkh3kbseN/2ILzwARQCy4F1gduu1sQwFX@vger.kernel.org, AJvYcCW1WLDoWz95LLjUhRAC2xgwt3NWCPJH8KOqPKoZ/Fcekrjqz+GLCDxAOwc+jDgWqo/IqenQzyhcNmMAKnw5@vger.kernel.org, AJvYcCWuXt+Ic+6LI+7e33mD0wyKRcNoEkBedLm/8xWG973zgDIuLKOxno6KACIXGOADM/H+8EcZ58bbeh4u@vger.kernel.org X-Gm-Message-State: AOJu0YxqrqHJeZnlbVLx4rOuHiwe+aF8mWiEhca9QKE2PRIj1WEsmAzl QtivqUeujaNp61XEsK6NLonTNoeYRp1w4GIFP7yBqMW8s+TEs5WF X-Gm-Gg: ASbGncvN1XJdZoe9wi2qDpwlcLEoWpDlaVVyC9qtS6H4NXBRoTIjiceNj9aBFFDiu1I TDUCahE4/SxF78MtwQkB1EYVUmWNm8Ah2/FXzR7xw7CwHhRb66IaQrrP9v4hxbaPCkNPNApswds ms0Pz//8iAsrKurpp8FErOjnjqKdLtZ9a9RNqNu98jiW4vO+dD3lyNI4JmT2CmEtitNfm96ttAA PBE0jOf72tJLrlvKc2mlWSoz1l5qYMzqAf4BXsuHSN1JT6MPyxvJSktB9KvOiqvwrcjc6MhLguh 7iSXnjJk9k8JBCJguixKRaRdEAMhSajUArVh6BTlnMWTPJu05W0= X-Google-Smtp-Source: AGHT+IGhZSWHAvtCtWF+S1BsjEkbqrkDYmcIb4DzzzZPqCMUNu5kqWN7ZmWqkl/XnpG1SgIQ2+ZSNg== X-Received: by 2002:a05:6512:3e2a:b0:545:114a:5618 with SMTP id 2adb3069b0e04-54990e29ba2mr4430176e87.7.1741611361580; Mon, 10 Mar 2025 05:56:01 -0700 (PDT) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5498b1c33f1sm1442139e87.226.2025.03.10.05.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 05:56:00 -0700 (PDT) Date: Mon, 10 Mar 2025 14:55:53 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Matti Vaittinen , Claudiu Manoil , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v6 02/10] property: Add functions to iterate named child Message-ID: References: Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are a few use-cases where child nodes with a specific name need to be parsed. Code like: fwnode_for_each_child_node() if (fwnode_name_eq()) ... can be found from a various drivers/subsystems. Adding a macro for this can simplify things a bit. In a few cases the data from the found nodes is later added to an array, which is allocated based on the number of found nodes. One example of such use is the IIO subsystem's ADC channel nodes, where the relevant nodes are named as channel[@N]. Add a helpers for iterating and counting device's sub-nodes with certain name instead, of open-coding this in every user. Suggested-by: Jonathan Cameron Signed-off-by: Matti Vaittinen --- Revision history: v5 => v6: - Add helpers to also iterate through the nodes. v4 => v5: - Use given name instead of string 'channel' when counting the nodes - Add also fwnode_get_child_node_count_named() as suggested by Rob. v3 => v4: - New patch as suggested by Jonathan, see discussion in: https://lore.kernel.org/lkml/20250223161338.5c896280@jic23-huawei/ Please note, the checkpatch.pl was not happy about the for_each...() macros. I tried to make them to follow the existing convention. I am open to suggestions how to improve. --- drivers/base/property.c | 54 ++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 20 +++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index c1392743df9c..335262a894f4 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -945,6 +945,60 @@ unsigned int device_get_child_node_count(const struct device *dev) } EXPORT_SYMBOL_GPL(device_get_child_node_count); +/** + * fwnode_get_named_child_node_count - number of child nodes with given name + * @fwnode: Node which child nodes are counted. + * @name: String to match child node name against. + * + * Scan child nodes and count all the nodes with a specific name. Return the + * number of found nodes. Potential '@number' -ending for scanned names is + * ignored. Eg, + * device_get_child_node_count(dev, "channel"); + * would match all the nodes: + * channel { }, channel@0 {}, channel@0xabba {}... + * + * Return: the number of child nodes with a matching name for a given device. + */ +unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode, + const char *name) +{ + struct fwnode_handle *child; + unsigned int count = 0; + + fwnode_for_each_named_child_node(fwnode, child, name) + count++; + + return count; +} +EXPORT_SYMBOL_GPL(fwnode_get_named_child_node_count); + +/** + * device_get_named_child_node_count - number of child nodes with given name + * @dev: Device to count the child nodes for. + * @name: String to match child node name against. + * + * Scan device's child nodes and find all the nodes with a specific name and + * return the number of found nodes. Potential '@number' -ending for scanned + * names is ignored. Eg, + * device_get_child_node_count(dev, "channel"); + * would match all the nodes: + * channel { }, channel@0 {}, channel@0xabba {}... + * + * Return: the number of child nodes with a matching name for a given device. + */ +unsigned int device_get_named_child_node_count(const struct device *dev, + const char *name) +{ + struct fwnode_handle *child; + unsigned int count = 0; + + device_for_each_named_child_node(dev, child, name) + count++; + + return count; +} +EXPORT_SYMBOL_GPL(device_get_named_child_node_count); + bool device_dma_supported(const struct device *dev) { return fwnode_call_bool_op(dev_fwnode(dev), device_dma_supported); diff --git a/include/linux/property.h b/include/linux/property.h index e214ecd241eb..6dd9ae83e9a5 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -167,10 +167,18 @@ struct fwnode_handle *fwnode_get_next_available_child_node( for (child = fwnode_get_next_child_node(fwnode, NULL); child; \ child = fwnode_get_next_child_node(fwnode, child)) +#define fwnode_for_each_named_child_node(fwnode, child, name) \ + fwnode_for_each_child_node(fwnode, child) \ + if (!fwnode_name_eq(child, name)) { } else + #define fwnode_for_each_available_child_node(fwnode, child) \ for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\ child = fwnode_get_next_available_child_node(fwnode, child)) +#define fwnode_for_each_available_named_child_node(fwnode, child, name) \ + fwnode_for_each_available_child_node(fwnode, child) \ + if (!fwnode_name_eq(child, name)) { } else + struct fwnode_handle *device_get_next_child_node(const struct device *dev, struct fwnode_handle *child); @@ -178,11 +186,19 @@ struct fwnode_handle *device_get_next_child_node(const struct device *dev, for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child)) +#define device_for_each_named_child_node(dev, child, name) \ + device_for_each_child_node(dev, child) \ + if (!fwnode_name_eq(child, name)) { } else + #define device_for_each_child_node_scoped(dev, child) \ for (struct fwnode_handle *child __free(fwnode_handle) = \ device_get_next_child_node(dev, NULL); \ child; child = device_get_next_child_node(dev, child)) +#define device_for_each_named_child_node_scoped(dev, child, name) \ + device_for_each_child_node_scoped(dev, child) \ + if (!fwnode_name_eq(child, name)) { } else + struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode, const char *childname); struct fwnode_handle *device_get_named_child_node(const struct device *dev, @@ -209,6 +225,10 @@ int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); unsigned int device_get_child_node_count(const struct device *dev); +unsigned int fwnode_get_named_child_node_count(const struct fwnode_handle *fwnode, + const char *name); +unsigned int device_get_named_child_node_count(const struct device *dev, + const char *name); static inline int device_property_read_u8(const struct device *dev, const char *propname, u8 *val) From patchwork Mon Mar 10 12:56:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 872234 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 134A7227E98; Mon, 10 Mar 2025 12:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611381; cv=none; b=UZQV6ckTjHAeBCbK9SUIL7ql1fPhPuigFoEHZjjpK4OQ7jEY0TAWpS+DegG4/jciR/9qWKcSipQYQmVtovOCjG5OI8VoqxbyrlbaCZ5QVP+MJf9AKgTvS2Psn4PgFfeDObpfCxx48GQkRe5KfrVf1X2FLS8su1FVK93gJ6bSdis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611381; c=relaxed/simple; bh=g0jZnLSa9pPHhKusFdn4qSS/J9LINnm5/xWCLl9Nvbk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tOtTakosq8ABJ2E/O1wagu27qW+/zKQmWl8IQVr93aJmBOggkM4e44gxZwV39RkH8FLMCuv7+jimdB+Ti9nvrESeBMJNo8KPjJSPePCUwqA8waslFlqGytuUuMATiUSpVJmYc38CRLGsfkVkOJCIzZ1GexBikeyWPO7+s2OHszo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hGDfJapK; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hGDfJapK" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-548409cd2a8so4068162e87.3; Mon, 10 Mar 2025 05:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741611377; x=1742216177; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pvlmIYXxPFwsgRKDsD0xfbB0Kf2m77owf2uPI4W2MCQ=; b=hGDfJapKBx0x5za59h3IcvoO5PmJQRK3Ay32tx2/7gHmt5Zv50t/awOyVc599VURDd Nyo0SH0vaYppHqjvkBFDApgQ/TWENdyXS7fVIZLxsy7bKYB6REd6o/ul1UWegXcabJt1 QTWJ5Qy+DxeNhZdYxYMx0jsfCxl7jNLOmnn21nfFyFvtjxviBMKmO6YY5IFOM+4eZ3eT HvlW4fh1VxbL0gKjmo49XK+3rBjwefFPrLNl00xdib3sueX56UTYvD7tdnBkBK5CRN4f 3FfLMV8QkXzX6eC05XGO5FRVkG7qXJzUK52CoW7g1bz7JALlEM9TrPEuHsqbNXA3IhPa 06ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741611377; x=1742216177; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pvlmIYXxPFwsgRKDsD0xfbB0Kf2m77owf2uPI4W2MCQ=; b=hUzCxDmkGxZFImu+NrYqV2XJxF0KEy2wvgG3EJgeywxlLO66lQoeCu1b3V4hFbjrxj SJtXXtx9AcQyX+8vSnaNeU31KlDXoo0cYzx375ZW7trHUio0/z3YQGgioxHvyO056u2P xkx1u8OqizSWhMLnd8Ozmu/Y46AC88Uczh1poD5EiiJObo0T+kOKYPz4UB23c+Mw91e+ MWeew2rgTjqwTvYkot/SXrgNCKyg3DKZae/2dGIpcg5YfK1DFGE2OBpMkUA83b0LogKW MbZExNVsckI5DasF2v0JUO7zxUQTBfFcEB8IfMYS9YvKCFWrHqKhpXO6bCPbxpwEpYsS AsMA== X-Forwarded-Encrypted: i=1; AJvYcCU2oaDJcfkztReulQ81peYT2Vtyc+QSaoH6lVTLilVgdMZxDJTrdAQGjcgs40Ad/HtomLDKSsEd7LWK@vger.kernel.org, AJvYcCUkhxM9oJ7mDt7jL7fr/GJw3HU0B2dJF1u+QeskqwV+blexbt9pOAfYUEe46LDdOCf6ETvLGrzQe/24Ng==@vger.kernel.org, AJvYcCVYfPVIS6Pn9AkoV34OdhxyB8bVoJpv0berOnyVZ6aWdZwH7Jb2kUOYNrv/iPBk037FsGMe2eouYLN/3OOD@vger.kernel.org, AJvYcCVq7vQ6WTAO3kB9NruOVyz5g7ekuplzghgzNYZ2jgupYWntZ0oPLg9xBe8KWK0lR8mWqBUS7bClnXVFbXaCtqC0KBY=@vger.kernel.org, AJvYcCXfxKLRgbiLa1WgowS8gBNl4ZVhxFzZCZoeykclFXSZ61whFBA3UBHzdzvYOVMBMDrd0ajjY4peqQ49@vger.kernel.org X-Gm-Message-State: AOJu0YxVwiTo3C+LVljgjA2CXCf9/MlX1YbaWC2xkch2He/HNYjvIwvs AYEXgrHUZdVLKX1naKIsGARVOW9I9Dl01e/7+6+Nz9tb4YkLA8VlDCurEg== X-Gm-Gg: ASbGncsJtPF7Dewi+buDanSgETKKUI2ZRvWyCuOlUUaTbYqRDet7b4MPXnj6z0RLsBg tX/OU1q5G46thxNHYU/y6B57hr06GyVzXwYXFOoBqnxjIiCtiVnacZu/bKlQWyTjEgY4om/1KVN 2SC0f+Y8JaweaaBKmE7DSPYkPuarW87Q4RQuNTFR2wCPeO0btSuqX1FPPFBQulPhnheWpxmlBEV Gnqo6NCfbZbPVQJHHPhOEla1iDbSwR0sKQEX5aDG6Tum3N5DvOcr1a0AxzQ5UUxzgGozXUyhwwW Z8jQEvYSO02QFWHU4tW2+35JJg5szJH65vGT2kGheh+ysdzQxNA= X-Google-Smtp-Source: AGHT+IGu/NN+//EpU7CYFukNrNlPLiWHT6UQmiVwqBJ4NNs9fZZiJnlH6BOdww1vKwf1TPdeJLv8dQ== X-Received: by 2002:a05:6512:2342:b0:549:4de9:22df with SMTP id 2adb3069b0e04-54990da2057mr4566087e87.0.1741611376948; Mon, 10 Mar 2025 05:56:16 -0700 (PDT) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5498b0bd0a0sm1446345e87.156.2025.03.10.05.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 05:56:15 -0700 (PDT) Date: Mon, 10 Mar 2025 14:56:11 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Matti Vaittinen , Lad Prabhakar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hugo Villeneuve , Nuno Sa , David Lechner , Javier Carrasco , Guillaume Stols , Dumitru Ceclan , Trevor Gamblin , Matteo Martelli , Alisa-Dariana Roman , Ramona Alexandra Nechita , AngeloGioacchino Del Regno , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v6 03/10] iio: adc: add helpers for parsing ADC nodes Message-ID: References: Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are ADC ICs which may have some of the AIN pins usable for other functions. These ICs may have some of the AIN pins wired so that they should not be used for ADC. (Preferred?) way for marking pins which can be used as ADC inputs is to add corresponding channels@N nodes in the device tree as described in the ADC binding yaml. Add couple of helper functions which can be used to retrieve the channel information from the device node. Signed-off-by: Matti Vaittinen --- Revision history: v5 => v6: - Adapt to changed fwnode helper names - Fix spelling v4 => v5: - Inline iio_adc_device_num_channels() - Fix Indenting function parameters - Combine the max channel ID checks. v3 => v4: - Drop diff-channel support - Drop iio_adc_device_channels_by_property() - Add IIO_DEVICE namespace - Move industrialio-adc.o to top of the Makefile - Some styling as suggested by Andy - Re-consider included headers v2 => v3: Mostly based on review comments by Jonathan - Support differential and single-ended channels - Rename iio_adc_device_get_channels() as iio_adc_device_channels_by_property() - Improve spelling - Drop support for cases where DT comes from parent device's node - Decrease loop indent by reverting node name check conditions - Don't set 'chan->indexed' by number of channels to keep the interface consistent no matter how many channels are connected. - Fix ID range check and related comment RFC v1 => v2: - New patch --- drivers/iio/adc/Kconfig | 3 ++ drivers/iio/adc/Makefile | 2 + drivers/iio/adc/industrialio-adc.c | 79 ++++++++++++++++++++++++++++++ include/linux/iio/adc-helpers.h | 27 ++++++++++ 4 files changed, 111 insertions(+) create mode 100644 drivers/iio/adc/industrialio-adc.c create mode 100644 include/linux/iio/adc-helpers.h diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 849c90203071..37b70a65da6f 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -6,6 +6,9 @@ menu "Analog to digital converters" +config IIO_ADC_HELPER + tristate + config AB8500_GPADC bool "ST-Ericsson AB8500 GPADC driver" depends on AB8500_CORE && REGULATOR_AB8500 diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index ee19afba62b7..1c410f483029 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -3,6 +3,8 @@ # Makefile for IIO ADC drivers # +obj-$(CONFIG_IIO_ADC_HELPER) += industrialio-adc.o + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o diff --git a/drivers/iio/adc/industrialio-adc.c b/drivers/iio/adc/industrialio-adc.c new file mode 100644 index 000000000000..6cfb001c74b9 --- /dev/null +++ b/drivers/iio/adc/industrialio-adc.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Helpers for parsing common ADC information from a firmware node. + * + * Copyright (c) 2025 Matti Vaittinen + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +/** + * devm_iio_adc_device_alloc_chaninfo_se - allocate and fill iio_chan_spec for ADC + * + * Scan the device node for single-ended ADC channel information. Channel ID is + * expected to be found from the "reg" property. Allocate and populate the + * iio_chan_spec structure corresponding to channels that are found. The memory + * for iio_chan_spec structure will be freed upon device detach. + * + * @dev: Pointer to the ADC device. + * @template: Template iio_chan_spec from which the fields of all + * found and allocated channels are initialized. + * @max_chan_id: Maximum value of a channel ID. Use -1 if no checking + * is required. + * @cs: Location where pointer to allocated iio_chan_spec + * should be stored. + * + * Return: Number of found channels on success. Negative value to indicate + * failure. + */ +int devm_iio_adc_device_alloc_chaninfo_se(struct device *dev, + const struct iio_chan_spec *template, + int max_chan_id, + struct iio_chan_spec **cs) +{ + struct iio_chan_spec *chan_array, *chan; + int num_chan = 0, ret; + + num_chan = iio_adc_device_num_channels(dev); + if (num_chan < 1) + return num_chan; + + chan_array = devm_kcalloc(dev, num_chan, sizeof(*chan_array), + GFP_KERNEL); + if (!chan_array) + return -ENOMEM; + + chan = &chan_array[0]; + + device_for_each_named_child_node_scoped(dev, child, "channel") { + u32 ch; + + ret = fwnode_property_read_u32(child, "reg", &ch); + if (ret) + return ret; + + if (max_chan_id != -1 && ch > max_chan_id) + return -ERANGE; + + *chan = *template; + chan->channel = ch; + chan++; + } + + *cs = chan_array; + + return num_chan; +} +EXPORT_SYMBOL_NS_GPL(devm_iio_adc_device_alloc_chaninfo_se, "IIO_DRIVER"); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Matti Vaittinen "); +MODULE_DESCRIPTION("IIO ADC fwnode parsing helpers"); diff --git a/include/linux/iio/adc-helpers.h b/include/linux/iio/adc-helpers.h new file mode 100644 index 000000000000..56b092a2a4c4 --- /dev/null +++ b/include/linux/iio/adc-helpers.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* + * The industrial I/O ADC firmware property parsing helpers + * + * Copyright (c) 2025 Matti Vaittinen + */ + +#ifndef _INDUSTRIAL_IO_ADC_HELPERS_H_ +#define _INDUSTRIAL_IO_ADC_HELPERS_H_ + +#include + +struct device; +struct iio_chan_spec; + +static inline int iio_adc_device_num_channels(struct device *dev) +{ + return device_get_named_child_node_count(dev, "channel"); +} + +int devm_iio_adc_device_alloc_chaninfo_se(struct device *dev, + const struct iio_chan_spec *template, + int max_chan_id, + struct iio_chan_spec **cs); + +#endif /* _INDUSTRIAL_IO_ADC_HELPERS_H_ */ From patchwork Mon Mar 10 12:56:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 872526 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDB7522A1CD; Mon, 10 Mar 2025 12:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611429; cv=none; b=OMO2wkpBAnLduFUQD5ZImW7Y4ozWFLe/BVRf9/yZ7ZbkO/32KeEyyK42vWgYI6HMFdfXjPb4TNRiWRokVhVvs/JHUUJ20Jv3T16krcSQJc+BqIw/54wQ8ttgSrZnzBfrGtSB5x3YelGy5/9gO63CvFbHHtydvEpUdr+OU+tfg8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611429; c=relaxed/simple; bh=TDKDDPzUaodJtc5UW4XdfLKZzE9wHy3a9yu8RMvuGOo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=djlbETLcKdLuVKVn/OXW+SPF7HC4p0K/Rp5DmvjRjNzayr+eBLH8FzlNQsmH2ZHZ8l/C0W9RQOaJW3Na9T9enLf2hJ2BY9eE+mwHraAJX0vLASIVp17qc6gBiL5Am6MhnQJOvOR2IaG6NXK1LMj1dl3uccih+IQSkjEEUKTCT8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y2lUq+8T; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y2lUq+8T" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5439a6179a7so4135224e87.1; Mon, 10 Mar 2025 05:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741611426; x=1742216226; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=3YGvj5iF7isPICFknfIGBgf8Vkx+OSuL7svbCQwNvKw=; b=Y2lUq+8TebobZ4hLm8jLkwI2JmSRefrx2tH5WFIl4VIQ9vmdOMcLf0vIuUg6m6k21z u7yN3hzn00I66gkVx9hmlZinryyHSE7T0NwPhkpSzd1chi5VMZricW7mdVjXcSlPW3HP ijqLcwnCdyfNVoLLoHTJbuLpXcVspgcbHDr3WY6agMmW3gyRiZBb/ua5PdKhEDckF+mZ AaIe1+05muqNtkk/i9eQjdWQMfdyvPioYDTQ8Kj2bOQSZ+JNMdmbMWvoA4066AKFg/uj bc65pNtVIm0HZLtFYvPgiVZKZ/YDQya/yVMBn88OFpBe5FILHwEJc3cb56/A7IoRyZxk zkVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741611426; x=1742216226; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3YGvj5iF7isPICFknfIGBgf8Vkx+OSuL7svbCQwNvKw=; b=E37ctcZ8GsOQLxVVgNaNHBuuFNjfJ75Y4qYyiKwuuyT07S0eilz2+puATAuJs9FpDq gNiGHI39/f42uavCbxoPWFPcxSYoxTDBEVLMZtg+ZygvVMqETkhcxr9iGXhdZDW6T2DO jF8RVYDZGaJ+pQa/SpS+oWCp0BtDGeDsTN1qlvMWa1g9SZaFYDKM8naMEkXrmsPFLSVB 8v853dwKnu7gcTFPyHlcuDjCHdeYXzissh0J5I57OetlFfrjtalnjOJWZvc3YZ6Nqpu1 e3TIASSD+m62ZOb25b6XWs5wrwWxlcR2RMW99BxeICXhfJG8qwC39w33Wg5kWbTsYcPv +exw== X-Forwarded-Encrypted: i=1; AJvYcCUR0Lzvb04HILgttbMEwddkprmUZiDi37bi9rGtpeG3BQOI7aEpTyVWVsMDEdHZ4e64KPGAI5kvw0zO@vger.kernel.org, AJvYcCV4wh6DR4l1BYzkZLCyIe6SJI80wWiQLrZV5VBPPNM/BSDXIQDJQeHd3VcYCjkn3LYZksOxveWU7Z7Ysw==@vger.kernel.org, AJvYcCVDetf4Ur+t5rDajxd23kZLbJWdmewwJ0VV60kHXGtXl8nUPEFsqrFJQjXt2L/pzv6apqlptooJly6W3U4h@vger.kernel.org, AJvYcCVd7gvJUFVA8aiUo0UX6BQVS3uaM1iXtCWvNQ8YU7Bv5jIq6T0tYM+s2gu1VlQx/WLnNV3yY3p8QS0O@vger.kernel.org, AJvYcCXCllyRZAsi8Uedm+H06WlUaChgJOYj5qiqNV6+qyyXavUBjTeODWncTvIzd6vBy7zRDYFtj89cj20vA92hmSS36oQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yzsp03NOmi9A8Nqu4Blw0ro/UjJP2rttuS0VnTEdhj8p4oswcVF ZOUck4idLxV5iMI7LZijq5mtfj7dXU3RVLb4aqthVmdNW57cJ09b X-Gm-Gg: ASbGncsieSOKeYBgwPffKCPe7TVKtsiOhl062FzlOSacME+RQyzZu+EACogzz3U2ZOa fG9imxsQ9EE34xX9FGBwve4Id3VNoUpO+xIEOn7OvUeTz9hJ14IXWkjWsVoijjvqp4aVGm3R3SM eirMvnpYjrx6IuTHTrTudq9OeGye3eTCrdQitv0TA1cUu7Lyb1pvqziVuTwgwrV3xzb/EVHcM5Y jPWV3sfg+PmOvMUUqxn2prFrySu4OoJkOMQVeQmd1yP0fUfU3V2w7oTQuAtUZtd2ZCmYWZPduP0 tq21HlWkL7ccJ0Pmwi6WCQyeQcW00U4+q9G0OCJYHK0zZjsHVayOUJRn+9O2nA== X-Google-Smtp-Source: AGHT+IF1vXuuBbI7nLmEiCd1MxAiAY5UstFD2g17yL/xAwUgcupEf5SWUE4YyitfHSkIrkHA8dJSBQ== X-Received: by 2002:a05:6512:b0a:b0:549:8c0c:ea15 with SMTP id 2adb3069b0e04-54997d99dbemr3607673e87.0.1741611425535; Mon, 10 Mar 2025 05:57:05 -0700 (PDT) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-549a17fb84csm548493e87.250.2025.03.10.05.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 05:57:03 -0700 (PDT) Date: Mon, 10 Mar 2025 14:56:59 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Matti Vaittinen , Lad Prabhakar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hugo Villeneuve , Nuno Sa , David Lechner , Javier Carrasco , Guillaume Stols , Dumitru Ceclan , Trevor Gamblin , Matteo Martelli , Alisa-Dariana Roman , Ramona Alexandra Nechita , AngeloGioacchino Del Regno , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v6 07/10] MAINTAINERS: Add IIO ADC helpers Message-ID: References: Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add undersigned as a maintainer for the IIO ADC helpers. Signed-off-by: Matti Vaittinen --- Revision history: v2 => - No changes RFC v1 => v2: - New patch --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 8e0736dc2ee0..5b96fb864227 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11208,6 +11208,13 @@ L: linux-media@vger.kernel.org S: Maintained F: drivers/media/rc/iguanair.c +IIO ADC HELPERS +M: Matti Vaittinen +L: linux-iio@vger.kernel.org +S: Maintained +F: drivers/iio/adc/industrialio-adc.c +F: include/linux/iio/adc-helpers.h + IIO BACKEND FRAMEWORK M: Nuno Sa R: Olivier Moysan From patchwork Mon Mar 10 12:57:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 872233 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 703D62288F7; Mon, 10 Mar 2025 12:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611454; cv=none; b=KAh4PDYuidlH5Up2NJ/GqZ65/8EupeD9TWT25bbbE/sJLP+NtxEEvnqO8jkfy1rvpfFXFhZWzunF1OKAe7/+EqZfB+lVoRB4rEtd2tgTy8Lrj0N8lVvC2W9ztvTtUogpbO27yJ82tkjJruDc66C5/vAYu3ke6H+39SMeNdceT3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741611454; c=relaxed/simple; bh=XusGCXjnLrO4NIpb4V870oB4yFDARgNHjuBdPCvCho4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l+rzD9/xcMSOyM9Vlj2tBMIjdmiahR/Pzvhc69d9r4tuQczkRlacWyxRQ6epomgYM1tV++9c2zj96O3fUSFor7/pnatmWvZh1nlUcFjfshn6aH7AGTFzCSkNESm4h4dtt5CBNj5Lpvl0N8Zf7HEs5MxBBrlyDHFUSTFDELmrgT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mQJyaen2; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mQJyaen2" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-30bae572157so41846021fa.3; Mon, 10 Mar 2025 05:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741611450; x=1742216250; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fpwBD3x8iSJEU67vP+98+iDTZb39NqeaJlJjG/XKE/4=; b=mQJyaen2Zc8q9CW4NkbTp/UCFB4Rl36rrp92iocTn2fdUhA+hns0i+xwEzYFkMEFf+ 5+SoxbdTJfVHqgHQAAct/fijfQT4tB+NNPhDa14L5p6UWd9jOdHqCyh+khbgOZpdDZHk eUYQclPy++PgxQCLGFp+XTGjnzRz5PrgW0q3XyN3TpXvNDOpHKGdGdzJnwzYXiyZas21 GthUDdpISM0YXdjYnDsd2RHSzbQGDGqDMwcgWzqx515RLBBEr7+8y/zhbGe+Cfx5YOz6 G4U4acn56BXBHkRJzltjO6YPIpELklRi0ki8cZEOczeyg3aCyZGXzc59ORgk/hmWz0gq eByg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741611450; x=1742216250; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fpwBD3x8iSJEU67vP+98+iDTZb39NqeaJlJjG/XKE/4=; b=U51Jz5ade3x3gNPfuMbOhKxjR53ed+TUfTyw05cKgceVjZrCcC/4B4VP51AadPQHFk 5yf4vjz/YgHaWXYQLze25WhdM9gIiEwpUf7wBJohi8wWgHHAr5rGJz8IRizWKs2dO7BK tIh4UKZtOgDj+zKc7wmNtW708djdkvzPmBRtThgHsTJfK1mPcQer700eo4B4PVlpG21h yzRAkpwy+Vx1xw7wK2UA0DJWKmtRQhakyOn+jlTQJBgbKWF4QmN89B4HYr4d6H+DeNWC p2DeJI/5qUbbfQlwBsOe3qVgx7Ik6IxJxviRVBeEFtOhTgivFSrDmiANh0MmMnP6RJms Qsjg== X-Forwarded-Encrypted: i=1; AJvYcCVjOexvvCFodMPZMT3y6GbM1glh6Xv/gxVA9fUqXXd/yQzPl/H3dOOJnrfHqGZ5O4J1v/dsqENwDBnY@vger.kernel.org, AJvYcCWZzZ7HNdXG87wZ2fEciydGS5A2eG3ZBjWR4IEqZxkFPZUfehJHeM+dqNldICG553QIeNKBEjVE@vger.kernel.org, AJvYcCWoF7dfpzss8gQDJTFWlhtlVn52wHGK6xYTAyPRL5Xo7C7QLOU2DGSeNktZ3B56G/FJD0oktHrw3ZL58Tfu@vger.kernel.org X-Gm-Message-State: AOJu0YxvITheEUjXhgCBWj+97TA0JSq+1oD0mFKLCqKy0NEBpi+nagmw mIb9rZ1Oyivqm2ZTEHeP1WuZw5SEw0elqL4qD+ZfXkOj+mELj9Y+ X-Gm-Gg: ASbGncu/gjHZyWrfZp6gxwyjDbprAvLc5xVGSGmhJy8L1uGBGY1S4AG47xiwRzEZ1u3 4cTrzIk38fHVcCPTEpTOz9qYxC303HsEzU4zt7h7mjkj6MY2XY3f4gLTrOwz8ADR717pAghk+fZ J/AN8ISChB5zHOS75RZ0fZjnGsR3Njki20QcQ+8wRvYUemvzQWWrAPrbqojU1MTjaItsK0MpKJU H8hvGwqm4m4cjhWuZT15yMhQTq8vM4lZnB7Z9wlRtGkAU1POeaCCzO+NBR8t5/OCij4dcjB7JeZ t9TCgAcoHSBNp9J87nsSCe47y29bmFa+yvLEjdqUP15Fv1AuFH4fitejSe1Urw== X-Google-Smtp-Source: AGHT+IGI+4SKzYIDDI/CqOFuISbqcvk/INtbWwZopqKeLbrpPLP1v3bcrvM01tlRht/FIloSf5xc7A== X-Received: by 2002:a05:6512:3d15:b0:549:5b54:2c68 with SMTP id 2adb3069b0e04-54990e5daccmr4642748e87.22.1741611450194; Mon, 10 Mar 2025 05:57:30 -0700 (PDT) Received: from mva-rohm ([2a10:a5c0:800d:dd00:8fdf:935a:2c85:d703]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5498b0bcf98sm1451461e87.128.2025.03.10.05.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 05:57:29 -0700 (PDT) Date: Mon, 10 Mar 2025 14:57:26 +0200 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Claudiu Manoil , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v6 09/10] net: gianfar: Use device_get_child_node_count_named() Message-ID: <1c4b9b4ceb1995bce76a0ddef0e04ad0d1d81190.1741610847.git.mazziesaccount@gmail.com> References: Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We can avoid open-coding the loop construct which counts firmware child nodes with a specific name by using the newly added device_get_child_node_count_named(). The gianfar driver has such open-coded loop. Replace it with the device_get_child_node_count_named(). Suggested-by: Andy Shevchenko Signed-off-by: Matti Vaittinen --- It's fair to tell the pros and cons of this patch. The simplification is there, but it's not a big one. It comes with a cost of getting the property.h included in this driver which currently uses exclusively the of_* APIs. NOTE: This patch depends on the patch: [2/10] "property: Add functions to iterate named child" Compile-tested only! --- drivers/net/ethernet/freescale/gianfar.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index 435138f4699d..d4ee0fc843be 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -97,6 +97,7 @@ #include #include #include +#include #include "gianfar.h" @@ -571,18 +572,6 @@ static int gfar_parse_group(struct device_node *np, return 0; } -static int gfar_of_group_count(struct device_node *np) -{ - struct device_node *child; - int num = 0; - - for_each_available_child_of_node(np, child) - if (of_node_name_eq(child, "queue-group")) - num++; - - return num; -} - /* Reads the controller's registers to determine what interface * connects it to the PHY. */ @@ -654,8 +643,10 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev) num_rx_qs = 1; } else { /* MQ_MG_MODE */ /* get the actual number of supported groups */ - unsigned int num_grps = gfar_of_group_count(np); + unsigned int num_grps; + num_grps = device_get_named_child_node_count(&ofdev->dev, + "queue-group"); if (num_grps == 0 || num_grps > MAXGROUPS) { dev_err(&ofdev->dev, "Invalid # of int groups(%d)\n", num_grps);