drivers/input/rmi4/rmi_spi.c
Source file repositories/reference/linux-study-clean/drivers/input/rmi4/rmi_spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/rmi4/rmi_spi.c- Extension
.c- Size
- 12048 bytes
- Lines
- 529
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kernel.hlinux/module.hlinux/rmi.hlinux/slab.hlinux/spi/spi.hlinux/of.hrmi_driver.h
Detected Declarations
struct rmi_spi_cmdstruct rmi_spi_xportenum rmi_spi_opfunction rmi_spi_manage_poolsfunction rmi_spi_xferfunction implementationsfunction rmi_spi_write_blockfunction rmi_spi_read_blockfunction rmi_spi_of_probefunction rmi_spi_of_probefunction rmi_spi_unregister_transportfunction rmi_spi_probefunction rmi_spi_suspendfunction rmi_spi_resumefunction rmi_spi_runtime_suspendfunction rmi_spi_runtime_resume
Annotated Snippet
struct rmi_spi_cmd {
enum rmi_spi_op op;
u16 addr;
};
struct rmi_spi_xport {
struct rmi_transport_dev xport;
struct spi_device *spi;
struct mutex page_mutex;
int page;
u8 *rx_buf;
u8 *tx_buf;
int xfer_buf_size;
struct spi_transfer *rx_xfers;
struct spi_transfer *tx_xfers;
int rx_xfer_count;
int tx_xfer_count;
};
static int rmi_spi_manage_pools(struct rmi_spi_xport *rmi_spi, int len)
{
struct spi_device *spi = rmi_spi->spi;
int buf_size = rmi_spi->xfer_buf_size
? rmi_spi->xfer_buf_size : RMI_SPI_DEFAULT_XFER_BUF_SIZE;
struct spi_transfer *xfer_buf;
void *buf;
void *tmp;
while (buf_size < len)
buf_size *= 2;
if (buf_size > RMI_SPI_XFER_SIZE_LIMIT)
buf_size = RMI_SPI_XFER_SIZE_LIMIT;
tmp = rmi_spi->rx_buf;
buf = devm_kcalloc(&spi->dev, buf_size, 2,
GFP_KERNEL | GFP_DMA);
if (!buf)
return -ENOMEM;
rmi_spi->rx_buf = buf;
rmi_spi->tx_buf = &rmi_spi->rx_buf[buf_size];
rmi_spi->xfer_buf_size = buf_size;
if (tmp)
devm_kfree(&spi->dev, tmp);
if (rmi_spi->xport.pdata.spi_data.read_delay_us)
rmi_spi->rx_xfer_count = buf_size;
else
rmi_spi->rx_xfer_count = 1;
if (rmi_spi->xport.pdata.spi_data.write_delay_us)
rmi_spi->tx_xfer_count = buf_size;
else
rmi_spi->tx_xfer_count = 1;
/*
* Allocate a pool of spi_transfer buffers for devices which need
* per byte delays.
*/
tmp = rmi_spi->rx_xfers;
xfer_buf = devm_kcalloc(&spi->dev,
rmi_spi->rx_xfer_count + rmi_spi->tx_xfer_count,
sizeof(struct spi_transfer),
GFP_KERNEL);
if (!xfer_buf)
return -ENOMEM;
rmi_spi->rx_xfers = xfer_buf;
rmi_spi->tx_xfers = &xfer_buf[rmi_spi->rx_xfer_count];
if (tmp)
devm_kfree(&spi->dev, tmp);
return 0;
}
static int rmi_spi_xfer(struct rmi_spi_xport *rmi_spi,
const struct rmi_spi_cmd *cmd, const u8 *tx_buf,
int tx_len, u8 *rx_buf, int rx_len)
{
struct spi_device *spi = rmi_spi->spi;
struct rmi_device_platform_data_spi *spi_data =
&rmi_spi->xport.pdata.spi_data;
struct spi_message msg;
struct spi_transfer *xfer;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/rmi.h`, `linux/slab.h`, `linux/spi/spi.h`, `linux/of.h`, `rmi_driver.h`.
- Detected declarations: `struct rmi_spi_cmd`, `struct rmi_spi_xport`, `enum rmi_spi_op`, `function rmi_spi_manage_pools`, `function rmi_spi_xfer`, `function implementations`, `function rmi_spi_write_block`, `function rmi_spi_read_block`, `function rmi_spi_of_probe`, `function rmi_spi_of_probe`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.