mtd/drivers/mtd/maps integrator-flash.c,1.12,1.13
Russell King
rmk at infradead.org
Sat Oct 11 05:48:33 EDT 2003
Update of /home/cvs/mtd/drivers/mtd/maps
In directory phoenix.infradead.org:/tmp/cvs-serv20139
Modified Files:
integrator-flash.c
Log Message:
integrator-flash.c for 2.6 kernels only.
Updates:
- use driver model.
- pass platform specific information via dev->platform_data
- remove all platform specific info from integrator-flash.c
Index: integrator-flash.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/integrator-flash.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- integrator-flash.c 20 May 2003 20:59:30 -0000 1.12
+++ integrator-flash.c 11 Oct 2003 09:48:30 -0000 1.13
@@ -31,223 +31,181 @@
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/ioport.h>
+#include <linux/device.h>
#include <linux/init.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
+#include <asm/mach/flash.h>
#include <asm/hardware.h>
#include <asm/io.h>
#include <asm/system.h>
-// board specific stuff - sorry, it should be in arch/arm/mach-*.
-#ifdef CONFIG_ARCH_INTEGRATOR
-
-#define FLASH_BASE INTEGRATOR_FLASH_BASE
-#define FLASH_SIZE INTEGRATOR_FLASH_SIZE
-
-#define FLASH_PART_SIZE 0x400000
-
-#define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
-#define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
-#define EBI_CSR1 (IO_ADDRESS(INTEGRATOR_EBI_BASE) + INTEGRATOR_EBI_CSR1_OFFSET)
-#define EBI_LOCK (IO_ADDRESS(INTEGRATOR_EBI_BASE) + INTEGRATOR_EBI_LOCK_OFFSET)
-
-/*
- * Initialise the flash access systems:
- * - Disable VPP
- * - Assert WP
- * - Set write enable bit in EBI reg
- */
-static void armflash_flash_init(void)
-{
- unsigned int tmp;
-
- __raw_writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
-
- tmp = __raw_readl(EBI_CSR1) | INTEGRATOR_EBI_WRITE_ENABLE;
- __raw_writel(tmp, EBI_CSR1);
-
- if (!(__raw_readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE)) {
- __raw_writel(0xa05f, EBI_LOCK);
- __raw_writel(tmp, EBI_CSR1);
- __raw_writel(0, EBI_LOCK);
- }
-}
-
-/*
- * Shutdown the flash access systems:
- * - Disable VPP
- * - Assert WP
- * - Clear write enable bit in EBI reg
- */
-static void armflash_flash_exit(void)
-{
- unsigned int tmp;
-
- __raw_writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
-
- /*
- * Clear the write enable bit in system controller EBI register.
- */
- tmp = __raw_readl(EBI_CSR1) & ~INTEGRATOR_EBI_WRITE_ENABLE;
- __raw_writel(tmp, EBI_CSR1);
-
- if (__raw_readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE) {
- __raw_writel(0xa05f, EBI_LOCK);
- __raw_writel(tmp, EBI_CSR1);
- __raw_writel(0, EBI_LOCK);
- }
-}
-
-static void armflash_flash_wp(int on)
-{
- unsigned int reg;
-
- if (on)
- reg = SC_CTRLC;
- else
- reg = SC_CTRLS;
-
- __raw_writel(INTEGRATOR_SC_CTRL_nFLWP, reg);
-}
-
-static void armflash_set_vpp(struct map_info *map, int on)
-{
- unsigned int reg;
-
- if (on)
- reg = SC_CTRLS;
- else
- reg = SC_CTRLC;
-
- __raw_writel(INTEGRATOR_SC_CTRL_nFLVPPEN, reg);
-}
-#endif
-
#ifdef CONFIG_ARCH_P720T
-
#define FLASH_BASE (0x04000000)
#define FLASH_SIZE (64*1024*1024)
+#endif
-#define FLASH_PART_SIZE (4*1024*1024)
-#define FLASH_BLOCK_SIZE (128*1024)
+struct armflash_info {
+ struct flash_platform_data *plat;
+ struct resource *res;
+ struct mtd_partition *parts;
+ struct mtd_info *mtd;
+ struct map_info map;
+};
-static void armflash_flash_init(void)
+static void armflash_set_vpp(struct map_info *map, int on)
{
-}
+ struct armflash_info *info = container_of(map, struct armflash_info, map);
-static void armflash_flash_exit(void)
-{
+ if (info->plat && info->plat->set_vpp)
+ info->plat->set_vpp(on);
}
-static void armflash_flash_wp(int on)
-{
-}
+static const char *probes[] = { "RedBoot", "afs", NULL };
-static void armflash_set_vpp(struct map_info *map, int on)
+static int armflash_probe(struct device *_dev)
{
-}
-#endif
+ struct platform_device *dev = to_platform_device(_dev);
+ struct flash_platform_data *plat = dev->dev.platform_data;
+ struct resource *res = dev->resource;
+ unsigned int size = res->end - res->start + 1;
+ struct armflash_info *info;
+ int err;
+ void *base;
+ info = kmalloc(sizeof(struct armflash_info), GFP_KERNEL);
+ if (!info) {
+ err = -ENOMEM;
+ goto out;
+ }
-static struct map_info armflash_map =
-{
- .name = "AFS",
- .set_vpp = armflash_set_vpp,
- .phys = FLASH_BASE,
-};
+ memset(info, 0, sizeof(struct armflash_info));
-static struct mtd_info *mtd;
-static struct mtd_partition *parts;
-static const char *probes[] = { "RedBoot", "afs", NULL };
+ info->plat = plat;
+ if (plat && plat->init) {
+ err = plat->init();
+ if (err)
+ goto no_resource;
+ }
-static int __init armflash_cfi_init(void *base, u_int size)
-{
- int ret;
+ info->res = request_mem_region(res->start, size, "armflash");
+ if (!info->res) {
+ err = -EBUSY;
+ goto no_resource;
+ }
- armflash_flash_init();
- armflash_flash_wp(1);
+ base = ioremap(res->start, size);
+ if (!base) {
+ err = -ENOMEM;
+ goto no_mem;
+ }
/*
* look for CFI based flash parts fitted to this board
*/
- armflash_map.size = size;
- armflash_map.buswidth = 4;
- armflash_map.virt = (unsigned long) base;
+ info->map.size = size;
+ info->map.buswidth = plat->width;
+ info->map.phys = res->start;
+ info->map.virt = (unsigned long) base;
+ info->map.name = dev->dev.bus_id;
+ info->map.set_vpp = armflash_set_vpp;
- simple_map_init(&armflash_map);
+ simple_map_init(&info->map);
/*
* Also, the CFI layer automatically works out what size
* of chips we have, and does the necessary identification
* for us automatically.
*/
- mtd = do_map_probe("cfi_probe", &armflash_map);
- if (!mtd)
- return -ENXIO;
-
- mtd->owner = THIS_MODULE;
-
- ret = parse_mtd_partitions(mtd, probes, &parts, (void *)0);
- if (ret > 0) {
- ret = add_mtd_partitions(mtd, parts, ret);
- if (ret)
- printk(KERN_ERR "mtd partition registration "
- "failed: %d\n", ret);
+ info->mtd = do_map_probe(plat->map_name, &info->map);
+ if (!info->mtd) {
+ err = -ENXIO;
+ goto no_device;
}
+ info->mtd->owner = THIS_MODULE;
+
+ err = parse_mtd_partitions(info->mtd, probes, &info->parts, 0);
+ if (err > 0) {
+ err = add_mtd_partitions(info->mtd, info->parts, err);
+ if (err)
+ printk(KERN_ERR
+ "mtd partition registration failed: %d\n", err);
+ }
+
+ if (err == 0)
+ dev_set_drvdata(&dev->dev, info);
+
/*
* If we got an error, free all resources.
*/
- if (ret < 0) {
- del_mtd_partitions(mtd);
- map_destroy(mtd);
- }
+ if (err < 0) {
+ if (info->mtd) {
+ del_mtd_partitions(info->mtd);
+ map_destroy(info->mtd);
+ }
+ if (info->parts)
+ kfree(info->parts);
- return ret;
-}
-
-static void armflash_cfi_exit(void)
-{
- if (mtd) {
- del_mtd_partitions(mtd);
- map_destroy(mtd);
+ no_device:
+ iounmap(base);
+ no_mem:
+ release_mem_region(res->start, size);
+ no_resource:
+ if (plat && plat->exit)
+ plat->exit();
+ kfree(info);
}
- if (parts)
- kfree(parts);
+ out:
+ return err;
}
-static int __init armflash_init(void)
+static int armflash_remove(struct device *_dev)
{
- int err = -EBUSY;
- void *base;
+ struct platform_device *dev = to_platform_device(_dev);
+ struct armflash_info *info = dev_get_drvdata(&dev->dev);
- if (request_mem_region(FLASH_BASE, FLASH_SIZE, "flash") == NULL)
- goto out;
+ dev_set_drvdata(&dev->dev, NULL);
- base = ioremap(FLASH_BASE, FLASH_SIZE);
- err = -ENOMEM;
- if (base == NULL)
- goto release;
+ if (info) {
+ if (info->mtd) {
+ del_mtd_partitions(info->mtd);
+ map_destroy(info->mtd);
+ }
+ if (info->parts)
+ kfree(info->parts);
- err = armflash_cfi_init(base, FLASH_SIZE);
- if (err) {
- iounmap(base);
-release:
- release_mem_region(FLASH_BASE, FLASH_SIZE);
+ iounmap((void *)info->map.virt);
+ release_resource(info->res);
+ kfree(info->res);
+
+ if (info->plat && info->plat->exit)
+ info->plat->exit();
+
+ kfree(info);
}
-out:
- return err;
+
+ return 0;
+}
+
+static struct device_driver armflash_driver = {
+ .name = "armflash",
+ .bus = &platform_bus_type,
+ .probe = armflash_probe,
+ .remove = armflash_remove,
+};
+
+static int __init armflash_init(void)
+{
+ return driver_register(&armflash_driver);
}
static void __exit armflash_exit(void)
{
- armflash_cfi_exit();
- iounmap((void *)armflash_map.virt);
- release_mem_region(FLASH_BASE, FLASH_SIZE);
- armflash_flash_exit();
+ driver_unregister(&armflash_driver);
}
module_init(armflash_init);
More information about the linux-mtd-cvs
mailing list