Skip to content

Commit

Permalink
tty: serial: qcom_geni_serial: Use OPP API to set clk/perf state
Browse files Browse the repository at this point in the history
geni serial needs to express a perforamnce state requirement on CX
powerdomain depending on the frequency of the clock rates.
Use OPP table from DT to register with OPP framework and use
dev_pm_opp_set_rate() to set the clk/perf state.

Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Akash Asthana <akashast@codeaurora.org>
Cc: linux-serial@vger.kernel.org
Link: https://lore.kernel.org/r/1588507469-31889-2-git-send-email-rnayak@codeaurora.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Rajendra Nayak authored and gregkh committed May 5, 2020
1 parent c2880ec commit 3d9231e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
34 changes: 29 additions & 5 deletions drivers/tty/serial/qcom_geni_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/pm_opp.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/pm_wakeirq.h>
Expand Down Expand Up @@ -961,7 +962,7 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,
goto out_restart_rx;

uport->uartclk = clk_rate;
clk_set_rate(port->se.clk, clk_rate);
dev_pm_opp_set_rate(uport->dev, clk_rate);
ser_clk_cfg = SER_CLK_EN;
ser_clk_cfg |= clk_div << CLK_DIV_SHFT;

Expand Down Expand Up @@ -1198,8 +1199,11 @@ static void qcom_geni_serial_pm(struct uart_port *uport,
if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF)
geni_se_resources_on(&port->se);
else if (new_state == UART_PM_STATE_OFF &&
old_state == UART_PM_STATE_ON)
old_state == UART_PM_STATE_ON) {
/* Drop the performance state vote */
dev_pm_opp_set_rate(uport->dev, 0);
geni_se_resources_off(&port->se);
}
}

static const struct uart_ops qcom_geni_console_pops = {
Expand Down Expand Up @@ -1318,21 +1322,33 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
if (of_property_read_bool(pdev->dev.of_node, "cts-rts-swap"))
port->cts_rts_swap = true;

port->se.opp_table = dev_pm_opp_set_clkname(&pdev->dev, "se");
if (IS_ERR(port->se.opp_table))
return PTR_ERR(port->se.opp_table);
/* OPP table is optional */
ret = dev_pm_opp_of_add_table(&pdev->dev);
if (!ret) {
port->se.has_opp_table = true;
} else if (ret != -ENODEV) {
dev_err(&pdev->dev, "invalid OPP table in device tree\n");
return ret;
}

uport->private_data = drv;
platform_set_drvdata(pdev, port);
port->handle_rx = console ? handle_rx_console : handle_rx_uart;

ret = uart_add_one_port(drv, uport);
if (ret)
return ret;
goto err;

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;
goto err;
}

/*
Expand All @@ -1349,18 +1365,26 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
if (ret) {
device_init_wakeup(&pdev->dev, false);
uart_remove_one_port(drv, uport);
return ret;
goto err;
}
}

return 0;
err:
if (port->se.has_opp_table)
dev_pm_opp_of_remove_table(&pdev->dev);
dev_pm_opp_put_clkname(port->se.opp_table);
return ret;
}

static int qcom_geni_serial_remove(struct platform_device *pdev)
{
struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
struct uart_driver *drv = port->uport.private_data;

if (port->se.has_opp_table)
dev_pm_opp_of_remove_table(&pdev->dev);
dev_pm_opp_put_clkname(port->se.opp_table);
dev_pm_clear_wake_irq(&pdev->dev);
device_init_wakeup(&pdev->dev, false);
uart_remove_one_port(drv, &port->uport);
Expand Down
4 changes: 4 additions & 0 deletions include/linux/qcom-geni-se.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct clk;
* @clk: Handle to the core serial engine clock
* @num_clk_levels: Number of valid clock levels in clk_perf_tbl
* @clk_perf_tbl: Table of clock frequency input to serial engine clock
* @opp_table: Pointer to the OPP table
* @has_opp_table: Specifies if the SE has an OPP table
*/
struct geni_se {
void __iomem *base;
Expand All @@ -41,6 +43,8 @@ struct geni_se {
struct clk *clk;
unsigned int num_clk_levels;
unsigned long *clk_perf_tbl;
struct opp_table *opp_table;
bool has_opp_table;
};

/* Common SE registers */
Expand Down

0 comments on commit 3d9231e

Please sign in to comment.