19c92ab61SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 23e9f0b3eSChen Zhong /* 33e9f0b3eSChen Zhong * Copyright (C) 2017 MediaTek, Inc. 43e9f0b3eSChen Zhong * 53e9f0b3eSChen Zhong * Author: Chen Zhong <chen.zhong@mediatek.com> 63e9f0b3eSChen Zhong */ 73e9f0b3eSChen Zhong 83e9f0b3eSChen Zhong #include <linux/input.h> 93e9f0b3eSChen Zhong #include <linux/interrupt.h> 103e9f0b3eSChen Zhong #include <linux/kernel.h> 113e9f0b3eSChen Zhong #include <linux/mfd/mt6323/registers.h> 12994673dcSMattijs Korpershoek #include <linux/mfd/mt6358/registers.h> 133e9f0b3eSChen Zhong #include <linux/mfd/mt6397/core.h> 141eb7ea26SYueHaibing #include <linux/mfd/mt6397/registers.h> 151eb7ea26SYueHaibing #include <linux/module.h> 161eb7ea26SYueHaibing #include <linux/of_device.h> 171eb7ea26SYueHaibing #include <linux/of.h> 181eb7ea26SYueHaibing #include <linux/platform_device.h> 191eb7ea26SYueHaibing #include <linux/regmap.h> 203e9f0b3eSChen Zhong 212a0a5828SDmitry Torokhov #define MTK_PMIC_RST_DU_MASK GENMASK(9, 8) 223e9f0b3eSChen Zhong #define MTK_PMIC_RST_DU_SHIFT 8 232a0a5828SDmitry Torokhov #define MTK_PMIC_PWRKEY_RST BIT(6) 242a0a5828SDmitry Torokhov #define MTK_PMIC_HOMEKEY_RST BIT(5) 253e9f0b3eSChen Zhong 263e9f0b3eSChen Zhong #define MTK_PMIC_PWRKEY_INDEX 0 273e9f0b3eSChen Zhong #define MTK_PMIC_HOMEKEY_INDEX 1 283e9f0b3eSChen Zhong #define MTK_PMIC_MAX_KEY_COUNT 2 293e9f0b3eSChen Zhong 303e9f0b3eSChen Zhong struct mtk_pmic_keys_regs { 313e9f0b3eSChen Zhong u32 deb_reg; 323e9f0b3eSChen Zhong u32 deb_mask; 333e9f0b3eSChen Zhong u32 intsel_reg; 343e9f0b3eSChen Zhong u32 intsel_mask; 35*b581acb4SAngeloGioacchino Del Regno u32 rst_en_mask; 363e9f0b3eSChen Zhong }; 373e9f0b3eSChen Zhong 383e9f0b3eSChen Zhong #define MTK_PMIC_KEYS_REGS(_deb_reg, _deb_mask, \ 39*b581acb4SAngeloGioacchino Del Regno _intsel_reg, _intsel_mask, _rst_mask) \ 403e9f0b3eSChen Zhong { \ 413e9f0b3eSChen Zhong .deb_reg = _deb_reg, \ 423e9f0b3eSChen Zhong .deb_mask = _deb_mask, \ 433e9f0b3eSChen Zhong .intsel_reg = _intsel_reg, \ 443e9f0b3eSChen Zhong .intsel_mask = _intsel_mask, \ 45*b581acb4SAngeloGioacchino Del Regno .rst_en_mask = _rst_mask, \ 463e9f0b3eSChen Zhong } 473e9f0b3eSChen Zhong 483e9f0b3eSChen Zhong struct mtk_pmic_regs { 493e9f0b3eSChen Zhong const struct mtk_pmic_keys_regs keys_regs[MTK_PMIC_MAX_KEY_COUNT]; 503e9f0b3eSChen Zhong u32 pmic_rst_reg; 513e9f0b3eSChen Zhong }; 523e9f0b3eSChen Zhong 533e9f0b3eSChen Zhong static const struct mtk_pmic_regs mt6397_regs = { 543e9f0b3eSChen Zhong .keys_regs[MTK_PMIC_PWRKEY_INDEX] = 553e9f0b3eSChen Zhong MTK_PMIC_KEYS_REGS(MT6397_CHRSTATUS, 56*b581acb4SAngeloGioacchino Del Regno 0x8, MT6397_INT_RSV, 0x10, MTK_PMIC_PWRKEY_RST), 573e9f0b3eSChen Zhong .keys_regs[MTK_PMIC_HOMEKEY_INDEX] = 583e9f0b3eSChen Zhong MTK_PMIC_KEYS_REGS(MT6397_OCSTATUS2, 59*b581acb4SAngeloGioacchino Del Regno 0x10, MT6397_INT_RSV, 0x8, MTK_PMIC_HOMEKEY_RST), 603e9f0b3eSChen Zhong .pmic_rst_reg = MT6397_TOP_RST_MISC, 613e9f0b3eSChen Zhong }; 623e9f0b3eSChen Zhong 633e9f0b3eSChen Zhong static const struct mtk_pmic_regs mt6323_regs = { 643e9f0b3eSChen Zhong .keys_regs[MTK_PMIC_PWRKEY_INDEX] = 653e9f0b3eSChen Zhong MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS, 66*b581acb4SAngeloGioacchino Del Regno 0x2, MT6323_INT_MISC_CON, 0x10, MTK_PMIC_PWRKEY_RST), 673e9f0b3eSChen Zhong .keys_regs[MTK_PMIC_HOMEKEY_INDEX] = 683e9f0b3eSChen Zhong MTK_PMIC_KEYS_REGS(MT6323_CHRSTATUS, 69*b581acb4SAngeloGioacchino Del Regno 0x4, MT6323_INT_MISC_CON, 0x8, MTK_PMIC_HOMEKEY_RST), 703e9f0b3eSChen Zhong .pmic_rst_reg = MT6323_TOP_RST_MISC, 713e9f0b3eSChen Zhong }; 723e9f0b3eSChen Zhong 73994673dcSMattijs Korpershoek static const struct mtk_pmic_regs mt6358_regs = { 74994673dcSMattijs Korpershoek .keys_regs[MTK_PMIC_PWRKEY_INDEX] = 75994673dcSMattijs Korpershoek MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS, 76*b581acb4SAngeloGioacchino Del Regno 0x2, MT6358_PSC_TOP_INT_CON0, 0x5, 77*b581acb4SAngeloGioacchino Del Regno MTK_PMIC_PWRKEY_RST), 78994673dcSMattijs Korpershoek .keys_regs[MTK_PMIC_HOMEKEY_INDEX] = 79994673dcSMattijs Korpershoek MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS, 80*b581acb4SAngeloGioacchino Del Regno 0x8, MT6358_PSC_TOP_INT_CON0, 0xa, 81*b581acb4SAngeloGioacchino Del Regno MTK_PMIC_HOMEKEY_RST), 82994673dcSMattijs Korpershoek .pmic_rst_reg = MT6358_TOP_RST_MISC, 83994673dcSMattijs Korpershoek }; 84994673dcSMattijs Korpershoek 853e9f0b3eSChen Zhong struct mtk_pmic_keys_info { 863e9f0b3eSChen Zhong struct mtk_pmic_keys *keys; 873e9f0b3eSChen Zhong const struct mtk_pmic_keys_regs *regs; 883e9f0b3eSChen Zhong unsigned int keycode; 893e9f0b3eSChen Zhong int irq; 90994673dcSMattijs Korpershoek int irq_r; /* optional: release irq if different */ 913e9f0b3eSChen Zhong bool wakeup:1; 923e9f0b3eSChen Zhong }; 933e9f0b3eSChen Zhong 943e9f0b3eSChen Zhong struct mtk_pmic_keys { 953e9f0b3eSChen Zhong struct input_dev *input_dev; 963e9f0b3eSChen Zhong struct device *dev; 973e9f0b3eSChen Zhong struct regmap *regmap; 983e9f0b3eSChen Zhong struct mtk_pmic_keys_info keys[MTK_PMIC_MAX_KEY_COUNT]; 993e9f0b3eSChen Zhong }; 1003e9f0b3eSChen Zhong 1013e9f0b3eSChen Zhong enum mtk_pmic_keys_lp_mode { 1023e9f0b3eSChen Zhong LP_DISABLE, 1033e9f0b3eSChen Zhong LP_ONEKEY, 1043e9f0b3eSChen Zhong LP_TWOKEY, 1053e9f0b3eSChen Zhong }; 1063e9f0b3eSChen Zhong 1073e9f0b3eSChen Zhong static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys, 1083e9f0b3eSChen Zhong u32 pmic_rst_reg) 1093e9f0b3eSChen Zhong { 110*b581acb4SAngeloGioacchino Del Regno const struct mtk_pmic_keys_regs *kregs_home, *kregs_pwr; 1113e9f0b3eSChen Zhong u32 long_press_mode, long_press_debounce; 1122a0a5828SDmitry Torokhov u32 value, mask; 1132a0a5828SDmitry Torokhov int error; 1143e9f0b3eSChen Zhong 115*b581acb4SAngeloGioacchino Del Regno kregs_home = keys->keys[MTK_PMIC_HOMEKEY_INDEX].regs; 116*b581acb4SAngeloGioacchino Del Regno kregs_pwr = keys->keys[MTK_PMIC_PWRKEY_INDEX].regs; 117*b581acb4SAngeloGioacchino Del Regno 1182a0a5828SDmitry Torokhov error = of_property_read_u32(keys->dev->of_node, "power-off-time-sec", 1192a0a5828SDmitry Torokhov &long_press_debounce); 1202a0a5828SDmitry Torokhov if (error) 1213e9f0b3eSChen Zhong long_press_debounce = 0; 1223e9f0b3eSChen Zhong 1232a0a5828SDmitry Torokhov mask = MTK_PMIC_RST_DU_MASK; 1242a0a5828SDmitry Torokhov value = long_press_debounce << MTK_PMIC_RST_DU_SHIFT; 1253e9f0b3eSChen Zhong 1262a0a5828SDmitry Torokhov error = of_property_read_u32(keys->dev->of_node, 1272a0a5828SDmitry Torokhov "mediatek,long-press-mode", 1282a0a5828SDmitry Torokhov &long_press_mode); 1292a0a5828SDmitry Torokhov if (error) 1303e9f0b3eSChen Zhong long_press_mode = LP_DISABLE; 1313e9f0b3eSChen Zhong 1323e9f0b3eSChen Zhong switch (long_press_mode) { 1333e9f0b3eSChen Zhong case LP_TWOKEY: 134*b581acb4SAngeloGioacchino Del Regno value |= kregs_home->rst_en_mask; 1352a0a5828SDmitry Torokhov fallthrough; 1362a0a5828SDmitry Torokhov 1372a0a5828SDmitry Torokhov case LP_ONEKEY: 138*b581acb4SAngeloGioacchino Del Regno value |= kregs_pwr->rst_en_mask; 1392a0a5828SDmitry Torokhov fallthrough; 1402a0a5828SDmitry Torokhov 1413e9f0b3eSChen Zhong case LP_DISABLE: 142*b581acb4SAngeloGioacchino Del Regno mask |= kregs_home->rst_en_mask; 143*b581acb4SAngeloGioacchino Del Regno mask |= kregs_pwr->rst_en_mask; 1443e9f0b3eSChen Zhong break; 1452a0a5828SDmitry Torokhov 1463e9f0b3eSChen Zhong default: 1473e9f0b3eSChen Zhong break; 1483e9f0b3eSChen Zhong } 1492a0a5828SDmitry Torokhov 1502a0a5828SDmitry Torokhov regmap_update_bits(keys->regmap, pmic_rst_reg, mask, value); 1513e9f0b3eSChen Zhong } 1523e9f0b3eSChen Zhong 1533e9f0b3eSChen Zhong static irqreturn_t mtk_pmic_keys_irq_handler_thread(int irq, void *data) 1543e9f0b3eSChen Zhong { 1553e9f0b3eSChen Zhong struct mtk_pmic_keys_info *info = data; 1563e9f0b3eSChen Zhong u32 key_deb, pressed; 1573e9f0b3eSChen Zhong 1583e9f0b3eSChen Zhong regmap_read(info->keys->regmap, info->regs->deb_reg, &key_deb); 1593e9f0b3eSChen Zhong 1603e9f0b3eSChen Zhong key_deb &= info->regs->deb_mask; 1613e9f0b3eSChen Zhong 1623e9f0b3eSChen Zhong pressed = !key_deb; 1633e9f0b3eSChen Zhong 1643e9f0b3eSChen Zhong input_report_key(info->keys->input_dev, info->keycode, pressed); 1653e9f0b3eSChen Zhong input_sync(info->keys->input_dev); 1663e9f0b3eSChen Zhong 1673e9f0b3eSChen Zhong dev_dbg(info->keys->dev, "(%s) key =%d using PMIC\n", 1683e9f0b3eSChen Zhong pressed ? "pressed" : "released", info->keycode); 1693e9f0b3eSChen Zhong 1703e9f0b3eSChen Zhong return IRQ_HANDLED; 1713e9f0b3eSChen Zhong } 1723e9f0b3eSChen Zhong 1733e9f0b3eSChen Zhong static int mtk_pmic_key_setup(struct mtk_pmic_keys *keys, 1743e9f0b3eSChen Zhong struct mtk_pmic_keys_info *info) 1753e9f0b3eSChen Zhong { 1763e9f0b3eSChen Zhong int ret; 1773e9f0b3eSChen Zhong 1783e9f0b3eSChen Zhong info->keys = keys; 1793e9f0b3eSChen Zhong 1803e9f0b3eSChen Zhong ret = regmap_update_bits(keys->regmap, info->regs->intsel_reg, 1813e9f0b3eSChen Zhong info->regs->intsel_mask, 1823e9f0b3eSChen Zhong info->regs->intsel_mask); 1833e9f0b3eSChen Zhong if (ret < 0) 1843e9f0b3eSChen Zhong return ret; 1853e9f0b3eSChen Zhong 1863e9f0b3eSChen Zhong ret = devm_request_threaded_irq(keys->dev, info->irq, NULL, 1873e9f0b3eSChen Zhong mtk_pmic_keys_irq_handler_thread, 1883e9f0b3eSChen Zhong IRQF_ONESHOT | IRQF_TRIGGER_HIGH, 1893e9f0b3eSChen Zhong "mtk-pmic-keys", info); 1903e9f0b3eSChen Zhong if (ret) { 1913e9f0b3eSChen Zhong dev_err(keys->dev, "Failed to request IRQ: %d: %d\n", 1923e9f0b3eSChen Zhong info->irq, ret); 1933e9f0b3eSChen Zhong return ret; 1943e9f0b3eSChen Zhong } 1953e9f0b3eSChen Zhong 196994673dcSMattijs Korpershoek if (info->irq_r > 0) { 197994673dcSMattijs Korpershoek ret = devm_request_threaded_irq(keys->dev, info->irq_r, NULL, 198994673dcSMattijs Korpershoek mtk_pmic_keys_irq_handler_thread, 199994673dcSMattijs Korpershoek IRQF_ONESHOT | IRQF_TRIGGER_HIGH, 200994673dcSMattijs Korpershoek "mtk-pmic-keys", info); 201994673dcSMattijs Korpershoek if (ret) { 202994673dcSMattijs Korpershoek dev_err(keys->dev, "Failed to request IRQ_r: %d: %d\n", 203994673dcSMattijs Korpershoek info->irq, ret); 204994673dcSMattijs Korpershoek return ret; 205994673dcSMattijs Korpershoek } 206994673dcSMattijs Korpershoek } 207994673dcSMattijs Korpershoek 2083e9f0b3eSChen Zhong input_set_capability(keys->input_dev, EV_KEY, info->keycode); 2093e9f0b3eSChen Zhong 2103e9f0b3eSChen Zhong return 0; 2113e9f0b3eSChen Zhong } 2123e9f0b3eSChen Zhong 2133e9f0b3eSChen Zhong static int __maybe_unused mtk_pmic_keys_suspend(struct device *dev) 2143e9f0b3eSChen Zhong { 2153e9f0b3eSChen Zhong struct mtk_pmic_keys *keys = dev_get_drvdata(dev); 2163e9f0b3eSChen Zhong int index; 2173e9f0b3eSChen Zhong 2183e9f0b3eSChen Zhong for (index = 0; index < MTK_PMIC_MAX_KEY_COUNT; index++) { 219994673dcSMattijs Korpershoek if (keys->keys[index].wakeup) { 2203e9f0b3eSChen Zhong enable_irq_wake(keys->keys[index].irq); 221994673dcSMattijs Korpershoek if (keys->keys[index].irq_r > 0) 222994673dcSMattijs Korpershoek enable_irq_wake(keys->keys[index].irq_r); 223994673dcSMattijs Korpershoek } 2243e9f0b3eSChen Zhong } 2253e9f0b3eSChen Zhong 2263e9f0b3eSChen Zhong return 0; 2273e9f0b3eSChen Zhong } 2283e9f0b3eSChen Zhong 2293e9f0b3eSChen Zhong static int __maybe_unused mtk_pmic_keys_resume(struct device *dev) 2303e9f0b3eSChen Zhong { 2313e9f0b3eSChen Zhong struct mtk_pmic_keys *keys = dev_get_drvdata(dev); 2323e9f0b3eSChen Zhong int index; 2333e9f0b3eSChen Zhong 2343e9f0b3eSChen Zhong for (index = 0; index < MTK_PMIC_MAX_KEY_COUNT; index++) { 235994673dcSMattijs Korpershoek if (keys->keys[index].wakeup) { 2363e9f0b3eSChen Zhong disable_irq_wake(keys->keys[index].irq); 237994673dcSMattijs Korpershoek if (keys->keys[index].irq_r > 0) 238994673dcSMattijs Korpershoek disable_irq_wake(keys->keys[index].irq_r); 239994673dcSMattijs Korpershoek } 2403e9f0b3eSChen Zhong } 2413e9f0b3eSChen Zhong 2423e9f0b3eSChen Zhong return 0; 2433e9f0b3eSChen Zhong } 2443e9f0b3eSChen Zhong 2453e9f0b3eSChen Zhong static SIMPLE_DEV_PM_OPS(mtk_pmic_keys_pm_ops, mtk_pmic_keys_suspend, 2463e9f0b3eSChen Zhong mtk_pmic_keys_resume); 2473e9f0b3eSChen Zhong 2483e9f0b3eSChen Zhong static const struct of_device_id of_mtk_pmic_keys_match_tbl[] = { 2493e9f0b3eSChen Zhong { 2503e9f0b3eSChen Zhong .compatible = "mediatek,mt6397-keys", 2513e9f0b3eSChen Zhong .data = &mt6397_regs, 2523e9f0b3eSChen Zhong }, { 2533e9f0b3eSChen Zhong .compatible = "mediatek,mt6323-keys", 2543e9f0b3eSChen Zhong .data = &mt6323_regs, 2553e9f0b3eSChen Zhong }, { 256994673dcSMattijs Korpershoek .compatible = "mediatek,mt6358-keys", 257994673dcSMattijs Korpershoek .data = &mt6358_regs, 258994673dcSMattijs Korpershoek }, { 2593e9f0b3eSChen Zhong /* sentinel */ 2603e9f0b3eSChen Zhong } 2613e9f0b3eSChen Zhong }; 2623e9f0b3eSChen Zhong MODULE_DEVICE_TABLE(of, of_mtk_pmic_keys_match_tbl); 2633e9f0b3eSChen Zhong 2643e9f0b3eSChen Zhong static int mtk_pmic_keys_probe(struct platform_device *pdev) 2653e9f0b3eSChen Zhong { 2663e9f0b3eSChen Zhong int error, index = 0; 2673e9f0b3eSChen Zhong unsigned int keycount; 2683e9f0b3eSChen Zhong struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent); 2693e9f0b3eSChen Zhong struct device_node *node = pdev->dev.of_node, *child; 270f4e09e8bSMattijs Korpershoek static const char *const irqnames[] = { "powerkey", "homekey" }; 271994673dcSMattijs Korpershoek static const char *const irqnames_r[] = { "powerkey_r", "homekey_r" }; 2723e9f0b3eSChen Zhong struct mtk_pmic_keys *keys; 2733e9f0b3eSChen Zhong const struct mtk_pmic_regs *mtk_pmic_regs; 2743e9f0b3eSChen Zhong struct input_dev *input_dev; 2753e9f0b3eSChen Zhong const struct of_device_id *of_id = 2763e9f0b3eSChen Zhong of_match_device(of_mtk_pmic_keys_match_tbl, &pdev->dev); 2773e9f0b3eSChen Zhong 2783e9f0b3eSChen Zhong keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL); 2793e9f0b3eSChen Zhong if (!keys) 2803e9f0b3eSChen Zhong return -ENOMEM; 2813e9f0b3eSChen Zhong 2823e9f0b3eSChen Zhong keys->dev = &pdev->dev; 2833e9f0b3eSChen Zhong keys->regmap = pmic_chip->regmap; 2843e9f0b3eSChen Zhong mtk_pmic_regs = of_id->data; 2853e9f0b3eSChen Zhong 2863e9f0b3eSChen Zhong keys->input_dev = input_dev = devm_input_allocate_device(keys->dev); 2873e9f0b3eSChen Zhong if (!input_dev) { 2883e9f0b3eSChen Zhong dev_err(keys->dev, "input allocate device fail.\n"); 2893e9f0b3eSChen Zhong return -ENOMEM; 2903e9f0b3eSChen Zhong } 2913e9f0b3eSChen Zhong 2923e9f0b3eSChen Zhong input_dev->name = "mtk-pmic-keys"; 2933e9f0b3eSChen Zhong input_dev->id.bustype = BUS_HOST; 2943e9f0b3eSChen Zhong input_dev->id.vendor = 0x0001; 2953e9f0b3eSChen Zhong input_dev->id.product = 0x0001; 2963e9f0b3eSChen Zhong input_dev->id.version = 0x0001; 2973e9f0b3eSChen Zhong 2983e9f0b3eSChen Zhong keycount = of_get_available_child_count(node); 299f4e09e8bSMattijs Korpershoek if (keycount > MTK_PMIC_MAX_KEY_COUNT || 300f4e09e8bSMattijs Korpershoek keycount > ARRAY_SIZE(irqnames)) { 3013e9f0b3eSChen Zhong dev_err(keys->dev, "too many keys defined (%d)\n", keycount); 3023e9f0b3eSChen Zhong return -EINVAL; 3033e9f0b3eSChen Zhong } 3043e9f0b3eSChen Zhong 3053e9f0b3eSChen Zhong for_each_child_of_node(node, child) { 3063e9f0b3eSChen Zhong keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index]; 3073e9f0b3eSChen Zhong 308f4e09e8bSMattijs Korpershoek keys->keys[index].irq = 309f4e09e8bSMattijs Korpershoek platform_get_irq_byname(pdev, irqnames[index]); 310cc95527cSNishka Dasgupta if (keys->keys[index].irq < 0) { 311cc95527cSNishka Dasgupta of_node_put(child); 3123e9f0b3eSChen Zhong return keys->keys[index].irq; 313cc95527cSNishka Dasgupta } 3143e9f0b3eSChen Zhong 315994673dcSMattijs Korpershoek if (of_device_is_compatible(node, "mediatek,mt6358-keys")) { 316994673dcSMattijs Korpershoek keys->keys[index].irq_r = platform_get_irq_byname(pdev, 317994673dcSMattijs Korpershoek irqnames_r[index]); 318994673dcSMattijs Korpershoek 319994673dcSMattijs Korpershoek if (keys->keys[index].irq_r < 0) { 320994673dcSMattijs Korpershoek of_node_put(child); 321994673dcSMattijs Korpershoek return keys->keys[index].irq_r; 322994673dcSMattijs Korpershoek } 323994673dcSMattijs Korpershoek } 324994673dcSMattijs Korpershoek 3253e9f0b3eSChen Zhong error = of_property_read_u32(child, 3263e9f0b3eSChen Zhong "linux,keycodes", &keys->keys[index].keycode); 3273e9f0b3eSChen Zhong if (error) { 3283e9f0b3eSChen Zhong dev_err(keys->dev, 3293e9f0b3eSChen Zhong "failed to read key:%d linux,keycode property: %d\n", 3303e9f0b3eSChen Zhong index, error); 331cc95527cSNishka Dasgupta of_node_put(child); 3323e9f0b3eSChen Zhong return error; 3333e9f0b3eSChen Zhong } 3343e9f0b3eSChen Zhong 3353e9f0b3eSChen Zhong if (of_property_read_bool(child, "wakeup-source")) 3363e9f0b3eSChen Zhong keys->keys[index].wakeup = true; 3373e9f0b3eSChen Zhong 3383e9f0b3eSChen Zhong error = mtk_pmic_key_setup(keys, &keys->keys[index]); 339cc95527cSNishka Dasgupta if (error) { 340cc95527cSNishka Dasgupta of_node_put(child); 3413e9f0b3eSChen Zhong return error; 342cc95527cSNishka Dasgupta } 3433e9f0b3eSChen Zhong 3443e9f0b3eSChen Zhong index++; 3453e9f0b3eSChen Zhong } 3463e9f0b3eSChen Zhong 3473e9f0b3eSChen Zhong error = input_register_device(input_dev); 3483e9f0b3eSChen Zhong if (error) { 3493e9f0b3eSChen Zhong dev_err(&pdev->dev, 3503e9f0b3eSChen Zhong "register input device failed (%d)\n", error); 3513e9f0b3eSChen Zhong return error; 3523e9f0b3eSChen Zhong } 3533e9f0b3eSChen Zhong 3543e9f0b3eSChen Zhong mtk_pmic_keys_lp_reset_setup(keys, mtk_pmic_regs->pmic_rst_reg); 3553e9f0b3eSChen Zhong 3563e9f0b3eSChen Zhong platform_set_drvdata(pdev, keys); 3573e9f0b3eSChen Zhong 3583e9f0b3eSChen Zhong return 0; 3593e9f0b3eSChen Zhong } 3603e9f0b3eSChen Zhong 3613e9f0b3eSChen Zhong static struct platform_driver pmic_keys_pdrv = { 3623e9f0b3eSChen Zhong .probe = mtk_pmic_keys_probe, 3633e9f0b3eSChen Zhong .driver = { 3643e9f0b3eSChen Zhong .name = "mtk-pmic-keys", 3653e9f0b3eSChen Zhong .of_match_table = of_mtk_pmic_keys_match_tbl, 3663e9f0b3eSChen Zhong .pm = &mtk_pmic_keys_pm_ops, 3673e9f0b3eSChen Zhong }, 3683e9f0b3eSChen Zhong }; 3693e9f0b3eSChen Zhong 3703e9f0b3eSChen Zhong module_platform_driver(pmic_keys_pdrv); 3713e9f0b3eSChen Zhong 3723e9f0b3eSChen Zhong MODULE_LICENSE("GPL v2"); 3733e9f0b3eSChen Zhong MODULE_AUTHOR("Chen Zhong <chen.zhong@mediatek.com>"); 3743e9f0b3eSChen Zhong MODULE_DESCRIPTION("MTK pmic-keys driver v0.1"); 375