Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Handle mapping of the NOR flash on implementa A7 boards |
| 3 | * |
| 4 | * Copyright 2002 SYSGO Real-Time Solutions GmbH |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <linux/mtd/mtd.h> |
| 17 | #include <linux/mtd/map.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/mtd/partitions.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #define WINDOW_ADDR0 0x00000000 /* physical properties of flash */ |
| 21 | #define WINDOW_SIZE0 0x00800000 |
| 22 | #define WINDOW_ADDR1 0x10000000 /* physical properties of flash */ |
| 23 | #define WINDOW_SIZE1 0x00800000 |
| 24 | #define NUM_FLASHBANKS 2 |
| 25 | #define BUSWIDTH 4 |
| 26 | |
| 27 | /* can be { "cfi_probe", "jedec_probe", "map_rom", NULL } */ |
| 28 | #define PROBETYPES { "jedec_probe", NULL } |
| 29 | |
| 30 | #define MSG_PREFIX "impA7:" /* prefix for our printk()'s */ |
| 31 | #define MTDID "impa7-%d" /* for mtdparts= partitioning */ |
| 32 | |
| 33 | static struct mtd_info *impa7_mtd[NUM_FLASHBANKS]; |
| 34 | |
| 35 | |
| 36 | static struct map_info impa7_map[NUM_FLASHBANKS] = { |
| 37 | { |
| 38 | .name = "impA7 NOR Flash Bank #0", |
| 39 | .size = WINDOW_SIZE0, |
| 40 | .bankwidth = BUSWIDTH, |
| 41 | }, |
| 42 | { |
| 43 | .name = "impA7 NOR Flash Bank #1", |
| 44 | .size = WINDOW_SIZE1, |
| 45 | .bankwidth = BUSWIDTH, |
| 46 | }, |
| 47 | }; |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | /* |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 50 | * MTD partitioning stuff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | */ |
| 52 | static struct mtd_partition static_partitions[] = |
| 53 | { |
| 54 | { |
| 55 | .name = "FileSystem", |
| 56 | .size = 0x800000, |
| 57 | .offset = 0x00000000 |
| 58 | }, |
| 59 | }; |
| 60 | |
| 61 | static int mtd_parts_nb[NUM_FLASHBANKS]; |
| 62 | static struct mtd_partition *mtd_parts[NUM_FLASHBANKS]; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static const char *probes[] = { "cmdlinepart", NULL }; |
| 65 | |
Dmitri Vorobiev | 4f8f3af | 2008-11-25 02:54:59 +0200 | [diff] [blame] | 66 | static int __init init_impa7(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | static const char *rom_probe_types[] = PROBETYPES; |
| 69 | const char **type; |
| 70 | const char *part_type = 0; |
| 71 | int i; |
| 72 | static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = { |
| 73 | { WINDOW_ADDR0, WINDOW_SIZE0 }, |
| 74 | { WINDOW_ADDR1, WINDOW_SIZE1 }, |
| 75 | }; |
| 76 | int devicesfound = 0; |
| 77 | |
| 78 | for(i=0; i<NUM_FLASHBANKS; i++) |
| 79 | { |
| 80 | printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n", |
| 81 | pt[i].size, pt[i].addr); |
| 82 | |
| 83 | impa7_map[i].phys = pt[i].addr; |
| 84 | impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size); |
| 85 | if (!impa7_map[i].virt) { |
| 86 | printk(MSG_PREFIX "failed to ioremap\n"); |
| 87 | return -EIO; |
| 88 | } |
| 89 | simple_map_init(&impa7_map[i]); |
| 90 | |
| 91 | impa7_mtd[i] = 0; |
| 92 | type = rom_probe_types; |
| 93 | for(; !impa7_mtd[i] && *type; type++) { |
| 94 | impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]); |
| 95 | } |
| 96 | |
| 97 | if (impa7_mtd[i]) { |
| 98 | impa7_mtd[i]->owner = THIS_MODULE; |
| 99 | devicesfound++; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 100 | mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | probes, |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 102 | &mtd_parts[i], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | 0); |
| 104 | if (mtd_parts_nb[i] > 0) { |
| 105 | part_type = "command line"; |
| 106 | } else { |
| 107 | mtd_parts[i] = static_partitions; |
| 108 | mtd_parts_nb[i] = ARRAY_SIZE(static_partitions); |
| 109 | part_type = "static"; |
| 110 | } |
| 111 | |
| 112 | printk(KERN_NOTICE MSG_PREFIX |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 113 | "using %s partition definition\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | part_type); |
Jamie Iles | 96b639f | 2011-05-23 10:23:04 +0100 | [diff] [blame^] | 115 | mtd_device_register(impa7_mtd[i], |
| 116 | mtd_parts[i], mtd_parts_nb[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 118 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | iounmap((void *)impa7_map[i].virt); |
| 120 | } |
| 121 | return devicesfound == 0 ? -ENXIO : 0; |
| 122 | } |
| 123 | |
| 124 | static void __exit cleanup_impa7(void) |
| 125 | { |
| 126 | int i; |
| 127 | for (i=0; i<NUM_FLASHBANKS; i++) { |
| 128 | if (impa7_mtd[i]) { |
Jamie Iles | 96b639f | 2011-05-23 10:23:04 +0100 | [diff] [blame^] | 129 | mtd_device_unregister(impa7_mtd[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | map_destroy(impa7_mtd[i]); |
| 131 | iounmap((void *)impa7_map[i].virt); |
| 132 | impa7_map[i].virt = 0; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | module_init(init_impa7); |
| 138 | module_exit(cleanup_impa7); |
| 139 | |
| 140 | MODULE_LICENSE("GPL"); |
| 141 | MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>"); |
| 142 | MODULE_DESCRIPTION("MTD map driver for implementa impA7"); |