Title: [4122] trunk: [#2628] move flash/ partition information to board resources file
Revision
4122
Author
vapier
Date
2008-01-21 02:55:04 -0600 (Mon, 21 Jan 2008)

Log Message

[#2628] move flash/partition information to board resources file

Diffstat

 arch/blackfin/mach-bf533/boards/stamp.c |   46 +++++
 drivers/mtd/maps/bf5xx-flash.c          |  263 +++++++++++---------------------
 2 files changed, 140 insertions(+), 169 deletions(-)

Modified Paths

Diff

Modified: trunk/arch/blackfin/mach-bf533/boards/stamp.c (4121 => 4122)


--- trunk/arch/blackfin/mach-bf533/boards/stamp.c	2008-01-21 02:43:31 UTC (rev 4121)
+++ trunk/arch/blackfin/mach-bf533/boards/stamp.c	2008-01-21 08:55:04 UTC (rev 4122)
@@ -32,6 +32,7 @@
 #include <linux/platform_device.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
@@ -108,6 +109,50 @@
 };
 #endif
 
+static struct mtd_partition stamp_partitions[] = {
+	{
+		.name   = "Bootloader",
+		.size   = 0x20000,
+		.offset = 0,
+	}, {
+		.name   = "Kernel",
+		.size   = 0xE0000,
+		.offset = MTDPART_OFS_APPEND,
+	}, {
+		.name   = "RootFS",
+		.size   = MTDPART_SIZ_FULL,
+		.offset = MTDPART_OFS_APPEND,
+	}
+};
+
+static struct physmap_flash_data stamp_flash_data = {
+	.width    = 2,
+	.parts    = stamp_partitions,
+	.nr_parts = ARRAY_SIZE(stamp_partitions),
+};
+
+static struct resource stamp_flash_resource[] = {
+	{
+		.name  = "stm_flash",
+		.start = 0x20000000,
+		.end   = 0x203fffff,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.start = CONFIG_ENET_FLASH_PIN,
+		.flags = IORESOURCE_IRQ,
+	}
+};
+
+static struct platform_device stamp_flash_device = {
+	.name          = "BF5xx-Flash",
+	.id            = 0,
+	.dev = {
+		.platform_data = &stamp_flash_data,
+	},
+	.num_resources = ARRAY_SIZE(stamp_flash_resource),
+	.resource      = stamp_flash_resource,
+};
+
 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
 /* all SPI peripherals info goes here */
 
@@ -457,6 +502,7 @@
 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
 	&i2c_gpio_device,
 #endif
+	&stamp_flash_device,
 };
 
 static int __init stamp_init(void)

Modified: trunk/drivers/mtd/maps/bf5xx-flash.c (4121 => 4122)


--- trunk/drivers/mtd/maps/bf5xx-flash.c	2008-01-21 02:43:31 UTC (rev 4121)
+++ trunk/drivers/mtd/maps/bf5xx-flash.c	2008-01-21 08:55:04 UTC (rev 4122)
@@ -1,67 +1,56 @@
 /*
- * File:         drivers/mtd/maps/bf5xx-flash.c
- * Based on:
- * Author:
+ * drivers/mtd/maps/bf5xx-flash.c
  *
- * Created:
- * Description:  Flash memory access on BlackFin BF5xx based devices
+ * Handle the case where flash memory and ethernet mac/phy are
+ * mapped onto the same async bank.  The BF533-STAMP does this
+ * for example.  All board-specific configuration goes in your
+ * board resources file.
  *
- * Rev:          $Id$
+ * Copyright 2000 Nicolas Pitre <[EMAIL PROTECTED]>
+ * Copyright 2005-2008 Analog Devices Inc.
  *
- * Modified:
- *               Copyright 2000 Nicolas Pitre <[EMAIL PROTECTED]>
- *               Copyright 2005-2008 Analog Devices Inc.
+ * Enter bugs at http://blackfin.uclinux.org/
  *
- * Bugs:         Enter bugs at http://blackfin.uclinux.org/
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see the file COPYING, or write
- * to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Licensed under the GPL-2 or later.
  */
 
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/kernel.h>
 #include <linux/init.h>
-
+#include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+#include <linux/platform_device.h>
+#include <linux/types.h>
 
 #include <asm/blackfin.h>
+#include <asm/gpio.h>
 #include <asm/io.h>
 #include <asm/unaligned.h>
-#include <asm/gpio.h>
 
+#define pr_init(fmt, args...) ({ static const __initdata char __fmt[] = fmt; printk(__fmt, ## args); })
+
+#define DRIVER_NAME "BF5xx-Flash"
+
 #define BFIN_FLASH_AMBCTL0VAL	((CONFIG_BFIN_FLASH_BANK_1 << 16) | CONFIG_BFIN_FLASH_BANK_0)
 #define BFIN_FLASH_AMBCTL1VAL	((CONFIG_BFIN_FLASH_BANK_3 << 16) | CONFIG_BFIN_FLASH_BANK_2)
 
+/* Should add a per-device structure and track this there ... */
+static int enet_flash_pin;
+static struct mtd_info *bf5xx_mtd;
+
 struct flash_save {
-#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
 	u32 ambctl0;
 	u32 ambctl1;
-#endif
 	unsigned long flags;
 };
 
-#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
-static inline void switch_to_flash(struct flash_save *save)
+static void switch_to_flash(struct flash_save *save)
 {
 	local_irq_save(save->flags);
 
-	gpio_set_value(CONFIG_ENET_FLASH_PIN, 0);
-
+	gpio_set_value(enet_flash_pin, 0);
 	SSYNC();
 
 	save->ambctl0 = bfin_read_EBIU_AMBCTL0();
@@ -70,55 +59,31 @@
 	bfin_write_EBIU_AMBCTL1(BFIN_FLASH_AMBCTL1VAL);
 	SSYNC();
 }
-#else
-static inline void switch_to_flash(struct flash_save *save) {}
-#endif
 
-#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
-static inline void switch_back(struct flash_save *save)
+static void switch_back(struct flash_save *save)
 {
-
 	bfin_write_EBIU_AMBCTL0(save->ambctl0);
 	bfin_write_EBIU_AMBCTL1(save->ambctl1);
 	SSYNC();
 
-	gpio_set_value(CONFIG_ENET_FLASH_PIN, 1);
+	gpio_set_value(enet_flash_pin, 1);
 
 	local_irq_restore(save->flags);
 }
-#else
-static inline void switch_back(struct flash_save *save) {}
-#endif
 
-#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
-static inline int setup_pfpins(void)
-{
-	if (gpio_request(CONFIG_ENET_FLASH_PIN, "bf5xx-flash")) {
-		printk(KERN_ERR "BF5xx flash: Failed ro request GPIO_%d\n", CONFIG_ENET_FLASH_PIN);
-		return -EBUSY;
-	}
-
-	return gpio_direction_output(CONFIG_ENET_FLASH_PIN, 1);
-}
-#else
-static inline int setup_pfpins(void) {return 0;}
-#endif
-
-
 static map_word bf5xx_read(struct map_info *map, unsigned long ofs)
 {
 	int nValue = 0x0;
 	map_word test;
-
 	struct flash_save save;
 
 	switch_to_flash(&save);
 	SSYNC();
-	nValue = readw((void*)CONFIG_EBIU_FLASH_BASE + ofs);
+	nValue = readw(map->virt + ofs);
 	SSYNC();
 	switch_back(&save);
 
-	test.x[0]=(__u16)nValue;
+	test.x[0] = (u16)nValue;
 	return test;
 }
 
@@ -127,19 +92,19 @@
 	unsigned long i;
 	map_word test;
 
-	if((unsigned long)to & 0x1) {
-		for (i = 0; i < len/2*2; i += 2) {
-			test = bf5xx_read(map,from+i);
-			put_unaligned(test.x[0], (__le16 *) (to + i));
+	if ((unsigned long)to & 0x1) {
+		for (i = 0; i < len / 2 * 2; i += 2) {
+			test = bf5xx_read(map, from + i);
+			put_unaligned(test.x[0], (__le16 *)(to + i));
 		}
 	} else {
-		for (i = 0; i < len/2*2; i += 2) {
-			test = bf5xx_read(map,from+i);
+		for (i = 0; i < len / 2 * 2; i += 2) {
+			test = bf5xx_read(map, from + i);
 			*((u16*)(to + i)) = test.x[0];
 		}
 	}
 
-	if (len & 0x01) {
+	if (len & 0x1) {
 		test = bf5xx_read(map, from + i);
 		*((u8*)(to + i)) = (u8)test.x[0];
 	}
@@ -147,16 +112,16 @@
 
 static void bf5xx_write(struct map_info *map, map_word d1, unsigned long ofs)
 {
-	__u16 d;
+	u16 d;
 	struct flash_save save;
 
-	d = (__u16)d1.x[0];
+	d = (u16)d1.x[0];
 
 	switch_to_flash(&save);
 
-		SSYNC();
-		writew(d, CONFIG_EBIU_FLASH_BASE + ofs);
-		SSYNC();
+	SSYNC();
+	writew(d, map->virt + ofs);
+	SSYNC();
 
 	switch_back(&save);
 }
@@ -167,120 +132,80 @@
 
 	switch_to_flash(&save);
 
-	memcpy((void *)(CONFIG_EBIU_FLASH_BASE + to), from, len);
+	memcpy(map->virt + to, from, len);
 
 	switch_back(&save);
 }
 
 static struct map_info bf5xx_map = {
-	name:        "BF5xx flash",
-	CONFIG_BFIN_FLASH_SIZE,
-	CONFIG_EBIU_FLASH_BASE,
-	(void __iomem *)CONFIG_EBIU_FLASH_BASE,
-	(void *)NULL,
-	read:        bf5xx_read,
-	copy_from:   bf5xx_copy_from,
-	write:       bf5xx_write,
-	copy_to:     bf5xx_copy_to
+	.name      = DRIVER_NAME,
+	.read      = bf5xx_read,
+	.copy_from = bf5xx_copy_from,
+	.write     = bf5xx_write,
+	.copy_to   = bf5xx_copy_to,
 };
 
+static int __init bf5xx_flash_probe(struct platform_device *dev)
+{
+	struct physmap_flash_data *pdata = dev->dev.platform_data;
+	struct resource *memory = platform_get_resource(dev, IORESOURCE_MEM, 0);
 
-/*
- * Here are partition information for all known BlackFin-based devices.
- * See include/linux/mtd/partitions.h for definition of the mtd_partition
- * structure.
- *
- * The *_max_flash_size is the maximum possible mapped flash size which
- * is not necessarily the actual flash size.  It must correspond to the
- * value specified in the mapping definition defined by the
- * "struct map_desc *_io_desc" for the corresponding machine.
- */
+	enet_flash_pin = platform_get_irq(dev, 0);
 
+	bf5xx_map.bankwidth = pdata->width;
+	bf5xx_map.size = memory->end - memory->start;
+	bf5xx_map.virt = (void __iomem *)memory->start;
+	bf5xx_map.phys = memory->start;
 
-static unsigned long bf5xx_max_flash_size = CONFIG_BFIN_FLASH_SIZE;
-
-static struct mtd_partition bf5xx_partitions[] = {
-	{
-		name: "Bootloader",
-		size: 0x20000,
-		//size: 0x1FFFF,
-		offset: 0,
-	},{
-		name: "Kernel",
-		size: 0xE0000,
-		//size: 0xDFFFF,
-		offset: 0x20000,
-	},
-#ifdef CONFIG_BF537
-	{
-		name: "JFFS2",
-		size: 0x2f0000,
-		//size: 0x2effff,
-		offset: 0x100000,
+	if (gpio_request(enet_flash_pin, DRIVER_NAME)) {
+		pr_init(KERN_ERR DRIVER_NAME ": Failed to request gpio %d\n", enet_flash_pin);
+		return -EBUSY;
 	}
-#else
-	{
-		name: "JFFS2",
-		size: 0x300000,
-		//size: 0x2fffff,
-		offset: 0x100000,
-	}
-#endif
-};
+	gpio_direction_output(enet_flash_pin, 1);
 
-#define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
-
-
-static struct mtd_info *mymtd;
-
-int __init bf5xx_mtd_init(void)
-{
-	struct mtd_partition *parts;
-	int nb_parts = 0;
-	char *part_type;
-
-	bf5xx_map.bankwidth = 2;
-	bf5xx_map.size = bf5xx_max_flash_size;
-
-	if(setup_pfpins())
-		return -EBUSY;
-
-	printk(KERN_NOTICE "BF5xx flash: probing %d-bit flash bus\n", bf5xx_map.bankwidth*8);
-	mymtd = do_map_probe("stm_flash", &bf5xx_map);
-	if (!mymtd)
+	pr_init(KERN_NOTICE DRIVER_NAME ": probing %d-bit flash bus\n", bf5xx_map.bankwidth * 8);
+	bf5xx_mtd = do_map_probe(memory->name, &bf5xx_map);
+	if (!bf5xx_mtd)
 		return -ENXIO;
 
-	/*
-	 * Static partition definition selection
-	 */
-	part_type = "static";
-#ifdef CONFIG_BLACKFIN
-	parts = bf5xx_partitions;
-	nb_parts = NB_OF(bf5xx_partitions);
-#endif
-
-	if (nb_parts == 0) {
-		printk(KERN_NOTICE "BF5xx flash: no partition info available, registering whole flash at once\n");
-		add_mtd_device(mymtd);
+	if (pdata->nr_parts) {
+		pr_init(KERN_NOTICE DRIVER_NAME ": Using board partition definition\n");
+		add_mtd_partitions(bf5xx_mtd, pdata->parts, pdata->nr_parts);
 	} else {
-		printk(KERN_NOTICE "Using %s partition definition\n", part_type);
-		add_mtd_partitions(mymtd, parts, nb_parts);
+		pr_init(KERN_NOTICE DRIVER_NAME ": no partition info available, registering whole flash at once\n");
+		add_mtd_device(bf5xx_mtd);
 	}
+
 	return 0;
 }
 
-static void __exit bf5xx_mtd_cleanup(void)
+static int __devexit bf5xx_flash_remove(struct platform_device *dev)
 {
-	if (mymtd) {
-#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
-		gpio_free(CONFIG_ENET_FLASH_PIN);
-#endif
-		del_mtd_partitions(mymtd);
-		map_destroy(mymtd);
-	}
+	gpio_free(enet_flash_pin);
+	del_mtd_partitions(bf5xx_mtd);
+	map_destroy(bf5xx_mtd);
+	return 0;
 }
 
-module_init(bf5xx_mtd_init);
-module_exit(bf5xx_mtd_cleanup);
+static struct platform_driver bf5xx_flash_driver = {
+	.probe		= bf5xx_flash_probe,
+	.remove		= __devexit_p(bf5xx_flash_remove),
+	.driver		= {
+		.name	= DRIVER_NAME,
+	},
+};
 
+static int __init bf5xx_flash_init(void)
+{
+	return platform_driver_register(&bf5xx_flash_driver);
+}
+module_init(bf5xx_flash_init);
+
+static void __exit bf5xx_flash_exit(void)
+{
+	platform_driver_unregister(&bf5xx_flash_driver);
+}
+module_exit(bf5xx_flash_exit);
+
 MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("MTD map driver for Blackfins with flash/ethernet on same async bank");
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
http://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to