hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/input/misc/cobalt_btns.c
....@@ -1,23 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Cobalt button interface driver.
34 *
45 * Copyright (C) 2007-2008 Yoichi Yuasa <yuasa@linux-mips.org>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
196 */
20
-#include <linux/input-polldev.h>
7
+#include <linux/input.h>
8
+#include <linux/io.h>
219 #include <linux/ioport.h>
2210 #include <linux/module.h>
2311 #include <linux/platform_device.h>
....@@ -39,16 +27,14 @@
3927 };
4028
4129 struct buttons_dev {
42
- struct input_polled_dev *poll_dev;
4330 unsigned short keymap[ARRAY_SIZE(cobalt_map)];
4431 int count[ARRAY_SIZE(cobalt_map)];
4532 void __iomem *reg;
4633 };
4734
48
-static void handle_buttons(struct input_polled_dev *dev)
35
+static void handle_buttons(struct input_dev *input)
4936 {
50
- struct buttons_dev *bdev = dev->private;
51
- struct input_dev *input = dev->input;
37
+ struct buttons_dev *bdev = input_get_drvdata(input);
5238 uint32_t status;
5339 int i;
5440
....@@ -75,29 +61,33 @@
7561 static int cobalt_buttons_probe(struct platform_device *pdev)
7662 {
7763 struct buttons_dev *bdev;
78
- struct input_polled_dev *poll_dev;
7964 struct input_dev *input;
8065 struct resource *res;
8166 int error, i;
8267
83
- bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL);
84
- poll_dev = input_allocate_polled_device();
85
- if (!bdev || !poll_dev) {
86
- error = -ENOMEM;
87
- goto err_free_mem;
88
- }
68
+ bdev = devm_kzalloc(&pdev->dev, sizeof(*bdev), GFP_KERNEL);
69
+ if (!bdev)
70
+ return -ENOMEM;
71
+
72
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
73
+ if (!res)
74
+ return -EBUSY;
75
+
76
+ bdev->reg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
77
+ if (!bdev->reg)
78
+ return -ENOMEM;
8979
9080 memcpy(bdev->keymap, cobalt_map, sizeof(bdev->keymap));
9181
92
- poll_dev->private = bdev;
93
- poll_dev->poll = handle_buttons;
94
- poll_dev->poll_interval = BUTTONS_POLL_INTERVAL;
82
+ input = devm_input_allocate_device(&pdev->dev);
83
+ if (!input)
84
+ return -ENOMEM;
9585
96
- input = poll_dev->input;
86
+ input_set_drvdata(input, bdev);
87
+
9788 input->name = "Cobalt buttons";
9889 input->phys = "cobalt/input0";
9990 input->id.bustype = BUS_HOST;
100
- input->dev.parent = &pdev->dev;
10191
10292 input->keycode = bdev->keymap;
10393 input->keycodemax = ARRAY_SIZE(bdev->keymap);
....@@ -109,39 +99,16 @@
10999 __set_bit(bdev->keymap[i], input->keybit);
110100 __clear_bit(KEY_RESERVED, input->keybit);
111101
112
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
113
- if (!res) {
114
- error = -EBUSY;
115
- goto err_free_mem;
116
- }
117102
118
- bdev->poll_dev = poll_dev;
119
- bdev->reg = ioremap(res->start, resource_size(res));
120
- dev_set_drvdata(&pdev->dev, bdev);
121
-
122
- error = input_register_polled_device(poll_dev);
103
+ error = input_setup_polling(input, handle_buttons);
123104 if (error)
124
- goto err_iounmap;
105
+ return error;
125106
126
- return 0;
107
+ input_set_poll_interval(input, BUTTONS_POLL_INTERVAL);
127108
128
- err_iounmap:
129
- iounmap(bdev->reg);
130
- err_free_mem:
131
- input_free_polled_device(poll_dev);
132
- kfree(bdev);
133
- return error;
134
-}
135
-
136
-static int cobalt_buttons_remove(struct platform_device *pdev)
137
-{
138
- struct device *dev = &pdev->dev;
139
- struct buttons_dev *bdev = dev_get_drvdata(dev);
140
-
141
- input_unregister_polled_device(bdev->poll_dev);
142
- input_free_polled_device(bdev->poll_dev);
143
- iounmap(bdev->reg);
144
- kfree(bdev);
109
+ error = input_register_device(input);
110
+ if (error)
111
+ return error;
145112
146113 return 0;
147114 }
....@@ -154,7 +121,6 @@
154121
155122 static struct platform_driver cobalt_buttons_driver = {
156123 .probe = cobalt_buttons_probe,
157
- .remove = cobalt_buttons_remove,
158124 .driver = {
159125 .name = "Cobalt buttons",
160126 },