Skip to contentSkip to conversation

Magic Panel (SH3-DSP board) MTD mapping

PATCH In review Markus Brunner 3 participants 5 messages Aug 20, 2007 – Sep 21, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Magic Panel (SH3-DSP board) MTD mapping

Hi,

this adds a MTD mapping for the onboard NOR flash on the Magic Panel R2. The mapping module is based on the solutionengine mapping module.

How are the chances for inclusion in 2.6.24?

Signed-off by: Markus Brunner <[email protected]> Signed-off by: Mark Jonas <[email protected]>

---
 Kconfig        |    6 +++
 Makefile       |    1
 magicpanelr2.c |   98 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+)
drivers/mtd/maps/Kconfig +6 -0
@@ -407,6 +407,12 @@ config MTD_SOLUTIONENGINE
 	  This enables access to the flash chips on the Hitachi SolutionEngine and
 	  similar boards. Say 'Y' if you are building a kernel for such a board.
 
+config MTD_MAGICPANELR2
+	tristate "CFI Flash device mapped on Magic Panel R2"
+	depends on SUPERH && MTD_CFI && MTD_REDBOOT_PARTS
+	help
+	  This enables access to the flash chip on the Magic Panel R2.
+
 config MTD_ARM_INTEGRATOR
 	tristate "CFI Flash device mapped on ARM Integrator/P720T"
 	depends on ARM && MTD_CFI

--- sh-2.6-intc/drivers/mtd/maps/magicpanelr2.c 1970-01-01 01:00:00.000000000
+0100
+++ sh-2.6/drivers/mtd/maps/magicpanelr2.c 2007-08-17 14:30:37.000000000 +0200
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2007 Markus Brunner, Mark Jonas
+ *
+ * Flash on Magic Panel R2 board.
+ *
+ * Based on solutionengine.c
+ *
+ * (C) 2001 Red Hat, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>
+#include <linux/errno.h>
+#include <asm/magicpanelr2.h>
+
+static struct mtd_info *flash_mtd;
+
+struct map_info mpr2_flash_map = {
+ .name = "Magic Panel R2 Flash",
+ .size = 0x2000000UL,
+ .bankwidth = 2,
+};
+static struct mtd_partition *parsed_parts;
+
+static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; +
+static struct mtd_partition mpr2_partitions[] = {
+ /* Reserved for bootloader, read-only */
+ {
+ .name = "Bootloader",
+ .offset = 0x00000000UL,
+ .size = MPR2_MTD_BOOTLOADER_SIZE,
+ .mask_flags = MTD_WRITEABLE,
+ },
+ /* Reserved for kernel image */
+ {
+ .name = "Kernel Image",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = MPR2_MTD_KERNEL_SIZE,
+ },
+ /* Rest is used for Flash FS */
+ {
+ .name = "Flash FS",
+ .offset = MTDPART_OFS_NXTBLK,
+ .size = MTDPART_SIZ_FULL,
+ }
+};
+
+static int __init init_mpr2_maps(void)
+{
+ int nr_parts = 0;
+
+ /* Probe at offset 0 */
+ mpr2_flash_map.phys = 0x00000000UL;
+ mpr2_flash_map.virt = (void __iomem *)P2SEGADDR(0x00000000UL);
+ simple_map_init(&mpr2_flash_map);
+
+ flash_mtd = do_map_probe("cfi_probe", &mpr2_flash_map);
+
+ flash_mtd->owner = THIS_MODULE;
+
+ /* Check if there is a partition table */
+ nr_parts = parse_mtd_partitions(flash_mtd, probes, &parsed_parts, 0);
+
+ /* If there is no partition table, used the hard coded table */
+ if (nr_parts <= 0) {
+ parsed_parts = mpr2_partitions;
+ nr_parts = sizeof(mpr2_partitions)/sizeof(*parsed_parts);
+ }
+
+ /* Add partitions */
+ add_mtd_partitions(flash_mtd, parsed_parts, nr_parts);
+
+ return 0;
+}
+
+static void __exit cleanup_mpr2_maps(void)
+{
+ del_mtd_partitions(flash_mtd);
+ map_destroy(flash_mtd);
+}
+
+module_init(init_mpr2_maps);
+module_exit(cleanup_mpr2_maps);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mark Jonas <[email protected]>"); +MODULE_DESCRIPTION("MTD map driver for Magic Panel R2");

drivers/mtd/maps/Makefile +1 -0
@@ -71,3 +71,4 @@ obj-$(CONFIG_MTD_PLATRAM)	+= plat-ram.o
 obj-$(CONFIG_MTD_OMAP_NOR)	+= omap_nor.o
 obj-$(CONFIG_MTD_MTX1)		+= mtx-1_flash.o
 obj-$(CONFIG_MTD_TQM834x)	+= tqm834x.o
+obj-$(CONFIG_MTD_MAGICPANELR2)	+= magicpanelr2.o
\ No newline at end of file
#1 lore raw
Quoted 4 lines · Markus Brunner

this adds a MTD mapping for the onboard NOR flash on the Magic Panel R2. The mapping module is based on the solutionengine mapping module.

How are the chances for inclusion in 2.6.24?

Looks like you should be able to use a platform_device for this.

Signature · 1 line
dwmw2
#2 lore raw
Quoted 7 lines · David Woodhouse
Quoted 4 lines · Markus Brunner

this adds a MTD mapping for the onboard NOR flash on the Magic Panel R2. The mapping module is based on the solutionengine mapping module.

How are the chances for inclusion in 2.6.24?

Looks like you should be able to use a platform_device for this.

Yes. I should have looked outside arch/sh/, too.
I'm just a bit confused why the solutionengine mapping isn't done there.

#3 lore raw

PATCH 1/1 Magic Panel MTD mapping update

In reply to David Woodhouse

Hi Paul,

this update moves the flash mapping for the Magic Panel into the board setup. It also removes references to the old MTD mapping option in the defconfig.

Signed-off by: Markus Brunner <[email protected]> Signed-off by: Mark Jonas <[email protected]>
---

 boards/magicpanelr2/setup.c    |   83 ++++++++++++++++++++++++++++++++++++++++-
 configs/magicpanelr2_defconfig |    8 ++-
 2 files changed, 86 insertions(+), 5 deletions(-)
arch/sh/boards/magicpanelr2/setup.c +81 -2
index c593065..854bcc6 100644
@@ -12,14 +12,19 @@
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/platform_device.h>
-#include <linux/ide.h>
-#include <linux/irq.h>
 #include <linux/delay.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/map.h>
 #include <asm/magicpanelr2.h>
 #include <asm/heartbeat.h>
 
 #define LAN9115_READY	(ctrl_inl(0xA8000084UL) & 0x00000001UL)
 
+/* Prefer cmdline over RedBoot */
+static const char *probes[] = { "cmdlinepart", "RedBoot", NULL };
+
 /* Wait until reset finished. Timeout is 100ms. */
 static int __init ethernet_reset_finished(void)
 {
@@ -270,13 +275,87 @@ static struct platform_device heartbeat_device = {
 	.resource	= heartbeat_resources,
 };
 
+static struct mtd_partition *parsed_partitions;
+
+static struct mtd_partition mpr2_partitions[] = {
+	/* Reserved for bootloader, read-only */
+	{
+		.name = "Bootloader",
+		.offset = 0x00000000UL,
+		.size = MPR2_MTD_BOOTLOADER_SIZE,
+		.mask_flags = MTD_WRITEABLE,
+	},
+	/* Reserved for kernel image */
+	{
+		.name = "Kernel",
+		.offset = MTDPART_OFS_NXTBLK,
+		.size = MPR2_MTD_KERNEL_SIZE,
+	},
+	/* Rest is used for Flash FS */
+	{
+		.name = "Flash_FS",
+		.offset = MTDPART_OFS_NXTBLK,
+		.size = MTDPART_SIZ_FULL,
+	}
+};
+
+static struct physmap_flash_data flash_data = {
+	.width		= 2,
+};
+
+static struct resource flash_resource = {
+	.start		= 0x00000000,
+	.end		= 0x2000000UL,
+	.flags		= IORESOURCE_MEM,
+};
+
+static struct platform_device flash_device = {
+	.name		= "physmap-flash",
+	.id		= -1,
+	.resource	= &flash_resource,
+	.num_resources	= 1,
+	.dev		= {
+		.platform_data = &flash_data,
+	},
+};
+
+static struct mtd_info *flash_mtd;
+
+struct map_info mpr2_flash_map = {
+	.name = "Magic Panel R2 Flash",
+	.size = 0x2000000UL,
+	.bankwidth = 2,
+};
+
+static void __init set_mtd_partitions(){
+	int nr_parts = 0;
+	simple_map_init(&mpr2_flash_map);
+	flash_mtd = do_map_probe("cfi_probe", &mpr2_flash_map);
+	nr_parts = parse_mtd_partitions(flash_mtd, probes, &parsed_partitions, 0);
+	/* If there is no partition table, used the hard coded table */
+	if (nr_parts <= 0) {
+		flash_data.parts = mpr2_partitions;
+		flash_data.nr_parts = ARRAY_SIZE(mpr2_partitions);
+	} else {
+		flash_data.nr_parts = nr_parts;
+		flash_data.parts = parsed_partitions;
+	}
+}
+
+/*
+ * Add all resources to the platform_device
+ */
+
 static struct platform_device *mpr2_devices[] __initdata = {
 	&heartbeat_device,
 	&smc911x_device,
+	&flash_device,
 };
 
+
 static int __init mpr2_devices_setup(void)
 {
+	set_mtd_partitions();
 	return platform_add_devices(mpr2_devices, ARRAY_SIZE(mpr2_devices));
 }
 device_initcall(mpr2_devices_setup);
arch/sh/configs/magicpanelr2_defconfig +5 -3
index ce4e764..f8398a5 100644
@@ -185,7 +185,7 @@ CONFIG_SH_MAGIC_PANEL_R2=y
 #
 # Magic Panel R2 options
 #
-CONFIG_SH_MAGIC_PANEL_R2_VERSION=2
+CONFIG_SH_MAGIC_PANEL_R2_VERSION=3
 
 #
 # Timer and clock configuration
@@ -404,9 +404,11 @@ CONFIG_MTD_CFI_UTIL=y
 # Mapping drivers for chip access
 #
 # CONFIG_MTD_COMPLEX_MAPPINGS is not set
-# CONFIG_MTD_PHYSMAP is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x0000000
+CONFIG_MTD_PHYSMAP_LEN=0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=0
 # CONFIG_MTD_SOLUTIONENGINE is not set
-CONFIG_MTD_MAGICPANELR2=y
 # CONFIG_MTD_PLATRAM is not set
 
 #
Applied
#4 lore raw

Re: [PATCH] Magic Panel MTD mapping update

Quoted 5 lines · Markus Brunner

this update moves the flash mapping for the Magic Panel into the board setup. It also removes references to the old MTD mapping option in the defconfig.

Signed-off by: Markus Brunner <[email protected]> Signed-off by: Mark Jonas <[email protected]>

Applied, thanks.