Lines Matching full:ts

110 static void *goodix_get_event_report(struct goodix_ts_data *ts, u32 addr,  in goodix_get_event_report()  argument
113 struct spi_device *spi = to_spi_device(&ts->spi->dev); in goodix_get_event_report()
131 dev_err(ts->dev, "spi transfer error: %d", error); in goodix_get_event_report()
138 static int goodix_spi_read(struct goodix_ts_data *ts, u32 addr, in goodix_spi_read() argument
141 struct spi_device *spi = to_spi_device(&ts->spi->dev); in goodix_spi_read()
146 if (GOODIX_SPI_READ_PREFIX_LEN + len > sizeof(ts->xfer_buf)) { in goodix_spi_read()
147 dev_err(ts->dev, "read data len exceed limit %zu", in goodix_spi_read()
148 sizeof(ts->xfer_buf) - GOODIX_SPI_READ_PREFIX_LEN); in goodix_spi_read()
153 ts->xfer_buf[0] = GOODIX_SPI_READ_FLAG; in goodix_spi_read()
154 put_unaligned_be32(addr, ts->xfer_buf + GOODIX_SPI_TRANS_PREFIX_LEN); in goodix_spi_read()
158 xfers.tx_buf = ts->xfer_buf; in goodix_spi_read()
159 xfers.rx_buf = ts->xfer_buf; in goodix_spi_read()
165 dev_err(ts->dev, "spi transfer error: %d", error); in goodix_spi_read()
167 memcpy(data, ts->xfer_buf + GOODIX_SPI_READ_PREFIX_LEN, len); in goodix_spi_read()
172 static int goodix_spi_write(struct goodix_ts_data *ts, u32 addr, in goodix_spi_write() argument
175 struct spi_device *spi = to_spi_device(&ts->spi->dev); in goodix_spi_write()
180 if (GOODIX_SPI_WRITE_PREFIX_LEN + len > sizeof(ts->xfer_buf)) { in goodix_spi_write()
181 dev_err(ts->dev, "write data len exceed limit %zu", in goodix_spi_write()
182 sizeof(ts->xfer_buf) - GOODIX_SPI_WRITE_PREFIX_LEN); in goodix_spi_write()
187 ts->xfer_buf[0] = GOODIX_SPI_WRITE_FLAG; in goodix_spi_write()
188 put_unaligned_be32(addr, ts->xfer_buf + GOODIX_SPI_TRANS_PREFIX_LEN); in goodix_spi_write()
189 memcpy(ts->xfer_buf + GOODIX_SPI_WRITE_PREFIX_LEN, data, len); in goodix_spi_write()
193 xfers.tx_buf = ts->xfer_buf; in goodix_spi_write()
199 dev_err(ts->dev, "spi transfer error: %d", error); in goodix_spi_write()
204 static int goodix_dev_confirm(struct goodix_ts_data *ts) in goodix_dev_confirm() argument
210 gpiod_set_value_cansleep(ts->reset_gpio, 0); in goodix_dev_confirm()
215 error = goodix_spi_write(ts, GOODIX_DEV_CONFIRM_ADDR, in goodix_dev_confirm()
220 error = goodix_spi_read(ts, GOODIX_DEV_CONFIRM_ADDR, in goodix_dev_confirm()
231 dev_err(ts->dev, "device confirm failed, rx_buf: %*ph", 8, rx_buf); in goodix_dev_confirm()
245 struct goodix_ts_data *ts = hid->driver_data; in goodix_hid_parse() local
249 rsize = le16_to_cpu(ts->hid_desc.report_desc_length); in goodix_hid_parse()
251 dev_err(ts->dev, "invalid report desc size, %d", rsize); in goodix_hid_parse()
259 error = goodix_spi_read(ts, GOODIX_HID_REPORT_DESC_ADDR, rdesc, rsize); in goodix_hid_parse()
261 dev_err(ts->dev, "failed get report desc, %d", error); in goodix_hid_parse()
267 dev_err(ts->dev, "failed parse report, %d", error); in goodix_hid_parse()
295 struct goodix_ts_data *ts = hid->driver_data; in goodix_hid_start() local
305 if (report_size <= ts->hid_max_event_sz) in goodix_hid_start()
308 ts->event_buf = devm_krealloc(ts->dev, ts->event_buf, in goodix_hid_start()
310 if (!ts->event_buf) in goodix_hid_start()
313 ts->hid_max_event_sz = report_size; in goodix_hid_start()
324 struct goodix_ts_data *ts = hid->driver_data; in goodix_hid_open() local
326 set_bit(GOODIX_HID_STARTED, &ts->flags); in goodix_hid_open()
332 struct goodix_ts_data *ts = hid->driver_data; in goodix_hid_close() local
334 clear_bit(GOODIX_HID_STARTED, &ts->flags); in goodix_hid_close()
338 static int goodix_hid_check_ack_status(struct goodix_ts_data *ts, u32 *resp_len) in goodix_hid_check_ack_status() argument
351 error = goodix_spi_read(ts, ts->hid_report_addr, in goodix_hid_check_ack_status()
356 dev_err(ts->dev, "hrd.size too short: %d", len); in goodix_hid_check_ack_status()
389 struct goodix_ts_data *ts = hid->driver_data; in goodix_hid_get_raw_report() local
390 u16 data_register = le16_to_cpu(ts->hid_desc.data_register); in goodix_hid_get_raw_report()
391 u16 cmd_register = le16_to_cpu(ts->hid_desc.cmd_register); in goodix_hid_get_raw_report()
403 error = goodix_spi_read(ts, GOODIX_HID_SIGN_ADDR, buf, len); in goodix_hid_get_raw_report()
405 dev_err(ts->dev, "failed get win8 sign: %d", error); in goodix_hid_get_raw_report()
434 error = goodix_spi_write(ts, ts->hid_report_addr, tmp_buf, tx_len); in goodix_hid_get_raw_report()
436 dev_err(ts->dev, "failed send read feature cmd, %d", error); in goodix_hid_get_raw_report()
445 error = goodix_hid_check_ack_status(ts, &response_data_len); in goodix_hid_get_raw_report()
451 error = goodix_spi_read(ts, ts->hid_report_addr + in goodix_hid_get_raw_report()
455 dev_err(ts->dev, "failed read hid response data, %d", error); in goodix_hid_get_raw_report()
460 dev_err(ts->dev, "incorrect report (%d vs %d expected)", in goodix_hid_get_raw_report()
486 struct goodix_ts_data *ts = hid->driver_data; in goodix_hid_set_raw_report() local
487 u16 data_register = le16_to_cpu(ts->hid_desc.data_register); in goodix_hid_set_raw_report()
488 u16 cmd_register = le16_to_cpu(ts->hid_desc.cmd_register); in goodix_hid_set_raw_report()
521 error = goodix_spi_write(ts, ts->hid_report_addr, tmp_buf, tx_len); in goodix_hid_set_raw_report()
523 dev_err(ts->dev, "failed send report: %*ph", tx_len, tmp_buf); in goodix_hid_set_raw_report()
534 struct goodix_ts_data *ts = hid->driver_data; in goodix_hid_raw_request() local
537 guard(mutex)(&ts->hid_request_lock); in goodix_hid_raw_request()
566 struct goodix_ts_data *ts = data; in goodix_hid_irq() local
571 if (!test_bit(GOODIX_HID_STARTED, &ts->flags)) in goodix_hid_irq()
582 event = goodix_get_event_report(ts, ts->hid_report_addr, ts->event_buf, in goodix_hid_irq()
586 dev_err(ts->dev, "failed get coordinate data"); in goodix_hid_irq()
596 dev_err(ts->dev, "invalid coordinate event package size, %d", in goodix_hid_irq()
600 hid_input_report(ts->hid, HID_INPUT_REPORT, pkg->data, in goodix_hid_irq()
608 if (report_size >= ts->hid_max_event_sz) { in goodix_hid_irq()
609 dev_err(ts->dev, "package size exceed limit %d vs %d", in goodix_hid_irq()
610 report_size, ts->hid_max_event_sz); in goodix_hid_irq()
615 pkg = goodix_get_event_report(ts, ts->hid_report_addr + sizeof(*event), in goodix_hid_irq()
616 ts->event_buf, in goodix_hid_irq()
619 dev_err(ts->dev, "failed read attachment data content"); in goodix_hid_irq()
623 hid_input_report(ts->hid, HID_INPUT_REPORT, pkg->data, in goodix_hid_irq()
629 static int goodix_hid_init(struct goodix_ts_data *ts) in goodix_hid_init() argument
635 error = goodix_spi_read(ts, GOODIX_HID_DESC_ADDR, &ts->hid_desc, in goodix_hid_init()
636 sizeof(ts->hid_desc)); in goodix_hid_init()
638 dev_err(ts->dev, "failed get hid desc, %d", error); in goodix_hid_init()
646 hid->driver_data = ts; in goodix_hid_init()
649 hid->dev.parent = &ts->spi->dev; in goodix_hid_init()
651 hid->version = le16_to_cpu(ts->hid_desc.bcd_version); in goodix_hid_init()
652 hid->vendor = le16_to_cpu(ts->hid_desc.vendor_id); in goodix_hid_init()
653 hid->product = le16_to_cpu(ts->hid_desc.product_id); in goodix_hid_init()
659 dev_err(ts->dev, "failed add hid device, %d", error); in goodix_hid_init()
664 ts->hid = hid; in goodix_hid_init()
671 struct goodix_ts_data *ts; in goodix_spi_probe() local
681 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in goodix_spi_probe()
682 if (!ts) in goodix_spi_probe()
685 mutex_init(&ts->hid_request_lock); in goodix_spi_probe()
686 spi_set_drvdata(spi, ts); in goodix_spi_probe()
687 ts->spi = spi; in goodix_spi_probe()
688 ts->dev = dev; in goodix_spi_probe()
689 ts->hid_max_event_sz = GOODIX_SPI_READ_PREFIX_LEN + in goodix_spi_probe()
691 ts->event_buf = devm_kmalloc(dev, ts->hid_max_event_sz, GFP_KERNEL); in goodix_spi_probe()
692 if (!ts->event_buf) in goodix_spi_probe()
695 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in goodix_spi_probe()
696 if (IS_ERR(ts->reset_gpio)) in goodix_spi_probe()
697 return dev_err_probe(dev, PTR_ERR(ts->reset_gpio), in goodix_spi_probe()
701 &ts->hid_report_addr); in goodix_spi_probe()
706 error = goodix_dev_confirm(ts); in goodix_spi_probe()
713 error = goodix_hid_init(ts); in goodix_spi_probe()
719 error = devm_request_threaded_irq(&ts->spi->dev, ts->spi->irq, in goodix_spi_probe()
721 "goodix_spi_hid", ts); in goodix_spi_probe()
723 dev_err(ts->dev, "could not register interrupt, irq = %d, %d", in goodix_spi_probe()
724 ts->spi->irq, error); in goodix_spi_probe()
731 hid_destroy_device(ts->hid); in goodix_spi_probe()
737 struct goodix_ts_data *ts = spi_get_drvdata(spi); in goodix_spi_remove() local
740 hid_destroy_device(ts->hid); in goodix_spi_remove()
743 static int goodix_spi_set_power(struct goodix_ts_data *ts, int power_state) in goodix_spi_set_power() argument
751 guard(mutex)(&ts->hid_request_lock); in goodix_spi_set_power()
752 error = goodix_spi_write(ts, ts->hid_report_addr, power_control_cmd, in goodix_spi_set_power()
755 dev_err(ts->dev, "failed set power mode: %s", in goodix_spi_set_power()
764 struct goodix_ts_data *ts = dev_get_drvdata(dev); in goodix_spi_suspend() local
766 disable_irq(ts->spi->irq); in goodix_spi_suspend()
767 return goodix_spi_set_power(ts, GOODIX_SPI_POWER_SLEEP); in goodix_spi_suspend()
772 struct goodix_ts_data *ts = dev_get_drvdata(dev); in goodix_spi_resume() local
774 enable_irq(ts->spi->irq); in goodix_spi_resume()
775 return goodix_spi_set_power(ts, GOODIX_SPI_POWER_ON); in goodix_spi_resume()