1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/drivers/misc/xillybus_of.c
4  *
5  * Copyright 2011 Xillybus Ltd, http://xillybus.com
6  *
7  * Driver for the Xillybus FPGA/host framework using Open Firmware.
8  */
9 
10 #include <linux/module.h>
11 #include <linux/device.h>
12 #include <linux/slab.h>
13 #include <linux/platform_device.h>
14 #include <linux/of.h>
15 #include <linux/err.h>
16 #include "xillybus.h"
17 
18 MODULE_DESCRIPTION("Xillybus driver for Open Firmware");
19 MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
20 MODULE_ALIAS("xillybus_of");
21 MODULE_LICENSE("GPL v2");
22 
23 static const char xillyname[] = "xillybus_of";
24 
25 /* Match table for of_platform binding */
26 static const struct of_device_id xillybus_of_match[] = {
27 	{ .compatible = "xillybus,xillybus-1.00.a", },
28 	{ .compatible = "xlnx,xillybus-1.00.a", }, /* Deprecated */
29 	{}
30 };
31 
32 MODULE_DEVICE_TABLE(of, xillybus_of_match);
33 
xilly_drv_probe(struct platform_device * op)34 static int xilly_drv_probe(struct platform_device *op)
35 {
36 	struct device *dev = &op->dev;
37 	struct xilly_endpoint *endpoint;
38 	int rc;
39 	int irq;
40 
41 	endpoint = xillybus_init_endpoint(dev);
42 
43 	if (!endpoint)
44 		return -ENOMEM;
45 
46 	dev_set_drvdata(dev, endpoint);
47 
48 	endpoint->owner = THIS_MODULE;
49 
50 	endpoint->registers = devm_platform_ioremap_resource(op, 0);
51 	if (IS_ERR(endpoint->registers))
52 		return PTR_ERR(endpoint->registers);
53 
54 	irq = platform_get_irq(op, 0);
55 
56 	rc = devm_request_irq(dev, irq, xillybus_isr, 0, xillyname, endpoint);
57 
58 	if (rc) {
59 		dev_err(endpoint->dev,
60 			"Failed to register IRQ handler. Aborting.\n");
61 		return -ENODEV;
62 	}
63 
64 	return xillybus_endpoint_discovery(endpoint);
65 }
66 
xilly_drv_remove(struct platform_device * op)67 static void xilly_drv_remove(struct platform_device *op)
68 {
69 	struct device *dev = &op->dev;
70 	struct xilly_endpoint *endpoint = dev_get_drvdata(dev);
71 
72 	xillybus_endpoint_remove(endpoint);
73 }
74 
75 static struct platform_driver xillybus_platform_driver = {
76 	.probe = xilly_drv_probe,
77 	.remove_new = xilly_drv_remove,
78 	.driver = {
79 		.name = xillyname,
80 		.of_match_table = xillybus_of_match,
81 	},
82 };
83 
84 module_platform_driver(xillybus_platform_driver);
85