74 #include <linux/module.h>
75 #include <linux/kernel.h>
76 #include <linux/types.h>
79 #include <linux/fcntl.h>
81 #include <linux/poll.h>
84 #include <linux/sysctl.h>
88 #include <linux/slab.h>
91 #include <asm/uaccess.h>
104 #define DRIVER_NAME "icap"
106 #define HWICAP_REGS (0x10000)
108 #define XHWICAP_MAJOR 259
109 #define XHWICAP_MINOR 0
110 #define HWICAP_DEVICES 1
115 static struct mutex icap_sem;
117 static struct class *icap_class;
119 #define UNIMPLEMENTED 0xFFFF
237 buffer[index++] = hwicap_type_1_write(drvdata->
config_regs->CMD) | 1;
246 return drvdata->
config->set_configuration(drvdata,
261 static int hwicap_get_configuration_register(
struct hwicap_drvdata *drvdata,
281 status = drvdata->
config->set_configuration(drvdata,
287 status = drvdata->
config->get_status(drvdata);
292 buffer[index++] = hwicap_type_1_read(reg) | 1;
300 status = drvdata->
config->set_configuration(drvdata,
308 status = drvdata->
config->get_configuration(drvdata, reg_data, 1);
315 static int hwicap_initialize_hwicap(
struct hwicap_drvdata *drvdata)
325 drvdata->
config->reset(drvdata);
328 status = hwicap_command_desync(drvdata);
337 status = hwicap_get_configuration_register(
339 dev_dbg(drvdata->
dev,
"IDCODE = %x\n", idcode);
344 status = hwicap_command_desync(drvdata);
352 hwicap_read(
struct file *
file,
char __user *
buf,
size_t count, loff_t *ppos)
398 words = ((count + 3) >> 2);
399 bytes_to_read = words << 2;
405 bytes_remaining = bytes_to_read & 3;
407 words = bytes_to_read >> 2;
409 status = drvdata->
config->get_configuration(drvdata,
430 status = bytes_to_read;
437 hwicap_write(
struct file *file,
const char __user *buf,
438 size_t count, loff_t *ppos)
493 status = drvdata->
config->set_configuration(drvdata,
509 if ((left > 0) && (left < 4)) {
511 buf + written, left)) {
525 static int hwicap_open(
struct inode *
inode,
struct file *file)
542 status = hwicap_initialize_hwicap(drvdata);
560 static int hwicap_release(
struct inode *inode,
struct file *file)
573 status = drvdata->
config->set_configuration(drvdata,
579 status = hwicap_command_desync(drvdata);
591 .write = hwicap_write,
594 .release = hwicap_release,
607 dev_info(dev,
"Xilinx icap port driver\n");
613 if (!probed_devices[
id])
621 if (probed_devices[
id]) {
623 dev_err(dev,
"cannot assign to %s%i; it is already in use\n",
628 probed_devices[
id] = 1;
635 dev_err(dev,
"Couldn't allocate device private record\n");
642 dev_err(dev,
"Couldn't get registers resource\n");
649 drvdata->
mem_size = resource_size(regs_res);
653 dev_err(dev,
"Couldn't lock memory region at %Lx\n",
654 (
unsigned long long) regs_res->
start);
663 dev_err(dev,
"ioremap() failed\n");
673 dev_info(dev,
"ioremap %llx to %p with size %llx\n",
676 (
unsigned long long) drvdata->
mem_size);
682 dev_err(dev,
"cdev_add() failed\n");
700 probed_devices[
id] = 0;
747 const unsigned int *
id;
763 regs = &v4_config_registers;
767 if (!
strcmp(family,
"virtex2p")) {
768 regs = &v2_config_registers;
769 }
else if (!
strcmp(family,
"virtex4")) {
770 regs = &v4_config_registers;
771 }
else if (!
strcmp(family,
"virtex5")) {
772 regs = &v5_config_registers;
773 }
else if (!
strcmp(family,
"virtex6")) {
774 regs = &v6_config_registers;
777 return hwicap_setup(&op->
dev,
id ? *
id : -1, &
res, config,
798 return hwicap_of_probe(pdev, match->
data);
806 regs = &v4_config_registers;
807 family = pdev->
dev.platform_data;
810 if (!
strcmp(family,
"virtex2p")) {
811 regs = &v2_config_registers;
812 }
else if (!
strcmp(family,
"virtex4")) {
813 regs = &v4_config_registers;
814 }
else if (!
strcmp(family,
"virtex5")) {
815 regs = &v5_config_registers;
816 }
else if (!
strcmp(family,
"virtex6")) {
817 regs = &v6_config_registers;
821 return hwicap_setup(&pdev->
dev, pdev->
id, res,
822 &buffer_icap_config, regs);
827 return hwicap_remove(&pdev->
dev);
833 { .compatible =
"xlnx,opb-hwicap-1.00.b", .data = &buffer_icap_config},
834 { .compatible =
"xlnx,xps-hwicap-1.00.a", .data = &fifo_icap_config},
839 #define hwicap_of_match NULL
843 .probe = hwicap_drv_probe,
844 .remove = hwicap_drv_remove,
852 static int __init hwicap_module_init(
void)
879 static void __exit hwicap_module_cleanup(
void)