[PATCH,RFC] [MTD] replace MTD_NORFLASH with MTD_GENERIC_TYPE

Artem B. Bityutskiy dedekind at yandex.ru
Thu Jun 1 08:57:31 EDT 2006


Jörn Engel wrote:
> I don't understand how that layer would not introduce overhead.  But
> maybe you have some explanation in diff -up format.  That would
> certainly make things easier to understand.

I wrote this already. Sketck:

1. add a 'void *capabilities' field to mtd_info.

2. create mtd_capps.c like this:

#include <mtd_capps.h>

/*
  * Called from mtd_add_device() or like such, i.e., on MTD device
  * initialization.
  */
int mtd_capabilities_init(struct mtd_info *mtd)
{
	struct mtd_capabilities *caps;

	caps = mtd->capabilities = kmalloc(sizeof(struct mtd_capabilities), 
GFP_KERNEL);
	if (!mtd->capabilities)
		return -ENOMEM;

	switch (mtd->type) {
	case MTD_NORFLASH:
		caps->can_milk_goat = 0;
		caps->can_pass_iq_tests = 1;
		/* ETC */
		break;
	case MTD_NANDFLASH:
		/* ETC */
		break;
	/* ETC */
	default:
		return -EINVAL;
	}
	
	return 0;
}

/*
  * Called from mtd_del_device() or like such, i.e., on MTD device
  * de-initialization.
  */
void mtd_capabilities_free(struct mtd_info *mtd)
{
	kfree(mtd->capabilities);
}

3. create mtd_capps.h like this:

struct mtd_capabilities {
	int can_milk_goat;
	int can_pass_iq_tests;
	/* ETC */
};

/* Can this flash milk goats ? */
#define mtd_can_milk_goat(mtd) \
	((struct mtd_capabilities*)(mtd->capabilities))->can_milk_goat

-----

Well, in this case word "layer" becomes not very appropriate. It'll be a 
distinct *unit* within MTD. But the idea to have all the 
application-dependent stuff in one place, not scattered over drivers, stays.

-- 
Best Regards,
Artem B. Bityutskiy,
St.-Petersburg, Russia.





More information about the linux-mtd mailing list