cb710.h 6.5 KB

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