2 * include/asm-sh/io_bigsur.c
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)
11 * May be copied or modified under the terms of the GNU General Public
12 * License. See linux/COPYING for more information.
14 * IO functions for a Hitachi Big Sur Evaluation Board.
17 #include <linux/config.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <asm/machvec.h>
22 #include <asm/bigsur.h>
24 //#define BIGSUR_DEBUG 2
28 #define DPRINTK(args...) printk(args)
29 #define DIPRINTK(n, args...) if (BIGSUR_DEBUG>(n)) printk(args)
31 #define DPRINTK(args...)
32 #define DIPRINTK(n, args...)
36 /* Low iomap maps port 0-1K to addresses in 8byte chunks */
37 #define BIGSUR_IOMAP_LO_THRESH 0x400
38 #define BIGSUR_IOMAP_LO_SHIFT 3
39 #define BIGSUR_IOMAP_LO_MASK ((1<<BIGSUR_IOMAP_LO_SHIFT)-1)
40 #define BIGSUR_IOMAP_LO_NMAP (BIGSUR_IOMAP_LO_THRESH>>BIGSUR_IOMAP_LO_SHIFT)
41 static u32 bigsur_iomap_lo[BIGSUR_IOMAP_LO_NMAP];
42 static u8 bigsur_iomap_lo_shift[BIGSUR_IOMAP_LO_NMAP];
44 /* High iomap maps port 1K-64K to addresses in 1K chunks */
45 #define BIGSUR_IOMAP_HI_THRESH 0x10000
46 #define BIGSUR_IOMAP_HI_SHIFT 10
47 #define BIGSUR_IOMAP_HI_MASK ((1<<BIGSUR_IOMAP_HI_SHIFT)-1)
48 #define BIGSUR_IOMAP_HI_NMAP (BIGSUR_IOMAP_HI_THRESH>>BIGSUR_IOMAP_HI_SHIFT)
49 static u32 bigsur_iomap_hi[BIGSUR_IOMAP_HI_NMAP];
50 static u8 bigsur_iomap_hi_shift[BIGSUR_IOMAP_HI_NMAP];
53 #define MAX(a,b) ((a)>(b)?(a):(b))
56 #define PORT2ADDR(x) (sh_mv.mv_isa_port2addr(x))
58 void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift)
60 u32 port, endport = baseport + nports;
62 DPRINTK("bigsur_port_map(base=0x%0x, n=0x%0x, addr=0x%08x)\n",
63 baseport, nports, addr);
65 for (port = baseport ;
66 port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
67 port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
68 DPRINTK(" maplo[0x%x] = 0x%08x\n", port, addr);
69 bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = addr;
70 bigsur_iomap_lo_shift[port>>BIGSUR_IOMAP_LO_SHIFT] = shift;
71 addr += (1<<(BIGSUR_IOMAP_LO_SHIFT));
74 for (port = MAX(baseport, BIGSUR_IOMAP_LO_THRESH) ;
75 port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
76 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
77 DPRINTK(" maphi[0x%x] = 0x%08x\n", port, addr);
78 bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = addr;
79 bigsur_iomap_hi_shift[port>>BIGSUR_IOMAP_HI_SHIFT] = shift;
80 addr += (1<<(BIGSUR_IOMAP_HI_SHIFT));
83 EXPORT_SYMBOL(bigsur_port_map);
85 void bigsur_port_unmap(u32 baseport, u32 nports)
87 u32 port, endport = baseport + nports;
89 DPRINTK("bigsur_port_unmap(base=0x%0x, n=0x%0x)\n", baseport, nports);
91 for (port = baseport ;
92 port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
93 port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
94 bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = 0;
97 for (port = MAX(baseport, BIGSUR_IOMAP_LO_THRESH) ;
98 port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
99 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
100 bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = 0;
103 EXPORT_SYMBOL(bigsur_port_unmap);
105 unsigned long bigsur_isa_port2addr(unsigned long port)
107 unsigned long addr = 0;
110 /* Physical address not in P0, do nothing */
111 if (PXSEG(port)) addr = port;
112 /* physical address in P0, map to P2 */
113 else if (port >= 0x30000)
114 addr = P2SEGADDR(port);
115 /* Big Sur I/O + HD64465 registers 0x10000-0x30000 */
116 else if (port >= BIGSUR_IOMAP_HI_THRESH)
117 addr = BIGSUR_INTERNAL_BASE + (port - BIGSUR_IOMAP_HI_THRESH);
118 /* Handle remapping of high IO/PCI IO ports */
119 else if (port >= BIGSUR_IOMAP_LO_THRESH) {
120 addr = bigsur_iomap_hi[port >> BIGSUR_IOMAP_HI_SHIFT];
121 shift = bigsur_iomap_hi_shift[port >> BIGSUR_IOMAP_HI_SHIFT];
123 addr += (port & BIGSUR_IOMAP_HI_MASK) << shift;
125 /* Handle remapping of low IO ports */
127 addr = bigsur_iomap_lo[port >> BIGSUR_IOMAP_LO_SHIFT];
128 shift = bigsur_iomap_lo_shift[port >> BIGSUR_IOMAP_LO_SHIFT];
130 addr += (port & BIGSUR_IOMAP_LO_MASK) << shift;
133 DIPRINTK(2, "PORT2ADDR(0x%08lx) = 0x%08lx\n", port, addr);
138 static inline void delay(void)
140 ctrl_inw(0xa0000000);
143 unsigned char bigsur_inb(unsigned long port)
145 unsigned long addr = PORT2ADDR(port);
146 unsigned long b = (addr == 0 ? 0 : *(volatile unsigned char*)addr);
148 DIPRINTK(0, "inb(%08lx) = %02x\n", addr, (unsigned)b);
152 unsigned char bigsur_inb_p(unsigned long port)
155 unsigned long addr = PORT2ADDR(port);
157 v = (addr == 0 ? 0 : *(volatile unsigned char*)addr);
159 DIPRINTK(0, "inb_p(%08lx) = %02x\n", addr, (unsigned)v);
163 unsigned short bigsur_inw(unsigned long port)
165 unsigned long addr = PORT2ADDR(port);
166 unsigned long b = (addr == 0 ? 0 : *(volatile unsigned short*)addr);
167 DIPRINTK(0, "inw(%08lx) = %04lx\n", addr, b);
171 unsigned int bigsur_inl(unsigned long port)
173 unsigned long addr = PORT2ADDR(port);
174 unsigned int b = (addr == 0 ? 0 : *(volatile unsigned long*)addr);
175 DIPRINTK(0, "inl(%08lx) = %08x\n", addr, b);
179 void bigsur_insb(unsigned long port, void *buffer, unsigned long count)
181 unsigned char *buf=buffer;
182 while(count--) *buf++=inb(port);
185 void bigsur_insw(unsigned long port, void *buffer, unsigned long count)
187 unsigned short *buf=buffer;
188 while(count--) *buf++=inw(port);
191 void bigsur_insl(unsigned long port, void *buffer, unsigned long count)
193 unsigned long *buf=buffer;
194 while(count--) *buf++=inl(port);
197 void bigsur_outb(unsigned char b, unsigned long port)
199 unsigned long addr = PORT2ADDR(port);
201 DIPRINTK(0, "outb(%02x, %08lx)\n", (unsigned)b, addr);
203 *(volatile unsigned char*)addr = b;
206 void bigsur_outb_p(unsigned char b, unsigned long port)
208 unsigned long addr = PORT2ADDR(port);
210 DIPRINTK(0, "outb_p(%02x, %08lx)\n", (unsigned)b, addr);
212 *(volatile unsigned char*)addr = b;
216 void bigsur_outw(unsigned short b, unsigned long port)
218 unsigned long addr = PORT2ADDR(port);
219 DIPRINTK(0, "outw(%04x, %08lx)\n", (unsigned)b, addr);
221 *(volatile unsigned short*)addr = b;
224 void bigsur_outl(unsigned int b, unsigned long port)
226 unsigned long addr = PORT2ADDR(port);
227 DIPRINTK(0, "outl(%08x, %08lx)\n", b, addr);
229 *(volatile unsigned long*)addr = b;
232 void bigsur_outsb(unsigned long port, const void *buffer, unsigned long count)
234 const unsigned char *buf=buffer;
235 while(count--) outb(*buf++, port);
238 void bigsur_outsw(unsigned long port, const void *buffer, unsigned long count)
240 const unsigned short *buf=buffer;
241 while(count--) outw(*buf++, port);
244 void bigsur_outsl(unsigned long port, const void *buffer, unsigned long count)
246 const unsigned long *buf=buffer;
247 while(count--) outl(*buf++, port);