io.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * linux/arch/arm/mach-ebsa110/isamem.c
  3. *
  4. * Copyright (C) 2001 Russell King
  5. *
  6. * Perform "ISA" memory and IO accesses. The EBSA110 has some "peculiarities"
  7. * in the way it handles accesses to odd IO ports on 16-bit devices. These
  8. * devices have their D0-D15 lines connected to the processors D0-D15 lines.
  9. * Since they expect all byte IO operations to be performed on D0-D7, and the
  10. * StrongARM expects to transfer the byte to these odd addresses on D8-D15,
  11. * we must use a trick to get the required behaviour.
  12. *
  13. * The trick employed here is to use long word stores to odd address -1. The
  14. * glue logic picks this up as a "trick" access, and asserts the LSB of the
  15. * peripherals address bus, thereby accessing the odd IO port. Meanwhile, the
  16. * StrongARM transfers its data on D0-D7 as expected.
  17. *
  18. * Things get more interesting on the pass-1 EBSA110 - the PCMCIA controller
  19. * wiring was screwed in such a way that it had limited memory space access.
  20. * Luckily, the work-around for this is not too horrible. See
  21. * __isamem_convert_addr for the details.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/types.h>
  26. #include <asm/hardware.h>
  27. #include <asm/io.h>
  28. #include <asm/page.h>
  29. static void __iomem *__isamem_convert_addr(void __iomem *addr)
  30. {
  31. u32 ret, a = (u32 __force) addr;
  32. /*
  33. * The PCMCIA controller is wired up as follows:
  34. * +---------+---------+---------+---------+---------+---------+
  35. * PCMCIA | 2 2 2 2 | 1 1 1 1 | 1 1 1 1 | 1 1 | | |
  36. * | 3 2 1 0 | 9 8 7 6 | 5 4 3 2 | 1 0 9 8 | 7 6 5 4 | 3 2 1 0 |
  37. * +---------+---------+---------+---------+---------+---------+
  38. * CPU | 2 2 2 2 | 2 1 1 1 | 1 1 1 1 | 1 1 1 | | |
  39. * | 4 3 2 1 | 0 9 9 8 | 7 6 5 4 | 3 2 0 9 | 8 7 6 5 | 4 3 2 x |
  40. * +---------+---------+---------+---------+---------+---------+
  41. *
  42. * This means that we can access PCMCIA regions as follows:
  43. * 0x*10000 -> 0x*1ffff
  44. * 0x*70000 -> 0x*7ffff
  45. * 0x*90000 -> 0x*9ffff
  46. * 0x*f0000 -> 0x*fffff
  47. */
  48. ret = (a & 0xf803fe) << 1;
  49. ret |= (a & 0x03fc00) << 2;
  50. ret += 0xe8000000;
  51. if ((a & 0x20000) == (a & 0x40000) >> 1)
  52. return (void __iomem *)ret;
  53. BUG();
  54. return NULL;
  55. }
  56. /*
  57. * read[bwl] and write[bwl]
  58. */
  59. u8 __readb(void __iomem *addr)
  60. {
  61. void __iomem *a = __isamem_convert_addr(addr);
  62. u32 ret;
  63. if ((unsigned long)addr & 1)
  64. ret = __raw_readl(a);
  65. else
  66. ret = __raw_readb(a);
  67. return ret;
  68. }
  69. u16 __readw(void __iomem *addr)
  70. {
  71. void __iomem *a = __isamem_convert_addr(addr);
  72. if ((unsigned long)addr & 1)
  73. BUG();
  74. return __raw_readw(a);
  75. }
  76. u32 __readl(void __iomem *addr)
  77. {
  78. void __iomem *a = __isamem_convert_addr(addr);
  79. u32 ret;
  80. if ((unsigned long)addr & 3)
  81. BUG();
  82. ret = __raw_readw(a);
  83. ret |= __raw_readw(a + 4) << 16;
  84. return ret;
  85. }
  86. EXPORT_SYMBOL(__readb);
  87. EXPORT_SYMBOL(__readw);
  88. EXPORT_SYMBOL(__readl);
  89. void __writeb(u8 val, void __iomem *addr)
  90. {
  91. void __iomem *a = __isamem_convert_addr(addr);
  92. if ((unsigned long)addr & 1)
  93. __raw_writel(val, a);
  94. else
  95. __raw_writeb(val, a);
  96. }
  97. void __writew(u16 val, void __iomem *addr)
  98. {
  99. void __iomem *a = __isamem_convert_addr(addr);
  100. if ((unsigned long)addr & 1)
  101. BUG();
  102. __raw_writew(val, a);
  103. }
  104. void __writel(u32 val, void __iomem *addr)
  105. {
  106. void __iomem *a = __isamem_convert_addr(addr);
  107. if ((unsigned long)addr & 3)
  108. BUG();
  109. __raw_writew(val, a);
  110. __raw_writew(val >> 16, a + 4);
  111. }
  112. EXPORT_SYMBOL(__writeb);
  113. EXPORT_SYMBOL(__writew);
  114. EXPORT_SYMBOL(__writel);
  115. #define SUPERIO_PORT(p) \
  116. (((p) >> 3) == (0x3f8 >> 3) || \
  117. ((p) >> 3) == (0x2f8 >> 3) || \
  118. ((p) >> 3) == (0x378 >> 3))
  119. /*
  120. * We're addressing an 8 or 16-bit peripheral which tranfers
  121. * odd addresses on the low ISA byte lane.
  122. */
  123. u8 __inb8(unsigned int port)
  124. {
  125. u32 ret;
  126. /*
  127. * The SuperIO registers use sane addressing techniques...
  128. */
  129. if (SUPERIO_PORT(port))
  130. ret = __raw_readb((void __iomem *)ISAIO_BASE + (port << 2));
  131. else {
  132. void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  133. /*
  134. * Shame nothing else does
  135. */
  136. if (port & 1)
  137. ret = __raw_readl(a);
  138. else
  139. ret = __raw_readb(a);
  140. }
  141. return ret;
  142. }
  143. /*
  144. * We're addressing a 16-bit peripheral which transfers odd
  145. * addresses on the high ISA byte lane.
  146. */
  147. u8 __inb16(unsigned int port)
  148. {
  149. unsigned int offset;
  150. /*
  151. * The SuperIO registers use sane addressing techniques...
  152. */
  153. if (SUPERIO_PORT(port))
  154. offset = port << 2;
  155. else
  156. offset = (port & ~1) << 1 | (port & 1);
  157. return __raw_readb((void __iomem *)ISAIO_BASE + offset);
  158. }
  159. u16 __inw(unsigned int port)
  160. {
  161. unsigned int offset;
  162. /*
  163. * The SuperIO registers use sane addressing techniques...
  164. */
  165. if (SUPERIO_PORT(port))
  166. offset = port << 2;
  167. else {
  168. offset = port << 1;
  169. BUG_ON(port & 1);
  170. }
  171. return __raw_readw((void __iomem *)ISAIO_BASE + offset);
  172. }
  173. /*
  174. * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
  175. */
  176. u32 __inl(unsigned int port)
  177. {
  178. void __iomem *a;
  179. if (SUPERIO_PORT(port) || port & 3)
  180. BUG();
  181. a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  182. return __raw_readw(a) | __raw_readw(a + 4) << 16;
  183. }
  184. EXPORT_SYMBOL(__inb8);
  185. EXPORT_SYMBOL(__inb16);
  186. EXPORT_SYMBOL(__inw);
  187. EXPORT_SYMBOL(__inl);
  188. void __outb8(u8 val, unsigned int port)
  189. {
  190. /*
  191. * The SuperIO registers use sane addressing techniques...
  192. */
  193. if (SUPERIO_PORT(port))
  194. __raw_writeb(val, (void __iomem *)ISAIO_BASE + (port << 2));
  195. else {
  196. void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  197. /*
  198. * Shame nothing else does
  199. */
  200. if (port & 1)
  201. __raw_writel(val, a);
  202. else
  203. __raw_writeb(val, a);
  204. }
  205. }
  206. void __outb16(u8 val, unsigned int port)
  207. {
  208. unsigned int offset;
  209. /*
  210. * The SuperIO registers use sane addressing techniques...
  211. */
  212. if (SUPERIO_PORT(port))
  213. offset = port << 2;
  214. else
  215. offset = (port & ~1) << 1 | (port & 1);
  216. __raw_writeb(val, (void __iomem *)ISAIO_BASE + offset);
  217. }
  218. void __outw(u16 val, unsigned int port)
  219. {
  220. unsigned int offset;
  221. /*
  222. * The SuperIO registers use sane addressing techniques...
  223. */
  224. if (SUPERIO_PORT(port))
  225. offset = port << 2;
  226. else {
  227. offset = port << 1;
  228. BUG_ON(port & 1);
  229. }
  230. __raw_writew(val, (void __iomem *)ISAIO_BASE + offset);
  231. }
  232. void __outl(u32 val, unsigned int port)
  233. {
  234. BUG();
  235. }
  236. EXPORT_SYMBOL(__outb8);
  237. EXPORT_SYMBOL(__outb16);
  238. EXPORT_SYMBOL(__outw);
  239. EXPORT_SYMBOL(__outl);
  240. void outsb(unsigned int port, const void *from, int len)
  241. {
  242. u32 off;
  243. if (SUPERIO_PORT(port))
  244. off = port << 2;
  245. else {
  246. off = (port & ~1) << 1;
  247. if (port & 1)
  248. BUG();
  249. }
  250. __raw_writesb((void __iomem *)ISAIO_BASE + off, from, len);
  251. }
  252. void insb(unsigned int port, void *from, int len)
  253. {
  254. u32 off;
  255. if (SUPERIO_PORT(port))
  256. off = port << 2;
  257. else {
  258. off = (port & ~1) << 1;
  259. if (port & 1)
  260. BUG();
  261. }
  262. __raw_readsb((void __iomem *)ISAIO_BASE + off, from, len);
  263. }
  264. EXPORT_SYMBOL(outsb);
  265. EXPORT_SYMBOL(insb);
  266. void outsw(unsigned int port, const void *from, int len)
  267. {
  268. u32 off;
  269. if (SUPERIO_PORT(port))
  270. off = port << 2;
  271. else {
  272. off = (port & ~1) << 1;
  273. if (port & 1)
  274. BUG();
  275. }
  276. __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len);
  277. }
  278. void insw(unsigned int port, void *from, int len)
  279. {
  280. u32 off;
  281. if (SUPERIO_PORT(port))
  282. off = port << 2;
  283. else {
  284. off = (port & ~1) << 1;
  285. if (port & 1)
  286. BUG();
  287. }
  288. __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len);
  289. }
  290. EXPORT_SYMBOL(outsw);
  291. EXPORT_SYMBOL(insw);
  292. /*
  293. * We implement these as 16-bit insw/outsw, mainly for
  294. * 3c589 cards.
  295. */
  296. void outsl(unsigned int port, const void *from, int len)
  297. {
  298. u32 off = port << 1;
  299. if (SUPERIO_PORT(port) || port & 3)
  300. BUG();
  301. __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len << 1);
  302. }
  303. void insl(unsigned int port, void *from, int len)
  304. {
  305. u32 off = port << 1;
  306. if (SUPERIO_PORT(port) || port & 3)
  307. BUG();
  308. __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len << 1);
  309. }
  310. EXPORT_SYMBOL(outsl);
  311. EXPORT_SYMBOL(insl);