21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
25 #include <linux/i2c.h>
29 #define MMA8450_DRV_NAME "mma8450"
31 #define MODE_CHANGE_DELAY_MS 100
32 #define POLL_INTERVAL 100
33 #define POLL_INTERVAL_MAX 500
36 #define MMA8450_STATUS 0x00
37 #define MMA8450_STATUS_ZXYDR 0x08
39 #define MMA8450_OUT_X8 0x01
40 #define MMA8450_OUT_Y8 0x02
41 #define MMA8450_OUT_Z8 0x03
43 #define MMA8450_OUT_X_LSB 0x05
44 #define MMA8450_OUT_X_MSB 0x06
45 #define MMA8450_OUT_Y_LSB 0x07
46 #define MMA8450_OUT_Y_MSB 0x08
47 #define MMA8450_OUT_Z_LSB 0x09
48 #define MMA8450_OUT_Z_MSB 0x0a
50 #define MMA8450_XYZ_DATA_CFG 0x16
52 #define MMA8450_CTRL_REG1 0x38
53 #define MMA8450_CTRL_REG2 0x39
58 struct input_polled_dev *
idev;
61 static int mma8450_read(
struct mma8450 *
m,
unsigned off)
69 "failed to read register 0x%02x, error %d\n",
75 static int mma8450_write(
struct mma8450 *
m,
unsigned off,
u8 v)
83 "failed to write to register 0x%02x, error %d\n",
91 static int mma8450_read_block(
struct mma8450 *m,
unsigned off,
100 "failed to read block data at 0x%02x, error %d\n",
108 static void mma8450_poll(
struct input_polled_dev *
dev)
110 struct mma8450 *m = dev->private;
126 x = ((buf[1] << 4) & 0xff0) | (buf[0] & 0xf);
127 y = ((buf[3] << 4) & 0xff0) | (buf[2] & 0xf);
128 z = ((buf[5] << 4) & 0xff0) | (buf[4] & 0xf);
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);
137 static void mma8450_open(
struct input_polled_dev *dev)
139 struct mma8450 *m = dev->private;
159 static void mma8450_close(
struct input_polled_dev *dev)
161 struct mma8450 *m = dev->private;
173 struct input_polled_dev *
idev;
189 idev->input->id.bustype =
BUS_I2C;
190 idev->poll = mma8450_poll;
193 idev->open = mma8450_open;
194 idev->close = mma8450_close;
197 input_set_abs_params(idev->input,
ABS_X, -2048, 2047, 32, 32);
198 input_set_abs_params(idev->input,
ABS_Y, -2048, 2047, 32, 32);
199 input_set_abs_params(idev->input,
ABS_Z, -2048, 2047, 32, 32);
203 dev_err(&c->
dev,
"failed to register polled input device\n");
217 struct mma8450 *m = i2c_get_clientdata(c);
218 struct input_polled_dev *idev = m->
idev;
234 { .compatible =
"fsl,mma8450", },
243 .of_match_table = mma8450_dt_ids,
245 .probe = mma8450_probe,
247 .id_table = mma8450_id,