blob: 496109071cb10dc86bb828a0654ff295660f1ac0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * NOR Flash memory access on TI Toto board
3 *
4 * jzhang@ti.com (C) 2003 Texas Instruments.
5 *
6 * (C) 2002 MontVista Software, Inc.
7 *
8 * $Id: omap-toto-flash.c,v 1.3 2004/09/16 23:27:13 gleixner Exp $
9 */
10
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/kernel.h>
15
16#include <linux/errno.h>
17#include <linux/init.h>
18
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h>
21#include <linux/mtd/partitions.h>
22
23#include <asm/hardware.h>
24#include <asm/io.h>
25
26
27#ifndef CONFIG_ARCH_OMAP
28#error This is for OMAP architecture only
29#endif
30
31//these lines need be moved to a hardware header file
32#define OMAP_TOTO_FLASH_BASE 0xd8000000
33#define OMAP_TOTO_FLASH_SIZE 0x80000
34
35static struct map_info omap_toto_map_flash = {
36 .name = "OMAP Toto flash",
37 .bankwidth = 2,
38 .virt = (void __iomem *)OMAP_TOTO_FLASH_BASE,
39};
40
41
42static struct mtd_partition toto_flash_partitions[] = {
43 {
44 .name = "BootLoader",
45 .size = 0x00040000, /* hopefully u-boot will stay 128k + 128*/
46 .offset = 0,
47 .mask_flags = MTD_WRITEABLE, /* force read-only */
48 }, {
49 .name = "ReservedSpace",
50 .size = 0x00030000,
51 .offset = MTDPART_OFS_APPEND,
52 //mask_flags: MTD_WRITEABLE, /* force read-only */
53 }, {
54 .name = "EnvArea", /* bottom 64KiB for env vars */
55 .size = MTDPART_SIZ_FULL,
56 .offset = MTDPART_OFS_APPEND,
57 }
58};
59
60static struct mtd_partition *parsed_parts;
61
62static struct mtd_info *flash_mtd;
63
64static int __init init_flash (void)
65{
66
67 struct mtd_partition *parts;
68 int nb_parts = 0;
69 int parsed_nr_parts = 0;
70 const char *part_type;
71
72 /*
73 * Static partition definition selection
74 */
75 part_type = "static";
76
77 parts = toto_flash_partitions;
78 nb_parts = ARRAY_SIZE(toto_flash_partitions);
79 omap_toto_map_flash.size = OMAP_TOTO_FLASH_SIZE;
80 omap_toto_map_flash.phys = virt_to_phys(OMAP_TOTO_FLASH_BASE);
81
82 simple_map_init(&omap_toto_map_flash);
83 /*
84 * Now let's probe for the actual flash. Do it here since
85 * specific machine settings might have been set above.
86 */
87 printk(KERN_NOTICE "OMAP toto flash: probing %d-bit flash bus\n",
88 omap_toto_map_flash.bankwidth*8);
89 flash_mtd = do_map_probe("jedec_probe", &omap_toto_map_flash);
90 if (!flash_mtd)
91 return -ENXIO;
92
93 if (parsed_nr_parts > 0) {
94 parts = parsed_parts;
95 nb_parts = parsed_nr_parts;
96 }
97
98 if (nb_parts == 0) {
99 printk(KERN_NOTICE "OMAP toto flash: no partition info available,"
100 "registering whole flash at once\n");
101 if (add_mtd_device(flash_mtd)){
102 return -ENXIO;
103 }
104 } else {
105 printk(KERN_NOTICE "Using %s partition definition\n",
106 part_type);
107 return add_mtd_partitions(flash_mtd, parts, nb_parts);
108 }
109 return 0;
110}
111
112int __init omap_toto_mtd_init(void)
113{
114 int status;
115
116 if (status = init_flash()) {
117 printk(KERN_ERR "OMAP Toto Flash: unable to init map for toto flash\n");
118 }
119 return status;
120}
121
122static void __exit omap_toto_mtd_cleanup(void)
123{
124 if (flash_mtd) {
125 del_mtd_partitions(flash_mtd);
126 map_destroy(flash_mtd);
127 if (parsed_parts)
128 kfree(parsed_parts);
129 }
130}
131
132module_init(omap_toto_mtd_init);
133module_exit(omap_toto_mtd_cleanup);
134
135MODULE_AUTHOR("Jian Zhang");
136MODULE_DESCRIPTION("OMAP Toto board map driver");
137MODULE_LICENSE("GPL");