From patchwork Fri Feb 11 13:05:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 12743427 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 F384EC433F5 for ; Fri, 11 Feb 2022 13:07:52 +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=CO/KfhwGbwH9Z/eXLCsxCh8pX7RYFG0COGrwz02UbqA=; b=tGEi7GQgIYgBH3 Q8b5uf0+uPwOyHzGR3w4hrO/ZQNDwas/mM9zmiZWM7nEl/SNuXUj22EdM2Z0aO7qI/utK51r1SqfM o/OEp6FUhaL9ITUMPtqPE0b2X4vycEgDCeiVOX+2Z7rgxRYbqUs/uMcAxCGKHR7tnD+QYRqUTkv/Z 8BxW+t6mqDfwtch72sQah6xpFJKmAvskH6l55bJRA4D0tcIltQHVKK0tR8dytkyHn2bisBwoIb/MD 2xIJAqLsQ6TwOYI1QArpBBaRCF/wXi7TqmLtEHkGuYixcS2Vah5wqINp8vt+293CiJbL+5X3Kfhs3 9TTUTPXT4pr+ROl0EOjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIVdI-007JiG-Ub; Fri, 11 Feb 2022 13:06:41 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIVcs-007JYA-AA for linux-arm-kernel@lists.infradead.org; Fri, 11 Feb 2022 13:06:16 +0000 Received: by mail-lj1-x233.google.com with SMTP id n24so9754317ljj.10 for ; Fri, 11 Feb 2022 05:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tX9YbbK4wZDYd/1rJF+Fsl9cu8MwUvaAy3wkrzRgdck=; b=EYhftBejqCnc8+Xc8fkkRb1kgXnwY9DZicwijRuZEMwqwLctCSRnWT3czltZ1Oe7Vi RRYXVlpSymNMkx85YtOHjmuCrs4Rw1nSL9N5I1CLdYMj78PYUCVl0FtUgXFjgJTHx9TZ HQdK1nrxeRo/nseosHSxIJdwwgSttMcTBwBK7BVq95O65zEO9lyQT5Ko+tFf1bS7VG3S OQuJYPPe3DOGMSto56n04z06eUyBmXcgu4jxGd9GtAbNNXNIKURGrny0I2FNPa2g2E7a O6NltEOPRVDIM2iBU+78Qa4FgjfDX3ggUzOcjIBgqXnASsQX3Yep9azAufzehByV5hAI a6KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tX9YbbK4wZDYd/1rJF+Fsl9cu8MwUvaAy3wkrzRgdck=; b=M2pdRc1qW4IRoiVtfiby7OiQDXGAfudTkZnylrlPIITqKq8+rOynpMArgZKDPqjjoE YINOwB9509oTEG4sDeTHPit8dCXXp5oz/E+6nz0QrEwuDmSYMNsckAISPqUm3JZJKhiY Kc8pxQMoxjSAVhSCOXPHhR8xYTuSvwpRYBFnkRCAvYORGOC8odmo6agQmsdgDqK9Qmxq gPg8THS5oCx1rLYrQPcZFKHi8mSMLuN/f1d91jE/srKOtx9UOkj1hlV8gE0OCY+tS1zi Ti0EiTnH65SzwAPx1y6PTmTGQHnCSCd9sLHJakDDihFdyA9Tfb/Q3dK4af+v64Qn59je DMGg== X-Gm-Message-State: AOAM531JYzlmIDbeOW95K6QSsiNcfUgU0JcQUJrIkqx2FnYxtm52M7BX RBA4aBw8iInaRmVeeWBcabg= X-Google-Smtp-Source: ABdhPJwjh3Lda7G/sGCxxqTFqmt+fCLA8UjkG+crA1HMkLbUpGWDYr9nLfTZA8qjf3oHiyFBjGOzjA== X-Received: by 2002:a2e:9d96:: with SMTP id c22mr976389ljj.293.1644584772698; Fri, 11 Feb 2022 05:06:12 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id b13sm3111094lfv.175.2022.02.11.05.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 05:06:12 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring Cc: Krzysztof Kozlowski , Florian Fainelli , Hauke Mehrtens , bcm-kernel-feedback-list@broadcom.com, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 3/3] nvmem: core: add cell name based matching of DT cell nodes Date: Fri, 11 Feb 2022 14:05:54 +0100 Message-Id: <20220211130554.13062-4-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220211130554.13062-1-zajec5@gmail.com> References: <20220124160300.25131-1-zajec5@gmail.com> <20220211130554.13062-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220211_050614_405504_87388827 X-CRM114-Status: GOOD ( 14.74 ) 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 From: Rafał Miłecki When adding NVMEM cells defined by driver it's important to match them with DT nodes that specify matching names. That way other bindings & drivers can reference such "dynamic" NVMEM cells. Signed-off-by: Rafał Miłecki --- drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 53a43d843743..a891449c52f1 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem, return 0; } +/** + * nvmem_find_cell_of_node() - Find DT node matching nvmem cell + * + * @nvmem: nvmem provider + * @name: nvmem cell name + * + * Runtime created nvmem cells (those not coming from DT) may still need to be + * referenced in DT. This function allows finding DT node referencing nvmem cell + * by its name. Such a DT node can be then used by nvmem consumers. + * + * Return: NULL or pointer to DT node + */ +static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem, + const char *name) +{ + struct device_node *child; + + for_each_child_of_node(nvmem->dev.of_node, child) { + if (!strcmp(child->name, name)) + return child; + } + + return NULL; +} + /** * nvmem_add_cells() - Add cell information to an nvmem device * @@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, goto err; } + cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name); + nvmem_cell_entry_add(cells[i]); }