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
113 u8 x_res; /* units/mm */
114 u8 y_res; /* units/mm */
117 /* 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()
249 .addr = client->addr, in raydium_i2c_read()
254 .addr = client->addr, in raydium_i2c_read()
259 .addr = client->addr, in raydium_i2c_read()
270 len -= xfer_len; in raydium_i2c_read()
286 dev_err(&client->dev, "software reset failed: %d\n", error); in raydium_i2c_sw_reset()
297 struct i2c_client *client = ts->client; in raydium_i2c_query_ts_bootloader_info()
307 dev_err(&client->dev, "WRT HWID command failed: %d\n", error); in raydium_i2c_query_ts_bootloader_info()
313 dev_err(&client->dev, "Ack HWID command failed: %d\n", error); in raydium_i2c_query_ts_bootloader_info()
319 dev_err(&client->dev, "Read HWID command failed: %d (%4ph)\n", in raydium_i2c_query_ts_bootloader_info()
326 ts->info.hw_ver = cpu_to_le32(hw_ver); in raydium_i2c_query_ts_bootloader_info()
327 ts->info.main_ver = 0xff; in raydium_i2c_query_ts_bootloader_info()
328 ts->info.sub_ver = 0xff; in raydium_i2c_query_ts_bootloader_info()
335 struct i2c_client *client = ts->client; in raydium_i2c_query_ts_info()
352 if (ts->report_data && ts->pkg_size != data_info.pkg_size) { in raydium_i2c_query_ts_info()
353 dev_warn(&client->dev, in raydium_i2c_query_ts_info()
355 ts->pkg_size, data_info.pkg_size); in raydium_i2c_query_ts_info()
357 ts->pkg_size = data_info.pkg_size; in raydium_i2c_query_ts_info()
358 ts->report_size = ts->pkg_size - RM_PACKET_CRC_SIZE; in raydium_i2c_query_ts_info()
361 ts->contact_size = data_info.tp_info_size; in raydium_i2c_query_ts_info()
362 ts->data_bank_addr = le32_to_cpu(data_info.data_bank_addr); in raydium_i2c_query_ts_info()
364 dev_dbg(&client->dev, in raydium_i2c_query_ts_info()
365 "data_bank_addr: %#08x, report_size: %d, contact_size: %d\n", in raydium_i2c_query_ts_info()
366 ts->data_bank_addr, ts->report_size, ts->contact_size); in raydium_i2c_query_ts_info()
375 &ts->info, sizeof(ts->info)); in raydium_i2c_query_ts_info()
382 dev_err(&client->dev, "failed to query device parameters: %d\n", error); in raydium_i2c_query_ts_info()
388 struct i2c_client *client = ts->client; in raydium_i2c_check_fw_status()
397 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_check_fw_status()
399 ts->boot_mode = RAYDIUM_TS_MAIN; in raydium_i2c_check_fw_status()
408 struct i2c_client *client = ts->client; in raydium_i2c_initialize()
417 dev_err(&client->dev, in raydium_i2c_initialize()
422 if (ts->boot_mode == RAYDIUM_TS_BLDR || in raydium_i2c_initialize()
423 ts->boot_mode == RAYDIUM_TS_MAIN) { in raydium_i2c_initialize()
429 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_initialize()
431 if (ts->boot_mode == RAYDIUM_TS_BLDR) in raydium_i2c_initialize()
469 dev_err(&client->dev, "%s: invalid target state %d\n", in raydium_i2c_bl_chk_state()
471 return -EINVAL; in raydium_i2c_bl_chk_state()
477 return -ETIMEDOUT; in raydium_i2c_bl_chk_state()
489 dev_err(&client->dev, "WRT obj command failed: %d\n", in raydium_i2c_write_object()
496 dev_err(&client->dev, "Ack obj command failed: %d\n", error); in raydium_i2c_write_object()
502 dev_err(&client->dev, "BL check state failed: %d\n", error); in raydium_i2c_write_object()
526 dev_err(&client->dev, in raydium_i2c_boot_trigger()
552 dev_err(&client->dev, in raydium_i2c_fw_trigger()
570 dev_err(&client->dev, "check path command failed: %d\n", error); in raydium_i2c_check_path()
585 dev_err(&client->dev, "enter bl command failed: %d\n", error); in raydium_i2c_enter_bl()
601 dev_err(&client->dev, "leave bl command failed: %d\n", error); in raydium_i2c_leave_bl()
622 dev_err(&client->dev, "failed to write checksum: %d\n", in raydium_i2c_write_checksum()
638 dev_err(&client->dev, "disable watchdog command failed: %d\n", in raydium_i2c_disable_watch_dog()
665 RM_BL_WRT_PKG_SIZE - xfer_len); in raydium_i2c_fw_write_page()
670 dev_err(&client->dev, in raydium_i2c_fw_write_page()
677 len -= xfer_len; in raydium_i2c_fw_write_page()
697 struct i2c_client *client = ts->client; in raydium_i2c_do_update_firmware()
706 if (fw->size == 0 || fw->size > RM_MAX_FW_SIZE) { in raydium_i2c_do_update_firmware()
707 dev_err(&client->dev, "Invalid firmware length\n"); in raydium_i2c_do_update_firmware()
708 return -EINVAL; in raydium_i2c_do_update_firmware()
713 dev_err(&client->dev, "Unable to access IC %d\n", error); in raydium_i2c_do_update_firmware()
717 if (ts->boot_mode == RAYDIUM_TS_MAIN) { in raydium_i2c_do_update_firmware()
723 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
729 if (ts->boot_mode == RAYDIUM_TS_BLDR) in raydium_i2c_do_update_firmware()
734 if (ts->boot_mode == RAYDIUM_TS_MAIN) { in raydium_i2c_do_update_firmware()
735 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
738 return -EIO; in raydium_i2c_do_update_firmware()
752 dev_err(&client->dev, "send boot trigger fail: %d\n", error); in raydium_i2c_do_update_firmware()
758 data = fw->data; in raydium_i2c_do_update_firmware()
759 data_len = fw->size; in raydium_i2c_do_update_firmware()
772 data_len -= len; in raydium_i2c_do_update_firmware()
777 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
782 dev_dbg(&client->dev, "left boot loader mode\n"); in raydium_i2c_do_update_firmware()
787 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
793 if (ts->boot_mode != RAYDIUM_TS_MAIN) { in raydium_i2c_do_update_firmware()
794 dev_err(&client->dev, in raydium_i2c_do_update_firmware()
797 return -EINVAL; in raydium_i2c_do_update_firmware()
802 dev_err(&client->dev, "failed to trigger fw: %d\n", error); in raydium_i2c_do_update_firmware()
806 fw_checksum = raydium_calc_chksum(fw->data, fw->size); in raydium_i2c_do_update_firmware()
808 error = raydium_i2c_write_checksum(client, fw->size, fw_checksum); in raydium_i2c_do_update_firmware()
817 struct i2c_client *client = ts->client; in raydium_i2c_fw_update()
822 fw_file = kasprintf(GFP_KERNEL, "raydium_%#04x.fw", in raydium_i2c_fw_update()
823 le32_to_cpu(ts->info.hw_ver)); in raydium_i2c_fw_update()
825 return -ENOMEM; in raydium_i2c_fw_update()
827 dev_dbg(&client->dev, "firmware name: %s\n", fw_file); in raydium_i2c_fw_update()
829 error = request_firmware(&fw, fw_file, &client->dev); in raydium_i2c_fw_update()
831 dev_err(&client->dev, "Unable to open firmware %s\n", fw_file); in raydium_i2c_fw_update()
835 disable_irq(client->irq); in raydium_i2c_fw_update()
839 dev_err(&client->dev, "firmware update failed: %d\n", error); in raydium_i2c_fw_update()
840 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_fw_update()
846 dev_err(&client->dev, in raydium_i2c_fw_update()
849 ts->boot_mode = RAYDIUM_TS_BLDR; in raydium_i2c_fw_update()
853 ts->boot_mode = RAYDIUM_TS_MAIN; in raydium_i2c_fw_update()
856 enable_irq(client->irq); in raydium_i2c_fw_update()
871 for (i = 0; i < ts->report_size / ts->contact_size; i++) { in raydium_mt_event()
872 u8 *contact = &ts->report_data[ts->contact_size * i]; in raydium_mt_event()
876 input_mt_slot(ts->input, i); in raydium_mt_event()
877 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, state); in raydium_mt_event()
882 input_report_abs(ts->input, ABS_MT_POSITION_X, in raydium_mt_event()
884 input_report_abs(ts->input, ABS_MT_POSITION_Y, in raydium_mt_event()
886 input_report_abs(ts->input, ABS_MT_PRESSURE, in raydium_mt_event()
892 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, max(wx, wy)); in raydium_mt_event()
893 input_report_abs(ts->input, ABS_MT_TOUCH_MINOR, min(wx, wy)); in raydium_mt_event()
896 input_mt_sync_frame(ts->input); in raydium_mt_event()
897 input_sync(ts->input); in raydium_mt_event()
907 if (ts->boot_mode != RAYDIUM_TS_MAIN) in raydium_i2c_irq()
910 error = raydium_i2c_read(ts->client, ts->data_bank_addr, in raydium_i2c_irq()
911 ts->report_data, ts->pkg_size); in raydium_i2c_irq()
915 fw_crc = get_unaligned_le16(&ts->report_data[ts->report_size]); in raydium_i2c_irq()
916 calc_crc = raydium_calc_chksum(ts->report_data, ts->report_size); in raydium_i2c_irq()
918 dev_warn(&ts->client->dev, in raydium_i2c_irq()
919 "%s: invalid packet crc %#04x vs %#04x\n", in raydium_i2c_irq()
936 return sprintf(buf, "%d.%d\n", ts->info.main_ver, ts->info.sub_ver); in raydium_i2c_fw_ver_show()
945 return sprintf(buf, "%#04x\n", le32_to_cpu(ts->info.hw_ver)); in raydium_i2c_hw_ver_show()
956 ts->boot_mode == RAYDIUM_TS_MAIN ? in raydium_i2c_boot_mode_show()
968 error = mutex_lock_interruptible(&ts->sysfs_mutex); in raydium_i2c_update_fw_store()
974 mutex_unlock(&ts->sysfs_mutex); in raydium_i2c_update_fw_store()
988 error = mutex_lock_interruptible(&ts->sysfs_mutex); in raydium_i2c_calibrate_store()
995 dev_err(&client->dev, "calibrate command failed: %d\n", error); in raydium_i2c_calibrate_store()
997 mutex_unlock(&ts->sysfs_mutex); in raydium_i2c_calibrate_store()
1021 if (!ts->reset_gpio) in raydium_i2c_power_on()
1024 gpiod_set_value_cansleep(ts->reset_gpio, 1); in raydium_i2c_power_on()
1026 error = regulator_enable(ts->avdd); in raydium_i2c_power_on()
1028 dev_err(&ts->client->dev, in raydium_i2c_power_on()
1033 error = regulator_enable(ts->vccio); in raydium_i2c_power_on()
1035 regulator_disable(ts->avdd); in raydium_i2c_power_on()
1036 dev_err(&ts->client->dev, in raydium_i2c_power_on()
1044 gpiod_set_value_cansleep(ts->reset_gpio, 0); in raydium_i2c_power_on()
1058 if (ts->reset_gpio) { in raydium_i2c_power_off()
1059 gpiod_set_value_cansleep(ts->reset_gpio, 1); in raydium_i2c_power_off()
1060 regulator_disable(ts->vccio); in raydium_i2c_power_off()
1061 regulator_disable(ts->avdd); in raydium_i2c_power_off()
1071 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in raydium_i2c_probe()
1072 dev_err(&client->dev, in raydium_i2c_probe()
1074 return -ENXIO; in raydium_i2c_probe()
1077 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in raydium_i2c_probe()
1079 return -ENOMEM; in raydium_i2c_probe()
1081 mutex_init(&ts->sysfs_mutex); in raydium_i2c_probe()
1083 ts->client = client; in raydium_i2c_probe()
1086 ts->avdd = devm_regulator_get(&client->dev, "avdd"); in raydium_i2c_probe()
1087 if (IS_ERR(ts->avdd)) in raydium_i2c_probe()
1088 return dev_err_probe(&client->dev, PTR_ERR(ts->avdd), in raydium_i2c_probe()
1091 ts->vccio = devm_regulator_get(&client->dev, "vccio"); in raydium_i2c_probe()
1092 if (IS_ERR(ts->vccio)) in raydium_i2c_probe()
1093 return dev_err_probe(&client->dev, PTR_ERR(ts->vccio), in raydium_i2c_probe()
1096 ts->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", in raydium_i2c_probe()
1098 if (IS_ERR(ts->reset_gpio)) in raydium_i2c_probe()
1099 return dev_err_probe(&client->dev, PTR_ERR(ts->reset_gpio), in raydium_i2c_probe()
1106 error = devm_add_action_or_reset(&client->dev, in raydium_i2c_probe()
1109 dev_err(&client->dev, in raydium_i2c_probe()
1115 if (i2c_smbus_xfer(client->adapter, client->addr, 0, in raydium_i2c_probe()
1117 dev_err(&client->dev, "nothing at this address\n"); in raydium_i2c_probe()
1118 return -ENXIO; in raydium_i2c_probe()
1123 dev_err(&client->dev, "failed to initialize: %d\n", error); in raydium_i2c_probe()
1127 ts->report_data = devm_kmalloc(&client->dev, in raydium_i2c_probe()
1128 ts->pkg_size, GFP_KERNEL); in raydium_i2c_probe()
1129 if (!ts->report_data) in raydium_i2c_probe()
1130 return -ENOMEM; in raydium_i2c_probe()
1132 ts->input = devm_input_allocate_device(&client->dev); in raydium_i2c_probe()
1133 if (!ts->input) { in raydium_i2c_probe()
1134 dev_err(&client->dev, "Failed to allocate input device\n"); in raydium_i2c_probe()
1135 return -ENOMEM; in raydium_i2c_probe()
1138 ts->input->name = "Raydium Touchscreen"; in raydium_i2c_probe()
1139 ts->input->id.bustype = BUS_I2C; in raydium_i2c_probe()
1141 input_set_abs_params(ts->input, ABS_MT_POSITION_X, in raydium_i2c_probe()
1142 0, le16_to_cpu(ts->info.x_max), 0, 0); in raydium_i2c_probe()
1143 input_set_abs_params(ts->input, ABS_MT_POSITION_Y, in raydium_i2c_probe()
1144 0, le16_to_cpu(ts->info.y_max), 0, 0); in raydium_i2c_probe()
1145 input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->info.x_res); in raydium_i2c_probe()
1146 input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->info.y_res); in raydium_i2c_probe()
1148 input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); in raydium_i2c_probe()
1149 input_set_abs_params(ts->input, ABS_MT_PRESSURE, 0, 255, 0, 0); in raydium_i2c_probe()
1151 error = input_mt_init_slots(ts->input, RM_MAX_TOUCH_NUM, in raydium_i2c_probe()
1154 dev_err(&client->dev, in raydium_i2c_probe()
1159 error = input_register_device(ts->input); in raydium_i2c_probe()
1161 dev_err(&client->dev, in raydium_i2c_probe()
1166 error = devm_request_threaded_irq(&client->dev, client->irq, in raydium_i2c_probe()
1168 IRQF_ONESHOT, client->name, ts); in raydium_i2c_probe()
1170 dev_err(&client->dev, "Failed to register interrupt\n"); in raydium_i2c_probe()
1185 dev_err(&client->dev, in raydium_enter_sleep()
1195 if (ts->boot_mode != RAYDIUM_TS_MAIN) in raydium_i2c_suspend()
1196 return -EBUSY; in raydium_i2c_suspend()
1198 disable_irq(client->irq); in raydium_i2c_suspend()
1221 enable_irq(client->irq); in raydium_i2c_resume()
1266 MODULE_DESCRIPTION("Raydium I2c Touchscreen driver");