mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-18 07:23:59 +00:00
kernel: backport U-Boot environment data NVMEM driver
It parses U-Boot env data into NVMEM cells.
Fixes: 978bfe3
("kernel: replace downstream get_mtd_device_by_node()
implementation"), #10177, #10178
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
This commit is contained in:
parent
98a38cf20a
commit
f2dd752bf2
target/linux/generic
backport-5.10
pending-5.10
@ -0,0 +1,72 @@
|
||||
From b0321721be50b80c03a51866a94fde4f94690e18 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
|
||||
Date: Wed, 15 Jun 2022 21:42:59 +0200
|
||||
Subject: [PATCH] mtd: allow getting MTD device associated with a specific DT
|
||||
node
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
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 <rafal@milecki.pl>
|
||||
Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
|
||||
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
|
||||
---
|
||||
drivers/mtd/mtdcore.c | 28 ++++++++++++++++++++++++++++
|
||||
include/linux/mtd/mtd.h | 1 +
|
||||
2 files changed, 29 insertions(+)
|
||||
|
||||
--- a/drivers/mtd/mtdcore.c
|
||||
+++ b/drivers/mtd/mtdcore.c
|
||||
@@ -1070,6 +1070,34 @@ int __get_mtd_device(struct mtd_info *mt
|
||||
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
|
||||
* @name: MTD device name to open
|
||||
--- a/include/linux/mtd/mtd.h
|
||||
+++ b/include/linux/mtd/mtd.h
|
||||
@@ -675,6 +675,7 @@ extern int mtd_device_unregister(struct
|
||||
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);
|
||||
|
@ -297,7 +297,7 @@
|
||||
static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->writesize_shift)
|
||||
@@ -678,6 +696,13 @@ extern void __put_mtd_device(struct mtd_
|
||||
@@ -679,6 +697,13 @@ extern struct mtd_info *of_get_mtd_devic
|
||||
extern struct mtd_info *get_mtd_device_nm(const char *name);
|
||||
extern void put_mtd_device(struct mtd_info *mtd);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user