Skip to contentSkip to conversation

input synaptics-rmi4: Bug fixes to ATTN GPIO handling.

PATCH Superseded Christopher Heiny 2 participants 3 messages Dec 17, 2013 – Dec 19, 2013

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 input synaptics-rmi4: Bug fixes to ATTN GPIO handling.

This patch fixes two bugs in handling of the RMI4 attention line GPIO.

1) in enable_sensor(), make sure the attn_gpio is defined before attempting to get its value.

2) in rmi_driver_probe(), declare the name of the attn_gpio, then request the attn_gpio before attempting to export it.

Also introduces a GPIO_LABEL constant for identifying the attention GPIO.

Cc Dmitry Torokhov <[email protected]>
Cc Benjamin Tissoires <[email protected]>

---

 drivers/input/rmi4/rmi_driver.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/input/rmi4/rmi_driver.c +17 -11
index a30c7d3..33fb8f8 100644
@@ -169,7 +169,7 @@ static int enable_sensor(struct rmi_device *rmi_dev)
 
 	data->enabled = true;
 
-	if (!pdata->level_triggered &&
+	if (pdata->attn_gpio && !pdata->level_triggered &&
 		    gpio_get_value(pdata->attn_gpio) == pdata->attn_polarity)
 		retval = process_interrupt_requests(rmi_dev);
 
@@ -807,6 +807,8 @@ static int rmi_driver_remove(struct device *dev)
 	return 0;
 }
 
+static const char GPIO_LABEL[] = "attn";
+
 static int rmi_driver_probe(struct device *dev)
 {
 	struct rmi_driver *rmi_driver;
@@ -959,20 +961,24 @@ static int rmi_driver_probe(struct device *dev)
 	}
 
 	if (IS_ENABLED(CONFIG_RMI4_DEV) && pdata->attn_gpio) {
-		retval = gpio_export(pdata->attn_gpio, false);
+		retval = gpio_request(pdata->attn_gpio, GPIO_LABEL);
 		if (retval) {
-			dev_warn(dev, "WARNING: Failed to export ATTN gpio!\n");
-			retval = 0;
+			dev_warn(dev, "WARNING: Failed to request ATTN gpio %d, code: %d.\n",
+				pdata->attn_gpio, retval);
 		} else {
-			retval = gpio_export_link(dev,
-						  "attn", pdata->attn_gpio);
+			retval = gpio_export(pdata->attn_gpio, false);
 			if (retval) {
-				dev_warn(dev,
-					"WARNING: Failed to symlink ATTN gpio!\n");
-				retval = 0;
+				dev_warn(dev, "WARNING: Failed to export ATTN gpio %d, code: %d.\n",
+					pdata->attn_gpio, retval);
 			} else {
-				dev_info(dev, "Exported ATTN GPIO %d.",
-					pdata->attn_gpio);
+				retval = gpio_export_link(dev, GPIO_LABEL,
+							  pdata->attn_gpio);
+				if (retval)
+					dev_warn(dev,
+						"WARNING: Failed to symlink ATTN gpio!\n");
+				else
+					dev_info(dev, "Exported ATTN GPIO %d.",
+						pdata->attn_gpio);
 			}
 		}
 	}
maintainer
#1 lore raw

Hi Chris,

Quoted 10 lines · Christopher Heiny

This patch fixes two bugs in handling of the RMI4 attention line GPIO.

1) in enable_sensor(), make sure the attn_gpio is defined before attempting to get its value.

2) in rmi_driver_probe(), declare the name of the attn_gpio, then request the attn_gpio before attempting to export it.

Also introduces a GPIO_LABEL constant for identifying the attention GPIO.

I was looking at the patch some more and I have some concerns with it.

Quoted 14 lines
Cc Dmitry Torokhov <[email protected]>
Cc Benjamin Tissoires <[email protected]>

---

 drivers/input/rmi4/rmi_driver.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/input/rmi4/rmi_driver.c +0 -0
index a30c7d3..33fb8f8 100644

drivers/input/rmi4/rmi_driver.c static int enable_sensor(struct rmi_device *rmi_dev) · line 172

Quoted 5 lines
drivers/input/rmi4/rmi_driver.c +1 -1
@@ -169,7 +169,7 @@ static int enable_sensor(struct rmi_device *rmi_dev)
 
 	data->enabled = true;
 
-	if (!pdata->level_triggered &&
+	if (pdata->attn_gpio && !pdata->level_triggered &&

O is perfectly fine GPIO number, you want to use gpio_is_valid() hete. I also wonder why do you need such elaborate check. Can we simply "flush" device before enabling interrupts?

Quoted 13 lines
drivers/input/rmi4/rmi_driver.c +2 -0
 		    gpio_get_value(pdata->attn_gpio) == pdata->attn_polarity)
 		retval = process_interrupt_requests(rmi_dev);
 
@@ -807,6 +807,8 @@ static int rmi_driver_remove(struct device *dev)
 	return 0;
 }
 
+static const char GPIO_LABEL[] = "attn";
+
 static int rmi_driver_probe(struct device *dev)
 {
 	struct rmi_driver *rmi_driver;

drivers/input/rmi4/rmi_driver.c static int rmi_driver_probe(struct device *dev) · line 964

Quoted 5 lines
drivers/input/rmi4/rmi_driver.c +1 -1
@@ -959,20 +961,24 @@ static int rmi_driver_probe(struct device *dev)
 	}
 
 	if (IS_ENABLED(CONFIG_RMI4_DEV) && pdata->attn_gpio) {
-		retval = gpio_export(pdata->attn_gpio, false);
+		retval = gpio_request(pdata->attn_gpio, GPIO_LABEL);

Here it is too late to request GPIO. You have been converting it to IRQ, enabling that IRQ and calling gpio_get_value() so GPIO should have already been requested by now.

So you need to move this code up. You may also consider using gpio_request_one() and use GPIOF_EXPORT flag if you want to export it. It would also be nice to set the direction (GPIOF_DIR_IN).

I also do not see matching call to gpio_free() in remove().

Quoted 19 lines
drivers/input/rmi4/rmi_driver.c +6 -9
 		if (retval) {
-			dev_warn(dev, "WARNING: Failed to export ATTN gpio!\n");
-			retval = 0;
+			dev_warn(dev, "WARNING: Failed to request ATTN gpio %d, code: %d.\n",
+				pdata->attn_gpio, retval);
 		} else {
-			retval = gpio_export_link(dev,
-						  "attn", pdata->attn_gpio);
+			retval = gpio_export(pdata->attn_gpio, false);
 			if (retval) {
-				dev_warn(dev,
-					"WARNING: Failed to symlink ATTN gpio!\n");
-				retval = 0;
+				dev_warn(dev, "WARNING: Failed to export ATTN gpio %d, code: %d.\n",
+					pdata->attn_gpio, retval);
 			} else {
-				dev_info(dev, "Exported ATTN GPIO %d.",
-					pdata->attn_gpio);
+				retval = gpio_export_link(dev, GPIO_LABEL,

drivers/input/rmi4/rmi_driver.c static int rmi_driver_probe(struct device *dev) · line 984

Quoted 10 lines
drivers/input/rmi4/rmi_driver.c +7 -0
+							  pdata->attn_gpio);
+				if (retval)
+					dev_warn(dev,
+						"WARNING: Failed to symlink ATTN gpio!\n");
+				else
+					dev_info(dev, "Exported ATTN GPIO %d.",
+						pdata->attn_gpio);
 			}
 		}
 	}

Thanks.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 31 lines · Dmitry Torokhov

Hi Chris,

Quoted 10 lines · Christopher Heiny

This patch fixes two bugs in handling of the RMI4 attention line GPIO.

1) in enable_sensor(), make sure the attn_gpio is defined before attempting to get its value.

2) in rmi_driver_probe(), declare the name of the attn_gpio, then request the attn_gpio before attempting to export it.

Also introduces a GPIO_LABEL constant for identifying the attention GPIO.

I was looking at the patch some more and I have some concerns with it.

Quoted 15 lines
Cc Dmitry Torokhov <[email protected]>
Cc Benjamin Tissoires <[email protected]>

---

  drivers/input/rmi4/rmi_driver.c | 28 +++++++++++++++++-----------
  1 file changed, 17 insertions(+), 11 deletions(-)
drivers/input/rmi4/rmi_driver.c +0 -0
index a30c7d3..33fb8f8 100644
@@ -169,7 +169,7 @@ static int enable_sensor(struct rmi_device *rmi_dev)
 
Quoted 8 lines

drivers/input/rmi4/rmi_driver.c static int enable_sensor(struct rmi_device *rmi_dev) · line 172

Quoted 4 lines
drivers/input/rmi4/rmi_driver.c +1 -1
  	data->enabled = true;
 
-	if (!pdata->level_triggered &&
+	if (pdata->attn_gpio && !pdata->level_triggered &&

O is perfectly fine GPIO number, you want to use gpio_is_valid() hete. I also wonder why do you need such elaborate check. Can we simply "flush" device before enabling interrupts?

Hmmm. gpio_is_valid() is a good suggestion. However, I think we can do away with the whole check on the ATTN gpio, and just call process_interrupt_requests(). That will both flush the state and handle any important pending events. In the typical use case for enable_sensor(), the RMI4 device will either be just coming up or else coming out of a diagnostic mode, and there will at least be a status event to handle. In the off-case where there is nothing pending (that is, ATTN not asserted), the overhead is pretty low - just a quick read of the interrupt status register.

Quoted 24 lines
Quoted 14 lines
drivers/input/rmi4/rmi_driver.c +2 -0
  		    gpio_get_value(pdata->attn_gpio) == pdata->attn_polarity)
  		retval = process_interrupt_requests(rmi_dev);
 
@@ -807,6 +807,8 @@ static int rmi_driver_remove(struct device *dev)
  	return 0;
  }
 
+static const char GPIO_LABEL[] = "attn";
+
  static int rmi_driver_probe(struct device *dev)
  {
  	struct rmi_driver *rmi_driver;

drivers/input/rmi4/rmi_driver.c static int rmi_driver_probe(struct device *dev) · line 964

Quoted 5 lines
drivers/input/rmi4/rmi_driver.c +1 -1
@@ -959,20 +961,24 @@ static int rmi_driver_probe(struct device *dev)
  	}
 
  	if (IS_ENABLED(CONFIG_RMI4_DEV) && pdata->attn_gpio) {
-		retval = gpio_export(pdata->attn_gpio, false);
+		retval = gpio_request(pdata->attn_gpio, GPIO_LABEL);

Here it is too late to request GPIO. You have been converting it to IRQ, enabling that IRQ and calling gpio_get_value() so GPIO should have already been requested by now.

Quoted 1 line

So you need to move this code up.

I'll give that a try.

Quoted 3 lines

You may also consider using
gpio_request_one() and use GPIOF_EXPORT flag if you want to export it. It would also be nice to set the direction (GPIOF_DIR_IN).

Both of these are good ideas.

Quoted 1 line

I also do not see matching call to gpio_free() in remove().

Neither do I :-(.

We'll update.

Quoted 33 lines
Quoted 20 lines
drivers/input/rmi4/rmi_driver.c +6 -9
  		if (retval) {
-			dev_warn(dev, "WARNING: Failed to export ATTN gpio!\n");
-			retval = 0;
+			dev_warn(dev, "WARNING: Failed to request ATTN gpio %d, code: %d.\n",
+				pdata->attn_gpio, retval);
  		} else {
-			retval = gpio_export_link(dev,
-						  "attn", pdata->attn_gpio);
+			retval = gpio_export(pdata->attn_gpio, false);
  			if (retval) {
-				dev_warn(dev,
-					"WARNING: Failed to symlink ATTN gpio!\n");
-				retval = 0;
+				dev_warn(dev, "WARNING: Failed to export ATTN gpio %d, code: %d.\n",
+					pdata->attn_gpio, retval);
  			} else {
-				dev_info(dev, "Exported ATTN GPIO %d.",
-					pdata->attn_gpio);
+				retval = gpio_export_link(dev, GPIO_LABEL,

drivers/input/rmi4/rmi_driver.c static int rmi_driver_probe(struct device *dev) · line 984

Quoted 10 lines
drivers/input/rmi4/rmi_driver.c +7 -0
+							  pdata->attn_gpio);
+				if (retval)
+					dev_warn(dev,
+						"WARNING: Failed to symlink ATTN gpio!\n");
+				else
+					dev_info(dev, "Exported ATTN GPIO %d.",
+						pdata->attn_gpio);
  			}
  		}
  	}

Thanks.