Lines Matching +full:client +full:- +full:id
194 struct i2c_client *client; member
235 struct device_node *np = gsl_client->dev.of_node; in gsl3673_init()
239 this_ts->irq = of_get_named_gpio_flags(np, "irq_gpio_number", 0, in gsl3673_init()
241 if (!gpio_is_valid(this_ts->irq)) { in gsl3673_init()
242 dev_err(&this_ts->client->dev, "irq pin invalid\n"); in gsl3673_init()
243 return -EINVAL; in gsl3673_init()
246 this_ts->rst = of_get_named_gpio_flags(np, "rst_gpio_number", 0, in gsl3673_init()
248 if (!gpio_is_valid(this_ts->rst)) { in gsl3673_init()
249 dev_err(&this_ts->client->dev, "rst pin invalid\n"); in gsl3673_init()
250 return -EINVAL; in gsl3673_init()
253 if (devm_gpio_request(&this_ts->client->dev, this_ts->rst, NULL) != 0) { in gsl3673_init()
254 dev_err(&this_ts->client->dev, "gpio_request this_ts->rst error\n"); in gsl3673_init()
255 return -EIO; in gsl3673_init()
257 gpio_direction_output(this_ts->rst, 0); in gsl3673_init()
258 gpio_set_value(this_ts->rst, 1); in gsl3673_init()
264 if (this_ts->rst > 1) in gsl3673_shutdown_low()
265 gpio_set_value(this_ts->rst, 0); in gsl3673_shutdown_low()
271 if (this_ts->rst > 1) in gsl3673_shutdown_high()
272 gpio_set_value(this_ts->rst, 1); in gsl3673_shutdown_high()
285 static u32 gsl_write_interface(struct i2c_client *client, const u8 reg, in gsl_write_interface() argument
291 xfer_msg[0].addr = client->addr; in gsl_write_interface()
293 xfer_msg[0].flags = client->flags & I2C_M_TEN; in gsl_write_interface()
296 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT; in gsl_write_interface()
299 static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata, in gsl_ts_write() argument
308 return -1; in gsl_ts_write()
316 ret = i2c_master_send(client, tmp_buf, bytelen); in gsl_ts_write()
320 static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata, in gsl_ts_read() argument
327 return -1; in gsl_ts_read()
329 ret = gsl_ts_write(client, addr, NULL, 0); in gsl_ts_read()
334 return i2c_master_recv(client, pdata, datalen); in gsl_ts_read()
338 static void judge_chip_type(struct i2c_client *client) in judge_chip_type() argument
343 gsl_ts_read(client, 0xfc, read_buf, sizeof(read_buf)); in judge_chip_type()
346 gsl_ts_read(client, 0xfc, read_buf, sizeof(read_buf)); in judge_chip_type()
360 static void gsl_load_fw(struct i2c_client *client) in gsl_load_fw() argument
384 gsl_write_interface(client, GSL_PAGE_REG, buf, 4); in gsl_load_fw()
392 gsl_write_interface(client, buf[0], buf, cur - buf - 1); in gsl_load_fw()
400 static int test_i2c(struct i2c_client *client) in test_i2c() argument
406 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf)); in test_i2c()
408 rc--; in test_i2c()
410 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf)); in test_i2c()
412 rc--; in test_i2c()
414 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf)); in test_i2c()
416 rc--; in test_i2c()
420 static void startup_chip(struct i2c_client *client) in startup_chip() argument
427 gsl_ts_write(client, 0xe0, &tmp, 1); in startup_chip()
431 static void reset_chip(struct i2c_client *client) in reset_chip() argument
436 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp)); in reset_chip()
439 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp)); in reset_chip()
441 gsl_ts_write(client, 0xbc, buf, sizeof(buf)); in reset_chip()
445 static void clr_reg(struct i2c_client *client) in clr_reg() argument
450 gsl_ts_write(client, 0xe0, &write_buf[0], 1); in clr_reg()
453 gsl_ts_write(client, 0x80, &write_buf[0], 1); in clr_reg()
456 gsl_ts_write(client, 0xe4, &write_buf[0], 1); in clr_reg()
459 gsl_ts_write(client, 0xe0, &write_buf[0], 1); in clr_reg()
463 static int init_chip(struct i2c_client *client) in init_chip() argument
466 struct gsl_ts *ts = i2c_get_clientdata(client); in init_chip()
472 rc = test_i2c(client); in init_chip()
474 dev_err(&client->dev, "GSL3673 test_i2c error!\n"); in init_chip()
477 schedule_work(&ts->download_fw_work); in init_chip()
481 static int check_mem_data(struct i2c_client *client) in check_mem_data() argument
487 gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf)); in check_mem_data()
492 rc = init_chip(client); in check_mem_data()
503 return (ch - '0'); in char_to_int()
505 return (ch - 'a' + 10); in char_to_int()
554 return -EFAULT; in gsl_config_write_proc()
559 return -EFAULT; in gsl_config_write_proc()
619 static void filter_point(u16 x, u16 y, u8 id) in filter_point() argument
625 id_sign[id] = id_sign[id] + 1; in filter_point()
626 if (id_sign[id] == 1) { in filter_point()
627 x_old[id] = x; in filter_point()
628 y_old[id] = y; in filter_point()
630 x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x); in filter_point()
631 y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y); in filter_point()
652 x_new = x > x_old[id] ? (x_old[id] + filter_step_x) in filter_point()
653 : (x_old[id] - filter_step_x); in filter_point()
654 y_new = y > y_old[id] ? (y_old[id] + filter_step_y) in filter_point()
655 : (y_old[id] - filter_step_y); in filter_point()
656 x_old[id] = x_new; in filter_point()
657 y_old[id] = y_new; in filter_point()
661 static void record_point(u16 x, u16 y, u8 id) in record_point() argument
666 id_sign[id] = id_sign[id] + 1; in record_point()
667 if (id_sign[id] == 1) { in record_point()
668 x_old[id] = x; in record_point()
669 y_old[id] = y; in record_point()
671 x = (x_old[id] + x) / 2; in record_point()
672 y = (y_old[id] + y) / 2; in record_point()
673 if (x > x_old[id]) in record_point()
674 x_err = x - x_old[id]; in record_point()
676 x_err = x_old[id] - x; in record_point()
677 if (y > y_old[id]) in record_point()
678 y_err = y - y_old[id]; in record_point()
680 y_err = y_old[id] - y; in record_point()
683 x_old[id] = x; in record_point()
685 y_old[id] = y; in record_point()
689 x_old[id] = x; in record_point()
691 x_new = x_old[id]; in record_point()
695 y_old[id] = y; in record_point()
697 y_new = y_old[id]; in record_point()
700 if (id_sign[id] == 1) { in record_point()
701 x_new = x_old[id]; in record_point()
702 y_new = y_old[id]; in record_point()
717 input_report_key(ts->input, key, 1); in report_key()
718 input_sync(ts->input); in report_key()
726 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id) in report_data() argument
738 input_mt_slot(ts->input, id); in report_data()
739 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id); in report_data()
740 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure); in report_data()
742 input_report_abs(ts->input, ABS_MT_POSITION_X, SCREEN_MAX_X - x); in report_data()
744 input_report_abs(ts->input, ABS_MT_POSITION_X, x); in report_data()
747 input_report_abs(ts->input, ABS_MT_POSITION_Y, (SCREEN_MAX_Y - y)); in report_data()
749 input_report_abs(ts->input, ABS_MT_POSITION_Y, (y)); in report_data()
751 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1); in report_data()
753 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id); in report_data()
754 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure); in report_data()
755 input_report_abs(ts->input, ABS_MT_POSITION_X, x); in report_data()
756 input_report_abs(ts->input, ABS_MT_POSITION_Y, y); in report_data()
757 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1); in report_data()
758 input_mt_sync(ts->input); in report_data()
766 spin_lock_irqsave(&ts->irq_lock, irqflags); in ts_irq_disable()
767 if (!ts->flag_irq_is_disable) { in ts_irq_disable()
768 disable_irq_nosync(ts->client->irq); in ts_irq_disable()
769 ts->flag_irq_is_disable = 1; in ts_irq_disable()
771 spin_unlock_irqrestore(&ts->irq_lock, irqflags); in ts_irq_disable()
778 spin_lock_irqsave(&ts->irq_lock, irqflags); in ts_irq_enable()
779 if (ts->flag_irq_is_disable) { in ts_irq_enable()
780 enable_irq(ts->client->irq); in ts_irq_enable()
781 ts->flag_irq_is_disable = 0; in ts_irq_enable()
783 spin_unlock_irqrestore(&ts->irq_lock, irqflags); in ts_irq_enable()
789 u8 id, touches; in gsl3673_ts_worker() local
809 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size); in gsl3673_ts_worker()
811 dev_err(&ts->client->dev, "read failed\n"); in gsl3673_ts_worker()
814 touches = ts->touch_data[ts->dd->touch_index]; in gsl3673_ts_worker()
818 cinfo.x[i] = join_bytes((ts->touch_data[ts->dd->x_index + in gsl3673_ts_worker()
819 4 * i + 1] & 0xf), ts->touch_data[ts->dd->x_index + 4 * i]); in gsl3673_ts_worker()
820 cinfo.y[i] = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1], in gsl3673_ts_worker()
821 ts->touch_data[ts->dd->y_index + 4 * i]); in gsl3673_ts_worker()
822 cinfo.id[i] = ((ts->touch_data[ts->dd->x_index + 4 * i + 1] in gsl3673_ts_worker()
825 cinfo.finger_num = (ts->touch_data[3] << 24) | (ts->touch_data[2] << 16) in gsl3673_ts_worker()
826 | (ts->touch_data[1] << 8) | (ts->touch_data[0]); in gsl3673_ts_worker()
834 gsl_ts_write(ts->client, 0xf0, buf, 4); in gsl3673_ts_worker()
842 gsl_ts_write(ts->client, 0x8, buf, 4); in gsl3673_ts_worker()
853 id = cinfo.id[i]; in gsl3673_ts_worker()
857 x = join_bytes((ts->touch_data[ts->dd->x_index + 4 * i + 1] in gsl3673_ts_worker()
858 & 0xf), ts->touch_data[ts->dd->x_index + 4 * i]); in gsl3673_ts_worker()
859 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1], in gsl3673_ts_worker()
860 ts->touch_data[ts->dd->y_index + 4 * i]); in gsl3673_ts_worker()
861 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4; in gsl3673_ts_worker()
863 if (id >= 1 && id <= MAX_CONTACTS) { in gsl3673_ts_worker()
865 filter_point(x, y, id); in gsl3673_ts_worker()
867 record_point(x, y, id); in gsl3673_ts_worker()
869 report_data(ts, x_new, y_new, 10, id); in gsl3673_ts_worker()
870 id_state_flag[id] = 1; in gsl3673_ts_worker()
877 input_mt_slot(ts->input, i); in gsl3673_ts_worker()
878 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1); in gsl3673_ts_worker()
879 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false); in gsl3673_ts_worker()
888 input_report_key(ts->input, key, 0); in gsl3673_ts_worker()
889 input_sync(ts->input); in gsl3673_ts_worker()
894 input_sync(ts->input); in gsl3673_ts_worker()
970 if (!work_pending(&ts->work)) in gsl_ts_irq()
971 queue_work(ts->wq, &ts->work); in gsl_ts_irq()
975 static int gsl3673_ts_init(struct i2c_client *client, struct gsl_ts *ts) in gsl3673_ts_init() argument
983 ts->dd = &devices[ts->device_id]; in gsl3673_ts_init()
984 if (ts->device_id == 0) { in gsl3673_ts_init()
985 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + in gsl3673_ts_init()
986 ts->dd->touch_meta_data; in gsl3673_ts_init()
987 ts->dd->touch_index = 0; in gsl3673_ts_init()
989 ts->touch_data = devm_kzalloc(&client->dev, in gsl3673_ts_init()
990 ts->dd->data_size, GFP_KERNEL); in gsl3673_ts_init()
991 if (!ts->touch_data) in gsl3673_ts_init()
992 return -ENOMEM; in gsl3673_ts_init()
993 input_device = devm_input_allocate_device(&ts->client->dev); in gsl3673_ts_init()
995 return -ENOMEM; in gsl3673_ts_init()
997 ts->input = input_device; in gsl3673_ts_init()
998 input_device->name = GSL3673_I2C_NAME; in gsl3673_ts_init()
999 input_device->id.bustype = BUS_I2C; in gsl3673_ts_init()
1000 input_device->dev.parent = &client->dev; in gsl3673_ts_init()
1004 input_device->evbit[i] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY); in gsl3673_ts_init()
1005 set_bit(key_array[i], input_device->keybit); in gsl3673_ts_init()
1009 __set_bit(EV_ABS, input_device->evbit); in gsl3673_ts_init()
1010 __set_bit(EV_KEY, input_device->evbit); in gsl3673_ts_init()
1011 __set_bit(EV_REP, input_device->evbit); in gsl3673_ts_init()
1012 __set_bit(INPUT_PROP_DIRECT, input_device->propbit); in gsl3673_ts_init()
1017 set_bit(EV_ABS, input_device->evbit); in gsl3673_ts_init()
1018 set_bit(EV_KEY, input_device->evbit); in gsl3673_ts_init()
1019 __set_bit(INPUT_PROP_DIRECT, input_device->propbit); in gsl3673_ts_init()
1020 input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); in gsl3673_ts_init()
1022 set_bit(ABS_MT_POSITION_X, input_device->absbit); in gsl3673_ts_init()
1023 set_bit(ABS_MT_POSITION_Y, input_device->absbit); in gsl3673_ts_init()
1024 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit); in gsl3673_ts_init()
1025 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit); in gsl3673_ts_init()
1033 ts->wq = create_singlethread_workqueue("kworkqueue_ts"); in gsl3673_ts_init()
1034 if (!ts->wq) { in gsl3673_ts_init()
1035 dev_err(&client->dev, "gsl Could not create workqueue\n"); in gsl3673_ts_init()
1036 return -ENOMEM; in gsl3673_ts_init()
1038 flush_workqueue(ts->wq); in gsl3673_ts_init()
1039 INIT_WORK(&ts->work, gsl3673_ts_worker); in gsl3673_ts_init()
1045 destroy_workqueue(ts->wq); in gsl3673_ts_init()
1056 if (!ts->flag_activated) in gsl_ts_suspend()
1063 cancel_work_sync(&ts->work); in gsl_ts_suspend()
1070 input_mt_slot(ts->input, i); in gsl_ts_suspend()
1071 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1); in gsl_ts_suspend()
1072 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false); in gsl_ts_suspend()
1075 input_mt_sync(ts->input); in gsl_ts_suspend()
1077 input_sync(ts->input); in gsl_ts_suspend()
1080 input_sync(ts->input); in gsl_ts_suspend()
1082 ts->flag_activated = false; in gsl_ts_suspend()
1095 if (ts->flag_activated) in gsl_ts_resume()
1100 reset_chip(ts->client); in gsl_ts_resume()
1101 startup_chip(ts->client); in gsl_ts_resume()
1102 rc = check_mem_data(ts->client); in gsl_ts_resume()
1108 input_mt_slot(ts->input, i); in gsl_ts_resume()
1109 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1); in gsl_ts_resume()
1110 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false); in gsl_ts_resume()
1113 input_mt_sync(ts->input); in gsl_ts_resume()
1115 input_sync(ts->input); in gsl_ts_resume()
1122 ts->flag_activated = true; in gsl_ts_resume()
1132 if (!ts->flag_activated) in gsl_ts_pm_suspend()
1139 ts->flag_need_resume = true; in gsl_ts_pm_suspend()
1147 if (!ts->flag_need_resume) in gsl_ts_pm_resume()
1150 ts->flag_need_resume = false; in gsl_ts_pm_resume()
1159 return gsl_ts_suspend(&ts->client->dev); in gsl_ts_early_suspend()
1166 return gsl_ts_resume(&ts->client->dev); in gsl_ts_late_resume()
1173 clr_reg(ts->client); in gsl_download_fw_work()
1174 reset_chip(ts->client); in gsl_download_fw_work()
1175 gsl_load_fw(ts->client); in gsl_download_fw_work()
1176 startup_chip(ts->client); in gsl_download_fw_work()
1177 reset_chip(ts->client); in gsl_download_fw_work()
1178 startup_chip(ts->client); in gsl_download_fw_work()
1181 static int gsl_ts_probe(struct i2c_client *client, in gsl_ts_probe() argument
1182 const struct i2c_device_id *id) in gsl_ts_probe() argument
1190 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in gsl_ts_probe()
1191 dev_err(&client->dev, "gsl I2C functionality not supported\n"); in gsl_ts_probe()
1192 return -ENODEV; in gsl_ts_probe()
1194 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in gsl_ts_probe()
1196 return -ENOMEM; in gsl_ts_probe()
1197 ts->tp.tp_resume = gsl_ts_late_resume; in gsl_ts_probe()
1198 ts->tp.tp_suspend = gsl_ts_early_suspend; in gsl_ts_probe()
1199 tp_register_fb(&ts->tp); in gsl_ts_probe()
1200 ts->client = client; in gsl_ts_probe()
1201 i2c_set_clientdata(client, ts); in gsl_ts_probe()
1203 gsl_client = client; in gsl_ts_probe()
1205 rc = gsl3673_ts_init(client, ts); in gsl_ts_probe()
1207 dev_err(&client->dev, "gsl GSL3673 init failed\n"); in gsl_ts_probe()
1211 judge_chip_type(client); in gsl_ts_probe()
1213 INIT_WORK(&ts->download_fw_work, gsl_download_fw_work); in gsl_ts_probe()
1214 rc = init_chip(ts->client); in gsl_ts_probe()
1216 dev_err(&client->dev, "gsl_probe: init_chip failed\n"); in gsl_ts_probe()
1219 spin_lock_init(&ts->irq_lock); in gsl_ts_probe()
1220 client->irq = gpio_to_irq(ts->irq); in gsl_ts_probe()
1221 rc = devm_request_irq(&client->dev, client->irq, gsl_ts_irq, in gsl_ts_probe()
1222 IRQF_TRIGGER_RISING, client->name, ts); in gsl_ts_probe()
1224 dev_err(&client->dev, "gsl_probe: request irq failed\n"); in gsl_ts_probe()
1238 ts->flag_activated = true; in gsl_ts_probe()
1242 cancel_work_sync(&ts->download_fw_work); in gsl_ts_probe()
1244 tp_unregister_fb(&ts->tp); in gsl_ts_probe()
1248 static int gsl_ts_remove(struct i2c_client *client) in gsl_ts_remove() argument
1250 struct gsl_ts *ts = i2c_get_clientdata(client); in gsl_ts_remove()
1256 device_init_wakeup(&client->dev, 0); in gsl_ts_remove()
1257 cancel_work_sync(&ts->work); in gsl_ts_remove()
1258 destroy_workqueue(ts->wq); in gsl_ts_remove()
1259 cancel_work_sync(&ts->download_fw_work); in gsl_ts_remove()