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 | * Flash and EPROM on Hitachi Solution Engine and similar boards. |
| 3 | * |
| 4 | * (C) 2001 Red Hat, Inc. |
| 5 | * |
| 6 | * GPL'd |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <linux/mtd/mtd.h> |
| 15 | #include <linux/mtd/map.h> |
| 16 | #include <linux/mtd/partitions.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/errno.h> |
| 18 | |
| 19 | static struct mtd_info *flash_mtd; |
| 20 | static struct mtd_info *eprom_mtd; |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | struct map_info soleng_eprom_map = { |
| 23 | .name = "Solution Engine EPROM", |
| 24 | .size = 0x400000, |
| 25 | .bankwidth = 4, |
| 26 | }; |
| 27 | |
| 28 | struct map_info soleng_flash_map = { |
| 29 | .name = "Solution Engine FLASH", |
| 30 | .size = 0x400000, |
| 31 | .bankwidth = 4, |
| 32 | }; |
| 33 | |
Artem Bityutskiy | 0984c89 | 2013-03-12 10:46:37 +0200 | [diff] [blame] | 34 | static const char * const probes[] = { "RedBoot", "cmdlinepart", NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static int __init init_soleng_maps(void) |
| 37 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | /* First probe at offset 0 */ |
| 39 | soleng_flash_map.phys = 0; |
| 40 | soleng_flash_map.virt = (void __iomem *)P2SEGADDR(0); |
| 41 | soleng_eprom_map.phys = 0x01000000; |
| 42 | soleng_eprom_map.virt = (void __iomem *)P1SEGADDR(0x01000000); |
| 43 | simple_map_init(&soleng_eprom_map); |
| 44 | simple_map_init(&soleng_flash_map); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | printk(KERN_NOTICE "Probing for flash chips at 0x00000000:\n"); |
| 47 | flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map); |
| 48 | if (!flash_mtd) { |
| 49 | /* Not there. Try swapping */ |
| 50 | printk(KERN_NOTICE "Probing for flash chips at 0x01000000:\n"); |
| 51 | soleng_flash_map.phys = 0x01000000; |
| 52 | soleng_flash_map.virt = P2SEGADDR(0x01000000); |
| 53 | soleng_eprom_map.phys = 0; |
| 54 | soleng_eprom_map.virt = P1SEGADDR(0); |
| 55 | flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map); |
| 56 | if (!flash_mtd) { |
| 57 | /* Eep. */ |
| 58 | printk(KERN_NOTICE "Flash chips not detected at either possible location.\n"); |
| 59 | return -ENXIO; |
| 60 | } |
| 61 | } |
| 62 | printk(KERN_NOTICE "Solution Engine: Flash at 0x%08lx, EPROM at 0x%08lx\n", |
| 63 | soleng_flash_map.phys & 0x1fffffff, |
| 64 | soleng_eprom_map.phys & 0x1fffffff); |
| 65 | flash_mtd->owner = THIS_MODULE; |
| 66 | |
| 67 | eprom_mtd = do_map_probe("map_rom", &soleng_eprom_map); |
| 68 | if (eprom_mtd) { |
| 69 | eprom_mtd->owner = THIS_MODULE; |
Jamie Iles | ee0e87b | 2011-05-23 10:23:40 +0100 | [diff] [blame] | 70 | mtd_device_register(eprom_mtd, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Paul Bolle | 390e9ea | 2014-05-23 16:29:54 +0200 | [diff] [blame] | 73 | mtd_device_parse_register(flash_mtd, probes, NULL, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static void __exit cleanup_soleng_maps(void) |
| 79 | { |
| 80 | if (eprom_mtd) { |
Jamie Iles | ee0e87b | 2011-05-23 10:23:40 +0100 | [diff] [blame] | 81 | mtd_device_unregister(eprom_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | map_destroy(eprom_mtd); |
| 83 | } |
| 84 | |
Dmitry Eremin-Solenikov | 7029eef | 2011-06-02 18:00:12 +0400 | [diff] [blame] | 85 | mtd_device_unregister(flash_mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | map_destroy(flash_mtd); |
| 87 | } |
| 88 | |
| 89 | module_init(init_soleng_maps); |
| 90 | module_exit(cleanup_soleng_maps); |
| 91 | |
| 92 | MODULE_LICENSE("GPL"); |
| 93 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); |
| 94 | MODULE_DESCRIPTION("MTD map driver for Hitachi SolutionEngine (and similar) boards"); |
| 95 | |