[PATCH v3 1/2] Input: synaptics-rmi4 - rename f30_data to gpio_data

2020-09-30 Thread Vincent Huang
f30_data in rmi_device_platform_data could be also referenced by RMI
function 3A, so rename it and the structure name to avoid confusion.

Signed-off-by: Vincent Huang 
Reviewed-by: Hans de Goede 
Tested-by: Hans de Goede 
---
 drivers/hid/hid-rmi.c   |  2 +-
 drivers/input/mouse/synaptics.c |  2 +-
 drivers/input/rmi4/rmi_f30.c| 14 +++---
 include/linux/rmi.h | 11 ++-
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
index 9ce22acdfaca..62315e31d520 100644
--- a/drivers/hid/hid-rmi.c
+++ b/drivers/hid/hid-rmi.c
@@ -722,7 +722,7 @@ static int rmi_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
}
 
if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS)
-   rmi_hid_pdata.f30_data.disable = true;
+   rmi_hid_pdata.gpio_data.disable = true;
 
data->xport.dev = hdev->dev.parent;
data->xport.pdata = rmi_hid_pdata;
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 4b81b2d0fe06..8a54efd6eb95 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -1752,7 +1752,7 @@ static int synaptics_create_intertouch(struct psmouse 
*psmouse,
.kernel_tracking = false,
.topbuttonpad = topbuttonpad,
},
-   .f30_data = {
+   .gpio_data = {
.buttonpad = SYN_CAP_CLICKPAD(info->ext_cap_0c),
.trackstick_buttons =
!!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10),
diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c
index a90dad1d9ac7..35045f161dc2 100644
--- a/drivers/input/rmi4/rmi_f30.c
+++ b/drivers/input/rmi4/rmi_f30.c
@@ -168,17 +168,17 @@ static int rmi_f30_config(struct rmi_function *fn)
rmi_get_platform_data(fn->rmi_dev);
int error;
 
-   /* can happen if f30_data.disable is set */
+   /* can happen if gpio_data.disable is set */
if (!f30)
return 0;
 
-   if (pdata->f30_data.trackstick_buttons) {
+   if (pdata->gpio_data.trackstick_buttons) {
/* Try [re-]establish link to F03. */
f30->f03 = rmi_find_function(fn->rmi_dev, 0x03);
f30->trackstick_buttons = f30->f03 != NULL;
}
 
-   if (pdata->f30_data.disable) {
+   if (pdata->gpio_data.disable) {
drv->clear_irq_bits(fn->rmi_dev, fn->irq_mask);
} else {
/* Write Control Register values back to device */
@@ -245,10 +245,10 @@ static int rmi_f30_map_gpios(struct rmi_function *fn,
if (!rmi_f30_is_valid_button(i, f30->ctrl))
continue;
 
-   if (pdata->f30_data.trackstick_buttons &&
+   if (pdata->gpio_data.trackstick_buttons &&
i >= TRACKSTICK_RANGE_START && i < TRACKSTICK_RANGE_END) {
f30->gpioled_key_map[i] = trackstick_button++;
-   } else if (!pdata->f30_data.buttonpad || !button_mapped) {
+   } else if (!pdata->gpio_data.buttonpad || !button_mapped) {
f30->gpioled_key_map[i] = button;
input_set_capability(input, EV_KEY, button++);
button_mapped = true;
@@ -264,7 +264,7 @@ static int rmi_f30_map_gpios(struct rmi_function *fn,
 * but I am not sure, so use only the pdata info and the number of
 * mapped buttons.
 */
-   if (pdata->f30_data.buttonpad || (button - BTN_LEFT == 1))
+   if (pdata->gpio_data.buttonpad || (button - BTN_LEFT == 1))
__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 
return 0;
@@ -372,7 +372,7 @@ static int rmi_f30_probe(struct rmi_function *fn)
struct f30_data *f30;
int error;
 
-   if (pdata->f30_data.disable)
+   if (pdata->gpio_data.disable)
return 0;
 
if (!drv_data->input) {
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index 7b22366d0065..00dda5381bf8 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -102,15 +102,16 @@ struct rmi_2d_sensor_platform_data {
 };
 
 /**
- * struct rmi_f30_data - overrides defaults for a single F30 GPIOs/LED chip.
+ * struct rmi_gpio_data - overrides defaults for a single F30/F3A GPIOs/LED
+ * chip.
  * @buttonpad - the touchpad is a buttonpad, so enable only the first actual
  * button that is found.
- * @trackstick_buttons - Set when the function 30 is handling the physical
+ * @trackstick_buttons - Set when the function 30 or 3a is handling the 
physical
  * buttons of the trackstick (as a PS/2 passthrough device).
- * @disable - the touchpad incorrectly reports F30 and it s

[PATCH v3 0/2] Add support for F3A

2020-09-30 Thread Vincent Huang
RMI4 F3A supports the touchpad GPIO function, it's designed to support
more GPIOs and used on newer touchpads. The patches add support of
touchpad buttons and rename f30_data to avoid confusion.

Changes in v2:
- Combined patch 1 and 2 of v1 to fix bisectability.

Changes in v3:
- Fix indentations pointed out by Lyude Paul.

Vincent Huang (2):
  Input: synaptics-rmi4 - rename f30_data to gpio_data
  Input: synaptics-rmi4 - add support for F3A

 drivers/hid/hid-rmi.c   |   2 +-
 drivers/input/mouse/synaptics.c |   2 +-
 drivers/input/rmi4/Kconfig  |   8 ++
 drivers/input/rmi4/Makefile |   1 +
 drivers/input/rmi4/rmi_bus.c|   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f30.c|  14 +-
 drivers/input/rmi4/rmi_f3a.c| 240 
 include/linux/rmi.h |  11 +-
 9 files changed, 268 insertions(+), 14 deletions(-)
 create mode 100644 drivers/input/rmi4/rmi_f3a.c

-- 
2.25.1



[PATCH v3 2/2] Input: synaptics-rmi4 - add support for F3A

2020-09-30 Thread Vincent Huang
RMI4 F3A supports the touchpad GPIO function, it's designed to
support more GPIOs and used on newer touchpads. This patch adds
support of the touchpad buttons.

Signed-off-by: Vincent Huang 
Reviewed-by: Hans de Goede 
Tested-by: Hans de Goede 
---
 drivers/input/rmi4/Kconfig  |   8 ++
 drivers/input/rmi4/Makefile |   1 +
 drivers/input/rmi4/rmi_bus.c|   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f3a.c| 240 
 5 files changed, 253 insertions(+)
 create mode 100644 drivers/input/rmi4/rmi_f3a.c

diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
index a212ff706f74..16119f760d11 100644
--- a/drivers/input/rmi4/Kconfig
+++ b/drivers/input/rmi4/Kconfig
@@ -100,6 +100,14 @@ config RMI4_F34
  device via the firmware loader interface. This is triggered using a
  sysfs attribute.
 
+config RMI4_F3A
+   bool "RMI4 Function 3A (GPIO)"
+   help
+ Say Y here if you want to add support for RMI4 function 3A.
+
+ Function 3A provides GPIO support for RMI4 devices. This includes
+ support for buttons on TouchPads and ClickPads.
+
 config RMI4_F54
bool "RMI4 Function 54 (Analog diagnostics)"
depends on VIDEO_V4L2=y || (RMI4_CORE=m && VIDEO_V4L2=m)
diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
index f17631656987..02f14c846861 100644
--- a/drivers/input/rmi4/Makefile
+++ b/drivers/input/rmi4/Makefile
@@ -10,6 +10,7 @@ rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
 rmi_core-$(CONFIG_RMI4_F34) += rmi_f34.o rmi_f34v7.o
+rmi_core-$(CONFIG_RMI4_F3A) += rmi_f3a.o
 rmi_core-$(CONFIG_RMI4_F54) += rmi_f54.o
 rmi_core-$(CONFIG_RMI4_F55) += rmi_f55.o
 
diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index af706a583656..47d1b97ed6cf 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -365,6 +365,9 @@ static struct rmi_function_handler *fn_handlers[] = {
 #ifdef CONFIG_RMI4_F34
&rmi_f34_handler,
 #endif
+#ifdef CONFIG_RMI4_F3A
+   &rmi_f3a_handler,
+#endif
 #ifdef CONFIG_RMI4_F54
&rmi_f54_handler,
 #endif
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index 65bfaa95e193..1c6c6086c0e5 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -135,6 +135,7 @@ extern struct rmi_function_handler rmi_f11_handler;
 extern struct rmi_function_handler rmi_f12_handler;
 extern struct rmi_function_handler rmi_f30_handler;
 extern struct rmi_function_handler rmi_f34_handler;
+extern struct rmi_function_handler rmi_f3a_handler;
 extern struct rmi_function_handler rmi_f54_handler;
 extern struct rmi_function_handler rmi_f55_handler;
 #endif
diff --git a/drivers/input/rmi4/rmi_f3a.c b/drivers/input/rmi4/rmi_f3a.c
new file mode 100644
index ..11ff35f811b0
--- /dev/null
+++ b/drivers/input/rmi4/rmi_f3a.c
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2012-2020 Synaptics Incorporated
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "rmi_driver.h"
+
+#define RMI_F3A_MAX_GPIO_COUNT 128
+#define RMI_F3A_MAX_REG_SIZE   DIV_ROUND_UP(RMI_F3A_MAX_GPIO_COUNT, 8)
+
+/* Defs for Query 0 */
+#define RMI_F3A_GPIO_COUNT 0x7F
+
+#define RMI_F3A_DATA_REGS_MAX_SIZE RMI_F3A_MAX_REG_SIZE
+
+#define TRACKSTICK_RANGE_START 3
+#define TRACKSTICK_RANGE_END   6
+
+struct f3a_data {
+   /* Query Data */
+   u8 gpio_count;
+
+   u8 register_count;
+
+   u8 data_regs[RMI_F3A_DATA_REGS_MAX_SIZE];
+   u16 *gpio_key_map;
+
+   struct input_dev *input;
+
+   struct rmi_function *f03;
+   bool trackstick_buttons;
+};
+
+static void rmi_f3a_report_button(struct rmi_function *fn,
+ struct f3a_data *f3a, unsigned int button)
+{
+   u16 key_code = f3a->gpio_key_map[button];
+   bool key_down = !(f3a->data_regs[0] & BIT(button));
+
+   if (f3a->trackstick_buttons &&
+   button >= TRACKSTICK_RANGE_START &&
+   button <= TRACKSTICK_RANGE_END) {
+   rmi_f03_overwrite_button(f3a->f03, key_code, key_down);
+   } else {
+   rmi_dbg(RMI_DEBUG_FN, &fn->dev,
+   "%s: call input report key (0x%04x) value (0x%02x)",
+   __func__, key_code, key_down);
+   input_report_key(f3a->input, key_code, key_down);
+   }
+}
+
+static irqreturn_t rmi_f3a_attention(int irq, void *ctx)
+{
+   struct rmi_function *fn = ctx;
+   struct f3a_data *f3a = dev_get_drvdata(&fn->dev);
+   struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev);
+   int error;
+   int i;
+
+   if (drvdata

[PATCH v2 1/2] Input: synaptics-rmi4 - rename f30_data to gpio_data

2020-09-27 Thread Vincent Huang
f30_data in rmi_device_platform_data could be also referenced by RMI
function 3A, so rename it and the structure name to avoid confusion.

Signed-off-by: Vincent Huang 
Reviewed-by: Hans de Goede 
Tested-by: Hans de Goede 
---
 drivers/hid/hid-rmi.c   |  2 +-
 drivers/input/mouse/synaptics.c |  2 +-
 drivers/input/rmi4/rmi_f30.c| 14 +++---
 include/linux/rmi.h | 11 ++-
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
index 9ce22acdfaca..62315e31d520 100644
--- a/drivers/hid/hid-rmi.c
+++ b/drivers/hid/hid-rmi.c
@@ -722,7 +722,7 @@ static int rmi_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
}
 
if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS)
-   rmi_hid_pdata.f30_data.disable = true;
+   rmi_hid_pdata.gpio_data.disable = true;
 
data->xport.dev = hdev->dev.parent;
data->xport.pdata = rmi_hid_pdata;
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 4b81b2d0fe06..8a54efd6eb95 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -1752,7 +1752,7 @@ static int synaptics_create_intertouch(struct psmouse 
*psmouse,
.kernel_tracking = false,
.topbuttonpad = topbuttonpad,
},
-   .f30_data = {
+   .gpio_data = {
.buttonpad = SYN_CAP_CLICKPAD(info->ext_cap_0c),
.trackstick_buttons =
!!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10),
diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c
index a90dad1d9ac7..35045f161dc2 100644
--- a/drivers/input/rmi4/rmi_f30.c
+++ b/drivers/input/rmi4/rmi_f30.c
@@ -168,17 +168,17 @@ static int rmi_f30_config(struct rmi_function *fn)
rmi_get_platform_data(fn->rmi_dev);
int error;
 
-   /* can happen if f30_data.disable is set */
+   /* can happen if gpio_data.disable is set */
if (!f30)
return 0;
 
-   if (pdata->f30_data.trackstick_buttons) {
+   if (pdata->gpio_data.trackstick_buttons) {
/* Try [re-]establish link to F03. */
f30->f03 = rmi_find_function(fn->rmi_dev, 0x03);
f30->trackstick_buttons = f30->f03 != NULL;
}
 
-   if (pdata->f30_data.disable) {
+   if (pdata->gpio_data.disable) {
drv->clear_irq_bits(fn->rmi_dev, fn->irq_mask);
} else {
/* Write Control Register values back to device */
@@ -245,10 +245,10 @@ static int rmi_f30_map_gpios(struct rmi_function *fn,
if (!rmi_f30_is_valid_button(i, f30->ctrl))
continue;
 
-   if (pdata->f30_data.trackstick_buttons &&
+   if (pdata->gpio_data.trackstick_buttons &&
i >= TRACKSTICK_RANGE_START && i < TRACKSTICK_RANGE_END) {
f30->gpioled_key_map[i] = trackstick_button++;
-   } else if (!pdata->f30_data.buttonpad || !button_mapped) {
+   } else if (!pdata->gpio_data.buttonpad || !button_mapped) {
f30->gpioled_key_map[i] = button;
input_set_capability(input, EV_KEY, button++);
button_mapped = true;
@@ -264,7 +264,7 @@ static int rmi_f30_map_gpios(struct rmi_function *fn,
 * but I am not sure, so use only the pdata info and the number of
 * mapped buttons.
 */
-   if (pdata->f30_data.buttonpad || (button - BTN_LEFT == 1))
+   if (pdata->gpio_data.buttonpad || (button - BTN_LEFT == 1))
__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 
return 0;
@@ -372,7 +372,7 @@ static int rmi_f30_probe(struct rmi_function *fn)
struct f30_data *f30;
int error;
 
-   if (pdata->f30_data.disable)
+   if (pdata->gpio_data.disable)
return 0;
 
if (!drv_data->input) {
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index 7b22366d0065..00dda5381bf8 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -102,15 +102,16 @@ struct rmi_2d_sensor_platform_data {
 };
 
 /**
- * struct rmi_f30_data - overrides defaults for a single F30 GPIOs/LED chip.
+ * struct rmi_gpio_data - overrides defaults for a single F30/F3A GPIOs/LED
+ * chip.
  * @buttonpad - the touchpad is a buttonpad, so enable only the first actual
  * button that is found.
- * @trackstick_buttons - Set when the function 30 is handling the physical
+ * @trackstick_buttons - Set when the function 30 or 3a is handling the 
physical
  * buttons of the trackstick (as a PS/2 passthrough device).
- * @disable - the touchpad incorrectly reports F30 and it s

[PATCH v2 2/2] Input: synaptics-rmi4 - add support for F3A

2020-09-27 Thread Vincent Huang
RMI4 F3A supports the touchpad GPIO function, it's designed to
support more GPIOs and used on newer touchpads. This patch adds
support of the touchpad buttons.

Signed-off-by: Vincent Huang 
Reviewed-by: Hans de Goede 
Tested-by: Hans de Goede 
---
 drivers/input/rmi4/Kconfig  |   8 ++
 drivers/input/rmi4/Makefile |   1 +
 drivers/input/rmi4/rmi_bus.c|   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f3a.c| 241 
 5 files changed, 254 insertions(+)
 create mode 100644 drivers/input/rmi4/rmi_f3a.c

diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
index a212ff706f74..16119f760d11 100644
--- a/drivers/input/rmi4/Kconfig
+++ b/drivers/input/rmi4/Kconfig
@@ -100,6 +100,14 @@ config RMI4_F34
  device via the firmware loader interface. This is triggered using a
  sysfs attribute.
 
+config RMI4_F3A
+   bool "RMI4 Function 3A (GPIO)"
+   help
+ Say Y here if you want to add support for RMI4 function 3A.
+
+ Function 3A provides GPIO support for RMI4 devices. This includes
+ support for buttons on TouchPads and ClickPads.
+
 config RMI4_F54
bool "RMI4 Function 54 (Analog diagnostics)"
depends on VIDEO_V4L2=y || (RMI4_CORE=m && VIDEO_V4L2=m)
diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
index f17631656987..02f14c846861 100644
--- a/drivers/input/rmi4/Makefile
+++ b/drivers/input/rmi4/Makefile
@@ -10,6 +10,7 @@ rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
 rmi_core-$(CONFIG_RMI4_F34) += rmi_f34.o rmi_f34v7.o
+rmi_core-$(CONFIG_RMI4_F3A) += rmi_f3a.o
 rmi_core-$(CONFIG_RMI4_F54) += rmi_f54.o
 rmi_core-$(CONFIG_RMI4_F55) += rmi_f55.o
 
diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index af706a583656..47d1b97ed6cf 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -365,6 +365,9 @@ static struct rmi_function_handler *fn_handlers[] = {
 #ifdef CONFIG_RMI4_F34
&rmi_f34_handler,
 #endif
+#ifdef CONFIG_RMI4_F3A
+   &rmi_f3a_handler,
+#endif
 #ifdef CONFIG_RMI4_F54
&rmi_f54_handler,
 #endif
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index 65bfaa95e193..1c6c6086c0e5 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -135,6 +135,7 @@ extern struct rmi_function_handler rmi_f11_handler;
 extern struct rmi_function_handler rmi_f12_handler;
 extern struct rmi_function_handler rmi_f30_handler;
 extern struct rmi_function_handler rmi_f34_handler;
+extern struct rmi_function_handler rmi_f3a_handler;
 extern struct rmi_function_handler rmi_f54_handler;
 extern struct rmi_function_handler rmi_f55_handler;
 #endif
diff --git a/drivers/input/rmi4/rmi_f3a.c b/drivers/input/rmi4/rmi_f3a.c
new file mode 100644
index ..be3c1ecc1181
--- /dev/null
+++ b/drivers/input/rmi4/rmi_f3a.c
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2012-2020 Synaptics Incorporated
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "rmi_driver.h"
+
+#define RMI_F3A_MAX_GPIO_COUNT 128
+#define RMI_F3A_MAX_REG_SIZE   DIV_ROUND_UP(RMI_F3A_MAX_GPIO_COUNT, 8)
+
+/* Defs for Query 0 */
+#define RMI_F3A_GPIO_COUNT 0x7F
+
+#define RMI_F3A_DATA_REGS_MAX_SIZE RMI_F3A_MAX_REG_SIZE
+
+#define TRACKSTICK_RANGE_START 3
+#define TRACKSTICK_RANGE_END   6
+
+struct f3a_data {
+   /* Query Data */
+   u8 gpio_count;
+
+   u8 register_count;
+
+   u8 data_regs[RMI_F3A_DATA_REGS_MAX_SIZE];
+   u16 *gpio_key_map;
+
+   struct input_dev *input;
+
+   struct rmi_function *f03;
+   bool trackstick_buttons;
+};
+
+static void rmi_f3a_report_button(struct rmi_function *fn,
+ struct f3a_data *f3a, unsigned int button)
+{
+   u16 key_code = f3a->gpio_key_map[button];
+   bool key_down = !(f3a->data_regs[0] & BIT(button));
+
+   if (f3a->trackstick_buttons &&
+   button >= TRACKSTICK_RANGE_START &&
+   button <= TRACKSTICK_RANGE_END) {
+   rmi_f03_overwrite_button(f3a->f03, key_code, key_down);
+   } else {
+   rmi_dbg(RMI_DEBUG_FN, &fn->dev,
+   "%s: call input report key (0x%04x) value (0x%02x)",
+   __func__, key_code, key_down);
+   input_report_key(f3a->input, key_code, key_down);
+   }
+}
+
+static irqreturn_t rmi_f3a_attention(int irq, void *ctx)
+{
+   struct rmi_function *fn = ctx;
+   struct f3a_data *f3a = dev_get_drvdata(&fn->dev);
+   struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev);
+   int error;
+   int i;
+
+   if (drvdata

[PATCH v2 0/2] Add support for F3A

2020-09-27 Thread Vincent Huang
RMI4 F3A supports the touchpad GPIO function, it's designed to support
more GPIOs and used on newer touchpads. The patches add support of
touchpad buttons and rename f30_data to avoid confusion.

Changes in v2:
- Combined patch 1 and 2 of v1 to fix bisectability.

Vincent Huang (2):
  Input: synaptics-rmi4 - rename f30_data to gpio_data
  Input: synaptics-rmi4 - add support for F3A

 drivers/hid/hid-rmi.c   |   2 +-
 drivers/input/mouse/synaptics.c |   2 +-
 drivers/input/rmi4/Kconfig  |   8 ++
 drivers/input/rmi4/Makefile |   1 +
 drivers/input/rmi4/rmi_bus.c|   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f30.c|  14 +-
 drivers/input/rmi4/rmi_f3a.c| 241 
 include/linux/rmi.h |  11 +-
 9 files changed, 269 insertions(+), 14 deletions(-)
 create mode 100644 drivers/input/rmi4/rmi_f3a.c

-- 
2.25.1



[PATCH 3/3] Input: synaptics-rmi4 - add support for F3A

2020-09-24 Thread Vincent Huang
RMI4 F3A supports the touchpad GPIO function, it's designed to
support more GPIOs and used on newer touchpads. This patch adds
support of the touchpad buttons.

Signed-off-by: Vincent Huang 
---
 drivers/input/rmi4/Kconfig  |   8 ++
 drivers/input/rmi4/Makefile |   1 +
 drivers/input/rmi4/rmi_bus.c|   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f3a.c| 241 
 5 files changed, 254 insertions(+)
 create mode 100644 drivers/input/rmi4/rmi_f3a.c

diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
index a212ff706f74..16119f760d11 100644
--- a/drivers/input/rmi4/Kconfig
+++ b/drivers/input/rmi4/Kconfig
@@ -100,6 +100,14 @@ config RMI4_F34
  device via the firmware loader interface. This is triggered using a
  sysfs attribute.
 
+config RMI4_F3A
+   bool "RMI4 Function 3A (GPIO)"
+   help
+ Say Y here if you want to add support for RMI4 function 3A.
+
+ Function 3A provides GPIO support for RMI4 devices. This includes
+ support for buttons on TouchPads and ClickPads.
+
 config RMI4_F54
bool "RMI4 Function 54 (Analog diagnostics)"
depends on VIDEO_V4L2=y || (RMI4_CORE=m && VIDEO_V4L2=m)
diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
index f17631656987..02f14c846861 100644
--- a/drivers/input/rmi4/Makefile
+++ b/drivers/input/rmi4/Makefile
@@ -10,6 +10,7 @@ rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
 rmi_core-$(CONFIG_RMI4_F34) += rmi_f34.o rmi_f34v7.o
+rmi_core-$(CONFIG_RMI4_F3A) += rmi_f3a.o
 rmi_core-$(CONFIG_RMI4_F54) += rmi_f54.o
 rmi_core-$(CONFIG_RMI4_F55) += rmi_f55.o
 
diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index af706a583656..47d1b97ed6cf 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -365,6 +365,9 @@ static struct rmi_function_handler *fn_handlers[] = {
 #ifdef CONFIG_RMI4_F34
&rmi_f34_handler,
 #endif
+#ifdef CONFIG_RMI4_F3A
+   &rmi_f3a_handler,
+#endif
 #ifdef CONFIG_RMI4_F54
&rmi_f54_handler,
 #endif
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index 65bfaa95e193..1c6c6086c0e5 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -135,6 +135,7 @@ extern struct rmi_function_handler rmi_f11_handler;
 extern struct rmi_function_handler rmi_f12_handler;
 extern struct rmi_function_handler rmi_f30_handler;
 extern struct rmi_function_handler rmi_f34_handler;
+extern struct rmi_function_handler rmi_f3a_handler;
 extern struct rmi_function_handler rmi_f54_handler;
 extern struct rmi_function_handler rmi_f55_handler;
 #endif
diff --git a/drivers/input/rmi4/rmi_f3a.c b/drivers/input/rmi4/rmi_f3a.c
new file mode 100644
index ..be3c1ecc1181
--- /dev/null
+++ b/drivers/input/rmi4/rmi_f3a.c
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2012-2020 Synaptics Incorporated
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "rmi_driver.h"
+
+#define RMI_F3A_MAX_GPIO_COUNT 128
+#define RMI_F3A_MAX_REG_SIZE   DIV_ROUND_UP(RMI_F3A_MAX_GPIO_COUNT, 8)
+
+/* Defs for Query 0 */
+#define RMI_F3A_GPIO_COUNT 0x7F
+
+#define RMI_F3A_DATA_REGS_MAX_SIZE RMI_F3A_MAX_REG_SIZE
+
+#define TRACKSTICK_RANGE_START 3
+#define TRACKSTICK_RANGE_END   6
+
+struct f3a_data {
+   /* Query Data */
+   u8 gpio_count;
+
+   u8 register_count;
+
+   u8 data_regs[RMI_F3A_DATA_REGS_MAX_SIZE];
+   u16 *gpio_key_map;
+
+   struct input_dev *input;
+
+   struct rmi_function *f03;
+   bool trackstick_buttons;
+};
+
+static void rmi_f3a_report_button(struct rmi_function *fn,
+ struct f3a_data *f3a, unsigned int button)
+{
+   u16 key_code = f3a->gpio_key_map[button];
+   bool key_down = !(f3a->data_regs[0] & BIT(button));
+
+   if (f3a->trackstick_buttons &&
+   button >= TRACKSTICK_RANGE_START &&
+   button <= TRACKSTICK_RANGE_END) {
+   rmi_f03_overwrite_button(f3a->f03, key_code, key_down);
+   } else {
+   rmi_dbg(RMI_DEBUG_FN, &fn->dev,
+   "%s: call input report key (0x%04x) value (0x%02x)",
+   __func__, key_code, key_down);
+   input_report_key(f3a->input, key_code, key_down);
+   }
+}
+
+static irqreturn_t rmi_f3a_attention(int irq, void *ctx)
+{
+   struct rmi_function *fn = ctx;
+   struct f3a_data *f3a = dev_get_drvdata(&fn->dev);
+   struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev);
+   int error;
+   int i;
+
+   if (drvdata->attn_data.data) {
+   if (drvdata->attn_data

[PATCH 1/3] Input: synaptics-rmi4 - rename f30_data to gpio_data

2020-09-24 Thread Vincent Huang
f30_data in rmi_device_platform_data could be also referenced by RMI
function 3A, so rename it and the structure name to avoid confusion.

Signed-off-by: Vincent Huang 
---
 drivers/input/mouse/synaptics.c |  2 +-
 drivers/input/rmi4/rmi_f30.c| 14 +++---
 include/linux/rmi.h | 11 ++-
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 4b81b2d0fe06..8a54efd6eb95 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -1752,7 +1752,7 @@ static int synaptics_create_intertouch(struct psmouse 
*psmouse,
.kernel_tracking = false,
.topbuttonpad = topbuttonpad,
},
-   .f30_data = {
+   .gpio_data = {
.buttonpad = SYN_CAP_CLICKPAD(info->ext_cap_0c),
.trackstick_buttons =
!!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10),
diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c
index a90dad1d9ac7..35045f161dc2 100644
--- a/drivers/input/rmi4/rmi_f30.c
+++ b/drivers/input/rmi4/rmi_f30.c
@@ -168,17 +168,17 @@ static int rmi_f30_config(struct rmi_function *fn)
rmi_get_platform_data(fn->rmi_dev);
int error;
 
-   /* can happen if f30_data.disable is set */
+   /* can happen if gpio_data.disable is set */
if (!f30)
return 0;
 
-   if (pdata->f30_data.trackstick_buttons) {
+   if (pdata->gpio_data.trackstick_buttons) {
/* Try [re-]establish link to F03. */
f30->f03 = rmi_find_function(fn->rmi_dev, 0x03);
f30->trackstick_buttons = f30->f03 != NULL;
}
 
-   if (pdata->f30_data.disable) {
+   if (pdata->gpio_data.disable) {
drv->clear_irq_bits(fn->rmi_dev, fn->irq_mask);
} else {
/* Write Control Register values back to device */
@@ -245,10 +245,10 @@ static int rmi_f30_map_gpios(struct rmi_function *fn,
if (!rmi_f30_is_valid_button(i, f30->ctrl))
continue;
 
-   if (pdata->f30_data.trackstick_buttons &&
+   if (pdata->gpio_data.trackstick_buttons &&
i >= TRACKSTICK_RANGE_START && i < TRACKSTICK_RANGE_END) {
f30->gpioled_key_map[i] = trackstick_button++;
-   } else if (!pdata->f30_data.buttonpad || !button_mapped) {
+   } else if (!pdata->gpio_data.buttonpad || !button_mapped) {
f30->gpioled_key_map[i] = button;
input_set_capability(input, EV_KEY, button++);
button_mapped = true;
@@ -264,7 +264,7 @@ static int rmi_f30_map_gpios(struct rmi_function *fn,
 * but I am not sure, so use only the pdata info and the number of
 * mapped buttons.
 */
-   if (pdata->f30_data.buttonpad || (button - BTN_LEFT == 1))
+   if (pdata->gpio_data.buttonpad || (button - BTN_LEFT == 1))
__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 
return 0;
@@ -372,7 +372,7 @@ static int rmi_f30_probe(struct rmi_function *fn)
struct f30_data *f30;
int error;
 
-   if (pdata->f30_data.disable)
+   if (pdata->gpio_data.disable)
return 0;
 
if (!drv_data->input) {
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index 7b22366d0065..00dda5381bf8 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -102,15 +102,16 @@ struct rmi_2d_sensor_platform_data {
 };
 
 /**
- * struct rmi_f30_data - overrides defaults for a single F30 GPIOs/LED chip.
+ * struct rmi_gpio_data - overrides defaults for a single F30/F3A GPIOs/LED
+ * chip.
  * @buttonpad - the touchpad is a buttonpad, so enable only the first actual
  * button that is found.
- * @trackstick_buttons - Set when the function 30 is handling the physical
+ * @trackstick_buttons - Set when the function 30 or 3a is handling the 
physical
  * buttons of the trackstick (as a PS/2 passthrough device).
- * @disable - the touchpad incorrectly reports F30 and it should be ignored.
+ * @disable - the touchpad incorrectly reports F30/F3A and it should be 
ignored.
  * This is a special case which is due to misconfigured firmware.
  */
-struct rmi_f30_data {
+struct rmi_gpio_data {
bool buttonpad;
bool trackstick_buttons;
bool disable;
@@ -218,7 +219,7 @@ struct rmi_device_platform_data {
/* function handler pdata */
struct rmi_2d_sensor_platform_data sensor_pdata;
struct rmi_f01_power_management power_management;
-   struct rmi_f30_data f30_data;
+   struct rmi_gpio_data gpio_data;
 };
 
 /**
-- 
2.25.1



[PATCH 0/3] Add support for F3A

2020-09-24 Thread Vincent Huang
RMI4 F3A supports the touchpad GPIO function, it's designed to support
more GPIOs and used on newer touchpads. The patches add support of
touchpad buttons and rename f30_data to avoid confusion.

Vincent Huang (3):
  Input: synaptics-rmi4 - rename f30_data to gpio_data
  HID: rmi - rename f30_data to gpio_data
  Input: synaptics-rmi4 - add support for F3A

 drivers/hid/hid-rmi.c   |   2 +-
 drivers/input/mouse/synaptics.c |   2 +-
 drivers/input/rmi4/Kconfig  |   8 ++
 drivers/input/rmi4/Makefile |   1 +
 drivers/input/rmi4/rmi_bus.c|   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f30.c|  14 +-
 drivers/input/rmi4/rmi_f3a.c| 241 
 include/linux/rmi.h |  11 +-
 9 files changed, 269 insertions(+), 14 deletions(-)
 create mode 100644 drivers/input/rmi4/rmi_f3a.c

-- 
2.25.1



[PATCH 2/3] HID: rmi - rename f30_data to gpio_data

2020-09-24 Thread Vincent Huang
f30_data in rmi_device_platform_data could be also referenced by RMI
function 3A, so rename it and the structure name to avoid confusion.

Signed-off-by: Vincent Huang 
---
 drivers/hid/hid-rmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
index 9ce22acdfaca..62315e31d520 100644
--- a/drivers/hid/hid-rmi.c
+++ b/drivers/hid/hid-rmi.c
@@ -722,7 +722,7 @@ static int rmi_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
}
 
if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS)
-   rmi_hid_pdata.f30_data.disable = true;
+   rmi_hid_pdata.gpio_data.disable = true;
 
data->xport.dev = hdev->dev.parent;
data->xport.pdata = rmi_hid_pdata;
-- 
2.25.1



[PATCH] Input: trackpoint - enable Synaptics trackpoints

2020-09-23 Thread Vincent Huang
Add Synaptics IDs in trackpoint_start_protocol() to mark them as valid.

Signed-off-by: Vincent Huang 
---
 drivers/input/mouse/trackpoint.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 854d5e758724..ef2fa0905208 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -282,6 +282,8 @@ static int trackpoint_start_protocol(struct psmouse 
*psmouse,
case TP_VARIANT_ALPS:
case TP_VARIANT_ELAN:
case TP_VARIANT_NXP:
+   case TP_VARIANT_JYT_SYNAPTICS:
+   case TP_VARIANT_SYNAPTICS:
if (variant_id)
*variant_id = param[0];
if (firmware_id)
-- 
2.25.1



Re: [PATCH 4.19 43/49] Input: trackpoint - add new trackpoint variant IDs

2020-09-23 Thread Vincent Huang



On 9/24/20 4:42 AM, Dmitry Torokhov wrote:

CAUTION: Email originated externally, do not click links or open attachments 
unless you recognize the sender and know the content is safe.


On Tue, Sep 22, 2020 at 10:24:03PM +0200, Pavel Machek wrote:

On Tue 2020-09-22 18:16:42, Greg Kroah-Hartman wrote:

On Tue, Sep 22, 2020 at 05:39:57PM +0200, Pavel Machek wrote:

Hi!


From: Vincent Huang 

commit 6c77545af100a72bf5e28142b510ba042a17648d upstream.

Add trackpoint variant IDs to allow supported control on Synaptics
trackpoints.

This just adds unused definitions. I don't think it is needed in
stable.

It add support for a new device.

No, it does not. Maybe in mainline there's followup patch that adds
such support, but that's not in 4.19.

es, indeed, there is a chunk missing, so this patch is incomplete. It
will not cause any issues if applied, so I'll leave it to Greg to decide
what to do with this.

Vincent, there needs to be a change in trackpoint_start_protocol() to
mark these new IDs as valid. Was it s3ent in a separate patch and I
missed it?


Hi Dmitry:

You are right, I think the code is missing in start_protocol(), I'll 
send one patch to complete it.



Thanks

Vincent



Thanks.

--
Dmitry


[PATCH v2] Input: trackpoint - add new trackpoint variant IDs

2020-09-14 Thread Vincent Huang
Add trackpoint variant IDs to allow supported control on Synaptics
trackpoints

Signed-off-by: Vincent Huang 
---
 drivers/input/mouse/trackpoint.c | 2 ++
 drivers/input/mouse/trackpoint.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 3eefee2ee2a1..dde4c9d8d6bc 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -21,6 +21,8 @@ static const char * const trackpoint_variants[] = {
[TP_VARIANT_ALPS]   = "ALPS",
[TP_VARIANT_ELAN]   = "Elan",
[TP_VARIANT_NXP]= "NXP",
+   [TP_VARIANT_JYT_SYNAPTICS]  = "JYT_Synaptics",
+   [TP_VARIANT_SYNAPTICS]  = "Synaptics",
 };
 
 /*
diff --git a/drivers/input/mouse/trackpoint.h b/drivers/input/mouse/trackpoint.h
index 5cb93ed26085..42eda7d4ba08 100644
--- a/drivers/input/mouse/trackpoint.h
+++ b/drivers/input/mouse/trackpoint.h
@@ -28,6 +28,8 @@
 #define TP_VARIANT_ALPS0x02
 #define TP_VARIANT_ELAN0x03
 #define TP_VARIANT_NXP 0x04
+#define TP_VARIANT_JYT_SYNAPTICS   0x05
+#define TP_VARIANT_SYNAPTICS   0x06
 
 /*
  * Commands
-- 
2.25.1



[PATCH] Input: trackpoint - add new trackpoint variant IDs

2020-09-09 Thread Vincent Huang
Add trackpoint variant IDs to allow supported control
on Synaptics trackpoints

Signed-off-by: Vincent Huang 
---
 drivers/input/mouse/trackpoint.c | 2 ++
 drivers/input/mouse/trackpoint.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 3eefee2ee2a1..c54d2f9e1c4a 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -21,6 +21,8 @@ static const char * const trackpoint_variants[] = {
[TP_VARIANT_ALPS]   = "ALPS",
[TP_VARIANT_ELAN]   = "Elan",
[TP_VARIANT_NXP]= "NXP",
+   [TP_VARIANT_JYT_SYNAPTICS]  = "JYT_SYNAPTICS",
+   [TP_VARIANT_SYNAPTICS]  = "SYNAPTICS",
 };
 
 /*
diff --git a/drivers/input/mouse/trackpoint.h b/drivers/input/mouse/trackpoint.h
index 5cb93ed26085..42eda7d4ba08 100644
--- a/drivers/input/mouse/trackpoint.h
+++ b/drivers/input/mouse/trackpoint.h
@@ -28,6 +28,8 @@
 #define TP_VARIANT_ALPS0x02
 #define TP_VARIANT_ELAN0x03
 #define TP_VARIANT_NXP 0x04
+#define TP_VARIANT_JYT_SYNAPTICS   0x05
+#define TP_VARIANT_SYNAPTICS   0x06
 
 /*
  * Commands
-- 
2.25.1