31 #include <linux/input.h>
35 #include <linux/slab.h>
40 #define CY_NUM_BL_KEYS 8
43 #define GET_NUM_TOUCHES(x) ((x) & 0x0F)
44 #define IS_LARGE_AREA(x) (((x) & 0x10) >> 4)
45 #define IS_BAD_PKT(x) ((x) & 0x20)
46 #define IS_VALID_APP(x) ((x) & 0x01)
47 #define IS_OPERATIONAL_ERR(x) ((x) & 0x3F)
48 #define GET_HSTMODE(reg) (((reg) & 0x70) >> 4)
49 #define GET_BOOTLOADERMODE(reg) (((reg) & 0x10) >> 4)
51 #define CY_REG_BASE 0x00
52 #define CY_REG_ACT_DIST 0x1E
53 #define CY_REG_ACT_INTRVL 0x1D
54 #define CY_REG_TCH_TMOUT (CY_REG_ACT_INTRVL + 1)
55 #define CY_REG_LP_INTRVL (CY_REG_TCH_TMOUT + 1)
57 #define CY_DELAY_DFLT 20
58 #define CY_DELAY_MAX 500
59 #define CY_ACT_DIST_DFLT 0xF8
60 #define CY_HNDSHK_BIT 0x80
62 #define CY_OPERATE_MODE 0x00
63 #define CY_SYSINFO_MODE 0x10
65 #define CY_SOFT_RESET_MODE 0x01
66 #define CY_DEEP_SLEEP_MODE 0x02
67 #define CY_LOW_POWER_MODE 0x04
70 #define CY_MAX_FINGER 4
73 static const u8 bl_command[] = {
77 0, 1, 2, 3, 4, 5, 6, 7
87 error = ts->
bus_ops->read(ts, command, length, buf);
97 static int ttsp_write_block_data(
struct cyttsp *ts,
u8 command,
104 error = ts->
bus_ops->write(ts, command, length, buf);
114 static int ttsp_send_command(
struct cyttsp *ts,
u8 cmd)
116 return ttsp_write_block_data(ts,
CY_REG_BASE,
sizeof(cmd), &cmd);
119 static int cyttsp_load_bl_regs(
struct cyttsp *ts)
128 static int cyttsp_exit_bl_mode(
struct cyttsp *ts)
131 u8 bl_cmd[
sizeof(bl_command)];
133 memcpy(bl_cmd, bl_command,
sizeof(bl_command));
134 if (ts->
pdata->bl_keys)
136 ts->
pdata->bl_keys,
sizeof(bl_command));
139 sizeof(bl_cmd), bl_cmd);
146 error = cyttsp_load_bl_regs(ts);
156 static int cyttsp_set_operational_mode(
struct cyttsp *ts)
173 static int cyttsp_set_sysinfo_mode(
struct cyttsp *ts)
197 static int cyttsp_set_sysinfo_regs(
struct cyttsp *ts)
206 ts->
pdata->act_intrvl,
207 ts->
pdata->tch_tmout,
213 sizeof(intrvl_ray), intrvl_ray);
220 static int cyttsp_soft_reset(
struct cyttsp *ts)
237 retval = timeout ? 0 : -
EIO;
245 static int cyttsp_act_dist_setup(
struct cyttsp *ts)
247 u8 act_dist_setup = ts->
pdata->act_dist;
251 sizeof(act_dist_setup), &act_dist_setup);
254 static void cyttsp_extract_track_ids(
struct cyttsp_xydata *xy_data,
int *ids)
267 return &xy_data->
tch1;
269 return &xy_data->
tch2;
271 return &xy_data->
tch3;
273 return &xy_data->
tch4;
279 static void cyttsp_report_tchdata(
struct cyttsp *ts)
292 dev_dbg(ts->
dev,
"%s: Large area detected\n", __func__);
296 dev_dbg(ts->
dev,
"%s: Num touch error detected\n", __func__);
300 dev_dbg(ts->
dev,
"%s: Invalid buffer detected\n", __func__);
303 cyttsp_extract_track_ids(xy_data, ids);
307 for (i = 0; i < num_tch; i++) {
308 tch = cyttsp_get_tch(xy_data, i);
347 if (ts->
pdata->use_hndshk) {
348 error = ttsp_send_command(ts,
362 error = cyttsp_exit_bl_mode(ts);
365 "Could not return to operational mode, err: %d\n",
370 cyttsp_report_tchdata(ts);
377 static int cyttsp_power_on(
struct cyttsp *ts)
381 error = cyttsp_soft_reset(ts);
385 error = cyttsp_load_bl_regs(ts);
391 error = cyttsp_exit_bl_mode(ts);
401 error = cyttsp_set_sysinfo_mode(ts);
405 error = cyttsp_set_sysinfo_regs(ts);
409 error = cyttsp_set_operational_mode(ts);
414 error = cyttsp_act_dist_setup(ts);
423 static int cyttsp_enable(
struct cyttsp *ts)
446 static int cyttsp_disable(
struct cyttsp *ts)
459 #ifdef CONFIG_PM_SLEEP
460 static int cyttsp_suspend(
struct device *
dev)
467 if (ts->
input->users) {
468 retval = cyttsp_disable(ts);
478 static int cyttsp_resume(
struct device *dev)
484 if (ts->
input->users)
499 static int cyttsp_open(
struct input_dev *dev)
501 struct cyttsp *ts = input_get_drvdata(dev);
505 retval = cyttsp_enable(ts);
510 static void cyttsp_close(
struct input_dev *dev)
512 struct cyttsp *ts = input_get_drvdata(dev);
519 struct device *dev,
int irq,
size_t xfer_buf_size)
523 struct input_dev *input_dev;
526 if (!pdata || !pdata->
name || irq <= 0) {
531 ts = kzalloc(
sizeof(*ts) + xfer_buf_size,
GFP_KERNEL);
532 input_dev = input_allocate_device();
533 if (!ts || !input_dev) {
539 ts->
input = input_dev;
548 error = pdata->
init();
550 dev_err(ts->
dev,
"platform init failed, err: %d\n",
556 input_dev->name = pdata->
name;
557 input_dev->phys = ts->
phys;
558 input_dev->id.bustype = bus_ops->
bustype;
559 input_dev->dev.parent = ts->
dev;
561 input_dev->open = cyttsp_open;
562 input_dev->close = cyttsp_close;
564 input_set_drvdata(input_dev, ts);
568 0, pdata->
maxx, 0, 0);
570 0, pdata->
maxy, 0, 0);
580 dev_err(ts->
dev,
"failed to request IRQ %d, err: %d\n",
582 goto err_platform_exit;
587 error = cyttsp_power_on(ts);
591 error = input_register_device(input_dev);
593 dev_err(ts->
dev,
"failed to register input device: %d\n",
606 input_free_device(input_dev);
609 return ERR_PTR(error);
616 input_unregister_device(ts->
input);