parport.h 4.8 KB

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