xilinx_hwicap.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*****************************************************************************
  2. *
  3. * Author: Xilinx, Inc.
  4. *
  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.
  9. *
  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.
  23. *
  24. * (c) Copyright 2003-2007 Xilinx Inc.
  25. * All rights reserved.
  26. *
  27. * You should have received a copy of the GNU General Public License along
  28. * with this program; if not, write to the Free Software Foundation, Inc.,
  29. * 675 Mass Ave, Cambridge, MA 02139, USA.
  30. *
  31. *****************************************************************************/
  32. #ifndef XILINX_HWICAP_H_ /* prevent circular inclusions */
  33. #define XILINX_HWICAP_H_ /* by using protection macros */
  34. #include <linux/types.h>
  35. #include <linux/cdev.h>
  36. #include <linux/platform_device.h>
  37. #include <asm/io.h>
  38. struct hwicap_drvdata {
  39. u32 write_buffer_in_use; /* Always in [0,3] */
  40. u8 write_buffer[4];
  41. u32 read_buffer_in_use; /* Always in [0,3] */
  42. u8 read_buffer[4];
  43. resource_size_t mem_start;/* phys. address of the control registers */
  44. resource_size_t mem_end; /* phys. address of the control registers */
  45. resource_size_t mem_size;
  46. void __iomem *base_address;/* virt. address of the control registers */
  47. struct device *dev;
  48. struct cdev cdev; /* Char device structure */
  49. dev_t devt;
  50. const struct hwicap_driver_config *config;
  51. const struct config_registers *config_regs;
  52. void *private_data;
  53. bool is_open;
  54. struct mutex sem;
  55. };
  56. struct hwicap_driver_config {
  57. /* Read configuration data given by size into the data buffer.
  58. Return 0 if successful. */
  59. int (*get_configuration)(struct hwicap_drvdata *drvdata, u32 *data,
  60. u32 size);
  61. /* Write configuration data given by size from the data buffer.
  62. Return 0 if successful. */
  63. int (*set_configuration)(struct hwicap_drvdata *drvdata, u32 *data,
  64. u32 size);
  65. /* Get the status register, bit pattern given by:
  66. * D8 - 0 = configuration error
  67. * D7 - 1 = alignment found
  68. * D6 - 1 = readback in progress
  69. * D5 - 0 = abort in progress
  70. * D4 - Always 1
  71. * D3 - Always 1
  72. * D2 - Always 1
  73. * D1 - Always 1
  74. * D0 - 1 = operation completed
  75. */
  76. u32 (*get_status)(struct hwicap_drvdata *drvdata);
  77. /* Reset the hw */
  78. void (*reset)(struct hwicap_drvdata *drvdata);
  79. };
  80. /* Number of times to poll the done regsiter */
  81. #define XHI_MAX_RETRIES 10
  82. /************ Constant Definitions *************/
  83. #define XHI_PAD_FRAMES 0x1
  84. /* Mask for calculating configuration packet headers */
  85. #define XHI_WORD_COUNT_MASK_TYPE_1 0x7FFUL
  86. #define XHI_WORD_COUNT_MASK_TYPE_2 0x1FFFFFUL
  87. #define XHI_TYPE_MASK 0x7
  88. #define XHI_REGISTER_MASK 0xF
  89. #define XHI_OP_MASK 0x3
  90. #define XHI_TYPE_SHIFT 29
  91. #define XHI_REGISTER_SHIFT 13
  92. #define XHI_OP_SHIFT 27
  93. #define XHI_TYPE_1 1
  94. #define XHI_TYPE_2 2
  95. #define XHI_OP_WRITE 2
  96. #define XHI_OP_READ 1
  97. /* Address Block Types */
  98. #define XHI_FAR_CLB_BLOCK 0
  99. #define XHI_FAR_BRAM_BLOCK 1
  100. #define XHI_FAR_BRAM_INT_BLOCK 2
  101. struct config_registers {
  102. u32 CRC;
  103. u32 FAR;
  104. u32 FDRI;
  105. u32 FDRO;
  106. u32 CMD;
  107. u32 CTL;
  108. u32 MASK;
  109. u32 STAT;
  110. u32 LOUT;
  111. u32 COR;
  112. u32 MFWR;
  113. u32 FLR;
  114. u32 KEY;
  115. u32 CBC;
  116. u32 IDCODE;
  117. u32 AXSS;
  118. u32 C0R_1;
  119. u32 CSOB;
  120. u32 WBSTAR;
  121. u32 TIMER;
  122. u32 BOOTSTS;
  123. u32 CTL_1;
  124. };
  125. /* Configuration Commands */
  126. #define XHI_CMD_NULL 0
  127. #define XHI_CMD_WCFG 1
  128. #define XHI_CMD_MFW 2
  129. #define XHI_CMD_DGHIGH 3
  130. #define XHI_CMD_RCFG 4
  131. #define XHI_CMD_START 5
  132. #define XHI_CMD_RCAP 6
  133. #define XHI_CMD_RCRC 7
  134. #define XHI_CMD_AGHIGH 8
  135. #define XHI_CMD_SWITCH 9
  136. #define XHI_CMD_GRESTORE 10
  137. #define XHI_CMD_SHUTDOWN 11
  138. #define XHI_CMD_GCAPTURE 12
  139. #define XHI_CMD_DESYNCH 13
  140. #define XHI_CMD_IPROG 15 /* Only in Virtex5 */
  141. #define XHI_CMD_CRCC 16 /* Only in Virtex5 */
  142. #define XHI_CMD_LTIMER 17 /* Only in Virtex5 */
  143. /* Packet constants */
  144. #define XHI_SYNC_PACKET 0xAA995566UL
  145. #define XHI_DUMMY_PACKET 0xFFFFFFFFUL
  146. #define XHI_NOOP_PACKET (XHI_TYPE_1 << XHI_TYPE_SHIFT)
  147. #define XHI_TYPE_2_READ ((XHI_TYPE_2 << XHI_TYPE_SHIFT) | \
  148. (XHI_OP_READ << XHI_OP_SHIFT))
  149. #define XHI_TYPE_2_WRITE ((XHI_TYPE_2 << XHI_TYPE_SHIFT) | \
  150. (XHI_OP_WRITE << XHI_OP_SHIFT))
  151. #define XHI_TYPE2_CNT_MASK 0x07FFFFFF
  152. #define XHI_TYPE_1_PACKET_MAX_WORDS 2047UL
  153. #define XHI_TYPE_1_HEADER_BYTES 4
  154. #define XHI_TYPE_2_HEADER_BYTES 8
  155. /* Constant to use for CRC check when CRC has been disabled */
  156. #define XHI_DISABLED_AUTO_CRC 0x0000DEFCUL
  157. /* Meanings of the bits returned by get_status */
  158. #define XHI_SR_CFGERR_N_MASK 0x00000100 /* Config Error Mask */
  159. #define XHI_SR_DALIGN_MASK 0x00000080 /* Data Alignment Mask */
  160. #define XHI_SR_RIP_MASK 0x00000040 /* Read back Mask */
  161. #define XHI_SR_IN_ABORT_N_MASK 0x00000020 /* Select Map Abort Mask */
  162. #define XHI_SR_DONE_MASK 0x00000001 /* Done bit Mask */
  163. /**
  164. * hwicap_type_1_read - Generates a Type 1 read packet header.
  165. * @reg: is the address of the register to be read back.
  166. *
  167. * Generates a Type 1 read packet header, which is used to indirectly
  168. * read registers in the configuration logic. This packet must then
  169. * be sent through the icap device, and a return packet received with
  170. * the information.
  171. **/
  172. static inline u32 hwicap_type_1_read(u32 reg)
  173. {
  174. return (XHI_TYPE_1 << XHI_TYPE_SHIFT) |
  175. (reg << XHI_REGISTER_SHIFT) |
  176. (XHI_OP_READ << XHI_OP_SHIFT);
  177. }
  178. /**
  179. * hwicap_type_1_write - Generates a Type 1 write packet header
  180. * @reg: is the address of the register to be read back.
  181. **/
  182. static inline u32 hwicap_type_1_write(u32 reg)
  183. {
  184. return (XHI_TYPE_1 << XHI_TYPE_SHIFT) |
  185. (reg << XHI_REGISTER_SHIFT) |
  186. (XHI_OP_WRITE << XHI_OP_SHIFT);
  187. }
  188. #endif