diff options
Diffstat (limited to 'drivers/input/keyboard/snvs_pwrkey.c')
-rw-r--r-- | drivers/input/keyboard/snvs_pwrkey.c | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/drivers/input/keyboard/snvs_pwrkey.c b/drivers/input/keyboard/snvs_pwrkey.c index 248bb86f4b3f..0c2e06a1f0d0 100644 --- a/drivers/input/keyboard/snvs_pwrkey.c +++ b/drivers/input/keyboard/snvs_pwrkey.c @@ -36,6 +36,8 @@ struct pwrkey_drv_data { int keycode; int keystate; /* 1:pressed */ int wakeup; + bool suspended; + struct clk *clk; struct timer_list check_timer; struct input_dev *input; }; @@ -46,7 +48,22 @@ static void imx_imx_snvs_check_for_events(struct timer_list *t) struct input_dev *input = pdata->input; u32 state; + if (pdata->clk) { + if (pdata->suspended) + clk_prepare_enable(pdata->clk); + else + clk_enable(pdata->clk); + } + regmap_read(pdata->snvs, SNVS_HPSR_REG, &state); + + if (pdata->clk) { + if (pdata->suspended) + clk_disable_unprepare(pdata->clk); + else + clk_disable(pdata->clk); + } + state = state & SNVS_HPSR_BTN ? 1 : 0; /* only report new event if status changed */ @@ -68,10 +85,20 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id) { struct platform_device *pdev = dev_id; struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev); + struct input_dev *input = pdata->input; u32 lp_status; pm_wakeup_event(pdata->input->dev.parent, 0); + if (pdata->clk) + clk_enable(pdata->clk); + + if (pdata->suspended) { + pdata->keystate = 1; + input_event(input, EV_KEY, pdata->keycode, 1); + input_sync(input); + } + regmap_read(pdata->snvs, SNVS_LPSR_REG, &lp_status); if (lp_status & SNVS_LPSR_SPO) mod_timer(&pdata->check_timer, jiffies + msecs_to_jiffies(DEBOUNCE_TIME)); @@ -79,6 +106,9 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id) /* clear SPO status */ regmap_write(pdata->snvs, SNVS_LPSR_REG, SNVS_LPSR_SPO); + if (pdata->clk) + clk_disable(pdata->clk); + return IRQ_HANDLED; } @@ -150,6 +180,18 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) if (pdata->irq < 0) return -EINVAL; + pdata->clk = devm_clk_get(&pdev->dev, "snvs"); + if (IS_ERR(pdata->clk)) { + pdata->clk = NULL; + } else { + error = clk_prepare_enable(pdata->clk); + if (error) { + dev_err(&pdev->dev, + "Could not enable the snvs clock\n"); + return error; + } + } + regmap_update_bits(pdata->snvs, SNVS_LPCR_REG, SNVS_LPCR_DEP_EN, SNVS_LPCR_DEP_EN); /* clear the unexpected interrupt before driver ready */ @@ -160,7 +202,8 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) input = devm_input_allocate_device(&pdev->dev); if (!input) { dev_err(&pdev->dev, "failed to allocate the input device\n"); - return -ENOMEM; + error = -ENOMEM; + goto error_probe; } input->name = pdev->name; @@ -173,7 +216,7 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) error = devm_add_action(&pdev->dev, imx_snvs_pwrkey_act, pdata); if (error) { dev_err(&pdev->dev, "failed to register remove action\n"); - return error; + goto error_probe; } pdata->input = input; @@ -185,13 +228,13 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) if (error) { dev_err(&pdev->dev, "interrupt not available.\n"); - return error; + goto error_probe; } error = input_register_device(input); if (error < 0) { dev_err(&pdev->dev, "failed to register input device\n"); - return error; + goto error_probe; } device_init_wakeup(&pdev->dev, pdata->wakeup); @@ -200,8 +243,43 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev) dev_err(&pdev->dev, "irq wake enable failed.\n"); return 0; + +error_probe: + if (pdata->clk) + clk_disable_unprepare(pdata->clk); + + return error; +} + +static int __maybe_unused imx_snvs_pwrkey_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev); + + if (pdata->clk) + clk_disable_unprepare(pdata->clk); + + pdata->suspended = true; + + return 0; } +static int __maybe_unused imx_snvs_pwrkey_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev); + + if (pdata->clk) + clk_prepare_enable(pdata->clk); + + pdata->suspended = false; + + return 0; +} + +static SIMPLE_DEV_PM_OPS(imx_snvs_pwrkey_pm_ops, imx_snvs_pwrkey_suspend, + imx_snvs_pwrkey_resume); + static const struct of_device_id imx_snvs_pwrkey_ids[] = { { .compatible = "fsl,sec-v4.0-pwrkey" }, { /* sentinel */ } @@ -211,6 +289,7 @@ MODULE_DEVICE_TABLE(of, imx_snvs_pwrkey_ids); static struct platform_driver imx_snvs_pwrkey_driver = { .driver = { .name = "snvs_pwrkey", + .pm = &imx_snvs_pwrkey_pm_ops, .of_match_table = imx_snvs_pwrkey_ids, }, .probe = imx_snvs_pwrkey_probe, |