2 * linux/drivers/misc/xillybus_of.c
4 * Copyright 2011 Xillybus Ltd, http://xillybus.com
6 * Driver for the Xillybus FPGA/host framework using Open Firmware.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the smems of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
13 #include <linux/module.h>
14 #include <linux/device.h>
15 #include <linux/slab.h>
16 #include <linux/platform_device.h>
18 #include <linux/of_irq.h>
19 #include <linux/of_address.h>
20 #include <linux/of_device.h>
21 #include <linux/of_platform.h>
24 MODULE_DESCRIPTION("Xillybus driver for Open Firmware");
25 MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
26 MODULE_VERSION("1.06");
27 MODULE_ALIAS("xillybus_of");
28 MODULE_LICENSE("GPL v2");
30 static const char xillyname[] = "xillybus_of";
32 /* Match table for of_platform binding */
33 static struct of_device_id xillybus_of_match[] = {
34 { .compatible = "xillybus,xillybus-1.00.a", },
35 { .compatible = "xlnx,xillybus-1.00.a", }, /* Deprecated */
39 MODULE_DEVICE_TABLE(of, xillybus_of_match);
41 static void xilly_dma_sync_single_for_cpu_of(struct xilly_endpoint *ep,
42 dma_addr_t dma_handle,
46 dma_sync_single_for_cpu(ep->dev, dma_handle, size, direction);
49 static void xilly_dma_sync_single_for_device_of(struct xilly_endpoint *ep,
50 dma_addr_t dma_handle,
54 dma_sync_single_for_device(ep->dev, dma_handle, size, direction);
57 static void xilly_dma_sync_single_nop(struct xilly_endpoint *ep,
58 dma_addr_t dma_handle,
64 static dma_addr_t xilly_map_single_of(struct xilly_cleanup *mem,
65 struct xilly_endpoint *ep,
73 struct xilly_dma *this;
75 this = kmalloc(sizeof(struct xilly_dma), GFP_KERNEL);
79 addr = dma_map_single(ep->dev, ptr, size, direction);
80 this->direction = direction;
82 if (dma_mapping_error(ep->dev, addr)) {
87 this->dma_addr = addr;
91 list_add_tail(&this->node, &mem->to_unmap);
96 static void xilly_unmap_single_of(struct xilly_dma *entry)
98 dma_unmap_single(entry->dev,
104 static struct xilly_endpoint_hardware of_hw = {
105 .owner = THIS_MODULE,
106 .hw_sync_sgl_for_cpu = xilly_dma_sync_single_for_cpu_of,
107 .hw_sync_sgl_for_device = xilly_dma_sync_single_for_device_of,
108 .map_single = xilly_map_single_of,
109 .unmap_single = xilly_unmap_single_of
112 static struct xilly_endpoint_hardware of_hw_coherent = {
113 .owner = THIS_MODULE,
114 .hw_sync_sgl_for_cpu = xilly_dma_sync_single_nop,
115 .hw_sync_sgl_for_device = xilly_dma_sync_single_nop,
116 .map_single = xilly_map_single_of,
117 .unmap_single = xilly_unmap_single_of
120 static int xilly_drv_probe(struct platform_device *op)
122 struct device *dev = &op->dev;
123 struct xilly_endpoint *endpoint;
126 struct xilly_endpoint_hardware *ephw = &of_hw;
128 if (of_property_read_bool(dev->of_node, "dma-coherent"))
129 ephw = &of_hw_coherent;
131 endpoint = xillybus_init_endpoint(NULL, dev, ephw);
136 dev_set_drvdata(dev, endpoint);
138 rc = of_address_to_resource(dev->of_node, 0, &endpoint->res);
140 dev_warn(endpoint->dev,
141 "Failed to obtain device tree resource\n");
142 goto failed_request_regions;
145 if (!request_mem_region(endpoint->res.start,
146 resource_size(&endpoint->res), xillyname)) {
147 dev_err(endpoint->dev,
148 "request_mem_region failed. Aborting.\n");
150 goto failed_request_regions;
153 endpoint->registers = of_iomap(dev->of_node, 0);
154 if (!endpoint->registers) {
155 dev_err(endpoint->dev,
156 "Failed to map I/O memory. Aborting.\n");
161 irq = irq_of_parse_and_map(dev->of_node, 0);
163 rc = request_irq(irq, xillybus_isr, 0, xillyname, endpoint);
166 dev_err(endpoint->dev,
167 "Failed to register IRQ handler. Aborting.\n");
169 goto failed_register_irq;
172 rc = xillybus_endpoint_discovery(endpoint);
177 free_irq(irq, endpoint);
180 iounmap(endpoint->registers);
182 release_mem_region(endpoint->res.start,
183 resource_size(&endpoint->res));
185 failed_request_regions:
186 xillybus_do_cleanup(&endpoint->cleanup, endpoint);
192 static int xilly_drv_remove(struct platform_device *op)
194 struct device *dev = &op->dev;
195 struct xilly_endpoint *endpoint = dev_get_drvdata(dev);
196 int irq = irq_of_parse_and_map(dev->of_node, 0);
198 xillybus_endpoint_remove(endpoint);
200 free_irq(irq, endpoint);
202 iounmap(endpoint->registers);
203 release_mem_region(endpoint->res.start,
204 resource_size(&endpoint->res));
206 xillybus_do_cleanup(&endpoint->cleanup, endpoint);
213 static struct platform_driver xillybus_platform_driver = {
214 .probe = xilly_drv_probe,
215 .remove = xilly_drv_remove,
218 .owner = THIS_MODULE,
219 .of_match_table = xillybus_of_match,
223 module_platform_driver(xillybus_platform_driver);