Skip to contentSkip to conversation

convert physmap to platform driver

RFC PATCH In review Lennert Buytenhek 4 participants 8 messages Feb 12, 2006 – Mar 14, 2006 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 convert physmap to platform driver

Hi!

After dwmw2 let me know it ought to be done, I rewrote the physmap map driver to be a platform driver. I know zilch about the driver model, so I probably botched it in some way, but I've done some tests on an ixp23xx board which uses physmap, and it all seems to work.

In order to not break existing physmap users, I've added some compat code that will instantiate a platform device iff CONFIG_MTD_PHYSMAP_LEN is defined and != 0. Also, I've changed the default value for CONFIG_MTD_PHYSMAP_LEN to zero, so that people who inadvertently compile in physmap (or new, platform-style, users of physmap) don't get burned.

This works pretty well -- the new physmap driver is a drop-in replacement for the old one, and works on said ixp23xx board without any code changes needed. (This should hold as long as users don't touch 'physmap_map' directly.)

Once all physmap users have been converted to instantiate their own platform devices, the compat code can go. (Or we decide that we can change all the in-tree users at the same time, and never merge the compat code.)

Comments?

cheers,
Lennert

drivers/mtd/maps/Kconfig +1 -1
diff -ur linux-2.6.16-rc2.orig/drivers/mtd/maps/Kconfig linux-2.6.16-rc2/drivers/mtd/maps/Kconfig
@@ -37,7 +37,7 @@
 config MTD_PHYSMAP_LEN
 	hex "Physical length of flash mapping"
 	depends on MTD_PHYSMAP
-	default "0x4000000"
+	default "0"
 	help
 	  This is the total length of the mapping of the flash chips on
 	  your particular board. If there is space, or aliases, in the
drivers/mtd/maps/physmap.c +187 -69

299 lines not on this page · raw message

include/linux/mtd/physmap.h +8 -13
diff -urN linux-2.6.16-rc2.orig/include/linux/mtd/physmap.h linux-2.6.16-rc2/include/linux/mtd/physmap.h
@@ -24,22 +24,18 @@
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
 
-/*
- * The map_info for physmap.  Board can override size, buswidth, phys,
- * (*set_vpp)(), etc in their initial setup routine.
- */
-extern struct map_info physmap_map;
+struct physmap_flash_data {
+	unsigned int		width;
+	void			(*set_vpp)(struct map_info *, int);
+	unsigned int		nr_parts;
+	struct mtd_partition	*parts;
+};
 
 /*
  * Board needs to specify the exact mapping during their setup time.
  */
-static inline void physmap_configure(unsigned long addr, unsigned long size, int bankwidth, void (*set_vpp)(struct map_info *, int) )
-{
-	physmap_map.phys = addr;
-	physmap_map.size = size;
-	physmap_map.bankwidth = bankwidth;
-	physmap_map.set_vpp = set_vpp;
-}
+void physmap_configure(unsigned long addr, unsigned long size,
+		int bankwidth, void (*set_vpp)(struct map_info *, int) );
 
 #if defined(CONFIG_MTD_PARTITIONS)
 
@@ -58,4 +54,3 @@
 #endif /* defined(CONFIG_MTD) */
 
 #endif /* __LINUX_MTD_PHYSMAP__ */
-
#1 lore raw

Hi,

Quoted 4 lines · Lennert Buytenhek

After dwmw2 let me know it ought to be done, I rewrote the physmap map driver to be a platform driver. I know zilch about the driver model, so I probably botched it in some way, but I've done some tests on an ixp23xx board which uses physmap, and it all seems to work.

I wonder whether anyone had a chance to look at this yet?

thanks,
Lennert

#2 lore raw

On Feb 21 2006, at 14:51, Lennert Buytenhek was caught saying:

Quoted 10 lines

Hi,

Quoted 4 lines · Lennert Buytenhek

After dwmw2 let me know it ought to be done, I rewrote the physmap map driver to be a platform driver. I know zilch about the driver model, so I probably botched it in some way, but I've done some tests on an ixp23xx board which uses physmap, and it all seems to work.

I wonder whether anyone had a chance to look at this yet?

/me wonders same. Would like to see this upstream.

~Deepak

Signature · 4 lines
Deepak Saxena - [email protected] - http://www.plexity.net

A starving child in Africa or you in front of your TV?
Where's the real tragedy?
#3 lore raw

RFC PATCH 1/1 don't load physmap if length is zero

In reply to Lennert Buytenhek

OK, so if the previous patch (which converted physmap into a platform driver) was too nonobvious, can we at least apply a patch like this so that it's possible to compile in physmap without using it?

This is useful for example on the Technologic Systems TS-72xx boards, where some models in the series have NOR flash while others have NAND flash, and you'd like to be able to compile a single kernel that works on all models. (So for the NOR models, you call physmap_configure at run time, while for the NAND models, you initialise the board-specific NAND driver (which I shall submit later.))

I'd still prefer the platform driver patch to be applied, but having some kind of solution merged is better than no solution at all :-)

-- CUT HERE --
Allow compiling in the physmap mtd map driver without using it -- this is useful for multi-machine kernels where some of the supported machines need physmap while others do not.

drivers/mtd/maps/Kconfig +1 -1
diff -urN linux-2.6.15.orig/drivers/mtd/maps/Kconfig linux-2.6.15/drivers/mtd/maps/Kconfig
@@ -37,7 +37,7 @@
 config MTD_PHYSMAP_LEN
 	hex "Physical length of flash mapping"
 	depends on MTD_PHYSMAP
-	default "0x4000000"
+	default "0"
 	help
 	  This is the total length of the mapping of the flash chips on
 	  your particular board. If there is space, or aliases, in the
drivers/mtd/maps/physmap.c +3 -0
diff -urN linux-2.6.15.orig/drivers/mtd/maps/physmap.c linux-2.6.15/drivers/mtd/maps/physmap.c
@@ -51,6 +51,9 @@
 	static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
 	const char **type;
 
+	if (!physmap_map.size)
+		return -EIO;
+
        	printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys);
 	physmap_map.virt = ioremap(physmap_map.phys, physmap_map.size);
 
#4 lore raw

Re: [less intrusive PATCH, RFC] don't load physmap if length is zero

Quoted 12 lines · Lennert Buytenhek

OK, so if the previous patch (which converted physmap into a platform driver) was too nonobvious, can we at least apply a patch like this so that it's possible to compile in physmap without using it?

This is useful for example on the Technologic Systems TS-72xx boards, where some models in the series have NOR flash while others have NAND flash, and you'd like to be able to compile a single kernel that works on all models. (So for the NOR models, you call physmap_configure at run time, while for the NAND models, you initialise the board-specific NAND driver (which I shall submit later.))

Quoted 2 lines

I'd still prefer the platform driver patch to be applied, but having some kind of solution merged is better than no solution at all :-)

Is there a good reason why you didn't just write your own mapping driver? Most people copy physmap.c, change a few things and use that driver instead of physmap.c. It does involve many copies of essentially the same code, but that code is very simple and no sane kernel should have more than one mapping driver included, so no object code is duplicated.

Jörn

Signature · 4 lines
Public Domain  - Free as in Beer
General Public - Free as in Speech
BSD License    - Free as in Enterprise
Shared Source  - Free as in "Work will make you..."
#5 lore raw

Re: [less intrusive PATCH, RFC] don't load physmap if length is zero

Quoted 11 lines · J?rn Engel
Quoted 2 lines · Lennert Buytenhek

I'd still prefer the platform driver patch to be applied, but having some kind of solution merged is better than no solution at all :-)

Is there a good reason why you didn't just write your own mapping driver? Most people copy physmap.c, change a few things and use that driver instead of physmap.c. It does involve many copies of essentially the same code, but that code is very simple and no sane kernel should have more than one mapping driver included, so no object code is duplicated.

It is reasonable to have multiple board variants with differing flash setups but still want them all to run the same kernel. If you're using platform devices to tell the world about the rest of the differing fit information it's reasonable to also want to use it for the flash.

Signature · 1 line
"You grabbed my hand and we fell into it, like a daydream - or a fever."
#6 lore raw

Re: [less intrusive PATCH, RFC] don't load physmap if length is zero

Quoted 13 lines · Mark Brown
Quoted 11 lines · J?rn Engel
Quoted 2 lines · Lennert Buytenhek

I'd still prefer the platform driver patch to be applied, but having some kind of solution merged is better than no solution at all :-)

Is there a good reason why you didn't just write your own mapping driver? Most people copy physmap.c, change a few things and use that driver instead of physmap.c. It does involve many copies of essentially the same code, but that code is very simple and no sane kernel should have more than one mapping driver included, so no object code is duplicated.

Quoted 4 lines

It is reasonable to have multiple board variants with differing flash setups but still want them all to run the same kernel. If you're using platform devices to tell the world about the rest of the differing fit information it's reasonable to also want to use it for the flash.

Sure. So why don't you:
1. Turn physmap.c into a platform driver.
2. Rename physmap.c into something.c
3. Remove unnecessary generic code from something.c
4. Submit a patch adding something.c

Instead, steps 2 and 3 were skipped and physmap itself was supposed to become a platform driver. And at the moment I don't understand the advantages of skipping said steps.

Jörn

Signature · 3 lines
Das Aufregende am Schreiben ist es, eine Ordnung zu schaffen, wo
vorher keine existiert hat.
-- Doris Lessing
#7 lore raw

Re: [less intrusive PATCH, RFC] don't load physmap if length is zero

Quoted 5 lines · Jörn Engel

Sure. So why don't you:
1. Turn physmap.c into a platform driver.
2. Rename physmap.c into something.c
3. Remove unnecessary generic code from something.c
4. Submit a patch adding something.c

That's roughly what I have done (except I just added the ability to configure the probe type to a copy of the existing platform RAM driver). A patch against 2.6.13 is below: it probably needs updating. Ben Dooks wanted me to re-add the write locking support that the original code had but I stripped out pending adding windowing support.

I haven't been trying very hard to integrate that yet (I think I posted it once before), mostly due to not having done what Ben asked although there's no reason why that couldn't be added later.

Quoted 3 lines

Instead, steps 2 and 3 were skipped and physmap itself was supposed to become a platform driver. And at the moment I don't understand the advantages of skipping said steps.

That makes sense. I guess if I were going to do anything with physmap I would be making it register a platform device rather than just talk to the MTD code directly.

drivers/mtd/maps/Kconfig +7 -0
diff -uprN linux-2.6.13/drivers/mtd/maps/Kconfig linux-plat-flash/drivers/mtd/maps/Kconfig
@@ -624,5 +624,12 @@ config MTD_PLATRAM
 
 	  This selection automatically selects the map_ram driver.
 
+config MTD_PLATFLASH
+	tristate "Map driver for platform device physically mapped flash"
+	depends on MTD
+	help
+	  Map driver allowing MTD devices which are physically mapped into
+	  the CPU's address space to be enumerated using the platform bus.
+
 endmenu
 
drivers/mtd/maps/Makefile +1 -0
diff -uprN linux-2.6.13/drivers/mtd/maps/Makefile linux-plat-flash/drivers/mtd/maps/Makefile
@@ -69,4 +69,5 @@ obj-$(CONFIG_MTD_WRSBC8260)	+= wr_sbc82x
 obj-$(CONFIG_MTD_DMV182)	+= dmv182.o
 obj-$(CONFIG_MTD_SHARP_SL)	+= sharpsl-flash.o
 obj-$(CONFIG_MTD_PLATRAM)	+= plat-ram.o
+obj-$(CONFIG_MTD_PLATFLASH)     += plat-flash.o
 obj-$(CONFIG_MTD_OMAP_NOR)	+= omap_nor.o
drivers/mtd/maps/plat-flash.c +272 -0

272 lines not on this page · raw message

include/linux/mtd/plat-flash.h +31 -0
diff -uprN linux-2.6.13/include/linux/mtd/plat-flash.h linux-plat-flash/include/linux/mtd/plat-flash.h
@@ -0,0 +1,31 @@
+/* linux/include/mtd/plat-flash.h
+ *
+ * (c) 2005 Aculab plc
+ *     Mark Brown <[email protected]>
+ * (c) 2004 Simtec Electronics
+ *	http://www.simtec.co.uk/products/SWLINUX/
+ *	Ben Dooks <[email protected]>
+ *
+ * Generic platform device based flash map
+ *
+ * $Id: $
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __LINUX_MTD_PLATFLASH_H
+#define __LINUX_MTD_PLATFLASH_H __FILE__
+
+struct platdata_mtd_flash {
+	char			*mapname;
+	char                   **chip_probes;
+	char		       **partition_probes;
+	struct mtd_partition	*partitions;
+	int			 nr_partitions;
+	int			 bankwidth;
+};
+
+#endif /* __LINUX_MTD_PLATRAM_H */
Signature · 1 line
"You grabbed my hand and we fell into it, like a daydream - or a fever."