Skip to contentSkip to conversation

Revert "tty: serial: qcom_geni_serial: Wakeup over UART RX"

PATCH In review Akash Asthana 3 participants 13 messages Nov 22, 2019 – Nov 25, 2019 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v6 1/5 Revert "tty: serial: qcom_geni_serial: Wakeup over UART RX"

This reverts commit 8b7103f31950443fd5727d7d80d3c65416b5a390.

To apply v6 patches cleanly on tty-next, revert v2 patches.

---
 drivers/tty/serial/qcom_geni_serial.c | 44 +----------------------------------
 1 file changed, 1 insertion(+), 43 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +1 -43
index ff63728..5180cd8 100644
@@ -14,7 +14,6 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
-#include <linux/pm_wakeirq.h>
 #include <linux/qcom-geni-se.h>
 #include <linux/serial.h>
 #include <linux/serial_core.h>
@@ -117,7 +116,6 @@ struct qcom_geni_serial_port {
 	bool brk;
 
 	unsigned int tx_remaining;
-	int wakeup_irq;
 };
 
 static const struct uart_ops qcom_geni_console_pops;
@@ -757,15 +755,6 @@ static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done,
 		uart_write_wakeup(uport);
 }
 
-static irqreturn_t qcom_geni_serial_wakeup_isr(int isr, void *dev)
-{
-	struct uart_port *uport = dev;
-
-	pm_wakeup_event(uport->dev, 2000);
-
-	return IRQ_HANDLED;
-}
-
 static irqreturn_t qcom_geni_serial_isr(int isr, void *dev)
 {
 	u32 m_irq_en;
@@ -1317,29 +1306,6 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	if (!console) {
-		port->wakeup_irq = platform_get_irq(pdev, 1);
-		if (port->wakeup_irq < 0) {
-			dev_err(&pdev->dev, "Failed to get wakeup IRQ %d\n",
-					port->wakeup_irq);
-		} else {
-			irq_set_status_flags(port->wakeup_irq, IRQ_NOAUTOEN);
-			ret = devm_request_irq(uport->dev, port->wakeup_irq,
-				qcom_geni_serial_wakeup_isr,
-				IRQF_TRIGGER_FALLING, "uart_wakeup", uport);
-			if (ret) {
-				dev_err(uport->dev, "Failed to register wakeup IRQ ret %d\n",
-						ret);
-				return ret;
-			}
-
-			device_init_wakeup(&pdev->dev, true);
-			ret = dev_pm_set_wake_irq(&pdev->dev, port->wakeup_irq);
-			if (unlikely(ret))
-				dev_err(uport->dev, "%s:Failed to set IRQ wake:%d\n",
-						__func__, ret);
-		}
-	}
 	uport->private_data = drv;
 	platform_set_drvdata(pdev, port);
 	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
@@ -1362,12 +1328,7 @@ static int __maybe_unused qcom_geni_serial_sys_suspend(struct device *dev)
 	struct qcom_geni_serial_port *port = dev_get_drvdata(dev);
 	struct uart_port *uport = &port->uport;
 
-	uart_suspend_port(uport->private_data, uport);
-
-	if (port->wakeup_irq > 0)
-		enable_irq(port->wakeup_irq);
-
-	return 0;
+	return uart_suspend_port(uport->private_data, uport);
 }
 
 static int __maybe_unused qcom_geni_serial_sys_resume(struct device *dev)
@@ -1375,9 +1336,6 @@ static int __maybe_unused qcom_geni_serial_sys_resume(struct device *dev)
 	struct qcom_geni_serial_port *port = dev_get_drvdata(dev);
 	struct uart_port *uport = &port->uport;
 
-	if (port->wakeup_irq > 0)
-		disable_irq(port->wakeup_irq);
-
 	return uart_resume_port(uport->private_data, uport);
 }
 
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
#2 lore raw

PATCH v6 2/5 Revert "tty: serial: qcom_geni_serial: IRQ cleanup"

In reply to a message not in the archive

This reverts commit 3e4aaea7a0391d47f6ffff1f10594c658a67c881.

To apply v6 patches cleanly on tty-next branch, revert v2 patches.

---
 drivers/tty/serial/qcom_geni_serial.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +10 -14
index 5180cd8..14c6306 100644
@@ -9,7 +9,6 @@
 #include <linux/console.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
-#include <linux/irq.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -831,7 +830,7 @@ static void qcom_geni_serial_shutdown(struct uart_port *uport)
 	if (uart_console(uport))
 		console_stop(uport->cons);
 
-	disable_irq(uport->irq);
+	free_irq(uport->irq, uport);
 	spin_lock_irqsave(&uport->lock, flags);
 	qcom_geni_serial_stop_tx(uport);
 	qcom_geni_serial_stop_rx(uport);
@@ -891,14 +890,21 @@ static int qcom_geni_serial_startup(struct uart_port *uport)
 	int ret;
 	struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
 
+	scnprintf(port->name, sizeof(port->name),
+		  "qcom_serial_%s%d",
+		(uart_console(uport) ? "console" : "uart"), uport->line);
+
 	if (!port->setup) {
 		ret = qcom_geni_serial_port_setup(uport);
 		if (ret)
 			return ret;
 	}
-	enable_irq(uport->irq);
 
-	return 0;
+	ret = request_irq(uport->irq, qcom_geni_serial_isr, IRQF_TRIGGER_HIGH,
+							port->name, uport);
+	if (ret)
+		dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
+	return ret;
 }
 
 static unsigned long get_clk_cfg(unsigned long clk_freq)
@@ -1291,21 +1297,11 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 	port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
 	port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
 
-	scnprintf(port->name, sizeof(port->name), "qcom_geni_serial_%s%d",
-		(uart_console(uport) ? "console" : "uart"), uport->line);
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
 	uport->irq = irq;
 
-	irq_set_status_flags(uport->irq, IRQ_NOAUTOEN);
-	ret = devm_request_irq(uport->dev, uport->irq, qcom_geni_serial_isr,
-			IRQF_TRIGGER_HIGH, port->name, uport);
-	if (ret) {
-		dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
-		return ret;
-	}
-
 	uport->private_data = drv;
 	platform_set_drvdata(pdev, port);
 	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
#3 lore raw

PATCH v6 3/5 tty: serial: qcom_geni_serial: IRQ cleanup

In reply to a message not in the archive

Move ISR registration from startup to probe function to avoid registering it everytime when the port open is called for driver.

---
Changes in v6:
- Rebased on tty-next branch

Changes in v5:
- No change.

Changes in v4:
- As per Stephen's comment, move ISR registration(later in probe) after registering uart port with serial core.
- As per Greg's comment, corrected returning of PTR value from integer type function(probe).

Changes in v3:
- As per Stephen's comment, using devm_kasprintf instead of scnprintf API.

 drivers/tty/serial/qcom_geni_serial.c | 38 ++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 12 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +26 -12
index 14c6306..634054a 100644
@@ -9,6 +9,7 @@
 #include <linux/console.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
+#include <linux/irq.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -101,7 +102,7 @@
 struct qcom_geni_serial_port {
 	struct uart_port uport;
 	struct geni_se se;
-	char name[20];
+	const char *name;
 	u32 tx_fifo_depth;
 	u32 tx_fifo_width;
 	u32 rx_fifo_depth;
@@ -830,7 +831,7 @@ static void qcom_geni_serial_shutdown(struct uart_port *uport)
 	if (uart_console(uport))
 		console_stop(uport->cons);
 
-	free_irq(uport->irq, uport);
+	disable_irq(uport->irq);
 	spin_lock_irqsave(&uport->lock, flags);
 	qcom_geni_serial_stop_tx(uport);
 	qcom_geni_serial_stop_rx(uport);
@@ -890,21 +891,14 @@ static int qcom_geni_serial_startup(struct uart_port *uport)
 	int ret;
 	struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
 
-	scnprintf(port->name, sizeof(port->name),
-		  "qcom_serial_%s%d",
-		(uart_console(uport) ? "console" : "uart"), uport->line);
-
 	if (!port->setup) {
 		ret = qcom_geni_serial_port_setup(uport);
 		if (ret)
 			return ret;
 	}
+	enable_irq(uport->irq);
 
-	ret = request_irq(uport->irq, qcom_geni_serial_isr, IRQF_TRIGGER_HIGH,
-							port->name, uport);
-	if (ret)
-		dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
-	return ret;
+	return 0;
 }
 
 static unsigned long get_clk_cfg(unsigned long clk_freq)
@@ -1297,6 +1291,12 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 	port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
 	port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
 
+	port->name = devm_kasprintf(uport->dev, GFP_KERNEL,
+			"qcom_geni_serial_%s%d",
+			uart_console(uport) ? "console" : "uart", uport->line);
+	if (!port->name)
+		return -ENOMEM;
+
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
@@ -1307,7 +1307,21 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
 	if (!console)
 		device_create_file(uport->dev, &dev_attr_loopback);
-	return uart_add_one_port(drv, uport);
+
+	ret = uart_add_one_port(drv, uport);
+	if (ret)
+		return ret;
+
+	irq_set_status_flags(uport->irq, IRQ_NOAUTOEN);
+	ret = devm_request_irq(uport->dev, uport->irq, qcom_geni_serial_isr,
+			IRQF_TRIGGER_HIGH, port->name, uport);
+	if (ret) {
+		dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
+		uart_remove_one_port(drv, uport);
+		return ret;
+	}
+
+	return ret;
 }
 
 static int qcom_geni_serial_remove(struct platform_device *pdev)
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
Reviewed-by on v6 3/5
#4 lore raw

Re: [PATCH v6 3/5] tty: serial: qcom_geni_serial: IRQ cleanup

Quoted 37 lines · Akash Asthana

Move ISR registration from startup to probe function to avoid registering it everytime when the port open is called for driver.

---
Changes in v6:
- Rebased on tty-next branch

Changes in v5:
- No change.

Changes in v4:
- As per Stephen's comment, move ISR registration(later in probe) after registering uart port with serial core.
- As per Greg's comment, corrected returning of PTR value from integer type function(probe).

Changes in v3:
- As per Stephen's comment, using devm_kasprintf instead of scnprintf API.

 drivers/tty/serial/qcom_geni_serial.c | 38 ++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 12 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +2 -1
index 14c6306..634054a 100644
 
...
@@ -1307,7 +1307,21 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
 	if (!console)
 		device_create_file(uport->dev, &dev_attr_loopback);
-	return uart_add_one_port(drv, uport);
+
+	ret = uart_add_one_port(drv, uport);

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct platform_device *pdev) · line 1321

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c +10 -0
+	if (ret)
+		return ret;
+
+	irq_set_status_flags(uport->irq, IRQ_NOAUTOEN);
+	ret = devm_request_irq(uport->dev, uport->irq, qcom_geni_serial_isr,
+			IRQF_TRIGGER_HIGH, port->name, uport);
+	if (ret) {
+		dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
+		uart_remove_one_port(drv, uport);
+		return ret;

nit: could fall through

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct platform_device *pdev) · line 1324

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c +3 -0
+	}
+
+	return ret;

nit: if not falling through above this could/should be 0.

#5 lore raw

Re: [PATCH v6 3/5] tty: serial: qcom_geni_serial: IRQ cleanup

Quoted 50 lines · Matthias Kaehlcke
Quoted 37 lines · Akash Asthana

Move ISR registration from startup to probe function to avoid registering it everytime when the port open is called for driver.

---
Changes in v6:
- Rebased on tty-next branch

Changes in v5:
- No change.

Changes in v4:
- As per Stephen's comment, move ISR registration(later in probe) after registering uart port with serial core.
- As per Greg's comment, corrected returning of PTR value from integer type function(probe).

Changes in v3:
- As per Stephen's comment, using devm_kasprintf instead of scnprintf API.

  drivers/tty/serial/qcom_geni_serial.c | 38 ++++++++++++++++++++++++-----------
  1 file changed, 26 insertions(+), 12 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +2 -1
index 14c6306..634054a 100644
 
...
@@ -1307,7 +1307,21 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
  	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
  	if (!console)
  		device_create_file(uport->dev, &dev_attr_loopback);
-	return uart_add_one_port(drv, uport);
+
+	ret = uart_add_one_port(drv, uport);

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct platform_device *pdev) · line 1321

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c +10 -0
+	if (ret)
+		return ret;
+
+	irq_set_status_flags(uport->irq, IRQ_NOAUTOEN);
+	ret = devm_request_irq(uport->dev, uport->irq, qcom_geni_serial_isr,
+			IRQF_TRIGGER_HIGH, port->name, uport);
+	if (ret) {
+		dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
+		uart_remove_one_port(drv, uport);
+		return ret;

nit: could fall through

Quoted 4 lines

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct platform_device *pdev) · line 1324

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c +3 -0
+	}
+
+	return ret;

nit: if not falling through above this could/should be 0.

ok, will change it to return 0;

Quoted 1 line
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
#6 lore raw

PATCH v6 4/5 tty: serial: qcom_geni_serial: Wakeup over UART RX

In reply to a message not in the archive

Add system wakeup capability over UART RX line for wakeup capable UART. When system is suspended, RX line act as an interrupt to wakeup system for any communication requests from peer.

---
Changes in V6:
- Rebased on top of tty-next branch.
- As per stephen's comment mark devices runtime status as active irrespective of wakeup feature.

Changes in V5:
- No change.

Changes in V4:
- As per Greg's comment, removed extra dev_err logging.
- As per Stephen's comment, using common code that manage wakeirq irqs for devices. Using dev_pm_set_dedicated_wake_irq API that will take care of requesting and attaching wakeup irqs for devices. Also, it sets wakeirq status to WAKE_IRQ_DEDICATED_ALLOCATED as a result enabling/disabling of wake irq will be managed by suspend/resume framework so, removed the code for enabling and disabling of wake irq from the driver.

Changes in V3:
- As per Stephen's comment, using platform_get_irq_optional API to get wakeup IRQ for device.

Changes in V2:
- As per Stephen's comment, splitted V1 patch into 2 seperate patch.
a) Clean up of core IRQ registration b) Add wakeup feature.

 drivers/tty/serial/qcom_geni_serial.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/tty/serial/qcom_geni_serial.c +28 -0
index 634054a..b952509 100644
@@ -14,6 +14,8 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
 #include <linux/qcom-geni-se.h>
 #include <linux/serial.h>
 #include <linux/serial_core.h>
@@ -116,6 +118,7 @@ struct qcom_geni_serial_port {
 	bool brk;
 
 	unsigned int tx_remaining;
+	int wakeup_irq;
 };
 
 static const struct uart_ops qcom_geni_console_pops;
@@ -1302,6 +1305,9 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 		return irq;
 	uport->irq = irq;
 
+	if (!console)
+		port->wakeup_irq = platform_get_irq_optional(pdev, 1);
+
 	uport->private_data = drv;
 	platform_set_drvdata(pdev, port);
 	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
@@ -1321,6 +1327,24 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	/*
+	 * Set pm_runtime status as ACTIVE so that wakeup_irq gets
+	 * enabled/disabled from dev_pm_arm_wake_irq  during  system
+	 * suspend/resume respectively.
+	 */
+	pm_runtime_set_active(&pdev->dev);
+
+	if (port->wakeup_irq > 0) {
+		device_init_wakeup(&pdev->dev, true);
+		ret = dev_pm_set_dedicated_wake_irq(&pdev->dev,
+						port->wakeup_irq);
+		if (ret) {
+			device_init_wakeup(&pdev->dev, false);
+			uart_remove_one_port(drv, uport);
+			return ret;
+		}
+	}
+
 	return ret;
 }
 
@@ -1330,6 +1354,10 @@ static int qcom_geni_serial_remove(struct platform_device *pdev)
 	struct uart_driver *drv = port->uport.private_data;
 
 	uart_remove_one_port(drv, &port->uport);
+
+	device_init_wakeup(&pdev->dev, false);
+	dev_pm_clear_wake_irq(&pdev->dev);
+
 	return 0;
 }
 
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
Reviewed-by on v6 4/5
#7 lore raw

Re: [PATCH v6 4/5] tty: serial: qcom_geni_serial: Wakeup over UART RX

Quoting Akash Asthana (2019-11-22 06:18:19)

Quoted 5 lines

Add system wakeup capability over UART RX line for wakeup capable UART. When system is suspended, RX line act as an interrupt to wakeup system for any communication requests from peer.

One question below.

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_remove(struct platform_device *pdev) · line 1359

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c +3 -0
@@ -1330,6 +1354,10 @@ static int qcom_geni_serial_remove(struct platform_device *pdev)
        struct uart_driver *drv = port->uport.private_data;
 
        uart_remove_one_port(drv, &port->uport);
+
+       device_init_wakeup(&pdev->dev, false);
+       dev_pm_clear_wake_irq(&pdev->dev);

Should this order be swapped? Usually remove is done in reverse of probe order, so clear_wake_irq, init wakeup, and remove uart port. I'm not convinced it will actually matter though so maybe this isn't a problem.

#8 lore raw

Re: [PATCH v6 4/5] tty: serial: qcom_geni_serial: Wakeup over UART RX

Quoted 13 lines · Stephen Boyd

Quoting Akash Asthana (2019-11-22 06:18:19)

Quoted 5 lines

Add system wakeup capability over UART RX line for wakeup capable UART. When system is suspended, RX line act as an interrupt to wakeup system for any communication requests from peer.

One question below.

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c +0 -0
@@ -1330,6 +1354,10 @@ static int qcom_geni_serial_remove(struct platform_device *pdev)
         struct uart_driver *drv = port->uport.private_data;
 
Quoted 7 lines

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_remove(struct platform_device *pdev) · line 1359

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c +3 -0
         uart_remove_one_port(drv, &port->uport);
+
+       device_init_wakeup(&pdev->dev, false);
+       dev_pm_clear_wake_irq(&pdev->dev);

Should this order be swapped? Usually remove is done in reverse of probe order, so clear_wake_irq, init wakeup, and remove uart port. I'm not convinced it will actually matter though so maybe this isn't a problem.

Ok, I will update the order here.

Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
Reviewed-by on v6 4/5
#9 lore raw

Re: [PATCH v6 4/5] tty: serial: qcom_geni_serial: Wakeup over UART RX

In reply to Akash Asthana
Quoted 66 lines · Akash Asthana

Add system wakeup capability over UART RX line for wakeup capable UART. When system is suspended, RX line act as an interrupt to wakeup system for any communication requests from peer.

---
Changes in V6:
- Rebased on top of tty-next branch.
- As per stephen's comment mark devices runtime status as active irrespective of wakeup feature.

Changes in V5:
- No change.

Changes in V4:
- As per Greg's comment, removed extra dev_err logging.
- As per Stephen's comment, using common code that manage wakeirq irqs for devices. Using dev_pm_set_dedicated_wake_irq API that will take care of requesting and attaching wakeup irqs for devices. Also, it sets wakeirq status to WAKE_IRQ_DEDICATED_ALLOCATED as a result enabling/disabling of wake irq will be managed by suspend/resume framework so, removed the code for enabling and disabling of wake irq from the driver.

Changes in V3:
- As per Stephen's comment, using platform_get_irq_optional API to get wakeup IRQ for device.

Changes in V2:
- As per Stephen's comment, splitted V1 patch into 2 seperate patch.
a) Clean up of core IRQ registration b) Add wakeup feature.

 drivers/tty/serial/qcom_geni_serial.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/tty/serial/qcom_geni_serial.c +6 -0
index 634054a..b952509 100644
@@ -14,6 +14,8 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
 #include <linux/qcom-geni-se.h>
 #include <linux/serial.h>
 #include <linux/serial_core.h>
@@ -116,6 +118,7 @@ struct qcom_geni_serial_port {
 	bool brk;
 
 	unsigned int tx_remaining;
+	int wakeup_irq;
 };
 
 static const struct uart_ops qcom_geni_console_pops;
@@ -1302,6 +1305,9 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 		return irq;
 	uport->irq = irq;
 
+	if (!console)
+		port->wakeup_irq = platform_get_irq_optional(pdev, 1);
+
 	uport->private_data = drv;
 	platform_set_drvdata(pdev, port);
 	port->handle_rx = console ? handle_rx_console : handle_rx_uart;

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct platform_device *pdev) · line 1332

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c +3 -0
@@ -1321,6 +1327,24 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	/*
+	 * Set pm_runtime status as ACTIVE so that wakeup_irq gets
+	 * enabled/disabled from dev_pm_arm_wake_irq  during  system

nit: remove one of the two blanks before/after 'during'.

Quoted 19 lines
drivers/tty/serial/qcom_geni_serial.c +15 -0
+	 * suspend/resume respectively.
+	 */
+	pm_runtime_set_active(&pdev->dev);
+
+	if (port->wakeup_irq > 0) {
+		device_init_wakeup(&pdev->dev, true);
+		ret = dev_pm_set_dedicated_wake_irq(&pdev->dev,
+						port->wakeup_irq);
+		if (ret) {
+			device_init_wakeup(&pdev->dev, false);
+			uart_remove_one_port(drv, uport);
+			return ret;
+		}
+	}
+
 	return ret;
 }
 

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_remove(struct platform_device *pdev) · line 1362

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c +4 -0
@@ -1330,6 +1354,10 @@ static int qcom_geni_serial_remove(struct platform_device *pdev)
 	struct uart_driver *drv = port->uport.private_data;
 
 	uart_remove_one_port(drv, &port->uport);
+
+	device_init_wakeup(&pdev->dev, false);
+	dev_pm_clear_wake_irq(&pdev->dev);
+
 	return 0;
 }
#10 lore raw

Re: [PATCH v6 4/5] tty: serial: qcom_geni_serial: Wakeup over UART RX

Quoted 70 lines · Matthias Kaehlcke
Quoted 69 lines · Akash Asthana

Add system wakeup capability over UART RX line for wakeup capable UART. When system is suspended, RX line act as an interrupt to wakeup system for any communication requests from peer.

---
Changes in V6:
- Rebased on top of tty-next branch.
- As per stephen's comment mark devices runtime status as active irrespective of wakeup feature.

Changes in V5:
- No change.

Changes in V4:
- As per Greg's comment, removed extra dev_err logging.
- As per Stephen's comment, using common code that manage wakeirq irqs for devices. Using dev_pm_set_dedicated_wake_irq API that will take care of requesting and attaching wakeup irqs for devices. Also, it sets wakeirq status to WAKE_IRQ_DEDICATED_ALLOCATED as a result enabling/disabling of wake irq will be managed by suspend/resume framework so, removed the code for enabling and disabling of wake irq from the driver.

Changes in V3:
- As per Stephen's comment, using platform_get_irq_optional API to get wakeup IRQ for device.

Changes in V2:
- As per Stephen's comment, splitted V1 patch into 2 seperate patch.
a) Clean up of core IRQ registration b) Add wakeup feature.

  drivers/tty/serial/qcom_geni_serial.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
drivers/tty/serial/qcom_geni_serial.c +6 -0
index 634054a..b952509 100644
@@ -14,6 +14,8 @@
  #include <linux/of.h>
  #include <linux/of_device.h>
  #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
  #include <linux/qcom-geni-se.h>
  #include <linux/serial.h>
  #include <linux/serial_core.h>
@@ -116,6 +118,7 @@ struct qcom_geni_serial_port {
  	bool brk;
 
  	unsigned int tx_remaining;
+	int wakeup_irq;
  };
 
  static const struct uart_ops qcom_geni_console_pops;
@@ -1302,6 +1305,9 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
  		return irq;
  	uport->irq = irq;
 
+	if (!console)
+		port->wakeup_irq = platform_get_irq_optional(pdev, 1);
+
  	uport->private_data = drv;
  	platform_set_drvdata(pdev, port);
  	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
@@ -1321,6 +1327,24 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
  		return ret;
  	}
 
Quoted 4 lines

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct platform_device *pdev) · line 1332

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c +3 -0
+	/*
+	 * Set pm_runtime status as ACTIVE so that wakeup_irq gets
+	 * enabled/disabled from dev_pm_arm_wake_irq  during  system

nit: remove one of the two blanks before/after 'during'.

ok

Quoted 30 lines
Quoted 20 lines
drivers/tty/serial/qcom_geni_serial.c +15 -0
+	 * suspend/resume respectively.
+	 */
+	pm_runtime_set_active(&pdev->dev);
+
+	if (port->wakeup_irq > 0) {
+		device_init_wakeup(&pdev->dev, true);
+		ret = dev_pm_set_dedicated_wake_irq(&pdev->dev,
+						port->wakeup_irq);
+		if (ret) {
+			device_init_wakeup(&pdev->dev, false);
+			uart_remove_one_port(drv, uport);
+			return ret;
+		}
+	}
+
  	return ret;
  }
 

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_remove(struct platform_device *pdev) · line 1362

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c +4 -0
@@ -1330,6 +1354,10 @@ static int qcom_geni_serial_remove(struct platform_device *pdev)
  	struct uart_driver *drv = port->uport.private_data;
 
  	uart_remove_one_port(drv, &port->uport);
+
+	device_init_wakeup(&pdev->dev, false);
+	dev_pm_clear_wake_irq(&pdev->dev);
+
  	return 0;
  }
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
#11 lore raw

PATCH v6 5/5 tty: serial: qcom_geni_serial: Move loopback support to TIOCM_LOOP

In reply to a message not in the archive

Remove code from the driver that create and maintain loopback sysfs node. Instead use the ioctl TIOCMSET with TIOCM_LOOP argument to set HW to loopback mode.

---
Change in V6:
- As per stephen's comment corrected commit subject.
- As per stephen's comment defined new macros for different loopback mode.

 drivers/tty/serial/qcom_geni_serial.c | 36 +++++++++--------------------------
 1 file changed, 9 insertions(+), 27 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +9 -27
index b952509..3e84192 100644
@@ -93,7 +93,11 @@
 #define DEF_TX_WM		2
 #define DEF_FIFO_WIDTH_BITS	32
 #define UART_RX_WM		2
-#define MAX_LOOPBACK_CFG	3
+
+/* SE_UART_LOOPBACK_CFG */
+#define RX_TX_SORTED	BIT(0)
+#define CTS_RTS_SORTED	BIT(1)
+#define RX_TX_CTS_RTS_SORTED	(RX_TX_SORTED | CTS_RTS_SORTED)
 
 #ifdef CONFIG_CONSOLE_POLL
 #define CONSOLE_RX_BYTES_PW 1
@@ -165,30 +169,6 @@ static struct qcom_geni_serial_port qcom_geni_uart_ports[GENI_UART_PORTS] = {
 	},
 };
 
-static ssize_t loopback_show(struct device *dev,
-				struct device_attribute *attr, char *buf)
-{
-	struct qcom_geni_serial_port *port = dev_get_drvdata(dev);
-
-	return snprintf(buf, sizeof(u32), "%d\n", port->loopback);
-}
-
-static ssize_t loopback_store(struct device *dev,
-				struct device_attribute *attr, const char *buf,
-				size_t size)
-{
-	struct qcom_geni_serial_port *port = dev_get_drvdata(dev);
-	u32 loopback;
-
-	if (kstrtoint(buf, 0, &loopback) || loopback > MAX_LOOPBACK_CFG) {
-		dev_err(dev, "Invalid input\n");
-		return -EINVAL;
-	}
-	port->loopback = loopback;
-	return size;
-}
-static DEVICE_ATTR_RW(loopback);
-
 static struct qcom_geni_serial_port qcom_geni_console_port = {
 	.uport = {
 		.iotype = UPIO_MEM,
@@ -238,10 +218,14 @@ static void qcom_geni_serial_set_mctrl(struct uart_port *uport,
 							unsigned int mctrl)
 {
 	u32 uart_manual_rfr = 0;
+	struct qcom_geni_serial_port *port = to_dev_port(uport, uport);
 
 	if (uart_console(uport))
 		return;
 
+	if (mctrl & TIOCM_LOOP)
+		port->loopback = RX_TX_CTS_RTS_SORTED;
+
 	if (!(mctrl & TIOCM_RTS))
 		uart_manual_rfr = UART_MANUAL_RFR_EN | UART_RFR_NOT_READY;
 	writel(uart_manual_rfr, uport->membase + SE_UART_MANUAL_RFR);
@@ -1311,8 +1295,6 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
 	uport->private_data = drv;
 	platform_set_drvdata(pdev, port);
 	port->handle_rx = console ? handle_rx_console : handle_rx_uart;
-	if (!console)
-		device_create_file(uport->dev, &dev_attr_loopback);
 
 	ret = uart_add_one_port(drv, uport);
 	if (ret)
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
Reviewed-by on v6 5/5
#12 lore raw

Re: [PATCH v6 5/5] tty: serial: qcom_geni_serial: Move loopback support to TIOCM_LOOP

Quoting Akash Asthana (2019-11-22 06:18:24)

Quoted 6 lines

Remove code from the driver that create and maintain loopback sysfs node. Instead use the ioctl TIOCMSET with TIOCM_LOOP argument to set HW to loopback mode.

---

A message that is not in the archive (sent off-list or not yet received): 0101016e937a3f78-11fa1469-8c73-4f56-a3de-3221dcf6f0e3-000000@us-west-2.amazonses.com