kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/boards/landisk/io.c |
| 3 | * |
| 4 | * Copyright (C) 2001 Ian da Silva, Jeremy Siegel |
| 5 | * Based largely on io_se.c. |
| 6 | * |
| 7 | * I/O routine for I-O Data Device, Inc. LANDISK. |
| 8 | * |
| 9 | * Initial version only to support LAN access; some |
| 10 | * placeholder code from io_landisk.c left in with the |
| 11 | * expectation of later SuperIO and PCMCIA access. |
| 12 | */ |
| 13 | /* |
| 14 | * modifed by kogiidena |
| 15 | * 2005.03.03 |
| 16 | */ |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 17 | #include <linux/kernel.h> |
| 18 | #include <linux/types.h> |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 19 | #include <linux/pci.h> |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 20 | #include <asm/landisk/iodata_landisk.h> |
| 21 | #include <asm/addrspace.h> |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 22 | #include <asm/io.h> |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 23 | |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 24 | extern void *area5_io_base; /* Area 5 I/O Base address */ |
| 25 | extern void *area6_io_base; /* Area 6 I/O Base address */ |
| 26 | |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 27 | static inline unsigned long port2adr(unsigned int port) |
| 28 | { |
| 29 | if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6) |
| 30 | if (port == 0x3f6) |
| 31 | return ((unsigned long)area5_io_base + 0x2c); |
| 32 | else |
| 33 | return ((unsigned long)area5_io_base + PA_PIDE_OFFSET + |
| 34 | ((port - 0x1f0) << 1)); |
| 35 | else if ((0x170 <= port && port < 0x178) || port == 0x376) |
| 36 | if (port == 0x376) |
| 37 | return ((unsigned long)area6_io_base + 0x2c); |
| 38 | else |
| 39 | return ((unsigned long)area6_io_base + PA_SIDE_OFFSET + |
| 40 | ((port - 0x170) << 1)); |
| 41 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 42 | maybebadio((unsigned long)port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 43 | |
| 44 | return port; |
| 45 | } |
| 46 | |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 47 | /* |
| 48 | * General outline: remap really low stuff [eventually] to SuperIO, |
| 49 | * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO) |
| 50 | * is mapped through the PCI IO window. Stuff with high bits (PXSEG) |
| 51 | * should be way beyond the window, and is used w/o translation for |
| 52 | * compatibility. |
| 53 | */ |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 54 | u8 landisk_inb(unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 55 | { |
| 56 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 57 | return ctrl_inb(port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 58 | else if (is_pci_ioaddr(port)) |
| 59 | return ctrl_inb(pci_ioaddr(port)); |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 60 | |
| 61 | return ctrl_inw(port2adr(port)) & 0xff; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 62 | } |
| 63 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 64 | u8 landisk_inb_p(unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 65 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 66 | u8 v; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 67 | |
| 68 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 69 | v = ctrl_inb(port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 70 | else if (is_pci_ioaddr(port)) |
| 71 | v = ctrl_inb(pci_ioaddr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 72 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 73 | v = ctrl_inw(port2adr(port)) & 0xff; |
| 74 | |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 75 | ctrl_delay(); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 76 | |
| 77 | return v; |
| 78 | } |
| 79 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 80 | u16 landisk_inw(unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 81 | { |
| 82 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 83 | return ctrl_inw(port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 84 | else if (is_pci_ioaddr(port)) |
| 85 | return ctrl_inw(pci_ioaddr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 86 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 87 | maybebadio(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 92 | u32 landisk_inl(unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 93 | { |
| 94 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 95 | return ctrl_inl(port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 96 | else if (is_pci_ioaddr(port)) |
| 97 | return ctrl_inl(pci_ioaddr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 98 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 99 | maybebadio(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 104 | void landisk_outb(u8 value, unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 105 | { |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 106 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 107 | ctrl_outb(value, port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 108 | else if (is_pci_ioaddr(port)) |
| 109 | ctrl_outb(value, pci_ioaddr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 110 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 111 | ctrl_outw(value, port2adr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 112 | } |
| 113 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 114 | void landisk_outb_p(u8 value, unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 115 | { |
| 116 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 117 | ctrl_outb(value, port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 118 | else if (is_pci_ioaddr(port)) |
| 119 | ctrl_outb(value, pci_ioaddr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 120 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 121 | ctrl_outw(value, port2adr(port)); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 122 | ctrl_delay(); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 123 | } |
| 124 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 125 | void landisk_outw(u16 value, unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 126 | { |
| 127 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 128 | ctrl_outw(value, port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 129 | else if (is_pci_ioaddr(port)) |
| 130 | ctrl_outw(value, pci_ioaddr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 131 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 132 | maybebadio(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 133 | } |
| 134 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 135 | void landisk_outl(u32 value, unsigned long port) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 136 | { |
| 137 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 138 | ctrl_outl(value, port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 139 | else if (is_pci_ioaddr(port)) |
| 140 | ctrl_outl(value, pci_ioaddr(port)); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 141 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 142 | maybebadio(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 143 | } |
| 144 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 145 | void landisk_insb(unsigned long port, void *dst, unsigned long count) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 146 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 147 | volatile u16 *p; |
| 148 | u8 *buf = dst; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 149 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 150 | if (PXSEG(port)) { |
| 151 | while (count--) |
| 152 | *buf++ = *(volatile u8 *)port; |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 153 | } else if (is_pci_ioaddr(port)) { |
| 154 | volatile u8 *bp = (volatile u8 *)pci_ioaddr(port); |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 155 | |
| 156 | while (count--) |
| 157 | *buf++ = *bp; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 158 | } else { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 159 | p = (volatile u16 *)port2adr(port); |
| 160 | while (count--) |
| 161 | *buf++ = *p & 0xff; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 165 | void landisk_insw(unsigned long port, void *dst, unsigned long count) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 166 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 167 | volatile u16 *p; |
| 168 | u16 *buf = dst; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 169 | |
| 170 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 171 | p = (volatile u16 *)port; |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 172 | else if (is_pci_ioaddr(port)) |
| 173 | p = (volatile u16 *)pci_ioaddr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 174 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 175 | p = (volatile u16 *)port2adr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 176 | while (count--) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 177 | *buf++ = *p; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 178 | } |
| 179 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 180 | void landisk_insl(unsigned long port, void *dst, unsigned long count) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 181 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 182 | u32 *buf = dst; |
| 183 | |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 184 | if (is_pci_ioaddr(port)) { |
| 185 | volatile u32 *p = (volatile u32 *)pci_ioaddr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 186 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 187 | while (count--) |
| 188 | *buf++ = *p; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 189 | } else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 190 | maybebadio(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 191 | } |
| 192 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 193 | void landisk_outsb(unsigned long port, const void *src, unsigned long count) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 194 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 195 | volatile u16 *p; |
| 196 | const u8 *buf = src; |
| 197 | |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 198 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 199 | while (count--) |
| 200 | ctrl_outb(*buf++, port); |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 201 | else if (is_pci_ioaddr(port)) { |
| 202 | volatile u8 *bp = (volatile u8 *)pci_ioaddr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 203 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 204 | while (count--) |
| 205 | *bp = *buf++; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 206 | } else { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 207 | p = (volatile u16 *)port2adr(port); |
| 208 | while (count--) |
| 209 | *p = *buf++; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 213 | void landisk_outsw(unsigned long port, const void *src, unsigned long count) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 214 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 215 | volatile u16 *p; |
| 216 | const u16 *buf = src; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 217 | |
| 218 | if (PXSEG(port)) |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 219 | p = (volatile u16 *)port; |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 220 | else if (is_pci_ioaddr(port)) |
| 221 | p = (volatile u16 *)pci_ioaddr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 222 | else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 223 | p = (volatile u16 *)port2adr(port); |
| 224 | |
| 225 | while (count--) |
| 226 | *p = *buf++; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 227 | } |
| 228 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 229 | void landisk_outsl(unsigned long port, const void *src, unsigned long count) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 230 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 231 | const u32 *buf = src; |
| 232 | |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 233 | if (is_pci_ioaddr(port)) { |
| 234 | volatile u32 *p = (volatile u32 *)pci_ioaddr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 235 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 236 | while (count--) |
| 237 | *p = *buf++; |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 238 | } else |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 239 | maybebadio(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 240 | } |
| 241 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 242 | void __iomem *landisk_ioport_map(unsigned long port, unsigned int size) |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 243 | { |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 244 | if (PXSEG(port)) |
| 245 | return (void __iomem *)port; |
Paul Mundt | 959f85f | 2006-09-27 16:43:28 +0900 | [diff] [blame] | 246 | else if (is_pci_ioaddr(port)) |
| 247 | return (void __iomem *)pci_ioaddr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 248 | |
Paul Mundt | d7cdc9e | 2006-09-27 15:16:42 +0900 | [diff] [blame] | 249 | return (void __iomem *)port2adr(port); |
kogiidena | 94c0fa5 | 2006-09-27 14:53:35 +0900 | [diff] [blame] | 250 | } |