drivers/input/keyboard/qt2160.c
Source file repositories/reference/linux-study-clean/drivers/input/keyboard/qt2160.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/keyboard/qt2160.c- Extension
.c- Size
- 9505 bytes
- Lines
- 416
- 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/kernel.hlinux/leds.hlinux/module.hlinux/slab.hlinux/jiffies.hlinux/i2c.hlinux/irq.hlinux/interrupt.hlinux/input.h
Detected Declarations
struct qt2160_ledstruct qt2160_datafunction qt2160_led_setfunction qt2160_read_blockfunction qt2160_get_key_matrixfunction qt2160_irqfunction qt2160_readfunction qt2160_writefunction qt2160_register_ledsfunction qt2160_register_ledsfunction qt2160_identifyfunction qt2160_probe
Annotated Snippet
struct qt2160_led {
struct qt2160_data *qt2160;
struct led_classdev cdev;
char name[32];
int id;
enum led_brightness brightness;
};
#endif
struct qt2160_data {
struct i2c_client *client;
struct input_dev *input;
unsigned short keycodes[ARRAY_SIZE(qt2160_key2code)];
u16 key_matrix;
#ifdef CONFIG_LEDS_CLASS
struct qt2160_led leds[QT2160_NUM_LEDS_X];
#endif
};
static int qt2160_read(struct i2c_client *client, u8 reg);
static int qt2160_write(struct i2c_client *client, u8 reg, u8 data);
#ifdef CONFIG_LEDS_CLASS
static int qt2160_led_set(struct led_classdev *cdev,
enum led_brightness value)
{
struct qt2160_led *led = container_of(cdev, struct qt2160_led, cdev);
struct qt2160_data *qt2160 = led->qt2160;
struct i2c_client *client = qt2160->client;
u32 drive, pwmen;
if (value != led->brightness) {
drive = qt2160_read(client, QT2160_CMD_DRIVE_X);
pwmen = qt2160_read(client, QT2160_CMD_PWMEN_X);
if (value != LED_OFF) {
drive |= BIT(led->id);
pwmen |= BIT(led->id);
} else {
drive &= ~BIT(led->id);
pwmen &= ~BIT(led->id);
}
qt2160_write(client, QT2160_CMD_DRIVE_X, drive);
qt2160_write(client, QT2160_CMD_PWMEN_X, pwmen);
/*
* Changing this register will change the brightness
* of every LED in the qt2160. It's a HW limitation.
*/
if (value != LED_OFF)
qt2160_write(client, QT2160_CMD_PWM_DUTY, value);
led->brightness = value;
}
return 0;
}
#endif /* CONFIG_LEDS_CLASS */
static int qt2160_read_block(struct i2c_client *client,
u8 inireg, u8 *buffer, unsigned int count)
{
int error, idx = 0;
/*
* Can't use SMBus block data read. Check for I2C functionality to speed
* things up whenever possible. Otherwise we will be forced to read
* sequentially.
*/
if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
error = i2c_smbus_write_byte(client, inireg + idx);
if (error) {
dev_err(&client->dev,
"couldn't send request. Returned %d\n", error);
return error;
}
error = i2c_master_recv(client, buffer, count);
if (error != count) {
dev_err(&client->dev,
"couldn't read registers. Returned %d bytes\n", error);
return error;
}
} else {
while (count--) {
int data;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/leds.h`, `linux/module.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/irq.h`, `linux/interrupt.h`.
- Detected declarations: `struct qt2160_led`, `struct qt2160_data`, `function qt2160_led_set`, `function qt2160_read_block`, `function qt2160_get_key_matrix`, `function qt2160_irq`, `function qt2160_read`, `function qt2160_write`, `function qt2160_register_leds`, `function qt2160_register_leds`.
- 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.