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: dbox2-flash.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * D-Box 2 flash driver |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <linux/mtd/mtd.h> |
| 13 | #include <linux/mtd/map.h> |
| 14 | #include <linux/mtd/partitions.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/errno.h> |
| 16 | |
| 17 | /* partition_info gives details on the logical partitions that the split the |
| 18 | * single flash device into. If the size if zero we use up to the end of the |
| 19 | * device. */ |
| 20 | static struct mtd_partition partition_info[]= { |
| 21 | { |
| 22 | .name = "BR bootloader", |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 23 | .size = 128 * 1024, |
| 24 | .offset = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | .mask_flags = MTD_WRITEABLE |
| 26 | }, |
| 27 | { |
| 28 | .name = "FLFS (U-Boot)", |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 29 | .size = 128 * 1024, |
| 30 | .offset = MTDPART_OFS_APPEND, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | .mask_flags = 0 |
| 32 | }, |
| 33 | { |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 34 | .name = "Root (SquashFS)", |
| 35 | .size = 7040 * 1024, |
| 36 | .offset = MTDPART_OFS_APPEND, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | .mask_flags = 0 |
| 38 | }, |
| 39 | { |
| 40 | .name = "var (JFFS2)", |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 41 | .size = 896 * 1024, |
| 42 | .offset = MTDPART_OFS_APPEND, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | .mask_flags = 0 |
| 44 | }, |
| 45 | { |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 46 | .name = "Flash without bootloader", |
| 47 | .size = MTDPART_SIZ_FULL, |
| 48 | .offset = 128 * 1024, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | .mask_flags = 0 |
| 50 | }, |
| 51 | { |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 52 | .name = "Complete Flash", |
| 53 | .size = MTDPART_SIZ_FULL, |
| 54 | .offset = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .mask_flags = MTD_WRITEABLE |
| 56 | } |
| 57 | }; |
| 58 | |
Tobias Klauser | 87d10f3 | 2006-03-31 02:29:45 -0800 | [diff] [blame] | 59 | #define NUM_PARTITIONS ARRAY_SIZE(partition_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | #define WINDOW_ADDR 0x10000000 |
| 62 | #define WINDOW_SIZE 0x800000 |
| 63 | |
| 64 | static struct mtd_info *mymtd; |
| 65 | |
| 66 | |
| 67 | struct map_info dbox2_flash_map = { |
| 68 | .name = "D-Box 2 flash memory", |
| 69 | .size = WINDOW_SIZE, |
| 70 | .bankwidth = 4, |
| 71 | .phys = WINDOW_ADDR, |
| 72 | }; |
| 73 | |
| 74 | int __init init_dbox2_flash(void) |
| 75 | { |
| 76 | printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)\n", WINDOW_SIZE, WINDOW_ADDR); |
| 77 | dbox2_flash_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE); |
| 78 | |
| 79 | if (!dbox2_flash_map.virt) { |
| 80 | printk("Failed to ioremap\n"); |
| 81 | return -EIO; |
| 82 | } |
| 83 | simple_map_init(&dbox2_flash_map); |
| 84 | |
| 85 | // Probe for dual Intel 28F320 or dual AMD |
| 86 | mymtd = do_map_probe("cfi_probe", &dbox2_flash_map); |
| 87 | if (!mymtd) { |
| 88 | // Probe for single Intel 28F640 |
| 89 | dbox2_flash_map.bankwidth = 2; |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | mymtd = do_map_probe("cfi_probe", &dbox2_flash_map); |
| 92 | } |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if (mymtd) { |
| 95 | mymtd->owner = THIS_MODULE; |
| 96 | |
| 97 | /* Create MTD devices for each partition. */ |
| 98 | add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS); |
Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | iounmap((void *)dbox2_flash_map.virt); |
| 104 | return -ENXIO; |
| 105 | } |
| 106 | |
| 107 | static void __exit cleanup_dbox2_flash(void) |
| 108 | { |
| 109 | if (mymtd) { |
| 110 | del_mtd_partitions(mymtd); |
| 111 | map_destroy(mymtd); |
| 112 | } |
| 113 | if (dbox2_flash_map.virt) { |
| 114 | iounmap((void *)dbox2_flash_map.virt); |
| 115 | dbox2_flash_map.virt = 0; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | module_init(init_dbox2_flash); |
| 120 | module_exit(cleanup_dbox2_flash); |
| 121 | |
| 122 | |
| 123 | MODULE_LICENSE("GPL"); |
David Woodhouse | 151e765 | 2006-05-14 01:51:54 +0100 | [diff] [blame] | 124 | MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>, Bastian Blank <waldi@tuxbox.org>, Alexander Wild <wild@te-elektronik.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | MODULE_DESCRIPTION("MTD map driver for D-Box 2 board"); |