dma-isa.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * linux/arch/arm/kernel/dma-isa.c
  3. *
  4. * Copyright (C) 1999-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * ISA DMA primitives
  11. * Taken from various sources, including:
  12. * linux/include/asm/dma.h: Defines for using and allocating dma channels.
  13. * Written by Hennus Bergman, 1992.
  14. * High DMA channel support & info by Hannu Savolainen and John Boyd,
  15. * Nov. 1992.
  16. * arch/arm/kernel/dma-ebsa285.c
  17. * Copyright (C) 1998 Phil Blundell
  18. */
  19. #include <linux/ioport.h>
  20. #include <linux/init.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/io.h>
  23. #include <asm/dma.h>
  24. #include <asm/mach/dma.h>
  25. #define ISA_DMA_MASK 0
  26. #define ISA_DMA_MODE 1
  27. #define ISA_DMA_CLRFF 2
  28. #define ISA_DMA_PGHI 3
  29. #define ISA_DMA_PGLO 4
  30. #define ISA_DMA_ADDR 5
  31. #define ISA_DMA_COUNT 6
  32. static unsigned int isa_dma_port[8][7] = {
  33. /* MASK MODE CLRFF PAGE_HI PAGE_LO ADDR COUNT */
  34. { 0x0a, 0x0b, 0x0c, 0x487, 0x087, 0x00, 0x01 },
  35. { 0x0a, 0x0b, 0x0c, 0x483, 0x083, 0x02, 0x03 },
  36. { 0x0a, 0x0b, 0x0c, 0x481, 0x081, 0x04, 0x05 },
  37. { 0x0a, 0x0b, 0x0c, 0x482, 0x082, 0x06, 0x07 },
  38. { 0xd4, 0xd6, 0xd8, 0x000, 0x000, 0xc0, 0xc2 },
  39. { 0xd4, 0xd6, 0xd8, 0x48b, 0x08b, 0xc4, 0xc6 },
  40. { 0xd4, 0xd6, 0xd8, 0x489, 0x089, 0xc8, 0xca },
  41. { 0xd4, 0xd6, 0xd8, 0x48a, 0x08a, 0xcc, 0xce }
  42. };
  43. static int isa_get_dma_residue(unsigned int chan, dma_t *dma)
  44. {
  45. unsigned int io_port = isa_dma_port[chan][ISA_DMA_COUNT];
  46. int count;
  47. count = 1 + inb(io_port);
  48. count |= inb(io_port) << 8;
  49. return chan < 4 ? count : (count << 1);
  50. }
  51. static void isa_enable_dma(unsigned int chan, dma_t *dma)
  52. {
  53. if (dma->invalid) {
  54. unsigned long address, length;
  55. unsigned int mode;
  56. enum dma_data_direction direction;
  57. mode = (chan & 3) | dma->dma_mode;
  58. switch (dma->dma_mode & DMA_MODE_MASK) {
  59. case DMA_MODE_READ:
  60. direction = DMA_FROM_DEVICE;
  61. break;
  62. case DMA_MODE_WRITE:
  63. direction = DMA_TO_DEVICE;
  64. break;
  65. case DMA_MODE_CASCADE:
  66. direction = DMA_BIDIRECTIONAL;
  67. break;
  68. default:
  69. direction = DMA_NONE;
  70. break;
  71. }
  72. if (!dma->sg) {
  73. /*
  74. * Cope with ISA-style drivers which expect cache
  75. * coherence.
  76. */
  77. dma->sg = &dma->buf;
  78. dma->sgcount = 1;
  79. dma->buf.length = dma->count;
  80. dma->buf.dma_address = dma_map_single(NULL,
  81. dma->addr, dma->count,
  82. direction);
  83. }
  84. address = dma->buf.dma_address;
  85. length = dma->buf.length - 1;
  86. outb(address >> 16, isa_dma_port[chan][ISA_DMA_PGLO]);
  87. outb(address >> 24, isa_dma_port[chan][ISA_DMA_PGHI]);
  88. if (chan >= 4) {
  89. address >>= 1;
  90. length >>= 1;
  91. }
  92. outb(0, isa_dma_port[chan][ISA_DMA_CLRFF]);
  93. outb(address, isa_dma_port[chan][ISA_DMA_ADDR]);
  94. outb(address >> 8, isa_dma_port[chan][ISA_DMA_ADDR]);
  95. outb(length, isa_dma_port[chan][ISA_DMA_COUNT]);
  96. outb(length >> 8, isa_dma_port[chan][ISA_DMA_COUNT]);
  97. outb(mode, isa_dma_port[chan][ISA_DMA_MODE]);
  98. dma->invalid = 0;
  99. }
  100. outb(chan & 3, isa_dma_port[chan][ISA_DMA_MASK]);
  101. }
  102. static void isa_disable_dma(unsigned int chan, dma_t *dma)
  103. {
  104. outb(chan | 4, isa_dma_port[chan][ISA_DMA_MASK]);
  105. }
  106. static struct dma_ops isa_dma_ops = {
  107. .type = "ISA",
  108. .enable = isa_enable_dma,
  109. .disable = isa_disable_dma,
  110. .residue = isa_get_dma_residue,
  111. };
  112. static struct resource dma_resources[] = { {
  113. .name = "dma1",
  114. .start = 0x0000,
  115. .end = 0x000f
  116. }, {
  117. .name = "dma low page",
  118. .start = 0x0080,
  119. .end = 0x008f
  120. }, {
  121. .name = "dma2",
  122. .start = 0x00c0,
  123. .end = 0x00df
  124. }, {
  125. .name = "dma high page",
  126. .start = 0x0480,
  127. .end = 0x048f
  128. } };
  129. static dma_t isa_dma[8];
  130. /*
  131. * ISA DMA always starts at channel 0
  132. */
  133. void __init isa_init_dma(void)
  134. {
  135. /*
  136. * Try to autodetect presence of an ISA DMA controller.
  137. * We do some minimal initialisation, and check that
  138. * channel 0's DMA address registers are writeable.
  139. */
  140. outb(0xff, 0x0d);
  141. outb(0xff, 0xda);
  142. /*
  143. * Write high and low address, and then read them back
  144. * in the same order.
  145. */
  146. outb(0x55, 0x00);
  147. outb(0xaa, 0x00);
  148. if (inb(0) == 0x55 && inb(0) == 0xaa) {
  149. unsigned int chan, i;
  150. for (chan = 0; chan < 8; chan++) {
  151. isa_dma[chan].d_ops = &isa_dma_ops;
  152. isa_disable_dma(chan, NULL);
  153. }
  154. outb(0x40, 0x0b);
  155. outb(0x41, 0x0b);
  156. outb(0x42, 0x0b);
  157. outb(0x43, 0x0b);
  158. outb(0xc0, 0xd6);
  159. outb(0x41, 0xd6);
  160. outb(0x42, 0xd6);
  161. outb(0x43, 0xd6);
  162. outb(0, 0xd4);
  163. outb(0x10, 0x08);
  164. outb(0x10, 0xd0);
  165. /*
  166. * Is this correct? According to my documentation, it
  167. * doesn't appear to be. It should be:
  168. * outb(0x3f, 0x40b); outb(0x3f, 0x4d6);
  169. */
  170. outb(0x30, 0x40b);
  171. outb(0x31, 0x40b);
  172. outb(0x32, 0x40b);
  173. outb(0x33, 0x40b);
  174. outb(0x31, 0x4d6);
  175. outb(0x32, 0x4d6);
  176. outb(0x33, 0x4d6);
  177. for (i = 0; i < ARRAY_SIZE(dma_resources); i++)
  178. request_resource(&ioport_resource, dma_resources + i);
  179. for (chan = 0; chan < 8; chan++) {
  180. int ret = isa_dma_add(chan, &isa_dma[chan]);
  181. if (ret)
  182. pr_err("ISADMA%u: unable to register: %d\n",
  183. chan, ret);
  184. }
  185. request_dma(DMA_ISA_CASCADE, "cascade");
  186. }
  187. }