Lines Matching full:ts
188 static int mip4_i2c_xfer(struct mip4_ts *ts, in mip4_i2c_xfer() argument
194 .addr = ts->client->addr, in mip4_i2c_xfer()
199 .addr = ts->client->addr, in mip4_i2c_xfer()
210 res = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_i2c_xfer()
215 dev_err(&ts->client->dev, in mip4_i2c_xfer()
234 static int mip4_get_fw_version(struct mip4_ts *ts) in mip4_get_fw_version() argument
237 u8 buf[sizeof(ts->fw_version)]; in mip4_get_fw_version()
240 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, sizeof(buf)); in mip4_get_fw_version()
242 memset(&ts->fw_version, 0xff, sizeof(ts->fw_version)); in mip4_get_fw_version()
246 mip4_parse_fw_version(buf, &ts->fw_version); in mip4_get_fw_version()
254 static int mip4_query_device(struct mip4_ts *ts) in mip4_query_device() argument
265 if (i2c_smbus_xfer(ts->client->adapter, ts->client->addr, in mip4_query_device()
267 dev_err(&ts->client->dev, "nothing at this address\n"); in mip4_query_device()
274 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), in mip4_query_device()
275 ts->product_name, sizeof(ts->product_name)); in mip4_query_device()
277 dev_warn(&ts->client->dev, in mip4_query_device()
280 dev_dbg(&ts->client->dev, "product name: %.*s\n", in mip4_query_device()
281 (int)sizeof(ts->product_name), ts->product_name); in mip4_query_device()
286 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, 2); in mip4_query_device()
288 dev_warn(&ts->client->dev, in mip4_query_device()
291 ts->product_id = get_unaligned_le16(&buf[0]); in mip4_query_device()
292 dev_dbg(&ts->client->dev, "product id: %04X\n", ts->product_id); in mip4_query_device()
296 snprintf(ts->fw_name, sizeof(ts->fw_name), in mip4_query_device()
297 "melfas_mip4_%04X.fw", ts->product_id); in mip4_query_device()
298 dev_dbg(&ts->client->dev, "firmware name: %s\n", ts->fw_name); in mip4_query_device()
303 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), in mip4_query_device()
304 ts->ic_name, sizeof(ts->ic_name)); in mip4_query_device()
306 dev_warn(&ts->client->dev, in mip4_query_device()
309 dev_dbg(&ts->client->dev, "IC name: %.*s\n", in mip4_query_device()
310 (int)sizeof(ts->ic_name), ts->ic_name); in mip4_query_device()
313 error = mip4_get_fw_version(ts); in mip4_query_device()
315 dev_warn(&ts->client->dev, in mip4_query_device()
318 dev_dbg(&ts->client->dev, "F/W Version: %04X %04X %04X %04X\n", in mip4_query_device()
319 ts->fw_version.boot, ts->fw_version.core, in mip4_query_device()
320 ts->fw_version.app, ts->fw_version.param); in mip4_query_device()
325 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, 14); in mip4_query_device()
327 dev_warn(&ts->client->dev, in mip4_query_device()
331 ts->max_x = get_unaligned_le16(&buf[0]); in mip4_query_device()
332 ts->max_y = get_unaligned_le16(&buf[2]); in mip4_query_device()
333 dev_dbg(&ts->client->dev, "max_x: %d, max_y: %d\n", in mip4_query_device()
334 ts->max_x, ts->max_y); in mip4_query_device()
336 ts->node_x = buf[4]; in mip4_query_device()
337 ts->node_y = buf[5]; in mip4_query_device()
338 ts->node_key = buf[6]; in mip4_query_device()
339 dev_dbg(&ts->client->dev, in mip4_query_device()
341 ts->node_x, ts->node_y, ts->node_key); in mip4_query_device()
343 ts->ppm_x = buf[12]; in mip4_query_device()
344 ts->ppm_y = buf[13]; in mip4_query_device()
345 dev_dbg(&ts->client->dev, "ppm_x: %d, ppm_y: %d\n", in mip4_query_device()
346 ts->ppm_x, ts->ppm_y); in mip4_query_device()
348 /* Key ts */ in mip4_query_device()
349 if (ts->node_key > 0) in mip4_query_device()
350 ts->key_num = ts->node_key; in mip4_query_device()
356 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, 7); in mip4_query_device()
358 dev_warn(&ts->client->dev, in mip4_query_device()
360 ts->event_format = 0xff; in mip4_query_device()
362 ts->event_format = get_unaligned_le16(&buf[4]); in mip4_query_device()
363 ts->event_size = buf[6]; in mip4_query_device()
364 dev_dbg(&ts->client->dev, "event_format: %d, event_size: %d\n", in mip4_query_device()
365 ts->event_format, ts->event_size); in mip4_query_device()
367 if (ts->event_format == 2 || ts->event_format > 3) in mip4_query_device()
368 dev_warn(&ts->client->dev, in mip4_query_device()
369 "Unknown event format %d\n", ts->event_format); in mip4_query_device()
375 static int mip4_power_on(struct mip4_ts *ts) in mip4_power_on() argument
377 if (ts->gpio_ce) { in mip4_power_on()
378 gpiod_set_value_cansleep(ts->gpio_ce, 1); in mip4_power_on()
387 static void mip4_power_off(struct mip4_ts *ts) in mip4_power_off() argument
389 if (ts->gpio_ce) in mip4_power_off()
390 gpiod_set_value_cansleep(ts->gpio_ce, 0); in mip4_power_off()
396 static void mip4_clear_input(struct mip4_ts *ts) in mip4_clear_input() argument
402 input_mt_slot(ts->input, i); in mip4_clear_input()
403 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 0); in mip4_clear_input()
407 for (i = 0; i < ts->key_num; i++) in mip4_clear_input()
408 input_report_key(ts->input, ts->key_code[i], 0); in mip4_clear_input()
410 input_sync(ts->input); in mip4_clear_input()
413 static int mip4_enable(struct mip4_ts *ts) in mip4_enable() argument
417 error = mip4_power_on(ts); in mip4_enable()
421 enable_irq(ts->client->irq); in mip4_enable()
426 static void mip4_disable(struct mip4_ts *ts) in mip4_disable() argument
428 disable_irq(ts->client->irq); in mip4_disable()
430 mip4_power_off(ts); in mip4_disable()
432 mip4_clear_input(ts); in mip4_disable()
439 static void mip4_report_keys(struct mip4_ts *ts, u8 *packet) in mip4_report_keys() argument
444 switch (ts->event_format) { in mip4_report_keys()
459 if (key >= 1 && key <= ts->key_num) { in mip4_report_keys()
460 unsigned short keycode = ts->key_code[key - 1]; in mip4_report_keys()
462 dev_dbg(&ts->client->dev, in mip4_report_keys()
466 input_event(ts->input, EV_MSC, MSC_SCAN, keycode); in mip4_report_keys()
467 input_report_key(ts->input, keycode, down); in mip4_report_keys()
470 dev_err(&ts->client->dev, "Unknown key: %d\n", key); in mip4_report_keys()
474 static void mip4_report_touch(struct mip4_ts *ts, u8 *packet) in mip4_report_touch() argument
487 switch (ts->event_format) { in mip4_report_touch()
500 if (ts->event_format == 0) { in mip4_report_touch()
528 dev_dbg(&ts->client->dev, in mip4_report_touch()
533 dev_err(&ts->client->dev, "Screen - invalid slot ID: %d\n", id); in mip4_report_touch()
536 input_mt_slot(ts->input, id); in mip4_report_touch()
537 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, true); in mip4_report_touch()
538 input_report_abs(ts->input, ABS_MT_POSITION_X, x); in mip4_report_touch()
539 input_report_abs(ts->input, ABS_MT_POSITION_Y, y); in mip4_report_touch()
540 input_report_abs(ts->input, ABS_MT_PRESSURE, pressure); in mip4_report_touch()
541 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, touch_major); in mip4_report_touch()
542 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR, touch_minor); in mip4_report_touch()
545 input_mt_slot(ts->input, id); in mip4_report_touch()
546 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 0); in mip4_report_touch()
549 input_mt_sync_frame(ts->input); in mip4_report_touch()
552 static int mip4_handle_packet(struct mip4_ts *ts, u8 *packet) in mip4_handle_packet() argument
556 switch (ts->event_format) { in mip4_handle_packet()
571 dev_dbg(&ts->client->dev, "Type: %d\n", type); in mip4_handle_packet()
576 mip4_report_keys(ts, packet); in mip4_handle_packet()
580 mip4_report_touch(ts, packet); in mip4_handle_packet()
584 dev_err(&ts->client->dev, "Unknown event type: %d\n", type); in mip4_handle_packet()
593 struct mip4_ts *ts = dev_id; in mip4_interrupt() local
594 struct i2c_client *client = ts->client; in mip4_interrupt()
604 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), ts->buf, 1); in mip4_interrupt()
611 size = ts->buf[0] & 0x7F; in mip4_interrupt()
612 alert = ts->buf[0] & BIT(7); in mip4_interrupt()
624 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), ts->buf, size); in mip4_interrupt()
632 dev_dbg(&client->dev, "Alert: %d\n", ts->buf[0]); in mip4_interrupt()
634 for (i = 0; i < size; i += ts->event_size) { in mip4_interrupt()
635 error = mip4_handle_packet(ts, &ts->buf[i]); in mip4_interrupt()
640 input_sync(ts->input); in mip4_interrupt()
649 struct mip4_ts *ts = input_get_drvdata(dev); in mip4_input_open() local
651 return mip4_enable(ts); in mip4_input_open()
656 struct mip4_ts *ts = input_get_drvdata(dev); in mip4_input_close() local
658 mip4_disable(ts); in mip4_input_close()
715 static int mip4_bl_read_status(struct mip4_ts *ts) in mip4_bl_read_status() argument
721 .addr = ts->client->addr, in mip4_bl_read_status()
726 .addr = ts->client->addr, in mip4_bl_read_status()
737 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_read_status()
740 dev_err(&ts->client->dev, in mip4_bl_read_status()
748 dev_dbg(&ts->client->dev, "%s - done\n", __func__); in mip4_bl_read_status()
752 dev_err(&ts->client->dev, "Bootloader failure\n"); in mip4_bl_read_status()
756 dev_dbg(&ts->client->dev, "%s - Busy\n", __func__); in mip4_bl_read_status()
761 dev_err(&ts->client->dev, in mip4_bl_read_status()
777 static int mip4_bl_change_mode(struct mip4_ts *ts, u8 mode) in mip4_bl_change_mode() argument
784 .addr = ts->client->addr, in mip4_bl_change_mode()
789 .addr = ts->client->addr, in mip4_bl_change_mode()
801 ret = i2c_master_send(ts->client, in mip4_bl_change_mode()
805 dev_err(&ts->client->dev, in mip4_bl_change_mode()
811 dev_dbg(&ts->client->dev, in mip4_bl_change_mode()
818 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_change_mode()
821 dev_err(&ts->client->dev, in mip4_bl_change_mode()
826 dev_dbg(&ts->client->dev, in mip4_bl_change_mode()
840 static int mip4_bl_enter(struct mip4_ts *ts) in mip4_bl_enter() argument
842 return mip4_bl_change_mode(ts, MIP4_BOOT_MODE_BOOT); in mip4_bl_enter()
848 static int mip4_bl_exit(struct mip4_ts *ts) in mip4_bl_exit() argument
850 return mip4_bl_change_mode(ts, MIP4_BOOT_MODE_APP); in mip4_bl_exit()
853 static int mip4_bl_get_address(struct mip4_ts *ts, u16 *buf_addr) in mip4_bl_get_address() argument
859 .addr = ts->client->addr, in mip4_bl_get_address()
864 .addr = ts->client->addr, in mip4_bl_get_address()
873 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_get_address()
876 dev_err(&ts->client->dev, in mip4_bl_get_address()
883 dev_dbg(&ts->client->dev, in mip4_bl_get_address()
889 static int mip4_bl_program_page(struct mip4_ts *ts, int offset, in mip4_bl_program_page() argument
898 dev_dbg(&ts->client->dev, "Writing page @%#06x (%d)\n", in mip4_bl_program_page()
902 dev_err(&ts->client->dev, in mip4_bl_program_page()
915 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_program_page()
918 dev_err(&ts->client->dev, in mip4_bl_program_page()
927 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_program_page()
930 dev_err(&ts->client->dev, in mip4_bl_program_page()
939 dev_dbg(&ts->client->dev, in mip4_bl_program_page()
944 ret = i2c_master_send(ts->client, in mip4_bl_program_page()
948 dev_err(&ts->client->dev, in mip4_bl_program_page()
959 ret = i2c_master_send(ts->client, cmd, 3); in mip4_bl_program_page()
962 dev_err(&ts->client->dev, in mip4_bl_program_page()
968 error = mip4_bl_read_status(ts); in mip4_bl_program_page()
975 static int mip4_bl_verify_page(struct mip4_ts *ts, int offset, in mip4_bl_verify_page() argument
983 .addr = ts->client->addr, in mip4_bl_verify_page()
988 .addr = ts->client->addr, in mip4_bl_verify_page()
996 dev_dbg(&ts->client->dev, "Validating page @%#06x (%d)\n", in mip4_bl_verify_page()
1003 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_verify_page()
1006 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1015 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_verify_page()
1018 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1027 ret = i2c_master_send(ts->client, cmd, 3); in mip4_bl_verify_page()
1030 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1036 error = mip4_bl_read_status(ts); in mip4_bl_verify_page()
1048 dev_dbg(&ts->client->dev, in mip4_bl_verify_page()
1052 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_verify_page()
1055 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1062 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1088 static int mip4_flash_fw(struct mip4_ts *ts, in mip4_flash_fw() argument
1091 struct i2c_client *client = ts->client; in mip4_flash_fw()
1099 error = mip4_bl_enter(ts); in mip4_flash_fw()
1108 error = mip4_bl_get_address(ts, &buf_addr); in mip4_flash_fw()
1121 error = mip4_bl_program_page(ts, offset, fw_data + offset, in mip4_flash_fw()
1127 error = mip4_bl_verify_page(ts, offset, fw_data + offset, in mip4_flash_fw()
1137 error2 = mip4_bl_exit(ts); in mip4_flash_fw()
1146 mip4_power_off(ts); in mip4_flash_fw()
1147 mip4_power_on(ts); in mip4_flash_fw()
1149 mip4_query_device(ts); in mip4_flash_fw()
1152 input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0); in mip4_flash_fw()
1153 input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0); in mip4_flash_fw()
1154 input_set_abs_params(ts->input, ABS_X, 0, ts->max_x, 0, 0); in mip4_flash_fw()
1155 input_set_abs_params(ts->input, ABS_Y, 0, ts->max_y, 0, 0); in mip4_flash_fw()
1156 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x); in mip4_flash_fw()
1157 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y); in mip4_flash_fw()
1158 input_abs_set_res(ts->input, ABS_X, ts->ppm_x); in mip4_flash_fw()
1159 input_abs_set_res(ts->input, ABS_Y, ts->ppm_y); in mip4_flash_fw()
1164 static int mip4_parse_firmware(struct mip4_ts *ts, const struct firmware *fw, in mip4_parse_firmware() argument
1173 dev_err(&ts->client->dev, in mip4_parse_firmware()
1188 dev_err(&ts->client->dev, in mip4_parse_firmware()
1197 dev_err(&ts->client->dev, in mip4_parse_firmware()
1207 dev_dbg(&ts->client->dev, in mip4_parse_firmware()
1212 dev_err(&ts->client->dev, in mip4_parse_firmware()
1219 dev_err(&ts->client->dev, in mip4_parse_firmware()
1227 dev_dbg(&ts->client->dev, in mip4_parse_firmware()
1232 dev_dbg(&ts->client->dev, "F/W chip version: %04X %04X %04X %04X\n", in mip4_parse_firmware()
1233 ts->fw_version.boot, ts->fw_version.core, in mip4_parse_firmware()
1234 ts->fw_version.app, ts->fw_version.param); in mip4_parse_firmware()
1241 dev_dbg(&ts->client->dev, "F/W type: Bootloader\n"); in mip4_parse_firmware()
1246 dev_dbg(&ts->client->dev, "F/W type: Main\n"); in mip4_parse_firmware()
1248 dev_err(&ts->client->dev, "Wrong firmware type\n"); in mip4_parse_firmware()
1255 static int mip4_execute_fw_update(struct mip4_ts *ts, const struct firmware *fw) in mip4_execute_fw_update() argument
1263 error = mip4_parse_firmware(ts, fw, in mip4_execute_fw_update()
1268 if (ts->input->users) { in mip4_execute_fw_update()
1269 disable_irq(ts->client->irq); in mip4_execute_fw_update()
1271 error = mip4_power_on(ts); in mip4_execute_fw_update()
1278 error = mip4_flash_fw(ts, fw->data, fw_size, fw_start_offset); in mip4_execute_fw_update()
1284 dev_err(&ts->client->dev, in mip4_execute_fw_update()
1288 if (ts->input->users) in mip4_execute_fw_update()
1289 enable_irq(ts->client->irq); in mip4_execute_fw_update()
1291 mip4_power_off(ts); in mip4_execute_fw_update()
1301 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_fw_update() local
1305 error = request_firmware(&fw, ts->fw_name, dev); in mip4_sysfs_fw_update()
1307 dev_err(&ts->client->dev, in mip4_sysfs_fw_update()
1309 ts->fw_name, error); in mip4_sysfs_fw_update()
1318 mutex_lock(&ts->input->mutex); in mip4_sysfs_fw_update()
1320 error = mip4_execute_fw_update(ts, fw); in mip4_sysfs_fw_update()
1322 mutex_unlock(&ts->input->mutex); in mip4_sysfs_fw_update()
1327 dev_err(&ts->client->dev, in mip4_sysfs_fw_update()
1342 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_fw_version() local
1346 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_fw_version()
1349 ts->fw_version.boot, ts->fw_version.core, in mip4_sysfs_read_fw_version()
1350 ts->fw_version.app, ts->fw_version.param); in mip4_sysfs_read_fw_version()
1352 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_fw_version()
1364 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_hw_version() local
1368 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_hw_version()
1375 (int)sizeof(ts->product_name), ts->product_name); in mip4_sysfs_read_hw_version()
1377 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_hw_version()
1389 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_product_id() local
1392 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_product_id()
1394 count = snprintf(buf, PAGE_SIZE, "%04X\n", ts->product_id); in mip4_sysfs_read_product_id()
1396 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_product_id()
1408 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_ic_name() local
1411 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_ic_name()
1414 (int)sizeof(ts->ic_name), ts->ic_name); in mip4_sysfs_read_ic_name()
1416 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_ic_name()
1438 struct mip4_ts *ts; in mip4_probe() local
1447 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in mip4_probe()
1448 if (!ts) in mip4_probe()
1455 ts->client = client; in mip4_probe()
1456 ts->input = input; in mip4_probe()
1458 snprintf(ts->phys, sizeof(ts->phys), in mip4_probe()
1461 ts->gpio_ce = devm_gpiod_get_optional(&client->dev, in mip4_probe()
1463 if (IS_ERR(ts->gpio_ce)) { in mip4_probe()
1464 error = PTR_ERR(ts->gpio_ce); in mip4_probe()
1471 error = mip4_power_on(ts); in mip4_probe()
1474 error = mip4_query_device(ts); in mip4_probe()
1475 mip4_power_off(ts); in mip4_probe()
1480 input->phys = ts->phys; in mip4_probe()
1484 input->id.product = ts->product_id; in mip4_probe()
1489 input_set_drvdata(input, ts); in mip4_probe()
1491 input->keycode = ts->key_code; in mip4_probe()
1492 input->keycodesize = sizeof(*ts->key_code); in mip4_probe()
1493 input->keycodemax = ts->key_num; in mip4_probe()
1495 input_set_abs_params(input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0); in mip4_probe()
1496 input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0); in mip4_probe()
1503 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x); in mip4_probe()
1504 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y); in mip4_probe()
1510 i2c_set_clientdata(client, ts); in mip4_probe()
1514 IRQF_ONESHOT, MIP4_DEVICE_NAME, ts); in mip4_probe()
1544 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_suspend() local
1545 struct input_dev *input = ts->input; in mip4_suspend()
1550 ts->wake_irq_enabled = enable_irq_wake(client->irq) == 0; in mip4_suspend()
1552 mip4_disable(ts); in mip4_suspend()
1562 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_resume() local
1563 struct input_dev *input = ts->input; in mip4_resume()
1567 if (ts->wake_irq_enabled) in mip4_resume()
1570 mip4_enable(ts); in mip4_resume()