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