I have a NOR and NAND flash chips
Ian Campbell
icampbell at arcom.com
Thu Aug 7 07:18:50 EDT 2003
> You just have to be aware
> that they'll get assigned numbers in the order they get registered,
> that's all.
A long while ago I submitted a patch which added a function
add_mtd_device_full which allowed you to request a specific minor
number. We use it to ensure SRAM is always minor 15, no matter how many
partitions are in the main flash array, which can make things easier on
the support guys, for documentation purposes etc.
I've attached it again since it may be of interest, since your map
driver could then register the flash at a specific device. I can see how
a add_mtd_partition_full which allowed you to specify a starting minor
number would be useful too, but I haven't needed it myself.
Ian.
--
Ian Campbell, Senior Design Engineer
Arcom, Clifton Road, Direct: +44 (0)1223 403 465
Cambridge CB1 7EA, United Kingdom Phone: +44 (0)1223 411 200
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________
-------------- next part --------------
%patch
Index: q/drivers/mtd/mtdcore.c
===================================================================
--- q.orig/drivers/mtd/mtdcore.c Tue Aug 5 16:46:21 2003
+++ q/drivers/mtd/mtdcore.c Tue Aug 5 16:46:38 2003
@@ -36,30 +36,39 @@
static LIST_HEAD(mtd_notifiers);
/**
- * add_mtd_device - register an MTD device
+ * add_mtd_device_full - register an MTD device at a particular minor number
* @mtd: pointer to new MTD device info structure
+ * @minor: requested minor number. -1 to for the first free.
*
- * Add a device to the list of MTD devices present in the system, and
- * notify each currently active MTD 'user' of its arrival. Returns
- * zero on success or 1 on failure, which currently will only happen
- * if the number of present devices exceeds MAX_MTD_DEVICES (i.e. 16)
+ * Add a device to the list of MTD devices present in the system,
+ * and notifies each currently active MTD 'user' of its
+ * arrival. Returns zero on success or 1 on failure, which
+ * currently only occurs if the requested minor number has
+ * already been allocated or if minor exceeds MAX_MTD_DEVICES
+ * (i.e. 16)
*/
-
-int add_mtd_device(struct mtd_info *mtd)
+int add_mtd_device_full(struct mtd_info *mtd, int minor)
{
- int i;
-
down(&mtd_table_mutex);
- for (i=0; i < MAX_MTD_DEVICES; i++)
- if (!mtd_table[i]) {
+ if ( minor == -1 ) {
+ for (minor = 0; minor < MAX_MTD_DEVICES; minor++)
+ if (!mtd_table[minor])
+ break;
+ }
+
+ if ( minor >= MAX_MTD_DEVICES || minor < 0 || mtd_table[minor] ) {
+ up(&mtd_table_mutex);
+ return 1;
+ }
+
struct list_head *this;
- mtd_table[i] = mtd;
- mtd->index = i;
+ mtd_table[minor] = mtd;
+ mtd->index = minor;
mtd->usecount = 0;
- DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name);
+ DEBUG(0, "mtd: Giving out device %d to %s\n",minor, mtd->name);
/* No need to get a refcount on the module containing
the notifier, since we hold the mtd_table_mutex */
list_for_each(this, &mtd_notifiers) {
@@ -76,8 +85,18 @@
return 0;
}
- up(&mtd_table_mutex);
- return 1;
+/**
+ * add_mtd_device - register an MTD device
+ * @mtd: pointer to new MTD device info structure
+ *
+ * Add a device to the list of MTD devices present in the system, and
+ * notify each currently active MTD 'user' of its arrival. Returns
+ * zero on success or 1 on failure, which currently will only happen
+ * if the number of present devices exceeds MAX_MTD_DEVICES (i.e. 16)
+ */
+int add_mtd_device(struct mtd_info *mtd)
+{
+ return add_mtd_device_full(mtd, -1);
}
/**
@@ -288,6 +307,7 @@
EXPORT_SYMBOL(add_mtd_device);
+EXPORT_SYMBOL(add_mtd_device_full);
EXPORT_SYMBOL(del_mtd_device);
EXPORT_SYMBOL(get_mtd_device);
EXPORT_SYMBOL(put_mtd_device);
Index: q/include/linux/mtd/mtd.h
===================================================================
--- q.orig/include/linux/mtd/mtd.h Tue Aug 5 16:46:22 2003
+++ q/include/linux/mtd/mtd.h Tue Aug 5 16:46:38 2003
@@ -238,6 +238,7 @@
/* Kernel-side ioctl definitions */
extern int add_mtd_device(struct mtd_info *mtd);
+extern int add_mtd_device_full(struct mtd_info *mtd, int minor);
extern int del_mtd_device (struct mtd_info *mtd);
extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
%diffstat
drivers/mtd/mtdcore.c | 52 +++++++++++++++++++++++++++++++++---------------
include/linux/mtd/mtd.h | 1
2 files changed, 37 insertions(+), 16 deletions(-)
More information about the linux-mtd
mailing list