blob: dc37652700570e3c6899fb881f1269fc17e8d270 [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 *
Thomas Gleixner69f34c92005-11-07 11:15:40 +00008 * $Id: omap-toto-flash.c,v 1.5 2005/11/07 11:14:27 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/errno.h>
16#include <linux/init.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080017#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
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
Thomas Gleixner69f34c92005-11-07 11:15:40 +000041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static 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,
Thomas Gleixner69f34c92005-11-07 11:15:40 +000057 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070058};
59
60static struct mtd_partition *parsed_parts;
61
62static struct mtd_info *flash_mtd;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000063
64static int __init init_flash (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66
67 struct mtd_partition *parts;
68 int nb_parts = 0;
69 int parsed_nr_parts = 0;
70 const char *part_type;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 /*
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;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 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}
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000111
112int __init omap_toto_mtd_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
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
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000122static void __exit omap_toto_mtd_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 if (flash_mtd) {
125 del_mtd_partitions(flash_mtd);
126 map_destroy(flash_mtd);
Jesper Juhlfa671642005-11-07 01:01:27 -0800127 kfree(parsed_parts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129}
130
131module_init(omap_toto_mtd_init);
132module_exit(omap_toto_mtd_cleanup);
133
134MODULE_AUTHOR("Jian Zhang");
135MODULE_DESCRIPTION("OMAP Toto board map driver");
136MODULE_LICENSE("GPL");