io.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 <linux/io.h>
  27. #include <mach/hardware.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 volatile 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 volatile 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, volatile 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, volatile 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, volatile 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(volatile 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(volatile 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. /*
  144. * The EBSA110 has a weird "ISA IO" region:
  145. *
  146. * Region 0 (addr = 0xf0000000 + io << 2)
  147. * --------------------------------------------------------
  148. * Physical region IO region
  149. * f0000fe0 - f0000ffc 3f8 - 3ff ttyS0
  150. * f0000e60 - f0000e64 398 - 399
  151. * f0000de0 - f0000dfc 378 - 37f lp0
  152. * f0000be0 - f0000bfc 2f8 - 2ff ttyS1
  153. *
  154. * Region 1 (addr = 0xf0000000 + (io & ~1) << 1 + (io & 1))
  155. * --------------------------------------------------------
  156. * Physical region IO region
  157. * f00014f1 a79 pnp write data
  158. * f00007c0 - f00007c1 3e0 - 3e1 pcmcia
  159. * f00004f1 279 pnp address
  160. * f0000440 - f000046c 220 - 236 eth0
  161. * f0000405 203 pnp read data
  162. */
  163. #define SUPERIO_PORT(p) \
  164. (((p) >> 3) == (0x3f8 >> 3) || \
  165. ((p) >> 3) == (0x2f8 >> 3) || \
  166. ((p) >> 3) == (0x378 >> 3))
  167. /*
  168. * We're addressing an 8 or 16-bit peripheral which tranfers
  169. * odd addresses on the low ISA byte lane.
  170. */
  171. u8 __inb8(unsigned int port)
  172. {
  173. u32 ret;
  174. /*
  175. * The SuperIO registers use sane addressing techniques...
  176. */
  177. if (SUPERIO_PORT(port))
  178. ret = __raw_readb((void __iomem *)ISAIO_BASE + (port << 2));
  179. else {
  180. void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  181. /*
  182. * Shame nothing else does
  183. */
  184. if (port & 1)
  185. ret = __raw_readl(a);
  186. else
  187. ret = __raw_readb(a);
  188. }
  189. return ret;
  190. }
  191. /*
  192. * We're addressing a 16-bit peripheral which transfers odd
  193. * addresses on the high ISA byte lane.
  194. */
  195. u8 __inb16(unsigned int port)
  196. {
  197. unsigned int offset;
  198. /*
  199. * The SuperIO registers use sane addressing techniques...
  200. */
  201. if (SUPERIO_PORT(port))
  202. offset = port << 2;
  203. else
  204. offset = (port & ~1) << 1 | (port & 1);
  205. return __raw_readb((void __iomem *)ISAIO_BASE + offset);
  206. }
  207. u16 __inw(unsigned int port)
  208. {
  209. unsigned int offset;
  210. /*
  211. * The SuperIO registers use sane addressing techniques...
  212. */
  213. if (SUPERIO_PORT(port))
  214. offset = port << 2;
  215. else {
  216. offset = port << 1;
  217. BUG_ON(port & 1);
  218. }
  219. return __raw_readw((void __iomem *)ISAIO_BASE + offset);
  220. }
  221. /*
  222. * Fake a 32-bit read with two 16-bit reads. Needed for 3c589.
  223. */
  224. u32 __inl(unsigned int port)
  225. {
  226. void __iomem *a;
  227. if (SUPERIO_PORT(port) || port & 3)
  228. BUG();
  229. a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  230. return __raw_readw(a) | __raw_readw(a + 4) << 16;
  231. }
  232. EXPORT_SYMBOL(__inb8);
  233. EXPORT_SYMBOL(__inb16);
  234. EXPORT_SYMBOL(__inw);
  235. EXPORT_SYMBOL(__inl);
  236. void __outb8(u8 val, unsigned int port)
  237. {
  238. /*
  239. * The SuperIO registers use sane addressing techniques...
  240. */
  241. if (SUPERIO_PORT(port))
  242. __raw_writeb(val, (void __iomem *)ISAIO_BASE + (port << 2));
  243. else {
  244. void __iomem *a = (void __iomem *)ISAIO_BASE + ((port & ~1) << 1);
  245. /*
  246. * Shame nothing else does
  247. */
  248. if (port & 1)
  249. __raw_writel(val, a);
  250. else
  251. __raw_writeb(val, a);
  252. }
  253. }
  254. void __outb16(u8 val, unsigned int port)
  255. {
  256. unsigned int offset;
  257. /*
  258. * The SuperIO registers use sane addressing techniques...
  259. */
  260. if (SUPERIO_PORT(port))
  261. offset = port << 2;
  262. else
  263. offset = (port & ~1) << 1 | (port & 1);
  264. __raw_writeb(val, (void __iomem *)ISAIO_BASE + offset);
  265. }
  266. void __outw(u16 val, unsigned int port)
  267. {
  268. unsigned int offset;
  269. /*
  270. * The SuperIO registers use sane addressing techniques...
  271. */
  272. if (SUPERIO_PORT(port))
  273. offset = port << 2;
  274. else {
  275. offset = port << 1;
  276. BUG_ON(port & 1);
  277. }
  278. __raw_writew(val, (void __iomem *)ISAIO_BASE + offset);
  279. }
  280. void __outl(u32 val, unsigned int port)
  281. {
  282. BUG();
  283. }
  284. EXPORT_SYMBOL(__outb8);
  285. EXPORT_SYMBOL(__outb16);
  286. EXPORT_SYMBOL(__outw);
  287. EXPORT_SYMBOL(__outl);
  288. void outsb(unsigned int port, const void *from, int len)
  289. {
  290. u32 off;
  291. if (SUPERIO_PORT(port))
  292. off = port << 2;
  293. else {
  294. off = (port & ~1) << 1;
  295. if (port & 1)
  296. BUG();
  297. }
  298. __raw_writesb((void __iomem *)ISAIO_BASE + off, from, len);
  299. }
  300. void insb(unsigned int port, void *from, int len)
  301. {
  302. u32 off;
  303. if (SUPERIO_PORT(port))
  304. off = port << 2;
  305. else {
  306. off = (port & ~1) << 1;
  307. if (port & 1)
  308. BUG();
  309. }
  310. __raw_readsb((void __iomem *)ISAIO_BASE + off, from, len);
  311. }
  312. EXPORT_SYMBOL(outsb);
  313. EXPORT_SYMBOL(insb);
  314. void outsw(unsigned int port, const void *from, int len)
  315. {
  316. u32 off;
  317. if (SUPERIO_PORT(port))
  318. off = port << 2;
  319. else {
  320. off = (port & ~1) << 1;
  321. if (port & 1)
  322. BUG();
  323. }
  324. __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len);
  325. }
  326. void insw(unsigned int port, void *from, int len)
  327. {
  328. u32 off;
  329. if (SUPERIO_PORT(port))
  330. off = port << 2;
  331. else {
  332. off = (port & ~1) << 1;
  333. if (port & 1)
  334. BUG();
  335. }
  336. __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len);
  337. }
  338. EXPORT_SYMBOL(outsw);
  339. EXPORT_SYMBOL(insw);
  340. /*
  341. * We implement these as 16-bit insw/outsw, mainly for
  342. * 3c589 cards.
  343. */
  344. void outsl(unsigned int port, const void *from, int len)
  345. {
  346. u32 off = port << 1;
  347. if (SUPERIO_PORT(port) || port & 3)
  348. BUG();
  349. __raw_writesw((void __iomem *)ISAIO_BASE + off, from, len << 1);
  350. }
  351. void insl(unsigned int port, void *from, int len)
  352. {
  353. u32 off = port << 1;
  354. if (SUPERIO_PORT(port) || port & 3)
  355. BUG();
  356. __raw_readsw((void __iomem *)ISAIO_BASE + off, from, len << 1);
  357. }
  358. EXPORT_SYMBOL(outsl);
  359. EXPORT_SYMBOL(insl);