blob: 6dde3182d64a6966d1b6247bc52dd5ee25c8c78b [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 *
5 * $Id: h720x-flash.c,v 1.12 2005/11/07 11:14:27 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com>
Thomas Gleixner69f34c92005-11-07 11:15:40 +00008 * 2003 Thomas Gleixner <tglx@linutronix.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/slab.h>
17
18#include <linux/mtd/mtd.h>
19#include <linux/mtd/map.h>
20#include <linux/mtd/partitions.h>
21#include <asm/hardware.h>
22#include <asm/io.h>
23
24static struct mtd_info *mymtd;
25
26static struct map_info h720x_map = {
27 .name = "H720X",
28 .bankwidth = 4,
29 .size = FLASH_SIZE,
30 .phys = FLASH_PHYS,
31};
32
33static struct mtd_partition h720x_partitions[] = {
34 {
35 .name = "ArMon",
36 .size = 0x00080000,
37 .offset = 0,
38 .mask_flags = MTD_WRITEABLE
39 },{
40 .name = "Env",
41 .size = 0x00040000,
42 .offset = 0x00080000,
43 .mask_flags = MTD_WRITEABLE
44 },{
45 .name = "Kernel",
46 .size = 0x00180000,
47 .offset = 0x000c0000,
48 .mask_flags = MTD_WRITEABLE
49 },{
50 .name = "Ramdisk",
51 .size = 0x00400000,
52 .offset = 0x00240000,
53 .mask_flags = MTD_WRITEABLE
54 },{
55 .name = "jffs2",
56 .size = MTDPART_SIZ_FULL,
57 .offset = MTDPART_OFS_APPEND
58 }
59};
60
Tobias Klauser87d10f32006-03-31 02:29:45 -080061#define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63static int nr_mtd_parts;
64static struct mtd_partition *mtd_parts;
65static const char *probes[] = { "cmdlinepart", NULL };
66
67/*
68 * Initialize FLASH support
69 */
70int __init h720x_mtd_init(void)
71{
72
73 char *part_type = NULL;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 h720x_map.virt = ioremap(FLASH_PHYS, FLASH_SIZE);
76
77 if (!h720x_map.virt) {
78 printk(KERN_ERR "H720x-MTD: ioremap failed\n");
79 return -EIO;
80 }
81
82 simple_map_init(&h720x_map);
83
84 // Probe for flash bankwidth 4
85 printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n");
86 mymtd = do_map_probe("cfi_probe", &h720x_map);
87 if (!mymtd) {
88 printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n");
89 // Probe for bankwidth 2
90 h720x_map.bankwidth = 2;
91 mymtd = do_map_probe("cfi_probe", &h720x_map);
92 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 if (mymtd) {
95 mymtd->owner = THIS_MODULE;
96
97#ifdef CONFIG_MTD_PARTITIONS
98 nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0);
99 if (nr_mtd_parts > 0)
100 part_type = "command line";
101#endif
102 if (nr_mtd_parts <= 0) {
103 mtd_parts = h720x_partitions;
104 nr_mtd_parts = NUM_PARTITIONS;
105 part_type = "builtin";
106 }
107 printk(KERN_INFO "Using %s partition table\n", part_type);
108 add_mtd_partitions(mymtd, mtd_parts, nr_mtd_parts);
109 return 0;
110 }
111
112 iounmap((void *)h720x_map.virt);
113 return -ENXIO;
114}
115
116/*
117 * Cleanup
118 */
119static void __exit h720x_mtd_cleanup(void)
120{
121
122 if (mymtd) {
123 del_mtd_partitions(mymtd);
124 map_destroy(mymtd);
125 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* Free partition info, if commandline partition was used */
128 if (mtd_parts && (mtd_parts != h720x_partitions))
129 kfree (mtd_parts);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 if (h720x_map.virt) {
132 iounmap((void *)h720x_map.virt);
133 h720x_map.virt = 0;
134 }
135}
136
137
138module_init(h720x_mtd_init);
139module_exit(h720x_mtd_cleanup);
140
141MODULE_LICENSE("GPL");
142MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
143MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards");