io.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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(const volatile 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(const volatile 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(const volatile 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(const volatile 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 readsw(const void __iomem *addr, void *data, int len)
  90. {
  91. void __iomem *a = __isamem_convert_addr(addr);
  92. BUG_ON((unsigned long)addr & 1);
  93. __raw_readsw(a, data, len);
  94. }
  95. EXPORT_SYMBOL(readsw);
  96. void readsl(const void __iomem *addr, void *data, int len)
  97. {
  98. void __iomem *a = __isamem_convert_addr(addr);
  99. BUG_ON((unsigned long)addr & 3);
  100. __raw_readsl(a, data, len);
  101. }
  102. EXPORT_SYMBOL(readsl);
  103. void __writeb(u8 val, void __iomem *addr)
  104. {
  105. void __iomem *a = __isamem_convert_addr(addr);
  106. if ((unsigned long)addr & 1)
  107. __raw_writel(val, a);
  108. else
  109. __raw_writeb(val, a);
  110. }
  111. void __writew(u16 val, void __iomem *addr)
  112. {
  113. void __iomem *a = __isamem_convert_addr(addr);
  114. if ((unsigned long)addr & 1)
  115. BUG();
  116. __raw_writew(val, a);
  117. }
  118. void __writel(u32 val, void __iomem *addr)
  119. {
  120. void __iomem *a = __isamem_convert_addr(addr);
  121. if ((unsigned long)addr & 3)
  122. BUG();
  123. __raw_writew(val, a);
  124. __raw_writew(val >> 16, a + 4);
  125. }
  126. EXPORT_SYMBOL(__writeb);
  127. EXPORT_SYMBOL(__writew);
  128. EXPORT_SYMBOL(__writel);
  129. void writesw(void __iomem *addr, const void *data, int len)
  130. {
  131. void __iomem *a = __isamem_convert_addr(addr);
  132. BUG_ON((unsigned long)addr & 1);
  133. __raw_writesw(a, data, len);
  134. }
  135. EXPORT_SYMBOL(writesw);
  136. void writesl(void __iomem *addr, const void *data, int len)
  137. {
  138. void __iomem *a = __isamem_convert_addr(addr);
  139. BUG_ON((unsigned long)addr & 3);
  140. __raw_writesl(a, data, len);
  141. }
  142. EXPORT_SYMBOL(writesl);
  143. #define SUPERIO_PORT(p) \
  144. (((p) >> 3) == (0x3f8 >> 3) || \
  145. ((p) >> 3) == (0x2f8 >> 3) || \
  146. ((p) >> 3) == (0x378 >> 3))
  147. /*
  148. * We're addressing an 8 or 16-bit peripheral which tranfers
  149. * odd addresses on the low ISA byte lane.
  150. */
  151. u8 __inb8(unsigned int port)
  152. {
  153. u32 ret;
  154. /*
  155. * The SuperIO registers use sane addressing techniques...
  156. */
  157. if (SUPERIO_PORT(port))
  158. ret = __raw_readb((void __iomem *)ISAIO_BASE + (port << 2));
  159. else {
  160. void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  161. /*
  162. * Shame nothing else does
  163. */
  164. if (port & 1)
  165. ret = __raw_readl(a);
  166. else
  167. ret = __raw_readb(a);
  168. }
  169. return ret;
  170. }
  171. /*
  172. * We're addressing a 16-bit peripheral which transfers odd
  173. * addresses on the high ISA byte lane.
  174. */
  175. u8 __inb16(unsigned int port)
  176. {
  177. unsigned int offset;
  178. /*
  179. * The SuperIO registers use sane addressing techniques...
  180. */
  181. if (SUPERIO_PORT(port))
  182. offset = port << 2;
  183. else
  184. offset = (port & ~1) << 1 | (port & 1);
  185. return __raw_readb((void __iomem *)ISAIO_BASE + offset);
  186. }
  187. u16 __inw(unsigned int port)
  188. {
  189. unsigned int offset;
  190. /*
  191. * The SuperIO registers use sane addressing techniques...
  192. */
  193. if (SUPERIO_PORT(port))
  194. offset = port << 2;
  195. else {
  196. offset = port << 1;
  197. BUG_ON(port & 1);
  198. }
  199. return __raw_readw((void __iomem *)ISAIO_BASE + offset);
  200. }
  201. /*
  202. * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
  203. */
  204. u32 __inl(unsigned int port)
  205. {
  206. void __iomem *a;
  207. if (SUPERIO_PORT(port) || port & 3)
  208. BUG();
  209. a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  210. return __raw_readw(a) | __raw_readw(a + 4) << 16;
  211. }
  212. EXPORT_SYMBOL(__inb8);
  213. EXPORT_SYMBOL(__inb16);
  214. EXPORT_SYMBOL(__inw);
  215. EXPORT_SYMBOL(__inl);
  216. void __outb8(u8 val, unsigned int port)
  217. {
  218. /*
  219. * The SuperIO registers use sane addressing techniques...
  220. */
  221. if (SUPERIO_PORT(port))
  222. __raw_writeb(val, (void __iomem *)ISAIO_BASE + (port << 2));
  223. else {
  224. void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  225. /*
  226. * Shame nothing else does
  227. */
  228. if (port & 1)
  229. __raw_writel(val, a);
  230. else
  231. __raw_writeb(val, a);
  232. }
  233. }
  234. void __outb16(u8 val, unsigned int port)
  235. {
  236. unsigned int offset;
  237. /*
  238. * The SuperIO registers use sane addressing techniques...
  239. */
  240. if (SUPERIO_PORT(port))
  241. offset = port << 2;
  242. else
  243. offset = (port & ~1) << 1 | (port & 1);
  244. __raw_writeb(val, (void __iomem *)ISAIO_BASE + offset);
  245. }
  246. void __outw(u16 val, unsigned int port)
  247. {
  248. unsigned int offset;
  249. /*
  250. * The SuperIO registers use sane addressing techniques...
  251. */
  252. if (SUPERIO_PORT(port))
  253. offset = port << 2;
  254. else {
  255. offset = port << 1;
  256. BUG_ON(port & 1);
  257. }
  258. __raw_writew(val, (void __iomem *)ISAIO_BASE + offset);
  259. }
  260. void __outl(u32 val, unsigned int port)
  261. {
  262. BUG();
  263. }
  264. EXPORT_SYMBOL(__outb8);
  265. EXPORT_SYMBOL(__outb16);
  266. EXPORT_SYMBOL(__outw);
  267. EXPORT_SYMBOL(__outl);
  268. void outsb(unsigned int port, const void *from, int len)
  269. {
  270. u32 off;
  271. if (SUPERIO_PORT(port))
  272. off = port << 2;
  273. else {
  274. off = (port & ~1) << 1;
  275. if (port & 1)
  276. BUG();
  277. }
  278. __raw_writesb((void __iomem *)ISAIO_BASE + off, from, len);
  279. }
  280. void insb(unsigned int port, void *from, int len)
  281. {
  282. u32 off;
  283. if (SUPERIO_PORT(port))
  284. off = port << 2;
  285. else {
  286. off = (port & ~1) << 1;
  287. if (port & 1)
  288. BUG();
  289. }
  290. __raw_readsb((void __iomem *)ISAIO_BASE + off, from, len);
  291. }
  292. EXPORT_SYMBOL(outsb);
  293. EXPORT_SYMBOL(insb);
  294. void outsw(unsigned int port, const void *from, int len)
  295. {
  296. u32 off;
  297. if (SUPERIO_PORT(port))
  298. off = port << 2;
  299. else {
  300. off = (port & ~1) << 1;
  301. if (port & 1)
  302. BUG();
  303. }
  304. __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len);
  305. }
  306. void insw(unsigned int port, void *from, int len)
  307. {
  308. u32 off;
  309. if (SUPERIO_PORT(port))
  310. off = port << 2;
  311. else {
  312. off = (port & ~1) << 1;
  313. if (port & 1)
  314. BUG();
  315. }
  316. __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len);
  317. }
  318. EXPORT_SYMBOL(outsw);
  319. EXPORT_SYMBOL(insw);
  320. /*
  321. * We implement these as 16-bit insw/outsw, mainly for
  322. * 3c589 cards.
  323. */
  324. void outsl(unsigned int port, const void *from, int len)
  325. {
  326. u32 off = port << 1;
  327. if (SUPERIO_PORT(port) || port & 3)
  328. BUG();
  329. __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len << 1);
  330. }
  331. void insl(unsigned int port, void *from, int len)
  332. {
  333. u32 off = port << 1;
  334. if (SUPERIO_PORT(port) || port & 3)
  335. BUG();
  336. __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len << 1);
  337. }
  338. EXPORT_SYMBOL(outsl);
  339. EXPORT_SYMBOL(insl);