io.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * arch/sh/boards/bigsur/io.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/kernel.h>
  17. #include <linux/module.h>
  18. #include <asm/machvec.h>
  19. #include <asm/io.h>
  20. #include <asm/bigsur/bigsur.h>
  21. /* Low iomap maps port 0-1K to addresses in 8byte chunks */
  22. #define BIGSUR_IOMAP_LO_THRESH 0x400
  23. #define BIGSUR_IOMAP_LO_SHIFT 3
  24. #define BIGSUR_IOMAP_LO_MASK ((1<<BIGSUR_IOMAP_LO_SHIFT)-1)
  25. #define BIGSUR_IOMAP_LO_NMAP (BIGSUR_IOMAP_LO_THRESH>>BIGSUR_IOMAP_LO_SHIFT)
  26. static u32 bigsur_iomap_lo[BIGSUR_IOMAP_LO_NMAP];
  27. static u8 bigsur_iomap_lo_shift[BIGSUR_IOMAP_LO_NMAP];
  28. /* High iomap maps port 1K-64K to addresses in 1K chunks */
  29. #define BIGSUR_IOMAP_HI_THRESH 0x10000
  30. #define BIGSUR_IOMAP_HI_SHIFT 10
  31. #define BIGSUR_IOMAP_HI_MASK ((1<<BIGSUR_IOMAP_HI_SHIFT)-1)
  32. #define BIGSUR_IOMAP_HI_NMAP (BIGSUR_IOMAP_HI_THRESH>>BIGSUR_IOMAP_HI_SHIFT)
  33. static u32 bigsur_iomap_hi[BIGSUR_IOMAP_HI_NMAP];
  34. static u8 bigsur_iomap_hi_shift[BIGSUR_IOMAP_HI_NMAP];
  35. void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift)
  36. {
  37. u32 port, endport = baseport + nports;
  38. pr_debug("bigsur_port_map(base=0x%0x, n=0x%0x, addr=0x%08x)\n",
  39. baseport, nports, addr);
  40. for (port = baseport ;
  41. port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
  42. port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
  43. pr_debug(" maplo[0x%x] = 0x%08x\n", port, addr);
  44. bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = addr;
  45. bigsur_iomap_lo_shift[port>>BIGSUR_IOMAP_LO_SHIFT] = shift;
  46. addr += (1<<(BIGSUR_IOMAP_LO_SHIFT));
  47. }
  48. for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
  49. port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
  50. port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
  51. pr_debug(" maphi[0x%x] = 0x%08x\n", port, addr);
  52. bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = addr;
  53. bigsur_iomap_hi_shift[port>>BIGSUR_IOMAP_HI_SHIFT] = shift;
  54. addr += (1<<(BIGSUR_IOMAP_HI_SHIFT));
  55. }
  56. }
  57. EXPORT_SYMBOL(bigsur_port_map);
  58. void bigsur_port_unmap(u32 baseport, u32 nports)
  59. {
  60. u32 port, endport = baseport + nports;
  61. pr_debug("bigsur_port_unmap(base=0x%0x, n=0x%0x)\n", baseport, nports);
  62. for (port = baseport ;
  63. port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
  64. port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
  65. bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = 0;
  66. }
  67. for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
  68. port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
  69. port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
  70. bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = 0;
  71. }
  72. }
  73. EXPORT_SYMBOL(bigsur_port_unmap);
  74. unsigned long bigsur_isa_port2addr(unsigned long port)
  75. {
  76. unsigned long addr = 0;
  77. unsigned char shift;
  78. /* Physical address not in P0, do nothing */
  79. if (PXSEG(port)) {
  80. addr = port;
  81. /* physical address in P0, map to P2 */
  82. } else if (port >= 0x30000) {
  83. addr = P2SEGADDR(port);
  84. /* Big Sur I/O + HD64465 registers 0x10000-0x30000 */
  85. } else if (port >= BIGSUR_IOMAP_HI_THRESH) {
  86. addr = BIGSUR_INTERNAL_BASE + (port - BIGSUR_IOMAP_HI_THRESH);
  87. /* Handle remapping of high IO/PCI IO ports */
  88. } else if (port >= BIGSUR_IOMAP_LO_THRESH) {
  89. addr = bigsur_iomap_hi[port >> BIGSUR_IOMAP_HI_SHIFT];
  90. shift = bigsur_iomap_hi_shift[port >> BIGSUR_IOMAP_HI_SHIFT];
  91. if (addr != 0)
  92. addr += (port & BIGSUR_IOMAP_HI_MASK) << shift;
  93. } else {
  94. /* Handle remapping of low IO ports */
  95. addr = bigsur_iomap_lo[port >> BIGSUR_IOMAP_LO_SHIFT];
  96. shift = bigsur_iomap_lo_shift[port >> BIGSUR_IOMAP_LO_SHIFT];
  97. if (addr != 0)
  98. addr += (port & BIGSUR_IOMAP_LO_MASK) << shift;
  99. }
  100. pr_debug("%s(0x%08lx) = 0x%08lx\n", __FUNCTION__, port, addr);
  101. return addr;
  102. }