cb710.h 5.4 KB

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