io.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * include/asm-sh/io_bigsur.c
  3. *
  4. * By Dustin McIntire (dustin@sensoria.com) (c)2001
  5. * Derived from io_hd64465.h, which bore the message:
  6. * By Greg Banks <gbanks@pocketpenguins.com>
  7. * (c) 2000 PocketPenguins Inc.
  8. * and from io_hd64461.h, which bore the message:
  9. * Copyright 2000 Stuart Menefy (stuart.menefy@st.com)
  10. *
  11. * May be copied or modified under the terms of the GNU General Public
  12. * License. See linux/COPYING for more information.
  13. *
  14. * IO functions for a Hitachi Big Sur Evaluation Board.
  15. */
  16. #include <linux/config.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <asm/machvec.h>
  20. #include <asm/io.h>
  21. #include <asm/bigsur/bigsur.h>
  22. /* Low iomap maps port 0-1K to addresses in 8byte chunks */
  23. #define BIGSUR_IOMAP_LO_THRESH 0x400
  24. #define BIGSUR_IOMAP_LO_SHIFT 3
  25. #define BIGSUR_IOMAP_LO_MASK ((1<<BIGSUR_IOMAP_LO_SHIFT)-1)
  26. #define BIGSUR_IOMAP_LO_NMAP (BIGSUR_IOMAP_LO_THRESH>>BIGSUR_IOMAP_LO_SHIFT)
  27. static u32 bigsur_iomap_lo[BIGSUR_IOMAP_LO_NMAP];
  28. static u8 bigsur_iomap_lo_shift[BIGSUR_IOMAP_LO_NMAP];
  29. /* High iomap maps port 1K-64K to addresses in 1K chunks */
  30. #define BIGSUR_IOMAP_HI_THRESH 0x10000
  31. #define BIGSUR_IOMAP_HI_SHIFT 10
  32. #define BIGSUR_IOMAP_HI_MASK ((1<<BIGSUR_IOMAP_HI_SHIFT)-1)
  33. #define BIGSUR_IOMAP_HI_NMAP (BIGSUR_IOMAP_HI_THRESH>>BIGSUR_IOMAP_HI_SHIFT)
  34. static u32 bigsur_iomap_hi[BIGSUR_IOMAP_HI_NMAP];
  35. static u8 bigsur_iomap_hi_shift[BIGSUR_IOMAP_HI_NMAP];
  36. #ifndef MAX
  37. #define MAX(a,b) ((a)>(b)?(a):(b))
  38. #endif
  39. void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift)
  40. {
  41. u32 port, endport = baseport + nports;
  42. pr_debug("bigsur_port_map(base=0x%0x, n=0x%0x, addr=0x%08x)\n",
  43. baseport, nports, addr);
  44. for (port = baseport ;
  45. port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
  46. port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
  47. pr_debug(" maplo[0x%x] = 0x%08x\n", port, addr);
  48. bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = addr;
  49. bigsur_iomap_lo_shift[port>>BIGSUR_IOMAP_LO_SHIFT] = shift;
  50. addr += (1<<(BIGSUR_IOMAP_LO_SHIFT));
  51. }
  52. for (port = MAX(baseport, BIGSUR_IOMAP_LO_THRESH) ;
  53. port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
  54. port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
  55. pr_debug(" maphi[0x%x] = 0x%08x\n", port, addr);
  56. bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = addr;
  57. bigsur_iomap_hi_shift[port>>BIGSUR_IOMAP_HI_SHIFT] = shift;
  58. addr += (1<<(BIGSUR_IOMAP_HI_SHIFT));
  59. }
  60. }
  61. EXPORT_SYMBOL(bigsur_port_map);
  62. void bigsur_port_unmap(u32 baseport, u32 nports)
  63. {
  64. u32 port, endport = baseport + nports;
  65. pr_debug("bigsur_port_unmap(base=0x%0x, n=0x%0x)\n", baseport, nports);
  66. for (port = baseport ;
  67. port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
  68. port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
  69. bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = 0;
  70. }
  71. for (port = MAX(baseport, BIGSUR_IOMAP_LO_THRESH) ;
  72. port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
  73. port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
  74. bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = 0;
  75. }
  76. }
  77. EXPORT_SYMBOL(bigsur_port_unmap);
  78. unsigned long bigsur_isa_port2addr(unsigned long port)
  79. {
  80. unsigned long addr = 0;
  81. unsigned char shift;
  82. /* Physical address not in P0, do nothing */
  83. if (PXSEG(port)) {
  84. addr = port;
  85. /* physical address in P0, map to P2 */
  86. } else if (port >= 0x30000) {
  87. addr = P2SEGADDR(port);
  88. /* Big Sur I/O + HD64465 registers 0x10000-0x30000 */
  89. } else if (port >= BIGSUR_IOMAP_HI_THRESH) {
  90. addr = BIGSUR_INTERNAL_BASE + (port - BIGSUR_IOMAP_HI_THRESH);
  91. /* Handle remapping of high IO/PCI IO ports */
  92. } else if (port >= BIGSUR_IOMAP_LO_THRESH) {
  93. addr = bigsur_iomap_hi[port >> BIGSUR_IOMAP_HI_SHIFT];
  94. shift = bigsur_iomap_hi_shift[port >> BIGSUR_IOMAP_HI_SHIFT];
  95. if (addr != 0)
  96. addr += (port & BIGSUR_IOMAP_HI_MASK) << shift;
  97. } else {
  98. /* Handle remapping of low IO ports */
  99. addr = bigsur_iomap_lo[port >> BIGSUR_IOMAP_LO_SHIFT];
  100. shift = bigsur_iomap_lo_shift[port >> BIGSUR_IOMAP_LO_SHIFT];
  101. if (addr != 0)
  102. addr += (port & BIGSUR_IOMAP_LO_MASK) << shift;
  103. }
  104. pr_debug("%s(0x%08lx) = 0x%08lx\n", __FUNCTION__, port, addr);
  105. return addr;
  106. }