linux-old/drivers/mtd/chips/map_rom.c
<<
>>
Prefs
   1/*
   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.17 2001/10/02 15:05:12 dwmw2 Exp $
   5 */
   6
   7#include <linux/version.h>
   8#include <linux/module.h>
   9#include <linux/types.h>
  10#include <linux/kernel.h>
  11#include <asm/io.h>
  12#include <asm/byteorder.h>
  13#include <linux/errno.h>
  14#include <linux/slab.h>
  15
  16#include <linux/mtd/map.h>
  17
  18static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
  19static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
  20static void maprom_nop (struct mtd_info *);
  21struct mtd_info *map_rom_probe(struct map_info *map);
  22
  23static struct mtd_chip_driver maprom_chipdrv = {
  24        probe: map_rom_probe,
  25        name: "map_rom",
  26        module: THIS_MODULE
  27};
  28
  29struct mtd_info *map_rom_probe(struct map_info *map)
  30{
  31        struct mtd_info *mtd;
  32
  33        mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
  34        if (!mtd)
  35                return NULL;
  36
  37        memset(mtd, 0, sizeof(*mtd));
  38
  39        map->fldrv = &maprom_chipdrv;
  40        mtd->priv = map;
  41        mtd->name = map->name;
  42        mtd->type = MTD_ROM;
  43        mtd->size = map->size;
  44        mtd->read = maprom_read;
  45        mtd->write = maprom_write;
  46        mtd->sync = maprom_nop;
  47        mtd->flags = MTD_CAP_ROM;
  48        mtd->erasesize = 131072;
  49        while(mtd->size & (mtd->erasesize - 1))
  50                mtd->erasesize >>= 1;
  51
  52        MOD_INC_USE_COUNT;
  53        return mtd;
  54}
  55
  56
  57static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
  58{
  59        struct map_info *map = (struct map_info *)mtd->priv;
  60
  61        map->copy_from(map, buf, from, len);
  62        *retlen = len;
  63        return 0;
  64}
  65
  66static void maprom_nop(struct mtd_info *mtd)
  67{
  68        /* Nothing to see here */
  69}
  70
  71static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
  72{
  73        printk(KERN_NOTICE "maprom_write called\n");
  74        return -EIO;
  75}
  76
  77int __init map_rom_init(void)
  78{
  79        register_mtd_chip_driver(&maprom_chipdrv);
  80        return 0;
  81}
  82
  83static void __exit map_rom_exit(void)
  84{
  85        unregister_mtd_chip_driver(&maprom_chipdrv);
  86}
  87
  88module_init(map_rom_init);
  89module_exit(map_rom_exit);
  90
  91MODULE_LICENSE("GPL");
  92MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  93MODULE_DESCRIPTION("MTD chip driver for ROM chips");
  94