Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Common code to handle map devices which are simple ROM
  4 * (C) 2000 Red Hat.
  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#include <linux/init.h>
 15#include <linux/of.h>
 16#include <linux/mtd/mtd.h>
 17#include <linux/mtd/map.h>
 18
 19static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
 20static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
 21static void maprom_nop (struct mtd_info *);
 22static struct mtd_info *map_rom_probe(struct map_info *map);
 23static int maprom_erase (struct mtd_info *mtd, struct erase_info *info);
 24static int maprom_point (struct mtd_info *mtd, loff_t from, size_t len,
 25			 size_t *retlen, void **virt, resource_size_t *phys);
 26static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
 27
 28
 29static struct mtd_chip_driver maprom_chipdrv = {
 30	.probe	= map_rom_probe,
 31	.name	= "map_rom",
 32	.module	= THIS_MODULE
 33};
 34
 35static unsigned int default_erasesize(struct map_info *map)
 36{
 37	const __be32 *erase_size = NULL;
 38
 39	erase_size = of_get_property(map->device_node, "erase-size", NULL);
 40
 41	return !erase_size ? map->size : be32_to_cpu(*erase_size);
 42}
 43
 44static struct mtd_info *map_rom_probe(struct map_info *map)
 45{
 46	struct mtd_info *mtd;
 47
 48	mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
 49	if (!mtd)
 50		return NULL;
 51
 52	map->fldrv = &maprom_chipdrv;
 53	mtd->priv = map;
 54	mtd->name = map->name;
 55	mtd->type = MTD_ROM;
 56	mtd->size = map->size;
 57	mtd->_point = maprom_point;
 58	mtd->_unpoint = maprom_unpoint;
 59	mtd->_read = maprom_read;
 60	mtd->_write = maprom_write;
 61	mtd->_sync = maprom_nop;
 62	mtd->_erase = maprom_erase;
 63	mtd->flags = MTD_CAP_ROM;
 64	mtd->erasesize = default_erasesize(map);
 65	mtd->writesize = 1;
 66	mtd->writebufsize = 1;
 67
 68	__module_get(THIS_MODULE);
 69	return mtd;
 70}
 71
 72
 73static int maprom_point(struct mtd_info *mtd, loff_t from, size_t len,
 74			size_t *retlen, void **virt, resource_size_t *phys)
 75{
 76	struct map_info *map = mtd->priv;
 77
 78	if (!map->virt)
 79		return -EINVAL;
 80	*virt = map->virt + from;
 81	if (phys)
 82		*phys = map->phys + from;
 83	*retlen = len;
 84	return 0;
 85}
 86
 87static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
 88{
 89	return 0;
 90}
 91
 92static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 93{
 94	struct map_info *map = mtd->priv;
 95
 96	map_copy_from(map, buf, from, len);
 97	*retlen = len;
 98	return 0;
 99}
100
101static void maprom_nop(struct mtd_info *mtd)
102{
103	/* Nothing to see here */
104}
105
106static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
107{
108	return -EROFS;
109}
110
111static int maprom_erase (struct mtd_info *mtd, struct erase_info *info)
112{
113	/* We do our best 8) */
114	return -EROFS;
115}
116
117static int __init map_rom_init(void)
118{
119	register_mtd_chip_driver(&maprom_chipdrv);
120	return 0;
121}
122
123static void __exit map_rom_exit(void)
124{
125	unregister_mtd_chip_driver(&maprom_chipdrv);
126}
127
128module_init(map_rom_init);
129module_exit(map_rom_exit);
130
131MODULE_LICENSE("GPL");
132MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
133MODULE_DESCRIPTION("MTD chip driver for ROM chips");
v6.2
 
  1/*
  2 * Common code to handle map devices which are simple ROM
  3 * (C) 2000 Red Hat. GPL'd.
  4 */
  5
  6#include <linux/module.h>
  7#include <linux/types.h>
  8#include <linux/kernel.h>
  9#include <asm/io.h>
 10#include <asm/byteorder.h>
 11#include <linux/errno.h>
 12#include <linux/slab.h>
 13#include <linux/init.h>
 14#include <linux/of.h>
 15#include <linux/mtd/mtd.h>
 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 *);
 21static struct mtd_info *map_rom_probe(struct map_info *map);
 22static int maprom_erase (struct mtd_info *mtd, struct erase_info *info);
 23static int maprom_point (struct mtd_info *mtd, loff_t from, size_t len,
 24			 size_t *retlen, void **virt, resource_size_t *phys);
 25static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
 26
 27
 28static struct mtd_chip_driver maprom_chipdrv = {
 29	.probe	= map_rom_probe,
 30	.name	= "map_rom",
 31	.module	= THIS_MODULE
 32};
 33
 34static unsigned int default_erasesize(struct map_info *map)
 35{
 36	const __be32 *erase_size = NULL;
 37
 38	erase_size = of_get_property(map->device_node, "erase-size", NULL);
 39
 40	return !erase_size ? map->size : be32_to_cpu(*erase_size);
 41}
 42
 43static struct mtd_info *map_rom_probe(struct map_info *map)
 44{
 45	struct mtd_info *mtd;
 46
 47	mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
 48	if (!mtd)
 49		return NULL;
 50
 51	map->fldrv = &maprom_chipdrv;
 52	mtd->priv = map;
 53	mtd->name = map->name;
 54	mtd->type = MTD_ROM;
 55	mtd->size = map->size;
 56	mtd->_point = maprom_point;
 57	mtd->_unpoint = maprom_unpoint;
 58	mtd->_read = maprom_read;
 59	mtd->_write = maprom_write;
 60	mtd->_sync = maprom_nop;
 61	mtd->_erase = maprom_erase;
 62	mtd->flags = MTD_CAP_ROM;
 63	mtd->erasesize = default_erasesize(map);
 64	mtd->writesize = 1;
 65	mtd->writebufsize = 1;
 66
 67	__module_get(THIS_MODULE);
 68	return mtd;
 69}
 70
 71
 72static int maprom_point(struct mtd_info *mtd, loff_t from, size_t len,
 73			size_t *retlen, void **virt, resource_size_t *phys)
 74{
 75	struct map_info *map = mtd->priv;
 76
 77	if (!map->virt)
 78		return -EINVAL;
 79	*virt = map->virt + from;
 80	if (phys)
 81		*phys = map->phys + from;
 82	*retlen = len;
 83	return 0;
 84}
 85
 86static int maprom_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
 87{
 88	return 0;
 89}
 90
 91static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 92{
 93	struct map_info *map = mtd->priv;
 94
 95	map_copy_from(map, buf, from, len);
 96	*retlen = len;
 97	return 0;
 98}
 99
100static void maprom_nop(struct mtd_info *mtd)
101{
102	/* Nothing to see here */
103}
104
105static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
106{
107	return -EROFS;
108}
109
110static int maprom_erase (struct mtd_info *mtd, struct erase_info *info)
111{
112	/* We do our best 8) */
113	return -EROFS;
114}
115
116static int __init map_rom_init(void)
117{
118	register_mtd_chip_driver(&maprom_chipdrv);
119	return 0;
120}
121
122static void __exit map_rom_exit(void)
123{
124	unregister_mtd_chip_driver(&maprom_chipdrv);
125}
126
127module_init(map_rom_init);
128module_exit(map_rom_exit);
129
130MODULE_LICENSE("GPL");
131MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
132MODULE_DESCRIPTION("MTD chip driver for ROM chips");