parport.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* $Id: parport.h,v 1.11 2001/05/11 07:54:24 davem Exp $
  2. * parport.h: sparc64 specific parport initialization and dma.
  3. *
  4. * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
  5. */
  6. #ifndef _ASM_SPARC64_PARPORT_H
  7. #define _ASM_SPARC64_PARPORT_H 1
  8. #include <asm/ebus.h>
  9. #include <asm/isa.h>
  10. #include <asm/ns87303.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. } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
  31. static __inline__ int request_dma(unsigned int dmanr, const char *device_id)
  32. {
  33. if (dmanr >= PARPORT_PC_MAX_PORTS)
  34. return -EINVAL;
  35. if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
  36. return -EBUSY;
  37. return 0;
  38. }
  39. static __inline__ void free_dma(unsigned int dmanr)
  40. {
  41. if (dmanr >= PARPORT_PC_MAX_PORTS) {
  42. printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
  43. return;
  44. }
  45. if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
  46. printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
  47. return;
  48. }
  49. }
  50. static __inline__ void enable_dma(unsigned int dmanr)
  51. {
  52. ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
  53. if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
  54. sparc_ebus_dmas[dmanr].addr,
  55. sparc_ebus_dmas[dmanr].count))
  56. BUG();
  57. }
  58. static __inline__ void disable_dma(unsigned int dmanr)
  59. {
  60. ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
  61. }
  62. static __inline__ void clear_dma_ff(unsigned int dmanr)
  63. {
  64. /* nothing */
  65. }
  66. static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
  67. {
  68. ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
  69. }
  70. static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int addr)
  71. {
  72. sparc_ebus_dmas[dmanr].addr = addr;
  73. }
  74. static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
  75. {
  76. sparc_ebus_dmas[dmanr].count = count;
  77. }
  78. static __inline__ unsigned int get_dma_residue(unsigned int dmanr)
  79. {
  80. return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
  81. }
  82. static int ebus_ecpp_p(struct linux_ebus_device *edev)
  83. {
  84. if (!strcmp(edev->prom_node->name, "ecpp"))
  85. return 1;
  86. if (!strcmp(edev->prom_node->name, "parallel")) {
  87. const char *compat;
  88. compat = of_get_property(edev->prom_node,
  89. "compatible", NULL);
  90. if (compat &&
  91. (!strcmp(compat, "ecpp") ||
  92. !strcmp(compat, "ns87317-ecpp") ||
  93. !strcmp(compat + 13, "ecpp")))
  94. return 1;
  95. }
  96. return 0;
  97. }
  98. static int parport_isa_probe(int count)
  99. {
  100. struct sparc_isa_bridge *isa_br;
  101. struct sparc_isa_device *isa_dev;
  102. for_each_isa(isa_br) {
  103. for_each_isadev(isa_dev, isa_br) {
  104. struct sparc_isa_device *child;
  105. unsigned long base;
  106. if (strcmp(isa_dev->prom_node->name, "dma"))
  107. continue;
  108. child = isa_dev->child;
  109. while (child) {
  110. if (!strcmp(child->prom_node->name, "parallel"))
  111. break;
  112. child = child->next;
  113. }
  114. if (!child)
  115. continue;
  116. base = child->resource.start;
  117. /* No DMA, see commentary in
  118. * asm-sparc64/floppy.h:isa_floppy_init()
  119. */
  120. if (parport_pc_probe_port(base, base + 0x400,
  121. child->irq, PARPORT_DMA_NOFIFO,
  122. &child->bus->self->dev))
  123. count++;
  124. }
  125. }
  126. return count;
  127. }
  128. static int parport_pc_find_nonpci_ports (int autoirq, int autodma)
  129. {
  130. struct linux_ebus *ebus;
  131. struct linux_ebus_device *edev;
  132. int count = 0;
  133. for_each_ebus(ebus) {
  134. for_each_ebusdev(edev, ebus) {
  135. if (ebus_ecpp_p(edev)) {
  136. unsigned long base = edev->resource[0].start;
  137. unsigned long config = edev->resource[1].start;
  138. unsigned long d_base = edev->resource[2].start;
  139. unsigned long d_len;
  140. spin_lock_init(&sparc_ebus_dmas[count].info.lock);
  141. d_len = (edev->resource[2].end -
  142. d_base) + 1;
  143. sparc_ebus_dmas[count].info.regs =
  144. ioremap(d_base, d_len);
  145. if (!sparc_ebus_dmas[count].info.regs)
  146. continue;
  147. sparc_ebus_dmas[count].info.flags = 0;
  148. sparc_ebus_dmas[count].info.callback = NULL;
  149. sparc_ebus_dmas[count].info.client_cookie = NULL;
  150. sparc_ebus_dmas[count].info.irq = 0xdeadbeef;
  151. strcpy(sparc_ebus_dmas[count].info.name, "parport");
  152. if (ebus_dma_register(&sparc_ebus_dmas[count].info))
  153. continue;
  154. ebus_dma_irq_enable(&sparc_ebus_dmas[count].info, 1);
  155. /* Configure IRQ to Push Pull, Level Low */
  156. /* Enable ECP, set bit 2 of the CTR first */
  157. outb(0x04, base + 0x02);
  158. ns87303_modify(config, PCR,
  159. PCR_EPP_ENABLE |
  160. PCR_IRQ_ODRAIN,
  161. PCR_ECP_ENABLE |
  162. PCR_ECP_CLK_ENA |
  163. PCR_IRQ_POLAR);
  164. /* CTR bit 5 controls direction of port */
  165. ns87303_modify(config, PTR,
  166. 0, PTR_LPT_REG_DIR);
  167. if (parport_pc_probe_port(base, base + 0x400,
  168. edev->irqs[0],
  169. count,
  170. &ebus->self->dev))
  171. count++;
  172. }
  173. }
  174. }
  175. count = parport_isa_probe(count);
  176. return count;
  177. }
  178. #endif /* !(_ASM_SPARC64_PARPORT_H */