diff mbox series

[v3,3/3] Input: Introduce goodix-i2c-hid as a subclass of i2c-hid

Message ID 20201102161210.v3.3.If41b7d621633b94d56653c6d53f5f89c5274de7b@changeid (mailing list archive)
State New, archived
Headers show
Series [v3,1/3] dt-bindings: HID: i2c-hid: Introduce bindings for the Goodix GT7375P | expand

Commit Message

Doug Anderson Nov. 3, 2020, 12:12 a.m. UTC
Goodix i2c-hid touchscreens are mostly i2c-hid compliant but have some
special power sequencing requirements, including the need to drive a
reset line during the sequencing.

Let's use the new ability of i2c-hid to have subclasses for power
sequencing to support the first Goodix i2c-hid touchscreen: GT7375P

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

Changes in v3:
- Rework to use subclassing.

 drivers/input/touchscreen/Kconfig          |  12 +++
 drivers/input/touchscreen/Makefile         |   1 +
 drivers/input/touchscreen/goodix-i2c-hid.c | 115 +++++++++++++++++++++
 3 files changed, 128 insertions(+)
 create mode 100644 drivers/input/touchscreen/goodix-i2c-hid.c

Comments

kernel test robot Nov. 10, 2020, 11:19 a.m. UTC | #1
Hi Douglas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on input/next]
[also build test WARNING on jikos-trivial/for-next linus/master v5.10-rc3 next-20201110]
[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/Douglas-Anderson/dt-bindings-HID-i2c-hid-Introduce-bindings-for-the-Goodix-GT7375P/20201103-081548
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: x86_64-randconfig-a016-20201110 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4d81c8adb6ed9840257f6cb6b93f60856d422a15)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/528ad0eceb01a39e733c337c44500abd49b7bc2a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Douglas-Anderson/dt-bindings-HID-i2c-hid-Introduce-bindings-for-the-Goodix-GT7375P/20201103-081548
        git checkout 528ad0eceb01a39e733c337c44500abd49b7bc2a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

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

All warnings (new ones prefixed by >>):

>> drivers/input/touchscreen/goodix-i2c-hid.c:90:34: warning: unused variable 'goodix_i2c_hid_of_match' [-Wunused-const-variable]
   static const struct of_device_id goodix_i2c_hid_of_match[] = {
                                    ^
   1 warning generated.

vim +/goodix_i2c_hid_of_match +90 drivers/input/touchscreen/goodix-i2c-hid.c

    89	
  > 90	static const struct of_device_id goodix_i2c_hid_of_match[] = {
    91		{ .compatible = "goodix,gt7375p", .data = &goodix_gt7375p_timing_data },
    92		{ }
    93	};
    94	MODULE_DEVICE_TABLE(of, goodix_i2c_hid_of_match);
    95	

---
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/Kconfig b/drivers/input/touchscreen/Kconfig
index f012fe746df0..64d481101917 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -403,6 +403,18 @@  config TOUCHSCREEN_GOODIX
 	  To compile this driver as a module, choose M here: the
 	  module will be called goodix.
 
+config TOUCHSCREEN_GOODIX_I2C_HID
+	tristate "Goodix I2C-HID touchscreen"
+	depends on I2C_HID
+	help
+	  Say Y here if you have a Goodix touchscreen that uses i2c-hid
+	  to communicate.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called goodix-i2c-hid.
+
 config TOUCHSCREEN_HIDEEP
 	tristate "HiDeep Touch IC"
 	depends on I2C
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 6233541e9173..32b1a768aa06 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -45,6 +45,7 @@  obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL)	+= egalax_ts_serial.o
 obj-$(CONFIG_TOUCHSCREEN_EXC3000)	+= exc3000.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)	+= fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX)	+= goodix.o
+obj-$(CONFIG_TOUCHSCREEN_GOODIX_I2C_HID)	+= goodix-i2c-hid.o
 obj-$(CONFIG_TOUCHSCREEN_HIDEEP)	+= hideep.o
 obj-$(CONFIG_TOUCHSCREEN_ILI210X)	+= ili210x.o
 obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC)	+= imx6ul_tsc.o
diff --git a/drivers/input/touchscreen/goodix-i2c-hid.c b/drivers/input/touchscreen/goodix-i2c-hid.c
new file mode 100644
index 000000000000..a2cc4f923d8a
--- /dev/null
+++ b/drivers/input/touchscreen/goodix-i2c-hid.c
@@ -0,0 +1,115 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for Goodix touchscreens that use the i2c-hid protocol.
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/input/i2c-hid-core.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_data/i2c-hid.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+
+struct goodix_i2c_hid_timing_data {
+	unsigned int post_gpio_reset_delay_ms;
+	unsigned int post_power_delay_ms;
+};
+
+static const struct goodix_i2c_hid_timing_data goodix_gt7375p_timing_data = {
+	.post_power_delay_ms = 10,
+	.post_gpio_reset_delay_ms = 120,
+};
+
+struct goodix_i2c_hid_plat_data {
+	struct gpio_desc *reset_gpio;
+	const struct goodix_i2c_hid_timing_data *timings;
+
+	struct i2c_hid_platform_data ihid_pdata;
+};
+
+static int goodix_i2c_hid_power_up_device(struct i2c_hid_platform_data *ihid_pdata)
+{
+	struct goodix_i2c_hid_plat_data *pdata = ihid_pdata->power_data;
+	int ret;
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(ihid_pdata->supplies),
+				    ihid_pdata->supplies);
+	if (ret)
+		return ret;
+
+	if (pdata->timings->post_power_delay_ms)
+		msleep(pdata->timings->post_power_delay_ms);
+
+	gpiod_set_value_cansleep(pdata->reset_gpio, 0);
+	if (pdata->timings->post_gpio_reset_delay_ms)
+		msleep(pdata->timings->post_gpio_reset_delay_ms);
+
+	return 0;
+}
+
+static void goodix_i2c_hid_power_down_device(struct i2c_hid_platform_data *ihid_pdata)
+{
+	struct goodix_i2c_hid_plat_data *pdata = ihid_pdata->power_data;
+
+	gpiod_set_value_cansleep(pdata->reset_gpio, 1);
+	regulator_bulk_disable(ARRAY_SIZE(ihid_pdata->supplies),
+			       ihid_pdata->supplies);
+}
+
+static int goodix_i2c_hid_ts_probe(struct i2c_client *client,
+				   const struct i2c_device_id *id)
+{
+	struct goodix_i2c_hid_plat_data *pdata;
+
+	pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
+
+	/* Start out with reset asserted */
+	pdata->reset_gpio =
+		devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(pdata->reset_gpio))
+		return PTR_ERR(pdata->reset_gpio);
+
+	pdata->timings = device_get_match_data(&client->dev);
+
+	pdata->ihid_pdata.hid_descriptor_address = 0x0001;
+	pdata->ihid_pdata.power_data = pdata;
+	pdata->ihid_pdata.power_up_device = goodix_i2c_hid_power_up_device;
+	pdata->ihid_pdata.power_down_device = goodix_i2c_hid_power_down_device;
+
+	client->dev.platform_data = &pdata->ihid_pdata;
+
+	return i2c_hid_probe(client, id);
+}
+
+static const struct of_device_id goodix_i2c_hid_of_match[] = {
+	{ .compatible = "goodix,gt7375p", .data = &goodix_gt7375p_timing_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, goodix_i2c_hid_of_match);
+
+static const struct dev_pm_ops goodix_i2c_hid_pm = {
+	SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume)
+};
+
+static struct i2c_driver goodix_i2c_hid_ts_driver = {
+	.driver = {
+		.name	= "goodix-i2c-hid",
+		.pm	= &goodix_i2c_hid_pm,
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+		.of_match_table = of_match_ptr(goodix_i2c_hid_of_match),
+	},
+	.probe		= goodix_i2c_hid_ts_probe,
+	.remove		= i2c_hid_remove,
+	.shutdown	= i2c_hid_shutdown,
+};
+module_i2c_driver(goodix_i2c_hid_ts_driver);
+
+MODULE_AUTHOR("Douglas Anderson <dianders@chromium.org>");
+MODULE_DESCRIPTION("Goodix i2c-hid touchscreen driver");
+MODULE_LICENSE("GPL v2");