ignatenkobrain / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
e336be
From 0a74d0f27e8d60e427b447a041bc061917d85fac Mon Sep 17 00:00:00 2001
e336be
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
e336be
Date: Mon, 3 Apr 2017 18:18:21 +0200
e336be
Subject: [PATCH] Input: rmi4 - remove the need for artificial IRQ in case of
e336be
 HID
e336be
e336be
The IRQ from rmi4 may interfere with the one we currently use on i2c-hid.
e336be
Given that there is already a need for an external API from rmi4 to
e336be
forward the attention data, we can, in this particular case rely on a
e336be
separate workqueue to prevent cursor jumps.
e336be
e336be
Reported-by: Cameron Gutman <aicommander@gmail.com>
e336be
Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
e336be
Reported-by: Jason Ekstrand <jason@jlekstrand.net>
e336be
Tested-by: Andrew Duggan <aduggan@synaptics.com>
e336be
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
e336be
Signed-off-by: Lyude <lyude@redhat.com>
e336be
---
e336be
 drivers/hid/hid-rmi.c           |  64 -----------------
e336be
 drivers/input/rmi4/rmi_driver.c | 124 +++++++++++++++++++-------------
e336be
 include/linux/rmi.h             |   1 +
e336be
 3 files changed, 75 insertions(+), 114 deletions(-)
e336be
e336be
diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
e336be
index 9e33165250a3..e7e33a160b47 100644
e336be
--- a/drivers/hid/hid-rmi.c
e336be
+++ b/drivers/hid/hid-rmi.c
e336be
@@ -316,19 +316,12 @@ static int rmi_input_event(struct hid_device *hdev, u8 *data, int size)
e336be
 {
e336be
 	struct rmi_data *hdata = hid_get_drvdata(hdev);
e336be
 	struct rmi_device *rmi_dev = hdata->xport.rmi_dev;
e336be
-	unsigned long flags;
e336be
 
e336be
 	if (!(test_bit(RMI_STARTED, &hdata->flags)))
e336be
 		return 0;
e336be
 
e336be
-	local_irq_save(flags);
e336be
-
e336be
 	rmi_set_attn_data(rmi_dev, data[1], &data[2], size - 2);
e336be
 
e336be
-	generic_handle_irq(hdata->rmi_irq);
e336be
-
e336be
-	local_irq_restore(flags);
e336be
-
e336be
 	return 1;
e336be
 }
e336be
 
e336be
@@ -586,56 +579,6 @@ static const struct rmi_transport_ops hid_rmi_ops = {
e336be
 	.reset		= rmi_hid_reset,
e336be
 };
e336be
 
e336be
-static void rmi_irq_teardown(void *data)
e336be
-{
e336be
-	struct rmi_data *hdata = data;
e336be
-	struct irq_domain *domain = hdata->domain;
e336be
-
e336be
-	if (!domain)
e336be
-		return;
e336be
-
e336be
-	irq_dispose_mapping(irq_find_mapping(domain, 0));
e336be
-
e336be
-	irq_domain_remove(domain);
e336be
-	hdata->domain = NULL;
e336be
-	hdata->rmi_irq = 0;
e336be
-}
e336be
-
e336be
-static int rmi_irq_map(struct irq_domain *h, unsigned int virq,
e336be
-		       irq_hw_number_t hw_irq_num)
e336be
-{
e336be
-	irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq);
e336be
-
e336be
-	return 0;
e336be
-}
e336be
-
e336be
-static const struct irq_domain_ops rmi_irq_ops = {
e336be
-	.map = rmi_irq_map,
e336be
-};
e336be
-
e336be
-static int rmi_setup_irq_domain(struct hid_device *hdev)
e336be
-{
e336be
-	struct rmi_data *hdata = hid_get_drvdata(hdev);
e336be
-	int ret;
e336be
-
e336be
-	hdata->domain = irq_domain_create_linear(hdev->dev.fwnode, 1,
e336be
-						 &rmi_irq_ops, hdata);
e336be
-	if (!hdata->domain)
e336be
-		return -ENOMEM;
e336be
-
e336be
-	ret = devm_add_action_or_reset(&hdev->dev, &rmi_irq_teardown, hdata);
e336be
-	if (ret)
e336be
-		return ret;
e336be
-
e336be
-	hdata->rmi_irq = irq_create_mapping(hdata->domain, 0);
e336be
-	if (hdata->rmi_irq <= 0) {
e336be
-		hid_err(hdev, "Can't allocate an IRQ\n");
e336be
-		return hdata->rmi_irq < 0 ? hdata->rmi_irq : -ENXIO;
e336be
-	}
e336be
-
e336be
-	return 0;
e336be
-}
e336be
-
e336be
 static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
e336be
 {
e336be
 	struct rmi_data *data = NULL;
e336be
@@ -708,18 +651,11 @@ static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
e336be
 
e336be
 	mutex_init(&data->page_mutex);
e336be
 
e336be
-	ret = rmi_setup_irq_domain(hdev);
e336be
-	if (ret) {
e336be
-		hid_err(hdev, "failed to allocate IRQ domain\n");
e336be
-		return ret;
e336be
-	}
e336be
-
e336be
 	if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS)
e336be
 		rmi_hid_pdata.f30_data.disable = true;
e336be
 
e336be
 	data->xport.dev = hdev->dev.parent;
e336be
 	data->xport.pdata = rmi_hid_pdata;
e336be
-	data->xport.pdata.irq = data->rmi_irq;
e336be
 	data->xport.proto_name = "hid";
e336be
 	data->xport.ops = &hid_rmi_ops;
e336be
 
e336be
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
e336be
index fc3ab93b7aea..35bc90141db8 100644
e336be
--- a/drivers/input/rmi4/rmi_driver.c
e336be
+++ b/drivers/input/rmi4/rmi_driver.c
e336be
@@ -185,34 +185,47 @@ void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
e336be
 	attn_data.data = fifo_data;
e336be
 
e336be
 	kfifo_put(&drvdata->attn_fifo, attn_data);
e336be
+
e336be
+	schedule_work(&drvdata->attn_work);
e336be
 }
e336be
 EXPORT_SYMBOL_GPL(rmi_set_attn_data);
e336be
 
e336be
-static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
e336be
+static void attn_callback(struct work_struct *work)
e336be
 {
e336be
-	struct rmi_device *rmi_dev = dev_id;
e336be
-	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
e336be
+	struct rmi_driver_data *drvdata = container_of(work,
e336be
+							struct rmi_driver_data,
e336be
+							attn_work);
e336be
 	struct rmi4_attn_data attn_data = {0};
e336be
 	int ret, count;
e336be
 
e336be
 	count = kfifo_get(&drvdata->attn_fifo, &attn_data);
e336be
-	if (count) {
e336be
-		*(drvdata->irq_status) = attn_data.irq_status;
e336be
-		drvdata->attn_data = attn_data;
e336be
-	}
e336be
+	if (!count)
e336be
+		return;
e336be
 
e336be
-	ret = rmi_process_interrupt_requests(rmi_dev);
e336be
+	*(drvdata->irq_status) = attn_data.irq_status;
e336be
+	drvdata->attn_data = attn_data;
e336be
+
e336be
+	ret = rmi_process_interrupt_requests(drvdata->rmi_dev);
e336be
 	if (ret)
e336be
-		rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev,
e336be
+		rmi_dbg(RMI_DEBUG_CORE, &drvdata->rmi_dev->dev,
e336be
 			"Failed to process interrupt request: %d\n", ret);
e336be
 
e336be
-	if (count) {
e336be
-		kfree(attn_data.data);
e336be
-		attn_data.data = NULL;
e336be
-	}
e336be
+	kfree(attn_data.data);
e336be
+	attn_data.data = NULL;
e336be
 
e336be
 	if (!kfifo_is_empty(&drvdata->attn_fifo))
e336be
-		return rmi_irq_fn(irq, dev_id);
e336be
+		schedule_work(&drvdata->attn_work);
e336be
+}
e336be
+
e336be
+static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
e336be
+{
e336be
+	struct rmi_device *rmi_dev = dev_id;
e336be
+	int ret;
e336be
+
e336be
+	ret = rmi_process_interrupt_requests(rmi_dev);
e336be
+	if (ret)
e336be
+		rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev,
e336be
+			"Failed to process interrupt request: %d\n", ret);
e336be
 
e336be
 	return IRQ_HANDLED;
e336be
 }
e336be
@@ -220,7 +233,6 @@ static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
e336be
 static int rmi_irq_init(struct rmi_device *rmi_dev)
e336be
 {
e336be
 	struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
e336be
-	struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
e336be
 	int irq_flags = irq_get_trigger_type(pdata->irq);
e336be
 	int ret;
e336be
 
e336be
@@ -238,8 +250,6 @@ static int rmi_irq_init(struct rmi_device *rmi_dev)
e336be
 		return ret;
e336be
 	}
e336be
 
e336be
-	data->enabled = true;
e336be
-
e336be
 	return 0;
e336be
 }
e336be
 
e336be
@@ -889,23 +899,27 @@ void rmi_enable_irq(struct rmi_device *rmi_dev, bool clear_wake)
e336be
 	if (data->enabled)
e336be
 		goto out;
e336be
 
e336be
-	enable_irq(irq);
e336be
-	data->enabled = true;
e336be
-	if (clear_wake && device_may_wakeup(rmi_dev->xport->dev)) {
e336be
-		retval = disable_irq_wake(irq);
e336be
-		if (retval)
e336be
-			dev_warn(&rmi_dev->dev,
e336be
-				 "Failed to disable irq for wake: %d\n",
e336be
-				 retval);
e336be
-	}
e336be
+	if (irq) {
e336be
+		enable_irq(irq);
e336be
+		data->enabled = true;
e336be
+		if (clear_wake && device_may_wakeup(rmi_dev->xport->dev)) {
e336be
+			retval = disable_irq_wake(irq);
e336be
+			if (retval)
e336be
+				dev_warn(&rmi_dev->dev,
e336be
+					 "Failed to disable irq for wake: %d\n",
e336be
+					 retval);
e336be
+		}
e336be
 
e336be
-	/*
e336be
-	 * Call rmi_process_interrupt_requests() after enabling irq,
e336be
-	 * otherwise we may lose interrupt on edge-triggered systems.
e336be
-	 */
e336be
-	irq_flags = irq_get_trigger_type(pdata->irq);
e336be
-	if (irq_flags & IRQ_TYPE_EDGE_BOTH)
e336be
-		rmi_process_interrupt_requests(rmi_dev);
e336be
+		/*
e336be
+		 * Call rmi_process_interrupt_requests() after enabling irq,
e336be
+		 * otherwise we may lose interrupt on edge-triggered systems.
e336be
+		 */
e336be
+		irq_flags = irq_get_trigger_type(pdata->irq);
e336be
+		if (irq_flags & IRQ_TYPE_EDGE_BOTH)
e336be
+			rmi_process_interrupt_requests(rmi_dev);
e336be
+	} else {
e336be
+		data->enabled = true;
e336be
+	}
e336be
 
e336be
 out:
e336be
 	mutex_unlock(&data->enabled_mutex);
e336be
@@ -925,20 +939,22 @@ void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake)
e336be
 		goto out;
e336be
 
e336be
 	data->enabled = false;
e336be
-	disable_irq(irq);
e336be
-	if (enable_wake && device_may_wakeup(rmi_dev->xport->dev)) {
e336be
-		retval = enable_irq_wake(irq);
e336be
-		if (retval)
e336be
-			dev_warn(&rmi_dev->dev,
e336be
-				 "Failed to enable irq for wake: %d\n",
e336be
-				 retval);
e336be
-	}
e336be
-
e336be
-	/* make sure the fifo is clean */
e336be
-	while (!kfifo_is_empty(&data->attn_fifo)) {
e336be
-		count = kfifo_get(&data->attn_fifo, &attn_data);
e336be
-		if (count)
e336be
-			kfree(attn_data.data);
e336be
+	if (irq) {
e336be
+		disable_irq(irq);
e336be
+		if (enable_wake && device_may_wakeup(rmi_dev->xport->dev)) {
e336be
+			retval = enable_irq_wake(irq);
e336be
+			if (retval)
e336be
+				dev_warn(&rmi_dev->dev,
e336be
+					 "Failed to enable irq for wake: %d\n",
e336be
+					 retval);
e336be
+		}
e336be
+	} else {
e336be
+		/* make sure the fifo is clean */
e336be
+		while (!kfifo_is_empty(&data->attn_fifo)) {
e336be
+			count = kfifo_get(&data->attn_fifo, &attn_data);
e336be
+			if (count)
e336be
+				kfree(attn_data.data);
e336be
+		}
e336be
 	}
e336be
 
e336be
 out:
e336be
@@ -984,6 +1000,8 @@ static int rmi_driver_remove(struct device *dev)
e336be
 	irq_domain_remove(data->irqdomain);
e336be
 	data->irqdomain = NULL;
e336be
 
e336be
+	cancel_work_sync(&data->attn_work);
e336be
+
e336be
 	rmi_f34_remove_sysfs(rmi_dev);
e336be
 	rmi_free_function_list(rmi_dev);
e336be
 
e336be
@@ -1221,9 +1239,15 @@ static int rmi_driver_probe(struct device *dev)
e336be
 		}
e336be
 	}
e336be
 
e336be
-	retval = rmi_irq_init(rmi_dev);
e336be
-	if (retval < 0)
e336be
-		goto err_destroy_functions;
e336be
+	if (pdata->irq) {
e336be
+		retval = rmi_irq_init(rmi_dev);
e336be
+		if (retval < 0)
e336be
+			goto err_destroy_functions;
e336be
+	}
e336be
+
e336be
+	data->enabled = true;
e336be
+
e336be
+	INIT_WORK(&data->attn_work, attn_callback);
e336be
 
e336be
 	if (data->f01_container->dev.driver) {
e336be
 		/* Driver already bound, so enable ATTN now. */
e336be
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
e336be
index 5ef5c7c412a7..21f48f2807de 100644
e336be
--- a/include/linux/rmi.h
e336be
+++ b/include/linux/rmi.h
e336be
@@ -366,6 +366,7 @@ struct rmi_driver_data {
e336be
 
e336be
 	struct rmi4_attn_data attn_data;
e336be
 	DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
e336be
+	struct work_struct attn_work;
e336be
 };
e336be
 
e336be
 int rmi_register_transport_device(struct rmi_transport_dev *xport);
e336be
-- 
e336be
2.17.1
e336be