xref: /openbmc/linux/drivers/char/xillybus/xillybus_of.c (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1a6377d90SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27051924fSEli Billauer /*
37051924fSEli Billauer  * linux/drivers/misc/xillybus_of.c
47051924fSEli Billauer  *
57051924fSEli Billauer  * Copyright 2011 Xillybus Ltd, http://xillybus.com
67051924fSEli Billauer  *
77051924fSEli Billauer  * Driver for the Xillybus FPGA/host framework using Open Firmware.
87051924fSEli Billauer  */
97051924fSEli Billauer 
107051924fSEli Billauer #include <linux/module.h>
117051924fSEli Billauer #include <linux/device.h>
127051924fSEli Billauer #include <linux/slab.h>
137051924fSEli Billauer #include <linux/platform_device.h>
147051924fSEli Billauer #include <linux/of.h>
157051924fSEli Billauer #include <linux/err.h>
167051924fSEli Billauer #include "xillybus.h"
177051924fSEli Billauer 
187051924fSEli Billauer MODULE_DESCRIPTION("Xillybus driver for Open Firmware");
197051924fSEli Billauer MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
207051924fSEli Billauer MODULE_ALIAS("xillybus_of");
217051924fSEli Billauer MODULE_LICENSE("GPL v2");
227051924fSEli Billauer 
237051924fSEli Billauer static const char xillyname[] = "xillybus_of";
247051924fSEli Billauer 
257051924fSEli Billauer /* Match table for of_platform binding */
26da2ff527SFabian Frederick static const struct of_device_id xillybus_of_match[] = {
277051924fSEli Billauer 	{ .compatible = "xillybus,xillybus-1.00.a", },
287051924fSEli Billauer 	{ .compatible = "xlnx,xillybus-1.00.a", }, /* Deprecated */
297051924fSEli Billauer 	{}
307051924fSEli Billauer };
317051924fSEli Billauer 
327051924fSEli Billauer MODULE_DEVICE_TABLE(of, xillybus_of_match);
337051924fSEli Billauer 
xilly_drv_probe(struct platform_device * op)347051924fSEli Billauer static int xilly_drv_probe(struct platform_device *op)
357051924fSEli Billauer {
367051924fSEli Billauer 	struct device *dev = &op->dev;
377051924fSEli Billauer 	struct xilly_endpoint *endpoint;
387051924fSEli Billauer 	int rc;
397051924fSEli Billauer 	int irq;
407051924fSEli Billauer 
41*c31bbc14SEli Billauer 	endpoint = xillybus_init_endpoint(dev);
427051924fSEli Billauer 
437051924fSEli Billauer 	if (!endpoint)
447051924fSEli Billauer 		return -ENOMEM;
457051924fSEli Billauer 
467051924fSEli Billauer 	dev_set_drvdata(dev, endpoint);
477051924fSEli Billauer 
48*c31bbc14SEli Billauer 	endpoint->owner = THIS_MODULE;
49*c31bbc14SEli Billauer 
50482c86ccSYueHaibing 	endpoint->registers = devm_platform_ioremap_resource(op, 0);
517051924fSEli Billauer 	if (IS_ERR(endpoint->registers))
527051924fSEli Billauer 		return PTR_ERR(endpoint->registers);
537051924fSEli Billauer 
5474d83a5dSRob Herring 	irq = platform_get_irq(op, 0);
557051924fSEli Billauer 
567051924fSEli Billauer 	rc = devm_request_irq(dev, irq, xillybus_isr, 0, xillyname, endpoint);
577051924fSEli Billauer 
587051924fSEli Billauer 	if (rc) {
597051924fSEli Billauer 		dev_err(endpoint->dev,
607051924fSEli Billauer 			"Failed to register IRQ handler. Aborting.\n");
617051924fSEli Billauer 		return -ENODEV;
627051924fSEli Billauer 	}
637051924fSEli Billauer 
647051924fSEli Billauer 	return xillybus_endpoint_discovery(endpoint);
657051924fSEli Billauer }
667051924fSEli Billauer 
xilly_drv_remove(struct platform_device * op)677051924fSEli Billauer static int xilly_drv_remove(struct platform_device *op)
687051924fSEli Billauer {
697051924fSEli Billauer 	struct device *dev = &op->dev;
707051924fSEli Billauer 	struct xilly_endpoint *endpoint = dev_get_drvdata(dev);
717051924fSEli Billauer 
727051924fSEli Billauer 	xillybus_endpoint_remove(endpoint);
737051924fSEli Billauer 
747051924fSEli Billauer 	return 0;
757051924fSEli Billauer }
767051924fSEli Billauer 
777051924fSEli Billauer static struct platform_driver xillybus_platform_driver = {
787051924fSEli Billauer 	.probe = xilly_drv_probe,
797051924fSEli Billauer 	.remove = xilly_drv_remove,
807051924fSEli Billauer 	.driver = {
817051924fSEli Billauer 		.name = xillyname,
827051924fSEli Billauer 		.of_match_table = xillybus_of_match,
837051924fSEli Billauer 	},
847051924fSEli Billauer };
857051924fSEli Billauer 
867051924fSEli Billauer module_platform_driver(xillybus_platform_driver);
87