1 /* linux/drivers/mtd/maps/bast_flash.c
3 * Copyright (c) 2004 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * Simtec Bast (EB2410ITX) NOR MTD Mapping driver
9 * 20-Sep-2004 BJD Initial version
11 * $Id: bast-flash.c,v 1.1 2004/09/21 14:29:04 bjd Exp $
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/module.h>
29 #include <linux/types.h>
30 #include <linux/init.h>
31 #include <linux/kernel.h>
32 #include <linux/string.h>
33 #include <linux/ioport.h>
34 #include <linux/device.h>
36 #include <linux/mtd/mtd.h>
37 #include <linux/mtd/map.h>
38 #include <linux/mtd/partitions.h>
41 #include <asm/mach-types.h>
42 #include <asm/mach/flash.h>
44 #include <asm/arch/map.h>
45 #include <asm/arch/bast-map.h>
46 #include <asm/arch/bast-cpld.h>
48 #ifdef CONFIG_MTD_BAST_MAXSIZE
49 #define AREA_MAXSIZE (CONFIG_MTD_BAST_MAXSIZE * (1024*1024))
51 #define AREA_MAXSIZE (32*1024*1024)
54 #define PFX "bast-flash: "
56 struct bast_flash_info
{
59 struct mtd_partition
*partitions
;
60 struct resource
*area
;
63 static const char *probes
[] = { "RedBoot", "cmdlinepart", NULL
};
65 static struct bast_flash_info
*to_bast_info(struct device
*dev
)
67 return (struct bast_flash_info
*)dev_get_drvdata(dev
);
70 static void bast_flash_setrw(int to
)
75 local_irq_save(flags
);
76 val
= __raw_readb(BAST_VA_CTRL3
);
79 val
|= BAST_CPLD_CTRL3_ROMWEN
;
81 val
&= ~BAST_CPLD_CTRL3_ROMWEN
;
83 pr_debug("new cpld ctrl3=%02x\n", val
);
85 __raw_writeb(val
, BAST_VA_CTRL3
);
86 local_irq_restore(flags
);
89 static int bast_flash_remove(struct device
*dev
)
91 struct bast_flash_info
*info
= to_bast_info(dev
);
93 dev_set_drvdata(dev
, NULL
);
98 if (info
->map
.virt
!= NULL
)
99 iounmap(info
->map
.virt
);
102 del_mtd_partitions(info
->mtd
);
103 map_destroy(info
->mtd
);
106 if (info
->partitions
)
107 kfree(info
->partitions
);
110 release_resource(info
->area
);
119 static int bast_flash_probe(struct device
*dev
)
121 struct platform_device
*pdev
= to_platform_device(dev
);
122 struct bast_flash_info
*info
;
123 struct resource
*res
;
126 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
128 printk(KERN_ERR PFX
"no memory for flash info\n");
133 memzero(info
, sizeof(*info
));
134 dev_set_drvdata(dev
, info
);
136 res
= pdev
->resource
; /* assume that the flash has one resource */
138 info
->map
.phys
= res
->start
;
139 info
->map
.size
= res
->end
- res
->start
+ 1;
140 info
->map
.name
= dev
->bus_id
;
141 info
->map
.bankwidth
= 2;
143 if (info
->map
.size
> AREA_MAXSIZE
)
144 info
->map
.size
= AREA_MAXSIZE
;
146 pr_debug("%s: area %08lx, size %ld\n", __FUNCTION__
,
147 info
->map
.phys
, info
->map
.size
);
149 info
->area
= request_mem_region(res
->start
, info
->map
.size
,
151 if (info
->area
== NULL
) {
152 printk(KERN_ERR PFX
"cannot reserve flash memory region\n");
157 info
->map
.virt
= ioremap(res
->start
, info
->map
.size
);
158 pr_debug("%s: virt at %08x\n", __FUNCTION__
, (int)info
->map
.virt
);
160 if (info
->map
.virt
== 0) {
161 printk(KERN_ERR PFX
"failed to ioremap() region\n");
166 simple_map_init(&info
->map
);
168 /* enable the write to the flash area */
172 /* probe for the device(s) */
174 info
->mtd
= do_map_probe("jedec_probe", &info
->map
);
175 if (info
->mtd
== NULL
)
176 info
->mtd
= do_map_probe("cfi_probe", &info
->map
);
178 if (info
->mtd
== NULL
) {
179 printk(KERN_ERR PFX
"map_probe() failed\n");
184 /* mark ourselves as the owner */
185 info
->mtd
->owner
= THIS_MODULE
;
187 err
= parse_mtd_partitions(info
->mtd
, probes
, &info
->partitions
, 0);
189 err
= add_mtd_partitions(info
->mtd
, info
->partitions
, err
);
191 printk(KERN_ERR PFX
"cannot add/parse partitions\n");
197 /* fall through to exit error */
200 bast_flash_remove(dev
);
204 static struct device_driver bast_flash_driver
= {
206 .bus
= &platform_bus_type
,
207 .probe
= bast_flash_probe
,
208 .remove
= bast_flash_remove
,
211 static int __init
bast_flash_init(void)
213 printk("BAST NOR-Flash Driver, (c) 2004 Simtec Electronics\n");
214 return driver_register(&bast_flash_driver
);
217 static void __exit
bast_flash_exit(void)
219 driver_unregister(&bast_flash_driver
);
222 module_init(bast_flash_init
);
223 module_exit(bast_flash_exit
);
225 MODULE_LICENSE("GPL");
226 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
227 MODULE_DESCRIPTION("BAST MTD Map driver");