diff options
Diffstat (limited to 'drivers/firewire/ohci.c')
| -rw-r--r-- | drivers/firewire/ohci.c | 188 |
1 files changed, 154 insertions, 34 deletions
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index a3b083a7403a..9f627e758cfc 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c | |||
| @@ -236,13 +236,15 @@ static char ohci_driver_name[] = KBUILD_MODNAME; | |||
| 236 | #define QUIRK_CYCLE_TIMER 1 | 236 | #define QUIRK_CYCLE_TIMER 1 |
| 237 | #define QUIRK_RESET_PACKET 2 | 237 | #define QUIRK_RESET_PACKET 2 |
| 238 | #define QUIRK_BE_HEADERS 4 | 238 | #define QUIRK_BE_HEADERS 4 |
| 239 | #define QUIRK_NO_1394A 8 | ||
| 239 | 240 | ||
| 240 | /* In case of multiple matches in ohci_quirks[], only the first one is used. */ | 241 | /* In case of multiple matches in ohci_quirks[], only the first one is used. */ |
| 241 | static const struct { | 242 | static const struct { |
| 242 | unsigned short vendor, device, flags; | 243 | unsigned short vendor, device, flags; |
| 243 | } ohci_quirks[] = { | 244 | } ohci_quirks[] = { |
| 244 | {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, QUIRK_CYCLE_TIMER | | 245 | {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_TSB12LV22, QUIRK_CYCLE_TIMER | |
| 245 | QUIRK_RESET_PACKET}, | 246 | QUIRK_RESET_PACKET | |
| 247 | QUIRK_NO_1394A}, | ||
| 246 | {PCI_VENDOR_ID_TI, PCI_ANY_ID, QUIRK_RESET_PACKET}, | 248 | {PCI_VENDOR_ID_TI, PCI_ANY_ID, QUIRK_RESET_PACKET}, |
| 247 | {PCI_VENDOR_ID_AL, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | 249 | {PCI_VENDOR_ID_AL, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, |
| 248 | {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, | 250 | {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, |
| @@ -257,15 +259,16 @@ MODULE_PARM_DESC(quirks, "Chip quirks (default = 0" | |||
| 257 | ", nonatomic cycle timer = " __stringify(QUIRK_CYCLE_TIMER) | 259 | ", nonatomic cycle timer = " __stringify(QUIRK_CYCLE_TIMER) |
| 258 | ", reset packet generation = " __stringify(QUIRK_RESET_PACKET) | 260 | ", reset packet generation = " __stringify(QUIRK_RESET_PACKET) |
| 259 | ", AR/selfID endianess = " __stringify(QUIRK_BE_HEADERS) | 261 | ", AR/selfID endianess = " __stringify(QUIRK_BE_HEADERS) |
| 262 | ", no 1394a enhancements = " __stringify(QUIRK_NO_1394A) | ||
| 260 | ")"); | 263 | ")"); |
| 261 | 264 | ||
| 262 | #ifdef CONFIG_FIREWIRE_OHCI_DEBUG | ||
| 263 | |||
| 264 | #define OHCI_PARAM_DEBUG_AT_AR 1 | 265 | #define OHCI_PARAM_DEBUG_AT_AR 1 |
| 265 | #define OHCI_PARAM_DEBUG_SELFIDS 2 | 266 | #define OHCI_PARAM_DEBUG_SELFIDS 2 |
| 266 | #define OHCI_PARAM_DEBUG_IRQS 4 | 267 | #define OHCI_PARAM_DEBUG_IRQS 4 |
| 267 | #define OHCI_PARAM_DEBUG_BUSRESETS 8 /* only effective before chip init */ | 268 | #define OHCI_PARAM_DEBUG_BUSRESETS 8 /* only effective before chip init */ |
| 268 | 269 | ||
| 270 | #ifdef CONFIG_FIREWIRE_OHCI_DEBUG | ||
| 271 | |||
| 269 | static int param_debug; | 272 | static int param_debug; |
| 270 | module_param_named(debug, param_debug, int, 0644); | 273 | module_param_named(debug, param_debug, int, 0644); |
| 271 | MODULE_PARM_DESC(debug, "Verbose logging (default = 0" | 274 | MODULE_PARM_DESC(debug, "Verbose logging (default = 0" |
| @@ -438,9 +441,10 @@ static void log_ar_at_event(char dir, int speed, u32 *header, int evt) | |||
| 438 | 441 | ||
| 439 | #else | 442 | #else |
| 440 | 443 | ||
| 441 | #define log_irqs(evt) | 444 | #define param_debug 0 |
| 442 | #define log_selfids(node_id, generation, self_id_count, sid) | 445 | static inline void log_irqs(u32 evt) {} |
| 443 | #define log_ar_at_event(dir, speed, header, evt) | 446 | static inline void log_selfids(int node_id, int generation, int self_id_count, u32 *s) {} |
| 447 | static inline void log_ar_at_event(char dir, int speed, u32 *header, int evt) {} | ||
| 444 | 448 | ||
| 445 | #endif /* CONFIG_FIREWIRE_OHCI_DEBUG */ | 449 | #endif /* CONFIG_FIREWIRE_OHCI_DEBUG */ |
| 446 | 450 | ||
| @@ -460,27 +464,71 @@ static inline void flush_writes(const struct fw_ohci *ohci) | |||
| 460 | reg_read(ohci, OHCI1394_Version); | 464 | reg_read(ohci, OHCI1394_Version); |
| 461 | } | 465 | } |
| 462 | 466 | ||
| 463 | static int ohci_update_phy_reg(struct fw_card *card, int addr, | 467 | static int read_phy_reg(struct fw_ohci *ohci, int addr) |
| 464 | int clear_bits, int set_bits) | ||
| 465 | { | 468 | { |
| 466 | struct fw_ohci *ohci = fw_ohci(card); | 469 | u32 val; |
| 467 | u32 val, old; | 470 | int i; |
| 468 | 471 | ||
| 469 | reg_write(ohci, OHCI1394_PhyControl, OHCI1394_PhyControl_Read(addr)); | 472 | reg_write(ohci, OHCI1394_PhyControl, OHCI1394_PhyControl_Read(addr)); |
| 470 | flush_writes(ohci); | 473 | for (i = 0; i < 10; i++) { |
| 471 | msleep(2); | 474 | val = reg_read(ohci, OHCI1394_PhyControl); |
| 472 | val = reg_read(ohci, OHCI1394_PhyControl); | 475 | if (val & OHCI1394_PhyControl_ReadDone) |
| 473 | if ((val & OHCI1394_PhyControl_ReadDone) == 0) { | 476 | return OHCI1394_PhyControl_ReadData(val); |
| 474 | fw_error("failed to set phy reg bits.\n"); | 477 | |
| 475 | return -EBUSY; | 478 | msleep(1); |
| 476 | } | 479 | } |
| 480 | fw_error("failed to read phy reg\n"); | ||
| 481 | |||
| 482 | return -EBUSY; | ||
| 483 | } | ||
| 484 | |||
| 485 | static int write_phy_reg(const struct fw_ohci *ohci, int addr, u32 val) | ||
| 486 | { | ||
| 487 | int i; | ||
| 477 | 488 | ||
| 478 | old = OHCI1394_PhyControl_ReadData(val); | ||
| 479 | old = (old & ~clear_bits) | set_bits; | ||
| 480 | reg_write(ohci, OHCI1394_PhyControl, | 489 | reg_write(ohci, OHCI1394_PhyControl, |
| 481 | OHCI1394_PhyControl_Write(addr, old)); | 490 | OHCI1394_PhyControl_Write(addr, val)); |
| 491 | for (i = 0; i < 100; i++) { | ||
| 492 | val = reg_read(ohci, OHCI1394_PhyControl); | ||
| 493 | if (!(val & OHCI1394_PhyControl_WritePending)) | ||
| 494 | return 0; | ||
| 482 | 495 | ||
| 483 | return 0; | 496 | msleep(1); |
| 497 | } | ||
| 498 | fw_error("failed to write phy reg\n"); | ||
| 499 | |||
| 500 | return -EBUSY; | ||
| 501 | } | ||
| 502 | |||
| 503 | static int ohci_update_phy_reg(struct fw_card *card, int addr, | ||
| 504 | int clear_bits, int set_bits) | ||
| 505 | { | ||
| 506 | struct fw_ohci *ohci = fw_ohci(card); | ||
| 507 | int ret; | ||
| 508 | |||
| 509 | ret = read_phy_reg(ohci, addr); | ||
| 510 | if (ret < 0) | ||
| 511 | return ret; | ||
| 512 | |||
| 513 | /* | ||
| 514 | * The interrupt status bits are cleared by writing a one bit. | ||
| 515 | * Avoid clearing them unless explicitly requested in set_bits. | ||
| 516 | */ | ||
| 517 | if (addr == 5) | ||
| 518 | clear_bits |= PHY_INT_STATUS_BITS; | ||
| 519 | |||
| 520 | return write_phy_reg(ohci, addr, (ret & ~clear_bits) | set_bits); | ||
| 521 | } | ||
| 522 | |||
| 523 | static int read_paged_phy_reg(struct fw_ohci *ohci, int page, int addr) | ||
| 524 | { | ||
| 525 | int ret; | ||
| 526 | |||
| 527 | ret = ohci_update_phy_reg(&ohci->card, 7, PHY_PAGE_SELECT, page << 5); | ||
| 528 | if (ret < 0) | ||
| 529 | return ret; | ||
| 530 | |||
| 531 | return read_phy_reg(ohci, addr); | ||
| 484 | } | 532 | } |
| 485 | 533 | ||
| 486 | static int ar_context_add_page(struct ar_context *ctx) | 534 | static int ar_context_add_page(struct ar_context *ctx) |
| @@ -1495,13 +1543,64 @@ static void copy_config_rom(__be32 *dest, const __be32 *src, size_t length) | |||
| 1495 | memset(&dest[length], 0, CONFIG_ROM_SIZE - size); | 1543 | memset(&dest[length], 0, CONFIG_ROM_SIZE - size); |
| 1496 | } | 1544 | } |
| 1497 | 1545 | ||
| 1546 | static int configure_1394a_enhancements(struct fw_ohci *ohci) | ||
| 1547 | { | ||
| 1548 | bool enable_1394a; | ||
| 1549 | int ret, clear, set, offset; | ||
| 1550 | |||
| 1551 | /* Check if the driver should configure link and PHY. */ | ||
| 1552 | if (!(reg_read(ohci, OHCI1394_HCControlSet) & | ||
| 1553 | OHCI1394_HCControl_programPhyEnable)) | ||
| 1554 | return 0; | ||
| 1555 | |||
| 1556 | /* Paranoia: check whether the PHY supports 1394a, too. */ | ||
| 1557 | enable_1394a = false; | ||
| 1558 | ret = read_phy_reg(ohci, 2); | ||
| 1559 | if (ret < 0) | ||
| 1560 | return ret; | ||
| 1561 | if ((ret & PHY_EXTENDED_REGISTERS) == PHY_EXTENDED_REGISTERS) { | ||
| 1562 | ret = read_paged_phy_reg(ohci, 1, 8); | ||
| 1563 | if (ret < 0) | ||
| 1564 | return ret; | ||
| 1565 | if (ret >= 1) | ||
| 1566 | enable_1394a = true; | ||
| 1567 | } | ||
| 1568 | |||
| 1569 | if (ohci->quirks & QUIRK_NO_1394A) | ||
| 1570 | enable_1394a = false; | ||
| 1571 | |||
| 1572 | /* Configure PHY and link consistently. */ | ||
| 1573 | if (enable_1394a) { | ||
| 1574 | clear = 0; | ||
| 1575 | set = PHY_ENABLE_ACCEL | PHY_ENABLE_MULTI; | ||
| 1576 | } else { | ||
| 1577 | clear = PHY_ENABLE_ACCEL | PHY_ENABLE_MULTI; | ||
| 1578 | set = 0; | ||
| 1579 | } | ||
| 1580 | ret = ohci_update_phy_reg(&ohci->card, 5, clear, set); | ||
| 1581 | if (ret < 0) | ||
| 1582 | return ret; | ||
| 1583 | |||
| 1584 | if (enable_1394a) | ||
| 1585 | offset = OHCI1394_HCControlSet; | ||
| 1586 | else | ||
| 1587 | offset = OHCI1394_HCControlClear; | ||
| 1588 | reg_write(ohci, offset, OHCI1394_HCControl_aPhyEnhanceEnable); | ||
| 1589 | |||
| 1590 | /* Clean up: configuration has been taken care of. */ | ||
| 1591 | reg_write(ohci, OHCI1394_HCControlClear, | ||
| 1592 | OHCI1394_HCControl_programPhyEnable); | ||
| 1593 | |||
| 1594 | return 0; | ||
| 1595 | } | ||
| 1596 | |||
| 1498 | static int ohci_enable(struct fw_card *card, | 1597 | static int ohci_enable(struct fw_card *card, |
| 1499 | const __be32 *config_rom, size_t length) | 1598 | const __be32 *config_rom, size_t length) |
| 1500 | { | 1599 | { |
| 1501 | struct fw_ohci *ohci = fw_ohci(card); | 1600 | struct fw_ohci *ohci = fw_ohci(card); |
| 1502 | struct pci_dev *dev = to_pci_dev(card->device); | 1601 | struct pci_dev *dev = to_pci_dev(card->device); |
| 1503 | u32 lps; | 1602 | u32 lps; |
| 1504 | int i; | 1603 | int i, ret; |
| 1505 | 1604 | ||
| 1506 | if (software_reset(ohci)) { | 1605 | if (software_reset(ohci)) { |
| 1507 | fw_error("Failed to reset ohci card.\n"); | 1606 | fw_error("Failed to reset ohci card.\n"); |
| @@ -1565,10 +1664,14 @@ static int ohci_enable(struct fw_card *card, | |||
| 1565 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) | 1664 | if (param_debug & OHCI_PARAM_DEBUG_BUSRESETS) |
| 1566 | reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); | 1665 | reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); |
| 1567 | 1666 | ||
| 1667 | ret = configure_1394a_enhancements(ohci); | ||
| 1668 | if (ret < 0) | ||
| 1669 | return ret; | ||
| 1670 | |||
| 1568 | /* Activate link_on bit and contender bit in our self ID packets.*/ | 1671 | /* Activate link_on bit and contender bit in our self ID packets.*/ |
| 1569 | if (ohci_update_phy_reg(card, 4, 0, | 1672 | ret = ohci_update_phy_reg(card, 4, 0, PHY_LINK_ACTIVE | PHY_CONTENDER); |
| 1570 | PHY_LINK_ACTIVE | PHY_CONTENDER) < 0) | 1673 | if (ret < 0) |
| 1571 | return -EIO; | 1674 | return ret; |
| 1572 | 1675 | ||
| 1573 | /* | 1676 | /* |
| 1574 | * When the link is not yet enabled, the atomic config rom | 1677 | * When the link is not yet enabled, the atomic config rom |
| @@ -2304,7 +2407,7 @@ static const struct fw_card_driver ohci_driver = { | |||
| 2304 | }; | 2407 | }; |
| 2305 | 2408 | ||
| 2306 | #ifdef CONFIG_PPC_PMAC | 2409 | #ifdef CONFIG_PPC_PMAC |
| 2307 | static void ohci_pmac_on(struct pci_dev *dev) | 2410 | static void pmac_ohci_on(struct pci_dev *dev) |
| 2308 | { | 2411 | { |
| 2309 | if (machine_is(powermac)) { | 2412 | if (machine_is(powermac)) { |
| 2310 | struct device_node *ofn = pci_device_to_OF_node(dev); | 2413 | struct device_node *ofn = pci_device_to_OF_node(dev); |
| @@ -2316,7 +2419,7 @@ static void ohci_pmac_on(struct pci_dev *dev) | |||
| 2316 | } | 2419 | } |
| 2317 | } | 2420 | } |
| 2318 | 2421 | ||
| 2319 | static void ohci_pmac_off(struct pci_dev *dev) | 2422 | static void pmac_ohci_off(struct pci_dev *dev) |
| 2320 | { | 2423 | { |
| 2321 | if (machine_is(powermac)) { | 2424 | if (machine_is(powermac)) { |
| 2322 | struct device_node *ofn = pci_device_to_OF_node(dev); | 2425 | struct device_node *ofn = pci_device_to_OF_node(dev); |
| @@ -2328,15 +2431,15 @@ static void ohci_pmac_off(struct pci_dev *dev) | |||
| 2328 | } | 2431 | } |
| 2329 | } | 2432 | } |
| 2330 | #else | 2433 | #else |
| 2331 | #define ohci_pmac_on(dev) | 2434 | static inline void pmac_ohci_on(struct pci_dev *dev) {} |
| 2332 | #define ohci_pmac_off(dev) | 2435 | static inline void pmac_ohci_off(struct pci_dev *dev) {} |
| 2333 | #endif /* CONFIG_PPC_PMAC */ | 2436 | #endif /* CONFIG_PPC_PMAC */ |
| 2334 | 2437 | ||
| 2335 | static int __devinit pci_probe(struct pci_dev *dev, | 2438 | static int __devinit pci_probe(struct pci_dev *dev, |
| 2336 | const struct pci_device_id *ent) | 2439 | const struct pci_device_id *ent) |
| 2337 | { | 2440 | { |
| 2338 | struct fw_ohci *ohci; | 2441 | struct fw_ohci *ohci; |
| 2339 | u32 bus_options, max_receive, link_speed, version; | 2442 | u32 bus_options, max_receive, link_speed, version, link_enh; |
| 2340 | u64 guid; | 2443 | u64 guid; |
| 2341 | int i, err, n_ir, n_it; | 2444 | int i, err, n_ir, n_it; |
| 2342 | size_t size; | 2445 | size_t size; |
| @@ -2349,7 +2452,7 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
| 2349 | 2452 | ||
| 2350 | fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev); | 2453 | fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev); |
| 2351 | 2454 | ||
| 2352 | ohci_pmac_on(dev); | 2455 | pmac_ohci_on(dev); |
| 2353 | 2456 | ||
| 2354 | err = pci_enable_device(dev); | 2457 | err = pci_enable_device(dev); |
| 2355 | if (err) { | 2458 | if (err) { |
| @@ -2389,6 +2492,23 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
| 2389 | if (param_quirks) | 2492 | if (param_quirks) |
| 2390 | ohci->quirks = param_quirks; | 2493 | ohci->quirks = param_quirks; |
| 2391 | 2494 | ||
| 2495 | /* TI OHCI-Lynx and compatible: set recommended configuration bits. */ | ||
| 2496 | if (dev->vendor == PCI_VENDOR_ID_TI) { | ||
| 2497 | pci_read_config_dword(dev, PCI_CFG_TI_LinkEnh, &link_enh); | ||
| 2498 | |||
| 2499 | /* adjust latency of ATx FIFO: use 1.7 KB threshold */ | ||
| 2500 | link_enh &= ~TI_LinkEnh_atx_thresh_mask; | ||
| 2501 | link_enh |= TI_LinkEnh_atx_thresh_1_7K; | ||
| 2502 | |||
| 2503 | /* use priority arbitration for asynchronous responses */ | ||
| 2504 | link_enh |= TI_LinkEnh_enab_unfair; | ||
| 2505 | |||
| 2506 | /* required for aPhyEnhanceEnable to work */ | ||
| 2507 | link_enh |= TI_LinkEnh_enab_accel; | ||
| 2508 | |||
| 2509 | pci_write_config_dword(dev, PCI_CFG_TI_LinkEnh, link_enh); | ||
| 2510 | } | ||
| 2511 | |||
| 2392 | ar_context_init(&ohci->ar_request_ctx, ohci, | 2512 | ar_context_init(&ohci->ar_request_ctx, ohci, |
| 2393 | OHCI1394_AsReqRcvContextControlSet); | 2513 | OHCI1394_AsReqRcvContextControlSet); |
| 2394 | 2514 | ||
| @@ -2466,7 +2586,7 @@ static int __devinit pci_probe(struct pci_dev *dev, | |||
| 2466 | pci_disable_device(dev); | 2586 | pci_disable_device(dev); |
| 2467 | fail_free: | 2587 | fail_free: |
| 2468 | kfree(&ohci->card); | 2588 | kfree(&ohci->card); |
| 2469 | ohci_pmac_off(dev); | 2589 | pmac_ohci_off(dev); |
| 2470 | fail: | 2590 | fail: |
| 2471 | if (err == -ENOMEM) | 2591 | if (err == -ENOMEM) |
| 2472 | fw_error("Out of memory\n"); | 2592 | fw_error("Out of memory\n"); |
| @@ -2509,7 +2629,7 @@ static void pci_remove(struct pci_dev *dev) | |||
| 2509 | pci_release_region(dev, 0); | 2629 | pci_release_region(dev, 0); |
| 2510 | pci_disable_device(dev); | 2630 | pci_disable_device(dev); |
| 2511 | kfree(&ohci->card); | 2631 | kfree(&ohci->card); |
| 2512 | ohci_pmac_off(dev); | 2632 | pmac_ohci_off(dev); |
| 2513 | 2633 | ||
| 2514 | fw_notify("Removed fw-ohci device.\n"); | 2634 | fw_notify("Removed fw-ohci device.\n"); |
| 2515 | } | 2635 | } |
| @@ -2530,7 +2650,7 @@ static int pci_suspend(struct pci_dev *dev, pm_message_t state) | |||
| 2530 | err = pci_set_power_state(dev, pci_choose_state(dev, state)); | 2650 | err = pci_set_power_state(dev, pci_choose_state(dev, state)); |
| 2531 | if (err) | 2651 | if (err) |
| 2532 | fw_error("pci_set_power_state failed with %d\n", err); | 2652 | fw_error("pci_set_power_state failed with %d\n", err); |
| 2533 | ohci_pmac_off(dev); | 2653 | pmac_ohci_off(dev); |
| 2534 | 2654 | ||
| 2535 | return 0; | 2655 | return 0; |
| 2536 | } | 2656 | } |
| @@ -2540,7 +2660,7 @@ static int pci_resume(struct pci_dev *dev) | |||
| 2540 | struct fw_ohci *ohci = pci_get_drvdata(dev); | 2660 | struct fw_ohci *ohci = pci_get_drvdata(dev); |
| 2541 | int err; | 2661 | int err; |
| 2542 | 2662 | ||
| 2543 | ohci_pmac_on(dev); | 2663 | pmac_ohci_on(dev); |
| 2544 | pci_set_power_state(dev, PCI_D0); | 2664 | pci_set_power_state(dev, PCI_D0); |
| 2545 | pci_restore_state(dev); | 2665 | pci_restore_state(dev); |
| 2546 | err = pci_enable_device(dev); | 2666 | err = pci_enable_device(dev); |
