Re: [PATCH 02/21] tty: serial: qcom_geni_serial: Use OPP API to set clk/perf state

From: Rajendra Nayak
Date: Mon Apr 13 2020 - 10:13:33 EST


[]..

@@ -1318,13 +1321,16 @@ 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 = dev_pm_opp_set_clkname(&pdev->dev, "se");
+ÂÂÂ dev_pm_opp_of_add_table(&pdev->dev);
+
ÂÂÂÂÂ 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,
@@ -1332,7 +1338,7 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
ÂÂÂÂÂ if (ret) {
ÂÂÂÂÂÂÂÂÂ dev_err(uport->dev, "Failed to get IRQ ret %d\n", ret);
ÂÂÂÂÂÂÂÂÂ uart_remove_one_port(drv, uport);
-ÂÂÂÂÂÂÂ return ret;
+ÂÂÂÂÂÂÂ goto err;
ÂÂÂÂÂ }
ÂÂÂÂÂ /*
@@ -1349,11 +1355,14 @@ 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:
+ÂÂÂ dev_pm_opp_of_remove_table(&pdev->dev);
do we need to call "dev_pm_opp_put_clkname" here and in remove to release clk resource grabbed by

dev_pm_opp_set_clkname(&pdev->dev, "se");?

Thanks for catching this, I did indeed try to call dev_pm_opp_put_clkname() but the way clk_put
is handled in it seems buggy. I need to go back and fix it. Besides I realized dev_pm_opp_of_remove_table()
does go ahead and do a clk_put on the clock.

Viresh, whats the right way to clean up

+ port->se.opp = dev_pm_opp_set_clkname(&pdev->dev, "se");
+ dev_pm_opp_of_add_table(&pdev->dev);

is it
1. dev_pm_opp_of_remove_table()
dev_pm_opp_put_clkname()

or
2. dev_pm_opp_put_clkname()
dev_pm_opp_of_remove_table()

or, what this patch is currently doing, which is just calling dev_pm_opp_of_remove_table()?

Note that both 1. and 2. today result in a crash, since they don't handle clk_put very well.
I can send in a fix if you think dev_pm_opp_put_clkname is needed and in a certain order.

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation