MINIARM: ts: Add the ft5406 touch driver for tinker board.
Change-Id: I03eeb48d60cfad984038bf2301f7bb41d4d95804
This commit is contained in:
committed by
Jacob Chen
parent
a62972a55d
commit
8f299bac54
@@ -40,6 +40,12 @@ static struct i2c_board_info __initdata i2c_devices_tinker_mcu[] = {
|
||||
},
|
||||
};
|
||||
|
||||
static struct i2c_board_info __initdata i2c_devices_tinker_ft5406[] = {
|
||||
{
|
||||
I2C_BOARD_INFO("tinker_ft5406", 0x38),
|
||||
},
|
||||
};
|
||||
|
||||
static void __init rockchip_timer_init(void)
|
||||
{
|
||||
if (of_machine_is_compatible("rockchip,rk3288")) {
|
||||
@@ -71,6 +77,7 @@ static void __init rockchip_dt_init(void)
|
||||
platform_device_register_simple("cpufreq-dt", 0, NULL, 0);
|
||||
|
||||
i2c_register_board_info(3, i2c_devices_tinker_mcu, ARRAY_SIZE(i2c_devices_tinker_mcu));
|
||||
i2c_register_board_info(3, i2c_devices_tinker_ft5406, ARRAY_SIZE(i2c_devices_tinker_ft5406));
|
||||
}
|
||||
|
||||
static const char * const rockchip_board_dt_compat[] = {
|
||||
|
||||
@@ -34,3 +34,10 @@ config TINKER_MCU
|
||||
depends on I2C
|
||||
help
|
||||
Control the power of touch screen for tinker board.
|
||||
|
||||
config TOUCHSCREEN_TINKER_FT5406
|
||||
tristate "tinker ft5406"
|
||||
default y
|
||||
depends on I2C
|
||||
help
|
||||
Control ft5406 touch ic.
|
||||
|
||||
@@ -2,3 +2,4 @@ obj-$(CONFIG_DRM_PANEL_TOSHIBA_TC358762) += panel-toshiba-tc358762.o
|
||||
obj-$(CONFIG_ASUS_RPI_MCU) += asus_mcu.o
|
||||
obj-$(CONFIG_ROCKCHIP_DW_MIPI_DSI2) += dw-mipi-dsi.o
|
||||
obj-$(CONFIG_TINKER_MCU) += tinker_mcu.o
|
||||
obj-$(CONFIG_TOUCHSCREEN_TINKER_FT5406) += tinker_ft5406.o
|
||||
|
||||
323
drivers/miniarm/dsi/tinker_ft5406.c
Normal file
323
drivers/miniarm/dsi/tinker_ft5406.c
Normal file
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
*
|
||||
* TINKER BOARD FT5406 touch driver.
|
||||
*
|
||||
* Copyright (c) 2016 ASUSTek Computer Inc.
|
||||
* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/input/mt.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include "tinker_ft5406.h"
|
||||
|
||||
static int fts_i2c_read(struct i2c_client *client, char *writebuf,
|
||||
int writelen, char *readbuf, int readlen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (writelen > 0) {
|
||||
struct i2c_msg msgs[] = {
|
||||
{
|
||||
.addr = client->addr,
|
||||
.flags = 0,
|
||||
.len = writelen,
|
||||
.buf = writebuf,
|
||||
},
|
||||
{
|
||||
.addr = client->addr,
|
||||
.flags = I2C_M_RD,
|
||||
.len = readlen,
|
||||
.buf = readbuf,
|
||||
},
|
||||
};
|
||||
ret = i2c_transfer(client->adapter, msgs, 2);
|
||||
if (ret < 0)
|
||||
LOG_ERR("i2c read error, %d\n", ret);
|
||||
} else {
|
||||
struct i2c_msg msgs[] = {
|
||||
{
|
||||
.addr = client->addr,
|
||||
.flags = I2C_M_RD,
|
||||
.len = readlen,
|
||||
.buf = readbuf,
|
||||
},
|
||||
};
|
||||
ret = i2c_transfer(client->adapter, msgs, 1);
|
||||
if (ret < 0)
|
||||
LOG_ERR("i2c read error, %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fts_read_reg(struct i2c_client *client, u8 addr, u8 *val)
|
||||
{
|
||||
return fts_i2c_read(client, &addr, 1, val, 1);
|
||||
}
|
||||
|
||||
static int fts_check_fw_ver(struct i2c_client *client)
|
||||
{
|
||||
u8 reg_addr, fw_ver[3];
|
||||
int ret;
|
||||
|
||||
reg_addr = FT_REG_FW_VER;
|
||||
ret = fts_i2c_read(client, ®_addr, 1, &fw_ver[0], 1);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
reg_addr = FT_REG_FW_MIN_VER;
|
||||
ret = fts_i2c_read(client, ®_addr, 1, &fw_ver[1], 1);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
reg_addr = FT_REG_FW_SUB_MIN_VER;
|
||||
ret = fts_i2c_read(client, ®_addr, 1, &fw_ver[2], 1);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
LOG_INFO("Firmware version = %d.%d.%d\n", fw_ver[0], fw_ver[1], fw_ver[2]);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fts_read_td_status(struct tinker_ft5406_data *ts_data)
|
||||
{
|
||||
u8 td_status;
|
||||
int ret = -1;
|
||||
ret = fts_read_reg(ts_data->client, FT_TD_STATUS_REG, &td_status);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("get reg td_status failed, %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
return (int)td_status;
|
||||
}
|
||||
|
||||
static int fts_read_touchdata(struct tinker_ft5406_data *ts_data)
|
||||
{
|
||||
struct ts_event *event = &ts_data->event;
|
||||
int ret = -1, i;
|
||||
u8 buf[FT_ONE_TCH_LEN-2] = { 0 };
|
||||
u8 reg_addr, pointid = FT_MAX_ID;
|
||||
|
||||
for (i = 0; i < event->touch_point && i < MAX_TOUCH_POINTS; i++) {
|
||||
reg_addr = FT_TOUCH_X_H_REG + (i * FT_ONE_TCH_LEN);
|
||||
ret = fts_i2c_read(ts_data->client, ®_addr, 1, buf, FT_ONE_TCH_LEN-2);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("read touchdata failed.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
pointid = (buf[FT_TOUCH_ID]) >> 4;
|
||||
if (pointid >= MAX_TOUCH_POINTS)
|
||||
break;
|
||||
event->au8_finger_id[i] = pointid;
|
||||
event->au16_x[i] = (s16) (buf[FT_TOUCH_X_H] & 0x0F) << 8 | (s16) buf[FT_TOUCH_X_L];
|
||||
event->au16_y[i] = (s16) (buf[FT_TOUCH_Y_H] & 0x0F) << 8 | (s16) buf[FT_TOUCH_Y_L];
|
||||
event->au8_touch_event[i] = buf[FT_TOUCH_EVENT] >> 6;
|
||||
|
||||
#if XY_REVERSE
|
||||
event->au16_x[i] = SCREEN_WIDTH - event->au16_x[i] - 1;
|
||||
event->au16_y[i] = SCREEN_HEIGHT - event->au16_y[i] - 1;
|
||||
#endif
|
||||
}
|
||||
event->pressure = FT_PRESS;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fts_report_value(struct tinker_ft5406_data *ts_data)
|
||||
{
|
||||
struct ts_event *event = &ts_data->event;
|
||||
int i, modified_ids = 0, released_ids;
|
||||
|
||||
for (i = 0; i < event->touch_point && i < MAX_TOUCH_POINTS; i++) {
|
||||
if (event->au8_touch_event[i]== FT_TOUCH_DOWN
|
||||
|| event->au8_touch_event[i] == FT_TOUCH_CONTACT)
|
||||
{
|
||||
modified_ids |= 1 << event->au8_finger_id[i];
|
||||
input_mt_slot(ts_data->input_dev, event->au8_finger_id[i]);
|
||||
input_mt_report_slot_state(ts_data->input_dev, MT_TOOL_FINGER,
|
||||
true);
|
||||
input_report_abs(ts_data->input_dev, ABS_MT_TOUCH_MAJOR,
|
||||
event->pressure);
|
||||
input_report_abs(ts_data->input_dev, ABS_MT_POSITION_X,
|
||||
event->au16_x[i]);
|
||||
input_report_abs(ts_data->input_dev, ABS_MT_POSITION_Y,
|
||||
event->au16_y[i]);
|
||||
|
||||
if(!((1 << event->au8_finger_id[i]) & ts_data->known_ids))
|
||||
LOG_DBG("Touch id-%d: x = %d, y = %d\n",
|
||||
event->au8_finger_id[i], event->au16_x[i], event->au16_y[i]);
|
||||
}
|
||||
}
|
||||
|
||||
released_ids = ts_data->known_ids & ~modified_ids;
|
||||
for(i = 0; released_ids && i < MAX_TOUCH_POINTS; i++) {
|
||||
if(released_ids & (1<<i)) {
|
||||
LOG_DBG("Release id-%d, known = %x modified = %x\n", i, ts_data->known_ids, modified_ids);
|
||||
input_mt_slot(ts_data->input_dev, i);
|
||||
input_mt_report_slot_state(ts_data->input_dev, MT_TOOL_FINGER, false);
|
||||
modified_ids &= ~(1 << i);
|
||||
}
|
||||
}
|
||||
ts_data->known_ids = modified_ids;
|
||||
input_mt_report_pointer_emulation(ts_data->input_dev, true);
|
||||
input_sync(ts_data->input_dev);
|
||||
}
|
||||
|
||||
extern int tinker_mcu_is_connected(void);
|
||||
|
||||
static void tinker_ft5406_work(struct work_struct *work)
|
||||
{
|
||||
struct tinker_ft5406_data *ts_data
|
||||
= container_of(work, struct tinker_ft5406_data, ft5406_work);
|
||||
struct ts_event *event = &ts_data->event;
|
||||
int ret = 0, count = 8, td_status;
|
||||
|
||||
while(count > 0) {
|
||||
ret = fts_check_fw_ver(ts_data->client);
|
||||
if (ret == 0)
|
||||
break;
|
||||
LOG_INFO("checking touch ic, countdown: %d\n", count);
|
||||
msleep(1000);
|
||||
count--;
|
||||
}
|
||||
if (!count) {
|
||||
LOG_ERR("checking touch ic timeout, %d\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
//polling 60fps
|
||||
while(1) {
|
||||
td_status = fts_read_td_status(ts_data);
|
||||
if (td_status < VALID_TD_STATUS_VAL+1 && (td_status > 0 || ts_data->known_ids != 0)) {
|
||||
memset(event, -1, sizeof(struct ts_event));
|
||||
event->touch_point = td_status;
|
||||
ret = fts_read_touchdata(ts_data);
|
||||
if (ret == 0)
|
||||
fts_report_value(ts_data);
|
||||
}
|
||||
msleep_interruptible(17);
|
||||
}
|
||||
}
|
||||
|
||||
static int tinker_ft5406_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
struct tinker_ft5406_data *ts_data;
|
||||
struct input_dev *input_dev;
|
||||
int ret = 0, timeout = 10;
|
||||
|
||||
LOG_INFO("address = 0x%x\n", client->addr);
|
||||
|
||||
ts_data = kzalloc(sizeof(struct tinker_ft5406_data), GFP_KERNEL);
|
||||
if (ts_data == NULL) {
|
||||
LOG_ERR("no memory for device\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ts_data->client = client;
|
||||
i2c_set_clientdata(client, ts_data);
|
||||
|
||||
while(!tinker_mcu_is_connected() && timeout > 0) {
|
||||
msleep(50);
|
||||
timeout--;
|
||||
}
|
||||
|
||||
if (timeout == 0) {
|
||||
LOG_ERR("wait connected timeout\n");
|
||||
ret = -ENODEV;
|
||||
goto timeout_failed;
|
||||
}
|
||||
|
||||
input_dev = input_allocate_device();
|
||||
if (!input_dev) {
|
||||
LOG_ERR("failed to allocate input device\n");
|
||||
goto input_allocate_failed;
|
||||
}
|
||||
input_dev->name = "fts_ts";
|
||||
input_dev->id.bustype = BUS_I2C;
|
||||
input_dev->dev.parent = &ts_data->client->dev;
|
||||
|
||||
ts_data->input_dev = input_dev;
|
||||
input_set_drvdata(input_dev, ts_data);
|
||||
|
||||
__set_bit(EV_SYN, input_dev->evbit);
|
||||
__set_bit(EV_KEY, input_dev->evbit);
|
||||
__set_bit(EV_ABS, input_dev->evbit);
|
||||
__set_bit(BTN_TOUCH, input_dev->keybit);
|
||||
|
||||
input_mt_init_slots(input_dev, MAX_TOUCH_POINTS, 0);
|
||||
input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
|
||||
SCREEN_WIDTH, 0, 0);
|
||||
input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
|
||||
SCREEN_HEIGHT, 0, 0);
|
||||
|
||||
ret = input_register_device(input_dev);
|
||||
if (ret) {
|
||||
LOG_ERR("Input device registration failed\n");
|
||||
goto input_register_failed;
|
||||
}
|
||||
|
||||
INIT_WORK(&ts_data->ft5406_work, tinker_ft5406_work);
|
||||
schedule_work(&ts_data->ft5406_work);
|
||||
|
||||
return 0;
|
||||
|
||||
input_register_failed:
|
||||
input_free_device(input_dev);
|
||||
input_allocate_failed:
|
||||
timeout_failed:
|
||||
kfree(ts_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tinker_ft5406_remove(struct i2c_client *client)
|
||||
{
|
||||
struct tinker_ft5406_data *ts_data = i2c_get_clientdata(client);
|
||||
|
||||
cancel_work_sync(&ts_data->ft5406_work);
|
||||
if (ts_data->input_dev) {
|
||||
input_unregister_device(ts_data->input_dev);
|
||||
input_free_device(ts_data->input_dev);
|
||||
}
|
||||
kfree(ts_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id tinker_ft5406_id[] = {
|
||||
{"tinker_ft5406", 0},
|
||||
{},
|
||||
};
|
||||
|
||||
static struct i2c_driver tinker_ft5406_driver = {
|
||||
.driver = {
|
||||
.name = "tinker_ft5406",
|
||||
},
|
||||
.probe = tinker_ft5406_probe,
|
||||
.remove = tinker_ft5406_remove,
|
||||
.id_table = tinker_ft5406_id,
|
||||
};
|
||||
module_i2c_driver(tinker_ft5406_driver);
|
||||
|
||||
MODULE_DESCRIPTION("TINKER BOARD FT5406 Touch driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
64
drivers/miniarm/dsi/tinker_ft5406.h
Normal file
64
drivers/miniarm/dsi/tinker_ft5406.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _TINKER_FT5406_H_
|
||||
#define _TINKER_FT5406_H_
|
||||
|
||||
#define LOG_DBG(fmt,arg...) pr_debug("tinker-ft5406: %s: "fmt, __func__, ##arg);
|
||||
#define LOG_INFO(fmt,arg...) pr_info("tinker-ft5406: %s: "fmt, __func__, ##arg);
|
||||
#define LOG_ERR(fmt,arg...) pr_err("tinker-ft5406: %s: "fmt, __func__, ##arg);
|
||||
|
||||
#define XY_REVERSE 1
|
||||
|
||||
#define SCREEN_WIDTH 800
|
||||
#define SCREEN_HEIGHT 480
|
||||
|
||||
#define FT_ONE_TCH_LEN 6
|
||||
|
||||
#define FT_REG_FW_VER 0xA6
|
||||
#define FT_REG_FW_MIN_VER 0xB2
|
||||
#define FT_REG_FW_SUB_MIN_VER 0xB3
|
||||
|
||||
#define VALID_TD_STATUS_VAL 10
|
||||
#define MAX_TOUCH_POINTS 1
|
||||
|
||||
#define FT_PRESS 0x7F
|
||||
#define FT_MAX_ID 0x0F
|
||||
|
||||
#define FT_TOUCH_X_H 0
|
||||
#define FT_TOUCH_X_L 1
|
||||
#define FT_TOUCH_Y_H 2
|
||||
#define FT_TOUCH_Y_L 3
|
||||
#define FT_TOUCH_EVENT 0
|
||||
#define FT_TOUCH_ID 2
|
||||
|
||||
#define FT_TOUCH_X_H_REG 3
|
||||
#define FT_TOUCH_X_L_REG 4
|
||||
#define FT_TOUCH_Y_H_REG 5
|
||||
#define FT_TOUCH_Y_L_REG 6
|
||||
#define FT_TD_STATUS_REG 2
|
||||
#define FT_TOUCH_EVENT_REG 3
|
||||
#define FT_TOUCH_ID_REG 5
|
||||
|
||||
#define FT_TOUCH_DOWN 0
|
||||
#define FT_TOUCH_CONTACT 2
|
||||
|
||||
struct ts_event {
|
||||
u16 au16_x[MAX_TOUCH_POINTS]; /*x coordinate */
|
||||
u16 au16_y[MAX_TOUCH_POINTS]; /*y coordinate */
|
||||
u8 au8_touch_event[MAX_TOUCH_POINTS]; /*touch event: 0:down; 1:up; 2:contact */
|
||||
u8 au8_finger_id[MAX_TOUCH_POINTS]; /*touch ID */
|
||||
u16 pressure;
|
||||
u8 touch_point;
|
||||
u8 point_num;
|
||||
};
|
||||
|
||||
struct tinker_ft5406_data {
|
||||
struct device *dev;
|
||||
struct i2c_client *client;
|
||||
struct input_dev *input_dev;
|
||||
struct ts_event event;
|
||||
struct work_struct ft5406_work;
|
||||
|
||||
int known_ids;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user