hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/input/misc/mma8450.c
....@@ -1,21 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for Freescale's 3-Axis Accelerometer MMA8450
34 *
45 * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
196 */
207
218 #include <linux/kernel.h>
....@@ -23,7 +10,7 @@
2310 #include <linux/slab.h>
2411 #include <linux/delay.h>
2512 #include <linux/i2c.h>
26
-#include <linux/input-polldev.h>
13
+#include <linux/input.h>
2714 #include <linux/of_device.h>
2815
2916 #define MMA8450_DRV_NAME "mma8450"
....@@ -52,15 +39,8 @@
5239 #define MMA8450_CTRL_REG1 0x38
5340 #define MMA8450_CTRL_REG2 0x39
5441
55
-/* mma8450 status */
56
-struct mma8450 {
57
- struct i2c_client *client;
58
- struct input_polled_dev *idev;
59
-};
60
-
61
-static int mma8450_read(struct mma8450 *m, unsigned off)
42
+static int mma8450_read(struct i2c_client *c, unsigned int off)
6243 {
63
- struct i2c_client *c = m->client;
6444 int ret;
6545
6646 ret = i2c_smbus_read_byte_data(c, off);
....@@ -72,9 +52,8 @@
7252 return ret;
7353 }
7454
75
-static int mma8450_write(struct mma8450 *m, unsigned off, u8 v)
55
+static int mma8450_write(struct i2c_client *c, unsigned int off, u8 v)
7656 {
77
- struct i2c_client *c = m->client;
7857 int error;
7958
8059 error = i2c_smbus_write_byte_data(c, off, v);
....@@ -88,10 +67,9 @@
8867 return 0;
8968 }
9069
91
-static int mma8450_read_block(struct mma8450 *m, unsigned off,
70
+static int mma8450_read_block(struct i2c_client *c, unsigned int off,
9271 u8 *buf, size_t size)
9372 {
94
- struct i2c_client *c = m->client;
9573 int err;
9674
9775 err = i2c_smbus_read_i2c_block_data(c, off, size, buf);
....@@ -105,21 +83,21 @@
10583 return 0;
10684 }
10785
108
-static void mma8450_poll(struct input_polled_dev *dev)
86
+static void mma8450_poll(struct input_dev *input)
10987 {
110
- struct mma8450 *m = dev->private;
88
+ struct i2c_client *c = input_get_drvdata(input);
11189 int x, y, z;
11290 int ret;
11391 u8 buf[6];
11492
115
- ret = mma8450_read(m, MMA8450_STATUS);
93
+ ret = mma8450_read(c, MMA8450_STATUS);
11694 if (ret < 0)
11795 return;
11896
11997 if (!(ret & MMA8450_STATUS_ZXYDR))
12098 return;
12199
122
- ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, buf, sizeof(buf));
100
+ ret = mma8450_read_block(c, MMA8450_OUT_X_LSB, buf, sizeof(buf));
123101 if (ret < 0)
124102 return;
125103
....@@ -127,41 +105,42 @@
127105 y = ((int)(s8)buf[3] << 4) | (buf[2] & 0xf);
128106 z = ((int)(s8)buf[5] << 4) | (buf[4] & 0xf);
129107
130
- input_report_abs(dev->input, ABS_X, x);
131
- input_report_abs(dev->input, ABS_Y, y);
132
- input_report_abs(dev->input, ABS_Z, z);
133
- input_sync(dev->input);
108
+ input_report_abs(input, ABS_X, x);
109
+ input_report_abs(input, ABS_Y, y);
110
+ input_report_abs(input, ABS_Z, z);
111
+ input_sync(input);
134112 }
135113
136114 /* Initialize the MMA8450 chip */
137
-static void mma8450_open(struct input_polled_dev *dev)
115
+static int mma8450_open(struct input_dev *input)
138116 {
139
- struct mma8450 *m = dev->private;
117
+ struct i2c_client *c = input_get_drvdata(input);
140118 int err;
141119
142120 /* enable all events from X/Y/Z, no FIFO */
143
- err = mma8450_write(m, MMA8450_XYZ_DATA_CFG, 0x07);
121
+ err = mma8450_write(c, MMA8450_XYZ_DATA_CFG, 0x07);
144122 if (err)
145
- return;
123
+ return err;
146124
147125 /*
148126 * Sleep mode poll rate - 50Hz
149127 * System output data rate - 400Hz
150128 * Full scale selection - Active, +/- 2G
151129 */
152
- err = mma8450_write(m, MMA8450_CTRL_REG1, 0x01);
153
- if (err < 0)
154
- return;
130
+ err = mma8450_write(c, MMA8450_CTRL_REG1, 0x01);
131
+ if (err)
132
+ return err;
155133
156134 msleep(MODE_CHANGE_DELAY_MS);
135
+ return 0;
157136 }
158137
159
-static void mma8450_close(struct input_polled_dev *dev)
138
+static void mma8450_close(struct input_dev *input)
160139 {
161
- struct mma8450 *m = dev->private;
140
+ struct i2c_client *c = input_get_drvdata(input);
162141
163
- mma8450_write(m, MMA8450_CTRL_REG1, 0x00);
164
- mma8450_write(m, MMA8450_CTRL_REG2, 0x01);
142
+ mma8450_write(c, MMA8450_CTRL_REG1, 0x00);
143
+ mma8450_write(c, MMA8450_CTRL_REG2, 0x01);
165144 }
166145
167146 /*
....@@ -170,38 +149,37 @@
170149 static int mma8450_probe(struct i2c_client *c,
171150 const struct i2c_device_id *id)
172151 {
173
- struct input_polled_dev *idev;
174
- struct mma8450 *m;
152
+ struct input_dev *input;
175153 int err;
176154
177
- m = devm_kzalloc(&c->dev, sizeof(*m), GFP_KERNEL);
178
- if (!m)
155
+ input = devm_input_allocate_device(&c->dev);
156
+ if (!input)
179157 return -ENOMEM;
180158
181
- idev = devm_input_allocate_polled_device(&c->dev);
182
- if (!idev)
183
- return -ENOMEM;
159
+ input_set_drvdata(input, c);
184160
185
- m->client = c;
186
- m->idev = idev;
161
+ input->name = MMA8450_DRV_NAME;
162
+ input->id.bustype = BUS_I2C;
187163
188
- idev->private = m;
189
- idev->input->name = MMA8450_DRV_NAME;
190
- idev->input->id.bustype = BUS_I2C;
191
- idev->poll = mma8450_poll;
192
- idev->poll_interval = POLL_INTERVAL;
193
- idev->poll_interval_max = POLL_INTERVAL_MAX;
194
- idev->open = mma8450_open;
195
- idev->close = mma8450_close;
164
+ input->open = mma8450_open;
165
+ input->close = mma8450_close;
196166
197
- __set_bit(EV_ABS, idev->input->evbit);
198
- input_set_abs_params(idev->input, ABS_X, -2048, 2047, 32, 32);
199
- input_set_abs_params(idev->input, ABS_Y, -2048, 2047, 32, 32);
200
- input_set_abs_params(idev->input, ABS_Z, -2048, 2047, 32, 32);
167
+ input_set_abs_params(input, ABS_X, -2048, 2047, 32, 32);
168
+ input_set_abs_params(input, ABS_Y, -2048, 2047, 32, 32);
169
+ input_set_abs_params(input, ABS_Z, -2048, 2047, 32, 32);
201170
202
- err = input_register_polled_device(idev);
171
+ err = input_setup_polling(input, mma8450_poll);
203172 if (err) {
204
- dev_err(&c->dev, "failed to register polled input device\n");
173
+ dev_err(&c->dev, "failed to set up polling\n");
174
+ return err;
175
+ }
176
+
177
+ input_set_poll_interval(input, POLL_INTERVAL);
178
+ input_set_max_poll_interval(input, POLL_INTERVAL_MAX);
179
+
180
+ err = input_register_device(input);
181
+ if (err) {
182
+ dev_err(&c->dev, "failed to register input device\n");
205183 return err;
206184 }
207185