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