parport.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* parport.h: sparc64 specific parport initialization and dma.
  2. *
  3. * Copyright (C) 1999 Eddie C. Dost ([email protected])
  4. */
  5. #ifndef _ASM_SPARC64_PARPORT_H
  6. #define _ASM_SPARC64_PARPORT_H 1
  7. #include <linux/of_device.h>
  8. #include <asm/ebus_dma.h>
  9. #include <asm/ns87303.h>
  10. #include <asm/prom.h>
  11. #define PARPORT_PC_MAX_PORTS PARPORT_MAX
  12. /*
  13. * While sparc64 doesn't have an ISA DMA API, we provide something that looks
  14. * close enough to make parport_pc happy
  15. */
  16. #define HAS_DMA
  17. static DEFINE_SPINLOCK(dma_spin_lock);
  18. #define claim_dma_lock() \
  19. ({ unsigned long flags; \
  20. spin_lock_irqsave(&dma_spin_lock, flags); \
  21. flags; \
  22. })
  23. #define release_dma_lock(__flags) \
  24. spin_unlock_irqrestore(&dma_spin_lock, __flags);
  25. static struct sparc_ebus_info {
  26. struct ebus_dma_info info;
  27. unsigned int addr;
  28. unsigned int count;
  29. int lock;
  30. struct parport *port;
  31. } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
  32. static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
  33. static inline int request_dma(unsigned int dmanr, const char *device_id)
  34. {
  35. if (dmanr >= PARPORT_PC_MAX_PORTS)
  36. return -EINVAL;
  37. if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
  38. return -EBUSY;
  39. return 0;
  40. }
  41. static inline void free_dma(unsigned int dmanr)
  42. {
  43. if (dmanr >= PARPORT_PC_MAX_PORTS) {
  44. printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
  45. return;
  46. }
  47. if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
  48. printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
  49. return;
  50. }
  51. }
  52. static inline void enable_dma(unsigned int dmanr)
  53. {
  54. ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
  55. if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
  56. sparc_ebus_dmas[dmanr].addr,
  57. sparc_ebus_dmas[dmanr].count))
  58. BUG();
  59. }
  60. static inline void disable_dma(unsigned int dmanr)
  61. {
  62. ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
  63. }
  64. static inline void clear_dma_ff(unsigned int dmanr)
  65. {
  66. /* nothing */
  67. }
  68. static inline void set_dma_mode(unsigned int dmanr, char mode)
  69. {
  70. ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
  71. }
  72. static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
  73. {
  74. sparc_ebus_dmas[dmanr].addr = addr;
  75. }
  76. static inline void set_dma_count(unsigned int dmanr, unsigned int count)
  77. {
  78. sparc_ebus_dmas[dmanr].count = count;
  79. }
  80. static inline unsigned int get_dma_residue(unsigned int dmanr)
  81. {
  82. return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
  83. }
  84. static int ecpp_probe(struct platform_device *op)
  85. {
  86. unsigned long base = op->resource[0].start;
  87. unsigned long config = op->resource[1].start;
  88. unsigned long d_base = op->resource[2].start;
  89. unsigned long d_len;
  90. struct device_node *parent;
  91. struct parport *p;
  92. int slot, err;
  93. parent = op->dev.of_node->parent;
  94. if (!strcmp(parent->name, "dma")) {
  95. p = parport_pc_probe_port(base, base + 0x400,
  96. op->archdata.irqs[0], PARPORT_DMA_NOFIFO,
  97. op->dev.parent->parent, 0);
  98. if (!p)
  99. return -ENOMEM;
  100. dev_set_drvdata(&op->dev, p);
  101. return 0;
  102. }
  103. for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
  104. if (!test_and_set_bit(slot, dma_slot_map))
  105. break;
  106. }
  107. err = -ENODEV;
  108. if (slot >= PARPORT_PC_MAX_PORTS)
  109. goto out_err;
  110. spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
  111. d_len = (op->resource[2].end - d_base) + 1UL;
  112. sparc_ebus_dmas[slot].info.regs =
  113. of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
  114. if (!sparc_ebus_dmas[slot].info.regs)
  115. goto out_clear_map;
  116. sparc_ebus_dmas[slot].info.flags = 0;
  117. sparc_ebus_dmas[slot].info.callback = NULL;
  118. sparc_ebus_dmas[slot].info.client_cookie = NULL;
  119. sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
  120. strcpy(sparc_ebus_dmas[slot].info.name, "parport");
  121. if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
  122. goto out_unmap_regs;
  123. ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
  124. /* Configure IRQ to Push Pull, Level Low */
  125. /* Enable ECP, set bit 2 of the CTR first */
  126. outb(0x04, base + 0x02);
  127. ns87303_modify(config, PCR,
  128. PCR_EPP_ENABLE |
  129. PCR_IRQ_ODRAIN,
  130. PCR_ECP_ENABLE |
  131. PCR_ECP_CLK_ENA |
  132. PCR_IRQ_POLAR);
  133. /* CTR bit 5 controls direction of port */
  134. ns87303_modify(config, PTR,
  135. 0, PTR_LPT_REG_DIR);
  136. p = parport_pc_probe_port(base, base + 0x400,
  137. op->archdata.irqs[0],
  138. slot,
  139. op->dev.parent,
  140. 0);
  141. err = -ENOMEM;
  142. if (!p)
  143. goto out_disable_irq;
  144. dev_set_drvdata(&op->dev, p);
  145. return 0;
  146. out_disable_irq:
  147. ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
  148. ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
  149. out_unmap_regs:
  150. of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
  151. out_clear_map:
  152. clear_bit(slot, dma_slot_map);
  153. out_err:
  154. return err;
  155. }
  156. static int ecpp_remove(struct platform_device *op)
  157. {
  158. struct parport *p = dev_get_drvdata(&op->dev);
  159. int slot = p->dma;
  160. parport_pc_unregister_port(p);
  161. if (slot != PARPORT_DMA_NOFIFO) {
  162. unsigned long d_base = op->resource[2].start;
  163. unsigned long d_len;
  164. d_len = (op->resource[2].end - d_base) + 1UL;
  165. ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
  166. ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
  167. of_iounmap(&op->resource[2],
  168. sparc_ebus_dmas[slot].info.regs,
  169. d_len);
  170. clear_bit(slot, dma_slot_map);
  171. }
  172. return 0;
  173. }
  174. static const struct of_device_id ecpp_match[] = {
  175. {
  176. .name = "ecpp",
  177. },
  178. {
  179. .name = "parallel",
  180. .compatible = "ecpp",
  181. },
  182. {
  183. .name = "parallel",
  184. .compatible = "ns87317-ecpp",
  185. },
  186. {
  187. .name = "parallel",
  188. .compatible = "pnpALI,1533,3",
  189. },
  190. {},
  191. };
  192. static struct platform_driver ecpp_driver = {
  193. .driver = {
  194. .name = "ecpp",
  195. .of_match_table = ecpp_match,
  196. },
  197. .probe = ecpp_probe,
  198. .remove = ecpp_remove,
  199. };
  200. static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
  201. {
  202. return platform_driver_register(&ecpp_driver);
  203. }
  204. #endif /* !(_ASM_SPARC64_PARPORT_H */