drivers/input/rmi4/rmi_i2c.c
Source file repositories/reference/linux-study-clean/drivers/input/rmi4/rmi_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/rmi4/rmi_i2c.c- Extension
.c- Size
- 9555 bytes
- Lines
- 389
- 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/i2c.hlinux/rmi.hlinux/of.hlinux/delay.hlinux/regulator/consumer.hrmi_driver.h
Detected Declarations
struct rmi_i2c_xportfunction implementationsfunction rmi_i2c_write_blockfunction rmi_i2c_read_blockfunction rmi_i2c_regulator_bulk_disablefunction rmi_i2c_unregister_transportfunction rmi_i2c_probefunction rmi_i2c_suspendfunction rmi_i2c_resumefunction rmi_i2c_runtime_suspendfunction rmi_i2c_runtime_resume
Annotated Snippet
struct rmi_i2c_xport {
struct rmi_transport_dev xport;
struct i2c_client *client;
struct mutex page_mutex;
int page;
u8 *tx_buf;
size_t tx_buf_size;
struct regulator_bulk_data supplies[2];
u32 startup_delay;
};
#define RMI_PAGE_SELECT_REGISTER 0xff
#define RMI_I2C_PAGE(addr) (((addr) >> 8) & 0xff)
/*
* rmi_set_page - Set RMI page
* @xport: The pointer to the rmi_transport_dev struct
* @page: The new page address.
*
* RMI devices have 16-bit addressing, but some of the transport
* implementations (like SMBus) only have 8-bit addressing. So RMI implements
* a page address at 0xff of every page so we can reliable page addresses
* every 256 registers.
*
* The page_mutex lock must be held when this function is entered.
*
* Returns zero on success, non-zero on failure.
*/
static int rmi_set_page(struct rmi_i2c_xport *rmi_i2c, u8 page)
{
struct i2c_client *client = rmi_i2c->client;
u8 txbuf[2] = {RMI_PAGE_SELECT_REGISTER, page};
int retval;
retval = i2c_master_send(client, txbuf, sizeof(txbuf));
if (retval != sizeof(txbuf)) {
dev_err(&client->dev,
"%s: set page failed: %d.", __func__, retval);
return (retval < 0) ? retval : -EIO;
}
rmi_i2c->page = page;
return 0;
}
static int rmi_i2c_write_block(struct rmi_transport_dev *xport, u16 addr,
const void *buf, size_t len)
{
struct rmi_i2c_xport *rmi_i2c =
container_of(xport, struct rmi_i2c_xport, xport);
struct i2c_client *client = rmi_i2c->client;
size_t tx_size = len + 1;
int retval;
mutex_lock(&rmi_i2c->page_mutex);
if (!rmi_i2c->tx_buf || rmi_i2c->tx_buf_size < tx_size) {
if (rmi_i2c->tx_buf)
devm_kfree(&client->dev, rmi_i2c->tx_buf);
rmi_i2c->tx_buf_size = tx_size + BUFFER_SIZE_INCREMENT;
rmi_i2c->tx_buf = devm_kzalloc(&client->dev,
rmi_i2c->tx_buf_size,
GFP_KERNEL);
if (!rmi_i2c->tx_buf) {
rmi_i2c->tx_buf_size = 0;
retval = -ENOMEM;
goto exit;
}
}
rmi_i2c->tx_buf[0] = addr & 0xff;
memcpy(rmi_i2c->tx_buf + 1, buf, len);
if (RMI_I2C_PAGE(addr) != rmi_i2c->page) {
retval = rmi_set_page(rmi_i2c, RMI_I2C_PAGE(addr));
if (retval)
goto exit;
}
retval = i2c_master_send(client, rmi_i2c->tx_buf, tx_size);
if (retval == tx_size)
retval = 0;
else if (retval >= 0)
retval = -EIO;
exit:
rmi_dbg(RMI_DEBUG_XPORT, &client->dev,
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/rmi.h`, `linux/of.h`, `linux/delay.h`, `linux/regulator/consumer.h`, `rmi_driver.h`.
- Detected declarations: `struct rmi_i2c_xport`, `function implementations`, `function rmi_i2c_write_block`, `function rmi_i2c_read_block`, `function rmi_i2c_regulator_bulk_disable`, `function rmi_i2c_unregister_transport`, `function rmi_i2c_probe`, `function rmi_i2c_suspend`, `function rmi_i2c_resume`, `function rmi_i2c_runtime_suspend`.
- 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.