hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/input/keyboard/snvs_pwrkey.c
....@@ -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>
....@@ -15,18 +16,20 @@
1516 #include <linux/of.h>
1617 #include <linux/of_address.h>
1718 #include <linux/platform_device.h>
19
+#include <linux/pm_wakeirq.h>
1820 #include <linux/mfd/syscon.h>
1921 #include <linux/regmap.h>
2022
21
-#define SNVS_LPSR_REG 0x4C /* LP Status Register */
22
-#define SNVS_LPCR_REG 0x38 /* LP Control Register */
23
-#define SNVS_HPSR_REG 0x14
24
-#define SNVS_HPSR_BTN BIT(6)
25
-#define SNVS_LPSR_SPO BIT(18)
26
-#define SNVS_LPCR_DEP_EN BIT(5)
23
+#define SNVS_HPVIDR1_REG 0xBF8
24
+#define SNVS_LPSR_REG 0x4C /* LP Status Register */
25
+#define SNVS_LPCR_REG 0x38 /* LP Control Register */
26
+#define SNVS_HPSR_REG 0x14
27
+#define SNVS_HPSR_BTN BIT(6)
28
+#define SNVS_LPSR_SPO BIT(18)
29
+#define SNVS_LPCR_DEP_EN BIT(5)
2730
28
-#define DEBOUNCE_TIME 30
29
-#define REPEAT_INTERVAL 60
31
+#define DEBOUNCE_TIME 30
32
+#define REPEAT_INTERVAL 60
3033
3134 struct pwrkey_drv_data {
3235 struct regmap *snvs;
....@@ -36,6 +39,7 @@
3639 int wakeup;
3740 struct timer_list check_timer;
3841 struct input_dev *input;
42
+ u8 minor_rev;
3943 };
4044
4145 static void imx_imx_snvs_check_for_events(struct timer_list *t)
....@@ -66,18 +70,39 @@
6670 {
6771 struct platform_device *pdev = dev_id;
6872 struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
73
+ struct input_dev *input = pdata->input;
6974 u32 lp_status;
7075
71
- pm_wakeup_event(pdata->input->dev.parent, 0);
76
+ pm_wakeup_event(input->dev.parent, 0);
7277
7378 regmap_read(pdata->snvs, SNVS_LPSR_REG, &lp_status);
74
- if (lp_status & SNVS_LPSR_SPO)
75
- mod_timer(&pdata->check_timer, jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
79
+ if (lp_status & SNVS_LPSR_SPO) {
80
+ if (pdata->minor_rev == 0) {
81
+ /*
82
+ * The first generation i.MX6 SoCs only sends an
83
+ * interrupt on button release. To mimic power-key
84
+ * usage, we'll prepend a press event.
85
+ */
86
+ input_report_key(input, pdata->keycode, 1);
87
+ input_sync(input);
88
+ input_report_key(input, pdata->keycode, 0);
89
+ input_sync(input);
90
+ pm_relax(input->dev.parent);
91
+ } else {
92
+ mod_timer(&pdata->check_timer,
93
+ jiffies + msecs_to_jiffies(DEBOUNCE_TIME));
94
+ }
95
+ }
7696
7797 /* clear SPO status */
7898 regmap_write(pdata->snvs, SNVS_LPSR_REG, SNVS_LPSR_SPO);
7999
80100 return IRQ_HANDLED;
101
+}
102
+
103
+static void imx_snvs_pwrkey_disable_clk(void *data)
104
+{
105
+ clk_disable_unprepare(data);
81106 }
82107
83108 static void imx_snvs_pwrkey_act(void *pdata)
....@@ -89,10 +114,12 @@
89114
90115 static int imx_snvs_pwrkey_probe(struct platform_device *pdev)
91116 {
92
- struct pwrkey_drv_data *pdata = NULL;
93
- struct input_dev *input = NULL;
117
+ struct pwrkey_drv_data *pdata;
118
+ struct input_dev *input;
94119 struct device_node *np;
120
+ struct clk *clk;
95121 int error;
122
+ u32 vid;
96123
97124 /* Get SNVS register Page */
98125 np = pdev->dev.of_node;
....@@ -114,13 +141,36 @@
114141 dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n");
115142 }
116143
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
+
117166 pdata->wakeup = of_property_read_bool(np, "wakeup-source");
118167
119168 pdata->irq = platform_get_irq(pdev, 0);
120
- if (pdata->irq < 0) {
121
- dev_err(&pdev->dev, "no irq defined in platform data\n");
169
+ if (pdata->irq < 0)
122170 return -EINVAL;
123
- }
171
+
172
+ regmap_read(pdata->snvs, SNVS_HPVIDR1_REG, &vid);
173
+ pdata->minor_rev = vid & 0xff;
124174
125175 regmap_update_bits(pdata->snvs, SNVS_LPCR_REG, SNVS_LPCR_DEP_EN, SNVS_LPCR_DEP_EN);
126176
....@@ -167,28 +217,9 @@
167217 }
168218
169219 device_init_wakeup(&pdev->dev, pdata->wakeup);
170
-
171
- return 0;
172
-}
173
-
174
-static int __maybe_unused imx_snvs_pwrkey_suspend(struct device *dev)
175
-{
176
- struct platform_device *pdev = to_platform_device(dev);
177
- struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
178
-
179
- if (device_may_wakeup(&pdev->dev))
180
- enable_irq_wake(pdata->irq);
181
-
182
- return 0;
183
-}
184
-
185
-static int __maybe_unused imx_snvs_pwrkey_resume(struct device *dev)
186
-{
187
- struct platform_device *pdev = to_platform_device(dev);
188
- struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev);
189
-
190
- if (device_may_wakeup(&pdev->dev))
191
- disable_irq_wake(pdata->irq);
220
+ error = dev_pm_set_wake_irq(&pdev->dev, pdata->irq);
221
+ if (error)
222
+ dev_err(&pdev->dev, "irq wake enable failed.\n");
192223
193224 return 0;
194225 }
....@@ -199,13 +230,9 @@
199230 };
200231 MODULE_DEVICE_TABLE(of, imx_snvs_pwrkey_ids);
201232
202
-static SIMPLE_DEV_PM_OPS(imx_snvs_pwrkey_pm_ops, imx_snvs_pwrkey_suspend,
203
- imx_snvs_pwrkey_resume);
204
-
205233 static struct platform_driver imx_snvs_pwrkey_driver = {
206234 .driver = {
207235 .name = "snvs_pwrkey",
208
- .pm = &imx_snvs_pwrkey_pm_ops,
209236 .of_match_table = imx_snvs_pwrkey_ids,
210237 },
211238 .probe = imx_snvs_pwrkey_probe,