Create platform_device.h to contain all the platform device details.
[deliverable/linux.git] / drivers / mtd / maps / omap_nor.c
CommitLineData
10c96f2e
TP
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
d052d1be 33#include <linux/platform_device.h>
10c96f2e
TP
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/mtd/mtd.h>
40#include <linux/mtd/map.h>
41#include <linux/mtd/partitions.h>
42
43#include <asm/io.h>
44#include <asm/hardware.h>
10c96f2e
TP
45#include <asm/mach/flash.h>
46#include <asm/arch/tc.h>
47
48#ifdef CONFIG_MTD_PARTITIONS
49static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL };
50#endif
51
52struct omapflash_info {
53 struct mtd_partition *parts;
54 struct mtd_info *mtd;
55 struct map_info map;
56};
57
58static void omap_set_vpp(struct map_info *map, int enable)
59{
60 static int count;
61
62 if (enable) {
63 if (count++ == 0)
64 OMAP_EMIFS_CONFIG_REG |= OMAP_EMIFS_CONFIG_WP;
65 } else {
66 if (count && (--count == 0))
67 OMAP_EMIFS_CONFIG_REG &= ~OMAP_EMIFS_CONFIG_WP;
68 }
69}
70
71static int __devinit omapflash_probe(struct device *dev)
72{
73 int err;
74 struct omapflash_info *info;
75 struct platform_device *pdev = to_platform_device(dev);
76 struct flash_platform_data *pdata = pdev->dev.platform_data;
77 struct resource *res = pdev->resource;
78 unsigned long size = res->end - res->start + 1;
79
80 info = kmalloc(sizeof(struct omapflash_info), GFP_KERNEL);
81 if (!info)
82 return -ENOMEM;
83
84 memset(info, 0, sizeof(struct omapflash_info));
85
86 if (!request_mem_region(res->start, size, "flash")) {
87 err = -EBUSY;
88 goto out_free_info;
89 }
90
91 info->map.virt = ioremap(res->start, size);
92 if (!info->map.virt) {
93 err = -ENOMEM;
94 goto out_release_mem_region;
95 }
96 info->map.name = pdev->dev.bus_id;
97 info->map.phys = res->start;
98 info->map.size = size;
99 info->map.bankwidth = pdata->width;
100 info->map.set_vpp = omap_set_vpp;
101
102 simple_map_init(&info->map);
103 info->mtd = do_map_probe(pdata->map_name, &info->map);
104 if (!info->mtd) {
105 err = -EIO;
106 goto out_iounmap;
107 }
108 info->mtd->owner = THIS_MODULE;
109
110#ifdef CONFIG_MTD_PARTITIONS
111 err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0);
112 if (err > 0)
113 add_mtd_partitions(info->mtd, info->parts, err);
114 else if (err < 0 && pdata->parts)
115 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
116 else
117#endif
118 add_mtd_device(info->mtd);
119
120 dev_set_drvdata(&pdev->dev, info);
121
122 return 0;
123
124out_iounmap:
125 iounmap(info->map.virt);
126out_release_mem_region:
127 release_mem_region(res->start, size);
128out_free_info:
129 kfree(info);
130
131 return err;
132}
133
134static int __devexit omapflash_remove(struct device *dev)
135{
136 struct platform_device *pdev = to_platform_device(dev);
137 struct omapflash_info *info = dev_get_drvdata(&pdev->dev);
138
139 dev_set_drvdata(&pdev->dev, NULL);
140
141 if (info) {
142 if (info->parts) {
143 del_mtd_partitions(info->mtd);
144 kfree(info->parts);
145 } else
146 del_mtd_device(info->mtd);
147 map_destroy(info->mtd);
148 release_mem_region(info->map.phys, info->map.size);
149 iounmap((void __iomem *) info->map.virt);
150 kfree(info);
151 }
152
153 return 0;
154}
155
156static struct device_driver omapflash_driver = {
157 .name = "omapflash",
158 .bus = &platform_bus_type,
159 .probe = omapflash_probe,
160 .remove = __devexit_p(omapflash_remove),
161};
162
163static int __init omapflash_init(void)
164{
165 return driver_register(&omapflash_driver);
166}
167
168static void __exit omapflash_exit(void)
169{
170 driver_unregister(&omapflash_driver);
171}
172
173module_init(omapflash_init);
174module_exit(omapflash_exit);
175
176MODULE_LICENSE("GPL");
177MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");
178
This page took 0.064748 seconds and 5 git commands to generate.