aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/input/lpc32xx-key.txt28
-rw-r--r--Documentation/devicetree/bindings/input/omap-keypad.txt31
-rw-r--r--Documentation/devicetree/bindings/input/twl6040-vibra.txt37
-rw-r--r--Documentation/input/multi-touch-protocol.txt118
-rw-r--r--arch/arm/plat-spear/include/plat/keyboard.h2
-rw-r--r--drivers/input/ff-memless.c4
-rw-r--r--drivers/input/input-mt.c2
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/gpio_keys.c1
-rw-r--r--drivers/input/keyboard/imx_keypad.c25
-rw-r--r--drivers/input/keyboard/lpc32xx-keys.c394
-rw-r--r--drivers/input/keyboard/nomadik-ske-keypad.c76
-rw-r--r--drivers/input/keyboard/omap4-keypad.c127
-rw-r--r--drivers/input/keyboard/spear-keyboard.c137
-rw-r--r--drivers/input/misc/ab8500-ponkey.c9
-rw-r--r--drivers/input/misc/twl6040-vibra.c42
-rw-r--r--drivers/input/mouse/synaptics.c38
-rw-r--r--drivers/input/mouse/synaptics.h3
-rw-r--r--drivers/input/mouse/synaptics_usb.c2
-rw-r--r--drivers/input/tablet/hanwang.c57
-rw-r--r--drivers/input/tablet/wacom_sys.c101
-rw-r--r--drivers/input/tablet/wacom_wac.c27
-rw-r--r--drivers/input/tablet/wacom_wac.h8
-rw-r--r--drivers/input/touchscreen/Kconfig12
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/ad7879.c5
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c463
-rw-r--r--drivers/input/touchscreen/mms114.c544
-rw-r--r--drivers/input/touchscreen/wacom_i2c.c2
-rw-r--r--include/linux/i2c/mms114.h24
-rw-r--r--include/linux/input.h8
-rw-r--r--include/linux/spi/ad7879.h2
33 files changed, 1839 insertions, 502 deletions
diff --git a/Documentation/devicetree/bindings/input/lpc32xx-key.txt b/Documentation/devicetree/bindings/input/lpc32xx-key.txt
new file mode 100644
index 000000000000..31afd5014c48
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/lpc32xx-key.txt
@@ -0,0 +1,28 @@
1NXP LPC32xx Key Scan Interface
2
3Required Properties:
4- compatible: Should be "nxp,lpc3220-key"
5- reg: Physical base address of the controller and length of memory mapped
6 region.
7- interrupts: The interrupt number to the cpu.
8- keypad,num-rows: Number of rows and columns, e.g. 1: 1x1, 6: 6x6
9- keypad,num-columns: Must be equal to keypad,num-rows since LPC32xx only
10 supports square matrices
11- nxp,debounce-delay-ms: Debounce delay in ms
12- nxp,scan-delay-ms: Repeated scan period in ms
13- linux,keymap: the key-code to be reported when the key is pressed
14 and released, see also
15 Documentation/devicetree/bindings/input/matrix-keymap.txt
16
17Example:
18
19 key@40050000 {
20 compatible = "nxp,lpc3220-key";
21 reg = <0x40050000 0x1000>;
22 interrupts = <54 0>;
23 keypad,num-rows = <1>;
24 keypad,num-columns = <1>;
25 nxp,debounce-delay-ms = <3>;
26 nxp,scan-delay-ms = <34>;
27 linux,keymap = <0x00000002>;
28 };
diff --git a/Documentation/devicetree/bindings/input/omap-keypad.txt b/Documentation/devicetree/bindings/input/omap-keypad.txt
new file mode 100644
index 000000000000..f2fa5e10493d
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/omap-keypad.txt
@@ -0,0 +1,31 @@
1* TI's Keypad Controller device tree bindings
2
3TI's Keypad controller is used to interface a SoC with a matrix-type
4keypad device. The keypad controller supports multiple row and column lines.
5A key can be placed at each intersection of a unique row and a unique column.
6The keypad controller can sense a key-press and key-release and report the
7event using a interrupt to the cpu.
8
9Required SoC Specific Properties:
10- compatible: should be one of the following
11 - "ti,omap4-keypad": For controllers compatible with omap4 keypad
12 controller.
13
14Required Board Specific Properties, in addition to those specified by
15the shared matrix-keyboard bindings:
16- keypad,num-rows: Number of row lines connected to the keypad
17 controller.
18
19- keypad,num-columns: Number of column lines connected to the
20 keypad controller.
21
22Optional Properties specific to linux:
23- linux,keypad-no-autorepeat: do no enable autorepeat feature.
24
25Example:
26 keypad@4ae1c000{
27 compatible = "ti,omap4-keypad";
28 keypad,num-rows = <2>;
29 keypad,num-columns = <8>;
30 linux,keypad-no-autorepeat;
31 };
diff --git a/Documentation/devicetree/bindings/input/twl6040-vibra.txt b/Documentation/devicetree/bindings/input/twl6040-vibra.txt
deleted file mode 100644
index 5b1918b818fb..000000000000
--- a/Documentation/devicetree/bindings/input/twl6040-vibra.txt
+++ /dev/null
@@ -1,37 +0,0 @@
1Vibra driver for the twl6040 family
2
3The vibra driver is a child of the twl6040 MFD dirver.
4Documentation/devicetree/bindings/mfd/twl6040.txt
5
6Required properties:
7- compatible : Must be "ti,twl6040-vibra";
8- interrupts: 4, Vibra overcurrent interrupt
9- vddvibl-supply: Regulator supplying the left vibra motor
10- vddvibr-supply: Regulator supplying the right vibra motor
11- vibldrv_res: Board specific left driver resistance
12- vibrdrv_res: Board specific right driver resistance
13- viblmotor_res: Board specific left motor resistance
14- vibrmotor_res: Board specific right motor resistance
15
16Optional properties:
17- vddvibl_uV: If the vddvibl default voltage need to be changed
18- vddvibr_uV: If the vddvibr default voltage need to be changed
19
20Example:
21/*
22 * 8-channel high quality low-power audio codec
23 * http://www.ti.com/lit/ds/symlink/twl6040.pdf
24 */
25twl6040: twl6040@4b {
26 ...
27 twl6040_vibra: twl6040@1 {
28 compatible = "ti,twl6040-vibra";
29 interrupts = <4>;
30 vddvibl-supply = <&vbat>;
31 vddvibr-supply = <&vbat>;
32 vibldrv_res = <8>;
33 vibrdrv_res = <3>;
34 viblmotor_res = <10>;
35 vibrmotor_res = <10>;
36 };
37};
diff --git a/Documentation/input/multi-touch-protocol.txt b/Documentation/input/multi-touch-protocol.txt
index 543101c5bf26..2c179613f81b 100644
--- a/Documentation/input/multi-touch-protocol.txt
+++ b/Documentation/input/multi-touch-protocol.txt
@@ -162,26 +162,48 @@ are divided into categories, to allow for partial implementation. The
162minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which 162minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which
163allows for multiple contacts to be tracked. If the device supports it, the 163allows for multiple contacts to be tracked. If the device supports it, the
164ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size 164ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size
165of the contact area and approaching contact, respectively. 165of the contact area and approaching tool, respectively.
166 166
167The TOUCH and WIDTH parameters have a geometrical interpretation; imagine 167The TOUCH and WIDTH parameters have a geometrical interpretation; imagine
168looking through a window at someone gently holding a finger against the 168looking through a window at someone gently holding a finger against the
169glass. You will see two regions, one inner region consisting of the part 169glass. You will see two regions, one inner region consisting of the part
170of the finger actually touching the glass, and one outer region formed by 170of the finger actually touching the glass, and one outer region formed by
171the perimeter of the finger. The diameter of the inner region is the 171the perimeter of the finger. The center of the touching region (a) is
172ABS_MT_TOUCH_MAJOR, the diameter of the outer region is 172ABS_MT_POSITION_X/Y and the center of the approaching finger (b) is
173ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger harder 173ABS_MT_TOOL_X/Y. The touch diameter is ABS_MT_TOUCH_MAJOR and the finger
174against the glass. The inner region will increase, and in general, the 174diameter is ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger
175ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller than 175harder against the glass. The touch region will increase, and in general,
176unity, is related to the contact pressure. For pressure-based devices, 176the ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller
177than unity, is related to the contact pressure. For pressure-based devices,
177ABS_MT_PRESSURE may be used to provide the pressure on the contact area 178ABS_MT_PRESSURE may be used to provide the pressure on the contact area
178instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to 179instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to
179indicate the distance between the contact and the surface. 180indicate the distance between the contact and the surface.
180 181
181In addition to the MAJOR parameters, the oval shape of the contact can be 182
182described by adding the MINOR parameters, such that MAJOR and MINOR are the 183 Linux MT Win8
183major and minor axis of an ellipse. Finally, the orientation of the oval 184 __________ _______________________
184shape can be describe with the ORIENTATION parameter. 185 / \ | |
186 / \ | |
187 / ____ \ | |
188 / / \ \ | |
189 \ \ a \ \ | a |
190 \ \____/ \ | |
191 \ \ | |
192 \ b \ | b |
193 \ \ | |
194 \ \ | |
195 \ \ | |
196 \ / | |
197 \ / | |
198 \ / | |
199 \__________/ |_______________________|
200
201
202In addition to the MAJOR parameters, the oval shape of the touch and finger
203regions can be described by adding the MINOR parameters, such that MAJOR
204and MINOR are the major and minor axis of an ellipse. The orientation of
205the touch ellipse can be described with the ORIENTATION parameter, and the
206direction of the finger ellipse is given by the vector (a - b).
185 207
186For type A devices, further specification of the touch shape is possible 208For type A devices, further specification of the touch shape is possible
187via ABS_MT_BLOB_ID. 209via ABS_MT_BLOB_ID.
@@ -224,7 +246,7 @@ tool. Omit if circular [4].
224The above four values can be used to derive additional information about 246The above four values can be used to derive additional information about
225the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates 247the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
226the notion of pressure. The fingers of the hand and the palm all have 248the notion of pressure. The fingers of the hand and the palm all have
227different characteristic widths [1]. 249different characteristic widths.
228 250
229ABS_MT_PRESSURE 251ABS_MT_PRESSURE
230 252
@@ -240,17 +262,24 @@ the contact is hovering above the surface.
240 262
241ABS_MT_ORIENTATION 263ABS_MT_ORIENTATION
242 264
243The orientation of the ellipse. The value should describe a signed quarter 265The orientation of the touching ellipse. The value should describe a signed
244of a revolution clockwise around the touch center. The signed value range 266quarter of a revolution clockwise around the touch center. The signed value
245is arbitrary, but zero should be returned for a finger aligned along the Y 267range is arbitrary, but zero should be returned for an ellipse aligned with
246axis of the surface, a negative value when finger is turned to the left, and 268the Y axis of the surface, a negative value when the ellipse is turned to
247a positive value when finger turned to the right. When completely aligned with 269the left, and a positive value when the ellipse is turned to the
248the X axis, the range max should be returned. Orientation can be omitted 270right. When completely aligned with the X axis, the range max should be
249if the touching object is circular, or if the information is not available 271returned.
250in the kernel driver. Partial orientation support is possible if the device 272
251can distinguish between the two axis, but not (uniquely) any values in 273Touch ellipsis are symmetrical by default. For devices capable of true 360
252between. In such cases, the range of ABS_MT_ORIENTATION should be [0, 1] 274degree orientation, the reported orientation must exceed the range max to
253[4]. 275indicate more than a quarter of a revolution. For an upside-down finger,
276range max * 2 should be returned.
277
278Orientation can be omitted if the touch area is circular, or if the
279information is not available in the kernel driver. Partial orientation
280support is possible if the device can distinguish between the two axis, but
281not (uniquely) any values in between. In such cases, the range of
282ABS_MT_ORIENTATION should be [0, 1] [4].
254 283
255ABS_MT_POSITION_X 284ABS_MT_POSITION_X
256 285
@@ -260,6 +289,23 @@ ABS_MT_POSITION_Y
260 289
261The surface Y coordinate of the center of the touching ellipse. 290The surface Y coordinate of the center of the touching ellipse.
262 291
292ABS_MT_TOOL_X
293
294The surface X coordinate of the center of the approaching tool. Omit if
295the device cannot distinguish between the intended touch point and the
296tool itself.
297
298ABS_MT_TOOL_Y
299
300The surface Y coordinate of the center of the approaching tool. Omit if the
301device cannot distinguish between the intended touch point and the tool
302itself.
303
304The four position values can be used to separate the position of the touch
305from the position of the tool. If both positions are present, the major
306tool axis points towards the touch point [1]. Otherwise, the tool axes are
307aligned with the touch axes.
308
263ABS_MT_TOOL_TYPE 309ABS_MT_TOOL_TYPE
264 310
265The type of approaching tool. A lot of kernel drivers cannot distinguish 311The type of approaching tool. A lot of kernel drivers cannot distinguish
@@ -305,6 +351,28 @@ The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
305the device can distinguish between a finger along the Y axis (0) and a 351the device can distinguish between a finger along the Y axis (0) and a
306finger along the X axis (1). 352finger along the X axis (1).
307 353
354For win8 devices with both T and C coordinates, the position mapping is
355
356 ABS_MT_POSITION_X := T_X
357 ABS_MT_POSITION_Y := T_Y
358 ABS_MT_TOOL_X := C_X
359 ABS_MT_TOOL_X := C_Y
360
361Unfortunately, there is not enough information to specify both the touching
362ellipse and the tool ellipse, so one has to resort to approximations. One
363simple scheme, which is compatible with earlier usage, is:
364
365 ABS_MT_TOUCH_MAJOR := min(X, Y)
366 ABS_MT_TOUCH_MINOR := <not used>
367 ABS_MT_ORIENTATION := <not used>
368 ABS_MT_WIDTH_MAJOR := min(X, Y) + distance(T, C)
369 ABS_MT_WIDTH_MINOR := min(X, Y)
370
371Rationale: We have no information about the orientation of the touching
372ellipse, so approximate it with an inscribed circle instead. The tool
373ellipse should align with the the vector (T - C), so the diameter must
374increase with distance(T, C). Finally, assume that the touch diameter is
375equal to the tool thickness, and we arrive at the formulas above.
308 376
309Finger Tracking 377Finger Tracking
310--------------- 378---------------
@@ -338,9 +406,7 @@ subsequent events of the same type refer to different fingers.
338For example usage of the type A protocol, see the bcm5974 driver. For 406For example usage of the type A protocol, see the bcm5974 driver. For
339example usage of the type B protocol, see the hid-egalax driver. 407example usage of the type B protocol, see the hid-egalax driver.
340 408
341[1] With the extension ABS_MT_APPROACH_X and ABS_MT_APPROACH_Y, the 409[1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt.
342difference between the contact position and the approaching tool position
343could be used to derive tilt.
344[2] The list can of course be extended. 410[2] The list can of course be extended.
345[3] The mtdev project: http://bitmath.org/code/mtdev/. 411[3] The mtdev project: http://bitmath.org/code/mtdev/.
346[4] See the section on event computation. 412[4] See the section on event computation.
diff --git a/arch/arm/plat-spear/include/plat/keyboard.h b/arch/arm/plat-spear/include/plat/keyboard.h
index 0562f134621d..9248e3a7e333 100644
--- a/arch/arm/plat-spear/include/plat/keyboard.h
+++ b/arch/arm/plat-spear/include/plat/keyboard.h
@@ -149,6 +149,7 @@ int _name[] = { \
149 * keymap: pointer to keymap data (table and size) 149 * keymap: pointer to keymap data (table and size)
150 * rep: enables key autorepeat 150 * rep: enables key autorepeat
151 * mode: choose keyboard support(9x9, 6x6, 2x2) 151 * mode: choose keyboard support(9x9, 6x6, 2x2)
152 * suspended_rate: rate at which keyboard would operate in suspended mode
152 * 153 *
153 * This structure is supposed to be used by platform code to supply 154 * This structure is supposed to be used by platform code to supply
154 * keymaps to drivers that implement keyboards. 155 * keymaps to drivers that implement keyboards.
@@ -157,6 +158,7 @@ struct kbd_platform_data {
157 const struct matrix_keymap_data *keymap; 158 const struct matrix_keymap_data *keymap;
158 bool rep; 159 bool rep;
159 unsigned int mode; 160 unsigned int mode;
161 unsigned int suspended_rate;
160}; 162};
161 163
162#endif /* __PLAT_KEYBOARD_H */ 164#endif /* __PLAT_KEYBOARD_H */
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
index 5f558851d646..b107922514fb 100644
--- a/drivers/input/ff-memless.c
+++ b/drivers/input/ff-memless.c
@@ -176,7 +176,7 @@ static int apply_envelope(struct ml_effect_state *state, int value,
176 value, envelope->attack_level); 176 value, envelope->attack_level);
177 time_from_level = jiffies_to_msecs(now - state->play_at); 177 time_from_level = jiffies_to_msecs(now - state->play_at);
178 time_of_envelope = envelope->attack_length; 178 time_of_envelope = envelope->attack_length;
179 envelope_level = min_t(__s16, envelope->attack_level, 0x7fff); 179 envelope_level = min_t(u16, envelope->attack_level, 0x7fff);
180 180
181 } else if (envelope->fade_length && effect->replay.length && 181 } else if (envelope->fade_length && effect->replay.length &&
182 time_after(now, 182 time_after(now,
@@ -184,7 +184,7 @@ static int apply_envelope(struct ml_effect_state *state, int value,
184 time_before(now, state->stop_at)) { 184 time_before(now, state->stop_at)) {
185 time_from_level = jiffies_to_msecs(state->stop_at - now); 185 time_from_level = jiffies_to_msecs(state->stop_at - now);
186 time_of_envelope = envelope->fade_length; 186 time_of_envelope = envelope->fade_length;
187 envelope_level = min_t(__s16, envelope->fade_level, 0x7fff); 187 envelope_level = min_t(u16, envelope->fade_level, 0x7fff);
188 } else 188 } else
189 return value; 189 return value;
190 190
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index f658086fbbe0..70a16c7da8cc 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -135,7 +135,7 @@ EXPORT_SYMBOL(input_mt_report_finger_count);
135 */ 135 */
136void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count) 136void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count)
137{ 137{
138 struct input_mt_slot *oldest = 0; 138 struct input_mt_slot *oldest = NULL;
139 int oldid = dev->trkid; 139 int oldid = dev->trkid;
140 int count = 0; 140 int count = 0;
141 int i; 141 int i;
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index c0e11ecc646f..c50fa75416f8 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -332,6 +332,16 @@ config KEYBOARD_LOCOMO
332 To compile this driver as a module, choose M here: the 332 To compile this driver as a module, choose M here: the
333 module will be called locomokbd. 333 module will be called locomokbd.
334 334
335config KEYBOARD_LPC32XX
336 tristate "LPC32XX matrix key scanner support"
337 depends on ARCH_LPC32XX && OF
338 help
339 Say Y here if you want to use NXP LPC32XX SoC key scanner interface,
340 connected to a key matrix.
341
342 To compile this driver as a module, choose M here: the
343 module will be called lpc32xx-keys.
344
335config KEYBOARD_MAPLE 345config KEYBOARD_MAPLE
336 tristate "Maple bus keyboard" 346 tristate "Maple bus keyboard"
337 depends on SH_DREAMCAST && MAPLE 347 depends on SH_DREAMCAST && MAPLE
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index b03b02456a82..44e76002f54b 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o
26obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o 26obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o
27obj-$(CONFIG_KEYBOARD_LM8333) += lm8333.o 27obj-$(CONFIG_KEYBOARD_LM8333) += lm8333.o
28obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o 28obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o
29obj-$(CONFIG_KEYBOARD_LPC32XX) += lpc32xx-keys.o
29obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o 30obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o
30obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o 31obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
31obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o 32obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 62bfce468f9f..cbb1add43d5e 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -559,7 +559,6 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
559 pdata->rep = !!of_get_property(node, "autorepeat", NULL); 559 pdata->rep = !!of_get_property(node, "autorepeat", NULL);
560 560
561 /* First count the subnodes */ 561 /* First count the subnodes */
562 pdata->nbuttons = 0;
563 pp = NULL; 562 pp = NULL;
564 while ((pp = of_get_next_child(node, pp))) 563 while ((pp = of_get_next_child(node, pp)))
565 pdata->nbuttons++; 564 pdata->nbuttons++;
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index 6ee7421e2321..ff4c0a87a25f 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -378,20 +378,24 @@ static void imx_keypad_close(struct input_dev *dev)
378 imx_keypad_inhibit(keypad); 378 imx_keypad_inhibit(keypad);
379 379
380 /* Disable clock unit */ 380 /* Disable clock unit */
381 clk_disable(keypad->clk); 381 clk_disable_unprepare(keypad->clk);
382} 382}
383 383
384static int imx_keypad_open(struct input_dev *dev) 384static int imx_keypad_open(struct input_dev *dev)
385{ 385{
386 struct imx_keypad *keypad = input_get_drvdata(dev); 386 struct imx_keypad *keypad = input_get_drvdata(dev);
387 int error;
387 388
388 dev_dbg(&dev->dev, ">%s\n", __func__); 389 dev_dbg(&dev->dev, ">%s\n", __func__);
389 390
391 /* Enable the kpp clock */
392 error = clk_prepare_enable(keypad->clk);
393 if (error)
394 return error;
395
390 /* We became active from now */ 396 /* We became active from now */
391 keypad->enabled = true; 397 keypad->enabled = true;
392 398
393 /* Enable the kpp clock */
394 clk_enable(keypad->clk);
395 imx_keypad_config(keypad); 399 imx_keypad_config(keypad);
396 400
397 /* Sanity control, not all the rows must be actived now. */ 401 /* Sanity control, not all the rows must be actived now. */
@@ -467,7 +471,7 @@ static int __devinit imx_keypad_probe(struct platform_device *pdev)
467 goto failed_free_priv; 471 goto failed_free_priv;
468 } 472 }
469 473
470 keypad->clk = clk_get(&pdev->dev, "kpp"); 474 keypad->clk = clk_get(&pdev->dev, NULL);
471 if (IS_ERR(keypad->clk)) { 475 if (IS_ERR(keypad->clk)) {
472 dev_err(&pdev->dev, "failed to get keypad clock\n"); 476 dev_err(&pdev->dev, "failed to get keypad clock\n");
473 error = PTR_ERR(keypad->clk); 477 error = PTR_ERR(keypad->clk);
@@ -581,7 +585,7 @@ static int imx_kbd_suspend(struct device *dev)
581 mutex_lock(&input_dev->mutex); 585 mutex_lock(&input_dev->mutex);
582 586
583 if (input_dev->users) 587 if (input_dev->users)
584 clk_disable(kbd->clk); 588 clk_disable_unprepare(kbd->clk);
585 589
586 mutex_unlock(&input_dev->mutex); 590 mutex_unlock(&input_dev->mutex);
587 591
@@ -596,18 +600,23 @@ static int imx_kbd_resume(struct device *dev)
596 struct platform_device *pdev = to_platform_device(dev); 600 struct platform_device *pdev = to_platform_device(dev);
597 struct imx_keypad *kbd = platform_get_drvdata(pdev); 601 struct imx_keypad *kbd = platform_get_drvdata(pdev);
598 struct input_dev *input_dev = kbd->input_dev; 602 struct input_dev *input_dev = kbd->input_dev;
603 int ret = 0;
599 604
600 if (device_may_wakeup(&pdev->dev)) 605 if (device_may_wakeup(&pdev->dev))
601 disable_irq_wake(kbd->irq); 606 disable_irq_wake(kbd->irq);
602 607
603 mutex_lock(&input_dev->mutex); 608 mutex_lock(&input_dev->mutex);
604 609
605 if (input_dev->users) 610 if (input_dev->users) {
606 clk_enable(kbd->clk); 611 ret = clk_prepare_enable(kbd->clk);
612 if (ret)
613 goto err_clk;
614 }
607 615
616err_clk:
608 mutex_unlock(&input_dev->mutex); 617 mutex_unlock(&input_dev->mutex);
609 618
610 return 0; 619 return ret;
611} 620}
612#endif 621#endif
613 622
diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c
new file mode 100644
index 000000000000..dd786c8a7584
--- /dev/null
+++ b/drivers/input/keyboard/lpc32xx-keys.c
@@ -0,0 +1,394 @@
1/*
2 * NXP LPC32xx SoC Key Scan Interface
3 *
4 * Authors:
5 * Kevin Wells <kevin.wells@nxp.com>
6 * Roland Stigge <stigge@antcom.de>
7 *
8 * Copyright (C) 2010 NXP Semiconductors
9 * Copyright (C) 2012 Roland Stigge
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 *
22 * This controller supports square key matrices from 1x1 up to 8x8
23 */
24
25#include <linux/module.h>
26#include <linux/interrupt.h>
27#include <linux/slab.h>
28#include <linux/irq.h>
29#include <linux/pm.h>
30#include <linux/platform_device.h>
31#include <linux/input.h>
32#include <linux/clk.h>
33#include <linux/io.h>
34#include <linux/of.h>
35#include <linux/input/matrix_keypad.h>
36
37#define DRV_NAME "lpc32xx_keys"
38
39/*
40 * Key scanner register offsets
41 */
42#define LPC32XX_KS_DEB(x) ((x) + 0x00)
43#define LPC32XX_KS_STATE_COND(x) ((x) + 0x04)
44#define LPC32XX_KS_IRQ(x) ((x) + 0x08)
45#define LPC32XX_KS_SCAN_CTL(x) ((x) + 0x0C)
46#define LPC32XX_KS_FAST_TST(x) ((x) + 0x10)
47#define LPC32XX_KS_MATRIX_DIM(x) ((x) + 0x14) /* 1..8 */
48#define LPC32XX_KS_DATA(x, y) ((x) + 0x40 + ((y) << 2))
49
50#define LPC32XX_KSCAN_DEB_NUM_DEB_PASS(n) ((n) & 0xFF)
51
52#define LPC32XX_KSCAN_SCOND_IN_IDLE 0x0
53#define LPC32XX_KSCAN_SCOND_IN_SCANONCE 0x1
54#define LPC32XX_KSCAN_SCOND_IN_IRQGEN 0x2
55#define LPC32XX_KSCAN_SCOND_IN_SCAN_MATRIX 0x3
56
57#define LPC32XX_KSCAN_IRQ_PENDING_CLR 0x1
58
59#define LPC32XX_KSCAN_SCTRL_SCAN_DELAY(n) ((n) & 0xFF)
60
61#define LPC32XX_KSCAN_FTST_FORCESCANONCE 0x1
62#define LPC32XX_KSCAN_FTST_USE32K_CLK 0x2
63
64#define LPC32XX_KSCAN_MSEL_SELECT(n) ((n) & 0xF)
65
66struct lpc32xx_kscan_drv {
67 struct input_dev *input;
68 struct clk *clk;
69 struct resource *iores;
70 void __iomem *kscan_base;
71 unsigned int irq;
72
73 u32 matrix_sz; /* Size of matrix in XxY, ie. 3 = 3x3 */
74 u32 deb_clks; /* Debounce clocks (based on 32KHz clock) */
75 u32 scan_delay; /* Scan delay (based on 32KHz clock) */
76
77 unsigned short *keymap; /* Pointer to key map for the scan matrix */
78 unsigned int row_shift;
79
80 u8 lastkeystates[8];
81};
82
83static void lpc32xx_mod_states(struct lpc32xx_kscan_drv *kscandat, int col)
84{
85 struct input_dev *input = kscandat->input;
86 unsigned row, changed, scancode, keycode;
87 u8 key;
88
89 key = readl(LPC32XX_KS_DATA(kscandat->kscan_base, col));
90 changed = key ^ kscandat->lastkeystates[col];
91 kscandat->lastkeystates[col] = key;
92
93 for (row = 0; changed; row++, changed >>= 1) {
94 if (changed & 1) {
95 /* Key state changed, signal an event */
96 scancode = MATRIX_SCAN_CODE(row, col,
97 kscandat->row_shift);
98 keycode = kscandat->keymap[scancode];
99 input_event(input, EV_MSC, MSC_SCAN, scancode);
100 input_report_key(input, keycode, key & (1 << row));
101 }
102 }
103}
104
105static irqreturn_t lpc32xx_kscan_irq(int irq, void *dev_id)
106{
107 struct lpc32xx_kscan_drv *kscandat = dev_id;
108 int i;
109
110 for (i = 0; i < kscandat->matrix_sz; i++)
111 lpc32xx_mod_states(kscandat, i);
112
113 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
114
115 input_sync(kscandat->input);
116
117 return IRQ_HANDLED;
118}
119
120static int lpc32xx_kscan_open(struct input_dev *dev)
121{
122 struct lpc32xx_kscan_drv *kscandat = input_get_drvdata(dev);
123 int error;
124
125 error = clk_prepare_enable(kscandat->clk);
126 if (error)
127 return error;
128
129 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
130
131 return 0;
132}
133
134static void lpc32xx_kscan_close(struct input_dev *dev)
135{
136 struct lpc32xx_kscan_drv *kscandat = input_get_drvdata(dev);
137
138 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
139 clk_disable_unprepare(kscandat->clk);
140}
141
142static int __devinit lpc32xx_parse_dt(struct device *dev,
143 struct lpc32xx_kscan_drv *kscandat)
144{
145 struct device_node *np = dev->of_node;
146 u32 rows = 0, columns = 0;
147
148 of_property_read_u32(np, "keypad,num-rows", &rows);
149 of_property_read_u32(np, "keypad,num-columns", &columns);
150 if (!rows || rows != columns) {
151 dev_err(dev,
152 "rows and columns must be specified and be equal!\n");
153 return -EINVAL;
154 }
155
156 kscandat->matrix_sz = rows;
157 kscandat->row_shift = get_count_order(columns);
158
159 of_property_read_u32(np, "nxp,debounce-delay-ms", &kscandat->deb_clks);
160 of_property_read_u32(np, "nxp,scan-delay-ms", &kscandat->scan_delay);
161 if (!kscandat->deb_clks || !kscandat->scan_delay) {
162 dev_err(dev, "debounce or scan delay not specified\n");
163 return -EINVAL;
164 }
165
166 return 0;
167}
168
169static int __devinit lpc32xx_kscan_probe(struct platform_device *pdev)
170{
171 struct lpc32xx_kscan_drv *kscandat;
172 struct input_dev *input;
173 struct resource *res;
174 size_t keymap_size;
175 int error;
176 int irq;
177
178 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
179 if (!res) {
180 dev_err(&pdev->dev, "failed to get platform I/O memory\n");
181 return -EINVAL;
182 }
183
184 irq = platform_get_irq(pdev, 0);
185 if (irq < 0 || irq >= NR_IRQS) {
186 dev_err(&pdev->dev, "failed to get platform irq\n");
187 return -EINVAL;
188 }
189
190 kscandat = kzalloc(sizeof(struct lpc32xx_kscan_drv), GFP_KERNEL);
191 if (!kscandat) {
192 dev_err(&pdev->dev, "failed to allocate memory\n");
193 return -ENOMEM;
194 }
195
196 error = lpc32xx_parse_dt(&pdev->dev, kscandat);
197 if (error) {
198 dev_err(&pdev->dev, "failed to parse device tree\n");
199 goto err_free_mem;
200 }
201
202 keymap_size = sizeof(kscandat->keymap[0]) *
203 (kscandat->matrix_sz << kscandat->row_shift);
204 kscandat->keymap = kzalloc(keymap_size, GFP_KERNEL);
205 if (!kscandat->keymap) {
206 dev_err(&pdev->dev, "could not allocate memory for keymap\n");
207 error = -ENOMEM;
208 goto err_free_mem;
209 }
210
211 kscandat->input = input = input_allocate_device();
212 if (!input) {
213 dev_err(&pdev->dev, "failed to allocate input device\n");
214 error = -ENOMEM;
215 goto err_free_keymap;
216 }
217
218 /* Setup key input */
219 input->name = pdev->name;
220 input->phys = "lpc32xx/input0";
221 input->id.vendor = 0x0001;
222 input->id.product = 0x0001;
223 input->id.version = 0x0100;
224 input->open = lpc32xx_kscan_open;
225 input->close = lpc32xx_kscan_close;
226 input->dev.parent = &pdev->dev;
227
228 input_set_capability(input, EV_MSC, MSC_SCAN);
229
230 error = matrix_keypad_build_keymap(NULL, NULL,
231 kscandat->matrix_sz,
232 kscandat->matrix_sz,
233 kscandat->keymap, kscandat->input);
234 if (error) {
235 dev_err(&pdev->dev, "failed to build keymap\n");
236 goto err_free_input;
237 }
238
239 input_set_drvdata(kscandat->input, kscandat);
240
241 kscandat->iores = request_mem_region(res->start, resource_size(res),
242 pdev->name);
243 if (!kscandat->iores) {
244 dev_err(&pdev->dev, "failed to request I/O memory\n");
245 error = -EBUSY;
246 goto err_free_input;
247 }
248
249 kscandat->kscan_base = ioremap(kscandat->iores->start,
250 resource_size(kscandat->iores));
251 if (!kscandat->kscan_base) {
252 dev_err(&pdev->dev, "failed to remap I/O memory\n");
253 error = -EBUSY;
254 goto err_release_memregion;
255 }
256
257 /* Get the key scanner clock */
258 kscandat->clk = clk_get(&pdev->dev, NULL);
259 if (IS_ERR(kscandat->clk)) {
260 dev_err(&pdev->dev, "failed to get clock\n");
261 error = PTR_ERR(kscandat->clk);
262 goto err_unmap;
263 }
264
265 /* Configure the key scanner */
266 error = clk_prepare_enable(kscandat->clk);
267 if (error)
268 goto err_clk_put;
269
270 writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base));
271 writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base));
272 writel(LPC32XX_KSCAN_FTST_USE32K_CLK,
273 LPC32XX_KS_FAST_TST(kscandat->kscan_base));
274 writel(kscandat->matrix_sz,
275 LPC32XX_KS_MATRIX_DIM(kscandat->kscan_base));
276 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
277 clk_disable_unprepare(kscandat->clk);
278
279 error = request_irq(irq, lpc32xx_kscan_irq, 0, pdev->name, kscandat);
280 if (error) {
281 dev_err(&pdev->dev, "failed to request irq\n");
282 goto err_clk_put;
283 }
284
285 error = input_register_device(kscandat->input);
286 if (error) {
287 dev_err(&pdev->dev, "failed to register input device\n");
288 goto err_free_irq;
289 }
290
291 platform_set_drvdata(pdev, kscandat);
292 return 0;
293
294err_free_irq:
295 free_irq(irq, kscandat);
296err_clk_put:
297 clk_put(kscandat->clk);
298err_unmap:
299 iounmap(kscandat->kscan_base);
300err_release_memregion:
301 release_mem_region(kscandat->iores->start,
302 resource_size(kscandat->iores));
303err_free_input:
304 input_free_device(kscandat->input);
305err_free_keymap:
306 kfree(kscandat->keymap);
307err_free_mem:
308 kfree(kscandat);
309
310 return error;
311}
312
313static int __devexit lpc32xx_kscan_remove(struct platform_device *pdev)
314{
315 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
316
317 free_irq(platform_get_irq(pdev, 0), kscandat);
318 clk_put(kscandat->clk);
319 iounmap(kscandat->kscan_base);
320 release_mem_region(kscandat->iores->start,
321 resource_size(kscandat->iores));
322 input_unregister_device(kscandat->input);
323 kfree(kscandat->keymap);
324 kfree(kscandat);
325
326 return 0;
327}
328
329#ifdef CONFIG_PM_SLEEP
330static int lpc32xx_kscan_suspend(struct device *dev)
331{
332 struct platform_device *pdev = to_platform_device(dev);
333 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
334 struct input_dev *input = kscandat->input;
335
336 mutex_lock(&input->mutex);
337
338 if (input->users) {
339 /* Clear IRQ and disable clock */
340 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
341 clk_disable_unprepare(kscandat->clk);
342 }
343
344 mutex_unlock(&input->mutex);
345 return 0;
346}
347
348static int lpc32xx_kscan_resume(struct device *dev)
349{
350 struct platform_device *pdev = to_platform_device(dev);
351 struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
352 struct input_dev *input = kscandat->input;
353 int retval = 0;
354
355 mutex_lock(&input->mutex);
356
357 if (input->users) {
358 /* Enable clock and clear IRQ */
359 retval = clk_prepare_enable(kscandat->clk);
360 if (retval == 0)
361 writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
362 }
363
364 mutex_unlock(&input->mutex);
365 return retval;
366}
367#endif
368
369static SIMPLE_DEV_PM_OPS(lpc32xx_kscan_pm_ops, lpc32xx_kscan_suspend,
370 lpc32xx_kscan_resume);
371
372static const struct of_device_id lpc32xx_kscan_match[] = {
373 { .compatible = "nxp,lpc3220-key" },
374 {},
375};
376MODULE_DEVICE_TABLE(of, lpc32xx_kscan_match);
377
378static struct platform_driver lpc32xx_kscan_driver = {
379 .probe = lpc32xx_kscan_probe,
380 .remove = __devexit_p(lpc32xx_kscan_remove),
381 .driver = {
382 .name = DRV_NAME,
383 .owner = THIS_MODULE,
384 .pm = &lpc32xx_kscan_pm_ops,
385 .of_match_table = of_match_ptr(lpc32xx_kscan_match),
386 }
387};
388
389module_platform_driver(lpc32xx_kscan_driver);
390
391MODULE_LICENSE("GPL");
392MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
393MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
394MODULE_DESCRIPTION("Key scanner driver for LPC32XX devices");
diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c
index 4ea4341a68c5..a880e7414202 100644
--- a/drivers/input/keyboard/nomadik-ske-keypad.c
+++ b/drivers/input/keyboard/nomadik-ske-keypad.c
@@ -49,6 +49,7 @@
49#define SKE_ASR3 0x2C 49#define SKE_ASR3 0x2C
50 50
51#define SKE_NUM_ASRX_REGISTERS (4) 51#define SKE_NUM_ASRX_REGISTERS (4)
52#define KEY_PRESSED_DELAY 10
52 53
53/** 54/**
54 * struct ske_keypad - data structure used by keypad driver 55 * struct ske_keypad - data structure used by keypad driver
@@ -92,7 +93,7 @@ static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr,
92static int __init ske_keypad_chip_init(struct ske_keypad *keypad) 93static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
93{ 94{
94 u32 value; 95 u32 value;
95 int timeout = 50; 96 int timeout = keypad->board->debounce_ms;
96 97
97 /* check SKE_RIS to be 0 */ 98 /* check SKE_RIS to be 0 */
98 while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--) 99 while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--)
@@ -135,12 +136,37 @@ static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
135 return 0; 136 return 0;
136} 137}
137 138
138static void ske_keypad_read_data(struct ske_keypad *keypad) 139static void ske_keypad_report(struct ske_keypad *keypad, u8 status, int col)
139{ 140{
141 int row = 0, code, pos;
140 struct input_dev *input = keypad->input; 142 struct input_dev *input = keypad->input;
141 u16 status; 143 u32 ske_ris;
142 int col = 0, row = 0, code; 144 int key_pressed;
143 int ske_asr, ske_ris, key_pressed, i; 145 int num_of_rows;
146
147 /* find out the row */
148 num_of_rows = hweight8(status);
149 do {
150 pos = __ffs(status);
151 row = pos;
152 status &= ~(1 << pos);
153
154 code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
155 ske_ris = readl(keypad->reg_base + SKE_RIS);
156 key_pressed = ske_ris & SKE_KPRISA;
157
158 input_event(input, EV_MSC, MSC_SCAN, code);
159 input_report_key(input, keypad->keymap[code], key_pressed);
160 input_sync(input);
161 num_of_rows--;
162 } while (num_of_rows);
163}
164
165static void ske_keypad_read_data(struct ske_keypad *keypad)
166{
167 u8 status;
168 int col = 0;
169 int ske_asr, i;
144 170
145 /* 171 /*
146 * Read the auto scan registers 172 * Read the auto scan registers
@@ -154,44 +180,38 @@ static void ske_keypad_read_data(struct ske_keypad *keypad)
154 if (!ske_asr) 180 if (!ske_asr)
155 continue; 181 continue;
156 182
157 /* now that ASRx is zero, find out the column x and row y*/ 183 /* now that ASRx is zero, find out the coloumn x and row y */
158 if (ske_asr & 0xff) { 184 status = ske_asr & 0xff;
185 if (status) {
159 col = i * 2; 186 col = i * 2;
160 status = ske_asr & 0xff; 187 ske_keypad_report(keypad, status, col);
161 } else { 188 }
189 status = (ske_asr & 0xff00) >> 8;
190 if (status) {
162 col = (i * 2) + 1; 191 col = (i * 2) + 1;
163 status = (ske_asr & 0xff00) >> 8; 192 ske_keypad_report(keypad, status, col);
164 } 193 }
165
166 /* find out the row */
167 row = __ffs(status);
168
169 code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
170 ske_ris = readl(keypad->reg_base + SKE_RIS);
171 key_pressed = ske_ris & SKE_KPRISA;
172
173 input_event(input, EV_MSC, MSC_SCAN, code);
174 input_report_key(input, keypad->keymap[code], key_pressed);
175 input_sync(input);
176 } 194 }
177} 195}
178 196
179static irqreturn_t ske_keypad_irq(int irq, void *dev_id) 197static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
180{ 198{
181 struct ske_keypad *keypad = dev_id; 199 struct ske_keypad *keypad = dev_id;
182 int retries = 20; 200 int timeout = keypad->board->debounce_ms;
183 201
184 /* disable auto scan interrupt; mask the interrupt generated */ 202 /* disable auto scan interrupt; mask the interrupt generated */
185 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0); 203 ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
186 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA); 204 ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA);
187 205
188 while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --retries) 206 while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --timeout)
189 msleep(5); 207 cpu_relax();
190 208
191 if (retries) { 209 /* SKEx registers are stable and can be read */
192 /* SKEx registers are stable and can be read */ 210 ske_keypad_read_data(keypad);
193 ske_keypad_read_data(keypad); 211
194 } 212 /* wait until raw interrupt is clear */
213 while ((readl(keypad->reg_base + SKE_RIS)) && --timeout)
214 msleep(KEY_PRESSED_DELAY);
195 215
196 /* enable auto scan interrupts */ 216 /* enable auto scan interrupts */
197 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 217 ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index aed5f6999ce2..c05f98c41410 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -27,6 +27,7 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/io.h> 29#include <linux/io.h>
30#include <linux/of.h>
30#include <linux/input.h> 31#include <linux/input.h>
31#include <linux/slab.h> 32#include <linux/slab.h>
32#include <linux/pm_runtime.h> 33#include <linux/pm_runtime.h>
@@ -84,8 +85,9 @@ struct omap4_keypad {
84 u32 reg_offset; 85 u32 reg_offset;
85 u32 irqreg_offset; 86 u32 irqreg_offset;
86 unsigned int row_shift; 87 unsigned int row_shift;
88 bool no_autorepeat;
87 unsigned char key_state[8]; 89 unsigned char key_state[8];
88 unsigned short keymap[]; 90 unsigned short *keymap;
89}; 91};
90 92
91static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset) 93static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
@@ -208,25 +210,51 @@ static void omap4_keypad_close(struct input_dev *input)
208 pm_runtime_put_sync(input->dev.parent); 210 pm_runtime_put_sync(input->dev.parent);
209} 211}
210 212
213#ifdef CONFIG_OF
214static int __devinit omap4_keypad_parse_dt(struct device *dev,
215 struct omap4_keypad *keypad_data)
216{
217 struct device_node *np = dev->of_node;
218
219 if (!np) {
220 dev_err(dev, "missing DT data");
221 return -EINVAL;
222 }
223
224 of_property_read_u32(np, "keypad,num-rows", &keypad_data->rows);
225 of_property_read_u32(np, "keypad,num-columns", &keypad_data->cols);
226 if (!keypad_data->rows || !keypad_data->cols) {
227 dev_err(dev, "number of keypad rows/columns not specified\n");
228 return -EINVAL;
229 }
230
231 if (of_get_property(np, "linux,input-no-autorepeat", NULL))
232 keypad_data->no_autorepeat = true;
233
234 return 0;
235}
236#else
237static inline int omap4_keypad_parse_dt(struct device *dev,
238 struct omap4_keypad *keypad_data)
239{
240 return -ENOSYS;
241}
242#endif
243
211static int __devinit omap4_keypad_probe(struct platform_device *pdev) 244static int __devinit omap4_keypad_probe(struct platform_device *pdev)
212{ 245{
213 const struct omap4_keypad_platform_data *pdata; 246 const struct omap4_keypad_platform_data *pdata =
247 dev_get_platdata(&pdev->dev);
248 const struct matrix_keymap_data *keymap_data =
249 pdata ? pdata->keymap_data : NULL;
214 struct omap4_keypad *keypad_data; 250 struct omap4_keypad *keypad_data;
215 struct input_dev *input_dev; 251 struct input_dev *input_dev;
216 struct resource *res; 252 struct resource *res;
217 resource_size_t size; 253 unsigned int max_keys;
218 unsigned int row_shift, max_keys;
219 int rev; 254 int rev;
220 int irq; 255 int irq;
221 int error; 256 int error;
222 257
223 /* platform data */
224 pdata = pdev->dev.platform_data;
225 if (!pdata) {
226 dev_err(&pdev->dev, "no platform data defined\n");
227 return -EINVAL;
228 }
229
230 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 258 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
231 if (!res) { 259 if (!res) {
232 dev_err(&pdev->dev, "no base address specified\n"); 260 dev_err(&pdev->dev, "no base address specified\n");
@@ -239,25 +267,24 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
239 return -EINVAL; 267 return -EINVAL;
240 } 268 }
241 269
242 if (!pdata->keymap_data) { 270 keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
243 dev_err(&pdev->dev, "no keymap data defined\n");
244 return -EINVAL;
245 }
246
247 row_shift = get_count_order(pdata->cols);
248 max_keys = pdata->rows << row_shift;
249
250 keypad_data = kzalloc(sizeof(struct omap4_keypad) +
251 max_keys * sizeof(keypad_data->keymap[0]),
252 GFP_KERNEL);
253 if (!keypad_data) { 271 if (!keypad_data) {
254 dev_err(&pdev->dev, "keypad_data memory allocation failed\n"); 272 dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
255 return -ENOMEM; 273 return -ENOMEM;
256 } 274 }
257 275
258 size = resource_size(res); 276 keypad_data->irq = irq;
277
278 if (pdata) {
279 keypad_data->rows = pdata->rows;
280 keypad_data->cols = pdata->cols;
281 } else {
282 error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
283 if (error)
284 return error;
285 }
259 286
260 res = request_mem_region(res->start, size, pdev->name); 287 res = request_mem_region(res->start, resource_size(res), pdev->name);
261 if (!res) { 288 if (!res) {
262 dev_err(&pdev->dev, "can't request mem region\n"); 289 dev_err(&pdev->dev, "can't request mem region\n");
263 error = -EBUSY; 290 error = -EBUSY;
@@ -271,15 +298,11 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
271 goto err_release_mem; 298 goto err_release_mem;
272 } 299 }
273 300
274 keypad_data->irq = irq;
275 keypad_data->row_shift = row_shift;
276 keypad_data->rows = pdata->rows;
277 keypad_data->cols = pdata->cols;
278 301
279 /* 302 /*
280 * Enable clocks for the keypad module so that we can read 303 * Enable clocks for the keypad module so that we can read
281 * revision register. 304 * revision register.
282 */ 305 */
283 pm_runtime_enable(&pdev->dev); 306 pm_runtime_enable(&pdev->dev);
284 error = pm_runtime_get_sync(&pdev->dev); 307 error = pm_runtime_get_sync(&pdev->dev);
285 if (error) { 308 if (error) {
@@ -322,19 +345,30 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
322 input_dev->open = omap4_keypad_open; 345 input_dev->open = omap4_keypad_open;
323 input_dev->close = omap4_keypad_close; 346 input_dev->close = omap4_keypad_close;
324 347
325 error = matrix_keypad_build_keymap(pdata->keymap_data, NULL, 348 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
326 pdata->rows, pdata->cols, 349 if (!keypad_data->no_autorepeat)
350 __set_bit(EV_REP, input_dev->evbit);
351
352 input_set_drvdata(input_dev, keypad_data);
353
354 keypad_data->row_shift = get_count_order(keypad_data->cols);
355 max_keys = keypad_data->rows << keypad_data->row_shift;
356 keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]),
357 GFP_KERNEL);
358 if (!keypad_data->keymap) {
359 dev_err(&pdev->dev, "Not enough memory for keymap\n");
360 error = -ENOMEM;
361 goto err_free_input;
362 }
363
364 error = matrix_keypad_build_keymap(keymap_data, NULL,
365 keypad_data->rows, keypad_data->cols,
327 keypad_data->keymap, input_dev); 366 keypad_data->keymap, input_dev);
328 if (error) { 367 if (error) {
329 dev_err(&pdev->dev, "failed to build keymap\n"); 368 dev_err(&pdev->dev, "failed to build keymap\n");
330 goto err_free_input; 369 goto err_free_keymap;
331 } 370 }
332 371
333 __set_bit(EV_REP, input_dev->evbit);
334 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
335
336 input_set_drvdata(input_dev, keypad_data);
337
338 error = request_irq(keypad_data->irq, omap4_keypad_interrupt, 372 error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
339 IRQF_TRIGGER_RISING, 373 IRQF_TRIGGER_RISING,
340 "omap4-keypad", keypad_data); 374 "omap4-keypad", keypad_data);
@@ -357,6 +391,8 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
357err_pm_disable: 391err_pm_disable:
358 pm_runtime_disable(&pdev->dev); 392 pm_runtime_disable(&pdev->dev);
359 free_irq(keypad_data->irq, keypad_data); 393 free_irq(keypad_data->irq, keypad_data);
394err_free_keymap:
395 kfree(keypad_data->keymap);
360err_free_input: 396err_free_input:
361 input_free_device(input_dev); 397 input_free_device(input_dev);
362err_pm_put_sync: 398err_pm_put_sync:
@@ -364,7 +400,7 @@ err_pm_put_sync:
364err_unmap: 400err_unmap:
365 iounmap(keypad_data->base); 401 iounmap(keypad_data->base);
366err_release_mem: 402err_release_mem:
367 release_mem_region(res->start, size); 403 release_mem_region(res->start, resource_size(res));
368err_free_keypad: 404err_free_keypad:
369 kfree(keypad_data); 405 kfree(keypad_data);
370 return error; 406 return error;
@@ -386,18 +422,29 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
386 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 422 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
387 release_mem_region(res->start, resource_size(res)); 423 release_mem_region(res->start, resource_size(res));
388 424
425 kfree(keypad_data->keymap);
389 kfree(keypad_data); 426 kfree(keypad_data);
427
390 platform_set_drvdata(pdev, NULL); 428 platform_set_drvdata(pdev, NULL);
391 429
392 return 0; 430 return 0;
393} 431}
394 432
433#ifdef CONFIG_OF
434static const struct of_device_id omap_keypad_dt_match[] = {
435 { .compatible = "ti,omap4-keypad" },
436 {},
437};
438MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
439#endif
440
395static struct platform_driver omap4_keypad_driver = { 441static struct platform_driver omap4_keypad_driver = {
396 .probe = omap4_keypad_probe, 442 .probe = omap4_keypad_probe,
397 .remove = __devexit_p(omap4_keypad_remove), 443 .remove = __devexit_p(omap4_keypad_remove),
398 .driver = { 444 .driver = {
399 .name = "omap4-keypad", 445 .name = "omap4-keypad",
400 .owner = THIS_MODULE, 446 .owner = THIS_MODULE,
447 .of_match_table = of_match_ptr(omap_keypad_dt_match),
401 }, 448 },
402}; 449};
403module_platform_driver(omap4_keypad_driver); 450module_platform_driver(omap4_keypad_driver);
diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
index 6f287f7e1538..72ef01be3360 100644
--- a/drivers/input/keyboard/spear-keyboard.c
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -27,33 +27,31 @@
27#include <plat/keyboard.h> 27#include <plat/keyboard.h>
28 28
29/* Keyboard Registers */ 29/* Keyboard Registers */
30#define MODE_REG 0x00 /* 16 bit reg */ 30#define MODE_CTL_REG 0x00
31#define STATUS_REG 0x0C /* 2 bit reg */ 31#define STATUS_REG 0x0C
32#define DATA_REG 0x10 /* 8 bit reg */ 32#define DATA_REG 0x10
33#define INTR_MASK 0x54 33#define INTR_MASK 0x54
34 34
35/* Register Values */ 35/* Register Values */
36/*
37 * pclk freq mask = (APB FEQ -1)= 82 MHZ.Programme bit 15-9 in mode
38 * control register as 1010010(82MHZ)
39 */
40#define PCLK_FREQ_MSK 0xA400 /* 82 MHz */
41#define START_SCAN 0x0100
42#define SCAN_RATE_10 0x0000
43#define SCAN_RATE_20 0x0004
44#define SCAN_RATE_40 0x0008
45#define SCAN_RATE_80 0x000C
46#define MODE_KEYBOARD 0x0002
47#define DATA_AVAIL 0x2
48
49#define KEY_MASK 0xFF000000
50#define KEY_VALUE 0x00FFFFFF
51#define ROW_MASK 0xF0
52#define COLUMN_MASK 0x0F
53#define NUM_ROWS 16 36#define NUM_ROWS 16
54#define NUM_COLS 16 37#define NUM_COLS 16
38#define MODE_CTL_PCLK_FREQ_SHIFT 9
39#define MODE_CTL_PCLK_FREQ_MSK 0x7F
40
41#define MODE_CTL_KEYBOARD (0x2 << 0)
42#define MODE_CTL_SCAN_RATE_10 (0x0 << 2)
43#define MODE_CTL_SCAN_RATE_20 (0x1 << 2)
44#define MODE_CTL_SCAN_RATE_40 (0x2 << 2)
45#define MODE_CTL_SCAN_RATE_80 (0x3 << 2)
46#define MODE_CTL_KEYNUM_SHIFT 6
47#define MODE_CTL_START_SCAN (0x1 << 8)
55 48
56#define KEY_MATRIX_SHIFT 6 49#define STATUS_DATA_AVAIL (0x1 << 1)
50
51#define DATA_ROW_MASK 0xF0
52#define DATA_COLUMN_MASK 0x0F
53
54#define ROW_SHIFT 4
57 55
58struct spear_kbd { 56struct spear_kbd {
59 struct input_dev *input; 57 struct input_dev *input;
@@ -65,6 +63,8 @@ struct spear_kbd {
65 unsigned short last_key; 63 unsigned short last_key;
66 unsigned short keycodes[NUM_ROWS * NUM_COLS]; 64 unsigned short keycodes[NUM_ROWS * NUM_COLS];
67 bool rep; 65 bool rep;
66 unsigned int suspended_rate;
67 u32 mode_ctl_reg;
68}; 68};
69 69
70static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id) 70static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
@@ -72,10 +72,10 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
72 struct spear_kbd *kbd = dev_id; 72 struct spear_kbd *kbd = dev_id;
73 struct input_dev *input = kbd->input; 73 struct input_dev *input = kbd->input;
74 unsigned int key; 74 unsigned int key;
75 u8 sts, val; 75 u32 sts, val;
76 76
77 sts = readb(kbd->io_base + STATUS_REG); 77 sts = readl_relaxed(kbd->io_base + STATUS_REG);
78 if (!(sts & DATA_AVAIL)) 78 if (!(sts & STATUS_DATA_AVAIL))
79 return IRQ_NONE; 79 return IRQ_NONE;
80 80
81 if (kbd->last_key != KEY_RESERVED) { 81 if (kbd->last_key != KEY_RESERVED) {
@@ -84,7 +84,8 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
84 } 84 }
85 85
86 /* following reads active (row, col) pair */ 86 /* following reads active (row, col) pair */
87 val = readb(kbd->io_base + DATA_REG); 87 val = readl_relaxed(kbd->io_base + DATA_REG) &
88 (DATA_ROW_MASK | DATA_COLUMN_MASK);
88 key = kbd->keycodes[val]; 89 key = kbd->keycodes[val];
89 90
90 input_event(input, EV_MSC, MSC_SCAN, val); 91 input_event(input, EV_MSC, MSC_SCAN, val);
@@ -94,7 +95,7 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
94 kbd->last_key = key; 95 kbd->last_key = key;
95 96
96 /* clear interrupt */ 97 /* clear interrupt */
97 writeb(0, kbd->io_base + STATUS_REG); 98 writel_relaxed(0, kbd->io_base + STATUS_REG);
98 99
99 return IRQ_HANDLED; 100 return IRQ_HANDLED;
100} 101}
@@ -103,7 +104,7 @@ static int spear_kbd_open(struct input_dev *dev)
103{ 104{
104 struct spear_kbd *kbd = input_get_drvdata(dev); 105 struct spear_kbd *kbd = input_get_drvdata(dev);
105 int error; 106 int error;
106 u16 val; 107 u32 val;
107 108
108 kbd->last_key = KEY_RESERVED; 109 kbd->last_key = KEY_RESERVED;
109 110
@@ -111,16 +112,20 @@ static int spear_kbd_open(struct input_dev *dev)
111 if (error) 112 if (error)
112 return error; 113 return error;
113 114
115 /* keyboard rate to be programmed is input clock (in MHz) - 1 */
116 val = clk_get_rate(kbd->clk) / 1000000 - 1;
117 val = (val & MODE_CTL_PCLK_FREQ_MSK) << MODE_CTL_PCLK_FREQ_SHIFT;
118
114 /* program keyboard */ 119 /* program keyboard */
115 val = SCAN_RATE_80 | MODE_KEYBOARD | PCLK_FREQ_MSK | 120 val = MODE_CTL_SCAN_RATE_80 | MODE_CTL_KEYBOARD | val |
116 (kbd->mode << KEY_MATRIX_SHIFT); 121 (kbd->mode << MODE_CTL_KEYNUM_SHIFT);
117 writew(val, kbd->io_base + MODE_REG); 122 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
118 writeb(1, kbd->io_base + STATUS_REG); 123 writel_relaxed(1, kbd->io_base + STATUS_REG);
119 124
120 /* start key scan */ 125 /* start key scan */
121 val = readw(kbd->io_base + MODE_REG); 126 val = readl_relaxed(kbd->io_base + MODE_CTL_REG);
122 val |= START_SCAN; 127 val |= MODE_CTL_START_SCAN;
123 writew(val, kbd->io_base + MODE_REG); 128 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
124 129
125 return 0; 130 return 0;
126} 131}
@@ -128,12 +133,12 @@ static int spear_kbd_open(struct input_dev *dev)
128static void spear_kbd_close(struct input_dev *dev) 133static void spear_kbd_close(struct input_dev *dev)
129{ 134{
130 struct spear_kbd *kbd = input_get_drvdata(dev); 135 struct spear_kbd *kbd = input_get_drvdata(dev);
131 u16 val; 136 u32 val;
132 137
133 /* stop key scan */ 138 /* stop key scan */
134 val = readw(kbd->io_base + MODE_REG); 139 val = readl_relaxed(kbd->io_base + MODE_CTL_REG);
135 val &= ~START_SCAN; 140 val &= ~MODE_CTL_START_SCAN;
136 writew(val, kbd->io_base + MODE_REG); 141 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
137 142
138 clk_disable(kbd->clk); 143 clk_disable(kbd->clk);
139 144
@@ -146,7 +151,7 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev,
146{ 151{
147 struct device_node *np = pdev->dev.of_node; 152 struct device_node *np = pdev->dev.of_node;
148 int error; 153 int error;
149 u32 val; 154 u32 val, suspended_rate;
150 155
151 if (!np) { 156 if (!np) {
152 dev_err(&pdev->dev, "Missing DT data\n"); 157 dev_err(&pdev->dev, "Missing DT data\n");
@@ -156,6 +161,9 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev,
156 if (of_property_read_bool(np, "autorepeat")) 161 if (of_property_read_bool(np, "autorepeat"))
157 kbd->rep = true; 162 kbd->rep = true;
158 163
164 if (of_property_read_u32(np, "suspended_rate", &suspended_rate))
165 kbd->suspended_rate = suspended_rate;
166
159 error = of_property_read_u32(np, "st,mode", &val); 167 error = of_property_read_u32(np, "st,mode", &val);
160 if (error) { 168 if (error) {
161 dev_err(&pdev->dev, "DT: Invalid or missing mode\n"); 169 dev_err(&pdev->dev, "DT: Invalid or missing mode\n");
@@ -213,6 +221,7 @@ static int __devinit spear_kbd_probe(struct platform_device *pdev)
213 } else { 221 } else {
214 kbd->mode = pdata->mode; 222 kbd->mode = pdata->mode;
215 kbd->rep = pdata->rep; 223 kbd->rep = pdata->rep;
224 kbd->suspended_rate = pdata->suspended_rate;
216 } 225 }
217 226
218 kbd->res = request_mem_region(res->start, resource_size(res), 227 kbd->res = request_mem_region(res->start, resource_size(res),
@@ -302,7 +311,7 @@ static int __devexit spear_kbd_remove(struct platform_device *pdev)
302 release_mem_region(kbd->res->start, resource_size(kbd->res)); 311 release_mem_region(kbd->res->start, resource_size(kbd->res));
303 kfree(kbd); 312 kfree(kbd);
304 313
305 device_init_wakeup(&pdev->dev, 1); 314 device_init_wakeup(&pdev->dev, 0);
306 platform_set_drvdata(pdev, NULL); 315 platform_set_drvdata(pdev, NULL);
307 316
308 return 0; 317 return 0;
@@ -314,15 +323,48 @@ static int spear_kbd_suspend(struct device *dev)
314 struct platform_device *pdev = to_platform_device(dev); 323 struct platform_device *pdev = to_platform_device(dev);
315 struct spear_kbd *kbd = platform_get_drvdata(pdev); 324 struct spear_kbd *kbd = platform_get_drvdata(pdev);
316 struct input_dev *input_dev = kbd->input; 325 struct input_dev *input_dev = kbd->input;
326 unsigned int rate = 0, mode_ctl_reg, val;
317 327
318 mutex_lock(&input_dev->mutex); 328 mutex_lock(&input_dev->mutex);
319 329
320 if (input_dev->users) 330 /* explicitly enable clock as we may program device */
321 clk_enable(kbd->clk); 331 clk_enable(kbd->clk);
322 332
323 if (device_may_wakeup(&pdev->dev)) 333 mode_ctl_reg = readl_relaxed(kbd->io_base + MODE_CTL_REG);
334
335 if (device_may_wakeup(&pdev->dev)) {
324 enable_irq_wake(kbd->irq); 336 enable_irq_wake(kbd->irq);
325 337
338 /*
339 * reprogram the keyboard operating frequency as on some
340 * platform it may change during system suspended
341 */
342 if (kbd->suspended_rate)
343 rate = kbd->suspended_rate / 1000000 - 1;
344 else
345 rate = clk_get_rate(kbd->clk) / 1000000 - 1;
346
347 val = mode_ctl_reg &
348 ~(MODE_CTL_PCLK_FREQ_MSK << MODE_CTL_PCLK_FREQ_SHIFT);
349 val |= (rate & MODE_CTL_PCLK_FREQ_MSK)
350 << MODE_CTL_PCLK_FREQ_SHIFT;
351 writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
352
353 } else {
354 if (input_dev->users) {
355 writel_relaxed(mode_ctl_reg & ~MODE_CTL_START_SCAN,
356 kbd->io_base + MODE_CTL_REG);
357 clk_disable(kbd->clk);
358 }
359 }
360
361 /* store current configuration */
362 if (input_dev->users)
363 kbd->mode_ctl_reg = mode_ctl_reg;
364
365 /* restore previous clk state */
366 clk_disable(kbd->clk);
367
326 mutex_unlock(&input_dev->mutex); 368 mutex_unlock(&input_dev->mutex);
327 369
328 return 0; 370 return 0;
@@ -336,11 +378,16 @@ static int spear_kbd_resume(struct device *dev)
336 378
337 mutex_lock(&input_dev->mutex); 379 mutex_lock(&input_dev->mutex);
338 380
339 if (device_may_wakeup(&pdev->dev)) 381 if (device_may_wakeup(&pdev->dev)) {
340 disable_irq_wake(kbd->irq); 382 disable_irq_wake(kbd->irq);
383 } else {
384 if (input_dev->users)
385 clk_enable(kbd->clk);
386 }
341 387
388 /* restore current configuration */
342 if (input_dev->users) 389 if (input_dev->users)
343 clk_enable(kbd->clk); 390 writel_relaxed(kbd->mode_ctl_reg, kbd->io_base + MODE_CTL_REG);
344 391
345 mutex_unlock(&input_dev->mutex); 392 mutex_unlock(&input_dev->mutex);
346 393
diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c
index 350fd0c385d2..84ec691c05aa 100644
--- a/drivers/input/misc/ab8500-ponkey.c
+++ b/drivers/input/misc/ab8500-ponkey.c
@@ -13,6 +13,7 @@
13#include <linux/input.h> 13#include <linux/input.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/mfd/abx500/ab8500.h> 15#include <linux/mfd/abx500/ab8500.h>
16#include <linux/of.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17 18
18/** 19/**
@@ -131,10 +132,18 @@ static int __devexit ab8500_ponkey_remove(struct platform_device *pdev)
131 return 0; 132 return 0;
132} 133}
133 134
135#ifdef CONFIG_OF
136static const struct of_device_id ab8500_ponkey_match[] = {
137 { .compatible = "stericsson,ab8500-ponkey", },
138 {}
139};
140#endif
141
134static struct platform_driver ab8500_ponkey_driver = { 142static struct platform_driver ab8500_ponkey_driver = {
135 .driver = { 143 .driver = {
136 .name = "ab8500-poweron-key", 144 .name = "ab8500-poweron-key",
137 .owner = THIS_MODULE, 145 .owner = THIS_MODULE,
146 .of_match_table = of_match_ptr(ab8500_ponkey_match),
138 }, 147 },
139 .probe = ab8500_ponkey_probe, 148 .probe = ab8500_ponkey_probe,
140 .remove = __devexit_p(ab8500_ponkey_remove), 149 .remove = __devexit_p(ab8500_ponkey_remove),
diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c
index c34f6c0371c4..c8a288ae1d5b 100644
--- a/drivers/input/misc/twl6040-vibra.c
+++ b/drivers/input/misc/twl6040-vibra.c
@@ -251,7 +251,6 @@ static int twl6040_vibra_suspend(struct device *dev)
251 251
252 return 0; 252 return 0;
253} 253}
254
255#endif 254#endif
256 255
257static SIMPLE_DEV_PM_OPS(twl6040_vibra_pm_ops, twl6040_vibra_suspend, NULL); 256static SIMPLE_DEV_PM_OPS(twl6040_vibra_pm_ops, twl6040_vibra_suspend, NULL);
@@ -259,13 +258,19 @@ static SIMPLE_DEV_PM_OPS(twl6040_vibra_pm_ops, twl6040_vibra_suspend, NULL);
259static int __devinit twl6040_vibra_probe(struct platform_device *pdev) 258static int __devinit twl6040_vibra_probe(struct platform_device *pdev)
260{ 259{
261 struct twl6040_vibra_data *pdata = pdev->dev.platform_data; 260 struct twl6040_vibra_data *pdata = pdev->dev.platform_data;
262 struct device_node *node = pdev->dev.of_node; 261 struct device *twl6040_core_dev = pdev->dev.parent;
262 struct device_node *twl6040_core_node = NULL;
263 struct vibra_info *info; 263 struct vibra_info *info;
264 int vddvibl_uV = 0; 264 int vddvibl_uV = 0;
265 int vddvibr_uV = 0; 265 int vddvibr_uV = 0;
266 int ret; 266 int ret;
267 267
268 if (!pdata && !node) { 268#ifdef CONFIG_OF
269 twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node,
270 "vibra");
271#endif
272
273 if (!pdata && !twl6040_core_node) {
269 dev_err(&pdev->dev, "platform_data not available\n"); 274 dev_err(&pdev->dev, "platform_data not available\n");
270 return -EINVAL; 275 return -EINVAL;
271 } 276 }
@@ -287,14 +292,18 @@ static int __devinit twl6040_vibra_probe(struct platform_device *pdev)
287 vddvibl_uV = pdata->vddvibl_uV; 292 vddvibl_uV = pdata->vddvibl_uV;
288 vddvibr_uV = pdata->vddvibr_uV; 293 vddvibr_uV = pdata->vddvibr_uV;
289 } else { 294 } else {
290 of_property_read_u32(node, "vibldrv_res", &info->vibldrv_res); 295 of_property_read_u32(twl6040_core_node, "ti,vibldrv-res",
291 of_property_read_u32(node, "vibrdrv_res", &info->vibrdrv_res); 296 &info->vibldrv_res);
292 of_property_read_u32(node, "viblmotor_res", 297 of_property_read_u32(twl6040_core_node, "ti,vibrdrv-res",
298 &info->vibrdrv_res);
299 of_property_read_u32(twl6040_core_node, "ti,viblmotor-res",
293 &info->viblmotor_res); 300 &info->viblmotor_res);
294 of_property_read_u32(node, "vibrmotor_res", 301 of_property_read_u32(twl6040_core_node, "ti,vibrmotor-res",
295 &info->vibrmotor_res); 302 &info->vibrmotor_res);
296 of_property_read_u32(node, "vddvibl_uV", &vddvibl_uV); 303 of_property_read_u32(twl6040_core_node, "ti,vddvibl-uV",
297 of_property_read_u32(node, "vddvibr_uV", &vddvibr_uV); 304 &vddvibl_uV);
305 of_property_read_u32(twl6040_core_node, "ti,vddvibr-uV",
306 &vddvibr_uV);
298 } 307 }
299 308
300 if ((!info->vibldrv_res && !info->viblmotor_res) || 309 if ((!info->vibldrv_res && !info->viblmotor_res) ||
@@ -351,8 +360,12 @@ static int __devinit twl6040_vibra_probe(struct platform_device *pdev)
351 360
352 info->supplies[0].supply = "vddvibl"; 361 info->supplies[0].supply = "vddvibl";
353 info->supplies[1].supply = "vddvibr"; 362 info->supplies[1].supply = "vddvibr";
354 ret = regulator_bulk_get(info->dev, ARRAY_SIZE(info->supplies), 363 /*
355 info->supplies); 364 * When booted with Device tree the regulators are attached to the
365 * parent device (twl6040 MFD core)
366 */
367 ret = regulator_bulk_get(pdata ? info->dev : twl6040_core_dev,
368 ARRAY_SIZE(info->supplies), info->supplies);
356 if (ret) { 369 if (ret) {
357 dev_err(info->dev, "couldn't get regulators %d\n", ret); 370 dev_err(info->dev, "couldn't get regulators %d\n", ret);
358 goto err_regulator; 371 goto err_regulator;
@@ -418,12 +431,6 @@ static int __devexit twl6040_vibra_remove(struct platform_device *pdev)
418 return 0; 431 return 0;
419} 432}
420 433
421static const struct of_device_id twl6040_vibra_of_match[] = {
422 {.compatible = "ti,twl6040-vibra", },
423 { },
424};
425MODULE_DEVICE_TABLE(of, twl6040_vibra_of_match);
426
427static struct platform_driver twl6040_vibra_driver = { 434static struct platform_driver twl6040_vibra_driver = {
428 .probe = twl6040_vibra_probe, 435 .probe = twl6040_vibra_probe,
429 .remove = __devexit_p(twl6040_vibra_remove), 436 .remove = __devexit_p(twl6040_vibra_remove),
@@ -431,7 +438,6 @@ static struct platform_driver twl6040_vibra_driver = {
431 .name = "twl6040-vibra", 438 .name = "twl6040-vibra",
432 .owner = THIS_MODULE, 439 .owner = THIS_MODULE,
433 .pm = &twl6040_vibra_pm_ops, 440 .pm = &twl6040_vibra_pm_ops,
434 .of_match_table = twl6040_vibra_of_match,
435 }, 441 },
436}; 442};
437module_platform_driver(twl6040_vibra_driver); 443module_platform_driver(twl6040_vibra_driver);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index c703d53be3a0..d5b390f75c9a 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -139,6 +139,35 @@ static int synaptics_model_id(struct psmouse *psmouse)
139} 139}
140 140
141/* 141/*
142 * Read the board id from the touchpad
143 * The board id is encoded in the "QUERY MODES" response
144 */
145static int synaptics_board_id(struct psmouse *psmouse)
146{
147 struct synaptics_data *priv = psmouse->private;
148 unsigned char bid[3];
149
150 if (synaptics_send_cmd(psmouse, SYN_QUE_MODES, bid))
151 return -1;
152 priv->board_id = ((bid[0] & 0xfc) << 6) | bid[1];
153 return 0;
154}
155
156/*
157 * Read the firmware id from the touchpad
158 */
159static int synaptics_firmware_id(struct psmouse *psmouse)
160{
161 struct synaptics_data *priv = psmouse->private;
162 unsigned char fwid[3];
163
164 if (synaptics_send_cmd(psmouse, SYN_QUE_FIRMWARE_ID, fwid))
165 return -1;
166 priv->firmware_id = (fwid[0] << 16) | (fwid[1] << 8) | fwid[2];
167 return 0;
168}
169
170/*
142 * Read the capability-bits from the touchpad 171 * Read the capability-bits from the touchpad
143 * see also the SYN_CAP_* macros 172 * see also the SYN_CAP_* macros
144 */ 173 */
@@ -261,6 +290,10 @@ static int synaptics_query_hardware(struct psmouse *psmouse)
261 return -1; 290 return -1;
262 if (synaptics_model_id(psmouse)) 291 if (synaptics_model_id(psmouse))
263 return -1; 292 return -1;
293 if (synaptics_firmware_id(psmouse))
294 return -1;
295 if (synaptics_board_id(psmouse))
296 return -1;
264 if (synaptics_capability(psmouse)) 297 if (synaptics_capability(psmouse))
265 return -1; 298 return -1;
266 if (synaptics_resolution(psmouse)) 299 if (synaptics_resolution(psmouse))
@@ -1435,11 +1468,12 @@ static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
1435 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS; 1468 priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS;
1436 1469
1437 psmouse_info(psmouse, 1470 psmouse_info(psmouse,
1438 "Touchpad model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n", 1471 "Touchpad model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx, board id: %lu, fw id: %lu\n",
1439 SYN_ID_MODEL(priv->identity), 1472 SYN_ID_MODEL(priv->identity),
1440 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), 1473 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
1441 priv->model_id, 1474 priv->model_id,
1442 priv->capabilities, priv->ext_cap, priv->ext_cap_0c); 1475 priv->capabilities, priv->ext_cap, priv->ext_cap_0c,
1476 priv->board_id, priv->firmware_id);
1443 1477
1444 set_input_params(psmouse->dev, priv); 1478 set_input_params(psmouse->dev, priv);
1445 1479
diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h
index fd26ccca13d7..e594af0b264b 100644
--- a/drivers/input/mouse/synaptics.h
+++ b/drivers/input/mouse/synaptics.h
@@ -18,6 +18,7 @@
18#define SYN_QUE_SERIAL_NUMBER_SUFFIX 0x07 18#define SYN_QUE_SERIAL_NUMBER_SUFFIX 0x07
19#define SYN_QUE_RESOLUTION 0x08 19#define SYN_QUE_RESOLUTION 0x08
20#define SYN_QUE_EXT_CAPAB 0x09 20#define SYN_QUE_EXT_CAPAB 0x09
21#define SYN_QUE_FIRMWARE_ID 0x0a
21#define SYN_QUE_EXT_CAPAB_0C 0x0c 22#define SYN_QUE_EXT_CAPAB_0C 0x0c
22#define SYN_QUE_EXT_MAX_COORDS 0x0d 23#define SYN_QUE_EXT_MAX_COORDS 0x0d
23#define SYN_QUE_EXT_MIN_COORDS 0x0f 24#define SYN_QUE_EXT_MIN_COORDS 0x0f
@@ -148,6 +149,8 @@ struct synaptics_hw_state {
148struct synaptics_data { 149struct synaptics_data {
149 /* Data read from the touchpad */ 150 /* Data read from the touchpad */
150 unsigned long int model_id; /* Model-ID */ 151 unsigned long int model_id; /* Model-ID */
152 unsigned long int firmware_id; /* Firmware-ID */
153 unsigned long int board_id; /* Board-ID */
151 unsigned long int capabilities; /* Capabilities */ 154 unsigned long int capabilities; /* Capabilities */
152 unsigned long int ext_cap; /* Extended Capabilities */ 155 unsigned long int ext_cap; /* Extended Capabilities */
153 unsigned long int ext_cap_0c; /* Ext Caps from 0x0c query */ 156 unsigned long int ext_cap_0c; /* Ext Caps from 0x0c query */
diff --git a/drivers/input/mouse/synaptics_usb.c b/drivers/input/mouse/synaptics_usb.c
index 3c5eaaa5d154..64cf34ea7604 100644
--- a/drivers/input/mouse/synaptics_usb.c
+++ b/drivers/input/mouse/synaptics_usb.c
@@ -364,7 +364,7 @@ static int synusb_probe(struct usb_interface *intf,
364 le16_to_cpu(udev->descriptor.idProduct)); 364 le16_to_cpu(udev->descriptor.idProduct));
365 365
366 if (synusb->flags & SYNUSB_STICK) 366 if (synusb->flags & SYNUSB_STICK)
367 strlcat(synusb->name, " (Stick) ", sizeof(synusb->name)); 367 strlcat(synusb->name, " (Stick)", sizeof(synusb->name));
368 368
369 usb_make_path(udev, synusb->phys, sizeof(synusb->phys)); 369 usb_make_path(udev, synusb->phys, sizeof(synusb->phys));
370 strlcat(synusb->phys, "/input0", sizeof(synusb->phys)); 370 strlcat(synusb->phys, "/input0", sizeof(synusb->phys));
diff --git a/drivers/input/tablet/hanwang.c b/drivers/input/tablet/hanwang.c
index b2db3cfe3084..5cc04124995c 100644
--- a/drivers/input/tablet/hanwang.c
+++ b/drivers/input/tablet/hanwang.c
@@ -63,6 +63,7 @@ MODULE_LICENSE(DRIVER_LICENSE);
63enum hanwang_tablet_type { 63enum hanwang_tablet_type {
64 HANWANG_ART_MASTER_III, 64 HANWANG_ART_MASTER_III,
65 HANWANG_ART_MASTER_HD, 65 HANWANG_ART_MASTER_HD,
66 HANWANG_ART_MASTER_II,
66}; 67};
67 68
68struct hanwang { 69struct hanwang {
@@ -99,6 +100,8 @@ static const struct hanwang_features features_array[] = {
99 ART_MASTER_PKGLEN_MAX, 0x7f00, 0x4f60, 0x3f, 0x7f, 2048 }, 100 ART_MASTER_PKGLEN_MAX, 0x7f00, 0x4f60, 0x3f, 0x7f, 2048 },
100 { 0x8401, "Hanwang Art Master HD 5012", HANWANG_ART_MASTER_HD, 101 { 0x8401, "Hanwang Art Master HD 5012", HANWANG_ART_MASTER_HD,
101 ART_MASTER_PKGLEN_MAX, 0x678e, 0x4150, 0x3f, 0x7f, 1024 }, 102 ART_MASTER_PKGLEN_MAX, 0x678e, 0x4150, 0x3f, 0x7f, 1024 },
103 { 0x8503, "Hanwang Art Master II", HANWANG_ART_MASTER_II,
104 ART_MASTER_PKGLEN_MAX, 0x27de, 0x1cfe, 0x3f, 0x7f, 1024 },
102}; 105};
103 106
104static const int hw_eventtypes[] = { 107static const int hw_eventtypes[] = {
@@ -127,14 +130,30 @@ static void hanwang_parse_packet(struct hanwang *hanwang)
127 struct usb_device *dev = hanwang->usbdev; 130 struct usb_device *dev = hanwang->usbdev;
128 enum hanwang_tablet_type type = hanwang->features->type; 131 enum hanwang_tablet_type type = hanwang->features->type;
129 int i; 132 int i;
130 u16 x, y, p; 133 u16 p;
134
135 if (type == HANWANG_ART_MASTER_II) {
136 hanwang->current_tool = BTN_TOOL_PEN;
137 hanwang->current_id = STYLUS_DEVICE_ID;
138 }
131 139
132 switch (data[0]) { 140 switch (data[0]) {
133 case 0x02: /* data packet */ 141 case 0x02: /* data packet */
134 switch (data[1]) { 142 switch (data[1]) {
135 case 0x80: /* tool prox out */ 143 case 0x80: /* tool prox out */
136 hanwang->current_id = 0; 144 if (type != HANWANG_ART_MASTER_II) {
137 input_report_key(input_dev, hanwang->current_tool, 0); 145 hanwang->current_id = 0;
146 input_report_key(input_dev,
147 hanwang->current_tool, 0);
148 }
149 break;
150
151 case 0x00: /* artmaster ii pen leave */
152 if (type == HANWANG_ART_MASTER_II) {
153 hanwang->current_id = 0;
154 input_report_key(input_dev,
155 hanwang->current_tool, 0);
156 }
138 break; 157 break;
139 158
140 case 0xc2: /* first time tool prox in */ 159 case 0xc2: /* first time tool prox in */
@@ -154,15 +173,12 @@ static void hanwang_parse_packet(struct hanwang *hanwang)
154 default: 173 default:
155 hanwang->current_id = 0; 174 hanwang->current_id = 0;
156 dev_dbg(&dev->dev, 175 dev_dbg(&dev->dev,
157 "unknown tablet tool %02x ", data[0]); 176 "unknown tablet tool %02x\n", data[0]);
158 break; 177 break;
159 } 178 }
160 break; 179 break;
161 180
162 default: /* tool data packet */ 181 default: /* tool data packet */
163 x = (data[2] << 8) | data[3];
164 y = (data[4] << 8) | data[5];
165
166 switch (type) { 182 switch (type) {
167 case HANWANG_ART_MASTER_III: 183 case HANWANG_ART_MASTER_III:
168 p = (data[6] << 3) | 184 p = (data[6] << 3) |
@@ -171,6 +187,7 @@ static void hanwang_parse_packet(struct hanwang *hanwang)
171 break; 187 break;
172 188
173 case HANWANG_ART_MASTER_HD: 189 case HANWANG_ART_MASTER_HD:
190 case HANWANG_ART_MASTER_II:
174 p = (data[7] >> 6) | (data[6] << 2); 191 p = (data[7] >> 6) | (data[6] << 2);
175 break; 192 break;
176 193
@@ -180,17 +197,23 @@ static void hanwang_parse_packet(struct hanwang *hanwang)
180 } 197 }
181 198
182 input_report_abs(input_dev, ABS_X, 199 input_report_abs(input_dev, ABS_X,
183 le16_to_cpup((__le16 *)&x)); 200 be16_to_cpup((__be16 *)&data[2]));
184 input_report_abs(input_dev, ABS_Y, 201 input_report_abs(input_dev, ABS_Y,
185 le16_to_cpup((__le16 *)&y)); 202 be16_to_cpup((__be16 *)&data[4]));
186 input_report_abs(input_dev, ABS_PRESSURE, 203 input_report_abs(input_dev, ABS_PRESSURE, p);
187 le16_to_cpup((__le16 *)&p));
188 input_report_abs(input_dev, ABS_TILT_X, data[7] & 0x3f); 204 input_report_abs(input_dev, ABS_TILT_X, data[7] & 0x3f);
189 input_report_abs(input_dev, ABS_TILT_Y, data[8] & 0x7f); 205 input_report_abs(input_dev, ABS_TILT_Y, data[8] & 0x7f);
190 input_report_key(input_dev, BTN_STYLUS, data[1] & 0x02); 206 input_report_key(input_dev, BTN_STYLUS, data[1] & 0x02);
191 input_report_key(input_dev, BTN_STYLUS2, data[1] & 0x04); 207
208 if (type != HANWANG_ART_MASTER_II)
209 input_report_key(input_dev, BTN_STYLUS2,
210 data[1] & 0x04);
211 else
212 input_report_key(input_dev, BTN_TOOL_PEN, 1);
213
192 break; 214 break;
193 } 215 }
216
194 input_report_abs(input_dev, ABS_MISC, hanwang->current_id); 217 input_report_abs(input_dev, ABS_MISC, hanwang->current_id);
195 input_event(input_dev, EV_MSC, MSC_SERIAL, 218 input_event(input_dev, EV_MSC, MSC_SERIAL,
196 hanwang->features->pid); 219 hanwang->features->pid);
@@ -202,8 +225,8 @@ static void hanwang_parse_packet(struct hanwang *hanwang)
202 225
203 switch (type) { 226 switch (type) {
204 case HANWANG_ART_MASTER_III: 227 case HANWANG_ART_MASTER_III:
205 input_report_key(input_dev, BTN_TOOL_FINGER, data[1] || 228 input_report_key(input_dev, BTN_TOOL_FINGER,
206 data[2] || data[3]); 229 data[1] || data[2] || data[3]);
207 input_report_abs(input_dev, ABS_WHEEL, data[1]); 230 input_report_abs(input_dev, ABS_WHEEL, data[1]);
208 input_report_key(input_dev, BTN_0, data[2]); 231 input_report_key(input_dev, BTN_0, data[2]);
209 for (i = 0; i < 8; i++) 232 for (i = 0; i < 8; i++)
@@ -227,6 +250,10 @@ static void hanwang_parse_packet(struct hanwang *hanwang)
227 BTN_5 + i, data[6] & (1 << i)); 250 BTN_5 + i, data[6] & (1 << i));
228 } 251 }
229 break; 252 break;
253
254 case HANWANG_ART_MASTER_II:
255 dev_dbg(&dev->dev, "error packet %02x\n", data[0]);
256 return;
230 } 257 }
231 258
232 input_report_abs(input_dev, ABS_MISC, hanwang->current_id); 259 input_report_abs(input_dev, ABS_MISC, hanwang->current_id);
@@ -234,7 +261,7 @@ static void hanwang_parse_packet(struct hanwang *hanwang)
234 break; 261 break;
235 262
236 default: 263 default:
237 dev_dbg(&dev->dev, "error packet %02x ", data[0]); 264 dev_dbg(&dev->dev, "error packet %02x\n", data[0]);
238 break; 265 break;
239 } 266 }
240 267
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 8b31473a81fe..0d3219f29744 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -445,8 +445,7 @@ static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_feat
445 /* ask to report Wacom data */ 445 /* ask to report Wacom data */
446 if (features->device_type == BTN_TOOL_FINGER) { 446 if (features->device_type == BTN_TOOL_FINGER) {
447 /* if it is an MT Tablet PC touch */ 447 /* if it is an MT Tablet PC touch */
448 if (features->type == TABLETPC2FG || 448 if (features->type > TABLETPC) {
449 features->type == MTSCREEN) {
450 do { 449 do {
451 rep_data[0] = 3; 450 rep_data[0] = 3;
452 rep_data[1] = 4; 451 rep_data[1] = 4;
@@ -465,7 +464,7 @@ static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_feat
465 } while ((error < 0 || rep_data[1] != 4) && 464 } while ((error < 0 || rep_data[1] != 4) &&
466 limit++ < WAC_MSG_RETRIES); 465 limit++ < WAC_MSG_RETRIES);
467 } 466 }
468 } else if (features->type != TABLETPC && 467 } else if (features->type <= BAMBOO_PT &&
469 features->type != WIRELESS && 468 features->type != WIRELESS &&
470 features->device_type == BTN_TOOL_PEN) { 469 features->device_type == BTN_TOOL_PEN) {
471 do { 470 do {
@@ -509,16 +508,13 @@ static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
509 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { 508 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
510 features->device_type = 0; 509 features->device_type = 0;
511 } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) { 510 } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
512 features->device_type = BTN_TOOL_DOUBLETAP; 511 features->device_type = BTN_TOOL_FINGER;
513 features->pktlen = WACOM_PKGLEN_BBTOUCH3; 512 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
514 } 513 }
515 } 514 }
516 515
517 /* only devices that support touch need to retrieve the info */ 516 /* only devices that support touch need to retrieve the info */
518 if (features->type != TABLETPC && 517 if (features->type < BAMBOO_PT) {
519 features->type != TABLETPC2FG &&
520 features->type != BAMBOO_PT &&
521 features->type != MTSCREEN) {
522 goto out; 518 goto out;
523 } 519 }
524 520
@@ -860,6 +856,7 @@ static int wacom_initialize_leds(struct wacom *wacom)
860 856
861 /* Initialize default values */ 857 /* Initialize default values */
862 switch (wacom->wacom_wac.features.type) { 858 switch (wacom->wacom_wac.features.type) {
859 case INTUOS4S:
863 case INTUOS4: 860 case INTUOS4:
864 case INTUOS4L: 861 case INTUOS4L:
865 wacom->led.select[0] = 0; 862 wacom->led.select[0] = 0;
@@ -913,6 +910,7 @@ static int wacom_initialize_leds(struct wacom *wacom)
913static void wacom_destroy_leds(struct wacom *wacom) 910static void wacom_destroy_leds(struct wacom *wacom)
914{ 911{
915 switch (wacom->wacom_wac.features.type) { 912 switch (wacom->wacom_wac.features.type) {
913 case INTUOS4S:
916 case INTUOS4: 914 case INTUOS4:
917 case INTUOS4L: 915 case INTUOS4L:
918 sysfs_remove_group(&wacom->intf->dev.kobj, 916 sysfs_remove_group(&wacom->intf->dev.kobj,
@@ -972,6 +970,10 @@ static int wacom_initialize_battery(struct wacom *wacom)
972 970
973 error = power_supply_register(&wacom->usbdev->dev, 971 error = power_supply_register(&wacom->usbdev->dev,
974 &wacom->battery); 972 &wacom->battery);
973
974 if (!error)
975 power_supply_powers(&wacom->battery,
976 &wacom->usbdev->dev);
975 } 977 }
976 978
977 return error; 979 return error;
@@ -979,8 +981,11 @@ static int wacom_initialize_battery(struct wacom *wacom)
979 981
980static void wacom_destroy_battery(struct wacom *wacom) 982static void wacom_destroy_battery(struct wacom *wacom)
981{ 983{
982 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) 984 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR &&
985 wacom->battery.dev) {
983 power_supply_unregister(&wacom->battery); 986 power_supply_unregister(&wacom->battery);
987 wacom->battery.dev = NULL;
988 }
984} 989}
985 990
986static int wacom_register_input(struct wacom *wacom) 991static int wacom_register_input(struct wacom *wacom)
@@ -1027,23 +1032,30 @@ static void wacom_wireless_work(struct work_struct *work)
1027 struct wacom *wacom = container_of(work, struct wacom, work); 1032 struct wacom *wacom = container_of(work, struct wacom, work);
1028 struct usb_device *usbdev = wacom->usbdev; 1033 struct usb_device *usbdev = wacom->usbdev;
1029 struct wacom_wac *wacom_wac = &wacom->wacom_wac; 1034 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1035 struct wacom *wacom1, *wacom2;
1036 struct wacom_wac *wacom_wac1, *wacom_wac2;
1037 int error;
1030 1038
1031 /* 1039 /*
1032 * Regardless if this is a disconnect or a new tablet, 1040 * Regardless if this is a disconnect or a new tablet,
1033 * remove any existing input devices. 1041 * remove any existing input and battery devices.
1034 */ 1042 */
1035 1043
1044 wacom_destroy_battery(wacom);
1045
1036 /* Stylus interface */ 1046 /* Stylus interface */
1037 wacom = usb_get_intfdata(usbdev->config->interface[1]); 1047 wacom1 = usb_get_intfdata(usbdev->config->interface[1]);
1038 if (wacom->wacom_wac.input) 1048 wacom_wac1 = &(wacom1->wacom_wac);
1039 input_unregister_device(wacom->wacom_wac.input); 1049 if (wacom_wac1->input)
1040 wacom->wacom_wac.input = NULL; 1050 input_unregister_device(wacom_wac1->input);
1051 wacom_wac1->input = NULL;
1041 1052
1042 /* Touch interface */ 1053 /* Touch interface */
1043 wacom = usb_get_intfdata(usbdev->config->interface[2]); 1054 wacom2 = usb_get_intfdata(usbdev->config->interface[2]);
1044 if (wacom->wacom_wac.input) 1055 wacom_wac2 = &(wacom2->wacom_wac);
1045 input_unregister_device(wacom->wacom_wac.input); 1056 if (wacom_wac2->input)
1046 wacom->wacom_wac.input = NULL; 1057 input_unregister_device(wacom_wac2->input);
1058 wacom_wac2->input = NULL;
1047 1059
1048 if (wacom_wac->pid == 0) { 1060 if (wacom_wac->pid == 0) {
1049 dev_info(&wacom->intf->dev, "wireless tablet disconnected\n"); 1061 dev_info(&wacom->intf->dev, "wireless tablet disconnected\n");
@@ -1068,24 +1080,39 @@ static void wacom_wireless_work(struct work_struct *work)
1068 } 1080 }
1069 1081
1070 /* Stylus interface */ 1082 /* Stylus interface */
1071 wacom = usb_get_intfdata(usbdev->config->interface[1]); 1083 wacom_wac1->features =
1072 wacom_wac = &wacom->wacom_wac;
1073 wacom_wac->features =
1074 *((struct wacom_features *)id->driver_info); 1084 *((struct wacom_features *)id->driver_info);
1075 wacom_wac->features.device_type = BTN_TOOL_PEN; 1085 wacom_wac1->features.device_type = BTN_TOOL_PEN;
1076 wacom_register_input(wacom); 1086 error = wacom_register_input(wacom1);
1087 if (error)
1088 goto fail1;
1077 1089
1078 /* Touch interface */ 1090 /* Touch interface */
1079 wacom = usb_get_intfdata(usbdev->config->interface[2]); 1091 wacom_wac2->features =
1080 wacom_wac = &wacom->wacom_wac;
1081 wacom_wac->features =
1082 *((struct wacom_features *)id->driver_info); 1092 *((struct wacom_features *)id->driver_info);
1083 wacom_wac->features.pktlen = WACOM_PKGLEN_BBTOUCH3; 1093 wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
1084 wacom_wac->features.device_type = BTN_TOOL_FINGER; 1094 wacom_wac2->features.device_type = BTN_TOOL_FINGER;
1085 wacom_set_phy_from_res(&wacom_wac->features); 1095 wacom_set_phy_from_res(&wacom_wac2->features);
1086 wacom_wac->features.x_max = wacom_wac->features.y_max = 4096; 1096 wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
1087 wacom_register_input(wacom); 1097 error = wacom_register_input(wacom2);
1098 if (error)
1099 goto fail2;
1100
1101 error = wacom_initialize_battery(wacom);
1102 if (error)
1103 goto fail3;
1088 } 1104 }
1105
1106 return;
1107
1108fail3:
1109 input_unregister_device(wacom_wac2->input);
1110 wacom_wac2->input = NULL;
1111fail2:
1112 input_unregister_device(wacom_wac1->input);
1113 wacom_wac1->input = NULL;
1114fail1:
1115 return;
1089} 1116}
1090 1117
1091static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) 1118static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -1149,10 +1176,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
1149 features->device_type = BTN_TOOL_FINGER; 1176 features->device_type = BTN_TOOL_FINGER;
1150 features->pktlen = WACOM_PKGLEN_BBTOUCH3; 1177 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
1151 1178
1152 features->x_phy = 1179 wacom_set_phy_from_res(features);
1153 (features->x_max * 100) / features->x_resolution;
1154 features->y_phy =
1155 (features->y_max * 100) / features->y_resolution;
1156 1180
1157 features->x_max = 4096; 1181 features->x_max = 4096;
1158 features->y_max = 4096; 1182 features->y_max = 4096;
@@ -1188,14 +1212,10 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
1188 if (error) 1212 if (error)
1189 goto fail4; 1213 goto fail4;
1190 1214
1191 error = wacom_initialize_battery(wacom);
1192 if (error)
1193 goto fail5;
1194
1195 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { 1215 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
1196 error = wacom_register_input(wacom); 1216 error = wacom_register_input(wacom);
1197 if (error) 1217 if (error)
1198 goto fail6; 1218 goto fail5;
1199 } 1219 }
1200 1220
1201 /* Note that if query fails it is not a hard failure */ 1221 /* Note that if query fails it is not a hard failure */
@@ -1210,7 +1230,6 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
1210 1230
1211 return 0; 1231 return 0;
1212 1232
1213 fail6: wacom_destroy_battery(wacom);
1214 fail5: wacom_destroy_leds(wacom); 1233 fail5: wacom_destroy_leds(wacom);
1215 fail4: wacom_remove_shared_data(wacom_wac); 1234 fail4: wacom_remove_shared_data(wacom_wac);
1216 fail3: usb_free_urb(wacom->irq); 1235 fail3: usb_free_urb(wacom->irq);
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 004bc1bb1544..6533f44be5bd 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -248,7 +248,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom)
248 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2])); 248 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
249 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4])); 249 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
250 if (wacom->tool[0] != BTN_TOOL_MOUSE) { 250 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
251 input_report_abs(input, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8)); 251 input_report_abs(input, ABS_PRESSURE, data[6] | ((data[7] & 0x03) << 8));
252 input_report_key(input, BTN_TOUCH, data[1] & 0x01); 252 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
253 input_report_key(input, BTN_STYLUS, data[1] & 0x02); 253 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
254 input_report_key(input, BTN_STYLUS2, data[1] & 0x04); 254 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
@@ -888,7 +888,7 @@ static int wacom_tpc_single_touch(struct wacom_wac *wacom, size_t len)
888 prox = data[0] & 0x01; 888 prox = data[0] & 0x01;
889 x = get_unaligned_le16(&data[1]); 889 x = get_unaligned_le16(&data[1]);
890 y = get_unaligned_le16(&data[3]); 890 y = get_unaligned_le16(&data[3]);
891 } else { /* with capacity */ 891 } else {
892 prox = data[1] & 0x01; 892 prox = data[1] & 0x01;
893 x = le16_to_cpup((__le16 *)&data[2]); 893 x = le16_to_cpup((__le16 *)&data[2]);
894 y = le16_to_cpup((__le16 *)&data[4]); 894 y = le16_to_cpup((__le16 *)&data[4]);
@@ -961,6 +961,7 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
961 case WACOM_REPORT_TPC1FG: 961 case WACOM_REPORT_TPC1FG:
962 case WACOM_REPORT_TPCHID: 962 case WACOM_REPORT_TPCHID:
963 case WACOM_REPORT_TPCST: 963 case WACOM_REPORT_TPCST:
964 case WACOM_REPORT_TPC1FGE:
964 return wacom_tpc_single_touch(wacom, len); 965 return wacom_tpc_single_touch(wacom, len);
965 966
966 case WACOM_REPORT_TPCMT: 967 case WACOM_REPORT_TPCMT:
@@ -1244,6 +1245,7 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
1244 break; 1245 break;
1245 1246
1246 case TABLETPC: 1247 case TABLETPC:
1248 case TABLETPCE:
1247 case TABLETPC2FG: 1249 case TABLETPC2FG:
1248 case MTSCREEN: 1250 case MTSCREEN:
1249 sync = wacom_tpc_irq(wacom_wac, len); 1251 sync = wacom_tpc_irq(wacom_wac, len);
@@ -1317,10 +1319,8 @@ void wacom_setup_device_quirks(struct wacom_features *features)
1317 } 1319 }
1318 1320
1319 /* these device have multiple inputs */ 1321 /* these device have multiple inputs */
1320 if (features->type == TABLETPC || features->type == TABLETPC2FG || 1322 if (features->type >= WIRELESS ||
1321 features->type == BAMBOO_PT || features->type == WIRELESS || 1323 (features->type >= INTUOS5S && features->type <= INTUOS5L))
1322 (features->type >= INTUOS5S && features->type <= INTUOS5L) ||
1323 features->type == MTSCREEN)
1324 features->quirks |= WACOM_QUIRK_MULTI_INPUT; 1324 features->quirks |= WACOM_QUIRK_MULTI_INPUT;
1325 1325
1326 /* quirk for bamboo touch with 2 low res touches */ 1326 /* quirk for bamboo touch with 2 low res touches */
@@ -1547,10 +1547,8 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1547 __set_bit(INPUT_PROP_POINTER, input_dev->propbit); 1547 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
1548 break; 1548 break;
1549 1549
1550 case TABLETPC2FG:
1551 case MTSCREEN: 1550 case MTSCREEN:
1552 if (features->device_type == BTN_TOOL_FINGER) { 1551 if (features->device_type == BTN_TOOL_FINGER) {
1553
1554 wacom_wac->slots = kmalloc(features->touch_max * 1552 wacom_wac->slots = kmalloc(features->touch_max *
1555 sizeof(int), 1553 sizeof(int),
1556 GFP_KERNEL); 1554 GFP_KERNEL);
@@ -1559,7 +1557,11 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1559 1557
1560 for (i = 0; i < features->touch_max; i++) 1558 for (i = 0; i < features->touch_max; i++)
1561 wacom_wac->slots[i] = -1; 1559 wacom_wac->slots[i] = -1;
1560 }
1561 /* fall through */
1562 1562
1563 case TABLETPC2FG:
1564 if (features->device_type == BTN_TOOL_FINGER) {
1563 input_mt_init_slots(input_dev, features->touch_max); 1565 input_mt_init_slots(input_dev, features->touch_max);
1564 input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, 1566 input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE,
1565 0, MT_TOOL_MAX, 0, 0); 1567 0, MT_TOOL_MAX, 0, 0);
@@ -1571,6 +1573,7 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
1571 /* fall through */ 1573 /* fall through */
1572 1574
1573 case TABLETPC: 1575 case TABLETPC:
1576 case TABLETPCE:
1574 __clear_bit(ABS_MISC, input_dev->absbit); 1577 __clear_bit(ABS_MISC, input_dev->absbit);
1575 1578
1576 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit); 1579 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
@@ -1888,6 +1891,12 @@ static const struct wacom_features wacom_features_0xE6 =
1888static const struct wacom_features wacom_features_0xEC = 1891static const struct wacom_features wacom_features_0xEC =
1889 { "Wacom ISDv4 EC", WACOM_PKGLEN_GRAPHIRE, 25710, 14500, 255, 1892 { "Wacom ISDv4 EC", WACOM_PKGLEN_GRAPHIRE, 25710, 14500, 255,
1890 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 1893 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1894static const struct wacom_features wacom_features_0xED =
1895 { "Wacom ISDv4 ED", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
1896 0, TABLETPCE, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1897static const struct wacom_features wacom_features_0xEF =
1898 { "Wacom ISDv4 EF", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255,
1899 0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
1891static const struct wacom_features wacom_features_0x47 = 1900static const struct wacom_features wacom_features_0x47 =
1892 { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 1901 { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023,
1893 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 1902 31, INTUOS, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
@@ -2062,6 +2071,8 @@ const struct usb_device_id wacom_ids[] = {
2062 { USB_DEVICE_WACOM(0xE5) }, 2071 { USB_DEVICE_WACOM(0xE5) },
2063 { USB_DEVICE_WACOM(0xE6) }, 2072 { USB_DEVICE_WACOM(0xE6) },
2064 { USB_DEVICE_WACOM(0xEC) }, 2073 { USB_DEVICE_WACOM(0xEC) },
2074 { USB_DEVICE_WACOM(0xED) },
2075 { USB_DEVICE_WACOM(0xEF) },
2065 { USB_DEVICE_WACOM(0x47) }, 2076 { USB_DEVICE_WACOM(0x47) },
2066 { USB_DEVICE_WACOM(0xF4) }, 2077 { USB_DEVICE_WACOM(0xF4) },
2067 { USB_DEVICE_LENOVO(0x6004) }, 2078 { USB_DEVICE_LENOVO(0x6004) },
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h
index 78fbd3f42009..bd5d37b28714 100644
--- a/drivers/input/tablet/wacom_wac.h
+++ b/drivers/input/tablet/wacom_wac.h
@@ -48,6 +48,7 @@
48#define WACOM_REPORT_TPCMT 13 48#define WACOM_REPORT_TPCMT 13
49#define WACOM_REPORT_TPCHID 15 49#define WACOM_REPORT_TPCHID 15
50#define WACOM_REPORT_TPCST 16 50#define WACOM_REPORT_TPCST 16
51#define WACOM_REPORT_TPC1FGE 18
51 52
52/* device quirks */ 53/* device quirks */
53#define WACOM_QUIRK_MULTI_INPUT 0x0001 54#define WACOM_QUIRK_MULTI_INPUT 0x0001
@@ -62,8 +63,6 @@ enum {
62 PTU, 63 PTU,
63 PL, 64 PL,
64 DTU, 65 DTU,
65 BAMBOO_PT,
66 WIRELESS,
67 INTUOS, 66 INTUOS,
68 INTUOS3S, 67 INTUOS3S,
69 INTUOS3, 68 INTUOS3,
@@ -79,7 +78,10 @@ enum {
79 CINTIQ, 78 CINTIQ,
80 WACOM_BEE, 79 WACOM_BEE,
81 WACOM_MO, 80 WACOM_MO,
82 TABLETPC, 81 WIRELESS,
82 BAMBOO_PT,
83 TABLETPC, /* add new TPC below */
84 TABLETPCE,
83 TABLETPC2FG, 85 TABLETPC2FG,
84 MTSCREEN, 86 MTSCREEN,
85 MAX_TYPE 87 MAX_TYPE
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 98d263504eea..73bd2f6b82ec 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -369,6 +369,18 @@ config TOUCHSCREEN_MCS5000
369 To compile this driver as a module, choose M here: the 369 To compile this driver as a module, choose M here: the
370 module will be called mcs5000_ts. 370 module will be called mcs5000_ts.
371 371
372config TOUCHSCREEN_MMS114
373 tristate "MELFAS MMS114 touchscreen"
374 depends on I2C
375 help
376 Say Y here if you have the MELFAS MMS114 touchscreen controller
377 chip in your system.
378
379 If unsure, say N.
380
381 To compile this driver as a module, choose M here: the
382 module will be called mms114.
383
372config TOUCHSCREEN_MTOUCH 384config TOUCHSCREEN_MTOUCH
373 tristate "MicroTouch serial touchscreens" 385 tristate "MicroTouch serial touchscreens"
374 select SERIO 386 select SERIO
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index eb8bfe1c1a46..5920c60f999d 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o
38obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o 38obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o
39obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o 39obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o
40obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o 40obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
41obj-$(CONFIG_TOUCHSCREEN_MMS114) += mms114.o
41obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o 42obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
42obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o 43obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
43obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o 44obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index bd4eb4277697..facd3057b62d 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -118,6 +118,7 @@ struct ad7879 {
118 unsigned int irq; 118 unsigned int irq;
119 bool disabled; /* P: input->mutex */ 119 bool disabled; /* P: input->mutex */
120 bool suspended; /* P: input->mutex */ 120 bool suspended; /* P: input->mutex */
121 bool swap_xy;
121 u16 conversion_data[AD7879_NR_SENSE]; 122 u16 conversion_data[AD7879_NR_SENSE];
122 char phys[32]; 123 char phys[32];
123 u8 first_conversion_delay; 124 u8 first_conversion_delay;
@@ -161,6 +162,9 @@ static int ad7879_report(struct ad7879 *ts)
161 z1 = ts->conversion_data[AD7879_SEQ_Z1] & MAX_12BIT; 162 z1 = ts->conversion_data[AD7879_SEQ_Z1] & MAX_12BIT;
162 z2 = ts->conversion_data[AD7879_SEQ_Z2] & MAX_12BIT; 163 z2 = ts->conversion_data[AD7879_SEQ_Z2] & MAX_12BIT;
163 164
165 if (ts->swap_xy)
166 swap(x, y);
167
164 /* 168 /*
165 * The samples processed here are already preprocessed by the AD7879. 169 * The samples processed here are already preprocessed by the AD7879.
166 * The preprocessing function consists of a median and an averaging 170 * The preprocessing function consists of a median and an averaging
@@ -520,6 +524,7 @@ struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq,
520 ts->dev = dev; 524 ts->dev = dev;
521 ts->input = input_dev; 525 ts->input = input_dev;
522 ts->irq = irq; 526 ts->irq = irq;
527 ts->swap_xy = pdata->swap_xy;
523 528
524 setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts); 529 setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts);
525 530
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 25fd0561a17d..4623cc69fc60 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -36,6 +36,7 @@
36#define MXT_FW_NAME "maxtouch.fw" 36#define MXT_FW_NAME "maxtouch.fw"
37 37
38/* Registers */ 38/* Registers */
39#define MXT_INFO 0x00
39#define MXT_FAMILY_ID 0x00 40#define MXT_FAMILY_ID 0x00
40#define MXT_VARIANT_ID 0x01 41#define MXT_VARIANT_ID 0x01
41#define MXT_VERSION 0x02 42#define MXT_VERSION 0x02
@@ -194,6 +195,7 @@
194#define MXT_BOOT_STATUS_MASK 0x3f 195#define MXT_BOOT_STATUS_MASK 0x3f
195 196
196/* Touch status */ 197/* Touch status */
198#define MXT_UNGRIP (1 << 0)
197#define MXT_SUPPRESS (1 << 1) 199#define MXT_SUPPRESS (1 << 1)
198#define MXT_AMP (1 << 2) 200#define MXT_AMP (1 << 2)
199#define MXT_VECTOR (1 << 3) 201#define MXT_VECTOR (1 << 3)
@@ -210,8 +212,6 @@
210/* Touchscreen absolute values */ 212/* Touchscreen absolute values */
211#define MXT_MAX_AREA 0xff 213#define MXT_MAX_AREA 0xff
212 214
213#define MXT_MAX_FINGER 10
214
215struct mxt_info { 215struct mxt_info {
216 u8 family_id; 216 u8 family_id;
217 u8 variant_id; 217 u8 variant_id;
@@ -225,44 +225,37 @@ struct mxt_info {
225struct mxt_object { 225struct mxt_object {
226 u8 type; 226 u8 type;
227 u16 start_address; 227 u16 start_address;
228 u8 size; 228 u8 size; /* Size of each instance - 1 */
229 u8 instances; 229 u8 instances; /* Number of instances - 1 */
230 u8 num_report_ids; 230 u8 num_report_ids;
231 231} __packed;
232 /* to map object and message */
233 u8 max_reportid;
234};
235 232
236struct mxt_message { 233struct mxt_message {
237 u8 reportid; 234 u8 reportid;
238 u8 message[7]; 235 u8 message[7];
239}; 236};
240 237
241struct mxt_finger {
242 int status;
243 int x;
244 int y;
245 int area;
246 int pressure;
247};
248
249/* Each client has this additional data */ 238/* Each client has this additional data */
250struct mxt_data { 239struct mxt_data {
251 struct i2c_client *client; 240 struct i2c_client *client;
252 struct input_dev *input_dev; 241 struct input_dev *input_dev;
242 char phys[64]; /* device physical location */
253 const struct mxt_platform_data *pdata; 243 const struct mxt_platform_data *pdata;
254 struct mxt_object *object_table; 244 struct mxt_object *object_table;
255 struct mxt_info info; 245 struct mxt_info info;
256 struct mxt_finger finger[MXT_MAX_FINGER];
257 unsigned int irq; 246 unsigned int irq;
258 unsigned int max_x; 247 unsigned int max_x;
259 unsigned int max_y; 248 unsigned int max_y;
249
250 /* Cached parameters from object table */
251 u8 T6_reportid;
252 u8 T9_reportid_min;
253 u8 T9_reportid_max;
260}; 254};
261 255
262static bool mxt_object_readable(unsigned int type) 256static bool mxt_object_readable(unsigned int type)
263{ 257{
264 switch (type) { 258 switch (type) {
265 case MXT_GEN_MESSAGE_T5:
266 case MXT_GEN_COMMAND_T6: 259 case MXT_GEN_COMMAND_T6:
267 case MXT_GEN_POWER_T7: 260 case MXT_GEN_POWER_T7:
268 case MXT_GEN_ACQUIRE_T8: 261 case MXT_GEN_ACQUIRE_T8:
@@ -396,6 +389,7 @@ static int __mxt_read_reg(struct i2c_client *client,
396{ 389{
397 struct i2c_msg xfer[2]; 390 struct i2c_msg xfer[2];
398 u8 buf[2]; 391 u8 buf[2];
392 int ret;
399 393
400 buf[0] = reg & 0xff; 394 buf[0] = reg & 0xff;
401 buf[1] = (reg >> 8) & 0xff; 395 buf[1] = (reg >> 8) & 0xff;
@@ -412,12 +406,17 @@ static int __mxt_read_reg(struct i2c_client *client,
412 xfer[1].len = len; 406 xfer[1].len = len;
413 xfer[1].buf = val; 407 xfer[1].buf = val;
414 408
415 if (i2c_transfer(client->adapter, xfer, 2) != 2) { 409 ret = i2c_transfer(client->adapter, xfer, 2);
416 dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); 410 if (ret == 2) {
417 return -EIO; 411 ret = 0;
412 } else {
413 if (ret >= 0)
414 ret = -EIO;
415 dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
416 __func__, ret);
418 } 417 }
419 418
420 return 0; 419 return ret;
421} 420}
422 421
423static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val) 422static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
@@ -425,27 +424,39 @@ static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val)
425 return __mxt_read_reg(client, reg, 1, val); 424 return __mxt_read_reg(client, reg, 1, val);
426} 425}
427 426
428static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) 427static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
428 const void *val)
429{ 429{
430 u8 buf[3]; 430 u8 *buf;
431 size_t count;
432 int ret;
433
434 count = len + 2;
435 buf = kmalloc(count, GFP_KERNEL);
436 if (!buf)
437 return -ENOMEM;
431 438
432 buf[0] = reg & 0xff; 439 buf[0] = reg & 0xff;
433 buf[1] = (reg >> 8) & 0xff; 440 buf[1] = (reg >> 8) & 0xff;
434 buf[2] = val; 441 memcpy(&buf[2], val, len);
435 442
436 if (i2c_master_send(client, buf, 3) != 3) { 443 ret = i2c_master_send(client, buf, count);
437 dev_err(&client->dev, "%s: i2c send failed\n", __func__); 444 if (ret == count) {
438 return -EIO; 445 ret = 0;
446 } else {
447 if (ret >= 0)
448 ret = -EIO;
449 dev_err(&client->dev, "%s: i2c send failed (%d)\n",
450 __func__, ret);
439 } 451 }
440 452
441 return 0; 453 kfree(buf);
454 return ret;
442} 455}
443 456
444static int mxt_read_object_table(struct i2c_client *client, 457static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
445 u16 reg, u8 *object_buf)
446{ 458{
447 return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, 459 return __mxt_write_reg(client, reg, 1, &val);
448 object_buf);
449} 460}
450 461
451static struct mxt_object * 462static struct mxt_object *
@@ -479,20 +490,6 @@ static int mxt_read_message(struct mxt_data *data,
479 sizeof(struct mxt_message), message); 490 sizeof(struct mxt_message), message);
480} 491}
481 492
482static int mxt_read_object(struct mxt_data *data,
483 u8 type, u8 offset, u8 *val)
484{
485 struct mxt_object *object;
486 u16 reg;
487
488 object = mxt_get_object(data, type);
489 if (!object)
490 return -EINVAL;
491
492 reg = object->start_address;
493 return __mxt_read_reg(data->client, reg + offset, 1, val);
494}
495
496static int mxt_write_object(struct mxt_data *data, 493static int mxt_write_object(struct mxt_data *data,
497 u8 type, u8 offset, u8 val) 494 u8 type, u8 offset, u8 val)
498{ 495{
@@ -507,75 +504,17 @@ static int mxt_write_object(struct mxt_data *data,
507 return mxt_write_reg(data->client, reg + offset, val); 504 return mxt_write_reg(data->client, reg + offset, val);
508} 505}
509 506
510static void mxt_input_report(struct mxt_data *data, int single_id)
511{
512 struct mxt_finger *finger = data->finger;
513 struct input_dev *input_dev = data->input_dev;
514 int status = finger[single_id].status;
515 int finger_num = 0;
516 int id;
517
518 for (id = 0; id < MXT_MAX_FINGER; id++) {
519 if (!finger[id].status)
520 continue;
521
522 input_mt_slot(input_dev, id);
523 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
524 finger[id].status != MXT_RELEASE);
525
526 if (finger[id].status != MXT_RELEASE) {
527 finger_num++;
528 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,
529 finger[id].area);
530 input_report_abs(input_dev, ABS_MT_POSITION_X,
531 finger[id].x);
532 input_report_abs(input_dev, ABS_MT_POSITION_Y,
533 finger[id].y);
534 input_report_abs(input_dev, ABS_MT_PRESSURE,
535 finger[id].pressure);
536 } else {
537 finger[id].status = 0;
538 }
539 }
540
541 input_report_key(input_dev, BTN_TOUCH, finger_num > 0);
542
543 if (status != MXT_RELEASE) {
544 input_report_abs(input_dev, ABS_X, finger[single_id].x);
545 input_report_abs(input_dev, ABS_Y, finger[single_id].y);
546 input_report_abs(input_dev,
547 ABS_PRESSURE, finger[single_id].pressure);
548 }
549
550 input_sync(input_dev);
551}
552
553static void mxt_input_touchevent(struct mxt_data *data, 507static void mxt_input_touchevent(struct mxt_data *data,
554 struct mxt_message *message, int id) 508 struct mxt_message *message, int id)
555{ 509{
556 struct mxt_finger *finger = data->finger;
557 struct device *dev = &data->client->dev; 510 struct device *dev = &data->client->dev;
558 u8 status = message->message[0]; 511 u8 status = message->message[0];
512 struct input_dev *input_dev = data->input_dev;
559 int x; 513 int x;
560 int y; 514 int y;
561 int area; 515 int area;
562 int pressure; 516 int pressure;
563 517
564 /* Check the touch is present on the screen */
565 if (!(status & MXT_DETECT)) {
566 if (status & MXT_RELEASE) {
567 dev_dbg(dev, "[%d] released\n", id);
568
569 finger[id].status = MXT_RELEASE;
570 mxt_input_report(data, id);
571 }
572 return;
573 }
574
575 /* Check only AMP detection */
576 if (!(status & (MXT_PRESS | MXT_MOVE)))
577 return;
578
579 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); 518 x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf);
580 y = (message->message[2] << 4) | ((message->message[3] & 0xf)); 519 y = (message->message[2] << 4) | ((message->message[3] & 0xf));
581 if (data->max_x < 1024) 520 if (data->max_x < 1024)
@@ -586,30 +525,50 @@ static void mxt_input_touchevent(struct mxt_data *data,
586 area = message->message[4]; 525 area = message->message[4];
587 pressure = message->message[5]; 526 pressure = message->message[5];
588 527
589 dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, 528 dev_dbg(dev,
590 status & MXT_MOVE ? "moved" : "pressed", 529 "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n",
591 x, y, area); 530 id,
531 (status & MXT_DETECT) ? 'D' : '.',
532 (status & MXT_PRESS) ? 'P' : '.',
533 (status & MXT_RELEASE) ? 'R' : '.',
534 (status & MXT_MOVE) ? 'M' : '.',
535 (status & MXT_VECTOR) ? 'V' : '.',
536 (status & MXT_AMP) ? 'A' : '.',
537 (status & MXT_SUPPRESS) ? 'S' : '.',
538 (status & MXT_UNGRIP) ? 'U' : '.',
539 x, y, area, pressure);
540
541 input_mt_slot(input_dev, id);
542 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER,
543 status & MXT_DETECT);
544
545 if (status & MXT_DETECT) {
546 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
547 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
548 input_report_abs(input_dev, ABS_MT_PRESSURE, pressure);
549 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
550 }
551}
592 552
593 finger[id].status = status & MXT_MOVE ? 553static unsigned mxt_extract_T6_csum(const u8 *csum)
594 MXT_MOVE : MXT_PRESS; 554{
595 finger[id].x = x; 555 return csum[0] | (csum[1] << 8) | (csum[2] << 16);
596 finger[id].y = y; 556}
597 finger[id].area = area;
598 finger[id].pressure = pressure;
599 557
600 mxt_input_report(data, id); 558static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg)
559{
560 u8 id = msg->reportid;
561 return (id >= data->T9_reportid_min && id <= data->T9_reportid_max);
601} 562}
602 563
603static irqreturn_t mxt_interrupt(int irq, void *dev_id) 564static irqreturn_t mxt_interrupt(int irq, void *dev_id)
604{ 565{
605 struct mxt_data *data = dev_id; 566 struct mxt_data *data = dev_id;
606 struct mxt_message message; 567 struct mxt_message message;
607 struct mxt_object *object; 568 const u8 *payload = &message.message[0];
608 struct device *dev = &data->client->dev; 569 struct device *dev = &data->client->dev;
609 int id;
610 u8 reportid; 570 u8 reportid;
611 u8 max_reportid; 571 bool update_input = false;
612 u8 min_reportid;
613 572
614 do { 573 do {
615 if (mxt_read_message(data, &message)) { 574 if (mxt_read_message(data, &message)) {
@@ -619,21 +578,25 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id)
619 578
620 reportid = message.reportid; 579 reportid = message.reportid;
621 580
622 /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */ 581 if (reportid == data->T6_reportid) {
623 object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); 582 u8 status = payload[0];
624 if (!object) 583 unsigned csum = mxt_extract_T6_csum(&payload[1]);
625 goto end; 584 dev_dbg(dev, "Status: %02x Config Checksum: %06x\n",
626 585 status, csum);
627 max_reportid = object->max_reportid; 586 } else if (mxt_is_T9_message(data, &message)) {
628 min_reportid = max_reportid - object->num_report_ids + 1; 587 int id = reportid - data->T9_reportid_min;
629 id = reportid - min_reportid;
630
631 if (reportid >= min_reportid && reportid <= max_reportid)
632 mxt_input_touchevent(data, &message, id); 588 mxt_input_touchevent(data, &message, id);
633 else 589 update_input = true;
590 } else {
634 mxt_dump_message(dev, &message); 591 mxt_dump_message(dev, &message);
592 }
635 } while (reportid != 0xff); 593 } while (reportid != 0xff);
636 594
595 if (update_input) {
596 input_mt_report_pointer_emulation(data->input_dev, false);
597 input_sync(data->input_dev);
598 }
599
637end: 600end:
638 return IRQ_HANDLED; 601 return IRQ_HANDLED;
639} 602}
@@ -644,7 +607,8 @@ static int mxt_check_reg_init(struct mxt_data *data)
644 struct mxt_object *object; 607 struct mxt_object *object;
645 struct device *dev = &data->client->dev; 608 struct device *dev = &data->client->dev;
646 int index = 0; 609 int index = 0;
647 int i, j, config_offset; 610 int i, size;
611 int ret;
648 612
649 if (!pdata->config) { 613 if (!pdata->config) {
650 dev_dbg(dev, "No cfg data defined, skipping reg init\n"); 614 dev_dbg(dev, "No cfg data defined, skipping reg init\n");
@@ -657,18 +621,17 @@ static int mxt_check_reg_init(struct mxt_data *data)
657 if (!mxt_object_writable(object->type)) 621 if (!mxt_object_writable(object->type))
658 continue; 622 continue;
659 623
660 for (j = 0; 624 size = (object->size + 1) * (object->instances + 1);
661 j < (object->size + 1) * (object->instances + 1); 625 if (index + size > pdata->config_length) {
662 j++) { 626 dev_err(dev, "Not enough config data!\n");
663 config_offset = index + j; 627 return -EINVAL;
664 if (config_offset > pdata->config_length) {
665 dev_err(dev, "Not enough config data!\n");
666 return -EINVAL;
667 }
668 mxt_write_object(data, object->type, j,
669 pdata->config[config_offset]);
670 } 628 }
671 index += (object->size + 1) * (object->instances + 1); 629
630 ret = __mxt_write_reg(data->client, object->start_address,
631 size, &pdata->config[index]);
632 if (ret)
633 return ret;
634 index += size;
672 } 635 }
673 636
674 return 0; 637 return 0;
@@ -749,68 +712,76 @@ static int mxt_get_info(struct mxt_data *data)
749 struct i2c_client *client = data->client; 712 struct i2c_client *client = data->client;
750 struct mxt_info *info = &data->info; 713 struct mxt_info *info = &data->info;
751 int error; 714 int error;
752 u8 val;
753 715
754 error = mxt_read_reg(client, MXT_FAMILY_ID, &val); 716 /* Read 7-byte info block starting at address 0 */
717 error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info);
755 if (error) 718 if (error)
756 return error; 719 return error;
757 info->family_id = val;
758
759 error = mxt_read_reg(client, MXT_VARIANT_ID, &val);
760 if (error)
761 return error;
762 info->variant_id = val;
763
764 error = mxt_read_reg(client, MXT_VERSION, &val);
765 if (error)
766 return error;
767 info->version = val;
768
769 error = mxt_read_reg(client, MXT_BUILD, &val);
770 if (error)
771 return error;
772 info->build = val;
773
774 error = mxt_read_reg(client, MXT_OBJECT_NUM, &val);
775 if (error)
776 return error;
777 info->object_num = val;
778 720
779 return 0; 721 return 0;
780} 722}
781 723
782static int mxt_get_object_table(struct mxt_data *data) 724static int mxt_get_object_table(struct mxt_data *data)
783{ 725{
726 struct i2c_client *client = data->client;
727 size_t table_size;
784 int error; 728 int error;
785 int i; 729 int i;
786 u16 reg; 730 u8 reportid;
787 u8 reportid = 0; 731
788 u8 buf[MXT_OBJECT_SIZE]; 732 table_size = data->info.object_num * sizeof(struct mxt_object);
733 error = __mxt_read_reg(client, MXT_OBJECT_START, table_size,
734 data->object_table);
735 if (error)
736 return error;
789 737
738 /* Valid Report IDs start counting from 1 */
739 reportid = 1;
790 for (i = 0; i < data->info.object_num; i++) { 740 for (i = 0; i < data->info.object_num; i++) {
791 struct mxt_object *object = data->object_table + i; 741 struct mxt_object *object = data->object_table + i;
742 u8 min_id, max_id;
792 743
793 reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; 744 le16_to_cpus(&object->start_address);
794 error = mxt_read_object_table(data->client, reg, buf);
795 if (error)
796 return error;
797
798 object->type = buf[0];
799 object->start_address = (buf[2] << 8) | buf[1];
800 object->size = buf[3];
801 object->instances = buf[4];
802 object->num_report_ids = buf[5];
803 745
804 if (object->num_report_ids) { 746 if (object->num_report_ids) {
747 min_id = reportid;
805 reportid += object->num_report_ids * 748 reportid += object->num_report_ids *
806 (object->instances + 1); 749 (object->instances + 1);
807 object->max_reportid = reportid; 750 max_id = reportid - 1;
751 } else {
752 min_id = 0;
753 max_id = 0;
754 }
755
756 dev_dbg(&data->client->dev,
757 "Type %2d Start %3d Size %3d Instances %2d ReportIDs %3u : %3u\n",
758 object->type, object->start_address, object->size + 1,
759 object->instances + 1, min_id, max_id);
760
761 switch (object->type) {
762 case MXT_GEN_COMMAND_T6:
763 data->T6_reportid = min_id;
764 break;
765 case MXT_TOUCH_MULTI_T9:
766 data->T9_reportid_min = min_id;
767 data->T9_reportid_max = max_id;
768 break;
808 } 769 }
809 } 770 }
810 771
811 return 0; 772 return 0;
812} 773}
813 774
775static void mxt_free_object_table(struct mxt_data *data)
776{
777 kfree(data->object_table);
778 data->object_table = NULL;
779 data->T6_reportid = 0;
780 data->T9_reportid_min = 0;
781 data->T9_reportid_max = 0;
782
783}
784
814static int mxt_initialize(struct mxt_data *data) 785static int mxt_initialize(struct mxt_data *data)
815{ 786{
816 struct i2c_client *client = data->client; 787 struct i2c_client *client = data->client;
@@ -833,12 +804,12 @@ static int mxt_initialize(struct mxt_data *data)
833 /* Get object table information */ 804 /* Get object table information */
834 error = mxt_get_object_table(data); 805 error = mxt_get_object_table(data);
835 if (error) 806 if (error)
836 return error; 807 goto err_free_object_table;
837 808
838 /* Check register init values */ 809 /* Check register init values */
839 error = mxt_check_reg_init(data); 810 error = mxt_check_reg_init(data);
840 if (error) 811 if (error)
841 return error; 812 goto err_free_object_table;
842 813
843 mxt_handle_pdata(data); 814 mxt_handle_pdata(data);
844 815
@@ -856,25 +827,29 @@ static int mxt_initialize(struct mxt_data *data)
856 /* Update matrix size at info struct */ 827 /* Update matrix size at info struct */
857 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); 828 error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val);
858 if (error) 829 if (error)
859 return error; 830 goto err_free_object_table;
860 info->matrix_xsize = val; 831 info->matrix_xsize = val;
861 832
862 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); 833 error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val);
863 if (error) 834 if (error)
864 return error; 835 goto err_free_object_table;
865 info->matrix_ysize = val; 836 info->matrix_ysize = val;
866 837
867 dev_info(&client->dev, 838 dev_info(&client->dev,
868 "Family ID: %d Variant ID: %d Version: %d Build: %d\n", 839 "Family ID: %u Variant ID: %u Major.Minor.Build: %u.%u.%02X\n",
869 info->family_id, info->variant_id, info->version, 840 info->family_id, info->variant_id, info->version >> 4,
870 info->build); 841 info->version & 0xf, info->build);
871 842
872 dev_info(&client->dev, 843 dev_info(&client->dev,
873 "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", 844 "Matrix X Size: %u Matrix Y Size: %u Object Num: %u\n",
874 info->matrix_xsize, info->matrix_ysize, 845 info->matrix_xsize, info->matrix_ysize,
875 info->object_num); 846 info->object_num);
876 847
877 return 0; 848 return 0;
849
850err_free_object_table:
851 mxt_free_object_table(data);
852 return error;
878} 853}
879 854
880static void mxt_calc_resolution(struct mxt_data *data) 855static void mxt_calc_resolution(struct mxt_data *data)
@@ -891,6 +866,44 @@ static void mxt_calc_resolution(struct mxt_data *data)
891 } 866 }
892} 867}
893 868
869/* Firmware Version is returned as Major.Minor.Build */
870static ssize_t mxt_fw_version_show(struct device *dev,
871 struct device_attribute *attr, char *buf)
872{
873 struct mxt_data *data = dev_get_drvdata(dev);
874 struct mxt_info *info = &data->info;
875 return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n",
876 info->version >> 4, info->version & 0xf, info->build);
877}
878
879/* Hardware Version is returned as FamilyID.VariantID */
880static ssize_t mxt_hw_version_show(struct device *dev,
881 struct device_attribute *attr, char *buf)
882{
883 struct mxt_data *data = dev_get_drvdata(dev);
884 struct mxt_info *info = &data->info;
885 return scnprintf(buf, PAGE_SIZE, "%u.%u\n",
886 info->family_id, info->variant_id);
887}
888
889static ssize_t mxt_show_instance(char *buf, int count,
890 struct mxt_object *object, int instance,
891 const u8 *val)
892{
893 int i;
894
895 if (object->instances > 0)
896 count += scnprintf(buf + count, PAGE_SIZE - count,
897 "Instance %u\n", instance);
898
899 for (i = 0; i < object->size + 1; i++)
900 count += scnprintf(buf + count, PAGE_SIZE - count,
901 "\t[%2u]: %02x (%d)\n", i, val[i], val[i]);
902 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
903
904 return count;
905}
906
894static ssize_t mxt_object_show(struct device *dev, 907static ssize_t mxt_object_show(struct device *dev,
895 struct device_attribute *attr, char *buf) 908 struct device_attribute *attr, char *buf)
896{ 909{
@@ -899,43 +912,38 @@ static ssize_t mxt_object_show(struct device *dev,
899 int count = 0; 912 int count = 0;
900 int i, j; 913 int i, j;
901 int error; 914 int error;
902 u8 val; 915 u8 *obuf;
903 916
917 /* Pre-allocate buffer large enough to hold max sized object. */
918 obuf = kmalloc(256, GFP_KERNEL);
919 if (!obuf)
920 return -ENOMEM;
921
922 error = 0;
904 for (i = 0; i < data->info.object_num; i++) { 923 for (i = 0; i < data->info.object_num; i++) {
905 object = data->object_table + i; 924 object = data->object_table + i;
906 925
907 count += snprintf(buf + count, PAGE_SIZE - count, 926 if (!mxt_object_readable(object->type))
908 "Object[%d] (Type %d)\n",
909 i + 1, object->type);
910 if (count >= PAGE_SIZE)
911 return PAGE_SIZE - 1;
912
913 if (!mxt_object_readable(object->type)) {
914 count += snprintf(buf + count, PAGE_SIZE - count,
915 "\n");
916 if (count >= PAGE_SIZE)
917 return PAGE_SIZE - 1;
918 continue; 927 continue;
919 }
920 928
921 for (j = 0; j < object->size + 1; j++) { 929 count += scnprintf(buf + count, PAGE_SIZE - count,
922 error = mxt_read_object(data, 930 "T%u:\n", object->type);
923 object->type, j, &val); 931
932 for (j = 0; j < object->instances + 1; j++) {
933 u16 size = object->size + 1;
934 u16 addr = object->start_address + j * size;
935
936 error = __mxt_read_reg(data->client, addr, size, obuf);
924 if (error) 937 if (error)
925 return error; 938 goto done;
926 939
927 count += snprintf(buf + count, PAGE_SIZE - count, 940 count = mxt_show_instance(buf, count, object, j, obuf);
928 "\t[%2d]: %02x (%d)\n", j, val, val);
929 if (count >= PAGE_SIZE)
930 return PAGE_SIZE - 1;
931 } 941 }
932
933 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
934 if (count >= PAGE_SIZE)
935 return PAGE_SIZE - 1;
936 } 942 }
937 943
938 return count; 944done:
945 kfree(obuf);
946 return error ?: count;
939} 947}
940 948
941static int mxt_load_fw(struct device *dev, const char *fn) 949static int mxt_load_fw(struct device *dev, const char *fn)
@@ -1028,8 +1036,7 @@ static ssize_t mxt_update_fw_store(struct device *dev,
1028 /* Wait for reset */ 1036 /* Wait for reset */
1029 msleep(MXT_FWRESET_TIME); 1037 msleep(MXT_FWRESET_TIME);
1030 1038
1031 kfree(data->object_table); 1039 mxt_free_object_table(data);
1032 data->object_table = NULL;
1033 1040
1034 mxt_initialize(data); 1041 mxt_initialize(data);
1035 } 1042 }
@@ -1043,10 +1050,14 @@ static ssize_t mxt_update_fw_store(struct device *dev,
1043 return count; 1050 return count;
1044} 1051}
1045 1052
1053static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL);
1054static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL);
1046static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); 1055static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL);
1047static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); 1056static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store);
1048 1057
1049static struct attribute *mxt_attrs[] = { 1058static struct attribute *mxt_attrs[] = {
1059 &dev_attr_fw_version.attr,
1060 &dev_attr_hw_version.attr,
1050 &dev_attr_object.attr, 1061 &dev_attr_object.attr,
1051 &dev_attr_update_fw.attr, 1062 &dev_attr_update_fw.attr,
1052 NULL 1063 NULL
@@ -1093,6 +1104,7 @@ static int __devinit mxt_probe(struct i2c_client *client,
1093 struct mxt_data *data; 1104 struct mxt_data *data;
1094 struct input_dev *input_dev; 1105 struct input_dev *input_dev;
1095 int error; 1106 int error;
1107 unsigned int num_mt_slots;
1096 1108
1097 if (!pdata) 1109 if (!pdata)
1098 return -EINVAL; 1110 return -EINVAL;
@@ -1106,6 +1118,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
1106 } 1118 }
1107 1119
1108 input_dev->name = "Atmel maXTouch Touchscreen"; 1120 input_dev->name = "Atmel maXTouch Touchscreen";
1121 snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0",
1122 client->adapter->nr, client->addr);
1123 input_dev->phys = data->phys;
1124
1109 input_dev->id.bustype = BUS_I2C; 1125 input_dev->id.bustype = BUS_I2C;
1110 input_dev->dev.parent = &client->dev; 1126 input_dev->dev.parent = &client->dev;
1111 input_dev->open = mxt_input_open; 1127 input_dev->open = mxt_input_open;
@@ -1118,6 +1134,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
1118 1134
1119 mxt_calc_resolution(data); 1135 mxt_calc_resolution(data);
1120 1136
1137 error = mxt_initialize(data);
1138 if (error)
1139 goto err_free_mem;
1140
1121 __set_bit(EV_ABS, input_dev->evbit); 1141 __set_bit(EV_ABS, input_dev->evbit);
1122 __set_bit(EV_KEY, input_dev->evbit); 1142 __set_bit(EV_KEY, input_dev->evbit);
1123 __set_bit(BTN_TOUCH, input_dev->keybit); 1143 __set_bit(BTN_TOUCH, input_dev->keybit);
@@ -1131,7 +1151,10 @@ static int __devinit mxt_probe(struct i2c_client *client,
1131 0, 255, 0, 0); 1151 0, 255, 0, 0);
1132 1152
1133 /* For multi touch */ 1153 /* For multi touch */
1134 input_mt_init_slots(input_dev, MXT_MAX_FINGER); 1154 num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
1155 error = input_mt_init_slots(input_dev, num_mt_slots);
1156 if (error)
1157 goto err_free_object;
1135 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 1158 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
1136 0, MXT_MAX_AREA, 0, 0); 1159 0, MXT_MAX_AREA, 0, 0);
1137 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 1160 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
@@ -1144,13 +1167,9 @@ static int __devinit mxt_probe(struct i2c_client *client,
1144 input_set_drvdata(input_dev, data); 1167 input_set_drvdata(input_dev, data);
1145 i2c_set_clientdata(client, data); 1168 i2c_set_clientdata(client, data);
1146 1169
1147 error = mxt_initialize(data);
1148 if (error)
1149 goto err_free_object;
1150
1151 error = request_threaded_irq(client->irq, NULL, mxt_interrupt, 1170 error = request_threaded_irq(client->irq, NULL, mxt_interrupt,
1152 pdata->irqflags | IRQF_ONESHOT, 1171 pdata->irqflags | IRQF_ONESHOT,
1153 client->dev.driver->name, data); 1172 client->name, data);
1154 if (error) { 1173 if (error) {
1155 dev_err(&client->dev, "Failed to register interrupt\n"); 1174 dev_err(&client->dev, "Failed to register interrupt\n");
1156 goto err_free_object; 1175 goto err_free_object;
diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c
new file mode 100644
index 000000000000..49c44bbf548d
--- /dev/null
+++ b/drivers/input/touchscreen/mms114.c
@@ -0,0 +1,544 @@
1/*
2 * Copyright (C) 2012 Samsung Electronics Co.Ltd
3 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/delay.h>
13#include <linux/i2c.h>
14#include <linux/i2c/mms114.h>
15#include <linux/input/mt.h>
16#include <linux/interrupt.h>
17#include <linux/regulator/consumer.h>
18#include <linux/slab.h>
19
20/* Write only registers */
21#define MMS114_MODE_CONTROL 0x01
22#define MMS114_OPERATION_MODE_MASK 0xE
23#define MMS114_ACTIVE (1 << 1)
24
25#define MMS114_XY_RESOLUTION_H 0x02
26#define MMS114_X_RESOLUTION 0x03
27#define MMS114_Y_RESOLUTION 0x04
28#define MMS114_CONTACT_THRESHOLD 0x05
29#define MMS114_MOVING_THRESHOLD 0x06
30
31/* Read only registers */
32#define MMS114_PACKET_SIZE 0x0F
33#define MMS114_INFOMATION 0x10
34#define MMS114_TSP_REV 0xF0
35
36/* Minimum delay time is 50us between stop and start signal of i2c */
37#define MMS114_I2C_DELAY 50
38
39/* 200ms needs after power on */
40#define MMS114_POWERON_DELAY 200
41
42/* Touchscreen absolute values */
43#define MMS114_MAX_AREA 0xff
44
45#define MMS114_MAX_TOUCH 10
46#define MMS114_PACKET_NUM 8
47
48/* Touch type */
49#define MMS114_TYPE_NONE 0
50#define MMS114_TYPE_TOUCHSCREEN 1
51#define MMS114_TYPE_TOUCHKEY 2
52
53struct mms114_data {
54 struct i2c_client *client;
55 struct input_dev *input_dev;
56 struct regulator *core_reg;
57 struct regulator *io_reg;
58 const struct mms114_platform_data *pdata;
59
60 /* Use cache data for mode control register(write only) */
61 u8 cache_mode_control;
62};
63
64struct mms114_touch {
65 u8 id:4, reserved_bit4:1, type:2, pressed:1;
66 u8 x_hi:4, y_hi:4;
67 u8 x_lo;
68 u8 y_lo;
69 u8 width;
70 u8 strength;
71 u8 reserved[2];
72} __packed;
73
74static int __mms114_read_reg(struct mms114_data *data, unsigned int reg,
75 unsigned int len, u8 *val)
76{
77 struct i2c_client *client = data->client;
78 struct i2c_msg xfer[2];
79 u8 buf = reg & 0xff;
80 int error;
81
82 if (reg <= MMS114_MODE_CONTROL && reg + len > MMS114_MODE_CONTROL)
83 BUG();
84
85 /* Write register: use repeated start */
86 xfer[0].addr = client->addr;
87 xfer[0].flags = I2C_M_TEN | I2C_M_NOSTART;
88 xfer[0].len = 1;
89 xfer[0].buf = &buf;
90
91 /* Read data */
92 xfer[1].addr = client->addr;
93 xfer[1].flags = I2C_M_RD;
94 xfer[1].len = len;
95 xfer[1].buf = val;
96
97 error = i2c_transfer(client->adapter, xfer, 2);
98 if (error != 2) {
99 dev_err(&client->dev,
100 "%s: i2c transfer failed (%d)\n", __func__, error);
101 return error < 0 ? error : -EIO;
102 }
103 udelay(MMS114_I2C_DELAY);
104
105 return 0;
106}
107
108static int mms114_read_reg(struct mms114_data *data, unsigned int reg)
109{
110 u8 val;
111 int error;
112
113 if (reg == MMS114_MODE_CONTROL)
114 return data->cache_mode_control;
115
116 error = __mms114_read_reg(data, reg, 1, &val);
117 return error < 0 ? error : val;
118}
119
120static int mms114_write_reg(struct mms114_data *data, unsigned int reg,
121 unsigned int val)
122{
123 struct i2c_client *client = data->client;
124 u8 buf[2];
125 int error;
126
127 buf[0] = reg & 0xff;
128 buf[1] = val & 0xff;
129
130 error = i2c_master_send(client, buf, 2);
131 if (error != 2) {
132 dev_err(&client->dev,
133 "%s: i2c send failed (%d)\n", __func__, error);
134 return error < 0 ? error : -EIO;
135 }
136 udelay(MMS114_I2C_DELAY);
137
138 if (reg == MMS114_MODE_CONTROL)
139 data->cache_mode_control = val;
140
141 return 0;
142}
143
144static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *touch)
145{
146 const struct mms114_platform_data *pdata = data->pdata;
147 struct i2c_client *client = data->client;
148 struct input_dev *input_dev = data->input_dev;
149 unsigned int id;
150 unsigned int x;
151 unsigned int y;
152
153 if (touch->id > MMS114_MAX_TOUCH) {
154 dev_err(&client->dev, "Wrong touch id (%d)\n", touch->id);
155 return;
156 }
157
158 if (touch->type != MMS114_TYPE_TOUCHSCREEN) {
159 dev_err(&client->dev, "Wrong touch type (%d)\n", touch->type);
160 return;
161 }
162
163 id = touch->id - 1;
164 x = touch->x_lo | touch->x_hi << 8;
165 y = touch->y_lo | touch->y_hi << 8;
166 if (x > pdata->x_size || y > pdata->y_size) {
167 dev_dbg(&client->dev,
168 "Wrong touch coordinates (%d, %d)\n", x, y);
169 return;
170 }
171
172 if (pdata->x_invert)
173 x = pdata->x_size - x;
174 if (pdata->y_invert)
175 y = pdata->y_size - y;
176
177 dev_dbg(&client->dev,
178 "id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n",
179 id, touch->type, touch->pressed,
180 x, y, touch->width, touch->strength);
181
182 input_mt_slot(input_dev, id);
183 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed);
184
185 if (touch->pressed) {
186 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width);
187 input_report_abs(input_dev, ABS_MT_POSITION_X, x);
188 input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
189 input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength);
190 }
191}
192
193static irqreturn_t mms114_interrupt(int irq, void *dev_id)
194{
195 struct mms114_data *data = dev_id;
196 struct input_dev *input_dev = data->input_dev;
197 struct mms114_touch touch[MMS114_MAX_TOUCH];
198 int packet_size;
199 int touch_size;
200 int index;
201 int error;
202
203 mutex_lock(&input_dev->mutex);
204 if (!input_dev->users) {
205 mutex_unlock(&input_dev->mutex);
206 goto out;
207 }
208 mutex_unlock(&input_dev->mutex);
209
210 packet_size = mms114_read_reg(data, MMS114_PACKET_SIZE);
211 if (packet_size <= 0)
212 goto out;
213
214 touch_size = packet_size / MMS114_PACKET_NUM;
215
216 error = __mms114_read_reg(data, MMS114_INFOMATION, packet_size,
217 (u8 *)touch);
218 if (error < 0)
219 goto out;
220
221 for (index = 0; index < touch_size; index++)
222 mms114_process_mt(data, touch + index);
223
224 input_mt_report_pointer_emulation(data->input_dev, true);
225 input_sync(data->input_dev);
226
227out:
228 return IRQ_HANDLED;
229}
230
231static int mms114_set_active(struct mms114_data *data, bool active)
232{
233 int val;
234
235 val = mms114_read_reg(data, MMS114_MODE_CONTROL);
236 if (val < 0)
237 return val;
238
239 val &= ~MMS114_OPERATION_MODE_MASK;
240
241 /* If active is false, sleep mode */
242 if (active)
243 val |= MMS114_ACTIVE;
244
245 return mms114_write_reg(data, MMS114_MODE_CONTROL, val);
246}
247
248static int mms114_get_version(struct mms114_data *data)
249{
250 struct device *dev = &data->client->dev;
251 u8 buf[6];
252 int error;
253
254 error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf);
255 if (error < 0)
256 return error;
257
258 dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n",
259 buf[0], buf[1], buf[3]);
260
261 return 0;
262}
263
264static int mms114_setup_regs(struct mms114_data *data)
265{
266 const struct mms114_platform_data *pdata = data->pdata;
267 int val;
268 int error;
269
270 error = mms114_get_version(data);
271 if (error < 0)
272 return error;
273
274 error = mms114_set_active(data, true);
275 if (error < 0)
276 return error;
277
278 val = (pdata->x_size >> 8) & 0xf;
279 val |= ((pdata->y_size >> 8) & 0xf) << 4;
280 error = mms114_write_reg(data, MMS114_XY_RESOLUTION_H, val);
281 if (error < 0)
282 return error;
283
284 val = pdata->x_size & 0xff;
285 error = mms114_write_reg(data, MMS114_X_RESOLUTION, val);
286 if (error < 0)
287 return error;
288
289 val = pdata->y_size & 0xff;
290 error = mms114_write_reg(data, MMS114_Y_RESOLUTION, val);
291 if (error < 0)
292 return error;
293
294 if (pdata->contact_threshold) {
295 error = mms114_write_reg(data, MMS114_CONTACT_THRESHOLD,
296 pdata->contact_threshold);
297 if (error < 0)
298 return error;
299 }
300
301 if (pdata->moving_threshold) {
302 error = mms114_write_reg(data, MMS114_MOVING_THRESHOLD,
303 pdata->moving_threshold);
304 if (error < 0)
305 return error;
306 }
307
308 return 0;
309}
310
311static int mms114_start(struct mms114_data *data)
312{
313 struct i2c_client *client = data->client;
314 int error;
315
316 if (data->core_reg)
317 regulator_enable(data->core_reg);
318 if (data->io_reg)
319 regulator_enable(data->io_reg);
320 mdelay(MMS114_POWERON_DELAY);
321
322 error = mms114_setup_regs(data);
323 if (error < 0)
324 return error;
325
326 if (data->pdata->cfg_pin)
327 data->pdata->cfg_pin(true);
328
329 enable_irq(client->irq);
330
331 return 0;
332}
333
334static void mms114_stop(struct mms114_data *data)
335{
336 struct i2c_client *client = data->client;
337
338 disable_irq(client->irq);
339
340 if (data->pdata->cfg_pin)
341 data->pdata->cfg_pin(false);
342
343 if (data->io_reg)
344 regulator_disable(data->io_reg);
345 if (data->core_reg)
346 regulator_disable(data->core_reg);
347}
348
349static int mms114_input_open(struct input_dev *dev)
350{
351 struct mms114_data *data = input_get_drvdata(dev);
352
353 return mms114_start(data);
354}
355
356static void mms114_input_close(struct input_dev *dev)
357{
358 struct mms114_data *data = input_get_drvdata(dev);
359
360 mms114_stop(data);
361}
362
363static int __devinit mms114_probe(struct i2c_client *client,
364 const struct i2c_device_id *id)
365{
366 struct mms114_data *data;
367 struct input_dev *input_dev;
368 int error;
369
370 if (!client->dev.platform_data) {
371 dev_err(&client->dev, "Need platform data\n");
372 return -EINVAL;
373 }
374
375 if (!i2c_check_functionality(client->adapter,
376 I2C_FUNC_PROTOCOL_MANGLING)) {
377 dev_err(&client->dev,
378 "Need i2c bus that supports protocol mangling\n");
379 return -ENODEV;
380 }
381
382 data = kzalloc(sizeof(struct mms114_data), GFP_KERNEL);
383 input_dev = input_allocate_device();
384 if (!data || !input_dev) {
385 dev_err(&client->dev, "Failed to allocate memory\n");
386 error = -ENOMEM;
387 goto err_free_mem;
388 }
389
390 data->client = client;
391 data->input_dev = input_dev;
392 data->pdata = client->dev.platform_data;
393
394 input_dev->name = "MELPAS MMS114 Touchscreen";
395 input_dev->id.bustype = BUS_I2C;
396 input_dev->dev.parent = &client->dev;
397 input_dev->open = mms114_input_open;
398 input_dev->close = mms114_input_close;
399
400 __set_bit(EV_ABS, input_dev->evbit);
401 __set_bit(EV_KEY, input_dev->evbit);
402 __set_bit(BTN_TOUCH, input_dev->keybit);
403 input_set_abs_params(input_dev, ABS_X, 0, data->pdata->x_size, 0, 0);
404 input_set_abs_params(input_dev, ABS_Y, 0, data->pdata->y_size, 0, 0);
405
406 /* For multi touch */
407 input_mt_init_slots(input_dev, MMS114_MAX_TOUCH);
408 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
409 0, MMS114_MAX_AREA, 0, 0);
410 input_set_abs_params(input_dev, ABS_MT_POSITION_X,
411 0, data->pdata->x_size, 0, 0);
412 input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
413 0, data->pdata->y_size, 0, 0);
414 input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
415
416 input_set_drvdata(input_dev, data);
417 i2c_set_clientdata(client, data);
418
419 data->core_reg = regulator_get(&client->dev, "avdd");
420 if (IS_ERR(data->core_reg)) {
421 error = PTR_ERR(data->core_reg);
422 dev_err(&client->dev,
423 "Unable to get the Core regulator (%d)\n", error);
424 goto err_free_mem;
425 }
426
427 data->io_reg = regulator_get(&client->dev, "vdd");
428 if (IS_ERR(data->io_reg)) {
429 error = PTR_ERR(data->io_reg);
430 dev_err(&client->dev,
431 "Unable to get the IO regulator (%d)\n", error);
432 goto err_core_reg;
433 }
434
435 error = request_threaded_irq(client->irq, NULL, mms114_interrupt,
436 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "mms114", data);
437 if (error) {
438 dev_err(&client->dev, "Failed to register interrupt\n");
439 goto err_io_reg;
440 }
441 disable_irq(client->irq);
442
443 error = input_register_device(data->input_dev);
444 if (error)
445 goto err_free_irq;
446
447 return 0;
448
449err_free_irq:
450 free_irq(client->irq, data);
451err_io_reg:
452 regulator_put(data->io_reg);
453err_core_reg:
454 regulator_put(data->core_reg);
455err_free_mem:
456 input_free_device(input_dev);
457 kfree(data);
458 return error;
459}
460
461static int __devexit mms114_remove(struct i2c_client *client)
462{
463 struct mms114_data *data = i2c_get_clientdata(client);
464
465 free_irq(client->irq, data);
466 regulator_put(data->io_reg);
467 regulator_put(data->core_reg);
468 input_unregister_device(data->input_dev);
469 kfree(data);
470
471 return 0;
472}
473
474#ifdef CONFIG_PM_SLEEP
475static int mms114_suspend(struct device *dev)
476{
477 struct i2c_client *client = to_i2c_client(dev);
478 struct mms114_data *data = i2c_get_clientdata(client);
479 struct input_dev *input_dev = data->input_dev;
480 int id;
481
482 /* Release all touch */
483 for (id = 0; id < MMS114_MAX_TOUCH; id++) {
484 input_mt_slot(input_dev, id);
485 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false);
486 }
487
488 input_mt_report_pointer_emulation(input_dev, true);
489 input_sync(input_dev);
490
491 mutex_lock(&input_dev->mutex);
492 if (input_dev->users)
493 mms114_stop(data);
494 mutex_unlock(&input_dev->mutex);
495
496 return 0;
497}
498
499static int mms114_resume(struct device *dev)
500{
501 struct i2c_client *client = to_i2c_client(dev);
502 struct mms114_data *data = i2c_get_clientdata(client);
503 struct input_dev *input_dev = data->input_dev;
504 int error;
505
506 mutex_lock(&input_dev->mutex);
507 if (input_dev->users) {
508 error = mms114_start(data);
509 if (error < 0) {
510 mutex_unlock(&input_dev->mutex);
511 return error;
512 }
513 }
514 mutex_unlock(&input_dev->mutex);
515
516 return 0;
517}
518#endif
519
520static SIMPLE_DEV_PM_OPS(mms114_pm_ops, mms114_suspend, mms114_resume);
521
522static const struct i2c_device_id mms114_id[] = {
523 { "mms114", 0 },
524 { }
525};
526MODULE_DEVICE_TABLE(i2c, mms114_id);
527
528static struct i2c_driver mms114_driver = {
529 .driver = {
530 .name = "mms114",
531 .owner = THIS_MODULE,
532 .pm = &mms114_pm_ops,
533 },
534 .probe = mms114_probe,
535 .remove = __devexit_p(mms114_remove),
536 .id_table = mms114_id,
537};
538
539module_i2c_driver(mms114_driver);
540
541/* Module information */
542MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
543MODULE_DESCRIPTION("MELFAS mms114 Touchscreen driver");
544MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c
index 35572575d34a..0c01657132fd 100644
--- a/drivers/input/touchscreen/wacom_i2c.c
+++ b/drivers/input/touchscreen/wacom_i2c.c
@@ -149,7 +149,7 @@ static int __devinit wacom_i2c_probe(struct i2c_client *client,
149{ 149{
150 struct wacom_i2c *wac_i2c; 150 struct wacom_i2c *wac_i2c;
151 struct input_dev *input; 151 struct input_dev *input;
152 struct wacom_features features; 152 struct wacom_features features = { 0 };
153 int error; 153 int error;
154 154
155 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 155 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
diff --git a/include/linux/i2c/mms114.h b/include/linux/i2c/mms114.h
new file mode 100644
index 000000000000..5722ebfb2738
--- /dev/null
+++ b/include/linux/i2c/mms114.h
@@ -0,0 +1,24 @@
1/*
2 * Copyright (C) 2012 Samsung Electronics Co.Ltd
3 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundationr
8 */
9
10#ifndef __LINUX_MMS114_H
11#define __LINUX_MMS114_H
12
13struct mms114_platform_data {
14 unsigned int x_size;
15 unsigned int y_size;
16 unsigned int contact_threshold;
17 unsigned int moving_threshold;
18 bool x_invert;
19 bool y_invert;
20
21 void (*cfg_pin)(bool);
22};
23
24#endif /* __LINUX_MMS114_H */
diff --git a/include/linux/input.h b/include/linux/input.h
index 2740d080ec6b..725dcd0f63a4 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -807,18 +807,20 @@ struct input_keymap_entry {
807#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ 807#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
808#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ 808#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
809#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ 809#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
810#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */ 810#define ABS_MT_POSITION_X 0x35 /* Center X touch position */
811#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */ 811#define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */
812#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ 812#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
813#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ 813#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
814#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ 814#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
815#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ 815#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
816#define ABS_MT_DISTANCE 0x3b /* Contact hover distance */ 816#define ABS_MT_DISTANCE 0x3b /* Contact hover distance */
817#define ABS_MT_TOOL_X 0x3c /* Center X tool position */
818#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */
817 819
818#ifdef __KERNEL__ 820#ifdef __KERNEL__
819/* Implementation details, userspace should not care about these */ 821/* Implementation details, userspace should not care about these */
820#define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR 822#define ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
821#define ABS_MT_LAST ABS_MT_DISTANCE 823#define ABS_MT_LAST ABS_MT_TOOL_Y
822#endif 824#endif
823 825
824#define ABS_MAX 0x3f 826#define ABS_MAX 0x3f
diff --git a/include/linux/spi/ad7879.h b/include/linux/spi/ad7879.h
index 6334cee1a3be..58368be0b4c0 100644
--- a/include/linux/spi/ad7879.h
+++ b/include/linux/spi/ad7879.h
@@ -12,6 +12,8 @@ struct ad7879_platform_data {
12 u16 y_min, y_max; 12 u16 y_min, y_max;
13 u16 pressure_min, pressure_max; 13 u16 pressure_min, pressure_max;
14 14
15 bool swap_xy; /* swap x and y axes */
16
15 /* [0..255] 0=OFF Starts at 1=550us and goes 17 /* [0..255] 0=OFF Starts at 1=550us and goes
16 * all the way to 9.440ms in steps of 35us. 18 * all the way to 9.440ms in steps of 35us.
17 */ 19 */