Lines Matching +full:mode +full:- +full:bootloader
1 // SPDX-License-Identifier: GPL-2.0-only
29 /* Bootloader number of command keys */
59 /* device mode bits */
62 /* power mode select bits */
63 #define CY_SOFT_RESET_MODE 0x01 /* return to Bootloader mode */
74 0xA5, /* exit bootloader command */
85 error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command, in ttsp_read_block_data()
93 return -EIO; in ttsp_read_block_data()
103 error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command, in ttsp_write_block_data()
111 return -EIO; in ttsp_write_block_data()
121 if (ts->use_hndshk) in cyttsp_handshake()
123 ts->xy_data.hst_mode ^ CY_HNDSHK_BIT); in cyttsp_handshake()
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()
134 sizeof(ts->bl_data), &ts->bl_data); in cyttsp_load_bl_regs()
143 if (ts->bl_keys) in cyttsp_exit_bl_mode()
144 memcpy(&bl_cmd[sizeof(bl_command) - CY_NUM_BL_KEYS], in cyttsp_exit_bl_mode()
145 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_exit_bl_mode()
159 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status)) in cyttsp_exit_bl_mode()
160 return -EIO; in cyttsp_exit_bl_mode()
173 /* wait for TTSP Device to complete switch to Operational mode */ in cyttsp_set_operational_mode()
175 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_set_operational_mode()
183 return ts->xy_data.act_dist == CY_ACT_DIST_DFLT ? -EIO : 0; in cyttsp_set_operational_mode()
190 memset(&ts->sysinfo_data, 0, sizeof(ts->sysinfo_data)); in cyttsp_set_sysinfo_mode()
192 /* switch to 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()
208 if (!ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) in cyttsp_set_sysinfo_mode()
209 return -EIO; in cyttsp_set_sysinfo_mode()
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()
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()
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()
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()
272 retval = -EIO; in cyttsp_soft_reset()
276 ts->state = CY_IDLE_STATE; in cyttsp_soft_reset()
277 disable_irq(ts->irq); in cyttsp_soft_reset()
283 u8 act_dist_setup = ts->act_dist; in cyttsp_act_dist_setup()
292 ids[0] = xy_data->touch12_id >> 4; in cyttsp_extract_track_ids()
293 ids[1] = xy_data->touch12_id & 0xF; in cyttsp_extract_track_ids()
294 ids[2] = xy_data->touch34_id >> 4; in cyttsp_extract_track_ids()
295 ids[3] = xy_data->touch34_id & 0xF; in cyttsp_extract_track_ids()
303 return &xy_data->tch1; in cyttsp_get_tch()
305 return &xy_data->tch2; in cyttsp_get_tch()
307 return &xy_data->tch3; in cyttsp_get_tch()
309 return &xy_data->tch4; in cyttsp_get_tch()
317 struct cyttsp_xydata *xy_data = &ts->xy_data; in cyttsp_report_tchdata()
318 struct input_dev *input = ts->input; in cyttsp_report_tchdata()
319 int num_tch = GET_NUM_TOUCHES(xy_data->tt_stat); in cyttsp_report_tchdata()
325 if (IS_LARGE_AREA(xy_data->tt_stat) == 1) { 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()
333 } else if (IS_BAD_PKT(xy_data->tt_mode)) { in cyttsp_report_tchdata()
336 dev_dbg(ts->dev, "%s: Invalid buffer detected\n", __func__); in cyttsp_report_tchdata()
348 input_report_abs(input, ABS_MT_POSITION_X, be16_to_cpu(tch->x)); in cyttsp_report_tchdata()
349 input_report_abs(input, ABS_MT_POSITION_Y, be16_to_cpu(tch->y)); in cyttsp_report_tchdata()
350 input_report_abs(input, ABS_MT_TOUCH_MAJOR, tch->z); in cyttsp_report_tchdata()
371 if (unlikely(ts->state == CY_BL_STATE)) { in cyttsp_irq()
372 complete(&ts->bl_ready); in cyttsp_irq()
378 sizeof(struct cyttsp_xydata), &ts->xy_data); 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()
392 * TTSP device has reset back to bootloader mode. in cyttsp_irq()
393 * Restore to operational mode. in cyttsp_irq()
397 dev_err(ts->dev, in cyttsp_irq()
398 "Could not return to operational mode, err: %d\n", in cyttsp_irq()
400 ts->state = CY_IDLE_STATE; in cyttsp_irq()
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()
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()
433 return -ENODEV; in cyttsp_power_on()
453 ts->state = CY_ACTIVE_STATE; in cyttsp_power_on()
469 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_enable()
473 if (GET_HSTMODE(ts->xy_data.hst_mode)) in cyttsp_enable()
474 return -EIO; in cyttsp_enable()
476 enable_irq(ts->irq); in cyttsp_enable()
489 disable_irq(ts->irq); in cyttsp_disable()
499 mutex_lock(&ts->input->mutex); in cyttsp_suspend()
501 if (input_device_enabled(ts->input)) { in cyttsp_suspend()
504 ts->suspended = true; in cyttsp_suspend()
507 mutex_unlock(&ts->input->mutex); in cyttsp_suspend()
516 mutex_lock(&ts->input->mutex); in cyttsp_resume()
518 if (input_device_enabled(ts->input)) in cyttsp_resume()
521 ts->suspended = false; in cyttsp_resume()
523 mutex_unlock(&ts->input->mutex); in cyttsp_resume()
535 if (!ts->suspended) in cyttsp_open()
545 if (!ts->suspended) in cyttsp_close()
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()
557 return -ENOMEM; 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()
566 ret = device_property_read_u8_array(dev, "bootloader-key", in cyttsp_parse_properties()
567 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_parse_properties()
570 "bootloader-key property could not be retrieved\n"); in cyttsp_parse_properties()
574 ts->use_hndshk = device_property_present(dev, "use-handshake"); in cyttsp_parse_properties()
576 if (!device_property_read_u32(dev, "active-distance", &dt_value)) { in cyttsp_parse_properties()
578 dev_err(dev, "active-distance (%u) must be [0-15]\n", in cyttsp_parse_properties()
580 return -EINVAL; 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()
586 if (!device_property_read_u32(dev, "active-interval-ms", &dt_value)) { in cyttsp_parse_properties()
588 dev_err(dev, "active-interval-ms (%u) must be [0-255]\n", in cyttsp_parse_properties()
590 return -EINVAL; in cyttsp_parse_properties()
592 ts->act_intrvl = dt_value; in cyttsp_parse_properties()
595 if (!device_property_read_u32(dev, "lowpower-interval-ms", &dt_value)) { in cyttsp_parse_properties()
597 dev_err(dev, "lowpower-interval-ms (%u) must be [0-2550]\n", in cyttsp_parse_properties()
599 return -EINVAL; in cyttsp_parse_properties()
602 ts->lp_intrvl = dt_value / 10; in cyttsp_parse_properties()
605 if (!device_property_read_u32(dev, "touch-timeout-ms", &dt_value)) { in cyttsp_parse_properties()
607 dev_err(dev, "touch-timeout-ms (%u) must be [0-2550]\n", in cyttsp_parse_properties()
609 return -EINVAL; in cyttsp_parse_properties()
612 ts->tch_tmout = dt_value / 10; in cyttsp_parse_properties()
622 regulator_bulk_disable(ARRAY_SIZE(ts->regulators), in cyttsp_disable_regulators()
623 ts->regulators); in cyttsp_disable_regulators()
635 return ERR_PTR(-ENOMEM); in cyttsp_probe()
639 return ERR_PTR(-ENOMEM); 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()
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()
683 init_completion(&ts->bl_ready); in cyttsp_probe()
685 input_dev->name = "Cypress TTSP TouchScreen"; in cyttsp_probe()
686 input_dev->id.bustype = bus_ops->bustype; in cyttsp_probe()
687 input_dev->dev.parent = ts->dev; in cyttsp_probe()
689 input_dev->open = cyttsp_open; in cyttsp_probe()
690 input_dev->close = cyttsp_close; in cyttsp_probe()
707 error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, 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()
724 dev_err(ts->dev, "failed to register input device: %d\n", in cyttsp_probe()