Lines Matching refs:ts
78 static int ttsp_read_block_data(struct cyttsp *ts, u8 command, in ttsp_read_block_data() argument
85 error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command, in ttsp_read_block_data()
96 static int ttsp_write_block_data(struct cyttsp *ts, u8 command, in ttsp_write_block_data() argument
103 error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command, in ttsp_write_block_data()
114 static int ttsp_send_command(struct cyttsp *ts, u8 cmd) in ttsp_send_command() argument
116 return ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); in ttsp_send_command()
119 static int cyttsp_handshake(struct cyttsp *ts) in cyttsp_handshake() argument
121 if (ts->use_hndshk) in cyttsp_handshake()
122 return ttsp_send_command(ts, in cyttsp_handshake()
123 ts->xy_data.hst_mode ^ CY_HNDSHK_BIT); in cyttsp_handshake()
128 static int cyttsp_load_bl_regs(struct cyttsp *ts) in cyttsp_load_bl_regs() argument
130 memset(&ts->bl_data, 0, sizeof(ts->bl_data)); in cyttsp_load_bl_regs()
131 ts->bl_data.bl_status = 0x10; in cyttsp_load_bl_regs()
133 return ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_load_bl_regs()
134 sizeof(ts->bl_data), &ts->bl_data); in cyttsp_load_bl_regs()
137 static int cyttsp_exit_bl_mode(struct cyttsp *ts) in cyttsp_exit_bl_mode() argument
143 if (ts->bl_keys) in cyttsp_exit_bl_mode()
145 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_exit_bl_mode()
147 error = ttsp_write_block_data(ts, CY_REG_BASE, in cyttsp_exit_bl_mode()
155 error = cyttsp_load_bl_regs(ts); in cyttsp_exit_bl_mode()
159 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status)) in cyttsp_exit_bl_mode()
165 static int cyttsp_set_operational_mode(struct cyttsp *ts) in cyttsp_set_operational_mode() argument
169 error = ttsp_send_command(ts, CY_OPERATE_MODE); in cyttsp_set_operational_mode()
174 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_set_operational_mode()
175 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_set_operational_mode()
179 error = cyttsp_handshake(ts); in cyttsp_set_operational_mode()
183 return ts->xy_data.act_dist == CY_ACT_DIST_DFLT ? -EIO : 0; in cyttsp_set_operational_mode()
186 static int cyttsp_set_sysinfo_mode(struct cyttsp *ts) in cyttsp_set_sysinfo_mode() argument
190 memset(&ts->sysinfo_data, 0, sizeof(ts->sysinfo_data)); in cyttsp_set_sysinfo_mode()
193 error = ttsp_send_command(ts, CY_SYSINFO_MODE); in cyttsp_set_sysinfo_mode()
199 error = ttsp_read_block_data(ts, CY_REG_BASE, sizeof(ts->sysinfo_data), in cyttsp_set_sysinfo_mode()
200 &ts->sysinfo_data); in cyttsp_set_sysinfo_mode()
204 error = cyttsp_handshake(ts); in cyttsp_set_sysinfo_mode()
208 if (!ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) in cyttsp_set_sysinfo_mode()
214 static int cyttsp_set_sysinfo_regs(struct cyttsp *ts) in cyttsp_set_sysinfo_regs() argument
218 if (ts->act_intrvl != CY_ACT_INTRVL_DFLT || in cyttsp_set_sysinfo_regs()
219 ts->tch_tmout != CY_TCH_TMOUT_DFLT || in cyttsp_set_sysinfo_regs()
220 ts->lp_intrvl != CY_LP_INTRVL_DFLT) { in cyttsp_set_sysinfo_regs()
223 ts->act_intrvl, in cyttsp_set_sysinfo_regs()
224 ts->tch_tmout, in cyttsp_set_sysinfo_regs()
225 ts->lp_intrvl in cyttsp_set_sysinfo_regs()
229 retval = ttsp_write_block_data(ts, CY_REG_ACT_INTRVL, in cyttsp_set_sysinfo_regs()
237 static void cyttsp_hard_reset(struct cyttsp *ts) in cyttsp_hard_reset() argument
239 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
258 reinit_completion(&ts->bl_ready); in cyttsp_soft_reset()
259 ts->state = CY_BL_STATE; in cyttsp_soft_reset()
261 enable_irq(ts->irq); in cyttsp_soft_reset()
263 retval = ttsp_send_command(ts, CY_SOFT_RESET_MODE); in cyttsp_soft_reset()
265 dev_err(ts->dev, "failed to send soft reset\n"); in cyttsp_soft_reset()
269 if (!wait_for_completion_timeout(&ts->bl_ready, in cyttsp_soft_reset()
271 dev_err(ts->dev, "timeout waiting for soft reset\n"); in cyttsp_soft_reset()
276 ts->state = CY_IDLE_STATE; in cyttsp_soft_reset()
277 disable_irq(ts->irq); in cyttsp_soft_reset()
281 static int cyttsp_act_dist_setup(struct cyttsp *ts) in cyttsp_act_dist_setup() argument
283 u8 act_dist_setup = ts->act_dist; in cyttsp_act_dist_setup()
286 return ttsp_write_block_data(ts, CY_REG_ACT_DIST, in cyttsp_act_dist_setup()
315 static void cyttsp_report_tchdata(struct cyttsp *ts) in cyttsp_report_tchdata() argument
317 struct cyttsp_xydata *xy_data = &ts->xy_data; in cyttsp_report_tchdata()
318 struct input_dev *input = ts->input; in cyttsp_report_tchdata()
328 dev_dbg(ts->dev, "%s: Large area detected\n", __func__); in cyttsp_report_tchdata()
332 dev_dbg(ts->dev, "%s: Num touch error detected\n", __func__); in cyttsp_report_tchdata()
336 dev_dbg(ts->dev, "%s: Invalid buffer detected\n", __func__); in cyttsp_report_tchdata()
368 struct cyttsp *ts = handle; in cyttsp_irq() local
371 if (unlikely(ts->state == CY_BL_STATE)) { in cyttsp_irq()
372 complete(&ts->bl_ready); in cyttsp_irq()
377 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_irq()
378 sizeof(struct cyttsp_xydata), &ts->xy_data); in cyttsp_irq()
383 error = cyttsp_handshake(ts); in cyttsp_irq()
387 if (unlikely(ts->state == CY_IDLE_STATE)) in cyttsp_irq()
390 if (GET_BOOTLOADERMODE(ts->xy_data.tt_mode)) { in cyttsp_irq()
395 error = cyttsp_exit_bl_mode(ts); in cyttsp_irq()
397 dev_err(ts->dev, in cyttsp_irq()
400 ts->state = CY_IDLE_STATE; in cyttsp_irq()
403 cyttsp_report_tchdata(ts); in cyttsp_irq()
410 static int cyttsp_power_on(struct cyttsp *ts) in cyttsp_power_on() argument
414 error = cyttsp_soft_reset(ts); in cyttsp_power_on()
418 error = cyttsp_load_bl_regs(ts); in cyttsp_power_on()
422 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status) && in cyttsp_power_on()
423 IS_VALID_APP(ts->bl_data.bl_status)) { in cyttsp_power_on()
424 error = cyttsp_exit_bl_mode(ts); in cyttsp_power_on()
426 dev_err(ts->dev, "failed to exit bootloader mode\n"); in cyttsp_power_on()
431 if (GET_HSTMODE(ts->bl_data.bl_file) != CY_OPERATE_MODE || in cyttsp_power_on()
432 IS_OPERATIONAL_ERR(ts->bl_data.bl_status)) { in cyttsp_power_on()
436 error = cyttsp_set_sysinfo_mode(ts); in cyttsp_power_on()
440 error = cyttsp_set_sysinfo_regs(ts); in cyttsp_power_on()
444 error = cyttsp_set_operational_mode(ts); in cyttsp_power_on()
449 error = cyttsp_act_dist_setup(ts); in cyttsp_power_on()
453 ts->state = CY_ACTIVE_STATE; in cyttsp_power_on()
458 static int cyttsp_enable(struct cyttsp *ts) in cyttsp_enable() argument
468 error = ttsp_read_block_data(ts, CY_REG_BASE, in cyttsp_enable()
469 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_enable()
473 if (GET_HSTMODE(ts->xy_data.hst_mode)) in cyttsp_enable()
476 enable_irq(ts->irq); in cyttsp_enable()
481 static int cyttsp_disable(struct cyttsp *ts) in cyttsp_disable() argument
485 error = ttsp_send_command(ts, CY_LOW_POWER_MODE); in cyttsp_disable()
489 disable_irq(ts->irq); in cyttsp_disable()
496 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_suspend() local
499 mutex_lock(&ts->input->mutex); in cyttsp_suspend()
501 if (input_device_enabled(ts->input)) { in cyttsp_suspend()
502 retval = cyttsp_disable(ts); in cyttsp_suspend()
504 ts->suspended = true; in cyttsp_suspend()
507 mutex_unlock(&ts->input->mutex); in cyttsp_suspend()
514 struct cyttsp *ts = dev_get_drvdata(dev); in cyttsp_resume() local
516 mutex_lock(&ts->input->mutex); in cyttsp_resume()
518 if (input_device_enabled(ts->input)) in cyttsp_resume()
519 cyttsp_enable(ts); in cyttsp_resume()
521 ts->suspended = false; in cyttsp_resume()
523 mutex_unlock(&ts->input->mutex); in cyttsp_resume()
532 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_open() local
535 if (!ts->suspended) in cyttsp_open()
536 retval = cyttsp_enable(ts); in cyttsp_open()
543 struct cyttsp *ts = input_get_drvdata(dev); in cyttsp_close() local
545 if (!ts->suspended) in cyttsp_close()
546 cyttsp_disable(ts); in cyttsp_close()
549 static int cyttsp_parse_properties(struct cyttsp *ts) in cyttsp_parse_properties() argument
551 struct device *dev = ts->dev; in cyttsp_parse_properties()
555 ts->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL); in cyttsp_parse_properties()
556 if (!ts->bl_keys) in cyttsp_parse_properties()
560 ts->use_hndshk = false; in cyttsp_parse_properties()
561 ts->act_dist = CY_ACT_DIST_DFLT; in cyttsp_parse_properties()
562 ts->act_intrvl = CY_ACT_INTRVL_DFLT; in cyttsp_parse_properties()
563 ts->tch_tmout = CY_TCH_TMOUT_DFLT; in cyttsp_parse_properties()
564 ts->lp_intrvl = CY_LP_INTRVL_DFLT; in cyttsp_parse_properties()
567 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_parse_properties()
574 ts->use_hndshk = device_property_present(dev, "use-handshake"); in cyttsp_parse_properties()
582 ts->act_dist &= ~CY_ACT_DIST_MASK; in cyttsp_parse_properties()
583 ts->act_dist |= dt_value; in cyttsp_parse_properties()
592 ts->act_intrvl = dt_value; in cyttsp_parse_properties()
602 ts->lp_intrvl = dt_value / 10; in cyttsp_parse_properties()
612 ts->tch_tmout = dt_value / 10; in cyttsp_parse_properties()
620 struct cyttsp *ts = _ts; in cyttsp_disable_regulators() local
622 regulator_bulk_disable(ARRAY_SIZE(ts->regulators), in cyttsp_disable_regulators()
623 ts->regulators); in cyttsp_disable_regulators()
629 struct cyttsp *ts; in cyttsp_probe() local
633 ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL); in cyttsp_probe()
634 if (!ts) in cyttsp_probe()
641 ts->dev = dev; in cyttsp_probe()
642 ts->input = input_dev; in cyttsp_probe()
643 ts->bus_ops = bus_ops; in cyttsp_probe()
644 ts->irq = irq; in cyttsp_probe()
650 ts->regulators[0].supply = "vcpin"; in cyttsp_probe()
651 ts->regulators[1].supply = "vdd"; in cyttsp_probe()
652 error = devm_regulator_bulk_get(dev, ARRAY_SIZE(ts->regulators), in cyttsp_probe()
653 ts->regulators); in cyttsp_probe()
659 error = regulator_bulk_enable(ARRAY_SIZE(ts->regulators), in cyttsp_probe()
660 ts->regulators); in cyttsp_probe()
666 error = devm_add_action_or_reset(dev, cyttsp_disable_regulators, ts); in cyttsp_probe()
672 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in cyttsp_probe()
673 if (IS_ERR(ts->reset_gpio)) { in cyttsp_probe()
674 error = PTR_ERR(ts->reset_gpio); in cyttsp_probe()
679 error = cyttsp_parse_properties(ts); in cyttsp_probe()
683 init_completion(&ts->bl_ready); in cyttsp_probe()
687 input_dev->dev.parent = ts->dev; in cyttsp_probe()
692 input_set_drvdata(input_dev, ts); in cyttsp_probe()
707 error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, in cyttsp_probe()
709 "cyttsp", ts); in cyttsp_probe()
711 dev_err(ts->dev, "failed to request IRQ %d, err: %d\n", in cyttsp_probe()
712 ts->irq, error); in cyttsp_probe()
716 cyttsp_hard_reset(ts); in cyttsp_probe()
718 error = cyttsp_power_on(ts); in cyttsp_probe()
724 dev_err(ts->dev, "failed to register input device: %d\n", in cyttsp_probe()
729 return ts; in cyttsp_probe()