parport.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_name, "ecpp"))
  57. return 1;
  58. if (!strcmp(edev->prom_name, "parallel")) {
  59. char compat[19];
  60. prom_getstring(edev->prom_node,
  61. "compatible",
  62. compat, sizeof(compat));
  63. compat[18] = '\0';
  64. if (!strcmp(compat, "ecpp"))
  65. return 1;
  66. if (!strcmp(compat, "ns87317-ecpp") &&
  67. !strcmp(compat + 13, "ecpp"))
  68. return 1;
  69. }
  70. return 0;
  71. }
  72. static int parport_isa_probe(int count)
  73. {
  74. struct sparc_isa_bridge *isa_br;
  75. struct sparc_isa_device *isa_dev;
  76. for_each_isa(isa_br) {
  77. for_each_isadev(isa_dev, isa_br) {
  78. struct sparc_isa_device *child;
  79. unsigned long base;
  80. if (strcmp(isa_dev->prom_name, "dma"))
  81. continue;
  82. child = isa_dev->child;
  83. while (child) {
  84. if (!strcmp(child->prom_name, "parallel"))
  85. break;
  86. child = child->next;
  87. }
  88. if (!child)
  89. continue;
  90. base = child->resource.start;
  91. /* No DMA, see commentary in
  92. * asm-sparc64/floppy.h:isa_floppy_init()
  93. */
  94. if (parport_pc_probe_port(base, base + 0x400,
  95. child->irq, PARPORT_DMA_NOFIFO,
  96. child->bus->self))
  97. count++;
  98. }
  99. }
  100. return count;
  101. }
  102. static int parport_pc_find_nonpci_ports (int autoirq, int autodma)
  103. {
  104. struct linux_ebus *ebus;
  105. struct linux_ebus_device *edev;
  106. int count = 0;
  107. for_each_ebus(ebus) {
  108. for_each_ebusdev(edev, ebus) {
  109. if (ebus_ecpp_p(edev)) {
  110. unsigned long base = edev->resource[0].start;
  111. unsigned long config = edev->resource[1].start;
  112. unsigned long d_base = edev->resource[2].start;
  113. unsigned long d_len;
  114. spin_lock_init(&sparc_ebus_dmas[count].info.lock);
  115. d_len = (edev->resource[2].end -
  116. d_base) + 1;
  117. sparc_ebus_dmas[count].info.regs =
  118. ioremap(d_base, d_len);
  119. if (!sparc_ebus_dmas[count].info.regs)
  120. continue;
  121. sparc_ebus_dmas[count].info.flags = 0;
  122. sparc_ebus_dmas[count].info.callback = NULL;
  123. sparc_ebus_dmas[count].info.client_cookie = NULL;
  124. sparc_ebus_dmas[count].info.irq = 0xdeadbeef;
  125. strcpy(sparc_ebus_dmas[count].info.name, "parport");
  126. if (ebus_dma_register(&sparc_ebus_dmas[count].info))
  127. continue;
  128. ebus_dma_irq_enable(&sparc_ebus_dmas[count].info, 1);
  129. /* Configure IRQ to Push Pull, Level Low */
  130. /* Enable ECP, set bit 2 of the CTR first */
  131. outb(0x04, base + 0x02);
  132. ns87303_modify(config, PCR,
  133. PCR_EPP_ENABLE |
  134. PCR_IRQ_ODRAIN,
  135. PCR_ECP_ENABLE |
  136. PCR_ECP_CLK_ENA |
  137. PCR_IRQ_POLAR);
  138. /* CTR bit 5 controls direction of port */
  139. ns87303_modify(config, PTR,
  140. 0, PTR_LPT_REG_DIR);
  141. if (parport_pc_probe_port(base, base + 0x400,
  142. edev->irqs[0],
  143. count, ebus->self))
  144. count++;
  145. }
  146. }
  147. }
  148. count = parport_isa_probe(count);
  149. return count;
  150. }
  151. #endif /* !(_ASM_SPARC64_PARPORT_H */