xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // Copyright (c) 2020 MediaTek Inc. |
| 4 | |
| 5 | #include <linux/interrupt.h> |
| 6 | #include <linux/mfd/mt6330/core.h> |
| 7 | #include <linux/mfd/mt6330/registers.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/mutex.h> |
| 10 | #include <linux/of_device.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/reboot.h> |
| 13 | #include <linux/regmap.h> |
| 14 | #include <linux/suspend.h> |
| 15 | |
| 16 | static struct regmap *g_regmap; |
| 17 | |
| 18 | static irqreturn_t ot_int_handler(int irq, void *data) |
| 19 | { |
| 20 | int ret, irq_index = (uintptr_t)data; |
| 21 | |
| 22 | pr_info("%s with irq index=%d\n", __func__, irq_index); |
| 23 | ret = regmap_update_bits(g_regmap, |
| 24 | PMIC_RG_RSV_SWREG_ADDR, |
| 25 | 1 << irq_index, |
| 26 | 1 << irq_index); |
| 27 | if (ret) |
| 28 | pr_info("%s error\n", __func__); |
| 29 | |
| 30 | if (mutex_trylock(&system_transition_mutex)) { |
| 31 | kernel_power_off(); |
| 32 | mutex_unlock(&system_transition_mutex); |
| 33 | } |
| 34 | return IRQ_HANDLED; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | static int mt63xx_ot_debug_probe(struct platform_device *pdev) |
| 39 | { |
| 40 | struct mt6330_chip *pmic = dev_get_drvdata(pdev->dev.parent); |
| 41 | int i = 0, virq = 0, num_irqs = 0, ret = 0; |
| 42 | |
| 43 | g_regmap = pmic->regmap; |
| 44 | if (!g_regmap) |
| 45 | return -ENODEV; |
| 46 | |
| 47 | num_irqs = platform_irq_count(pdev); |
| 48 | if (num_irqs <= 0) |
| 49 | return num_irqs; |
| 50 | |
| 51 | for (i = 0; i < num_irqs; i++) { |
| 52 | virq = platform_get_irq(pdev, i); |
| 53 | if (virq <= 0) { |
| 54 | dev_notice(&pdev->dev, "get virq fail\n"); |
| 55 | continue; |
| 56 | } |
| 57 | ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, |
| 58 | ot_int_handler, |
| 59 | IRQF_TRIGGER_NONE, |
| 60 | "PMIC_OT", |
| 61 | (void *)(uintptr_t)i); |
| 62 | if (ret < 0) |
| 63 | dev_notice(&pdev->dev, "request irq fail\n"); |
| 64 | } |
| 65 | dev_info(&pdev->dev, "%s\n", __func__); |
| 66 | |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | static const struct of_device_id mt63xx_ot_debug_of_match[] = { |
| 71 | { |
| 72 | .compatible = "mediatek,mt63xx-ot-debug", |
| 73 | }, { |
| 74 | /* sentinel */ |
| 75 | } |
| 76 | }; |
| 77 | MODULE_DEVICE_TABLE(of, mt63xx_ot_debug_of_match); |
| 78 | |
| 79 | static struct platform_driver mt63xx_ot_debug_driver = { |
| 80 | .driver = { |
| 81 | .name = "mt63xx-ot-debug", |
| 82 | .of_match_table = mt63xx_ot_debug_of_match, |
| 83 | }, |
| 84 | .probe = mt63xx_ot_debug_probe, |
| 85 | }; |
| 86 | module_platform_driver(mt63xx_ot_debug_driver); |
| 87 | |
| 88 | MODULE_LICENSE("GPL v2"); |
| 89 | MODULE_AUTHOR("Wen Su <wen.su@mediatek.com>"); |
| 90 | MODULE_DESCRIPTION("PMIC Over Thermal Debug driver for MediaTek MT63xx PMIC"); |