Re: [PATCH v2 3/3] Input: add driver for the Hycon HY46XX touchpanel series

2021-04-02 Thread Giulio Benetti

Hi Jonathan,

On 4/2/21 10:59 AM, Jonathan Neuschäfer wrote:

Hi,

a few remarks below.

On Fri, Apr 02, 2021 at 01:03:58AM +0200, Giulio Benetti wrote:

This patch adds support for Hycon HY46XX.

Signed-off-by: Giulio Benetti 
---
V1->V2:
* removed proximity-sensor-switch property according to previous patch
As suggested by Dmitry Torokhov
* moved i2c communaction to regmap use
* added macro to avoid magic number
* removed cmd variable that could uninitiliazed since we're using regmap now
* removed useless byte masking
* removed useless struct hycon_hy46xx_i2c_chip_data
* used IRQF_ONESHOT only for isr
---




+config TOUCHSCREEN_HYCON_HY46XX
+   tristate "Hycon hy46xx touchscreen support"
+   depends on I2C
+   help
+ Say Y here if you have a touchscreen using Hycon hy46xx,
+ or something similar enough.


The "something similar enough" part doesn't seem relevant, because the
driver only lists HY46xx chips (in the compatible strings), and no chips
that are similar enough to work with the driver, but have a different
part number.


Right


+static void hycon_hy46xx_get_defaults(struct device *dev, struct 
hycon_hy46xx_data *tsdata)
+{
+   bool val_bool;
+   int error;
+   u32 val;
+
+   error = device_property_read_u32(dev, "threshold", &val);


This seems to follow the old version of the binding, where
Hycon-specific properties didn't have the "hycon," prefix.
Please check that the driver still works with a devicetree that follows
the newest version of the binding.


Ah yes, I've forgotten it while changing in bindings.


+MODULE_AUTHOR("Giulio Benetti ");


This is a different email address than you used in the DT binding. If
this is intentional, no problem (Just letting you know, in case it's
unintentional).


I've missed that



Thanks,
Jonathan Neuschäfer



Thank you!
Best regards
--
Giulio Benetti
Benetti Engineering sas


Re: [PATCH v2 3/3] Input: add driver for the Hycon HY46XX touchpanel series

2021-04-02 Thread Jonathan Neuschäfer
Hi,

a few remarks below.

On Fri, Apr 02, 2021 at 01:03:58AM +0200, Giulio Benetti wrote:
> This patch adds support for Hycon HY46XX.
> 
> Signed-off-by: Giulio Benetti 
> ---
> V1->V2:
> * removed proximity-sensor-switch property according to previous patch
> As suggested by Dmitry Torokhov
> * moved i2c communaction to regmap use
> * added macro to avoid magic number
> * removed cmd variable that could uninitiliazed since we're using regmap now
> * removed useless byte masking
> * removed useless struct hycon_hy46xx_i2c_chip_data
> * used IRQF_ONESHOT only for isr
> ---


> +config TOUCHSCREEN_HYCON_HY46XX
> + tristate "Hycon hy46xx touchscreen support"
> + depends on I2C
> + help
> +   Say Y here if you have a touchscreen using Hycon hy46xx,
> +   or something similar enough.

The "something similar enough" part doesn't seem relevant, because the
driver only lists HY46xx chips (in the compatible strings), and no chips
that are similar enough to work with the driver, but have a different
part number.

> +static void hycon_hy46xx_get_defaults(struct device *dev, struct 
> hycon_hy46xx_data *tsdata)
> +{
> + bool val_bool;
> + int error;
> + u32 val;
> +
> + error = device_property_read_u32(dev, "threshold", &val);

This seems to follow the old version of the binding, where
Hycon-specific properties didn't have the "hycon," prefix.
Please check that the driver still works with a devicetree that follows
the newest version of the binding.

> +MODULE_AUTHOR("Giulio Benetti ");

This is a different email address than you used in the DT binding. If
this is intentional, no problem (Just letting you know, in case it's
unintentional).


Thanks,
Jonathan Neuschäfer


signature.asc
Description: PGP signature


[PATCH v2 3/3] Input: add driver for the Hycon HY46XX touchpanel series

2021-04-01 Thread Giulio Benetti
This patch adds support for Hycon HY46XX.

Signed-off-by: Giulio Benetti 
---
V1->V2:
* removed proximity-sensor-switch property according to previous patch
As suggested by Dmitry Torokhov
* moved i2c communaction to regmap use
* added macro to avoid magic number
* removed cmd variable that could uninitiliazed since we're using regmap now
* removed useless byte masking
* removed useless struct hycon_hy46xx_i2c_chip_data
* used IRQF_ONESHOT only for isr
---
 MAINTAINERS  |   1 +
 drivers/input/touchscreen/Kconfig|  12 +
 drivers/input/touchscreen/Makefile   |   1 +
 drivers/input/touchscreen/hycon-hy46xx.c | 591 +++
 4 files changed, 605 insertions(+)
 create mode 100644 drivers/input/touchscreen/hycon-hy46xx.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 5e9cc7e610ce..93f22de4b9ee 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8247,6 +8247,7 @@ M:Giulio Benetti 

 L: linux-in...@vger.kernel.org
 S: Maintained
 F: Documentation/devicetree/bindings/input/touchscreen/hycon,hy46xx.yaml
+F: drivers/input/touchscreen/hy46xx.c
 
 HYGON PROCESSOR SUPPORT
 M: Pu Wen 
diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
index 529614d364fe..5d4751d901cb 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -1335,4 +1335,16 @@ config TOUCHSCREEN_ZINITIX
  To compile this driver as a module, choose M here: the
  module will be called zinitix.
 
+config TOUCHSCREEN_HYCON_HY46XX
+   tristate "Hycon hy46xx touchscreen support"
+   depends on I2C
+   help
+ Say Y here if you have a touchscreen using Hycon hy46xx,
+ or something similar enough.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called hycon-hy46xx.
+
 endif
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
index 6233541e9173..8b68cf3a3e6d 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -112,3 +112,4 @@ obj-$(CONFIG_TOUCHSCREEN_ROHM_BU21023)  += 
rohm_bu21023.o
 obj-$(CONFIG_TOUCHSCREEN_RASPBERRYPI_FW)   += raspberrypi-ts.o
 obj-$(CONFIG_TOUCHSCREEN_IQS5XX)   += iqs5xx.o
 obj-$(CONFIG_TOUCHSCREEN_ZINITIX)  += zinitix.o
+obj-$(CONFIG_TOUCHSCREEN_HYCON_HY46XX) += hycon-hy46xx.o
diff --git a/drivers/input/touchscreen/hycon-hy46xx.c 
b/drivers/input/touchscreen/hycon-hy46xx.c
new file mode 100644
index ..42d7df86600d
--- /dev/null
+++ b/drivers/input/touchscreen/hycon-hy46xx.c
@@ -0,0 +1,591 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021
+ * Author(s): Giulio Benetti 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define HY46XX_CHKSUM_CODE 0x1
+#define HY46XX_FINGER_NUM  0x2
+#define HY46XX_CHKSUM_LEN  0x7
+#define HY46XX_THRESHOLD   0x80
+#define HY46XX_GLOVE_EN0x84
+#define HY46XX_REPORT_SPEED0x88
+#define HY46XX_PWR_NOISE_EN0x89
+#define HY46XX_FILTER_DATA 0x8A
+#define HY46XX_GAIN0x92
+#define HY46XX_EDGE_OFFSET 0x93
+#define HY46XX_RX_NR_USED  0x94
+#define HY46XX_TX_NR_USED  0x95
+#define HY46XX_PWR_MODE0xA5
+#define HY46XX_FW_VERSION  0xA6
+#define HY46XX_LIB_VERSION 0xA7
+#define HY46XX_TP_INFO 0xA8
+#define HY46XX_TP_CHIP_ID  0xA9
+#define HY46XX_BOOT_VER0xB0
+
+#define HY46XX_TPLEN   0x6
+#define HY46XX_REPORT_PKT_LEN  0x44
+
+#define HY46XX_MAX_SUPPORTED_POINTS11
+
+#define TOUCH_EVENT_DOWN   0x00
+#define TOUCH_EVENT_UP 0x01
+#define TOUCH_EVENT_CONTACT0x02
+#define TOUCH_EVENT_RESERVED   0x03
+
+struct hycon_hy46xx_data {
+   struct i2c_client *client;
+   struct input_dev *input;
+   struct touchscreen_properties prop;
+   struct regulator *vcc;
+
+   struct gpio_desc *reset_gpio;
+
+   struct mutex mutex;
+   struct regmap *regmap;
+
+   int threshold;
+   bool glove_enable;
+   int report_speed;
+   bool power_noise_enable;
+   int filter_data;
+   int gain;
+   int edge_offset;
+   int rx_number_used;
+   int tx_number_used;
+   int power_mode;
+   int fw_version;
+   int lib_version;
+   int tp_information;
+   int tp_chip_id;
+   int bootloader_version;
+};
+
+static const struct regmap_config hycon_hy46xx_i2c_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+};
+
+static bool hycon_hy46xx_check_checksum(struct hycon_hy46xx_data *tsdata, u8 
*buf)
+{
+   u8 chksum = 0;
+   int i;
+
+   for (i = 2; i < buf[HY46XX_CHKSUM_L