bfin_crc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * bfin_crc.h - interface to Blackfin CRC controllers
  3. *
  4. * Copyright 2012 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef __BFIN_CRC_H__
  9. #define __BFIN_CRC_H__
  10. /* Function driver which use hardware crc must initialize the structure */
  11. struct crc_info {
  12. /* Input data address */
  13. unsigned char *in_addr;
  14. /* Output data address */
  15. unsigned char *out_addr;
  16. /* Input or output bytes */
  17. unsigned long datasize;
  18. union {
  19. /* CRC to compare with that of input buffer */
  20. unsigned long crc_compare;
  21. /* Value to compare with input data */
  22. unsigned long val_verify;
  23. /* Value to fill */
  24. unsigned long val_fill;
  25. };
  26. /* Value to program the 32b CRC Polynomial */
  27. unsigned long crc_poly;
  28. union {
  29. /* CRC calculated from the input data */
  30. unsigned long crc_result;
  31. /* First failed position to verify input data */
  32. unsigned long pos_verify;
  33. };
  34. /* CRC mirror flags */
  35. unsigned int bitmirr:1;
  36. unsigned int bytmirr:1;
  37. unsigned int w16swp:1;
  38. unsigned int fdsel:1;
  39. unsigned int rsltmirr:1;
  40. unsigned int polymirr:1;
  41. unsigned int cmpmirr:1;
  42. };
  43. /* Userspace interface */
  44. #define CRC_IOC_MAGIC 'C'
  45. #define CRC_IOC_CALC_CRC _IOWR('C', 0x01, unsigned int)
  46. #define CRC_IOC_MEMCPY_CRC _IOWR('C', 0x02, unsigned int)
  47. #define CRC_IOC_VERIFY_VAL _IOWR('C', 0x03, unsigned int)
  48. #define CRC_IOC_FILL_VAL _IOWR('C', 0x04, unsigned int)
  49. #ifdef __KERNEL__
  50. #include <linux/types.h>
  51. #include <linux/spinlock.h>
  52. #include <linux/miscdevice.h>
  53. struct crc_register {
  54. u32 control;
  55. u32 datacnt;
  56. u32 datacntrld;
  57. u32 __pad_1[2];
  58. u32 compare;
  59. u32 fillval;
  60. u32 datafifo;
  61. u32 intren;
  62. u32 intrenset;
  63. u32 intrenclr;
  64. u32 poly;
  65. u32 __pad_2[4];
  66. u32 status;
  67. u32 datacntcap;
  68. u32 __pad_3;
  69. u32 result;
  70. u32 curresult;
  71. u32 __pad_4[3];
  72. u32 revid;
  73. };
  74. /* CRC_STATUS Masks */
  75. #define CMPERR 0x00000002 /* Compare error */
  76. #define DCNTEXP 0x00000010 /* datacnt register expired */
  77. #define IBR 0x00010000 /* Input buffer ready */
  78. #define OBR 0x00020000 /* Output buffer ready */
  79. #define IRR 0x00040000 /* Immediate result readt */
  80. #define LUTDONE 0x00080000 /* Look-up table generation done */
  81. #define FSTAT 0x00700000 /* FIFO status */
  82. #define MAX_FIFO 4 /* Max fifo size */
  83. /* CRC_CONTROL Masks */
  84. #define BLKEN 0x00000001 /* Block enable */
  85. #define OPMODE 0x000000F0 /* Operation mode */
  86. #define OPMODE_OFFSET 4 /* Operation mode mask offset*/
  87. #define MODE_DMACPY_CRC 1 /* MTM CRC compute and compare */
  88. #define MODE_DATA_FILL 2 /* MTM data fill */
  89. #define MODE_CALC_CRC 3 /* MSM CRC compute and compare */
  90. #define MODE_DATA_VERIFY 4 /* MSM data verify */
  91. #define AUTOCLRZ 0x00000100 /* Auto clear to zero */
  92. #define AUTOCLRF 0x00000200 /* Auto clear to one */
  93. #define OBRSTALL 0x00001000 /* Stall on output buffer ready */
  94. #define IRRSTALL 0x00002000 /* Stall on immediate result ready */
  95. #define BITMIRR 0x00010000 /* Mirror bits within each byte of 32-bit input data */
  96. #define BITMIRR_OFFSET 16 /* Mirror bits offset */
  97. #define BYTMIRR 0x00020000 /* Mirror bytes of 32-bit input data */
  98. #define BYTMIRR_OFFSET 17 /* Mirror bytes offset */
  99. #define W16SWP 0x00040000 /* Mirror uppper and lower 16-bit word of 32-bit input data */
  100. #define W16SWP_OFFSET 18 /* Mirror 16-bit word offset */
  101. #define FDSEL 0x00080000 /* FIFO is written after input data is mirrored */
  102. #define FDSEL_OFFSET 19 /* Mirror FIFO offset */
  103. #define RSLTMIRR 0x00100000 /* CRC result registers are mirrored. */
  104. #define RSLTMIRR_OFFSET 20 /* Mirror CRC result offset. */
  105. #define POLYMIRR 0x00200000 /* CRC poly register is mirrored. */
  106. #define POLYMIRR_OFFSET 21 /* Mirror CRC poly offset. */
  107. #define CMPMIRR 0x00400000 /* CRC compare register is mirrored. */
  108. #define CMPMIRR_OFFSET 22 /* Mirror CRC compare offset. */
  109. /* CRC_INTREN Masks */
  110. #define CMPERRI 0x02 /* CRC_ERROR_INTR */
  111. #define DCNTEXPI 0x10 /* CRC_STATUS_INTR */
  112. #endif
  113. #endif