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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Wacom Penabled Driver for I2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2011 - 2013 Tatsunosuke Tobita, Wacom.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * <tobita.tatsunosuke@wacom.co.jp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This program is free software; you can redistribute it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * and/or modify it under the terms of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Public License as published by the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Foundation; either version of 2 of the License,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * or (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "tp_suspend.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) //#define	ORIGIN_COORD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static int exchange_x_y_flag 	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int revert_x_flag 		= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int revert_y_flag 		= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int screen_max_x = 20280;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int screen_max_y = 13942;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define WACOM_CMD_QUERY0	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define WACOM_CMD_QUERY1	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define WACOM_CMD_QUERY2	0x33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define WACOM_CMD_QUERY3	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define WACOM_CMD_THROW0	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define WACOM_CMD_THROW1	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define WACOM_QUERY_SIZE	19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) struct wacom_features {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	int x_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int y_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int pressure_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	char fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /*HID specific register*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define HID_DESC_REGISTER       1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define COMM_REG                0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define DATA_REG                0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) typedef struct hid_descriptor {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u16 wHIDDescLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u16 bcdVersion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u16 wReportDescLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u16 wReportDescRegister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u16 wInputRegister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u16 wMaxInputLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u16 wOutputRegister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	u16 wMaxOutputLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u16 wCommandRegister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u16 wDataRegister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u16 wVendorID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	u16 wProductID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u16 wVersion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u16 RESERVED_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	u16 RESERVED_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) } HID_DESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) struct wacom_i2c {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct wacom_features *features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u8 data[WACOM_QUERY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	bool prox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	int tool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct tp_device tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct regulator *supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int irq_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int pen_detect_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int get_hid_desc(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			      struct hid_descriptor *hid_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	char cmd[] = {HID_DESC_REGISTER, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct i2c_msg msgs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			.addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			.flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			.len = sizeof(cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			.buf = cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			.addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			.flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			.len = sizeof(HID_DESC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			.buf = (char *)hid_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (ret != ARRAY_SIZE(msgs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	printk("******************************\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	printk("wacom firmware vesrsion:0x%x\n", hid_desc->wVersion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	printk("******************************\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) //out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^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) static int wacom_query_device(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			      struct wacom_features *features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	u8 cmd1[] = { WACOM_CMD_QUERY0, WACOM_CMD_QUERY1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			WACOM_CMD_QUERY2, WACOM_CMD_QUERY3 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	u8 cmd2[] = { WACOM_CMD_THROW0, WACOM_CMD_THROW1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	u8 data[WACOM_QUERY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct i2c_msg msgs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			.addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			.flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			.len = sizeof(cmd1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			.buf = cmd1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			.addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			.flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			.len = sizeof(cmd2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			.buf = cmd2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			.addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			.flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			.len = sizeof(data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			.buf = 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) 	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (ret != ARRAY_SIZE(msgs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	features->x_max = get_unaligned_le16(&data[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	features->y_max = get_unaligned_le16(&data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	features->pressure_max = get_unaligned_le16(&data[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	features->fw_version = get_unaligned_le16(&data[13]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	printk("Wacom source screen x_max:%d, y_max:%d, pressure:%d, fw:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		features->x_max, features->y_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		features->pressure_max, features->fw_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (1 == exchange_x_y_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		swap(features->x_max, features->y_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	screen_max_x = features->x_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	screen_max_y = features->y_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	printk("Wacom desc screen x_max:%d, y_max:%d\n", features->x_max, features->y_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return 0;
^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) static irqreturn_t wacom_i2c_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct wacom_i2c *wac_i2c = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct input_dev *input = wac_i2c->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	//struct wacom_features *features = wac_i2c->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	u8 *data = wac_i2c->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	unsigned int x, y, pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned char tsw, f1, f2, ers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (device_can_wakeup(&wac_i2c->client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		pm_stay_awake(&wac_i2c->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	error = i2c_master_recv(wac_i2c->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				wac_i2c->data, sizeof(wac_i2c->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	tsw = data[3] & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	ers = data[3] & 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	f1 = data[3] & 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	f2 = data[3] & 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	x = le16_to_cpup((__le16 *)&data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	y = le16_to_cpup((__le16 *)&data[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	pressure = le16_to_cpup((__le16 *)&data[8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (!wac_i2c->prox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		wac_i2c->tool = (data[3] & 0x0c) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			BTN_TOOL_RUBBER : BTN_TOOL_PEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	wac_i2c->prox = data[3] & 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (1 == exchange_x_y_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		swap(x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (1 == revert_x_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		x = screen_max_x - x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (1 == revert_y_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		y = screen_max_y - y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	input_report_key(input, BTN_TOUCH, tsw || ers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	input_report_key(input, wac_i2c->tool, wac_i2c->prox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	input_report_key(input, BTN_STYLUS, f1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	input_report_key(input, BTN_STYLUS2, f2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	input_report_abs(input, ABS_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	input_report_abs(input, ABS_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	input_report_abs(input, ABS_PRESSURE, pressure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (device_can_wakeup(&wac_i2c->client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		pm_relax(&wac_i2c->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	return IRQ_HANDLED;
^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) static int wacom_i2c_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct wacom_i2c *wac_i2c = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct i2c_client *client = wac_i2c->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	enable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return 0;
^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 void wacom_i2c_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct wacom_i2c *wac_i2c = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct i2c_client *client = wac_i2c->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int __maybe_unused wacom_i2c_suspend(struct tp_device *tp_d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct wacom_i2c *wac_i2c = container_of(tp_d, struct wacom_i2c, tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	dev_dbg(&wac_i2c->client->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	disable_irq(wac_i2c->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (wac_i2c->supply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		gpio_direction_output(wac_i2c->irq_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		gpio_direction_output(wac_i2c->pen_detect_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		gpio_direction_output(wac_i2c->reset_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		regulator_disable(wac_i2c->supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int __maybe_unused wacom_i2c_resume(struct tp_device *tp_d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct wacom_i2c *wac_i2c = container_of(tp_d, struct wacom_i2c, tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	dev_dbg(&wac_i2c->client->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (wac_i2c->supply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		gpio_direction_input(wac_i2c->irq_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		gpio_direction_input(wac_i2c->pen_detect_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		gpio_direction_output(wac_i2c->reset_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		ret = regulator_enable(wac_i2c->supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			dev_err(&wac_i2c->client->dev, "failed to enable wacom power supply\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	enable_irq(wac_i2c->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int wacom_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 				     const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct wacom_i2c *wac_i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct wacom_features features = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	HID_DESC hid_desc = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	struct device_node *wac_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct regulator *power_supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	wac_np = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (!wac_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		dev_err(&client->dev, "get device node error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		dev_err(&client->dev, "i2c_check_functionality error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	of_property_read_u32(wac_np, "revert_x", &revert_x_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	of_property_read_u32(wac_np, "revert_y", &revert_y_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	of_property_read_u32(wac_np, "xy_exchange", &exchange_x_y_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	power_supply = devm_regulator_get(&client->dev, "pwr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (power_supply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		dev_info(&client->dev, "wacom power supply = %dmv\n", regulator_get_voltage(power_supply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		error = regulator_enable(power_supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			dev_err(&client->dev, "failed to enable wacom power supply\n");
^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) 	error = wacom_query_device(client, &features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	error = get_hid_desc(client, &hid_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	wac_i2c = kzalloc(sizeof(*wac_i2c), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	input = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (!wac_i2c || !input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (power_supply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		wac_i2c->supply = power_supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	wac_i2c->reset_gpio = of_get_named_gpio(wac_np, "gpio_rst", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (!gpio_is_valid(wac_i2c->reset_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		dev_err(&client->dev, "no gpio_rst pin available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	error = devm_gpio_request_one(&client->dev, wac_i2c->reset_gpio, GPIOF_OUT_INIT_LOW, "gpio-rst");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	gpio_direction_output(wac_i2c->reset_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	gpio_direction_output(wac_i2c->reset_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	wac_i2c->pen_detect_gpio = of_get_named_gpio(wac_np, "gpio_detect", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (!gpio_is_valid(wac_i2c->pen_detect_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		dev_err(&client->dev, "no pen_detect_gpio pin available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		goto err_free_reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	error = devm_gpio_request_one(&client->dev, wac_i2c->pen_detect_gpio, GPIOF_IN, "gpio_detect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		goto err_free_reset_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	wac_i2c->irq_gpio = of_get_named_gpio(wac_np, "gpio_intr", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (!gpio_is_valid(wac_i2c->irq_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		dev_err(&client->dev, "no gpio_intr pin available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		goto err_free_pen_detect_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	error = devm_gpio_request_one(&client->dev, wac_i2c->irq_gpio, GPIOF_IN, "gpio_intr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		goto err_free_pen_detect_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	client->irq = gpio_to_irq(wac_i2c->irq_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (client->irq < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		dev_err(&client->dev, "Unable to get irq number for GPIO %d, error %d\n", wac_i2c->irq_gpio, client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		goto err_free_irq_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	wac_i2c->features = &features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	wac_i2c->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	wac_i2c->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	input->name = "Wacom I2C Digitizer";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	input->id.vendor = 0x56a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	//input->id.version = features.fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	input->id.version = hid_desc.wVersion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	input->dev.parent = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	input->open = wacom_i2c_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	input->close = wacom_i2c_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	input->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	__set_bit(BTN_TOOL_PEN, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	__set_bit(BTN_TOOL_RUBBER, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	__set_bit(BTN_STYLUS, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	__set_bit(BTN_STYLUS2, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	__set_bit(BTN_TOUCH, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	__set_bit(INPUT_PROP_DIRECT, input->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	input_set_abs_params(input, ABS_X, 0, features.x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	input_set_abs_params(input, ABS_Y, 0, features.y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	input_set_abs_params(input, ABS_PRESSURE, 0, features.pressure_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	input_set_drvdata(input, wac_i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	error = request_threaded_irq(client->irq, NULL, wacom_i2c_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				     IRQF_TRIGGER_LOW | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 				     "wacom", wac_i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			"Failed to enable IRQ, error: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	/* Disable the IRQ, we'll enable it in wac_i2c_open() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	disable_irq(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	error = input_register_device(wac_i2c->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			"Failed to register input device, error: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	device_init_wakeup(&client->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	enable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	wac_i2c->tp.tp_resume = wacom_i2c_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	wac_i2c->tp.tp_suspend = wacom_i2c_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	tp_register_fb(&wac_i2c->tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	i2c_set_clientdata(client, wac_i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	free_irq(client->irq, wac_i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) err_free_reset_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) err_free_pen_detect_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) err_free_irq_gpio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	kfree(wac_i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static int wacom_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct wacom_i2c *wac_i2c = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	free_irq(client->irq, wac_i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	input_unregister_device(wac_i2c->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	kfree(wac_i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static const struct i2c_device_id wacom_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	{ "wacom", 0 },
^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) MODULE_DEVICE_TABLE(i2c, wacom_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static const struct of_device_id wacom_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		.compatible = "wacom,w9013",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		.data = (void *) &wacom_i2c_id[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		/* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) MODULE_DEVICE_TABLE(of, wacom_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static struct i2c_driver wacom_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		.name	= "wacom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		.owner	= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		.of_match_table = wacom_dt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	.probe		= wacom_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	.remove		= wacom_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	.id_table	= wacom_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static int __init wacom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	return i2c_add_driver(&wacom_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static void __exit wacom_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	i2c_del_driver(&wacom_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  * Module entry points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) subsys_initcall(wacom_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) //late_initcall(wacom_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) module_exit(wacom_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) //module_i2c_driver(wacom_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) MODULE_AUTHOR("Tatsunosuke Tobita <tobita.tatsunosuke@wacom.co.jp>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) MODULE_DESCRIPTION("WACOM EMR I2C Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) MODULE_LICENSE("GPL");