cb710.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. * 32-bit PIO mapping sg iterator
  123. *
  124. * Hides scatterlist access issues - fragment boundaries, alignment, page
  125. * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices
  126. * without DMA support).
  127. *
  128. * Best-case reading (transfer from device):
  129. * sg_miter_start(, SG_MITER_TO_SG);
  130. * cb710_sg_dwiter_write_from_io();
  131. * sg_miter_stop();
  132. *
  133. * Best-case writing (transfer to device):
  134. * sg_miter_start(, SG_MITER_FROM_SG);
  135. * cb710_sg_dwiter_read_to_io();
  136. * sg_miter_stop();
  137. */
  138. uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter);
  139. void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data);
  140. /**
  141. * cb710_sg_dwiter_write_from_io - transfer data to mapped buffer from 32-bit IO port
  142. * @miter: sg mapping iter
  143. * @port: PIO port - IO or MMIO address
  144. * @count: number of 32-bit words to transfer
  145. *
  146. * Description:
  147. * Reads @count 32-bit words from register @port and stores it in
  148. * buffer iterated by @miter. Data that would overflow the buffer
  149. * is silently ignored. Iterator is advanced by 4*@count bytes
  150. * or to the buffer's end whichever is closer.
  151. *
  152. * Context:
  153. * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
  154. */
  155. static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
  156. void __iomem *port, size_t count)
  157. {
  158. while (count-- > 0)
  159. cb710_sg_dwiter_write_next_block(miter, ioread32(port));
  160. }
  161. /**
  162. * cb710_sg_dwiter_read_to_io - transfer data to 32-bit IO port from mapped buffer
  163. * @miter: sg mapping iter
  164. * @port: PIO port - IO or MMIO address
  165. * @count: number of 32-bit words to transfer
  166. *
  167. * Description:
  168. * Writes @count 32-bit words to register @port from buffer iterated
  169. * through @miter. If buffer ends before @count words are written
  170. * missing data is replaced by zeroes. @miter is advanced by 4*@count
  171. * bytes or to the buffer's end whichever is closer.
  172. *
  173. * Context:
  174. * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
  175. */
  176. static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
  177. void __iomem *port, size_t count)
  178. {
  179. while (count-- > 0)
  180. iowrite32(cb710_sg_dwiter_read_next_block(miter), port);
  181. }
  182. #endif /* LINUX_CB710_SG_H */