Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003-2005 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 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> |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #include <common.h> |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 33 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 34 | #ifdef CONFIG_I82365 |
| 35 | |
| 36 | #include <command.h> |
| 37 | #include <pci.h> |
| 38 | #include <pcmcia.h> |
| 39 | #include <asm/io.h> |
| 40 | |
| 41 | #include <pcmcia/ss.h> |
| 42 | #include <pcmcia/i82365.h> |
| 43 | #include <pcmcia/yenta.h> |
| 44 | #include <pcmcia/cirrus.h> |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 45 | |
| 46 | static struct pci_device_id supported[] = { |
| 47 | {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6729}, |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 48 | {0, 0} |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 51 | #define CYCLE_TIME 120 |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 52 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 53 | #ifdef DEBUG |
| 54 | static void i82365_dump_regions (pci_dev_t dev); |
| 55 | #endif |
| 56 | |
| 57 | typedef struct socket_info_t { |
| 58 | pci_dev_t dev; |
| 59 | u_short bcr; |
| 60 | u_char pci_lat, cb_lat, sub_bus, cache; |
| 61 | u_int cb_phys; |
| 62 | |
| 63 | socket_cap_t cap; |
| 64 | u_short type; |
| 65 | u_int flags; |
| 66 | cirrus_state_t c_state; |
| 67 | } socket_info_t; |
| 68 | |
| 69 | /* These definitions must match the pcic table! */ |
| 70 | typedef enum pcic_id { |
| 71 | IS_PD6710, IS_PD672X, IS_VT83C469 |
| 72 | } pcic_id; |
| 73 | |
| 74 | typedef struct pcic_t { |
| 75 | char *name; |
| 76 | } pcic_t; |
| 77 | |
| 78 | static pcic_t pcic[] = { |
| 79 | {" Cirrus PD6710: "}, |
| 80 | {" Cirrus PD672x: "}, |
| 81 | {" VIA VT83C469: "}, |
| 82 | }; |
| 83 | |
| 84 | static socket_info_t socket; |
| 85 | static socket_state_t state; |
| 86 | static struct pccard_mem_map mem; |
| 87 | static struct pccard_io_map io; |
| 88 | |
| 89 | /*====================================================================*/ |
| 90 | |
| 91 | /* Some PCI shortcuts */ |
| 92 | |
| 93 | static int pci_readb (socket_info_t * s, int r, u_char * v) |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 94 | { |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 95 | return pci_read_config_byte (s->dev, r, v); |
| 96 | } |
| 97 | static int pci_writeb (socket_info_t * s, int r, u_char v) |
| 98 | { |
| 99 | return pci_write_config_byte (s->dev, r, v); |
| 100 | } |
| 101 | static int pci_readw (socket_info_t * s, int r, u_short * v) |
| 102 | { |
| 103 | return pci_read_config_word (s->dev, r, v); |
| 104 | } |
| 105 | static int pci_writew (socket_info_t * s, int r, u_short v) |
| 106 | { |
| 107 | return pci_write_config_word (s->dev, r, v); |
| 108 | } |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 109 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 110 | /*====================================================================*/ |
| 111 | |
| 112 | #define cb_readb(s) readb((s)->cb_phys + 1) |
| 113 | #define cb_writeb(s, v) writeb(v, (s)->cb_phys) |
| 114 | #define cb_writeb2(s, v) writeb(v, (s)->cb_phys + 1) |
| 115 | #define cb_readl(s, r) readl((s)->cb_phys + (r)) |
| 116 | #define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r)) |
| 117 | |
| 118 | |
| 119 | static u_char i365_get (socket_info_t * s, u_short reg) |
| 120 | { |
| 121 | u_char val; |
| 122 | #ifdef CONFIG_PCMCIA_SLOT_A |
| 123 | int slot = 0; |
| 124 | #else |
| 125 | int slot = 1; |
| 126 | #endif |
| 127 | |
| 128 | val = I365_REG (slot, reg); |
| 129 | |
| 130 | cb_writeb (s, val); |
| 131 | val = cb_readb (s); |
| 132 | |
| 133 | debug ("i365_get slot:%x reg: %x val: %x\n", slot, reg, val); |
| 134 | return val; |
| 135 | } |
| 136 | |
| 137 | static void i365_set (socket_info_t * s, u_short reg, u_char data) |
| 138 | { |
| 139 | #ifdef CONFIG_PCMCIA_SLOT_A |
| 140 | int slot = 0; |
| 141 | #else |
| 142 | int slot = 1; |
| 143 | #endif |
| 144 | u_char val; |
| 145 | |
| 146 | val = I365_REG (slot, reg); |
| 147 | |
| 148 | cb_writeb (s, val); |
| 149 | cb_writeb2 (s, data); |
| 150 | |
| 151 | debug ("i365_set slot:%x reg: %x data:%x\n", slot, reg, data); |
| 152 | } |
| 153 | |
| 154 | static void i365_bset (socket_info_t * s, u_short reg, u_char mask) |
| 155 | { |
| 156 | i365_set (s, reg, i365_get (s, reg) | mask); |
| 157 | } |
| 158 | |
| 159 | static void i365_bclr (socket_info_t * s, u_short reg, u_char mask) |
| 160 | { |
| 161 | i365_set (s, reg, i365_get (s, reg) & ~mask); |
| 162 | } |
| 163 | |
| 164 | #if 0 /* not used */ |
| 165 | static void i365_bflip (socket_info_t * s, u_short reg, u_char mask, int b) |
| 166 | { |
| 167 | u_char d = i365_get (s, reg); |
| 168 | |
| 169 | i365_set (s, reg, (b) ? (d | mask) : (d & ~mask)); |
| 170 | } |
| 171 | |
| 172 | static u_short i365_get_pair (socket_info_t * s, u_short reg) |
| 173 | { |
| 174 | return (i365_get (s, reg) + (i365_get (s, reg + 1) << 8)); |
| 175 | } |
| 176 | #endif /* not used */ |
| 177 | |
| 178 | static void i365_set_pair (socket_info_t * s, u_short reg, u_short data) |
| 179 | { |
| 180 | i365_set (s, reg, data & 0xff); |
| 181 | i365_set (s, reg + 1, data >> 8); |
| 182 | } |
| 183 | |
| 184 | /*====================================================================== |
| 185 | |
| 186 | Code to save and restore global state information for Cirrus |
| 187 | PD67xx controllers, and to set and report global configuration |
| 188 | options. |
| 189 | |
| 190 | ======================================================================*/ |
| 191 | |
| 192 | #define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b)))) |
| 193 | |
| 194 | static void cirrus_get_state (socket_info_t * s) |
| 195 | { |
| 196 | int i; |
| 197 | cirrus_state_t *p = &s->c_state; |
| 198 | |
| 199 | p->misc1 = i365_get (s, PD67_MISC_CTL_1); |
| 200 | p->misc1 &= (PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA); |
| 201 | p->misc2 = i365_get (s, PD67_MISC_CTL_2); |
| 202 | for (i = 0; i < 6; i++) |
| 203 | p->timer[i] = i365_get (s, PD67_TIME_SETUP (0) + i); |
| 204 | |
| 205 | } |
| 206 | |
| 207 | static void cirrus_set_state (socket_info_t * s) |
| 208 | { |
| 209 | int i; |
| 210 | u_char misc; |
| 211 | cirrus_state_t *p = &s->c_state; |
| 212 | |
| 213 | misc = i365_get (s, PD67_MISC_CTL_2); |
| 214 | i365_set (s, PD67_MISC_CTL_2, p->misc2); |
| 215 | if (misc & PD67_MC2_SUSPEND) |
| 216 | udelay (50000); |
| 217 | misc = i365_get (s, PD67_MISC_CTL_1); |
| 218 | misc &= ~(PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA); |
| 219 | i365_set (s, PD67_MISC_CTL_1, misc | p->misc1); |
| 220 | for (i = 0; i < 6; i++) |
| 221 | i365_set (s, PD67_TIME_SETUP (0) + i, p->timer[i]); |
| 222 | } |
| 223 | |
| 224 | static u_int cirrus_set_opts (socket_info_t * s) |
| 225 | { |
| 226 | cirrus_state_t *p = &s->c_state; |
| 227 | u_int mask = 0xffff; |
Marek Vasut | 17f5f1e | 2011-10-21 14:17:31 +0000 | [diff] [blame] | 228 | char buf[200] = {0}; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 229 | |
| 230 | if (has_ring == -1) |
| 231 | has_ring = 1; |
| 232 | flip (p->misc2, PD67_MC2_IRQ15_RI, has_ring); |
| 233 | flip (p->misc2, PD67_MC2_DYNAMIC_MODE, dynamic_mode); |
| 234 | #if DEBUG |
| 235 | if (p->misc2 & PD67_MC2_IRQ15_RI) |
| 236 | strcat (buf, " [ring]"); |
| 237 | if (p->misc2 & PD67_MC2_DYNAMIC_MODE) |
| 238 | strcat (buf, " [dyn mode]"); |
| 239 | if (p->misc1 & PD67_MC1_INPACK_ENA) |
| 240 | strcat (buf, " [inpack]"); |
| 241 | #endif |
| 242 | |
| 243 | if (p->misc2 & PD67_MC2_IRQ15_RI) |
| 244 | mask &= ~0x8000; |
| 245 | if (has_led > 0) { |
| 246 | #if DEBUG |
| 247 | strcat (buf, " [led]"); |
| 248 | #endif |
| 249 | mask &= ~0x1000; |
| 250 | } |
| 251 | if (has_dma > 0) { |
| 252 | #if DEBUG |
| 253 | strcat (buf, " [dma]"); |
| 254 | #endif |
| 255 | mask &= ~0x0600; |
| 256 | flip (p->misc2, PD67_MC2_FREQ_BYPASS, freq_bypass); |
| 257 | #if DEBUG |
| 258 | if (p->misc2 & PD67_MC2_FREQ_BYPASS) |
| 259 | strcat (buf, " [freq bypass]"); |
| 260 | #endif |
| 261 | } |
| 262 | |
| 263 | if (setup_time >= 0) |
| 264 | p->timer[0] = p->timer[3] = setup_time; |
| 265 | if (cmd_time > 0) { |
| 266 | p->timer[1] = cmd_time; |
| 267 | p->timer[4] = cmd_time * 2 + 4; |
| 268 | } |
| 269 | if (p->timer[1] == 0) { |
| 270 | p->timer[1] = 6; |
| 271 | p->timer[4] = 16; |
| 272 | if (p->timer[0] == 0) |
| 273 | p->timer[0] = p->timer[3] = 1; |
| 274 | } |
| 275 | if (recov_time >= 0) |
| 276 | p->timer[2] = p->timer[5] = recov_time; |
| 277 | |
| 278 | debug ("i82365 Opt: %s [%d/%d/%d] [%d/%d/%d]\n", |
| 279 | buf, |
| 280 | p->timer[0], p->timer[1], p->timer[2], |
| 281 | p->timer[3], p->timer[4], p->timer[5]); |
| 282 | |
| 283 | return mask; |
| 284 | } |
| 285 | |
| 286 | /*====================================================================== |
| 287 | |
| 288 | Routines to handle common CardBus options |
| 289 | |
| 290 | ======================================================================*/ |
| 291 | |
| 292 | /* Default settings for PCI command configuration register */ |
| 293 | #define CMD_DFLT (PCI_COMMAND_IO|PCI_COMMAND_MEMORY| \ |
| 294 | PCI_COMMAND_MASTER|PCI_COMMAND_WAIT) |
| 295 | |
| 296 | static void cb_get_state (socket_info_t * s) |
| 297 | { |
| 298 | pci_readb (s, PCI_CACHE_LINE_SIZE, &s->cache); |
| 299 | pci_readb (s, PCI_LATENCY_TIMER, &s->pci_lat); |
| 300 | pci_readb (s, CB_LATENCY_TIMER, &s->cb_lat); |
| 301 | pci_readb (s, CB_CARDBUS_BUS, &s->cap.cardbus); |
| 302 | pci_readb (s, CB_SUBORD_BUS, &s->sub_bus); |
| 303 | pci_readw (s, CB_BRIDGE_CONTROL, &s->bcr); |
| 304 | } |
| 305 | |
| 306 | static void cb_set_state (socket_info_t * s) |
| 307 | { |
| 308 | pci_writew (s, PCI_COMMAND, CMD_DFLT); |
| 309 | pci_writeb (s, PCI_CACHE_LINE_SIZE, s->cache); |
| 310 | pci_writeb (s, PCI_LATENCY_TIMER, s->pci_lat); |
| 311 | pci_writeb (s, CB_LATENCY_TIMER, s->cb_lat); |
| 312 | pci_writeb (s, CB_CARDBUS_BUS, s->cap.cardbus); |
| 313 | pci_writeb (s, CB_SUBORD_BUS, s->sub_bus); |
| 314 | pci_writew (s, CB_BRIDGE_CONTROL, s->bcr); |
| 315 | } |
| 316 | |
| 317 | static void cb_set_opts (socket_info_t * s) |
| 318 | { |
| 319 | } |
| 320 | |
| 321 | /*====================================================================== |
| 322 | |
| 323 | Power control for Cardbus controllers: used both for 16-bit and |
| 324 | Cardbus cards. |
| 325 | |
| 326 | ======================================================================*/ |
| 327 | |
| 328 | static int cb_set_power (socket_info_t * s, socket_state_t * state) |
| 329 | { |
| 330 | u_int reg = 0; |
| 331 | |
| 332 | reg = I365_PWR_NORESET; |
| 333 | if (state->flags & SS_PWR_AUTO) |
| 334 | reg |= I365_PWR_AUTO; |
| 335 | if (state->flags & SS_OUTPUT_ENA) |
| 336 | reg |= I365_PWR_OUT; |
| 337 | if (state->Vpp != 0) { |
| 338 | if (state->Vpp == 120) { |
| 339 | reg |= I365_VPP1_12V; |
| 340 | puts (" 12V card found: "); |
| 341 | } else if (state->Vpp == state->Vcc) { |
| 342 | reg |= I365_VPP1_5V; |
| 343 | } else { |
| 344 | puts (" power not found: "); |
| 345 | return -1; |
| 346 | } |
| 347 | } |
| 348 | if (state->Vcc != 0) { |
| 349 | reg |= I365_VCC_5V; |
| 350 | if (state->Vcc == 33) { |
| 351 | puts (" 3.3V card found: "); |
| 352 | i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 353 | } else if (state->Vcc == 50) { |
| 354 | puts (" 5V card found: "); |
| 355 | i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 356 | } else { |
| 357 | puts (" power not found: "); |
| 358 | return -1; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if (reg != i365_get (s, I365_POWER)) { |
| 363 | reg = (I365_PWR_OUT | I365_PWR_NORESET | I365_VCC_5V | I365_VPP1_5V); |
| 364 | i365_set (s, I365_POWER, reg); |
| 365 | } |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | /*====================================================================== |
| 371 | |
| 372 | Generic routines to get and set controller options |
| 373 | |
| 374 | ======================================================================*/ |
| 375 | |
| 376 | static void get_bridge_state (socket_info_t * s) |
| 377 | { |
| 378 | cirrus_get_state (s); |
| 379 | cb_get_state (s); |
| 380 | } |
| 381 | |
| 382 | static void set_bridge_state (socket_info_t * s) |
| 383 | { |
| 384 | cb_set_state (s); |
| 385 | i365_set (s, I365_GBLCTL, 0x00); |
| 386 | i365_set (s, I365_GENCTL, 0x00); |
| 387 | cirrus_set_state (s); |
| 388 | } |
| 389 | |
| 390 | static void set_bridge_opts (socket_info_t * s) |
| 391 | { |
| 392 | cirrus_set_opts (s); |
| 393 | cb_set_opts (s); |
| 394 | } |
| 395 | |
| 396 | /*====================================================================*/ |
| 397 | #define PD67_EXT_INDEX 0x2e /* Extension index */ |
| 398 | #define PD67_EXT_DATA 0x2f /* Extension data */ |
| 399 | #define PD67_EXD_VS1(s) (0x01 << ((s)<<1)) |
| 400 | |
| 401 | #define pd67_ext_get(s, r) \ |
| 402 | (i365_set(s, PD67_EXT_INDEX, r), i365_get(s, PD67_EXT_DATA)) |
| 403 | |
| 404 | static int i365_get_status (socket_info_t * s, u_int * value) |
| 405 | { |
| 406 | u_int status; |
| 407 | u_char val; |
| 408 | u_char power, vcc, vpp; |
| 409 | u_int powerstate; |
| 410 | |
| 411 | status = i365_get (s, I365_IDENT); |
| 412 | status = i365_get (s, I365_STATUS); |
| 413 | *value = ((status & I365_CS_DETECT) == I365_CS_DETECT) ? SS_DETECT : 0; |
| 414 | if (i365_get (s, I365_INTCTL) & I365_PC_IOCARD) { |
| 415 | *value |= (status & I365_CS_STSCHG) ? 0 : SS_STSCHG; |
| 416 | } else { |
| 417 | *value |= (status & I365_CS_BVD1) ? 0 : SS_BATDEAD; |
| 418 | *value |= (status & I365_CS_BVD2) ? 0 : SS_BATWARN; |
| 419 | } |
| 420 | *value |= (status & I365_CS_WRPROT) ? SS_WRPROT : 0; |
| 421 | *value |= (status & I365_CS_READY) ? SS_READY : 0; |
| 422 | *value |= (status & I365_CS_POWERON) ? SS_POWERON : 0; |
| 423 | |
| 424 | /* Check for Cirrus CL-PD67xx chips */ |
| 425 | i365_set (s, PD67_CHIP_INFO, 0); |
| 426 | val = i365_get (s, PD67_CHIP_INFO); |
| 427 | s->type = -1; |
| 428 | if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) { |
| 429 | val = i365_get (s, PD67_CHIP_INFO); |
| 430 | if ((val & PD67_INFO_CHIP_ID) == 0) { |
| 431 | s->type = (val & PD67_INFO_SLOTS) ? IS_PD672X : IS_PD6710; |
| 432 | i365_set (s, PD67_EXT_INDEX, 0xe5); |
| 433 | if (i365_get (s, PD67_EXT_INDEX) != 0xe5) |
| 434 | s->type = IS_VT83C469; |
| 435 | } |
| 436 | } else { |
| 437 | printf ("no Cirrus Chip found\n"); |
| 438 | *value = 0; |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 439 | return -1; |
| 440 | } |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 441 | |
| 442 | power = i365_get (s, I365_POWER); |
| 443 | state.flags |= (power & I365_PWR_AUTO) ? SS_PWR_AUTO : 0; |
| 444 | state.flags |= (power & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0; |
| 445 | vcc = power & I365_VCC_MASK; |
| 446 | vpp = power & I365_VPP1_MASK; |
| 447 | state.Vcc = state.Vpp = 0; |
| 448 | if((vcc== 0) || (vpp == 0)) { |
| 449 | /* |
| 450 | * On the Cirrus we get the info which card voltage |
| 451 | * we have in EXTERN DATA and write it to MISC_CTL1 |
| 452 | */ |
| 453 | powerstate = pd67_ext_get(s, PD67_EXTERN_DATA); |
| 454 | if (powerstate & PD67_EXD_VS1(0)) { |
| 455 | /* 5V Card */ |
| 456 | i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 457 | } else { |
| 458 | /* 3.3V Card */ |
| 459 | i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V); |
| 460 | } |
| 461 | i365_set (s, I365_POWER, (I365_PWR_OUT | I365_PWR_NORESET | I365_VCC_5V | I365_VPP1_5V)); |
| 462 | power = i365_get (s, I365_POWER); |
| 463 | } |
| 464 | if (power & I365_VCC_5V) { |
| 465 | state.Vcc = (i365_get(s, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) ? 33 : 50; |
| 466 | } |
| 467 | |
| 468 | if (power == I365_VPP1_12V) |
| 469 | state.Vpp = 120; |
| 470 | |
| 471 | /* IO card, RESET flags, IO interrupt */ |
| 472 | power = i365_get (s, I365_INTCTL); |
| 473 | state.flags |= (power & I365_PC_RESET) ? 0 : SS_RESET; |
| 474 | if (power & I365_PC_IOCARD) |
| 475 | state.flags |= SS_IOCARD; |
| 476 | state.io_irq = power & I365_IRQ_MASK; |
| 477 | |
| 478 | /* Card status change mask */ |
| 479 | power = i365_get (s, I365_CSCINT); |
| 480 | state.csc_mask = (power & I365_CSC_DETECT) ? SS_DETECT : 0; |
| 481 | if (state.flags & SS_IOCARD) |
| 482 | state.csc_mask |= (power & I365_CSC_STSCHG) ? SS_STSCHG : 0; |
| 483 | else { |
| 484 | state.csc_mask |= (power & I365_CSC_BVD1) ? SS_BATDEAD : 0; |
| 485 | state.csc_mask |= (power & I365_CSC_BVD2) ? SS_BATWARN : 0; |
| 486 | state.csc_mask |= (power & I365_CSC_READY) ? SS_READY : 0; |
| 487 | } |
| 488 | debug ("i82365: GetStatus(0) = flags %#3.3x, Vcc %d, Vpp %d, " |
| 489 | "io_irq %d, csc_mask %#2.2x\n", state.flags, |
| 490 | state.Vcc, state.Vpp, state.io_irq, state.csc_mask); |
| 491 | |
| 492 | return 0; |
| 493 | } /* i365_get_status */ |
| 494 | |
| 495 | static int i365_set_socket (socket_info_t * s, socket_state_t * state) |
| 496 | { |
| 497 | u_char reg; |
| 498 | |
| 499 | set_bridge_state (s); |
| 500 | |
| 501 | /* IO card, RESET flag */ |
| 502 | reg = 0; |
| 503 | reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET; |
| 504 | reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0; |
| 505 | i365_set (s, I365_INTCTL, reg); |
| 506 | |
| 507 | cb_set_power (s, state); |
| 508 | |
| 509 | #if 0 |
| 510 | /* Card status change interrupt mask */ |
| 511 | reg = s->cs_irq << 4; |
| 512 | if (state->csc_mask & SS_DETECT) |
| 513 | reg |= I365_CSC_DETECT; |
| 514 | if (state->flags & SS_IOCARD) { |
| 515 | if (state->csc_mask & SS_STSCHG) |
| 516 | reg |= I365_CSC_STSCHG; |
| 517 | } else { |
| 518 | if (state->csc_mask & SS_BATDEAD) |
| 519 | reg |= I365_CSC_BVD1; |
| 520 | if (state->csc_mask & SS_BATWARN) |
| 521 | reg |= I365_CSC_BVD2; |
| 522 | if (state->csc_mask & SS_READY) |
| 523 | reg |= I365_CSC_READY; |
| 524 | } |
| 525 | i365_set (s, I365_CSCINT, reg); |
| 526 | i365_get (s, I365_CSC); |
| 527 | #endif /* 0 */ |
| 528 | |
| 529 | return 0; |
| 530 | } /* i365_set_socket */ |
| 531 | |
| 532 | /*====================================================================*/ |
| 533 | |
| 534 | static int i365_set_mem_map (socket_info_t * s, struct pccard_mem_map *mem) |
| 535 | { |
| 536 | u_short base, i; |
| 537 | u_char map; |
| 538 | |
| 539 | debug ("i82365: SetMemMap(%d, %#2.2x, %d ns, %#5.5lx-%#5.5lx, %#5.5x)\n", |
| 540 | mem->map, mem->flags, mem->speed, |
| 541 | mem->sys_start, mem->sys_stop, mem->card_start); |
| 542 | |
| 543 | map = mem->map; |
| 544 | if ((map > 4) || |
| 545 | (mem->card_start > 0x3ffffff) || |
| 546 | (mem->sys_start > mem->sys_stop) || |
| 547 | (mem->speed > 1000)) { |
| 548 | return -1; |
| 549 | } |
| 550 | |
| 551 | /* Turn off the window before changing anything */ |
| 552 | if (i365_get (s, I365_ADDRWIN) & I365_ENA_MEM (map)) |
| 553 | i365_bclr (s, I365_ADDRWIN, I365_ENA_MEM (map)); |
| 554 | |
| 555 | /* Take care of high byte, for PCI controllers */ |
| 556 | i365_set (s, CB_MEM_PAGE (map), mem->sys_start >> 24); |
| 557 | |
| 558 | base = I365_MEM (map); |
| 559 | i = (mem->sys_start >> 12) & 0x0fff; |
| 560 | if (mem->flags & MAP_16BIT) |
| 561 | i |= I365_MEM_16BIT; |
| 562 | if (mem->flags & MAP_0WS) |
| 563 | i |= I365_MEM_0WS; |
| 564 | i365_set_pair (s, base + I365_W_START, i); |
| 565 | |
| 566 | i = (mem->sys_stop >> 12) & 0x0fff; |
| 567 | switch (mem->speed / CYCLE_TIME) { |
| 568 | case 0: |
| 569 | break; |
| 570 | case 1: |
| 571 | i |= I365_MEM_WS0; |
| 572 | break; |
| 573 | case 2: |
| 574 | i |= I365_MEM_WS1; |
| 575 | break; |
| 576 | default: |
| 577 | i |= I365_MEM_WS1 | I365_MEM_WS0; |
| 578 | break; |
| 579 | } |
| 580 | i365_set_pair (s, base + I365_W_STOP, i); |
| 581 | |
| 582 | i = 0; |
| 583 | if (mem->flags & MAP_WRPROT) |
| 584 | i |= I365_MEM_WRPROT; |
| 585 | if (mem->flags & MAP_ATTRIB) |
| 586 | i |= I365_MEM_REG; |
| 587 | i365_set_pair (s, base + I365_W_OFF, i); |
| 588 | |
| 589 | /* set System Memory map Upper Adress */ |
| 590 | i365_set(s, PD67_EXT_INDEX, PD67_MEM_PAGE(map)); |
| 591 | i365_set(s, PD67_EXT_DATA, ((mem->sys_start >> 24) & 0xff)); |
| 592 | |
| 593 | /* Turn on the window if necessary */ |
| 594 | if (mem->flags & MAP_ACTIVE) |
| 595 | i365_bset (s, I365_ADDRWIN, I365_ENA_MEM (map)); |
| 596 | return 0; |
| 597 | } /* i365_set_mem_map */ |
| 598 | |
| 599 | static int i365_set_io_map (socket_info_t * s, struct pccard_io_map *io) |
| 600 | { |
| 601 | u_char map, ioctl; |
| 602 | |
| 603 | map = io->map; |
| 604 | /* comment out: comparison is always false due to limited range of data type */ |
| 605 | if ((map > 1) || /* (io->start > 0xffff) || (io->stop > 0xffff) || */ |
| 606 | (io->stop < io->start)) |
| 607 | return -1; |
| 608 | /* Turn off the window before changing anything */ |
| 609 | if (i365_get (s, I365_ADDRWIN) & I365_ENA_IO (map)) |
| 610 | i365_bclr (s, I365_ADDRWIN, I365_ENA_IO (map)); |
| 611 | i365_set_pair (s, I365_IO (map) + I365_W_START, io->start); |
| 612 | i365_set_pair (s, I365_IO (map) + I365_W_STOP, io->stop); |
| 613 | ioctl = i365_get (s, I365_IOCTL) & ~I365_IOCTL_MASK (map); |
| 614 | if (io->speed) |
| 615 | ioctl |= I365_IOCTL_WAIT (map); |
| 616 | if (io->flags & MAP_0WS) |
| 617 | ioctl |= I365_IOCTL_0WS (map); |
| 618 | if (io->flags & MAP_16BIT) |
| 619 | ioctl |= I365_IOCTL_16BIT (map); |
| 620 | if (io->flags & MAP_AUTOSZ) |
| 621 | ioctl |= I365_IOCTL_IOCS16 (map); |
| 622 | i365_set (s, I365_IOCTL, ioctl); |
| 623 | /* Turn on the window if necessary */ |
| 624 | if (io->flags & MAP_ACTIVE) |
| 625 | i365_bset (s, I365_ADDRWIN, I365_ENA_IO (map)); |
| 626 | return 0; |
| 627 | } /* i365_set_io_map */ |
| 628 | |
| 629 | /*====================================================================*/ |
| 630 | |
| 631 | /* |
| 632 | * PCI_ADDR = (HOST_ADDR - 0xfe000000) |
| 633 | * see MPC 8245 Users Manual Adress Map B |
| 634 | */ |
| 635 | #define HOST_TO_PCI(addr) ((addr) - 0xfe000000) |
| 636 | #define PCI_TO_HOST(addr) ((addr) + 0xfe000000) |
| 637 | |
Wolfgang Denk | de550d6 | 2010-11-23 23:48:56 +0100 | [diff] [blame] | 638 | static int i82365_init (void) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 639 | { |
| 640 | u_int val; |
| 641 | int i; |
| 642 | |
| 643 | if ((socket.dev = pci_find_devices (supported, 0)) < 0) { |
| 644 | /* Controller not found */ |
| 645 | printf ("No PD67290 device found !!\n"); |
| 646 | return 1; |
| 647 | } |
| 648 | debug ("i82365 Device Found!\n"); |
| 649 | |
| 650 | socket.cb_phys = PCMCIA_IO_BASE; |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 651 | |
| 652 | /* set base address */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 653 | pci_write_config_dword (socket.dev, PCI_BASE_ADDRESS_0, |
| 654 | HOST_TO_PCI(socket.cb_phys)); |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 655 | |
| 656 | /* enable mapped memory and IO addresses */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 657 | pci_write_config_dword (socket.dev, |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 658 | PCI_COMMAND, |
| 659 | PCI_COMMAND_MEMORY | |
| 660 | PCI_COMMAND_IO | PCI_COMMAND_WAIT); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 661 | |
| 662 | get_bridge_state (&socket); |
| 663 | set_bridge_opts (&socket); |
| 664 | |
| 665 | i = i365_get_status (&socket, &val); |
| 666 | |
| 667 | if (i > -1) { |
| 668 | puts (pcic[socket.type].name); |
| 669 | } else { |
| 670 | printf ("i82365: Controller not found.\n"); |
| 671 | return 1; |
| 672 | } |
| 673 | if((val & SS_DETECT) != SS_DETECT){ |
| 674 | puts ("No card\n"); |
| 675 | return 1; |
| 676 | } |
| 677 | |
| 678 | state.flags |= SS_OUTPUT_ENA; |
| 679 | |
| 680 | i365_set_socket (&socket, &state); |
| 681 | |
| 682 | for (i = 500; i; i--) { |
| 683 | if ((i365_get (&socket, I365_STATUS) & I365_CS_READY)) |
| 684 | break; |
| 685 | udelay (1000); |
| 686 | } |
| 687 | |
| 688 | if (i == 0) { |
| 689 | /* PC Card not ready for data transfer */ |
| 690 | puts ("i82365 PC Card not ready for data transfer\n"); |
| 691 | return 1; |
| 692 | } |
| 693 | debug (" PC Card ready for data transfer: "); |
| 694 | |
| 695 | mem.map = 0; |
| 696 | mem.flags = MAP_ATTRIB | MAP_ACTIVE; |
| 697 | mem.speed = 300; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 698 | mem.sys_start = CONFIG_SYS_PCMCIA_MEM_ADDR; |
| 699 | mem.sys_stop = CONFIG_SYS_PCMCIA_MEM_ADDR + CONFIG_SYS_PCMCIA_MEM_SIZE - 1; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 700 | mem.card_start = 0; |
| 701 | i365_set_mem_map (&socket, &mem); |
| 702 | |
| 703 | mem.map = 1; |
| 704 | mem.flags = MAP_ACTIVE; |
| 705 | mem.speed = 300; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 706 | mem.sys_start = CONFIG_SYS_PCMCIA_MEM_ADDR + CONFIG_SYS_PCMCIA_MEM_SIZE; |
| 707 | mem.sys_stop = CONFIG_SYS_PCMCIA_MEM_ADDR + (2 * CONFIG_SYS_PCMCIA_MEM_SIZE) - 1; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 708 | mem.card_start = 0; |
| 709 | i365_set_mem_map (&socket, &mem); |
| 710 | |
| 711 | #ifdef DEBUG |
| 712 | i82365_dump_regions (socket.dev); |
| 713 | #endif |
| 714 | |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 715 | return 0; |
| 716 | } |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 717 | |
Wolfgang Denk | de550d6 | 2010-11-23 23:48:56 +0100 | [diff] [blame] | 718 | static void i82365_exit (void) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 719 | { |
| 720 | io.map = 0; |
| 721 | io.flags = 0; |
| 722 | io.speed = 0; |
| 723 | io.start = 0; |
| 724 | io.stop = 0x1; |
| 725 | |
| 726 | i365_set_io_map (&socket, &io); |
| 727 | |
| 728 | mem.map = 0; |
| 729 | mem.flags = 0; |
| 730 | mem.speed = 0; |
| 731 | mem.sys_start = 0; |
| 732 | mem.sys_stop = 0x1000; |
| 733 | mem.card_start = 0; |
| 734 | |
| 735 | i365_set_mem_map (&socket, &mem); |
| 736 | |
| 737 | mem.map = 1; |
| 738 | mem.flags = 0; |
| 739 | mem.speed = 0; |
| 740 | mem.sys_start = 0; |
| 741 | mem.sys_stop = 0x1000; |
| 742 | mem.card_start = 0; |
| 743 | |
| 744 | i365_set_mem_map (&socket, &mem); |
| 745 | |
| 746 | state.Vcc = state.Vpp = 0; |
| 747 | |
| 748 | i365_set_socket (&socket, &state); |
| 749 | } |
| 750 | |
| 751 | int pcmcia_on (void) |
| 752 | { |
| 753 | u_int rc; |
| 754 | |
| 755 | debug ("Enable PCMCIA " PCMCIA_SLOT_MSG "\n"); |
| 756 | |
| 757 | rc = i82365_init(); |
| 758 | if (rc) |
| 759 | goto exit; |
| 760 | |
| 761 | rc = check_ide_device(0); |
| 762 | if (rc == 0) |
| 763 | goto exit; |
| 764 | |
| 765 | i82365_exit(); |
| 766 | |
| 767 | exit: |
| 768 | return rc; |
| 769 | } |
| 770 | |
Jon Loeliger | fcec2eb | 2007-07-09 18:19:09 -0500 | [diff] [blame] | 771 | #if defined(CONFIG_CMD_PCMCIA) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 772 | int pcmcia_off (void) |
| 773 | { |
| 774 | printf ("Disable PCMCIA " PCMCIA_SLOT_MSG "\n"); |
| 775 | |
| 776 | i82365_exit(); |
| 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | #endif |
| 781 | |
| 782 | /*====================================================================== |
| 783 | |
| 784 | Debug stuff |
| 785 | |
| 786 | ======================================================================*/ |
| 787 | |
| 788 | #ifdef DEBUG |
| 789 | static void i82365_dump_regions (pci_dev_t dev) |
| 790 | { |
| 791 | u_int tmp[2]; |
| 792 | u_int *mem = (void *) socket.cb_phys; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 793 | u_char *cis = (void *) CONFIG_SYS_PCMCIA_MEM_ADDR; |
| 794 | u_char *ide = (void *) (CONFIG_SYS_ATA_BASE_ADDR + CONFIG_SYS_ATA_REG_OFFSET); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 795 | |
| 796 | pci_read_config_dword (dev, 0x00, tmp + 0); |
| 797 | pci_read_config_dword (dev, 0x80, tmp + 1); |
| 798 | |
| 799 | printf ("PCI CONF: %08X ... %08X\n", |
| 800 | tmp[0], tmp[1]); |
| 801 | printf ("PCI MEM: ... %08X ... %08X\n", |
| 802 | mem[0x8 / 4], mem[0x800 / 4]); |
| 803 | printf ("CIS: ...%c%c%c%c%c%c%c%c...\n", |
| 804 | cis[0x38], cis[0x3a], cis[0x3c], cis[0x3e], |
| 805 | cis[0x40], cis[0x42], cis[0x44], cis[0x48]); |
| 806 | printf ("CIS CONF: %02X %02X %02X ...\n", |
| 807 | cis[0x200], cis[0x202], cis[0x204]); |
| 808 | printf ("IDE: %02X %02X %02X %02X %02X %02X %02X %02X\n", |
| 809 | ide[0], ide[1], ide[2], ide[3], |
| 810 | ide[4], ide[5], ide[6], ide[7]); |
| 811 | } |
| 812 | #endif /* DEBUG */ |
| 813 | |
| 814 | #endif /* CONFIG_I82365 */ |