diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2013-12-14 15:06:53 -0500 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2013-12-15 20:00:00 -0500 |
commit | e7b4f0d7841b188423b641cab71d20b1a05234e9 (patch) | |
tree | 4bce89fc568ce7ed97509f4126015dff511c8feb | |
parent | df72648c4d61d6d0ce033c0467a9fabec670fe46 (diff) |
PCI: pciehp: Use symbolic constants for Slot Control fields
Add symbolic constants for the PCIe Slot Control indicator and power
control fields defined by spec and use them instead of open-coded hex
constants.
No functional change.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r-- | drivers/pci/hotplug/pciehp_hpc.c | 86 | ||||
-rw-r--r-- | include/uapi/linux/pci_regs.h | 8 |
2 files changed, 36 insertions, 58 deletions
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 915bb35f9180..05d421cf935e 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c | |||
@@ -46,10 +46,6 @@ static inline struct pci_dev *ctrl_dev(struct controller *ctrl) | |||
46 | return ctrl->pcie->port; | 46 | return ctrl->pcie->port; |
47 | } | 47 | } |
48 | 48 | ||
49 | /* Power Control Command */ | ||
50 | #define POWER_ON 0 | ||
51 | #define POWER_OFF PCI_EXP_SLTCTL_PCC | ||
52 | |||
53 | static irqreturn_t pcie_isr(int irq, void *dev_id); | 49 | static irqreturn_t pcie_isr(int irq, void *dev_id); |
54 | static void start_int_poll_timer(struct controller *ctrl, int sec); | 50 | static void start_int_poll_timer(struct controller *ctrl, int sec); |
55 | 51 | ||
@@ -346,25 +342,19 @@ void pciehp_get_attention_status(struct slot *slot, u8 *status) | |||
346 | struct controller *ctrl = slot->ctrl; | 342 | struct controller *ctrl = slot->ctrl; |
347 | struct pci_dev *pdev = ctrl_dev(ctrl); | 343 | struct pci_dev *pdev = ctrl_dev(ctrl); |
348 | u16 slot_ctrl; | 344 | u16 slot_ctrl; |
349 | u8 atten_led_state; | ||
350 | 345 | ||
351 | pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); | 346 | pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); |
352 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x, value read %x\n", __func__, | 347 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x, value read %x\n", __func__, |
353 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_ctrl); | 348 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_ctrl); |
354 | 349 | ||
355 | atten_led_state = (slot_ctrl & PCI_EXP_SLTCTL_AIC) >> 6; | 350 | switch (slot_ctrl & PCI_EXP_SLTCTL_AIC) { |
356 | 351 | case PCI_EXP_SLTCTL_ATTN_IND_ON: | |
357 | switch (atten_led_state) { | ||
358 | case 0: | ||
359 | *status = 0xFF; /* Reserved */ | ||
360 | break; | ||
361 | case 1: | ||
362 | *status = 1; /* On */ | 352 | *status = 1; /* On */ |
363 | break; | 353 | break; |
364 | case 2: | 354 | case PCI_EXP_SLTCTL_ATTN_IND_BLINK: |
365 | *status = 2; /* Blink */ | 355 | *status = 2; /* Blink */ |
366 | break; | 356 | break; |
367 | case 3: | 357 | case PCI_EXP_SLTCTL_ATTN_IND_OFF: |
368 | *status = 0; /* Off */ | 358 | *status = 0; /* Off */ |
369 | break; | 359 | break; |
370 | default: | 360 | default: |
@@ -378,20 +368,17 @@ void pciehp_get_power_status(struct slot *slot, u8 *status) | |||
378 | struct controller *ctrl = slot->ctrl; | 368 | struct controller *ctrl = slot->ctrl; |
379 | struct pci_dev *pdev = ctrl_dev(ctrl); | 369 | struct pci_dev *pdev = ctrl_dev(ctrl); |
380 | u16 slot_ctrl; | 370 | u16 slot_ctrl; |
381 | u8 pwr_state; | ||
382 | 371 | ||
383 | pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); | 372 | pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &slot_ctrl); |
384 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x value read %x\n", __func__, | 373 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x value read %x\n", __func__, |
385 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_ctrl); | 374 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_ctrl); |
386 | 375 | ||
387 | pwr_state = (slot_ctrl & PCI_EXP_SLTCTL_PCC) >> 10; | 376 | switch (slot_ctrl & PCI_EXP_SLTCTL_PCC) { |
388 | 377 | case PCI_EXP_SLTCTL_PWR_ON: | |
389 | switch (pwr_state) { | 378 | *status = 1; /* On */ |
390 | case 0: | ||
391 | *status = 1; | ||
392 | break; | 379 | break; |
393 | case 1: | 380 | case PCI_EXP_SLTCTL_PWR_OFF: |
394 | *status = 0; | 381 | *status = 0; /* Off */ |
395 | break; | 382 | break; |
396 | default: | 383 | default: |
397 | *status = 0xFF; | 384 | *status = 0xFF; |
@@ -430,72 +417,59 @@ void pciehp_set_attention_status(struct slot *slot, u8 value) | |||
430 | { | 417 | { |
431 | struct controller *ctrl = slot->ctrl; | 418 | struct controller *ctrl = slot->ctrl; |
432 | u16 slot_cmd; | 419 | u16 slot_cmd; |
433 | u16 cmd_mask; | ||
434 | 420 | ||
435 | cmd_mask = PCI_EXP_SLTCTL_AIC; | ||
436 | switch (value) { | 421 | switch (value) { |
437 | case 0 : /* turn off */ | 422 | case 0 : /* turn off */ |
438 | slot_cmd = 0x00C0; | 423 | slot_cmd = PCI_EXP_SLTCTL_ATTN_IND_OFF; |
439 | break; | 424 | break; |
440 | case 1: /* turn on */ | 425 | case 1: /* turn on */ |
441 | slot_cmd = 0x0040; | 426 | slot_cmd = PCI_EXP_SLTCTL_ATTN_IND_ON; |
442 | break; | 427 | break; |
443 | case 2: /* turn blink */ | 428 | case 2: /* turn blink */ |
444 | slot_cmd = 0x0080; | 429 | slot_cmd = PCI_EXP_SLTCTL_ATTN_IND_BLINK; |
445 | break; | 430 | break; |
446 | default: | 431 | default: |
447 | return; | 432 | return; |
448 | } | 433 | } |
449 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, | 434 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, |
450 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); | 435 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); |
451 | pcie_write_cmd(ctrl, slot_cmd, cmd_mask); | 436 | pcie_write_cmd(ctrl, slot_cmd, PCI_EXP_SLTCTL_AIC); |
452 | } | 437 | } |
453 | 438 | ||
454 | void pciehp_green_led_on(struct slot *slot) | 439 | void pciehp_green_led_on(struct slot *slot) |
455 | { | 440 | { |
456 | struct controller *ctrl = slot->ctrl; | 441 | struct controller *ctrl = slot->ctrl; |
457 | u16 slot_cmd; | ||
458 | u16 cmd_mask; | ||
459 | 442 | ||
460 | slot_cmd = 0x0100; | 443 | pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_PWR_IND_ON, PCI_EXP_SLTCTL_PIC); |
461 | cmd_mask = PCI_EXP_SLTCTL_PIC; | ||
462 | pcie_write_cmd(ctrl, slot_cmd, cmd_mask); | ||
463 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, | 444 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, |
464 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); | 445 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, |
446 | PCI_EXP_SLTCTL_PWR_IND_ON); | ||
465 | } | 447 | } |
466 | 448 | ||
467 | void pciehp_green_led_off(struct slot *slot) | 449 | void pciehp_green_led_off(struct slot *slot) |
468 | { | 450 | { |
469 | struct controller *ctrl = slot->ctrl; | 451 | struct controller *ctrl = slot->ctrl; |
470 | u16 slot_cmd; | ||
471 | u16 cmd_mask; | ||
472 | 452 | ||
473 | slot_cmd = 0x0300; | 453 | pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, PCI_EXP_SLTCTL_PIC); |
474 | cmd_mask = PCI_EXP_SLTCTL_PIC; | ||
475 | pcie_write_cmd(ctrl, slot_cmd, cmd_mask); | ||
476 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, | 454 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, |
477 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); | 455 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, |
456 | PCI_EXP_SLTCTL_PWR_IND_OFF); | ||
478 | } | 457 | } |
479 | 458 | ||
480 | void pciehp_green_led_blink(struct slot *slot) | 459 | void pciehp_green_led_blink(struct slot *slot) |
481 | { | 460 | { |
482 | struct controller *ctrl = slot->ctrl; | 461 | struct controller *ctrl = slot->ctrl; |
483 | u16 slot_cmd; | ||
484 | u16 cmd_mask; | ||
485 | 462 | ||
486 | slot_cmd = 0x0200; | 463 | pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_PWR_IND_BLINK, PCI_EXP_SLTCTL_PIC); |
487 | cmd_mask = PCI_EXP_SLTCTL_PIC; | ||
488 | pcie_write_cmd(ctrl, slot_cmd, cmd_mask); | ||
489 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, | 464 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, |
490 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); | 465 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, |
466 | PCI_EXP_SLTCTL_PWR_IND_BLINK); | ||
491 | } | 467 | } |
492 | 468 | ||
493 | int pciehp_power_on_slot(struct slot * slot) | 469 | int pciehp_power_on_slot(struct slot * slot) |
494 | { | 470 | { |
495 | struct controller *ctrl = slot->ctrl; | 471 | struct controller *ctrl = slot->ctrl; |
496 | struct pci_dev *pdev = ctrl_dev(ctrl); | 472 | struct pci_dev *pdev = ctrl_dev(ctrl); |
497 | u16 slot_cmd; | ||
498 | u16 cmd_mask; | ||
499 | u16 slot_status; | 473 | u16 slot_status; |
500 | int retval; | 474 | int retval; |
501 | 475 | ||
@@ -506,11 +480,10 @@ int pciehp_power_on_slot(struct slot * slot) | |||
506 | PCI_EXP_SLTSTA_PFD); | 480 | PCI_EXP_SLTSTA_PFD); |
507 | ctrl->power_fault_detected = 0; | 481 | ctrl->power_fault_detected = 0; |
508 | 482 | ||
509 | slot_cmd = POWER_ON; | 483 | pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_PWR_ON, PCI_EXP_SLTCTL_PCC); |
510 | cmd_mask = PCI_EXP_SLTCTL_PCC; | ||
511 | pcie_write_cmd(ctrl, slot_cmd, cmd_mask); | ||
512 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, | 484 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, |
513 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); | 485 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, |
486 | PCI_EXP_SLTCTL_PWR_ON); | ||
514 | 487 | ||
515 | retval = pciehp_link_enable(ctrl); | 488 | retval = pciehp_link_enable(ctrl); |
516 | if (retval) | 489 | if (retval) |
@@ -522,8 +495,6 @@ int pciehp_power_on_slot(struct slot * slot) | |||
522 | void pciehp_power_off_slot(struct slot * slot) | 495 | void pciehp_power_off_slot(struct slot * slot) |
523 | { | 496 | { |
524 | struct controller *ctrl = slot->ctrl; | 497 | struct controller *ctrl = slot->ctrl; |
525 | u16 slot_cmd; | ||
526 | u16 cmd_mask; | ||
527 | 498 | ||
528 | /* Disable the link at first */ | 499 | /* Disable the link at first */ |
529 | pciehp_link_disable(ctrl); | 500 | pciehp_link_disable(ctrl); |
@@ -533,11 +504,10 @@ void pciehp_power_off_slot(struct slot * slot) | |||
533 | else | 504 | else |
534 | msleep(1000); | 505 | msleep(1000); |
535 | 506 | ||
536 | slot_cmd = POWER_OFF; | 507 | pcie_write_cmd(ctrl, PCI_EXP_SLTCTL_PWR_OFF, PCI_EXP_SLTCTL_PCC); |
537 | cmd_mask = PCI_EXP_SLTCTL_PCC; | ||
538 | pcie_write_cmd(ctrl, slot_cmd, cmd_mask); | ||
539 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, | 508 | ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, |
540 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); | 509 | pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, |
510 | PCI_EXP_SLTCTL_PWR_OFF); | ||
541 | } | 511 | } |
542 | 512 | ||
543 | static irqreturn_t pcie_isr(int irq, void *dev_id) | 513 | static irqreturn_t pcie_isr(int irq, void *dev_id) |
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index 4a98e85438a7..6d03ba42ab23 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h | |||
@@ -518,8 +518,16 @@ | |||
518 | #define PCI_EXP_SLTCTL_CCIE 0x0010 /* Command Completed Interrupt Enable */ | 518 | #define PCI_EXP_SLTCTL_CCIE 0x0010 /* Command Completed Interrupt Enable */ |
519 | #define PCI_EXP_SLTCTL_HPIE 0x0020 /* Hot-Plug Interrupt Enable */ | 519 | #define PCI_EXP_SLTCTL_HPIE 0x0020 /* Hot-Plug Interrupt Enable */ |
520 | #define PCI_EXP_SLTCTL_AIC 0x00c0 /* Attention Indicator Control */ | 520 | #define PCI_EXP_SLTCTL_AIC 0x00c0 /* Attention Indicator Control */ |
521 | #define PCI_EXP_SLTCTL_ATTN_IND_ON 0x0040 /* Attention Indicator on */ | ||
522 | #define PCI_EXP_SLTCTL_ATTN_IND_BLINK 0x0080 /* Attention Indicator blinking */ | ||
523 | #define PCI_EXP_SLTCTL_ATTN_IND_OFF 0x00c0 /* Attention Indicator off */ | ||
521 | #define PCI_EXP_SLTCTL_PIC 0x0300 /* Power Indicator Control */ | 524 | #define PCI_EXP_SLTCTL_PIC 0x0300 /* Power Indicator Control */ |
525 | #define PCI_EXP_SLTCTL_PWR_IND_ON 0x0100 /* Power Indicator on */ | ||
526 | #define PCI_EXP_SLTCTL_PWR_IND_BLINK 0x0200 /* Power Indicator blinking */ | ||
527 | #define PCI_EXP_SLTCTL_PWR_IND_OFF 0x0300 /* Power Indicator off */ | ||
522 | #define PCI_EXP_SLTCTL_PCC 0x0400 /* Power Controller Control */ | 528 | #define PCI_EXP_SLTCTL_PCC 0x0400 /* Power Controller Control */ |
529 | #define PCI_EXP_SLTCTL_PWR_ON 0x0000 /* Power On */ | ||
530 | #define PCI_EXP_SLTCTL_PWR_OFF 0x0400 /* Power Off */ | ||
523 | #define PCI_EXP_SLTCTL_EIC 0x0800 /* Electromechanical Interlock Control */ | 531 | #define PCI_EXP_SLTCTL_EIC 0x0800 /* Electromechanical Interlock Control */ |
524 | #define PCI_EXP_SLTCTL_DLLSCE 0x1000 /* Data Link Layer State Changed Enable */ | 532 | #define PCI_EXP_SLTCTL_DLLSCE 0x1000 /* Data Link Layer State Changed Enable */ |
525 | #define PCI_EXP_SLTSTA 26 /* Slot Status */ | 533 | #define PCI_EXP_SLTSTA 26 /* Slot Status */ |