drivers/hid/hid-goodix-spi.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-goodix-spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-goodix-spi.c- Extension
.c- Size
- 21679 bytes
- Lines
- 822
- Domain
- Driver Families
- Bucket
- drivers/hid
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/unaligned.hlinux/delay.hlinux/hid.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/of.hlinux/sizes.hlinux/spi/spi.h
Detected Declarations
struct goodix_hid_report_headerstruct goodix_hid_report_packagestruct goodix_hid_report_eventstruct goodix_hid_descstruct goodix_ts_datafunction goodix_spi_readfunction goodix_spi_writefunction goodix_dev_confirmfunction goodix_hid_parsefunction goodix_hid_get_report_lengthfunction goodix_hid_find_max_reportfunction list_for_each_entryfunction goodix_hid_startfunction goodix_hid_stopfunction goodix_hid_openfunction goodix_hid_closefunction goodix_hid_check_ack_statusfunction goodix_hid_get_raw_reportfunction goodix_hid_set_raw_reportfunction goodix_hid_raw_requestfunction goodix_hid_irqfunction goodix_hid_initfunction goodix_spi_probefunction goodix_spi_removefunction goodix_spi_set_powerfunction goodix_spi_suspendfunction goodix_spi_resume
Annotated Snippet
struct goodix_hid_report_header {
u8 flag;
__le16 size;
} __packed;
#define GOODIX_HID_ACK_HEADER_SIZE sizeof(struct goodix_hid_report_header)
struct goodix_hid_report_package {
__le16 size;
u8 data[];
};
#define GOODIX_HID_PKG_LEN_SIZE sizeof(u16)
#define GOODIX_HID_COOR_DATA_LEN 82
#define GOODIX_HID_COOR_PKG_LEN (GOODIX_HID_PKG_LEN_SIZE + \
GOODIX_HID_COOR_DATA_LEN)
/* power state */
#define GOODIX_SPI_POWER_ON 0x00
#define GOODIX_SPI_POWER_SLEEP 0x01
/* flags used to record the current device operating state */
#define GOODIX_HID_STARTED 0
struct goodix_hid_report_event {
struct goodix_hid_report_header hdr;
u8 data[GOODIX_HID_COOR_PKG_LEN];
} __packed;
struct goodix_hid_desc {
__le16 desc_length;
__le16 bcd_version;
__le16 report_desc_length;
__le16 report_desc_register;
__le16 input_register;
__le16 max_input_length;
__le16 output_register;
__le16 max_output_length;
__le16 cmd_register;
__le16 data_register;
__le16 vendor_id;
__le16 product_id;
__le16 version_id;
__le32 reserved;
} __packed;
struct goodix_ts_data {
struct device *dev;
struct spi_device *spi;
struct hid_device *hid;
struct goodix_hid_desc hid_desc;
struct gpio_desc *reset_gpio;
u32 hid_report_addr;
unsigned long flags;
/* lock for hid raw request operation */
struct mutex hid_request_lock;
/* buffer used to store hid report event */
u8 *event_buf;
u32 hid_max_event_sz;
/* buffer used to do spi data transfer */
u8 xfer_buf[SZ_2K] ____cacheline_aligned;
};
static void *goodix_get_event_report(struct goodix_ts_data *ts, u32 addr,
u8 *data, size_t len)
{
struct spi_device *spi = to_spi_device(&ts->spi->dev);
struct spi_transfer xfers;
struct spi_message spi_msg;
int error;
/* buffer format: 0xF1 + addr(4bytes) + dummy(3bytes) + data */
data[0] = GOODIX_SPI_READ_FLAG;
put_unaligned_be32(addr, data + GOODIX_SPI_TRANS_PREFIX_LEN);
spi_message_init(&spi_msg);
memset(&xfers, 0, sizeof(xfers));
xfers.tx_buf = data;
xfers.rx_buf = data;
xfers.len = GOODIX_SPI_READ_PREFIX_LEN + len;
spi_message_add_tail(&xfers, &spi_msg);
error = spi_sync(spi, &spi_msg);
if (error) {
dev_err(ts->dev, "spi transfer error: %d", error);
return NULL;
}
return data + GOODIX_SPI_READ_PREFIX_LEN;
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/delay.h`, `linux/hid.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/of.h`.
- Detected declarations: `struct goodix_hid_report_header`, `struct goodix_hid_report_package`, `struct goodix_hid_report_event`, `struct goodix_hid_desc`, `struct goodix_ts_data`, `function goodix_spi_read`, `function goodix_spi_write`, `function goodix_dev_confirm`, `function goodix_hid_parse`, `function goodix_hid_get_report_length`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.