Lines Matching refs:ts

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