Lines Matching refs:ts

179 static int mip4_i2c_xfer(struct mip4_ts *ts,  in mip4_i2c_xfer()  argument
185 .addr = ts->client->addr, in mip4_i2c_xfer()
190 .addr = ts->client->addr, in mip4_i2c_xfer()
201 res = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_i2c_xfer()
206 dev_err(&ts->client->dev, in mip4_i2c_xfer()
225 static int mip4_get_fw_version(struct mip4_ts *ts) in mip4_get_fw_version() argument
228 u8 buf[sizeof(ts->fw_version)]; in mip4_get_fw_version()
231 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, sizeof(buf)); in mip4_get_fw_version()
233 memset(&ts->fw_version, 0xff, sizeof(ts->fw_version)); in mip4_get_fw_version()
237 mip4_parse_fw_version(buf, &ts->fw_version); in mip4_get_fw_version()
245 static int mip4_query_device(struct mip4_ts *ts) in mip4_query_device() argument
256 if (i2c_smbus_xfer(ts->client->adapter, ts->client->addr, in mip4_query_device()
258 dev_err(&ts->client->dev, "nothing at this address\n"); in mip4_query_device()
265 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), in mip4_query_device()
266 ts->product_name, sizeof(ts->product_name)); in mip4_query_device()
268 dev_warn(&ts->client->dev, in mip4_query_device()
271 dev_dbg(&ts->client->dev, "product name: %.*s\n", in mip4_query_device()
272 (int)sizeof(ts->product_name), ts->product_name); in mip4_query_device()
277 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, 2); in mip4_query_device()
279 dev_warn(&ts->client->dev, in mip4_query_device()
282 ts->product_id = get_unaligned_le16(&buf[0]); in mip4_query_device()
283 dev_dbg(&ts->client->dev, "product id: %04X\n", ts->product_id); in mip4_query_device()
287 snprintf(ts->fw_name, sizeof(ts->fw_name), in mip4_query_device()
288 "melfas_mip4_%04X.fw", ts->product_id); in mip4_query_device()
289 dev_dbg(&ts->client->dev, "firmware name: %s\n", ts->fw_name); in mip4_query_device()
294 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), in mip4_query_device()
295 ts->ic_name, sizeof(ts->ic_name)); in mip4_query_device()
297 dev_warn(&ts->client->dev, in mip4_query_device()
300 dev_dbg(&ts->client->dev, "IC name: %.*s\n", in mip4_query_device()
301 (int)sizeof(ts->ic_name), ts->ic_name); in mip4_query_device()
304 error = mip4_get_fw_version(ts); in mip4_query_device()
306 dev_warn(&ts->client->dev, in mip4_query_device()
309 dev_dbg(&ts->client->dev, "F/W Version: %04X %04X %04X %04X\n", in mip4_query_device()
310 ts->fw_version.boot, ts->fw_version.core, in mip4_query_device()
311 ts->fw_version.app, ts->fw_version.param); in mip4_query_device()
316 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, 14); in mip4_query_device()
318 dev_warn(&ts->client->dev, in mip4_query_device()
322 ts->max_x = get_unaligned_le16(&buf[0]); in mip4_query_device()
323 ts->max_y = get_unaligned_le16(&buf[2]); in mip4_query_device()
324 dev_dbg(&ts->client->dev, "max_x: %d, max_y: %d\n", in mip4_query_device()
325 ts->max_x, ts->max_y); in mip4_query_device()
327 ts->node_x = buf[4]; in mip4_query_device()
328 ts->node_y = buf[5]; in mip4_query_device()
329 ts->node_key = buf[6]; in mip4_query_device()
330 dev_dbg(&ts->client->dev, in mip4_query_device()
332 ts->node_x, ts->node_y, ts->node_key); in mip4_query_device()
334 ts->ppm_x = buf[12]; in mip4_query_device()
335 ts->ppm_y = buf[13]; in mip4_query_device()
336 dev_dbg(&ts->client->dev, "ppm_x: %d, ppm_y: %d\n", in mip4_query_device()
337 ts->ppm_x, ts->ppm_y); in mip4_query_device()
340 if (ts->node_key > 0) in mip4_query_device()
341 ts->key_num = ts->node_key; in mip4_query_device()
347 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), buf, 7); in mip4_query_device()
349 dev_warn(&ts->client->dev, in mip4_query_device()
351 ts->event_format = 0xff; in mip4_query_device()
353 ts->event_format = get_unaligned_le16(&buf[4]); in mip4_query_device()
354 ts->event_size = buf[6]; in mip4_query_device()
355 dev_dbg(&ts->client->dev, "event_format: %d, event_size: %d\n", in mip4_query_device()
356 ts->event_format, ts->event_size); in mip4_query_device()
358 if (ts->event_format == 2 || ts->event_format > 3) in mip4_query_device()
359 dev_warn(&ts->client->dev, in mip4_query_device()
360 "Unknown event format %d\n", ts->event_format); in mip4_query_device()
366 static int mip4_power_on(struct mip4_ts *ts) in mip4_power_on() argument
368 if (ts->gpio_ce) { in mip4_power_on()
369 gpiod_set_value_cansleep(ts->gpio_ce, 1); in mip4_power_on()
378 static void mip4_power_off(struct mip4_ts *ts) in mip4_power_off() argument
380 if (ts->gpio_ce) in mip4_power_off()
381 gpiod_set_value_cansleep(ts->gpio_ce, 0); in mip4_power_off()
387 static void mip4_clear_input(struct mip4_ts *ts) in mip4_clear_input() argument
393 input_mt_slot(ts->input, i); in mip4_clear_input()
394 input_mt_report_slot_inactive(ts->input); in mip4_clear_input()
398 for (i = 0; i < ts->key_num; i++) in mip4_clear_input()
399 input_report_key(ts->input, ts->key_code[i], 0); in mip4_clear_input()
401 input_sync(ts->input); in mip4_clear_input()
404 static int mip4_enable(struct mip4_ts *ts) in mip4_enable() argument
408 error = mip4_power_on(ts); in mip4_enable()
412 enable_irq(ts->client->irq); in mip4_enable()
417 static void mip4_disable(struct mip4_ts *ts) in mip4_disable() argument
419 disable_irq(ts->client->irq); in mip4_disable()
421 mip4_power_off(ts); in mip4_disable()
423 mip4_clear_input(ts); in mip4_disable()
430 static void mip4_report_keys(struct mip4_ts *ts, u8 *packet) in mip4_report_keys() argument
435 switch (ts->event_format) { in mip4_report_keys()
450 if (key >= 1 && key <= ts->key_num) { in mip4_report_keys()
451 unsigned short keycode = ts->key_code[key - 1]; in mip4_report_keys()
453 dev_dbg(&ts->client->dev, in mip4_report_keys()
457 input_event(ts->input, EV_MSC, MSC_SCAN, keycode); in mip4_report_keys()
458 input_report_key(ts->input, keycode, down); in mip4_report_keys()
461 dev_err(&ts->client->dev, "Unknown key: %d\n", key); in mip4_report_keys()
465 static void mip4_report_touch(struct mip4_ts *ts, u8 *packet) in mip4_report_touch() argument
478 switch (ts->event_format) { in mip4_report_touch()
491 if (ts->event_format == 0) { in mip4_report_touch()
519 dev_dbg(&ts->client->dev, in mip4_report_touch()
524 dev_err(&ts->client->dev, "Screen - invalid slot ID: %d\n", id); in mip4_report_touch()
528 input_mt_slot(ts->input, id); in mip4_report_touch()
529 if (input_mt_report_slot_state(ts->input, in mip4_report_touch()
532 input_report_abs(ts->input, ABS_MT_POSITION_X, x); in mip4_report_touch()
533 input_report_abs(ts->input, ABS_MT_POSITION_Y, y); in mip4_report_touch()
534 input_report_abs(ts->input, ABS_MT_PRESSURE, pressure); in mip4_report_touch()
535 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, touch_major); in mip4_report_touch()
536 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR, touch_minor); in mip4_report_touch()
540 input_mt_sync_frame(ts->input); in mip4_report_touch()
543 static int mip4_handle_packet(struct mip4_ts *ts, u8 *packet) in mip4_handle_packet() argument
547 switch (ts->event_format) { in mip4_handle_packet()
562 dev_dbg(&ts->client->dev, "Type: %d\n", type); in mip4_handle_packet()
567 mip4_report_keys(ts, packet); in mip4_handle_packet()
571 mip4_report_touch(ts, packet); in mip4_handle_packet()
575 dev_err(&ts->client->dev, "Unknown event type: %d\n", type); in mip4_handle_packet()
584 struct mip4_ts *ts = dev_id; in mip4_interrupt() local
585 struct i2c_client *client = ts->client; in mip4_interrupt()
595 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), ts->buf, 1); in mip4_interrupt()
602 size = ts->buf[0] & 0x7F; in mip4_interrupt()
603 alert = ts->buf[0] & BIT(7); in mip4_interrupt()
615 error = mip4_i2c_xfer(ts, cmd, sizeof(cmd), ts->buf, size); in mip4_interrupt()
623 dev_dbg(&client->dev, "Alert: %d\n", ts->buf[0]); in mip4_interrupt()
625 for (i = 0; i < size; i += ts->event_size) { in mip4_interrupt()
626 error = mip4_handle_packet(ts, &ts->buf[i]); in mip4_interrupt()
631 input_sync(ts->input); in mip4_interrupt()
640 struct mip4_ts *ts = input_get_drvdata(dev); in mip4_input_open() local
642 return mip4_enable(ts); in mip4_input_open()
647 struct mip4_ts *ts = input_get_drvdata(dev); in mip4_input_close() local
649 mip4_disable(ts); in mip4_input_close()
706 static int mip4_bl_read_status(struct mip4_ts *ts) in mip4_bl_read_status() argument
712 .addr = ts->client->addr, in mip4_bl_read_status()
717 .addr = ts->client->addr, in mip4_bl_read_status()
728 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_read_status()
731 dev_err(&ts->client->dev, in mip4_bl_read_status()
739 dev_dbg(&ts->client->dev, "%s - done\n", __func__); in mip4_bl_read_status()
743 dev_err(&ts->client->dev, "Bootloader failure\n"); in mip4_bl_read_status()
747 dev_dbg(&ts->client->dev, "%s - Busy\n", __func__); in mip4_bl_read_status()
752 dev_err(&ts->client->dev, in mip4_bl_read_status()
768 static int mip4_bl_change_mode(struct mip4_ts *ts, u8 mode) in mip4_bl_change_mode() argument
775 .addr = ts->client->addr, in mip4_bl_change_mode()
780 .addr = ts->client->addr, in mip4_bl_change_mode()
792 ret = i2c_master_send(ts->client, in mip4_bl_change_mode()
796 dev_err(&ts->client->dev, in mip4_bl_change_mode()
802 dev_dbg(&ts->client->dev, in mip4_bl_change_mode()
809 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_change_mode()
812 dev_err(&ts->client->dev, in mip4_bl_change_mode()
817 dev_dbg(&ts->client->dev, in mip4_bl_change_mode()
831 static int mip4_bl_enter(struct mip4_ts *ts) in mip4_bl_enter() argument
833 return mip4_bl_change_mode(ts, MIP4_BOOT_MODE_BOOT); in mip4_bl_enter()
839 static int mip4_bl_exit(struct mip4_ts *ts) in mip4_bl_exit() argument
841 return mip4_bl_change_mode(ts, MIP4_BOOT_MODE_APP); in mip4_bl_exit()
844 static int mip4_bl_get_address(struct mip4_ts *ts, u16 *buf_addr) in mip4_bl_get_address() argument
850 .addr = ts->client->addr, in mip4_bl_get_address()
855 .addr = ts->client->addr, in mip4_bl_get_address()
864 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_get_address()
867 dev_err(&ts->client->dev, in mip4_bl_get_address()
874 dev_dbg(&ts->client->dev, in mip4_bl_get_address()
880 static int mip4_bl_program_page(struct mip4_ts *ts, int offset, in mip4_bl_program_page() argument
889 dev_dbg(&ts->client->dev, "Writing page @%#06x (%d)\n", in mip4_bl_program_page()
893 dev_err(&ts->client->dev, in mip4_bl_program_page()
906 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_program_page()
909 dev_err(&ts->client->dev, in mip4_bl_program_page()
918 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_program_page()
921 dev_err(&ts->client->dev, in mip4_bl_program_page()
930 dev_dbg(&ts->client->dev, in mip4_bl_program_page()
935 ret = i2c_master_send(ts->client, in mip4_bl_program_page()
939 dev_err(&ts->client->dev, in mip4_bl_program_page()
950 ret = i2c_master_send(ts->client, cmd, 3); in mip4_bl_program_page()
953 dev_err(&ts->client->dev, in mip4_bl_program_page()
959 error = mip4_bl_read_status(ts); in mip4_bl_program_page()
966 static int mip4_bl_verify_page(struct mip4_ts *ts, int offset, in mip4_bl_verify_page() argument
974 .addr = ts->client->addr, in mip4_bl_verify_page()
979 .addr = ts->client->addr, in mip4_bl_verify_page()
987 dev_dbg(&ts->client->dev, "Validating page @%#06x (%d)\n", in mip4_bl_verify_page()
994 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_verify_page()
997 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1006 ret = i2c_master_send(ts->client, cmd, 6); in mip4_bl_verify_page()
1009 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1018 ret = i2c_master_send(ts->client, cmd, 3); in mip4_bl_verify_page()
1021 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1027 error = mip4_bl_read_status(ts); in mip4_bl_verify_page()
1039 dev_dbg(&ts->client->dev, in mip4_bl_verify_page()
1043 ret = i2c_transfer(ts->client->adapter, msg, ARRAY_SIZE(msg)); in mip4_bl_verify_page()
1046 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1053 dev_err(&ts->client->dev, in mip4_bl_verify_page()
1079 static int mip4_flash_fw(struct mip4_ts *ts, in mip4_flash_fw() argument
1082 struct i2c_client *client = ts->client; in mip4_flash_fw()
1090 error = mip4_bl_enter(ts); in mip4_flash_fw()
1099 error = mip4_bl_get_address(ts, &buf_addr); in mip4_flash_fw()
1112 error = mip4_bl_program_page(ts, offset, fw_data + offset, in mip4_flash_fw()
1118 error = mip4_bl_verify_page(ts, offset, fw_data + offset, in mip4_flash_fw()
1128 error2 = mip4_bl_exit(ts); in mip4_flash_fw()
1137 mip4_power_off(ts); in mip4_flash_fw()
1138 mip4_power_on(ts); in mip4_flash_fw()
1140 mip4_query_device(ts); in mip4_flash_fw()
1143 input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0); in mip4_flash_fw()
1144 input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0); in mip4_flash_fw()
1145 input_set_abs_params(ts->input, ABS_X, 0, ts->max_x, 0, 0); in mip4_flash_fw()
1146 input_set_abs_params(ts->input, ABS_Y, 0, ts->max_y, 0, 0); in mip4_flash_fw()
1147 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x); in mip4_flash_fw()
1148 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y); in mip4_flash_fw()
1149 input_abs_set_res(ts->input, ABS_X, ts->ppm_x); in mip4_flash_fw()
1150 input_abs_set_res(ts->input, ABS_Y, ts->ppm_y); in mip4_flash_fw()
1155 static int mip4_parse_firmware(struct mip4_ts *ts, const struct firmware *fw, in mip4_parse_firmware() argument
1164 dev_err(&ts->client->dev, in mip4_parse_firmware()
1179 dev_err(&ts->client->dev, in mip4_parse_firmware()
1188 dev_err(&ts->client->dev, in mip4_parse_firmware()
1198 dev_dbg(&ts->client->dev, in mip4_parse_firmware()
1203 dev_err(&ts->client->dev, in mip4_parse_firmware()
1210 dev_err(&ts->client->dev, in mip4_parse_firmware()
1218 dev_dbg(&ts->client->dev, in mip4_parse_firmware()
1223 dev_dbg(&ts->client->dev, "F/W chip version: %04X %04X %04X %04X\n", in mip4_parse_firmware()
1224 ts->fw_version.boot, ts->fw_version.core, in mip4_parse_firmware()
1225 ts->fw_version.app, ts->fw_version.param); in mip4_parse_firmware()
1232 dev_dbg(&ts->client->dev, "F/W type: Bootloader\n"); in mip4_parse_firmware()
1237 dev_dbg(&ts->client->dev, "F/W type: Main\n"); in mip4_parse_firmware()
1239 dev_err(&ts->client->dev, "Wrong firmware type\n"); in mip4_parse_firmware()
1246 static int mip4_execute_fw_update(struct mip4_ts *ts, const struct firmware *fw) in mip4_execute_fw_update() argument
1254 error = mip4_parse_firmware(ts, fw, in mip4_execute_fw_update()
1259 if (input_device_enabled(ts->input)) { in mip4_execute_fw_update()
1260 disable_irq(ts->client->irq); in mip4_execute_fw_update()
1262 error = mip4_power_on(ts); in mip4_execute_fw_update()
1269 error = mip4_flash_fw(ts, fw->data, fw_size, fw_start_offset); in mip4_execute_fw_update()
1275 dev_err(&ts->client->dev, in mip4_execute_fw_update()
1279 if (input_device_enabled(ts->input)) in mip4_execute_fw_update()
1280 enable_irq(ts->client->irq); in mip4_execute_fw_update()
1282 mip4_power_off(ts); in mip4_execute_fw_update()
1292 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_fw_update() local
1296 error = request_firmware(&fw, ts->fw_name, dev); in mip4_sysfs_fw_update()
1298 dev_err(&ts->client->dev, in mip4_sysfs_fw_update()
1300 ts->fw_name, error); in mip4_sysfs_fw_update()
1309 mutex_lock(&ts->input->mutex); in mip4_sysfs_fw_update()
1311 error = mip4_execute_fw_update(ts, fw); in mip4_sysfs_fw_update()
1313 mutex_unlock(&ts->input->mutex); in mip4_sysfs_fw_update()
1318 dev_err(&ts->client->dev, in mip4_sysfs_fw_update()
1333 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_fw_version() local
1337 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_fw_version()
1340 ts->fw_version.boot, ts->fw_version.core, in mip4_sysfs_read_fw_version()
1341 ts->fw_version.app, ts->fw_version.param); in mip4_sysfs_read_fw_version()
1343 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_fw_version()
1355 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_hw_version() local
1359 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_hw_version()
1366 (int)sizeof(ts->product_name), ts->product_name); in mip4_sysfs_read_hw_version()
1368 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_hw_version()
1380 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_product_id() local
1383 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_product_id()
1385 count = snprintf(buf, PAGE_SIZE, "%04X\n", ts->product_id); in mip4_sysfs_read_product_id()
1387 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_product_id()
1399 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_sysfs_read_ic_name() local
1402 mutex_lock(&ts->input->mutex); in mip4_sysfs_read_ic_name()
1405 (int)sizeof(ts->ic_name), ts->ic_name); in mip4_sysfs_read_ic_name()
1407 mutex_unlock(&ts->input->mutex); in mip4_sysfs_read_ic_name()
1429 struct mip4_ts *ts; in mip4_probe() local
1438 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in mip4_probe()
1439 if (!ts) in mip4_probe()
1446 ts->client = client; in mip4_probe()
1447 ts->input = input; in mip4_probe()
1449 snprintf(ts->phys, sizeof(ts->phys), in mip4_probe()
1452 ts->gpio_ce = devm_gpiod_get_optional(&client->dev, in mip4_probe()
1454 if (IS_ERR(ts->gpio_ce)) in mip4_probe()
1455 return dev_err_probe(&client->dev, PTR_ERR(ts->gpio_ce), "Failed to get gpio\n"); in mip4_probe()
1457 error = mip4_power_on(ts); in mip4_probe()
1460 error = mip4_query_device(ts); in mip4_probe()
1461 mip4_power_off(ts); in mip4_probe()
1466 input->phys = ts->phys; in mip4_probe()
1470 input->id.product = ts->product_id; in mip4_probe()
1475 input_set_drvdata(input, ts); in mip4_probe()
1477 input->keycode = ts->key_code; in mip4_probe()
1478 input->keycodesize = sizeof(*ts->key_code); in mip4_probe()
1479 input->keycodemax = ts->key_num; in mip4_probe()
1482 input_set_abs_params(input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0); in mip4_probe()
1483 input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0); in mip4_probe()
1490 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x); in mip4_probe()
1491 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y); in mip4_probe()
1497 i2c_set_clientdata(client, ts); in mip4_probe()
1502 MIP4_DEVICE_NAME, ts); in mip4_probe()
1530 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_suspend() local
1531 struct input_dev *input = ts->input; in mip4_suspend()
1536 ts->wake_irq_enabled = enable_irq_wake(client->irq) == 0; in mip4_suspend()
1538 mip4_disable(ts); in mip4_suspend()
1548 struct mip4_ts *ts = i2c_get_clientdata(client); in mip4_resume() local
1549 struct input_dev *input = ts->input; in mip4_resume()
1553 if (ts->wake_irq_enabled) in mip4_resume()
1556 mip4_enable(ts); in mip4_resume()