Skip to content

Commit 2dceda4

Browse files
committed
ft5406: Export the start polling function.
Change-Id: Id10b4ad7b0efc1630d4399615c933eb87de961f4
1 parent bc9ed15 commit 2dceda4

File tree

3 files changed

+70
-28
lines changed

3 files changed

+70
-28
lines changed

drivers/input/touchscreen/tinker_ft5406.c

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <linux/workqueue.h>
2727
#include "tinker_ft5406.h"
2828

29+
struct tinker_ft5406_data *g_ts_data = NULL;
30+
2931
static int fts_i2c_read(struct i2c_client *client, char *writebuf,
3032
int writelen, char *readbuf, int readlen)
3133
{
@@ -91,7 +93,7 @@ static int fts_check_fw_ver(struct i2c_client *client)
9193
if (ret < 0)
9294
goto error;
9395

94-
LOG_INFO("Firmware version = %d.%d.%d\n", fw_ver[0], fw_ver[1], fw_ver[2]);
96+
LOG_ERR("Firmware version = %d.%d.%d\n", fw_ver[0], fw_ver[1], fw_ver[2]);
9597
return 0;
9698

9799
error:
@@ -185,15 +187,31 @@ static void fts_report_value(struct tinker_ft5406_data *ts_data)
185187

186188
extern int tinker_mcu_is_connected(void);
187189

190+
static void fts_retry_clear(struct tinker_ft5406_data *ts_data)
191+
{
192+
if (ts_data->retry_count != 0)
193+
ts_data->retry_count = 0;
194+
}
195+
196+
static int fts_retry_wait(struct tinker_ft5406_data *ts_data)
197+
{
198+
if (ts_data->retry_count < RETRY_COUNT) {
199+
LOG_INFO("wait and retry, count = %d\n", ts_data->retry_count)
200+
ts_data->retry_count++;
201+
msleep(1000);
202+
return 1;
203+
}
204+
LOG_ERR("attach retry count\n");
205+
return 0;
206+
}
207+
188208
static void tinker_ft5406_work(struct work_struct *work)
189209
{
190-
struct tinker_ft5406_data *ts_data
191-
= container_of(work, struct tinker_ft5406_data, ft5406_work);
192-
struct ts_event *event = &ts_data->event;
193-
int ret = 0, count = 8, td_status;
210+
struct ts_event *event = &g_ts_data->event;
211+
int ret = 0, count = 5, td_status;
194212

195213
while(count > 0) {
196-
ret = fts_check_fw_ver(ts_data->client);
214+
ret = fts_check_fw_ver(g_ts_data->client);
197215
if (ret == 0)
198216
break;
199217
LOG_INFO("checking touch ic, countdown: %d\n", count);
@@ -202,40 +220,59 @@ static void tinker_ft5406_work(struct work_struct *work)
202220
}
203221
if (!count) {
204222
LOG_ERR("checking touch ic timeout, %d\n", ret);
223+
g_ts_data->is_polling = 0;
205224
return;
206225
}
207226

208227
//polling 60fps
209228
while(1) {
210-
td_status = fts_read_td_status(ts_data);
211-
if (td_status < VALID_TD_STATUS_VAL+1 && (td_status > 0 || ts_data->known_ids != 0)) {
229+
td_status = fts_read_td_status(g_ts_data);
230+
if (td_status < 0) {
231+
ret = fts_retry_wait(g_ts_data);
232+
if (ret == 0) {
233+
LOG_ERR("stop touch polling\n");
234+
g_ts_data->is_polling = 0;
235+
break;
236+
}
237+
} else if (td_status < VALID_TD_STATUS_VAL+1 && (td_status > 0 || g_ts_data->known_ids != 0)) {
238+
fts_retry_clear(g_ts_data);
212239
memset(event, -1, sizeof(struct ts_event));
213240
event->touch_point = td_status;
214-
ret = fts_read_touchdata(ts_data);
241+
ret = fts_read_touchdata(g_ts_data);
215242
if (ret == 0)
216-
fts_report_value(ts_data);
243+
fts_report_value(g_ts_data);
217244
}
218245
msleep_interruptible(17);
219246
}
220247
}
221248

249+
void tinker_ft5406_start_polling(void)
250+
{
251+
if (g_ts_data != NULL && g_ts_data->is_polling != 1) {
252+
g_ts_data->is_polling = 1;
253+
schedule_work(&g_ts_data->ft5406_work);
254+
} else {
255+
LOG_ERR("touch is not ready or busy\n");
256+
}
257+
}
258+
EXPORT_SYMBOL_GPL(tinker_ft5406_start_polling);
259+
222260
static int tinker_ft5406_probe(struct i2c_client *client,
223261
const struct i2c_device_id *id)
224262
{
225-
struct tinker_ft5406_data *ts_data;
226263
struct input_dev *input_dev;
227264
int ret = 0, timeout = 10;
228265

229266
LOG_INFO("address = 0x%x\n", client->addr);
230267

231-
ts_data = kzalloc(sizeof(struct tinker_ft5406_data), GFP_KERNEL);
232-
if (ts_data == NULL) {
268+
g_ts_data = kzalloc(sizeof(struct tinker_ft5406_data), GFP_KERNEL);
269+
if (g_ts_data == NULL) {
233270
LOG_ERR("no memory for device\n");
234271
return -ENOMEM;
235272
}
236273

237-
ts_data->client = client;
238-
i2c_set_clientdata(client, ts_data);
274+
g_ts_data->client = client;
275+
i2c_set_clientdata(client, g_ts_data);
239276

240277
while(!tinker_mcu_is_connected() && timeout > 0) {
241278
msleep(50);
@@ -255,10 +292,10 @@ static int tinker_ft5406_probe(struct i2c_client *client,
255292
}
256293
input_dev->name = "fts_ts";
257294
input_dev->id.bustype = BUS_I2C;
258-
input_dev->dev.parent = &ts_data->client->dev;
295+
input_dev->dev.parent = &g_ts_data->client->dev;
259296

260-
ts_data->input_dev = input_dev;
261-
input_set_drvdata(input_dev, ts_data);
297+
g_ts_data->input_dev = input_dev;
298+
input_set_drvdata(input_dev, g_ts_data);
262299

263300
__set_bit(EV_SYN, input_dev->evbit);
264301
__set_bit(EV_KEY, input_dev->evbit);
@@ -277,29 +314,28 @@ static int tinker_ft5406_probe(struct i2c_client *client,
277314
goto input_register_failed;
278315
}
279316

280-
INIT_WORK(&ts_data->ft5406_work, tinker_ft5406_work);
281-
schedule_work(&ts_data->ft5406_work);
317+
INIT_WORK(&g_ts_data->ft5406_work, tinker_ft5406_work);
282318

283319
return 0;
284320

285321
input_register_failed:
286322
input_free_device(input_dev);
287323
input_allocate_failed:
288324
timeout_failed:
289-
kfree(ts_data);
325+
kfree(g_ts_data);
326+
g_ts_data = NULL;
290327
return ret;
291328
}
292329

293330
static int tinker_ft5406_remove(struct i2c_client *client)
294331
{
295-
struct tinker_ft5406_data *ts_data = i2c_get_clientdata(client);
296-
297-
cancel_work_sync(&ts_data->ft5406_work);
298-
if (ts_data->input_dev) {
299-
input_unregister_device(ts_data->input_dev);
300-
input_free_device(ts_data->input_dev);
332+
cancel_work_sync(&g_ts_data->ft5406_work);
333+
if (g_ts_data->input_dev) {
334+
input_unregister_device(g_ts_data->input_dev);
335+
input_free_device(g_ts_data->input_dev);
301336
}
302-
kfree(ts_data);
337+
kfree(g_ts_data);
338+
g_ts_data = NULL;
303339
return 0;
304340
}
305341

drivers/input/touchscreen/tinker_ft5406.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define LOG_INFO(fmt,arg...) pr_info("tinker-ft5406: %s: "fmt, __func__, ##arg);
66
#define LOG_ERR(fmt,arg...) pr_err("tinker-ft5406: %s: "fmt, __func__, ##arg);
77

8+
#define RETRY_COUNT 10
89
#define XY_REVERSE 1
910

1011
#define SCREEN_WIDTH 800
@@ -57,7 +58,9 @@ struct tinker_ft5406_data {
5758
struct ts_event event;
5859
struct work_struct ft5406_work;
5960

61+
int is_polling;
6062
int known_ids;
63+
int retry_count;
6164
};
6265

6366
#endif

drivers/miniarm/dsi/panel-toshiba-tc358762.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ static int tc358762_prepare(struct drm_panel *panel)
296296
}
297297

298298
extern void tinker_mcu_screen_power_up(void);
299+
extern void tinker_ft5406_start_polling(void);
299300
static int tc358762_enable(struct drm_panel *panel)
300301
{
301302
struct tc358762 *p = to_tc358762(panel);
@@ -308,6 +309,8 @@ static int tc358762_enable(struct drm_panel *panel)
308309
if(trigger_bridge) {
309310
pr_info("tinker_mcu_screen_power_up");
310311
tinker_mcu_screen_power_up();
312+
msleep(100);
313+
tinker_ft5406_start_polling();
311314
trigger_bridge = 0;
312315
}
313316

0 commit comments

Comments
 (0)