Lines Matching +full:touchscreen +full:- +full:x +full:- +full:mm

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Raydium touchscreen I2C driver.
5 * Copyright (C) 2012-2014, Raydium Semiconductor Corporation.
11 * Contact Raydium Semiconductor Corporation at www.rad-ic.com
111 u8 x_res; /* units/mm */
112 u8 y_res; /* units/mm */
115 /* struct raydium_data - represents state of Raydium touchscreen device */
158 xfer_count -= xfer_start_idx; in raydium_i2c_xfer()
160 ret = i2c_transfer(client->adapter, &xfer[xfer_start_idx], xfer_count); in raydium_i2c_xfer()
164 return ret < 0 ? ret : -EIO; in raydium_i2c_xfer()
177 return -ENOMEM; in raydium_i2c_send()
200 .addr = client->addr, in raydium_i2c_send()
205 .addr = client->addr, in raydium_i2c_send()
218 dev_err(&client->dev, "%s failed: %d\n", __func__, error); in raydium_i2c_send()
247 .addr = client->addr, in raydium_i2c_read()
252 .addr = client->addr, in raydium_i2c_read()
257 .addr = client->addr, in raydium_i2c_read()
268 len -= xfer_len; in raydium_i2c_read()
284 dev_err(&client->dev, "software reset failed: %d\n", error); in raydium_i2c_sw_reset()
295 struct i2c_client *client = ts->client; in raydium_i2c_query_ts_info()
312 if (ts->report_data && ts->pkg_size != data_info.pkg_size) { in raydium_i2c_query_ts_info()
313 dev_warn(&client->dev, in raydium_i2c_query_ts_info()
315 ts->pkg_size, data_info.pkg_size); in raydium_i2c_query_ts_info()
317 ts->pkg_size = data_info.pkg_size; in raydium_i2c_query_ts_info()
318 ts->report_size = ts->pkg_size - RM_PACKET_CRC_SIZE; in raydium_i2c_query_ts_info()
321 ts->contact_size = data_info.tp_info_size; in raydium_i2c_query_ts_info()
322 ts->data_bank_addr = le32_to_cpu(data_info.data_bank_addr); in raydium_i2c_query_ts_info()
324 dev_dbg(&client->dev, in raydium_i2c_query_ts_info()
325 "data_bank_addr: %#08x, report_size: %d, contact_size: %d\n", in raydium_i2c_query_ts_info()
326 ts->data_bank_addr, ts->report_size, ts->contact_size); in raydium_i2c_query_ts_info()
335 &ts->info, sizeof(ts->info)); in raydium_i2c_query_ts_info()
342 dev_err(&client->dev, "failed to query device parameters: %d\n", error); in raydium_i2c_query_ts_info()
348 struct i2c_client *client = ts->client; in raydium_i2c_check_fw_status()
357 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_check_fw_status()
359 ts->boot_mode = RAYDIUM_TS_MAIN; in raydium_i2c_check_fw_status()
368 struct i2c_client *client = ts->client; in raydium_i2c_initialize()
377 dev_err(&client->dev, in raydium_i2c_initialize()
382 if (ts->boot_mode == RAYDIUM_TS_BLDR || in raydium_i2c_initialize()
383 ts->boot_mode == RAYDIUM_TS_MAIN) { in raydium_i2c_initialize()
389 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_initialize()
391 if (ts->boot_mode == RAYDIUM_TS_BLDR) { in raydium_i2c_initialize()
392 ts->info.hw_ver = cpu_to_le32(0xffffffffUL); in raydium_i2c_initialize()
393 ts->info.main_ver = 0xff; in raydium_i2c_initialize()
394 ts->info.sub_ver = 0xff; in raydium_i2c_initialize()
432 dev_err(&client->dev, "%s: invalid target state %d\n", in raydium_i2c_bl_chk_state()
434 return -EINVAL; in raydium_i2c_bl_chk_state()
440 return -ETIMEDOUT; in raydium_i2c_bl_chk_state()
451 dev_err(&client->dev, "WRT obj command failed: %d\n", in raydium_i2c_write_object()
458 dev_err(&client->dev, "Ack obj command failed: %d\n", error); in raydium_i2c_write_object()
464 dev_err(&client->dev, "BL check state failed: %d\n", error); in raydium_i2c_write_object()
488 dev_err(&client->dev, in raydium_i2c_boot_trigger()
514 dev_err(&client->dev, in raydium_i2c_fw_trigger()
532 dev_err(&client->dev, "check path command failed: %d\n", error); in raydium_i2c_check_path()
547 dev_err(&client->dev, "enter bl command failed: %d\n", error); in raydium_i2c_enter_bl()
563 dev_err(&client->dev, "leave bl command failed: %d\n", error); in raydium_i2c_leave_bl()
584 dev_err(&client->dev, "failed to write checksum: %d\n", in raydium_i2c_write_checksum()
600 dev_err(&client->dev, "disable watchdog command failed: %d\n", in raydium_i2c_disable_watch_dog()
627 RM_BL_WRT_PKG_SIZE - xfer_len); in raydium_i2c_fw_write_page()
632 dev_err(&client->dev, in raydium_i2c_fw_write_page()
639 len -= xfer_len; in raydium_i2c_fw_write_page()
659 struct i2c_client *client = ts->client; in raydium_i2c_do_update_firmware()
668 if (fw->size == 0 || fw->size > RM_MAX_FW_SIZE) { in raydium_i2c_do_update_firmware()
669 dev_err(&client->dev, "Invalid firmware length\n"); in raydium_i2c_do_update_firmware()
670 return -EINVAL; in raydium_i2c_do_update_firmware()
675 dev_err(&client->dev, "Unable to access IC %d\n", error); in raydium_i2c_do_update_firmware()
679 if (ts->boot_mode == RAYDIUM_TS_MAIN) { in raydium_i2c_do_update_firmware()
685 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
691 if (ts->boot_mode == RAYDIUM_TS_BLDR) in raydium_i2c_do_update_firmware()
696 if (ts->boot_mode == RAYDIUM_TS_MAIN) { in raydium_i2c_do_update_firmware()
697 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
700 return -EIO; in raydium_i2c_do_update_firmware()
714 dev_err(&client->dev, "send boot trigger fail: %d\n", error); in raydium_i2c_do_update_firmware()
720 data = fw->data; in raydium_i2c_do_update_firmware()
721 data_len = fw->size; in raydium_i2c_do_update_firmware()
734 data_len -= len; in raydium_i2c_do_update_firmware()
739 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
744 dev_dbg(&client->dev, "left boot loader mode\n"); in raydium_i2c_do_update_firmware()
749 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
755 if (ts->boot_mode != RAYDIUM_TS_MAIN) { in raydium_i2c_do_update_firmware()
756 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
759 return -EINVAL; in raydium_i2c_do_update_firmware()
764 dev_err(&client->dev, "failed to trigger fw: %d\n", error); in raydium_i2c_do_update_firmware()
768 fw_checksum = raydium_calc_chksum(fw->data, fw->size); in raydium_i2c_do_update_firmware()
770 error = raydium_i2c_write_checksum(client, fw->size, fw_checksum); in raydium_i2c_do_update_firmware()
779 struct i2c_client *client = ts->client; in raydium_i2c_fw_update()
784 fw_file = kasprintf(GFP_KERNEL, "raydium_%#04x.fw", in raydium_i2c_fw_update()
785 le32_to_cpu(ts->info.hw_ver)); in raydium_i2c_fw_update()
787 return -ENOMEM; in raydium_i2c_fw_update()
789 dev_dbg(&client->dev, "firmware name: %s\n", fw_file); in raydium_i2c_fw_update()
791 error = request_firmware(&fw, fw_file, &client->dev); in raydium_i2c_fw_update()
793 dev_err(&client->dev, "Unable to open firmware %s\n", fw_file); in raydium_i2c_fw_update()
797 disable_irq(client->irq); in raydium_i2c_fw_update()
801 dev_err(&client->dev, "firmware update failed: %d\n", error); in raydium_i2c_fw_update()
802 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_fw_update()
808 dev_err(&client->dev, in raydium_i2c_fw_update()
811 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_fw_update()
815 ts->boot_mode = RAYDIUM_TS_MAIN; in raydium_i2c_fw_update()
818 enable_irq(client->irq); in raydium_i2c_fw_update()
833 for (i = 0; i < ts->report_size / ts->contact_size; i++) { in raydium_mt_event()
834 u8 *contact = &ts->report_data[ts->contact_size * i]; in raydium_mt_event()
838 input_mt_slot(ts->input, i); in raydium_mt_event()
839 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, state); in raydium_mt_event()
844 input_report_abs(ts->input, ABS_MT_POSITION_X, in raydium_mt_event()
846 input_report_abs(ts->input, ABS_MT_POSITION_Y, in raydium_mt_event()
848 input_report_abs(ts->input, ABS_MT_PRESSURE, in raydium_mt_event()
854 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, max(wx, wy)); in raydium_mt_event()
855 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR, min(wx, wy)); in raydium_mt_event()
858 input_mt_sync_frame(ts->input); in raydium_mt_event()
859 input_sync(ts->input); in raydium_mt_event()
869 if (ts->boot_mode != RAYDIUM_TS_MAIN) in raydium_i2c_irq()
872 error = raydium_i2c_read(ts->client, ts->data_bank_addr, in raydium_i2c_irq()
873 ts->report_data, ts->pkg_size); in raydium_i2c_irq()
877 fw_crc = get_unaligned_le16(&ts->report_data[ts->report_size]); in raydium_i2c_irq()
878 calc_crc = raydium_calc_chksum(ts->report_data, ts->report_size); in raydium_i2c_irq()
880 dev_warn(&ts->client->dev, in raydium_i2c_irq()
881 "%s: invalid packet crc %#04x vs %#04x\n", in raydium_i2c_irq()
898 return sprintf(buf, "%d.%d\n", ts->info.main_ver, ts->info.sub_ver); in raydium_i2c_fw_ver_show()
907 return sprintf(buf, "%#04x\n", le32_to_cpu(ts->info.hw_ver)); in raydium_i2c_hw_ver_show()
918 ts->boot_mode == RAYDIUM_TS_MAIN ? in raydium_i2c_boot_mode_show()
930 error = mutex_lock_interruptible(&ts->sysfs_mutex); in raydium_i2c_update_fw_store()
936 mutex_unlock(&ts->sysfs_mutex); in raydium_i2c_update_fw_store()
950 error = mutex_lock_interruptible(&ts->sysfs_mutex); in raydium_i2c_calibrate_store()
957 dev_err(&client->dev, "calibrate command failed: %d\n", error); in raydium_i2c_calibrate_store()
959 mutex_unlock(&ts->sysfs_mutex); in raydium_i2c_calibrate_store()
986 if (!ts->reset_gpio) in raydium_i2c_power_on()
989 gpiod_set_value_cansleep(ts->reset_gpio, 1); in raydium_i2c_power_on()
991 error = regulator_enable(ts->avdd); in raydium_i2c_power_on()
993 dev_err(&ts->client->dev, in raydium_i2c_power_on()
998 error = regulator_enable(ts->vccio); in raydium_i2c_power_on()
1000 regulator_disable(ts->avdd); in raydium_i2c_power_on()
1001 dev_err(&ts->client->dev, in raydium_i2c_power_on()
1009 gpiod_set_value_cansleep(ts->reset_gpio, 0); in raydium_i2c_power_on()
1023 if (ts->reset_gpio) { in raydium_i2c_power_off()
1024 gpiod_set_value_cansleep(ts->reset_gpio, 1); in raydium_i2c_power_off()
1025 regulator_disable(ts->vccio); in raydium_i2c_power_off()
1026 regulator_disable(ts->avdd); in raydium_i2c_power_off()
1037 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in raydium_i2c_probe()
1038 dev_err(&client->dev, in raydium_i2c_probe()
1040 return -ENXIO; in raydium_i2c_probe()
1043 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in raydium_i2c_probe()
1045 return -ENOMEM; in raydium_i2c_probe()
1047 mutex_init(&ts->sysfs_mutex); in raydium_i2c_probe()
1049 ts->client = client; in raydium_i2c_probe()
1052 ts->avdd = devm_regulator_get(&client->dev, "avdd"); in raydium_i2c_probe()
1053 if (IS_ERR(ts->avdd)) { in raydium_i2c_probe()
1054 error = PTR_ERR(ts->avdd); in raydium_i2c_probe()
1055 if (error != -EPROBE_DEFER) in raydium_i2c_probe()
1056 dev_err(&client->dev, in raydium_i2c_probe()
1061 ts->vccio = devm_regulator_get(&client->dev, "vccio"); in raydium_i2c_probe()
1062 if (IS_ERR(ts->vccio)) { in raydium_i2c_probe()
1063 error = PTR_ERR(ts->vccio); in raydium_i2c_probe()
1064 if (error != -EPROBE_DEFER) in raydium_i2c_probe()
1065 dev_err(&client->dev, in raydium_i2c_probe()
1070 ts->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", in raydium_i2c_probe()
1072 if (IS_ERR(ts->reset_gpio)) { in raydium_i2c_probe()
1073 error = PTR_ERR(ts->reset_gpio); in raydium_i2c_probe()
1074 if (error != -EPROBE_DEFER) in raydium_i2c_probe()
1075 dev_err(&client->dev, in raydium_i2c_probe()
1084 error = devm_add_action(&client->dev, raydium_i2c_power_off, ts); in raydium_i2c_probe()
1086 dev_err(&client->dev, in raydium_i2c_probe()
1093 if (i2c_smbus_xfer(client->adapter, client->addr, 0, in raydium_i2c_probe()
1095 dev_err(&client->dev, "nothing at this address\n"); in raydium_i2c_probe()
1096 return -ENXIO; in raydium_i2c_probe()
1101 dev_err(&client->dev, "failed to initialize: %d\n", error); in raydium_i2c_probe()
1105 ts->report_data = devm_kmalloc(&client->dev, in raydium_i2c_probe()
1106 ts->pkg_size, GFP_KERNEL); in raydium_i2c_probe()
1107 if (!ts->report_data) in raydium_i2c_probe()
1108 return -ENOMEM; in raydium_i2c_probe()
1110 ts->input = devm_input_allocate_device(&client->dev); in raydium_i2c_probe()
1111 if (!ts->input) { in raydium_i2c_probe()
1112 dev_err(&client->dev, "Failed to allocate input device\n"); in raydium_i2c_probe()
1113 return -ENOMEM; in raydium_i2c_probe()
1116 ts->input->name = "Raydium Touchscreen"; in raydium_i2c_probe()
1117 ts->input->id.bustype = BUS_I2C; in raydium_i2c_probe()
1119 input_set_abs_params(ts->input, ABS_MT_POSITION_X, in raydium_i2c_probe()
1120 0, le16_to_cpu(ts->info.x_max), 0, 0); in raydium_i2c_probe()
1121 input_set_abs_params(ts->input, ABS_MT_POSITION_Y, in raydium_i2c_probe()
1122 0, le16_to_cpu(ts->info.y_max), 0, 0); in raydium_i2c_probe()
1123 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->info.x_res); in raydium_i2c_probe()
1124 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->info.y_res); in raydium_i2c_probe()
1126 input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); in raydium_i2c_probe()
1127 input_set_abs_params(ts->input, ABS_MT_PRESSURE, 0, 255, 0, 0); in raydium_i2c_probe()
1129 error = input_mt_init_slots(ts->input, RM_MAX_TOUCH_NUM, in raydium_i2c_probe()
1132 dev_err(&client->dev, in raydium_i2c_probe()
1137 error = input_register_device(ts->input); in raydium_i2c_probe()
1139 dev_err(&client->dev, in raydium_i2c_probe()
1144 error = devm_request_threaded_irq(&client->dev, client->irq, in raydium_i2c_probe()
1146 IRQF_ONESHOT, client->name, ts); in raydium_i2c_probe()
1148 dev_err(&client->dev, "Failed to register interrupt\n"); in raydium_i2c_probe()
1152 error = devm_device_add_group(&client->dev, in raydium_i2c_probe()
1155 dev_err(&client->dev, "failed to create sysfs attributes: %d\n", in raydium_i2c_probe()
1171 dev_err(&client->dev, in raydium_enter_sleep()
1181 if (ts->boot_mode != RAYDIUM_TS_MAIN) in raydium_i2c_suspend()
1182 return -EBUSY; in raydium_i2c_suspend()
1184 disable_irq(client->irq); in raydium_i2c_suspend()
1189 ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0); in raydium_i2c_suspend()
1203 if (ts->wake_irq_enabled) in raydium_i2c_resume()
1204 disable_irq_wake(client->irq); in raydium_i2c_resume()
1211 enable_irq(client->irq); in raydium_i2c_resume()
1255 MODULE_DESCRIPTION("Raydium I2c Touchscreen driver");