]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/mtd/maps/omap_nor.c
Merge with /home/tmlind/src/kernel/linux-2.6
[linux-2.6-omap-h63xx.git] / drivers / mtd / maps / omap_nor.c
1 /*
2  * Flash memory support for various TI OMAP boards
3  *
4  * Copyright (C) 2001-2002 MontaVista Software Inc.
5  * Copyright (C) 2003-2004 Texas Instruments
6  * Copyright (C) 2004 Nokia Corporation
7  *
8  *      Assembled using driver code copyright the companies above
9  *      and written by David Brownell, Jian Zhang <jzhang@ti.com>,
10  *      Tony Lindgren <tony@atomide.com> and others.
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation; either version 2 of the License, or (at your
15  * option) any later version.
16  *
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * You should have received a copy of the  GNU General Public License along
29  * with this program; if not, write  to the Free Software Foundation, Inc.,
30  * 675 Mass Ave, Cambridge, MA 02139, USA.
31  */
32
33 #include <linux/platform_device.h>
34 #include <linux/module.h>
35 #include <linux/types.h>
36 #include <linux/kernel.h>
37 #include <linux/init.h>
38 #include <linux/ioport.h>
39 #include <linux/slab.h>
40
41 #include <linux/mtd/mtd.h>
42 #include <linux/mtd/map.h>
43 #include <linux/mtd/partitions.h>
44
45 #include <asm/io.h>
46 #include <asm/hardware.h>
47 #include <asm/mach/flash.h>
48 #include <asm/arch/tc.h>
49
50 #ifdef CONFIG_MTD_PARTITIONS
51 static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL };
52 #endif
53
54 struct omapflash_info {
55         struct mtd_partition    *parts;
56         struct mtd_info         *mtd;
57         struct map_info         map;
58 };
59
60 static void omap_set_vpp(struct map_info *map, int enable)
61 {
62         static int      count;
63
64         if (!cpu_is_omap24xx()) {
65                 if (enable) {
66                         if (count++ == 0)
67                                 OMAP_EMIFS_CONFIG_REG |= OMAP_EMIFS_CONFIG_WP;
68                 } else {
69                         if (count && (--count == 0))
70                                 OMAP_EMIFS_CONFIG_REG &= ~OMAP_EMIFS_CONFIG_WP;
71                 }
72         }
73 }
74
75 static int __devinit omapflash_probe(struct platform_device *pdev)
76 {
77         int err;
78         struct omapflash_info *info;
79         struct flash_platform_data *pdata = pdev->dev.platform_data;
80         struct resource *res = pdev->resource;
81         unsigned long size = res->end - res->start + 1;
82
83         info = kmalloc(sizeof(struct omapflash_info), GFP_KERNEL);
84         if (!info)
85                 return -ENOMEM;
86
87         memset(info, 0, sizeof(struct omapflash_info));
88
89         if (!request_mem_region(res->start, size, "flash")) {
90                 err = -EBUSY;
91                 goto out_free_info;
92         }
93
94         info->map.virt          = ioremap(res->start, size);
95         if (!info->map.virt) {
96                 err = -ENOMEM;
97                 goto out_release_mem_region;
98         }
99         info->map.name          = pdev->dev.bus_id;
100         info->map.phys          = res->start;
101         info->map.size          = size;
102         info->map.bankwidth     = pdata->width;
103         info->map.set_vpp       = omap_set_vpp;
104
105         simple_map_init(&info->map);
106         info->mtd = do_map_probe(pdata->map_name, &info->map);
107         if (!info->mtd) {
108                 err = -EIO;
109                 goto out_iounmap;
110         }
111         info->mtd->owner = THIS_MODULE;
112
113 #ifdef CONFIG_MTD_PARTITIONS
114         err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0);
115         if (err > 0)
116                 add_mtd_partitions(info->mtd, info->parts, err);
117         else if (err < 0 && pdata->parts)
118                 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
119         else
120 #endif
121                 add_mtd_device(info->mtd);
122
123         platform_set_drvdata(pdev, info);
124
125         return 0;
126
127 out_iounmap:
128         iounmap(info->map.virt);
129 out_release_mem_region:
130         release_mem_region(res->start, size);
131 out_free_info:
132         kfree(info);
133
134         return err;
135 }
136
137 static int __devexit omapflash_remove(struct platform_device *pdev)
138 {
139         struct omapflash_info *info = platform_get_drvdata(pdev);
140         struct flash_platform_data *pdata = pdev->dev.platform_data;
141
142         platform_set_drvdata(pdev, NULL);
143
144         if (info) {
145                 if (info->parts || (pdata && pdata->parts)) {
146                         del_mtd_partitions(info->mtd);
147                         kfree(info->parts);
148                 } else
149                         del_mtd_device(info->mtd);
150                 map_destroy(info->mtd);
151                 release_mem_region(info->map.phys, info->map.size);
152                 iounmap((void __iomem *) info->map.virt);
153                 kfree(info);
154         }
155
156         return 0;
157 }
158
159 static struct platform_driver omapflash_driver = {
160         .probe  = omapflash_probe,
161         .remove = __devexit_p(omapflash_remove),
162         .driver = {
163                 .name   = "omapflash",
164         },
165 };
166
167 static int __init omapflash_init(void)
168 {
169         return platform_driver_register(&omapflash_driver);
170 }
171
172 static void __exit omapflash_exit(void)
173 {
174         platform_driver_unregister(&omapflash_driver);
175 }
176
177 module_init(omapflash_init);
178 module_exit(omapflash_exit);
179
180 MODULE_LICENSE("GPL");
181 MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");
182