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