intel_th: pci: Add Tiger Lake CPU support
[linux/fpc-iii.git] / drivers / mtd / mtdblock_ro.c
blob7fcf29ef2bdc4664ebf5520c254aee7219621ad1
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Simple read-only (writable only for RAM) mtdblock driver
5 * Copyright © 2001-2010 David Woodhouse <dwmw2@infradead.org>
6 */
8 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/mtd/mtd.h>
11 #include <linux/mtd/blktrans.h>
12 #include <linux/module.h>
13 #include <linux/major.h>
15 static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
16 unsigned long block, char *buf)
18 size_t retlen;
20 if (mtd_read(dev->mtd, (block * 512), 512, &retlen, buf))
21 return 1;
22 return 0;
25 static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
26 unsigned long block, char *buf)
28 size_t retlen;
30 if (mtd_write(dev->mtd, (block * 512), 512, &retlen, buf))
31 return 1;
32 return 0;
35 static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
37 struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
39 if (!dev)
40 return;
42 dev->mtd = mtd;
43 dev->devnum = mtd->index;
45 dev->size = mtd->size >> 9;
46 dev->tr = tr;
47 dev->readonly = 1;
49 if (add_mtd_blktrans_dev(dev))
50 kfree(dev);
53 static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev)
55 del_mtd_blktrans_dev(dev);
58 static struct mtd_blktrans_ops mtdblock_tr = {
59 .name = "mtdblock",
60 .major = MTD_BLOCK_MAJOR,
61 .part_bits = 0,
62 .blksize = 512,
63 .readsect = mtdblock_readsect,
64 .writesect = mtdblock_writesect,
65 .add_mtd = mtdblock_add_mtd,
66 .remove_dev = mtdblock_remove_dev,
67 .owner = THIS_MODULE,
70 static int __init mtdblock_init(void)
72 return register_mtd_blktrans(&mtdblock_tr);
75 static void __exit mtdblock_exit(void)
77 deregister_mtd_blktrans(&mtdblock_tr);
80 module_init(mtdblock_init);
81 module_exit(mtdblock_exit);
83 MODULE_LICENSE("GPL");
84 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
85 MODULE_DESCRIPTION("Simple read-only block device emulation access to MTD devices");