treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / platform / x86 / intel_bxtwc_tmu.c
blob7ccf583649e6beb8d0386d34305b1268b6c9843d
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Intel BXT Whiskey Cove PMIC TMU driver
5 * Copyright (C) 2016 Intel Corporation. All rights reserved.
7 * This driver adds TMU (Time Management Unit) support for Intel BXT platform.
8 * It enables the alarm wake-up functionality in the TMU unit of Whiskey Cove
9 * PMIC.
12 #include <linux/module.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/interrupt.h>
15 #include <linux/platform_device.h>
16 #include <linux/mfd/intel_soc_pmic.h>
18 #define BXTWC_TMUIRQ 0x4fb6
19 #define BXTWC_MIRQLVL1 0x4e0e
20 #define BXTWC_MTMUIRQ_REG 0x4fb7
21 #define BXTWC_MIRQLVL1_MTMU BIT(1)
22 #define BXTWC_TMU_WK_ALRM BIT(1)
23 #define BXTWC_TMU_SYS_ALRM BIT(2)
24 #define BXTWC_TMU_ALRM_MASK (BXTWC_TMU_WK_ALRM | BXTWC_TMU_SYS_ALRM)
25 #define BXTWC_TMU_ALRM_IRQ (BXTWC_TMU_WK_ALRM | BXTWC_TMU_SYS_ALRM)
27 struct wcove_tmu {
28 int irq;
29 struct device *dev;
30 struct regmap *regmap;
33 static irqreturn_t bxt_wcove_tmu_irq_handler(int irq, void *data)
35 struct wcove_tmu *wctmu = data;
36 unsigned int tmu_irq;
38 /* Read TMU interrupt reg */
39 regmap_read(wctmu->regmap, BXTWC_TMUIRQ, &tmu_irq);
40 if (tmu_irq & BXTWC_TMU_ALRM_IRQ) {
41 /* clear TMU irq */
42 regmap_write(wctmu->regmap, BXTWC_TMUIRQ, tmu_irq);
43 return IRQ_HANDLED;
45 return IRQ_NONE;
48 static int bxt_wcove_tmu_probe(struct platform_device *pdev)
50 struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
51 struct regmap_irq_chip_data *regmap_irq_chip;
52 struct wcove_tmu *wctmu;
53 int ret, virq, irq;
55 wctmu = devm_kzalloc(&pdev->dev, sizeof(*wctmu), GFP_KERNEL);
56 if (!wctmu)
57 return -ENOMEM;
59 wctmu->dev = &pdev->dev;
60 wctmu->regmap = pmic->regmap;
62 irq = platform_get_irq(pdev, 0);
63 if (irq < 0)
64 return irq;
66 regmap_irq_chip = pmic->irq_chip_data_tmu;
67 virq = regmap_irq_get_virq(regmap_irq_chip, irq);
68 if (virq < 0) {
69 dev_err(&pdev->dev,
70 "failed to get virtual interrupt=%d\n", irq);
71 return virq;
74 ret = devm_request_threaded_irq(&pdev->dev, virq,
75 NULL, bxt_wcove_tmu_irq_handler,
76 IRQF_ONESHOT, "bxt_wcove_tmu", wctmu);
77 if (ret) {
78 dev_err(&pdev->dev, "request irq failed: %d,virq: %d\n",
79 ret, virq);
80 return ret;
82 wctmu->irq = virq;
84 /* Unmask TMU second level Wake & System alarm */
85 regmap_update_bits(wctmu->regmap, BXTWC_MTMUIRQ_REG,
86 BXTWC_TMU_ALRM_MASK, 0);
88 platform_set_drvdata(pdev, wctmu);
89 return 0;
92 static int bxt_wcove_tmu_remove(struct platform_device *pdev)
94 struct wcove_tmu *wctmu = platform_get_drvdata(pdev);
95 unsigned int val;
97 /* Mask TMU interrupts */
98 regmap_read(wctmu->regmap, BXTWC_MIRQLVL1, &val);
99 regmap_write(wctmu->regmap, BXTWC_MIRQLVL1,
100 val | BXTWC_MIRQLVL1_MTMU);
101 regmap_read(wctmu->regmap, BXTWC_MTMUIRQ_REG, &val);
102 regmap_write(wctmu->regmap, BXTWC_MTMUIRQ_REG,
103 val | BXTWC_TMU_ALRM_MASK);
104 return 0;
107 #ifdef CONFIG_PM_SLEEP
108 static int bxtwc_tmu_suspend(struct device *dev)
110 struct wcove_tmu *wctmu = dev_get_drvdata(dev);
112 enable_irq_wake(wctmu->irq);
113 return 0;
116 static int bxtwc_tmu_resume(struct device *dev)
118 struct wcove_tmu *wctmu = dev_get_drvdata(dev);
120 disable_irq_wake(wctmu->irq);
121 return 0;
123 #endif
125 static SIMPLE_DEV_PM_OPS(bxtwc_tmu_pm_ops, bxtwc_tmu_suspend, bxtwc_tmu_resume);
127 static const struct platform_device_id bxt_wcove_tmu_id_table[] = {
128 { .name = "bxt_wcove_tmu" },
131 MODULE_DEVICE_TABLE(platform, bxt_wcove_tmu_id_table);
133 static struct platform_driver bxt_wcove_tmu_driver = {
134 .probe = bxt_wcove_tmu_probe,
135 .remove = bxt_wcove_tmu_remove,
136 .driver = {
137 .name = "bxt_wcove_tmu",
138 .pm = &bxtwc_tmu_pm_ops,
140 .id_table = bxt_wcove_tmu_id_table,
143 module_platform_driver(bxt_wcove_tmu_driver);
145 MODULE_LICENSE("GPL v2");
146 MODULE_AUTHOR("Nilesh Bacchewar <nilesh.bacchewar@intel.com>");
147 MODULE_DESCRIPTION("BXT Whiskey Cove TMU Driver");