summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-03-14 12:44:22 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2016-04-08 13:34:45 +0200
commit05be9036220af61ee8d93f0197a05251e840c852 (patch)
tree017af240462e712b35e9b050a40f7f29b64eb32c
parent4d28946ac019472186a7139754f35832198e64d2 (diff)
downloadbarebox-05be9036220af61ee8d93f0197a05251e840c852.tar.gz
barebox-05be9036220af61ee8d93f0197a05251e840c852.tar.xz
mtd: ubi: Add function to get ubi number from mtd device
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/mtd/ubi/barebox.c20
-rw-r--r--include/mtd/ubi-user.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c
index f81705e932..c26a2455b2 100644
--- a/drivers/mtd/ubi/barebox.c
+++ b/drivers/mtd/ubi/barebox.c
@@ -297,3 +297,23 @@ int ubi_detach(int ubi_num)
return ubi_detach_mtd_dev(ubi_num, 1);
}
+
+/**
+ * ubi_num_get_by_mtd - find the ubi number to the given mtd
+ * @mtd: the mtd device
+ *
+ * @return: positive or zero for a UBI number, negative error code otherwise
+ */
+int ubi_num_get_by_mtd(struct mtd_info *mtd)
+{
+ int i;
+ struct ubi_device *ubi;
+
+ for (i = 0; i < UBI_MAX_DEVICES; i++) {
+ ubi = ubi_devices[i];
+ if (ubi && mtd == ubi->mtd)
+ return ubi->ubi_num;
+ }
+
+ return -ENOENT;
+}
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index 2002548526..8c02f96e4c 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -407,5 +407,6 @@ struct ubi_set_vol_prop_req {
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
int vid_hdr_offset, int max_beb_per1024);
int ubi_detach(int ubi_num);
+int ubi_num_get_by_mtd(struct mtd_info *mtd);
#endif /* __UBI_USER_H__ */