OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [mtd/] [maps/] [epxa10db-flash.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * Flash memory access on EPXA based devices
3
 *
4
 * (C) 2000 Nicolas Pitre <nico@cam.org>
5
 *  Copyright (C) 2001 Altera Corporation
6
 *  Copyright (C) 2001 Red Hat, Inc.
7
 *
8
 * $Id: epxa10db-flash.c,v 1.1.1.1 2004-04-15 01:51:54 phoenix Exp $
9
 *
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.
14
 *
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.
19
 *
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
23
 */
24
 
25
#include <linux/config.h>
26
#include <linux/module.h>
27
#include <linux/types.h>
28
#include <linux/kernel.h>
29
#include <asm/io.h>
30
#include <linux/mtd/mtd.h>
31
#include <linux/mtd/map.h>
32
#include <linux/mtd/partitions.h>
33
 
34
#include <asm/hardware.h>
35
#ifdef CONFIG_EPXA10DB
36
#define BOARD_NAME "EPXA10DB"
37
#else
38
#define BOARD_NAME "EPXA1DB"
39
#endif
40
 
41
static int nr_parts = 0;
42
static struct mtd_partition *parts;
43
 
44
static struct mtd_info *mymtd;
45
 
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);
48
 
49
static __u8 epxa_read8(struct map_info *map, unsigned long ofs)
50
{
51
        return __raw_readb(map->map_priv_1 + ofs);
52
}
53
 
54
static __u16 epxa_read16(struct map_info *map, unsigned long ofs)
55
{
56
        return __raw_readw(map->map_priv_1 + ofs);
57
}
58
 
59
static __u32 epxa_read32(struct map_info *map, unsigned long ofs)
60
{
61
        return __raw_readl(map->map_priv_1 + ofs);
62
}
63
 
64
static void epxa_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
65
{
66
        memcpy_fromio(to, (void *)(map->map_priv_1 + from), len);
67
}
68
 
69
static void epxa_write8(struct map_info *map, __u8 d, unsigned long adr)
70
{
71
        __raw_writeb(d, map->map_priv_1 + adr);
72
        mb();
73
}
74
 
75
static void epxa_write16(struct map_info *map, __u16 d, unsigned long adr)
76
{
77
        __raw_writew(d, map->map_priv_1 + adr);
78
        mb();
79
}
80
 
81
static void epxa_write32(struct map_info *map, __u32 d, unsigned long adr)
82
{
83
        __raw_writel(d, map->map_priv_1 + adr);
84
        mb();
85
}
86
 
87
static void epxa_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
88
{
89
        memcpy_toio((void *)(map->map_priv_1 + to), from, len);
90
}
91
 
92
 
93
 
94
static struct map_info epxa_map = {
95
        name:           "EPXA flash",
96
        size:           FLASH_SIZE,
97
        buswidth:       2,
98
        read8:          epxa_read8,
99
        read16:         epxa_read16,
100
        read32:         epxa_read32,
101
        copy_from:      epxa_copy_from,
102
        write8:         epxa_write8,
103
        write16:        epxa_write16,
104
        write32:        epxa_write32,
105
        copy_to:        epxa_copy_to
106
};
107
 
108
 
109
static int __init epxa_mtd_init(void)
110
{
111
        int i;
112
 
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);
117
                return -EIO;
118
        }
119
 
120
        mymtd = do_map_probe("cfi_probe", &epxa_map);
121
        if (!mymtd) {
122
                iounmap((void *)epxa_map.map_priv_1);
123
                return -ENXIO;
124
        }
125
 
126
        mymtd->module = THIS_MODULE;
127
 
128
        /* Unlock the flash device. */
129
        if(mymtd->unlock){
130
                for (i=0; i<mymtd->numeraseregions;i++){
131
                        int j;
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);
134
                        }
135
                }
136
        }
137
 
138
#ifdef CONFIG_MTD_REDBOOT_PARTS
139
        nr_parts = parse_redboot_partitions(mymtd, &parts);
140
 
141
        if (nr_parts > 0) {
142
                add_mtd_partitions(mymtd, parts, nr_parts);
143
                return 0;
144
        }
145
#endif
146
#ifdef CONFIG_MTD_AFS_PARTS
147
        nr_parts = parse_afs_partitions(mymtd, &parts);
148
 
149
        if (nr_parts > 0) {
150
                add_mtd_partitions(mymtd, parts, nr_parts);
151
                return 0;
152
        }
153
#endif
154
 
155
        /* No recognised partitioning schemes found - use defaults */
156
        nr_parts = epxa_default_partitions(mymtd, &parts);
157
        if (nr_parts > 0) {
158
                add_mtd_partitions(mymtd, parts, nr_parts);
159
                return 0;
160
        }
161
 
162
        /* If all else fails... */
163
        add_mtd_device(mymtd);
164
        return 0;
165
}
166
 
167
static void __exit epxa_mtd_cleanup(void)
168
{
169
        if (mymtd) {
170
                if (nr_parts)
171
                        del_mtd_partitions(mymtd);
172
                else
173
                        del_mtd_device(mymtd);
174
                map_destroy(mymtd);
175
        }
176
        if (epxa_map.map_priv_1) {
177
                iounmap((void *)epxa_map.map_priv_1);
178
                epxa_map.map_priv_1 = 0;
179
        }
180
}
181
 
182
 
183
/*
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
186
 *
187
 * Partions are currently (as offsets from base of flash):
188
 * 0x00000000 - 0x003FFFFF - bootloader (!)
189
 * 0x00400000 - 0x00FFFFFF - Flashdisk
190
 */
191
 
192
static int __init epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts)
193
{
194
        struct mtd_partition *parts;
195
        int ret, i;
196
        int npartitions = 0;
197
        char *names;
198
        const char *name = "jffs";
199
 
200
        printk("Using default partitions for %s\n",BOARD_NAME);
201
        npartitions=1;
202
        parts = kmalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL);
203
        memzero(parts,npartitions*sizeof(*parts)+strlen(name));
204
        if (!parts) {
205
                ret = -ENOMEM;
206
                goto out;
207
        }
208
        i=0;
209
        names = (char *)&parts[npartitions];
210
        parts[i].name = names;
211
        names += strlen(name) + 1;
212
        strcpy(parts[i].name, name);
213
 
214
#ifdef CONFIG_EPXA10DB
215
        parts[i].size = FLASH_SIZE-0x00400000;
216
        parts[i].offset = 0x00400000;
217
#else
218
        parts[i].size = FLASH_SIZE-0x00180000;
219
        parts[i].offset = 0x00180000;
220
#endif
221
 
222
 out:
223
        *pparts = parts;
224
        return npartitions;
225
}
226
 
227
 
228
module_init(epxa_mtd_init);
229
module_exit(epxa_mtd_cleanup);
230
 
231
MODULE_AUTHOR("Clive Davies");
232
MODULE_DESCRIPTION("Altera epxa mtd flash map");
233
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.