drivers/input/touchscreen/raspberrypi-ts.c
Source file repositories/reference/linux-study-clean/drivers/input/touchscreen/raspberrypi-ts.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/touchscreen/raspberrypi-ts.c- Extension
.c- Size
- 5738 bytes
- Lines
- 227
- Domain
- Driver Families
- Bucket
- drivers/input
- 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/io.hlinux/of.hlinux/slab.hlinux/device.hlinux/module.hlinux/bitops.hlinux/dma-mapping.hlinux/platform_device.hlinux/input.hlinux/input/mt.hlinux/input/touchscreen.hsoc/bcm2835/raspberrypi-firmware.h
Detected Declarations
struct rpi_tsstruct rpi_ts_regsstruct rpi_ts_touchfunction rpi_ts_pollfunction rpi_ts_dma_cleanupfunction rpi_ts_probe
Annotated Snippet
struct rpi_ts {
struct platform_device *pdev;
struct input_dev *input;
struct touchscreen_properties prop;
void __iomem *fw_regs_va;
dma_addr_t fw_regs_phys;
int known_ids;
};
struct rpi_ts_regs {
u8 device_mode;
u8 gesture_id;
u8 num_points;
struct rpi_ts_touch {
u8 xh;
u8 xl;
u8 yh;
u8 yl;
u8 pressure; /* Not supported */
u8 area; /* Not supported */
} point[RPI_TS_MAX_SUPPORTED_POINTS];
};
static void rpi_ts_poll(struct input_dev *input)
{
struct rpi_ts *ts = input_get_drvdata(input);
struct rpi_ts_regs regs;
int modified_ids = 0;
long released_ids;
int event_type;
int touchid;
int x, y;
int i;
memcpy_fromio(®s, ts->fw_regs_va, sizeof(regs));
/*
* We poll the memory based register copy of the touchscreen chip using
* the number of points register to know whether the copy has been
* updated (we write 99 to the memory copy, the GPU will write between
* 0 - 10 points)
*/
iowrite8(RPI_TS_NPOINTS_REG_INVALIDATE,
ts->fw_regs_va + offsetof(struct rpi_ts_regs, num_points));
if (regs.num_points == RPI_TS_NPOINTS_REG_INVALIDATE ||
(regs.num_points == 0 && ts->known_ids == 0))
return;
for (i = 0; i < regs.num_points; i++) {
x = (((int)regs.point[i].xh & 0xf) << 8) + regs.point[i].xl;
y = (((int)regs.point[i].yh & 0xf) << 8) + regs.point[i].yl;
touchid = (regs.point[i].yh >> 4) & 0xf;
event_type = (regs.point[i].xh >> 6) & 0x03;
modified_ids |= BIT(touchid);
if (event_type == RPI_TS_FTS_TOUCH_DOWN ||
event_type == RPI_TS_FTS_TOUCH_CONTACT) {
input_mt_slot(input, touchid);
input_mt_report_slot_state(input, MT_TOOL_FINGER, 1);
touchscreen_report_pos(input, &ts->prop, x, y, true);
}
}
released_ids = ts->known_ids & ~modified_ids;
for_each_set_bit(i, &released_ids, RPI_TS_MAX_SUPPORTED_POINTS) {
input_mt_slot(input, i);
input_mt_report_slot_inactive(input);
modified_ids &= ~(BIT(i));
}
ts->known_ids = modified_ids;
input_mt_sync_frame(input);
input_sync(input);
}
static void rpi_ts_dma_cleanup(void *data)
{
struct rpi_ts *ts = data;
struct device *dev = &ts->pdev->dev;
dma_free_coherent(dev, PAGE_SIZE, ts->fw_regs_va, ts->fw_regs_phys);
}
static int rpi_ts_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
Annotation
- Immediate include surface: `linux/io.h`, `linux/of.h`, `linux/slab.h`, `linux/device.h`, `linux/module.h`, `linux/bitops.h`, `linux/dma-mapping.h`, `linux/platform_device.h`.
- Detected declarations: `struct rpi_ts`, `struct rpi_ts_regs`, `struct rpi_ts_touch`, `function rpi_ts_poll`, `function rpi_ts_dma_cleanup`, `function rpi_ts_probe`.
- Atlas domain: Driver Families / drivers/input.
- 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.