20 #include <linux/types.h>
23 #include <linux/slab.h>
24 #include <linux/input.h>
26 #include <linux/module.h>
30 #define CMA3000_WHOAMI 0x00
31 #define CMA3000_REVID 0x01
32 #define CMA3000_CTRL 0x02
33 #define CMA3000_STATUS 0x03
34 #define CMA3000_RSTR 0x04
35 #define CMA3000_INTSTATUS 0x05
36 #define CMA3000_DOUTX 0x06
37 #define CMA3000_DOUTY 0x07
38 #define CMA3000_DOUTZ 0x08
39 #define CMA3000_MDTHR 0x09
40 #define CMA3000_MDFFTMR 0x0A
41 #define CMA3000_FFTHR 0x0B
43 #define CMA3000_RANGE2G (1 << 7)
44 #define CMA3000_RANGE8G (0 << 7)
45 #define CMA3000_BUSI2C (0 << 4)
46 #define CMA3000_MODEMASK (7 << 1)
47 #define CMA3000_GRANGEMASK (1 << 7)
49 #define CMA3000_STATUS_PERR 1
50 #define CMA3000_INTSTATUS_FFDET (1 << 2)
53 #define CMA3000_SETDELAY 30
56 #define CMA3000_INTDELAY 44
84 #define CMA3000_READ(data, reg, msg) \
85 (data->bus_ops->read(data->dev, reg, msg))
86 #define CMA3000_SET(data, reg, val, msg) \
87 ((data)->bus_ops->write(data->dev, reg, val, msg))
95 static int mode_to_mg[8][2] = {
107 int *datay,
int *dataz)
118 int datax, datay, dataz, intr_status;
148 decode_mg(data, &datax, &datay, &dataz);
196 "Invalid G range specified, assuming 8G\n");
200 ctrl |= data->
bus_ops->ctrl_mod;
203 "Motion Detect Threshold");
207 "Free fall threshold");
227 static int cma3000_open(
struct input_dev *input_dev)
234 cma3000_poweron(data);
243 static void cma3000_close(
struct input_dev *input_dev)
250 cma3000_poweroff(data);
262 cma3000_poweroff(data);
276 cma3000_poweron(data);
289 struct input_dev *input_dev;
294 dev_err(dev,
"platform data not found\n");
307 input_dev = input_allocate_device();
308 if (!data || !input_dev) {
324 "Invalid mode specified, assuming Motion Detect\n");
330 "Invalid G range specified, assuming 8G\n");
334 input_dev->name =
"cma3000-accelerometer";
335 input_dev->id.bustype = bops->
bustype;
336 input_dev->open = cma3000_open;
337 input_dev->close = cma3000_close;
341 input_set_abs_params(input_dev,
ABS_X,
343 input_set_abs_params(input_dev,
ABS_Y,
345 input_set_abs_params(input_dev,
ABS_Z,
347 input_set_abs_params(input_dev,
ABS_MISC, 0, 1, 0, 0);
349 input_set_drvdata(input_dev, data);
351 error = cma3000_reset(data);
361 pr_info(
"CMA3000 Accelerometer: Revision %x\n", rev);
365 "cma3000_d0x", data);
367 dev_err(dev,
"request_threaded_irq failed\n");
371 error = input_register_device(data->
input_dev);
373 dev_err(dev,
"Unable to register input device\n");
382 input_free_device(input_dev);
385 return ERR_PTR(error);
392 input_unregister_device(data->
input_dev);