hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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>
....@@ -58,7 +55,7 @@
5855 struct input_dev *input;
5956 struct mutex disable_lock;
6057 unsigned short *keymap;
61
- struct gpio_button_data data[0];
58
+ struct gpio_button_data data[];
6259 };
6360
6461 /*
....@@ -354,10 +351,7 @@
354351 &dev_attr_disabled_switches.attr,
355352 NULL,
356353 };
357
-
358
-static const struct attribute_group gpio_keys_attr_group = {
359
- .attrs = gpio_keys_attrs,
360
-};
354
+ATTRIBUTE_GROUPS(gpio_keys);
361355
362356 static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
363357 {
....@@ -500,10 +494,8 @@
500494 spin_lock_init(&bdata->lock);
501495
502496 if (child) {
503
- bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL,
504
- child,
505
- GPIOD_IN,
506
- desc);
497
+ bdata->gpiod = devm_fwnode_gpiod_get(dev, child,
498
+ NULL, GPIOD_IN, desc);
507499 if (IS_ERR(bdata->gpiod)) {
508500 error = PTR_ERR(bdata->gpiod);
509501 if (error == -ENOENT) {
....@@ -582,7 +574,6 @@
582574 IRQ_TYPE_EDGE_RISING : IRQ_TYPE_EDGE_FALLING;
583575 break;
584576 case EV_ACT_ANY:
585
- /* fall through */
586577 default:
587578 /*
588579 * For other cases, we are OK letting suspend/resume
....@@ -774,7 +765,6 @@
774765 struct fwnode_handle *child = NULL;
775766 struct gpio_keys_drvdata *ddata;
776767 struct input_dev *input;
777
- size_t size;
778768 int i, error;
779769 int wakeup = 0;
780770
....@@ -784,9 +774,8 @@
784774 return PTR_ERR(pdata);
785775 }
786776
787
- size = sizeof(struct gpio_keys_drvdata) +
788
- pdata->nbuttons * sizeof(struct gpio_button_data);
789
- ddata = devm_kzalloc(dev, size, GFP_KERNEL);
777
+ ddata = devm_kzalloc(dev, struct_size(ddata, data, pdata->nbuttons),
778
+ GFP_KERNEL);
790779 if (!ddata) {
791780 dev_err(dev, "failed to allocate state\n");
792781 return -ENOMEM;
....@@ -855,13 +844,6 @@
855844 }
856845
857846 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
- }
865847
866848 error = input_register_device(input);
867849 if (error) {
....@@ -1015,12 +997,23 @@
1015997
1016998 static SIMPLE_DEV_PM_OPS(gpio_keys_pm_ops, gpio_keys_suspend, gpio_keys_resume);
1017999
1000
+static void gpio_keys_shutdown(struct platform_device *pdev)
1001
+{
1002
+ int ret;
1003
+
1004
+ ret = gpio_keys_suspend(&pdev->dev);
1005
+ if (ret)
1006
+ dev_err(&pdev->dev, "failed to shutdown\n");
1007
+}
1008
+
10181009 static struct platform_driver gpio_keys_device_driver = {
10191010 .probe = gpio_keys_probe,
1011
+ .shutdown = gpio_keys_shutdown,
10201012 .driver = {
10211013 .name = "gpio-keys",
10221014 .pm = &gpio_keys_pm_ops,
10231015 .of_match_table = gpio_keys_of_match,
1016
+ .dev_groups = gpio_keys_groups,
10241017 }
10251018 };
10261019