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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #define MSG_PREFIX "impA7:" /* prefix for our printk()'s */ |
| 28 | #define MTDID "impa7-%d" /* for mtdparts= partitioning */ |
| 29 | |
| 30 | static struct mtd_info *impa7_mtd[NUM_FLASHBANKS]; |
| 31 | |
Artem Bityutskiy | 0984c89 | 2013-03-12 10:46:37 +0200 | [diff] [blame] | 32 | static const char * const rom_probe_types[] = { "jedec_probe", NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | static struct map_info impa7_map[NUM_FLASHBANKS] = { |
| 35 | { |
| 36 | .name = "impA7 NOR Flash Bank #0", |
| 37 | .size = WINDOW_SIZE0, |
| 38 | .bankwidth = BUSWIDTH, |
| 39 | }, |
| 40 | { |
| 41 | .name = "impA7 NOR Flash Bank #1", |
| 42 | .size = WINDOW_SIZE1, |
| 43 | .bankwidth = BUSWIDTH, |
| 44 | }, |
| 45 | }; |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /* |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 48 | * MTD partitioning stuff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | */ |
Dmitry Eremin-Solenikov | 5003403 | 2011-06-02 17:59:44 +0400 | [diff] [blame] | 50 | static struct mtd_partition partitions[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
| 52 | { |
| 53 | .name = "FileSystem", |
| 54 | .size = 0x800000, |
| 55 | .offset = 0x00000000 |
| 56 | }, |
| 57 | }; |
| 58 | |
Dmitri Vorobiev | 4f8f3af | 2008-11-25 02:54:59 +0200 | [diff] [blame] | 59 | static int __init init_impa7(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Artem Bityutskiy | 0984c89 | 2013-03-12 10:46:37 +0200 | [diff] [blame] | 61 | const char * const *type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | int i; |
| 63 | static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = { |
| 64 | { WINDOW_ADDR0, WINDOW_SIZE0 }, |
| 65 | { WINDOW_ADDR1, WINDOW_SIZE1 }, |
| 66 | }; |
| 67 | int devicesfound = 0; |
| 68 | |
| 69 | for(i=0; i<NUM_FLASHBANKS; i++) |
| 70 | { |
| 71 | printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n", |
| 72 | pt[i].size, pt[i].addr); |
| 73 | |
| 74 | impa7_map[i].phys = pt[i].addr; |
| 75 | impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size); |
| 76 | if (!impa7_map[i].virt) { |
| 77 | printk(MSG_PREFIX "failed to ioremap\n"); |
| 78 | return -EIO; |
| 79 | } |
| 80 | simple_map_init(&impa7_map[i]); |
| 81 | |
Jingoo Han | d1d90c99 | 2013-08-07 16:12:14 +0900 | [diff] [blame] | 82 | impa7_mtd[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | type = rom_probe_types; |
| 84 | for(; !impa7_mtd[i] && *type; type++) { |
| 85 | impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]); |
| 86 | } |
| 87 | |
| 88 | if (impa7_mtd[i]) { |
| 89 | impa7_mtd[i]->owner = THIS_MODULE; |
| 90 | devicesfound++; |
Artem Bityutskiy | 42d7fbe | 2012-03-09 19:24:26 +0200 | [diff] [blame] | 91 | mtd_device_parse_register(impa7_mtd[i], NULL, NULL, |
Dmitry Eremin-Solenikov | 5003403 | 2011-06-02 17:59:44 +0400 | [diff] [blame] | 92 | partitions, |
| 93 | ARRAY_SIZE(partitions)); |
Jingoo Han | d1d90c99 | 2013-08-07 16:12:14 +0900 | [diff] [blame] | 94 | } else { |
| 95 | iounmap((void __iomem *)impa7_map[i].virt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | return devicesfound == 0 ? -ENXIO : 0; |
| 99 | } |
| 100 | |
| 101 | static void __exit cleanup_impa7(void) |
| 102 | { |
| 103 | int i; |
| 104 | for (i=0; i<NUM_FLASHBANKS; i++) { |
| 105 | if (impa7_mtd[i]) { |
Jamie Iles | 96b639f | 2011-05-23 10:23:04 +0100 | [diff] [blame] | 106 | mtd_device_unregister(impa7_mtd[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | map_destroy(impa7_mtd[i]); |
Jingoo Han | d1d90c99 | 2013-08-07 16:12:14 +0900 | [diff] [blame] | 108 | iounmap((void __iomem *)impa7_map[i].virt); |
| 109 | impa7_map[i].virt = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | module_init(init_impa7); |
| 115 | module_exit(cleanup_impa7); |
| 116 | |
| 117 | MODULE_LICENSE("GPL"); |
| 118 | MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>"); |
| 119 | MODULE_DESCRIPTION("MTD map driver for implementa impA7"); |