r592.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (C) 2010 - Maxim Levitsky
  3. * driver for Ricoh memstick readers
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef R592_H
  10. #include <linux/memstick.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/kfifo.h>
  15. #include <linux/ctype.h>
  16. /* write to this reg (number,len) triggers TPC execution */
  17. #define R592_TPC_EXEC 0x00
  18. #define R592_TPC_EXEC_LEN_SHIFT 16 /* Bits 16..25 are TPC len */
  19. #define R592_TPC_EXEC_BIG_FIFO (1 << 26) /* If bit 26 is set, large fifo is used (reg 48) */
  20. #define R592_TPC_EXEC_TPC_SHIFT 28 /* Bits 28..31 are the TPC number */
  21. /* Window for small TPC fifo (big endian)*/
  22. /* reads and writes always are done in 8 byte chunks */
  23. /* Not used in driver, because large fifo does better job */
  24. #define R592_SFIFO 0x08
  25. /* Status register (ms int, small fifo, IO)*/
  26. #define R592_STATUS 0x10
  27. /* Parallel INT bits */
  28. #define R592_STATUS_P_CMDNACK (1 << 16) /* INT reg: NACK (parallel mode) */
  29. #define R592_STATUS_P_BREQ (1 << 17) /* INT reg: card ready (parallel mode)*/
  30. #define R592_STATUS_P_INTERR (1 << 18) /* INT reg: int error (parallel mode)*/
  31. #define R592_STATUS_P_CED (1 << 19) /* INT reg: command done (parallel mode) */
  32. /* Fifo status */
  33. #define R592_STATUS_SFIFO_FULL (1 << 20) /* Small Fifo almost full (last chunk is written) */
  34. #define R592_STATUS_SFIFO_EMPTY (1 << 21) /* Small Fifo empty */
  35. /* Error detection via CRC */
  36. #define R592_STATUS_SEND_ERR (1 << 24) /* Send failed */
  37. #define R592_STATUS_RECV_ERR (1 << 25) /* Receive failed */
  38. /* Card state */
  39. #define R592_STATUS_RDY (1 << 28) /* RDY signal received */
  40. #define R592_STATUS_CED (1 << 29) /* INT: Command done (serial mode)*/
  41. #define R592_STATUS_SFIFO_INPUT (1 << 30) /* Small fifo received data*/
  42. #define R592_SFIFO_SIZE 32 /* total size of small fifo is 32 bytes */
  43. #define R592_SFIFO_PACKET 8 /* packet size of small fifo */
  44. /* IO control */
  45. #define R592_IO 0x18
  46. #define R592_IO_16 (1 << 16) /* Set by default, can be cleared */
  47. #define R592_IO_18 (1 << 18) /* Set by default, can be cleared */
  48. #define R592_IO_SERIAL1 (1 << 20) /* Set by default, can be cleared, (cleared on parallel) */
  49. #define R592_IO_22 (1 << 22) /* Set by default, can be cleared */
  50. #define R592_IO_DIRECTION (1 << 24) /* TPC direction (1 write 0 read) */
  51. #define R592_IO_26 (1 << 26) /* Set by default, can be cleared */
  52. #define R592_IO_SERIAL2 (1 << 30) /* Set by default, can be cleared (cleared on parallel), serial doesn't work if unset */
  53. #define R592_IO_RESET (1 << 31) /* Reset, sets defaults*/
  54. /* Turns hardware on/off */
  55. #define R592_POWER 0x20 /* bits 0-7 writeable */
  56. #define R592_POWER_0 (1 << 0) /* set on start, cleared on stop - must be set*/
  57. #define R592_POWER_1 (1 << 1) /* set on start, cleared on stop - must be set*/
  58. #define R592_POWER_3 (1 << 3) /* must be clear */
  59. #define R592_POWER_20 (1 << 5) /* set before switch to parallel */
  60. /* IO mode*/
  61. #define R592_IO_MODE 0x24
  62. #define R592_IO_MODE_SERIAL 1
  63. #define R592_IO_MODE_PARALLEL 3
  64. /* IRQ,card detection,large fifo (first word irq status, second enable) */
  65. /* IRQs are ACKed by clearing the bits */
  66. #define R592_REG_MSC 0x28
  67. #define R592_REG_MSC_PRSNT (1 << 1) /* card present (only status)*/
  68. #define R592_REG_MSC_IRQ_INSERT (1 << 8) /* detect insert / card insered */
  69. #define R592_REG_MSC_IRQ_REMOVE (1 << 9) /* detect removal / card removed */
  70. #define R592_REG_MSC_FIFO_EMPTY (1 << 10) /* fifo is empty */
  71. #define R592_REG_MSC_FIFO_DMA_DONE (1 << 11) /* dma enable / dma done */
  72. #define R592_REG_MSC_FIFO_USER_ORN (1 << 12) /* set if software reads empty fifo (if R592_REG_MSC_FIFO_EMPTY is set) */
  73. #define R592_REG_MSC_FIFO_MISMATH (1 << 13) /* set if amount of data in fifo doesn't match amount in TPC */
  74. #define R592_REG_MSC_FIFO_DMA_ERR (1 << 14) /* IO failure */
  75. #define R592_REG_MSC_LED (1 << 15) /* clear to turn led off (only status)*/
  76. #define DMA_IRQ_ACK_MASK \
  77. (R592_REG_MSC_FIFO_DMA_DONE | R592_REG_MSC_FIFO_DMA_ERR)
  78. #define DMA_IRQ_EN_MASK (DMA_IRQ_ACK_MASK << 16)
  79. #define IRQ_ALL_ACK_MASK 0x00007F00
  80. #define IRQ_ALL_EN_MASK (IRQ_ALL_ACK_MASK << 16)
  81. /* DMA address for large FIFO read/writes*/
  82. #define R592_FIFO_DMA 0x2C
  83. /* PIO access to large FIFO (512 bytes) (big endian)*/
  84. #define R592_FIFO_PIO 0x30
  85. #define R592_LFIFO_SIZE 512 /* large fifo size */
  86. /* large FIFO DMA settings */
  87. #define R592_FIFO_DMA_SETTINGS 0x34
  88. #define R592_FIFO_DMA_SETTINGS_EN (1 << 0) /* DMA enabled */
  89. #define R592_FIFO_DMA_SETTINGS_DIR (1 << 1) /* Dma direction (1 read, 0 write) */
  90. #define R592_FIFO_DMA_SETTINGS_CAP (1 << 24) /* Dma is aviable */
  91. /* Maybe just an delay */
  92. /* Bits 17..19 are just number */
  93. /* bit 16 is set, then bit 20 is waited */
  94. /* time to wait is about 50 spins * 2 ^ (bits 17..19) */
  95. /* seems to be possible just to ignore */
  96. /* Probably debug register */
  97. #define R592_REG38 0x38
  98. #define R592_REG38_CHANGE (1 << 16) /* Start bit */
  99. #define R592_REG38_DONE (1 << 20) /* HW set this after the delay */
  100. #define R592_REG38_SHIFT 17
  101. /* Debug register, written (0xABCDEF00) when error happens - not used*/
  102. #define R592_REG_3C 0x3C
  103. struct r592_device {
  104. struct pci_dev *pci_dev;
  105. struct memstick_host *host; /* host backpointer */
  106. struct memstick_request *req; /* current request */
  107. /* Registers, IRQ */
  108. void __iomem *mmio;
  109. int irq;
  110. spinlock_t irq_lock;
  111. spinlock_t io_thread_lock;
  112. struct timer_list detect_timer;
  113. struct task_struct *io_thread;
  114. bool parallel_mode;
  115. DECLARE_KFIFO(pio_fifo, u8, sizeof(u32));
  116. /* DMA area */
  117. int dma_capable;
  118. int dma_error;
  119. struct completion dma_done;
  120. void *dummy_dma_page;
  121. dma_addr_t dummy_dma_page_physical_address;
  122. };
  123. #define DRV_NAME "r592"
  124. #define message(format, ...) \
  125. printk(KERN_INFO DRV_NAME ": " format "\n", ## __VA_ARGS__)
  126. #define __dbg(level, format, ...) \
  127. do { \
  128. if (debug >= level) \
  129. printk(KERN_DEBUG DRV_NAME \
  130. ": " format "\n", ## __VA_ARGS__); \
  131. } while (0)
  132. #define dbg(format, ...) __dbg(1, format, ## __VA_ARGS__)
  133. #define dbg_verbose(format, ...) __dbg(2, format, ## __VA_ARGS__)
  134. #define dbg_reg(format, ...) __dbg(3, format, ## __VA_ARGS__)
  135. #endif