drivers/input/misc/kxtj9.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/kxtj9.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/kxtj9.c- Extension
.c- Size
- 12787 bytes
- Lines
- 549
- 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/delay.hlinux/i2c.hlinux/input.hlinux/interrupt.hlinux/module.hlinux/slab.hlinux/input/kxtj9.h
Detected Declarations
struct kxtj9_datafunction kxtj9_i2c_readfunction kxtj9_report_acceleration_datafunction kxtj9_isrfunction kxtj9_update_g_rangefunction kxtj9_update_odrfunction kxtj9_device_power_onfunction kxtj9_device_power_offfunction kxtj9_enablefunction kxtj9_disablefunction kxtj9_input_openfunction kxtj9_input_closefunction update_odrfunction kxtj9_set_pollfunction kxtj9_attr_is_visiblefunction kxtj9_pollfunction kxtj9_platform_exitfunction kxtj9_verifyfunction kxtj9_probefunction kxtj9_suspendfunction kxtj9_resume
Annotated Snippet
struct kxtj9_data {
struct i2c_client *client;
struct kxtj9_platform_data pdata;
struct input_dev *input_dev;
unsigned int last_poll_interval;
u8 shift;
u8 ctrl_reg1;
u8 data_ctrl;
u8 int_ctrl;
};
static int kxtj9_i2c_read(struct kxtj9_data *tj9, u8 addr, u8 *data, int len)
{
struct i2c_msg msgs[] = {
{
.addr = tj9->client->addr,
.flags = tj9->client->flags,
.len = 1,
.buf = &addr,
},
{
.addr = tj9->client->addr,
.flags = tj9->client->flags | I2C_M_RD,
.len = len,
.buf = data,
},
};
return i2c_transfer(tj9->client->adapter, msgs, 2);
}
static void kxtj9_report_acceleration_data(struct kxtj9_data *tj9)
{
s16 acc_data[3]; /* Data bytes from hardware xL, xH, yL, yH, zL, zH */
s16 x, y, z;
int err;
err = kxtj9_i2c_read(tj9, XOUT_L, (u8 *)acc_data, 6);
if (err < 0)
dev_err(&tj9->client->dev, "accelerometer data read failed\n");
x = le16_to_cpu(acc_data[tj9->pdata.axis_map_x]);
y = le16_to_cpu(acc_data[tj9->pdata.axis_map_y]);
z = le16_to_cpu(acc_data[tj9->pdata.axis_map_z]);
x >>= tj9->shift;
y >>= tj9->shift;
z >>= tj9->shift;
input_report_abs(tj9->input_dev, ABS_X, tj9->pdata.negate_x ? -x : x);
input_report_abs(tj9->input_dev, ABS_Y, tj9->pdata.negate_y ? -y : y);
input_report_abs(tj9->input_dev, ABS_Z, tj9->pdata.negate_z ? -z : z);
input_sync(tj9->input_dev);
}
static irqreturn_t kxtj9_isr(int irq, void *dev)
{
struct kxtj9_data *tj9 = dev;
int err;
/* data ready is the only possible interrupt type */
kxtj9_report_acceleration_data(tj9);
err = i2c_smbus_read_byte_data(tj9->client, INT_REL);
if (err < 0)
dev_err(&tj9->client->dev,
"error clearing interrupt status: %d\n", err);
return IRQ_HANDLED;
}
static int kxtj9_update_g_range(struct kxtj9_data *tj9, u8 new_g_range)
{
switch (new_g_range) {
case KXTJ9_G_2G:
tj9->shift = 4;
break;
case KXTJ9_G_4G:
tj9->shift = 3;
break;
case KXTJ9_G_8G:
tj9->shift = 2;
break;
default:
return -EINVAL;
}
tj9->ctrl_reg1 &= 0xe7;
tj9->ctrl_reg1 |= new_g_range;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/input.h`, `linux/interrupt.h`, `linux/module.h`, `linux/slab.h`, `linux/input/kxtj9.h`.
- Detected declarations: `struct kxtj9_data`, `function kxtj9_i2c_read`, `function kxtj9_report_acceleration_data`, `function kxtj9_isr`, `function kxtj9_update_g_range`, `function kxtj9_update_odr`, `function kxtj9_device_power_on`, `function kxtj9_device_power_off`, `function kxtj9_enable`, `function kxtj9_disable`.
- 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.