Lines Matching +full:mt6397 +full:- +full:keys

1 // SPDX-License-Identifier: GPL-2.0-only
15 #include <linux/mfd/mt6397/core.h>
16 #include <linux/mfd/mt6397/registers.h>
56 u32 rst_lprst_mask; /* Long-press reset timeout bitmask */
121 struct mtk_pmic_keys *keys; member
133 struct mtk_pmic_keys_info keys[MTK_PMIC_MAX_KEY_COUNT]; member
142 static void mtk_pmic_keys_lp_reset_setup(struct mtk_pmic_keys *keys, in mtk_pmic_keys_lp_reset_setup() argument
150 kregs_home = keys->keys[MTK_PMIC_HOMEKEY_INDEX].regs; in mtk_pmic_keys_lp_reset_setup()
151 kregs_pwr = keys->keys[MTK_PMIC_PWRKEY_INDEX].regs; in mtk_pmic_keys_lp_reset_setup()
153 error = of_property_read_u32(keys->dev->of_node, "power-off-time-sec", in mtk_pmic_keys_lp_reset_setup()
158 mask = regs->rst_lprst_mask; in mtk_pmic_keys_lp_reset_setup()
159 value = long_press_debounce << (ffs(regs->rst_lprst_mask) - 1); in mtk_pmic_keys_lp_reset_setup()
161 error = of_property_read_u32(keys->dev->of_node, in mtk_pmic_keys_lp_reset_setup()
162 "mediatek,long-press-mode", in mtk_pmic_keys_lp_reset_setup()
169 value |= kregs_home->rst_en_mask; in mtk_pmic_keys_lp_reset_setup()
173 value |= kregs_pwr->rst_en_mask; in mtk_pmic_keys_lp_reset_setup()
177 mask |= kregs_home->rst_en_mask; in mtk_pmic_keys_lp_reset_setup()
178 mask |= kregs_pwr->rst_en_mask; in mtk_pmic_keys_lp_reset_setup()
185 regmap_update_bits(keys->regmap, regs->pmic_rst_reg, mask, value); in mtk_pmic_keys_lp_reset_setup()
193 regmap_read(info->keys->regmap, info->regs->deb_reg, &key_deb); in mtk_pmic_keys_irq_handler_thread()
195 key_deb &= info->regs->deb_mask; in mtk_pmic_keys_irq_handler_thread()
199 input_report_key(info->keys->input_dev, info->keycode, pressed); in mtk_pmic_keys_irq_handler_thread()
200 input_sync(info->keys->input_dev); in mtk_pmic_keys_irq_handler_thread()
202 dev_dbg(info->keys->dev, "(%s) key =%d using PMIC\n", in mtk_pmic_keys_irq_handler_thread()
203 pressed ? "pressed" : "released", info->keycode); in mtk_pmic_keys_irq_handler_thread()
208 static int mtk_pmic_key_setup(struct mtk_pmic_keys *keys, in mtk_pmic_key_setup() argument
213 info->keys = keys; in mtk_pmic_key_setup()
215 ret = regmap_update_bits(keys->regmap, info->regs->intsel_reg, in mtk_pmic_key_setup()
216 info->regs->intsel_mask, in mtk_pmic_key_setup()
217 info->regs->intsel_mask); in mtk_pmic_key_setup()
221 ret = devm_request_threaded_irq(keys->dev, info->irq, NULL, in mtk_pmic_key_setup()
224 "mtk-pmic-keys", info); in mtk_pmic_key_setup()
226 dev_err(keys->dev, "Failed to request IRQ: %d: %d\n", in mtk_pmic_key_setup()
227 info->irq, ret); in mtk_pmic_key_setup()
231 if (info->irq_r > 0) { in mtk_pmic_key_setup()
232 ret = devm_request_threaded_irq(keys->dev, info->irq_r, NULL, in mtk_pmic_key_setup()
235 "mtk-pmic-keys", info); in mtk_pmic_key_setup()
237 dev_err(keys->dev, "Failed to request IRQ_r: %d: %d\n", in mtk_pmic_key_setup()
238 info->irq, ret); in mtk_pmic_key_setup()
243 input_set_capability(keys->input_dev, EV_KEY, info->keycode); in mtk_pmic_key_setup()
250 struct mtk_pmic_keys *keys = dev_get_drvdata(dev); in mtk_pmic_keys_suspend() local
254 if (keys->keys[index].wakeup) { in mtk_pmic_keys_suspend()
255 enable_irq_wake(keys->keys[index].irq); in mtk_pmic_keys_suspend()
256 if (keys->keys[index].irq_r > 0) in mtk_pmic_keys_suspend()
257 enable_irq_wake(keys->keys[index].irq_r); in mtk_pmic_keys_suspend()
266 struct mtk_pmic_keys *keys = dev_get_drvdata(dev); in mtk_pmic_keys_resume() local
270 if (keys->keys[index].wakeup) { in mtk_pmic_keys_resume()
271 disable_irq_wake(keys->keys[index].irq); in mtk_pmic_keys_resume()
272 if (keys->keys[index].irq_r > 0) in mtk_pmic_keys_resume()
273 disable_irq_wake(keys->keys[index].irq_r); in mtk_pmic_keys_resume()
285 .compatible = "mediatek,mt6397-keys",
288 .compatible = "mediatek,mt6323-keys",
291 .compatible = "mediatek,mt6331-keys",
294 .compatible = "mediatek,mt6357-keys",
297 .compatible = "mediatek,mt6358-keys",
309 struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent); in mtk_pmic_keys_probe()
310 struct device_node *node = pdev->dev.of_node; in mtk_pmic_keys_probe()
313 struct mtk_pmic_keys *keys; in mtk_pmic_keys_probe() local
317 of_match_device(of_mtk_pmic_keys_match_tbl, &pdev->dev); in mtk_pmic_keys_probe()
319 keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL); in mtk_pmic_keys_probe()
320 if (!keys) in mtk_pmic_keys_probe()
321 return -ENOMEM; in mtk_pmic_keys_probe()
323 keys->dev = &pdev->dev; in mtk_pmic_keys_probe()
324 keys->regmap = pmic_chip->regmap; in mtk_pmic_keys_probe()
325 mtk_pmic_regs = of_id->data; in mtk_pmic_keys_probe()
327 keys->input_dev = input_dev = devm_input_allocate_device(keys->dev); in mtk_pmic_keys_probe()
329 dev_err(keys->dev, "input allocate device fail.\n"); in mtk_pmic_keys_probe()
330 return -ENOMEM; in mtk_pmic_keys_probe()
333 input_dev->name = "mtk-pmic-keys"; in mtk_pmic_keys_probe()
334 input_dev->id.bustype = BUS_HOST; in mtk_pmic_keys_probe()
335 input_dev->id.vendor = 0x0001; in mtk_pmic_keys_probe()
336 input_dev->id.product = 0x0001; in mtk_pmic_keys_probe()
337 input_dev->id.version = 0x0001; in mtk_pmic_keys_probe()
342 dev_err(keys->dev, "too many keys defined (%d)\n", keycount); in mtk_pmic_keys_probe()
343 return -EINVAL; in mtk_pmic_keys_probe()
347 keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index]; in mtk_pmic_keys_probe()
349 keys->keys[index].irq = in mtk_pmic_keys_probe()
351 if (keys->keys[index].irq < 0) in mtk_pmic_keys_probe()
352 return keys->keys[index].irq; in mtk_pmic_keys_probe()
354 if (of_device_is_compatible(node, "mediatek,mt6358-keys")) { in mtk_pmic_keys_probe()
355 keys->keys[index].irq_r = platform_get_irq_byname(pdev, in mtk_pmic_keys_probe()
358 if (keys->keys[index].irq_r < 0) in mtk_pmic_keys_probe()
359 return keys->keys[index].irq_r; in mtk_pmic_keys_probe()
363 "linux,keycodes", &keys->keys[index].keycode); in mtk_pmic_keys_probe()
365 dev_err(keys->dev, in mtk_pmic_keys_probe()
371 if (of_property_read_bool(child, "wakeup-source")) in mtk_pmic_keys_probe()
372 keys->keys[index].wakeup = true; in mtk_pmic_keys_probe()
374 error = mtk_pmic_key_setup(keys, &keys->keys[index]); in mtk_pmic_keys_probe()
383 dev_err(&pdev->dev, in mtk_pmic_keys_probe()
388 mtk_pmic_keys_lp_reset_setup(keys, mtk_pmic_regs); in mtk_pmic_keys_probe()
390 platform_set_drvdata(pdev, keys); in mtk_pmic_keys_probe()
398 .name = "mtk-pmic-keys",
408 MODULE_DESCRIPTION("MTK pmic-keys driver v0.1");