|
楼主 |
发表于 2004-3-21 18:46:30
|
显示全部楼层
--------my eb438.c----------------------
#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 0x11000000
#define WINDOW_SIZE 0x200000
#define BUSWIDTH 2
static struct mtd_info *mymtd;
__u8 eb438_read8(struct map_info *map, unsigned long ofs)
{
return __raw_readb(map->map_priv_1 + ofs);
}
__u16 eb438_read16(struct map_info *map, unsigned long ofs)
{
return __raw_readw(map->map_priv_1 + ofs);
}
__u32 eb438_read32(struct map_info *map, unsigned long ofs)
{
return __raw_readl(map->map_priv_1 + ofs);
}
void eb438_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
{
memcpy_fromio(to, map->map_priv_1 + from, len);
}
void eb438_write8(struct map_info *map, __u8 d, unsigned long adr)
{
__raw_writeb(d, map->map_priv_1 + adr);
mb();
}
void eb438_write16(struct map_info *map, __u16 d, unsigned long adr)
{
__raw_writew(d, map->map_priv_1 + adr);
mb();
}
void eb438_write32(struct map_info *map, __u32 d, unsigned long adr)
{
__raw_writel(d, map->map_priv_1 + adr);
mb();
}
void eb438_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 eb438_map = {
name: "eb438 flash device",
size: WINDOW_SIZE,
buswidth: BUSWIDTH,
read8: eb438_read8,
read16: eb438_read16,
read32: eb438_read32,
copy_from: eb438_copy_from,
write8: eb438_write8,
write16: eb438_write16,
write32: eb438_write32,
copy_to: eb438_copy_to
};
/****************************************************************************/
/*
* MTD 'PARTITIONING' STUFF
*/
static struct mtd_partition eb438_partitions[] = {
{
name: "kernel",
offset: 0x0,
size: 0x200000,
},
{
name: "cramfs",
offset: 0x200000,
size: 0x200000,
}
};
int __init init_eb438(void)
{
struct mtd_info *mtd;
printk(KERN_NOTICE "eb438 flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
eb438_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
if (!eb438_map.map_priv_1) {
printk("Failed to ioremap\n");
return -EIO;
}
mymtd = do_map_probe("cfi_probe", &eb438_map);
if (mymtd) {
mymtd->module = THIS_MODULE;
mymtd->erasesize = 0x40000;
return add_mtd_partitions(mymtd, eb438_partitions,
sizeof(eb438_partitions) /
sizeof(eb438_partitions[0]) );
}
iounmap((void *)eb438_map.map_priv_1);
return -ENXIO;
}
static void __exit cleanup_eb438(void)
{
if (mymtd) {
del_mtd_partitions(mymtd);
map_destroy(mymtd);
}
if (eb438_map.map_priv_1) {
iounmap((void *)eb438_map.map_priv_1);
eb438_map.map_priv_1 = 0;
}
}
module_init(init_eb43;
module_exit(cleanup_eb43; |
|