Lines Matching full:ts
70 static int ttsp_read_block_data(struct cyttsp *ts, u8 command, in ttsp_read_block_data() argument
77 error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command, in ttsp_read_block_data()
88 static int ttsp_write_block_data(struct cyttsp *ts, u8 command, in ttsp_write_block_data() argument
95 error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command, in ttsp_write_block_data()
106 static int ttsp_send_command(struct cyttsp *ts, u8 cmd) in ttsp_send_command() argument
108 return ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); in ttsp_send_command()
111 static int cyttsp_handshake(struct cyttsp *ts) in cyttsp_handshake() argument
113 if (ts->use_hndshk) in cyttsp_handshake()
114 return ttsp_send_command(ts, in cyttsp_handshake()
115 ts->xy_data.hst_mode ^ CY_HNDSHK_BIT); in cyttsp_handshake()
120 static int cyttsp_load_bl_regs(struct cyttsp *ts) in cyttsp_load_bl_regs() argument
122 memset(&ts->bl_data, 0, sizeof(ts->bl_data)); in cyttsp_load_bl_regs()
123 ts->bl_data.bl_status = 0x10; in cyttsp_load_bl_regs()
125 return ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_load_bl_regs()
126 sizeof(ts->bl_data), &ts->bl_data); in cyttsp_load_bl_regs()
129 static int cyttsp_exit_bl_mode(struct cyttsp *ts) in cyttsp_exit_bl_mode() argument
135 if (ts->bl_keys) in cyttsp_exit_bl_mode()
137 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_exit_bl_mode()
139 error = ttsp_write_block_data(ts, CY_REG_BASE, in cyttsp_exit_bl_mode()
147 error = cyttsp_load_bl_regs(ts); in cyttsp_exit_bl_mode()
151 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status)) in cyttsp_exit_bl_mode()
157 static int cyttsp_set_operational_mode(struct cyttsp *ts) in cyttsp_set_operational_mode() argument
161 error = ttsp_send_command(ts, CY_OPERATE_MODE); in cyttsp_set_operational_mode()
166 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_set_operational_mode()
167 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_set_operational_mode()
171 error = cyttsp_handshake(ts); in cyttsp_set_operational_mode()
175 return ts->xy_data.act_dist == CY_ACT_DIST_DFLT ? -EIO : 0; in cyttsp_set_operational_mode()
178 static int cyttsp_set_sysinfo_mode(struct cyttsp *ts) in cyttsp_set_sysinfo_mode() argument
182 memset(&ts->sysinfo_data, 0, sizeof(ts->sysinfo_data)); in cyttsp_set_sysinfo_mode()
185 error = ttsp_send_command(ts, CY_SYSINFO_MODE); in cyttsp_set_sysinfo_mode()
191 error = ttsp_read_block_data(ts, CY_REG_BASE, sizeof(ts->sysinfo_data), in cyttsp_set_sysinfo_mode()
192 &ts->sysinfo_data); in cyttsp_set_sysinfo_mode()
196 error = cyttsp_handshake(ts); in cyttsp_set_sysinfo_mode()
200 if (!ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) in cyttsp_set_sysinfo_mode()
206 static int cyttsp_set_sysinfo_regs(struct cyttsp *ts) in cyttsp_set_sysinfo_regs() argument
210 if (ts->act_intrvl != CY_ACT_INTRVL_DFLT || in cyttsp_set_sysinfo_regs()
211 ts->tch_tmout != CY_TCH_TMOUT_DFLT || in cyttsp_set_sysinfo_regs()
212 ts->lp_intrvl != CY_LP_INTRVL_DFLT) { in cyttsp_set_sysinfo_regs()
215 ts->act_intrvl, in cyttsp_set_sysinfo_regs()
216 ts->tch_tmout, in cyttsp_set_sysinfo_regs()
217 ts->lp_intrvl in cyttsp_set_sysinfo_regs()
221 retval = ttsp_write_block_data(ts, CY_REG_ACT_INTRVL, in cyttsp_set_sysinfo_regs()
229 static void cyttsp_hard_reset(struct cyttsp *ts) in cyttsp_hard_reset() argument
231 if (ts->reset_gpio) { in cyttsp_hard_reset()
232 gpiod_set_value_cansleep(ts->reset_gpio, 1); in cyttsp_hard_reset()
234 gpiod_set_value_cansleep(ts->reset_gpio, 0); in cyttsp_hard_reset()
239 static int cyttsp_soft_reset(struct cyttsp *ts) in cyttsp_soft_reset() argument
245 reinit_completion(&ts->bl_ready); in cyttsp_soft_reset()
246 ts->state = CY_BL_STATE; in cyttsp_soft_reset()
248 enable_irq(ts->irq); in cyttsp_soft_reset()
250 retval = ttsp_send_command(ts, CY_SOFT_RESET_MODE); in cyttsp_soft_reset()
254 timeout = wait_for_completion_timeout(&ts->bl_ready, in cyttsp_soft_reset()
259 ts->state = CY_IDLE_STATE; in cyttsp_soft_reset()
260 disable_irq(ts->irq); in cyttsp_soft_reset()
264 static int cyttsp_act_dist_setup(struct cyttsp *ts) in cyttsp_act_dist_setup() argument
266 u8 act_dist_setup = ts->act_dist; in cyttsp_act_dist_setup()
269 return ttsp_write_block_data(ts, CY_REG_ACT_DIST, in cyttsp_act_dist_setup()
298 static void cyttsp_report_tchdata(struct cyttsp *ts) in cyttsp_report_tchdata() argument
300 struct cyttsp_xydata *xy_data = &ts->xy_data; in cyttsp_report_tchdata()
301 struct input_dev *input = ts->input; in cyttsp_report_tchdata()
311 dev_dbg(ts->dev, "%s: Large area detected\n", __func__); in cyttsp_report_tchdata()
315 dev_dbg(ts->dev, "%s: Num touch error detected\n", __func__); in cyttsp_report_tchdata()
319 dev_dbg(ts->dev, "%s: Invalid buffer detected\n", __func__); in cyttsp_report_tchdata()
351 struct cyttsp *ts = handle; in cyttsp_irq() local
354 if (unlikely(ts->state == CY_BL_STATE)) { in cyttsp_irq()
355 complete(&ts->bl_ready); in cyttsp_irq()
360 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_irq()
361 sizeof(struct cyttsp_xydata), &ts->xy_data); in cyttsp_irq()
366 error = cyttsp_handshake(ts); in cyttsp_irq()
370 if (unlikely(ts->state == CY_IDLE_STATE)) in cyttsp_irq()
373 if (GET_BOOTLOADERMODE(ts->xy_data.tt_mode)) { in cyttsp_irq()
378 error = cyttsp_exit_bl_mode(ts); in cyttsp_irq()
380 dev_err(ts->dev, in cyttsp_irq()
383 ts->state = CY_IDLE_STATE; in cyttsp_irq()
386 cyttsp_report_tchdata(ts); in cyttsp_irq()
393 static int cyttsp_power_on(struct cyttsp *ts) in cyttsp_power_on() argument
397 error = cyttsp_soft_reset(ts); in cyttsp_power_on()
401 error = cyttsp_load_bl_regs(ts); in cyttsp_power_on()
405 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status) && in cyttsp_power_on()
406 IS_VALID_APP(ts->bl_data.bl_status)) { in cyttsp_power_on()
407 error = cyttsp_exit_bl_mode(ts); in cyttsp_power_on()
412 if (GET_HSTMODE(ts->bl_data.bl_file) != CY_OPERATE_MODE || in cyttsp_power_on()
413 IS_OPERATIONAL_ERR(ts->bl_data.bl_status)) { in cyttsp_power_on()
417 error = cyttsp_set_sysinfo_mode(ts); in cyttsp_power_on()
421 error = cyttsp_set_sysinfo_regs(ts); in cyttsp_power_on()
425 error = cyttsp_set_operational_mode(ts); in cyttsp_power_on()
430 error = cyttsp_act_dist_setup(ts); in cyttsp_power_on()
434 ts->state = CY_ACTIVE_STATE; in cyttsp_power_on()
439 static int cyttsp_enable(struct cyttsp *ts) in cyttsp_enable() argument
449 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_enable()
450 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_enable()
454 if (GET_HSTMODE(ts->xy_data.hst_mode)) in cyttsp_enable()
457 enable_irq(ts->irq); in cyttsp_enable()
462 static int cyttsp_disable(struct cyttsp *ts) in cyttsp_disable() argument
466 error = ttsp_send_command(ts, CY_LOW_POWER_MODE); in cyttsp_disable()
470 disable_irq(ts->irq); in cyttsp_disable()
477 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_suspend() local
480 mutex_lock(&ts->input->mutex); in cyttsp_suspend()
482 if (ts->input->users) { in cyttsp_suspend()
483 retval = cyttsp_disable(ts); in cyttsp_suspend()
485 ts->suspended = true; in cyttsp_suspend()
488 mutex_unlock(&ts->input->mutex); in cyttsp_suspend()
495 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_resume() local
497 mutex_lock(&ts->input->mutex); in cyttsp_resume()
499 if (ts->input->users) in cyttsp_resume()
500 cyttsp_enable(ts); in cyttsp_resume()
502 ts->suspended = false; in cyttsp_resume()
504 mutex_unlock(&ts->input->mutex); in cyttsp_resume()
514 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_open() local
517 if (!ts->suspended) in cyttsp_open()
518 retval = cyttsp_enable(ts); in cyttsp_open()
525 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_close() local
527 if (!ts->suspended) in cyttsp_close()
528 cyttsp_disable(ts); in cyttsp_close()
531 static int cyttsp_parse_properties(struct cyttsp *ts) in cyttsp_parse_properties() argument
533 struct device *dev = ts->dev; in cyttsp_parse_properties()
537 ts->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL); in cyttsp_parse_properties()
538 if (!ts->bl_keys) in cyttsp_parse_properties()
542 ts->use_hndshk = false; in cyttsp_parse_properties()
543 ts->act_dist = CY_ACT_DIST_DFLT; in cyttsp_parse_properties()
544 ts->act_intrvl = CY_ACT_INTRVL_DFLT; in cyttsp_parse_properties()
545 ts->tch_tmout = CY_TCH_TMOUT_DFLT; in cyttsp_parse_properties()
546 ts->lp_intrvl = CY_LP_INTRVL_DFLT; in cyttsp_parse_properties()
549 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_parse_properties()
556 ts->use_hndshk = device_property_present(dev, "use-handshake"); in cyttsp_parse_properties()
564 ts->act_dist &= ~CY_ACT_DIST_MASK; in cyttsp_parse_properties()
565 ts->act_dist |= dt_value; in cyttsp_parse_properties()
574 ts->act_intrvl = dt_value; in cyttsp_parse_properties()
584 ts->lp_intrvl = dt_value / 10; in cyttsp_parse_properties()
594 ts->tch_tmout = dt_value / 10; in cyttsp_parse_properties()
603 struct cyttsp *ts; in cyttsp_probe() local
607 ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL); in cyttsp_probe()
608 if (!ts) in cyttsp_probe()
615 ts->dev = dev; in cyttsp_probe()
616 ts->input = input_dev; in cyttsp_probe()
617 ts->bus_ops = bus_ops; in cyttsp_probe()
618 ts->irq = irq; in cyttsp_probe()
620 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in cyttsp_probe()
621 if (IS_ERR(ts->reset_gpio)) { in cyttsp_probe()
622 error = PTR_ERR(ts->reset_gpio); in cyttsp_probe()
627 error = cyttsp_parse_properties(ts); in cyttsp_probe()
631 init_completion(&ts->bl_ready); in cyttsp_probe()
632 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in cyttsp_probe()
635 input_dev->phys = ts->phys; in cyttsp_probe()
637 input_dev->dev.parent = ts->dev; in cyttsp_probe()
642 input_set_drvdata(input_dev, ts); in cyttsp_probe()
654 error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, in cyttsp_probe()
656 "cyttsp", ts); in cyttsp_probe()
658 dev_err(ts->dev, "failed to request IRQ %d, err: %d\n", in cyttsp_probe()
659 ts->irq, error); in cyttsp_probe()
663 disable_irq(ts->irq); in cyttsp_probe()
665 cyttsp_hard_reset(ts); in cyttsp_probe()
667 error = cyttsp_power_on(ts); in cyttsp_probe()
673 dev_err(ts->dev, "failed to register input device: %d\n", in cyttsp_probe()
678 return ts; in cyttsp_probe()