Merge master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / sh / boards / bigsur / io.c
CommitLineData
1da177e4
LT
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
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
1da177e4
LT
40void bigsur_port_map(u32 baseport, u32 nports, u32 addr, u8 shift)
41{
42 u32 port, endport = baseport + nports;
43
44 pr_debug("bigsur_port_map(base=0x%0x, n=0x%0x, addr=0x%08x)\n",
45 baseport, nports, addr);
46
47 for (port = baseport ;
48 port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
49 port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
50 pr_debug(" maplo[0x%x] = 0x%08x\n", port, addr);
51 bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = addr;
52 bigsur_iomap_lo_shift[port>>BIGSUR_IOMAP_LO_SHIFT] = shift;
53 addr += (1<<(BIGSUR_IOMAP_LO_SHIFT));
54 }
55
0e8bbf59 56 for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
1da177e4
LT
57 port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
58 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
59 pr_debug(" maphi[0x%x] = 0x%08x\n", port, addr);
60 bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = addr;
61 bigsur_iomap_hi_shift[port>>BIGSUR_IOMAP_HI_SHIFT] = shift;
62 addr += (1<<(BIGSUR_IOMAP_HI_SHIFT));
63 }
64}
65EXPORT_SYMBOL(bigsur_port_map);
66
67void bigsur_port_unmap(u32 baseport, u32 nports)
68{
69 u32 port, endport = baseport + nports;
70
71 pr_debug("bigsur_port_unmap(base=0x%0x, n=0x%0x)\n", baseport, nports);
72
73 for (port = baseport ;
74 port < endport && port < BIGSUR_IOMAP_LO_THRESH ;
75 port += (1<<BIGSUR_IOMAP_LO_SHIFT)) {
76 bigsur_iomap_lo[port>>BIGSUR_IOMAP_LO_SHIFT] = 0;
77 }
78
0e8bbf59 79 for (port = max_t(u32, baseport, BIGSUR_IOMAP_LO_THRESH);
1da177e4
LT
80 port < endport && port < BIGSUR_IOMAP_HI_THRESH ;
81 port += (1<<BIGSUR_IOMAP_HI_SHIFT)) {
82 bigsur_iomap_hi[port>>BIGSUR_IOMAP_HI_SHIFT] = 0;
83 }
84}
85EXPORT_SYMBOL(bigsur_port_unmap);
86
87unsigned long bigsur_isa_port2addr(unsigned long port)
88{
89 unsigned long addr = 0;
90 unsigned char shift;
91
92 /* Physical address not in P0, do nothing */
93 if (PXSEG(port)) {
94 addr = port;
95 /* physical address in P0, map to P2 */
96 } else if (port >= 0x30000) {
97 addr = P2SEGADDR(port);
98 /* Big Sur I/O + HD64465 registers 0x10000-0x30000 */
99 } else if (port >= BIGSUR_IOMAP_HI_THRESH) {
100 addr = BIGSUR_INTERNAL_BASE + (port - BIGSUR_IOMAP_HI_THRESH);
101 /* Handle remapping of high IO/PCI IO ports */
102 } else if (port >= BIGSUR_IOMAP_LO_THRESH) {
103 addr = bigsur_iomap_hi[port >> BIGSUR_IOMAP_HI_SHIFT];
104 shift = bigsur_iomap_hi_shift[port >> BIGSUR_IOMAP_HI_SHIFT];
105
106 if (addr != 0)
107 addr += (port & BIGSUR_IOMAP_HI_MASK) << shift;
108 } else {
109 /* Handle remapping of low IO ports */
110 addr = bigsur_iomap_lo[port >> BIGSUR_IOMAP_LO_SHIFT];
111 shift = bigsur_iomap_lo_shift[port >> BIGSUR_IOMAP_LO_SHIFT];
112
113 if (addr != 0)
114 addr += (port & BIGSUR_IOMAP_LO_MASK) << shift;
115 }
116
117 pr_debug("%s(0x%08lx) = 0x%08lx\n", __FUNCTION__, port, addr);
118
119 return addr;
120}
121