summaryrefslogtreecommitdiffstats
path: root/uClinux-2.4.20-uc1/drivers/mtd/maps/cobra5272.c
blob: f7022a2034b491b179f820eef857eda70960b642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
 * This file is "heavily based" ;) on physmap.c, which I copied
 * and changed to suit my needs! But to show who is responsible
 * for the file I included the new copyright. I don't know if that
 * is the correct way, so if this should be a problem, please
 * email me! 
 * 
 * (C) 2002 senTec Elektronik GmbH, Heiko Degenhardt
 * <linux@sentec-elektronik.de>
 * 
 * 
 * $Id: $
 *     
 * ----------------------------------------------------------------------
 * File:       cobra5272.c
 * Place:      uClinux-dist/linux-2.4.x/drivers/mtd/maps/
 * Author:     Heiko Degenhardt (linux@sentec-elektronik.de)
 * Contents:   Flash layout of the COBRA5272 board.
 * Version:    v01.00
 * Date:       Mon Mar 25 09:01:01 CET 2002
 * ______________________________________________________________________
 *
 * CHANGES
 * 020325   v01.00 Creation from physmap.c
 *          (hede)
 * ______________________________________________________________________
 *
 *  This program is free software; you can redistribute  it and/or
 *  modify it under  the terms of  the GNU General  Public License as
 *  published by the Free Software Foundation;  either version 2 of
 *  the  License, or (at your option) any later version.
 *
 *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR
 *  IMPLIED WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED.  IN NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE
 *  FOR ANY   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED   TO,
 *  PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF USE, DATA,
 *  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR
 *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 *  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 *  SUCH DAMAGE.
 *
 *  You should have received a copy of the  GNU General Public License
 *  along with this program; if not, write  to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Mappings of chips in memory of the senTec COBRA5272 board.
 * 
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
#include <linux/config.h>


#define WINDOW_ADDR 0xffe00000
#define WINDOW_SIZE 0x200000
#define BUSWIDTH 2

static struct mtd_info *mymtd;

__u8 cb5272map_read8(struct map_info *map, unsigned long ofs)
{
	return __raw_readb(map->map_priv_1 + ofs);
}

__u16 cb5272map_read16(struct map_info *map, unsigned long ofs)
{
	return __raw_readw(map->map_priv_1 + ofs);
}

__u32 cb5272map_read32(struct map_info *map, unsigned long ofs)
{
	return __raw_readl(map->map_priv_1 + ofs);
}

void cb5272map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
{
	memcpy_fromio(to, map->map_priv_1 + from, len);
}

void cb5272map_write8(struct map_info *map, __u8 d, unsigned long adr)
{
	__raw_writeb(d, map->map_priv_1 + adr);
	mb();
}

void cb5272map_write16(struct map_info *map, __u16 d, unsigned long adr)
{
	__raw_writew(d, map->map_priv_1 + adr);
	mb();
}

void cb5272map_write32(struct map_info *map, __u32 d, unsigned long adr)
{
	__raw_writel(d, map->map_priv_1 + adr);
	mb();
}

void cb5272map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
{
	memcpy_toio(map->map_priv_1 + to, from, len);
}

struct map_info cb5272map_map = {
	name: "Physically mapped flash of COBRA5272",
	size: WINDOW_SIZE,
	buswidth: BUSWIDTH,
	read8: cb5272map_read8,
	read16: cb5272map_read16,
	read32: cb5272map_read32,
	copy_from: cb5272map_copy_from,
	write8: cb5272map_write8,
	write16: cb5272map_write16,
	write32: cb5272map_write32,
	copy_to: cb5272map_copy_to
};

/*
 * MTD 'PARTITIONING' STUFF 
 */
#define NUM_PARTITIONS 10
static struct mtd_partition nettel_partitions[NUM_PARTITIONS] = {
        {
                name: "boot (16K)",
                size: 0x4000,
                offset: 0
        },
        {
                name: "kernel (512K)",
                size: 0x80000,
                offset: 0x80000
        },
        {
                name: "rootfs (1024K)",
                size: 0x100000,
                offset: 0x100000
        },
	{
                name: "spare (8K)",
                size: 0x2000,
                offset: 0x4000
        },
        {
                name: "spare (8K)",
                size: 0x2000,
                offset: 0x6000
        },
        {
                name: "spare (256K)",
                size: 0x40000,
                offset: 0x40000
        },
        {
                name: "complete (2048K)",
                size: 0x200000,
                offset: 0x0
        },
        {
                name: "boot J13 (256K)",
                size: 0x40000,
                offset: 0x100000
        },
        {
                name: "kernel J13 (512K)",
                size: 0x80000,
                offset: 0x140000
        },
        {
                name: "rootfs J13 (256K)",
                size: 0x40000,
                offset: 0x1c0000
        }
};

#if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
#define init_cb5272map init_module
#define cleanup_cb5272map cleanup_module
#endif

int __init init_cb5272map(void)
{
  	printk(KERN_NOTICE "cb5272map flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
	cb5272map_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);

	if (!cb5272map_map.map_priv_1) {
		printk("Failed to ioremap\n");
		return -EIO;
	}
	mymtd = do_map_probe("cfi_probe", &cb5272map_map);
	if (mymtd) {
		mymtd->module = THIS_MODULE;

		return add_mtd_partitions(mymtd, nettel_partitions, NUM_PARTITIONS);
	}

	iounmap((void *)cb5272map_map.map_priv_1);
	return -ENXIO;
}

static void __exit cleanup_cb5272map(void)
{
	if (mymtd) {
		del_mtd_partitions(mymtd);
		map_destroy(mymtd);
	}
	if (cb5272map_map.map_priv_1) {
		iounmap((void *)cb5272map_map.map_priv_1);
		cb5272map_map.map_priv_1 = 0;
	}
}

module_init(init_cb5272map);
module_exit(cleanup_cb5272map);