hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/drivers/input/keyboard/gpio_keys.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for keys on GPIO lines capable of generating interrupts.
34 *
45 * Copyright 2005 Phil Blundell
56 * Copyright 2010, 2011 David Jander <david@protonic.nl>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118
129 #include <linux/module.h>
....@@ -31,6 +28,7 @@
3128 #include <linux/of_irq.h>
3229 #include <linux/spinlock.h>
3330 #include <dt-bindings/input/gpio-keys.h>
31
+#include <trace/hooks/wakeupbypass.h>
3432
3533 struct gpio_button_data {
3634 const struct gpio_keys_button *button;
....@@ -58,7 +56,7 @@
5856 struct input_dev *input;
5957 struct mutex disable_lock;
6058 unsigned short *keymap;
61
- struct gpio_button_data data[0];
59
+ struct gpio_button_data data[];
6260 };
6361
6462 /*
....@@ -354,10 +352,7 @@
354352 &dev_attr_disabled_switches.attr,
355353 NULL,
356354 };
357
-
358
-static const struct attribute_group gpio_keys_attr_group = {
359
- .attrs = gpio_keys_attrs,
360
-};
355
+ATTRIBUTE_GROUPS(gpio_keys);
361356
362357 static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
363358 {
....@@ -500,10 +495,8 @@
500495 spin_lock_init(&bdata->lock);
501496
502497 if (child) {
503
- bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL,
504
- child,
505
- GPIOD_IN,
506
- desc);
498
+ bdata->gpiod = devm_fwnode_gpiod_get(dev, child,
499
+ NULL, GPIOD_IN, desc);
507500 if (IS_ERR(bdata->gpiod)) {
508501 error = PTR_ERR(bdata->gpiod);
509502 if (error == -ENOENT) {
....@@ -582,7 +575,6 @@
582575 IRQ_TYPE_EDGE_RISING : IRQ_TYPE_EDGE_FALLING;
583576 break;
584577 case EV_ACT_ANY:
585
- /* fall through */
586578 default:
587579 /*
588580 * For other cases, we are OK letting suspend/resume
....@@ -774,7 +766,6 @@
774766 struct fwnode_handle *child = NULL;
775767 struct gpio_keys_drvdata *ddata;
776768 struct input_dev *input;
777
- size_t size;
778769 int i, error;
779770 int wakeup = 0;
780771
....@@ -784,9 +775,8 @@
784775 return PTR_ERR(pdata);
785776 }
786777
787
- size = sizeof(struct gpio_keys_drvdata) +
788
- pdata->nbuttons * sizeof(struct gpio_button_data);
789
- ddata = devm_kzalloc(dev, size, GFP_KERNEL);
778
+ ddata = devm_kzalloc(dev, struct_size(ddata, data, pdata->nbuttons),
779
+ GFP_KERNEL);
790780 if (!ddata) {
791781 dev_err(dev, "failed to allocate state\n");
792782 return -ENOMEM;
....@@ -855,13 +845,6 @@
855845 }
856846
857847 fwnode_handle_put(child);
858
-
859
- error = devm_device_add_group(dev, &gpio_keys_attr_group);
860
- if (error) {
861
- dev_err(dev, "Unable to export keys/switches, error: %d\n",
862
- error);
863
- return error;
864
- }
865848
866849 error = input_register_device(input);
867850 if (error) {
....@@ -976,11 +959,16 @@
976959 struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
977960 struct input_dev *input = ddata->input;
978961 int error;
962
+ int wakeup_bypass_enabled = 0;
963
+
964
+ trace_android_vh_wakeup_bypass(&wakeup_bypass_enabled);
979965
980966 if (device_may_wakeup(dev)) {
981
- error = gpio_keys_enable_wakeup(ddata);
982
- if (error)
983
- return error;
967
+ if (!wakeup_bypass_enabled) {
968
+ error = gpio_keys_enable_wakeup(ddata);
969
+ if (error)
970
+ return error;
971
+ }
984972 } else {
985973 mutex_lock(&input->mutex);
986974 if (input->users)
....@@ -996,9 +984,13 @@
996984 struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev);
997985 struct input_dev *input = ddata->input;
998986 int error = 0;
987
+ int wakeup_bypass_enabled = 0;
988
+
989
+ trace_android_vh_wakeup_bypass(&wakeup_bypass_enabled);
999990
1000991 if (device_may_wakeup(dev)) {
1001
- gpio_keys_disable_wakeup(ddata);
992
+ if (!wakeup_bypass_enabled)
993
+ gpio_keys_disable_wakeup(ddata);
1002994 } else {
1003995 mutex_lock(&input->mutex);
1004996 if (input->users)
....@@ -1015,12 +1007,23 @@
10151007
10161008 static SIMPLE_DEV_PM_OPS(gpio_keys_pm_ops, gpio_keys_suspend, gpio_keys_resume);
10171009
1010
+static void gpio_keys_shutdown(struct platform_device *pdev)
1011
+{
1012
+ int ret;
1013
+
1014
+ ret = gpio_keys_suspend(&pdev->dev);
1015
+ if (ret)
1016
+ dev_err(&pdev->dev, "failed to shutdown\n");
1017
+}
1018
+
10181019 static struct platform_driver gpio_keys_device_driver = {
10191020 .probe = gpio_keys_probe,
1021
+ .shutdown = gpio_keys_shutdown,
10201022 .driver = {
10211023 .name = "gpio-keys",
10221024 .pm = &gpio_keys_pm_ops,
10231025 .of_match_table = gpio_keys_of_match,
1026
+ .dev_groups = gpio_keys_groups,
10241027 }
10251028 };
10261029