Skip to contentSkip to conversation

Input: add new touchpad driver for Zinitix IC

PATCH In review KwangDeok Son 2 participants 2 messages Nov 12, 2020 – Nov 13, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: add new touchpad driver for Zinitix IC

Add new touchpad driver for Zinitix IC Supports five fingers multi-touch and firmware updates. It communicates with the device via an I2C bus.

drivers/input/mouse/Kconfig +11 -0
index d8b6a5dab190..effd1b019b02 100644
@@ -457,4 +457,15 @@ config MOUSE_NAVPOINT_PXA27x
 	  To compile this driver as a module, choose M here: the
 	  module will be called navpoint.
 
+config MOUSE_ZINITIX_I2C
+	tristate "ZINITIX I2C Touchpad support"
+	depends on I2C
+	help
+	  This driver adds support for Zinitix I2C Touchpad.
+
+	  Say Y here if you have a Zinitix I2C Touchpad.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called zinitix_i2c.
+
 endif
drivers/input/mouse/Makefile +1 -0
index e49f08565076..b0329e21a079 100644
@@ -24,6 +24,7 @@ obj-$(CONFIG_MOUSE_SERIAL)		+= sermouse.o
 obj-$(CONFIG_MOUSE_SYNAPTICS_I2C)	+= synaptics_i2c.o
 obj-$(CONFIG_MOUSE_SYNAPTICS_USB)	+= synaptics_usb.o
 obj-$(CONFIG_MOUSE_VSXXXAA)		+= vsxxxaa.o
+obj-$(CONFIG_MOUSE_ZINITIX)		+= zinitix_i2c.o
 
 cyapatp-objs := cyapa.o cyapa_gen3.o cyapa_gen5.o cyapa_gen6.o
 psmouse-objs := psmouse-base.o synaptics.o focaltech.o
drivers/input/mouse/zinitix_i2c.c +1524 -0

1,524 lines not on this page · raw message

drivers/input/mouse/zinitix_i2c.h +255 -0

255 lines not on this page · raw message

maintainer
#1 lore raw

Hi KwangDeok,

Quoted 5 lines · KwangDeok Son

Add new touchpad driver for Zinitix IC Supports five fingers multi-touch and firmware updates. It communicates with the device via an I2C bus.

Please run the patch through ./scripts/checkpatch.pl and fix warnings from the tool.

Quoted 6 lines
drivers/input/mouse/zinitix_i2c.c +5 -0
@@ -0,0 +1,1524 @@
+/*
+ * Zinitics I2C Touchpad driver
+ *
+ * Copyright (c) 2020 ZINITIX Co.,Ltd
+ *

drivers/input/mouse/zinitix_i2c.c line 15

Quoted 10 lines
drivers/input/mouse/zinitix_i2c.c +10 -0
+ * Author: KwangDeok Son <[email protected]>
+ *
+ * Based on elan driver:
+ * Copyright (c) 2011-2013 ELAN Microelectronics Corp.
+ * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
+ * copyright (c) 2011-2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.

Please drop GPL notice, use SPDX tag instead.

drivers/input/mouse/zinitix_i2c.c line 26

Quoted 11 lines
drivers/input/mouse/zinitix_i2c.c +11 -0
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>

Please double-check that all includes are actually needed.

drivers/input/mouse/zinitix_i2c.c line 32

Quoted 6 lines
drivers/input/mouse/zinitix_i2c.c +6 -0
+#include <linux/input.h>
+#include <linux/uaccess.h>
+#include <linux/jiffies.h>
+#include <linux/completion.h>
+#include <linux/of.h>
+#include <asm/unaligned.h>

asm includes should go after linux ones.

drivers/input/mouse/zinitix_i2c.c line 41

Quoted 9 lines
drivers/input/mouse/zinitix_i2c.c +9 -0
+
+#include <linux/delay.h>
+#include <linux/firmware.h>
+#include <linux/i2c.h>
+#include <linux/input/mt.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/regulator/consumer.h>
+#include "zinitix_i2c.h"

We are not going to share any definitions with other modules, so put all the constants in this file and drop the .h one.

drivers/input/mouse/zinitix_i2c.c line 144

Quoted 4 lines
drivers/input/mouse/zinitix_i2c.c +4 -0
+int zinitix_i2c_write_reg(struct i2c_client *client, u16 reg, u16 value)
+{
+        int errno = 0;
+        u8 buf[22] = {0x80, 0x01, 0x14, 0x00, 0x06, 0x00, };

Please add a #define for 22 constant.

drivers/input/mouse/zinitix_i2c.c line 150

Quoted 6 lines
drivers/input/mouse/zinitix_i2c.c +6 -0
+
+	buf[6] = reg & 0xFF;
+	buf[7] = (reg>>8)&0xFF;
+	buf[8] = value & 0xFF;;
+	buf[9] = (value>>8)&0xFF;;
+		

We have cpu_to_le16 and put_unaligned_le16 for this.

Review line 52

Quoted 1 line
(quoted diff) +1 -0
+	errno = zinitix_i2c_write_buf(client, buf, 22);

sizeof(buf) instead of 22

drivers/input/mouse/zinitix_i2c.c line 164

Quoted 13 lines
drivers/input/mouse/zinitix_i2c.c +13 -0
+
+	return errno;
+}
+
+int zinitix_i2c_write_data(struct i2c_client *client, u16 reg, 
+                                const u8* value, u16 size)
+{
+        int errno = 0;
+        u8 buf[22] = {0x80, 0x01, 0x14, 0x00, 0x06, 0x00, };
+	buf[5] = size & 0xFF;
+	buf[6] = reg & 0xFF;
+	buf[7] = (reg>>8)&0xFF;
+	memcpy(&buf[8], value, size);

Need to make sure we are not overwriting the buffer.

drivers/input/mouse/zinitix_i2c.c line 178

Quoted 13 lines
drivers/input/mouse/zinitix_i2c.c +13 -0
+	errno = zinitix_i2c_write_buf(client, buf, 22);	
+
+	return errno;
+}
+
+int zinitix_i2c_write_fwdata(struct i2c_client *client, u16 reg, 
+                                const u8* value, u16 size)
+{
+        int errno = 0;
+        u8 buf[22] = {0x80, 0x01, 0x14, 0x00, 0x06, 0x00, };
+	buf[5] = size & 0xFF;
+	
+	memcpy(&buf[6], value, size);

Need to make sure we are not overwriting the buffer.

drivers/input/mouse/zinitix_i2c.c line 191

Quoted 13 lines
drivers/input/mouse/zinitix_i2c.c +13 -0
+	
+	errno = zinitix_i2c_write_buf(client, buf, 22);	
+	
+	return errno;
+}
+
+u16 zinitix_i2c_read_reg(struct i2c_client *client, u16 reg, u16* value)
+{
+	u16 retval = 0;
+	u8 outBuf[26] = {0x94, 0x1, 0x26, 0x3, 0x96, 0x1, 0x14, 0, 0x6, 0x1, };
+	u8 inBuf[8] = {0, };
+	
+	//Sample

I prefer C-style comments.

drivers/input/mouse/zinitix_i2c.c line 195

Quoted 4 lines
drivers/input/mouse/zinitix_i2c.c +4 -0
+	outBuf[10] = reg & 0xFF;
+	outBuf[11] = (reg>>8)&0xFF;
+	//Send
+	retval = (u16)zinitix_i2c_write_buf(client, outBuf, 26);

Error handling?

drivers/input/mouse/zinitix_i2c.c line 200

Quoted 5 lines
drivers/input/mouse/zinitix_i2c.c +5 -0
+	//Recv
+	outBuf[2] = 0x16;
+	outBuf[3] = 0x02;
+	retval = (u16)zinitix_i2c_read_buf(client, outBuf,6, inBuf, 8);
+	if (retval < 0) {

?? You are casing to u16 and then checking for negative value?

drivers/input/mouse/zinitix_i2c.c line 205

Quoted 5 lines
drivers/input/mouse/zinitix_i2c.c +5 -0
+		dev_err(&client->dev, "reading cmd (0x%04x) fail.\n", reg);
+		return retval;
+	}
+
+	*value = (inBuf[6]&0xFF) | ((inBuf[7]<<8)&0xFF00);

le16_to_cpup(). Elsewhere too.

drivers/input/mouse/zinitix_i2c.c line 279

Quoted 8 lines
drivers/input/mouse/zinitix_i2c.c +8 -0
+
+static int get_descriptor(struct i2c_client *client, u8* val)
+{
+        struct touchpad_data *data = i2c_get_clientdata(client);
+        int error;
+        //Get HID Descriptor
+        error = zinitix_i2c_read(client, ZINITIX_GET_DESC, 
+                                val, ZINITIX_DESC_LENGTH);

Is this truly HID descriptor? Is device compatible with I2C HID spec/Microsoft Precision point protocol? If so this driver is not needed at all and we can use i2c-hid + hid-multitouch to handle the device.

drivers/input/mouse/zinitix_i2c.c line 635

Quoted 13 lines
drivers/input/mouse/zinitix_i2c.c +13 -0
+
+const struct zinitix_transport_ops zinitix_i2c_ops = {
+	.initialize		= zinitix_i2c_initialize,
+	.sleep_control		= zinitix_sleep_control,
+	.reset		        = zinitix_reset,
+	.get_max		= zinitix_i2c_get_max,
+	.get_num_channel        = zinitix_i2c_get_num_channel,
+	.prepare_fw_update	= zinitix_i2c_prepare_fw_update,
+	.write_fw_block		= zinitix_i2c_write_fw_block,
+	.read_fw_block		= zinitix_i2c_read_fw_block,
+	.finish_fw_update	= zinitix_i2c_finish_fw_update,
+	.get_report		= zinitix_i2c_get_report,
+};

Are you planning on adding additional transports (such as SMB)? If not, then this indirection is not needed.

Thanks.

Signature · 1 line
Dmitry