Lines Matching refs:ts
84 static int ttsp_read_block_data(struct cyttsp *ts, u8 command, in ttsp_read_block_data() argument
91 error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command, in ttsp_read_block_data()
102 static int ttsp_write_block_data(struct cyttsp *ts, u8 command, in ttsp_write_block_data() argument
109 error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command, in ttsp_write_block_data()
120 static int ttsp_send_command(struct cyttsp *ts, u8 cmd) in ttsp_send_command() argument
122 return ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); in ttsp_send_command()
125 static int cyttsp_handshake(struct cyttsp *ts) in cyttsp_handshake() argument
127 if (ts->use_hndshk) in cyttsp_handshake()
128 return ttsp_send_command(ts, in cyttsp_handshake()
129 ts->xy_data.hst_mode ^ CY_HNDSHK_BIT); in cyttsp_handshake()
134 static int cyttsp_load_bl_regs(struct cyttsp *ts) in cyttsp_load_bl_regs() argument
136 memset(&ts->bl_data, 0, sizeof(ts->bl_data)); in cyttsp_load_bl_regs()
137 ts->bl_data.bl_status = 0x10; in cyttsp_load_bl_regs()
139 return ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_load_bl_regs()
140 sizeof(ts->bl_data), &ts->bl_data); in cyttsp_load_bl_regs()
143 static int cyttsp_exit_bl_mode(struct cyttsp *ts) in cyttsp_exit_bl_mode() argument
149 if (ts->bl_keys) in cyttsp_exit_bl_mode()
151 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_exit_bl_mode()
153 error = ttsp_write_block_data(ts, CY_REG_BASE, in cyttsp_exit_bl_mode()
161 error = cyttsp_load_bl_regs(ts); in cyttsp_exit_bl_mode()
165 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status)) in cyttsp_exit_bl_mode()
171 static int cyttsp_set_operational_mode(struct cyttsp *ts) in cyttsp_set_operational_mode() argument
175 error = ttsp_send_command(ts, CY_OPERATE_MODE); in cyttsp_set_operational_mode()
180 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_set_operational_mode()
181 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_set_operational_mode()
185 error = cyttsp_handshake(ts); in cyttsp_set_operational_mode()
189 return ts->xy_data.act_dist == CY_ACT_DIST_DFLT ? -EIO : 0; in cyttsp_set_operational_mode()
192 static int cyttsp_set_sysinfo_mode(struct cyttsp *ts) in cyttsp_set_sysinfo_mode() argument
196 memset(&ts->sysinfo_data, 0, sizeof(ts->sysinfo_data)); in cyttsp_set_sysinfo_mode()
199 error = ttsp_send_command(ts, CY_SYSINFO_MODE); in cyttsp_set_sysinfo_mode()
205 error = ttsp_read_block_data(ts, CY_REG_BASE, sizeof(ts->sysinfo_data), in cyttsp_set_sysinfo_mode()
206 &ts->sysinfo_data); in cyttsp_set_sysinfo_mode()
210 error = cyttsp_handshake(ts); in cyttsp_set_sysinfo_mode()
214 if (!ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) in cyttsp_set_sysinfo_mode()
220 static int cyttsp_set_sysinfo_regs(struct cyttsp *ts) in cyttsp_set_sysinfo_regs() argument
224 if (ts->act_intrvl != CY_ACT_INTRVL_DFLT || in cyttsp_set_sysinfo_regs()
225 ts->tch_tmout != CY_TCH_TMOUT_DFLT || in cyttsp_set_sysinfo_regs()
226 ts->lp_intrvl != CY_LP_INTRVL_DFLT) { in cyttsp_set_sysinfo_regs()
229 ts->act_intrvl, in cyttsp_set_sysinfo_regs()
230 ts->tch_tmout, in cyttsp_set_sysinfo_regs()
231 ts->lp_intrvl in cyttsp_set_sysinfo_regs()
235 retval = ttsp_write_block_data(ts, CY_REG_ACT_INTRVL, in cyttsp_set_sysinfo_regs()
243 static void cyttsp_hard_reset(struct cyttsp *ts) in cyttsp_hard_reset() argument
245 if (ts->reset_gpio) { in cyttsp_hard_reset()
246 gpiod_set_value_cansleep(ts->reset_gpio, 1); in cyttsp_hard_reset()
248 gpiod_set_value_cansleep(ts->reset_gpio, 0); in cyttsp_hard_reset()
253 static int cyttsp_soft_reset(struct cyttsp *ts) in cyttsp_soft_reset() argument
259 reinit_completion(&ts->bl_ready); in cyttsp_soft_reset()
260 ts->state = CY_BL_STATE; in cyttsp_soft_reset()
262 enable_irq(ts->irq); in cyttsp_soft_reset()
264 retval = ttsp_send_command(ts, CY_SOFT_RESET_MODE); in cyttsp_soft_reset()
268 timeout = wait_for_completion_timeout(&ts->bl_ready, in cyttsp_soft_reset()
273 ts->state = CY_IDLE_STATE; in cyttsp_soft_reset()
274 disable_irq(ts->irq); in cyttsp_soft_reset()
278 static int cyttsp_act_dist_setup(struct cyttsp *ts) in cyttsp_act_dist_setup() argument
280 u8 act_dist_setup = ts->act_dist; in cyttsp_act_dist_setup()
283 return ttsp_write_block_data(ts, CY_REG_ACT_DIST, in cyttsp_act_dist_setup()
312 static void cyttsp_report_tchdata(struct cyttsp *ts) in cyttsp_report_tchdata() argument
314 struct cyttsp_xydata *xy_data = &ts->xy_data; in cyttsp_report_tchdata()
315 struct input_dev *input = ts->input; in cyttsp_report_tchdata()
325 dev_dbg(ts->dev, "%s: Large area detected\n", __func__); in cyttsp_report_tchdata()
329 dev_dbg(ts->dev, "%s: Num touch error detected\n", __func__); in cyttsp_report_tchdata()
333 dev_dbg(ts->dev, "%s: Invalid buffer detected\n", __func__); in cyttsp_report_tchdata()
365 struct cyttsp *ts = handle; in cyttsp_irq() local
368 if (unlikely(ts->state == CY_BL_STATE)) { in cyttsp_irq()
369 complete(&ts->bl_ready); in cyttsp_irq()
374 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_irq()
375 sizeof(struct cyttsp_xydata), &ts->xy_data); in cyttsp_irq()
380 error = cyttsp_handshake(ts); in cyttsp_irq()
384 if (unlikely(ts->state == CY_IDLE_STATE)) in cyttsp_irq()
387 if (GET_BOOTLOADERMODE(ts->xy_data.tt_mode)) { in cyttsp_irq()
392 error = cyttsp_exit_bl_mode(ts); in cyttsp_irq()
394 dev_err(ts->dev, in cyttsp_irq()
397 ts->state = CY_IDLE_STATE; in cyttsp_irq()
400 cyttsp_report_tchdata(ts); in cyttsp_irq()
407 static int cyttsp_power_on(struct cyttsp *ts) in cyttsp_power_on() argument
411 error = cyttsp_soft_reset(ts); in cyttsp_power_on()
415 error = cyttsp_load_bl_regs(ts); in cyttsp_power_on()
419 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status) && in cyttsp_power_on()
420 IS_VALID_APP(ts->bl_data.bl_status)) { in cyttsp_power_on()
421 error = cyttsp_exit_bl_mode(ts); in cyttsp_power_on()
426 if (GET_HSTMODE(ts->bl_data.bl_file) != CY_OPERATE_MODE || in cyttsp_power_on()
427 IS_OPERATIONAL_ERR(ts->bl_data.bl_status)) { in cyttsp_power_on()
431 error = cyttsp_set_sysinfo_mode(ts); in cyttsp_power_on()
435 error = cyttsp_set_sysinfo_regs(ts); in cyttsp_power_on()
439 error = cyttsp_set_operational_mode(ts); in cyttsp_power_on()
444 error = cyttsp_act_dist_setup(ts); in cyttsp_power_on()
448 ts->state = CY_ACTIVE_STATE; in cyttsp_power_on()
453 static int cyttsp_enable(struct cyttsp *ts) in cyttsp_enable() argument
463 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_enable()
464 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_enable()
468 if (GET_HSTMODE(ts->xy_data.hst_mode)) in cyttsp_enable()
471 enable_irq(ts->irq); in cyttsp_enable()
476 static int cyttsp_disable(struct cyttsp *ts) in cyttsp_disable() argument
480 error = ttsp_send_command(ts, CY_LOW_POWER_MODE); in cyttsp_disable()
484 disable_irq(ts->irq); in cyttsp_disable()
491 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_suspend() local
494 mutex_lock(&ts->input->mutex); in cyttsp_suspend()
496 if (ts->input->users) { in cyttsp_suspend()
497 retval = cyttsp_disable(ts); in cyttsp_suspend()
499 ts->suspended = true; in cyttsp_suspend()
502 mutex_unlock(&ts->input->mutex); in cyttsp_suspend()
509 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_resume() local
511 mutex_lock(&ts->input->mutex); in cyttsp_resume()
513 if (ts->input->users) in cyttsp_resume()
514 cyttsp_enable(ts); in cyttsp_resume()
516 ts->suspended = false; in cyttsp_resume()
518 mutex_unlock(&ts->input->mutex); in cyttsp_resume()
528 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_open() local
531 if (!ts->suspended) in cyttsp_open()
532 retval = cyttsp_enable(ts); in cyttsp_open()
539 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_close() local
541 if (!ts->suspended) in cyttsp_close()
542 cyttsp_disable(ts); in cyttsp_close()
545 static int cyttsp_parse_properties(struct cyttsp *ts) in cyttsp_parse_properties() argument
547 struct device *dev = ts->dev; in cyttsp_parse_properties()
551 ts->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL); in cyttsp_parse_properties()
552 if (!ts->bl_keys) in cyttsp_parse_properties()
556 ts->use_hndshk = false; in cyttsp_parse_properties()
557 ts->act_dist = CY_ACT_DIST_DFLT; in cyttsp_parse_properties()
558 ts->act_intrvl = CY_ACT_INTRVL_DFLT; in cyttsp_parse_properties()
559 ts->tch_tmout = CY_TCH_TMOUT_DFLT; in cyttsp_parse_properties()
560 ts->lp_intrvl = CY_LP_INTRVL_DFLT; in cyttsp_parse_properties()
563 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_parse_properties()
570 ts->use_hndshk = device_property_present(dev, "use-handshake"); in cyttsp_parse_properties()
578 ts->act_dist &= ~CY_ACT_DIST_MASK; in cyttsp_parse_properties()
579 ts->act_dist |= dt_value; in cyttsp_parse_properties()
588 ts->act_intrvl = dt_value; in cyttsp_parse_properties()
598 ts->lp_intrvl = dt_value / 10; in cyttsp_parse_properties()
608 ts->tch_tmout = dt_value / 10; in cyttsp_parse_properties()
617 struct cyttsp *ts; in cyttsp_probe() local
621 ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL); in cyttsp_probe()
622 if (!ts) in cyttsp_probe()
629 ts->dev = dev; in cyttsp_probe()
630 ts->input = input_dev; in cyttsp_probe()
631 ts->bus_ops = bus_ops; in cyttsp_probe()
632 ts->irq = irq; in cyttsp_probe()
634 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in cyttsp_probe()
635 if (IS_ERR(ts->reset_gpio)) { in cyttsp_probe()
636 error = PTR_ERR(ts->reset_gpio); in cyttsp_probe()
641 error = cyttsp_parse_properties(ts); in cyttsp_probe()
645 init_completion(&ts->bl_ready); in cyttsp_probe()
646 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in cyttsp_probe()
649 input_dev->phys = ts->phys; in cyttsp_probe()
651 input_dev->dev.parent = ts->dev; in cyttsp_probe()
656 input_set_drvdata(input_dev, ts); in cyttsp_probe()
668 error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, in cyttsp_probe()
670 "cyttsp", ts); in cyttsp_probe()
672 dev_err(ts->dev, "failed to request IRQ %d, err: %d\n", in cyttsp_probe()
673 ts->irq, error); in cyttsp_probe()
677 disable_irq(ts->irq); in cyttsp_probe()
679 cyttsp_hard_reset(ts); in cyttsp_probe()
681 error = cyttsp_power_on(ts); in cyttsp_probe()
687 dev_err(ts->dev, "failed to register input device: %d\n", in cyttsp_probe()
692 return ts; in cyttsp_probe()