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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [mtd/] [chips/] [map_ram.c] - Blame information for rev 1275

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

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * Common code to handle map devices which are simple RAM
3
 * (C) 2000 Red Hat. GPL'd.
4
 * $Id: map_ram.c,v 1.1.1.1 2004-04-15 01:52:10 phoenix Exp $
5
 */
6
 
7
#include <linux/module.h>
8
#include <linux/types.h>
9
#include <linux/kernel.h>
10
#include <asm/io.h>
11
#include <asm/byteorder.h>
12
#include <linux/errno.h>
13
#include <linux/slab.h>
14
 
15
#include <linux/mtd/map.h>
16
 
17
 
18
static int mapram_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
19
static int mapram_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
20
static int mapram_erase (struct mtd_info *, struct erase_info *);
21
static void mapram_nop (struct mtd_info *);
22
static struct mtd_info *map_ram_probe(struct map_info *map);
23
 
24
 
25
static struct mtd_chip_driver mapram_chipdrv = {
26
        probe: map_ram_probe,
27
        name: "map_ram",
28
        module: THIS_MODULE
29
};
30
 
31
static struct mtd_info *map_ram_probe(struct map_info *map)
32
{
33
        struct mtd_info *mtd;
34
 
35
        /* Check the first byte is RAM */
36
#if 0
37
        map->write8(map, 0x55, 0);
38
        if (map->read8(map, 0) != 0x55)
39
                return NULL;
40
 
41
        map->write8(map, 0xAA, 0);
42
        if (map->read8(map, 0) != 0xAA)
43
                return NULL;
44
 
45
        /* Check the last byte is RAM */
46
        map->write8(map, 0x55, map->size-1);
47
        if (map->read8(map, map->size-1) != 0x55)
48
                return NULL;
49
 
50
        map->write8(map, 0xAA, map->size-1);
51
        if (map->read8(map, map->size-1) != 0xAA)
52
                return NULL;
53
#endif
54
        /* OK. It seems to be RAM. */
55
 
56
        mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
57
        if (!mtd)
58
                return NULL;
59
 
60
        memset(mtd, 0, sizeof(*mtd));
61
 
62
        map->fldrv = &mapram_chipdrv;
63
        mtd->priv = map;
64
        mtd->name = map->name;
65
        mtd->type = MTD_RAM;
66
        mtd->size = map->size;
67
        mtd->erase = mapram_erase;
68
        mtd->read = mapram_read;
69
        mtd->write = mapram_write;
70
        mtd->sync = mapram_nop;
71
        mtd->flags = MTD_CAP_RAM | MTD_VOLATILE;
72
 
73
        mtd->erasesize = PAGE_SIZE;
74
        while(mtd->size & (mtd->erasesize - 1))
75
                mtd->erasesize >>= 1;
76
 
77
        MOD_INC_USE_COUNT;
78
        return mtd;
79
}
80
 
81
 
82
static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
83
{
84
        struct map_info *map = (struct map_info *)mtd->priv;
85
 
86
        map->copy_from(map, buf, from, len);
87
        *retlen = len;
88
        return 0;
89
}
90
 
91
static int mapram_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
92
{
93
        struct map_info *map = (struct map_info *)mtd->priv;
94
 
95
        map->copy_to(map, to, buf, len);
96
        *retlen = len;
97
        return 0;
98
}
99
 
100
static int mapram_erase (struct mtd_info *mtd, struct erase_info *instr)
101
{
102
        /* Yeah, it's inefficient. Who cares? It's faster than a _real_
103
           flash erase. */
104
        struct map_info *map = (struct map_info *)mtd->priv;
105
        unsigned long i;
106
 
107
        for (i=0; i<instr->len; i++)
108
                map->write8(map, 0xFF, instr->addr + i);
109
 
110
        if (instr->callback)
111
                instr->callback(instr);
112
 
113
        return 0;
114
}
115
 
116
static void mapram_nop(struct mtd_info *mtd)
117
{
118
        /* Nothing to see here */
119
}
120
 
121
int __init map_ram_init(void)
122
{
123
        register_mtd_chip_driver(&mapram_chipdrv);
124
        return 0;
125
}
126
 
127
static void __exit map_ram_exit(void)
128
{
129
        unregister_mtd_chip_driver(&mapram_chipdrv);
130
}
131
 
132
module_init(map_ram_init);
133
module_exit(map_ram_exit);
134
 
135
MODULE_LICENSE("GPL");
136
MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
137
MODULE_DESCRIPTION("MTD chip driver for RAM chips");

powered by: WebSVN 2.1.0

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