parport.h 4.3 KB

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