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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [mtd/] [maps/] [impa7.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * $Id: impa7.c,v 1.1.1.1 2004-04-15 01:51:55 phoenix Exp $
3
 *
4
 * Handle mapping of the NOR flash on implementa A7 boards
5
 *
6
 * Copyright 2002 SYSGO Real-Time Solutions GmbH
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License version 2 as
10
 * published by the Free Software Foundation.
11
 */
12
 
13
#include <linux/module.h>
14
#include <linux/types.h>
15
#include <linux/kernel.h>
16
#include <asm/io.h>
17
#include <linux/mtd/mtd.h>
18
#include <linux/mtd/map.h>
19
#include <linux/config.h>
20
 
21
#ifdef CONFIG_MTD_PARTITIONS
22
#include <linux/mtd/partitions.h>
23
#endif
24
 
25
#define WINDOW_ADDR0 0x00000000      /* physical properties of flash */
26
#define WINDOW_SIZE0 0x00800000
27
#define WINDOW_ADDR1 0x10000000      /* physical properties of flash */
28
#define WINDOW_SIZE1 0x00800000
29
#define NUM_FLASHBANKS 2
30
#define BUSWIDTH     4
31
 
32
/* can be { "cfi_probe", "jedec_probe", "map_rom", 0 }; */
33
#define PROBETYPES { "jedec_probe", 0 }
34
 
35
#define MSG_PREFIX "impA7:"   /* prefix for our printk()'s */
36
#define MTDID      "impa7-%d"  /* for mtdparts= partitioning */
37
 
38
static struct mtd_info *impa7_mtd[NUM_FLASHBANKS] = { 0 };
39
 
40
__u8 impa7_read8(struct map_info *map, unsigned long ofs)
41
{
42
        return __raw_readb(map->map_priv_1 + ofs);
43
}
44
 
45
__u16 impa7_read16(struct map_info *map, unsigned long ofs)
46
{
47
        return __raw_readw(map->map_priv_1 + ofs);
48
}
49
 
50
__u32 impa7_read32(struct map_info *map, unsigned long ofs)
51
{
52
        return __raw_readl(map->map_priv_1 + ofs);
53
}
54
 
55
void impa7_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
56
{
57
        memcpy_fromio(to, map->map_priv_1 + from, len);
58
}
59
 
60
void impa7_write8(struct map_info *map, __u8 d, unsigned long adr)
61
{
62
        __raw_writeb(d, map->map_priv_1 + adr);
63
        mb();
64
}
65
 
66
void impa7_write16(struct map_info *map, __u16 d, unsigned long adr)
67
{
68
        __raw_writew(d, map->map_priv_1 + adr);
69
        mb();
70
}
71
 
72
void impa7_write32(struct map_info *map, __u32 d, unsigned long adr)
73
{
74
        __raw_writel(d, map->map_priv_1 + adr);
75
        mb();
76
}
77
 
78
void impa7_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
79
{
80
        memcpy_toio(map->map_priv_1 + to, from, len);
81
}
82
 
83
static struct map_info impa7_map[NUM_FLASHBANKS] = {
84
        {
85
        name: "impA7 NOR Flash Bank #0",
86
        size: WINDOW_SIZE0,
87
        buswidth: BUSWIDTH,
88
        read8: impa7_read8,
89
        read16: impa7_read16,
90
        read32: impa7_read32,
91
        copy_from: impa7_copy_from,
92
        write8: impa7_write8,
93
        write16: impa7_write16,
94
        write32: impa7_write32,
95
        copy_to: impa7_copy_to
96
        },
97
        {
98
        name: "impA7 NOR Flash Bank #1",
99
        size: WINDOW_SIZE1,
100
        buswidth: BUSWIDTH,
101
        read8: impa7_read8,
102
        read16: impa7_read16,
103
        read32: impa7_read32,
104
        copy_from: impa7_copy_from,
105
        write8: impa7_write8,
106
        write16: impa7_write16,
107
        write32: impa7_write32,
108
        copy_to: impa7_copy_to
109
        },
110
};
111
 
112
#ifdef CONFIG_MTD_PARTITIONS
113
 
114
/*
115
 * MTD partitioning stuff
116
 */
117
static struct mtd_partition static_partitions[] =
118
{
119
    {
120
        name: "FileSystem",
121
          size: 0x800000,
122
          offset: 0x00000000
123
    },
124
};
125
 
126
#define NB_OF(x) (sizeof (x) / sizeof (x[0]))
127
 
128
#ifdef CONFIG_MTD_CMDLINE_PARTS
129
int parse_cmdline_partitions(struct mtd_info *master,
130
                             struct mtd_partition **pparts,
131
                             const char *mtd_id);
132
#endif
133
 
134
#endif
135
 
136
static int                   mtd_parts_nb = 0;
137
static struct mtd_partition *mtd_parts    = 0;
138
 
139
int __init init_impa7(void)
140
{
141
        static const char *rom_probe_types[] = PROBETYPES;
142
        const char **type;
143
        const char *part_type = 0;
144
        int i;
145
        static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
146
          { WINDOW_ADDR0, WINDOW_SIZE0 },
147
          { WINDOW_ADDR1, WINDOW_SIZE1 },
148
        };
149
        char mtdid[10];
150
        int devicesfound = 0;
151
 
152
        for(i=0; i<NUM_FLASHBANKS; i++)
153
        {
154
                printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
155
                       pt[i].size, pt[i].addr);
156
                impa7_map[i].map_priv_1 = (unsigned long)
157
                  ioremap(pt[i].addr, pt[i].size);
158
 
159
                if (!impa7_map[i].map_priv_1) {
160
                        printk(MSG_PREFIX "failed to ioremap\n");
161
                        return -EIO;
162
                }
163
 
164
                impa7_mtd[i] = 0;
165
                type = rom_probe_types;
166
                for(; !impa7_mtd[i] && *type; type++) {
167
                        impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
168
                }
169
 
170
                if (impa7_mtd[i])
171
                {
172
                        impa7_mtd[i]->module = THIS_MODULE;
173
                        add_mtd_device(impa7_mtd[i]);
174
                        devicesfound++;
175
#ifdef CONFIG_MTD_PARTITIONS
176
#ifdef CONFIG_MTD_CMDLINE_PARTS
177
                        sprintf(mtdid, MTDID, i);
178
                        mtd_parts_nb = parse_cmdline_partitions(impa7_mtd[i],
179
                                                                &mtd_parts,
180
                                                                mtdid);
181
                        if (mtd_parts_nb > 0)
182
                          part_type = "command line";
183
#endif
184
                        if (mtd_parts_nb <= 0)
185
                        {
186
                                mtd_parts = static_partitions;
187
                                mtd_parts_nb = NB_OF(static_partitions);
188
                                part_type = "static";
189
                        }
190
                        if (mtd_parts_nb <= 0)
191
                        {
192
                                printk(KERN_NOTICE MSG_PREFIX
193
                                       "no partition info available\n");
194
                        }
195
                        else
196
                        {
197
                                printk(KERN_NOTICE MSG_PREFIX
198
                                       "using %s partition definition\n",
199
                                       part_type);
200
                                add_mtd_partitions(impa7_mtd[i],
201
                                                   mtd_parts, mtd_parts_nb);
202
                        }
203
#endif
204
                }
205
                else
206
                  iounmap((void *)impa7_map[i].map_priv_1);
207
        }
208
        return devicesfound == 0 ? -ENXIO : 0;
209
}
210
 
211
static void __exit cleanup_impa7(void)
212
{
213
        int i;
214
        for (i=0; i<NUM_FLASHBANKS; i++)
215
        {
216
                if (impa7_mtd[i])
217
                {
218
                        del_mtd_device(impa7_mtd[i]);
219
                        map_destroy(impa7_mtd[i]);
220
                }
221
                if (impa7_map[i].map_priv_1)
222
                {
223
                        iounmap((void *)impa7_map[i].map_priv_1);
224
                        impa7_map[i].map_priv_1 = 0;
225
                }
226
        }
227
}
228
 
229
module_init(init_impa7);
230
module_exit(cleanup_impa7);
231
 
232
MODULE_LICENSE("GPL");
233
MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
234
MODULE_DESCRIPTION("MTD map driver for implementa impA7");

powered by: WebSVN 2.1.0

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