Skip to content

Commit 390b059

Browse files
author
Jiri Kosina
committed
Merge branch 'for-6.13/goodix' into for-linus
- Support for Goodix GT7986U SPI (Charles Wang) - assorted code cleanups and fixes (Charles Wang)
2 parents d273b82 + c8eb2fa commit 390b059

2 files changed

Lines changed: 91 additions & 13 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/input/goodix,gt7986u-spifw.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Goodix GT7986U SPI HID Touchscreen
8+
9+
maintainers:
10+
- Charles Wang <charles.goodix@gmail.com>
11+
12+
description: |
13+
Supports the Goodix GT7986U touchscreen.
14+
This touch controller reports data packaged according to the HID protocol
15+
over the SPI bus, but it is incompatible with Microsoft's HID-over-SPI protocol.
16+
17+
NOTE: these bindings are distinct from the bindings used with the
18+
GT7986U when the chip is running I2C firmware. This is because there's
19+
not a single device that talks over both I2C and SPI but rather
20+
distinct touchscreens that happen to be built with the same ASIC but
21+
that are distinct products running distinct firmware.
22+
23+
allOf:
24+
- $ref: /schemas/spi/spi-peripheral-props.yaml#
25+
26+
properties:
27+
compatible:
28+
enum:
29+
- goodix,gt7986u-spifw
30+
31+
reg:
32+
maxItems: 1
33+
34+
interrupts:
35+
maxItems: 1
36+
37+
reset-gpios:
38+
maxItems: 1
39+
40+
spi-max-frequency: true
41+
42+
required:
43+
- compatible
44+
- reg
45+
- interrupts
46+
- reset-gpios
47+
48+
unevaluatedProperties: false
49+
50+
examples:
51+
- |
52+
#include <dt-bindings/interrupt-controller/irq.h>
53+
#include <dt-bindings/gpio/gpio.h>
54+
55+
spi {
56+
#address-cells = <1>;
57+
#size-cells = <0>;
58+
59+
touchscreen@0 {
60+
compatible = "goodix,gt7986u-spifw";
61+
reg = <0>;
62+
interrupt-parent = <&gpio>;
63+
interrupts = <25 IRQ_TYPE_LEVEL_LOW>;
64+
reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
65+
spi-max-frequency = <10000000>;
66+
};
67+
};
68+
69+
...

drivers/hid/hid-goodix-spi.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define GOODIX_HID_DESC_ADDR 0x1058C
2020
#define GOODIX_HID_REPORT_DESC_ADDR 0x105AA
2121
#define GOODIX_HID_SIGN_ADDR 0x10D32
22+
#define GOODIX_HID_CMD_ADDR 0x10364
23+
#define GOODIX_HID_REPORT_ADDR 0x22C8C
2224

2325
#define GOODIX_HID_GET_REPORT_CMD 0x02
2426
#define GOODIX_HID_SET_REPORT_CMD 0x03
@@ -348,15 +350,15 @@ static int goodix_hid_check_ack_status(struct goodix_ts_data *ts, u32 *resp_len)
348350
* - byte 0: Ack flag, value of 1 for data ready
349351
* - bytes 1-2: Response data length
350352
*/
351-
error = goodix_spi_read(ts, ts->hid_report_addr,
353+
error = goodix_spi_read(ts, GOODIX_HID_CMD_ADDR,
352354
&hdr, sizeof(hdr));
353355
if (!error && (hdr.flag & GOODIX_HID_ACK_READY_FLAG)) {
354356
len = le16_to_cpu(hdr.size);
355357
if (len < GOODIX_HID_PKG_LEN_SIZE) {
356358
dev_err(ts->dev, "hrd.size too short: %d", len);
357359
return -EINVAL;
358360
}
359-
*resp_len = len;
361+
*resp_len = len - GOODIX_HID_PKG_LEN_SIZE;
360362
return 0;
361363
}
362364

@@ -431,7 +433,7 @@ static int goodix_hid_get_raw_report(struct hid_device *hid,
431433
tx_len += args_len;
432434

433435
/* Step1: write report request info */
434-
error = goodix_spi_write(ts, ts->hid_report_addr, tmp_buf, tx_len);
436+
error = goodix_spi_write(ts, GOODIX_HID_CMD_ADDR, tmp_buf, tx_len);
435437
if (error) {
436438
dev_err(ts->dev, "failed send read feature cmd, %d", error);
437439
return error;
@@ -446,9 +448,12 @@ static int goodix_hid_get_raw_report(struct hid_device *hid,
446448
if (error)
447449
return error;
448450

449-
len = min(len, response_data_len - GOODIX_HID_PKG_LEN_SIZE);
451+
/* Empty reprot response */
452+
if (!response_data_len)
453+
return 0;
454+
len = min(len, response_data_len);
450455
/* Step3: read response data(skip 2bytes of hid pkg length) */
451-
error = goodix_spi_read(ts, ts->hid_report_addr +
456+
error = goodix_spi_read(ts, GOODIX_HID_CMD_ADDR +
452457
GOODIX_HID_ACK_HEADER_SIZE +
453458
GOODIX_HID_PKG_LEN_SIZE, buf, len);
454459
if (error) {
@@ -518,7 +523,7 @@ static int goodix_hid_set_raw_report(struct hid_device *hid,
518523
memcpy(tmp_buf + tx_len, buf, len);
519524
tx_len += len;
520525

521-
error = goodix_spi_write(ts, ts->hid_report_addr, tmp_buf, tx_len);
526+
error = goodix_spi_write(ts, GOODIX_HID_CMD_ADDR, tmp_buf, tx_len);
522527
if (error) {
523528
dev_err(ts->dev, "failed send report: %*ph", tx_len, tmp_buf);
524529
return error;
@@ -697,12 +702,7 @@ static int goodix_spi_probe(struct spi_device *spi)
697702
return dev_err_probe(dev, PTR_ERR(ts->reset_gpio),
698703
"failed to request reset gpio\n");
699704

700-
error = device_property_read_u32(dev, "goodix,hid-report-addr",
701-
&ts->hid_report_addr);
702-
if (error)
703-
return dev_err_probe(dev, error,
704-
"failed get hid report addr\n");
705-
705+
ts->hid_report_addr = GOODIX_HID_REPORT_ADDR;
706706
error = goodix_dev_confirm(ts);
707707
if (error)
708708
return error;
@@ -749,7 +749,7 @@ static int goodix_spi_set_power(struct goodix_ts_data *ts, int power_state)
749749
power_control_cmd[5] = power_state;
750750

751751
guard(mutex)(&ts->hid_request_lock);
752-
error = goodix_spi_write(ts, ts->hid_report_addr, power_control_cmd,
752+
error = goodix_spi_write(ts, GOODIX_HID_CMD_ADDR, power_control_cmd,
753753
sizeof(power_control_cmd));
754754
if (error) {
755755
dev_err(ts->dev, "failed set power mode: %s",
@@ -786,6 +786,14 @@ static const struct acpi_device_id goodix_spi_acpi_match[] = {
786786
MODULE_DEVICE_TABLE(acpi, goodix_spi_acpi_match);
787787
#endif
788788

789+
#ifdef CONFIG_OF
790+
static const struct of_device_id goodix_spi_of_match[] = {
791+
{ .compatible = "goodix,gt7986u-spifw", },
792+
{ }
793+
};
794+
MODULE_DEVICE_TABLE(of, goodix_spi_of_match);
795+
#endif
796+
789797
static const struct spi_device_id goodix_spi_ids[] = {
790798
{ "gt7986u" },
791799
{ },
@@ -796,6 +804,7 @@ static struct spi_driver goodix_spi_driver = {
796804
.driver = {
797805
.name = "goodix-spi-hid",
798806
.acpi_match_table = ACPI_PTR(goodix_spi_acpi_match),
807+
.of_match_table = of_match_ptr(goodix_spi_of_match),
799808
.pm = pm_sleep_ptr(&goodix_spi_pm_ops),
800809
},
801810
.probe = goodix_spi_probe,

0 commit comments

Comments
 (0)