diff mbox series

[v2,6/6] input: zinitix: Add touchkey support

Message ID 20220105060323.7928-7-nikita@trvn.ru (mailing list archive)
State Superseded
Headers show
Series Add touch-keys support to the Zinitix touch driver | expand

Commit Message

Nikita Travkin Jan. 5, 2022, 6:03 a.m. UTC
Zinitix touch controllers can use some of the sense lines for virtual
keys (like those found on many phones). Add support for those keys.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
Changes in v2:
 - Add missing le16_to_cpu()
---
 drivers/input/touchscreen/zinitix.c | 61 +++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 3 deletions(-)

Comments

kernel test robot Jan. 5, 2022, 3:38 p.m. UTC | #1
Hi Nikita,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on dtor-input/next]
[also build test WARNING on robh/for-next hid/for-next linus/master v5.16-rc8 next-20220105]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Nikita-Travkin/Add-touch-keys-support-to-the-Zinitix-touch-driver/20220105-140610
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: powerpc-randconfig-s031-20220105 (https://download.01.org/0day-ci/archive/20220105/202201052355.c806rw3s-lkp@intel.com/config)
compiler: powerpc-linux-gcc (GCC) 11.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/0day-ci/linux/commit/545e0de93da58f29350c2908498a4621f5ef59e4
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Nikita-Travkin/Add-touch-keys-support-to-the-Zinitix-touch-driver/20220105-140610
        git checkout 545e0de93da58f29350c2908498a4621f5ef59e4
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=powerpc SHELL=/bin/bash drivers/ata/ drivers/input/touchscreen/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
>> drivers/input/touchscreen/zinitix.c:371:24: sparse: sparse: restricted __le16 degrades to integer

vim +371 drivers/input/touchscreen/zinitix.c

   352	
   353	static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
   354	{
   355		struct bt541_ts_data *bt541 = bt541_handler;
   356		struct i2c_client *client = bt541->client;
   357		struct touch_event touch_event;
   358		int error;
   359		int i;
   360		__le16 icon_events = 0;
   361	
   362		memset(&touch_event, 0, sizeof(struct touch_event));
   363	
   364		error = zinitix_read_data(bt541->client, BT541_POINT_STATUS_REG,
   365					  &touch_event, sizeof(struct touch_event));
   366		if (error) {
   367			dev_err(&client->dev, "Failed to read in touchpoint struct\n");
   368			goto out;
   369		}
   370	
 > 371		if (touch_event.status & BIT_ICON_EVENT) {
   372			error = zinitix_read_data(bt541->client, BT541_ICON_STATUS_REG,
   373						  &icon_events, sizeof(icon_events));
   374			if (error) {
   375				dev_err(&client->dev, "Failed to read icon events\n");
   376				goto out;
   377			}
   378	
   379			zinitix_report_keys(bt541, le16_to_cpu(icon_events));
   380		}
   381	
   382		for (i = 0; i < MAX_SUPPORTED_FINGER_NUM; i++)
   383			if (touch_event.point_coord[i].sub_status & SUB_BIT_EXIST)
   384				zinitix_report_finger(bt541, i,
   385						      &touch_event.point_coord[i]);
   386	
   387		input_mt_sync_frame(bt541->input_dev);
   388		input_sync(bt541->input_dev);
   389	
   390	out:
   391		zinitix_write_cmd(bt541->client, BT541_CLEAR_INT_STATUS_CMD);
   392		return IRQ_HANDLED;
   393	}
   394	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c
index 7c82c4f5fa6b..a1c2620507b4 100644
--- a/drivers/input/touchscreen/zinitix.c
+++ b/drivers/input/touchscreen/zinitix.c
@@ -119,6 +119,7 @@ 
 
 #define DEFAULT_TOUCH_POINT_MODE		2
 #define MAX_SUPPORTED_FINGER_NUM		5
+#define MAX_SUPPORTED_BUTTON_NUM		8
 
 #define CHIP_ON_DELAY				15 // ms
 #define FIRMWARE_ON_DELAY			40 // ms
@@ -146,6 +147,8 @@  struct bt541_ts_data {
 	struct touchscreen_properties prop;
 	struct regulator_bulk_data supplies[2];
 	u32 zinitix_mode;
+	u32 keycodes[MAX_SUPPORTED_BUTTON_NUM];
+	int num_keycodes;
 };
 
 static int zinitix_read_data(struct i2c_client *client,
@@ -195,6 +198,7 @@  static int zinitix_init_touch(struct bt541_ts_data *bt541)
 	struct i2c_client *client = bt541->client;
 	int i;
 	int error;
+	u16 int_flags = 0;
 
 	error = zinitix_write_cmd(client, BT541_SWRESET_CMD);
 	if (error) {
@@ -225,6 +229,11 @@  static int zinitix_init_touch(struct bt541_ts_data *bt541)
 	if (error)
 		return error;
 
+	error = zinitix_write_u16(client, BT541_BUTTON_SUPPORTED_NUM,
+				  bt541->num_keycodes);
+	if (error)
+		return error;
+
 	error = zinitix_write_u16(client, BT541_INITIAL_TOUCH_MODE,
 				  bt541->zinitix_mode);
 	if (error)
@@ -235,9 +244,12 @@  static int zinitix_init_touch(struct bt541_ts_data *bt541)
 	if (error)
 		return error;
 
-	error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG,
-				  BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE |
-					BIT_UP);
+	int_flags = BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE | BIT_UP;
+
+	if (bt541->num_keycodes)
+		int_flags |= BIT_ICON_EVENT;
+
+	error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG, int_flags);
 	if (error)
 		return error;
 
@@ -329,6 +341,15 @@  static void zinitix_report_finger(struct bt541_ts_data *bt541, int slot,
 	input_report_abs(bt541->input_dev, ABS_MT_TOUCH_MAJOR, p->width);
 }
 
+static void zinitix_report_keys(struct bt541_ts_data *bt541, u16 icon_events)
+{
+	int i;
+
+	for (i = 0; i < bt541->num_keycodes; i++)
+		input_report_key(bt541->input_dev,
+				 bt541->keycodes[i], !!(icon_events & BIT(i)));
+}
+
 static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
 {
 	struct bt541_ts_data *bt541 = bt541_handler;
@@ -336,6 +357,7 @@  static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
 	struct touch_event touch_event;
 	int error;
 	int i;
+	__le16 icon_events = 0;
 
 	memset(&touch_event, 0, sizeof(struct touch_event));
 
@@ -346,6 +368,17 @@  static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
 		goto out;
 	}
 
+	if (touch_event.status & BIT_ICON_EVENT) {
+		error = zinitix_read_data(bt541->client, BT541_ICON_STATUS_REG,
+					  &icon_events, sizeof(icon_events));
+		if (error) {
+			dev_err(&client->dev, "Failed to read icon events\n");
+			goto out;
+		}
+
+		zinitix_report_keys(bt541, le16_to_cpu(icon_events));
+	}
+
 	for (i = 0; i < MAX_SUPPORTED_FINGER_NUM; i++)
 		if (touch_event.point_coord[i].sub_status & SUB_BIT_EXIST)
 			zinitix_report_finger(bt541, i,
@@ -427,6 +460,7 @@  static int zinitix_init_input_dev(struct bt541_ts_data *bt541)
 {
 	struct input_dev *input_dev;
 	int error;
+	int i;
 
 	input_dev = devm_input_allocate_device(&bt541->client->dev);
 	if (!input_dev) {
@@ -444,6 +478,14 @@  static int zinitix_init_input_dev(struct bt541_ts_data *bt541)
 	input_dev->open = zinitix_input_open;
 	input_dev->close = zinitix_input_close;
 
+	if (bt541->num_keycodes) {
+		input_dev->keycode = bt541->keycodes;
+		input_dev->keycodemax = bt541->num_keycodes;
+		input_dev->keycodesize = sizeof(bt541->keycodes[0]);
+		for (i = 0; i < bt541->num_keycodes; i++)
+			input_set_capability(input_dev, EV_KEY, bt541->keycodes[i]);
+	}
+
 	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
 	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
 	input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
@@ -508,6 +550,19 @@  static int zinitix_ts_probe(struct i2c_client *client)
 		return error;
 	}
 
+	bt541->num_keycodes = of_property_read_variable_u32_array(
+					client->dev.of_node, "linux,keycodes",
+					bt541->keycodes, 0,
+					ARRAY_SIZE(bt541->keycodes));
+	if (bt541->num_keycodes == -EINVAL) {
+		bt541->num_keycodes = 0;
+	} else if (bt541->num_keycodes < 0) {
+		dev_err(&client->dev,
+			"Unable to parse \"linux,keycodes\" property: %d\n",
+			bt541->num_keycodes);
+		return bt541->num_keycodes;
+	}
+
 	error = zinitix_init_input_dev(bt541);
 	if (error) {
 		dev_err(&client->dev,