aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2011-10-27 00:46:20 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-10-27 00:46:20 -0400
commit6ad390a25a9d1d8606b9b826878f0a30639dc2b3 (patch)
tree05aff14f02776bc0d59a1f777cb92df6f4456ba9 /drivers/input/misc
parentd6069dae4700cf5290a75002c46b9be8ea7eef3c (diff)
parent3f48e7354358519e5b93f7f755ec270b3f8eafa0 (diff)
Merge branch 'next' into for-linus
Diffstat (limited to 'drivers/input/misc')
-rw-r--r--drivers/input/misc/Kconfig58
-rw-r--r--drivers/input/misc/Makefile5
-rw-r--r--drivers/input/misc/ad714x-i2c.c4
-rw-r--r--drivers/input/misc/bma150.c691
-rw-r--r--drivers/input/misc/ixp4xx-beeper.c2
-rw-r--r--drivers/input/misc/mma8450.c20
-rw-r--r--drivers/input/misc/pcspkr.c9
-rw-r--r--drivers/input/misc/pm8xxx-vibrator.c296
-rw-r--r--drivers/input/misc/pmic8xxx-pwrkey.c3
-rw-r--r--drivers/input/misc/twl4030-vibra.c12
-rw-r--r--drivers/input/misc/twl6040-vibra.c423
11 files changed, 1482 insertions, 41 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 01344280e145..a1aa35a053b7 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -62,6 +62,17 @@ config INPUT_AD714X_SPI
62 To compile this driver as a module, choose M here: the 62 To compile this driver as a module, choose M here: the
63 module will be called ad714x-spi. 63 module will be called ad714x-spi.
64 64
65config INPUT_BMA150
66 tristate "BMA150/SMB380 acceleration sensor support"
67 depends on I2C
68 select INPUT_POLLDEV
69 help
70 Say Y here if you have Bosch Sensortec's BMA150 or SMB380
71 acceleration sensor hooked to an I2C bus.
72
73 To compile this driver as a module, choose M here: the
74 module will be called bma150.
75
65config INPUT_PCSPKR 76config INPUT_PCSPKR
66 tristate "PC Speaker support" 77 tristate "PC Speaker support"
67 depends on PCSPKR_PLATFORM 78 depends on PCSPKR_PLATFORM
@@ -74,6 +85,29 @@ config INPUT_PCSPKR
74 To compile this driver as a module, choose M here: the 85 To compile this driver as a module, choose M here: the
75 module will be called pcspkr. 86 module will be called pcspkr.
76 87
88config INPUT_PM8XXX_VIBRATOR
89 tristate "Qualcomm PM8XXX vibrator support"
90 depends on MFD_PM8XXX
91 select INPUT_FF_MEMLESS
92 help
93 This option enables device driver support for the vibrator
94 on Qualcomm PM8xxx chip. This driver supports ff-memless interface
95 from input framework.
96
97 To compile this driver as module, choose M here: the
98 module will be called pm8xxx-vibrator.
99
100config INPUT_PMIC8XXX_PWRKEY
101 tristate "PMIC8XXX power key support"
102 depends on MFD_PM8XXX
103 help
104 Say Y here if you want support for the PMIC8XXX power key.
105
106 If unsure, say N.
107
108 To compile this driver as a module, choose M here: the
109 module will be called pmic8xxx-pwrkey.
110
77config INPUT_SPARCSPKR 111config INPUT_SPARCSPKR
78 tristate "SPARC Speaker support" 112 tristate "SPARC Speaker support"
79 depends on PCI && SPARC64 113 depends on PCI && SPARC64
@@ -305,7 +339,7 @@ config INPUT_TWL4030_PWRBUTTON
305config INPUT_TWL4030_VIBRA 339config INPUT_TWL4030_VIBRA
306 tristate "Support for TWL4030 Vibrator" 340 tristate "Support for TWL4030 Vibrator"
307 depends on TWL4030_CORE 341 depends on TWL4030_CORE
308 select TWL4030_CODEC 342 select MFD_TWL4030_AUDIO
309 select INPUT_FF_MEMLESS 343 select INPUT_FF_MEMLESS
310 help 344 help
311 This option enables support for TWL4030 Vibrator Driver. 345 This option enables support for TWL4030 Vibrator Driver.
@@ -313,6 +347,17 @@ config INPUT_TWL4030_VIBRA
313 To compile this driver as a module, choose M here. The module will 347 To compile this driver as a module, choose M here. The module will
314 be called twl4030_vibra. 348 be called twl4030_vibra.
315 349
350config INPUT_TWL6040_VIBRA
351 tristate "Support for TWL6040 Vibrator"
352 depends on TWL4030_CORE
353 select TWL6040_CORE
354 select INPUT_FF_MEMLESS
355 help
356 This option enables support for TWL6040 Vibrator Driver.
357
358 To compile this driver as a module, choose M here. The module will
359 be called twl6040_vibra.
360
316config INPUT_UINPUT 361config INPUT_UINPUT
317 tristate "User level driver support" 362 tristate "User level driver support"
318 help 363 help
@@ -368,17 +413,6 @@ config INPUT_PWM_BEEPER
368 To compile this driver as a module, choose M here: the module will be 413 To compile this driver as a module, choose M here: the module will be
369 called pwm-beeper. 414 called pwm-beeper.
370 415
371config INPUT_PMIC8XXX_PWRKEY
372 tristate "PMIC8XXX power key support"
373 depends on MFD_PM8XXX
374 help
375 Say Y here if you want support for the PMIC8XXX power key.
376
377 If unsure, say N.
378
379 To compile this driver as a module, choose M here: the
380 module will be called pmic8xxx-pwrkey.
381
382config INPUT_GPIO_ROTARY_ENCODER 416config INPUT_GPIO_ROTARY_ENCODER
383 tristate "Rotary encoders connected to GPIO pins" 417 tristate "Rotary encoders connected to GPIO pins"
384 depends on GPIOLIB && GENERIC_GPIO 418 depends on GPIOLIB && GENERIC_GPIO
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index be39d813354d..53a8d0faad52 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o
17obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o 17obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o
18obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o 18obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o
19obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o 19obj-$(CONFIG_INPUT_BFIN_ROTARY) += bfin_rotary.o
20obj-$(CONFIG_INPUT_BMA150) += bma150.o
20obj-$(CONFIG_INPUT_CM109) += cm109.o 21obj-$(CONFIG_INPUT_CM109) += cm109.o
21obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o 22obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o
22obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o 23obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o
@@ -34,15 +35,17 @@ obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o
34obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o 35obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
35obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o 36obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o
36obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o 37obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o
38obj-$(CONFIG_INPUT_PM8XXX_VIBRATOR) += pm8xxx-vibrator.o
39obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += pmic8xxx-pwrkey.o
37obj-$(CONFIG_INPUT_POWERMATE) += powermate.o 40obj-$(CONFIG_INPUT_POWERMATE) += powermate.o
38obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o 41obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o
39obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += pmic8xxx-pwrkey.o
40obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o 42obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o
41obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o 43obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o
42obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o 44obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
43obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o 45obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o
44obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o 46obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o
45obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o 47obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o
48obj-$(CONFIG_INPUT_TWL6040_VIBRA) += twl6040-vibra.o
46obj-$(CONFIG_INPUT_UINPUT) += uinput.o 49obj-$(CONFIG_INPUT_UINPUT) += uinput.o
47obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o 50obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
48obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o 51obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c
index 025417d74ca2..56810fb4eadd 100644
--- a/drivers/input/misc/ad714x-i2c.c
+++ b/drivers/input/misc/ad714x-i2c.c
@@ -116,13 +116,13 @@ static struct i2c_driver ad714x_i2c_driver = {
116 .id_table = ad714x_id, 116 .id_table = ad714x_id,
117}; 117};
118 118
119static __init int ad714x_i2c_init(void) 119static int __init ad714x_i2c_init(void)
120{ 120{
121 return i2c_add_driver(&ad714x_i2c_driver); 121 return i2c_add_driver(&ad714x_i2c_driver);
122} 122}
123module_init(ad714x_i2c_init); 123module_init(ad714x_i2c_init);
124 124
125static __exit void ad714x_i2c_exit(void) 125static void __exit ad714x_i2c_exit(void)
126{ 126{
127 i2c_del_driver(&ad714x_i2c_driver); 127 i2c_del_driver(&ad714x_i2c_driver);
128} 128}
diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
new file mode 100644
index 000000000000..8f55b54352b6
--- /dev/null
+++ b/drivers/input/misc/bma150.c
@@ -0,0 +1,691 @@
1/*
2 * Copyright (c) 2011 Bosch Sensortec GmbH
3 * Copyright (c) 2011 Unixphere
4 *
5 * This driver adds support for Bosch Sensortec's digital acceleration
6 * sensors BMA150 and SMB380.
7 * The SMB380 is fully compatible with BMA150 and only differs in packaging.
8 *
9 * The datasheet for the BMA150 chip can be found here:
10 * http://www.bosch-sensortec.com/content/language1/downloads/BST-BMA150-DS000-07.pdf
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/i2c.h>
29#include <linux/input.h>
30#include <linux/input-polldev.h>
31#include <linux/interrupt.h>
32#include <linux/delay.h>
33#include <linux/slab.h>
34#include <linux/pm.h>
35#include <linux/pm_runtime.h>
36#include <linux/bma150.h>
37
38#define ABSMAX_ACC_VAL 0x01FF
39#define ABSMIN_ACC_VAL -(ABSMAX_ACC_VAL)
40
41/* Each axis is represented by a 2-byte data word */
42#define BMA150_XYZ_DATA_SIZE 6
43
44/* Input poll interval in milliseconds */
45#define BMA150_POLL_INTERVAL 10
46#define BMA150_POLL_MAX 200
47#define BMA150_POLL_MIN 0
48
49#define BMA150_BW_25HZ 0
50#define BMA150_BW_50HZ 1
51#define BMA150_BW_100HZ 2
52#define BMA150_BW_190HZ 3
53#define BMA150_BW_375HZ 4
54#define BMA150_BW_750HZ 5
55#define BMA150_BW_1500HZ 6
56
57#define BMA150_RANGE_2G 0
58#define BMA150_RANGE_4G 1
59#define BMA150_RANGE_8G 2
60
61#define BMA150_MODE_NORMAL 0
62#define BMA150_MODE_SLEEP 2
63#define BMA150_MODE_WAKE_UP 3
64
65/* Data register addresses */
66#define BMA150_DATA_0_REG 0x00
67#define BMA150_DATA_1_REG 0x01
68#define BMA150_DATA_2_REG 0x02
69
70/* Control register addresses */
71#define BMA150_CTRL_0_REG 0x0A
72#define BMA150_CTRL_1_REG 0x0B
73#define BMA150_CTRL_2_REG 0x14
74#define BMA150_CTRL_3_REG 0x15
75
76/* Configuration/Setting register addresses */
77#define BMA150_CFG_0_REG 0x0C
78#define BMA150_CFG_1_REG 0x0D
79#define BMA150_CFG_2_REG 0x0E
80#define BMA150_CFG_3_REG 0x0F
81#define BMA150_CFG_4_REG 0x10
82#define BMA150_CFG_5_REG 0x11
83
84#define BMA150_CHIP_ID 2
85#define BMA150_CHIP_ID_REG BMA150_DATA_0_REG
86
87#define BMA150_ACC_X_LSB_REG BMA150_DATA_2_REG
88
89#define BMA150_SLEEP_POS 0
90#define BMA150_SLEEP_MSK 0x01
91#define BMA150_SLEEP_REG BMA150_CTRL_0_REG
92
93#define BMA150_BANDWIDTH_POS 0
94#define BMA150_BANDWIDTH_MSK 0x07
95#define BMA150_BANDWIDTH_REG BMA150_CTRL_2_REG
96
97#define BMA150_RANGE_POS 3
98#define BMA150_RANGE_MSK 0x18
99#define BMA150_RANGE_REG BMA150_CTRL_2_REG
100
101#define BMA150_WAKE_UP_POS 0
102#define BMA150_WAKE_UP_MSK 0x01
103#define BMA150_WAKE_UP_REG BMA150_CTRL_3_REG
104
105#define BMA150_SW_RES_POS 1
106#define BMA150_SW_RES_MSK 0x02
107#define BMA150_SW_RES_REG BMA150_CTRL_0_REG
108
109/* Any-motion interrupt register fields */
110#define BMA150_ANY_MOTION_EN_POS 6
111#define BMA150_ANY_MOTION_EN_MSK 0x40
112#define BMA150_ANY_MOTION_EN_REG BMA150_CTRL_1_REG
113
114#define BMA150_ANY_MOTION_DUR_POS 6
115#define BMA150_ANY_MOTION_DUR_MSK 0xC0
116#define BMA150_ANY_MOTION_DUR_REG BMA150_CFG_5_REG
117
118#define BMA150_ANY_MOTION_THRES_REG BMA150_CFG_4_REG
119
120/* Advanced interrupt register fields */
121#define BMA150_ADV_INT_EN_POS 6
122#define BMA150_ADV_INT_EN_MSK 0x40
123#define BMA150_ADV_INT_EN_REG BMA150_CTRL_3_REG
124
125/* High-G interrupt register fields */
126#define BMA150_HIGH_G_EN_POS 1
127#define BMA150_HIGH_G_EN_MSK 0x02
128#define BMA150_HIGH_G_EN_REG BMA150_CTRL_1_REG
129
130#define BMA150_HIGH_G_HYST_POS 3
131#define BMA150_HIGH_G_HYST_MSK 0x38
132#define BMA150_HIGH_G_HYST_REG BMA150_CFG_5_REG
133
134#define BMA150_HIGH_G_DUR_REG BMA150_CFG_3_REG
135#define BMA150_HIGH_G_THRES_REG BMA150_CFG_2_REG
136
137/* Low-G interrupt register fields */
138#define BMA150_LOW_G_EN_POS 0
139#define BMA150_LOW_G_EN_MSK 0x01
140#define BMA150_LOW_G_EN_REG BMA150_CTRL_1_REG
141
142#define BMA150_LOW_G_HYST_POS 0
143#define BMA150_LOW_G_HYST_MSK 0x07
144#define BMA150_LOW_G_HYST_REG BMA150_CFG_5_REG
145
146#define BMA150_LOW_G_DUR_REG BMA150_CFG_1_REG
147#define BMA150_LOW_G_THRES_REG BMA150_CFG_0_REG
148
149struct bma150_data {
150 struct i2c_client *client;
151 struct input_polled_dev *input_polled;
152 struct input_dev *input;
153 u8 mode;
154};
155
156/*
157 * The settings for the given range, bandwidth and interrupt features
158 * are stated and verified by Bosch Sensortec where they are configured
159 * to provide a generic sensitivity performance.
160 */
161static struct bma150_cfg default_cfg __devinitdata = {
162 .any_motion_int = 1,
163 .hg_int = 1,
164 .lg_int = 1,
165 .any_motion_dur = 0,
166 .any_motion_thres = 0,
167 .hg_hyst = 0,
168 .hg_dur = 150,
169 .hg_thres = 160,
170 .lg_hyst = 0,
171 .lg_dur = 150,
172 .lg_thres = 20,
173 .range = BMA150_RANGE_2G,
174 .bandwidth = BMA150_BW_50HZ
175};
176
177static int bma150_write_byte(struct i2c_client *client, u8 reg, u8 val)
178{
179 s32 ret;
180
181 /* As per specification, disable irq in between register writes */
182 if (client->irq)
183 disable_irq_nosync(client->irq);
184
185 ret = i2c_smbus_write_byte_data(client, reg, val);
186
187 if (client->irq)
188 enable_irq(client->irq);
189
190 return ret;
191}
192
193static int bma150_set_reg_bits(struct i2c_client *client,
194 int val, int shift, u8 mask, u8 reg)
195{
196 int data;
197
198 data = i2c_smbus_read_byte_data(client, reg);
199 if (data < 0)
200 return data;
201
202 data = (data & ~mask) | ((val << shift) & mask);
203 return bma150_write_byte(client, reg, data);
204}
205
206static int bma150_set_mode(struct bma150_data *bma150, u8 mode)
207{
208 int error;
209
210 error = bma150_set_reg_bits(bma150->client, mode, BMA150_WAKE_UP_POS,
211 BMA150_WAKE_UP_MSK, BMA150_WAKE_UP_REG);
212 if (error)
213 return error;
214
215 error = bma150_set_reg_bits(bma150->client, mode, BMA150_SLEEP_POS,
216 BMA150_SLEEP_MSK, BMA150_SLEEP_REG);
217 if (error)
218 return error;
219
220 if (mode == BMA150_MODE_NORMAL)
221 msleep(2);
222
223 bma150->mode = mode;
224 return 0;
225}
226
227static int __devinit bma150_soft_reset(struct bma150_data *bma150)
228{
229 int error;
230
231 error = bma150_set_reg_bits(bma150->client, 1, BMA150_SW_RES_POS,
232 BMA150_SW_RES_MSK, BMA150_SW_RES_REG);
233 if (error)
234 return error;
235
236 msleep(2);
237 return 0;
238}
239
240static int __devinit bma150_set_range(struct bma150_data *bma150, u8 range)
241{
242 return bma150_set_reg_bits(bma150->client, range, BMA150_RANGE_POS,
243 BMA150_RANGE_MSK, BMA150_RANGE_REG);
244}
245
246static int __devinit bma150_set_bandwidth(struct bma150_data *bma150, u8 bw)
247{
248 return bma150_set_reg_bits(bma150->client, bw, BMA150_BANDWIDTH_POS,
249 BMA150_BANDWIDTH_MSK, BMA150_BANDWIDTH_REG);
250}
251
252static int __devinit bma150_set_low_g_interrupt(struct bma150_data *bma150,
253 u8 enable, u8 hyst, u8 dur, u8 thres)
254{
255 int error;
256
257 error = bma150_set_reg_bits(bma150->client, hyst,
258 BMA150_LOW_G_HYST_POS, BMA150_LOW_G_HYST_MSK,
259 BMA150_LOW_G_HYST_REG);
260 if (error)
261 return error;
262
263 error = bma150_write_byte(bma150->client, BMA150_LOW_G_DUR_REG, dur);
264 if (error)
265 return error;
266
267 error = bma150_write_byte(bma150->client, BMA150_LOW_G_THRES_REG, thres);
268 if (error)
269 return error;
270
271 return bma150_set_reg_bits(bma150->client, !!enable,
272 BMA150_LOW_G_EN_POS, BMA150_LOW_G_EN_MSK,
273 BMA150_LOW_G_EN_REG);
274}
275
276static int __devinit bma150_set_high_g_interrupt(struct bma150_data *bma150,
277 u8 enable, u8 hyst, u8 dur, u8 thres)
278{
279 int error;
280
281 error = bma150_set_reg_bits(bma150->client, hyst,
282 BMA150_HIGH_G_HYST_POS, BMA150_HIGH_G_HYST_MSK,
283 BMA150_HIGH_G_HYST_REG);
284 if (error)
285 return error;
286
287 error = bma150_write_byte(bma150->client,
288 BMA150_HIGH_G_DUR_REG, dur);
289 if (error)
290 return error;
291
292 error = bma150_write_byte(bma150->client,
293 BMA150_HIGH_G_THRES_REG, thres);
294 if (error)
295 return error;
296
297 return bma150_set_reg_bits(bma150->client, !!enable,
298 BMA150_HIGH_G_EN_POS, BMA150_HIGH_G_EN_MSK,
299 BMA150_HIGH_G_EN_REG);
300}
301
302
303static int __devinit bma150_set_any_motion_interrupt(struct bma150_data *bma150,
304 u8 enable, u8 dur, u8 thres)
305{
306 int error;
307
308 error = bma150_set_reg_bits(bma150->client, dur,
309 BMA150_ANY_MOTION_DUR_POS,
310 BMA150_ANY_MOTION_DUR_MSK,
311 BMA150_ANY_MOTION_DUR_REG);
312 if (error)
313 return error;
314
315 error = bma150_write_byte(bma150->client,
316 BMA150_ANY_MOTION_THRES_REG, thres);
317 if (error)
318 return error;
319
320 error = bma150_set_reg_bits(bma150->client, !!enable,
321 BMA150_ADV_INT_EN_POS, BMA150_ADV_INT_EN_MSK,
322 BMA150_ADV_INT_EN_REG);
323 if (error)
324 return error;
325
326 return bma150_set_reg_bits(bma150->client, !!enable,
327 BMA150_ANY_MOTION_EN_POS,
328 BMA150_ANY_MOTION_EN_MSK,
329 BMA150_ANY_MOTION_EN_REG);
330}
331
332static void bma150_report_xyz(struct bma150_data *bma150)
333{
334 u8 data[BMA150_XYZ_DATA_SIZE];
335 s16 x, y, z;
336 s32 ret;
337
338 ret = i2c_smbus_read_i2c_block_data(bma150->client,
339 BMA150_ACC_X_LSB_REG, BMA150_XYZ_DATA_SIZE, data);
340 if (ret != BMA150_XYZ_DATA_SIZE)
341 return;
342
343 x = ((0xc0 & data[0]) >> 6) | (data[1] << 2);
344 y = ((0xc0 & data[2]) >> 6) | (data[3] << 2);
345 z = ((0xc0 & data[4]) >> 6) | (data[5] << 2);
346
347 /* sign extension */
348 x = (s16) (x << 6) >> 6;
349 y = (s16) (y << 6) >> 6;
350 z = (s16) (z << 6) >> 6;
351
352 input_report_abs(bma150->input, ABS_X, x);
353 input_report_abs(bma150->input, ABS_Y, y);
354 input_report_abs(bma150->input, ABS_Z, z);
355 input_sync(bma150->input);
356}
357
358static irqreturn_t bma150_irq_thread(int irq, void *dev)
359{
360 bma150_report_xyz(dev);
361
362 return IRQ_HANDLED;
363}
364
365static void bma150_poll(struct input_polled_dev *dev)
366{
367 bma150_report_xyz(dev->private);
368}
369
370static int bma150_open(struct bma150_data *bma150)
371{
372 int error;
373
374 error = pm_runtime_get_sync(&bma150->client->dev);
375 if (error && error != -ENOSYS)
376 return error;
377
378 /*
379 * See if runtime PM woke up the device. If runtime PM
380 * is disabled we need to do it ourselves.
381 */
382 if (bma150->mode != BMA150_MODE_NORMAL) {
383 error = bma150_set_mode(bma150, BMA150_MODE_NORMAL);
384 if (error)
385 return error;
386 }
387
388 return 0;
389}
390
391static void bma150_close(struct bma150_data *bma150)
392{
393 pm_runtime_put_sync(&bma150->client->dev);
394
395 if (bma150->mode != BMA150_MODE_SLEEP)
396 bma150_set_mode(bma150, BMA150_MODE_SLEEP);
397}
398
399static int bma150_irq_open(struct input_dev *input)
400{
401 struct bma150_data *bma150 = input_get_drvdata(input);
402
403 return bma150_open(bma150);
404}
405
406static void bma150_irq_close(struct input_dev *input)
407{
408 struct bma150_data *bma150 = input_get_drvdata(input);
409
410 bma150_close(bma150);
411}
412
413static void bma150_poll_open(struct input_polled_dev *ipoll_dev)
414{
415 struct bma150_data *bma150 = ipoll_dev->private;
416
417 bma150_open(bma150);
418}
419
420static void bma150_poll_close(struct input_polled_dev *ipoll_dev)
421{
422 struct bma150_data *bma150 = ipoll_dev->private;
423
424 bma150_close(bma150);
425}
426
427static int __devinit bma150_initialize(struct bma150_data *bma150,
428 const struct bma150_cfg *cfg)
429{
430 int error;
431
432 error = bma150_soft_reset(bma150);
433 if (error)
434 return error;
435
436 error = bma150_set_bandwidth(bma150, cfg->bandwidth);
437 if (error)
438 return error;
439
440 error = bma150_set_range(bma150, cfg->range);
441 if (error)
442 return error;
443
444 if (bma150->client->irq) {
445 error = bma150_set_any_motion_interrupt(bma150,
446 cfg->any_motion_int,
447 cfg->any_motion_dur,
448 cfg->any_motion_thres);
449 if (error)
450 return error;
451
452 error = bma150_set_high_g_interrupt(bma150,
453 cfg->hg_int, cfg->hg_hyst,
454 cfg->hg_dur, cfg->hg_thres);
455 if (error)
456 return error;
457
458 error = bma150_set_low_g_interrupt(bma150,
459 cfg->lg_int, cfg->lg_hyst,
460 cfg->lg_dur, cfg->lg_thres);
461 if (error)
462 return error;
463 }
464
465 return bma150_set_mode(bma150, BMA150_MODE_SLEEP);
466}
467
468static void __devinit bma150_init_input_device(struct bma150_data *bma150,
469 struct input_dev *idev)
470{
471 idev->name = BMA150_DRIVER;
472 idev->phys = BMA150_DRIVER "/input0";
473 idev->id.bustype = BUS_I2C;
474 idev->dev.parent = &bma150->client->dev;
475
476 idev->evbit[0] = BIT_MASK(EV_ABS);
477 input_set_abs_params(idev, ABS_X, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
478 input_set_abs_params(idev, ABS_Y, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
479 input_set_abs_params(idev, ABS_Z, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
480}
481
482static int __devinit bma150_register_input_device(struct bma150_data *bma150)
483{
484 struct input_dev *idev;
485 int error;
486
487 idev = input_allocate_device();
488 if (!idev)
489 return -ENOMEM;
490
491 bma150_init_input_device(bma150, idev);
492
493 idev->open = bma150_irq_open;
494 idev->close = bma150_irq_close;
495 input_set_drvdata(idev, bma150);
496
497 error = input_register_device(idev);
498 if (error) {
499 input_free_device(idev);
500 return error;
501 }
502
503 bma150->input = idev;
504 return 0;
505}
506
507static int __devinit bma150_register_polled_device(struct bma150_data *bma150)
508{
509 struct input_polled_dev *ipoll_dev;
510 int error;
511
512 ipoll_dev = input_allocate_polled_device();
513 if (!ipoll_dev)
514 return -ENOMEM;
515
516 ipoll_dev->private = bma150;
517 ipoll_dev->open = bma150_poll_open;
518 ipoll_dev->close = bma150_poll_close;
519 ipoll_dev->poll = bma150_poll;
520 ipoll_dev->poll_interval = BMA150_POLL_INTERVAL;
521 ipoll_dev->poll_interval_min = BMA150_POLL_MIN;
522 ipoll_dev->poll_interval_max = BMA150_POLL_MAX;
523
524 bma150_init_input_device(bma150, ipoll_dev->input);
525
526 error = input_register_polled_device(ipoll_dev);
527 if (error) {
528 input_free_polled_device(ipoll_dev);
529 return error;
530 }
531
532 bma150->input_polled = ipoll_dev;
533 bma150->input = ipoll_dev->input;
534
535 return 0;
536}
537
538static int __devinit bma150_probe(struct i2c_client *client,
539 const struct i2c_device_id *id)
540{
541 const struct bma150_platform_data *pdata = client->dev.platform_data;
542 const struct bma150_cfg *cfg;
543 struct bma150_data *bma150;
544 int chip_id;
545 int error;
546
547 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
548 dev_err(&client->dev, "i2c_check_functionality error\n");
549 return -EIO;
550 }
551
552 chip_id = i2c_smbus_read_byte_data(client, BMA150_CHIP_ID_REG);
553 if (chip_id != BMA150_CHIP_ID) {
554 dev_err(&client->dev, "BMA150 chip id error: %d\n", chip_id);
555 return -EINVAL;
556 }
557
558 bma150 = kzalloc(sizeof(struct bma150_data), GFP_KERNEL);
559 if (!bma150)
560 return -ENOMEM;
561
562 bma150->client = client;
563
564 if (pdata) {
565 if (pdata->irq_gpio_cfg) {
566 error = pdata->irq_gpio_cfg();
567 if (error) {
568 dev_err(&client->dev,
569 "IRQ GPIO conf. error %d, error %d\n",
570 client->irq, error);
571 goto err_free_mem;
572 }
573 }
574 cfg = &pdata->cfg;
575 } else {
576 cfg = &default_cfg;
577 }
578
579 error = bma150_initialize(bma150, cfg);
580 if (error)
581 goto err_free_mem;
582
583 if (client->irq > 0) {
584 error = bma150_register_input_device(bma150);
585 if (error)
586 goto err_free_mem;
587
588 error = request_threaded_irq(client->irq,
589 NULL, bma150_irq_thread,
590 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
591 BMA150_DRIVER, bma150);
592 if (error) {
593 dev_err(&client->dev,
594 "irq request failed %d, error %d\n",
595 client->irq, error);
596 input_unregister_device(bma150->input);
597 goto err_free_mem;
598 }
599 } else {
600 error = bma150_register_polled_device(bma150);
601 if (error)
602 goto err_free_mem;
603 }
604
605 i2c_set_clientdata(client, bma150);
606
607 pm_runtime_enable(&client->dev);
608
609 return 0;
610
611err_free_mem:
612 kfree(bma150);
613 return error;
614}
615
616static int __devexit bma150_remove(struct i2c_client *client)
617{
618 struct bma150_data *bma150 = i2c_get_clientdata(client);
619
620 pm_runtime_disable(&client->dev);
621
622 if (client->irq > 0) {
623 free_irq(client->irq, bma150);
624 input_unregister_device(bma150->input);
625 } else {
626 input_unregister_polled_device(bma150->input_polled);
627 input_free_polled_device(bma150->input_polled);
628 }
629
630 kfree(bma150);
631
632 return 0;
633}
634
635#ifdef CONFIG_PM
636static int bma150_suspend(struct device *dev)
637{
638 struct i2c_client *client = to_i2c_client(dev);
639 struct bma150_data *bma150 = i2c_get_clientdata(client);
640
641 return bma150_set_mode(bma150, BMA150_MODE_SLEEP);
642}
643
644static int bma150_resume(struct device *dev)
645{
646 struct i2c_client *client = to_i2c_client(dev);
647 struct bma150_data *bma150 = i2c_get_clientdata(client);
648
649 return bma150_set_mode(bma150, BMA150_MODE_NORMAL);
650}
651#endif
652
653static UNIVERSAL_DEV_PM_OPS(bma150_pm, bma150_suspend, bma150_resume, NULL);
654
655static const struct i2c_device_id bma150_id[] = {
656 { "bma150", 0 },
657 { "smb380", 0 },
658 { "bma023", 0 },
659 { }
660};
661
662MODULE_DEVICE_TABLE(i2c, bma150_id);
663
664static struct i2c_driver bma150_driver = {
665 .driver = {
666 .owner = THIS_MODULE,
667 .name = BMA150_DRIVER,
668 .pm = &bma150_pm,
669 },
670 .class = I2C_CLASS_HWMON,
671 .id_table = bma150_id,
672 .probe = bma150_probe,
673 .remove = __devexit_p(bma150_remove),
674};
675
676static int __init BMA150_init(void)
677{
678 return i2c_add_driver(&bma150_driver);
679}
680
681static void __exit BMA150_exit(void)
682{
683 i2c_del_driver(&bma150_driver);
684}
685
686MODULE_AUTHOR("Albert Zhang <xu.zhang@bosch-sensortec.com>");
687MODULE_DESCRIPTION("BMA150 driver");
688MODULE_LICENSE("GPL");
689
690module_init(BMA150_init);
691module_exit(BMA150_exit);
diff --git a/drivers/input/misc/ixp4xx-beeper.c b/drivers/input/misc/ixp4xx-beeper.c
index 1f38302a5951..302ab46ce752 100644
--- a/drivers/input/misc/ixp4xx-beeper.c
+++ b/drivers/input/misc/ixp4xx-beeper.c
@@ -111,7 +111,7 @@ static int __devinit ixp4xx_spkr_probe(struct platform_device *dev)
111 input_dev->event = ixp4xx_spkr_event; 111 input_dev->event = ixp4xx_spkr_event;
112 112
113 err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt, 113 err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt,
114 IRQF_DISABLED | IRQF_NO_SUSPEND, "ixp4xx-beeper", 114 IRQF_NO_SUSPEND, "ixp4xx-beeper",
115 (void *) dev->id); 115 (void *) dev->id);
116 if (err) 116 if (err)
117 goto err_free_device; 117 goto err_free_device;
diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 0794778295fc..4d60080bb5d5 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -88,13 +88,13 @@ static int mma8450_write(struct mma8450 *m, unsigned off, u8 v)
88 return 0; 88 return 0;
89} 89}
90 90
91static int mma8450_read_xyz(struct mma8450 *m, int *x, int *y, int *z) 91static int mma8450_read_block(struct mma8450 *m, unsigned off,
92 u8 *buf, size_t size)
92{ 93{
93 struct i2c_client *c = m->client; 94 struct i2c_client *c = m->client;
94 u8 buff[6];
95 int err; 95 int err;
96 96
97 err = i2c_smbus_read_i2c_block_data(c, MMA8450_OUT_X_LSB, 6, buff); 97 err = i2c_smbus_read_i2c_block_data(c, off, size, buf);
98 if (err < 0) { 98 if (err < 0) {
99 dev_err(&c->dev, 99 dev_err(&c->dev,
100 "failed to read block data at 0x%02x, error %d\n", 100 "failed to read block data at 0x%02x, error %d\n",
@@ -102,10 +102,6 @@ static int mma8450_read_xyz(struct mma8450 *m, int *x, int *y, int *z)
102 return err; 102 return err;
103 } 103 }
104 104
105 *x = ((buff[1] << 4) & 0xff0) | (buff[0] & 0xf);
106 *y = ((buff[3] << 4) & 0xff0) | (buff[2] & 0xf);
107 *z = ((buff[5] << 4) & 0xff0) | (buff[4] & 0xf);
108
109 return 0; 105 return 0;
110} 106}
111 107
@@ -114,7 +110,7 @@ static void mma8450_poll(struct input_polled_dev *dev)
114 struct mma8450 *m = dev->private; 110 struct mma8450 *m = dev->private;
115 int x, y, z; 111 int x, y, z;
116 int ret; 112 int ret;
117 int err; 113 u8 buf[6];
118 114
119 ret = mma8450_read(m, MMA8450_STATUS); 115 ret = mma8450_read(m, MMA8450_STATUS);
120 if (ret < 0) 116 if (ret < 0)
@@ -123,10 +119,14 @@ static void mma8450_poll(struct input_polled_dev *dev)
123 if (!(ret & MMA8450_STATUS_ZXYDR)) 119 if (!(ret & MMA8450_STATUS_ZXYDR))
124 return; 120 return;
125 121
126 err = mma8450_read_xyz(m, &x, &y, &z); 122 ret = mma8450_read_block(m, MMA8450_OUT_X_LSB, buf, sizeof(buf));
127 if (err) 123 if (ret < 0)
128 return; 124 return;
129 125
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);
129
130 input_report_abs(dev->input, ABS_X, x); 130 input_report_abs(dev->input, ABS_X, x);
131 input_report_abs(dev->input, ABS_Y, y); 131 input_report_abs(dev->input, ABS_Y, y);
132 input_report_abs(dev->input, ABS_Z, z); 132 input_report_abs(dev->input, ABS_Z, z);
diff --git a/drivers/input/misc/pcspkr.c b/drivers/input/misc/pcspkr.c
index f080dd31499b..34f4d2e0f50f 100644
--- a/drivers/input/misc/pcspkr.c
+++ b/drivers/input/misc/pcspkr.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/i8253.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/input.h> 19#include <linux/input.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
@@ -25,14 +26,6 @@ MODULE_DESCRIPTION("PC Speaker beeper driver");
25MODULE_LICENSE("GPL"); 26MODULE_LICENSE("GPL");
26MODULE_ALIAS("platform:pcspkr"); 27MODULE_ALIAS("platform:pcspkr");
27 28
28#if defined(CONFIG_MIPS) || defined(CONFIG_X86)
29/* Use the global PIT lock ! */
30#include <asm/i8253.h>
31#else
32#include <asm/8253pit.h>
33static DEFINE_RAW_SPINLOCK(i8253_lock);
34#endif
35
36static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 29static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
37{ 30{
38 unsigned int count = 0; 31 unsigned int count = 0;
diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c
new file mode 100644
index 000000000000..43192930824b
--- /dev/null
+++ b/drivers/input/misc/pm8xxx-vibrator.c
@@ -0,0 +1,296 @@
1/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/platform_device.h>
18#include <linux/input.h>
19#include <linux/slab.h>
20#include <linux/mfd/pm8xxx/core.h>
21
22#define VIB_DRV 0x4A
23
24#define VIB_DRV_SEL_MASK 0xf8
25#define VIB_DRV_SEL_SHIFT 0x03
26#define VIB_DRV_EN_MANUAL_MASK 0xfc
27
28#define VIB_MAX_LEVEL_mV (3100)
29#define VIB_MIN_LEVEL_mV (1200)
30#define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV)
31
32#define MAX_FF_SPEED 0xff
33
34/**
35 * struct pm8xxx_vib - structure to hold vibrator data
36 * @vib_input_dev: input device supporting force feedback
37 * @work: work structure to set the vibration parameters
38 * @dev: device supporting force feedback
39 * @speed: speed of vibration set from userland
40 * @active: state of vibrator
41 * @level: level of vibration to set in the chip
42 * @reg_vib_drv: VIB_DRV register value
43 */
44struct pm8xxx_vib {
45 struct input_dev *vib_input_dev;
46 struct work_struct work;
47 struct device *dev;
48 int speed;
49 int level;
50 bool active;
51 u8 reg_vib_drv;
52};
53
54/**
55 * pm8xxx_vib_read_u8 - helper to read a byte from pmic chip
56 * @vib: pointer to vibrator structure
57 * @data: placeholder for data to be read
58 * @reg: register address
59 */
60static int pm8xxx_vib_read_u8(struct pm8xxx_vib *vib,
61 u8 *data, u16 reg)
62{
63 int rc;
64
65 rc = pm8xxx_readb(vib->dev->parent, reg, data);
66 if (rc < 0)
67 dev_warn(vib->dev, "Error reading pm8xxx reg 0x%x(0x%x)\n",
68 reg, rc);
69 return rc;
70}
71
72/**
73 * pm8xxx_vib_write_u8 - helper to write a byte to pmic chip
74 * @vib: pointer to vibrator structure
75 * @data: data to write
76 * @reg: register address
77 */
78static int pm8xxx_vib_write_u8(struct pm8xxx_vib *vib,
79 u8 data, u16 reg)
80{
81 int rc;
82
83 rc = pm8xxx_writeb(vib->dev->parent, reg, data);
84 if (rc < 0)
85 dev_warn(vib->dev, "Error writing pm8xxx reg 0x%x(0x%x)\n",
86 reg, rc);
87 return rc;
88}
89
90/**
91 * pm8xxx_vib_set - handler to start/stop vibration
92 * @vib: pointer to vibrator structure
93 * @on: state to set
94 */
95static int pm8xxx_vib_set(struct pm8xxx_vib *vib, bool on)
96{
97 int rc;
98 u8 val = vib->reg_vib_drv;
99
100 if (on)
101 val |= ((vib->level << VIB_DRV_SEL_SHIFT) & VIB_DRV_SEL_MASK);
102 else
103 val &= ~VIB_DRV_SEL_MASK;
104
105 rc = pm8xxx_vib_write_u8(vib, val, VIB_DRV);
106 if (rc < 0)
107 return rc;
108
109 vib->reg_vib_drv = val;
110 return 0;
111}
112
113/**
114 * pm8xxx_work_handler - worker to set vibration level
115 * @work: pointer to work_struct
116 */
117static void pm8xxx_work_handler(struct work_struct *work)
118{
119 struct pm8xxx_vib *vib = container_of(work, struct pm8xxx_vib, work);
120 int rc;
121 u8 val;
122
123 rc = pm8xxx_vib_read_u8(vib, &val, VIB_DRV);
124 if (rc < 0)
125 return;
126
127 /*
128 * pmic vibrator supports voltage ranges from 1.2 to 3.1V, so
129 * scale the level to fit into these ranges.
130 */
131 if (vib->speed) {
132 vib->active = true;
133 vib->level = ((VIB_MAX_LEVELS * vib->speed) / MAX_FF_SPEED) +
134 VIB_MIN_LEVEL_mV;
135 vib->level /= 100;
136 } else {
137 vib->active = false;
138 vib->level = VIB_MIN_LEVEL_mV / 100;
139 }
140
141 pm8xxx_vib_set(vib, vib->active);
142}
143
144/**
145 * pm8xxx_vib_close - callback of input close callback
146 * @dev: input device pointer
147 *
148 * Turns off the vibrator.
149 */
150static void pm8xxx_vib_close(struct input_dev *dev)
151{
152 struct pm8xxx_vib *vib = input_get_drvdata(dev);
153
154 cancel_work_sync(&vib->work);
155 if (vib->active)
156 pm8xxx_vib_set(vib, false);
157}
158
159/**
160 * pm8xxx_vib_play_effect - function to handle vib effects.
161 * @dev: input device pointer
162 * @data: data of effect
163 * @effect: effect to play
164 *
165 * Currently this driver supports only rumble effects.
166 */
167static int pm8xxx_vib_play_effect(struct input_dev *dev, void *data,
168 struct ff_effect *effect)
169{
170 struct pm8xxx_vib *vib = input_get_drvdata(dev);
171
172 vib->speed = effect->u.rumble.strong_magnitude >> 8;
173 if (!vib->speed)
174 vib->speed = effect->u.rumble.weak_magnitude >> 9;
175
176 schedule_work(&vib->work);
177
178 return 0;
179}
180
181static int __devinit pm8xxx_vib_probe(struct platform_device *pdev)
182
183{
184 struct pm8xxx_vib *vib;
185 struct input_dev *input_dev;
186 int error;
187 u8 val;
188
189 vib = kzalloc(sizeof(*vib), GFP_KERNEL);
190 input_dev = input_allocate_device();
191 if (!vib || !input_dev) {
192 dev_err(&pdev->dev, "couldn't allocate memory\n");
193 error = -ENOMEM;
194 goto err_free_mem;
195 }
196
197 INIT_WORK(&vib->work, pm8xxx_work_handler);
198 vib->dev = &pdev->dev;
199 vib->vib_input_dev = input_dev;
200
201 /* operate in manual mode */
202 error = pm8xxx_vib_read_u8(vib, &val, VIB_DRV);
203 if (error < 0)
204 goto err_free_mem;
205 val &= ~VIB_DRV_EN_MANUAL_MASK;
206 error = pm8xxx_vib_write_u8(vib, val, VIB_DRV);
207 if (error < 0)
208 goto err_free_mem;
209
210 vib->reg_vib_drv = val;
211
212 input_dev->name = "pm8xxx_vib_ffmemless";
213 input_dev->id.version = 1;
214 input_dev->dev.parent = &pdev->dev;
215 input_dev->close = pm8xxx_vib_close;
216 input_set_drvdata(input_dev, vib);
217 input_set_capability(vib->vib_input_dev, EV_FF, FF_RUMBLE);
218
219 error = input_ff_create_memless(input_dev, NULL,
220 pm8xxx_vib_play_effect);
221 if (error) {
222 dev_err(&pdev->dev,
223 "couldn't register vibrator as FF device\n");
224 goto err_free_mem;
225 }
226
227 error = input_register_device(input_dev);
228 if (error) {
229 dev_err(&pdev->dev, "couldn't register input device\n");
230 goto err_destroy_memless;
231 }
232
233 platform_set_drvdata(pdev, vib);
234 return 0;
235
236err_destroy_memless:
237 input_ff_destroy(input_dev);
238err_free_mem:
239 input_free_device(input_dev);
240 kfree(vib);
241
242 return error;
243}
244
245static int __devexit pm8xxx_vib_remove(struct platform_device *pdev)
246{
247 struct pm8xxx_vib *vib = platform_get_drvdata(pdev);
248
249 input_unregister_device(vib->vib_input_dev);
250 kfree(vib);
251
252 platform_set_drvdata(pdev, NULL);
253
254 return 0;
255}
256
257#ifdef CONFIG_PM_SLEEP
258static int pm8xxx_vib_suspend(struct device *dev)
259{
260 struct pm8xxx_vib *vib = dev_get_drvdata(dev);
261
262 /* Turn off the vibrator */
263 pm8xxx_vib_set(vib, false);
264
265 return 0;
266}
267#endif
268
269static SIMPLE_DEV_PM_OPS(pm8xxx_vib_pm_ops, pm8xxx_vib_suspend, NULL);
270
271static struct platform_driver pm8xxx_vib_driver = {
272 .probe = pm8xxx_vib_probe,
273 .remove = __devexit_p(pm8xxx_vib_remove),
274 .driver = {
275 .name = "pm8xxx-vib",
276 .owner = THIS_MODULE,
277 .pm = &pm8xxx_vib_pm_ops,
278 },
279};
280
281static int __init pm8xxx_vib_init(void)
282{
283 return platform_driver_register(&pm8xxx_vib_driver);
284}
285module_init(pm8xxx_vib_init);
286
287static void __exit pm8xxx_vib_exit(void)
288{
289 platform_driver_unregister(&pm8xxx_vib_driver);
290}
291module_exit(pm8xxx_vib_exit);
292
293MODULE_ALIAS("platform:pm8xxx_vib");
294MODULE_DESCRIPTION("PMIC8xxx vibrator driver based on ff-memless framework");
295MODULE_LICENSE("GPL v2");
296MODULE_AUTHOR("Amy Maloche <amaloche@codeaurora.org>");
diff --git a/drivers/input/misc/pmic8xxx-pwrkey.c b/drivers/input/misc/pmic8xxx-pwrkey.c
index 97e07e786e41..b3cfb9c71e66 100644
--- a/drivers/input/misc/pmic8xxx-pwrkey.c
+++ b/drivers/input/misc/pmic8xxx-pwrkey.c
@@ -90,7 +90,8 @@ static int __devinit pmic8xxx_pwrkey_probe(struct platform_device *pdev)
90 unsigned int delay; 90 unsigned int delay;
91 u8 pon_cntl; 91 u8 pon_cntl;
92 struct pmic8xxx_pwrkey *pwrkey; 92 struct pmic8xxx_pwrkey *pwrkey;
93 const struct pm8xxx_pwrkey_platform_data *pdata = mfd_get_data(pdev); 93 const struct pm8xxx_pwrkey_platform_data *pdata =
94 dev_get_platdata(&pdev->dev);
94 95
95 if (!pdata) { 96 if (!pdata) {
96 dev_err(&pdev->dev, "power key platform data not supplied\n"); 97 dev_err(&pdev->dev, "power key platform data not supplied\n");
diff --git a/drivers/input/misc/twl4030-vibra.c b/drivers/input/misc/twl4030-vibra.c
index 014dd4ad0d4f..3c1a432c14dc 100644
--- a/drivers/input/misc/twl4030-vibra.c
+++ b/drivers/input/misc/twl4030-vibra.c
@@ -28,7 +28,7 @@
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/workqueue.h> 29#include <linux/workqueue.h>
30#include <linux/i2c/twl.h> 30#include <linux/i2c/twl.h>
31#include <linux/mfd/twl4030-codec.h> 31#include <linux/mfd/twl4030-audio.h>
32#include <linux/input.h> 32#include <linux/input.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34 34
@@ -67,7 +67,7 @@ static void vibra_enable(struct vibra_info *info)
67{ 67{
68 u8 reg; 68 u8 reg;
69 69
70 twl4030_codec_enable_resource(TWL4030_CODEC_RES_POWER); 70 twl4030_audio_enable_resource(TWL4030_AUDIO_RES_POWER);
71 71
72 /* turn H-Bridge on */ 72 /* turn H-Bridge on */
73 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, 73 twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE,
@@ -75,7 +75,7 @@ static void vibra_enable(struct vibra_info *info)
75 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, 75 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
76 (reg | TWL4030_VIBRA_EN), TWL4030_REG_VIBRA_CTL); 76 (reg | TWL4030_VIBRA_EN), TWL4030_REG_VIBRA_CTL);
77 77
78 twl4030_codec_enable_resource(TWL4030_CODEC_RES_APLL); 78 twl4030_audio_enable_resource(TWL4030_AUDIO_RES_APLL);
79 79
80 info->enabled = true; 80 info->enabled = true;
81} 81}
@@ -90,8 +90,8 @@ static void vibra_disable(struct vibra_info *info)
90 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, 90 twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
91 (reg & ~TWL4030_VIBRA_EN), TWL4030_REG_VIBRA_CTL); 91 (reg & ~TWL4030_VIBRA_EN), TWL4030_REG_VIBRA_CTL);
92 92
93 twl4030_codec_disable_resource(TWL4030_CODEC_RES_APLL); 93 twl4030_audio_disable_resource(TWL4030_AUDIO_RES_APLL);
94 twl4030_codec_disable_resource(TWL4030_CODEC_RES_POWER); 94 twl4030_audio_disable_resource(TWL4030_AUDIO_RES_POWER);
95 95
96 info->enabled = false; 96 info->enabled = false;
97} 97}
@@ -196,7 +196,7 @@ static SIMPLE_DEV_PM_OPS(twl4030_vibra_pm_ops,
196 196
197static int __devinit twl4030_vibra_probe(struct platform_device *pdev) 197static int __devinit twl4030_vibra_probe(struct platform_device *pdev)
198{ 198{
199 struct twl4030_codec_vibra_data *pdata = pdev->dev.platform_data; 199 struct twl4030_vibra_data *pdata = pdev->dev.platform_data;
200 struct vibra_info *info; 200 struct vibra_info *info;
201 int ret; 201 int ret;
202 202
diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c
new file mode 100644
index 000000000000..23855e12a30b
--- /dev/null
+++ b/drivers/input/misc/twl6040-vibra.c
@@ -0,0 +1,423 @@
1/*
2 * twl6040-vibra.c - TWL6040 Vibrator driver
3 *
4 * Author: Jorge Eduardo Candelaria <jorge.candelaria@ti.com>
5 * Author: Misael Lopez Cruz <misael.lopez@ti.com>
6 *
7 * Copyright: (C) 2011 Texas Instruments, Inc.
8 *
9 * Based on twl4030-vibra.c by Henrik Saari <henrik.saari@nokia.com>
10 * Felipe Balbi <felipe.balbi@nokia.com>
11 * Jari Vanhala <ext-javi.vanhala@nokia.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 * 02110-1301 USA
26 *
27 */
28#include <linux/module.h>
29#include <linux/platform_device.h>
30#include <linux/workqueue.h>
31#include <linux/i2c/twl.h>
32#include <linux/mfd/twl6040.h>
33#include <linux/slab.h>
34#include <linux/delay.h>
35#include <linux/regulator/consumer.h>
36
37#define EFFECT_DIR_180_DEG 0x8000
38
39/* Recommended modulation index 85% */
40#define TWL6040_VIBRA_MOD 85
41
42#define TWL6040_NUM_SUPPLIES 2
43
44struct vibra_info {
45 struct device *dev;
46 struct input_dev *input_dev;
47 struct workqueue_struct *workqueue;
48 struct work_struct play_work;
49 struct mutex mutex;
50 int irq;
51
52 bool enabled;
53 int weak_speed;
54 int strong_speed;
55 int direction;
56
57 unsigned int vibldrv_res;
58 unsigned int vibrdrv_res;
59 unsigned int viblmotor_res;
60 unsigned int vibrmotor_res;
61
62 struct regulator_bulk_data supplies[TWL6040_NUM_SUPPLIES];
63
64 struct twl6040 *twl6040;
65};
66
67static irqreturn_t twl6040_vib_irq_handler(int irq, void *data)
68{
69 struct vibra_info *info = data;
70 struct twl6040 *twl6040 = info->twl6040;
71 u8 status;
72
73 status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
74 if (status & TWL6040_VIBLOCDET) {
75 dev_warn(info->dev, "Left Vibrator overcurrent detected\n");
76 twl6040_clear_bits(twl6040, TWL6040_REG_VIBCTLL,
77 TWL6040_VIBENAL);
78 }
79 if (status & TWL6040_VIBROCDET) {
80 dev_warn(info->dev, "Right Vibrator overcurrent detected\n");
81 twl6040_clear_bits(twl6040, TWL6040_REG_VIBCTLR,
82 TWL6040_VIBENAR);
83 }
84
85 return IRQ_HANDLED;
86}
87
88static void twl6040_vibra_enable(struct vibra_info *info)
89{
90 struct twl6040 *twl6040 = info->twl6040;
91 int ret;
92
93 ret = regulator_bulk_enable(ARRAY_SIZE(info->supplies), info->supplies);
94 if (ret) {
95 dev_err(info->dev, "failed to enable regulators %d\n", ret);
96 return;
97 }
98
99 twl6040_power(info->twl6040, 1);
100 if (twl6040->rev <= TWL6040_REV_ES1_1) {
101 /*
102 * ERRATA: Disable overcurrent protection for at least
103 * 3ms when enabling vibrator drivers to avoid false
104 * overcurrent detection
105 */
106 twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL,
107 TWL6040_VIBENAL | TWL6040_VIBCTRLL);
108 twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR,
109 TWL6040_VIBENAR | TWL6040_VIBCTRLR);
110 usleep_range(3000, 3500);
111 }
112
113 twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL,
114 TWL6040_VIBENAL);
115 twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR,
116 TWL6040_VIBENAR);
117
118 info->enabled = true;
119}
120
121static void twl6040_vibra_disable(struct vibra_info *info)
122{
123 struct twl6040 *twl6040 = info->twl6040;
124
125 twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLL, 0x00);
126 twl6040_reg_write(twl6040, TWL6040_REG_VIBCTLR, 0x00);
127 twl6040_power(info->twl6040, 0);
128
129 regulator_bulk_disable(ARRAY_SIZE(info->supplies), info->supplies);
130
131 info->enabled = false;
132}
133
134static u8 twl6040_vibra_code(int vddvib, int vibdrv_res, int motor_res,
135 int speed, int direction)
136{
137 int vpk, max_code;
138 u8 vibdat;
139
140 /* output swing */
141 vpk = (vddvib * motor_res * TWL6040_VIBRA_MOD) /
142 (100 * (vibdrv_res + motor_res));
143
144 /* 50mV per VIBDAT code step */
145 max_code = vpk / 50;
146 if (max_code > TWL6040_VIBDAT_MAX)
147 max_code = TWL6040_VIBDAT_MAX;
148
149 /* scale speed to max allowed code */
150 vibdat = (u8)((speed * max_code) / USHRT_MAX);
151
152 /* 2's complement for direction > 180 degrees */
153 vibdat *= direction;
154
155 return vibdat;
156}
157
158static void twl6040_vibra_set_effect(struct vibra_info *info)
159{
160 struct twl6040 *twl6040 = info->twl6040;
161 u8 vibdatl, vibdatr;
162 int volt;
163
164 /* weak motor */
165 volt = regulator_get_voltage(info->supplies[0].consumer) / 1000;
166 vibdatl = twl6040_vibra_code(volt, info->vibldrv_res,
167 info->viblmotor_res,
168 info->weak_speed, info->direction);
169
170 /* strong motor */
171 volt = regulator_get_voltage(info->supplies[1].consumer) / 1000;
172 vibdatr = twl6040_vibra_code(volt, info->vibrdrv_res,
173 info->vibrmotor_res,
174 info->strong_speed, info->direction);
175
176 twl6040_reg_write(twl6040, TWL6040_REG_VIBDATL, vibdatl);
177 twl6040_reg_write(twl6040, TWL6040_REG_VIBDATR, vibdatr);
178}
179
180static void vibra_play_work(struct work_struct *work)
181{
182 struct vibra_info *info = container_of(work,
183 struct vibra_info, play_work);
184
185 mutex_lock(&info->mutex);
186
187 if (info->weak_speed || info->strong_speed) {
188 if (!info->enabled)
189 twl6040_vibra_enable(info);
190
191 twl6040_vibra_set_effect(info);
192 } else if (info->enabled)
193 twl6040_vibra_disable(info);
194
195 mutex_unlock(&info->mutex);
196}
197
198static int vibra_play(struct input_dev *input, void *data,
199 struct ff_effect *effect)
200{
201 struct vibra_info *info = input_get_drvdata(input);
202 int ret;
203
204 info->weak_speed = effect->u.rumble.weak_magnitude;
205 info->strong_speed = effect->u.rumble.strong_magnitude;
206 info->direction = effect->direction < EFFECT_DIR_180_DEG ? 1 : -1;
207
208 ret = queue_work(info->workqueue, &info->play_work);
209 if (!ret) {
210 dev_info(&input->dev, "work is already on queue\n");
211 return ret;
212 }
213
214 return 0;
215}
216
217static void twl6040_vibra_close(struct input_dev *input)
218{
219 struct vibra_info *info = input_get_drvdata(input);
220
221 cancel_work_sync(&info->play_work);
222
223 mutex_lock(&info->mutex);
224
225 if (info->enabled)
226 twl6040_vibra_disable(info);
227
228 mutex_unlock(&info->mutex);
229}
230
231#ifdef CONFIG_PM_SLEEP
232static int twl6040_vibra_suspend(struct device *dev)
233{
234 struct platform_device *pdev = to_platform_device(dev);
235 struct vibra_info *info = platform_get_drvdata(pdev);
236
237 mutex_lock(&info->mutex);
238
239 if (info->enabled)
240 twl6040_vibra_disable(info);
241
242 mutex_unlock(&info->mutex);
243
244 return 0;
245}
246
247#endif
248
249static SIMPLE_DEV_PM_OPS(twl6040_vibra_pm_ops, twl6040_vibra_suspend, NULL);
250
251static int __devinit twl6040_vibra_probe(struct platform_device *pdev)
252{
253 struct twl4030_vibra_data *pdata = pdev->dev.platform_data;
254 struct vibra_info *info;
255 int ret;
256
257 if (!pdata) {
258 dev_err(&pdev->dev, "platform_data not available\n");
259 return -EINVAL;
260 }
261
262 info = kzalloc(sizeof(*info), GFP_KERNEL);
263 if (!info) {
264 dev_err(&pdev->dev, "couldn't allocate memory\n");
265 return -ENOMEM;
266 }
267
268 info->dev = &pdev->dev;
269 info->twl6040 = dev_get_drvdata(pdev->dev.parent);
270 info->vibldrv_res = pdata->vibldrv_res;
271 info->vibrdrv_res = pdata->vibrdrv_res;
272 info->viblmotor_res = pdata->viblmotor_res;
273 info->vibrmotor_res = pdata->vibrmotor_res;
274 if ((!info->vibldrv_res && !info->viblmotor_res) ||
275 (!info->vibrdrv_res && !info->vibrmotor_res)) {
276 dev_err(info->dev, "invalid vibra driver/motor resistance\n");
277 ret = -EINVAL;
278 goto err_kzalloc;
279 }
280
281 info->irq = platform_get_irq(pdev, 0);
282 if (info->irq < 0) {
283 dev_err(info->dev, "invalid irq\n");
284 ret = -EINVAL;
285 goto err_kzalloc;
286 }
287
288 mutex_init(&info->mutex);
289
290 info->input_dev = input_allocate_device();
291 if (info->input_dev == NULL) {
292 dev_err(info->dev, "couldn't allocate input device\n");
293 ret = -ENOMEM;
294 goto err_kzalloc;
295 }
296
297 input_set_drvdata(info->input_dev, info);
298
299 info->input_dev->name = "twl6040:vibrator";
300 info->input_dev->id.version = 1;
301 info->input_dev->dev.parent = pdev->dev.parent;
302 info->input_dev->close = twl6040_vibra_close;
303 __set_bit(FF_RUMBLE, info->input_dev->ffbit);
304
305 ret = input_ff_create_memless(info->input_dev, NULL, vibra_play);
306 if (ret < 0) {
307 dev_err(info->dev, "couldn't register vibrator to FF\n");
308 goto err_ialloc;
309 }
310
311 ret = input_register_device(info->input_dev);
312 if (ret < 0) {
313 dev_err(info->dev, "couldn't register input device\n");
314 goto err_iff;
315 }
316
317 platform_set_drvdata(pdev, info);
318
319 ret = request_threaded_irq(info->irq, NULL, twl6040_vib_irq_handler, 0,
320 "twl6040_irq_vib", info);
321 if (ret) {
322 dev_err(info->dev, "VIB IRQ request failed: %d\n", ret);
323 goto err_irq;
324 }
325
326 info->supplies[0].supply = "vddvibl";
327 info->supplies[1].supply = "vddvibr";
328 ret = regulator_bulk_get(info->dev, ARRAY_SIZE(info->supplies),
329 info->supplies);
330 if (ret) {
331 dev_err(info->dev, "couldn't get regulators %d\n", ret);
332 goto err_regulator;
333 }
334
335 if (pdata->vddvibl_uV) {
336 ret = regulator_set_voltage(info->supplies[0].consumer,
337 pdata->vddvibl_uV,
338 pdata->vddvibl_uV);
339 if (ret) {
340 dev_err(info->dev, "failed to set VDDVIBL volt %d\n",
341 ret);
342 goto err_voltage;
343 }
344 }
345
346 if (pdata->vddvibr_uV) {
347 ret = regulator_set_voltage(info->supplies[1].consumer,
348 pdata->vddvibr_uV,
349 pdata->vddvibr_uV);
350 if (ret) {
351 dev_err(info->dev, "failed to set VDDVIBR volt %d\n",
352 ret);
353 goto err_voltage;
354 }
355 }
356
357 info->workqueue = alloc_workqueue("twl6040-vibra", 0, 0);
358 if (info->workqueue == NULL) {
359 dev_err(info->dev, "couldn't create workqueue\n");
360 ret = -ENOMEM;
361 goto err_voltage;
362 }
363 INIT_WORK(&info->play_work, vibra_play_work);
364
365 return 0;
366
367err_voltage:
368 regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies);
369err_regulator:
370 free_irq(info->irq, info);
371err_irq:
372 input_unregister_device(info->input_dev);
373 info->input_dev = NULL;
374err_iff:
375 if (info->input_dev)
376 input_ff_destroy(info->input_dev);
377err_ialloc:
378 input_free_device(info->input_dev);
379err_kzalloc:
380 kfree(info);
381 return ret;
382}
383
384static int __devexit twl6040_vibra_remove(struct platform_device *pdev)
385{
386 struct vibra_info *info = platform_get_drvdata(pdev);
387
388 input_unregister_device(info->input_dev);
389 free_irq(info->irq, info);
390 regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies);
391 destroy_workqueue(info->workqueue);
392 kfree(info);
393
394 return 0;
395}
396
397static struct platform_driver twl6040_vibra_driver = {
398 .probe = twl6040_vibra_probe,
399 .remove = __devexit_p(twl6040_vibra_remove),
400 .driver = {
401 .name = "twl6040-vibra",
402 .owner = THIS_MODULE,
403 .pm = &twl6040_vibra_pm_ops,
404 },
405};
406
407static int __init twl6040_vibra_init(void)
408{
409 return platform_driver_register(&twl6040_vibra_driver);
410}
411module_init(twl6040_vibra_init);
412
413static void __exit twl6040_vibra_exit(void)
414{
415 platform_driver_unregister(&twl6040_vibra_driver);
416}
417module_exit(twl6040_vibra_exit);
418
419MODULE_ALIAS("platform:twl6040-vibra");
420MODULE_DESCRIPTION("TWL6040 Vibra driver");
421MODULE_LICENSE("GPL");
422MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>");
423MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");