Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * NOR Flash memory access on TI Toto board |
| 3 | * |
| 4 | * jzhang@ti.com (C) 2003 Texas Instruments. |
| 5 | * |
| 6 | * (C) 2002 MontVista Software, Inc. |
| 7 | * |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 8 | * $Id: omap-toto-flash.c,v 1.5 2005/11/07 11:14:27 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/errno.h> |
| 15 | #include <linux/init.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 16 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include <linux/mtd/mtd.h> |
| 19 | #include <linux/mtd/map.h> |
| 20 | #include <linux/mtd/partitions.h> |
| 21 | |
| 22 | #include <asm/hardware.h> |
| 23 | #include <asm/io.h> |
| 24 | |
| 25 | |
| 26 | #ifndef CONFIG_ARCH_OMAP |
| 27 | #error This is for OMAP architecture only |
| 28 | #endif |
| 29 | |
| 30 | //these lines need be moved to a hardware header file |
| 31 | #define OMAP_TOTO_FLASH_BASE 0xd8000000 |
| 32 | #define OMAP_TOTO_FLASH_SIZE 0x80000 |
| 33 | |
| 34 | static struct map_info omap_toto_map_flash = { |
| 35 | .name = "OMAP Toto flash", |
| 36 | .bankwidth = 2, |
| 37 | .virt = (void __iomem *)OMAP_TOTO_FLASH_BASE, |
| 38 | }; |
| 39 | |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static struct mtd_partition toto_flash_partitions[] = { |
| 42 | { |
| 43 | .name = "BootLoader", |
| 44 | .size = 0x00040000, /* hopefully u-boot will stay 128k + 128*/ |
| 45 | .offset = 0, |
| 46 | .mask_flags = MTD_WRITEABLE, /* force read-only */ |
| 47 | }, { |
| 48 | .name = "ReservedSpace", |
| 49 | .size = 0x00030000, |
| 50 | .offset = MTDPART_OFS_APPEND, |
| 51 | //mask_flags: MTD_WRITEABLE, /* force read-only */ |
| 52 | }, { |
| 53 | .name = "EnvArea", /* bottom 64KiB for env vars */ |
| 54 | .size = MTDPART_SIZ_FULL, |
| 55 | .offset = MTDPART_OFS_APPEND, |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 56 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static struct mtd_partition *parsed_parts; |
| 60 | |
| 61 | static struct mtd_info *flash_mtd; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 62 | |
| 63 | static int __init init_flash (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | |
| 66 | struct mtd_partition *parts; |
| 67 | int nb_parts = 0; |
| 68 | int parsed_nr_parts = 0; |
| 69 | const char *part_type; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Static partition definition selection |
| 73 | */ |
| 74 | part_type = "static"; |
| 75 | |
| 76 | parts = toto_flash_partitions; |
| 77 | nb_parts = ARRAY_SIZE(toto_flash_partitions); |
| 78 | omap_toto_map_flash.size = OMAP_TOTO_FLASH_SIZE; |
| 79 | omap_toto_map_flash.phys = virt_to_phys(OMAP_TOTO_FLASH_BASE); |
| 80 | |
| 81 | simple_map_init(&omap_toto_map_flash); |
| 82 | /* |
| 83 | * Now let's probe for the actual flash. Do it here since |
| 84 | * specific machine settings might have been set above. |
| 85 | */ |
| 86 | printk(KERN_NOTICE "OMAP toto flash: probing %d-bit flash bus\n", |
| 87 | omap_toto_map_flash.bankwidth*8); |
| 88 | flash_mtd = do_map_probe("jedec_probe", &omap_toto_map_flash); |
| 89 | if (!flash_mtd) |
| 90 | return -ENXIO; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (parsed_nr_parts > 0) { |
| 93 | parts = parsed_parts; |
| 94 | nb_parts = parsed_nr_parts; |
| 95 | } |
| 96 | |
| 97 | if (nb_parts == 0) { |
| 98 | printk(KERN_NOTICE "OMAP toto flash: no partition info available," |
| 99 | "registering whole flash at once\n"); |
| 100 | if (add_mtd_device(flash_mtd)){ |
| 101 | return -ENXIO; |
| 102 | } |
| 103 | } else { |
| 104 | printk(KERN_NOTICE "Using %s partition definition\n", |
| 105 | part_type); |
| 106 | return add_mtd_partitions(flash_mtd, parts, nb_parts); |
| 107 | } |
| 108 | return 0; |
| 109 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 110 | |
| 111 | int __init omap_toto_mtd_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | int status; |
| 114 | |
| 115 | if (status = init_flash()) { |
| 116 | printk(KERN_ERR "OMAP Toto Flash: unable to init map for toto flash\n"); |
| 117 | } |
| 118 | return status; |
| 119 | } |
| 120 | |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 121 | static void __exit omap_toto_mtd_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | if (flash_mtd) { |
| 124 | del_mtd_partitions(flash_mtd); |
| 125 | map_destroy(flash_mtd); |
Jesper Juhl | fa67164 | 2005-11-07 01:01:27 -0800 | [diff] [blame] | 126 | kfree(parsed_parts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | module_init(omap_toto_mtd_init); |
| 131 | module_exit(omap_toto_mtd_cleanup); |
| 132 | |
| 133 | MODULE_AUTHOR("Jian Zhang"); |
| 134 | MODULE_DESCRIPTION("OMAP Toto board map driver"); |
| 135 | MODULE_LICENSE("GPL"); |