Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 2 | * $Id: lubbock-flash.c,v 1.21 2005/11/07 11:14:27 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Map driver for the Lubbock developer platform. |
| 5 | * |
| 6 | * Author: Nicolas Pitre |
| 7 | * Copyright: (C) 2001 MontaVista Software Inc. |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/mtd/mtd.h> |
| 20 | #include <linux/mtd/map.h> |
| 21 | #include <linux/mtd/partitions.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <asm/hardware.h> |
| 25 | #include <asm/arch/pxa-regs.h> |
| 26 | #include <asm/arch/lubbock.h> |
Jared Hulbert | 90833fd | 2007-08-22 17:38:25 +0100 | [diff] [blame] | 27 | #include <asm/cacheflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #define ROM_ADDR 0x00000000 |
| 30 | #define FLASH_ADDR 0x04000000 |
| 31 | |
| 32 | #define WINDOW_SIZE 64*1024*1024 |
| 33 | |
| 34 | static void lubbock_map_inval_cache(struct map_info *map, unsigned long from, ssize_t len) |
| 35 | { |
Jared Hulbert | 90833fd | 2007-08-22 17:38:25 +0100 | [diff] [blame] | 36 | flush_ioremap_region(map->phys, map->cached, from, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static struct map_info lubbock_maps[2] = { { |
| 40 | .size = WINDOW_SIZE, |
| 41 | .phys = 0x00000000, |
| 42 | .inval_cache = lubbock_map_inval_cache, |
| 43 | }, { |
| 44 | .size = WINDOW_SIZE, |
| 45 | .phys = 0x04000000, |
| 46 | .inval_cache = lubbock_map_inval_cache, |
| 47 | } }; |
| 48 | |
| 49 | static struct mtd_partition lubbock_partitions[] = { |
| 50 | { |
| 51 | .name = "Bootloader", |
| 52 | .size = 0x00040000, |
| 53 | .offset = 0, |
| 54 | .mask_flags = MTD_WRITEABLE /* force read-only */ |
| 55 | },{ |
| 56 | .name = "Kernel", |
| 57 | .size = 0x00100000, |
| 58 | .offset = 0x00040000, |
| 59 | },{ |
| 60 | .name = "Filesystem", |
| 61 | .size = MTDPART_SIZ_FULL, |
| 62 | .offset = 0x00140000 |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | static struct mtd_info *mymtds[2]; |
| 67 | static struct mtd_partition *parsed_parts[2]; |
| 68 | static int nr_parsed_parts[2]; |
| 69 | |
| 70 | static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; |
| 71 | |
| 72 | static int __init init_lubbock(void) |
| 73 | { |
| 74 | int flashboot = (LUB_CONF_SWITCHES & 1); |
| 75 | int ret = 0, i; |
| 76 | |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 77 | lubbock_maps[0].bankwidth = lubbock_maps[1].bankwidth = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | (BOOT_DEF & 1) ? 2 : 4; |
| 79 | |
| 80 | /* Compensate for the nROMBT switch which swaps the flash banks */ |
| 81 | printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n", |
| 82 | flashboot?"Flash":"ROM", flashboot); |
| 83 | |
| 84 | lubbock_maps[flashboot^1].name = "Lubbock Application Flash"; |
| 85 | lubbock_maps[flashboot].name = "Lubbock Boot ROM"; |
| 86 | |
| 87 | for (i = 0; i < 2; i++) { |
| 88 | lubbock_maps[i].virt = ioremap(lubbock_maps[i].phys, WINDOW_SIZE); |
| 89 | if (!lubbock_maps[i].virt) { |
| 90 | printk(KERN_WARNING "Failed to ioremap %s\n", lubbock_maps[i].name); |
| 91 | if (!ret) |
| 92 | ret = -ENOMEM; |
| 93 | continue; |
| 94 | } |
| 95 | lubbock_maps[i].cached = ioremap_cached(lubbock_maps[i].phys, WINDOW_SIZE); |
| 96 | if (!lubbock_maps[i].cached) |
| 97 | printk(KERN_WARNING "Failed to ioremap cached %s\n", lubbock_maps[i].name); |
| 98 | simple_map_init(&lubbock_maps[i]); |
| 99 | |
| 100 | printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit bankwidth)\n", |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 101 | lubbock_maps[i].name, lubbock_maps[i].phys, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | lubbock_maps[i].bankwidth * 8); |
| 103 | |
| 104 | mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | if (!mymtds[i]) { |
| 107 | iounmap((void *)lubbock_maps[i].virt); |
| 108 | if (lubbock_maps[i].cached) |
| 109 | iounmap(lubbock_maps[i].cached); |
| 110 | if (!ret) |
| 111 | ret = -EIO; |
| 112 | continue; |
| 113 | } |
| 114 | mymtds[i]->owner = THIS_MODULE; |
| 115 | |
| 116 | ret = parse_mtd_partitions(mymtds[i], probes, |
| 117 | &parsed_parts[i], 0); |
| 118 | |
| 119 | if (ret > 0) |
| 120 | nr_parsed_parts[i] = ret; |
| 121 | } |
| 122 | |
| 123 | if (!mymtds[0] && !mymtds[1]) |
| 124 | return ret; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | for (i = 0; i < 2; i++) { |
| 127 | if (!mymtds[i]) { |
| 128 | printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name); |
| 129 | } else if (nr_parsed_parts[i]) { |
| 130 | add_mtd_partitions(mymtds[i], parsed_parts[i], nr_parsed_parts[i]); |
| 131 | } else if (!i) { |
| 132 | printk("Using static partitions on %s\n", lubbock_maps[i].name); |
| 133 | add_mtd_partitions(mymtds[i], lubbock_partitions, ARRAY_SIZE(lubbock_partitions)); |
| 134 | } else { |
| 135 | printk("Registering %s as whole device\n", lubbock_maps[i].name); |
| 136 | add_mtd_device(mymtds[i]); |
| 137 | } |
| 138 | } |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static void __exit cleanup_lubbock(void) |
| 143 | { |
| 144 | int i; |
| 145 | for (i = 0; i < 2; i++) { |
| 146 | if (!mymtds[i]) |
| 147 | continue; |
| 148 | |
| 149 | if (nr_parsed_parts[i] || !i) |
| 150 | del_mtd_partitions(mymtds[i]); |
| 151 | else |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 152 | del_mtd_device(mymtds[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | map_destroy(mymtds[i]); |
| 155 | iounmap((void *)lubbock_maps[i].virt); |
| 156 | if (lubbock_maps[i].cached) |
| 157 | iounmap(lubbock_maps[i].cached); |
| 158 | |
Jesper Juhl | fa67164 | 2005-11-07 01:01:27 -0800 | [diff] [blame] | 159 | kfree(parsed_parts[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
| 163 | module_init(init_lubbock); |
| 164 | module_exit(cleanup_lubbock); |
| 165 | |
| 166 | MODULE_LICENSE("GPL"); |
| 167 | MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>"); |
| 168 | MODULE_DESCRIPTION("MTD map driver for Intel Lubbock"); |