Skip to content

Commit d997cc1

Browse files
Uwe Kleine-Königdtor
authored andcommitted
Input: snvs_pwrkey - add clk handling
On i.MX7S and i.MX8M* (but not i.MX6*) the pwrkey device has an associated clock. Accessing the registers requires that this clock is enabled. Binding the driver on at least i.MX7S and i.MX8MP while not having the clock enabled results in a complete hang of the machine. (This usually only happens if snvs_pwrkey is built as a module and the rtc-snvs driver isn't already bound because at bootup the required clk is on and only gets disabled when the clk framework disables unused clks late during boot.) This completes the fix in commit 135be16 ("ARM: dts: imx7s: add snvs clock to pwrkey"). Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 0c5483a commit d997cc1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

drivers/input/keyboard/snvs_pwrkey.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Driver for the IMX SNVS ON/OFF Power Key
44
// Copyright (C) 2015 Freescale Semiconductor, Inc. All Rights Reserved.
55

6+
#include <linux/clk.h>
67
#include <linux/device.h>
78
#include <linux/err.h>
89
#include <linux/init.h>
@@ -99,6 +100,11 @@ static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id)
99100
return IRQ_HANDLED;
100101
}
101102

103+
static void imx_snvs_pwrkey_disable_clk(void *data)
104+
{
105+
clk_disable_unprepare(data);
106+
}
107+
102108
static void imx_snvs_pwrkey_act(void *pdata)
103109
{
104110
struct pwrkey_drv_data *pd = pdata;
@@ -111,6 +117,7 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev)
111117
struct pwrkey_drv_data *pdata;
112118
struct input_dev *input;
113119
struct device_node *np;
120+
struct clk *clk;
114121
int error;
115122
u32 vid;
116123

@@ -134,6 +141,28 @@ static int imx_snvs_pwrkey_probe(struct platform_device *pdev)
134141
dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n");
135142
}
136143

144+
clk = devm_clk_get_optional(&pdev->dev, NULL);
145+
if (IS_ERR(clk)) {
146+
dev_err(&pdev->dev, "Failed to get snvs clock (%pe)\n", clk);
147+
return PTR_ERR(clk);
148+
}
149+
150+
error = clk_prepare_enable(clk);
151+
if (error) {
152+
dev_err(&pdev->dev, "Failed to enable snvs clock (%pe)\n",
153+
ERR_PTR(error));
154+
return error;
155+
}
156+
157+
error = devm_add_action_or_reset(&pdev->dev,
158+
imx_snvs_pwrkey_disable_clk, clk);
159+
if (error) {
160+
dev_err(&pdev->dev,
161+
"Failed to register clock cleanup handler (%pe)\n",
162+
ERR_PTR(error));
163+
return error;
164+
}
165+
137166
pdata->wakeup = of_property_read_bool(np, "wakeup-source");
138167

139168
pdata->irq = platform_get_irq(pdev, 0);

0 commit comments

Comments
 (0)