mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 8/8] ubi: register ubi devices and volumes as devices
Date: Thu, 13 Feb 2014 11:25:35 +0100	[thread overview]
Message-ID: <1392287135-445-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1392287135-445-1-git-send-email-s.hauer@pengutronix.de>

struct ubi_device and struct ubi_volume have devices attached
to them. Register them to make them part of the barebox device
hierarchy.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/ubi/build.c | 13 ++++++++++++-
 drivers/mtd/ubi/cdev.c  |  2 ++
 drivers/mtd/ubi/vmt.c   | 12 ++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 202b046..9c75442 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -157,10 +157,18 @@ static int uif_init(struct ubi_device *ubi, int *ref)
 	*ref = 0;
 	sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
 
+	sprintf(ubi->dev.name, "ubi");
+	ubi->dev.id = DEVICE_ID_DYNAMIC;
+	ubi->dev.parent = &ubi->mtd->class_dev;
+
+	err = register_device(&ubi->dev);
+	if (err)
+		goto out_unreg;
+
 	err = ubi_cdev_add(ubi);
 	if (err) {
 		ubi_err("cannot add character device");
-		goto out_unreg;
+		goto out_dev;
 	}
 
 	for (i = 0; i < ubi->vtbl_slots; i++)
@@ -177,6 +185,8 @@ static int uif_init(struct ubi_device *ubi, int *ref)
 out_volumes:
 	kill_volumes(ubi);
 	devfs_remove(&ubi->cdev);
+out_dev:
+	unregister_device(&ubi->dev);
 out_unreg:
 	ubi_err("cannot initialize UBI %s, error %d", ubi->ubi_name, err);
 	return err;
@@ -193,6 +203,7 @@ out_unreg:
 static void uif_close(struct ubi_device *ubi)
 {
 	kill_volumes(ubi);
+	unregister_device(&ubi->dev);
 	ubi_cdev_remove(ubi);
 }
 
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 129f2e2..e8beaa5 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -179,6 +179,7 @@ int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
 	cdev->name = asprintf("ubi%d.%s", ubi->ubi_num, vol->name);
 	cdev->priv = priv;
 	cdev->size = vol->used_bytes;
+	cdev->dev = &vol->dev;
 	printf("registering %s as /dev/%s\n", vol->name, cdev->name);
 	ret = devfs_create(cdev);
 	if (ret) {
@@ -199,6 +200,7 @@ void ubi_volume_cdev_remove(struct ubi_volume *vol)
 	list_del(&vol->list);
 
 	devfs_remove(cdev);
+	unregister_device(&vol->dev);
 	kfree(cdev->name);
 	kfree(priv);
 }
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 65339ef..e7a5d9a 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -147,6 +147,11 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
 			vol->last_eb_bytes = vol->usable_leb_size;
 	}
 
+	sprintf(vol->dev.name, "%s.%s", dev_name(&ubi->dev), vol->name);
+	vol->dev.id = DEVICE_ID_SINGLE;
+	vol->dev.parent = &ubi->dev;
+	register_device(&vol->dev);
+
 	/* Register character device for the volume */
 	err = ubi_volume_cdev_add(ubi, vol);
 	if (err) {
@@ -190,6 +195,7 @@ out_sysfs:
 out_mapping:
 	if (do_free)
 		kfree(vol->eba_tbl);
+	unregister_device(&vol->dev);
 out_acc:
 	ubi->rsvd_pebs -= vol->reserved_pebs;
 	ubi->avail_pebs += vol->reserved_pebs;
@@ -427,6 +433,11 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
 
 	dbg_gen("add volume");
 
+	sprintf(vol->dev.name, "%s.%s", dev_name(&ubi->dev), vol->name);
+	vol->dev.id = DEVICE_ID_SINGLE;
+	vol->dev.parent = &ubi->dev;
+	register_device(&vol->dev);
+
 	/* Register character device for the volume */
 	err = ubi_volume_cdev_add(ubi, vol);
 	if (err) {
@@ -454,6 +465,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
 	dbg_gen("free volume %d", vol->vol_id);
 
 	ubi->volumes[vol->vol_id] = NULL;
+	unregister_device(&vol->dev);
 	devfs_remove(&vol->cdev);
 }
 
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-02-13 10:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13 10:25 [PATCH 1/8] mtd: Simplify partitions Sascha Hauer
2014-02-13 10:25 ` [PATCH 2/8] device: init bus list Sascha Hauer
2014-02-13 10:25 ` [PATCH 3/8] device: remove parameters when unregistering a device Sascha Hauer
2014-02-13 10:25 ` [PATCH 4/8] mtd: erase_info may be modified in mtd_erase Sascha Hauer
2014-02-13 10:25 ` [PATCH 5/8] mtd: Only call of_parse_partitions when the mtd has a parent Sascha Hauer
2014-02-13 10:25 ` [PATCH 6/8] mtd: partition: only copy selected fields to partition Sascha Hauer
2014-02-13 10:25 ` [PATCH 7/8] mtd: register mtd partitions as real mtd devices Sascha Hauer
2014-02-13 10:25 ` Sascha Hauer [this message]
2014-02-13 11:08 ` [PATCH 1/8] mtd: Simplify partitions Alexander Aring
2014-02-13 13:34   ` Sascha Hauer
2014-02-13 14:01     ` Alexander Aring
2014-02-13 18:45       ` Sascha Hauer
2014-02-13 19:05         ` Alexander Aring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392287135-445-8-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox