| 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 |  * Flash memory access on Hynix GMS30C7201/HMS30C7202 based | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 |  * evaluation boards | 
| Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 4 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 |  * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com> | 
| Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 6 |  *     2003 Thomas Gleixner <tglx@linutronix.de> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  */ | 
 | 8 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/module.h> | 
 | 10 | #include <linux/types.h> | 
 | 11 | #include <linux/kernel.h> | 
 | 12 | #include <linux/init.h> | 
 | 13 | #include <linux/errno.h> | 
 | 14 | #include <linux/slab.h> | 
 | 15 |  | 
 | 16 | #include <linux/mtd/mtd.h> | 
 | 17 | #include <linux/mtd/map.h> | 
 | 18 | #include <linux/mtd/partitions.h> | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 19 | #include <mach/hardware.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/io.h> | 
 | 21 |  | 
 | 22 | static struct mtd_info *mymtd; | 
 | 23 |  | 
 | 24 | static struct map_info h720x_map = { | 
 | 25 | 	.name =		"H720X", | 
 | 26 | 	.bankwidth =	4, | 
| Russell King | d9a682a | 2008-11-13 14:53:08 +0000 | [diff] [blame] | 27 | 	.size =		H720X_FLASH_SIZE, | 
 | 28 | 	.phys =		H720X_FLASH_PHYS, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | }; | 
 | 30 |  | 
 | 31 | static struct mtd_partition h720x_partitions[] = { | 
 | 32 |         { | 
 | 33 |                 .name = "ArMon", | 
 | 34 |                 .size = 0x00080000, | 
 | 35 |                 .offset = 0, | 
 | 36 |                 .mask_flags = MTD_WRITEABLE | 
 | 37 |         },{ | 
 | 38 |                 .name = "Env", | 
 | 39 |                 .size = 0x00040000, | 
 | 40 |                 .offset = 0x00080000, | 
 | 41 |                 .mask_flags = MTD_WRITEABLE | 
 | 42 |         },{ | 
 | 43 |                 .name = "Kernel", | 
 | 44 |                 .size = 0x00180000, | 
 | 45 |                 .offset = 0x000c0000, | 
 | 46 |                 .mask_flags = MTD_WRITEABLE | 
 | 47 |         },{ | 
 | 48 |                 .name = "Ramdisk", | 
 | 49 |                 .size = 0x00400000, | 
 | 50 |                 .offset = 0x00240000, | 
 | 51 |                 .mask_flags = MTD_WRITEABLE | 
 | 52 |         },{ | 
 | 53 |                 .name = "jffs2", | 
 | 54 |                 .size = MTDPART_SIZ_FULL, | 
 | 55 |                 .offset = MTDPART_OFS_APPEND | 
 | 56 |         } | 
 | 57 | }; | 
 | 58 |  | 
| Tobias Klauser | 87d10f3 | 2006-03-31 02:29:45 -0800 | [diff] [blame] | 59 | #define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* | 
 | 62 |  * Initialize FLASH support | 
 | 63 |  */ | 
| Dmitri Vorobiev | 2257594 | 2008-11-25 02:54:58 +0200 | [diff] [blame] | 64 | static int __init h720x_mtd_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { | 
| Russell King | d9a682a | 2008-11-13 14:53:08 +0000 | [diff] [blame] | 66 | 	h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 |  | 
 | 68 | 	if (!h720x_map.virt) { | 
 | 69 | 		printk(KERN_ERR "H720x-MTD: ioremap failed\n"); | 
 | 70 | 		return -EIO; | 
 | 71 | 	} | 
 | 72 |  | 
 | 73 | 	simple_map_init(&h720x_map); | 
 | 74 |  | 
 | 75 | 	// Probe for flash bankwidth 4 | 
 | 76 | 	printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n"); | 
 | 77 | 	mymtd = do_map_probe("cfi_probe", &h720x_map); | 
 | 78 | 	if (!mymtd) { | 
 | 79 | 		printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n"); | 
 | 80 | 	    // Probe for bankwidth 2 | 
 | 81 | 	    h720x_map.bankwidth = 2; | 
 | 82 | 	    mymtd = do_map_probe("cfi_probe", &h720x_map); | 
 | 83 | 	} | 
| Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 84 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 	if (mymtd) { | 
 | 86 | 		mymtd->owner = THIS_MODULE; | 
 | 87 |  | 
| Artem Bityutskiy | 42d7fbe | 2012-03-09 19:24:26 +0200 | [diff] [blame] | 88 | 		mtd_device_parse_register(mymtd, NULL, NULL, | 
 | 89 | 					  h720x_partitions, NUM_PARTITIONS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | 		return 0; | 
 | 91 | 	} | 
 | 92 |  | 
 | 93 | 	iounmap((void *)h720x_map.virt); | 
 | 94 | 	return -ENXIO; | 
 | 95 | } | 
 | 96 |  | 
 | 97 | /* | 
 | 98 |  * Cleanup | 
 | 99 |  */ | 
 | 100 | static void __exit h720x_mtd_cleanup(void) | 
 | 101 | { | 
 | 102 |  | 
 | 103 | 	if (mymtd) { | 
| Jamie Iles | 360e40a | 2011-05-23 10:23:03 +0100 | [diff] [blame] | 104 | 		mtd_device_unregister(mymtd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | 		map_destroy(mymtd); | 
 | 106 | 	} | 
| Thomas Gleixner | 69f34c9 | 2005-11-07 11:15:40 +0000 | [diff] [blame] | 107 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | 	if (h720x_map.virt) { | 
 | 109 | 		iounmap((void *)h720x_map.virt); | 
 | 110 | 		h720x_map.virt = 0; | 
 | 111 | 	} | 
 | 112 | } | 
 | 113 |  | 
 | 114 |  | 
 | 115 | module_init(h720x_mtd_init); | 
 | 116 | module_exit(h720x_mtd_cleanup); | 
 | 117 |  | 
 | 118 | MODULE_LICENSE("GPL"); | 
 | 119 | MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>"); | 
 | 120 | MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards"); |