2 * Flash memory access on EPXA based devices
4 * (C) 2000 Nicolas Pitre <nico@cam.org>
5 * Copyright (C) 2001 Altera Corporation
6 * Copyright (C) 2001 Red Hat, Inc.
8 * $Id: epxa10db-flash.c,v 1.4 2002/08/22 10:46:19 cdavies Exp $
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/kernel.h>
30 #include <linux/mtd/mtd.h>
31 #include <linux/mtd/map.h>
32 #include <linux/mtd/partitions.h>
34 #include <asm/hardware.h>
35 #ifdef CONFIG_EPXA10DB
36 #define BOARD_NAME "EPXA10DB"
38 #define BOARD_NAME "EPXA1DB"
41 static int nr_parts = 0;
42 static struct mtd_partition *parts;
44 static struct mtd_info *mymtd;
46 extern int parse_redboot_partitions(struct mtd_info *, struct mtd_partition **);
47 static int epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts);
49 static __u8 epxa_read8(struct map_info *map, unsigned long ofs)
51 return __raw_readb(map->map_priv_1 + ofs);
54 static __u16 epxa_read16(struct map_info *map, unsigned long ofs)
56 return __raw_readw(map->map_priv_1 + ofs);
59 static __u32 epxa_read32(struct map_info *map, unsigned long ofs)
61 return __raw_readl(map->map_priv_1 + ofs);
64 static void epxa_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
66 memcpy_fromio(to, (void *)(map->map_priv_1 + from), len);
69 static void epxa_write8(struct map_info *map, __u8 d, unsigned long adr)
71 __raw_writeb(d, map->map_priv_1 + adr);
75 static void epxa_write16(struct map_info *map, __u16 d, unsigned long adr)
77 __raw_writew(d, map->map_priv_1 + adr);
81 static void epxa_write32(struct map_info *map, __u32 d, unsigned long adr)
83 __raw_writel(d, map->map_priv_1 + adr);
87 static void epxa_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
89 memcpy_toio((void *)(map->map_priv_1 + to), from, len);
94 static struct map_info epxa_map = {
101 copy_from: epxa_copy_from,
103 write16: epxa_write16,
104 write32: epxa_write32,
105 copy_to: epxa_copy_to
109 static int __init epxa_mtd_init(void)
113 printk(KERN_NOTICE "%s flash device: %x at %x\n", BOARD_NAME, FLASH_SIZE, FLASH_START);
114 epxa_map.map_priv_1 = (unsigned long)ioremap(FLASH_START, FLASH_SIZE);
115 if (!epxa_map.map_priv_1) {
116 printk("Failed to ioremap %s flash\n",BOARD_NAME);
120 mymtd = do_map_probe("cfi_probe", &epxa_map);
122 iounmap((void *)epxa_map.map_priv_1);
126 mymtd->module = THIS_MODULE;
128 /* Unlock the flash device. */
130 for (i=0; i<mymtd->numeraseregions;i++){
132 for(j=0;j<mymtd->eraseregions[i].numblocks;j++){
133 mymtd->unlock(mymtd,mymtd->eraseregions[i].offset + j * mymtd->eraseregions[i].erasesize,mymtd->eraseregions[i].erasesize);
138 #ifdef CONFIG_MTD_REDBOOT_PARTS
139 nr_parts = parse_redboot_partitions(mymtd, &parts);
142 add_mtd_partitions(mymtd, parts, nr_parts);
146 #ifdef CONFIG_MTD_AFS_PARTS
147 nr_parts = parse_afs_partitions(mymtd, &parts);
150 add_mtd_partitions(mymtd, parts, nr_parts);
155 /* No recognised partitioning schemes found - use defaults */
156 nr_parts = epxa_default_partitions(mymtd, &parts);
158 add_mtd_partitions(mymtd, parts, nr_parts);
162 /* If all else fails... */
163 add_mtd_device(mymtd);
167 static void __exit epxa_mtd_cleanup(void)
171 del_mtd_partitions(mymtd);
173 del_mtd_device(mymtd);
176 if (epxa_map.map_priv_1) {
177 iounmap((void *)epxa_map.map_priv_1);
178 epxa_map.map_priv_1 = 0;
184 * This will do for now, once we decide which bootldr we're finally
185 * going to use then we'll remove this function and do it properly
187 * Partions are currently (as offsets from base of flash):
188 * 0x00000000 - 0x003FFFFF - bootloader (!)
189 * 0x00400000 - 0x00FFFFFF - Flashdisk
192 static int __init epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts)
194 struct mtd_partition *parts;
198 const char *name = "jffs";
200 printk("Using default partitions for %s\n",BOARD_NAME);
202 parts = kmalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL);
203 memzero(parts,npartitions*sizeof(*parts)+strlen(name));
209 names = (char *)&parts[npartitions];
210 parts[i].name = names;
211 names += strlen(name) + 1;
212 strcpy(parts[i].name, name);
214 #ifdef CONFIG_EPXA10DB
215 parts[i].size = FLASH_SIZE-0x00400000;
216 parts[i].offset = 0x00400000;
218 parts[i].size = FLASH_SIZE-0x00180000;
219 parts[i].offset = 0x00180000;
228 module_init(epxa_mtd_init);
229 module_exit(epxa_mtd_cleanup);
231 MODULE_AUTHOR("Clive Davies");
232 MODULE_DESCRIPTION("Altera epxa mtd flash map");
233 MODULE_LICENSE("GPL");