Lines Matching refs:ts

88 static int goodix_check_cfg_8(struct goodix_ts_data *ts,
90 static int goodix_check_cfg_16(struct goodix_ts_data *ts,
237 static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) in goodix_ts_read_input_report() argument
250 error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR, in goodix_ts_read_input_report()
253 dev_err(&ts->client->dev, "I2C transfer error: %d\n", in goodix_ts_read_input_report()
260 if (touch_num > ts->max_touch_num) in goodix_ts_read_input_report()
265 error = goodix_i2c_read(ts->client, in goodix_ts_read_input_report()
288 static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data) in goodix_ts_report_touch() argument
295 input_mt_slot(ts->input_dev, id); in goodix_ts_report_touch()
296 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true); in goodix_ts_report_touch()
297 touchscreen_report_pos(ts->input_dev, &ts->prop, in goodix_ts_report_touch()
299 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w); in goodix_ts_report_touch()
300 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w); in goodix_ts_report_touch()
311 static void goodix_process_events(struct goodix_ts_data *ts) in goodix_process_events() argument
317 touch_num = goodix_ts_read_input_report(ts, point_data); in goodix_process_events()
325 input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4)); in goodix_process_events()
328 goodix_ts_report_touch(ts, in goodix_process_events()
331 input_mt_sync_frame(ts->input_dev); in goodix_process_events()
332 input_sync(ts->input_dev); in goodix_process_events()
343 struct goodix_ts_data *ts = dev_id; in goodix_ts_irq_handler() local
345 goodix_process_events(ts); in goodix_ts_irq_handler()
347 if (goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0) < 0) in goodix_ts_irq_handler()
348 dev_err(&ts->client->dev, "I2C write end_cmd error\n"); in goodix_ts_irq_handler()
353 static void goodix_free_irq(struct goodix_ts_data *ts) in goodix_free_irq() argument
355 devm_free_irq(&ts->client->dev, ts->client->irq, ts); in goodix_free_irq()
358 static int goodix_request_irq(struct goodix_ts_data *ts) in goodix_request_irq() argument
360 return devm_request_threaded_irq(&ts->client->dev, ts->client->irq, in goodix_request_irq()
362 ts->irq_flags, ts->client->name, ts); in goodix_request_irq()
365 static int goodix_check_cfg_8(struct goodix_ts_data *ts, in goodix_check_cfg_8() argument
375 dev_err(&ts->client->dev, in goodix_check_cfg_8()
381 dev_err(&ts->client->dev, in goodix_check_cfg_8()
389 static int goodix_check_cfg_16(struct goodix_ts_data *ts, in goodix_check_cfg_16() argument
399 dev_err(&ts->client->dev, in goodix_check_cfg_16()
405 dev_err(&ts->client->dev, in goodix_check_cfg_16()
419 static int goodix_check_cfg(struct goodix_ts_data *ts, in goodix_check_cfg() argument
423 dev_err(&ts->client->dev, in goodix_check_cfg()
428 return ts->chip->check_config(ts, cfg); in goodix_check_cfg()
437 static int goodix_send_cfg(struct goodix_ts_data *ts, in goodix_send_cfg() argument
442 error = goodix_check_cfg(ts, cfg); in goodix_send_cfg()
446 error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg->data, in goodix_send_cfg()
449 dev_err(&ts->client->dev, "Failed to write config data: %d", in goodix_send_cfg()
453 dev_dbg(&ts->client->dev, "Config sent successfully."); in goodix_send_cfg()
461 static int goodix_int_sync(struct goodix_ts_data *ts) in goodix_int_sync() argument
465 error = gpiod_direction_output(ts->gpiod_int, 0); in goodix_int_sync()
471 error = gpiod_direction_input(ts->gpiod_int); in goodix_int_sync()
483 static int goodix_reset(struct goodix_ts_data *ts) in goodix_reset() argument
488 error = gpiod_direction_output(ts->gpiod_rst, 0); in goodix_reset()
495 error = gpiod_direction_output(ts->gpiod_int, ts->client->addr == 0x14); in goodix_reset()
501 error = gpiod_direction_output(ts->gpiod_rst, 1); in goodix_reset()
508 error = gpiod_direction_input(ts->gpiod_rst); in goodix_reset()
512 error = goodix_int_sync(ts); in goodix_reset()
524 static int goodix_get_gpio_config(struct goodix_ts_data *ts) in goodix_get_gpio_config() argument
530 if (!ts->client) in goodix_get_gpio_config()
532 dev = &ts->client->dev; in goodix_get_gpio_config()
544 ts->gpiod_int = gpiod; in goodix_get_gpio_config()
556 ts->gpiod_rst = gpiod; in goodix_get_gpio_config()
568 static void goodix_read_config(struct goodix_ts_data *ts) in goodix_read_config() argument
574 error = goodix_i2c_read(ts->client, ts->chip->config_addr, in goodix_read_config()
575 config, ts->chip->config_len); in goodix_read_config()
577 dev_warn(&ts->client->dev, "Error reading config: %d\n", in goodix_read_config()
579 ts->int_trigger_type = GOODIX_INT_TRIGGER; in goodix_read_config()
580 ts->max_touch_num = GOODIX_MAX_CONTACTS; in goodix_read_config()
584 ts->int_trigger_type = config[TRIGGER_LOC] & 0x03; in goodix_read_config()
585 ts->max_touch_num = config[MAX_CONTACTS_LOC] & 0x0f; in goodix_read_config()
590 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_X, x_max - 1); in goodix_read_config()
591 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_Y, y_max - 1); in goodix_read_config()
600 static int goodix_read_version(struct goodix_ts_data *ts) in goodix_read_version() argument
606 error = goodix_i2c_read(ts->client, GOODIX_REG_ID, buf, sizeof(buf)); in goodix_read_version()
608 dev_err(&ts->client->dev, "read version failed: %d\n", error); in goodix_read_version()
614 if (kstrtou16(id_str, 10, &ts->id)) in goodix_read_version()
615 ts->id = 0x1001; in goodix_read_version()
617 ts->version = get_unaligned_le16(&buf[4]); in goodix_read_version()
619 dev_info(&ts->client->dev, "ID %d, version: %04x\n", ts->id, in goodix_read_version()
620 ts->version); in goodix_read_version()
660 static int goodix_configure_dev(struct goodix_ts_data *ts) in goodix_configure_dev() argument
664 ts->int_trigger_type = GOODIX_INT_TRIGGER; in goodix_configure_dev()
665 ts->max_touch_num = GOODIX_MAX_CONTACTS; in goodix_configure_dev()
667 ts->input_dev = devm_input_allocate_device(&ts->client->dev); in goodix_configure_dev()
668 if (!ts->input_dev) { in goodix_configure_dev()
669 dev_err(&ts->client->dev, "Failed to allocate input device."); in goodix_configure_dev()
673 ts->input_dev->name = "Goodix Capacitive TouchScreen"; in goodix_configure_dev()
674 ts->input_dev->phys = "input/ts"; in goodix_configure_dev()
675 ts->input_dev->id.bustype = BUS_I2C; in goodix_configure_dev()
676 ts->input_dev->id.vendor = 0x0416; in goodix_configure_dev()
677 ts->input_dev->id.product = ts->id; in goodix_configure_dev()
678 ts->input_dev->id.version = ts->version; in goodix_configure_dev()
681 input_set_capability(ts->input_dev, EV_KEY, KEY_LEFTMETA); in goodix_configure_dev()
683 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X); in goodix_configure_dev()
684 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y); in goodix_configure_dev()
685 input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); in goodix_configure_dev()
686 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); in goodix_configure_dev()
689 goodix_read_config(ts); in goodix_configure_dev()
692 touchscreen_parse_properties(ts->input_dev, true, &ts->prop); in goodix_configure_dev()
694 if (!ts->prop.max_x || !ts->prop.max_y || !ts->max_touch_num) { in goodix_configure_dev()
695 dev_err(&ts->client->dev, "Invalid config, using defaults\n"); in goodix_configure_dev()
696 ts->prop.max_x = GOODIX_MAX_WIDTH - 1; in goodix_configure_dev()
697 ts->prop.max_y = GOODIX_MAX_HEIGHT - 1; in goodix_configure_dev()
698 ts->max_touch_num = GOODIX_MAX_CONTACTS; in goodix_configure_dev()
699 input_abs_set_max(ts->input_dev, in goodix_configure_dev()
700 ABS_MT_POSITION_X, ts->prop.max_x); in goodix_configure_dev()
701 input_abs_set_max(ts->input_dev, in goodix_configure_dev()
702 ABS_MT_POSITION_Y, ts->prop.max_y); in goodix_configure_dev()
706 ts->prop.invert_x = true; in goodix_configure_dev()
707 ts->prop.invert_y = true; in goodix_configure_dev()
708 dev_dbg(&ts->client->dev, in goodix_configure_dev()
712 error = input_mt_init_slots(ts->input_dev, ts->max_touch_num, in goodix_configure_dev()
715 dev_err(&ts->client->dev, in goodix_configure_dev()
720 error = input_register_device(ts->input_dev); in goodix_configure_dev()
722 dev_err(&ts->client->dev, in goodix_configure_dev()
727 ts->irq_flags = goodix_irq_flags[ts->int_trigger_type] | IRQF_ONESHOT; in goodix_configure_dev()
728 error = goodix_request_irq(ts); in goodix_configure_dev()
730 dev_err(&ts->client->dev, "request IRQ failed: %d\n", error); in goodix_configure_dev()
747 struct goodix_ts_data *ts = ctx; in goodix_config_cb() local
752 error = goodix_send_cfg(ts, cfg); in goodix_config_cb()
757 goodix_configure_dev(ts); in goodix_config_cb()
761 complete_all(&ts->firmware_loading_complete); in goodix_config_cb()
767 struct goodix_ts_data *ts; in goodix_ts_probe() local
777 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); in goodix_ts_probe()
778 if (!ts) in goodix_ts_probe()
781 ts->client = client; in goodix_ts_probe()
782 i2c_set_clientdata(client, ts); in goodix_ts_probe()
783 init_completion(&ts->firmware_loading_complete); in goodix_ts_probe()
785 error = goodix_get_gpio_config(ts); in goodix_ts_probe()
789 if (ts->gpiod_int && ts->gpiod_rst) { in goodix_ts_probe()
791 error = goodix_reset(ts); in goodix_ts_probe()
804 error = goodix_read_version(ts); in goodix_ts_probe()
810 ts->chip = goodix_get_chip_data(ts->id); in goodix_ts_probe()
812 if (ts->gpiod_int && ts->gpiod_rst) { in goodix_ts_probe()
814 ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL, in goodix_ts_probe()
815 "goodix_%d_cfg.bin", ts->id); in goodix_ts_probe()
816 if (!ts->cfg_name) in goodix_ts_probe()
819 error = request_firmware_nowait(THIS_MODULE, true, ts->cfg_name, in goodix_ts_probe()
820 &client->dev, GFP_KERNEL, ts, in goodix_ts_probe()
831 error = goodix_configure_dev(ts); in goodix_ts_probe()
841 struct goodix_ts_data *ts = i2c_get_clientdata(client); in goodix_ts_remove() local
843 if (ts->gpiod_int && ts->gpiod_rst) in goodix_ts_remove()
844 wait_for_completion(&ts->firmware_loading_complete); in goodix_ts_remove()
852 struct goodix_ts_data *ts = i2c_get_clientdata(client); in goodix_suspend() local
856 if (!ts->gpiod_int || !ts->gpiod_rst) { in goodix_suspend()
861 wait_for_completion(&ts->firmware_loading_complete); in goodix_suspend()
864 goodix_free_irq(ts); in goodix_suspend()
867 error = gpiod_direction_output(ts->gpiod_int, 0); in goodix_suspend()
869 goodix_request_irq(ts); in goodix_suspend()
875 error = goodix_i2c_write_u8(ts->client, GOODIX_REG_COMMAND, in goodix_suspend()
878 dev_err(&ts->client->dev, "Screen off command failed\n"); in goodix_suspend()
879 gpiod_direction_input(ts->gpiod_int); in goodix_suspend()
880 goodix_request_irq(ts); in goodix_suspend()
896 struct goodix_ts_data *ts = i2c_get_clientdata(client); in goodix_resume() local
899 if (!ts->gpiod_int || !ts->gpiod_rst) { in goodix_resume()
908 error = gpiod_direction_output(ts->gpiod_int, 1); in goodix_resume()
914 error = goodix_int_sync(ts); in goodix_resume()
918 error = goodix_request_irq(ts); in goodix_resume()