diff mbox series

serial: 8250_bcm2835aux: Fix clock imbalance in PM resume

Message ID 20240818174936.88372-1-wahrenst@gmx.net (mailing list archive)
State New, archived
Headers show
Series serial: 8250_bcm2835aux: Fix clock imbalance in PM resume | expand

Commit Message

Stefan Wahren Aug. 18, 2024, 5:49 p.m. UTC
During review Ulf Hansson discovered a clock imbalance in the recently
introduced PM resume code. The driver should enable the clock only in
case it has been disabled in suspend before. In order to make the
conditions easier to read, refactor this into a separate function.

Reported-by: Ulf Hansson <ulf.hansson@linaro.org>
Closes: https://lore.kernel.org/linux-arm-kernel/CAPDyKFoJh3j8xSeXZ9o031YZLTCDYVA+dgvURuwozjDpU_aauA@mail.gmail.com/
Fixes: 0e1d8780526f ("serial: 8250_bcm2835aux: add PM suspend/resume support")
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 26 +++++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)

--
2.34.1

Comments

Stefan Wahren Aug. 31, 2024, 9:16 a.m. UTC | #1
Hi,

Am 18.08.24 um 19:49 schrieb Stefan Wahren:
> During review Ulf Hansson discovered a clock imbalance in the recently
> introduced PM resume code. The driver should enable the clock only in
> case it has been disabled in suspend before. In order to make the
> conditions easier to read, refactor this into a separate function.
>
> Reported-by: Ulf Hansson <ulf.hansson@linaro.org>
> Closes: https://lore.kernel.org/linux-arm-kernel/CAPDyKFoJh3j8xSeXZ9o031YZLTCDYVA+dgvURuwozjDpU_aauA@mail.gmail.com/
> Fixes: 0e1d8780526f ("serial: 8250_bcm2835aux: add PM suspend/resume support")
> Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
i missed to mention that this is for tty-next.

Now i can take the chance for a gentle ping ...
> ---
>   drivers/tty/serial/8250/8250_bcm2835aux.c | 26 +++++++++++++++++------
>   1 file changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_bcm2835aux.c b/drivers/tty/serial/8250/8250_bcm2835aux.c
> index 36e2bb34d82b..e6b42ca6151e 100644
> --- a/drivers/tty/serial/8250/8250_bcm2835aux.c
> +++ b/drivers/tty/serial/8250/8250_bcm2835aux.c
> @@ -214,17 +214,27 @@ static const struct acpi_device_id bcm2835aux_serial_acpi_match[] = {
>   };
>   MODULE_DEVICE_TABLE(acpi, bcm2835aux_serial_acpi_match);
>
> -static int bcm2835aux_suspend(struct device *dev)
> +static bool bcm2835aux_can_disable_clock(struct device *dev)
>   {
>   	struct bcm2835aux_data *data = dev_get_drvdata(dev);
>   	struct uart_8250_port *up = serial8250_get_port(data->line);
>
> -	serial8250_suspend_port(data->line);
> -
>   	if (device_may_wakeup(dev))
> -		return 0;
> +		return false;
>
>   	if (uart_console(&up->port) && !console_suspend_enabled)
> +		return false;
> +
> +	return true;
> +}
> +
> +static int bcm2835aux_suspend(struct device *dev)
> +{
> +	struct bcm2835aux_data *data = dev_get_drvdata(dev);
> +
> +	serial8250_suspend_port(data->line);
> +
> +	if (!bcm2835aux_can_disable_clock(dev))
>   		return 0;
>
>   	clk_disable_unprepare(data->clk);
> @@ -236,9 +246,11 @@ static int bcm2835aux_resume(struct device *dev)
>   	struct bcm2835aux_data *data = dev_get_drvdata(dev);
>   	int ret;
>
> -	ret = clk_prepare_enable(data->clk);
> -	if (ret)
> -		return ret;
> +	if (bcm2835aux_can_disable_clock(dev)) {
> +		ret = clk_prepare_enable(data->clk);
> +		if (ret)
> +			return ret;
> +	}
>
>   	serial8250_resume_port(data->line);
>
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/tty/serial/8250/8250_bcm2835aux.c b/drivers/tty/serial/8250/8250_bcm2835aux.c
index 36e2bb34d82b..e6b42ca6151e 100644
--- a/drivers/tty/serial/8250/8250_bcm2835aux.c
+++ b/drivers/tty/serial/8250/8250_bcm2835aux.c
@@ -214,17 +214,27 @@  static const struct acpi_device_id bcm2835aux_serial_acpi_match[] = {
 };
 MODULE_DEVICE_TABLE(acpi, bcm2835aux_serial_acpi_match);

-static int bcm2835aux_suspend(struct device *dev)
+static bool bcm2835aux_can_disable_clock(struct device *dev)
 {
 	struct bcm2835aux_data *data = dev_get_drvdata(dev);
 	struct uart_8250_port *up = serial8250_get_port(data->line);

-	serial8250_suspend_port(data->line);
-
 	if (device_may_wakeup(dev))
-		return 0;
+		return false;

 	if (uart_console(&up->port) && !console_suspend_enabled)
+		return false;
+
+	return true;
+}
+
+static int bcm2835aux_suspend(struct device *dev)
+{
+	struct bcm2835aux_data *data = dev_get_drvdata(dev);
+
+	serial8250_suspend_port(data->line);
+
+	if (!bcm2835aux_can_disable_clock(dev))
 		return 0;

 	clk_disable_unprepare(data->clk);
@@ -236,9 +246,11 @@  static int bcm2835aux_resume(struct device *dev)
 	struct bcm2835aux_data *data = dev_get_drvdata(dev);
 	int ret;

-	ret = clk_prepare_enable(data->clk);
-	if (ret)
-		return ret;
+	if (bcm2835aux_can_disable_clock(dev)) {
+		ret = clk_prepare_enable(data->clk);
+		if (ret)
+			return ret;
+	}

 	serial8250_resume_port(data->line);