diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2017-01-26 10:16:26 -0500 |
---|---|---|
committer | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2017-10-08 14:07:13 -0400 |
commit | f5b33d94c1eca23802e3ac76b0788ba59e44a481 (patch) | |
tree | 46a1bf52ee83f711c60c6f68c787fc5d0347099d /drivers/platform/x86/intel_ips.c | |
parent | 687d25a2bae98b32534d2119419ed1eea6e53bbb (diff) |
platform/x86: intel_ips: Simplify error handling via devres API
Use devm_ and pcim_ functions to make error handling
simpler and code smaller and tidier.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Diffstat (limited to 'drivers/platform/x86/intel_ips.c')
-rw-r--r-- | drivers/platform/x86/intel_ips.c | 62 |
1 files changed, 15 insertions, 47 deletions
diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c index 58dcee562d64..063d9a1624b4 100644 --- a/drivers/platform/x86/intel_ips.c +++ b/drivers/platform/x86/intel_ips.c | |||
@@ -296,7 +296,7 @@ static struct ips_mcp_limits ips_ulv_limits = { | |||
296 | 296 | ||
297 | struct ips_driver { | 297 | struct ips_driver { |
298 | struct pci_dev *dev; | 298 | struct pci_dev *dev; |
299 | void *regmap; | 299 | void __iomem *regmap; |
300 | struct task_struct *monitor; | 300 | struct task_struct *monitor; |
301 | struct task_struct *adjust; | 301 | struct task_struct *adjust; |
302 | struct dentry *debug_root; | 302 | struct dentry *debug_root; |
@@ -1517,62 +1517,45 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
1517 | if (dmi_check_system(ips_blacklist)) | 1517 | if (dmi_check_system(ips_blacklist)) |
1518 | return -ENODEV; | 1518 | return -ENODEV; |
1519 | 1519 | ||
1520 | ips = kzalloc(sizeof(struct ips_driver), GFP_KERNEL); | 1520 | ips = devm_kzalloc(&dev->dev, sizeof(*ips), GFP_KERNEL); |
1521 | if (!ips) | 1521 | if (!ips) |
1522 | return -ENOMEM; | 1522 | return -ENOMEM; |
1523 | 1523 | ||
1524 | pci_set_drvdata(dev, ips); | 1524 | spin_lock_init(&ips->turbo_status_lock); |
1525 | ips->dev = dev; | 1525 | ips->dev = dev; |
1526 | 1526 | ||
1527 | ips->limits = ips_detect_cpu(ips); | 1527 | ips->limits = ips_detect_cpu(ips); |
1528 | if (!ips->limits) { | 1528 | if (!ips->limits) { |
1529 | dev_info(&dev->dev, "IPS not supported on this CPU\n"); | 1529 | dev_info(&dev->dev, "IPS not supported on this CPU\n"); |
1530 | ret = -ENXIO; | 1530 | return -ENXIO; |
1531 | goto error_free; | ||
1532 | } | 1531 | } |
1533 | 1532 | ||
1534 | spin_lock_init(&ips->turbo_status_lock); | 1533 | ret = pcim_enable_device(dev); |
1535 | |||
1536 | ret = pci_enable_device(dev); | ||
1537 | if (ret) { | 1534 | if (ret) { |
1538 | dev_err(&dev->dev, "can't enable PCI device, aborting\n"); | 1535 | dev_err(&dev->dev, "can't enable PCI device, aborting\n"); |
1539 | goto error_free; | 1536 | return ret; |
1540 | } | 1537 | } |
1541 | 1538 | ||
1542 | if (!pci_resource_start(dev, 0)) { | 1539 | ret = pcim_iomap_regions(dev, 1 << 0, pci_name(dev)); |
1543 | dev_err(&dev->dev, "TBAR not assigned, aborting\n"); | ||
1544 | ret = -ENXIO; | ||
1545 | goto error_free; | ||
1546 | } | ||
1547 | |||
1548 | ret = pci_request_regions(dev, "ips thermal sensor"); | ||
1549 | if (ret) { | 1540 | if (ret) { |
1550 | dev_err(&dev->dev, "thermal resource busy, aborting\n"); | ||
1551 | goto error_free; | ||
1552 | } | ||
1553 | |||
1554 | |||
1555 | ips->regmap = ioremap(pci_resource_start(dev, 0), | ||
1556 | pci_resource_len(dev, 0)); | ||
1557 | if (!ips->regmap) { | ||
1558 | dev_err(&dev->dev, "failed to map thermal regs, aborting\n"); | 1541 | dev_err(&dev->dev, "failed to map thermal regs, aborting\n"); |
1559 | ret = -EBUSY; | 1542 | return ret; |
1560 | goto error_release; | ||
1561 | } | 1543 | } |
1544 | ips->regmap = pcim_iomap_table(dev)[0]; | ||
1545 | |||
1546 | pci_set_drvdata(dev, ips); | ||
1562 | 1547 | ||
1563 | tse = thm_readb(THM_TSE); | 1548 | tse = thm_readb(THM_TSE); |
1564 | if (tse != TSE_EN) { | 1549 | if (tse != TSE_EN) { |
1565 | dev_err(&dev->dev, "thermal device not enabled (0x%02x), aborting\n", tse); | 1550 | dev_err(&dev->dev, "thermal device not enabled (0x%02x), aborting\n", tse); |
1566 | ret = -ENXIO; | 1551 | return -ENXIO; |
1567 | goto error_unmap; | ||
1568 | } | 1552 | } |
1569 | 1553 | ||
1570 | trc = thm_readw(THM_TRC); | 1554 | trc = thm_readw(THM_TRC); |
1571 | trc_required_mask = TRC_CORE1_EN | TRC_CORE_PWR | TRC_MCH_EN; | 1555 | trc_required_mask = TRC_CORE1_EN | TRC_CORE_PWR | TRC_MCH_EN; |
1572 | if ((trc & trc_required_mask) != trc_required_mask) { | 1556 | if ((trc & trc_required_mask) != trc_required_mask) { |
1573 | dev_err(&dev->dev, "thermal reporting for required devices not enabled, aborting\n"); | 1557 | dev_err(&dev->dev, "thermal reporting for required devices not enabled, aborting\n"); |
1574 | ret = -ENXIO; | 1558 | return -ENXIO; |
1575 | goto error_unmap; | ||
1576 | } | 1559 | } |
1577 | 1560 | ||
1578 | if (trc & TRC_CORE2_EN) | 1561 | if (trc & TRC_CORE2_EN) |
@@ -1602,8 +1585,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
1602 | rdmsrl(PLATFORM_INFO, platform_info); | 1585 | rdmsrl(PLATFORM_INFO, platform_info); |
1603 | if (!(platform_info & PLATFORM_TDP)) { | 1586 | if (!(platform_info & PLATFORM_TDP)) { |
1604 | dev_err(&dev->dev, "platform indicates TDP override unavailable, aborting\n"); | 1587 | dev_err(&dev->dev, "platform indicates TDP override unavailable, aborting\n"); |
1605 | ret = -ENODEV; | 1588 | return -ENODEV; |
1606 | goto error_unmap; | ||
1607 | } | 1589 | } |
1608 | 1590 | ||
1609 | /* | 1591 | /* |
@@ -1615,7 +1597,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
1615 | ips); | 1597 | ips); |
1616 | if (ret) { | 1598 | if (ret) { |
1617 | dev_err(&dev->dev, "request irq failed, aborting\n"); | 1599 | dev_err(&dev->dev, "request irq failed, aborting\n"); |
1618 | goto error_unmap; | 1600 | return ret; |
1619 | } | 1601 | } |
1620 | 1602 | ||
1621 | /* Enable aux, hot & critical interrupts */ | 1603 | /* Enable aux, hot & critical interrupts */ |
@@ -1673,12 +1655,6 @@ error_thread_cleanup: | |||
1673 | kthread_stop(ips->adjust); | 1655 | kthread_stop(ips->adjust); |
1674 | error_free_irq: | 1656 | error_free_irq: |
1675 | free_irq(ips->dev->irq, ips); | 1657 | free_irq(ips->dev->irq, ips); |
1676 | error_unmap: | ||
1677 | iounmap(ips->regmap); | ||
1678 | error_release: | ||
1679 | pci_release_regions(dev); | ||
1680 | error_free: | ||
1681 | kfree(ips); | ||
1682 | return ret; | 1658 | return ret; |
1683 | } | 1659 | } |
1684 | 1660 | ||
@@ -1714,22 +1690,14 @@ static void ips_remove(struct pci_dev *dev) | |||
1714 | kthread_stop(ips->adjust); | 1690 | kthread_stop(ips->adjust); |
1715 | if (ips->monitor) | 1691 | if (ips->monitor) |
1716 | kthread_stop(ips->monitor); | 1692 | kthread_stop(ips->monitor); |
1717 | iounmap(ips->regmap); | ||
1718 | pci_release_regions(dev); | ||
1719 | kfree(ips); | ||
1720 | dev_dbg(&dev->dev, "IPS driver removed\n"); | 1693 | dev_dbg(&dev->dev, "IPS driver removed\n"); |
1721 | } | 1694 | } |
1722 | 1695 | ||
1723 | static void ips_shutdown(struct pci_dev *dev) | ||
1724 | { | ||
1725 | } | ||
1726 | |||
1727 | static struct pci_driver ips_pci_driver = { | 1696 | static struct pci_driver ips_pci_driver = { |
1728 | .name = "intel ips", | 1697 | .name = "intel ips", |
1729 | .id_table = ips_id_table, | 1698 | .id_table = ips_id_table, |
1730 | .probe = ips_probe, | 1699 | .probe = ips_probe, |
1731 | .remove = ips_remove, | 1700 | .remove = ips_remove, |
1732 | .shutdown = ips_shutdown, | ||
1733 | }; | 1701 | }; |
1734 | 1702 | ||
1735 | module_pci_driver(ips_pci_driver); | 1703 | module_pci_driver(ips_pci_driver); |