Lines Matching +full:mode +full:- +full:bootloader
1 // SPDX-License-Identifier: GPL-2.0-only
28 /* Bootloader number of command keys */
58 /* device mode bits */
61 /* power mode select bits */
62 #define CY_SOFT_RESET_MODE 0x01 /* return to Bootloader mode */
73 0xA5, /* exit bootloader command */
84 error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command, in ttsp_read_block_data()
92 return -EIO; in ttsp_read_block_data()
102 error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command, in ttsp_write_block_data()
110 return -EIO; in ttsp_write_block_data()
120 if (ts->use_hndshk) in cyttsp_handshake()
122 ts->xy_data.hst_mode ^ CY_HNDSHK_BIT); in cyttsp_handshake()
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()
133 sizeof(ts->bl_data), &ts->bl_data); in cyttsp_load_bl_regs()
142 if (ts->bl_keys) in cyttsp_exit_bl_mode()
143 memcpy(&bl_cmd[sizeof(bl_command) - CY_NUM_BL_KEYS], in cyttsp_exit_bl_mode()
144 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_exit_bl_mode()
158 if (GET_BOOTLOADERMODE(ts->bl_data.bl_status)) in cyttsp_exit_bl_mode()
159 return -EIO; in cyttsp_exit_bl_mode()
172 /* wait for TTSP Device to complete switch to Operational mode */ in cyttsp_set_operational_mode()
174 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_set_operational_mode()
182 return ts->xy_data.act_dist == CY_ACT_DIST_DFLT ? -EIO : 0; in cyttsp_set_operational_mode()
189 memset(&ts->sysinfo_data, 0, sizeof(ts->sysinfo_data)); in cyttsp_set_sysinfo_mode()
191 /* switch to 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()
207 if (!ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) in cyttsp_set_sysinfo_mode()
208 return -EIO; in cyttsp_set_sysinfo_mode()
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()
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()
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()
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()
271 retval = -EIO; in cyttsp_soft_reset()
275 ts->state = CY_IDLE_STATE; in cyttsp_soft_reset()
276 disable_irq(ts->irq); in cyttsp_soft_reset()
282 u8 act_dist_setup = ts->act_dist; in cyttsp_act_dist_setup()
291 ids[0] = xy_data->touch12_id >> 4; in cyttsp_extract_track_ids()
292 ids[1] = xy_data->touch12_id & 0xF; in cyttsp_extract_track_ids()
293 ids[2] = xy_data->touch34_id >> 4; in cyttsp_extract_track_ids()
294 ids[3] = xy_data->touch34_id & 0xF; in cyttsp_extract_track_ids()
302 return &xy_data->tch1; in cyttsp_get_tch()
304 return &xy_data->tch2; in cyttsp_get_tch()
306 return &xy_data->tch3; in cyttsp_get_tch()
308 return &xy_data->tch4; in cyttsp_get_tch()
316 struct cyttsp_xydata *xy_data = &ts->xy_data; in cyttsp_report_tchdata()
317 struct input_dev *input = ts->input; in cyttsp_report_tchdata()
318 int num_tch = GET_NUM_TOUCHES(xy_data->tt_stat); in cyttsp_report_tchdata()
324 if (IS_LARGE_AREA(xy_data->tt_stat) == 1) { 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()
332 } else if (IS_BAD_PKT(xy_data->tt_mode)) { in cyttsp_report_tchdata()
335 dev_dbg(ts->dev, "%s: Invalid buffer detected\n", __func__); in cyttsp_report_tchdata()
347 input_report_abs(input, ABS_MT_POSITION_X, be16_to_cpu(tch->x)); in cyttsp_report_tchdata()
348 input_report_abs(input, ABS_MT_POSITION_Y, be16_to_cpu(tch->y)); in cyttsp_report_tchdata()
349 input_report_abs(input, ABS_MT_TOUCH_MAJOR, tch->z); in cyttsp_report_tchdata()
370 if (unlikely(ts->state == CY_BL_STATE)) { in cyttsp_irq()
371 complete(&ts->bl_ready); in cyttsp_irq()
377 sizeof(struct cyttsp_xydata), &ts->xy_data); 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()
391 * TTSP device has reset back to bootloader mode. in cyttsp_irq()
392 * Restore to operational mode. in cyttsp_irq()
396 dev_err(ts->dev, in cyttsp_irq()
397 "Could not return to operational mode, err: %d\n", in cyttsp_irq()
399 ts->state = CY_IDLE_STATE; in cyttsp_irq()
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()
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()
432 return -ENODEV; in cyttsp_power_on()
452 ts->state = CY_ACTIVE_STATE; in cyttsp_power_on()
468 sizeof(ts->xy_data), &ts->xy_data); in cyttsp_enable()
472 if (GET_HSTMODE(ts->xy_data.hst_mode)) in cyttsp_enable()
473 return -EIO; in cyttsp_enable()
475 enable_irq(ts->irq); in cyttsp_enable()
488 disable_irq(ts->irq); in cyttsp_disable()
498 mutex_lock(&ts->input->mutex); in cyttsp_suspend()
500 if (input_device_enabled(ts->input)) { in cyttsp_suspend()
503 ts->suspended = true; in cyttsp_suspend()
506 mutex_unlock(&ts->input->mutex); in cyttsp_suspend()
515 mutex_lock(&ts->input->mutex); in cyttsp_resume()
517 if (input_device_enabled(ts->input)) in cyttsp_resume()
520 ts->suspended = false; in cyttsp_resume()
522 mutex_unlock(&ts->input->mutex); in cyttsp_resume()
534 if (!ts->suspended) in cyttsp_open()
544 if (!ts->suspended) in cyttsp_close()
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()
556 return -ENOMEM; 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()
565 ret = device_property_read_u8_array(dev, "bootloader-key", in cyttsp_parse_properties()
566 ts->bl_keys, CY_NUM_BL_KEYS); in cyttsp_parse_properties()
569 "bootloader-key property could not be retrieved\n"); in cyttsp_parse_properties()
573 ts->use_hndshk = device_property_present(dev, "use-handshake"); in cyttsp_parse_properties()
575 if (!device_property_read_u32(dev, "active-distance", &dt_value)) { in cyttsp_parse_properties()
577 dev_err(dev, "active-distance (%u) must be [0-15]\n", in cyttsp_parse_properties()
579 return -EINVAL; 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()
585 if (!device_property_read_u32(dev, "active-interval-ms", &dt_value)) { in cyttsp_parse_properties()
587 dev_err(dev, "active-interval-ms (%u) must be [0-255]\n", in cyttsp_parse_properties()
589 return -EINVAL; in cyttsp_parse_properties()
591 ts->act_intrvl = dt_value; in cyttsp_parse_properties()
594 if (!device_property_read_u32(dev, "lowpower-interval-ms", &dt_value)) { in cyttsp_parse_properties()
596 dev_err(dev, "lowpower-interval-ms (%u) must be [0-2550]\n", in cyttsp_parse_properties()
598 return -EINVAL; in cyttsp_parse_properties()
601 ts->lp_intrvl = dt_value / 10; in cyttsp_parse_properties()
604 if (!device_property_read_u32(dev, "touch-timeout-ms", &dt_value)) { in cyttsp_parse_properties()
606 dev_err(dev, "touch-timeout-ms (%u) must be [0-2550]\n", in cyttsp_parse_properties()
608 return -EINVAL; in cyttsp_parse_properties()
611 ts->tch_tmout = dt_value / 10; in cyttsp_parse_properties()
631 return ERR_PTR(-ENOMEM); in cyttsp_probe()
635 return ERR_PTR(-ENOMEM); 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()
660 init_completion(&ts->bl_ready); in cyttsp_probe()
662 input_dev->name = "Cypress TTSP TouchScreen"; in cyttsp_probe()
663 input_dev->id.bustype = bus_ops->bustype; in cyttsp_probe()
664 input_dev->dev.parent = ts->dev; in cyttsp_probe()
666 input_dev->open = cyttsp_open; in cyttsp_probe()
667 input_dev->close = cyttsp_close; in cyttsp_probe()
684 error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, 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()
701 dev_err(ts->dev, "failed to register input device: %d\n", in cyttsp_probe()