Lines Matching +full:deep +full:- +full:touch

9  * Copyright (C) 2011-2015 Cypress Semiconductor, Inc.
10 * Copyright (C) 2011-2012 Google, Inc.
46 if (cyapa->gen == CYAPA_GEN6 && cyapa->state == CYAPA_STATE_GEN6_BL) in cyapa_is_pip_bl_mode()
49 if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_BL) in cyapa_is_pip_bl_mode()
57 if (cyapa->gen == CYAPA_GEN6 && cyapa->state == CYAPA_STATE_GEN6_APP) in cyapa_is_pip_app_mode()
60 if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_APP) in cyapa_is_pip_app_mode()
71 if (cyapa->gen == CYAPA_GEN3 && in cyapa_is_bootloader_mode()
72 cyapa->state >= CYAPA_STATE_BL_BUSY && in cyapa_is_bootloader_mode()
73 cyapa->state <= CYAPA_STATE_BL_ACTIVE) in cyapa_is_bootloader_mode()
84 if (cyapa->gen == CYAPA_GEN3 && cyapa->state == CYAPA_STATE_OP) in cyapa_is_operational_mode()
94 struct i2c_client *client = cyapa->client; in cyapa_i2c_read()
97 .addr = client->addr, in cyapa_i2c_read()
103 .addr = client->addr, in cyapa_i2c_read()
111 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); in cyapa_i2c_read()
114 return ret < 0 ? ret : -EIO; in cyapa_i2c_read()
120 * cyapa_i2c_write - Execute i2c block data write operation
131 struct i2c_client *client = cyapa->client; in cyapa_i2c_write()
135 if (len > sizeof(buf) - 1) in cyapa_i2c_write()
136 return -ENOMEM; in cyapa_i2c_write()
143 return ret < 0 ? ret : -EIO; in cyapa_i2c_write()
152 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) in cyapa_check_adapter_functionality()
154 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | in cyapa_check_adapter_functionality()
169 bool even_addr = ((cyapa->client->addr & 0x0001) == 0); in cyapa_get_state()
174 cyapa->state = CYAPA_STATE_NO_DEVICE; in cyapa_get_state()
187 * -ETIMEDOUT. In this case, try again using the smbus equivalent in cyapa_get_state()
190 if (cyapa->smbus && (error == -ETIMEDOUT || error == -ENXIO)) { in cyapa_get_state()
204 cyapa->status[REG_OP_STATUS] = status[REG_OP_STATUS]; in cyapa_get_state()
205 cyapa->status[REG_BL_STATUS] = status[REG_BL_STATUS]; in cyapa_get_state()
206 cyapa->status[REG_BL_ERROR] = status[REG_BL_ERROR]; in cyapa_get_state()
208 if (cyapa->gen == CYAPA_GEN_UNKNOWN || in cyapa_get_state()
209 cyapa->gen == CYAPA_GEN3) { in cyapa_get_state()
215 if (cyapa->gen == CYAPA_GEN_UNKNOWN || in cyapa_get_state()
216 cyapa->gen == CYAPA_GEN6 || in cyapa_get_state()
217 cyapa->gen == CYAPA_GEN5) { in cyapa_get_state()
224 if ((cyapa->gen == CYAPA_GEN_UNKNOWN || in cyapa_get_state()
225 cyapa->gen == CYAPA_GEN5) && in cyapa_get_state()
251 } while (--retries > 0 && !smbus); in cyapa_get_state()
256 if (cyapa->state <= CYAPA_STATE_BL_BUSY) in cyapa_get_state()
257 return -EAGAIN; in cyapa_get_state()
261 return (error < 0) ? error : -EAGAIN; in cyapa_get_state()
274 * 0 when the device eventually responds with a valid non-busy state.
275 * -ETIMEDOUT if device never responds (too many -EAGAIN)
276 * -EAGAIN if bootload is busy, or unknown state.
286 if (!error && cyapa->state > CYAPA_STATE_BL_BUSY) in cyapa_poll_state()
290 } while (tries--); in cyapa_poll_state()
292 return (error == -EAGAIN || error == -ETIMEDOUT) ? -ETIMEDOUT : error; in cyapa_poll_state()
302 * -ENODEV no device
303 * -EBUSY no device or in bootloader
304 * -EIO failure while reading from device
305 * -ETIMEDOUT timeout failure for bus idle or bus no response
306 * -EAGAIN device is still in bootloader
307 * if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware
308 * -EINVAL device is in operational mode, but not supported by this driver
319 switch (cyapa->gen) { in cyapa_check_is_operational()
321 cyapa->ops = &cyapa_gen6_ops; in cyapa_check_is_operational()
324 cyapa->ops = &cyapa_gen5_ops; in cyapa_check_is_operational()
327 cyapa->ops = &cyapa_gen3_ops; in cyapa_check_is_operational()
330 return -ENODEV; in cyapa_check_is_operational()
333 error = cyapa->ops->operational_check(cyapa); in cyapa_check_is_operational()
335 cyapa->operational = true; in cyapa_check_is_operational()
337 cyapa->operational = false; in cyapa_check_is_operational()
350 struct device *dev = &cyapa->client->dev; in cyapa_detect()
355 if (error != -ETIMEDOUT && error != -ENODEV && in cyapa_detect()
371 struct i2c_client *client = cyapa->client; in cyapa_open()
372 struct device *dev = &client->dev; in cyapa_open()
375 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_open()
379 if (cyapa->operational) { in cyapa_open()
385 error = cyapa->ops->set_power_mode(cyapa, in cyapa_open()
393 if (error || !cyapa->operational) { in cyapa_open()
394 error = error ? error : -EAGAIN; in cyapa_open()
399 enable_irq(client->irq); in cyapa_open()
409 mutex_unlock(&cyapa->state_sync_lock); in cyapa_open()
416 struct i2c_client *client = cyapa->client; in cyapa_close()
417 struct device *dev = &cyapa->client->dev; in cyapa_close()
419 mutex_lock(&cyapa->state_sync_lock); in cyapa_close()
421 disable_irq(client->irq); in cyapa_close()
426 if (cyapa->operational) in cyapa_close()
427 cyapa->ops->set_power_mode(cyapa, in cyapa_close()
430 mutex_unlock(&cyapa->state_sync_lock); in cyapa_close()
435 struct device *dev = &cyapa->client->dev; in cyapa_create_input_dev()
439 if (!cyapa->physical_size_x || !cyapa->physical_size_y) in cyapa_create_input_dev()
440 return -EINVAL; in cyapa_create_input_dev()
445 return -ENOMEM; in cyapa_create_input_dev()
448 input->name = CYAPA_NAME; in cyapa_create_input_dev()
449 input->phys = cyapa->phys; in cyapa_create_input_dev()
450 input->id.bustype = BUS_I2C; in cyapa_create_input_dev()
451 input->id.version = 1; in cyapa_create_input_dev()
452 input->id.product = 0; /* Means any product in eventcomm. */ in cyapa_create_input_dev()
453 input->dev.parent = &cyapa->client->dev; in cyapa_create_input_dev()
455 input->open = cyapa_open; in cyapa_create_input_dev()
456 input->close = cyapa_close; in cyapa_create_input_dev()
460 __set_bit(EV_ABS, input->evbit); in cyapa_create_input_dev()
463 input_set_abs_params(input, ABS_MT_POSITION_X, 0, cyapa->max_abs_x, 0, in cyapa_create_input_dev()
465 input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cyapa->max_abs_y, 0, in cyapa_create_input_dev()
467 input_set_abs_params(input, ABS_MT_PRESSURE, 0, cyapa->max_z, 0, 0); in cyapa_create_input_dev()
468 if (cyapa->gen > CYAPA_GEN3) { in cyapa_create_input_dev()
474 * The range is -127 to 127. in cyapa_create_input_dev()
480 * value is value + (-30 ~ 30). in cyapa_create_input_dev()
483 -127, 127, 0, 0); in cyapa_create_input_dev()
485 if (cyapa->gen >= CYAPA_GEN5) { in cyapa_create_input_dev()
492 cyapa->max_abs_x / cyapa->physical_size_x); in cyapa_create_input_dev()
494 cyapa->max_abs_y / cyapa->physical_size_y); in cyapa_create_input_dev()
496 if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK) in cyapa_create_input_dev()
497 __set_bit(BTN_LEFT, input->keybit); in cyapa_create_input_dev()
498 if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK) in cyapa_create_input_dev()
499 __set_bit(BTN_MIDDLE, input->keybit); in cyapa_create_input_dev()
500 if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK) in cyapa_create_input_dev()
501 __set_bit(BTN_RIGHT, input->keybit); in cyapa_create_input_dev()
503 if (cyapa->btn_capability == CAPABILITY_LEFT_BTN_MASK) in cyapa_create_input_dev()
504 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); in cyapa_create_input_dev()
521 cyapa->input = input; in cyapa_create_input_dev()
527 struct input_dev *input = cyapa->input; in cyapa_enable_irq_for_cmd()
529 if (!input || !input->users) { in cyapa_enable_irq_for_cmd()
531 * When input is NULL, TP must be in deep sleep mode. in cyapa_enable_irq_for_cmd()
532 * In this mode, later non-power I2C command will always failed in cyapa_enable_irq_for_cmd()
533 * if not bring it out of deep sleep mode firstly, in cyapa_enable_irq_for_cmd()
536 if (!input || cyapa->operational) in cyapa_enable_irq_for_cmd()
537 cyapa->ops->set_power_mode(cyapa, in cyapa_enable_irq_for_cmd()
540 if (cyapa->gen >= CYAPA_GEN5) in cyapa_enable_irq_for_cmd()
541 enable_irq(cyapa->client->irq); in cyapa_enable_irq_for_cmd()
547 struct input_dev *input = cyapa->input; in cyapa_disable_irq_for_cmd()
549 if (!input || !input->users) { in cyapa_disable_irq_for_cmd()
550 if (cyapa->gen >= CYAPA_GEN5) in cyapa_disable_irq_for_cmd()
551 disable_irq(cyapa->client->irq); in cyapa_disable_irq_for_cmd()
552 if (!input || cyapa->operational) in cyapa_disable_irq_for_cmd()
553 cyapa->ops->set_power_mode(cyapa, in cyapa_disable_irq_for_cmd()
586 : (encoded_time - 5) * 20; in cyapa_pwr_cmd_to_sleep_time()
594 cyapa->state = CYAPA_STATE_NO_DEVICE; in cyapa_initialize()
595 cyapa->gen = CYAPA_GEN_UNKNOWN; in cyapa_initialize()
596 mutex_init(&cyapa->state_sync_lock); in cyapa_initialize()
602 cyapa->suspend_power_mode = PWR_MODE_SLEEP; in cyapa_initialize()
603 cyapa->suspend_sleep_time = in cyapa_initialize()
604 cyapa_pwr_cmd_to_sleep_time(cyapa->suspend_power_mode); in cyapa_initialize()
620 if (cyapa->operational) in cyapa_initialize()
621 cyapa->ops->set_power_mode(cyapa, in cyapa_initialize()
629 struct device *dev = &cyapa->client->dev; in cyapa_reinitialize()
630 struct input_dev *input = cyapa->input; in cyapa_reinitialize()
637 if (cyapa->operational) in cyapa_reinitialize()
638 cyapa->ops->set_power_mode(cyapa, in cyapa_reinitialize()
645 if (!input && cyapa->operational) { in cyapa_reinitialize()
655 if (!input || !input->users) { in cyapa_reinitialize()
657 if (cyapa->operational) in cyapa_reinitialize()
658 cyapa->ops->set_power_mode(cyapa, in cyapa_reinitialize()
660 } else if (!error && cyapa->operational) { in cyapa_reinitialize()
663 * in operational mode and input->users > 0. in cyapa_reinitialize()
679 struct device *dev = &cyapa->client->dev; in cyapa_irq()
686 if (cyapa->ops->irq_cmd_handler(cyapa)) { in cyapa_irq()
690 if (!cyapa->input) { in cyapa_irq()
695 cyapa->ops->sort_empty_output_data(cyapa, in cyapa_irq()
700 if (cyapa->operational) { in cyapa_irq()
701 error = cyapa->ops->irq_handler(cyapa); in cyapa_irq()
704 * Apply runtime power management to touch report event in cyapa_irq()
708 * time in receiving for first valid touch report data. in cyapa_irq()
717 if (!cyapa->operational || error) { in cyapa_irq()
718 if (!mutex_trylock(&cyapa->state_sync_lock)) { in cyapa_irq()
719 cyapa->ops->sort_empty_output_data(cyapa, in cyapa_irq()
724 mutex_unlock(&cyapa->state_sync_lock); in cyapa_irq()
748 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_suspend_scanrate()
752 pwr_cmd = cyapa->suspend_power_mode; in cyapa_show_suspend_scanrate()
753 sleep_time = cyapa->suspend_sleep_time; in cyapa_show_suspend_scanrate()
755 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_suspend_scanrate()
768 cyapa->gen == CYAPA_GEN3 ? in cyapa_show_suspend_scanrate()
785 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_update_suspend_scanrate()
790 cyapa->suspend_power_mode = PWR_MODE_BTN_ONLY; in cyapa_update_suspend_scanrate()
792 cyapa->suspend_power_mode = PWR_MODE_OFF; in cyapa_update_suspend_scanrate()
794 cyapa->suspend_sleep_time = min_t(u16, sleep_time, 1000); in cyapa_update_suspend_scanrate()
795 cyapa->suspend_power_mode = in cyapa_update_suspend_scanrate()
796 cyapa_sleep_time_to_pwr_cmd(cyapa->suspend_sleep_time); in cyapa_update_suspend_scanrate()
798 count = -EINVAL; in cyapa_update_suspend_scanrate()
801 mutex_unlock(&cyapa->state_sync_lock); in cyapa_update_suspend_scanrate()
824 sysfs_unmerge_group(&cyapa->client->dev.kobj, in cyapa_remove_power_wakeup_group()
830 struct i2c_client *client = cyapa->client; in cyapa_prepare_wakeup_controls()
831 struct device *dev = &client->dev; in cyapa_prepare_wakeup_controls()
835 error = sysfs_merge_group(&dev->kobj, in cyapa_prepare_wakeup_controls()
872 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_rt_suspend_scanrate()
876 pwr_cmd = cyapa->runtime_suspend_power_mode; in cyapa_show_rt_suspend_scanrate()
877 sleep_time = cyapa->runtime_suspend_sleep_time; in cyapa_show_rt_suspend_scanrate()
879 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_rt_suspend_scanrate()
882 cyapa->gen == CYAPA_GEN3 ? in cyapa_show_rt_suspend_scanrate()
897 return -EINVAL; in cyapa_update_rt_suspend_scanrate()
907 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_update_rt_suspend_scanrate()
911 cyapa->runtime_suspend_sleep_time = min_t(u16, time, 1000); in cyapa_update_rt_suspend_scanrate()
912 cyapa->runtime_suspend_power_mode = in cyapa_update_rt_suspend_scanrate()
913 cyapa_sleep_time_to_pwr_cmd(cyapa->runtime_suspend_sleep_time); in cyapa_update_rt_suspend_scanrate()
915 mutex_unlock(&cyapa->state_sync_lock); in cyapa_update_rt_suspend_scanrate()
940 sysfs_unmerge_group(&cyapa->client->dev.kobj, in cyapa_remove_power_runtime_group()
946 struct device *dev = &cyapa->client->dev; in cyapa_start_runtime()
949 cyapa->runtime_suspend_power_mode = PWR_MODE_IDLE; in cyapa_start_runtime()
950 cyapa->runtime_suspend_sleep_time = in cyapa_start_runtime()
951 cyapa_pwr_cmd_to_sleep_time(cyapa->runtime_suspend_power_mode); in cyapa_start_runtime()
953 error = sysfs_merge_group(&dev->kobj, &cyapa_power_runtime_group); in cyapa_start_runtime()
989 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_fm_ver()
992 error = scnprintf(buf, PAGE_SIZE, "%d.%d\n", cyapa->fw_maj_ver, in cyapa_show_fm_ver()
993 cyapa->fw_min_ver); in cyapa_show_fm_ver()
994 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_fm_ver()
1005 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_product_id()
1008 size = scnprintf(buf, PAGE_SIZE, "%s\n", cyapa->product_id); in cyapa_show_product_id()
1009 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_product_id()
1015 struct device *dev = &cyapa->client->dev; in cyapa_firmware()
1026 error = cyapa->ops->check_fw(cyapa, fw); in cyapa_firmware()
1043 error = cyapa->ops->bl_enter(cyapa); in cyapa_firmware()
1049 error = cyapa->ops->bl_activate(cyapa); in cyapa_firmware()
1055 error = cyapa->ops->bl_initiate(cyapa, fw); in cyapa_firmware()
1061 error = cyapa->ops->update_fw(cyapa, fw); in cyapa_firmware()
1086 return -EINVAL; in cyapa_update_fw_store()
1090 if (fw_name[count - 1] == '\n') in cyapa_update_fw_store()
1091 fw_name[count - 1] = '\0'; in cyapa_update_fw_store()
1095 if (cyapa->input) { in cyapa_update_fw_store()
1101 input_unregister_device(cyapa->input); in cyapa_update_fw_store()
1102 cyapa->input = NULL; in cyapa_update_fw_store()
1105 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_update_fw_store()
1122 * Re-detect trackpad device states because firmware update process in cyapa_update_fw_store()
1127 dev_err(dev, "failed to re-detect after updated: %d\n", ret); in cyapa_update_fw_store()
1131 mutex_unlock(&cyapa->state_sync_lock); in cyapa_update_fw_store()
1143 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_calibrate_store()
1147 if (cyapa->operational) { in cyapa_calibrate_store()
1149 error = cyapa->ops->calibrate_store(dev, attr, buf, count); in cyapa_calibrate_store()
1152 error = -EBUSY; /* Still running in bootloader mode. */ in cyapa_calibrate_store()
1155 mutex_unlock(&cyapa->state_sync_lock); in cyapa_calibrate_store()
1165 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_baseline()
1169 if (cyapa->operational) { in cyapa_show_baseline()
1171 error = cyapa->ops->show_baseline(dev, attr, buf); in cyapa_show_baseline()
1174 error = -EBUSY; /* Still running in bootloader mode. */ in cyapa_show_baseline()
1177 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_baseline()
1183 switch (cyapa->state) { in cyapa_state_to_string()
1209 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_mode()
1214 cyapa->gen, cyapa_state_to_string(cyapa)); in cyapa_show_mode()
1216 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_mode()
1245 regulator_disable(cyapa->vcc); in cyapa_disable_regulator()
1251 struct device *dev = &client->dev; in cyapa_probe()
1260 return -EIO; in cyapa_probe()
1264 if (i2c_smbus_xfer(client->adapter, client->addr, 0, in cyapa_probe()
1266 return -ENODEV; in cyapa_probe()
1270 return -ENOMEM; in cyapa_probe()
1274 cyapa->smbus = true; in cyapa_probe()
1276 cyapa->client = client; in cyapa_probe()
1278 sprintf(cyapa->phys, "i2c-%d-%04x/input0", client->adapter->nr, in cyapa_probe()
1279 client->addr); in cyapa_probe()
1281 cyapa->vcc = devm_regulator_get(dev, "vcc"); in cyapa_probe()
1282 if (IS_ERR(cyapa->vcc)) { in cyapa_probe()
1283 error = PTR_ERR(cyapa->vcc); in cyapa_probe()
1288 error = regulator_enable(cyapa->vcc); in cyapa_probe()
1326 error = devm_request_threaded_irq(dev, client->irq, in cyapa_probe()
1336 disable_irq(client->irq); in cyapa_probe()
1343 if (cyapa->operational) { in cyapa_probe()
1362 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_suspend()
1373 disable_irq(client->irq); in cyapa_suspend()
1379 if (cyapa->operational) { in cyapa_suspend()
1380 power_mode = device_may_wakeup(dev) ? cyapa->suspend_power_mode in cyapa_suspend()
1382 error = cyapa->ops->set_power_mode(cyapa, power_mode, in cyapa_suspend()
1383 cyapa->suspend_sleep_time, CYAPA_PM_SUSPEND); in cyapa_suspend()
1390 * Disable proximity interrupt when system idle, want true touch to in cyapa_suspend()
1393 if (cyapa->dev_pwr_mode != PWR_MODE_OFF) in cyapa_suspend()
1394 cyapa->ops->set_proximity(cyapa, false); in cyapa_suspend()
1397 cyapa->irq_wake = (enable_irq_wake(client->irq) == 0); in cyapa_suspend()
1399 mutex_unlock(&cyapa->state_sync_lock); in cyapa_suspend()
1409 mutex_lock(&cyapa->state_sync_lock); in cyapa_resume()
1411 if (device_may_wakeup(dev) && cyapa->irq_wake) { in cyapa_resume()
1412 disable_irq_wake(client->irq); in cyapa_resume()
1413 cyapa->irq_wake = false; in cyapa_resume()
1418 * Re-Enable proximity interrupt after enter operational mode. in cyapa_resume()
1424 enable_irq(client->irq); in cyapa_resume()
1426 mutex_unlock(&cyapa->state_sync_lock); in cyapa_resume()
1435 error = cyapa->ops->set_power_mode(cyapa, in cyapa_runtime_suspend()
1436 cyapa->runtime_suspend_power_mode, in cyapa_runtime_suspend()
1437 cyapa->runtime_suspend_sleep_time, in cyapa_runtime_suspend()
1450 error = cyapa->ops->set_power_mode(cyapa, in cyapa_runtime_resume()