aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/input/misc/Kconfig37
-rw-r--r--drivers/input/misc/Makefile3
-rw-r--r--drivers/input/misc/adxl34x-i2c.c163
-rw-r--r--drivers/input/misc/adxl34x-spi.c145
-rw-r--r--drivers/input/misc/adxl34x.c840
-rw-r--r--drivers/input/misc/adxl34x.h30
-rw-r--r--include/linux/input/adxl34x.h293
7 files changed, 1511 insertions, 0 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index c44b9eafc556..ede6d52fe95c 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -390,4 +390,41 @@ config INPUT_PCAP
390 To compile this driver as a module, choose M here: the 390 To compile this driver as a module, choose M here: the
391 module will be called pcap_keys. 391 module will be called pcap_keys.
392 392
393config INPUT_ADXL34X
394 tristate "Analog Devices ADXL34x Three-Axis Digital Accelerometer"
395 default n
396 help
397 Say Y here if you have a Accelerometer interface using the
398 ADXL345/6 controller, and your board-specific initialization
399 code includes that in its table of devices.
400
401 This driver can use either I2C or SPI communication to the
402 ADXL345/6 controller. Select the appropriate method for
403 your system.
404
405 If unsure, say N (but it's safe to say "Y").
406
407 To compile this driver as a module, choose M here: the
408 module will be called adxl34x.
409
410config INPUT_ADXL34X_I2C
411 tristate "support I2C bus connection"
412 depends on INPUT_ADXL34X && I2C
413 default y
414 help
415 Say Y here if you have ADXL345/6 hooked to an I2C bus.
416
417 To compile this driver as a module, choose M here: the
418 module will be called adxl34x-i2c.
419
420config INPUT_ADXL34X_SPI
421 tristate "support SPI bus connection"
422 depends on INPUT_ADXL34X && SPI
423 default y
424 help
425 Say Y here if you have ADXL345/6 hooked to a SPI bus.
426
427 To compile this driver as a module, choose M here: the
428 module will be called adxl34x-spi.
429
393endif 430endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 71fe57d8023f..97b5dc32df19 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey.o
8obj-$(CONFIG_INPUT_AD714X) += ad714x.o 8obj-$(CONFIG_INPUT_AD714X) += ad714x.o
9obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o 9obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o
10obj-$(CONFIG_INPUT_AD714X_SPI) += ad714x-spi.o 10obj-$(CONFIG_INPUT_AD714X_SPI) += ad714x-spi.o
11obj-$(CONFIG_INPUT_ADXL34X) += adxl34x.o
12obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o
13obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o
11obj-$(CONFIG_INPUT_APANEL) += apanel.o 14obj-$(CONFIG_INPUT_APANEL) += apanel.o
12obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o 15obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o
13obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o 16obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o
diff --git a/drivers/input/misc/adxl34x-i2c.c b/drivers/input/misc/adxl34x-i2c.c
new file mode 100644
index 000000000000..76194b58bd0b
--- /dev/null
+++ b/drivers/input/misc/adxl34x-i2c.c
@@ -0,0 +1,163 @@
1/*
2 * ADLX345/346 Three-Axis Digital Accelerometers (I2C Interface)
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/input.h> /* BUS_I2C */
11#include <linux/i2c.h>
12#include <linux/module.h>
13#include <linux/types.h>
14#include "adxl34x.h"
15
16static int adxl34x_smbus_read(struct device *dev, unsigned char reg)
17{
18 struct i2c_client *client = to_i2c_client(dev);
19
20 return i2c_smbus_read_byte_data(client, reg);
21}
22
23static int adxl34x_smbus_write(struct device *dev,
24 unsigned char reg, unsigned char val)
25{
26 struct i2c_client *client = to_i2c_client(dev);
27
28 return i2c_smbus_write_byte_data(client, reg, val);
29}
30
31static int adxl34x_smbus_read_block(struct device *dev,
32 unsigned char reg, int count,
33 void *buf)
34{
35 struct i2c_client *client = to_i2c_client(dev);
36
37 return i2c_smbus_read_i2c_block_data(client, reg, count, buf);
38}
39
40static int adxl34x_i2c_read_block(struct device *dev,
41 unsigned char reg, int count,
42 void *buf)
43{
44 struct i2c_client *client = to_i2c_client(dev);
45 int ret;
46
47 ret = i2c_master_send(client, &reg, 1);
48 if (ret < 0)
49 return ret;
50
51 ret = i2c_master_recv(client, buf, count);
52 if (ret < 0)
53 return ret;
54
55 if (ret != count)
56 return -EIO;
57
58 return 0;
59}
60
61static const struct adxl34x_bus_ops adx134x_smbus_bops = {
62 .bustype = BUS_I2C,
63 .write = adxl34x_smbus_write,
64 .read = adxl34x_smbus_read,
65 .read_block = adxl34x_smbus_read_block,
66};
67
68static const struct adxl34x_bus_ops adx134x_i2c_bops = {
69 .bustype = BUS_I2C,
70 .write = adxl34x_smbus_write,
71 .read = adxl34x_smbus_read,
72 .read_block = adxl34x_i2c_read_block,
73};
74
75static int __devinit adxl34x_i2c_probe(struct i2c_client *client,
76 const struct i2c_device_id *id)
77{
78 struct adxl34x *ac;
79 int error;
80
81 error = i2c_check_functionality(client->adapter,
82 I2C_FUNC_SMBUS_BYTE_DATA);
83 if (!error) {
84 dev_err(&client->dev, "SMBUS Byte Data not Supported\n");
85 return -EIO;
86 }
87
88 ac = adxl34x_probe(&client->dev, client->irq, false,
89 i2c_check_functionality(client->adapter,
90 I2C_FUNC_SMBUS_READ_I2C_BLOCK) ?
91 &adx134x_smbus_bops : &adx134x_i2c_bops);
92 if (IS_ERR(ac))
93 return PTR_ERR(ac);
94
95 i2c_set_clientdata(client, ac);
96
97 return 0;
98}
99
100static int __devexit adxl34x_i2c_remove(struct i2c_client *client)
101{
102 struct adxl34x *ac = i2c_get_clientdata(client);
103
104 return adxl34x_remove(ac);
105}
106
107#ifdef CONFIG_PM
108static int adxl34x_suspend(struct i2c_client *client, pm_message_t message)
109{
110 struct adxl34x *ac = i2c_get_clientdata(client);
111
112 adxl34x_disable(ac);
113
114 return 0;
115}
116
117static int adxl34x_resume(struct i2c_client *client)
118{
119 struct adxl34x *ac = i2c_get_clientdata(client);
120
121 adxl34x_enable(ac);
122
123 return 0;
124}
125#else
126# define adxl34x_suspend NULL
127# define adxl34x_resume NULL
128#endif
129
130static const struct i2c_device_id adxl34x_id[] = {
131 { "adxl34x", 0 },
132 { }
133};
134
135MODULE_DEVICE_TABLE(i2c, adxl34x_id);
136
137static struct i2c_driver adxl34x_driver = {
138 .driver = {
139 .name = "adxl34x",
140 .owner = THIS_MODULE,
141 },
142 .probe = adxl34x_i2c_probe,
143 .remove = __devexit_p(adxl34x_i2c_remove),
144 .suspend = adxl34x_suspend,
145 .resume = adxl34x_resume,
146 .id_table = adxl34x_id,
147};
148
149static int __init adxl34x_i2c_init(void)
150{
151 return i2c_add_driver(&adxl34x_driver);
152}
153module_init(adxl34x_i2c_init);
154
155static void __exit adxl34x_i2c_exit(void)
156{
157 i2c_del_driver(&adxl34x_driver);
158}
159module_exit(adxl34x_i2c_exit);
160
161MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
162MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer I2C Bus Driver");
163MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/adxl34x-spi.c b/drivers/input/misc/adxl34x-spi.c
new file mode 100644
index 000000000000..7f992353ffdd
--- /dev/null
+++ b/drivers/input/misc/adxl34x-spi.c
@@ -0,0 +1,145 @@
1/*
2 * ADLX345/346 Three-Axis Digital Accelerometers (SPI Interface)
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/input.h> /* BUS_SPI */
11#include <linux/module.h>
12#include <linux/spi/spi.h>
13#include <linux/types.h>
14#include "adxl34x.h"
15
16#define MAX_SPI_FREQ_HZ 5000000
17#define MAX_FREQ_NO_FIFODELAY 1500000
18#define ADXL34X_CMD_MULTB (1 << 6)
19#define ADXL34X_CMD_READ (1 << 7)
20#define ADXL34X_WRITECMD(reg) (reg & 0x3F)
21#define ADXL34X_READCMD(reg) (ADXL34X_CMD_READ | (reg & 0x3F))
22#define ADXL34X_READMB_CMD(reg) (ADXL34X_CMD_READ | ADXL34X_CMD_MULTB \
23 | (reg & 0x3F))
24
25static int adxl34x_spi_read(struct device *dev, unsigned char reg)
26{
27 struct spi_device *spi = to_spi_device(dev);
28 unsigned char cmd;
29
30 cmd = ADXL34X_READCMD(reg);
31
32 return spi_w8r8(spi, cmd);
33}
34
35static int adxl34x_spi_write(struct device *dev,
36 unsigned char reg, unsigned char val)
37{
38 struct spi_device *spi = to_spi_device(dev);
39 unsigned char buf[2];
40
41 buf[0] = ADXL34X_WRITECMD(reg);
42 buf[1] = val;
43
44 return spi_write(spi, buf, sizeof(buf));
45}
46
47static int adxl34x_spi_read_block(struct device *dev,
48 unsigned char reg, int count,
49 void *buf)
50{
51 struct spi_device *spi = to_spi_device(dev);
52 ssize_t status;
53
54 reg = ADXL34X_READMB_CMD(reg);
55 status = spi_write_then_read(spi, &reg, 1, buf, count);
56
57 return (status < 0) ? status : 0;
58}
59
60static const struct adxl34x_bus_ops adx134x_spi_bops = {
61 .bustype = BUS_SPI,
62 .write = adxl34x_spi_write,
63 .read = adxl34x_spi_read,
64 .read_block = adxl34x_spi_read_block,
65};
66
67static int __devinit adxl34x_spi_probe(struct spi_device *spi)
68{
69 struct adxl34x *ac;
70
71 /* don't exceed max specified SPI CLK frequency */
72 if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
73 dev_err(&spi->dev, "SPI CLK %d Hz too fast\n", spi->max_speed_hz);
74 return -EINVAL;
75 }
76
77 ac = adxl34x_probe(&spi->dev, spi->irq,
78 spi->max_speed_hz > MAX_FREQ_NO_FIFODELAY,
79 &adx134x_spi_bops);
80
81 if (IS_ERR(ac))
82 return PTR_ERR(ac);
83
84 spi_set_drvdata(spi, ac);
85
86 return 0;
87}
88
89static int __devexit adxl34x_spi_remove(struct spi_device *spi)
90{
91 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
92
93 return adxl34x_remove(ac);
94}
95
96#ifdef CONFIG_PM
97static int adxl34x_suspend(struct spi_device *spi, pm_message_t message)
98{
99 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
100
101 adxl34x_disable(ac);
102
103 return 0;
104}
105
106static int adxl34x_resume(struct spi_device *spi)
107{
108 struct adxl34x *ac = dev_get_drvdata(&spi->dev);
109
110 adxl34x_enable(ac);
111
112 return 0;
113}
114#else
115# define adxl34x_suspend NULL
116# define adxl34x_resume NULL
117#endif
118
119static struct spi_driver adxl34x_driver = {
120 .driver = {
121 .name = "adxl34x",
122 .bus = &spi_bus_type,
123 .owner = THIS_MODULE,
124 },
125 .probe = adxl34x_spi_probe,
126 .remove = __devexit_p(adxl34x_spi_remove),
127 .suspend = adxl34x_suspend,
128 .resume = adxl34x_resume,
129};
130
131static int __init adxl34x_spi_init(void)
132{
133 return spi_register_driver(&adxl34x_driver);
134}
135module_init(adxl34x_spi_init);
136
137static void __exit adxl34x_spi_exit(void)
138{
139 spi_unregister_driver(&adxl34x_driver);
140}
141module_exit(adxl34x_spi_exit);
142
143MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
144MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer SPI Bus Driver");
145MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
new file mode 100644
index 000000000000..07f9ef631540
--- /dev/null
+++ b/drivers/input/misc/adxl34x.c
@@ -0,0 +1,840 @@
1/*
2 * ADXL345/346 Three-Axis Digital Accelerometers
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/device.h>
11#include <linux/init.h>
12#include <linux/delay.h>
13#include <linux/input.h>
14#include <linux/interrupt.h>
15#include <linux/irq.h>
16#include <linux/slab.h>
17#include <linux/workqueue.h>
18#include <linux/input/adxl34x.h>
19
20#include "adxl34x.h"
21
22/* ADXL345/6 Register Map */
23#define DEVID 0x00 /* R Device ID */
24#define THRESH_TAP 0x1D /* R/W Tap threshold */
25#define OFSX 0x1E /* R/W X-axis offset */
26#define OFSY 0x1F /* R/W Y-axis offset */
27#define OFSZ 0x20 /* R/W Z-axis offset */
28#define DUR 0x21 /* R/W Tap duration */
29#define LATENT 0x22 /* R/W Tap latency */
30#define WINDOW 0x23 /* R/W Tap window */
31#define THRESH_ACT 0x24 /* R/W Activity threshold */
32#define THRESH_INACT 0x25 /* R/W Inactivity threshold */
33#define TIME_INACT 0x26 /* R/W Inactivity time */
34#define ACT_INACT_CTL 0x27 /* R/W Axis enable control for activity and */
35 /* inactivity detection */
36#define THRESH_FF 0x28 /* R/W Free-fall threshold */
37#define TIME_FF 0x29 /* R/W Free-fall time */
38#define TAP_AXES 0x2A /* R/W Axis control for tap/double tap */
39#define ACT_TAP_STATUS 0x2B /* R Source of tap/double tap */
40#define BW_RATE 0x2C /* R/W Data rate and power mode control */
41#define POWER_CTL 0x2D /* R/W Power saving features control */
42#define INT_ENABLE 0x2E /* R/W Interrupt enable control */
43#define INT_MAP 0x2F /* R/W Interrupt mapping control */
44#define INT_SOURCE 0x30 /* R Source of interrupts */
45#define DATA_FORMAT 0x31 /* R/W Data format control */
46#define DATAX0 0x32 /* R X-Axis Data 0 */
47#define DATAX1 0x33 /* R X-Axis Data 1 */
48#define DATAY0 0x34 /* R Y-Axis Data 0 */
49#define DATAY1 0x35 /* R Y-Axis Data 1 */
50#define DATAZ0 0x36 /* R Z-Axis Data 0 */
51#define DATAZ1 0x37 /* R Z-Axis Data 1 */
52#define FIFO_CTL 0x38 /* R/W FIFO control */
53#define FIFO_STATUS 0x39 /* R FIFO status */
54#define TAP_SIGN 0x3A /* R Sign and source for tap/double tap */
55/* Orientation ADXL346 only */
56#define ORIENT_CONF 0x3B /* R/W Orientation configuration */
57#define ORIENT 0x3C /* R Orientation status */
58
59/* DEVIDs */
60#define ID_ADXL345 0xE5
61#define ID_ADXL346 0xE6
62
63/* INT_ENABLE/INT_MAP/INT_SOURCE Bits */
64#define DATA_READY (1 << 7)
65#define SINGLE_TAP (1 << 6)
66#define DOUBLE_TAP (1 << 5)
67#define ACTIVITY (1 << 4)
68#define INACTIVITY (1 << 3)
69#define FREE_FALL (1 << 2)
70#define WATERMARK (1 << 1)
71#define OVERRUN (1 << 0)
72
73/* ACT_INACT_CONTROL Bits */
74#define ACT_ACDC (1 << 7)
75#define ACT_X_EN (1 << 6)
76#define ACT_Y_EN (1 << 5)
77#define ACT_Z_EN (1 << 4)
78#define INACT_ACDC (1 << 3)
79#define INACT_X_EN (1 << 2)
80#define INACT_Y_EN (1 << 1)
81#define INACT_Z_EN (1 << 0)
82
83/* TAP_AXES Bits */
84#define SUPPRESS (1 << 3)
85#define TAP_X_EN (1 << 2)
86#define TAP_Y_EN (1 << 1)
87#define TAP_Z_EN (1 << 0)
88
89/* ACT_TAP_STATUS Bits */
90#define ACT_X_SRC (1 << 6)
91#define ACT_Y_SRC (1 << 5)
92#define ACT_Z_SRC (1 << 4)
93#define ASLEEP (1 << 3)
94#define TAP_X_SRC (1 << 2)
95#define TAP_Y_SRC (1 << 1)
96#define TAP_Z_SRC (1 << 0)
97
98/* BW_RATE Bits */
99#define LOW_POWER (1 << 4)
100#define RATE(x) ((x) & 0xF)
101
102/* POWER_CTL Bits */
103#define PCTL_LINK (1 << 5)
104#define PCTL_AUTO_SLEEP (1 << 4)
105#define PCTL_MEASURE (1 << 3)
106#define PCTL_SLEEP (1 << 2)
107#define PCTL_WAKEUP(x) ((x) & 0x3)
108
109/* DATA_FORMAT Bits */
110#define SELF_TEST (1 << 7)
111#define SPI (1 << 6)
112#define INT_INVERT (1 << 5)
113#define FULL_RES (1 << 3)
114#define JUSTIFY (1 << 2)
115#define RANGE(x) ((x) & 0x3)
116#define RANGE_PM_2g 0
117#define RANGE_PM_4g 1
118#define RANGE_PM_8g 2
119#define RANGE_PM_16g 3
120
121/*
122 * Maximum value our axis may get in full res mode for the input device
123 * (signed 13 bits)
124 */
125#define ADXL_FULLRES_MAX_VAL 4096
126
127/*
128 * Maximum value our axis may get in fixed res mode for the input device
129 * (signed 10 bits)
130 */
131#define ADXL_FIXEDRES_MAX_VAL 512
132
133/* FIFO_CTL Bits */
134#define FIFO_MODE(x) (((x) & 0x3) << 6)
135#define FIFO_BYPASS 0
136#define FIFO_FIFO 1
137#define FIFO_STREAM 2
138#define FIFO_TRIGGER 3
139#define TRIGGER (1 << 5)
140#define SAMPLES(x) ((x) & 0x1F)
141
142/* FIFO_STATUS Bits */
143#define FIFO_TRIG (1 << 7)
144#define ENTRIES(x) ((x) & 0x3F)
145
146/* TAP_SIGN Bits ADXL346 only */
147#define XSIGN (1 << 6)
148#define YSIGN (1 << 5)
149#define ZSIGN (1 << 4)
150#define XTAP (1 << 3)
151#define YTAP (1 << 2)
152#define ZTAP (1 << 1)
153
154/* ORIENT_CONF ADXL346 only */
155#define ORIENT_DEADZONE(x) (((x) & 0x7) << 4)
156#define ORIENT_DIVISOR(x) ((x) & 0x7)
157
158/* ORIENT ADXL346 only */
159#define ADXL346_2D_VALID (1 << 6)
160#define ADXL346_2D_ORIENT(x) (((x) & 0x3) >> 4)
161#define ADXL346_3D_VALID (1 << 3)
162#define ADXL346_3D_ORIENT(x) ((x) & 0x7)
163#define ADXL346_2D_PORTRAIT_POS 0 /* +X */
164#define ADXL346_2D_PORTRAIT_NEG 1 /* -X */
165#define ADXL346_2D_LANDSCAPE_POS 2 /* +Y */
166#define ADXL346_2D_LANDSCAPE_NEG 3 /* -Y */
167
168#define ADXL346_3D_FRONT 3 /* +X */
169#define ADXL346_3D_BACK 4 /* -X */
170#define ADXL346_3D_RIGHT 2 /* +Y */
171#define ADXL346_3D_LEFT 5 /* -Y */
172#define ADXL346_3D_TOP 1 /* +Z */
173#define ADXL346_3D_BOTTOM 6 /* -Z */
174
175#undef ADXL_DEBUG
176
177#define ADXL_X_AXIS 0
178#define ADXL_Y_AXIS 1
179#define ADXL_Z_AXIS 2
180
181#define AC_READ(ac, reg) ((ac)->bops->read((ac)->dev, reg))
182#define AC_WRITE(ac, reg, val) ((ac)->bops->write((ac)->dev, reg, val))
183
184struct axis_triple {
185 int x;
186 int y;
187 int z;
188};
189
190struct adxl34x {
191 struct device *dev;
192 struct input_dev *input;
193 struct mutex mutex; /* reentrant protection for struct */
194 struct adxl34x_platform_data pdata;
195 struct axis_triple swcal;
196 struct axis_triple hwcal;
197 struct axis_triple saved;
198 char phys[32];
199 bool disabled; /* P: mutex */
200 bool opened; /* P: mutex */
201 bool fifo_delay;
202 int irq;
203 unsigned model;
204 unsigned int_mask;
205
206 const struct adxl34x_bus_ops *bops;
207};
208
209static const struct adxl34x_platform_data adxl34x_default_init = {
210 .tap_threshold = 35,
211 .tap_duration = 3,
212 .tap_latency = 20,
213 .tap_window = 20,
214 .tap_axis_control = ADXL_TAP_X_EN | ADXL_TAP_Y_EN | ADXL_TAP_Z_EN,
215 .act_axis_control = 0xFF,
216 .activity_threshold = 6,
217 .inactivity_threshold = 4,
218 .inactivity_time = 3,
219 .free_fall_threshold = 8,
220 .free_fall_time = 0x20,
221 .data_rate = 8,
222 .data_range = ADXL_FULL_RES,
223
224 .ev_type = EV_ABS,
225 .ev_code_x = ABS_X, /* EV_REL */
226 .ev_code_y = ABS_Y, /* EV_REL */
227 .ev_code_z = ABS_Z, /* EV_REL */
228
229 .ev_code_tap = {BTN_TOUCH, BTN_TOUCH, BTN_TOUCH}, /* EV_KEY {x,y,z} */
230 .power_mode = ADXL_AUTO_SLEEP | ADXL_LINK,
231 .fifo_mode = FIFO_STREAM,
232 .watermark = 0,
233};
234
235static void adxl34x_get_triple(struct adxl34x *ac, struct axis_triple *axis)
236{
237 short buf[3];
238
239 ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf);
240
241 mutex_lock(&ac->mutex);
242 ac->saved.x = (s16) le16_to_cpu(buf[0]);
243 axis->x = ac->saved.x;
244
245 ac->saved.y = (s16) le16_to_cpu(buf[1]);
246 axis->y = ac->saved.y;
247
248 ac->saved.z = (s16) le16_to_cpu(buf[2]);
249 axis->z = ac->saved.z;
250 mutex_unlock(&ac->mutex);
251}
252
253static void adxl34x_service_ev_fifo(struct adxl34x *ac)
254{
255 struct adxl34x_platform_data *pdata = &ac->pdata;
256 struct axis_triple axis;
257
258 adxl34x_get_triple(ac, &axis);
259
260 input_event(ac->input, pdata->ev_type, pdata->ev_code_x,
261 axis.x - ac->swcal.x);
262 input_event(ac->input, pdata->ev_type, pdata->ev_code_y,
263 axis.y - ac->swcal.y);
264 input_event(ac->input, pdata->ev_type, pdata->ev_code_z,
265 axis.z - ac->swcal.z);
266}
267
268static void adxl34x_report_key_single(struct input_dev *input, int key)
269{
270 input_report_key(input, key, true);
271 input_sync(input);
272 input_report_key(input, key, false);
273}
274
275static void adxl34x_send_key_events(struct adxl34x *ac,
276 struct adxl34x_platform_data *pdata, int status, int press)
277{
278 int i;
279
280 for (i = ADXL_X_AXIS; i <= ADXL_Z_AXIS; i++) {
281 if (status & (1 << (ADXL_Z_AXIS - i)))
282 input_report_key(ac->input,
283 pdata->ev_code_tap[i], press);
284 }
285}
286
287static void adxl34x_do_tap(struct adxl34x *ac,
288 struct adxl34x_platform_data *pdata, int status)
289{
290 adxl34x_send_key_events(ac, pdata, status, true);
291 input_sync(ac->input);
292 adxl34x_send_key_events(ac, pdata, status, false);
293}
294
295static irqreturn_t adxl34x_irq(int irq, void *handle)
296{
297 struct adxl34x *ac = handle;
298 struct adxl34x_platform_data *pdata = &ac->pdata;
299 int int_stat, tap_stat, samples;
300
301 /*
302 * ACT_TAP_STATUS should be read before clearing the interrupt
303 * Avoid reading ACT_TAP_STATUS in case TAP detection is disabled
304 */
305
306 if (pdata->tap_axis_control & (TAP_X_EN | TAP_Y_EN | TAP_Z_EN))
307 tap_stat = AC_READ(ac, ACT_TAP_STATUS);
308 else
309 tap_stat = 0;
310
311 int_stat = AC_READ(ac, INT_SOURCE);
312
313 if (int_stat & FREE_FALL)
314 adxl34x_report_key_single(ac->input, pdata->ev_code_ff);
315
316 if (int_stat & OVERRUN)
317 dev_dbg(ac->dev, "OVERRUN\n");
318
319 if (int_stat & (SINGLE_TAP | DOUBLE_TAP)) {
320 adxl34x_do_tap(ac, pdata, tap_stat);
321
322 if (int_stat & DOUBLE_TAP)
323 adxl34x_do_tap(ac, pdata, tap_stat);
324 }
325
326 if (pdata->ev_code_act_inactivity) {
327 if (int_stat & ACTIVITY)
328 input_report_key(ac->input,
329 pdata->ev_code_act_inactivity, 1);
330 if (int_stat & INACTIVITY)
331 input_report_key(ac->input,
332 pdata->ev_code_act_inactivity, 0);
333 }
334
335 if (int_stat & (DATA_READY | WATERMARK)) {
336
337 if (pdata->fifo_mode)
338 samples = ENTRIES(AC_READ(ac, FIFO_STATUS)) + 1;
339 else
340 samples = 1;
341
342 for (; samples > 0; samples--) {
343 adxl34x_service_ev_fifo(ac);
344 /*
345 * To ensure that the FIFO has
346 * completely popped, there must be at least 5 us between
347 * the end of reading the data registers, signified by the
348 * transition to register 0x38 from 0x37 or the CS pin
349 * going high, and the start of new reads of the FIFO or
350 * reading the FIFO_STATUS register. For SPI operation at
351 * 1.5 MHz or lower, the register addressing portion of the
352 * transmission is sufficient delay to ensure the FIFO has
353 * completely popped. It is necessary for SPI operation
354 * greater than 1.5 MHz to de-assert the CS pin to ensure a
355 * total of 5 us, which is at most 3.4 us at 5 MHz
356 * operation.
357 */
358 if (ac->fifo_delay && (samples > 1))
359 udelay(3);
360 }
361 }
362
363 input_sync(ac->input);
364
365 return IRQ_HANDLED;
366}
367
368static void __adxl34x_disable(struct adxl34x *ac)
369{
370 if (!ac->disabled && ac->opened) {
371 /*
372 * A '0' places the ADXL34x into standby mode
373 * with minimum power consumption.
374 */
375 AC_WRITE(ac, POWER_CTL, 0);
376
377 ac->disabled = true;
378 }
379}
380
381static void __adxl34x_enable(struct adxl34x *ac)
382{
383 if (ac->disabled && ac->opened) {
384 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE);
385 ac->disabled = false;
386 }
387}
388
389void adxl34x_disable(struct adxl34x *ac)
390{
391 mutex_lock(&ac->mutex);
392 __adxl34x_disable(ac);
393 mutex_unlock(&ac->mutex);
394}
395EXPORT_SYMBOL_GPL(adxl34x_disable);
396
397void adxl34x_enable(struct adxl34x *ac)
398{
399 mutex_lock(&ac->mutex);
400 __adxl34x_enable(ac);
401 mutex_unlock(&ac->mutex);
402}
403
404EXPORT_SYMBOL_GPL(adxl34x_enable);
405
406static ssize_t adxl34x_disable_show(struct device *dev,
407 struct device_attribute *attr, char *buf)
408{
409 struct adxl34x *ac = dev_get_drvdata(dev);
410
411 return sprintf(buf, "%u\n", ac->disabled);
412}
413
414static ssize_t adxl34x_disable_store(struct device *dev,
415 struct device_attribute *attr,
416 const char *buf, size_t count)
417{
418 struct adxl34x *ac = dev_get_drvdata(dev);
419 unsigned long val;
420 int error;
421
422 error = strict_strtoul(buf, 10, &val);
423 if (error)
424 return error;
425
426 if (val)
427 adxl34x_disable(ac);
428 else
429 adxl34x_enable(ac);
430
431 return count;
432}
433
434static DEVICE_ATTR(disable, 0664, adxl34x_disable_show, adxl34x_disable_store);
435
436static ssize_t adxl34x_calibrate_show(struct device *dev,
437 struct device_attribute *attr, char *buf)
438{
439 struct adxl34x *ac = dev_get_drvdata(dev);
440 ssize_t count;
441
442 mutex_lock(&ac->mutex);
443 count = sprintf(buf, "%d,%d,%d\n",
444 ac->hwcal.x * 4 + ac->swcal.x,
445 ac->hwcal.y * 4 + ac->swcal.y,
446 ac->hwcal.z * 4 + ac->swcal.z);
447 mutex_unlock(&ac->mutex);
448
449 return count;
450}
451
452static ssize_t adxl34x_calibrate_store(struct device *dev,
453 struct device_attribute *attr,
454 const char *buf, size_t count)
455{
456 struct adxl34x *ac = dev_get_drvdata(dev);
457
458 /*
459 * Hardware offset calibration has a resolution of 15.6 mg/LSB.
460 * We use HW calibration and handle the remaining bits in SW. (4mg/LSB)
461 */
462
463 mutex_lock(&ac->mutex);
464 ac->hwcal.x -= (ac->saved.x / 4);
465 ac->swcal.x = ac->saved.x % 4;
466
467 ac->hwcal.y -= (ac->saved.y / 4);
468 ac->swcal.y = ac->saved.y % 4;
469
470 ac->hwcal.z -= (ac->saved.z / 4);
471 ac->swcal.z = ac->saved.z % 4;
472
473 AC_WRITE(ac, OFSX, (s8) ac->hwcal.x);
474 AC_WRITE(ac, OFSY, (s8) ac->hwcal.y);
475 AC_WRITE(ac, OFSZ, (s8) ac->hwcal.z);
476 mutex_unlock(&ac->mutex);
477
478 return count;
479}
480
481static DEVICE_ATTR(calibrate, 0664,
482 adxl34x_calibrate_show, adxl34x_calibrate_store);
483
484static ssize_t adxl34x_rate_show(struct device *dev,
485 struct device_attribute *attr, char *buf)
486{
487 struct adxl34x *ac = dev_get_drvdata(dev);
488
489 return sprintf(buf, "%u\n", RATE(ac->pdata.data_rate));
490}
491
492static ssize_t adxl34x_rate_store(struct device *dev,
493 struct device_attribute *attr,
494 const char *buf, size_t count)
495{
496 struct adxl34x *ac = dev_get_drvdata(dev);
497 unsigned long val;
498 int error;
499
500 error = strict_strtoul(buf, 10, &val);
501 if (error)
502 return error;
503
504 mutex_lock(&ac->mutex);
505
506 ac->pdata.data_rate = RATE(val);
507 AC_WRITE(ac, BW_RATE,
508 ac->pdata.data_rate |
509 (ac->pdata.low_power_mode ? LOW_POWER : 0));
510
511 mutex_unlock(&ac->mutex);
512
513 return count;
514}
515
516static DEVICE_ATTR(rate, 0664, adxl34x_rate_show, adxl34x_rate_store);
517
518static ssize_t adxl34x_autosleep_show(struct device *dev,
519 struct device_attribute *attr, char *buf)
520{
521 struct adxl34x *ac = dev_get_drvdata(dev);
522
523 return sprintf(buf, "%u\n",
524 ac->pdata.power_mode & (PCTL_AUTO_SLEEP | PCTL_LINK) ? 1 : 0);
525}
526
527static ssize_t adxl34x_autosleep_store(struct device *dev,
528 struct device_attribute *attr,
529 const char *buf, size_t count)
530{
531 struct adxl34x *ac = dev_get_drvdata(dev);
532 unsigned long val;
533 int error;
534
535 error = strict_strtoul(buf, 10, &val);
536 if (error)
537 return error;
538
539 mutex_lock(&ac->mutex);
540
541 if (val)
542 ac->pdata.power_mode |= (PCTL_AUTO_SLEEP | PCTL_LINK);
543 else
544 ac->pdata.power_mode &= ~(PCTL_AUTO_SLEEP | PCTL_LINK);
545
546 if (!ac->disabled && ac->opened)
547 AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE);
548
549 mutex_unlock(&ac->mutex);
550
551 return count;
552}
553
554static DEVICE_ATTR(autosleep, 0664,
555 adxl34x_autosleep_show, adxl34x_autosleep_store);
556
557static ssize_t adxl34x_position_show(struct device *dev,
558 struct device_attribute *attr, char *buf)
559{
560 struct adxl34x *ac = dev_get_drvdata(dev);
561 ssize_t count;
562
563 mutex_lock(&ac->mutex);
564 count = sprintf(buf, "(%d, %d, %d)\n",
565 ac->saved.x, ac->saved.y, ac->saved.z);
566 mutex_unlock(&ac->mutex);
567
568 return count;
569}
570
571static DEVICE_ATTR(position, S_IRUGO, adxl34x_position_show, NULL);
572
573#ifdef ADXL_DEBUG
574static ssize_t adxl34x_write_store(struct device *dev,
575 struct device_attribute *attr,
576 const char *buf, size_t count)
577{
578 struct adxl34x *ac = dev_get_drvdata(dev);
579 unsigned long val;
580 int error;
581
582 /*
583 * This allows basic ADXL register write access for debug purposes.
584 */
585 error = strict_strtoul(buf, 16, &val);
586 if (error)
587 return error;
588
589 mutex_lock(&ac->mutex);
590 AC_WRITE(ac, val >> 8, val & 0xFF);
591 mutex_unlock(&ac->mutex);
592
593 return count;
594}
595
596static DEVICE_ATTR(write, 0664, NULL, adxl34x_write_store);
597#endif
598
599static struct attribute *adxl34x_attributes[] = {
600 &dev_attr_disable.attr,
601 &dev_attr_calibrate.attr,
602 &dev_attr_rate.attr,
603 &dev_attr_autosleep.attr,
604 &dev_attr_position.attr,
605#ifdef ADXL_DEBUG
606 &dev_attr_write.attr,
607#endif
608 NULL
609};
610
611static const struct attribute_group adxl34x_attr_group = {
612 .attrs = adxl34x_attributes,
613};
614
615static int adxl34x_input_open(struct input_dev *input)
616{
617 struct adxl34x *ac = input_get_drvdata(input);
618
619 mutex_lock(&ac->mutex);
620 ac->opened = true;
621 __adxl34x_enable(ac);
622 mutex_unlock(&ac->mutex);
623
624 return 0;
625}
626
627static void adxl34x_input_close(struct input_dev *input)
628{
629 struct adxl34x *ac = input_get_drvdata(input);
630
631 mutex_lock(&ac->mutex);
632 __adxl34x_disable(ac);
633 ac->opened = false;
634 mutex_unlock(&ac->mutex);
635}
636
637struct adxl34x *adxl34x_probe(struct device *dev, int irq,
638 bool fifo_delay_default,
639 const struct adxl34x_bus_ops *bops)
640{
641 struct adxl34x *ac;
642 struct input_dev *input_dev;
643 const struct adxl34x_platform_data *pdata;
644 int err, range;
645 unsigned char revid;
646
647 if (!irq) {
648 dev_err(dev, "no IRQ?\n");
649 err = -ENODEV;
650 goto err_out;
651 }
652
653 ac = kzalloc(sizeof(*ac), GFP_KERNEL);
654 input_dev = input_allocate_device();
655 if (!ac || !input_dev) {
656 err = -ENOMEM;
657 goto err_out;
658 }
659
660 ac->fifo_delay = fifo_delay_default;
661
662 pdata = dev->platform_data;
663 if (!pdata) {
664 dev_dbg(dev,
665 "No platfrom data: Using default initialization\n");
666 pdata = &adxl34x_default_init;
667 }
668
669 ac->pdata = *pdata;
670 pdata = &ac->pdata;
671
672 ac->input = input_dev;
673 ac->disabled = true;
674 ac->dev = dev;
675 ac->irq = irq;
676 ac->bops = bops;
677
678 mutex_init(&ac->mutex);
679
680 input_dev->name = "ADXL34x accelerometer";
681 revid = ac->bops->read(dev, DEVID);
682
683 switch (revid) {
684 case ID_ADXL345:
685 ac->model = 345;
686 break;
687 case ID_ADXL346:
688 ac->model = 346;
689 break;
690 default:
691 dev_err(dev, "Failed to probe %s\n", input_dev->name);
692 err = -ENODEV;
693 goto err_free_mem;
694 }
695
696 snprintf(ac->phys, sizeof(ac->phys), "%s/input0", dev_name(dev));
697
698 input_dev->phys = ac->phys;
699 input_dev->dev.parent = dev;
700 input_dev->id.product = ac->model;
701 input_dev->id.bustype = bops->bustype;
702 input_dev->open = adxl34x_input_open;
703 input_dev->close = adxl34x_input_close;
704
705 input_set_drvdata(input_dev, ac);
706
707 __set_bit(ac->pdata.ev_type, input_dev->evbit);
708
709 if (ac->pdata.ev_type == EV_REL) {
710 __set_bit(REL_X, input_dev->relbit);
711 __set_bit(REL_Y, input_dev->relbit);
712 __set_bit(REL_Z, input_dev->relbit);
713 } else {
714 /* EV_ABS */
715 __set_bit(ABS_X, input_dev->absbit);
716 __set_bit(ABS_Y, input_dev->absbit);
717 __set_bit(ABS_Z, input_dev->absbit);
718
719 if (pdata->data_range & FULL_RES)
720 range = ADXL_FULLRES_MAX_VAL; /* Signed 13-bit */
721 else
722 range = ADXL_FIXEDRES_MAX_VAL; /* Signed 10-bit */
723
724 input_set_abs_params(input_dev, ABS_X, -range, range, 3, 3);
725 input_set_abs_params(input_dev, ABS_Y, -range, range, 3, 3);
726 input_set_abs_params(input_dev, ABS_Z, -range, range, 3, 3);
727 }
728
729 __set_bit(EV_KEY, input_dev->evbit);
730 __set_bit(pdata->ev_code_tap[ADXL_X_AXIS], input_dev->keybit);
731 __set_bit(pdata->ev_code_tap[ADXL_Y_AXIS], input_dev->keybit);
732 __set_bit(pdata->ev_code_tap[ADXL_Z_AXIS], input_dev->keybit);
733
734 if (pdata->ev_code_ff) {
735 ac->int_mask = FREE_FALL;
736 __set_bit(pdata->ev_code_ff, input_dev->keybit);
737 }
738
739 if (pdata->ev_code_act_inactivity)
740 __set_bit(pdata->ev_code_act_inactivity, input_dev->keybit);
741
742 ac->int_mask |= ACTIVITY | INACTIVITY;
743
744 if (pdata->watermark) {
745 ac->int_mask |= WATERMARK;
746 if (!FIFO_MODE(pdata->fifo_mode))
747 ac->pdata.fifo_mode |= FIFO_STREAM;
748 } else {
749 ac->int_mask |= DATA_READY;
750 }
751
752 if (pdata->tap_axis_control & (TAP_X_EN | TAP_Y_EN | TAP_Z_EN))
753 ac->int_mask |= SINGLE_TAP | DOUBLE_TAP;
754
755 if (FIFO_MODE(pdata->fifo_mode) == FIFO_BYPASS)
756 ac->fifo_delay = false;
757
758 ac->bops->write(dev, POWER_CTL, 0);
759
760 err = request_threaded_irq(ac->irq, NULL, adxl34x_irq,
761 IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
762 dev_name(dev), ac);
763 if (err) {
764 dev_err(dev, "irq %d busy?\n", ac->irq);
765 goto err_free_mem;
766 }
767
768 err = sysfs_create_group(&dev->kobj, &adxl34x_attr_group);
769 if (err)
770 goto err_free_irq;
771
772 err = input_register_device(input_dev);
773 if (err)
774 goto err_remove_attr;
775
776 AC_WRITE(ac, THRESH_TAP, pdata->tap_threshold);
777 AC_WRITE(ac, OFSX, pdata->x_axis_offset);
778 ac->hwcal.x = pdata->x_axis_offset;
779 AC_WRITE(ac, OFSY, pdata->y_axis_offset);
780 ac->hwcal.y = pdata->y_axis_offset;
781 AC_WRITE(ac, OFSZ, pdata->z_axis_offset);
782 ac->hwcal.z = pdata->z_axis_offset;
783 AC_WRITE(ac, THRESH_TAP, pdata->tap_threshold);
784 AC_WRITE(ac, DUR, pdata->tap_duration);
785 AC_WRITE(ac, LATENT, pdata->tap_latency);
786 AC_WRITE(ac, WINDOW, pdata->tap_window);
787 AC_WRITE(ac, THRESH_ACT, pdata->activity_threshold);
788 AC_WRITE(ac, THRESH_INACT, pdata->inactivity_threshold);
789 AC_WRITE(ac, TIME_INACT, pdata->inactivity_time);
790 AC_WRITE(ac, THRESH_FF, pdata->free_fall_threshold);
791 AC_WRITE(ac, TIME_FF, pdata->free_fall_time);
792 AC_WRITE(ac, TAP_AXES, pdata->tap_axis_control);
793 AC_WRITE(ac, ACT_INACT_CTL, pdata->act_axis_control);
794 AC_WRITE(ac, BW_RATE, RATE(ac->pdata.data_rate) |
795 (pdata->low_power_mode ? LOW_POWER : 0));
796 AC_WRITE(ac, DATA_FORMAT, pdata->data_range);
797 AC_WRITE(ac, FIFO_CTL, FIFO_MODE(pdata->fifo_mode) |
798 SAMPLES(pdata->watermark));
799
800 if (pdata->use_int2)
801 /* Map all INTs to INT2 */
802 AC_WRITE(ac, INT_MAP, ac->int_mask | OVERRUN);
803 else
804 /* Map all INTs to INT1 */
805 AC_WRITE(ac, INT_MAP, 0);
806
807 AC_WRITE(ac, INT_ENABLE, ac->int_mask | OVERRUN);
808
809 ac->pdata.power_mode &= (PCTL_AUTO_SLEEP | PCTL_LINK);
810
811 return ac;
812
813 err_remove_attr:
814 sysfs_remove_group(&dev->kobj, &adxl34x_attr_group);
815 err_free_irq:
816 free_irq(ac->irq, ac);
817 err_free_mem:
818 input_free_device(input_dev);
819 kfree(ac);
820 err_out:
821 return ERR_PTR(err);
822}
823EXPORT_SYMBOL_GPL(adxl34x_probe);
824
825int adxl34x_remove(struct adxl34x *ac)
826{
827 adxl34x_disable(ac);
828 sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group);
829 free_irq(ac->irq, ac);
830 input_unregister_device(ac->input);
831 kfree(ac);
832
833 dev_dbg(ac->dev, "unregistered accelerometer\n");
834 return 0;
835}
836EXPORT_SYMBOL_GPL(adxl34x_remove);
837
838MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
839MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer Driver");
840MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/adxl34x.h b/drivers/input/misc/adxl34x.h
new file mode 100644
index 000000000000..ea9093c15c81
--- /dev/null
+++ b/drivers/input/misc/adxl34x.h
@@ -0,0 +1,30 @@
1/*
2 * ADXL345/346 Three-Axis Digital Accelerometers (I2C/SPI Interface)
3 *
4 * Enter bugs at http://blackfin.uclinux.org/
5 *
6 * Copyright (C) 2009 Michael Hennerich, Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
8 */
9
10#ifndef _ADXL34X_H_
11#define _ADXL34X_H_
12
13struct device;
14struct adxl34x;
15
16struct adxl34x_bus_ops {
17 u16 bustype;
18 int (*read)(struct device *, unsigned char);
19 int (*read_block)(struct device *, unsigned char, int, void *);
20 int (*write)(struct device *, unsigned char, unsigned char);
21};
22
23void adxl34x_disable(struct adxl34x *ac);
24void adxl34x_enable(struct adxl34x *ac);
25struct adxl34x *adxl34x_probe(struct device *dev, int irq,
26 bool fifo_delay_default,
27 const struct adxl34x_bus_ops *bops);
28int adxl34x_remove(struct adxl34x *ac);
29
30#endif
diff --git a/include/linux/input/adxl34x.h b/include/linux/input/adxl34x.h
new file mode 100644
index 000000000000..712118238038
--- /dev/null
+++ b/include/linux/input/adxl34x.h
@@ -0,0 +1,293 @@
1/*
2 * include/linux/input/adxl34x.h
3 *
4 * Digital Accelerometer characteristics are highly application specific
5 * and may vary between boards and models. The platform_data for the
6 * device's "struct device" holds this information.
7 *
8 * Copyright 2009 Analog Devices Inc.
9 *
10 * Licensed under the GPL-2 or later.
11 */
12
13#ifndef __LINUX_INPUT_ADXL34X_H__
14#define __LINUX_INPUT_ADXL34X_H__
15
16struct adxl34x_platform_data {
17
18 /*
19 * X,Y,Z Axis Offset:
20 * offer user offset adjustments in twoscompliment
21 * form with a scale factor of 15.6 mg/LSB (i.e. 0x7F = +2 g)
22 */
23
24 s8 x_axis_offset;
25 s8 y_axis_offset;
26 s8 z_axis_offset;
27
28 /*
29 * TAP_X/Y/Z Enable: Setting TAP_X, Y, or Z Enable enables X,
30 * Y, or Z participation in Tap detection. A '0' excludes the
31 * selected axis from participation in Tap detection.
32 * Setting the SUPPRESS bit suppresses Double Tap detection if
33 * acceleration greater than tap_threshold is present between
34 * taps.
35 */
36
37#define ADXL_SUPPRESS (1 << 3)
38#define ADXL_TAP_X_EN (1 << 2)
39#define ADXL_TAP_Y_EN (1 << 1)
40#define ADXL_TAP_Z_EN (1 << 0)
41
42 u8 tap_axis_control;
43
44 /*
45 * tap_threshold:
46 * holds the threshold value for tap detection/interrupts.
47 * The data format is unsigned. The scale factor is 62.5 mg/LSB
48 * (i.e. 0xFF = +16 g). A zero value may result in undesirable
49 * behavior if Tap/Double Tap is enabled.
50 */
51
52 u8 tap_threshold;
53
54 /*
55 * tap_duration:
56 * is an unsigned time value representing the maximum
57 * time that an event must be above the tap_threshold threshold
58 * to qualify as a tap event. The scale factor is 625 us/LSB. A zero
59 * value will prevent Tap/Double Tap functions from working.
60 */
61
62 u8 tap_duration;
63
64 /*
65 * tap_latency:
66 * is an unsigned time value representing the wait time
67 * from the detection of a tap event to the opening of the time
68 * window tap_window for a possible second tap event. The scale
69 * factor is 1.25 ms/LSB. A zero value will disable the Double Tap
70 * function.
71 */
72
73 u8 tap_latency;
74
75 /*
76 * tap_window:
77 * is an unsigned time value representing the amount
78 * of time after the expiration of tap_latency during which a second
79 * tap can begin. The scale factor is 1.25 ms/LSB. A zero value will
80 * disable the Double Tap function.
81 */
82
83 u8 tap_window;
84
85 /*
86 * act_axis_control:
87 * X/Y/Z Enable: A '1' enables X, Y, or Z participation in activity
88 * or inactivity detection. A '0' excludes the selected axis from
89 * participation. If all of the axes are excluded, the function is
90 * disabled.
91 * AC/DC: A '0' = DC coupled operation and a '1' = AC coupled
92 * operation. In DC coupled operation, the current acceleration is
93 * compared with activity_threshold and inactivity_threshold directly
94 * to determine whether activity or inactivity is detected. In AC
95 * coupled operation for activity detection, the acceleration value
96 * at the start of activity detection is taken as a reference value.
97 * New samples of acceleration are then compared to this
98 * reference value and if the magnitude of the difference exceeds
99 * activity_threshold the device will trigger an activity interrupt. In
100 * AC coupled operation for inactivity detection, a reference value
101 * is used again for comparison and is updated whenever the
102 * device exceeds the inactivity threshold. Once the reference
103 * value is selected, the device compares the magnitude of the
104 * difference between the reference value and the current
105 * acceleration with inactivity_threshold. If the difference is below
106 * inactivity_threshold for a total of inactivity_time, the device is
107 * considered inactive and the inactivity interrupt is triggered.
108 */
109
110#define ADXL_ACT_ACDC (1 << 7)
111#define ADXL_ACT_X_EN (1 << 6)
112#define ADXL_ACT_Y_EN (1 << 5)
113#define ADXL_ACT_Z_EN (1 << 4)
114#define ADXL_INACT_ACDC (1 << 3)
115#define ADXL_INACT_X_EN (1 << 2)
116#define ADXL_INACT_Y_EN (1 << 1)
117#define ADXL_INACT_Z_EN (1 << 0)
118
119 u8 act_axis_control;
120
121 /*
122 * activity_threshold:
123 * holds the threshold value for activity detection.
124 * The data format is unsigned. The scale factor is
125 * 62.5 mg/LSB. A zero value may result in undesirable behavior if
126 * Activity interrupt is enabled.
127 */
128
129 u8 activity_threshold;
130
131 /*
132 * inactivity_threshold:
133 * holds the threshold value for inactivity
134 * detection. The data format is unsigned. The scale
135 * factor is 62.5 mg/LSB. A zero value may result in undesirable
136 * behavior if Inactivity interrupt is enabled.
137 */
138
139 u8 inactivity_threshold;
140
141 /*
142 * inactivity_time:
143 * is an unsigned time value representing the
144 * amount of time that acceleration must be below the value in
145 * inactivity_threshold for inactivity to be declared. The scale factor
146 * is 1 second/LSB. Unlike the other interrupt functions, which
147 * operate on unfiltered data, the inactivity function operates on the
148 * filtered output data. At least one output sample must be
149 * generated for the inactivity interrupt to be triggered. This will
150 * result in the function appearing un-responsive if the
151 * inactivity_time register is set with a value less than the time
152 * constant of the Output Data Rate. A zero value will result in an
153 * interrupt when the output data is below inactivity_threshold.
154 */
155
156 u8 inactivity_time;
157
158 /*
159 * free_fall_threshold:
160 * holds the threshold value for Free-Fall detection.
161 * The data format is unsigned. The root-sum-square(RSS) value
162 * of all axes is calculated and compared to the value in
163 * free_fall_threshold to determine if a free fall event may be
164 * occurring. The scale factor is 62.5 mg/LSB. A zero value may
165 * result in undesirable behavior if Free-Fall interrupt is
166 * enabled. Values between 300 and 600 mg (0x05 to 0x09) are
167 * recommended.
168 */
169
170 u8 free_fall_threshold;
171
172 /*
173 * free_fall_time:
174 * is an unsigned time value representing the minimum
175 * time that the RSS value of all axes must be less than
176 * free_fall_threshold to generate a Free-Fall interrupt. The
177 * scale factor is 5 ms/LSB. A zero value may result in
178 * undesirable behavior if Free-Fall interrupt is enabled.
179 * Values between 100 to 350 ms (0x14 to 0x46) are recommended.
180 */
181
182 u8 free_fall_time;
183
184 /*
185 * data_rate:
186 * Selects device bandwidth and output data rate.
187 * RATE = 3200 Hz / (2^(15 - x)). Default value is 0x0A, or 100 Hz
188 * Output Data Rate. An Output Data Rate should be selected that
189 * is appropriate for the communication protocol and frequency
190 * selected. Selecting too high of an Output Data Rate with a low
191 * communication speed will result in samples being discarded.
192 */
193
194 u8 data_rate;
195
196 /*
197 * data_range:
198 * FULL_RES: When this bit is set with the device is
199 * in Full-Resolution Mode, where the output resolution increases
200 * with RANGE to maintain a 4 mg/LSB scale factor. When this
201 * bit is cleared the device is in 10-bit Mode and RANGE determine the
202 * maximum g-Range and scale factor.
203 */
204
205#define ADXL_FULL_RES (1 << 3)
206#define ADXL_RANGE_PM_2g 0
207#define ADXL_RANGE_PM_4g 1
208#define ADXL_RANGE_PM_8g 2
209#define ADXL_RANGE_PM_16g 3
210
211 u8 data_range;
212
213 /*
214 * low_power_mode:
215 * A '0' = Normal operation and a '1' = Reduced
216 * power operation with somewhat higher noise.
217 */
218
219 u8 low_power_mode;
220
221 /*
222 * power_mode:
223 * LINK: A '1' with both the activity and inactivity functions
224 * enabled will delay the start of the activity function until
225 * inactivity is detected. Once activity is detected, inactivity
226 * detection will begin and prevent the detection of activity. This
227 * bit serially links the activity and inactivity functions. When '0'
228 * the inactivity and activity functions are concurrent. Additional
229 * information can be found in the Application section under Link
230 * Mode.
231 * AUTO_SLEEP: A '1' sets the ADXL34x to switch to Sleep Mode
232 * when inactivity (acceleration has been below inactivity_threshold
233 * for at least inactivity_time) is detected and the LINK bit is set.
234 * A '0' disables automatic switching to Sleep Mode. See SLEEP
235 * for further description.
236 */
237
238#define ADXL_LINK (1 << 5)
239#define ADXL_AUTO_SLEEP (1 << 4)
240
241 u8 power_mode;
242
243 /*
244 * fifo_mode:
245 * BYPASS The FIFO is bypassed
246 * FIFO FIFO collects up to 32 values then stops collecting data
247 * STREAM FIFO holds the last 32 data values. Once full, the FIFO's
248 * oldest data is lost as it is replaced with newer data
249 *
250 * DEFAULT should be ADXL_FIFO_STREAM
251 */
252
253#define ADXL_FIFO_BYPASS 0
254#define ADXL_FIFO_FIFO 1
255#define ADXL_FIFO_STREAM 2
256
257 u8 fifo_mode;
258
259 /*
260 * watermark:
261 * The Watermark feature can be used to reduce the interrupt load
262 * of the system. The FIFO fills up to the value stored in watermark
263 * [1..32] and then generates an interrupt.
264 * A '0' disables the watermark feature.
265 */
266
267 u8 watermark;
268
269 u32 ev_type; /* EV_ABS or EV_REL */
270
271 u32 ev_code_x; /* ABS_X,Y,Z or REL_X,Y,Z */
272 u32 ev_code_y; /* ABS_X,Y,Z or REL_X,Y,Z */
273 u32 ev_code_z; /* ABS_X,Y,Z or REL_X,Y,Z */
274
275 /*
276 * A valid BTN or KEY Code; use tap_axis_control to disable
277 * event reporting
278 */
279
280 u32 ev_code_tap[3]; /* EV_KEY {X-Axis, Y-Axis, Z-Axis} */
281
282 /*
283 * A valid BTN or KEY Code for Free-Fall or Activity enables
284 * input event reporting. A '0' disables the Free-Fall or
285 * Activity reporting.
286 */
287
288 u32 ev_code_ff; /* EV_KEY */
289 u32 ev_code_act_inactivity; /* EV_KEY */
290
291 u8 use_int2;
292};
293#endif