Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/* sun_uflash.c - Driver for user-programmable flash on
  3 *                Sun Microsystems SME boardsets.
  4 *
  5 * This driver does NOT provide access to the OBP-flash for
  6 * safety reasons-- use <linux>/drivers/sbus/char/flash.c instead.
  7 *
  8 * Copyright (c) 2001 Eric Brower (ebrower@usa.net)
  9 */
 10
 11#include <linux/kernel.h>
 12#include <linux/module.h>
 13#include <linux/fs.h>
 14#include <linux/errno.h>
 15#include <linux/ioport.h>
 16#include <linux/of.h>
 17#include <linux/platform_device.h>
 18#include <linux/slab.h>
 19#include <asm/prom.h>
 20#include <linux/uaccess.h>
 21#include <asm/io.h>
 22
 23#include <linux/mtd/mtd.h>
 24#include <linux/mtd/map.h>
 25
 26#define UFLASH_OBPNAME	"flashprom"
 27#define DRIVER_NAME	"sun_uflash"
 28#define PFX		DRIVER_NAME ": "
 29
 30#define UFLASH_WINDOW_SIZE	0x200000
 31#define UFLASH_BUSWIDTH		1			/* EBus is 8-bit */
 32
 33MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
 34MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
 
 35MODULE_LICENSE("GPL");
 36MODULE_VERSION("2.1");
 37
 38struct uflash_dev {
 39	const char		*name;	/* device name */
 40	struct map_info 	map;	/* mtd map info */
 41	struct mtd_info		*mtd;	/* mtd info */
 42};
 43
 44struct map_info uflash_map_templ = {
 45	.name =		"SUNW,???-????",
 46	.size =		UFLASH_WINDOW_SIZE,
 47	.bankwidth =	UFLASH_BUSWIDTH,
 48};
 49
 50int uflash_devinit(struct platform_device *op, struct device_node *dp)
 51{
 52	struct uflash_dev *up;
 53
 54	if (op->resource[1].flags) {
 55		/* Non-CFI userflash device-- once I find one we
 56		 * can work on supporting it.
 57		 */
 58		printk(KERN_ERR PFX "Unsupported device at %pOF, 0x%llx\n",
 59		       dp, (unsigned long long)op->resource[0].start);
 60
 61		return -ENODEV;
 62	}
 63
 64	up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
 65	if (!up)
 
 66		return -ENOMEM;
 
 67
 68	/* copy defaults and tweak parameters */
 69	memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ));
 70
 71	up->map.size = resource_size(&op->resource[0]);
 72
 73	up->name = of_get_property(dp, "model", NULL);
 74	if (up->name && 0 < strlen(up->name))
 75		up->map.name = up->name;
 76
 77	up->map.phys = op->resource[0].start;
 78
 79	up->map.virt = of_ioremap(&op->resource[0], 0, up->map.size,
 80				  DRIVER_NAME);
 81	if (!up->map.virt) {
 82		printk(KERN_ERR PFX "Failed to map device.\n");
 83		kfree(up);
 84
 85		return -EINVAL;
 86	}
 87
 88	simple_map_init(&up->map);
 89
 90	/* MTD registration */
 91	up->mtd = do_map_probe("cfi_probe", &up->map);
 92	if (!up->mtd) {
 93		of_iounmap(&op->resource[0], up->map.virt, up->map.size);
 94		kfree(up);
 95
 96		return -ENXIO;
 97	}
 98
 99	up->mtd->owner = THIS_MODULE;
100
101	mtd_device_register(up->mtd, NULL, 0);
102
103	dev_set_drvdata(&op->dev, up);
104
105	return 0;
106}
107
108static int uflash_probe(struct platform_device *op)
109{
110	struct device_node *dp = op->dev.of_node;
111
112	/* Flashprom must have the "user" property in order to
113	 * be used by this driver.
114	 */
115	if (!of_property_read_bool(dp, "user"))
116		return -ENODEV;
117
118	return uflash_devinit(op, dp);
119}
120
121static void uflash_remove(struct platform_device *op)
122{
123	struct uflash_dev *up = dev_get_drvdata(&op->dev);
124
125	if (up->mtd) {
126		mtd_device_unregister(up->mtd);
127		map_destroy(up->mtd);
128	}
129	if (up->map.virt) {
130		of_iounmap(&op->resource[0], up->map.virt, up->map.size);
131		up->map.virt = NULL;
132	}
133
134	kfree(up);
 
 
135}
136
137static const struct of_device_id uflash_match[] = {
138	{
139		.name = UFLASH_OBPNAME,
140	},
141	{},
142};
143
144MODULE_DEVICE_TABLE(of, uflash_match);
145
146static struct platform_driver uflash_driver = {
147	.driver = {
148		.name = DRIVER_NAME,
149		.of_match_table = uflash_match,
150	},
151	.probe		= uflash_probe,
152	.remove_new	= uflash_remove,
153};
154
155module_platform_driver(uflash_driver);
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/* sun_uflash.c - Driver for user-programmable flash on
  3 *                Sun Microsystems SME boardsets.
  4 *
  5 * This driver does NOT provide access to the OBP-flash for
  6 * safety reasons-- use <linux>/drivers/sbus/char/flash.c instead.
  7 *
  8 * Copyright (c) 2001 Eric Brower (ebrower@usa.net)
  9 */
 10
 11#include <linux/kernel.h>
 12#include <linux/module.h>
 13#include <linux/fs.h>
 14#include <linux/errno.h>
 15#include <linux/ioport.h>
 16#include <linux/of.h>
 17#include <linux/of_device.h>
 18#include <linux/slab.h>
 19#include <asm/prom.h>
 20#include <linux/uaccess.h>
 21#include <asm/io.h>
 22
 23#include <linux/mtd/mtd.h>
 24#include <linux/mtd/map.h>
 25
 26#define UFLASH_OBPNAME	"flashprom"
 27#define DRIVER_NAME	"sun_uflash"
 28#define PFX		DRIVER_NAME ": "
 29
 30#define UFLASH_WINDOW_SIZE	0x200000
 31#define UFLASH_BUSWIDTH		1			/* EBus is 8-bit */
 32
 33MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
 34MODULE_DESCRIPTION("User-programmable flash device on Sun Microsystems boardsets");
 35MODULE_SUPPORTED_DEVICE(DRIVER_NAME);
 36MODULE_LICENSE("GPL");
 37MODULE_VERSION("2.1");
 38
 39struct uflash_dev {
 40	const char		*name;	/* device name */
 41	struct map_info 	map;	/* mtd map info */
 42	struct mtd_info		*mtd;	/* mtd info */
 43};
 44
 45struct map_info uflash_map_templ = {
 46	.name =		"SUNW,???-????",
 47	.size =		UFLASH_WINDOW_SIZE,
 48	.bankwidth =	UFLASH_BUSWIDTH,
 49};
 50
 51int uflash_devinit(struct platform_device *op, struct device_node *dp)
 52{
 53	struct uflash_dev *up;
 54
 55	if (op->resource[1].flags) {
 56		/* Non-CFI userflash device-- once I find one we
 57		 * can work on supporting it.
 58		 */
 59		printk(KERN_ERR PFX "Unsupported device at %pOF, 0x%llx\n",
 60		       dp, (unsigned long long)op->resource[0].start);
 61
 62		return -ENODEV;
 63	}
 64
 65	up = kzalloc(sizeof(struct uflash_dev), GFP_KERNEL);
 66	if (!up) {
 67		printk(KERN_ERR PFX "Cannot allocate struct uflash_dev\n");
 68		return -ENOMEM;
 69	}
 70
 71	/* copy defaults and tweak parameters */
 72	memcpy(&up->map, &uflash_map_templ, sizeof(uflash_map_templ));
 73
 74	up->map.size = resource_size(&op->resource[0]);
 75
 76	up->name = of_get_property(dp, "model", NULL);
 77	if (up->name && 0 < strlen(up->name))
 78		up->map.name = up->name;
 79
 80	up->map.phys = op->resource[0].start;
 81
 82	up->map.virt = of_ioremap(&op->resource[0], 0, up->map.size,
 83				  DRIVER_NAME);
 84	if (!up->map.virt) {
 85		printk(KERN_ERR PFX "Failed to map device.\n");
 86		kfree(up);
 87
 88		return -EINVAL;
 89	}
 90
 91	simple_map_init(&up->map);
 92
 93	/* MTD registration */
 94	up->mtd = do_map_probe("cfi_probe", &up->map);
 95	if (!up->mtd) {
 96		of_iounmap(&op->resource[0], up->map.virt, up->map.size);
 97		kfree(up);
 98
 99		return -ENXIO;
100	}
101
102	up->mtd->owner = THIS_MODULE;
103
104	mtd_device_register(up->mtd, NULL, 0);
105
106	dev_set_drvdata(&op->dev, up);
107
108	return 0;
109}
110
111static int uflash_probe(struct platform_device *op)
112{
113	struct device_node *dp = op->dev.of_node;
114
115	/* Flashprom must have the "user" property in order to
116	 * be used by this driver.
117	 */
118	if (!of_find_property(dp, "user", NULL))
119		return -ENODEV;
120
121	return uflash_devinit(op, dp);
122}
123
124static int uflash_remove(struct platform_device *op)
125{
126	struct uflash_dev *up = dev_get_drvdata(&op->dev);
127
128	if (up->mtd) {
129		mtd_device_unregister(up->mtd);
130		map_destroy(up->mtd);
131	}
132	if (up->map.virt) {
133		of_iounmap(&op->resource[0], up->map.virt, up->map.size);
134		up->map.virt = NULL;
135	}
136
137	kfree(up);
138
139	return 0;
140}
141
142static const struct of_device_id uflash_match[] = {
143	{
144		.name = UFLASH_OBPNAME,
145	},
146	{},
147};
148
149MODULE_DEVICE_TABLE(of, uflash_match);
150
151static struct platform_driver uflash_driver = {
152	.driver = {
153		.name = DRIVER_NAME,
154		.of_match_table = uflash_match,
155	},
156	.probe		= uflash_probe,
157	.remove		= uflash_remove,
158};
159
160module_platform_driver(uflash_driver);