Lines Matching full:ts
77 static int ttsp_read_block_data(struct cyttsp *ts, u8 command, in ttsp_read_block_data() argument
84 error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command, in ttsp_read_block_data()
95 static int ttsp_write_block_data(struct cyttsp *ts, u8 command, in ttsp_write_block_data() argument
102 error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command, in ttsp_write_block_data()
113 static int ttsp_send_command(struct cyttsp *ts, u8 cmd) in ttsp_send_command() argument
115 return ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); in ttsp_send_command()
118 static int cyttsp_handshake(struct cyttsp *ts) in cyttsp_handshake() argument
120 if (ts->use_hndshk) in cyttsp_handshake()
121 return ttsp_send_command(ts, in cyttsp_handshake()
122 ts->xy_data.hst_mode ^ CY_HNDSHK_BIT); in cyttsp_handshake()
127 static int cyttsp_load_bl_regs(struct cyttsp *ts) in cyttsp_load_bl_regs() argument
129 memset(&ts->bl_data, 0, sizeof(ts->bl_data)); in cyttsp_load_bl_regs()
130 ts->bl_data.bl_status = 0x10; in cyttsp_load_bl_regs()
132 return ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_load_bl_regs()
133 sizeof(ts->bl_data), &ts->bl_data); in cyttsp_load_bl_regs()
136 static int cyttsp_exit_bl_mode(struct cyttsp *ts) in cyttsp_exit_bl_mode() argument
142 if (ts->bl_keys) in cyttsp_exit_bl_mode()
144 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_exit_bl_mode()
146 error = ttsp_write_block_data(ts, CY_REG_BASE, in cyttsp_exit_bl_mode()
154 error = cyttsp_load_bl_regs(ts); in cyttsp_exit_bl_mode()
158 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status)) in cyttsp_exit_bl_mode()
164 static int cyttsp_set_operational_mode(struct cyttsp *ts) in cyttsp_set_operational_mode() argument
168 error = ttsp_send_command(ts, CY_OPERATE_MODE); in cyttsp_set_operational_mode()
173 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_set_operational_mode()
174 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_set_operational_mode()
178 error = cyttsp_handshake(ts); in cyttsp_set_operational_mode()
182 return ts->xy_data.act_dist == CY_ACT_DIST_DFLT ? -EIO : 0; in cyttsp_set_operational_mode()
185 static int cyttsp_set_sysinfo_mode(struct cyttsp *ts) in cyttsp_set_sysinfo_mode() argument
189 memset(&ts->sysinfo_data, 0, sizeof(ts->sysinfo_data)); in cyttsp_set_sysinfo_mode()
192 error = ttsp_send_command(ts, CY_SYSINFO_MODE); in cyttsp_set_sysinfo_mode()
198 error = ttsp_read_block_data(ts, CY_REG_BASE, sizeof(ts->sysinfo_data), in cyttsp_set_sysinfo_mode()
199 &ts->sysinfo_data); in cyttsp_set_sysinfo_mode()
203 error = cyttsp_handshake(ts); in cyttsp_set_sysinfo_mode()
207 if (!ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) in cyttsp_set_sysinfo_mode()
213 static int cyttsp_set_sysinfo_regs(struct cyttsp *ts) in cyttsp_set_sysinfo_regs() argument
217 if (ts->act_intrvl != CY_ACT_INTRVL_DFLT || in cyttsp_set_sysinfo_regs()
218 ts->tch_tmout != CY_TCH_TMOUT_DFLT || in cyttsp_set_sysinfo_regs()
219 ts->lp_intrvl != CY_LP_INTRVL_DFLT) { in cyttsp_set_sysinfo_regs()
222 ts->act_intrvl, in cyttsp_set_sysinfo_regs()
223 ts->tch_tmout, in cyttsp_set_sysinfo_regs()
224 ts->lp_intrvl in cyttsp_set_sysinfo_regs()
228 retval = ttsp_write_block_data(ts, CY_REG_ACT_INTRVL, in cyttsp_set_sysinfo_regs()
236 static void cyttsp_hard_reset(struct cyttsp *ts) in cyttsp_hard_reset() argument
238 if (ts->reset_gpio) { in cyttsp_hard_reset()
245 gpiod_set_value_cansleep(ts->reset_gpio, 1); in cyttsp_hard_reset()
247 gpiod_set_value_cansleep(ts->reset_gpio, 0); in cyttsp_hard_reset()
252 static int cyttsp_soft_reset(struct cyttsp *ts) in cyttsp_soft_reset() argument
257 reinit_completion(&ts->bl_ready); in cyttsp_soft_reset()
258 ts->state = CY_BL_STATE; in cyttsp_soft_reset()
260 enable_irq(ts->irq); in cyttsp_soft_reset()
262 retval = ttsp_send_command(ts, CY_SOFT_RESET_MODE); in cyttsp_soft_reset()
264 dev_err(ts->dev, "failed to send soft reset\n"); in cyttsp_soft_reset()
268 if (!wait_for_completion_timeout(&ts->bl_ready, in cyttsp_soft_reset()
270 dev_err(ts->dev, "timeout waiting for soft reset\n"); in cyttsp_soft_reset()
275 ts->state = CY_IDLE_STATE; in cyttsp_soft_reset()
276 disable_irq(ts->irq); in cyttsp_soft_reset()
280 static int cyttsp_act_dist_setup(struct cyttsp *ts) in cyttsp_act_dist_setup() argument
282 u8 act_dist_setup = ts->act_dist; in cyttsp_act_dist_setup()
285 return ttsp_write_block_data(ts, CY_REG_ACT_DIST, in cyttsp_act_dist_setup()
314 static void cyttsp_report_tchdata(struct cyttsp *ts) in cyttsp_report_tchdata() argument
316 struct cyttsp_xydata *xy_data = &ts->xy_data; in cyttsp_report_tchdata()
317 struct input_dev *input = ts->input; in cyttsp_report_tchdata()
327 dev_dbg(ts->dev, "%s: Large area detected\n", __func__); in cyttsp_report_tchdata()
331 dev_dbg(ts->dev, "%s: Num touch error detected\n", __func__); in cyttsp_report_tchdata()
335 dev_dbg(ts->dev, "%s: Invalid buffer detected\n", __func__); in cyttsp_report_tchdata()
367 struct cyttsp *ts = handle; in cyttsp_irq() local
370 if (unlikely(ts->state == CY_BL_STATE)) { in cyttsp_irq()
371 complete(&ts->bl_ready); in cyttsp_irq()
376 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_irq()
377 sizeof(struct cyttsp_xydata), &ts->xy_data); in cyttsp_irq()
382 error = cyttsp_handshake(ts); in cyttsp_irq()
386 if (unlikely(ts->state == CY_IDLE_STATE)) in cyttsp_irq()
389 if (GET_BOOTLOADERMODE(ts->xy_data.tt_mode)) { in cyttsp_irq()
394 error = cyttsp_exit_bl_mode(ts); in cyttsp_irq()
396 dev_err(ts->dev, in cyttsp_irq()
399 ts->state = CY_IDLE_STATE; in cyttsp_irq()
402 cyttsp_report_tchdata(ts); in cyttsp_irq()
409 static int cyttsp_power_on(struct cyttsp *ts) in cyttsp_power_on() argument
413 error = cyttsp_soft_reset(ts); in cyttsp_power_on()
417 error = cyttsp_load_bl_regs(ts); in cyttsp_power_on()
421 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status) && in cyttsp_power_on()
422 IS_VALID_APP(ts->bl_data.bl_status)) { in cyttsp_power_on()
423 error = cyttsp_exit_bl_mode(ts); in cyttsp_power_on()
425 dev_err(ts->dev, "failed to exit bootloader mode\n"); in cyttsp_power_on()
430 if (GET_HSTMODE(ts->bl_data.bl_file) != CY_OPERATE_MODE || in cyttsp_power_on()
431 IS_OPERATIONAL_ERR(ts->bl_data.bl_status)) { in cyttsp_power_on()
435 error = cyttsp_set_sysinfo_mode(ts); in cyttsp_power_on()
439 error = cyttsp_set_sysinfo_regs(ts); in cyttsp_power_on()
443 error = cyttsp_set_operational_mode(ts); in cyttsp_power_on()
448 error = cyttsp_act_dist_setup(ts); in cyttsp_power_on()
452 ts->state = CY_ACTIVE_STATE; in cyttsp_power_on()
457 static int cyttsp_enable(struct cyttsp *ts) in cyttsp_enable() argument
467 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_enable()
468 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_enable()
472 if (GET_HSTMODE(ts->xy_data.hst_mode)) in cyttsp_enable()
475 enable_irq(ts->irq); in cyttsp_enable()
480 static int cyttsp_disable(struct cyttsp *ts) in cyttsp_disable() argument
484 error = ttsp_send_command(ts, CY_LOW_POWER_MODE); in cyttsp_disable()
488 disable_irq(ts->irq); in cyttsp_disable()
495 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_suspend() local
498 mutex_lock(&ts->input->mutex); in cyttsp_suspend()
500 if (input_device_enabled(ts->input)) { in cyttsp_suspend()
501 retval = cyttsp_disable(ts); in cyttsp_suspend()
503 ts->suspended = true; in cyttsp_suspend()
506 mutex_unlock(&ts->input->mutex); in cyttsp_suspend()
513 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_resume() local
515 mutex_lock(&ts->input->mutex); in cyttsp_resume()
517 if (input_device_enabled(ts->input)) in cyttsp_resume()
518 cyttsp_enable(ts); in cyttsp_resume()
520 ts->suspended = false; in cyttsp_resume()
522 mutex_unlock(&ts->input->mutex); in cyttsp_resume()
531 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_open() local
534 if (!ts->suspended) in cyttsp_open()
535 retval = cyttsp_enable(ts); in cyttsp_open()
542 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_close() local
544 if (!ts->suspended) in cyttsp_close()
545 cyttsp_disable(ts); in cyttsp_close()
548 static int cyttsp_parse_properties(struct cyttsp *ts) in cyttsp_parse_properties() argument
550 struct device *dev = ts->dev; in cyttsp_parse_properties()
554 ts->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL); in cyttsp_parse_properties()
555 if (!ts->bl_keys) in cyttsp_parse_properties()
559 ts->use_hndshk = false; in cyttsp_parse_properties()
560 ts->act_dist = CY_ACT_DIST_DFLT; in cyttsp_parse_properties()
561 ts->act_intrvl = CY_ACT_INTRVL_DFLT; in cyttsp_parse_properties()
562 ts->tch_tmout = CY_TCH_TMOUT_DFLT; in cyttsp_parse_properties()
563 ts->lp_intrvl = CY_LP_INTRVL_DFLT; in cyttsp_parse_properties()
566 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_parse_properties()
573 ts->use_hndshk = device_property_present(dev, "use-handshake"); in cyttsp_parse_properties()
581 ts->act_dist &= ~CY_ACT_DIST_MASK; in cyttsp_parse_properties()
582 ts->act_dist |= dt_value; in cyttsp_parse_properties()
591 ts->act_intrvl = dt_value; in cyttsp_parse_properties()
601 ts->lp_intrvl = dt_value / 10; in cyttsp_parse_properties()
611 ts->tch_tmout = dt_value / 10; in cyttsp_parse_properties()
625 struct cyttsp *ts; in cyttsp_probe() local
629 ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL); in cyttsp_probe()
630 if (!ts) in cyttsp_probe()
637 ts->dev = dev; in cyttsp_probe()
638 ts->input = input_dev; in cyttsp_probe()
639 ts->bus_ops = bus_ops; in cyttsp_probe()
640 ts->irq = irq; in cyttsp_probe()
649 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in cyttsp_probe()
650 if (IS_ERR(ts->reset_gpio)) { in cyttsp_probe()
651 error = PTR_ERR(ts->reset_gpio); in cyttsp_probe()
656 error = cyttsp_parse_properties(ts); in cyttsp_probe()
660 init_completion(&ts->bl_ready); in cyttsp_probe()
664 input_dev->dev.parent = ts->dev; in cyttsp_probe()
669 input_set_drvdata(input_dev, ts); in cyttsp_probe()
684 error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, in cyttsp_probe()
686 "cyttsp", ts); in cyttsp_probe()
688 dev_err(ts->dev, "failed to request IRQ %d, err: %d\n", in cyttsp_probe()
689 ts->irq, error); in cyttsp_probe()
693 cyttsp_hard_reset(ts); in cyttsp_probe()
695 error = cyttsp_power_on(ts); in cyttsp_probe()
701 dev_err(ts->dev, "failed to register input device: %d\n", in cyttsp_probe()
706 return ts; in cyttsp_probe()