parport.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. static struct sparc_ebus_info {
  13. struct ebus_dma_info info;
  14. unsigned int addr;
  15. unsigned int count;
  16. } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
  17. static __inline__ void enable_dma(unsigned int dmanr)
  18. {
  19. if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
  20. sparc_ebus_dmas[dmanr].addr,
  21. sparc_ebus_dmas[dmanr].count))
  22. BUG();
  23. ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
  24. }
  25. static __inline__ void disable_dma(unsigned int dmanr)
  26. {
  27. ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
  28. }
  29. static __inline__ void clear_dma_ff(unsigned int dmanr)
  30. {
  31. /* nothing */
  32. }
  33. static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
  34. {
  35. ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
  36. }
  37. static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int addr)
  38. {
  39. sparc_ebus_dmas[dmanr].addr = addr;
  40. }
  41. static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
  42. {
  43. sparc_ebus_dmas[dmanr].count = count;
  44. }
  45. static __inline__ unsigned int get_dma_residue(unsigned int dmanr)
  46. {
  47. return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
  48. }
  49. static int ebus_ecpp_p(struct linux_ebus_device *edev)
  50. {
  51. if (!strcmp(edev->prom_name, "ecpp"))
  52. return 1;
  53. if (!strcmp(edev->prom_name, "parallel")) {
  54. char compat[19];
  55. prom_getstring(edev->prom_node,
  56. "compatible",
  57. compat, sizeof(compat));
  58. compat[18] = '\0';
  59. if (!strcmp(compat, "ecpp"))
  60. return 1;
  61. if (!strcmp(compat, "ns87317-ecpp") &&
  62. !strcmp(compat + 13, "ecpp"))
  63. return 1;
  64. }
  65. return 0;
  66. }
  67. static int parport_isa_probe(int count)
  68. {
  69. struct sparc_isa_bridge *isa_br;
  70. struct sparc_isa_device *isa_dev;
  71. for_each_isa(isa_br) {
  72. for_each_isadev(isa_dev, isa_br) {
  73. struct sparc_isa_device *child;
  74. unsigned long base;
  75. if (strcmp(isa_dev->prom_name, "dma"))
  76. continue;
  77. child = isa_dev->child;
  78. while (child) {
  79. if (!strcmp(child->prom_name, "parallel"))
  80. break;
  81. child = child->next;
  82. }
  83. if (!child)
  84. continue;
  85. base = child->resource.start;
  86. /* No DMA, see commentary in
  87. * asm-sparc64/floppy.h:isa_floppy_init()
  88. */
  89. if (parport_pc_probe_port(base, base + 0x400,
  90. child->irq, PARPORT_DMA_NOFIFO,
  91. child->bus->self))
  92. count++;
  93. }
  94. }
  95. return count;
  96. }
  97. static int parport_pc_find_nonpci_ports (int autoirq, int autodma)
  98. {
  99. struct linux_ebus *ebus;
  100. struct linux_ebus_device *edev;
  101. int count = 0;
  102. for_each_ebus(ebus) {
  103. for_each_ebusdev(edev, ebus) {
  104. if (ebus_ecpp_p(edev)) {
  105. unsigned long base = edev->resource[0].start;
  106. unsigned long config = edev->resource[1].start;
  107. unsigned long d_base = edev->resource[2].start;
  108. unsigned long d_len;
  109. spin_lock_init(&sparc_ebus_dmas[count].info.lock);
  110. d_len = (edev->resource[2].end -
  111. d_base) + 1;
  112. sparc_ebus_dmas[count].info.regs =
  113. ioremap(d_base, d_len);
  114. if (!sparc_ebus_dmas[count].info.regs)
  115. continue;
  116. sparc_ebus_dmas[count].info.flags = 0;
  117. sparc_ebus_dmas[count].info.callback = NULL;
  118. sparc_ebus_dmas[count].info.client_cookie = NULL;
  119. sparc_ebus_dmas[count].info.irq = 0xdeadbeef;
  120. strcpy(sparc_ebus_dmas[count].info.name, "parport");
  121. if (ebus_dma_register(&sparc_ebus_dmas[count].info))
  122. continue;
  123. ebus_dma_irq_enable(&sparc_ebus_dmas[count].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. if (parport_pc_probe_port(base, base + 0x400,
  137. edev->irqs[0],
  138. count, ebus->self))
  139. count++;
  140. }
  141. }
  142. }
  143. count = parport_isa_probe(count);
  144. return count;
  145. }
  146. #endif /* !(_ASM_SPARC64_PARPORT_H */