From patchwork Fri Mar 15 18:49:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayush Singh X-Patchwork-Id: 13593886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A743EC54E67 for ; Fri, 15 Mar 2024 18:50:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gkd9hlNSBgd1k0JjSBY3DVsxhI9QZvgu7ioiU7Yv02c=; b=j4MtDqG8aZWpCk 4b90Am2lpAygh7Ku+UBPDXh92yXFwXbNlNOi9YCs5RGQ+zDumJNc7QUDIkYdAQfXlvzdpE6mHx30M 70wW90zl9eKD6hjY5k9L4kDGP8haPSBkzr5QMSrNcPJtImR+aprZeqNYpwtKUoCFDw1plQm8513YL 2ygf2BHzkj4gRGS5rzwf1PQtdF1+qy2fjhjOLmMYDQhjgX+mZvwsNvOmc0sNgp+pLZkdVvrfatWDl rG6ot3KmBF1lMMrtCtwE+J8oeDmH9Ml49tlXuOcL62/Sgm6mywErlD8iXWT4KkK/6iKBs3sVUsyHe 8WAw8zHfVC8sVw70L3hg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlCcq-00000001DK3-3y4h; Fri, 15 Mar 2024 18:49:52 +0000 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rlCck-00000001DHN-37FE for linux-arm-kernel@lists.infradead.org; Fri, 15 Mar 2024 18:49:50 +0000 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5a1a069bd16so1374698eaf.3 for ; Fri, 15 Mar 2024 11:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710528585; x=1711133385; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/0yWXrzwVMKSKKedkMOfXRJscJkRhDPTzhMhPeSYFEA=; b=akPdtHb+wMQIBEG17SIuTG9CDZJiihevyKkku/nps8sb1SRjGs6//xn66gGS4kv7u5 U/9tzvaJO2SHPl9ZFaC/uE0no0LH4WNLv47Inp9jjM53WdUcRYzZvQjrWRrmwofT795/ APib0ZJdkTLulcE5Jg7wYs3eH5XwmRMi6Z6D/sCpelafi/y9twCo0HEq0N92GZsdYDxu o1bjyceeiCrsaA75LUUmRhBndmiP0jWgXDhpdYdtyi4iJkfn+MRK/TwvD3Ym+my184Z4 Yq6HiJ+rZLivKmQdmXB4Z7BJ2/Ycv18Bh2oN9OLpEss5GkRhr3uNzvJejEmn1XWl2+Hz AhtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710528585; x=1711133385; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/0yWXrzwVMKSKKedkMOfXRJscJkRhDPTzhMhPeSYFEA=; b=o7Vu6slABpnxW/88mLC5Jlg7/pCOJJIGSuoo5dFLUyq2sUe0Rw+57pqVfj23T1hhBa okwYDsJT3kvwa8gaAc9tQFXexF4iEBtaV49QsylNTSTd3QfnzTrKn3Ws+hRbqS+spqvW AW1/dfy3j545fMmCyB960S30n1y4SIKQrIG1xPqHPk8USli9ZUs59Bhwci2/Zdyh8ark 4TbzZKgDx56GduaEkyhxBlfSypDPPTcpmaQAaLcdPiQKJxNxjd6R9xwUWmC+AUcknnXA YGYDaXPmfuROvrhZOyLCOhcGiiZhh0HEUBmOQVhShxikRdbI/WL0Q9AQ2ucMjGgGsMZw 1nhw== X-Forwarded-Encrypted: i=1; AJvYcCW0Pf66dScQ9Z3I82aqcGHH7NhkHyEpAA9k1NZdGvo48jGo+NBsQlEJVCA0gF8EfkGYX/nYkZv/pGYizmaEZXOTKQ0GvQR+CBQ3DrPlMEmxl751whQ= X-Gm-Message-State: AOJu0YyHoTUcwEC+SSiZpmiZU7MiIV3rphBbzR9azZLrYBhTH4vLjc+f GdmPfSDJ92pIUcBltB2S7YeDMfUpeZBwVbPBMsHJaRGI9OmcM+9V X-Google-Smtp-Source: AGHT+IFg3xw+0ZVudlfm5n/W4rF1HiiD1YucYUMdRXsV4US1Q/BNo5ENea/QqSt1LEy1pQccA1e6fg== X-Received: by 2002:a05:6870:d251:b0:222:3792:d968 with SMTP id h17-20020a056870d25100b002223792d968mr5680859oac.4.1710528585135; Fri, 15 Mar 2024 11:49:45 -0700 (PDT) Received: from toolbox.iitism.net ([103.15.228.94]) by smtp.gmail.com with ESMTPSA id f17-20020a056a0022d100b006e6cc998be8sm3580784pfj.207.2024.03.15.11.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 11:49:44 -0700 (PDT) From: Ayush Singh To: linux-kernel@vger.kernel.org Cc: Ayush Singh , jkridner@beagleboard.org, robertcnelson@beagleboard.org, Vaishnav M A , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Liam Girdwood , Mark Brown , Jiri Slaby , Johan Hovold , Alex Elder , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, linux-serial@vger.kernel.org, greybus-dev@lists.linaro.org Subject: [PATCH v3 2/8] w1: Add w1_find_master_device Date: Sat, 16 Mar 2024 00:19:00 +0530 Message-ID: <20240315184908.500352-3-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240315184908.500352-1-ayushdevel1325@gmail.com> References: <20240315184908.500352-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240315_114946_820873_68EC87FD X-CRM114-Status: GOOD ( 15.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add helper to find w1_master from w1_bus_master, which is present in drvdata of platform device. Signed-off-by: Vaishnav M A Signed-off-by: Ayush Singh --- drivers/w1/w1.c | 6 +++--- drivers/w1/w1_int.c | 27 +++++++++++++++++++++++++++ include/linux/w1.h | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index afb1cc4606c5..ce8a3f93f2ef 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -673,9 +673,9 @@ static int __w1_attach_slave_device(struct w1_slave *sl) sl->dev.of_node = of_find_matching_node(sl->master->dev.of_node, sl->family->of_match_table); - dev_set_name(&sl->dev, "%02x-%012llx", - (unsigned int) sl->reg_num.family, - (unsigned long long) sl->reg_num.id); + dev_set_name(&sl->dev, "%s-%02x-%012llx", sl->master->name, + (unsigned int)sl->reg_num.family, + (unsigned long long)sl->reg_num.id); snprintf(&sl->name[0], sizeof(sl->name), "%02x-%012llx", (unsigned int) sl->reg_num.family, diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c index 3a71c5eb2f83..2bfef8e67687 100644 --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c @@ -242,3 +242,30 @@ void w1_remove_master_device(struct w1_bus_master *bm) __w1_remove_master_device(found); } EXPORT_SYMBOL(w1_remove_master_device); + +/** + * w1_find_master_device() - find a master device + * @bm: master bus device to search + */ +struct w1_master *w1_find_master_device(struct w1_bus_master *bm) +{ + struct w1_master *dev, *found = NULL; + + list_for_each_entry(dev, &w1_masters, w1_master_entry) { + if (!dev->initialized) + continue; + + if (dev->bus_master->data == bm->data) { + found = dev; + break; + } + } + + if (!found) { + pr_err("device doesn't exist.\n"); + return ERR_PTR(-ENODEV); + } + + return found; +} +EXPORT_SYMBOL(w1_find_master_device); diff --git a/include/linux/w1.h b/include/linux/w1.h index 9a2a0ef39018..24269d0dd5d1 100644 --- a/include/linux/w1.h +++ b/include/linux/w1.h @@ -242,6 +242,7 @@ struct w1_master { int w1_add_master_device(struct w1_bus_master *master); void w1_remove_master_device(struct w1_bus_master *master); +struct w1_master *w1_find_master_device(struct w1_bus_master *master); /** * struct w1_family_ops - operations for a family type