2 * Common code to handle map devices which are simple ROM
3 * (C) 2000 Red Hat. GPL'd.
4 * $Id: map_rom.c,v 1.10 2000/12/10 01:39:13 dwmw2 Exp $
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
11 #include <asm/byteorder.h>
12 #include <linux/errno.h>
13 #include <linux/malloc.h>
15 #include <linux/mtd/map.h>
17 static int maprom_read (struct mtd_info
*, loff_t
, size_t, size_t *, u_char
*);
18 static int maprom_write (struct mtd_info
*, loff_t
, size_t, size_t *, const u_char
*);
19 static void maprom_nop (struct mtd_info
*);
21 static const char im_name
[] = "map_rom_probe";
23 /* This routine is made available to other mtd code via
24 * inter_module_register. It must only be accessed through
25 * inter_module_get which will bump the use count of this module. The
26 * addresses passed back in mtd are valid as long as the use count of
27 * this module is non-zero, i.e. between inter_module_get and
28 * inter_module_put. Keith Owens <kaos@ocs.com.au> 29 Oct 2000.
31 struct mtd_info
*map_rom_probe(struct map_info
*map
)
35 mtd
= kmalloc(sizeof(*mtd
), GFP_KERNEL
);
39 memset(mtd
, 0, sizeof(*mtd
));
41 map
->im_name
= im_name
;
42 map
->fldrv_destroy
= maprom_nop
;
44 mtd
->name
= map
->name
;
46 mtd
->size
= map
->size
;
47 mtd
->read
= maprom_read
;
48 mtd
->write
= maprom_write
;
49 mtd
->sync
= maprom_nop
;
50 mtd
->flags
= MTD_CAP_ROM
;
51 mtd
->erasesize
= 131072;
57 static int maprom_read (struct mtd_info
*mtd
, loff_t from
, size_t len
, size_t *retlen
, u_char
*buf
)
59 struct map_info
*map
= (struct map_info
*)mtd
->priv
;
61 map
->copy_from(map
, buf
, from
, len
);
66 static void maprom_nop(struct mtd_info
*mtd
)
68 /* Nothing to see here */
71 static int maprom_write (struct mtd_info
*mtd
, loff_t to
, size_t len
, size_t *retlen
, const u_char
*buf
)
73 printk(KERN_NOTICE
"maprom_write called\n");
77 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
78 #define map_rom_init init_module
79 #define map_rom_exit cleanup_module
82 static int __init
map_rom_init(void)
84 inter_module_register(im_name
, THIS_MODULE
, &map_rom_probe
);
88 static void __exit
map_rom_exit(void)
90 inter_module_unregister(im_name
);
93 module_init(map_rom_init
);
94 module_exit(map_rom_exit
);