1 From 75a6299867667a481a12f3c833322e39ff4fb089 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= <noralf@tronnes.org>
3 Date: Fri, 2 Oct 2015 11:30:11 -0700
4 Subject: [PATCH 205/222] Input: add support for FocalTech FT6236 touchscreen
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 This adds support for the FT6x06 and the FT6x36 family of capacitive touch
11 panel controllers, in particular the FT6236.
13 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
14 Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
16 .../input/touchscreen/focaltech-ft6236.txt | 35 +++
17 .../devicetree/bindings/vendor-prefixes.txt | 1 +
18 drivers/input/touchscreen/Kconfig | 13 +
19 drivers/input/touchscreen/Makefile | 1 +
20 drivers/input/touchscreen/ft6236.c | 327 +++++++++++++++++++++
21 5 files changed, 377 insertions(+)
22 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/focaltech-ft6236.txt
23 create mode 100644 drivers/input/touchscreen/ft6236.c
26 +++ b/Documentation/devicetree/bindings/input/touchscreen/focaltech-ft6236.txt
28 +* FocalTech FT6236 I2C touchscreen controller
31 + - compatible : "focaltech,ft6236"
32 + - reg : I2C slave address of the chip (0x38)
33 + - interrupt-parent : a phandle pointing to the interrupt controller
34 + serving the interrupt for this chip
35 + - interrupts : interrupt specification for the touch controller
37 + - reset-gpios : GPIO specification for the RSTN input
38 + - touchscreen-size-x : horizontal resolution of touchscreen (in pixels)
39 + - touchscreen-size-y : vertical resolution of touchscreen (in pixels)
42 + - touchscreen-fuzz-x : horizontal noise value of the absolute input
44 + - touchscreen-fuzz-y : vertical noise value of the absolute input
46 + - touchscreen-inverted-x : X axis is inverted (boolean)
47 + - touchscreen-inverted-y : Y axis is inverted (boolean)
48 + - touchscreen-swapped-x-y: X and Y axis are swapped (boolean)
49 + Swapping is done after inverting the axis
54 + compatible = "focaltech,ft6236";
56 + interrupt-parent = <&gpio>;
57 + interrupts = <23 2>;
58 + touchscreen-size-x = <320>;
59 + touchscreen-size-y = <480>;
60 + touchscreen-inverted-x;
61 + touchscreen-swapped-x-y;
63 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt
64 +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
65 @@ -76,6 +76,7 @@ everspin Everspin Technologies, Inc.
67 fcs Fairchild Semiconductor
69 +focaltech FocalTech Systems Co.,Ltd
70 fsl Freescale Semiconductor
71 GEFanuc GE Fanuc Intelligent Platforms Embedded Systems, Inc.
72 gef GE Fanuc Intelligent Platforms Embedded Systems, Inc.
73 --- a/drivers/input/touchscreen/Kconfig
74 +++ b/drivers/input/touchscreen/Kconfig
75 @@ -295,6 +295,19 @@ config TOUCHSCREEN_EGALAX
76 To compile this driver as a module, choose M here: the
77 module will be called egalax_ts.
79 +config TOUCHSCREEN_FT6236
80 + tristate "FT6236 I2C touchscreen"
82 + depends on GPIOLIB || COMPILE_TEST
84 + Say Y here to enable support for the I2C connected FT6x06 and
85 + FT6x36 family of capacitive touchscreen drivers.
89 + To compile this driver as a module, choose M here: the
90 + module will be called ft6236.
92 config TOUCHSCREEN_FUJITSU
93 tristate "Fujitsu serial touchscreen"
95 --- a/drivers/input/touchscreen/Makefile
96 +++ b/drivers/input/touchscreen/Makefile
97 @@ -36,6 +36,7 @@ obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_
98 obj-$(CONFIG_TOUCHSCREEN_ELAN) += elants_i2c.o
99 obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
100 obj-$(CONFIG_TOUCHSCREEN_EGALAX) += egalax_ts.o
101 +obj-$(CONFIG_TOUCHSCREEN_FT6236) += ft6236.o
102 obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
103 obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix.o
104 obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o
106 +++ b/drivers/input/touchscreen/ft6236.c
109 + * FocalTech FT6236 TouchScreen driver.
111 + * Copyright (c) 2010 Focal tech Ltd.
113 + * This software is licensed under the terms of the GNU General Public
114 + * License version 2, as published by the Free Software Foundation, and
115 + * may be copied, distributed, and modified under those terms.
117 + * This program is distributed in the hope that it will be useful,
118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120 + * GNU General Public License for more details.
123 +#include <linux/delay.h>
124 +#include <linux/gpio/consumer.h>
125 +#include <linux/i2c.h>
126 +#include <linux/input.h>
127 +#include <linux/input/mt.h>
128 +#include <linux/interrupt.h>
129 +#include <linux/module.h>
130 +#include <linux/property.h>
132 +#define FT6236_MAX_TOUCH_POINTS 2
134 +#define FT6236_REG_TH_GROUP 0x80
135 +#define FT6236_REG_PERIODACTIVE 0x88
136 +#define FT6236_REG_LIB_VER_H 0xa1
137 +#define FT6236_REG_LIB_VER_L 0xa2
138 +#define FT6236_REG_CIPHER 0xa3
139 +#define FT6236_REG_FIRMID 0xa6
140 +#define FT6236_REG_FOCALTECH_ID 0xa8
141 +#define FT6236_REG_RELEASE_CODE_ID 0xaf
143 +#define FT6236_EVENT_PRESS_DOWN 0
144 +#define FT6236_EVENT_LIFT_UP 1
145 +#define FT6236_EVENT_CONTACT 2
146 +#define FT6236_EVENT_NO_EVENT 3
148 +struct ft6236_data {
149 + struct i2c_client *client;
150 + struct input_dev *input;
151 + struct gpio_desc *reset_gpio;
160 + * This struct is a touchpoint as stored in hardware. Note that the id,
161 + * as well as the event, are stored in the upper nybble of the hi byte.
163 +struct ft6236_touchpoint {
178 +/* This packet represents the register map as read from offset 0 */
179 +struct ft6236_packet {
183 + struct ft6236_touchpoint points[FT6236_MAX_TOUCH_POINTS];
186 +static int ft6236_read(struct i2c_client *client, u8 reg, u8 len, void *data)
190 + error = i2c_smbus_read_i2c_block_data(client, reg, len, data);
200 +static irqreturn_t ft6236_interrupt(int irq, void *dev_id)
202 + struct ft6236_data *ft6236 = dev_id;
203 + struct device *dev = &ft6236->client->dev;
204 + struct input_dev *input = ft6236->input;
205 + struct ft6236_packet buf;
209 + error = ft6236_read(ft6236->client, 0, sizeof(buf), &buf);
211 + dev_err(dev, "read touchdata failed %d\n", error);
212 + return IRQ_HANDLED;
215 + touches = buf.touches & 0xf;
216 + if (touches > FT6236_MAX_TOUCH_POINTS) {
218 + "%d touch points reported, only %d are supported\n",
219 + touches, FT6236_MAX_TOUCH_POINTS);
220 + touches = FT6236_MAX_TOUCH_POINTS;
223 + for (i = 0; i < touches; i++) {
224 + struct ft6236_touchpoint *point = &buf.points[i];
225 + u16 x = ((point->xhi & 0xf) << 8) | buf.points[i].xlo;
226 + u16 y = ((point->yhi & 0xf) << 8) | buf.points[i].ylo;
227 + u8 event = point->event >> 6;
228 + u8 id = point->id >> 4;
229 + bool act = (event == FT6236_EVENT_PRESS_DOWN ||
230 + event == FT6236_EVENT_CONTACT);
232 + input_mt_slot(input, id);
233 + input_mt_report_slot_state(input, MT_TOOL_FINGER, act);
237 + if (ft6236->invert_x)
238 + x = ft6236->max_x - x;
240 + if (ft6236->invert_y)
241 + y = ft6236->max_y - y;
243 + if (ft6236->swap_xy) {
244 + input_report_abs(input, ABS_MT_POSITION_X, y);
245 + input_report_abs(input, ABS_MT_POSITION_Y, x);
247 + input_report_abs(input, ABS_MT_POSITION_X, x);
248 + input_report_abs(input, ABS_MT_POSITION_Y, y);
252 + input_mt_sync_frame(input);
255 + return IRQ_HANDLED;
258 +static u8 ft6236_debug_read_byte(struct ft6236_data *ft6236, u8 reg)
260 + struct i2c_client *client = ft6236->client;
264 + error = ft6236_read(client, reg, 1, &val);
266 + dev_dbg(&client->dev,
267 + "error reading register 0x%02x: %d\n", reg, error);
272 +static void ft6236_debug_info(struct ft6236_data *ft6236)
274 + struct device *dev = &ft6236->client->dev;
276 + dev_dbg(dev, "Touch threshold is %d\n",
277 + ft6236_debug_read_byte(ft6236, FT6236_REG_TH_GROUP) * 4);
278 + dev_dbg(dev, "Report rate is %dHz\n",
279 + ft6236_debug_read_byte(ft6236, FT6236_REG_PERIODACTIVE) * 10);
280 + dev_dbg(dev, "Firmware library version 0x%02x%02x\n",
281 + ft6236_debug_read_byte(ft6236, FT6236_REG_LIB_VER_H),
282 + ft6236_debug_read_byte(ft6236, FT6236_REG_LIB_VER_L));
283 + dev_dbg(dev, "Firmware version 0x%02x\n",
284 + ft6236_debug_read_byte(ft6236, FT6236_REG_FIRMID));
285 + dev_dbg(dev, "Chip vendor ID 0x%02x\n",
286 + ft6236_debug_read_byte(ft6236, FT6236_REG_CIPHER));
287 + dev_dbg(dev, "CTPM vendor ID 0x%02x\n",
288 + ft6236_debug_read_byte(ft6236, FT6236_REG_FOCALTECH_ID));
289 + dev_dbg(dev, "Release code version 0x%02x\n",
290 + ft6236_debug_read_byte(ft6236, FT6236_REG_RELEASE_CODE_ID));
293 +static void ft6236_reset(struct ft6236_data *ft6236)
295 + if (!ft6236->reset_gpio)
298 + gpiod_set_value_cansleep(ft6236->reset_gpio, 1);
299 + usleep_range(5000, 20000);
300 + gpiod_set_value_cansleep(ft6236->reset_gpio, 0);
304 +static int ft6236_probe(struct i2c_client *client,
305 + const struct i2c_device_id *id)
307 + struct device *dev = &client->dev;
308 + struct ft6236_data *ft6236;
309 + struct input_dev *input;
310 + u32 fuzz_x = 0, fuzz_y = 0;
314 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
317 + if (!client->irq) {
318 + dev_err(dev, "irq is missing\n");
322 + ft6236 = devm_kzalloc(dev, sizeof(*ft6236), GFP_KERNEL);
326 + ft6236->client = client;
327 + ft6236->reset_gpio = devm_gpiod_get_optional(dev, "reset",
329 + if (IS_ERR(ft6236->reset_gpio)) {
330 + error = PTR_ERR(ft6236->reset_gpio);
331 + if (error != -EPROBE_DEFER)
332 + dev_err(dev, "error getting reset gpio: %d\n", error);
336 + ft6236_reset(ft6236);
338 + /* verify that the controller is present */
339 + error = ft6236_read(client, 0x00, 1, &val);
341 + dev_err(dev, "failed to read from controller: %d\n", error);
345 + ft6236_debug_info(ft6236);
347 + input = devm_input_allocate_device(dev);
351 + ft6236->input = input;
352 + input->name = client->name;
353 + input->id.bustype = BUS_I2C;
355 + if (device_property_read_u32(dev, "touchscreen-size-x",
357 + device_property_read_u32(dev, "touchscreen-size-y",
359 + dev_err(dev, "touchscreen-size-x and/or -y missing\n");
363 + device_property_read_u32(dev, "touchscreen-fuzz-x", &fuzz_x);
364 + device_property_read_u32(dev, "touchscreen-fuzz-y", &fuzz_y);
365 + ft6236->invert_x = device_property_read_bool(dev,
366 + "touchscreen-inverted-x");
367 + ft6236->invert_y = device_property_read_bool(dev,
368 + "touchscreen-inverted-y");
369 + ft6236->swap_xy = device_property_read_bool(dev,
370 + "touchscreen-swapped-x-y");
372 + if (ft6236->swap_xy) {
373 + input_set_abs_params(input, ABS_MT_POSITION_X, 0,
374 + ft6236->max_y, fuzz_y, 0);
375 + input_set_abs_params(input, ABS_MT_POSITION_Y, 0,
376 + ft6236->max_x, fuzz_x, 0);
378 + input_set_abs_params(input, ABS_MT_POSITION_X, 0,
379 + ft6236->max_x, fuzz_x, 0);
380 + input_set_abs_params(input, ABS_MT_POSITION_Y, 0,
381 + ft6236->max_y, fuzz_y, 0);
384 + error = input_mt_init_slots(input, FT6236_MAX_TOUCH_POINTS,
385 + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
389 + error = devm_request_threaded_irq(dev, client->irq, NULL,
390 + ft6236_interrupt, IRQF_ONESHOT,
391 + client->name, ft6236);
393 + dev_err(dev, "request irq %d failed: %d\n", client->irq, error);
397 + error = input_register_device(input);
399 + dev_err(dev, "failed to register input device: %d\n", error);
407 +static const struct of_device_id ft6236_of_match[] = {
408 + { .compatible = "focaltech,ft6236", },
411 +MODULE_DEVICE_TABLE(of, ft6236_of_match);
414 +static const struct i2c_device_id ft6236_id[] = {
418 +MODULE_DEVICE_TABLE(i2c, ft6236_id);
420 +static struct i2c_driver ft6236_driver = {
423 + .owner = THIS_MODULE,
424 + .of_match_table = of_match_ptr(ft6236_of_match),
426 + .probe = ft6236_probe,
427 + .id_table = ft6236_id,
429 +module_i2c_driver(ft6236_driver);
431 +MODULE_AUTHOR("Sean Cross <xobs@kosagi.com>");
432 +MODULE_AUTHOR("Noralf Trønnes <noralf@tronnes.org>");
433 +MODULE_DESCRIPTION("FocalTech FT6236 TouchScreen driver");
434 +MODULE_LICENSE("GPL");