blob: 7f035860a36bd43b8683945804fee50690f32351 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Thomas Gleixner69f34c92005-11-07 11:15:40 +00002 * Flash memory access on Hynix GMS30C7201/HMS30C7202 based
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * evaluation boards
Thomas Gleixner69f34c92005-11-07 11:15:40 +00004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com>
Thomas Gleixner69f34c92005-11-07 11:15:40 +00006 * 2003 Thomas Gleixner <tglx@linutronix.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#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 Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/io.h>
21
22static struct mtd_info *mymtd;
23
24static struct map_info h720x_map = {
25 .name = "H720X",
26 .bankwidth = 4,
Russell Kingd9a682a2008-11-13 14:53:08 +000027 .size = H720X_FLASH_SIZE,
28 .phys = H720X_FLASH_PHYS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029};
30
31static 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 Klauser87d10f32006-03-31 02:29:45 -080059#define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static int nr_mtd_parts;
62static struct mtd_partition *mtd_parts;
63static const char *probes[] = { "cmdlinepart", NULL };
64
65/*
66 * Initialize FLASH support
67 */
Dmitri Vorobiev22575942008-11-25 02:54:58 +020068static int __init h720x_mtd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70
71 char *part_type = NULL;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000072
Russell Kingd9a682a2008-11-13 14:53:08 +000073 h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 if (!h720x_map.virt) {
76 printk(KERN_ERR "H720x-MTD: ioremap failed\n");
77 return -EIO;
78 }
79
80 simple_map_init(&h720x_map);
81
82 // Probe for flash bankwidth 4
83 printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n");
84 mymtd = do_map_probe("cfi_probe", &h720x_map);
85 if (!mymtd) {
86 printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n");
87 // Probe for bankwidth 2
88 h720x_map.bankwidth = 2;
89 mymtd = do_map_probe("cfi_probe", &h720x_map);
90 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 if (mymtd) {
93 mymtd->owner = THIS_MODULE;
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0);
96 if (nr_mtd_parts > 0)
97 part_type = "command line";
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (nr_mtd_parts <= 0) {
99 mtd_parts = h720x_partitions;
100 nr_mtd_parts = NUM_PARTITIONS;
101 part_type = "builtin";
102 }
103 printk(KERN_INFO "Using %s partition table\n", part_type);
Jamie Iles360e40a2011-05-23 10:23:03 +0100104 mtd_device_register(mymtd, mtd_parts, nr_mtd_parts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return 0;
106 }
107
108 iounmap((void *)h720x_map.virt);
109 return -ENXIO;
110}
111
112/*
113 * Cleanup
114 */
115static void __exit h720x_mtd_cleanup(void)
116{
117
118 if (mymtd) {
Jamie Iles360e40a2011-05-23 10:23:03 +0100119 mtd_device_unregister(mymtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 map_destroy(mymtd);
121 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 /* Free partition info, if commandline partition was used */
124 if (mtd_parts && (mtd_parts != h720x_partitions))
125 kfree (mtd_parts);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if (h720x_map.virt) {
128 iounmap((void *)h720x_map.virt);
129 h720x_map.virt = 0;
130 }
131}
132
133
134module_init(h720x_mtd_init);
135module_exit(h720x_mtd_cleanup);
136
137MODULE_LICENSE("GPL");
138MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
139MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards");