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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [mtd/] [maps/] [netsc520.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
/* netsc520.c -- MTD map driver for AMD NetSc520 Demonstration Board
2
 *
3
 * Copyright (C) 2001 Mark Langsdorf (mark.langsdorf@amd.com)
4
 *      based on sc520cdp.c by Sysgo Real-Time Solutions GmbH
5
 *
6
 * $Id: netsc520.c,v 1.1.1.1 2004-04-15 01:51:56 phoenix Exp $
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 as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21
 *
22
 * The NetSc520 is a demonstration board for the Elan Sc520 processor available
23
 * from AMD.  It has a single back of 16 megs of 32-bit Flash ROM and another
24
 * 16 megs of SDRAM.
25
 */
26
 
27
#include <linux/module.h>
28
#include <linux/types.h>
29
#include <linux/kernel.h>
30
#include <asm/io.h>
31
#include <linux/mtd/mtd.h>
32
#include <linux/mtd/map.h>
33
#include <linux/mtd/partitions.h>
34
 
35
 
36
/*
37
** The single, 16 megabyte flash bank is divided into four virtual
38
** partitions.  The first partition is 768 KiB and is intended to
39
** store the kernel image loaded by the bootstrap loader.  The second
40
** partition is 256 KiB and holds the BIOS image.  The third
41
** partition is 14.5 MiB and is intended for the flash file system
42
** image.  The last partition is 512 KiB and contains another copy
43
** of the BIOS image and the reset vector.
44
**
45
** Only the third partition should be mounted.  The first partition
46
** should not be mounted, but it can erased and written to using the
47
** MTD character routines.  The second and fourth partitions should
48
** not be touched - it is possible to corrupt the BIOS image by
49
** mounting these partitions, and potentially the board will not be
50
** recoverable afterwards.
51
*/
52
 
53
static __u8 netsc520_read8(struct map_info *map, unsigned long ofs)
54
{
55
        return readb(map->map_priv_1 + ofs);
56
}
57
 
58
static __u16 netsc520_read16(struct map_info *map, unsigned long ofs)
59
{
60
        return readw(map->map_priv_1 + ofs);
61
}
62
 
63
static __u32 netsc520_read32(struct map_info *map, unsigned long ofs)
64
{
65
        return readl(map->map_priv_1 + ofs);
66
}
67
 
68
static void netsc520_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
69
{
70
        memcpy_fromio(to, (void *)(map->map_priv_1 + from), len);
71
}
72
 
73
static void netsc520_write8(struct map_info *map, __u8 d, unsigned long adr)
74
{
75
        writeb(d, map->map_priv_1 + adr);
76
}
77
 
78
static void netsc520_write16(struct map_info *map, __u16 d, unsigned long adr)
79
{
80
        writew(d, map->map_priv_1 + adr);
81
}
82
 
83
static void netsc520_write32(struct map_info *map, __u32 d, unsigned long adr)
84
{
85
        writel(d, map->map_priv_1 + adr);
86
}
87
 
88
static void netsc520_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
89
{
90
        memcpy_toio((void *)(map->map_priv_1 + to), from, len);
91
}
92
 
93
/* partition_info gives details on the logical partitions that the split the
94
 * single flash device into. If the size if zero we use up to the end of the
95
 * device. */
96
static struct mtd_partition partition_info[]={
97
    {
98
            name: "NetSc520 boot kernel",
99
            offset: 0,
100
            size:       0xc0000
101
    },
102
    {
103
            name: "NetSc520 Low BIOS",
104
            offset: 0xc0000,
105
            size:       0x40000
106
    },
107
    {
108
            name: "NetSc520 file system",
109
            offset: 0x100000,
110
            size:       0xe80000
111
    },
112
    {
113
            name: "NetSc520 High BIOS",
114
            offset: 0xf80000,
115
            size: 0x80000
116
    },
117
};
118
#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
119
 
120
/*
121
 * If no idea what is going on here.  This is taken from the FlashFX stuff.
122
 */
123
#define ROMCS 1
124
 
125
 
126
#define WINDOW_SIZE     0x00100000
127
#define WINDOW_ADDR     0x00200000
128
 
129
static struct map_info netsc520_map = {
130
        name: "netsc520 Flash Bank",
131
        size: WINDOW_SIZE,
132
        buswidth: 4,
133
        read8: netsc520_read8,
134
        read16: netsc520_read16,
135
        read32: netsc520_read32,
136
        copy_from: netsc520_copy_from,
137
        write8: netsc520_write8,
138
        write16: netsc520_write16,
139
        write32: netsc520_write32,
140
        copy_to: netsc520_copy_to,
141
        map_priv_2: WINDOW_ADDR
142
};
143
 
144
#define NUM_FLASH_BANKS (sizeof(netsc520_map)/sizeof(struct map_info))
145
 
146
static struct mtd_info *mymtd;
147
 
148
static int __init init_netsc520(void)
149
{
150
        printk(KERN_NOTICE "NetSc520 flash device: %lx at %lx\n", netsc520_map.size, netsc520_map.map_priv_2);
151
        netsc520_map.map_priv_1 = (unsigned long)ioremap_nocache(netsc520_map.map_priv_2, netsc520_map.size);
152
 
153
        if (!netsc520_map.map_priv_1) {
154
                printk("Failed to ioremap_nocache\n");
155
                return -EIO;
156
        }
157
        mymtd = do_map_probe("cfi_probe", &netsc520_map);
158
        if(!mymtd)
159
                mymtd = do_map_probe("map_ram", &netsc520_map);
160
        if(!mymtd)
161
                mymtd = do_map_probe("map_rom", &netsc520_map);
162
 
163
        if (!mymtd) {
164
                iounmap((void *)netsc520_map.map_priv_1);
165
                return -ENXIO;
166
        }
167
 
168
        mymtd->module = THIS_MODULE;
169
        add_mtd_partitions( mymtd, partition_info, NUM_PARTITIONS );
170
        return 0;
171
}
172
 
173
static void __exit cleanup_netsc520(void)
174
{
175
        if (mymtd) {
176
                del_mtd_partitions(mymtd);
177
                map_destroy(mymtd);
178
        }
179
        if (netsc520_map.map_priv_1) {
180
                iounmap((void *)netsc520_map.map_priv_1);
181
                netsc520_map.map_priv_1 = 0;
182
        }
183
}
184
 
185
module_init(init_netsc520);
186
module_exit(cleanup_netsc520);
187
 
188
MODULE_LICENSE("GPL");
189
MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@amd.com>");
190
MODULE_DESCRIPTION("MTD map driver for AMD NetSc520 Demonstration Board");

powered by: WebSVN 2.1.0

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