Lines Matching refs:ts

234 static int elants_i2c_calibrate(struct elants_data *ts)  in elants_i2c_calibrate()  argument
236 struct i2c_client *client = ts->client; in elants_i2c_calibrate()
244 ts->state = ELAN_WAIT_RECALIBRATION; in elants_i2c_calibrate()
245 reinit_completion(&ts->cmd_done); in elants_i2c_calibrate()
252 ret = wait_for_completion_interruptible_timeout(&ts->cmd_done, in elants_i2c_calibrate()
255 ts->state = ELAN_STATE_NORMAL; in elants_i2c_calibrate()
265 if (memcmp(rek_resp, ts->cmd_resp, sizeof(rek_resp))) { in elants_i2c_calibrate()
268 (int)sizeof(ts->cmd_resp), ts->cmd_resp); in elants_i2c_calibrate()
301 static int elants_i2c_query_hw_version(struct elants_data *ts) in elants_i2c_query_hw_version() argument
303 struct i2c_client *client = ts->client; in elants_i2c_query_hw_version()
312 ts->hw_version = elants_i2c_parse_version(resp); in elants_i2c_query_hw_version()
313 if (ts->hw_version != 0xffff) in elants_i2c_query_hw_version()
327 dev_err(&client->dev, "Invalid fw id: %#04x\n", ts->hw_version); in elants_i2c_query_hw_version()
332 static int elants_i2c_query_fw_version(struct elants_data *ts) in elants_i2c_query_fw_version() argument
334 struct i2c_client *client = ts->client; in elants_i2c_query_fw_version()
343 ts->fw_version = elants_i2c_parse_version(resp); in elants_i2c_query_fw_version()
344 if (ts->fw_version != 0x0000 && in elants_i2c_query_fw_version()
345 ts->fw_version != 0xffff) in elants_i2c_query_fw_version()
359 static int elants_i2c_query_test_version(struct elants_data *ts) in elants_i2c_query_test_version() argument
361 struct i2c_client *client = ts->client; in elants_i2c_query_test_version()
372 ts->test_version = version >> 8; in elants_i2c_query_test_version()
373 ts->solution_version = version & 0xff; in elants_i2c_query_test_version()
388 static int elants_i2c_query_bc_version(struct elants_data *ts) in elants_i2c_query_bc_version() argument
390 struct i2c_client *client = ts->client; in elants_i2c_query_bc_version()
406 ts->bc_version = version >> 8; in elants_i2c_query_bc_version()
407 ts->iap_version = version & 0xff; in elants_i2c_query_bc_version()
412 static int elants_i2c_query_ts_info(struct elants_data *ts) in elants_i2c_query_ts_info() argument
414 struct i2c_client *client = ts->client; in elants_i2c_query_ts_info()
489 ts->x_max = ELAN_TS_RESOLUTION(rows, osr); in elants_i2c_query_ts_info()
490 ts->x_res = DIV_ROUND_CLOSEST(ts->x_max, phy_x); in elants_i2c_query_ts_info()
491 ts->y_max = ELAN_TS_RESOLUTION(cols, osr); in elants_i2c_query_ts_info()
492 ts->y_res = DIV_ROUND_CLOSEST(ts->y_max, phy_y); in elants_i2c_query_ts_info()
513 static int elants_i2c_initialize(struct elants_data *ts) in elants_i2c_initialize() argument
515 struct i2c_client *client = ts->client; in elants_i2c_initialize()
544 ts->iap_mode = ELAN_IAP_OPERATIONAL; in elants_i2c_initialize()
562 error2 = elants_i2c_query_hw_version(ts); in elants_i2c_initialize()
567 error = elants_i2c_query_fw_version(ts); in elants_i2c_initialize()
569 error = elants_i2c_query_test_version(ts); in elants_i2c_initialize()
571 error = elants_i2c_query_bc_version(ts); in elants_i2c_initialize()
573 error = elants_i2c_query_ts_info(ts); in elants_i2c_initialize()
576 ts->iap_mode = ELAN_IAP_RECOVERY; in elants_i2c_initialize()
720 static int elants_i2c_fw_update(struct elants_data *ts) in elants_i2c_fw_update() argument
722 struct i2c_client *client = ts->client; in elants_i2c_fw_update()
727 fw_name = kasprintf(GFP_KERNEL, "elants_i2c_%04x.bin", ts->hw_version); in elants_i2c_fw_update()
750 ts->iap_mode == ELAN_IAP_RECOVERY); in elants_i2c_fw_update()
753 ts->iap_mode = ELAN_IAP_RECOVERY; in elants_i2c_fw_update()
757 error = elants_i2c_initialize(ts); in elants_i2c_fw_update()
762 ts->iap_mode = ELAN_IAP_RECOVERY; in elants_i2c_fw_update()
766 ts->iap_mode = ELAN_IAP_OPERATIONAL; in elants_i2c_fw_update()
769 ts->state = ELAN_STATE_NORMAL; in elants_i2c_fw_update()
774 elants_i2c_calibrate(ts); in elants_i2c_fw_update()
784 static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf) in elants_i2c_mt_event() argument
786 struct input_dev *input = ts->input; in elants_i2c_mt_event()
795 dev_dbg(&ts->client->dev, in elants_i2c_mt_event()
809 dev_dbg(&ts->client->dev, "i=%d x=%d y=%d p=%d w=%d\n", in elants_i2c_mt_event()
840 static void elants_i2c_event(struct elants_data *ts, u8 *buf) in elants_i2c_event() argument
845 dev_warn(&ts->client->dev, in elants_i2c_event()
850 dev_warn(&ts->client->dev, in elants_i2c_event()
854 elants_i2c_mt_event(ts, buf); in elants_i2c_event()
860 struct elants_data *ts = _dev; in elants_i2c_irq() local
861 struct i2c_client *client = ts->client; in elants_i2c_irq()
866 len = i2c_master_recv(client, ts->buf, sizeof(ts->buf)); in elants_i2c_irq()
874 __func__, HEADER_SIZE, ts->buf); in elants_i2c_irq()
876 switch (ts->state) { in elants_i2c_irq()
878 if (ts->buf[FW_HDR_TYPE] == CMD_HEADER_REK) { in elants_i2c_irq()
879 memcpy(ts->cmd_resp, ts->buf, sizeof(ts->cmd_resp)); in elants_i2c_irq()
880 complete(&ts->cmd_done); in elants_i2c_irq()
881 ts->state = ELAN_STATE_NORMAL; in elants_i2c_irq()
886 if (ts->buf[FW_HDR_TYPE] != QUEUE_HEADER_NORMAL) in elants_i2c_irq()
889 ts->state = ELAN_STATE_NORMAL; in elants_i2c_irq()
894 switch (ts->buf[FW_HDR_TYPE]) { in elants_i2c_irq()
901 if (memcmp(ts->buf, wait_packet, sizeof(wait_packet))) { in elants_i2c_irq()
904 HEADER_SIZE, ts->buf); in elants_i2c_irq()
906 ts->state = ELAN_WAIT_QUEUE_HEADER; in elants_i2c_irq()
912 elants_i2c_event(ts, &ts->buf[HEADER_SIZE]); in elants_i2c_irq()
916 report_count = ts->buf[FW_HDR_COUNT]; in elants_i2c_irq()
920 HEADER_SIZE, ts->buf); in elants_i2c_irq()
924 report_len = ts->buf[FW_HDR_LENGTH] / report_count; in elants_i2c_irq()
928 HEADER_SIZE, ts->buf); in elants_i2c_irq()
933 u8 *buf = ts->buf + HEADER_SIZE + in elants_i2c_irq()
935 elants_i2c_event(ts, buf); in elants_i2c_irq()
941 HEADER_SIZE, ts->buf); in elants_i2c_irq()
959 struct elants_data *ts = i2c_get_clientdata(client); in calibrate_store() local
962 error = mutex_lock_interruptible(&ts->sysfs_mutex); in calibrate_store()
966 error = elants_i2c_calibrate(ts); in calibrate_store()
968 mutex_unlock(&ts->sysfs_mutex); in calibrate_store()
977 struct elants_data *ts = i2c_get_clientdata(client); in write_update_fw() local
980 error = mutex_lock_interruptible(&ts->sysfs_mutex); in write_update_fw()
984 error = elants_i2c_fw_update(ts); in write_update_fw()
987 mutex_unlock(&ts->sysfs_mutex); in write_update_fw()
995 struct elants_data *ts = i2c_get_clientdata(client); in show_iap_mode() local
998 ts->iap_mode == ELAN_IAP_OPERATIONAL ? in show_iap_mode()
1030 struct elants_data *ts = i2c_get_clientdata(client); in elants_version_attribute_show() local
1033 u8 *field = (u8 *)((char *)ts + attr->field_offset); in elants_version_attribute_show()
1073 static int elants_i2c_power_on(struct elants_data *ts) in elants_i2c_power_on() argument
1081 if (IS_ERR_OR_NULL(ts->reset_gpio)) in elants_i2c_power_on()
1084 gpiod_set_value_cansleep(ts->reset_gpio, 1); in elants_i2c_power_on()
1086 error = regulator_enable(ts->vcc33); in elants_i2c_power_on()
1088 dev_err(&ts->client->dev, in elants_i2c_power_on()
1094 error = regulator_enable(ts->vccio); in elants_i2c_power_on()
1096 dev_err(&ts->client->dev, in elants_i2c_power_on()
1099 regulator_disable(ts->vcc33); in elants_i2c_power_on()
1110 gpiod_set_value_cansleep(ts->reset_gpio, 0); in elants_i2c_power_on()
1121 struct elants_data *ts = _data; in elants_i2c_power_off() local
1123 if (!IS_ERR_OR_NULL(ts->reset_gpio)) { in elants_i2c_power_off()
1128 gpiod_set_value_cansleep(ts->reset_gpio, 1); in elants_i2c_power_off()
1129 regulator_disable(ts->vccio); in elants_i2c_power_off()
1130 regulator_disable(ts->vcc33); in elants_i2c_power_off()
1138 struct elants_data *ts; in elants_i2c_probe() local
1148 ts = devm_kzalloc(&client->dev, sizeof(struct elants_data), GFP_KERNEL); in elants_i2c_probe()
1149 if (!ts) in elants_i2c_probe()
1152 mutex_init(&ts->sysfs_mutex); in elants_i2c_probe()
1153 init_completion(&ts->cmd_done); in elants_i2c_probe()
1155 ts->client = client; in elants_i2c_probe()
1156 i2c_set_clientdata(client, ts); in elants_i2c_probe()
1158 ts->vcc33 = devm_regulator_get(&client->dev, "vcc33"); in elants_i2c_probe()
1159 if (IS_ERR(ts->vcc33)) { in elants_i2c_probe()
1160 error = PTR_ERR(ts->vcc33); in elants_i2c_probe()
1168 ts->vccio = devm_regulator_get(&client->dev, "vccio"); in elants_i2c_probe()
1169 if (IS_ERR(ts->vccio)) { in elants_i2c_probe()
1170 error = PTR_ERR(ts->vccio); in elants_i2c_probe()
1178 ts->reset_gpio = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_LOW); in elants_i2c_probe()
1179 if (IS_ERR(ts->reset_gpio)) { in elants_i2c_probe()
1180 error = PTR_ERR(ts->reset_gpio); in elants_i2c_probe()
1192 ts->keep_power_in_suspend = true; in elants_i2c_probe()
1195 error = elants_i2c_power_on(ts); in elants_i2c_probe()
1199 error = devm_add_action(&client->dev, elants_i2c_power_off, ts); in elants_i2c_probe()
1203 elants_i2c_power_off(ts); in elants_i2c_probe()
1214 error = elants_i2c_initialize(ts); in elants_i2c_probe()
1220 ts->input = devm_input_allocate_device(&client->dev); in elants_i2c_probe()
1221 if (!ts->input) { in elants_i2c_probe()
1226 ts->input->name = "Elan Touchscreen"; in elants_i2c_probe()
1227 ts->input->id.bustype = BUS_I2C; in elants_i2c_probe()
1229 __set_bit(BTN_TOUCH, ts->input->keybit); in elants_i2c_probe()
1230 __set_bit(EV_ABS, ts->input->evbit); in elants_i2c_probe()
1231 __set_bit(EV_KEY, ts->input->evbit); in elants_i2c_probe()
1234 input_set_abs_params(ts->input, ABS_X, 0, ts->x_max, 0, 0); in elants_i2c_probe()
1235 input_set_abs_params(ts->input, ABS_Y, 0, ts->y_max, 0, 0); in elants_i2c_probe()
1236 input_set_abs_params(ts->input, ABS_PRESSURE, 0, 255, 0, 0); in elants_i2c_probe()
1237 input_abs_set_res(ts->input, ABS_X, ts->x_res); in elants_i2c_probe()
1238 input_abs_set_res(ts->input, ABS_Y, ts->y_res); in elants_i2c_probe()
1241 error = input_mt_init_slots(ts->input, MAX_CONTACT_NUM, in elants_i2c_probe()
1249 input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts->x_max, 0, 0); in elants_i2c_probe()
1250 input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->y_max, 0, 0); in elants_i2c_probe()
1251 input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); in elants_i2c_probe()
1252 input_set_abs_params(ts->input, ABS_MT_PRESSURE, 0, 255, 0, 0); in elants_i2c_probe()
1253 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->x_res); in elants_i2c_probe()
1254 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res); in elants_i2c_probe()
1256 error = input_register_device(ts->input); in elants_i2c_probe()
1275 client->name, ts); in elants_i2c_probe()
1301 struct elants_data *ts = i2c_get_clientdata(client); in elants_i2c_suspend() local
1307 if (ts->iap_mode != ELAN_IAP_OPERATIONAL) in elants_i2c_suspend()
1317 ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0); in elants_i2c_suspend()
1318 } else if (ts->keep_power_in_suspend) { in elants_i2c_suspend()
1329 elants_i2c_power_off(ts); in elants_i2c_suspend()
1338 struct elants_data *ts = i2c_get_clientdata(client); in elants_i2c_resume() local
1344 if (ts->wake_irq_enabled) in elants_i2c_resume()
1347 } else if (ts->keep_power_in_suspend) { in elants_i2c_resume()
1358 elants_i2c_power_on(ts); in elants_i2c_resume()
1359 elants_i2c_initialize(ts); in elants_i2c_resume()
1362 ts->state = ELAN_STATE_NORMAL; in elants_i2c_resume()