2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-01-24 00:37:04 +00:00
|
|
|
/* drivers/mtd/maps/plat-ram.c
|
|
|
|
*
|
|
|
|
* (c) 2004-2005 Simtec Electronics
|
|
|
|
* http://www.simtec.co.uk/products/SWLINUX/
|
|
|
|
* Ben Dooks <ben@simtec.co.uk>
|
|
|
|
*
|
2010-01-06 23:03:52 +00:00
|
|
|
* Generic platform device based RAM map
|
2005-01-24 00:37:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/device.h>
|
2005-10-30 23:03:48 +00:00
|
|
|
#include <linux/slab.h>
|
2005-10-29 18:07:23 +00:00
|
|
|
#include <linux/platform_device.h>
|
2005-01-24 00:37:04 +00:00
|
|
|
|
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/map.h>
|
|
|
|
#include <linux/mtd/partitions.h>
|
|
|
|
#include <linux/mtd/plat-ram.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
/* private structure for each mtd platform ram device created */
|
|
|
|
|
|
|
|
struct platram_info {
|
|
|
|
struct device *dev;
|
|
|
|
struct mtd_info *mtd;
|
|
|
|
struct map_info map;
|
|
|
|
struct platdata_mtd_ram *pdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* to_platram_info()
|
|
|
|
*
|
|
|
|
* device private data to struct platram_info conversion
|
|
|
|
*/
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
static inline struct platram_info *to_platram_info(struct platform_device *dev)
|
2005-01-24 00:37:04 +00:00
|
|
|
{
|
2013-09-09 05:42:52 +00:00
|
|
|
return platform_get_drvdata(dev);
|
2005-01-24 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* platram_setrw
|
|
|
|
*
|
|
|
|
* call the platform device's set rw/ro control
|
|
|
|
*
|
|
|
|
* to = 0 => read-only
|
|
|
|
* = 1 => read-write
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void platram_setrw(struct platram_info *info, int to)
|
|
|
|
{
|
|
|
|
if (info->pdata == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info->pdata->set_rw != NULL)
|
|
|
|
(info->pdata->set_rw)(info->dev, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* platram_remove
|
|
|
|
*
|
|
|
|
* called to remove the device from the driver's control
|
|
|
|
*/
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
static int platram_remove(struct platform_device *pdev)
|
2005-01-24 00:37:04 +00:00
|
|
|
{
|
2005-11-09 22:32:44 +00:00
|
|
|
struct platram_info *info = to_platram_info(pdev);
|
2005-01-24 00:37:04 +00:00
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
dev_dbg(&pdev->dev, "removing device\n");
|
2005-01-24 00:37:04 +00:00
|
|
|
|
2005-11-07 11:15:40 +00:00
|
|
|
if (info == NULL)
|
2005-01-24 00:37:04 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (info->mtd) {
|
2011-05-23 09:23:07 +00:00
|
|
|
mtd_device_unregister(info->mtd);
|
2005-01-24 00:37:04 +00:00
|
|
|
map_destroy(info->mtd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure ram is left read-only */
|
|
|
|
|
|
|
|
platram_setrw(info, PLATRAM_RO);
|
|
|
|
|
|
|
|
kfree(info);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* platram_probe
|
|
|
|
*
|
|
|
|
* called from device drive system when a device matching our
|
|
|
|
* driver is found.
|
|
|
|
*/
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
static int platram_probe(struct platform_device *pdev)
|
2005-01-24 00:37:04 +00:00
|
|
|
{
|
|
|
|
struct platdata_mtd_ram *pdata;
|
|
|
|
struct platram_info *info;
|
|
|
|
struct resource *res;
|
|
|
|
int err = 0;
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
dev_dbg(&pdev->dev, "probe entered\n");
|
2005-11-07 11:15:40 +00:00
|
|
|
|
2013-07-30 08:18:06 +00:00
|
|
|
if (dev_get_platdata(&pdev->dev) == NULL) {
|
2005-11-09 22:32:44 +00:00
|
|
|
dev_err(&pdev->dev, "no platform data supplied\n");
|
2005-01-24 00:37:04 +00:00
|
|
|
err = -ENOENT;
|
|
|
|
goto exit_error;
|
|
|
|
}
|
|
|
|
|
2013-07-30 08:18:06 +00:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2005-01-24 00:37:04 +00:00
|
|
|
|
2006-11-15 19:10:29 +00:00
|
|
|
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
2005-01-24 00:37:04 +00:00
|
|
|
if (info == NULL) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto exit_error;
|
|
|
|
}
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
platform_set_drvdata(pdev, info);
|
2005-01-24 00:37:04 +00:00
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
info->dev = &pdev->dev;
|
2005-01-24 00:37:04 +00:00
|
|
|
info->pdata = pdata;
|
|
|
|
|
|
|
|
/* get the resource for the memory mapping */
|
2005-11-09 22:32:44 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2017-08-22 13:24:11 +00:00
|
|
|
info->map.virt = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(info->map.virt)) {
|
|
|
|
err = PTR_ERR(info->map.virt);
|
|
|
|
dev_err(&pdev->dev, "failed to ioremap() region\n");
|
2005-01-24 00:37:04 +00:00
|
|
|
goto exit_free;
|
|
|
|
}
|
|
|
|
|
2007-04-26 05:41:34 +00:00
|
|
|
dev_dbg(&pdev->dev, "got platform resource %p (0x%llx)\n", res,
|
|
|
|
(unsigned long long)res->start);
|
2005-01-24 00:37:04 +00:00
|
|
|
|
|
|
|
/* setup map parameters */
|
|
|
|
|
|
|
|
info->map.phys = res->start;
|
2009-07-17 15:47:37 +00:00
|
|
|
info->map.size = resource_size(res);
|
2008-03-03 17:30:24 +00:00
|
|
|
info->map.name = pdata->mapname != NULL ?
|
|
|
|
(char *)pdata->mapname : (char *)pdev->name;
|
2005-01-24 00:37:04 +00:00
|
|
|
info->map.bankwidth = pdata->bankwidth;
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
dev_dbg(&pdev->dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size);
|
2005-01-24 00:37:04 +00:00
|
|
|
|
|
|
|
simple_map_init(&info->map);
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
|
2005-01-24 00:37:04 +00:00
|
|
|
|
2008-03-03 17:30:24 +00:00
|
|
|
/* probe for the right mtd map driver
|
|
|
|
* supplied by the platform_data struct */
|
|
|
|
|
2008-04-28 23:50:04 +00:00
|
|
|
if (pdata->map_probes) {
|
2013-03-12 08:28:31 +00:00
|
|
|
const char * const *map_probes = pdata->map_probes;
|
2008-03-03 17:30:24 +00:00
|
|
|
|
|
|
|
for ( ; !info->mtd && *map_probes; map_probes++)
|
|
|
|
info->mtd = do_map_probe(*map_probes , &info->map);
|
|
|
|
}
|
|
|
|
/* fallback to map_ram */
|
|
|
|
else
|
|
|
|
info->mtd = do_map_probe("map_ram", &info->map);
|
2005-01-24 00:37:04 +00:00
|
|
|
|
|
|
|
if (info->mtd == NULL) {
|
2005-11-09 22:32:44 +00:00
|
|
|
dev_err(&pdev->dev, "failed to probe for map_ram\n");
|
2005-01-24 00:37:04 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto exit_free;
|
|
|
|
}
|
|
|
|
|
2009-03-26 07:42:50 +00:00
|
|
|
info->mtd->dev.parent = &pdev->dev;
|
2005-01-24 00:37:04 +00:00
|
|
|
|
|
|
|
platram_setrw(info, PLATRAM_RW);
|
|
|
|
|
2012-09-20 01:48:00 +00:00
|
|
|
/* check to see if there are any available partitions, or whether
|
2005-01-24 00:37:04 +00:00
|
|
|
* to add this device whole */
|
|
|
|
|
mtd: do not use plain 0 as NULL
The first 3 arguments of 'mtd_device_parse_register()' are pointers,
but many callers pass '0' instead of 'NULL'. Fix this globally. Thanks
to coccinelle for making it easy to do with the following semantic patch:
@@
expression mtd, types, parser_data, parts, nr_parts;
@@
(
-mtd_device_parse_register(mtd, 0, parser_data, parts, nr_parts)
+mtd_device_parse_register(mtd, NULL, parser_data, parts, nr_parts)
|
-mtd_device_parse_register(mtd, types, 0, parts, nr_parts)
+mtd_device_parse_register(mtd, types, NULL, parts, nr_parts)
|
-mtd_device_parse_register(mtd, types, parser_data, 0, nr_parts)
+mtd_device_parse_register(mtd, types, parser_data, NULL, nr_parts)
)
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2012-03-09 17:24:26 +00:00
|
|
|
err = mtd_device_parse_register(info->mtd, pdata->probes, NULL,
|
|
|
|
pdata->partitions,
|
|
|
|
pdata->nr_partitions);
|
2008-03-03 17:30:24 +00:00
|
|
|
if (!err)
|
|
|
|
dev_info(&pdev->dev, "registered mtd device\n");
|
|
|
|
|
2011-12-12 23:37:56 +00:00
|
|
|
if (pdata->nr_partitions) {
|
|
|
|
/* add the whole device. */
|
|
|
|
err = mtd_device_register(info->mtd, NULL, 0);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"failed to register the entire device\n");
|
|
|
|
}
|
|
|
|
}
|
2011-05-23 09:23:07 +00:00
|
|
|
|
2005-01-24 00:37:04 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
exit_free:
|
2005-11-09 22:32:44 +00:00
|
|
|
platram_remove(pdev);
|
2005-01-24 00:37:04 +00:00
|
|
|
exit_error:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* device driver info */
|
|
|
|
|
2008-04-18 20:44:26 +00:00
|
|
|
/* work with hotplug and coldplug */
|
|
|
|
MODULE_ALIAS("platform:mtd-ram");
|
|
|
|
|
2005-11-09 22:32:44 +00:00
|
|
|
static struct platform_driver platram_driver = {
|
2005-01-24 00:37:04 +00:00
|
|
|
.probe = platram_probe,
|
|
|
|
.remove = platram_remove,
|
2005-11-09 22:32:44 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "mtd-ram",
|
|
|
|
},
|
2005-01-24 00:37:04 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 04:41:23 +00:00
|
|
|
module_platform_driver(platram_driver);
|
2005-01-24 00:37:04 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
|
|
|
|
MODULE_DESCRIPTION("MTD platform RAM map driver");
|