hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/input/misc/axp20x-pek.c
....@@ -191,24 +191,25 @@
191191 axp20x_pek->info->shutdown_mask, buf, count);
192192 }
193193
194
-DEVICE_ATTR(startup, 0644, axp20x_show_attr_startup, axp20x_store_attr_startup);
195
-DEVICE_ATTR(shutdown, 0644, axp20x_show_attr_shutdown,
196
- axp20x_store_attr_shutdown);
194
+static DEVICE_ATTR(startup, 0644, axp20x_show_attr_startup,
195
+ axp20x_store_attr_startup);
196
+static DEVICE_ATTR(shutdown, 0644, axp20x_show_attr_shutdown,
197
+ axp20x_store_attr_shutdown);
197198
198
-static struct attribute *axp20x_attributes[] = {
199
+static struct attribute *axp20x_attrs[] = {
199200 &dev_attr_startup.attr,
200201 &dev_attr_shutdown.attr,
201202 NULL,
202203 };
203
-
204
-static const struct attribute_group axp20x_attribute_group = {
205
- .attrs = axp20x_attributes,
206
-};
204
+ATTRIBUTE_GROUPS(axp20x);
207205
208206 static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
209207 {
210
- struct input_dev *idev = pwr;
211
- struct axp20x_pek *axp20x_pek = input_get_drvdata(idev);
208
+ struct axp20x_pek *axp20x_pek = pwr;
209
+ struct input_dev *idev = axp20x_pek->input;
210
+
211
+ if (!idev)
212
+ return IRQ_HANDLED;
212213
213214 /*
214215 * The power-button is connected to ground so a falling edge (dbf)
....@@ -227,27 +228,8 @@
227228 static int axp20x_pek_probe_input_device(struct axp20x_pek *axp20x_pek,
228229 struct platform_device *pdev)
229230 {
230
- struct axp20x_dev *axp20x = axp20x_pek->axp20x;
231231 struct input_dev *idev;
232232 int error;
233
-
234
- axp20x_pek->irq_dbr = platform_get_irq_byname(pdev, "PEK_DBR");
235
- if (axp20x_pek->irq_dbr < 0) {
236
- dev_err(&pdev->dev, "No IRQ for PEK_DBR, error=%d\n",
237
- axp20x_pek->irq_dbr);
238
- return axp20x_pek->irq_dbr;
239
- }
240
- axp20x_pek->irq_dbr = regmap_irq_get_virq(axp20x->regmap_irqc,
241
- axp20x_pek->irq_dbr);
242
-
243
- axp20x_pek->irq_dbf = platform_get_irq_byname(pdev, "PEK_DBF");
244
- if (axp20x_pek->irq_dbf < 0) {
245
- dev_err(&pdev->dev, "No IRQ for PEK_DBF, error=%d\n",
246
- axp20x_pek->irq_dbf);
247
- return axp20x_pek->irq_dbf;
248
- }
249
- axp20x_pek->irq_dbf = regmap_irq_get_virq(axp20x->regmap_irqc,
250
- axp20x_pek->irq_dbf);
251233
252234 axp20x_pek->input = devm_input_allocate_device(&pdev->dev);
253235 if (!axp20x_pek->input)
....@@ -263,33 +245,12 @@
263245
264246 input_set_drvdata(idev, axp20x_pek);
265247
266
- error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbr,
267
- axp20x_pek_irq, 0,
268
- "axp20x-pek-dbr", idev);
269
- if (error < 0) {
270
- dev_err(&pdev->dev, "Failed to request dbr IRQ#%d: %d\n",
271
- axp20x_pek->irq_dbr, error);
272
- return error;
273
- }
274
-
275
- error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbf,
276
- axp20x_pek_irq, 0,
277
- "axp20x-pek-dbf", idev);
278
- if (error < 0) {
279
- dev_err(&pdev->dev, "Failed to request dbf IRQ#%d: %d\n",
280
- axp20x_pek->irq_dbf, error);
281
- return error;
282
- }
283
-
284248 error = input_register_device(idev);
285249 if (error) {
286250 dev_err(&pdev->dev, "Can't register input device: %d\n",
287251 error);
288252 return error;
289253 }
290
-
291
- if (axp20x_pek->axp20x->variant == AXP288_ID)
292
- enable_irq_wake(axp20x_pek->irq_dbr);
293254
294255 return 0;
295256 }
....@@ -348,6 +309,18 @@
348309
349310 axp20x_pek->axp20x = dev_get_drvdata(pdev->dev.parent);
350311
312
+ axp20x_pek->irq_dbr = platform_get_irq_byname(pdev, "PEK_DBR");
313
+ if (axp20x_pek->irq_dbr < 0)
314
+ return axp20x_pek->irq_dbr;
315
+ axp20x_pek->irq_dbr = regmap_irq_get_virq(
316
+ axp20x_pek->axp20x->regmap_irqc, axp20x_pek->irq_dbr);
317
+
318
+ axp20x_pek->irq_dbf = platform_get_irq_byname(pdev, "PEK_DBF");
319
+ if (axp20x_pek->irq_dbf < 0)
320
+ return axp20x_pek->irq_dbf;
321
+ axp20x_pek->irq_dbf = regmap_irq_get_virq(
322
+ axp20x_pek->axp20x->regmap_irqc, axp20x_pek->irq_dbf);
323
+
351324 if (axp20x_pek_should_register_input(axp20x_pek, pdev)) {
352325 error = axp20x_pek_probe_input_device(axp20x_pek, pdev);
353326 if (error)
....@@ -356,14 +329,61 @@
356329
357330 axp20x_pek->info = (struct axp20x_info *)match->driver_data;
358331
359
- error = devm_device_add_group(&pdev->dev, &axp20x_attribute_group);
360
- if (error) {
361
- dev_err(&pdev->dev, "Failed to create sysfs attributes: %d\n",
362
- error);
332
+ error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbr,
333
+ axp20x_pek_irq, 0,
334
+ "axp20x-pek-dbr", axp20x_pek);
335
+ if (error < 0) {
336
+ dev_err(&pdev->dev, "Failed to request dbr IRQ#%d: %d\n",
337
+ axp20x_pek->irq_dbr, error);
363338 return error;
364339 }
365340
341
+ error = devm_request_any_context_irq(&pdev->dev, axp20x_pek->irq_dbf,
342
+ axp20x_pek_irq, 0,
343
+ "axp20x-pek-dbf", axp20x_pek);
344
+ if (error < 0) {
345
+ dev_err(&pdev->dev, "Failed to request dbf IRQ#%d: %d\n",
346
+ axp20x_pek->irq_dbf, error);
347
+ return error;
348
+ }
349
+
350
+ device_init_wakeup(&pdev->dev, true);
351
+
366352 platform_set_drvdata(pdev, axp20x_pek);
353
+
354
+ return 0;
355
+}
356
+
357
+static int __maybe_unused axp20x_pek_suspend(struct device *dev)
358
+{
359
+ struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
360
+
361
+ /*
362
+ * As nested threaded IRQs are not automatically disabled during
363
+ * suspend, we must explicitly disable non-wakeup IRQs.
364
+ */
365
+ if (device_may_wakeup(dev)) {
366
+ enable_irq_wake(axp20x_pek->irq_dbf);
367
+ enable_irq_wake(axp20x_pek->irq_dbr);
368
+ } else {
369
+ disable_irq(axp20x_pek->irq_dbf);
370
+ disable_irq(axp20x_pek->irq_dbr);
371
+ }
372
+
373
+ return 0;
374
+}
375
+
376
+static int __maybe_unused axp20x_pek_resume(struct device *dev)
377
+{
378
+ struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
379
+
380
+ if (device_may_wakeup(dev)) {
381
+ disable_irq_wake(axp20x_pek->irq_dbf);
382
+ disable_irq_wake(axp20x_pek->irq_dbr);
383
+ } else {
384
+ enable_irq(axp20x_pek->irq_dbf);
385
+ enable_irq(axp20x_pek->irq_dbr);
386
+ }
367387
368388 return 0;
369389 }
....@@ -387,6 +407,7 @@
387407 }
388408
389409 static const struct dev_pm_ops axp20x_pek_pm_ops = {
410
+ SET_SYSTEM_SLEEP_PM_OPS(axp20x_pek_suspend, axp20x_pek_resume)
390411 #ifdef CONFIG_PM_SLEEP
391412 .resume_noirq = axp20x_pek_resume_noirq,
392413 #endif
....@@ -411,6 +432,7 @@
411432 .driver = {
412433 .name = "axp20x-pek",
413434 .pm = &axp20x_pek_pm_ops,
435
+ .dev_groups = axp20x_groups,
414436 },
415437 };
416438 module_platform_driver(axp20x_pek_driver);