wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 1 | /* |
wdenk | b22532e | 2005-02-07 19:44:17 +0000 | [diff] [blame] | 2 | * (C) Copyright 2003-2005 |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | ******************************************************************** |
| 24 | * |
| 25 | * Lots of code copied from: |
| 26 | * |
| 27 | * i82365.c 1.352 - Linux driver for Intel 82365 and compatible |
| 28 | * PC Card controllers, and Yenta-compatible PCI-to-CardBus controllers. |
| 29 | * (C) 1999 David A. Hinds <dahinds@users.sourceforge.net> |
| 30 | */ |
| 31 | |
| 32 | #include <common.h> |
| 33 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 34 | #include <command.h> |
| 35 | #include <pci.h> |
| 36 | #include <pcmcia.h> |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 37 | #include <asm/io.h> |
| 38 | |
| 39 | #include <pcmcia/ss.h> |
| 40 | #include <pcmcia/i82365.h> |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 41 | #include <pcmcia/yenta.h> |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 42 | #ifdef CONFIG_CPC45 |
| 43 | #include <pcmcia/cirrus.h> |
| 44 | #else |
| 45 | #include <pcmcia/ti113x.h> |
| 46 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 47 | |
| 48 | static struct pci_device_id supported[] = { |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 49 | #ifdef CONFIG_CPC45 |
| 50 | {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6729}, |
| 51 | #else |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 52 | {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510}, |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 53 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 54 | {0, 0} |
| 55 | }; |
| 56 | |
| 57 | #define CYCLE_TIME 120 |
| 58 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_CPC45 |
| 60 | extern int SPD67290Init (void); |
| 61 | #endif |
| 62 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 63 | #ifdef DEBUG |
| 64 | static void i82365_dump_regions (pci_dev_t dev); |
| 65 | #endif |
| 66 | |
| 67 | typedef struct socket_info_t { |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 68 | pci_dev_t dev; |
| 69 | u_short bcr; |
| 70 | u_char pci_lat, cb_lat, sub_bus, cache; |
| 71 | u_int cb_phys; |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 72 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 73 | socket_cap_t cap; |
| 74 | u_short type; |
| 75 | u_int flags; |
| 76 | #ifdef CONFIG_CPC45 |
| 77 | cirrus_state_t c_state; |
| 78 | #else |
| 79 | ti113x_state_t state; |
| 80 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 81 | } socket_info_t; |
| 82 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 83 | #ifdef CONFIG_CPC45 |
| 84 | /* These definitions must match the pcic table! */ |
| 85 | typedef enum pcic_id { |
| 86 | IS_PD6710, IS_PD672X, IS_VT83C469 |
| 87 | } pcic_id; |
| 88 | |
| 89 | typedef struct pcic_t { |
| 90 | char *name; |
| 91 | } pcic_t; |
| 92 | |
| 93 | static pcic_t pcic[] = { |
| 94 | {" Cirrus PD6710: "}, |
| 95 | {" Cirrus PD672x: "}, |
| 96 | {" VIA VT83C469: "}, |
| 97 | }; |
| 98 | #endif |
| 99 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 100 | static socket_info_t socket; |
| 101 | static socket_state_t state; |
| 102 | static struct pccard_mem_map mem; |
| 103 | static struct pccard_io_map io; |
| 104 | |
| 105 | /*====================================================================*/ |
| 106 | |
| 107 | /* Some PCI shortcuts */ |
| 108 | |
| 109 | static int pci_readb (socket_info_t * s, int r, u_char * v) |
| 110 | { |
| 111 | return pci_read_config_byte (s->dev, r, v); |
| 112 | } |
| 113 | static int pci_writeb (socket_info_t * s, int r, u_char v) |
| 114 | { |
| 115 | return pci_write_config_byte (s->dev, r, v); |
| 116 | } |
| 117 | static int pci_readw (socket_info_t * s, int r, u_short * v) |
| 118 | { |
| 119 | return pci_read_config_word (s->dev, r, v); |
| 120 | } |
| 121 | static int pci_writew (socket_info_t * s, int r, u_short v) |
| 122 | { |
| 123 | return pci_write_config_word (s->dev, r, v); |
| 124 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 125 | #ifndef CONFIG_CPC45 |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 126 | static int pci_readl (socket_info_t * s, int r, u_int * v) |
| 127 | { |
| 128 | return pci_read_config_dword (s->dev, r, v); |
| 129 | } |
| 130 | static int pci_writel (socket_info_t * s, int r, u_int v) |
| 131 | { |
| 132 | return pci_write_config_dword (s->dev, r, v); |
| 133 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 134 | #endif /* !CONFIG_CPC45 */ |
| 135 | |
| 136 | /*====================================================================*/ |
| 137 | |
| 138 | #ifdef CONFIG_CPC45 |
| 139 | |
| 140 | #define cb_readb(s) readb((s)->cb_phys + 1) |
| 141 | #define cb_writeb(s, v) writeb(v, (s)->cb_phys) |
| 142 | #define cb_writeb2(s, v) writeb(v, (s)->cb_phys + 1) |
| 143 | #define cb_readl(s, r) readl((s)->cb_phys + (r)) |
| 144 | #define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r)) |
| 145 | |
| 146 | |
| 147 | static u_char i365_get (socket_info_t * s, u_short reg) |
| 148 | { |
| 149 | u_char val; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 150 | #ifdef CONFIG_PCMCIA_SLOT_A |
| 151 | int slot = 0; |
| 152 | #else |
| 153 | int slot = 1; |
| 154 | #endif |
| 155 | |
| 156 | val = I365_REG (slot, reg); |
| 157 | |
| 158 | cb_writeb (s, val); |
| 159 | val = cb_readb (s); |
| 160 | |
| 161 | debug ("i365_get slot:%x reg: %x val: %x\n", slot, reg, val); |
| 162 | return val; |
| 163 | } |
| 164 | |
| 165 | static void i365_set (socket_info_t * s, u_short reg, u_char data) |
| 166 | { |
| 167 | #ifdef CONFIG_PCMCIA_SLOT_A |
| 168 | int slot = 0; |
| 169 | #else |
| 170 | int slot = 1; |
| 171 | #endif |
wdenk | 525d7b6 | 2005-01-22 18:13:04 +0000 | [diff] [blame] | 172 | u_char val; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 173 | |
wdenk | 525d7b6 | 2005-01-22 18:13:04 +0000 | [diff] [blame] | 174 | val = I365_REG (slot, reg); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 175 | |
| 176 | cb_writeb (s, val); |
| 177 | cb_writeb2 (s, data); |
| 178 | |
| 179 | debug ("i365_set slot:%x reg: %x data:%x\n", slot, reg, data); |
| 180 | } |
| 181 | |
| 182 | #else /* ! CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 183 | |
| 184 | #define cb_readb(s, r) readb((s)->cb_phys + (r)) |
| 185 | #define cb_readl(s, r) readl((s)->cb_phys + (r)) |
| 186 | #define cb_writeb(s, r, v) writeb(v, (s)->cb_phys + (r)) |
| 187 | #define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r)) |
| 188 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 189 | static u_char i365_get (socket_info_t * s, u_short reg) |
| 190 | { |
| 191 | return cb_readb (s, 0x0800 + reg); |
| 192 | } |
| 193 | |
| 194 | static void i365_set (socket_info_t * s, u_short reg, u_char data) |
| 195 | { |
| 196 | cb_writeb (s, 0x0800 + reg, data); |
| 197 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 198 | #endif /* CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 199 | |
| 200 | static void i365_bset (socket_info_t * s, u_short reg, u_char mask) |
| 201 | { |
| 202 | i365_set (s, reg, i365_get (s, reg) | mask); |
| 203 | } |
| 204 | |
| 205 | static void i365_bclr (socket_info_t * s, u_short reg, u_char mask) |
| 206 | { |
| 207 | i365_set (s, reg, i365_get (s, reg) & ~mask); |
| 208 | } |
| 209 | |
| 210 | #if 0 /* not used */ |
| 211 | static void i365_bflip (socket_info_t * s, u_short reg, u_char mask, int b) |
| 212 | { |
| 213 | u_char d = i365_get (s, reg); |
| 214 | |
| 215 | i365_set (s, reg, (b) ? (d | mask) : (d & ~mask)); |
| 216 | } |
| 217 | |
| 218 | static u_short i365_get_pair (socket_info_t * s, u_short reg) |
| 219 | { |
| 220 | return (i365_get (s, reg) + (i365_get (s, reg + 1) << 8)); |
| 221 | } |
| 222 | #endif /* not used */ |
| 223 | |
| 224 | static void i365_set_pair (socket_info_t * s, u_short reg, u_short data) |
| 225 | { |
| 226 | i365_set (s, reg, data & 0xff); |
| 227 | i365_set (s, reg + 1, data >> 8); |
| 228 | } |
| 229 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 230 | #ifdef CONFIG_CPC45 |
| 231 | /*====================================================================== |
| 232 | |
| 233 | Code to save and restore global state information for Cirrus |
| 234 | PD67xx controllers, and to set and report global configuration |
| 235 | options. |
| 236 | |
| 237 | ======================================================================*/ |
| 238 | |
| 239 | #define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b)))) |
| 240 | |
| 241 | static void cirrus_get_state (socket_info_t * s) |
| 242 | { |
| 243 | int i; |
| 244 | cirrus_state_t *p = &s->c_state; |
| 245 | |
| 246 | p->misc1 = i365_get (s, PD67_MISC_CTL_1); |
| 247 | p->misc1 &= (PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA); |
| 248 | p->misc2 = i365_get (s, PD67_MISC_CTL_2); |
| 249 | for (i = 0; i < 6; i++) |
| 250 | p->timer[i] = i365_get (s, PD67_TIME_SETUP (0) + i); |
| 251 | |
| 252 | } |
| 253 | |
| 254 | static void cirrus_set_state (socket_info_t * s) |
| 255 | { |
| 256 | int i; |
| 257 | u_char misc; |
| 258 | cirrus_state_t *p = &s->c_state; |
| 259 | |
| 260 | misc = i365_get (s, PD67_MISC_CTL_2); |
| 261 | i365_set (s, PD67_MISC_CTL_2, p->misc2); |
| 262 | if (misc & PD67_MC2_SUSPEND) |
| 263 | udelay (50000); |
| 264 | misc = i365_get (s, PD67_MISC_CTL_1); |
| 265 | misc &= ~(PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA); |
| 266 | i365_set (s, PD67_MISC_CTL_1, misc | p->misc1); |
| 267 | for (i = 0; i < 6; i++) |
| 268 | i365_set (s, PD67_TIME_SETUP (0) + i, p->timer[i]); |
| 269 | } |
| 270 | |
| 271 | static u_int cirrus_set_opts (socket_info_t * s) |
| 272 | { |
| 273 | cirrus_state_t *p = &s->c_state; |
| 274 | u_int mask = 0xffff; |
Marek Vasut | 95fbd0b | 2011-10-21 14:17:30 +0000 | [diff] [blame] | 275 | char buf[200] = {0}; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 276 | |
| 277 | if (has_ring == -1) |
| 278 | has_ring = 1; |
| 279 | flip (p->misc2, PD67_MC2_IRQ15_RI, has_ring); |
| 280 | flip (p->misc2, PD67_MC2_DYNAMIC_MODE, dynamic_mode); |
| 281 | #if DEBUG |
| 282 | if (p->misc2 & PD67_MC2_IRQ15_RI) |
| 283 | strcat (buf, " [ring]"); |
| 284 | if (p->misc2 & PD67_MC2_DYNAMIC_MODE) |
| 285 | strcat (buf, " [dyn mode]"); |
| 286 | if (p->misc1 & PD67_MC1_INPACK_ENA) |
| 287 | strcat (buf, " [inpack]"); |
| 288 | #endif |
| 289 | |
| 290 | if (p->misc2 & PD67_MC2_IRQ15_RI) |
| 291 | mask &= ~0x8000; |
| 292 | if (has_led > 0) { |
| 293 | #if DEBUG |
| 294 | strcat (buf, " [led]"); |
| 295 | #endif |
| 296 | mask &= ~0x1000; |
| 297 | } |
| 298 | if (has_dma > 0) { |
| 299 | #if DEBUG |
| 300 | strcat (buf, " [dma]"); |
| 301 | #endif |
| 302 | mask &= ~0x0600; |
| 303 | flip (p->misc2, PD67_MC2_FREQ_BYPASS, freq_bypass); |
| 304 | #if DEBUG |
| 305 | if (p->misc2 & PD67_MC2_FREQ_BYPASS) |
| 306 | strcat (buf, " [freq bypass]"); |
| 307 | #endif |
| 308 | } |
| 309 | |
| 310 | if (setup_time >= 0) |
| 311 | p->timer[0] = p->timer[3] = setup_time; |
| 312 | if (cmd_time > 0) { |
| 313 | p->timer[1] = cmd_time; |
| 314 | p->timer[4] = cmd_time * 2 + 4; |
| 315 | } |
| 316 | if (p->timer[1] == 0) { |
| 317 | p->timer[1] = 6; |
| 318 | p->timer[4] = 16; |
| 319 | if (p->timer[0] == 0) |
| 320 | p->timer[0] = p->timer[3] = 1; |
| 321 | } |
| 322 | if (recov_time >= 0) |
| 323 | p->timer[2] = p->timer[5] = recov_time; |
| 324 | |
| 325 | debug ("i82365 Opt: %s [%d/%d/%d] [%d/%d/%d]\n", |
| 326 | buf, |
| 327 | p->timer[0], p->timer[1], p->timer[2], |
| 328 | p->timer[3], p->timer[4], p->timer[5]); |
| 329 | |
| 330 | return mask; |
| 331 | } |
| 332 | |
| 333 | #else /* !CONFIG_CPC45 */ |
| 334 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 335 | /*====================================================================== |
| 336 | |
| 337 | Code to save and restore global state information for TI 1130 and |
| 338 | TI 1131 controllers, and to set and report global configuration |
| 339 | options. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 340 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 341 | ======================================================================*/ |
| 342 | |
| 343 | static void ti113x_get_state (socket_info_t * s) |
| 344 | { |
| 345 | ti113x_state_t *p = &s->state; |
| 346 | |
| 347 | pci_readl (s, TI113X_SYSTEM_CONTROL, &p->sysctl); |
| 348 | pci_readb (s, TI113X_CARD_CONTROL, &p->cardctl); |
| 349 | pci_readb (s, TI113X_DEVICE_CONTROL, &p->devctl); |
| 350 | pci_readb (s, TI1250_DIAGNOSTIC, &p->diag); |
| 351 | pci_readl (s, TI12XX_IRQMUX, &p->irqmux); |
| 352 | } |
| 353 | |
| 354 | static void ti113x_set_state (socket_info_t * s) |
| 355 | { |
| 356 | ti113x_state_t *p = &s->state; |
| 357 | |
| 358 | pci_writel (s, TI113X_SYSTEM_CONTROL, p->sysctl); |
| 359 | pci_writeb (s, TI113X_CARD_CONTROL, p->cardctl); |
| 360 | pci_writeb (s, TI113X_DEVICE_CONTROL, p->devctl); |
| 361 | pci_writeb (s, TI1250_MULTIMEDIA_CTL, 0); |
| 362 | pci_writeb (s, TI1250_DIAGNOSTIC, p->diag); |
| 363 | pci_writel (s, TI12XX_IRQMUX, p->irqmux); |
| 364 | i365_set_pair (s, TI113X_IO_OFFSET (0), 0); |
| 365 | i365_set_pair (s, TI113X_IO_OFFSET (1), 0); |
| 366 | } |
| 367 | |
| 368 | static u_int ti113x_set_opts (socket_info_t * s) |
| 369 | { |
| 370 | ti113x_state_t *p = &s->state; |
| 371 | u_int mask = 0xffff; |
| 372 | |
| 373 | p->cardctl &= ~TI113X_CCR_ZVENABLE; |
| 374 | p->cardctl |= TI113X_CCR_SPKROUTEN; |
| 375 | |
| 376 | return mask; |
| 377 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 378 | #endif /* CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 379 | |
| 380 | /*====================================================================== |
| 381 | |
| 382 | Routines to handle common CardBus options |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 383 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 384 | ======================================================================*/ |
| 385 | |
| 386 | /* Default settings for PCI command configuration register */ |
| 387 | #define CMD_DFLT (PCI_COMMAND_IO|PCI_COMMAND_MEMORY| \ |
| 388 | PCI_COMMAND_MASTER|PCI_COMMAND_WAIT) |
| 389 | |
| 390 | static void cb_get_state (socket_info_t * s) |
| 391 | { |
| 392 | pci_readb (s, PCI_CACHE_LINE_SIZE, &s->cache); |
| 393 | pci_readb (s, PCI_LATENCY_TIMER, &s->pci_lat); |
| 394 | pci_readb (s, CB_LATENCY_TIMER, &s->cb_lat); |
| 395 | pci_readb (s, CB_CARDBUS_BUS, &s->cap.cardbus); |
| 396 | pci_readb (s, CB_SUBORD_BUS, &s->sub_bus); |
| 397 | pci_readw (s, CB_BRIDGE_CONTROL, &s->bcr); |
| 398 | } |
| 399 | |
| 400 | static void cb_set_state (socket_info_t * s) |
| 401 | { |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 402 | #ifndef CONFIG_CPC45 |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 403 | pci_writel (s, CB_LEGACY_MODE_BASE, 0); |
| 404 | pci_writel (s, PCI_BASE_ADDRESS_0, s->cb_phys); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 405 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 406 | pci_writew (s, PCI_COMMAND, CMD_DFLT); |
| 407 | pci_writeb (s, PCI_CACHE_LINE_SIZE, s->cache); |
| 408 | pci_writeb (s, PCI_LATENCY_TIMER, s->pci_lat); |
| 409 | pci_writeb (s, CB_LATENCY_TIMER, s->cb_lat); |
| 410 | pci_writeb (s, CB_CARDBUS_BUS, s->cap.cardbus); |
| 411 | pci_writeb (s, CB_SUBORD_BUS, s->sub_bus); |
| 412 | pci_writew (s, CB_BRIDGE_CONTROL, s->bcr); |
| 413 | } |
| 414 | |
| 415 | static void cb_set_opts (socket_info_t * s) |
| 416 | { |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 417 | #ifndef CONFIG_CPC45 |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 418 | if (s->cache == 0) |
| 419 | s->cache = 8; |
| 420 | if (s->pci_lat == 0) |
| 421 | s->pci_lat = 0xa8; |
| 422 | if (s->cb_lat == 0) |
| 423 | s->cb_lat = 0xb0; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 424 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /*====================================================================== |
| 428 | |
| 429 | Power control for Cardbus controllers: used both for 16-bit and |
| 430 | Cardbus cards. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 431 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 432 | ======================================================================*/ |
| 433 | |
| 434 | static int cb_set_power (socket_info_t * s, socket_state_t * state) |
| 435 | { |
| 436 | u_int reg = 0; |
| 437 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 438 | #ifdef CONFIG_CPC45 |
| 439 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 440 | reg = I365_PWR_NORESET; |
| 441 | if (state->flags & SS_PWR_AUTO) |
| 442 | reg |= I365_PWR_AUTO; |
| 443 | if (state->flags & SS_OUTPUT_ENA) |
| 444 | reg |= I365_PWR_OUT; |
| 445 | if (state->Vpp != 0) { |
| 446 | if (state->Vpp == 120) { |
| 447 | reg |= I365_VPP1_12V; |
| 448 | puts (" 12V card found: "); |
| 449 | } else if (state->Vpp == state->Vcc) { |
| 450 | reg |= I365_VPP1_5V; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 451 | } else { |
| 452 | puts (" power not found: "); |
| 453 | return -1; |
| 454 | } |
| 455 | } |
| 456 | if (state->Vcc != 0) { |
| 457 | reg |= I365_VCC_5V; |
| 458 | if (state->Vcc == 33) { |
| 459 | puts (" 3.3V card found: "); |
| 460 | i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 461 | } else if (state->Vcc == 50) { |
| 462 | puts (" 5V card found: "); |
| 463 | i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 464 | } else { |
| 465 | puts (" power not found: "); |
| 466 | return -1; |
| 467 | } |
| 468 | } |
wdenk | b22532e | 2005-02-07 19:44:17 +0000 | [diff] [blame] | 469 | |
| 470 | if (reg != i365_get (s, I365_POWER)) { |
| 471 | reg = (I365_PWR_OUT | I365_PWR_NORESET | I365_VCC_5V | I365_VPP1_5V); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 472 | i365_set (s, I365_POWER, reg); |
wdenk | b22532e | 2005-02-07 19:44:17 +0000 | [diff] [blame] | 473 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 474 | |
| 475 | #else /* ! CONFIG_CPC45 */ |
| 476 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 477 | /* restart card voltage detection if it seems appropriate */ |
| 478 | if ((state->Vcc == 0) && (state->Vpp == 0) && |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 479 | !(cb_readl (s, CB_SOCKET_STATE) & CB_SS_VSENSE)) |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 480 | cb_writel (s, CB_SOCKET_FORCE, CB_SF_CVSTEST); |
| 481 | switch (state->Vcc) { |
| 482 | case 0: |
| 483 | reg = 0; |
| 484 | break; |
| 485 | case 33: |
| 486 | reg = CB_SC_VCC_3V; |
| 487 | break; |
| 488 | case 50: |
| 489 | reg = CB_SC_VCC_5V; |
| 490 | break; |
| 491 | default: |
| 492 | return -1; |
| 493 | } |
| 494 | switch (state->Vpp) { |
| 495 | case 0: |
| 496 | break; |
| 497 | case 33: |
| 498 | reg |= CB_SC_VPP_3V; |
| 499 | break; |
| 500 | case 50: |
| 501 | reg |= CB_SC_VPP_5V; |
| 502 | break; |
| 503 | case 120: |
| 504 | reg |= CB_SC_VPP_12V; |
| 505 | break; |
| 506 | default: |
| 507 | return -1; |
| 508 | } |
| 509 | if (reg != cb_readl (s, CB_SOCKET_CONTROL)) |
| 510 | cb_writel (s, CB_SOCKET_CONTROL, reg); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 511 | #endif /* CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /*====================================================================== |
| 516 | |
| 517 | Generic routines to get and set controller options |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 518 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 519 | ======================================================================*/ |
| 520 | |
| 521 | static void get_bridge_state (socket_info_t * s) |
| 522 | { |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 523 | #ifdef CONFIG_CPC45 |
| 524 | cirrus_get_state (s); |
| 525 | #else |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 526 | ti113x_get_state (s); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 527 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 528 | cb_get_state (s); |
| 529 | } |
| 530 | |
| 531 | static void set_bridge_state (socket_info_t * s) |
| 532 | { |
| 533 | cb_set_state (s); |
| 534 | i365_set (s, I365_GBLCTL, 0x00); |
| 535 | i365_set (s, I365_GENCTL, 0x00); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 536 | #ifdef CONFIG_CPC45 |
| 537 | cirrus_set_state (s); |
| 538 | #else |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 539 | ti113x_set_state (s); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 540 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static void set_bridge_opts (socket_info_t * s) |
| 544 | { |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 545 | #ifdef CONFIG_CPC45 |
| 546 | cirrus_set_opts (s); |
| 547 | #else |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 548 | ti113x_set_opts (s); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 549 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 550 | cb_set_opts (s); |
| 551 | } |
| 552 | |
| 553 | /*====================================================================*/ |
wdenk | b22532e | 2005-02-07 19:44:17 +0000 | [diff] [blame] | 554 | #define PD67_EXT_INDEX 0x2e /* Extension index */ |
| 555 | #define PD67_EXT_DATA 0x2f /* Extension data */ |
| 556 | #define PD67_EXD_VS1(s) (0x01 << ((s)<<1)) |
| 557 | |
| 558 | #define pd67_ext_get(s, r) \ |
| 559 | (i365_set(s, PD67_EXT_INDEX, r), i365_get(s, PD67_EXT_DATA)) |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 560 | |
| 561 | static int i365_get_status (socket_info_t * s, u_int * value) |
| 562 | { |
| 563 | u_int status; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 564 | #ifdef CONFIG_CPC45 |
| 565 | u_char val; |
| 566 | u_char power, vcc, vpp; |
wdenk | b22532e | 2005-02-07 19:44:17 +0000 | [diff] [blame] | 567 | u_int powerstate; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 568 | #endif |
| 569 | |
| 570 | status = i365_get (s, I365_IDENT); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 571 | status = i365_get (s, I365_STATUS); |
| 572 | *value = ((status & I365_CS_DETECT) == I365_CS_DETECT) ? SS_DETECT : 0; |
| 573 | if (i365_get (s, I365_INTCTL) & I365_PC_IOCARD) { |
| 574 | *value |= (status & I365_CS_STSCHG) ? 0 : SS_STSCHG; |
| 575 | } else { |
| 576 | *value |= (status & I365_CS_BVD1) ? 0 : SS_BATDEAD; |
| 577 | *value |= (status & I365_CS_BVD2) ? 0 : SS_BATWARN; |
| 578 | } |
| 579 | *value |= (status & I365_CS_WRPROT) ? SS_WRPROT : 0; |
| 580 | *value |= (status & I365_CS_READY) ? SS_READY : 0; |
| 581 | *value |= (status & I365_CS_POWERON) ? SS_POWERON : 0; |
| 582 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 583 | #ifdef CONFIG_CPC45 |
| 584 | /* Check for Cirrus CL-PD67xx chips */ |
| 585 | i365_set (s, PD67_CHIP_INFO, 0); |
| 586 | val = i365_get (s, PD67_CHIP_INFO); |
| 587 | s->type = -1; |
| 588 | if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) { |
| 589 | val = i365_get (s, PD67_CHIP_INFO); |
| 590 | if ((val & PD67_INFO_CHIP_ID) == 0) { |
wdenk | 525d7b6 | 2005-01-22 18:13:04 +0000 | [diff] [blame] | 591 | s->type = (val & PD67_INFO_SLOTS) ? IS_PD672X : IS_PD6710; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 592 | i365_set (s, PD67_EXT_INDEX, 0xe5); |
| 593 | if (i365_get (s, PD67_EXT_INDEX) != 0xe5) |
| 594 | s->type = IS_VT83C469; |
| 595 | } |
| 596 | } else { |
| 597 | printf ("no Cirrus Chip found\n"); |
| 598 | *value = 0; |
| 599 | return -1; |
| 600 | } |
| 601 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 602 | power = i365_get (s, I365_POWER); |
| 603 | state.flags |= (power & I365_PWR_AUTO) ? SS_PWR_AUTO : 0; |
| 604 | state.flags |= (power & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0; |
| 605 | vcc = power & I365_VCC_MASK; |
| 606 | vpp = power & I365_VPP1_MASK; |
| 607 | state.Vcc = state.Vpp = 0; |
wdenk | b22532e | 2005-02-07 19:44:17 +0000 | [diff] [blame] | 608 | if((vcc== 0) || (vpp == 0)) { |
| 609 | /* |
| 610 | * On the Cirrus we get the info which card voltage |
| 611 | * we have in EXTERN DATA and write it to MISC_CTL1 |
| 612 | */ |
| 613 | powerstate = pd67_ext_get(s, PD67_EXTERN_DATA); |
| 614 | if (powerstate & PD67_EXD_VS1(0)) { |
| 615 | /* 5V Card */ |
| 616 | i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 617 | } else { |
| 618 | /* 3.3V Card */ |
| 619 | i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 620 | } |
| 621 | i365_set (s, I365_POWER, (I365_PWR_OUT | I365_PWR_NORESET | I365_VCC_5V | I365_VPP1_5V)); |
| 622 | power = i365_get (s, I365_POWER); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 623 | } |
wdenk | b22532e | 2005-02-07 19:44:17 +0000 | [diff] [blame] | 624 | if (power & I365_VCC_5V) { |
| 625 | state.Vcc = (i365_get(s, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) ? 33 : 50; |
| 626 | } |
| 627 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 628 | if (power == I365_VPP1_12V) |
| 629 | state.Vpp = 120; |
| 630 | |
| 631 | /* IO card, RESET flags, IO interrupt */ |
| 632 | power = i365_get (s, I365_INTCTL); |
| 633 | state.flags |= (power & I365_PC_RESET) ? 0 : SS_RESET; |
| 634 | if (power & I365_PC_IOCARD) |
| 635 | state.flags |= SS_IOCARD; |
| 636 | state.io_irq = power & I365_IRQ_MASK; |
| 637 | |
| 638 | /* Card status change mask */ |
| 639 | power = i365_get (s, I365_CSCINT); |
| 640 | state.csc_mask = (power & I365_CSC_DETECT) ? SS_DETECT : 0; |
| 641 | if (state.flags & SS_IOCARD) |
| 642 | state.csc_mask |= (power & I365_CSC_STSCHG) ? SS_STSCHG : 0; |
| 643 | else { |
| 644 | state.csc_mask |= (power & I365_CSC_BVD1) ? SS_BATDEAD : 0; |
| 645 | state.csc_mask |= (power & I365_CSC_BVD2) ? SS_BATWARN : 0; |
| 646 | state.csc_mask |= (power & I365_CSC_READY) ? SS_READY : 0; |
| 647 | } |
| 648 | debug ("i82365: GetStatus(0) = flags %#3.3x, Vcc %d, Vpp %d, " |
| 649 | "io_irq %d, csc_mask %#2.2x\n", state.flags, |
| 650 | state.Vcc, state.Vpp, state.io_irq, state.csc_mask); |
| 651 | |
| 652 | #else /* !CONFIG_CPC45 */ |
| 653 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 654 | status = cb_readl (s, CB_SOCKET_STATE); |
| 655 | *value |= (status & CB_SS_32BIT) ? SS_CARDBUS : 0; |
| 656 | *value |= (status & CB_SS_3VCARD) ? SS_3VCARD : 0; |
| 657 | *value |= (status & CB_SS_XVCARD) ? SS_XVCARD : 0; |
| 658 | *value |= (status & CB_SS_VSENSE) ? 0 : SS_PENDING; |
| 659 | /* For now, ignore cards with unsupported voltage keys */ |
| 660 | if (*value & SS_XVCARD) |
| 661 | *value &= ~(SS_DETECT | SS_3VCARD | SS_XVCARD); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 662 | #endif /* CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 663 | return 0; |
| 664 | } /* i365_get_status */ |
| 665 | |
| 666 | static int i365_set_socket (socket_info_t * s, socket_state_t * state) |
| 667 | { |
| 668 | u_char reg; |
| 669 | |
| 670 | set_bridge_state (s); |
| 671 | |
| 672 | /* IO card, RESET flag */ |
| 673 | reg = 0; |
| 674 | reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET; |
| 675 | reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0; |
| 676 | i365_set (s, I365_INTCTL, reg); |
| 677 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 678 | #ifdef CONFIG_CPC45 |
| 679 | cb_set_power (s, state); |
| 680 | |
| 681 | #if 0 |
| 682 | /* Card status change interrupt mask */ |
| 683 | reg = s->cs_irq << 4; |
| 684 | if (state->csc_mask & SS_DETECT) |
| 685 | reg |= I365_CSC_DETECT; |
| 686 | if (state->flags & SS_IOCARD) { |
| 687 | if (state->csc_mask & SS_STSCHG) |
| 688 | reg |= I365_CSC_STSCHG; |
| 689 | } else { |
| 690 | if (state->csc_mask & SS_BATDEAD) |
| 691 | reg |= I365_CSC_BVD1; |
| 692 | if (state->csc_mask & SS_BATWARN) |
| 693 | reg |= I365_CSC_BVD2; |
| 694 | if (state->csc_mask & SS_READY) |
| 695 | reg |= I365_CSC_READY; |
| 696 | } |
| 697 | i365_set (s, I365_CSCINT, reg); |
| 698 | i365_get (s, I365_CSC); |
| 699 | #endif /* 0 */ |
| 700 | |
| 701 | #else /* !CONFIG_CPC45 */ |
| 702 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 703 | reg = I365_PWR_NORESET; |
| 704 | if (state->flags & SS_PWR_AUTO) |
| 705 | reg |= I365_PWR_AUTO; |
| 706 | if (state->flags & SS_OUTPUT_ENA) |
| 707 | reg |= I365_PWR_OUT; |
| 708 | |
| 709 | cb_set_power (s, state); |
| 710 | reg |= i365_get (s, I365_POWER) & (I365_VCC_MASK | I365_VPP1_MASK); |
| 711 | |
| 712 | if (reg != i365_get (s, I365_POWER)) |
| 713 | i365_set (s, I365_POWER, reg); |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 714 | #endif /* CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 715 | |
| 716 | return 0; |
| 717 | } /* i365_set_socket */ |
| 718 | |
| 719 | /*====================================================================*/ |
| 720 | |
| 721 | static int i365_set_mem_map (socket_info_t * s, struct pccard_mem_map *mem) |
| 722 | { |
| 723 | u_short base, i; |
| 724 | u_char map; |
| 725 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 726 | debug ("i82365: SetMemMap(%d, %#2.2x, %d ns, %#5.5lx-%#5.5lx, %#5.5x)\n", |
| 727 | mem->map, mem->flags, mem->speed, |
| 728 | mem->sys_start, mem->sys_stop, mem->card_start); |
| 729 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 730 | map = mem->map; |
| 731 | if ((map > 4) || |
| 732 | (mem->card_start > 0x3ffffff) || |
| 733 | (mem->sys_start > mem->sys_stop) || |
| 734 | (mem->speed > 1000)) { |
| 735 | return -1; |
| 736 | } |
| 737 | |
| 738 | /* Turn off the window before changing anything */ |
| 739 | if (i365_get (s, I365_ADDRWIN) & I365_ENA_MEM (map)) |
| 740 | i365_bclr (s, I365_ADDRWIN, I365_ENA_MEM (map)); |
| 741 | |
| 742 | /* Take care of high byte, for PCI controllers */ |
| 743 | i365_set (s, CB_MEM_PAGE (map), mem->sys_start >> 24); |
| 744 | |
| 745 | base = I365_MEM (map); |
| 746 | i = (mem->sys_start >> 12) & 0x0fff; |
| 747 | if (mem->flags & MAP_16BIT) |
| 748 | i |= I365_MEM_16BIT; |
| 749 | if (mem->flags & MAP_0WS) |
| 750 | i |= I365_MEM_0WS; |
| 751 | i365_set_pair (s, base + I365_W_START, i); |
| 752 | |
| 753 | i = (mem->sys_stop >> 12) & 0x0fff; |
| 754 | switch (mem->speed / CYCLE_TIME) { |
| 755 | case 0: |
| 756 | break; |
| 757 | case 1: |
| 758 | i |= I365_MEM_WS0; |
| 759 | break; |
| 760 | case 2: |
| 761 | i |= I365_MEM_WS1; |
| 762 | break; |
| 763 | default: |
| 764 | i |= I365_MEM_WS1 | I365_MEM_WS0; |
| 765 | break; |
| 766 | } |
| 767 | i365_set_pair (s, base + I365_W_STOP, i); |
| 768 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 769 | #ifdef CONFIG_CPC45 |
| 770 | i = 0; |
| 771 | #else |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 772 | i = ((mem->card_start - mem->sys_start) >> 12) & 0x3fff; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 773 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 774 | if (mem->flags & MAP_WRPROT) |
| 775 | i |= I365_MEM_WRPROT; |
| 776 | if (mem->flags & MAP_ATTRIB) |
| 777 | i |= I365_MEM_REG; |
| 778 | i365_set_pair (s, base + I365_W_OFF, i); |
| 779 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 780 | #ifdef CONFIG_CPC45 |
| 781 | /* set System Memory map Upper Adress */ |
| 782 | i365_set(s, PD67_EXT_INDEX, PD67_MEM_PAGE(map)); |
| 783 | i365_set(s, PD67_EXT_DATA, ((mem->sys_start >> 24) & 0xff)); |
| 784 | #endif |
| 785 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 786 | /* Turn on the window if necessary */ |
| 787 | if (mem->flags & MAP_ACTIVE) |
| 788 | i365_bset (s, I365_ADDRWIN, I365_ENA_MEM (map)); |
| 789 | return 0; |
| 790 | } /* i365_set_mem_map */ |
| 791 | |
| 792 | static int i365_set_io_map (socket_info_t * s, struct pccard_io_map *io) |
| 793 | { |
| 794 | u_char map, ioctl; |
| 795 | |
| 796 | map = io->map; |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 797 | /* comment out: comparison is always false due to limited range of data type */ |
| 798 | if ((map > 1) || /* (io->start > 0xffff) || (io->stop > 0xffff) || */ |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 799 | (io->stop < io->start)) |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 800 | return -1; |
| 801 | /* Turn off the window before changing anything */ |
| 802 | if (i365_get (s, I365_ADDRWIN) & I365_ENA_IO (map)) |
| 803 | i365_bclr (s, I365_ADDRWIN, I365_ENA_IO (map)); |
| 804 | i365_set_pair (s, I365_IO (map) + I365_W_START, io->start); |
| 805 | i365_set_pair (s, I365_IO (map) + I365_W_STOP, io->stop); |
| 806 | ioctl = i365_get (s, I365_IOCTL) & ~I365_IOCTL_MASK (map); |
| 807 | if (io->speed) |
| 808 | ioctl |= I365_IOCTL_WAIT (map); |
| 809 | if (io->flags & MAP_0WS) |
| 810 | ioctl |= I365_IOCTL_0WS (map); |
| 811 | if (io->flags & MAP_16BIT) |
| 812 | ioctl |= I365_IOCTL_16BIT (map); |
| 813 | if (io->flags & MAP_AUTOSZ) |
| 814 | ioctl |= I365_IOCTL_IOCS16 (map); |
| 815 | i365_set (s, I365_IOCTL, ioctl); |
| 816 | /* Turn on the window if necessary */ |
| 817 | if (io->flags & MAP_ACTIVE) |
| 818 | i365_bset (s, I365_ADDRWIN, I365_ENA_IO (map)); |
| 819 | return 0; |
| 820 | } /* i365_set_io_map */ |
| 821 | |
| 822 | /*====================================================================*/ |
| 823 | |
| 824 | int i82365_init (void) |
| 825 | { |
| 826 | u_int val; |
| 827 | int i; |
| 828 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 829 | #ifdef CONFIG_CPC45 |
| 830 | if (SPD67290Init () != 0) |
| 831 | return 1; |
| 832 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 833 | if ((socket.dev = pci_find_devices (supported, 0)) < 0) { |
| 834 | /* Controller not found */ |
| 835 | return 1; |
| 836 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 837 | debug ("i82365 Device Found!\n"); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 838 | |
| 839 | pci_read_config_dword (socket.dev, PCI_BASE_ADDRESS_0, &socket.cb_phys); |
| 840 | socket.cb_phys &= ~0xf; |
| 841 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 842 | #ifdef CONFIG_CPC45 |
| 843 | /* + 0xfe000000 see MPC 8245 Users Manual Adress Map B */ |
| 844 | socket.cb_phys += 0xfe000000; |
| 845 | #endif |
| 846 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 847 | get_bridge_state (&socket); |
| 848 | set_bridge_opts (&socket); |
| 849 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 850 | i = i365_get_status (&socket, &val); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 851 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 852 | #ifdef CONFIG_CPC45 |
| 853 | if (i > -1) { |
| 854 | puts (pcic[socket.type].name); |
| 855 | } else { |
| 856 | printf ("i82365: Controller not found.\n"); |
| 857 | return 1; |
| 858 | } |
wdenk | 8141446 | 2005-01-31 22:09:11 +0000 | [diff] [blame] | 859 | if((val & SS_DETECT) != SS_DETECT){ |
| 860 | puts ("No card\n"); |
| 861 | return 1; |
| 862 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 863 | #else /* !CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 864 | if (val & SS_DETECT) { |
| 865 | if (val & SS_3VCARD) { |
| 866 | state.Vcc = state.Vpp = 33; |
| 867 | puts (" 3.3V card found: "); |
| 868 | } else if (!(val & SS_XVCARD)) { |
| 869 | state.Vcc = state.Vpp = 50; |
| 870 | puts (" 5.0V card found: "); |
| 871 | } else { |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 872 | puts ("i82365: unsupported voltage key\n"); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 873 | state.Vcc = state.Vpp = 0; |
| 874 | } |
| 875 | } else { |
| 876 | /* No card inserted */ |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 877 | puts ("No card\n"); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 878 | return 1; |
| 879 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 880 | #endif /* CONFIG_CPC45 */ |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 881 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 882 | #ifdef CONFIG_CPC45 |
| 883 | state.flags |= SS_OUTPUT_ENA; |
| 884 | #else |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 885 | state.flags = SS_IOCARD | SS_OUTPUT_ENA; |
| 886 | state.csc_mask = 0; |
| 887 | state.io_irq = 0; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 888 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 889 | |
| 890 | i365_set_socket (&socket, &state); |
| 891 | |
| 892 | for (i = 500; i; i--) { |
| 893 | if ((i365_get (&socket, I365_STATUS) & I365_CS_READY)) |
| 894 | break; |
| 895 | udelay (1000); |
| 896 | } |
| 897 | |
| 898 | if (i == 0) { |
| 899 | /* PC Card not ready for data transfer */ |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 900 | puts ("i82365 PC Card not ready for data transfer\n"); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 901 | return 1; |
| 902 | } |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 903 | debug (" PC Card ready for data transfer: "); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 904 | |
| 905 | mem.map = 0; |
| 906 | mem.flags = MAP_ATTRIB | MAP_ACTIVE; |
| 907 | mem.speed = 300; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 908 | mem.sys_start = CONFIG_SYS_PCMCIA_MEM_ADDR; |
| 909 | mem.sys_stop = CONFIG_SYS_PCMCIA_MEM_ADDR + CONFIG_SYS_PCMCIA_MEM_SIZE - 1; |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 910 | mem.card_start = 0; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 911 | i365_set_mem_map (&socket, &mem); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 912 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 913 | #ifdef CONFIG_CPC45 |
| 914 | mem.map = 1; |
| 915 | mem.flags = MAP_ACTIVE; |
| 916 | mem.speed = 300; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 917 | mem.sys_start = CONFIG_SYS_PCMCIA_MEM_ADDR + CONFIG_SYS_PCMCIA_MEM_SIZE; |
| 918 | mem.sys_stop = CONFIG_SYS_PCMCIA_MEM_ADDR + (2 * CONFIG_SYS_PCMCIA_MEM_SIZE) - 1; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 919 | mem.card_start = 0; |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 920 | i365_set_mem_map (&socket, &mem); |
| 921 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 922 | #else /* !CONFIG_CPC45 */ |
| 923 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 924 | io.map = 0; |
| 925 | io.flags = MAP_AUTOSZ | MAP_ACTIVE; |
| 926 | io.speed = 0; |
| 927 | io.start = 0x0100; |
| 928 | io.stop = 0x010F; |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 929 | i365_set_io_map (&socket, &io); |
| 930 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 931 | #endif /* CONFIG_CPC45 */ |
| 932 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 933 | #ifdef DEBUG |
| 934 | i82365_dump_regions (socket.dev); |
| 935 | #endif |
| 936 | |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | void i82365_exit (void) |
| 941 | { |
| 942 | io.map = 0; |
| 943 | io.flags = 0; |
| 944 | io.speed = 0; |
| 945 | io.start = 0; |
| 946 | io.stop = 0x1; |
| 947 | |
| 948 | i365_set_io_map (&socket, &io); |
| 949 | |
| 950 | mem.map = 0; |
| 951 | mem.flags = 0; |
| 952 | mem.speed = 0; |
| 953 | mem.sys_start = 0; |
| 954 | mem.sys_stop = 0x1000; |
| 955 | mem.card_start = 0; |
| 956 | |
| 957 | i365_set_mem_map (&socket, &mem); |
| 958 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 959 | #ifdef CONFIG_CPC45 |
| 960 | mem.map = 1; |
| 961 | mem.flags = 0; |
| 962 | mem.speed = 0; |
| 963 | mem.sys_start = 0; |
| 964 | mem.sys_stop = 0x1000; |
| 965 | mem.card_start = 0; |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 966 | |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 967 | i365_set_mem_map (&socket, &mem); |
| 968 | #else /* !CONFIG_CPC45 */ |
| 969 | socket.state.sysctl &= 0xFFFF00FF; |
| 970 | #endif |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 971 | state.Vcc = state.Vpp = 0; |
| 972 | |
| 973 | i365_set_socket (&socket, &state); |
| 974 | } |
| 975 | |
| 976 | /*====================================================================== |
| 977 | |
| 978 | Debug stuff |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 979 | |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 980 | ======================================================================*/ |
| 981 | |
| 982 | #ifdef DEBUG |
| 983 | static void i82365_dump_regions (pci_dev_t dev) |
| 984 | { |
| 985 | u_int tmp[2]; |
wdenk | 54070ab | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 986 | u_int *mem = (void *) socket.cb_phys; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 987 | u_char *cis = (void *) CONFIG_SYS_PCMCIA_MEM_ADDR; |
| 988 | u_char *ide = (void *) (CONFIG_SYS_ATA_BASE_ADDR + CONFIG_SYS_ATA_REG_OFFSET); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 989 | |
| 990 | pci_read_config_dword (dev, 0x00, tmp + 0); |
| 991 | pci_read_config_dword (dev, 0x80, tmp + 1); |
| 992 | |
wdenk | 525d7b6 | 2005-01-22 18:13:04 +0000 | [diff] [blame] | 993 | printf ("PCI CONF: %08X ... %08X\n", |
| 994 | tmp[0], tmp[1]); |
| 995 | printf ("PCI MEM: ... %08X ... %08X\n", |
| 996 | mem[0x8 / 4], mem[0x800 / 4]); |
wdenk | e5d61c7 | 2003-05-18 11:30:09 +0000 | [diff] [blame] | 997 | printf ("CIS: ...%c%c%c%c%c%c%c%c...\n", |
| 998 | cis[0x38], cis[0x3a], cis[0x3c], cis[0x3e], |
| 999 | cis[0x40], cis[0x42], cis[0x44], cis[0x48]); |
| 1000 | printf ("CIS CONF: %02X %02X %02X ...\n", |
| 1001 | cis[0x200], cis[0x202], cis[0x204]); |
| 1002 | printf ("IDE: %02X %02X %02X %02X %02X %02X %02X %02X\n", |
| 1003 | ide[0], ide[1], ide[2], ide[3], |
| 1004 | ide[4], ide[5], ide[6], ide[7]); |
| 1005 | } |
| 1006 | #endif /* DEBUG */ |