cb710.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * cb710/cb710.h
  3. *
  4. * Copyright by Michał Mirosław, 2008-2009
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef LINUX_CB710_DRIVER_H
  11. #define LINUX_CB710_DRIVER_H
  12. #include <linux/io.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/pci.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mmc/host.h>
  18. struct cb710_slot;
  19. typedef int (*cb710_irq_handler_t)(struct cb710_slot *);
  20. /* per-virtual-slot structure */
  21. struct cb710_slot {
  22. struct platform_device pdev;
  23. void __iomem *iobase;
  24. cb710_irq_handler_t irq_handler;
  25. };
  26. /* per-device structure */
  27. struct cb710_chip {
  28. struct pci_dev *pdev;
  29. void __iomem *iobase;
  30. unsigned platform_id;
  31. #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
  32. atomic_t slot_refs_count;
  33. #endif
  34. unsigned slot_mask;
  35. unsigned slots;
  36. spinlock_t irq_lock;
  37. struct cb710_slot slot[0];
  38. };
  39. /* NOTE: cb710_chip.slots is modified only during device init/exit and
  40. * they are all serialized wrt themselves */
  41. /* cb710_chip.slot_mask values */
  42. #define CB710_SLOT_MMC 1
  43. #define CB710_SLOT_MS 2
  44. #define CB710_SLOT_SM 4
  45. /* slot port accessors - so the logic is more clear in the code */
  46. #define CB710_PORT_ACCESSORS(t) \
  47. static inline void cb710_write_port_##t(struct cb710_slot *slot, \
  48. unsigned port, u##t value) \
  49. { \
  50. iowrite##t(value, slot->iobase + port); \
  51. } \
  52. \
  53. static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
  54. unsigned port) \
  55. { \
  56. return ioread##t(slot->iobase + port); \
  57. } \
  58. \
  59. static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
  60. unsigned port, u##t set, u##t clear) \
  61. { \
  62. iowrite##t( \
  63. (ioread##t(slot->iobase + port) & ~clear)|set, \
  64. slot->iobase + port); \
  65. }
  66. CB710_PORT_ACCESSORS(8)
  67. CB710_PORT_ACCESSORS(16)
  68. CB710_PORT_ACCESSORS(32)
  69. void cb710_pci_update_config_reg(struct pci_dev *pdev,
  70. int reg, uint32_t and, uint32_t xor);
  71. void cb710_set_irq_handler(struct cb710_slot *slot,
  72. cb710_irq_handler_t handler);
  73. /* some device struct walking */
  74. static inline struct cb710_slot *cb710_pdev_to_slot(
  75. struct platform_device *pdev)
  76. {
  77. return container_of(pdev, struct cb710_slot, pdev);
  78. }
  79. static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot)
  80. {
  81. return dev_get_drvdata(slot->pdev.dev.parent);
  82. }
  83. static inline struct device *cb710_slot_dev(struct cb710_slot *slot)
  84. {
  85. return &slot->pdev.dev;
  86. }
  87. static inline struct device *cb710_chip_dev(struct cb710_chip *chip)
  88. {
  89. return &chip->pdev->dev;
  90. }
  91. /* debugging aids */
  92. #ifdef CONFIG_CB710_DEBUG
  93. void cb710_dump_regs(struct cb710_chip *chip, unsigned dump);
  94. #else
  95. #define cb710_dump_regs(c, d) do {} while (0)
  96. #endif
  97. #define CB710_DUMP_REGS_MMC 0x0F
  98. #define CB710_DUMP_REGS_MS 0x30
  99. #define CB710_DUMP_REGS_SM 0xC0
  100. #define CB710_DUMP_REGS_ALL 0xFF
  101. #define CB710_DUMP_REGS_MASK 0xFF
  102. #define CB710_DUMP_ACCESS_8 0x100
  103. #define CB710_DUMP_ACCESS_16 0x200
  104. #define CB710_DUMP_ACCESS_32 0x400
  105. #define CB710_DUMP_ACCESS_ALL 0x700
  106. #define CB710_DUMP_ACCESS_MASK 0x700
  107. #endif /* LINUX_CB710_DRIVER_H */
  108. /*
  109. * cb710/sgbuf2.h
  110. *
  111. * Copyright by Michał Mirosław, 2008-2009
  112. *
  113. * This program is free software; you can redistribute it and/or modify
  114. * it under the terms of the GNU General Public License version 2 as
  115. * published by the Free Software Foundation.
  116. */
  117. #ifndef LINUX_CB710_SG_H
  118. #define LINUX_CB710_SG_H
  119. #include <linux/highmem.h>
  120. #include <linux/scatterlist.h>
  121. /**
  122. * cb710_sg_miter_stop_writing - stop mapping iteration after writing
  123. * @miter: sg mapping iter to be stopped
  124. *
  125. * Description:
  126. * Stops mapping iterator @miter. @miter should have been started
  127. * started using sg_miter_start(). A stopped iteration can be
  128. * resumed by calling sg_miter_next() on it. This is useful when
  129. * resources (kmap) need to be released during iteration.
  130. *
  131. * This is a convenience wrapper that will be optimized out for arches
  132. * that don't need flush_kernel_dcache_page().
  133. *
  134. * Context:
  135. * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
  136. */
  137. static inline void cb710_sg_miter_stop_writing(struct sg_mapping_iter *miter)
  138. {
  139. if (miter->page)
  140. flush_kernel_dcache_page(miter->page);
  141. sg_miter_stop(miter);
  142. }
  143. /*
  144. * 32-bit PIO mapping sg iterator
  145. *
  146. * Hides scatterlist access issues - fragment boundaries, alignment, page
  147. * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices
  148. * without DMA support).
  149. *
  150. * Best-case reading (transfer from device):
  151. * sg_miter_start();
  152. * cb710_sg_dwiter_write_from_io();
  153. * cb710_sg_miter_stop_writing();
  154. *
  155. * Best-case writing (transfer to device):
  156. * sg_miter_start();
  157. * cb710_sg_dwiter_read_to_io();
  158. * sg_miter_stop();
  159. */
  160. uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter);
  161. void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data);
  162. /**
  163. * cb710_sg_dwiter_write_from_io - transfer data to mapped buffer from 32-bit IO port
  164. * @miter: sg mapping iter
  165. * @port: PIO port - IO or MMIO address
  166. * @count: number of 32-bit words to transfer
  167. *
  168. * Description:
  169. * Reads @count 32-bit words from register @port and stores it in
  170. * buffer iterated by @miter. Data that would overflow the buffer
  171. * is silently ignored. Iterator is advanced by 4*@count bytes
  172. * or to the buffer's end whichever is closer.
  173. *
  174. * Context:
  175. * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
  176. */
  177. static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
  178. void __iomem *port, size_t count)
  179. {
  180. while (count-- > 0)
  181. cb710_sg_dwiter_write_next_block(miter, ioread32(port));
  182. }
  183. /**
  184. * cb710_sg_dwiter_read_to_io - transfer data to 32-bit IO port from mapped buffer
  185. * @miter: sg mapping iter
  186. * @port: PIO port - IO or MMIO address
  187. * @count: number of 32-bit words to transfer
  188. *
  189. * Description:
  190. * Writes @count 32-bit words to register @port from buffer iterated
  191. * through @miter. If buffer ends before @count words are written
  192. * missing data is replaced by zeroes. @miter is advanced by 4*@count
  193. * bytes or to the buffer's end whichever is closer.
  194. *
  195. * Context:
  196. * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
  197. */
  198. static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
  199. void __iomem *port, size_t count)
  200. {
  201. while (count-- > 0)
  202. iowrite32(cb710_sg_dwiter_read_next_block(miter), port);
  203. }
  204. #endif /* LINUX_CB710_SG_H */