2 * $Id: io.c,v 1.4 2003/08/03 03:05:10 lethal Exp $
3 * by Greg Banks <gbanks@pocketpenguins.com>
4 * (c) 2000 PocketPenguins Inc
6 * Derived from io_hd64461.c, which bore the message:
7 * Copyright (C) 2000 YAEGASHI Takeshi
9 * Typical I/O routines for HD64465 system.
12 #include <linux/config.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
16 #include <asm/hd64465/hd64465.h>
19 #define HD64465_DEBUG 0
22 #define DPRINTK(args...) printk(args)
23 #define DIPRINTK(n, args...) if (hd64465_io_debug>(n)) printk(args)
25 #define DPRINTK(args...)
26 #define DIPRINTK(n, args...)
31 /* This is a hack suitable only for debugging IO port problems */
33 EXPORT_SYMBOL(hd64465_io_debug
);
35 /* Low iomap maps port 0-1K to addresses in 8byte chunks */
36 #define HD64465_IOMAP_LO_THRESH 0x400
37 #define HD64465_IOMAP_LO_SHIFT 3
38 #define HD64465_IOMAP_LO_MASK ((1<<HD64465_IOMAP_LO_SHIFT)-1)
39 #define HD64465_IOMAP_LO_NMAP (HD64465_IOMAP_LO_THRESH>>HD64465_IOMAP_LO_SHIFT)
40 static unsigned long hd64465_iomap_lo
[HD64465_IOMAP_LO_NMAP
];
41 static unsigned char hd64465_iomap_lo_shift
[HD64465_IOMAP_LO_NMAP
];
43 /* High iomap maps port 1K-64K to addresses in 1K chunks */
44 #define HD64465_IOMAP_HI_THRESH 0x10000
45 #define HD64465_IOMAP_HI_SHIFT 10
46 #define HD64465_IOMAP_HI_MASK ((1<<HD64465_IOMAP_HI_SHIFT)-1)
47 #define HD64465_IOMAP_HI_NMAP (HD64465_IOMAP_HI_THRESH>>HD64465_IOMAP_HI_SHIFT)
48 static unsigned long hd64465_iomap_hi
[HD64465_IOMAP_HI_NMAP
];
49 static unsigned char hd64465_iomap_hi_shift
[HD64465_IOMAP_HI_NMAP
];
52 #define MAX(a,b) ((a)>(b)?(a):(b))
55 #define PORT2ADDR(x) (sh_mv.mv_isa_port2addr(x))
57 void hd64465_port_map(unsigned short baseport
, unsigned int nports
,
58 unsigned long addr
, unsigned char shift
)
60 unsigned int port
, endport
= baseport
+ nports
;
62 DPRINTK("hd64465_port_map(base=0x%04hx, n=0x%04hx, addr=0x%08lx,endport=0x%04x)\n",
63 baseport
, nports
, addr
,endport
);
65 for (port
= baseport
;
66 port
< endport
&& port
< HD64465_IOMAP_LO_THRESH
;
67 port
+= (1<<HD64465_IOMAP_LO_SHIFT
)) {
68 DPRINTK(" maplo[0x%x] = 0x%08lx\n", port
, addr
);
69 hd64465_iomap_lo
[port
>>HD64465_IOMAP_LO_SHIFT
] = addr
;
70 hd64465_iomap_lo_shift
[port
>>HD64465_IOMAP_LO_SHIFT
] = shift
;
71 addr
+= (1<<(HD64465_IOMAP_LO_SHIFT
));
74 for (port
= MAX(baseport
, HD64465_IOMAP_LO_THRESH
) ;
75 port
< endport
&& port
< HD64465_IOMAP_HI_THRESH
;
76 port
+= (1<<HD64465_IOMAP_HI_SHIFT
)) {
77 DPRINTK(" maphi[0x%x] = 0x%08lx\n", port
, addr
);
78 hd64465_iomap_hi
[port
>>HD64465_IOMAP_HI_SHIFT
] = addr
;
79 hd64465_iomap_hi_shift
[port
>>HD64465_IOMAP_HI_SHIFT
] = shift
;
80 addr
+= (1<<(HD64465_IOMAP_HI_SHIFT
));
83 EXPORT_SYMBOL(hd64465_port_map
);
85 void hd64465_port_unmap(unsigned short baseport
, unsigned int nports
)
87 unsigned int port
, endport
= baseport
+ nports
;
89 DPRINTK("hd64465_port_unmap(base=0x%04hx, n=0x%04hx)\n",
92 for (port
= baseport
;
93 port
< endport
&& port
< HD64465_IOMAP_LO_THRESH
;
94 port
+= (1<<HD64465_IOMAP_LO_SHIFT
)) {
95 hd64465_iomap_lo
[port
>>HD64465_IOMAP_LO_SHIFT
] = 0;
98 for (port
= MAX(baseport
, HD64465_IOMAP_LO_THRESH
) ;
99 port
< endport
&& port
< HD64465_IOMAP_HI_THRESH
;
100 port
+= (1<<HD64465_IOMAP_HI_SHIFT
)) {
101 hd64465_iomap_hi
[port
>>HD64465_IOMAP_HI_SHIFT
] = 0;
104 EXPORT_SYMBOL(hd64465_port_unmap
);
106 unsigned long hd64465_isa_port2addr(unsigned long port
)
108 unsigned long addr
= 0;
111 /* handle remapping of low IO ports */
112 if (port
< HD64465_IOMAP_LO_THRESH
) {
113 addr
= hd64465_iomap_lo
[port
>> HD64465_IOMAP_LO_SHIFT
];
114 shift
= hd64465_iomap_lo_shift
[port
>> HD64465_IOMAP_LO_SHIFT
];
116 addr
+= (port
& HD64465_IOMAP_LO_MASK
) << shift
;
118 printk(KERN_NOTICE
"io_hd64465: access to un-mapped port %lx\n", port
);
119 } else if (port
< HD64465_IOMAP_HI_THRESH
) {
120 addr
= hd64465_iomap_hi
[port
>> HD64465_IOMAP_HI_SHIFT
];
121 shift
= hd64465_iomap_hi_shift
[port
>> HD64465_IOMAP_HI_SHIFT
];
123 addr
+= (port
& HD64465_IOMAP_HI_MASK
) << shift
;
125 printk(KERN_NOTICE
"io_hd64465: access to un-mapped port %lx\n", port
);
128 /* HD64465 internal devices (0xb0000000) */
129 else if (port
< 0x20000)
130 addr
= CONFIG_HD64465_IOBASE
+ port
- 0x10000;
132 /* Whole physical address space (0xa0000000) */
134 addr
= P2SEGADDR(port
);
136 DIPRINTK(2, "PORT2ADDR(0x%08lx) = 0x%08lx\n", port
, addr
);
141 static inline void delay(void)
143 ctrl_inw(0xa0000000);
146 unsigned char hd64465_inb(unsigned long port
)
148 unsigned long addr
= PORT2ADDR(port
);
149 unsigned long b
= (addr
== 0 ? 0 : *(volatile unsigned char*)addr
);
151 DIPRINTK(0, "inb(%08lx) = %02x\n", addr
, (unsigned)b
);
155 unsigned char hd64465_inb_p(unsigned long port
)
158 unsigned long addr
= PORT2ADDR(port
);
160 v
= (addr
== 0 ? 0 : *(volatile unsigned char*)addr
);
162 DIPRINTK(0, "inb_p(%08lx) = %02x\n", addr
, (unsigned)v
);
166 unsigned short hd64465_inw(unsigned long port
)
168 unsigned long addr
= PORT2ADDR(port
);
169 unsigned long b
= (addr
== 0 ? 0 : *(volatile unsigned short*)addr
);
170 DIPRINTK(0, "inw(%08lx) = %04lx\n", addr
, b
);
174 unsigned int hd64465_inl(unsigned long port
)
176 unsigned long addr
= PORT2ADDR(port
);
177 unsigned int b
= (addr
== 0 ? 0 : *(volatile unsigned long*)addr
);
178 DIPRINTK(0, "inl(%08lx) = %08x\n", addr
, b
);
182 void hd64465_outb(unsigned char b
, unsigned long port
)
184 unsigned long addr
= PORT2ADDR(port
);
186 DIPRINTK(0, "outb(%02x, %08lx)\n", (unsigned)b
, addr
);
188 *(volatile unsigned char*)addr
= b
;
191 void hd64465_outb_p(unsigned char b
, unsigned long port
)
193 unsigned long addr
= PORT2ADDR(port
);
195 DIPRINTK(0, "outb_p(%02x, %08lx)\n", (unsigned)b
, addr
);
197 *(volatile unsigned char*)addr
= b
;
201 void hd64465_outw(unsigned short b
, unsigned long port
)
203 unsigned long addr
= PORT2ADDR(port
);
204 DIPRINTK(0, "outw(%04x, %08lx)\n", (unsigned)b
, addr
);
206 *(volatile unsigned short*)addr
= b
;
209 void hd64465_outl(unsigned int b
, unsigned long port
)
211 unsigned long addr
= PORT2ADDR(port
);
212 DIPRINTK(0, "outl(%08x, %08lx)\n", b
, addr
);
214 *(volatile unsigned long*)addr
= b
;