From patchwork Wed Jun 15 19:42:59 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: 1643948 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=k14tMQCV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LNbMN6Myzz9sG2 for ; Thu, 16 Jun 2022 05:43:26 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C3A0C832DA; Wed, 15 Jun 2022 21:43:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="k14tMQCV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A47D83020; Wed, 15 Jun 2022 21:43:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A005883020 for ; Wed, 15 Jun 2022 21:43:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=zajec5@gmail.com Received: by mail-ej1-x62a.google.com with SMTP id gl15so25253186ejb.4 for ; Wed, 15 Jun 2022 12:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NeAaQxHNgpvGGApabF2dZ5cx3n1PATnxM0M/iIuIjaA=; b=k14tMQCVOVeOrgEvHimQMUqpKcCa52Ahn9gpZ0rCs6UBPmduwGS/RyEeSxGl32iBsa 6sdJ2TwTf6gszE58GZjCVQJGrDA8gpYriykjwER+3ZPpzBx0LofuIzLo3P27yLoq7fgW 7Rt6xQ+cd9bin8kCAxVf9OAmEkf0xoPvJLzAq1UnhUnZXXHDizAgllKcQfoCJgc78lH8 f21xjPvnjHZJTTHcF5sfaryaMZuoSMBC9rM7poPFB2MPk1aJEBojUV7SB2CYo3Di4L+B +NVJ/3Qlpw2Fql50DHr+uEEqIoYmTRaMWDB+tUmgCak9rIhAlxwXqizC2JzH6fYVEb/l H8aQ== 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:mime-version :content-transfer-encoding; bh=NeAaQxHNgpvGGApabF2dZ5cx3n1PATnxM0M/iIuIjaA=; b=puIgJAld2+Zrh8TxcMjc8Y1r56IvAZnfkIvUhiGDkklkz0i8e8f9daQR7nCPifGWBB DQnJQSdvBKOOwnqMU2gGZ92r7Zs8gbhGloqyu9KRpYO8heDGjepLzzCjjJDbAIqvLYT+ LnKJ8i95qmb/KFruZyWdwJp9saWJbq8B0iOiXu2vEr9SNepLa5vZV9/rsbxe1HWoCvs9 MX9t4Cbhes+m64pzaFocMhR6dXdfkJrgj1J5C0QOzEoC2baJ/fCTF82kgeFUAskDGfrI Dpz12v2pwA4VvcO4TUyC3B2Q1KTJQA5Jnz6RbQb2ejEbhomiRGmFV6SB7yPES+i1fOaa 96Sw== X-Gm-Message-State: AJIora/DjqoWRQ9o67mNyw5vtG9iQqBC+TDhw0XRAMsBBhREDrDpCSq5 VE6w1IRLYBKjTvut+b8C0aM= X-Google-Smtp-Source: AGRyM1sAO6s8WrkND9IqSLFNkOoSsbBsyq8tmeli3+/6WTSIMEkds8HRFI63vvFEhffvyAQFIfxN2g== X-Received: by 2002:a17:906:9244:b0:70c:f626:944d with SMTP id c4-20020a170906924400b0070cf626944dmr1300802ejx.496.1655322191129; Wed, 15 Jun 2022 12:43:11 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id a16-20020aa7d750000000b0042bd6f745fasm18096eds.92.2022.06.15.12.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 12:43:10 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Tom Rini , Ahmad Fatoum , linux-arm-kernel@lists.infradead.org, u-boot@lists.denx.de, devicetree@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V4 1/2] mtd: allow getting MTD device associated with a specific DT node Date: Wed, 15 Jun 2022 21:42:59 +0200 Message-Id: <20220615194300.13358-1-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean From: Rafał Miłecki MTD subsystem API allows interacting with MTD devices (e.g. reading, writing, handling bad blocks). So far a random driver could get MTD device only by its name (get_mtd_device_nm()). This change allows getting them also by a DT node. This API is required for drivers handling DT defined MTD partitions in a specific way (e.g. U-Boot (sub)partition with environment variables). Signed-off-by: Rafał Miłecki Acked-by: Miquel Raynal Reviewed-by: Ahmad Fatoum --- V3: First introduction of of_get_mtd_device_by_node() V4: Use EPROBE_DEFER Srinivas: in V3 Miquel said it's OK to push this patch through NVMEM --- drivers/mtd/mtdcore.c | 28 ++++++++++++++++++++++++++++ include/linux/mtd/mtd.h | 1 + 2 files changed, 29 insertions(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 9eb0680db312..3613cc142f25 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -1154,6 +1154,34 @@ int __get_mtd_device(struct mtd_info *mtd) } EXPORT_SYMBOL_GPL(__get_mtd_device); +/** + * of_get_mtd_device_by_node - obtain an MTD device associated with a given node + * + * @np: device tree node + */ +struct mtd_info *of_get_mtd_device_by_node(struct device_node *np) +{ + struct mtd_info *mtd = NULL; + struct mtd_info *tmp; + int err; + + mutex_lock(&mtd_table_mutex); + + err = -EPROBE_DEFER; + mtd_for_each_device(tmp) { + if (mtd_get_of_node(tmp) == np) { + mtd = tmp; + err = __get_mtd_device(mtd); + break; + } + } + + mutex_unlock(&mtd_table_mutex); + + return err ? ERR_PTR(err) : mtd; +} +EXPORT_SYMBOL_GPL(of_get_mtd_device_by_node); + /** * get_mtd_device_nm - obtain a validated handle for an MTD device by * device name diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 955aee14b0f7..6fc841ceef31 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -677,6 +677,7 @@ extern int mtd_device_unregister(struct mtd_info *master); extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); extern int __get_mtd_device(struct mtd_info *mtd); extern void __put_mtd_device(struct mtd_info *mtd); +extern struct mtd_info *of_get_mtd_device_by_node(struct device_node *np); extern struct mtd_info *get_mtd_device_nm(const char *name); extern void put_mtd_device(struct mtd_info *mtd);