Lines Matching refs:ts
89 static int goodix_check_cfg_8(struct goodix_ts_data *ts,
91 static int goodix_check_cfg_16(struct goodix_ts_data *ts,
253 static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) in goodix_ts_read_input_report() argument
266 error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR, in goodix_ts_read_input_report()
267 data, ts->contact_size + 1); in goodix_ts_read_input_report()
269 dev_err(&ts->client->dev, "I2C transfer error: %d\n", in goodix_ts_read_input_report()
276 if (touch_num > ts->max_touch_num) in goodix_ts_read_input_report()
280 data += 1 + ts->contact_size; in goodix_ts_read_input_report()
281 error = goodix_i2c_read(ts->client, in goodix_ts_read_input_report()
283 1 + ts->contact_size, in goodix_ts_read_input_report()
285 ts->contact_size * in goodix_ts_read_input_report()
304 static void goodix_ts_report_touch_8b(struct goodix_ts_data *ts, u8 *coor_data) in goodix_ts_report_touch_8b() argument
311 input_mt_slot(ts->input_dev, id); in goodix_ts_report_touch_8b()
312 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true); in goodix_ts_report_touch_8b()
313 touchscreen_report_pos(ts->input_dev, &ts->prop, in goodix_ts_report_touch_8b()
315 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w); in goodix_ts_report_touch_8b()
316 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w); in goodix_ts_report_touch_8b()
319 static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data) in goodix_ts_report_touch_9b() argument
326 input_mt_slot(ts->input_dev, id); in goodix_ts_report_touch_9b()
327 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true); in goodix_ts_report_touch_9b()
328 touchscreen_report_pos(ts->input_dev, &ts->prop, in goodix_ts_report_touch_9b()
330 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w); in goodix_ts_report_touch_9b()
331 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w); in goodix_ts_report_touch_9b()
342 static void goodix_process_events(struct goodix_ts_data *ts) in goodix_process_events() argument
348 touch_num = goodix_ts_read_input_report(ts, point_data); in goodix_process_events()
356 input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4)); in goodix_process_events()
359 if (ts->contact_size == 9) in goodix_process_events()
360 goodix_ts_report_touch_9b(ts, in goodix_process_events()
361 &point_data[1 + ts->contact_size * i]); in goodix_process_events()
363 goodix_ts_report_touch_8b(ts, in goodix_process_events()
364 &point_data[1 + ts->contact_size * i]); in goodix_process_events()
366 input_mt_sync_frame(ts->input_dev); in goodix_process_events()
367 input_sync(ts->input_dev); in goodix_process_events()
378 struct goodix_ts_data *ts = dev_id; in goodix_ts_irq_handler() local
380 goodix_process_events(ts); in goodix_ts_irq_handler()
382 if (goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0) < 0) in goodix_ts_irq_handler()
383 dev_err(&ts->client->dev, "I2C write end_cmd error\n"); in goodix_ts_irq_handler()
388 static void goodix_free_irq(struct goodix_ts_data *ts) in goodix_free_irq() argument
390 devm_free_irq(&ts->client->dev, ts->client->irq, ts); in goodix_free_irq()
393 static int goodix_request_irq(struct goodix_ts_data *ts) in goodix_request_irq() argument
395 return devm_request_threaded_irq(&ts->client->dev, ts->client->irq, in goodix_request_irq()
397 ts->irq_flags, ts->client->name, ts); in goodix_request_irq()
400 static int goodix_check_cfg_8(struct goodix_ts_data *ts, in goodix_check_cfg_8() argument
410 dev_err(&ts->client->dev, in goodix_check_cfg_8()
416 dev_err(&ts->client->dev, in goodix_check_cfg_8()
424 static int goodix_check_cfg_16(struct goodix_ts_data *ts, in goodix_check_cfg_16() argument
434 dev_err(&ts->client->dev, in goodix_check_cfg_16()
440 dev_err(&ts->client->dev, in goodix_check_cfg_16()
454 static int goodix_check_cfg(struct goodix_ts_data *ts, in goodix_check_cfg() argument
458 dev_err(&ts->client->dev, in goodix_check_cfg()
463 return ts->chip->check_config(ts, cfg); in goodix_check_cfg()
472 static int goodix_send_cfg(struct goodix_ts_data *ts, in goodix_send_cfg() argument
477 error = goodix_check_cfg(ts, cfg); in goodix_send_cfg()
481 error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg->data, in goodix_send_cfg()
484 dev_err(&ts->client->dev, "Failed to write config data: %d", in goodix_send_cfg()
488 dev_dbg(&ts->client->dev, "Config sent successfully."); in goodix_send_cfg()
496 static int goodix_int_sync(struct goodix_ts_data *ts) in goodix_int_sync() argument
500 error = gpiod_direction_output(ts->gpiod_int, 0); in goodix_int_sync()
506 error = gpiod_direction_input(ts->gpiod_int); in goodix_int_sync()
518 static int goodix_reset(struct goodix_ts_data *ts) in goodix_reset() argument
523 error = gpiod_direction_output(ts->gpiod_rst, 0); in goodix_reset()
530 error = gpiod_direction_output(ts->gpiod_int, ts->client->addr == 0x14); in goodix_reset()
536 error = gpiod_direction_output(ts->gpiod_rst, 1); in goodix_reset()
543 error = gpiod_direction_input(ts->gpiod_rst); in goodix_reset()
547 error = goodix_int_sync(ts); in goodix_reset()
559 static int goodix_get_gpio_config(struct goodix_ts_data *ts) in goodix_get_gpio_config() argument
565 if (!ts->client) in goodix_get_gpio_config()
567 dev = &ts->client->dev; in goodix_get_gpio_config()
569 ts->avdd28 = devm_regulator_get(dev, "AVDD28"); in goodix_get_gpio_config()
570 if (IS_ERR(ts->avdd28)) { in goodix_get_gpio_config()
571 error = PTR_ERR(ts->avdd28); in goodix_get_gpio_config()
578 ts->vddio = devm_regulator_get(dev, "VDDIO"); in goodix_get_gpio_config()
579 if (IS_ERR(ts->vddio)) { in goodix_get_gpio_config()
580 error = PTR_ERR(ts->vddio); in goodix_get_gpio_config()
597 ts->gpiod_int = gpiod; in goodix_get_gpio_config()
609 ts->gpiod_rst = gpiod; in goodix_get_gpio_config()
621 static void goodix_read_config(struct goodix_ts_data *ts) in goodix_read_config() argument
627 error = goodix_i2c_read(ts->client, ts->chip->config_addr, in goodix_read_config()
628 config, ts->chip->config_len); in goodix_read_config()
630 dev_warn(&ts->client->dev, "Error reading config: %d\n", in goodix_read_config()
632 ts->int_trigger_type = GOODIX_INT_TRIGGER; in goodix_read_config()
633 ts->max_touch_num = GOODIX_MAX_CONTACTS; in goodix_read_config()
637 ts->int_trigger_type = config[TRIGGER_LOC] & 0x03; in goodix_read_config()
638 ts->max_touch_num = config[MAX_CONTACTS_LOC] & 0x0f; in goodix_read_config()
643 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_X, x_max - 1); in goodix_read_config()
644 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_Y, y_max - 1); in goodix_read_config()
653 static int goodix_read_version(struct goodix_ts_data *ts) in goodix_read_version() argument
659 error = goodix_i2c_read(ts->client, GOODIX_REG_ID, buf, sizeof(buf)); in goodix_read_version()
661 dev_err(&ts->client->dev, "read version failed: %d\n", error); in goodix_read_version()
667 if (kstrtou16(id_str, 10, &ts->id)) in goodix_read_version()
668 ts->id = 0x1001; in goodix_read_version()
670 ts->version = get_unaligned_le16(&buf[4]); in goodix_read_version()
672 dev_info(&ts->client->dev, "ID %d, version: %04x\n", ts->id, in goodix_read_version()
673 ts->version); in goodix_read_version()
713 static int goodix_configure_dev(struct goodix_ts_data *ts) in goodix_configure_dev() argument
717 ts->int_trigger_type = GOODIX_INT_TRIGGER; in goodix_configure_dev()
718 ts->max_touch_num = GOODIX_MAX_CONTACTS; in goodix_configure_dev()
720 ts->input_dev = devm_input_allocate_device(&ts->client->dev); in goodix_configure_dev()
721 if (!ts->input_dev) { in goodix_configure_dev()
722 dev_err(&ts->client->dev, "Failed to allocate input device."); in goodix_configure_dev()
726 ts->input_dev->name = "Goodix Capacitive TouchScreen"; in goodix_configure_dev()
727 ts->input_dev->phys = "input/ts"; in goodix_configure_dev()
728 ts->input_dev->id.bustype = BUS_I2C; in goodix_configure_dev()
729 ts->input_dev->id.vendor = 0x0416; in goodix_configure_dev()
730 ts->input_dev->id.product = ts->id; in goodix_configure_dev()
731 ts->input_dev->id.version = ts->version; in goodix_configure_dev()
734 input_set_capability(ts->input_dev, EV_KEY, KEY_LEFTMETA); in goodix_configure_dev()
736 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X); in goodix_configure_dev()
737 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y); in goodix_configure_dev()
738 input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); in goodix_configure_dev()
739 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); in goodix_configure_dev()
742 goodix_read_config(ts); in goodix_configure_dev()
745 touchscreen_parse_properties(ts->input_dev, true, &ts->prop); in goodix_configure_dev()
747 if (!ts->prop.max_x || !ts->prop.max_y || !ts->max_touch_num) { in goodix_configure_dev()
748 dev_err(&ts->client->dev, in goodix_configure_dev()
750 ts->prop.max_x, ts->prop.max_y, ts->max_touch_num); in goodix_configure_dev()
751 ts->prop.max_x = GOODIX_MAX_WIDTH - 1; in goodix_configure_dev()
752 ts->prop.max_y = GOODIX_MAX_HEIGHT - 1; in goodix_configure_dev()
753 ts->max_touch_num = GOODIX_MAX_CONTACTS; in goodix_configure_dev()
754 input_abs_set_max(ts->input_dev, in goodix_configure_dev()
755 ABS_MT_POSITION_X, ts->prop.max_x); in goodix_configure_dev()
756 input_abs_set_max(ts->input_dev, in goodix_configure_dev()
757 ABS_MT_POSITION_Y, ts->prop.max_y); in goodix_configure_dev()
761 ts->prop.invert_x = true; in goodix_configure_dev()
762 ts->prop.invert_y = true; in goodix_configure_dev()
763 dev_dbg(&ts->client->dev, in goodix_configure_dev()
768 ts->contact_size = 9; in goodix_configure_dev()
770 dev_dbg(&ts->client->dev, in goodix_configure_dev()
774 error = input_mt_init_slots(ts->input_dev, ts->max_touch_num, in goodix_configure_dev()
777 dev_err(&ts->client->dev, in goodix_configure_dev()
782 error = input_register_device(ts->input_dev); in goodix_configure_dev()
784 dev_err(&ts->client->dev, in goodix_configure_dev()
789 ts->irq_flags = goodix_irq_flags[ts->int_trigger_type] | IRQF_ONESHOT; in goodix_configure_dev()
790 error = goodix_request_irq(ts); in goodix_configure_dev()
792 dev_err(&ts->client->dev, "request IRQ failed: %d\n", error); in goodix_configure_dev()
809 struct goodix_ts_data *ts = ctx; in goodix_config_cb() local
814 error = goodix_send_cfg(ts, cfg); in goodix_config_cb()
819 goodix_configure_dev(ts); in goodix_config_cb()
823 complete_all(&ts->firmware_loading_complete); in goodix_config_cb()
828 struct goodix_ts_data *ts = arg; in goodix_disable_regulators() local
830 regulator_disable(ts->vddio); in goodix_disable_regulators()
831 regulator_disable(ts->avdd28); in goodix_disable_regulators()
837 struct goodix_ts_data *ts; in goodix_ts_probe() local
847 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in goodix_ts_probe()
848 if (!ts) in goodix_ts_probe()
851 ts->client = client; in goodix_ts_probe()
852 i2c_set_clientdata(client, ts); in goodix_ts_probe()
853 init_completion(&ts->firmware_loading_complete); in goodix_ts_probe()
854 ts->contact_size = GOODIX_CONTACT_SIZE; in goodix_ts_probe()
856 error = goodix_get_gpio_config(ts); in goodix_ts_probe()
861 error = regulator_enable(ts->avdd28); in goodix_ts_probe()
869 error = regulator_enable(ts->vddio); in goodix_ts_probe()
874 regulator_disable(ts->avdd28); in goodix_ts_probe()
879 goodix_disable_regulators, ts); in goodix_ts_probe()
883 if (ts->gpiod_int && ts->gpiod_rst) { in goodix_ts_probe()
885 error = goodix_reset(ts); in goodix_ts_probe()
898 error = goodix_read_version(ts); in goodix_ts_probe()
904 ts->chip = goodix_get_chip_data(ts->id); in goodix_ts_probe()
906 if (ts->gpiod_int && ts->gpiod_rst) { in goodix_ts_probe()
908 ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL, in goodix_ts_probe()
909 "goodix_%d_cfg.bin", ts->id); in goodix_ts_probe()
910 if (!ts->cfg_name) in goodix_ts_probe()
913 error = request_firmware_nowait(THIS_MODULE, true, ts->cfg_name, in goodix_ts_probe()
914 &client->dev, GFP_KERNEL, ts, in goodix_ts_probe()
925 error = goodix_configure_dev(ts); in goodix_ts_probe()
935 struct goodix_ts_data *ts = i2c_get_clientdata(client); in goodix_ts_remove() local
937 if (ts->gpiod_int && ts->gpiod_rst) in goodix_ts_remove()
938 wait_for_completion(&ts->firmware_loading_complete); in goodix_ts_remove()
946 struct goodix_ts_data *ts = i2c_get_clientdata(client); in goodix_suspend() local
950 if (!ts->gpiod_int || !ts->gpiod_rst) { in goodix_suspend()
955 wait_for_completion(&ts->firmware_loading_complete); in goodix_suspend()
958 goodix_free_irq(ts); in goodix_suspend()
961 error = gpiod_direction_output(ts->gpiod_int, 0); in goodix_suspend()
963 goodix_request_irq(ts); in goodix_suspend()
969 error = goodix_i2c_write_u8(ts->client, GOODIX_REG_COMMAND, in goodix_suspend()
972 dev_err(&ts->client->dev, "Screen off command failed\n"); in goodix_suspend()
973 gpiod_direction_input(ts->gpiod_int); in goodix_suspend()
974 goodix_request_irq(ts); in goodix_suspend()
990 struct goodix_ts_data *ts = i2c_get_clientdata(client); in goodix_resume() local
993 if (!ts->gpiod_int || !ts->gpiod_rst) { in goodix_resume()
1002 error = gpiod_direction_output(ts->gpiod_int, 1); in goodix_resume()
1008 error = goodix_int_sync(ts); in goodix_resume()
1012 error = goodix_request_irq(ts); in goodix_resume()