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()
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()
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()
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()
871 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_rt_suspend_scanrate()
875 pwr_cmd = cyapa->runtime_suspend_power_mode; in cyapa_show_rt_suspend_scanrate()
876 sleep_time = cyapa->runtime_suspend_sleep_time; in cyapa_show_rt_suspend_scanrate()
878 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_rt_suspend_scanrate()
881 cyapa->gen == CYAPA_GEN3 ? in cyapa_show_rt_suspend_scanrate()
896 return -EINVAL; in cyapa_update_rt_suspend_scanrate()
906 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_update_rt_suspend_scanrate()
910 cyapa->runtime_suspend_sleep_time = min_t(u16, time, 1000); in cyapa_update_rt_suspend_scanrate()
911 cyapa->runtime_suspend_power_mode = in cyapa_update_rt_suspend_scanrate()
912 cyapa_sleep_time_to_pwr_cmd(cyapa->runtime_suspend_sleep_time); in cyapa_update_rt_suspend_scanrate()
914 mutex_unlock(&cyapa->state_sync_lock); in cyapa_update_rt_suspend_scanrate()
939 sysfs_unmerge_group(&cyapa->client->dev.kobj, in cyapa_remove_power_runtime_group()
945 struct device *dev = &cyapa->client->dev; in cyapa_start_runtime()
948 cyapa->runtime_suspend_power_mode = PWR_MODE_IDLE; in cyapa_start_runtime()
949 cyapa->runtime_suspend_sleep_time = in cyapa_start_runtime()
950 cyapa_pwr_cmd_to_sleep_time(cyapa->runtime_suspend_power_mode); in cyapa_start_runtime()
952 error = sysfs_merge_group(&dev->kobj, &cyapa_power_runtime_group); in cyapa_start_runtime()
988 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_fm_ver()
992 cyapa->fw_maj_ver, cyapa->fw_min_ver); in cyapa_show_fm_ver()
993 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_fm_ver()
1004 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_product_id()
1007 size = sysfs_emit(buf, "%s\n", cyapa->product_id); in cyapa_show_product_id()
1008 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_product_id()
1014 struct device *dev = &cyapa->client->dev; in cyapa_firmware()
1025 error = cyapa->ops->check_fw(cyapa, fw); in cyapa_firmware()
1042 error = cyapa->ops->bl_enter(cyapa); in cyapa_firmware()
1048 error = cyapa->ops->bl_activate(cyapa); in cyapa_firmware()
1054 error = cyapa->ops->bl_initiate(cyapa, fw); in cyapa_firmware()
1060 error = cyapa->ops->update_fw(cyapa, fw); in cyapa_firmware()
1085 return -EINVAL; in cyapa_update_fw_store()
1089 if (fw_name[count - 1] == '\n') in cyapa_update_fw_store()
1090 fw_name[count - 1] = '\0'; in cyapa_update_fw_store()
1094 if (cyapa->input) { in cyapa_update_fw_store()
1100 input_unregister_device(cyapa->input); in cyapa_update_fw_store()
1101 cyapa->input = NULL; in cyapa_update_fw_store()
1104 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_update_fw_store()
1121 * Re-detect trackpad device states because firmware update process in cyapa_update_fw_store()
1126 dev_err(dev, "failed to re-detect after updated: %d\n", ret); in cyapa_update_fw_store()
1130 mutex_unlock(&cyapa->state_sync_lock); in cyapa_update_fw_store()
1142 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_calibrate_store()
1146 if (cyapa->operational) { in cyapa_calibrate_store()
1148 error = cyapa->ops->calibrate_store(dev, attr, buf, count); in cyapa_calibrate_store()
1151 error = -EBUSY; /* Still running in bootloader mode. */ in cyapa_calibrate_store()
1154 mutex_unlock(&cyapa->state_sync_lock); in cyapa_calibrate_store()
1164 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_baseline()
1168 if (cyapa->operational) { in cyapa_show_baseline()
1170 error = cyapa->ops->show_baseline(dev, attr, buf); in cyapa_show_baseline()
1173 error = -EBUSY; /* Still running in bootloader mode. */ in cyapa_show_baseline()
1176 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_baseline()
1182 switch (cyapa->state) { in cyapa_state_to_string()
1208 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_show_mode()
1213 cyapa->gen, cyapa_state_to_string(cyapa)); in cyapa_show_mode()
1215 mutex_unlock(&cyapa->state_sync_lock); in cyapa_show_mode()
1241 regulator_disable(cyapa->vcc); in cyapa_disable_regulator()
1246 struct device *dev = &client->dev; in cyapa_probe()
1255 return -EIO; in cyapa_probe()
1259 if (i2c_smbus_xfer(client->adapter, client->addr, 0, in cyapa_probe()
1261 return -ENODEV; in cyapa_probe()
1265 return -ENOMEM; in cyapa_probe()
1269 cyapa->smbus = true; in cyapa_probe()
1271 cyapa->client = client; in cyapa_probe()
1273 sprintf(cyapa->phys, "i2c-%d-%04x/input0", client->adapter->nr, in cyapa_probe()
1274 client->addr); in cyapa_probe()
1276 cyapa->vcc = devm_regulator_get(dev, "vcc"); in cyapa_probe()
1277 if (IS_ERR(cyapa->vcc)) { in cyapa_probe()
1278 error = PTR_ERR(cyapa->vcc); in cyapa_probe()
1283 error = regulator_enable(cyapa->vcc); in cyapa_probe()
1314 error = devm_request_threaded_irq(dev, client->irq, in cyapa_probe()
1324 disable_irq(client->irq); in cyapa_probe()
1331 if (cyapa->operational) { in cyapa_probe()
1350 error = mutex_lock_interruptible(&cyapa->input->mutex); in cyapa_suspend()
1354 error = mutex_lock_interruptible(&cyapa->state_sync_lock); in cyapa_suspend()
1356 mutex_unlock(&cyapa->input->mutex); in cyapa_suspend()
1367 disable_irq(client->irq); in cyapa_suspend()
1373 if (cyapa->operational) { in cyapa_suspend()
1374 power_mode = device_may_wakeup(dev) ? cyapa->suspend_power_mode in cyapa_suspend()
1376 error = cyapa->ops->set_power_mode(cyapa, power_mode, in cyapa_suspend()
1377 cyapa->suspend_sleep_time, CYAPA_PM_SUSPEND); in cyapa_suspend()
1384 * Disable proximity interrupt when system idle, want true touch to in cyapa_suspend()
1387 if (cyapa->dev_pwr_mode != PWR_MODE_OFF) in cyapa_suspend()
1388 cyapa->ops->set_proximity(cyapa, false); in cyapa_suspend()
1391 cyapa->irq_wake = (enable_irq_wake(client->irq) == 0); in cyapa_suspend()
1393 mutex_unlock(&cyapa->state_sync_lock); in cyapa_suspend()
1394 mutex_unlock(&cyapa->input->mutex); in cyapa_suspend()
1405 mutex_lock(&cyapa->input->mutex); in cyapa_resume()
1406 mutex_lock(&cyapa->state_sync_lock); in cyapa_resume()
1408 if (device_may_wakeup(dev) && cyapa->irq_wake) { in cyapa_resume()
1409 disable_irq_wake(client->irq); in cyapa_resume()
1410 cyapa->irq_wake = false; in cyapa_resume()
1415 * Re-Enable proximity interrupt after enter operational mode. in cyapa_resume()
1421 enable_irq(client->irq); in cyapa_resume()
1423 mutex_unlock(&cyapa->state_sync_lock); in cyapa_resume()
1424 mutex_unlock(&cyapa->input->mutex); in cyapa_resume()
1433 error = cyapa->ops->set_power_mode(cyapa, in cyapa_runtime_suspend()
1434 cyapa->runtime_suspend_power_mode, in cyapa_runtime_suspend()
1435 cyapa->runtime_suspend_sleep_time, in cyapa_runtime_suspend()
1448 error = cyapa->ops->set_power_mode(cyapa, in cyapa_runtime_resume()