16861d27cSMihai Carabas // SPDX-License-Identifier: GPL-2.0+
26861d27cSMihai Carabas /*
36861d27cSMihai Carabas * Pvpanic MMIO Device Support
46861d27cSMihai Carabas *
56861d27cSMihai Carabas * Copyright (C) 2013 Fujitsu.
66861d27cSMihai Carabas * Copyright (C) 2018 ZTE.
76861d27cSMihai Carabas * Copyright (C) 2021 Oracle.
86861d27cSMihai Carabas */
96861d27cSMihai Carabas
10*7037f714SAndy Shevchenko #include <linux/device.h>
11*7037f714SAndy Shevchenko #include <linux/err.h>
126861d27cSMihai Carabas #include <linux/io.h>
13*7037f714SAndy Shevchenko #include <linux/ioport.h>
146861d27cSMihai Carabas #include <linux/kexec.h>
156861d27cSMihai Carabas #include <linux/mod_devicetable.h>
166861d27cSMihai Carabas #include <linux/module.h>
176861d27cSMihai Carabas #include <linux/platform_device.h>
186861d27cSMihai Carabas #include <linux/types.h>
196861d27cSMihai Carabas
206861d27cSMihai Carabas #include "pvpanic.h"
216861d27cSMihai Carabas
226861d27cSMihai Carabas MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
236861d27cSMihai Carabas MODULE_DESCRIPTION("pvpanic-mmio device driver");
246861d27cSMihai Carabas MODULE_LICENSE("GPL");
256861d27cSMihai Carabas
pvpanic_mmio_probe(struct platform_device * pdev)266861d27cSMihai Carabas static int pvpanic_mmio_probe(struct platform_device *pdev)
276861d27cSMihai Carabas {
286861d27cSMihai Carabas struct device *dev = &pdev->dev;
296861d27cSMihai Carabas struct resource *res;
30b3c0f877SMihai Carabas void __iomem *base;
316861d27cSMihai Carabas
326861d27cSMihai Carabas res = platform_get_mem_or_io(pdev, 0);
336861d27cSMihai Carabas if (!res)
346861d27cSMihai Carabas return -EINVAL;
356861d27cSMihai Carabas
366861d27cSMihai Carabas switch (resource_type(res)) {
376861d27cSMihai Carabas case IORESOURCE_IO:
386861d27cSMihai Carabas base = devm_ioport_map(dev, res->start, resource_size(res));
396861d27cSMihai Carabas if (!base)
406861d27cSMihai Carabas return -ENOMEM;
416861d27cSMihai Carabas break;
426861d27cSMihai Carabas case IORESOURCE_MEM:
436861d27cSMihai Carabas base = devm_ioremap_resource(dev, res);
446861d27cSMihai Carabas if (IS_ERR(base))
456861d27cSMihai Carabas return PTR_ERR(base);
466861d27cSMihai Carabas break;
476861d27cSMihai Carabas default:
486861d27cSMihai Carabas return -EINVAL;
496861d27cSMihai Carabas }
506861d27cSMihai Carabas
51c1426d39SThomas Weißschuh return devm_pvpanic_probe(dev, base);
526861d27cSMihai Carabas }
536861d27cSMihai Carabas
546861d27cSMihai Carabas static const struct of_device_id pvpanic_mmio_match[] = {
556861d27cSMihai Carabas { .compatible = "qemu,pvpanic-mmio", },
566861d27cSMihai Carabas {}
576861d27cSMihai Carabas };
586861d27cSMihai Carabas MODULE_DEVICE_TABLE(of, pvpanic_mmio_match);
596861d27cSMihai Carabas
606861d27cSMihai Carabas static const struct acpi_device_id pvpanic_device_ids[] = {
616861d27cSMihai Carabas { "QEMU0001", 0 },
626861d27cSMihai Carabas { "", 0 }
636861d27cSMihai Carabas };
646861d27cSMihai Carabas MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
656861d27cSMihai Carabas
666861d27cSMihai Carabas static struct platform_driver pvpanic_mmio_driver = {
676861d27cSMihai Carabas .driver = {
686861d27cSMihai Carabas .name = "pvpanic-mmio",
696861d27cSMihai Carabas .of_match_table = pvpanic_mmio_match,
706861d27cSMihai Carabas .acpi_match_table = pvpanic_device_ids,
71c1426d39SThomas Weißschuh .dev_groups = pvpanic_dev_groups,
726861d27cSMihai Carabas },
736861d27cSMihai Carabas .probe = pvpanic_mmio_probe,
746861d27cSMihai Carabas };
756861d27cSMihai Carabas module_platform_driver(pvpanic_mmio_driver);
76