Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  qt2160.c - Atmel AT42QT2160 Touch Sense Controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2009 Raphael Derosso Pereira <raphaelpereira@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define QT2160_VALID_CHIPID  0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define QT2160_CMD_CHIPID     0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define QT2160_CMD_CODEVER    1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define QT2160_CMD_GSTAT      2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define QT2160_CMD_KEYS3      3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define QT2160_CMD_KEYS4      4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define QT2160_CMD_SLIDE      5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define QT2160_CMD_GPIOS      6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define QT2160_CMD_SUBVER     7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define QT2160_CMD_CALIBRATE  10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define QT2160_CMD_DRIVE_X    70
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define QT2160_CMD_PWMEN_X    74
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define QT2160_CMD_PWM_DUTY   76
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define QT2160_NUM_LEDS_X	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define QT2160_CYCLE_INTERVAL	(2*HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static unsigned char qt2160_key2code[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	KEY_0, KEY_1, KEY_2, KEY_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	KEY_4, KEY_5, KEY_6, KEY_7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	KEY_8, KEY_9, KEY_A, KEY_B,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	KEY_C, KEY_D, KEY_E, KEY_F,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #ifdef CONFIG_LEDS_CLASS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) struct qt2160_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct qt2160_data *qt2160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct led_classdev cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	char name[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	enum led_brightness brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) struct qt2160_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct delayed_work dwork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned short keycodes[ARRAY_SIZE(qt2160_key2code)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u16 key_matrix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #ifdef CONFIG_LEDS_CLASS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct qt2160_led leds[QT2160_NUM_LEDS_X];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int qt2160_read(struct i2c_client *client, u8 reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int qt2160_write(struct i2c_client *client, u8 reg, u8 data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #ifdef CONFIG_LEDS_CLASS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int qt2160_led_set(struct led_classdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			  enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct qt2160_led *led = container_of(cdev, struct qt2160_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct qt2160_data *qt2160 = led->qt2160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct i2c_client *client = qt2160->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u32 drive, pwmen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (value != led->brightness) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		drive = qt2160_read(client, QT2160_CMD_DRIVE_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		pwmen = qt2160_read(client, QT2160_CMD_PWMEN_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (value != LED_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			drive |= BIT(led->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			pwmen |= BIT(led->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			drive &= ~BIT(led->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			pwmen &= ~BIT(led->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		qt2160_write(client, QT2160_CMD_DRIVE_X, drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		qt2160_write(client, QT2160_CMD_PWMEN_X, pwmen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		 * Changing this register will change the brightness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		 * of every LED in the qt2160. It's a HW limitation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (value != LED_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			qt2160_write(client, QT2160_CMD_PWM_DUTY, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		led->brightness = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #endif /* CONFIG_LEDS_CLASS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int qt2160_read_block(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			     u8 inireg, u8 *buffer, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	int error, idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 * Can't use SMBus block data read. Check for I2C functionality to speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * things up whenever possible. Otherwise we will be forced to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * sequentially.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C))	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		error = i2c_smbus_write_byte(client, inireg + idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				"couldn't send request. Returned %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		error = i2c_master_recv(client, buffer, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (error != count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				"couldn't read registers. Returned %d bytes\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			int data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			error = i2c_smbus_write_byte(client, inireg + idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 					"couldn't send request. Returned %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			data = i2c_smbus_read_byte(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			if (data < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 					"couldn't read register. Returned %d\n", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			buffer[idx++] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int qt2160_get_key_matrix(struct qt2160_data *qt2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct i2c_client *client = qt2160->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct input_dev *input = qt2160->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	u8 regs[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	u16 old_matrix, new_matrix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int ret, i, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	dev_dbg(&client->dev, "requesting keys...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 * Read all registers from General Status Register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	 * to GPIOs register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ret = qt2160_read_block(client, QT2160_CMD_GSTAT, regs, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			"could not perform chip read.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	old_matrix = qt2160->key_matrix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	qt2160->key_matrix = new_matrix = (regs[2] << 8) | regs[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	mask = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	for (i = 0; i < 16; ++i, mask <<= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		int keyval = new_matrix & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if ((old_matrix & mask) != keyval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			input_report_key(input, qt2160->keycodes[i], keyval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			dev_dbg(&client->dev, "key %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 				i, keyval ? "pressed" : "released");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static irqreturn_t qt2160_irq(int irq, void *_qt2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct qt2160_data *qt2160 = _qt2160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	mod_delayed_work(system_wq, &qt2160->dwork, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void qt2160_schedule_read(struct qt2160_data *qt2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	schedule_delayed_work(&qt2160->dwork, QT2160_CYCLE_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void qt2160_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct qt2160_data *qt2160 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		container_of(work, struct qt2160_data, dwork.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	dev_dbg(&qt2160->client->dev, "worker\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	qt2160_get_key_matrix(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/* Avoid device lock up by checking every so often */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	qt2160_schedule_read(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int qt2160_read(struct i2c_client *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	ret = i2c_smbus_write_byte(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			"couldn't send request. Returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	ret = i2c_smbus_read_byte(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			"couldn't read register. Returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int qt2160_write(struct i2c_client *client, u8 reg, u8 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	ret = i2c_smbus_write_byte_data(client, reg, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			"couldn't write data. Returned %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #ifdef CONFIG_LEDS_CLASS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int qt2160_register_leds(struct qt2160_data *qt2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct i2c_client *client = qt2160->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	for (i = 0; i < QT2160_NUM_LEDS_X; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		struct qt2160_led *led = &qt2160->leds[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		snprintf(led->name, sizeof(led->name), "qt2160:x%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		led->cdev.name = led->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		led->cdev.brightness_set_blocking = qt2160_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		led->cdev.brightness = LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		led->id = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		led->qt2160 = qt2160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		ret = led_classdev_register(&client->dev, &led->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* Tur off LEDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	qt2160_write(client, QT2160_CMD_DRIVE_X, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	qt2160_write(client, QT2160_CMD_PWMEN_X, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	qt2160_write(client, QT2160_CMD_PWM_DUTY, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static void qt2160_unregister_leds(struct qt2160_data *qt2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	for (i = 0; i < QT2160_NUM_LEDS_X; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		led_classdev_unregister(&qt2160->leds[i].cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline int qt2160_register_leds(struct qt2160_data *qt2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static inline void qt2160_unregister_leds(struct qt2160_data *qt2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static bool qt2160_identify(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	int id, ver, rev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	/* Read Chid ID to check if chip is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	id = qt2160_read(client, QT2160_CMD_CHIPID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (id != QT2160_VALID_CHIPID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		dev_err(&client->dev, "ID %d not supported\n", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	/* Read chip firmware version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	ver = qt2160_read(client, QT2160_CMD_CODEVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (ver < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		dev_err(&client->dev, "could not get firmware version\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	/* Read chip firmware revision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	rev = qt2160_read(client, QT2160_CMD_SUBVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (rev < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		dev_err(&client->dev, "could not get firmware revision\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	dev_info(&client->dev, "AT42QT2160 firmware version %d.%d.%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			ver >> 4, ver & 0xf, rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int qt2160_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct qt2160_data *qt2160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	/* Check functionality */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	error = i2c_check_functionality(client->adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			I2C_FUNC_SMBUS_BYTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		dev_err(&client->dev, "%s adapter not supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				dev_driver_string(&client->adapter->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (!qt2160_identify(client))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	/* Chip is valid and active. Allocate structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	qt2160 = kzalloc(sizeof(struct qt2160_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	input = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (!qt2160 || !input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		dev_err(&client->dev, "insufficient memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	qt2160->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	qt2160->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	INIT_DELAYED_WORK(&qt2160->dwork, qt2160_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	input->name = "AT42QT2160 Touch Sense Keyboard";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	input->keycode = qt2160->keycodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	input->keycodesize = sizeof(qt2160->keycodes[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	input->keycodemax = ARRAY_SIZE(qt2160_key2code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	__set_bit(EV_KEY, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	__clear_bit(EV_REP, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	for (i = 0; i < ARRAY_SIZE(qt2160_key2code); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		qt2160->keycodes[i] = qt2160_key2code[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		__set_bit(qt2160_key2code[i], input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	__clear_bit(KEY_RESERVED, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	/* Calibrate device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	error = qt2160_write(client, QT2160_CMD_CALIBRATE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		dev_err(&client->dev, "failed to calibrate device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		error = request_irq(client->irq, qt2160_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				    IRQF_TRIGGER_FALLING, "qt2160", qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 				"failed to allocate irq %d\n", client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	error = qt2160_register_leds(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		dev_err(&client->dev, "Failed to register leds\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	error = input_register_device(qt2160->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			"Failed to register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		goto err_unregister_leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	i2c_set_clientdata(client, qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	qt2160_schedule_read(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) err_unregister_leds:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	qt2160_unregister_leds(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (client->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		free_irq(client->irq, qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	kfree(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static int qt2160_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	struct qt2160_data *qt2160 = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	qt2160_unregister_leds(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	/* Release IRQ so no queue will be scheduled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if (client->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		free_irq(client->irq, qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	cancel_delayed_work_sync(&qt2160->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	input_unregister_device(qt2160->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	kfree(qt2160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static const struct i2c_device_id qt2160_idtable[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	{ "qt2160", 0, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) MODULE_DEVICE_TABLE(i2c, qt2160_idtable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static struct i2c_driver qt2160_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		.name	= "qt2160",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	.id_table	= qt2160_idtable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	.probe		= qt2160_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	.remove		= qt2160_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) module_i2c_driver(qt2160_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) MODULE_AUTHOR("Raphael Derosso Pereira <raphaelpereira@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) MODULE_DESCRIPTION("Driver for AT42QT2160 Touch Sensor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) MODULE_LICENSE("GPL");