#include <linux/module.h>
#include <linux/acpi.h>
#include <linux/io.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#define INT0800_DEFAULT_PHYS 0xffe00000UL
#define INT0800_DEFAULT_SIZE SZ_2M
struct int0800 {
struct map_info map;
struct mtd_info *mtd;
};
static int int0800_probe(struct platform_device *pdev)
{
struct resource *res;
struct int0800 *fw;
resource_size_t end;
int ret;
fw = devm_kzalloc_obj(&pdev->dev, *fw);
if (!fw)
return -ENOMEM;
fw->map.name = dev_name(&pdev->dev);
fw->map.bankwidth = 1;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res) {
fw->map.phys = res->start;
fw->map.size = resource_size(res);
} else {
fw->map.phys = INT0800_DEFAULT_PHYS;
fw->map.size = INT0800_DEFAULT_SIZE;
}
fw->map.virt = devm_ioremap(&pdev->dev, fw->map.phys, fw->map.size);
if (!fw->map.virt)
return -ENOMEM;
simple_map_init(&fw->map);
fw->mtd = do_map_probe("map_rom", &fw->map);
if (!fw->mtd)
return -ENODEV;
fw->mtd->dev.parent = &pdev->dev;
platform_set_drvdata(pdev, fw);
end = fw->map.phys + fw->map.size - 1;
dev_info(&pdev->dev, "mapped firmware window %pa-%pa\n",
&fw->map.phys, &end);
ret = mtd_device_register(fw->mtd, NULL, 0);
if (ret)
map_destroy(fw->mtd);
return ret;
}
static void int0800_remove(struct platform_device *pdev)
{
struct int0800 *fw = platform_get_drvdata(pdev);
mtd_device_unregister(fw->mtd);
map_destroy(fw->mtd);
}
static const struct acpi_device_id int0800_ids[] = {
{ "INT0800", 0 },
{ }
};
MODULE_DEVICE_TABLE(acpi, int0800_ids);
static struct platform_driver int0800_driver = {
.probe = int0800_probe,
.remove = int0800_remove,
.driver = {
.name = "int0800",
.acpi_match_table = int0800_ids,
.suppress_bind_attrs = true,
},
};
module_platform_driver(int0800_driver);
MODULE_AUTHOR("Stephen Bancroft <stevereaver@gmail.com>");
MODULE_DESCRIPTION("Read-only MTD map over the INT0800 firmware flash window");
MODULE_LICENSE("GPL"