1 /*****************************************************************************
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
11 * AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
12 * SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE,
13 * OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
14 * APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
15 * THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
16 * AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
17 * FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY
18 * WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
19 * IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
20 * REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
21 * INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE.
24 * Xilinx products are not intended for use in life support appliances,
25 * devices, or systems. Use in such applications is expressly prohibited.
27 * (c) Copyright 2002 Xilinx Inc., Systems Engineering Group
28 * (c) Copyright 2004 Xilinx Inc., Systems Engineering Group
29 * (c) Copyright 2007-2008 Xilinx Inc.
30 * All rights reserved.
32 * You should have received a copy of the GNU General Public License along
33 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 675 Mass Ave, Cambridge, MA 02139, USA.
36 *****************************************************************************/
39 * This is the code behind /dev/xilinx_icap -- it allows a user-space
40 * application to use the Xilinx ICAP subsystem.
42 * The following operations are possible:
44 * open open the port and initialize for access.
45 * release release port
46 * write Write a bitstream to the configuration processor.
47 * read Read a data stream from the configuration processor.
49 * After being opened, the port is initialized and accessed to avoid a
50 * corrupted first read which may occur with some hardware. The port
51 * is left in a desynched state, requiring that a synch sequence be
52 * transmitted before any valid configuration data. A user will have
53 * exclusive access to the device while it remains open, and the state
54 * of the ICAP cannot be guaranteed after the device is closed. Note
55 * that a complete reset of the core and the state of the ICAP cannot
56 * be performed on many versions of the cores, hence users of this
57 * device should avoid making inconsistent accesses to the device. In
58 * particular, accessing the read interface, without first generating
59 * a write containing a readback packet can leave the ICAP in an
62 * Note that in order to use the read interface, it is first necessary
63 * to write a request packet to the write interface. i.e., it is not
64 * possible to simply readback the bitstream (or any configuration
65 * bits) from a device without specifically requesting them first.
66 * The code to craft such packets is intended to be part of the
67 * user-space application code that uses this device. The simplest
68 * way to use this interface is simply:
70 * cp foo.bit /dev/xilinx_icap
72 * Note that unless foo.bit is an appropriately constructed partial
73 * bitstream, this has a high likelyhood of overwriting the design
74 * currently programmed in the FPGA.
77 #include <linux/version.h>
78 #include <linux/module.h>
79 #include <linux/kernel.h>
80 #include <linux/types.h>
81 #include <linux/ioport.h>
82 #include <linux/interrupt.h>
83 #include <linux/fcntl.h>
84 #include <linux/init.h>
85 #include <linux/poll.h>
86 #include <linux/proc_fs.h>
87 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
88 #include <asm/semaphore.h>
90 #include <linux/mutex.h>
91 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
92 #include <linux/sysctl.h>
93 #include <linux/version.h>
95 #include <linux/cdev.h>
96 #include <linux/platform_device.h>
99 #include <asm/uaccess.h>
100 #include <asm/system.h>
103 /* For open firmware. */
104 #include <linux/of_device.h>
105 #include <linux/of_platform.h>
108 #include "xilinx_hwicap.h"
109 #include "buffer_icap.h"
110 #include "fifo_icap.h"
112 #define DRIVER_NAME "xilinx_icap"
114 #define HWICAP_REGS (0x10000)
116 /* dynamically allocate device number */
117 static int xhwicap_major
;
118 static int xhwicap_minor
;
119 #define HWICAP_DEVICES 1
121 module_param(xhwicap_major
, int, S_IRUGO
);
122 module_param(xhwicap_minor
, int, S_IRUGO
);
124 /* An array, which is set to true when the device is registered. */
125 static bool probed_devices
[HWICAP_DEVICES
];
126 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
128 static struct mutex icap_sem
;
129 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
131 static struct class *icap_class
;
133 #define UNIMPLEMENTED 0xFFFF
135 static const struct config_registers v2_config_registers
= {
151 .AXSS
= UNIMPLEMENTED
,
152 .C0R_1
= UNIMPLEMENTED
,
153 .CSOB
= UNIMPLEMENTED
,
154 .WBSTAR
= UNIMPLEMENTED
,
155 .TIMER
= UNIMPLEMENTED
,
156 .BOOTSTS
= UNIMPLEMENTED
,
157 .CTL_1
= UNIMPLEMENTED
,
160 static const struct config_registers v4_config_registers
= {
172 .FLR
= UNIMPLEMENTED
,
173 .KEY
= UNIMPLEMENTED
,
177 .C0R_1
= UNIMPLEMENTED
,
178 .CSOB
= UNIMPLEMENTED
,
179 .WBSTAR
= UNIMPLEMENTED
,
180 .TIMER
= UNIMPLEMENTED
,
181 .BOOTSTS
= UNIMPLEMENTED
,
182 .CTL_1
= UNIMPLEMENTED
,
184 static const struct config_registers v5_config_registers
= {
196 .FLR
= UNIMPLEMENTED
,
197 .KEY
= UNIMPLEMENTED
,
210 <<<<<<< HEAD:drivers/char/xilinx_hwicap/xilinx_hwicap.c
211 * hwicap_command_desync: Send a DESYNC command to the ICAP port.
212 * @parameter drvdata: a pointer to the drvdata.
214 * hwicap_command_desync - Send a DESYNC command to the ICAP port.
215 * @drvdata: a pointer to the drvdata.
216 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/xilinx_hwicap/xilinx_hwicap.c
218 * This command desynchronizes the ICAP After this command, a
219 * bitstream containing a NULL packet, followed by a SYNCH packet is
220 * required before the ICAP will recognize commands.
222 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
223 int hwicap_command_desync(struct hwicap_drvdata
*drvdata
)
225 static int hwicap_command_desync(struct hwicap_drvdata
*drvdata
)
226 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
232 * Create the data to be written to the ICAP.
234 buffer
[index
++] = hwicap_type_1_write(drvdata
->config_regs
->CMD
) | 1;
235 buffer
[index
++] = XHI_CMD_DESYNCH
;
236 buffer
[index
++] = XHI_NOOP_PACKET
;
237 buffer
[index
++] = XHI_NOOP_PACKET
;
240 * Write the data to the FIFO and intiate the transfer of data present
241 * in the FIFO to the ICAP device.
243 return drvdata
->config
->set_configuration(drvdata
,
248 <<<<<<< HEAD:drivers/char/xilinx_hwicap/xilinx_hwicap.c
249 * hwicap_command_capture: Send a CAPTURE command to the ICAP port.
250 * @parameter drvdata: a pointer to the drvdata.
252 * This command captures all of the flip flop states so they will be
253 * available during readback. One can use this command instead of
254 * enabling the CAPTURE block in the design.
256 int hwicap_command_capture(struct hwicap_drvdata
*drvdata
)
262 * Create the data to be written to the ICAP.
264 buffer
[index
++] = XHI_DUMMY_PACKET
;
265 buffer
[index
++] = XHI_SYNC_PACKET
;
266 buffer
[index
++] = XHI_NOOP_PACKET
;
267 buffer
[index
++] = hwicap_type_1_write(drvdata
->config_regs
->CMD
) | 1;
268 buffer
[index
++] = XHI_CMD_GCAPTURE
;
269 buffer
[index
++] = XHI_DUMMY_PACKET
;
270 buffer
[index
++] = XHI_DUMMY_PACKET
;
273 * Write the data to the FIFO and intiate the transfer of data
274 * present in the FIFO to the ICAP device.
276 return drvdata
->config
->set_configuration(drvdata
,
282 * hwicap_get_configuration_register: Query a configuration register.
283 * @parameter drvdata: a pointer to the drvdata.
284 * @parameter reg: a constant which represents the configuration
286 * hwicap_get_configuration_register - Query a configuration register.
287 * @drvdata: a pointer to the drvdata.
288 * @reg: a constant which represents the configuration
289 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/xilinx_hwicap/xilinx_hwicap.c
290 * register value to be returned.
291 * Examples: XHI_IDCODE, XHI_FLR.
292 <<<<<<< HEAD:drivers/char/xilinx_hwicap/xilinx_hwicap.c
293 * @parameter RegData: returns the value of the register.
295 * @reg_data: returns the value of the register.
296 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/xilinx_hwicap/xilinx_hwicap.c
298 * Sends a query packet to the ICAP and then receives the response.
299 * The icap is left in Synched state.
301 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
302 int hwicap_get_configuration_register(struct hwicap_drvdata
*drvdata
,
303 u32 reg
, u32
*RegData
)
305 static int hwicap_get_configuration_register(struct hwicap_drvdata
*drvdata
,
306 u32 reg
, u32
*reg_data
)
307 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
314 * Create the data to be written to the ICAP.
316 buffer
[index
++] = XHI_DUMMY_PACKET
;
317 buffer
[index
++] = XHI_SYNC_PACKET
;
318 buffer
[index
++] = XHI_NOOP_PACKET
;
319 buffer
[index
++] = hwicap_type_1_read(reg
) | 1;
320 buffer
[index
++] = XHI_NOOP_PACKET
;
321 buffer
[index
++] = XHI_NOOP_PACKET
;
324 * Write the data to the FIFO and intiate the transfer of data present
325 * in the FIFO to the ICAP device.
327 status
= drvdata
->config
->set_configuration(drvdata
,
333 * Read the configuration register
335 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
336 status
= drvdata
->config
->get_configuration(drvdata
, RegData
, 1);
338 status
= drvdata
->config
->get_configuration(drvdata
, reg_data
, 1);
339 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
346 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
347 int hwicap_initialize_hwicap(struct hwicap_drvdata
*drvdata
)
349 static int hwicap_initialize_hwicap(struct hwicap_drvdata
*drvdata
)
350 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
355 dev_dbg(drvdata
->dev
, "initializing\n");
357 /* Abort any current transaction, to make sure we have the
358 * ICAP in a good state. */
359 dev_dbg(drvdata
->dev
, "Reset...\n");
360 drvdata
->config
->reset(drvdata
);
362 dev_dbg(drvdata
->dev
, "Desync...\n");
363 status
= hwicap_command_desync(drvdata
);
367 /* Attempt to read the IDCODE from ICAP. This
368 * may not be returned correctly, due to the design of the
371 dev_dbg(drvdata
->dev
, "Reading IDCODE...\n");
372 status
= hwicap_get_configuration_register(
373 drvdata
, drvdata
->config_regs
->IDCODE
, &idcode
);
374 dev_dbg(drvdata
->dev
, "IDCODE = %x\n", idcode
);
378 dev_dbg(drvdata
->dev
, "Desync...\n");
379 status
= hwicap_command_desync(drvdata
);
387 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
388 hwicap_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
390 hwicap_read(struct file
*file
, char __user
*buf
, size_t count
, loff_t
*ppos
)
391 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
393 struct hwicap_drvdata
*drvdata
= file
->private_data
;
394 ssize_t bytes_to_read
= 0;
400 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
401 if (down_interruptible(&drvdata
->sem
))
404 status
= mutex_lock_interruptible(&drvdata
->sem
);
407 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
409 if (drvdata
->read_buffer_in_use
) {
410 /* If there are leftover bytes in the buffer, just */
411 /* return them and don't try to read more from the */
414 (count
< drvdata
->read_buffer_in_use
) ? count
:
415 drvdata
->read_buffer_in_use
;
417 /* Return the data currently in the read buffer. */
418 if (copy_to_user(buf
, drvdata
->read_buffer
, bytes_to_read
)) {
422 drvdata
->read_buffer_in_use
-= bytes_to_read
;
423 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
424 memcpy(drvdata
->read_buffer
+ bytes_to_read
,
425 drvdata
->read_buffer
, 4 - bytes_to_read
);
427 memmove(drvdata
->read_buffer
,
428 drvdata
->read_buffer
+ bytes_to_read
,
430 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
432 /* Get new data from the ICAP, and return was was requested. */
433 kbuf
= (u32
*) get_zeroed_page(GFP_KERNEL
);
439 /* The ICAP device is only able to read complete */
440 /* words. If a number of bytes that do not correspond */
441 /* to complete words is requested, then we read enough */
442 /* words to get the required number of bytes, and then */
443 /* save the remaining bytes for the next read. */
445 /* Determine the number of words to read, rounding up */
447 words
= ((count
+ 3) >> 2);
448 bytes_to_read
= words
<< 2;
450 if (bytes_to_read
> PAGE_SIZE
)
451 bytes_to_read
= PAGE_SIZE
;
453 /* Ensure we only read a complete number of words. */
454 bytes_remaining
= bytes_to_read
& 3;
456 words
= bytes_to_read
>> 2;
458 status
= drvdata
->config
->get_configuration(drvdata
,
461 /* If we didn't read correctly, then bail out. */
463 free_page((unsigned long)kbuf
);
467 /* If we fail to return the data to the user, then bail out. */
468 if (copy_to_user(buf
, kbuf
, bytes_to_read
)) {
469 free_page((unsigned long)kbuf
);
473 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
474 memcpy(kbuf
, drvdata
->read_buffer
, bytes_remaining
);
476 memcpy(drvdata
->read_buffer
,
479 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
480 drvdata
->read_buffer_in_use
= bytes_remaining
;
481 free_page((unsigned long)kbuf
);
483 status
= bytes_to_read
;
485 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
488 mutex_unlock(&drvdata
->sem
);
489 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
494 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
495 hwicap_write(struct file
*file
, const char *buf
,
497 hwicap_write(struct file
*file
, const char __user
*buf
,
498 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
499 size_t count
, loff_t
*ppos
)
501 struct hwicap_drvdata
*drvdata
= file
->private_data
;
503 ssize_t left
= count
;
508 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
509 if (down_interruptible(&drvdata
->sem
))
512 status
= mutex_lock_interruptible(&drvdata
->sem
);
515 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
517 left
+= drvdata
->write_buffer_in_use
;
519 /* Only write multiples of 4 bytes. */
525 kbuf
= (u32
*) __get_free_page(GFP_KERNEL
);
532 /* only write multiples of 4 bytes, so there might */
533 /* be as many as 3 bytes left (at the end). */
540 if (drvdata
->write_buffer_in_use
) {
541 memcpy(kbuf
, drvdata
->write_buffer
,
542 drvdata
->write_buffer_in_use
);
544 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
545 (((char *)kbuf
) + (drvdata
->write_buffer_in_use
)),
547 (((char *)kbuf
) + drvdata
->write_buffer_in_use
),
548 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
550 len
- (drvdata
->write_buffer_in_use
))) {
551 free_page((unsigned long)kbuf
);
556 if (copy_from_user(kbuf
, buf
+ written
, len
)) {
557 free_page((unsigned long)kbuf
);
563 status
= drvdata
->config
->set_configuration(drvdata
,
567 free_page((unsigned long)kbuf
);
571 if (drvdata
->write_buffer_in_use
) {
572 len
-= drvdata
->write_buffer_in_use
;
573 left
-= drvdata
->write_buffer_in_use
;
574 drvdata
->write_buffer_in_use
= 0;
579 if ((left
> 0) && (left
< 4)) {
580 if (!copy_from_user(drvdata
->write_buffer
,
581 buf
+ written
, left
)) {
582 drvdata
->write_buffer_in_use
= left
;
588 free_page((unsigned long)kbuf
);
591 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
594 mutex_unlock(&drvdata
->sem
);
595 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
599 static int hwicap_open(struct inode
*inode
, struct file
*file
)
601 struct hwicap_drvdata
*drvdata
;
604 drvdata
= container_of(inode
->i_cdev
, struct hwicap_drvdata
, cdev
);
606 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
607 if (down_interruptible(&drvdata
->sem
))
610 status
= mutex_lock_interruptible(&drvdata
->sem
);
613 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
615 if (drvdata
->is_open
) {
620 status
= hwicap_initialize_hwicap(drvdata
);
622 dev_err(drvdata
->dev
, "Failed to open file");
626 file
->private_data
= drvdata
;
627 drvdata
->write_buffer_in_use
= 0;
628 drvdata
->read_buffer_in_use
= 0;
629 drvdata
->is_open
= 1;
632 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
635 mutex_unlock(&drvdata
->sem
);
636 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
640 static int hwicap_release(struct inode
*inode
, struct file
*file
)
642 struct hwicap_drvdata
*drvdata
= file
->private_data
;
646 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
647 if (down_interruptible(&drvdata
->sem
))
650 mutex_lock(&drvdata
->sem
);
651 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
653 if (drvdata
->write_buffer_in_use
) {
654 /* Flush write buffer. */
655 for (i
= drvdata
->write_buffer_in_use
; i
< 4; i
++)
656 drvdata
->write_buffer
[i
] = 0;
658 status
= drvdata
->config
->set_configuration(drvdata
,
659 (u32
*) drvdata
->write_buffer
, 1);
664 status
= hwicap_command_desync(drvdata
);
669 drvdata
->is_open
= 0;
670 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
673 mutex_unlock(&drvdata
->sem
);
674 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
678 static struct file_operations hwicap_fops
= {
679 .owner
= THIS_MODULE
,
680 .write
= hwicap_write
,
683 .release
= hwicap_release
,
686 static int __devinit
hwicap_setup(struct device
*dev
, int id
,
687 const struct resource
*regs_res
,
688 const struct hwicap_driver_config
*config
,
689 const struct config_registers
*config_regs
)
692 struct hwicap_drvdata
*drvdata
= NULL
;
695 dev_info(dev
, "Xilinx icap port driver\n");
697 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
699 mutex_lock(&icap_sem
);
701 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
703 for (id
= 0; id
< HWICAP_DEVICES
; id
++)
704 if (!probed_devices
[id
])
707 if (id
< 0 || id
>= HWICAP_DEVICES
) {
708 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
710 mutex_unlock(&icap_sem
);
711 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
712 dev_err(dev
, "%s%i too large\n", DRIVER_NAME
, id
);
715 if (probed_devices
[id
]) {
716 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
718 mutex_unlock(&icap_sem
);
719 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
720 dev_err(dev
, "cannot assign to %s%i; it is already in use\n",
725 probed_devices
[id
] = 1;
726 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
728 mutex_unlock(&icap_sem
);
729 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
731 devt
= MKDEV(xhwicap_major
, xhwicap_minor
+ id
);
733 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
734 drvdata
= kmalloc(sizeof(struct hwicap_drvdata
), GFP_KERNEL
);
736 drvdata
= kzalloc(sizeof(struct hwicap_drvdata
), GFP_KERNEL
);
737 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
739 dev_err(dev
, "Couldn't allocate device private record\n");
740 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
745 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
747 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
748 memset((void *)drvdata
, 0, sizeof(struct hwicap_drvdata
));
750 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
751 dev_set_drvdata(dev
, (void *)drvdata
);
754 dev_err(dev
, "Couldn't get registers resource\n");
759 drvdata
->mem_start
= regs_res
->start
;
760 drvdata
->mem_end
= regs_res
->end
;
761 drvdata
->mem_size
= regs_res
->end
- regs_res
->start
+ 1;
763 if (!request_mem_region(drvdata
->mem_start
,
764 drvdata
->mem_size
, DRIVER_NAME
)) {
765 dev_err(dev
, "Couldn't lock memory region at %p\n",
766 (void *)regs_res
->start
);
771 drvdata
->devt
= devt
;
773 drvdata
->base_address
= ioremap(drvdata
->mem_start
, drvdata
->mem_size
);
774 if (!drvdata
->base_address
) {
775 dev_err(dev
, "ioremap() failed\n");
779 drvdata
->config
= config
;
780 drvdata
->config_regs
= config_regs
;
782 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
783 init_MUTEX(&drvdata
->sem
);
785 mutex_init(&drvdata
->sem
);
786 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
787 drvdata
->is_open
= 0;
789 dev_info(dev
, "ioremap %lx to %p with size %x\n",
790 (unsigned long int)drvdata
->mem_start
,
791 drvdata
->base_address
, drvdata
->mem_size
);
793 cdev_init(&drvdata
->cdev
, &hwicap_fops
);
794 drvdata
->cdev
.owner
= THIS_MODULE
;
795 retval
= cdev_add(&drvdata
->cdev
, devt
, 1);
797 dev_err(dev
, "cdev_add() failed\n");
800 /* devfs_mk_cdev(devt, S_IFCHR|S_IRUGO|S_IWUGO, DRIVER_NAME); */
801 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
802 class_device_create(icap_class
, NULL
, devt
, NULL
, DRIVER_NAME
);
804 device_create(icap_class
, dev
, devt
, "%s%d", DRIVER_NAME
, id
);
805 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
806 return 0; /* success */
809 iounmap(drvdata
->base_address
);
812 release_mem_region(regs_res
->start
, drvdata
->mem_size
);
817 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
820 mutex_lock(&icap_sem
);
821 probed_devices
[id
] = 0;
822 mutex_unlock(&icap_sem
);
824 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
828 static struct hwicap_driver_config buffer_icap_config
= {
829 .get_configuration
= buffer_icap_get_configuration
,
830 .set_configuration
= buffer_icap_set_configuration
,
831 .reset
= buffer_icap_reset
,
834 static struct hwicap_driver_config fifo_icap_config
= {
835 .get_configuration
= fifo_icap_get_configuration
,
836 .set_configuration
= fifo_icap_set_configuration
,
837 .reset
= fifo_icap_reset
,
840 static int __devexit
hwicap_remove(struct device
*dev
)
842 struct hwicap_drvdata
*drvdata
;
844 drvdata
= (struct hwicap_drvdata
*)dev_get_drvdata(dev
);
849 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
850 class_device_destroy(icap_class
, drvdata
->devt
);
852 device_destroy(icap_class
, drvdata
->devt
);
853 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
854 cdev_del(&drvdata
->cdev
);
855 iounmap(drvdata
->base_address
);
856 release_mem_region(drvdata
->mem_start
, drvdata
->mem_size
);
858 dev_set_drvdata(dev
, NULL
);
859 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
860 probed_devices
[MINOR(dev
->devt
)-xhwicap_minor
] = 0;
862 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
864 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
866 mutex_lock(&icap_sem
);
867 probed_devices
[MINOR(dev
->devt
)-xhwicap_minor
] = 0;
868 mutex_unlock(&icap_sem
);
869 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
870 return 0; /* success */
873 static int __devinit
hwicap_drv_probe(struct platform_device
*pdev
)
875 struct resource
*res
;
876 const struct config_registers
*regs
;
879 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
883 /* It's most likely that we're using V4, if the family is not
885 regs
= &v4_config_registers
;
886 family
= pdev
->dev
.platform_data
;
889 if (!strcmp(family
, "virtex2p")) {
890 regs
= &v2_config_registers
;
891 } else if (!strcmp(family
, "virtex4")) {
892 regs
= &v4_config_registers
;
893 } else if (!strcmp(family
, "virtex5")) {
894 regs
= &v5_config_registers
;
898 return hwicap_setup(&pdev
->dev
, pdev
->id
, res
,
899 &buffer_icap_config
, regs
);
902 static int __devexit
hwicap_drv_remove(struct platform_device
*pdev
)
904 return hwicap_remove(&pdev
->dev
);
907 static struct platform_driver hwicap_platform_driver
= {
908 .probe
= hwicap_drv_probe
,
909 .remove
= hwicap_drv_remove
,
911 .owner
= THIS_MODULE
,
916 /* ---------------------------------------------------------------------
920 #if defined(CONFIG_OF)
922 hwicap_of_probe(struct of_device
*op
, const struct of_device_id
*match
)
925 const unsigned int *id
;
928 const struct hwicap_driver_config
*config
= match
->data
;
929 const struct config_registers
*regs
;
931 dev_dbg(&op
->dev
, "hwicap_of_probe(%p, %p)\n", op
, match
);
933 rc
= of_address_to_resource(op
->node
, 0, &res
);
935 dev_err(&op
->dev
, "invalid address\n");
939 id
= of_get_property(op
->node
, "port-number", NULL
);
941 /* It's most likely that we're using V4, if the family is not
943 regs
= &v4_config_registers
;
944 family
= of_get_property(op
->node
, "xlnx,family", NULL
);
947 if (!strcmp(family
, "virtex2p")) {
948 regs
= &v2_config_registers
;
949 } else if (!strcmp(family
, "virtex4")) {
950 regs
= &v4_config_registers
;
951 } else if (!strcmp(family
, "virtex5")) {
952 regs
= &v5_config_registers
;
955 return hwicap_setup(&op
->dev
, id
? *id
: -1, &res
, config
,
959 static int __devexit
hwicap_of_remove(struct of_device
*op
)
961 return hwicap_remove(&op
->dev
);
964 /* Match table for of_platform binding */
965 static const struct of_device_id __devinit hwicap_of_match
[] = {
966 { .compatible
= "xlnx,opb-hwicap-1.00.b", .data
= &buffer_icap_config
},
967 { .compatible
= "xlnx,xps-hwicap-1.00.a", .data
= &fifo_icap_config
},
970 MODULE_DEVICE_TABLE(of
, hwicap_of_match
);
972 static struct of_platform_driver hwicap_of_driver
= {
973 .owner
= THIS_MODULE
,
975 .match_table
= hwicap_of_match
,
976 .probe
= hwicap_of_probe
,
977 .remove
= __devexit_p(hwicap_of_remove
),
983 /* Registration helpers to keep the number of #ifdefs to a minimum */
984 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
985 static inline int __devinit
hwicap_of_register(void)
987 static inline int __init
hwicap_of_register(void)
988 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
990 pr_debug("hwicap: calling of_register_platform_driver()\n");
991 return of_register_platform_driver(&hwicap_of_driver
);
994 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
995 static inline void __devexit
hwicap_of_unregister(void)
997 static inline void __exit
hwicap_of_unregister(void)
998 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1000 of_unregister_platform_driver(&hwicap_of_driver
);
1002 #else /* CONFIG_OF */
1003 /* CONFIG_OF not enabled; do nothing helpers */
1004 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1005 static inline int __devinit
hwicap_of_register(void) { return 0; }
1006 static inline void __devexit
hwicap_of_unregister(void) { }
1008 static inline int __init
hwicap_of_register(void) { return 0; }
1009 static inline void __exit
hwicap_of_unregister(void) { }
1010 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1011 #endif /* CONFIG_OF */
1013 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1014 static int __devinit
hwicap_module_init(void)
1016 static int __init
hwicap_module_init(void)
1017 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1022 icap_class
= class_create(THIS_MODULE
, "xilinx_config");
1023 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1025 mutex_init(&icap_sem
);
1026 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1028 if (xhwicap_major
) {
1029 devt
= MKDEV(xhwicap_major
, xhwicap_minor
);
1030 retval
= register_chrdev_region(
1037 retval
= alloc_chrdev_region(&devt
,
1043 xhwicap_major
= MAJOR(devt
);
1046 retval
= platform_driver_register(&hwicap_platform_driver
);
1051 retval
= hwicap_of_register();
1059 platform_driver_unregister(&hwicap_platform_driver
);
1062 unregister_chrdev_region(devt
, HWICAP_DEVICES
);
1067 <<<<<<< HEAD
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1068 static void __devexit
hwicap_module_cleanup(void)
1070 static void __exit
hwicap_module_cleanup(void)
1071 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/char/xilinx_hwicap
/xilinx_hwicap
.c
1073 dev_t devt
= MKDEV(xhwicap_major
, xhwicap_minor
);
1075 class_destroy(icap_class
);
1077 platform_driver_unregister(&hwicap_platform_driver
);
1079 hwicap_of_unregister();
1081 unregister_chrdev_region(devt
, HWICAP_DEVICES
);
1084 module_init(hwicap_module_init
);
1085 module_exit(hwicap_module_cleanup
);
1087 MODULE_AUTHOR("Xilinx, Inc; Xilinx Research Labs Group");
1088 MODULE_DESCRIPTION("Xilinx ICAP Port Driver");
1089 MODULE_LICENSE("GPL");