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.

Dependency Surface

Detected Declarations

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

Implementation Notes